bnx2.c 134 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558
  1. /* bnx2.c: Broadcom NX2 network driver.
  2. *
  3. * Copyright (c) 2004, 2005 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 "bnx2.h"
  12. #include "bnx2_fw.h"
  13. #define DRV_MODULE_NAME "bnx2"
  14. #define PFX DRV_MODULE_NAME ": "
  15. #define DRV_MODULE_VERSION "1.2.21"
  16. #define DRV_MODULE_RELDATE "September 7, 2005"
  17. #define RUN_AT(x) (jiffies + (x))
  18. /* Time in jiffies before concluding the transmitter is hung. */
  19. #define TX_TIMEOUT (5*HZ)
  20. static char version[] __devinitdata =
  21. "Broadcom NetXtreme II Gigabit Ethernet Driver " DRV_MODULE_NAME " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  22. MODULE_AUTHOR("Michael Chan <mchan@broadcom.com>");
  23. MODULE_DESCRIPTION("Broadcom NetXtreme II BCM5706 Driver");
  24. MODULE_LICENSE("GPL");
  25. MODULE_VERSION(DRV_MODULE_VERSION);
  26. static int disable_msi = 0;
  27. module_param(disable_msi, int, 0);
  28. MODULE_PARM_DESC(disable_msi, "Disable Message Signaled Interrupt (MSI)");
  29. typedef enum {
  30. BCM5706 = 0,
  31. NC370T,
  32. NC370I,
  33. BCM5706S,
  34. NC370F,
  35. } board_t;
  36. /* indexed by board_t, above */
  37. static struct {
  38. char *name;
  39. } board_info[] __devinitdata = {
  40. { "Broadcom NetXtreme II BCM5706 1000Base-T" },
  41. { "HP NC370T Multifunction Gigabit Server Adapter" },
  42. { "HP NC370i Multifunction Gigabit Server Adapter" },
  43. { "Broadcom NetXtreme II BCM5706 1000Base-SX" },
  44. { "HP NC370F Multifunction Gigabit Server Adapter" },
  45. };
  46. static struct pci_device_id bnx2_pci_tbl[] = {
  47. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706,
  48. PCI_VENDOR_ID_HP, 0x3101, 0, 0, NC370T },
  49. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706,
  50. PCI_VENDOR_ID_HP, 0x3106, 0, 0, NC370I },
  51. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706,
  52. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5706 },
  53. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706S,
  54. PCI_VENDOR_ID_HP, 0x3102, 0, 0, NC370F },
  55. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706S,
  56. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5706S },
  57. { 0, }
  58. };
  59. static struct flash_spec flash_table[] =
  60. {
  61. /* Slow EEPROM */
  62. {0x00000000, 0x40030380, 0x009f0081, 0xa184a053, 0xaf000400,
  63. 1, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
  64. SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
  65. "EEPROM - slow"},
  66. /* Fast EEPROM */
  67. {0x02000000, 0x62008380, 0x009f0081, 0xa184a053, 0xaf000400,
  68. 1, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
  69. SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
  70. "EEPROM - fast"},
  71. /* ATMEL AT45DB011B (buffered flash) */
  72. {0x02000003, 0x6e008173, 0x00570081, 0x68848353, 0xaf000400,
  73. 1, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
  74. BUFFERED_FLASH_BYTE_ADDR_MASK, BUFFERED_FLASH_TOTAL_SIZE,
  75. "Buffered flash"},
  76. /* Saifun SA25F005 (non-buffered flash) */
  77. /* strap, cfg1, & write1 need updates */
  78. {0x01000003, 0x5f008081, 0x00050081, 0x03840253, 0xaf020406,
  79. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  80. SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE,
  81. "Non-buffered flash (64kB)"},
  82. /* Saifun SA25F010 (non-buffered flash) */
  83. /* strap, cfg1, & write1 need updates */
  84. {0x00000001, 0x47008081, 0x00050081, 0x03840253, 0xaf020406,
  85. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  86. SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE*2,
  87. "Non-buffered flash (128kB)"},
  88. /* Saifun SA25F020 (non-buffered flash) */
  89. /* strap, cfg1, & write1 need updates */
  90. {0x00000003, 0x4f008081, 0x00050081, 0x03840253, 0xaf020406,
  91. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  92. SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE*4,
  93. "Non-buffered flash (256kB)"},
  94. };
  95. MODULE_DEVICE_TABLE(pci, bnx2_pci_tbl);
  96. static inline u32 bnx2_tx_avail(struct bnx2 *bp)
  97. {
  98. u32 diff = TX_RING_IDX(bp->tx_prod) - TX_RING_IDX(bp->tx_cons);
  99. if (diff > MAX_TX_DESC_CNT)
  100. diff = (diff & MAX_TX_DESC_CNT) - 1;
  101. return (bp->tx_ring_size - diff);
  102. }
  103. static u32
  104. bnx2_reg_rd_ind(struct bnx2 *bp, u32 offset)
  105. {
  106. REG_WR(bp, BNX2_PCICFG_REG_WINDOW_ADDRESS, offset);
  107. return (REG_RD(bp, BNX2_PCICFG_REG_WINDOW));
  108. }
  109. static void
  110. bnx2_reg_wr_ind(struct bnx2 *bp, u32 offset, u32 val)
  111. {
  112. REG_WR(bp, BNX2_PCICFG_REG_WINDOW_ADDRESS, offset);
  113. REG_WR(bp, BNX2_PCICFG_REG_WINDOW, val);
  114. }
  115. static void
  116. bnx2_ctx_wr(struct bnx2 *bp, u32 cid_addr, u32 offset, u32 val)
  117. {
  118. offset += cid_addr;
  119. REG_WR(bp, BNX2_CTX_DATA_ADR, offset);
  120. REG_WR(bp, BNX2_CTX_DATA, val);
  121. }
  122. static int
  123. bnx2_read_phy(struct bnx2 *bp, u32 reg, u32 *val)
  124. {
  125. u32 val1;
  126. int i, ret;
  127. if (bp->phy_flags & PHY_INT_MODE_AUTO_POLLING_FLAG) {
  128. val1 = REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  129. val1 &= ~BNX2_EMAC_MDIO_MODE_AUTO_POLL;
  130. REG_WR(bp, BNX2_EMAC_MDIO_MODE, val1);
  131. REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  132. udelay(40);
  133. }
  134. val1 = (bp->phy_addr << 21) | (reg << 16) |
  135. BNX2_EMAC_MDIO_COMM_COMMAND_READ | BNX2_EMAC_MDIO_COMM_DISEXT |
  136. BNX2_EMAC_MDIO_COMM_START_BUSY;
  137. REG_WR(bp, BNX2_EMAC_MDIO_COMM, val1);
  138. for (i = 0; i < 50; i++) {
  139. udelay(10);
  140. val1 = REG_RD(bp, BNX2_EMAC_MDIO_COMM);
  141. if (!(val1 & BNX2_EMAC_MDIO_COMM_START_BUSY)) {
  142. udelay(5);
  143. val1 = REG_RD(bp, BNX2_EMAC_MDIO_COMM);
  144. val1 &= BNX2_EMAC_MDIO_COMM_DATA;
  145. break;
  146. }
  147. }
  148. if (val1 & BNX2_EMAC_MDIO_COMM_START_BUSY) {
  149. *val = 0x0;
  150. ret = -EBUSY;
  151. }
  152. else {
  153. *val = val1;
  154. ret = 0;
  155. }
  156. if (bp->phy_flags & PHY_INT_MODE_AUTO_POLLING_FLAG) {
  157. val1 = REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  158. val1 |= BNX2_EMAC_MDIO_MODE_AUTO_POLL;
  159. REG_WR(bp, BNX2_EMAC_MDIO_MODE, val1);
  160. REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  161. udelay(40);
  162. }
  163. return ret;
  164. }
  165. static int
  166. bnx2_write_phy(struct bnx2 *bp, u32 reg, u32 val)
  167. {
  168. u32 val1;
  169. int i, ret;
  170. if (bp->phy_flags & PHY_INT_MODE_AUTO_POLLING_FLAG) {
  171. val1 = REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  172. val1 &= ~BNX2_EMAC_MDIO_MODE_AUTO_POLL;
  173. REG_WR(bp, BNX2_EMAC_MDIO_MODE, val1);
  174. REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  175. udelay(40);
  176. }
  177. val1 = (bp->phy_addr << 21) | (reg << 16) | val |
  178. BNX2_EMAC_MDIO_COMM_COMMAND_WRITE |
  179. BNX2_EMAC_MDIO_COMM_START_BUSY | BNX2_EMAC_MDIO_COMM_DISEXT;
  180. REG_WR(bp, BNX2_EMAC_MDIO_COMM, val1);
  181. for (i = 0; i < 50; i++) {
  182. udelay(10);
  183. val1 = REG_RD(bp, BNX2_EMAC_MDIO_COMM);
  184. if (!(val1 & BNX2_EMAC_MDIO_COMM_START_BUSY)) {
  185. udelay(5);
  186. break;
  187. }
  188. }
  189. if (val1 & BNX2_EMAC_MDIO_COMM_START_BUSY)
  190. ret = -EBUSY;
  191. else
  192. ret = 0;
  193. if (bp->phy_flags & PHY_INT_MODE_AUTO_POLLING_FLAG) {
  194. val1 = REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  195. val1 |= BNX2_EMAC_MDIO_MODE_AUTO_POLL;
  196. REG_WR(bp, BNX2_EMAC_MDIO_MODE, val1);
  197. REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  198. udelay(40);
  199. }
  200. return ret;
  201. }
  202. static void
  203. bnx2_disable_int(struct bnx2 *bp)
  204. {
  205. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  206. BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
  207. REG_RD(bp, BNX2_PCICFG_INT_ACK_CMD);
  208. }
  209. static void
  210. bnx2_enable_int(struct bnx2 *bp)
  211. {
  212. u32 val;
  213. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  214. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID | bp->last_status_idx);
  215. val = REG_RD(bp, BNX2_HC_COMMAND);
  216. REG_WR(bp, BNX2_HC_COMMAND, val | BNX2_HC_COMMAND_COAL_NOW);
  217. }
  218. static void
  219. bnx2_disable_int_sync(struct bnx2 *bp)
  220. {
  221. atomic_inc(&bp->intr_sem);
  222. bnx2_disable_int(bp);
  223. synchronize_irq(bp->pdev->irq);
  224. }
  225. static void
  226. bnx2_netif_stop(struct bnx2 *bp)
  227. {
  228. bnx2_disable_int_sync(bp);
  229. if (netif_running(bp->dev)) {
  230. netif_poll_disable(bp->dev);
  231. netif_tx_disable(bp->dev);
  232. bp->dev->trans_start = jiffies; /* prevent tx timeout */
  233. }
  234. }
  235. static void
  236. bnx2_netif_start(struct bnx2 *bp)
  237. {
  238. if (atomic_dec_and_test(&bp->intr_sem)) {
  239. if (netif_running(bp->dev)) {
  240. netif_wake_queue(bp->dev);
  241. netif_poll_enable(bp->dev);
  242. bnx2_enable_int(bp);
  243. }
  244. }
  245. }
  246. static void
  247. bnx2_free_mem(struct bnx2 *bp)
  248. {
  249. if (bp->stats_blk) {
  250. pci_free_consistent(bp->pdev, sizeof(struct statistics_block),
  251. bp->stats_blk, bp->stats_blk_mapping);
  252. bp->stats_blk = NULL;
  253. }
  254. if (bp->status_blk) {
  255. pci_free_consistent(bp->pdev, sizeof(struct status_block),
  256. bp->status_blk, bp->status_blk_mapping);
  257. bp->status_blk = NULL;
  258. }
  259. if (bp->tx_desc_ring) {
  260. pci_free_consistent(bp->pdev,
  261. sizeof(struct tx_bd) * TX_DESC_CNT,
  262. bp->tx_desc_ring, bp->tx_desc_mapping);
  263. bp->tx_desc_ring = NULL;
  264. }
  265. kfree(bp->tx_buf_ring);
  266. bp->tx_buf_ring = NULL;
  267. if (bp->rx_desc_ring) {
  268. pci_free_consistent(bp->pdev,
  269. sizeof(struct rx_bd) * RX_DESC_CNT,
  270. bp->rx_desc_ring, bp->rx_desc_mapping);
  271. bp->rx_desc_ring = NULL;
  272. }
  273. kfree(bp->rx_buf_ring);
  274. bp->rx_buf_ring = NULL;
  275. }
  276. static int
  277. bnx2_alloc_mem(struct bnx2 *bp)
  278. {
  279. bp->tx_buf_ring = kmalloc(sizeof(struct sw_bd) * TX_DESC_CNT,
  280. GFP_KERNEL);
  281. if (bp->tx_buf_ring == NULL)
  282. return -ENOMEM;
  283. memset(bp->tx_buf_ring, 0, sizeof(struct sw_bd) * TX_DESC_CNT);
  284. bp->tx_desc_ring = pci_alloc_consistent(bp->pdev,
  285. sizeof(struct tx_bd) *
  286. TX_DESC_CNT,
  287. &bp->tx_desc_mapping);
  288. if (bp->tx_desc_ring == NULL)
  289. goto alloc_mem_err;
  290. bp->rx_buf_ring = kmalloc(sizeof(struct sw_bd) * RX_DESC_CNT,
  291. GFP_KERNEL);
  292. if (bp->rx_buf_ring == NULL)
  293. goto alloc_mem_err;
  294. memset(bp->rx_buf_ring, 0, sizeof(struct sw_bd) * RX_DESC_CNT);
  295. bp->rx_desc_ring = pci_alloc_consistent(bp->pdev,
  296. sizeof(struct rx_bd) *
  297. RX_DESC_CNT,
  298. &bp->rx_desc_mapping);
  299. if (bp->rx_desc_ring == NULL)
  300. goto alloc_mem_err;
  301. bp->status_blk = pci_alloc_consistent(bp->pdev,
  302. sizeof(struct status_block),
  303. &bp->status_blk_mapping);
  304. if (bp->status_blk == NULL)
  305. goto alloc_mem_err;
  306. memset(bp->status_blk, 0, sizeof(struct status_block));
  307. bp->stats_blk = pci_alloc_consistent(bp->pdev,
  308. sizeof(struct statistics_block),
  309. &bp->stats_blk_mapping);
  310. if (bp->stats_blk == NULL)
  311. goto alloc_mem_err;
  312. memset(bp->stats_blk, 0, sizeof(struct statistics_block));
  313. return 0;
  314. alloc_mem_err:
  315. bnx2_free_mem(bp);
  316. return -ENOMEM;
  317. }
  318. static void
  319. bnx2_report_link(struct bnx2 *bp)
  320. {
  321. if (bp->link_up) {
  322. netif_carrier_on(bp->dev);
  323. printk(KERN_INFO PFX "%s NIC Link is Up, ", bp->dev->name);
  324. printk("%d Mbps ", bp->line_speed);
  325. if (bp->duplex == DUPLEX_FULL)
  326. printk("full duplex");
  327. else
  328. printk("half duplex");
  329. if (bp->flow_ctrl) {
  330. if (bp->flow_ctrl & FLOW_CTRL_RX) {
  331. printk(", receive ");
  332. if (bp->flow_ctrl & FLOW_CTRL_TX)
  333. printk("& transmit ");
  334. }
  335. else {
  336. printk(", transmit ");
  337. }
  338. printk("flow control ON");
  339. }
  340. printk("\n");
  341. }
  342. else {
  343. netif_carrier_off(bp->dev);
  344. printk(KERN_ERR PFX "%s NIC Link is Down\n", bp->dev->name);
  345. }
  346. }
  347. static void
  348. bnx2_resolve_flow_ctrl(struct bnx2 *bp)
  349. {
  350. u32 local_adv, remote_adv;
  351. bp->flow_ctrl = 0;
  352. if ((bp->autoneg & (AUTONEG_SPEED | AUTONEG_FLOW_CTRL)) !=
  353. (AUTONEG_SPEED | AUTONEG_FLOW_CTRL)) {
  354. if (bp->duplex == DUPLEX_FULL) {
  355. bp->flow_ctrl = bp->req_flow_ctrl;
  356. }
  357. return;
  358. }
  359. if (bp->duplex != DUPLEX_FULL) {
  360. return;
  361. }
  362. bnx2_read_phy(bp, MII_ADVERTISE, &local_adv);
  363. bnx2_read_phy(bp, MII_LPA, &remote_adv);
  364. if (bp->phy_flags & PHY_SERDES_FLAG) {
  365. u32 new_local_adv = 0;
  366. u32 new_remote_adv = 0;
  367. if (local_adv & ADVERTISE_1000XPAUSE)
  368. new_local_adv |= ADVERTISE_PAUSE_CAP;
  369. if (local_adv & ADVERTISE_1000XPSE_ASYM)
  370. new_local_adv |= ADVERTISE_PAUSE_ASYM;
  371. if (remote_adv & ADVERTISE_1000XPAUSE)
  372. new_remote_adv |= ADVERTISE_PAUSE_CAP;
  373. if (remote_adv & ADVERTISE_1000XPSE_ASYM)
  374. new_remote_adv |= ADVERTISE_PAUSE_ASYM;
  375. local_adv = new_local_adv;
  376. remote_adv = new_remote_adv;
  377. }
  378. /* See Table 28B-3 of 802.3ab-1999 spec. */
  379. if (local_adv & ADVERTISE_PAUSE_CAP) {
  380. if(local_adv & ADVERTISE_PAUSE_ASYM) {
  381. if (remote_adv & ADVERTISE_PAUSE_CAP) {
  382. bp->flow_ctrl = FLOW_CTRL_TX | FLOW_CTRL_RX;
  383. }
  384. else if (remote_adv & ADVERTISE_PAUSE_ASYM) {
  385. bp->flow_ctrl = FLOW_CTRL_RX;
  386. }
  387. }
  388. else {
  389. if (remote_adv & ADVERTISE_PAUSE_CAP) {
  390. bp->flow_ctrl = FLOW_CTRL_TX | FLOW_CTRL_RX;
  391. }
  392. }
  393. }
  394. else if (local_adv & ADVERTISE_PAUSE_ASYM) {
  395. if ((remote_adv & ADVERTISE_PAUSE_CAP) &&
  396. (remote_adv & ADVERTISE_PAUSE_ASYM)) {
  397. bp->flow_ctrl = FLOW_CTRL_TX;
  398. }
  399. }
  400. }
  401. static int
  402. bnx2_serdes_linkup(struct bnx2 *bp)
  403. {
  404. u32 bmcr, local_adv, remote_adv, common;
  405. bp->link_up = 1;
  406. bp->line_speed = SPEED_1000;
  407. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  408. if (bmcr & BMCR_FULLDPLX) {
  409. bp->duplex = DUPLEX_FULL;
  410. }
  411. else {
  412. bp->duplex = DUPLEX_HALF;
  413. }
  414. if (!(bmcr & BMCR_ANENABLE)) {
  415. return 0;
  416. }
  417. bnx2_read_phy(bp, MII_ADVERTISE, &local_adv);
  418. bnx2_read_phy(bp, MII_LPA, &remote_adv);
  419. common = local_adv & remote_adv;
  420. if (common & (ADVERTISE_1000XHALF | ADVERTISE_1000XFULL)) {
  421. if (common & ADVERTISE_1000XFULL) {
  422. bp->duplex = DUPLEX_FULL;
  423. }
  424. else {
  425. bp->duplex = DUPLEX_HALF;
  426. }
  427. }
  428. return 0;
  429. }
  430. static int
  431. bnx2_copper_linkup(struct bnx2 *bp)
  432. {
  433. u32 bmcr;
  434. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  435. if (bmcr & BMCR_ANENABLE) {
  436. u32 local_adv, remote_adv, common;
  437. bnx2_read_phy(bp, MII_CTRL1000, &local_adv);
  438. bnx2_read_phy(bp, MII_STAT1000, &remote_adv);
  439. common = local_adv & (remote_adv >> 2);
  440. if (common & ADVERTISE_1000FULL) {
  441. bp->line_speed = SPEED_1000;
  442. bp->duplex = DUPLEX_FULL;
  443. }
  444. else if (common & ADVERTISE_1000HALF) {
  445. bp->line_speed = SPEED_1000;
  446. bp->duplex = DUPLEX_HALF;
  447. }
  448. else {
  449. bnx2_read_phy(bp, MII_ADVERTISE, &local_adv);
  450. bnx2_read_phy(bp, MII_LPA, &remote_adv);
  451. common = local_adv & remote_adv;
  452. if (common & ADVERTISE_100FULL) {
  453. bp->line_speed = SPEED_100;
  454. bp->duplex = DUPLEX_FULL;
  455. }
  456. else if (common & ADVERTISE_100HALF) {
  457. bp->line_speed = SPEED_100;
  458. bp->duplex = DUPLEX_HALF;
  459. }
  460. else if (common & ADVERTISE_10FULL) {
  461. bp->line_speed = SPEED_10;
  462. bp->duplex = DUPLEX_FULL;
  463. }
  464. else if (common & ADVERTISE_10HALF) {
  465. bp->line_speed = SPEED_10;
  466. bp->duplex = DUPLEX_HALF;
  467. }
  468. else {
  469. bp->line_speed = 0;
  470. bp->link_up = 0;
  471. }
  472. }
  473. }
  474. else {
  475. if (bmcr & BMCR_SPEED100) {
  476. bp->line_speed = SPEED_100;
  477. }
  478. else {
  479. bp->line_speed = SPEED_10;
  480. }
  481. if (bmcr & BMCR_FULLDPLX) {
  482. bp->duplex = DUPLEX_FULL;
  483. }
  484. else {
  485. bp->duplex = DUPLEX_HALF;
  486. }
  487. }
  488. return 0;
  489. }
  490. static int
  491. bnx2_set_mac_link(struct bnx2 *bp)
  492. {
  493. u32 val;
  494. REG_WR(bp, BNX2_EMAC_TX_LENGTHS, 0x2620);
  495. if (bp->link_up && (bp->line_speed == SPEED_1000) &&
  496. (bp->duplex == DUPLEX_HALF)) {
  497. REG_WR(bp, BNX2_EMAC_TX_LENGTHS, 0x26ff);
  498. }
  499. /* Configure the EMAC mode register. */
  500. val = REG_RD(bp, BNX2_EMAC_MODE);
  501. val &= ~(BNX2_EMAC_MODE_PORT | BNX2_EMAC_MODE_HALF_DUPLEX |
  502. BNX2_EMAC_MODE_MAC_LOOP | BNX2_EMAC_MODE_FORCE_LINK);
  503. if (bp->link_up) {
  504. if (bp->line_speed != SPEED_1000)
  505. val |= BNX2_EMAC_MODE_PORT_MII;
  506. else
  507. val |= BNX2_EMAC_MODE_PORT_GMII;
  508. }
  509. else {
  510. val |= BNX2_EMAC_MODE_PORT_GMII;
  511. }
  512. /* Set the MAC to operate in the appropriate duplex mode. */
  513. if (bp->duplex == DUPLEX_HALF)
  514. val |= BNX2_EMAC_MODE_HALF_DUPLEX;
  515. REG_WR(bp, BNX2_EMAC_MODE, val);
  516. /* Enable/disable rx PAUSE. */
  517. bp->rx_mode &= ~BNX2_EMAC_RX_MODE_FLOW_EN;
  518. if (bp->flow_ctrl & FLOW_CTRL_RX)
  519. bp->rx_mode |= BNX2_EMAC_RX_MODE_FLOW_EN;
  520. REG_WR(bp, BNX2_EMAC_RX_MODE, bp->rx_mode);
  521. /* Enable/disable tx PAUSE. */
  522. val = REG_RD(bp, BNX2_EMAC_TX_MODE);
  523. val &= ~BNX2_EMAC_TX_MODE_FLOW_EN;
  524. if (bp->flow_ctrl & FLOW_CTRL_TX)
  525. val |= BNX2_EMAC_TX_MODE_FLOW_EN;
  526. REG_WR(bp, BNX2_EMAC_TX_MODE, val);
  527. /* Acknowledge the interrupt. */
  528. REG_WR(bp, BNX2_EMAC_STATUS, BNX2_EMAC_STATUS_LINK_CHANGE);
  529. return 0;
  530. }
  531. static int
  532. bnx2_set_link(struct bnx2 *bp)
  533. {
  534. u32 bmsr;
  535. u8 link_up;
  536. if (bp->loopback == MAC_LOOPBACK) {
  537. bp->link_up = 1;
  538. return 0;
  539. }
  540. link_up = bp->link_up;
  541. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  542. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  543. if ((bp->phy_flags & PHY_SERDES_FLAG) &&
  544. (CHIP_NUM(bp) == CHIP_NUM_5706)) {
  545. u32 val;
  546. val = REG_RD(bp, BNX2_EMAC_STATUS);
  547. if (val & BNX2_EMAC_STATUS_LINK)
  548. bmsr |= BMSR_LSTATUS;
  549. else
  550. bmsr &= ~BMSR_LSTATUS;
  551. }
  552. if (bmsr & BMSR_LSTATUS) {
  553. bp->link_up = 1;
  554. if (bp->phy_flags & PHY_SERDES_FLAG) {
  555. bnx2_serdes_linkup(bp);
  556. }
  557. else {
  558. bnx2_copper_linkup(bp);
  559. }
  560. bnx2_resolve_flow_ctrl(bp);
  561. }
  562. else {
  563. if ((bp->phy_flags & PHY_SERDES_FLAG) &&
  564. (bp->autoneg & AUTONEG_SPEED)) {
  565. u32 bmcr;
  566. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  567. if (!(bmcr & BMCR_ANENABLE)) {
  568. bnx2_write_phy(bp, MII_BMCR, bmcr |
  569. BMCR_ANENABLE);
  570. }
  571. }
  572. bp->phy_flags &= ~PHY_PARALLEL_DETECT_FLAG;
  573. bp->link_up = 0;
  574. }
  575. if (bp->link_up != link_up) {
  576. bnx2_report_link(bp);
  577. }
  578. bnx2_set_mac_link(bp);
  579. return 0;
  580. }
  581. static int
  582. bnx2_reset_phy(struct bnx2 *bp)
  583. {
  584. int i;
  585. u32 reg;
  586. bnx2_write_phy(bp, MII_BMCR, BMCR_RESET);
  587. #define PHY_RESET_MAX_WAIT 100
  588. for (i = 0; i < PHY_RESET_MAX_WAIT; i++) {
  589. udelay(10);
  590. bnx2_read_phy(bp, MII_BMCR, &reg);
  591. if (!(reg & BMCR_RESET)) {
  592. udelay(20);
  593. break;
  594. }
  595. }
  596. if (i == PHY_RESET_MAX_WAIT) {
  597. return -EBUSY;
  598. }
  599. return 0;
  600. }
  601. static u32
  602. bnx2_phy_get_pause_adv(struct bnx2 *bp)
  603. {
  604. u32 adv = 0;
  605. if ((bp->req_flow_ctrl & (FLOW_CTRL_RX | FLOW_CTRL_TX)) ==
  606. (FLOW_CTRL_RX | FLOW_CTRL_TX)) {
  607. if (bp->phy_flags & PHY_SERDES_FLAG) {
  608. adv = ADVERTISE_1000XPAUSE;
  609. }
  610. else {
  611. adv = ADVERTISE_PAUSE_CAP;
  612. }
  613. }
  614. else if (bp->req_flow_ctrl & FLOW_CTRL_TX) {
  615. if (bp->phy_flags & PHY_SERDES_FLAG) {
  616. adv = ADVERTISE_1000XPSE_ASYM;
  617. }
  618. else {
  619. adv = ADVERTISE_PAUSE_ASYM;
  620. }
  621. }
  622. else if (bp->req_flow_ctrl & FLOW_CTRL_RX) {
  623. if (bp->phy_flags & PHY_SERDES_FLAG) {
  624. adv = ADVERTISE_1000XPAUSE | ADVERTISE_1000XPSE_ASYM;
  625. }
  626. else {
  627. adv = ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
  628. }
  629. }
  630. return adv;
  631. }
  632. static int
  633. bnx2_setup_serdes_phy(struct bnx2 *bp)
  634. {
  635. u32 adv, bmcr;
  636. u32 new_adv = 0;
  637. if (!(bp->autoneg & AUTONEG_SPEED)) {
  638. u32 new_bmcr;
  639. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  640. new_bmcr = bmcr & ~BMCR_ANENABLE;
  641. new_bmcr |= BMCR_SPEED1000;
  642. if (bp->req_duplex == DUPLEX_FULL) {
  643. new_bmcr |= BMCR_FULLDPLX;
  644. }
  645. else {
  646. new_bmcr &= ~BMCR_FULLDPLX;
  647. }
  648. if (new_bmcr != bmcr) {
  649. /* Force a link down visible on the other side */
  650. if (bp->link_up) {
  651. bnx2_read_phy(bp, MII_ADVERTISE, &adv);
  652. adv &= ~(ADVERTISE_1000XFULL |
  653. ADVERTISE_1000XHALF);
  654. bnx2_write_phy(bp, MII_ADVERTISE, adv);
  655. bnx2_write_phy(bp, MII_BMCR, bmcr |
  656. BMCR_ANRESTART | BMCR_ANENABLE);
  657. bp->link_up = 0;
  658. netif_carrier_off(bp->dev);
  659. }
  660. bnx2_write_phy(bp, MII_BMCR, new_bmcr);
  661. }
  662. return 0;
  663. }
  664. if (bp->advertising & ADVERTISED_1000baseT_Full)
  665. new_adv |= ADVERTISE_1000XFULL;
  666. new_adv |= bnx2_phy_get_pause_adv(bp);
  667. bnx2_read_phy(bp, MII_ADVERTISE, &adv);
  668. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  669. bp->serdes_an_pending = 0;
  670. if ((adv != new_adv) || ((bmcr & BMCR_ANENABLE) == 0)) {
  671. /* Force a link down visible on the other side */
  672. if (bp->link_up) {
  673. int i;
  674. bnx2_write_phy(bp, MII_BMCR, BMCR_LOOPBACK);
  675. for (i = 0; i < 110; i++) {
  676. udelay(100);
  677. }
  678. }
  679. bnx2_write_phy(bp, MII_ADVERTISE, new_adv);
  680. bnx2_write_phy(bp, MII_BMCR, bmcr | BMCR_ANRESTART |
  681. BMCR_ANENABLE);
  682. if (CHIP_NUM(bp) == CHIP_NUM_5706) {
  683. /* Speed up link-up time when the link partner
  684. * does not autonegotiate which is very common
  685. * in blade servers. Some blade servers use
  686. * IPMI for kerboard input and it's important
  687. * to minimize link disruptions. Autoneg. involves
  688. * exchanging base pages plus 3 next pages and
  689. * normally completes in about 120 msec.
  690. */
  691. bp->current_interval = SERDES_AN_TIMEOUT;
  692. bp->serdes_an_pending = 1;
  693. mod_timer(&bp->timer, jiffies + bp->current_interval);
  694. }
  695. }
  696. return 0;
  697. }
  698. #define ETHTOOL_ALL_FIBRE_SPEED \
  699. (ADVERTISED_1000baseT_Full)
  700. #define ETHTOOL_ALL_COPPER_SPEED \
  701. (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | \
  702. ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | \
  703. ADVERTISED_1000baseT_Full)
  704. #define PHY_ALL_10_100_SPEED (ADVERTISE_10HALF | ADVERTISE_10FULL | \
  705. ADVERTISE_100HALF | ADVERTISE_100FULL | ADVERTISE_CSMA)
  706. #define PHY_ALL_1000_SPEED (ADVERTISE_1000HALF | ADVERTISE_1000FULL)
  707. static int
  708. bnx2_setup_copper_phy(struct bnx2 *bp)
  709. {
  710. u32 bmcr;
  711. u32 new_bmcr;
  712. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  713. if (bp->autoneg & AUTONEG_SPEED) {
  714. u32 adv_reg, adv1000_reg;
  715. u32 new_adv_reg = 0;
  716. u32 new_adv1000_reg = 0;
  717. bnx2_read_phy(bp, MII_ADVERTISE, &adv_reg);
  718. adv_reg &= (PHY_ALL_10_100_SPEED | ADVERTISE_PAUSE_CAP |
  719. ADVERTISE_PAUSE_ASYM);
  720. bnx2_read_phy(bp, MII_CTRL1000, &adv1000_reg);
  721. adv1000_reg &= PHY_ALL_1000_SPEED;
  722. if (bp->advertising & ADVERTISED_10baseT_Half)
  723. new_adv_reg |= ADVERTISE_10HALF;
  724. if (bp->advertising & ADVERTISED_10baseT_Full)
  725. new_adv_reg |= ADVERTISE_10FULL;
  726. if (bp->advertising & ADVERTISED_100baseT_Half)
  727. new_adv_reg |= ADVERTISE_100HALF;
  728. if (bp->advertising & ADVERTISED_100baseT_Full)
  729. new_adv_reg |= ADVERTISE_100FULL;
  730. if (bp->advertising & ADVERTISED_1000baseT_Full)
  731. new_adv1000_reg |= ADVERTISE_1000FULL;
  732. new_adv_reg |= ADVERTISE_CSMA;
  733. new_adv_reg |= bnx2_phy_get_pause_adv(bp);
  734. if ((adv1000_reg != new_adv1000_reg) ||
  735. (adv_reg != new_adv_reg) ||
  736. ((bmcr & BMCR_ANENABLE) == 0)) {
  737. bnx2_write_phy(bp, MII_ADVERTISE, new_adv_reg);
  738. bnx2_write_phy(bp, MII_CTRL1000, new_adv1000_reg);
  739. bnx2_write_phy(bp, MII_BMCR, BMCR_ANRESTART |
  740. BMCR_ANENABLE);
  741. }
  742. else if (bp->link_up) {
  743. /* Flow ctrl may have changed from auto to forced */
  744. /* or vice-versa. */
  745. bnx2_resolve_flow_ctrl(bp);
  746. bnx2_set_mac_link(bp);
  747. }
  748. return 0;
  749. }
  750. new_bmcr = 0;
  751. if (bp->req_line_speed == SPEED_100) {
  752. new_bmcr |= BMCR_SPEED100;
  753. }
  754. if (bp->req_duplex == DUPLEX_FULL) {
  755. new_bmcr |= BMCR_FULLDPLX;
  756. }
  757. if (new_bmcr != bmcr) {
  758. u32 bmsr;
  759. int i = 0;
  760. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  761. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  762. if (bmsr & BMSR_LSTATUS) {
  763. /* Force link down */
  764. bnx2_write_phy(bp, MII_BMCR, BMCR_LOOPBACK);
  765. do {
  766. udelay(100);
  767. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  768. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  769. i++;
  770. } while ((bmsr & BMSR_LSTATUS) && (i < 620));
  771. }
  772. bnx2_write_phy(bp, MII_BMCR, new_bmcr);
  773. /* Normally, the new speed is setup after the link has
  774. * gone down and up again. In some cases, link will not go
  775. * down so we need to set up the new speed here.
  776. */
  777. if (bmsr & BMSR_LSTATUS) {
  778. bp->line_speed = bp->req_line_speed;
  779. bp->duplex = bp->req_duplex;
  780. bnx2_resolve_flow_ctrl(bp);
  781. bnx2_set_mac_link(bp);
  782. }
  783. }
  784. return 0;
  785. }
  786. static int
  787. bnx2_setup_phy(struct bnx2 *bp)
  788. {
  789. if (bp->loopback == MAC_LOOPBACK)
  790. return 0;
  791. if (bp->phy_flags & PHY_SERDES_FLAG) {
  792. return (bnx2_setup_serdes_phy(bp));
  793. }
  794. else {
  795. return (bnx2_setup_copper_phy(bp));
  796. }
  797. }
  798. static int
  799. bnx2_init_serdes_phy(struct bnx2 *bp)
  800. {
  801. bp->phy_flags &= ~PHY_PARALLEL_DETECT_FLAG;
  802. if (CHIP_NUM(bp) == CHIP_NUM_5706) {
  803. REG_WR(bp, BNX2_MISC_UNUSED0, 0x300);
  804. }
  805. if (bp->dev->mtu > 1500) {
  806. u32 val;
  807. /* Set extended packet length bit */
  808. bnx2_write_phy(bp, 0x18, 0x7);
  809. bnx2_read_phy(bp, 0x18, &val);
  810. bnx2_write_phy(bp, 0x18, (val & 0xfff8) | 0x4000);
  811. bnx2_write_phy(bp, 0x1c, 0x6c00);
  812. bnx2_read_phy(bp, 0x1c, &val);
  813. bnx2_write_phy(bp, 0x1c, (val & 0x3ff) | 0xec02);
  814. }
  815. else {
  816. u32 val;
  817. bnx2_write_phy(bp, 0x18, 0x7);
  818. bnx2_read_phy(bp, 0x18, &val);
  819. bnx2_write_phy(bp, 0x18, val & ~0x4007);
  820. bnx2_write_phy(bp, 0x1c, 0x6c00);
  821. bnx2_read_phy(bp, 0x1c, &val);
  822. bnx2_write_phy(bp, 0x1c, (val & 0x3fd) | 0xec00);
  823. }
  824. return 0;
  825. }
  826. static int
  827. bnx2_init_copper_phy(struct bnx2 *bp)
  828. {
  829. bp->phy_flags |= PHY_CRC_FIX_FLAG;
  830. if (bp->phy_flags & PHY_CRC_FIX_FLAG) {
  831. bnx2_write_phy(bp, 0x18, 0x0c00);
  832. bnx2_write_phy(bp, 0x17, 0x000a);
  833. bnx2_write_phy(bp, 0x15, 0x310b);
  834. bnx2_write_phy(bp, 0x17, 0x201f);
  835. bnx2_write_phy(bp, 0x15, 0x9506);
  836. bnx2_write_phy(bp, 0x17, 0x401f);
  837. bnx2_write_phy(bp, 0x15, 0x14e2);
  838. bnx2_write_phy(bp, 0x18, 0x0400);
  839. }
  840. if (bp->dev->mtu > 1500) {
  841. u32 val;
  842. /* Set extended packet length bit */
  843. bnx2_write_phy(bp, 0x18, 0x7);
  844. bnx2_read_phy(bp, 0x18, &val);
  845. bnx2_write_phy(bp, 0x18, val | 0x4000);
  846. bnx2_read_phy(bp, 0x10, &val);
  847. bnx2_write_phy(bp, 0x10, val | 0x1);
  848. }
  849. else {
  850. u32 val;
  851. bnx2_write_phy(bp, 0x18, 0x7);
  852. bnx2_read_phy(bp, 0x18, &val);
  853. bnx2_write_phy(bp, 0x18, val & ~0x4007);
  854. bnx2_read_phy(bp, 0x10, &val);
  855. bnx2_write_phy(bp, 0x10, val & ~0x1);
  856. }
  857. return 0;
  858. }
  859. static int
  860. bnx2_init_phy(struct bnx2 *bp)
  861. {
  862. u32 val;
  863. int rc = 0;
  864. bp->phy_flags &= ~PHY_INT_MODE_MASK_FLAG;
  865. bp->phy_flags |= PHY_INT_MODE_LINK_READY_FLAG;
  866. REG_WR(bp, BNX2_EMAC_ATTENTION_ENA, BNX2_EMAC_ATTENTION_ENA_LINK);
  867. bnx2_reset_phy(bp);
  868. bnx2_read_phy(bp, MII_PHYSID1, &val);
  869. bp->phy_id = val << 16;
  870. bnx2_read_phy(bp, MII_PHYSID2, &val);
  871. bp->phy_id |= val & 0xffff;
  872. if (bp->phy_flags & PHY_SERDES_FLAG) {
  873. rc = bnx2_init_serdes_phy(bp);
  874. }
  875. else {
  876. rc = bnx2_init_copper_phy(bp);
  877. }
  878. bnx2_setup_phy(bp);
  879. return rc;
  880. }
  881. static int
  882. bnx2_set_mac_loopback(struct bnx2 *bp)
  883. {
  884. u32 mac_mode;
  885. mac_mode = REG_RD(bp, BNX2_EMAC_MODE);
  886. mac_mode &= ~BNX2_EMAC_MODE_PORT;
  887. mac_mode |= BNX2_EMAC_MODE_MAC_LOOP | BNX2_EMAC_MODE_FORCE_LINK;
  888. REG_WR(bp, BNX2_EMAC_MODE, mac_mode);
  889. bp->link_up = 1;
  890. return 0;
  891. }
  892. static int
  893. bnx2_fw_sync(struct bnx2 *bp, u32 msg_data)
  894. {
  895. int i;
  896. u32 val;
  897. if (bp->fw_timed_out)
  898. return -EBUSY;
  899. bp->fw_wr_seq++;
  900. msg_data |= bp->fw_wr_seq;
  901. REG_WR_IND(bp, HOST_VIEW_SHMEM_BASE + BNX2_DRV_MB, msg_data);
  902. /* wait for an acknowledgement. */
  903. for (i = 0; i < (FW_ACK_TIME_OUT_MS * 1000)/5; i++) {
  904. udelay(5);
  905. val = REG_RD_IND(bp, HOST_VIEW_SHMEM_BASE + BNX2_FW_MB);
  906. if ((val & BNX2_FW_MSG_ACK) == (msg_data & BNX2_DRV_MSG_SEQ))
  907. break;
  908. }
  909. /* If we timed out, inform the firmware that this is the case. */
  910. if (((val & BNX2_FW_MSG_ACK) != (msg_data & BNX2_DRV_MSG_SEQ)) &&
  911. ((msg_data & BNX2_DRV_MSG_DATA) != BNX2_DRV_MSG_DATA_WAIT0)) {
  912. msg_data &= ~BNX2_DRV_MSG_CODE;
  913. msg_data |= BNX2_DRV_MSG_CODE_FW_TIMEOUT;
  914. REG_WR_IND(bp, HOST_VIEW_SHMEM_BASE + BNX2_DRV_MB, msg_data);
  915. bp->fw_timed_out = 1;
  916. return -EBUSY;
  917. }
  918. return 0;
  919. }
  920. static void
  921. bnx2_init_context(struct bnx2 *bp)
  922. {
  923. u32 vcid;
  924. vcid = 96;
  925. while (vcid) {
  926. u32 vcid_addr, pcid_addr, offset;
  927. vcid--;
  928. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  929. u32 new_vcid;
  930. vcid_addr = GET_PCID_ADDR(vcid);
  931. if (vcid & 0x8) {
  932. new_vcid = 0x60 + (vcid & 0xf0) + (vcid & 0x7);
  933. }
  934. else {
  935. new_vcid = vcid;
  936. }
  937. pcid_addr = GET_PCID_ADDR(new_vcid);
  938. }
  939. else {
  940. vcid_addr = GET_CID_ADDR(vcid);
  941. pcid_addr = vcid_addr;
  942. }
  943. REG_WR(bp, BNX2_CTX_VIRT_ADDR, 0x00);
  944. REG_WR(bp, BNX2_CTX_PAGE_TBL, pcid_addr);
  945. /* Zero out the context. */
  946. for (offset = 0; offset < PHY_CTX_SIZE; offset += 4) {
  947. CTX_WR(bp, 0x00, offset, 0);
  948. }
  949. REG_WR(bp, BNX2_CTX_VIRT_ADDR, vcid_addr);
  950. REG_WR(bp, BNX2_CTX_PAGE_TBL, pcid_addr);
  951. }
  952. }
  953. static int
  954. bnx2_alloc_bad_rbuf(struct bnx2 *bp)
  955. {
  956. u16 *good_mbuf;
  957. u32 good_mbuf_cnt;
  958. u32 val;
  959. good_mbuf = kmalloc(512 * sizeof(u16), GFP_KERNEL);
  960. if (good_mbuf == NULL) {
  961. printk(KERN_ERR PFX "Failed to allocate memory in "
  962. "bnx2_alloc_bad_rbuf\n");
  963. return -ENOMEM;
  964. }
  965. REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS,
  966. BNX2_MISC_ENABLE_SET_BITS_RX_MBUF_ENABLE);
  967. good_mbuf_cnt = 0;
  968. /* Allocate a bunch of mbufs and save the good ones in an array. */
  969. val = REG_RD_IND(bp, BNX2_RBUF_STATUS1);
  970. while (val & BNX2_RBUF_STATUS1_FREE_COUNT) {
  971. REG_WR_IND(bp, BNX2_RBUF_COMMAND, BNX2_RBUF_COMMAND_ALLOC_REQ);
  972. val = REG_RD_IND(bp, BNX2_RBUF_FW_BUF_ALLOC);
  973. val &= BNX2_RBUF_FW_BUF_ALLOC_VALUE;
  974. /* The addresses with Bit 9 set are bad memory blocks. */
  975. if (!(val & (1 << 9))) {
  976. good_mbuf[good_mbuf_cnt] = (u16) val;
  977. good_mbuf_cnt++;
  978. }
  979. val = REG_RD_IND(bp, BNX2_RBUF_STATUS1);
  980. }
  981. /* Free the good ones back to the mbuf pool thus discarding
  982. * all the bad ones. */
  983. while (good_mbuf_cnt) {
  984. good_mbuf_cnt--;
  985. val = good_mbuf[good_mbuf_cnt];
  986. val = (val << 9) | val | 1;
  987. REG_WR_IND(bp, BNX2_RBUF_FW_BUF_FREE, val);
  988. }
  989. kfree(good_mbuf);
  990. return 0;
  991. }
  992. static void
  993. bnx2_set_mac_addr(struct bnx2 *bp)
  994. {
  995. u32 val;
  996. u8 *mac_addr = bp->dev->dev_addr;
  997. val = (mac_addr[0] << 8) | mac_addr[1];
  998. REG_WR(bp, BNX2_EMAC_MAC_MATCH0, val);
  999. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  1000. (mac_addr[4] << 8) | mac_addr[5];
  1001. REG_WR(bp, BNX2_EMAC_MAC_MATCH1, val);
  1002. }
  1003. static inline int
  1004. bnx2_alloc_rx_skb(struct bnx2 *bp, u16 index)
  1005. {
  1006. struct sk_buff *skb;
  1007. struct sw_bd *rx_buf = &bp->rx_buf_ring[index];
  1008. dma_addr_t mapping;
  1009. struct rx_bd *rxbd = &bp->rx_desc_ring[index];
  1010. unsigned long align;
  1011. skb = dev_alloc_skb(bp->rx_buf_size);
  1012. if (skb == NULL) {
  1013. return -ENOMEM;
  1014. }
  1015. if (unlikely((align = (unsigned long) skb->data & 0x7))) {
  1016. skb_reserve(skb, 8 - align);
  1017. }
  1018. skb->dev = bp->dev;
  1019. mapping = pci_map_single(bp->pdev, skb->data, bp->rx_buf_use_size,
  1020. PCI_DMA_FROMDEVICE);
  1021. rx_buf->skb = skb;
  1022. pci_unmap_addr_set(rx_buf, mapping, mapping);
  1023. rxbd->rx_bd_haddr_hi = (u64) mapping >> 32;
  1024. rxbd->rx_bd_haddr_lo = (u64) mapping & 0xffffffff;
  1025. bp->rx_prod_bseq += bp->rx_buf_use_size;
  1026. return 0;
  1027. }
  1028. static void
  1029. bnx2_phy_int(struct bnx2 *bp)
  1030. {
  1031. u32 new_link_state, old_link_state;
  1032. new_link_state = bp->status_blk->status_attn_bits &
  1033. STATUS_ATTN_BITS_LINK_STATE;
  1034. old_link_state = bp->status_blk->status_attn_bits_ack &
  1035. STATUS_ATTN_BITS_LINK_STATE;
  1036. if (new_link_state != old_link_state) {
  1037. if (new_link_state) {
  1038. REG_WR(bp, BNX2_PCICFG_STATUS_BIT_SET_CMD,
  1039. STATUS_ATTN_BITS_LINK_STATE);
  1040. }
  1041. else {
  1042. REG_WR(bp, BNX2_PCICFG_STATUS_BIT_CLEAR_CMD,
  1043. STATUS_ATTN_BITS_LINK_STATE);
  1044. }
  1045. bnx2_set_link(bp);
  1046. }
  1047. }
  1048. static void
  1049. bnx2_tx_int(struct bnx2 *bp)
  1050. {
  1051. u16 hw_cons, sw_cons, sw_ring_cons;
  1052. int tx_free_bd = 0;
  1053. hw_cons = bp->status_blk->status_tx_quick_consumer_index0;
  1054. if ((hw_cons & MAX_TX_DESC_CNT) == MAX_TX_DESC_CNT) {
  1055. hw_cons++;
  1056. }
  1057. sw_cons = bp->tx_cons;
  1058. while (sw_cons != hw_cons) {
  1059. struct sw_bd *tx_buf;
  1060. struct sk_buff *skb;
  1061. int i, last;
  1062. sw_ring_cons = TX_RING_IDX(sw_cons);
  1063. tx_buf = &bp->tx_buf_ring[sw_ring_cons];
  1064. skb = tx_buf->skb;
  1065. #ifdef BCM_TSO
  1066. /* partial BD completions possible with TSO packets */
  1067. if (skb_shinfo(skb)->tso_size) {
  1068. u16 last_idx, last_ring_idx;
  1069. last_idx = sw_cons +
  1070. skb_shinfo(skb)->nr_frags + 1;
  1071. last_ring_idx = sw_ring_cons +
  1072. skb_shinfo(skb)->nr_frags + 1;
  1073. if (unlikely(last_ring_idx >= MAX_TX_DESC_CNT)) {
  1074. last_idx++;
  1075. }
  1076. if (((s16) ((s16) last_idx - (s16) hw_cons)) > 0) {
  1077. break;
  1078. }
  1079. }
  1080. #endif
  1081. pci_unmap_single(bp->pdev, pci_unmap_addr(tx_buf, mapping),
  1082. skb_headlen(skb), PCI_DMA_TODEVICE);
  1083. tx_buf->skb = NULL;
  1084. last = skb_shinfo(skb)->nr_frags;
  1085. for (i = 0; i < last; i++) {
  1086. sw_cons = NEXT_TX_BD(sw_cons);
  1087. pci_unmap_page(bp->pdev,
  1088. pci_unmap_addr(
  1089. &bp->tx_buf_ring[TX_RING_IDX(sw_cons)],
  1090. mapping),
  1091. skb_shinfo(skb)->frags[i].size,
  1092. PCI_DMA_TODEVICE);
  1093. }
  1094. sw_cons = NEXT_TX_BD(sw_cons);
  1095. tx_free_bd += last + 1;
  1096. dev_kfree_skb_irq(skb);
  1097. hw_cons = bp->status_blk->status_tx_quick_consumer_index0;
  1098. if ((hw_cons & MAX_TX_DESC_CNT) == MAX_TX_DESC_CNT) {
  1099. hw_cons++;
  1100. }
  1101. }
  1102. bp->tx_cons = sw_cons;
  1103. if (unlikely(netif_queue_stopped(bp->dev))) {
  1104. spin_lock(&bp->tx_lock);
  1105. if ((netif_queue_stopped(bp->dev)) &&
  1106. (bnx2_tx_avail(bp) > MAX_SKB_FRAGS)) {
  1107. netif_wake_queue(bp->dev);
  1108. }
  1109. spin_unlock(&bp->tx_lock);
  1110. }
  1111. }
  1112. static inline void
  1113. bnx2_reuse_rx_skb(struct bnx2 *bp, struct sk_buff *skb,
  1114. u16 cons, u16 prod)
  1115. {
  1116. struct sw_bd *cons_rx_buf = &bp->rx_buf_ring[cons];
  1117. struct sw_bd *prod_rx_buf = &bp->rx_buf_ring[prod];
  1118. struct rx_bd *cons_bd = &bp->rx_desc_ring[cons];
  1119. struct rx_bd *prod_bd = &bp->rx_desc_ring[prod];
  1120. pci_dma_sync_single_for_device(bp->pdev,
  1121. pci_unmap_addr(cons_rx_buf, mapping),
  1122. bp->rx_offset + RX_COPY_THRESH, PCI_DMA_FROMDEVICE);
  1123. prod_rx_buf->skb = cons_rx_buf->skb;
  1124. pci_unmap_addr_set(prod_rx_buf, mapping,
  1125. pci_unmap_addr(cons_rx_buf, mapping));
  1126. memcpy(prod_bd, cons_bd, 8);
  1127. bp->rx_prod_bseq += bp->rx_buf_use_size;
  1128. }
  1129. static int
  1130. bnx2_rx_int(struct bnx2 *bp, int budget)
  1131. {
  1132. u16 hw_cons, sw_cons, sw_ring_cons, sw_prod, sw_ring_prod;
  1133. struct l2_fhdr *rx_hdr;
  1134. int rx_pkt = 0;
  1135. hw_cons = bp->status_blk->status_rx_quick_consumer_index0;
  1136. if ((hw_cons & MAX_RX_DESC_CNT) == MAX_RX_DESC_CNT) {
  1137. hw_cons++;
  1138. }
  1139. sw_cons = bp->rx_cons;
  1140. sw_prod = bp->rx_prod;
  1141. /* Memory barrier necessary as speculative reads of the rx
  1142. * buffer can be ahead of the index in the status block
  1143. */
  1144. rmb();
  1145. while (sw_cons != hw_cons) {
  1146. unsigned int len;
  1147. u16 status;
  1148. struct sw_bd *rx_buf;
  1149. struct sk_buff *skb;
  1150. sw_ring_cons = RX_RING_IDX(sw_cons);
  1151. sw_ring_prod = RX_RING_IDX(sw_prod);
  1152. rx_buf = &bp->rx_buf_ring[sw_ring_cons];
  1153. skb = rx_buf->skb;
  1154. pci_dma_sync_single_for_cpu(bp->pdev,
  1155. pci_unmap_addr(rx_buf, mapping),
  1156. bp->rx_offset + RX_COPY_THRESH, PCI_DMA_FROMDEVICE);
  1157. rx_hdr = (struct l2_fhdr *) skb->data;
  1158. len = rx_hdr->l2_fhdr_pkt_len - 4;
  1159. if (rx_hdr->l2_fhdr_errors &
  1160. (L2_FHDR_ERRORS_BAD_CRC |
  1161. L2_FHDR_ERRORS_PHY_DECODE |
  1162. L2_FHDR_ERRORS_ALIGNMENT |
  1163. L2_FHDR_ERRORS_TOO_SHORT |
  1164. L2_FHDR_ERRORS_GIANT_FRAME)) {
  1165. goto reuse_rx;
  1166. }
  1167. /* Since we don't have a jumbo ring, copy small packets
  1168. * if mtu > 1500
  1169. */
  1170. if ((bp->dev->mtu > 1500) && (len <= RX_COPY_THRESH)) {
  1171. struct sk_buff *new_skb;
  1172. new_skb = dev_alloc_skb(len + 2);
  1173. if (new_skb == NULL)
  1174. goto reuse_rx;
  1175. /* aligned copy */
  1176. memcpy(new_skb->data,
  1177. skb->data + bp->rx_offset - 2,
  1178. len + 2);
  1179. skb_reserve(new_skb, 2);
  1180. skb_put(new_skb, len);
  1181. new_skb->dev = bp->dev;
  1182. bnx2_reuse_rx_skb(bp, skb,
  1183. sw_ring_cons, sw_ring_prod);
  1184. skb = new_skb;
  1185. }
  1186. else if (bnx2_alloc_rx_skb(bp, sw_ring_prod) == 0) {
  1187. pci_unmap_single(bp->pdev,
  1188. pci_unmap_addr(rx_buf, mapping),
  1189. bp->rx_buf_use_size, PCI_DMA_FROMDEVICE);
  1190. skb_reserve(skb, bp->rx_offset);
  1191. skb_put(skb, len);
  1192. }
  1193. else {
  1194. reuse_rx:
  1195. bnx2_reuse_rx_skb(bp, skb,
  1196. sw_ring_cons, sw_ring_prod);
  1197. goto next_rx;
  1198. }
  1199. skb->protocol = eth_type_trans(skb, bp->dev);
  1200. if ((len > (bp->dev->mtu + ETH_HLEN)) &&
  1201. (htons(skb->protocol) != 0x8100)) {
  1202. dev_kfree_skb_irq(skb);
  1203. goto next_rx;
  1204. }
  1205. status = rx_hdr->l2_fhdr_status;
  1206. skb->ip_summed = CHECKSUM_NONE;
  1207. if (bp->rx_csum &&
  1208. (status & (L2_FHDR_STATUS_TCP_SEGMENT |
  1209. L2_FHDR_STATUS_UDP_DATAGRAM))) {
  1210. u16 cksum = rx_hdr->l2_fhdr_tcp_udp_xsum;
  1211. if (cksum == 0xffff)
  1212. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1213. }
  1214. #ifdef BCM_VLAN
  1215. if ((status & L2_FHDR_STATUS_L2_VLAN_TAG) && (bp->vlgrp != 0)) {
  1216. vlan_hwaccel_receive_skb(skb, bp->vlgrp,
  1217. rx_hdr->l2_fhdr_vlan_tag);
  1218. }
  1219. else
  1220. #endif
  1221. netif_receive_skb(skb);
  1222. bp->dev->last_rx = jiffies;
  1223. rx_pkt++;
  1224. next_rx:
  1225. rx_buf->skb = NULL;
  1226. sw_cons = NEXT_RX_BD(sw_cons);
  1227. sw_prod = NEXT_RX_BD(sw_prod);
  1228. if ((rx_pkt == budget))
  1229. break;
  1230. }
  1231. bp->rx_cons = sw_cons;
  1232. bp->rx_prod = sw_prod;
  1233. REG_WR16(bp, MB_RX_CID_ADDR + BNX2_L2CTX_HOST_BDIDX, sw_prod);
  1234. REG_WR(bp, MB_RX_CID_ADDR + BNX2_L2CTX_HOST_BSEQ, bp->rx_prod_bseq);
  1235. mmiowb();
  1236. return rx_pkt;
  1237. }
  1238. /* MSI ISR - The only difference between this and the INTx ISR
  1239. * is that the MSI interrupt is always serviced.
  1240. */
  1241. static irqreturn_t
  1242. bnx2_msi(int irq, void *dev_instance, struct pt_regs *regs)
  1243. {
  1244. struct net_device *dev = dev_instance;
  1245. struct bnx2 *bp = dev->priv;
  1246. prefetch(bp->status_blk);
  1247. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  1248. BNX2_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM |
  1249. BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
  1250. /* Return here if interrupt is disabled. */
  1251. if (unlikely(atomic_read(&bp->intr_sem) != 0))
  1252. return IRQ_HANDLED;
  1253. netif_rx_schedule(dev);
  1254. return IRQ_HANDLED;
  1255. }
  1256. static irqreturn_t
  1257. bnx2_interrupt(int irq, void *dev_instance, struct pt_regs *regs)
  1258. {
  1259. struct net_device *dev = dev_instance;
  1260. struct bnx2 *bp = dev->priv;
  1261. /* When using INTx, it is possible for the interrupt to arrive
  1262. * at the CPU before the status block posted prior to the
  1263. * interrupt. Reading a register will flush the status block.
  1264. * When using MSI, the MSI message will always complete after
  1265. * the status block write.
  1266. */
  1267. if ((bp->status_blk->status_idx == bp->last_status_idx) &&
  1268. (REG_RD(bp, BNX2_PCICFG_MISC_STATUS) &
  1269. BNX2_PCICFG_MISC_STATUS_INTA_VALUE))
  1270. return IRQ_NONE;
  1271. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  1272. BNX2_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM |
  1273. BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
  1274. /* Return here if interrupt is shared and is disabled. */
  1275. if (unlikely(atomic_read(&bp->intr_sem) != 0))
  1276. return IRQ_HANDLED;
  1277. netif_rx_schedule(dev);
  1278. return IRQ_HANDLED;
  1279. }
  1280. static int
  1281. bnx2_poll(struct net_device *dev, int *budget)
  1282. {
  1283. struct bnx2 *bp = dev->priv;
  1284. int rx_done = 1;
  1285. bp->last_status_idx = bp->status_blk->status_idx;
  1286. rmb();
  1287. if ((bp->status_blk->status_attn_bits &
  1288. STATUS_ATTN_BITS_LINK_STATE) !=
  1289. (bp->status_blk->status_attn_bits_ack &
  1290. STATUS_ATTN_BITS_LINK_STATE)) {
  1291. spin_lock(&bp->phy_lock);
  1292. bnx2_phy_int(bp);
  1293. spin_unlock(&bp->phy_lock);
  1294. }
  1295. if (bp->status_blk->status_tx_quick_consumer_index0 != bp->tx_cons) {
  1296. bnx2_tx_int(bp);
  1297. }
  1298. if (bp->status_blk->status_rx_quick_consumer_index0 != bp->rx_cons) {
  1299. int orig_budget = *budget;
  1300. int work_done;
  1301. if (orig_budget > dev->quota)
  1302. orig_budget = dev->quota;
  1303. work_done = bnx2_rx_int(bp, orig_budget);
  1304. *budget -= work_done;
  1305. dev->quota -= work_done;
  1306. if (work_done >= orig_budget) {
  1307. rx_done = 0;
  1308. }
  1309. }
  1310. if (rx_done) {
  1311. netif_rx_complete(dev);
  1312. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  1313. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID |
  1314. bp->last_status_idx);
  1315. return 0;
  1316. }
  1317. return 1;
  1318. }
  1319. /* Called with rtnl_lock from vlan functions and also dev->xmit_lock
  1320. * from set_multicast.
  1321. */
  1322. static void
  1323. bnx2_set_rx_mode(struct net_device *dev)
  1324. {
  1325. struct bnx2 *bp = dev->priv;
  1326. u32 rx_mode, sort_mode;
  1327. int i;
  1328. spin_lock_bh(&bp->phy_lock);
  1329. rx_mode = bp->rx_mode & ~(BNX2_EMAC_RX_MODE_PROMISCUOUS |
  1330. BNX2_EMAC_RX_MODE_KEEP_VLAN_TAG);
  1331. sort_mode = 1 | BNX2_RPM_SORT_USER0_BC_EN;
  1332. #ifdef BCM_VLAN
  1333. if (!bp->vlgrp) {
  1334. rx_mode |= BNX2_EMAC_RX_MODE_KEEP_VLAN_TAG;
  1335. }
  1336. #else
  1337. rx_mode |= BNX2_EMAC_RX_MODE_KEEP_VLAN_TAG;
  1338. #endif
  1339. if (dev->flags & IFF_PROMISC) {
  1340. /* Promiscuous mode. */
  1341. rx_mode |= BNX2_EMAC_RX_MODE_PROMISCUOUS;
  1342. sort_mode |= BNX2_RPM_SORT_USER0_PROM_EN;
  1343. }
  1344. else if (dev->flags & IFF_ALLMULTI) {
  1345. for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
  1346. REG_WR(bp, BNX2_EMAC_MULTICAST_HASH0 + (i * 4),
  1347. 0xffffffff);
  1348. }
  1349. sort_mode |= BNX2_RPM_SORT_USER0_MC_EN;
  1350. }
  1351. else {
  1352. /* Accept one or more multicast(s). */
  1353. struct dev_mc_list *mclist;
  1354. u32 mc_filter[NUM_MC_HASH_REGISTERS];
  1355. u32 regidx;
  1356. u32 bit;
  1357. u32 crc;
  1358. memset(mc_filter, 0, 4 * NUM_MC_HASH_REGISTERS);
  1359. for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
  1360. i++, mclist = mclist->next) {
  1361. crc = ether_crc_le(ETH_ALEN, mclist->dmi_addr);
  1362. bit = crc & 0xff;
  1363. regidx = (bit & 0xe0) >> 5;
  1364. bit &= 0x1f;
  1365. mc_filter[regidx] |= (1 << bit);
  1366. }
  1367. for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
  1368. REG_WR(bp, BNX2_EMAC_MULTICAST_HASH0 + (i * 4),
  1369. mc_filter[i]);
  1370. }
  1371. sort_mode |= BNX2_RPM_SORT_USER0_MC_HSH_EN;
  1372. }
  1373. if (rx_mode != bp->rx_mode) {
  1374. bp->rx_mode = rx_mode;
  1375. REG_WR(bp, BNX2_EMAC_RX_MODE, rx_mode);
  1376. }
  1377. REG_WR(bp, BNX2_RPM_SORT_USER0, 0x0);
  1378. REG_WR(bp, BNX2_RPM_SORT_USER0, sort_mode);
  1379. REG_WR(bp, BNX2_RPM_SORT_USER0, sort_mode | BNX2_RPM_SORT_USER0_ENA);
  1380. spin_unlock_bh(&bp->phy_lock);
  1381. }
  1382. static void
  1383. load_rv2p_fw(struct bnx2 *bp, u32 *rv2p_code, u32 rv2p_code_len,
  1384. u32 rv2p_proc)
  1385. {
  1386. int i;
  1387. u32 val;
  1388. for (i = 0; i < rv2p_code_len; i += 8) {
  1389. REG_WR(bp, BNX2_RV2P_INSTR_HIGH, *rv2p_code);
  1390. rv2p_code++;
  1391. REG_WR(bp, BNX2_RV2P_INSTR_LOW, *rv2p_code);
  1392. rv2p_code++;
  1393. if (rv2p_proc == RV2P_PROC1) {
  1394. val = (i / 8) | BNX2_RV2P_PROC1_ADDR_CMD_RDWR;
  1395. REG_WR(bp, BNX2_RV2P_PROC1_ADDR_CMD, val);
  1396. }
  1397. else {
  1398. val = (i / 8) | BNX2_RV2P_PROC2_ADDR_CMD_RDWR;
  1399. REG_WR(bp, BNX2_RV2P_PROC2_ADDR_CMD, val);
  1400. }
  1401. }
  1402. /* Reset the processor, un-stall is done later. */
  1403. if (rv2p_proc == RV2P_PROC1) {
  1404. REG_WR(bp, BNX2_RV2P_COMMAND, BNX2_RV2P_COMMAND_PROC1_RESET);
  1405. }
  1406. else {
  1407. REG_WR(bp, BNX2_RV2P_COMMAND, BNX2_RV2P_COMMAND_PROC2_RESET);
  1408. }
  1409. }
  1410. static void
  1411. load_cpu_fw(struct bnx2 *bp, struct cpu_reg *cpu_reg, struct fw_info *fw)
  1412. {
  1413. u32 offset;
  1414. u32 val;
  1415. /* Halt the CPU. */
  1416. val = REG_RD_IND(bp, cpu_reg->mode);
  1417. val |= cpu_reg->mode_value_halt;
  1418. REG_WR_IND(bp, cpu_reg->mode, val);
  1419. REG_WR_IND(bp, cpu_reg->state, cpu_reg->state_value_clear);
  1420. /* Load the Text area. */
  1421. offset = cpu_reg->spad_base + (fw->text_addr - cpu_reg->mips_view_base);
  1422. if (fw->text) {
  1423. int j;
  1424. for (j = 0; j < (fw->text_len / 4); j++, offset += 4) {
  1425. REG_WR_IND(bp, offset, fw->text[j]);
  1426. }
  1427. }
  1428. /* Load the Data area. */
  1429. offset = cpu_reg->spad_base + (fw->data_addr - cpu_reg->mips_view_base);
  1430. if (fw->data) {
  1431. int j;
  1432. for (j = 0; j < (fw->data_len / 4); j++, offset += 4) {
  1433. REG_WR_IND(bp, offset, fw->data[j]);
  1434. }
  1435. }
  1436. /* Load the SBSS area. */
  1437. offset = cpu_reg->spad_base + (fw->sbss_addr - cpu_reg->mips_view_base);
  1438. if (fw->sbss) {
  1439. int j;
  1440. for (j = 0; j < (fw->sbss_len / 4); j++, offset += 4) {
  1441. REG_WR_IND(bp, offset, fw->sbss[j]);
  1442. }
  1443. }
  1444. /* Load the BSS area. */
  1445. offset = cpu_reg->spad_base + (fw->bss_addr - cpu_reg->mips_view_base);
  1446. if (fw->bss) {
  1447. int j;
  1448. for (j = 0; j < (fw->bss_len/4); j++, offset += 4) {
  1449. REG_WR_IND(bp, offset, fw->bss[j]);
  1450. }
  1451. }
  1452. /* Load the Read-Only area. */
  1453. offset = cpu_reg->spad_base +
  1454. (fw->rodata_addr - cpu_reg->mips_view_base);
  1455. if (fw->rodata) {
  1456. int j;
  1457. for (j = 0; j < (fw->rodata_len / 4); j++, offset += 4) {
  1458. REG_WR_IND(bp, offset, fw->rodata[j]);
  1459. }
  1460. }
  1461. /* Clear the pre-fetch instruction. */
  1462. REG_WR_IND(bp, cpu_reg->inst, 0);
  1463. REG_WR_IND(bp, cpu_reg->pc, fw->start_addr);
  1464. /* Start the CPU. */
  1465. val = REG_RD_IND(bp, cpu_reg->mode);
  1466. val &= ~cpu_reg->mode_value_halt;
  1467. REG_WR_IND(bp, cpu_reg->state, cpu_reg->state_value_clear);
  1468. REG_WR_IND(bp, cpu_reg->mode, val);
  1469. }
  1470. static void
  1471. bnx2_init_cpus(struct bnx2 *bp)
  1472. {
  1473. struct cpu_reg cpu_reg;
  1474. struct fw_info fw;
  1475. /* Initialize the RV2P processor. */
  1476. load_rv2p_fw(bp, bnx2_rv2p_proc1, sizeof(bnx2_rv2p_proc1), RV2P_PROC1);
  1477. load_rv2p_fw(bp, bnx2_rv2p_proc2, sizeof(bnx2_rv2p_proc2), RV2P_PROC2);
  1478. /* Initialize the RX Processor. */
  1479. cpu_reg.mode = BNX2_RXP_CPU_MODE;
  1480. cpu_reg.mode_value_halt = BNX2_RXP_CPU_MODE_SOFT_HALT;
  1481. cpu_reg.mode_value_sstep = BNX2_RXP_CPU_MODE_STEP_ENA;
  1482. cpu_reg.state = BNX2_RXP_CPU_STATE;
  1483. cpu_reg.state_value_clear = 0xffffff;
  1484. cpu_reg.gpr0 = BNX2_RXP_CPU_REG_FILE;
  1485. cpu_reg.evmask = BNX2_RXP_CPU_EVENT_MASK;
  1486. cpu_reg.pc = BNX2_RXP_CPU_PROGRAM_COUNTER;
  1487. cpu_reg.inst = BNX2_RXP_CPU_INSTRUCTION;
  1488. cpu_reg.bp = BNX2_RXP_CPU_HW_BREAKPOINT;
  1489. cpu_reg.spad_base = BNX2_RXP_SCRATCH;
  1490. cpu_reg.mips_view_base = 0x8000000;
  1491. fw.ver_major = bnx2_RXP_b06FwReleaseMajor;
  1492. fw.ver_minor = bnx2_RXP_b06FwReleaseMinor;
  1493. fw.ver_fix = bnx2_RXP_b06FwReleaseFix;
  1494. fw.start_addr = bnx2_RXP_b06FwStartAddr;
  1495. fw.text_addr = bnx2_RXP_b06FwTextAddr;
  1496. fw.text_len = bnx2_RXP_b06FwTextLen;
  1497. fw.text_index = 0;
  1498. fw.text = bnx2_RXP_b06FwText;
  1499. fw.data_addr = bnx2_RXP_b06FwDataAddr;
  1500. fw.data_len = bnx2_RXP_b06FwDataLen;
  1501. fw.data_index = 0;
  1502. fw.data = bnx2_RXP_b06FwData;
  1503. fw.sbss_addr = bnx2_RXP_b06FwSbssAddr;
  1504. fw.sbss_len = bnx2_RXP_b06FwSbssLen;
  1505. fw.sbss_index = 0;
  1506. fw.sbss = bnx2_RXP_b06FwSbss;
  1507. fw.bss_addr = bnx2_RXP_b06FwBssAddr;
  1508. fw.bss_len = bnx2_RXP_b06FwBssLen;
  1509. fw.bss_index = 0;
  1510. fw.bss = bnx2_RXP_b06FwBss;
  1511. fw.rodata_addr = bnx2_RXP_b06FwRodataAddr;
  1512. fw.rodata_len = bnx2_RXP_b06FwRodataLen;
  1513. fw.rodata_index = 0;
  1514. fw.rodata = bnx2_RXP_b06FwRodata;
  1515. load_cpu_fw(bp, &cpu_reg, &fw);
  1516. /* Initialize the TX Processor. */
  1517. cpu_reg.mode = BNX2_TXP_CPU_MODE;
  1518. cpu_reg.mode_value_halt = BNX2_TXP_CPU_MODE_SOFT_HALT;
  1519. cpu_reg.mode_value_sstep = BNX2_TXP_CPU_MODE_STEP_ENA;
  1520. cpu_reg.state = BNX2_TXP_CPU_STATE;
  1521. cpu_reg.state_value_clear = 0xffffff;
  1522. cpu_reg.gpr0 = BNX2_TXP_CPU_REG_FILE;
  1523. cpu_reg.evmask = BNX2_TXP_CPU_EVENT_MASK;
  1524. cpu_reg.pc = BNX2_TXP_CPU_PROGRAM_COUNTER;
  1525. cpu_reg.inst = BNX2_TXP_CPU_INSTRUCTION;
  1526. cpu_reg.bp = BNX2_TXP_CPU_HW_BREAKPOINT;
  1527. cpu_reg.spad_base = BNX2_TXP_SCRATCH;
  1528. cpu_reg.mips_view_base = 0x8000000;
  1529. fw.ver_major = bnx2_TXP_b06FwReleaseMajor;
  1530. fw.ver_minor = bnx2_TXP_b06FwReleaseMinor;
  1531. fw.ver_fix = bnx2_TXP_b06FwReleaseFix;
  1532. fw.start_addr = bnx2_TXP_b06FwStartAddr;
  1533. fw.text_addr = bnx2_TXP_b06FwTextAddr;
  1534. fw.text_len = bnx2_TXP_b06FwTextLen;
  1535. fw.text_index = 0;
  1536. fw.text = bnx2_TXP_b06FwText;
  1537. fw.data_addr = bnx2_TXP_b06FwDataAddr;
  1538. fw.data_len = bnx2_TXP_b06FwDataLen;
  1539. fw.data_index = 0;
  1540. fw.data = bnx2_TXP_b06FwData;
  1541. fw.sbss_addr = bnx2_TXP_b06FwSbssAddr;
  1542. fw.sbss_len = bnx2_TXP_b06FwSbssLen;
  1543. fw.sbss_index = 0;
  1544. fw.sbss = bnx2_TXP_b06FwSbss;
  1545. fw.bss_addr = bnx2_TXP_b06FwBssAddr;
  1546. fw.bss_len = bnx2_TXP_b06FwBssLen;
  1547. fw.bss_index = 0;
  1548. fw.bss = bnx2_TXP_b06FwBss;
  1549. fw.rodata_addr = bnx2_TXP_b06FwRodataAddr;
  1550. fw.rodata_len = bnx2_TXP_b06FwRodataLen;
  1551. fw.rodata_index = 0;
  1552. fw.rodata = bnx2_TXP_b06FwRodata;
  1553. load_cpu_fw(bp, &cpu_reg, &fw);
  1554. /* Initialize the TX Patch-up Processor. */
  1555. cpu_reg.mode = BNX2_TPAT_CPU_MODE;
  1556. cpu_reg.mode_value_halt = BNX2_TPAT_CPU_MODE_SOFT_HALT;
  1557. cpu_reg.mode_value_sstep = BNX2_TPAT_CPU_MODE_STEP_ENA;
  1558. cpu_reg.state = BNX2_TPAT_CPU_STATE;
  1559. cpu_reg.state_value_clear = 0xffffff;
  1560. cpu_reg.gpr0 = BNX2_TPAT_CPU_REG_FILE;
  1561. cpu_reg.evmask = BNX2_TPAT_CPU_EVENT_MASK;
  1562. cpu_reg.pc = BNX2_TPAT_CPU_PROGRAM_COUNTER;
  1563. cpu_reg.inst = BNX2_TPAT_CPU_INSTRUCTION;
  1564. cpu_reg.bp = BNX2_TPAT_CPU_HW_BREAKPOINT;
  1565. cpu_reg.spad_base = BNX2_TPAT_SCRATCH;
  1566. cpu_reg.mips_view_base = 0x8000000;
  1567. fw.ver_major = bnx2_TPAT_b06FwReleaseMajor;
  1568. fw.ver_minor = bnx2_TPAT_b06FwReleaseMinor;
  1569. fw.ver_fix = bnx2_TPAT_b06FwReleaseFix;
  1570. fw.start_addr = bnx2_TPAT_b06FwStartAddr;
  1571. fw.text_addr = bnx2_TPAT_b06FwTextAddr;
  1572. fw.text_len = bnx2_TPAT_b06FwTextLen;
  1573. fw.text_index = 0;
  1574. fw.text = bnx2_TPAT_b06FwText;
  1575. fw.data_addr = bnx2_TPAT_b06FwDataAddr;
  1576. fw.data_len = bnx2_TPAT_b06FwDataLen;
  1577. fw.data_index = 0;
  1578. fw.data = bnx2_TPAT_b06FwData;
  1579. fw.sbss_addr = bnx2_TPAT_b06FwSbssAddr;
  1580. fw.sbss_len = bnx2_TPAT_b06FwSbssLen;
  1581. fw.sbss_index = 0;
  1582. fw.sbss = bnx2_TPAT_b06FwSbss;
  1583. fw.bss_addr = bnx2_TPAT_b06FwBssAddr;
  1584. fw.bss_len = bnx2_TPAT_b06FwBssLen;
  1585. fw.bss_index = 0;
  1586. fw.bss = bnx2_TPAT_b06FwBss;
  1587. fw.rodata_addr = bnx2_TPAT_b06FwRodataAddr;
  1588. fw.rodata_len = bnx2_TPAT_b06FwRodataLen;
  1589. fw.rodata_index = 0;
  1590. fw.rodata = bnx2_TPAT_b06FwRodata;
  1591. load_cpu_fw(bp, &cpu_reg, &fw);
  1592. /* Initialize the Completion Processor. */
  1593. cpu_reg.mode = BNX2_COM_CPU_MODE;
  1594. cpu_reg.mode_value_halt = BNX2_COM_CPU_MODE_SOFT_HALT;
  1595. cpu_reg.mode_value_sstep = BNX2_COM_CPU_MODE_STEP_ENA;
  1596. cpu_reg.state = BNX2_COM_CPU_STATE;
  1597. cpu_reg.state_value_clear = 0xffffff;
  1598. cpu_reg.gpr0 = BNX2_COM_CPU_REG_FILE;
  1599. cpu_reg.evmask = BNX2_COM_CPU_EVENT_MASK;
  1600. cpu_reg.pc = BNX2_COM_CPU_PROGRAM_COUNTER;
  1601. cpu_reg.inst = BNX2_COM_CPU_INSTRUCTION;
  1602. cpu_reg.bp = BNX2_COM_CPU_HW_BREAKPOINT;
  1603. cpu_reg.spad_base = BNX2_COM_SCRATCH;
  1604. cpu_reg.mips_view_base = 0x8000000;
  1605. fw.ver_major = bnx2_COM_b06FwReleaseMajor;
  1606. fw.ver_minor = bnx2_COM_b06FwReleaseMinor;
  1607. fw.ver_fix = bnx2_COM_b06FwReleaseFix;
  1608. fw.start_addr = bnx2_COM_b06FwStartAddr;
  1609. fw.text_addr = bnx2_COM_b06FwTextAddr;
  1610. fw.text_len = bnx2_COM_b06FwTextLen;
  1611. fw.text_index = 0;
  1612. fw.text = bnx2_COM_b06FwText;
  1613. fw.data_addr = bnx2_COM_b06FwDataAddr;
  1614. fw.data_len = bnx2_COM_b06FwDataLen;
  1615. fw.data_index = 0;
  1616. fw.data = bnx2_COM_b06FwData;
  1617. fw.sbss_addr = bnx2_COM_b06FwSbssAddr;
  1618. fw.sbss_len = bnx2_COM_b06FwSbssLen;
  1619. fw.sbss_index = 0;
  1620. fw.sbss = bnx2_COM_b06FwSbss;
  1621. fw.bss_addr = bnx2_COM_b06FwBssAddr;
  1622. fw.bss_len = bnx2_COM_b06FwBssLen;
  1623. fw.bss_index = 0;
  1624. fw.bss = bnx2_COM_b06FwBss;
  1625. fw.rodata_addr = bnx2_COM_b06FwRodataAddr;
  1626. fw.rodata_len = bnx2_COM_b06FwRodataLen;
  1627. fw.rodata_index = 0;
  1628. fw.rodata = bnx2_COM_b06FwRodata;
  1629. load_cpu_fw(bp, &cpu_reg, &fw);
  1630. }
  1631. static int
  1632. bnx2_set_power_state(struct bnx2 *bp, pci_power_t state)
  1633. {
  1634. u16 pmcsr;
  1635. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmcsr);
  1636. switch (state) {
  1637. case PCI_D0: {
  1638. u32 val;
  1639. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL,
  1640. (pmcsr & ~PCI_PM_CTRL_STATE_MASK) |
  1641. PCI_PM_CTRL_PME_STATUS);
  1642. if (pmcsr & PCI_PM_CTRL_STATE_MASK)
  1643. /* delay required during transition out of D3hot */
  1644. msleep(20);
  1645. val = REG_RD(bp, BNX2_EMAC_MODE);
  1646. val |= BNX2_EMAC_MODE_MPKT_RCVD | BNX2_EMAC_MODE_ACPI_RCVD;
  1647. val &= ~BNX2_EMAC_MODE_MPKT;
  1648. REG_WR(bp, BNX2_EMAC_MODE, val);
  1649. val = REG_RD(bp, BNX2_RPM_CONFIG);
  1650. val &= ~BNX2_RPM_CONFIG_ACPI_ENA;
  1651. REG_WR(bp, BNX2_RPM_CONFIG, val);
  1652. break;
  1653. }
  1654. case PCI_D3hot: {
  1655. int i;
  1656. u32 val, wol_msg;
  1657. if (bp->wol) {
  1658. u32 advertising;
  1659. u8 autoneg;
  1660. autoneg = bp->autoneg;
  1661. advertising = bp->advertising;
  1662. bp->autoneg = AUTONEG_SPEED;
  1663. bp->advertising = ADVERTISED_10baseT_Half |
  1664. ADVERTISED_10baseT_Full |
  1665. ADVERTISED_100baseT_Half |
  1666. ADVERTISED_100baseT_Full |
  1667. ADVERTISED_Autoneg;
  1668. bnx2_setup_copper_phy(bp);
  1669. bp->autoneg = autoneg;
  1670. bp->advertising = advertising;
  1671. bnx2_set_mac_addr(bp);
  1672. val = REG_RD(bp, BNX2_EMAC_MODE);
  1673. /* Enable port mode. */
  1674. val &= ~BNX2_EMAC_MODE_PORT;
  1675. val |= BNX2_EMAC_MODE_PORT_MII |
  1676. BNX2_EMAC_MODE_MPKT_RCVD |
  1677. BNX2_EMAC_MODE_ACPI_RCVD |
  1678. BNX2_EMAC_MODE_FORCE_LINK |
  1679. BNX2_EMAC_MODE_MPKT;
  1680. REG_WR(bp, BNX2_EMAC_MODE, val);
  1681. /* receive all multicast */
  1682. for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
  1683. REG_WR(bp, BNX2_EMAC_MULTICAST_HASH0 + (i * 4),
  1684. 0xffffffff);
  1685. }
  1686. REG_WR(bp, BNX2_EMAC_RX_MODE,
  1687. BNX2_EMAC_RX_MODE_SORT_MODE);
  1688. val = 1 | BNX2_RPM_SORT_USER0_BC_EN |
  1689. BNX2_RPM_SORT_USER0_MC_EN;
  1690. REG_WR(bp, BNX2_RPM_SORT_USER0, 0x0);
  1691. REG_WR(bp, BNX2_RPM_SORT_USER0, val);
  1692. REG_WR(bp, BNX2_RPM_SORT_USER0, val |
  1693. BNX2_RPM_SORT_USER0_ENA);
  1694. /* Need to enable EMAC and RPM for WOL. */
  1695. REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS,
  1696. BNX2_MISC_ENABLE_SET_BITS_RX_PARSER_MAC_ENABLE |
  1697. BNX2_MISC_ENABLE_SET_BITS_TX_HEADER_Q_ENABLE |
  1698. BNX2_MISC_ENABLE_SET_BITS_EMAC_ENABLE);
  1699. val = REG_RD(bp, BNX2_RPM_CONFIG);
  1700. val &= ~BNX2_RPM_CONFIG_ACPI_ENA;
  1701. REG_WR(bp, BNX2_RPM_CONFIG, val);
  1702. wol_msg = BNX2_DRV_MSG_CODE_SUSPEND_WOL;
  1703. }
  1704. else {
  1705. wol_msg = BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL;
  1706. }
  1707. bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT3 | wol_msg);
  1708. pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
  1709. if ((CHIP_ID(bp) == CHIP_ID_5706_A0) ||
  1710. (CHIP_ID(bp) == CHIP_ID_5706_A1)) {
  1711. if (bp->wol)
  1712. pmcsr |= 3;
  1713. }
  1714. else {
  1715. pmcsr |= 3;
  1716. }
  1717. if (bp->wol) {
  1718. pmcsr |= PCI_PM_CTRL_PME_ENABLE;
  1719. }
  1720. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL,
  1721. pmcsr);
  1722. /* No more memory access after this point until
  1723. * device is brought back to D0.
  1724. */
  1725. udelay(50);
  1726. break;
  1727. }
  1728. default:
  1729. return -EINVAL;
  1730. }
  1731. return 0;
  1732. }
  1733. static int
  1734. bnx2_acquire_nvram_lock(struct bnx2 *bp)
  1735. {
  1736. u32 val;
  1737. int j;
  1738. /* Request access to the flash interface. */
  1739. REG_WR(bp, BNX2_NVM_SW_ARB, BNX2_NVM_SW_ARB_ARB_REQ_SET2);
  1740. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  1741. val = REG_RD(bp, BNX2_NVM_SW_ARB);
  1742. if (val & BNX2_NVM_SW_ARB_ARB_ARB2)
  1743. break;
  1744. udelay(5);
  1745. }
  1746. if (j >= NVRAM_TIMEOUT_COUNT)
  1747. return -EBUSY;
  1748. return 0;
  1749. }
  1750. static int
  1751. bnx2_release_nvram_lock(struct bnx2 *bp)
  1752. {
  1753. int j;
  1754. u32 val;
  1755. /* Relinquish nvram interface. */
  1756. REG_WR(bp, BNX2_NVM_SW_ARB, BNX2_NVM_SW_ARB_ARB_REQ_CLR2);
  1757. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  1758. val = REG_RD(bp, BNX2_NVM_SW_ARB);
  1759. if (!(val & BNX2_NVM_SW_ARB_ARB_ARB2))
  1760. break;
  1761. udelay(5);
  1762. }
  1763. if (j >= NVRAM_TIMEOUT_COUNT)
  1764. return -EBUSY;
  1765. return 0;
  1766. }
  1767. static int
  1768. bnx2_enable_nvram_write(struct bnx2 *bp)
  1769. {
  1770. u32 val;
  1771. val = REG_RD(bp, BNX2_MISC_CFG);
  1772. REG_WR(bp, BNX2_MISC_CFG, val | BNX2_MISC_CFG_NVM_WR_EN_PCI);
  1773. if (!bp->flash_info->buffered) {
  1774. int j;
  1775. REG_WR(bp, BNX2_NVM_COMMAND, BNX2_NVM_COMMAND_DONE);
  1776. REG_WR(bp, BNX2_NVM_COMMAND,
  1777. BNX2_NVM_COMMAND_WREN | BNX2_NVM_COMMAND_DOIT);
  1778. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  1779. udelay(5);
  1780. val = REG_RD(bp, BNX2_NVM_COMMAND);
  1781. if (val & BNX2_NVM_COMMAND_DONE)
  1782. break;
  1783. }
  1784. if (j >= NVRAM_TIMEOUT_COUNT)
  1785. return -EBUSY;
  1786. }
  1787. return 0;
  1788. }
  1789. static void
  1790. bnx2_disable_nvram_write(struct bnx2 *bp)
  1791. {
  1792. u32 val;
  1793. val = REG_RD(bp, BNX2_MISC_CFG);
  1794. REG_WR(bp, BNX2_MISC_CFG, val & ~BNX2_MISC_CFG_NVM_WR_EN);
  1795. }
  1796. static void
  1797. bnx2_enable_nvram_access(struct bnx2 *bp)
  1798. {
  1799. u32 val;
  1800. val = REG_RD(bp, BNX2_NVM_ACCESS_ENABLE);
  1801. /* Enable both bits, even on read. */
  1802. REG_WR(bp, BNX2_NVM_ACCESS_ENABLE,
  1803. val | BNX2_NVM_ACCESS_ENABLE_EN | BNX2_NVM_ACCESS_ENABLE_WR_EN);
  1804. }
  1805. static void
  1806. bnx2_disable_nvram_access(struct bnx2 *bp)
  1807. {
  1808. u32 val;
  1809. val = REG_RD(bp, BNX2_NVM_ACCESS_ENABLE);
  1810. /* Disable both bits, even after read. */
  1811. REG_WR(bp, BNX2_NVM_ACCESS_ENABLE,
  1812. val & ~(BNX2_NVM_ACCESS_ENABLE_EN |
  1813. BNX2_NVM_ACCESS_ENABLE_WR_EN));
  1814. }
  1815. static int
  1816. bnx2_nvram_erase_page(struct bnx2 *bp, u32 offset)
  1817. {
  1818. u32 cmd;
  1819. int j;
  1820. if (bp->flash_info->buffered)
  1821. /* Buffered flash, no erase needed */
  1822. return 0;
  1823. /* Build an erase command */
  1824. cmd = BNX2_NVM_COMMAND_ERASE | BNX2_NVM_COMMAND_WR |
  1825. BNX2_NVM_COMMAND_DOIT;
  1826. /* Need to clear DONE bit separately. */
  1827. REG_WR(bp, BNX2_NVM_COMMAND, BNX2_NVM_COMMAND_DONE);
  1828. /* Address of the NVRAM to read from. */
  1829. REG_WR(bp, BNX2_NVM_ADDR, offset & BNX2_NVM_ADDR_NVM_ADDR_VALUE);
  1830. /* Issue an erase command. */
  1831. REG_WR(bp, BNX2_NVM_COMMAND, cmd);
  1832. /* Wait for completion. */
  1833. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  1834. u32 val;
  1835. udelay(5);
  1836. val = REG_RD(bp, BNX2_NVM_COMMAND);
  1837. if (val & BNX2_NVM_COMMAND_DONE)
  1838. break;
  1839. }
  1840. if (j >= NVRAM_TIMEOUT_COUNT)
  1841. return -EBUSY;
  1842. return 0;
  1843. }
  1844. static int
  1845. bnx2_nvram_read_dword(struct bnx2 *bp, u32 offset, u8 *ret_val, u32 cmd_flags)
  1846. {
  1847. u32 cmd;
  1848. int j;
  1849. /* Build the command word. */
  1850. cmd = BNX2_NVM_COMMAND_DOIT | cmd_flags;
  1851. /* Calculate an offset of a buffered flash. */
  1852. if (bp->flash_info->buffered) {
  1853. offset = ((offset / bp->flash_info->page_size) <<
  1854. bp->flash_info->page_bits) +
  1855. (offset % bp->flash_info->page_size);
  1856. }
  1857. /* Need to clear DONE bit separately. */
  1858. REG_WR(bp, BNX2_NVM_COMMAND, BNX2_NVM_COMMAND_DONE);
  1859. /* Address of the NVRAM to read from. */
  1860. REG_WR(bp, BNX2_NVM_ADDR, offset & BNX2_NVM_ADDR_NVM_ADDR_VALUE);
  1861. /* Issue a read command. */
  1862. REG_WR(bp, BNX2_NVM_COMMAND, cmd);
  1863. /* Wait for completion. */
  1864. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  1865. u32 val;
  1866. udelay(5);
  1867. val = REG_RD(bp, BNX2_NVM_COMMAND);
  1868. if (val & BNX2_NVM_COMMAND_DONE) {
  1869. val = REG_RD(bp, BNX2_NVM_READ);
  1870. val = be32_to_cpu(val);
  1871. memcpy(ret_val, &val, 4);
  1872. break;
  1873. }
  1874. }
  1875. if (j >= NVRAM_TIMEOUT_COUNT)
  1876. return -EBUSY;
  1877. return 0;
  1878. }
  1879. static int
  1880. bnx2_nvram_write_dword(struct bnx2 *bp, u32 offset, u8 *val, u32 cmd_flags)
  1881. {
  1882. u32 cmd, val32;
  1883. int j;
  1884. /* Build the command word. */
  1885. cmd = BNX2_NVM_COMMAND_DOIT | BNX2_NVM_COMMAND_WR | cmd_flags;
  1886. /* Calculate an offset of a buffered flash. */
  1887. if (bp->flash_info->buffered) {
  1888. offset = ((offset / bp->flash_info->page_size) <<
  1889. bp->flash_info->page_bits) +
  1890. (offset % bp->flash_info->page_size);
  1891. }
  1892. /* Need to clear DONE bit separately. */
  1893. REG_WR(bp, BNX2_NVM_COMMAND, BNX2_NVM_COMMAND_DONE);
  1894. memcpy(&val32, val, 4);
  1895. val32 = cpu_to_be32(val32);
  1896. /* Write the data. */
  1897. REG_WR(bp, BNX2_NVM_WRITE, val32);
  1898. /* Address of the NVRAM to write to. */
  1899. REG_WR(bp, BNX2_NVM_ADDR, offset & BNX2_NVM_ADDR_NVM_ADDR_VALUE);
  1900. /* Issue the write command. */
  1901. REG_WR(bp, BNX2_NVM_COMMAND, cmd);
  1902. /* Wait for completion. */
  1903. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  1904. udelay(5);
  1905. if (REG_RD(bp, BNX2_NVM_COMMAND) & BNX2_NVM_COMMAND_DONE)
  1906. break;
  1907. }
  1908. if (j >= NVRAM_TIMEOUT_COUNT)
  1909. return -EBUSY;
  1910. return 0;
  1911. }
  1912. static int
  1913. bnx2_init_nvram(struct bnx2 *bp)
  1914. {
  1915. u32 val;
  1916. int j, entry_count, rc;
  1917. struct flash_spec *flash;
  1918. /* Determine the selected interface. */
  1919. val = REG_RD(bp, BNX2_NVM_CFG1);
  1920. entry_count = sizeof(flash_table) / sizeof(struct flash_spec);
  1921. rc = 0;
  1922. if (val & 0x40000000) {
  1923. /* Flash interface has been reconfigured */
  1924. for (j = 0, flash = &flash_table[0]; j < entry_count;
  1925. j++, flash++) {
  1926. if (val == flash->config1) {
  1927. bp->flash_info = flash;
  1928. break;
  1929. }
  1930. }
  1931. }
  1932. else {
  1933. /* Not yet been reconfigured */
  1934. for (j = 0, flash = &flash_table[0]; j < entry_count;
  1935. j++, flash++) {
  1936. if ((val & FLASH_STRAP_MASK) == flash->strapping) {
  1937. bp->flash_info = flash;
  1938. /* Request access to the flash interface. */
  1939. if ((rc = bnx2_acquire_nvram_lock(bp)) != 0)
  1940. return rc;
  1941. /* Enable access to flash interface */
  1942. bnx2_enable_nvram_access(bp);
  1943. /* Reconfigure the flash interface */
  1944. REG_WR(bp, BNX2_NVM_CFG1, flash->config1);
  1945. REG_WR(bp, BNX2_NVM_CFG2, flash->config2);
  1946. REG_WR(bp, BNX2_NVM_CFG3, flash->config3);
  1947. REG_WR(bp, BNX2_NVM_WRITE1, flash->write1);
  1948. /* Disable access to flash interface */
  1949. bnx2_disable_nvram_access(bp);
  1950. bnx2_release_nvram_lock(bp);
  1951. break;
  1952. }
  1953. }
  1954. } /* if (val & 0x40000000) */
  1955. if (j == entry_count) {
  1956. bp->flash_info = NULL;
  1957. printk(KERN_ALERT "Unknown flash/EEPROM type.\n");
  1958. rc = -ENODEV;
  1959. }
  1960. return rc;
  1961. }
  1962. static int
  1963. bnx2_nvram_read(struct bnx2 *bp, u32 offset, u8 *ret_buf,
  1964. int buf_size)
  1965. {
  1966. int rc = 0;
  1967. u32 cmd_flags, offset32, len32, extra;
  1968. if (buf_size == 0)
  1969. return 0;
  1970. /* Request access to the flash interface. */
  1971. if ((rc = bnx2_acquire_nvram_lock(bp)) != 0)
  1972. return rc;
  1973. /* Enable access to flash interface */
  1974. bnx2_enable_nvram_access(bp);
  1975. len32 = buf_size;
  1976. offset32 = offset;
  1977. extra = 0;
  1978. cmd_flags = 0;
  1979. if (offset32 & 3) {
  1980. u8 buf[4];
  1981. u32 pre_len;
  1982. offset32 &= ~3;
  1983. pre_len = 4 - (offset & 3);
  1984. if (pre_len >= len32) {
  1985. pre_len = len32;
  1986. cmd_flags = BNX2_NVM_COMMAND_FIRST |
  1987. BNX2_NVM_COMMAND_LAST;
  1988. }
  1989. else {
  1990. cmd_flags = BNX2_NVM_COMMAND_FIRST;
  1991. }
  1992. rc = bnx2_nvram_read_dword(bp, offset32, buf, cmd_flags);
  1993. if (rc)
  1994. return rc;
  1995. memcpy(ret_buf, buf + (offset & 3), pre_len);
  1996. offset32 += 4;
  1997. ret_buf += pre_len;
  1998. len32 -= pre_len;
  1999. }
  2000. if (len32 & 3) {
  2001. extra = 4 - (len32 & 3);
  2002. len32 = (len32 + 4) & ~3;
  2003. }
  2004. if (len32 == 4) {
  2005. u8 buf[4];
  2006. if (cmd_flags)
  2007. cmd_flags = BNX2_NVM_COMMAND_LAST;
  2008. else
  2009. cmd_flags = BNX2_NVM_COMMAND_FIRST |
  2010. BNX2_NVM_COMMAND_LAST;
  2011. rc = bnx2_nvram_read_dword(bp, offset32, buf, cmd_flags);
  2012. memcpy(ret_buf, buf, 4 - extra);
  2013. }
  2014. else if (len32 > 0) {
  2015. u8 buf[4];
  2016. /* Read the first word. */
  2017. if (cmd_flags)
  2018. cmd_flags = 0;
  2019. else
  2020. cmd_flags = BNX2_NVM_COMMAND_FIRST;
  2021. rc = bnx2_nvram_read_dword(bp, offset32, ret_buf, cmd_flags);
  2022. /* Advance to the next dword. */
  2023. offset32 += 4;
  2024. ret_buf += 4;
  2025. len32 -= 4;
  2026. while (len32 > 4 && rc == 0) {
  2027. rc = bnx2_nvram_read_dword(bp, offset32, ret_buf, 0);
  2028. /* Advance to the next dword. */
  2029. offset32 += 4;
  2030. ret_buf += 4;
  2031. len32 -= 4;
  2032. }
  2033. if (rc)
  2034. return rc;
  2035. cmd_flags = BNX2_NVM_COMMAND_LAST;
  2036. rc = bnx2_nvram_read_dword(bp, offset32, buf, cmd_flags);
  2037. memcpy(ret_buf, buf, 4 - extra);
  2038. }
  2039. /* Disable access to flash interface */
  2040. bnx2_disable_nvram_access(bp);
  2041. bnx2_release_nvram_lock(bp);
  2042. return rc;
  2043. }
  2044. static int
  2045. bnx2_nvram_write(struct bnx2 *bp, u32 offset, u8 *data_buf,
  2046. int buf_size)
  2047. {
  2048. u32 written, offset32, len32;
  2049. u8 *buf, start[4], end[4];
  2050. int rc = 0;
  2051. int align_start, align_end;
  2052. buf = data_buf;
  2053. offset32 = offset;
  2054. len32 = buf_size;
  2055. align_start = align_end = 0;
  2056. if ((align_start = (offset32 & 3))) {
  2057. offset32 &= ~3;
  2058. len32 += align_start;
  2059. if ((rc = bnx2_nvram_read(bp, offset32, start, 4)))
  2060. return rc;
  2061. }
  2062. if (len32 & 3) {
  2063. if ((len32 > 4) || !align_start) {
  2064. align_end = 4 - (len32 & 3);
  2065. len32 += align_end;
  2066. if ((rc = bnx2_nvram_read(bp, offset32 + len32 - 4,
  2067. end, 4))) {
  2068. return rc;
  2069. }
  2070. }
  2071. }
  2072. if (align_start || align_end) {
  2073. buf = kmalloc(len32, GFP_KERNEL);
  2074. if (buf == 0)
  2075. return -ENOMEM;
  2076. if (align_start) {
  2077. memcpy(buf, start, 4);
  2078. }
  2079. if (align_end) {
  2080. memcpy(buf + len32 - 4, end, 4);
  2081. }
  2082. memcpy(buf + align_start, data_buf, buf_size);
  2083. }
  2084. written = 0;
  2085. while ((written < len32) && (rc == 0)) {
  2086. u32 page_start, page_end, data_start, data_end;
  2087. u32 addr, cmd_flags;
  2088. int i;
  2089. u8 flash_buffer[264];
  2090. /* Find the page_start addr */
  2091. page_start = offset32 + written;
  2092. page_start -= (page_start % bp->flash_info->page_size);
  2093. /* Find the page_end addr */
  2094. page_end = page_start + bp->flash_info->page_size;
  2095. /* Find the data_start addr */
  2096. data_start = (written == 0) ? offset32 : page_start;
  2097. /* Find the data_end addr */
  2098. data_end = (page_end > offset32 + len32) ?
  2099. (offset32 + len32) : page_end;
  2100. /* Request access to the flash interface. */
  2101. if ((rc = bnx2_acquire_nvram_lock(bp)) != 0)
  2102. goto nvram_write_end;
  2103. /* Enable access to flash interface */
  2104. bnx2_enable_nvram_access(bp);
  2105. cmd_flags = BNX2_NVM_COMMAND_FIRST;
  2106. if (bp->flash_info->buffered == 0) {
  2107. int j;
  2108. /* Read the whole page into the buffer
  2109. * (non-buffer flash only) */
  2110. for (j = 0; j < bp->flash_info->page_size; j += 4) {
  2111. if (j == (bp->flash_info->page_size - 4)) {
  2112. cmd_flags |= BNX2_NVM_COMMAND_LAST;
  2113. }
  2114. rc = bnx2_nvram_read_dword(bp,
  2115. page_start + j,
  2116. &flash_buffer[j],
  2117. cmd_flags);
  2118. if (rc)
  2119. goto nvram_write_end;
  2120. cmd_flags = 0;
  2121. }
  2122. }
  2123. /* Enable writes to flash interface (unlock write-protect) */
  2124. if ((rc = bnx2_enable_nvram_write(bp)) != 0)
  2125. goto nvram_write_end;
  2126. /* Erase the page */
  2127. if ((rc = bnx2_nvram_erase_page(bp, page_start)) != 0)
  2128. goto nvram_write_end;
  2129. /* Re-enable the write again for the actual write */
  2130. bnx2_enable_nvram_write(bp);
  2131. /* Loop to write back the buffer data from page_start to
  2132. * data_start */
  2133. i = 0;
  2134. if (bp->flash_info->buffered == 0) {
  2135. for (addr = page_start; addr < data_start;
  2136. addr += 4, i += 4) {
  2137. rc = bnx2_nvram_write_dword(bp, addr,
  2138. &flash_buffer[i], cmd_flags);
  2139. if (rc != 0)
  2140. goto nvram_write_end;
  2141. cmd_flags = 0;
  2142. }
  2143. }
  2144. /* Loop to write the new data from data_start to data_end */
  2145. for (addr = data_start; addr < data_end; addr += 4, i++) {
  2146. if ((addr == page_end - 4) ||
  2147. ((bp->flash_info->buffered) &&
  2148. (addr == data_end - 4))) {
  2149. cmd_flags |= BNX2_NVM_COMMAND_LAST;
  2150. }
  2151. rc = bnx2_nvram_write_dword(bp, addr, buf,
  2152. cmd_flags);
  2153. if (rc != 0)
  2154. goto nvram_write_end;
  2155. cmd_flags = 0;
  2156. buf += 4;
  2157. }
  2158. /* Loop to write back the buffer data from data_end
  2159. * to page_end */
  2160. if (bp->flash_info->buffered == 0) {
  2161. for (addr = data_end; addr < page_end;
  2162. addr += 4, i += 4) {
  2163. if (addr == page_end-4) {
  2164. cmd_flags = BNX2_NVM_COMMAND_LAST;
  2165. }
  2166. rc = bnx2_nvram_write_dword(bp, addr,
  2167. &flash_buffer[i], cmd_flags);
  2168. if (rc != 0)
  2169. goto nvram_write_end;
  2170. cmd_flags = 0;
  2171. }
  2172. }
  2173. /* Disable writes to flash interface (lock write-protect) */
  2174. bnx2_disable_nvram_write(bp);
  2175. /* Disable access to flash interface */
  2176. bnx2_disable_nvram_access(bp);
  2177. bnx2_release_nvram_lock(bp);
  2178. /* Increment written */
  2179. written += data_end - data_start;
  2180. }
  2181. nvram_write_end:
  2182. if (align_start || align_end)
  2183. kfree(buf);
  2184. return rc;
  2185. }
  2186. static int
  2187. bnx2_reset_chip(struct bnx2 *bp, u32 reset_code)
  2188. {
  2189. u32 val;
  2190. int i, rc = 0;
  2191. /* Wait for the current PCI transaction to complete before
  2192. * issuing a reset. */
  2193. REG_WR(bp, BNX2_MISC_ENABLE_CLR_BITS,
  2194. BNX2_MISC_ENABLE_CLR_BITS_TX_DMA_ENABLE |
  2195. BNX2_MISC_ENABLE_CLR_BITS_DMA_ENGINE_ENABLE |
  2196. BNX2_MISC_ENABLE_CLR_BITS_RX_DMA_ENABLE |
  2197. BNX2_MISC_ENABLE_CLR_BITS_HOST_COALESCE_ENABLE);
  2198. val = REG_RD(bp, BNX2_MISC_ENABLE_CLR_BITS);
  2199. udelay(5);
  2200. /* Deposit a driver reset signature so the firmware knows that
  2201. * this is a soft reset. */
  2202. REG_WR_IND(bp, HOST_VIEW_SHMEM_BASE + BNX2_DRV_RESET_SIGNATURE,
  2203. BNX2_DRV_RESET_SIGNATURE_MAGIC);
  2204. bp->fw_timed_out = 0;
  2205. /* Wait for the firmware to tell us it is ok to issue a reset. */
  2206. bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT0 | reset_code);
  2207. /* Do a dummy read to force the chip to complete all current transaction
  2208. * before we issue a reset. */
  2209. val = REG_RD(bp, BNX2_MISC_ID);
  2210. val = BNX2_PCICFG_MISC_CONFIG_CORE_RST_REQ |
  2211. BNX2_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
  2212. BNX2_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP;
  2213. /* Chip reset. */
  2214. REG_WR(bp, BNX2_PCICFG_MISC_CONFIG, val);
  2215. if ((CHIP_ID(bp) == CHIP_ID_5706_A0) ||
  2216. (CHIP_ID(bp) == CHIP_ID_5706_A1))
  2217. msleep(15);
  2218. /* Reset takes approximate 30 usec */
  2219. for (i = 0; i < 10; i++) {
  2220. val = REG_RD(bp, BNX2_PCICFG_MISC_CONFIG);
  2221. if ((val & (BNX2_PCICFG_MISC_CONFIG_CORE_RST_REQ |
  2222. BNX2_PCICFG_MISC_CONFIG_CORE_RST_BSY)) == 0) {
  2223. break;
  2224. }
  2225. udelay(10);
  2226. }
  2227. if (val & (BNX2_PCICFG_MISC_CONFIG_CORE_RST_REQ |
  2228. BNX2_PCICFG_MISC_CONFIG_CORE_RST_BSY)) {
  2229. printk(KERN_ERR PFX "Chip reset did not complete\n");
  2230. return -EBUSY;
  2231. }
  2232. /* Make sure byte swapping is properly configured. */
  2233. val = REG_RD(bp, BNX2_PCI_SWAP_DIAG0);
  2234. if (val != 0x01020304) {
  2235. printk(KERN_ERR PFX "Chip not in correct endian mode\n");
  2236. return -ENODEV;
  2237. }
  2238. bp->fw_timed_out = 0;
  2239. /* Wait for the firmware to finish its initialization. */
  2240. bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT1 | reset_code);
  2241. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  2242. /* Adjust the voltage regular to two steps lower. The default
  2243. * of this register is 0x0000000e. */
  2244. REG_WR(bp, BNX2_MISC_VREG_CONTROL, 0x000000fa);
  2245. /* Remove bad rbuf memory from the free pool. */
  2246. rc = bnx2_alloc_bad_rbuf(bp);
  2247. }
  2248. return rc;
  2249. }
  2250. static int
  2251. bnx2_init_chip(struct bnx2 *bp)
  2252. {
  2253. u32 val;
  2254. /* Make sure the interrupt is not active. */
  2255. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD, BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
  2256. val = BNX2_DMA_CONFIG_DATA_BYTE_SWAP |
  2257. BNX2_DMA_CONFIG_DATA_WORD_SWAP |
  2258. #ifdef __BIG_ENDIAN
  2259. BNX2_DMA_CONFIG_CNTL_BYTE_SWAP |
  2260. #endif
  2261. BNX2_DMA_CONFIG_CNTL_WORD_SWAP |
  2262. DMA_READ_CHANS << 12 |
  2263. DMA_WRITE_CHANS << 16;
  2264. val |= (0x2 << 20) | (1 << 11);
  2265. if ((bp->flags & PCIX_FLAG) && (bp->bus_speed_mhz = 133))
  2266. val |= (1 << 23);
  2267. if ((CHIP_NUM(bp) == CHIP_NUM_5706) &&
  2268. (CHIP_ID(bp) != CHIP_ID_5706_A0) && !(bp->flags & PCIX_FLAG))
  2269. val |= BNX2_DMA_CONFIG_CNTL_PING_PONG_DMA;
  2270. REG_WR(bp, BNX2_DMA_CONFIG, val);
  2271. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  2272. val = REG_RD(bp, BNX2_TDMA_CONFIG);
  2273. val |= BNX2_TDMA_CONFIG_ONE_DMA;
  2274. REG_WR(bp, BNX2_TDMA_CONFIG, val);
  2275. }
  2276. if (bp->flags & PCIX_FLAG) {
  2277. u16 val16;
  2278. pci_read_config_word(bp->pdev, bp->pcix_cap + PCI_X_CMD,
  2279. &val16);
  2280. pci_write_config_word(bp->pdev, bp->pcix_cap + PCI_X_CMD,
  2281. val16 & ~PCI_X_CMD_ERO);
  2282. }
  2283. REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS,
  2284. BNX2_MISC_ENABLE_SET_BITS_HOST_COALESCE_ENABLE |
  2285. BNX2_MISC_ENABLE_STATUS_BITS_RX_V2P_ENABLE |
  2286. BNX2_MISC_ENABLE_STATUS_BITS_CONTEXT_ENABLE);
  2287. /* Initialize context mapping and zero out the quick contexts. The
  2288. * context block must have already been enabled. */
  2289. bnx2_init_context(bp);
  2290. bnx2_init_cpus(bp);
  2291. bnx2_init_nvram(bp);
  2292. bnx2_set_mac_addr(bp);
  2293. val = REG_RD(bp, BNX2_MQ_CONFIG);
  2294. val &= ~BNX2_MQ_CONFIG_KNL_BYP_BLK_SIZE;
  2295. val |= BNX2_MQ_CONFIG_KNL_BYP_BLK_SIZE_256;
  2296. REG_WR(bp, BNX2_MQ_CONFIG, val);
  2297. val = 0x10000 + (MAX_CID_CNT * MB_KERNEL_CTX_SIZE);
  2298. REG_WR(bp, BNX2_MQ_KNL_BYP_WIND_START, val);
  2299. REG_WR(bp, BNX2_MQ_KNL_WIND_END, val);
  2300. val = (BCM_PAGE_BITS - 8) << 24;
  2301. REG_WR(bp, BNX2_RV2P_CONFIG, val);
  2302. /* Configure page size. */
  2303. val = REG_RD(bp, BNX2_TBDR_CONFIG);
  2304. val &= ~BNX2_TBDR_CONFIG_PAGE_SIZE;
  2305. val |= (BCM_PAGE_BITS - 8) << 24 | 0x40;
  2306. REG_WR(bp, BNX2_TBDR_CONFIG, val);
  2307. val = bp->mac_addr[0] +
  2308. (bp->mac_addr[1] << 8) +
  2309. (bp->mac_addr[2] << 16) +
  2310. bp->mac_addr[3] +
  2311. (bp->mac_addr[4] << 8) +
  2312. (bp->mac_addr[5] << 16);
  2313. REG_WR(bp, BNX2_EMAC_BACKOFF_SEED, val);
  2314. /* Program the MTU. Also include 4 bytes for CRC32. */
  2315. val = bp->dev->mtu + ETH_HLEN + 4;
  2316. if (val > (MAX_ETHERNET_PACKET_SIZE + 4))
  2317. val |= BNX2_EMAC_RX_MTU_SIZE_JUMBO_ENA;
  2318. REG_WR(bp, BNX2_EMAC_RX_MTU_SIZE, val);
  2319. bp->last_status_idx = 0;
  2320. bp->rx_mode = BNX2_EMAC_RX_MODE_SORT_MODE;
  2321. /* Set up how to generate a link change interrupt. */
  2322. REG_WR(bp, BNX2_EMAC_ATTENTION_ENA, BNX2_EMAC_ATTENTION_ENA_LINK);
  2323. REG_WR(bp, BNX2_HC_STATUS_ADDR_L,
  2324. (u64) bp->status_blk_mapping & 0xffffffff);
  2325. REG_WR(bp, BNX2_HC_STATUS_ADDR_H, (u64) bp->status_blk_mapping >> 32);
  2326. REG_WR(bp, BNX2_HC_STATISTICS_ADDR_L,
  2327. (u64) bp->stats_blk_mapping & 0xffffffff);
  2328. REG_WR(bp, BNX2_HC_STATISTICS_ADDR_H,
  2329. (u64) bp->stats_blk_mapping >> 32);
  2330. REG_WR(bp, BNX2_HC_TX_QUICK_CONS_TRIP,
  2331. (bp->tx_quick_cons_trip_int << 16) | bp->tx_quick_cons_trip);
  2332. REG_WR(bp, BNX2_HC_RX_QUICK_CONS_TRIP,
  2333. (bp->rx_quick_cons_trip_int << 16) | bp->rx_quick_cons_trip);
  2334. REG_WR(bp, BNX2_HC_COMP_PROD_TRIP,
  2335. (bp->comp_prod_trip_int << 16) | bp->comp_prod_trip);
  2336. REG_WR(bp, BNX2_HC_TX_TICKS, (bp->tx_ticks_int << 16) | bp->tx_ticks);
  2337. REG_WR(bp, BNX2_HC_RX_TICKS, (bp->rx_ticks_int << 16) | bp->rx_ticks);
  2338. REG_WR(bp, BNX2_HC_COM_TICKS,
  2339. (bp->com_ticks_int << 16) | bp->com_ticks);
  2340. REG_WR(bp, BNX2_HC_CMD_TICKS,
  2341. (bp->cmd_ticks_int << 16) | bp->cmd_ticks);
  2342. REG_WR(bp, BNX2_HC_STATS_TICKS, bp->stats_ticks & 0xffff00);
  2343. REG_WR(bp, BNX2_HC_STAT_COLLECT_TICKS, 0xbb8); /* 3ms */
  2344. if (CHIP_ID(bp) == CHIP_ID_5706_A1)
  2345. REG_WR(bp, BNX2_HC_CONFIG, BNX2_HC_CONFIG_COLLECT_STATS);
  2346. else {
  2347. REG_WR(bp, BNX2_HC_CONFIG, BNX2_HC_CONFIG_RX_TMR_MODE |
  2348. BNX2_HC_CONFIG_TX_TMR_MODE |
  2349. BNX2_HC_CONFIG_COLLECT_STATS);
  2350. }
  2351. /* Clear internal stats counters. */
  2352. REG_WR(bp, BNX2_HC_COMMAND, BNX2_HC_COMMAND_CLR_STAT_NOW);
  2353. REG_WR(bp, BNX2_HC_ATTN_BITS_ENABLE, STATUS_ATTN_BITS_LINK_STATE);
  2354. /* Initialize the receive filter. */
  2355. bnx2_set_rx_mode(bp->dev);
  2356. bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT2 | BNX2_DRV_MSG_CODE_RESET);
  2357. REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS, 0x5ffffff);
  2358. REG_RD(bp, BNX2_MISC_ENABLE_SET_BITS);
  2359. udelay(20);
  2360. return 0;
  2361. }
  2362. static void
  2363. bnx2_init_tx_ring(struct bnx2 *bp)
  2364. {
  2365. struct tx_bd *txbd;
  2366. u32 val;
  2367. txbd = &bp->tx_desc_ring[MAX_TX_DESC_CNT];
  2368. txbd->tx_bd_haddr_hi = (u64) bp->tx_desc_mapping >> 32;
  2369. txbd->tx_bd_haddr_lo = (u64) bp->tx_desc_mapping & 0xffffffff;
  2370. bp->tx_prod = 0;
  2371. bp->tx_cons = 0;
  2372. bp->tx_prod_bseq = 0;
  2373. val = BNX2_L2CTX_TYPE_TYPE_L2;
  2374. val |= BNX2_L2CTX_TYPE_SIZE_L2;
  2375. CTX_WR(bp, GET_CID_ADDR(TX_CID), BNX2_L2CTX_TYPE, val);
  2376. val = BNX2_L2CTX_CMD_TYPE_TYPE_L2;
  2377. val |= 8 << 16;
  2378. CTX_WR(bp, GET_CID_ADDR(TX_CID), BNX2_L2CTX_CMD_TYPE, val);
  2379. val = (u64) bp->tx_desc_mapping >> 32;
  2380. CTX_WR(bp, GET_CID_ADDR(TX_CID), BNX2_L2CTX_TBDR_BHADDR_HI, val);
  2381. val = (u64) bp->tx_desc_mapping & 0xffffffff;
  2382. CTX_WR(bp, GET_CID_ADDR(TX_CID), BNX2_L2CTX_TBDR_BHADDR_LO, val);
  2383. }
  2384. static void
  2385. bnx2_init_rx_ring(struct bnx2 *bp)
  2386. {
  2387. struct rx_bd *rxbd;
  2388. int i;
  2389. u16 prod, ring_prod;
  2390. u32 val;
  2391. /* 8 for CRC and VLAN */
  2392. bp->rx_buf_use_size = bp->dev->mtu + ETH_HLEN + bp->rx_offset + 8;
  2393. /* 8 for alignment */
  2394. bp->rx_buf_size = bp->rx_buf_use_size + 8;
  2395. ring_prod = prod = bp->rx_prod = 0;
  2396. bp->rx_cons = 0;
  2397. bp->rx_prod_bseq = 0;
  2398. rxbd = &bp->rx_desc_ring[0];
  2399. for (i = 0; i < MAX_RX_DESC_CNT; i++, rxbd++) {
  2400. rxbd->rx_bd_len = bp->rx_buf_use_size;
  2401. rxbd->rx_bd_flags = RX_BD_FLAGS_START | RX_BD_FLAGS_END;
  2402. }
  2403. rxbd->rx_bd_haddr_hi = (u64) bp->rx_desc_mapping >> 32;
  2404. rxbd->rx_bd_haddr_lo = (u64) bp->rx_desc_mapping & 0xffffffff;
  2405. val = BNX2_L2CTX_CTX_TYPE_CTX_BD_CHN_TYPE_VALUE;
  2406. val |= BNX2_L2CTX_CTX_TYPE_SIZE_L2;
  2407. val |= 0x02 << 8;
  2408. CTX_WR(bp, GET_CID_ADDR(RX_CID), BNX2_L2CTX_CTX_TYPE, val);
  2409. val = (u64) bp->rx_desc_mapping >> 32;
  2410. CTX_WR(bp, GET_CID_ADDR(RX_CID), BNX2_L2CTX_NX_BDHADDR_HI, val);
  2411. val = (u64) bp->rx_desc_mapping & 0xffffffff;
  2412. CTX_WR(bp, GET_CID_ADDR(RX_CID), BNX2_L2CTX_NX_BDHADDR_LO, val);
  2413. for ( ;ring_prod < bp->rx_ring_size; ) {
  2414. if (bnx2_alloc_rx_skb(bp, ring_prod) < 0) {
  2415. break;
  2416. }
  2417. prod = NEXT_RX_BD(prod);
  2418. ring_prod = RX_RING_IDX(prod);
  2419. }
  2420. bp->rx_prod = prod;
  2421. REG_WR16(bp, MB_RX_CID_ADDR + BNX2_L2CTX_HOST_BDIDX, prod);
  2422. REG_WR(bp, MB_RX_CID_ADDR + BNX2_L2CTX_HOST_BSEQ, bp->rx_prod_bseq);
  2423. }
  2424. static void
  2425. bnx2_free_tx_skbs(struct bnx2 *bp)
  2426. {
  2427. int i;
  2428. if (bp->tx_buf_ring == NULL)
  2429. return;
  2430. for (i = 0; i < TX_DESC_CNT; ) {
  2431. struct sw_bd *tx_buf = &bp->tx_buf_ring[i];
  2432. struct sk_buff *skb = tx_buf->skb;
  2433. int j, last;
  2434. if (skb == NULL) {
  2435. i++;
  2436. continue;
  2437. }
  2438. pci_unmap_single(bp->pdev, pci_unmap_addr(tx_buf, mapping),
  2439. skb_headlen(skb), PCI_DMA_TODEVICE);
  2440. tx_buf->skb = NULL;
  2441. last = skb_shinfo(skb)->nr_frags;
  2442. for (j = 0; j < last; j++) {
  2443. tx_buf = &bp->tx_buf_ring[i + j + 1];
  2444. pci_unmap_page(bp->pdev,
  2445. pci_unmap_addr(tx_buf, mapping),
  2446. skb_shinfo(skb)->frags[j].size,
  2447. PCI_DMA_TODEVICE);
  2448. }
  2449. dev_kfree_skb_any(skb);
  2450. i += j + 1;
  2451. }
  2452. }
  2453. static void
  2454. bnx2_free_rx_skbs(struct bnx2 *bp)
  2455. {
  2456. int i;
  2457. if (bp->rx_buf_ring == NULL)
  2458. return;
  2459. for (i = 0; i < RX_DESC_CNT; i++) {
  2460. struct sw_bd *rx_buf = &bp->rx_buf_ring[i];
  2461. struct sk_buff *skb = rx_buf->skb;
  2462. if (skb == 0)
  2463. continue;
  2464. pci_unmap_single(bp->pdev, pci_unmap_addr(rx_buf, mapping),
  2465. bp->rx_buf_use_size, PCI_DMA_FROMDEVICE);
  2466. rx_buf->skb = NULL;
  2467. dev_kfree_skb_any(skb);
  2468. }
  2469. }
  2470. static void
  2471. bnx2_free_skbs(struct bnx2 *bp)
  2472. {
  2473. bnx2_free_tx_skbs(bp);
  2474. bnx2_free_rx_skbs(bp);
  2475. }
  2476. static int
  2477. bnx2_reset_nic(struct bnx2 *bp, u32 reset_code)
  2478. {
  2479. int rc;
  2480. rc = bnx2_reset_chip(bp, reset_code);
  2481. bnx2_free_skbs(bp);
  2482. if (rc)
  2483. return rc;
  2484. bnx2_init_chip(bp);
  2485. bnx2_init_tx_ring(bp);
  2486. bnx2_init_rx_ring(bp);
  2487. return 0;
  2488. }
  2489. static int
  2490. bnx2_init_nic(struct bnx2 *bp)
  2491. {
  2492. int rc;
  2493. if ((rc = bnx2_reset_nic(bp, BNX2_DRV_MSG_CODE_RESET)) != 0)
  2494. return rc;
  2495. bnx2_init_phy(bp);
  2496. bnx2_set_link(bp);
  2497. return 0;
  2498. }
  2499. static int
  2500. bnx2_test_registers(struct bnx2 *bp)
  2501. {
  2502. int ret;
  2503. int i;
  2504. static struct {
  2505. u16 offset;
  2506. u16 flags;
  2507. u32 rw_mask;
  2508. u32 ro_mask;
  2509. } reg_tbl[] = {
  2510. { 0x006c, 0, 0x00000000, 0x0000003f },
  2511. { 0x0090, 0, 0xffffffff, 0x00000000 },
  2512. { 0x0094, 0, 0x00000000, 0x00000000 },
  2513. { 0x0404, 0, 0x00003f00, 0x00000000 },
  2514. { 0x0418, 0, 0x00000000, 0xffffffff },
  2515. { 0x041c, 0, 0x00000000, 0xffffffff },
  2516. { 0x0420, 0, 0x00000000, 0x80ffffff },
  2517. { 0x0424, 0, 0x00000000, 0x00000000 },
  2518. { 0x0428, 0, 0x00000000, 0x00000001 },
  2519. { 0x0450, 0, 0x00000000, 0x0000ffff },
  2520. { 0x0454, 0, 0x00000000, 0xffffffff },
  2521. { 0x0458, 0, 0x00000000, 0xffffffff },
  2522. { 0x0808, 0, 0x00000000, 0xffffffff },
  2523. { 0x0854, 0, 0x00000000, 0xffffffff },
  2524. { 0x0868, 0, 0x00000000, 0x77777777 },
  2525. { 0x086c, 0, 0x00000000, 0x77777777 },
  2526. { 0x0870, 0, 0x00000000, 0x77777777 },
  2527. { 0x0874, 0, 0x00000000, 0x77777777 },
  2528. { 0x0c00, 0, 0x00000000, 0x00000001 },
  2529. { 0x0c04, 0, 0x00000000, 0x03ff0001 },
  2530. { 0x0c08, 0, 0x0f0ff073, 0x00000000 },
  2531. { 0x0c0c, 0, 0x00ffffff, 0x00000000 },
  2532. { 0x0c30, 0, 0x00000000, 0xffffffff },
  2533. { 0x0c34, 0, 0x00000000, 0xffffffff },
  2534. { 0x0c38, 0, 0x00000000, 0xffffffff },
  2535. { 0x0c3c, 0, 0x00000000, 0xffffffff },
  2536. { 0x0c40, 0, 0x00000000, 0xffffffff },
  2537. { 0x0c44, 0, 0x00000000, 0xffffffff },
  2538. { 0x0c48, 0, 0x00000000, 0x0007ffff },
  2539. { 0x0c4c, 0, 0x00000000, 0xffffffff },
  2540. { 0x0c50, 0, 0x00000000, 0xffffffff },
  2541. { 0x0c54, 0, 0x00000000, 0xffffffff },
  2542. { 0x0c58, 0, 0x00000000, 0xffffffff },
  2543. { 0x0c5c, 0, 0x00000000, 0xffffffff },
  2544. { 0x0c60, 0, 0x00000000, 0xffffffff },
  2545. { 0x0c64, 0, 0x00000000, 0xffffffff },
  2546. { 0x0c68, 0, 0x00000000, 0xffffffff },
  2547. { 0x0c6c, 0, 0x00000000, 0xffffffff },
  2548. { 0x0c70, 0, 0x00000000, 0xffffffff },
  2549. { 0x0c74, 0, 0x00000000, 0xffffffff },
  2550. { 0x0c78, 0, 0x00000000, 0xffffffff },
  2551. { 0x0c7c, 0, 0x00000000, 0xffffffff },
  2552. { 0x0c80, 0, 0x00000000, 0xffffffff },
  2553. { 0x0c84, 0, 0x00000000, 0xffffffff },
  2554. { 0x0c88, 0, 0x00000000, 0xffffffff },
  2555. { 0x0c8c, 0, 0x00000000, 0xffffffff },
  2556. { 0x0c90, 0, 0x00000000, 0xffffffff },
  2557. { 0x0c94, 0, 0x00000000, 0xffffffff },
  2558. { 0x0c98, 0, 0x00000000, 0xffffffff },
  2559. { 0x0c9c, 0, 0x00000000, 0xffffffff },
  2560. { 0x0ca0, 0, 0x00000000, 0xffffffff },
  2561. { 0x0ca4, 0, 0x00000000, 0xffffffff },
  2562. { 0x0ca8, 0, 0x00000000, 0x0007ffff },
  2563. { 0x0cac, 0, 0x00000000, 0xffffffff },
  2564. { 0x0cb0, 0, 0x00000000, 0xffffffff },
  2565. { 0x0cb4, 0, 0x00000000, 0xffffffff },
  2566. { 0x0cb8, 0, 0x00000000, 0xffffffff },
  2567. { 0x0cbc, 0, 0x00000000, 0xffffffff },
  2568. { 0x0cc0, 0, 0x00000000, 0xffffffff },
  2569. { 0x0cc4, 0, 0x00000000, 0xffffffff },
  2570. { 0x0cc8, 0, 0x00000000, 0xffffffff },
  2571. { 0x0ccc, 0, 0x00000000, 0xffffffff },
  2572. { 0x0cd0, 0, 0x00000000, 0xffffffff },
  2573. { 0x0cd4, 0, 0x00000000, 0xffffffff },
  2574. { 0x0cd8, 0, 0x00000000, 0xffffffff },
  2575. { 0x0cdc, 0, 0x00000000, 0xffffffff },
  2576. { 0x0ce0, 0, 0x00000000, 0xffffffff },
  2577. { 0x0ce4, 0, 0x00000000, 0xffffffff },
  2578. { 0x0ce8, 0, 0x00000000, 0xffffffff },
  2579. { 0x0cec, 0, 0x00000000, 0xffffffff },
  2580. { 0x0cf0, 0, 0x00000000, 0xffffffff },
  2581. { 0x0cf4, 0, 0x00000000, 0xffffffff },
  2582. { 0x0cf8, 0, 0x00000000, 0xffffffff },
  2583. { 0x0cfc, 0, 0x00000000, 0xffffffff },
  2584. { 0x0d00, 0, 0x00000000, 0xffffffff },
  2585. { 0x0d04, 0, 0x00000000, 0xffffffff },
  2586. { 0x1000, 0, 0x00000000, 0x00000001 },
  2587. { 0x1004, 0, 0x00000000, 0x000f0001 },
  2588. { 0x1044, 0, 0x00000000, 0xffc003ff },
  2589. { 0x1080, 0, 0x00000000, 0x0001ffff },
  2590. { 0x1084, 0, 0x00000000, 0xffffffff },
  2591. { 0x1088, 0, 0x00000000, 0xffffffff },
  2592. { 0x108c, 0, 0x00000000, 0xffffffff },
  2593. { 0x1090, 0, 0x00000000, 0xffffffff },
  2594. { 0x1094, 0, 0x00000000, 0xffffffff },
  2595. { 0x1098, 0, 0x00000000, 0xffffffff },
  2596. { 0x109c, 0, 0x00000000, 0xffffffff },
  2597. { 0x10a0, 0, 0x00000000, 0xffffffff },
  2598. { 0x1408, 0, 0x01c00800, 0x00000000 },
  2599. { 0x149c, 0, 0x8000ffff, 0x00000000 },
  2600. { 0x14a8, 0, 0x00000000, 0x000001ff },
  2601. { 0x14ac, 0, 0x4fffffff, 0x10000000 },
  2602. { 0x14b0, 0, 0x00000002, 0x00000001 },
  2603. { 0x14b8, 0, 0x00000000, 0x00000000 },
  2604. { 0x14c0, 0, 0x00000000, 0x00000009 },
  2605. { 0x14c4, 0, 0x00003fff, 0x00000000 },
  2606. { 0x14cc, 0, 0x00000000, 0x00000001 },
  2607. { 0x14d0, 0, 0xffffffff, 0x00000000 },
  2608. { 0x1500, 0, 0x00000000, 0xffffffff },
  2609. { 0x1504, 0, 0x00000000, 0xffffffff },
  2610. { 0x1508, 0, 0x00000000, 0xffffffff },
  2611. { 0x150c, 0, 0x00000000, 0xffffffff },
  2612. { 0x1510, 0, 0x00000000, 0xffffffff },
  2613. { 0x1514, 0, 0x00000000, 0xffffffff },
  2614. { 0x1518, 0, 0x00000000, 0xffffffff },
  2615. { 0x151c, 0, 0x00000000, 0xffffffff },
  2616. { 0x1520, 0, 0x00000000, 0xffffffff },
  2617. { 0x1524, 0, 0x00000000, 0xffffffff },
  2618. { 0x1528, 0, 0x00000000, 0xffffffff },
  2619. { 0x152c, 0, 0x00000000, 0xffffffff },
  2620. { 0x1530, 0, 0x00000000, 0xffffffff },
  2621. { 0x1534, 0, 0x00000000, 0xffffffff },
  2622. { 0x1538, 0, 0x00000000, 0xffffffff },
  2623. { 0x153c, 0, 0x00000000, 0xffffffff },
  2624. { 0x1540, 0, 0x00000000, 0xffffffff },
  2625. { 0x1544, 0, 0x00000000, 0xffffffff },
  2626. { 0x1548, 0, 0x00000000, 0xffffffff },
  2627. { 0x154c, 0, 0x00000000, 0xffffffff },
  2628. { 0x1550, 0, 0x00000000, 0xffffffff },
  2629. { 0x1554, 0, 0x00000000, 0xffffffff },
  2630. { 0x1558, 0, 0x00000000, 0xffffffff },
  2631. { 0x1600, 0, 0x00000000, 0xffffffff },
  2632. { 0x1604, 0, 0x00000000, 0xffffffff },
  2633. { 0x1608, 0, 0x00000000, 0xffffffff },
  2634. { 0x160c, 0, 0x00000000, 0xffffffff },
  2635. { 0x1610, 0, 0x00000000, 0xffffffff },
  2636. { 0x1614, 0, 0x00000000, 0xffffffff },
  2637. { 0x1618, 0, 0x00000000, 0xffffffff },
  2638. { 0x161c, 0, 0x00000000, 0xffffffff },
  2639. { 0x1620, 0, 0x00000000, 0xffffffff },
  2640. { 0x1624, 0, 0x00000000, 0xffffffff },
  2641. { 0x1628, 0, 0x00000000, 0xffffffff },
  2642. { 0x162c, 0, 0x00000000, 0xffffffff },
  2643. { 0x1630, 0, 0x00000000, 0xffffffff },
  2644. { 0x1634, 0, 0x00000000, 0xffffffff },
  2645. { 0x1638, 0, 0x00000000, 0xffffffff },
  2646. { 0x163c, 0, 0x00000000, 0xffffffff },
  2647. { 0x1640, 0, 0x00000000, 0xffffffff },
  2648. { 0x1644, 0, 0x00000000, 0xffffffff },
  2649. { 0x1648, 0, 0x00000000, 0xffffffff },
  2650. { 0x164c, 0, 0x00000000, 0xffffffff },
  2651. { 0x1650, 0, 0x00000000, 0xffffffff },
  2652. { 0x1654, 0, 0x00000000, 0xffffffff },
  2653. { 0x1800, 0, 0x00000000, 0x00000001 },
  2654. { 0x1804, 0, 0x00000000, 0x00000003 },
  2655. { 0x1840, 0, 0x00000000, 0xffffffff },
  2656. { 0x1844, 0, 0x00000000, 0xffffffff },
  2657. { 0x1848, 0, 0x00000000, 0xffffffff },
  2658. { 0x184c, 0, 0x00000000, 0xffffffff },
  2659. { 0x1850, 0, 0x00000000, 0xffffffff },
  2660. { 0x1900, 0, 0x7ffbffff, 0x00000000 },
  2661. { 0x1904, 0, 0xffffffff, 0x00000000 },
  2662. { 0x190c, 0, 0xffffffff, 0x00000000 },
  2663. { 0x1914, 0, 0xffffffff, 0x00000000 },
  2664. { 0x191c, 0, 0xffffffff, 0x00000000 },
  2665. { 0x1924, 0, 0xffffffff, 0x00000000 },
  2666. { 0x192c, 0, 0xffffffff, 0x00000000 },
  2667. { 0x1934, 0, 0xffffffff, 0x00000000 },
  2668. { 0x193c, 0, 0xffffffff, 0x00000000 },
  2669. { 0x1944, 0, 0xffffffff, 0x00000000 },
  2670. { 0x194c, 0, 0xffffffff, 0x00000000 },
  2671. { 0x1954, 0, 0xffffffff, 0x00000000 },
  2672. { 0x195c, 0, 0xffffffff, 0x00000000 },
  2673. { 0x1964, 0, 0xffffffff, 0x00000000 },
  2674. { 0x196c, 0, 0xffffffff, 0x00000000 },
  2675. { 0x1974, 0, 0xffffffff, 0x00000000 },
  2676. { 0x197c, 0, 0xffffffff, 0x00000000 },
  2677. { 0x1980, 0, 0x0700ffff, 0x00000000 },
  2678. { 0x1c00, 0, 0x00000000, 0x00000001 },
  2679. { 0x1c04, 0, 0x00000000, 0x00000003 },
  2680. { 0x1c08, 0, 0x0000000f, 0x00000000 },
  2681. { 0x1c40, 0, 0x00000000, 0xffffffff },
  2682. { 0x1c44, 0, 0x00000000, 0xffffffff },
  2683. { 0x1c48, 0, 0x00000000, 0xffffffff },
  2684. { 0x1c4c, 0, 0x00000000, 0xffffffff },
  2685. { 0x1c50, 0, 0x00000000, 0xffffffff },
  2686. { 0x1d00, 0, 0x7ffbffff, 0x00000000 },
  2687. { 0x1d04, 0, 0xffffffff, 0x00000000 },
  2688. { 0x1d0c, 0, 0xffffffff, 0x00000000 },
  2689. { 0x1d14, 0, 0xffffffff, 0x00000000 },
  2690. { 0x1d1c, 0, 0xffffffff, 0x00000000 },
  2691. { 0x1d24, 0, 0xffffffff, 0x00000000 },
  2692. { 0x1d2c, 0, 0xffffffff, 0x00000000 },
  2693. { 0x1d34, 0, 0xffffffff, 0x00000000 },
  2694. { 0x1d3c, 0, 0xffffffff, 0x00000000 },
  2695. { 0x1d44, 0, 0xffffffff, 0x00000000 },
  2696. { 0x1d4c, 0, 0xffffffff, 0x00000000 },
  2697. { 0x1d54, 0, 0xffffffff, 0x00000000 },
  2698. { 0x1d5c, 0, 0xffffffff, 0x00000000 },
  2699. { 0x1d64, 0, 0xffffffff, 0x00000000 },
  2700. { 0x1d6c, 0, 0xffffffff, 0x00000000 },
  2701. { 0x1d74, 0, 0xffffffff, 0x00000000 },
  2702. { 0x1d7c, 0, 0xffffffff, 0x00000000 },
  2703. { 0x1d80, 0, 0x0700ffff, 0x00000000 },
  2704. { 0x2004, 0, 0x00000000, 0x0337000f },
  2705. { 0x2008, 0, 0xffffffff, 0x00000000 },
  2706. { 0x200c, 0, 0xffffffff, 0x00000000 },
  2707. { 0x2010, 0, 0xffffffff, 0x00000000 },
  2708. { 0x2014, 0, 0x801fff80, 0x00000000 },
  2709. { 0x2018, 0, 0x000003ff, 0x00000000 },
  2710. { 0x2800, 0, 0x00000000, 0x00000001 },
  2711. { 0x2804, 0, 0x00000000, 0x00003f01 },
  2712. { 0x2808, 0, 0x0f3f3f03, 0x00000000 },
  2713. { 0x2810, 0, 0xffff0000, 0x00000000 },
  2714. { 0x2814, 0, 0xffff0000, 0x00000000 },
  2715. { 0x2818, 0, 0xffff0000, 0x00000000 },
  2716. { 0x281c, 0, 0xffff0000, 0x00000000 },
  2717. { 0x2834, 0, 0xffffffff, 0x00000000 },
  2718. { 0x2840, 0, 0x00000000, 0xffffffff },
  2719. { 0x2844, 0, 0x00000000, 0xffffffff },
  2720. { 0x2848, 0, 0xffffffff, 0x00000000 },
  2721. { 0x284c, 0, 0xf800f800, 0x07ff07ff },
  2722. { 0x2c00, 0, 0x00000000, 0x00000011 },
  2723. { 0x2c04, 0, 0x00000000, 0x00030007 },
  2724. { 0x3000, 0, 0x00000000, 0x00000001 },
  2725. { 0x3004, 0, 0x00000000, 0x007007ff },
  2726. { 0x3008, 0, 0x00000003, 0x00000000 },
  2727. { 0x300c, 0, 0xffffffff, 0x00000000 },
  2728. { 0x3010, 0, 0xffffffff, 0x00000000 },
  2729. { 0x3014, 0, 0xffffffff, 0x00000000 },
  2730. { 0x3034, 0, 0xffffffff, 0x00000000 },
  2731. { 0x3038, 0, 0xffffffff, 0x00000000 },
  2732. { 0x3050, 0, 0x00000001, 0x00000000 },
  2733. { 0x3c00, 0, 0x00000000, 0x00000001 },
  2734. { 0x3c04, 0, 0x00000000, 0x00070000 },
  2735. { 0x3c08, 0, 0x00007f71, 0x07f00000 },
  2736. { 0x3c0c, 0, 0x1f3ffffc, 0x00000000 },
  2737. { 0x3c10, 0, 0xffffffff, 0x00000000 },
  2738. { 0x3c14, 0, 0x00000000, 0xffffffff },
  2739. { 0x3c18, 0, 0x00000000, 0xffffffff },
  2740. { 0x3c1c, 0, 0xfffff000, 0x00000000 },
  2741. { 0x3c20, 0, 0xffffff00, 0x00000000 },
  2742. { 0x3c24, 0, 0xffffffff, 0x00000000 },
  2743. { 0x3c28, 0, 0xffffffff, 0x00000000 },
  2744. { 0x3c2c, 0, 0xffffffff, 0x00000000 },
  2745. { 0x3c30, 0, 0xffffffff, 0x00000000 },
  2746. { 0x3c34, 0, 0xffffffff, 0x00000000 },
  2747. { 0x3c38, 0, 0xffffffff, 0x00000000 },
  2748. { 0x3c3c, 0, 0xffffffff, 0x00000000 },
  2749. { 0x3c40, 0, 0xffffffff, 0x00000000 },
  2750. { 0x3c44, 0, 0xffffffff, 0x00000000 },
  2751. { 0x3c48, 0, 0xffffffff, 0x00000000 },
  2752. { 0x3c4c, 0, 0xffffffff, 0x00000000 },
  2753. { 0x3c50, 0, 0xffffffff, 0x00000000 },
  2754. { 0x3c54, 0, 0xffffffff, 0x00000000 },
  2755. { 0x3c58, 0, 0xffffffff, 0x00000000 },
  2756. { 0x3c5c, 0, 0xffffffff, 0x00000000 },
  2757. { 0x3c60, 0, 0xffffffff, 0x00000000 },
  2758. { 0x3c64, 0, 0xffffffff, 0x00000000 },
  2759. { 0x3c68, 0, 0xffffffff, 0x00000000 },
  2760. { 0x3c6c, 0, 0xffffffff, 0x00000000 },
  2761. { 0x3c70, 0, 0xffffffff, 0x00000000 },
  2762. { 0x3c74, 0, 0x0000003f, 0x00000000 },
  2763. { 0x3c78, 0, 0x00000000, 0x00000000 },
  2764. { 0x3c7c, 0, 0x00000000, 0x00000000 },
  2765. { 0x3c80, 0, 0x3fffffff, 0x00000000 },
  2766. { 0x3c84, 0, 0x0000003f, 0x00000000 },
  2767. { 0x3c88, 0, 0x00000000, 0xffffffff },
  2768. { 0x3c8c, 0, 0x00000000, 0xffffffff },
  2769. { 0x4000, 0, 0x00000000, 0x00000001 },
  2770. { 0x4004, 0, 0x00000000, 0x00030000 },
  2771. { 0x4008, 0, 0x00000ff0, 0x00000000 },
  2772. { 0x400c, 0, 0xffffffff, 0x00000000 },
  2773. { 0x4088, 0, 0x00000000, 0x00070303 },
  2774. { 0x4400, 0, 0x00000000, 0x00000001 },
  2775. { 0x4404, 0, 0x00000000, 0x00003f01 },
  2776. { 0x4408, 0, 0x7fff00ff, 0x00000000 },
  2777. { 0x440c, 0, 0xffffffff, 0x00000000 },
  2778. { 0x4410, 0, 0xffff, 0x0000 },
  2779. { 0x4414, 0, 0xffff, 0x0000 },
  2780. { 0x4418, 0, 0xffff, 0x0000 },
  2781. { 0x441c, 0, 0xffff, 0x0000 },
  2782. { 0x4428, 0, 0xffffffff, 0x00000000 },
  2783. { 0x442c, 0, 0xffffffff, 0x00000000 },
  2784. { 0x4430, 0, 0xffffffff, 0x00000000 },
  2785. { 0x4434, 0, 0xffffffff, 0x00000000 },
  2786. { 0x4438, 0, 0xffffffff, 0x00000000 },
  2787. { 0x443c, 0, 0xffffffff, 0x00000000 },
  2788. { 0x4440, 0, 0xffffffff, 0x00000000 },
  2789. { 0x4444, 0, 0xffffffff, 0x00000000 },
  2790. { 0x4c00, 0, 0x00000000, 0x00000001 },
  2791. { 0x4c04, 0, 0x00000000, 0x0000003f },
  2792. { 0x4c08, 0, 0xffffffff, 0x00000000 },
  2793. { 0x4c0c, 0, 0x0007fc00, 0x00000000 },
  2794. { 0x4c10, 0, 0x80003fe0, 0x00000000 },
  2795. { 0x4c14, 0, 0xffffffff, 0x00000000 },
  2796. { 0x4c44, 0, 0x00000000, 0x9fff9fff },
  2797. { 0x4c48, 0, 0x00000000, 0xb3009fff },
  2798. { 0x4c4c, 0, 0x00000000, 0x77f33b30 },
  2799. { 0x4c50, 0, 0x00000000, 0xffffffff },
  2800. { 0x5004, 0, 0x00000000, 0x0000007f },
  2801. { 0x5008, 0, 0x0f0007ff, 0x00000000 },
  2802. { 0x500c, 0, 0xf800f800, 0x07ff07ff },
  2803. { 0x5400, 0, 0x00000008, 0x00000001 },
  2804. { 0x5404, 0, 0x00000000, 0x0000003f },
  2805. { 0x5408, 0, 0x0000001f, 0x00000000 },
  2806. { 0x540c, 0, 0xffffffff, 0x00000000 },
  2807. { 0x5410, 0, 0xffffffff, 0x00000000 },
  2808. { 0x5414, 0, 0x0000ffff, 0x00000000 },
  2809. { 0x5418, 0, 0x0000ffff, 0x00000000 },
  2810. { 0x541c, 0, 0x0000ffff, 0x00000000 },
  2811. { 0x5420, 0, 0x0000ffff, 0x00000000 },
  2812. { 0x5428, 0, 0x000000ff, 0x00000000 },
  2813. { 0x542c, 0, 0xff00ffff, 0x00000000 },
  2814. { 0x5430, 0, 0x001fff80, 0x00000000 },
  2815. { 0x5438, 0, 0xffffffff, 0x00000000 },
  2816. { 0x543c, 0, 0xffffffff, 0x00000000 },
  2817. { 0x5440, 0, 0xf800f800, 0x07ff07ff },
  2818. { 0x5c00, 0, 0x00000000, 0x00000001 },
  2819. { 0x5c04, 0, 0x00000000, 0x0003000f },
  2820. { 0x5c08, 0, 0x00000003, 0x00000000 },
  2821. { 0x5c0c, 0, 0x0000fff8, 0x00000000 },
  2822. { 0x5c10, 0, 0x00000000, 0xffffffff },
  2823. { 0x5c80, 0, 0x00000000, 0x0f7113f1 },
  2824. { 0x5c84, 0, 0x00000000, 0x0000f333 },
  2825. { 0x5c88, 0, 0x00000000, 0x00077373 },
  2826. { 0x5c8c, 0, 0x00000000, 0x0007f737 },
  2827. { 0x6808, 0, 0x0000ff7f, 0x00000000 },
  2828. { 0x680c, 0, 0xffffffff, 0x00000000 },
  2829. { 0x6810, 0, 0xffffffff, 0x00000000 },
  2830. { 0x6814, 0, 0xffffffff, 0x00000000 },
  2831. { 0x6818, 0, 0xffffffff, 0x00000000 },
  2832. { 0x681c, 0, 0xffffffff, 0x00000000 },
  2833. { 0x6820, 0, 0x00ff00ff, 0x00000000 },
  2834. { 0x6824, 0, 0x00ff00ff, 0x00000000 },
  2835. { 0x6828, 0, 0x00ff00ff, 0x00000000 },
  2836. { 0x682c, 0, 0x03ff03ff, 0x00000000 },
  2837. { 0x6830, 0, 0x03ff03ff, 0x00000000 },
  2838. { 0x6834, 0, 0x03ff03ff, 0x00000000 },
  2839. { 0x6838, 0, 0x03ff03ff, 0x00000000 },
  2840. { 0x683c, 0, 0x0000ffff, 0x00000000 },
  2841. { 0x6840, 0, 0x00000ff0, 0x00000000 },
  2842. { 0x6844, 0, 0x00ffff00, 0x00000000 },
  2843. { 0x684c, 0, 0xffffffff, 0x00000000 },
  2844. { 0x6850, 0, 0x7f7f7f7f, 0x00000000 },
  2845. { 0x6854, 0, 0x7f7f7f7f, 0x00000000 },
  2846. { 0x6858, 0, 0x7f7f7f7f, 0x00000000 },
  2847. { 0x685c, 0, 0x7f7f7f7f, 0x00000000 },
  2848. { 0x6908, 0, 0x00000000, 0x0001ff0f },
  2849. { 0x690c, 0, 0x00000000, 0x0ffe00f0 },
  2850. { 0xffff, 0, 0x00000000, 0x00000000 },
  2851. };
  2852. ret = 0;
  2853. for (i = 0; reg_tbl[i].offset != 0xffff; i++) {
  2854. u32 offset, rw_mask, ro_mask, save_val, val;
  2855. offset = (u32) reg_tbl[i].offset;
  2856. rw_mask = reg_tbl[i].rw_mask;
  2857. ro_mask = reg_tbl[i].ro_mask;
  2858. save_val = readl(bp->regview + offset);
  2859. writel(0, bp->regview + offset);
  2860. val = readl(bp->regview + offset);
  2861. if ((val & rw_mask) != 0) {
  2862. goto reg_test_err;
  2863. }
  2864. if ((val & ro_mask) != (save_val & ro_mask)) {
  2865. goto reg_test_err;
  2866. }
  2867. writel(0xffffffff, bp->regview + offset);
  2868. val = readl(bp->regview + offset);
  2869. if ((val & rw_mask) != rw_mask) {
  2870. goto reg_test_err;
  2871. }
  2872. if ((val & ro_mask) != (save_val & ro_mask)) {
  2873. goto reg_test_err;
  2874. }
  2875. writel(save_val, bp->regview + offset);
  2876. continue;
  2877. reg_test_err:
  2878. writel(save_val, bp->regview + offset);
  2879. ret = -ENODEV;
  2880. break;
  2881. }
  2882. return ret;
  2883. }
  2884. static int
  2885. bnx2_do_mem_test(struct bnx2 *bp, u32 start, u32 size)
  2886. {
  2887. static u32 test_pattern[] = { 0x00000000, 0xffffffff, 0x55555555,
  2888. 0xaaaaaaaa , 0xaa55aa55, 0x55aa55aa };
  2889. int i;
  2890. for (i = 0; i < sizeof(test_pattern) / 4; i++) {
  2891. u32 offset;
  2892. for (offset = 0; offset < size; offset += 4) {
  2893. REG_WR_IND(bp, start + offset, test_pattern[i]);
  2894. if (REG_RD_IND(bp, start + offset) !=
  2895. test_pattern[i]) {
  2896. return -ENODEV;
  2897. }
  2898. }
  2899. }
  2900. return 0;
  2901. }
  2902. static int
  2903. bnx2_test_memory(struct bnx2 *bp)
  2904. {
  2905. int ret = 0;
  2906. int i;
  2907. static struct {
  2908. u32 offset;
  2909. u32 len;
  2910. } mem_tbl[] = {
  2911. { 0x60000, 0x4000 },
  2912. { 0xa0000, 0x4000 },
  2913. { 0xe0000, 0x4000 },
  2914. { 0x120000, 0x4000 },
  2915. { 0x1a0000, 0x4000 },
  2916. { 0x160000, 0x4000 },
  2917. { 0xffffffff, 0 },
  2918. };
  2919. for (i = 0; mem_tbl[i].offset != 0xffffffff; i++) {
  2920. if ((ret = bnx2_do_mem_test(bp, mem_tbl[i].offset,
  2921. mem_tbl[i].len)) != 0) {
  2922. return ret;
  2923. }
  2924. }
  2925. return ret;
  2926. }
  2927. static int
  2928. bnx2_test_loopback(struct bnx2 *bp)
  2929. {
  2930. unsigned int pkt_size, num_pkts, i;
  2931. struct sk_buff *skb, *rx_skb;
  2932. unsigned char *packet;
  2933. u16 rx_start_idx, rx_idx, send_idx;
  2934. u32 send_bseq, val;
  2935. dma_addr_t map;
  2936. struct tx_bd *txbd;
  2937. struct sw_bd *rx_buf;
  2938. struct l2_fhdr *rx_hdr;
  2939. int ret = -ENODEV;
  2940. if (!netif_running(bp->dev))
  2941. return -ENODEV;
  2942. bp->loopback = MAC_LOOPBACK;
  2943. bnx2_reset_nic(bp, BNX2_DRV_MSG_CODE_DIAG);
  2944. bnx2_set_mac_loopback(bp);
  2945. pkt_size = 1514;
  2946. skb = dev_alloc_skb(pkt_size);
  2947. packet = skb_put(skb, pkt_size);
  2948. memcpy(packet, bp->mac_addr, 6);
  2949. memset(packet + 6, 0x0, 8);
  2950. for (i = 14; i < pkt_size; i++)
  2951. packet[i] = (unsigned char) (i & 0xff);
  2952. map = pci_map_single(bp->pdev, skb->data, pkt_size,
  2953. PCI_DMA_TODEVICE);
  2954. val = REG_RD(bp, BNX2_HC_COMMAND);
  2955. REG_WR(bp, BNX2_HC_COMMAND, val | BNX2_HC_COMMAND_COAL_NOW_WO_INT);
  2956. REG_RD(bp, BNX2_HC_COMMAND);
  2957. udelay(5);
  2958. rx_start_idx = bp->status_blk->status_rx_quick_consumer_index0;
  2959. send_idx = 0;
  2960. send_bseq = 0;
  2961. num_pkts = 0;
  2962. txbd = &bp->tx_desc_ring[send_idx];
  2963. txbd->tx_bd_haddr_hi = (u64) map >> 32;
  2964. txbd->tx_bd_haddr_lo = (u64) map & 0xffffffff;
  2965. txbd->tx_bd_mss_nbytes = pkt_size;
  2966. txbd->tx_bd_vlan_tag_flags = TX_BD_FLAGS_START | TX_BD_FLAGS_END;
  2967. num_pkts++;
  2968. send_idx = NEXT_TX_BD(send_idx);
  2969. send_bseq += pkt_size;
  2970. REG_WR16(bp, MB_TX_CID_ADDR + BNX2_L2CTX_TX_HOST_BIDX, send_idx);
  2971. REG_WR(bp, MB_TX_CID_ADDR + BNX2_L2CTX_TX_HOST_BSEQ, send_bseq);
  2972. udelay(100);
  2973. val = REG_RD(bp, BNX2_HC_COMMAND);
  2974. REG_WR(bp, BNX2_HC_COMMAND, val | BNX2_HC_COMMAND_COAL_NOW_WO_INT);
  2975. REG_RD(bp, BNX2_HC_COMMAND);
  2976. udelay(5);
  2977. pci_unmap_single(bp->pdev, map, pkt_size, PCI_DMA_TODEVICE);
  2978. dev_kfree_skb_irq(skb);
  2979. if (bp->status_blk->status_tx_quick_consumer_index0 != send_idx) {
  2980. goto loopback_test_done;
  2981. }
  2982. rx_idx = bp->status_blk->status_rx_quick_consumer_index0;
  2983. if (rx_idx != rx_start_idx + num_pkts) {
  2984. goto loopback_test_done;
  2985. }
  2986. rx_buf = &bp->rx_buf_ring[rx_start_idx];
  2987. rx_skb = rx_buf->skb;
  2988. rx_hdr = (struct l2_fhdr *) rx_skb->data;
  2989. skb_reserve(rx_skb, bp->rx_offset);
  2990. pci_dma_sync_single_for_cpu(bp->pdev,
  2991. pci_unmap_addr(rx_buf, mapping),
  2992. bp->rx_buf_size, PCI_DMA_FROMDEVICE);
  2993. if (rx_hdr->l2_fhdr_errors &
  2994. (L2_FHDR_ERRORS_BAD_CRC |
  2995. L2_FHDR_ERRORS_PHY_DECODE |
  2996. L2_FHDR_ERRORS_ALIGNMENT |
  2997. L2_FHDR_ERRORS_TOO_SHORT |
  2998. L2_FHDR_ERRORS_GIANT_FRAME)) {
  2999. goto loopback_test_done;
  3000. }
  3001. if ((rx_hdr->l2_fhdr_pkt_len - 4) != pkt_size) {
  3002. goto loopback_test_done;
  3003. }
  3004. for (i = 14; i < pkt_size; i++) {
  3005. if (*(rx_skb->data + i) != (unsigned char) (i & 0xff)) {
  3006. goto loopback_test_done;
  3007. }
  3008. }
  3009. ret = 0;
  3010. loopback_test_done:
  3011. bp->loopback = 0;
  3012. return ret;
  3013. }
  3014. #define NVRAM_SIZE 0x200
  3015. #define CRC32_RESIDUAL 0xdebb20e3
  3016. static int
  3017. bnx2_test_nvram(struct bnx2 *bp)
  3018. {
  3019. u32 buf[NVRAM_SIZE / 4];
  3020. u8 *data = (u8 *) buf;
  3021. int rc = 0;
  3022. u32 magic, csum;
  3023. if ((rc = bnx2_nvram_read(bp, 0, data, 4)) != 0)
  3024. goto test_nvram_done;
  3025. magic = be32_to_cpu(buf[0]);
  3026. if (magic != 0x669955aa) {
  3027. rc = -ENODEV;
  3028. goto test_nvram_done;
  3029. }
  3030. if ((rc = bnx2_nvram_read(bp, 0x100, data, NVRAM_SIZE)) != 0)
  3031. goto test_nvram_done;
  3032. csum = ether_crc_le(0x100, data);
  3033. if (csum != CRC32_RESIDUAL) {
  3034. rc = -ENODEV;
  3035. goto test_nvram_done;
  3036. }
  3037. csum = ether_crc_le(0x100, data + 0x100);
  3038. if (csum != CRC32_RESIDUAL) {
  3039. rc = -ENODEV;
  3040. }
  3041. test_nvram_done:
  3042. return rc;
  3043. }
  3044. static int
  3045. bnx2_test_link(struct bnx2 *bp)
  3046. {
  3047. u32 bmsr;
  3048. spin_lock_bh(&bp->phy_lock);
  3049. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  3050. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  3051. spin_unlock_bh(&bp->phy_lock);
  3052. if (bmsr & BMSR_LSTATUS) {
  3053. return 0;
  3054. }
  3055. return -ENODEV;
  3056. }
  3057. static int
  3058. bnx2_test_intr(struct bnx2 *bp)
  3059. {
  3060. int i;
  3061. u32 val;
  3062. u16 status_idx;
  3063. if (!netif_running(bp->dev))
  3064. return -ENODEV;
  3065. status_idx = REG_RD(bp, BNX2_PCICFG_INT_ACK_CMD) & 0xffff;
  3066. /* This register is not touched during run-time. */
  3067. val = REG_RD(bp, BNX2_HC_COMMAND);
  3068. REG_WR(bp, BNX2_HC_COMMAND, val | BNX2_HC_COMMAND_COAL_NOW);
  3069. REG_RD(bp, BNX2_HC_COMMAND);
  3070. for (i = 0; i < 10; i++) {
  3071. if ((REG_RD(bp, BNX2_PCICFG_INT_ACK_CMD) & 0xffff) !=
  3072. status_idx) {
  3073. break;
  3074. }
  3075. msleep_interruptible(10);
  3076. }
  3077. if (i < 10)
  3078. return 0;
  3079. return -ENODEV;
  3080. }
  3081. static void
  3082. bnx2_timer(unsigned long data)
  3083. {
  3084. struct bnx2 *bp = (struct bnx2 *) data;
  3085. u32 msg;
  3086. if (!netif_running(bp->dev))
  3087. return;
  3088. if (atomic_read(&bp->intr_sem) != 0)
  3089. goto bnx2_restart_timer;
  3090. msg = (u32) ++bp->fw_drv_pulse_wr_seq;
  3091. REG_WR_IND(bp, HOST_VIEW_SHMEM_BASE + BNX2_DRV_PULSE_MB, msg);
  3092. if ((bp->phy_flags & PHY_SERDES_FLAG) &&
  3093. (CHIP_NUM(bp) == CHIP_NUM_5706)) {
  3094. spin_lock(&bp->phy_lock);
  3095. if (bp->serdes_an_pending) {
  3096. bp->serdes_an_pending--;
  3097. }
  3098. else if ((bp->link_up == 0) && (bp->autoneg & AUTONEG_SPEED)) {
  3099. u32 bmcr;
  3100. bp->current_interval = bp->timer_interval;
  3101. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  3102. if (bmcr & BMCR_ANENABLE) {
  3103. u32 phy1, phy2;
  3104. bnx2_write_phy(bp, 0x1c, 0x7c00);
  3105. bnx2_read_phy(bp, 0x1c, &phy1);
  3106. bnx2_write_phy(bp, 0x17, 0x0f01);
  3107. bnx2_read_phy(bp, 0x15, &phy2);
  3108. bnx2_write_phy(bp, 0x17, 0x0f01);
  3109. bnx2_read_phy(bp, 0x15, &phy2);
  3110. if ((phy1 & 0x10) && /* SIGNAL DETECT */
  3111. !(phy2 & 0x20)) { /* no CONFIG */
  3112. bmcr &= ~BMCR_ANENABLE;
  3113. bmcr |= BMCR_SPEED1000 |
  3114. BMCR_FULLDPLX;
  3115. bnx2_write_phy(bp, MII_BMCR, bmcr);
  3116. bp->phy_flags |=
  3117. PHY_PARALLEL_DETECT_FLAG;
  3118. }
  3119. }
  3120. }
  3121. else if ((bp->link_up) && (bp->autoneg & AUTONEG_SPEED) &&
  3122. (bp->phy_flags & PHY_PARALLEL_DETECT_FLAG)) {
  3123. u32 phy2;
  3124. bnx2_write_phy(bp, 0x17, 0x0f01);
  3125. bnx2_read_phy(bp, 0x15, &phy2);
  3126. if (phy2 & 0x20) {
  3127. u32 bmcr;
  3128. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  3129. bmcr |= BMCR_ANENABLE;
  3130. bnx2_write_phy(bp, MII_BMCR, bmcr);
  3131. bp->phy_flags &= ~PHY_PARALLEL_DETECT_FLAG;
  3132. }
  3133. }
  3134. else
  3135. bp->current_interval = bp->timer_interval;
  3136. spin_unlock(&bp->phy_lock);
  3137. }
  3138. bnx2_restart_timer:
  3139. mod_timer(&bp->timer, jiffies + bp->current_interval);
  3140. }
  3141. /* Called with rtnl_lock */
  3142. static int
  3143. bnx2_open(struct net_device *dev)
  3144. {
  3145. struct bnx2 *bp = dev->priv;
  3146. int rc;
  3147. bnx2_set_power_state(bp, PCI_D0);
  3148. bnx2_disable_int(bp);
  3149. rc = bnx2_alloc_mem(bp);
  3150. if (rc)
  3151. return rc;
  3152. if ((CHIP_ID(bp) != CHIP_ID_5706_A0) &&
  3153. (CHIP_ID(bp) != CHIP_ID_5706_A1) &&
  3154. !disable_msi) {
  3155. if (pci_enable_msi(bp->pdev) == 0) {
  3156. bp->flags |= USING_MSI_FLAG;
  3157. rc = request_irq(bp->pdev->irq, bnx2_msi, 0, dev->name,
  3158. dev);
  3159. }
  3160. else {
  3161. rc = request_irq(bp->pdev->irq, bnx2_interrupt,
  3162. SA_SHIRQ, dev->name, dev);
  3163. }
  3164. }
  3165. else {
  3166. rc = request_irq(bp->pdev->irq, bnx2_interrupt, SA_SHIRQ,
  3167. dev->name, dev);
  3168. }
  3169. if (rc) {
  3170. bnx2_free_mem(bp);
  3171. return rc;
  3172. }
  3173. rc = bnx2_init_nic(bp);
  3174. if (rc) {
  3175. free_irq(bp->pdev->irq, dev);
  3176. if (bp->flags & USING_MSI_FLAG) {
  3177. pci_disable_msi(bp->pdev);
  3178. bp->flags &= ~USING_MSI_FLAG;
  3179. }
  3180. bnx2_free_skbs(bp);
  3181. bnx2_free_mem(bp);
  3182. return rc;
  3183. }
  3184. mod_timer(&bp->timer, jiffies + bp->current_interval);
  3185. atomic_set(&bp->intr_sem, 0);
  3186. bnx2_enable_int(bp);
  3187. if (bp->flags & USING_MSI_FLAG) {
  3188. /* Test MSI to make sure it is working
  3189. * If MSI test fails, go back to INTx mode
  3190. */
  3191. if (bnx2_test_intr(bp) != 0) {
  3192. printk(KERN_WARNING PFX "%s: No interrupt was generated"
  3193. " using MSI, switching to INTx mode. Please"
  3194. " report this failure to the PCI maintainer"
  3195. " and include system chipset information.\n",
  3196. bp->dev->name);
  3197. bnx2_disable_int(bp);
  3198. free_irq(bp->pdev->irq, dev);
  3199. pci_disable_msi(bp->pdev);
  3200. bp->flags &= ~USING_MSI_FLAG;
  3201. rc = bnx2_init_nic(bp);
  3202. if (!rc) {
  3203. rc = request_irq(bp->pdev->irq, bnx2_interrupt,
  3204. SA_SHIRQ, dev->name, dev);
  3205. }
  3206. if (rc) {
  3207. bnx2_free_skbs(bp);
  3208. bnx2_free_mem(bp);
  3209. del_timer_sync(&bp->timer);
  3210. return rc;
  3211. }
  3212. bnx2_enable_int(bp);
  3213. }
  3214. }
  3215. if (bp->flags & USING_MSI_FLAG) {
  3216. printk(KERN_INFO PFX "%s: using MSI\n", dev->name);
  3217. }
  3218. netif_start_queue(dev);
  3219. return 0;
  3220. }
  3221. static void
  3222. bnx2_reset_task(void *data)
  3223. {
  3224. struct bnx2 *bp = data;
  3225. if (!netif_running(bp->dev))
  3226. return;
  3227. bp->in_reset_task = 1;
  3228. bnx2_netif_stop(bp);
  3229. bnx2_init_nic(bp);
  3230. atomic_set(&bp->intr_sem, 1);
  3231. bnx2_netif_start(bp);
  3232. bp->in_reset_task = 0;
  3233. }
  3234. static void
  3235. bnx2_tx_timeout(struct net_device *dev)
  3236. {
  3237. struct bnx2 *bp = dev->priv;
  3238. /* This allows the netif to be shutdown gracefully before resetting */
  3239. schedule_work(&bp->reset_task);
  3240. }
  3241. #ifdef BCM_VLAN
  3242. /* Called with rtnl_lock */
  3243. static void
  3244. bnx2_vlan_rx_register(struct net_device *dev, struct vlan_group *vlgrp)
  3245. {
  3246. struct bnx2 *bp = dev->priv;
  3247. bnx2_netif_stop(bp);
  3248. bp->vlgrp = vlgrp;
  3249. bnx2_set_rx_mode(dev);
  3250. bnx2_netif_start(bp);
  3251. }
  3252. /* Called with rtnl_lock */
  3253. static void
  3254. bnx2_vlan_rx_kill_vid(struct net_device *dev, uint16_t vid)
  3255. {
  3256. struct bnx2 *bp = dev->priv;
  3257. bnx2_netif_stop(bp);
  3258. if (bp->vlgrp)
  3259. bp->vlgrp->vlan_devices[vid] = NULL;
  3260. bnx2_set_rx_mode(dev);
  3261. bnx2_netif_start(bp);
  3262. }
  3263. #endif
  3264. /* Called with dev->xmit_lock.
  3265. * hard_start_xmit is pseudo-lockless - a lock is only required when
  3266. * the tx queue is full. This way, we get the benefit of lockless
  3267. * operations most of the time without the complexities to handle
  3268. * netif_stop_queue/wake_queue race conditions.
  3269. */
  3270. static int
  3271. bnx2_start_xmit(struct sk_buff *skb, struct net_device *dev)
  3272. {
  3273. struct bnx2 *bp = dev->priv;
  3274. dma_addr_t mapping;
  3275. struct tx_bd *txbd;
  3276. struct sw_bd *tx_buf;
  3277. u32 len, vlan_tag_flags, last_frag, mss;
  3278. u16 prod, ring_prod;
  3279. int i;
  3280. if (unlikely(bnx2_tx_avail(bp) < (skb_shinfo(skb)->nr_frags + 1))) {
  3281. netif_stop_queue(dev);
  3282. printk(KERN_ERR PFX "%s: BUG! Tx ring full when queue awake!\n",
  3283. dev->name);
  3284. return NETDEV_TX_BUSY;
  3285. }
  3286. len = skb_headlen(skb);
  3287. prod = bp->tx_prod;
  3288. ring_prod = TX_RING_IDX(prod);
  3289. vlan_tag_flags = 0;
  3290. if (skb->ip_summed == CHECKSUM_HW) {
  3291. vlan_tag_flags |= TX_BD_FLAGS_TCP_UDP_CKSUM;
  3292. }
  3293. if (bp->vlgrp != 0 && vlan_tx_tag_present(skb)) {
  3294. vlan_tag_flags |=
  3295. (TX_BD_FLAGS_VLAN_TAG | (vlan_tx_tag_get(skb) << 16));
  3296. }
  3297. #ifdef BCM_TSO
  3298. if ((mss = skb_shinfo(skb)->tso_size) &&
  3299. (skb->len > (bp->dev->mtu + ETH_HLEN))) {
  3300. u32 tcp_opt_len, ip_tcp_len;
  3301. if (skb_header_cloned(skb) &&
  3302. pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) {
  3303. dev_kfree_skb(skb);
  3304. return NETDEV_TX_OK;
  3305. }
  3306. tcp_opt_len = ((skb->h.th->doff - 5) * 4);
  3307. vlan_tag_flags |= TX_BD_FLAGS_SW_LSO;
  3308. tcp_opt_len = 0;
  3309. if (skb->h.th->doff > 5) {
  3310. tcp_opt_len = (skb->h.th->doff - 5) << 2;
  3311. }
  3312. ip_tcp_len = (skb->nh.iph->ihl << 2) + sizeof(struct tcphdr);
  3313. skb->nh.iph->check = 0;
  3314. skb->nh.iph->tot_len = ntohs(mss + ip_tcp_len + tcp_opt_len);
  3315. skb->h.th->check =
  3316. ~csum_tcpudp_magic(skb->nh.iph->saddr,
  3317. skb->nh.iph->daddr,
  3318. 0, IPPROTO_TCP, 0);
  3319. if (tcp_opt_len || (skb->nh.iph->ihl > 5)) {
  3320. vlan_tag_flags |= ((skb->nh.iph->ihl - 5) +
  3321. (tcp_opt_len >> 2)) << 8;
  3322. }
  3323. }
  3324. else
  3325. #endif
  3326. {
  3327. mss = 0;
  3328. }
  3329. mapping = pci_map_single(bp->pdev, skb->data, len, PCI_DMA_TODEVICE);
  3330. tx_buf = &bp->tx_buf_ring[ring_prod];
  3331. tx_buf->skb = skb;
  3332. pci_unmap_addr_set(tx_buf, mapping, mapping);
  3333. txbd = &bp->tx_desc_ring[ring_prod];
  3334. txbd->tx_bd_haddr_hi = (u64) mapping >> 32;
  3335. txbd->tx_bd_haddr_lo = (u64) mapping & 0xffffffff;
  3336. txbd->tx_bd_mss_nbytes = len | (mss << 16);
  3337. txbd->tx_bd_vlan_tag_flags = vlan_tag_flags | TX_BD_FLAGS_START;
  3338. last_frag = skb_shinfo(skb)->nr_frags;
  3339. for (i = 0; i < last_frag; i++) {
  3340. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  3341. prod = NEXT_TX_BD(prod);
  3342. ring_prod = TX_RING_IDX(prod);
  3343. txbd = &bp->tx_desc_ring[ring_prod];
  3344. len = frag->size;
  3345. mapping = pci_map_page(bp->pdev, frag->page, frag->page_offset,
  3346. len, PCI_DMA_TODEVICE);
  3347. pci_unmap_addr_set(&bp->tx_buf_ring[ring_prod],
  3348. mapping, mapping);
  3349. txbd->tx_bd_haddr_hi = (u64) mapping >> 32;
  3350. txbd->tx_bd_haddr_lo = (u64) mapping & 0xffffffff;
  3351. txbd->tx_bd_mss_nbytes = len | (mss << 16);
  3352. txbd->tx_bd_vlan_tag_flags = vlan_tag_flags;
  3353. }
  3354. txbd->tx_bd_vlan_tag_flags |= TX_BD_FLAGS_END;
  3355. prod = NEXT_TX_BD(prod);
  3356. bp->tx_prod_bseq += skb->len;
  3357. REG_WR16(bp, MB_TX_CID_ADDR + BNX2_L2CTX_TX_HOST_BIDX, prod);
  3358. REG_WR(bp, MB_TX_CID_ADDR + BNX2_L2CTX_TX_HOST_BSEQ, bp->tx_prod_bseq);
  3359. mmiowb();
  3360. bp->tx_prod = prod;
  3361. dev->trans_start = jiffies;
  3362. if (unlikely(bnx2_tx_avail(bp) <= MAX_SKB_FRAGS)) {
  3363. spin_lock(&bp->tx_lock);
  3364. netif_stop_queue(dev);
  3365. if (bnx2_tx_avail(bp) > MAX_SKB_FRAGS)
  3366. netif_wake_queue(dev);
  3367. spin_unlock(&bp->tx_lock);
  3368. }
  3369. return NETDEV_TX_OK;
  3370. }
  3371. /* Called with rtnl_lock */
  3372. static int
  3373. bnx2_close(struct net_device *dev)
  3374. {
  3375. struct bnx2 *bp = dev->priv;
  3376. u32 reset_code;
  3377. /* Calling flush_scheduled_work() may deadlock because
  3378. * linkwatch_event() may be on the workqueue and it will try to get
  3379. * the rtnl_lock which we are holding.
  3380. */
  3381. while (bp->in_reset_task)
  3382. msleep(1);
  3383. bnx2_netif_stop(bp);
  3384. del_timer_sync(&bp->timer);
  3385. if (bp->wol)
  3386. reset_code = BNX2_DRV_MSG_CODE_SUSPEND_WOL;
  3387. else
  3388. reset_code = BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL;
  3389. bnx2_reset_chip(bp, reset_code);
  3390. free_irq(bp->pdev->irq, dev);
  3391. if (bp->flags & USING_MSI_FLAG) {
  3392. pci_disable_msi(bp->pdev);
  3393. bp->flags &= ~USING_MSI_FLAG;
  3394. }
  3395. bnx2_free_skbs(bp);
  3396. bnx2_free_mem(bp);
  3397. bp->link_up = 0;
  3398. netif_carrier_off(bp->dev);
  3399. bnx2_set_power_state(bp, PCI_D3hot);
  3400. return 0;
  3401. }
  3402. #define GET_NET_STATS64(ctr) \
  3403. (unsigned long) ((unsigned long) (ctr##_hi) << 32) + \
  3404. (unsigned long) (ctr##_lo)
  3405. #define GET_NET_STATS32(ctr) \
  3406. (ctr##_lo)
  3407. #if (BITS_PER_LONG == 64)
  3408. #define GET_NET_STATS GET_NET_STATS64
  3409. #else
  3410. #define GET_NET_STATS GET_NET_STATS32
  3411. #endif
  3412. static struct net_device_stats *
  3413. bnx2_get_stats(struct net_device *dev)
  3414. {
  3415. struct bnx2 *bp = dev->priv;
  3416. struct statistics_block *stats_blk = bp->stats_blk;
  3417. struct net_device_stats *net_stats = &bp->net_stats;
  3418. if (bp->stats_blk == NULL) {
  3419. return net_stats;
  3420. }
  3421. net_stats->rx_packets =
  3422. GET_NET_STATS(stats_blk->stat_IfHCInUcastPkts) +
  3423. GET_NET_STATS(stats_blk->stat_IfHCInMulticastPkts) +
  3424. GET_NET_STATS(stats_blk->stat_IfHCInBroadcastPkts);
  3425. net_stats->tx_packets =
  3426. GET_NET_STATS(stats_blk->stat_IfHCOutUcastPkts) +
  3427. GET_NET_STATS(stats_blk->stat_IfHCOutMulticastPkts) +
  3428. GET_NET_STATS(stats_blk->stat_IfHCOutBroadcastPkts);
  3429. net_stats->rx_bytes =
  3430. GET_NET_STATS(stats_blk->stat_IfHCInOctets);
  3431. net_stats->tx_bytes =
  3432. GET_NET_STATS(stats_blk->stat_IfHCOutOctets);
  3433. net_stats->multicast =
  3434. GET_NET_STATS(stats_blk->stat_IfHCOutMulticastPkts);
  3435. net_stats->collisions =
  3436. (unsigned long) stats_blk->stat_EtherStatsCollisions;
  3437. net_stats->rx_length_errors =
  3438. (unsigned long) (stats_blk->stat_EtherStatsUndersizePkts +
  3439. stats_blk->stat_EtherStatsOverrsizePkts);
  3440. net_stats->rx_over_errors =
  3441. (unsigned long) stats_blk->stat_IfInMBUFDiscards;
  3442. net_stats->rx_frame_errors =
  3443. (unsigned long) stats_blk->stat_Dot3StatsAlignmentErrors;
  3444. net_stats->rx_crc_errors =
  3445. (unsigned long) stats_blk->stat_Dot3StatsFCSErrors;
  3446. net_stats->rx_errors = net_stats->rx_length_errors +
  3447. net_stats->rx_over_errors + net_stats->rx_frame_errors +
  3448. net_stats->rx_crc_errors;
  3449. net_stats->tx_aborted_errors =
  3450. (unsigned long) (stats_blk->stat_Dot3StatsExcessiveCollisions +
  3451. stats_blk->stat_Dot3StatsLateCollisions);
  3452. if (CHIP_NUM(bp) == CHIP_NUM_5706)
  3453. net_stats->tx_carrier_errors = 0;
  3454. else {
  3455. net_stats->tx_carrier_errors =
  3456. (unsigned long)
  3457. stats_blk->stat_Dot3StatsCarrierSenseErrors;
  3458. }
  3459. net_stats->tx_errors =
  3460. (unsigned long)
  3461. stats_blk->stat_emac_tx_stat_dot3statsinternalmactransmiterrors
  3462. +
  3463. net_stats->tx_aborted_errors +
  3464. net_stats->tx_carrier_errors;
  3465. return net_stats;
  3466. }
  3467. /* All ethtool functions called with rtnl_lock */
  3468. static int
  3469. bnx2_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  3470. {
  3471. struct bnx2 *bp = dev->priv;
  3472. cmd->supported = SUPPORTED_Autoneg;
  3473. if (bp->phy_flags & PHY_SERDES_FLAG) {
  3474. cmd->supported |= SUPPORTED_1000baseT_Full |
  3475. SUPPORTED_FIBRE;
  3476. cmd->port = PORT_FIBRE;
  3477. }
  3478. else {
  3479. cmd->supported |= SUPPORTED_10baseT_Half |
  3480. SUPPORTED_10baseT_Full |
  3481. SUPPORTED_100baseT_Half |
  3482. SUPPORTED_100baseT_Full |
  3483. SUPPORTED_1000baseT_Full |
  3484. SUPPORTED_TP;
  3485. cmd->port = PORT_TP;
  3486. }
  3487. cmd->advertising = bp->advertising;
  3488. if (bp->autoneg & AUTONEG_SPEED) {
  3489. cmd->autoneg = AUTONEG_ENABLE;
  3490. }
  3491. else {
  3492. cmd->autoneg = AUTONEG_DISABLE;
  3493. }
  3494. if (netif_carrier_ok(dev)) {
  3495. cmd->speed = bp->line_speed;
  3496. cmd->duplex = bp->duplex;
  3497. }
  3498. else {
  3499. cmd->speed = -1;
  3500. cmd->duplex = -1;
  3501. }
  3502. cmd->transceiver = XCVR_INTERNAL;
  3503. cmd->phy_address = bp->phy_addr;
  3504. return 0;
  3505. }
  3506. static int
  3507. bnx2_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  3508. {
  3509. struct bnx2 *bp = dev->priv;
  3510. u8 autoneg = bp->autoneg;
  3511. u8 req_duplex = bp->req_duplex;
  3512. u16 req_line_speed = bp->req_line_speed;
  3513. u32 advertising = bp->advertising;
  3514. if (cmd->autoneg == AUTONEG_ENABLE) {
  3515. autoneg |= AUTONEG_SPEED;
  3516. cmd->advertising &= ETHTOOL_ALL_COPPER_SPEED;
  3517. /* allow advertising 1 speed */
  3518. if ((cmd->advertising == ADVERTISED_10baseT_Half) ||
  3519. (cmd->advertising == ADVERTISED_10baseT_Full) ||
  3520. (cmd->advertising == ADVERTISED_100baseT_Half) ||
  3521. (cmd->advertising == ADVERTISED_100baseT_Full)) {
  3522. if (bp->phy_flags & PHY_SERDES_FLAG)
  3523. return -EINVAL;
  3524. advertising = cmd->advertising;
  3525. }
  3526. else if (cmd->advertising == ADVERTISED_1000baseT_Full) {
  3527. advertising = cmd->advertising;
  3528. }
  3529. else if (cmd->advertising == ADVERTISED_1000baseT_Half) {
  3530. return -EINVAL;
  3531. }
  3532. else {
  3533. if (bp->phy_flags & PHY_SERDES_FLAG) {
  3534. advertising = ETHTOOL_ALL_FIBRE_SPEED;
  3535. }
  3536. else {
  3537. advertising = ETHTOOL_ALL_COPPER_SPEED;
  3538. }
  3539. }
  3540. advertising |= ADVERTISED_Autoneg;
  3541. }
  3542. else {
  3543. if (bp->phy_flags & PHY_SERDES_FLAG) {
  3544. if ((cmd->speed != SPEED_1000) ||
  3545. (cmd->duplex != DUPLEX_FULL)) {
  3546. return -EINVAL;
  3547. }
  3548. }
  3549. else if (cmd->speed == SPEED_1000) {
  3550. return -EINVAL;
  3551. }
  3552. autoneg &= ~AUTONEG_SPEED;
  3553. req_line_speed = cmd->speed;
  3554. req_duplex = cmd->duplex;
  3555. advertising = 0;
  3556. }
  3557. bp->autoneg = autoneg;
  3558. bp->advertising = advertising;
  3559. bp->req_line_speed = req_line_speed;
  3560. bp->req_duplex = req_duplex;
  3561. spin_lock_bh(&bp->phy_lock);
  3562. bnx2_setup_phy(bp);
  3563. spin_unlock_bh(&bp->phy_lock);
  3564. return 0;
  3565. }
  3566. static void
  3567. bnx2_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  3568. {
  3569. struct bnx2 *bp = dev->priv;
  3570. strcpy(info->driver, DRV_MODULE_NAME);
  3571. strcpy(info->version, DRV_MODULE_VERSION);
  3572. strcpy(info->bus_info, pci_name(bp->pdev));
  3573. info->fw_version[0] = ((bp->fw_ver & 0xff000000) >> 24) + '0';
  3574. info->fw_version[2] = ((bp->fw_ver & 0xff0000) >> 16) + '0';
  3575. info->fw_version[4] = ((bp->fw_ver & 0xff00) >> 8) + '0';
  3576. info->fw_version[6] = (bp->fw_ver & 0xff) + '0';
  3577. info->fw_version[1] = info->fw_version[3] = info->fw_version[5] = '.';
  3578. info->fw_version[7] = 0;
  3579. }
  3580. static void
  3581. bnx2_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  3582. {
  3583. struct bnx2 *bp = dev->priv;
  3584. if (bp->flags & NO_WOL_FLAG) {
  3585. wol->supported = 0;
  3586. wol->wolopts = 0;
  3587. }
  3588. else {
  3589. wol->supported = WAKE_MAGIC;
  3590. if (bp->wol)
  3591. wol->wolopts = WAKE_MAGIC;
  3592. else
  3593. wol->wolopts = 0;
  3594. }
  3595. memset(&wol->sopass, 0, sizeof(wol->sopass));
  3596. }
  3597. static int
  3598. bnx2_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  3599. {
  3600. struct bnx2 *bp = dev->priv;
  3601. if (wol->wolopts & ~WAKE_MAGIC)
  3602. return -EINVAL;
  3603. if (wol->wolopts & WAKE_MAGIC) {
  3604. if (bp->flags & NO_WOL_FLAG)
  3605. return -EINVAL;
  3606. bp->wol = 1;
  3607. }
  3608. else {
  3609. bp->wol = 0;
  3610. }
  3611. return 0;
  3612. }
  3613. static int
  3614. bnx2_nway_reset(struct net_device *dev)
  3615. {
  3616. struct bnx2 *bp = dev->priv;
  3617. u32 bmcr;
  3618. if (!(bp->autoneg & AUTONEG_SPEED)) {
  3619. return -EINVAL;
  3620. }
  3621. spin_lock_bh(&bp->phy_lock);
  3622. /* Force a link down visible on the other side */
  3623. if (bp->phy_flags & PHY_SERDES_FLAG) {
  3624. bnx2_write_phy(bp, MII_BMCR, BMCR_LOOPBACK);
  3625. spin_unlock_bh(&bp->phy_lock);
  3626. msleep(20);
  3627. spin_lock_bh(&bp->phy_lock);
  3628. if (CHIP_NUM(bp) == CHIP_NUM_5706) {
  3629. bp->current_interval = SERDES_AN_TIMEOUT;
  3630. bp->serdes_an_pending = 1;
  3631. mod_timer(&bp->timer, jiffies + bp->current_interval);
  3632. }
  3633. }
  3634. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  3635. bmcr &= ~BMCR_LOOPBACK;
  3636. bnx2_write_phy(bp, MII_BMCR, bmcr | BMCR_ANRESTART | BMCR_ANENABLE);
  3637. spin_unlock_bh(&bp->phy_lock);
  3638. return 0;
  3639. }
  3640. static int
  3641. bnx2_get_eeprom_len(struct net_device *dev)
  3642. {
  3643. struct bnx2 *bp = dev->priv;
  3644. if (bp->flash_info == 0)
  3645. return 0;
  3646. return (int) bp->flash_info->total_size;
  3647. }
  3648. static int
  3649. bnx2_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
  3650. u8 *eebuf)
  3651. {
  3652. struct bnx2 *bp = dev->priv;
  3653. int rc;
  3654. if (eeprom->offset > bp->flash_info->total_size)
  3655. return -EINVAL;
  3656. if ((eeprom->offset + eeprom->len) > bp->flash_info->total_size)
  3657. eeprom->len = bp->flash_info->total_size - eeprom->offset;
  3658. rc = bnx2_nvram_read(bp, eeprom->offset, eebuf, eeprom->len);
  3659. return rc;
  3660. }
  3661. static int
  3662. bnx2_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
  3663. u8 *eebuf)
  3664. {
  3665. struct bnx2 *bp = dev->priv;
  3666. int rc;
  3667. if (eeprom->offset > bp->flash_info->total_size)
  3668. return -EINVAL;
  3669. if ((eeprom->offset + eeprom->len) > bp->flash_info->total_size)
  3670. eeprom->len = bp->flash_info->total_size - eeprom->offset;
  3671. rc = bnx2_nvram_write(bp, eeprom->offset, eebuf, eeprom->len);
  3672. return rc;
  3673. }
  3674. static int
  3675. bnx2_get_coalesce(struct net_device *dev, struct ethtool_coalesce *coal)
  3676. {
  3677. struct bnx2 *bp = dev->priv;
  3678. memset(coal, 0, sizeof(struct ethtool_coalesce));
  3679. coal->rx_coalesce_usecs = bp->rx_ticks;
  3680. coal->rx_max_coalesced_frames = bp->rx_quick_cons_trip;
  3681. coal->rx_coalesce_usecs_irq = bp->rx_ticks_int;
  3682. coal->rx_max_coalesced_frames_irq = bp->rx_quick_cons_trip_int;
  3683. coal->tx_coalesce_usecs = bp->tx_ticks;
  3684. coal->tx_max_coalesced_frames = bp->tx_quick_cons_trip;
  3685. coal->tx_coalesce_usecs_irq = bp->tx_ticks_int;
  3686. coal->tx_max_coalesced_frames_irq = bp->tx_quick_cons_trip_int;
  3687. coal->stats_block_coalesce_usecs = bp->stats_ticks;
  3688. return 0;
  3689. }
  3690. static int
  3691. bnx2_set_coalesce(struct net_device *dev, struct ethtool_coalesce *coal)
  3692. {
  3693. struct bnx2 *bp = dev->priv;
  3694. bp->rx_ticks = (u16) coal->rx_coalesce_usecs;
  3695. if (bp->rx_ticks > 0x3ff) bp->rx_ticks = 0x3ff;
  3696. bp->rx_quick_cons_trip = (u16) coal->rx_max_coalesced_frames;
  3697. if (bp->rx_quick_cons_trip > 0xff) bp->rx_quick_cons_trip = 0xff;
  3698. bp->rx_ticks_int = (u16) coal->rx_coalesce_usecs_irq;
  3699. if (bp->rx_ticks_int > 0x3ff) bp->rx_ticks_int = 0x3ff;
  3700. bp->rx_quick_cons_trip_int = (u16) coal->rx_max_coalesced_frames_irq;
  3701. if (bp->rx_quick_cons_trip_int > 0xff)
  3702. bp->rx_quick_cons_trip_int = 0xff;
  3703. bp->tx_ticks = (u16) coal->tx_coalesce_usecs;
  3704. if (bp->tx_ticks > 0x3ff) bp->tx_ticks = 0x3ff;
  3705. bp->tx_quick_cons_trip = (u16) coal->tx_max_coalesced_frames;
  3706. if (bp->tx_quick_cons_trip > 0xff) bp->tx_quick_cons_trip = 0xff;
  3707. bp->tx_ticks_int = (u16) coal->tx_coalesce_usecs_irq;
  3708. if (bp->tx_ticks_int > 0x3ff) bp->tx_ticks_int = 0x3ff;
  3709. bp->tx_quick_cons_trip_int = (u16) coal->tx_max_coalesced_frames_irq;
  3710. if (bp->tx_quick_cons_trip_int > 0xff) bp->tx_quick_cons_trip_int =
  3711. 0xff;
  3712. bp->stats_ticks = coal->stats_block_coalesce_usecs;
  3713. if (bp->stats_ticks > 0xffff00) bp->stats_ticks = 0xffff00;
  3714. bp->stats_ticks &= 0xffff00;
  3715. if (netif_running(bp->dev)) {
  3716. bnx2_netif_stop(bp);
  3717. bnx2_init_nic(bp);
  3718. bnx2_netif_start(bp);
  3719. }
  3720. return 0;
  3721. }
  3722. static void
  3723. bnx2_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
  3724. {
  3725. struct bnx2 *bp = dev->priv;
  3726. ering->rx_max_pending = MAX_RX_DESC_CNT;
  3727. ering->rx_mini_max_pending = 0;
  3728. ering->rx_jumbo_max_pending = 0;
  3729. ering->rx_pending = bp->rx_ring_size;
  3730. ering->rx_mini_pending = 0;
  3731. ering->rx_jumbo_pending = 0;
  3732. ering->tx_max_pending = MAX_TX_DESC_CNT;
  3733. ering->tx_pending = bp->tx_ring_size;
  3734. }
  3735. static int
  3736. bnx2_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
  3737. {
  3738. struct bnx2 *bp = dev->priv;
  3739. if ((ering->rx_pending > MAX_RX_DESC_CNT) ||
  3740. (ering->tx_pending > MAX_TX_DESC_CNT) ||
  3741. (ering->tx_pending <= MAX_SKB_FRAGS)) {
  3742. return -EINVAL;
  3743. }
  3744. bp->rx_ring_size = ering->rx_pending;
  3745. bp->tx_ring_size = ering->tx_pending;
  3746. if (netif_running(bp->dev)) {
  3747. bnx2_netif_stop(bp);
  3748. bnx2_init_nic(bp);
  3749. bnx2_netif_start(bp);
  3750. }
  3751. return 0;
  3752. }
  3753. static void
  3754. bnx2_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
  3755. {
  3756. struct bnx2 *bp = dev->priv;
  3757. epause->autoneg = ((bp->autoneg & AUTONEG_FLOW_CTRL) != 0);
  3758. epause->rx_pause = ((bp->flow_ctrl & FLOW_CTRL_RX) != 0);
  3759. epause->tx_pause = ((bp->flow_ctrl & FLOW_CTRL_TX) != 0);
  3760. }
  3761. static int
  3762. bnx2_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
  3763. {
  3764. struct bnx2 *bp = dev->priv;
  3765. bp->req_flow_ctrl = 0;
  3766. if (epause->rx_pause)
  3767. bp->req_flow_ctrl |= FLOW_CTRL_RX;
  3768. if (epause->tx_pause)
  3769. bp->req_flow_ctrl |= FLOW_CTRL_TX;
  3770. if (epause->autoneg) {
  3771. bp->autoneg |= AUTONEG_FLOW_CTRL;
  3772. }
  3773. else {
  3774. bp->autoneg &= ~AUTONEG_FLOW_CTRL;
  3775. }
  3776. spin_lock_bh(&bp->phy_lock);
  3777. bnx2_setup_phy(bp);
  3778. spin_unlock_bh(&bp->phy_lock);
  3779. return 0;
  3780. }
  3781. static u32
  3782. bnx2_get_rx_csum(struct net_device *dev)
  3783. {
  3784. struct bnx2 *bp = dev->priv;
  3785. return bp->rx_csum;
  3786. }
  3787. static int
  3788. bnx2_set_rx_csum(struct net_device *dev, u32 data)
  3789. {
  3790. struct bnx2 *bp = dev->priv;
  3791. bp->rx_csum = data;
  3792. return 0;
  3793. }
  3794. #define BNX2_NUM_STATS 45
  3795. static struct {
  3796. char string[ETH_GSTRING_LEN];
  3797. } bnx2_stats_str_arr[BNX2_NUM_STATS] = {
  3798. { "rx_bytes" },
  3799. { "rx_error_bytes" },
  3800. { "tx_bytes" },
  3801. { "tx_error_bytes" },
  3802. { "rx_ucast_packets" },
  3803. { "rx_mcast_packets" },
  3804. { "rx_bcast_packets" },
  3805. { "tx_ucast_packets" },
  3806. { "tx_mcast_packets" },
  3807. { "tx_bcast_packets" },
  3808. { "tx_mac_errors" },
  3809. { "tx_carrier_errors" },
  3810. { "rx_crc_errors" },
  3811. { "rx_align_errors" },
  3812. { "tx_single_collisions" },
  3813. { "tx_multi_collisions" },
  3814. { "tx_deferred" },
  3815. { "tx_excess_collisions" },
  3816. { "tx_late_collisions" },
  3817. { "tx_total_collisions" },
  3818. { "rx_fragments" },
  3819. { "rx_jabbers" },
  3820. { "rx_undersize_packets" },
  3821. { "rx_oversize_packets" },
  3822. { "rx_64_byte_packets" },
  3823. { "rx_65_to_127_byte_packets" },
  3824. { "rx_128_to_255_byte_packets" },
  3825. { "rx_256_to_511_byte_packets" },
  3826. { "rx_512_to_1023_byte_packets" },
  3827. { "rx_1024_to_1522_byte_packets" },
  3828. { "rx_1523_to_9022_byte_packets" },
  3829. { "tx_64_byte_packets" },
  3830. { "tx_65_to_127_byte_packets" },
  3831. { "tx_128_to_255_byte_packets" },
  3832. { "tx_256_to_511_byte_packets" },
  3833. { "tx_512_to_1023_byte_packets" },
  3834. { "tx_1024_to_1522_byte_packets" },
  3835. { "tx_1523_to_9022_byte_packets" },
  3836. { "rx_xon_frames" },
  3837. { "rx_xoff_frames" },
  3838. { "tx_xon_frames" },
  3839. { "tx_xoff_frames" },
  3840. { "rx_mac_ctrl_frames" },
  3841. { "rx_filtered_packets" },
  3842. { "rx_discards" },
  3843. };
  3844. #define STATS_OFFSET32(offset_name) (offsetof(struct statistics_block, offset_name) / 4)
  3845. static unsigned long bnx2_stats_offset_arr[BNX2_NUM_STATS] = {
  3846. STATS_OFFSET32(stat_IfHCInOctets_hi),
  3847. STATS_OFFSET32(stat_IfHCInBadOctets_hi),
  3848. STATS_OFFSET32(stat_IfHCOutOctets_hi),
  3849. STATS_OFFSET32(stat_IfHCOutBadOctets_hi),
  3850. STATS_OFFSET32(stat_IfHCInUcastPkts_hi),
  3851. STATS_OFFSET32(stat_IfHCInMulticastPkts_hi),
  3852. STATS_OFFSET32(stat_IfHCInBroadcastPkts_hi),
  3853. STATS_OFFSET32(stat_IfHCOutUcastPkts_hi),
  3854. STATS_OFFSET32(stat_IfHCOutMulticastPkts_hi),
  3855. STATS_OFFSET32(stat_IfHCOutBroadcastPkts_hi),
  3856. STATS_OFFSET32(stat_emac_tx_stat_dot3statsinternalmactransmiterrors),
  3857. STATS_OFFSET32(stat_Dot3StatsCarrierSenseErrors),
  3858. STATS_OFFSET32(stat_Dot3StatsFCSErrors),
  3859. STATS_OFFSET32(stat_Dot3StatsAlignmentErrors),
  3860. STATS_OFFSET32(stat_Dot3StatsSingleCollisionFrames),
  3861. STATS_OFFSET32(stat_Dot3StatsMultipleCollisionFrames),
  3862. STATS_OFFSET32(stat_Dot3StatsDeferredTransmissions),
  3863. STATS_OFFSET32(stat_Dot3StatsExcessiveCollisions),
  3864. STATS_OFFSET32(stat_Dot3StatsLateCollisions),
  3865. STATS_OFFSET32(stat_EtherStatsCollisions),
  3866. STATS_OFFSET32(stat_EtherStatsFragments),
  3867. STATS_OFFSET32(stat_EtherStatsJabbers),
  3868. STATS_OFFSET32(stat_EtherStatsUndersizePkts),
  3869. STATS_OFFSET32(stat_EtherStatsOverrsizePkts),
  3870. STATS_OFFSET32(stat_EtherStatsPktsRx64Octets),
  3871. STATS_OFFSET32(stat_EtherStatsPktsRx65Octetsto127Octets),
  3872. STATS_OFFSET32(stat_EtherStatsPktsRx128Octetsto255Octets),
  3873. STATS_OFFSET32(stat_EtherStatsPktsRx256Octetsto511Octets),
  3874. STATS_OFFSET32(stat_EtherStatsPktsRx512Octetsto1023Octets),
  3875. STATS_OFFSET32(stat_EtherStatsPktsRx1024Octetsto1522Octets),
  3876. STATS_OFFSET32(stat_EtherStatsPktsRx1523Octetsto9022Octets),
  3877. STATS_OFFSET32(stat_EtherStatsPktsTx64Octets),
  3878. STATS_OFFSET32(stat_EtherStatsPktsTx65Octetsto127Octets),
  3879. STATS_OFFSET32(stat_EtherStatsPktsTx128Octetsto255Octets),
  3880. STATS_OFFSET32(stat_EtherStatsPktsTx256Octetsto511Octets),
  3881. STATS_OFFSET32(stat_EtherStatsPktsTx512Octetsto1023Octets),
  3882. STATS_OFFSET32(stat_EtherStatsPktsTx1024Octetsto1522Octets),
  3883. STATS_OFFSET32(stat_EtherStatsPktsTx1523Octetsto9022Octets),
  3884. STATS_OFFSET32(stat_XonPauseFramesReceived),
  3885. STATS_OFFSET32(stat_XoffPauseFramesReceived),
  3886. STATS_OFFSET32(stat_OutXonSent),
  3887. STATS_OFFSET32(stat_OutXoffSent),
  3888. STATS_OFFSET32(stat_MacControlFramesReceived),
  3889. STATS_OFFSET32(stat_IfInFramesL2FilterDiscards),
  3890. STATS_OFFSET32(stat_IfInMBUFDiscards),
  3891. };
  3892. /* stat_IfHCInBadOctets and stat_Dot3StatsCarrierSenseErrors are
  3893. * skipped because of errata.
  3894. */
  3895. static u8 bnx2_5706_stats_len_arr[BNX2_NUM_STATS] = {
  3896. 8,0,8,8,8,8,8,8,8,8,
  3897. 4,0,4,4,4,4,4,4,4,4,
  3898. 4,4,4,4,4,4,4,4,4,4,
  3899. 4,4,4,4,4,4,4,4,4,4,
  3900. 4,4,4,4,4,
  3901. };
  3902. #define BNX2_NUM_TESTS 6
  3903. static struct {
  3904. char string[ETH_GSTRING_LEN];
  3905. } bnx2_tests_str_arr[BNX2_NUM_TESTS] = {
  3906. { "register_test (offline)" },
  3907. { "memory_test (offline)" },
  3908. { "loopback_test (offline)" },
  3909. { "nvram_test (online)" },
  3910. { "interrupt_test (online)" },
  3911. { "link_test (online)" },
  3912. };
  3913. static int
  3914. bnx2_self_test_count(struct net_device *dev)
  3915. {
  3916. return BNX2_NUM_TESTS;
  3917. }
  3918. static void
  3919. bnx2_self_test(struct net_device *dev, struct ethtool_test *etest, u64 *buf)
  3920. {
  3921. struct bnx2 *bp = dev->priv;
  3922. memset(buf, 0, sizeof(u64) * BNX2_NUM_TESTS);
  3923. if (etest->flags & ETH_TEST_FL_OFFLINE) {
  3924. bnx2_netif_stop(bp);
  3925. bnx2_reset_chip(bp, BNX2_DRV_MSG_CODE_DIAG);
  3926. bnx2_free_skbs(bp);
  3927. if (bnx2_test_registers(bp) != 0) {
  3928. buf[0] = 1;
  3929. etest->flags |= ETH_TEST_FL_FAILED;
  3930. }
  3931. if (bnx2_test_memory(bp) != 0) {
  3932. buf[1] = 1;
  3933. etest->flags |= ETH_TEST_FL_FAILED;
  3934. }
  3935. if (bnx2_test_loopback(bp) != 0) {
  3936. buf[2] = 1;
  3937. etest->flags |= ETH_TEST_FL_FAILED;
  3938. }
  3939. if (!netif_running(bp->dev)) {
  3940. bnx2_reset_chip(bp, BNX2_DRV_MSG_CODE_RESET);
  3941. }
  3942. else {
  3943. bnx2_init_nic(bp);
  3944. bnx2_netif_start(bp);
  3945. }
  3946. /* wait for link up */
  3947. msleep_interruptible(3000);
  3948. if ((!bp->link_up) && !(bp->phy_flags & PHY_SERDES_FLAG))
  3949. msleep_interruptible(4000);
  3950. }
  3951. if (bnx2_test_nvram(bp) != 0) {
  3952. buf[3] = 1;
  3953. etest->flags |= ETH_TEST_FL_FAILED;
  3954. }
  3955. if (bnx2_test_intr(bp) != 0) {
  3956. buf[4] = 1;
  3957. etest->flags |= ETH_TEST_FL_FAILED;
  3958. }
  3959. if (bnx2_test_link(bp) != 0) {
  3960. buf[5] = 1;
  3961. etest->flags |= ETH_TEST_FL_FAILED;
  3962. }
  3963. }
  3964. static void
  3965. bnx2_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
  3966. {
  3967. switch (stringset) {
  3968. case ETH_SS_STATS:
  3969. memcpy(buf, bnx2_stats_str_arr,
  3970. sizeof(bnx2_stats_str_arr));
  3971. break;
  3972. case ETH_SS_TEST:
  3973. memcpy(buf, bnx2_tests_str_arr,
  3974. sizeof(bnx2_tests_str_arr));
  3975. break;
  3976. }
  3977. }
  3978. static int
  3979. bnx2_get_stats_count(struct net_device *dev)
  3980. {
  3981. return BNX2_NUM_STATS;
  3982. }
  3983. static void
  3984. bnx2_get_ethtool_stats(struct net_device *dev,
  3985. struct ethtool_stats *stats, u64 *buf)
  3986. {
  3987. struct bnx2 *bp = dev->priv;
  3988. int i;
  3989. u32 *hw_stats = (u32 *) bp->stats_blk;
  3990. u8 *stats_len_arr = NULL;
  3991. if (hw_stats == NULL) {
  3992. memset(buf, 0, sizeof(u64) * BNX2_NUM_STATS);
  3993. return;
  3994. }
  3995. if (CHIP_NUM(bp) == CHIP_NUM_5706)
  3996. stats_len_arr = bnx2_5706_stats_len_arr;
  3997. for (i = 0; i < BNX2_NUM_STATS; i++) {
  3998. if (stats_len_arr[i] == 0) {
  3999. /* skip this counter */
  4000. buf[i] = 0;
  4001. continue;
  4002. }
  4003. if (stats_len_arr[i] == 4) {
  4004. /* 4-byte counter */
  4005. buf[i] = (u64)
  4006. *(hw_stats + bnx2_stats_offset_arr[i]);
  4007. continue;
  4008. }
  4009. /* 8-byte counter */
  4010. buf[i] = (((u64) *(hw_stats +
  4011. bnx2_stats_offset_arr[i])) << 32) +
  4012. *(hw_stats + bnx2_stats_offset_arr[i] + 1);
  4013. }
  4014. }
  4015. static int
  4016. bnx2_phys_id(struct net_device *dev, u32 data)
  4017. {
  4018. struct bnx2 *bp = dev->priv;
  4019. int i;
  4020. u32 save;
  4021. if (data == 0)
  4022. data = 2;
  4023. save = REG_RD(bp, BNX2_MISC_CFG);
  4024. REG_WR(bp, BNX2_MISC_CFG, BNX2_MISC_CFG_LEDMODE_MAC);
  4025. for (i = 0; i < (data * 2); i++) {
  4026. if ((i % 2) == 0) {
  4027. REG_WR(bp, BNX2_EMAC_LED, BNX2_EMAC_LED_OVERRIDE);
  4028. }
  4029. else {
  4030. REG_WR(bp, BNX2_EMAC_LED, BNX2_EMAC_LED_OVERRIDE |
  4031. BNX2_EMAC_LED_1000MB_OVERRIDE |
  4032. BNX2_EMAC_LED_100MB_OVERRIDE |
  4033. BNX2_EMAC_LED_10MB_OVERRIDE |
  4034. BNX2_EMAC_LED_TRAFFIC_OVERRIDE |
  4035. BNX2_EMAC_LED_TRAFFIC);
  4036. }
  4037. msleep_interruptible(500);
  4038. if (signal_pending(current))
  4039. break;
  4040. }
  4041. REG_WR(bp, BNX2_EMAC_LED, 0);
  4042. REG_WR(bp, BNX2_MISC_CFG, save);
  4043. return 0;
  4044. }
  4045. static struct ethtool_ops bnx2_ethtool_ops = {
  4046. .get_settings = bnx2_get_settings,
  4047. .set_settings = bnx2_set_settings,
  4048. .get_drvinfo = bnx2_get_drvinfo,
  4049. .get_wol = bnx2_get_wol,
  4050. .set_wol = bnx2_set_wol,
  4051. .nway_reset = bnx2_nway_reset,
  4052. .get_link = ethtool_op_get_link,
  4053. .get_eeprom_len = bnx2_get_eeprom_len,
  4054. .get_eeprom = bnx2_get_eeprom,
  4055. .set_eeprom = bnx2_set_eeprom,
  4056. .get_coalesce = bnx2_get_coalesce,
  4057. .set_coalesce = bnx2_set_coalesce,
  4058. .get_ringparam = bnx2_get_ringparam,
  4059. .set_ringparam = bnx2_set_ringparam,
  4060. .get_pauseparam = bnx2_get_pauseparam,
  4061. .set_pauseparam = bnx2_set_pauseparam,
  4062. .get_rx_csum = bnx2_get_rx_csum,
  4063. .set_rx_csum = bnx2_set_rx_csum,
  4064. .get_tx_csum = ethtool_op_get_tx_csum,
  4065. .set_tx_csum = ethtool_op_set_tx_csum,
  4066. .get_sg = ethtool_op_get_sg,
  4067. .set_sg = ethtool_op_set_sg,
  4068. #ifdef BCM_TSO
  4069. .get_tso = ethtool_op_get_tso,
  4070. .set_tso = ethtool_op_set_tso,
  4071. #endif
  4072. .self_test_count = bnx2_self_test_count,
  4073. .self_test = bnx2_self_test,
  4074. .get_strings = bnx2_get_strings,
  4075. .phys_id = bnx2_phys_id,
  4076. .get_stats_count = bnx2_get_stats_count,
  4077. .get_ethtool_stats = bnx2_get_ethtool_stats,
  4078. .get_perm_addr = ethtool_op_get_perm_addr,
  4079. };
  4080. /* Called with rtnl_lock */
  4081. static int
  4082. bnx2_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  4083. {
  4084. struct mii_ioctl_data *data = if_mii(ifr);
  4085. struct bnx2 *bp = dev->priv;
  4086. int err;
  4087. switch(cmd) {
  4088. case SIOCGMIIPHY:
  4089. data->phy_id = bp->phy_addr;
  4090. /* fallthru */
  4091. case SIOCGMIIREG: {
  4092. u32 mii_regval;
  4093. spin_lock_bh(&bp->phy_lock);
  4094. err = bnx2_read_phy(bp, data->reg_num & 0x1f, &mii_regval);
  4095. spin_unlock_bh(&bp->phy_lock);
  4096. data->val_out = mii_regval;
  4097. return err;
  4098. }
  4099. case SIOCSMIIREG:
  4100. if (!capable(CAP_NET_ADMIN))
  4101. return -EPERM;
  4102. spin_lock_bh(&bp->phy_lock);
  4103. err = bnx2_write_phy(bp, data->reg_num & 0x1f, data->val_in);
  4104. spin_unlock_bh(&bp->phy_lock);
  4105. return err;
  4106. default:
  4107. /* do nothing */
  4108. break;
  4109. }
  4110. return -EOPNOTSUPP;
  4111. }
  4112. /* Called with rtnl_lock */
  4113. static int
  4114. bnx2_change_mac_addr(struct net_device *dev, void *p)
  4115. {
  4116. struct sockaddr *addr = p;
  4117. struct bnx2 *bp = dev->priv;
  4118. if (!is_valid_ether_addr(addr->sa_data))
  4119. return -EINVAL;
  4120. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  4121. if (netif_running(dev))
  4122. bnx2_set_mac_addr(bp);
  4123. return 0;
  4124. }
  4125. /* Called with rtnl_lock */
  4126. static int
  4127. bnx2_change_mtu(struct net_device *dev, int new_mtu)
  4128. {
  4129. struct bnx2 *bp = dev->priv;
  4130. if (((new_mtu + ETH_HLEN) > MAX_ETHERNET_JUMBO_PACKET_SIZE) ||
  4131. ((new_mtu + ETH_HLEN) < MIN_ETHERNET_PACKET_SIZE))
  4132. return -EINVAL;
  4133. dev->mtu = new_mtu;
  4134. if (netif_running(dev)) {
  4135. bnx2_netif_stop(bp);
  4136. bnx2_init_nic(bp);
  4137. bnx2_netif_start(bp);
  4138. }
  4139. return 0;
  4140. }
  4141. #if defined(HAVE_POLL_CONTROLLER) || defined(CONFIG_NET_POLL_CONTROLLER)
  4142. static void
  4143. poll_bnx2(struct net_device *dev)
  4144. {
  4145. struct bnx2 *bp = dev->priv;
  4146. disable_irq(bp->pdev->irq);
  4147. bnx2_interrupt(bp->pdev->irq, dev, NULL);
  4148. enable_irq(bp->pdev->irq);
  4149. }
  4150. #endif
  4151. static int __devinit
  4152. bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
  4153. {
  4154. struct bnx2 *bp;
  4155. unsigned long mem_len;
  4156. int rc;
  4157. u32 reg;
  4158. SET_MODULE_OWNER(dev);
  4159. SET_NETDEV_DEV(dev, &pdev->dev);
  4160. bp = dev->priv;
  4161. bp->flags = 0;
  4162. bp->phy_flags = 0;
  4163. /* enable device (incl. PCI PM wakeup), and bus-mastering */
  4164. rc = pci_enable_device(pdev);
  4165. if (rc) {
  4166. printk(KERN_ERR PFX "Cannot enable PCI device, aborting.");
  4167. goto err_out;
  4168. }
  4169. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  4170. printk(KERN_ERR PFX "Cannot find PCI device base address, "
  4171. "aborting.\n");
  4172. rc = -ENODEV;
  4173. goto err_out_disable;
  4174. }
  4175. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  4176. if (rc) {
  4177. printk(KERN_ERR PFX "Cannot obtain PCI resources, aborting.\n");
  4178. goto err_out_disable;
  4179. }
  4180. pci_set_master(pdev);
  4181. bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  4182. if (bp->pm_cap == 0) {
  4183. printk(KERN_ERR PFX "Cannot find power management capability, "
  4184. "aborting.\n");
  4185. rc = -EIO;
  4186. goto err_out_release;
  4187. }
  4188. bp->pcix_cap = pci_find_capability(pdev, PCI_CAP_ID_PCIX);
  4189. if (bp->pcix_cap == 0) {
  4190. printk(KERN_ERR PFX "Cannot find PCIX capability, aborting.\n");
  4191. rc = -EIO;
  4192. goto err_out_release;
  4193. }
  4194. if (pci_set_dma_mask(pdev, DMA_64BIT_MASK) == 0) {
  4195. bp->flags |= USING_DAC_FLAG;
  4196. if (pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK) != 0) {
  4197. printk(KERN_ERR PFX "pci_set_consistent_dma_mask "
  4198. "failed, aborting.\n");
  4199. rc = -EIO;
  4200. goto err_out_release;
  4201. }
  4202. }
  4203. else if (pci_set_dma_mask(pdev, DMA_32BIT_MASK) != 0) {
  4204. printk(KERN_ERR PFX "System does not support DMA, aborting.\n");
  4205. rc = -EIO;
  4206. goto err_out_release;
  4207. }
  4208. bp->dev = dev;
  4209. bp->pdev = pdev;
  4210. spin_lock_init(&bp->phy_lock);
  4211. spin_lock_init(&bp->tx_lock);
  4212. INIT_WORK(&bp->reset_task, bnx2_reset_task, bp);
  4213. dev->base_addr = dev->mem_start = pci_resource_start(pdev, 0);
  4214. mem_len = MB_GET_CID_ADDR(17);
  4215. dev->mem_end = dev->mem_start + mem_len;
  4216. dev->irq = pdev->irq;
  4217. bp->regview = ioremap_nocache(dev->base_addr, mem_len);
  4218. if (!bp->regview) {
  4219. printk(KERN_ERR PFX "Cannot map register space, aborting.\n");
  4220. rc = -ENOMEM;
  4221. goto err_out_release;
  4222. }
  4223. /* Configure byte swap and enable write to the reg_window registers.
  4224. * Rely on CPU to do target byte swapping on big endian systems
  4225. * The chip's target access swapping will not swap all accesses
  4226. */
  4227. pci_write_config_dword(bp->pdev, BNX2_PCICFG_MISC_CONFIG,
  4228. BNX2_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
  4229. BNX2_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP);
  4230. bnx2_set_power_state(bp, PCI_D0);
  4231. bp->chip_id = REG_RD(bp, BNX2_MISC_ID);
  4232. bp->phy_addr = 1;
  4233. /* Get bus information. */
  4234. reg = REG_RD(bp, BNX2_PCICFG_MISC_STATUS);
  4235. if (reg & BNX2_PCICFG_MISC_STATUS_PCIX_DET) {
  4236. u32 clkreg;
  4237. bp->flags |= PCIX_FLAG;
  4238. clkreg = REG_RD(bp, BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS);
  4239. clkreg &= BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET;
  4240. switch (clkreg) {
  4241. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_133MHZ:
  4242. bp->bus_speed_mhz = 133;
  4243. break;
  4244. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_95MHZ:
  4245. bp->bus_speed_mhz = 100;
  4246. break;
  4247. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_66MHZ:
  4248. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_80MHZ:
  4249. bp->bus_speed_mhz = 66;
  4250. break;
  4251. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_48MHZ:
  4252. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_55MHZ:
  4253. bp->bus_speed_mhz = 50;
  4254. break;
  4255. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_LOW:
  4256. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_32MHZ:
  4257. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_38MHZ:
  4258. bp->bus_speed_mhz = 33;
  4259. break;
  4260. }
  4261. }
  4262. else {
  4263. if (reg & BNX2_PCICFG_MISC_STATUS_M66EN)
  4264. bp->bus_speed_mhz = 66;
  4265. else
  4266. bp->bus_speed_mhz = 33;
  4267. }
  4268. if (reg & BNX2_PCICFG_MISC_STATUS_32BIT_DET)
  4269. bp->flags |= PCI_32BIT_FLAG;
  4270. /* 5706A0 may falsely detect SERR and PERR. */
  4271. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  4272. reg = REG_RD(bp, PCI_COMMAND);
  4273. reg &= ~(PCI_COMMAND_SERR | PCI_COMMAND_PARITY);
  4274. REG_WR(bp, PCI_COMMAND, reg);
  4275. }
  4276. else if ((CHIP_ID(bp) == CHIP_ID_5706_A1) &&
  4277. !(bp->flags & PCIX_FLAG)) {
  4278. printk(KERN_ERR PFX "5706 A1 can only be used in a PCIX bus, "
  4279. "aborting.\n");
  4280. goto err_out_unmap;
  4281. }
  4282. bnx2_init_nvram(bp);
  4283. /* Get the permanent MAC address. First we need to make sure the
  4284. * firmware is actually running.
  4285. */
  4286. reg = REG_RD_IND(bp, HOST_VIEW_SHMEM_BASE + BNX2_DEV_INFO_SIGNATURE);
  4287. if ((reg & BNX2_DEV_INFO_SIGNATURE_MAGIC_MASK) !=
  4288. BNX2_DEV_INFO_SIGNATURE_MAGIC) {
  4289. printk(KERN_ERR PFX "Firmware not running, aborting.\n");
  4290. rc = -ENODEV;
  4291. goto err_out_unmap;
  4292. }
  4293. bp->fw_ver = REG_RD_IND(bp, HOST_VIEW_SHMEM_BASE +
  4294. BNX2_DEV_INFO_BC_REV);
  4295. reg = REG_RD_IND(bp, HOST_VIEW_SHMEM_BASE + BNX2_PORT_HW_CFG_MAC_UPPER);
  4296. bp->mac_addr[0] = (u8) (reg >> 8);
  4297. bp->mac_addr[1] = (u8) reg;
  4298. reg = REG_RD_IND(bp, HOST_VIEW_SHMEM_BASE + BNX2_PORT_HW_CFG_MAC_LOWER);
  4299. bp->mac_addr[2] = (u8) (reg >> 24);
  4300. bp->mac_addr[3] = (u8) (reg >> 16);
  4301. bp->mac_addr[4] = (u8) (reg >> 8);
  4302. bp->mac_addr[5] = (u8) reg;
  4303. bp->tx_ring_size = MAX_TX_DESC_CNT;
  4304. bp->rx_ring_size = 100;
  4305. bp->rx_csum = 1;
  4306. bp->rx_offset = sizeof(struct l2_fhdr) + 2;
  4307. bp->tx_quick_cons_trip_int = 20;
  4308. bp->tx_quick_cons_trip = 20;
  4309. bp->tx_ticks_int = 80;
  4310. bp->tx_ticks = 80;
  4311. bp->rx_quick_cons_trip_int = 6;
  4312. bp->rx_quick_cons_trip = 6;
  4313. bp->rx_ticks_int = 18;
  4314. bp->rx_ticks = 18;
  4315. bp->stats_ticks = 1000000 & 0xffff00;
  4316. bp->timer_interval = HZ;
  4317. bp->current_interval = HZ;
  4318. /* Disable WOL support if we are running on a SERDES chip. */
  4319. if (CHIP_BOND_ID(bp) & CHIP_BOND_ID_SERDES_BIT) {
  4320. bp->phy_flags |= PHY_SERDES_FLAG;
  4321. bp->flags |= NO_WOL_FLAG;
  4322. }
  4323. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  4324. bp->tx_quick_cons_trip_int =
  4325. bp->tx_quick_cons_trip;
  4326. bp->tx_ticks_int = bp->tx_ticks;
  4327. bp->rx_quick_cons_trip_int =
  4328. bp->rx_quick_cons_trip;
  4329. bp->rx_ticks_int = bp->rx_ticks;
  4330. bp->comp_prod_trip_int = bp->comp_prod_trip;
  4331. bp->com_ticks_int = bp->com_ticks;
  4332. bp->cmd_ticks_int = bp->cmd_ticks;
  4333. }
  4334. bp->autoneg = AUTONEG_SPEED | AUTONEG_FLOW_CTRL;
  4335. bp->req_line_speed = 0;
  4336. if (bp->phy_flags & PHY_SERDES_FLAG) {
  4337. bp->advertising = ETHTOOL_ALL_FIBRE_SPEED | ADVERTISED_Autoneg;
  4338. reg = REG_RD_IND(bp, HOST_VIEW_SHMEM_BASE +
  4339. BNX2_PORT_HW_CFG_CONFIG);
  4340. reg &= BNX2_PORT_HW_CFG_CFG_DFLT_LINK_MASK;
  4341. if (reg == BNX2_PORT_HW_CFG_CFG_DFLT_LINK_1G) {
  4342. bp->autoneg = 0;
  4343. bp->req_line_speed = bp->line_speed = SPEED_1000;
  4344. bp->req_duplex = DUPLEX_FULL;
  4345. }
  4346. }
  4347. else {
  4348. bp->advertising = ETHTOOL_ALL_COPPER_SPEED | ADVERTISED_Autoneg;
  4349. }
  4350. bp->req_flow_ctrl = FLOW_CTRL_RX | FLOW_CTRL_TX;
  4351. init_timer(&bp->timer);
  4352. bp->timer.expires = RUN_AT(bp->timer_interval);
  4353. bp->timer.data = (unsigned long) bp;
  4354. bp->timer.function = bnx2_timer;
  4355. return 0;
  4356. err_out_unmap:
  4357. if (bp->regview) {
  4358. iounmap(bp->regview);
  4359. bp->regview = NULL;
  4360. }
  4361. err_out_release:
  4362. pci_release_regions(pdev);
  4363. err_out_disable:
  4364. pci_disable_device(pdev);
  4365. pci_set_drvdata(pdev, NULL);
  4366. err_out:
  4367. return rc;
  4368. }
  4369. static int __devinit
  4370. bnx2_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
  4371. {
  4372. static int version_printed = 0;
  4373. struct net_device *dev = NULL;
  4374. struct bnx2 *bp;
  4375. int rc, i;
  4376. if (version_printed++ == 0)
  4377. printk(KERN_INFO "%s", version);
  4378. /* dev zeroed in init_etherdev */
  4379. dev = alloc_etherdev(sizeof(*bp));
  4380. if (!dev)
  4381. return -ENOMEM;
  4382. rc = bnx2_init_board(pdev, dev);
  4383. if (rc < 0) {
  4384. free_netdev(dev);
  4385. return rc;
  4386. }
  4387. dev->open = bnx2_open;
  4388. dev->hard_start_xmit = bnx2_start_xmit;
  4389. dev->stop = bnx2_close;
  4390. dev->get_stats = bnx2_get_stats;
  4391. dev->set_multicast_list = bnx2_set_rx_mode;
  4392. dev->do_ioctl = bnx2_ioctl;
  4393. dev->set_mac_address = bnx2_change_mac_addr;
  4394. dev->change_mtu = bnx2_change_mtu;
  4395. dev->tx_timeout = bnx2_tx_timeout;
  4396. dev->watchdog_timeo = TX_TIMEOUT;
  4397. #ifdef BCM_VLAN
  4398. dev->vlan_rx_register = bnx2_vlan_rx_register;
  4399. dev->vlan_rx_kill_vid = bnx2_vlan_rx_kill_vid;
  4400. #endif
  4401. dev->poll = bnx2_poll;
  4402. dev->ethtool_ops = &bnx2_ethtool_ops;
  4403. dev->weight = 64;
  4404. bp = dev->priv;
  4405. #if defined(HAVE_POLL_CONTROLLER) || defined(CONFIG_NET_POLL_CONTROLLER)
  4406. dev->poll_controller = poll_bnx2;
  4407. #endif
  4408. if ((rc = register_netdev(dev))) {
  4409. printk(KERN_ERR PFX "Cannot register net device\n");
  4410. if (bp->regview)
  4411. iounmap(bp->regview);
  4412. pci_release_regions(pdev);
  4413. pci_disable_device(pdev);
  4414. pci_set_drvdata(pdev, NULL);
  4415. free_netdev(dev);
  4416. return rc;
  4417. }
  4418. pci_set_drvdata(pdev, dev);
  4419. memcpy(dev->dev_addr, bp->mac_addr, 6);
  4420. memcpy(dev->perm_addr, bp->mac_addr, 6);
  4421. bp->name = board_info[ent->driver_data].name,
  4422. printk(KERN_INFO "%s: %s (%c%d) PCI%s %s %dMHz found at mem %lx, "
  4423. "IRQ %d, ",
  4424. dev->name,
  4425. bp->name,
  4426. ((CHIP_ID(bp) & 0xf000) >> 12) + 'A',
  4427. ((CHIP_ID(bp) & 0x0ff0) >> 4),
  4428. ((bp->flags & PCIX_FLAG) ? "-X" : ""),
  4429. ((bp->flags & PCI_32BIT_FLAG) ? "32-bit" : "64-bit"),
  4430. bp->bus_speed_mhz,
  4431. dev->base_addr,
  4432. bp->pdev->irq);
  4433. printk("node addr ");
  4434. for (i = 0; i < 6; i++)
  4435. printk("%2.2x", dev->dev_addr[i]);
  4436. printk("\n");
  4437. dev->features |= NETIF_F_SG;
  4438. if (bp->flags & USING_DAC_FLAG)
  4439. dev->features |= NETIF_F_HIGHDMA;
  4440. dev->features |= NETIF_F_IP_CSUM;
  4441. #ifdef BCM_VLAN
  4442. dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
  4443. #endif
  4444. #ifdef BCM_TSO
  4445. dev->features |= NETIF_F_TSO;
  4446. #endif
  4447. netif_carrier_off(bp->dev);
  4448. return 0;
  4449. }
  4450. static void __devexit
  4451. bnx2_remove_one(struct pci_dev *pdev)
  4452. {
  4453. struct net_device *dev = pci_get_drvdata(pdev);
  4454. struct bnx2 *bp = dev->priv;
  4455. flush_scheduled_work();
  4456. unregister_netdev(dev);
  4457. if (bp->regview)
  4458. iounmap(bp->regview);
  4459. free_netdev(dev);
  4460. pci_release_regions(pdev);
  4461. pci_disable_device(pdev);
  4462. pci_set_drvdata(pdev, NULL);
  4463. }
  4464. static int
  4465. bnx2_suspend(struct pci_dev *pdev, pm_message_t state)
  4466. {
  4467. struct net_device *dev = pci_get_drvdata(pdev);
  4468. struct bnx2 *bp = dev->priv;
  4469. u32 reset_code;
  4470. if (!netif_running(dev))
  4471. return 0;
  4472. bnx2_netif_stop(bp);
  4473. netif_device_detach(dev);
  4474. del_timer_sync(&bp->timer);
  4475. if (bp->wol)
  4476. reset_code = BNX2_DRV_MSG_CODE_SUSPEND_WOL;
  4477. else
  4478. reset_code = BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL;
  4479. bnx2_reset_chip(bp, reset_code);
  4480. bnx2_free_skbs(bp);
  4481. bnx2_set_power_state(bp, pci_choose_state(pdev, state));
  4482. return 0;
  4483. }
  4484. static int
  4485. bnx2_resume(struct pci_dev *pdev)
  4486. {
  4487. struct net_device *dev = pci_get_drvdata(pdev);
  4488. struct bnx2 *bp = dev->priv;
  4489. if (!netif_running(dev))
  4490. return 0;
  4491. bnx2_set_power_state(bp, PCI_D0);
  4492. netif_device_attach(dev);
  4493. bnx2_init_nic(bp);
  4494. bnx2_netif_start(bp);
  4495. return 0;
  4496. }
  4497. static struct pci_driver bnx2_pci_driver = {
  4498. .name = DRV_MODULE_NAME,
  4499. .id_table = bnx2_pci_tbl,
  4500. .probe = bnx2_init_one,
  4501. .remove = __devexit_p(bnx2_remove_one),
  4502. .suspend = bnx2_suspend,
  4503. .resume = bnx2_resume,
  4504. };
  4505. static int __init bnx2_init(void)
  4506. {
  4507. return pci_module_init(&bnx2_pci_driver);
  4508. }
  4509. static void __exit bnx2_cleanup(void)
  4510. {
  4511. pci_unregister_driver(&bnx2_pci_driver);
  4512. }
  4513. module_init(bnx2_init);
  4514. module_exit(bnx2_cleanup);