bnx2x_main.c 348 KB

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