bnx2.c 209 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600
  1. /* bnx2.c: Broadcom NX2 network driver.
  2. *
  3. * Copyright (c) 2004-2011 Broadcom Corporation
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation.
  8. *
  9. * Written by: Michael Chan (mchan@broadcom.com)
  10. */
  11. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  12. #include <linux/module.h>
  13. #include <linux/moduleparam.h>
  14. #include <linux/kernel.h>
  15. #include <linux/timer.h>
  16. #include <linux/errno.h>
  17. #include <linux/ioport.h>
  18. #include <linux/slab.h>
  19. #include <linux/vmalloc.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/pci.h>
  22. #include <linux/init.h>
  23. #include <linux/netdevice.h>
  24. #include <linux/etherdevice.h>
  25. #include <linux/skbuff.h>
  26. #include <linux/dma-mapping.h>
  27. #include <linux/bitops.h>
  28. #include <asm/io.h>
  29. #include <asm/irq.h>
  30. #include <linux/delay.h>
  31. #include <asm/byteorder.h>
  32. #include <asm/page.h>
  33. #include <linux/time.h>
  34. #include <linux/ethtool.h>
  35. #include <linux/mii.h>
  36. #include <linux/if_vlan.h>
  37. #include <net/ip.h>
  38. #include <net/tcp.h>
  39. #include <net/checksum.h>
  40. #include <linux/workqueue.h>
  41. #include <linux/crc32.h>
  42. #include <linux/prefetch.h>
  43. #include <linux/cache.h>
  44. #include <linux/firmware.h>
  45. #include <linux/log2.h>
  46. #include <linux/aer.h>
  47. #if defined(CONFIG_CNIC) || defined(CONFIG_CNIC_MODULE)
  48. #define BCM_CNIC 1
  49. #include "cnic_if.h"
  50. #endif
  51. #include "bnx2.h"
  52. #include "bnx2_fw.h"
  53. #define DRV_MODULE_NAME "bnx2"
  54. #define DRV_MODULE_VERSION "2.1.10"
  55. #define DRV_MODULE_RELDATE "July 12, 2011"
  56. #define FW_MIPS_FILE_06 "bnx2/bnx2-mips-06-6.2.1.fw"
  57. #define FW_RV2P_FILE_06 "bnx2/bnx2-rv2p-06-6.0.15.fw"
  58. #define FW_MIPS_FILE_09 "bnx2/bnx2-mips-09-6.2.1a.fw"
  59. #define FW_RV2P_FILE_09_Ax "bnx2/bnx2-rv2p-09ax-6.0.17.fw"
  60. #define FW_RV2P_FILE_09 "bnx2/bnx2-rv2p-09-6.0.17.fw"
  61. #define RUN_AT(x) (jiffies + (x))
  62. /* Time in jiffies before concluding the transmitter is hung. */
  63. #define TX_TIMEOUT (5*HZ)
  64. static char version[] __devinitdata =
  65. "Broadcom NetXtreme II Gigabit Ethernet Driver " DRV_MODULE_NAME " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  66. MODULE_AUTHOR("Michael Chan <mchan@broadcom.com>");
  67. MODULE_DESCRIPTION("Broadcom NetXtreme II BCM5706/5708/5709/5716 Driver");
  68. MODULE_LICENSE("GPL");
  69. MODULE_VERSION(DRV_MODULE_VERSION);
  70. MODULE_FIRMWARE(FW_MIPS_FILE_06);
  71. MODULE_FIRMWARE(FW_RV2P_FILE_06);
  72. MODULE_FIRMWARE(FW_MIPS_FILE_09);
  73. MODULE_FIRMWARE(FW_RV2P_FILE_09);
  74. MODULE_FIRMWARE(FW_RV2P_FILE_09_Ax);
  75. static int disable_msi = 0;
  76. module_param(disable_msi, int, 0);
  77. MODULE_PARM_DESC(disable_msi, "Disable Message Signaled Interrupt (MSI)");
  78. typedef enum {
  79. BCM5706 = 0,
  80. NC370T,
  81. NC370I,
  82. BCM5706S,
  83. NC370F,
  84. BCM5708,
  85. BCM5708S,
  86. BCM5709,
  87. BCM5709S,
  88. BCM5716,
  89. BCM5716S,
  90. } board_t;
  91. /* indexed by board_t, above */
  92. static struct {
  93. char *name;
  94. } board_info[] __devinitdata = {
  95. { "Broadcom NetXtreme II BCM5706 1000Base-T" },
  96. { "HP NC370T Multifunction Gigabit Server Adapter" },
  97. { "HP NC370i Multifunction Gigabit Server Adapter" },
  98. { "Broadcom NetXtreme II BCM5706 1000Base-SX" },
  99. { "HP NC370F Multifunction Gigabit Server Adapter" },
  100. { "Broadcom NetXtreme II BCM5708 1000Base-T" },
  101. { "Broadcom NetXtreme II BCM5708 1000Base-SX" },
  102. { "Broadcom NetXtreme II BCM5709 1000Base-T" },
  103. { "Broadcom NetXtreme II BCM5709 1000Base-SX" },
  104. { "Broadcom NetXtreme II BCM5716 1000Base-T" },
  105. { "Broadcom NetXtreme II BCM5716 1000Base-SX" },
  106. };
  107. static DEFINE_PCI_DEVICE_TABLE(bnx2_pci_tbl) = {
  108. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706,
  109. PCI_VENDOR_ID_HP, 0x3101, 0, 0, NC370T },
  110. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706,
  111. PCI_VENDOR_ID_HP, 0x3106, 0, 0, NC370I },
  112. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706,
  113. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5706 },
  114. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5708,
  115. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5708 },
  116. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706S,
  117. PCI_VENDOR_ID_HP, 0x3102, 0, 0, NC370F },
  118. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706S,
  119. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5706S },
  120. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5708S,
  121. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5708S },
  122. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5709,
  123. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5709 },
  124. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5709S,
  125. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5709S },
  126. { PCI_VENDOR_ID_BROADCOM, 0x163b,
  127. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5716 },
  128. { PCI_VENDOR_ID_BROADCOM, 0x163c,
  129. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5716S },
  130. { 0, }
  131. };
  132. static const struct flash_spec flash_table[] =
  133. {
  134. #define BUFFERED_FLAGS (BNX2_NV_BUFFERED | BNX2_NV_TRANSLATE)
  135. #define NONBUFFERED_FLAGS (BNX2_NV_WREN)
  136. /* Slow EEPROM */
  137. {0x00000000, 0x40830380, 0x009f0081, 0xa184a053, 0xaf000400,
  138. BUFFERED_FLAGS, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
  139. SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
  140. "EEPROM - slow"},
  141. /* Expansion entry 0001 */
  142. {0x08000002, 0x4b808201, 0x00050081, 0x03840253, 0xaf020406,
  143. NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  144. SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
  145. "Entry 0001"},
  146. /* Saifun SA25F010 (non-buffered flash) */
  147. /* strap, cfg1, & write1 need updates */
  148. {0x04000001, 0x47808201, 0x00050081, 0x03840253, 0xaf020406,
  149. NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  150. SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE*2,
  151. "Non-buffered flash (128kB)"},
  152. /* Saifun SA25F020 (non-buffered flash) */
  153. /* strap, cfg1, & write1 need updates */
  154. {0x0c000003, 0x4f808201, 0x00050081, 0x03840253, 0xaf020406,
  155. NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  156. SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE*4,
  157. "Non-buffered flash (256kB)"},
  158. /* Expansion entry 0100 */
  159. {0x11000000, 0x53808201, 0x00050081, 0x03840253, 0xaf020406,
  160. NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  161. SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
  162. "Entry 0100"},
  163. /* Entry 0101: ST M45PE10 (non-buffered flash, TetonII B0) */
  164. {0x19000002, 0x5b808201, 0x000500db, 0x03840253, 0xaf020406,
  165. NONBUFFERED_FLAGS, ST_MICRO_FLASH_PAGE_BITS, ST_MICRO_FLASH_PAGE_SIZE,
  166. ST_MICRO_FLASH_BYTE_ADDR_MASK, ST_MICRO_FLASH_BASE_TOTAL_SIZE*2,
  167. "Entry 0101: ST M45PE10 (128kB non-bufferred)"},
  168. /* Entry 0110: ST M45PE20 (non-buffered flash)*/
  169. {0x15000001, 0x57808201, 0x000500db, 0x03840253, 0xaf020406,
  170. NONBUFFERED_FLAGS, ST_MICRO_FLASH_PAGE_BITS, ST_MICRO_FLASH_PAGE_SIZE,
  171. ST_MICRO_FLASH_BYTE_ADDR_MASK, ST_MICRO_FLASH_BASE_TOTAL_SIZE*4,
  172. "Entry 0110: ST M45PE20 (256kB non-bufferred)"},
  173. /* Saifun SA25F005 (non-buffered flash) */
  174. /* strap, cfg1, & write1 need updates */
  175. {0x1d000003, 0x5f808201, 0x00050081, 0x03840253, 0xaf020406,
  176. NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  177. SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE,
  178. "Non-buffered flash (64kB)"},
  179. /* Fast EEPROM */
  180. {0x22000000, 0x62808380, 0x009f0081, 0xa184a053, 0xaf000400,
  181. BUFFERED_FLAGS, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
  182. SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
  183. "EEPROM - fast"},
  184. /* Expansion entry 1001 */
  185. {0x2a000002, 0x6b808201, 0x00050081, 0x03840253, 0xaf020406,
  186. NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  187. SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
  188. "Entry 1001"},
  189. /* Expansion entry 1010 */
  190. {0x26000001, 0x67808201, 0x00050081, 0x03840253, 0xaf020406,
  191. NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  192. SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
  193. "Entry 1010"},
  194. /* ATMEL AT45DB011B (buffered flash) */
  195. {0x2e000003, 0x6e808273, 0x00570081, 0x68848353, 0xaf000400,
  196. BUFFERED_FLAGS, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
  197. BUFFERED_FLASH_BYTE_ADDR_MASK, BUFFERED_FLASH_TOTAL_SIZE,
  198. "Buffered flash (128kB)"},
  199. /* Expansion entry 1100 */
  200. {0x33000000, 0x73808201, 0x00050081, 0x03840253, 0xaf020406,
  201. NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  202. SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
  203. "Entry 1100"},
  204. /* Expansion entry 1101 */
  205. {0x3b000002, 0x7b808201, 0x00050081, 0x03840253, 0xaf020406,
  206. NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  207. SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
  208. "Entry 1101"},
  209. /* Ateml Expansion entry 1110 */
  210. {0x37000001, 0x76808273, 0x00570081, 0x68848353, 0xaf000400,
  211. BUFFERED_FLAGS, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
  212. BUFFERED_FLASH_BYTE_ADDR_MASK, 0,
  213. "Entry 1110 (Atmel)"},
  214. /* ATMEL AT45DB021B (buffered flash) */
  215. {0x3f000003, 0x7e808273, 0x00570081, 0x68848353, 0xaf000400,
  216. BUFFERED_FLAGS, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
  217. BUFFERED_FLASH_BYTE_ADDR_MASK, BUFFERED_FLASH_TOTAL_SIZE*2,
  218. "Buffered flash (256kB)"},
  219. };
  220. static const struct flash_spec flash_5709 = {
  221. .flags = BNX2_NV_BUFFERED,
  222. .page_bits = BCM5709_FLASH_PAGE_BITS,
  223. .page_size = BCM5709_FLASH_PAGE_SIZE,
  224. .addr_mask = BCM5709_FLASH_BYTE_ADDR_MASK,
  225. .total_size = BUFFERED_FLASH_TOTAL_SIZE*2,
  226. .name = "5709 Buffered flash (256kB)",
  227. };
  228. MODULE_DEVICE_TABLE(pci, bnx2_pci_tbl);
  229. static void bnx2_init_napi(struct bnx2 *bp);
  230. static void bnx2_del_napi(struct bnx2 *bp);
  231. static inline u32 bnx2_tx_avail(struct bnx2 *bp, struct bnx2_tx_ring_info *txr)
  232. {
  233. u32 diff;
  234. /* Tell compiler to fetch tx_prod and tx_cons from memory. */
  235. barrier();
  236. /* The ring uses 256 indices for 255 entries, one of them
  237. * needs to be skipped.
  238. */
  239. diff = txr->tx_prod - txr->tx_cons;
  240. if (unlikely(diff >= TX_DESC_CNT)) {
  241. diff &= 0xffff;
  242. if (diff == TX_DESC_CNT)
  243. diff = MAX_TX_DESC_CNT;
  244. }
  245. return bp->tx_ring_size - diff;
  246. }
  247. static u32
  248. bnx2_reg_rd_ind(struct bnx2 *bp, u32 offset)
  249. {
  250. u32 val;
  251. spin_lock_bh(&bp->indirect_lock);
  252. REG_WR(bp, BNX2_PCICFG_REG_WINDOW_ADDRESS, offset);
  253. val = REG_RD(bp, BNX2_PCICFG_REG_WINDOW);
  254. spin_unlock_bh(&bp->indirect_lock);
  255. return val;
  256. }
  257. static void
  258. bnx2_reg_wr_ind(struct bnx2 *bp, u32 offset, u32 val)
  259. {
  260. spin_lock_bh(&bp->indirect_lock);
  261. REG_WR(bp, BNX2_PCICFG_REG_WINDOW_ADDRESS, offset);
  262. REG_WR(bp, BNX2_PCICFG_REG_WINDOW, val);
  263. spin_unlock_bh(&bp->indirect_lock);
  264. }
  265. static void
  266. bnx2_shmem_wr(struct bnx2 *bp, u32 offset, u32 val)
  267. {
  268. bnx2_reg_wr_ind(bp, bp->shmem_base + offset, val);
  269. }
  270. static u32
  271. bnx2_shmem_rd(struct bnx2 *bp, u32 offset)
  272. {
  273. return bnx2_reg_rd_ind(bp, bp->shmem_base + offset);
  274. }
  275. static void
  276. bnx2_ctx_wr(struct bnx2 *bp, u32 cid_addr, u32 offset, u32 val)
  277. {
  278. offset += cid_addr;
  279. spin_lock_bh(&bp->indirect_lock);
  280. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  281. int i;
  282. REG_WR(bp, BNX2_CTX_CTX_DATA, val);
  283. REG_WR(bp, BNX2_CTX_CTX_CTRL,
  284. offset | BNX2_CTX_CTX_CTRL_WRITE_REQ);
  285. for (i = 0; i < 5; i++) {
  286. val = REG_RD(bp, BNX2_CTX_CTX_CTRL);
  287. if ((val & BNX2_CTX_CTX_CTRL_WRITE_REQ) == 0)
  288. break;
  289. udelay(5);
  290. }
  291. } else {
  292. REG_WR(bp, BNX2_CTX_DATA_ADR, offset);
  293. REG_WR(bp, BNX2_CTX_DATA, val);
  294. }
  295. spin_unlock_bh(&bp->indirect_lock);
  296. }
  297. #ifdef BCM_CNIC
  298. static int
  299. bnx2_drv_ctl(struct net_device *dev, struct drv_ctl_info *info)
  300. {
  301. struct bnx2 *bp = netdev_priv(dev);
  302. struct drv_ctl_io *io = &info->data.io;
  303. switch (info->cmd) {
  304. case DRV_CTL_IO_WR_CMD:
  305. bnx2_reg_wr_ind(bp, io->offset, io->data);
  306. break;
  307. case DRV_CTL_IO_RD_CMD:
  308. io->data = bnx2_reg_rd_ind(bp, io->offset);
  309. break;
  310. case DRV_CTL_CTX_WR_CMD:
  311. bnx2_ctx_wr(bp, io->cid_addr, io->offset, io->data);
  312. break;
  313. default:
  314. return -EINVAL;
  315. }
  316. return 0;
  317. }
  318. static void bnx2_setup_cnic_irq_info(struct bnx2 *bp)
  319. {
  320. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  321. struct bnx2_napi *bnapi = &bp->bnx2_napi[0];
  322. int sb_id;
  323. if (bp->flags & BNX2_FLAG_USING_MSIX) {
  324. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  325. bnapi->cnic_present = 0;
  326. sb_id = bp->irq_nvecs;
  327. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  328. } else {
  329. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  330. bnapi->cnic_tag = bnapi->last_status_idx;
  331. bnapi->cnic_present = 1;
  332. sb_id = 0;
  333. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  334. }
  335. cp->irq_arr[0].vector = bp->irq_tbl[sb_id].vector;
  336. cp->irq_arr[0].status_blk = (void *)
  337. ((unsigned long) bnapi->status_blk.msi +
  338. (BNX2_SBLK_MSIX_ALIGN_SIZE * sb_id));
  339. cp->irq_arr[0].status_blk_num = sb_id;
  340. cp->num_irq = 1;
  341. }
  342. static int bnx2_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  343. void *data)
  344. {
  345. struct bnx2 *bp = netdev_priv(dev);
  346. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  347. if (ops == NULL)
  348. return -EINVAL;
  349. if (cp->drv_state & CNIC_DRV_STATE_REGD)
  350. return -EBUSY;
  351. if (!bnx2_reg_rd_ind(bp, BNX2_FW_MAX_ISCSI_CONN))
  352. return -ENODEV;
  353. bp->cnic_data = data;
  354. rcu_assign_pointer(bp->cnic_ops, ops);
  355. cp->num_irq = 0;
  356. cp->drv_state = CNIC_DRV_STATE_REGD;
  357. bnx2_setup_cnic_irq_info(bp);
  358. return 0;
  359. }
  360. static int bnx2_unregister_cnic(struct net_device *dev)
  361. {
  362. struct bnx2 *bp = netdev_priv(dev);
  363. struct bnx2_napi *bnapi = &bp->bnx2_napi[0];
  364. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  365. mutex_lock(&bp->cnic_lock);
  366. cp->drv_state = 0;
  367. bnapi->cnic_present = 0;
  368. rcu_assign_pointer(bp->cnic_ops, NULL);
  369. mutex_unlock(&bp->cnic_lock);
  370. synchronize_rcu();
  371. return 0;
  372. }
  373. struct cnic_eth_dev *bnx2_cnic_probe(struct net_device *dev)
  374. {
  375. struct bnx2 *bp = netdev_priv(dev);
  376. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  377. if (!cp->max_iscsi_conn)
  378. return NULL;
  379. cp->drv_owner = THIS_MODULE;
  380. cp->chip_id = bp->chip_id;
  381. cp->pdev = bp->pdev;
  382. cp->io_base = bp->regview;
  383. cp->drv_ctl = bnx2_drv_ctl;
  384. cp->drv_register_cnic = bnx2_register_cnic;
  385. cp->drv_unregister_cnic = bnx2_unregister_cnic;
  386. return cp;
  387. }
  388. EXPORT_SYMBOL(bnx2_cnic_probe);
  389. static void
  390. bnx2_cnic_stop(struct bnx2 *bp)
  391. {
  392. struct cnic_ops *c_ops;
  393. struct cnic_ctl_info info;
  394. mutex_lock(&bp->cnic_lock);
  395. c_ops = rcu_dereference_protected(bp->cnic_ops,
  396. lockdep_is_held(&bp->cnic_lock));
  397. if (c_ops) {
  398. info.cmd = CNIC_CTL_STOP_CMD;
  399. c_ops->cnic_ctl(bp->cnic_data, &info);
  400. }
  401. mutex_unlock(&bp->cnic_lock);
  402. }
  403. static void
  404. bnx2_cnic_start(struct bnx2 *bp)
  405. {
  406. struct cnic_ops *c_ops;
  407. struct cnic_ctl_info info;
  408. mutex_lock(&bp->cnic_lock);
  409. c_ops = rcu_dereference_protected(bp->cnic_ops,
  410. lockdep_is_held(&bp->cnic_lock));
  411. if (c_ops) {
  412. if (!(bp->flags & BNX2_FLAG_USING_MSIX)) {
  413. struct bnx2_napi *bnapi = &bp->bnx2_napi[0];
  414. bnapi->cnic_tag = bnapi->last_status_idx;
  415. }
  416. info.cmd = CNIC_CTL_START_CMD;
  417. c_ops->cnic_ctl(bp->cnic_data, &info);
  418. }
  419. mutex_unlock(&bp->cnic_lock);
  420. }
  421. #else
  422. static void
  423. bnx2_cnic_stop(struct bnx2 *bp)
  424. {
  425. }
  426. static void
  427. bnx2_cnic_start(struct bnx2 *bp)
  428. {
  429. }
  430. #endif
  431. static int
  432. bnx2_read_phy(struct bnx2 *bp, u32 reg, u32 *val)
  433. {
  434. u32 val1;
  435. int i, ret;
  436. if (bp->phy_flags & BNX2_PHY_FLAG_INT_MODE_AUTO_POLLING) {
  437. val1 = REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  438. val1 &= ~BNX2_EMAC_MDIO_MODE_AUTO_POLL;
  439. REG_WR(bp, BNX2_EMAC_MDIO_MODE, val1);
  440. REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  441. udelay(40);
  442. }
  443. val1 = (bp->phy_addr << 21) | (reg << 16) |
  444. BNX2_EMAC_MDIO_COMM_COMMAND_READ | BNX2_EMAC_MDIO_COMM_DISEXT |
  445. BNX2_EMAC_MDIO_COMM_START_BUSY;
  446. REG_WR(bp, BNX2_EMAC_MDIO_COMM, val1);
  447. for (i = 0; i < 50; i++) {
  448. udelay(10);
  449. val1 = REG_RD(bp, BNX2_EMAC_MDIO_COMM);
  450. if (!(val1 & BNX2_EMAC_MDIO_COMM_START_BUSY)) {
  451. udelay(5);
  452. val1 = REG_RD(bp, BNX2_EMAC_MDIO_COMM);
  453. val1 &= BNX2_EMAC_MDIO_COMM_DATA;
  454. break;
  455. }
  456. }
  457. if (val1 & BNX2_EMAC_MDIO_COMM_START_BUSY) {
  458. *val = 0x0;
  459. ret = -EBUSY;
  460. }
  461. else {
  462. *val = val1;
  463. ret = 0;
  464. }
  465. if (bp->phy_flags & BNX2_PHY_FLAG_INT_MODE_AUTO_POLLING) {
  466. val1 = REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  467. val1 |= BNX2_EMAC_MDIO_MODE_AUTO_POLL;
  468. REG_WR(bp, BNX2_EMAC_MDIO_MODE, val1);
  469. REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  470. udelay(40);
  471. }
  472. return ret;
  473. }
  474. static int
  475. bnx2_write_phy(struct bnx2 *bp, u32 reg, u32 val)
  476. {
  477. u32 val1;
  478. int i, ret;
  479. if (bp->phy_flags & BNX2_PHY_FLAG_INT_MODE_AUTO_POLLING) {
  480. val1 = REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  481. val1 &= ~BNX2_EMAC_MDIO_MODE_AUTO_POLL;
  482. REG_WR(bp, BNX2_EMAC_MDIO_MODE, val1);
  483. REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  484. udelay(40);
  485. }
  486. val1 = (bp->phy_addr << 21) | (reg << 16) | val |
  487. BNX2_EMAC_MDIO_COMM_COMMAND_WRITE |
  488. BNX2_EMAC_MDIO_COMM_START_BUSY | BNX2_EMAC_MDIO_COMM_DISEXT;
  489. REG_WR(bp, BNX2_EMAC_MDIO_COMM, val1);
  490. for (i = 0; i < 50; i++) {
  491. udelay(10);
  492. val1 = REG_RD(bp, BNX2_EMAC_MDIO_COMM);
  493. if (!(val1 & BNX2_EMAC_MDIO_COMM_START_BUSY)) {
  494. udelay(5);
  495. break;
  496. }
  497. }
  498. if (val1 & BNX2_EMAC_MDIO_COMM_START_BUSY)
  499. ret = -EBUSY;
  500. else
  501. ret = 0;
  502. if (bp->phy_flags & BNX2_PHY_FLAG_INT_MODE_AUTO_POLLING) {
  503. val1 = REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  504. val1 |= BNX2_EMAC_MDIO_MODE_AUTO_POLL;
  505. REG_WR(bp, BNX2_EMAC_MDIO_MODE, val1);
  506. REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  507. udelay(40);
  508. }
  509. return ret;
  510. }
  511. static void
  512. bnx2_disable_int(struct bnx2 *bp)
  513. {
  514. int i;
  515. struct bnx2_napi *bnapi;
  516. for (i = 0; i < bp->irq_nvecs; i++) {
  517. bnapi = &bp->bnx2_napi[i];
  518. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD, bnapi->int_num |
  519. BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
  520. }
  521. REG_RD(bp, BNX2_PCICFG_INT_ACK_CMD);
  522. }
  523. static void
  524. bnx2_enable_int(struct bnx2 *bp)
  525. {
  526. int i;
  527. struct bnx2_napi *bnapi;
  528. for (i = 0; i < bp->irq_nvecs; i++) {
  529. bnapi = &bp->bnx2_napi[i];
  530. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD, bnapi->int_num |
  531. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID |
  532. BNX2_PCICFG_INT_ACK_CMD_MASK_INT |
  533. bnapi->last_status_idx);
  534. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD, bnapi->int_num |
  535. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID |
  536. bnapi->last_status_idx);
  537. }
  538. REG_WR(bp, BNX2_HC_COMMAND, bp->hc_cmd | BNX2_HC_COMMAND_COAL_NOW);
  539. }
  540. static void
  541. bnx2_disable_int_sync(struct bnx2 *bp)
  542. {
  543. int i;
  544. atomic_inc(&bp->intr_sem);
  545. if (!netif_running(bp->dev))
  546. return;
  547. bnx2_disable_int(bp);
  548. for (i = 0; i < bp->irq_nvecs; i++)
  549. synchronize_irq(bp->irq_tbl[i].vector);
  550. }
  551. static void
  552. bnx2_napi_disable(struct bnx2 *bp)
  553. {
  554. int i;
  555. for (i = 0; i < bp->irq_nvecs; i++)
  556. napi_disable(&bp->bnx2_napi[i].napi);
  557. }
  558. static void
  559. bnx2_napi_enable(struct bnx2 *bp)
  560. {
  561. int i;
  562. for (i = 0; i < bp->irq_nvecs; i++)
  563. napi_enable(&bp->bnx2_napi[i].napi);
  564. }
  565. static void
  566. bnx2_netif_stop(struct bnx2 *bp, bool stop_cnic)
  567. {
  568. if (stop_cnic)
  569. bnx2_cnic_stop(bp);
  570. if (netif_running(bp->dev)) {
  571. bnx2_napi_disable(bp);
  572. netif_tx_disable(bp->dev);
  573. }
  574. bnx2_disable_int_sync(bp);
  575. netif_carrier_off(bp->dev); /* prevent tx timeout */
  576. }
  577. static void
  578. bnx2_netif_start(struct bnx2 *bp, bool start_cnic)
  579. {
  580. if (atomic_dec_and_test(&bp->intr_sem)) {
  581. if (netif_running(bp->dev)) {
  582. netif_tx_wake_all_queues(bp->dev);
  583. spin_lock_bh(&bp->phy_lock);
  584. if (bp->link_up)
  585. netif_carrier_on(bp->dev);
  586. spin_unlock_bh(&bp->phy_lock);
  587. bnx2_napi_enable(bp);
  588. bnx2_enable_int(bp);
  589. if (start_cnic)
  590. bnx2_cnic_start(bp);
  591. }
  592. }
  593. }
  594. static void
  595. bnx2_free_tx_mem(struct bnx2 *bp)
  596. {
  597. int i;
  598. for (i = 0; i < bp->num_tx_rings; i++) {
  599. struct bnx2_napi *bnapi = &bp->bnx2_napi[i];
  600. struct bnx2_tx_ring_info *txr = &bnapi->tx_ring;
  601. if (txr->tx_desc_ring) {
  602. dma_free_coherent(&bp->pdev->dev, TXBD_RING_SIZE,
  603. txr->tx_desc_ring,
  604. txr->tx_desc_mapping);
  605. txr->tx_desc_ring = NULL;
  606. }
  607. kfree(txr->tx_buf_ring);
  608. txr->tx_buf_ring = NULL;
  609. }
  610. }
  611. static void
  612. bnx2_free_rx_mem(struct bnx2 *bp)
  613. {
  614. int i;
  615. for (i = 0; i < bp->num_rx_rings; i++) {
  616. struct bnx2_napi *bnapi = &bp->bnx2_napi[i];
  617. struct bnx2_rx_ring_info *rxr = &bnapi->rx_ring;
  618. int j;
  619. for (j = 0; j < bp->rx_max_ring; j++) {
  620. if (rxr->rx_desc_ring[j])
  621. dma_free_coherent(&bp->pdev->dev, RXBD_RING_SIZE,
  622. rxr->rx_desc_ring[j],
  623. rxr->rx_desc_mapping[j]);
  624. rxr->rx_desc_ring[j] = NULL;
  625. }
  626. vfree(rxr->rx_buf_ring);
  627. rxr->rx_buf_ring = NULL;
  628. for (j = 0; j < bp->rx_max_pg_ring; j++) {
  629. if (rxr->rx_pg_desc_ring[j])
  630. dma_free_coherent(&bp->pdev->dev, RXBD_RING_SIZE,
  631. rxr->rx_pg_desc_ring[j],
  632. rxr->rx_pg_desc_mapping[j]);
  633. rxr->rx_pg_desc_ring[j] = NULL;
  634. }
  635. vfree(rxr->rx_pg_ring);
  636. rxr->rx_pg_ring = NULL;
  637. }
  638. }
  639. static int
  640. bnx2_alloc_tx_mem(struct bnx2 *bp)
  641. {
  642. int i;
  643. for (i = 0; i < bp->num_tx_rings; i++) {
  644. struct bnx2_napi *bnapi = &bp->bnx2_napi[i];
  645. struct bnx2_tx_ring_info *txr = &bnapi->tx_ring;
  646. txr->tx_buf_ring = kzalloc(SW_TXBD_RING_SIZE, GFP_KERNEL);
  647. if (txr->tx_buf_ring == NULL)
  648. return -ENOMEM;
  649. txr->tx_desc_ring =
  650. dma_alloc_coherent(&bp->pdev->dev, TXBD_RING_SIZE,
  651. &txr->tx_desc_mapping, GFP_KERNEL);
  652. if (txr->tx_desc_ring == NULL)
  653. return -ENOMEM;
  654. }
  655. return 0;
  656. }
  657. static int
  658. bnx2_alloc_rx_mem(struct bnx2 *bp)
  659. {
  660. int i;
  661. for (i = 0; i < bp->num_rx_rings; i++) {
  662. struct bnx2_napi *bnapi = &bp->bnx2_napi[i];
  663. struct bnx2_rx_ring_info *rxr = &bnapi->rx_ring;
  664. int j;
  665. rxr->rx_buf_ring =
  666. vzalloc(SW_RXBD_RING_SIZE * bp->rx_max_ring);
  667. if (rxr->rx_buf_ring == NULL)
  668. return -ENOMEM;
  669. for (j = 0; j < bp->rx_max_ring; j++) {
  670. rxr->rx_desc_ring[j] =
  671. dma_alloc_coherent(&bp->pdev->dev,
  672. RXBD_RING_SIZE,
  673. &rxr->rx_desc_mapping[j],
  674. GFP_KERNEL);
  675. if (rxr->rx_desc_ring[j] == NULL)
  676. return -ENOMEM;
  677. }
  678. if (bp->rx_pg_ring_size) {
  679. rxr->rx_pg_ring = vzalloc(SW_RXPG_RING_SIZE *
  680. bp->rx_max_pg_ring);
  681. if (rxr->rx_pg_ring == NULL)
  682. return -ENOMEM;
  683. }
  684. for (j = 0; j < bp->rx_max_pg_ring; j++) {
  685. rxr->rx_pg_desc_ring[j] =
  686. dma_alloc_coherent(&bp->pdev->dev,
  687. RXBD_RING_SIZE,
  688. &rxr->rx_pg_desc_mapping[j],
  689. GFP_KERNEL);
  690. if (rxr->rx_pg_desc_ring[j] == NULL)
  691. return -ENOMEM;
  692. }
  693. }
  694. return 0;
  695. }
  696. static void
  697. bnx2_free_mem(struct bnx2 *bp)
  698. {
  699. int i;
  700. struct bnx2_napi *bnapi = &bp->bnx2_napi[0];
  701. bnx2_free_tx_mem(bp);
  702. bnx2_free_rx_mem(bp);
  703. for (i = 0; i < bp->ctx_pages; i++) {
  704. if (bp->ctx_blk[i]) {
  705. dma_free_coherent(&bp->pdev->dev, BCM_PAGE_SIZE,
  706. bp->ctx_blk[i],
  707. bp->ctx_blk_mapping[i]);
  708. bp->ctx_blk[i] = NULL;
  709. }
  710. }
  711. if (bnapi->status_blk.msi) {
  712. dma_free_coherent(&bp->pdev->dev, bp->status_stats_size,
  713. bnapi->status_blk.msi,
  714. bp->status_blk_mapping);
  715. bnapi->status_blk.msi = NULL;
  716. bp->stats_blk = NULL;
  717. }
  718. }
  719. static int
  720. bnx2_alloc_mem(struct bnx2 *bp)
  721. {
  722. int i, status_blk_size, err;
  723. struct bnx2_napi *bnapi;
  724. void *status_blk;
  725. /* Combine status and statistics blocks into one allocation. */
  726. status_blk_size = L1_CACHE_ALIGN(sizeof(struct status_block));
  727. if (bp->flags & BNX2_FLAG_MSIX_CAP)
  728. status_blk_size = L1_CACHE_ALIGN(BNX2_MAX_MSIX_HW_VEC *
  729. BNX2_SBLK_MSIX_ALIGN_SIZE);
  730. bp->status_stats_size = status_blk_size +
  731. sizeof(struct statistics_block);
  732. status_blk = dma_alloc_coherent(&bp->pdev->dev, bp->status_stats_size,
  733. &bp->status_blk_mapping, GFP_KERNEL);
  734. if (status_blk == NULL)
  735. goto alloc_mem_err;
  736. memset(status_blk, 0, bp->status_stats_size);
  737. bnapi = &bp->bnx2_napi[0];
  738. bnapi->status_blk.msi = status_blk;
  739. bnapi->hw_tx_cons_ptr =
  740. &bnapi->status_blk.msi->status_tx_quick_consumer_index0;
  741. bnapi->hw_rx_cons_ptr =
  742. &bnapi->status_blk.msi->status_rx_quick_consumer_index0;
  743. if (bp->flags & BNX2_FLAG_MSIX_CAP) {
  744. for (i = 1; i < bp->irq_nvecs; i++) {
  745. struct status_block_msix *sblk;
  746. bnapi = &bp->bnx2_napi[i];
  747. sblk = (void *) (status_blk +
  748. BNX2_SBLK_MSIX_ALIGN_SIZE * i);
  749. bnapi->status_blk.msix = sblk;
  750. bnapi->hw_tx_cons_ptr =
  751. &sblk->status_tx_quick_consumer_index;
  752. bnapi->hw_rx_cons_ptr =
  753. &sblk->status_rx_quick_consumer_index;
  754. bnapi->int_num = i << 24;
  755. }
  756. }
  757. bp->stats_blk = status_blk + status_blk_size;
  758. bp->stats_blk_mapping = bp->status_blk_mapping + status_blk_size;
  759. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  760. bp->ctx_pages = 0x2000 / BCM_PAGE_SIZE;
  761. if (bp->ctx_pages == 0)
  762. bp->ctx_pages = 1;
  763. for (i = 0; i < bp->ctx_pages; i++) {
  764. bp->ctx_blk[i] = dma_alloc_coherent(&bp->pdev->dev,
  765. BCM_PAGE_SIZE,
  766. &bp->ctx_blk_mapping[i],
  767. GFP_KERNEL);
  768. if (bp->ctx_blk[i] == NULL)
  769. goto alloc_mem_err;
  770. }
  771. }
  772. err = bnx2_alloc_rx_mem(bp);
  773. if (err)
  774. goto alloc_mem_err;
  775. err = bnx2_alloc_tx_mem(bp);
  776. if (err)
  777. goto alloc_mem_err;
  778. return 0;
  779. alloc_mem_err:
  780. bnx2_free_mem(bp);
  781. return -ENOMEM;
  782. }
  783. static void
  784. bnx2_report_fw_link(struct bnx2 *bp)
  785. {
  786. u32 fw_link_status = 0;
  787. if (bp->phy_flags & BNX2_PHY_FLAG_REMOTE_PHY_CAP)
  788. return;
  789. if (bp->link_up) {
  790. u32 bmsr;
  791. switch (bp->line_speed) {
  792. case SPEED_10:
  793. if (bp->duplex == DUPLEX_HALF)
  794. fw_link_status = BNX2_LINK_STATUS_10HALF;
  795. else
  796. fw_link_status = BNX2_LINK_STATUS_10FULL;
  797. break;
  798. case SPEED_100:
  799. if (bp->duplex == DUPLEX_HALF)
  800. fw_link_status = BNX2_LINK_STATUS_100HALF;
  801. else
  802. fw_link_status = BNX2_LINK_STATUS_100FULL;
  803. break;
  804. case SPEED_1000:
  805. if (bp->duplex == DUPLEX_HALF)
  806. fw_link_status = BNX2_LINK_STATUS_1000HALF;
  807. else
  808. fw_link_status = BNX2_LINK_STATUS_1000FULL;
  809. break;
  810. case SPEED_2500:
  811. if (bp->duplex == DUPLEX_HALF)
  812. fw_link_status = BNX2_LINK_STATUS_2500HALF;
  813. else
  814. fw_link_status = BNX2_LINK_STATUS_2500FULL;
  815. break;
  816. }
  817. fw_link_status |= BNX2_LINK_STATUS_LINK_UP;
  818. if (bp->autoneg) {
  819. fw_link_status |= BNX2_LINK_STATUS_AN_ENABLED;
  820. bnx2_read_phy(bp, bp->mii_bmsr, &bmsr);
  821. bnx2_read_phy(bp, bp->mii_bmsr, &bmsr);
  822. if (!(bmsr & BMSR_ANEGCOMPLETE) ||
  823. bp->phy_flags & BNX2_PHY_FLAG_PARALLEL_DETECT)
  824. fw_link_status |= BNX2_LINK_STATUS_PARALLEL_DET;
  825. else
  826. fw_link_status |= BNX2_LINK_STATUS_AN_COMPLETE;
  827. }
  828. }
  829. else
  830. fw_link_status = BNX2_LINK_STATUS_LINK_DOWN;
  831. bnx2_shmem_wr(bp, BNX2_LINK_STATUS, fw_link_status);
  832. }
  833. static char *
  834. bnx2_xceiver_str(struct bnx2 *bp)
  835. {
  836. return (bp->phy_port == PORT_FIBRE) ? "SerDes" :
  837. ((bp->phy_flags & BNX2_PHY_FLAG_SERDES) ? "Remote Copper" :
  838. "Copper");
  839. }
  840. static void
  841. bnx2_report_link(struct bnx2 *bp)
  842. {
  843. if (bp->link_up) {
  844. netif_carrier_on(bp->dev);
  845. netdev_info(bp->dev, "NIC %s Link is Up, %d Mbps %s duplex",
  846. bnx2_xceiver_str(bp),
  847. bp->line_speed,
  848. bp->duplex == DUPLEX_FULL ? "full" : "half");
  849. if (bp->flow_ctrl) {
  850. if (bp->flow_ctrl & FLOW_CTRL_RX) {
  851. pr_cont(", receive ");
  852. if (bp->flow_ctrl & FLOW_CTRL_TX)
  853. pr_cont("& transmit ");
  854. }
  855. else {
  856. pr_cont(", transmit ");
  857. }
  858. pr_cont("flow control ON");
  859. }
  860. pr_cont("\n");
  861. } else {
  862. netif_carrier_off(bp->dev);
  863. netdev_err(bp->dev, "NIC %s Link is Down\n",
  864. bnx2_xceiver_str(bp));
  865. }
  866. bnx2_report_fw_link(bp);
  867. }
  868. static void
  869. bnx2_resolve_flow_ctrl(struct bnx2 *bp)
  870. {
  871. u32 local_adv, remote_adv;
  872. bp->flow_ctrl = 0;
  873. if ((bp->autoneg & (AUTONEG_SPEED | AUTONEG_FLOW_CTRL)) !=
  874. (AUTONEG_SPEED | AUTONEG_FLOW_CTRL)) {
  875. if (bp->duplex == DUPLEX_FULL) {
  876. bp->flow_ctrl = bp->req_flow_ctrl;
  877. }
  878. return;
  879. }
  880. if (bp->duplex != DUPLEX_FULL) {
  881. return;
  882. }
  883. if ((bp->phy_flags & BNX2_PHY_FLAG_SERDES) &&
  884. (CHIP_NUM(bp) == CHIP_NUM_5708)) {
  885. u32 val;
  886. bnx2_read_phy(bp, BCM5708S_1000X_STAT1, &val);
  887. if (val & BCM5708S_1000X_STAT1_TX_PAUSE)
  888. bp->flow_ctrl |= FLOW_CTRL_TX;
  889. if (val & BCM5708S_1000X_STAT1_RX_PAUSE)
  890. bp->flow_ctrl |= FLOW_CTRL_RX;
  891. return;
  892. }
  893. bnx2_read_phy(bp, bp->mii_adv, &local_adv);
  894. bnx2_read_phy(bp, bp->mii_lpa, &remote_adv);
  895. if (bp->phy_flags & BNX2_PHY_FLAG_SERDES) {
  896. u32 new_local_adv = 0;
  897. u32 new_remote_adv = 0;
  898. if (local_adv & ADVERTISE_1000XPAUSE)
  899. new_local_adv |= ADVERTISE_PAUSE_CAP;
  900. if (local_adv & ADVERTISE_1000XPSE_ASYM)
  901. new_local_adv |= ADVERTISE_PAUSE_ASYM;
  902. if (remote_adv & ADVERTISE_1000XPAUSE)
  903. new_remote_adv |= ADVERTISE_PAUSE_CAP;
  904. if (remote_adv & ADVERTISE_1000XPSE_ASYM)
  905. new_remote_adv |= ADVERTISE_PAUSE_ASYM;
  906. local_adv = new_local_adv;
  907. remote_adv = new_remote_adv;
  908. }
  909. /* See Table 28B-3 of 802.3ab-1999 spec. */
  910. if (local_adv & ADVERTISE_PAUSE_CAP) {
  911. if(local_adv & ADVERTISE_PAUSE_ASYM) {
  912. if (remote_adv & ADVERTISE_PAUSE_CAP) {
  913. bp->flow_ctrl = FLOW_CTRL_TX | FLOW_CTRL_RX;
  914. }
  915. else if (remote_adv & ADVERTISE_PAUSE_ASYM) {
  916. bp->flow_ctrl = FLOW_CTRL_RX;
  917. }
  918. }
  919. else {
  920. if (remote_adv & ADVERTISE_PAUSE_CAP) {
  921. bp->flow_ctrl = FLOW_CTRL_TX | FLOW_CTRL_RX;
  922. }
  923. }
  924. }
  925. else if (local_adv & ADVERTISE_PAUSE_ASYM) {
  926. if ((remote_adv & ADVERTISE_PAUSE_CAP) &&
  927. (remote_adv & ADVERTISE_PAUSE_ASYM)) {
  928. bp->flow_ctrl = FLOW_CTRL_TX;
  929. }
  930. }
  931. }
  932. static int
  933. bnx2_5709s_linkup(struct bnx2 *bp)
  934. {
  935. u32 val, speed;
  936. bp->link_up = 1;
  937. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR, MII_BNX2_BLK_ADDR_GP_STATUS);
  938. bnx2_read_phy(bp, MII_BNX2_GP_TOP_AN_STATUS1, &val);
  939. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR, MII_BNX2_BLK_ADDR_COMBO_IEEEB0);
  940. if ((bp->autoneg & AUTONEG_SPEED) == 0) {
  941. bp->line_speed = bp->req_line_speed;
  942. bp->duplex = bp->req_duplex;
  943. return 0;
  944. }
  945. speed = val & MII_BNX2_GP_TOP_AN_SPEED_MSK;
  946. switch (speed) {
  947. case MII_BNX2_GP_TOP_AN_SPEED_10:
  948. bp->line_speed = SPEED_10;
  949. break;
  950. case MII_BNX2_GP_TOP_AN_SPEED_100:
  951. bp->line_speed = SPEED_100;
  952. break;
  953. case MII_BNX2_GP_TOP_AN_SPEED_1G:
  954. case MII_BNX2_GP_TOP_AN_SPEED_1GKV:
  955. bp->line_speed = SPEED_1000;
  956. break;
  957. case MII_BNX2_GP_TOP_AN_SPEED_2_5G:
  958. bp->line_speed = SPEED_2500;
  959. break;
  960. }
  961. if (val & MII_BNX2_GP_TOP_AN_FD)
  962. bp->duplex = DUPLEX_FULL;
  963. else
  964. bp->duplex = DUPLEX_HALF;
  965. return 0;
  966. }
  967. static int
  968. bnx2_5708s_linkup(struct bnx2 *bp)
  969. {
  970. u32 val;
  971. bp->link_up = 1;
  972. bnx2_read_phy(bp, BCM5708S_1000X_STAT1, &val);
  973. switch (val & BCM5708S_1000X_STAT1_SPEED_MASK) {
  974. case BCM5708S_1000X_STAT1_SPEED_10:
  975. bp->line_speed = SPEED_10;
  976. break;
  977. case BCM5708S_1000X_STAT1_SPEED_100:
  978. bp->line_speed = SPEED_100;
  979. break;
  980. case BCM5708S_1000X_STAT1_SPEED_1G:
  981. bp->line_speed = SPEED_1000;
  982. break;
  983. case BCM5708S_1000X_STAT1_SPEED_2G5:
  984. bp->line_speed = SPEED_2500;
  985. break;
  986. }
  987. if (val & BCM5708S_1000X_STAT1_FD)
  988. bp->duplex = DUPLEX_FULL;
  989. else
  990. bp->duplex = DUPLEX_HALF;
  991. return 0;
  992. }
  993. static int
  994. bnx2_5706s_linkup(struct bnx2 *bp)
  995. {
  996. u32 bmcr, local_adv, remote_adv, common;
  997. bp->link_up = 1;
  998. bp->line_speed = SPEED_1000;
  999. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  1000. if (bmcr & BMCR_FULLDPLX) {
  1001. bp->duplex = DUPLEX_FULL;
  1002. }
  1003. else {
  1004. bp->duplex = DUPLEX_HALF;
  1005. }
  1006. if (!(bmcr & BMCR_ANENABLE)) {
  1007. return 0;
  1008. }
  1009. bnx2_read_phy(bp, bp->mii_adv, &local_adv);
  1010. bnx2_read_phy(bp, bp->mii_lpa, &remote_adv);
  1011. common = local_adv & remote_adv;
  1012. if (common & (ADVERTISE_1000XHALF | ADVERTISE_1000XFULL)) {
  1013. if (common & ADVERTISE_1000XFULL) {
  1014. bp->duplex = DUPLEX_FULL;
  1015. }
  1016. else {
  1017. bp->duplex = DUPLEX_HALF;
  1018. }
  1019. }
  1020. return 0;
  1021. }
  1022. static int
  1023. bnx2_copper_linkup(struct bnx2 *bp)
  1024. {
  1025. u32 bmcr;
  1026. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  1027. if (bmcr & BMCR_ANENABLE) {
  1028. u32 local_adv, remote_adv, common;
  1029. bnx2_read_phy(bp, MII_CTRL1000, &local_adv);
  1030. bnx2_read_phy(bp, MII_STAT1000, &remote_adv);
  1031. common = local_adv & (remote_adv >> 2);
  1032. if (common & ADVERTISE_1000FULL) {
  1033. bp->line_speed = SPEED_1000;
  1034. bp->duplex = DUPLEX_FULL;
  1035. }
  1036. else if (common & ADVERTISE_1000HALF) {
  1037. bp->line_speed = SPEED_1000;
  1038. bp->duplex = DUPLEX_HALF;
  1039. }
  1040. else {
  1041. bnx2_read_phy(bp, bp->mii_adv, &local_adv);
  1042. bnx2_read_phy(bp, bp->mii_lpa, &remote_adv);
  1043. common = local_adv & remote_adv;
  1044. if (common & ADVERTISE_100FULL) {
  1045. bp->line_speed = SPEED_100;
  1046. bp->duplex = DUPLEX_FULL;
  1047. }
  1048. else if (common & ADVERTISE_100HALF) {
  1049. bp->line_speed = SPEED_100;
  1050. bp->duplex = DUPLEX_HALF;
  1051. }
  1052. else if (common & ADVERTISE_10FULL) {
  1053. bp->line_speed = SPEED_10;
  1054. bp->duplex = DUPLEX_FULL;
  1055. }
  1056. else if (common & ADVERTISE_10HALF) {
  1057. bp->line_speed = SPEED_10;
  1058. bp->duplex = DUPLEX_HALF;
  1059. }
  1060. else {
  1061. bp->line_speed = 0;
  1062. bp->link_up = 0;
  1063. }
  1064. }
  1065. }
  1066. else {
  1067. if (bmcr & BMCR_SPEED100) {
  1068. bp->line_speed = SPEED_100;
  1069. }
  1070. else {
  1071. bp->line_speed = SPEED_10;
  1072. }
  1073. if (bmcr & BMCR_FULLDPLX) {
  1074. bp->duplex = DUPLEX_FULL;
  1075. }
  1076. else {
  1077. bp->duplex = DUPLEX_HALF;
  1078. }
  1079. }
  1080. return 0;
  1081. }
  1082. static void
  1083. bnx2_init_rx_context(struct bnx2 *bp, u32 cid)
  1084. {
  1085. u32 val, rx_cid_addr = GET_CID_ADDR(cid);
  1086. val = BNX2_L2CTX_CTX_TYPE_CTX_BD_CHN_TYPE_VALUE;
  1087. val |= BNX2_L2CTX_CTX_TYPE_SIZE_L2;
  1088. val |= 0x02 << 8;
  1089. if (bp->flow_ctrl & FLOW_CTRL_TX)
  1090. val |= BNX2_L2CTX_FLOW_CTRL_ENABLE;
  1091. bnx2_ctx_wr(bp, rx_cid_addr, BNX2_L2CTX_CTX_TYPE, val);
  1092. }
  1093. static void
  1094. bnx2_init_all_rx_contexts(struct bnx2 *bp)
  1095. {
  1096. int i;
  1097. u32 cid;
  1098. for (i = 0, cid = RX_CID; i < bp->num_rx_rings; i++, cid++) {
  1099. if (i == 1)
  1100. cid = RX_RSS_CID;
  1101. bnx2_init_rx_context(bp, cid);
  1102. }
  1103. }
  1104. static void
  1105. bnx2_set_mac_link(struct bnx2 *bp)
  1106. {
  1107. u32 val;
  1108. REG_WR(bp, BNX2_EMAC_TX_LENGTHS, 0x2620);
  1109. if (bp->link_up && (bp->line_speed == SPEED_1000) &&
  1110. (bp->duplex == DUPLEX_HALF)) {
  1111. REG_WR(bp, BNX2_EMAC_TX_LENGTHS, 0x26ff);
  1112. }
  1113. /* Configure the EMAC mode register. */
  1114. val = REG_RD(bp, BNX2_EMAC_MODE);
  1115. val &= ~(BNX2_EMAC_MODE_PORT | BNX2_EMAC_MODE_HALF_DUPLEX |
  1116. BNX2_EMAC_MODE_MAC_LOOP | BNX2_EMAC_MODE_FORCE_LINK |
  1117. BNX2_EMAC_MODE_25G_MODE);
  1118. if (bp->link_up) {
  1119. switch (bp->line_speed) {
  1120. case SPEED_10:
  1121. if (CHIP_NUM(bp) != CHIP_NUM_5706) {
  1122. val |= BNX2_EMAC_MODE_PORT_MII_10M;
  1123. break;
  1124. }
  1125. /* fall through */
  1126. case SPEED_100:
  1127. val |= BNX2_EMAC_MODE_PORT_MII;
  1128. break;
  1129. case SPEED_2500:
  1130. val |= BNX2_EMAC_MODE_25G_MODE;
  1131. /* fall through */
  1132. case SPEED_1000:
  1133. val |= BNX2_EMAC_MODE_PORT_GMII;
  1134. break;
  1135. }
  1136. }
  1137. else {
  1138. val |= BNX2_EMAC_MODE_PORT_GMII;
  1139. }
  1140. /* Set the MAC to operate in the appropriate duplex mode. */
  1141. if (bp->duplex == DUPLEX_HALF)
  1142. val |= BNX2_EMAC_MODE_HALF_DUPLEX;
  1143. REG_WR(bp, BNX2_EMAC_MODE, val);
  1144. /* Enable/disable rx PAUSE. */
  1145. bp->rx_mode &= ~BNX2_EMAC_RX_MODE_FLOW_EN;
  1146. if (bp->flow_ctrl & FLOW_CTRL_RX)
  1147. bp->rx_mode |= BNX2_EMAC_RX_MODE_FLOW_EN;
  1148. REG_WR(bp, BNX2_EMAC_RX_MODE, bp->rx_mode);
  1149. /* Enable/disable tx PAUSE. */
  1150. val = REG_RD(bp, BNX2_EMAC_TX_MODE);
  1151. val &= ~BNX2_EMAC_TX_MODE_FLOW_EN;
  1152. if (bp->flow_ctrl & FLOW_CTRL_TX)
  1153. val |= BNX2_EMAC_TX_MODE_FLOW_EN;
  1154. REG_WR(bp, BNX2_EMAC_TX_MODE, val);
  1155. /* Acknowledge the interrupt. */
  1156. REG_WR(bp, BNX2_EMAC_STATUS, BNX2_EMAC_STATUS_LINK_CHANGE);
  1157. bnx2_init_all_rx_contexts(bp);
  1158. }
  1159. static void
  1160. bnx2_enable_bmsr1(struct bnx2 *bp)
  1161. {
  1162. if ((bp->phy_flags & BNX2_PHY_FLAG_SERDES) &&
  1163. (CHIP_NUM(bp) == CHIP_NUM_5709))
  1164. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR,
  1165. MII_BNX2_BLK_ADDR_GP_STATUS);
  1166. }
  1167. static void
  1168. bnx2_disable_bmsr1(struct bnx2 *bp)
  1169. {
  1170. if ((bp->phy_flags & BNX2_PHY_FLAG_SERDES) &&
  1171. (CHIP_NUM(bp) == CHIP_NUM_5709))
  1172. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR,
  1173. MII_BNX2_BLK_ADDR_COMBO_IEEEB0);
  1174. }
  1175. static int
  1176. bnx2_test_and_enable_2g5(struct bnx2 *bp)
  1177. {
  1178. u32 up1;
  1179. int ret = 1;
  1180. if (!(bp->phy_flags & BNX2_PHY_FLAG_2_5G_CAPABLE))
  1181. return 0;
  1182. if (bp->autoneg & AUTONEG_SPEED)
  1183. bp->advertising |= ADVERTISED_2500baseX_Full;
  1184. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  1185. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR, MII_BNX2_BLK_ADDR_OVER1G);
  1186. bnx2_read_phy(bp, bp->mii_up1, &up1);
  1187. if (!(up1 & BCM5708S_UP1_2G5)) {
  1188. up1 |= BCM5708S_UP1_2G5;
  1189. bnx2_write_phy(bp, bp->mii_up1, up1);
  1190. ret = 0;
  1191. }
  1192. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  1193. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR,
  1194. MII_BNX2_BLK_ADDR_COMBO_IEEEB0);
  1195. return ret;
  1196. }
  1197. static int
  1198. bnx2_test_and_disable_2g5(struct bnx2 *bp)
  1199. {
  1200. u32 up1;
  1201. int ret = 0;
  1202. if (!(bp->phy_flags & BNX2_PHY_FLAG_2_5G_CAPABLE))
  1203. return 0;
  1204. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  1205. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR, MII_BNX2_BLK_ADDR_OVER1G);
  1206. bnx2_read_phy(bp, bp->mii_up1, &up1);
  1207. if (up1 & BCM5708S_UP1_2G5) {
  1208. up1 &= ~BCM5708S_UP1_2G5;
  1209. bnx2_write_phy(bp, bp->mii_up1, up1);
  1210. ret = 1;
  1211. }
  1212. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  1213. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR,
  1214. MII_BNX2_BLK_ADDR_COMBO_IEEEB0);
  1215. return ret;
  1216. }
  1217. static void
  1218. bnx2_enable_forced_2g5(struct bnx2 *bp)
  1219. {
  1220. u32 uninitialized_var(bmcr);
  1221. int err;
  1222. if (!(bp->phy_flags & BNX2_PHY_FLAG_2_5G_CAPABLE))
  1223. return;
  1224. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  1225. u32 val;
  1226. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR,
  1227. MII_BNX2_BLK_ADDR_SERDES_DIG);
  1228. if (!bnx2_read_phy(bp, MII_BNX2_SERDES_DIG_MISC1, &val)) {
  1229. val &= ~MII_BNX2_SD_MISC1_FORCE_MSK;
  1230. val |= MII_BNX2_SD_MISC1_FORCE |
  1231. MII_BNX2_SD_MISC1_FORCE_2_5G;
  1232. bnx2_write_phy(bp, MII_BNX2_SERDES_DIG_MISC1, val);
  1233. }
  1234. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR,
  1235. MII_BNX2_BLK_ADDR_COMBO_IEEEB0);
  1236. err = bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  1237. } else if (CHIP_NUM(bp) == CHIP_NUM_5708) {
  1238. err = bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  1239. if (!err)
  1240. bmcr |= BCM5708S_BMCR_FORCE_2500;
  1241. } else {
  1242. return;
  1243. }
  1244. if (err)
  1245. return;
  1246. if (bp->autoneg & AUTONEG_SPEED) {
  1247. bmcr &= ~BMCR_ANENABLE;
  1248. if (bp->req_duplex == DUPLEX_FULL)
  1249. bmcr |= BMCR_FULLDPLX;
  1250. }
  1251. bnx2_write_phy(bp, bp->mii_bmcr, bmcr);
  1252. }
  1253. static void
  1254. bnx2_disable_forced_2g5(struct bnx2 *bp)
  1255. {
  1256. u32 uninitialized_var(bmcr);
  1257. int err;
  1258. if (!(bp->phy_flags & BNX2_PHY_FLAG_2_5G_CAPABLE))
  1259. return;
  1260. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  1261. u32 val;
  1262. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR,
  1263. MII_BNX2_BLK_ADDR_SERDES_DIG);
  1264. if (!bnx2_read_phy(bp, MII_BNX2_SERDES_DIG_MISC1, &val)) {
  1265. val &= ~MII_BNX2_SD_MISC1_FORCE;
  1266. bnx2_write_phy(bp, MII_BNX2_SERDES_DIG_MISC1, val);
  1267. }
  1268. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR,
  1269. MII_BNX2_BLK_ADDR_COMBO_IEEEB0);
  1270. err = bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  1271. } else if (CHIP_NUM(bp) == CHIP_NUM_5708) {
  1272. err = bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  1273. if (!err)
  1274. bmcr &= ~BCM5708S_BMCR_FORCE_2500;
  1275. } else {
  1276. return;
  1277. }
  1278. if (err)
  1279. return;
  1280. if (bp->autoneg & AUTONEG_SPEED)
  1281. bmcr |= BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_ANRESTART;
  1282. bnx2_write_phy(bp, bp->mii_bmcr, bmcr);
  1283. }
  1284. static void
  1285. bnx2_5706s_force_link_dn(struct bnx2 *bp, int start)
  1286. {
  1287. u32 val;
  1288. bnx2_write_phy(bp, MII_BNX2_DSP_ADDRESS, MII_EXPAND_SERDES_CTL);
  1289. bnx2_read_phy(bp, MII_BNX2_DSP_RW_PORT, &val);
  1290. if (start)
  1291. bnx2_write_phy(bp, MII_BNX2_DSP_RW_PORT, val & 0xff0f);
  1292. else
  1293. bnx2_write_phy(bp, MII_BNX2_DSP_RW_PORT, val | 0xc0);
  1294. }
  1295. static int
  1296. bnx2_set_link(struct bnx2 *bp)
  1297. {
  1298. u32 bmsr;
  1299. u8 link_up;
  1300. if (bp->loopback == MAC_LOOPBACK || bp->loopback == PHY_LOOPBACK) {
  1301. bp->link_up = 1;
  1302. return 0;
  1303. }
  1304. if (bp->phy_flags & BNX2_PHY_FLAG_REMOTE_PHY_CAP)
  1305. return 0;
  1306. link_up = bp->link_up;
  1307. bnx2_enable_bmsr1(bp);
  1308. bnx2_read_phy(bp, bp->mii_bmsr1, &bmsr);
  1309. bnx2_read_phy(bp, bp->mii_bmsr1, &bmsr);
  1310. bnx2_disable_bmsr1(bp);
  1311. if ((bp->phy_flags & BNX2_PHY_FLAG_SERDES) &&
  1312. (CHIP_NUM(bp) == CHIP_NUM_5706)) {
  1313. u32 val, an_dbg;
  1314. if (bp->phy_flags & BNX2_PHY_FLAG_FORCED_DOWN) {
  1315. bnx2_5706s_force_link_dn(bp, 0);
  1316. bp->phy_flags &= ~BNX2_PHY_FLAG_FORCED_DOWN;
  1317. }
  1318. val = REG_RD(bp, BNX2_EMAC_STATUS);
  1319. bnx2_write_phy(bp, MII_BNX2_MISC_SHADOW, MISC_SHDW_AN_DBG);
  1320. bnx2_read_phy(bp, MII_BNX2_MISC_SHADOW, &an_dbg);
  1321. bnx2_read_phy(bp, MII_BNX2_MISC_SHADOW, &an_dbg);
  1322. if ((val & BNX2_EMAC_STATUS_LINK) &&
  1323. !(an_dbg & MISC_SHDW_AN_DBG_NOSYNC))
  1324. bmsr |= BMSR_LSTATUS;
  1325. else
  1326. bmsr &= ~BMSR_LSTATUS;
  1327. }
  1328. if (bmsr & BMSR_LSTATUS) {
  1329. bp->link_up = 1;
  1330. if (bp->phy_flags & BNX2_PHY_FLAG_SERDES) {
  1331. if (CHIP_NUM(bp) == CHIP_NUM_5706)
  1332. bnx2_5706s_linkup(bp);
  1333. else if (CHIP_NUM(bp) == CHIP_NUM_5708)
  1334. bnx2_5708s_linkup(bp);
  1335. else if (CHIP_NUM(bp) == CHIP_NUM_5709)
  1336. bnx2_5709s_linkup(bp);
  1337. }
  1338. else {
  1339. bnx2_copper_linkup(bp);
  1340. }
  1341. bnx2_resolve_flow_ctrl(bp);
  1342. }
  1343. else {
  1344. if ((bp->phy_flags & BNX2_PHY_FLAG_SERDES) &&
  1345. (bp->autoneg & AUTONEG_SPEED))
  1346. bnx2_disable_forced_2g5(bp);
  1347. if (bp->phy_flags & BNX2_PHY_FLAG_PARALLEL_DETECT) {
  1348. u32 bmcr;
  1349. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  1350. bmcr |= BMCR_ANENABLE;
  1351. bnx2_write_phy(bp, bp->mii_bmcr, bmcr);
  1352. bp->phy_flags &= ~BNX2_PHY_FLAG_PARALLEL_DETECT;
  1353. }
  1354. bp->link_up = 0;
  1355. }
  1356. if (bp->link_up != link_up) {
  1357. bnx2_report_link(bp);
  1358. }
  1359. bnx2_set_mac_link(bp);
  1360. return 0;
  1361. }
  1362. static int
  1363. bnx2_reset_phy(struct bnx2 *bp)
  1364. {
  1365. int i;
  1366. u32 reg;
  1367. bnx2_write_phy(bp, bp->mii_bmcr, BMCR_RESET);
  1368. #define PHY_RESET_MAX_WAIT 100
  1369. for (i = 0; i < PHY_RESET_MAX_WAIT; i++) {
  1370. udelay(10);
  1371. bnx2_read_phy(bp, bp->mii_bmcr, &reg);
  1372. if (!(reg & BMCR_RESET)) {
  1373. udelay(20);
  1374. break;
  1375. }
  1376. }
  1377. if (i == PHY_RESET_MAX_WAIT) {
  1378. return -EBUSY;
  1379. }
  1380. return 0;
  1381. }
  1382. static u32
  1383. bnx2_phy_get_pause_adv(struct bnx2 *bp)
  1384. {
  1385. u32 adv = 0;
  1386. if ((bp->req_flow_ctrl & (FLOW_CTRL_RX | FLOW_CTRL_TX)) ==
  1387. (FLOW_CTRL_RX | FLOW_CTRL_TX)) {
  1388. if (bp->phy_flags & BNX2_PHY_FLAG_SERDES) {
  1389. adv = ADVERTISE_1000XPAUSE;
  1390. }
  1391. else {
  1392. adv = ADVERTISE_PAUSE_CAP;
  1393. }
  1394. }
  1395. else if (bp->req_flow_ctrl & FLOW_CTRL_TX) {
  1396. if (bp->phy_flags & BNX2_PHY_FLAG_SERDES) {
  1397. adv = ADVERTISE_1000XPSE_ASYM;
  1398. }
  1399. else {
  1400. adv = ADVERTISE_PAUSE_ASYM;
  1401. }
  1402. }
  1403. else if (bp->req_flow_ctrl & FLOW_CTRL_RX) {
  1404. if (bp->phy_flags & BNX2_PHY_FLAG_SERDES) {
  1405. adv = ADVERTISE_1000XPAUSE | ADVERTISE_1000XPSE_ASYM;
  1406. }
  1407. else {
  1408. adv = ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
  1409. }
  1410. }
  1411. return adv;
  1412. }
  1413. static int bnx2_fw_sync(struct bnx2 *, u32, int, int);
  1414. static int
  1415. bnx2_setup_remote_phy(struct bnx2 *bp, u8 port)
  1416. __releases(&bp->phy_lock)
  1417. __acquires(&bp->phy_lock)
  1418. {
  1419. u32 speed_arg = 0, pause_adv;
  1420. pause_adv = bnx2_phy_get_pause_adv(bp);
  1421. if (bp->autoneg & AUTONEG_SPEED) {
  1422. speed_arg |= BNX2_NETLINK_SET_LINK_ENABLE_AUTONEG;
  1423. if (bp->advertising & ADVERTISED_10baseT_Half)
  1424. speed_arg |= BNX2_NETLINK_SET_LINK_SPEED_10HALF;
  1425. if (bp->advertising & ADVERTISED_10baseT_Full)
  1426. speed_arg |= BNX2_NETLINK_SET_LINK_SPEED_10FULL;
  1427. if (bp->advertising & ADVERTISED_100baseT_Half)
  1428. speed_arg |= BNX2_NETLINK_SET_LINK_SPEED_100HALF;
  1429. if (bp->advertising & ADVERTISED_100baseT_Full)
  1430. speed_arg |= BNX2_NETLINK_SET_LINK_SPEED_100FULL;
  1431. if (bp->advertising & ADVERTISED_1000baseT_Full)
  1432. speed_arg |= BNX2_NETLINK_SET_LINK_SPEED_1GFULL;
  1433. if (bp->advertising & ADVERTISED_2500baseX_Full)
  1434. speed_arg |= BNX2_NETLINK_SET_LINK_SPEED_2G5FULL;
  1435. } else {
  1436. if (bp->req_line_speed == SPEED_2500)
  1437. speed_arg = BNX2_NETLINK_SET_LINK_SPEED_2G5FULL;
  1438. else if (bp->req_line_speed == SPEED_1000)
  1439. speed_arg = BNX2_NETLINK_SET_LINK_SPEED_1GFULL;
  1440. else if (bp->req_line_speed == SPEED_100) {
  1441. if (bp->req_duplex == DUPLEX_FULL)
  1442. speed_arg = BNX2_NETLINK_SET_LINK_SPEED_100FULL;
  1443. else
  1444. speed_arg = BNX2_NETLINK_SET_LINK_SPEED_100HALF;
  1445. } else if (bp->req_line_speed == SPEED_10) {
  1446. if (bp->req_duplex == DUPLEX_FULL)
  1447. speed_arg = BNX2_NETLINK_SET_LINK_SPEED_10FULL;
  1448. else
  1449. speed_arg = BNX2_NETLINK_SET_LINK_SPEED_10HALF;
  1450. }
  1451. }
  1452. if (pause_adv & (ADVERTISE_1000XPAUSE | ADVERTISE_PAUSE_CAP))
  1453. speed_arg |= BNX2_NETLINK_SET_LINK_FC_SYM_PAUSE;
  1454. if (pause_adv & (ADVERTISE_1000XPSE_ASYM | ADVERTISE_PAUSE_ASYM))
  1455. speed_arg |= BNX2_NETLINK_SET_LINK_FC_ASYM_PAUSE;
  1456. if (port == PORT_TP)
  1457. speed_arg |= BNX2_NETLINK_SET_LINK_PHY_APP_REMOTE |
  1458. BNX2_NETLINK_SET_LINK_ETH_AT_WIRESPEED;
  1459. bnx2_shmem_wr(bp, BNX2_DRV_MB_ARG0, speed_arg);
  1460. spin_unlock_bh(&bp->phy_lock);
  1461. bnx2_fw_sync(bp, BNX2_DRV_MSG_CODE_CMD_SET_LINK, 1, 0);
  1462. spin_lock_bh(&bp->phy_lock);
  1463. return 0;
  1464. }
  1465. static int
  1466. bnx2_setup_serdes_phy(struct bnx2 *bp, u8 port)
  1467. __releases(&bp->phy_lock)
  1468. __acquires(&bp->phy_lock)
  1469. {
  1470. u32 adv, bmcr;
  1471. u32 new_adv = 0;
  1472. if (bp->phy_flags & BNX2_PHY_FLAG_REMOTE_PHY_CAP)
  1473. return bnx2_setup_remote_phy(bp, port);
  1474. if (!(bp->autoneg & AUTONEG_SPEED)) {
  1475. u32 new_bmcr;
  1476. int force_link_down = 0;
  1477. if (bp->req_line_speed == SPEED_2500) {
  1478. if (!bnx2_test_and_enable_2g5(bp))
  1479. force_link_down = 1;
  1480. } else if (bp->req_line_speed == SPEED_1000) {
  1481. if (bnx2_test_and_disable_2g5(bp))
  1482. force_link_down = 1;
  1483. }
  1484. bnx2_read_phy(bp, bp->mii_adv, &adv);
  1485. adv &= ~(ADVERTISE_1000XFULL | ADVERTISE_1000XHALF);
  1486. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  1487. new_bmcr = bmcr & ~BMCR_ANENABLE;
  1488. new_bmcr |= BMCR_SPEED1000;
  1489. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  1490. if (bp->req_line_speed == SPEED_2500)
  1491. bnx2_enable_forced_2g5(bp);
  1492. else if (bp->req_line_speed == SPEED_1000) {
  1493. bnx2_disable_forced_2g5(bp);
  1494. new_bmcr &= ~0x2000;
  1495. }
  1496. } else if (CHIP_NUM(bp) == CHIP_NUM_5708) {
  1497. if (bp->req_line_speed == SPEED_2500)
  1498. new_bmcr |= BCM5708S_BMCR_FORCE_2500;
  1499. else
  1500. new_bmcr = bmcr & ~BCM5708S_BMCR_FORCE_2500;
  1501. }
  1502. if (bp->req_duplex == DUPLEX_FULL) {
  1503. adv |= ADVERTISE_1000XFULL;
  1504. new_bmcr |= BMCR_FULLDPLX;
  1505. }
  1506. else {
  1507. adv |= ADVERTISE_1000XHALF;
  1508. new_bmcr &= ~BMCR_FULLDPLX;
  1509. }
  1510. if ((new_bmcr != bmcr) || (force_link_down)) {
  1511. /* Force a link down visible on the other side */
  1512. if (bp->link_up) {
  1513. bnx2_write_phy(bp, bp->mii_adv, adv &
  1514. ~(ADVERTISE_1000XFULL |
  1515. ADVERTISE_1000XHALF));
  1516. bnx2_write_phy(bp, bp->mii_bmcr, bmcr |
  1517. BMCR_ANRESTART | BMCR_ANENABLE);
  1518. bp->link_up = 0;
  1519. netif_carrier_off(bp->dev);
  1520. bnx2_write_phy(bp, bp->mii_bmcr, new_bmcr);
  1521. bnx2_report_link(bp);
  1522. }
  1523. bnx2_write_phy(bp, bp->mii_adv, adv);
  1524. bnx2_write_phy(bp, bp->mii_bmcr, new_bmcr);
  1525. } else {
  1526. bnx2_resolve_flow_ctrl(bp);
  1527. bnx2_set_mac_link(bp);
  1528. }
  1529. return 0;
  1530. }
  1531. bnx2_test_and_enable_2g5(bp);
  1532. if (bp->advertising & ADVERTISED_1000baseT_Full)
  1533. new_adv |= ADVERTISE_1000XFULL;
  1534. new_adv |= bnx2_phy_get_pause_adv(bp);
  1535. bnx2_read_phy(bp, bp->mii_adv, &adv);
  1536. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  1537. bp->serdes_an_pending = 0;
  1538. if ((adv != new_adv) || ((bmcr & BMCR_ANENABLE) == 0)) {
  1539. /* Force a link down visible on the other side */
  1540. if (bp->link_up) {
  1541. bnx2_write_phy(bp, bp->mii_bmcr, BMCR_LOOPBACK);
  1542. spin_unlock_bh(&bp->phy_lock);
  1543. msleep(20);
  1544. spin_lock_bh(&bp->phy_lock);
  1545. }
  1546. bnx2_write_phy(bp, bp->mii_adv, new_adv);
  1547. bnx2_write_phy(bp, bp->mii_bmcr, bmcr | BMCR_ANRESTART |
  1548. BMCR_ANENABLE);
  1549. /* Speed up link-up time when the link partner
  1550. * does not autonegotiate which is very common
  1551. * in blade servers. Some blade servers use
  1552. * IPMI for kerboard input and it's important
  1553. * to minimize link disruptions. Autoneg. involves
  1554. * exchanging base pages plus 3 next pages and
  1555. * normally completes in about 120 msec.
  1556. */
  1557. bp->current_interval = BNX2_SERDES_AN_TIMEOUT;
  1558. bp->serdes_an_pending = 1;
  1559. mod_timer(&bp->timer, jiffies + bp->current_interval);
  1560. } else {
  1561. bnx2_resolve_flow_ctrl(bp);
  1562. bnx2_set_mac_link(bp);
  1563. }
  1564. return 0;
  1565. }
  1566. #define ETHTOOL_ALL_FIBRE_SPEED \
  1567. (bp->phy_flags & BNX2_PHY_FLAG_2_5G_CAPABLE) ? \
  1568. (ADVERTISED_2500baseX_Full | ADVERTISED_1000baseT_Full) :\
  1569. (ADVERTISED_1000baseT_Full)
  1570. #define ETHTOOL_ALL_COPPER_SPEED \
  1571. (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | \
  1572. ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | \
  1573. ADVERTISED_1000baseT_Full)
  1574. #define PHY_ALL_10_100_SPEED (ADVERTISE_10HALF | ADVERTISE_10FULL | \
  1575. ADVERTISE_100HALF | ADVERTISE_100FULL | ADVERTISE_CSMA)
  1576. #define PHY_ALL_1000_SPEED (ADVERTISE_1000HALF | ADVERTISE_1000FULL)
  1577. static void
  1578. bnx2_set_default_remote_link(struct bnx2 *bp)
  1579. {
  1580. u32 link;
  1581. if (bp->phy_port == PORT_TP)
  1582. link = bnx2_shmem_rd(bp, BNX2_RPHY_COPPER_LINK);
  1583. else
  1584. link = bnx2_shmem_rd(bp, BNX2_RPHY_SERDES_LINK);
  1585. if (link & BNX2_NETLINK_SET_LINK_ENABLE_AUTONEG) {
  1586. bp->req_line_speed = 0;
  1587. bp->autoneg |= AUTONEG_SPEED;
  1588. bp->advertising = ADVERTISED_Autoneg;
  1589. if (link & BNX2_NETLINK_SET_LINK_SPEED_10HALF)
  1590. bp->advertising |= ADVERTISED_10baseT_Half;
  1591. if (link & BNX2_NETLINK_SET_LINK_SPEED_10FULL)
  1592. bp->advertising |= ADVERTISED_10baseT_Full;
  1593. if (link & BNX2_NETLINK_SET_LINK_SPEED_100HALF)
  1594. bp->advertising |= ADVERTISED_100baseT_Half;
  1595. if (link & BNX2_NETLINK_SET_LINK_SPEED_100FULL)
  1596. bp->advertising |= ADVERTISED_100baseT_Full;
  1597. if (link & BNX2_NETLINK_SET_LINK_SPEED_1GFULL)
  1598. bp->advertising |= ADVERTISED_1000baseT_Full;
  1599. if (link & BNX2_NETLINK_SET_LINK_SPEED_2G5FULL)
  1600. bp->advertising |= ADVERTISED_2500baseX_Full;
  1601. } else {
  1602. bp->autoneg = 0;
  1603. bp->advertising = 0;
  1604. bp->req_duplex = DUPLEX_FULL;
  1605. if (link & BNX2_NETLINK_SET_LINK_SPEED_10) {
  1606. bp->req_line_speed = SPEED_10;
  1607. if (link & BNX2_NETLINK_SET_LINK_SPEED_10HALF)
  1608. bp->req_duplex = DUPLEX_HALF;
  1609. }
  1610. if (link & BNX2_NETLINK_SET_LINK_SPEED_100) {
  1611. bp->req_line_speed = SPEED_100;
  1612. if (link & BNX2_NETLINK_SET_LINK_SPEED_100HALF)
  1613. bp->req_duplex = DUPLEX_HALF;
  1614. }
  1615. if (link & BNX2_NETLINK_SET_LINK_SPEED_1GFULL)
  1616. bp->req_line_speed = SPEED_1000;
  1617. if (link & BNX2_NETLINK_SET_LINK_SPEED_2G5FULL)
  1618. bp->req_line_speed = SPEED_2500;
  1619. }
  1620. }
  1621. static void
  1622. bnx2_set_default_link(struct bnx2 *bp)
  1623. {
  1624. if (bp->phy_flags & BNX2_PHY_FLAG_REMOTE_PHY_CAP) {
  1625. bnx2_set_default_remote_link(bp);
  1626. return;
  1627. }
  1628. bp->autoneg = AUTONEG_SPEED | AUTONEG_FLOW_CTRL;
  1629. bp->req_line_speed = 0;
  1630. if (bp->phy_flags & BNX2_PHY_FLAG_SERDES) {
  1631. u32 reg;
  1632. bp->advertising = ETHTOOL_ALL_FIBRE_SPEED | ADVERTISED_Autoneg;
  1633. reg = bnx2_shmem_rd(bp, BNX2_PORT_HW_CFG_CONFIG);
  1634. reg &= BNX2_PORT_HW_CFG_CFG_DFLT_LINK_MASK;
  1635. if (reg == BNX2_PORT_HW_CFG_CFG_DFLT_LINK_1G) {
  1636. bp->autoneg = 0;
  1637. bp->req_line_speed = bp->line_speed = SPEED_1000;
  1638. bp->req_duplex = DUPLEX_FULL;
  1639. }
  1640. } else
  1641. bp->advertising = ETHTOOL_ALL_COPPER_SPEED | ADVERTISED_Autoneg;
  1642. }
  1643. static void
  1644. bnx2_send_heart_beat(struct bnx2 *bp)
  1645. {
  1646. u32 msg;
  1647. u32 addr;
  1648. spin_lock(&bp->indirect_lock);
  1649. msg = (u32) (++bp->fw_drv_pulse_wr_seq & BNX2_DRV_PULSE_SEQ_MASK);
  1650. addr = bp->shmem_base + BNX2_DRV_PULSE_MB;
  1651. REG_WR(bp, BNX2_PCICFG_REG_WINDOW_ADDRESS, addr);
  1652. REG_WR(bp, BNX2_PCICFG_REG_WINDOW, msg);
  1653. spin_unlock(&bp->indirect_lock);
  1654. }
  1655. static void
  1656. bnx2_remote_phy_event(struct bnx2 *bp)
  1657. {
  1658. u32 msg;
  1659. u8 link_up = bp->link_up;
  1660. u8 old_port;
  1661. msg = bnx2_shmem_rd(bp, BNX2_LINK_STATUS);
  1662. if (msg & BNX2_LINK_STATUS_HEART_BEAT_EXPIRED)
  1663. bnx2_send_heart_beat(bp);
  1664. msg &= ~BNX2_LINK_STATUS_HEART_BEAT_EXPIRED;
  1665. if ((msg & BNX2_LINK_STATUS_LINK_UP) == BNX2_LINK_STATUS_LINK_DOWN)
  1666. bp->link_up = 0;
  1667. else {
  1668. u32 speed;
  1669. bp->link_up = 1;
  1670. speed = msg & BNX2_LINK_STATUS_SPEED_MASK;
  1671. bp->duplex = DUPLEX_FULL;
  1672. switch (speed) {
  1673. case BNX2_LINK_STATUS_10HALF:
  1674. bp->duplex = DUPLEX_HALF;
  1675. case BNX2_LINK_STATUS_10FULL:
  1676. bp->line_speed = SPEED_10;
  1677. break;
  1678. case BNX2_LINK_STATUS_100HALF:
  1679. bp->duplex = DUPLEX_HALF;
  1680. case BNX2_LINK_STATUS_100BASE_T4:
  1681. case BNX2_LINK_STATUS_100FULL:
  1682. bp->line_speed = SPEED_100;
  1683. break;
  1684. case BNX2_LINK_STATUS_1000HALF:
  1685. bp->duplex = DUPLEX_HALF;
  1686. case BNX2_LINK_STATUS_1000FULL:
  1687. bp->line_speed = SPEED_1000;
  1688. break;
  1689. case BNX2_LINK_STATUS_2500HALF:
  1690. bp->duplex = DUPLEX_HALF;
  1691. case BNX2_LINK_STATUS_2500FULL:
  1692. bp->line_speed = SPEED_2500;
  1693. break;
  1694. default:
  1695. bp->line_speed = 0;
  1696. break;
  1697. }
  1698. bp->flow_ctrl = 0;
  1699. if ((bp->autoneg & (AUTONEG_SPEED | AUTONEG_FLOW_CTRL)) !=
  1700. (AUTONEG_SPEED | AUTONEG_FLOW_CTRL)) {
  1701. if (bp->duplex == DUPLEX_FULL)
  1702. bp->flow_ctrl = bp->req_flow_ctrl;
  1703. } else {
  1704. if (msg & BNX2_LINK_STATUS_TX_FC_ENABLED)
  1705. bp->flow_ctrl |= FLOW_CTRL_TX;
  1706. if (msg & BNX2_LINK_STATUS_RX_FC_ENABLED)
  1707. bp->flow_ctrl |= FLOW_CTRL_RX;
  1708. }
  1709. old_port = bp->phy_port;
  1710. if (msg & BNX2_LINK_STATUS_SERDES_LINK)
  1711. bp->phy_port = PORT_FIBRE;
  1712. else
  1713. bp->phy_port = PORT_TP;
  1714. if (old_port != bp->phy_port)
  1715. bnx2_set_default_link(bp);
  1716. }
  1717. if (bp->link_up != link_up)
  1718. bnx2_report_link(bp);
  1719. bnx2_set_mac_link(bp);
  1720. }
  1721. static int
  1722. bnx2_set_remote_link(struct bnx2 *bp)
  1723. {
  1724. u32 evt_code;
  1725. evt_code = bnx2_shmem_rd(bp, BNX2_FW_EVT_CODE_MB);
  1726. switch (evt_code) {
  1727. case BNX2_FW_EVT_CODE_LINK_EVENT:
  1728. bnx2_remote_phy_event(bp);
  1729. break;
  1730. case BNX2_FW_EVT_CODE_SW_TIMER_EXPIRATION_EVENT:
  1731. default:
  1732. bnx2_send_heart_beat(bp);
  1733. break;
  1734. }
  1735. return 0;
  1736. }
  1737. static int
  1738. bnx2_setup_copper_phy(struct bnx2 *bp)
  1739. __releases(&bp->phy_lock)
  1740. __acquires(&bp->phy_lock)
  1741. {
  1742. u32 bmcr;
  1743. u32 new_bmcr;
  1744. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  1745. if (bp->autoneg & AUTONEG_SPEED) {
  1746. u32 adv_reg, adv1000_reg;
  1747. u32 new_adv_reg = 0;
  1748. u32 new_adv1000_reg = 0;
  1749. bnx2_read_phy(bp, bp->mii_adv, &adv_reg);
  1750. adv_reg &= (PHY_ALL_10_100_SPEED | ADVERTISE_PAUSE_CAP |
  1751. ADVERTISE_PAUSE_ASYM);
  1752. bnx2_read_phy(bp, MII_CTRL1000, &adv1000_reg);
  1753. adv1000_reg &= PHY_ALL_1000_SPEED;
  1754. if (bp->advertising & ADVERTISED_10baseT_Half)
  1755. new_adv_reg |= ADVERTISE_10HALF;
  1756. if (bp->advertising & ADVERTISED_10baseT_Full)
  1757. new_adv_reg |= ADVERTISE_10FULL;
  1758. if (bp->advertising & ADVERTISED_100baseT_Half)
  1759. new_adv_reg |= ADVERTISE_100HALF;
  1760. if (bp->advertising & ADVERTISED_100baseT_Full)
  1761. new_adv_reg |= ADVERTISE_100FULL;
  1762. if (bp->advertising & ADVERTISED_1000baseT_Full)
  1763. new_adv1000_reg |= ADVERTISE_1000FULL;
  1764. new_adv_reg |= ADVERTISE_CSMA;
  1765. new_adv_reg |= bnx2_phy_get_pause_adv(bp);
  1766. if ((adv1000_reg != new_adv1000_reg) ||
  1767. (adv_reg != new_adv_reg) ||
  1768. ((bmcr & BMCR_ANENABLE) == 0)) {
  1769. bnx2_write_phy(bp, bp->mii_adv, new_adv_reg);
  1770. bnx2_write_phy(bp, MII_CTRL1000, new_adv1000_reg);
  1771. bnx2_write_phy(bp, bp->mii_bmcr, BMCR_ANRESTART |
  1772. BMCR_ANENABLE);
  1773. }
  1774. else if (bp->link_up) {
  1775. /* Flow ctrl may have changed from auto to forced */
  1776. /* or vice-versa. */
  1777. bnx2_resolve_flow_ctrl(bp);
  1778. bnx2_set_mac_link(bp);
  1779. }
  1780. return 0;
  1781. }
  1782. new_bmcr = 0;
  1783. if (bp->req_line_speed == SPEED_100) {
  1784. new_bmcr |= BMCR_SPEED100;
  1785. }
  1786. if (bp->req_duplex == DUPLEX_FULL) {
  1787. new_bmcr |= BMCR_FULLDPLX;
  1788. }
  1789. if (new_bmcr != bmcr) {
  1790. u32 bmsr;
  1791. bnx2_read_phy(bp, bp->mii_bmsr, &bmsr);
  1792. bnx2_read_phy(bp, bp->mii_bmsr, &bmsr);
  1793. if (bmsr & BMSR_LSTATUS) {
  1794. /* Force link down */
  1795. bnx2_write_phy(bp, bp->mii_bmcr, BMCR_LOOPBACK);
  1796. spin_unlock_bh(&bp->phy_lock);
  1797. msleep(50);
  1798. spin_lock_bh(&bp->phy_lock);
  1799. bnx2_read_phy(bp, bp->mii_bmsr, &bmsr);
  1800. bnx2_read_phy(bp, bp->mii_bmsr, &bmsr);
  1801. }
  1802. bnx2_write_phy(bp, bp->mii_bmcr, new_bmcr);
  1803. /* Normally, the new speed is setup after the link has
  1804. * gone down and up again. In some cases, link will not go
  1805. * down so we need to set up the new speed here.
  1806. */
  1807. if (bmsr & BMSR_LSTATUS) {
  1808. bp->line_speed = bp->req_line_speed;
  1809. bp->duplex = bp->req_duplex;
  1810. bnx2_resolve_flow_ctrl(bp);
  1811. bnx2_set_mac_link(bp);
  1812. }
  1813. } else {
  1814. bnx2_resolve_flow_ctrl(bp);
  1815. bnx2_set_mac_link(bp);
  1816. }
  1817. return 0;
  1818. }
  1819. static int
  1820. bnx2_setup_phy(struct bnx2 *bp, u8 port)
  1821. __releases(&bp->phy_lock)
  1822. __acquires(&bp->phy_lock)
  1823. {
  1824. if (bp->loopback == MAC_LOOPBACK)
  1825. return 0;
  1826. if (bp->phy_flags & BNX2_PHY_FLAG_SERDES) {
  1827. return bnx2_setup_serdes_phy(bp, port);
  1828. }
  1829. else {
  1830. return bnx2_setup_copper_phy(bp);
  1831. }
  1832. }
  1833. static int
  1834. bnx2_init_5709s_phy(struct bnx2 *bp, int reset_phy)
  1835. {
  1836. u32 val;
  1837. bp->mii_bmcr = MII_BMCR + 0x10;
  1838. bp->mii_bmsr = MII_BMSR + 0x10;
  1839. bp->mii_bmsr1 = MII_BNX2_GP_TOP_AN_STATUS1;
  1840. bp->mii_adv = MII_ADVERTISE + 0x10;
  1841. bp->mii_lpa = MII_LPA + 0x10;
  1842. bp->mii_up1 = MII_BNX2_OVER1G_UP1;
  1843. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR, MII_BNX2_BLK_ADDR_AER);
  1844. bnx2_write_phy(bp, MII_BNX2_AER_AER, MII_BNX2_AER_AER_AN_MMD);
  1845. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR, MII_BNX2_BLK_ADDR_COMBO_IEEEB0);
  1846. if (reset_phy)
  1847. bnx2_reset_phy(bp);
  1848. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR, MII_BNX2_BLK_ADDR_SERDES_DIG);
  1849. bnx2_read_phy(bp, MII_BNX2_SERDES_DIG_1000XCTL1, &val);
  1850. val &= ~MII_BNX2_SD_1000XCTL1_AUTODET;
  1851. val |= MII_BNX2_SD_1000XCTL1_FIBER;
  1852. bnx2_write_phy(bp, MII_BNX2_SERDES_DIG_1000XCTL1, val);
  1853. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR, MII_BNX2_BLK_ADDR_OVER1G);
  1854. bnx2_read_phy(bp, MII_BNX2_OVER1G_UP1, &val);
  1855. if (bp->phy_flags & BNX2_PHY_FLAG_2_5G_CAPABLE)
  1856. val |= BCM5708S_UP1_2G5;
  1857. else
  1858. val &= ~BCM5708S_UP1_2G5;
  1859. bnx2_write_phy(bp, MII_BNX2_OVER1G_UP1, val);
  1860. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR, MII_BNX2_BLK_ADDR_BAM_NXTPG);
  1861. bnx2_read_phy(bp, MII_BNX2_BAM_NXTPG_CTL, &val);
  1862. val |= MII_BNX2_NXTPG_CTL_T2 | MII_BNX2_NXTPG_CTL_BAM;
  1863. bnx2_write_phy(bp, MII_BNX2_BAM_NXTPG_CTL, val);
  1864. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR, MII_BNX2_BLK_ADDR_CL73_USERB0);
  1865. val = MII_BNX2_CL73_BAM_EN | MII_BNX2_CL73_BAM_STA_MGR_EN |
  1866. MII_BNX2_CL73_BAM_NP_AFT_BP_EN;
  1867. bnx2_write_phy(bp, MII_BNX2_CL73_BAM_CTL1, val);
  1868. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR, MII_BNX2_BLK_ADDR_COMBO_IEEEB0);
  1869. return 0;
  1870. }
  1871. static int
  1872. bnx2_init_5708s_phy(struct bnx2 *bp, int reset_phy)
  1873. {
  1874. u32 val;
  1875. if (reset_phy)
  1876. bnx2_reset_phy(bp);
  1877. bp->mii_up1 = BCM5708S_UP1;
  1878. bnx2_write_phy(bp, BCM5708S_BLK_ADDR, BCM5708S_BLK_ADDR_DIG3);
  1879. bnx2_write_phy(bp, BCM5708S_DIG_3_0, BCM5708S_DIG_3_0_USE_IEEE);
  1880. bnx2_write_phy(bp, BCM5708S_BLK_ADDR, BCM5708S_BLK_ADDR_DIG);
  1881. bnx2_read_phy(bp, BCM5708S_1000X_CTL1, &val);
  1882. val |= BCM5708S_1000X_CTL1_FIBER_MODE | BCM5708S_1000X_CTL1_AUTODET_EN;
  1883. bnx2_write_phy(bp, BCM5708S_1000X_CTL1, val);
  1884. bnx2_read_phy(bp, BCM5708S_1000X_CTL2, &val);
  1885. val |= BCM5708S_1000X_CTL2_PLLEL_DET_EN;
  1886. bnx2_write_phy(bp, BCM5708S_1000X_CTL2, val);
  1887. if (bp->phy_flags & BNX2_PHY_FLAG_2_5G_CAPABLE) {
  1888. bnx2_read_phy(bp, BCM5708S_UP1, &val);
  1889. val |= BCM5708S_UP1_2G5;
  1890. bnx2_write_phy(bp, BCM5708S_UP1, val);
  1891. }
  1892. if ((CHIP_ID(bp) == CHIP_ID_5708_A0) ||
  1893. (CHIP_ID(bp) == CHIP_ID_5708_B0) ||
  1894. (CHIP_ID(bp) == CHIP_ID_5708_B1)) {
  1895. /* increase tx signal amplitude */
  1896. bnx2_write_phy(bp, BCM5708S_BLK_ADDR,
  1897. BCM5708S_BLK_ADDR_TX_MISC);
  1898. bnx2_read_phy(bp, BCM5708S_TX_ACTL1, &val);
  1899. val &= ~BCM5708S_TX_ACTL1_DRIVER_VCM;
  1900. bnx2_write_phy(bp, BCM5708S_TX_ACTL1, val);
  1901. bnx2_write_phy(bp, BCM5708S_BLK_ADDR, BCM5708S_BLK_ADDR_DIG);
  1902. }
  1903. val = bnx2_shmem_rd(bp, BNX2_PORT_HW_CFG_CONFIG) &
  1904. BNX2_PORT_HW_CFG_CFG_TXCTL3_MASK;
  1905. if (val) {
  1906. u32 is_backplane;
  1907. is_backplane = bnx2_shmem_rd(bp, BNX2_SHARED_HW_CFG_CONFIG);
  1908. if (is_backplane & BNX2_SHARED_HW_CFG_PHY_BACKPLANE) {
  1909. bnx2_write_phy(bp, BCM5708S_BLK_ADDR,
  1910. BCM5708S_BLK_ADDR_TX_MISC);
  1911. bnx2_write_phy(bp, BCM5708S_TX_ACTL3, val);
  1912. bnx2_write_phy(bp, BCM5708S_BLK_ADDR,
  1913. BCM5708S_BLK_ADDR_DIG);
  1914. }
  1915. }
  1916. return 0;
  1917. }
  1918. static int
  1919. bnx2_init_5706s_phy(struct bnx2 *bp, int reset_phy)
  1920. {
  1921. if (reset_phy)
  1922. bnx2_reset_phy(bp);
  1923. bp->phy_flags &= ~BNX2_PHY_FLAG_PARALLEL_DETECT;
  1924. if (CHIP_NUM(bp) == CHIP_NUM_5706)
  1925. REG_WR(bp, BNX2_MISC_GP_HW_CTL0, 0x300);
  1926. if (bp->dev->mtu > 1500) {
  1927. u32 val;
  1928. /* Set extended packet length bit */
  1929. bnx2_write_phy(bp, 0x18, 0x7);
  1930. bnx2_read_phy(bp, 0x18, &val);
  1931. bnx2_write_phy(bp, 0x18, (val & 0xfff8) | 0x4000);
  1932. bnx2_write_phy(bp, 0x1c, 0x6c00);
  1933. bnx2_read_phy(bp, 0x1c, &val);
  1934. bnx2_write_phy(bp, 0x1c, (val & 0x3ff) | 0xec02);
  1935. }
  1936. else {
  1937. u32 val;
  1938. bnx2_write_phy(bp, 0x18, 0x7);
  1939. bnx2_read_phy(bp, 0x18, &val);
  1940. bnx2_write_phy(bp, 0x18, val & ~0x4007);
  1941. bnx2_write_phy(bp, 0x1c, 0x6c00);
  1942. bnx2_read_phy(bp, 0x1c, &val);
  1943. bnx2_write_phy(bp, 0x1c, (val & 0x3fd) | 0xec00);
  1944. }
  1945. return 0;
  1946. }
  1947. static int
  1948. bnx2_init_copper_phy(struct bnx2 *bp, int reset_phy)
  1949. {
  1950. u32 val;
  1951. if (reset_phy)
  1952. bnx2_reset_phy(bp);
  1953. if (bp->phy_flags & BNX2_PHY_FLAG_CRC_FIX) {
  1954. bnx2_write_phy(bp, 0x18, 0x0c00);
  1955. bnx2_write_phy(bp, 0x17, 0x000a);
  1956. bnx2_write_phy(bp, 0x15, 0x310b);
  1957. bnx2_write_phy(bp, 0x17, 0x201f);
  1958. bnx2_write_phy(bp, 0x15, 0x9506);
  1959. bnx2_write_phy(bp, 0x17, 0x401f);
  1960. bnx2_write_phy(bp, 0x15, 0x14e2);
  1961. bnx2_write_phy(bp, 0x18, 0x0400);
  1962. }
  1963. if (bp->phy_flags & BNX2_PHY_FLAG_DIS_EARLY_DAC) {
  1964. bnx2_write_phy(bp, MII_BNX2_DSP_ADDRESS,
  1965. MII_BNX2_DSP_EXPAND_REG | 0x8);
  1966. bnx2_read_phy(bp, MII_BNX2_DSP_RW_PORT, &val);
  1967. val &= ~(1 << 8);
  1968. bnx2_write_phy(bp, MII_BNX2_DSP_RW_PORT, val);
  1969. }
  1970. if (bp->dev->mtu > 1500) {
  1971. /* Set extended packet length bit */
  1972. bnx2_write_phy(bp, 0x18, 0x7);
  1973. bnx2_read_phy(bp, 0x18, &val);
  1974. bnx2_write_phy(bp, 0x18, val | 0x4000);
  1975. bnx2_read_phy(bp, 0x10, &val);
  1976. bnx2_write_phy(bp, 0x10, val | 0x1);
  1977. }
  1978. else {
  1979. bnx2_write_phy(bp, 0x18, 0x7);
  1980. bnx2_read_phy(bp, 0x18, &val);
  1981. bnx2_write_phy(bp, 0x18, val & ~0x4007);
  1982. bnx2_read_phy(bp, 0x10, &val);
  1983. bnx2_write_phy(bp, 0x10, val & ~0x1);
  1984. }
  1985. /* ethernet@wirespeed */
  1986. bnx2_write_phy(bp, 0x18, 0x7007);
  1987. bnx2_read_phy(bp, 0x18, &val);
  1988. bnx2_write_phy(bp, 0x18, val | (1 << 15) | (1 << 4));
  1989. return 0;
  1990. }
  1991. static int
  1992. bnx2_init_phy(struct bnx2 *bp, int reset_phy)
  1993. __releases(&bp->phy_lock)
  1994. __acquires(&bp->phy_lock)
  1995. {
  1996. u32 val;
  1997. int rc = 0;
  1998. bp->phy_flags &= ~BNX2_PHY_FLAG_INT_MODE_MASK;
  1999. bp->phy_flags |= BNX2_PHY_FLAG_INT_MODE_LINK_READY;
  2000. bp->mii_bmcr = MII_BMCR;
  2001. bp->mii_bmsr = MII_BMSR;
  2002. bp->mii_bmsr1 = MII_BMSR;
  2003. bp->mii_adv = MII_ADVERTISE;
  2004. bp->mii_lpa = MII_LPA;
  2005. REG_WR(bp, BNX2_EMAC_ATTENTION_ENA, BNX2_EMAC_ATTENTION_ENA_LINK);
  2006. if (bp->phy_flags & BNX2_PHY_FLAG_REMOTE_PHY_CAP)
  2007. goto setup_phy;
  2008. bnx2_read_phy(bp, MII_PHYSID1, &val);
  2009. bp->phy_id = val << 16;
  2010. bnx2_read_phy(bp, MII_PHYSID2, &val);
  2011. bp->phy_id |= val & 0xffff;
  2012. if (bp->phy_flags & BNX2_PHY_FLAG_SERDES) {
  2013. if (CHIP_NUM(bp) == CHIP_NUM_5706)
  2014. rc = bnx2_init_5706s_phy(bp, reset_phy);
  2015. else if (CHIP_NUM(bp) == CHIP_NUM_5708)
  2016. rc = bnx2_init_5708s_phy(bp, reset_phy);
  2017. else if (CHIP_NUM(bp) == CHIP_NUM_5709)
  2018. rc = bnx2_init_5709s_phy(bp, reset_phy);
  2019. }
  2020. else {
  2021. rc = bnx2_init_copper_phy(bp, reset_phy);
  2022. }
  2023. setup_phy:
  2024. if (!rc)
  2025. rc = bnx2_setup_phy(bp, bp->phy_port);
  2026. return rc;
  2027. }
  2028. static int
  2029. bnx2_set_mac_loopback(struct bnx2 *bp)
  2030. {
  2031. u32 mac_mode;
  2032. mac_mode = REG_RD(bp, BNX2_EMAC_MODE);
  2033. mac_mode &= ~BNX2_EMAC_MODE_PORT;
  2034. mac_mode |= BNX2_EMAC_MODE_MAC_LOOP | BNX2_EMAC_MODE_FORCE_LINK;
  2035. REG_WR(bp, BNX2_EMAC_MODE, mac_mode);
  2036. bp->link_up = 1;
  2037. return 0;
  2038. }
  2039. static int bnx2_test_link(struct bnx2 *);
  2040. static int
  2041. bnx2_set_phy_loopback(struct bnx2 *bp)
  2042. {
  2043. u32 mac_mode;
  2044. int rc, i;
  2045. spin_lock_bh(&bp->phy_lock);
  2046. rc = bnx2_write_phy(bp, bp->mii_bmcr, BMCR_LOOPBACK | BMCR_FULLDPLX |
  2047. BMCR_SPEED1000);
  2048. spin_unlock_bh(&bp->phy_lock);
  2049. if (rc)
  2050. return rc;
  2051. for (i = 0; i < 10; i++) {
  2052. if (bnx2_test_link(bp) == 0)
  2053. break;
  2054. msleep(100);
  2055. }
  2056. mac_mode = REG_RD(bp, BNX2_EMAC_MODE);
  2057. mac_mode &= ~(BNX2_EMAC_MODE_PORT | BNX2_EMAC_MODE_HALF_DUPLEX |
  2058. BNX2_EMAC_MODE_MAC_LOOP | BNX2_EMAC_MODE_FORCE_LINK |
  2059. BNX2_EMAC_MODE_25G_MODE);
  2060. mac_mode |= BNX2_EMAC_MODE_PORT_GMII;
  2061. REG_WR(bp, BNX2_EMAC_MODE, mac_mode);
  2062. bp->link_up = 1;
  2063. return 0;
  2064. }
  2065. static void
  2066. bnx2_dump_mcp_state(struct bnx2 *bp)
  2067. {
  2068. struct net_device *dev = bp->dev;
  2069. u32 mcp_p0, mcp_p1;
  2070. netdev_err(dev, "<--- start MCP states dump --->\n");
  2071. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  2072. mcp_p0 = BNX2_MCP_STATE_P0;
  2073. mcp_p1 = BNX2_MCP_STATE_P1;
  2074. } else {
  2075. mcp_p0 = BNX2_MCP_STATE_P0_5708;
  2076. mcp_p1 = BNX2_MCP_STATE_P1_5708;
  2077. }
  2078. netdev_err(dev, "DEBUG: MCP_STATE_P0[%08x] MCP_STATE_P1[%08x]\n",
  2079. bnx2_reg_rd_ind(bp, mcp_p0), bnx2_reg_rd_ind(bp, mcp_p1));
  2080. netdev_err(dev, "DEBUG: MCP mode[%08x] state[%08x] evt_mask[%08x]\n",
  2081. bnx2_reg_rd_ind(bp, BNX2_MCP_CPU_MODE),
  2082. bnx2_reg_rd_ind(bp, BNX2_MCP_CPU_STATE),
  2083. bnx2_reg_rd_ind(bp, BNX2_MCP_CPU_EVENT_MASK));
  2084. netdev_err(dev, "DEBUG: pc[%08x] pc[%08x] instr[%08x]\n",
  2085. bnx2_reg_rd_ind(bp, BNX2_MCP_CPU_PROGRAM_COUNTER),
  2086. bnx2_reg_rd_ind(bp, BNX2_MCP_CPU_PROGRAM_COUNTER),
  2087. bnx2_reg_rd_ind(bp, BNX2_MCP_CPU_INSTRUCTION));
  2088. netdev_err(dev, "DEBUG: shmem states:\n");
  2089. netdev_err(dev, "DEBUG: drv_mb[%08x] fw_mb[%08x] link_status[%08x]",
  2090. bnx2_shmem_rd(bp, BNX2_DRV_MB),
  2091. bnx2_shmem_rd(bp, BNX2_FW_MB),
  2092. bnx2_shmem_rd(bp, BNX2_LINK_STATUS));
  2093. pr_cont(" drv_pulse_mb[%08x]\n", bnx2_shmem_rd(bp, BNX2_DRV_PULSE_MB));
  2094. netdev_err(dev, "DEBUG: dev_info_signature[%08x] reset_type[%08x]",
  2095. bnx2_shmem_rd(bp, BNX2_DEV_INFO_SIGNATURE),
  2096. bnx2_shmem_rd(bp, BNX2_BC_STATE_RESET_TYPE));
  2097. pr_cont(" condition[%08x]\n",
  2098. bnx2_shmem_rd(bp, BNX2_BC_STATE_CONDITION));
  2099. DP_SHMEM_LINE(bp, 0x3cc);
  2100. DP_SHMEM_LINE(bp, 0x3dc);
  2101. DP_SHMEM_LINE(bp, 0x3ec);
  2102. netdev_err(dev, "DEBUG: 0x3fc[%08x]\n", bnx2_shmem_rd(bp, 0x3fc));
  2103. netdev_err(dev, "<--- end MCP states dump --->\n");
  2104. }
  2105. static int
  2106. bnx2_fw_sync(struct bnx2 *bp, u32 msg_data, int ack, int silent)
  2107. {
  2108. int i;
  2109. u32 val;
  2110. bp->fw_wr_seq++;
  2111. msg_data |= bp->fw_wr_seq;
  2112. bnx2_shmem_wr(bp, BNX2_DRV_MB, msg_data);
  2113. if (!ack)
  2114. return 0;
  2115. /* wait for an acknowledgement. */
  2116. for (i = 0; i < (BNX2_FW_ACK_TIME_OUT_MS / 10); i++) {
  2117. msleep(10);
  2118. val = bnx2_shmem_rd(bp, BNX2_FW_MB);
  2119. if ((val & BNX2_FW_MSG_ACK) == (msg_data & BNX2_DRV_MSG_SEQ))
  2120. break;
  2121. }
  2122. if ((msg_data & BNX2_DRV_MSG_DATA) == BNX2_DRV_MSG_DATA_WAIT0)
  2123. return 0;
  2124. /* If we timed out, inform the firmware that this is the case. */
  2125. if ((val & BNX2_FW_MSG_ACK) != (msg_data & BNX2_DRV_MSG_SEQ)) {
  2126. msg_data &= ~BNX2_DRV_MSG_CODE;
  2127. msg_data |= BNX2_DRV_MSG_CODE_FW_TIMEOUT;
  2128. bnx2_shmem_wr(bp, BNX2_DRV_MB, msg_data);
  2129. if (!silent) {
  2130. pr_err("fw sync timeout, reset code = %x\n", msg_data);
  2131. bnx2_dump_mcp_state(bp);
  2132. }
  2133. return -EBUSY;
  2134. }
  2135. if ((val & BNX2_FW_MSG_STATUS_MASK) != BNX2_FW_MSG_STATUS_OK)
  2136. return -EIO;
  2137. return 0;
  2138. }
  2139. static int
  2140. bnx2_init_5709_context(struct bnx2 *bp)
  2141. {
  2142. int i, ret = 0;
  2143. u32 val;
  2144. val = BNX2_CTX_COMMAND_ENABLED | BNX2_CTX_COMMAND_MEM_INIT | (1 << 12);
  2145. val |= (BCM_PAGE_BITS - 8) << 16;
  2146. REG_WR(bp, BNX2_CTX_COMMAND, val);
  2147. for (i = 0; i < 10; i++) {
  2148. val = REG_RD(bp, BNX2_CTX_COMMAND);
  2149. if (!(val & BNX2_CTX_COMMAND_MEM_INIT))
  2150. break;
  2151. udelay(2);
  2152. }
  2153. if (val & BNX2_CTX_COMMAND_MEM_INIT)
  2154. return -EBUSY;
  2155. for (i = 0; i < bp->ctx_pages; i++) {
  2156. int j;
  2157. if (bp->ctx_blk[i])
  2158. memset(bp->ctx_blk[i], 0, BCM_PAGE_SIZE);
  2159. else
  2160. return -ENOMEM;
  2161. REG_WR(bp, BNX2_CTX_HOST_PAGE_TBL_DATA0,
  2162. (bp->ctx_blk_mapping[i] & 0xffffffff) |
  2163. BNX2_CTX_HOST_PAGE_TBL_DATA0_VALID);
  2164. REG_WR(bp, BNX2_CTX_HOST_PAGE_TBL_DATA1,
  2165. (u64) bp->ctx_blk_mapping[i] >> 32);
  2166. REG_WR(bp, BNX2_CTX_HOST_PAGE_TBL_CTRL, i |
  2167. BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ);
  2168. for (j = 0; j < 10; j++) {
  2169. val = REG_RD(bp, BNX2_CTX_HOST_PAGE_TBL_CTRL);
  2170. if (!(val & BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ))
  2171. break;
  2172. udelay(5);
  2173. }
  2174. if (val & BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ) {
  2175. ret = -EBUSY;
  2176. break;
  2177. }
  2178. }
  2179. return ret;
  2180. }
  2181. static void
  2182. bnx2_init_context(struct bnx2 *bp)
  2183. {
  2184. u32 vcid;
  2185. vcid = 96;
  2186. while (vcid) {
  2187. u32 vcid_addr, pcid_addr, offset;
  2188. int i;
  2189. vcid--;
  2190. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  2191. u32 new_vcid;
  2192. vcid_addr = GET_PCID_ADDR(vcid);
  2193. if (vcid & 0x8) {
  2194. new_vcid = 0x60 + (vcid & 0xf0) + (vcid & 0x7);
  2195. }
  2196. else {
  2197. new_vcid = vcid;
  2198. }
  2199. pcid_addr = GET_PCID_ADDR(new_vcid);
  2200. }
  2201. else {
  2202. vcid_addr = GET_CID_ADDR(vcid);
  2203. pcid_addr = vcid_addr;
  2204. }
  2205. for (i = 0; i < (CTX_SIZE / PHY_CTX_SIZE); i++) {
  2206. vcid_addr += (i << PHY_CTX_SHIFT);
  2207. pcid_addr += (i << PHY_CTX_SHIFT);
  2208. REG_WR(bp, BNX2_CTX_VIRT_ADDR, vcid_addr);
  2209. REG_WR(bp, BNX2_CTX_PAGE_TBL, pcid_addr);
  2210. /* Zero out the context. */
  2211. for (offset = 0; offset < PHY_CTX_SIZE; offset += 4)
  2212. bnx2_ctx_wr(bp, vcid_addr, offset, 0);
  2213. }
  2214. }
  2215. }
  2216. static int
  2217. bnx2_alloc_bad_rbuf(struct bnx2 *bp)
  2218. {
  2219. u16 *good_mbuf;
  2220. u32 good_mbuf_cnt;
  2221. u32 val;
  2222. good_mbuf = kmalloc(512 * sizeof(u16), GFP_KERNEL);
  2223. if (good_mbuf == NULL) {
  2224. pr_err("Failed to allocate memory in %s\n", __func__);
  2225. return -ENOMEM;
  2226. }
  2227. REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS,
  2228. BNX2_MISC_ENABLE_SET_BITS_RX_MBUF_ENABLE);
  2229. good_mbuf_cnt = 0;
  2230. /* Allocate a bunch of mbufs and save the good ones in an array. */
  2231. val = bnx2_reg_rd_ind(bp, BNX2_RBUF_STATUS1);
  2232. while (val & BNX2_RBUF_STATUS1_FREE_COUNT) {
  2233. bnx2_reg_wr_ind(bp, BNX2_RBUF_COMMAND,
  2234. BNX2_RBUF_COMMAND_ALLOC_REQ);
  2235. val = bnx2_reg_rd_ind(bp, BNX2_RBUF_FW_BUF_ALLOC);
  2236. val &= BNX2_RBUF_FW_BUF_ALLOC_VALUE;
  2237. /* The addresses with Bit 9 set are bad memory blocks. */
  2238. if (!(val & (1 << 9))) {
  2239. good_mbuf[good_mbuf_cnt] = (u16) val;
  2240. good_mbuf_cnt++;
  2241. }
  2242. val = bnx2_reg_rd_ind(bp, BNX2_RBUF_STATUS1);
  2243. }
  2244. /* Free the good ones back to the mbuf pool thus discarding
  2245. * all the bad ones. */
  2246. while (good_mbuf_cnt) {
  2247. good_mbuf_cnt--;
  2248. val = good_mbuf[good_mbuf_cnt];
  2249. val = (val << 9) | val | 1;
  2250. bnx2_reg_wr_ind(bp, BNX2_RBUF_FW_BUF_FREE, val);
  2251. }
  2252. kfree(good_mbuf);
  2253. return 0;
  2254. }
  2255. static void
  2256. bnx2_set_mac_addr(struct bnx2 *bp, u8 *mac_addr, u32 pos)
  2257. {
  2258. u32 val;
  2259. val = (mac_addr[0] << 8) | mac_addr[1];
  2260. REG_WR(bp, BNX2_EMAC_MAC_MATCH0 + (pos * 8), val);
  2261. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  2262. (mac_addr[4] << 8) | mac_addr[5];
  2263. REG_WR(bp, BNX2_EMAC_MAC_MATCH1 + (pos * 8), val);
  2264. }
  2265. static inline int
  2266. bnx2_alloc_rx_page(struct bnx2 *bp, struct bnx2_rx_ring_info *rxr, u16 index, gfp_t gfp)
  2267. {
  2268. dma_addr_t mapping;
  2269. struct sw_pg *rx_pg = &rxr->rx_pg_ring[index];
  2270. struct rx_bd *rxbd =
  2271. &rxr->rx_pg_desc_ring[RX_RING(index)][RX_IDX(index)];
  2272. struct page *page = alloc_page(gfp);
  2273. if (!page)
  2274. return -ENOMEM;
  2275. mapping = dma_map_page(&bp->pdev->dev, page, 0, PAGE_SIZE,
  2276. PCI_DMA_FROMDEVICE);
  2277. if (dma_mapping_error(&bp->pdev->dev, mapping)) {
  2278. __free_page(page);
  2279. return -EIO;
  2280. }
  2281. rx_pg->page = page;
  2282. dma_unmap_addr_set(rx_pg, mapping, mapping);
  2283. rxbd->rx_bd_haddr_hi = (u64) mapping >> 32;
  2284. rxbd->rx_bd_haddr_lo = (u64) mapping & 0xffffffff;
  2285. return 0;
  2286. }
  2287. static void
  2288. bnx2_free_rx_page(struct bnx2 *bp, struct bnx2_rx_ring_info *rxr, u16 index)
  2289. {
  2290. struct sw_pg *rx_pg = &rxr->rx_pg_ring[index];
  2291. struct page *page = rx_pg->page;
  2292. if (!page)
  2293. return;
  2294. dma_unmap_page(&bp->pdev->dev, dma_unmap_addr(rx_pg, mapping),
  2295. PAGE_SIZE, PCI_DMA_FROMDEVICE);
  2296. __free_page(page);
  2297. rx_pg->page = NULL;
  2298. }
  2299. static inline int
  2300. bnx2_alloc_rx_skb(struct bnx2 *bp, struct bnx2_rx_ring_info *rxr, u16 index, gfp_t gfp)
  2301. {
  2302. struct sk_buff *skb;
  2303. struct sw_bd *rx_buf = &rxr->rx_buf_ring[index];
  2304. dma_addr_t mapping;
  2305. struct rx_bd *rxbd = &rxr->rx_desc_ring[RX_RING(index)][RX_IDX(index)];
  2306. unsigned long align;
  2307. skb = __netdev_alloc_skb(bp->dev, bp->rx_buf_size, gfp);
  2308. if (skb == NULL) {
  2309. return -ENOMEM;
  2310. }
  2311. if (unlikely((align = (unsigned long) skb->data & (BNX2_RX_ALIGN - 1))))
  2312. skb_reserve(skb, BNX2_RX_ALIGN - align);
  2313. mapping = dma_map_single(&bp->pdev->dev, skb->data, bp->rx_buf_use_size,
  2314. PCI_DMA_FROMDEVICE);
  2315. if (dma_mapping_error(&bp->pdev->dev, mapping)) {
  2316. dev_kfree_skb(skb);
  2317. return -EIO;
  2318. }
  2319. rx_buf->skb = skb;
  2320. rx_buf->desc = (struct l2_fhdr *) skb->data;
  2321. dma_unmap_addr_set(rx_buf, mapping, mapping);
  2322. rxbd->rx_bd_haddr_hi = (u64) mapping >> 32;
  2323. rxbd->rx_bd_haddr_lo = (u64) mapping & 0xffffffff;
  2324. rxr->rx_prod_bseq += bp->rx_buf_use_size;
  2325. return 0;
  2326. }
  2327. static int
  2328. bnx2_phy_event_is_set(struct bnx2 *bp, struct bnx2_napi *bnapi, u32 event)
  2329. {
  2330. struct status_block *sblk = bnapi->status_blk.msi;
  2331. u32 new_link_state, old_link_state;
  2332. int is_set = 1;
  2333. new_link_state = sblk->status_attn_bits & event;
  2334. old_link_state = sblk->status_attn_bits_ack & event;
  2335. if (new_link_state != old_link_state) {
  2336. if (new_link_state)
  2337. REG_WR(bp, BNX2_PCICFG_STATUS_BIT_SET_CMD, event);
  2338. else
  2339. REG_WR(bp, BNX2_PCICFG_STATUS_BIT_CLEAR_CMD, event);
  2340. } else
  2341. is_set = 0;
  2342. return is_set;
  2343. }
  2344. static void
  2345. bnx2_phy_int(struct bnx2 *bp, struct bnx2_napi *bnapi)
  2346. {
  2347. spin_lock(&bp->phy_lock);
  2348. if (bnx2_phy_event_is_set(bp, bnapi, STATUS_ATTN_BITS_LINK_STATE))
  2349. bnx2_set_link(bp);
  2350. if (bnx2_phy_event_is_set(bp, bnapi, STATUS_ATTN_BITS_TIMER_ABORT))
  2351. bnx2_set_remote_link(bp);
  2352. spin_unlock(&bp->phy_lock);
  2353. }
  2354. static inline u16
  2355. bnx2_get_hw_tx_cons(struct bnx2_napi *bnapi)
  2356. {
  2357. u16 cons;
  2358. /* Tell compiler that status block fields can change. */
  2359. barrier();
  2360. cons = *bnapi->hw_tx_cons_ptr;
  2361. barrier();
  2362. if (unlikely((cons & MAX_TX_DESC_CNT) == MAX_TX_DESC_CNT))
  2363. cons++;
  2364. return cons;
  2365. }
  2366. static int
  2367. bnx2_tx_int(struct bnx2 *bp, struct bnx2_napi *bnapi, int budget)
  2368. {
  2369. struct bnx2_tx_ring_info *txr = &bnapi->tx_ring;
  2370. u16 hw_cons, sw_cons, sw_ring_cons;
  2371. int tx_pkt = 0, index;
  2372. struct netdev_queue *txq;
  2373. index = (bnapi - bp->bnx2_napi);
  2374. txq = netdev_get_tx_queue(bp->dev, index);
  2375. hw_cons = bnx2_get_hw_tx_cons(bnapi);
  2376. sw_cons = txr->tx_cons;
  2377. while (sw_cons != hw_cons) {
  2378. struct sw_tx_bd *tx_buf;
  2379. struct sk_buff *skb;
  2380. int i, last;
  2381. sw_ring_cons = TX_RING_IDX(sw_cons);
  2382. tx_buf = &txr->tx_buf_ring[sw_ring_cons];
  2383. skb = tx_buf->skb;
  2384. /* prefetch skb_end_pointer() to speedup skb_shinfo(skb) */
  2385. prefetch(&skb->end);
  2386. /* partial BD completions possible with TSO packets */
  2387. if (tx_buf->is_gso) {
  2388. u16 last_idx, last_ring_idx;
  2389. last_idx = sw_cons + tx_buf->nr_frags + 1;
  2390. last_ring_idx = sw_ring_cons + tx_buf->nr_frags + 1;
  2391. if (unlikely(last_ring_idx >= MAX_TX_DESC_CNT)) {
  2392. last_idx++;
  2393. }
  2394. if (((s16) ((s16) last_idx - (s16) hw_cons)) > 0) {
  2395. break;
  2396. }
  2397. }
  2398. dma_unmap_single(&bp->pdev->dev, dma_unmap_addr(tx_buf, mapping),
  2399. skb_headlen(skb), PCI_DMA_TODEVICE);
  2400. tx_buf->skb = NULL;
  2401. last = tx_buf->nr_frags;
  2402. for (i = 0; i < last; i++) {
  2403. sw_cons = NEXT_TX_BD(sw_cons);
  2404. dma_unmap_page(&bp->pdev->dev,
  2405. dma_unmap_addr(
  2406. &txr->tx_buf_ring[TX_RING_IDX(sw_cons)],
  2407. mapping),
  2408. skb_shinfo(skb)->frags[i].size,
  2409. PCI_DMA_TODEVICE);
  2410. }
  2411. sw_cons = NEXT_TX_BD(sw_cons);
  2412. dev_kfree_skb(skb);
  2413. tx_pkt++;
  2414. if (tx_pkt == budget)
  2415. break;
  2416. if (hw_cons == sw_cons)
  2417. hw_cons = bnx2_get_hw_tx_cons(bnapi);
  2418. }
  2419. txr->hw_tx_cons = hw_cons;
  2420. txr->tx_cons = sw_cons;
  2421. /* Need to make the tx_cons update visible to bnx2_start_xmit()
  2422. * before checking for netif_tx_queue_stopped(). Without the
  2423. * memory barrier, there is a small possibility that bnx2_start_xmit()
  2424. * will miss it and cause the queue to be stopped forever.
  2425. */
  2426. smp_mb();
  2427. if (unlikely(netif_tx_queue_stopped(txq)) &&
  2428. (bnx2_tx_avail(bp, txr) > bp->tx_wake_thresh)) {
  2429. __netif_tx_lock(txq, smp_processor_id());
  2430. if ((netif_tx_queue_stopped(txq)) &&
  2431. (bnx2_tx_avail(bp, txr) > bp->tx_wake_thresh))
  2432. netif_tx_wake_queue(txq);
  2433. __netif_tx_unlock(txq);
  2434. }
  2435. return tx_pkt;
  2436. }
  2437. static void
  2438. bnx2_reuse_rx_skb_pages(struct bnx2 *bp, struct bnx2_rx_ring_info *rxr,
  2439. struct sk_buff *skb, int count)
  2440. {
  2441. struct sw_pg *cons_rx_pg, *prod_rx_pg;
  2442. struct rx_bd *cons_bd, *prod_bd;
  2443. int i;
  2444. u16 hw_prod, prod;
  2445. u16 cons = rxr->rx_pg_cons;
  2446. cons_rx_pg = &rxr->rx_pg_ring[cons];
  2447. /* The caller was unable to allocate a new page to replace the
  2448. * last one in the frags array, so we need to recycle that page
  2449. * and then free the skb.
  2450. */
  2451. if (skb) {
  2452. struct page *page;
  2453. struct skb_shared_info *shinfo;
  2454. shinfo = skb_shinfo(skb);
  2455. shinfo->nr_frags--;
  2456. page = shinfo->frags[shinfo->nr_frags].page;
  2457. shinfo->frags[shinfo->nr_frags].page = NULL;
  2458. cons_rx_pg->page = page;
  2459. dev_kfree_skb(skb);
  2460. }
  2461. hw_prod = rxr->rx_pg_prod;
  2462. for (i = 0; i < count; i++) {
  2463. prod = RX_PG_RING_IDX(hw_prod);
  2464. prod_rx_pg = &rxr->rx_pg_ring[prod];
  2465. cons_rx_pg = &rxr->rx_pg_ring[cons];
  2466. cons_bd = &rxr->rx_pg_desc_ring[RX_RING(cons)][RX_IDX(cons)];
  2467. prod_bd = &rxr->rx_pg_desc_ring[RX_RING(prod)][RX_IDX(prod)];
  2468. if (prod != cons) {
  2469. prod_rx_pg->page = cons_rx_pg->page;
  2470. cons_rx_pg->page = NULL;
  2471. dma_unmap_addr_set(prod_rx_pg, mapping,
  2472. dma_unmap_addr(cons_rx_pg, mapping));
  2473. prod_bd->rx_bd_haddr_hi = cons_bd->rx_bd_haddr_hi;
  2474. prod_bd->rx_bd_haddr_lo = cons_bd->rx_bd_haddr_lo;
  2475. }
  2476. cons = RX_PG_RING_IDX(NEXT_RX_BD(cons));
  2477. hw_prod = NEXT_RX_BD(hw_prod);
  2478. }
  2479. rxr->rx_pg_prod = hw_prod;
  2480. rxr->rx_pg_cons = cons;
  2481. }
  2482. static inline void
  2483. bnx2_reuse_rx_skb(struct bnx2 *bp, struct bnx2_rx_ring_info *rxr,
  2484. struct sk_buff *skb, u16 cons, u16 prod)
  2485. {
  2486. struct sw_bd *cons_rx_buf, *prod_rx_buf;
  2487. struct rx_bd *cons_bd, *prod_bd;
  2488. cons_rx_buf = &rxr->rx_buf_ring[cons];
  2489. prod_rx_buf = &rxr->rx_buf_ring[prod];
  2490. dma_sync_single_for_device(&bp->pdev->dev,
  2491. dma_unmap_addr(cons_rx_buf, mapping),
  2492. BNX2_RX_OFFSET + BNX2_RX_COPY_THRESH, PCI_DMA_FROMDEVICE);
  2493. rxr->rx_prod_bseq += bp->rx_buf_use_size;
  2494. prod_rx_buf->skb = skb;
  2495. prod_rx_buf->desc = (struct l2_fhdr *) skb->data;
  2496. if (cons == prod)
  2497. return;
  2498. dma_unmap_addr_set(prod_rx_buf, mapping,
  2499. dma_unmap_addr(cons_rx_buf, mapping));
  2500. cons_bd = &rxr->rx_desc_ring[RX_RING(cons)][RX_IDX(cons)];
  2501. prod_bd = &rxr->rx_desc_ring[RX_RING(prod)][RX_IDX(prod)];
  2502. prod_bd->rx_bd_haddr_hi = cons_bd->rx_bd_haddr_hi;
  2503. prod_bd->rx_bd_haddr_lo = cons_bd->rx_bd_haddr_lo;
  2504. }
  2505. static int
  2506. bnx2_rx_skb(struct bnx2 *bp, struct bnx2_rx_ring_info *rxr, struct sk_buff *skb,
  2507. unsigned int len, unsigned int hdr_len, dma_addr_t dma_addr,
  2508. u32 ring_idx)
  2509. {
  2510. int err;
  2511. u16 prod = ring_idx & 0xffff;
  2512. err = bnx2_alloc_rx_skb(bp, rxr, prod, GFP_ATOMIC);
  2513. if (unlikely(err)) {
  2514. bnx2_reuse_rx_skb(bp, rxr, skb, (u16) (ring_idx >> 16), prod);
  2515. if (hdr_len) {
  2516. unsigned int raw_len = len + 4;
  2517. int pages = PAGE_ALIGN(raw_len - hdr_len) >> PAGE_SHIFT;
  2518. bnx2_reuse_rx_skb_pages(bp, rxr, NULL, pages);
  2519. }
  2520. return err;
  2521. }
  2522. skb_reserve(skb, BNX2_RX_OFFSET);
  2523. dma_unmap_single(&bp->pdev->dev, dma_addr, bp->rx_buf_use_size,
  2524. PCI_DMA_FROMDEVICE);
  2525. if (hdr_len == 0) {
  2526. skb_put(skb, len);
  2527. return 0;
  2528. } else {
  2529. unsigned int i, frag_len, frag_size, pages;
  2530. struct sw_pg *rx_pg;
  2531. u16 pg_cons = rxr->rx_pg_cons;
  2532. u16 pg_prod = rxr->rx_pg_prod;
  2533. frag_size = len + 4 - hdr_len;
  2534. pages = PAGE_ALIGN(frag_size) >> PAGE_SHIFT;
  2535. skb_put(skb, hdr_len);
  2536. for (i = 0; i < pages; i++) {
  2537. dma_addr_t mapping_old;
  2538. frag_len = min(frag_size, (unsigned int) PAGE_SIZE);
  2539. if (unlikely(frag_len <= 4)) {
  2540. unsigned int tail = 4 - frag_len;
  2541. rxr->rx_pg_cons = pg_cons;
  2542. rxr->rx_pg_prod = pg_prod;
  2543. bnx2_reuse_rx_skb_pages(bp, rxr, NULL,
  2544. pages - i);
  2545. skb->len -= tail;
  2546. if (i == 0) {
  2547. skb->tail -= tail;
  2548. } else {
  2549. skb_frag_t *frag =
  2550. &skb_shinfo(skb)->frags[i - 1];
  2551. frag->size -= tail;
  2552. skb->data_len -= tail;
  2553. skb->truesize -= tail;
  2554. }
  2555. return 0;
  2556. }
  2557. rx_pg = &rxr->rx_pg_ring[pg_cons];
  2558. /* Don't unmap yet. If we're unable to allocate a new
  2559. * page, we need to recycle the page and the DMA addr.
  2560. */
  2561. mapping_old = dma_unmap_addr(rx_pg, mapping);
  2562. if (i == pages - 1)
  2563. frag_len -= 4;
  2564. skb_fill_page_desc(skb, i, rx_pg->page, 0, frag_len);
  2565. rx_pg->page = NULL;
  2566. err = bnx2_alloc_rx_page(bp, rxr,
  2567. RX_PG_RING_IDX(pg_prod),
  2568. GFP_ATOMIC);
  2569. if (unlikely(err)) {
  2570. rxr->rx_pg_cons = pg_cons;
  2571. rxr->rx_pg_prod = pg_prod;
  2572. bnx2_reuse_rx_skb_pages(bp, rxr, skb,
  2573. pages - i);
  2574. return err;
  2575. }
  2576. dma_unmap_page(&bp->pdev->dev, mapping_old,
  2577. PAGE_SIZE, PCI_DMA_FROMDEVICE);
  2578. frag_size -= frag_len;
  2579. skb->data_len += frag_len;
  2580. skb->truesize += frag_len;
  2581. skb->len += frag_len;
  2582. pg_prod = NEXT_RX_BD(pg_prod);
  2583. pg_cons = RX_PG_RING_IDX(NEXT_RX_BD(pg_cons));
  2584. }
  2585. rxr->rx_pg_prod = pg_prod;
  2586. rxr->rx_pg_cons = pg_cons;
  2587. }
  2588. return 0;
  2589. }
  2590. static inline u16
  2591. bnx2_get_hw_rx_cons(struct bnx2_napi *bnapi)
  2592. {
  2593. u16 cons;
  2594. /* Tell compiler that status block fields can change. */
  2595. barrier();
  2596. cons = *bnapi->hw_rx_cons_ptr;
  2597. barrier();
  2598. if (unlikely((cons & MAX_RX_DESC_CNT) == MAX_RX_DESC_CNT))
  2599. cons++;
  2600. return cons;
  2601. }
  2602. static int
  2603. bnx2_rx_int(struct bnx2 *bp, struct bnx2_napi *bnapi, int budget)
  2604. {
  2605. struct bnx2_rx_ring_info *rxr = &bnapi->rx_ring;
  2606. u16 hw_cons, sw_cons, sw_ring_cons, sw_prod, sw_ring_prod;
  2607. struct l2_fhdr *rx_hdr;
  2608. int rx_pkt = 0, pg_ring_used = 0;
  2609. hw_cons = bnx2_get_hw_rx_cons(bnapi);
  2610. sw_cons = rxr->rx_cons;
  2611. sw_prod = rxr->rx_prod;
  2612. /* Memory barrier necessary as speculative reads of the rx
  2613. * buffer can be ahead of the index in the status block
  2614. */
  2615. rmb();
  2616. while (sw_cons != hw_cons) {
  2617. unsigned int len, hdr_len;
  2618. u32 status;
  2619. struct sw_bd *rx_buf, *next_rx_buf;
  2620. struct sk_buff *skb;
  2621. dma_addr_t dma_addr;
  2622. sw_ring_cons = RX_RING_IDX(sw_cons);
  2623. sw_ring_prod = RX_RING_IDX(sw_prod);
  2624. rx_buf = &rxr->rx_buf_ring[sw_ring_cons];
  2625. skb = rx_buf->skb;
  2626. prefetchw(skb);
  2627. next_rx_buf =
  2628. &rxr->rx_buf_ring[RX_RING_IDX(NEXT_RX_BD(sw_cons))];
  2629. prefetch(next_rx_buf->desc);
  2630. rx_buf->skb = NULL;
  2631. dma_addr = dma_unmap_addr(rx_buf, mapping);
  2632. dma_sync_single_for_cpu(&bp->pdev->dev, dma_addr,
  2633. BNX2_RX_OFFSET + BNX2_RX_COPY_THRESH,
  2634. PCI_DMA_FROMDEVICE);
  2635. rx_hdr = rx_buf->desc;
  2636. len = rx_hdr->l2_fhdr_pkt_len;
  2637. status = rx_hdr->l2_fhdr_status;
  2638. hdr_len = 0;
  2639. if (status & L2_FHDR_STATUS_SPLIT) {
  2640. hdr_len = rx_hdr->l2_fhdr_ip_xsum;
  2641. pg_ring_used = 1;
  2642. } else if (len > bp->rx_jumbo_thresh) {
  2643. hdr_len = bp->rx_jumbo_thresh;
  2644. pg_ring_used = 1;
  2645. }
  2646. if (unlikely(status & (L2_FHDR_ERRORS_BAD_CRC |
  2647. L2_FHDR_ERRORS_PHY_DECODE |
  2648. L2_FHDR_ERRORS_ALIGNMENT |
  2649. L2_FHDR_ERRORS_TOO_SHORT |
  2650. L2_FHDR_ERRORS_GIANT_FRAME))) {
  2651. bnx2_reuse_rx_skb(bp, rxr, skb, sw_ring_cons,
  2652. sw_ring_prod);
  2653. if (pg_ring_used) {
  2654. int pages;
  2655. pages = PAGE_ALIGN(len - hdr_len) >> PAGE_SHIFT;
  2656. bnx2_reuse_rx_skb_pages(bp, rxr, NULL, pages);
  2657. }
  2658. goto next_rx;
  2659. }
  2660. len -= 4;
  2661. if (len <= bp->rx_copy_thresh) {
  2662. struct sk_buff *new_skb;
  2663. new_skb = netdev_alloc_skb(bp->dev, len + 6);
  2664. if (new_skb == NULL) {
  2665. bnx2_reuse_rx_skb(bp, rxr, skb, sw_ring_cons,
  2666. sw_ring_prod);
  2667. goto next_rx;
  2668. }
  2669. /* aligned copy */
  2670. skb_copy_from_linear_data_offset(skb,
  2671. BNX2_RX_OFFSET - 6,
  2672. new_skb->data, len + 6);
  2673. skb_reserve(new_skb, 6);
  2674. skb_put(new_skb, len);
  2675. bnx2_reuse_rx_skb(bp, rxr, skb,
  2676. sw_ring_cons, sw_ring_prod);
  2677. skb = new_skb;
  2678. } else if (unlikely(bnx2_rx_skb(bp, rxr, skb, len, hdr_len,
  2679. dma_addr, (sw_ring_cons << 16) | sw_ring_prod)))
  2680. goto next_rx;
  2681. if ((status & L2_FHDR_STATUS_L2_VLAN_TAG) &&
  2682. !(bp->rx_mode & BNX2_EMAC_RX_MODE_KEEP_VLAN_TAG))
  2683. __vlan_hwaccel_put_tag(skb, rx_hdr->l2_fhdr_vlan_tag);
  2684. skb->protocol = eth_type_trans(skb, bp->dev);
  2685. if ((len > (bp->dev->mtu + ETH_HLEN)) &&
  2686. (ntohs(skb->protocol) != 0x8100)) {
  2687. dev_kfree_skb(skb);
  2688. goto next_rx;
  2689. }
  2690. skb_checksum_none_assert(skb);
  2691. if ((bp->dev->features & NETIF_F_RXCSUM) &&
  2692. (status & (L2_FHDR_STATUS_TCP_SEGMENT |
  2693. L2_FHDR_STATUS_UDP_DATAGRAM))) {
  2694. if (likely((status & (L2_FHDR_ERRORS_TCP_XSUM |
  2695. L2_FHDR_ERRORS_UDP_XSUM)) == 0))
  2696. skb->ip_summed = CHECKSUM_UNNECESSARY;
  2697. }
  2698. if ((bp->dev->features & NETIF_F_RXHASH) &&
  2699. ((status & L2_FHDR_STATUS_USE_RXHASH) ==
  2700. L2_FHDR_STATUS_USE_RXHASH))
  2701. skb->rxhash = rx_hdr->l2_fhdr_hash;
  2702. skb_record_rx_queue(skb, bnapi - &bp->bnx2_napi[0]);
  2703. napi_gro_receive(&bnapi->napi, skb);
  2704. rx_pkt++;
  2705. next_rx:
  2706. sw_cons = NEXT_RX_BD(sw_cons);
  2707. sw_prod = NEXT_RX_BD(sw_prod);
  2708. if ((rx_pkt == budget))
  2709. break;
  2710. /* Refresh hw_cons to see if there is new work */
  2711. if (sw_cons == hw_cons) {
  2712. hw_cons = bnx2_get_hw_rx_cons(bnapi);
  2713. rmb();
  2714. }
  2715. }
  2716. rxr->rx_cons = sw_cons;
  2717. rxr->rx_prod = sw_prod;
  2718. if (pg_ring_used)
  2719. REG_WR16(bp, rxr->rx_pg_bidx_addr, rxr->rx_pg_prod);
  2720. REG_WR16(bp, rxr->rx_bidx_addr, sw_prod);
  2721. REG_WR(bp, rxr->rx_bseq_addr, rxr->rx_prod_bseq);
  2722. mmiowb();
  2723. return rx_pkt;
  2724. }
  2725. /* MSI ISR - The only difference between this and the INTx ISR
  2726. * is that the MSI interrupt is always serviced.
  2727. */
  2728. static irqreturn_t
  2729. bnx2_msi(int irq, void *dev_instance)
  2730. {
  2731. struct bnx2_napi *bnapi = dev_instance;
  2732. struct bnx2 *bp = bnapi->bp;
  2733. prefetch(bnapi->status_blk.msi);
  2734. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  2735. BNX2_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM |
  2736. BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
  2737. /* Return here if interrupt is disabled. */
  2738. if (unlikely(atomic_read(&bp->intr_sem) != 0))
  2739. return IRQ_HANDLED;
  2740. napi_schedule(&bnapi->napi);
  2741. return IRQ_HANDLED;
  2742. }
  2743. static irqreturn_t
  2744. bnx2_msi_1shot(int irq, void *dev_instance)
  2745. {
  2746. struct bnx2_napi *bnapi = dev_instance;
  2747. struct bnx2 *bp = bnapi->bp;
  2748. prefetch(bnapi->status_blk.msi);
  2749. /* Return here if interrupt is disabled. */
  2750. if (unlikely(atomic_read(&bp->intr_sem) != 0))
  2751. return IRQ_HANDLED;
  2752. napi_schedule(&bnapi->napi);
  2753. return IRQ_HANDLED;
  2754. }
  2755. static irqreturn_t
  2756. bnx2_interrupt(int irq, void *dev_instance)
  2757. {
  2758. struct bnx2_napi *bnapi = dev_instance;
  2759. struct bnx2 *bp = bnapi->bp;
  2760. struct status_block *sblk = bnapi->status_blk.msi;
  2761. /* When using INTx, it is possible for the interrupt to arrive
  2762. * at the CPU before the status block posted prior to the
  2763. * interrupt. Reading a register will flush the status block.
  2764. * When using MSI, the MSI message will always complete after
  2765. * the status block write.
  2766. */
  2767. if ((sblk->status_idx == bnapi->last_status_idx) &&
  2768. (REG_RD(bp, BNX2_PCICFG_MISC_STATUS) &
  2769. BNX2_PCICFG_MISC_STATUS_INTA_VALUE))
  2770. return IRQ_NONE;
  2771. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  2772. BNX2_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM |
  2773. BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
  2774. /* Read back to deassert IRQ immediately to avoid too many
  2775. * spurious interrupts.
  2776. */
  2777. REG_RD(bp, BNX2_PCICFG_INT_ACK_CMD);
  2778. /* Return here if interrupt is shared and is disabled. */
  2779. if (unlikely(atomic_read(&bp->intr_sem) != 0))
  2780. return IRQ_HANDLED;
  2781. if (napi_schedule_prep(&bnapi->napi)) {
  2782. bnapi->last_status_idx = sblk->status_idx;
  2783. __napi_schedule(&bnapi->napi);
  2784. }
  2785. return IRQ_HANDLED;
  2786. }
  2787. static inline int
  2788. bnx2_has_fast_work(struct bnx2_napi *bnapi)
  2789. {
  2790. struct bnx2_tx_ring_info *txr = &bnapi->tx_ring;
  2791. struct bnx2_rx_ring_info *rxr = &bnapi->rx_ring;
  2792. if ((bnx2_get_hw_rx_cons(bnapi) != rxr->rx_cons) ||
  2793. (bnx2_get_hw_tx_cons(bnapi) != txr->hw_tx_cons))
  2794. return 1;
  2795. return 0;
  2796. }
  2797. #define STATUS_ATTN_EVENTS (STATUS_ATTN_BITS_LINK_STATE | \
  2798. STATUS_ATTN_BITS_TIMER_ABORT)
  2799. static inline int
  2800. bnx2_has_work(struct bnx2_napi *bnapi)
  2801. {
  2802. struct status_block *sblk = bnapi->status_blk.msi;
  2803. if (bnx2_has_fast_work(bnapi))
  2804. return 1;
  2805. #ifdef BCM_CNIC
  2806. if (bnapi->cnic_present && (bnapi->cnic_tag != sblk->status_idx))
  2807. return 1;
  2808. #endif
  2809. if ((sblk->status_attn_bits & STATUS_ATTN_EVENTS) !=
  2810. (sblk->status_attn_bits_ack & STATUS_ATTN_EVENTS))
  2811. return 1;
  2812. return 0;
  2813. }
  2814. static void
  2815. bnx2_chk_missed_msi(struct bnx2 *bp)
  2816. {
  2817. struct bnx2_napi *bnapi = &bp->bnx2_napi[0];
  2818. u32 msi_ctrl;
  2819. if (bnx2_has_work(bnapi)) {
  2820. msi_ctrl = REG_RD(bp, BNX2_PCICFG_MSI_CONTROL);
  2821. if (!(msi_ctrl & BNX2_PCICFG_MSI_CONTROL_ENABLE))
  2822. return;
  2823. if (bnapi->last_status_idx == bp->idle_chk_status_idx) {
  2824. REG_WR(bp, BNX2_PCICFG_MSI_CONTROL, msi_ctrl &
  2825. ~BNX2_PCICFG_MSI_CONTROL_ENABLE);
  2826. REG_WR(bp, BNX2_PCICFG_MSI_CONTROL, msi_ctrl);
  2827. bnx2_msi(bp->irq_tbl[0].vector, bnapi);
  2828. }
  2829. }
  2830. bp->idle_chk_status_idx = bnapi->last_status_idx;
  2831. }
  2832. #ifdef BCM_CNIC
  2833. static void bnx2_poll_cnic(struct bnx2 *bp, struct bnx2_napi *bnapi)
  2834. {
  2835. struct cnic_ops *c_ops;
  2836. if (!bnapi->cnic_present)
  2837. return;
  2838. rcu_read_lock();
  2839. c_ops = rcu_dereference(bp->cnic_ops);
  2840. if (c_ops)
  2841. bnapi->cnic_tag = c_ops->cnic_handler(bp->cnic_data,
  2842. bnapi->status_blk.msi);
  2843. rcu_read_unlock();
  2844. }
  2845. #endif
  2846. static void bnx2_poll_link(struct bnx2 *bp, struct bnx2_napi *bnapi)
  2847. {
  2848. struct status_block *sblk = bnapi->status_blk.msi;
  2849. u32 status_attn_bits = sblk->status_attn_bits;
  2850. u32 status_attn_bits_ack = sblk->status_attn_bits_ack;
  2851. if ((status_attn_bits & STATUS_ATTN_EVENTS) !=
  2852. (status_attn_bits_ack & STATUS_ATTN_EVENTS)) {
  2853. bnx2_phy_int(bp, bnapi);
  2854. /* This is needed to take care of transient status
  2855. * during link changes.
  2856. */
  2857. REG_WR(bp, BNX2_HC_COMMAND,
  2858. bp->hc_cmd | BNX2_HC_COMMAND_COAL_NOW_WO_INT);
  2859. REG_RD(bp, BNX2_HC_COMMAND);
  2860. }
  2861. }
  2862. static int bnx2_poll_work(struct bnx2 *bp, struct bnx2_napi *bnapi,
  2863. int work_done, int budget)
  2864. {
  2865. struct bnx2_tx_ring_info *txr = &bnapi->tx_ring;
  2866. struct bnx2_rx_ring_info *rxr = &bnapi->rx_ring;
  2867. if (bnx2_get_hw_tx_cons(bnapi) != txr->hw_tx_cons)
  2868. bnx2_tx_int(bp, bnapi, 0);
  2869. if (bnx2_get_hw_rx_cons(bnapi) != rxr->rx_cons)
  2870. work_done += bnx2_rx_int(bp, bnapi, budget - work_done);
  2871. return work_done;
  2872. }
  2873. static int bnx2_poll_msix(struct napi_struct *napi, int budget)
  2874. {
  2875. struct bnx2_napi *bnapi = container_of(napi, struct bnx2_napi, napi);
  2876. struct bnx2 *bp = bnapi->bp;
  2877. int work_done = 0;
  2878. struct status_block_msix *sblk = bnapi->status_blk.msix;
  2879. while (1) {
  2880. work_done = bnx2_poll_work(bp, bnapi, work_done, budget);
  2881. if (unlikely(work_done >= budget))
  2882. break;
  2883. bnapi->last_status_idx = sblk->status_idx;
  2884. /* status idx must be read before checking for more work. */
  2885. rmb();
  2886. if (likely(!bnx2_has_fast_work(bnapi))) {
  2887. napi_complete(napi);
  2888. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD, bnapi->int_num |
  2889. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID |
  2890. bnapi->last_status_idx);
  2891. break;
  2892. }
  2893. }
  2894. return work_done;
  2895. }
  2896. static int bnx2_poll(struct napi_struct *napi, int budget)
  2897. {
  2898. struct bnx2_napi *bnapi = container_of(napi, struct bnx2_napi, napi);
  2899. struct bnx2 *bp = bnapi->bp;
  2900. int work_done = 0;
  2901. struct status_block *sblk = bnapi->status_blk.msi;
  2902. while (1) {
  2903. bnx2_poll_link(bp, bnapi);
  2904. work_done = bnx2_poll_work(bp, bnapi, work_done, budget);
  2905. #ifdef BCM_CNIC
  2906. bnx2_poll_cnic(bp, bnapi);
  2907. #endif
  2908. /* bnapi->last_status_idx is used below to tell the hw how
  2909. * much work has been processed, so we must read it before
  2910. * checking for more work.
  2911. */
  2912. bnapi->last_status_idx = sblk->status_idx;
  2913. if (unlikely(work_done >= budget))
  2914. break;
  2915. rmb();
  2916. if (likely(!bnx2_has_work(bnapi))) {
  2917. napi_complete(napi);
  2918. if (likely(bp->flags & BNX2_FLAG_USING_MSI_OR_MSIX)) {
  2919. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  2920. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID |
  2921. bnapi->last_status_idx);
  2922. break;
  2923. }
  2924. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  2925. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID |
  2926. BNX2_PCICFG_INT_ACK_CMD_MASK_INT |
  2927. bnapi->last_status_idx);
  2928. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  2929. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID |
  2930. bnapi->last_status_idx);
  2931. break;
  2932. }
  2933. }
  2934. return work_done;
  2935. }
  2936. /* Called with rtnl_lock from vlan functions and also netif_tx_lock
  2937. * from set_multicast.
  2938. */
  2939. static void
  2940. bnx2_set_rx_mode(struct net_device *dev)
  2941. {
  2942. struct bnx2 *bp = netdev_priv(dev);
  2943. u32 rx_mode, sort_mode;
  2944. struct netdev_hw_addr *ha;
  2945. int i;
  2946. if (!netif_running(dev))
  2947. return;
  2948. spin_lock_bh(&bp->phy_lock);
  2949. rx_mode = bp->rx_mode & ~(BNX2_EMAC_RX_MODE_PROMISCUOUS |
  2950. BNX2_EMAC_RX_MODE_KEEP_VLAN_TAG);
  2951. sort_mode = 1 | BNX2_RPM_SORT_USER0_BC_EN;
  2952. if (!(dev->features & NETIF_F_HW_VLAN_RX) &&
  2953. (bp->flags & BNX2_FLAG_CAN_KEEP_VLAN))
  2954. rx_mode |= BNX2_EMAC_RX_MODE_KEEP_VLAN_TAG;
  2955. if (dev->flags & IFF_PROMISC) {
  2956. /* Promiscuous mode. */
  2957. rx_mode |= BNX2_EMAC_RX_MODE_PROMISCUOUS;
  2958. sort_mode |= BNX2_RPM_SORT_USER0_PROM_EN |
  2959. BNX2_RPM_SORT_USER0_PROM_VLAN;
  2960. }
  2961. else if (dev->flags & IFF_ALLMULTI) {
  2962. for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
  2963. REG_WR(bp, BNX2_EMAC_MULTICAST_HASH0 + (i * 4),
  2964. 0xffffffff);
  2965. }
  2966. sort_mode |= BNX2_RPM_SORT_USER0_MC_EN;
  2967. }
  2968. else {
  2969. /* Accept one or more multicast(s). */
  2970. u32 mc_filter[NUM_MC_HASH_REGISTERS];
  2971. u32 regidx;
  2972. u32 bit;
  2973. u32 crc;
  2974. memset(mc_filter, 0, 4 * NUM_MC_HASH_REGISTERS);
  2975. netdev_for_each_mc_addr(ha, dev) {
  2976. crc = ether_crc_le(ETH_ALEN, ha->addr);
  2977. bit = crc & 0xff;
  2978. regidx = (bit & 0xe0) >> 5;
  2979. bit &= 0x1f;
  2980. mc_filter[regidx] |= (1 << bit);
  2981. }
  2982. for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
  2983. REG_WR(bp, BNX2_EMAC_MULTICAST_HASH0 + (i * 4),
  2984. mc_filter[i]);
  2985. }
  2986. sort_mode |= BNX2_RPM_SORT_USER0_MC_HSH_EN;
  2987. }
  2988. if (netdev_uc_count(dev) > BNX2_MAX_UNICAST_ADDRESSES) {
  2989. rx_mode |= BNX2_EMAC_RX_MODE_PROMISCUOUS;
  2990. sort_mode |= BNX2_RPM_SORT_USER0_PROM_EN |
  2991. BNX2_RPM_SORT_USER0_PROM_VLAN;
  2992. } else if (!(dev->flags & IFF_PROMISC)) {
  2993. /* Add all entries into to the match filter list */
  2994. i = 0;
  2995. netdev_for_each_uc_addr(ha, dev) {
  2996. bnx2_set_mac_addr(bp, ha->addr,
  2997. i + BNX2_START_UNICAST_ADDRESS_INDEX);
  2998. sort_mode |= (1 <<
  2999. (i + BNX2_START_UNICAST_ADDRESS_INDEX));
  3000. i++;
  3001. }
  3002. }
  3003. if (rx_mode != bp->rx_mode) {
  3004. bp->rx_mode = rx_mode;
  3005. REG_WR(bp, BNX2_EMAC_RX_MODE, rx_mode);
  3006. }
  3007. REG_WR(bp, BNX2_RPM_SORT_USER0, 0x0);
  3008. REG_WR(bp, BNX2_RPM_SORT_USER0, sort_mode);
  3009. REG_WR(bp, BNX2_RPM_SORT_USER0, sort_mode | BNX2_RPM_SORT_USER0_ENA);
  3010. spin_unlock_bh(&bp->phy_lock);
  3011. }
  3012. static int __devinit
  3013. check_fw_section(const struct firmware *fw,
  3014. const struct bnx2_fw_file_section *section,
  3015. u32 alignment, bool non_empty)
  3016. {
  3017. u32 offset = be32_to_cpu(section->offset);
  3018. u32 len = be32_to_cpu(section->len);
  3019. if ((offset == 0 && len != 0) || offset >= fw->size || offset & 3)
  3020. return -EINVAL;
  3021. if ((non_empty && len == 0) || len > fw->size - offset ||
  3022. len & (alignment - 1))
  3023. return -EINVAL;
  3024. return 0;
  3025. }
  3026. static int __devinit
  3027. check_mips_fw_entry(const struct firmware *fw,
  3028. const struct bnx2_mips_fw_file_entry *entry)
  3029. {
  3030. if (check_fw_section(fw, &entry->text, 4, true) ||
  3031. check_fw_section(fw, &entry->data, 4, false) ||
  3032. check_fw_section(fw, &entry->rodata, 4, false))
  3033. return -EINVAL;
  3034. return 0;
  3035. }
  3036. static int __devinit
  3037. bnx2_request_firmware(struct bnx2 *bp)
  3038. {
  3039. const char *mips_fw_file, *rv2p_fw_file;
  3040. const struct bnx2_mips_fw_file *mips_fw;
  3041. const struct bnx2_rv2p_fw_file *rv2p_fw;
  3042. int rc;
  3043. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  3044. mips_fw_file = FW_MIPS_FILE_09;
  3045. if ((CHIP_ID(bp) == CHIP_ID_5709_A0) ||
  3046. (CHIP_ID(bp) == CHIP_ID_5709_A1))
  3047. rv2p_fw_file = FW_RV2P_FILE_09_Ax;
  3048. else
  3049. rv2p_fw_file = FW_RV2P_FILE_09;
  3050. } else {
  3051. mips_fw_file = FW_MIPS_FILE_06;
  3052. rv2p_fw_file = FW_RV2P_FILE_06;
  3053. }
  3054. rc = request_firmware(&bp->mips_firmware, mips_fw_file, &bp->pdev->dev);
  3055. if (rc) {
  3056. pr_err("Can't load firmware file \"%s\"\n", mips_fw_file);
  3057. return rc;
  3058. }
  3059. rc = request_firmware(&bp->rv2p_firmware, rv2p_fw_file, &bp->pdev->dev);
  3060. if (rc) {
  3061. pr_err("Can't load firmware file \"%s\"\n", rv2p_fw_file);
  3062. return rc;
  3063. }
  3064. mips_fw = (const struct bnx2_mips_fw_file *) bp->mips_firmware->data;
  3065. rv2p_fw = (const struct bnx2_rv2p_fw_file *) bp->rv2p_firmware->data;
  3066. if (bp->mips_firmware->size < sizeof(*mips_fw) ||
  3067. check_mips_fw_entry(bp->mips_firmware, &mips_fw->com) ||
  3068. check_mips_fw_entry(bp->mips_firmware, &mips_fw->cp) ||
  3069. check_mips_fw_entry(bp->mips_firmware, &mips_fw->rxp) ||
  3070. check_mips_fw_entry(bp->mips_firmware, &mips_fw->tpat) ||
  3071. check_mips_fw_entry(bp->mips_firmware, &mips_fw->txp)) {
  3072. pr_err("Firmware file \"%s\" is invalid\n", mips_fw_file);
  3073. return -EINVAL;
  3074. }
  3075. if (bp->rv2p_firmware->size < sizeof(*rv2p_fw) ||
  3076. check_fw_section(bp->rv2p_firmware, &rv2p_fw->proc1.rv2p, 8, true) ||
  3077. check_fw_section(bp->rv2p_firmware, &rv2p_fw->proc2.rv2p, 8, true)) {
  3078. pr_err("Firmware file \"%s\" is invalid\n", rv2p_fw_file);
  3079. return -EINVAL;
  3080. }
  3081. return 0;
  3082. }
  3083. static u32
  3084. rv2p_fw_fixup(u32 rv2p_proc, int idx, u32 loc, u32 rv2p_code)
  3085. {
  3086. switch (idx) {
  3087. case RV2P_P1_FIXUP_PAGE_SIZE_IDX:
  3088. rv2p_code &= ~RV2P_BD_PAGE_SIZE_MSK;
  3089. rv2p_code |= RV2P_BD_PAGE_SIZE;
  3090. break;
  3091. }
  3092. return rv2p_code;
  3093. }
  3094. static int
  3095. load_rv2p_fw(struct bnx2 *bp, u32 rv2p_proc,
  3096. const struct bnx2_rv2p_fw_file_entry *fw_entry)
  3097. {
  3098. u32 rv2p_code_len, file_offset;
  3099. __be32 *rv2p_code;
  3100. int i;
  3101. u32 val, cmd, addr;
  3102. rv2p_code_len = be32_to_cpu(fw_entry->rv2p.len);
  3103. file_offset = be32_to_cpu(fw_entry->rv2p.offset);
  3104. rv2p_code = (__be32 *)(bp->rv2p_firmware->data + file_offset);
  3105. if (rv2p_proc == RV2P_PROC1) {
  3106. cmd = BNX2_RV2P_PROC1_ADDR_CMD_RDWR;
  3107. addr = BNX2_RV2P_PROC1_ADDR_CMD;
  3108. } else {
  3109. cmd = BNX2_RV2P_PROC2_ADDR_CMD_RDWR;
  3110. addr = BNX2_RV2P_PROC2_ADDR_CMD;
  3111. }
  3112. for (i = 0; i < rv2p_code_len; i += 8) {
  3113. REG_WR(bp, BNX2_RV2P_INSTR_HIGH, be32_to_cpu(*rv2p_code));
  3114. rv2p_code++;
  3115. REG_WR(bp, BNX2_RV2P_INSTR_LOW, be32_to_cpu(*rv2p_code));
  3116. rv2p_code++;
  3117. val = (i / 8) | cmd;
  3118. REG_WR(bp, addr, val);
  3119. }
  3120. rv2p_code = (__be32 *)(bp->rv2p_firmware->data + file_offset);
  3121. for (i = 0; i < 8; i++) {
  3122. u32 loc, code;
  3123. loc = be32_to_cpu(fw_entry->fixup[i]);
  3124. if (loc && ((loc * 4) < rv2p_code_len)) {
  3125. code = be32_to_cpu(*(rv2p_code + loc - 1));
  3126. REG_WR(bp, BNX2_RV2P_INSTR_HIGH, code);
  3127. code = be32_to_cpu(*(rv2p_code + loc));
  3128. code = rv2p_fw_fixup(rv2p_proc, i, loc, code);
  3129. REG_WR(bp, BNX2_RV2P_INSTR_LOW, code);
  3130. val = (loc / 2) | cmd;
  3131. REG_WR(bp, addr, val);
  3132. }
  3133. }
  3134. /* Reset the processor, un-stall is done later. */
  3135. if (rv2p_proc == RV2P_PROC1) {
  3136. REG_WR(bp, BNX2_RV2P_COMMAND, BNX2_RV2P_COMMAND_PROC1_RESET);
  3137. }
  3138. else {
  3139. REG_WR(bp, BNX2_RV2P_COMMAND, BNX2_RV2P_COMMAND_PROC2_RESET);
  3140. }
  3141. return 0;
  3142. }
  3143. static int
  3144. load_cpu_fw(struct bnx2 *bp, const struct cpu_reg *cpu_reg,
  3145. const struct bnx2_mips_fw_file_entry *fw_entry)
  3146. {
  3147. u32 addr, len, file_offset;
  3148. __be32 *data;
  3149. u32 offset;
  3150. u32 val;
  3151. /* Halt the CPU. */
  3152. val = bnx2_reg_rd_ind(bp, cpu_reg->mode);
  3153. val |= cpu_reg->mode_value_halt;
  3154. bnx2_reg_wr_ind(bp, cpu_reg->mode, val);
  3155. bnx2_reg_wr_ind(bp, cpu_reg->state, cpu_reg->state_value_clear);
  3156. /* Load the Text area. */
  3157. addr = be32_to_cpu(fw_entry->text.addr);
  3158. len = be32_to_cpu(fw_entry->text.len);
  3159. file_offset = be32_to_cpu(fw_entry->text.offset);
  3160. data = (__be32 *)(bp->mips_firmware->data + file_offset);
  3161. offset = cpu_reg->spad_base + (addr - cpu_reg->mips_view_base);
  3162. if (len) {
  3163. int j;
  3164. for (j = 0; j < (len / 4); j++, offset += 4)
  3165. bnx2_reg_wr_ind(bp, offset, be32_to_cpu(data[j]));
  3166. }
  3167. /* Load the Data area. */
  3168. addr = be32_to_cpu(fw_entry->data.addr);
  3169. len = be32_to_cpu(fw_entry->data.len);
  3170. file_offset = be32_to_cpu(fw_entry->data.offset);
  3171. data = (__be32 *)(bp->mips_firmware->data + file_offset);
  3172. offset = cpu_reg->spad_base + (addr - cpu_reg->mips_view_base);
  3173. if (len) {
  3174. int j;
  3175. for (j = 0; j < (len / 4); j++, offset += 4)
  3176. bnx2_reg_wr_ind(bp, offset, be32_to_cpu(data[j]));
  3177. }
  3178. /* Load the Read-Only area. */
  3179. addr = be32_to_cpu(fw_entry->rodata.addr);
  3180. len = be32_to_cpu(fw_entry->rodata.len);
  3181. file_offset = be32_to_cpu(fw_entry->rodata.offset);
  3182. data = (__be32 *)(bp->mips_firmware->data + file_offset);
  3183. offset = cpu_reg->spad_base + (addr - cpu_reg->mips_view_base);
  3184. if (len) {
  3185. int j;
  3186. for (j = 0; j < (len / 4); j++, offset += 4)
  3187. bnx2_reg_wr_ind(bp, offset, be32_to_cpu(data[j]));
  3188. }
  3189. /* Clear the pre-fetch instruction. */
  3190. bnx2_reg_wr_ind(bp, cpu_reg->inst, 0);
  3191. val = be32_to_cpu(fw_entry->start_addr);
  3192. bnx2_reg_wr_ind(bp, cpu_reg->pc, val);
  3193. /* Start the CPU. */
  3194. val = bnx2_reg_rd_ind(bp, cpu_reg->mode);
  3195. val &= ~cpu_reg->mode_value_halt;
  3196. bnx2_reg_wr_ind(bp, cpu_reg->state, cpu_reg->state_value_clear);
  3197. bnx2_reg_wr_ind(bp, cpu_reg->mode, val);
  3198. return 0;
  3199. }
  3200. static int
  3201. bnx2_init_cpus(struct bnx2 *bp)
  3202. {
  3203. const struct bnx2_mips_fw_file *mips_fw =
  3204. (const struct bnx2_mips_fw_file *) bp->mips_firmware->data;
  3205. const struct bnx2_rv2p_fw_file *rv2p_fw =
  3206. (const struct bnx2_rv2p_fw_file *) bp->rv2p_firmware->data;
  3207. int rc;
  3208. /* Initialize the RV2P processor. */
  3209. load_rv2p_fw(bp, RV2P_PROC1, &rv2p_fw->proc1);
  3210. load_rv2p_fw(bp, RV2P_PROC2, &rv2p_fw->proc2);
  3211. /* Initialize the RX Processor. */
  3212. rc = load_cpu_fw(bp, &cpu_reg_rxp, &mips_fw->rxp);
  3213. if (rc)
  3214. goto init_cpu_err;
  3215. /* Initialize the TX Processor. */
  3216. rc = load_cpu_fw(bp, &cpu_reg_txp, &mips_fw->txp);
  3217. if (rc)
  3218. goto init_cpu_err;
  3219. /* Initialize the TX Patch-up Processor. */
  3220. rc = load_cpu_fw(bp, &cpu_reg_tpat, &mips_fw->tpat);
  3221. if (rc)
  3222. goto init_cpu_err;
  3223. /* Initialize the Completion Processor. */
  3224. rc = load_cpu_fw(bp, &cpu_reg_com, &mips_fw->com);
  3225. if (rc)
  3226. goto init_cpu_err;
  3227. /* Initialize the Command Processor. */
  3228. rc = load_cpu_fw(bp, &cpu_reg_cp, &mips_fw->cp);
  3229. init_cpu_err:
  3230. return rc;
  3231. }
  3232. static int
  3233. bnx2_set_power_state(struct bnx2 *bp, pci_power_t state)
  3234. {
  3235. u16 pmcsr;
  3236. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmcsr);
  3237. switch (state) {
  3238. case PCI_D0: {
  3239. u32 val;
  3240. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL,
  3241. (pmcsr & ~PCI_PM_CTRL_STATE_MASK) |
  3242. PCI_PM_CTRL_PME_STATUS);
  3243. if (pmcsr & PCI_PM_CTRL_STATE_MASK)
  3244. /* delay required during transition out of D3hot */
  3245. msleep(20);
  3246. val = REG_RD(bp, BNX2_EMAC_MODE);
  3247. val |= BNX2_EMAC_MODE_MPKT_RCVD | BNX2_EMAC_MODE_ACPI_RCVD;
  3248. val &= ~BNX2_EMAC_MODE_MPKT;
  3249. REG_WR(bp, BNX2_EMAC_MODE, val);
  3250. val = REG_RD(bp, BNX2_RPM_CONFIG);
  3251. val &= ~BNX2_RPM_CONFIG_ACPI_ENA;
  3252. REG_WR(bp, BNX2_RPM_CONFIG, val);
  3253. break;
  3254. }
  3255. case PCI_D3hot: {
  3256. int i;
  3257. u32 val, wol_msg;
  3258. if (bp->wol) {
  3259. u32 advertising;
  3260. u8 autoneg;
  3261. autoneg = bp->autoneg;
  3262. advertising = bp->advertising;
  3263. if (bp->phy_port == PORT_TP) {
  3264. bp->autoneg = AUTONEG_SPEED;
  3265. bp->advertising = ADVERTISED_10baseT_Half |
  3266. ADVERTISED_10baseT_Full |
  3267. ADVERTISED_100baseT_Half |
  3268. ADVERTISED_100baseT_Full |
  3269. ADVERTISED_Autoneg;
  3270. }
  3271. spin_lock_bh(&bp->phy_lock);
  3272. bnx2_setup_phy(bp, bp->phy_port);
  3273. spin_unlock_bh(&bp->phy_lock);
  3274. bp->autoneg = autoneg;
  3275. bp->advertising = advertising;
  3276. bnx2_set_mac_addr(bp, bp->dev->dev_addr, 0);
  3277. val = REG_RD(bp, BNX2_EMAC_MODE);
  3278. /* Enable port mode. */
  3279. val &= ~BNX2_EMAC_MODE_PORT;
  3280. val |= BNX2_EMAC_MODE_MPKT_RCVD |
  3281. BNX2_EMAC_MODE_ACPI_RCVD |
  3282. BNX2_EMAC_MODE_MPKT;
  3283. if (bp->phy_port == PORT_TP)
  3284. val |= BNX2_EMAC_MODE_PORT_MII;
  3285. else {
  3286. val |= BNX2_EMAC_MODE_PORT_GMII;
  3287. if (bp->line_speed == SPEED_2500)
  3288. val |= BNX2_EMAC_MODE_25G_MODE;
  3289. }
  3290. REG_WR(bp, BNX2_EMAC_MODE, val);
  3291. /* receive all multicast */
  3292. for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
  3293. REG_WR(bp, BNX2_EMAC_MULTICAST_HASH0 + (i * 4),
  3294. 0xffffffff);
  3295. }
  3296. REG_WR(bp, BNX2_EMAC_RX_MODE,
  3297. BNX2_EMAC_RX_MODE_SORT_MODE);
  3298. val = 1 | BNX2_RPM_SORT_USER0_BC_EN |
  3299. BNX2_RPM_SORT_USER0_MC_EN;
  3300. REG_WR(bp, BNX2_RPM_SORT_USER0, 0x0);
  3301. REG_WR(bp, BNX2_RPM_SORT_USER0, val);
  3302. REG_WR(bp, BNX2_RPM_SORT_USER0, val |
  3303. BNX2_RPM_SORT_USER0_ENA);
  3304. /* Need to enable EMAC and RPM for WOL. */
  3305. REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS,
  3306. BNX2_MISC_ENABLE_SET_BITS_RX_PARSER_MAC_ENABLE |
  3307. BNX2_MISC_ENABLE_SET_BITS_TX_HEADER_Q_ENABLE |
  3308. BNX2_MISC_ENABLE_SET_BITS_EMAC_ENABLE);
  3309. val = REG_RD(bp, BNX2_RPM_CONFIG);
  3310. val &= ~BNX2_RPM_CONFIG_ACPI_ENA;
  3311. REG_WR(bp, BNX2_RPM_CONFIG, val);
  3312. wol_msg = BNX2_DRV_MSG_CODE_SUSPEND_WOL;
  3313. }
  3314. else {
  3315. wol_msg = BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL;
  3316. }
  3317. if (!(bp->flags & BNX2_FLAG_NO_WOL))
  3318. bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT3 | wol_msg,
  3319. 1, 0);
  3320. pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
  3321. if ((CHIP_ID(bp) == CHIP_ID_5706_A0) ||
  3322. (CHIP_ID(bp) == CHIP_ID_5706_A1)) {
  3323. if (bp->wol)
  3324. pmcsr |= 3;
  3325. }
  3326. else {
  3327. pmcsr |= 3;
  3328. }
  3329. if (bp->wol) {
  3330. pmcsr |= PCI_PM_CTRL_PME_ENABLE;
  3331. }
  3332. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL,
  3333. pmcsr);
  3334. /* No more memory access after this point until
  3335. * device is brought back to D0.
  3336. */
  3337. udelay(50);
  3338. break;
  3339. }
  3340. default:
  3341. return -EINVAL;
  3342. }
  3343. return 0;
  3344. }
  3345. static int
  3346. bnx2_acquire_nvram_lock(struct bnx2 *bp)
  3347. {
  3348. u32 val;
  3349. int j;
  3350. /* Request access to the flash interface. */
  3351. REG_WR(bp, BNX2_NVM_SW_ARB, BNX2_NVM_SW_ARB_ARB_REQ_SET2);
  3352. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  3353. val = REG_RD(bp, BNX2_NVM_SW_ARB);
  3354. if (val & BNX2_NVM_SW_ARB_ARB_ARB2)
  3355. break;
  3356. udelay(5);
  3357. }
  3358. if (j >= NVRAM_TIMEOUT_COUNT)
  3359. return -EBUSY;
  3360. return 0;
  3361. }
  3362. static int
  3363. bnx2_release_nvram_lock(struct bnx2 *bp)
  3364. {
  3365. int j;
  3366. u32 val;
  3367. /* Relinquish nvram interface. */
  3368. REG_WR(bp, BNX2_NVM_SW_ARB, BNX2_NVM_SW_ARB_ARB_REQ_CLR2);
  3369. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  3370. val = REG_RD(bp, BNX2_NVM_SW_ARB);
  3371. if (!(val & BNX2_NVM_SW_ARB_ARB_ARB2))
  3372. break;
  3373. udelay(5);
  3374. }
  3375. if (j >= NVRAM_TIMEOUT_COUNT)
  3376. return -EBUSY;
  3377. return 0;
  3378. }
  3379. static int
  3380. bnx2_enable_nvram_write(struct bnx2 *bp)
  3381. {
  3382. u32 val;
  3383. val = REG_RD(bp, BNX2_MISC_CFG);
  3384. REG_WR(bp, BNX2_MISC_CFG, val | BNX2_MISC_CFG_NVM_WR_EN_PCI);
  3385. if (bp->flash_info->flags & BNX2_NV_WREN) {
  3386. int j;
  3387. REG_WR(bp, BNX2_NVM_COMMAND, BNX2_NVM_COMMAND_DONE);
  3388. REG_WR(bp, BNX2_NVM_COMMAND,
  3389. BNX2_NVM_COMMAND_WREN | BNX2_NVM_COMMAND_DOIT);
  3390. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  3391. udelay(5);
  3392. val = REG_RD(bp, BNX2_NVM_COMMAND);
  3393. if (val & BNX2_NVM_COMMAND_DONE)
  3394. break;
  3395. }
  3396. if (j >= NVRAM_TIMEOUT_COUNT)
  3397. return -EBUSY;
  3398. }
  3399. return 0;
  3400. }
  3401. static void
  3402. bnx2_disable_nvram_write(struct bnx2 *bp)
  3403. {
  3404. u32 val;
  3405. val = REG_RD(bp, BNX2_MISC_CFG);
  3406. REG_WR(bp, BNX2_MISC_CFG, val & ~BNX2_MISC_CFG_NVM_WR_EN);
  3407. }
  3408. static void
  3409. bnx2_enable_nvram_access(struct bnx2 *bp)
  3410. {
  3411. u32 val;
  3412. val = REG_RD(bp, BNX2_NVM_ACCESS_ENABLE);
  3413. /* Enable both bits, even on read. */
  3414. REG_WR(bp, BNX2_NVM_ACCESS_ENABLE,
  3415. val | BNX2_NVM_ACCESS_ENABLE_EN | BNX2_NVM_ACCESS_ENABLE_WR_EN);
  3416. }
  3417. static void
  3418. bnx2_disable_nvram_access(struct bnx2 *bp)
  3419. {
  3420. u32 val;
  3421. val = REG_RD(bp, BNX2_NVM_ACCESS_ENABLE);
  3422. /* Disable both bits, even after read. */
  3423. REG_WR(bp, BNX2_NVM_ACCESS_ENABLE,
  3424. val & ~(BNX2_NVM_ACCESS_ENABLE_EN |
  3425. BNX2_NVM_ACCESS_ENABLE_WR_EN));
  3426. }
  3427. static int
  3428. bnx2_nvram_erase_page(struct bnx2 *bp, u32 offset)
  3429. {
  3430. u32 cmd;
  3431. int j;
  3432. if (bp->flash_info->flags & BNX2_NV_BUFFERED)
  3433. /* Buffered flash, no erase needed */
  3434. return 0;
  3435. /* Build an erase command */
  3436. cmd = BNX2_NVM_COMMAND_ERASE | BNX2_NVM_COMMAND_WR |
  3437. BNX2_NVM_COMMAND_DOIT;
  3438. /* Need to clear DONE bit separately. */
  3439. REG_WR(bp, BNX2_NVM_COMMAND, BNX2_NVM_COMMAND_DONE);
  3440. /* Address of the NVRAM to read from. */
  3441. REG_WR(bp, BNX2_NVM_ADDR, offset & BNX2_NVM_ADDR_NVM_ADDR_VALUE);
  3442. /* Issue an erase command. */
  3443. REG_WR(bp, BNX2_NVM_COMMAND, cmd);
  3444. /* Wait for completion. */
  3445. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  3446. u32 val;
  3447. udelay(5);
  3448. val = REG_RD(bp, BNX2_NVM_COMMAND);
  3449. if (val & BNX2_NVM_COMMAND_DONE)
  3450. break;
  3451. }
  3452. if (j >= NVRAM_TIMEOUT_COUNT)
  3453. return -EBUSY;
  3454. return 0;
  3455. }
  3456. static int
  3457. bnx2_nvram_read_dword(struct bnx2 *bp, u32 offset, u8 *ret_val, u32 cmd_flags)
  3458. {
  3459. u32 cmd;
  3460. int j;
  3461. /* Build the command word. */
  3462. cmd = BNX2_NVM_COMMAND_DOIT | cmd_flags;
  3463. /* Calculate an offset of a buffered flash, not needed for 5709. */
  3464. if (bp->flash_info->flags & BNX2_NV_TRANSLATE) {
  3465. offset = ((offset / bp->flash_info->page_size) <<
  3466. bp->flash_info->page_bits) +
  3467. (offset % bp->flash_info->page_size);
  3468. }
  3469. /* Need to clear DONE bit separately. */
  3470. REG_WR(bp, BNX2_NVM_COMMAND, BNX2_NVM_COMMAND_DONE);
  3471. /* Address of the NVRAM to read from. */
  3472. REG_WR(bp, BNX2_NVM_ADDR, offset & BNX2_NVM_ADDR_NVM_ADDR_VALUE);
  3473. /* Issue a read command. */
  3474. REG_WR(bp, BNX2_NVM_COMMAND, cmd);
  3475. /* Wait for completion. */
  3476. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  3477. u32 val;
  3478. udelay(5);
  3479. val = REG_RD(bp, BNX2_NVM_COMMAND);
  3480. if (val & BNX2_NVM_COMMAND_DONE) {
  3481. __be32 v = cpu_to_be32(REG_RD(bp, BNX2_NVM_READ));
  3482. memcpy(ret_val, &v, 4);
  3483. break;
  3484. }
  3485. }
  3486. if (j >= NVRAM_TIMEOUT_COUNT)
  3487. return -EBUSY;
  3488. return 0;
  3489. }
  3490. static int
  3491. bnx2_nvram_write_dword(struct bnx2 *bp, u32 offset, u8 *val, u32 cmd_flags)
  3492. {
  3493. u32 cmd;
  3494. __be32 val32;
  3495. int j;
  3496. /* Build the command word. */
  3497. cmd = BNX2_NVM_COMMAND_DOIT | BNX2_NVM_COMMAND_WR | cmd_flags;
  3498. /* Calculate an offset of a buffered flash, not needed for 5709. */
  3499. if (bp->flash_info->flags & BNX2_NV_TRANSLATE) {
  3500. offset = ((offset / bp->flash_info->page_size) <<
  3501. bp->flash_info->page_bits) +
  3502. (offset % bp->flash_info->page_size);
  3503. }
  3504. /* Need to clear DONE bit separately. */
  3505. REG_WR(bp, BNX2_NVM_COMMAND, BNX2_NVM_COMMAND_DONE);
  3506. memcpy(&val32, val, 4);
  3507. /* Write the data. */
  3508. REG_WR(bp, BNX2_NVM_WRITE, be32_to_cpu(val32));
  3509. /* Address of the NVRAM to write to. */
  3510. REG_WR(bp, BNX2_NVM_ADDR, offset & BNX2_NVM_ADDR_NVM_ADDR_VALUE);
  3511. /* Issue the write command. */
  3512. REG_WR(bp, BNX2_NVM_COMMAND, cmd);
  3513. /* Wait for completion. */
  3514. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  3515. udelay(5);
  3516. if (REG_RD(bp, BNX2_NVM_COMMAND) & BNX2_NVM_COMMAND_DONE)
  3517. break;
  3518. }
  3519. if (j >= NVRAM_TIMEOUT_COUNT)
  3520. return -EBUSY;
  3521. return 0;
  3522. }
  3523. static int
  3524. bnx2_init_nvram(struct bnx2 *bp)
  3525. {
  3526. u32 val;
  3527. int j, entry_count, rc = 0;
  3528. const struct flash_spec *flash;
  3529. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  3530. bp->flash_info = &flash_5709;
  3531. goto get_flash_size;
  3532. }
  3533. /* Determine the selected interface. */
  3534. val = REG_RD(bp, BNX2_NVM_CFG1);
  3535. entry_count = ARRAY_SIZE(flash_table);
  3536. if (val & 0x40000000) {
  3537. /* Flash interface has been reconfigured */
  3538. for (j = 0, flash = &flash_table[0]; j < entry_count;
  3539. j++, flash++) {
  3540. if ((val & FLASH_BACKUP_STRAP_MASK) ==
  3541. (flash->config1 & FLASH_BACKUP_STRAP_MASK)) {
  3542. bp->flash_info = flash;
  3543. break;
  3544. }
  3545. }
  3546. }
  3547. else {
  3548. u32 mask;
  3549. /* Not yet been reconfigured */
  3550. if (val & (1 << 23))
  3551. mask = FLASH_BACKUP_STRAP_MASK;
  3552. else
  3553. mask = FLASH_STRAP_MASK;
  3554. for (j = 0, flash = &flash_table[0]; j < entry_count;
  3555. j++, flash++) {
  3556. if ((val & mask) == (flash->strapping & mask)) {
  3557. bp->flash_info = flash;
  3558. /* Request access to the flash interface. */
  3559. if ((rc = bnx2_acquire_nvram_lock(bp)) != 0)
  3560. return rc;
  3561. /* Enable access to flash interface */
  3562. bnx2_enable_nvram_access(bp);
  3563. /* Reconfigure the flash interface */
  3564. REG_WR(bp, BNX2_NVM_CFG1, flash->config1);
  3565. REG_WR(bp, BNX2_NVM_CFG2, flash->config2);
  3566. REG_WR(bp, BNX2_NVM_CFG3, flash->config3);
  3567. REG_WR(bp, BNX2_NVM_WRITE1, flash->write1);
  3568. /* Disable access to flash interface */
  3569. bnx2_disable_nvram_access(bp);
  3570. bnx2_release_nvram_lock(bp);
  3571. break;
  3572. }
  3573. }
  3574. } /* if (val & 0x40000000) */
  3575. if (j == entry_count) {
  3576. bp->flash_info = NULL;
  3577. pr_alert("Unknown flash/EEPROM type\n");
  3578. return -ENODEV;
  3579. }
  3580. get_flash_size:
  3581. val = bnx2_shmem_rd(bp, BNX2_SHARED_HW_CFG_CONFIG2);
  3582. val &= BNX2_SHARED_HW_CFG2_NVM_SIZE_MASK;
  3583. if (val)
  3584. bp->flash_size = val;
  3585. else
  3586. bp->flash_size = bp->flash_info->total_size;
  3587. return rc;
  3588. }
  3589. static int
  3590. bnx2_nvram_read(struct bnx2 *bp, u32 offset, u8 *ret_buf,
  3591. int buf_size)
  3592. {
  3593. int rc = 0;
  3594. u32 cmd_flags, offset32, len32, extra;
  3595. if (buf_size == 0)
  3596. return 0;
  3597. /* Request access to the flash interface. */
  3598. if ((rc = bnx2_acquire_nvram_lock(bp)) != 0)
  3599. return rc;
  3600. /* Enable access to flash interface */
  3601. bnx2_enable_nvram_access(bp);
  3602. len32 = buf_size;
  3603. offset32 = offset;
  3604. extra = 0;
  3605. cmd_flags = 0;
  3606. if (offset32 & 3) {
  3607. u8 buf[4];
  3608. u32 pre_len;
  3609. offset32 &= ~3;
  3610. pre_len = 4 - (offset & 3);
  3611. if (pre_len >= len32) {
  3612. pre_len = len32;
  3613. cmd_flags = BNX2_NVM_COMMAND_FIRST |
  3614. BNX2_NVM_COMMAND_LAST;
  3615. }
  3616. else {
  3617. cmd_flags = BNX2_NVM_COMMAND_FIRST;
  3618. }
  3619. rc = bnx2_nvram_read_dword(bp, offset32, buf, cmd_flags);
  3620. if (rc)
  3621. return rc;
  3622. memcpy(ret_buf, buf + (offset & 3), pre_len);
  3623. offset32 += 4;
  3624. ret_buf += pre_len;
  3625. len32 -= pre_len;
  3626. }
  3627. if (len32 & 3) {
  3628. extra = 4 - (len32 & 3);
  3629. len32 = (len32 + 4) & ~3;
  3630. }
  3631. if (len32 == 4) {
  3632. u8 buf[4];
  3633. if (cmd_flags)
  3634. cmd_flags = BNX2_NVM_COMMAND_LAST;
  3635. else
  3636. cmd_flags = BNX2_NVM_COMMAND_FIRST |
  3637. BNX2_NVM_COMMAND_LAST;
  3638. rc = bnx2_nvram_read_dword(bp, offset32, buf, cmd_flags);
  3639. memcpy(ret_buf, buf, 4 - extra);
  3640. }
  3641. else if (len32 > 0) {
  3642. u8 buf[4];
  3643. /* Read the first word. */
  3644. if (cmd_flags)
  3645. cmd_flags = 0;
  3646. else
  3647. cmd_flags = BNX2_NVM_COMMAND_FIRST;
  3648. rc = bnx2_nvram_read_dword(bp, offset32, ret_buf, cmd_flags);
  3649. /* Advance to the next dword. */
  3650. offset32 += 4;
  3651. ret_buf += 4;
  3652. len32 -= 4;
  3653. while (len32 > 4 && rc == 0) {
  3654. rc = bnx2_nvram_read_dword(bp, offset32, ret_buf, 0);
  3655. /* Advance to the next dword. */
  3656. offset32 += 4;
  3657. ret_buf += 4;
  3658. len32 -= 4;
  3659. }
  3660. if (rc)
  3661. return rc;
  3662. cmd_flags = BNX2_NVM_COMMAND_LAST;
  3663. rc = bnx2_nvram_read_dword(bp, offset32, buf, cmd_flags);
  3664. memcpy(ret_buf, buf, 4 - extra);
  3665. }
  3666. /* Disable access to flash interface */
  3667. bnx2_disable_nvram_access(bp);
  3668. bnx2_release_nvram_lock(bp);
  3669. return rc;
  3670. }
  3671. static int
  3672. bnx2_nvram_write(struct bnx2 *bp, u32 offset, u8 *data_buf,
  3673. int buf_size)
  3674. {
  3675. u32 written, offset32, len32;
  3676. u8 *buf, start[4], end[4], *align_buf = NULL, *flash_buffer = NULL;
  3677. int rc = 0;
  3678. int align_start, align_end;
  3679. buf = data_buf;
  3680. offset32 = offset;
  3681. len32 = buf_size;
  3682. align_start = align_end = 0;
  3683. if ((align_start = (offset32 & 3))) {
  3684. offset32 &= ~3;
  3685. len32 += align_start;
  3686. if (len32 < 4)
  3687. len32 = 4;
  3688. if ((rc = bnx2_nvram_read(bp, offset32, start, 4)))
  3689. return rc;
  3690. }
  3691. if (len32 & 3) {
  3692. align_end = 4 - (len32 & 3);
  3693. len32 += align_end;
  3694. if ((rc = bnx2_nvram_read(bp, offset32 + len32 - 4, end, 4)))
  3695. return rc;
  3696. }
  3697. if (align_start || align_end) {
  3698. align_buf = kmalloc(len32, GFP_KERNEL);
  3699. if (align_buf == NULL)
  3700. return -ENOMEM;
  3701. if (align_start) {
  3702. memcpy(align_buf, start, 4);
  3703. }
  3704. if (align_end) {
  3705. memcpy(align_buf + len32 - 4, end, 4);
  3706. }
  3707. memcpy(align_buf + align_start, data_buf, buf_size);
  3708. buf = align_buf;
  3709. }
  3710. if (!(bp->flash_info->flags & BNX2_NV_BUFFERED)) {
  3711. flash_buffer = kmalloc(264, GFP_KERNEL);
  3712. if (flash_buffer == NULL) {
  3713. rc = -ENOMEM;
  3714. goto nvram_write_end;
  3715. }
  3716. }
  3717. written = 0;
  3718. while ((written < len32) && (rc == 0)) {
  3719. u32 page_start, page_end, data_start, data_end;
  3720. u32 addr, cmd_flags;
  3721. int i;
  3722. /* Find the page_start addr */
  3723. page_start = offset32 + written;
  3724. page_start -= (page_start % bp->flash_info->page_size);
  3725. /* Find the page_end addr */
  3726. page_end = page_start + bp->flash_info->page_size;
  3727. /* Find the data_start addr */
  3728. data_start = (written == 0) ? offset32 : page_start;
  3729. /* Find the data_end addr */
  3730. data_end = (page_end > offset32 + len32) ?
  3731. (offset32 + len32) : page_end;
  3732. /* Request access to the flash interface. */
  3733. if ((rc = bnx2_acquire_nvram_lock(bp)) != 0)
  3734. goto nvram_write_end;
  3735. /* Enable access to flash interface */
  3736. bnx2_enable_nvram_access(bp);
  3737. cmd_flags = BNX2_NVM_COMMAND_FIRST;
  3738. if (!(bp->flash_info->flags & BNX2_NV_BUFFERED)) {
  3739. int j;
  3740. /* Read the whole page into the buffer
  3741. * (non-buffer flash only) */
  3742. for (j = 0; j < bp->flash_info->page_size; j += 4) {
  3743. if (j == (bp->flash_info->page_size - 4)) {
  3744. cmd_flags |= BNX2_NVM_COMMAND_LAST;
  3745. }
  3746. rc = bnx2_nvram_read_dword(bp,
  3747. page_start + j,
  3748. &flash_buffer[j],
  3749. cmd_flags);
  3750. if (rc)
  3751. goto nvram_write_end;
  3752. cmd_flags = 0;
  3753. }
  3754. }
  3755. /* Enable writes to flash interface (unlock write-protect) */
  3756. if ((rc = bnx2_enable_nvram_write(bp)) != 0)
  3757. goto nvram_write_end;
  3758. /* Loop to write back the buffer data from page_start to
  3759. * data_start */
  3760. i = 0;
  3761. if (!(bp->flash_info->flags & BNX2_NV_BUFFERED)) {
  3762. /* Erase the page */
  3763. if ((rc = bnx2_nvram_erase_page(bp, page_start)) != 0)
  3764. goto nvram_write_end;
  3765. /* Re-enable the write again for the actual write */
  3766. bnx2_enable_nvram_write(bp);
  3767. for (addr = page_start; addr < data_start;
  3768. addr += 4, i += 4) {
  3769. rc = bnx2_nvram_write_dword(bp, addr,
  3770. &flash_buffer[i], cmd_flags);
  3771. if (rc != 0)
  3772. goto nvram_write_end;
  3773. cmd_flags = 0;
  3774. }
  3775. }
  3776. /* Loop to write the new data from data_start to data_end */
  3777. for (addr = data_start; addr < data_end; addr += 4, i += 4) {
  3778. if ((addr == page_end - 4) ||
  3779. ((bp->flash_info->flags & BNX2_NV_BUFFERED) &&
  3780. (addr == data_end - 4))) {
  3781. cmd_flags |= BNX2_NVM_COMMAND_LAST;
  3782. }
  3783. rc = bnx2_nvram_write_dword(bp, addr, buf,
  3784. cmd_flags);
  3785. if (rc != 0)
  3786. goto nvram_write_end;
  3787. cmd_flags = 0;
  3788. buf += 4;
  3789. }
  3790. /* Loop to write back the buffer data from data_end
  3791. * to page_end */
  3792. if (!(bp->flash_info->flags & BNX2_NV_BUFFERED)) {
  3793. for (addr = data_end; addr < page_end;
  3794. addr += 4, i += 4) {
  3795. if (addr == page_end-4) {
  3796. cmd_flags = BNX2_NVM_COMMAND_LAST;
  3797. }
  3798. rc = bnx2_nvram_write_dword(bp, addr,
  3799. &flash_buffer[i], cmd_flags);
  3800. if (rc != 0)
  3801. goto nvram_write_end;
  3802. cmd_flags = 0;
  3803. }
  3804. }
  3805. /* Disable writes to flash interface (lock write-protect) */
  3806. bnx2_disable_nvram_write(bp);
  3807. /* Disable access to flash interface */
  3808. bnx2_disable_nvram_access(bp);
  3809. bnx2_release_nvram_lock(bp);
  3810. /* Increment written */
  3811. written += data_end - data_start;
  3812. }
  3813. nvram_write_end:
  3814. kfree(flash_buffer);
  3815. kfree(align_buf);
  3816. return rc;
  3817. }
  3818. static void
  3819. bnx2_init_fw_cap(struct bnx2 *bp)
  3820. {
  3821. u32 val, sig = 0;
  3822. bp->phy_flags &= ~BNX2_PHY_FLAG_REMOTE_PHY_CAP;
  3823. bp->flags &= ~BNX2_FLAG_CAN_KEEP_VLAN;
  3824. if (!(bp->flags & BNX2_FLAG_ASF_ENABLE))
  3825. bp->flags |= BNX2_FLAG_CAN_KEEP_VLAN;
  3826. val = bnx2_shmem_rd(bp, BNX2_FW_CAP_MB);
  3827. if ((val & BNX2_FW_CAP_SIGNATURE_MASK) != BNX2_FW_CAP_SIGNATURE)
  3828. return;
  3829. if ((val & BNX2_FW_CAP_CAN_KEEP_VLAN) == BNX2_FW_CAP_CAN_KEEP_VLAN) {
  3830. bp->flags |= BNX2_FLAG_CAN_KEEP_VLAN;
  3831. sig |= BNX2_DRV_ACK_CAP_SIGNATURE | BNX2_FW_CAP_CAN_KEEP_VLAN;
  3832. }
  3833. if ((bp->phy_flags & BNX2_PHY_FLAG_SERDES) &&
  3834. (val & BNX2_FW_CAP_REMOTE_PHY_CAPABLE)) {
  3835. u32 link;
  3836. bp->phy_flags |= BNX2_PHY_FLAG_REMOTE_PHY_CAP;
  3837. link = bnx2_shmem_rd(bp, BNX2_LINK_STATUS);
  3838. if (link & BNX2_LINK_STATUS_SERDES_LINK)
  3839. bp->phy_port = PORT_FIBRE;
  3840. else
  3841. bp->phy_port = PORT_TP;
  3842. sig |= BNX2_DRV_ACK_CAP_SIGNATURE |
  3843. BNX2_FW_CAP_REMOTE_PHY_CAPABLE;
  3844. }
  3845. if (netif_running(bp->dev) && sig)
  3846. bnx2_shmem_wr(bp, BNX2_DRV_ACK_CAP_MB, sig);
  3847. }
  3848. static void
  3849. bnx2_setup_msix_tbl(struct bnx2 *bp)
  3850. {
  3851. REG_WR(bp, BNX2_PCI_GRC_WINDOW_ADDR, BNX2_PCI_GRC_WINDOW_ADDR_SEP_WIN);
  3852. REG_WR(bp, BNX2_PCI_GRC_WINDOW2_ADDR, BNX2_MSIX_TABLE_ADDR);
  3853. REG_WR(bp, BNX2_PCI_GRC_WINDOW3_ADDR, BNX2_MSIX_PBA_ADDR);
  3854. }
  3855. static int
  3856. bnx2_reset_chip(struct bnx2 *bp, u32 reset_code)
  3857. {
  3858. u32 val;
  3859. int i, rc = 0;
  3860. u8 old_port;
  3861. /* Wait for the current PCI transaction to complete before
  3862. * issuing a reset. */
  3863. if ((CHIP_NUM(bp) == CHIP_NUM_5706) ||
  3864. (CHIP_NUM(bp) == CHIP_NUM_5708)) {
  3865. REG_WR(bp, BNX2_MISC_ENABLE_CLR_BITS,
  3866. BNX2_MISC_ENABLE_CLR_BITS_TX_DMA_ENABLE |
  3867. BNX2_MISC_ENABLE_CLR_BITS_DMA_ENGINE_ENABLE |
  3868. BNX2_MISC_ENABLE_CLR_BITS_RX_DMA_ENABLE |
  3869. BNX2_MISC_ENABLE_CLR_BITS_HOST_COALESCE_ENABLE);
  3870. val = REG_RD(bp, BNX2_MISC_ENABLE_CLR_BITS);
  3871. udelay(5);
  3872. } else { /* 5709 */
  3873. val = REG_RD(bp, BNX2_MISC_NEW_CORE_CTL);
  3874. val &= ~BNX2_MISC_NEW_CORE_CTL_DMA_ENABLE;
  3875. REG_WR(bp, BNX2_MISC_NEW_CORE_CTL, val);
  3876. val = REG_RD(bp, BNX2_MISC_NEW_CORE_CTL);
  3877. for (i = 0; i < 100; i++) {
  3878. msleep(1);
  3879. val = REG_RD(bp, BNX2_PCICFG_DEVICE_CONTROL);
  3880. if (!(val & BNX2_PCICFG_DEVICE_STATUS_NO_PEND))
  3881. break;
  3882. }
  3883. }
  3884. /* Wait for the firmware to tell us it is ok to issue a reset. */
  3885. bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT0 | reset_code, 1, 1);
  3886. /* Deposit a driver reset signature so the firmware knows that
  3887. * this is a soft reset. */
  3888. bnx2_shmem_wr(bp, BNX2_DRV_RESET_SIGNATURE,
  3889. BNX2_DRV_RESET_SIGNATURE_MAGIC);
  3890. /* Do a dummy read to force the chip to complete all current transaction
  3891. * before we issue a reset. */
  3892. val = REG_RD(bp, BNX2_MISC_ID);
  3893. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  3894. REG_WR(bp, BNX2_MISC_COMMAND, BNX2_MISC_COMMAND_SW_RESET);
  3895. REG_RD(bp, BNX2_MISC_COMMAND);
  3896. udelay(5);
  3897. val = BNX2_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
  3898. BNX2_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP;
  3899. REG_WR(bp, BNX2_PCICFG_MISC_CONFIG, val);
  3900. } else {
  3901. val = BNX2_PCICFG_MISC_CONFIG_CORE_RST_REQ |
  3902. BNX2_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
  3903. BNX2_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP;
  3904. /* Chip reset. */
  3905. REG_WR(bp, BNX2_PCICFG_MISC_CONFIG, val);
  3906. /* Reading back any register after chip reset will hang the
  3907. * bus on 5706 A0 and A1. The msleep below provides plenty
  3908. * of margin for write posting.
  3909. */
  3910. if ((CHIP_ID(bp) == CHIP_ID_5706_A0) ||
  3911. (CHIP_ID(bp) == CHIP_ID_5706_A1))
  3912. msleep(20);
  3913. /* Reset takes approximate 30 usec */
  3914. for (i = 0; i < 10; i++) {
  3915. val = REG_RD(bp, BNX2_PCICFG_MISC_CONFIG);
  3916. if ((val & (BNX2_PCICFG_MISC_CONFIG_CORE_RST_REQ |
  3917. BNX2_PCICFG_MISC_CONFIG_CORE_RST_BSY)) == 0)
  3918. break;
  3919. udelay(10);
  3920. }
  3921. if (val & (BNX2_PCICFG_MISC_CONFIG_CORE_RST_REQ |
  3922. BNX2_PCICFG_MISC_CONFIG_CORE_RST_BSY)) {
  3923. pr_err("Chip reset did not complete\n");
  3924. return -EBUSY;
  3925. }
  3926. }
  3927. /* Make sure byte swapping is properly configured. */
  3928. val = REG_RD(bp, BNX2_PCI_SWAP_DIAG0);
  3929. if (val != 0x01020304) {
  3930. pr_err("Chip not in correct endian mode\n");
  3931. return -ENODEV;
  3932. }
  3933. /* Wait for the firmware to finish its initialization. */
  3934. rc = bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT1 | reset_code, 1, 0);
  3935. if (rc)
  3936. return rc;
  3937. spin_lock_bh(&bp->phy_lock);
  3938. old_port = bp->phy_port;
  3939. bnx2_init_fw_cap(bp);
  3940. if ((bp->phy_flags & BNX2_PHY_FLAG_REMOTE_PHY_CAP) &&
  3941. old_port != bp->phy_port)
  3942. bnx2_set_default_remote_link(bp);
  3943. spin_unlock_bh(&bp->phy_lock);
  3944. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  3945. /* Adjust the voltage regular to two steps lower. The default
  3946. * of this register is 0x0000000e. */
  3947. REG_WR(bp, BNX2_MISC_VREG_CONTROL, 0x000000fa);
  3948. /* Remove bad rbuf memory from the free pool. */
  3949. rc = bnx2_alloc_bad_rbuf(bp);
  3950. }
  3951. if (bp->flags & BNX2_FLAG_USING_MSIX) {
  3952. bnx2_setup_msix_tbl(bp);
  3953. /* Prevent MSIX table reads and write from timing out */
  3954. REG_WR(bp, BNX2_MISC_ECO_HW_CTL,
  3955. BNX2_MISC_ECO_HW_CTL_LARGE_GRC_TMOUT_EN);
  3956. }
  3957. return rc;
  3958. }
  3959. static int
  3960. bnx2_init_chip(struct bnx2 *bp)
  3961. {
  3962. u32 val, mtu;
  3963. int rc, i;
  3964. /* Make sure the interrupt is not active. */
  3965. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD, BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
  3966. val = BNX2_DMA_CONFIG_DATA_BYTE_SWAP |
  3967. BNX2_DMA_CONFIG_DATA_WORD_SWAP |
  3968. #ifdef __BIG_ENDIAN
  3969. BNX2_DMA_CONFIG_CNTL_BYTE_SWAP |
  3970. #endif
  3971. BNX2_DMA_CONFIG_CNTL_WORD_SWAP |
  3972. DMA_READ_CHANS << 12 |
  3973. DMA_WRITE_CHANS << 16;
  3974. val |= (0x2 << 20) | (1 << 11);
  3975. if ((bp->flags & BNX2_FLAG_PCIX) && (bp->bus_speed_mhz == 133))
  3976. val |= (1 << 23);
  3977. if ((CHIP_NUM(bp) == CHIP_NUM_5706) &&
  3978. (CHIP_ID(bp) != CHIP_ID_5706_A0) && !(bp->flags & BNX2_FLAG_PCIX))
  3979. val |= BNX2_DMA_CONFIG_CNTL_PING_PONG_DMA;
  3980. REG_WR(bp, BNX2_DMA_CONFIG, val);
  3981. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  3982. val = REG_RD(bp, BNX2_TDMA_CONFIG);
  3983. val |= BNX2_TDMA_CONFIG_ONE_DMA;
  3984. REG_WR(bp, BNX2_TDMA_CONFIG, val);
  3985. }
  3986. if (bp->flags & BNX2_FLAG_PCIX) {
  3987. u16 val16;
  3988. pci_read_config_word(bp->pdev, bp->pcix_cap + PCI_X_CMD,
  3989. &val16);
  3990. pci_write_config_word(bp->pdev, bp->pcix_cap + PCI_X_CMD,
  3991. val16 & ~PCI_X_CMD_ERO);
  3992. }
  3993. REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS,
  3994. BNX2_MISC_ENABLE_SET_BITS_HOST_COALESCE_ENABLE |
  3995. BNX2_MISC_ENABLE_STATUS_BITS_RX_V2P_ENABLE |
  3996. BNX2_MISC_ENABLE_STATUS_BITS_CONTEXT_ENABLE);
  3997. /* Initialize context mapping and zero out the quick contexts. The
  3998. * context block must have already been enabled. */
  3999. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  4000. rc = bnx2_init_5709_context(bp);
  4001. if (rc)
  4002. return rc;
  4003. } else
  4004. bnx2_init_context(bp);
  4005. if ((rc = bnx2_init_cpus(bp)) != 0)
  4006. return rc;
  4007. bnx2_init_nvram(bp);
  4008. bnx2_set_mac_addr(bp, bp->dev->dev_addr, 0);
  4009. val = REG_RD(bp, BNX2_MQ_CONFIG);
  4010. val &= ~BNX2_MQ_CONFIG_KNL_BYP_BLK_SIZE;
  4011. val |= BNX2_MQ_CONFIG_KNL_BYP_BLK_SIZE_256;
  4012. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  4013. val |= BNX2_MQ_CONFIG_BIN_MQ_MODE;
  4014. if (CHIP_REV(bp) == CHIP_REV_Ax)
  4015. val |= BNX2_MQ_CONFIG_HALT_DIS;
  4016. }
  4017. REG_WR(bp, BNX2_MQ_CONFIG, val);
  4018. val = 0x10000 + (MAX_CID_CNT * MB_KERNEL_CTX_SIZE);
  4019. REG_WR(bp, BNX2_MQ_KNL_BYP_WIND_START, val);
  4020. REG_WR(bp, BNX2_MQ_KNL_WIND_END, val);
  4021. val = (BCM_PAGE_BITS - 8) << 24;
  4022. REG_WR(bp, BNX2_RV2P_CONFIG, val);
  4023. /* Configure page size. */
  4024. val = REG_RD(bp, BNX2_TBDR_CONFIG);
  4025. val &= ~BNX2_TBDR_CONFIG_PAGE_SIZE;
  4026. val |= (BCM_PAGE_BITS - 8) << 24 | 0x40;
  4027. REG_WR(bp, BNX2_TBDR_CONFIG, val);
  4028. val = bp->mac_addr[0] +
  4029. (bp->mac_addr[1] << 8) +
  4030. (bp->mac_addr[2] << 16) +
  4031. bp->mac_addr[3] +
  4032. (bp->mac_addr[4] << 8) +
  4033. (bp->mac_addr[5] << 16);
  4034. REG_WR(bp, BNX2_EMAC_BACKOFF_SEED, val);
  4035. /* Program the MTU. Also include 4 bytes for CRC32. */
  4036. mtu = bp->dev->mtu;
  4037. val = mtu + ETH_HLEN + ETH_FCS_LEN;
  4038. if (val > (MAX_ETHERNET_PACKET_SIZE + 4))
  4039. val |= BNX2_EMAC_RX_MTU_SIZE_JUMBO_ENA;
  4040. REG_WR(bp, BNX2_EMAC_RX_MTU_SIZE, val);
  4041. if (mtu < 1500)
  4042. mtu = 1500;
  4043. bnx2_reg_wr_ind(bp, BNX2_RBUF_CONFIG, BNX2_RBUF_CONFIG_VAL(mtu));
  4044. bnx2_reg_wr_ind(bp, BNX2_RBUF_CONFIG2, BNX2_RBUF_CONFIG2_VAL(mtu));
  4045. bnx2_reg_wr_ind(bp, BNX2_RBUF_CONFIG3, BNX2_RBUF_CONFIG3_VAL(mtu));
  4046. memset(bp->bnx2_napi[0].status_blk.msi, 0, bp->status_stats_size);
  4047. for (i = 0; i < BNX2_MAX_MSIX_VEC; i++)
  4048. bp->bnx2_napi[i].last_status_idx = 0;
  4049. bp->idle_chk_status_idx = 0xffff;
  4050. bp->rx_mode = BNX2_EMAC_RX_MODE_SORT_MODE;
  4051. /* Set up how to generate a link change interrupt. */
  4052. REG_WR(bp, BNX2_EMAC_ATTENTION_ENA, BNX2_EMAC_ATTENTION_ENA_LINK);
  4053. REG_WR(bp, BNX2_HC_STATUS_ADDR_L,
  4054. (u64) bp->status_blk_mapping & 0xffffffff);
  4055. REG_WR(bp, BNX2_HC_STATUS_ADDR_H, (u64) bp->status_blk_mapping >> 32);
  4056. REG_WR(bp, BNX2_HC_STATISTICS_ADDR_L,
  4057. (u64) bp->stats_blk_mapping & 0xffffffff);
  4058. REG_WR(bp, BNX2_HC_STATISTICS_ADDR_H,
  4059. (u64) bp->stats_blk_mapping >> 32);
  4060. REG_WR(bp, BNX2_HC_TX_QUICK_CONS_TRIP,
  4061. (bp->tx_quick_cons_trip_int << 16) | bp->tx_quick_cons_trip);
  4062. REG_WR(bp, BNX2_HC_RX_QUICK_CONS_TRIP,
  4063. (bp->rx_quick_cons_trip_int << 16) | bp->rx_quick_cons_trip);
  4064. REG_WR(bp, BNX2_HC_COMP_PROD_TRIP,
  4065. (bp->comp_prod_trip_int << 16) | bp->comp_prod_trip);
  4066. REG_WR(bp, BNX2_HC_TX_TICKS, (bp->tx_ticks_int << 16) | bp->tx_ticks);
  4067. REG_WR(bp, BNX2_HC_RX_TICKS, (bp->rx_ticks_int << 16) | bp->rx_ticks);
  4068. REG_WR(bp, BNX2_HC_COM_TICKS,
  4069. (bp->com_ticks_int << 16) | bp->com_ticks);
  4070. REG_WR(bp, BNX2_HC_CMD_TICKS,
  4071. (bp->cmd_ticks_int << 16) | bp->cmd_ticks);
  4072. if (bp->flags & BNX2_FLAG_BROKEN_STATS)
  4073. REG_WR(bp, BNX2_HC_STATS_TICKS, 0);
  4074. else
  4075. REG_WR(bp, BNX2_HC_STATS_TICKS, bp->stats_ticks);
  4076. REG_WR(bp, BNX2_HC_STAT_COLLECT_TICKS, 0xbb8); /* 3ms */
  4077. if (CHIP_ID(bp) == CHIP_ID_5706_A1)
  4078. val = BNX2_HC_CONFIG_COLLECT_STATS;
  4079. else {
  4080. val = BNX2_HC_CONFIG_RX_TMR_MODE | BNX2_HC_CONFIG_TX_TMR_MODE |
  4081. BNX2_HC_CONFIG_COLLECT_STATS;
  4082. }
  4083. if (bp->flags & BNX2_FLAG_USING_MSIX) {
  4084. REG_WR(bp, BNX2_HC_MSIX_BIT_VECTOR,
  4085. BNX2_HC_MSIX_BIT_VECTOR_VAL);
  4086. val |= BNX2_HC_CONFIG_SB_ADDR_INC_128B;
  4087. }
  4088. if (bp->flags & BNX2_FLAG_ONE_SHOT_MSI)
  4089. val |= BNX2_HC_CONFIG_ONE_SHOT | BNX2_HC_CONFIG_USE_INT_PARAM;
  4090. REG_WR(bp, BNX2_HC_CONFIG, val);
  4091. if (bp->rx_ticks < 25)
  4092. bnx2_reg_wr_ind(bp, BNX2_FW_RX_LOW_LATENCY, 1);
  4093. else
  4094. bnx2_reg_wr_ind(bp, BNX2_FW_RX_LOW_LATENCY, 0);
  4095. for (i = 1; i < bp->irq_nvecs; i++) {
  4096. u32 base = ((i - 1) * BNX2_HC_SB_CONFIG_SIZE) +
  4097. BNX2_HC_SB_CONFIG_1;
  4098. REG_WR(bp, base,
  4099. BNX2_HC_SB_CONFIG_1_TX_TMR_MODE |
  4100. BNX2_HC_SB_CONFIG_1_RX_TMR_MODE |
  4101. BNX2_HC_SB_CONFIG_1_ONE_SHOT);
  4102. REG_WR(bp, base + BNX2_HC_TX_QUICK_CONS_TRIP_OFF,
  4103. (bp->tx_quick_cons_trip_int << 16) |
  4104. bp->tx_quick_cons_trip);
  4105. REG_WR(bp, base + BNX2_HC_TX_TICKS_OFF,
  4106. (bp->tx_ticks_int << 16) | bp->tx_ticks);
  4107. REG_WR(bp, base + BNX2_HC_RX_QUICK_CONS_TRIP_OFF,
  4108. (bp->rx_quick_cons_trip_int << 16) |
  4109. bp->rx_quick_cons_trip);
  4110. REG_WR(bp, base + BNX2_HC_RX_TICKS_OFF,
  4111. (bp->rx_ticks_int << 16) | bp->rx_ticks);
  4112. }
  4113. /* Clear internal stats counters. */
  4114. REG_WR(bp, BNX2_HC_COMMAND, BNX2_HC_COMMAND_CLR_STAT_NOW);
  4115. REG_WR(bp, BNX2_HC_ATTN_BITS_ENABLE, STATUS_ATTN_EVENTS);
  4116. /* Initialize the receive filter. */
  4117. bnx2_set_rx_mode(bp->dev);
  4118. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  4119. val = REG_RD(bp, BNX2_MISC_NEW_CORE_CTL);
  4120. val |= BNX2_MISC_NEW_CORE_CTL_DMA_ENABLE;
  4121. REG_WR(bp, BNX2_MISC_NEW_CORE_CTL, val);
  4122. }
  4123. rc = bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT2 | BNX2_DRV_MSG_CODE_RESET,
  4124. 1, 0);
  4125. REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS, BNX2_MISC_ENABLE_DEFAULT);
  4126. REG_RD(bp, BNX2_MISC_ENABLE_SET_BITS);
  4127. udelay(20);
  4128. bp->hc_cmd = REG_RD(bp, BNX2_HC_COMMAND);
  4129. return rc;
  4130. }
  4131. static void
  4132. bnx2_clear_ring_states(struct bnx2 *bp)
  4133. {
  4134. struct bnx2_napi *bnapi;
  4135. struct bnx2_tx_ring_info *txr;
  4136. struct bnx2_rx_ring_info *rxr;
  4137. int i;
  4138. for (i = 0; i < BNX2_MAX_MSIX_VEC; i++) {
  4139. bnapi = &bp->bnx2_napi[i];
  4140. txr = &bnapi->tx_ring;
  4141. rxr = &bnapi->rx_ring;
  4142. txr->tx_cons = 0;
  4143. txr->hw_tx_cons = 0;
  4144. rxr->rx_prod_bseq = 0;
  4145. rxr->rx_prod = 0;
  4146. rxr->rx_cons = 0;
  4147. rxr->rx_pg_prod = 0;
  4148. rxr->rx_pg_cons = 0;
  4149. }
  4150. }
  4151. static void
  4152. bnx2_init_tx_context(struct bnx2 *bp, u32 cid, struct bnx2_tx_ring_info *txr)
  4153. {
  4154. u32 val, offset0, offset1, offset2, offset3;
  4155. u32 cid_addr = GET_CID_ADDR(cid);
  4156. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  4157. offset0 = BNX2_L2CTX_TYPE_XI;
  4158. offset1 = BNX2_L2CTX_CMD_TYPE_XI;
  4159. offset2 = BNX2_L2CTX_TBDR_BHADDR_HI_XI;
  4160. offset3 = BNX2_L2CTX_TBDR_BHADDR_LO_XI;
  4161. } else {
  4162. offset0 = BNX2_L2CTX_TYPE;
  4163. offset1 = BNX2_L2CTX_CMD_TYPE;
  4164. offset2 = BNX2_L2CTX_TBDR_BHADDR_HI;
  4165. offset3 = BNX2_L2CTX_TBDR_BHADDR_LO;
  4166. }
  4167. val = BNX2_L2CTX_TYPE_TYPE_L2 | BNX2_L2CTX_TYPE_SIZE_L2;
  4168. bnx2_ctx_wr(bp, cid_addr, offset0, val);
  4169. val = BNX2_L2CTX_CMD_TYPE_TYPE_L2 | (8 << 16);
  4170. bnx2_ctx_wr(bp, cid_addr, offset1, val);
  4171. val = (u64) txr->tx_desc_mapping >> 32;
  4172. bnx2_ctx_wr(bp, cid_addr, offset2, val);
  4173. val = (u64) txr->tx_desc_mapping & 0xffffffff;
  4174. bnx2_ctx_wr(bp, cid_addr, offset3, val);
  4175. }
  4176. static void
  4177. bnx2_init_tx_ring(struct bnx2 *bp, int ring_num)
  4178. {
  4179. struct tx_bd *txbd;
  4180. u32 cid = TX_CID;
  4181. struct bnx2_napi *bnapi;
  4182. struct bnx2_tx_ring_info *txr;
  4183. bnapi = &bp->bnx2_napi[ring_num];
  4184. txr = &bnapi->tx_ring;
  4185. if (ring_num == 0)
  4186. cid = TX_CID;
  4187. else
  4188. cid = TX_TSS_CID + ring_num - 1;
  4189. bp->tx_wake_thresh = bp->tx_ring_size / 2;
  4190. txbd = &txr->tx_desc_ring[MAX_TX_DESC_CNT];
  4191. txbd->tx_bd_haddr_hi = (u64) txr->tx_desc_mapping >> 32;
  4192. txbd->tx_bd_haddr_lo = (u64) txr->tx_desc_mapping & 0xffffffff;
  4193. txr->tx_prod = 0;
  4194. txr->tx_prod_bseq = 0;
  4195. txr->tx_bidx_addr = MB_GET_CID_ADDR(cid) + BNX2_L2CTX_TX_HOST_BIDX;
  4196. txr->tx_bseq_addr = MB_GET_CID_ADDR(cid) + BNX2_L2CTX_TX_HOST_BSEQ;
  4197. bnx2_init_tx_context(bp, cid, txr);
  4198. }
  4199. static void
  4200. bnx2_init_rxbd_rings(struct rx_bd *rx_ring[], dma_addr_t dma[], u32 buf_size,
  4201. int num_rings)
  4202. {
  4203. int i;
  4204. struct rx_bd *rxbd;
  4205. for (i = 0; i < num_rings; i++) {
  4206. int j;
  4207. rxbd = &rx_ring[i][0];
  4208. for (j = 0; j < MAX_RX_DESC_CNT; j++, rxbd++) {
  4209. rxbd->rx_bd_len = buf_size;
  4210. rxbd->rx_bd_flags = RX_BD_FLAGS_START | RX_BD_FLAGS_END;
  4211. }
  4212. if (i == (num_rings - 1))
  4213. j = 0;
  4214. else
  4215. j = i + 1;
  4216. rxbd->rx_bd_haddr_hi = (u64) dma[j] >> 32;
  4217. rxbd->rx_bd_haddr_lo = (u64) dma[j] & 0xffffffff;
  4218. }
  4219. }
  4220. static void
  4221. bnx2_init_rx_ring(struct bnx2 *bp, int ring_num)
  4222. {
  4223. int i;
  4224. u16 prod, ring_prod;
  4225. u32 cid, rx_cid_addr, val;
  4226. struct bnx2_napi *bnapi = &bp->bnx2_napi[ring_num];
  4227. struct bnx2_rx_ring_info *rxr = &bnapi->rx_ring;
  4228. if (ring_num == 0)
  4229. cid = RX_CID;
  4230. else
  4231. cid = RX_RSS_CID + ring_num - 1;
  4232. rx_cid_addr = GET_CID_ADDR(cid);
  4233. bnx2_init_rxbd_rings(rxr->rx_desc_ring, rxr->rx_desc_mapping,
  4234. bp->rx_buf_use_size, bp->rx_max_ring);
  4235. bnx2_init_rx_context(bp, cid);
  4236. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  4237. val = REG_RD(bp, BNX2_MQ_MAP_L2_5);
  4238. REG_WR(bp, BNX2_MQ_MAP_L2_5, val | BNX2_MQ_MAP_L2_5_ARM);
  4239. }
  4240. bnx2_ctx_wr(bp, rx_cid_addr, BNX2_L2CTX_PG_BUF_SIZE, 0);
  4241. if (bp->rx_pg_ring_size) {
  4242. bnx2_init_rxbd_rings(rxr->rx_pg_desc_ring,
  4243. rxr->rx_pg_desc_mapping,
  4244. PAGE_SIZE, bp->rx_max_pg_ring);
  4245. val = (bp->rx_buf_use_size << 16) | PAGE_SIZE;
  4246. bnx2_ctx_wr(bp, rx_cid_addr, BNX2_L2CTX_PG_BUF_SIZE, val);
  4247. bnx2_ctx_wr(bp, rx_cid_addr, BNX2_L2CTX_RBDC_KEY,
  4248. BNX2_L2CTX_RBDC_JUMBO_KEY - ring_num);
  4249. val = (u64) rxr->rx_pg_desc_mapping[0] >> 32;
  4250. bnx2_ctx_wr(bp, rx_cid_addr, BNX2_L2CTX_NX_PG_BDHADDR_HI, val);
  4251. val = (u64) rxr->rx_pg_desc_mapping[0] & 0xffffffff;
  4252. bnx2_ctx_wr(bp, rx_cid_addr, BNX2_L2CTX_NX_PG_BDHADDR_LO, val);
  4253. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  4254. REG_WR(bp, BNX2_MQ_MAP_L2_3, BNX2_MQ_MAP_L2_3_DEFAULT);
  4255. }
  4256. val = (u64) rxr->rx_desc_mapping[0] >> 32;
  4257. bnx2_ctx_wr(bp, rx_cid_addr, BNX2_L2CTX_NX_BDHADDR_HI, val);
  4258. val = (u64) rxr->rx_desc_mapping[0] & 0xffffffff;
  4259. bnx2_ctx_wr(bp, rx_cid_addr, BNX2_L2CTX_NX_BDHADDR_LO, val);
  4260. ring_prod = prod = rxr->rx_pg_prod;
  4261. for (i = 0; i < bp->rx_pg_ring_size; i++) {
  4262. if (bnx2_alloc_rx_page(bp, rxr, ring_prod, GFP_KERNEL) < 0) {
  4263. netdev_warn(bp->dev, "init'ed rx page ring %d with %d/%d pages only\n",
  4264. ring_num, i, bp->rx_pg_ring_size);
  4265. break;
  4266. }
  4267. prod = NEXT_RX_BD(prod);
  4268. ring_prod = RX_PG_RING_IDX(prod);
  4269. }
  4270. rxr->rx_pg_prod = prod;
  4271. ring_prod = prod = rxr->rx_prod;
  4272. for (i = 0; i < bp->rx_ring_size; i++) {
  4273. if (bnx2_alloc_rx_skb(bp, rxr, ring_prod, GFP_KERNEL) < 0) {
  4274. netdev_warn(bp->dev, "init'ed rx ring %d with %d/%d skbs only\n",
  4275. ring_num, i, bp->rx_ring_size);
  4276. break;
  4277. }
  4278. prod = NEXT_RX_BD(prod);
  4279. ring_prod = RX_RING_IDX(prod);
  4280. }
  4281. rxr->rx_prod = prod;
  4282. rxr->rx_bidx_addr = MB_GET_CID_ADDR(cid) + BNX2_L2CTX_HOST_BDIDX;
  4283. rxr->rx_bseq_addr = MB_GET_CID_ADDR(cid) + BNX2_L2CTX_HOST_BSEQ;
  4284. rxr->rx_pg_bidx_addr = MB_GET_CID_ADDR(cid) + BNX2_L2CTX_HOST_PG_BDIDX;
  4285. REG_WR16(bp, rxr->rx_pg_bidx_addr, rxr->rx_pg_prod);
  4286. REG_WR16(bp, rxr->rx_bidx_addr, prod);
  4287. REG_WR(bp, rxr->rx_bseq_addr, rxr->rx_prod_bseq);
  4288. }
  4289. static void
  4290. bnx2_init_all_rings(struct bnx2 *bp)
  4291. {
  4292. int i;
  4293. u32 val;
  4294. bnx2_clear_ring_states(bp);
  4295. REG_WR(bp, BNX2_TSCH_TSS_CFG, 0);
  4296. for (i = 0; i < bp->num_tx_rings; i++)
  4297. bnx2_init_tx_ring(bp, i);
  4298. if (bp->num_tx_rings > 1)
  4299. REG_WR(bp, BNX2_TSCH_TSS_CFG, ((bp->num_tx_rings - 1) << 24) |
  4300. (TX_TSS_CID << 7));
  4301. REG_WR(bp, BNX2_RLUP_RSS_CONFIG, 0);
  4302. bnx2_reg_wr_ind(bp, BNX2_RXP_SCRATCH_RSS_TBL_SZ, 0);
  4303. for (i = 0; i < bp->num_rx_rings; i++)
  4304. bnx2_init_rx_ring(bp, i);
  4305. if (bp->num_rx_rings > 1) {
  4306. u32 tbl_32 = 0;
  4307. for (i = 0; i < BNX2_RXP_SCRATCH_RSS_TBL_MAX_ENTRIES; i++) {
  4308. int shift = (i % 8) << 2;
  4309. tbl_32 |= (i % (bp->num_rx_rings - 1)) << shift;
  4310. if ((i % 8) == 7) {
  4311. REG_WR(bp, BNX2_RLUP_RSS_DATA, tbl_32);
  4312. REG_WR(bp, BNX2_RLUP_RSS_COMMAND, (i >> 3) |
  4313. BNX2_RLUP_RSS_COMMAND_RSS_WRITE_MASK |
  4314. BNX2_RLUP_RSS_COMMAND_WRITE |
  4315. BNX2_RLUP_RSS_COMMAND_HASH_MASK);
  4316. tbl_32 = 0;
  4317. }
  4318. }
  4319. val = BNX2_RLUP_RSS_CONFIG_IPV4_RSS_TYPE_ALL_XI |
  4320. BNX2_RLUP_RSS_CONFIG_IPV6_RSS_TYPE_ALL_XI;
  4321. REG_WR(bp, BNX2_RLUP_RSS_CONFIG, val);
  4322. }
  4323. }
  4324. static u32 bnx2_find_max_ring(u32 ring_size, u32 max_size)
  4325. {
  4326. u32 max, num_rings = 1;
  4327. while (ring_size > MAX_RX_DESC_CNT) {
  4328. ring_size -= MAX_RX_DESC_CNT;
  4329. num_rings++;
  4330. }
  4331. /* round to next power of 2 */
  4332. max = max_size;
  4333. while ((max & num_rings) == 0)
  4334. max >>= 1;
  4335. if (num_rings != max)
  4336. max <<= 1;
  4337. return max;
  4338. }
  4339. static void
  4340. bnx2_set_rx_ring_size(struct bnx2 *bp, u32 size)
  4341. {
  4342. u32 rx_size, rx_space, jumbo_size;
  4343. /* 8 for CRC and VLAN */
  4344. rx_size = bp->dev->mtu + ETH_HLEN + BNX2_RX_OFFSET + 8;
  4345. rx_space = SKB_DATA_ALIGN(rx_size + BNX2_RX_ALIGN) + NET_SKB_PAD +
  4346. sizeof(struct skb_shared_info);
  4347. bp->rx_copy_thresh = BNX2_RX_COPY_THRESH;
  4348. bp->rx_pg_ring_size = 0;
  4349. bp->rx_max_pg_ring = 0;
  4350. bp->rx_max_pg_ring_idx = 0;
  4351. if ((rx_space > PAGE_SIZE) && !(bp->flags & BNX2_FLAG_JUMBO_BROKEN)) {
  4352. int pages = PAGE_ALIGN(bp->dev->mtu - 40) >> PAGE_SHIFT;
  4353. jumbo_size = size * pages;
  4354. if (jumbo_size > MAX_TOTAL_RX_PG_DESC_CNT)
  4355. jumbo_size = MAX_TOTAL_RX_PG_DESC_CNT;
  4356. bp->rx_pg_ring_size = jumbo_size;
  4357. bp->rx_max_pg_ring = bnx2_find_max_ring(jumbo_size,
  4358. MAX_RX_PG_RINGS);
  4359. bp->rx_max_pg_ring_idx = (bp->rx_max_pg_ring * RX_DESC_CNT) - 1;
  4360. rx_size = BNX2_RX_COPY_THRESH + BNX2_RX_OFFSET;
  4361. bp->rx_copy_thresh = 0;
  4362. }
  4363. bp->rx_buf_use_size = rx_size;
  4364. /* hw alignment */
  4365. bp->rx_buf_size = bp->rx_buf_use_size + BNX2_RX_ALIGN;
  4366. bp->rx_jumbo_thresh = rx_size - BNX2_RX_OFFSET;
  4367. bp->rx_ring_size = size;
  4368. bp->rx_max_ring = bnx2_find_max_ring(size, MAX_RX_RINGS);
  4369. bp->rx_max_ring_idx = (bp->rx_max_ring * RX_DESC_CNT) - 1;
  4370. }
  4371. static void
  4372. bnx2_free_tx_skbs(struct bnx2 *bp)
  4373. {
  4374. int i;
  4375. for (i = 0; i < bp->num_tx_rings; i++) {
  4376. struct bnx2_napi *bnapi = &bp->bnx2_napi[i];
  4377. struct bnx2_tx_ring_info *txr = &bnapi->tx_ring;
  4378. int j;
  4379. if (txr->tx_buf_ring == NULL)
  4380. continue;
  4381. for (j = 0; j < TX_DESC_CNT; ) {
  4382. struct sw_tx_bd *tx_buf = &txr->tx_buf_ring[j];
  4383. struct sk_buff *skb = tx_buf->skb;
  4384. int k, last;
  4385. if (skb == NULL) {
  4386. j++;
  4387. continue;
  4388. }
  4389. dma_unmap_single(&bp->pdev->dev,
  4390. dma_unmap_addr(tx_buf, mapping),
  4391. skb_headlen(skb),
  4392. PCI_DMA_TODEVICE);
  4393. tx_buf->skb = NULL;
  4394. last = tx_buf->nr_frags;
  4395. j++;
  4396. for (k = 0; k < last; k++, j++) {
  4397. tx_buf = &txr->tx_buf_ring[TX_RING_IDX(j)];
  4398. dma_unmap_page(&bp->pdev->dev,
  4399. dma_unmap_addr(tx_buf, mapping),
  4400. skb_shinfo(skb)->frags[k].size,
  4401. PCI_DMA_TODEVICE);
  4402. }
  4403. dev_kfree_skb(skb);
  4404. }
  4405. }
  4406. }
  4407. static void
  4408. bnx2_free_rx_skbs(struct bnx2 *bp)
  4409. {
  4410. int i;
  4411. for (i = 0; i < bp->num_rx_rings; i++) {
  4412. struct bnx2_napi *bnapi = &bp->bnx2_napi[i];
  4413. struct bnx2_rx_ring_info *rxr = &bnapi->rx_ring;
  4414. int j;
  4415. if (rxr->rx_buf_ring == NULL)
  4416. return;
  4417. for (j = 0; j < bp->rx_max_ring_idx; j++) {
  4418. struct sw_bd *rx_buf = &rxr->rx_buf_ring[j];
  4419. struct sk_buff *skb = rx_buf->skb;
  4420. if (skb == NULL)
  4421. continue;
  4422. dma_unmap_single(&bp->pdev->dev,
  4423. dma_unmap_addr(rx_buf, mapping),
  4424. bp->rx_buf_use_size,
  4425. PCI_DMA_FROMDEVICE);
  4426. rx_buf->skb = NULL;
  4427. dev_kfree_skb(skb);
  4428. }
  4429. for (j = 0; j < bp->rx_max_pg_ring_idx; j++)
  4430. bnx2_free_rx_page(bp, rxr, j);
  4431. }
  4432. }
  4433. static void
  4434. bnx2_free_skbs(struct bnx2 *bp)
  4435. {
  4436. bnx2_free_tx_skbs(bp);
  4437. bnx2_free_rx_skbs(bp);
  4438. }
  4439. static int
  4440. bnx2_reset_nic(struct bnx2 *bp, u32 reset_code)
  4441. {
  4442. int rc;
  4443. rc = bnx2_reset_chip(bp, reset_code);
  4444. bnx2_free_skbs(bp);
  4445. if (rc)
  4446. return rc;
  4447. if ((rc = bnx2_init_chip(bp)) != 0)
  4448. return rc;
  4449. bnx2_init_all_rings(bp);
  4450. return 0;
  4451. }
  4452. static int
  4453. bnx2_init_nic(struct bnx2 *bp, int reset_phy)
  4454. {
  4455. int rc;
  4456. if ((rc = bnx2_reset_nic(bp, BNX2_DRV_MSG_CODE_RESET)) != 0)
  4457. return rc;
  4458. spin_lock_bh(&bp->phy_lock);
  4459. bnx2_init_phy(bp, reset_phy);
  4460. bnx2_set_link(bp);
  4461. if (bp->phy_flags & BNX2_PHY_FLAG_REMOTE_PHY_CAP)
  4462. bnx2_remote_phy_event(bp);
  4463. spin_unlock_bh(&bp->phy_lock);
  4464. return 0;
  4465. }
  4466. static int
  4467. bnx2_shutdown_chip(struct bnx2 *bp)
  4468. {
  4469. u32 reset_code;
  4470. if (bp->flags & BNX2_FLAG_NO_WOL)
  4471. reset_code = BNX2_DRV_MSG_CODE_UNLOAD_LNK_DN;
  4472. else if (bp->wol)
  4473. reset_code = BNX2_DRV_MSG_CODE_SUSPEND_WOL;
  4474. else
  4475. reset_code = BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL;
  4476. return bnx2_reset_chip(bp, reset_code);
  4477. }
  4478. static int
  4479. bnx2_test_registers(struct bnx2 *bp)
  4480. {
  4481. int ret;
  4482. int i, is_5709;
  4483. static const struct {
  4484. u16 offset;
  4485. u16 flags;
  4486. #define BNX2_FL_NOT_5709 1
  4487. u32 rw_mask;
  4488. u32 ro_mask;
  4489. } reg_tbl[] = {
  4490. { 0x006c, 0, 0x00000000, 0x0000003f },
  4491. { 0x0090, 0, 0xffffffff, 0x00000000 },
  4492. { 0x0094, 0, 0x00000000, 0x00000000 },
  4493. { 0x0404, BNX2_FL_NOT_5709, 0x00003f00, 0x00000000 },
  4494. { 0x0418, BNX2_FL_NOT_5709, 0x00000000, 0xffffffff },
  4495. { 0x041c, BNX2_FL_NOT_5709, 0x00000000, 0xffffffff },
  4496. { 0x0420, BNX2_FL_NOT_5709, 0x00000000, 0x80ffffff },
  4497. { 0x0424, BNX2_FL_NOT_5709, 0x00000000, 0x00000000 },
  4498. { 0x0428, BNX2_FL_NOT_5709, 0x00000000, 0x00000001 },
  4499. { 0x0450, BNX2_FL_NOT_5709, 0x00000000, 0x0000ffff },
  4500. { 0x0454, BNX2_FL_NOT_5709, 0x00000000, 0xffffffff },
  4501. { 0x0458, BNX2_FL_NOT_5709, 0x00000000, 0xffffffff },
  4502. { 0x0808, BNX2_FL_NOT_5709, 0x00000000, 0xffffffff },
  4503. { 0x0854, BNX2_FL_NOT_5709, 0x00000000, 0xffffffff },
  4504. { 0x0868, BNX2_FL_NOT_5709, 0x00000000, 0x77777777 },
  4505. { 0x086c, BNX2_FL_NOT_5709, 0x00000000, 0x77777777 },
  4506. { 0x0870, BNX2_FL_NOT_5709, 0x00000000, 0x77777777 },
  4507. { 0x0874, BNX2_FL_NOT_5709, 0x00000000, 0x77777777 },
  4508. { 0x0c00, BNX2_FL_NOT_5709, 0x00000000, 0x00000001 },
  4509. { 0x0c04, BNX2_FL_NOT_5709, 0x00000000, 0x03ff0001 },
  4510. { 0x0c08, BNX2_FL_NOT_5709, 0x0f0ff073, 0x00000000 },
  4511. { 0x1000, 0, 0x00000000, 0x00000001 },
  4512. { 0x1004, BNX2_FL_NOT_5709, 0x00000000, 0x000f0001 },
  4513. { 0x1408, 0, 0x01c00800, 0x00000000 },
  4514. { 0x149c, 0, 0x8000ffff, 0x00000000 },
  4515. { 0x14a8, 0, 0x00000000, 0x000001ff },
  4516. { 0x14ac, 0, 0x0fffffff, 0x10000000 },
  4517. { 0x14b0, 0, 0x00000002, 0x00000001 },
  4518. { 0x14b8, 0, 0x00000000, 0x00000000 },
  4519. { 0x14c0, 0, 0x00000000, 0x00000009 },
  4520. { 0x14c4, 0, 0x00003fff, 0x00000000 },
  4521. { 0x14cc, 0, 0x00000000, 0x00000001 },
  4522. { 0x14d0, 0, 0xffffffff, 0x00000000 },
  4523. { 0x1800, 0, 0x00000000, 0x00000001 },
  4524. { 0x1804, 0, 0x00000000, 0x00000003 },
  4525. { 0x2800, 0, 0x00000000, 0x00000001 },
  4526. { 0x2804, 0, 0x00000000, 0x00003f01 },
  4527. { 0x2808, 0, 0x0f3f3f03, 0x00000000 },
  4528. { 0x2810, 0, 0xffff0000, 0x00000000 },
  4529. { 0x2814, 0, 0xffff0000, 0x00000000 },
  4530. { 0x2818, 0, 0xffff0000, 0x00000000 },
  4531. { 0x281c, 0, 0xffff0000, 0x00000000 },
  4532. { 0x2834, 0, 0xffffffff, 0x00000000 },
  4533. { 0x2840, 0, 0x00000000, 0xffffffff },
  4534. { 0x2844, 0, 0x00000000, 0xffffffff },
  4535. { 0x2848, 0, 0xffffffff, 0x00000000 },
  4536. { 0x284c, 0, 0xf800f800, 0x07ff07ff },
  4537. { 0x2c00, 0, 0x00000000, 0x00000011 },
  4538. { 0x2c04, 0, 0x00000000, 0x00030007 },
  4539. { 0x3c00, 0, 0x00000000, 0x00000001 },
  4540. { 0x3c04, 0, 0x00000000, 0x00070000 },
  4541. { 0x3c08, 0, 0x00007f71, 0x07f00000 },
  4542. { 0x3c0c, 0, 0x1f3ffffc, 0x00000000 },
  4543. { 0x3c10, 0, 0xffffffff, 0x00000000 },
  4544. { 0x3c14, 0, 0x00000000, 0xffffffff },
  4545. { 0x3c18, 0, 0x00000000, 0xffffffff },
  4546. { 0x3c1c, 0, 0xfffff000, 0x00000000 },
  4547. { 0x3c20, 0, 0xffffff00, 0x00000000 },
  4548. { 0x5004, 0, 0x00000000, 0x0000007f },
  4549. { 0x5008, 0, 0x0f0007ff, 0x00000000 },
  4550. { 0x5c00, 0, 0x00000000, 0x00000001 },
  4551. { 0x5c04, 0, 0x00000000, 0x0003000f },
  4552. { 0x5c08, 0, 0x00000003, 0x00000000 },
  4553. { 0x5c0c, 0, 0x0000fff8, 0x00000000 },
  4554. { 0x5c10, 0, 0x00000000, 0xffffffff },
  4555. { 0x5c80, 0, 0x00000000, 0x0f7113f1 },
  4556. { 0x5c84, 0, 0x00000000, 0x0000f333 },
  4557. { 0x5c88, 0, 0x00000000, 0x00077373 },
  4558. { 0x5c8c, 0, 0x00000000, 0x0007f737 },
  4559. { 0x6808, 0, 0x0000ff7f, 0x00000000 },
  4560. { 0x680c, 0, 0xffffffff, 0x00000000 },
  4561. { 0x6810, 0, 0xffffffff, 0x00000000 },
  4562. { 0x6814, 0, 0xffffffff, 0x00000000 },
  4563. { 0x6818, 0, 0xffffffff, 0x00000000 },
  4564. { 0x681c, 0, 0xffffffff, 0x00000000 },
  4565. { 0x6820, 0, 0x00ff00ff, 0x00000000 },
  4566. { 0x6824, 0, 0x00ff00ff, 0x00000000 },
  4567. { 0x6828, 0, 0x00ff00ff, 0x00000000 },
  4568. { 0x682c, 0, 0x03ff03ff, 0x00000000 },
  4569. { 0x6830, 0, 0x03ff03ff, 0x00000000 },
  4570. { 0x6834, 0, 0x03ff03ff, 0x00000000 },
  4571. { 0x6838, 0, 0x03ff03ff, 0x00000000 },
  4572. { 0x683c, 0, 0x0000ffff, 0x00000000 },
  4573. { 0x6840, 0, 0x00000ff0, 0x00000000 },
  4574. { 0x6844, 0, 0x00ffff00, 0x00000000 },
  4575. { 0x684c, 0, 0xffffffff, 0x00000000 },
  4576. { 0x6850, 0, 0x7f7f7f7f, 0x00000000 },
  4577. { 0x6854, 0, 0x7f7f7f7f, 0x00000000 },
  4578. { 0x6858, 0, 0x7f7f7f7f, 0x00000000 },
  4579. { 0x685c, 0, 0x7f7f7f7f, 0x00000000 },
  4580. { 0x6908, 0, 0x00000000, 0x0001ff0f },
  4581. { 0x690c, 0, 0x00000000, 0x0ffe00f0 },
  4582. { 0xffff, 0, 0x00000000, 0x00000000 },
  4583. };
  4584. ret = 0;
  4585. is_5709 = 0;
  4586. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  4587. is_5709 = 1;
  4588. for (i = 0; reg_tbl[i].offset != 0xffff; i++) {
  4589. u32 offset, rw_mask, ro_mask, save_val, val;
  4590. u16 flags = reg_tbl[i].flags;
  4591. if (is_5709 && (flags & BNX2_FL_NOT_5709))
  4592. continue;
  4593. offset = (u32) reg_tbl[i].offset;
  4594. rw_mask = reg_tbl[i].rw_mask;
  4595. ro_mask = reg_tbl[i].ro_mask;
  4596. save_val = readl(bp->regview + offset);
  4597. writel(0, bp->regview + offset);
  4598. val = readl(bp->regview + offset);
  4599. if ((val & rw_mask) != 0) {
  4600. goto reg_test_err;
  4601. }
  4602. if ((val & ro_mask) != (save_val & ro_mask)) {
  4603. goto reg_test_err;
  4604. }
  4605. writel(0xffffffff, bp->regview + offset);
  4606. val = readl(bp->regview + offset);
  4607. if ((val & rw_mask) != rw_mask) {
  4608. goto reg_test_err;
  4609. }
  4610. if ((val & ro_mask) != (save_val & ro_mask)) {
  4611. goto reg_test_err;
  4612. }
  4613. writel(save_val, bp->regview + offset);
  4614. continue;
  4615. reg_test_err:
  4616. writel(save_val, bp->regview + offset);
  4617. ret = -ENODEV;
  4618. break;
  4619. }
  4620. return ret;
  4621. }
  4622. static int
  4623. bnx2_do_mem_test(struct bnx2 *bp, u32 start, u32 size)
  4624. {
  4625. static const u32 test_pattern[] = { 0x00000000, 0xffffffff, 0x55555555,
  4626. 0xaaaaaaaa , 0xaa55aa55, 0x55aa55aa };
  4627. int i;
  4628. for (i = 0; i < sizeof(test_pattern) / 4; i++) {
  4629. u32 offset;
  4630. for (offset = 0; offset < size; offset += 4) {
  4631. bnx2_reg_wr_ind(bp, start + offset, test_pattern[i]);
  4632. if (bnx2_reg_rd_ind(bp, start + offset) !=
  4633. test_pattern[i]) {
  4634. return -ENODEV;
  4635. }
  4636. }
  4637. }
  4638. return 0;
  4639. }
  4640. static int
  4641. bnx2_test_memory(struct bnx2 *bp)
  4642. {
  4643. int ret = 0;
  4644. int i;
  4645. static struct mem_entry {
  4646. u32 offset;
  4647. u32 len;
  4648. } mem_tbl_5706[] = {
  4649. { 0x60000, 0x4000 },
  4650. { 0xa0000, 0x3000 },
  4651. { 0xe0000, 0x4000 },
  4652. { 0x120000, 0x4000 },
  4653. { 0x1a0000, 0x4000 },
  4654. { 0x160000, 0x4000 },
  4655. { 0xffffffff, 0 },
  4656. },
  4657. mem_tbl_5709[] = {
  4658. { 0x60000, 0x4000 },
  4659. { 0xa0000, 0x3000 },
  4660. { 0xe0000, 0x4000 },
  4661. { 0x120000, 0x4000 },
  4662. { 0x1a0000, 0x4000 },
  4663. { 0xffffffff, 0 },
  4664. };
  4665. struct mem_entry *mem_tbl;
  4666. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  4667. mem_tbl = mem_tbl_5709;
  4668. else
  4669. mem_tbl = mem_tbl_5706;
  4670. for (i = 0; mem_tbl[i].offset != 0xffffffff; i++) {
  4671. if ((ret = bnx2_do_mem_test(bp, mem_tbl[i].offset,
  4672. mem_tbl[i].len)) != 0) {
  4673. return ret;
  4674. }
  4675. }
  4676. return ret;
  4677. }
  4678. #define BNX2_MAC_LOOPBACK 0
  4679. #define BNX2_PHY_LOOPBACK 1
  4680. static int
  4681. bnx2_run_loopback(struct bnx2 *bp, int loopback_mode)
  4682. {
  4683. unsigned int pkt_size, num_pkts, i;
  4684. struct sk_buff *skb, *rx_skb;
  4685. unsigned char *packet;
  4686. u16 rx_start_idx, rx_idx;
  4687. dma_addr_t map;
  4688. struct tx_bd *txbd;
  4689. struct sw_bd *rx_buf;
  4690. struct l2_fhdr *rx_hdr;
  4691. int ret = -ENODEV;
  4692. struct bnx2_napi *bnapi = &bp->bnx2_napi[0], *tx_napi;
  4693. struct bnx2_tx_ring_info *txr = &bnapi->tx_ring;
  4694. struct bnx2_rx_ring_info *rxr = &bnapi->rx_ring;
  4695. tx_napi = bnapi;
  4696. txr = &tx_napi->tx_ring;
  4697. rxr = &bnapi->rx_ring;
  4698. if (loopback_mode == BNX2_MAC_LOOPBACK) {
  4699. bp->loopback = MAC_LOOPBACK;
  4700. bnx2_set_mac_loopback(bp);
  4701. }
  4702. else if (loopback_mode == BNX2_PHY_LOOPBACK) {
  4703. if (bp->phy_flags & BNX2_PHY_FLAG_REMOTE_PHY_CAP)
  4704. return 0;
  4705. bp->loopback = PHY_LOOPBACK;
  4706. bnx2_set_phy_loopback(bp);
  4707. }
  4708. else
  4709. return -EINVAL;
  4710. pkt_size = min(bp->dev->mtu + ETH_HLEN, bp->rx_jumbo_thresh - 4);
  4711. skb = netdev_alloc_skb(bp->dev, pkt_size);
  4712. if (!skb)
  4713. return -ENOMEM;
  4714. packet = skb_put(skb, pkt_size);
  4715. memcpy(packet, bp->dev->dev_addr, 6);
  4716. memset(packet + 6, 0x0, 8);
  4717. for (i = 14; i < pkt_size; i++)
  4718. packet[i] = (unsigned char) (i & 0xff);
  4719. map = dma_map_single(&bp->pdev->dev, skb->data, pkt_size,
  4720. PCI_DMA_TODEVICE);
  4721. if (dma_mapping_error(&bp->pdev->dev, map)) {
  4722. dev_kfree_skb(skb);
  4723. return -EIO;
  4724. }
  4725. REG_WR(bp, BNX2_HC_COMMAND,
  4726. bp->hc_cmd | BNX2_HC_COMMAND_COAL_NOW_WO_INT);
  4727. REG_RD(bp, BNX2_HC_COMMAND);
  4728. udelay(5);
  4729. rx_start_idx = bnx2_get_hw_rx_cons(bnapi);
  4730. num_pkts = 0;
  4731. txbd = &txr->tx_desc_ring[TX_RING_IDX(txr->tx_prod)];
  4732. txbd->tx_bd_haddr_hi = (u64) map >> 32;
  4733. txbd->tx_bd_haddr_lo = (u64) map & 0xffffffff;
  4734. txbd->tx_bd_mss_nbytes = pkt_size;
  4735. txbd->tx_bd_vlan_tag_flags = TX_BD_FLAGS_START | TX_BD_FLAGS_END;
  4736. num_pkts++;
  4737. txr->tx_prod = NEXT_TX_BD(txr->tx_prod);
  4738. txr->tx_prod_bseq += pkt_size;
  4739. REG_WR16(bp, txr->tx_bidx_addr, txr->tx_prod);
  4740. REG_WR(bp, txr->tx_bseq_addr, txr->tx_prod_bseq);
  4741. udelay(100);
  4742. REG_WR(bp, BNX2_HC_COMMAND,
  4743. bp->hc_cmd | BNX2_HC_COMMAND_COAL_NOW_WO_INT);
  4744. REG_RD(bp, BNX2_HC_COMMAND);
  4745. udelay(5);
  4746. dma_unmap_single(&bp->pdev->dev, map, pkt_size, PCI_DMA_TODEVICE);
  4747. dev_kfree_skb(skb);
  4748. if (bnx2_get_hw_tx_cons(tx_napi) != txr->tx_prod)
  4749. goto loopback_test_done;
  4750. rx_idx = bnx2_get_hw_rx_cons(bnapi);
  4751. if (rx_idx != rx_start_idx + num_pkts) {
  4752. goto loopback_test_done;
  4753. }
  4754. rx_buf = &rxr->rx_buf_ring[rx_start_idx];
  4755. rx_skb = rx_buf->skb;
  4756. rx_hdr = rx_buf->desc;
  4757. skb_reserve(rx_skb, BNX2_RX_OFFSET);
  4758. dma_sync_single_for_cpu(&bp->pdev->dev,
  4759. dma_unmap_addr(rx_buf, mapping),
  4760. bp->rx_buf_size, PCI_DMA_FROMDEVICE);
  4761. if (rx_hdr->l2_fhdr_status &
  4762. (L2_FHDR_ERRORS_BAD_CRC |
  4763. L2_FHDR_ERRORS_PHY_DECODE |
  4764. L2_FHDR_ERRORS_ALIGNMENT |
  4765. L2_FHDR_ERRORS_TOO_SHORT |
  4766. L2_FHDR_ERRORS_GIANT_FRAME)) {
  4767. goto loopback_test_done;
  4768. }
  4769. if ((rx_hdr->l2_fhdr_pkt_len - 4) != pkt_size) {
  4770. goto loopback_test_done;
  4771. }
  4772. for (i = 14; i < pkt_size; i++) {
  4773. if (*(rx_skb->data + i) != (unsigned char) (i & 0xff)) {
  4774. goto loopback_test_done;
  4775. }
  4776. }
  4777. ret = 0;
  4778. loopback_test_done:
  4779. bp->loopback = 0;
  4780. return ret;
  4781. }
  4782. #define BNX2_MAC_LOOPBACK_FAILED 1
  4783. #define BNX2_PHY_LOOPBACK_FAILED 2
  4784. #define BNX2_LOOPBACK_FAILED (BNX2_MAC_LOOPBACK_FAILED | \
  4785. BNX2_PHY_LOOPBACK_FAILED)
  4786. static int
  4787. bnx2_test_loopback(struct bnx2 *bp)
  4788. {
  4789. int rc = 0;
  4790. if (!netif_running(bp->dev))
  4791. return BNX2_LOOPBACK_FAILED;
  4792. bnx2_reset_nic(bp, BNX2_DRV_MSG_CODE_RESET);
  4793. spin_lock_bh(&bp->phy_lock);
  4794. bnx2_init_phy(bp, 1);
  4795. spin_unlock_bh(&bp->phy_lock);
  4796. if (bnx2_run_loopback(bp, BNX2_MAC_LOOPBACK))
  4797. rc |= BNX2_MAC_LOOPBACK_FAILED;
  4798. if (bnx2_run_loopback(bp, BNX2_PHY_LOOPBACK))
  4799. rc |= BNX2_PHY_LOOPBACK_FAILED;
  4800. return rc;
  4801. }
  4802. #define NVRAM_SIZE 0x200
  4803. #define CRC32_RESIDUAL 0xdebb20e3
  4804. static int
  4805. bnx2_test_nvram(struct bnx2 *bp)
  4806. {
  4807. __be32 buf[NVRAM_SIZE / 4];
  4808. u8 *data = (u8 *) buf;
  4809. int rc = 0;
  4810. u32 magic, csum;
  4811. if ((rc = bnx2_nvram_read(bp, 0, data, 4)) != 0)
  4812. goto test_nvram_done;
  4813. magic = be32_to_cpu(buf[0]);
  4814. if (magic != 0x669955aa) {
  4815. rc = -ENODEV;
  4816. goto test_nvram_done;
  4817. }
  4818. if ((rc = bnx2_nvram_read(bp, 0x100, data, NVRAM_SIZE)) != 0)
  4819. goto test_nvram_done;
  4820. csum = ether_crc_le(0x100, data);
  4821. if (csum != CRC32_RESIDUAL) {
  4822. rc = -ENODEV;
  4823. goto test_nvram_done;
  4824. }
  4825. csum = ether_crc_le(0x100, data + 0x100);
  4826. if (csum != CRC32_RESIDUAL) {
  4827. rc = -ENODEV;
  4828. }
  4829. test_nvram_done:
  4830. return rc;
  4831. }
  4832. static int
  4833. bnx2_test_link(struct bnx2 *bp)
  4834. {
  4835. u32 bmsr;
  4836. if (!netif_running(bp->dev))
  4837. return -ENODEV;
  4838. if (bp->phy_flags & BNX2_PHY_FLAG_REMOTE_PHY_CAP) {
  4839. if (bp->link_up)
  4840. return 0;
  4841. return -ENODEV;
  4842. }
  4843. spin_lock_bh(&bp->phy_lock);
  4844. bnx2_enable_bmsr1(bp);
  4845. bnx2_read_phy(bp, bp->mii_bmsr1, &bmsr);
  4846. bnx2_read_phy(bp, bp->mii_bmsr1, &bmsr);
  4847. bnx2_disable_bmsr1(bp);
  4848. spin_unlock_bh(&bp->phy_lock);
  4849. if (bmsr & BMSR_LSTATUS) {
  4850. return 0;
  4851. }
  4852. return -ENODEV;
  4853. }
  4854. static int
  4855. bnx2_test_intr(struct bnx2 *bp)
  4856. {
  4857. int i;
  4858. u16 status_idx;
  4859. if (!netif_running(bp->dev))
  4860. return -ENODEV;
  4861. status_idx = REG_RD(bp, BNX2_PCICFG_INT_ACK_CMD) & 0xffff;
  4862. /* This register is not touched during run-time. */
  4863. REG_WR(bp, BNX2_HC_COMMAND, bp->hc_cmd | BNX2_HC_COMMAND_COAL_NOW);
  4864. REG_RD(bp, BNX2_HC_COMMAND);
  4865. for (i = 0; i < 10; i++) {
  4866. if ((REG_RD(bp, BNX2_PCICFG_INT_ACK_CMD) & 0xffff) !=
  4867. status_idx) {
  4868. break;
  4869. }
  4870. msleep_interruptible(10);
  4871. }
  4872. if (i < 10)
  4873. return 0;
  4874. return -ENODEV;
  4875. }
  4876. /* Determining link for parallel detection. */
  4877. static int
  4878. bnx2_5706_serdes_has_link(struct bnx2 *bp)
  4879. {
  4880. u32 mode_ctl, an_dbg, exp;
  4881. if (bp->phy_flags & BNX2_PHY_FLAG_NO_PARALLEL)
  4882. return 0;
  4883. bnx2_write_phy(bp, MII_BNX2_MISC_SHADOW, MISC_SHDW_MODE_CTL);
  4884. bnx2_read_phy(bp, MII_BNX2_MISC_SHADOW, &mode_ctl);
  4885. if (!(mode_ctl & MISC_SHDW_MODE_CTL_SIG_DET))
  4886. return 0;
  4887. bnx2_write_phy(bp, MII_BNX2_MISC_SHADOW, MISC_SHDW_AN_DBG);
  4888. bnx2_read_phy(bp, MII_BNX2_MISC_SHADOW, &an_dbg);
  4889. bnx2_read_phy(bp, MII_BNX2_MISC_SHADOW, &an_dbg);
  4890. if (an_dbg & (MISC_SHDW_AN_DBG_NOSYNC | MISC_SHDW_AN_DBG_RUDI_INVALID))
  4891. return 0;
  4892. bnx2_write_phy(bp, MII_BNX2_DSP_ADDRESS, MII_EXPAND_REG1);
  4893. bnx2_read_phy(bp, MII_BNX2_DSP_RW_PORT, &exp);
  4894. bnx2_read_phy(bp, MII_BNX2_DSP_RW_PORT, &exp);
  4895. if (exp & MII_EXPAND_REG1_RUDI_C) /* receiving CONFIG */
  4896. return 0;
  4897. return 1;
  4898. }
  4899. static void
  4900. bnx2_5706_serdes_timer(struct bnx2 *bp)
  4901. {
  4902. int check_link = 1;
  4903. spin_lock(&bp->phy_lock);
  4904. if (bp->serdes_an_pending) {
  4905. bp->serdes_an_pending--;
  4906. check_link = 0;
  4907. } else if ((bp->link_up == 0) && (bp->autoneg & AUTONEG_SPEED)) {
  4908. u32 bmcr;
  4909. bp->current_interval = BNX2_TIMER_INTERVAL;
  4910. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  4911. if (bmcr & BMCR_ANENABLE) {
  4912. if (bnx2_5706_serdes_has_link(bp)) {
  4913. bmcr &= ~BMCR_ANENABLE;
  4914. bmcr |= BMCR_SPEED1000 | BMCR_FULLDPLX;
  4915. bnx2_write_phy(bp, bp->mii_bmcr, bmcr);
  4916. bp->phy_flags |= BNX2_PHY_FLAG_PARALLEL_DETECT;
  4917. }
  4918. }
  4919. }
  4920. else if ((bp->link_up) && (bp->autoneg & AUTONEG_SPEED) &&
  4921. (bp->phy_flags & BNX2_PHY_FLAG_PARALLEL_DETECT)) {
  4922. u32 phy2;
  4923. bnx2_write_phy(bp, 0x17, 0x0f01);
  4924. bnx2_read_phy(bp, 0x15, &phy2);
  4925. if (phy2 & 0x20) {
  4926. u32 bmcr;
  4927. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  4928. bmcr |= BMCR_ANENABLE;
  4929. bnx2_write_phy(bp, bp->mii_bmcr, bmcr);
  4930. bp->phy_flags &= ~BNX2_PHY_FLAG_PARALLEL_DETECT;
  4931. }
  4932. } else
  4933. bp->current_interval = BNX2_TIMER_INTERVAL;
  4934. if (check_link) {
  4935. u32 val;
  4936. bnx2_write_phy(bp, MII_BNX2_MISC_SHADOW, MISC_SHDW_AN_DBG);
  4937. bnx2_read_phy(bp, MII_BNX2_MISC_SHADOW, &val);
  4938. bnx2_read_phy(bp, MII_BNX2_MISC_SHADOW, &val);
  4939. if (bp->link_up && (val & MISC_SHDW_AN_DBG_NOSYNC)) {
  4940. if (!(bp->phy_flags & BNX2_PHY_FLAG_FORCED_DOWN)) {
  4941. bnx2_5706s_force_link_dn(bp, 1);
  4942. bp->phy_flags |= BNX2_PHY_FLAG_FORCED_DOWN;
  4943. } else
  4944. bnx2_set_link(bp);
  4945. } else if (!bp->link_up && !(val & MISC_SHDW_AN_DBG_NOSYNC))
  4946. bnx2_set_link(bp);
  4947. }
  4948. spin_unlock(&bp->phy_lock);
  4949. }
  4950. static void
  4951. bnx2_5708_serdes_timer(struct bnx2 *bp)
  4952. {
  4953. if (bp->phy_flags & BNX2_PHY_FLAG_REMOTE_PHY_CAP)
  4954. return;
  4955. if ((bp->phy_flags & BNX2_PHY_FLAG_2_5G_CAPABLE) == 0) {
  4956. bp->serdes_an_pending = 0;
  4957. return;
  4958. }
  4959. spin_lock(&bp->phy_lock);
  4960. if (bp->serdes_an_pending)
  4961. bp->serdes_an_pending--;
  4962. else if ((bp->link_up == 0) && (bp->autoneg & AUTONEG_SPEED)) {
  4963. u32 bmcr;
  4964. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  4965. if (bmcr & BMCR_ANENABLE) {
  4966. bnx2_enable_forced_2g5(bp);
  4967. bp->current_interval = BNX2_SERDES_FORCED_TIMEOUT;
  4968. } else {
  4969. bnx2_disable_forced_2g5(bp);
  4970. bp->serdes_an_pending = 2;
  4971. bp->current_interval = BNX2_TIMER_INTERVAL;
  4972. }
  4973. } else
  4974. bp->current_interval = BNX2_TIMER_INTERVAL;
  4975. spin_unlock(&bp->phy_lock);
  4976. }
  4977. static void
  4978. bnx2_timer(unsigned long data)
  4979. {
  4980. struct bnx2 *bp = (struct bnx2 *) data;
  4981. if (!netif_running(bp->dev))
  4982. return;
  4983. if (atomic_read(&bp->intr_sem) != 0)
  4984. goto bnx2_restart_timer;
  4985. if ((bp->flags & (BNX2_FLAG_USING_MSI | BNX2_FLAG_ONE_SHOT_MSI)) ==
  4986. BNX2_FLAG_USING_MSI)
  4987. bnx2_chk_missed_msi(bp);
  4988. bnx2_send_heart_beat(bp);
  4989. bp->stats_blk->stat_FwRxDrop =
  4990. bnx2_reg_rd_ind(bp, BNX2_FW_RX_DROP_COUNT);
  4991. /* workaround occasional corrupted counters */
  4992. if ((bp->flags & BNX2_FLAG_BROKEN_STATS) && bp->stats_ticks)
  4993. REG_WR(bp, BNX2_HC_COMMAND, bp->hc_cmd |
  4994. BNX2_HC_COMMAND_STATS_NOW);
  4995. if (bp->phy_flags & BNX2_PHY_FLAG_SERDES) {
  4996. if (CHIP_NUM(bp) == CHIP_NUM_5706)
  4997. bnx2_5706_serdes_timer(bp);
  4998. else
  4999. bnx2_5708_serdes_timer(bp);
  5000. }
  5001. bnx2_restart_timer:
  5002. mod_timer(&bp->timer, jiffies + bp->current_interval);
  5003. }
  5004. static int
  5005. bnx2_request_irq(struct bnx2 *bp)
  5006. {
  5007. unsigned long flags;
  5008. struct bnx2_irq *irq;
  5009. int rc = 0, i;
  5010. if (bp->flags & BNX2_FLAG_USING_MSI_OR_MSIX)
  5011. flags = 0;
  5012. else
  5013. flags = IRQF_SHARED;
  5014. for (i = 0; i < bp->irq_nvecs; i++) {
  5015. irq = &bp->irq_tbl[i];
  5016. rc = request_irq(irq->vector, irq->handler, flags, irq->name,
  5017. &bp->bnx2_napi[i]);
  5018. if (rc)
  5019. break;
  5020. irq->requested = 1;
  5021. }
  5022. return rc;
  5023. }
  5024. static void
  5025. __bnx2_free_irq(struct bnx2 *bp)
  5026. {
  5027. struct bnx2_irq *irq;
  5028. int i;
  5029. for (i = 0; i < bp->irq_nvecs; i++) {
  5030. irq = &bp->irq_tbl[i];
  5031. if (irq->requested)
  5032. free_irq(irq->vector, &bp->bnx2_napi[i]);
  5033. irq->requested = 0;
  5034. }
  5035. }
  5036. static void
  5037. bnx2_free_irq(struct bnx2 *bp)
  5038. {
  5039. __bnx2_free_irq(bp);
  5040. if (bp->flags & BNX2_FLAG_USING_MSI)
  5041. pci_disable_msi(bp->pdev);
  5042. else if (bp->flags & BNX2_FLAG_USING_MSIX)
  5043. pci_disable_msix(bp->pdev);
  5044. bp->flags &= ~(BNX2_FLAG_USING_MSI_OR_MSIX | BNX2_FLAG_ONE_SHOT_MSI);
  5045. }
  5046. static void
  5047. bnx2_enable_msix(struct bnx2 *bp, int msix_vecs)
  5048. {
  5049. int i, total_vecs, rc;
  5050. struct msix_entry msix_ent[BNX2_MAX_MSIX_VEC];
  5051. struct net_device *dev = bp->dev;
  5052. const int len = sizeof(bp->irq_tbl[0].name);
  5053. bnx2_setup_msix_tbl(bp);
  5054. REG_WR(bp, BNX2_PCI_MSIX_CONTROL, BNX2_MAX_MSIX_HW_VEC - 1);
  5055. REG_WR(bp, BNX2_PCI_MSIX_TBL_OFF_BIR, BNX2_PCI_GRC_WINDOW2_BASE);
  5056. REG_WR(bp, BNX2_PCI_MSIX_PBA_OFF_BIT, BNX2_PCI_GRC_WINDOW3_BASE);
  5057. /* Need to flush the previous three writes to ensure MSI-X
  5058. * is setup properly */
  5059. REG_RD(bp, BNX2_PCI_MSIX_CONTROL);
  5060. for (i = 0; i < BNX2_MAX_MSIX_VEC; i++) {
  5061. msix_ent[i].entry = i;
  5062. msix_ent[i].vector = 0;
  5063. }
  5064. total_vecs = msix_vecs;
  5065. #ifdef BCM_CNIC
  5066. total_vecs++;
  5067. #endif
  5068. rc = -ENOSPC;
  5069. while (total_vecs >= BNX2_MIN_MSIX_VEC) {
  5070. rc = pci_enable_msix(bp->pdev, msix_ent, total_vecs);
  5071. if (rc <= 0)
  5072. break;
  5073. if (rc > 0)
  5074. total_vecs = rc;
  5075. }
  5076. if (rc != 0)
  5077. return;
  5078. msix_vecs = total_vecs;
  5079. #ifdef BCM_CNIC
  5080. msix_vecs--;
  5081. #endif
  5082. bp->irq_nvecs = msix_vecs;
  5083. bp->flags |= BNX2_FLAG_USING_MSIX | BNX2_FLAG_ONE_SHOT_MSI;
  5084. for (i = 0; i < total_vecs; i++) {
  5085. bp->irq_tbl[i].vector = msix_ent[i].vector;
  5086. snprintf(bp->irq_tbl[i].name, len, "%s-%d", dev->name, i);
  5087. bp->irq_tbl[i].handler = bnx2_msi_1shot;
  5088. }
  5089. }
  5090. static int
  5091. bnx2_setup_int_mode(struct bnx2 *bp, int dis_msi)
  5092. {
  5093. int cpus = num_online_cpus();
  5094. int msix_vecs = min(cpus + 1, RX_MAX_RINGS);
  5095. bp->irq_tbl[0].handler = bnx2_interrupt;
  5096. strcpy(bp->irq_tbl[0].name, bp->dev->name);
  5097. bp->irq_nvecs = 1;
  5098. bp->irq_tbl[0].vector = bp->pdev->irq;
  5099. if ((bp->flags & BNX2_FLAG_MSIX_CAP) && !dis_msi)
  5100. bnx2_enable_msix(bp, msix_vecs);
  5101. if ((bp->flags & BNX2_FLAG_MSI_CAP) && !dis_msi &&
  5102. !(bp->flags & BNX2_FLAG_USING_MSIX)) {
  5103. if (pci_enable_msi(bp->pdev) == 0) {
  5104. bp->flags |= BNX2_FLAG_USING_MSI;
  5105. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  5106. bp->flags |= BNX2_FLAG_ONE_SHOT_MSI;
  5107. bp->irq_tbl[0].handler = bnx2_msi_1shot;
  5108. } else
  5109. bp->irq_tbl[0].handler = bnx2_msi;
  5110. bp->irq_tbl[0].vector = bp->pdev->irq;
  5111. }
  5112. }
  5113. bp->num_tx_rings = rounddown_pow_of_two(bp->irq_nvecs);
  5114. netif_set_real_num_tx_queues(bp->dev, bp->num_tx_rings);
  5115. bp->num_rx_rings = bp->irq_nvecs;
  5116. return netif_set_real_num_rx_queues(bp->dev, bp->num_rx_rings);
  5117. }
  5118. /* Called with rtnl_lock */
  5119. static int
  5120. bnx2_open(struct net_device *dev)
  5121. {
  5122. struct bnx2 *bp = netdev_priv(dev);
  5123. int rc;
  5124. netif_carrier_off(dev);
  5125. bnx2_set_power_state(bp, PCI_D0);
  5126. bnx2_disable_int(bp);
  5127. rc = bnx2_setup_int_mode(bp, disable_msi);
  5128. if (rc)
  5129. goto open_err;
  5130. bnx2_init_napi(bp);
  5131. bnx2_napi_enable(bp);
  5132. rc = bnx2_alloc_mem(bp);
  5133. if (rc)
  5134. goto open_err;
  5135. rc = bnx2_request_irq(bp);
  5136. if (rc)
  5137. goto open_err;
  5138. rc = bnx2_init_nic(bp, 1);
  5139. if (rc)
  5140. goto open_err;
  5141. mod_timer(&bp->timer, jiffies + bp->current_interval);
  5142. atomic_set(&bp->intr_sem, 0);
  5143. memset(bp->temp_stats_blk, 0, sizeof(struct statistics_block));
  5144. bnx2_enable_int(bp);
  5145. if (bp->flags & BNX2_FLAG_USING_MSI) {
  5146. /* Test MSI to make sure it is working
  5147. * If MSI test fails, go back to INTx mode
  5148. */
  5149. if (bnx2_test_intr(bp) != 0) {
  5150. netdev_warn(bp->dev, "No interrupt was generated using MSI, switching to INTx mode. Please report this failure to the PCI maintainer and include system chipset information.\n");
  5151. bnx2_disable_int(bp);
  5152. bnx2_free_irq(bp);
  5153. bnx2_setup_int_mode(bp, 1);
  5154. rc = bnx2_init_nic(bp, 0);
  5155. if (!rc)
  5156. rc = bnx2_request_irq(bp);
  5157. if (rc) {
  5158. del_timer_sync(&bp->timer);
  5159. goto open_err;
  5160. }
  5161. bnx2_enable_int(bp);
  5162. }
  5163. }
  5164. if (bp->flags & BNX2_FLAG_USING_MSI)
  5165. netdev_info(dev, "using MSI\n");
  5166. else if (bp->flags & BNX2_FLAG_USING_MSIX)
  5167. netdev_info(dev, "using MSIX\n");
  5168. netif_tx_start_all_queues(dev);
  5169. return 0;
  5170. open_err:
  5171. bnx2_napi_disable(bp);
  5172. bnx2_free_skbs(bp);
  5173. bnx2_free_irq(bp);
  5174. bnx2_free_mem(bp);
  5175. bnx2_del_napi(bp);
  5176. return rc;
  5177. }
  5178. static void
  5179. bnx2_reset_task(struct work_struct *work)
  5180. {
  5181. struct bnx2 *bp = container_of(work, struct bnx2, reset_task);
  5182. rtnl_lock();
  5183. if (!netif_running(bp->dev)) {
  5184. rtnl_unlock();
  5185. return;
  5186. }
  5187. bnx2_netif_stop(bp, true);
  5188. bnx2_init_nic(bp, 1);
  5189. atomic_set(&bp->intr_sem, 1);
  5190. bnx2_netif_start(bp, true);
  5191. rtnl_unlock();
  5192. }
  5193. static void
  5194. bnx2_dump_state(struct bnx2 *bp)
  5195. {
  5196. struct net_device *dev = bp->dev;
  5197. u32 val1, val2;
  5198. pci_read_config_dword(bp->pdev, PCI_COMMAND, &val1);
  5199. netdev_err(dev, "DEBUG: intr_sem[%x] PCI_CMD[%08x]\n",
  5200. atomic_read(&bp->intr_sem), val1);
  5201. pci_read_config_dword(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &val1);
  5202. pci_read_config_dword(bp->pdev, BNX2_PCICFG_MISC_CONFIG, &val2);
  5203. netdev_err(dev, "DEBUG: PCI_PM[%08x] PCI_MISC_CFG[%08x]\n", val1, val2);
  5204. netdev_err(dev, "DEBUG: EMAC_TX_STATUS[%08x] EMAC_RX_STATUS[%08x]\n",
  5205. REG_RD(bp, BNX2_EMAC_TX_STATUS),
  5206. REG_RD(bp, BNX2_EMAC_RX_STATUS));
  5207. netdev_err(dev, "DEBUG: RPM_MGMT_PKT_CTRL[%08x]\n",
  5208. REG_RD(bp, BNX2_RPM_MGMT_PKT_CTRL));
  5209. netdev_err(dev, "DEBUG: HC_STATS_INTERRUPT_STATUS[%08x]\n",
  5210. REG_RD(bp, BNX2_HC_STATS_INTERRUPT_STATUS));
  5211. if (bp->flags & BNX2_FLAG_USING_MSIX)
  5212. netdev_err(dev, "DEBUG: PBA[%08x]\n",
  5213. REG_RD(bp, BNX2_PCI_GRC_WINDOW3_BASE));
  5214. }
  5215. static void
  5216. bnx2_tx_timeout(struct net_device *dev)
  5217. {
  5218. struct bnx2 *bp = netdev_priv(dev);
  5219. bnx2_dump_state(bp);
  5220. bnx2_dump_mcp_state(bp);
  5221. /* This allows the netif to be shutdown gracefully before resetting */
  5222. schedule_work(&bp->reset_task);
  5223. }
  5224. /* Called with netif_tx_lock.
  5225. * bnx2_tx_int() runs without netif_tx_lock unless it needs to call
  5226. * netif_wake_queue().
  5227. */
  5228. static netdev_tx_t
  5229. bnx2_start_xmit(struct sk_buff *skb, struct net_device *dev)
  5230. {
  5231. struct bnx2 *bp = netdev_priv(dev);
  5232. dma_addr_t mapping;
  5233. struct tx_bd *txbd;
  5234. struct sw_tx_bd *tx_buf;
  5235. u32 len, vlan_tag_flags, last_frag, mss;
  5236. u16 prod, ring_prod;
  5237. int i;
  5238. struct bnx2_napi *bnapi;
  5239. struct bnx2_tx_ring_info *txr;
  5240. struct netdev_queue *txq;
  5241. /* Determine which tx ring we will be placed on */
  5242. i = skb_get_queue_mapping(skb);
  5243. bnapi = &bp->bnx2_napi[i];
  5244. txr = &bnapi->tx_ring;
  5245. txq = netdev_get_tx_queue(dev, i);
  5246. if (unlikely(bnx2_tx_avail(bp, txr) <
  5247. (skb_shinfo(skb)->nr_frags + 1))) {
  5248. netif_tx_stop_queue(txq);
  5249. netdev_err(dev, "BUG! Tx ring full when queue awake!\n");
  5250. return NETDEV_TX_BUSY;
  5251. }
  5252. len = skb_headlen(skb);
  5253. prod = txr->tx_prod;
  5254. ring_prod = TX_RING_IDX(prod);
  5255. vlan_tag_flags = 0;
  5256. if (skb->ip_summed == CHECKSUM_PARTIAL) {
  5257. vlan_tag_flags |= TX_BD_FLAGS_TCP_UDP_CKSUM;
  5258. }
  5259. if (vlan_tx_tag_present(skb)) {
  5260. vlan_tag_flags |=
  5261. (TX_BD_FLAGS_VLAN_TAG | (vlan_tx_tag_get(skb) << 16));
  5262. }
  5263. if ((mss = skb_shinfo(skb)->gso_size)) {
  5264. u32 tcp_opt_len;
  5265. struct iphdr *iph;
  5266. vlan_tag_flags |= TX_BD_FLAGS_SW_LSO;
  5267. tcp_opt_len = tcp_optlen(skb);
  5268. if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6) {
  5269. u32 tcp_off = skb_transport_offset(skb) -
  5270. sizeof(struct ipv6hdr) - ETH_HLEN;
  5271. vlan_tag_flags |= ((tcp_opt_len >> 2) << 8) |
  5272. TX_BD_FLAGS_SW_FLAGS;
  5273. if (likely(tcp_off == 0))
  5274. vlan_tag_flags &= ~TX_BD_FLAGS_TCP6_OFF0_MSK;
  5275. else {
  5276. tcp_off >>= 3;
  5277. vlan_tag_flags |= ((tcp_off & 0x3) <<
  5278. TX_BD_FLAGS_TCP6_OFF0_SHL) |
  5279. ((tcp_off & 0x10) <<
  5280. TX_BD_FLAGS_TCP6_OFF4_SHL);
  5281. mss |= (tcp_off & 0xc) << TX_BD_TCP6_OFF2_SHL;
  5282. }
  5283. } else {
  5284. iph = ip_hdr(skb);
  5285. if (tcp_opt_len || (iph->ihl > 5)) {
  5286. vlan_tag_flags |= ((iph->ihl - 5) +
  5287. (tcp_opt_len >> 2)) << 8;
  5288. }
  5289. }
  5290. } else
  5291. mss = 0;
  5292. mapping = dma_map_single(&bp->pdev->dev, skb->data, len, PCI_DMA_TODEVICE);
  5293. if (dma_mapping_error(&bp->pdev->dev, mapping)) {
  5294. dev_kfree_skb(skb);
  5295. return NETDEV_TX_OK;
  5296. }
  5297. tx_buf = &txr->tx_buf_ring[ring_prod];
  5298. tx_buf->skb = skb;
  5299. dma_unmap_addr_set(tx_buf, mapping, mapping);
  5300. txbd = &txr->tx_desc_ring[ring_prod];
  5301. txbd->tx_bd_haddr_hi = (u64) mapping >> 32;
  5302. txbd->tx_bd_haddr_lo = (u64) mapping & 0xffffffff;
  5303. txbd->tx_bd_mss_nbytes = len | (mss << 16);
  5304. txbd->tx_bd_vlan_tag_flags = vlan_tag_flags | TX_BD_FLAGS_START;
  5305. last_frag = skb_shinfo(skb)->nr_frags;
  5306. tx_buf->nr_frags = last_frag;
  5307. tx_buf->is_gso = skb_is_gso(skb);
  5308. for (i = 0; i < last_frag; i++) {
  5309. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  5310. prod = NEXT_TX_BD(prod);
  5311. ring_prod = TX_RING_IDX(prod);
  5312. txbd = &txr->tx_desc_ring[ring_prod];
  5313. len = frag->size;
  5314. mapping = dma_map_page(&bp->pdev->dev, frag->page, frag->page_offset,
  5315. len, PCI_DMA_TODEVICE);
  5316. if (dma_mapping_error(&bp->pdev->dev, mapping))
  5317. goto dma_error;
  5318. dma_unmap_addr_set(&txr->tx_buf_ring[ring_prod], mapping,
  5319. mapping);
  5320. txbd->tx_bd_haddr_hi = (u64) mapping >> 32;
  5321. txbd->tx_bd_haddr_lo = (u64) mapping & 0xffffffff;
  5322. txbd->tx_bd_mss_nbytes = len | (mss << 16);
  5323. txbd->tx_bd_vlan_tag_flags = vlan_tag_flags;
  5324. }
  5325. txbd->tx_bd_vlan_tag_flags |= TX_BD_FLAGS_END;
  5326. prod = NEXT_TX_BD(prod);
  5327. txr->tx_prod_bseq += skb->len;
  5328. REG_WR16(bp, txr->tx_bidx_addr, prod);
  5329. REG_WR(bp, txr->tx_bseq_addr, txr->tx_prod_bseq);
  5330. mmiowb();
  5331. txr->tx_prod = prod;
  5332. if (unlikely(bnx2_tx_avail(bp, txr) <= MAX_SKB_FRAGS)) {
  5333. netif_tx_stop_queue(txq);
  5334. /* netif_tx_stop_queue() must be done before checking
  5335. * tx index in bnx2_tx_avail() below, because in
  5336. * bnx2_tx_int(), we update tx index before checking for
  5337. * netif_tx_queue_stopped().
  5338. */
  5339. smp_mb();
  5340. if (bnx2_tx_avail(bp, txr) > bp->tx_wake_thresh)
  5341. netif_tx_wake_queue(txq);
  5342. }
  5343. return NETDEV_TX_OK;
  5344. dma_error:
  5345. /* save value of frag that failed */
  5346. last_frag = i;
  5347. /* start back at beginning and unmap skb */
  5348. prod = txr->tx_prod;
  5349. ring_prod = TX_RING_IDX(prod);
  5350. tx_buf = &txr->tx_buf_ring[ring_prod];
  5351. tx_buf->skb = NULL;
  5352. dma_unmap_single(&bp->pdev->dev, dma_unmap_addr(tx_buf, mapping),
  5353. skb_headlen(skb), PCI_DMA_TODEVICE);
  5354. /* unmap remaining mapped pages */
  5355. for (i = 0; i < last_frag; i++) {
  5356. prod = NEXT_TX_BD(prod);
  5357. ring_prod = TX_RING_IDX(prod);
  5358. tx_buf = &txr->tx_buf_ring[ring_prod];
  5359. dma_unmap_page(&bp->pdev->dev, dma_unmap_addr(tx_buf, mapping),
  5360. skb_shinfo(skb)->frags[i].size,
  5361. PCI_DMA_TODEVICE);
  5362. }
  5363. dev_kfree_skb(skb);
  5364. return NETDEV_TX_OK;
  5365. }
  5366. /* Called with rtnl_lock */
  5367. static int
  5368. bnx2_close(struct net_device *dev)
  5369. {
  5370. struct bnx2 *bp = netdev_priv(dev);
  5371. cancel_work_sync(&bp->reset_task);
  5372. bnx2_disable_int_sync(bp);
  5373. bnx2_napi_disable(bp);
  5374. del_timer_sync(&bp->timer);
  5375. bnx2_shutdown_chip(bp);
  5376. bnx2_free_irq(bp);
  5377. bnx2_free_skbs(bp);
  5378. bnx2_free_mem(bp);
  5379. bnx2_del_napi(bp);
  5380. bp->link_up = 0;
  5381. netif_carrier_off(bp->dev);
  5382. bnx2_set_power_state(bp, PCI_D3hot);
  5383. return 0;
  5384. }
  5385. static void
  5386. bnx2_save_stats(struct bnx2 *bp)
  5387. {
  5388. u32 *hw_stats = (u32 *) bp->stats_blk;
  5389. u32 *temp_stats = (u32 *) bp->temp_stats_blk;
  5390. int i;
  5391. /* The 1st 10 counters are 64-bit counters */
  5392. for (i = 0; i < 20; i += 2) {
  5393. u32 hi;
  5394. u64 lo;
  5395. hi = temp_stats[i] + hw_stats[i];
  5396. lo = (u64) temp_stats[i + 1] + (u64) hw_stats[i + 1];
  5397. if (lo > 0xffffffff)
  5398. hi++;
  5399. temp_stats[i] = hi;
  5400. temp_stats[i + 1] = lo & 0xffffffff;
  5401. }
  5402. for ( ; i < sizeof(struct statistics_block) / 4; i++)
  5403. temp_stats[i] += hw_stats[i];
  5404. }
  5405. #define GET_64BIT_NET_STATS64(ctr) \
  5406. (((u64) (ctr##_hi) << 32) + (u64) (ctr##_lo))
  5407. #define GET_64BIT_NET_STATS(ctr) \
  5408. GET_64BIT_NET_STATS64(bp->stats_blk->ctr) + \
  5409. GET_64BIT_NET_STATS64(bp->temp_stats_blk->ctr)
  5410. #define GET_32BIT_NET_STATS(ctr) \
  5411. (unsigned long) (bp->stats_blk->ctr + \
  5412. bp->temp_stats_blk->ctr)
  5413. static struct rtnl_link_stats64 *
  5414. bnx2_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *net_stats)
  5415. {
  5416. struct bnx2 *bp = netdev_priv(dev);
  5417. if (bp->stats_blk == NULL)
  5418. return net_stats;
  5419. net_stats->rx_packets =
  5420. GET_64BIT_NET_STATS(stat_IfHCInUcastPkts) +
  5421. GET_64BIT_NET_STATS(stat_IfHCInMulticastPkts) +
  5422. GET_64BIT_NET_STATS(stat_IfHCInBroadcastPkts);
  5423. net_stats->tx_packets =
  5424. GET_64BIT_NET_STATS(stat_IfHCOutUcastPkts) +
  5425. GET_64BIT_NET_STATS(stat_IfHCOutMulticastPkts) +
  5426. GET_64BIT_NET_STATS(stat_IfHCOutBroadcastPkts);
  5427. net_stats->rx_bytes =
  5428. GET_64BIT_NET_STATS(stat_IfHCInOctets);
  5429. net_stats->tx_bytes =
  5430. GET_64BIT_NET_STATS(stat_IfHCOutOctets);
  5431. net_stats->multicast =
  5432. GET_64BIT_NET_STATS(stat_IfHCInMulticastPkts);
  5433. net_stats->collisions =
  5434. GET_32BIT_NET_STATS(stat_EtherStatsCollisions);
  5435. net_stats->rx_length_errors =
  5436. GET_32BIT_NET_STATS(stat_EtherStatsUndersizePkts) +
  5437. GET_32BIT_NET_STATS(stat_EtherStatsOverrsizePkts);
  5438. net_stats->rx_over_errors =
  5439. GET_32BIT_NET_STATS(stat_IfInFTQDiscards) +
  5440. GET_32BIT_NET_STATS(stat_IfInMBUFDiscards);
  5441. net_stats->rx_frame_errors =
  5442. GET_32BIT_NET_STATS(stat_Dot3StatsAlignmentErrors);
  5443. net_stats->rx_crc_errors =
  5444. GET_32BIT_NET_STATS(stat_Dot3StatsFCSErrors);
  5445. net_stats->rx_errors = net_stats->rx_length_errors +
  5446. net_stats->rx_over_errors + net_stats->rx_frame_errors +
  5447. net_stats->rx_crc_errors;
  5448. net_stats->tx_aborted_errors =
  5449. GET_32BIT_NET_STATS(stat_Dot3StatsExcessiveCollisions) +
  5450. GET_32BIT_NET_STATS(stat_Dot3StatsLateCollisions);
  5451. if ((CHIP_NUM(bp) == CHIP_NUM_5706) ||
  5452. (CHIP_ID(bp) == CHIP_ID_5708_A0))
  5453. net_stats->tx_carrier_errors = 0;
  5454. else {
  5455. net_stats->tx_carrier_errors =
  5456. GET_32BIT_NET_STATS(stat_Dot3StatsCarrierSenseErrors);
  5457. }
  5458. net_stats->tx_errors =
  5459. GET_32BIT_NET_STATS(stat_emac_tx_stat_dot3statsinternalmactransmiterrors) +
  5460. net_stats->tx_aborted_errors +
  5461. net_stats->tx_carrier_errors;
  5462. net_stats->rx_missed_errors =
  5463. GET_32BIT_NET_STATS(stat_IfInFTQDiscards) +
  5464. GET_32BIT_NET_STATS(stat_IfInMBUFDiscards) +
  5465. GET_32BIT_NET_STATS(stat_FwRxDrop);
  5466. return net_stats;
  5467. }
  5468. /* All ethtool functions called with rtnl_lock */
  5469. static int
  5470. bnx2_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  5471. {
  5472. struct bnx2 *bp = netdev_priv(dev);
  5473. int support_serdes = 0, support_copper = 0;
  5474. cmd->supported = SUPPORTED_Autoneg;
  5475. if (bp->phy_flags & BNX2_PHY_FLAG_REMOTE_PHY_CAP) {
  5476. support_serdes = 1;
  5477. support_copper = 1;
  5478. } else if (bp->phy_port == PORT_FIBRE)
  5479. support_serdes = 1;
  5480. else
  5481. support_copper = 1;
  5482. if (support_serdes) {
  5483. cmd->supported |= SUPPORTED_1000baseT_Full |
  5484. SUPPORTED_FIBRE;
  5485. if (bp->phy_flags & BNX2_PHY_FLAG_2_5G_CAPABLE)
  5486. cmd->supported |= SUPPORTED_2500baseX_Full;
  5487. }
  5488. if (support_copper) {
  5489. cmd->supported |= SUPPORTED_10baseT_Half |
  5490. SUPPORTED_10baseT_Full |
  5491. SUPPORTED_100baseT_Half |
  5492. SUPPORTED_100baseT_Full |
  5493. SUPPORTED_1000baseT_Full |
  5494. SUPPORTED_TP;
  5495. }
  5496. spin_lock_bh(&bp->phy_lock);
  5497. cmd->port = bp->phy_port;
  5498. cmd->advertising = bp->advertising;
  5499. if (bp->autoneg & AUTONEG_SPEED) {
  5500. cmd->autoneg = AUTONEG_ENABLE;
  5501. } else {
  5502. cmd->autoneg = AUTONEG_DISABLE;
  5503. }
  5504. if (netif_carrier_ok(dev)) {
  5505. ethtool_cmd_speed_set(cmd, bp->line_speed);
  5506. cmd->duplex = bp->duplex;
  5507. }
  5508. else {
  5509. ethtool_cmd_speed_set(cmd, -1);
  5510. cmd->duplex = -1;
  5511. }
  5512. spin_unlock_bh(&bp->phy_lock);
  5513. cmd->transceiver = XCVR_INTERNAL;
  5514. cmd->phy_address = bp->phy_addr;
  5515. return 0;
  5516. }
  5517. static int
  5518. bnx2_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  5519. {
  5520. struct bnx2 *bp = netdev_priv(dev);
  5521. u8 autoneg = bp->autoneg;
  5522. u8 req_duplex = bp->req_duplex;
  5523. u16 req_line_speed = bp->req_line_speed;
  5524. u32 advertising = bp->advertising;
  5525. int err = -EINVAL;
  5526. spin_lock_bh(&bp->phy_lock);
  5527. if (cmd->port != PORT_TP && cmd->port != PORT_FIBRE)
  5528. goto err_out_unlock;
  5529. if (cmd->port != bp->phy_port &&
  5530. !(bp->phy_flags & BNX2_PHY_FLAG_REMOTE_PHY_CAP))
  5531. goto err_out_unlock;
  5532. /* If device is down, we can store the settings only if the user
  5533. * is setting the currently active port.
  5534. */
  5535. if (!netif_running(dev) && cmd->port != bp->phy_port)
  5536. goto err_out_unlock;
  5537. if (cmd->autoneg == AUTONEG_ENABLE) {
  5538. autoneg |= AUTONEG_SPEED;
  5539. advertising = cmd->advertising;
  5540. if (cmd->port == PORT_TP) {
  5541. advertising &= ETHTOOL_ALL_COPPER_SPEED;
  5542. if (!advertising)
  5543. advertising = ETHTOOL_ALL_COPPER_SPEED;
  5544. } else {
  5545. advertising &= ETHTOOL_ALL_FIBRE_SPEED;
  5546. if (!advertising)
  5547. advertising = ETHTOOL_ALL_FIBRE_SPEED;
  5548. }
  5549. advertising |= ADVERTISED_Autoneg;
  5550. }
  5551. else {
  5552. u32 speed = ethtool_cmd_speed(cmd);
  5553. if (cmd->port == PORT_FIBRE) {
  5554. if ((speed != SPEED_1000 &&
  5555. speed != SPEED_2500) ||
  5556. (cmd->duplex != DUPLEX_FULL))
  5557. goto err_out_unlock;
  5558. if (speed == SPEED_2500 &&
  5559. !(bp->phy_flags & BNX2_PHY_FLAG_2_5G_CAPABLE))
  5560. goto err_out_unlock;
  5561. } else if (speed == SPEED_1000 || speed == SPEED_2500)
  5562. goto err_out_unlock;
  5563. autoneg &= ~AUTONEG_SPEED;
  5564. req_line_speed = speed;
  5565. req_duplex = cmd->duplex;
  5566. advertising = 0;
  5567. }
  5568. bp->autoneg = autoneg;
  5569. bp->advertising = advertising;
  5570. bp->req_line_speed = req_line_speed;
  5571. bp->req_duplex = req_duplex;
  5572. err = 0;
  5573. /* If device is down, the new settings will be picked up when it is
  5574. * brought up.
  5575. */
  5576. if (netif_running(dev))
  5577. err = bnx2_setup_phy(bp, cmd->port);
  5578. err_out_unlock:
  5579. spin_unlock_bh(&bp->phy_lock);
  5580. return err;
  5581. }
  5582. static void
  5583. bnx2_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  5584. {
  5585. struct bnx2 *bp = netdev_priv(dev);
  5586. strcpy(info->driver, DRV_MODULE_NAME);
  5587. strcpy(info->version, DRV_MODULE_VERSION);
  5588. strcpy(info->bus_info, pci_name(bp->pdev));
  5589. strcpy(info->fw_version, bp->fw_version);
  5590. }
  5591. #define BNX2_REGDUMP_LEN (32 * 1024)
  5592. static int
  5593. bnx2_get_regs_len(struct net_device *dev)
  5594. {
  5595. return BNX2_REGDUMP_LEN;
  5596. }
  5597. static void
  5598. bnx2_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *_p)
  5599. {
  5600. u32 *p = _p, i, offset;
  5601. u8 *orig_p = _p;
  5602. struct bnx2 *bp = netdev_priv(dev);
  5603. static const u32 reg_boundaries[] = {
  5604. 0x0000, 0x0098, 0x0400, 0x045c,
  5605. 0x0800, 0x0880, 0x0c00, 0x0c10,
  5606. 0x0c30, 0x0d08, 0x1000, 0x101c,
  5607. 0x1040, 0x1048, 0x1080, 0x10a4,
  5608. 0x1400, 0x1490, 0x1498, 0x14f0,
  5609. 0x1500, 0x155c, 0x1580, 0x15dc,
  5610. 0x1600, 0x1658, 0x1680, 0x16d8,
  5611. 0x1800, 0x1820, 0x1840, 0x1854,
  5612. 0x1880, 0x1894, 0x1900, 0x1984,
  5613. 0x1c00, 0x1c0c, 0x1c40, 0x1c54,
  5614. 0x1c80, 0x1c94, 0x1d00, 0x1d84,
  5615. 0x2000, 0x2030, 0x23c0, 0x2400,
  5616. 0x2800, 0x2820, 0x2830, 0x2850,
  5617. 0x2b40, 0x2c10, 0x2fc0, 0x3058,
  5618. 0x3c00, 0x3c94, 0x4000, 0x4010,
  5619. 0x4080, 0x4090, 0x43c0, 0x4458,
  5620. 0x4c00, 0x4c18, 0x4c40, 0x4c54,
  5621. 0x4fc0, 0x5010, 0x53c0, 0x5444,
  5622. 0x5c00, 0x5c18, 0x5c80, 0x5c90,
  5623. 0x5fc0, 0x6000, 0x6400, 0x6428,
  5624. 0x6800, 0x6848, 0x684c, 0x6860,
  5625. 0x6888, 0x6910, 0x8000
  5626. };
  5627. regs->version = 0;
  5628. memset(p, 0, BNX2_REGDUMP_LEN);
  5629. if (!netif_running(bp->dev))
  5630. return;
  5631. i = 0;
  5632. offset = reg_boundaries[0];
  5633. p += offset;
  5634. while (offset < BNX2_REGDUMP_LEN) {
  5635. *p++ = REG_RD(bp, offset);
  5636. offset += 4;
  5637. if (offset == reg_boundaries[i + 1]) {
  5638. offset = reg_boundaries[i + 2];
  5639. p = (u32 *) (orig_p + offset);
  5640. i += 2;
  5641. }
  5642. }
  5643. }
  5644. static void
  5645. bnx2_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  5646. {
  5647. struct bnx2 *bp = netdev_priv(dev);
  5648. if (bp->flags & BNX2_FLAG_NO_WOL) {
  5649. wol->supported = 0;
  5650. wol->wolopts = 0;
  5651. }
  5652. else {
  5653. wol->supported = WAKE_MAGIC;
  5654. if (bp->wol)
  5655. wol->wolopts = WAKE_MAGIC;
  5656. else
  5657. wol->wolopts = 0;
  5658. }
  5659. memset(&wol->sopass, 0, sizeof(wol->sopass));
  5660. }
  5661. static int
  5662. bnx2_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  5663. {
  5664. struct bnx2 *bp = netdev_priv(dev);
  5665. if (wol->wolopts & ~WAKE_MAGIC)
  5666. return -EINVAL;
  5667. if (wol->wolopts & WAKE_MAGIC) {
  5668. if (bp->flags & BNX2_FLAG_NO_WOL)
  5669. return -EINVAL;
  5670. bp->wol = 1;
  5671. }
  5672. else {
  5673. bp->wol = 0;
  5674. }
  5675. return 0;
  5676. }
  5677. static int
  5678. bnx2_nway_reset(struct net_device *dev)
  5679. {
  5680. struct bnx2 *bp = netdev_priv(dev);
  5681. u32 bmcr;
  5682. if (!netif_running(dev))
  5683. return -EAGAIN;
  5684. if (!(bp->autoneg & AUTONEG_SPEED)) {
  5685. return -EINVAL;
  5686. }
  5687. spin_lock_bh(&bp->phy_lock);
  5688. if (bp->phy_flags & BNX2_PHY_FLAG_REMOTE_PHY_CAP) {
  5689. int rc;
  5690. rc = bnx2_setup_remote_phy(bp, bp->phy_port);
  5691. spin_unlock_bh(&bp->phy_lock);
  5692. return rc;
  5693. }
  5694. /* Force a link down visible on the other side */
  5695. if (bp->phy_flags & BNX2_PHY_FLAG_SERDES) {
  5696. bnx2_write_phy(bp, bp->mii_bmcr, BMCR_LOOPBACK);
  5697. spin_unlock_bh(&bp->phy_lock);
  5698. msleep(20);
  5699. spin_lock_bh(&bp->phy_lock);
  5700. bp->current_interval = BNX2_SERDES_AN_TIMEOUT;
  5701. bp->serdes_an_pending = 1;
  5702. mod_timer(&bp->timer, jiffies + bp->current_interval);
  5703. }
  5704. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  5705. bmcr &= ~BMCR_LOOPBACK;
  5706. bnx2_write_phy(bp, bp->mii_bmcr, bmcr | BMCR_ANRESTART | BMCR_ANENABLE);
  5707. spin_unlock_bh(&bp->phy_lock);
  5708. return 0;
  5709. }
  5710. static u32
  5711. bnx2_get_link(struct net_device *dev)
  5712. {
  5713. struct bnx2 *bp = netdev_priv(dev);
  5714. return bp->link_up;
  5715. }
  5716. static int
  5717. bnx2_get_eeprom_len(struct net_device *dev)
  5718. {
  5719. struct bnx2 *bp = netdev_priv(dev);
  5720. if (bp->flash_info == NULL)
  5721. return 0;
  5722. return (int) bp->flash_size;
  5723. }
  5724. static int
  5725. bnx2_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
  5726. u8 *eebuf)
  5727. {
  5728. struct bnx2 *bp = netdev_priv(dev);
  5729. int rc;
  5730. if (!netif_running(dev))
  5731. return -EAGAIN;
  5732. /* parameters already validated in ethtool_get_eeprom */
  5733. rc = bnx2_nvram_read(bp, eeprom->offset, eebuf, eeprom->len);
  5734. return rc;
  5735. }
  5736. static int
  5737. bnx2_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
  5738. u8 *eebuf)
  5739. {
  5740. struct bnx2 *bp = netdev_priv(dev);
  5741. int rc;
  5742. if (!netif_running(dev))
  5743. return -EAGAIN;
  5744. /* parameters already validated in ethtool_set_eeprom */
  5745. rc = bnx2_nvram_write(bp, eeprom->offset, eebuf, eeprom->len);
  5746. return rc;
  5747. }
  5748. static int
  5749. bnx2_get_coalesce(struct net_device *dev, struct ethtool_coalesce *coal)
  5750. {
  5751. struct bnx2 *bp = netdev_priv(dev);
  5752. memset(coal, 0, sizeof(struct ethtool_coalesce));
  5753. coal->rx_coalesce_usecs = bp->rx_ticks;
  5754. coal->rx_max_coalesced_frames = bp->rx_quick_cons_trip;
  5755. coal->rx_coalesce_usecs_irq = bp->rx_ticks_int;
  5756. coal->rx_max_coalesced_frames_irq = bp->rx_quick_cons_trip_int;
  5757. coal->tx_coalesce_usecs = bp->tx_ticks;
  5758. coal->tx_max_coalesced_frames = bp->tx_quick_cons_trip;
  5759. coal->tx_coalesce_usecs_irq = bp->tx_ticks_int;
  5760. coal->tx_max_coalesced_frames_irq = bp->tx_quick_cons_trip_int;
  5761. coal->stats_block_coalesce_usecs = bp->stats_ticks;
  5762. return 0;
  5763. }
  5764. static int
  5765. bnx2_set_coalesce(struct net_device *dev, struct ethtool_coalesce *coal)
  5766. {
  5767. struct bnx2 *bp = netdev_priv(dev);
  5768. bp->rx_ticks = (u16) coal->rx_coalesce_usecs;
  5769. if (bp->rx_ticks > 0x3ff) bp->rx_ticks = 0x3ff;
  5770. bp->rx_quick_cons_trip = (u16) coal->rx_max_coalesced_frames;
  5771. if (bp->rx_quick_cons_trip > 0xff) bp->rx_quick_cons_trip = 0xff;
  5772. bp->rx_ticks_int = (u16) coal->rx_coalesce_usecs_irq;
  5773. if (bp->rx_ticks_int > 0x3ff) bp->rx_ticks_int = 0x3ff;
  5774. bp->rx_quick_cons_trip_int = (u16) coal->rx_max_coalesced_frames_irq;
  5775. if (bp->rx_quick_cons_trip_int > 0xff)
  5776. bp->rx_quick_cons_trip_int = 0xff;
  5777. bp->tx_ticks = (u16) coal->tx_coalesce_usecs;
  5778. if (bp->tx_ticks > 0x3ff) bp->tx_ticks = 0x3ff;
  5779. bp->tx_quick_cons_trip = (u16) coal->tx_max_coalesced_frames;
  5780. if (bp->tx_quick_cons_trip > 0xff) bp->tx_quick_cons_trip = 0xff;
  5781. bp->tx_ticks_int = (u16) coal->tx_coalesce_usecs_irq;
  5782. if (bp->tx_ticks_int > 0x3ff) bp->tx_ticks_int = 0x3ff;
  5783. bp->tx_quick_cons_trip_int = (u16) coal->tx_max_coalesced_frames_irq;
  5784. if (bp->tx_quick_cons_trip_int > 0xff) bp->tx_quick_cons_trip_int =
  5785. 0xff;
  5786. bp->stats_ticks = coal->stats_block_coalesce_usecs;
  5787. if (bp->flags & BNX2_FLAG_BROKEN_STATS) {
  5788. if (bp->stats_ticks != 0 && bp->stats_ticks != USEC_PER_SEC)
  5789. bp->stats_ticks = USEC_PER_SEC;
  5790. }
  5791. if (bp->stats_ticks > BNX2_HC_STATS_TICKS_HC_STAT_TICKS)
  5792. bp->stats_ticks = BNX2_HC_STATS_TICKS_HC_STAT_TICKS;
  5793. bp->stats_ticks &= BNX2_HC_STATS_TICKS_HC_STAT_TICKS;
  5794. if (netif_running(bp->dev)) {
  5795. bnx2_netif_stop(bp, true);
  5796. bnx2_init_nic(bp, 0);
  5797. bnx2_netif_start(bp, true);
  5798. }
  5799. return 0;
  5800. }
  5801. static void
  5802. bnx2_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
  5803. {
  5804. struct bnx2 *bp = netdev_priv(dev);
  5805. ering->rx_max_pending = MAX_TOTAL_RX_DESC_CNT;
  5806. ering->rx_mini_max_pending = 0;
  5807. ering->rx_jumbo_max_pending = MAX_TOTAL_RX_PG_DESC_CNT;
  5808. ering->rx_pending = bp->rx_ring_size;
  5809. ering->rx_mini_pending = 0;
  5810. ering->rx_jumbo_pending = bp->rx_pg_ring_size;
  5811. ering->tx_max_pending = MAX_TX_DESC_CNT;
  5812. ering->tx_pending = bp->tx_ring_size;
  5813. }
  5814. static int
  5815. bnx2_change_ring_size(struct bnx2 *bp, u32 rx, u32 tx)
  5816. {
  5817. if (netif_running(bp->dev)) {
  5818. /* Reset will erase chipset stats; save them */
  5819. bnx2_save_stats(bp);
  5820. bnx2_netif_stop(bp, true);
  5821. bnx2_reset_chip(bp, BNX2_DRV_MSG_CODE_RESET);
  5822. __bnx2_free_irq(bp);
  5823. bnx2_free_skbs(bp);
  5824. bnx2_free_mem(bp);
  5825. }
  5826. bnx2_set_rx_ring_size(bp, rx);
  5827. bp->tx_ring_size = tx;
  5828. if (netif_running(bp->dev)) {
  5829. int rc;
  5830. rc = bnx2_alloc_mem(bp);
  5831. if (!rc)
  5832. rc = bnx2_request_irq(bp);
  5833. if (!rc)
  5834. rc = bnx2_init_nic(bp, 0);
  5835. if (rc) {
  5836. bnx2_napi_enable(bp);
  5837. dev_close(bp->dev);
  5838. return rc;
  5839. }
  5840. #ifdef BCM_CNIC
  5841. mutex_lock(&bp->cnic_lock);
  5842. /* Let cnic know about the new status block. */
  5843. if (bp->cnic_eth_dev.drv_state & CNIC_DRV_STATE_REGD)
  5844. bnx2_setup_cnic_irq_info(bp);
  5845. mutex_unlock(&bp->cnic_lock);
  5846. #endif
  5847. bnx2_netif_start(bp, true);
  5848. }
  5849. return 0;
  5850. }
  5851. static int
  5852. bnx2_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
  5853. {
  5854. struct bnx2 *bp = netdev_priv(dev);
  5855. int rc;
  5856. if ((ering->rx_pending > MAX_TOTAL_RX_DESC_CNT) ||
  5857. (ering->tx_pending > MAX_TX_DESC_CNT) ||
  5858. (ering->tx_pending <= MAX_SKB_FRAGS)) {
  5859. return -EINVAL;
  5860. }
  5861. rc = bnx2_change_ring_size(bp, ering->rx_pending, ering->tx_pending);
  5862. return rc;
  5863. }
  5864. static void
  5865. bnx2_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
  5866. {
  5867. struct bnx2 *bp = netdev_priv(dev);
  5868. epause->autoneg = ((bp->autoneg & AUTONEG_FLOW_CTRL) != 0);
  5869. epause->rx_pause = ((bp->flow_ctrl & FLOW_CTRL_RX) != 0);
  5870. epause->tx_pause = ((bp->flow_ctrl & FLOW_CTRL_TX) != 0);
  5871. }
  5872. static int
  5873. bnx2_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
  5874. {
  5875. struct bnx2 *bp = netdev_priv(dev);
  5876. bp->req_flow_ctrl = 0;
  5877. if (epause->rx_pause)
  5878. bp->req_flow_ctrl |= FLOW_CTRL_RX;
  5879. if (epause->tx_pause)
  5880. bp->req_flow_ctrl |= FLOW_CTRL_TX;
  5881. if (epause->autoneg) {
  5882. bp->autoneg |= AUTONEG_FLOW_CTRL;
  5883. }
  5884. else {
  5885. bp->autoneg &= ~AUTONEG_FLOW_CTRL;
  5886. }
  5887. if (netif_running(dev)) {
  5888. spin_lock_bh(&bp->phy_lock);
  5889. bnx2_setup_phy(bp, bp->phy_port);
  5890. spin_unlock_bh(&bp->phy_lock);
  5891. }
  5892. return 0;
  5893. }
  5894. static struct {
  5895. char string[ETH_GSTRING_LEN];
  5896. } bnx2_stats_str_arr[] = {
  5897. { "rx_bytes" },
  5898. { "rx_error_bytes" },
  5899. { "tx_bytes" },
  5900. { "tx_error_bytes" },
  5901. { "rx_ucast_packets" },
  5902. { "rx_mcast_packets" },
  5903. { "rx_bcast_packets" },
  5904. { "tx_ucast_packets" },
  5905. { "tx_mcast_packets" },
  5906. { "tx_bcast_packets" },
  5907. { "tx_mac_errors" },
  5908. { "tx_carrier_errors" },
  5909. { "rx_crc_errors" },
  5910. { "rx_align_errors" },
  5911. { "tx_single_collisions" },
  5912. { "tx_multi_collisions" },
  5913. { "tx_deferred" },
  5914. { "tx_excess_collisions" },
  5915. { "tx_late_collisions" },
  5916. { "tx_total_collisions" },
  5917. { "rx_fragments" },
  5918. { "rx_jabbers" },
  5919. { "rx_undersize_packets" },
  5920. { "rx_oversize_packets" },
  5921. { "rx_64_byte_packets" },
  5922. { "rx_65_to_127_byte_packets" },
  5923. { "rx_128_to_255_byte_packets" },
  5924. { "rx_256_to_511_byte_packets" },
  5925. { "rx_512_to_1023_byte_packets" },
  5926. { "rx_1024_to_1522_byte_packets" },
  5927. { "rx_1523_to_9022_byte_packets" },
  5928. { "tx_64_byte_packets" },
  5929. { "tx_65_to_127_byte_packets" },
  5930. { "tx_128_to_255_byte_packets" },
  5931. { "tx_256_to_511_byte_packets" },
  5932. { "tx_512_to_1023_byte_packets" },
  5933. { "tx_1024_to_1522_byte_packets" },
  5934. { "tx_1523_to_9022_byte_packets" },
  5935. { "rx_xon_frames" },
  5936. { "rx_xoff_frames" },
  5937. { "tx_xon_frames" },
  5938. { "tx_xoff_frames" },
  5939. { "rx_mac_ctrl_frames" },
  5940. { "rx_filtered_packets" },
  5941. { "rx_ftq_discards" },
  5942. { "rx_discards" },
  5943. { "rx_fw_discards" },
  5944. };
  5945. #define BNX2_NUM_STATS (sizeof(bnx2_stats_str_arr)/\
  5946. sizeof(bnx2_stats_str_arr[0]))
  5947. #define STATS_OFFSET32(offset_name) (offsetof(struct statistics_block, offset_name) / 4)
  5948. static const unsigned long bnx2_stats_offset_arr[BNX2_NUM_STATS] = {
  5949. STATS_OFFSET32(stat_IfHCInOctets_hi),
  5950. STATS_OFFSET32(stat_IfHCInBadOctets_hi),
  5951. STATS_OFFSET32(stat_IfHCOutOctets_hi),
  5952. STATS_OFFSET32(stat_IfHCOutBadOctets_hi),
  5953. STATS_OFFSET32(stat_IfHCInUcastPkts_hi),
  5954. STATS_OFFSET32(stat_IfHCInMulticastPkts_hi),
  5955. STATS_OFFSET32(stat_IfHCInBroadcastPkts_hi),
  5956. STATS_OFFSET32(stat_IfHCOutUcastPkts_hi),
  5957. STATS_OFFSET32(stat_IfHCOutMulticastPkts_hi),
  5958. STATS_OFFSET32(stat_IfHCOutBroadcastPkts_hi),
  5959. STATS_OFFSET32(stat_emac_tx_stat_dot3statsinternalmactransmiterrors),
  5960. STATS_OFFSET32(stat_Dot3StatsCarrierSenseErrors),
  5961. STATS_OFFSET32(stat_Dot3StatsFCSErrors),
  5962. STATS_OFFSET32(stat_Dot3StatsAlignmentErrors),
  5963. STATS_OFFSET32(stat_Dot3StatsSingleCollisionFrames),
  5964. STATS_OFFSET32(stat_Dot3StatsMultipleCollisionFrames),
  5965. STATS_OFFSET32(stat_Dot3StatsDeferredTransmissions),
  5966. STATS_OFFSET32(stat_Dot3StatsExcessiveCollisions),
  5967. STATS_OFFSET32(stat_Dot3StatsLateCollisions),
  5968. STATS_OFFSET32(stat_EtherStatsCollisions),
  5969. STATS_OFFSET32(stat_EtherStatsFragments),
  5970. STATS_OFFSET32(stat_EtherStatsJabbers),
  5971. STATS_OFFSET32(stat_EtherStatsUndersizePkts),
  5972. STATS_OFFSET32(stat_EtherStatsOverrsizePkts),
  5973. STATS_OFFSET32(stat_EtherStatsPktsRx64Octets),
  5974. STATS_OFFSET32(stat_EtherStatsPktsRx65Octetsto127Octets),
  5975. STATS_OFFSET32(stat_EtherStatsPktsRx128Octetsto255Octets),
  5976. STATS_OFFSET32(stat_EtherStatsPktsRx256Octetsto511Octets),
  5977. STATS_OFFSET32(stat_EtherStatsPktsRx512Octetsto1023Octets),
  5978. STATS_OFFSET32(stat_EtherStatsPktsRx1024Octetsto1522Octets),
  5979. STATS_OFFSET32(stat_EtherStatsPktsRx1523Octetsto9022Octets),
  5980. STATS_OFFSET32(stat_EtherStatsPktsTx64Octets),
  5981. STATS_OFFSET32(stat_EtherStatsPktsTx65Octetsto127Octets),
  5982. STATS_OFFSET32(stat_EtherStatsPktsTx128Octetsto255Octets),
  5983. STATS_OFFSET32(stat_EtherStatsPktsTx256Octetsto511Octets),
  5984. STATS_OFFSET32(stat_EtherStatsPktsTx512Octetsto1023Octets),
  5985. STATS_OFFSET32(stat_EtherStatsPktsTx1024Octetsto1522Octets),
  5986. STATS_OFFSET32(stat_EtherStatsPktsTx1523Octetsto9022Octets),
  5987. STATS_OFFSET32(stat_XonPauseFramesReceived),
  5988. STATS_OFFSET32(stat_XoffPauseFramesReceived),
  5989. STATS_OFFSET32(stat_OutXonSent),
  5990. STATS_OFFSET32(stat_OutXoffSent),
  5991. STATS_OFFSET32(stat_MacControlFramesReceived),
  5992. STATS_OFFSET32(stat_IfInFramesL2FilterDiscards),
  5993. STATS_OFFSET32(stat_IfInFTQDiscards),
  5994. STATS_OFFSET32(stat_IfInMBUFDiscards),
  5995. STATS_OFFSET32(stat_FwRxDrop),
  5996. };
  5997. /* stat_IfHCInBadOctets and stat_Dot3StatsCarrierSenseErrors are
  5998. * skipped because of errata.
  5999. */
  6000. static u8 bnx2_5706_stats_len_arr[BNX2_NUM_STATS] = {
  6001. 8,0,8,8,8,8,8,8,8,8,
  6002. 4,0,4,4,4,4,4,4,4,4,
  6003. 4,4,4,4,4,4,4,4,4,4,
  6004. 4,4,4,4,4,4,4,4,4,4,
  6005. 4,4,4,4,4,4,4,
  6006. };
  6007. static u8 bnx2_5708_stats_len_arr[BNX2_NUM_STATS] = {
  6008. 8,0,8,8,8,8,8,8,8,8,
  6009. 4,4,4,4,4,4,4,4,4,4,
  6010. 4,4,4,4,4,4,4,4,4,4,
  6011. 4,4,4,4,4,4,4,4,4,4,
  6012. 4,4,4,4,4,4,4,
  6013. };
  6014. #define BNX2_NUM_TESTS 6
  6015. static struct {
  6016. char string[ETH_GSTRING_LEN];
  6017. } bnx2_tests_str_arr[BNX2_NUM_TESTS] = {
  6018. { "register_test (offline)" },
  6019. { "memory_test (offline)" },
  6020. { "loopback_test (offline)" },
  6021. { "nvram_test (online)" },
  6022. { "interrupt_test (online)" },
  6023. { "link_test (online)" },
  6024. };
  6025. static int
  6026. bnx2_get_sset_count(struct net_device *dev, int sset)
  6027. {
  6028. switch (sset) {
  6029. case ETH_SS_TEST:
  6030. return BNX2_NUM_TESTS;
  6031. case ETH_SS_STATS:
  6032. return BNX2_NUM_STATS;
  6033. default:
  6034. return -EOPNOTSUPP;
  6035. }
  6036. }
  6037. static void
  6038. bnx2_self_test(struct net_device *dev, struct ethtool_test *etest, u64 *buf)
  6039. {
  6040. struct bnx2 *bp = netdev_priv(dev);
  6041. bnx2_set_power_state(bp, PCI_D0);
  6042. memset(buf, 0, sizeof(u64) * BNX2_NUM_TESTS);
  6043. if (etest->flags & ETH_TEST_FL_OFFLINE) {
  6044. int i;
  6045. bnx2_netif_stop(bp, true);
  6046. bnx2_reset_chip(bp, BNX2_DRV_MSG_CODE_DIAG);
  6047. bnx2_free_skbs(bp);
  6048. if (bnx2_test_registers(bp) != 0) {
  6049. buf[0] = 1;
  6050. etest->flags |= ETH_TEST_FL_FAILED;
  6051. }
  6052. if (bnx2_test_memory(bp) != 0) {
  6053. buf[1] = 1;
  6054. etest->flags |= ETH_TEST_FL_FAILED;
  6055. }
  6056. if ((buf[2] = bnx2_test_loopback(bp)) != 0)
  6057. etest->flags |= ETH_TEST_FL_FAILED;
  6058. if (!netif_running(bp->dev))
  6059. bnx2_shutdown_chip(bp);
  6060. else {
  6061. bnx2_init_nic(bp, 1);
  6062. bnx2_netif_start(bp, true);
  6063. }
  6064. /* wait for link up */
  6065. for (i = 0; i < 7; i++) {
  6066. if (bp->link_up)
  6067. break;
  6068. msleep_interruptible(1000);
  6069. }
  6070. }
  6071. if (bnx2_test_nvram(bp) != 0) {
  6072. buf[3] = 1;
  6073. etest->flags |= ETH_TEST_FL_FAILED;
  6074. }
  6075. if (bnx2_test_intr(bp) != 0) {
  6076. buf[4] = 1;
  6077. etest->flags |= ETH_TEST_FL_FAILED;
  6078. }
  6079. if (bnx2_test_link(bp) != 0) {
  6080. buf[5] = 1;
  6081. etest->flags |= ETH_TEST_FL_FAILED;
  6082. }
  6083. if (!netif_running(bp->dev))
  6084. bnx2_set_power_state(bp, PCI_D3hot);
  6085. }
  6086. static void
  6087. bnx2_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
  6088. {
  6089. switch (stringset) {
  6090. case ETH_SS_STATS:
  6091. memcpy(buf, bnx2_stats_str_arr,
  6092. sizeof(bnx2_stats_str_arr));
  6093. break;
  6094. case ETH_SS_TEST:
  6095. memcpy(buf, bnx2_tests_str_arr,
  6096. sizeof(bnx2_tests_str_arr));
  6097. break;
  6098. }
  6099. }
  6100. static void
  6101. bnx2_get_ethtool_stats(struct net_device *dev,
  6102. struct ethtool_stats *stats, u64 *buf)
  6103. {
  6104. struct bnx2 *bp = netdev_priv(dev);
  6105. int i;
  6106. u32 *hw_stats = (u32 *) bp->stats_blk;
  6107. u32 *temp_stats = (u32 *) bp->temp_stats_blk;
  6108. u8 *stats_len_arr = NULL;
  6109. if (hw_stats == NULL) {
  6110. memset(buf, 0, sizeof(u64) * BNX2_NUM_STATS);
  6111. return;
  6112. }
  6113. if ((CHIP_ID(bp) == CHIP_ID_5706_A0) ||
  6114. (CHIP_ID(bp) == CHIP_ID_5706_A1) ||
  6115. (CHIP_ID(bp) == CHIP_ID_5706_A2) ||
  6116. (CHIP_ID(bp) == CHIP_ID_5708_A0))
  6117. stats_len_arr = bnx2_5706_stats_len_arr;
  6118. else
  6119. stats_len_arr = bnx2_5708_stats_len_arr;
  6120. for (i = 0; i < BNX2_NUM_STATS; i++) {
  6121. unsigned long offset;
  6122. if (stats_len_arr[i] == 0) {
  6123. /* skip this counter */
  6124. buf[i] = 0;
  6125. continue;
  6126. }
  6127. offset = bnx2_stats_offset_arr[i];
  6128. if (stats_len_arr[i] == 4) {
  6129. /* 4-byte counter */
  6130. buf[i] = (u64) *(hw_stats + offset) +
  6131. *(temp_stats + offset);
  6132. continue;
  6133. }
  6134. /* 8-byte counter */
  6135. buf[i] = (((u64) *(hw_stats + offset)) << 32) +
  6136. *(hw_stats + offset + 1) +
  6137. (((u64) *(temp_stats + offset)) << 32) +
  6138. *(temp_stats + offset + 1);
  6139. }
  6140. }
  6141. static int
  6142. bnx2_set_phys_id(struct net_device *dev, enum ethtool_phys_id_state state)
  6143. {
  6144. struct bnx2 *bp = netdev_priv(dev);
  6145. switch (state) {
  6146. case ETHTOOL_ID_ACTIVE:
  6147. bnx2_set_power_state(bp, PCI_D0);
  6148. bp->leds_save = REG_RD(bp, BNX2_MISC_CFG);
  6149. REG_WR(bp, BNX2_MISC_CFG, BNX2_MISC_CFG_LEDMODE_MAC);
  6150. return 1; /* cycle on/off once per second */
  6151. case ETHTOOL_ID_ON:
  6152. REG_WR(bp, BNX2_EMAC_LED, BNX2_EMAC_LED_OVERRIDE |
  6153. BNX2_EMAC_LED_1000MB_OVERRIDE |
  6154. BNX2_EMAC_LED_100MB_OVERRIDE |
  6155. BNX2_EMAC_LED_10MB_OVERRIDE |
  6156. BNX2_EMAC_LED_TRAFFIC_OVERRIDE |
  6157. BNX2_EMAC_LED_TRAFFIC);
  6158. break;
  6159. case ETHTOOL_ID_OFF:
  6160. REG_WR(bp, BNX2_EMAC_LED, BNX2_EMAC_LED_OVERRIDE);
  6161. break;
  6162. case ETHTOOL_ID_INACTIVE:
  6163. REG_WR(bp, BNX2_EMAC_LED, 0);
  6164. REG_WR(bp, BNX2_MISC_CFG, bp->leds_save);
  6165. if (!netif_running(dev))
  6166. bnx2_set_power_state(bp, PCI_D3hot);
  6167. break;
  6168. }
  6169. return 0;
  6170. }
  6171. static u32
  6172. bnx2_fix_features(struct net_device *dev, u32 features)
  6173. {
  6174. struct bnx2 *bp = netdev_priv(dev);
  6175. if (!(bp->flags & BNX2_FLAG_CAN_KEEP_VLAN))
  6176. features |= NETIF_F_HW_VLAN_RX;
  6177. return features;
  6178. }
  6179. static int
  6180. bnx2_set_features(struct net_device *dev, u32 features)
  6181. {
  6182. struct bnx2 *bp = netdev_priv(dev);
  6183. /* TSO with VLAN tag won't work with current firmware */
  6184. if (features & NETIF_F_HW_VLAN_TX)
  6185. dev->vlan_features |= (dev->hw_features & NETIF_F_ALL_TSO);
  6186. else
  6187. dev->vlan_features &= ~NETIF_F_ALL_TSO;
  6188. if ((!!(features & NETIF_F_HW_VLAN_RX) !=
  6189. !!(bp->rx_mode & BNX2_EMAC_RX_MODE_KEEP_VLAN_TAG)) &&
  6190. netif_running(dev)) {
  6191. bnx2_netif_stop(bp, false);
  6192. dev->features = features;
  6193. bnx2_set_rx_mode(dev);
  6194. bnx2_fw_sync(bp, BNX2_DRV_MSG_CODE_KEEP_VLAN_UPDATE, 0, 1);
  6195. bnx2_netif_start(bp, false);
  6196. return 1;
  6197. }
  6198. return 0;
  6199. }
  6200. static const struct ethtool_ops bnx2_ethtool_ops = {
  6201. .get_settings = bnx2_get_settings,
  6202. .set_settings = bnx2_set_settings,
  6203. .get_drvinfo = bnx2_get_drvinfo,
  6204. .get_regs_len = bnx2_get_regs_len,
  6205. .get_regs = bnx2_get_regs,
  6206. .get_wol = bnx2_get_wol,
  6207. .set_wol = bnx2_set_wol,
  6208. .nway_reset = bnx2_nway_reset,
  6209. .get_link = bnx2_get_link,
  6210. .get_eeprom_len = bnx2_get_eeprom_len,
  6211. .get_eeprom = bnx2_get_eeprom,
  6212. .set_eeprom = bnx2_set_eeprom,
  6213. .get_coalesce = bnx2_get_coalesce,
  6214. .set_coalesce = bnx2_set_coalesce,
  6215. .get_ringparam = bnx2_get_ringparam,
  6216. .set_ringparam = bnx2_set_ringparam,
  6217. .get_pauseparam = bnx2_get_pauseparam,
  6218. .set_pauseparam = bnx2_set_pauseparam,
  6219. .self_test = bnx2_self_test,
  6220. .get_strings = bnx2_get_strings,
  6221. .set_phys_id = bnx2_set_phys_id,
  6222. .get_ethtool_stats = bnx2_get_ethtool_stats,
  6223. .get_sset_count = bnx2_get_sset_count,
  6224. };
  6225. /* Called with rtnl_lock */
  6226. static int
  6227. bnx2_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  6228. {
  6229. struct mii_ioctl_data *data = if_mii(ifr);
  6230. struct bnx2 *bp = netdev_priv(dev);
  6231. int err;
  6232. switch(cmd) {
  6233. case SIOCGMIIPHY:
  6234. data->phy_id = bp->phy_addr;
  6235. /* fallthru */
  6236. case SIOCGMIIREG: {
  6237. u32 mii_regval;
  6238. if (bp->phy_flags & BNX2_PHY_FLAG_REMOTE_PHY_CAP)
  6239. return -EOPNOTSUPP;
  6240. if (!netif_running(dev))
  6241. return -EAGAIN;
  6242. spin_lock_bh(&bp->phy_lock);
  6243. err = bnx2_read_phy(bp, data->reg_num & 0x1f, &mii_regval);
  6244. spin_unlock_bh(&bp->phy_lock);
  6245. data->val_out = mii_regval;
  6246. return err;
  6247. }
  6248. case SIOCSMIIREG:
  6249. if (bp->phy_flags & BNX2_PHY_FLAG_REMOTE_PHY_CAP)
  6250. return -EOPNOTSUPP;
  6251. if (!netif_running(dev))
  6252. return -EAGAIN;
  6253. spin_lock_bh(&bp->phy_lock);
  6254. err = bnx2_write_phy(bp, data->reg_num & 0x1f, data->val_in);
  6255. spin_unlock_bh(&bp->phy_lock);
  6256. return err;
  6257. default:
  6258. /* do nothing */
  6259. break;
  6260. }
  6261. return -EOPNOTSUPP;
  6262. }
  6263. /* Called with rtnl_lock */
  6264. static int
  6265. bnx2_change_mac_addr(struct net_device *dev, void *p)
  6266. {
  6267. struct sockaddr *addr = p;
  6268. struct bnx2 *bp = netdev_priv(dev);
  6269. if (!is_valid_ether_addr(addr->sa_data))
  6270. return -EINVAL;
  6271. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  6272. if (netif_running(dev))
  6273. bnx2_set_mac_addr(bp, bp->dev->dev_addr, 0);
  6274. return 0;
  6275. }
  6276. /* Called with rtnl_lock */
  6277. static int
  6278. bnx2_change_mtu(struct net_device *dev, int new_mtu)
  6279. {
  6280. struct bnx2 *bp = netdev_priv(dev);
  6281. if (((new_mtu + ETH_HLEN) > MAX_ETHERNET_JUMBO_PACKET_SIZE) ||
  6282. ((new_mtu + ETH_HLEN) < MIN_ETHERNET_PACKET_SIZE))
  6283. return -EINVAL;
  6284. dev->mtu = new_mtu;
  6285. return bnx2_change_ring_size(bp, bp->rx_ring_size, bp->tx_ring_size);
  6286. }
  6287. #ifdef CONFIG_NET_POLL_CONTROLLER
  6288. static void
  6289. poll_bnx2(struct net_device *dev)
  6290. {
  6291. struct bnx2 *bp = netdev_priv(dev);
  6292. int i;
  6293. for (i = 0; i < bp->irq_nvecs; i++) {
  6294. struct bnx2_irq *irq = &bp->irq_tbl[i];
  6295. disable_irq(irq->vector);
  6296. irq->handler(irq->vector, &bp->bnx2_napi[i]);
  6297. enable_irq(irq->vector);
  6298. }
  6299. }
  6300. #endif
  6301. static void __devinit
  6302. bnx2_get_5709_media(struct bnx2 *bp)
  6303. {
  6304. u32 val = REG_RD(bp, BNX2_MISC_DUAL_MEDIA_CTRL);
  6305. u32 bond_id = val & BNX2_MISC_DUAL_MEDIA_CTRL_BOND_ID;
  6306. u32 strap;
  6307. if (bond_id == BNX2_MISC_DUAL_MEDIA_CTRL_BOND_ID_C)
  6308. return;
  6309. else if (bond_id == BNX2_MISC_DUAL_MEDIA_CTRL_BOND_ID_S) {
  6310. bp->phy_flags |= BNX2_PHY_FLAG_SERDES;
  6311. return;
  6312. }
  6313. if (val & BNX2_MISC_DUAL_MEDIA_CTRL_STRAP_OVERRIDE)
  6314. strap = (val & BNX2_MISC_DUAL_MEDIA_CTRL_PHY_CTRL) >> 21;
  6315. else
  6316. strap = (val & BNX2_MISC_DUAL_MEDIA_CTRL_PHY_CTRL_STRAP) >> 8;
  6317. if (PCI_FUNC(bp->pdev->devfn) == 0) {
  6318. switch (strap) {
  6319. case 0x4:
  6320. case 0x5:
  6321. case 0x6:
  6322. bp->phy_flags |= BNX2_PHY_FLAG_SERDES;
  6323. return;
  6324. }
  6325. } else {
  6326. switch (strap) {
  6327. case 0x1:
  6328. case 0x2:
  6329. case 0x4:
  6330. bp->phy_flags |= BNX2_PHY_FLAG_SERDES;
  6331. return;
  6332. }
  6333. }
  6334. }
  6335. static void __devinit
  6336. bnx2_get_pci_speed(struct bnx2 *bp)
  6337. {
  6338. u32 reg;
  6339. reg = REG_RD(bp, BNX2_PCICFG_MISC_STATUS);
  6340. if (reg & BNX2_PCICFG_MISC_STATUS_PCIX_DET) {
  6341. u32 clkreg;
  6342. bp->flags |= BNX2_FLAG_PCIX;
  6343. clkreg = REG_RD(bp, BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS);
  6344. clkreg &= BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET;
  6345. switch (clkreg) {
  6346. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_133MHZ:
  6347. bp->bus_speed_mhz = 133;
  6348. break;
  6349. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_95MHZ:
  6350. bp->bus_speed_mhz = 100;
  6351. break;
  6352. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_66MHZ:
  6353. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_80MHZ:
  6354. bp->bus_speed_mhz = 66;
  6355. break;
  6356. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_48MHZ:
  6357. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_55MHZ:
  6358. bp->bus_speed_mhz = 50;
  6359. break;
  6360. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_LOW:
  6361. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_32MHZ:
  6362. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_38MHZ:
  6363. bp->bus_speed_mhz = 33;
  6364. break;
  6365. }
  6366. }
  6367. else {
  6368. if (reg & BNX2_PCICFG_MISC_STATUS_M66EN)
  6369. bp->bus_speed_mhz = 66;
  6370. else
  6371. bp->bus_speed_mhz = 33;
  6372. }
  6373. if (reg & BNX2_PCICFG_MISC_STATUS_32BIT_DET)
  6374. bp->flags |= BNX2_FLAG_PCI_32BIT;
  6375. }
  6376. static void __devinit
  6377. bnx2_read_vpd_fw_ver(struct bnx2 *bp)
  6378. {
  6379. int rc, i, j;
  6380. u8 *data;
  6381. unsigned int block_end, rosize, len;
  6382. #define BNX2_VPD_NVRAM_OFFSET 0x300
  6383. #define BNX2_VPD_LEN 128
  6384. #define BNX2_MAX_VER_SLEN 30
  6385. data = kmalloc(256, GFP_KERNEL);
  6386. if (!data)
  6387. return;
  6388. rc = bnx2_nvram_read(bp, BNX2_VPD_NVRAM_OFFSET, data + BNX2_VPD_LEN,
  6389. BNX2_VPD_LEN);
  6390. if (rc)
  6391. goto vpd_done;
  6392. for (i = 0; i < BNX2_VPD_LEN; i += 4) {
  6393. data[i] = data[i + BNX2_VPD_LEN + 3];
  6394. data[i + 1] = data[i + BNX2_VPD_LEN + 2];
  6395. data[i + 2] = data[i + BNX2_VPD_LEN + 1];
  6396. data[i + 3] = data[i + BNX2_VPD_LEN];
  6397. }
  6398. i = pci_vpd_find_tag(data, 0, BNX2_VPD_LEN, PCI_VPD_LRDT_RO_DATA);
  6399. if (i < 0)
  6400. goto vpd_done;
  6401. rosize = pci_vpd_lrdt_size(&data[i]);
  6402. i += PCI_VPD_LRDT_TAG_SIZE;
  6403. block_end = i + rosize;
  6404. if (block_end > BNX2_VPD_LEN)
  6405. goto vpd_done;
  6406. j = pci_vpd_find_info_keyword(data, i, rosize,
  6407. PCI_VPD_RO_KEYWORD_MFR_ID);
  6408. if (j < 0)
  6409. goto vpd_done;
  6410. len = pci_vpd_info_field_size(&data[j]);
  6411. j += PCI_VPD_INFO_FLD_HDR_SIZE;
  6412. if (j + len > block_end || len != 4 ||
  6413. memcmp(&data[j], "1028", 4))
  6414. goto vpd_done;
  6415. j = pci_vpd_find_info_keyword(data, i, rosize,
  6416. PCI_VPD_RO_KEYWORD_VENDOR0);
  6417. if (j < 0)
  6418. goto vpd_done;
  6419. len = pci_vpd_info_field_size(&data[j]);
  6420. j += PCI_VPD_INFO_FLD_HDR_SIZE;
  6421. if (j + len > block_end || len > BNX2_MAX_VER_SLEN)
  6422. goto vpd_done;
  6423. memcpy(bp->fw_version, &data[j], len);
  6424. bp->fw_version[len] = ' ';
  6425. vpd_done:
  6426. kfree(data);
  6427. }
  6428. static int __devinit
  6429. bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
  6430. {
  6431. struct bnx2 *bp;
  6432. unsigned long mem_len;
  6433. int rc, i, j;
  6434. u32 reg;
  6435. u64 dma_mask, persist_dma_mask;
  6436. int err;
  6437. SET_NETDEV_DEV(dev, &pdev->dev);
  6438. bp = netdev_priv(dev);
  6439. bp->flags = 0;
  6440. bp->phy_flags = 0;
  6441. bp->temp_stats_blk =
  6442. kzalloc(sizeof(struct statistics_block), GFP_KERNEL);
  6443. if (bp->temp_stats_blk == NULL) {
  6444. rc = -ENOMEM;
  6445. goto err_out;
  6446. }
  6447. /* enable device (incl. PCI PM wakeup), and bus-mastering */
  6448. rc = pci_enable_device(pdev);
  6449. if (rc) {
  6450. dev_err(&pdev->dev, "Cannot enable PCI device, aborting\n");
  6451. goto err_out;
  6452. }
  6453. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  6454. dev_err(&pdev->dev,
  6455. "Cannot find PCI device base address, aborting\n");
  6456. rc = -ENODEV;
  6457. goto err_out_disable;
  6458. }
  6459. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  6460. if (rc) {
  6461. dev_err(&pdev->dev, "Cannot obtain PCI resources, aborting\n");
  6462. goto err_out_disable;
  6463. }
  6464. pci_set_master(pdev);
  6465. bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  6466. if (bp->pm_cap == 0) {
  6467. dev_err(&pdev->dev,
  6468. "Cannot find power management capability, aborting\n");
  6469. rc = -EIO;
  6470. goto err_out_release;
  6471. }
  6472. bp->dev = dev;
  6473. bp->pdev = pdev;
  6474. spin_lock_init(&bp->phy_lock);
  6475. spin_lock_init(&bp->indirect_lock);
  6476. #ifdef BCM_CNIC
  6477. mutex_init(&bp->cnic_lock);
  6478. #endif
  6479. INIT_WORK(&bp->reset_task, bnx2_reset_task);
  6480. dev->base_addr = dev->mem_start = pci_resource_start(pdev, 0);
  6481. mem_len = MB_GET_CID_ADDR(TX_TSS_CID + TX_MAX_TSS_RINGS + 1);
  6482. dev->mem_end = dev->mem_start + mem_len;
  6483. dev->irq = pdev->irq;
  6484. bp->regview = ioremap_nocache(dev->base_addr, mem_len);
  6485. if (!bp->regview) {
  6486. dev_err(&pdev->dev, "Cannot map register space, aborting\n");
  6487. rc = -ENOMEM;
  6488. goto err_out_release;
  6489. }
  6490. bnx2_set_power_state(bp, PCI_D0);
  6491. /* Configure byte swap and enable write to the reg_window registers.
  6492. * Rely on CPU to do target byte swapping on big endian systems
  6493. * The chip's target access swapping will not swap all accesses
  6494. */
  6495. REG_WR(bp, BNX2_PCICFG_MISC_CONFIG,
  6496. BNX2_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
  6497. BNX2_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP);
  6498. bp->chip_id = REG_RD(bp, BNX2_MISC_ID);
  6499. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  6500. if (!pci_is_pcie(pdev)) {
  6501. dev_err(&pdev->dev, "Not PCIE, aborting\n");
  6502. rc = -EIO;
  6503. goto err_out_unmap;
  6504. }
  6505. bp->flags |= BNX2_FLAG_PCIE;
  6506. if (CHIP_REV(bp) == CHIP_REV_Ax)
  6507. bp->flags |= BNX2_FLAG_JUMBO_BROKEN;
  6508. /* AER (Advanced Error Reporting) hooks */
  6509. err = pci_enable_pcie_error_reporting(pdev);
  6510. if (!err)
  6511. bp->flags |= BNX2_FLAG_AER_ENABLED;
  6512. } else {
  6513. bp->pcix_cap = pci_find_capability(pdev, PCI_CAP_ID_PCIX);
  6514. if (bp->pcix_cap == 0) {
  6515. dev_err(&pdev->dev,
  6516. "Cannot find PCIX capability, aborting\n");
  6517. rc = -EIO;
  6518. goto err_out_unmap;
  6519. }
  6520. bp->flags |= BNX2_FLAG_BROKEN_STATS;
  6521. }
  6522. if (CHIP_NUM(bp) == CHIP_NUM_5709 && CHIP_REV(bp) != CHIP_REV_Ax) {
  6523. if (pci_find_capability(pdev, PCI_CAP_ID_MSIX))
  6524. bp->flags |= BNX2_FLAG_MSIX_CAP;
  6525. }
  6526. if (CHIP_ID(bp) != CHIP_ID_5706_A0 && CHIP_ID(bp) != CHIP_ID_5706_A1) {
  6527. if (pci_find_capability(pdev, PCI_CAP_ID_MSI))
  6528. bp->flags |= BNX2_FLAG_MSI_CAP;
  6529. }
  6530. /* 5708 cannot support DMA addresses > 40-bit. */
  6531. if (CHIP_NUM(bp) == CHIP_NUM_5708)
  6532. persist_dma_mask = dma_mask = DMA_BIT_MASK(40);
  6533. else
  6534. persist_dma_mask = dma_mask = DMA_BIT_MASK(64);
  6535. /* Configure DMA attributes. */
  6536. if (pci_set_dma_mask(pdev, dma_mask) == 0) {
  6537. dev->features |= NETIF_F_HIGHDMA;
  6538. rc = pci_set_consistent_dma_mask(pdev, persist_dma_mask);
  6539. if (rc) {
  6540. dev_err(&pdev->dev,
  6541. "pci_set_consistent_dma_mask failed, aborting\n");
  6542. goto err_out_unmap;
  6543. }
  6544. } else if ((rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) != 0) {
  6545. dev_err(&pdev->dev, "System does not support DMA, aborting\n");
  6546. goto err_out_unmap;
  6547. }
  6548. if (!(bp->flags & BNX2_FLAG_PCIE))
  6549. bnx2_get_pci_speed(bp);
  6550. /* 5706A0 may falsely detect SERR and PERR. */
  6551. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  6552. reg = REG_RD(bp, PCI_COMMAND);
  6553. reg &= ~(PCI_COMMAND_SERR | PCI_COMMAND_PARITY);
  6554. REG_WR(bp, PCI_COMMAND, reg);
  6555. }
  6556. else if ((CHIP_ID(bp) == CHIP_ID_5706_A1) &&
  6557. !(bp->flags & BNX2_FLAG_PCIX)) {
  6558. dev_err(&pdev->dev,
  6559. "5706 A1 can only be used in a PCIX bus, aborting\n");
  6560. goto err_out_unmap;
  6561. }
  6562. bnx2_init_nvram(bp);
  6563. reg = bnx2_reg_rd_ind(bp, BNX2_SHM_HDR_SIGNATURE);
  6564. if ((reg & BNX2_SHM_HDR_SIGNATURE_SIG_MASK) ==
  6565. BNX2_SHM_HDR_SIGNATURE_SIG) {
  6566. u32 off = PCI_FUNC(pdev->devfn) << 2;
  6567. bp->shmem_base = bnx2_reg_rd_ind(bp, BNX2_SHM_HDR_ADDR_0 + off);
  6568. } else
  6569. bp->shmem_base = HOST_VIEW_SHMEM_BASE;
  6570. /* Get the permanent MAC address. First we need to make sure the
  6571. * firmware is actually running.
  6572. */
  6573. reg = bnx2_shmem_rd(bp, BNX2_DEV_INFO_SIGNATURE);
  6574. if ((reg & BNX2_DEV_INFO_SIGNATURE_MAGIC_MASK) !=
  6575. BNX2_DEV_INFO_SIGNATURE_MAGIC) {
  6576. dev_err(&pdev->dev, "Firmware not running, aborting\n");
  6577. rc = -ENODEV;
  6578. goto err_out_unmap;
  6579. }
  6580. bnx2_read_vpd_fw_ver(bp);
  6581. j = strlen(bp->fw_version);
  6582. reg = bnx2_shmem_rd(bp, BNX2_DEV_INFO_BC_REV);
  6583. for (i = 0; i < 3 && j < 24; i++) {
  6584. u8 num, k, skip0;
  6585. if (i == 0) {
  6586. bp->fw_version[j++] = 'b';
  6587. bp->fw_version[j++] = 'c';
  6588. bp->fw_version[j++] = ' ';
  6589. }
  6590. num = (u8) (reg >> (24 - (i * 8)));
  6591. for (k = 100, skip0 = 1; k >= 1; num %= k, k /= 10) {
  6592. if (num >= k || !skip0 || k == 1) {
  6593. bp->fw_version[j++] = (num / k) + '0';
  6594. skip0 = 0;
  6595. }
  6596. }
  6597. if (i != 2)
  6598. bp->fw_version[j++] = '.';
  6599. }
  6600. reg = bnx2_shmem_rd(bp, BNX2_PORT_FEATURE);
  6601. if (reg & BNX2_PORT_FEATURE_WOL_ENABLED)
  6602. bp->wol = 1;
  6603. if (reg & BNX2_PORT_FEATURE_ASF_ENABLED) {
  6604. bp->flags |= BNX2_FLAG_ASF_ENABLE;
  6605. for (i = 0; i < 30; i++) {
  6606. reg = bnx2_shmem_rd(bp, BNX2_BC_STATE_CONDITION);
  6607. if (reg & BNX2_CONDITION_MFW_RUN_MASK)
  6608. break;
  6609. msleep(10);
  6610. }
  6611. }
  6612. reg = bnx2_shmem_rd(bp, BNX2_BC_STATE_CONDITION);
  6613. reg &= BNX2_CONDITION_MFW_RUN_MASK;
  6614. if (reg != BNX2_CONDITION_MFW_RUN_UNKNOWN &&
  6615. reg != BNX2_CONDITION_MFW_RUN_NONE) {
  6616. u32 addr = bnx2_shmem_rd(bp, BNX2_MFW_VER_PTR);
  6617. if (j < 32)
  6618. bp->fw_version[j++] = ' ';
  6619. for (i = 0; i < 3 && j < 28; i++) {
  6620. reg = bnx2_reg_rd_ind(bp, addr + i * 4);
  6621. reg = swab32(reg);
  6622. memcpy(&bp->fw_version[j], &reg, 4);
  6623. j += 4;
  6624. }
  6625. }
  6626. reg = bnx2_shmem_rd(bp, BNX2_PORT_HW_CFG_MAC_UPPER);
  6627. bp->mac_addr[0] = (u8) (reg >> 8);
  6628. bp->mac_addr[1] = (u8) reg;
  6629. reg = bnx2_shmem_rd(bp, BNX2_PORT_HW_CFG_MAC_LOWER);
  6630. bp->mac_addr[2] = (u8) (reg >> 24);
  6631. bp->mac_addr[3] = (u8) (reg >> 16);
  6632. bp->mac_addr[4] = (u8) (reg >> 8);
  6633. bp->mac_addr[5] = (u8) reg;
  6634. bp->tx_ring_size = MAX_TX_DESC_CNT;
  6635. bnx2_set_rx_ring_size(bp, 255);
  6636. bp->tx_quick_cons_trip_int = 2;
  6637. bp->tx_quick_cons_trip = 20;
  6638. bp->tx_ticks_int = 18;
  6639. bp->tx_ticks = 80;
  6640. bp->rx_quick_cons_trip_int = 2;
  6641. bp->rx_quick_cons_trip = 12;
  6642. bp->rx_ticks_int = 18;
  6643. bp->rx_ticks = 18;
  6644. bp->stats_ticks = USEC_PER_SEC & BNX2_HC_STATS_TICKS_HC_STAT_TICKS;
  6645. bp->current_interval = BNX2_TIMER_INTERVAL;
  6646. bp->phy_addr = 1;
  6647. /* Disable WOL support if we are running on a SERDES chip. */
  6648. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  6649. bnx2_get_5709_media(bp);
  6650. else if (CHIP_BOND_ID(bp) & CHIP_BOND_ID_SERDES_BIT)
  6651. bp->phy_flags |= BNX2_PHY_FLAG_SERDES;
  6652. bp->phy_port = PORT_TP;
  6653. if (bp->phy_flags & BNX2_PHY_FLAG_SERDES) {
  6654. bp->phy_port = PORT_FIBRE;
  6655. reg = bnx2_shmem_rd(bp, BNX2_SHARED_HW_CFG_CONFIG);
  6656. if (!(reg & BNX2_SHARED_HW_CFG_GIG_LINK_ON_VAUX)) {
  6657. bp->flags |= BNX2_FLAG_NO_WOL;
  6658. bp->wol = 0;
  6659. }
  6660. if (CHIP_NUM(bp) == CHIP_NUM_5706) {
  6661. /* Don't do parallel detect on this board because of
  6662. * some board problems. The link will not go down
  6663. * if we do parallel detect.
  6664. */
  6665. if (pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
  6666. pdev->subsystem_device == 0x310c)
  6667. bp->phy_flags |= BNX2_PHY_FLAG_NO_PARALLEL;
  6668. } else {
  6669. bp->phy_addr = 2;
  6670. if (reg & BNX2_SHARED_HW_CFG_PHY_2_5G)
  6671. bp->phy_flags |= BNX2_PHY_FLAG_2_5G_CAPABLE;
  6672. }
  6673. } else if (CHIP_NUM(bp) == CHIP_NUM_5706 ||
  6674. CHIP_NUM(bp) == CHIP_NUM_5708)
  6675. bp->phy_flags |= BNX2_PHY_FLAG_CRC_FIX;
  6676. else if (CHIP_NUM(bp) == CHIP_NUM_5709 &&
  6677. (CHIP_REV(bp) == CHIP_REV_Ax ||
  6678. CHIP_REV(bp) == CHIP_REV_Bx))
  6679. bp->phy_flags |= BNX2_PHY_FLAG_DIS_EARLY_DAC;
  6680. bnx2_init_fw_cap(bp);
  6681. if ((CHIP_ID(bp) == CHIP_ID_5708_A0) ||
  6682. (CHIP_ID(bp) == CHIP_ID_5708_B0) ||
  6683. (CHIP_ID(bp) == CHIP_ID_5708_B1) ||
  6684. !(REG_RD(bp, BNX2_PCI_CONFIG_3) & BNX2_PCI_CONFIG_3_VAUX_PRESET)) {
  6685. bp->flags |= BNX2_FLAG_NO_WOL;
  6686. bp->wol = 0;
  6687. }
  6688. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  6689. bp->tx_quick_cons_trip_int =
  6690. bp->tx_quick_cons_trip;
  6691. bp->tx_ticks_int = bp->tx_ticks;
  6692. bp->rx_quick_cons_trip_int =
  6693. bp->rx_quick_cons_trip;
  6694. bp->rx_ticks_int = bp->rx_ticks;
  6695. bp->comp_prod_trip_int = bp->comp_prod_trip;
  6696. bp->com_ticks_int = bp->com_ticks;
  6697. bp->cmd_ticks_int = bp->cmd_ticks;
  6698. }
  6699. /* Disable MSI on 5706 if AMD 8132 bridge is found.
  6700. *
  6701. * MSI is defined to be 32-bit write. The 5706 does 64-bit MSI writes
  6702. * with byte enables disabled on the unused 32-bit word. This is legal
  6703. * but causes problems on the AMD 8132 which will eventually stop
  6704. * responding after a while.
  6705. *
  6706. * AMD believes this incompatibility is unique to the 5706, and
  6707. * prefers to locally disable MSI rather than globally disabling it.
  6708. */
  6709. if (CHIP_NUM(bp) == CHIP_NUM_5706 && disable_msi == 0) {
  6710. struct pci_dev *amd_8132 = NULL;
  6711. while ((amd_8132 = pci_get_device(PCI_VENDOR_ID_AMD,
  6712. PCI_DEVICE_ID_AMD_8132_BRIDGE,
  6713. amd_8132))) {
  6714. if (amd_8132->revision >= 0x10 &&
  6715. amd_8132->revision <= 0x13) {
  6716. disable_msi = 1;
  6717. pci_dev_put(amd_8132);
  6718. break;
  6719. }
  6720. }
  6721. }
  6722. bnx2_set_default_link(bp);
  6723. bp->req_flow_ctrl = FLOW_CTRL_RX | FLOW_CTRL_TX;
  6724. init_timer(&bp->timer);
  6725. bp->timer.expires = RUN_AT(BNX2_TIMER_INTERVAL);
  6726. bp->timer.data = (unsigned long) bp;
  6727. bp->timer.function = bnx2_timer;
  6728. #ifdef BCM_CNIC
  6729. if (bnx2_shmem_rd(bp, BNX2_ISCSI_INITIATOR) & BNX2_ISCSI_INITIATOR_EN)
  6730. bp->cnic_eth_dev.max_iscsi_conn =
  6731. (bnx2_shmem_rd(bp, BNX2_ISCSI_MAX_CONN) &
  6732. BNX2_ISCSI_MAX_CONN_MASK) >> BNX2_ISCSI_MAX_CONN_SHIFT;
  6733. #endif
  6734. pci_save_state(pdev);
  6735. return 0;
  6736. err_out_unmap:
  6737. if (bp->flags & BNX2_FLAG_AER_ENABLED) {
  6738. pci_disable_pcie_error_reporting(pdev);
  6739. bp->flags &= ~BNX2_FLAG_AER_ENABLED;
  6740. }
  6741. if (bp->regview) {
  6742. iounmap(bp->regview);
  6743. bp->regview = NULL;
  6744. }
  6745. err_out_release:
  6746. pci_release_regions(pdev);
  6747. err_out_disable:
  6748. pci_disable_device(pdev);
  6749. pci_set_drvdata(pdev, NULL);
  6750. err_out:
  6751. return rc;
  6752. }
  6753. static char * __devinit
  6754. bnx2_bus_string(struct bnx2 *bp, char *str)
  6755. {
  6756. char *s = str;
  6757. if (bp->flags & BNX2_FLAG_PCIE) {
  6758. s += sprintf(s, "PCI Express");
  6759. } else {
  6760. s += sprintf(s, "PCI");
  6761. if (bp->flags & BNX2_FLAG_PCIX)
  6762. s += sprintf(s, "-X");
  6763. if (bp->flags & BNX2_FLAG_PCI_32BIT)
  6764. s += sprintf(s, " 32-bit");
  6765. else
  6766. s += sprintf(s, " 64-bit");
  6767. s += sprintf(s, " %dMHz", bp->bus_speed_mhz);
  6768. }
  6769. return str;
  6770. }
  6771. static void
  6772. bnx2_del_napi(struct bnx2 *bp)
  6773. {
  6774. int i;
  6775. for (i = 0; i < bp->irq_nvecs; i++)
  6776. netif_napi_del(&bp->bnx2_napi[i].napi);
  6777. }
  6778. static void
  6779. bnx2_init_napi(struct bnx2 *bp)
  6780. {
  6781. int i;
  6782. for (i = 0; i < bp->irq_nvecs; i++) {
  6783. struct bnx2_napi *bnapi = &bp->bnx2_napi[i];
  6784. int (*poll)(struct napi_struct *, int);
  6785. if (i == 0)
  6786. poll = bnx2_poll;
  6787. else
  6788. poll = bnx2_poll_msix;
  6789. netif_napi_add(bp->dev, &bp->bnx2_napi[i].napi, poll, 64);
  6790. bnapi->bp = bp;
  6791. }
  6792. }
  6793. static const struct net_device_ops bnx2_netdev_ops = {
  6794. .ndo_open = bnx2_open,
  6795. .ndo_start_xmit = bnx2_start_xmit,
  6796. .ndo_stop = bnx2_close,
  6797. .ndo_get_stats64 = bnx2_get_stats64,
  6798. .ndo_set_rx_mode = bnx2_set_rx_mode,
  6799. .ndo_do_ioctl = bnx2_ioctl,
  6800. .ndo_validate_addr = eth_validate_addr,
  6801. .ndo_set_mac_address = bnx2_change_mac_addr,
  6802. .ndo_change_mtu = bnx2_change_mtu,
  6803. .ndo_fix_features = bnx2_fix_features,
  6804. .ndo_set_features = bnx2_set_features,
  6805. .ndo_tx_timeout = bnx2_tx_timeout,
  6806. #ifdef CONFIG_NET_POLL_CONTROLLER
  6807. .ndo_poll_controller = poll_bnx2,
  6808. #endif
  6809. };
  6810. static int __devinit
  6811. bnx2_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
  6812. {
  6813. static int version_printed = 0;
  6814. struct net_device *dev = NULL;
  6815. struct bnx2 *bp;
  6816. int rc;
  6817. char str[40];
  6818. if (version_printed++ == 0)
  6819. pr_info("%s", version);
  6820. /* dev zeroed in init_etherdev */
  6821. dev = alloc_etherdev_mq(sizeof(*bp), TX_MAX_RINGS);
  6822. if (!dev)
  6823. return -ENOMEM;
  6824. rc = bnx2_init_board(pdev, dev);
  6825. if (rc < 0) {
  6826. free_netdev(dev);
  6827. return rc;
  6828. }
  6829. dev->netdev_ops = &bnx2_netdev_ops;
  6830. dev->watchdog_timeo = TX_TIMEOUT;
  6831. dev->ethtool_ops = &bnx2_ethtool_ops;
  6832. bp = netdev_priv(dev);
  6833. pci_set_drvdata(pdev, dev);
  6834. rc = bnx2_request_firmware(bp);
  6835. if (rc)
  6836. goto error;
  6837. memcpy(dev->dev_addr, bp->mac_addr, 6);
  6838. memcpy(dev->perm_addr, bp->mac_addr, 6);
  6839. dev->hw_features = NETIF_F_IP_CSUM | NETIF_F_SG |
  6840. NETIF_F_TSO | NETIF_F_TSO_ECN |
  6841. NETIF_F_RXHASH | NETIF_F_RXCSUM;
  6842. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  6843. dev->hw_features |= NETIF_F_IPV6_CSUM | NETIF_F_TSO6;
  6844. dev->vlan_features = dev->hw_features;
  6845. dev->hw_features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
  6846. dev->features |= dev->hw_features;
  6847. if ((rc = register_netdev(dev))) {
  6848. dev_err(&pdev->dev, "Cannot register net device\n");
  6849. goto error;
  6850. }
  6851. netdev_info(dev, "%s (%c%d) %s found at mem %lx, IRQ %d, node addr %pM\n",
  6852. board_info[ent->driver_data].name,
  6853. ((CHIP_ID(bp) & 0xf000) >> 12) + 'A',
  6854. ((CHIP_ID(bp) & 0x0ff0) >> 4),
  6855. bnx2_bus_string(bp, str),
  6856. dev->base_addr,
  6857. bp->pdev->irq, dev->dev_addr);
  6858. return 0;
  6859. error:
  6860. if (bp->mips_firmware)
  6861. release_firmware(bp->mips_firmware);
  6862. if (bp->rv2p_firmware)
  6863. release_firmware(bp->rv2p_firmware);
  6864. if (bp->regview)
  6865. iounmap(bp->regview);
  6866. pci_release_regions(pdev);
  6867. pci_disable_device(pdev);
  6868. pci_set_drvdata(pdev, NULL);
  6869. free_netdev(dev);
  6870. return rc;
  6871. }
  6872. static void __devexit
  6873. bnx2_remove_one(struct pci_dev *pdev)
  6874. {
  6875. struct net_device *dev = pci_get_drvdata(pdev);
  6876. struct bnx2 *bp = netdev_priv(dev);
  6877. unregister_netdev(dev);
  6878. del_timer_sync(&bp->timer);
  6879. if (bp->mips_firmware)
  6880. release_firmware(bp->mips_firmware);
  6881. if (bp->rv2p_firmware)
  6882. release_firmware(bp->rv2p_firmware);
  6883. if (bp->regview)
  6884. iounmap(bp->regview);
  6885. kfree(bp->temp_stats_blk);
  6886. if (bp->flags & BNX2_FLAG_AER_ENABLED) {
  6887. pci_disable_pcie_error_reporting(pdev);
  6888. bp->flags &= ~BNX2_FLAG_AER_ENABLED;
  6889. }
  6890. free_netdev(dev);
  6891. pci_release_regions(pdev);
  6892. pci_disable_device(pdev);
  6893. pci_set_drvdata(pdev, NULL);
  6894. }
  6895. static int
  6896. bnx2_suspend(struct pci_dev *pdev, pm_message_t state)
  6897. {
  6898. struct net_device *dev = pci_get_drvdata(pdev);
  6899. struct bnx2 *bp = netdev_priv(dev);
  6900. /* PCI register 4 needs to be saved whether netif_running() or not.
  6901. * MSI address and data need to be saved if using MSI and
  6902. * netif_running().
  6903. */
  6904. pci_save_state(pdev);
  6905. if (!netif_running(dev))
  6906. return 0;
  6907. cancel_work_sync(&bp->reset_task);
  6908. bnx2_netif_stop(bp, true);
  6909. netif_device_detach(dev);
  6910. del_timer_sync(&bp->timer);
  6911. bnx2_shutdown_chip(bp);
  6912. bnx2_free_skbs(bp);
  6913. bnx2_set_power_state(bp, pci_choose_state(pdev, state));
  6914. return 0;
  6915. }
  6916. static int
  6917. bnx2_resume(struct pci_dev *pdev)
  6918. {
  6919. struct net_device *dev = pci_get_drvdata(pdev);
  6920. struct bnx2 *bp = netdev_priv(dev);
  6921. pci_restore_state(pdev);
  6922. if (!netif_running(dev))
  6923. return 0;
  6924. bnx2_set_power_state(bp, PCI_D0);
  6925. netif_device_attach(dev);
  6926. bnx2_init_nic(bp, 1);
  6927. bnx2_netif_start(bp, true);
  6928. return 0;
  6929. }
  6930. /**
  6931. * bnx2_io_error_detected - called when PCI error is detected
  6932. * @pdev: Pointer to PCI device
  6933. * @state: The current pci connection state
  6934. *
  6935. * This function is called after a PCI bus error affecting
  6936. * this device has been detected.
  6937. */
  6938. static pci_ers_result_t bnx2_io_error_detected(struct pci_dev *pdev,
  6939. pci_channel_state_t state)
  6940. {
  6941. struct net_device *dev = pci_get_drvdata(pdev);
  6942. struct bnx2 *bp = netdev_priv(dev);
  6943. rtnl_lock();
  6944. netif_device_detach(dev);
  6945. if (state == pci_channel_io_perm_failure) {
  6946. rtnl_unlock();
  6947. return PCI_ERS_RESULT_DISCONNECT;
  6948. }
  6949. if (netif_running(dev)) {
  6950. bnx2_netif_stop(bp, true);
  6951. del_timer_sync(&bp->timer);
  6952. bnx2_reset_nic(bp, BNX2_DRV_MSG_CODE_RESET);
  6953. }
  6954. pci_disable_device(pdev);
  6955. rtnl_unlock();
  6956. /* Request a slot slot reset. */
  6957. return PCI_ERS_RESULT_NEED_RESET;
  6958. }
  6959. /**
  6960. * bnx2_io_slot_reset - called after the pci bus has been reset.
  6961. * @pdev: Pointer to PCI device
  6962. *
  6963. * Restart the card from scratch, as if from a cold-boot.
  6964. */
  6965. static pci_ers_result_t bnx2_io_slot_reset(struct pci_dev *pdev)
  6966. {
  6967. struct net_device *dev = pci_get_drvdata(pdev);
  6968. struct bnx2 *bp = netdev_priv(dev);
  6969. pci_ers_result_t result;
  6970. int err;
  6971. rtnl_lock();
  6972. if (pci_enable_device(pdev)) {
  6973. dev_err(&pdev->dev,
  6974. "Cannot re-enable PCI device after reset\n");
  6975. result = PCI_ERS_RESULT_DISCONNECT;
  6976. } else {
  6977. pci_set_master(pdev);
  6978. pci_restore_state(pdev);
  6979. pci_save_state(pdev);
  6980. if (netif_running(dev)) {
  6981. bnx2_set_power_state(bp, PCI_D0);
  6982. bnx2_init_nic(bp, 1);
  6983. }
  6984. result = PCI_ERS_RESULT_RECOVERED;
  6985. }
  6986. rtnl_unlock();
  6987. if (!(bp->flags & BNX2_FLAG_AER_ENABLED))
  6988. return result;
  6989. err = pci_cleanup_aer_uncorrect_error_status(pdev);
  6990. if (err) {
  6991. dev_err(&pdev->dev,
  6992. "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
  6993. err); /* non-fatal, continue */
  6994. }
  6995. return result;
  6996. }
  6997. /**
  6998. * bnx2_io_resume - called when traffic can start flowing again.
  6999. * @pdev: Pointer to PCI device
  7000. *
  7001. * This callback is called when the error recovery driver tells us that
  7002. * its OK to resume normal operation.
  7003. */
  7004. static void bnx2_io_resume(struct pci_dev *pdev)
  7005. {
  7006. struct net_device *dev = pci_get_drvdata(pdev);
  7007. struct bnx2 *bp = netdev_priv(dev);
  7008. rtnl_lock();
  7009. if (netif_running(dev))
  7010. bnx2_netif_start(bp, true);
  7011. netif_device_attach(dev);
  7012. rtnl_unlock();
  7013. }
  7014. static struct pci_error_handlers bnx2_err_handler = {
  7015. .error_detected = bnx2_io_error_detected,
  7016. .slot_reset = bnx2_io_slot_reset,
  7017. .resume = bnx2_io_resume,
  7018. };
  7019. static struct pci_driver bnx2_pci_driver = {
  7020. .name = DRV_MODULE_NAME,
  7021. .id_table = bnx2_pci_tbl,
  7022. .probe = bnx2_init_one,
  7023. .remove = __devexit_p(bnx2_remove_one),
  7024. .suspend = bnx2_suspend,
  7025. .resume = bnx2_resume,
  7026. .err_handler = &bnx2_err_handler,
  7027. };
  7028. static int __init bnx2_init(void)
  7029. {
  7030. return pci_register_driver(&bnx2_pci_driver);
  7031. }
  7032. static void __exit bnx2_cleanup(void)
  7033. {
  7034. pci_unregister_driver(&bnx2_pci_driver);
  7035. }
  7036. module_init(bnx2_init);
  7037. module_exit(bnx2_cleanup);