bnx2.c 193 KB

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