bnx2.c 200 KB

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