bnx2x_main.c 342 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769
  1. /* bnx2x_main.c: Broadcom Everest network driver.
  2. *
  3. * Copyright (c) 2007-2012 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_vlan.h>
  41. #include <net/ip.h>
  42. #include <net/ipv6.h>
  43. #include <net/tcp.h>
  44. #include <net/checksum.h>
  45. #include <net/ip6_checksum.h>
  46. #include <linux/workqueue.h>
  47. #include <linux/crc32.h>
  48. #include <linux/crc32c.h>
  49. #include <linux/prefetch.h>
  50. #include <linux/zlib.h>
  51. #include <linux/io.h>
  52. #include <linux/semaphore.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. #define MAC_LEADING_ZERO_CNT (ALIGN(ETH_ALEN, sizeof(u32)) - ETH_ALEN)
  73. /* Time in jiffies before concluding the transmitter is hung */
  74. #define TX_TIMEOUT (5*HZ)
  75. static char version[] __devinitdata =
  76. "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
  77. DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  78. MODULE_AUTHOR("Eliezer Tamir");
  79. MODULE_DESCRIPTION("Broadcom NetXtreme II "
  80. "BCM57710/57711/57711E/"
  81. "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
  82. "57840/57840_MF Driver");
  83. MODULE_LICENSE("GPL");
  84. MODULE_VERSION(DRV_MODULE_VERSION);
  85. MODULE_FIRMWARE(FW_FILE_NAME_E1);
  86. MODULE_FIRMWARE(FW_FILE_NAME_E1H);
  87. MODULE_FIRMWARE(FW_FILE_NAME_E2);
  88. int num_queues;
  89. module_param(num_queues, int, 0);
  90. MODULE_PARM_DESC(num_queues,
  91. " Set number of queues (default is as a number of CPUs)");
  92. static int disable_tpa;
  93. module_param(disable_tpa, int, 0);
  94. MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
  95. #define INT_MODE_INTx 1
  96. #define INT_MODE_MSI 2
  97. int int_mode;
  98. module_param(int_mode, int, 0);
  99. MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
  100. "(1 INT#x; 2 MSI)");
  101. static int dropless_fc;
  102. module_param(dropless_fc, int, 0);
  103. MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
  104. static int mrrs = -1;
  105. module_param(mrrs, int, 0);
  106. MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
  107. static int debug;
  108. module_param(debug, int, 0);
  109. MODULE_PARM_DESC(debug, " Default debug msglevel");
  110. struct workqueue_struct *bnx2x_wq;
  111. enum bnx2x_board_type {
  112. BCM57710 = 0,
  113. BCM57711,
  114. BCM57711E,
  115. BCM57712,
  116. BCM57712_MF,
  117. BCM57800,
  118. BCM57800_MF,
  119. BCM57810,
  120. BCM57810_MF,
  121. BCM57840_O,
  122. BCM57840_4_10,
  123. BCM57840_2_20,
  124. BCM57840_MFO,
  125. BCM57840_MF,
  126. BCM57811,
  127. BCM57811_MF
  128. };
  129. /* indexed by board_type, above */
  130. static struct {
  131. char *name;
  132. } board_info[] __devinitdata = {
  133. { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
  134. { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
  135. { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
  136. { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
  137. { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
  138. { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
  139. { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
  140. { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
  141. { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
  142. { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
  143. { "Broadcom NetXtreme II BCM57840 10 Gigabit Ethernet" },
  144. { "Broadcom NetXtreme II BCM57840 20 Gigabit Ethernet" },
  145. { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function"},
  146. { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function"},
  147. { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet"},
  148. { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet Multi Function"},
  149. };
  150. #ifndef PCI_DEVICE_ID_NX2_57710
  151. #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
  152. #endif
  153. #ifndef PCI_DEVICE_ID_NX2_57711
  154. #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
  155. #endif
  156. #ifndef PCI_DEVICE_ID_NX2_57711E
  157. #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
  158. #endif
  159. #ifndef PCI_DEVICE_ID_NX2_57712
  160. #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
  161. #endif
  162. #ifndef PCI_DEVICE_ID_NX2_57712_MF
  163. #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
  164. #endif
  165. #ifndef PCI_DEVICE_ID_NX2_57800
  166. #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
  167. #endif
  168. #ifndef PCI_DEVICE_ID_NX2_57800_MF
  169. #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
  170. #endif
  171. #ifndef PCI_DEVICE_ID_NX2_57810
  172. #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
  173. #endif
  174. #ifndef PCI_DEVICE_ID_NX2_57810_MF
  175. #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
  176. #endif
  177. #ifndef PCI_DEVICE_ID_NX2_57840_O
  178. #define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE
  179. #endif
  180. #ifndef PCI_DEVICE_ID_NX2_57840_4_10
  181. #define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10
  182. #endif
  183. #ifndef PCI_DEVICE_ID_NX2_57840_2_20
  184. #define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20
  185. #endif
  186. #ifndef PCI_DEVICE_ID_NX2_57840_MFO
  187. #define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE
  188. #endif
  189. #ifndef PCI_DEVICE_ID_NX2_57840_MF
  190. #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
  191. #endif
  192. #ifndef PCI_DEVICE_ID_NX2_57811
  193. #define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
  194. #endif
  195. #ifndef PCI_DEVICE_ID_NX2_57811_MF
  196. #define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
  197. #endif
  198. static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
  199. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
  200. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
  201. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
  202. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
  203. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
  204. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
  205. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
  206. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
  207. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
  208. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_O), BCM57840_O },
  209. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
  210. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_2_20), BCM57840_2_20 },
  211. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MFO), BCM57840_MFO },
  212. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
  213. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 },
  214. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF },
  215. { 0 }
  216. };
  217. MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
  218. /* Global resources for unloading a previously loaded device */
  219. #define BNX2X_PREV_WAIT_NEEDED 1
  220. static DEFINE_SEMAPHORE(bnx2x_prev_sem);
  221. static LIST_HEAD(bnx2x_prev_list);
  222. /****************************************************************************
  223. * General service functions
  224. ****************************************************************************/
  225. static void __storm_memset_dma_mapping(struct bnx2x *bp,
  226. u32 addr, dma_addr_t mapping)
  227. {
  228. REG_WR(bp, addr, U64_LO(mapping));
  229. REG_WR(bp, addr + 4, U64_HI(mapping));
  230. }
  231. static void storm_memset_spq_addr(struct bnx2x *bp,
  232. dma_addr_t mapping, u16 abs_fid)
  233. {
  234. u32 addr = XSEM_REG_FAST_MEMORY +
  235. XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
  236. __storm_memset_dma_mapping(bp, addr, mapping);
  237. }
  238. static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
  239. u16 pf_id)
  240. {
  241. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
  242. pf_id);
  243. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
  244. pf_id);
  245. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
  246. pf_id);
  247. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
  248. pf_id);
  249. }
  250. static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
  251. u8 enable)
  252. {
  253. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
  254. enable);
  255. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
  256. enable);
  257. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
  258. enable);
  259. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
  260. enable);
  261. }
  262. static void storm_memset_eq_data(struct bnx2x *bp,
  263. struct event_ring_data *eq_data,
  264. u16 pfid)
  265. {
  266. size_t size = sizeof(struct event_ring_data);
  267. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
  268. __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
  269. }
  270. static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
  271. u16 pfid)
  272. {
  273. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
  274. REG_WR16(bp, addr, eq_prod);
  275. }
  276. /* used only at init
  277. * locking is done by mcp
  278. */
  279. static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
  280. {
  281. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  282. pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
  283. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  284. PCICFG_VENDOR_ID_OFFSET);
  285. }
  286. static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
  287. {
  288. u32 val;
  289. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  290. pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
  291. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  292. PCICFG_VENDOR_ID_OFFSET);
  293. return val;
  294. }
  295. #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
  296. #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
  297. #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
  298. #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
  299. #define DMAE_DP_DST_NONE "dst_addr [none]"
  300. /* copy command into DMAE command memory and set DMAE command go */
  301. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
  302. {
  303. u32 cmd_offset;
  304. int i;
  305. cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
  306. for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
  307. REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
  308. }
  309. REG_WR(bp, dmae_reg_go_c[idx], 1);
  310. }
  311. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
  312. {
  313. return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
  314. DMAE_CMD_C_ENABLE);
  315. }
  316. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
  317. {
  318. return opcode & ~DMAE_CMD_SRC_RESET;
  319. }
  320. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  321. bool with_comp, u8 comp_type)
  322. {
  323. u32 opcode = 0;
  324. opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
  325. (dst_type << DMAE_COMMAND_DST_SHIFT));
  326. opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
  327. opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
  328. opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
  329. (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
  330. opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
  331. #ifdef __BIG_ENDIAN
  332. opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
  333. #else
  334. opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
  335. #endif
  336. if (with_comp)
  337. opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
  338. return opcode;
  339. }
  340. static void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
  341. struct dmae_command *dmae,
  342. u8 src_type, u8 dst_type)
  343. {
  344. memset(dmae, 0, sizeof(struct dmae_command));
  345. /* set the opcode */
  346. dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
  347. true, DMAE_COMP_PCI);
  348. /* fill in the completion parameters */
  349. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
  350. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
  351. dmae->comp_val = DMAE_COMP_VAL;
  352. }
  353. /* issue a dmae command over the init-channel and wailt for completion */
  354. static int bnx2x_issue_dmae_with_comp(struct bnx2x *bp,
  355. struct dmae_command *dmae)
  356. {
  357. u32 *wb_comp = bnx2x_sp(bp, wb_comp);
  358. int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
  359. int rc = 0;
  360. /*
  361. * Lock the dmae channel. Disable BHs to prevent a dead-lock
  362. * as long as this code is called both from syscall context and
  363. * from ndo_set_rx_mode() flow that may be called from BH.
  364. */
  365. spin_lock_bh(&bp->dmae_lock);
  366. /* reset completion */
  367. *wb_comp = 0;
  368. /* post the command on the channel used for initializations */
  369. bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
  370. /* wait for completion */
  371. udelay(5);
  372. while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
  373. if (!cnt ||
  374. (bp->recovery_state != BNX2X_RECOVERY_DONE &&
  375. bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  376. BNX2X_ERR("DMAE timeout!\n");
  377. rc = DMAE_TIMEOUT;
  378. goto unlock;
  379. }
  380. cnt--;
  381. udelay(50);
  382. }
  383. if (*wb_comp & DMAE_PCI_ERR_FLAG) {
  384. BNX2X_ERR("DMAE PCI error!\n");
  385. rc = DMAE_PCI_ERROR;
  386. }
  387. unlock:
  388. spin_unlock_bh(&bp->dmae_lock);
  389. return rc;
  390. }
  391. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  392. u32 len32)
  393. {
  394. struct dmae_command dmae;
  395. if (!bp->dmae_ready) {
  396. u32 *data = bnx2x_sp(bp, wb_data[0]);
  397. if (CHIP_IS_E1(bp))
  398. bnx2x_init_ind_wr(bp, dst_addr, data, len32);
  399. else
  400. bnx2x_init_str_wr(bp, dst_addr, data, len32);
  401. return;
  402. }
  403. /* set opcode and fixed command fields */
  404. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
  405. /* fill in addresses and len */
  406. dmae.src_addr_lo = U64_LO(dma_addr);
  407. dmae.src_addr_hi = U64_HI(dma_addr);
  408. dmae.dst_addr_lo = dst_addr >> 2;
  409. dmae.dst_addr_hi = 0;
  410. dmae.len = len32;
  411. /* issue the command and wait for completion */
  412. bnx2x_issue_dmae_with_comp(bp, &dmae);
  413. }
  414. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
  415. {
  416. struct dmae_command dmae;
  417. if (!bp->dmae_ready) {
  418. u32 *data = bnx2x_sp(bp, wb_data[0]);
  419. int i;
  420. if (CHIP_IS_E1(bp))
  421. for (i = 0; i < len32; i++)
  422. data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
  423. else
  424. for (i = 0; i < len32; i++)
  425. data[i] = REG_RD(bp, src_addr + i*4);
  426. return;
  427. }
  428. /* set opcode and fixed command fields */
  429. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
  430. /* fill in addresses and len */
  431. dmae.src_addr_lo = src_addr >> 2;
  432. dmae.src_addr_hi = 0;
  433. dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
  434. dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
  435. dmae.len = len32;
  436. /* issue the command and wait for completion */
  437. bnx2x_issue_dmae_with_comp(bp, &dmae);
  438. }
  439. static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
  440. u32 addr, u32 len)
  441. {
  442. int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
  443. int offset = 0;
  444. while (len > dmae_wr_max) {
  445. bnx2x_write_dmae(bp, phys_addr + offset,
  446. addr + offset, dmae_wr_max);
  447. offset += dmae_wr_max * 4;
  448. len -= dmae_wr_max;
  449. }
  450. bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
  451. }
  452. static int bnx2x_mc_assert(struct bnx2x *bp)
  453. {
  454. char last_idx;
  455. int i, rc = 0;
  456. u32 row0, row1, row2, row3;
  457. /* XSTORM */
  458. last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
  459. XSTORM_ASSERT_LIST_INDEX_OFFSET);
  460. if (last_idx)
  461. BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  462. /* print the asserts */
  463. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  464. row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  465. XSTORM_ASSERT_LIST_OFFSET(i));
  466. row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  467. XSTORM_ASSERT_LIST_OFFSET(i) + 4);
  468. row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  469. XSTORM_ASSERT_LIST_OFFSET(i) + 8);
  470. row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  471. XSTORM_ASSERT_LIST_OFFSET(i) + 12);
  472. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  473. BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  474. i, row3, row2, row1, row0);
  475. rc++;
  476. } else {
  477. break;
  478. }
  479. }
  480. /* TSTORM */
  481. last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
  482. TSTORM_ASSERT_LIST_INDEX_OFFSET);
  483. if (last_idx)
  484. BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  485. /* print the asserts */
  486. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  487. row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  488. TSTORM_ASSERT_LIST_OFFSET(i));
  489. row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  490. TSTORM_ASSERT_LIST_OFFSET(i) + 4);
  491. row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  492. TSTORM_ASSERT_LIST_OFFSET(i) + 8);
  493. row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  494. TSTORM_ASSERT_LIST_OFFSET(i) + 12);
  495. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  496. BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  497. i, row3, row2, row1, row0);
  498. rc++;
  499. } else {
  500. break;
  501. }
  502. }
  503. /* CSTORM */
  504. last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
  505. CSTORM_ASSERT_LIST_INDEX_OFFSET);
  506. if (last_idx)
  507. BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  508. /* print the asserts */
  509. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  510. row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  511. CSTORM_ASSERT_LIST_OFFSET(i));
  512. row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  513. CSTORM_ASSERT_LIST_OFFSET(i) + 4);
  514. row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  515. CSTORM_ASSERT_LIST_OFFSET(i) + 8);
  516. row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  517. CSTORM_ASSERT_LIST_OFFSET(i) + 12);
  518. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  519. BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  520. i, row3, row2, row1, row0);
  521. rc++;
  522. } else {
  523. break;
  524. }
  525. }
  526. /* USTORM */
  527. last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
  528. USTORM_ASSERT_LIST_INDEX_OFFSET);
  529. if (last_idx)
  530. BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  531. /* print the asserts */
  532. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  533. row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
  534. USTORM_ASSERT_LIST_OFFSET(i));
  535. row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
  536. USTORM_ASSERT_LIST_OFFSET(i) + 4);
  537. row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
  538. USTORM_ASSERT_LIST_OFFSET(i) + 8);
  539. row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
  540. USTORM_ASSERT_LIST_OFFSET(i) + 12);
  541. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  542. BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  543. i, row3, row2, row1, row0);
  544. rc++;
  545. } else {
  546. break;
  547. }
  548. }
  549. return rc;
  550. }
  551. void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
  552. {
  553. u32 addr, val;
  554. u32 mark, offset;
  555. __be32 data[9];
  556. int word;
  557. u32 trace_shmem_base;
  558. if (BP_NOMCP(bp)) {
  559. BNX2X_ERR("NO MCP - can not dump\n");
  560. return;
  561. }
  562. netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
  563. (bp->common.bc_ver & 0xff0000) >> 16,
  564. (bp->common.bc_ver & 0xff00) >> 8,
  565. (bp->common.bc_ver & 0xff));
  566. val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
  567. if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
  568. BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
  569. if (BP_PATH(bp) == 0)
  570. trace_shmem_base = bp->common.shmem_base;
  571. else
  572. trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
  573. addr = trace_shmem_base - 0x800;
  574. /* validate TRCB signature */
  575. mark = REG_RD(bp, addr);
  576. if (mark != MFW_TRACE_SIGNATURE) {
  577. BNX2X_ERR("Trace buffer signature is missing.");
  578. return ;
  579. }
  580. /* read cyclic buffer pointer */
  581. addr += 4;
  582. mark = REG_RD(bp, addr);
  583. mark = (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH)
  584. + ((mark + 0x3) & ~0x3) - 0x08000000;
  585. printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
  586. printk("%s", lvl);
  587. for (offset = mark; offset <= trace_shmem_base; offset += 0x8*4) {
  588. for (word = 0; word < 8; word++)
  589. data[word] = htonl(REG_RD(bp, offset + 4*word));
  590. data[8] = 0x0;
  591. pr_cont("%s", (char *)data);
  592. }
  593. for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
  594. for (word = 0; word < 8; word++)
  595. data[word] = htonl(REG_RD(bp, offset + 4*word));
  596. data[8] = 0x0;
  597. pr_cont("%s", (char *)data);
  598. }
  599. printk("%s" "end of fw dump\n", lvl);
  600. }
  601. static void bnx2x_fw_dump(struct bnx2x *bp)
  602. {
  603. bnx2x_fw_dump_lvl(bp, KERN_ERR);
  604. }
  605. void bnx2x_panic_dump(struct bnx2x *bp)
  606. {
  607. int i;
  608. u16 j;
  609. struct hc_sp_status_block_data sp_sb_data;
  610. int func = BP_FUNC(bp);
  611. #ifdef BNX2X_STOP_ON_ERROR
  612. u16 start = 0, end = 0;
  613. u8 cos;
  614. #endif
  615. bp->stats_state = STATS_STATE_DISABLED;
  616. bp->eth_stats.unrecoverable_error++;
  617. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  618. BNX2X_ERR("begin crash dump -----------------\n");
  619. /* Indices */
  620. /* Common */
  621. BNX2X_ERR("def_idx(0x%x) def_att_idx(0x%x) attn_state(0x%x) spq_prod_idx(0x%x) next_stats_cnt(0x%x)\n",
  622. bp->def_idx, bp->def_att_idx, bp->attn_state,
  623. bp->spq_prod_idx, bp->stats_counter);
  624. BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
  625. bp->def_status_blk->atten_status_block.attn_bits,
  626. bp->def_status_blk->atten_status_block.attn_bits_ack,
  627. bp->def_status_blk->atten_status_block.status_block_id,
  628. bp->def_status_blk->atten_status_block.attn_bits_index);
  629. BNX2X_ERR(" def (");
  630. for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
  631. pr_cont("0x%x%s",
  632. bp->def_status_blk->sp_sb.index_values[i],
  633. (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
  634. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  635. *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  636. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  637. i*sizeof(u32));
  638. 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",
  639. sp_sb_data.igu_sb_id,
  640. sp_sb_data.igu_seg_id,
  641. sp_sb_data.p_func.pf_id,
  642. sp_sb_data.p_func.vnic_id,
  643. sp_sb_data.p_func.vf_id,
  644. sp_sb_data.p_func.vf_valid,
  645. sp_sb_data.state);
  646. for_each_eth_queue(bp, i) {
  647. struct bnx2x_fastpath *fp = &bp->fp[i];
  648. int loop;
  649. struct hc_status_block_data_e2 sb_data_e2;
  650. struct hc_status_block_data_e1x sb_data_e1x;
  651. struct hc_status_block_sm *hc_sm_p =
  652. CHIP_IS_E1x(bp) ?
  653. sb_data_e1x.common.state_machine :
  654. sb_data_e2.common.state_machine;
  655. struct hc_index_data *hc_index_p =
  656. CHIP_IS_E1x(bp) ?
  657. sb_data_e1x.index_data :
  658. sb_data_e2.index_data;
  659. u8 data_size, cos;
  660. u32 *sb_data_p;
  661. struct bnx2x_fp_txdata txdata;
  662. /* Rx */
  663. BNX2X_ERR("fp%d: rx_bd_prod(0x%x) rx_bd_cons(0x%x) rx_comp_prod(0x%x) rx_comp_cons(0x%x) *rx_cons_sb(0x%x)\n",
  664. i, fp->rx_bd_prod, fp->rx_bd_cons,
  665. fp->rx_comp_prod,
  666. fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
  667. BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
  668. fp->rx_sge_prod, fp->last_max_sge,
  669. le16_to_cpu(fp->fp_hc_idx));
  670. /* Tx */
  671. for_each_cos_in_tx_queue(fp, cos)
  672. {
  673. txdata = *fp->txdata_ptr[cos];
  674. BNX2X_ERR("fp%d: tx_pkt_prod(0x%x) tx_pkt_cons(0x%x) tx_bd_prod(0x%x) tx_bd_cons(0x%x) *tx_cons_sb(0x%x)\n",
  675. i, txdata.tx_pkt_prod,
  676. txdata.tx_pkt_cons, txdata.tx_bd_prod,
  677. txdata.tx_bd_cons,
  678. le16_to_cpu(*txdata.tx_cons_sb));
  679. }
  680. loop = CHIP_IS_E1x(bp) ?
  681. HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
  682. /* host sb data */
  683. #ifdef BCM_CNIC
  684. if (IS_FCOE_FP(fp))
  685. continue;
  686. #endif
  687. BNX2X_ERR(" run indexes (");
  688. for (j = 0; j < HC_SB_MAX_SM; j++)
  689. pr_cont("0x%x%s",
  690. fp->sb_running_index[j],
  691. (j == HC_SB_MAX_SM - 1) ? ")" : " ");
  692. BNX2X_ERR(" indexes (");
  693. for (j = 0; j < loop; j++)
  694. pr_cont("0x%x%s",
  695. fp->sb_index_values[j],
  696. (j == loop - 1) ? ")" : " ");
  697. /* fw sb data */
  698. data_size = CHIP_IS_E1x(bp) ?
  699. sizeof(struct hc_status_block_data_e1x) :
  700. sizeof(struct hc_status_block_data_e2);
  701. data_size /= sizeof(u32);
  702. sb_data_p = CHIP_IS_E1x(bp) ?
  703. (u32 *)&sb_data_e1x :
  704. (u32 *)&sb_data_e2;
  705. /* copy sb data in here */
  706. for (j = 0; j < data_size; j++)
  707. *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  708. CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
  709. j * sizeof(u32));
  710. if (!CHIP_IS_E1x(bp)) {
  711. pr_cont("pf_id(0x%x) vf_id(0x%x) vf_valid(0x%x) vnic_id(0x%x) same_igu_sb_1b(0x%x) state(0x%x)\n",
  712. sb_data_e2.common.p_func.pf_id,
  713. sb_data_e2.common.p_func.vf_id,
  714. sb_data_e2.common.p_func.vf_valid,
  715. sb_data_e2.common.p_func.vnic_id,
  716. sb_data_e2.common.same_igu_sb_1b,
  717. sb_data_e2.common.state);
  718. } else {
  719. pr_cont("pf_id(0x%x) vf_id(0x%x) vf_valid(0x%x) vnic_id(0x%x) same_igu_sb_1b(0x%x) state(0x%x)\n",
  720. sb_data_e1x.common.p_func.pf_id,
  721. sb_data_e1x.common.p_func.vf_id,
  722. sb_data_e1x.common.p_func.vf_valid,
  723. sb_data_e1x.common.p_func.vnic_id,
  724. sb_data_e1x.common.same_igu_sb_1b,
  725. sb_data_e1x.common.state);
  726. }
  727. /* SB_SMs data */
  728. for (j = 0; j < HC_SB_MAX_SM; j++) {
  729. pr_cont("SM[%d] __flags (0x%x) igu_sb_id (0x%x) igu_seg_id(0x%x) time_to_expire (0x%x) timer_value(0x%x)\n",
  730. j, hc_sm_p[j].__flags,
  731. hc_sm_p[j].igu_sb_id,
  732. hc_sm_p[j].igu_seg_id,
  733. hc_sm_p[j].time_to_expire,
  734. hc_sm_p[j].timer_value);
  735. }
  736. /* Indecies data */
  737. for (j = 0; j < loop; j++) {
  738. pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
  739. hc_index_p[j].flags,
  740. hc_index_p[j].timeout);
  741. }
  742. }
  743. #ifdef BNX2X_STOP_ON_ERROR
  744. /* Rings */
  745. /* Rx */
  746. for_each_rx_queue(bp, i) {
  747. struct bnx2x_fastpath *fp = &bp->fp[i];
  748. start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
  749. end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
  750. for (j = start; j != end; j = RX_BD(j + 1)) {
  751. u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
  752. struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
  753. BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
  754. i, j, rx_bd[1], rx_bd[0], sw_bd->data);
  755. }
  756. start = RX_SGE(fp->rx_sge_prod);
  757. end = RX_SGE(fp->last_max_sge);
  758. for (j = start; j != end; j = RX_SGE(j + 1)) {
  759. u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
  760. struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
  761. BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
  762. i, j, rx_sge[1], rx_sge[0], sw_page->page);
  763. }
  764. start = RCQ_BD(fp->rx_comp_cons - 10);
  765. end = RCQ_BD(fp->rx_comp_cons + 503);
  766. for (j = start; j != end; j = RCQ_BD(j + 1)) {
  767. u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
  768. BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
  769. i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
  770. }
  771. }
  772. /* Tx */
  773. for_each_tx_queue(bp, i) {
  774. struct bnx2x_fastpath *fp = &bp->fp[i];
  775. for_each_cos_in_tx_queue(fp, cos) {
  776. struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos];
  777. start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
  778. end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
  779. for (j = start; j != end; j = TX_BD(j + 1)) {
  780. struct sw_tx_bd *sw_bd =
  781. &txdata->tx_buf_ring[j];
  782. BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
  783. i, cos, j, sw_bd->skb,
  784. sw_bd->first_bd);
  785. }
  786. start = TX_BD(txdata->tx_bd_cons - 10);
  787. end = TX_BD(txdata->tx_bd_cons + 254);
  788. for (j = start; j != end; j = TX_BD(j + 1)) {
  789. u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
  790. BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
  791. i, cos, j, tx_bd[0], tx_bd[1],
  792. tx_bd[2], tx_bd[3]);
  793. }
  794. }
  795. }
  796. #endif
  797. bnx2x_fw_dump(bp);
  798. bnx2x_mc_assert(bp);
  799. BNX2X_ERR("end crash dump -----------------\n");
  800. }
  801. /*
  802. * FLR Support for E2
  803. *
  804. * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
  805. * initialization.
  806. */
  807. #define FLR_WAIT_USEC 10000 /* 10 miliseconds */
  808. #define FLR_WAIT_INTERVAL 50 /* usec */
  809. #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
  810. struct pbf_pN_buf_regs {
  811. int pN;
  812. u32 init_crd;
  813. u32 crd;
  814. u32 crd_freed;
  815. };
  816. struct pbf_pN_cmd_regs {
  817. int pN;
  818. u32 lines_occup;
  819. u32 lines_freed;
  820. };
  821. static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
  822. struct pbf_pN_buf_regs *regs,
  823. u32 poll_count)
  824. {
  825. u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
  826. u32 cur_cnt = poll_count;
  827. crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
  828. crd = crd_start = REG_RD(bp, regs->crd);
  829. init_crd = REG_RD(bp, regs->init_crd);
  830. DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
  831. DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
  832. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
  833. while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
  834. (init_crd - crd_start))) {
  835. if (cur_cnt--) {
  836. udelay(FLR_WAIT_INTERVAL);
  837. crd = REG_RD(bp, regs->crd);
  838. crd_freed = REG_RD(bp, regs->crd_freed);
  839. } else {
  840. DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
  841. regs->pN);
  842. DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
  843. regs->pN, crd);
  844. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
  845. regs->pN, crd_freed);
  846. break;
  847. }
  848. }
  849. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
  850. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  851. }
  852. static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
  853. struct pbf_pN_cmd_regs *regs,
  854. u32 poll_count)
  855. {
  856. u32 occup, to_free, freed, freed_start;
  857. u32 cur_cnt = poll_count;
  858. occup = to_free = REG_RD(bp, regs->lines_occup);
  859. freed = freed_start = REG_RD(bp, regs->lines_freed);
  860. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
  861. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
  862. while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
  863. if (cur_cnt--) {
  864. udelay(FLR_WAIT_INTERVAL);
  865. occup = REG_RD(bp, regs->lines_occup);
  866. freed = REG_RD(bp, regs->lines_freed);
  867. } else {
  868. DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
  869. regs->pN);
  870. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
  871. regs->pN, occup);
  872. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
  873. regs->pN, freed);
  874. break;
  875. }
  876. }
  877. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
  878. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  879. }
  880. static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
  881. u32 expected, u32 poll_count)
  882. {
  883. u32 cur_cnt = poll_count;
  884. u32 val;
  885. while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
  886. udelay(FLR_WAIT_INTERVAL);
  887. return val;
  888. }
  889. static int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
  890. char *msg, u32 poll_cnt)
  891. {
  892. u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
  893. if (val != 0) {
  894. BNX2X_ERR("%s usage count=%d\n", msg, val);
  895. return 1;
  896. }
  897. return 0;
  898. }
  899. static u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
  900. {
  901. /* adjust polling timeout */
  902. if (CHIP_REV_IS_EMUL(bp))
  903. return FLR_POLL_CNT * 2000;
  904. if (CHIP_REV_IS_FPGA(bp))
  905. return FLR_POLL_CNT * 120;
  906. return FLR_POLL_CNT;
  907. }
  908. static void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
  909. {
  910. struct pbf_pN_cmd_regs cmd_regs[] = {
  911. {0, (CHIP_IS_E3B0(bp)) ?
  912. PBF_REG_TQ_OCCUPANCY_Q0 :
  913. PBF_REG_P0_TQ_OCCUPANCY,
  914. (CHIP_IS_E3B0(bp)) ?
  915. PBF_REG_TQ_LINES_FREED_CNT_Q0 :
  916. PBF_REG_P0_TQ_LINES_FREED_CNT},
  917. {1, (CHIP_IS_E3B0(bp)) ?
  918. PBF_REG_TQ_OCCUPANCY_Q1 :
  919. PBF_REG_P1_TQ_OCCUPANCY,
  920. (CHIP_IS_E3B0(bp)) ?
  921. PBF_REG_TQ_LINES_FREED_CNT_Q1 :
  922. PBF_REG_P1_TQ_LINES_FREED_CNT},
  923. {4, (CHIP_IS_E3B0(bp)) ?
  924. PBF_REG_TQ_OCCUPANCY_LB_Q :
  925. PBF_REG_P4_TQ_OCCUPANCY,
  926. (CHIP_IS_E3B0(bp)) ?
  927. PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
  928. PBF_REG_P4_TQ_LINES_FREED_CNT}
  929. };
  930. struct pbf_pN_buf_regs buf_regs[] = {
  931. {0, (CHIP_IS_E3B0(bp)) ?
  932. PBF_REG_INIT_CRD_Q0 :
  933. PBF_REG_P0_INIT_CRD ,
  934. (CHIP_IS_E3B0(bp)) ?
  935. PBF_REG_CREDIT_Q0 :
  936. PBF_REG_P0_CREDIT,
  937. (CHIP_IS_E3B0(bp)) ?
  938. PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
  939. PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
  940. {1, (CHIP_IS_E3B0(bp)) ?
  941. PBF_REG_INIT_CRD_Q1 :
  942. PBF_REG_P1_INIT_CRD,
  943. (CHIP_IS_E3B0(bp)) ?
  944. PBF_REG_CREDIT_Q1 :
  945. PBF_REG_P1_CREDIT,
  946. (CHIP_IS_E3B0(bp)) ?
  947. PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
  948. PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
  949. {4, (CHIP_IS_E3B0(bp)) ?
  950. PBF_REG_INIT_CRD_LB_Q :
  951. PBF_REG_P4_INIT_CRD,
  952. (CHIP_IS_E3B0(bp)) ?
  953. PBF_REG_CREDIT_LB_Q :
  954. PBF_REG_P4_CREDIT,
  955. (CHIP_IS_E3B0(bp)) ?
  956. PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
  957. PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
  958. };
  959. int i;
  960. /* Verify the command queues are flushed P0, P1, P4 */
  961. for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
  962. bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
  963. /* Verify the transmission buffers are flushed P0, P1, P4 */
  964. for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
  965. bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
  966. }
  967. #define OP_GEN_PARAM(param) \
  968. (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
  969. #define OP_GEN_TYPE(type) \
  970. (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
  971. #define OP_GEN_AGG_VECT(index) \
  972. (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
  973. static int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func,
  974. u32 poll_cnt)
  975. {
  976. struct sdm_op_gen op_gen = {0};
  977. u32 comp_addr = BAR_CSTRORM_INTMEM +
  978. CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
  979. int ret = 0;
  980. if (REG_RD(bp, comp_addr)) {
  981. BNX2X_ERR("Cleanup complete was not 0 before sending\n");
  982. return 1;
  983. }
  984. op_gen.command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
  985. op_gen.command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
  986. op_gen.command |= OP_GEN_AGG_VECT(clnup_func);
  987. op_gen.command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
  988. DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
  989. REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen.command);
  990. if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
  991. BNX2X_ERR("FW final cleanup did not succeed\n");
  992. DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
  993. (REG_RD(bp, comp_addr)));
  994. ret = 1;
  995. }
  996. /* Zero completion for nxt FLR */
  997. REG_WR(bp, comp_addr, 0);
  998. return ret;
  999. }
  1000. static u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
  1001. {
  1002. int pos;
  1003. u16 status;
  1004. pos = pci_pcie_cap(dev);
  1005. if (!pos)
  1006. return false;
  1007. pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, &status);
  1008. return status & PCI_EXP_DEVSTA_TRPND;
  1009. }
  1010. /* PF FLR specific routines
  1011. */
  1012. static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
  1013. {
  1014. /* wait for CFC PF usage-counter to zero (includes all the VFs) */
  1015. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1016. CFC_REG_NUM_LCIDS_INSIDE_PF,
  1017. "CFC PF usage counter timed out",
  1018. poll_cnt))
  1019. return 1;
  1020. /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
  1021. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1022. DORQ_REG_PF_USAGE_CNT,
  1023. "DQ PF usage counter timed out",
  1024. poll_cnt))
  1025. return 1;
  1026. /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
  1027. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1028. QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
  1029. "QM PF usage counter timed out",
  1030. poll_cnt))
  1031. return 1;
  1032. /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
  1033. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1034. TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
  1035. "Timers VNIC usage counter timed out",
  1036. poll_cnt))
  1037. return 1;
  1038. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1039. TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
  1040. "Timers NUM_SCANS usage counter timed out",
  1041. poll_cnt))
  1042. return 1;
  1043. /* Wait DMAE PF usage counter to zero */
  1044. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1045. dmae_reg_go_c[INIT_DMAE_C(bp)],
  1046. "DMAE dommand register timed out",
  1047. poll_cnt))
  1048. return 1;
  1049. return 0;
  1050. }
  1051. static void bnx2x_hw_enable_status(struct bnx2x *bp)
  1052. {
  1053. u32 val;
  1054. val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
  1055. DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
  1056. val = REG_RD(bp, PBF_REG_DISABLE_PF);
  1057. DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
  1058. val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
  1059. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
  1060. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
  1061. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
  1062. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
  1063. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
  1064. val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
  1065. DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
  1066. val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
  1067. DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
  1068. val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  1069. DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
  1070. val);
  1071. }
  1072. static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
  1073. {
  1074. u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
  1075. DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
  1076. /* Re-enable PF target read access */
  1077. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  1078. /* Poll HW usage counters */
  1079. DP(BNX2X_MSG_SP, "Polling usage counters\n");
  1080. if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
  1081. return -EBUSY;
  1082. /* Zero the igu 'trailing edge' and 'leading edge' */
  1083. /* Send the FW cleanup command */
  1084. if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
  1085. return -EBUSY;
  1086. /* ATC cleanup */
  1087. /* Verify TX hw is flushed */
  1088. bnx2x_tx_hw_flushed(bp, poll_cnt);
  1089. /* Wait 100ms (not adjusted according to platform) */
  1090. msleep(100);
  1091. /* Verify no pending pci transactions */
  1092. if (bnx2x_is_pcie_pending(bp->pdev))
  1093. BNX2X_ERR("PCIE Transactions still pending\n");
  1094. /* Debug */
  1095. bnx2x_hw_enable_status(bp);
  1096. /*
  1097. * Master enable - Due to WB DMAE writes performed before this
  1098. * register is re-initialized as part of the regular function init
  1099. */
  1100. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  1101. return 0;
  1102. }
  1103. static void bnx2x_hc_int_enable(struct bnx2x *bp)
  1104. {
  1105. int port = BP_PORT(bp);
  1106. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1107. u32 val = REG_RD(bp, addr);
  1108. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1109. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1110. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1111. if (msix) {
  1112. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1113. HC_CONFIG_0_REG_INT_LINE_EN_0);
  1114. val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1115. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1116. if (single_msix)
  1117. val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
  1118. } else if (msi) {
  1119. val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
  1120. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1121. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1122. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1123. } else {
  1124. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1125. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1126. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1127. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1128. if (!CHIP_IS_E1(bp)) {
  1129. DP(NETIF_MSG_IFUP,
  1130. "write %x to HC %d (addr 0x%x)\n", val, port, addr);
  1131. REG_WR(bp, addr, val);
  1132. val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
  1133. }
  1134. }
  1135. if (CHIP_IS_E1(bp))
  1136. REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
  1137. DP(NETIF_MSG_IFUP,
  1138. "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
  1139. (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1140. REG_WR(bp, addr, val);
  1141. /*
  1142. * Ensure that HC_CONFIG is written before leading/trailing edge config
  1143. */
  1144. mmiowb();
  1145. barrier();
  1146. if (!CHIP_IS_E1(bp)) {
  1147. /* init leading/trailing edge */
  1148. if (IS_MF(bp)) {
  1149. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1150. if (bp->port.pmf)
  1151. /* enable nig and gpio3 attention */
  1152. val |= 0x1100;
  1153. } else
  1154. val = 0xffff;
  1155. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  1156. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  1157. }
  1158. /* Make sure that interrupts are indeed enabled from here on */
  1159. mmiowb();
  1160. }
  1161. static void bnx2x_igu_int_enable(struct bnx2x *bp)
  1162. {
  1163. u32 val;
  1164. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1165. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1166. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1167. val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1168. if (msix) {
  1169. val &= ~(IGU_PF_CONF_INT_LINE_EN |
  1170. IGU_PF_CONF_SINGLE_ISR_EN);
  1171. val |= (IGU_PF_CONF_FUNC_EN |
  1172. IGU_PF_CONF_MSI_MSIX_EN |
  1173. IGU_PF_CONF_ATTN_BIT_EN);
  1174. if (single_msix)
  1175. val |= IGU_PF_CONF_SINGLE_ISR_EN;
  1176. } else if (msi) {
  1177. val &= ~IGU_PF_CONF_INT_LINE_EN;
  1178. val |= (IGU_PF_CONF_FUNC_EN |
  1179. IGU_PF_CONF_MSI_MSIX_EN |
  1180. IGU_PF_CONF_ATTN_BIT_EN |
  1181. IGU_PF_CONF_SINGLE_ISR_EN);
  1182. } else {
  1183. val &= ~IGU_PF_CONF_MSI_MSIX_EN;
  1184. val |= (IGU_PF_CONF_FUNC_EN |
  1185. IGU_PF_CONF_INT_LINE_EN |
  1186. IGU_PF_CONF_ATTN_BIT_EN |
  1187. IGU_PF_CONF_SINGLE_ISR_EN);
  1188. }
  1189. DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
  1190. val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1191. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1192. if (val & IGU_PF_CONF_INT_LINE_EN)
  1193. pci_intx(bp->pdev, true);
  1194. barrier();
  1195. /* init leading/trailing edge */
  1196. if (IS_MF(bp)) {
  1197. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1198. if (bp->port.pmf)
  1199. /* enable nig and gpio3 attention */
  1200. val |= 0x1100;
  1201. } else
  1202. val = 0xffff;
  1203. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  1204. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  1205. /* Make sure that interrupts are indeed enabled from here on */
  1206. mmiowb();
  1207. }
  1208. void bnx2x_int_enable(struct bnx2x *bp)
  1209. {
  1210. if (bp->common.int_block == INT_BLOCK_HC)
  1211. bnx2x_hc_int_enable(bp);
  1212. else
  1213. bnx2x_igu_int_enable(bp);
  1214. }
  1215. static void bnx2x_hc_int_disable(struct bnx2x *bp)
  1216. {
  1217. int port = BP_PORT(bp);
  1218. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1219. u32 val = REG_RD(bp, addr);
  1220. /*
  1221. * in E1 we must use only PCI configuration space to disable
  1222. * MSI/MSIX capablility
  1223. * It's forbitten to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
  1224. */
  1225. if (CHIP_IS_E1(bp)) {
  1226. /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
  1227. * Use mask register to prevent from HC sending interrupts
  1228. * after we exit the function
  1229. */
  1230. REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
  1231. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1232. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1233. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1234. } else
  1235. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1236. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1237. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1238. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1239. DP(NETIF_MSG_IFDOWN,
  1240. "write %x to HC %d (addr 0x%x)\n",
  1241. val, port, addr);
  1242. /* flush all outstanding writes */
  1243. mmiowb();
  1244. REG_WR(bp, addr, val);
  1245. if (REG_RD(bp, addr) != val)
  1246. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  1247. }
  1248. static void bnx2x_igu_int_disable(struct bnx2x *bp)
  1249. {
  1250. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1251. val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
  1252. IGU_PF_CONF_INT_LINE_EN |
  1253. IGU_PF_CONF_ATTN_BIT_EN);
  1254. DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
  1255. /* flush all outstanding writes */
  1256. mmiowb();
  1257. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1258. if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
  1259. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  1260. }
  1261. void bnx2x_int_disable(struct bnx2x *bp)
  1262. {
  1263. if (bp->common.int_block == INT_BLOCK_HC)
  1264. bnx2x_hc_int_disable(bp);
  1265. else
  1266. bnx2x_igu_int_disable(bp);
  1267. }
  1268. void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
  1269. {
  1270. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1271. int i, offset;
  1272. if (disable_hw)
  1273. /* prevent the HW from sending interrupts */
  1274. bnx2x_int_disable(bp);
  1275. /* make sure all ISRs are done */
  1276. if (msix) {
  1277. synchronize_irq(bp->msix_table[0].vector);
  1278. offset = 1;
  1279. #ifdef BCM_CNIC
  1280. offset++;
  1281. #endif
  1282. for_each_eth_queue(bp, i)
  1283. synchronize_irq(bp->msix_table[offset++].vector);
  1284. } else
  1285. synchronize_irq(bp->pdev->irq);
  1286. /* make sure sp_task is not running */
  1287. cancel_delayed_work(&bp->sp_task);
  1288. cancel_delayed_work(&bp->period_task);
  1289. flush_workqueue(bnx2x_wq);
  1290. }
  1291. /* fast path */
  1292. /*
  1293. * General service functions
  1294. */
  1295. /* Return true if succeeded to acquire the lock */
  1296. static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
  1297. {
  1298. u32 lock_status;
  1299. u32 resource_bit = (1 << resource);
  1300. int func = BP_FUNC(bp);
  1301. u32 hw_lock_control_reg;
  1302. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1303. "Trying to take a lock on resource %d\n", resource);
  1304. /* Validating that the resource is within range */
  1305. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1306. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1307. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1308. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1309. return false;
  1310. }
  1311. if (func <= 5)
  1312. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1313. else
  1314. hw_lock_control_reg =
  1315. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1316. /* Try to acquire the lock */
  1317. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1318. lock_status = REG_RD(bp, hw_lock_control_reg);
  1319. if (lock_status & resource_bit)
  1320. return true;
  1321. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1322. "Failed to get a lock on resource %d\n", resource);
  1323. return false;
  1324. }
  1325. /**
  1326. * bnx2x_get_leader_lock_resource - get the recovery leader resource id
  1327. *
  1328. * @bp: driver handle
  1329. *
  1330. * Returns the recovery leader resource id according to the engine this function
  1331. * belongs to. Currently only only 2 engines is supported.
  1332. */
  1333. static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
  1334. {
  1335. if (BP_PATH(bp))
  1336. return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
  1337. else
  1338. return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
  1339. }
  1340. /**
  1341. * bnx2x_trylock_leader_lock- try to aquire a leader lock.
  1342. *
  1343. * @bp: driver handle
  1344. *
  1345. * Tries to aquire a leader lock for current engine.
  1346. */
  1347. static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
  1348. {
  1349. return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1350. }
  1351. #ifdef BCM_CNIC
  1352. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
  1353. #endif
  1354. void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
  1355. {
  1356. struct bnx2x *bp = fp->bp;
  1357. int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1358. int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1359. enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
  1360. struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  1361. DP(BNX2X_MSG_SP,
  1362. "fp %d cid %d got ramrod #%d state is %x type is %d\n",
  1363. fp->index, cid, command, bp->state,
  1364. rr_cqe->ramrod_cqe.ramrod_type);
  1365. switch (command) {
  1366. case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
  1367. DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
  1368. drv_cmd = BNX2X_Q_CMD_UPDATE;
  1369. break;
  1370. case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
  1371. DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
  1372. drv_cmd = BNX2X_Q_CMD_SETUP;
  1373. break;
  1374. case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
  1375. DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
  1376. drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  1377. break;
  1378. case (RAMROD_CMD_ID_ETH_HALT):
  1379. DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
  1380. drv_cmd = BNX2X_Q_CMD_HALT;
  1381. break;
  1382. case (RAMROD_CMD_ID_ETH_TERMINATE):
  1383. DP(BNX2X_MSG_SP, "got MULTI[%d] teminate ramrod\n", cid);
  1384. drv_cmd = BNX2X_Q_CMD_TERMINATE;
  1385. break;
  1386. case (RAMROD_CMD_ID_ETH_EMPTY):
  1387. DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
  1388. drv_cmd = BNX2X_Q_CMD_EMPTY;
  1389. break;
  1390. default:
  1391. BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
  1392. command, fp->index);
  1393. return;
  1394. }
  1395. if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
  1396. q_obj->complete_cmd(bp, q_obj, drv_cmd))
  1397. /* q_obj->complete_cmd() failure means that this was
  1398. * an unexpected completion.
  1399. *
  1400. * In this case we don't want to increase the bp->spq_left
  1401. * because apparently we haven't sent this command the first
  1402. * place.
  1403. */
  1404. #ifdef BNX2X_STOP_ON_ERROR
  1405. bnx2x_panic();
  1406. #else
  1407. return;
  1408. #endif
  1409. smp_mb__before_atomic_inc();
  1410. atomic_inc(&bp->cq_spq_left);
  1411. /* push the change in bp->spq_left and towards the memory */
  1412. smp_mb__after_atomic_inc();
  1413. DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
  1414. if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
  1415. (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
  1416. /* if Q update ramrod is completed for last Q in AFEX vif set
  1417. * flow, then ACK MCP at the end
  1418. *
  1419. * mark pending ACK to MCP bit.
  1420. * prevent case that both bits are cleared.
  1421. * At the end of load/unload driver checks that
  1422. * sp_state is cleaerd, and this order prevents
  1423. * races
  1424. */
  1425. smp_mb__before_clear_bit();
  1426. set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
  1427. wmb();
  1428. clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  1429. smp_mb__after_clear_bit();
  1430. /* schedule workqueue to send ack to MCP */
  1431. queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1432. }
  1433. return;
  1434. }
  1435. void bnx2x_update_rx_prod(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  1436. u16 bd_prod, u16 rx_comp_prod, u16 rx_sge_prod)
  1437. {
  1438. u32 start = BAR_USTRORM_INTMEM + fp->ustorm_rx_prods_offset;
  1439. bnx2x_update_rx_prod_gen(bp, fp, bd_prod, rx_comp_prod, rx_sge_prod,
  1440. start);
  1441. }
  1442. irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
  1443. {
  1444. struct bnx2x *bp = netdev_priv(dev_instance);
  1445. u16 status = bnx2x_ack_int(bp);
  1446. u16 mask;
  1447. int i;
  1448. u8 cos;
  1449. /* Return here if interrupt is shared and it's not for us */
  1450. if (unlikely(status == 0)) {
  1451. DP(NETIF_MSG_INTR, "not our interrupt!\n");
  1452. return IRQ_NONE;
  1453. }
  1454. DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
  1455. #ifdef BNX2X_STOP_ON_ERROR
  1456. if (unlikely(bp->panic))
  1457. return IRQ_HANDLED;
  1458. #endif
  1459. for_each_eth_queue(bp, i) {
  1460. struct bnx2x_fastpath *fp = &bp->fp[i];
  1461. mask = 0x2 << (fp->index + CNIC_PRESENT);
  1462. if (status & mask) {
  1463. /* Handle Rx or Tx according to SB id */
  1464. prefetch(fp->rx_cons_sb);
  1465. for_each_cos_in_tx_queue(fp, cos)
  1466. prefetch(fp->txdata_ptr[cos]->tx_cons_sb);
  1467. prefetch(&fp->sb_running_index[SM_RX_ID]);
  1468. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  1469. status &= ~mask;
  1470. }
  1471. }
  1472. #ifdef BCM_CNIC
  1473. mask = 0x2;
  1474. if (status & (mask | 0x1)) {
  1475. struct cnic_ops *c_ops = NULL;
  1476. if (likely(bp->state == BNX2X_STATE_OPEN)) {
  1477. rcu_read_lock();
  1478. c_ops = rcu_dereference(bp->cnic_ops);
  1479. if (c_ops)
  1480. c_ops->cnic_handler(bp->cnic_data, NULL);
  1481. rcu_read_unlock();
  1482. }
  1483. status &= ~mask;
  1484. }
  1485. #endif
  1486. if (unlikely(status & 0x1)) {
  1487. queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1488. status &= ~0x1;
  1489. if (!status)
  1490. return IRQ_HANDLED;
  1491. }
  1492. if (unlikely(status))
  1493. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
  1494. status);
  1495. return IRQ_HANDLED;
  1496. }
  1497. /* Link */
  1498. /*
  1499. * General service functions
  1500. */
  1501. int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
  1502. {
  1503. u32 lock_status;
  1504. u32 resource_bit = (1 << resource);
  1505. int func = BP_FUNC(bp);
  1506. u32 hw_lock_control_reg;
  1507. int cnt;
  1508. /* Validating that the resource is within range */
  1509. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1510. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1511. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1512. return -EINVAL;
  1513. }
  1514. if (func <= 5) {
  1515. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1516. } else {
  1517. hw_lock_control_reg =
  1518. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1519. }
  1520. /* Validating that the resource is not already taken */
  1521. lock_status = REG_RD(bp, hw_lock_control_reg);
  1522. if (lock_status & resource_bit) {
  1523. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
  1524. lock_status, resource_bit);
  1525. return -EEXIST;
  1526. }
  1527. /* Try for 5 second every 5ms */
  1528. for (cnt = 0; cnt < 1000; cnt++) {
  1529. /* Try to acquire the lock */
  1530. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1531. lock_status = REG_RD(bp, hw_lock_control_reg);
  1532. if (lock_status & resource_bit)
  1533. return 0;
  1534. msleep(5);
  1535. }
  1536. BNX2X_ERR("Timeout\n");
  1537. return -EAGAIN;
  1538. }
  1539. int bnx2x_release_leader_lock(struct bnx2x *bp)
  1540. {
  1541. return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1542. }
  1543. int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
  1544. {
  1545. u32 lock_status;
  1546. u32 resource_bit = (1 << resource);
  1547. int func = BP_FUNC(bp);
  1548. u32 hw_lock_control_reg;
  1549. /* Validating that the resource is within range */
  1550. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1551. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1552. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1553. return -EINVAL;
  1554. }
  1555. if (func <= 5) {
  1556. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1557. } else {
  1558. hw_lock_control_reg =
  1559. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1560. }
  1561. /* Validating that the resource is currently taken */
  1562. lock_status = REG_RD(bp, hw_lock_control_reg);
  1563. if (!(lock_status & resource_bit)) {
  1564. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. unlock was called but lock wasn't taken!\n",
  1565. lock_status, resource_bit);
  1566. return -EFAULT;
  1567. }
  1568. REG_WR(bp, hw_lock_control_reg, resource_bit);
  1569. return 0;
  1570. }
  1571. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
  1572. {
  1573. /* The GPIO should be swapped if swap register is set and active */
  1574. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1575. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1576. int gpio_shift = gpio_num +
  1577. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1578. u32 gpio_mask = (1 << gpio_shift);
  1579. u32 gpio_reg;
  1580. int value;
  1581. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1582. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1583. return -EINVAL;
  1584. }
  1585. /* read GPIO value */
  1586. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1587. /* get the requested pin value */
  1588. if ((gpio_reg & gpio_mask) == gpio_mask)
  1589. value = 1;
  1590. else
  1591. value = 0;
  1592. DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
  1593. return value;
  1594. }
  1595. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1596. {
  1597. /* The GPIO should be swapped if swap register is set and active */
  1598. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1599. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1600. int gpio_shift = gpio_num +
  1601. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1602. u32 gpio_mask = (1 << gpio_shift);
  1603. u32 gpio_reg;
  1604. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1605. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1606. return -EINVAL;
  1607. }
  1608. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1609. /* read GPIO and mask except the float bits */
  1610. gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
  1611. switch (mode) {
  1612. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1613. DP(NETIF_MSG_LINK,
  1614. "Set GPIO %d (shift %d) -> output low\n",
  1615. gpio_num, gpio_shift);
  1616. /* clear FLOAT and set CLR */
  1617. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1618. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
  1619. break;
  1620. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1621. DP(NETIF_MSG_LINK,
  1622. "Set GPIO %d (shift %d) -> output high\n",
  1623. gpio_num, gpio_shift);
  1624. /* clear FLOAT and set SET */
  1625. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1626. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
  1627. break;
  1628. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1629. DP(NETIF_MSG_LINK,
  1630. "Set GPIO %d (shift %d) -> input\n",
  1631. gpio_num, gpio_shift);
  1632. /* set FLOAT */
  1633. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1634. break;
  1635. default:
  1636. break;
  1637. }
  1638. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1639. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1640. return 0;
  1641. }
  1642. int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
  1643. {
  1644. u32 gpio_reg = 0;
  1645. int rc = 0;
  1646. /* Any port swapping should be handled by caller. */
  1647. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1648. /* read GPIO and mask except the float bits */
  1649. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1650. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1651. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
  1652. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
  1653. switch (mode) {
  1654. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1655. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
  1656. /* set CLR */
  1657. gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
  1658. break;
  1659. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1660. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
  1661. /* set SET */
  1662. gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
  1663. break;
  1664. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1665. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
  1666. /* set FLOAT */
  1667. gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1668. break;
  1669. default:
  1670. BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
  1671. rc = -EINVAL;
  1672. break;
  1673. }
  1674. if (rc == 0)
  1675. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1676. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1677. return rc;
  1678. }
  1679. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1680. {
  1681. /* The GPIO should be swapped if swap register is set and active */
  1682. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1683. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1684. int gpio_shift = gpio_num +
  1685. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1686. u32 gpio_mask = (1 << gpio_shift);
  1687. u32 gpio_reg;
  1688. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1689. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1690. return -EINVAL;
  1691. }
  1692. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1693. /* read GPIO int */
  1694. gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
  1695. switch (mode) {
  1696. case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
  1697. DP(NETIF_MSG_LINK,
  1698. "Clear GPIO INT %d (shift %d) -> output low\n",
  1699. gpio_num, gpio_shift);
  1700. /* clear SET and set CLR */
  1701. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1702. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1703. break;
  1704. case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
  1705. DP(NETIF_MSG_LINK,
  1706. "Set GPIO INT %d (shift %d) -> output high\n",
  1707. gpio_num, gpio_shift);
  1708. /* clear CLR and set SET */
  1709. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1710. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1711. break;
  1712. default:
  1713. break;
  1714. }
  1715. REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
  1716. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1717. return 0;
  1718. }
  1719. static int bnx2x_set_spio(struct bnx2x *bp, int spio_num, u32 mode)
  1720. {
  1721. u32 spio_mask = (1 << spio_num);
  1722. u32 spio_reg;
  1723. if ((spio_num < MISC_REGISTERS_SPIO_4) ||
  1724. (spio_num > MISC_REGISTERS_SPIO_7)) {
  1725. BNX2X_ERR("Invalid SPIO %d\n", spio_num);
  1726. return -EINVAL;
  1727. }
  1728. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1729. /* read SPIO and mask except the float bits */
  1730. spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_REGISTERS_SPIO_FLOAT);
  1731. switch (mode) {
  1732. case MISC_REGISTERS_SPIO_OUTPUT_LOW:
  1733. DP(NETIF_MSG_HW, "Set SPIO %d -> output low\n", spio_num);
  1734. /* clear FLOAT and set CLR */
  1735. spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
  1736. spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_CLR_POS);
  1737. break;
  1738. case MISC_REGISTERS_SPIO_OUTPUT_HIGH:
  1739. DP(NETIF_MSG_HW, "Set SPIO %d -> output high\n", spio_num);
  1740. /* clear FLOAT and set SET */
  1741. spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
  1742. spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_SET_POS);
  1743. break;
  1744. case MISC_REGISTERS_SPIO_INPUT_HI_Z:
  1745. DP(NETIF_MSG_HW, "Set SPIO %d -> input\n", spio_num);
  1746. /* set FLOAT */
  1747. spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
  1748. break;
  1749. default:
  1750. break;
  1751. }
  1752. REG_WR(bp, MISC_REG_SPIO, spio_reg);
  1753. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1754. return 0;
  1755. }
  1756. void bnx2x_calc_fc_adv(struct bnx2x *bp)
  1757. {
  1758. u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1759. switch (bp->link_vars.ieee_fc &
  1760. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
  1761. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
  1762. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1763. ADVERTISED_Pause);
  1764. break;
  1765. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
  1766. bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
  1767. ADVERTISED_Pause);
  1768. break;
  1769. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
  1770. bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
  1771. break;
  1772. default:
  1773. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1774. ADVERTISED_Pause);
  1775. break;
  1776. }
  1777. }
  1778. u8 bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
  1779. {
  1780. if (!BP_NOMCP(bp)) {
  1781. u8 rc;
  1782. int cfx_idx = bnx2x_get_link_cfg_idx(bp);
  1783. u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
  1784. /*
  1785. * Initialize link parameters structure variables
  1786. * It is recommended to turn off RX FC for jumbo frames
  1787. * for better performance
  1788. */
  1789. if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
  1790. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
  1791. else
  1792. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
  1793. bnx2x_acquire_phy_lock(bp);
  1794. if (load_mode == LOAD_DIAG) {
  1795. struct link_params *lp = &bp->link_params;
  1796. lp->loopback_mode = LOOPBACK_XGXS;
  1797. /* do PHY loopback at 10G speed, if possible */
  1798. if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
  1799. if (lp->speed_cap_mask[cfx_idx] &
  1800. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  1801. lp->req_line_speed[cfx_idx] =
  1802. SPEED_10000;
  1803. else
  1804. lp->req_line_speed[cfx_idx] =
  1805. SPEED_1000;
  1806. }
  1807. }
  1808. if (load_mode == LOAD_LOOPBACK_EXT) {
  1809. struct link_params *lp = &bp->link_params;
  1810. lp->loopback_mode = LOOPBACK_EXT;
  1811. }
  1812. rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1813. bnx2x_release_phy_lock(bp);
  1814. bnx2x_calc_fc_adv(bp);
  1815. if (CHIP_REV_IS_SLOW(bp) && bp->link_vars.link_up) {
  1816. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  1817. bnx2x_link_report(bp);
  1818. } else
  1819. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  1820. bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
  1821. return rc;
  1822. }
  1823. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  1824. return -EINVAL;
  1825. }
  1826. void bnx2x_link_set(struct bnx2x *bp)
  1827. {
  1828. if (!BP_NOMCP(bp)) {
  1829. bnx2x_acquire_phy_lock(bp);
  1830. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  1831. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1832. bnx2x_release_phy_lock(bp);
  1833. bnx2x_calc_fc_adv(bp);
  1834. } else
  1835. BNX2X_ERR("Bootcode is missing - can not set link\n");
  1836. }
  1837. static void bnx2x__link_reset(struct bnx2x *bp)
  1838. {
  1839. if (!BP_NOMCP(bp)) {
  1840. bnx2x_acquire_phy_lock(bp);
  1841. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  1842. bnx2x_release_phy_lock(bp);
  1843. } else
  1844. BNX2X_ERR("Bootcode is missing - can not reset link\n");
  1845. }
  1846. u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
  1847. {
  1848. u8 rc = 0;
  1849. if (!BP_NOMCP(bp)) {
  1850. bnx2x_acquire_phy_lock(bp);
  1851. rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
  1852. is_serdes);
  1853. bnx2x_release_phy_lock(bp);
  1854. } else
  1855. BNX2X_ERR("Bootcode is missing - can not test link\n");
  1856. return rc;
  1857. }
  1858. /* Calculates the sum of vn_min_rates.
  1859. It's needed for further normalizing of the min_rates.
  1860. Returns:
  1861. sum of vn_min_rates.
  1862. or
  1863. 0 - if all the min_rates are 0.
  1864. In the later case fainess algorithm should be deactivated.
  1865. If not all min_rates are zero then those that are zeroes will be set to 1.
  1866. */
  1867. static void bnx2x_calc_vn_min(struct bnx2x *bp,
  1868. struct cmng_init_input *input)
  1869. {
  1870. int all_zero = 1;
  1871. int vn;
  1872. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  1873. u32 vn_cfg = bp->mf_config[vn];
  1874. u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  1875. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  1876. /* Skip hidden vns */
  1877. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  1878. vn_min_rate = 0;
  1879. /* If min rate is zero - set it to 1 */
  1880. else if (!vn_min_rate)
  1881. vn_min_rate = DEF_MIN_RATE;
  1882. else
  1883. all_zero = 0;
  1884. input->vnic_min_rate[vn] = vn_min_rate;
  1885. }
  1886. /* if ETS or all min rates are zeros - disable fairness */
  1887. if (BNX2X_IS_ETS_ENABLED(bp)) {
  1888. input->flags.cmng_enables &=
  1889. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  1890. DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
  1891. } else if (all_zero) {
  1892. input->flags.cmng_enables &=
  1893. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  1894. DP(NETIF_MSG_IFUP,
  1895. "All MIN values are zeroes fairness will be disabled\n");
  1896. } else
  1897. input->flags.cmng_enables |=
  1898. CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  1899. }
  1900. static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
  1901. struct cmng_init_input *input)
  1902. {
  1903. u16 vn_max_rate;
  1904. u32 vn_cfg = bp->mf_config[vn];
  1905. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  1906. vn_max_rate = 0;
  1907. else {
  1908. u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
  1909. if (IS_MF_SI(bp)) {
  1910. /* maxCfg in percents of linkspeed */
  1911. vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
  1912. } else /* SD modes */
  1913. /* maxCfg is absolute in 100Mb units */
  1914. vn_max_rate = maxCfg * 100;
  1915. }
  1916. DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
  1917. input->vnic_max_rate[vn] = vn_max_rate;
  1918. }
  1919. static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
  1920. {
  1921. if (CHIP_REV_IS_SLOW(bp))
  1922. return CMNG_FNS_NONE;
  1923. if (IS_MF(bp))
  1924. return CMNG_FNS_MINMAX;
  1925. return CMNG_FNS_NONE;
  1926. }
  1927. void bnx2x_read_mf_cfg(struct bnx2x *bp)
  1928. {
  1929. int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
  1930. if (BP_NOMCP(bp))
  1931. return; /* what should be the default bvalue in this case */
  1932. /* For 2 port configuration the absolute function number formula
  1933. * is:
  1934. * abs_func = 2 * vn + BP_PORT + BP_PATH
  1935. *
  1936. * and there are 4 functions per port
  1937. *
  1938. * For 4 port configuration it is
  1939. * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
  1940. *
  1941. * and there are 2 functions per port
  1942. */
  1943. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  1944. int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
  1945. if (func >= E1H_FUNC_MAX)
  1946. break;
  1947. bp->mf_config[vn] =
  1948. MF_CFG_RD(bp, func_mf_config[func].config);
  1949. }
  1950. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  1951. DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
  1952. bp->flags |= MF_FUNC_DIS;
  1953. } else {
  1954. DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
  1955. bp->flags &= ~MF_FUNC_DIS;
  1956. }
  1957. }
  1958. static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
  1959. {
  1960. struct cmng_init_input input;
  1961. memset(&input, 0, sizeof(struct cmng_init_input));
  1962. input.port_rate = bp->link_vars.line_speed;
  1963. if (cmng_type == CMNG_FNS_MINMAX) {
  1964. int vn;
  1965. /* read mf conf from shmem */
  1966. if (read_cfg)
  1967. bnx2x_read_mf_cfg(bp);
  1968. /* vn_weight_sum and enable fairness if not 0 */
  1969. bnx2x_calc_vn_min(bp, &input);
  1970. /* calculate and set min-max rate for each vn */
  1971. if (bp->port.pmf)
  1972. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
  1973. bnx2x_calc_vn_max(bp, vn, &input);
  1974. /* always enable rate shaping and fairness */
  1975. input.flags.cmng_enables |=
  1976. CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
  1977. bnx2x_init_cmng(&input, &bp->cmng);
  1978. return;
  1979. }
  1980. /* rate shaping and fairness are disabled */
  1981. DP(NETIF_MSG_IFUP,
  1982. "rate shaping and fairness are disabled\n");
  1983. }
  1984. static void storm_memset_cmng(struct bnx2x *bp,
  1985. struct cmng_init *cmng,
  1986. u8 port)
  1987. {
  1988. int vn;
  1989. size_t size = sizeof(struct cmng_struct_per_port);
  1990. u32 addr = BAR_XSTRORM_INTMEM +
  1991. XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
  1992. __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
  1993. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  1994. int func = func_by_vn(bp, vn);
  1995. addr = BAR_XSTRORM_INTMEM +
  1996. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
  1997. size = sizeof(struct rate_shaping_vars_per_vn);
  1998. __storm_memset_struct(bp, addr, size,
  1999. (u32 *)&cmng->vnic.vnic_max_rate[vn]);
  2000. addr = BAR_XSTRORM_INTMEM +
  2001. XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
  2002. size = sizeof(struct fairness_vars_per_vn);
  2003. __storm_memset_struct(bp, addr, size,
  2004. (u32 *)&cmng->vnic.vnic_min_rate[vn]);
  2005. }
  2006. }
  2007. /* This function is called upon link interrupt */
  2008. static void bnx2x_link_attn(struct bnx2x *bp)
  2009. {
  2010. /* Make sure that we are synced with the current statistics */
  2011. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2012. bnx2x_link_update(&bp->link_params, &bp->link_vars);
  2013. if (bp->link_vars.link_up) {
  2014. /* dropless flow control */
  2015. if (!CHIP_IS_E1(bp) && bp->dropless_fc) {
  2016. int port = BP_PORT(bp);
  2017. u32 pause_enabled = 0;
  2018. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  2019. pause_enabled = 1;
  2020. REG_WR(bp, BAR_USTRORM_INTMEM +
  2021. USTORM_ETH_PAUSE_ENABLED_OFFSET(port),
  2022. pause_enabled);
  2023. }
  2024. if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
  2025. struct host_port_stats *pstats;
  2026. pstats = bnx2x_sp(bp, port_stats);
  2027. /* reset old mac stats */
  2028. memset(&(pstats->mac_stx[0]), 0,
  2029. sizeof(struct mac_stx));
  2030. }
  2031. if (bp->state == BNX2X_STATE_OPEN)
  2032. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2033. }
  2034. if (bp->link_vars.link_up && bp->link_vars.line_speed) {
  2035. int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
  2036. if (cmng_fns != CMNG_FNS_NONE) {
  2037. bnx2x_cmng_fns_init(bp, false, cmng_fns);
  2038. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2039. } else
  2040. /* rate shaping and fairness are disabled */
  2041. DP(NETIF_MSG_IFUP,
  2042. "single function mode without fairness\n");
  2043. }
  2044. __bnx2x_link_report(bp);
  2045. if (IS_MF(bp))
  2046. bnx2x_link_sync_notify(bp);
  2047. }
  2048. void bnx2x__link_status_update(struct bnx2x *bp)
  2049. {
  2050. if (bp->state != BNX2X_STATE_OPEN)
  2051. return;
  2052. /* read updated dcb configuration */
  2053. bnx2x_dcbx_pmf_update(bp);
  2054. bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
  2055. if (bp->link_vars.link_up)
  2056. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2057. else
  2058. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2059. /* indicate link status */
  2060. bnx2x_link_report(bp);
  2061. }
  2062. static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
  2063. u16 vlan_val, u8 allowed_prio)
  2064. {
  2065. struct bnx2x_func_state_params func_params = {0};
  2066. struct bnx2x_func_afex_update_params *f_update_params =
  2067. &func_params.params.afex_update;
  2068. func_params.f_obj = &bp->func_obj;
  2069. func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
  2070. /* no need to wait for RAMROD completion, so don't
  2071. * set RAMROD_COMP_WAIT flag
  2072. */
  2073. f_update_params->vif_id = vifid;
  2074. f_update_params->afex_default_vlan = vlan_val;
  2075. f_update_params->allowed_priorities = allowed_prio;
  2076. /* if ramrod can not be sent, response to MCP immediately */
  2077. if (bnx2x_func_state_change(bp, &func_params) < 0)
  2078. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  2079. return 0;
  2080. }
  2081. static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
  2082. u16 vif_index, u8 func_bit_map)
  2083. {
  2084. struct bnx2x_func_state_params func_params = {0};
  2085. struct bnx2x_func_afex_viflists_params *update_params =
  2086. &func_params.params.afex_viflists;
  2087. int rc;
  2088. u32 drv_msg_code;
  2089. /* validate only LIST_SET and LIST_GET are received from switch */
  2090. if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
  2091. BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
  2092. cmd_type);
  2093. func_params.f_obj = &bp->func_obj;
  2094. func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
  2095. /* set parameters according to cmd_type */
  2096. update_params->afex_vif_list_command = cmd_type;
  2097. update_params->vif_list_index = cpu_to_le16(vif_index);
  2098. update_params->func_bit_map =
  2099. (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
  2100. update_params->func_to_clear = 0;
  2101. drv_msg_code =
  2102. (cmd_type == VIF_LIST_RULE_GET) ?
  2103. DRV_MSG_CODE_AFEX_LISTGET_ACK :
  2104. DRV_MSG_CODE_AFEX_LISTSET_ACK;
  2105. /* if ramrod can not be sent, respond to MCP immediately for
  2106. * SET and GET requests (other are not triggered from MCP)
  2107. */
  2108. rc = bnx2x_func_state_change(bp, &func_params);
  2109. if (rc < 0)
  2110. bnx2x_fw_command(bp, drv_msg_code, 0);
  2111. return 0;
  2112. }
  2113. static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
  2114. {
  2115. struct afex_stats afex_stats;
  2116. u32 func = BP_ABS_FUNC(bp);
  2117. u32 mf_config;
  2118. u16 vlan_val;
  2119. u32 vlan_prio;
  2120. u16 vif_id;
  2121. u8 allowed_prio;
  2122. u8 vlan_mode;
  2123. u32 addr_to_write, vifid, addrs, stats_type, i;
  2124. if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
  2125. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2126. DP(BNX2X_MSG_MCP,
  2127. "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
  2128. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
  2129. }
  2130. if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
  2131. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2132. addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
  2133. DP(BNX2X_MSG_MCP,
  2134. "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
  2135. vifid, addrs);
  2136. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
  2137. addrs);
  2138. }
  2139. if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
  2140. addr_to_write = SHMEM2_RD(bp,
  2141. afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
  2142. stats_type = SHMEM2_RD(bp,
  2143. afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2144. DP(BNX2X_MSG_MCP,
  2145. "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
  2146. addr_to_write);
  2147. bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
  2148. /* write response to scratchpad, for MCP */
  2149. for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
  2150. REG_WR(bp, addr_to_write + i*sizeof(u32),
  2151. *(((u32 *)(&afex_stats))+i));
  2152. /* send ack message to MCP */
  2153. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
  2154. }
  2155. if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
  2156. mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
  2157. bp->mf_config[BP_VN(bp)] = mf_config;
  2158. DP(BNX2X_MSG_MCP,
  2159. "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
  2160. mf_config);
  2161. /* if VIF_SET is "enabled" */
  2162. if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
  2163. /* set rate limit directly to internal RAM */
  2164. struct cmng_init_input cmng_input;
  2165. struct rate_shaping_vars_per_vn m_rs_vn;
  2166. size_t size = sizeof(struct rate_shaping_vars_per_vn);
  2167. u32 addr = BAR_XSTRORM_INTMEM +
  2168. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
  2169. bp->mf_config[BP_VN(bp)] = mf_config;
  2170. bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
  2171. m_rs_vn.vn_counter.rate =
  2172. cmng_input.vnic_max_rate[BP_VN(bp)];
  2173. m_rs_vn.vn_counter.quota =
  2174. (m_rs_vn.vn_counter.rate *
  2175. RS_PERIODIC_TIMEOUT_USEC) / 8;
  2176. __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
  2177. /* read relevant values from mf_cfg struct in shmem */
  2178. vif_id =
  2179. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2180. FUNC_MF_CFG_E1HOV_TAG_MASK) >>
  2181. FUNC_MF_CFG_E1HOV_TAG_SHIFT;
  2182. vlan_val =
  2183. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2184. FUNC_MF_CFG_AFEX_VLAN_MASK) >>
  2185. FUNC_MF_CFG_AFEX_VLAN_SHIFT;
  2186. vlan_prio = (mf_config &
  2187. FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
  2188. FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
  2189. vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
  2190. vlan_mode =
  2191. (MF_CFG_RD(bp,
  2192. func_mf_config[func].afex_config) &
  2193. FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
  2194. FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
  2195. allowed_prio =
  2196. (MF_CFG_RD(bp,
  2197. func_mf_config[func].afex_config) &
  2198. FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
  2199. FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
  2200. /* send ramrod to FW, return in case of failure */
  2201. if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
  2202. allowed_prio))
  2203. return;
  2204. bp->afex_def_vlan_tag = vlan_val;
  2205. bp->afex_vlan_mode = vlan_mode;
  2206. } else {
  2207. /* notify link down because BP->flags is disabled */
  2208. bnx2x_link_report(bp);
  2209. /* send INVALID VIF ramrod to FW */
  2210. bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
  2211. /* Reset the default afex VLAN */
  2212. bp->afex_def_vlan_tag = -1;
  2213. }
  2214. }
  2215. }
  2216. static void bnx2x_pmf_update(struct bnx2x *bp)
  2217. {
  2218. int port = BP_PORT(bp);
  2219. u32 val;
  2220. bp->port.pmf = 1;
  2221. DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
  2222. /*
  2223. * We need the mb() to ensure the ordering between the writing to
  2224. * bp->port.pmf here and reading it from the bnx2x_periodic_task().
  2225. */
  2226. smp_mb();
  2227. /* queue a periodic task */
  2228. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2229. bnx2x_dcbx_pmf_update(bp);
  2230. /* enable nig attention */
  2231. val = (0xff0f | (1 << (BP_VN(bp) + 4)));
  2232. if (bp->common.int_block == INT_BLOCK_HC) {
  2233. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  2234. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  2235. } else if (!CHIP_IS_E1x(bp)) {
  2236. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  2237. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  2238. }
  2239. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2240. }
  2241. /* end of Link */
  2242. /* slow path */
  2243. /*
  2244. * General service functions
  2245. */
  2246. /* send the MCP a request, block until there is a reply */
  2247. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
  2248. {
  2249. int mb_idx = BP_FW_MB_IDX(bp);
  2250. u32 seq;
  2251. u32 rc = 0;
  2252. u32 cnt = 1;
  2253. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  2254. mutex_lock(&bp->fw_mb_mutex);
  2255. seq = ++bp->fw_seq;
  2256. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
  2257. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
  2258. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
  2259. (command | seq), param);
  2260. do {
  2261. /* let the FW do it's magic ... */
  2262. msleep(delay);
  2263. rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
  2264. /* Give the FW up to 5 second (500*10ms) */
  2265. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
  2266. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  2267. cnt*delay, rc, seq);
  2268. /* is this a reply to our command? */
  2269. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
  2270. rc &= FW_MSG_CODE_MASK;
  2271. else {
  2272. /* FW BUG! */
  2273. BNX2X_ERR("FW failed to respond!\n");
  2274. bnx2x_fw_dump(bp);
  2275. rc = 0;
  2276. }
  2277. mutex_unlock(&bp->fw_mb_mutex);
  2278. return rc;
  2279. }
  2280. static void storm_memset_func_cfg(struct bnx2x *bp,
  2281. struct tstorm_eth_function_common_config *tcfg,
  2282. u16 abs_fid)
  2283. {
  2284. size_t size = sizeof(struct tstorm_eth_function_common_config);
  2285. u32 addr = BAR_TSTRORM_INTMEM +
  2286. TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
  2287. __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
  2288. }
  2289. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
  2290. {
  2291. if (CHIP_IS_E1x(bp)) {
  2292. struct tstorm_eth_function_common_config tcfg = {0};
  2293. storm_memset_func_cfg(bp, &tcfg, p->func_id);
  2294. }
  2295. /* Enable the function in the FW */
  2296. storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
  2297. storm_memset_func_en(bp, p->func_id, 1);
  2298. /* spq */
  2299. if (p->func_flgs & FUNC_FLG_SPQ) {
  2300. storm_memset_spq_addr(bp, p->spq_map, p->func_id);
  2301. REG_WR(bp, XSEM_REG_FAST_MEMORY +
  2302. XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
  2303. }
  2304. }
  2305. /**
  2306. * bnx2x_get_tx_only_flags - Return common flags
  2307. *
  2308. * @bp device handle
  2309. * @fp queue handle
  2310. * @zero_stats TRUE if statistics zeroing is needed
  2311. *
  2312. * Return the flags that are common for the Tx-only and not normal connections.
  2313. */
  2314. static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
  2315. struct bnx2x_fastpath *fp,
  2316. bool zero_stats)
  2317. {
  2318. unsigned long flags = 0;
  2319. /* PF driver will always initialize the Queue to an ACTIVE state */
  2320. __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
  2321. /* tx only connections collect statistics (on the same index as the
  2322. * parent connection). The statistics are zeroed when the parent
  2323. * connection is initialized.
  2324. */
  2325. __set_bit(BNX2X_Q_FLG_STATS, &flags);
  2326. if (zero_stats)
  2327. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
  2328. return flags;
  2329. }
  2330. static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
  2331. struct bnx2x_fastpath *fp,
  2332. bool leading)
  2333. {
  2334. unsigned long flags = 0;
  2335. /* calculate other queue flags */
  2336. if (IS_MF_SD(bp))
  2337. __set_bit(BNX2X_Q_FLG_OV, &flags);
  2338. if (IS_FCOE_FP(fp)) {
  2339. __set_bit(BNX2X_Q_FLG_FCOE, &flags);
  2340. /* For FCoE - force usage of default priority (for afex) */
  2341. __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
  2342. }
  2343. if (!fp->disable_tpa) {
  2344. __set_bit(BNX2X_Q_FLG_TPA, &flags);
  2345. __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
  2346. if (fp->mode == TPA_MODE_GRO)
  2347. __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
  2348. }
  2349. if (leading) {
  2350. __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
  2351. __set_bit(BNX2X_Q_FLG_MCAST, &flags);
  2352. }
  2353. /* Always set HW VLAN stripping */
  2354. __set_bit(BNX2X_Q_FLG_VLAN, &flags);
  2355. /* configure silent vlan removal */
  2356. if (IS_MF_AFEX(bp))
  2357. __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
  2358. return flags | bnx2x_get_common_flags(bp, fp, true);
  2359. }
  2360. static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
  2361. struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
  2362. u8 cos)
  2363. {
  2364. gen_init->stat_id = bnx2x_stats_id(fp);
  2365. gen_init->spcl_id = fp->cl_id;
  2366. /* Always use mini-jumbo MTU for FCoE L2 ring */
  2367. if (IS_FCOE_FP(fp))
  2368. gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
  2369. else
  2370. gen_init->mtu = bp->dev->mtu;
  2371. gen_init->cos = cos;
  2372. }
  2373. static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
  2374. struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
  2375. struct bnx2x_rxq_setup_params *rxq_init)
  2376. {
  2377. u8 max_sge = 0;
  2378. u16 sge_sz = 0;
  2379. u16 tpa_agg_size = 0;
  2380. if (!fp->disable_tpa) {
  2381. pause->sge_th_lo = SGE_TH_LO(bp);
  2382. pause->sge_th_hi = SGE_TH_HI(bp);
  2383. /* validate SGE ring has enough to cross high threshold */
  2384. WARN_ON(bp->dropless_fc &&
  2385. pause->sge_th_hi + FW_PREFETCH_CNT >
  2386. MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
  2387. tpa_agg_size = min_t(u32,
  2388. (min_t(u32, 8, MAX_SKB_FRAGS) *
  2389. SGE_PAGE_SIZE * PAGES_PER_SGE), 0xffff);
  2390. max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
  2391. SGE_PAGE_SHIFT;
  2392. max_sge = ((max_sge + PAGES_PER_SGE - 1) &
  2393. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  2394. sge_sz = (u16)min_t(u32, SGE_PAGE_SIZE * PAGES_PER_SGE,
  2395. 0xffff);
  2396. }
  2397. /* pause - not for e1 */
  2398. if (!CHIP_IS_E1(bp)) {
  2399. pause->bd_th_lo = BD_TH_LO(bp);
  2400. pause->bd_th_hi = BD_TH_HI(bp);
  2401. pause->rcq_th_lo = RCQ_TH_LO(bp);
  2402. pause->rcq_th_hi = RCQ_TH_HI(bp);
  2403. /*
  2404. * validate that rings have enough entries to cross
  2405. * high thresholds
  2406. */
  2407. WARN_ON(bp->dropless_fc &&
  2408. pause->bd_th_hi + FW_PREFETCH_CNT >
  2409. bp->rx_ring_size);
  2410. WARN_ON(bp->dropless_fc &&
  2411. pause->rcq_th_hi + FW_PREFETCH_CNT >
  2412. NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
  2413. pause->pri_map = 1;
  2414. }
  2415. /* rxq setup */
  2416. rxq_init->dscr_map = fp->rx_desc_mapping;
  2417. rxq_init->sge_map = fp->rx_sge_mapping;
  2418. rxq_init->rcq_map = fp->rx_comp_mapping;
  2419. rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  2420. /* This should be a maximum number of data bytes that may be
  2421. * placed on the BD (not including paddings).
  2422. */
  2423. rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
  2424. BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
  2425. rxq_init->cl_qzone_id = fp->cl_qzone_id;
  2426. rxq_init->tpa_agg_sz = tpa_agg_size;
  2427. rxq_init->sge_buf_sz = sge_sz;
  2428. rxq_init->max_sges_pkt = max_sge;
  2429. rxq_init->rss_engine_id = BP_FUNC(bp);
  2430. rxq_init->mcast_engine_id = BP_FUNC(bp);
  2431. /* Maximum number or simultaneous TPA aggregation for this Queue.
  2432. *
  2433. * For PF Clients it should be the maximum avaliable number.
  2434. * VF driver(s) may want to define it to a smaller value.
  2435. */
  2436. rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
  2437. rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  2438. rxq_init->fw_sb_id = fp->fw_sb_id;
  2439. if (IS_FCOE_FP(fp))
  2440. rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
  2441. else
  2442. rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  2443. /* configure silent vlan removal
  2444. * if multi function mode is afex, then mask default vlan
  2445. */
  2446. if (IS_MF_AFEX(bp)) {
  2447. rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
  2448. rxq_init->silent_removal_mask = VLAN_VID_MASK;
  2449. }
  2450. }
  2451. static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
  2452. struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
  2453. u8 cos)
  2454. {
  2455. txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
  2456. txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
  2457. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
  2458. txq_init->fw_sb_id = fp->fw_sb_id;
  2459. /*
  2460. * set the tss leading client id for TX classfication ==
  2461. * leading RSS client id
  2462. */
  2463. txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
  2464. if (IS_FCOE_FP(fp)) {
  2465. txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
  2466. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
  2467. }
  2468. }
  2469. static void bnx2x_pf_init(struct bnx2x *bp)
  2470. {
  2471. struct bnx2x_func_init_params func_init = {0};
  2472. struct event_ring_data eq_data = { {0} };
  2473. u16 flags;
  2474. if (!CHIP_IS_E1x(bp)) {
  2475. /* reset IGU PF statistics: MSIX + ATTN */
  2476. /* PF */
  2477. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2478. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2479. (CHIP_MODE_IS_4_PORT(bp) ?
  2480. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2481. /* ATTN */
  2482. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2483. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2484. BNX2X_IGU_STAS_MSG_PF_CNT*4 +
  2485. (CHIP_MODE_IS_4_PORT(bp) ?
  2486. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2487. }
  2488. /* function setup flags */
  2489. flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
  2490. /* This flag is relevant for E1x only.
  2491. * E2 doesn't have a TPA configuration in a function level.
  2492. */
  2493. flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
  2494. func_init.func_flgs = flags;
  2495. func_init.pf_id = BP_FUNC(bp);
  2496. func_init.func_id = BP_FUNC(bp);
  2497. func_init.spq_map = bp->spq_mapping;
  2498. func_init.spq_prod = bp->spq_prod_idx;
  2499. bnx2x_func_init(bp, &func_init);
  2500. memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
  2501. /*
  2502. * Congestion management values depend on the link rate
  2503. * There is no active link so initial link rate is set to 10 Gbps.
  2504. * When the link comes up The congestion management values are
  2505. * re-calculated according to the actual link rate.
  2506. */
  2507. bp->link_vars.line_speed = SPEED_10000;
  2508. bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
  2509. /* Only the PMF sets the HW */
  2510. if (bp->port.pmf)
  2511. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2512. /* init Event Queue */
  2513. eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
  2514. eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
  2515. eq_data.producer = bp->eq_prod;
  2516. eq_data.index_id = HC_SP_INDEX_EQ_CONS;
  2517. eq_data.sb_id = DEF_SB_ID;
  2518. storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
  2519. }
  2520. static void bnx2x_e1h_disable(struct bnx2x *bp)
  2521. {
  2522. int port = BP_PORT(bp);
  2523. bnx2x_tx_disable(bp);
  2524. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  2525. }
  2526. static void bnx2x_e1h_enable(struct bnx2x *bp)
  2527. {
  2528. int port = BP_PORT(bp);
  2529. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  2530. /* Tx queue should be only reenabled */
  2531. netif_tx_wake_all_queues(bp->dev);
  2532. /*
  2533. * Should not call netif_carrier_on since it will be called if the link
  2534. * is up when checking for link state
  2535. */
  2536. }
  2537. #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
  2538. static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
  2539. {
  2540. struct eth_stats_info *ether_stat =
  2541. &bp->slowpath->drv_info_to_mcp.ether_stat;
  2542. /* leave last char as NULL */
  2543. memcpy(ether_stat->version, DRV_MODULE_VERSION,
  2544. ETH_STAT_INFO_VERSION_LEN - 1);
  2545. bp->sp_objs[0].mac_obj.get_n_elements(bp, &bp->sp_objs[0].mac_obj,
  2546. DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
  2547. ether_stat->mac_local);
  2548. ether_stat->mtu_size = bp->dev->mtu;
  2549. if (bp->dev->features & NETIF_F_RXCSUM)
  2550. ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
  2551. if (bp->dev->features & NETIF_F_TSO)
  2552. ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
  2553. ether_stat->feature_flags |= bp->common.boot_mode;
  2554. ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
  2555. ether_stat->txq_size = bp->tx_ring_size;
  2556. ether_stat->rxq_size = bp->rx_ring_size;
  2557. }
  2558. static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
  2559. {
  2560. #ifdef BCM_CNIC
  2561. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2562. struct fcoe_stats_info *fcoe_stat =
  2563. &bp->slowpath->drv_info_to_mcp.fcoe_stat;
  2564. memcpy(fcoe_stat->mac_local + MAC_LEADING_ZERO_CNT,
  2565. bp->fip_mac, ETH_ALEN);
  2566. fcoe_stat->qos_priority =
  2567. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
  2568. /* insert FCoE stats from ramrod response */
  2569. if (!NO_FCOE(bp)) {
  2570. struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
  2571. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2572. tstorm_queue_statistics;
  2573. struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
  2574. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2575. xstorm_queue_statistics;
  2576. struct fcoe_statistics_params *fw_fcoe_stat =
  2577. &bp->fw_stats_data->fcoe;
  2578. ADD_64(fcoe_stat->rx_bytes_hi, 0, fcoe_stat->rx_bytes_lo,
  2579. fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
  2580. ADD_64(fcoe_stat->rx_bytes_hi,
  2581. fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
  2582. fcoe_stat->rx_bytes_lo,
  2583. fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
  2584. ADD_64(fcoe_stat->rx_bytes_hi,
  2585. fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
  2586. fcoe_stat->rx_bytes_lo,
  2587. fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
  2588. ADD_64(fcoe_stat->rx_bytes_hi,
  2589. fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
  2590. fcoe_stat->rx_bytes_lo,
  2591. fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
  2592. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2593. fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
  2594. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2595. fcoe_q_tstorm_stats->rcv_ucast_pkts);
  2596. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2597. fcoe_q_tstorm_stats->rcv_bcast_pkts);
  2598. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2599. fcoe_q_tstorm_stats->rcv_mcast_pkts);
  2600. ADD_64(fcoe_stat->tx_bytes_hi, 0, fcoe_stat->tx_bytes_lo,
  2601. fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
  2602. ADD_64(fcoe_stat->tx_bytes_hi,
  2603. fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
  2604. fcoe_stat->tx_bytes_lo,
  2605. fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
  2606. ADD_64(fcoe_stat->tx_bytes_hi,
  2607. fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
  2608. fcoe_stat->tx_bytes_lo,
  2609. fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
  2610. ADD_64(fcoe_stat->tx_bytes_hi,
  2611. fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
  2612. fcoe_stat->tx_bytes_lo,
  2613. fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
  2614. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2615. fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
  2616. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2617. fcoe_q_xstorm_stats->ucast_pkts_sent);
  2618. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2619. fcoe_q_xstorm_stats->bcast_pkts_sent);
  2620. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2621. fcoe_q_xstorm_stats->mcast_pkts_sent);
  2622. }
  2623. /* ask L5 driver to add data to the struct */
  2624. bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
  2625. #endif
  2626. }
  2627. static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
  2628. {
  2629. #ifdef BCM_CNIC
  2630. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2631. struct iscsi_stats_info *iscsi_stat =
  2632. &bp->slowpath->drv_info_to_mcp.iscsi_stat;
  2633. memcpy(iscsi_stat->mac_local + MAC_LEADING_ZERO_CNT,
  2634. bp->cnic_eth_dev.iscsi_mac, ETH_ALEN);
  2635. iscsi_stat->qos_priority =
  2636. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
  2637. /* ask L5 driver to add data to the struct */
  2638. bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
  2639. #endif
  2640. }
  2641. /* called due to MCP event (on pmf):
  2642. * reread new bandwidth configuration
  2643. * configure FW
  2644. * notify others function about the change
  2645. */
  2646. static void bnx2x_config_mf_bw(struct bnx2x *bp)
  2647. {
  2648. if (bp->link_vars.link_up) {
  2649. bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
  2650. bnx2x_link_sync_notify(bp);
  2651. }
  2652. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2653. }
  2654. static void bnx2x_set_mf_bw(struct bnx2x *bp)
  2655. {
  2656. bnx2x_config_mf_bw(bp);
  2657. bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
  2658. }
  2659. static void bnx2x_handle_eee_event(struct bnx2x *bp)
  2660. {
  2661. DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
  2662. bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
  2663. }
  2664. static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
  2665. {
  2666. enum drv_info_opcode op_code;
  2667. u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
  2668. /* if drv_info version supported by MFW doesn't match - send NACK */
  2669. if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
  2670. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2671. return;
  2672. }
  2673. op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
  2674. DRV_INFO_CONTROL_OP_CODE_SHIFT;
  2675. memset(&bp->slowpath->drv_info_to_mcp, 0,
  2676. sizeof(union drv_info_to_mcp));
  2677. switch (op_code) {
  2678. case ETH_STATS_OPCODE:
  2679. bnx2x_drv_info_ether_stat(bp);
  2680. break;
  2681. case FCOE_STATS_OPCODE:
  2682. bnx2x_drv_info_fcoe_stat(bp);
  2683. break;
  2684. case ISCSI_STATS_OPCODE:
  2685. bnx2x_drv_info_iscsi_stat(bp);
  2686. break;
  2687. default:
  2688. /* if op code isn't supported - send NACK */
  2689. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2690. return;
  2691. }
  2692. /* if we got drv_info attn from MFW then these fields are defined in
  2693. * shmem2 for sure
  2694. */
  2695. SHMEM2_WR(bp, drv_info_host_addr_lo,
  2696. U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2697. SHMEM2_WR(bp, drv_info_host_addr_hi,
  2698. U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2699. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
  2700. }
  2701. static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
  2702. {
  2703. DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
  2704. if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
  2705. /*
  2706. * This is the only place besides the function initialization
  2707. * where the bp->flags can change so it is done without any
  2708. * locks
  2709. */
  2710. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2711. DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
  2712. bp->flags |= MF_FUNC_DIS;
  2713. bnx2x_e1h_disable(bp);
  2714. } else {
  2715. DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
  2716. bp->flags &= ~MF_FUNC_DIS;
  2717. bnx2x_e1h_enable(bp);
  2718. }
  2719. dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
  2720. }
  2721. if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
  2722. bnx2x_config_mf_bw(bp);
  2723. dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
  2724. }
  2725. /* Report results to MCP */
  2726. if (dcc_event)
  2727. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
  2728. else
  2729. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
  2730. }
  2731. /* must be called under the spq lock */
  2732. static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
  2733. {
  2734. struct eth_spe *next_spe = bp->spq_prod_bd;
  2735. if (bp->spq_prod_bd == bp->spq_last_bd) {
  2736. bp->spq_prod_bd = bp->spq;
  2737. bp->spq_prod_idx = 0;
  2738. DP(BNX2X_MSG_SP, "end of spq\n");
  2739. } else {
  2740. bp->spq_prod_bd++;
  2741. bp->spq_prod_idx++;
  2742. }
  2743. return next_spe;
  2744. }
  2745. /* must be called under the spq lock */
  2746. static void bnx2x_sp_prod_update(struct bnx2x *bp)
  2747. {
  2748. int func = BP_FUNC(bp);
  2749. /*
  2750. * Make sure that BD data is updated before writing the producer:
  2751. * BD data is written to the memory, the producer is read from the
  2752. * memory, thus we need a full memory barrier to ensure the ordering.
  2753. */
  2754. mb();
  2755. REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
  2756. bp->spq_prod_idx);
  2757. mmiowb();
  2758. }
  2759. /**
  2760. * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
  2761. *
  2762. * @cmd: command to check
  2763. * @cmd_type: command type
  2764. */
  2765. static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
  2766. {
  2767. if ((cmd_type == NONE_CONNECTION_TYPE) ||
  2768. (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
  2769. (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
  2770. (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
  2771. (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
  2772. (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
  2773. (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
  2774. return true;
  2775. else
  2776. return false;
  2777. }
  2778. /**
  2779. * bnx2x_sp_post - place a single command on an SP ring
  2780. *
  2781. * @bp: driver handle
  2782. * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
  2783. * @cid: SW CID the command is related to
  2784. * @data_hi: command private data address (high 32 bits)
  2785. * @data_lo: command private data address (low 32 bits)
  2786. * @cmd_type: command type (e.g. NONE, ETH)
  2787. *
  2788. * SP data is handled as if it's always an address pair, thus data fields are
  2789. * not swapped to little endian in upper functions. Instead this function swaps
  2790. * data as if it's two u32 fields.
  2791. */
  2792. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  2793. u32 data_hi, u32 data_lo, int cmd_type)
  2794. {
  2795. struct eth_spe *spe;
  2796. u16 type;
  2797. bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
  2798. #ifdef BNX2X_STOP_ON_ERROR
  2799. if (unlikely(bp->panic)) {
  2800. BNX2X_ERR("Can't post SP when there is panic\n");
  2801. return -EIO;
  2802. }
  2803. #endif
  2804. spin_lock_bh(&bp->spq_lock);
  2805. if (common) {
  2806. if (!atomic_read(&bp->eq_spq_left)) {
  2807. BNX2X_ERR("BUG! EQ ring full!\n");
  2808. spin_unlock_bh(&bp->spq_lock);
  2809. bnx2x_panic();
  2810. return -EBUSY;
  2811. }
  2812. } else if (!atomic_read(&bp->cq_spq_left)) {
  2813. BNX2X_ERR("BUG! SPQ ring full!\n");
  2814. spin_unlock_bh(&bp->spq_lock);
  2815. bnx2x_panic();
  2816. return -EBUSY;
  2817. }
  2818. spe = bnx2x_sp_get_next(bp);
  2819. /* CID needs port number to be encoded int it */
  2820. spe->hdr.conn_and_cmd_data =
  2821. cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
  2822. HW_CID(bp, cid));
  2823. type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
  2824. type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
  2825. SPE_HDR_FUNCTION_ID);
  2826. spe->hdr.type = cpu_to_le16(type);
  2827. spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
  2828. spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
  2829. /*
  2830. * It's ok if the actual decrement is issued towards the memory
  2831. * somewhere between the spin_lock and spin_unlock. Thus no
  2832. * more explict memory barrier is needed.
  2833. */
  2834. if (common)
  2835. atomic_dec(&bp->eq_spq_left);
  2836. else
  2837. atomic_dec(&bp->cq_spq_left);
  2838. DP(BNX2X_MSG_SP,
  2839. "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
  2840. bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
  2841. (u32)(U64_LO(bp->spq_mapping) +
  2842. (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
  2843. HW_CID(bp, cid), data_hi, data_lo, type,
  2844. atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
  2845. bnx2x_sp_prod_update(bp);
  2846. spin_unlock_bh(&bp->spq_lock);
  2847. return 0;
  2848. }
  2849. /* acquire split MCP access lock register */
  2850. static int bnx2x_acquire_alr(struct bnx2x *bp)
  2851. {
  2852. u32 j, val;
  2853. int rc = 0;
  2854. might_sleep();
  2855. for (j = 0; j < 1000; j++) {
  2856. val = (1UL << 31);
  2857. REG_WR(bp, GRCBASE_MCP + 0x9c, val);
  2858. val = REG_RD(bp, GRCBASE_MCP + 0x9c);
  2859. if (val & (1L << 31))
  2860. break;
  2861. msleep(5);
  2862. }
  2863. if (!(val & (1L << 31))) {
  2864. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  2865. rc = -EBUSY;
  2866. }
  2867. return rc;
  2868. }
  2869. /* release split MCP access lock register */
  2870. static void bnx2x_release_alr(struct bnx2x *bp)
  2871. {
  2872. REG_WR(bp, GRCBASE_MCP + 0x9c, 0);
  2873. }
  2874. #define BNX2X_DEF_SB_ATT_IDX 0x0001
  2875. #define BNX2X_DEF_SB_IDX 0x0002
  2876. static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  2877. {
  2878. struct host_sp_status_block *def_sb = bp->def_status_blk;
  2879. u16 rc = 0;
  2880. barrier(); /* status block is written to by the chip */
  2881. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  2882. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  2883. rc |= BNX2X_DEF_SB_ATT_IDX;
  2884. }
  2885. if (bp->def_idx != def_sb->sp_sb.running_index) {
  2886. bp->def_idx = def_sb->sp_sb.running_index;
  2887. rc |= BNX2X_DEF_SB_IDX;
  2888. }
  2889. /* Do not reorder: indecies reading should complete before handling */
  2890. barrier();
  2891. return rc;
  2892. }
  2893. /*
  2894. * slow path service functions
  2895. */
  2896. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  2897. {
  2898. int port = BP_PORT(bp);
  2899. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  2900. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  2901. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  2902. NIG_REG_MASK_INTERRUPT_PORT0;
  2903. u32 aeu_mask;
  2904. u32 nig_mask = 0;
  2905. u32 reg_addr;
  2906. if (bp->attn_state & asserted)
  2907. BNX2X_ERR("IGU ERROR\n");
  2908. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  2909. aeu_mask = REG_RD(bp, aeu_addr);
  2910. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  2911. aeu_mask, asserted);
  2912. aeu_mask &= ~(asserted & 0x3ff);
  2913. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  2914. REG_WR(bp, aeu_addr, aeu_mask);
  2915. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  2916. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  2917. bp->attn_state |= asserted;
  2918. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  2919. if (asserted & ATTN_HARD_WIRED_MASK) {
  2920. if (asserted & ATTN_NIG_FOR_FUNC) {
  2921. bnx2x_acquire_phy_lock(bp);
  2922. /* save nig interrupt mask */
  2923. nig_mask = REG_RD(bp, nig_int_mask_addr);
  2924. /* If nig_mask is not set, no need to call the update
  2925. * function.
  2926. */
  2927. if (nig_mask) {
  2928. REG_WR(bp, nig_int_mask_addr, 0);
  2929. bnx2x_link_attn(bp);
  2930. }
  2931. /* handle unicore attn? */
  2932. }
  2933. if (asserted & ATTN_SW_TIMER_4_FUNC)
  2934. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  2935. if (asserted & GPIO_2_FUNC)
  2936. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  2937. if (asserted & GPIO_3_FUNC)
  2938. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  2939. if (asserted & GPIO_4_FUNC)
  2940. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  2941. if (port == 0) {
  2942. if (asserted & ATTN_GENERAL_ATTN_1) {
  2943. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  2944. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  2945. }
  2946. if (asserted & ATTN_GENERAL_ATTN_2) {
  2947. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  2948. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  2949. }
  2950. if (asserted & ATTN_GENERAL_ATTN_3) {
  2951. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  2952. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  2953. }
  2954. } else {
  2955. if (asserted & ATTN_GENERAL_ATTN_4) {
  2956. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  2957. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  2958. }
  2959. if (asserted & ATTN_GENERAL_ATTN_5) {
  2960. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  2961. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  2962. }
  2963. if (asserted & ATTN_GENERAL_ATTN_6) {
  2964. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  2965. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  2966. }
  2967. }
  2968. } /* if hardwired */
  2969. if (bp->common.int_block == INT_BLOCK_HC)
  2970. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  2971. COMMAND_REG_ATTN_BITS_SET);
  2972. else
  2973. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
  2974. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
  2975. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  2976. REG_WR(bp, reg_addr, asserted);
  2977. /* now set back the mask */
  2978. if (asserted & ATTN_NIG_FOR_FUNC) {
  2979. REG_WR(bp, nig_int_mask_addr, nig_mask);
  2980. bnx2x_release_phy_lock(bp);
  2981. }
  2982. }
  2983. static void bnx2x_fan_failure(struct bnx2x *bp)
  2984. {
  2985. int port = BP_PORT(bp);
  2986. u32 ext_phy_config;
  2987. /* mark the failure */
  2988. ext_phy_config =
  2989. SHMEM_RD(bp,
  2990. dev_info.port_hw_config[port].external_phy_config);
  2991. ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  2992. ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  2993. SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
  2994. ext_phy_config);
  2995. /* log the failure */
  2996. netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
  2997. "Please contact OEM Support for assistance\n");
  2998. /*
  2999. * Scheudle device reset (unload)
  3000. * This is due to some boards consuming sufficient power when driver is
  3001. * up to overheat if fan fails.
  3002. */
  3003. smp_mb__before_clear_bit();
  3004. set_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state);
  3005. smp_mb__after_clear_bit();
  3006. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3007. }
  3008. static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  3009. {
  3010. int port = BP_PORT(bp);
  3011. int reg_offset;
  3012. u32 val;
  3013. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  3014. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  3015. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  3016. val = REG_RD(bp, reg_offset);
  3017. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  3018. REG_WR(bp, reg_offset, val);
  3019. BNX2X_ERR("SPIO5 hw attention\n");
  3020. /* Fan failure attention */
  3021. bnx2x_hw_reset_phy(&bp->link_params);
  3022. bnx2x_fan_failure(bp);
  3023. }
  3024. if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
  3025. bnx2x_acquire_phy_lock(bp);
  3026. bnx2x_handle_module_detect_int(&bp->link_params);
  3027. bnx2x_release_phy_lock(bp);
  3028. }
  3029. if (attn & HW_INTERRUT_ASSERT_SET_0) {
  3030. val = REG_RD(bp, reg_offset);
  3031. val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
  3032. REG_WR(bp, reg_offset, val);
  3033. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  3034. (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
  3035. bnx2x_panic();
  3036. }
  3037. }
  3038. static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  3039. {
  3040. u32 val;
  3041. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  3042. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  3043. BNX2X_ERR("DB hw attention 0x%x\n", val);
  3044. /* DORQ discard attention */
  3045. if (val & 0x2)
  3046. BNX2X_ERR("FATAL error from DORQ\n");
  3047. }
  3048. if (attn & HW_INTERRUT_ASSERT_SET_1) {
  3049. int port = BP_PORT(bp);
  3050. int reg_offset;
  3051. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  3052. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  3053. val = REG_RD(bp, reg_offset);
  3054. val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
  3055. REG_WR(bp, reg_offset, val);
  3056. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  3057. (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
  3058. bnx2x_panic();
  3059. }
  3060. }
  3061. static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  3062. {
  3063. u32 val;
  3064. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  3065. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  3066. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  3067. /* CFC error attention */
  3068. if (val & 0x2)
  3069. BNX2X_ERR("FATAL error from CFC\n");
  3070. }
  3071. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  3072. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  3073. BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
  3074. /* RQ_USDMDP_FIFO_OVERFLOW */
  3075. if (val & 0x18000)
  3076. BNX2X_ERR("FATAL error from PXP\n");
  3077. if (!CHIP_IS_E1x(bp)) {
  3078. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
  3079. BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
  3080. }
  3081. }
  3082. if (attn & HW_INTERRUT_ASSERT_SET_2) {
  3083. int port = BP_PORT(bp);
  3084. int reg_offset;
  3085. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  3086. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  3087. val = REG_RD(bp, reg_offset);
  3088. val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
  3089. REG_WR(bp, reg_offset, val);
  3090. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  3091. (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
  3092. bnx2x_panic();
  3093. }
  3094. }
  3095. static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  3096. {
  3097. u32 val;
  3098. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  3099. if (attn & BNX2X_PMF_LINK_ASSERT) {
  3100. int func = BP_FUNC(bp);
  3101. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  3102. bnx2x_read_mf_cfg(bp);
  3103. bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
  3104. func_mf_config[BP_ABS_FUNC(bp)].config);
  3105. val = SHMEM_RD(bp,
  3106. func_mb[BP_FW_MB_IDX(bp)].drv_status);
  3107. if (val & DRV_STATUS_DCC_EVENT_MASK)
  3108. bnx2x_dcc_event(bp,
  3109. (val & DRV_STATUS_DCC_EVENT_MASK));
  3110. if (val & DRV_STATUS_SET_MF_BW)
  3111. bnx2x_set_mf_bw(bp);
  3112. if (val & DRV_STATUS_DRV_INFO_REQ)
  3113. bnx2x_handle_drv_info_req(bp);
  3114. if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
  3115. bnx2x_pmf_update(bp);
  3116. if (bp->port.pmf &&
  3117. (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
  3118. bp->dcbx_enabled > 0)
  3119. /* start dcbx state machine */
  3120. bnx2x_dcbx_set_params(bp,
  3121. BNX2X_DCBX_STATE_NEG_RECEIVED);
  3122. if (val & DRV_STATUS_AFEX_EVENT_MASK)
  3123. bnx2x_handle_afex_cmd(bp,
  3124. val & DRV_STATUS_AFEX_EVENT_MASK);
  3125. if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
  3126. bnx2x_handle_eee_event(bp);
  3127. if (bp->link_vars.periodic_flags &
  3128. PERIODIC_FLAGS_LINK_EVENT) {
  3129. /* sync with link */
  3130. bnx2x_acquire_phy_lock(bp);
  3131. bp->link_vars.periodic_flags &=
  3132. ~PERIODIC_FLAGS_LINK_EVENT;
  3133. bnx2x_release_phy_lock(bp);
  3134. if (IS_MF(bp))
  3135. bnx2x_link_sync_notify(bp);
  3136. bnx2x_link_report(bp);
  3137. }
  3138. /* Always call it here: bnx2x_link_report() will
  3139. * prevent the link indication duplication.
  3140. */
  3141. bnx2x__link_status_update(bp);
  3142. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  3143. BNX2X_ERR("MC assert!\n");
  3144. bnx2x_mc_assert(bp);
  3145. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  3146. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  3147. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  3148. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  3149. bnx2x_panic();
  3150. } else if (attn & BNX2X_MCP_ASSERT) {
  3151. BNX2X_ERR("MCP assert!\n");
  3152. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  3153. bnx2x_fw_dump(bp);
  3154. } else
  3155. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  3156. }
  3157. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  3158. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  3159. if (attn & BNX2X_GRC_TIMEOUT) {
  3160. val = CHIP_IS_E1(bp) ? 0 :
  3161. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
  3162. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  3163. }
  3164. if (attn & BNX2X_GRC_RSV) {
  3165. val = CHIP_IS_E1(bp) ? 0 :
  3166. REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
  3167. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  3168. }
  3169. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  3170. }
  3171. }
  3172. /*
  3173. * Bits map:
  3174. * 0-7 - Engine0 load counter.
  3175. * 8-15 - Engine1 load counter.
  3176. * 16 - Engine0 RESET_IN_PROGRESS bit.
  3177. * 17 - Engine1 RESET_IN_PROGRESS bit.
  3178. * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
  3179. * on the engine
  3180. * 19 - Engine1 ONE_IS_LOADED.
  3181. * 20 - Chip reset flow bit. When set none-leader must wait for both engines
  3182. * leader to complete (check for both RESET_IN_PROGRESS bits and not for
  3183. * just the one belonging to its engine).
  3184. *
  3185. */
  3186. #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
  3187. #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
  3188. #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
  3189. #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
  3190. #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
  3191. #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
  3192. #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
  3193. #define BNX2X_GLOBAL_RESET_BIT 0x00040000
  3194. /*
  3195. * Set the GLOBAL_RESET bit.
  3196. *
  3197. * Should be run under rtnl lock
  3198. */
  3199. void bnx2x_set_reset_global(struct bnx2x *bp)
  3200. {
  3201. u32 val;
  3202. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3203. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3204. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
  3205. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3206. }
  3207. /*
  3208. * Clear the GLOBAL_RESET bit.
  3209. *
  3210. * Should be run under rtnl lock
  3211. */
  3212. static void bnx2x_clear_reset_global(struct bnx2x *bp)
  3213. {
  3214. u32 val;
  3215. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3216. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3217. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
  3218. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3219. }
  3220. /*
  3221. * Checks the GLOBAL_RESET bit.
  3222. *
  3223. * should be run under rtnl lock
  3224. */
  3225. static bool bnx2x_reset_is_global(struct bnx2x *bp)
  3226. {
  3227. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3228. DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
  3229. return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
  3230. }
  3231. /*
  3232. * Clear RESET_IN_PROGRESS bit for the current engine.
  3233. *
  3234. * Should be run under rtnl lock
  3235. */
  3236. static void bnx2x_set_reset_done(struct bnx2x *bp)
  3237. {
  3238. u32 val;
  3239. u32 bit = BP_PATH(bp) ?
  3240. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3241. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3242. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3243. /* Clear the bit */
  3244. val &= ~bit;
  3245. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3246. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3247. }
  3248. /*
  3249. * Set RESET_IN_PROGRESS for the current engine.
  3250. *
  3251. * should be run under rtnl lock
  3252. */
  3253. void bnx2x_set_reset_in_progress(struct bnx2x *bp)
  3254. {
  3255. u32 val;
  3256. u32 bit = BP_PATH(bp) ?
  3257. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3258. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3259. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3260. /* Set the bit */
  3261. val |= bit;
  3262. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3263. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3264. }
  3265. /*
  3266. * Checks the RESET_IN_PROGRESS bit for the given engine.
  3267. * should be run under rtnl lock
  3268. */
  3269. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
  3270. {
  3271. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3272. u32 bit = engine ?
  3273. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3274. /* return false if bit is set */
  3275. return (val & bit) ? false : true;
  3276. }
  3277. /*
  3278. * set pf load for the current pf.
  3279. *
  3280. * should be run under rtnl lock
  3281. */
  3282. void bnx2x_set_pf_load(struct bnx2x *bp)
  3283. {
  3284. u32 val1, val;
  3285. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3286. BNX2X_PATH0_LOAD_CNT_MASK;
  3287. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3288. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3289. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3290. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3291. DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
  3292. /* get the current counter value */
  3293. val1 = (val & mask) >> shift;
  3294. /* set bit of that PF */
  3295. val1 |= (1 << bp->pf_num);
  3296. /* clear the old value */
  3297. val &= ~mask;
  3298. /* set the new one */
  3299. val |= ((val1 << shift) & mask);
  3300. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3301. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3302. }
  3303. /**
  3304. * bnx2x_clear_pf_load - clear pf load mark
  3305. *
  3306. * @bp: driver handle
  3307. *
  3308. * Should be run under rtnl lock.
  3309. * Decrements the load counter for the current engine. Returns
  3310. * whether other functions are still loaded
  3311. */
  3312. bool bnx2x_clear_pf_load(struct bnx2x *bp)
  3313. {
  3314. u32 val1, val;
  3315. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3316. BNX2X_PATH0_LOAD_CNT_MASK;
  3317. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3318. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3319. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3320. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3321. DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
  3322. /* get the current counter value */
  3323. val1 = (val & mask) >> shift;
  3324. /* clear bit of that PF */
  3325. val1 &= ~(1 << bp->pf_num);
  3326. /* clear the old value */
  3327. val &= ~mask;
  3328. /* set the new one */
  3329. val |= ((val1 << shift) & mask);
  3330. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3331. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3332. return val1 != 0;
  3333. }
  3334. /*
  3335. * Read the load status for the current engine.
  3336. *
  3337. * should be run under rtnl lock
  3338. */
  3339. static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
  3340. {
  3341. u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
  3342. BNX2X_PATH0_LOAD_CNT_MASK);
  3343. u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3344. BNX2X_PATH0_LOAD_CNT_SHIFT);
  3345. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3346. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
  3347. val = (val & mask) >> shift;
  3348. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
  3349. engine, val);
  3350. return val != 0;
  3351. }
  3352. static void _print_next_block(int idx, const char *blk)
  3353. {
  3354. pr_cont("%s%s", idx ? ", " : "", blk);
  3355. }
  3356. static int bnx2x_check_blocks_with_parity0(u32 sig, int par_num,
  3357. bool print)
  3358. {
  3359. int i = 0;
  3360. u32 cur_bit = 0;
  3361. for (i = 0; sig; i++) {
  3362. cur_bit = ((u32)0x1 << i);
  3363. if (sig & cur_bit) {
  3364. switch (cur_bit) {
  3365. case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
  3366. if (print)
  3367. _print_next_block(par_num++, "BRB");
  3368. break;
  3369. case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
  3370. if (print)
  3371. _print_next_block(par_num++, "PARSER");
  3372. break;
  3373. case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
  3374. if (print)
  3375. _print_next_block(par_num++, "TSDM");
  3376. break;
  3377. case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
  3378. if (print)
  3379. _print_next_block(par_num++,
  3380. "SEARCHER");
  3381. break;
  3382. case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
  3383. if (print)
  3384. _print_next_block(par_num++, "TCM");
  3385. break;
  3386. case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
  3387. if (print)
  3388. _print_next_block(par_num++, "TSEMI");
  3389. break;
  3390. case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
  3391. if (print)
  3392. _print_next_block(par_num++, "XPB");
  3393. break;
  3394. }
  3395. /* Clear the bit */
  3396. sig &= ~cur_bit;
  3397. }
  3398. }
  3399. return par_num;
  3400. }
  3401. static int bnx2x_check_blocks_with_parity1(u32 sig, int par_num,
  3402. bool *global, bool print)
  3403. {
  3404. int i = 0;
  3405. u32 cur_bit = 0;
  3406. for (i = 0; sig; i++) {
  3407. cur_bit = ((u32)0x1 << i);
  3408. if (sig & cur_bit) {
  3409. switch (cur_bit) {
  3410. case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
  3411. if (print)
  3412. _print_next_block(par_num++, "PBF");
  3413. break;
  3414. case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
  3415. if (print)
  3416. _print_next_block(par_num++, "QM");
  3417. break;
  3418. case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
  3419. if (print)
  3420. _print_next_block(par_num++, "TM");
  3421. break;
  3422. case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
  3423. if (print)
  3424. _print_next_block(par_num++, "XSDM");
  3425. break;
  3426. case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
  3427. if (print)
  3428. _print_next_block(par_num++, "XCM");
  3429. break;
  3430. case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
  3431. if (print)
  3432. _print_next_block(par_num++, "XSEMI");
  3433. break;
  3434. case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
  3435. if (print)
  3436. _print_next_block(par_num++,
  3437. "DOORBELLQ");
  3438. break;
  3439. case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
  3440. if (print)
  3441. _print_next_block(par_num++, "NIG");
  3442. break;
  3443. case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
  3444. if (print)
  3445. _print_next_block(par_num++,
  3446. "VAUX PCI CORE");
  3447. *global = true;
  3448. break;
  3449. case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
  3450. if (print)
  3451. _print_next_block(par_num++, "DEBUG");
  3452. break;
  3453. case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
  3454. if (print)
  3455. _print_next_block(par_num++, "USDM");
  3456. break;
  3457. case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
  3458. if (print)
  3459. _print_next_block(par_num++, "UCM");
  3460. break;
  3461. case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
  3462. if (print)
  3463. _print_next_block(par_num++, "USEMI");
  3464. break;
  3465. case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
  3466. if (print)
  3467. _print_next_block(par_num++, "UPB");
  3468. break;
  3469. case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
  3470. if (print)
  3471. _print_next_block(par_num++, "CSDM");
  3472. break;
  3473. case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
  3474. if (print)
  3475. _print_next_block(par_num++, "CCM");
  3476. break;
  3477. }
  3478. /* Clear the bit */
  3479. sig &= ~cur_bit;
  3480. }
  3481. }
  3482. return par_num;
  3483. }
  3484. static int bnx2x_check_blocks_with_parity2(u32 sig, int par_num,
  3485. bool print)
  3486. {
  3487. int i = 0;
  3488. u32 cur_bit = 0;
  3489. for (i = 0; sig; i++) {
  3490. cur_bit = ((u32)0x1 << i);
  3491. if (sig & cur_bit) {
  3492. switch (cur_bit) {
  3493. case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
  3494. if (print)
  3495. _print_next_block(par_num++, "CSEMI");
  3496. break;
  3497. case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
  3498. if (print)
  3499. _print_next_block(par_num++, "PXP");
  3500. break;
  3501. case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
  3502. if (print)
  3503. _print_next_block(par_num++,
  3504. "PXPPCICLOCKCLIENT");
  3505. break;
  3506. case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
  3507. if (print)
  3508. _print_next_block(par_num++, "CFC");
  3509. break;
  3510. case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
  3511. if (print)
  3512. _print_next_block(par_num++, "CDU");
  3513. break;
  3514. case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
  3515. if (print)
  3516. _print_next_block(par_num++, "DMAE");
  3517. break;
  3518. case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
  3519. if (print)
  3520. _print_next_block(par_num++, "IGU");
  3521. break;
  3522. case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
  3523. if (print)
  3524. _print_next_block(par_num++, "MISC");
  3525. break;
  3526. }
  3527. /* Clear the bit */
  3528. sig &= ~cur_bit;
  3529. }
  3530. }
  3531. return par_num;
  3532. }
  3533. static int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
  3534. bool *global, bool print)
  3535. {
  3536. int i = 0;
  3537. u32 cur_bit = 0;
  3538. for (i = 0; sig; i++) {
  3539. cur_bit = ((u32)0x1 << i);
  3540. if (sig & cur_bit) {
  3541. switch (cur_bit) {
  3542. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
  3543. if (print)
  3544. _print_next_block(par_num++, "MCP ROM");
  3545. *global = true;
  3546. break;
  3547. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
  3548. if (print)
  3549. _print_next_block(par_num++,
  3550. "MCP UMP RX");
  3551. *global = true;
  3552. break;
  3553. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
  3554. if (print)
  3555. _print_next_block(par_num++,
  3556. "MCP UMP TX");
  3557. *global = true;
  3558. break;
  3559. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
  3560. if (print)
  3561. _print_next_block(par_num++,
  3562. "MCP SCPAD");
  3563. *global = true;
  3564. break;
  3565. }
  3566. /* Clear the bit */
  3567. sig &= ~cur_bit;
  3568. }
  3569. }
  3570. return par_num;
  3571. }
  3572. static int bnx2x_check_blocks_with_parity4(u32 sig, int par_num,
  3573. bool print)
  3574. {
  3575. int i = 0;
  3576. u32 cur_bit = 0;
  3577. for (i = 0; sig; i++) {
  3578. cur_bit = ((u32)0x1 << i);
  3579. if (sig & cur_bit) {
  3580. switch (cur_bit) {
  3581. case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
  3582. if (print)
  3583. _print_next_block(par_num++, "PGLUE_B");
  3584. break;
  3585. case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
  3586. if (print)
  3587. _print_next_block(par_num++, "ATC");
  3588. break;
  3589. }
  3590. /* Clear the bit */
  3591. sig &= ~cur_bit;
  3592. }
  3593. }
  3594. return par_num;
  3595. }
  3596. static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
  3597. u32 *sig)
  3598. {
  3599. if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  3600. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  3601. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  3602. (sig[3] & HW_PRTY_ASSERT_SET_3) ||
  3603. (sig[4] & HW_PRTY_ASSERT_SET_4)) {
  3604. int par_num = 0;
  3605. DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
  3606. "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
  3607. sig[0] & HW_PRTY_ASSERT_SET_0,
  3608. sig[1] & HW_PRTY_ASSERT_SET_1,
  3609. sig[2] & HW_PRTY_ASSERT_SET_2,
  3610. sig[3] & HW_PRTY_ASSERT_SET_3,
  3611. sig[4] & HW_PRTY_ASSERT_SET_4);
  3612. if (print)
  3613. netdev_err(bp->dev,
  3614. "Parity errors detected in blocks: ");
  3615. par_num = bnx2x_check_blocks_with_parity0(
  3616. sig[0] & HW_PRTY_ASSERT_SET_0, par_num, print);
  3617. par_num = bnx2x_check_blocks_with_parity1(
  3618. sig[1] & HW_PRTY_ASSERT_SET_1, par_num, global, print);
  3619. par_num = bnx2x_check_blocks_with_parity2(
  3620. sig[2] & HW_PRTY_ASSERT_SET_2, par_num, print);
  3621. par_num = bnx2x_check_blocks_with_parity3(
  3622. sig[3] & HW_PRTY_ASSERT_SET_3, par_num, global, print);
  3623. par_num = bnx2x_check_blocks_with_parity4(
  3624. sig[4] & HW_PRTY_ASSERT_SET_4, par_num, print);
  3625. if (print)
  3626. pr_cont("\n");
  3627. return true;
  3628. } else
  3629. return false;
  3630. }
  3631. /**
  3632. * bnx2x_chk_parity_attn - checks for parity attentions.
  3633. *
  3634. * @bp: driver handle
  3635. * @global: true if there was a global attention
  3636. * @print: show parity attention in syslog
  3637. */
  3638. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
  3639. {
  3640. struct attn_route attn = { {0} };
  3641. int port = BP_PORT(bp);
  3642. attn.sig[0] = REG_RD(bp,
  3643. MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
  3644. port*4);
  3645. attn.sig[1] = REG_RD(bp,
  3646. MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
  3647. port*4);
  3648. attn.sig[2] = REG_RD(bp,
  3649. MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
  3650. port*4);
  3651. attn.sig[3] = REG_RD(bp,
  3652. MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
  3653. port*4);
  3654. if (!CHIP_IS_E1x(bp))
  3655. attn.sig[4] = REG_RD(bp,
  3656. MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
  3657. port*4);
  3658. return bnx2x_parity_attn(bp, global, print, attn.sig);
  3659. }
  3660. static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
  3661. {
  3662. u32 val;
  3663. if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
  3664. val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
  3665. BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
  3666. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
  3667. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
  3668. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
  3669. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
  3670. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
  3671. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
  3672. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
  3673. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
  3674. if (val &
  3675. PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
  3676. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
  3677. if (val &
  3678. PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
  3679. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
  3680. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
  3681. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
  3682. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
  3683. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
  3684. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
  3685. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
  3686. }
  3687. if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
  3688. val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
  3689. BNX2X_ERR("ATC hw attention 0x%x\n", val);
  3690. if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
  3691. BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
  3692. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
  3693. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
  3694. if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
  3695. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
  3696. if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
  3697. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
  3698. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
  3699. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
  3700. if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
  3701. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
  3702. }
  3703. if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3704. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
  3705. BNX2X_ERR("FATAL parity attention set4 0x%x\n",
  3706. (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3707. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
  3708. }
  3709. }
  3710. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  3711. {
  3712. struct attn_route attn, *group_mask;
  3713. int port = BP_PORT(bp);
  3714. int index;
  3715. u32 reg_addr;
  3716. u32 val;
  3717. u32 aeu_mask;
  3718. bool global = false;
  3719. /* need to take HW lock because MCP or other port might also
  3720. try to handle this event */
  3721. bnx2x_acquire_alr(bp);
  3722. if (bnx2x_chk_parity_attn(bp, &global, true)) {
  3723. #ifndef BNX2X_STOP_ON_ERROR
  3724. bp->recovery_state = BNX2X_RECOVERY_INIT;
  3725. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3726. /* Disable HW interrupts */
  3727. bnx2x_int_disable(bp);
  3728. /* In case of parity errors don't handle attentions so that
  3729. * other function would "see" parity errors.
  3730. */
  3731. #else
  3732. bnx2x_panic();
  3733. #endif
  3734. bnx2x_release_alr(bp);
  3735. return;
  3736. }
  3737. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  3738. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  3739. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  3740. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  3741. if (!CHIP_IS_E1x(bp))
  3742. attn.sig[4] =
  3743. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
  3744. else
  3745. attn.sig[4] = 0;
  3746. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
  3747. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
  3748. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  3749. if (deasserted & (1 << index)) {
  3750. group_mask = &bp->attn_group[index];
  3751. DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
  3752. index,
  3753. group_mask->sig[0], group_mask->sig[1],
  3754. group_mask->sig[2], group_mask->sig[3],
  3755. group_mask->sig[4]);
  3756. bnx2x_attn_int_deasserted4(bp,
  3757. attn.sig[4] & group_mask->sig[4]);
  3758. bnx2x_attn_int_deasserted3(bp,
  3759. attn.sig[3] & group_mask->sig[3]);
  3760. bnx2x_attn_int_deasserted1(bp,
  3761. attn.sig[1] & group_mask->sig[1]);
  3762. bnx2x_attn_int_deasserted2(bp,
  3763. attn.sig[2] & group_mask->sig[2]);
  3764. bnx2x_attn_int_deasserted0(bp,
  3765. attn.sig[0] & group_mask->sig[0]);
  3766. }
  3767. }
  3768. bnx2x_release_alr(bp);
  3769. if (bp->common.int_block == INT_BLOCK_HC)
  3770. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3771. COMMAND_REG_ATTN_BITS_CLR);
  3772. else
  3773. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
  3774. val = ~deasserted;
  3775. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
  3776. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3777. REG_WR(bp, reg_addr, val);
  3778. if (~bp->attn_state & deasserted)
  3779. BNX2X_ERR("IGU ERROR\n");
  3780. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3781. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3782. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3783. aeu_mask = REG_RD(bp, reg_addr);
  3784. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  3785. aeu_mask, deasserted);
  3786. aeu_mask |= (deasserted & 0x3ff);
  3787. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3788. REG_WR(bp, reg_addr, aeu_mask);
  3789. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3790. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3791. bp->attn_state &= ~deasserted;
  3792. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3793. }
  3794. static void bnx2x_attn_int(struct bnx2x *bp)
  3795. {
  3796. /* read local copy of bits */
  3797. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  3798. attn_bits);
  3799. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  3800. attn_bits_ack);
  3801. u32 attn_state = bp->attn_state;
  3802. /* look for changed bits */
  3803. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  3804. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  3805. DP(NETIF_MSG_HW,
  3806. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  3807. attn_bits, attn_ack, asserted, deasserted);
  3808. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  3809. BNX2X_ERR("BAD attention state\n");
  3810. /* handle bits that were raised */
  3811. if (asserted)
  3812. bnx2x_attn_int_asserted(bp, asserted);
  3813. if (deasserted)
  3814. bnx2x_attn_int_deasserted(bp, deasserted);
  3815. }
  3816. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  3817. u16 index, u8 op, u8 update)
  3818. {
  3819. u32 igu_addr = BAR_IGU_INTMEM + (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
  3820. bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
  3821. igu_addr);
  3822. }
  3823. static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
  3824. {
  3825. /* No memory barriers */
  3826. storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
  3827. mmiowb(); /* keep prod updates ordered */
  3828. }
  3829. #ifdef BCM_CNIC
  3830. static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
  3831. union event_ring_elem *elem)
  3832. {
  3833. u8 err = elem->message.error;
  3834. if (!bp->cnic_eth_dev.starting_cid ||
  3835. (cid < bp->cnic_eth_dev.starting_cid &&
  3836. cid != bp->cnic_eth_dev.iscsi_l2_cid))
  3837. return 1;
  3838. DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
  3839. if (unlikely(err)) {
  3840. BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
  3841. cid);
  3842. bnx2x_panic_dump(bp);
  3843. }
  3844. bnx2x_cnic_cfc_comp(bp, cid, err);
  3845. return 0;
  3846. }
  3847. #endif
  3848. static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
  3849. {
  3850. struct bnx2x_mcast_ramrod_params rparam;
  3851. int rc;
  3852. memset(&rparam, 0, sizeof(rparam));
  3853. rparam.mcast_obj = &bp->mcast_obj;
  3854. netif_addr_lock_bh(bp->dev);
  3855. /* Clear pending state for the last command */
  3856. bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
  3857. /* If there are pending mcast commands - send them */
  3858. if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
  3859. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  3860. if (rc < 0)
  3861. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  3862. rc);
  3863. }
  3864. netif_addr_unlock_bh(bp->dev);
  3865. }
  3866. static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
  3867. union event_ring_elem *elem)
  3868. {
  3869. unsigned long ramrod_flags = 0;
  3870. int rc = 0;
  3871. u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
  3872. struct bnx2x_vlan_mac_obj *vlan_mac_obj;
  3873. /* Always push next commands out, don't wait here */
  3874. __set_bit(RAMROD_CONT, &ramrod_flags);
  3875. switch (elem->message.data.eth_event.echo >> BNX2X_SWCID_SHIFT) {
  3876. case BNX2X_FILTER_MAC_PENDING:
  3877. DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
  3878. #ifdef BCM_CNIC
  3879. if (cid == BNX2X_ISCSI_ETH_CID(bp))
  3880. vlan_mac_obj = &bp->iscsi_l2_mac_obj;
  3881. else
  3882. #endif
  3883. vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
  3884. break;
  3885. case BNX2X_FILTER_MCAST_PENDING:
  3886. DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
  3887. /* This is only relevant for 57710 where multicast MACs are
  3888. * configured as unicast MACs using the same ramrod.
  3889. */
  3890. bnx2x_handle_mcast_eqe(bp);
  3891. return;
  3892. default:
  3893. BNX2X_ERR("Unsupported classification command: %d\n",
  3894. elem->message.data.eth_event.echo);
  3895. return;
  3896. }
  3897. rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
  3898. if (rc < 0)
  3899. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  3900. else if (rc > 0)
  3901. DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
  3902. }
  3903. #ifdef BCM_CNIC
  3904. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
  3905. #endif
  3906. static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
  3907. {
  3908. netif_addr_lock_bh(bp->dev);
  3909. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  3910. /* Send rx_mode command again if was requested */
  3911. if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
  3912. bnx2x_set_storm_rx_mode(bp);
  3913. #ifdef BCM_CNIC
  3914. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
  3915. &bp->sp_state))
  3916. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  3917. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
  3918. &bp->sp_state))
  3919. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  3920. #endif
  3921. netif_addr_unlock_bh(bp->dev);
  3922. }
  3923. static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
  3924. union event_ring_elem *elem)
  3925. {
  3926. if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
  3927. DP(BNX2X_MSG_SP,
  3928. "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
  3929. elem->message.data.vif_list_event.func_bit_map);
  3930. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
  3931. elem->message.data.vif_list_event.func_bit_map);
  3932. } else if (elem->message.data.vif_list_event.echo ==
  3933. VIF_LIST_RULE_SET) {
  3934. DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
  3935. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
  3936. }
  3937. }
  3938. /* called with rtnl_lock */
  3939. static void bnx2x_after_function_update(struct bnx2x *bp)
  3940. {
  3941. int q, rc;
  3942. struct bnx2x_fastpath *fp;
  3943. struct bnx2x_queue_state_params queue_params = {NULL};
  3944. struct bnx2x_queue_update_params *q_update_params =
  3945. &queue_params.params.update;
  3946. /* Send Q update command with afex vlan removal values for all Qs */
  3947. queue_params.cmd = BNX2X_Q_CMD_UPDATE;
  3948. /* set silent vlan removal values according to vlan mode */
  3949. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
  3950. &q_update_params->update_flags);
  3951. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
  3952. &q_update_params->update_flags);
  3953. __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  3954. /* in access mode mark mask and value are 0 to strip all vlans */
  3955. if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
  3956. q_update_params->silent_removal_value = 0;
  3957. q_update_params->silent_removal_mask = 0;
  3958. } else {
  3959. q_update_params->silent_removal_value =
  3960. (bp->afex_def_vlan_tag & VLAN_VID_MASK);
  3961. q_update_params->silent_removal_mask = VLAN_VID_MASK;
  3962. }
  3963. for_each_eth_queue(bp, q) {
  3964. /* Set the appropriate Queue object */
  3965. fp = &bp->fp[q];
  3966. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  3967. /* send the ramrod */
  3968. rc = bnx2x_queue_state_change(bp, &queue_params);
  3969. if (rc < 0)
  3970. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  3971. q);
  3972. }
  3973. #ifdef BCM_CNIC
  3974. if (!NO_FCOE(bp)) {
  3975. fp = &bp->fp[FCOE_IDX(bp)];
  3976. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  3977. /* clear pending completion bit */
  3978. __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  3979. /* mark latest Q bit */
  3980. smp_mb__before_clear_bit();
  3981. set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  3982. smp_mb__after_clear_bit();
  3983. /* send Q update ramrod for FCoE Q */
  3984. rc = bnx2x_queue_state_change(bp, &queue_params);
  3985. if (rc < 0)
  3986. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  3987. q);
  3988. } else {
  3989. /* If no FCoE ring - ACK MCP now */
  3990. bnx2x_link_report(bp);
  3991. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  3992. }
  3993. #else
  3994. /* If no FCoE ring - ACK MCP now */
  3995. bnx2x_link_report(bp);
  3996. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  3997. #endif /* BCM_CNIC */
  3998. }
  3999. static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
  4000. struct bnx2x *bp, u32 cid)
  4001. {
  4002. DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
  4003. #ifdef BCM_CNIC
  4004. if (cid == BNX2X_FCOE_ETH_CID(bp))
  4005. return &bnx2x_fcoe_sp_obj(bp, q_obj);
  4006. else
  4007. #endif
  4008. return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
  4009. }
  4010. static void bnx2x_eq_int(struct bnx2x *bp)
  4011. {
  4012. u16 hw_cons, sw_cons, sw_prod;
  4013. union event_ring_elem *elem;
  4014. u32 cid;
  4015. u8 opcode;
  4016. int spqe_cnt = 0;
  4017. struct bnx2x_queue_sp_obj *q_obj;
  4018. struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
  4019. struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
  4020. hw_cons = le16_to_cpu(*bp->eq_cons_sb);
  4021. /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
  4022. * when we get the the next-page we nned to adjust so the loop
  4023. * condition below will be met. The next element is the size of a
  4024. * regular element and hence incrementing by 1
  4025. */
  4026. if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
  4027. hw_cons++;
  4028. /* This function may never run in parallel with itself for a
  4029. * specific bp, thus there is no need in "paired" read memory
  4030. * barrier here.
  4031. */
  4032. sw_cons = bp->eq_cons;
  4033. sw_prod = bp->eq_prod;
  4034. DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
  4035. hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
  4036. for (; sw_cons != hw_cons;
  4037. sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
  4038. elem = &bp->eq_ring[EQ_DESC(sw_cons)];
  4039. cid = SW_CID(elem->message.data.cfc_del_event.cid);
  4040. opcode = elem->message.opcode;
  4041. /* handle eq element */
  4042. switch (opcode) {
  4043. case EVENT_RING_OPCODE_STAT_QUERY:
  4044. DP(BNX2X_MSG_SP | BNX2X_MSG_STATS,
  4045. "got statistics comp event %d\n",
  4046. bp->stats_comp++);
  4047. /* nothing to do with stats comp */
  4048. goto next_spqe;
  4049. case EVENT_RING_OPCODE_CFC_DEL:
  4050. /* handle according to cid range */
  4051. /*
  4052. * we may want to verify here that the bp state is
  4053. * HALTING
  4054. */
  4055. DP(BNX2X_MSG_SP,
  4056. "got delete ramrod for MULTI[%d]\n", cid);
  4057. #ifdef BCM_CNIC
  4058. if (!bnx2x_cnic_handle_cfc_del(bp, cid, elem))
  4059. goto next_spqe;
  4060. #endif
  4061. q_obj = bnx2x_cid_to_q_obj(bp, cid);
  4062. if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
  4063. break;
  4064. goto next_spqe;
  4065. case EVENT_RING_OPCODE_STOP_TRAFFIC:
  4066. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
  4067. if (f_obj->complete_cmd(bp, f_obj,
  4068. BNX2X_F_CMD_TX_STOP))
  4069. break;
  4070. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
  4071. goto next_spqe;
  4072. case EVENT_RING_OPCODE_START_TRAFFIC:
  4073. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
  4074. if (f_obj->complete_cmd(bp, f_obj,
  4075. BNX2X_F_CMD_TX_START))
  4076. break;
  4077. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
  4078. goto next_spqe;
  4079. case EVENT_RING_OPCODE_FUNCTION_UPDATE:
  4080. DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
  4081. "AFEX: ramrod completed FUNCTION_UPDATE\n");
  4082. f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_AFEX_UPDATE);
  4083. /* We will perform the Queues update from sp_rtnl task
  4084. * as all Queue SP operations should run under
  4085. * rtnl_lock.
  4086. */
  4087. smp_mb__before_clear_bit();
  4088. set_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE,
  4089. &bp->sp_rtnl_state);
  4090. smp_mb__after_clear_bit();
  4091. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4092. goto next_spqe;
  4093. case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
  4094. f_obj->complete_cmd(bp, f_obj,
  4095. BNX2X_F_CMD_AFEX_VIFLISTS);
  4096. bnx2x_after_afex_vif_lists(bp, elem);
  4097. goto next_spqe;
  4098. case EVENT_RING_OPCODE_FUNCTION_START:
  4099. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4100. "got FUNC_START ramrod\n");
  4101. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
  4102. break;
  4103. goto next_spqe;
  4104. case EVENT_RING_OPCODE_FUNCTION_STOP:
  4105. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4106. "got FUNC_STOP ramrod\n");
  4107. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
  4108. break;
  4109. goto next_spqe;
  4110. }
  4111. switch (opcode | bp->state) {
  4112. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4113. BNX2X_STATE_OPEN):
  4114. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4115. BNX2X_STATE_OPENING_WAIT4_PORT):
  4116. cid = elem->message.data.eth_event.echo &
  4117. BNX2X_SWCID_MASK;
  4118. DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
  4119. cid);
  4120. rss_raw->clear_pending(rss_raw);
  4121. break;
  4122. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
  4123. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
  4124. case (EVENT_RING_OPCODE_SET_MAC |
  4125. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4126. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4127. BNX2X_STATE_OPEN):
  4128. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4129. BNX2X_STATE_DIAG):
  4130. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4131. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4132. DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
  4133. bnx2x_handle_classification_eqe(bp, elem);
  4134. break;
  4135. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4136. BNX2X_STATE_OPEN):
  4137. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4138. BNX2X_STATE_DIAG):
  4139. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4140. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4141. DP(BNX2X_MSG_SP, "got mcast ramrod\n");
  4142. bnx2x_handle_mcast_eqe(bp);
  4143. break;
  4144. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4145. BNX2X_STATE_OPEN):
  4146. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4147. BNX2X_STATE_DIAG):
  4148. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4149. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4150. DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
  4151. bnx2x_handle_rx_mode_eqe(bp);
  4152. break;
  4153. default:
  4154. /* unknown event log error and continue */
  4155. BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
  4156. elem->message.opcode, bp->state);
  4157. }
  4158. next_spqe:
  4159. spqe_cnt++;
  4160. } /* for */
  4161. smp_mb__before_atomic_inc();
  4162. atomic_add(spqe_cnt, &bp->eq_spq_left);
  4163. bp->eq_cons = sw_cons;
  4164. bp->eq_prod = sw_prod;
  4165. /* Make sure that above mem writes were issued towards the memory */
  4166. smp_wmb();
  4167. /* update producer */
  4168. bnx2x_update_eq_prod(bp, bp->eq_prod);
  4169. }
  4170. static void bnx2x_sp_task(struct work_struct *work)
  4171. {
  4172. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  4173. u16 status;
  4174. status = bnx2x_update_dsb_idx(bp);
  4175. /* if (status == 0) */
  4176. /* BNX2X_ERR("spurious slowpath interrupt!\n"); */
  4177. DP(BNX2X_MSG_SP, "got a slowpath interrupt (status 0x%x)\n", status);
  4178. /* HW attentions */
  4179. if (status & BNX2X_DEF_SB_ATT_IDX) {
  4180. bnx2x_attn_int(bp);
  4181. status &= ~BNX2X_DEF_SB_ATT_IDX;
  4182. }
  4183. /* SP events: STAT_QUERY and others */
  4184. if (status & BNX2X_DEF_SB_IDX) {
  4185. #ifdef BCM_CNIC
  4186. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  4187. if ((!NO_FCOE(bp)) &&
  4188. (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  4189. /*
  4190. * Prevent local bottom-halves from running as
  4191. * we are going to change the local NAPI list.
  4192. */
  4193. local_bh_disable();
  4194. napi_schedule(&bnx2x_fcoe(bp, napi));
  4195. local_bh_enable();
  4196. }
  4197. #endif
  4198. /* Handle EQ completions */
  4199. bnx2x_eq_int(bp);
  4200. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
  4201. le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
  4202. status &= ~BNX2X_DEF_SB_IDX;
  4203. }
  4204. if (unlikely(status))
  4205. DP(BNX2X_MSG_SP, "got an unknown interrupt! (status 0x%x)\n",
  4206. status);
  4207. bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
  4208. le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
  4209. /* afex - poll to check if VIFSET_ACK should be sent to MFW */
  4210. if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
  4211. &bp->sp_state)) {
  4212. bnx2x_link_report(bp);
  4213. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4214. }
  4215. }
  4216. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  4217. {
  4218. struct net_device *dev = dev_instance;
  4219. struct bnx2x *bp = netdev_priv(dev);
  4220. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
  4221. IGU_INT_DISABLE, 0);
  4222. #ifdef BNX2X_STOP_ON_ERROR
  4223. if (unlikely(bp->panic))
  4224. return IRQ_HANDLED;
  4225. #endif
  4226. #ifdef BCM_CNIC
  4227. {
  4228. struct cnic_ops *c_ops;
  4229. rcu_read_lock();
  4230. c_ops = rcu_dereference(bp->cnic_ops);
  4231. if (c_ops)
  4232. c_ops->cnic_handler(bp->cnic_data, NULL);
  4233. rcu_read_unlock();
  4234. }
  4235. #endif
  4236. queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  4237. return IRQ_HANDLED;
  4238. }
  4239. /* end of slow path */
  4240. void bnx2x_drv_pulse(struct bnx2x *bp)
  4241. {
  4242. SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
  4243. bp->fw_drv_pulse_wr_seq);
  4244. }
  4245. static void bnx2x_timer(unsigned long data)
  4246. {
  4247. struct bnx2x *bp = (struct bnx2x *) data;
  4248. if (!netif_running(bp->dev))
  4249. return;
  4250. if (!BP_NOMCP(bp)) {
  4251. int mb_idx = BP_FW_MB_IDX(bp);
  4252. u32 drv_pulse;
  4253. u32 mcp_pulse;
  4254. ++bp->fw_drv_pulse_wr_seq;
  4255. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  4256. /* TBD - add SYSTEM_TIME */
  4257. drv_pulse = bp->fw_drv_pulse_wr_seq;
  4258. bnx2x_drv_pulse(bp);
  4259. mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
  4260. MCP_PULSE_SEQ_MASK);
  4261. /* The delta between driver pulse and mcp response
  4262. * should be 1 (before mcp response) or 0 (after mcp response)
  4263. */
  4264. if ((drv_pulse != mcp_pulse) &&
  4265. (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
  4266. /* someone lost a heartbeat... */
  4267. BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  4268. drv_pulse, mcp_pulse);
  4269. }
  4270. }
  4271. if (bp->state == BNX2X_STATE_OPEN)
  4272. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  4273. mod_timer(&bp->timer, jiffies + bp->current_interval);
  4274. }
  4275. /* end of Statistics */
  4276. /* nic init */
  4277. /*
  4278. * nic init service functions
  4279. */
  4280. static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  4281. {
  4282. u32 i;
  4283. if (!(len%4) && !(addr%4))
  4284. for (i = 0; i < len; i += 4)
  4285. REG_WR(bp, addr + i, fill);
  4286. else
  4287. for (i = 0; i < len; i++)
  4288. REG_WR8(bp, addr + i, fill);
  4289. }
  4290. /* helper: writes FP SP data to FW - data_size in dwords */
  4291. static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
  4292. int fw_sb_id,
  4293. u32 *sb_data_p,
  4294. u32 data_size)
  4295. {
  4296. int index;
  4297. for (index = 0; index < data_size; index++)
  4298. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4299. CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
  4300. sizeof(u32)*index,
  4301. *(sb_data_p + index));
  4302. }
  4303. static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
  4304. {
  4305. u32 *sb_data_p;
  4306. u32 data_size = 0;
  4307. struct hc_status_block_data_e2 sb_data_e2;
  4308. struct hc_status_block_data_e1x sb_data_e1x;
  4309. /* disable the function first */
  4310. if (!CHIP_IS_E1x(bp)) {
  4311. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4312. sb_data_e2.common.state = SB_DISABLED;
  4313. sb_data_e2.common.p_func.vf_valid = false;
  4314. sb_data_p = (u32 *)&sb_data_e2;
  4315. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4316. } else {
  4317. memset(&sb_data_e1x, 0,
  4318. sizeof(struct hc_status_block_data_e1x));
  4319. sb_data_e1x.common.state = SB_DISABLED;
  4320. sb_data_e1x.common.p_func.vf_valid = false;
  4321. sb_data_p = (u32 *)&sb_data_e1x;
  4322. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4323. }
  4324. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4325. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4326. CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
  4327. CSTORM_STATUS_BLOCK_SIZE);
  4328. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4329. CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
  4330. CSTORM_SYNC_BLOCK_SIZE);
  4331. }
  4332. /* helper: writes SP SB data to FW */
  4333. static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
  4334. struct hc_sp_status_block_data *sp_sb_data)
  4335. {
  4336. int func = BP_FUNC(bp);
  4337. int i;
  4338. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  4339. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4340. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  4341. i*sizeof(u32),
  4342. *((u32 *)sp_sb_data + i));
  4343. }
  4344. static void bnx2x_zero_sp_sb(struct bnx2x *bp)
  4345. {
  4346. int func = BP_FUNC(bp);
  4347. struct hc_sp_status_block_data sp_sb_data;
  4348. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4349. sp_sb_data.state = SB_DISABLED;
  4350. sp_sb_data.p_func.vf_valid = false;
  4351. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4352. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4353. CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
  4354. CSTORM_SP_STATUS_BLOCK_SIZE);
  4355. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4356. CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
  4357. CSTORM_SP_SYNC_BLOCK_SIZE);
  4358. }
  4359. static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
  4360. int igu_sb_id, int igu_seg_id)
  4361. {
  4362. hc_sm->igu_sb_id = igu_sb_id;
  4363. hc_sm->igu_seg_id = igu_seg_id;
  4364. hc_sm->timer_value = 0xFF;
  4365. hc_sm->time_to_expire = 0xFFFFFFFF;
  4366. }
  4367. /* allocates state machine ids. */
  4368. static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
  4369. {
  4370. /* zero out state machine indices */
  4371. /* rx indices */
  4372. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4373. /* tx indices */
  4374. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4375. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
  4376. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
  4377. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
  4378. /* map indices */
  4379. /* rx indices */
  4380. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
  4381. SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4382. /* tx indices */
  4383. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
  4384. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4385. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
  4386. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4387. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
  4388. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4389. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
  4390. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4391. }
  4392. static void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
  4393. u8 vf_valid, int fw_sb_id, int igu_sb_id)
  4394. {
  4395. int igu_seg_id;
  4396. struct hc_status_block_data_e2 sb_data_e2;
  4397. struct hc_status_block_data_e1x sb_data_e1x;
  4398. struct hc_status_block_sm *hc_sm_p;
  4399. int data_size;
  4400. u32 *sb_data_p;
  4401. if (CHIP_INT_MODE_IS_BC(bp))
  4402. igu_seg_id = HC_SEG_ACCESS_NORM;
  4403. else
  4404. igu_seg_id = IGU_SEG_ACCESS_NORM;
  4405. bnx2x_zero_fp_sb(bp, fw_sb_id);
  4406. if (!CHIP_IS_E1x(bp)) {
  4407. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4408. sb_data_e2.common.state = SB_ENABLED;
  4409. sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
  4410. sb_data_e2.common.p_func.vf_id = vfid;
  4411. sb_data_e2.common.p_func.vf_valid = vf_valid;
  4412. sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
  4413. sb_data_e2.common.same_igu_sb_1b = true;
  4414. sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
  4415. sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
  4416. hc_sm_p = sb_data_e2.common.state_machine;
  4417. sb_data_p = (u32 *)&sb_data_e2;
  4418. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4419. bnx2x_map_sb_state_machines(sb_data_e2.index_data);
  4420. } else {
  4421. memset(&sb_data_e1x, 0,
  4422. sizeof(struct hc_status_block_data_e1x));
  4423. sb_data_e1x.common.state = SB_ENABLED;
  4424. sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
  4425. sb_data_e1x.common.p_func.vf_id = 0xff;
  4426. sb_data_e1x.common.p_func.vf_valid = false;
  4427. sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
  4428. sb_data_e1x.common.same_igu_sb_1b = true;
  4429. sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
  4430. sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
  4431. hc_sm_p = sb_data_e1x.common.state_machine;
  4432. sb_data_p = (u32 *)&sb_data_e1x;
  4433. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4434. bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
  4435. }
  4436. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
  4437. igu_sb_id, igu_seg_id);
  4438. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
  4439. igu_sb_id, igu_seg_id);
  4440. DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
  4441. /* write indecies to HW */
  4442. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4443. }
  4444. static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
  4445. u16 tx_usec, u16 rx_usec)
  4446. {
  4447. bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
  4448. false, rx_usec);
  4449. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4450. HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
  4451. tx_usec);
  4452. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4453. HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
  4454. tx_usec);
  4455. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4456. HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
  4457. tx_usec);
  4458. }
  4459. static void bnx2x_init_def_sb(struct bnx2x *bp)
  4460. {
  4461. struct host_sp_status_block *def_sb = bp->def_status_blk;
  4462. dma_addr_t mapping = bp->def_status_blk_mapping;
  4463. int igu_sp_sb_index;
  4464. int igu_seg_id;
  4465. int port = BP_PORT(bp);
  4466. int func = BP_FUNC(bp);
  4467. int reg_offset, reg_offset_en5;
  4468. u64 section;
  4469. int index;
  4470. struct hc_sp_status_block_data sp_sb_data;
  4471. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4472. if (CHIP_INT_MODE_IS_BC(bp)) {
  4473. igu_sp_sb_index = DEF_SB_IGU_ID;
  4474. igu_seg_id = HC_SEG_ACCESS_DEF;
  4475. } else {
  4476. igu_sp_sb_index = bp->igu_dsb_id;
  4477. igu_seg_id = IGU_SEG_ACCESS_DEF;
  4478. }
  4479. /* ATTN */
  4480. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4481. atten_status_block);
  4482. def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
  4483. bp->attn_state = 0;
  4484. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  4485. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  4486. reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
  4487. MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
  4488. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4489. int sindex;
  4490. /* take care of sig[0]..sig[4] */
  4491. for (sindex = 0; sindex < 4; sindex++)
  4492. bp->attn_group[index].sig[sindex] =
  4493. REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
  4494. if (!CHIP_IS_E1x(bp))
  4495. /*
  4496. * enable5 is separate from the rest of the registers,
  4497. * and therefore the address skip is 4
  4498. * and not 16 between the different groups
  4499. */
  4500. bp->attn_group[index].sig[4] = REG_RD(bp,
  4501. reg_offset_en5 + 0x4*index);
  4502. else
  4503. bp->attn_group[index].sig[4] = 0;
  4504. }
  4505. if (bp->common.int_block == INT_BLOCK_HC) {
  4506. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  4507. HC_REG_ATTN_MSG0_ADDR_L);
  4508. REG_WR(bp, reg_offset, U64_LO(section));
  4509. REG_WR(bp, reg_offset + 4, U64_HI(section));
  4510. } else if (!CHIP_IS_E1x(bp)) {
  4511. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
  4512. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
  4513. }
  4514. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4515. sp_sb);
  4516. bnx2x_zero_sp_sb(bp);
  4517. sp_sb_data.state = SB_ENABLED;
  4518. sp_sb_data.host_sb_addr.lo = U64_LO(section);
  4519. sp_sb_data.host_sb_addr.hi = U64_HI(section);
  4520. sp_sb_data.igu_sb_id = igu_sp_sb_index;
  4521. sp_sb_data.igu_seg_id = igu_seg_id;
  4522. sp_sb_data.p_func.pf_id = func;
  4523. sp_sb_data.p_func.vnic_id = BP_VN(bp);
  4524. sp_sb_data.p_func.vf_id = 0xff;
  4525. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4526. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
  4527. }
  4528. void bnx2x_update_coalesce(struct bnx2x *bp)
  4529. {
  4530. int i;
  4531. for_each_eth_queue(bp, i)
  4532. bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
  4533. bp->tx_ticks, bp->rx_ticks);
  4534. }
  4535. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  4536. {
  4537. spin_lock_init(&bp->spq_lock);
  4538. atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
  4539. bp->spq_prod_idx = 0;
  4540. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  4541. bp->spq_prod_bd = bp->spq;
  4542. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  4543. }
  4544. static void bnx2x_init_eq_ring(struct bnx2x *bp)
  4545. {
  4546. int i;
  4547. for (i = 1; i <= NUM_EQ_PAGES; i++) {
  4548. union event_ring_elem *elem =
  4549. &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
  4550. elem->next_page.addr.hi =
  4551. cpu_to_le32(U64_HI(bp->eq_mapping +
  4552. BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
  4553. elem->next_page.addr.lo =
  4554. cpu_to_le32(U64_LO(bp->eq_mapping +
  4555. BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
  4556. }
  4557. bp->eq_cons = 0;
  4558. bp->eq_prod = NUM_EQ_DESC;
  4559. bp->eq_cons_sb = BNX2X_EQ_INDEX;
  4560. /* we want a warning message before it gets rought... */
  4561. atomic_set(&bp->eq_spq_left,
  4562. min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
  4563. }
  4564. /* called with netif_addr_lock_bh() */
  4565. void bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
  4566. unsigned long rx_mode_flags,
  4567. unsigned long rx_accept_flags,
  4568. unsigned long tx_accept_flags,
  4569. unsigned long ramrod_flags)
  4570. {
  4571. struct bnx2x_rx_mode_ramrod_params ramrod_param;
  4572. int rc;
  4573. memset(&ramrod_param, 0, sizeof(ramrod_param));
  4574. /* Prepare ramrod parameters */
  4575. ramrod_param.cid = 0;
  4576. ramrod_param.cl_id = cl_id;
  4577. ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
  4578. ramrod_param.func_id = BP_FUNC(bp);
  4579. ramrod_param.pstate = &bp->sp_state;
  4580. ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
  4581. ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
  4582. ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
  4583. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4584. ramrod_param.ramrod_flags = ramrod_flags;
  4585. ramrod_param.rx_mode_flags = rx_mode_flags;
  4586. ramrod_param.rx_accept_flags = rx_accept_flags;
  4587. ramrod_param.tx_accept_flags = tx_accept_flags;
  4588. rc = bnx2x_config_rx_mode(bp, &ramrod_param);
  4589. if (rc < 0) {
  4590. BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
  4591. return;
  4592. }
  4593. }
  4594. /* called with netif_addr_lock_bh() */
  4595. void bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  4596. {
  4597. unsigned long rx_mode_flags = 0, ramrod_flags = 0;
  4598. unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
  4599. #ifdef BCM_CNIC
  4600. if (!NO_FCOE(bp))
  4601. /* Configure rx_mode of FCoE Queue */
  4602. __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
  4603. #endif
  4604. switch (bp->rx_mode) {
  4605. case BNX2X_RX_MODE_NONE:
  4606. /*
  4607. * 'drop all' supersedes any accept flags that may have been
  4608. * passed to the function.
  4609. */
  4610. break;
  4611. case BNX2X_RX_MODE_NORMAL:
  4612. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4613. __set_bit(BNX2X_ACCEPT_MULTICAST, &rx_accept_flags);
  4614. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4615. /* internal switching mode */
  4616. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4617. __set_bit(BNX2X_ACCEPT_MULTICAST, &tx_accept_flags);
  4618. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4619. break;
  4620. case BNX2X_RX_MODE_ALLMULTI:
  4621. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4622. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
  4623. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4624. /* internal switching mode */
  4625. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4626. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
  4627. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4628. break;
  4629. case BNX2X_RX_MODE_PROMISC:
  4630. /* According to deffinition of SI mode, iface in promisc mode
  4631. * should receive matched and unmatched (in resolution of port)
  4632. * unicast packets.
  4633. */
  4634. __set_bit(BNX2X_ACCEPT_UNMATCHED, &rx_accept_flags);
  4635. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4636. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
  4637. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4638. /* internal switching mode */
  4639. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
  4640. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4641. if (IS_MF_SI(bp))
  4642. __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &tx_accept_flags);
  4643. else
  4644. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4645. break;
  4646. default:
  4647. BNX2X_ERR("Unknown rx_mode: %d\n", bp->rx_mode);
  4648. return;
  4649. }
  4650. if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
  4651. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &rx_accept_flags);
  4652. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &tx_accept_flags);
  4653. }
  4654. __set_bit(RAMROD_RX, &ramrod_flags);
  4655. __set_bit(RAMROD_TX, &ramrod_flags);
  4656. bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags, rx_accept_flags,
  4657. tx_accept_flags, ramrod_flags);
  4658. }
  4659. static void bnx2x_init_internal_common(struct bnx2x *bp)
  4660. {
  4661. int i;
  4662. if (IS_MF_SI(bp))
  4663. /*
  4664. * In switch independent mode, the TSTORM needs to accept
  4665. * packets that failed classification, since approximate match
  4666. * mac addresses aren't written to NIG LLH
  4667. */
  4668. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4669. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
  4670. else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
  4671. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4672. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
  4673. /* Zero this manually as its initialization is
  4674. currently missing in the initTool */
  4675. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  4676. REG_WR(bp, BAR_USTRORM_INTMEM +
  4677. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  4678. if (!CHIP_IS_E1x(bp)) {
  4679. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
  4680. CHIP_INT_MODE_IS_BC(bp) ?
  4681. HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
  4682. }
  4683. }
  4684. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  4685. {
  4686. switch (load_code) {
  4687. case FW_MSG_CODE_DRV_LOAD_COMMON:
  4688. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  4689. bnx2x_init_internal_common(bp);
  4690. /* no break */
  4691. case FW_MSG_CODE_DRV_LOAD_PORT:
  4692. /* nothing to do */
  4693. /* no break */
  4694. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  4695. /* internal memory per function is
  4696. initialized inside bnx2x_pf_init */
  4697. break;
  4698. default:
  4699. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  4700. break;
  4701. }
  4702. }
  4703. static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
  4704. {
  4705. return fp->bp->igu_base_sb + fp->index + CNIC_PRESENT;
  4706. }
  4707. static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
  4708. {
  4709. return fp->bp->base_fw_ndsb + fp->index + CNIC_PRESENT;
  4710. }
  4711. static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
  4712. {
  4713. if (CHIP_IS_E1x(fp->bp))
  4714. return BP_L_ID(fp->bp) + fp->index;
  4715. else /* We want Client ID to be the same as IGU SB ID for 57712 */
  4716. return bnx2x_fp_igu_sb_id(fp);
  4717. }
  4718. static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
  4719. {
  4720. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  4721. u8 cos;
  4722. unsigned long q_type = 0;
  4723. u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
  4724. fp->rx_queue = fp_idx;
  4725. fp->cid = fp_idx;
  4726. fp->cl_id = bnx2x_fp_cl_id(fp);
  4727. fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
  4728. fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
  4729. /* qZone id equals to FW (per path) client id */
  4730. fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
  4731. /* init shortcut */
  4732. fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
  4733. /* Setup SB indicies */
  4734. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  4735. /* Configure Queue State object */
  4736. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  4737. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  4738. BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
  4739. /* init tx data */
  4740. for_each_cos_in_tx_queue(fp, cos) {
  4741. bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
  4742. CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
  4743. FP_COS_TO_TXQ(fp, cos, bp),
  4744. BNX2X_TX_SB_INDEX_BASE + cos, fp);
  4745. cids[cos] = fp->txdata_ptr[cos]->cid;
  4746. }
  4747. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
  4748. fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  4749. bnx2x_sp_mapping(bp, q_rdata), q_type);
  4750. /**
  4751. * Configure classification DBs: Always enable Tx switching
  4752. */
  4753. bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
  4754. DP(NETIF_MSG_IFUP, "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  4755. fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  4756. fp->igu_sb_id);
  4757. bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
  4758. fp->fw_sb_id, fp->igu_sb_id);
  4759. bnx2x_update_fpsb_idx(fp);
  4760. }
  4761. static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
  4762. {
  4763. int i;
  4764. for (i = 1; i <= NUM_TX_RINGS; i++) {
  4765. struct eth_tx_next_bd *tx_next_bd =
  4766. &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
  4767. tx_next_bd->addr_hi =
  4768. cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
  4769. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  4770. tx_next_bd->addr_lo =
  4771. cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
  4772. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  4773. }
  4774. SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
  4775. txdata->tx_db.data.zero_fill1 = 0;
  4776. txdata->tx_db.data.prod = 0;
  4777. txdata->tx_pkt_prod = 0;
  4778. txdata->tx_pkt_cons = 0;
  4779. txdata->tx_bd_prod = 0;
  4780. txdata->tx_bd_cons = 0;
  4781. txdata->tx_pkt = 0;
  4782. }
  4783. static void bnx2x_init_tx_rings(struct bnx2x *bp)
  4784. {
  4785. int i;
  4786. u8 cos;
  4787. for_each_tx_queue(bp, i)
  4788. for_each_cos_in_tx_queue(&bp->fp[i], cos)
  4789. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
  4790. }
  4791. void bnx2x_nic_init(struct bnx2x *bp, u32 load_code)
  4792. {
  4793. int i;
  4794. for_each_eth_queue(bp, i)
  4795. bnx2x_init_eth_fp(bp, i);
  4796. #ifdef BCM_CNIC
  4797. if (!NO_FCOE(bp))
  4798. bnx2x_init_fcoe_fp(bp);
  4799. bnx2x_init_sb(bp, bp->cnic_sb_mapping,
  4800. BNX2X_VF_ID_INVALID, false,
  4801. bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
  4802. #endif
  4803. /* Initialize MOD_ABS interrupts */
  4804. bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
  4805. bp->common.shmem_base, bp->common.shmem2_base,
  4806. BP_PORT(bp));
  4807. /* ensure status block indices were read */
  4808. rmb();
  4809. bnx2x_init_def_sb(bp);
  4810. bnx2x_update_dsb_idx(bp);
  4811. bnx2x_init_rx_rings(bp);
  4812. bnx2x_init_tx_rings(bp);
  4813. bnx2x_init_sp_ring(bp);
  4814. bnx2x_init_eq_ring(bp);
  4815. bnx2x_init_internal(bp, load_code);
  4816. bnx2x_pf_init(bp);
  4817. bnx2x_stats_init(bp);
  4818. /* flush all before enabling interrupts */
  4819. mb();
  4820. mmiowb();
  4821. bnx2x_int_enable(bp);
  4822. /* Check for SPIO5 */
  4823. bnx2x_attn_int_deasserted0(bp,
  4824. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
  4825. AEU_INPUTS_ATTN_BITS_SPIO5);
  4826. }
  4827. /* end of nic init */
  4828. /*
  4829. * gzip service functions
  4830. */
  4831. static int bnx2x_gunzip_init(struct bnx2x *bp)
  4832. {
  4833. bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
  4834. &bp->gunzip_mapping, GFP_KERNEL);
  4835. if (bp->gunzip_buf == NULL)
  4836. goto gunzip_nomem1;
  4837. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  4838. if (bp->strm == NULL)
  4839. goto gunzip_nomem2;
  4840. bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
  4841. if (bp->strm->workspace == NULL)
  4842. goto gunzip_nomem3;
  4843. return 0;
  4844. gunzip_nomem3:
  4845. kfree(bp->strm);
  4846. bp->strm = NULL;
  4847. gunzip_nomem2:
  4848. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  4849. bp->gunzip_mapping);
  4850. bp->gunzip_buf = NULL;
  4851. gunzip_nomem1:
  4852. BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
  4853. return -ENOMEM;
  4854. }
  4855. static void bnx2x_gunzip_end(struct bnx2x *bp)
  4856. {
  4857. if (bp->strm) {
  4858. vfree(bp->strm->workspace);
  4859. kfree(bp->strm);
  4860. bp->strm = NULL;
  4861. }
  4862. if (bp->gunzip_buf) {
  4863. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  4864. bp->gunzip_mapping);
  4865. bp->gunzip_buf = NULL;
  4866. }
  4867. }
  4868. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
  4869. {
  4870. int n, rc;
  4871. /* check gzip header */
  4872. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
  4873. BNX2X_ERR("Bad gzip header\n");
  4874. return -EINVAL;
  4875. }
  4876. n = 10;
  4877. #define FNAME 0x8
  4878. if (zbuf[3] & FNAME)
  4879. while ((zbuf[n++] != 0) && (n < len));
  4880. bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
  4881. bp->strm->avail_in = len - n;
  4882. bp->strm->next_out = bp->gunzip_buf;
  4883. bp->strm->avail_out = FW_BUF_SIZE;
  4884. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  4885. if (rc != Z_OK)
  4886. return rc;
  4887. rc = zlib_inflate(bp->strm, Z_FINISH);
  4888. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  4889. netdev_err(bp->dev, "Firmware decompression error: %s\n",
  4890. bp->strm->msg);
  4891. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  4892. if (bp->gunzip_outlen & 0x3)
  4893. netdev_err(bp->dev,
  4894. "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
  4895. bp->gunzip_outlen);
  4896. bp->gunzip_outlen >>= 2;
  4897. zlib_inflateEnd(bp->strm);
  4898. if (rc == Z_STREAM_END)
  4899. return 0;
  4900. return rc;
  4901. }
  4902. /* nic load/unload */
  4903. /*
  4904. * General service functions
  4905. */
  4906. /* send a NIG loopback debug packet */
  4907. static void bnx2x_lb_pckt(struct bnx2x *bp)
  4908. {
  4909. u32 wb_write[3];
  4910. /* Ethernet source and destination addresses */
  4911. wb_write[0] = 0x55555555;
  4912. wb_write[1] = 0x55555555;
  4913. wb_write[2] = 0x20; /* SOP */
  4914. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  4915. /* NON-IP protocol */
  4916. wb_write[0] = 0x09000000;
  4917. wb_write[1] = 0x55555555;
  4918. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  4919. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  4920. }
  4921. /* some of the internal memories
  4922. * are not directly readable from the driver
  4923. * to test them we send debug packets
  4924. */
  4925. static int bnx2x_int_mem_test(struct bnx2x *bp)
  4926. {
  4927. int factor;
  4928. int count, i;
  4929. u32 val = 0;
  4930. if (CHIP_REV_IS_FPGA(bp))
  4931. factor = 120;
  4932. else if (CHIP_REV_IS_EMUL(bp))
  4933. factor = 200;
  4934. else
  4935. factor = 1;
  4936. /* Disable inputs of parser neighbor blocks */
  4937. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  4938. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  4939. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  4940. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  4941. /* Write 0 to parser credits for CFC search request */
  4942. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  4943. /* send Ethernet packet */
  4944. bnx2x_lb_pckt(bp);
  4945. /* TODO do i reset NIG statistic? */
  4946. /* Wait until NIG register shows 1 packet of size 0x10 */
  4947. count = 1000 * factor;
  4948. while (count) {
  4949. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  4950. val = *bnx2x_sp(bp, wb_data[0]);
  4951. if (val == 0x10)
  4952. break;
  4953. msleep(10);
  4954. count--;
  4955. }
  4956. if (val != 0x10) {
  4957. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  4958. return -1;
  4959. }
  4960. /* Wait until PRS register shows 1 packet */
  4961. count = 1000 * factor;
  4962. while (count) {
  4963. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  4964. if (val == 1)
  4965. break;
  4966. msleep(10);
  4967. count--;
  4968. }
  4969. if (val != 0x1) {
  4970. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  4971. return -2;
  4972. }
  4973. /* Reset and init BRB, PRS */
  4974. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  4975. msleep(50);
  4976. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  4977. msleep(50);
  4978. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  4979. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  4980. DP(NETIF_MSG_HW, "part2\n");
  4981. /* Disable inputs of parser neighbor blocks */
  4982. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  4983. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  4984. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  4985. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  4986. /* Write 0 to parser credits for CFC search request */
  4987. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  4988. /* send 10 Ethernet packets */
  4989. for (i = 0; i < 10; i++)
  4990. bnx2x_lb_pckt(bp);
  4991. /* Wait until NIG register shows 10 + 1
  4992. packets of size 11*0x10 = 0xb0 */
  4993. count = 1000 * factor;
  4994. while (count) {
  4995. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  4996. val = *bnx2x_sp(bp, wb_data[0]);
  4997. if (val == 0xb0)
  4998. break;
  4999. msleep(10);
  5000. count--;
  5001. }
  5002. if (val != 0xb0) {
  5003. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5004. return -3;
  5005. }
  5006. /* Wait until PRS register shows 2 packets */
  5007. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5008. if (val != 2)
  5009. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5010. /* Write 1 to parser credits for CFC search request */
  5011. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  5012. /* Wait until PRS register shows 3 packets */
  5013. msleep(10 * factor);
  5014. /* Wait until NIG register shows 1 packet of size 0x10 */
  5015. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5016. if (val != 3)
  5017. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5018. /* clear NIG EOP FIFO */
  5019. for (i = 0; i < 11; i++)
  5020. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  5021. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  5022. if (val != 1) {
  5023. BNX2X_ERR("clear of NIG failed\n");
  5024. return -4;
  5025. }
  5026. /* Reset and init BRB, PRS, NIG */
  5027. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5028. msleep(50);
  5029. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5030. msleep(50);
  5031. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5032. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5033. #ifndef BCM_CNIC
  5034. /* set NIC mode */
  5035. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5036. #endif
  5037. /* Enable inputs of parser neighbor blocks */
  5038. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  5039. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  5040. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  5041. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  5042. DP(NETIF_MSG_HW, "done\n");
  5043. return 0; /* OK */
  5044. }
  5045. static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
  5046. {
  5047. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5048. if (!CHIP_IS_E1x(bp))
  5049. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
  5050. else
  5051. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  5052. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5053. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5054. /*
  5055. * mask read length error interrupts in brb for parser
  5056. * (parsing unit and 'checksum and crc' unit)
  5057. * these errors are legal (PU reads fixed length and CAC can cause
  5058. * read length error on truncated packets)
  5059. */
  5060. REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
  5061. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  5062. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  5063. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  5064. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  5065. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  5066. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  5067. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  5068. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  5069. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  5070. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  5071. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  5072. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  5073. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  5074. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  5075. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  5076. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  5077. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  5078. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  5079. if (CHIP_REV_IS_FPGA(bp))
  5080. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x580000);
  5081. else if (!CHIP_IS_E1x(bp))
  5082. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0,
  5083. (PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF
  5084. | PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT
  5085. | PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN
  5086. | PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED
  5087. | PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED));
  5088. else
  5089. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x480000);
  5090. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  5091. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  5092. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  5093. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  5094. if (!CHIP_IS_E1x(bp))
  5095. /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
  5096. REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
  5097. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  5098. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  5099. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  5100. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
  5101. }
  5102. static void bnx2x_reset_common(struct bnx2x *bp)
  5103. {
  5104. u32 val = 0x1400;
  5105. /* reset_common */
  5106. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5107. 0xd3ffff7f);
  5108. if (CHIP_IS_E3(bp)) {
  5109. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5110. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5111. }
  5112. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
  5113. }
  5114. static void bnx2x_setup_dmae(struct bnx2x *bp)
  5115. {
  5116. bp->dmae_ready = 0;
  5117. spin_lock_init(&bp->dmae_lock);
  5118. }
  5119. static void bnx2x_init_pxp(struct bnx2x *bp)
  5120. {
  5121. u16 devctl;
  5122. int r_order, w_order;
  5123. pci_read_config_word(bp->pdev,
  5124. pci_pcie_cap(bp->pdev) + PCI_EXP_DEVCTL, &devctl);
  5125. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  5126. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  5127. if (bp->mrrs == -1)
  5128. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  5129. else {
  5130. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  5131. r_order = bp->mrrs;
  5132. }
  5133. bnx2x_init_pxp_arb(bp, r_order, w_order);
  5134. }
  5135. static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
  5136. {
  5137. int is_required;
  5138. u32 val;
  5139. int port;
  5140. if (BP_NOMCP(bp))
  5141. return;
  5142. is_required = 0;
  5143. val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  5144. SHARED_HW_CFG_FAN_FAILURE_MASK;
  5145. if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
  5146. is_required = 1;
  5147. /*
  5148. * The fan failure mechanism is usually related to the PHY type since
  5149. * the power consumption of the board is affected by the PHY. Currently,
  5150. * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
  5151. */
  5152. else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
  5153. for (port = PORT_0; port < PORT_MAX; port++) {
  5154. is_required |=
  5155. bnx2x_fan_failure_det_req(
  5156. bp,
  5157. bp->common.shmem_base,
  5158. bp->common.shmem2_base,
  5159. port);
  5160. }
  5161. DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
  5162. if (is_required == 0)
  5163. return;
  5164. /* Fan failure is indicated by SPIO 5 */
  5165. bnx2x_set_spio(bp, MISC_REGISTERS_SPIO_5,
  5166. MISC_REGISTERS_SPIO_INPUT_HI_Z);
  5167. /* set to active low mode */
  5168. val = REG_RD(bp, MISC_REG_SPIO_INT);
  5169. val |= ((1 << MISC_REGISTERS_SPIO_5) <<
  5170. MISC_REGISTERS_SPIO_INT_OLD_SET_POS);
  5171. REG_WR(bp, MISC_REG_SPIO_INT, val);
  5172. /* enable interrupt to signal the IGU */
  5173. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5174. val |= (1 << MISC_REGISTERS_SPIO_5);
  5175. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  5176. }
  5177. static void bnx2x_pretend_func(struct bnx2x *bp, u8 pretend_func_num)
  5178. {
  5179. u32 offset = 0;
  5180. if (CHIP_IS_E1(bp))
  5181. return;
  5182. if (CHIP_IS_E1H(bp) && (pretend_func_num >= E1H_FUNC_MAX))
  5183. return;
  5184. switch (BP_ABS_FUNC(bp)) {
  5185. case 0:
  5186. offset = PXP2_REG_PGL_PRETEND_FUNC_F0;
  5187. break;
  5188. case 1:
  5189. offset = PXP2_REG_PGL_PRETEND_FUNC_F1;
  5190. break;
  5191. case 2:
  5192. offset = PXP2_REG_PGL_PRETEND_FUNC_F2;
  5193. break;
  5194. case 3:
  5195. offset = PXP2_REG_PGL_PRETEND_FUNC_F3;
  5196. break;
  5197. case 4:
  5198. offset = PXP2_REG_PGL_PRETEND_FUNC_F4;
  5199. break;
  5200. case 5:
  5201. offset = PXP2_REG_PGL_PRETEND_FUNC_F5;
  5202. break;
  5203. case 6:
  5204. offset = PXP2_REG_PGL_PRETEND_FUNC_F6;
  5205. break;
  5206. case 7:
  5207. offset = PXP2_REG_PGL_PRETEND_FUNC_F7;
  5208. break;
  5209. default:
  5210. return;
  5211. }
  5212. REG_WR(bp, offset, pretend_func_num);
  5213. REG_RD(bp, offset);
  5214. DP(NETIF_MSG_HW, "Pretending to func %d\n", pretend_func_num);
  5215. }
  5216. void bnx2x_pf_disable(struct bnx2x *bp)
  5217. {
  5218. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  5219. val &= ~IGU_PF_CONF_FUNC_EN;
  5220. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  5221. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5222. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
  5223. }
  5224. static void bnx2x__common_init_phy(struct bnx2x *bp)
  5225. {
  5226. u32 shmem_base[2], shmem2_base[2];
  5227. shmem_base[0] = bp->common.shmem_base;
  5228. shmem2_base[0] = bp->common.shmem2_base;
  5229. if (!CHIP_IS_E1x(bp)) {
  5230. shmem_base[1] =
  5231. SHMEM2_RD(bp, other_shmem_base_addr);
  5232. shmem2_base[1] =
  5233. SHMEM2_RD(bp, other_shmem2_base_addr);
  5234. }
  5235. bnx2x_acquire_phy_lock(bp);
  5236. bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
  5237. bp->common.chip_id);
  5238. bnx2x_release_phy_lock(bp);
  5239. }
  5240. /**
  5241. * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
  5242. *
  5243. * @bp: driver handle
  5244. */
  5245. static int bnx2x_init_hw_common(struct bnx2x *bp)
  5246. {
  5247. u32 val;
  5248. DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
  5249. /*
  5250. * take the UNDI lock to protect undi_unload flow from accessing
  5251. * registers while we're resetting the chip
  5252. */
  5253. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5254. bnx2x_reset_common(bp);
  5255. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  5256. val = 0xfffc;
  5257. if (CHIP_IS_E3(bp)) {
  5258. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5259. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5260. }
  5261. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
  5262. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5263. bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
  5264. if (!CHIP_IS_E1x(bp)) {
  5265. u8 abs_func_id;
  5266. /**
  5267. * 4-port mode or 2-port mode we need to turn of master-enable
  5268. * for everyone, after that, turn it back on for self.
  5269. * so, we disregard multi-function or not, and always disable
  5270. * for all functions on the given path, this means 0,2,4,6 for
  5271. * path 0 and 1,3,5,7 for path 1
  5272. */
  5273. for (abs_func_id = BP_PATH(bp);
  5274. abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
  5275. if (abs_func_id == BP_ABS_FUNC(bp)) {
  5276. REG_WR(bp,
  5277. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
  5278. 1);
  5279. continue;
  5280. }
  5281. bnx2x_pretend_func(bp, abs_func_id);
  5282. /* clear pf enable */
  5283. bnx2x_pf_disable(bp);
  5284. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5285. }
  5286. }
  5287. bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
  5288. if (CHIP_IS_E1(bp)) {
  5289. /* enable HW interrupt from PXP on USDM overflow
  5290. bit 16 on INT_MASK_0 */
  5291. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5292. }
  5293. bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
  5294. bnx2x_init_pxp(bp);
  5295. #ifdef __BIG_ENDIAN
  5296. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
  5297. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
  5298. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
  5299. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
  5300. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
  5301. /* make sure this value is 0 */
  5302. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  5303. /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
  5304. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
  5305. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
  5306. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
  5307. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
  5308. #endif
  5309. bnx2x_ilt_init_page_size(bp, INITOP_SET);
  5310. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  5311. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  5312. /* let the HW do it's magic ... */
  5313. msleep(100);
  5314. /* finish PXP init */
  5315. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  5316. if (val != 1) {
  5317. BNX2X_ERR("PXP2 CFG failed\n");
  5318. return -EBUSY;
  5319. }
  5320. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  5321. if (val != 1) {
  5322. BNX2X_ERR("PXP2 RD_INIT failed\n");
  5323. return -EBUSY;
  5324. }
  5325. /* Timers bug workaround E2 only. We need to set the entire ILT to
  5326. * have entries with value "0" and valid bit on.
  5327. * This needs to be done by the first PF that is loaded in a path
  5328. * (i.e. common phase)
  5329. */
  5330. if (!CHIP_IS_E1x(bp)) {
  5331. /* In E2 there is a bug in the timers block that can cause function 6 / 7
  5332. * (i.e. vnic3) to start even if it is marked as "scan-off".
  5333. * This occurs when a different function (func2,3) is being marked
  5334. * as "scan-off". Real-life scenario for example: if a driver is being
  5335. * load-unloaded while func6,7 are down. This will cause the timer to access
  5336. * the ilt, translate to a logical address and send a request to read/write.
  5337. * Since the ilt for the function that is down is not valid, this will cause
  5338. * a translation error which is unrecoverable.
  5339. * The Workaround is intended to make sure that when this happens nothing fatal
  5340. * will occur. The workaround:
  5341. * 1. First PF driver which loads on a path will:
  5342. * a. After taking the chip out of reset, by using pretend,
  5343. * it will write "0" to the following registers of
  5344. * the other vnics.
  5345. * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5346. * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
  5347. * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
  5348. * And for itself it will write '1' to
  5349. * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
  5350. * dmae-operations (writing to pram for example.)
  5351. * note: can be done for only function 6,7 but cleaner this
  5352. * way.
  5353. * b. Write zero+valid to the entire ILT.
  5354. * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
  5355. * VNIC3 (of that port). The range allocated will be the
  5356. * entire ILT. This is needed to prevent ILT range error.
  5357. * 2. Any PF driver load flow:
  5358. * a. ILT update with the physical addresses of the allocated
  5359. * logical pages.
  5360. * b. Wait 20msec. - note that this timeout is needed to make
  5361. * sure there are no requests in one of the PXP internal
  5362. * queues with "old" ILT addresses.
  5363. * c. PF enable in the PGLC.
  5364. * d. Clear the was_error of the PF in the PGLC. (could have
  5365. * occured while driver was down)
  5366. * e. PF enable in the CFC (WEAK + STRONG)
  5367. * f. Timers scan enable
  5368. * 3. PF driver unload flow:
  5369. * a. Clear the Timers scan_en.
  5370. * b. Polling for scan_on=0 for that PF.
  5371. * c. Clear the PF enable bit in the PXP.
  5372. * d. Clear the PF enable in the CFC (WEAK + STRONG)
  5373. * e. Write zero+valid to all ILT entries (The valid bit must
  5374. * stay set)
  5375. * f. If this is VNIC 3 of a port then also init
  5376. * first_timers_ilt_entry to zero and last_timers_ilt_entry
  5377. * to the last enrty in the ILT.
  5378. *
  5379. * Notes:
  5380. * Currently the PF error in the PGLC is non recoverable.
  5381. * In the future the there will be a recovery routine for this error.
  5382. * Currently attention is masked.
  5383. * Having an MCP lock on the load/unload process does not guarantee that
  5384. * there is no Timer disable during Func6/7 enable. This is because the
  5385. * Timers scan is currently being cleared by the MCP on FLR.
  5386. * Step 2.d can be done only for PF6/7 and the driver can also check if
  5387. * there is error before clearing it. But the flow above is simpler and
  5388. * more general.
  5389. * All ILT entries are written by zero+valid and not just PF6/7
  5390. * ILT entries since in the future the ILT entries allocation for
  5391. * PF-s might be dynamic.
  5392. */
  5393. struct ilt_client_info ilt_cli;
  5394. struct bnx2x_ilt ilt;
  5395. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  5396. memset(&ilt, 0, sizeof(struct bnx2x_ilt));
  5397. /* initialize dummy TM client */
  5398. ilt_cli.start = 0;
  5399. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  5400. ilt_cli.client_num = ILT_CLIENT_TM;
  5401. /* Step 1: set zeroes to all ilt page entries with valid bit on
  5402. * Step 2: set the timers first/last ilt entry to point
  5403. * to the entire range to prevent ILT range error for 3rd/4th
  5404. * vnic (this code assumes existance of the vnic)
  5405. *
  5406. * both steps performed by call to bnx2x_ilt_client_init_op()
  5407. * with dummy TM client
  5408. *
  5409. * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
  5410. * and his brother are split registers
  5411. */
  5412. bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
  5413. bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
  5414. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5415. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
  5416. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
  5417. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
  5418. }
  5419. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  5420. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  5421. if (!CHIP_IS_E1x(bp)) {
  5422. int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
  5423. (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
  5424. bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
  5425. bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
  5426. /* let the HW do it's magic ... */
  5427. do {
  5428. msleep(200);
  5429. val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
  5430. } while (factor-- && (val != 1));
  5431. if (val != 1) {
  5432. BNX2X_ERR("ATC_INIT failed\n");
  5433. return -EBUSY;
  5434. }
  5435. }
  5436. bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
  5437. /* clean the DMAE memory */
  5438. bp->dmae_ready = 1;
  5439. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
  5440. bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
  5441. bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
  5442. bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
  5443. bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
  5444. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  5445. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  5446. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  5447. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  5448. bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
  5449. /* QM queues pointers table */
  5450. bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
  5451. /* soft reset pulse */
  5452. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  5453. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  5454. #ifdef BCM_CNIC
  5455. bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
  5456. #endif
  5457. bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
  5458. REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT);
  5459. if (!CHIP_REV_IS_SLOW(bp))
  5460. /* enable hw interrupt from doorbell Q */
  5461. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5462. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5463. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5464. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  5465. if (!CHIP_IS_E1(bp))
  5466. REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
  5467. if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
  5468. if (IS_MF_AFEX(bp)) {
  5469. /* configure that VNTag and VLAN headers must be
  5470. * received in afex mode
  5471. */
  5472. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
  5473. REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
  5474. REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
  5475. REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
  5476. REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
  5477. } else {
  5478. /* Bit-map indicating which L2 hdrs may appear
  5479. * after the basic Ethernet header
  5480. */
  5481. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
  5482. bp->path_has_ovlan ? 7 : 6);
  5483. }
  5484. }
  5485. bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
  5486. bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
  5487. bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
  5488. bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
  5489. if (!CHIP_IS_E1x(bp)) {
  5490. /* reset VFC memories */
  5491. REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5492. VFC_MEMORIES_RST_REG_CAM_RST |
  5493. VFC_MEMORIES_RST_REG_RAM_RST);
  5494. REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5495. VFC_MEMORIES_RST_REG_CAM_RST |
  5496. VFC_MEMORIES_RST_REG_RAM_RST);
  5497. msleep(20);
  5498. }
  5499. bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
  5500. bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
  5501. bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
  5502. bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
  5503. /* sync semi rtc */
  5504. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5505. 0x80000000);
  5506. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  5507. 0x80000000);
  5508. bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
  5509. bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
  5510. bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
  5511. if (!CHIP_IS_E1x(bp)) {
  5512. if (IS_MF_AFEX(bp)) {
  5513. /* configure that VNTag and VLAN headers must be
  5514. * sent in afex mode
  5515. */
  5516. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
  5517. REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
  5518. REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
  5519. REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
  5520. REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
  5521. } else {
  5522. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
  5523. bp->path_has_ovlan ? 7 : 6);
  5524. }
  5525. }
  5526. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  5527. bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
  5528. #ifdef BCM_CNIC
  5529. REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
  5530. REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
  5531. REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
  5532. REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
  5533. REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
  5534. REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
  5535. REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
  5536. REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
  5537. REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
  5538. REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
  5539. #endif
  5540. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  5541. if (sizeof(union cdu_context) != 1024)
  5542. /* we currently assume that a context is 1024 bytes */
  5543. dev_alert(&bp->pdev->dev,
  5544. "please adjust the size of cdu_context(%ld)\n",
  5545. (long)sizeof(union cdu_context));
  5546. bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
  5547. val = (4 << 24) + (0 << 12) + 1024;
  5548. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  5549. bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
  5550. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  5551. /* enable context validation interrupt from CFC */
  5552. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5553. /* set the thresholds to prevent CFC/CDU race */
  5554. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  5555. bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
  5556. if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
  5557. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
  5558. bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
  5559. bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
  5560. /* Reset PCIE errors for debug */
  5561. REG_WR(bp, 0x2814, 0xffffffff);
  5562. REG_WR(bp, 0x3820, 0xffffffff);
  5563. if (!CHIP_IS_E1x(bp)) {
  5564. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
  5565. (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
  5566. PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
  5567. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
  5568. (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
  5569. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
  5570. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
  5571. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
  5572. (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
  5573. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
  5574. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
  5575. }
  5576. bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
  5577. if (!CHIP_IS_E1(bp)) {
  5578. /* in E3 this done in per-port section */
  5579. if (!CHIP_IS_E3(bp))
  5580. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5581. }
  5582. if (CHIP_IS_E1H(bp))
  5583. /* not applicable for E2 (and above ...) */
  5584. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
  5585. if (CHIP_REV_IS_SLOW(bp))
  5586. msleep(200);
  5587. /* finish CFC init */
  5588. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  5589. if (val != 1) {
  5590. BNX2X_ERR("CFC LL_INIT failed\n");
  5591. return -EBUSY;
  5592. }
  5593. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  5594. if (val != 1) {
  5595. BNX2X_ERR("CFC AC_INIT failed\n");
  5596. return -EBUSY;
  5597. }
  5598. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  5599. if (val != 1) {
  5600. BNX2X_ERR("CFC CAM_INIT failed\n");
  5601. return -EBUSY;
  5602. }
  5603. REG_WR(bp, CFC_REG_DEBUG0, 0);
  5604. if (CHIP_IS_E1(bp)) {
  5605. /* read NIG statistic
  5606. to see if this is our first up since powerup */
  5607. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5608. val = *bnx2x_sp(bp, wb_data[0]);
  5609. /* do internal memory self test */
  5610. if ((val == 0) && bnx2x_int_mem_test(bp)) {
  5611. BNX2X_ERR("internal mem self test failed\n");
  5612. return -EBUSY;
  5613. }
  5614. }
  5615. bnx2x_setup_fan_failure_detection(bp);
  5616. /* clear PXP2 attentions */
  5617. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  5618. bnx2x_enable_blocks_attention(bp);
  5619. bnx2x_enable_blocks_parity(bp);
  5620. if (!BP_NOMCP(bp)) {
  5621. if (CHIP_IS_E1x(bp))
  5622. bnx2x__common_init_phy(bp);
  5623. } else
  5624. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  5625. return 0;
  5626. }
  5627. /**
  5628. * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
  5629. *
  5630. * @bp: driver handle
  5631. */
  5632. static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
  5633. {
  5634. int rc = bnx2x_init_hw_common(bp);
  5635. if (rc)
  5636. return rc;
  5637. /* In E2 2-PORT mode, same ext phy is used for the two paths */
  5638. if (!BP_NOMCP(bp))
  5639. bnx2x__common_init_phy(bp);
  5640. return 0;
  5641. }
  5642. static int bnx2x_init_hw_port(struct bnx2x *bp)
  5643. {
  5644. int port = BP_PORT(bp);
  5645. int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
  5646. u32 low, high;
  5647. u32 val;
  5648. bnx2x__link_reset(bp);
  5649. DP(NETIF_MSG_HW, "starting port init port %d\n", port);
  5650. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  5651. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  5652. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  5653. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  5654. /* Timers bug workaround: disables the pf_master bit in pglue at
  5655. * common phase, we need to enable it here before any dmae access are
  5656. * attempted. Therefore we manually added the enable-master to the
  5657. * port phase (it also happens in the function phase)
  5658. */
  5659. if (!CHIP_IS_E1x(bp))
  5660. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  5661. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  5662. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  5663. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  5664. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  5665. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  5666. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  5667. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  5668. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  5669. /* QM cid (connection) count */
  5670. bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
  5671. #ifdef BCM_CNIC
  5672. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  5673. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
  5674. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
  5675. #endif
  5676. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  5677. if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
  5678. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  5679. if (IS_MF(bp))
  5680. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  5681. else if (bp->dev->mtu > 4096) {
  5682. if (bp->flags & ONE_PORT_FLAG)
  5683. low = 160;
  5684. else {
  5685. val = bp->dev->mtu;
  5686. /* (24*1024 + val*4)/256 */
  5687. low = 96 + (val/64) +
  5688. ((val % 64) ? 1 : 0);
  5689. }
  5690. } else
  5691. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  5692. high = low + 56; /* 14*1024/256 */
  5693. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  5694. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  5695. }
  5696. if (CHIP_MODE_IS_4_PORT(bp))
  5697. REG_WR(bp, (BP_PORT(bp) ?
  5698. BRB1_REG_MAC_GUARANTIED_1 :
  5699. BRB1_REG_MAC_GUARANTIED_0), 40);
  5700. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  5701. if (CHIP_IS_E3B0(bp)) {
  5702. if (IS_MF_AFEX(bp)) {
  5703. /* configure headers for AFEX mode */
  5704. REG_WR(bp, BP_PORT(bp) ?
  5705. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  5706. PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
  5707. REG_WR(bp, BP_PORT(bp) ?
  5708. PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
  5709. PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
  5710. REG_WR(bp, BP_PORT(bp) ?
  5711. PRS_REG_MUST_HAVE_HDRS_PORT_1 :
  5712. PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
  5713. } else {
  5714. /* Ovlan exists only if we are in multi-function +
  5715. * switch-dependent mode, in switch-independent there
  5716. * is no ovlan headers
  5717. */
  5718. REG_WR(bp, BP_PORT(bp) ?
  5719. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  5720. PRS_REG_HDRS_AFTER_BASIC_PORT_0,
  5721. (bp->path_has_ovlan ? 7 : 6));
  5722. }
  5723. }
  5724. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  5725. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  5726. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  5727. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  5728. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  5729. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  5730. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  5731. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  5732. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  5733. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  5734. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  5735. if (CHIP_IS_E1x(bp)) {
  5736. /* configure PBF to work without PAUSE mtu 9000 */
  5737. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  5738. /* update threshold */
  5739. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  5740. /* update init credit */
  5741. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  5742. /* probe changes */
  5743. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  5744. udelay(50);
  5745. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  5746. }
  5747. #ifdef BCM_CNIC
  5748. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  5749. #endif
  5750. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  5751. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  5752. if (CHIP_IS_E1(bp)) {
  5753. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  5754. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  5755. }
  5756. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  5757. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  5758. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  5759. /* init aeu_mask_attn_func_0/1:
  5760. * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
  5761. * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
  5762. * bits 4-7 are used for "per vn group attention" */
  5763. val = IS_MF(bp) ? 0xF7 : 0x7;
  5764. /* Enable DCBX attention for all but E1 */
  5765. val |= CHIP_IS_E1(bp) ? 0 : 0x10;
  5766. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
  5767. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  5768. if (!CHIP_IS_E1x(bp)) {
  5769. /* Bit-map indicating which L2 hdrs may appear after the
  5770. * basic Ethernet header
  5771. */
  5772. if (IS_MF_AFEX(bp))
  5773. REG_WR(bp, BP_PORT(bp) ?
  5774. NIG_REG_P1_HDRS_AFTER_BASIC :
  5775. NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
  5776. else
  5777. REG_WR(bp, BP_PORT(bp) ?
  5778. NIG_REG_P1_HDRS_AFTER_BASIC :
  5779. NIG_REG_P0_HDRS_AFTER_BASIC,
  5780. IS_MF_SD(bp) ? 7 : 6);
  5781. if (CHIP_IS_E3(bp))
  5782. REG_WR(bp, BP_PORT(bp) ?
  5783. NIG_REG_LLH1_MF_MODE :
  5784. NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5785. }
  5786. if (!CHIP_IS_E3(bp))
  5787. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  5788. if (!CHIP_IS_E1(bp)) {
  5789. /* 0x2 disable mf_ov, 0x1 enable */
  5790. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  5791. (IS_MF_SD(bp) ? 0x1 : 0x2));
  5792. if (!CHIP_IS_E1x(bp)) {
  5793. val = 0;
  5794. switch (bp->mf_mode) {
  5795. case MULTI_FUNCTION_SD:
  5796. val = 1;
  5797. break;
  5798. case MULTI_FUNCTION_SI:
  5799. case MULTI_FUNCTION_AFEX:
  5800. val = 2;
  5801. break;
  5802. }
  5803. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
  5804. NIG_REG_LLH0_CLS_TYPE), val);
  5805. }
  5806. {
  5807. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  5808. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  5809. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  5810. }
  5811. }
  5812. /* If SPIO5 is set to generate interrupts, enable it for this port */
  5813. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5814. if (val & (1 << MISC_REGISTERS_SPIO_5)) {
  5815. u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  5816. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  5817. val = REG_RD(bp, reg_addr);
  5818. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  5819. REG_WR(bp, reg_addr, val);
  5820. }
  5821. return 0;
  5822. }
  5823. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  5824. {
  5825. int reg;
  5826. u32 wb_write[2];
  5827. if (CHIP_IS_E1(bp))
  5828. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  5829. else
  5830. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  5831. wb_write[0] = ONCHIP_ADDR1(addr);
  5832. wb_write[1] = ONCHIP_ADDR2(addr);
  5833. REG_WR_DMAE(bp, reg, wb_write, 2);
  5834. }
  5835. static void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func,
  5836. u8 idu_sb_id, bool is_Pf)
  5837. {
  5838. u32 data, ctl, cnt = 100;
  5839. u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
  5840. u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
  5841. u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
  5842. u32 sb_bit = 1 << (idu_sb_id%32);
  5843. u32 func_encode = func | (is_Pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
  5844. u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
  5845. /* Not supported in BC mode */
  5846. if (CHIP_INT_MODE_IS_BC(bp))
  5847. return;
  5848. data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
  5849. << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
  5850. IGU_REGULAR_CLEANUP_SET |
  5851. IGU_REGULAR_BCLEANUP;
  5852. ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
  5853. func_encode << IGU_CTRL_REG_FID_SHIFT |
  5854. IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
  5855. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  5856. data, igu_addr_data);
  5857. REG_WR(bp, igu_addr_data, data);
  5858. mmiowb();
  5859. barrier();
  5860. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  5861. ctl, igu_addr_ctl);
  5862. REG_WR(bp, igu_addr_ctl, ctl);
  5863. mmiowb();
  5864. barrier();
  5865. /* wait for clean up to finish */
  5866. while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
  5867. msleep(20);
  5868. if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
  5869. DP(NETIF_MSG_HW,
  5870. "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
  5871. idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
  5872. }
  5873. }
  5874. static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
  5875. {
  5876. bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
  5877. }
  5878. static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
  5879. {
  5880. u32 i, base = FUNC_ILT_BASE(func);
  5881. for (i = base; i < base + ILT_PER_FUNC; i++)
  5882. bnx2x_ilt_wr(bp, i, 0);
  5883. }
  5884. static int bnx2x_init_hw_func(struct bnx2x *bp)
  5885. {
  5886. int port = BP_PORT(bp);
  5887. int func = BP_FUNC(bp);
  5888. int init_phase = PHASE_PF0 + func;
  5889. struct bnx2x_ilt *ilt = BP_ILT(bp);
  5890. u16 cdu_ilt_start;
  5891. u32 addr, val;
  5892. u32 main_mem_base, main_mem_size, main_mem_prty_clr;
  5893. int i, main_mem_width, rc;
  5894. DP(NETIF_MSG_HW, "starting func init func %d\n", func);
  5895. /* FLR cleanup - hmmm */
  5896. if (!CHIP_IS_E1x(bp)) {
  5897. rc = bnx2x_pf_flr_clnup(bp);
  5898. if (rc)
  5899. return rc;
  5900. }
  5901. /* set MSI reconfigure capability */
  5902. if (bp->common.int_block == INT_BLOCK_HC) {
  5903. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  5904. val = REG_RD(bp, addr);
  5905. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  5906. REG_WR(bp, addr, val);
  5907. }
  5908. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  5909. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  5910. ilt = BP_ILT(bp);
  5911. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  5912. for (i = 0; i < L2_ILT_LINES(bp); i++) {
  5913. ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
  5914. ilt->lines[cdu_ilt_start + i].page_mapping =
  5915. bp->context[i].cxt_mapping;
  5916. ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
  5917. }
  5918. bnx2x_ilt_init_op(bp, INITOP_SET);
  5919. #ifdef BCM_CNIC
  5920. bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
  5921. /* T1 hash bits value determines the T1 number of entries */
  5922. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
  5923. #endif
  5924. #ifndef BCM_CNIC
  5925. /* set NIC mode */
  5926. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5927. #endif /* BCM_CNIC */
  5928. if (!CHIP_IS_E1x(bp)) {
  5929. u32 pf_conf = IGU_PF_CONF_FUNC_EN;
  5930. /* Turn on a single ISR mode in IGU if driver is going to use
  5931. * INT#x or MSI
  5932. */
  5933. if (!(bp->flags & USING_MSIX_FLAG))
  5934. pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  5935. /*
  5936. * Timers workaround bug: function init part.
  5937. * Need to wait 20msec after initializing ILT,
  5938. * needed to make sure there are no requests in
  5939. * one of the PXP internal queues with "old" ILT addresses
  5940. */
  5941. msleep(20);
  5942. /*
  5943. * Master enable - Due to WB DMAE writes performed before this
  5944. * register is re-initialized as part of the regular function
  5945. * init
  5946. */
  5947. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  5948. /* Enable the function in IGU */
  5949. REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
  5950. }
  5951. bp->dmae_ready = 1;
  5952. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  5953. if (!CHIP_IS_E1x(bp))
  5954. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
  5955. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  5956. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  5957. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  5958. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  5959. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  5960. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  5961. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  5962. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  5963. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  5964. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  5965. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  5966. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  5967. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  5968. if (!CHIP_IS_E1x(bp))
  5969. REG_WR(bp, QM_REG_PF_EN, 1);
  5970. if (!CHIP_IS_E1x(bp)) {
  5971. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  5972. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  5973. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  5974. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  5975. }
  5976. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  5977. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  5978. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  5979. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  5980. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  5981. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  5982. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  5983. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  5984. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  5985. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  5986. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  5987. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  5988. if (!CHIP_IS_E1x(bp))
  5989. REG_WR(bp, PBF_REG_DISABLE_PF, 0);
  5990. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  5991. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  5992. if (!CHIP_IS_E1x(bp))
  5993. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
  5994. if (IS_MF(bp)) {
  5995. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  5996. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
  5997. }
  5998. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  5999. /* HC init per function */
  6000. if (bp->common.int_block == INT_BLOCK_HC) {
  6001. if (CHIP_IS_E1H(bp)) {
  6002. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6003. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6004. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6005. }
  6006. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6007. } else {
  6008. int num_segs, sb_idx, prod_offset;
  6009. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6010. if (!CHIP_IS_E1x(bp)) {
  6011. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6012. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6013. }
  6014. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6015. if (!CHIP_IS_E1x(bp)) {
  6016. int dsb_idx = 0;
  6017. /**
  6018. * Producer memory:
  6019. * E2 mode: address 0-135 match to the mapping memory;
  6020. * 136 - PF0 default prod; 137 - PF1 default prod;
  6021. * 138 - PF2 default prod; 139 - PF3 default prod;
  6022. * 140 - PF0 attn prod; 141 - PF1 attn prod;
  6023. * 142 - PF2 attn prod; 143 - PF3 attn prod;
  6024. * 144-147 reserved.
  6025. *
  6026. * E1.5 mode - In backward compatible mode;
  6027. * for non default SB; each even line in the memory
  6028. * holds the U producer and each odd line hold
  6029. * the C producer. The first 128 producers are for
  6030. * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
  6031. * producers are for the DSB for each PF.
  6032. * Each PF has five segments: (the order inside each
  6033. * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
  6034. * 132-135 C prods; 136-139 X prods; 140-143 T prods;
  6035. * 144-147 attn prods;
  6036. */
  6037. /* non-default-status-blocks */
  6038. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6039. IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
  6040. for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
  6041. prod_offset = (bp->igu_base_sb + sb_idx) *
  6042. num_segs;
  6043. for (i = 0; i < num_segs; i++) {
  6044. addr = IGU_REG_PROD_CONS_MEMORY +
  6045. (prod_offset + i) * 4;
  6046. REG_WR(bp, addr, 0);
  6047. }
  6048. /* send consumer update with value 0 */
  6049. bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
  6050. USTORM_ID, 0, IGU_INT_NOP, 1);
  6051. bnx2x_igu_clear_sb(bp,
  6052. bp->igu_base_sb + sb_idx);
  6053. }
  6054. /* default-status-blocks */
  6055. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6056. IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
  6057. if (CHIP_MODE_IS_4_PORT(bp))
  6058. dsb_idx = BP_FUNC(bp);
  6059. else
  6060. dsb_idx = BP_VN(bp);
  6061. prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
  6062. IGU_BC_BASE_DSB_PROD + dsb_idx :
  6063. IGU_NORM_BASE_DSB_PROD + dsb_idx);
  6064. /*
  6065. * igu prods come in chunks of E1HVN_MAX (4) -
  6066. * does not matters what is the current chip mode
  6067. */
  6068. for (i = 0; i < (num_segs * E1HVN_MAX);
  6069. i += E1HVN_MAX) {
  6070. addr = IGU_REG_PROD_CONS_MEMORY +
  6071. (prod_offset + i)*4;
  6072. REG_WR(bp, addr, 0);
  6073. }
  6074. /* send consumer update with 0 */
  6075. if (CHIP_INT_MODE_IS_BC(bp)) {
  6076. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6077. USTORM_ID, 0, IGU_INT_NOP, 1);
  6078. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6079. CSTORM_ID, 0, IGU_INT_NOP, 1);
  6080. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6081. XSTORM_ID, 0, IGU_INT_NOP, 1);
  6082. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6083. TSTORM_ID, 0, IGU_INT_NOP, 1);
  6084. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6085. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6086. } else {
  6087. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6088. USTORM_ID, 0, IGU_INT_NOP, 1);
  6089. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6090. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6091. }
  6092. bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
  6093. /* !!! these should become driver const once
  6094. rf-tool supports split-68 const */
  6095. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  6096. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  6097. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  6098. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  6099. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  6100. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  6101. }
  6102. }
  6103. /* Reset PCIE errors for debug */
  6104. REG_WR(bp, 0x2114, 0xffffffff);
  6105. REG_WR(bp, 0x2120, 0xffffffff);
  6106. if (CHIP_IS_E1x(bp)) {
  6107. main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
  6108. main_mem_base = HC_REG_MAIN_MEMORY +
  6109. BP_PORT(bp) * (main_mem_size * 4);
  6110. main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
  6111. main_mem_width = 8;
  6112. val = REG_RD(bp, main_mem_prty_clr);
  6113. if (val)
  6114. DP(NETIF_MSG_HW,
  6115. "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
  6116. val);
  6117. /* Clear "false" parity errors in MSI-X table */
  6118. for (i = main_mem_base;
  6119. i < main_mem_base + main_mem_size * 4;
  6120. i += main_mem_width) {
  6121. bnx2x_read_dmae(bp, i, main_mem_width / 4);
  6122. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
  6123. i, main_mem_width / 4);
  6124. }
  6125. /* Clear HC parity attention */
  6126. REG_RD(bp, main_mem_prty_clr);
  6127. }
  6128. #ifdef BNX2X_STOP_ON_ERROR
  6129. /* Enable STORMs SP logging */
  6130. REG_WR8(bp, BAR_USTRORM_INTMEM +
  6131. USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6132. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  6133. TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6134. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6135. CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6136. REG_WR8(bp, BAR_XSTRORM_INTMEM +
  6137. XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6138. #endif
  6139. bnx2x_phy_probe(&bp->link_params);
  6140. return 0;
  6141. }
  6142. void bnx2x_free_mem(struct bnx2x *bp)
  6143. {
  6144. int i;
  6145. /* fastpath */
  6146. bnx2x_free_fp_mem(bp);
  6147. /* end of fastpath */
  6148. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  6149. sizeof(struct host_sp_status_block));
  6150. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6151. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6152. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  6153. sizeof(struct bnx2x_slowpath));
  6154. for (i = 0; i < L2_ILT_LINES(bp); i++)
  6155. BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
  6156. bp->context[i].size);
  6157. bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
  6158. BNX2X_FREE(bp->ilt->lines);
  6159. #ifdef BCM_CNIC
  6160. if (!CHIP_IS_E1x(bp))
  6161. BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
  6162. sizeof(struct host_hc_status_block_e2));
  6163. else
  6164. BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
  6165. sizeof(struct host_hc_status_block_e1x));
  6166. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6167. #endif
  6168. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  6169. BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
  6170. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6171. }
  6172. static int bnx2x_alloc_fw_stats_mem(struct bnx2x *bp)
  6173. {
  6174. int num_groups;
  6175. int is_fcoe_stats = NO_FCOE(bp) ? 0 : 1;
  6176. /* number of queues for statistics is number of eth queues + FCoE */
  6177. u8 num_queue_stats = BNX2X_NUM_ETH_QUEUES(bp) + is_fcoe_stats;
  6178. /* Total number of FW statistics requests =
  6179. * 1 for port stats + 1 for PF stats + potential 1 for FCoE stats +
  6180. * num of queues
  6181. */
  6182. bp->fw_stats_num = 2 + is_fcoe_stats + num_queue_stats;
  6183. /* Request is built from stats_query_header and an array of
  6184. * stats_query_cmd_group each of which contains
  6185. * STATS_QUERY_CMD_COUNT rules. The real number or requests is
  6186. * configured in the stats_query_header.
  6187. */
  6188. num_groups = ((bp->fw_stats_num) / STATS_QUERY_CMD_COUNT) +
  6189. (((bp->fw_stats_num) % STATS_QUERY_CMD_COUNT) ? 1 : 0);
  6190. bp->fw_stats_req_sz = sizeof(struct stats_query_header) +
  6191. num_groups * sizeof(struct stats_query_cmd_group);
  6192. /* Data for statistics requests + stats_conter
  6193. *
  6194. * stats_counter holds per-STORM counters that are incremented
  6195. * when STORM has finished with the current request.
  6196. *
  6197. * memory for FCoE offloaded statistics are counted anyway,
  6198. * even if they will not be sent.
  6199. */
  6200. bp->fw_stats_data_sz = sizeof(struct per_port_stats) +
  6201. sizeof(struct per_pf_stats) +
  6202. sizeof(struct fcoe_statistics_params) +
  6203. sizeof(struct per_queue_stats) * num_queue_stats +
  6204. sizeof(struct stats_counter);
  6205. BNX2X_PCI_ALLOC(bp->fw_stats, &bp->fw_stats_mapping,
  6206. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6207. /* Set shortcuts */
  6208. bp->fw_stats_req = (struct bnx2x_fw_stats_req *)bp->fw_stats;
  6209. bp->fw_stats_req_mapping = bp->fw_stats_mapping;
  6210. bp->fw_stats_data = (struct bnx2x_fw_stats_data *)
  6211. ((u8 *)bp->fw_stats + bp->fw_stats_req_sz);
  6212. bp->fw_stats_data_mapping = bp->fw_stats_mapping +
  6213. bp->fw_stats_req_sz;
  6214. return 0;
  6215. alloc_mem_err:
  6216. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6217. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6218. BNX2X_ERR("Can't allocate memory\n");
  6219. return -ENOMEM;
  6220. }
  6221. int bnx2x_alloc_mem(struct bnx2x *bp)
  6222. {
  6223. int i, allocated, context_size;
  6224. #ifdef BCM_CNIC
  6225. if (!CHIP_IS_E1x(bp))
  6226. /* size = the status block + ramrod buffers */
  6227. BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
  6228. sizeof(struct host_hc_status_block_e2));
  6229. else
  6230. BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb, &bp->cnic_sb_mapping,
  6231. sizeof(struct host_hc_status_block_e1x));
  6232. /* allocate searcher T2 table */
  6233. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6234. #endif
  6235. BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
  6236. sizeof(struct host_sp_status_block));
  6237. BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
  6238. sizeof(struct bnx2x_slowpath));
  6239. #ifdef BCM_CNIC
  6240. /* write address to which L5 should insert its values */
  6241. bp->cnic_eth_dev.addr_drv_info_to_mcp = &bp->slowpath->drv_info_to_mcp;
  6242. #endif
  6243. /* Allocated memory for FW statistics */
  6244. if (bnx2x_alloc_fw_stats_mem(bp))
  6245. goto alloc_mem_err;
  6246. /* Allocate memory for CDU context:
  6247. * This memory is allocated separately and not in the generic ILT
  6248. * functions because CDU differs in few aspects:
  6249. * 1. There are multiple entities allocating memory for context -
  6250. * 'regular' driver, CNIC and SRIOV driver. Each separately controls
  6251. * its own ILT lines.
  6252. * 2. Since CDU page-size is not a single 4KB page (which is the case
  6253. * for the other ILT clients), to be efficient we want to support
  6254. * allocation of sub-page-size in the last entry.
  6255. * 3. Context pointers are used by the driver to pass to FW / update
  6256. * the context (for the other ILT clients the pointers are used just to
  6257. * free the memory during unload).
  6258. */
  6259. context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
  6260. for (i = 0, allocated = 0; allocated < context_size; i++) {
  6261. bp->context[i].size = min(CDU_ILT_PAGE_SZ,
  6262. (context_size - allocated));
  6263. BNX2X_PCI_ALLOC(bp->context[i].vcxt,
  6264. &bp->context[i].cxt_mapping,
  6265. bp->context[i].size);
  6266. allocated += bp->context[i].size;
  6267. }
  6268. BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
  6269. if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
  6270. goto alloc_mem_err;
  6271. /* Slow path ring */
  6272. BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
  6273. /* EQ */
  6274. BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
  6275. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6276. /* fastpath */
  6277. /* need to be done at the end, since it's self adjusting to amount
  6278. * of memory available for RSS queues
  6279. */
  6280. if (bnx2x_alloc_fp_mem(bp))
  6281. goto alloc_mem_err;
  6282. return 0;
  6283. alloc_mem_err:
  6284. bnx2x_free_mem(bp);
  6285. BNX2X_ERR("Can't allocate memory\n");
  6286. return -ENOMEM;
  6287. }
  6288. /*
  6289. * Init service functions
  6290. */
  6291. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  6292. struct bnx2x_vlan_mac_obj *obj, bool set,
  6293. int mac_type, unsigned long *ramrod_flags)
  6294. {
  6295. int rc;
  6296. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  6297. memset(&ramrod_param, 0, sizeof(ramrod_param));
  6298. /* Fill general parameters */
  6299. ramrod_param.vlan_mac_obj = obj;
  6300. ramrod_param.ramrod_flags = *ramrod_flags;
  6301. /* Fill a user request section if needed */
  6302. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  6303. memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
  6304. __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
  6305. /* Set the command: ADD or DEL */
  6306. if (set)
  6307. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  6308. else
  6309. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  6310. }
  6311. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  6312. if (rc < 0)
  6313. BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
  6314. return rc;
  6315. }
  6316. int bnx2x_del_all_macs(struct bnx2x *bp,
  6317. struct bnx2x_vlan_mac_obj *mac_obj,
  6318. int mac_type, bool wait_for_comp)
  6319. {
  6320. int rc;
  6321. unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
  6322. /* Wait for completion of requested */
  6323. if (wait_for_comp)
  6324. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6325. /* Set the mac type of addresses we want to clear */
  6326. __set_bit(mac_type, &vlan_mac_flags);
  6327. rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
  6328. if (rc < 0)
  6329. BNX2X_ERR("Failed to delete MACs: %d\n", rc);
  6330. return rc;
  6331. }
  6332. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
  6333. {
  6334. unsigned long ramrod_flags = 0;
  6335. #ifdef BCM_CNIC
  6336. if (is_zero_ether_addr(bp->dev->dev_addr) &&
  6337. (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) {
  6338. DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
  6339. "Ignoring Zero MAC for STORAGE SD mode\n");
  6340. return 0;
  6341. }
  6342. #endif
  6343. DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
  6344. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6345. /* Eth MAC is set on RSS leading client (fp[0]) */
  6346. return bnx2x_set_mac_one(bp, bp->dev->dev_addr, &bp->sp_objs->mac_obj,
  6347. set, BNX2X_ETH_MAC, &ramrod_flags);
  6348. }
  6349. int bnx2x_setup_leading(struct bnx2x *bp)
  6350. {
  6351. return bnx2x_setup_queue(bp, &bp->fp[0], 1);
  6352. }
  6353. /**
  6354. * bnx2x_set_int_mode - configure interrupt mode
  6355. *
  6356. * @bp: driver handle
  6357. *
  6358. * In case of MSI-X it will also try to enable MSI-X.
  6359. */
  6360. void bnx2x_set_int_mode(struct bnx2x *bp)
  6361. {
  6362. switch (int_mode) {
  6363. case INT_MODE_MSI:
  6364. bnx2x_enable_msi(bp);
  6365. /* falling through... */
  6366. case INT_MODE_INTx:
  6367. bp->num_queues = 1 + NON_ETH_CONTEXT_USE;
  6368. BNX2X_DEV_INFO("set number of queues to 1\n");
  6369. break;
  6370. default:
  6371. /* if we can't use MSI-X we only need one fp,
  6372. * so try to enable MSI-X with the requested number of fp's
  6373. * and fallback to MSI or legacy INTx with one fp
  6374. */
  6375. if (bnx2x_enable_msix(bp) ||
  6376. bp->flags & USING_SINGLE_MSIX_FLAG) {
  6377. /* failed to enable multiple MSI-X */
  6378. BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
  6379. bp->num_queues, 1 + NON_ETH_CONTEXT_USE);
  6380. bp->num_queues = 1 + NON_ETH_CONTEXT_USE;
  6381. /* Try to enable MSI */
  6382. if (!(bp->flags & USING_SINGLE_MSIX_FLAG) &&
  6383. !(bp->flags & DISABLE_MSI_FLAG))
  6384. bnx2x_enable_msi(bp);
  6385. }
  6386. break;
  6387. }
  6388. }
  6389. /* must be called prioir to any HW initializations */
  6390. static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
  6391. {
  6392. return L2_ILT_LINES(bp);
  6393. }
  6394. void bnx2x_ilt_set_info(struct bnx2x *bp)
  6395. {
  6396. struct ilt_client_info *ilt_client;
  6397. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6398. u16 line = 0;
  6399. ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
  6400. DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
  6401. /* CDU */
  6402. ilt_client = &ilt->clients[ILT_CLIENT_CDU];
  6403. ilt_client->client_num = ILT_CLIENT_CDU;
  6404. ilt_client->page_size = CDU_ILT_PAGE_SZ;
  6405. ilt_client->flags = ILT_CLIENT_SKIP_MEM;
  6406. ilt_client->start = line;
  6407. line += bnx2x_cid_ilt_lines(bp);
  6408. #ifdef BCM_CNIC
  6409. line += CNIC_ILT_LINES;
  6410. #endif
  6411. ilt_client->end = line - 1;
  6412. DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6413. ilt_client->start,
  6414. ilt_client->end,
  6415. ilt_client->page_size,
  6416. ilt_client->flags,
  6417. ilog2(ilt_client->page_size >> 12));
  6418. /* QM */
  6419. if (QM_INIT(bp->qm_cid_count)) {
  6420. ilt_client = &ilt->clients[ILT_CLIENT_QM];
  6421. ilt_client->client_num = ILT_CLIENT_QM;
  6422. ilt_client->page_size = QM_ILT_PAGE_SZ;
  6423. ilt_client->flags = 0;
  6424. ilt_client->start = line;
  6425. /* 4 bytes for each cid */
  6426. line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
  6427. QM_ILT_PAGE_SZ);
  6428. ilt_client->end = line - 1;
  6429. DP(NETIF_MSG_IFUP,
  6430. "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6431. ilt_client->start,
  6432. ilt_client->end,
  6433. ilt_client->page_size,
  6434. ilt_client->flags,
  6435. ilog2(ilt_client->page_size >> 12));
  6436. }
  6437. /* SRC */
  6438. ilt_client = &ilt->clients[ILT_CLIENT_SRC];
  6439. #ifdef BCM_CNIC
  6440. ilt_client->client_num = ILT_CLIENT_SRC;
  6441. ilt_client->page_size = SRC_ILT_PAGE_SZ;
  6442. ilt_client->flags = 0;
  6443. ilt_client->start = line;
  6444. line += SRC_ILT_LINES;
  6445. ilt_client->end = line - 1;
  6446. DP(NETIF_MSG_IFUP,
  6447. "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6448. ilt_client->start,
  6449. ilt_client->end,
  6450. ilt_client->page_size,
  6451. ilt_client->flags,
  6452. ilog2(ilt_client->page_size >> 12));
  6453. #else
  6454. ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM);
  6455. #endif
  6456. /* TM */
  6457. ilt_client = &ilt->clients[ILT_CLIENT_TM];
  6458. #ifdef BCM_CNIC
  6459. ilt_client->client_num = ILT_CLIENT_TM;
  6460. ilt_client->page_size = TM_ILT_PAGE_SZ;
  6461. ilt_client->flags = 0;
  6462. ilt_client->start = line;
  6463. line += TM_ILT_LINES;
  6464. ilt_client->end = line - 1;
  6465. DP(NETIF_MSG_IFUP,
  6466. "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6467. ilt_client->start,
  6468. ilt_client->end,
  6469. ilt_client->page_size,
  6470. ilt_client->flags,
  6471. ilog2(ilt_client->page_size >> 12));
  6472. #else
  6473. ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM);
  6474. #endif
  6475. BUG_ON(line > ILT_MAX_LINES);
  6476. }
  6477. /**
  6478. * bnx2x_pf_q_prep_init - prepare INIT transition parameters
  6479. *
  6480. * @bp: driver handle
  6481. * @fp: pointer to fastpath
  6482. * @init_params: pointer to parameters structure
  6483. *
  6484. * parameters configured:
  6485. * - HC configuration
  6486. * - Queue's CDU context
  6487. */
  6488. static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
  6489. struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
  6490. {
  6491. u8 cos;
  6492. int cxt_index, cxt_offset;
  6493. /* FCoE Queue uses Default SB, thus has no HC capabilities */
  6494. if (!IS_FCOE_FP(fp)) {
  6495. __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
  6496. __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
  6497. /* If HC is supporterd, enable host coalescing in the transition
  6498. * to INIT state.
  6499. */
  6500. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
  6501. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
  6502. /* HC rate */
  6503. init_params->rx.hc_rate = bp->rx_ticks ?
  6504. (1000000 / bp->rx_ticks) : 0;
  6505. init_params->tx.hc_rate = bp->tx_ticks ?
  6506. (1000000 / bp->tx_ticks) : 0;
  6507. /* FW SB ID */
  6508. init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
  6509. fp->fw_sb_id;
  6510. /*
  6511. * CQ index among the SB indices: FCoE clients uses the default
  6512. * SB, therefore it's different.
  6513. */
  6514. init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  6515. init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
  6516. }
  6517. /* set maximum number of COSs supported by this queue */
  6518. init_params->max_cos = fp->max_cos;
  6519. DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
  6520. fp->index, init_params->max_cos);
  6521. /* set the context pointers queue object */
  6522. for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
  6523. cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
  6524. cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
  6525. ILT_PAGE_CIDS);
  6526. init_params->cxts[cos] =
  6527. &bp->context[cxt_index].vcxt[cxt_offset].eth;
  6528. }
  6529. }
  6530. int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6531. struct bnx2x_queue_state_params *q_params,
  6532. struct bnx2x_queue_setup_tx_only_params *tx_only_params,
  6533. int tx_index, bool leading)
  6534. {
  6535. memset(tx_only_params, 0, sizeof(*tx_only_params));
  6536. /* Set the command */
  6537. q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  6538. /* Set tx-only QUEUE flags: don't zero statistics */
  6539. tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
  6540. /* choose the index of the cid to send the slow path on */
  6541. tx_only_params->cid_index = tx_index;
  6542. /* Set general TX_ONLY_SETUP parameters */
  6543. bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
  6544. /* Set Tx TX_ONLY_SETUP parameters */
  6545. bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
  6546. DP(NETIF_MSG_IFUP,
  6547. "preparing to send tx-only ramrod for connection: cos %d, primary cid %d, cid %d, client id %d, sp-client id %d, flags %lx\n",
  6548. tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
  6549. q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
  6550. tx_only_params->gen_params.spcl_id, tx_only_params->flags);
  6551. /* send the ramrod */
  6552. return bnx2x_queue_state_change(bp, q_params);
  6553. }
  6554. /**
  6555. * bnx2x_setup_queue - setup queue
  6556. *
  6557. * @bp: driver handle
  6558. * @fp: pointer to fastpath
  6559. * @leading: is leading
  6560. *
  6561. * This function performs 2 steps in a Queue state machine
  6562. * actually: 1) RESET->INIT 2) INIT->SETUP
  6563. */
  6564. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6565. bool leading)
  6566. {
  6567. struct bnx2x_queue_state_params q_params = {NULL};
  6568. struct bnx2x_queue_setup_params *setup_params =
  6569. &q_params.params.setup;
  6570. struct bnx2x_queue_setup_tx_only_params *tx_only_params =
  6571. &q_params.params.tx_only;
  6572. int rc;
  6573. u8 tx_index;
  6574. DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
  6575. /* reset IGU state skip FCoE L2 queue */
  6576. if (!IS_FCOE_FP(fp))
  6577. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
  6578. IGU_INT_ENABLE, 0);
  6579. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  6580. /* We want to wait for completion in this context */
  6581. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6582. /* Prepare the INIT parameters */
  6583. bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
  6584. /* Set the command */
  6585. q_params.cmd = BNX2X_Q_CMD_INIT;
  6586. /* Change the state to INIT */
  6587. rc = bnx2x_queue_state_change(bp, &q_params);
  6588. if (rc) {
  6589. BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
  6590. return rc;
  6591. }
  6592. DP(NETIF_MSG_IFUP, "init complete\n");
  6593. /* Now move the Queue to the SETUP state... */
  6594. memset(setup_params, 0, sizeof(*setup_params));
  6595. /* Set QUEUE flags */
  6596. setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
  6597. /* Set general SETUP parameters */
  6598. bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
  6599. FIRST_TX_COS_INDEX);
  6600. bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
  6601. &setup_params->rxq_params);
  6602. bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
  6603. FIRST_TX_COS_INDEX);
  6604. /* Set the command */
  6605. q_params.cmd = BNX2X_Q_CMD_SETUP;
  6606. /* Change the state to SETUP */
  6607. rc = bnx2x_queue_state_change(bp, &q_params);
  6608. if (rc) {
  6609. BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
  6610. return rc;
  6611. }
  6612. /* loop through the relevant tx-only indices */
  6613. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6614. tx_index < fp->max_cos;
  6615. tx_index++) {
  6616. /* prepare and send tx-only ramrod*/
  6617. rc = bnx2x_setup_tx_only(bp, fp, &q_params,
  6618. tx_only_params, tx_index, leading);
  6619. if (rc) {
  6620. BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
  6621. fp->index, tx_index);
  6622. return rc;
  6623. }
  6624. }
  6625. return rc;
  6626. }
  6627. static int bnx2x_stop_queue(struct bnx2x *bp, int index)
  6628. {
  6629. struct bnx2x_fastpath *fp = &bp->fp[index];
  6630. struct bnx2x_fp_txdata *txdata;
  6631. struct bnx2x_queue_state_params q_params = {NULL};
  6632. int rc, tx_index;
  6633. DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
  6634. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  6635. /* We want to wait for completion in this context */
  6636. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6637. /* close tx-only connections */
  6638. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6639. tx_index < fp->max_cos;
  6640. tx_index++){
  6641. /* ascertain this is a normal queue*/
  6642. txdata = fp->txdata_ptr[tx_index];
  6643. DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
  6644. txdata->txq_index);
  6645. /* send halt terminate on tx-only connection */
  6646. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6647. memset(&q_params.params.terminate, 0,
  6648. sizeof(q_params.params.terminate));
  6649. q_params.params.terminate.cid_index = tx_index;
  6650. rc = bnx2x_queue_state_change(bp, &q_params);
  6651. if (rc)
  6652. return rc;
  6653. /* send halt terminate on tx-only connection */
  6654. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6655. memset(&q_params.params.cfc_del, 0,
  6656. sizeof(q_params.params.cfc_del));
  6657. q_params.params.cfc_del.cid_index = tx_index;
  6658. rc = bnx2x_queue_state_change(bp, &q_params);
  6659. if (rc)
  6660. return rc;
  6661. }
  6662. /* Stop the primary connection: */
  6663. /* ...halt the connection */
  6664. q_params.cmd = BNX2X_Q_CMD_HALT;
  6665. rc = bnx2x_queue_state_change(bp, &q_params);
  6666. if (rc)
  6667. return rc;
  6668. /* ...terminate the connection */
  6669. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6670. memset(&q_params.params.terminate, 0,
  6671. sizeof(q_params.params.terminate));
  6672. q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
  6673. rc = bnx2x_queue_state_change(bp, &q_params);
  6674. if (rc)
  6675. return rc;
  6676. /* ...delete cfc entry */
  6677. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6678. memset(&q_params.params.cfc_del, 0,
  6679. sizeof(q_params.params.cfc_del));
  6680. q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
  6681. return bnx2x_queue_state_change(bp, &q_params);
  6682. }
  6683. static void bnx2x_reset_func(struct bnx2x *bp)
  6684. {
  6685. int port = BP_PORT(bp);
  6686. int func = BP_FUNC(bp);
  6687. int i;
  6688. /* Disable the function in the FW */
  6689. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
  6690. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
  6691. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
  6692. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
  6693. /* FP SBs */
  6694. for_each_eth_queue(bp, i) {
  6695. struct bnx2x_fastpath *fp = &bp->fp[i];
  6696. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6697. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
  6698. SB_DISABLED);
  6699. }
  6700. #ifdef BCM_CNIC
  6701. /* CNIC SB */
  6702. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6703. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(bnx2x_cnic_fw_sb_id(bp)),
  6704. SB_DISABLED);
  6705. #endif
  6706. /* SP SB */
  6707. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6708. CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
  6709. SB_DISABLED);
  6710. for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
  6711. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
  6712. 0);
  6713. /* Configure IGU */
  6714. if (bp->common.int_block == INT_BLOCK_HC) {
  6715. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6716. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6717. } else {
  6718. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6719. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6720. }
  6721. #ifdef BCM_CNIC
  6722. /* Disable Timer scan */
  6723. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  6724. /*
  6725. * Wait for at least 10ms and up to 2 second for the timers scan to
  6726. * complete
  6727. */
  6728. for (i = 0; i < 200; i++) {
  6729. msleep(10);
  6730. if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
  6731. break;
  6732. }
  6733. #endif
  6734. /* Clear ILT */
  6735. bnx2x_clear_func_ilt(bp, func);
  6736. /* Timers workaround bug for E2: if this is vnic-3,
  6737. * we need to set the entire ilt range for this timers.
  6738. */
  6739. if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
  6740. struct ilt_client_info ilt_cli;
  6741. /* use dummy TM client */
  6742. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  6743. ilt_cli.start = 0;
  6744. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  6745. ilt_cli.client_num = ILT_CLIENT_TM;
  6746. bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
  6747. }
  6748. /* this assumes that reset_port() called before reset_func()*/
  6749. if (!CHIP_IS_E1x(bp))
  6750. bnx2x_pf_disable(bp);
  6751. bp->dmae_ready = 0;
  6752. }
  6753. static void bnx2x_reset_port(struct bnx2x *bp)
  6754. {
  6755. int port = BP_PORT(bp);
  6756. u32 val;
  6757. /* Reset physical Link */
  6758. bnx2x__link_reset(bp);
  6759. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  6760. /* Do not rcv packets to BRB */
  6761. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  6762. /* Do not direct rcv packets that are not for MCP to the BRB */
  6763. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  6764. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  6765. /* Configure AEU */
  6766. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  6767. msleep(100);
  6768. /* Check for BRB port occupancy */
  6769. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  6770. if (val)
  6771. DP(NETIF_MSG_IFDOWN,
  6772. "BRB1 is not empty %d blocks are occupied\n", val);
  6773. /* TODO: Close Doorbell port? */
  6774. }
  6775. static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
  6776. {
  6777. struct bnx2x_func_state_params func_params = {NULL};
  6778. /* Prepare parameters for function state transitions */
  6779. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6780. func_params.f_obj = &bp->func_obj;
  6781. func_params.cmd = BNX2X_F_CMD_HW_RESET;
  6782. func_params.params.hw_init.load_phase = load_code;
  6783. return bnx2x_func_state_change(bp, &func_params);
  6784. }
  6785. static int bnx2x_func_stop(struct bnx2x *bp)
  6786. {
  6787. struct bnx2x_func_state_params func_params = {NULL};
  6788. int rc;
  6789. /* Prepare parameters for function state transitions */
  6790. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6791. func_params.f_obj = &bp->func_obj;
  6792. func_params.cmd = BNX2X_F_CMD_STOP;
  6793. /*
  6794. * Try to stop the function the 'good way'. If fails (in case
  6795. * of a parity error during bnx2x_chip_cleanup()) and we are
  6796. * not in a debug mode, perform a state transaction in order to
  6797. * enable further HW_RESET transaction.
  6798. */
  6799. rc = bnx2x_func_state_change(bp, &func_params);
  6800. if (rc) {
  6801. #ifdef BNX2X_STOP_ON_ERROR
  6802. return rc;
  6803. #else
  6804. BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
  6805. __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
  6806. return bnx2x_func_state_change(bp, &func_params);
  6807. #endif
  6808. }
  6809. return 0;
  6810. }
  6811. /**
  6812. * bnx2x_send_unload_req - request unload mode from the MCP.
  6813. *
  6814. * @bp: driver handle
  6815. * @unload_mode: requested function's unload mode
  6816. *
  6817. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  6818. */
  6819. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
  6820. {
  6821. u32 reset_code = 0;
  6822. int port = BP_PORT(bp);
  6823. /* Select the UNLOAD request mode */
  6824. if (unload_mode == UNLOAD_NORMAL)
  6825. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  6826. else if (bp->flags & NO_WOL_FLAG)
  6827. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  6828. else if (bp->wol) {
  6829. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  6830. u8 *mac_addr = bp->dev->dev_addr;
  6831. u32 val;
  6832. u16 pmc;
  6833. /* The mac address is written to entries 1-4 to
  6834. * preserve entry 0 which is used by the PMF
  6835. */
  6836. u8 entry = (BP_VN(bp) + 1)*8;
  6837. val = (mac_addr[0] << 8) | mac_addr[1];
  6838. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  6839. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  6840. (mac_addr[4] << 8) | mac_addr[5];
  6841. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  6842. /* Enable the PME and clear the status */
  6843. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmc);
  6844. pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
  6845. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, pmc);
  6846. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  6847. } else
  6848. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  6849. /* Send the request to the MCP */
  6850. if (!BP_NOMCP(bp))
  6851. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  6852. else {
  6853. int path = BP_PATH(bp);
  6854. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
  6855. path, load_count[path][0], load_count[path][1],
  6856. load_count[path][2]);
  6857. load_count[path][0]--;
  6858. load_count[path][1 + port]--;
  6859. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
  6860. path, load_count[path][0], load_count[path][1],
  6861. load_count[path][2]);
  6862. if (load_count[path][0] == 0)
  6863. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  6864. else if (load_count[path][1 + port] == 0)
  6865. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  6866. else
  6867. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  6868. }
  6869. return reset_code;
  6870. }
  6871. /**
  6872. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  6873. *
  6874. * @bp: driver handle
  6875. */
  6876. void bnx2x_send_unload_done(struct bnx2x *bp)
  6877. {
  6878. /* Report UNLOAD_DONE to MCP */
  6879. if (!BP_NOMCP(bp))
  6880. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  6881. }
  6882. static int bnx2x_func_wait_started(struct bnx2x *bp)
  6883. {
  6884. int tout = 50;
  6885. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  6886. if (!bp->port.pmf)
  6887. return 0;
  6888. /*
  6889. * (assumption: No Attention from MCP at this stage)
  6890. * PMF probably in the middle of TXdisable/enable transaction
  6891. * 1. Sync IRS for default SB
  6892. * 2. Sync SP queue - this guarantes us that attention handling started
  6893. * 3. Wait, that TXdisable/enable transaction completes
  6894. *
  6895. * 1+2 guranty that if DCBx attention was scheduled it already changed
  6896. * pending bit of transaction from STARTED-->TX_STOPPED, if we alredy
  6897. * received complettion for the transaction the state is TX_STOPPED.
  6898. * State will return to STARTED after completion of TX_STOPPED-->STARTED
  6899. * transaction.
  6900. */
  6901. /* make sure default SB ISR is done */
  6902. if (msix)
  6903. synchronize_irq(bp->msix_table[0].vector);
  6904. else
  6905. synchronize_irq(bp->pdev->irq);
  6906. flush_workqueue(bnx2x_wq);
  6907. while (bnx2x_func_get_state(bp, &bp->func_obj) !=
  6908. BNX2X_F_STATE_STARTED && tout--)
  6909. msleep(20);
  6910. if (bnx2x_func_get_state(bp, &bp->func_obj) !=
  6911. BNX2X_F_STATE_STARTED) {
  6912. #ifdef BNX2X_STOP_ON_ERROR
  6913. BNX2X_ERR("Wrong function state\n");
  6914. return -EBUSY;
  6915. #else
  6916. /*
  6917. * Failed to complete the transaction in a "good way"
  6918. * Force both transactions with CLR bit
  6919. */
  6920. struct bnx2x_func_state_params func_params = {NULL};
  6921. DP(NETIF_MSG_IFDOWN,
  6922. "Hmmm... unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
  6923. func_params.f_obj = &bp->func_obj;
  6924. __set_bit(RAMROD_DRV_CLR_ONLY,
  6925. &func_params.ramrod_flags);
  6926. /* STARTED-->TX_ST0PPED */
  6927. func_params.cmd = BNX2X_F_CMD_TX_STOP;
  6928. bnx2x_func_state_change(bp, &func_params);
  6929. /* TX_ST0PPED-->STARTED */
  6930. func_params.cmd = BNX2X_F_CMD_TX_START;
  6931. return bnx2x_func_state_change(bp, &func_params);
  6932. #endif
  6933. }
  6934. return 0;
  6935. }
  6936. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode)
  6937. {
  6938. int port = BP_PORT(bp);
  6939. int i, rc = 0;
  6940. u8 cos;
  6941. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  6942. u32 reset_code;
  6943. /* Wait until tx fastpath tasks complete */
  6944. for_each_tx_queue(bp, i) {
  6945. struct bnx2x_fastpath *fp = &bp->fp[i];
  6946. for_each_cos_in_tx_queue(fp, cos)
  6947. rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
  6948. #ifdef BNX2X_STOP_ON_ERROR
  6949. if (rc)
  6950. return;
  6951. #endif
  6952. }
  6953. /* Give HW time to discard old tx messages */
  6954. usleep_range(1000, 1000);
  6955. /* Clean all ETH MACs */
  6956. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
  6957. false);
  6958. if (rc < 0)
  6959. BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
  6960. /* Clean up UC list */
  6961. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
  6962. true);
  6963. if (rc < 0)
  6964. BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
  6965. rc);
  6966. /* Disable LLH */
  6967. if (!CHIP_IS_E1(bp))
  6968. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  6969. /* Set "drop all" (stop Rx).
  6970. * We need to take a netif_addr_lock() here in order to prevent
  6971. * a race between the completion code and this code.
  6972. */
  6973. netif_addr_lock_bh(bp->dev);
  6974. /* Schedule the rx_mode command */
  6975. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  6976. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  6977. else
  6978. bnx2x_set_storm_rx_mode(bp);
  6979. /* Cleanup multicast configuration */
  6980. rparam.mcast_obj = &bp->mcast_obj;
  6981. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  6982. if (rc < 0)
  6983. BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
  6984. netif_addr_unlock_bh(bp->dev);
  6985. /*
  6986. * Send the UNLOAD_REQUEST to the MCP. This will return if
  6987. * this function should perform FUNC, PORT or COMMON HW
  6988. * reset.
  6989. */
  6990. reset_code = bnx2x_send_unload_req(bp, unload_mode);
  6991. /*
  6992. * (assumption: No Attention from MCP at this stage)
  6993. * PMF probably in the middle of TXdisable/enable transaction
  6994. */
  6995. rc = bnx2x_func_wait_started(bp);
  6996. if (rc) {
  6997. BNX2X_ERR("bnx2x_func_wait_started failed\n");
  6998. #ifdef BNX2X_STOP_ON_ERROR
  6999. return;
  7000. #endif
  7001. }
  7002. /* Close multi and leading connections
  7003. * Completions for ramrods are collected in a synchronous way
  7004. */
  7005. for_each_queue(bp, i)
  7006. if (bnx2x_stop_queue(bp, i))
  7007. #ifdef BNX2X_STOP_ON_ERROR
  7008. return;
  7009. #else
  7010. goto unload_error;
  7011. #endif
  7012. /* If SP settings didn't get completed so far - something
  7013. * very wrong has happen.
  7014. */
  7015. if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
  7016. BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
  7017. #ifndef BNX2X_STOP_ON_ERROR
  7018. unload_error:
  7019. #endif
  7020. rc = bnx2x_func_stop(bp);
  7021. if (rc) {
  7022. BNX2X_ERR("Function stop failed!\n");
  7023. #ifdef BNX2X_STOP_ON_ERROR
  7024. return;
  7025. #endif
  7026. }
  7027. /* Disable HW interrupts, NAPI */
  7028. bnx2x_netif_stop(bp, 1);
  7029. /* Delete all NAPI objects */
  7030. bnx2x_del_all_napi(bp);
  7031. /* Release IRQs */
  7032. bnx2x_free_irq(bp);
  7033. /* Reset the chip */
  7034. rc = bnx2x_reset_hw(bp, reset_code);
  7035. if (rc)
  7036. BNX2X_ERR("HW_RESET failed\n");
  7037. /* Report UNLOAD_DONE to MCP */
  7038. bnx2x_send_unload_done(bp);
  7039. }
  7040. void bnx2x_disable_close_the_gate(struct bnx2x *bp)
  7041. {
  7042. u32 val;
  7043. DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
  7044. if (CHIP_IS_E1(bp)) {
  7045. int port = BP_PORT(bp);
  7046. u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  7047. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  7048. val = REG_RD(bp, addr);
  7049. val &= ~(0x300);
  7050. REG_WR(bp, addr, val);
  7051. } else {
  7052. val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
  7053. val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
  7054. MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
  7055. REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
  7056. }
  7057. }
  7058. /* Close gates #2, #3 and #4: */
  7059. static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
  7060. {
  7061. u32 val;
  7062. /* Gates #2 and #4a are closed/opened for "not E1" only */
  7063. if (!CHIP_IS_E1(bp)) {
  7064. /* #4 */
  7065. REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
  7066. /* #2 */
  7067. REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
  7068. }
  7069. /* #3 */
  7070. if (CHIP_IS_E1x(bp)) {
  7071. /* Prevent interrupts from HC on both ports */
  7072. val = REG_RD(bp, HC_REG_CONFIG_1);
  7073. REG_WR(bp, HC_REG_CONFIG_1,
  7074. (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
  7075. (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
  7076. val = REG_RD(bp, HC_REG_CONFIG_0);
  7077. REG_WR(bp, HC_REG_CONFIG_0,
  7078. (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
  7079. (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
  7080. } else {
  7081. /* Prevent incomming interrupts in IGU */
  7082. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  7083. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
  7084. (!close) ?
  7085. (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
  7086. (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
  7087. }
  7088. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
  7089. close ? "closing" : "opening");
  7090. mmiowb();
  7091. }
  7092. #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
  7093. static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
  7094. {
  7095. /* Do some magic... */
  7096. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7097. *magic_val = val & SHARED_MF_CLP_MAGIC;
  7098. MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
  7099. }
  7100. /**
  7101. * bnx2x_clp_reset_done - restore the value of the `magic' bit.
  7102. *
  7103. * @bp: driver handle
  7104. * @magic_val: old value of the `magic' bit.
  7105. */
  7106. static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
  7107. {
  7108. /* Restore the `magic' bit value... */
  7109. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7110. MF_CFG_WR(bp, shared_mf_config.clp_mb,
  7111. (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
  7112. }
  7113. /**
  7114. * bnx2x_reset_mcp_prep - prepare for MCP reset.
  7115. *
  7116. * @bp: driver handle
  7117. * @magic_val: old value of 'magic' bit.
  7118. *
  7119. * Takes care of CLP configurations.
  7120. */
  7121. static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
  7122. {
  7123. u32 shmem;
  7124. u32 validity_offset;
  7125. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
  7126. /* Set `magic' bit in order to save MF config */
  7127. if (!CHIP_IS_E1(bp))
  7128. bnx2x_clp_reset_prep(bp, magic_val);
  7129. /* Get shmem offset */
  7130. shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7131. validity_offset = offsetof(struct shmem_region, validity_map[0]);
  7132. /* Clear validity map flags */
  7133. if (shmem > 0)
  7134. REG_WR(bp, shmem + validity_offset, 0);
  7135. }
  7136. #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
  7137. #define MCP_ONE_TIMEOUT 100 /* 100 ms */
  7138. /**
  7139. * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
  7140. *
  7141. * @bp: driver handle
  7142. */
  7143. static void bnx2x_mcp_wait_one(struct bnx2x *bp)
  7144. {
  7145. /* special handling for emulation and FPGA,
  7146. wait 10 times longer */
  7147. if (CHIP_REV_IS_SLOW(bp))
  7148. msleep(MCP_ONE_TIMEOUT*10);
  7149. else
  7150. msleep(MCP_ONE_TIMEOUT);
  7151. }
  7152. /*
  7153. * initializes bp->common.shmem_base and waits for validity signature to appear
  7154. */
  7155. static int bnx2x_init_shmem(struct bnx2x *bp)
  7156. {
  7157. int cnt = 0;
  7158. u32 val = 0;
  7159. do {
  7160. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7161. if (bp->common.shmem_base) {
  7162. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  7163. if (val & SHR_MEM_VALIDITY_MB)
  7164. return 0;
  7165. }
  7166. bnx2x_mcp_wait_one(bp);
  7167. } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
  7168. BNX2X_ERR("BAD MCP validity signature\n");
  7169. return -ENODEV;
  7170. }
  7171. static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
  7172. {
  7173. int rc = bnx2x_init_shmem(bp);
  7174. /* Restore the `magic' bit value */
  7175. if (!CHIP_IS_E1(bp))
  7176. bnx2x_clp_reset_done(bp, magic_val);
  7177. return rc;
  7178. }
  7179. static void bnx2x_pxp_prep(struct bnx2x *bp)
  7180. {
  7181. if (!CHIP_IS_E1(bp)) {
  7182. REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
  7183. REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
  7184. mmiowb();
  7185. }
  7186. }
  7187. /*
  7188. * Reset the whole chip except for:
  7189. * - PCIE core
  7190. * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
  7191. * one reset bit)
  7192. * - IGU
  7193. * - MISC (including AEU)
  7194. * - GRC
  7195. * - RBCN, RBCP
  7196. */
  7197. static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
  7198. {
  7199. u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
  7200. u32 global_bits2, stay_reset2;
  7201. /*
  7202. * Bits that have to be set in reset_mask2 if we want to reset 'global'
  7203. * (per chip) blocks.
  7204. */
  7205. global_bits2 =
  7206. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
  7207. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
  7208. /* Don't reset the following blocks */
  7209. not_reset_mask1 =
  7210. MISC_REGISTERS_RESET_REG_1_RST_HC |
  7211. MISC_REGISTERS_RESET_REG_1_RST_PXPV |
  7212. MISC_REGISTERS_RESET_REG_1_RST_PXP;
  7213. not_reset_mask2 =
  7214. MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
  7215. MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
  7216. MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
  7217. MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
  7218. MISC_REGISTERS_RESET_REG_2_RST_RBCN |
  7219. MISC_REGISTERS_RESET_REG_2_RST_GRC |
  7220. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
  7221. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
  7222. MISC_REGISTERS_RESET_REG_2_RST_ATC |
  7223. MISC_REGISTERS_RESET_REG_2_PGLC;
  7224. /*
  7225. * Keep the following blocks in reset:
  7226. * - all xxMACs are handled by the bnx2x_link code.
  7227. */
  7228. stay_reset2 =
  7229. MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
  7230. MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
  7231. MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
  7232. MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
  7233. MISC_REGISTERS_RESET_REG_2_UMAC0 |
  7234. MISC_REGISTERS_RESET_REG_2_UMAC1 |
  7235. MISC_REGISTERS_RESET_REG_2_XMAC |
  7236. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
  7237. /* Full reset masks according to the chip */
  7238. reset_mask1 = 0xffffffff;
  7239. if (CHIP_IS_E1(bp))
  7240. reset_mask2 = 0xffff;
  7241. else if (CHIP_IS_E1H(bp))
  7242. reset_mask2 = 0x1ffff;
  7243. else if (CHIP_IS_E2(bp))
  7244. reset_mask2 = 0xfffff;
  7245. else /* CHIP_IS_E3 */
  7246. reset_mask2 = 0x3ffffff;
  7247. /* Don't reset global blocks unless we need to */
  7248. if (!global)
  7249. reset_mask2 &= ~global_bits2;
  7250. /*
  7251. * In case of attention in the QM, we need to reset PXP
  7252. * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
  7253. * because otherwise QM reset would release 'close the gates' shortly
  7254. * before resetting the PXP, then the PSWRQ would send a write
  7255. * request to PGLUE. Then when PXP is reset, PGLUE would try to
  7256. * read the payload data from PSWWR, but PSWWR would not
  7257. * respond. The write queue in PGLUE would stuck, dmae commands
  7258. * would not return. Therefore it's important to reset the second
  7259. * reset register (containing the
  7260. * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
  7261. * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
  7262. * bit).
  7263. */
  7264. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  7265. reset_mask2 & (~not_reset_mask2));
  7266. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  7267. reset_mask1 & (~not_reset_mask1));
  7268. barrier();
  7269. mmiowb();
  7270. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  7271. reset_mask2 & (~stay_reset2));
  7272. barrier();
  7273. mmiowb();
  7274. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
  7275. mmiowb();
  7276. }
  7277. /**
  7278. * bnx2x_er_poll_igu_vq - poll for pending writes bit.
  7279. * It should get cleared in no more than 1s.
  7280. *
  7281. * @bp: driver handle
  7282. *
  7283. * It should get cleared in no more than 1s. Returns 0 if
  7284. * pending writes bit gets cleared.
  7285. */
  7286. static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
  7287. {
  7288. u32 cnt = 1000;
  7289. u32 pend_bits = 0;
  7290. do {
  7291. pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
  7292. if (pend_bits == 0)
  7293. break;
  7294. usleep_range(1000, 1000);
  7295. } while (cnt-- > 0);
  7296. if (cnt <= 0) {
  7297. BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
  7298. pend_bits);
  7299. return -EBUSY;
  7300. }
  7301. return 0;
  7302. }
  7303. static int bnx2x_process_kill(struct bnx2x *bp, bool global)
  7304. {
  7305. int cnt = 1000;
  7306. u32 val = 0;
  7307. u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
  7308. /* Empty the Tetris buffer, wait for 1s */
  7309. do {
  7310. sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
  7311. blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
  7312. port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
  7313. port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
  7314. pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
  7315. if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
  7316. ((port_is_idle_0 & 0x1) == 0x1) &&
  7317. ((port_is_idle_1 & 0x1) == 0x1) &&
  7318. (pgl_exp_rom2 == 0xffffffff))
  7319. break;
  7320. usleep_range(1000, 1000);
  7321. } while (cnt-- > 0);
  7322. if (cnt <= 0) {
  7323. BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
  7324. BNX2X_ERR("sr_cnt=0x%08x, blk_cnt=0x%08x, port_is_idle_0=0x%08x, port_is_idle_1=0x%08x, pgl_exp_rom2=0x%08x\n",
  7325. sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
  7326. pgl_exp_rom2);
  7327. return -EAGAIN;
  7328. }
  7329. barrier();
  7330. /* Close gates #2, #3 and #4 */
  7331. bnx2x_set_234_gates(bp, true);
  7332. /* Poll for IGU VQs for 57712 and newer chips */
  7333. if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
  7334. return -EAGAIN;
  7335. /* TBD: Indicate that "process kill" is in progress to MCP */
  7336. /* Clear "unprepared" bit */
  7337. REG_WR(bp, MISC_REG_UNPREPARED, 0);
  7338. barrier();
  7339. /* Make sure all is written to the chip before the reset */
  7340. mmiowb();
  7341. /* Wait for 1ms to empty GLUE and PCI-E core queues,
  7342. * PSWHST, GRC and PSWRD Tetris buffer.
  7343. */
  7344. usleep_range(1000, 1000);
  7345. /* Prepare to chip reset: */
  7346. /* MCP */
  7347. if (global)
  7348. bnx2x_reset_mcp_prep(bp, &val);
  7349. /* PXP */
  7350. bnx2x_pxp_prep(bp);
  7351. barrier();
  7352. /* reset the chip */
  7353. bnx2x_process_kill_chip_reset(bp, global);
  7354. barrier();
  7355. /* Recover after reset: */
  7356. /* MCP */
  7357. if (global && bnx2x_reset_mcp_comp(bp, val))
  7358. return -EAGAIN;
  7359. /* TBD: Add resetting the NO_MCP mode DB here */
  7360. /* PXP */
  7361. bnx2x_pxp_prep(bp);
  7362. /* Open the gates #2, #3 and #4 */
  7363. bnx2x_set_234_gates(bp, false);
  7364. /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
  7365. * reset state, re-enable attentions. */
  7366. return 0;
  7367. }
  7368. int bnx2x_leader_reset(struct bnx2x *bp)
  7369. {
  7370. int rc = 0;
  7371. bool global = bnx2x_reset_is_global(bp);
  7372. u32 load_code;
  7373. /* if not going to reset MCP - load "fake" driver to reset HW while
  7374. * driver is owner of the HW
  7375. */
  7376. if (!global && !BP_NOMCP(bp)) {
  7377. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ, 0);
  7378. if (!load_code) {
  7379. BNX2X_ERR("MCP response failure, aborting\n");
  7380. rc = -EAGAIN;
  7381. goto exit_leader_reset;
  7382. }
  7383. if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
  7384. (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
  7385. BNX2X_ERR("MCP unexpected resp, aborting\n");
  7386. rc = -EAGAIN;
  7387. goto exit_leader_reset2;
  7388. }
  7389. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  7390. if (!load_code) {
  7391. BNX2X_ERR("MCP response failure, aborting\n");
  7392. rc = -EAGAIN;
  7393. goto exit_leader_reset2;
  7394. }
  7395. }
  7396. /* Try to recover after the failure */
  7397. if (bnx2x_process_kill(bp, global)) {
  7398. BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
  7399. BP_PATH(bp));
  7400. rc = -EAGAIN;
  7401. goto exit_leader_reset2;
  7402. }
  7403. /*
  7404. * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
  7405. * state.
  7406. */
  7407. bnx2x_set_reset_done(bp);
  7408. if (global)
  7409. bnx2x_clear_reset_global(bp);
  7410. exit_leader_reset2:
  7411. /* unload "fake driver" if it was loaded */
  7412. if (!global && !BP_NOMCP(bp)) {
  7413. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
  7414. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  7415. }
  7416. exit_leader_reset:
  7417. bp->is_leader = 0;
  7418. bnx2x_release_leader_lock(bp);
  7419. smp_mb();
  7420. return rc;
  7421. }
  7422. static void bnx2x_recovery_failed(struct bnx2x *bp)
  7423. {
  7424. netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
  7425. /* Disconnect this device */
  7426. netif_device_detach(bp->dev);
  7427. /*
  7428. * Block ifup for all function on this engine until "process kill"
  7429. * or power cycle.
  7430. */
  7431. bnx2x_set_reset_in_progress(bp);
  7432. /* Shut down the power */
  7433. bnx2x_set_power_state(bp, PCI_D3hot);
  7434. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  7435. smp_mb();
  7436. }
  7437. /*
  7438. * Assumption: runs under rtnl lock. This together with the fact
  7439. * that it's called only from bnx2x_sp_rtnl() ensure that it
  7440. * will never be called when netif_running(bp->dev) is false.
  7441. */
  7442. static void bnx2x_parity_recover(struct bnx2x *bp)
  7443. {
  7444. bool global = false;
  7445. u32 error_recovered, error_unrecovered;
  7446. bool is_parity;
  7447. DP(NETIF_MSG_HW, "Handling parity\n");
  7448. while (1) {
  7449. switch (bp->recovery_state) {
  7450. case BNX2X_RECOVERY_INIT:
  7451. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
  7452. is_parity = bnx2x_chk_parity_attn(bp, &global, false);
  7453. WARN_ON(!is_parity);
  7454. /* Try to get a LEADER_LOCK HW lock */
  7455. if (bnx2x_trylock_leader_lock(bp)) {
  7456. bnx2x_set_reset_in_progress(bp);
  7457. /*
  7458. * Check if there is a global attention and if
  7459. * there was a global attention, set the global
  7460. * reset bit.
  7461. */
  7462. if (global)
  7463. bnx2x_set_reset_global(bp);
  7464. bp->is_leader = 1;
  7465. }
  7466. /* Stop the driver */
  7467. /* If interface has been removed - break */
  7468. if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY))
  7469. return;
  7470. bp->recovery_state = BNX2X_RECOVERY_WAIT;
  7471. /* Ensure "is_leader", MCP command sequence and
  7472. * "recovery_state" update values are seen on other
  7473. * CPUs.
  7474. */
  7475. smp_mb();
  7476. break;
  7477. case BNX2X_RECOVERY_WAIT:
  7478. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
  7479. if (bp->is_leader) {
  7480. int other_engine = BP_PATH(bp) ? 0 : 1;
  7481. bool other_load_status =
  7482. bnx2x_get_load_status(bp, other_engine);
  7483. bool load_status =
  7484. bnx2x_get_load_status(bp, BP_PATH(bp));
  7485. global = bnx2x_reset_is_global(bp);
  7486. /*
  7487. * In case of a parity in a global block, let
  7488. * the first leader that performs a
  7489. * leader_reset() reset the global blocks in
  7490. * order to clear global attentions. Otherwise
  7491. * the the gates will remain closed for that
  7492. * engine.
  7493. */
  7494. if (load_status ||
  7495. (global && other_load_status)) {
  7496. /* Wait until all other functions get
  7497. * down.
  7498. */
  7499. schedule_delayed_work(&bp->sp_rtnl_task,
  7500. HZ/10);
  7501. return;
  7502. } else {
  7503. /* If all other functions got down -
  7504. * try to bring the chip back to
  7505. * normal. In any case it's an exit
  7506. * point for a leader.
  7507. */
  7508. if (bnx2x_leader_reset(bp)) {
  7509. bnx2x_recovery_failed(bp);
  7510. return;
  7511. }
  7512. /* If we are here, means that the
  7513. * leader has succeeded and doesn't
  7514. * want to be a leader any more. Try
  7515. * to continue as a none-leader.
  7516. */
  7517. break;
  7518. }
  7519. } else { /* non-leader */
  7520. if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
  7521. /* Try to get a LEADER_LOCK HW lock as
  7522. * long as a former leader may have
  7523. * been unloaded by the user or
  7524. * released a leadership by another
  7525. * reason.
  7526. */
  7527. if (bnx2x_trylock_leader_lock(bp)) {
  7528. /* I'm a leader now! Restart a
  7529. * switch case.
  7530. */
  7531. bp->is_leader = 1;
  7532. break;
  7533. }
  7534. schedule_delayed_work(&bp->sp_rtnl_task,
  7535. HZ/10);
  7536. return;
  7537. } else {
  7538. /*
  7539. * If there was a global attention, wait
  7540. * for it to be cleared.
  7541. */
  7542. if (bnx2x_reset_is_global(bp)) {
  7543. schedule_delayed_work(
  7544. &bp->sp_rtnl_task,
  7545. HZ/10);
  7546. return;
  7547. }
  7548. error_recovered =
  7549. bp->eth_stats.recoverable_error;
  7550. error_unrecovered =
  7551. bp->eth_stats.unrecoverable_error;
  7552. bp->recovery_state =
  7553. BNX2X_RECOVERY_NIC_LOADING;
  7554. if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
  7555. error_unrecovered++;
  7556. netdev_err(bp->dev,
  7557. "Recovery failed. Power cycle needed\n");
  7558. /* Disconnect this device */
  7559. netif_device_detach(bp->dev);
  7560. /* Shut down the power */
  7561. bnx2x_set_power_state(
  7562. bp, PCI_D3hot);
  7563. smp_mb();
  7564. } else {
  7565. bp->recovery_state =
  7566. BNX2X_RECOVERY_DONE;
  7567. error_recovered++;
  7568. smp_mb();
  7569. }
  7570. bp->eth_stats.recoverable_error =
  7571. error_recovered;
  7572. bp->eth_stats.unrecoverable_error =
  7573. error_unrecovered;
  7574. return;
  7575. }
  7576. }
  7577. default:
  7578. return;
  7579. }
  7580. }
  7581. }
  7582. static int bnx2x_close(struct net_device *dev);
  7583. /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
  7584. * scheduled on a general queue in order to prevent a dead lock.
  7585. */
  7586. static void bnx2x_sp_rtnl_task(struct work_struct *work)
  7587. {
  7588. struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
  7589. rtnl_lock();
  7590. if (!netif_running(bp->dev))
  7591. goto sp_rtnl_exit;
  7592. /* if stop on error is defined no recovery flows should be executed */
  7593. #ifdef BNX2X_STOP_ON_ERROR
  7594. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  7595. "you will need to reboot when done\n");
  7596. goto sp_rtnl_not_reset;
  7597. #endif
  7598. if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
  7599. /*
  7600. * Clear all pending SP commands as we are going to reset the
  7601. * function anyway.
  7602. */
  7603. bp->sp_rtnl_state = 0;
  7604. smp_mb();
  7605. bnx2x_parity_recover(bp);
  7606. goto sp_rtnl_exit;
  7607. }
  7608. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
  7609. /*
  7610. * Clear all pending SP commands as we are going to reset the
  7611. * function anyway.
  7612. */
  7613. bp->sp_rtnl_state = 0;
  7614. smp_mb();
  7615. bnx2x_nic_unload(bp, UNLOAD_NORMAL);
  7616. bnx2x_nic_load(bp, LOAD_NORMAL);
  7617. goto sp_rtnl_exit;
  7618. }
  7619. #ifdef BNX2X_STOP_ON_ERROR
  7620. sp_rtnl_not_reset:
  7621. #endif
  7622. if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
  7623. bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
  7624. if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
  7625. bnx2x_after_function_update(bp);
  7626. /*
  7627. * in case of fan failure we need to reset id if the "stop on error"
  7628. * debug flag is set, since we trying to prevent permanent overheating
  7629. * damage
  7630. */
  7631. if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
  7632. DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
  7633. netif_device_detach(bp->dev);
  7634. bnx2x_close(bp->dev);
  7635. }
  7636. sp_rtnl_exit:
  7637. rtnl_unlock();
  7638. }
  7639. /* end of nic load/unload */
  7640. static void bnx2x_period_task(struct work_struct *work)
  7641. {
  7642. struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
  7643. if (!netif_running(bp->dev))
  7644. goto period_task_exit;
  7645. if (CHIP_REV_IS_SLOW(bp)) {
  7646. BNX2X_ERR("period task called on emulation, ignoring\n");
  7647. goto period_task_exit;
  7648. }
  7649. bnx2x_acquire_phy_lock(bp);
  7650. /*
  7651. * The barrier is needed to ensure the ordering between the writing to
  7652. * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
  7653. * the reading here.
  7654. */
  7655. smp_mb();
  7656. if (bp->port.pmf) {
  7657. bnx2x_period_func(&bp->link_params, &bp->link_vars);
  7658. /* Re-queue task in 1 sec */
  7659. queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
  7660. }
  7661. bnx2x_release_phy_lock(bp);
  7662. period_task_exit:
  7663. return;
  7664. }
  7665. /*
  7666. * Init service functions
  7667. */
  7668. static u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
  7669. {
  7670. u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
  7671. u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
  7672. return base + (BP_ABS_FUNC(bp)) * stride;
  7673. }
  7674. static void bnx2x_undi_int_disable_e1h(struct bnx2x *bp)
  7675. {
  7676. u32 reg = bnx2x_get_pretend_reg(bp);
  7677. /* Flush all outstanding writes */
  7678. mmiowb();
  7679. /* Pretend to be function 0 */
  7680. REG_WR(bp, reg, 0);
  7681. REG_RD(bp, reg); /* Flush the GRC transaction (in the chip) */
  7682. /* From now we are in the "like-E1" mode */
  7683. bnx2x_int_disable(bp);
  7684. /* Flush all outstanding writes */
  7685. mmiowb();
  7686. /* Restore the original function */
  7687. REG_WR(bp, reg, BP_ABS_FUNC(bp));
  7688. REG_RD(bp, reg);
  7689. }
  7690. static inline void bnx2x_undi_int_disable(struct bnx2x *bp)
  7691. {
  7692. if (CHIP_IS_E1(bp))
  7693. bnx2x_int_disable(bp);
  7694. else
  7695. bnx2x_undi_int_disable_e1h(bp);
  7696. }
  7697. static void __devinit bnx2x_prev_unload_close_mac(struct bnx2x *bp)
  7698. {
  7699. u32 val, base_addr, offset, mask, reset_reg;
  7700. bool mac_stopped = false;
  7701. u8 port = BP_PORT(bp);
  7702. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
  7703. if (!CHIP_IS_E3(bp)) {
  7704. val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
  7705. mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
  7706. if ((mask & reset_reg) && val) {
  7707. u32 wb_data[2];
  7708. BNX2X_DEV_INFO("Disable bmac Rx\n");
  7709. base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
  7710. : NIG_REG_INGRESS_BMAC0_MEM;
  7711. offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
  7712. : BIGMAC_REGISTER_BMAC_CONTROL;
  7713. /*
  7714. * use rd/wr since we cannot use dmae. This is safe
  7715. * since MCP won't access the bus due to the request
  7716. * to unload, and no function on the path can be
  7717. * loaded at this time.
  7718. */
  7719. wb_data[0] = REG_RD(bp, base_addr + offset);
  7720. wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
  7721. wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
  7722. REG_WR(bp, base_addr + offset, wb_data[0]);
  7723. REG_WR(bp, base_addr + offset + 0x4, wb_data[1]);
  7724. }
  7725. BNX2X_DEV_INFO("Disable emac Rx\n");
  7726. REG_WR(bp, NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4, 0);
  7727. mac_stopped = true;
  7728. } else {
  7729. if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
  7730. BNX2X_DEV_INFO("Disable xmac Rx\n");
  7731. base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  7732. val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
  7733. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  7734. val & ~(1 << 1));
  7735. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  7736. val | (1 << 1));
  7737. REG_WR(bp, base_addr + XMAC_REG_CTRL, 0);
  7738. mac_stopped = true;
  7739. }
  7740. mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
  7741. if (mask & reset_reg) {
  7742. BNX2X_DEV_INFO("Disable umac Rx\n");
  7743. base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
  7744. REG_WR(bp, base_addr + UMAC_REG_COMMAND_CONFIG, 0);
  7745. mac_stopped = true;
  7746. }
  7747. }
  7748. if (mac_stopped)
  7749. msleep(20);
  7750. }
  7751. #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
  7752. #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
  7753. #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
  7754. #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
  7755. static void __devinit bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port,
  7756. u8 inc)
  7757. {
  7758. u16 rcq, bd;
  7759. u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
  7760. rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
  7761. bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
  7762. tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
  7763. REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
  7764. BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
  7765. port, bd, rcq);
  7766. }
  7767. static int __devinit bnx2x_prev_mcp_done(struct bnx2x *bp)
  7768. {
  7769. u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  7770. if (!rc) {
  7771. BNX2X_ERR("MCP response failure, aborting\n");
  7772. return -EBUSY;
  7773. }
  7774. return 0;
  7775. }
  7776. static bool __devinit bnx2x_prev_is_path_marked(struct bnx2x *bp)
  7777. {
  7778. struct bnx2x_prev_path_list *tmp_list;
  7779. int rc = false;
  7780. if (down_trylock(&bnx2x_prev_sem))
  7781. return false;
  7782. list_for_each_entry(tmp_list, &bnx2x_prev_list, list) {
  7783. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  7784. bp->pdev->bus->number == tmp_list->bus &&
  7785. BP_PATH(bp) == tmp_list->path) {
  7786. rc = true;
  7787. BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
  7788. BP_PATH(bp));
  7789. break;
  7790. }
  7791. }
  7792. up(&bnx2x_prev_sem);
  7793. return rc;
  7794. }
  7795. static int __devinit bnx2x_prev_mark_path(struct bnx2x *bp)
  7796. {
  7797. struct bnx2x_prev_path_list *tmp_list;
  7798. int rc;
  7799. tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
  7800. if (!tmp_list) {
  7801. BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
  7802. return -ENOMEM;
  7803. }
  7804. tmp_list->bus = bp->pdev->bus->number;
  7805. tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
  7806. tmp_list->path = BP_PATH(bp);
  7807. rc = down_interruptible(&bnx2x_prev_sem);
  7808. if (rc) {
  7809. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  7810. kfree(tmp_list);
  7811. } else {
  7812. BNX2X_DEV_INFO("Marked path [%d] - finished previous unload\n",
  7813. BP_PATH(bp));
  7814. list_add(&tmp_list->list, &bnx2x_prev_list);
  7815. up(&bnx2x_prev_sem);
  7816. }
  7817. return rc;
  7818. }
  7819. static int __devinit bnx2x_do_flr(struct bnx2x *bp)
  7820. {
  7821. int i, pos;
  7822. u16 status;
  7823. struct pci_dev *dev = bp->pdev;
  7824. if (CHIP_IS_E1x(bp)) {
  7825. BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
  7826. return -EINVAL;
  7827. }
  7828. /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
  7829. if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
  7830. BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
  7831. bp->common.bc_ver);
  7832. return -EINVAL;
  7833. }
  7834. pos = pci_pcie_cap(dev);
  7835. if (!pos)
  7836. return -ENOTTY;
  7837. /* Wait for Transaction Pending bit clean */
  7838. for (i = 0; i < 4; i++) {
  7839. if (i)
  7840. msleep((1 << (i - 1)) * 100);
  7841. pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, &status);
  7842. if (!(status & PCI_EXP_DEVSTA_TRPND))
  7843. goto clear;
  7844. }
  7845. dev_err(&dev->dev,
  7846. "transaction is not cleared; proceeding with reset anyway\n");
  7847. clear:
  7848. BNX2X_DEV_INFO("Initiating FLR\n");
  7849. bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
  7850. return 0;
  7851. }
  7852. static int __devinit bnx2x_prev_unload_uncommon(struct bnx2x *bp)
  7853. {
  7854. int rc;
  7855. BNX2X_DEV_INFO("Uncommon unload Flow\n");
  7856. /* Test if previous unload process was already finished for this path */
  7857. if (bnx2x_prev_is_path_marked(bp))
  7858. return bnx2x_prev_mcp_done(bp);
  7859. /* If function has FLR capabilities, and existing FW version matches
  7860. * the one required, then FLR will be sufficient to clean any residue
  7861. * left by previous driver
  7862. */
  7863. rc = bnx2x_test_firmware_version(bp, false);
  7864. if (!rc) {
  7865. /* fw version is good */
  7866. BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
  7867. rc = bnx2x_do_flr(bp);
  7868. }
  7869. if (!rc) {
  7870. /* FLR was performed */
  7871. BNX2X_DEV_INFO("FLR successful\n");
  7872. return 0;
  7873. }
  7874. BNX2X_DEV_INFO("Could not FLR\n");
  7875. /* Close the MCP request, return failure*/
  7876. rc = bnx2x_prev_mcp_done(bp);
  7877. if (!rc)
  7878. rc = BNX2X_PREV_WAIT_NEEDED;
  7879. return rc;
  7880. }
  7881. static int __devinit bnx2x_prev_unload_common(struct bnx2x *bp)
  7882. {
  7883. u32 reset_reg, tmp_reg = 0, rc;
  7884. /* It is possible a previous function received 'common' answer,
  7885. * but hasn't loaded yet, therefore creating a scenario of
  7886. * multiple functions receiving 'common' on the same path.
  7887. */
  7888. BNX2X_DEV_INFO("Common unload Flow\n");
  7889. if (bnx2x_prev_is_path_marked(bp))
  7890. return bnx2x_prev_mcp_done(bp);
  7891. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  7892. /* Reset should be performed after BRB is emptied */
  7893. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
  7894. u32 timer_count = 1000;
  7895. bool prev_undi = false;
  7896. /* Close the MAC Rx to prevent BRB from filling up */
  7897. bnx2x_prev_unload_close_mac(bp);
  7898. /* Check if the UNDI driver was previously loaded
  7899. * UNDI driver initializes CID offset for normal bell to 0x7
  7900. */
  7901. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  7902. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
  7903. tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
  7904. if (tmp_reg == 0x7) {
  7905. BNX2X_DEV_INFO("UNDI previously loaded\n");
  7906. prev_undi = true;
  7907. /* clear the UNDI indication */
  7908. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  7909. }
  7910. }
  7911. /* wait until BRB is empty */
  7912. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  7913. while (timer_count) {
  7914. u32 prev_brb = tmp_reg;
  7915. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  7916. if (!tmp_reg)
  7917. break;
  7918. BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
  7919. /* reset timer as long as BRB actually gets emptied */
  7920. if (prev_brb > tmp_reg)
  7921. timer_count = 1000;
  7922. else
  7923. timer_count--;
  7924. /* If UNDI resides in memory, manually increment it */
  7925. if (prev_undi)
  7926. bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
  7927. udelay(10);
  7928. }
  7929. if (!timer_count)
  7930. BNX2X_ERR("Failed to empty BRB, hope for the best\n");
  7931. }
  7932. /* No packets are in the pipeline, path is ready for reset */
  7933. bnx2x_reset_common(bp);
  7934. rc = bnx2x_prev_mark_path(bp);
  7935. if (rc) {
  7936. bnx2x_prev_mcp_done(bp);
  7937. return rc;
  7938. }
  7939. return bnx2x_prev_mcp_done(bp);
  7940. }
  7941. /* previous driver DMAE transaction may have occurred when pre-boot stage ended
  7942. * and boot began, or when kdump kernel was loaded. Either case would invalidate
  7943. * the addresses of the transaction, resulting in was-error bit set in the pci
  7944. * causing all hw-to-host pcie transactions to timeout. If this happened we want
  7945. * to clear the interrupt which detected this from the pglueb and the was done
  7946. * bit
  7947. */
  7948. static void __devinit bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
  7949. {
  7950. u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
  7951. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
  7952. BNX2X_ERR("was error bit was found to be set in pglueb upon startup. Clearing");
  7953. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, 1 << BP_FUNC(bp));
  7954. }
  7955. }
  7956. static int __devinit bnx2x_prev_unload(struct bnx2x *bp)
  7957. {
  7958. int time_counter = 10;
  7959. u32 rc, fw, hw_lock_reg, hw_lock_val;
  7960. BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
  7961. /* clear hw from errors which may have resulted from an interrupted
  7962. * dmae transaction.
  7963. */
  7964. bnx2x_prev_interrupted_dmae(bp);
  7965. /* Release previously held locks */
  7966. hw_lock_reg = (BP_FUNC(bp) <= 5) ?
  7967. (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
  7968. (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
  7969. hw_lock_val = (REG_RD(bp, hw_lock_reg));
  7970. if (hw_lock_val) {
  7971. if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
  7972. BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
  7973. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  7974. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
  7975. }
  7976. BNX2X_DEV_INFO("Release Previously held hw lock\n");
  7977. REG_WR(bp, hw_lock_reg, 0xffffffff);
  7978. } else
  7979. BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
  7980. if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
  7981. BNX2X_DEV_INFO("Release previously held alr\n");
  7982. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
  7983. }
  7984. do {
  7985. /* Lock MCP using an unload request */
  7986. fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
  7987. if (!fw) {
  7988. BNX2X_ERR("MCP response failure, aborting\n");
  7989. rc = -EBUSY;
  7990. break;
  7991. }
  7992. if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON) {
  7993. rc = bnx2x_prev_unload_common(bp);
  7994. break;
  7995. }
  7996. /* non-common reply from MCP night require looping */
  7997. rc = bnx2x_prev_unload_uncommon(bp);
  7998. if (rc != BNX2X_PREV_WAIT_NEEDED)
  7999. break;
  8000. msleep(20);
  8001. } while (--time_counter);
  8002. if (!time_counter || rc) {
  8003. BNX2X_ERR("Failed unloading previous driver, aborting\n");
  8004. rc = -EBUSY;
  8005. }
  8006. BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
  8007. return rc;
  8008. }
  8009. static void __devinit bnx2x_get_common_hwinfo(struct bnx2x *bp)
  8010. {
  8011. u32 val, val2, val3, val4, id, boot_mode;
  8012. u16 pmc;
  8013. /* Get the chip revision id and number. */
  8014. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  8015. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  8016. id = ((val & 0xffff) << 16);
  8017. val = REG_RD(bp, MISC_REG_CHIP_REV);
  8018. id |= ((val & 0xf) << 12);
  8019. val = REG_RD(bp, MISC_REG_CHIP_METAL);
  8020. id |= ((val & 0xff) << 4);
  8021. val = REG_RD(bp, MISC_REG_BOND_ID);
  8022. id |= (val & 0xf);
  8023. bp->common.chip_id = id;
  8024. /* force 57811 according to MISC register */
  8025. if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
  8026. if (CHIP_IS_57810(bp))
  8027. bp->common.chip_id = (CHIP_NUM_57811 << 16) |
  8028. (bp->common.chip_id & 0x0000FFFF);
  8029. else if (CHIP_IS_57810_MF(bp))
  8030. bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
  8031. (bp->common.chip_id & 0x0000FFFF);
  8032. bp->common.chip_id |= 0x1;
  8033. }
  8034. /* Set doorbell size */
  8035. bp->db_size = (1 << BNX2X_DB_SHIFT);
  8036. if (!CHIP_IS_E1x(bp)) {
  8037. val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  8038. if ((val & 1) == 0)
  8039. val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
  8040. else
  8041. val = (val >> 1) & 1;
  8042. BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
  8043. "2_PORT_MODE");
  8044. bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
  8045. CHIP_2_PORT_MODE;
  8046. if (CHIP_MODE_IS_4_PORT(bp))
  8047. bp->pfid = (bp->pf_num >> 1); /* 0..3 */
  8048. else
  8049. bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
  8050. } else {
  8051. bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
  8052. bp->pfid = bp->pf_num; /* 0..7 */
  8053. }
  8054. BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
  8055. bp->link_params.chip_id = bp->common.chip_id;
  8056. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  8057. val = (REG_RD(bp, 0x2874) & 0x55);
  8058. if ((bp->common.chip_id & 0x1) ||
  8059. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  8060. bp->flags |= ONE_PORT_FLAG;
  8061. BNX2X_DEV_INFO("single port device\n");
  8062. }
  8063. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  8064. bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
  8065. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  8066. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  8067. bp->common.flash_size, bp->common.flash_size);
  8068. bnx2x_init_shmem(bp);
  8069. bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
  8070. MISC_REG_GENERIC_CR_1 :
  8071. MISC_REG_GENERIC_CR_0));
  8072. bp->link_params.shmem_base = bp->common.shmem_base;
  8073. bp->link_params.shmem2_base = bp->common.shmem2_base;
  8074. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  8075. bp->common.shmem_base, bp->common.shmem2_base);
  8076. if (!bp->common.shmem_base) {
  8077. BNX2X_DEV_INFO("MCP not active\n");
  8078. bp->flags |= NO_MCP_FLAG;
  8079. return;
  8080. }
  8081. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  8082. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  8083. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  8084. SHARED_HW_CFG_LED_MODE_MASK) >>
  8085. SHARED_HW_CFG_LED_MODE_SHIFT);
  8086. bp->link_params.feature_config_flags = 0;
  8087. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  8088. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  8089. bp->link_params.feature_config_flags |=
  8090. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8091. else
  8092. bp->link_params.feature_config_flags &=
  8093. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8094. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  8095. bp->common.bc_ver = val;
  8096. BNX2X_DEV_INFO("bc_ver %X\n", val);
  8097. if (val < BNX2X_BC_VER) {
  8098. /* for now only warn
  8099. * later we might need to enforce this */
  8100. BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
  8101. BNX2X_BC_VER, val);
  8102. }
  8103. bp->link_params.feature_config_flags |=
  8104. (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
  8105. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  8106. bp->link_params.feature_config_flags |=
  8107. (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
  8108. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
  8109. bp->link_params.feature_config_flags |=
  8110. (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
  8111. FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
  8112. bp->link_params.feature_config_flags |=
  8113. (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
  8114. FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
  8115. bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
  8116. BC_SUPPORTS_PFC_STATS : 0;
  8117. bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
  8118. BC_SUPPORTS_FCOE_FEATURES : 0;
  8119. bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
  8120. BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
  8121. boot_mode = SHMEM_RD(bp,
  8122. dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
  8123. PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
  8124. switch (boot_mode) {
  8125. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
  8126. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
  8127. break;
  8128. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
  8129. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
  8130. break;
  8131. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
  8132. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
  8133. break;
  8134. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
  8135. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
  8136. break;
  8137. }
  8138. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
  8139. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  8140. BNX2X_DEV_INFO("%sWoL capable\n",
  8141. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  8142. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  8143. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  8144. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  8145. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  8146. dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
  8147. val, val2, val3, val4);
  8148. }
  8149. #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
  8150. #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
  8151. static void __devinit bnx2x_get_igu_cam_info(struct bnx2x *bp)
  8152. {
  8153. int pfid = BP_FUNC(bp);
  8154. int igu_sb_id;
  8155. u32 val;
  8156. u8 fid, igu_sb_cnt = 0;
  8157. bp->igu_base_sb = 0xff;
  8158. if (CHIP_INT_MODE_IS_BC(bp)) {
  8159. int vn = BP_VN(bp);
  8160. igu_sb_cnt = bp->igu_sb_cnt;
  8161. bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
  8162. FP_SB_MAX_E1x;
  8163. bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
  8164. (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
  8165. return;
  8166. }
  8167. /* IGU in normal mode - read CAM */
  8168. for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
  8169. igu_sb_id++) {
  8170. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
  8171. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  8172. continue;
  8173. fid = IGU_FID(val);
  8174. if ((fid & IGU_FID_ENCODE_IS_PF)) {
  8175. if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
  8176. continue;
  8177. if (IGU_VEC(val) == 0)
  8178. /* default status block */
  8179. bp->igu_dsb_id = igu_sb_id;
  8180. else {
  8181. if (bp->igu_base_sb == 0xff)
  8182. bp->igu_base_sb = igu_sb_id;
  8183. igu_sb_cnt++;
  8184. }
  8185. }
  8186. }
  8187. #ifdef CONFIG_PCI_MSI
  8188. /*
  8189. * It's expected that number of CAM entries for this functions is equal
  8190. * to the number evaluated based on the MSI-X table size. We want a
  8191. * harsh warning if these values are different!
  8192. */
  8193. WARN_ON(bp->igu_sb_cnt != igu_sb_cnt);
  8194. #endif
  8195. if (igu_sb_cnt == 0)
  8196. BNX2X_ERR("CAM configuration error\n");
  8197. }
  8198. static void __devinit bnx2x_link_settings_supported(struct bnx2x *bp,
  8199. u32 switch_cfg)
  8200. {
  8201. int cfg_size = 0, idx, port = BP_PORT(bp);
  8202. /* Aggregation of supported attributes of all external phys */
  8203. bp->port.supported[0] = 0;
  8204. bp->port.supported[1] = 0;
  8205. switch (bp->link_params.num_phys) {
  8206. case 1:
  8207. bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
  8208. cfg_size = 1;
  8209. break;
  8210. case 2:
  8211. bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
  8212. cfg_size = 1;
  8213. break;
  8214. case 3:
  8215. if (bp->link_params.multi_phy_config &
  8216. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  8217. bp->port.supported[1] =
  8218. bp->link_params.phy[EXT_PHY1].supported;
  8219. bp->port.supported[0] =
  8220. bp->link_params.phy[EXT_PHY2].supported;
  8221. } else {
  8222. bp->port.supported[0] =
  8223. bp->link_params.phy[EXT_PHY1].supported;
  8224. bp->port.supported[1] =
  8225. bp->link_params.phy[EXT_PHY2].supported;
  8226. }
  8227. cfg_size = 2;
  8228. break;
  8229. }
  8230. if (!(bp->port.supported[0] || bp->port.supported[1])) {
  8231. BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
  8232. SHMEM_RD(bp,
  8233. dev_info.port_hw_config[port].external_phy_config),
  8234. SHMEM_RD(bp,
  8235. dev_info.port_hw_config[port].external_phy_config2));
  8236. return;
  8237. }
  8238. if (CHIP_IS_E3(bp))
  8239. bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
  8240. else {
  8241. switch (switch_cfg) {
  8242. case SWITCH_CFG_1G:
  8243. bp->port.phy_addr = REG_RD(
  8244. bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
  8245. break;
  8246. case SWITCH_CFG_10G:
  8247. bp->port.phy_addr = REG_RD(
  8248. bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
  8249. break;
  8250. default:
  8251. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  8252. bp->port.link_config[0]);
  8253. return;
  8254. }
  8255. }
  8256. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  8257. /* mask what we support according to speed_cap_mask per configuration */
  8258. for (idx = 0; idx < cfg_size; idx++) {
  8259. if (!(bp->link_params.speed_cap_mask[idx] &
  8260. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  8261. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
  8262. if (!(bp->link_params.speed_cap_mask[idx] &
  8263. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  8264. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
  8265. if (!(bp->link_params.speed_cap_mask[idx] &
  8266. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  8267. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
  8268. if (!(bp->link_params.speed_cap_mask[idx] &
  8269. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  8270. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
  8271. if (!(bp->link_params.speed_cap_mask[idx] &
  8272. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  8273. bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
  8274. SUPPORTED_1000baseT_Full);
  8275. if (!(bp->link_params.speed_cap_mask[idx] &
  8276. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  8277. bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
  8278. if (!(bp->link_params.speed_cap_mask[idx] &
  8279. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  8280. bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
  8281. }
  8282. BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
  8283. bp->port.supported[1]);
  8284. }
  8285. static void __devinit bnx2x_link_settings_requested(struct bnx2x *bp)
  8286. {
  8287. u32 link_config, idx, cfg_size = 0;
  8288. bp->port.advertising[0] = 0;
  8289. bp->port.advertising[1] = 0;
  8290. switch (bp->link_params.num_phys) {
  8291. case 1:
  8292. case 2:
  8293. cfg_size = 1;
  8294. break;
  8295. case 3:
  8296. cfg_size = 2;
  8297. break;
  8298. }
  8299. for (idx = 0; idx < cfg_size; idx++) {
  8300. bp->link_params.req_duplex[idx] = DUPLEX_FULL;
  8301. link_config = bp->port.link_config[idx];
  8302. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  8303. case PORT_FEATURE_LINK_SPEED_AUTO:
  8304. if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
  8305. bp->link_params.req_line_speed[idx] =
  8306. SPEED_AUTO_NEG;
  8307. bp->port.advertising[idx] |=
  8308. bp->port.supported[idx];
  8309. if (bp->link_params.phy[EXT_PHY1].type ==
  8310. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  8311. bp->port.advertising[idx] |=
  8312. (SUPPORTED_100baseT_Half |
  8313. SUPPORTED_100baseT_Full);
  8314. } else {
  8315. /* force 10G, no AN */
  8316. bp->link_params.req_line_speed[idx] =
  8317. SPEED_10000;
  8318. bp->port.advertising[idx] |=
  8319. (ADVERTISED_10000baseT_Full |
  8320. ADVERTISED_FIBRE);
  8321. continue;
  8322. }
  8323. break;
  8324. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  8325. if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
  8326. bp->link_params.req_line_speed[idx] =
  8327. SPEED_10;
  8328. bp->port.advertising[idx] |=
  8329. (ADVERTISED_10baseT_Full |
  8330. ADVERTISED_TP);
  8331. } else {
  8332. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8333. link_config,
  8334. bp->link_params.speed_cap_mask[idx]);
  8335. return;
  8336. }
  8337. break;
  8338. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  8339. if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
  8340. bp->link_params.req_line_speed[idx] =
  8341. SPEED_10;
  8342. bp->link_params.req_duplex[idx] =
  8343. DUPLEX_HALF;
  8344. bp->port.advertising[idx] |=
  8345. (ADVERTISED_10baseT_Half |
  8346. ADVERTISED_TP);
  8347. } else {
  8348. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8349. link_config,
  8350. bp->link_params.speed_cap_mask[idx]);
  8351. return;
  8352. }
  8353. break;
  8354. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  8355. if (bp->port.supported[idx] &
  8356. SUPPORTED_100baseT_Full) {
  8357. bp->link_params.req_line_speed[idx] =
  8358. SPEED_100;
  8359. bp->port.advertising[idx] |=
  8360. (ADVERTISED_100baseT_Full |
  8361. ADVERTISED_TP);
  8362. } else {
  8363. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8364. link_config,
  8365. bp->link_params.speed_cap_mask[idx]);
  8366. return;
  8367. }
  8368. break;
  8369. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  8370. if (bp->port.supported[idx] &
  8371. SUPPORTED_100baseT_Half) {
  8372. bp->link_params.req_line_speed[idx] =
  8373. SPEED_100;
  8374. bp->link_params.req_duplex[idx] =
  8375. DUPLEX_HALF;
  8376. bp->port.advertising[idx] |=
  8377. (ADVERTISED_100baseT_Half |
  8378. ADVERTISED_TP);
  8379. } else {
  8380. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8381. link_config,
  8382. bp->link_params.speed_cap_mask[idx]);
  8383. return;
  8384. }
  8385. break;
  8386. case PORT_FEATURE_LINK_SPEED_1G:
  8387. if (bp->port.supported[idx] &
  8388. SUPPORTED_1000baseT_Full) {
  8389. bp->link_params.req_line_speed[idx] =
  8390. SPEED_1000;
  8391. bp->port.advertising[idx] |=
  8392. (ADVERTISED_1000baseT_Full |
  8393. ADVERTISED_TP);
  8394. } else {
  8395. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8396. link_config,
  8397. bp->link_params.speed_cap_mask[idx]);
  8398. return;
  8399. }
  8400. break;
  8401. case PORT_FEATURE_LINK_SPEED_2_5G:
  8402. if (bp->port.supported[idx] &
  8403. SUPPORTED_2500baseX_Full) {
  8404. bp->link_params.req_line_speed[idx] =
  8405. SPEED_2500;
  8406. bp->port.advertising[idx] |=
  8407. (ADVERTISED_2500baseX_Full |
  8408. ADVERTISED_TP);
  8409. } else {
  8410. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8411. link_config,
  8412. bp->link_params.speed_cap_mask[idx]);
  8413. return;
  8414. }
  8415. break;
  8416. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  8417. if (bp->port.supported[idx] &
  8418. SUPPORTED_10000baseT_Full) {
  8419. bp->link_params.req_line_speed[idx] =
  8420. SPEED_10000;
  8421. bp->port.advertising[idx] |=
  8422. (ADVERTISED_10000baseT_Full |
  8423. ADVERTISED_FIBRE);
  8424. } else {
  8425. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8426. link_config,
  8427. bp->link_params.speed_cap_mask[idx]);
  8428. return;
  8429. }
  8430. break;
  8431. case PORT_FEATURE_LINK_SPEED_20G:
  8432. bp->link_params.req_line_speed[idx] = SPEED_20000;
  8433. break;
  8434. default:
  8435. BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
  8436. link_config);
  8437. bp->link_params.req_line_speed[idx] =
  8438. SPEED_AUTO_NEG;
  8439. bp->port.advertising[idx] =
  8440. bp->port.supported[idx];
  8441. break;
  8442. }
  8443. bp->link_params.req_flow_ctrl[idx] = (link_config &
  8444. PORT_FEATURE_FLOW_CONTROL_MASK);
  8445. if ((bp->link_params.req_flow_ctrl[idx] ==
  8446. BNX2X_FLOW_CTRL_AUTO) &&
  8447. !(bp->port.supported[idx] & SUPPORTED_Autoneg)) {
  8448. bp->link_params.req_flow_ctrl[idx] =
  8449. BNX2X_FLOW_CTRL_NONE;
  8450. }
  8451. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
  8452. bp->link_params.req_line_speed[idx],
  8453. bp->link_params.req_duplex[idx],
  8454. bp->link_params.req_flow_ctrl[idx],
  8455. bp->port.advertising[idx]);
  8456. }
  8457. }
  8458. static void __devinit bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  8459. {
  8460. mac_hi = cpu_to_be16(mac_hi);
  8461. mac_lo = cpu_to_be32(mac_lo);
  8462. memcpy(mac_buf, &mac_hi, sizeof(mac_hi));
  8463. memcpy(mac_buf + sizeof(mac_hi), &mac_lo, sizeof(mac_lo));
  8464. }
  8465. static void __devinit bnx2x_get_port_hwinfo(struct bnx2x *bp)
  8466. {
  8467. int port = BP_PORT(bp);
  8468. u32 config;
  8469. u32 ext_phy_type, ext_phy_config, eee_mode;
  8470. bp->link_params.bp = bp;
  8471. bp->link_params.port = port;
  8472. bp->link_params.lane_config =
  8473. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  8474. bp->link_params.speed_cap_mask[0] =
  8475. SHMEM_RD(bp,
  8476. dev_info.port_hw_config[port].speed_capability_mask);
  8477. bp->link_params.speed_cap_mask[1] =
  8478. SHMEM_RD(bp,
  8479. dev_info.port_hw_config[port].speed_capability_mask2);
  8480. bp->port.link_config[0] =
  8481. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  8482. bp->port.link_config[1] =
  8483. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
  8484. bp->link_params.multi_phy_config =
  8485. SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
  8486. /* If the device is capable of WoL, set the default state according
  8487. * to the HW
  8488. */
  8489. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  8490. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  8491. (config & PORT_FEATURE_WOL_ENABLED));
  8492. BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
  8493. bp->link_params.lane_config,
  8494. bp->link_params.speed_cap_mask[0],
  8495. bp->port.link_config[0]);
  8496. bp->link_params.switch_cfg = (bp->port.link_config[0] &
  8497. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  8498. bnx2x_phy_probe(&bp->link_params);
  8499. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  8500. bnx2x_link_settings_requested(bp);
  8501. /*
  8502. * If connected directly, work with the internal PHY, otherwise, work
  8503. * with the external PHY
  8504. */
  8505. ext_phy_config =
  8506. SHMEM_RD(bp,
  8507. dev_info.port_hw_config[port].external_phy_config);
  8508. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  8509. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  8510. bp->mdio.prtad = bp->port.phy_addr;
  8511. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  8512. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  8513. bp->mdio.prtad =
  8514. XGXS_EXT_PHY_ADDR(ext_phy_config);
  8515. /*
  8516. * Check if hw lock is required to access MDC/MDIO bus to the PHY(s)
  8517. * In MF mode, it is set to cover self test cases
  8518. */
  8519. if (IS_MF(bp))
  8520. bp->port.need_hw_lock = 1;
  8521. else
  8522. bp->port.need_hw_lock = bnx2x_hw_lock_required(bp,
  8523. bp->common.shmem_base,
  8524. bp->common.shmem2_base);
  8525. /* Configure link feature according to nvram value */
  8526. eee_mode = (((SHMEM_RD(bp, dev_info.
  8527. port_feature_config[port].eee_power_mode)) &
  8528. PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
  8529. PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
  8530. if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
  8531. bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
  8532. EEE_MODE_ENABLE_LPI |
  8533. EEE_MODE_OUTPUT_TIME;
  8534. } else {
  8535. bp->link_params.eee_mode = 0;
  8536. }
  8537. }
  8538. void bnx2x_get_iscsi_info(struct bnx2x *bp)
  8539. {
  8540. u32 no_flags = NO_ISCSI_FLAG;
  8541. #ifdef BCM_CNIC
  8542. int port = BP_PORT(bp);
  8543. u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  8544. drv_lic_key[port].max_iscsi_conn);
  8545. /* Get the number of maximum allowed iSCSI connections */
  8546. bp->cnic_eth_dev.max_iscsi_conn =
  8547. (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
  8548. BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
  8549. BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
  8550. bp->cnic_eth_dev.max_iscsi_conn);
  8551. /*
  8552. * If maximum allowed number of connections is zero -
  8553. * disable the feature.
  8554. */
  8555. if (!bp->cnic_eth_dev.max_iscsi_conn)
  8556. bp->flags |= no_flags;
  8557. #else
  8558. bp->flags |= no_flags;
  8559. #endif
  8560. }
  8561. #ifdef BCM_CNIC
  8562. static void __devinit bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
  8563. {
  8564. /* Port info */
  8565. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  8566. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
  8567. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  8568. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
  8569. /* Node info */
  8570. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  8571. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
  8572. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  8573. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
  8574. }
  8575. #endif
  8576. static void __devinit bnx2x_get_fcoe_info(struct bnx2x *bp)
  8577. {
  8578. #ifdef BCM_CNIC
  8579. int port = BP_PORT(bp);
  8580. int func = BP_ABS_FUNC(bp);
  8581. u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  8582. drv_lic_key[port].max_fcoe_conn);
  8583. /* Get the number of maximum allowed FCoE connections */
  8584. bp->cnic_eth_dev.max_fcoe_conn =
  8585. (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
  8586. BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
  8587. /* Read the WWN: */
  8588. if (!IS_MF(bp)) {
  8589. /* Port info */
  8590. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  8591. SHMEM_RD(bp,
  8592. dev_info.port_hw_config[port].
  8593. fcoe_wwn_port_name_upper);
  8594. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  8595. SHMEM_RD(bp,
  8596. dev_info.port_hw_config[port].
  8597. fcoe_wwn_port_name_lower);
  8598. /* Node info */
  8599. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  8600. SHMEM_RD(bp,
  8601. dev_info.port_hw_config[port].
  8602. fcoe_wwn_node_name_upper);
  8603. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  8604. SHMEM_RD(bp,
  8605. dev_info.port_hw_config[port].
  8606. fcoe_wwn_node_name_lower);
  8607. } else if (!IS_MF_SD(bp)) {
  8608. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  8609. /*
  8610. * Read the WWN info only if the FCoE feature is enabled for
  8611. * this function.
  8612. */
  8613. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD)
  8614. bnx2x_get_ext_wwn_info(bp, func);
  8615. } else if (IS_MF_FCOE_SD(bp))
  8616. bnx2x_get_ext_wwn_info(bp, func);
  8617. BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
  8618. /*
  8619. * If maximum allowed number of connections is zero -
  8620. * disable the feature.
  8621. */
  8622. if (!bp->cnic_eth_dev.max_fcoe_conn)
  8623. bp->flags |= NO_FCOE_FLAG;
  8624. #else
  8625. bp->flags |= NO_FCOE_FLAG;
  8626. #endif
  8627. }
  8628. static void __devinit bnx2x_get_cnic_info(struct bnx2x *bp)
  8629. {
  8630. /*
  8631. * iSCSI may be dynamically disabled but reading
  8632. * info here we will decrease memory usage by driver
  8633. * if the feature is disabled for good
  8634. */
  8635. bnx2x_get_iscsi_info(bp);
  8636. bnx2x_get_fcoe_info(bp);
  8637. }
  8638. static void __devinit bnx2x_get_mac_hwinfo(struct bnx2x *bp)
  8639. {
  8640. u32 val, val2;
  8641. int func = BP_ABS_FUNC(bp);
  8642. int port = BP_PORT(bp);
  8643. #ifdef BCM_CNIC
  8644. u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
  8645. u8 *fip_mac = bp->fip_mac;
  8646. #endif
  8647. /* Zero primary MAC configuration */
  8648. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  8649. if (BP_NOMCP(bp)) {
  8650. BNX2X_ERROR("warning: random MAC workaround active\n");
  8651. eth_hw_addr_random(bp->dev);
  8652. } else if (IS_MF(bp)) {
  8653. val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  8654. val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
  8655. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  8656. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
  8657. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  8658. #ifdef BCM_CNIC
  8659. /*
  8660. * iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
  8661. * FCoE MAC then the appropriate feature should be disabled.
  8662. *
  8663. * In non SD mode features configuration comes from
  8664. * struct func_ext_config.
  8665. */
  8666. if (!IS_MF_SD(bp)) {
  8667. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  8668. if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
  8669. val2 = MF_CFG_RD(bp, func_ext_config[func].
  8670. iscsi_mac_addr_upper);
  8671. val = MF_CFG_RD(bp, func_ext_config[func].
  8672. iscsi_mac_addr_lower);
  8673. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  8674. BNX2X_DEV_INFO("Read iSCSI MAC: %pM\n",
  8675. iscsi_mac);
  8676. } else
  8677. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  8678. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  8679. val2 = MF_CFG_RD(bp, func_ext_config[func].
  8680. fcoe_mac_addr_upper);
  8681. val = MF_CFG_RD(bp, func_ext_config[func].
  8682. fcoe_mac_addr_lower);
  8683. bnx2x_set_mac_buf(fip_mac, val, val2);
  8684. BNX2X_DEV_INFO("Read FCoE L2 MAC: %pM\n",
  8685. fip_mac);
  8686. } else
  8687. bp->flags |= NO_FCOE_FLAG;
  8688. bp->mf_ext_config = cfg;
  8689. } else { /* SD MODE */
  8690. if (IS_MF_STORAGE_SD(bp)) {
  8691. if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
  8692. /* use primary mac as iscsi mac */
  8693. memcpy(iscsi_mac, bp->dev->dev_addr,
  8694. ETH_ALEN);
  8695. BNX2X_DEV_INFO("SD ISCSI MODE\n");
  8696. BNX2X_DEV_INFO("Read iSCSI MAC: %pM\n",
  8697. iscsi_mac);
  8698. } else { /* FCoE */
  8699. memcpy(fip_mac, bp->dev->dev_addr,
  8700. ETH_ALEN);
  8701. BNX2X_DEV_INFO("SD FCoE MODE\n");
  8702. BNX2X_DEV_INFO("Read FIP MAC: %pM\n",
  8703. fip_mac);
  8704. }
  8705. /* Zero primary MAC configuration */
  8706. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  8707. }
  8708. }
  8709. if (IS_MF_FCOE_AFEX(bp))
  8710. /* use FIP MAC as primary MAC */
  8711. memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
  8712. #endif
  8713. } else {
  8714. /* in SF read MACs from port configuration */
  8715. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  8716. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  8717. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  8718. #ifdef BCM_CNIC
  8719. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  8720. iscsi_mac_upper);
  8721. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  8722. iscsi_mac_lower);
  8723. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  8724. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  8725. fcoe_fip_mac_upper);
  8726. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  8727. fcoe_fip_mac_lower);
  8728. bnx2x_set_mac_buf(fip_mac, val, val2);
  8729. #endif
  8730. }
  8731. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  8732. memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN);
  8733. #ifdef BCM_CNIC
  8734. /* Disable iSCSI if MAC configuration is
  8735. * invalid.
  8736. */
  8737. if (!is_valid_ether_addr(iscsi_mac)) {
  8738. bp->flags |= NO_ISCSI_FLAG;
  8739. memset(iscsi_mac, 0, ETH_ALEN);
  8740. }
  8741. /* Disable FCoE if MAC configuration is
  8742. * invalid.
  8743. */
  8744. if (!is_valid_ether_addr(fip_mac)) {
  8745. bp->flags |= NO_FCOE_FLAG;
  8746. memset(bp->fip_mac, 0, ETH_ALEN);
  8747. }
  8748. #endif
  8749. if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
  8750. dev_err(&bp->pdev->dev,
  8751. "bad Ethernet MAC address configuration: %pM\n"
  8752. "change it manually before bringing up the appropriate network interface\n",
  8753. bp->dev->dev_addr);
  8754. }
  8755. static int __devinit bnx2x_get_hwinfo(struct bnx2x *bp)
  8756. {
  8757. int /*abs*/func = BP_ABS_FUNC(bp);
  8758. int vn;
  8759. u32 val = 0;
  8760. int rc = 0;
  8761. bnx2x_get_common_hwinfo(bp);
  8762. /*
  8763. * initialize IGU parameters
  8764. */
  8765. if (CHIP_IS_E1x(bp)) {
  8766. bp->common.int_block = INT_BLOCK_HC;
  8767. bp->igu_dsb_id = DEF_SB_IGU_ID;
  8768. bp->igu_base_sb = 0;
  8769. } else {
  8770. bp->common.int_block = INT_BLOCK_IGU;
  8771. /* do not allow device reset during IGU info preocessing */
  8772. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  8773. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  8774. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  8775. int tout = 5000;
  8776. BNX2X_DEV_INFO("FORCING Normal Mode\n");
  8777. val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
  8778. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
  8779. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
  8780. while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  8781. tout--;
  8782. usleep_range(1000, 1000);
  8783. }
  8784. if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  8785. dev_err(&bp->pdev->dev,
  8786. "FORCING Normal Mode failed!!!\n");
  8787. return -EPERM;
  8788. }
  8789. }
  8790. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  8791. BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
  8792. bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
  8793. } else
  8794. BNX2X_DEV_INFO("IGU Normal Mode\n");
  8795. bnx2x_get_igu_cam_info(bp);
  8796. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  8797. }
  8798. /*
  8799. * set base FW non-default (fast path) status block id, this value is
  8800. * used to initialize the fw_sb_id saved on the fp/queue structure to
  8801. * determine the id used by the FW.
  8802. */
  8803. if (CHIP_IS_E1x(bp))
  8804. bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
  8805. else /*
  8806. * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
  8807. * the same queue are indicated on the same IGU SB). So we prefer
  8808. * FW and IGU SBs to be the same value.
  8809. */
  8810. bp->base_fw_ndsb = bp->igu_base_sb;
  8811. BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
  8812. "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
  8813. bp->igu_sb_cnt, bp->base_fw_ndsb);
  8814. /*
  8815. * Initialize MF configuration
  8816. */
  8817. bp->mf_ov = 0;
  8818. bp->mf_mode = 0;
  8819. vn = BP_VN(bp);
  8820. if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
  8821. BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
  8822. bp->common.shmem2_base, SHMEM2_RD(bp, size),
  8823. (u32)offsetof(struct shmem2_region, mf_cfg_addr));
  8824. if (SHMEM2_HAS(bp, mf_cfg_addr))
  8825. bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
  8826. else
  8827. bp->common.mf_cfg_base = bp->common.shmem_base +
  8828. offsetof(struct shmem_region, func_mb) +
  8829. E1H_FUNC_MAX * sizeof(struct drv_func_mb);
  8830. /*
  8831. * get mf configuration:
  8832. * 1. existence of MF configuration
  8833. * 2. MAC address must be legal (check only upper bytes)
  8834. * for Switch-Independent mode;
  8835. * OVLAN must be legal for Switch-Dependent mode
  8836. * 3. SF_MODE configures specific MF mode
  8837. */
  8838. if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  8839. /* get mf configuration */
  8840. val = SHMEM_RD(bp,
  8841. dev_info.shared_feature_config.config);
  8842. val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
  8843. switch (val) {
  8844. case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
  8845. val = MF_CFG_RD(bp, func_mf_config[func].
  8846. mac_upper);
  8847. /* check for legal mac (upper bytes)*/
  8848. if (val != 0xffff) {
  8849. bp->mf_mode = MULTI_FUNCTION_SI;
  8850. bp->mf_config[vn] = MF_CFG_RD(bp,
  8851. func_mf_config[func].config);
  8852. } else
  8853. BNX2X_DEV_INFO("illegal MAC address for SI\n");
  8854. break;
  8855. case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
  8856. if ((!CHIP_IS_E1x(bp)) &&
  8857. (MF_CFG_RD(bp, func_mf_config[func].
  8858. mac_upper) != 0xffff) &&
  8859. (SHMEM2_HAS(bp,
  8860. afex_driver_support))) {
  8861. bp->mf_mode = MULTI_FUNCTION_AFEX;
  8862. bp->mf_config[vn] = MF_CFG_RD(bp,
  8863. func_mf_config[func].config);
  8864. } else {
  8865. BNX2X_DEV_INFO("can not configure afex mode\n");
  8866. }
  8867. break;
  8868. case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
  8869. /* get OV configuration */
  8870. val = MF_CFG_RD(bp,
  8871. func_mf_config[FUNC_0].e1hov_tag);
  8872. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  8873. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  8874. bp->mf_mode = MULTI_FUNCTION_SD;
  8875. bp->mf_config[vn] = MF_CFG_RD(bp,
  8876. func_mf_config[func].config);
  8877. } else
  8878. BNX2X_DEV_INFO("illegal OV for SD\n");
  8879. break;
  8880. default:
  8881. /* Unknown configuration: reset mf_config */
  8882. bp->mf_config[vn] = 0;
  8883. BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
  8884. }
  8885. }
  8886. BNX2X_DEV_INFO("%s function mode\n",
  8887. IS_MF(bp) ? "multi" : "single");
  8888. switch (bp->mf_mode) {
  8889. case MULTI_FUNCTION_SD:
  8890. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  8891. FUNC_MF_CFG_E1HOV_TAG_MASK;
  8892. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  8893. bp->mf_ov = val;
  8894. bp->path_has_ovlan = true;
  8895. BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
  8896. func, bp->mf_ov, bp->mf_ov);
  8897. } else {
  8898. dev_err(&bp->pdev->dev,
  8899. "No valid MF OV for func %d, aborting\n",
  8900. func);
  8901. return -EPERM;
  8902. }
  8903. break;
  8904. case MULTI_FUNCTION_AFEX:
  8905. BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
  8906. break;
  8907. case MULTI_FUNCTION_SI:
  8908. BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
  8909. func);
  8910. break;
  8911. default:
  8912. if (vn) {
  8913. dev_err(&bp->pdev->dev,
  8914. "VN %d is in a single function mode, aborting\n",
  8915. vn);
  8916. return -EPERM;
  8917. }
  8918. break;
  8919. }
  8920. /* check if other port on the path needs ovlan:
  8921. * Since MF configuration is shared between ports
  8922. * Possible mixed modes are only
  8923. * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
  8924. */
  8925. if (CHIP_MODE_IS_4_PORT(bp) &&
  8926. !bp->path_has_ovlan &&
  8927. !IS_MF(bp) &&
  8928. bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  8929. u8 other_port = !BP_PORT(bp);
  8930. u8 other_func = BP_PATH(bp) + 2*other_port;
  8931. val = MF_CFG_RD(bp,
  8932. func_mf_config[other_func].e1hov_tag);
  8933. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  8934. bp->path_has_ovlan = true;
  8935. }
  8936. }
  8937. /* adjust igu_sb_cnt to MF for E1x */
  8938. if (CHIP_IS_E1x(bp) && IS_MF(bp))
  8939. bp->igu_sb_cnt /= E1HVN_MAX;
  8940. /* port info */
  8941. bnx2x_get_port_hwinfo(bp);
  8942. /* Get MAC addresses */
  8943. bnx2x_get_mac_hwinfo(bp);
  8944. bnx2x_get_cnic_info(bp);
  8945. return rc;
  8946. }
  8947. static void __devinit bnx2x_read_fwinfo(struct bnx2x *bp)
  8948. {
  8949. int cnt, i, block_end, rodi;
  8950. char vpd_start[BNX2X_VPD_LEN+1];
  8951. char str_id_reg[VENDOR_ID_LEN+1];
  8952. char str_id_cap[VENDOR_ID_LEN+1];
  8953. char *vpd_data;
  8954. char *vpd_extended_data = NULL;
  8955. u8 len;
  8956. cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
  8957. memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
  8958. if (cnt < BNX2X_VPD_LEN)
  8959. goto out_not_found;
  8960. /* VPD RO tag should be first tag after identifier string, hence
  8961. * we should be able to find it in first BNX2X_VPD_LEN chars
  8962. */
  8963. i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
  8964. PCI_VPD_LRDT_RO_DATA);
  8965. if (i < 0)
  8966. goto out_not_found;
  8967. block_end = i + PCI_VPD_LRDT_TAG_SIZE +
  8968. pci_vpd_lrdt_size(&vpd_start[i]);
  8969. i += PCI_VPD_LRDT_TAG_SIZE;
  8970. if (block_end > BNX2X_VPD_LEN) {
  8971. vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
  8972. if (vpd_extended_data == NULL)
  8973. goto out_not_found;
  8974. /* read rest of vpd image into vpd_extended_data */
  8975. memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
  8976. cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
  8977. block_end - BNX2X_VPD_LEN,
  8978. vpd_extended_data + BNX2X_VPD_LEN);
  8979. if (cnt < (block_end - BNX2X_VPD_LEN))
  8980. goto out_not_found;
  8981. vpd_data = vpd_extended_data;
  8982. } else
  8983. vpd_data = vpd_start;
  8984. /* now vpd_data holds full vpd content in both cases */
  8985. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  8986. PCI_VPD_RO_KEYWORD_MFR_ID);
  8987. if (rodi < 0)
  8988. goto out_not_found;
  8989. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  8990. if (len != VENDOR_ID_LEN)
  8991. goto out_not_found;
  8992. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  8993. /* vendor specific info */
  8994. snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
  8995. snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
  8996. if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
  8997. !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
  8998. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  8999. PCI_VPD_RO_KEYWORD_VENDOR0);
  9000. if (rodi >= 0) {
  9001. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9002. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9003. if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
  9004. memcpy(bp->fw_ver, &vpd_data[rodi], len);
  9005. bp->fw_ver[len] = ' ';
  9006. }
  9007. }
  9008. kfree(vpd_extended_data);
  9009. return;
  9010. }
  9011. out_not_found:
  9012. kfree(vpd_extended_data);
  9013. return;
  9014. }
  9015. static void __devinit bnx2x_set_modes_bitmap(struct bnx2x *bp)
  9016. {
  9017. u32 flags = 0;
  9018. if (CHIP_REV_IS_FPGA(bp))
  9019. SET_FLAGS(flags, MODE_FPGA);
  9020. else if (CHIP_REV_IS_EMUL(bp))
  9021. SET_FLAGS(flags, MODE_EMUL);
  9022. else
  9023. SET_FLAGS(flags, MODE_ASIC);
  9024. if (CHIP_MODE_IS_4_PORT(bp))
  9025. SET_FLAGS(flags, MODE_PORT4);
  9026. else
  9027. SET_FLAGS(flags, MODE_PORT2);
  9028. if (CHIP_IS_E2(bp))
  9029. SET_FLAGS(flags, MODE_E2);
  9030. else if (CHIP_IS_E3(bp)) {
  9031. SET_FLAGS(flags, MODE_E3);
  9032. if (CHIP_REV(bp) == CHIP_REV_Ax)
  9033. SET_FLAGS(flags, MODE_E3_A0);
  9034. else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
  9035. SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
  9036. }
  9037. if (IS_MF(bp)) {
  9038. SET_FLAGS(flags, MODE_MF);
  9039. switch (bp->mf_mode) {
  9040. case MULTI_FUNCTION_SD:
  9041. SET_FLAGS(flags, MODE_MF_SD);
  9042. break;
  9043. case MULTI_FUNCTION_SI:
  9044. SET_FLAGS(flags, MODE_MF_SI);
  9045. break;
  9046. case MULTI_FUNCTION_AFEX:
  9047. SET_FLAGS(flags, MODE_MF_AFEX);
  9048. break;
  9049. }
  9050. } else
  9051. SET_FLAGS(flags, MODE_SF);
  9052. #if defined(__LITTLE_ENDIAN)
  9053. SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
  9054. #else /*(__BIG_ENDIAN)*/
  9055. SET_FLAGS(flags, MODE_BIG_ENDIAN);
  9056. #endif
  9057. INIT_MODE_FLAGS(bp) = flags;
  9058. }
  9059. static int __devinit bnx2x_init_bp(struct bnx2x *bp)
  9060. {
  9061. int func;
  9062. int rc;
  9063. mutex_init(&bp->port.phy_mutex);
  9064. mutex_init(&bp->fw_mb_mutex);
  9065. spin_lock_init(&bp->stats_lock);
  9066. #ifdef BCM_CNIC
  9067. mutex_init(&bp->cnic_mutex);
  9068. #endif
  9069. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  9070. INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
  9071. INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
  9072. rc = bnx2x_get_hwinfo(bp);
  9073. if (rc)
  9074. return rc;
  9075. bnx2x_set_modes_bitmap(bp);
  9076. rc = bnx2x_alloc_mem_bp(bp);
  9077. if (rc)
  9078. return rc;
  9079. bnx2x_read_fwinfo(bp);
  9080. func = BP_FUNC(bp);
  9081. /* need to reset chip if undi was active */
  9082. if (!BP_NOMCP(bp)) {
  9083. /* init fw_seq */
  9084. bp->fw_seq =
  9085. SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  9086. DRV_MSG_SEQ_NUMBER_MASK;
  9087. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  9088. bnx2x_prev_unload(bp);
  9089. }
  9090. if (CHIP_REV_IS_FPGA(bp))
  9091. dev_err(&bp->pdev->dev, "FPGA detected\n");
  9092. if (BP_NOMCP(bp) && (func == 0))
  9093. dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
  9094. bp->disable_tpa = disable_tpa;
  9095. #ifdef BCM_CNIC
  9096. bp->disable_tpa |= IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp);
  9097. #endif
  9098. /* Set TPA flags */
  9099. if (bp->disable_tpa) {
  9100. bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9101. bp->dev->features &= ~NETIF_F_LRO;
  9102. } else {
  9103. bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9104. bp->dev->features |= NETIF_F_LRO;
  9105. }
  9106. if (CHIP_IS_E1(bp))
  9107. bp->dropless_fc = 0;
  9108. else
  9109. bp->dropless_fc = dropless_fc;
  9110. bp->mrrs = mrrs;
  9111. bp->tx_ring_size = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
  9112. /* make sure that the numbers are in the right granularity */
  9113. bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
  9114. bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
  9115. bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
  9116. init_timer(&bp->timer);
  9117. bp->timer.expires = jiffies + bp->current_interval;
  9118. bp->timer.data = (unsigned long) bp;
  9119. bp->timer.function = bnx2x_timer;
  9120. bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
  9121. bnx2x_dcbx_init_params(bp);
  9122. #ifdef BCM_CNIC
  9123. if (CHIP_IS_E1x(bp))
  9124. bp->cnic_base_cl_id = FP_SB_MAX_E1x;
  9125. else
  9126. bp->cnic_base_cl_id = FP_SB_MAX_E2;
  9127. #endif
  9128. /* multiple tx priority */
  9129. if (CHIP_IS_E1x(bp))
  9130. bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
  9131. if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
  9132. bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
  9133. if (CHIP_IS_E3B0(bp))
  9134. bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
  9135. return rc;
  9136. }
  9137. /****************************************************************************
  9138. * General service functions
  9139. ****************************************************************************/
  9140. /*
  9141. * net_device service functions
  9142. */
  9143. /* called with rtnl_lock */
  9144. static int bnx2x_open(struct net_device *dev)
  9145. {
  9146. struct bnx2x *bp = netdev_priv(dev);
  9147. bool global = false;
  9148. int other_engine = BP_PATH(bp) ? 0 : 1;
  9149. bool other_load_status, load_status;
  9150. bp->stats_init = true;
  9151. netif_carrier_off(dev);
  9152. bnx2x_set_power_state(bp, PCI_D0);
  9153. other_load_status = bnx2x_get_load_status(bp, other_engine);
  9154. load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
  9155. /*
  9156. * If parity had happen during the unload, then attentions
  9157. * and/or RECOVERY_IN_PROGRES may still be set. In this case we
  9158. * want the first function loaded on the current engine to
  9159. * complete the recovery.
  9160. */
  9161. if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
  9162. bnx2x_chk_parity_attn(bp, &global, true))
  9163. do {
  9164. /*
  9165. * If there are attentions and they are in a global
  9166. * blocks, set the GLOBAL_RESET bit regardless whether
  9167. * it will be this function that will complete the
  9168. * recovery or not.
  9169. */
  9170. if (global)
  9171. bnx2x_set_reset_global(bp);
  9172. /*
  9173. * Only the first function on the current engine should
  9174. * try to recover in open. In case of attentions in
  9175. * global blocks only the first in the chip should try
  9176. * to recover.
  9177. */
  9178. if ((!load_status &&
  9179. (!global || !other_load_status)) &&
  9180. bnx2x_trylock_leader_lock(bp) &&
  9181. !bnx2x_leader_reset(bp)) {
  9182. netdev_info(bp->dev, "Recovered in open\n");
  9183. break;
  9184. }
  9185. /* recovery has failed... */
  9186. bnx2x_set_power_state(bp, PCI_D3hot);
  9187. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  9188. BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
  9189. "If you still see this message after a few retries then power cycle is required.\n");
  9190. return -EAGAIN;
  9191. } while (0);
  9192. bp->recovery_state = BNX2X_RECOVERY_DONE;
  9193. return bnx2x_nic_load(bp, LOAD_OPEN);
  9194. }
  9195. /* called with rtnl_lock */
  9196. static int bnx2x_close(struct net_device *dev)
  9197. {
  9198. struct bnx2x *bp = netdev_priv(dev);
  9199. /* Unload the driver, release IRQs */
  9200. bnx2x_nic_unload(bp, UNLOAD_CLOSE);
  9201. /* Power off */
  9202. bnx2x_set_power_state(bp, PCI_D3hot);
  9203. return 0;
  9204. }
  9205. static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
  9206. struct bnx2x_mcast_ramrod_params *p)
  9207. {
  9208. int mc_count = netdev_mc_count(bp->dev);
  9209. struct bnx2x_mcast_list_elem *mc_mac =
  9210. kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
  9211. struct netdev_hw_addr *ha;
  9212. if (!mc_mac)
  9213. return -ENOMEM;
  9214. INIT_LIST_HEAD(&p->mcast_list);
  9215. netdev_for_each_mc_addr(ha, bp->dev) {
  9216. mc_mac->mac = bnx2x_mc_addr(ha);
  9217. list_add_tail(&mc_mac->link, &p->mcast_list);
  9218. mc_mac++;
  9219. }
  9220. p->mcast_list_len = mc_count;
  9221. return 0;
  9222. }
  9223. static void bnx2x_free_mcast_macs_list(
  9224. struct bnx2x_mcast_ramrod_params *p)
  9225. {
  9226. struct bnx2x_mcast_list_elem *mc_mac =
  9227. list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
  9228. link);
  9229. WARN_ON(!mc_mac);
  9230. kfree(mc_mac);
  9231. }
  9232. /**
  9233. * bnx2x_set_uc_list - configure a new unicast MACs list.
  9234. *
  9235. * @bp: driver handle
  9236. *
  9237. * We will use zero (0) as a MAC type for these MACs.
  9238. */
  9239. static int bnx2x_set_uc_list(struct bnx2x *bp)
  9240. {
  9241. int rc;
  9242. struct net_device *dev = bp->dev;
  9243. struct netdev_hw_addr *ha;
  9244. struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
  9245. unsigned long ramrod_flags = 0;
  9246. /* First schedule a cleanup up of old configuration */
  9247. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
  9248. if (rc < 0) {
  9249. BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
  9250. return rc;
  9251. }
  9252. netdev_for_each_uc_addr(ha, dev) {
  9253. rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
  9254. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9255. if (rc < 0) {
  9256. BNX2X_ERR("Failed to schedule ADD operations: %d\n",
  9257. rc);
  9258. return rc;
  9259. }
  9260. }
  9261. /* Execute the pending commands */
  9262. __set_bit(RAMROD_CONT, &ramrod_flags);
  9263. return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
  9264. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9265. }
  9266. static int bnx2x_set_mc_list(struct bnx2x *bp)
  9267. {
  9268. struct net_device *dev = bp->dev;
  9269. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  9270. int rc = 0;
  9271. rparam.mcast_obj = &bp->mcast_obj;
  9272. /* first, clear all configured multicast MACs */
  9273. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  9274. if (rc < 0) {
  9275. BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
  9276. return rc;
  9277. }
  9278. /* then, configure a new MACs list */
  9279. if (netdev_mc_count(dev)) {
  9280. rc = bnx2x_init_mcast_macs_list(bp, &rparam);
  9281. if (rc) {
  9282. BNX2X_ERR("Failed to create multicast MACs list: %d\n",
  9283. rc);
  9284. return rc;
  9285. }
  9286. /* Now add the new MACs */
  9287. rc = bnx2x_config_mcast(bp, &rparam,
  9288. BNX2X_MCAST_CMD_ADD);
  9289. if (rc < 0)
  9290. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  9291. rc);
  9292. bnx2x_free_mcast_macs_list(&rparam);
  9293. }
  9294. return rc;
  9295. }
  9296. /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
  9297. void bnx2x_set_rx_mode(struct net_device *dev)
  9298. {
  9299. struct bnx2x *bp = netdev_priv(dev);
  9300. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  9301. if (bp->state != BNX2X_STATE_OPEN) {
  9302. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  9303. return;
  9304. }
  9305. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
  9306. if (dev->flags & IFF_PROMISC)
  9307. rx_mode = BNX2X_RX_MODE_PROMISC;
  9308. else if ((dev->flags & IFF_ALLMULTI) ||
  9309. ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
  9310. CHIP_IS_E1(bp)))
  9311. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  9312. else {
  9313. /* some multicasts */
  9314. if (bnx2x_set_mc_list(bp) < 0)
  9315. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  9316. if (bnx2x_set_uc_list(bp) < 0)
  9317. rx_mode = BNX2X_RX_MODE_PROMISC;
  9318. }
  9319. bp->rx_mode = rx_mode;
  9320. #ifdef BCM_CNIC
  9321. /* handle ISCSI SD mode */
  9322. if (IS_MF_ISCSI_SD(bp))
  9323. bp->rx_mode = BNX2X_RX_MODE_NONE;
  9324. #endif
  9325. /* Schedule the rx_mode command */
  9326. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
  9327. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  9328. return;
  9329. }
  9330. bnx2x_set_storm_rx_mode(bp);
  9331. }
  9332. /* called with rtnl_lock */
  9333. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  9334. int devad, u16 addr)
  9335. {
  9336. struct bnx2x *bp = netdev_priv(netdev);
  9337. u16 value;
  9338. int rc;
  9339. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  9340. prtad, devad, addr);
  9341. /* The HW expects different devad if CL22 is used */
  9342. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  9343. bnx2x_acquire_phy_lock(bp);
  9344. rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
  9345. bnx2x_release_phy_lock(bp);
  9346. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  9347. if (!rc)
  9348. rc = value;
  9349. return rc;
  9350. }
  9351. /* called with rtnl_lock */
  9352. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  9353. u16 addr, u16 value)
  9354. {
  9355. struct bnx2x *bp = netdev_priv(netdev);
  9356. int rc;
  9357. DP(NETIF_MSG_LINK,
  9358. "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
  9359. prtad, devad, addr, value);
  9360. /* The HW expects different devad if CL22 is used */
  9361. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  9362. bnx2x_acquire_phy_lock(bp);
  9363. rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
  9364. bnx2x_release_phy_lock(bp);
  9365. return rc;
  9366. }
  9367. /* called with rtnl_lock */
  9368. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  9369. {
  9370. struct bnx2x *bp = netdev_priv(dev);
  9371. struct mii_ioctl_data *mdio = if_mii(ifr);
  9372. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  9373. mdio->phy_id, mdio->reg_num, mdio->val_in);
  9374. if (!netif_running(dev))
  9375. return -EAGAIN;
  9376. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  9377. }
  9378. #ifdef CONFIG_NET_POLL_CONTROLLER
  9379. static void poll_bnx2x(struct net_device *dev)
  9380. {
  9381. struct bnx2x *bp = netdev_priv(dev);
  9382. int i;
  9383. for_each_eth_queue(bp, i) {
  9384. struct bnx2x_fastpath *fp = &bp->fp[i];
  9385. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  9386. }
  9387. }
  9388. #endif
  9389. static int bnx2x_validate_addr(struct net_device *dev)
  9390. {
  9391. struct bnx2x *bp = netdev_priv(dev);
  9392. if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
  9393. BNX2X_ERR("Non-valid Ethernet address\n");
  9394. return -EADDRNOTAVAIL;
  9395. }
  9396. return 0;
  9397. }
  9398. static const struct net_device_ops bnx2x_netdev_ops = {
  9399. .ndo_open = bnx2x_open,
  9400. .ndo_stop = bnx2x_close,
  9401. .ndo_start_xmit = bnx2x_start_xmit,
  9402. .ndo_select_queue = bnx2x_select_queue,
  9403. .ndo_set_rx_mode = bnx2x_set_rx_mode,
  9404. .ndo_set_mac_address = bnx2x_change_mac_addr,
  9405. .ndo_validate_addr = bnx2x_validate_addr,
  9406. .ndo_do_ioctl = bnx2x_ioctl,
  9407. .ndo_change_mtu = bnx2x_change_mtu,
  9408. .ndo_fix_features = bnx2x_fix_features,
  9409. .ndo_set_features = bnx2x_set_features,
  9410. .ndo_tx_timeout = bnx2x_tx_timeout,
  9411. #ifdef CONFIG_NET_POLL_CONTROLLER
  9412. .ndo_poll_controller = poll_bnx2x,
  9413. #endif
  9414. .ndo_setup_tc = bnx2x_setup_tc,
  9415. #if defined(NETDEV_FCOE_WWNN) && defined(BCM_CNIC)
  9416. .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
  9417. #endif
  9418. };
  9419. static int bnx2x_set_coherency_mask(struct bnx2x *bp)
  9420. {
  9421. struct device *dev = &bp->pdev->dev;
  9422. if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
  9423. bp->flags |= USING_DAC_FLAG;
  9424. if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
  9425. dev_err(dev, "dma_set_coherent_mask failed, aborting\n");
  9426. return -EIO;
  9427. }
  9428. } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
  9429. dev_err(dev, "System does not support DMA, aborting\n");
  9430. return -EIO;
  9431. }
  9432. return 0;
  9433. }
  9434. static int __devinit bnx2x_init_dev(struct pci_dev *pdev,
  9435. struct net_device *dev,
  9436. unsigned long board_type)
  9437. {
  9438. struct bnx2x *bp;
  9439. int rc;
  9440. u32 pci_cfg_dword;
  9441. bool chip_is_e1x = (board_type == BCM57710 ||
  9442. board_type == BCM57711 ||
  9443. board_type == BCM57711E);
  9444. SET_NETDEV_DEV(dev, &pdev->dev);
  9445. bp = netdev_priv(dev);
  9446. bp->dev = dev;
  9447. bp->pdev = pdev;
  9448. bp->flags = 0;
  9449. rc = pci_enable_device(pdev);
  9450. if (rc) {
  9451. dev_err(&bp->pdev->dev,
  9452. "Cannot enable PCI device, aborting\n");
  9453. goto err_out;
  9454. }
  9455. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  9456. dev_err(&bp->pdev->dev,
  9457. "Cannot find PCI device base address, aborting\n");
  9458. rc = -ENODEV;
  9459. goto err_out_disable;
  9460. }
  9461. if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  9462. dev_err(&bp->pdev->dev, "Cannot find second PCI device"
  9463. " base address, aborting\n");
  9464. rc = -ENODEV;
  9465. goto err_out_disable;
  9466. }
  9467. if (atomic_read(&pdev->enable_cnt) == 1) {
  9468. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  9469. if (rc) {
  9470. dev_err(&bp->pdev->dev,
  9471. "Cannot obtain PCI resources, aborting\n");
  9472. goto err_out_disable;
  9473. }
  9474. pci_set_master(pdev);
  9475. pci_save_state(pdev);
  9476. }
  9477. bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  9478. if (bp->pm_cap == 0) {
  9479. dev_err(&bp->pdev->dev,
  9480. "Cannot find power management capability, aborting\n");
  9481. rc = -EIO;
  9482. goto err_out_release;
  9483. }
  9484. if (!pci_is_pcie(pdev)) {
  9485. dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
  9486. rc = -EIO;
  9487. goto err_out_release;
  9488. }
  9489. rc = bnx2x_set_coherency_mask(bp);
  9490. if (rc)
  9491. goto err_out_release;
  9492. dev->mem_start = pci_resource_start(pdev, 0);
  9493. dev->base_addr = dev->mem_start;
  9494. dev->mem_end = pci_resource_end(pdev, 0);
  9495. dev->irq = pdev->irq;
  9496. bp->regview = pci_ioremap_bar(pdev, 0);
  9497. if (!bp->regview) {
  9498. dev_err(&bp->pdev->dev,
  9499. "Cannot map register space, aborting\n");
  9500. rc = -ENOMEM;
  9501. goto err_out_release;
  9502. }
  9503. /* In E1/E1H use pci device function given by kernel.
  9504. * In E2/E3 read physical function from ME register since these chips
  9505. * support Physical Device Assignment where kernel BDF maybe arbitrary
  9506. * (depending on hypervisor).
  9507. */
  9508. if (chip_is_e1x)
  9509. bp->pf_num = PCI_FUNC(pdev->devfn);
  9510. else {/* chip is E2/3*/
  9511. pci_read_config_dword(bp->pdev,
  9512. PCICFG_ME_REGISTER, &pci_cfg_dword);
  9513. bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
  9514. ME_REG_ABS_PF_NUM_SHIFT);
  9515. }
  9516. BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
  9517. bnx2x_set_power_state(bp, PCI_D0);
  9518. /* clean indirect addresses */
  9519. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  9520. PCICFG_VENDOR_ID_OFFSET);
  9521. /*
  9522. * Clean the following indirect addresses for all functions since it
  9523. * is not used by the driver.
  9524. */
  9525. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
  9526. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
  9527. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
  9528. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
  9529. if (chip_is_e1x) {
  9530. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
  9531. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
  9532. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
  9533. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
  9534. }
  9535. /*
  9536. * Enable internal target-read (in case we are probed after PF FLR).
  9537. * Must be done prior to any BAR read access. Only for 57712 and up
  9538. */
  9539. if (!chip_is_e1x)
  9540. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  9541. dev->watchdog_timeo = TX_TIMEOUT;
  9542. dev->netdev_ops = &bnx2x_netdev_ops;
  9543. bnx2x_set_ethtool_ops(dev);
  9544. dev->priv_flags |= IFF_UNICAST_FLT;
  9545. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  9546. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  9547. NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
  9548. NETIF_F_RXHASH | NETIF_F_HW_VLAN_TX;
  9549. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  9550. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
  9551. dev->features |= dev->hw_features | NETIF_F_HW_VLAN_RX;
  9552. if (bp->flags & USING_DAC_FLAG)
  9553. dev->features |= NETIF_F_HIGHDMA;
  9554. /* Add Loopback capability to the device */
  9555. dev->hw_features |= NETIF_F_LOOPBACK;
  9556. #ifdef BCM_DCBNL
  9557. dev->dcbnl_ops = &bnx2x_dcbnl_ops;
  9558. #endif
  9559. /* get_port_hwinfo() will set prtad and mmds properly */
  9560. bp->mdio.prtad = MDIO_PRTAD_NONE;
  9561. bp->mdio.mmds = 0;
  9562. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  9563. bp->mdio.dev = dev;
  9564. bp->mdio.mdio_read = bnx2x_mdio_read;
  9565. bp->mdio.mdio_write = bnx2x_mdio_write;
  9566. return 0;
  9567. err_out_release:
  9568. if (atomic_read(&pdev->enable_cnt) == 1)
  9569. pci_release_regions(pdev);
  9570. err_out_disable:
  9571. pci_disable_device(pdev);
  9572. pci_set_drvdata(pdev, NULL);
  9573. err_out:
  9574. return rc;
  9575. }
  9576. static void __devinit bnx2x_get_pcie_width_speed(struct bnx2x *bp,
  9577. int *width, int *speed)
  9578. {
  9579. u32 val = REG_RD(bp, PCICFG_OFFSET + PCICFG_LINK_CONTROL);
  9580. *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
  9581. /* return value of 1=2.5GHz 2=5GHz */
  9582. *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
  9583. }
  9584. static int bnx2x_check_firmware(struct bnx2x *bp)
  9585. {
  9586. const struct firmware *firmware = bp->firmware;
  9587. struct bnx2x_fw_file_hdr *fw_hdr;
  9588. struct bnx2x_fw_file_section *sections;
  9589. u32 offset, len, num_ops;
  9590. u16 *ops_offsets;
  9591. int i;
  9592. const u8 *fw_ver;
  9593. if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
  9594. BNX2X_ERR("Wrong FW size\n");
  9595. return -EINVAL;
  9596. }
  9597. fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
  9598. sections = (struct bnx2x_fw_file_section *)fw_hdr;
  9599. /* Make sure none of the offsets and sizes make us read beyond
  9600. * the end of the firmware data */
  9601. for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
  9602. offset = be32_to_cpu(sections[i].offset);
  9603. len = be32_to_cpu(sections[i].len);
  9604. if (offset + len > firmware->size) {
  9605. BNX2X_ERR("Section %d length is out of bounds\n", i);
  9606. return -EINVAL;
  9607. }
  9608. }
  9609. /* Likewise for the init_ops offsets */
  9610. offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
  9611. ops_offsets = (u16 *)(firmware->data + offset);
  9612. num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
  9613. for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
  9614. if (be16_to_cpu(ops_offsets[i]) > num_ops) {
  9615. BNX2X_ERR("Section offset %d is out of bounds\n", i);
  9616. return -EINVAL;
  9617. }
  9618. }
  9619. /* Check FW version */
  9620. offset = be32_to_cpu(fw_hdr->fw_version.offset);
  9621. fw_ver = firmware->data + offset;
  9622. if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
  9623. (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
  9624. (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
  9625. (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
  9626. BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
  9627. fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
  9628. BCM_5710_FW_MAJOR_VERSION,
  9629. BCM_5710_FW_MINOR_VERSION,
  9630. BCM_5710_FW_REVISION_VERSION,
  9631. BCM_5710_FW_ENGINEERING_VERSION);
  9632. return -EINVAL;
  9633. }
  9634. return 0;
  9635. }
  9636. static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  9637. {
  9638. const __be32 *source = (const __be32 *)_source;
  9639. u32 *target = (u32 *)_target;
  9640. u32 i;
  9641. for (i = 0; i < n/4; i++)
  9642. target[i] = be32_to_cpu(source[i]);
  9643. }
  9644. /*
  9645. Ops array is stored in the following format:
  9646. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  9647. */
  9648. static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  9649. {
  9650. const __be32 *source = (const __be32 *)_source;
  9651. struct raw_op *target = (struct raw_op *)_target;
  9652. u32 i, j, tmp;
  9653. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  9654. tmp = be32_to_cpu(source[j]);
  9655. target[i].op = (tmp >> 24) & 0xff;
  9656. target[i].offset = tmp & 0xffffff;
  9657. target[i].raw_data = be32_to_cpu(source[j + 1]);
  9658. }
  9659. }
  9660. /* IRO array is stored in the following format:
  9661. * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
  9662. */
  9663. static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
  9664. {
  9665. const __be32 *source = (const __be32 *)_source;
  9666. struct iro *target = (struct iro *)_target;
  9667. u32 i, j, tmp;
  9668. for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
  9669. target[i].base = be32_to_cpu(source[j]);
  9670. j++;
  9671. tmp = be32_to_cpu(source[j]);
  9672. target[i].m1 = (tmp >> 16) & 0xffff;
  9673. target[i].m2 = tmp & 0xffff;
  9674. j++;
  9675. tmp = be32_to_cpu(source[j]);
  9676. target[i].m3 = (tmp >> 16) & 0xffff;
  9677. target[i].size = tmp & 0xffff;
  9678. j++;
  9679. }
  9680. }
  9681. static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  9682. {
  9683. const __be16 *source = (const __be16 *)_source;
  9684. u16 *target = (u16 *)_target;
  9685. u32 i;
  9686. for (i = 0; i < n/2; i++)
  9687. target[i] = be16_to_cpu(source[i]);
  9688. }
  9689. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  9690. do { \
  9691. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  9692. bp->arr = kmalloc(len, GFP_KERNEL); \
  9693. if (!bp->arr) \
  9694. goto lbl; \
  9695. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  9696. (u8 *)bp->arr, len); \
  9697. } while (0)
  9698. static int bnx2x_init_firmware(struct bnx2x *bp)
  9699. {
  9700. const char *fw_file_name;
  9701. struct bnx2x_fw_file_hdr *fw_hdr;
  9702. int rc;
  9703. if (bp->firmware)
  9704. return 0;
  9705. if (CHIP_IS_E1(bp))
  9706. fw_file_name = FW_FILE_NAME_E1;
  9707. else if (CHIP_IS_E1H(bp))
  9708. fw_file_name = FW_FILE_NAME_E1H;
  9709. else if (!CHIP_IS_E1x(bp))
  9710. fw_file_name = FW_FILE_NAME_E2;
  9711. else {
  9712. BNX2X_ERR("Unsupported chip revision\n");
  9713. return -EINVAL;
  9714. }
  9715. BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
  9716. rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
  9717. if (rc) {
  9718. BNX2X_ERR("Can't load firmware file %s\n",
  9719. fw_file_name);
  9720. goto request_firmware_exit;
  9721. }
  9722. rc = bnx2x_check_firmware(bp);
  9723. if (rc) {
  9724. BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
  9725. goto request_firmware_exit;
  9726. }
  9727. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  9728. /* Initialize the pointers to the init arrays */
  9729. /* Blob */
  9730. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  9731. /* Opcodes */
  9732. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  9733. /* Offsets */
  9734. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  9735. be16_to_cpu_n);
  9736. /* STORMs firmware */
  9737. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  9738. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  9739. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  9740. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  9741. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  9742. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  9743. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  9744. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  9745. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  9746. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  9747. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  9748. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  9749. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  9750. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  9751. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  9752. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  9753. /* IRO */
  9754. BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
  9755. return 0;
  9756. iro_alloc_err:
  9757. kfree(bp->init_ops_offsets);
  9758. init_offsets_alloc_err:
  9759. kfree(bp->init_ops);
  9760. init_ops_alloc_err:
  9761. kfree(bp->init_data);
  9762. request_firmware_exit:
  9763. release_firmware(bp->firmware);
  9764. bp->firmware = NULL;
  9765. return rc;
  9766. }
  9767. static void bnx2x_release_firmware(struct bnx2x *bp)
  9768. {
  9769. kfree(bp->init_ops_offsets);
  9770. kfree(bp->init_ops);
  9771. kfree(bp->init_data);
  9772. release_firmware(bp->firmware);
  9773. bp->firmware = NULL;
  9774. }
  9775. static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
  9776. .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
  9777. .init_hw_cmn = bnx2x_init_hw_common,
  9778. .init_hw_port = bnx2x_init_hw_port,
  9779. .init_hw_func = bnx2x_init_hw_func,
  9780. .reset_hw_cmn = bnx2x_reset_common,
  9781. .reset_hw_port = bnx2x_reset_port,
  9782. .reset_hw_func = bnx2x_reset_func,
  9783. .gunzip_init = bnx2x_gunzip_init,
  9784. .gunzip_end = bnx2x_gunzip_end,
  9785. .init_fw = bnx2x_init_firmware,
  9786. .release_fw = bnx2x_release_firmware,
  9787. };
  9788. void bnx2x__init_func_obj(struct bnx2x *bp)
  9789. {
  9790. /* Prepare DMAE related driver resources */
  9791. bnx2x_setup_dmae(bp);
  9792. bnx2x_init_func_obj(bp, &bp->func_obj,
  9793. bnx2x_sp(bp, func_rdata),
  9794. bnx2x_sp_mapping(bp, func_rdata),
  9795. bnx2x_sp(bp, func_afex_rdata),
  9796. bnx2x_sp_mapping(bp, func_afex_rdata),
  9797. &bnx2x_func_sp_drv);
  9798. }
  9799. /* must be called after sriov-enable */
  9800. static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
  9801. {
  9802. int cid_count = BNX2X_L2_MAX_CID(bp);
  9803. #ifdef BCM_CNIC
  9804. cid_count += CNIC_CID_MAX;
  9805. #endif
  9806. return roundup(cid_count, QM_CID_ROUND);
  9807. }
  9808. /**
  9809. * bnx2x_get_num_none_def_sbs - return the number of none default SBs
  9810. *
  9811. * @dev: pci device
  9812. *
  9813. */
  9814. static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev)
  9815. {
  9816. int pos;
  9817. u16 control;
  9818. pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
  9819. /*
  9820. * If MSI-X is not supported - return number of SBs needed to support
  9821. * one fast path queue: one FP queue + SB for CNIC
  9822. */
  9823. if (!pos)
  9824. return 1 + CNIC_PRESENT;
  9825. /*
  9826. * The value in the PCI configuration space is the index of the last
  9827. * entry, namely one less than the actual size of the table, which is
  9828. * exactly what we want to return from this function: number of all SBs
  9829. * without the default SB.
  9830. */
  9831. pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control);
  9832. return control & PCI_MSIX_FLAGS_QSIZE;
  9833. }
  9834. static int __devinit bnx2x_init_one(struct pci_dev *pdev,
  9835. const struct pci_device_id *ent)
  9836. {
  9837. struct net_device *dev = NULL;
  9838. struct bnx2x *bp;
  9839. int pcie_width, pcie_speed;
  9840. int rc, max_non_def_sbs;
  9841. int rx_count, tx_count, rss_count, doorbell_size;
  9842. /*
  9843. * An estimated maximum supported CoS number according to the chip
  9844. * version.
  9845. * We will try to roughly estimate the maximum number of CoSes this chip
  9846. * may support in order to minimize the memory allocated for Tx
  9847. * netdev_queue's. This number will be accurately calculated during the
  9848. * initialization of bp->max_cos based on the chip versions AND chip
  9849. * revision in the bnx2x_init_bp().
  9850. */
  9851. u8 max_cos_est = 0;
  9852. switch (ent->driver_data) {
  9853. case BCM57710:
  9854. case BCM57711:
  9855. case BCM57711E:
  9856. max_cos_est = BNX2X_MULTI_TX_COS_E1X;
  9857. break;
  9858. case BCM57712:
  9859. case BCM57712_MF:
  9860. max_cos_est = BNX2X_MULTI_TX_COS_E2_E3A0;
  9861. break;
  9862. case BCM57800:
  9863. case BCM57800_MF:
  9864. case BCM57810:
  9865. case BCM57810_MF:
  9866. case BCM57840_O:
  9867. case BCM57840_4_10:
  9868. case BCM57840_2_20:
  9869. case BCM57840_MFO:
  9870. case BCM57840_MF:
  9871. case BCM57811:
  9872. case BCM57811_MF:
  9873. max_cos_est = BNX2X_MULTI_TX_COS_E3B0;
  9874. break;
  9875. default:
  9876. pr_err("Unknown board_type (%ld), aborting\n",
  9877. ent->driver_data);
  9878. return -ENODEV;
  9879. }
  9880. max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev);
  9881. WARN_ON(!max_non_def_sbs);
  9882. /* Maximum number of RSS queues: one IGU SB goes to CNIC */
  9883. rss_count = max_non_def_sbs - CNIC_PRESENT;
  9884. /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
  9885. rx_count = rss_count + FCOE_PRESENT;
  9886. /*
  9887. * Maximum number of netdev Tx queues:
  9888. * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
  9889. */
  9890. tx_count = rss_count * max_cos_est + FCOE_PRESENT;
  9891. /* dev zeroed in init_etherdev */
  9892. dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
  9893. if (!dev)
  9894. return -ENOMEM;
  9895. bp = netdev_priv(dev);
  9896. bp->igu_sb_cnt = max_non_def_sbs;
  9897. bp->msg_enable = debug;
  9898. pci_set_drvdata(pdev, dev);
  9899. rc = bnx2x_init_dev(pdev, dev, ent->driver_data);
  9900. if (rc < 0) {
  9901. free_netdev(dev);
  9902. return rc;
  9903. }
  9904. BNX2X_DEV_INFO("max_non_def_sbs %d\n", max_non_def_sbs);
  9905. BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
  9906. tx_count, rx_count);
  9907. rc = bnx2x_init_bp(bp);
  9908. if (rc)
  9909. goto init_one_exit;
  9910. /*
  9911. * Map doorbels here as we need the real value of bp->max_cos which
  9912. * is initialized in bnx2x_init_bp().
  9913. */
  9914. doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
  9915. if (doorbell_size > pci_resource_len(pdev, 2)) {
  9916. dev_err(&bp->pdev->dev,
  9917. "Cannot map doorbells, bar size too small, aborting\n");
  9918. rc = -ENOMEM;
  9919. goto init_one_exit;
  9920. }
  9921. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  9922. doorbell_size);
  9923. if (!bp->doorbells) {
  9924. dev_err(&bp->pdev->dev,
  9925. "Cannot map doorbell space, aborting\n");
  9926. rc = -ENOMEM;
  9927. goto init_one_exit;
  9928. }
  9929. /* calc qm_cid_count */
  9930. bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
  9931. #ifdef BCM_CNIC
  9932. /* disable FCOE L2 queue for E1x */
  9933. if (CHIP_IS_E1x(bp))
  9934. bp->flags |= NO_FCOE_FLAG;
  9935. #endif
  9936. /* Set bp->num_queues for MSI-X mode*/
  9937. bnx2x_set_num_queues(bp);
  9938. /* Configure interrupt mode: try to enable MSI-X/MSI if
  9939. * needed.
  9940. */
  9941. bnx2x_set_int_mode(bp);
  9942. rc = register_netdev(dev);
  9943. if (rc) {
  9944. dev_err(&pdev->dev, "Cannot register net device\n");
  9945. goto init_one_exit;
  9946. }
  9947. #ifdef BCM_CNIC
  9948. if (!NO_FCOE(bp)) {
  9949. /* Add storage MAC address */
  9950. rtnl_lock();
  9951. dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  9952. rtnl_unlock();
  9953. }
  9954. #endif
  9955. bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
  9956. BNX2X_DEV_INFO(
  9957. "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
  9958. board_info[ent->driver_data].name,
  9959. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  9960. pcie_width,
  9961. ((!CHIP_IS_E2(bp) && pcie_speed == 2) ||
  9962. (CHIP_IS_E2(bp) && pcie_speed == 1)) ?
  9963. "5GHz (Gen2)" : "2.5GHz",
  9964. dev->base_addr, bp->pdev->irq, dev->dev_addr);
  9965. return 0;
  9966. init_one_exit:
  9967. if (bp->regview)
  9968. iounmap(bp->regview);
  9969. if (bp->doorbells)
  9970. iounmap(bp->doorbells);
  9971. free_netdev(dev);
  9972. if (atomic_read(&pdev->enable_cnt) == 1)
  9973. pci_release_regions(pdev);
  9974. pci_disable_device(pdev);
  9975. pci_set_drvdata(pdev, NULL);
  9976. return rc;
  9977. }
  9978. static void __devexit bnx2x_remove_one(struct pci_dev *pdev)
  9979. {
  9980. struct net_device *dev = pci_get_drvdata(pdev);
  9981. struct bnx2x *bp;
  9982. if (!dev) {
  9983. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  9984. return;
  9985. }
  9986. bp = netdev_priv(dev);
  9987. #ifdef BCM_CNIC
  9988. /* Delete storage MAC address */
  9989. if (!NO_FCOE(bp)) {
  9990. rtnl_lock();
  9991. dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  9992. rtnl_unlock();
  9993. }
  9994. #endif
  9995. #ifdef BCM_DCBNL
  9996. /* Delete app tlvs from dcbnl */
  9997. bnx2x_dcbnl_update_applist(bp, true);
  9998. #endif
  9999. unregister_netdev(dev);
  10000. /* Power on: we can't let PCI layer write to us while we are in D3 */
  10001. bnx2x_set_power_state(bp, PCI_D0);
  10002. /* Disable MSI/MSI-X */
  10003. bnx2x_disable_msi(bp);
  10004. /* Power off */
  10005. bnx2x_set_power_state(bp, PCI_D3hot);
  10006. /* Make sure RESET task is not scheduled before continuing */
  10007. cancel_delayed_work_sync(&bp->sp_rtnl_task);
  10008. if (bp->regview)
  10009. iounmap(bp->regview);
  10010. if (bp->doorbells)
  10011. iounmap(bp->doorbells);
  10012. bnx2x_release_firmware(bp);
  10013. bnx2x_free_mem_bp(bp);
  10014. free_netdev(dev);
  10015. if (atomic_read(&pdev->enable_cnt) == 1)
  10016. pci_release_regions(pdev);
  10017. pci_disable_device(pdev);
  10018. pci_set_drvdata(pdev, NULL);
  10019. }
  10020. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  10021. {
  10022. int i;
  10023. bp->state = BNX2X_STATE_ERROR;
  10024. bp->rx_mode = BNX2X_RX_MODE_NONE;
  10025. #ifdef BCM_CNIC
  10026. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  10027. #endif
  10028. /* Stop Tx */
  10029. bnx2x_tx_disable(bp);
  10030. bnx2x_netif_stop(bp, 0);
  10031. /* Delete all NAPI objects */
  10032. bnx2x_del_all_napi(bp);
  10033. del_timer_sync(&bp->timer);
  10034. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  10035. /* Release IRQs */
  10036. bnx2x_free_irq(bp);
  10037. /* Free SKBs, SGEs, TPA pool and driver internals */
  10038. bnx2x_free_skbs(bp);
  10039. for_each_rx_queue(bp, i)
  10040. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  10041. bnx2x_free_mem(bp);
  10042. bp->state = BNX2X_STATE_CLOSED;
  10043. netif_carrier_off(bp->dev);
  10044. return 0;
  10045. }
  10046. static void bnx2x_eeh_recover(struct bnx2x *bp)
  10047. {
  10048. u32 val;
  10049. mutex_init(&bp->port.phy_mutex);
  10050. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  10051. if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  10052. != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  10053. BNX2X_ERR("BAD MCP validity signature\n");
  10054. }
  10055. /**
  10056. * bnx2x_io_error_detected - called when PCI error is detected
  10057. * @pdev: Pointer to PCI device
  10058. * @state: The current pci connection state
  10059. *
  10060. * This function is called after a PCI bus error affecting
  10061. * this device has been detected.
  10062. */
  10063. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  10064. pci_channel_state_t state)
  10065. {
  10066. struct net_device *dev = pci_get_drvdata(pdev);
  10067. struct bnx2x *bp = netdev_priv(dev);
  10068. rtnl_lock();
  10069. netif_device_detach(dev);
  10070. if (state == pci_channel_io_perm_failure) {
  10071. rtnl_unlock();
  10072. return PCI_ERS_RESULT_DISCONNECT;
  10073. }
  10074. if (netif_running(dev))
  10075. bnx2x_eeh_nic_unload(bp);
  10076. pci_disable_device(pdev);
  10077. rtnl_unlock();
  10078. /* Request a slot reset */
  10079. return PCI_ERS_RESULT_NEED_RESET;
  10080. }
  10081. /**
  10082. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  10083. * @pdev: Pointer to PCI device
  10084. *
  10085. * Restart the card from scratch, as if from a cold-boot.
  10086. */
  10087. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  10088. {
  10089. struct net_device *dev = pci_get_drvdata(pdev);
  10090. struct bnx2x *bp = netdev_priv(dev);
  10091. rtnl_lock();
  10092. if (pci_enable_device(pdev)) {
  10093. dev_err(&pdev->dev,
  10094. "Cannot re-enable PCI device after reset\n");
  10095. rtnl_unlock();
  10096. return PCI_ERS_RESULT_DISCONNECT;
  10097. }
  10098. pci_set_master(pdev);
  10099. pci_restore_state(pdev);
  10100. if (netif_running(dev))
  10101. bnx2x_set_power_state(bp, PCI_D0);
  10102. rtnl_unlock();
  10103. return PCI_ERS_RESULT_RECOVERED;
  10104. }
  10105. /**
  10106. * bnx2x_io_resume - called when traffic can start flowing again
  10107. * @pdev: Pointer to PCI device
  10108. *
  10109. * This callback is called when the error recovery driver tells us that
  10110. * its OK to resume normal operation.
  10111. */
  10112. static void bnx2x_io_resume(struct pci_dev *pdev)
  10113. {
  10114. struct net_device *dev = pci_get_drvdata(pdev);
  10115. struct bnx2x *bp = netdev_priv(dev);
  10116. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  10117. netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
  10118. return;
  10119. }
  10120. rtnl_lock();
  10121. bnx2x_eeh_recover(bp);
  10122. if (netif_running(dev))
  10123. bnx2x_nic_load(bp, LOAD_NORMAL);
  10124. netif_device_attach(dev);
  10125. rtnl_unlock();
  10126. }
  10127. static struct pci_error_handlers bnx2x_err_handler = {
  10128. .error_detected = bnx2x_io_error_detected,
  10129. .slot_reset = bnx2x_io_slot_reset,
  10130. .resume = bnx2x_io_resume,
  10131. };
  10132. static struct pci_driver bnx2x_pci_driver = {
  10133. .name = DRV_MODULE_NAME,
  10134. .id_table = bnx2x_pci_tbl,
  10135. .probe = bnx2x_init_one,
  10136. .remove = __devexit_p(bnx2x_remove_one),
  10137. .suspend = bnx2x_suspend,
  10138. .resume = bnx2x_resume,
  10139. .err_handler = &bnx2x_err_handler,
  10140. };
  10141. static int __init bnx2x_init(void)
  10142. {
  10143. int ret;
  10144. pr_info("%s", version);
  10145. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  10146. if (bnx2x_wq == NULL) {
  10147. pr_err("Cannot create workqueue\n");
  10148. return -ENOMEM;
  10149. }
  10150. ret = pci_register_driver(&bnx2x_pci_driver);
  10151. if (ret) {
  10152. pr_err("Cannot register driver\n");
  10153. destroy_workqueue(bnx2x_wq);
  10154. }
  10155. return ret;
  10156. }
  10157. static void __exit bnx2x_cleanup(void)
  10158. {
  10159. struct list_head *pos, *q;
  10160. pci_unregister_driver(&bnx2x_pci_driver);
  10161. destroy_workqueue(bnx2x_wq);
  10162. /* Free globablly allocated resources */
  10163. list_for_each_safe(pos, q, &bnx2x_prev_list) {
  10164. struct bnx2x_prev_path_list *tmp =
  10165. list_entry(pos, struct bnx2x_prev_path_list, list);
  10166. list_del(pos);
  10167. kfree(tmp);
  10168. }
  10169. }
  10170. void bnx2x_notify_link_changed(struct bnx2x *bp)
  10171. {
  10172. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
  10173. }
  10174. module_init(bnx2x_init);
  10175. module_exit(bnx2x_cleanup);
  10176. #ifdef BCM_CNIC
  10177. /**
  10178. * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
  10179. *
  10180. * @bp: driver handle
  10181. * @set: set or clear the CAM entry
  10182. *
  10183. * This function will wait until the ramdord completion returns.
  10184. * Return 0 if success, -ENODEV if ramrod doesn't return.
  10185. */
  10186. static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
  10187. {
  10188. unsigned long ramrod_flags = 0;
  10189. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  10190. return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
  10191. &bp->iscsi_l2_mac_obj, true,
  10192. BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
  10193. }
  10194. /* count denotes the number of new completions we have seen */
  10195. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  10196. {
  10197. struct eth_spe *spe;
  10198. int cxt_index, cxt_offset;
  10199. #ifdef BNX2X_STOP_ON_ERROR
  10200. if (unlikely(bp->panic))
  10201. return;
  10202. #endif
  10203. spin_lock_bh(&bp->spq_lock);
  10204. BUG_ON(bp->cnic_spq_pending < count);
  10205. bp->cnic_spq_pending -= count;
  10206. for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
  10207. u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
  10208. & SPE_HDR_CONN_TYPE) >>
  10209. SPE_HDR_CONN_TYPE_SHIFT;
  10210. u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
  10211. >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
  10212. /* Set validation for iSCSI L2 client before sending SETUP
  10213. * ramrod
  10214. */
  10215. if (type == ETH_CONNECTION_TYPE) {
  10216. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
  10217. cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
  10218. ILT_PAGE_CIDS;
  10219. cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
  10220. (cxt_index * ILT_PAGE_CIDS);
  10221. bnx2x_set_ctx_validation(bp,
  10222. &bp->context[cxt_index].
  10223. vcxt[cxt_offset].eth,
  10224. BNX2X_ISCSI_ETH_CID(bp));
  10225. }
  10226. }
  10227. /*
  10228. * There may be not more than 8 L2, not more than 8 L5 SPEs
  10229. * and in the air. We also check that number of outstanding
  10230. * COMMON ramrods is not more than the EQ and SPQ can
  10231. * accommodate.
  10232. */
  10233. if (type == ETH_CONNECTION_TYPE) {
  10234. if (!atomic_read(&bp->cq_spq_left))
  10235. break;
  10236. else
  10237. atomic_dec(&bp->cq_spq_left);
  10238. } else if (type == NONE_CONNECTION_TYPE) {
  10239. if (!atomic_read(&bp->eq_spq_left))
  10240. break;
  10241. else
  10242. atomic_dec(&bp->eq_spq_left);
  10243. } else if ((type == ISCSI_CONNECTION_TYPE) ||
  10244. (type == FCOE_CONNECTION_TYPE)) {
  10245. if (bp->cnic_spq_pending >=
  10246. bp->cnic_eth_dev.max_kwqe_pending)
  10247. break;
  10248. else
  10249. bp->cnic_spq_pending++;
  10250. } else {
  10251. BNX2X_ERR("Unknown SPE type: %d\n", type);
  10252. bnx2x_panic();
  10253. break;
  10254. }
  10255. spe = bnx2x_sp_get_next(bp);
  10256. *spe = *bp->cnic_kwq_cons;
  10257. DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
  10258. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  10259. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  10260. bp->cnic_kwq_cons = bp->cnic_kwq;
  10261. else
  10262. bp->cnic_kwq_cons++;
  10263. }
  10264. bnx2x_sp_prod_update(bp);
  10265. spin_unlock_bh(&bp->spq_lock);
  10266. }
  10267. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  10268. struct kwqe_16 *kwqes[], u32 count)
  10269. {
  10270. struct bnx2x *bp = netdev_priv(dev);
  10271. int i;
  10272. #ifdef BNX2X_STOP_ON_ERROR
  10273. if (unlikely(bp->panic)) {
  10274. BNX2X_ERR("Can't post to SP queue while panic\n");
  10275. return -EIO;
  10276. }
  10277. #endif
  10278. if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
  10279. (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  10280. BNX2X_ERR("Handling parity error recovery. Try again later\n");
  10281. return -EAGAIN;
  10282. }
  10283. spin_lock_bh(&bp->spq_lock);
  10284. for (i = 0; i < count; i++) {
  10285. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  10286. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  10287. break;
  10288. *bp->cnic_kwq_prod = *spe;
  10289. bp->cnic_kwq_pending++;
  10290. DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
  10291. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  10292. spe->data.update_data_addr.hi,
  10293. spe->data.update_data_addr.lo,
  10294. bp->cnic_kwq_pending);
  10295. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  10296. bp->cnic_kwq_prod = bp->cnic_kwq;
  10297. else
  10298. bp->cnic_kwq_prod++;
  10299. }
  10300. spin_unlock_bh(&bp->spq_lock);
  10301. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  10302. bnx2x_cnic_sp_post(bp, 0);
  10303. return i;
  10304. }
  10305. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  10306. {
  10307. struct cnic_ops *c_ops;
  10308. int rc = 0;
  10309. mutex_lock(&bp->cnic_mutex);
  10310. c_ops = rcu_dereference_protected(bp->cnic_ops,
  10311. lockdep_is_held(&bp->cnic_mutex));
  10312. if (c_ops)
  10313. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  10314. mutex_unlock(&bp->cnic_mutex);
  10315. return rc;
  10316. }
  10317. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  10318. {
  10319. struct cnic_ops *c_ops;
  10320. int rc = 0;
  10321. rcu_read_lock();
  10322. c_ops = rcu_dereference(bp->cnic_ops);
  10323. if (c_ops)
  10324. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  10325. rcu_read_unlock();
  10326. return rc;
  10327. }
  10328. /*
  10329. * for commands that have no data
  10330. */
  10331. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  10332. {
  10333. struct cnic_ctl_info ctl = {0};
  10334. ctl.cmd = cmd;
  10335. return bnx2x_cnic_ctl_send(bp, &ctl);
  10336. }
  10337. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
  10338. {
  10339. struct cnic_ctl_info ctl = {0};
  10340. /* first we tell CNIC and only then we count this as a completion */
  10341. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  10342. ctl.data.comp.cid = cid;
  10343. ctl.data.comp.error = err;
  10344. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  10345. bnx2x_cnic_sp_post(bp, 0);
  10346. }
  10347. /* Called with netif_addr_lock_bh() taken.
  10348. * Sets an rx_mode config for an iSCSI ETH client.
  10349. * Doesn't block.
  10350. * Completion should be checked outside.
  10351. */
  10352. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
  10353. {
  10354. unsigned long accept_flags = 0, ramrod_flags = 0;
  10355. u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  10356. int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
  10357. if (start) {
  10358. /* Start accepting on iSCSI L2 ring. Accept all multicasts
  10359. * because it's the only way for UIO Queue to accept
  10360. * multicasts (in non-promiscuous mode only one Queue per
  10361. * function will receive multicast packets (leading in our
  10362. * case).
  10363. */
  10364. __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
  10365. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
  10366. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
  10367. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  10368. /* Clear STOP_PENDING bit if START is requested */
  10369. clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
  10370. sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
  10371. } else
  10372. /* Clear START_PENDING bit if STOP is requested */
  10373. clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
  10374. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  10375. set_bit(sched_state, &bp->sp_state);
  10376. else {
  10377. __set_bit(RAMROD_RX, &ramrod_flags);
  10378. bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
  10379. ramrod_flags);
  10380. }
  10381. }
  10382. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  10383. {
  10384. struct bnx2x *bp = netdev_priv(dev);
  10385. int rc = 0;
  10386. switch (ctl->cmd) {
  10387. case DRV_CTL_CTXTBL_WR_CMD: {
  10388. u32 index = ctl->data.io.offset;
  10389. dma_addr_t addr = ctl->data.io.dma_addr;
  10390. bnx2x_ilt_wr(bp, index, addr);
  10391. break;
  10392. }
  10393. case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
  10394. int count = ctl->data.credit.credit_count;
  10395. bnx2x_cnic_sp_post(bp, count);
  10396. break;
  10397. }
  10398. /* rtnl_lock is held. */
  10399. case DRV_CTL_START_L2_CMD: {
  10400. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10401. unsigned long sp_bits = 0;
  10402. /* Configure the iSCSI classification object */
  10403. bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
  10404. cp->iscsi_l2_client_id,
  10405. cp->iscsi_l2_cid, BP_FUNC(bp),
  10406. bnx2x_sp(bp, mac_rdata),
  10407. bnx2x_sp_mapping(bp, mac_rdata),
  10408. BNX2X_FILTER_MAC_PENDING,
  10409. &bp->sp_state, BNX2X_OBJ_TYPE_RX,
  10410. &bp->macs_pool);
  10411. /* Set iSCSI MAC address */
  10412. rc = bnx2x_set_iscsi_eth_mac_addr(bp);
  10413. if (rc)
  10414. break;
  10415. mmiowb();
  10416. barrier();
  10417. /* Start accepting on iSCSI L2 ring */
  10418. netif_addr_lock_bh(dev);
  10419. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  10420. netif_addr_unlock_bh(dev);
  10421. /* bits to wait on */
  10422. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  10423. __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
  10424. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  10425. BNX2X_ERR("rx_mode completion timed out!\n");
  10426. break;
  10427. }
  10428. /* rtnl_lock is held. */
  10429. case DRV_CTL_STOP_L2_CMD: {
  10430. unsigned long sp_bits = 0;
  10431. /* Stop accepting on iSCSI L2 ring */
  10432. netif_addr_lock_bh(dev);
  10433. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  10434. netif_addr_unlock_bh(dev);
  10435. /* bits to wait on */
  10436. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  10437. __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
  10438. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  10439. BNX2X_ERR("rx_mode completion timed out!\n");
  10440. mmiowb();
  10441. barrier();
  10442. /* Unset iSCSI L2 MAC */
  10443. rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
  10444. BNX2X_ISCSI_ETH_MAC, true);
  10445. break;
  10446. }
  10447. case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
  10448. int count = ctl->data.credit.credit_count;
  10449. smp_mb__before_atomic_inc();
  10450. atomic_add(count, &bp->cq_spq_left);
  10451. smp_mb__after_atomic_inc();
  10452. break;
  10453. }
  10454. case DRV_CTL_ULP_REGISTER_CMD: {
  10455. int ulp_type = ctl->data.register_data.ulp_type;
  10456. if (CHIP_IS_E3(bp)) {
  10457. int idx = BP_FW_MB_IDX(bp);
  10458. u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  10459. int path = BP_PATH(bp);
  10460. int port = BP_PORT(bp);
  10461. int i;
  10462. u32 scratch_offset;
  10463. u32 *host_addr;
  10464. /* first write capability to shmem2 */
  10465. if (ulp_type == CNIC_ULP_ISCSI)
  10466. cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  10467. else if (ulp_type == CNIC_ULP_FCOE)
  10468. cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  10469. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  10470. if ((ulp_type != CNIC_ULP_FCOE) ||
  10471. (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
  10472. (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
  10473. break;
  10474. /* if reached here - should write fcoe capabilities */
  10475. scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
  10476. if (!scratch_offset)
  10477. break;
  10478. scratch_offset += offsetof(struct glob_ncsi_oem_data,
  10479. fcoe_features[path][port]);
  10480. host_addr = (u32 *) &(ctl->data.register_data.
  10481. fcoe_features);
  10482. for (i = 0; i < sizeof(struct fcoe_capabilities);
  10483. i += 4)
  10484. REG_WR(bp, scratch_offset + i,
  10485. *(host_addr + i/4));
  10486. }
  10487. break;
  10488. }
  10489. case DRV_CTL_ULP_UNREGISTER_CMD: {
  10490. int ulp_type = ctl->data.ulp_type;
  10491. if (CHIP_IS_E3(bp)) {
  10492. int idx = BP_FW_MB_IDX(bp);
  10493. u32 cap;
  10494. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  10495. if (ulp_type == CNIC_ULP_ISCSI)
  10496. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  10497. else if (ulp_type == CNIC_ULP_FCOE)
  10498. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  10499. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  10500. }
  10501. break;
  10502. }
  10503. default:
  10504. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  10505. rc = -EINVAL;
  10506. }
  10507. return rc;
  10508. }
  10509. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  10510. {
  10511. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10512. if (bp->flags & USING_MSIX_FLAG) {
  10513. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  10514. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  10515. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  10516. } else {
  10517. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  10518. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  10519. }
  10520. if (!CHIP_IS_E1x(bp))
  10521. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
  10522. else
  10523. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
  10524. cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
  10525. cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
  10526. cp->irq_arr[1].status_blk = bp->def_status_blk;
  10527. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  10528. cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
  10529. cp->num_irq = 2;
  10530. }
  10531. void bnx2x_setup_cnic_info(struct bnx2x *bp)
  10532. {
  10533. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10534. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  10535. bnx2x_cid_ilt_lines(bp);
  10536. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  10537. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  10538. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  10539. if (NO_ISCSI_OOO(bp))
  10540. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  10541. }
  10542. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  10543. void *data)
  10544. {
  10545. struct bnx2x *bp = netdev_priv(dev);
  10546. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10547. if (ops == NULL) {
  10548. BNX2X_ERR("NULL ops received\n");
  10549. return -EINVAL;
  10550. }
  10551. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  10552. if (!bp->cnic_kwq)
  10553. return -ENOMEM;
  10554. bp->cnic_kwq_cons = bp->cnic_kwq;
  10555. bp->cnic_kwq_prod = bp->cnic_kwq;
  10556. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  10557. bp->cnic_spq_pending = 0;
  10558. bp->cnic_kwq_pending = 0;
  10559. bp->cnic_data = data;
  10560. cp->num_irq = 0;
  10561. cp->drv_state |= CNIC_DRV_STATE_REGD;
  10562. cp->iro_arr = bp->iro_arr;
  10563. bnx2x_setup_cnic_irq_info(bp);
  10564. rcu_assign_pointer(bp->cnic_ops, ops);
  10565. return 0;
  10566. }
  10567. static int bnx2x_unregister_cnic(struct net_device *dev)
  10568. {
  10569. struct bnx2x *bp = netdev_priv(dev);
  10570. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10571. mutex_lock(&bp->cnic_mutex);
  10572. cp->drv_state = 0;
  10573. RCU_INIT_POINTER(bp->cnic_ops, NULL);
  10574. mutex_unlock(&bp->cnic_mutex);
  10575. synchronize_rcu();
  10576. kfree(bp->cnic_kwq);
  10577. bp->cnic_kwq = NULL;
  10578. return 0;
  10579. }
  10580. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  10581. {
  10582. struct bnx2x *bp = netdev_priv(dev);
  10583. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10584. /* If both iSCSI and FCoE are disabled - return NULL in
  10585. * order to indicate CNIC that it should not try to work
  10586. * with this device.
  10587. */
  10588. if (NO_ISCSI(bp) && NO_FCOE(bp))
  10589. return NULL;
  10590. cp->drv_owner = THIS_MODULE;
  10591. cp->chip_id = CHIP_ID(bp);
  10592. cp->pdev = bp->pdev;
  10593. cp->io_base = bp->regview;
  10594. cp->io_base2 = bp->doorbells;
  10595. cp->max_kwqe_pending = 8;
  10596. cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
  10597. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  10598. bnx2x_cid_ilt_lines(bp);
  10599. cp->ctx_tbl_len = CNIC_ILT_LINES;
  10600. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  10601. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  10602. cp->drv_ctl = bnx2x_drv_ctl;
  10603. cp->drv_register_cnic = bnx2x_register_cnic;
  10604. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  10605. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  10606. cp->iscsi_l2_client_id =
  10607. bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  10608. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  10609. if (NO_ISCSI_OOO(bp))
  10610. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  10611. if (NO_ISCSI(bp))
  10612. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
  10613. if (NO_FCOE(bp))
  10614. cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
  10615. BNX2X_DEV_INFO(
  10616. "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
  10617. cp->ctx_blk_size,
  10618. cp->ctx_tbl_offset,
  10619. cp->ctx_tbl_len,
  10620. cp->starting_cid);
  10621. return cp;
  10622. }
  10623. EXPORT_SYMBOL(bnx2x_cnic_probe);
  10624. #endif /* BCM_CNIC */