bnx2x_main.c 317 KB

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