bnx2x_main.c 308 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617
  1. /* bnx2x_main.c: Broadcom Everest network driver.
  2. *
  3. * Copyright (c) 2007-2011 Broadcom Corporation
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation.
  8. *
  9. * Maintained by: Eilon Greenstein <eilong@broadcom.com>
  10. * Written by: Eliezer Tamir
  11. * Based on code from Michael Chan's bnx2 driver
  12. * UDP CSUM errata workaround by Arik Gendelman
  13. * Slowpath and fastpath rework by Vladislav Zolotarov
  14. * Statistics and Link management by Yitchak Gertner
  15. *
  16. */
  17. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  18. #include <linux/module.h>
  19. #include <linux/moduleparam.h>
  20. #include <linux/kernel.h>
  21. #include <linux/device.h> /* for dev_info() */
  22. #include <linux/timer.h>
  23. #include <linux/errno.h>
  24. #include <linux/ioport.h>
  25. #include <linux/slab.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/pci.h>
  28. #include <linux/init.h>
  29. #include <linux/netdevice.h>
  30. #include <linux/etherdevice.h>
  31. #include <linux/skbuff.h>
  32. #include <linux/dma-mapping.h>
  33. #include <linux/bitops.h>
  34. #include <linux/irq.h>
  35. #include <linux/delay.h>
  36. #include <asm/byteorder.h>
  37. #include <linux/time.h>
  38. #include <linux/ethtool.h>
  39. #include <linux/mii.h>
  40. #include <linux/if.h>
  41. #include <linux/if_vlan.h>
  42. #include <net/ip.h>
  43. #include <net/ipv6.h>
  44. #include <net/tcp.h>
  45. #include <net/checksum.h>
  46. #include <net/ip6_checksum.h>
  47. #include <linux/workqueue.h>
  48. #include <linux/crc32.h>
  49. #include <linux/crc32c.h>
  50. #include <linux/prefetch.h>
  51. #include <linux/zlib.h>
  52. #include <linux/io.h>
  53. #include <linux/stringify.h>
  54. #include <linux/vmalloc.h>
  55. #include "bnx2x.h"
  56. #include "bnx2x_init.h"
  57. #include "bnx2x_init_ops.h"
  58. #include "bnx2x_cmn.h"
  59. #include "bnx2x_dcb.h"
  60. #include "bnx2x_sp.h"
  61. #include <linux/firmware.h>
  62. #include "bnx2x_fw_file_hdr.h"
  63. /* FW files */
  64. #define FW_FILE_VERSION \
  65. __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
  66. __stringify(BCM_5710_FW_MINOR_VERSION) "." \
  67. __stringify(BCM_5710_FW_REVISION_VERSION) "." \
  68. __stringify(BCM_5710_FW_ENGINEERING_VERSION)
  69. #define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw"
  70. #define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw"
  71. #define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw"
  72. /* Time in jiffies before concluding the transmitter is hung */
  73. #define TX_TIMEOUT (5*HZ)
  74. static char version[] __devinitdata =
  75. "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
  76. DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  77. MODULE_AUTHOR("Eliezer Tamir");
  78. MODULE_DESCRIPTION("Broadcom NetXtreme II "
  79. "BCM57710/57711/57711E/"
  80. "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
  81. "57840/57840_MF Driver");
  82. MODULE_LICENSE("GPL");
  83. MODULE_VERSION(DRV_MODULE_VERSION);
  84. MODULE_FIRMWARE(FW_FILE_NAME_E1);
  85. MODULE_FIRMWARE(FW_FILE_NAME_E1H);
  86. MODULE_FIRMWARE(FW_FILE_NAME_E2);
  87. static int multi_mode = 1;
  88. module_param(multi_mode, int, 0);
  89. MODULE_PARM_DESC(multi_mode, " Multi queue mode "
  90. "(0 Disable; 1 Enable (default))");
  91. int num_queues;
  92. module_param(num_queues, int, 0);
  93. MODULE_PARM_DESC(num_queues, " Number of queues for multi_mode=1"
  94. " (default is as a number of CPUs)");
  95. static int disable_tpa;
  96. module_param(disable_tpa, int, 0);
  97. MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
  98. #define INT_MODE_INTx 1
  99. #define INT_MODE_MSI 2
  100. static int int_mode;
  101. module_param(int_mode, int, 0);
  102. MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
  103. "(1 INT#x; 2 MSI)");
  104. static int dropless_fc;
  105. module_param(dropless_fc, int, 0);
  106. MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
  107. static int poll;
  108. module_param(poll, int, 0);
  109. MODULE_PARM_DESC(poll, " Use polling (for debug)");
  110. static int mrrs = -1;
  111. module_param(mrrs, int, 0);
  112. MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
  113. static int debug;
  114. module_param(debug, int, 0);
  115. MODULE_PARM_DESC(debug, " Default debug msglevel");
  116. struct workqueue_struct *bnx2x_wq;
  117. enum bnx2x_board_type {
  118. BCM57710 = 0,
  119. BCM57711,
  120. BCM57711E,
  121. BCM57712,
  122. BCM57712_MF,
  123. BCM57800,
  124. BCM57800_MF,
  125. BCM57810,
  126. BCM57810_MF,
  127. BCM57840,
  128. BCM57840_MF
  129. };
  130. /* indexed by board_type, above */
  131. static struct {
  132. char *name;
  133. } board_info[] __devinitdata = {
  134. { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
  135. { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
  136. { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
  137. { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
  138. { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
  139. { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
  140. { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
  141. { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
  142. { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
  143. { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
  144. { "Broadcom NetXtreme II BCM57840 10/20 Gigabit "
  145. "Ethernet Multi Function"}
  146. };
  147. #ifndef PCI_DEVICE_ID_NX2_57710
  148. #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
  149. #endif
  150. #ifndef PCI_DEVICE_ID_NX2_57711
  151. #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
  152. #endif
  153. #ifndef PCI_DEVICE_ID_NX2_57711E
  154. #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
  155. #endif
  156. #ifndef PCI_DEVICE_ID_NX2_57712
  157. #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
  158. #endif
  159. #ifndef PCI_DEVICE_ID_NX2_57712_MF
  160. #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
  161. #endif
  162. #ifndef PCI_DEVICE_ID_NX2_57800
  163. #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
  164. #endif
  165. #ifndef PCI_DEVICE_ID_NX2_57800_MF
  166. #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
  167. #endif
  168. #ifndef PCI_DEVICE_ID_NX2_57810
  169. #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
  170. #endif
  171. #ifndef PCI_DEVICE_ID_NX2_57810_MF
  172. #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
  173. #endif
  174. #ifndef PCI_DEVICE_ID_NX2_57840
  175. #define PCI_DEVICE_ID_NX2_57840 CHIP_NUM_57840
  176. #endif
  177. #ifndef PCI_DEVICE_ID_NX2_57840_MF
  178. #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
  179. #endif
  180. static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
  181. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
  182. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
  183. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
  184. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
  185. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
  186. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
  187. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
  188. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
  189. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
  190. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840), BCM57840 },
  191. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
  192. { 0 }
  193. };
  194. MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
  195. /****************************************************************************
  196. * General service functions
  197. ****************************************************************************/
  198. static inline void __storm_memset_dma_mapping(struct bnx2x *bp,
  199. u32 addr, dma_addr_t mapping)
  200. {
  201. REG_WR(bp, addr, U64_LO(mapping));
  202. REG_WR(bp, addr + 4, U64_HI(mapping));
  203. }
  204. static inline void storm_memset_spq_addr(struct bnx2x *bp,
  205. dma_addr_t mapping, u16 abs_fid)
  206. {
  207. u32 addr = XSEM_REG_FAST_MEMORY +
  208. XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
  209. __storm_memset_dma_mapping(bp, addr, mapping);
  210. }
  211. static inline void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
  212. u16 pf_id)
  213. {
  214. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
  215. pf_id);
  216. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
  217. pf_id);
  218. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
  219. pf_id);
  220. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
  221. pf_id);
  222. }
  223. static inline void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
  224. u8 enable)
  225. {
  226. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
  227. enable);
  228. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
  229. enable);
  230. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
  231. enable);
  232. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
  233. enable);
  234. }
  235. static inline void storm_memset_eq_data(struct bnx2x *bp,
  236. struct event_ring_data *eq_data,
  237. u16 pfid)
  238. {
  239. size_t size = sizeof(struct event_ring_data);
  240. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
  241. __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
  242. }
  243. static inline void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
  244. u16 pfid)
  245. {
  246. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
  247. REG_WR16(bp, addr, eq_prod);
  248. }
  249. /* used only at init
  250. * locking is done by mcp
  251. */
  252. static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
  253. {
  254. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  255. pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
  256. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  257. PCICFG_VENDOR_ID_OFFSET);
  258. }
  259. static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
  260. {
  261. u32 val;
  262. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  263. pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
  264. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  265. PCICFG_VENDOR_ID_OFFSET);
  266. return val;
  267. }
  268. #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
  269. #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
  270. #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
  271. #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
  272. #define DMAE_DP_DST_NONE "dst_addr [none]"
  273. static void bnx2x_dp_dmae(struct bnx2x *bp, struct dmae_command *dmae,
  274. int msglvl)
  275. {
  276. u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
  277. switch (dmae->opcode & DMAE_COMMAND_DST) {
  278. case DMAE_CMD_DST_PCI:
  279. if (src_type == DMAE_CMD_SRC_PCI)
  280. DP(msglvl, "DMAE: opcode 0x%08x\n"
  281. "src [%x:%08x], len [%d*4], dst [%x:%08x]\n"
  282. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  283. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  284. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  285. dmae->comp_addr_hi, dmae->comp_addr_lo,
  286. dmae->comp_val);
  287. else
  288. DP(msglvl, "DMAE: opcode 0x%08x\n"
  289. "src [%08x], len [%d*4], dst [%x:%08x]\n"
  290. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  291. dmae->opcode, dmae->src_addr_lo >> 2,
  292. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  293. dmae->comp_addr_hi, dmae->comp_addr_lo,
  294. dmae->comp_val);
  295. break;
  296. case DMAE_CMD_DST_GRC:
  297. if (src_type == DMAE_CMD_SRC_PCI)
  298. DP(msglvl, "DMAE: opcode 0x%08x\n"
  299. "src [%x:%08x], len [%d*4], dst_addr [%08x]\n"
  300. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  301. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  302. dmae->len, dmae->dst_addr_lo >> 2,
  303. dmae->comp_addr_hi, dmae->comp_addr_lo,
  304. dmae->comp_val);
  305. else
  306. DP(msglvl, "DMAE: opcode 0x%08x\n"
  307. "src [%08x], len [%d*4], dst [%08x]\n"
  308. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  309. dmae->opcode, dmae->src_addr_lo >> 2,
  310. dmae->len, dmae->dst_addr_lo >> 2,
  311. dmae->comp_addr_hi, dmae->comp_addr_lo,
  312. dmae->comp_val);
  313. break;
  314. default:
  315. if (src_type == DMAE_CMD_SRC_PCI)
  316. DP(msglvl, "DMAE: opcode 0x%08x\n"
  317. "src_addr [%x:%08x] len [%d * 4] dst_addr [none]\n"
  318. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  319. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  320. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  321. dmae->comp_val);
  322. else
  323. DP(msglvl, "DMAE: opcode 0x%08x\n"
  324. "src_addr [%08x] len [%d * 4] dst_addr [none]\n"
  325. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  326. dmae->opcode, dmae->src_addr_lo >> 2,
  327. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  328. dmae->comp_val);
  329. break;
  330. }
  331. }
  332. /* copy command into DMAE command memory and set DMAE command go */
  333. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
  334. {
  335. u32 cmd_offset;
  336. int i;
  337. cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
  338. for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
  339. REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
  340. DP(BNX2X_MSG_OFF, "DMAE cmd[%d].%d (0x%08x) : 0x%08x\n",
  341. idx, i, cmd_offset + i*4, *(((u32 *)dmae) + i));
  342. }
  343. REG_WR(bp, dmae_reg_go_c[idx], 1);
  344. }
  345. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
  346. {
  347. return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
  348. DMAE_CMD_C_ENABLE);
  349. }
  350. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
  351. {
  352. return opcode & ~DMAE_CMD_SRC_RESET;
  353. }
  354. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  355. bool with_comp, u8 comp_type)
  356. {
  357. u32 opcode = 0;
  358. opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
  359. (dst_type << DMAE_COMMAND_DST_SHIFT));
  360. opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
  361. opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
  362. opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
  363. (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
  364. opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
  365. #ifdef __BIG_ENDIAN
  366. opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
  367. #else
  368. opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
  369. #endif
  370. if (with_comp)
  371. opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
  372. return opcode;
  373. }
  374. static void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
  375. struct dmae_command *dmae,
  376. u8 src_type, u8 dst_type)
  377. {
  378. memset(dmae, 0, sizeof(struct dmae_command));
  379. /* set the opcode */
  380. dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
  381. true, DMAE_COMP_PCI);
  382. /* fill in the completion parameters */
  383. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
  384. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
  385. dmae->comp_val = DMAE_COMP_VAL;
  386. }
  387. /* issue a dmae command over the init-channel and wailt for completion */
  388. static int bnx2x_issue_dmae_with_comp(struct bnx2x *bp,
  389. struct dmae_command *dmae)
  390. {
  391. u32 *wb_comp = bnx2x_sp(bp, wb_comp);
  392. int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
  393. int rc = 0;
  394. DP(BNX2X_MSG_OFF, "data before [0x%08x 0x%08x 0x%08x 0x%08x]\n",
  395. bp->slowpath->wb_data[0], bp->slowpath->wb_data[1],
  396. bp->slowpath->wb_data[2], bp->slowpath->wb_data[3]);
  397. /*
  398. * Lock the dmae channel. Disable BHs to prevent a dead-lock
  399. * as long as this code is called both from syscall context and
  400. * from ndo_set_rx_mode() flow that may be called from BH.
  401. */
  402. spin_lock_bh(&bp->dmae_lock);
  403. /* reset completion */
  404. *wb_comp = 0;
  405. /* post the command on the channel used for initializations */
  406. bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
  407. /* wait for completion */
  408. udelay(5);
  409. while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
  410. DP(BNX2X_MSG_OFF, "wb_comp 0x%08x\n", *wb_comp);
  411. if (!cnt) {
  412. BNX2X_ERR("DMAE timeout!\n");
  413. rc = DMAE_TIMEOUT;
  414. goto unlock;
  415. }
  416. cnt--;
  417. udelay(50);
  418. }
  419. if (*wb_comp & DMAE_PCI_ERR_FLAG) {
  420. BNX2X_ERR("DMAE PCI error!\n");
  421. rc = DMAE_PCI_ERROR;
  422. }
  423. DP(BNX2X_MSG_OFF, "data after [0x%08x 0x%08x 0x%08x 0x%08x]\n",
  424. bp->slowpath->wb_data[0], bp->slowpath->wb_data[1],
  425. bp->slowpath->wb_data[2], bp->slowpath->wb_data[3]);
  426. unlock:
  427. spin_unlock_bh(&bp->dmae_lock);
  428. return rc;
  429. }
  430. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  431. u32 len32)
  432. {
  433. struct dmae_command dmae;
  434. if (!bp->dmae_ready) {
  435. u32 *data = bnx2x_sp(bp, wb_data[0]);
  436. DP(BNX2X_MSG_OFF, "DMAE is not ready (dst_addr %08x len32 %d)"
  437. " using indirect\n", dst_addr, len32);
  438. bnx2x_init_ind_wr(bp, dst_addr, data, len32);
  439. return;
  440. }
  441. /* set opcode and fixed command fields */
  442. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
  443. /* fill in addresses and len */
  444. dmae.src_addr_lo = U64_LO(dma_addr);
  445. dmae.src_addr_hi = U64_HI(dma_addr);
  446. dmae.dst_addr_lo = dst_addr >> 2;
  447. dmae.dst_addr_hi = 0;
  448. dmae.len = len32;
  449. bnx2x_dp_dmae(bp, &dmae, BNX2X_MSG_OFF);
  450. /* issue the command and wait for completion */
  451. bnx2x_issue_dmae_with_comp(bp, &dmae);
  452. }
  453. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
  454. {
  455. struct dmae_command dmae;
  456. if (!bp->dmae_ready) {
  457. u32 *data = bnx2x_sp(bp, wb_data[0]);
  458. int i;
  459. DP(BNX2X_MSG_OFF, "DMAE is not ready (src_addr %08x len32 %d)"
  460. " using indirect\n", src_addr, len32);
  461. for (i = 0; i < len32; i++)
  462. data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
  463. return;
  464. }
  465. /* set opcode and fixed command fields */
  466. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
  467. /* fill in addresses and len */
  468. dmae.src_addr_lo = src_addr >> 2;
  469. dmae.src_addr_hi = 0;
  470. dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
  471. dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
  472. dmae.len = len32;
  473. bnx2x_dp_dmae(bp, &dmae, BNX2X_MSG_OFF);
  474. /* issue the command and wait for completion */
  475. bnx2x_issue_dmae_with_comp(bp, &dmae);
  476. }
  477. static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
  478. u32 addr, u32 len)
  479. {
  480. int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
  481. int offset = 0;
  482. while (len > dmae_wr_max) {
  483. bnx2x_write_dmae(bp, phys_addr + offset,
  484. addr + offset, dmae_wr_max);
  485. offset += dmae_wr_max * 4;
  486. len -= dmae_wr_max;
  487. }
  488. bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
  489. }
  490. /* used only for slowpath so not inlined */
  491. static void bnx2x_wb_wr(struct bnx2x *bp, int reg, u32 val_hi, u32 val_lo)
  492. {
  493. u32 wb_write[2];
  494. wb_write[0] = val_hi;
  495. wb_write[1] = val_lo;
  496. REG_WR_DMAE(bp, reg, wb_write, 2);
  497. }
  498. #ifdef USE_WB_RD
  499. static u64 bnx2x_wb_rd(struct bnx2x *bp, int reg)
  500. {
  501. u32 wb_data[2];
  502. REG_RD_DMAE(bp, reg, wb_data, 2);
  503. return HILO_U64(wb_data[0], wb_data[1]);
  504. }
  505. #endif
  506. static int bnx2x_mc_assert(struct bnx2x *bp)
  507. {
  508. char last_idx;
  509. int i, rc = 0;
  510. u32 row0, row1, row2, row3;
  511. /* XSTORM */
  512. last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
  513. XSTORM_ASSERT_LIST_INDEX_OFFSET);
  514. if (last_idx)
  515. BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  516. /* print the asserts */
  517. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  518. row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  519. XSTORM_ASSERT_LIST_OFFSET(i));
  520. row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  521. XSTORM_ASSERT_LIST_OFFSET(i) + 4);
  522. row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  523. XSTORM_ASSERT_LIST_OFFSET(i) + 8);
  524. row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  525. XSTORM_ASSERT_LIST_OFFSET(i) + 12);
  526. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  527. BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x"
  528. " 0x%08x 0x%08x 0x%08x\n",
  529. i, row3, row2, row1, row0);
  530. rc++;
  531. } else {
  532. break;
  533. }
  534. }
  535. /* TSTORM */
  536. last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
  537. TSTORM_ASSERT_LIST_INDEX_OFFSET);
  538. if (last_idx)
  539. BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  540. /* print the asserts */
  541. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  542. row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  543. TSTORM_ASSERT_LIST_OFFSET(i));
  544. row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  545. TSTORM_ASSERT_LIST_OFFSET(i) + 4);
  546. row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  547. TSTORM_ASSERT_LIST_OFFSET(i) + 8);
  548. row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  549. TSTORM_ASSERT_LIST_OFFSET(i) + 12);
  550. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  551. BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x"
  552. " 0x%08x 0x%08x 0x%08x\n",
  553. i, row3, row2, row1, row0);
  554. rc++;
  555. } else {
  556. break;
  557. }
  558. }
  559. /* CSTORM */
  560. last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
  561. CSTORM_ASSERT_LIST_INDEX_OFFSET);
  562. if (last_idx)
  563. BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  564. /* print the asserts */
  565. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  566. row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  567. CSTORM_ASSERT_LIST_OFFSET(i));
  568. row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  569. CSTORM_ASSERT_LIST_OFFSET(i) + 4);
  570. row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  571. CSTORM_ASSERT_LIST_OFFSET(i) + 8);
  572. row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  573. CSTORM_ASSERT_LIST_OFFSET(i) + 12);
  574. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  575. BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x"
  576. " 0x%08x 0x%08x 0x%08x\n",
  577. i, row3, row2, row1, row0);
  578. rc++;
  579. } else {
  580. break;
  581. }
  582. }
  583. /* USTORM */
  584. last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
  585. USTORM_ASSERT_LIST_INDEX_OFFSET);
  586. if (last_idx)
  587. BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  588. /* print the asserts */
  589. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  590. row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
  591. USTORM_ASSERT_LIST_OFFSET(i));
  592. row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
  593. USTORM_ASSERT_LIST_OFFSET(i) + 4);
  594. row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
  595. USTORM_ASSERT_LIST_OFFSET(i) + 8);
  596. row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
  597. USTORM_ASSERT_LIST_OFFSET(i) + 12);
  598. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  599. BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x"
  600. " 0x%08x 0x%08x 0x%08x\n",
  601. i, row3, row2, row1, row0);
  602. rc++;
  603. } else {
  604. break;
  605. }
  606. }
  607. return rc;
  608. }
  609. void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
  610. {
  611. u32 addr, val;
  612. u32 mark, offset;
  613. __be32 data[9];
  614. int word;
  615. u32 trace_shmem_base;
  616. if (BP_NOMCP(bp)) {
  617. BNX2X_ERR("NO MCP - can not dump\n");
  618. return;
  619. }
  620. netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
  621. (bp->common.bc_ver & 0xff0000) >> 16,
  622. (bp->common.bc_ver & 0xff00) >> 8,
  623. (bp->common.bc_ver & 0xff));
  624. val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
  625. if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
  626. printk("%s" "MCP PC at 0x%x\n", lvl, val);
  627. if (BP_PATH(bp) == 0)
  628. trace_shmem_base = bp->common.shmem_base;
  629. else
  630. trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
  631. addr = trace_shmem_base - 0x0800 + 4;
  632. mark = REG_RD(bp, addr);
  633. mark = (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH)
  634. + ((mark + 0x3) & ~0x3) - 0x08000000;
  635. printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
  636. printk("%s", lvl);
  637. for (offset = mark; offset <= trace_shmem_base; offset += 0x8*4) {
  638. for (word = 0; word < 8; word++)
  639. data[word] = htonl(REG_RD(bp, offset + 4*word));
  640. data[8] = 0x0;
  641. pr_cont("%s", (char *)data);
  642. }
  643. for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
  644. for (word = 0; word < 8; word++)
  645. data[word] = htonl(REG_RD(bp, offset + 4*word));
  646. data[8] = 0x0;
  647. pr_cont("%s", (char *)data);
  648. }
  649. printk("%s" "end of fw dump\n", lvl);
  650. }
  651. static inline void bnx2x_fw_dump(struct bnx2x *bp)
  652. {
  653. bnx2x_fw_dump_lvl(bp, KERN_ERR);
  654. }
  655. void bnx2x_panic_dump(struct bnx2x *bp)
  656. {
  657. int i;
  658. u16 j;
  659. struct hc_sp_status_block_data sp_sb_data;
  660. int func = BP_FUNC(bp);
  661. #ifdef BNX2X_STOP_ON_ERROR
  662. u16 start = 0, end = 0;
  663. u8 cos;
  664. #endif
  665. bp->stats_state = STATS_STATE_DISABLED;
  666. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  667. BNX2X_ERR("begin crash dump -----------------\n");
  668. /* Indices */
  669. /* Common */
  670. BNX2X_ERR("def_idx(0x%x) def_att_idx(0x%x) attn_state(0x%x)"
  671. " spq_prod_idx(0x%x) next_stats_cnt(0x%x)\n",
  672. bp->def_idx, bp->def_att_idx, bp->attn_state,
  673. bp->spq_prod_idx, bp->stats_counter);
  674. BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
  675. bp->def_status_blk->atten_status_block.attn_bits,
  676. bp->def_status_blk->atten_status_block.attn_bits_ack,
  677. bp->def_status_blk->atten_status_block.status_block_id,
  678. bp->def_status_blk->atten_status_block.attn_bits_index);
  679. BNX2X_ERR(" def (");
  680. for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
  681. pr_cont("0x%x%s",
  682. bp->def_status_blk->sp_sb.index_values[i],
  683. (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
  684. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  685. *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  686. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  687. i*sizeof(u32));
  688. pr_cont("igu_sb_id(0x%x) igu_seg_id(0x%x) pf_id(0x%x) vnic_id(0x%x) vf_id(0x%x) vf_valid (0x%x) state(0x%x)\n",
  689. sp_sb_data.igu_sb_id,
  690. sp_sb_data.igu_seg_id,
  691. sp_sb_data.p_func.pf_id,
  692. sp_sb_data.p_func.vnic_id,
  693. sp_sb_data.p_func.vf_id,
  694. sp_sb_data.p_func.vf_valid,
  695. sp_sb_data.state);
  696. for_each_eth_queue(bp, i) {
  697. struct bnx2x_fastpath *fp = &bp->fp[i];
  698. int loop;
  699. struct hc_status_block_data_e2 sb_data_e2;
  700. struct hc_status_block_data_e1x sb_data_e1x;
  701. struct hc_status_block_sm *hc_sm_p =
  702. CHIP_IS_E1x(bp) ?
  703. sb_data_e1x.common.state_machine :
  704. sb_data_e2.common.state_machine;
  705. struct hc_index_data *hc_index_p =
  706. CHIP_IS_E1x(bp) ?
  707. sb_data_e1x.index_data :
  708. sb_data_e2.index_data;
  709. u8 data_size, cos;
  710. u32 *sb_data_p;
  711. struct bnx2x_fp_txdata txdata;
  712. /* Rx */
  713. BNX2X_ERR("fp%d: rx_bd_prod(0x%x) rx_bd_cons(0x%x)"
  714. " rx_comp_prod(0x%x)"
  715. " rx_comp_cons(0x%x) *rx_cons_sb(0x%x)\n",
  716. i, fp->rx_bd_prod, fp->rx_bd_cons,
  717. fp->rx_comp_prod,
  718. fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
  719. BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x)"
  720. " fp_hc_idx(0x%x)\n",
  721. fp->rx_sge_prod, fp->last_max_sge,
  722. le16_to_cpu(fp->fp_hc_idx));
  723. /* Tx */
  724. for_each_cos_in_tx_queue(fp, cos)
  725. {
  726. txdata = fp->txdata[cos];
  727. BNX2X_ERR("fp%d: tx_pkt_prod(0x%x) tx_pkt_cons(0x%x)"
  728. " tx_bd_prod(0x%x) tx_bd_cons(0x%x)"
  729. " *tx_cons_sb(0x%x)\n",
  730. i, txdata.tx_pkt_prod,
  731. txdata.tx_pkt_cons, txdata.tx_bd_prod,
  732. txdata.tx_bd_cons,
  733. le16_to_cpu(*txdata.tx_cons_sb));
  734. }
  735. loop = CHIP_IS_E1x(bp) ?
  736. HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
  737. /* host sb data */
  738. #ifdef BCM_CNIC
  739. if (IS_FCOE_FP(fp))
  740. continue;
  741. #endif
  742. BNX2X_ERR(" run indexes (");
  743. for (j = 0; j < HC_SB_MAX_SM; j++)
  744. pr_cont("0x%x%s",
  745. fp->sb_running_index[j],
  746. (j == HC_SB_MAX_SM - 1) ? ")" : " ");
  747. BNX2X_ERR(" indexes (");
  748. for (j = 0; j < loop; j++)
  749. pr_cont("0x%x%s",
  750. fp->sb_index_values[j],
  751. (j == loop - 1) ? ")" : " ");
  752. /* fw sb data */
  753. data_size = CHIP_IS_E1x(bp) ?
  754. sizeof(struct hc_status_block_data_e1x) :
  755. sizeof(struct hc_status_block_data_e2);
  756. data_size /= sizeof(u32);
  757. sb_data_p = CHIP_IS_E1x(bp) ?
  758. (u32 *)&sb_data_e1x :
  759. (u32 *)&sb_data_e2;
  760. /* copy sb data in here */
  761. for (j = 0; j < data_size; j++)
  762. *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  763. CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
  764. j * sizeof(u32));
  765. if (!CHIP_IS_E1x(bp)) {
  766. pr_cont("pf_id(0x%x) vf_id(0x%x) vf_valid(0x%x) "
  767. "vnic_id(0x%x) same_igu_sb_1b(0x%x) "
  768. "state(0x%x)\n",
  769. sb_data_e2.common.p_func.pf_id,
  770. sb_data_e2.common.p_func.vf_id,
  771. sb_data_e2.common.p_func.vf_valid,
  772. sb_data_e2.common.p_func.vnic_id,
  773. sb_data_e2.common.same_igu_sb_1b,
  774. sb_data_e2.common.state);
  775. } else {
  776. pr_cont("pf_id(0x%x) vf_id(0x%x) vf_valid(0x%x) "
  777. "vnic_id(0x%x) same_igu_sb_1b(0x%x) "
  778. "state(0x%x)\n",
  779. sb_data_e1x.common.p_func.pf_id,
  780. sb_data_e1x.common.p_func.vf_id,
  781. sb_data_e1x.common.p_func.vf_valid,
  782. sb_data_e1x.common.p_func.vnic_id,
  783. sb_data_e1x.common.same_igu_sb_1b,
  784. sb_data_e1x.common.state);
  785. }
  786. /* SB_SMs data */
  787. for (j = 0; j < HC_SB_MAX_SM; j++) {
  788. pr_cont("SM[%d] __flags (0x%x) "
  789. "igu_sb_id (0x%x) igu_seg_id(0x%x) "
  790. "time_to_expire (0x%x) "
  791. "timer_value(0x%x)\n", j,
  792. hc_sm_p[j].__flags,
  793. hc_sm_p[j].igu_sb_id,
  794. hc_sm_p[j].igu_seg_id,
  795. hc_sm_p[j].time_to_expire,
  796. hc_sm_p[j].timer_value);
  797. }
  798. /* Indecies data */
  799. for (j = 0; j < loop; j++) {
  800. pr_cont("INDEX[%d] flags (0x%x) "
  801. "timeout (0x%x)\n", j,
  802. hc_index_p[j].flags,
  803. hc_index_p[j].timeout);
  804. }
  805. }
  806. #ifdef BNX2X_STOP_ON_ERROR
  807. /* Rings */
  808. /* Rx */
  809. for_each_rx_queue(bp, i) {
  810. struct bnx2x_fastpath *fp = &bp->fp[i];
  811. start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
  812. end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
  813. for (j = start; j != end; j = RX_BD(j + 1)) {
  814. u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
  815. struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
  816. BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
  817. i, j, rx_bd[1], rx_bd[0], sw_bd->skb);
  818. }
  819. start = RX_SGE(fp->rx_sge_prod);
  820. end = RX_SGE(fp->last_max_sge);
  821. for (j = start; j != end; j = RX_SGE(j + 1)) {
  822. u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
  823. struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
  824. BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
  825. i, j, rx_sge[1], rx_sge[0], sw_page->page);
  826. }
  827. start = RCQ_BD(fp->rx_comp_cons - 10);
  828. end = RCQ_BD(fp->rx_comp_cons + 503);
  829. for (j = start; j != end; j = RCQ_BD(j + 1)) {
  830. u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
  831. BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
  832. i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
  833. }
  834. }
  835. /* Tx */
  836. for_each_tx_queue(bp, i) {
  837. struct bnx2x_fastpath *fp = &bp->fp[i];
  838. for_each_cos_in_tx_queue(fp, cos) {
  839. struct bnx2x_fp_txdata *txdata = &fp->txdata[cos];
  840. start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
  841. end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
  842. for (j = start; j != end; j = TX_BD(j + 1)) {
  843. struct sw_tx_bd *sw_bd =
  844. &txdata->tx_buf_ring[j];
  845. BNX2X_ERR("fp%d: txdata %d, "
  846. "packet[%x]=[%p,%x]\n",
  847. i, cos, j, sw_bd->skb,
  848. sw_bd->first_bd);
  849. }
  850. start = TX_BD(txdata->tx_bd_cons - 10);
  851. end = TX_BD(txdata->tx_bd_cons + 254);
  852. for (j = start; j != end; j = TX_BD(j + 1)) {
  853. u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
  854. BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]="
  855. "[%x:%x:%x:%x]\n",
  856. i, cos, j, tx_bd[0], tx_bd[1],
  857. tx_bd[2], tx_bd[3]);
  858. }
  859. }
  860. }
  861. #endif
  862. bnx2x_fw_dump(bp);
  863. bnx2x_mc_assert(bp);
  864. BNX2X_ERR("end crash dump -----------------\n");
  865. }
  866. /*
  867. * FLR Support for E2
  868. *
  869. * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
  870. * initialization.
  871. */
  872. #define FLR_WAIT_USEC 10000 /* 10 miliseconds */
  873. #define FLR_WAIT_INTERAVAL 50 /* usec */
  874. #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERAVAL) /* 200 */
  875. struct pbf_pN_buf_regs {
  876. int pN;
  877. u32 init_crd;
  878. u32 crd;
  879. u32 crd_freed;
  880. };
  881. struct pbf_pN_cmd_regs {
  882. int pN;
  883. u32 lines_occup;
  884. u32 lines_freed;
  885. };
  886. static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
  887. struct pbf_pN_buf_regs *regs,
  888. u32 poll_count)
  889. {
  890. u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
  891. u32 cur_cnt = poll_count;
  892. crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
  893. crd = crd_start = REG_RD(bp, regs->crd);
  894. init_crd = REG_RD(bp, regs->init_crd);
  895. DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
  896. DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
  897. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
  898. while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
  899. (init_crd - crd_start))) {
  900. if (cur_cnt--) {
  901. udelay(FLR_WAIT_INTERAVAL);
  902. crd = REG_RD(bp, regs->crd);
  903. crd_freed = REG_RD(bp, regs->crd_freed);
  904. } else {
  905. DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
  906. regs->pN);
  907. DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
  908. regs->pN, crd);
  909. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
  910. regs->pN, crd_freed);
  911. break;
  912. }
  913. }
  914. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
  915. poll_count-cur_cnt, FLR_WAIT_INTERAVAL, regs->pN);
  916. }
  917. static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
  918. struct pbf_pN_cmd_regs *regs,
  919. u32 poll_count)
  920. {
  921. u32 occup, to_free, freed, freed_start;
  922. u32 cur_cnt = poll_count;
  923. occup = to_free = REG_RD(bp, regs->lines_occup);
  924. freed = freed_start = REG_RD(bp, regs->lines_freed);
  925. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
  926. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
  927. while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
  928. if (cur_cnt--) {
  929. udelay(FLR_WAIT_INTERAVAL);
  930. occup = REG_RD(bp, regs->lines_occup);
  931. freed = REG_RD(bp, regs->lines_freed);
  932. } else {
  933. DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
  934. regs->pN);
  935. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
  936. regs->pN, occup);
  937. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
  938. regs->pN, freed);
  939. break;
  940. }
  941. }
  942. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
  943. poll_count-cur_cnt, FLR_WAIT_INTERAVAL, regs->pN);
  944. }
  945. static inline u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
  946. u32 expected, u32 poll_count)
  947. {
  948. u32 cur_cnt = poll_count;
  949. u32 val;
  950. while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
  951. udelay(FLR_WAIT_INTERAVAL);
  952. return val;
  953. }
  954. static inline int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
  955. char *msg, u32 poll_cnt)
  956. {
  957. u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
  958. if (val != 0) {
  959. BNX2X_ERR("%s usage count=%d\n", msg, val);
  960. return 1;
  961. }
  962. return 0;
  963. }
  964. static u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
  965. {
  966. /* adjust polling timeout */
  967. if (CHIP_REV_IS_EMUL(bp))
  968. return FLR_POLL_CNT * 2000;
  969. if (CHIP_REV_IS_FPGA(bp))
  970. return FLR_POLL_CNT * 120;
  971. return FLR_POLL_CNT;
  972. }
  973. static void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
  974. {
  975. struct pbf_pN_cmd_regs cmd_regs[] = {
  976. {0, (CHIP_IS_E3B0(bp)) ?
  977. PBF_REG_TQ_OCCUPANCY_Q0 :
  978. PBF_REG_P0_TQ_OCCUPANCY,
  979. (CHIP_IS_E3B0(bp)) ?
  980. PBF_REG_TQ_LINES_FREED_CNT_Q0 :
  981. PBF_REG_P0_TQ_LINES_FREED_CNT},
  982. {1, (CHIP_IS_E3B0(bp)) ?
  983. PBF_REG_TQ_OCCUPANCY_Q1 :
  984. PBF_REG_P1_TQ_OCCUPANCY,
  985. (CHIP_IS_E3B0(bp)) ?
  986. PBF_REG_TQ_LINES_FREED_CNT_Q1 :
  987. PBF_REG_P1_TQ_LINES_FREED_CNT},
  988. {4, (CHIP_IS_E3B0(bp)) ?
  989. PBF_REG_TQ_OCCUPANCY_LB_Q :
  990. PBF_REG_P4_TQ_OCCUPANCY,
  991. (CHIP_IS_E3B0(bp)) ?
  992. PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
  993. PBF_REG_P4_TQ_LINES_FREED_CNT}
  994. };
  995. struct pbf_pN_buf_regs buf_regs[] = {
  996. {0, (CHIP_IS_E3B0(bp)) ?
  997. PBF_REG_INIT_CRD_Q0 :
  998. PBF_REG_P0_INIT_CRD ,
  999. (CHIP_IS_E3B0(bp)) ?
  1000. PBF_REG_CREDIT_Q0 :
  1001. PBF_REG_P0_CREDIT,
  1002. (CHIP_IS_E3B0(bp)) ?
  1003. PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
  1004. PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
  1005. {1, (CHIP_IS_E3B0(bp)) ?
  1006. PBF_REG_INIT_CRD_Q1 :
  1007. PBF_REG_P1_INIT_CRD,
  1008. (CHIP_IS_E3B0(bp)) ?
  1009. PBF_REG_CREDIT_Q1 :
  1010. PBF_REG_P1_CREDIT,
  1011. (CHIP_IS_E3B0(bp)) ?
  1012. PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
  1013. PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
  1014. {4, (CHIP_IS_E3B0(bp)) ?
  1015. PBF_REG_INIT_CRD_LB_Q :
  1016. PBF_REG_P4_INIT_CRD,
  1017. (CHIP_IS_E3B0(bp)) ?
  1018. PBF_REG_CREDIT_LB_Q :
  1019. PBF_REG_P4_CREDIT,
  1020. (CHIP_IS_E3B0(bp)) ?
  1021. PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
  1022. PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
  1023. };
  1024. int i;
  1025. /* Verify the command queues are flushed P0, P1, P4 */
  1026. for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
  1027. bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
  1028. /* Verify the transmission buffers are flushed P0, P1, P4 */
  1029. for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
  1030. bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
  1031. }
  1032. #define OP_GEN_PARAM(param) \
  1033. (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
  1034. #define OP_GEN_TYPE(type) \
  1035. (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
  1036. #define OP_GEN_AGG_VECT(index) \
  1037. (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
  1038. static inline int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func,
  1039. u32 poll_cnt)
  1040. {
  1041. struct sdm_op_gen op_gen = {0};
  1042. u32 comp_addr = BAR_CSTRORM_INTMEM +
  1043. CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
  1044. int ret = 0;
  1045. if (REG_RD(bp, comp_addr)) {
  1046. BNX2X_ERR("Cleanup complete is not 0\n");
  1047. return 1;
  1048. }
  1049. op_gen.command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
  1050. op_gen.command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
  1051. op_gen.command |= OP_GEN_AGG_VECT(clnup_func);
  1052. op_gen.command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
  1053. DP(BNX2X_MSG_SP, "FW Final cleanup\n");
  1054. REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen.command);
  1055. if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
  1056. BNX2X_ERR("FW final cleanup did not succeed\n");
  1057. ret = 1;
  1058. }
  1059. /* Zero completion for nxt FLR */
  1060. REG_WR(bp, comp_addr, 0);
  1061. return ret;
  1062. }
  1063. static inline u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
  1064. {
  1065. int pos;
  1066. u16 status;
  1067. pos = pci_pcie_cap(dev);
  1068. if (!pos)
  1069. return false;
  1070. pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, &status);
  1071. return status & PCI_EXP_DEVSTA_TRPND;
  1072. }
  1073. /* PF FLR specific routines
  1074. */
  1075. static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
  1076. {
  1077. /* wait for CFC PF usage-counter to zero (includes all the VFs) */
  1078. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1079. CFC_REG_NUM_LCIDS_INSIDE_PF,
  1080. "CFC PF usage counter timed out",
  1081. poll_cnt))
  1082. return 1;
  1083. /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
  1084. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1085. DORQ_REG_PF_USAGE_CNT,
  1086. "DQ PF usage counter timed out",
  1087. poll_cnt))
  1088. return 1;
  1089. /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
  1090. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1091. QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
  1092. "QM PF usage counter timed out",
  1093. poll_cnt))
  1094. return 1;
  1095. /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
  1096. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1097. TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
  1098. "Timers VNIC usage counter timed out",
  1099. poll_cnt))
  1100. return 1;
  1101. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1102. TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
  1103. "Timers NUM_SCANS usage counter timed out",
  1104. poll_cnt))
  1105. return 1;
  1106. /* Wait DMAE PF usage counter to zero */
  1107. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1108. dmae_reg_go_c[INIT_DMAE_C(bp)],
  1109. "DMAE dommand register timed out",
  1110. poll_cnt))
  1111. return 1;
  1112. return 0;
  1113. }
  1114. static void bnx2x_hw_enable_status(struct bnx2x *bp)
  1115. {
  1116. u32 val;
  1117. val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
  1118. DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
  1119. val = REG_RD(bp, PBF_REG_DISABLE_PF);
  1120. DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
  1121. val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
  1122. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
  1123. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
  1124. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
  1125. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
  1126. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
  1127. val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
  1128. DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
  1129. val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
  1130. DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
  1131. val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  1132. DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
  1133. val);
  1134. }
  1135. static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
  1136. {
  1137. u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
  1138. DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
  1139. /* Re-enable PF target read access */
  1140. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  1141. /* Poll HW usage counters */
  1142. if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
  1143. return -EBUSY;
  1144. /* Zero the igu 'trailing edge' and 'leading edge' */
  1145. /* Send the FW cleanup command */
  1146. if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
  1147. return -EBUSY;
  1148. /* ATC cleanup */
  1149. /* Verify TX hw is flushed */
  1150. bnx2x_tx_hw_flushed(bp, poll_cnt);
  1151. /* Wait 100ms (not adjusted according to platform) */
  1152. msleep(100);
  1153. /* Verify no pending pci transactions */
  1154. if (bnx2x_is_pcie_pending(bp->pdev))
  1155. BNX2X_ERR("PCIE Transactions still pending\n");
  1156. /* Debug */
  1157. bnx2x_hw_enable_status(bp);
  1158. /*
  1159. * Master enable - Due to WB DMAE writes performed before this
  1160. * register is re-initialized as part of the regular function init
  1161. */
  1162. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  1163. return 0;
  1164. }
  1165. static void bnx2x_hc_int_enable(struct bnx2x *bp)
  1166. {
  1167. int port = BP_PORT(bp);
  1168. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1169. u32 val = REG_RD(bp, addr);
  1170. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1171. int msi = (bp->flags & USING_MSI_FLAG) ? 1 : 0;
  1172. if (msix) {
  1173. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1174. HC_CONFIG_0_REG_INT_LINE_EN_0);
  1175. val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1176. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1177. } else if (msi) {
  1178. val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
  1179. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1180. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1181. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1182. } else {
  1183. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1184. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1185. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1186. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1187. if (!CHIP_IS_E1(bp)) {
  1188. DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x)\n",
  1189. val, port, addr);
  1190. REG_WR(bp, addr, val);
  1191. val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
  1192. }
  1193. }
  1194. if (CHIP_IS_E1(bp))
  1195. REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
  1196. DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x) mode %s\n",
  1197. val, port, addr, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1198. REG_WR(bp, addr, val);
  1199. /*
  1200. * Ensure that HC_CONFIG is written before leading/trailing edge config
  1201. */
  1202. mmiowb();
  1203. barrier();
  1204. if (!CHIP_IS_E1(bp)) {
  1205. /* init leading/trailing edge */
  1206. if (IS_MF(bp)) {
  1207. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1208. if (bp->port.pmf)
  1209. /* enable nig and gpio3 attention */
  1210. val |= 0x1100;
  1211. } else
  1212. val = 0xffff;
  1213. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  1214. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  1215. }
  1216. /* Make sure that interrupts are indeed enabled from here on */
  1217. mmiowb();
  1218. }
  1219. static void bnx2x_igu_int_enable(struct bnx2x *bp)
  1220. {
  1221. u32 val;
  1222. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1223. int msi = (bp->flags & USING_MSI_FLAG) ? 1 : 0;
  1224. val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1225. if (msix) {
  1226. val &= ~(IGU_PF_CONF_INT_LINE_EN |
  1227. IGU_PF_CONF_SINGLE_ISR_EN);
  1228. val |= (IGU_PF_CONF_FUNC_EN |
  1229. IGU_PF_CONF_MSI_MSIX_EN |
  1230. IGU_PF_CONF_ATTN_BIT_EN);
  1231. } else if (msi) {
  1232. val &= ~IGU_PF_CONF_INT_LINE_EN;
  1233. val |= (IGU_PF_CONF_FUNC_EN |
  1234. IGU_PF_CONF_MSI_MSIX_EN |
  1235. IGU_PF_CONF_ATTN_BIT_EN |
  1236. IGU_PF_CONF_SINGLE_ISR_EN);
  1237. } else {
  1238. val &= ~IGU_PF_CONF_MSI_MSIX_EN;
  1239. val |= (IGU_PF_CONF_FUNC_EN |
  1240. IGU_PF_CONF_INT_LINE_EN |
  1241. IGU_PF_CONF_ATTN_BIT_EN |
  1242. IGU_PF_CONF_SINGLE_ISR_EN);
  1243. }
  1244. DP(NETIF_MSG_INTR, "write 0x%x to IGU mode %s\n",
  1245. val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1246. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1247. barrier();
  1248. /* init leading/trailing edge */
  1249. if (IS_MF(bp)) {
  1250. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1251. if (bp->port.pmf)
  1252. /* enable nig and gpio3 attention */
  1253. val |= 0x1100;
  1254. } else
  1255. val = 0xffff;
  1256. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  1257. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  1258. /* Make sure that interrupts are indeed enabled from here on */
  1259. mmiowb();
  1260. }
  1261. void bnx2x_int_enable(struct bnx2x *bp)
  1262. {
  1263. if (bp->common.int_block == INT_BLOCK_HC)
  1264. bnx2x_hc_int_enable(bp);
  1265. else
  1266. bnx2x_igu_int_enable(bp);
  1267. }
  1268. static void bnx2x_hc_int_disable(struct bnx2x *bp)
  1269. {
  1270. int port = BP_PORT(bp);
  1271. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1272. u32 val = REG_RD(bp, addr);
  1273. /*
  1274. * in E1 we must use only PCI configuration space to disable
  1275. * MSI/MSIX capablility
  1276. * It's forbitten to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
  1277. */
  1278. if (CHIP_IS_E1(bp)) {
  1279. /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
  1280. * Use mask register to prevent from HC sending interrupts
  1281. * after we exit the function
  1282. */
  1283. REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
  1284. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1285. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1286. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1287. } else
  1288. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1289. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1290. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1291. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1292. DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x)\n",
  1293. val, port, addr);
  1294. /* flush all outstanding writes */
  1295. mmiowb();
  1296. REG_WR(bp, addr, val);
  1297. if (REG_RD(bp, addr) != val)
  1298. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  1299. }
  1300. static void bnx2x_igu_int_disable(struct bnx2x *bp)
  1301. {
  1302. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1303. val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
  1304. IGU_PF_CONF_INT_LINE_EN |
  1305. IGU_PF_CONF_ATTN_BIT_EN);
  1306. DP(NETIF_MSG_INTR, "write %x to IGU\n", val);
  1307. /* flush all outstanding writes */
  1308. mmiowb();
  1309. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1310. if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
  1311. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  1312. }
  1313. void bnx2x_int_disable(struct bnx2x *bp)
  1314. {
  1315. if (bp->common.int_block == INT_BLOCK_HC)
  1316. bnx2x_hc_int_disable(bp);
  1317. else
  1318. bnx2x_igu_int_disable(bp);
  1319. }
  1320. void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
  1321. {
  1322. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1323. int i, offset;
  1324. if (disable_hw)
  1325. /* prevent the HW from sending interrupts */
  1326. bnx2x_int_disable(bp);
  1327. /* make sure all ISRs are done */
  1328. if (msix) {
  1329. synchronize_irq(bp->msix_table[0].vector);
  1330. offset = 1;
  1331. #ifdef BCM_CNIC
  1332. offset++;
  1333. #endif
  1334. for_each_eth_queue(bp, i)
  1335. synchronize_irq(bp->msix_table[offset++].vector);
  1336. } else
  1337. synchronize_irq(bp->pdev->irq);
  1338. /* make sure sp_task is not running */
  1339. cancel_delayed_work(&bp->sp_task);
  1340. cancel_delayed_work(&bp->period_task);
  1341. flush_workqueue(bnx2x_wq);
  1342. }
  1343. /* fast path */
  1344. /*
  1345. * General service functions
  1346. */
  1347. /* Return true if succeeded to acquire the lock */
  1348. static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
  1349. {
  1350. u32 lock_status;
  1351. u32 resource_bit = (1 << resource);
  1352. int func = BP_FUNC(bp);
  1353. u32 hw_lock_control_reg;
  1354. DP(NETIF_MSG_HW, "Trying to take a lock on resource %d\n", resource);
  1355. /* Validating that the resource is within range */
  1356. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1357. DP(NETIF_MSG_HW,
  1358. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1359. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1360. return false;
  1361. }
  1362. if (func <= 5)
  1363. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1364. else
  1365. hw_lock_control_reg =
  1366. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1367. /* Try to acquire the lock */
  1368. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1369. lock_status = REG_RD(bp, hw_lock_control_reg);
  1370. if (lock_status & resource_bit)
  1371. return true;
  1372. DP(NETIF_MSG_HW, "Failed to get a lock on resource %d\n", resource);
  1373. return false;
  1374. }
  1375. /**
  1376. * bnx2x_get_leader_lock_resource - get the recovery leader resource id
  1377. *
  1378. * @bp: driver handle
  1379. *
  1380. * Returns the recovery leader resource id according to the engine this function
  1381. * belongs to. Currently only only 2 engines is supported.
  1382. */
  1383. static inline int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
  1384. {
  1385. if (BP_PATH(bp))
  1386. return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
  1387. else
  1388. return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
  1389. }
  1390. /**
  1391. * bnx2x_trylock_leader_lock- try to aquire a leader lock.
  1392. *
  1393. * @bp: driver handle
  1394. *
  1395. * Tries to aquire a leader lock for cuurent engine.
  1396. */
  1397. static inline bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
  1398. {
  1399. return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1400. }
  1401. #ifdef BCM_CNIC
  1402. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
  1403. #endif
  1404. void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
  1405. {
  1406. struct bnx2x *bp = fp->bp;
  1407. int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1408. int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1409. enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
  1410. struct bnx2x_queue_sp_obj *q_obj = &fp->q_obj;
  1411. DP(BNX2X_MSG_SP,
  1412. "fp %d cid %d got ramrod #%d state is %x type is %d\n",
  1413. fp->index, cid, command, bp->state,
  1414. rr_cqe->ramrod_cqe.ramrod_type);
  1415. switch (command) {
  1416. case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
  1417. DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
  1418. drv_cmd = BNX2X_Q_CMD_UPDATE;
  1419. break;
  1420. case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
  1421. DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
  1422. drv_cmd = BNX2X_Q_CMD_SETUP;
  1423. break;
  1424. case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
  1425. DP(NETIF_MSG_IFUP, "got MULTI[%d] tx-only setup ramrod\n", cid);
  1426. drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  1427. break;
  1428. case (RAMROD_CMD_ID_ETH_HALT):
  1429. DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
  1430. drv_cmd = BNX2X_Q_CMD_HALT;
  1431. break;
  1432. case (RAMROD_CMD_ID_ETH_TERMINATE):
  1433. DP(BNX2X_MSG_SP, "got MULTI[%d] teminate ramrod\n", cid);
  1434. drv_cmd = BNX2X_Q_CMD_TERMINATE;
  1435. break;
  1436. case (RAMROD_CMD_ID_ETH_EMPTY):
  1437. DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
  1438. drv_cmd = BNX2X_Q_CMD_EMPTY;
  1439. break;
  1440. default:
  1441. BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
  1442. command, fp->index);
  1443. return;
  1444. }
  1445. if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
  1446. q_obj->complete_cmd(bp, q_obj, drv_cmd))
  1447. /* q_obj->complete_cmd() failure means that this was
  1448. * an unexpected completion.
  1449. *
  1450. * In this case we don't want to increase the bp->spq_left
  1451. * because apparently we haven't sent this command the first
  1452. * place.
  1453. */
  1454. #ifdef BNX2X_STOP_ON_ERROR
  1455. bnx2x_panic();
  1456. #else
  1457. return;
  1458. #endif
  1459. smp_mb__before_atomic_inc();
  1460. atomic_inc(&bp->cq_spq_left);
  1461. /* push the change in bp->spq_left and towards the memory */
  1462. smp_mb__after_atomic_inc();
  1463. DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
  1464. return;
  1465. }
  1466. void bnx2x_update_rx_prod(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  1467. u16 bd_prod, u16 rx_comp_prod, u16 rx_sge_prod)
  1468. {
  1469. u32 start = BAR_USTRORM_INTMEM + fp->ustorm_rx_prods_offset;
  1470. bnx2x_update_rx_prod_gen(bp, fp, bd_prod, rx_comp_prod, rx_sge_prod,
  1471. start);
  1472. }
  1473. irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
  1474. {
  1475. struct bnx2x *bp = netdev_priv(dev_instance);
  1476. u16 status = bnx2x_ack_int(bp);
  1477. u16 mask;
  1478. int i;
  1479. u8 cos;
  1480. /* Return here if interrupt is shared and it's not for us */
  1481. if (unlikely(status == 0)) {
  1482. DP(NETIF_MSG_INTR, "not our interrupt!\n");
  1483. return IRQ_NONE;
  1484. }
  1485. DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
  1486. #ifdef BNX2X_STOP_ON_ERROR
  1487. if (unlikely(bp->panic))
  1488. return IRQ_HANDLED;
  1489. #endif
  1490. for_each_eth_queue(bp, i) {
  1491. struct bnx2x_fastpath *fp = &bp->fp[i];
  1492. mask = 0x2 << (fp->index + CNIC_PRESENT);
  1493. if (status & mask) {
  1494. /* Handle Rx or Tx according to SB id */
  1495. prefetch(fp->rx_cons_sb);
  1496. for_each_cos_in_tx_queue(fp, cos)
  1497. prefetch(fp->txdata[cos].tx_cons_sb);
  1498. prefetch(&fp->sb_running_index[SM_RX_ID]);
  1499. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  1500. status &= ~mask;
  1501. }
  1502. }
  1503. #ifdef BCM_CNIC
  1504. mask = 0x2;
  1505. if (status & (mask | 0x1)) {
  1506. struct cnic_ops *c_ops = NULL;
  1507. if (likely(bp->state == BNX2X_STATE_OPEN)) {
  1508. rcu_read_lock();
  1509. c_ops = rcu_dereference(bp->cnic_ops);
  1510. if (c_ops)
  1511. c_ops->cnic_handler(bp->cnic_data, NULL);
  1512. rcu_read_unlock();
  1513. }
  1514. status &= ~mask;
  1515. }
  1516. #endif
  1517. if (unlikely(status & 0x1)) {
  1518. queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1519. status &= ~0x1;
  1520. if (!status)
  1521. return IRQ_HANDLED;
  1522. }
  1523. if (unlikely(status))
  1524. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
  1525. status);
  1526. return IRQ_HANDLED;
  1527. }
  1528. /* Link */
  1529. /*
  1530. * General service functions
  1531. */
  1532. int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
  1533. {
  1534. u32 lock_status;
  1535. u32 resource_bit = (1 << resource);
  1536. int func = BP_FUNC(bp);
  1537. u32 hw_lock_control_reg;
  1538. int cnt;
  1539. /* Validating that the resource is within range */
  1540. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1541. DP(NETIF_MSG_HW,
  1542. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1543. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1544. return -EINVAL;
  1545. }
  1546. if (func <= 5) {
  1547. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1548. } else {
  1549. hw_lock_control_reg =
  1550. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1551. }
  1552. /* Validating that the resource is not already taken */
  1553. lock_status = REG_RD(bp, hw_lock_control_reg);
  1554. if (lock_status & resource_bit) {
  1555. DP(NETIF_MSG_HW, "lock_status 0x%x resource_bit 0x%x\n",
  1556. lock_status, resource_bit);
  1557. return -EEXIST;
  1558. }
  1559. /* Try for 5 second every 5ms */
  1560. for (cnt = 0; cnt < 1000; cnt++) {
  1561. /* Try to acquire the lock */
  1562. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1563. lock_status = REG_RD(bp, hw_lock_control_reg);
  1564. if (lock_status & resource_bit)
  1565. return 0;
  1566. msleep(5);
  1567. }
  1568. DP(NETIF_MSG_HW, "Timeout\n");
  1569. return -EAGAIN;
  1570. }
  1571. int bnx2x_release_leader_lock(struct bnx2x *bp)
  1572. {
  1573. return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1574. }
  1575. int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
  1576. {
  1577. u32 lock_status;
  1578. u32 resource_bit = (1 << resource);
  1579. int func = BP_FUNC(bp);
  1580. u32 hw_lock_control_reg;
  1581. DP(NETIF_MSG_HW, "Releasing a lock on resource %d\n", resource);
  1582. /* Validating that the resource is within range */
  1583. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1584. DP(NETIF_MSG_HW,
  1585. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1586. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1587. return -EINVAL;
  1588. }
  1589. if (func <= 5) {
  1590. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1591. } else {
  1592. hw_lock_control_reg =
  1593. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1594. }
  1595. /* Validating that the resource is currently taken */
  1596. lock_status = REG_RD(bp, hw_lock_control_reg);
  1597. if (!(lock_status & resource_bit)) {
  1598. DP(NETIF_MSG_HW, "lock_status 0x%x resource_bit 0x%x\n",
  1599. lock_status, resource_bit);
  1600. return -EFAULT;
  1601. }
  1602. REG_WR(bp, hw_lock_control_reg, resource_bit);
  1603. return 0;
  1604. }
  1605. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
  1606. {
  1607. /* The GPIO should be swapped if swap register is set and active */
  1608. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1609. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1610. int gpio_shift = gpio_num +
  1611. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1612. u32 gpio_mask = (1 << gpio_shift);
  1613. u32 gpio_reg;
  1614. int value;
  1615. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1616. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1617. return -EINVAL;
  1618. }
  1619. /* read GPIO value */
  1620. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1621. /* get the requested pin value */
  1622. if ((gpio_reg & gpio_mask) == gpio_mask)
  1623. value = 1;
  1624. else
  1625. value = 0;
  1626. DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
  1627. return value;
  1628. }
  1629. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1630. {
  1631. /* The GPIO should be swapped if swap register is set and active */
  1632. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1633. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1634. int gpio_shift = gpio_num +
  1635. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1636. u32 gpio_mask = (1 << gpio_shift);
  1637. u32 gpio_reg;
  1638. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1639. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1640. return -EINVAL;
  1641. }
  1642. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1643. /* read GPIO and mask except the float bits */
  1644. gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
  1645. switch (mode) {
  1646. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1647. DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> output low\n",
  1648. gpio_num, gpio_shift);
  1649. /* clear FLOAT and set CLR */
  1650. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1651. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
  1652. break;
  1653. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1654. DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> output high\n",
  1655. gpio_num, gpio_shift);
  1656. /* clear FLOAT and set SET */
  1657. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1658. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
  1659. break;
  1660. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1661. DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> input\n",
  1662. gpio_num, gpio_shift);
  1663. /* set FLOAT */
  1664. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1665. break;
  1666. default:
  1667. break;
  1668. }
  1669. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1670. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1671. return 0;
  1672. }
  1673. int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
  1674. {
  1675. u32 gpio_reg = 0;
  1676. int rc = 0;
  1677. /* Any port swapping should be handled by caller. */
  1678. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1679. /* read GPIO and mask except the float bits */
  1680. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1681. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1682. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
  1683. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
  1684. switch (mode) {
  1685. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1686. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
  1687. /* set CLR */
  1688. gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
  1689. break;
  1690. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1691. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
  1692. /* set SET */
  1693. gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
  1694. break;
  1695. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1696. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
  1697. /* set FLOAT */
  1698. gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1699. break;
  1700. default:
  1701. BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
  1702. rc = -EINVAL;
  1703. break;
  1704. }
  1705. if (rc == 0)
  1706. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1707. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1708. return rc;
  1709. }
  1710. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1711. {
  1712. /* The GPIO should be swapped if swap register is set and active */
  1713. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1714. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1715. int gpio_shift = gpio_num +
  1716. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1717. u32 gpio_mask = (1 << gpio_shift);
  1718. u32 gpio_reg;
  1719. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1720. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1721. return -EINVAL;
  1722. }
  1723. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1724. /* read GPIO int */
  1725. gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
  1726. switch (mode) {
  1727. case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
  1728. DP(NETIF_MSG_LINK, "Clear GPIO INT %d (shift %d) -> "
  1729. "output low\n", gpio_num, gpio_shift);
  1730. /* clear SET and set CLR */
  1731. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1732. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1733. break;
  1734. case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
  1735. DP(NETIF_MSG_LINK, "Set GPIO INT %d (shift %d) -> "
  1736. "output high\n", gpio_num, gpio_shift);
  1737. /* clear CLR and set SET */
  1738. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1739. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1740. break;
  1741. default:
  1742. break;
  1743. }
  1744. REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
  1745. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1746. return 0;
  1747. }
  1748. static int bnx2x_set_spio(struct bnx2x *bp, int spio_num, u32 mode)
  1749. {
  1750. u32 spio_mask = (1 << spio_num);
  1751. u32 spio_reg;
  1752. if ((spio_num < MISC_REGISTERS_SPIO_4) ||
  1753. (spio_num > MISC_REGISTERS_SPIO_7)) {
  1754. BNX2X_ERR("Invalid SPIO %d\n", spio_num);
  1755. return -EINVAL;
  1756. }
  1757. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1758. /* read SPIO and mask except the float bits */
  1759. spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_REGISTERS_SPIO_FLOAT);
  1760. switch (mode) {
  1761. case MISC_REGISTERS_SPIO_OUTPUT_LOW:
  1762. DP(NETIF_MSG_LINK, "Set SPIO %d -> output low\n", spio_num);
  1763. /* clear FLOAT and set CLR */
  1764. spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
  1765. spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_CLR_POS);
  1766. break;
  1767. case MISC_REGISTERS_SPIO_OUTPUT_HIGH:
  1768. DP(NETIF_MSG_LINK, "Set SPIO %d -> output high\n", spio_num);
  1769. /* clear FLOAT and set SET */
  1770. spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
  1771. spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_SET_POS);
  1772. break;
  1773. case MISC_REGISTERS_SPIO_INPUT_HI_Z:
  1774. DP(NETIF_MSG_LINK, "Set SPIO %d -> input\n", spio_num);
  1775. /* set FLOAT */
  1776. spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
  1777. break;
  1778. default:
  1779. break;
  1780. }
  1781. REG_WR(bp, MISC_REG_SPIO, spio_reg);
  1782. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1783. return 0;
  1784. }
  1785. void bnx2x_calc_fc_adv(struct bnx2x *bp)
  1786. {
  1787. u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1788. switch (bp->link_vars.ieee_fc &
  1789. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
  1790. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
  1791. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1792. ADVERTISED_Pause);
  1793. break;
  1794. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
  1795. bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
  1796. ADVERTISED_Pause);
  1797. break;
  1798. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
  1799. bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
  1800. break;
  1801. default:
  1802. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1803. ADVERTISED_Pause);
  1804. break;
  1805. }
  1806. }
  1807. u8 bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
  1808. {
  1809. if (!BP_NOMCP(bp)) {
  1810. u8 rc;
  1811. int cfx_idx = bnx2x_get_link_cfg_idx(bp);
  1812. u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
  1813. /*
  1814. * Initialize link parameters structure variables
  1815. * It is recommended to turn off RX FC for jumbo frames
  1816. * for better performance
  1817. */
  1818. if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
  1819. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
  1820. else
  1821. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
  1822. bnx2x_acquire_phy_lock(bp);
  1823. if (load_mode == LOAD_DIAG) {
  1824. struct link_params *lp = &bp->link_params;
  1825. lp->loopback_mode = LOOPBACK_XGXS;
  1826. /* do PHY loopback at 10G speed, if possible */
  1827. if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
  1828. if (lp->speed_cap_mask[cfx_idx] &
  1829. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  1830. lp->req_line_speed[cfx_idx] =
  1831. SPEED_10000;
  1832. else
  1833. lp->req_line_speed[cfx_idx] =
  1834. SPEED_1000;
  1835. }
  1836. }
  1837. rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1838. bnx2x_release_phy_lock(bp);
  1839. bnx2x_calc_fc_adv(bp);
  1840. if (CHIP_REV_IS_SLOW(bp) && bp->link_vars.link_up) {
  1841. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  1842. bnx2x_link_report(bp);
  1843. } else
  1844. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  1845. bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
  1846. return rc;
  1847. }
  1848. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  1849. return -EINVAL;
  1850. }
  1851. void bnx2x_link_set(struct bnx2x *bp)
  1852. {
  1853. if (!BP_NOMCP(bp)) {
  1854. bnx2x_acquire_phy_lock(bp);
  1855. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  1856. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1857. bnx2x_release_phy_lock(bp);
  1858. bnx2x_calc_fc_adv(bp);
  1859. } else
  1860. BNX2X_ERR("Bootcode is missing - can not set link\n");
  1861. }
  1862. static void bnx2x__link_reset(struct bnx2x *bp)
  1863. {
  1864. if (!BP_NOMCP(bp)) {
  1865. bnx2x_acquire_phy_lock(bp);
  1866. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  1867. bnx2x_release_phy_lock(bp);
  1868. } else
  1869. BNX2X_ERR("Bootcode is missing - can not reset link\n");
  1870. }
  1871. u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
  1872. {
  1873. u8 rc = 0;
  1874. if (!BP_NOMCP(bp)) {
  1875. bnx2x_acquire_phy_lock(bp);
  1876. rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
  1877. is_serdes);
  1878. bnx2x_release_phy_lock(bp);
  1879. } else
  1880. BNX2X_ERR("Bootcode is missing - can not test link\n");
  1881. return rc;
  1882. }
  1883. static void bnx2x_init_port_minmax(struct bnx2x *bp)
  1884. {
  1885. u32 r_param = bp->link_vars.line_speed / 8;
  1886. u32 fair_periodic_timeout_usec;
  1887. u32 t_fair;
  1888. memset(&(bp->cmng.rs_vars), 0,
  1889. sizeof(struct rate_shaping_vars_per_port));
  1890. memset(&(bp->cmng.fair_vars), 0, sizeof(struct fairness_vars_per_port));
  1891. /* 100 usec in SDM ticks = 25 since each tick is 4 usec */
  1892. bp->cmng.rs_vars.rs_periodic_timeout = RS_PERIODIC_TIMEOUT_USEC / 4;
  1893. /* this is the threshold below which no timer arming will occur
  1894. 1.25 coefficient is for the threshold to be a little bigger
  1895. than the real time, to compensate for timer in-accuracy */
  1896. bp->cmng.rs_vars.rs_threshold =
  1897. (RS_PERIODIC_TIMEOUT_USEC * r_param * 5) / 4;
  1898. /* resolution of fairness timer */
  1899. fair_periodic_timeout_usec = QM_ARB_BYTES / r_param;
  1900. /* for 10G it is 1000usec. for 1G it is 10000usec. */
  1901. t_fair = T_FAIR_COEF / bp->link_vars.line_speed;
  1902. /* this is the threshold below which we won't arm the timer anymore */
  1903. bp->cmng.fair_vars.fair_threshold = QM_ARB_BYTES;
  1904. /* we multiply by 1e3/8 to get bytes/msec.
  1905. We don't want the credits to pass a credit
  1906. of the t_fair*FAIR_MEM (algorithm resolution) */
  1907. bp->cmng.fair_vars.upper_bound = r_param * t_fair * FAIR_MEM;
  1908. /* since each tick is 4 usec */
  1909. bp->cmng.fair_vars.fairness_timeout = fair_periodic_timeout_usec / 4;
  1910. }
  1911. /* Calculates the sum of vn_min_rates.
  1912. It's needed for further normalizing of the min_rates.
  1913. Returns:
  1914. sum of vn_min_rates.
  1915. or
  1916. 0 - if all the min_rates are 0.
  1917. In the later case fainess algorithm should be deactivated.
  1918. If not all min_rates are zero then those that are zeroes will be set to 1.
  1919. */
  1920. static void bnx2x_calc_vn_weight_sum(struct bnx2x *bp)
  1921. {
  1922. int all_zero = 1;
  1923. int vn;
  1924. bp->vn_weight_sum = 0;
  1925. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  1926. u32 vn_cfg = bp->mf_config[vn];
  1927. u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  1928. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  1929. /* Skip hidden vns */
  1930. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  1931. continue;
  1932. /* If min rate is zero - set it to 1 */
  1933. if (!vn_min_rate)
  1934. vn_min_rate = DEF_MIN_RATE;
  1935. else
  1936. all_zero = 0;
  1937. bp->vn_weight_sum += vn_min_rate;
  1938. }
  1939. /* if ETS or all min rates are zeros - disable fairness */
  1940. if (BNX2X_IS_ETS_ENABLED(bp)) {
  1941. bp->cmng.flags.cmng_enables &=
  1942. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  1943. DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
  1944. } else if (all_zero) {
  1945. bp->cmng.flags.cmng_enables &=
  1946. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  1947. DP(NETIF_MSG_IFUP, "All MIN values are zeroes"
  1948. " fairness will be disabled\n");
  1949. } else
  1950. bp->cmng.flags.cmng_enables |=
  1951. CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  1952. }
  1953. /* returns func by VN for current port */
  1954. static inline int func_by_vn(struct bnx2x *bp, int vn)
  1955. {
  1956. return 2 * vn + BP_PORT(bp);
  1957. }
  1958. static void bnx2x_init_vn_minmax(struct bnx2x *bp, int vn)
  1959. {
  1960. struct rate_shaping_vars_per_vn m_rs_vn;
  1961. struct fairness_vars_per_vn m_fair_vn;
  1962. u32 vn_cfg = bp->mf_config[vn];
  1963. int func = func_by_vn(bp, vn);
  1964. u16 vn_min_rate, vn_max_rate;
  1965. int i;
  1966. /* If function is hidden - set min and max to zeroes */
  1967. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) {
  1968. vn_min_rate = 0;
  1969. vn_max_rate = 0;
  1970. } else {
  1971. u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
  1972. vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  1973. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  1974. /* If fairness is enabled (not all min rates are zeroes) and
  1975. if current min rate is zero - set it to 1.
  1976. This is a requirement of the algorithm. */
  1977. if (bp->vn_weight_sum && (vn_min_rate == 0))
  1978. vn_min_rate = DEF_MIN_RATE;
  1979. if (IS_MF_SI(bp))
  1980. /* maxCfg in percents of linkspeed */
  1981. vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
  1982. else
  1983. /* maxCfg is absolute in 100Mb units */
  1984. vn_max_rate = maxCfg * 100;
  1985. }
  1986. DP(NETIF_MSG_IFUP,
  1987. "func %d: vn_min_rate %d vn_max_rate %d vn_weight_sum %d\n",
  1988. func, vn_min_rate, vn_max_rate, bp->vn_weight_sum);
  1989. memset(&m_rs_vn, 0, sizeof(struct rate_shaping_vars_per_vn));
  1990. memset(&m_fair_vn, 0, sizeof(struct fairness_vars_per_vn));
  1991. /* global vn counter - maximal Mbps for this vn */
  1992. m_rs_vn.vn_counter.rate = vn_max_rate;
  1993. /* quota - number of bytes transmitted in this period */
  1994. m_rs_vn.vn_counter.quota =
  1995. (vn_max_rate * RS_PERIODIC_TIMEOUT_USEC) / 8;
  1996. if (bp->vn_weight_sum) {
  1997. /* credit for each period of the fairness algorithm:
  1998. number of bytes in T_FAIR (the vn share the port rate).
  1999. vn_weight_sum should not be larger than 10000, thus
  2000. T_FAIR_COEF / (8 * vn_weight_sum) will always be greater
  2001. than zero */
  2002. m_fair_vn.vn_credit_delta =
  2003. max_t(u32, (vn_min_rate * (T_FAIR_COEF /
  2004. (8 * bp->vn_weight_sum))),
  2005. (bp->cmng.fair_vars.fair_threshold +
  2006. MIN_ABOVE_THRESH));
  2007. DP(NETIF_MSG_IFUP, "m_fair_vn.vn_credit_delta %d\n",
  2008. m_fair_vn.vn_credit_delta);
  2009. }
  2010. /* Store it to internal memory */
  2011. for (i = 0; i < sizeof(struct rate_shaping_vars_per_vn)/4; i++)
  2012. REG_WR(bp, BAR_XSTRORM_INTMEM +
  2013. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func) + i * 4,
  2014. ((u32 *)(&m_rs_vn))[i]);
  2015. for (i = 0; i < sizeof(struct fairness_vars_per_vn)/4; i++)
  2016. REG_WR(bp, BAR_XSTRORM_INTMEM +
  2017. XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func) + i * 4,
  2018. ((u32 *)(&m_fair_vn))[i]);
  2019. }
  2020. static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
  2021. {
  2022. if (CHIP_REV_IS_SLOW(bp))
  2023. return CMNG_FNS_NONE;
  2024. if (IS_MF(bp))
  2025. return CMNG_FNS_MINMAX;
  2026. return CMNG_FNS_NONE;
  2027. }
  2028. void bnx2x_read_mf_cfg(struct bnx2x *bp)
  2029. {
  2030. int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
  2031. if (BP_NOMCP(bp))
  2032. return; /* what should be the default bvalue in this case */
  2033. /* For 2 port configuration the absolute function number formula
  2034. * is:
  2035. * abs_func = 2 * vn + BP_PORT + BP_PATH
  2036. *
  2037. * and there are 4 functions per port
  2038. *
  2039. * For 4 port configuration it is
  2040. * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
  2041. *
  2042. * and there are 2 functions per port
  2043. */
  2044. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2045. int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
  2046. if (func >= E1H_FUNC_MAX)
  2047. break;
  2048. bp->mf_config[vn] =
  2049. MF_CFG_RD(bp, func_mf_config[func].config);
  2050. }
  2051. }
  2052. static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
  2053. {
  2054. if (cmng_type == CMNG_FNS_MINMAX) {
  2055. int vn;
  2056. /* clear cmng_enables */
  2057. bp->cmng.flags.cmng_enables = 0;
  2058. /* read mf conf from shmem */
  2059. if (read_cfg)
  2060. bnx2x_read_mf_cfg(bp);
  2061. /* Init rate shaping and fairness contexts */
  2062. bnx2x_init_port_minmax(bp);
  2063. /* vn_weight_sum and enable fairness if not 0 */
  2064. bnx2x_calc_vn_weight_sum(bp);
  2065. /* calculate and set min-max rate for each vn */
  2066. if (bp->port.pmf)
  2067. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
  2068. bnx2x_init_vn_minmax(bp, vn);
  2069. /* always enable rate shaping and fairness */
  2070. bp->cmng.flags.cmng_enables |=
  2071. CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
  2072. if (!bp->vn_weight_sum)
  2073. DP(NETIF_MSG_IFUP, "All MIN values are zeroes"
  2074. " fairness will be disabled\n");
  2075. return;
  2076. }
  2077. /* rate shaping and fairness are disabled */
  2078. DP(NETIF_MSG_IFUP,
  2079. "rate shaping and fairness are disabled\n");
  2080. }
  2081. static inline void bnx2x_link_sync_notify(struct bnx2x *bp)
  2082. {
  2083. int func;
  2084. int vn;
  2085. /* Set the attention towards other drivers on the same port */
  2086. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2087. if (vn == BP_VN(bp))
  2088. continue;
  2089. func = func_by_vn(bp, vn);
  2090. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_0 +
  2091. (LINK_SYNC_ATTENTION_BIT_FUNC_0 + func)*4, 1);
  2092. }
  2093. }
  2094. /* This function is called upon link interrupt */
  2095. static void bnx2x_link_attn(struct bnx2x *bp)
  2096. {
  2097. /* Make sure that we are synced with the current statistics */
  2098. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2099. bnx2x_link_update(&bp->link_params, &bp->link_vars);
  2100. if (bp->link_vars.link_up) {
  2101. /* dropless flow control */
  2102. if (!CHIP_IS_E1(bp) && bp->dropless_fc) {
  2103. int port = BP_PORT(bp);
  2104. u32 pause_enabled = 0;
  2105. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  2106. pause_enabled = 1;
  2107. REG_WR(bp, BAR_USTRORM_INTMEM +
  2108. USTORM_ETH_PAUSE_ENABLED_OFFSET(port),
  2109. pause_enabled);
  2110. }
  2111. if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
  2112. struct host_port_stats *pstats;
  2113. pstats = bnx2x_sp(bp, port_stats);
  2114. /* reset old mac stats */
  2115. memset(&(pstats->mac_stx[0]), 0,
  2116. sizeof(struct mac_stx));
  2117. }
  2118. if (bp->state == BNX2X_STATE_OPEN)
  2119. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2120. }
  2121. if (bp->link_vars.link_up && bp->link_vars.line_speed) {
  2122. int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
  2123. if (cmng_fns != CMNG_FNS_NONE) {
  2124. bnx2x_cmng_fns_init(bp, false, cmng_fns);
  2125. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2126. } else
  2127. /* rate shaping and fairness are disabled */
  2128. DP(NETIF_MSG_IFUP,
  2129. "single function mode without fairness\n");
  2130. }
  2131. __bnx2x_link_report(bp);
  2132. if (IS_MF(bp))
  2133. bnx2x_link_sync_notify(bp);
  2134. }
  2135. void bnx2x__link_status_update(struct bnx2x *bp)
  2136. {
  2137. if (bp->state != BNX2X_STATE_OPEN)
  2138. return;
  2139. bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
  2140. if (bp->link_vars.link_up)
  2141. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2142. else
  2143. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2144. /* indicate link status */
  2145. bnx2x_link_report(bp);
  2146. }
  2147. static void bnx2x_pmf_update(struct bnx2x *bp)
  2148. {
  2149. int port = BP_PORT(bp);
  2150. u32 val;
  2151. bp->port.pmf = 1;
  2152. DP(NETIF_MSG_LINK, "pmf %d\n", bp->port.pmf);
  2153. /*
  2154. * We need the mb() to ensure the ordering between the writing to
  2155. * bp->port.pmf here and reading it from the bnx2x_periodic_task().
  2156. */
  2157. smp_mb();
  2158. /* queue a periodic task */
  2159. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2160. bnx2x_dcbx_pmf_update(bp);
  2161. /* enable nig attention */
  2162. val = (0xff0f | (1 << (BP_VN(bp) + 4)));
  2163. if (bp->common.int_block == INT_BLOCK_HC) {
  2164. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  2165. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  2166. } else if (!CHIP_IS_E1x(bp)) {
  2167. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  2168. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  2169. }
  2170. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2171. }
  2172. /* end of Link */
  2173. /* slow path */
  2174. /*
  2175. * General service functions
  2176. */
  2177. /* send the MCP a request, block until there is a reply */
  2178. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
  2179. {
  2180. int mb_idx = BP_FW_MB_IDX(bp);
  2181. u32 seq;
  2182. u32 rc = 0;
  2183. u32 cnt = 1;
  2184. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  2185. mutex_lock(&bp->fw_mb_mutex);
  2186. seq = ++bp->fw_seq;
  2187. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
  2188. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
  2189. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
  2190. (command | seq), param);
  2191. do {
  2192. /* let the FW do it's magic ... */
  2193. msleep(delay);
  2194. rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
  2195. /* Give the FW up to 5 second (500*10ms) */
  2196. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
  2197. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  2198. cnt*delay, rc, seq);
  2199. /* is this a reply to our command? */
  2200. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
  2201. rc &= FW_MSG_CODE_MASK;
  2202. else {
  2203. /* FW BUG! */
  2204. BNX2X_ERR("FW failed to respond!\n");
  2205. bnx2x_fw_dump(bp);
  2206. rc = 0;
  2207. }
  2208. mutex_unlock(&bp->fw_mb_mutex);
  2209. return rc;
  2210. }
  2211. static u8 stat_counter_valid(struct bnx2x *bp, struct bnx2x_fastpath *fp)
  2212. {
  2213. #ifdef BCM_CNIC
  2214. /* Statistics are not supported for CNIC Clients at the moment */
  2215. if (IS_FCOE_FP(fp))
  2216. return false;
  2217. #endif
  2218. return true;
  2219. }
  2220. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
  2221. {
  2222. if (CHIP_IS_E1x(bp)) {
  2223. struct tstorm_eth_function_common_config tcfg = {0};
  2224. storm_memset_func_cfg(bp, &tcfg, p->func_id);
  2225. }
  2226. /* Enable the function in the FW */
  2227. storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
  2228. storm_memset_func_en(bp, p->func_id, 1);
  2229. /* spq */
  2230. if (p->func_flgs & FUNC_FLG_SPQ) {
  2231. storm_memset_spq_addr(bp, p->spq_map, p->func_id);
  2232. REG_WR(bp, XSEM_REG_FAST_MEMORY +
  2233. XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
  2234. }
  2235. }
  2236. /**
  2237. * bnx2x_get_tx_only_flags - Return common flags
  2238. *
  2239. * @bp device handle
  2240. * @fp queue handle
  2241. * @zero_stats TRUE if statistics zeroing is needed
  2242. *
  2243. * Return the flags that are common for the Tx-only and not normal connections.
  2244. */
  2245. static inline unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
  2246. struct bnx2x_fastpath *fp,
  2247. bool zero_stats)
  2248. {
  2249. unsigned long flags = 0;
  2250. /* PF driver will always initialize the Queue to an ACTIVE state */
  2251. __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
  2252. /* tx only connections collect statistics (on the same index as the
  2253. * parent connection). The statistics are zeroed when the parent
  2254. * connection is initialized.
  2255. */
  2256. if (stat_counter_valid(bp, fp)) {
  2257. __set_bit(BNX2X_Q_FLG_STATS, &flags);
  2258. if (zero_stats)
  2259. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
  2260. }
  2261. return flags;
  2262. }
  2263. static inline unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
  2264. struct bnx2x_fastpath *fp,
  2265. bool leading)
  2266. {
  2267. unsigned long flags = 0;
  2268. /* calculate other queue flags */
  2269. if (IS_MF_SD(bp))
  2270. __set_bit(BNX2X_Q_FLG_OV, &flags);
  2271. if (IS_FCOE_FP(fp))
  2272. __set_bit(BNX2X_Q_FLG_FCOE, &flags);
  2273. if (!fp->disable_tpa) {
  2274. __set_bit(BNX2X_Q_FLG_TPA, &flags);
  2275. __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
  2276. }
  2277. if (leading) {
  2278. __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
  2279. __set_bit(BNX2X_Q_FLG_MCAST, &flags);
  2280. }
  2281. /* Always set HW VLAN stripping */
  2282. __set_bit(BNX2X_Q_FLG_VLAN, &flags);
  2283. return flags | bnx2x_get_common_flags(bp, fp, true);
  2284. }
  2285. static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
  2286. struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
  2287. u8 cos)
  2288. {
  2289. gen_init->stat_id = bnx2x_stats_id(fp);
  2290. gen_init->spcl_id = fp->cl_id;
  2291. /* Always use mini-jumbo MTU for FCoE L2 ring */
  2292. if (IS_FCOE_FP(fp))
  2293. gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
  2294. else
  2295. gen_init->mtu = bp->dev->mtu;
  2296. gen_init->cos = cos;
  2297. }
  2298. static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
  2299. struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
  2300. struct bnx2x_rxq_setup_params *rxq_init)
  2301. {
  2302. u8 max_sge = 0;
  2303. u16 sge_sz = 0;
  2304. u16 tpa_agg_size = 0;
  2305. if (!fp->disable_tpa) {
  2306. pause->sge_th_lo = SGE_TH_LO(bp);
  2307. pause->sge_th_hi = SGE_TH_HI(bp);
  2308. /* validate SGE ring has enough to cross high threshold */
  2309. WARN_ON(bp->dropless_fc &&
  2310. pause->sge_th_hi + FW_PREFETCH_CNT >
  2311. MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
  2312. tpa_agg_size = min_t(u32,
  2313. (min_t(u32, 8, MAX_SKB_FRAGS) *
  2314. SGE_PAGE_SIZE * PAGES_PER_SGE), 0xffff);
  2315. max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
  2316. SGE_PAGE_SHIFT;
  2317. max_sge = ((max_sge + PAGES_PER_SGE - 1) &
  2318. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  2319. sge_sz = (u16)min_t(u32, SGE_PAGE_SIZE * PAGES_PER_SGE,
  2320. 0xffff);
  2321. }
  2322. /* pause - not for e1 */
  2323. if (!CHIP_IS_E1(bp)) {
  2324. pause->bd_th_lo = BD_TH_LO(bp);
  2325. pause->bd_th_hi = BD_TH_HI(bp);
  2326. pause->rcq_th_lo = RCQ_TH_LO(bp);
  2327. pause->rcq_th_hi = RCQ_TH_HI(bp);
  2328. /*
  2329. * validate that rings have enough entries to cross
  2330. * high thresholds
  2331. */
  2332. WARN_ON(bp->dropless_fc &&
  2333. pause->bd_th_hi + FW_PREFETCH_CNT >
  2334. bp->rx_ring_size);
  2335. WARN_ON(bp->dropless_fc &&
  2336. pause->rcq_th_hi + FW_PREFETCH_CNT >
  2337. NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
  2338. pause->pri_map = 1;
  2339. }
  2340. /* rxq setup */
  2341. rxq_init->dscr_map = fp->rx_desc_mapping;
  2342. rxq_init->sge_map = fp->rx_sge_mapping;
  2343. rxq_init->rcq_map = fp->rx_comp_mapping;
  2344. rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  2345. /* This should be a maximum number of data bytes that may be
  2346. * placed on the BD (not including paddings).
  2347. */
  2348. rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN -
  2349. IP_HEADER_ALIGNMENT_PADDING;
  2350. rxq_init->cl_qzone_id = fp->cl_qzone_id;
  2351. rxq_init->tpa_agg_sz = tpa_agg_size;
  2352. rxq_init->sge_buf_sz = sge_sz;
  2353. rxq_init->max_sges_pkt = max_sge;
  2354. rxq_init->rss_engine_id = BP_FUNC(bp);
  2355. /* Maximum number or simultaneous TPA aggregation for this Queue.
  2356. *
  2357. * For PF Clients it should be the maximum avaliable number.
  2358. * VF driver(s) may want to define it to a smaller value.
  2359. */
  2360. rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
  2361. rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  2362. rxq_init->fw_sb_id = fp->fw_sb_id;
  2363. if (IS_FCOE_FP(fp))
  2364. rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
  2365. else
  2366. rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  2367. }
  2368. static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
  2369. struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
  2370. u8 cos)
  2371. {
  2372. txq_init->dscr_map = fp->txdata[cos].tx_desc_mapping;
  2373. txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
  2374. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
  2375. txq_init->fw_sb_id = fp->fw_sb_id;
  2376. /*
  2377. * set the tss leading client id for TX classfication ==
  2378. * leading RSS client id
  2379. */
  2380. txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
  2381. if (IS_FCOE_FP(fp)) {
  2382. txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
  2383. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
  2384. }
  2385. }
  2386. static void bnx2x_pf_init(struct bnx2x *bp)
  2387. {
  2388. struct bnx2x_func_init_params func_init = {0};
  2389. struct event_ring_data eq_data = { {0} };
  2390. u16 flags;
  2391. if (!CHIP_IS_E1x(bp)) {
  2392. /* reset IGU PF statistics: MSIX + ATTN */
  2393. /* PF */
  2394. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2395. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2396. (CHIP_MODE_IS_4_PORT(bp) ?
  2397. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2398. /* ATTN */
  2399. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2400. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2401. BNX2X_IGU_STAS_MSG_PF_CNT*4 +
  2402. (CHIP_MODE_IS_4_PORT(bp) ?
  2403. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2404. }
  2405. /* function setup flags */
  2406. flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
  2407. /* This flag is relevant for E1x only.
  2408. * E2 doesn't have a TPA configuration in a function level.
  2409. */
  2410. flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
  2411. func_init.func_flgs = flags;
  2412. func_init.pf_id = BP_FUNC(bp);
  2413. func_init.func_id = BP_FUNC(bp);
  2414. func_init.spq_map = bp->spq_mapping;
  2415. func_init.spq_prod = bp->spq_prod_idx;
  2416. bnx2x_func_init(bp, &func_init);
  2417. memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
  2418. /*
  2419. * Congestion management values depend on the link rate
  2420. * There is no active link so initial link rate is set to 10 Gbps.
  2421. * When the link comes up The congestion management values are
  2422. * re-calculated according to the actual link rate.
  2423. */
  2424. bp->link_vars.line_speed = SPEED_10000;
  2425. bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
  2426. /* Only the PMF sets the HW */
  2427. if (bp->port.pmf)
  2428. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2429. /* init Event Queue */
  2430. eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
  2431. eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
  2432. eq_data.producer = bp->eq_prod;
  2433. eq_data.index_id = HC_SP_INDEX_EQ_CONS;
  2434. eq_data.sb_id = DEF_SB_ID;
  2435. storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
  2436. }
  2437. static void bnx2x_e1h_disable(struct bnx2x *bp)
  2438. {
  2439. int port = BP_PORT(bp);
  2440. bnx2x_tx_disable(bp);
  2441. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  2442. }
  2443. static void bnx2x_e1h_enable(struct bnx2x *bp)
  2444. {
  2445. int port = BP_PORT(bp);
  2446. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  2447. /* Tx queue should be only reenabled */
  2448. netif_tx_wake_all_queues(bp->dev);
  2449. /*
  2450. * Should not call netif_carrier_on since it will be called if the link
  2451. * is up when checking for link state
  2452. */
  2453. }
  2454. /* called due to MCP event (on pmf):
  2455. * reread new bandwidth configuration
  2456. * configure FW
  2457. * notify others function about the change
  2458. */
  2459. static inline void bnx2x_config_mf_bw(struct bnx2x *bp)
  2460. {
  2461. if (bp->link_vars.link_up) {
  2462. bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
  2463. bnx2x_link_sync_notify(bp);
  2464. }
  2465. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2466. }
  2467. static inline void bnx2x_set_mf_bw(struct bnx2x *bp)
  2468. {
  2469. bnx2x_config_mf_bw(bp);
  2470. bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
  2471. }
  2472. static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
  2473. {
  2474. DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
  2475. if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
  2476. /*
  2477. * This is the only place besides the function initialization
  2478. * where the bp->flags can change so it is done without any
  2479. * locks
  2480. */
  2481. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2482. DP(NETIF_MSG_IFDOWN, "mf_cfg function disabled\n");
  2483. bp->flags |= MF_FUNC_DIS;
  2484. bnx2x_e1h_disable(bp);
  2485. } else {
  2486. DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
  2487. bp->flags &= ~MF_FUNC_DIS;
  2488. bnx2x_e1h_enable(bp);
  2489. }
  2490. dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
  2491. }
  2492. if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
  2493. bnx2x_config_mf_bw(bp);
  2494. dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
  2495. }
  2496. /* Report results to MCP */
  2497. if (dcc_event)
  2498. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
  2499. else
  2500. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
  2501. }
  2502. /* must be called under the spq lock */
  2503. static inline struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
  2504. {
  2505. struct eth_spe *next_spe = bp->spq_prod_bd;
  2506. if (bp->spq_prod_bd == bp->spq_last_bd) {
  2507. bp->spq_prod_bd = bp->spq;
  2508. bp->spq_prod_idx = 0;
  2509. DP(NETIF_MSG_TIMER, "end of spq\n");
  2510. } else {
  2511. bp->spq_prod_bd++;
  2512. bp->spq_prod_idx++;
  2513. }
  2514. return next_spe;
  2515. }
  2516. /* must be called under the spq lock */
  2517. static inline void bnx2x_sp_prod_update(struct bnx2x *bp)
  2518. {
  2519. int func = BP_FUNC(bp);
  2520. /*
  2521. * Make sure that BD data is updated before writing the producer:
  2522. * BD data is written to the memory, the producer is read from the
  2523. * memory, thus we need a full memory barrier to ensure the ordering.
  2524. */
  2525. mb();
  2526. REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
  2527. bp->spq_prod_idx);
  2528. mmiowb();
  2529. }
  2530. /**
  2531. * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
  2532. *
  2533. * @cmd: command to check
  2534. * @cmd_type: command type
  2535. */
  2536. static inline bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
  2537. {
  2538. if ((cmd_type == NONE_CONNECTION_TYPE) ||
  2539. (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
  2540. (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
  2541. (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
  2542. (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
  2543. (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
  2544. (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
  2545. return true;
  2546. else
  2547. return false;
  2548. }
  2549. /**
  2550. * bnx2x_sp_post - place a single command on an SP ring
  2551. *
  2552. * @bp: driver handle
  2553. * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
  2554. * @cid: SW CID the command is related to
  2555. * @data_hi: command private data address (high 32 bits)
  2556. * @data_lo: command private data address (low 32 bits)
  2557. * @cmd_type: command type (e.g. NONE, ETH)
  2558. *
  2559. * SP data is handled as if it's always an address pair, thus data fields are
  2560. * not swapped to little endian in upper functions. Instead this function swaps
  2561. * data as if it's two u32 fields.
  2562. */
  2563. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  2564. u32 data_hi, u32 data_lo, int cmd_type)
  2565. {
  2566. struct eth_spe *spe;
  2567. u16 type;
  2568. bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
  2569. #ifdef BNX2X_STOP_ON_ERROR
  2570. if (unlikely(bp->panic))
  2571. return -EIO;
  2572. #endif
  2573. spin_lock_bh(&bp->spq_lock);
  2574. if (common) {
  2575. if (!atomic_read(&bp->eq_spq_left)) {
  2576. BNX2X_ERR("BUG! EQ ring full!\n");
  2577. spin_unlock_bh(&bp->spq_lock);
  2578. bnx2x_panic();
  2579. return -EBUSY;
  2580. }
  2581. } else if (!atomic_read(&bp->cq_spq_left)) {
  2582. BNX2X_ERR("BUG! SPQ ring full!\n");
  2583. spin_unlock_bh(&bp->spq_lock);
  2584. bnx2x_panic();
  2585. return -EBUSY;
  2586. }
  2587. spe = bnx2x_sp_get_next(bp);
  2588. /* CID needs port number to be encoded int it */
  2589. spe->hdr.conn_and_cmd_data =
  2590. cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
  2591. HW_CID(bp, cid));
  2592. type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
  2593. type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
  2594. SPE_HDR_FUNCTION_ID);
  2595. spe->hdr.type = cpu_to_le16(type);
  2596. spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
  2597. spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
  2598. /*
  2599. * It's ok if the actual decrement is issued towards the memory
  2600. * somewhere between the spin_lock and spin_unlock. Thus no
  2601. * more explict memory barrier is needed.
  2602. */
  2603. if (common)
  2604. atomic_dec(&bp->eq_spq_left);
  2605. else
  2606. atomic_dec(&bp->cq_spq_left);
  2607. DP(BNX2X_MSG_SP/*NETIF_MSG_TIMER*/,
  2608. "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) "
  2609. "type(0x%x) left (CQ, EQ) (%x,%x)\n",
  2610. bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
  2611. (u32)(U64_LO(bp->spq_mapping) +
  2612. (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
  2613. HW_CID(bp, cid), data_hi, data_lo, type,
  2614. atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
  2615. bnx2x_sp_prod_update(bp);
  2616. spin_unlock_bh(&bp->spq_lock);
  2617. return 0;
  2618. }
  2619. /* acquire split MCP access lock register */
  2620. static int bnx2x_acquire_alr(struct bnx2x *bp)
  2621. {
  2622. u32 j, val;
  2623. int rc = 0;
  2624. might_sleep();
  2625. for (j = 0; j < 1000; j++) {
  2626. val = (1UL << 31);
  2627. REG_WR(bp, GRCBASE_MCP + 0x9c, val);
  2628. val = REG_RD(bp, GRCBASE_MCP + 0x9c);
  2629. if (val & (1L << 31))
  2630. break;
  2631. msleep(5);
  2632. }
  2633. if (!(val & (1L << 31))) {
  2634. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  2635. rc = -EBUSY;
  2636. }
  2637. return rc;
  2638. }
  2639. /* release split MCP access lock register */
  2640. static void bnx2x_release_alr(struct bnx2x *bp)
  2641. {
  2642. REG_WR(bp, GRCBASE_MCP + 0x9c, 0);
  2643. }
  2644. #define BNX2X_DEF_SB_ATT_IDX 0x0001
  2645. #define BNX2X_DEF_SB_IDX 0x0002
  2646. static inline u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  2647. {
  2648. struct host_sp_status_block *def_sb = bp->def_status_blk;
  2649. u16 rc = 0;
  2650. barrier(); /* status block is written to by the chip */
  2651. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  2652. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  2653. rc |= BNX2X_DEF_SB_ATT_IDX;
  2654. }
  2655. if (bp->def_idx != def_sb->sp_sb.running_index) {
  2656. bp->def_idx = def_sb->sp_sb.running_index;
  2657. rc |= BNX2X_DEF_SB_IDX;
  2658. }
  2659. /* Do not reorder: indecies reading should complete before handling */
  2660. barrier();
  2661. return rc;
  2662. }
  2663. /*
  2664. * slow path service functions
  2665. */
  2666. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  2667. {
  2668. int port = BP_PORT(bp);
  2669. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  2670. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  2671. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  2672. NIG_REG_MASK_INTERRUPT_PORT0;
  2673. u32 aeu_mask;
  2674. u32 nig_mask = 0;
  2675. u32 reg_addr;
  2676. if (bp->attn_state & asserted)
  2677. BNX2X_ERR("IGU ERROR\n");
  2678. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  2679. aeu_mask = REG_RD(bp, aeu_addr);
  2680. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  2681. aeu_mask, asserted);
  2682. aeu_mask &= ~(asserted & 0x3ff);
  2683. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  2684. REG_WR(bp, aeu_addr, aeu_mask);
  2685. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  2686. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  2687. bp->attn_state |= asserted;
  2688. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  2689. if (asserted & ATTN_HARD_WIRED_MASK) {
  2690. if (asserted & ATTN_NIG_FOR_FUNC) {
  2691. bnx2x_acquire_phy_lock(bp);
  2692. /* save nig interrupt mask */
  2693. nig_mask = REG_RD(bp, nig_int_mask_addr);
  2694. /* If nig_mask is not set, no need to call the update
  2695. * function.
  2696. */
  2697. if (nig_mask) {
  2698. REG_WR(bp, nig_int_mask_addr, 0);
  2699. bnx2x_link_attn(bp);
  2700. }
  2701. /* handle unicore attn? */
  2702. }
  2703. if (asserted & ATTN_SW_TIMER_4_FUNC)
  2704. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  2705. if (asserted & GPIO_2_FUNC)
  2706. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  2707. if (asserted & GPIO_3_FUNC)
  2708. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  2709. if (asserted & GPIO_4_FUNC)
  2710. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  2711. if (port == 0) {
  2712. if (asserted & ATTN_GENERAL_ATTN_1) {
  2713. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  2714. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  2715. }
  2716. if (asserted & ATTN_GENERAL_ATTN_2) {
  2717. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  2718. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  2719. }
  2720. if (asserted & ATTN_GENERAL_ATTN_3) {
  2721. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  2722. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  2723. }
  2724. } else {
  2725. if (asserted & ATTN_GENERAL_ATTN_4) {
  2726. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  2727. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  2728. }
  2729. if (asserted & ATTN_GENERAL_ATTN_5) {
  2730. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  2731. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  2732. }
  2733. if (asserted & ATTN_GENERAL_ATTN_6) {
  2734. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  2735. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  2736. }
  2737. }
  2738. } /* if hardwired */
  2739. if (bp->common.int_block == INT_BLOCK_HC)
  2740. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  2741. COMMAND_REG_ATTN_BITS_SET);
  2742. else
  2743. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
  2744. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
  2745. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  2746. REG_WR(bp, reg_addr, asserted);
  2747. /* now set back the mask */
  2748. if (asserted & ATTN_NIG_FOR_FUNC) {
  2749. REG_WR(bp, nig_int_mask_addr, nig_mask);
  2750. bnx2x_release_phy_lock(bp);
  2751. }
  2752. }
  2753. static inline void bnx2x_fan_failure(struct bnx2x *bp)
  2754. {
  2755. int port = BP_PORT(bp);
  2756. u32 ext_phy_config;
  2757. /* mark the failure */
  2758. ext_phy_config =
  2759. SHMEM_RD(bp,
  2760. dev_info.port_hw_config[port].external_phy_config);
  2761. ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  2762. ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  2763. SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
  2764. ext_phy_config);
  2765. /* log the failure */
  2766. netdev_err(bp->dev, "Fan Failure on Network Controller has caused"
  2767. " the driver to shutdown the card to prevent permanent"
  2768. " damage. Please contact OEM Support for assistance\n");
  2769. }
  2770. static inline void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  2771. {
  2772. int port = BP_PORT(bp);
  2773. int reg_offset;
  2774. u32 val;
  2775. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  2776. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  2777. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  2778. val = REG_RD(bp, reg_offset);
  2779. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  2780. REG_WR(bp, reg_offset, val);
  2781. BNX2X_ERR("SPIO5 hw attention\n");
  2782. /* Fan failure attention */
  2783. bnx2x_hw_reset_phy(&bp->link_params);
  2784. bnx2x_fan_failure(bp);
  2785. }
  2786. if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
  2787. bnx2x_acquire_phy_lock(bp);
  2788. bnx2x_handle_module_detect_int(&bp->link_params);
  2789. bnx2x_release_phy_lock(bp);
  2790. }
  2791. if (attn & HW_INTERRUT_ASSERT_SET_0) {
  2792. val = REG_RD(bp, reg_offset);
  2793. val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
  2794. REG_WR(bp, reg_offset, val);
  2795. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  2796. (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
  2797. bnx2x_panic();
  2798. }
  2799. }
  2800. static inline void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  2801. {
  2802. u32 val;
  2803. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  2804. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  2805. BNX2X_ERR("DB hw attention 0x%x\n", val);
  2806. /* DORQ discard attention */
  2807. if (val & 0x2)
  2808. BNX2X_ERR("FATAL error from DORQ\n");
  2809. }
  2810. if (attn & HW_INTERRUT_ASSERT_SET_1) {
  2811. int port = BP_PORT(bp);
  2812. int reg_offset;
  2813. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  2814. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  2815. val = REG_RD(bp, reg_offset);
  2816. val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
  2817. REG_WR(bp, reg_offset, val);
  2818. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  2819. (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
  2820. bnx2x_panic();
  2821. }
  2822. }
  2823. static inline void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  2824. {
  2825. u32 val;
  2826. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  2827. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  2828. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  2829. /* CFC error attention */
  2830. if (val & 0x2)
  2831. BNX2X_ERR("FATAL error from CFC\n");
  2832. }
  2833. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  2834. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  2835. BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
  2836. /* RQ_USDMDP_FIFO_OVERFLOW */
  2837. if (val & 0x18000)
  2838. BNX2X_ERR("FATAL error from PXP\n");
  2839. if (!CHIP_IS_E1x(bp)) {
  2840. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
  2841. BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
  2842. }
  2843. }
  2844. if (attn & HW_INTERRUT_ASSERT_SET_2) {
  2845. int port = BP_PORT(bp);
  2846. int reg_offset;
  2847. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  2848. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  2849. val = REG_RD(bp, reg_offset);
  2850. val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
  2851. REG_WR(bp, reg_offset, val);
  2852. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  2853. (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
  2854. bnx2x_panic();
  2855. }
  2856. }
  2857. static inline void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  2858. {
  2859. u32 val;
  2860. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  2861. if (attn & BNX2X_PMF_LINK_ASSERT) {
  2862. int func = BP_FUNC(bp);
  2863. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  2864. bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
  2865. func_mf_config[BP_ABS_FUNC(bp)].config);
  2866. val = SHMEM_RD(bp,
  2867. func_mb[BP_FW_MB_IDX(bp)].drv_status);
  2868. if (val & DRV_STATUS_DCC_EVENT_MASK)
  2869. bnx2x_dcc_event(bp,
  2870. (val & DRV_STATUS_DCC_EVENT_MASK));
  2871. if (val & DRV_STATUS_SET_MF_BW)
  2872. bnx2x_set_mf_bw(bp);
  2873. if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
  2874. bnx2x_pmf_update(bp);
  2875. if (bp->port.pmf &&
  2876. (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
  2877. bp->dcbx_enabled > 0)
  2878. /* start dcbx state machine */
  2879. bnx2x_dcbx_set_params(bp,
  2880. BNX2X_DCBX_STATE_NEG_RECEIVED);
  2881. if (bp->link_vars.periodic_flags &
  2882. PERIODIC_FLAGS_LINK_EVENT) {
  2883. /* sync with link */
  2884. bnx2x_acquire_phy_lock(bp);
  2885. bp->link_vars.periodic_flags &=
  2886. ~PERIODIC_FLAGS_LINK_EVENT;
  2887. bnx2x_release_phy_lock(bp);
  2888. if (IS_MF(bp))
  2889. bnx2x_link_sync_notify(bp);
  2890. bnx2x_link_report(bp);
  2891. }
  2892. /* Always call it here: bnx2x_link_report() will
  2893. * prevent the link indication duplication.
  2894. */
  2895. bnx2x__link_status_update(bp);
  2896. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  2897. BNX2X_ERR("MC assert!\n");
  2898. bnx2x_mc_assert(bp);
  2899. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  2900. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  2901. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  2902. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  2903. bnx2x_panic();
  2904. } else if (attn & BNX2X_MCP_ASSERT) {
  2905. BNX2X_ERR("MCP assert!\n");
  2906. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  2907. bnx2x_fw_dump(bp);
  2908. } else
  2909. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  2910. }
  2911. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  2912. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  2913. if (attn & BNX2X_GRC_TIMEOUT) {
  2914. val = CHIP_IS_E1(bp) ? 0 :
  2915. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
  2916. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  2917. }
  2918. if (attn & BNX2X_GRC_RSV) {
  2919. val = CHIP_IS_E1(bp) ? 0 :
  2920. REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
  2921. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  2922. }
  2923. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  2924. }
  2925. }
  2926. /*
  2927. * Bits map:
  2928. * 0-7 - Engine0 load counter.
  2929. * 8-15 - Engine1 load counter.
  2930. * 16 - Engine0 RESET_IN_PROGRESS bit.
  2931. * 17 - Engine1 RESET_IN_PROGRESS bit.
  2932. * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
  2933. * on the engine
  2934. * 19 - Engine1 ONE_IS_LOADED.
  2935. * 20 - Chip reset flow bit. When set none-leader must wait for both engines
  2936. * leader to complete (check for both RESET_IN_PROGRESS bits and not for
  2937. * just the one belonging to its engine).
  2938. *
  2939. */
  2940. #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
  2941. #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
  2942. #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
  2943. #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
  2944. #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
  2945. #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
  2946. #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
  2947. #define BNX2X_GLOBAL_RESET_BIT 0x00040000
  2948. /*
  2949. * Set the GLOBAL_RESET bit.
  2950. *
  2951. * Should be run under rtnl lock
  2952. */
  2953. void bnx2x_set_reset_global(struct bnx2x *bp)
  2954. {
  2955. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  2956. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
  2957. barrier();
  2958. mmiowb();
  2959. }
  2960. /*
  2961. * Clear the GLOBAL_RESET bit.
  2962. *
  2963. * Should be run under rtnl lock
  2964. */
  2965. static inline void bnx2x_clear_reset_global(struct bnx2x *bp)
  2966. {
  2967. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  2968. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
  2969. barrier();
  2970. mmiowb();
  2971. }
  2972. /*
  2973. * Checks the GLOBAL_RESET bit.
  2974. *
  2975. * should be run under rtnl lock
  2976. */
  2977. static inline bool bnx2x_reset_is_global(struct bnx2x *bp)
  2978. {
  2979. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  2980. DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
  2981. return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
  2982. }
  2983. /*
  2984. * Clear RESET_IN_PROGRESS bit for the current engine.
  2985. *
  2986. * Should be run under rtnl lock
  2987. */
  2988. static inline void bnx2x_set_reset_done(struct bnx2x *bp)
  2989. {
  2990. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  2991. u32 bit = BP_PATH(bp) ?
  2992. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  2993. /* Clear the bit */
  2994. val &= ~bit;
  2995. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  2996. barrier();
  2997. mmiowb();
  2998. }
  2999. /*
  3000. * Set RESET_IN_PROGRESS for the current engine.
  3001. *
  3002. * should be run under rtnl lock
  3003. */
  3004. void bnx2x_set_reset_in_progress(struct bnx2x *bp)
  3005. {
  3006. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3007. u32 bit = BP_PATH(bp) ?
  3008. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3009. /* Set the bit */
  3010. val |= bit;
  3011. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3012. barrier();
  3013. mmiowb();
  3014. }
  3015. /*
  3016. * Checks the RESET_IN_PROGRESS bit for the given engine.
  3017. * should be run under rtnl lock
  3018. */
  3019. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
  3020. {
  3021. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3022. u32 bit = engine ?
  3023. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3024. /* return false if bit is set */
  3025. return (val & bit) ? false : true;
  3026. }
  3027. /*
  3028. * Increment the load counter for the current engine.
  3029. *
  3030. * should be run under rtnl lock
  3031. */
  3032. void bnx2x_inc_load_cnt(struct bnx2x *bp)
  3033. {
  3034. u32 val1, val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3035. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3036. BNX2X_PATH0_LOAD_CNT_MASK;
  3037. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3038. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3039. DP(NETIF_MSG_HW, "Old GEN_REG_VAL=0x%08x\n", val);
  3040. /* get the current counter value */
  3041. val1 = (val & mask) >> shift;
  3042. /* increment... */
  3043. val1++;
  3044. /* clear the old value */
  3045. val &= ~mask;
  3046. /* set the new one */
  3047. val |= ((val1 << shift) & mask);
  3048. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3049. barrier();
  3050. mmiowb();
  3051. }
  3052. /**
  3053. * bnx2x_dec_load_cnt - decrement the load counter
  3054. *
  3055. * @bp: driver handle
  3056. *
  3057. * Should be run under rtnl lock.
  3058. * Decrements the load counter for the current engine. Returns
  3059. * the new counter value.
  3060. */
  3061. u32 bnx2x_dec_load_cnt(struct bnx2x *bp)
  3062. {
  3063. u32 val1, val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3064. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3065. BNX2X_PATH0_LOAD_CNT_MASK;
  3066. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3067. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3068. DP(NETIF_MSG_HW, "Old GEN_REG_VAL=0x%08x\n", val);
  3069. /* get the current counter value */
  3070. val1 = (val & mask) >> shift;
  3071. /* decrement... */
  3072. val1--;
  3073. /* clear the old value */
  3074. val &= ~mask;
  3075. /* set the new one */
  3076. val |= ((val1 << shift) & mask);
  3077. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3078. barrier();
  3079. mmiowb();
  3080. return val1;
  3081. }
  3082. /*
  3083. * Read the load counter for the current engine.
  3084. *
  3085. * should be run under rtnl lock
  3086. */
  3087. static inline u32 bnx2x_get_load_cnt(struct bnx2x *bp, int engine)
  3088. {
  3089. u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
  3090. BNX2X_PATH0_LOAD_CNT_MASK);
  3091. u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3092. BNX2X_PATH0_LOAD_CNT_SHIFT);
  3093. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3094. DP(NETIF_MSG_HW, "GLOB_REG=0x%08x\n", val);
  3095. val = (val & mask) >> shift;
  3096. DP(NETIF_MSG_HW, "load_cnt for engine %d = %d\n", engine, val);
  3097. return val;
  3098. }
  3099. /*
  3100. * Reset the load counter for the current engine.
  3101. *
  3102. * should be run under rtnl lock
  3103. */
  3104. static inline void bnx2x_clear_load_cnt(struct bnx2x *bp)
  3105. {
  3106. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3107. u32 mask = (BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3108. BNX2X_PATH0_LOAD_CNT_MASK);
  3109. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~mask));
  3110. }
  3111. static inline void _print_next_block(int idx, const char *blk)
  3112. {
  3113. pr_cont("%s%s", idx ? ", " : "", blk);
  3114. }
  3115. static inline int bnx2x_check_blocks_with_parity0(u32 sig, int par_num,
  3116. bool print)
  3117. {
  3118. int i = 0;
  3119. u32 cur_bit = 0;
  3120. for (i = 0; sig; i++) {
  3121. cur_bit = ((u32)0x1 << i);
  3122. if (sig & cur_bit) {
  3123. switch (cur_bit) {
  3124. case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
  3125. if (print)
  3126. _print_next_block(par_num++, "BRB");
  3127. break;
  3128. case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
  3129. if (print)
  3130. _print_next_block(par_num++, "PARSER");
  3131. break;
  3132. case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
  3133. if (print)
  3134. _print_next_block(par_num++, "TSDM");
  3135. break;
  3136. case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
  3137. if (print)
  3138. _print_next_block(par_num++,
  3139. "SEARCHER");
  3140. break;
  3141. case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
  3142. if (print)
  3143. _print_next_block(par_num++, "TCM");
  3144. break;
  3145. case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
  3146. if (print)
  3147. _print_next_block(par_num++, "TSEMI");
  3148. break;
  3149. case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
  3150. if (print)
  3151. _print_next_block(par_num++, "XPB");
  3152. break;
  3153. }
  3154. /* Clear the bit */
  3155. sig &= ~cur_bit;
  3156. }
  3157. }
  3158. return par_num;
  3159. }
  3160. static inline int bnx2x_check_blocks_with_parity1(u32 sig, int par_num,
  3161. bool *global, bool print)
  3162. {
  3163. int i = 0;
  3164. u32 cur_bit = 0;
  3165. for (i = 0; sig; i++) {
  3166. cur_bit = ((u32)0x1 << i);
  3167. if (sig & cur_bit) {
  3168. switch (cur_bit) {
  3169. case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
  3170. if (print)
  3171. _print_next_block(par_num++, "PBF");
  3172. break;
  3173. case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
  3174. if (print)
  3175. _print_next_block(par_num++, "QM");
  3176. break;
  3177. case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
  3178. if (print)
  3179. _print_next_block(par_num++, "TM");
  3180. break;
  3181. case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
  3182. if (print)
  3183. _print_next_block(par_num++, "XSDM");
  3184. break;
  3185. case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
  3186. if (print)
  3187. _print_next_block(par_num++, "XCM");
  3188. break;
  3189. case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
  3190. if (print)
  3191. _print_next_block(par_num++, "XSEMI");
  3192. break;
  3193. case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
  3194. if (print)
  3195. _print_next_block(par_num++,
  3196. "DOORBELLQ");
  3197. break;
  3198. case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
  3199. if (print)
  3200. _print_next_block(par_num++, "NIG");
  3201. break;
  3202. case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
  3203. if (print)
  3204. _print_next_block(par_num++,
  3205. "VAUX PCI CORE");
  3206. *global = true;
  3207. break;
  3208. case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
  3209. if (print)
  3210. _print_next_block(par_num++, "DEBUG");
  3211. break;
  3212. case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
  3213. if (print)
  3214. _print_next_block(par_num++, "USDM");
  3215. break;
  3216. case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
  3217. if (print)
  3218. _print_next_block(par_num++, "UCM");
  3219. break;
  3220. case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
  3221. if (print)
  3222. _print_next_block(par_num++, "USEMI");
  3223. break;
  3224. case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
  3225. if (print)
  3226. _print_next_block(par_num++, "UPB");
  3227. break;
  3228. case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
  3229. if (print)
  3230. _print_next_block(par_num++, "CSDM");
  3231. break;
  3232. case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
  3233. if (print)
  3234. _print_next_block(par_num++, "CCM");
  3235. break;
  3236. }
  3237. /* Clear the bit */
  3238. sig &= ~cur_bit;
  3239. }
  3240. }
  3241. return par_num;
  3242. }
  3243. static inline int bnx2x_check_blocks_with_parity2(u32 sig, int par_num,
  3244. bool print)
  3245. {
  3246. int i = 0;
  3247. u32 cur_bit = 0;
  3248. for (i = 0; sig; i++) {
  3249. cur_bit = ((u32)0x1 << i);
  3250. if (sig & cur_bit) {
  3251. switch (cur_bit) {
  3252. case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
  3253. if (print)
  3254. _print_next_block(par_num++, "CSEMI");
  3255. break;
  3256. case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
  3257. if (print)
  3258. _print_next_block(par_num++, "PXP");
  3259. break;
  3260. case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
  3261. if (print)
  3262. _print_next_block(par_num++,
  3263. "PXPPCICLOCKCLIENT");
  3264. break;
  3265. case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
  3266. if (print)
  3267. _print_next_block(par_num++, "CFC");
  3268. break;
  3269. case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
  3270. if (print)
  3271. _print_next_block(par_num++, "CDU");
  3272. break;
  3273. case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
  3274. if (print)
  3275. _print_next_block(par_num++, "DMAE");
  3276. break;
  3277. case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
  3278. if (print)
  3279. _print_next_block(par_num++, "IGU");
  3280. break;
  3281. case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
  3282. if (print)
  3283. _print_next_block(par_num++, "MISC");
  3284. break;
  3285. }
  3286. /* Clear the bit */
  3287. sig &= ~cur_bit;
  3288. }
  3289. }
  3290. return par_num;
  3291. }
  3292. static inline int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
  3293. bool *global, bool print)
  3294. {
  3295. int i = 0;
  3296. u32 cur_bit = 0;
  3297. for (i = 0; sig; i++) {
  3298. cur_bit = ((u32)0x1 << i);
  3299. if (sig & cur_bit) {
  3300. switch (cur_bit) {
  3301. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
  3302. if (print)
  3303. _print_next_block(par_num++, "MCP ROM");
  3304. *global = true;
  3305. break;
  3306. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
  3307. if (print)
  3308. _print_next_block(par_num++,
  3309. "MCP UMP RX");
  3310. *global = true;
  3311. break;
  3312. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
  3313. if (print)
  3314. _print_next_block(par_num++,
  3315. "MCP UMP TX");
  3316. *global = true;
  3317. break;
  3318. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
  3319. if (print)
  3320. _print_next_block(par_num++,
  3321. "MCP SCPAD");
  3322. *global = true;
  3323. break;
  3324. }
  3325. /* Clear the bit */
  3326. sig &= ~cur_bit;
  3327. }
  3328. }
  3329. return par_num;
  3330. }
  3331. static inline int bnx2x_check_blocks_with_parity4(u32 sig, int par_num,
  3332. bool print)
  3333. {
  3334. int i = 0;
  3335. u32 cur_bit = 0;
  3336. for (i = 0; sig; i++) {
  3337. cur_bit = ((u32)0x1 << i);
  3338. if (sig & cur_bit) {
  3339. switch (cur_bit) {
  3340. case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
  3341. if (print)
  3342. _print_next_block(par_num++, "PGLUE_B");
  3343. break;
  3344. case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
  3345. if (print)
  3346. _print_next_block(par_num++, "ATC");
  3347. break;
  3348. }
  3349. /* Clear the bit */
  3350. sig &= ~cur_bit;
  3351. }
  3352. }
  3353. return par_num;
  3354. }
  3355. static inline bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
  3356. u32 *sig)
  3357. {
  3358. if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  3359. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  3360. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  3361. (sig[3] & HW_PRTY_ASSERT_SET_3) ||
  3362. (sig[4] & HW_PRTY_ASSERT_SET_4)) {
  3363. int par_num = 0;
  3364. DP(NETIF_MSG_HW, "Was parity error: HW block parity attention: "
  3365. "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x "
  3366. "[4]:0x%08x\n",
  3367. sig[0] & HW_PRTY_ASSERT_SET_0,
  3368. sig[1] & HW_PRTY_ASSERT_SET_1,
  3369. sig[2] & HW_PRTY_ASSERT_SET_2,
  3370. sig[3] & HW_PRTY_ASSERT_SET_3,
  3371. sig[4] & HW_PRTY_ASSERT_SET_4);
  3372. if (print)
  3373. netdev_err(bp->dev,
  3374. "Parity errors detected in blocks: ");
  3375. par_num = bnx2x_check_blocks_with_parity0(
  3376. sig[0] & HW_PRTY_ASSERT_SET_0, par_num, print);
  3377. par_num = bnx2x_check_blocks_with_parity1(
  3378. sig[1] & HW_PRTY_ASSERT_SET_1, par_num, global, print);
  3379. par_num = bnx2x_check_blocks_with_parity2(
  3380. sig[2] & HW_PRTY_ASSERT_SET_2, par_num, print);
  3381. par_num = bnx2x_check_blocks_with_parity3(
  3382. sig[3] & HW_PRTY_ASSERT_SET_3, par_num, global, print);
  3383. par_num = bnx2x_check_blocks_with_parity4(
  3384. sig[4] & HW_PRTY_ASSERT_SET_4, par_num, print);
  3385. if (print)
  3386. pr_cont("\n");
  3387. return true;
  3388. } else
  3389. return false;
  3390. }
  3391. /**
  3392. * bnx2x_chk_parity_attn - checks for parity attentions.
  3393. *
  3394. * @bp: driver handle
  3395. * @global: true if there was a global attention
  3396. * @print: show parity attention in syslog
  3397. */
  3398. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
  3399. {
  3400. struct attn_route attn = { {0} };
  3401. int port = BP_PORT(bp);
  3402. attn.sig[0] = REG_RD(bp,
  3403. MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
  3404. port*4);
  3405. attn.sig[1] = REG_RD(bp,
  3406. MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
  3407. port*4);
  3408. attn.sig[2] = REG_RD(bp,
  3409. MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
  3410. port*4);
  3411. attn.sig[3] = REG_RD(bp,
  3412. MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
  3413. port*4);
  3414. if (!CHIP_IS_E1x(bp))
  3415. attn.sig[4] = REG_RD(bp,
  3416. MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
  3417. port*4);
  3418. return bnx2x_parity_attn(bp, global, print, attn.sig);
  3419. }
  3420. static inline void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
  3421. {
  3422. u32 val;
  3423. if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
  3424. val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
  3425. BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
  3426. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
  3427. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
  3428. "ADDRESS_ERROR\n");
  3429. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
  3430. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
  3431. "INCORRECT_RCV_BEHAVIOR\n");
  3432. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
  3433. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
  3434. "WAS_ERROR_ATTN\n");
  3435. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
  3436. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
  3437. "VF_LENGTH_VIOLATION_ATTN\n");
  3438. if (val &
  3439. PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
  3440. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
  3441. "VF_GRC_SPACE_VIOLATION_ATTN\n");
  3442. if (val &
  3443. PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
  3444. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
  3445. "VF_MSIX_BAR_VIOLATION_ATTN\n");
  3446. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
  3447. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
  3448. "TCPL_ERROR_ATTN\n");
  3449. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
  3450. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
  3451. "TCPL_IN_TWO_RCBS_ATTN\n");
  3452. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
  3453. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
  3454. "CSSNOOP_FIFO_OVERFLOW\n");
  3455. }
  3456. if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
  3457. val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
  3458. BNX2X_ERR("ATC hw attention 0x%x\n", val);
  3459. if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
  3460. BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
  3461. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
  3462. BNX2X_ERR("ATC_ATC_INT_STS_REG"
  3463. "_ATC_TCPL_TO_NOT_PEND\n");
  3464. if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
  3465. BNX2X_ERR("ATC_ATC_INT_STS_REG_"
  3466. "ATC_GPA_MULTIPLE_HITS\n");
  3467. if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
  3468. BNX2X_ERR("ATC_ATC_INT_STS_REG_"
  3469. "ATC_RCPL_TO_EMPTY_CNT\n");
  3470. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
  3471. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
  3472. if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
  3473. BNX2X_ERR("ATC_ATC_INT_STS_REG_"
  3474. "ATC_IREQ_LESS_THAN_STU\n");
  3475. }
  3476. if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3477. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
  3478. BNX2X_ERR("FATAL parity attention set4 0x%x\n",
  3479. (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3480. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
  3481. }
  3482. }
  3483. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  3484. {
  3485. struct attn_route attn, *group_mask;
  3486. int port = BP_PORT(bp);
  3487. int index;
  3488. u32 reg_addr;
  3489. u32 val;
  3490. u32 aeu_mask;
  3491. bool global = false;
  3492. /* need to take HW lock because MCP or other port might also
  3493. try to handle this event */
  3494. bnx2x_acquire_alr(bp);
  3495. if (bnx2x_chk_parity_attn(bp, &global, true)) {
  3496. #ifndef BNX2X_STOP_ON_ERROR
  3497. bp->recovery_state = BNX2X_RECOVERY_INIT;
  3498. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3499. /* Disable HW interrupts */
  3500. bnx2x_int_disable(bp);
  3501. /* In case of parity errors don't handle attentions so that
  3502. * other function would "see" parity errors.
  3503. */
  3504. #else
  3505. bnx2x_panic();
  3506. #endif
  3507. bnx2x_release_alr(bp);
  3508. return;
  3509. }
  3510. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  3511. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  3512. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  3513. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  3514. if (!CHIP_IS_E1x(bp))
  3515. attn.sig[4] =
  3516. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
  3517. else
  3518. attn.sig[4] = 0;
  3519. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
  3520. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
  3521. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  3522. if (deasserted & (1 << index)) {
  3523. group_mask = &bp->attn_group[index];
  3524. DP(NETIF_MSG_HW, "group[%d]: %08x %08x "
  3525. "%08x %08x %08x\n",
  3526. index,
  3527. group_mask->sig[0], group_mask->sig[1],
  3528. group_mask->sig[2], group_mask->sig[3],
  3529. group_mask->sig[4]);
  3530. bnx2x_attn_int_deasserted4(bp,
  3531. attn.sig[4] & group_mask->sig[4]);
  3532. bnx2x_attn_int_deasserted3(bp,
  3533. attn.sig[3] & group_mask->sig[3]);
  3534. bnx2x_attn_int_deasserted1(bp,
  3535. attn.sig[1] & group_mask->sig[1]);
  3536. bnx2x_attn_int_deasserted2(bp,
  3537. attn.sig[2] & group_mask->sig[2]);
  3538. bnx2x_attn_int_deasserted0(bp,
  3539. attn.sig[0] & group_mask->sig[0]);
  3540. }
  3541. }
  3542. bnx2x_release_alr(bp);
  3543. if (bp->common.int_block == INT_BLOCK_HC)
  3544. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3545. COMMAND_REG_ATTN_BITS_CLR);
  3546. else
  3547. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
  3548. val = ~deasserted;
  3549. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
  3550. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3551. REG_WR(bp, reg_addr, val);
  3552. if (~bp->attn_state & deasserted)
  3553. BNX2X_ERR("IGU ERROR\n");
  3554. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3555. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3556. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3557. aeu_mask = REG_RD(bp, reg_addr);
  3558. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  3559. aeu_mask, deasserted);
  3560. aeu_mask |= (deasserted & 0x3ff);
  3561. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3562. REG_WR(bp, reg_addr, aeu_mask);
  3563. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3564. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3565. bp->attn_state &= ~deasserted;
  3566. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3567. }
  3568. static void bnx2x_attn_int(struct bnx2x *bp)
  3569. {
  3570. /* read local copy of bits */
  3571. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  3572. attn_bits);
  3573. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  3574. attn_bits_ack);
  3575. u32 attn_state = bp->attn_state;
  3576. /* look for changed bits */
  3577. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  3578. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  3579. DP(NETIF_MSG_HW,
  3580. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  3581. attn_bits, attn_ack, asserted, deasserted);
  3582. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  3583. BNX2X_ERR("BAD attention state\n");
  3584. /* handle bits that were raised */
  3585. if (asserted)
  3586. bnx2x_attn_int_asserted(bp, asserted);
  3587. if (deasserted)
  3588. bnx2x_attn_int_deasserted(bp, deasserted);
  3589. }
  3590. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  3591. u16 index, u8 op, u8 update)
  3592. {
  3593. u32 igu_addr = BAR_IGU_INTMEM + (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
  3594. bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
  3595. igu_addr);
  3596. }
  3597. static inline void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
  3598. {
  3599. /* No memory barriers */
  3600. storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
  3601. mmiowb(); /* keep prod updates ordered */
  3602. }
  3603. #ifdef BCM_CNIC
  3604. static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
  3605. union event_ring_elem *elem)
  3606. {
  3607. u8 err = elem->message.error;
  3608. if (!bp->cnic_eth_dev.starting_cid ||
  3609. (cid < bp->cnic_eth_dev.starting_cid &&
  3610. cid != bp->cnic_eth_dev.iscsi_l2_cid))
  3611. return 1;
  3612. DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
  3613. if (unlikely(err)) {
  3614. BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
  3615. cid);
  3616. bnx2x_panic_dump(bp);
  3617. }
  3618. bnx2x_cnic_cfc_comp(bp, cid, err);
  3619. return 0;
  3620. }
  3621. #endif
  3622. static inline void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
  3623. {
  3624. struct bnx2x_mcast_ramrod_params rparam;
  3625. int rc;
  3626. memset(&rparam, 0, sizeof(rparam));
  3627. rparam.mcast_obj = &bp->mcast_obj;
  3628. netif_addr_lock_bh(bp->dev);
  3629. /* Clear pending state for the last command */
  3630. bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
  3631. /* If there are pending mcast commands - send them */
  3632. if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
  3633. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  3634. if (rc < 0)
  3635. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  3636. rc);
  3637. }
  3638. netif_addr_unlock_bh(bp->dev);
  3639. }
  3640. static inline void bnx2x_handle_classification_eqe(struct bnx2x *bp,
  3641. union event_ring_elem *elem)
  3642. {
  3643. unsigned long ramrod_flags = 0;
  3644. int rc = 0;
  3645. u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
  3646. struct bnx2x_vlan_mac_obj *vlan_mac_obj;
  3647. /* Always push next commands out, don't wait here */
  3648. __set_bit(RAMROD_CONT, &ramrod_flags);
  3649. switch (elem->message.data.eth_event.echo >> BNX2X_SWCID_SHIFT) {
  3650. case BNX2X_FILTER_MAC_PENDING:
  3651. #ifdef BCM_CNIC
  3652. if (cid == BNX2X_ISCSI_ETH_CID)
  3653. vlan_mac_obj = &bp->iscsi_l2_mac_obj;
  3654. else
  3655. #endif
  3656. vlan_mac_obj = &bp->fp[cid].mac_obj;
  3657. break;
  3658. case BNX2X_FILTER_MCAST_PENDING:
  3659. /* This is only relevant for 57710 where multicast MACs are
  3660. * configured as unicast MACs using the same ramrod.
  3661. */
  3662. bnx2x_handle_mcast_eqe(bp);
  3663. return;
  3664. default:
  3665. BNX2X_ERR("Unsupported classification command: %d\n",
  3666. elem->message.data.eth_event.echo);
  3667. return;
  3668. }
  3669. rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
  3670. if (rc < 0)
  3671. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  3672. else if (rc > 0)
  3673. DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
  3674. }
  3675. #ifdef BCM_CNIC
  3676. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
  3677. #endif
  3678. static inline void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
  3679. {
  3680. netif_addr_lock_bh(bp->dev);
  3681. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  3682. /* Send rx_mode command again if was requested */
  3683. if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
  3684. bnx2x_set_storm_rx_mode(bp);
  3685. #ifdef BCM_CNIC
  3686. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
  3687. &bp->sp_state))
  3688. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  3689. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
  3690. &bp->sp_state))
  3691. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  3692. #endif
  3693. netif_addr_unlock_bh(bp->dev);
  3694. }
  3695. static inline struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
  3696. struct bnx2x *bp, u32 cid)
  3697. {
  3698. DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
  3699. #ifdef BCM_CNIC
  3700. if (cid == BNX2X_FCOE_ETH_CID)
  3701. return &bnx2x_fcoe(bp, q_obj);
  3702. else
  3703. #endif
  3704. return &bnx2x_fp(bp, CID_TO_FP(cid), q_obj);
  3705. }
  3706. static void bnx2x_eq_int(struct bnx2x *bp)
  3707. {
  3708. u16 hw_cons, sw_cons, sw_prod;
  3709. union event_ring_elem *elem;
  3710. u32 cid;
  3711. u8 opcode;
  3712. int spqe_cnt = 0;
  3713. struct bnx2x_queue_sp_obj *q_obj;
  3714. struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
  3715. struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
  3716. hw_cons = le16_to_cpu(*bp->eq_cons_sb);
  3717. /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
  3718. * when we get the the next-page we nned to adjust so the loop
  3719. * condition below will be met. The next element is the size of a
  3720. * regular element and hence incrementing by 1
  3721. */
  3722. if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
  3723. hw_cons++;
  3724. /* This function may never run in parallel with itself for a
  3725. * specific bp, thus there is no need in "paired" read memory
  3726. * barrier here.
  3727. */
  3728. sw_cons = bp->eq_cons;
  3729. sw_prod = bp->eq_prod;
  3730. DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
  3731. hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
  3732. for (; sw_cons != hw_cons;
  3733. sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
  3734. elem = &bp->eq_ring[EQ_DESC(sw_cons)];
  3735. cid = SW_CID(elem->message.data.cfc_del_event.cid);
  3736. opcode = elem->message.opcode;
  3737. /* handle eq element */
  3738. switch (opcode) {
  3739. case EVENT_RING_OPCODE_STAT_QUERY:
  3740. DP(NETIF_MSG_TIMER, "got statistics comp event %d\n",
  3741. bp->stats_comp++);
  3742. /* nothing to do with stats comp */
  3743. goto next_spqe;
  3744. case EVENT_RING_OPCODE_CFC_DEL:
  3745. /* handle according to cid range */
  3746. /*
  3747. * we may want to verify here that the bp state is
  3748. * HALTING
  3749. */
  3750. DP(BNX2X_MSG_SP,
  3751. "got delete ramrod for MULTI[%d]\n", cid);
  3752. #ifdef BCM_CNIC
  3753. if (!bnx2x_cnic_handle_cfc_del(bp, cid, elem))
  3754. goto next_spqe;
  3755. #endif
  3756. q_obj = bnx2x_cid_to_q_obj(bp, cid);
  3757. if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
  3758. break;
  3759. goto next_spqe;
  3760. case EVENT_RING_OPCODE_STOP_TRAFFIC:
  3761. DP(BNX2X_MSG_SP, "got STOP TRAFFIC\n");
  3762. if (f_obj->complete_cmd(bp, f_obj,
  3763. BNX2X_F_CMD_TX_STOP))
  3764. break;
  3765. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
  3766. goto next_spqe;
  3767. case EVENT_RING_OPCODE_START_TRAFFIC:
  3768. DP(BNX2X_MSG_SP, "got START TRAFFIC\n");
  3769. if (f_obj->complete_cmd(bp, f_obj,
  3770. BNX2X_F_CMD_TX_START))
  3771. break;
  3772. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
  3773. goto next_spqe;
  3774. case EVENT_RING_OPCODE_FUNCTION_START:
  3775. DP(BNX2X_MSG_SP, "got FUNC_START ramrod\n");
  3776. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
  3777. break;
  3778. goto next_spqe;
  3779. case EVENT_RING_OPCODE_FUNCTION_STOP:
  3780. DP(BNX2X_MSG_SP, "got FUNC_STOP ramrod\n");
  3781. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
  3782. break;
  3783. goto next_spqe;
  3784. }
  3785. switch (opcode | bp->state) {
  3786. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  3787. BNX2X_STATE_OPEN):
  3788. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  3789. BNX2X_STATE_OPENING_WAIT4_PORT):
  3790. cid = elem->message.data.eth_event.echo &
  3791. BNX2X_SWCID_MASK;
  3792. DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
  3793. cid);
  3794. rss_raw->clear_pending(rss_raw);
  3795. break;
  3796. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
  3797. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
  3798. case (EVENT_RING_OPCODE_SET_MAC |
  3799. BNX2X_STATE_CLOSING_WAIT4_HALT):
  3800. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  3801. BNX2X_STATE_OPEN):
  3802. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  3803. BNX2X_STATE_DIAG):
  3804. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  3805. BNX2X_STATE_CLOSING_WAIT4_HALT):
  3806. DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
  3807. bnx2x_handle_classification_eqe(bp, elem);
  3808. break;
  3809. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  3810. BNX2X_STATE_OPEN):
  3811. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  3812. BNX2X_STATE_DIAG):
  3813. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  3814. BNX2X_STATE_CLOSING_WAIT4_HALT):
  3815. DP(BNX2X_MSG_SP, "got mcast ramrod\n");
  3816. bnx2x_handle_mcast_eqe(bp);
  3817. break;
  3818. case (EVENT_RING_OPCODE_FILTERS_RULES |
  3819. BNX2X_STATE_OPEN):
  3820. case (EVENT_RING_OPCODE_FILTERS_RULES |
  3821. BNX2X_STATE_DIAG):
  3822. case (EVENT_RING_OPCODE_FILTERS_RULES |
  3823. BNX2X_STATE_CLOSING_WAIT4_HALT):
  3824. DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
  3825. bnx2x_handle_rx_mode_eqe(bp);
  3826. break;
  3827. default:
  3828. /* unknown event log error and continue */
  3829. BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
  3830. elem->message.opcode, bp->state);
  3831. }
  3832. next_spqe:
  3833. spqe_cnt++;
  3834. } /* for */
  3835. smp_mb__before_atomic_inc();
  3836. atomic_add(spqe_cnt, &bp->eq_spq_left);
  3837. bp->eq_cons = sw_cons;
  3838. bp->eq_prod = sw_prod;
  3839. /* Make sure that above mem writes were issued towards the memory */
  3840. smp_wmb();
  3841. /* update producer */
  3842. bnx2x_update_eq_prod(bp, bp->eq_prod);
  3843. }
  3844. static void bnx2x_sp_task(struct work_struct *work)
  3845. {
  3846. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  3847. u16 status;
  3848. status = bnx2x_update_dsb_idx(bp);
  3849. /* if (status == 0) */
  3850. /* BNX2X_ERR("spurious slowpath interrupt!\n"); */
  3851. DP(NETIF_MSG_INTR, "got a slowpath interrupt (status 0x%x)\n", status);
  3852. /* HW attentions */
  3853. if (status & BNX2X_DEF_SB_ATT_IDX) {
  3854. bnx2x_attn_int(bp);
  3855. status &= ~BNX2X_DEF_SB_ATT_IDX;
  3856. }
  3857. /* SP events: STAT_QUERY and others */
  3858. if (status & BNX2X_DEF_SB_IDX) {
  3859. #ifdef BCM_CNIC
  3860. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  3861. if ((!NO_FCOE(bp)) &&
  3862. (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  3863. /*
  3864. * Prevent local bottom-halves from running as
  3865. * we are going to change the local NAPI list.
  3866. */
  3867. local_bh_disable();
  3868. napi_schedule(&bnx2x_fcoe(bp, napi));
  3869. local_bh_enable();
  3870. }
  3871. #endif
  3872. /* Handle EQ completions */
  3873. bnx2x_eq_int(bp);
  3874. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
  3875. le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
  3876. status &= ~BNX2X_DEF_SB_IDX;
  3877. }
  3878. if (unlikely(status))
  3879. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
  3880. status);
  3881. bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
  3882. le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
  3883. }
  3884. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  3885. {
  3886. struct net_device *dev = dev_instance;
  3887. struct bnx2x *bp = netdev_priv(dev);
  3888. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
  3889. IGU_INT_DISABLE, 0);
  3890. #ifdef BNX2X_STOP_ON_ERROR
  3891. if (unlikely(bp->panic))
  3892. return IRQ_HANDLED;
  3893. #endif
  3894. #ifdef BCM_CNIC
  3895. {
  3896. struct cnic_ops *c_ops;
  3897. rcu_read_lock();
  3898. c_ops = rcu_dereference(bp->cnic_ops);
  3899. if (c_ops)
  3900. c_ops->cnic_handler(bp->cnic_data, NULL);
  3901. rcu_read_unlock();
  3902. }
  3903. #endif
  3904. queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  3905. return IRQ_HANDLED;
  3906. }
  3907. /* end of slow path */
  3908. void bnx2x_drv_pulse(struct bnx2x *bp)
  3909. {
  3910. SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
  3911. bp->fw_drv_pulse_wr_seq);
  3912. }
  3913. static void bnx2x_timer(unsigned long data)
  3914. {
  3915. u8 cos;
  3916. struct bnx2x *bp = (struct bnx2x *) data;
  3917. if (!netif_running(bp->dev))
  3918. return;
  3919. if (poll) {
  3920. struct bnx2x_fastpath *fp = &bp->fp[0];
  3921. for_each_cos_in_tx_queue(fp, cos)
  3922. bnx2x_tx_int(bp, &fp->txdata[cos]);
  3923. bnx2x_rx_int(fp, 1000);
  3924. }
  3925. if (!BP_NOMCP(bp)) {
  3926. int mb_idx = BP_FW_MB_IDX(bp);
  3927. u32 drv_pulse;
  3928. u32 mcp_pulse;
  3929. ++bp->fw_drv_pulse_wr_seq;
  3930. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  3931. /* TBD - add SYSTEM_TIME */
  3932. drv_pulse = bp->fw_drv_pulse_wr_seq;
  3933. bnx2x_drv_pulse(bp);
  3934. mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
  3935. MCP_PULSE_SEQ_MASK);
  3936. /* The delta between driver pulse and mcp response
  3937. * should be 1 (before mcp response) or 0 (after mcp response)
  3938. */
  3939. if ((drv_pulse != mcp_pulse) &&
  3940. (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
  3941. /* someone lost a heartbeat... */
  3942. BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  3943. drv_pulse, mcp_pulse);
  3944. }
  3945. }
  3946. if (bp->state == BNX2X_STATE_OPEN)
  3947. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  3948. mod_timer(&bp->timer, jiffies + bp->current_interval);
  3949. }
  3950. /* end of Statistics */
  3951. /* nic init */
  3952. /*
  3953. * nic init service functions
  3954. */
  3955. static inline void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  3956. {
  3957. u32 i;
  3958. if (!(len%4) && !(addr%4))
  3959. for (i = 0; i < len; i += 4)
  3960. REG_WR(bp, addr + i, fill);
  3961. else
  3962. for (i = 0; i < len; i++)
  3963. REG_WR8(bp, addr + i, fill);
  3964. }
  3965. /* helper: writes FP SP data to FW - data_size in dwords */
  3966. static inline void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
  3967. int fw_sb_id,
  3968. u32 *sb_data_p,
  3969. u32 data_size)
  3970. {
  3971. int index;
  3972. for (index = 0; index < data_size; index++)
  3973. REG_WR(bp, BAR_CSTRORM_INTMEM +
  3974. CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
  3975. sizeof(u32)*index,
  3976. *(sb_data_p + index));
  3977. }
  3978. static inline void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
  3979. {
  3980. u32 *sb_data_p;
  3981. u32 data_size = 0;
  3982. struct hc_status_block_data_e2 sb_data_e2;
  3983. struct hc_status_block_data_e1x sb_data_e1x;
  3984. /* disable the function first */
  3985. if (!CHIP_IS_E1x(bp)) {
  3986. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  3987. sb_data_e2.common.state = SB_DISABLED;
  3988. sb_data_e2.common.p_func.vf_valid = false;
  3989. sb_data_p = (u32 *)&sb_data_e2;
  3990. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  3991. } else {
  3992. memset(&sb_data_e1x, 0,
  3993. sizeof(struct hc_status_block_data_e1x));
  3994. sb_data_e1x.common.state = SB_DISABLED;
  3995. sb_data_e1x.common.p_func.vf_valid = false;
  3996. sb_data_p = (u32 *)&sb_data_e1x;
  3997. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  3998. }
  3999. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4000. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4001. CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
  4002. CSTORM_STATUS_BLOCK_SIZE);
  4003. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4004. CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
  4005. CSTORM_SYNC_BLOCK_SIZE);
  4006. }
  4007. /* helper: writes SP SB data to FW */
  4008. static inline void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
  4009. struct hc_sp_status_block_data *sp_sb_data)
  4010. {
  4011. int func = BP_FUNC(bp);
  4012. int i;
  4013. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  4014. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4015. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  4016. i*sizeof(u32),
  4017. *((u32 *)sp_sb_data + i));
  4018. }
  4019. static inline void bnx2x_zero_sp_sb(struct bnx2x *bp)
  4020. {
  4021. int func = BP_FUNC(bp);
  4022. struct hc_sp_status_block_data sp_sb_data;
  4023. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4024. sp_sb_data.state = SB_DISABLED;
  4025. sp_sb_data.p_func.vf_valid = false;
  4026. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4027. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4028. CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
  4029. CSTORM_SP_STATUS_BLOCK_SIZE);
  4030. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4031. CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
  4032. CSTORM_SP_SYNC_BLOCK_SIZE);
  4033. }
  4034. static inline
  4035. void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
  4036. int igu_sb_id, int igu_seg_id)
  4037. {
  4038. hc_sm->igu_sb_id = igu_sb_id;
  4039. hc_sm->igu_seg_id = igu_seg_id;
  4040. hc_sm->timer_value = 0xFF;
  4041. hc_sm->time_to_expire = 0xFFFFFFFF;
  4042. }
  4043. /* allocates state machine ids. */
  4044. static inline
  4045. void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
  4046. {
  4047. /* zero out state machine indices */
  4048. /* rx indices */
  4049. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4050. /* tx indices */
  4051. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4052. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
  4053. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
  4054. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
  4055. /* map indices */
  4056. /* rx indices */
  4057. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
  4058. SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4059. /* tx indices */
  4060. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
  4061. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4062. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
  4063. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4064. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
  4065. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4066. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
  4067. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4068. }
  4069. static void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
  4070. u8 vf_valid, int fw_sb_id, int igu_sb_id)
  4071. {
  4072. int igu_seg_id;
  4073. struct hc_status_block_data_e2 sb_data_e2;
  4074. struct hc_status_block_data_e1x sb_data_e1x;
  4075. struct hc_status_block_sm *hc_sm_p;
  4076. int data_size;
  4077. u32 *sb_data_p;
  4078. if (CHIP_INT_MODE_IS_BC(bp))
  4079. igu_seg_id = HC_SEG_ACCESS_NORM;
  4080. else
  4081. igu_seg_id = IGU_SEG_ACCESS_NORM;
  4082. bnx2x_zero_fp_sb(bp, fw_sb_id);
  4083. if (!CHIP_IS_E1x(bp)) {
  4084. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4085. sb_data_e2.common.state = SB_ENABLED;
  4086. sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
  4087. sb_data_e2.common.p_func.vf_id = vfid;
  4088. sb_data_e2.common.p_func.vf_valid = vf_valid;
  4089. sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
  4090. sb_data_e2.common.same_igu_sb_1b = true;
  4091. sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
  4092. sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
  4093. hc_sm_p = sb_data_e2.common.state_machine;
  4094. sb_data_p = (u32 *)&sb_data_e2;
  4095. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4096. bnx2x_map_sb_state_machines(sb_data_e2.index_data);
  4097. } else {
  4098. memset(&sb_data_e1x, 0,
  4099. sizeof(struct hc_status_block_data_e1x));
  4100. sb_data_e1x.common.state = SB_ENABLED;
  4101. sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
  4102. sb_data_e1x.common.p_func.vf_id = 0xff;
  4103. sb_data_e1x.common.p_func.vf_valid = false;
  4104. sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
  4105. sb_data_e1x.common.same_igu_sb_1b = true;
  4106. sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
  4107. sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
  4108. hc_sm_p = sb_data_e1x.common.state_machine;
  4109. sb_data_p = (u32 *)&sb_data_e1x;
  4110. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4111. bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
  4112. }
  4113. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
  4114. igu_sb_id, igu_seg_id);
  4115. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
  4116. igu_sb_id, igu_seg_id);
  4117. DP(NETIF_MSG_HW, "Init FW SB %d\n", fw_sb_id);
  4118. /* write indecies to HW */
  4119. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4120. }
  4121. static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
  4122. u16 tx_usec, u16 rx_usec)
  4123. {
  4124. bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
  4125. false, rx_usec);
  4126. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4127. HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
  4128. tx_usec);
  4129. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4130. HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
  4131. tx_usec);
  4132. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4133. HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
  4134. tx_usec);
  4135. }
  4136. static void bnx2x_init_def_sb(struct bnx2x *bp)
  4137. {
  4138. struct host_sp_status_block *def_sb = bp->def_status_blk;
  4139. dma_addr_t mapping = bp->def_status_blk_mapping;
  4140. int igu_sp_sb_index;
  4141. int igu_seg_id;
  4142. int port = BP_PORT(bp);
  4143. int func = BP_FUNC(bp);
  4144. int reg_offset, reg_offset_en5;
  4145. u64 section;
  4146. int index;
  4147. struct hc_sp_status_block_data sp_sb_data;
  4148. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4149. if (CHIP_INT_MODE_IS_BC(bp)) {
  4150. igu_sp_sb_index = DEF_SB_IGU_ID;
  4151. igu_seg_id = HC_SEG_ACCESS_DEF;
  4152. } else {
  4153. igu_sp_sb_index = bp->igu_dsb_id;
  4154. igu_seg_id = IGU_SEG_ACCESS_DEF;
  4155. }
  4156. /* ATTN */
  4157. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4158. atten_status_block);
  4159. def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
  4160. bp->attn_state = 0;
  4161. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  4162. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  4163. reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
  4164. MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
  4165. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4166. int sindex;
  4167. /* take care of sig[0]..sig[4] */
  4168. for (sindex = 0; sindex < 4; sindex++)
  4169. bp->attn_group[index].sig[sindex] =
  4170. REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
  4171. if (!CHIP_IS_E1x(bp))
  4172. /*
  4173. * enable5 is separate from the rest of the registers,
  4174. * and therefore the address skip is 4
  4175. * and not 16 between the different groups
  4176. */
  4177. bp->attn_group[index].sig[4] = REG_RD(bp,
  4178. reg_offset_en5 + 0x4*index);
  4179. else
  4180. bp->attn_group[index].sig[4] = 0;
  4181. }
  4182. if (bp->common.int_block == INT_BLOCK_HC) {
  4183. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  4184. HC_REG_ATTN_MSG0_ADDR_L);
  4185. REG_WR(bp, reg_offset, U64_LO(section));
  4186. REG_WR(bp, reg_offset + 4, U64_HI(section));
  4187. } else if (!CHIP_IS_E1x(bp)) {
  4188. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
  4189. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
  4190. }
  4191. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4192. sp_sb);
  4193. bnx2x_zero_sp_sb(bp);
  4194. sp_sb_data.state = SB_ENABLED;
  4195. sp_sb_data.host_sb_addr.lo = U64_LO(section);
  4196. sp_sb_data.host_sb_addr.hi = U64_HI(section);
  4197. sp_sb_data.igu_sb_id = igu_sp_sb_index;
  4198. sp_sb_data.igu_seg_id = igu_seg_id;
  4199. sp_sb_data.p_func.pf_id = func;
  4200. sp_sb_data.p_func.vnic_id = BP_VN(bp);
  4201. sp_sb_data.p_func.vf_id = 0xff;
  4202. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4203. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
  4204. }
  4205. void bnx2x_update_coalesce(struct bnx2x *bp)
  4206. {
  4207. int i;
  4208. for_each_eth_queue(bp, i)
  4209. bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
  4210. bp->tx_ticks, bp->rx_ticks);
  4211. }
  4212. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  4213. {
  4214. spin_lock_init(&bp->spq_lock);
  4215. atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
  4216. bp->spq_prod_idx = 0;
  4217. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  4218. bp->spq_prod_bd = bp->spq;
  4219. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  4220. }
  4221. static void bnx2x_init_eq_ring(struct bnx2x *bp)
  4222. {
  4223. int i;
  4224. for (i = 1; i <= NUM_EQ_PAGES; i++) {
  4225. union event_ring_elem *elem =
  4226. &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
  4227. elem->next_page.addr.hi =
  4228. cpu_to_le32(U64_HI(bp->eq_mapping +
  4229. BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
  4230. elem->next_page.addr.lo =
  4231. cpu_to_le32(U64_LO(bp->eq_mapping +
  4232. BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
  4233. }
  4234. bp->eq_cons = 0;
  4235. bp->eq_prod = NUM_EQ_DESC;
  4236. bp->eq_cons_sb = BNX2X_EQ_INDEX;
  4237. /* we want a warning message before it gets rought... */
  4238. atomic_set(&bp->eq_spq_left,
  4239. min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
  4240. }
  4241. /* called with netif_addr_lock_bh() */
  4242. void bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
  4243. unsigned long rx_mode_flags,
  4244. unsigned long rx_accept_flags,
  4245. unsigned long tx_accept_flags,
  4246. unsigned long ramrod_flags)
  4247. {
  4248. struct bnx2x_rx_mode_ramrod_params ramrod_param;
  4249. int rc;
  4250. memset(&ramrod_param, 0, sizeof(ramrod_param));
  4251. /* Prepare ramrod parameters */
  4252. ramrod_param.cid = 0;
  4253. ramrod_param.cl_id = cl_id;
  4254. ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
  4255. ramrod_param.func_id = BP_FUNC(bp);
  4256. ramrod_param.pstate = &bp->sp_state;
  4257. ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
  4258. ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
  4259. ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
  4260. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4261. ramrod_param.ramrod_flags = ramrod_flags;
  4262. ramrod_param.rx_mode_flags = rx_mode_flags;
  4263. ramrod_param.rx_accept_flags = rx_accept_flags;
  4264. ramrod_param.tx_accept_flags = tx_accept_flags;
  4265. rc = bnx2x_config_rx_mode(bp, &ramrod_param);
  4266. if (rc < 0) {
  4267. BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
  4268. return;
  4269. }
  4270. }
  4271. /* called with netif_addr_lock_bh() */
  4272. void bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  4273. {
  4274. unsigned long rx_mode_flags = 0, ramrod_flags = 0;
  4275. unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
  4276. #ifdef BCM_CNIC
  4277. if (!NO_FCOE(bp))
  4278. /* Configure rx_mode of FCoE Queue */
  4279. __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
  4280. #endif
  4281. switch (bp->rx_mode) {
  4282. case BNX2X_RX_MODE_NONE:
  4283. /*
  4284. * 'drop all' supersedes any accept flags that may have been
  4285. * passed to the function.
  4286. */
  4287. break;
  4288. case BNX2X_RX_MODE_NORMAL:
  4289. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4290. __set_bit(BNX2X_ACCEPT_MULTICAST, &rx_accept_flags);
  4291. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4292. /* internal switching mode */
  4293. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4294. __set_bit(BNX2X_ACCEPT_MULTICAST, &tx_accept_flags);
  4295. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4296. break;
  4297. case BNX2X_RX_MODE_ALLMULTI:
  4298. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4299. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
  4300. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4301. /* internal switching mode */
  4302. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4303. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
  4304. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4305. break;
  4306. case BNX2X_RX_MODE_PROMISC:
  4307. /* According to deffinition of SI mode, iface in promisc mode
  4308. * should receive matched and unmatched (in resolution of port)
  4309. * unicast packets.
  4310. */
  4311. __set_bit(BNX2X_ACCEPT_UNMATCHED, &rx_accept_flags);
  4312. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4313. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
  4314. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4315. /* internal switching mode */
  4316. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
  4317. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4318. if (IS_MF_SI(bp))
  4319. __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &tx_accept_flags);
  4320. else
  4321. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4322. break;
  4323. default:
  4324. BNX2X_ERR("Unknown rx_mode: %d\n", bp->rx_mode);
  4325. return;
  4326. }
  4327. if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
  4328. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &rx_accept_flags);
  4329. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &tx_accept_flags);
  4330. }
  4331. __set_bit(RAMROD_RX, &ramrod_flags);
  4332. __set_bit(RAMROD_TX, &ramrod_flags);
  4333. bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags, rx_accept_flags,
  4334. tx_accept_flags, ramrod_flags);
  4335. }
  4336. static void bnx2x_init_internal_common(struct bnx2x *bp)
  4337. {
  4338. int i;
  4339. if (IS_MF_SI(bp))
  4340. /*
  4341. * In switch independent mode, the TSTORM needs to accept
  4342. * packets that failed classification, since approximate match
  4343. * mac addresses aren't written to NIG LLH
  4344. */
  4345. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4346. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
  4347. else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
  4348. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4349. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
  4350. /* Zero this manually as its initialization is
  4351. currently missing in the initTool */
  4352. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  4353. REG_WR(bp, BAR_USTRORM_INTMEM +
  4354. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  4355. if (!CHIP_IS_E1x(bp)) {
  4356. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
  4357. CHIP_INT_MODE_IS_BC(bp) ?
  4358. HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
  4359. }
  4360. }
  4361. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  4362. {
  4363. switch (load_code) {
  4364. case FW_MSG_CODE_DRV_LOAD_COMMON:
  4365. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  4366. bnx2x_init_internal_common(bp);
  4367. /* no break */
  4368. case FW_MSG_CODE_DRV_LOAD_PORT:
  4369. /* nothing to do */
  4370. /* no break */
  4371. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  4372. /* internal memory per function is
  4373. initialized inside bnx2x_pf_init */
  4374. break;
  4375. default:
  4376. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  4377. break;
  4378. }
  4379. }
  4380. static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
  4381. {
  4382. return fp->bp->igu_base_sb + fp->index + CNIC_PRESENT;
  4383. }
  4384. static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
  4385. {
  4386. return fp->bp->base_fw_ndsb + fp->index + CNIC_PRESENT;
  4387. }
  4388. static inline u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
  4389. {
  4390. if (CHIP_IS_E1x(fp->bp))
  4391. return BP_L_ID(fp->bp) + fp->index;
  4392. else /* We want Client ID to be the same as IGU SB ID for 57712 */
  4393. return bnx2x_fp_igu_sb_id(fp);
  4394. }
  4395. static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
  4396. {
  4397. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  4398. u8 cos;
  4399. unsigned long q_type = 0;
  4400. u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
  4401. fp->rx_queue = fp_idx;
  4402. fp->cid = fp_idx;
  4403. fp->cl_id = bnx2x_fp_cl_id(fp);
  4404. fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
  4405. fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
  4406. /* qZone id equals to FW (per path) client id */
  4407. fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
  4408. /* init shortcut */
  4409. fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
  4410. /* Setup SB indicies */
  4411. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  4412. /* Configure Queue State object */
  4413. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  4414. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  4415. BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
  4416. /* init tx data */
  4417. for_each_cos_in_tx_queue(fp, cos) {
  4418. bnx2x_init_txdata(bp, &fp->txdata[cos],
  4419. CID_COS_TO_TX_ONLY_CID(fp->cid, cos),
  4420. FP_COS_TO_TXQ(fp, cos),
  4421. BNX2X_TX_SB_INDEX_BASE + cos);
  4422. cids[cos] = fp->txdata[cos].cid;
  4423. }
  4424. bnx2x_init_queue_obj(bp, &fp->q_obj, fp->cl_id, cids, fp->max_cos,
  4425. BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  4426. bnx2x_sp_mapping(bp, q_rdata), q_type);
  4427. /**
  4428. * Configure classification DBs: Always enable Tx switching
  4429. */
  4430. bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
  4431. DP(NETIF_MSG_IFUP, "queue[%d]: bnx2x_init_sb(%p,%p) "
  4432. "cl_id %d fw_sb %d igu_sb %d\n",
  4433. fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  4434. fp->igu_sb_id);
  4435. bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
  4436. fp->fw_sb_id, fp->igu_sb_id);
  4437. bnx2x_update_fpsb_idx(fp);
  4438. }
  4439. void bnx2x_nic_init(struct bnx2x *bp, u32 load_code)
  4440. {
  4441. int i;
  4442. for_each_eth_queue(bp, i)
  4443. bnx2x_init_eth_fp(bp, i);
  4444. #ifdef BCM_CNIC
  4445. if (!NO_FCOE(bp))
  4446. bnx2x_init_fcoe_fp(bp);
  4447. bnx2x_init_sb(bp, bp->cnic_sb_mapping,
  4448. BNX2X_VF_ID_INVALID, false,
  4449. bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
  4450. #endif
  4451. /* Initialize MOD_ABS interrupts */
  4452. bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
  4453. bp->common.shmem_base, bp->common.shmem2_base,
  4454. BP_PORT(bp));
  4455. /* ensure status block indices were read */
  4456. rmb();
  4457. bnx2x_init_def_sb(bp);
  4458. bnx2x_update_dsb_idx(bp);
  4459. bnx2x_init_rx_rings(bp);
  4460. bnx2x_init_tx_rings(bp);
  4461. bnx2x_init_sp_ring(bp);
  4462. bnx2x_init_eq_ring(bp);
  4463. bnx2x_init_internal(bp, load_code);
  4464. bnx2x_pf_init(bp);
  4465. bnx2x_stats_init(bp);
  4466. /* flush all before enabling interrupts */
  4467. mb();
  4468. mmiowb();
  4469. bnx2x_int_enable(bp);
  4470. /* Check for SPIO5 */
  4471. bnx2x_attn_int_deasserted0(bp,
  4472. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
  4473. AEU_INPUTS_ATTN_BITS_SPIO5);
  4474. }
  4475. /* end of nic init */
  4476. /*
  4477. * gzip service functions
  4478. */
  4479. static int bnx2x_gunzip_init(struct bnx2x *bp)
  4480. {
  4481. bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
  4482. &bp->gunzip_mapping, GFP_KERNEL);
  4483. if (bp->gunzip_buf == NULL)
  4484. goto gunzip_nomem1;
  4485. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  4486. if (bp->strm == NULL)
  4487. goto gunzip_nomem2;
  4488. bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
  4489. if (bp->strm->workspace == NULL)
  4490. goto gunzip_nomem3;
  4491. return 0;
  4492. gunzip_nomem3:
  4493. kfree(bp->strm);
  4494. bp->strm = NULL;
  4495. gunzip_nomem2:
  4496. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  4497. bp->gunzip_mapping);
  4498. bp->gunzip_buf = NULL;
  4499. gunzip_nomem1:
  4500. netdev_err(bp->dev, "Cannot allocate firmware buffer for"
  4501. " un-compression\n");
  4502. return -ENOMEM;
  4503. }
  4504. static void bnx2x_gunzip_end(struct bnx2x *bp)
  4505. {
  4506. if (bp->strm) {
  4507. vfree(bp->strm->workspace);
  4508. kfree(bp->strm);
  4509. bp->strm = NULL;
  4510. }
  4511. if (bp->gunzip_buf) {
  4512. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  4513. bp->gunzip_mapping);
  4514. bp->gunzip_buf = NULL;
  4515. }
  4516. }
  4517. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
  4518. {
  4519. int n, rc;
  4520. /* check gzip header */
  4521. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
  4522. BNX2X_ERR("Bad gzip header\n");
  4523. return -EINVAL;
  4524. }
  4525. n = 10;
  4526. #define FNAME 0x8
  4527. if (zbuf[3] & FNAME)
  4528. while ((zbuf[n++] != 0) && (n < len));
  4529. bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
  4530. bp->strm->avail_in = len - n;
  4531. bp->strm->next_out = bp->gunzip_buf;
  4532. bp->strm->avail_out = FW_BUF_SIZE;
  4533. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  4534. if (rc != Z_OK)
  4535. return rc;
  4536. rc = zlib_inflate(bp->strm, Z_FINISH);
  4537. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  4538. netdev_err(bp->dev, "Firmware decompression error: %s\n",
  4539. bp->strm->msg);
  4540. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  4541. if (bp->gunzip_outlen & 0x3)
  4542. netdev_err(bp->dev, "Firmware decompression error:"
  4543. " gunzip_outlen (%d) not aligned\n",
  4544. bp->gunzip_outlen);
  4545. bp->gunzip_outlen >>= 2;
  4546. zlib_inflateEnd(bp->strm);
  4547. if (rc == Z_STREAM_END)
  4548. return 0;
  4549. return rc;
  4550. }
  4551. /* nic load/unload */
  4552. /*
  4553. * General service functions
  4554. */
  4555. /* send a NIG loopback debug packet */
  4556. static void bnx2x_lb_pckt(struct bnx2x *bp)
  4557. {
  4558. u32 wb_write[3];
  4559. /* Ethernet source and destination addresses */
  4560. wb_write[0] = 0x55555555;
  4561. wb_write[1] = 0x55555555;
  4562. wb_write[2] = 0x20; /* SOP */
  4563. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  4564. /* NON-IP protocol */
  4565. wb_write[0] = 0x09000000;
  4566. wb_write[1] = 0x55555555;
  4567. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  4568. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  4569. }
  4570. /* some of the internal memories
  4571. * are not directly readable from the driver
  4572. * to test them we send debug packets
  4573. */
  4574. static int bnx2x_int_mem_test(struct bnx2x *bp)
  4575. {
  4576. int factor;
  4577. int count, i;
  4578. u32 val = 0;
  4579. if (CHIP_REV_IS_FPGA(bp))
  4580. factor = 120;
  4581. else if (CHIP_REV_IS_EMUL(bp))
  4582. factor = 200;
  4583. else
  4584. factor = 1;
  4585. /* Disable inputs of parser neighbor blocks */
  4586. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  4587. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  4588. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  4589. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  4590. /* Write 0 to parser credits for CFC search request */
  4591. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  4592. /* send Ethernet packet */
  4593. bnx2x_lb_pckt(bp);
  4594. /* TODO do i reset NIG statistic? */
  4595. /* Wait until NIG register shows 1 packet of size 0x10 */
  4596. count = 1000 * factor;
  4597. while (count) {
  4598. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  4599. val = *bnx2x_sp(bp, wb_data[0]);
  4600. if (val == 0x10)
  4601. break;
  4602. msleep(10);
  4603. count--;
  4604. }
  4605. if (val != 0x10) {
  4606. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  4607. return -1;
  4608. }
  4609. /* Wait until PRS register shows 1 packet */
  4610. count = 1000 * factor;
  4611. while (count) {
  4612. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  4613. if (val == 1)
  4614. break;
  4615. msleep(10);
  4616. count--;
  4617. }
  4618. if (val != 0x1) {
  4619. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  4620. return -2;
  4621. }
  4622. /* Reset and init BRB, PRS */
  4623. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  4624. msleep(50);
  4625. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  4626. msleep(50);
  4627. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  4628. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  4629. DP(NETIF_MSG_HW, "part2\n");
  4630. /* Disable inputs of parser neighbor blocks */
  4631. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  4632. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  4633. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  4634. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  4635. /* Write 0 to parser credits for CFC search request */
  4636. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  4637. /* send 10 Ethernet packets */
  4638. for (i = 0; i < 10; i++)
  4639. bnx2x_lb_pckt(bp);
  4640. /* Wait until NIG register shows 10 + 1
  4641. packets of size 11*0x10 = 0xb0 */
  4642. count = 1000 * factor;
  4643. while (count) {
  4644. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  4645. val = *bnx2x_sp(bp, wb_data[0]);
  4646. if (val == 0xb0)
  4647. break;
  4648. msleep(10);
  4649. count--;
  4650. }
  4651. if (val != 0xb0) {
  4652. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  4653. return -3;
  4654. }
  4655. /* Wait until PRS register shows 2 packets */
  4656. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  4657. if (val != 2)
  4658. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  4659. /* Write 1 to parser credits for CFC search request */
  4660. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  4661. /* Wait until PRS register shows 3 packets */
  4662. msleep(10 * factor);
  4663. /* Wait until NIG register shows 1 packet of size 0x10 */
  4664. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  4665. if (val != 3)
  4666. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  4667. /* clear NIG EOP FIFO */
  4668. for (i = 0; i < 11; i++)
  4669. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  4670. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  4671. if (val != 1) {
  4672. BNX2X_ERR("clear of NIG failed\n");
  4673. return -4;
  4674. }
  4675. /* Reset and init BRB, PRS, NIG */
  4676. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  4677. msleep(50);
  4678. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  4679. msleep(50);
  4680. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  4681. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  4682. #ifndef BCM_CNIC
  4683. /* set NIC mode */
  4684. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  4685. #endif
  4686. /* Enable inputs of parser neighbor blocks */
  4687. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  4688. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  4689. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  4690. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  4691. DP(NETIF_MSG_HW, "done\n");
  4692. return 0; /* OK */
  4693. }
  4694. static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
  4695. {
  4696. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  4697. if (!CHIP_IS_E1x(bp))
  4698. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
  4699. else
  4700. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  4701. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  4702. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  4703. /*
  4704. * mask read length error interrupts in brb for parser
  4705. * (parsing unit and 'checksum and crc' unit)
  4706. * these errors are legal (PU reads fixed length and CAC can cause
  4707. * read length error on truncated packets)
  4708. */
  4709. REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
  4710. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  4711. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  4712. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  4713. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  4714. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  4715. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  4716. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  4717. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  4718. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  4719. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  4720. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  4721. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  4722. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  4723. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  4724. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  4725. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  4726. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  4727. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  4728. if (CHIP_REV_IS_FPGA(bp))
  4729. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x580000);
  4730. else if (!CHIP_IS_E1x(bp))
  4731. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0,
  4732. (PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF
  4733. | PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT
  4734. | PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN
  4735. | PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED
  4736. | PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED));
  4737. else
  4738. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x480000);
  4739. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  4740. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  4741. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  4742. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  4743. if (!CHIP_IS_E1x(bp))
  4744. /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
  4745. REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
  4746. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  4747. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  4748. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  4749. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
  4750. }
  4751. static void bnx2x_reset_common(struct bnx2x *bp)
  4752. {
  4753. u32 val = 0x1400;
  4754. /* reset_common */
  4755. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  4756. 0xd3ffff7f);
  4757. if (CHIP_IS_E3(bp)) {
  4758. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  4759. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  4760. }
  4761. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
  4762. }
  4763. static void bnx2x_setup_dmae(struct bnx2x *bp)
  4764. {
  4765. bp->dmae_ready = 0;
  4766. spin_lock_init(&bp->dmae_lock);
  4767. }
  4768. static void bnx2x_init_pxp(struct bnx2x *bp)
  4769. {
  4770. u16 devctl;
  4771. int r_order, w_order;
  4772. pci_read_config_word(bp->pdev,
  4773. pci_pcie_cap(bp->pdev) + PCI_EXP_DEVCTL, &devctl);
  4774. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  4775. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  4776. if (bp->mrrs == -1)
  4777. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  4778. else {
  4779. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  4780. r_order = bp->mrrs;
  4781. }
  4782. bnx2x_init_pxp_arb(bp, r_order, w_order);
  4783. }
  4784. static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
  4785. {
  4786. int is_required;
  4787. u32 val;
  4788. int port;
  4789. if (BP_NOMCP(bp))
  4790. return;
  4791. is_required = 0;
  4792. val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  4793. SHARED_HW_CFG_FAN_FAILURE_MASK;
  4794. if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
  4795. is_required = 1;
  4796. /*
  4797. * The fan failure mechanism is usually related to the PHY type since
  4798. * the power consumption of the board is affected by the PHY. Currently,
  4799. * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
  4800. */
  4801. else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
  4802. for (port = PORT_0; port < PORT_MAX; port++) {
  4803. is_required |=
  4804. bnx2x_fan_failure_det_req(
  4805. bp,
  4806. bp->common.shmem_base,
  4807. bp->common.shmem2_base,
  4808. port);
  4809. }
  4810. DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
  4811. if (is_required == 0)
  4812. return;
  4813. /* Fan failure is indicated by SPIO 5 */
  4814. bnx2x_set_spio(bp, MISC_REGISTERS_SPIO_5,
  4815. MISC_REGISTERS_SPIO_INPUT_HI_Z);
  4816. /* set to active low mode */
  4817. val = REG_RD(bp, MISC_REG_SPIO_INT);
  4818. val |= ((1 << MISC_REGISTERS_SPIO_5) <<
  4819. MISC_REGISTERS_SPIO_INT_OLD_SET_POS);
  4820. REG_WR(bp, MISC_REG_SPIO_INT, val);
  4821. /* enable interrupt to signal the IGU */
  4822. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  4823. val |= (1 << MISC_REGISTERS_SPIO_5);
  4824. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  4825. }
  4826. static void bnx2x_pretend_func(struct bnx2x *bp, u8 pretend_func_num)
  4827. {
  4828. u32 offset = 0;
  4829. if (CHIP_IS_E1(bp))
  4830. return;
  4831. if (CHIP_IS_E1H(bp) && (pretend_func_num >= E1H_FUNC_MAX))
  4832. return;
  4833. switch (BP_ABS_FUNC(bp)) {
  4834. case 0:
  4835. offset = PXP2_REG_PGL_PRETEND_FUNC_F0;
  4836. break;
  4837. case 1:
  4838. offset = PXP2_REG_PGL_PRETEND_FUNC_F1;
  4839. break;
  4840. case 2:
  4841. offset = PXP2_REG_PGL_PRETEND_FUNC_F2;
  4842. break;
  4843. case 3:
  4844. offset = PXP2_REG_PGL_PRETEND_FUNC_F3;
  4845. break;
  4846. case 4:
  4847. offset = PXP2_REG_PGL_PRETEND_FUNC_F4;
  4848. break;
  4849. case 5:
  4850. offset = PXP2_REG_PGL_PRETEND_FUNC_F5;
  4851. break;
  4852. case 6:
  4853. offset = PXP2_REG_PGL_PRETEND_FUNC_F6;
  4854. break;
  4855. case 7:
  4856. offset = PXP2_REG_PGL_PRETEND_FUNC_F7;
  4857. break;
  4858. default:
  4859. return;
  4860. }
  4861. REG_WR(bp, offset, pretend_func_num);
  4862. REG_RD(bp, offset);
  4863. DP(NETIF_MSG_HW, "Pretending to func %d\n", pretend_func_num);
  4864. }
  4865. void bnx2x_pf_disable(struct bnx2x *bp)
  4866. {
  4867. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  4868. val &= ~IGU_PF_CONF_FUNC_EN;
  4869. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  4870. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  4871. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
  4872. }
  4873. static inline void bnx2x__common_init_phy(struct bnx2x *bp)
  4874. {
  4875. u32 shmem_base[2], shmem2_base[2];
  4876. shmem_base[0] = bp->common.shmem_base;
  4877. shmem2_base[0] = bp->common.shmem2_base;
  4878. if (!CHIP_IS_E1x(bp)) {
  4879. shmem_base[1] =
  4880. SHMEM2_RD(bp, other_shmem_base_addr);
  4881. shmem2_base[1] =
  4882. SHMEM2_RD(bp, other_shmem2_base_addr);
  4883. }
  4884. bnx2x_acquire_phy_lock(bp);
  4885. bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
  4886. bp->common.chip_id);
  4887. bnx2x_release_phy_lock(bp);
  4888. }
  4889. /**
  4890. * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
  4891. *
  4892. * @bp: driver handle
  4893. */
  4894. static int bnx2x_init_hw_common(struct bnx2x *bp)
  4895. {
  4896. u32 val;
  4897. DP(BNX2X_MSG_MCP, "starting common init func %d\n", BP_ABS_FUNC(bp));
  4898. /*
  4899. * take the UNDI lock to protect undi_unload flow from accessing
  4900. * registers while we're resetting the chip
  4901. */
  4902. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  4903. bnx2x_reset_common(bp);
  4904. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  4905. val = 0xfffc;
  4906. if (CHIP_IS_E3(bp)) {
  4907. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  4908. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  4909. }
  4910. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
  4911. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  4912. bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
  4913. if (!CHIP_IS_E1x(bp)) {
  4914. u8 abs_func_id;
  4915. /**
  4916. * 4-port mode or 2-port mode we need to turn of master-enable
  4917. * for everyone, after that, turn it back on for self.
  4918. * so, we disregard multi-function or not, and always disable
  4919. * for all functions on the given path, this means 0,2,4,6 for
  4920. * path 0 and 1,3,5,7 for path 1
  4921. */
  4922. for (abs_func_id = BP_PATH(bp);
  4923. abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
  4924. if (abs_func_id == BP_ABS_FUNC(bp)) {
  4925. REG_WR(bp,
  4926. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
  4927. 1);
  4928. continue;
  4929. }
  4930. bnx2x_pretend_func(bp, abs_func_id);
  4931. /* clear pf enable */
  4932. bnx2x_pf_disable(bp);
  4933. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  4934. }
  4935. }
  4936. bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
  4937. if (CHIP_IS_E1(bp)) {
  4938. /* enable HW interrupt from PXP on USDM overflow
  4939. bit 16 on INT_MASK_0 */
  4940. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  4941. }
  4942. bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
  4943. bnx2x_init_pxp(bp);
  4944. #ifdef __BIG_ENDIAN
  4945. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
  4946. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
  4947. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
  4948. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
  4949. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
  4950. /* make sure this value is 0 */
  4951. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  4952. /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
  4953. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
  4954. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
  4955. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
  4956. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
  4957. #endif
  4958. bnx2x_ilt_init_page_size(bp, INITOP_SET);
  4959. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  4960. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  4961. /* let the HW do it's magic ... */
  4962. msleep(100);
  4963. /* finish PXP init */
  4964. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  4965. if (val != 1) {
  4966. BNX2X_ERR("PXP2 CFG failed\n");
  4967. return -EBUSY;
  4968. }
  4969. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  4970. if (val != 1) {
  4971. BNX2X_ERR("PXP2 RD_INIT failed\n");
  4972. return -EBUSY;
  4973. }
  4974. /* Timers bug workaround E2 only. We need to set the entire ILT to
  4975. * have entries with value "0" and valid bit on.
  4976. * This needs to be done by the first PF that is loaded in a path
  4977. * (i.e. common phase)
  4978. */
  4979. if (!CHIP_IS_E1x(bp)) {
  4980. /* In E2 there is a bug in the timers block that can cause function 6 / 7
  4981. * (i.e. vnic3) to start even if it is marked as "scan-off".
  4982. * This occurs when a different function (func2,3) is being marked
  4983. * as "scan-off". Real-life scenario for example: if a driver is being
  4984. * load-unloaded while func6,7 are down. This will cause the timer to access
  4985. * the ilt, translate to a logical address and send a request to read/write.
  4986. * Since the ilt for the function that is down is not valid, this will cause
  4987. * a translation error which is unrecoverable.
  4988. * The Workaround is intended to make sure that when this happens nothing fatal
  4989. * will occur. The workaround:
  4990. * 1. First PF driver which loads on a path will:
  4991. * a. After taking the chip out of reset, by using pretend,
  4992. * it will write "0" to the following registers of
  4993. * the other vnics.
  4994. * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  4995. * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
  4996. * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
  4997. * And for itself it will write '1' to
  4998. * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
  4999. * dmae-operations (writing to pram for example.)
  5000. * note: can be done for only function 6,7 but cleaner this
  5001. * way.
  5002. * b. Write zero+valid to the entire ILT.
  5003. * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
  5004. * VNIC3 (of that port). The range allocated will be the
  5005. * entire ILT. This is needed to prevent ILT range error.
  5006. * 2. Any PF driver load flow:
  5007. * a. ILT update with the physical addresses of the allocated
  5008. * logical pages.
  5009. * b. Wait 20msec. - note that this timeout is needed to make
  5010. * sure there are no requests in one of the PXP internal
  5011. * queues with "old" ILT addresses.
  5012. * c. PF enable in the PGLC.
  5013. * d. Clear the was_error of the PF in the PGLC. (could have
  5014. * occured while driver was down)
  5015. * e. PF enable in the CFC (WEAK + STRONG)
  5016. * f. Timers scan enable
  5017. * 3. PF driver unload flow:
  5018. * a. Clear the Timers scan_en.
  5019. * b. Polling for scan_on=0 for that PF.
  5020. * c. Clear the PF enable bit in the PXP.
  5021. * d. Clear the PF enable in the CFC (WEAK + STRONG)
  5022. * e. Write zero+valid to all ILT entries (The valid bit must
  5023. * stay set)
  5024. * f. If this is VNIC 3 of a port then also init
  5025. * first_timers_ilt_entry to zero and last_timers_ilt_entry
  5026. * to the last enrty in the ILT.
  5027. *
  5028. * Notes:
  5029. * Currently the PF error in the PGLC is non recoverable.
  5030. * In the future the there will be a recovery routine for this error.
  5031. * Currently attention is masked.
  5032. * Having an MCP lock on the load/unload process does not guarantee that
  5033. * there is no Timer disable during Func6/7 enable. This is because the
  5034. * Timers scan is currently being cleared by the MCP on FLR.
  5035. * Step 2.d can be done only for PF6/7 and the driver can also check if
  5036. * there is error before clearing it. But the flow above is simpler and
  5037. * more general.
  5038. * All ILT entries are written by zero+valid and not just PF6/7
  5039. * ILT entries since in the future the ILT entries allocation for
  5040. * PF-s might be dynamic.
  5041. */
  5042. struct ilt_client_info ilt_cli;
  5043. struct bnx2x_ilt ilt;
  5044. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  5045. memset(&ilt, 0, sizeof(struct bnx2x_ilt));
  5046. /* initialize dummy TM client */
  5047. ilt_cli.start = 0;
  5048. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  5049. ilt_cli.client_num = ILT_CLIENT_TM;
  5050. /* Step 1: set zeroes to all ilt page entries with valid bit on
  5051. * Step 2: set the timers first/last ilt entry to point
  5052. * to the entire range to prevent ILT range error for 3rd/4th
  5053. * vnic (this code assumes existance of the vnic)
  5054. *
  5055. * both steps performed by call to bnx2x_ilt_client_init_op()
  5056. * with dummy TM client
  5057. *
  5058. * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
  5059. * and his brother are split registers
  5060. */
  5061. bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
  5062. bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
  5063. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5064. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
  5065. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
  5066. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
  5067. }
  5068. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  5069. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  5070. if (!CHIP_IS_E1x(bp)) {
  5071. int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
  5072. (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
  5073. bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
  5074. bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
  5075. /* let the HW do it's magic ... */
  5076. do {
  5077. msleep(200);
  5078. val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
  5079. } while (factor-- && (val != 1));
  5080. if (val != 1) {
  5081. BNX2X_ERR("ATC_INIT failed\n");
  5082. return -EBUSY;
  5083. }
  5084. }
  5085. bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
  5086. /* clean the DMAE memory */
  5087. bp->dmae_ready = 1;
  5088. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
  5089. bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
  5090. bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
  5091. bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
  5092. bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
  5093. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  5094. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  5095. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  5096. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  5097. bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
  5098. /* QM queues pointers table */
  5099. bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
  5100. /* soft reset pulse */
  5101. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  5102. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  5103. #ifdef BCM_CNIC
  5104. bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
  5105. #endif
  5106. bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
  5107. REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT);
  5108. if (!CHIP_REV_IS_SLOW(bp))
  5109. /* enable hw interrupt from doorbell Q */
  5110. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5111. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5112. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5113. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  5114. if (!CHIP_IS_E1(bp))
  5115. REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
  5116. if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp))
  5117. /* Bit-map indicating which L2 hdrs may appear
  5118. * after the basic Ethernet header
  5119. */
  5120. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
  5121. bp->path_has_ovlan ? 7 : 6);
  5122. bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
  5123. bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
  5124. bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
  5125. bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
  5126. if (!CHIP_IS_E1x(bp)) {
  5127. /* reset VFC memories */
  5128. REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5129. VFC_MEMORIES_RST_REG_CAM_RST |
  5130. VFC_MEMORIES_RST_REG_RAM_RST);
  5131. REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5132. VFC_MEMORIES_RST_REG_CAM_RST |
  5133. VFC_MEMORIES_RST_REG_RAM_RST);
  5134. msleep(20);
  5135. }
  5136. bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
  5137. bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
  5138. bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
  5139. bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
  5140. /* sync semi rtc */
  5141. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5142. 0x80000000);
  5143. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  5144. 0x80000000);
  5145. bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
  5146. bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
  5147. bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
  5148. if (!CHIP_IS_E1x(bp))
  5149. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
  5150. bp->path_has_ovlan ? 7 : 6);
  5151. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  5152. bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
  5153. #ifdef BCM_CNIC
  5154. REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
  5155. REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
  5156. REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
  5157. REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
  5158. REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
  5159. REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
  5160. REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
  5161. REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
  5162. REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
  5163. REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
  5164. #endif
  5165. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  5166. if (sizeof(union cdu_context) != 1024)
  5167. /* we currently assume that a context is 1024 bytes */
  5168. dev_alert(&bp->pdev->dev, "please adjust the size "
  5169. "of cdu_context(%ld)\n",
  5170. (long)sizeof(union cdu_context));
  5171. bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
  5172. val = (4 << 24) + (0 << 12) + 1024;
  5173. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  5174. bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
  5175. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  5176. /* enable context validation interrupt from CFC */
  5177. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5178. /* set the thresholds to prevent CFC/CDU race */
  5179. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  5180. bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
  5181. if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
  5182. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
  5183. bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
  5184. bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
  5185. /* Reset PCIE errors for debug */
  5186. REG_WR(bp, 0x2814, 0xffffffff);
  5187. REG_WR(bp, 0x3820, 0xffffffff);
  5188. if (!CHIP_IS_E1x(bp)) {
  5189. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
  5190. (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
  5191. PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
  5192. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
  5193. (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
  5194. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
  5195. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
  5196. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
  5197. (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
  5198. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
  5199. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
  5200. }
  5201. bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
  5202. if (!CHIP_IS_E1(bp)) {
  5203. /* in E3 this done in per-port section */
  5204. if (!CHIP_IS_E3(bp))
  5205. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5206. }
  5207. if (CHIP_IS_E1H(bp))
  5208. /* not applicable for E2 (and above ...) */
  5209. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
  5210. if (CHIP_REV_IS_SLOW(bp))
  5211. msleep(200);
  5212. /* finish CFC init */
  5213. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  5214. if (val != 1) {
  5215. BNX2X_ERR("CFC LL_INIT failed\n");
  5216. return -EBUSY;
  5217. }
  5218. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  5219. if (val != 1) {
  5220. BNX2X_ERR("CFC AC_INIT failed\n");
  5221. return -EBUSY;
  5222. }
  5223. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  5224. if (val != 1) {
  5225. BNX2X_ERR("CFC CAM_INIT failed\n");
  5226. return -EBUSY;
  5227. }
  5228. REG_WR(bp, CFC_REG_DEBUG0, 0);
  5229. if (CHIP_IS_E1(bp)) {
  5230. /* read NIG statistic
  5231. to see if this is our first up since powerup */
  5232. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5233. val = *bnx2x_sp(bp, wb_data[0]);
  5234. /* do internal memory self test */
  5235. if ((val == 0) && bnx2x_int_mem_test(bp)) {
  5236. BNX2X_ERR("internal mem self test failed\n");
  5237. return -EBUSY;
  5238. }
  5239. }
  5240. bnx2x_setup_fan_failure_detection(bp);
  5241. /* clear PXP2 attentions */
  5242. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  5243. bnx2x_enable_blocks_attention(bp);
  5244. bnx2x_enable_blocks_parity(bp);
  5245. if (!BP_NOMCP(bp)) {
  5246. if (CHIP_IS_E1x(bp))
  5247. bnx2x__common_init_phy(bp);
  5248. } else
  5249. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  5250. return 0;
  5251. }
  5252. /**
  5253. * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
  5254. *
  5255. * @bp: driver handle
  5256. */
  5257. static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
  5258. {
  5259. int rc = bnx2x_init_hw_common(bp);
  5260. if (rc)
  5261. return rc;
  5262. /* In E2 2-PORT mode, same ext phy is used for the two paths */
  5263. if (!BP_NOMCP(bp))
  5264. bnx2x__common_init_phy(bp);
  5265. return 0;
  5266. }
  5267. static int bnx2x_init_hw_port(struct bnx2x *bp)
  5268. {
  5269. int port = BP_PORT(bp);
  5270. int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
  5271. u32 low, high;
  5272. u32 val;
  5273. bnx2x__link_reset(bp);
  5274. DP(BNX2X_MSG_MCP, "starting port init port %d\n", port);
  5275. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  5276. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  5277. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  5278. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  5279. /* Timers bug workaround: disables the pf_master bit in pglue at
  5280. * common phase, we need to enable it here before any dmae access are
  5281. * attempted. Therefore we manually added the enable-master to the
  5282. * port phase (it also happens in the function phase)
  5283. */
  5284. if (!CHIP_IS_E1x(bp))
  5285. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  5286. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  5287. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  5288. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  5289. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  5290. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  5291. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  5292. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  5293. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  5294. /* QM cid (connection) count */
  5295. bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
  5296. #ifdef BCM_CNIC
  5297. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  5298. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
  5299. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
  5300. #endif
  5301. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  5302. if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
  5303. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  5304. if (IS_MF(bp))
  5305. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  5306. else if (bp->dev->mtu > 4096) {
  5307. if (bp->flags & ONE_PORT_FLAG)
  5308. low = 160;
  5309. else {
  5310. val = bp->dev->mtu;
  5311. /* (24*1024 + val*4)/256 */
  5312. low = 96 + (val/64) +
  5313. ((val % 64) ? 1 : 0);
  5314. }
  5315. } else
  5316. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  5317. high = low + 56; /* 14*1024/256 */
  5318. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  5319. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  5320. }
  5321. if (CHIP_MODE_IS_4_PORT(bp))
  5322. REG_WR(bp, (BP_PORT(bp) ?
  5323. BRB1_REG_MAC_GUARANTIED_1 :
  5324. BRB1_REG_MAC_GUARANTIED_0), 40);
  5325. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  5326. if (CHIP_IS_E3B0(bp))
  5327. /* Ovlan exists only if we are in multi-function +
  5328. * switch-dependent mode, in switch-independent there
  5329. * is no ovlan headers
  5330. */
  5331. REG_WR(bp, BP_PORT(bp) ?
  5332. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  5333. PRS_REG_HDRS_AFTER_BASIC_PORT_0,
  5334. (bp->path_has_ovlan ? 7 : 6));
  5335. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  5336. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  5337. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  5338. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  5339. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  5340. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  5341. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  5342. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  5343. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  5344. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  5345. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  5346. if (CHIP_IS_E1x(bp)) {
  5347. /* configure PBF to work without PAUSE mtu 9000 */
  5348. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  5349. /* update threshold */
  5350. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  5351. /* update init credit */
  5352. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  5353. /* probe changes */
  5354. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  5355. udelay(50);
  5356. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  5357. }
  5358. #ifdef BCM_CNIC
  5359. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  5360. #endif
  5361. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  5362. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  5363. if (CHIP_IS_E1(bp)) {
  5364. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  5365. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  5366. }
  5367. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  5368. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  5369. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  5370. /* init aeu_mask_attn_func_0/1:
  5371. * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
  5372. * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
  5373. * bits 4-7 are used for "per vn group attention" */
  5374. val = IS_MF(bp) ? 0xF7 : 0x7;
  5375. /* Enable DCBX attention for all but E1 */
  5376. val |= CHIP_IS_E1(bp) ? 0 : 0x10;
  5377. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
  5378. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  5379. if (!CHIP_IS_E1x(bp)) {
  5380. /* Bit-map indicating which L2 hdrs may appear after the
  5381. * basic Ethernet header
  5382. */
  5383. REG_WR(bp, BP_PORT(bp) ?
  5384. NIG_REG_P1_HDRS_AFTER_BASIC :
  5385. NIG_REG_P0_HDRS_AFTER_BASIC,
  5386. IS_MF_SD(bp) ? 7 : 6);
  5387. if (CHIP_IS_E3(bp))
  5388. REG_WR(bp, BP_PORT(bp) ?
  5389. NIG_REG_LLH1_MF_MODE :
  5390. NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5391. }
  5392. if (!CHIP_IS_E3(bp))
  5393. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  5394. if (!CHIP_IS_E1(bp)) {
  5395. /* 0x2 disable mf_ov, 0x1 enable */
  5396. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  5397. (IS_MF_SD(bp) ? 0x1 : 0x2));
  5398. if (!CHIP_IS_E1x(bp)) {
  5399. val = 0;
  5400. switch (bp->mf_mode) {
  5401. case MULTI_FUNCTION_SD:
  5402. val = 1;
  5403. break;
  5404. case MULTI_FUNCTION_SI:
  5405. val = 2;
  5406. break;
  5407. }
  5408. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
  5409. NIG_REG_LLH0_CLS_TYPE), val);
  5410. }
  5411. {
  5412. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  5413. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  5414. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  5415. }
  5416. }
  5417. /* If SPIO5 is set to generate interrupts, enable it for this port */
  5418. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5419. if (val & (1 << MISC_REGISTERS_SPIO_5)) {
  5420. u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  5421. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  5422. val = REG_RD(bp, reg_addr);
  5423. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  5424. REG_WR(bp, reg_addr, val);
  5425. }
  5426. return 0;
  5427. }
  5428. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  5429. {
  5430. int reg;
  5431. if (CHIP_IS_E1(bp))
  5432. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  5433. else
  5434. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  5435. bnx2x_wb_wr(bp, reg, ONCHIP_ADDR1(addr), ONCHIP_ADDR2(addr));
  5436. }
  5437. static inline void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
  5438. {
  5439. bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
  5440. }
  5441. static inline void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
  5442. {
  5443. u32 i, base = FUNC_ILT_BASE(func);
  5444. for (i = base; i < base + ILT_PER_FUNC; i++)
  5445. bnx2x_ilt_wr(bp, i, 0);
  5446. }
  5447. static int bnx2x_init_hw_func(struct bnx2x *bp)
  5448. {
  5449. int port = BP_PORT(bp);
  5450. int func = BP_FUNC(bp);
  5451. int init_phase = PHASE_PF0 + func;
  5452. struct bnx2x_ilt *ilt = BP_ILT(bp);
  5453. u16 cdu_ilt_start;
  5454. u32 addr, val;
  5455. u32 main_mem_base, main_mem_size, main_mem_prty_clr;
  5456. int i, main_mem_width;
  5457. DP(BNX2X_MSG_MCP, "starting func init func %d\n", func);
  5458. /* FLR cleanup - hmmm */
  5459. if (!CHIP_IS_E1x(bp))
  5460. bnx2x_pf_flr_clnup(bp);
  5461. /* set MSI reconfigure capability */
  5462. if (bp->common.int_block == INT_BLOCK_HC) {
  5463. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  5464. val = REG_RD(bp, addr);
  5465. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  5466. REG_WR(bp, addr, val);
  5467. }
  5468. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  5469. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  5470. ilt = BP_ILT(bp);
  5471. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  5472. for (i = 0; i < L2_ILT_LINES(bp); i++) {
  5473. ilt->lines[cdu_ilt_start + i].page =
  5474. bp->context.vcxt + (ILT_PAGE_CIDS * i);
  5475. ilt->lines[cdu_ilt_start + i].page_mapping =
  5476. bp->context.cxt_mapping + (CDU_ILT_PAGE_SZ * i);
  5477. /* cdu ilt pages are allocated manually so there's no need to
  5478. set the size */
  5479. }
  5480. bnx2x_ilt_init_op(bp, INITOP_SET);
  5481. #ifdef BCM_CNIC
  5482. bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
  5483. /* T1 hash bits value determines the T1 number of entries */
  5484. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
  5485. #endif
  5486. #ifndef BCM_CNIC
  5487. /* set NIC mode */
  5488. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5489. #endif /* BCM_CNIC */
  5490. if (!CHIP_IS_E1x(bp)) {
  5491. u32 pf_conf = IGU_PF_CONF_FUNC_EN;
  5492. /* Turn on a single ISR mode in IGU if driver is going to use
  5493. * INT#x or MSI
  5494. */
  5495. if (!(bp->flags & USING_MSIX_FLAG))
  5496. pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  5497. /*
  5498. * Timers workaround bug: function init part.
  5499. * Need to wait 20msec after initializing ILT,
  5500. * needed to make sure there are no requests in
  5501. * one of the PXP internal queues with "old" ILT addresses
  5502. */
  5503. msleep(20);
  5504. /*
  5505. * Master enable - Due to WB DMAE writes performed before this
  5506. * register is re-initialized as part of the regular function
  5507. * init
  5508. */
  5509. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  5510. /* Enable the function in IGU */
  5511. REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
  5512. }
  5513. bp->dmae_ready = 1;
  5514. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  5515. if (!CHIP_IS_E1x(bp))
  5516. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
  5517. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  5518. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  5519. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  5520. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  5521. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  5522. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  5523. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  5524. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  5525. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  5526. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  5527. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  5528. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  5529. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  5530. if (!CHIP_IS_E1x(bp))
  5531. REG_WR(bp, QM_REG_PF_EN, 1);
  5532. if (!CHIP_IS_E1x(bp)) {
  5533. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  5534. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  5535. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  5536. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  5537. }
  5538. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  5539. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  5540. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  5541. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  5542. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  5543. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  5544. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  5545. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  5546. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  5547. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  5548. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  5549. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  5550. if (!CHIP_IS_E1x(bp))
  5551. REG_WR(bp, PBF_REG_DISABLE_PF, 0);
  5552. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  5553. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  5554. if (!CHIP_IS_E1x(bp))
  5555. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
  5556. if (IS_MF(bp)) {
  5557. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  5558. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
  5559. }
  5560. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  5561. /* HC init per function */
  5562. if (bp->common.int_block == INT_BLOCK_HC) {
  5563. if (CHIP_IS_E1H(bp)) {
  5564. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  5565. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  5566. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  5567. }
  5568. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  5569. } else {
  5570. int num_segs, sb_idx, prod_offset;
  5571. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  5572. if (!CHIP_IS_E1x(bp)) {
  5573. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  5574. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  5575. }
  5576. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  5577. if (!CHIP_IS_E1x(bp)) {
  5578. int dsb_idx = 0;
  5579. /**
  5580. * Producer memory:
  5581. * E2 mode: address 0-135 match to the mapping memory;
  5582. * 136 - PF0 default prod; 137 - PF1 default prod;
  5583. * 138 - PF2 default prod; 139 - PF3 default prod;
  5584. * 140 - PF0 attn prod; 141 - PF1 attn prod;
  5585. * 142 - PF2 attn prod; 143 - PF3 attn prod;
  5586. * 144-147 reserved.
  5587. *
  5588. * E1.5 mode - In backward compatible mode;
  5589. * for non default SB; each even line in the memory
  5590. * holds the U producer and each odd line hold
  5591. * the C producer. The first 128 producers are for
  5592. * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
  5593. * producers are for the DSB for each PF.
  5594. * Each PF has five segments: (the order inside each
  5595. * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
  5596. * 132-135 C prods; 136-139 X prods; 140-143 T prods;
  5597. * 144-147 attn prods;
  5598. */
  5599. /* non-default-status-blocks */
  5600. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  5601. IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
  5602. for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
  5603. prod_offset = (bp->igu_base_sb + sb_idx) *
  5604. num_segs;
  5605. for (i = 0; i < num_segs; i++) {
  5606. addr = IGU_REG_PROD_CONS_MEMORY +
  5607. (prod_offset + i) * 4;
  5608. REG_WR(bp, addr, 0);
  5609. }
  5610. /* send consumer update with value 0 */
  5611. bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
  5612. USTORM_ID, 0, IGU_INT_NOP, 1);
  5613. bnx2x_igu_clear_sb(bp,
  5614. bp->igu_base_sb + sb_idx);
  5615. }
  5616. /* default-status-blocks */
  5617. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  5618. IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
  5619. if (CHIP_MODE_IS_4_PORT(bp))
  5620. dsb_idx = BP_FUNC(bp);
  5621. else
  5622. dsb_idx = BP_VN(bp);
  5623. prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
  5624. IGU_BC_BASE_DSB_PROD + dsb_idx :
  5625. IGU_NORM_BASE_DSB_PROD + dsb_idx);
  5626. /*
  5627. * igu prods come in chunks of E1HVN_MAX (4) -
  5628. * does not matters what is the current chip mode
  5629. */
  5630. for (i = 0; i < (num_segs * E1HVN_MAX);
  5631. i += E1HVN_MAX) {
  5632. addr = IGU_REG_PROD_CONS_MEMORY +
  5633. (prod_offset + i)*4;
  5634. REG_WR(bp, addr, 0);
  5635. }
  5636. /* send consumer update with 0 */
  5637. if (CHIP_INT_MODE_IS_BC(bp)) {
  5638. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  5639. USTORM_ID, 0, IGU_INT_NOP, 1);
  5640. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  5641. CSTORM_ID, 0, IGU_INT_NOP, 1);
  5642. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  5643. XSTORM_ID, 0, IGU_INT_NOP, 1);
  5644. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  5645. TSTORM_ID, 0, IGU_INT_NOP, 1);
  5646. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  5647. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  5648. } else {
  5649. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  5650. USTORM_ID, 0, IGU_INT_NOP, 1);
  5651. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  5652. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  5653. }
  5654. bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
  5655. /* !!! these should become driver const once
  5656. rf-tool supports split-68 const */
  5657. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  5658. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  5659. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  5660. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  5661. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  5662. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  5663. }
  5664. }
  5665. /* Reset PCIE errors for debug */
  5666. REG_WR(bp, 0x2114, 0xffffffff);
  5667. REG_WR(bp, 0x2120, 0xffffffff);
  5668. if (CHIP_IS_E1x(bp)) {
  5669. main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
  5670. main_mem_base = HC_REG_MAIN_MEMORY +
  5671. BP_PORT(bp) * (main_mem_size * 4);
  5672. main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
  5673. main_mem_width = 8;
  5674. val = REG_RD(bp, main_mem_prty_clr);
  5675. if (val)
  5676. DP(BNX2X_MSG_MCP, "Hmmm... Parity errors in HC "
  5677. "block during "
  5678. "function init (0x%x)!\n", val);
  5679. /* Clear "false" parity errors in MSI-X table */
  5680. for (i = main_mem_base;
  5681. i < main_mem_base + main_mem_size * 4;
  5682. i += main_mem_width) {
  5683. bnx2x_read_dmae(bp, i, main_mem_width / 4);
  5684. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
  5685. i, main_mem_width / 4);
  5686. }
  5687. /* Clear HC parity attention */
  5688. REG_RD(bp, main_mem_prty_clr);
  5689. }
  5690. #ifdef BNX2X_STOP_ON_ERROR
  5691. /* Enable STORMs SP logging */
  5692. REG_WR8(bp, BAR_USTRORM_INTMEM +
  5693. USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  5694. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  5695. TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  5696. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  5697. CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  5698. REG_WR8(bp, BAR_XSTRORM_INTMEM +
  5699. XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  5700. #endif
  5701. bnx2x_phy_probe(&bp->link_params);
  5702. return 0;
  5703. }
  5704. void bnx2x_free_mem(struct bnx2x *bp)
  5705. {
  5706. /* fastpath */
  5707. bnx2x_free_fp_mem(bp);
  5708. /* end of fastpath */
  5709. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  5710. sizeof(struct host_sp_status_block));
  5711. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  5712. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  5713. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  5714. sizeof(struct bnx2x_slowpath));
  5715. BNX2X_PCI_FREE(bp->context.vcxt, bp->context.cxt_mapping,
  5716. bp->context.size);
  5717. bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
  5718. BNX2X_FREE(bp->ilt->lines);
  5719. #ifdef BCM_CNIC
  5720. if (!CHIP_IS_E1x(bp))
  5721. BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
  5722. sizeof(struct host_hc_status_block_e2));
  5723. else
  5724. BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
  5725. sizeof(struct host_hc_status_block_e1x));
  5726. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  5727. #endif
  5728. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  5729. BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
  5730. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  5731. }
  5732. static inline int bnx2x_alloc_fw_stats_mem(struct bnx2x *bp)
  5733. {
  5734. int num_groups;
  5735. /* number of eth_queues */
  5736. u8 num_queue_stats = BNX2X_NUM_ETH_QUEUES(bp);
  5737. /* Total number of FW statistics requests =
  5738. * 1 for port stats + 1 for PF stats + num_eth_queues */
  5739. bp->fw_stats_num = 2 + num_queue_stats;
  5740. /* Request is built from stats_query_header and an array of
  5741. * stats_query_cmd_group each of which contains
  5742. * STATS_QUERY_CMD_COUNT rules. The real number or requests is
  5743. * configured in the stats_query_header.
  5744. */
  5745. num_groups = (2 + num_queue_stats) / STATS_QUERY_CMD_COUNT +
  5746. (((2 + num_queue_stats) % STATS_QUERY_CMD_COUNT) ? 1 : 0);
  5747. bp->fw_stats_req_sz = sizeof(struct stats_query_header) +
  5748. num_groups * sizeof(struct stats_query_cmd_group);
  5749. /* Data for statistics requests + stats_conter
  5750. *
  5751. * stats_counter holds per-STORM counters that are incremented
  5752. * when STORM has finished with the current request.
  5753. */
  5754. bp->fw_stats_data_sz = sizeof(struct per_port_stats) +
  5755. sizeof(struct per_pf_stats) +
  5756. sizeof(struct per_queue_stats) * num_queue_stats +
  5757. sizeof(struct stats_counter);
  5758. BNX2X_PCI_ALLOC(bp->fw_stats, &bp->fw_stats_mapping,
  5759. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  5760. /* Set shortcuts */
  5761. bp->fw_stats_req = (struct bnx2x_fw_stats_req *)bp->fw_stats;
  5762. bp->fw_stats_req_mapping = bp->fw_stats_mapping;
  5763. bp->fw_stats_data = (struct bnx2x_fw_stats_data *)
  5764. ((u8 *)bp->fw_stats + bp->fw_stats_req_sz);
  5765. bp->fw_stats_data_mapping = bp->fw_stats_mapping +
  5766. bp->fw_stats_req_sz;
  5767. return 0;
  5768. alloc_mem_err:
  5769. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  5770. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  5771. return -ENOMEM;
  5772. }
  5773. int bnx2x_alloc_mem(struct bnx2x *bp)
  5774. {
  5775. #ifdef BCM_CNIC
  5776. if (!CHIP_IS_E1x(bp))
  5777. /* size = the status block + ramrod buffers */
  5778. BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
  5779. sizeof(struct host_hc_status_block_e2));
  5780. else
  5781. BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb, &bp->cnic_sb_mapping,
  5782. sizeof(struct host_hc_status_block_e1x));
  5783. /* allocate searcher T2 table */
  5784. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  5785. #endif
  5786. BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
  5787. sizeof(struct host_sp_status_block));
  5788. BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
  5789. sizeof(struct bnx2x_slowpath));
  5790. /* Allocated memory for FW statistics */
  5791. if (bnx2x_alloc_fw_stats_mem(bp))
  5792. goto alloc_mem_err;
  5793. bp->context.size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
  5794. BNX2X_PCI_ALLOC(bp->context.vcxt, &bp->context.cxt_mapping,
  5795. bp->context.size);
  5796. BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
  5797. if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
  5798. goto alloc_mem_err;
  5799. /* Slow path ring */
  5800. BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
  5801. /* EQ */
  5802. BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
  5803. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  5804. /* fastpath */
  5805. /* need to be done at the end, since it's self adjusting to amount
  5806. * of memory available for RSS queues
  5807. */
  5808. if (bnx2x_alloc_fp_mem(bp))
  5809. goto alloc_mem_err;
  5810. return 0;
  5811. alloc_mem_err:
  5812. bnx2x_free_mem(bp);
  5813. return -ENOMEM;
  5814. }
  5815. /*
  5816. * Init service functions
  5817. */
  5818. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  5819. struct bnx2x_vlan_mac_obj *obj, bool set,
  5820. int mac_type, unsigned long *ramrod_flags)
  5821. {
  5822. int rc;
  5823. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  5824. memset(&ramrod_param, 0, sizeof(ramrod_param));
  5825. /* Fill general parameters */
  5826. ramrod_param.vlan_mac_obj = obj;
  5827. ramrod_param.ramrod_flags = *ramrod_flags;
  5828. /* Fill a user request section if needed */
  5829. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  5830. memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
  5831. __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
  5832. /* Set the command: ADD or DEL */
  5833. if (set)
  5834. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  5835. else
  5836. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  5837. }
  5838. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  5839. if (rc < 0)
  5840. BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
  5841. return rc;
  5842. }
  5843. int bnx2x_del_all_macs(struct bnx2x *bp,
  5844. struct bnx2x_vlan_mac_obj *mac_obj,
  5845. int mac_type, bool wait_for_comp)
  5846. {
  5847. int rc;
  5848. unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
  5849. /* Wait for completion of requested */
  5850. if (wait_for_comp)
  5851. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  5852. /* Set the mac type of addresses we want to clear */
  5853. __set_bit(mac_type, &vlan_mac_flags);
  5854. rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
  5855. if (rc < 0)
  5856. BNX2X_ERR("Failed to delete MACs: %d\n", rc);
  5857. return rc;
  5858. }
  5859. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
  5860. {
  5861. unsigned long ramrod_flags = 0;
  5862. DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
  5863. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  5864. /* Eth MAC is set on RSS leading client (fp[0]) */
  5865. return bnx2x_set_mac_one(bp, bp->dev->dev_addr, &bp->fp->mac_obj, set,
  5866. BNX2X_ETH_MAC, &ramrod_flags);
  5867. }
  5868. int bnx2x_setup_leading(struct bnx2x *bp)
  5869. {
  5870. return bnx2x_setup_queue(bp, &bp->fp[0], 1);
  5871. }
  5872. /**
  5873. * bnx2x_set_int_mode - configure interrupt mode
  5874. *
  5875. * @bp: driver handle
  5876. *
  5877. * In case of MSI-X it will also try to enable MSI-X.
  5878. */
  5879. static void __devinit bnx2x_set_int_mode(struct bnx2x *bp)
  5880. {
  5881. switch (int_mode) {
  5882. case INT_MODE_MSI:
  5883. bnx2x_enable_msi(bp);
  5884. /* falling through... */
  5885. case INT_MODE_INTx:
  5886. bp->num_queues = 1 + NON_ETH_CONTEXT_USE;
  5887. DP(NETIF_MSG_IFUP, "set number of queues to 1\n");
  5888. break;
  5889. default:
  5890. /* Set number of queues according to bp->multi_mode value */
  5891. bnx2x_set_num_queues(bp);
  5892. DP(NETIF_MSG_IFUP, "set number of queues to %d\n",
  5893. bp->num_queues);
  5894. /* if we can't use MSI-X we only need one fp,
  5895. * so try to enable MSI-X with the requested number of fp's
  5896. * and fallback to MSI or legacy INTx with one fp
  5897. */
  5898. if (bnx2x_enable_msix(bp)) {
  5899. /* failed to enable MSI-X */
  5900. if (bp->multi_mode)
  5901. DP(NETIF_MSG_IFUP,
  5902. "Multi requested but failed to "
  5903. "enable MSI-X (%d), "
  5904. "set number of queues to %d\n",
  5905. bp->num_queues,
  5906. 1 + NON_ETH_CONTEXT_USE);
  5907. bp->num_queues = 1 + NON_ETH_CONTEXT_USE;
  5908. /* Try to enable MSI */
  5909. if (!(bp->flags & DISABLE_MSI_FLAG))
  5910. bnx2x_enable_msi(bp);
  5911. }
  5912. break;
  5913. }
  5914. }
  5915. /* must be called prioir to any HW initializations */
  5916. static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
  5917. {
  5918. return L2_ILT_LINES(bp);
  5919. }
  5920. void bnx2x_ilt_set_info(struct bnx2x *bp)
  5921. {
  5922. struct ilt_client_info *ilt_client;
  5923. struct bnx2x_ilt *ilt = BP_ILT(bp);
  5924. u16 line = 0;
  5925. ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
  5926. DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
  5927. /* CDU */
  5928. ilt_client = &ilt->clients[ILT_CLIENT_CDU];
  5929. ilt_client->client_num = ILT_CLIENT_CDU;
  5930. ilt_client->page_size = CDU_ILT_PAGE_SZ;
  5931. ilt_client->flags = ILT_CLIENT_SKIP_MEM;
  5932. ilt_client->start = line;
  5933. line += bnx2x_cid_ilt_lines(bp);
  5934. #ifdef BCM_CNIC
  5935. line += CNIC_ILT_LINES;
  5936. #endif
  5937. ilt_client->end = line - 1;
  5938. DP(BNX2X_MSG_SP, "ilt client[CDU]: start %d, end %d, psz 0x%x, "
  5939. "flags 0x%x, hw psz %d\n",
  5940. ilt_client->start,
  5941. ilt_client->end,
  5942. ilt_client->page_size,
  5943. ilt_client->flags,
  5944. ilog2(ilt_client->page_size >> 12));
  5945. /* QM */
  5946. if (QM_INIT(bp->qm_cid_count)) {
  5947. ilt_client = &ilt->clients[ILT_CLIENT_QM];
  5948. ilt_client->client_num = ILT_CLIENT_QM;
  5949. ilt_client->page_size = QM_ILT_PAGE_SZ;
  5950. ilt_client->flags = 0;
  5951. ilt_client->start = line;
  5952. /* 4 bytes for each cid */
  5953. line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
  5954. QM_ILT_PAGE_SZ);
  5955. ilt_client->end = line - 1;
  5956. DP(BNX2X_MSG_SP, "ilt client[QM]: start %d, end %d, psz 0x%x, "
  5957. "flags 0x%x, hw psz %d\n",
  5958. ilt_client->start,
  5959. ilt_client->end,
  5960. ilt_client->page_size,
  5961. ilt_client->flags,
  5962. ilog2(ilt_client->page_size >> 12));
  5963. }
  5964. /* SRC */
  5965. ilt_client = &ilt->clients[ILT_CLIENT_SRC];
  5966. #ifdef BCM_CNIC
  5967. ilt_client->client_num = ILT_CLIENT_SRC;
  5968. ilt_client->page_size = SRC_ILT_PAGE_SZ;
  5969. ilt_client->flags = 0;
  5970. ilt_client->start = line;
  5971. line += SRC_ILT_LINES;
  5972. ilt_client->end = line - 1;
  5973. DP(BNX2X_MSG_SP, "ilt client[SRC]: start %d, end %d, psz 0x%x, "
  5974. "flags 0x%x, hw psz %d\n",
  5975. ilt_client->start,
  5976. ilt_client->end,
  5977. ilt_client->page_size,
  5978. ilt_client->flags,
  5979. ilog2(ilt_client->page_size >> 12));
  5980. #else
  5981. ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM);
  5982. #endif
  5983. /* TM */
  5984. ilt_client = &ilt->clients[ILT_CLIENT_TM];
  5985. #ifdef BCM_CNIC
  5986. ilt_client->client_num = ILT_CLIENT_TM;
  5987. ilt_client->page_size = TM_ILT_PAGE_SZ;
  5988. ilt_client->flags = 0;
  5989. ilt_client->start = line;
  5990. line += TM_ILT_LINES;
  5991. ilt_client->end = line - 1;
  5992. DP(BNX2X_MSG_SP, "ilt client[TM]: start %d, end %d, psz 0x%x, "
  5993. "flags 0x%x, hw psz %d\n",
  5994. ilt_client->start,
  5995. ilt_client->end,
  5996. ilt_client->page_size,
  5997. ilt_client->flags,
  5998. ilog2(ilt_client->page_size >> 12));
  5999. #else
  6000. ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM);
  6001. #endif
  6002. BUG_ON(line > ILT_MAX_LINES);
  6003. }
  6004. /**
  6005. * bnx2x_pf_q_prep_init - prepare INIT transition parameters
  6006. *
  6007. * @bp: driver handle
  6008. * @fp: pointer to fastpath
  6009. * @init_params: pointer to parameters structure
  6010. *
  6011. * parameters configured:
  6012. * - HC configuration
  6013. * - Queue's CDU context
  6014. */
  6015. static inline void bnx2x_pf_q_prep_init(struct bnx2x *bp,
  6016. struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
  6017. {
  6018. u8 cos;
  6019. /* FCoE Queue uses Default SB, thus has no HC capabilities */
  6020. if (!IS_FCOE_FP(fp)) {
  6021. __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
  6022. __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
  6023. /* If HC is supporterd, enable host coalescing in the transition
  6024. * to INIT state.
  6025. */
  6026. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
  6027. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
  6028. /* HC rate */
  6029. init_params->rx.hc_rate = bp->rx_ticks ?
  6030. (1000000 / bp->rx_ticks) : 0;
  6031. init_params->tx.hc_rate = bp->tx_ticks ?
  6032. (1000000 / bp->tx_ticks) : 0;
  6033. /* FW SB ID */
  6034. init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
  6035. fp->fw_sb_id;
  6036. /*
  6037. * CQ index among the SB indices: FCoE clients uses the default
  6038. * SB, therefore it's different.
  6039. */
  6040. init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  6041. init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
  6042. }
  6043. /* set maximum number of COSs supported by this queue */
  6044. init_params->max_cos = fp->max_cos;
  6045. DP(BNX2X_MSG_SP, "fp: %d setting queue params max cos to: %d\n",
  6046. fp->index, init_params->max_cos);
  6047. /* set the context pointers queue object */
  6048. for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++)
  6049. init_params->cxts[cos] =
  6050. &bp->context.vcxt[fp->txdata[cos].cid].eth;
  6051. }
  6052. int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6053. struct bnx2x_queue_state_params *q_params,
  6054. struct bnx2x_queue_setup_tx_only_params *tx_only_params,
  6055. int tx_index, bool leading)
  6056. {
  6057. memset(tx_only_params, 0, sizeof(*tx_only_params));
  6058. /* Set the command */
  6059. q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  6060. /* Set tx-only QUEUE flags: don't zero statistics */
  6061. tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
  6062. /* choose the index of the cid to send the slow path on */
  6063. tx_only_params->cid_index = tx_index;
  6064. /* Set general TX_ONLY_SETUP parameters */
  6065. bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
  6066. /* Set Tx TX_ONLY_SETUP parameters */
  6067. bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
  6068. DP(BNX2X_MSG_SP, "preparing to send tx-only ramrod for connection:"
  6069. "cos %d, primary cid %d, cid %d, "
  6070. "client id %d, sp-client id %d, flags %lx\n",
  6071. tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
  6072. q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
  6073. tx_only_params->gen_params.spcl_id, tx_only_params->flags);
  6074. /* send the ramrod */
  6075. return bnx2x_queue_state_change(bp, q_params);
  6076. }
  6077. /**
  6078. * bnx2x_setup_queue - setup queue
  6079. *
  6080. * @bp: driver handle
  6081. * @fp: pointer to fastpath
  6082. * @leading: is leading
  6083. *
  6084. * This function performs 2 steps in a Queue state machine
  6085. * actually: 1) RESET->INIT 2) INIT->SETUP
  6086. */
  6087. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6088. bool leading)
  6089. {
  6090. struct bnx2x_queue_state_params q_params = {0};
  6091. struct bnx2x_queue_setup_params *setup_params =
  6092. &q_params.params.setup;
  6093. struct bnx2x_queue_setup_tx_only_params *tx_only_params =
  6094. &q_params.params.tx_only;
  6095. int rc;
  6096. u8 tx_index;
  6097. DP(BNX2X_MSG_SP, "setting up queue %d\n", fp->index);
  6098. /* reset IGU state skip FCoE L2 queue */
  6099. if (!IS_FCOE_FP(fp))
  6100. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
  6101. IGU_INT_ENABLE, 0);
  6102. q_params.q_obj = &fp->q_obj;
  6103. /* We want to wait for completion in this context */
  6104. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6105. /* Prepare the INIT parameters */
  6106. bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
  6107. /* Set the command */
  6108. q_params.cmd = BNX2X_Q_CMD_INIT;
  6109. /* Change the state to INIT */
  6110. rc = bnx2x_queue_state_change(bp, &q_params);
  6111. if (rc) {
  6112. BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
  6113. return rc;
  6114. }
  6115. DP(BNX2X_MSG_SP, "init complete\n");
  6116. /* Now move the Queue to the SETUP state... */
  6117. memset(setup_params, 0, sizeof(*setup_params));
  6118. /* Set QUEUE flags */
  6119. setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
  6120. /* Set general SETUP parameters */
  6121. bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
  6122. FIRST_TX_COS_INDEX);
  6123. bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
  6124. &setup_params->rxq_params);
  6125. bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
  6126. FIRST_TX_COS_INDEX);
  6127. /* Set the command */
  6128. q_params.cmd = BNX2X_Q_CMD_SETUP;
  6129. /* Change the state to SETUP */
  6130. rc = bnx2x_queue_state_change(bp, &q_params);
  6131. if (rc) {
  6132. BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
  6133. return rc;
  6134. }
  6135. /* loop through the relevant tx-only indices */
  6136. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6137. tx_index < fp->max_cos;
  6138. tx_index++) {
  6139. /* prepare and send tx-only ramrod*/
  6140. rc = bnx2x_setup_tx_only(bp, fp, &q_params,
  6141. tx_only_params, tx_index, leading);
  6142. if (rc) {
  6143. BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
  6144. fp->index, tx_index);
  6145. return rc;
  6146. }
  6147. }
  6148. return rc;
  6149. }
  6150. static int bnx2x_stop_queue(struct bnx2x *bp, int index)
  6151. {
  6152. struct bnx2x_fastpath *fp = &bp->fp[index];
  6153. struct bnx2x_fp_txdata *txdata;
  6154. struct bnx2x_queue_state_params q_params = {0};
  6155. int rc, tx_index;
  6156. DP(BNX2X_MSG_SP, "stopping queue %d cid %d\n", index, fp->cid);
  6157. q_params.q_obj = &fp->q_obj;
  6158. /* We want to wait for completion in this context */
  6159. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6160. /* close tx-only connections */
  6161. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6162. tx_index < fp->max_cos;
  6163. tx_index++){
  6164. /* ascertain this is a normal queue*/
  6165. txdata = &fp->txdata[tx_index];
  6166. DP(BNX2X_MSG_SP, "stopping tx-only queue %d\n",
  6167. txdata->txq_index);
  6168. /* send halt terminate on tx-only connection */
  6169. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6170. memset(&q_params.params.terminate, 0,
  6171. sizeof(q_params.params.terminate));
  6172. q_params.params.terminate.cid_index = tx_index;
  6173. rc = bnx2x_queue_state_change(bp, &q_params);
  6174. if (rc)
  6175. return rc;
  6176. /* send halt terminate on tx-only connection */
  6177. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6178. memset(&q_params.params.cfc_del, 0,
  6179. sizeof(q_params.params.cfc_del));
  6180. q_params.params.cfc_del.cid_index = tx_index;
  6181. rc = bnx2x_queue_state_change(bp, &q_params);
  6182. if (rc)
  6183. return rc;
  6184. }
  6185. /* Stop the primary connection: */
  6186. /* ...halt the connection */
  6187. q_params.cmd = BNX2X_Q_CMD_HALT;
  6188. rc = bnx2x_queue_state_change(bp, &q_params);
  6189. if (rc)
  6190. return rc;
  6191. /* ...terminate the connection */
  6192. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6193. memset(&q_params.params.terminate, 0,
  6194. sizeof(q_params.params.terminate));
  6195. q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
  6196. rc = bnx2x_queue_state_change(bp, &q_params);
  6197. if (rc)
  6198. return rc;
  6199. /* ...delete cfc entry */
  6200. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6201. memset(&q_params.params.cfc_del, 0,
  6202. sizeof(q_params.params.cfc_del));
  6203. q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
  6204. return bnx2x_queue_state_change(bp, &q_params);
  6205. }
  6206. static void bnx2x_reset_func(struct bnx2x *bp)
  6207. {
  6208. int port = BP_PORT(bp);
  6209. int func = BP_FUNC(bp);
  6210. int i;
  6211. /* Disable the function in the FW */
  6212. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
  6213. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
  6214. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
  6215. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
  6216. /* FP SBs */
  6217. for_each_eth_queue(bp, i) {
  6218. struct bnx2x_fastpath *fp = &bp->fp[i];
  6219. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6220. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
  6221. SB_DISABLED);
  6222. }
  6223. #ifdef BCM_CNIC
  6224. /* CNIC SB */
  6225. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6226. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(bnx2x_cnic_fw_sb_id(bp)),
  6227. SB_DISABLED);
  6228. #endif
  6229. /* SP SB */
  6230. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6231. CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
  6232. SB_DISABLED);
  6233. for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
  6234. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
  6235. 0);
  6236. /* Configure IGU */
  6237. if (bp->common.int_block == INT_BLOCK_HC) {
  6238. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6239. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6240. } else {
  6241. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6242. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6243. }
  6244. #ifdef BCM_CNIC
  6245. /* Disable Timer scan */
  6246. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  6247. /*
  6248. * Wait for at least 10ms and up to 2 second for the timers scan to
  6249. * complete
  6250. */
  6251. for (i = 0; i < 200; i++) {
  6252. msleep(10);
  6253. if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
  6254. break;
  6255. }
  6256. #endif
  6257. /* Clear ILT */
  6258. bnx2x_clear_func_ilt(bp, func);
  6259. /* Timers workaround bug for E2: if this is vnic-3,
  6260. * we need to set the entire ilt range for this timers.
  6261. */
  6262. if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
  6263. struct ilt_client_info ilt_cli;
  6264. /* use dummy TM client */
  6265. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  6266. ilt_cli.start = 0;
  6267. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  6268. ilt_cli.client_num = ILT_CLIENT_TM;
  6269. bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
  6270. }
  6271. /* this assumes that reset_port() called before reset_func()*/
  6272. if (!CHIP_IS_E1x(bp))
  6273. bnx2x_pf_disable(bp);
  6274. bp->dmae_ready = 0;
  6275. }
  6276. static void bnx2x_reset_port(struct bnx2x *bp)
  6277. {
  6278. int port = BP_PORT(bp);
  6279. u32 val;
  6280. /* Reset physical Link */
  6281. bnx2x__link_reset(bp);
  6282. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  6283. /* Do not rcv packets to BRB */
  6284. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  6285. /* Do not direct rcv packets that are not for MCP to the BRB */
  6286. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  6287. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  6288. /* Configure AEU */
  6289. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  6290. msleep(100);
  6291. /* Check for BRB port occupancy */
  6292. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  6293. if (val)
  6294. DP(NETIF_MSG_IFDOWN,
  6295. "BRB1 is not empty %d blocks are occupied\n", val);
  6296. /* TODO: Close Doorbell port? */
  6297. }
  6298. static inline int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
  6299. {
  6300. struct bnx2x_func_state_params func_params = {0};
  6301. /* Prepare parameters for function state transitions */
  6302. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6303. func_params.f_obj = &bp->func_obj;
  6304. func_params.cmd = BNX2X_F_CMD_HW_RESET;
  6305. func_params.params.hw_init.load_phase = load_code;
  6306. return bnx2x_func_state_change(bp, &func_params);
  6307. }
  6308. static inline int bnx2x_func_stop(struct bnx2x *bp)
  6309. {
  6310. struct bnx2x_func_state_params func_params = {0};
  6311. int rc;
  6312. /* Prepare parameters for function state transitions */
  6313. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6314. func_params.f_obj = &bp->func_obj;
  6315. func_params.cmd = BNX2X_F_CMD_STOP;
  6316. /*
  6317. * Try to stop the function the 'good way'. If fails (in case
  6318. * of a parity error during bnx2x_chip_cleanup()) and we are
  6319. * not in a debug mode, perform a state transaction in order to
  6320. * enable further HW_RESET transaction.
  6321. */
  6322. rc = bnx2x_func_state_change(bp, &func_params);
  6323. if (rc) {
  6324. #ifdef BNX2X_STOP_ON_ERROR
  6325. return rc;
  6326. #else
  6327. BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry "
  6328. "transaction\n");
  6329. __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
  6330. return bnx2x_func_state_change(bp, &func_params);
  6331. #endif
  6332. }
  6333. return 0;
  6334. }
  6335. /**
  6336. * bnx2x_send_unload_req - request unload mode from the MCP.
  6337. *
  6338. * @bp: driver handle
  6339. * @unload_mode: requested function's unload mode
  6340. *
  6341. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  6342. */
  6343. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
  6344. {
  6345. u32 reset_code = 0;
  6346. int port = BP_PORT(bp);
  6347. /* Select the UNLOAD request mode */
  6348. if (unload_mode == UNLOAD_NORMAL)
  6349. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  6350. else if (bp->flags & NO_WOL_FLAG)
  6351. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  6352. else if (bp->wol) {
  6353. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  6354. u8 *mac_addr = bp->dev->dev_addr;
  6355. u32 val;
  6356. u16 pmc;
  6357. /* The mac address is written to entries 1-4 to
  6358. * preserve entry 0 which is used by the PMF
  6359. */
  6360. u8 entry = (BP_VN(bp) + 1)*8;
  6361. val = (mac_addr[0] << 8) | mac_addr[1];
  6362. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  6363. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  6364. (mac_addr[4] << 8) | mac_addr[5];
  6365. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  6366. /* Enable the PME and clear the status */
  6367. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmc);
  6368. pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
  6369. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, pmc);
  6370. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  6371. } else
  6372. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  6373. /* Send the request to the MCP */
  6374. if (!BP_NOMCP(bp))
  6375. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  6376. else {
  6377. int path = BP_PATH(bp);
  6378. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] "
  6379. "%d, %d, %d\n",
  6380. path, load_count[path][0], load_count[path][1],
  6381. load_count[path][2]);
  6382. load_count[path][0]--;
  6383. load_count[path][1 + port]--;
  6384. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] "
  6385. "%d, %d, %d\n",
  6386. path, load_count[path][0], load_count[path][1],
  6387. load_count[path][2]);
  6388. if (load_count[path][0] == 0)
  6389. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  6390. else if (load_count[path][1 + port] == 0)
  6391. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  6392. else
  6393. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  6394. }
  6395. return reset_code;
  6396. }
  6397. /**
  6398. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  6399. *
  6400. * @bp: driver handle
  6401. */
  6402. void bnx2x_send_unload_done(struct bnx2x *bp)
  6403. {
  6404. /* Report UNLOAD_DONE to MCP */
  6405. if (!BP_NOMCP(bp))
  6406. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  6407. }
  6408. static inline int bnx2x_func_wait_started(struct bnx2x *bp)
  6409. {
  6410. int tout = 50;
  6411. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  6412. if (!bp->port.pmf)
  6413. return 0;
  6414. /*
  6415. * (assumption: No Attention from MCP at this stage)
  6416. * PMF probably in the middle of TXdisable/enable transaction
  6417. * 1. Sync IRS for default SB
  6418. * 2. Sync SP queue - this guarantes us that attention handling started
  6419. * 3. Wait, that TXdisable/enable transaction completes
  6420. *
  6421. * 1+2 guranty that if DCBx attention was scheduled it already changed
  6422. * pending bit of transaction from STARTED-->TX_STOPPED, if we alredy
  6423. * received complettion for the transaction the state is TX_STOPPED.
  6424. * State will return to STARTED after completion of TX_STOPPED-->STARTED
  6425. * transaction.
  6426. */
  6427. /* make sure default SB ISR is done */
  6428. if (msix)
  6429. synchronize_irq(bp->msix_table[0].vector);
  6430. else
  6431. synchronize_irq(bp->pdev->irq);
  6432. flush_workqueue(bnx2x_wq);
  6433. while (bnx2x_func_get_state(bp, &bp->func_obj) !=
  6434. BNX2X_F_STATE_STARTED && tout--)
  6435. msleep(20);
  6436. if (bnx2x_func_get_state(bp, &bp->func_obj) !=
  6437. BNX2X_F_STATE_STARTED) {
  6438. #ifdef BNX2X_STOP_ON_ERROR
  6439. return -EBUSY;
  6440. #else
  6441. /*
  6442. * Failed to complete the transaction in a "good way"
  6443. * Force both transactions with CLR bit
  6444. */
  6445. struct bnx2x_func_state_params func_params = {0};
  6446. DP(BNX2X_MSG_SP, "Hmmm... unexpected function state! "
  6447. "Forcing STARTED-->TX_ST0PPED-->STARTED\n");
  6448. func_params.f_obj = &bp->func_obj;
  6449. __set_bit(RAMROD_DRV_CLR_ONLY,
  6450. &func_params.ramrod_flags);
  6451. /* STARTED-->TX_ST0PPED */
  6452. func_params.cmd = BNX2X_F_CMD_TX_STOP;
  6453. bnx2x_func_state_change(bp, &func_params);
  6454. /* TX_ST0PPED-->STARTED */
  6455. func_params.cmd = BNX2X_F_CMD_TX_START;
  6456. return bnx2x_func_state_change(bp, &func_params);
  6457. #endif
  6458. }
  6459. return 0;
  6460. }
  6461. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode)
  6462. {
  6463. int port = BP_PORT(bp);
  6464. int i, rc = 0;
  6465. u8 cos;
  6466. struct bnx2x_mcast_ramrod_params rparam = {0};
  6467. u32 reset_code;
  6468. /* Wait until tx fastpath tasks complete */
  6469. for_each_tx_queue(bp, i) {
  6470. struct bnx2x_fastpath *fp = &bp->fp[i];
  6471. for_each_cos_in_tx_queue(fp, cos)
  6472. rc = bnx2x_clean_tx_queue(bp, &fp->txdata[cos]);
  6473. #ifdef BNX2X_STOP_ON_ERROR
  6474. if (rc)
  6475. return;
  6476. #endif
  6477. }
  6478. /* Give HW time to discard old tx messages */
  6479. usleep_range(1000, 1000);
  6480. /* Clean all ETH MACs */
  6481. rc = bnx2x_del_all_macs(bp, &bp->fp[0].mac_obj, BNX2X_ETH_MAC, false);
  6482. if (rc < 0)
  6483. BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
  6484. /* Clean up UC list */
  6485. rc = bnx2x_del_all_macs(bp, &bp->fp[0].mac_obj, BNX2X_UC_LIST_MAC,
  6486. true);
  6487. if (rc < 0)
  6488. BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: "
  6489. "%d\n", rc);
  6490. /* Disable LLH */
  6491. if (!CHIP_IS_E1(bp))
  6492. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  6493. /* Set "drop all" (stop Rx).
  6494. * We need to take a netif_addr_lock() here in order to prevent
  6495. * a race between the completion code and this code.
  6496. */
  6497. netif_addr_lock_bh(bp->dev);
  6498. /* Schedule the rx_mode command */
  6499. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  6500. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  6501. else
  6502. bnx2x_set_storm_rx_mode(bp);
  6503. /* Cleanup multicast configuration */
  6504. rparam.mcast_obj = &bp->mcast_obj;
  6505. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  6506. if (rc < 0)
  6507. BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
  6508. netif_addr_unlock_bh(bp->dev);
  6509. /*
  6510. * Send the UNLOAD_REQUEST to the MCP. This will return if
  6511. * this function should perform FUNC, PORT or COMMON HW
  6512. * reset.
  6513. */
  6514. reset_code = bnx2x_send_unload_req(bp, unload_mode);
  6515. /*
  6516. * (assumption: No Attention from MCP at this stage)
  6517. * PMF probably in the middle of TXdisable/enable transaction
  6518. */
  6519. rc = bnx2x_func_wait_started(bp);
  6520. if (rc) {
  6521. BNX2X_ERR("bnx2x_func_wait_started failed\n");
  6522. #ifdef BNX2X_STOP_ON_ERROR
  6523. return;
  6524. #endif
  6525. }
  6526. /* Close multi and leading connections
  6527. * Completions for ramrods are collected in a synchronous way
  6528. */
  6529. for_each_queue(bp, i)
  6530. if (bnx2x_stop_queue(bp, i))
  6531. #ifdef BNX2X_STOP_ON_ERROR
  6532. return;
  6533. #else
  6534. goto unload_error;
  6535. #endif
  6536. /* If SP settings didn't get completed so far - something
  6537. * very wrong has happen.
  6538. */
  6539. if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
  6540. BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
  6541. #ifndef BNX2X_STOP_ON_ERROR
  6542. unload_error:
  6543. #endif
  6544. rc = bnx2x_func_stop(bp);
  6545. if (rc) {
  6546. BNX2X_ERR("Function stop failed!\n");
  6547. #ifdef BNX2X_STOP_ON_ERROR
  6548. return;
  6549. #endif
  6550. }
  6551. /* Disable HW interrupts, NAPI */
  6552. bnx2x_netif_stop(bp, 1);
  6553. /* Release IRQs */
  6554. bnx2x_free_irq(bp);
  6555. /* Reset the chip */
  6556. rc = bnx2x_reset_hw(bp, reset_code);
  6557. if (rc)
  6558. BNX2X_ERR("HW_RESET failed\n");
  6559. /* Report UNLOAD_DONE to MCP */
  6560. bnx2x_send_unload_done(bp);
  6561. }
  6562. void bnx2x_disable_close_the_gate(struct bnx2x *bp)
  6563. {
  6564. u32 val;
  6565. DP(NETIF_MSG_HW, "Disabling \"close the gates\"\n");
  6566. if (CHIP_IS_E1(bp)) {
  6567. int port = BP_PORT(bp);
  6568. u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  6569. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  6570. val = REG_RD(bp, addr);
  6571. val &= ~(0x300);
  6572. REG_WR(bp, addr, val);
  6573. } else {
  6574. val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
  6575. val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
  6576. MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
  6577. REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
  6578. }
  6579. }
  6580. /* Close gates #2, #3 and #4: */
  6581. static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
  6582. {
  6583. u32 val;
  6584. /* Gates #2 and #4a are closed/opened for "not E1" only */
  6585. if (!CHIP_IS_E1(bp)) {
  6586. /* #4 */
  6587. REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
  6588. /* #2 */
  6589. REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
  6590. }
  6591. /* #3 */
  6592. if (CHIP_IS_E1x(bp)) {
  6593. /* Prevent interrupts from HC on both ports */
  6594. val = REG_RD(bp, HC_REG_CONFIG_1);
  6595. REG_WR(bp, HC_REG_CONFIG_1,
  6596. (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
  6597. (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
  6598. val = REG_RD(bp, HC_REG_CONFIG_0);
  6599. REG_WR(bp, HC_REG_CONFIG_0,
  6600. (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
  6601. (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
  6602. } else {
  6603. /* Prevent incomming interrupts in IGU */
  6604. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  6605. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
  6606. (!close) ?
  6607. (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
  6608. (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
  6609. }
  6610. DP(NETIF_MSG_HW, "%s gates #2, #3 and #4\n",
  6611. close ? "closing" : "opening");
  6612. mmiowb();
  6613. }
  6614. #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
  6615. static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
  6616. {
  6617. /* Do some magic... */
  6618. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  6619. *magic_val = val & SHARED_MF_CLP_MAGIC;
  6620. MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
  6621. }
  6622. /**
  6623. * bnx2x_clp_reset_done - restore the value of the `magic' bit.
  6624. *
  6625. * @bp: driver handle
  6626. * @magic_val: old value of the `magic' bit.
  6627. */
  6628. static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
  6629. {
  6630. /* Restore the `magic' bit value... */
  6631. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  6632. MF_CFG_WR(bp, shared_mf_config.clp_mb,
  6633. (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
  6634. }
  6635. /**
  6636. * bnx2x_reset_mcp_prep - prepare for MCP reset.
  6637. *
  6638. * @bp: driver handle
  6639. * @magic_val: old value of 'magic' bit.
  6640. *
  6641. * Takes care of CLP configurations.
  6642. */
  6643. static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
  6644. {
  6645. u32 shmem;
  6646. u32 validity_offset;
  6647. DP(NETIF_MSG_HW, "Starting\n");
  6648. /* Set `magic' bit in order to save MF config */
  6649. if (!CHIP_IS_E1(bp))
  6650. bnx2x_clp_reset_prep(bp, magic_val);
  6651. /* Get shmem offset */
  6652. shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  6653. validity_offset = offsetof(struct shmem_region, validity_map[0]);
  6654. /* Clear validity map flags */
  6655. if (shmem > 0)
  6656. REG_WR(bp, shmem + validity_offset, 0);
  6657. }
  6658. #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
  6659. #define MCP_ONE_TIMEOUT 100 /* 100 ms */
  6660. /**
  6661. * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
  6662. *
  6663. * @bp: driver handle
  6664. */
  6665. static inline void bnx2x_mcp_wait_one(struct bnx2x *bp)
  6666. {
  6667. /* special handling for emulation and FPGA,
  6668. wait 10 times longer */
  6669. if (CHIP_REV_IS_SLOW(bp))
  6670. msleep(MCP_ONE_TIMEOUT*10);
  6671. else
  6672. msleep(MCP_ONE_TIMEOUT);
  6673. }
  6674. /*
  6675. * initializes bp->common.shmem_base and waits for validity signature to appear
  6676. */
  6677. static int bnx2x_init_shmem(struct bnx2x *bp)
  6678. {
  6679. int cnt = 0;
  6680. u32 val = 0;
  6681. do {
  6682. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  6683. if (bp->common.shmem_base) {
  6684. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  6685. if (val & SHR_MEM_VALIDITY_MB)
  6686. return 0;
  6687. }
  6688. bnx2x_mcp_wait_one(bp);
  6689. } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
  6690. BNX2X_ERR("BAD MCP validity signature\n");
  6691. return -ENODEV;
  6692. }
  6693. static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
  6694. {
  6695. int rc = bnx2x_init_shmem(bp);
  6696. /* Restore the `magic' bit value */
  6697. if (!CHIP_IS_E1(bp))
  6698. bnx2x_clp_reset_done(bp, magic_val);
  6699. return rc;
  6700. }
  6701. static void bnx2x_pxp_prep(struct bnx2x *bp)
  6702. {
  6703. if (!CHIP_IS_E1(bp)) {
  6704. REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
  6705. REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
  6706. mmiowb();
  6707. }
  6708. }
  6709. /*
  6710. * Reset the whole chip except for:
  6711. * - PCIE core
  6712. * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
  6713. * one reset bit)
  6714. * - IGU
  6715. * - MISC (including AEU)
  6716. * - GRC
  6717. * - RBCN, RBCP
  6718. */
  6719. static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
  6720. {
  6721. u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
  6722. u32 global_bits2, stay_reset2;
  6723. /*
  6724. * Bits that have to be set in reset_mask2 if we want to reset 'global'
  6725. * (per chip) blocks.
  6726. */
  6727. global_bits2 =
  6728. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
  6729. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
  6730. /* Don't reset the following blocks */
  6731. not_reset_mask1 =
  6732. MISC_REGISTERS_RESET_REG_1_RST_HC |
  6733. MISC_REGISTERS_RESET_REG_1_RST_PXPV |
  6734. MISC_REGISTERS_RESET_REG_1_RST_PXP;
  6735. not_reset_mask2 =
  6736. MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
  6737. MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
  6738. MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
  6739. MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
  6740. MISC_REGISTERS_RESET_REG_2_RST_RBCN |
  6741. MISC_REGISTERS_RESET_REG_2_RST_GRC |
  6742. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
  6743. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
  6744. MISC_REGISTERS_RESET_REG_2_RST_ATC |
  6745. MISC_REGISTERS_RESET_REG_2_PGLC;
  6746. /*
  6747. * Keep the following blocks in reset:
  6748. * - all xxMACs are handled by the bnx2x_link code.
  6749. */
  6750. stay_reset2 =
  6751. MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
  6752. MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
  6753. MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
  6754. MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
  6755. MISC_REGISTERS_RESET_REG_2_UMAC0 |
  6756. MISC_REGISTERS_RESET_REG_2_UMAC1 |
  6757. MISC_REGISTERS_RESET_REG_2_XMAC |
  6758. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
  6759. /* Full reset masks according to the chip */
  6760. reset_mask1 = 0xffffffff;
  6761. if (CHIP_IS_E1(bp))
  6762. reset_mask2 = 0xffff;
  6763. else if (CHIP_IS_E1H(bp))
  6764. reset_mask2 = 0x1ffff;
  6765. else if (CHIP_IS_E2(bp))
  6766. reset_mask2 = 0xfffff;
  6767. else /* CHIP_IS_E3 */
  6768. reset_mask2 = 0x3ffffff;
  6769. /* Don't reset global blocks unless we need to */
  6770. if (!global)
  6771. reset_mask2 &= ~global_bits2;
  6772. /*
  6773. * In case of attention in the QM, we need to reset PXP
  6774. * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
  6775. * because otherwise QM reset would release 'close the gates' shortly
  6776. * before resetting the PXP, then the PSWRQ would send a write
  6777. * request to PGLUE. Then when PXP is reset, PGLUE would try to
  6778. * read the payload data from PSWWR, but PSWWR would not
  6779. * respond. The write queue in PGLUE would stuck, dmae commands
  6780. * would not return. Therefore it's important to reset the second
  6781. * reset register (containing the
  6782. * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
  6783. * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
  6784. * bit).
  6785. */
  6786. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  6787. reset_mask2 & (~not_reset_mask2));
  6788. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  6789. reset_mask1 & (~not_reset_mask1));
  6790. barrier();
  6791. mmiowb();
  6792. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  6793. reset_mask2 & (~stay_reset2));
  6794. barrier();
  6795. mmiowb();
  6796. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
  6797. mmiowb();
  6798. }
  6799. /**
  6800. * bnx2x_er_poll_igu_vq - poll for pending writes bit.
  6801. * It should get cleared in no more than 1s.
  6802. *
  6803. * @bp: driver handle
  6804. *
  6805. * It should get cleared in no more than 1s. Returns 0 if
  6806. * pending writes bit gets cleared.
  6807. */
  6808. static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
  6809. {
  6810. u32 cnt = 1000;
  6811. u32 pend_bits = 0;
  6812. do {
  6813. pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
  6814. if (pend_bits == 0)
  6815. break;
  6816. usleep_range(1000, 1000);
  6817. } while (cnt-- > 0);
  6818. if (cnt <= 0) {
  6819. BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
  6820. pend_bits);
  6821. return -EBUSY;
  6822. }
  6823. return 0;
  6824. }
  6825. static int bnx2x_process_kill(struct bnx2x *bp, bool global)
  6826. {
  6827. int cnt = 1000;
  6828. u32 val = 0;
  6829. u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
  6830. /* Empty the Tetris buffer, wait for 1s */
  6831. do {
  6832. sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
  6833. blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
  6834. port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
  6835. port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
  6836. pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
  6837. if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
  6838. ((port_is_idle_0 & 0x1) == 0x1) &&
  6839. ((port_is_idle_1 & 0x1) == 0x1) &&
  6840. (pgl_exp_rom2 == 0xffffffff))
  6841. break;
  6842. usleep_range(1000, 1000);
  6843. } while (cnt-- > 0);
  6844. if (cnt <= 0) {
  6845. DP(NETIF_MSG_HW, "Tetris buffer didn't get empty or there"
  6846. " are still"
  6847. " outstanding read requests after 1s!\n");
  6848. DP(NETIF_MSG_HW, "sr_cnt=0x%08x, blk_cnt=0x%08x,"
  6849. " port_is_idle_0=0x%08x,"
  6850. " port_is_idle_1=0x%08x, pgl_exp_rom2=0x%08x\n",
  6851. sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
  6852. pgl_exp_rom2);
  6853. return -EAGAIN;
  6854. }
  6855. barrier();
  6856. /* Close gates #2, #3 and #4 */
  6857. bnx2x_set_234_gates(bp, true);
  6858. /* Poll for IGU VQs for 57712 and newer chips */
  6859. if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
  6860. return -EAGAIN;
  6861. /* TBD: Indicate that "process kill" is in progress to MCP */
  6862. /* Clear "unprepared" bit */
  6863. REG_WR(bp, MISC_REG_UNPREPARED, 0);
  6864. barrier();
  6865. /* Make sure all is written to the chip before the reset */
  6866. mmiowb();
  6867. /* Wait for 1ms to empty GLUE and PCI-E core queues,
  6868. * PSWHST, GRC and PSWRD Tetris buffer.
  6869. */
  6870. usleep_range(1000, 1000);
  6871. /* Prepare to chip reset: */
  6872. /* MCP */
  6873. if (global)
  6874. bnx2x_reset_mcp_prep(bp, &val);
  6875. /* PXP */
  6876. bnx2x_pxp_prep(bp);
  6877. barrier();
  6878. /* reset the chip */
  6879. bnx2x_process_kill_chip_reset(bp, global);
  6880. barrier();
  6881. /* Recover after reset: */
  6882. /* MCP */
  6883. if (global && bnx2x_reset_mcp_comp(bp, val))
  6884. return -EAGAIN;
  6885. /* TBD: Add resetting the NO_MCP mode DB here */
  6886. /* PXP */
  6887. bnx2x_pxp_prep(bp);
  6888. /* Open the gates #2, #3 and #4 */
  6889. bnx2x_set_234_gates(bp, false);
  6890. /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
  6891. * reset state, re-enable attentions. */
  6892. return 0;
  6893. }
  6894. int bnx2x_leader_reset(struct bnx2x *bp)
  6895. {
  6896. int rc = 0;
  6897. bool global = bnx2x_reset_is_global(bp);
  6898. /* Try to recover after the failure */
  6899. if (bnx2x_process_kill(bp, global)) {
  6900. netdev_err(bp->dev, "Something bad had happen on engine %d! "
  6901. "Aii!\n", BP_PATH(bp));
  6902. rc = -EAGAIN;
  6903. goto exit_leader_reset;
  6904. }
  6905. /*
  6906. * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
  6907. * state.
  6908. */
  6909. bnx2x_set_reset_done(bp);
  6910. if (global)
  6911. bnx2x_clear_reset_global(bp);
  6912. exit_leader_reset:
  6913. bp->is_leader = 0;
  6914. bnx2x_release_leader_lock(bp);
  6915. smp_mb();
  6916. return rc;
  6917. }
  6918. static inline void bnx2x_recovery_failed(struct bnx2x *bp)
  6919. {
  6920. netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
  6921. /* Disconnect this device */
  6922. netif_device_detach(bp->dev);
  6923. /*
  6924. * Block ifup for all function on this engine until "process kill"
  6925. * or power cycle.
  6926. */
  6927. bnx2x_set_reset_in_progress(bp);
  6928. /* Shut down the power */
  6929. bnx2x_set_power_state(bp, PCI_D3hot);
  6930. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  6931. smp_mb();
  6932. }
  6933. /*
  6934. * Assumption: runs under rtnl lock. This together with the fact
  6935. * that it's called only from bnx2x_sp_rtnl() ensure that it
  6936. * will never be called when netif_running(bp->dev) is false.
  6937. */
  6938. static void bnx2x_parity_recover(struct bnx2x *bp)
  6939. {
  6940. bool global = false;
  6941. DP(NETIF_MSG_HW, "Handling parity\n");
  6942. while (1) {
  6943. switch (bp->recovery_state) {
  6944. case BNX2X_RECOVERY_INIT:
  6945. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
  6946. bnx2x_chk_parity_attn(bp, &global, false);
  6947. /* Try to get a LEADER_LOCK HW lock */
  6948. if (bnx2x_trylock_leader_lock(bp)) {
  6949. bnx2x_set_reset_in_progress(bp);
  6950. /*
  6951. * Check if there is a global attention and if
  6952. * there was a global attention, set the global
  6953. * reset bit.
  6954. */
  6955. if (global)
  6956. bnx2x_set_reset_global(bp);
  6957. bp->is_leader = 1;
  6958. }
  6959. /* Stop the driver */
  6960. /* If interface has been removed - break */
  6961. if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY))
  6962. return;
  6963. bp->recovery_state = BNX2X_RECOVERY_WAIT;
  6964. /*
  6965. * Reset MCP command sequence number and MCP mail box
  6966. * sequence as we are going to reset the MCP.
  6967. */
  6968. if (global) {
  6969. bp->fw_seq = 0;
  6970. bp->fw_drv_pulse_wr_seq = 0;
  6971. }
  6972. /* Ensure "is_leader", MCP command sequence and
  6973. * "recovery_state" update values are seen on other
  6974. * CPUs.
  6975. */
  6976. smp_mb();
  6977. break;
  6978. case BNX2X_RECOVERY_WAIT:
  6979. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
  6980. if (bp->is_leader) {
  6981. int other_engine = BP_PATH(bp) ? 0 : 1;
  6982. u32 other_load_counter =
  6983. bnx2x_get_load_cnt(bp, other_engine);
  6984. u32 load_counter =
  6985. bnx2x_get_load_cnt(bp, BP_PATH(bp));
  6986. global = bnx2x_reset_is_global(bp);
  6987. /*
  6988. * In case of a parity in a global block, let
  6989. * the first leader that performs a
  6990. * leader_reset() reset the global blocks in
  6991. * order to clear global attentions. Otherwise
  6992. * the the gates will remain closed for that
  6993. * engine.
  6994. */
  6995. if (load_counter ||
  6996. (global && other_load_counter)) {
  6997. /* Wait until all other functions get
  6998. * down.
  6999. */
  7000. schedule_delayed_work(&bp->sp_rtnl_task,
  7001. HZ/10);
  7002. return;
  7003. } else {
  7004. /* If all other functions got down -
  7005. * try to bring the chip back to
  7006. * normal. In any case it's an exit
  7007. * point for a leader.
  7008. */
  7009. if (bnx2x_leader_reset(bp)) {
  7010. bnx2x_recovery_failed(bp);
  7011. return;
  7012. }
  7013. /* If we are here, means that the
  7014. * leader has succeeded and doesn't
  7015. * want to be a leader any more. Try
  7016. * to continue as a none-leader.
  7017. */
  7018. break;
  7019. }
  7020. } else { /* non-leader */
  7021. if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
  7022. /* Try to get a LEADER_LOCK HW lock as
  7023. * long as a former leader may have
  7024. * been unloaded by the user or
  7025. * released a leadership by another
  7026. * reason.
  7027. */
  7028. if (bnx2x_trylock_leader_lock(bp)) {
  7029. /* I'm a leader now! Restart a
  7030. * switch case.
  7031. */
  7032. bp->is_leader = 1;
  7033. break;
  7034. }
  7035. schedule_delayed_work(&bp->sp_rtnl_task,
  7036. HZ/10);
  7037. return;
  7038. } else {
  7039. /*
  7040. * If there was a global attention, wait
  7041. * for it to be cleared.
  7042. */
  7043. if (bnx2x_reset_is_global(bp)) {
  7044. schedule_delayed_work(
  7045. &bp->sp_rtnl_task,
  7046. HZ/10);
  7047. return;
  7048. }
  7049. if (bnx2x_nic_load(bp, LOAD_NORMAL))
  7050. bnx2x_recovery_failed(bp);
  7051. else {
  7052. bp->recovery_state =
  7053. BNX2X_RECOVERY_DONE;
  7054. smp_mb();
  7055. }
  7056. return;
  7057. }
  7058. }
  7059. default:
  7060. return;
  7061. }
  7062. }
  7063. }
  7064. /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
  7065. * scheduled on a general queue in order to prevent a dead lock.
  7066. */
  7067. static void bnx2x_sp_rtnl_task(struct work_struct *work)
  7068. {
  7069. struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
  7070. rtnl_lock();
  7071. if (!netif_running(bp->dev))
  7072. goto sp_rtnl_exit;
  7073. /* if stop on error is defined no recovery flows should be executed */
  7074. #ifdef BNX2X_STOP_ON_ERROR
  7075. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined "
  7076. "so reset not done to allow debug dump,\n"
  7077. "you will need to reboot when done\n");
  7078. goto sp_rtnl_not_reset;
  7079. #endif
  7080. if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
  7081. /*
  7082. * Clear all pending SP commands as we are going to reset the
  7083. * function anyway.
  7084. */
  7085. bp->sp_rtnl_state = 0;
  7086. smp_mb();
  7087. bnx2x_parity_recover(bp);
  7088. goto sp_rtnl_exit;
  7089. }
  7090. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
  7091. /*
  7092. * Clear all pending SP commands as we are going to reset the
  7093. * function anyway.
  7094. */
  7095. bp->sp_rtnl_state = 0;
  7096. smp_mb();
  7097. bnx2x_nic_unload(bp, UNLOAD_NORMAL);
  7098. bnx2x_nic_load(bp, LOAD_NORMAL);
  7099. goto sp_rtnl_exit;
  7100. }
  7101. #ifdef BNX2X_STOP_ON_ERROR
  7102. sp_rtnl_not_reset:
  7103. #endif
  7104. if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
  7105. bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
  7106. sp_rtnl_exit:
  7107. rtnl_unlock();
  7108. }
  7109. /* end of nic load/unload */
  7110. static void bnx2x_period_task(struct work_struct *work)
  7111. {
  7112. struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
  7113. if (!netif_running(bp->dev))
  7114. goto period_task_exit;
  7115. if (CHIP_REV_IS_SLOW(bp)) {
  7116. BNX2X_ERR("period task called on emulation, ignoring\n");
  7117. goto period_task_exit;
  7118. }
  7119. bnx2x_acquire_phy_lock(bp);
  7120. /*
  7121. * The barrier is needed to ensure the ordering between the writing to
  7122. * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
  7123. * the reading here.
  7124. */
  7125. smp_mb();
  7126. if (bp->port.pmf) {
  7127. bnx2x_period_func(&bp->link_params, &bp->link_vars);
  7128. /* Re-queue task in 1 sec */
  7129. queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
  7130. }
  7131. bnx2x_release_phy_lock(bp);
  7132. period_task_exit:
  7133. return;
  7134. }
  7135. /*
  7136. * Init service functions
  7137. */
  7138. static u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
  7139. {
  7140. u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
  7141. u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
  7142. return base + (BP_ABS_FUNC(bp)) * stride;
  7143. }
  7144. static void bnx2x_undi_int_disable_e1h(struct bnx2x *bp)
  7145. {
  7146. u32 reg = bnx2x_get_pretend_reg(bp);
  7147. /* Flush all outstanding writes */
  7148. mmiowb();
  7149. /* Pretend to be function 0 */
  7150. REG_WR(bp, reg, 0);
  7151. REG_RD(bp, reg); /* Flush the GRC transaction (in the chip) */
  7152. /* From now we are in the "like-E1" mode */
  7153. bnx2x_int_disable(bp);
  7154. /* Flush all outstanding writes */
  7155. mmiowb();
  7156. /* Restore the original function */
  7157. REG_WR(bp, reg, BP_ABS_FUNC(bp));
  7158. REG_RD(bp, reg);
  7159. }
  7160. static inline void bnx2x_undi_int_disable(struct bnx2x *bp)
  7161. {
  7162. if (CHIP_IS_E1(bp))
  7163. bnx2x_int_disable(bp);
  7164. else
  7165. bnx2x_undi_int_disable_e1h(bp);
  7166. }
  7167. static void __devinit bnx2x_undi_unload(struct bnx2x *bp)
  7168. {
  7169. u32 val;
  7170. /* Check if there is any driver already loaded */
  7171. val = REG_RD(bp, MISC_REG_UNPREPARED);
  7172. if (val == 0x1) {
  7173. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  7174. /*
  7175. * Check if it is the UNDI driver
  7176. * UNDI driver initializes CID offset for normal bell to 0x7
  7177. */
  7178. val = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
  7179. if (val == 0x7) {
  7180. u32 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7181. /* save our pf_num */
  7182. int orig_pf_num = bp->pf_num;
  7183. int port;
  7184. u32 swap_en, swap_val, value;
  7185. /* clear the UNDI indication */
  7186. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  7187. BNX2X_DEV_INFO("UNDI is active! reset device\n");
  7188. /* try unload UNDI on port 0 */
  7189. bp->pf_num = 0;
  7190. bp->fw_seq =
  7191. (SHMEM_RD(bp, func_mb[bp->pf_num].drv_mb_header) &
  7192. DRV_MSG_SEQ_NUMBER_MASK);
  7193. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  7194. /* if UNDI is loaded on the other port */
  7195. if (reset_code != FW_MSG_CODE_DRV_UNLOAD_COMMON) {
  7196. /* send "DONE" for previous unload */
  7197. bnx2x_fw_command(bp,
  7198. DRV_MSG_CODE_UNLOAD_DONE, 0);
  7199. /* unload UNDI on port 1 */
  7200. bp->pf_num = 1;
  7201. bp->fw_seq =
  7202. (SHMEM_RD(bp, func_mb[bp->pf_num].drv_mb_header) &
  7203. DRV_MSG_SEQ_NUMBER_MASK);
  7204. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7205. bnx2x_fw_command(bp, reset_code, 0);
  7206. }
  7207. bnx2x_undi_int_disable(bp);
  7208. port = BP_PORT(bp);
  7209. /* close input traffic and wait for it */
  7210. /* Do not rcv packets to BRB */
  7211. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_DRV_MASK :
  7212. NIG_REG_LLH0_BRB1_DRV_MASK), 0x0);
  7213. /* Do not direct rcv packets that are not for MCP to
  7214. * the BRB */
  7215. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  7216. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  7217. /* clear AEU */
  7218. REG_WR(bp, (port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  7219. MISC_REG_AEU_MASK_ATTN_FUNC_0), 0);
  7220. msleep(10);
  7221. /* save NIG port swap info */
  7222. swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
  7223. swap_en = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
  7224. /* reset device */
  7225. REG_WR(bp,
  7226. GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  7227. 0xd3ffffff);
  7228. value = 0x1400;
  7229. if (CHIP_IS_E3(bp)) {
  7230. value |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  7231. value |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  7232. }
  7233. REG_WR(bp,
  7234. GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  7235. value);
  7236. /* take the NIG out of reset and restore swap values */
  7237. REG_WR(bp,
  7238. GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  7239. MISC_REGISTERS_RESET_REG_1_RST_NIG);
  7240. REG_WR(bp, NIG_REG_PORT_SWAP, swap_val);
  7241. REG_WR(bp, NIG_REG_STRAP_OVERRIDE, swap_en);
  7242. /* send unload done to the MCP */
  7243. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  7244. /* restore our func and fw_seq */
  7245. bp->pf_num = orig_pf_num;
  7246. bp->fw_seq =
  7247. (SHMEM_RD(bp, func_mb[bp->pf_num].drv_mb_header) &
  7248. DRV_MSG_SEQ_NUMBER_MASK);
  7249. }
  7250. /* now it's safe to release the lock */
  7251. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  7252. }
  7253. }
  7254. static void __devinit bnx2x_get_common_hwinfo(struct bnx2x *bp)
  7255. {
  7256. u32 val, val2, val3, val4, id;
  7257. u16 pmc;
  7258. /* Get the chip revision id and number. */
  7259. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  7260. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  7261. id = ((val & 0xffff) << 16);
  7262. val = REG_RD(bp, MISC_REG_CHIP_REV);
  7263. id |= ((val & 0xf) << 12);
  7264. val = REG_RD(bp, MISC_REG_CHIP_METAL);
  7265. id |= ((val & 0xff) << 4);
  7266. val = REG_RD(bp, MISC_REG_BOND_ID);
  7267. id |= (val & 0xf);
  7268. bp->common.chip_id = id;
  7269. /* Set doorbell size */
  7270. bp->db_size = (1 << BNX2X_DB_SHIFT);
  7271. if (!CHIP_IS_E1x(bp)) {
  7272. val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  7273. if ((val & 1) == 0)
  7274. val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
  7275. else
  7276. val = (val >> 1) & 1;
  7277. BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
  7278. "2_PORT_MODE");
  7279. bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
  7280. CHIP_2_PORT_MODE;
  7281. if (CHIP_MODE_IS_4_PORT(bp))
  7282. bp->pfid = (bp->pf_num >> 1); /* 0..3 */
  7283. else
  7284. bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
  7285. } else {
  7286. bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
  7287. bp->pfid = bp->pf_num; /* 0..7 */
  7288. }
  7289. bp->link_params.chip_id = bp->common.chip_id;
  7290. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  7291. val = (REG_RD(bp, 0x2874) & 0x55);
  7292. if ((bp->common.chip_id & 0x1) ||
  7293. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  7294. bp->flags |= ONE_PORT_FLAG;
  7295. BNX2X_DEV_INFO("single port device\n");
  7296. }
  7297. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  7298. bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
  7299. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  7300. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  7301. bp->common.flash_size, bp->common.flash_size);
  7302. bnx2x_init_shmem(bp);
  7303. bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
  7304. MISC_REG_GENERIC_CR_1 :
  7305. MISC_REG_GENERIC_CR_0));
  7306. bp->link_params.shmem_base = bp->common.shmem_base;
  7307. bp->link_params.shmem2_base = bp->common.shmem2_base;
  7308. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  7309. bp->common.shmem_base, bp->common.shmem2_base);
  7310. if (!bp->common.shmem_base) {
  7311. BNX2X_DEV_INFO("MCP not active\n");
  7312. bp->flags |= NO_MCP_FLAG;
  7313. return;
  7314. }
  7315. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  7316. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  7317. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  7318. SHARED_HW_CFG_LED_MODE_MASK) >>
  7319. SHARED_HW_CFG_LED_MODE_SHIFT);
  7320. bp->link_params.feature_config_flags = 0;
  7321. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  7322. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  7323. bp->link_params.feature_config_flags |=
  7324. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  7325. else
  7326. bp->link_params.feature_config_flags &=
  7327. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  7328. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  7329. bp->common.bc_ver = val;
  7330. BNX2X_DEV_INFO("bc_ver %X\n", val);
  7331. if (val < BNX2X_BC_VER) {
  7332. /* for now only warn
  7333. * later we might need to enforce this */
  7334. BNX2X_ERR("This driver needs bc_ver %X but found %X, "
  7335. "please upgrade BC\n", BNX2X_BC_VER, val);
  7336. }
  7337. bp->link_params.feature_config_flags |=
  7338. (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
  7339. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  7340. bp->link_params.feature_config_flags |=
  7341. (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
  7342. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
  7343. bp->link_params.feature_config_flags |=
  7344. (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
  7345. FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
  7346. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
  7347. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  7348. BNX2X_DEV_INFO("%sWoL capable\n",
  7349. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  7350. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  7351. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  7352. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  7353. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  7354. dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
  7355. val, val2, val3, val4);
  7356. }
  7357. #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
  7358. #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
  7359. static void __devinit bnx2x_get_igu_cam_info(struct bnx2x *bp)
  7360. {
  7361. int pfid = BP_FUNC(bp);
  7362. int igu_sb_id;
  7363. u32 val;
  7364. u8 fid, igu_sb_cnt = 0;
  7365. bp->igu_base_sb = 0xff;
  7366. if (CHIP_INT_MODE_IS_BC(bp)) {
  7367. int vn = BP_VN(bp);
  7368. igu_sb_cnt = bp->igu_sb_cnt;
  7369. bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
  7370. FP_SB_MAX_E1x;
  7371. bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
  7372. (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
  7373. return;
  7374. }
  7375. /* IGU in normal mode - read CAM */
  7376. for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
  7377. igu_sb_id++) {
  7378. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
  7379. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  7380. continue;
  7381. fid = IGU_FID(val);
  7382. if ((fid & IGU_FID_ENCODE_IS_PF)) {
  7383. if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
  7384. continue;
  7385. if (IGU_VEC(val) == 0)
  7386. /* default status block */
  7387. bp->igu_dsb_id = igu_sb_id;
  7388. else {
  7389. if (bp->igu_base_sb == 0xff)
  7390. bp->igu_base_sb = igu_sb_id;
  7391. igu_sb_cnt++;
  7392. }
  7393. }
  7394. }
  7395. #ifdef CONFIG_PCI_MSI
  7396. /*
  7397. * It's expected that number of CAM entries for this functions is equal
  7398. * to the number evaluated based on the MSI-X table size. We want a
  7399. * harsh warning if these values are different!
  7400. */
  7401. WARN_ON(bp->igu_sb_cnt != igu_sb_cnt);
  7402. #endif
  7403. if (igu_sb_cnt == 0)
  7404. BNX2X_ERR("CAM configuration error\n");
  7405. }
  7406. static void __devinit bnx2x_link_settings_supported(struct bnx2x *bp,
  7407. u32 switch_cfg)
  7408. {
  7409. int cfg_size = 0, idx, port = BP_PORT(bp);
  7410. /* Aggregation of supported attributes of all external phys */
  7411. bp->port.supported[0] = 0;
  7412. bp->port.supported[1] = 0;
  7413. switch (bp->link_params.num_phys) {
  7414. case 1:
  7415. bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
  7416. cfg_size = 1;
  7417. break;
  7418. case 2:
  7419. bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
  7420. cfg_size = 1;
  7421. break;
  7422. case 3:
  7423. if (bp->link_params.multi_phy_config &
  7424. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  7425. bp->port.supported[1] =
  7426. bp->link_params.phy[EXT_PHY1].supported;
  7427. bp->port.supported[0] =
  7428. bp->link_params.phy[EXT_PHY2].supported;
  7429. } else {
  7430. bp->port.supported[0] =
  7431. bp->link_params.phy[EXT_PHY1].supported;
  7432. bp->port.supported[1] =
  7433. bp->link_params.phy[EXT_PHY2].supported;
  7434. }
  7435. cfg_size = 2;
  7436. break;
  7437. }
  7438. if (!(bp->port.supported[0] || bp->port.supported[1])) {
  7439. BNX2X_ERR("NVRAM config error. BAD phy config."
  7440. "PHY1 config 0x%x, PHY2 config 0x%x\n",
  7441. SHMEM_RD(bp,
  7442. dev_info.port_hw_config[port].external_phy_config),
  7443. SHMEM_RD(bp,
  7444. dev_info.port_hw_config[port].external_phy_config2));
  7445. return;
  7446. }
  7447. if (CHIP_IS_E3(bp))
  7448. bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
  7449. else {
  7450. switch (switch_cfg) {
  7451. case SWITCH_CFG_1G:
  7452. bp->port.phy_addr = REG_RD(
  7453. bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
  7454. break;
  7455. case SWITCH_CFG_10G:
  7456. bp->port.phy_addr = REG_RD(
  7457. bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
  7458. break;
  7459. default:
  7460. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  7461. bp->port.link_config[0]);
  7462. return;
  7463. }
  7464. }
  7465. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  7466. /* mask what we support according to speed_cap_mask per configuration */
  7467. for (idx = 0; idx < cfg_size; idx++) {
  7468. if (!(bp->link_params.speed_cap_mask[idx] &
  7469. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  7470. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
  7471. if (!(bp->link_params.speed_cap_mask[idx] &
  7472. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  7473. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
  7474. if (!(bp->link_params.speed_cap_mask[idx] &
  7475. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  7476. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
  7477. if (!(bp->link_params.speed_cap_mask[idx] &
  7478. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  7479. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
  7480. if (!(bp->link_params.speed_cap_mask[idx] &
  7481. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  7482. bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
  7483. SUPPORTED_1000baseT_Full);
  7484. if (!(bp->link_params.speed_cap_mask[idx] &
  7485. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  7486. bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
  7487. if (!(bp->link_params.speed_cap_mask[idx] &
  7488. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  7489. bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
  7490. }
  7491. BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
  7492. bp->port.supported[1]);
  7493. }
  7494. static void __devinit bnx2x_link_settings_requested(struct bnx2x *bp)
  7495. {
  7496. u32 link_config, idx, cfg_size = 0;
  7497. bp->port.advertising[0] = 0;
  7498. bp->port.advertising[1] = 0;
  7499. switch (bp->link_params.num_phys) {
  7500. case 1:
  7501. case 2:
  7502. cfg_size = 1;
  7503. break;
  7504. case 3:
  7505. cfg_size = 2;
  7506. break;
  7507. }
  7508. for (idx = 0; idx < cfg_size; idx++) {
  7509. bp->link_params.req_duplex[idx] = DUPLEX_FULL;
  7510. link_config = bp->port.link_config[idx];
  7511. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  7512. case PORT_FEATURE_LINK_SPEED_AUTO:
  7513. if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
  7514. bp->link_params.req_line_speed[idx] =
  7515. SPEED_AUTO_NEG;
  7516. bp->port.advertising[idx] |=
  7517. bp->port.supported[idx];
  7518. } else {
  7519. /* force 10G, no AN */
  7520. bp->link_params.req_line_speed[idx] =
  7521. SPEED_10000;
  7522. bp->port.advertising[idx] |=
  7523. (ADVERTISED_10000baseT_Full |
  7524. ADVERTISED_FIBRE);
  7525. continue;
  7526. }
  7527. break;
  7528. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  7529. if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
  7530. bp->link_params.req_line_speed[idx] =
  7531. SPEED_10;
  7532. bp->port.advertising[idx] |=
  7533. (ADVERTISED_10baseT_Full |
  7534. ADVERTISED_TP);
  7535. } else {
  7536. BNX2X_ERR("NVRAM config error. "
  7537. "Invalid link_config 0x%x"
  7538. " speed_cap_mask 0x%x\n",
  7539. link_config,
  7540. bp->link_params.speed_cap_mask[idx]);
  7541. return;
  7542. }
  7543. break;
  7544. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  7545. if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
  7546. bp->link_params.req_line_speed[idx] =
  7547. SPEED_10;
  7548. bp->link_params.req_duplex[idx] =
  7549. DUPLEX_HALF;
  7550. bp->port.advertising[idx] |=
  7551. (ADVERTISED_10baseT_Half |
  7552. ADVERTISED_TP);
  7553. } else {
  7554. BNX2X_ERR("NVRAM config error. "
  7555. "Invalid link_config 0x%x"
  7556. " speed_cap_mask 0x%x\n",
  7557. link_config,
  7558. bp->link_params.speed_cap_mask[idx]);
  7559. return;
  7560. }
  7561. break;
  7562. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  7563. if (bp->port.supported[idx] &
  7564. SUPPORTED_100baseT_Full) {
  7565. bp->link_params.req_line_speed[idx] =
  7566. SPEED_100;
  7567. bp->port.advertising[idx] |=
  7568. (ADVERTISED_100baseT_Full |
  7569. ADVERTISED_TP);
  7570. } else {
  7571. BNX2X_ERR("NVRAM config error. "
  7572. "Invalid link_config 0x%x"
  7573. " speed_cap_mask 0x%x\n",
  7574. link_config,
  7575. bp->link_params.speed_cap_mask[idx]);
  7576. return;
  7577. }
  7578. break;
  7579. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  7580. if (bp->port.supported[idx] &
  7581. SUPPORTED_100baseT_Half) {
  7582. bp->link_params.req_line_speed[idx] =
  7583. SPEED_100;
  7584. bp->link_params.req_duplex[idx] =
  7585. DUPLEX_HALF;
  7586. bp->port.advertising[idx] |=
  7587. (ADVERTISED_100baseT_Half |
  7588. ADVERTISED_TP);
  7589. } else {
  7590. BNX2X_ERR("NVRAM config error. "
  7591. "Invalid link_config 0x%x"
  7592. " speed_cap_mask 0x%x\n",
  7593. link_config,
  7594. bp->link_params.speed_cap_mask[idx]);
  7595. return;
  7596. }
  7597. break;
  7598. case PORT_FEATURE_LINK_SPEED_1G:
  7599. if (bp->port.supported[idx] &
  7600. SUPPORTED_1000baseT_Full) {
  7601. bp->link_params.req_line_speed[idx] =
  7602. SPEED_1000;
  7603. bp->port.advertising[idx] |=
  7604. (ADVERTISED_1000baseT_Full |
  7605. ADVERTISED_TP);
  7606. } else {
  7607. BNX2X_ERR("NVRAM config error. "
  7608. "Invalid link_config 0x%x"
  7609. " speed_cap_mask 0x%x\n",
  7610. link_config,
  7611. bp->link_params.speed_cap_mask[idx]);
  7612. return;
  7613. }
  7614. break;
  7615. case PORT_FEATURE_LINK_SPEED_2_5G:
  7616. if (bp->port.supported[idx] &
  7617. SUPPORTED_2500baseX_Full) {
  7618. bp->link_params.req_line_speed[idx] =
  7619. SPEED_2500;
  7620. bp->port.advertising[idx] |=
  7621. (ADVERTISED_2500baseX_Full |
  7622. ADVERTISED_TP);
  7623. } else {
  7624. BNX2X_ERR("NVRAM config error. "
  7625. "Invalid link_config 0x%x"
  7626. " speed_cap_mask 0x%x\n",
  7627. link_config,
  7628. bp->link_params.speed_cap_mask[idx]);
  7629. return;
  7630. }
  7631. break;
  7632. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  7633. if (bp->port.supported[idx] &
  7634. SUPPORTED_10000baseT_Full) {
  7635. bp->link_params.req_line_speed[idx] =
  7636. SPEED_10000;
  7637. bp->port.advertising[idx] |=
  7638. (ADVERTISED_10000baseT_Full |
  7639. ADVERTISED_FIBRE);
  7640. } else {
  7641. BNX2X_ERR("NVRAM config error. "
  7642. "Invalid link_config 0x%x"
  7643. " speed_cap_mask 0x%x\n",
  7644. link_config,
  7645. bp->link_params.speed_cap_mask[idx]);
  7646. return;
  7647. }
  7648. break;
  7649. case PORT_FEATURE_LINK_SPEED_20G:
  7650. bp->link_params.req_line_speed[idx] = SPEED_20000;
  7651. break;
  7652. default:
  7653. BNX2X_ERR("NVRAM config error. "
  7654. "BAD link speed link_config 0x%x\n",
  7655. link_config);
  7656. bp->link_params.req_line_speed[idx] =
  7657. SPEED_AUTO_NEG;
  7658. bp->port.advertising[idx] =
  7659. bp->port.supported[idx];
  7660. break;
  7661. }
  7662. bp->link_params.req_flow_ctrl[idx] = (link_config &
  7663. PORT_FEATURE_FLOW_CONTROL_MASK);
  7664. if ((bp->link_params.req_flow_ctrl[idx] ==
  7665. BNX2X_FLOW_CTRL_AUTO) &&
  7666. !(bp->port.supported[idx] & SUPPORTED_Autoneg)) {
  7667. bp->link_params.req_flow_ctrl[idx] =
  7668. BNX2X_FLOW_CTRL_NONE;
  7669. }
  7670. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl"
  7671. " 0x%x advertising 0x%x\n",
  7672. bp->link_params.req_line_speed[idx],
  7673. bp->link_params.req_duplex[idx],
  7674. bp->link_params.req_flow_ctrl[idx],
  7675. bp->port.advertising[idx]);
  7676. }
  7677. }
  7678. static void __devinit bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  7679. {
  7680. mac_hi = cpu_to_be16(mac_hi);
  7681. mac_lo = cpu_to_be32(mac_lo);
  7682. memcpy(mac_buf, &mac_hi, sizeof(mac_hi));
  7683. memcpy(mac_buf + sizeof(mac_hi), &mac_lo, sizeof(mac_lo));
  7684. }
  7685. static void __devinit bnx2x_get_port_hwinfo(struct bnx2x *bp)
  7686. {
  7687. int port = BP_PORT(bp);
  7688. u32 config;
  7689. u32 ext_phy_type, ext_phy_config;
  7690. bp->link_params.bp = bp;
  7691. bp->link_params.port = port;
  7692. bp->link_params.lane_config =
  7693. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  7694. bp->link_params.speed_cap_mask[0] =
  7695. SHMEM_RD(bp,
  7696. dev_info.port_hw_config[port].speed_capability_mask);
  7697. bp->link_params.speed_cap_mask[1] =
  7698. SHMEM_RD(bp,
  7699. dev_info.port_hw_config[port].speed_capability_mask2);
  7700. bp->port.link_config[0] =
  7701. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  7702. bp->port.link_config[1] =
  7703. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
  7704. bp->link_params.multi_phy_config =
  7705. SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
  7706. /* If the device is capable of WoL, set the default state according
  7707. * to the HW
  7708. */
  7709. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  7710. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  7711. (config & PORT_FEATURE_WOL_ENABLED));
  7712. BNX2X_DEV_INFO("lane_config 0x%08x "
  7713. "speed_cap_mask0 0x%08x link_config0 0x%08x\n",
  7714. bp->link_params.lane_config,
  7715. bp->link_params.speed_cap_mask[0],
  7716. bp->port.link_config[0]);
  7717. bp->link_params.switch_cfg = (bp->port.link_config[0] &
  7718. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  7719. bnx2x_phy_probe(&bp->link_params);
  7720. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  7721. bnx2x_link_settings_requested(bp);
  7722. /*
  7723. * If connected directly, work with the internal PHY, otherwise, work
  7724. * with the external PHY
  7725. */
  7726. ext_phy_config =
  7727. SHMEM_RD(bp,
  7728. dev_info.port_hw_config[port].external_phy_config);
  7729. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  7730. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  7731. bp->mdio.prtad = bp->port.phy_addr;
  7732. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  7733. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  7734. bp->mdio.prtad =
  7735. XGXS_EXT_PHY_ADDR(ext_phy_config);
  7736. /*
  7737. * Check if hw lock is required to access MDC/MDIO bus to the PHY(s)
  7738. * In MF mode, it is set to cover self test cases
  7739. */
  7740. if (IS_MF(bp))
  7741. bp->port.need_hw_lock = 1;
  7742. else
  7743. bp->port.need_hw_lock = bnx2x_hw_lock_required(bp,
  7744. bp->common.shmem_base,
  7745. bp->common.shmem2_base);
  7746. }
  7747. #ifdef BCM_CNIC
  7748. static void __devinit bnx2x_get_cnic_info(struct bnx2x *bp)
  7749. {
  7750. int port = BP_PORT(bp);
  7751. int func = BP_ABS_FUNC(bp);
  7752. u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  7753. drv_lic_key[port].max_iscsi_conn);
  7754. u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  7755. drv_lic_key[port].max_fcoe_conn);
  7756. /* Get the number of maximum allowed iSCSI and FCoE connections */
  7757. bp->cnic_eth_dev.max_iscsi_conn =
  7758. (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
  7759. BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
  7760. bp->cnic_eth_dev.max_fcoe_conn =
  7761. (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
  7762. BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
  7763. /* Read the WWN: */
  7764. if (!IS_MF(bp)) {
  7765. /* Port info */
  7766. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  7767. SHMEM_RD(bp,
  7768. dev_info.port_hw_config[port].
  7769. fcoe_wwn_port_name_upper);
  7770. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  7771. SHMEM_RD(bp,
  7772. dev_info.port_hw_config[port].
  7773. fcoe_wwn_port_name_lower);
  7774. /* Node info */
  7775. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  7776. SHMEM_RD(bp,
  7777. dev_info.port_hw_config[port].
  7778. fcoe_wwn_node_name_upper);
  7779. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  7780. SHMEM_RD(bp,
  7781. dev_info.port_hw_config[port].
  7782. fcoe_wwn_node_name_lower);
  7783. } else if (!IS_MF_SD(bp)) {
  7784. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  7785. /*
  7786. * Read the WWN info only if the FCoE feature is enabled for
  7787. * this function.
  7788. */
  7789. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  7790. /* Port info */
  7791. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  7792. MF_CFG_RD(bp, func_ext_config[func].
  7793. fcoe_wwn_port_name_upper);
  7794. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  7795. MF_CFG_RD(bp, func_ext_config[func].
  7796. fcoe_wwn_port_name_lower);
  7797. /* Node info */
  7798. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  7799. MF_CFG_RD(bp, func_ext_config[func].
  7800. fcoe_wwn_node_name_upper);
  7801. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  7802. MF_CFG_RD(bp, func_ext_config[func].
  7803. fcoe_wwn_node_name_lower);
  7804. }
  7805. }
  7806. BNX2X_DEV_INFO("max_iscsi_conn 0x%x max_fcoe_conn 0x%x\n",
  7807. bp->cnic_eth_dev.max_iscsi_conn,
  7808. bp->cnic_eth_dev.max_fcoe_conn);
  7809. /*
  7810. * If maximum allowed number of connections is zero -
  7811. * disable the feature.
  7812. */
  7813. if (!bp->cnic_eth_dev.max_iscsi_conn)
  7814. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  7815. if (!bp->cnic_eth_dev.max_fcoe_conn)
  7816. bp->flags |= NO_FCOE_FLAG;
  7817. }
  7818. #endif
  7819. static void __devinit bnx2x_get_mac_hwinfo(struct bnx2x *bp)
  7820. {
  7821. u32 val, val2;
  7822. int func = BP_ABS_FUNC(bp);
  7823. int port = BP_PORT(bp);
  7824. #ifdef BCM_CNIC
  7825. u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
  7826. u8 *fip_mac = bp->fip_mac;
  7827. #endif
  7828. /* Zero primary MAC configuration */
  7829. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  7830. if (BP_NOMCP(bp)) {
  7831. BNX2X_ERROR("warning: random MAC workaround active\n");
  7832. random_ether_addr(bp->dev->dev_addr);
  7833. } else if (IS_MF(bp)) {
  7834. val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  7835. val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
  7836. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  7837. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
  7838. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  7839. #ifdef BCM_CNIC
  7840. /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
  7841. * FCoE MAC then the appropriate feature should be disabled.
  7842. */
  7843. if (IS_MF_SI(bp)) {
  7844. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  7845. if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
  7846. val2 = MF_CFG_RD(bp, func_ext_config[func].
  7847. iscsi_mac_addr_upper);
  7848. val = MF_CFG_RD(bp, func_ext_config[func].
  7849. iscsi_mac_addr_lower);
  7850. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  7851. BNX2X_DEV_INFO("Read iSCSI MAC: %pM\n",
  7852. iscsi_mac);
  7853. } else
  7854. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  7855. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  7856. val2 = MF_CFG_RD(bp, func_ext_config[func].
  7857. fcoe_mac_addr_upper);
  7858. val = MF_CFG_RD(bp, func_ext_config[func].
  7859. fcoe_mac_addr_lower);
  7860. bnx2x_set_mac_buf(fip_mac, val, val2);
  7861. BNX2X_DEV_INFO("Read FCoE L2 MAC to %pM\n",
  7862. fip_mac);
  7863. } else
  7864. bp->flags |= NO_FCOE_FLAG;
  7865. }
  7866. #endif
  7867. } else {
  7868. /* in SF read MACs from port configuration */
  7869. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  7870. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  7871. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  7872. #ifdef BCM_CNIC
  7873. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  7874. iscsi_mac_upper);
  7875. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  7876. iscsi_mac_lower);
  7877. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  7878. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  7879. fcoe_fip_mac_upper);
  7880. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  7881. fcoe_fip_mac_lower);
  7882. bnx2x_set_mac_buf(fip_mac, val, val2);
  7883. #endif
  7884. }
  7885. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  7886. memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN);
  7887. #ifdef BCM_CNIC
  7888. /* Set the FCoE MAC in MF_SD mode */
  7889. if (!CHIP_IS_E1x(bp) && IS_MF_SD(bp))
  7890. memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
  7891. /* Disable iSCSI if MAC configuration is
  7892. * invalid.
  7893. */
  7894. if (!is_valid_ether_addr(iscsi_mac)) {
  7895. bp->flags |= NO_ISCSI_FLAG;
  7896. memset(iscsi_mac, 0, ETH_ALEN);
  7897. }
  7898. /* Disable FCoE if MAC configuration is
  7899. * invalid.
  7900. */
  7901. if (!is_valid_ether_addr(fip_mac)) {
  7902. bp->flags |= NO_FCOE_FLAG;
  7903. memset(bp->fip_mac, 0, ETH_ALEN);
  7904. }
  7905. #endif
  7906. if (!is_valid_ether_addr(bp->dev->dev_addr))
  7907. dev_err(&bp->pdev->dev,
  7908. "bad Ethernet MAC address configuration: "
  7909. "%pM, change it manually before bringing up "
  7910. "the appropriate network interface\n",
  7911. bp->dev->dev_addr);
  7912. }
  7913. static int __devinit bnx2x_get_hwinfo(struct bnx2x *bp)
  7914. {
  7915. int /*abs*/func = BP_ABS_FUNC(bp);
  7916. int vn;
  7917. u32 val = 0;
  7918. int rc = 0;
  7919. bnx2x_get_common_hwinfo(bp);
  7920. /*
  7921. * initialize IGU parameters
  7922. */
  7923. if (CHIP_IS_E1x(bp)) {
  7924. bp->common.int_block = INT_BLOCK_HC;
  7925. bp->igu_dsb_id = DEF_SB_IGU_ID;
  7926. bp->igu_base_sb = 0;
  7927. } else {
  7928. bp->common.int_block = INT_BLOCK_IGU;
  7929. /* do not allow device reset during IGU info preocessing */
  7930. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  7931. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  7932. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  7933. int tout = 5000;
  7934. BNX2X_DEV_INFO("FORCING Normal Mode\n");
  7935. val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
  7936. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
  7937. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
  7938. while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  7939. tout--;
  7940. usleep_range(1000, 1000);
  7941. }
  7942. if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  7943. dev_err(&bp->pdev->dev,
  7944. "FORCING Normal Mode failed!!!\n");
  7945. return -EPERM;
  7946. }
  7947. }
  7948. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  7949. BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
  7950. bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
  7951. } else
  7952. BNX2X_DEV_INFO("IGU Normal Mode\n");
  7953. bnx2x_get_igu_cam_info(bp);
  7954. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  7955. }
  7956. /*
  7957. * set base FW non-default (fast path) status block id, this value is
  7958. * used to initialize the fw_sb_id saved on the fp/queue structure to
  7959. * determine the id used by the FW.
  7960. */
  7961. if (CHIP_IS_E1x(bp))
  7962. bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
  7963. else /*
  7964. * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
  7965. * the same queue are indicated on the same IGU SB). So we prefer
  7966. * FW and IGU SBs to be the same value.
  7967. */
  7968. bp->base_fw_ndsb = bp->igu_base_sb;
  7969. BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
  7970. "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
  7971. bp->igu_sb_cnt, bp->base_fw_ndsb);
  7972. /*
  7973. * Initialize MF configuration
  7974. */
  7975. bp->mf_ov = 0;
  7976. bp->mf_mode = 0;
  7977. vn = BP_VN(bp);
  7978. if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
  7979. BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
  7980. bp->common.shmem2_base, SHMEM2_RD(bp, size),
  7981. (u32)offsetof(struct shmem2_region, mf_cfg_addr));
  7982. if (SHMEM2_HAS(bp, mf_cfg_addr))
  7983. bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
  7984. else
  7985. bp->common.mf_cfg_base = bp->common.shmem_base +
  7986. offsetof(struct shmem_region, func_mb) +
  7987. E1H_FUNC_MAX * sizeof(struct drv_func_mb);
  7988. /*
  7989. * get mf configuration:
  7990. * 1. existence of MF configuration
  7991. * 2. MAC address must be legal (check only upper bytes)
  7992. * for Switch-Independent mode;
  7993. * OVLAN must be legal for Switch-Dependent mode
  7994. * 3. SF_MODE configures specific MF mode
  7995. */
  7996. if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  7997. /* get mf configuration */
  7998. val = SHMEM_RD(bp,
  7999. dev_info.shared_feature_config.config);
  8000. val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
  8001. switch (val) {
  8002. case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
  8003. val = MF_CFG_RD(bp, func_mf_config[func].
  8004. mac_upper);
  8005. /* check for legal mac (upper bytes)*/
  8006. if (val != 0xffff) {
  8007. bp->mf_mode = MULTI_FUNCTION_SI;
  8008. bp->mf_config[vn] = MF_CFG_RD(bp,
  8009. func_mf_config[func].config);
  8010. } else
  8011. BNX2X_DEV_INFO("illegal MAC address "
  8012. "for SI\n");
  8013. break;
  8014. case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
  8015. /* get OV configuration */
  8016. val = MF_CFG_RD(bp,
  8017. func_mf_config[FUNC_0].e1hov_tag);
  8018. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  8019. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  8020. bp->mf_mode = MULTI_FUNCTION_SD;
  8021. bp->mf_config[vn] = MF_CFG_RD(bp,
  8022. func_mf_config[func].config);
  8023. } else
  8024. BNX2X_DEV_INFO("illegal OV for SD\n");
  8025. break;
  8026. default:
  8027. /* Unknown configuration: reset mf_config */
  8028. bp->mf_config[vn] = 0;
  8029. BNX2X_DEV_INFO("unkown MF mode 0x%x\n", val);
  8030. }
  8031. }
  8032. BNX2X_DEV_INFO("%s function mode\n",
  8033. IS_MF(bp) ? "multi" : "single");
  8034. switch (bp->mf_mode) {
  8035. case MULTI_FUNCTION_SD:
  8036. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  8037. FUNC_MF_CFG_E1HOV_TAG_MASK;
  8038. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  8039. bp->mf_ov = val;
  8040. bp->path_has_ovlan = true;
  8041. BNX2X_DEV_INFO("MF OV for func %d is %d "
  8042. "(0x%04x)\n", func, bp->mf_ov,
  8043. bp->mf_ov);
  8044. } else {
  8045. dev_err(&bp->pdev->dev,
  8046. "No valid MF OV for func %d, "
  8047. "aborting\n", func);
  8048. return -EPERM;
  8049. }
  8050. break;
  8051. case MULTI_FUNCTION_SI:
  8052. BNX2X_DEV_INFO("func %d is in MF "
  8053. "switch-independent mode\n", func);
  8054. break;
  8055. default:
  8056. if (vn) {
  8057. dev_err(&bp->pdev->dev,
  8058. "VN %d is in a single function mode, "
  8059. "aborting\n", vn);
  8060. return -EPERM;
  8061. }
  8062. break;
  8063. }
  8064. /* check if other port on the path needs ovlan:
  8065. * Since MF configuration is shared between ports
  8066. * Possible mixed modes are only
  8067. * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
  8068. */
  8069. if (CHIP_MODE_IS_4_PORT(bp) &&
  8070. !bp->path_has_ovlan &&
  8071. !IS_MF(bp) &&
  8072. bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  8073. u8 other_port = !BP_PORT(bp);
  8074. u8 other_func = BP_PATH(bp) + 2*other_port;
  8075. val = MF_CFG_RD(bp,
  8076. func_mf_config[other_func].e1hov_tag);
  8077. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  8078. bp->path_has_ovlan = true;
  8079. }
  8080. }
  8081. /* adjust igu_sb_cnt to MF for E1x */
  8082. if (CHIP_IS_E1x(bp) && IS_MF(bp))
  8083. bp->igu_sb_cnt /= E1HVN_MAX;
  8084. /* port info */
  8085. bnx2x_get_port_hwinfo(bp);
  8086. /* Get MAC addresses */
  8087. bnx2x_get_mac_hwinfo(bp);
  8088. #ifdef BCM_CNIC
  8089. bnx2x_get_cnic_info(bp);
  8090. #endif
  8091. /* Get current FW pulse sequence */
  8092. if (!BP_NOMCP(bp)) {
  8093. int mb_idx = BP_FW_MB_IDX(bp);
  8094. bp->fw_drv_pulse_wr_seq =
  8095. (SHMEM_RD(bp, func_mb[mb_idx].drv_pulse_mb) &
  8096. DRV_PULSE_SEQ_MASK);
  8097. BNX2X_DEV_INFO("drv_pulse 0x%x\n", bp->fw_drv_pulse_wr_seq);
  8098. }
  8099. return rc;
  8100. }
  8101. static void __devinit bnx2x_read_fwinfo(struct bnx2x *bp)
  8102. {
  8103. int cnt, i, block_end, rodi;
  8104. char vpd_data[BNX2X_VPD_LEN+1];
  8105. char str_id_reg[VENDOR_ID_LEN+1];
  8106. char str_id_cap[VENDOR_ID_LEN+1];
  8107. u8 len;
  8108. cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_data);
  8109. memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
  8110. if (cnt < BNX2X_VPD_LEN)
  8111. goto out_not_found;
  8112. i = pci_vpd_find_tag(vpd_data, 0, BNX2X_VPD_LEN,
  8113. PCI_VPD_LRDT_RO_DATA);
  8114. if (i < 0)
  8115. goto out_not_found;
  8116. block_end = i + PCI_VPD_LRDT_TAG_SIZE +
  8117. pci_vpd_lrdt_size(&vpd_data[i]);
  8118. i += PCI_VPD_LRDT_TAG_SIZE;
  8119. if (block_end > BNX2X_VPD_LEN)
  8120. goto out_not_found;
  8121. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  8122. PCI_VPD_RO_KEYWORD_MFR_ID);
  8123. if (rodi < 0)
  8124. goto out_not_found;
  8125. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  8126. if (len != VENDOR_ID_LEN)
  8127. goto out_not_found;
  8128. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  8129. /* vendor specific info */
  8130. snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
  8131. snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
  8132. if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
  8133. !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
  8134. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  8135. PCI_VPD_RO_KEYWORD_VENDOR0);
  8136. if (rodi >= 0) {
  8137. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  8138. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  8139. if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
  8140. memcpy(bp->fw_ver, &vpd_data[rodi], len);
  8141. bp->fw_ver[len] = ' ';
  8142. }
  8143. }
  8144. return;
  8145. }
  8146. out_not_found:
  8147. return;
  8148. }
  8149. static void __devinit bnx2x_set_modes_bitmap(struct bnx2x *bp)
  8150. {
  8151. u32 flags = 0;
  8152. if (CHIP_REV_IS_FPGA(bp))
  8153. SET_FLAGS(flags, MODE_FPGA);
  8154. else if (CHIP_REV_IS_EMUL(bp))
  8155. SET_FLAGS(flags, MODE_EMUL);
  8156. else
  8157. SET_FLAGS(flags, MODE_ASIC);
  8158. if (CHIP_MODE_IS_4_PORT(bp))
  8159. SET_FLAGS(flags, MODE_PORT4);
  8160. else
  8161. SET_FLAGS(flags, MODE_PORT2);
  8162. if (CHIP_IS_E2(bp))
  8163. SET_FLAGS(flags, MODE_E2);
  8164. else if (CHIP_IS_E3(bp)) {
  8165. SET_FLAGS(flags, MODE_E3);
  8166. if (CHIP_REV(bp) == CHIP_REV_Ax)
  8167. SET_FLAGS(flags, MODE_E3_A0);
  8168. else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
  8169. SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
  8170. }
  8171. if (IS_MF(bp)) {
  8172. SET_FLAGS(flags, MODE_MF);
  8173. switch (bp->mf_mode) {
  8174. case MULTI_FUNCTION_SD:
  8175. SET_FLAGS(flags, MODE_MF_SD);
  8176. break;
  8177. case MULTI_FUNCTION_SI:
  8178. SET_FLAGS(flags, MODE_MF_SI);
  8179. break;
  8180. }
  8181. } else
  8182. SET_FLAGS(flags, MODE_SF);
  8183. #if defined(__LITTLE_ENDIAN)
  8184. SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
  8185. #else /*(__BIG_ENDIAN)*/
  8186. SET_FLAGS(flags, MODE_BIG_ENDIAN);
  8187. #endif
  8188. INIT_MODE_FLAGS(bp) = flags;
  8189. }
  8190. static int __devinit bnx2x_init_bp(struct bnx2x *bp)
  8191. {
  8192. int func;
  8193. int timer_interval;
  8194. int rc;
  8195. mutex_init(&bp->port.phy_mutex);
  8196. mutex_init(&bp->fw_mb_mutex);
  8197. spin_lock_init(&bp->stats_lock);
  8198. #ifdef BCM_CNIC
  8199. mutex_init(&bp->cnic_mutex);
  8200. #endif
  8201. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  8202. INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
  8203. INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
  8204. rc = bnx2x_get_hwinfo(bp);
  8205. if (rc)
  8206. return rc;
  8207. bnx2x_set_modes_bitmap(bp);
  8208. rc = bnx2x_alloc_mem_bp(bp);
  8209. if (rc)
  8210. return rc;
  8211. bnx2x_read_fwinfo(bp);
  8212. func = BP_FUNC(bp);
  8213. /* need to reset chip if undi was active */
  8214. if (!BP_NOMCP(bp))
  8215. bnx2x_undi_unload(bp);
  8216. /* init fw_seq after undi_unload! */
  8217. if (!BP_NOMCP(bp)) {
  8218. bp->fw_seq =
  8219. (SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  8220. DRV_MSG_SEQ_NUMBER_MASK);
  8221. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  8222. }
  8223. if (CHIP_REV_IS_FPGA(bp))
  8224. dev_err(&bp->pdev->dev, "FPGA detected\n");
  8225. if (BP_NOMCP(bp) && (func == 0))
  8226. dev_err(&bp->pdev->dev, "MCP disabled, "
  8227. "must load devices in order!\n");
  8228. bp->multi_mode = multi_mode;
  8229. /* Set TPA flags */
  8230. if (disable_tpa) {
  8231. bp->flags &= ~TPA_ENABLE_FLAG;
  8232. bp->dev->features &= ~NETIF_F_LRO;
  8233. } else {
  8234. bp->flags |= TPA_ENABLE_FLAG;
  8235. bp->dev->features |= NETIF_F_LRO;
  8236. }
  8237. bp->disable_tpa = disable_tpa;
  8238. if (CHIP_IS_E1(bp))
  8239. bp->dropless_fc = 0;
  8240. else
  8241. bp->dropless_fc = dropless_fc;
  8242. bp->mrrs = mrrs;
  8243. bp->tx_ring_size = MAX_TX_AVAIL;
  8244. /* make sure that the numbers are in the right granularity */
  8245. bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
  8246. bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
  8247. timer_interval = (CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ);
  8248. bp->current_interval = (poll ? poll : timer_interval);
  8249. init_timer(&bp->timer);
  8250. bp->timer.expires = jiffies + bp->current_interval;
  8251. bp->timer.data = (unsigned long) bp;
  8252. bp->timer.function = bnx2x_timer;
  8253. bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
  8254. bnx2x_dcbx_init_params(bp);
  8255. #ifdef BCM_CNIC
  8256. if (CHIP_IS_E1x(bp))
  8257. bp->cnic_base_cl_id = FP_SB_MAX_E1x;
  8258. else
  8259. bp->cnic_base_cl_id = FP_SB_MAX_E2;
  8260. #endif
  8261. /* multiple tx priority */
  8262. if (CHIP_IS_E1x(bp))
  8263. bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
  8264. if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
  8265. bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
  8266. if (CHIP_IS_E3B0(bp))
  8267. bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
  8268. return rc;
  8269. }
  8270. /****************************************************************************
  8271. * General service functions
  8272. ****************************************************************************/
  8273. /*
  8274. * net_device service functions
  8275. */
  8276. /* called with rtnl_lock */
  8277. static int bnx2x_open(struct net_device *dev)
  8278. {
  8279. struct bnx2x *bp = netdev_priv(dev);
  8280. bool global = false;
  8281. int other_engine = BP_PATH(bp) ? 0 : 1;
  8282. u32 other_load_counter, load_counter;
  8283. netif_carrier_off(dev);
  8284. bnx2x_set_power_state(bp, PCI_D0);
  8285. other_load_counter = bnx2x_get_load_cnt(bp, other_engine);
  8286. load_counter = bnx2x_get_load_cnt(bp, BP_PATH(bp));
  8287. /*
  8288. * If parity had happen during the unload, then attentions
  8289. * and/or RECOVERY_IN_PROGRES may still be set. In this case we
  8290. * want the first function loaded on the current engine to
  8291. * complete the recovery.
  8292. */
  8293. if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
  8294. bnx2x_chk_parity_attn(bp, &global, true))
  8295. do {
  8296. /*
  8297. * If there are attentions and they are in a global
  8298. * blocks, set the GLOBAL_RESET bit regardless whether
  8299. * it will be this function that will complete the
  8300. * recovery or not.
  8301. */
  8302. if (global)
  8303. bnx2x_set_reset_global(bp);
  8304. /*
  8305. * Only the first function on the current engine should
  8306. * try to recover in open. In case of attentions in
  8307. * global blocks only the first in the chip should try
  8308. * to recover.
  8309. */
  8310. if ((!load_counter &&
  8311. (!global || !other_load_counter)) &&
  8312. bnx2x_trylock_leader_lock(bp) &&
  8313. !bnx2x_leader_reset(bp)) {
  8314. netdev_info(bp->dev, "Recovered in open\n");
  8315. break;
  8316. }
  8317. /* recovery has failed... */
  8318. bnx2x_set_power_state(bp, PCI_D3hot);
  8319. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  8320. netdev_err(bp->dev, "Recovery flow hasn't been properly"
  8321. " completed yet. Try again later. If u still see this"
  8322. " message after a few retries then power cycle is"
  8323. " required.\n");
  8324. return -EAGAIN;
  8325. } while (0);
  8326. bp->recovery_state = BNX2X_RECOVERY_DONE;
  8327. return bnx2x_nic_load(bp, LOAD_OPEN);
  8328. }
  8329. /* called with rtnl_lock */
  8330. static int bnx2x_close(struct net_device *dev)
  8331. {
  8332. struct bnx2x *bp = netdev_priv(dev);
  8333. /* Unload the driver, release IRQs */
  8334. bnx2x_nic_unload(bp, UNLOAD_CLOSE);
  8335. /* Power off */
  8336. bnx2x_set_power_state(bp, PCI_D3hot);
  8337. return 0;
  8338. }
  8339. static inline int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
  8340. struct bnx2x_mcast_ramrod_params *p)
  8341. {
  8342. int mc_count = netdev_mc_count(bp->dev);
  8343. struct bnx2x_mcast_list_elem *mc_mac =
  8344. kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
  8345. struct netdev_hw_addr *ha;
  8346. if (!mc_mac)
  8347. return -ENOMEM;
  8348. INIT_LIST_HEAD(&p->mcast_list);
  8349. netdev_for_each_mc_addr(ha, bp->dev) {
  8350. mc_mac->mac = bnx2x_mc_addr(ha);
  8351. list_add_tail(&mc_mac->link, &p->mcast_list);
  8352. mc_mac++;
  8353. }
  8354. p->mcast_list_len = mc_count;
  8355. return 0;
  8356. }
  8357. static inline void bnx2x_free_mcast_macs_list(
  8358. struct bnx2x_mcast_ramrod_params *p)
  8359. {
  8360. struct bnx2x_mcast_list_elem *mc_mac =
  8361. list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
  8362. link);
  8363. WARN_ON(!mc_mac);
  8364. kfree(mc_mac);
  8365. }
  8366. /**
  8367. * bnx2x_set_uc_list - configure a new unicast MACs list.
  8368. *
  8369. * @bp: driver handle
  8370. *
  8371. * We will use zero (0) as a MAC type for these MACs.
  8372. */
  8373. static inline int bnx2x_set_uc_list(struct bnx2x *bp)
  8374. {
  8375. int rc;
  8376. struct net_device *dev = bp->dev;
  8377. struct netdev_hw_addr *ha;
  8378. struct bnx2x_vlan_mac_obj *mac_obj = &bp->fp->mac_obj;
  8379. unsigned long ramrod_flags = 0;
  8380. /* First schedule a cleanup up of old configuration */
  8381. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
  8382. if (rc < 0) {
  8383. BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
  8384. return rc;
  8385. }
  8386. netdev_for_each_uc_addr(ha, dev) {
  8387. rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
  8388. BNX2X_UC_LIST_MAC, &ramrod_flags);
  8389. if (rc < 0) {
  8390. BNX2X_ERR("Failed to schedule ADD operations: %d\n",
  8391. rc);
  8392. return rc;
  8393. }
  8394. }
  8395. /* Execute the pending commands */
  8396. __set_bit(RAMROD_CONT, &ramrod_flags);
  8397. return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
  8398. BNX2X_UC_LIST_MAC, &ramrod_flags);
  8399. }
  8400. static inline int bnx2x_set_mc_list(struct bnx2x *bp)
  8401. {
  8402. struct net_device *dev = bp->dev;
  8403. struct bnx2x_mcast_ramrod_params rparam = {0};
  8404. int rc = 0;
  8405. rparam.mcast_obj = &bp->mcast_obj;
  8406. /* first, clear all configured multicast MACs */
  8407. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  8408. if (rc < 0) {
  8409. BNX2X_ERR("Failed to clear multicast "
  8410. "configuration: %d\n", rc);
  8411. return rc;
  8412. }
  8413. /* then, configure a new MACs list */
  8414. if (netdev_mc_count(dev)) {
  8415. rc = bnx2x_init_mcast_macs_list(bp, &rparam);
  8416. if (rc) {
  8417. BNX2X_ERR("Failed to create multicast MACs "
  8418. "list: %d\n", rc);
  8419. return rc;
  8420. }
  8421. /* Now add the new MACs */
  8422. rc = bnx2x_config_mcast(bp, &rparam,
  8423. BNX2X_MCAST_CMD_ADD);
  8424. if (rc < 0)
  8425. BNX2X_ERR("Failed to set a new multicast "
  8426. "configuration: %d\n", rc);
  8427. bnx2x_free_mcast_macs_list(&rparam);
  8428. }
  8429. return rc;
  8430. }
  8431. /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
  8432. void bnx2x_set_rx_mode(struct net_device *dev)
  8433. {
  8434. struct bnx2x *bp = netdev_priv(dev);
  8435. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  8436. if (bp->state != BNX2X_STATE_OPEN) {
  8437. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  8438. return;
  8439. }
  8440. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
  8441. if (dev->flags & IFF_PROMISC)
  8442. rx_mode = BNX2X_RX_MODE_PROMISC;
  8443. else if ((dev->flags & IFF_ALLMULTI) ||
  8444. ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
  8445. CHIP_IS_E1(bp)))
  8446. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  8447. else {
  8448. /* some multicasts */
  8449. if (bnx2x_set_mc_list(bp) < 0)
  8450. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  8451. if (bnx2x_set_uc_list(bp) < 0)
  8452. rx_mode = BNX2X_RX_MODE_PROMISC;
  8453. }
  8454. bp->rx_mode = rx_mode;
  8455. /* Schedule the rx_mode command */
  8456. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
  8457. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  8458. return;
  8459. }
  8460. bnx2x_set_storm_rx_mode(bp);
  8461. }
  8462. /* called with rtnl_lock */
  8463. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  8464. int devad, u16 addr)
  8465. {
  8466. struct bnx2x *bp = netdev_priv(netdev);
  8467. u16 value;
  8468. int rc;
  8469. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  8470. prtad, devad, addr);
  8471. /* The HW expects different devad if CL22 is used */
  8472. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  8473. bnx2x_acquire_phy_lock(bp);
  8474. rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
  8475. bnx2x_release_phy_lock(bp);
  8476. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  8477. if (!rc)
  8478. rc = value;
  8479. return rc;
  8480. }
  8481. /* called with rtnl_lock */
  8482. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  8483. u16 addr, u16 value)
  8484. {
  8485. struct bnx2x *bp = netdev_priv(netdev);
  8486. int rc;
  8487. DP(NETIF_MSG_LINK, "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x,"
  8488. " value 0x%x\n", prtad, devad, addr, value);
  8489. /* The HW expects different devad if CL22 is used */
  8490. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  8491. bnx2x_acquire_phy_lock(bp);
  8492. rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
  8493. bnx2x_release_phy_lock(bp);
  8494. return rc;
  8495. }
  8496. /* called with rtnl_lock */
  8497. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  8498. {
  8499. struct bnx2x *bp = netdev_priv(dev);
  8500. struct mii_ioctl_data *mdio = if_mii(ifr);
  8501. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  8502. mdio->phy_id, mdio->reg_num, mdio->val_in);
  8503. if (!netif_running(dev))
  8504. return -EAGAIN;
  8505. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  8506. }
  8507. #ifdef CONFIG_NET_POLL_CONTROLLER
  8508. static void poll_bnx2x(struct net_device *dev)
  8509. {
  8510. struct bnx2x *bp = netdev_priv(dev);
  8511. disable_irq(bp->pdev->irq);
  8512. bnx2x_interrupt(bp->pdev->irq, dev);
  8513. enable_irq(bp->pdev->irq);
  8514. }
  8515. #endif
  8516. static const struct net_device_ops bnx2x_netdev_ops = {
  8517. .ndo_open = bnx2x_open,
  8518. .ndo_stop = bnx2x_close,
  8519. .ndo_start_xmit = bnx2x_start_xmit,
  8520. .ndo_select_queue = bnx2x_select_queue,
  8521. .ndo_set_rx_mode = bnx2x_set_rx_mode,
  8522. .ndo_set_mac_address = bnx2x_change_mac_addr,
  8523. .ndo_validate_addr = eth_validate_addr,
  8524. .ndo_do_ioctl = bnx2x_ioctl,
  8525. .ndo_change_mtu = bnx2x_change_mtu,
  8526. .ndo_fix_features = bnx2x_fix_features,
  8527. .ndo_set_features = bnx2x_set_features,
  8528. .ndo_tx_timeout = bnx2x_tx_timeout,
  8529. #ifdef CONFIG_NET_POLL_CONTROLLER
  8530. .ndo_poll_controller = poll_bnx2x,
  8531. #endif
  8532. .ndo_setup_tc = bnx2x_setup_tc,
  8533. #if defined(NETDEV_FCOE_WWNN) && defined(BCM_CNIC)
  8534. .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
  8535. #endif
  8536. };
  8537. static inline int bnx2x_set_coherency_mask(struct bnx2x *bp)
  8538. {
  8539. struct device *dev = &bp->pdev->dev;
  8540. if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
  8541. bp->flags |= USING_DAC_FLAG;
  8542. if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
  8543. dev_err(dev, "dma_set_coherent_mask failed, "
  8544. "aborting\n");
  8545. return -EIO;
  8546. }
  8547. } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
  8548. dev_err(dev, "System does not support DMA, aborting\n");
  8549. return -EIO;
  8550. }
  8551. return 0;
  8552. }
  8553. static int __devinit bnx2x_init_dev(struct pci_dev *pdev,
  8554. struct net_device *dev,
  8555. unsigned long board_type)
  8556. {
  8557. struct bnx2x *bp;
  8558. int rc;
  8559. SET_NETDEV_DEV(dev, &pdev->dev);
  8560. bp = netdev_priv(dev);
  8561. bp->dev = dev;
  8562. bp->pdev = pdev;
  8563. bp->flags = 0;
  8564. bp->pf_num = PCI_FUNC(pdev->devfn);
  8565. rc = pci_enable_device(pdev);
  8566. if (rc) {
  8567. dev_err(&bp->pdev->dev,
  8568. "Cannot enable PCI device, aborting\n");
  8569. goto err_out;
  8570. }
  8571. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  8572. dev_err(&bp->pdev->dev,
  8573. "Cannot find PCI device base address, aborting\n");
  8574. rc = -ENODEV;
  8575. goto err_out_disable;
  8576. }
  8577. if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  8578. dev_err(&bp->pdev->dev, "Cannot find second PCI device"
  8579. " base address, aborting\n");
  8580. rc = -ENODEV;
  8581. goto err_out_disable;
  8582. }
  8583. if (atomic_read(&pdev->enable_cnt) == 1) {
  8584. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  8585. if (rc) {
  8586. dev_err(&bp->pdev->dev,
  8587. "Cannot obtain PCI resources, aborting\n");
  8588. goto err_out_disable;
  8589. }
  8590. pci_set_master(pdev);
  8591. pci_save_state(pdev);
  8592. }
  8593. bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  8594. if (bp->pm_cap == 0) {
  8595. dev_err(&bp->pdev->dev,
  8596. "Cannot find power management capability, aborting\n");
  8597. rc = -EIO;
  8598. goto err_out_release;
  8599. }
  8600. if (!pci_is_pcie(pdev)) {
  8601. dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
  8602. rc = -EIO;
  8603. goto err_out_release;
  8604. }
  8605. rc = bnx2x_set_coherency_mask(bp);
  8606. if (rc)
  8607. goto err_out_release;
  8608. dev->mem_start = pci_resource_start(pdev, 0);
  8609. dev->base_addr = dev->mem_start;
  8610. dev->mem_end = pci_resource_end(pdev, 0);
  8611. dev->irq = pdev->irq;
  8612. bp->regview = pci_ioremap_bar(pdev, 0);
  8613. if (!bp->regview) {
  8614. dev_err(&bp->pdev->dev,
  8615. "Cannot map register space, aborting\n");
  8616. rc = -ENOMEM;
  8617. goto err_out_release;
  8618. }
  8619. bnx2x_set_power_state(bp, PCI_D0);
  8620. /* clean indirect addresses */
  8621. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  8622. PCICFG_VENDOR_ID_OFFSET);
  8623. /*
  8624. * Clean the following indirect addresses for all functions since it
  8625. * is not used by the driver.
  8626. */
  8627. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
  8628. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
  8629. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
  8630. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
  8631. if (CHIP_IS_E1x(bp)) {
  8632. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
  8633. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
  8634. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
  8635. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
  8636. }
  8637. /*
  8638. * Enable internal target-read (in case we are probed after PF FLR).
  8639. * Must be done prior to any BAR read access. Only for 57712 and up
  8640. */
  8641. if (board_type != BCM57710 &&
  8642. board_type != BCM57711 &&
  8643. board_type != BCM57711E)
  8644. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  8645. /* Reset the load counter */
  8646. bnx2x_clear_load_cnt(bp);
  8647. dev->watchdog_timeo = TX_TIMEOUT;
  8648. dev->netdev_ops = &bnx2x_netdev_ops;
  8649. bnx2x_set_ethtool_ops(dev);
  8650. dev->priv_flags |= IFF_UNICAST_FLT;
  8651. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  8652. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_LRO |
  8653. NETIF_F_RXCSUM | NETIF_F_RXHASH | NETIF_F_HW_VLAN_TX;
  8654. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  8655. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
  8656. dev->features |= dev->hw_features | NETIF_F_HW_VLAN_RX;
  8657. if (bp->flags & USING_DAC_FLAG)
  8658. dev->features |= NETIF_F_HIGHDMA;
  8659. /* Add Loopback capability to the device */
  8660. dev->hw_features |= NETIF_F_LOOPBACK;
  8661. #ifdef BCM_DCBNL
  8662. dev->dcbnl_ops = &bnx2x_dcbnl_ops;
  8663. #endif
  8664. /* get_port_hwinfo() will set prtad and mmds properly */
  8665. bp->mdio.prtad = MDIO_PRTAD_NONE;
  8666. bp->mdio.mmds = 0;
  8667. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  8668. bp->mdio.dev = dev;
  8669. bp->mdio.mdio_read = bnx2x_mdio_read;
  8670. bp->mdio.mdio_write = bnx2x_mdio_write;
  8671. return 0;
  8672. err_out_release:
  8673. if (atomic_read(&pdev->enable_cnt) == 1)
  8674. pci_release_regions(pdev);
  8675. err_out_disable:
  8676. pci_disable_device(pdev);
  8677. pci_set_drvdata(pdev, NULL);
  8678. err_out:
  8679. return rc;
  8680. }
  8681. static void __devinit bnx2x_get_pcie_width_speed(struct bnx2x *bp,
  8682. int *width, int *speed)
  8683. {
  8684. u32 val = REG_RD(bp, PCICFG_OFFSET + PCICFG_LINK_CONTROL);
  8685. *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
  8686. /* return value of 1=2.5GHz 2=5GHz */
  8687. *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
  8688. }
  8689. static int bnx2x_check_firmware(struct bnx2x *bp)
  8690. {
  8691. const struct firmware *firmware = bp->firmware;
  8692. struct bnx2x_fw_file_hdr *fw_hdr;
  8693. struct bnx2x_fw_file_section *sections;
  8694. u32 offset, len, num_ops;
  8695. u16 *ops_offsets;
  8696. int i;
  8697. const u8 *fw_ver;
  8698. if (firmware->size < sizeof(struct bnx2x_fw_file_hdr))
  8699. return -EINVAL;
  8700. fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
  8701. sections = (struct bnx2x_fw_file_section *)fw_hdr;
  8702. /* Make sure none of the offsets and sizes make us read beyond
  8703. * the end of the firmware data */
  8704. for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
  8705. offset = be32_to_cpu(sections[i].offset);
  8706. len = be32_to_cpu(sections[i].len);
  8707. if (offset + len > firmware->size) {
  8708. dev_err(&bp->pdev->dev,
  8709. "Section %d length is out of bounds\n", i);
  8710. return -EINVAL;
  8711. }
  8712. }
  8713. /* Likewise for the init_ops offsets */
  8714. offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
  8715. ops_offsets = (u16 *)(firmware->data + offset);
  8716. num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
  8717. for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
  8718. if (be16_to_cpu(ops_offsets[i]) > num_ops) {
  8719. dev_err(&bp->pdev->dev,
  8720. "Section offset %d is out of bounds\n", i);
  8721. return -EINVAL;
  8722. }
  8723. }
  8724. /* Check FW version */
  8725. offset = be32_to_cpu(fw_hdr->fw_version.offset);
  8726. fw_ver = firmware->data + offset;
  8727. if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
  8728. (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
  8729. (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
  8730. (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
  8731. dev_err(&bp->pdev->dev,
  8732. "Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
  8733. fw_ver[0], fw_ver[1], fw_ver[2],
  8734. fw_ver[3], BCM_5710_FW_MAJOR_VERSION,
  8735. BCM_5710_FW_MINOR_VERSION,
  8736. BCM_5710_FW_REVISION_VERSION,
  8737. BCM_5710_FW_ENGINEERING_VERSION);
  8738. return -EINVAL;
  8739. }
  8740. return 0;
  8741. }
  8742. static inline void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  8743. {
  8744. const __be32 *source = (const __be32 *)_source;
  8745. u32 *target = (u32 *)_target;
  8746. u32 i;
  8747. for (i = 0; i < n/4; i++)
  8748. target[i] = be32_to_cpu(source[i]);
  8749. }
  8750. /*
  8751. Ops array is stored in the following format:
  8752. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  8753. */
  8754. static inline void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  8755. {
  8756. const __be32 *source = (const __be32 *)_source;
  8757. struct raw_op *target = (struct raw_op *)_target;
  8758. u32 i, j, tmp;
  8759. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  8760. tmp = be32_to_cpu(source[j]);
  8761. target[i].op = (tmp >> 24) & 0xff;
  8762. target[i].offset = tmp & 0xffffff;
  8763. target[i].raw_data = be32_to_cpu(source[j + 1]);
  8764. }
  8765. }
  8766. /**
  8767. * IRO array is stored in the following format:
  8768. * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
  8769. */
  8770. static inline void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
  8771. {
  8772. const __be32 *source = (const __be32 *)_source;
  8773. struct iro *target = (struct iro *)_target;
  8774. u32 i, j, tmp;
  8775. for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
  8776. target[i].base = be32_to_cpu(source[j]);
  8777. j++;
  8778. tmp = be32_to_cpu(source[j]);
  8779. target[i].m1 = (tmp >> 16) & 0xffff;
  8780. target[i].m2 = tmp & 0xffff;
  8781. j++;
  8782. tmp = be32_to_cpu(source[j]);
  8783. target[i].m3 = (tmp >> 16) & 0xffff;
  8784. target[i].size = tmp & 0xffff;
  8785. j++;
  8786. }
  8787. }
  8788. static inline void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  8789. {
  8790. const __be16 *source = (const __be16 *)_source;
  8791. u16 *target = (u16 *)_target;
  8792. u32 i;
  8793. for (i = 0; i < n/2; i++)
  8794. target[i] = be16_to_cpu(source[i]);
  8795. }
  8796. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  8797. do { \
  8798. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  8799. bp->arr = kmalloc(len, GFP_KERNEL); \
  8800. if (!bp->arr) { \
  8801. pr_err("Failed to allocate %d bytes for "#arr"\n", len); \
  8802. goto lbl; \
  8803. } \
  8804. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  8805. (u8 *)bp->arr, len); \
  8806. } while (0)
  8807. int bnx2x_init_firmware(struct bnx2x *bp)
  8808. {
  8809. const char *fw_file_name;
  8810. struct bnx2x_fw_file_hdr *fw_hdr;
  8811. int rc;
  8812. if (CHIP_IS_E1(bp))
  8813. fw_file_name = FW_FILE_NAME_E1;
  8814. else if (CHIP_IS_E1H(bp))
  8815. fw_file_name = FW_FILE_NAME_E1H;
  8816. else if (!CHIP_IS_E1x(bp))
  8817. fw_file_name = FW_FILE_NAME_E2;
  8818. else {
  8819. BNX2X_ERR("Unsupported chip revision\n");
  8820. return -EINVAL;
  8821. }
  8822. BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
  8823. rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
  8824. if (rc) {
  8825. BNX2X_ERR("Can't load firmware file %s\n", fw_file_name);
  8826. goto request_firmware_exit;
  8827. }
  8828. rc = bnx2x_check_firmware(bp);
  8829. if (rc) {
  8830. BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
  8831. goto request_firmware_exit;
  8832. }
  8833. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  8834. /* Initialize the pointers to the init arrays */
  8835. /* Blob */
  8836. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  8837. /* Opcodes */
  8838. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  8839. /* Offsets */
  8840. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  8841. be16_to_cpu_n);
  8842. /* STORMs firmware */
  8843. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  8844. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  8845. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  8846. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  8847. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  8848. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  8849. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  8850. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  8851. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  8852. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  8853. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  8854. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  8855. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  8856. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  8857. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  8858. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  8859. /* IRO */
  8860. BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
  8861. return 0;
  8862. iro_alloc_err:
  8863. kfree(bp->init_ops_offsets);
  8864. init_offsets_alloc_err:
  8865. kfree(bp->init_ops);
  8866. init_ops_alloc_err:
  8867. kfree(bp->init_data);
  8868. request_firmware_exit:
  8869. release_firmware(bp->firmware);
  8870. return rc;
  8871. }
  8872. static void bnx2x_release_firmware(struct bnx2x *bp)
  8873. {
  8874. kfree(bp->init_ops_offsets);
  8875. kfree(bp->init_ops);
  8876. kfree(bp->init_data);
  8877. release_firmware(bp->firmware);
  8878. }
  8879. static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
  8880. .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
  8881. .init_hw_cmn = bnx2x_init_hw_common,
  8882. .init_hw_port = bnx2x_init_hw_port,
  8883. .init_hw_func = bnx2x_init_hw_func,
  8884. .reset_hw_cmn = bnx2x_reset_common,
  8885. .reset_hw_port = bnx2x_reset_port,
  8886. .reset_hw_func = bnx2x_reset_func,
  8887. .gunzip_init = bnx2x_gunzip_init,
  8888. .gunzip_end = bnx2x_gunzip_end,
  8889. .init_fw = bnx2x_init_firmware,
  8890. .release_fw = bnx2x_release_firmware,
  8891. };
  8892. void bnx2x__init_func_obj(struct bnx2x *bp)
  8893. {
  8894. /* Prepare DMAE related driver resources */
  8895. bnx2x_setup_dmae(bp);
  8896. bnx2x_init_func_obj(bp, &bp->func_obj,
  8897. bnx2x_sp(bp, func_rdata),
  8898. bnx2x_sp_mapping(bp, func_rdata),
  8899. &bnx2x_func_sp_drv);
  8900. }
  8901. /* must be called after sriov-enable */
  8902. static inline int bnx2x_set_qm_cid_count(struct bnx2x *bp)
  8903. {
  8904. int cid_count = BNX2X_L2_CID_COUNT(bp);
  8905. #ifdef BCM_CNIC
  8906. cid_count += CNIC_CID_MAX;
  8907. #endif
  8908. return roundup(cid_count, QM_CID_ROUND);
  8909. }
  8910. /**
  8911. * bnx2x_get_num_none_def_sbs - return the number of none default SBs
  8912. *
  8913. * @dev: pci device
  8914. *
  8915. */
  8916. static inline int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev)
  8917. {
  8918. int pos;
  8919. u16 control;
  8920. pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
  8921. /*
  8922. * If MSI-X is not supported - return number of SBs needed to support
  8923. * one fast path queue: one FP queue + SB for CNIC
  8924. */
  8925. if (!pos)
  8926. return 1 + CNIC_PRESENT;
  8927. /*
  8928. * The value in the PCI configuration space is the index of the last
  8929. * entry, namely one less than the actual size of the table, which is
  8930. * exactly what we want to return from this function: number of all SBs
  8931. * without the default SB.
  8932. */
  8933. pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control);
  8934. return control & PCI_MSIX_FLAGS_QSIZE;
  8935. }
  8936. static int __devinit bnx2x_init_one(struct pci_dev *pdev,
  8937. const struct pci_device_id *ent)
  8938. {
  8939. struct net_device *dev = NULL;
  8940. struct bnx2x *bp;
  8941. int pcie_width, pcie_speed;
  8942. int rc, max_non_def_sbs;
  8943. int rx_count, tx_count, rss_count;
  8944. /*
  8945. * An estimated maximum supported CoS number according to the chip
  8946. * version.
  8947. * We will try to roughly estimate the maximum number of CoSes this chip
  8948. * may support in order to minimize the memory allocated for Tx
  8949. * netdev_queue's. This number will be accurately calculated during the
  8950. * initialization of bp->max_cos based on the chip versions AND chip
  8951. * revision in the bnx2x_init_bp().
  8952. */
  8953. u8 max_cos_est = 0;
  8954. switch (ent->driver_data) {
  8955. case BCM57710:
  8956. case BCM57711:
  8957. case BCM57711E:
  8958. max_cos_est = BNX2X_MULTI_TX_COS_E1X;
  8959. break;
  8960. case BCM57712:
  8961. case BCM57712_MF:
  8962. max_cos_est = BNX2X_MULTI_TX_COS_E2_E3A0;
  8963. break;
  8964. case BCM57800:
  8965. case BCM57800_MF:
  8966. case BCM57810:
  8967. case BCM57810_MF:
  8968. case BCM57840:
  8969. case BCM57840_MF:
  8970. max_cos_est = BNX2X_MULTI_TX_COS_E3B0;
  8971. break;
  8972. default:
  8973. pr_err("Unknown board_type (%ld), aborting\n",
  8974. ent->driver_data);
  8975. return -ENODEV;
  8976. }
  8977. max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev);
  8978. /* !!! FIXME !!!
  8979. * Do not allow the maximum SB count to grow above 16
  8980. * since Special CIDs starts from 16*BNX2X_MULTI_TX_COS=48.
  8981. * We will use the FP_SB_MAX_E1x macro for this matter.
  8982. */
  8983. max_non_def_sbs = min_t(int, FP_SB_MAX_E1x, max_non_def_sbs);
  8984. WARN_ON(!max_non_def_sbs);
  8985. /* Maximum number of RSS queues: one IGU SB goes to CNIC */
  8986. rss_count = max_non_def_sbs - CNIC_PRESENT;
  8987. /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
  8988. rx_count = rss_count + FCOE_PRESENT;
  8989. /*
  8990. * Maximum number of netdev Tx queues:
  8991. * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
  8992. */
  8993. tx_count = MAX_TXQS_PER_COS * max_cos_est + FCOE_PRESENT;
  8994. /* dev zeroed in init_etherdev */
  8995. dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
  8996. if (!dev) {
  8997. dev_err(&pdev->dev, "Cannot allocate net device\n");
  8998. return -ENOMEM;
  8999. }
  9000. bp = netdev_priv(dev);
  9001. DP(NETIF_MSG_DRV, "Allocated netdev with %d tx and %d rx queues\n",
  9002. tx_count, rx_count);
  9003. bp->igu_sb_cnt = max_non_def_sbs;
  9004. bp->msg_enable = debug;
  9005. pci_set_drvdata(pdev, dev);
  9006. rc = bnx2x_init_dev(pdev, dev, ent->driver_data);
  9007. if (rc < 0) {
  9008. free_netdev(dev);
  9009. return rc;
  9010. }
  9011. DP(NETIF_MSG_DRV, "max_non_def_sbs %d\n", max_non_def_sbs);
  9012. rc = bnx2x_init_bp(bp);
  9013. if (rc)
  9014. goto init_one_exit;
  9015. /*
  9016. * Map doorbels here as we need the real value of bp->max_cos which
  9017. * is initialized in bnx2x_init_bp().
  9018. */
  9019. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  9020. min_t(u64, BNX2X_DB_SIZE(bp),
  9021. pci_resource_len(pdev, 2)));
  9022. if (!bp->doorbells) {
  9023. dev_err(&bp->pdev->dev,
  9024. "Cannot map doorbell space, aborting\n");
  9025. rc = -ENOMEM;
  9026. goto init_one_exit;
  9027. }
  9028. /* calc qm_cid_count */
  9029. bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
  9030. #ifdef BCM_CNIC
  9031. /* disable FCOE L2 queue for E1x */
  9032. if (CHIP_IS_E1x(bp))
  9033. bp->flags |= NO_FCOE_FLAG;
  9034. #endif
  9035. /* Configure interrupt mode: try to enable MSI-X/MSI if
  9036. * needed, set bp->num_queues appropriately.
  9037. */
  9038. bnx2x_set_int_mode(bp);
  9039. /* Add all NAPI objects */
  9040. bnx2x_add_all_napi(bp);
  9041. rc = register_netdev(dev);
  9042. if (rc) {
  9043. dev_err(&pdev->dev, "Cannot register net device\n");
  9044. goto init_one_exit;
  9045. }
  9046. #ifdef BCM_CNIC
  9047. if (!NO_FCOE(bp)) {
  9048. /* Add storage MAC address */
  9049. rtnl_lock();
  9050. dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  9051. rtnl_unlock();
  9052. }
  9053. #endif
  9054. bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
  9055. netdev_info(dev, "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
  9056. board_info[ent->driver_data].name,
  9057. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  9058. pcie_width,
  9059. ((!CHIP_IS_E2(bp) && pcie_speed == 2) ||
  9060. (CHIP_IS_E2(bp) && pcie_speed == 1)) ?
  9061. "5GHz (Gen2)" : "2.5GHz",
  9062. dev->base_addr, bp->pdev->irq, dev->dev_addr);
  9063. return 0;
  9064. init_one_exit:
  9065. if (bp->regview)
  9066. iounmap(bp->regview);
  9067. if (bp->doorbells)
  9068. iounmap(bp->doorbells);
  9069. free_netdev(dev);
  9070. if (atomic_read(&pdev->enable_cnt) == 1)
  9071. pci_release_regions(pdev);
  9072. pci_disable_device(pdev);
  9073. pci_set_drvdata(pdev, NULL);
  9074. return rc;
  9075. }
  9076. static void __devexit bnx2x_remove_one(struct pci_dev *pdev)
  9077. {
  9078. struct net_device *dev = pci_get_drvdata(pdev);
  9079. struct bnx2x *bp;
  9080. if (!dev) {
  9081. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  9082. return;
  9083. }
  9084. bp = netdev_priv(dev);
  9085. #ifdef BCM_CNIC
  9086. /* Delete storage MAC address */
  9087. if (!NO_FCOE(bp)) {
  9088. rtnl_lock();
  9089. dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  9090. rtnl_unlock();
  9091. }
  9092. #endif
  9093. #ifdef BCM_DCBNL
  9094. /* Delete app tlvs from dcbnl */
  9095. bnx2x_dcbnl_update_applist(bp, true);
  9096. #endif
  9097. unregister_netdev(dev);
  9098. /* Delete all NAPI objects */
  9099. bnx2x_del_all_napi(bp);
  9100. /* Power on: we can't let PCI layer write to us while we are in D3 */
  9101. bnx2x_set_power_state(bp, PCI_D0);
  9102. /* Disable MSI/MSI-X */
  9103. bnx2x_disable_msi(bp);
  9104. /* Power off */
  9105. bnx2x_set_power_state(bp, PCI_D3hot);
  9106. /* Make sure RESET task is not scheduled before continuing */
  9107. cancel_delayed_work_sync(&bp->sp_rtnl_task);
  9108. if (bp->regview)
  9109. iounmap(bp->regview);
  9110. if (bp->doorbells)
  9111. iounmap(bp->doorbells);
  9112. bnx2x_free_mem_bp(bp);
  9113. free_netdev(dev);
  9114. if (atomic_read(&pdev->enable_cnt) == 1)
  9115. pci_release_regions(pdev);
  9116. pci_disable_device(pdev);
  9117. pci_set_drvdata(pdev, NULL);
  9118. }
  9119. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  9120. {
  9121. int i;
  9122. bp->state = BNX2X_STATE_ERROR;
  9123. bp->rx_mode = BNX2X_RX_MODE_NONE;
  9124. #ifdef BCM_CNIC
  9125. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  9126. #endif
  9127. /* Stop Tx */
  9128. bnx2x_tx_disable(bp);
  9129. bnx2x_netif_stop(bp, 0);
  9130. del_timer_sync(&bp->timer);
  9131. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  9132. /* Release IRQs */
  9133. bnx2x_free_irq(bp);
  9134. /* Free SKBs, SGEs, TPA pool and driver internals */
  9135. bnx2x_free_skbs(bp);
  9136. for_each_rx_queue(bp, i)
  9137. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  9138. bnx2x_free_mem(bp);
  9139. bp->state = BNX2X_STATE_CLOSED;
  9140. netif_carrier_off(bp->dev);
  9141. return 0;
  9142. }
  9143. static void bnx2x_eeh_recover(struct bnx2x *bp)
  9144. {
  9145. u32 val;
  9146. mutex_init(&bp->port.phy_mutex);
  9147. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  9148. bp->link_params.shmem_base = bp->common.shmem_base;
  9149. BNX2X_DEV_INFO("shmem offset is 0x%x\n", bp->common.shmem_base);
  9150. if (!bp->common.shmem_base ||
  9151. (bp->common.shmem_base < 0xA0000) ||
  9152. (bp->common.shmem_base >= 0xC0000)) {
  9153. BNX2X_DEV_INFO("MCP not active\n");
  9154. bp->flags |= NO_MCP_FLAG;
  9155. return;
  9156. }
  9157. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  9158. if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  9159. != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  9160. BNX2X_ERR("BAD MCP validity signature\n");
  9161. if (!BP_NOMCP(bp)) {
  9162. bp->fw_seq =
  9163. (SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  9164. DRV_MSG_SEQ_NUMBER_MASK);
  9165. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  9166. }
  9167. }
  9168. /**
  9169. * bnx2x_io_error_detected - called when PCI error is detected
  9170. * @pdev: Pointer to PCI device
  9171. * @state: The current pci connection state
  9172. *
  9173. * This function is called after a PCI bus error affecting
  9174. * this device has been detected.
  9175. */
  9176. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  9177. pci_channel_state_t state)
  9178. {
  9179. struct net_device *dev = pci_get_drvdata(pdev);
  9180. struct bnx2x *bp = netdev_priv(dev);
  9181. rtnl_lock();
  9182. netif_device_detach(dev);
  9183. if (state == pci_channel_io_perm_failure) {
  9184. rtnl_unlock();
  9185. return PCI_ERS_RESULT_DISCONNECT;
  9186. }
  9187. if (netif_running(dev))
  9188. bnx2x_eeh_nic_unload(bp);
  9189. pci_disable_device(pdev);
  9190. rtnl_unlock();
  9191. /* Request a slot reset */
  9192. return PCI_ERS_RESULT_NEED_RESET;
  9193. }
  9194. /**
  9195. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  9196. * @pdev: Pointer to PCI device
  9197. *
  9198. * Restart the card from scratch, as if from a cold-boot.
  9199. */
  9200. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  9201. {
  9202. struct net_device *dev = pci_get_drvdata(pdev);
  9203. struct bnx2x *bp = netdev_priv(dev);
  9204. rtnl_lock();
  9205. if (pci_enable_device(pdev)) {
  9206. dev_err(&pdev->dev,
  9207. "Cannot re-enable PCI device after reset\n");
  9208. rtnl_unlock();
  9209. return PCI_ERS_RESULT_DISCONNECT;
  9210. }
  9211. pci_set_master(pdev);
  9212. pci_restore_state(pdev);
  9213. if (netif_running(dev))
  9214. bnx2x_set_power_state(bp, PCI_D0);
  9215. rtnl_unlock();
  9216. return PCI_ERS_RESULT_RECOVERED;
  9217. }
  9218. /**
  9219. * bnx2x_io_resume - called when traffic can start flowing again
  9220. * @pdev: Pointer to PCI device
  9221. *
  9222. * This callback is called when the error recovery driver tells us that
  9223. * its OK to resume normal operation.
  9224. */
  9225. static void bnx2x_io_resume(struct pci_dev *pdev)
  9226. {
  9227. struct net_device *dev = pci_get_drvdata(pdev);
  9228. struct bnx2x *bp = netdev_priv(dev);
  9229. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  9230. netdev_err(bp->dev, "Handling parity error recovery. "
  9231. "Try again later\n");
  9232. return;
  9233. }
  9234. rtnl_lock();
  9235. bnx2x_eeh_recover(bp);
  9236. if (netif_running(dev))
  9237. bnx2x_nic_load(bp, LOAD_NORMAL);
  9238. netif_device_attach(dev);
  9239. rtnl_unlock();
  9240. }
  9241. static struct pci_error_handlers bnx2x_err_handler = {
  9242. .error_detected = bnx2x_io_error_detected,
  9243. .slot_reset = bnx2x_io_slot_reset,
  9244. .resume = bnx2x_io_resume,
  9245. };
  9246. static struct pci_driver bnx2x_pci_driver = {
  9247. .name = DRV_MODULE_NAME,
  9248. .id_table = bnx2x_pci_tbl,
  9249. .probe = bnx2x_init_one,
  9250. .remove = __devexit_p(bnx2x_remove_one),
  9251. .suspend = bnx2x_suspend,
  9252. .resume = bnx2x_resume,
  9253. .err_handler = &bnx2x_err_handler,
  9254. };
  9255. static int __init bnx2x_init(void)
  9256. {
  9257. int ret;
  9258. pr_info("%s", version);
  9259. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  9260. if (bnx2x_wq == NULL) {
  9261. pr_err("Cannot create workqueue\n");
  9262. return -ENOMEM;
  9263. }
  9264. ret = pci_register_driver(&bnx2x_pci_driver);
  9265. if (ret) {
  9266. pr_err("Cannot register driver\n");
  9267. destroy_workqueue(bnx2x_wq);
  9268. }
  9269. return ret;
  9270. }
  9271. static void __exit bnx2x_cleanup(void)
  9272. {
  9273. pci_unregister_driver(&bnx2x_pci_driver);
  9274. destroy_workqueue(bnx2x_wq);
  9275. }
  9276. void bnx2x_notify_link_changed(struct bnx2x *bp)
  9277. {
  9278. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
  9279. }
  9280. module_init(bnx2x_init);
  9281. module_exit(bnx2x_cleanup);
  9282. #ifdef BCM_CNIC
  9283. /**
  9284. * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
  9285. *
  9286. * @bp: driver handle
  9287. * @set: set or clear the CAM entry
  9288. *
  9289. * This function will wait until the ramdord completion returns.
  9290. * Return 0 if success, -ENODEV if ramrod doesn't return.
  9291. */
  9292. static inline int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
  9293. {
  9294. unsigned long ramrod_flags = 0;
  9295. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  9296. return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
  9297. &bp->iscsi_l2_mac_obj, true,
  9298. BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
  9299. }
  9300. /* count denotes the number of new completions we have seen */
  9301. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  9302. {
  9303. struct eth_spe *spe;
  9304. #ifdef BNX2X_STOP_ON_ERROR
  9305. if (unlikely(bp->panic))
  9306. return;
  9307. #endif
  9308. spin_lock_bh(&bp->spq_lock);
  9309. BUG_ON(bp->cnic_spq_pending < count);
  9310. bp->cnic_spq_pending -= count;
  9311. for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
  9312. u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
  9313. & SPE_HDR_CONN_TYPE) >>
  9314. SPE_HDR_CONN_TYPE_SHIFT;
  9315. u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
  9316. >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
  9317. /* Set validation for iSCSI L2 client before sending SETUP
  9318. * ramrod
  9319. */
  9320. if (type == ETH_CONNECTION_TYPE) {
  9321. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP)
  9322. bnx2x_set_ctx_validation(bp, &bp->context.
  9323. vcxt[BNX2X_ISCSI_ETH_CID].eth,
  9324. BNX2X_ISCSI_ETH_CID);
  9325. }
  9326. /*
  9327. * There may be not more than 8 L2, not more than 8 L5 SPEs
  9328. * and in the air. We also check that number of outstanding
  9329. * COMMON ramrods is not more than the EQ and SPQ can
  9330. * accommodate.
  9331. */
  9332. if (type == ETH_CONNECTION_TYPE) {
  9333. if (!atomic_read(&bp->cq_spq_left))
  9334. break;
  9335. else
  9336. atomic_dec(&bp->cq_spq_left);
  9337. } else if (type == NONE_CONNECTION_TYPE) {
  9338. if (!atomic_read(&bp->eq_spq_left))
  9339. break;
  9340. else
  9341. atomic_dec(&bp->eq_spq_left);
  9342. } else if ((type == ISCSI_CONNECTION_TYPE) ||
  9343. (type == FCOE_CONNECTION_TYPE)) {
  9344. if (bp->cnic_spq_pending >=
  9345. bp->cnic_eth_dev.max_kwqe_pending)
  9346. break;
  9347. else
  9348. bp->cnic_spq_pending++;
  9349. } else {
  9350. BNX2X_ERR("Unknown SPE type: %d\n", type);
  9351. bnx2x_panic();
  9352. break;
  9353. }
  9354. spe = bnx2x_sp_get_next(bp);
  9355. *spe = *bp->cnic_kwq_cons;
  9356. DP(NETIF_MSG_TIMER, "pending on SPQ %d, on KWQ %d count %d\n",
  9357. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  9358. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  9359. bp->cnic_kwq_cons = bp->cnic_kwq;
  9360. else
  9361. bp->cnic_kwq_cons++;
  9362. }
  9363. bnx2x_sp_prod_update(bp);
  9364. spin_unlock_bh(&bp->spq_lock);
  9365. }
  9366. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  9367. struct kwqe_16 *kwqes[], u32 count)
  9368. {
  9369. struct bnx2x *bp = netdev_priv(dev);
  9370. int i;
  9371. #ifdef BNX2X_STOP_ON_ERROR
  9372. if (unlikely(bp->panic))
  9373. return -EIO;
  9374. #endif
  9375. spin_lock_bh(&bp->spq_lock);
  9376. for (i = 0; i < count; i++) {
  9377. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  9378. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  9379. break;
  9380. *bp->cnic_kwq_prod = *spe;
  9381. bp->cnic_kwq_pending++;
  9382. DP(NETIF_MSG_TIMER, "L5 SPQE %x %x %x:%x pos %d\n",
  9383. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  9384. spe->data.update_data_addr.hi,
  9385. spe->data.update_data_addr.lo,
  9386. bp->cnic_kwq_pending);
  9387. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  9388. bp->cnic_kwq_prod = bp->cnic_kwq;
  9389. else
  9390. bp->cnic_kwq_prod++;
  9391. }
  9392. spin_unlock_bh(&bp->spq_lock);
  9393. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  9394. bnx2x_cnic_sp_post(bp, 0);
  9395. return i;
  9396. }
  9397. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  9398. {
  9399. struct cnic_ops *c_ops;
  9400. int rc = 0;
  9401. mutex_lock(&bp->cnic_mutex);
  9402. c_ops = rcu_dereference_protected(bp->cnic_ops,
  9403. lockdep_is_held(&bp->cnic_mutex));
  9404. if (c_ops)
  9405. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  9406. mutex_unlock(&bp->cnic_mutex);
  9407. return rc;
  9408. }
  9409. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  9410. {
  9411. struct cnic_ops *c_ops;
  9412. int rc = 0;
  9413. rcu_read_lock();
  9414. c_ops = rcu_dereference(bp->cnic_ops);
  9415. if (c_ops)
  9416. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  9417. rcu_read_unlock();
  9418. return rc;
  9419. }
  9420. /*
  9421. * for commands that have no data
  9422. */
  9423. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  9424. {
  9425. struct cnic_ctl_info ctl = {0};
  9426. ctl.cmd = cmd;
  9427. return bnx2x_cnic_ctl_send(bp, &ctl);
  9428. }
  9429. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
  9430. {
  9431. struct cnic_ctl_info ctl = {0};
  9432. /* first we tell CNIC and only then we count this as a completion */
  9433. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  9434. ctl.data.comp.cid = cid;
  9435. ctl.data.comp.error = err;
  9436. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  9437. bnx2x_cnic_sp_post(bp, 0);
  9438. }
  9439. /* Called with netif_addr_lock_bh() taken.
  9440. * Sets an rx_mode config for an iSCSI ETH client.
  9441. * Doesn't block.
  9442. * Completion should be checked outside.
  9443. */
  9444. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
  9445. {
  9446. unsigned long accept_flags = 0, ramrod_flags = 0;
  9447. u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  9448. int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
  9449. if (start) {
  9450. /* Start accepting on iSCSI L2 ring. Accept all multicasts
  9451. * because it's the only way for UIO Queue to accept
  9452. * multicasts (in non-promiscuous mode only one Queue per
  9453. * function will receive multicast packets (leading in our
  9454. * case).
  9455. */
  9456. __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
  9457. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
  9458. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
  9459. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  9460. /* Clear STOP_PENDING bit if START is requested */
  9461. clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
  9462. sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
  9463. } else
  9464. /* Clear START_PENDING bit if STOP is requested */
  9465. clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
  9466. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  9467. set_bit(sched_state, &bp->sp_state);
  9468. else {
  9469. __set_bit(RAMROD_RX, &ramrod_flags);
  9470. bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
  9471. ramrod_flags);
  9472. }
  9473. }
  9474. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  9475. {
  9476. struct bnx2x *bp = netdev_priv(dev);
  9477. int rc = 0;
  9478. switch (ctl->cmd) {
  9479. case DRV_CTL_CTXTBL_WR_CMD: {
  9480. u32 index = ctl->data.io.offset;
  9481. dma_addr_t addr = ctl->data.io.dma_addr;
  9482. bnx2x_ilt_wr(bp, index, addr);
  9483. break;
  9484. }
  9485. case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
  9486. int count = ctl->data.credit.credit_count;
  9487. bnx2x_cnic_sp_post(bp, count);
  9488. break;
  9489. }
  9490. /* rtnl_lock is held. */
  9491. case DRV_CTL_START_L2_CMD: {
  9492. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  9493. unsigned long sp_bits = 0;
  9494. /* Configure the iSCSI classification object */
  9495. bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
  9496. cp->iscsi_l2_client_id,
  9497. cp->iscsi_l2_cid, BP_FUNC(bp),
  9498. bnx2x_sp(bp, mac_rdata),
  9499. bnx2x_sp_mapping(bp, mac_rdata),
  9500. BNX2X_FILTER_MAC_PENDING,
  9501. &bp->sp_state, BNX2X_OBJ_TYPE_RX,
  9502. &bp->macs_pool);
  9503. /* Set iSCSI MAC address */
  9504. rc = bnx2x_set_iscsi_eth_mac_addr(bp);
  9505. if (rc)
  9506. break;
  9507. mmiowb();
  9508. barrier();
  9509. /* Start accepting on iSCSI L2 ring */
  9510. netif_addr_lock_bh(dev);
  9511. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  9512. netif_addr_unlock_bh(dev);
  9513. /* bits to wait on */
  9514. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  9515. __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
  9516. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  9517. BNX2X_ERR("rx_mode completion timed out!\n");
  9518. break;
  9519. }
  9520. /* rtnl_lock is held. */
  9521. case DRV_CTL_STOP_L2_CMD: {
  9522. unsigned long sp_bits = 0;
  9523. /* Stop accepting on iSCSI L2 ring */
  9524. netif_addr_lock_bh(dev);
  9525. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  9526. netif_addr_unlock_bh(dev);
  9527. /* bits to wait on */
  9528. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  9529. __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
  9530. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  9531. BNX2X_ERR("rx_mode completion timed out!\n");
  9532. mmiowb();
  9533. barrier();
  9534. /* Unset iSCSI L2 MAC */
  9535. rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
  9536. BNX2X_ISCSI_ETH_MAC, true);
  9537. break;
  9538. }
  9539. case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
  9540. int count = ctl->data.credit.credit_count;
  9541. smp_mb__before_atomic_inc();
  9542. atomic_add(count, &bp->cq_spq_left);
  9543. smp_mb__after_atomic_inc();
  9544. break;
  9545. }
  9546. default:
  9547. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  9548. rc = -EINVAL;
  9549. }
  9550. return rc;
  9551. }
  9552. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  9553. {
  9554. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  9555. if (bp->flags & USING_MSIX_FLAG) {
  9556. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  9557. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  9558. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  9559. } else {
  9560. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  9561. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  9562. }
  9563. if (!CHIP_IS_E1x(bp))
  9564. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
  9565. else
  9566. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
  9567. cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
  9568. cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
  9569. cp->irq_arr[1].status_blk = bp->def_status_blk;
  9570. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  9571. cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
  9572. cp->num_irq = 2;
  9573. }
  9574. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  9575. void *data)
  9576. {
  9577. struct bnx2x *bp = netdev_priv(dev);
  9578. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  9579. if (ops == NULL)
  9580. return -EINVAL;
  9581. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  9582. if (!bp->cnic_kwq)
  9583. return -ENOMEM;
  9584. bp->cnic_kwq_cons = bp->cnic_kwq;
  9585. bp->cnic_kwq_prod = bp->cnic_kwq;
  9586. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  9587. bp->cnic_spq_pending = 0;
  9588. bp->cnic_kwq_pending = 0;
  9589. bp->cnic_data = data;
  9590. cp->num_irq = 0;
  9591. cp->drv_state |= CNIC_DRV_STATE_REGD;
  9592. cp->iro_arr = bp->iro_arr;
  9593. bnx2x_setup_cnic_irq_info(bp);
  9594. rcu_assign_pointer(bp->cnic_ops, ops);
  9595. return 0;
  9596. }
  9597. static int bnx2x_unregister_cnic(struct net_device *dev)
  9598. {
  9599. struct bnx2x *bp = netdev_priv(dev);
  9600. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  9601. mutex_lock(&bp->cnic_mutex);
  9602. cp->drv_state = 0;
  9603. rcu_assign_pointer(bp->cnic_ops, NULL);
  9604. mutex_unlock(&bp->cnic_mutex);
  9605. synchronize_rcu();
  9606. kfree(bp->cnic_kwq);
  9607. bp->cnic_kwq = NULL;
  9608. return 0;
  9609. }
  9610. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  9611. {
  9612. struct bnx2x *bp = netdev_priv(dev);
  9613. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  9614. /* If both iSCSI and FCoE are disabled - return NULL in
  9615. * order to indicate CNIC that it should not try to work
  9616. * with this device.
  9617. */
  9618. if (NO_ISCSI(bp) && NO_FCOE(bp))
  9619. return NULL;
  9620. cp->drv_owner = THIS_MODULE;
  9621. cp->chip_id = CHIP_ID(bp);
  9622. cp->pdev = bp->pdev;
  9623. cp->io_base = bp->regview;
  9624. cp->io_base2 = bp->doorbells;
  9625. cp->max_kwqe_pending = 8;
  9626. cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
  9627. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  9628. bnx2x_cid_ilt_lines(bp);
  9629. cp->ctx_tbl_len = CNIC_ILT_LINES;
  9630. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  9631. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  9632. cp->drv_ctl = bnx2x_drv_ctl;
  9633. cp->drv_register_cnic = bnx2x_register_cnic;
  9634. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  9635. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID;
  9636. cp->iscsi_l2_client_id =
  9637. bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  9638. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID;
  9639. if (NO_ISCSI_OOO(bp))
  9640. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  9641. if (NO_ISCSI(bp))
  9642. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
  9643. if (NO_FCOE(bp))
  9644. cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
  9645. DP(BNX2X_MSG_SP, "page_size %d, tbl_offset %d, tbl_lines %d, "
  9646. "starting cid %d\n",
  9647. cp->ctx_blk_size,
  9648. cp->ctx_tbl_offset,
  9649. cp->ctx_tbl_len,
  9650. cp->starting_cid);
  9651. return cp;
  9652. }
  9653. EXPORT_SYMBOL(bnx2x_cnic_probe);
  9654. #endif /* BCM_CNIC */