bnx2x_main.c 318 KB

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