bnx2x_main.c 291 KB

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