de4x5.c 164 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582
  1. /* de4x5.c: A DIGITAL DC21x4x DECchip and DE425/DE434/DE435/DE450/DE500
  2. ethernet driver for Linux.
  3. Copyright 1994, 1995 Digital Equipment Corporation.
  4. Testing resources for this driver have been made available
  5. in part by NASA Ames Research Center (mjacob@nas.nasa.gov).
  6. The author may be reached at davies@maniac.ultranet.com.
  7. This program is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2 of the License, or (at your
  10. option) any later version.
  11. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  12. WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  13. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  14. NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  15. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  16. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  17. USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  18. ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  19. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  20. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  21. You should have received a copy of the GNU General Public License along
  22. with this program; if not, write to the Free Software Foundation, Inc.,
  23. 675 Mass Ave, Cambridge, MA 02139, USA.
  24. Originally, this driver was written for the Digital Equipment
  25. Corporation series of EtherWORKS ethernet cards:
  26. DE425 TP/COAX EISA
  27. DE434 TP PCI
  28. DE435 TP/COAX/AUI PCI
  29. DE450 TP/COAX/AUI PCI
  30. DE500 10/100 PCI Fasternet
  31. but it will now attempt to support all cards which conform to the
  32. Digital Semiconductor SROM Specification. The driver currently
  33. recognises the following chips:
  34. DC21040 (no SROM)
  35. DC21041[A]
  36. DC21140[A]
  37. DC21142
  38. DC21143
  39. So far the driver is known to work with the following cards:
  40. KINGSTON
  41. Linksys
  42. ZNYX342
  43. SMC8432
  44. SMC9332 (w/new SROM)
  45. ZNYX31[45]
  46. ZNYX346 10/100 4 port (can act as a 10/100 bridge!)
  47. The driver has been tested on a relatively busy network using the DE425,
  48. DE434, DE435 and DE500 cards and benchmarked with 'ttcp': it transferred
  49. 16M of data to a DECstation 5000/200 as follows:
  50. TCP UDP
  51. TX RX TX RX
  52. DE425 1030k 997k 1170k 1128k
  53. DE434 1063k 995k 1170k 1125k
  54. DE435 1063k 995k 1170k 1125k
  55. DE500 1063k 998k 1170k 1125k in 10Mb/s mode
  56. All values are typical (in kBytes/sec) from a sample of 4 for each
  57. measurement. Their error is +/-20k on a quiet (private) network and also
  58. depend on what load the CPU has.
  59. =========================================================================
  60. This driver has been written substantially from scratch, although its
  61. inheritance of style and stack interface from 'ewrk3.c' and in turn from
  62. Donald Becker's 'lance.c' should be obvious. With the module autoload of
  63. every usable DECchip board, I pinched Donald's 'next_module' field to
  64. link my modules together.
  65. Up to 15 EISA cards can be supported under this driver, limited primarily
  66. by the available IRQ lines. I have checked different configurations of
  67. multiple depca, EtherWORKS 3 cards and de4x5 cards and have not found a
  68. problem yet (provided you have at least depca.c v0.38) ...
  69. PCI support has been added to allow the driver to work with the DE434,
  70. DE435, DE450 and DE500 cards. The I/O accesses are a bit of a kludge due
  71. to the differences in the EISA and PCI CSR address offsets from the base
  72. address.
  73. The ability to load this driver as a loadable module has been included
  74. and used extensively during the driver development (to save those long
  75. reboot sequences). Loadable module support under PCI and EISA has been
  76. achieved by letting the driver autoprobe as if it were compiled into the
  77. kernel. Do make sure you're not sharing interrupts with anything that
  78. cannot accommodate interrupt sharing!
  79. To utilise this ability, you have to do 8 things:
  80. 0) have a copy of the loadable modules code installed on your system.
  81. 1) copy de4x5.c from the /linux/drivers/net directory to your favourite
  82. temporary directory.
  83. 2) for fixed autoprobes (not recommended), edit the source code near
  84. line 5594 to reflect the I/O address you're using, or assign these when
  85. loading by:
  86. insmod de4x5 io=0xghh where g = bus number
  87. hh = device number
  88. NB: autoprobing for modules is now supported by default. You may just
  89. use:
  90. insmod de4x5
  91. to load all available boards. For a specific board, still use
  92. the 'io=?' above.
  93. 3) compile de4x5.c, but include -DMODULE in the command line to ensure
  94. that the correct bits are compiled (see end of source code).
  95. 4) if you are wanting to add a new card, goto 5. Otherwise, recompile a
  96. kernel with the de4x5 configuration turned off and reboot.
  97. 5) insmod de4x5 [io=0xghh]
  98. 6) run the net startup bits for your new eth?? interface(s) manually
  99. (usually /etc/rc.inet[12] at boot time).
  100. 7) enjoy!
  101. To unload a module, turn off the associated interface(s)
  102. 'ifconfig eth?? down' then 'rmmod de4x5'.
  103. Automedia detection is included so that in principal you can disconnect
  104. from, e.g. TP, reconnect to BNC and things will still work (after a
  105. pause whilst the driver figures out where its media went). My tests
  106. using ping showed that it appears to work....
  107. By default, the driver will now autodetect any DECchip based card.
  108. Should you have a need to restrict the driver to DIGITAL only cards, you
  109. can compile with a DEC_ONLY define, or if loading as a module, use the
  110. 'dec_only=1' parameter.
  111. I've changed the timing routines to use the kernel timer and scheduling
  112. functions so that the hangs and other assorted problems that occurred
  113. while autosensing the media should be gone. A bonus for the DC21040
  114. auto media sense algorithm is that it can now use one that is more in
  115. line with the rest (the DC21040 chip doesn't have a hardware timer).
  116. The downside is the 1 'jiffies' (10ms) resolution.
  117. IEEE 802.3u MII interface code has been added in anticipation that some
  118. products may use it in the future.
  119. The SMC9332 card has a non-compliant SROM which needs fixing - I have
  120. patched this driver to detect it because the SROM format used complies
  121. to a previous DEC-STD format.
  122. I have removed the buffer copies needed for receive on Intels. I cannot
  123. remove them for Alphas since the Tulip hardware only does longword
  124. aligned DMA transfers and the Alphas get alignment traps with non
  125. longword aligned data copies (which makes them really slow). No comment.
  126. I have added SROM decoding routines to make this driver work with any
  127. card that supports the Digital Semiconductor SROM spec. This will help
  128. all cards running the dc2114x series chips in particular. Cards using
  129. the dc2104x chips should run correctly with the basic driver. I'm in
  130. debt to <mjacob@feral.com> for the testing and feedback that helped get
  131. this feature working. So far we have tested KINGSTON, SMC8432, SMC9332
  132. (with the latest SROM complying with the SROM spec V3: their first was
  133. broken), ZNYX342 and LinkSys. ZYNX314 (dual 21041 MAC) and ZNYX 315
  134. (quad 21041 MAC) cards also appear to work despite their incorrectly
  135. wired IRQs.
  136. I have added a temporary fix for interrupt problems when some SCSI cards
  137. share the same interrupt as the DECchip based cards. The problem occurs
  138. because the SCSI card wants to grab the interrupt as a fast interrupt
  139. (runs the service routine with interrupts turned off) vs. this card
  140. which really needs to run the service routine with interrupts turned on.
  141. This driver will now add the interrupt service routine as a fast
  142. interrupt if it is bounced from the slow interrupt. THIS IS NOT A
  143. RECOMMENDED WAY TO RUN THE DRIVER and has been done for a limited time
  144. until people sort out their compatibility issues and the kernel
  145. interrupt service code is fixed. YOU SHOULD SEPARATE OUT THE FAST
  146. INTERRUPT CARDS FROM THE SLOW INTERRUPT CARDS to ensure that they do not
  147. run on the same interrupt. PCMCIA/CardBus is another can of worms...
  148. Finally, I think I have really fixed the module loading problem with
  149. more than one DECchip based card. As a side effect, I don't mess with
  150. the device structure any more which means that if more than 1 card in
  151. 2.0.x is installed (4 in 2.1.x), the user will have to edit
  152. linux/drivers/net/Space.c to make room for them. Hence, module loading
  153. is the preferred way to use this driver, since it doesn't have this
  154. limitation.
  155. Where SROM media detection is used and full duplex is specified in the
  156. SROM, the feature is ignored unless lp->params.fdx is set at compile
  157. time OR during a module load (insmod de4x5 args='eth??:fdx' [see
  158. below]). This is because there is no way to automatically detect full
  159. duplex links except through autonegotiation. When I include the
  160. autonegotiation feature in the SROM autoconf code, this detection will
  161. occur automatically for that case.
  162. Command line arguments are now allowed, similar to passing arguments
  163. through LILO. This will allow a per adapter board set up of full duplex
  164. and media. The only lexical constraints are: the board name (dev->name)
  165. appears in the list before its parameters. The list of parameters ends
  166. either at the end of the parameter list or with another board name. The
  167. following parameters are allowed:
  168. fdx for full duplex
  169. autosense to set the media/speed; with the following
  170. sub-parameters:
  171. TP, TP_NW, BNC, AUI, BNC_AUI, 100Mb, 10Mb, AUTO
  172. Case sensitivity is important for the sub-parameters. They *must* be
  173. upper case. Examples:
  174. insmod de4x5 args='eth1:fdx autosense=BNC eth0:autosense=100Mb'.
  175. For a compiled in driver, at or above line 548, place e.g.
  176. #define DE4X5_PARM "eth0:fdx autosense=AUI eth2:autosense=TP"
  177. Yes, I know full duplex isn't permissible on BNC or AUI; they're just
  178. examples. By default, full duplex is turned off and AUTO is the default
  179. autosense setting. In reality, I expect only the full duplex option to
  180. be used. Note the use of single quotes in the two examples above and the
  181. lack of commas to separate items. ALSO, you must get the requested media
  182. correct in relation to what the adapter SROM says it has. There's no way
  183. to determine this in advance other than by trial and error and common
  184. sense, e.g. call a BNC connectored port 'BNC', not '10Mb'.
  185. Changed the bus probing. EISA used to be done first, followed by PCI.
  186. Most people probably don't even know what a de425 is today and the EISA
  187. probe has messed up some SCSI cards in the past, so now PCI is always
  188. probed first followed by EISA if a) the architecture allows EISA and
  189. either b) there have been no PCI cards detected or c) an EISA probe is
  190. forced by the user. To force a probe include "force_eisa" in your
  191. insmod "args" line; for built-in kernels either change the driver to do
  192. this automatically or include #define DE4X5_FORCE_EISA on or before
  193. line 1040 in the driver.
  194. TO DO:
  195. ------
  196. Revision History
  197. ----------------
  198. Version Date Description
  199. 0.1 17-Nov-94 Initial writing. ALPHA code release.
  200. 0.2 13-Jan-95 Added PCI support for DE435's.
  201. 0.21 19-Jan-95 Added auto media detection.
  202. 0.22 10-Feb-95 Fix interrupt handler call <chris@cosy.sbg.ac.at>.
  203. Fix recognition bug reported by <bkm@star.rl.ac.uk>.
  204. Add request/release_region code.
  205. Add loadable modules support for PCI.
  206. Clean up loadable modules support.
  207. 0.23 28-Feb-95 Added DC21041 and DC21140 support.
  208. Fix missed frame counter value and initialisation.
  209. Fixed EISA probe.
  210. 0.24 11-Apr-95 Change delay routine to use <linux/udelay>.
  211. Change TX_BUFFS_AVAIL macro.
  212. Change media autodetection to allow manual setting.
  213. Completed DE500 (DC21140) support.
  214. 0.241 18-Apr-95 Interim release without DE500 Autosense Algorithm.
  215. 0.242 10-May-95 Minor changes.
  216. 0.30 12-Jun-95 Timer fix for DC21140.
  217. Portability changes.
  218. Add ALPHA changes from <jestabro@ant.tay1.dec.com>.
  219. Add DE500 semi automatic autosense.
  220. Add Link Fail interrupt TP failure detection.
  221. Add timer based link change detection.
  222. Plugged a memory leak in de4x5_queue_pkt().
  223. 0.31 13-Jun-95 Fixed PCI stuff for 1.3.1.
  224. 0.32 26-Jun-95 Added verify_area() calls in de4x5_ioctl() from a
  225. suggestion by <heiko@colossus.escape.de>.
  226. 0.33 8-Aug-95 Add shared interrupt support (not released yet).
  227. 0.331 21-Aug-95 Fix de4x5_open() with fast CPUs.
  228. Fix de4x5_interrupt().
  229. Fix dc21140_autoconf() mess.
  230. No shared interrupt support.
  231. 0.332 11-Sep-95 Added MII management interface routines.
  232. 0.40 5-Mar-96 Fix setup frame timeout <maartenb@hpkuipc.cern.ch>.
  233. Add kernel timer code (h/w is too flaky).
  234. Add MII based PHY autosense.
  235. Add new multicasting code.
  236. Add new autosense algorithms for media/mode
  237. selection using kernel scheduling/timing.
  238. Re-formatted.
  239. Made changes suggested by <jeff@router.patch.net>:
  240. Change driver to detect all DECchip based cards
  241. with DEC_ONLY restriction a special case.
  242. Changed driver to autoprobe as a module. No irq
  243. checking is done now - assume BIOS is good!
  244. Added SMC9332 detection <manabe@Roy.dsl.tutics.ac.jp>
  245. 0.41 21-Mar-96 Don't check for get_hw_addr checksum unless DEC card
  246. only <niles@axp745gsfc.nasa.gov>
  247. Fix for multiple PCI cards reported by <jos@xos.nl>
  248. Duh, put the IRQF_SHARED flag into request_interrupt().
  249. Fix SMC ethernet address in enet_det[].
  250. Print chip name instead of "UNKNOWN" during boot.
  251. 0.42 26-Apr-96 Fix MII write TA bit error.
  252. Fix bug in dc21040 and dc21041 autosense code.
  253. Remove buffer copies on receive for Intels.
  254. Change sk_buff handling during media disconnects to
  255. eliminate DUP packets.
  256. Add dynamic TX thresholding.
  257. Change all chips to use perfect multicast filtering.
  258. Fix alloc_device() bug <jari@markkus2.fimr.fi>
  259. 0.43 21-Jun-96 Fix unconnected media TX retry bug.
  260. Add Accton to the list of broken cards.
  261. Fix TX under-run bug for non DC21140 chips.
  262. Fix boot command probe bug in alloc_device() as
  263. reported by <koen.gadeyne@barco.com> and
  264. <orava@nether.tky.hut.fi>.
  265. Add cache locks to prevent a race condition as
  266. reported by <csd@microplex.com> and
  267. <baba@beckman.uiuc.edu>.
  268. Upgraded alloc_device() code.
  269. 0.431 28-Jun-96 Fix potential bug in queue_pkt() from discussion
  270. with <csd@microplex.com>
  271. 0.44 13-Aug-96 Fix RX overflow bug in 2114[023] chips.
  272. Fix EISA probe bugs reported by <os2@kpi.kharkov.ua>
  273. and <michael@compurex.com>.
  274. 0.441 9-Sep-96 Change dc21041_autoconf() to probe quiet BNC media
  275. with a loopback packet.
  276. 0.442 9-Sep-96 Include AUI in dc21041 media printout. Bug reported
  277. by <bhat@mundook.cs.mu.OZ.AU>
  278. 0.45 8-Dec-96 Include endian functions for PPC use, from work
  279. by <cort@cs.nmt.edu> and <g.thomas@opengroup.org>.
  280. 0.451 28-Dec-96 Added fix to allow autoprobe for modules after
  281. suggestion from <mjacob@feral.com>.
  282. 0.5 30-Jan-97 Added SROM decoding functions.
  283. Updated debug flags.
  284. Fix sleep/wakeup calls for PCI cards, bug reported
  285. by <cross@gweep.lkg.dec.com>.
  286. Added multi-MAC, one SROM feature from discussion
  287. with <mjacob@feral.com>.
  288. Added full module autoprobe capability.
  289. Added attempt to use an SMC9332 with broken SROM.
  290. Added fix for ZYNX multi-mac cards that didn't
  291. get their IRQs wired correctly.
  292. 0.51 13-Feb-97 Added endian fixes for the SROM accesses from
  293. <paubert@iram.es>
  294. Fix init_connection() to remove extra device reset.
  295. Fix MAC/PHY reset ordering in dc21140m_autoconf().
  296. Fix initialisation problem with lp->timeout in
  297. typeX_infoblock() from <paubert@iram.es>.
  298. Fix MII PHY reset problem from work done by
  299. <paubert@iram.es>.
  300. 0.52 26-Apr-97 Some changes may not credit the right people -
  301. a disk crash meant I lost some mail.
  302. Change RX interrupt routine to drop rather than
  303. defer packets to avoid hang reported by
  304. <g.thomas@opengroup.org>.
  305. Fix srom_exec() to return for COMPACT and type 1
  306. infoblocks.
  307. Added DC21142 and DC21143 functions.
  308. Added byte counters from <phil@tazenda.demon.co.uk>
  309. Added IRQF_DISABLED temporary fix from
  310. <mjacob@feral.com>.
  311. 0.53 12-Nov-97 Fix the *_probe() to include 'eth??' name during
  312. module load: bug reported by
  313. <Piete.Brooks@cl.cam.ac.uk>
  314. Fix multi-MAC, one SROM, to work with 2114x chips:
  315. bug reported by <cmetz@inner.net>.
  316. Make above search independent of BIOS device scan
  317. direction.
  318. Completed DC2114[23] autosense functions.
  319. 0.531 21-Dec-97 Fix DE500-XA 100Mb/s bug reported by
  320. <robin@intercore.com
  321. Fix type1_infoblock() bug introduced in 0.53, from
  322. problem reports by
  323. <parmee@postecss.ncrfran.france.ncr.com> and
  324. <jo@ice.dillingen.baynet.de>.
  325. Added argument list to set up each board from either
  326. a module's command line or a compiled in #define.
  327. Added generic MII PHY functionality to deal with
  328. newer PHY chips.
  329. Fix the mess in 2.1.67.
  330. 0.532 5-Jan-98 Fix bug in mii_get_phy() reported by
  331. <redhat@cococo.net>.
  332. Fix bug in pci_probe() for 64 bit systems reported
  333. by <belliott@accessone.com>.
  334. 0.533 9-Jan-98 Fix more 64 bit bugs reported by <jal@cs.brown.edu>.
  335. 0.534 24-Jan-98 Fix last (?) endian bug from <geert@linux-m68k.org>
  336. 0.535 21-Feb-98 Fix Ethernet Address PROM reset bug for DC21040.
  337. 0.536 21-Mar-98 Change pci_probe() to use the pci_dev structure.
  338. **Incompatible with 2.0.x from here.**
  339. 0.540 5-Jul-98 Atomicize assertion of dev->interrupt for SMP
  340. from <lma@varesearch.com>
  341. Add TP, AUI and BNC cases to 21140m_autoconf() for
  342. case where a 21140 under SROM control uses, e.g. AUI
  343. from problem report by <delchini@lpnp09.in2p3.fr>
  344. Add MII parallel detection to 2114x_autoconf() for
  345. case where no autonegotiation partner exists from
  346. problem report by <mlapsley@ndirect.co.uk>.
  347. Add ability to force connection type directly even
  348. when using SROM control from problem report by
  349. <earl@exis.net>.
  350. Updated the PCI interface to conform with the latest
  351. version. I hope nothing is broken...
  352. Add TX done interrupt modification from suggestion
  353. by <Austin.Donnelly@cl.cam.ac.uk>.
  354. Fix is_anc_capable() bug reported by
  355. <Austin.Donnelly@cl.cam.ac.uk>.
  356. Fix type[13]_infoblock() bug: during MII search, PHY
  357. lp->rst not run because lp->ibn not initialised -
  358. from report & fix by <paubert@iram.es>.
  359. Fix probe bug with EISA & PCI cards present from
  360. report by <eirik@netcom.com>.
  361. 0.541 24-Aug-98 Fix compiler problems associated with i386-string
  362. ops from multiple bug reports and temporary fix
  363. from <paubert@iram.es>.
  364. Fix pci_probe() to correctly emulate the old
  365. pcibios_find_class() function.
  366. Add an_exception() for old ZYNX346 and fix compile
  367. warning on PPC & SPARC, from <ecd@skynet.be>.
  368. Fix lastPCI to correctly work with compiled in
  369. kernels and modules from bug report by
  370. <Zlatko.Calusic@CARNet.hr> et al.
  371. 0.542 15-Sep-98 Fix dc2114x_autoconf() to stop multiple messages
  372. when media is unconnected.
  373. Change dev->interrupt to lp->interrupt to ensure
  374. alignment for Alpha's and avoid their unaligned
  375. access traps. This flag is merely for log messages:
  376. should do something more definitive though...
  377. 0.543 30-Dec-98 Add SMP spin locking.
  378. 0.544 8-May-99 Fix for buggy SROM in Motorola embedded boards using
  379. a 21143 by <mmporter@home.com>.
  380. Change PCI/EISA bus probing order.
  381. 0.545 28-Nov-99 Further Moto SROM bug fix from
  382. <mporter@eng.mcd.mot.com>
  383. Remove double checking for DEBUG_RX in de4x5_dbg_rx()
  384. from report by <geert@linux-m68k.org>
  385. 0.546 22-Feb-01 Fixes Alpha XP1000 oops. The srom_search function
  386. was causing a page fault when initializing the
  387. variable 'pb', on a non de4x5 PCI device, in this
  388. case a PCI bridge (DEC chip 21152). The value of
  389. 'pb' is now only initialized if a de4x5 chip is
  390. present.
  391. <france@handhelds.org>
  392. 0.547 08-Nov-01 Use library crc32 functions by <Matt_Domsch@dell.com>
  393. 0.548 30-Aug-03 Big 2.6 cleanup. Ported to PCI/EISA probing and
  394. generic DMA APIs. Fixed DE425 support on Alpha.
  395. <maz@wild-wind.fr.eu.org>
  396. =========================================================================
  397. */
  398. #include <linux/module.h>
  399. #include <linux/kernel.h>
  400. #include <linux/string.h>
  401. #include <linux/interrupt.h>
  402. #include <linux/ptrace.h>
  403. #include <linux/errno.h>
  404. #include <linux/ioport.h>
  405. #include <linux/pci.h>
  406. #include <linux/eisa.h>
  407. #include <linux/delay.h>
  408. #include <linux/init.h>
  409. #include <linux/spinlock.h>
  410. #include <linux/crc32.h>
  411. #include <linux/netdevice.h>
  412. #include <linux/etherdevice.h>
  413. #include <linux/skbuff.h>
  414. #include <linux/time.h>
  415. #include <linux/types.h>
  416. #include <linux/unistd.h>
  417. #include <linux/ctype.h>
  418. #include <linux/dma-mapping.h>
  419. #include <linux/moduleparam.h>
  420. #include <linux/bitops.h>
  421. #include <linux/gfp.h>
  422. #include <asm/io.h>
  423. #include <asm/dma.h>
  424. #include <asm/byteorder.h>
  425. #include <asm/unaligned.h>
  426. #include <linux/uaccess.h>
  427. #ifdef CONFIG_PPC_PMAC
  428. #include <asm/machdep.h>
  429. #endif /* CONFIG_PPC_PMAC */
  430. #include "de4x5.h"
  431. static const char version[] =
  432. KERN_INFO "de4x5.c:V0.546 2001/02/22 davies@maniac.ultranet.com\n";
  433. #define c_char const char
  434. /*
  435. ** MII Information
  436. */
  437. struct phy_table {
  438. int reset; /* Hard reset required? */
  439. int id; /* IEEE OUI */
  440. int ta; /* One cycle TA time - 802.3u is confusing here */
  441. struct { /* Non autonegotiation (parallel) speed det. */
  442. int reg;
  443. int mask;
  444. int value;
  445. } spd;
  446. };
  447. struct mii_phy {
  448. int reset; /* Hard reset required? */
  449. int id; /* IEEE OUI */
  450. int ta; /* One cycle TA time */
  451. struct { /* Non autonegotiation (parallel) speed det. */
  452. int reg;
  453. int mask;
  454. int value;
  455. } spd;
  456. int addr; /* MII address for the PHY */
  457. u_char *gep; /* Start of GEP sequence block in SROM */
  458. u_char *rst; /* Start of reset sequence in SROM */
  459. u_int mc; /* Media Capabilities */
  460. u_int ana; /* NWay Advertisement */
  461. u_int fdx; /* Full DupleX capabilities for each media */
  462. u_int ttm; /* Transmit Threshold Mode for each media */
  463. u_int mci; /* 21142 MII Connector Interrupt info */
  464. };
  465. #define DE4X5_MAX_PHY 8 /* Allow up to 8 attached PHY devices per board */
  466. struct sia_phy {
  467. u_char mc; /* Media Code */
  468. u_char ext; /* csr13-15 valid when set */
  469. int csr13; /* SIA Connectivity Register */
  470. int csr14; /* SIA TX/RX Register */
  471. int csr15; /* SIA General Register */
  472. int gepc; /* SIA GEP Control Information */
  473. int gep; /* SIA GEP Data */
  474. };
  475. /*
  476. ** Define the know universe of PHY devices that can be
  477. ** recognised by this driver.
  478. */
  479. static struct phy_table phy_info[] = {
  480. {0, NATIONAL_TX, 1, {0x19, 0x40, 0x00}}, /* National TX */
  481. {1, BROADCOM_T4, 1, {0x10, 0x02, 0x02}}, /* Broadcom T4 */
  482. {0, SEEQ_T4 , 1, {0x12, 0x10, 0x10}}, /* SEEQ T4 */
  483. {0, CYPRESS_T4 , 1, {0x05, 0x20, 0x20}}, /* Cypress T4 */
  484. {0, 0x7810 , 1, {0x14, 0x0800, 0x0800}} /* Level One LTX970 */
  485. };
  486. /*
  487. ** These GENERIC values assumes that the PHY devices follow 802.3u and
  488. ** allow parallel detection to set the link partner ability register.
  489. ** Detection of 100Base-TX [H/F Duplex] and 100Base-T4 is supported.
  490. */
  491. #define GENERIC_REG 0x05 /* Autoneg. Link Partner Advertisement Reg. */
  492. #define GENERIC_MASK MII_ANLPA_100M /* All 100Mb/s Technologies */
  493. #define GENERIC_VALUE MII_ANLPA_100M /* 100B-TX, 100B-TX FDX, 100B-T4 */
  494. /*
  495. ** Define special SROM detection cases
  496. */
  497. static c_char enet_det[][ETH_ALEN] = {
  498. {0x00, 0x00, 0xc0, 0x00, 0x00, 0x00},
  499. {0x00, 0x00, 0xe8, 0x00, 0x00, 0x00}
  500. };
  501. #define SMC 1
  502. #define ACCTON 2
  503. /*
  504. ** SROM Repair definitions. If a broken SROM is detected a card may
  505. ** use this information to help figure out what to do. This is a
  506. ** "stab in the dark" and so far for SMC9332's only.
  507. */
  508. static c_char srom_repair_info[][100] = {
  509. {0x00,0x1e,0x00,0x00,0x00,0x08, /* SMC9332 */
  510. 0x1f,0x01,0x8f,0x01,0x00,0x01,0x00,0x02,
  511. 0x01,0x00,0x00,0x78,0xe0,0x01,0x00,0x50,
  512. 0x00,0x18,}
  513. };
  514. #ifdef DE4X5_DEBUG
  515. static int de4x5_debug = DE4X5_DEBUG;
  516. #else
  517. /*static int de4x5_debug = (DEBUG_MII | DEBUG_SROM | DEBUG_PCICFG | DEBUG_MEDIA | DEBUG_VERSION);*/
  518. static int de4x5_debug = (DEBUG_MEDIA | DEBUG_VERSION);
  519. #endif
  520. /*
  521. ** Allow per adapter set up. For modules this is simply a command line
  522. ** parameter, e.g.:
  523. ** insmod de4x5 args='eth1:fdx autosense=BNC eth0:autosense=100Mb'.
  524. **
  525. ** For a compiled in driver, place e.g.
  526. ** #define DE4X5_PARM "eth0:fdx autosense=AUI eth2:autosense=TP"
  527. ** here
  528. */
  529. #ifdef DE4X5_PARM
  530. static char *args = DE4X5_PARM;
  531. #else
  532. static char *args;
  533. #endif
  534. struct parameters {
  535. bool fdx;
  536. int autosense;
  537. };
  538. #define DE4X5_AUTOSENSE_MS 250 /* msec autosense tick (DE500) */
  539. #define DE4X5_NDA 0xffe0 /* No Device (I/O) Address */
  540. /*
  541. ** Ethernet PROM defines
  542. */
  543. #define PROBE_LENGTH 32
  544. #define ETH_PROM_SIG 0xAA5500FFUL
  545. /*
  546. ** Ethernet Info
  547. */
  548. #define PKT_BUF_SZ 1536 /* Buffer size for each Tx/Rx buffer */
  549. #define IEEE802_3_SZ 1518 /* Packet + CRC */
  550. #define MAX_PKT_SZ 1514 /* Maximum ethernet packet length */
  551. #define MAX_DAT_SZ 1500 /* Maximum ethernet data length */
  552. #define MIN_DAT_SZ 1 /* Minimum ethernet data length */
  553. #define PKT_HDR_LEN 14 /* Addresses and data length info */
  554. #define FAKE_FRAME_LEN (MAX_PKT_SZ + 1)
  555. #define QUEUE_PKT_TIMEOUT (3*HZ) /* 3 second timeout */
  556. /*
  557. ** EISA bus defines
  558. */
  559. #define DE4X5_EISA_IO_PORTS 0x0c00 /* I/O port base address, slot 0 */
  560. #define DE4X5_EISA_TOTAL_SIZE 0x100 /* I/O address extent */
  561. #define EISA_ALLOWED_IRQ_LIST {5, 9, 10, 11}
  562. #define DE4X5_SIGNATURE {"DE425","DE434","DE435","DE450","DE500"}
  563. #define DE4X5_NAME_LENGTH 8
  564. static c_char *de4x5_signatures[] = DE4X5_SIGNATURE;
  565. /*
  566. ** Ethernet PROM defines for DC21040
  567. */
  568. #define PROBE_LENGTH 32
  569. #define ETH_PROM_SIG 0xAA5500FFUL
  570. /*
  571. ** PCI Bus defines
  572. */
  573. #define PCI_MAX_BUS_NUM 8
  574. #define DE4X5_PCI_TOTAL_SIZE 0x80 /* I/O address extent */
  575. #define DE4X5_CLASS_CODE 0x00020000 /* Network controller, Ethernet */
  576. /*
  577. ** Memory Alignment. Each descriptor is 4 longwords long. To force a
  578. ** particular alignment on the TX descriptor, adjust DESC_SKIP_LEN and
  579. ** DESC_ALIGN. ALIGN aligns the start address of the private memory area
  580. ** and hence the RX descriptor ring's first entry.
  581. */
  582. #define DE4X5_ALIGN4 ((u_long)4 - 1) /* 1 longword align */
  583. #define DE4X5_ALIGN8 ((u_long)8 - 1) /* 2 longword align */
  584. #define DE4X5_ALIGN16 ((u_long)16 - 1) /* 4 longword align */
  585. #define DE4X5_ALIGN32 ((u_long)32 - 1) /* 8 longword align */
  586. #define DE4X5_ALIGN64 ((u_long)64 - 1) /* 16 longword align */
  587. #define DE4X5_ALIGN128 ((u_long)128 - 1) /* 32 longword align */
  588. #define DE4X5_ALIGN DE4X5_ALIGN32 /* Keep the DC21040 happy... */
  589. #define DE4X5_CACHE_ALIGN CAL_16LONG
  590. #define DESC_SKIP_LEN DSL_0 /* Must agree with DESC_ALIGN */
  591. /*#define DESC_ALIGN u32 dummy[4]; / * Must agree with DESC_SKIP_LEN */
  592. #define DESC_ALIGN
  593. #ifndef DEC_ONLY /* See README.de4x5 for using this */
  594. static int dec_only;
  595. #else
  596. static int dec_only = 1;
  597. #endif
  598. /*
  599. ** DE4X5 IRQ ENABLE/DISABLE
  600. */
  601. #define ENABLE_IRQs { \
  602. imr |= lp->irq_en;\
  603. outl(imr, DE4X5_IMR); /* Enable the IRQs */\
  604. }
  605. #define DISABLE_IRQs {\
  606. imr = inl(DE4X5_IMR);\
  607. imr &= ~lp->irq_en;\
  608. outl(imr, DE4X5_IMR); /* Disable the IRQs */\
  609. }
  610. #define UNMASK_IRQs {\
  611. imr |= lp->irq_mask;\
  612. outl(imr, DE4X5_IMR); /* Unmask the IRQs */\
  613. }
  614. #define MASK_IRQs {\
  615. imr = inl(DE4X5_IMR);\
  616. imr &= ~lp->irq_mask;\
  617. outl(imr, DE4X5_IMR); /* Mask the IRQs */\
  618. }
  619. /*
  620. ** DE4X5 START/STOP
  621. */
  622. #define START_DE4X5 {\
  623. omr = inl(DE4X5_OMR);\
  624. omr |= OMR_ST | OMR_SR;\
  625. outl(omr, DE4X5_OMR); /* Enable the TX and/or RX */\
  626. }
  627. #define STOP_DE4X5 {\
  628. omr = inl(DE4X5_OMR);\
  629. omr &= ~(OMR_ST|OMR_SR);\
  630. outl(omr, DE4X5_OMR); /* Disable the TX and/or RX */ \
  631. }
  632. /*
  633. ** DE4X5 SIA RESET
  634. */
  635. #define RESET_SIA outl(0, DE4X5_SICR); /* Reset SIA connectivity regs */
  636. /*
  637. ** DE500 AUTOSENSE TIMER INTERVAL (MILLISECS)
  638. */
  639. #define DE4X5_AUTOSENSE_MS 250
  640. /*
  641. ** SROM Structure
  642. */
  643. struct de4x5_srom {
  644. char sub_vendor_id[2];
  645. char sub_system_id[2];
  646. char reserved[12];
  647. char id_block_crc;
  648. char reserved2;
  649. char version;
  650. char num_controllers;
  651. char ieee_addr[6];
  652. char info[100];
  653. short chksum;
  654. };
  655. #define SUB_VENDOR_ID 0x500a
  656. /*
  657. ** DE4X5 Descriptors. Make sure that all the RX buffers are contiguous
  658. ** and have sizes of both a power of 2 and a multiple of 4.
  659. ** A size of 256 bytes for each buffer could be chosen because over 90% of
  660. ** all packets in our network are <256 bytes long and 64 longword alignment
  661. ** is possible. 1536 showed better 'ttcp' performance. Take your pick. 32 TX
  662. ** descriptors are needed for machines with an ALPHA CPU.
  663. */
  664. #define NUM_RX_DESC 8 /* Number of RX descriptors */
  665. #define NUM_TX_DESC 32 /* Number of TX descriptors */
  666. #define RX_BUFF_SZ 1536 /* Power of 2 for kmalloc and */
  667. /* Multiple of 4 for DC21040 */
  668. /* Allows 512 byte alignment */
  669. struct de4x5_desc {
  670. volatile __le32 status;
  671. __le32 des1;
  672. __le32 buf;
  673. __le32 next;
  674. DESC_ALIGN
  675. };
  676. /*
  677. ** The DE4X5 private structure
  678. */
  679. #define DE4X5_PKT_STAT_SZ 16
  680. #define DE4X5_PKT_BIN_SZ 128 /* Should be >=100 unless you
  681. increase DE4X5_PKT_STAT_SZ */
  682. struct pkt_stats {
  683. u_int bins[DE4X5_PKT_STAT_SZ]; /* Private stats counters */
  684. u_int unicast;
  685. u_int multicast;
  686. u_int broadcast;
  687. u_int excessive_collisions;
  688. u_int tx_underruns;
  689. u_int excessive_underruns;
  690. u_int rx_runt_frames;
  691. u_int rx_collision;
  692. u_int rx_dribble;
  693. u_int rx_overflow;
  694. };
  695. struct de4x5_private {
  696. char adapter_name[80]; /* Adapter name */
  697. u_long interrupt; /* Aligned ISR flag */
  698. struct de4x5_desc *rx_ring; /* RX descriptor ring */
  699. struct de4x5_desc *tx_ring; /* TX descriptor ring */
  700. struct sk_buff *tx_skb[NUM_TX_DESC]; /* TX skb for freeing when sent */
  701. struct sk_buff *rx_skb[NUM_RX_DESC]; /* RX skb's */
  702. int rx_new, rx_old; /* RX descriptor ring pointers */
  703. int tx_new, tx_old; /* TX descriptor ring pointers */
  704. char setup_frame[SETUP_FRAME_LEN]; /* Holds MCA and PA info. */
  705. char frame[64]; /* Min sized packet for loopback*/
  706. spinlock_t lock; /* Adapter specific spinlock */
  707. struct net_device_stats stats; /* Public stats */
  708. struct pkt_stats pktStats; /* Private stats counters */
  709. char rxRingSize;
  710. char txRingSize;
  711. int bus; /* EISA or PCI */
  712. int bus_num; /* PCI Bus number */
  713. int device; /* Device number on PCI bus */
  714. int state; /* Adapter OPENED or CLOSED */
  715. int chipset; /* DC21040, DC21041 or DC21140 */
  716. s32 irq_mask; /* Interrupt Mask (Enable) bits */
  717. s32 irq_en; /* Summary interrupt bits */
  718. int media; /* Media (eg TP), mode (eg 100B)*/
  719. int c_media; /* Remember the last media conn */
  720. bool fdx; /* media full duplex flag */
  721. int linkOK; /* Link is OK */
  722. int autosense; /* Allow/disallow autosensing */
  723. bool tx_enable; /* Enable descriptor polling */
  724. int setup_f; /* Setup frame filtering type */
  725. int local_state; /* State within a 'media' state */
  726. struct mii_phy phy[DE4X5_MAX_PHY]; /* List of attached PHY devices */
  727. struct sia_phy sia; /* SIA PHY Information */
  728. int active; /* Index to active PHY device */
  729. int mii_cnt; /* Number of attached PHY's */
  730. int timeout; /* Scheduling counter */
  731. struct timer_list timer; /* Timer info for kernel */
  732. int tmp; /* Temporary global per card */
  733. struct {
  734. u_long lock; /* Lock the cache accesses */
  735. s32 csr0; /* Saved Bus Mode Register */
  736. s32 csr6; /* Saved Operating Mode Reg. */
  737. s32 csr7; /* Saved IRQ Mask Register */
  738. s32 gep; /* Saved General Purpose Reg. */
  739. s32 gepc; /* Control info for GEP */
  740. s32 csr13; /* Saved SIA Connectivity Reg. */
  741. s32 csr14; /* Saved SIA TX/RX Register */
  742. s32 csr15; /* Saved SIA General Register */
  743. int save_cnt; /* Flag if state already saved */
  744. struct sk_buff_head queue; /* Save the (re-ordered) skb's */
  745. } cache;
  746. struct de4x5_srom srom; /* A copy of the SROM */
  747. int cfrv; /* Card CFRV copy */
  748. int rx_ovf; /* Check for 'RX overflow' tag */
  749. bool useSROM; /* For non-DEC card use SROM */
  750. bool useMII; /* Infoblock using the MII */
  751. int asBitValid; /* Autosense bits in GEP? */
  752. int asPolarity; /* 0 => asserted high */
  753. int asBit; /* Autosense bit number in GEP */
  754. int defMedium; /* SROM default medium */
  755. int tcount; /* Last infoblock number */
  756. int infoblock_init; /* Initialised this infoblock? */
  757. int infoleaf_offset; /* SROM infoleaf for controller */
  758. s32 infoblock_csr6; /* csr6 value in SROM infoblock */
  759. int infoblock_media; /* infoblock media */
  760. int (*infoleaf_fn)(struct net_device *); /* Pointer to infoleaf function */
  761. u_char *rst; /* Pointer to Type 5 reset info */
  762. u_char ibn; /* Infoblock number */
  763. struct parameters params; /* Command line/ #defined params */
  764. struct device *gendev; /* Generic device */
  765. dma_addr_t dma_rings; /* DMA handle for rings */
  766. int dma_size; /* Size of the DMA area */
  767. char *rx_bufs; /* rx bufs on alpha, sparc, ... */
  768. };
  769. /*
  770. ** To get around certain poxy cards that don't provide an SROM
  771. ** for the second and more DECchip, I have to key off the first
  772. ** chip's address. I'll assume there's not a bad SROM iff:
  773. **
  774. ** o the chipset is the same
  775. ** o the bus number is the same and > 0
  776. ** o the sum of all the returned hw address bytes is 0 or 0x5fa
  777. **
  778. ** Also have to save the irq for those cards whose hardware designers
  779. ** can't follow the PCI to PCI Bridge Architecture spec.
  780. */
  781. static struct {
  782. int chipset;
  783. int bus;
  784. int irq;
  785. u_char addr[ETH_ALEN];
  786. } last = {0,};
  787. /*
  788. ** The transmit ring full condition is described by the tx_old and tx_new
  789. ** pointers by:
  790. ** tx_old = tx_new Empty ring
  791. ** tx_old = tx_new+1 Full ring
  792. ** tx_old+txRingSize = tx_new+1 Full ring (wrapped condition)
  793. */
  794. #define TX_BUFFS_AVAIL ((lp->tx_old<=lp->tx_new)?\
  795. lp->tx_old+lp->txRingSize-lp->tx_new-1:\
  796. lp->tx_old -lp->tx_new-1)
  797. #define TX_PKT_PENDING (lp->tx_old != lp->tx_new)
  798. /*
  799. ** Public Functions
  800. */
  801. static int de4x5_open(struct net_device *dev);
  802. static netdev_tx_t de4x5_queue_pkt(struct sk_buff *skb,
  803. struct net_device *dev);
  804. static irqreturn_t de4x5_interrupt(int irq, void *dev_id);
  805. static int de4x5_close(struct net_device *dev);
  806. static struct net_device_stats *de4x5_get_stats(struct net_device *dev);
  807. static void de4x5_local_stats(struct net_device *dev, char *buf, int pkt_len);
  808. static void set_multicast_list(struct net_device *dev);
  809. static int de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
  810. /*
  811. ** Private functions
  812. */
  813. static int de4x5_hw_init(struct net_device *dev, u_long iobase, struct device *gendev);
  814. static int de4x5_init(struct net_device *dev);
  815. static int de4x5_sw_reset(struct net_device *dev);
  816. static int de4x5_rx(struct net_device *dev);
  817. static int de4x5_tx(struct net_device *dev);
  818. static void de4x5_ast(struct timer_list *t);
  819. static int de4x5_txur(struct net_device *dev);
  820. static int de4x5_rx_ovfc(struct net_device *dev);
  821. static int autoconf_media(struct net_device *dev);
  822. static void create_packet(struct net_device *dev, char *frame, int len);
  823. static void load_packet(struct net_device *dev, char *buf, u32 flags, struct sk_buff *skb);
  824. static int dc21040_autoconf(struct net_device *dev);
  825. static int dc21041_autoconf(struct net_device *dev);
  826. static int dc21140m_autoconf(struct net_device *dev);
  827. static int dc2114x_autoconf(struct net_device *dev);
  828. static int srom_autoconf(struct net_device *dev);
  829. static int de4x5_suspect_state(struct net_device *dev, int timeout, int prev_state, int (*fn)(struct net_device *, int), int (*asfn)(struct net_device *));
  830. static int dc21040_state(struct net_device *dev, int csr13, int csr14, int csr15, int timeout, int next_state, int suspect_state, int (*fn)(struct net_device *, int));
  831. static int test_media(struct net_device *dev, s32 irqs, s32 irq_mask, s32 csr13, s32 csr14, s32 csr15, s32 msec);
  832. static int test_for_100Mb(struct net_device *dev, int msec);
  833. static int wait_for_link(struct net_device *dev);
  834. static int test_mii_reg(struct net_device *dev, int reg, int mask, bool pol, long msec);
  835. static int is_spd_100(struct net_device *dev);
  836. static int is_100_up(struct net_device *dev);
  837. static int is_10_up(struct net_device *dev);
  838. static int is_anc_capable(struct net_device *dev);
  839. static int ping_media(struct net_device *dev, int msec);
  840. static struct sk_buff *de4x5_alloc_rx_buff(struct net_device *dev, int index, int len);
  841. static void de4x5_free_rx_buffs(struct net_device *dev);
  842. static void de4x5_free_tx_buffs(struct net_device *dev);
  843. static void de4x5_save_skbs(struct net_device *dev);
  844. static void de4x5_rst_desc_ring(struct net_device *dev);
  845. static void de4x5_cache_state(struct net_device *dev, int flag);
  846. static void de4x5_put_cache(struct net_device *dev, struct sk_buff *skb);
  847. static void de4x5_putb_cache(struct net_device *dev, struct sk_buff *skb);
  848. static struct sk_buff *de4x5_get_cache(struct net_device *dev);
  849. static void de4x5_setup_intr(struct net_device *dev);
  850. static void de4x5_init_connection(struct net_device *dev);
  851. static int de4x5_reset_phy(struct net_device *dev);
  852. static void reset_init_sia(struct net_device *dev, s32 sicr, s32 strr, s32 sigr);
  853. static int test_ans(struct net_device *dev, s32 irqs, s32 irq_mask, s32 msec);
  854. static int test_tp(struct net_device *dev, s32 msec);
  855. static int EISA_signature(char *name, struct device *device);
  856. static int PCI_signature(char *name, struct de4x5_private *lp);
  857. static void DevicePresent(struct net_device *dev, u_long iobase);
  858. static void enet_addr_rst(u_long aprom_addr);
  859. static int de4x5_bad_srom(struct de4x5_private *lp);
  860. static short srom_rd(u_long address, u_char offset);
  861. static void srom_latch(u_int command, u_long address);
  862. static void srom_command(u_int command, u_long address);
  863. static void srom_address(u_int command, u_long address, u_char offset);
  864. static short srom_data(u_int command, u_long address);
  865. /*static void srom_busy(u_int command, u_long address);*/
  866. static void sendto_srom(u_int command, u_long addr);
  867. static int getfrom_srom(u_long addr);
  868. static int srom_map_media(struct net_device *dev);
  869. static int srom_infoleaf_info(struct net_device *dev);
  870. static void srom_init(struct net_device *dev);
  871. static void srom_exec(struct net_device *dev, u_char *p);
  872. static int mii_rd(u_char phyreg, u_char phyaddr, u_long ioaddr);
  873. static void mii_wr(int data, u_char phyreg, u_char phyaddr, u_long ioaddr);
  874. static int mii_rdata(u_long ioaddr);
  875. static void mii_wdata(int data, int len, u_long ioaddr);
  876. static void mii_ta(u_long rw, u_long ioaddr);
  877. static int mii_swap(int data, int len);
  878. static void mii_address(u_char addr, u_long ioaddr);
  879. static void sendto_mii(u32 command, int data, u_long ioaddr);
  880. static int getfrom_mii(u32 command, u_long ioaddr);
  881. static int mii_get_oui(u_char phyaddr, u_long ioaddr);
  882. static int mii_get_phy(struct net_device *dev);
  883. static void SetMulticastFilter(struct net_device *dev);
  884. static int get_hw_addr(struct net_device *dev);
  885. static void srom_repair(struct net_device *dev, int card);
  886. static int test_bad_enet(struct net_device *dev, int status);
  887. static int an_exception(struct de4x5_private *lp);
  888. static char *build_setup_frame(struct net_device *dev, int mode);
  889. static void disable_ast(struct net_device *dev);
  890. static long de4x5_switch_mac_port(struct net_device *dev);
  891. static int gep_rd(struct net_device *dev);
  892. static void gep_wr(s32 data, struct net_device *dev);
  893. static void yawn(struct net_device *dev, int state);
  894. static void de4x5_parse_params(struct net_device *dev);
  895. static void de4x5_dbg_open(struct net_device *dev);
  896. static void de4x5_dbg_mii(struct net_device *dev, int k);
  897. static void de4x5_dbg_media(struct net_device *dev);
  898. static void de4x5_dbg_srom(struct de4x5_srom *p);
  899. static void de4x5_dbg_rx(struct sk_buff *skb, int len);
  900. static int dc21041_infoleaf(struct net_device *dev);
  901. static int dc21140_infoleaf(struct net_device *dev);
  902. static int dc21142_infoleaf(struct net_device *dev);
  903. static int dc21143_infoleaf(struct net_device *dev);
  904. static int type0_infoblock(struct net_device *dev, u_char count, u_char *p);
  905. static int type1_infoblock(struct net_device *dev, u_char count, u_char *p);
  906. static int type2_infoblock(struct net_device *dev, u_char count, u_char *p);
  907. static int type3_infoblock(struct net_device *dev, u_char count, u_char *p);
  908. static int type4_infoblock(struct net_device *dev, u_char count, u_char *p);
  909. static int type5_infoblock(struct net_device *dev, u_char count, u_char *p);
  910. static int compact_infoblock(struct net_device *dev, u_char count, u_char *p);
  911. /*
  912. ** Note now that module autoprobing is allowed under EISA and PCI. The
  913. ** IRQ lines will not be auto-detected; instead I'll rely on the BIOSes
  914. ** to "do the right thing".
  915. */
  916. static int io=0x0;/* EDIT THIS LINE FOR YOUR CONFIGURATION IF NEEDED */
  917. module_param_hw(io, int, ioport, 0);
  918. module_param(de4x5_debug, int, 0);
  919. module_param(dec_only, int, 0);
  920. module_param(args, charp, 0);
  921. MODULE_PARM_DESC(io, "de4x5 I/O base address");
  922. MODULE_PARM_DESC(de4x5_debug, "de4x5 debug mask");
  923. MODULE_PARM_DESC(dec_only, "de4x5 probe only for Digital boards (0-1)");
  924. MODULE_PARM_DESC(args, "de4x5 full duplex and media type settings; see de4x5.c for details");
  925. MODULE_LICENSE("GPL");
  926. /*
  927. ** List the SROM infoleaf functions and chipsets
  928. */
  929. struct InfoLeaf {
  930. int chipset;
  931. int (*fn)(struct net_device *);
  932. };
  933. static struct InfoLeaf infoleaf_array[] = {
  934. {DC21041, dc21041_infoleaf},
  935. {DC21140, dc21140_infoleaf},
  936. {DC21142, dc21142_infoleaf},
  937. {DC21143, dc21143_infoleaf}
  938. };
  939. #define INFOLEAF_SIZE ARRAY_SIZE(infoleaf_array)
  940. /*
  941. ** List the SROM info block functions
  942. */
  943. static int (*dc_infoblock[])(struct net_device *dev, u_char, u_char *) = {
  944. type0_infoblock,
  945. type1_infoblock,
  946. type2_infoblock,
  947. type3_infoblock,
  948. type4_infoblock,
  949. type5_infoblock,
  950. compact_infoblock
  951. };
  952. #define COMPACT (ARRAY_SIZE(dc_infoblock) - 1)
  953. /*
  954. ** Miscellaneous defines...
  955. */
  956. #define RESET_DE4X5 {\
  957. int i;\
  958. i=inl(DE4X5_BMR);\
  959. mdelay(1);\
  960. outl(i | BMR_SWR, DE4X5_BMR);\
  961. mdelay(1);\
  962. outl(i, DE4X5_BMR);\
  963. mdelay(1);\
  964. for (i=0;i<5;i++) {inl(DE4X5_BMR); mdelay(1);}\
  965. mdelay(1);\
  966. }
  967. #define PHY_HARD_RESET {\
  968. outl(GEP_HRST, DE4X5_GEP); /* Hard RESET the PHY dev. */\
  969. mdelay(1); /* Assert for 1ms */\
  970. outl(0x00, DE4X5_GEP);\
  971. mdelay(2); /* Wait for 2ms */\
  972. }
  973. static const struct net_device_ops de4x5_netdev_ops = {
  974. .ndo_open = de4x5_open,
  975. .ndo_stop = de4x5_close,
  976. .ndo_start_xmit = de4x5_queue_pkt,
  977. .ndo_get_stats = de4x5_get_stats,
  978. .ndo_set_rx_mode = set_multicast_list,
  979. .ndo_do_ioctl = de4x5_ioctl,
  980. .ndo_set_mac_address= eth_mac_addr,
  981. .ndo_validate_addr = eth_validate_addr,
  982. };
  983. static int
  984. de4x5_hw_init(struct net_device *dev, u_long iobase, struct device *gendev)
  985. {
  986. char name[DE4X5_NAME_LENGTH + 1];
  987. struct de4x5_private *lp = netdev_priv(dev);
  988. struct pci_dev *pdev = NULL;
  989. int i, status=0;
  990. dev_set_drvdata(gendev, dev);
  991. /* Ensure we're not sleeping */
  992. if (lp->bus == EISA) {
  993. outb(WAKEUP, PCI_CFPM);
  994. } else {
  995. pdev = to_pci_dev (gendev);
  996. pci_write_config_byte(pdev, PCI_CFDA_PSM, WAKEUP);
  997. }
  998. mdelay(10);
  999. RESET_DE4X5;
  1000. if ((inl(DE4X5_STS) & (STS_TS | STS_RS)) != 0) {
  1001. return -ENXIO; /* Hardware could not reset */
  1002. }
  1003. /*
  1004. ** Now find out what kind of DC21040/DC21041/DC21140 board we have.
  1005. */
  1006. lp->useSROM = false;
  1007. if (lp->bus == PCI) {
  1008. PCI_signature(name, lp);
  1009. } else {
  1010. EISA_signature(name, gendev);
  1011. }
  1012. if (*name == '\0') { /* Not found a board signature */
  1013. return -ENXIO;
  1014. }
  1015. dev->base_addr = iobase;
  1016. printk ("%s: %s at 0x%04lx", dev_name(gendev), name, iobase);
  1017. status = get_hw_addr(dev);
  1018. printk(", h/w address %pM\n", dev->dev_addr);
  1019. if (status != 0) {
  1020. printk(" which has an Ethernet PROM CRC error.\n");
  1021. return -ENXIO;
  1022. } else {
  1023. skb_queue_head_init(&lp->cache.queue);
  1024. lp->cache.gepc = GEP_INIT;
  1025. lp->asBit = GEP_SLNK;
  1026. lp->asPolarity = GEP_SLNK;
  1027. lp->asBitValid = ~0;
  1028. lp->timeout = -1;
  1029. lp->gendev = gendev;
  1030. spin_lock_init(&lp->lock);
  1031. timer_setup(&lp->timer, de4x5_ast, 0);
  1032. de4x5_parse_params(dev);
  1033. /*
  1034. ** Choose correct autosensing in case someone messed up
  1035. */
  1036. lp->autosense = lp->params.autosense;
  1037. if (lp->chipset != DC21140) {
  1038. if ((lp->chipset==DC21040) && (lp->params.autosense&TP_NW)) {
  1039. lp->params.autosense = TP;
  1040. }
  1041. if ((lp->chipset==DC21041) && (lp->params.autosense&BNC_AUI)) {
  1042. lp->params.autosense = BNC;
  1043. }
  1044. }
  1045. lp->fdx = lp->params.fdx;
  1046. sprintf(lp->adapter_name,"%s (%s)", name, dev_name(gendev));
  1047. lp->dma_size = (NUM_RX_DESC + NUM_TX_DESC) * sizeof(struct de4x5_desc);
  1048. #if defined(__alpha__) || defined(__powerpc__) || defined(CONFIG_SPARC) || defined(DE4X5_DO_MEMCPY)
  1049. lp->dma_size += RX_BUFF_SZ * NUM_RX_DESC + DE4X5_ALIGN;
  1050. #endif
  1051. lp->rx_ring = dma_alloc_coherent(gendev, lp->dma_size,
  1052. &lp->dma_rings, GFP_ATOMIC);
  1053. if (lp->rx_ring == NULL) {
  1054. return -ENOMEM;
  1055. }
  1056. lp->tx_ring = lp->rx_ring + NUM_RX_DESC;
  1057. /*
  1058. ** Set up the RX descriptor ring (Intels)
  1059. ** Allocate contiguous receive buffers, long word aligned (Alphas)
  1060. */
  1061. #if !defined(__alpha__) && !defined(__powerpc__) && !defined(CONFIG_SPARC) && !defined(DE4X5_DO_MEMCPY)
  1062. for (i=0; i<NUM_RX_DESC; i++) {
  1063. lp->rx_ring[i].status = 0;
  1064. lp->rx_ring[i].des1 = cpu_to_le32(RX_BUFF_SZ);
  1065. lp->rx_ring[i].buf = 0;
  1066. lp->rx_ring[i].next = 0;
  1067. lp->rx_skb[i] = (struct sk_buff *) 1; /* Dummy entry */
  1068. }
  1069. #else
  1070. {
  1071. dma_addr_t dma_rx_bufs;
  1072. dma_rx_bufs = lp->dma_rings + (NUM_RX_DESC + NUM_TX_DESC)
  1073. * sizeof(struct de4x5_desc);
  1074. dma_rx_bufs = (dma_rx_bufs + DE4X5_ALIGN) & ~DE4X5_ALIGN;
  1075. lp->rx_bufs = (char *)(((long)(lp->rx_ring + NUM_RX_DESC
  1076. + NUM_TX_DESC) + DE4X5_ALIGN) & ~DE4X5_ALIGN);
  1077. for (i=0; i<NUM_RX_DESC; i++) {
  1078. lp->rx_ring[i].status = 0;
  1079. lp->rx_ring[i].des1 = cpu_to_le32(RX_BUFF_SZ);
  1080. lp->rx_ring[i].buf =
  1081. cpu_to_le32(dma_rx_bufs+i*RX_BUFF_SZ);
  1082. lp->rx_ring[i].next = 0;
  1083. lp->rx_skb[i] = (struct sk_buff *) 1; /* Dummy entry */
  1084. }
  1085. }
  1086. #endif
  1087. barrier();
  1088. lp->rxRingSize = NUM_RX_DESC;
  1089. lp->txRingSize = NUM_TX_DESC;
  1090. /* Write the end of list marker to the descriptor lists */
  1091. lp->rx_ring[lp->rxRingSize - 1].des1 |= cpu_to_le32(RD_RER);
  1092. lp->tx_ring[lp->txRingSize - 1].des1 |= cpu_to_le32(TD_TER);
  1093. /* Tell the adapter where the TX/RX rings are located. */
  1094. outl(lp->dma_rings, DE4X5_RRBA);
  1095. outl(lp->dma_rings + NUM_RX_DESC * sizeof(struct de4x5_desc),
  1096. DE4X5_TRBA);
  1097. /* Initialise the IRQ mask and Enable/Disable */
  1098. lp->irq_mask = IMR_RIM | IMR_TIM | IMR_TUM | IMR_UNM;
  1099. lp->irq_en = IMR_NIM | IMR_AIM;
  1100. /* Create a loopback packet frame for later media probing */
  1101. create_packet(dev, lp->frame, sizeof(lp->frame));
  1102. /* Check if the RX overflow bug needs testing for */
  1103. i = lp->cfrv & 0x000000fe;
  1104. if ((lp->chipset == DC21140) && (i == 0x20)) {
  1105. lp->rx_ovf = 1;
  1106. }
  1107. /* Initialise the SROM pointers if possible */
  1108. if (lp->useSROM) {
  1109. lp->state = INITIALISED;
  1110. if (srom_infoleaf_info(dev)) {
  1111. dma_free_coherent (gendev, lp->dma_size,
  1112. lp->rx_ring, lp->dma_rings);
  1113. return -ENXIO;
  1114. }
  1115. srom_init(dev);
  1116. }
  1117. lp->state = CLOSED;
  1118. /*
  1119. ** Check for an MII interface
  1120. */
  1121. if ((lp->chipset != DC21040) && (lp->chipset != DC21041)) {
  1122. mii_get_phy(dev);
  1123. }
  1124. printk(" and requires IRQ%d (provided by %s).\n", dev->irq,
  1125. ((lp->bus == PCI) ? "PCI BIOS" : "EISA CNFG"));
  1126. }
  1127. if (de4x5_debug & DEBUG_VERSION) {
  1128. printk(version);
  1129. }
  1130. /* The DE4X5-specific entries in the device structure. */
  1131. SET_NETDEV_DEV(dev, gendev);
  1132. dev->netdev_ops = &de4x5_netdev_ops;
  1133. dev->mem_start = 0;
  1134. /* Fill in the generic fields of the device structure. */
  1135. if ((status = register_netdev (dev))) {
  1136. dma_free_coherent (gendev, lp->dma_size,
  1137. lp->rx_ring, lp->dma_rings);
  1138. return status;
  1139. }
  1140. /* Let the adapter sleep to save power */
  1141. yawn(dev, SLEEP);
  1142. return status;
  1143. }
  1144. static int
  1145. de4x5_open(struct net_device *dev)
  1146. {
  1147. struct de4x5_private *lp = netdev_priv(dev);
  1148. u_long iobase = dev->base_addr;
  1149. int i, status = 0;
  1150. s32 omr;
  1151. /* Allocate the RX buffers */
  1152. for (i=0; i<lp->rxRingSize; i++) {
  1153. if (de4x5_alloc_rx_buff(dev, i, 0) == NULL) {
  1154. de4x5_free_rx_buffs(dev);
  1155. return -EAGAIN;
  1156. }
  1157. }
  1158. /*
  1159. ** Wake up the adapter
  1160. */
  1161. yawn(dev, WAKEUP);
  1162. /*
  1163. ** Re-initialize the DE4X5...
  1164. */
  1165. status = de4x5_init(dev);
  1166. spin_lock_init(&lp->lock);
  1167. lp->state = OPEN;
  1168. de4x5_dbg_open(dev);
  1169. if (request_irq(dev->irq, de4x5_interrupt, IRQF_SHARED,
  1170. lp->adapter_name, dev)) {
  1171. printk("de4x5_open(): Requested IRQ%d is busy - attempting FAST/SHARE...", dev->irq);
  1172. if (request_irq(dev->irq, de4x5_interrupt, IRQF_SHARED,
  1173. lp->adapter_name, dev)) {
  1174. printk("\n Cannot get IRQ- reconfigure your hardware.\n");
  1175. disable_ast(dev);
  1176. de4x5_free_rx_buffs(dev);
  1177. de4x5_free_tx_buffs(dev);
  1178. yawn(dev, SLEEP);
  1179. lp->state = CLOSED;
  1180. return -EAGAIN;
  1181. } else {
  1182. printk("\n Succeeded, but you should reconfigure your hardware to avoid this.\n");
  1183. printk("WARNING: there may be IRQ related problems in heavily loaded systems.\n");
  1184. }
  1185. }
  1186. lp->interrupt = UNMASK_INTERRUPTS;
  1187. netif_trans_update(dev); /* prevent tx timeout */
  1188. START_DE4X5;
  1189. de4x5_setup_intr(dev);
  1190. if (de4x5_debug & DEBUG_OPEN) {
  1191. printk("\tsts: 0x%08x\n", inl(DE4X5_STS));
  1192. printk("\tbmr: 0x%08x\n", inl(DE4X5_BMR));
  1193. printk("\timr: 0x%08x\n", inl(DE4X5_IMR));
  1194. printk("\tomr: 0x%08x\n", inl(DE4X5_OMR));
  1195. printk("\tsisr: 0x%08x\n", inl(DE4X5_SISR));
  1196. printk("\tsicr: 0x%08x\n", inl(DE4X5_SICR));
  1197. printk("\tstrr: 0x%08x\n", inl(DE4X5_STRR));
  1198. printk("\tsigr: 0x%08x\n", inl(DE4X5_SIGR));
  1199. }
  1200. return status;
  1201. }
  1202. /*
  1203. ** Initialize the DE4X5 operating conditions. NB: a chip problem with the
  1204. ** DC21140 requires using perfect filtering mode for that chip. Since I can't
  1205. ** see why I'd want > 14 multicast addresses, I have changed all chips to use
  1206. ** the perfect filtering mode. Keep the DMA burst length at 8: there seems
  1207. ** to be data corruption problems if it is larger (UDP errors seen from a
  1208. ** ttcp source).
  1209. */
  1210. static int
  1211. de4x5_init(struct net_device *dev)
  1212. {
  1213. /* Lock out other processes whilst setting up the hardware */
  1214. netif_stop_queue(dev);
  1215. de4x5_sw_reset(dev);
  1216. /* Autoconfigure the connected port */
  1217. autoconf_media(dev);
  1218. return 0;
  1219. }
  1220. static int
  1221. de4x5_sw_reset(struct net_device *dev)
  1222. {
  1223. struct de4x5_private *lp = netdev_priv(dev);
  1224. u_long iobase = dev->base_addr;
  1225. int i, j, status = 0;
  1226. s32 bmr, omr;
  1227. /* Select the MII or SRL port now and RESET the MAC */
  1228. if (!lp->useSROM) {
  1229. if (lp->phy[lp->active].id != 0) {
  1230. lp->infoblock_csr6 = OMR_SDP | OMR_PS | OMR_HBD;
  1231. } else {
  1232. lp->infoblock_csr6 = OMR_SDP | OMR_TTM;
  1233. }
  1234. de4x5_switch_mac_port(dev);
  1235. }
  1236. /*
  1237. ** Set the programmable burst length to 8 longwords for all the DC21140
  1238. ** Fasternet chips and 4 longwords for all others: DMA errors result
  1239. ** without these values. Cache align 16 long.
  1240. */
  1241. bmr = (lp->chipset==DC21140 ? PBL_8 : PBL_4) | DESC_SKIP_LEN | DE4X5_CACHE_ALIGN;
  1242. bmr |= ((lp->chipset & ~0x00ff)==DC2114x ? BMR_RML : 0);
  1243. outl(bmr, DE4X5_BMR);
  1244. omr = inl(DE4X5_OMR) & ~OMR_PR; /* Turn off promiscuous mode */
  1245. if (lp->chipset == DC21140) {
  1246. omr |= (OMR_SDP | OMR_SB);
  1247. }
  1248. lp->setup_f = PERFECT;
  1249. outl(lp->dma_rings, DE4X5_RRBA);
  1250. outl(lp->dma_rings + NUM_RX_DESC * sizeof(struct de4x5_desc),
  1251. DE4X5_TRBA);
  1252. lp->rx_new = lp->rx_old = 0;
  1253. lp->tx_new = lp->tx_old = 0;
  1254. for (i = 0; i < lp->rxRingSize; i++) {
  1255. lp->rx_ring[i].status = cpu_to_le32(R_OWN);
  1256. }
  1257. for (i = 0; i < lp->txRingSize; i++) {
  1258. lp->tx_ring[i].status = cpu_to_le32(0);
  1259. }
  1260. barrier();
  1261. /* Build the setup frame depending on filtering mode */
  1262. SetMulticastFilter(dev);
  1263. load_packet(dev, lp->setup_frame, PERFECT_F|TD_SET|SETUP_FRAME_LEN, (struct sk_buff *)1);
  1264. outl(omr|OMR_ST, DE4X5_OMR);
  1265. /* Poll for setup frame completion (adapter interrupts are disabled now) */
  1266. for (j=0, i=0;(i<500) && (j==0);i++) { /* Up to 500ms delay */
  1267. mdelay(1);
  1268. if ((s32)le32_to_cpu(lp->tx_ring[lp->tx_new].status) >= 0) j=1;
  1269. }
  1270. outl(omr, DE4X5_OMR); /* Stop everything! */
  1271. if (j == 0) {
  1272. printk("%s: Setup frame timed out, status %08x\n", dev->name,
  1273. inl(DE4X5_STS));
  1274. status = -EIO;
  1275. }
  1276. lp->tx_new = (lp->tx_new + 1) % lp->txRingSize;
  1277. lp->tx_old = lp->tx_new;
  1278. return status;
  1279. }
  1280. /*
  1281. ** Writes a socket buffer address to the next available transmit descriptor.
  1282. */
  1283. static netdev_tx_t
  1284. de4x5_queue_pkt(struct sk_buff *skb, struct net_device *dev)
  1285. {
  1286. struct de4x5_private *lp = netdev_priv(dev);
  1287. u_long iobase = dev->base_addr;
  1288. u_long flags = 0;
  1289. netif_stop_queue(dev);
  1290. if (!lp->tx_enable) /* Cannot send for now */
  1291. goto tx_err;
  1292. /*
  1293. ** Clean out the TX ring asynchronously to interrupts - sometimes the
  1294. ** interrupts are lost by delayed descriptor status updates relative to
  1295. ** the irq assertion, especially with a busy PCI bus.
  1296. */
  1297. spin_lock_irqsave(&lp->lock, flags);
  1298. de4x5_tx(dev);
  1299. spin_unlock_irqrestore(&lp->lock, flags);
  1300. /* Test if cache is already locked - requeue skb if so */
  1301. if (test_and_set_bit(0, (void *)&lp->cache.lock) && !lp->interrupt)
  1302. goto tx_err;
  1303. /* Transmit descriptor ring full or stale skb */
  1304. if (netif_queue_stopped(dev) || (u_long) lp->tx_skb[lp->tx_new] > 1) {
  1305. if (lp->interrupt) {
  1306. de4x5_putb_cache(dev, skb); /* Requeue the buffer */
  1307. } else {
  1308. de4x5_put_cache(dev, skb);
  1309. }
  1310. if (de4x5_debug & DEBUG_TX) {
  1311. printk("%s: transmit busy, lost media or stale skb found:\n STS:%08x\n tbusy:%d\n IMR:%08x\n OMR:%08x\n Stale skb: %s\n",dev->name, inl(DE4X5_STS), netif_queue_stopped(dev), inl(DE4X5_IMR), inl(DE4X5_OMR), ((u_long) lp->tx_skb[lp->tx_new] > 1) ? "YES" : "NO");
  1312. }
  1313. } else if (skb->len > 0) {
  1314. /* If we already have stuff queued locally, use that first */
  1315. if (!skb_queue_empty(&lp->cache.queue) && !lp->interrupt) {
  1316. de4x5_put_cache(dev, skb);
  1317. skb = de4x5_get_cache(dev);
  1318. }
  1319. while (skb && !netif_queue_stopped(dev) &&
  1320. (u_long) lp->tx_skb[lp->tx_new] <= 1) {
  1321. spin_lock_irqsave(&lp->lock, flags);
  1322. netif_stop_queue(dev);
  1323. load_packet(dev, skb->data, TD_IC | TD_LS | TD_FS | skb->len, skb);
  1324. lp->stats.tx_bytes += skb->len;
  1325. outl(POLL_DEMAND, DE4X5_TPD);/* Start the TX */
  1326. lp->tx_new = (lp->tx_new + 1) % lp->txRingSize;
  1327. if (TX_BUFFS_AVAIL) {
  1328. netif_start_queue(dev); /* Another pkt may be queued */
  1329. }
  1330. skb = de4x5_get_cache(dev);
  1331. spin_unlock_irqrestore(&lp->lock, flags);
  1332. }
  1333. if (skb) de4x5_putb_cache(dev, skb);
  1334. }
  1335. lp->cache.lock = 0;
  1336. return NETDEV_TX_OK;
  1337. tx_err:
  1338. dev_kfree_skb_any(skb);
  1339. return NETDEV_TX_OK;
  1340. }
  1341. /*
  1342. ** The DE4X5 interrupt handler.
  1343. **
  1344. ** I/O Read/Writes through intermediate PCI bridges are never 'posted',
  1345. ** so that the asserted interrupt always has some real data to work with -
  1346. ** if these I/O accesses are ever changed to memory accesses, ensure the
  1347. ** STS write is read immediately to complete the transaction if the adapter
  1348. ** is not on bus 0. Lost interrupts can still occur when the PCI bus load
  1349. ** is high and descriptor status bits cannot be set before the associated
  1350. ** interrupt is asserted and this routine entered.
  1351. */
  1352. static irqreturn_t
  1353. de4x5_interrupt(int irq, void *dev_id)
  1354. {
  1355. struct net_device *dev = dev_id;
  1356. struct de4x5_private *lp;
  1357. s32 imr, omr, sts, limit;
  1358. u_long iobase;
  1359. unsigned int handled = 0;
  1360. lp = netdev_priv(dev);
  1361. spin_lock(&lp->lock);
  1362. iobase = dev->base_addr;
  1363. DISABLE_IRQs; /* Ensure non re-entrancy */
  1364. if (test_and_set_bit(MASK_INTERRUPTS, (void*) &lp->interrupt))
  1365. printk("%s: Re-entering the interrupt handler.\n", dev->name);
  1366. synchronize_irq(dev->irq);
  1367. for (limit=0; limit<8; limit++) {
  1368. sts = inl(DE4X5_STS); /* Read IRQ status */
  1369. outl(sts, DE4X5_STS); /* Reset the board interrupts */
  1370. if (!(sts & lp->irq_mask)) break;/* All done */
  1371. handled = 1;
  1372. if (sts & (STS_RI | STS_RU)) /* Rx interrupt (packet[s] arrived) */
  1373. de4x5_rx(dev);
  1374. if (sts & (STS_TI | STS_TU)) /* Tx interrupt (packet sent) */
  1375. de4x5_tx(dev);
  1376. if (sts & STS_LNF) { /* TP Link has failed */
  1377. lp->irq_mask &= ~IMR_LFM;
  1378. }
  1379. if (sts & STS_UNF) { /* Transmit underrun */
  1380. de4x5_txur(dev);
  1381. }
  1382. if (sts & STS_SE) { /* Bus Error */
  1383. STOP_DE4X5;
  1384. printk("%s: Fatal bus error occurred, sts=%#8x, device stopped.\n",
  1385. dev->name, sts);
  1386. spin_unlock(&lp->lock);
  1387. return IRQ_HANDLED;
  1388. }
  1389. }
  1390. /* Load the TX ring with any locally stored packets */
  1391. if (!test_and_set_bit(0, (void *)&lp->cache.lock)) {
  1392. while (!skb_queue_empty(&lp->cache.queue) && !netif_queue_stopped(dev) && lp->tx_enable) {
  1393. de4x5_queue_pkt(de4x5_get_cache(dev), dev);
  1394. }
  1395. lp->cache.lock = 0;
  1396. }
  1397. lp->interrupt = UNMASK_INTERRUPTS;
  1398. ENABLE_IRQs;
  1399. spin_unlock(&lp->lock);
  1400. return IRQ_RETVAL(handled);
  1401. }
  1402. static int
  1403. de4x5_rx(struct net_device *dev)
  1404. {
  1405. struct de4x5_private *lp = netdev_priv(dev);
  1406. u_long iobase = dev->base_addr;
  1407. int entry;
  1408. s32 status;
  1409. for (entry=lp->rx_new; (s32)le32_to_cpu(lp->rx_ring[entry].status)>=0;
  1410. entry=lp->rx_new) {
  1411. status = (s32)le32_to_cpu(lp->rx_ring[entry].status);
  1412. if (lp->rx_ovf) {
  1413. if (inl(DE4X5_MFC) & MFC_FOCM) {
  1414. de4x5_rx_ovfc(dev);
  1415. break;
  1416. }
  1417. }
  1418. if (status & RD_FS) { /* Remember the start of frame */
  1419. lp->rx_old = entry;
  1420. }
  1421. if (status & RD_LS) { /* Valid frame status */
  1422. if (lp->tx_enable) lp->linkOK++;
  1423. if (status & RD_ES) { /* There was an error. */
  1424. lp->stats.rx_errors++; /* Update the error stats. */
  1425. if (status & (RD_RF | RD_TL)) lp->stats.rx_frame_errors++;
  1426. if (status & RD_CE) lp->stats.rx_crc_errors++;
  1427. if (status & RD_OF) lp->stats.rx_fifo_errors++;
  1428. if (status & RD_TL) lp->stats.rx_length_errors++;
  1429. if (status & RD_RF) lp->pktStats.rx_runt_frames++;
  1430. if (status & RD_CS) lp->pktStats.rx_collision++;
  1431. if (status & RD_DB) lp->pktStats.rx_dribble++;
  1432. if (status & RD_OF) lp->pktStats.rx_overflow++;
  1433. } else { /* A valid frame received */
  1434. struct sk_buff *skb;
  1435. short pkt_len = (short)(le32_to_cpu(lp->rx_ring[entry].status)
  1436. >> 16) - 4;
  1437. if ((skb = de4x5_alloc_rx_buff(dev, entry, pkt_len)) == NULL) {
  1438. printk("%s: Insufficient memory; nuking packet.\n",
  1439. dev->name);
  1440. lp->stats.rx_dropped++;
  1441. } else {
  1442. de4x5_dbg_rx(skb, pkt_len);
  1443. /* Push up the protocol stack */
  1444. skb->protocol=eth_type_trans(skb,dev);
  1445. de4x5_local_stats(dev, skb->data, pkt_len);
  1446. netif_rx(skb);
  1447. /* Update stats */
  1448. lp->stats.rx_packets++;
  1449. lp->stats.rx_bytes += pkt_len;
  1450. }
  1451. }
  1452. /* Change buffer ownership for this frame, back to the adapter */
  1453. for (;lp->rx_old!=entry;lp->rx_old=(lp->rx_old + 1)%lp->rxRingSize) {
  1454. lp->rx_ring[lp->rx_old].status = cpu_to_le32(R_OWN);
  1455. barrier();
  1456. }
  1457. lp->rx_ring[entry].status = cpu_to_le32(R_OWN);
  1458. barrier();
  1459. }
  1460. /*
  1461. ** Update entry information
  1462. */
  1463. lp->rx_new = (lp->rx_new + 1) % lp->rxRingSize;
  1464. }
  1465. return 0;
  1466. }
  1467. static inline void
  1468. de4x5_free_tx_buff(struct de4x5_private *lp, int entry)
  1469. {
  1470. dma_unmap_single(lp->gendev, le32_to_cpu(lp->tx_ring[entry].buf),
  1471. le32_to_cpu(lp->tx_ring[entry].des1) & TD_TBS1,
  1472. DMA_TO_DEVICE);
  1473. if ((u_long) lp->tx_skb[entry] > 1)
  1474. dev_kfree_skb_irq(lp->tx_skb[entry]);
  1475. lp->tx_skb[entry] = NULL;
  1476. }
  1477. /*
  1478. ** Buffer sent - check for TX buffer errors.
  1479. */
  1480. static int
  1481. de4x5_tx(struct net_device *dev)
  1482. {
  1483. struct de4x5_private *lp = netdev_priv(dev);
  1484. u_long iobase = dev->base_addr;
  1485. int entry;
  1486. s32 status;
  1487. for (entry = lp->tx_old; entry != lp->tx_new; entry = lp->tx_old) {
  1488. status = (s32)le32_to_cpu(lp->tx_ring[entry].status);
  1489. if (status < 0) { /* Buffer not sent yet */
  1490. break;
  1491. } else if (status != 0x7fffffff) { /* Not setup frame */
  1492. if (status & TD_ES) { /* An error happened */
  1493. lp->stats.tx_errors++;
  1494. if (status & TD_NC) lp->stats.tx_carrier_errors++;
  1495. if (status & TD_LC) lp->stats.tx_window_errors++;
  1496. if (status & TD_UF) lp->stats.tx_fifo_errors++;
  1497. if (status & TD_EC) lp->pktStats.excessive_collisions++;
  1498. if (status & TD_DE) lp->stats.tx_aborted_errors++;
  1499. if (TX_PKT_PENDING) {
  1500. outl(POLL_DEMAND, DE4X5_TPD);/* Restart a stalled TX */
  1501. }
  1502. } else { /* Packet sent */
  1503. lp->stats.tx_packets++;
  1504. if (lp->tx_enable) lp->linkOK++;
  1505. }
  1506. /* Update the collision counter */
  1507. lp->stats.collisions += ((status & TD_EC) ? 16 :
  1508. ((status & TD_CC) >> 3));
  1509. /* Free the buffer. */
  1510. if (lp->tx_skb[entry] != NULL)
  1511. de4x5_free_tx_buff(lp, entry);
  1512. }
  1513. /* Update all the pointers */
  1514. lp->tx_old = (lp->tx_old + 1) % lp->txRingSize;
  1515. }
  1516. /* Any resources available? */
  1517. if (TX_BUFFS_AVAIL && netif_queue_stopped(dev)) {
  1518. if (lp->interrupt)
  1519. netif_wake_queue(dev);
  1520. else
  1521. netif_start_queue(dev);
  1522. }
  1523. return 0;
  1524. }
  1525. static void
  1526. de4x5_ast(struct timer_list *t)
  1527. {
  1528. struct de4x5_private *lp = from_timer(lp, t, timer);
  1529. struct net_device *dev = dev_get_drvdata(lp->gendev);
  1530. int next_tick = DE4X5_AUTOSENSE_MS;
  1531. int dt;
  1532. if (lp->useSROM)
  1533. next_tick = srom_autoconf(dev);
  1534. else if (lp->chipset == DC21140)
  1535. next_tick = dc21140m_autoconf(dev);
  1536. else if (lp->chipset == DC21041)
  1537. next_tick = dc21041_autoconf(dev);
  1538. else if (lp->chipset == DC21040)
  1539. next_tick = dc21040_autoconf(dev);
  1540. lp->linkOK = 0;
  1541. dt = (next_tick * HZ) / 1000;
  1542. if (!dt)
  1543. dt = 1;
  1544. mod_timer(&lp->timer, jiffies + dt);
  1545. }
  1546. static int
  1547. de4x5_txur(struct net_device *dev)
  1548. {
  1549. struct de4x5_private *lp = netdev_priv(dev);
  1550. u_long iobase = dev->base_addr;
  1551. int omr;
  1552. omr = inl(DE4X5_OMR);
  1553. if (!(omr & OMR_SF) || (lp->chipset==DC21041) || (lp->chipset==DC21040)) {
  1554. omr &= ~(OMR_ST|OMR_SR);
  1555. outl(omr, DE4X5_OMR);
  1556. while (inl(DE4X5_STS) & STS_TS);
  1557. if ((omr & OMR_TR) < OMR_TR) {
  1558. omr += 0x4000;
  1559. } else {
  1560. omr |= OMR_SF;
  1561. }
  1562. outl(omr | OMR_ST | OMR_SR, DE4X5_OMR);
  1563. }
  1564. return 0;
  1565. }
  1566. static int
  1567. de4x5_rx_ovfc(struct net_device *dev)
  1568. {
  1569. struct de4x5_private *lp = netdev_priv(dev);
  1570. u_long iobase = dev->base_addr;
  1571. int omr;
  1572. omr = inl(DE4X5_OMR);
  1573. outl(omr & ~OMR_SR, DE4X5_OMR);
  1574. while (inl(DE4X5_STS) & STS_RS);
  1575. for (; (s32)le32_to_cpu(lp->rx_ring[lp->rx_new].status)>=0;) {
  1576. lp->rx_ring[lp->rx_new].status = cpu_to_le32(R_OWN);
  1577. lp->rx_new = (lp->rx_new + 1) % lp->rxRingSize;
  1578. }
  1579. outl(omr, DE4X5_OMR);
  1580. return 0;
  1581. }
  1582. static int
  1583. de4x5_close(struct net_device *dev)
  1584. {
  1585. struct de4x5_private *lp = netdev_priv(dev);
  1586. u_long iobase = dev->base_addr;
  1587. s32 imr, omr;
  1588. disable_ast(dev);
  1589. netif_stop_queue(dev);
  1590. if (de4x5_debug & DEBUG_CLOSE) {
  1591. printk("%s: Shutting down ethercard, status was %8.8x.\n",
  1592. dev->name, inl(DE4X5_STS));
  1593. }
  1594. /*
  1595. ** We stop the DE4X5 here... mask interrupts and stop TX & RX
  1596. */
  1597. DISABLE_IRQs;
  1598. STOP_DE4X5;
  1599. /* Free the associated irq */
  1600. free_irq(dev->irq, dev);
  1601. lp->state = CLOSED;
  1602. /* Free any socket buffers */
  1603. de4x5_free_rx_buffs(dev);
  1604. de4x5_free_tx_buffs(dev);
  1605. /* Put the adapter to sleep to save power */
  1606. yawn(dev, SLEEP);
  1607. return 0;
  1608. }
  1609. static struct net_device_stats *
  1610. de4x5_get_stats(struct net_device *dev)
  1611. {
  1612. struct de4x5_private *lp = netdev_priv(dev);
  1613. u_long iobase = dev->base_addr;
  1614. lp->stats.rx_missed_errors = (int)(inl(DE4X5_MFC) & (MFC_OVFL | MFC_CNTR));
  1615. return &lp->stats;
  1616. }
  1617. static void
  1618. de4x5_local_stats(struct net_device *dev, char *buf, int pkt_len)
  1619. {
  1620. struct de4x5_private *lp = netdev_priv(dev);
  1621. int i;
  1622. for (i=1; i<DE4X5_PKT_STAT_SZ-1; i++) {
  1623. if (pkt_len < (i*DE4X5_PKT_BIN_SZ)) {
  1624. lp->pktStats.bins[i]++;
  1625. i = DE4X5_PKT_STAT_SZ;
  1626. }
  1627. }
  1628. if (is_multicast_ether_addr(buf)) {
  1629. if (is_broadcast_ether_addr(buf)) {
  1630. lp->pktStats.broadcast++;
  1631. } else {
  1632. lp->pktStats.multicast++;
  1633. }
  1634. } else if (ether_addr_equal(buf, dev->dev_addr)) {
  1635. lp->pktStats.unicast++;
  1636. }
  1637. lp->pktStats.bins[0]++; /* Duplicates stats.rx_packets */
  1638. if (lp->pktStats.bins[0] == 0) { /* Reset counters */
  1639. memset((char *)&lp->pktStats, 0, sizeof(lp->pktStats));
  1640. }
  1641. }
  1642. /*
  1643. ** Removes the TD_IC flag from previous descriptor to improve TX performance.
  1644. ** If the flag is changed on a descriptor that is being read by the hardware,
  1645. ** I assume PCI transaction ordering will mean you are either successful or
  1646. ** just miss asserting the change to the hardware. Anyway you're messing with
  1647. ** a descriptor you don't own, but this shouldn't kill the chip provided
  1648. ** the descriptor register is read only to the hardware.
  1649. */
  1650. static void
  1651. load_packet(struct net_device *dev, char *buf, u32 flags, struct sk_buff *skb)
  1652. {
  1653. struct de4x5_private *lp = netdev_priv(dev);
  1654. int entry = (lp->tx_new ? lp->tx_new-1 : lp->txRingSize-1);
  1655. dma_addr_t buf_dma = dma_map_single(lp->gendev, buf, flags & TD_TBS1, DMA_TO_DEVICE);
  1656. lp->tx_ring[lp->tx_new].buf = cpu_to_le32(buf_dma);
  1657. lp->tx_ring[lp->tx_new].des1 &= cpu_to_le32(TD_TER);
  1658. lp->tx_ring[lp->tx_new].des1 |= cpu_to_le32(flags);
  1659. lp->tx_skb[lp->tx_new] = skb;
  1660. lp->tx_ring[entry].des1 &= cpu_to_le32(~TD_IC);
  1661. barrier();
  1662. lp->tx_ring[lp->tx_new].status = cpu_to_le32(T_OWN);
  1663. barrier();
  1664. }
  1665. /*
  1666. ** Set or clear the multicast filter for this adaptor.
  1667. */
  1668. static void
  1669. set_multicast_list(struct net_device *dev)
  1670. {
  1671. struct de4x5_private *lp = netdev_priv(dev);
  1672. u_long iobase = dev->base_addr;
  1673. /* First, double check that the adapter is open */
  1674. if (lp->state == OPEN) {
  1675. if (dev->flags & IFF_PROMISC) { /* set promiscuous mode */
  1676. u32 omr;
  1677. omr = inl(DE4X5_OMR);
  1678. omr |= OMR_PR;
  1679. outl(omr, DE4X5_OMR);
  1680. } else {
  1681. SetMulticastFilter(dev);
  1682. load_packet(dev, lp->setup_frame, TD_IC | PERFECT_F | TD_SET |
  1683. SETUP_FRAME_LEN, (struct sk_buff *)1);
  1684. lp->tx_new = (lp->tx_new + 1) % lp->txRingSize;
  1685. outl(POLL_DEMAND, DE4X5_TPD); /* Start the TX */
  1686. netif_trans_update(dev); /* prevent tx timeout */
  1687. }
  1688. }
  1689. }
  1690. /*
  1691. ** Calculate the hash code and update the logical address filter
  1692. ** from a list of ethernet multicast addresses.
  1693. ** Little endian crc one liner from Matt Thomas, DEC.
  1694. */
  1695. static void
  1696. SetMulticastFilter(struct net_device *dev)
  1697. {
  1698. struct de4x5_private *lp = netdev_priv(dev);
  1699. struct netdev_hw_addr *ha;
  1700. u_long iobase = dev->base_addr;
  1701. int i, bit, byte;
  1702. u16 hashcode;
  1703. u32 omr, crc;
  1704. char *pa;
  1705. unsigned char *addrs;
  1706. omr = inl(DE4X5_OMR);
  1707. omr &= ~(OMR_PR | OMR_PM);
  1708. pa = build_setup_frame(dev, ALL); /* Build the basic frame */
  1709. if ((dev->flags & IFF_ALLMULTI) || (netdev_mc_count(dev) > 14)) {
  1710. omr |= OMR_PM; /* Pass all multicasts */
  1711. } else if (lp->setup_f == HASH_PERF) { /* Hash Filtering */
  1712. netdev_for_each_mc_addr(ha, dev) {
  1713. crc = ether_crc_le(ETH_ALEN, ha->addr);
  1714. hashcode = crc & DE4X5_HASH_BITS; /* hashcode is 9 LSb of CRC */
  1715. byte = hashcode >> 3; /* bit[3-8] -> byte in filter */
  1716. bit = 1 << (hashcode & 0x07);/* bit[0-2] -> bit in byte */
  1717. byte <<= 1; /* calc offset into setup frame */
  1718. if (byte & 0x02) {
  1719. byte -= 1;
  1720. }
  1721. lp->setup_frame[byte] |= bit;
  1722. }
  1723. } else { /* Perfect filtering */
  1724. netdev_for_each_mc_addr(ha, dev) {
  1725. addrs = ha->addr;
  1726. for (i=0; i<ETH_ALEN; i++) {
  1727. *(pa + (i&1)) = *addrs++;
  1728. if (i & 0x01) pa += 4;
  1729. }
  1730. }
  1731. }
  1732. outl(omr, DE4X5_OMR);
  1733. }
  1734. #ifdef CONFIG_EISA
  1735. static u_char de4x5_irq[] = EISA_ALLOWED_IRQ_LIST;
  1736. static int de4x5_eisa_probe(struct device *gendev)
  1737. {
  1738. struct eisa_device *edev;
  1739. u_long iobase;
  1740. u_char irq, regval;
  1741. u_short vendor;
  1742. u32 cfid;
  1743. int status, device;
  1744. struct net_device *dev;
  1745. struct de4x5_private *lp;
  1746. edev = to_eisa_device (gendev);
  1747. iobase = edev->base_addr;
  1748. if (!request_region (iobase, DE4X5_EISA_TOTAL_SIZE, "de4x5"))
  1749. return -EBUSY;
  1750. if (!request_region (iobase + DE4X5_EISA_IO_PORTS,
  1751. DE4X5_EISA_TOTAL_SIZE, "de4x5")) {
  1752. status = -EBUSY;
  1753. goto release_reg_1;
  1754. }
  1755. if (!(dev = alloc_etherdev (sizeof (struct de4x5_private)))) {
  1756. status = -ENOMEM;
  1757. goto release_reg_2;
  1758. }
  1759. lp = netdev_priv(dev);
  1760. cfid = (u32) inl(PCI_CFID);
  1761. lp->cfrv = (u_short) inl(PCI_CFRV);
  1762. device = (cfid >> 8) & 0x00ffff00;
  1763. vendor = (u_short) cfid;
  1764. /* Read the EISA Configuration Registers */
  1765. regval = inb(EISA_REG0) & (ER0_INTL | ER0_INTT);
  1766. #ifdef CONFIG_ALPHA
  1767. /* Looks like the Jensen firmware (rev 2.2) doesn't really
  1768. * care about the EISA configuration, and thus doesn't
  1769. * configure the PLX bridge properly. Oh well... Simply mimic
  1770. * the EISA config file to sort it out. */
  1771. /* EISA REG1: Assert DecChip 21040 HW Reset */
  1772. outb (ER1_IAM | 1, EISA_REG1);
  1773. mdelay (1);
  1774. /* EISA REG1: Deassert DecChip 21040 HW Reset */
  1775. outb (ER1_IAM, EISA_REG1);
  1776. mdelay (1);
  1777. /* EISA REG3: R/W Burst Transfer Enable */
  1778. outb (ER3_BWE | ER3_BRE, EISA_REG3);
  1779. /* 32_bit slave/master, Preempt Time=23 bclks, Unlatched Interrupt */
  1780. outb (ER0_BSW | ER0_BMW | ER0_EPT | regval, EISA_REG0);
  1781. #endif
  1782. irq = de4x5_irq[(regval >> 1) & 0x03];
  1783. if (is_DC2114x) {
  1784. device = ((lp->cfrv & CFRV_RN) < DC2114x_BRK ? DC21142 : DC21143);
  1785. }
  1786. lp->chipset = device;
  1787. lp->bus = EISA;
  1788. /* Write the PCI Configuration Registers */
  1789. outl(PCI_COMMAND_IO | PCI_COMMAND_MASTER, PCI_CFCS);
  1790. outl(0x00006000, PCI_CFLT);
  1791. outl(iobase, PCI_CBIO);
  1792. DevicePresent(dev, EISA_APROM);
  1793. dev->irq = irq;
  1794. if (!(status = de4x5_hw_init (dev, iobase, gendev))) {
  1795. return 0;
  1796. }
  1797. free_netdev (dev);
  1798. release_reg_2:
  1799. release_region (iobase + DE4X5_EISA_IO_PORTS, DE4X5_EISA_TOTAL_SIZE);
  1800. release_reg_1:
  1801. release_region (iobase, DE4X5_EISA_TOTAL_SIZE);
  1802. return status;
  1803. }
  1804. static int de4x5_eisa_remove(struct device *device)
  1805. {
  1806. struct net_device *dev;
  1807. u_long iobase;
  1808. dev = dev_get_drvdata(device);
  1809. iobase = dev->base_addr;
  1810. unregister_netdev (dev);
  1811. free_netdev (dev);
  1812. release_region (iobase + DE4X5_EISA_IO_PORTS, DE4X5_EISA_TOTAL_SIZE);
  1813. release_region (iobase, DE4X5_EISA_TOTAL_SIZE);
  1814. return 0;
  1815. }
  1816. static const struct eisa_device_id de4x5_eisa_ids[] = {
  1817. { "DEC4250", 0 }, /* 0 is the board name index... */
  1818. { "" }
  1819. };
  1820. MODULE_DEVICE_TABLE(eisa, de4x5_eisa_ids);
  1821. static struct eisa_driver de4x5_eisa_driver = {
  1822. .id_table = de4x5_eisa_ids,
  1823. .driver = {
  1824. .name = "de4x5",
  1825. .probe = de4x5_eisa_probe,
  1826. .remove = de4x5_eisa_remove,
  1827. }
  1828. };
  1829. #endif
  1830. #ifdef CONFIG_PCI
  1831. /*
  1832. ** This function searches the current bus (which is >0) for a DECchip with an
  1833. ** SROM, so that in multiport cards that have one SROM shared between multiple
  1834. ** DECchips, we can find the base SROM irrespective of the BIOS scan direction.
  1835. ** For single port cards this is a time waster...
  1836. */
  1837. static void
  1838. srom_search(struct net_device *dev, struct pci_dev *pdev)
  1839. {
  1840. u_char pb;
  1841. u_short vendor, status;
  1842. u_int irq = 0, device;
  1843. u_long iobase = 0; /* Clear upper 32 bits in Alphas */
  1844. int i, j;
  1845. struct de4x5_private *lp = netdev_priv(dev);
  1846. struct pci_dev *this_dev;
  1847. list_for_each_entry(this_dev, &pdev->bus->devices, bus_list) {
  1848. vendor = this_dev->vendor;
  1849. device = this_dev->device << 8;
  1850. if (!(is_DC21040 || is_DC21041 || is_DC21140 || is_DC2114x)) continue;
  1851. /* Get the chip configuration revision register */
  1852. pb = this_dev->bus->number;
  1853. /* Set the device number information */
  1854. lp->device = PCI_SLOT(this_dev->devfn);
  1855. lp->bus_num = pb;
  1856. /* Set the chipset information */
  1857. if (is_DC2114x) {
  1858. device = ((this_dev->revision & CFRV_RN) < DC2114x_BRK
  1859. ? DC21142 : DC21143);
  1860. }
  1861. lp->chipset = device;
  1862. /* Get the board I/O address (64 bits on sparc64) */
  1863. iobase = pci_resource_start(this_dev, 0);
  1864. /* Fetch the IRQ to be used */
  1865. irq = this_dev->irq;
  1866. if ((irq == 0) || (irq == 0xff) || ((int)irq == -1)) continue;
  1867. /* Check if I/O accesses are enabled */
  1868. pci_read_config_word(this_dev, PCI_COMMAND, &status);
  1869. if (!(status & PCI_COMMAND_IO)) continue;
  1870. /* Search for a valid SROM attached to this DECchip */
  1871. DevicePresent(dev, DE4X5_APROM);
  1872. for (j=0, i=0; i<ETH_ALEN; i++) {
  1873. j += (u_char) *((u_char *)&lp->srom + SROM_HWADD + i);
  1874. }
  1875. if (j != 0 && j != 6 * 0xff) {
  1876. last.chipset = device;
  1877. last.bus = pb;
  1878. last.irq = irq;
  1879. for (i=0; i<ETH_ALEN; i++) {
  1880. last.addr[i] = (u_char)*((u_char *)&lp->srom + SROM_HWADD + i);
  1881. }
  1882. return;
  1883. }
  1884. }
  1885. }
  1886. /*
  1887. ** PCI bus I/O device probe
  1888. ** NB: PCI I/O accesses and Bus Mastering are enabled by the PCI BIOS, not
  1889. ** the driver. Some PCI BIOS's, pre V2.1, need the slot + features to be
  1890. ** enabled by the user first in the set up utility. Hence we just check for
  1891. ** enabled features and silently ignore the card if they're not.
  1892. **
  1893. ** STOP PRESS: Some BIOS's __require__ the driver to enable the bus mastering
  1894. ** bit. Here, check for I/O accesses and then set BM. If you put the card in
  1895. ** a non BM slot, you're on your own (and complain to the PC vendor that your
  1896. ** PC doesn't conform to the PCI standard)!
  1897. **
  1898. ** This function is only compatible with the *latest* 2.1.x kernels. For 2.0.x
  1899. ** kernels use the V0.535[n] drivers.
  1900. */
  1901. static int de4x5_pci_probe(struct pci_dev *pdev,
  1902. const struct pci_device_id *ent)
  1903. {
  1904. u_char pb, pbus = 0, dev_num, dnum = 0, timer;
  1905. u_short vendor, status;
  1906. u_int irq = 0, device;
  1907. u_long iobase = 0; /* Clear upper 32 bits in Alphas */
  1908. int error;
  1909. struct net_device *dev;
  1910. struct de4x5_private *lp;
  1911. dev_num = PCI_SLOT(pdev->devfn);
  1912. pb = pdev->bus->number;
  1913. if (io) { /* probe a single PCI device */
  1914. pbus = (u_short)(io >> 8);
  1915. dnum = (u_short)(io & 0xff);
  1916. if ((pbus != pb) || (dnum != dev_num))
  1917. return -ENODEV;
  1918. }
  1919. vendor = pdev->vendor;
  1920. device = pdev->device << 8;
  1921. if (!(is_DC21040 || is_DC21041 || is_DC21140 || is_DC2114x))
  1922. return -ENODEV;
  1923. /* Ok, the device seems to be for us. */
  1924. if ((error = pci_enable_device (pdev)))
  1925. return error;
  1926. if (!(dev = alloc_etherdev (sizeof (struct de4x5_private)))) {
  1927. error = -ENOMEM;
  1928. goto disable_dev;
  1929. }
  1930. lp = netdev_priv(dev);
  1931. lp->bus = PCI;
  1932. lp->bus_num = 0;
  1933. /* Search for an SROM on this bus */
  1934. if (lp->bus_num != pb) {
  1935. lp->bus_num = pb;
  1936. srom_search(dev, pdev);
  1937. }
  1938. /* Get the chip configuration revision register */
  1939. lp->cfrv = pdev->revision;
  1940. /* Set the device number information */
  1941. lp->device = dev_num;
  1942. lp->bus_num = pb;
  1943. /* Set the chipset information */
  1944. if (is_DC2114x) {
  1945. device = ((lp->cfrv & CFRV_RN) < DC2114x_BRK ? DC21142 : DC21143);
  1946. }
  1947. lp->chipset = device;
  1948. /* Get the board I/O address (64 bits on sparc64) */
  1949. iobase = pci_resource_start(pdev, 0);
  1950. /* Fetch the IRQ to be used */
  1951. irq = pdev->irq;
  1952. if ((irq == 0) || (irq == 0xff) || ((int)irq == -1)) {
  1953. error = -ENODEV;
  1954. goto free_dev;
  1955. }
  1956. /* Check if I/O accesses and Bus Mastering are enabled */
  1957. pci_read_config_word(pdev, PCI_COMMAND, &status);
  1958. #ifdef __powerpc__
  1959. if (!(status & PCI_COMMAND_IO)) {
  1960. status |= PCI_COMMAND_IO;
  1961. pci_write_config_word(pdev, PCI_COMMAND, status);
  1962. pci_read_config_word(pdev, PCI_COMMAND, &status);
  1963. }
  1964. #endif /* __powerpc__ */
  1965. if (!(status & PCI_COMMAND_IO)) {
  1966. error = -ENODEV;
  1967. goto free_dev;
  1968. }
  1969. if (!(status & PCI_COMMAND_MASTER)) {
  1970. status |= PCI_COMMAND_MASTER;
  1971. pci_write_config_word(pdev, PCI_COMMAND, status);
  1972. pci_read_config_word(pdev, PCI_COMMAND, &status);
  1973. }
  1974. if (!(status & PCI_COMMAND_MASTER)) {
  1975. error = -ENODEV;
  1976. goto free_dev;
  1977. }
  1978. /* Check the latency timer for values >= 0x60 */
  1979. pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &timer);
  1980. if (timer < 0x60) {
  1981. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x60);
  1982. }
  1983. DevicePresent(dev, DE4X5_APROM);
  1984. if (!request_region (iobase, DE4X5_PCI_TOTAL_SIZE, "de4x5")) {
  1985. error = -EBUSY;
  1986. goto free_dev;
  1987. }
  1988. dev->irq = irq;
  1989. if ((error = de4x5_hw_init(dev, iobase, &pdev->dev))) {
  1990. goto release;
  1991. }
  1992. return 0;
  1993. release:
  1994. release_region (iobase, DE4X5_PCI_TOTAL_SIZE);
  1995. free_dev:
  1996. free_netdev (dev);
  1997. disable_dev:
  1998. pci_disable_device (pdev);
  1999. return error;
  2000. }
  2001. static void de4x5_pci_remove(struct pci_dev *pdev)
  2002. {
  2003. struct net_device *dev;
  2004. u_long iobase;
  2005. dev = pci_get_drvdata(pdev);
  2006. iobase = dev->base_addr;
  2007. unregister_netdev (dev);
  2008. free_netdev (dev);
  2009. release_region (iobase, DE4X5_PCI_TOTAL_SIZE);
  2010. pci_disable_device (pdev);
  2011. }
  2012. static const struct pci_device_id de4x5_pci_tbl[] = {
  2013. { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_TULIP,
  2014. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  2015. { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_TULIP_PLUS,
  2016. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
  2017. { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_TULIP_FAST,
  2018. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
  2019. { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_21142,
  2020. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
  2021. { },
  2022. };
  2023. static struct pci_driver de4x5_pci_driver = {
  2024. .name = "de4x5",
  2025. .id_table = de4x5_pci_tbl,
  2026. .probe = de4x5_pci_probe,
  2027. .remove = de4x5_pci_remove,
  2028. };
  2029. #endif
  2030. /*
  2031. ** Auto configure the media here rather than setting the port at compile
  2032. ** time. This routine is called by de4x5_init() and when a loss of media is
  2033. ** detected (excessive collisions, loss of carrier, no carrier or link fail
  2034. ** [TP] or no recent receive activity) to check whether the user has been
  2035. ** sneaky and changed the port on us.
  2036. */
  2037. static int
  2038. autoconf_media(struct net_device *dev)
  2039. {
  2040. struct de4x5_private *lp = netdev_priv(dev);
  2041. u_long iobase = dev->base_addr;
  2042. disable_ast(dev);
  2043. lp->c_media = AUTO; /* Bogus last media */
  2044. inl(DE4X5_MFC); /* Zero the lost frames counter */
  2045. lp->media = INIT;
  2046. lp->tcount = 0;
  2047. de4x5_ast(&lp->timer);
  2048. return lp->media;
  2049. }
  2050. /*
  2051. ** Autoconfigure the media when using the DC21040. AUI cannot be distinguished
  2052. ** from BNC as the port has a jumper to set thick or thin wire. When set for
  2053. ** BNC, the BNC port will indicate activity if it's not terminated correctly.
  2054. ** The only way to test for that is to place a loopback packet onto the
  2055. ** network and watch for errors. Since we're messing with the interrupt mask
  2056. ** register, disable the board interrupts and do not allow any more packets to
  2057. ** be queued to the hardware. Re-enable everything only when the media is
  2058. ** found.
  2059. ** I may have to "age out" locally queued packets so that the higher layer
  2060. ** timeouts don't effectively duplicate packets on the network.
  2061. */
  2062. static int
  2063. dc21040_autoconf(struct net_device *dev)
  2064. {
  2065. struct de4x5_private *lp = netdev_priv(dev);
  2066. u_long iobase = dev->base_addr;
  2067. int next_tick = DE4X5_AUTOSENSE_MS;
  2068. s32 imr;
  2069. switch (lp->media) {
  2070. case INIT:
  2071. DISABLE_IRQs;
  2072. lp->tx_enable = false;
  2073. lp->timeout = -1;
  2074. de4x5_save_skbs(dev);
  2075. if ((lp->autosense == AUTO) || (lp->autosense == TP)) {
  2076. lp->media = TP;
  2077. } else if ((lp->autosense == BNC) || (lp->autosense == AUI) || (lp->autosense == BNC_AUI)) {
  2078. lp->media = BNC_AUI;
  2079. } else if (lp->autosense == EXT_SIA) {
  2080. lp->media = EXT_SIA;
  2081. } else {
  2082. lp->media = NC;
  2083. }
  2084. lp->local_state = 0;
  2085. next_tick = dc21040_autoconf(dev);
  2086. break;
  2087. case TP:
  2088. next_tick = dc21040_state(dev, 0x8f01, 0xffff, 0x0000, 3000, BNC_AUI,
  2089. TP_SUSPECT, test_tp);
  2090. break;
  2091. case TP_SUSPECT:
  2092. next_tick = de4x5_suspect_state(dev, 1000, TP, test_tp, dc21040_autoconf);
  2093. break;
  2094. case BNC:
  2095. case AUI:
  2096. case BNC_AUI:
  2097. next_tick = dc21040_state(dev, 0x8f09, 0x0705, 0x0006, 3000, EXT_SIA,
  2098. BNC_AUI_SUSPECT, ping_media);
  2099. break;
  2100. case BNC_AUI_SUSPECT:
  2101. next_tick = de4x5_suspect_state(dev, 1000, BNC_AUI, ping_media, dc21040_autoconf);
  2102. break;
  2103. case EXT_SIA:
  2104. next_tick = dc21040_state(dev, 0x3041, 0x0000, 0x0006, 3000,
  2105. NC, EXT_SIA_SUSPECT, ping_media);
  2106. break;
  2107. case EXT_SIA_SUSPECT:
  2108. next_tick = de4x5_suspect_state(dev, 1000, EXT_SIA, ping_media, dc21040_autoconf);
  2109. break;
  2110. case NC:
  2111. /* default to TP for all */
  2112. reset_init_sia(dev, 0x8f01, 0xffff, 0x0000);
  2113. if (lp->media != lp->c_media) {
  2114. de4x5_dbg_media(dev);
  2115. lp->c_media = lp->media;
  2116. }
  2117. lp->media = INIT;
  2118. lp->tx_enable = false;
  2119. break;
  2120. }
  2121. return next_tick;
  2122. }
  2123. static int
  2124. dc21040_state(struct net_device *dev, int csr13, int csr14, int csr15, int timeout,
  2125. int next_state, int suspect_state,
  2126. int (*fn)(struct net_device *, int))
  2127. {
  2128. struct de4x5_private *lp = netdev_priv(dev);
  2129. int next_tick = DE4X5_AUTOSENSE_MS;
  2130. int linkBad;
  2131. switch (lp->local_state) {
  2132. case 0:
  2133. reset_init_sia(dev, csr13, csr14, csr15);
  2134. lp->local_state++;
  2135. next_tick = 500;
  2136. break;
  2137. case 1:
  2138. if (!lp->tx_enable) {
  2139. linkBad = fn(dev, timeout);
  2140. if (linkBad < 0) {
  2141. next_tick = linkBad & ~TIMER_CB;
  2142. } else {
  2143. if (linkBad && (lp->autosense == AUTO)) {
  2144. lp->local_state = 0;
  2145. lp->media = next_state;
  2146. } else {
  2147. de4x5_init_connection(dev);
  2148. }
  2149. }
  2150. } else if (!lp->linkOK && (lp->autosense == AUTO)) {
  2151. lp->media = suspect_state;
  2152. next_tick = 3000;
  2153. }
  2154. break;
  2155. }
  2156. return next_tick;
  2157. }
  2158. static int
  2159. de4x5_suspect_state(struct net_device *dev, int timeout, int prev_state,
  2160. int (*fn)(struct net_device *, int),
  2161. int (*asfn)(struct net_device *))
  2162. {
  2163. struct de4x5_private *lp = netdev_priv(dev);
  2164. int next_tick = DE4X5_AUTOSENSE_MS;
  2165. int linkBad;
  2166. switch (lp->local_state) {
  2167. case 1:
  2168. if (lp->linkOK) {
  2169. lp->media = prev_state;
  2170. } else {
  2171. lp->local_state++;
  2172. next_tick = asfn(dev);
  2173. }
  2174. break;
  2175. case 2:
  2176. linkBad = fn(dev, timeout);
  2177. if (linkBad < 0) {
  2178. next_tick = linkBad & ~TIMER_CB;
  2179. } else if (!linkBad) {
  2180. lp->local_state--;
  2181. lp->media = prev_state;
  2182. } else {
  2183. lp->media = INIT;
  2184. lp->tcount++;
  2185. }
  2186. }
  2187. return next_tick;
  2188. }
  2189. /*
  2190. ** Autoconfigure the media when using the DC21041. AUI needs to be tested
  2191. ** before BNC, because the BNC port will indicate activity if it's not
  2192. ** terminated correctly. The only way to test for that is to place a loopback
  2193. ** packet onto the network and watch for errors. Since we're messing with
  2194. ** the interrupt mask register, disable the board interrupts and do not allow
  2195. ** any more packets to be queued to the hardware. Re-enable everything only
  2196. ** when the media is found.
  2197. */
  2198. static int
  2199. dc21041_autoconf(struct net_device *dev)
  2200. {
  2201. struct de4x5_private *lp = netdev_priv(dev);
  2202. u_long iobase = dev->base_addr;
  2203. s32 sts, irqs, irq_mask, imr, omr;
  2204. int next_tick = DE4X5_AUTOSENSE_MS;
  2205. switch (lp->media) {
  2206. case INIT:
  2207. DISABLE_IRQs;
  2208. lp->tx_enable = false;
  2209. lp->timeout = -1;
  2210. de4x5_save_skbs(dev); /* Save non transmitted skb's */
  2211. if ((lp->autosense == AUTO) || (lp->autosense == TP_NW)) {
  2212. lp->media = TP; /* On chip auto negotiation is broken */
  2213. } else if (lp->autosense == TP) {
  2214. lp->media = TP;
  2215. } else if (lp->autosense == BNC) {
  2216. lp->media = BNC;
  2217. } else if (lp->autosense == AUI) {
  2218. lp->media = AUI;
  2219. } else {
  2220. lp->media = NC;
  2221. }
  2222. lp->local_state = 0;
  2223. next_tick = dc21041_autoconf(dev);
  2224. break;
  2225. case TP_NW:
  2226. if (lp->timeout < 0) {
  2227. omr = inl(DE4X5_OMR);/* Set up full duplex for the autonegotiate */
  2228. outl(omr | OMR_FDX, DE4X5_OMR);
  2229. }
  2230. irqs = STS_LNF | STS_LNP;
  2231. irq_mask = IMR_LFM | IMR_LPM;
  2232. sts = test_media(dev, irqs, irq_mask, 0xef01, 0xffff, 0x0008, 2400);
  2233. if (sts < 0) {
  2234. next_tick = sts & ~TIMER_CB;
  2235. } else {
  2236. if (sts & STS_LNP) {
  2237. lp->media = ANS;
  2238. } else {
  2239. lp->media = AUI;
  2240. }
  2241. next_tick = dc21041_autoconf(dev);
  2242. }
  2243. break;
  2244. case ANS:
  2245. if (!lp->tx_enable) {
  2246. irqs = STS_LNP;
  2247. irq_mask = IMR_LPM;
  2248. sts = test_ans(dev, irqs, irq_mask, 3000);
  2249. if (sts < 0) {
  2250. next_tick = sts & ~TIMER_CB;
  2251. } else {
  2252. if (!(sts & STS_LNP) && (lp->autosense == AUTO)) {
  2253. lp->media = TP;
  2254. next_tick = dc21041_autoconf(dev);
  2255. } else {
  2256. lp->local_state = 1;
  2257. de4x5_init_connection(dev);
  2258. }
  2259. }
  2260. } else if (!lp->linkOK && (lp->autosense == AUTO)) {
  2261. lp->media = ANS_SUSPECT;
  2262. next_tick = 3000;
  2263. }
  2264. break;
  2265. case ANS_SUSPECT:
  2266. next_tick = de4x5_suspect_state(dev, 1000, ANS, test_tp, dc21041_autoconf);
  2267. break;
  2268. case TP:
  2269. if (!lp->tx_enable) {
  2270. if (lp->timeout < 0) {
  2271. omr = inl(DE4X5_OMR); /* Set up half duplex for TP */
  2272. outl(omr & ~OMR_FDX, DE4X5_OMR);
  2273. }
  2274. irqs = STS_LNF | STS_LNP;
  2275. irq_mask = IMR_LFM | IMR_LPM;
  2276. sts = test_media(dev,irqs, irq_mask, 0xef01, 0xff3f, 0x0008, 2400);
  2277. if (sts < 0) {
  2278. next_tick = sts & ~TIMER_CB;
  2279. } else {
  2280. if (!(sts & STS_LNP) && (lp->autosense == AUTO)) {
  2281. if (inl(DE4X5_SISR) & SISR_NRA) {
  2282. lp->media = AUI; /* Non selected port activity */
  2283. } else {
  2284. lp->media = BNC;
  2285. }
  2286. next_tick = dc21041_autoconf(dev);
  2287. } else {
  2288. lp->local_state = 1;
  2289. de4x5_init_connection(dev);
  2290. }
  2291. }
  2292. } else if (!lp->linkOK && (lp->autosense == AUTO)) {
  2293. lp->media = TP_SUSPECT;
  2294. next_tick = 3000;
  2295. }
  2296. break;
  2297. case TP_SUSPECT:
  2298. next_tick = de4x5_suspect_state(dev, 1000, TP, test_tp, dc21041_autoconf);
  2299. break;
  2300. case AUI:
  2301. if (!lp->tx_enable) {
  2302. if (lp->timeout < 0) {
  2303. omr = inl(DE4X5_OMR); /* Set up half duplex for AUI */
  2304. outl(omr & ~OMR_FDX, DE4X5_OMR);
  2305. }
  2306. irqs = 0;
  2307. irq_mask = 0;
  2308. sts = test_media(dev,irqs, irq_mask, 0xef09, 0xf73d, 0x000e, 1000);
  2309. if (sts < 0) {
  2310. next_tick = sts & ~TIMER_CB;
  2311. } else {
  2312. if (!(inl(DE4X5_SISR) & SISR_SRA) && (lp->autosense == AUTO)) {
  2313. lp->media = BNC;
  2314. next_tick = dc21041_autoconf(dev);
  2315. } else {
  2316. lp->local_state = 1;
  2317. de4x5_init_connection(dev);
  2318. }
  2319. }
  2320. } else if (!lp->linkOK && (lp->autosense == AUTO)) {
  2321. lp->media = AUI_SUSPECT;
  2322. next_tick = 3000;
  2323. }
  2324. break;
  2325. case AUI_SUSPECT:
  2326. next_tick = de4x5_suspect_state(dev, 1000, AUI, ping_media, dc21041_autoconf);
  2327. break;
  2328. case BNC:
  2329. switch (lp->local_state) {
  2330. case 0:
  2331. if (lp->timeout < 0) {
  2332. omr = inl(DE4X5_OMR); /* Set up half duplex for BNC */
  2333. outl(omr & ~OMR_FDX, DE4X5_OMR);
  2334. }
  2335. irqs = 0;
  2336. irq_mask = 0;
  2337. sts = test_media(dev,irqs, irq_mask, 0xef09, 0xf73d, 0x0006, 1000);
  2338. if (sts < 0) {
  2339. next_tick = sts & ~TIMER_CB;
  2340. } else {
  2341. lp->local_state++; /* Ensure media connected */
  2342. next_tick = dc21041_autoconf(dev);
  2343. }
  2344. break;
  2345. case 1:
  2346. if (!lp->tx_enable) {
  2347. if ((sts = ping_media(dev, 3000)) < 0) {
  2348. next_tick = sts & ~TIMER_CB;
  2349. } else {
  2350. if (sts) {
  2351. lp->local_state = 0;
  2352. lp->media = NC;
  2353. } else {
  2354. de4x5_init_connection(dev);
  2355. }
  2356. }
  2357. } else if (!lp->linkOK && (lp->autosense == AUTO)) {
  2358. lp->media = BNC_SUSPECT;
  2359. next_tick = 3000;
  2360. }
  2361. break;
  2362. }
  2363. break;
  2364. case BNC_SUSPECT:
  2365. next_tick = de4x5_suspect_state(dev, 1000, BNC, ping_media, dc21041_autoconf);
  2366. break;
  2367. case NC:
  2368. omr = inl(DE4X5_OMR); /* Set up full duplex for the autonegotiate */
  2369. outl(omr | OMR_FDX, DE4X5_OMR);
  2370. reset_init_sia(dev, 0xef01, 0xffff, 0x0008);/* Initialise the SIA */
  2371. if (lp->media != lp->c_media) {
  2372. de4x5_dbg_media(dev);
  2373. lp->c_media = lp->media;
  2374. }
  2375. lp->media = INIT;
  2376. lp->tx_enable = false;
  2377. break;
  2378. }
  2379. return next_tick;
  2380. }
  2381. /*
  2382. ** Some autonegotiation chips are broken in that they do not return the
  2383. ** acknowledge bit (anlpa & MII_ANLPA_ACK) in the link partner advertisement
  2384. ** register, except at the first power up negotiation.
  2385. */
  2386. static int
  2387. dc21140m_autoconf(struct net_device *dev)
  2388. {
  2389. struct de4x5_private *lp = netdev_priv(dev);
  2390. int ana, anlpa, cap, cr, slnk, sr;
  2391. int next_tick = DE4X5_AUTOSENSE_MS;
  2392. u_long imr, omr, iobase = dev->base_addr;
  2393. switch(lp->media) {
  2394. case INIT:
  2395. if (lp->timeout < 0) {
  2396. DISABLE_IRQs;
  2397. lp->tx_enable = false;
  2398. lp->linkOK = 0;
  2399. de4x5_save_skbs(dev); /* Save non transmitted skb's */
  2400. }
  2401. if ((next_tick = de4x5_reset_phy(dev)) < 0) {
  2402. next_tick &= ~TIMER_CB;
  2403. } else {
  2404. if (lp->useSROM) {
  2405. if (srom_map_media(dev) < 0) {
  2406. lp->tcount++;
  2407. return next_tick;
  2408. }
  2409. srom_exec(dev, lp->phy[lp->active].gep);
  2410. if (lp->infoblock_media == ANS) {
  2411. ana = lp->phy[lp->active].ana | MII_ANA_CSMA;
  2412. mii_wr(ana, MII_ANA, lp->phy[lp->active].addr, DE4X5_MII);
  2413. }
  2414. } else {
  2415. lp->tmp = MII_SR_ASSC; /* Fake out the MII speed set */
  2416. SET_10Mb;
  2417. if (lp->autosense == _100Mb) {
  2418. lp->media = _100Mb;
  2419. } else if (lp->autosense == _10Mb) {
  2420. lp->media = _10Mb;
  2421. } else if ((lp->autosense == AUTO) &&
  2422. ((sr=is_anc_capable(dev)) & MII_SR_ANC)) {
  2423. ana = (((sr >> 6) & MII_ANA_TAF) | MII_ANA_CSMA);
  2424. ana &= (lp->fdx ? ~0 : ~MII_ANA_FDAM);
  2425. mii_wr(ana, MII_ANA, lp->phy[lp->active].addr, DE4X5_MII);
  2426. lp->media = ANS;
  2427. } else if (lp->autosense == AUTO) {
  2428. lp->media = SPD_DET;
  2429. } else if (is_spd_100(dev) && is_100_up(dev)) {
  2430. lp->media = _100Mb;
  2431. } else {
  2432. lp->media = NC;
  2433. }
  2434. }
  2435. lp->local_state = 0;
  2436. next_tick = dc21140m_autoconf(dev);
  2437. }
  2438. break;
  2439. case ANS:
  2440. switch (lp->local_state) {
  2441. case 0:
  2442. if (lp->timeout < 0) {
  2443. mii_wr(MII_CR_ASSE | MII_CR_RAN, MII_CR, lp->phy[lp->active].addr, DE4X5_MII);
  2444. }
  2445. cr = test_mii_reg(dev, MII_CR, MII_CR_RAN, false, 500);
  2446. if (cr < 0) {
  2447. next_tick = cr & ~TIMER_CB;
  2448. } else {
  2449. if (cr) {
  2450. lp->local_state = 0;
  2451. lp->media = SPD_DET;
  2452. } else {
  2453. lp->local_state++;
  2454. }
  2455. next_tick = dc21140m_autoconf(dev);
  2456. }
  2457. break;
  2458. case 1:
  2459. if ((sr=test_mii_reg(dev, MII_SR, MII_SR_ASSC, true, 2000)) < 0) {
  2460. next_tick = sr & ~TIMER_CB;
  2461. } else {
  2462. lp->media = SPD_DET;
  2463. lp->local_state = 0;
  2464. if (sr) { /* Success! */
  2465. lp->tmp = MII_SR_ASSC;
  2466. anlpa = mii_rd(MII_ANLPA, lp->phy[lp->active].addr, DE4X5_MII);
  2467. ana = mii_rd(MII_ANA, lp->phy[lp->active].addr, DE4X5_MII);
  2468. if (!(anlpa & MII_ANLPA_RF) &&
  2469. (cap = anlpa & MII_ANLPA_TAF & ana)) {
  2470. if (cap & MII_ANA_100M) {
  2471. lp->fdx = (ana & anlpa & MII_ANA_FDAM & MII_ANA_100M) != 0;
  2472. lp->media = _100Mb;
  2473. } else if (cap & MII_ANA_10M) {
  2474. lp->fdx = (ana & anlpa & MII_ANA_FDAM & MII_ANA_10M) != 0;
  2475. lp->media = _10Mb;
  2476. }
  2477. }
  2478. } /* Auto Negotiation failed to finish */
  2479. next_tick = dc21140m_autoconf(dev);
  2480. } /* Auto Negotiation failed to start */
  2481. break;
  2482. }
  2483. break;
  2484. case SPD_DET: /* Choose 10Mb/s or 100Mb/s */
  2485. if (lp->timeout < 0) {
  2486. lp->tmp = (lp->phy[lp->active].id ? MII_SR_LKS :
  2487. (~gep_rd(dev) & GEP_LNP));
  2488. SET_100Mb_PDET;
  2489. }
  2490. if ((slnk = test_for_100Mb(dev, 6500)) < 0) {
  2491. next_tick = slnk & ~TIMER_CB;
  2492. } else {
  2493. if (is_spd_100(dev) && is_100_up(dev)) {
  2494. lp->media = _100Mb;
  2495. } else if ((!is_spd_100(dev) && (is_10_up(dev) & lp->tmp))) {
  2496. lp->media = _10Mb;
  2497. } else {
  2498. lp->media = NC;
  2499. }
  2500. next_tick = dc21140m_autoconf(dev);
  2501. }
  2502. break;
  2503. case _100Mb: /* Set 100Mb/s */
  2504. next_tick = 3000;
  2505. if (!lp->tx_enable) {
  2506. SET_100Mb;
  2507. de4x5_init_connection(dev);
  2508. } else {
  2509. if (!lp->linkOK && (lp->autosense == AUTO)) {
  2510. if (!is_100_up(dev) || (!lp->useSROM && !is_spd_100(dev))) {
  2511. lp->media = INIT;
  2512. lp->tcount++;
  2513. next_tick = DE4X5_AUTOSENSE_MS;
  2514. }
  2515. }
  2516. }
  2517. break;
  2518. case BNC:
  2519. case AUI:
  2520. case _10Mb: /* Set 10Mb/s */
  2521. next_tick = 3000;
  2522. if (!lp->tx_enable) {
  2523. SET_10Mb;
  2524. de4x5_init_connection(dev);
  2525. } else {
  2526. if (!lp->linkOK && (lp->autosense == AUTO)) {
  2527. if (!is_10_up(dev) || (!lp->useSROM && is_spd_100(dev))) {
  2528. lp->media = INIT;
  2529. lp->tcount++;
  2530. next_tick = DE4X5_AUTOSENSE_MS;
  2531. }
  2532. }
  2533. }
  2534. break;
  2535. case NC:
  2536. if (lp->media != lp->c_media) {
  2537. de4x5_dbg_media(dev);
  2538. lp->c_media = lp->media;
  2539. }
  2540. lp->media = INIT;
  2541. lp->tx_enable = false;
  2542. break;
  2543. }
  2544. return next_tick;
  2545. }
  2546. /*
  2547. ** This routine may be merged into dc21140m_autoconf() sometime as I'm
  2548. ** changing how I figure out the media - but trying to keep it backwards
  2549. ** compatible with the de500-xa and de500-aa.
  2550. ** Whether it's BNC, AUI, SYM or MII is sorted out in the infoblock
  2551. ** functions and set during de4x5_mac_port() and/or de4x5_reset_phy().
  2552. ** This routine just has to figure out whether 10Mb/s or 100Mb/s is
  2553. ** active.
  2554. ** When autonegotiation is working, the ANS part searches the SROM for
  2555. ** the highest common speed (TP) link that both can run and if that can
  2556. ** be full duplex. That infoblock is executed and then the link speed set.
  2557. **
  2558. ** Only _10Mb and _100Mb are tested here.
  2559. */
  2560. static int
  2561. dc2114x_autoconf(struct net_device *dev)
  2562. {
  2563. struct de4x5_private *lp = netdev_priv(dev);
  2564. u_long iobase = dev->base_addr;
  2565. s32 cr, anlpa, ana, cap, irqs, irq_mask, imr, omr, slnk, sr, sts;
  2566. int next_tick = DE4X5_AUTOSENSE_MS;
  2567. switch (lp->media) {
  2568. case INIT:
  2569. if (lp->timeout < 0) {
  2570. DISABLE_IRQs;
  2571. lp->tx_enable = false;
  2572. lp->linkOK = 0;
  2573. lp->timeout = -1;
  2574. de4x5_save_skbs(dev); /* Save non transmitted skb's */
  2575. if (lp->params.autosense & ~AUTO) {
  2576. srom_map_media(dev); /* Fixed media requested */
  2577. if (lp->media != lp->params.autosense) {
  2578. lp->tcount++;
  2579. lp->media = INIT;
  2580. return next_tick;
  2581. }
  2582. lp->media = INIT;
  2583. }
  2584. }
  2585. if ((next_tick = de4x5_reset_phy(dev)) < 0) {
  2586. next_tick &= ~TIMER_CB;
  2587. } else {
  2588. if (lp->autosense == _100Mb) {
  2589. lp->media = _100Mb;
  2590. } else if (lp->autosense == _10Mb) {
  2591. lp->media = _10Mb;
  2592. } else if (lp->autosense == TP) {
  2593. lp->media = TP;
  2594. } else if (lp->autosense == BNC) {
  2595. lp->media = BNC;
  2596. } else if (lp->autosense == AUI) {
  2597. lp->media = AUI;
  2598. } else {
  2599. lp->media = SPD_DET;
  2600. if ((lp->infoblock_media == ANS) &&
  2601. ((sr=is_anc_capable(dev)) & MII_SR_ANC)) {
  2602. ana = (((sr >> 6) & MII_ANA_TAF) | MII_ANA_CSMA);
  2603. ana &= (lp->fdx ? ~0 : ~MII_ANA_FDAM);
  2604. mii_wr(ana, MII_ANA, lp->phy[lp->active].addr, DE4X5_MII);
  2605. lp->media = ANS;
  2606. }
  2607. }
  2608. lp->local_state = 0;
  2609. next_tick = dc2114x_autoconf(dev);
  2610. }
  2611. break;
  2612. case ANS:
  2613. switch (lp->local_state) {
  2614. case 0:
  2615. if (lp->timeout < 0) {
  2616. mii_wr(MII_CR_ASSE | MII_CR_RAN, MII_CR, lp->phy[lp->active].addr, DE4X5_MII);
  2617. }
  2618. cr = test_mii_reg(dev, MII_CR, MII_CR_RAN, false, 500);
  2619. if (cr < 0) {
  2620. next_tick = cr & ~TIMER_CB;
  2621. } else {
  2622. if (cr) {
  2623. lp->local_state = 0;
  2624. lp->media = SPD_DET;
  2625. } else {
  2626. lp->local_state++;
  2627. }
  2628. next_tick = dc2114x_autoconf(dev);
  2629. }
  2630. break;
  2631. case 1:
  2632. sr = test_mii_reg(dev, MII_SR, MII_SR_ASSC, true, 2000);
  2633. if (sr < 0) {
  2634. next_tick = sr & ~TIMER_CB;
  2635. } else {
  2636. lp->media = SPD_DET;
  2637. lp->local_state = 0;
  2638. if (sr) { /* Success! */
  2639. lp->tmp = MII_SR_ASSC;
  2640. anlpa = mii_rd(MII_ANLPA, lp->phy[lp->active].addr, DE4X5_MII);
  2641. ana = mii_rd(MII_ANA, lp->phy[lp->active].addr, DE4X5_MII);
  2642. if (!(anlpa & MII_ANLPA_RF) &&
  2643. (cap = anlpa & MII_ANLPA_TAF & ana)) {
  2644. if (cap & MII_ANA_100M) {
  2645. lp->fdx = (ana & anlpa & MII_ANA_FDAM & MII_ANA_100M) != 0;
  2646. lp->media = _100Mb;
  2647. } else if (cap & MII_ANA_10M) {
  2648. lp->fdx = (ana & anlpa & MII_ANA_FDAM & MII_ANA_10M) != 0;
  2649. lp->media = _10Mb;
  2650. }
  2651. }
  2652. } /* Auto Negotiation failed to finish */
  2653. next_tick = dc2114x_autoconf(dev);
  2654. } /* Auto Negotiation failed to start */
  2655. break;
  2656. }
  2657. break;
  2658. case AUI:
  2659. if (!lp->tx_enable) {
  2660. if (lp->timeout < 0) {
  2661. omr = inl(DE4X5_OMR); /* Set up half duplex for AUI */
  2662. outl(omr & ~OMR_FDX, DE4X5_OMR);
  2663. }
  2664. irqs = 0;
  2665. irq_mask = 0;
  2666. sts = test_media(dev,irqs, irq_mask, 0, 0, 0, 1000);
  2667. if (sts < 0) {
  2668. next_tick = sts & ~TIMER_CB;
  2669. } else {
  2670. if (!(inl(DE4X5_SISR) & SISR_SRA) && (lp->autosense == AUTO)) {
  2671. lp->media = BNC;
  2672. next_tick = dc2114x_autoconf(dev);
  2673. } else {
  2674. lp->local_state = 1;
  2675. de4x5_init_connection(dev);
  2676. }
  2677. }
  2678. } else if (!lp->linkOK && (lp->autosense == AUTO)) {
  2679. lp->media = AUI_SUSPECT;
  2680. next_tick = 3000;
  2681. }
  2682. break;
  2683. case AUI_SUSPECT:
  2684. next_tick = de4x5_suspect_state(dev, 1000, AUI, ping_media, dc2114x_autoconf);
  2685. break;
  2686. case BNC:
  2687. switch (lp->local_state) {
  2688. case 0:
  2689. if (lp->timeout < 0) {
  2690. omr = inl(DE4X5_OMR); /* Set up half duplex for BNC */
  2691. outl(omr & ~OMR_FDX, DE4X5_OMR);
  2692. }
  2693. irqs = 0;
  2694. irq_mask = 0;
  2695. sts = test_media(dev,irqs, irq_mask, 0, 0, 0, 1000);
  2696. if (sts < 0) {
  2697. next_tick = sts & ~TIMER_CB;
  2698. } else {
  2699. lp->local_state++; /* Ensure media connected */
  2700. next_tick = dc2114x_autoconf(dev);
  2701. }
  2702. break;
  2703. case 1:
  2704. if (!lp->tx_enable) {
  2705. if ((sts = ping_media(dev, 3000)) < 0) {
  2706. next_tick = sts & ~TIMER_CB;
  2707. } else {
  2708. if (sts) {
  2709. lp->local_state = 0;
  2710. lp->tcount++;
  2711. lp->media = INIT;
  2712. } else {
  2713. de4x5_init_connection(dev);
  2714. }
  2715. }
  2716. } else if (!lp->linkOK && (lp->autosense == AUTO)) {
  2717. lp->media = BNC_SUSPECT;
  2718. next_tick = 3000;
  2719. }
  2720. break;
  2721. }
  2722. break;
  2723. case BNC_SUSPECT:
  2724. next_tick = de4x5_suspect_state(dev, 1000, BNC, ping_media, dc2114x_autoconf);
  2725. break;
  2726. case SPD_DET: /* Choose 10Mb/s or 100Mb/s */
  2727. if (srom_map_media(dev) < 0) {
  2728. lp->tcount++;
  2729. lp->media = INIT;
  2730. return next_tick;
  2731. }
  2732. if (lp->media == _100Mb) {
  2733. if ((slnk = test_for_100Mb(dev, 6500)) < 0) {
  2734. lp->media = SPD_DET;
  2735. return slnk & ~TIMER_CB;
  2736. }
  2737. } else {
  2738. if (wait_for_link(dev) < 0) {
  2739. lp->media = SPD_DET;
  2740. return PDET_LINK_WAIT;
  2741. }
  2742. }
  2743. if (lp->media == ANS) { /* Do MII parallel detection */
  2744. if (is_spd_100(dev)) {
  2745. lp->media = _100Mb;
  2746. } else {
  2747. lp->media = _10Mb;
  2748. }
  2749. next_tick = dc2114x_autoconf(dev);
  2750. } else if (((lp->media == _100Mb) && is_100_up(dev)) ||
  2751. (((lp->media == _10Mb) || (lp->media == TP) ||
  2752. (lp->media == BNC) || (lp->media == AUI)) &&
  2753. is_10_up(dev))) {
  2754. next_tick = dc2114x_autoconf(dev);
  2755. } else {
  2756. lp->tcount++;
  2757. lp->media = INIT;
  2758. }
  2759. break;
  2760. case _10Mb:
  2761. next_tick = 3000;
  2762. if (!lp->tx_enable) {
  2763. SET_10Mb;
  2764. de4x5_init_connection(dev);
  2765. } else {
  2766. if (!lp->linkOK && (lp->autosense == AUTO)) {
  2767. if (!is_10_up(dev) || (!lp->useSROM && is_spd_100(dev))) {
  2768. lp->media = INIT;
  2769. lp->tcount++;
  2770. next_tick = DE4X5_AUTOSENSE_MS;
  2771. }
  2772. }
  2773. }
  2774. break;
  2775. case _100Mb:
  2776. next_tick = 3000;
  2777. if (!lp->tx_enable) {
  2778. SET_100Mb;
  2779. de4x5_init_connection(dev);
  2780. } else {
  2781. if (!lp->linkOK && (lp->autosense == AUTO)) {
  2782. if (!is_100_up(dev) || (!lp->useSROM && !is_spd_100(dev))) {
  2783. lp->media = INIT;
  2784. lp->tcount++;
  2785. next_tick = DE4X5_AUTOSENSE_MS;
  2786. }
  2787. }
  2788. }
  2789. break;
  2790. default:
  2791. lp->tcount++;
  2792. printk("Huh?: media:%02x\n", lp->media);
  2793. lp->media = INIT;
  2794. break;
  2795. }
  2796. return next_tick;
  2797. }
  2798. static int
  2799. srom_autoconf(struct net_device *dev)
  2800. {
  2801. struct de4x5_private *lp = netdev_priv(dev);
  2802. return lp->infoleaf_fn(dev);
  2803. }
  2804. /*
  2805. ** This mapping keeps the original media codes and FDX flag unchanged.
  2806. ** While it isn't strictly necessary, it helps me for the moment...
  2807. ** The early return avoids a media state / SROM media space clash.
  2808. */
  2809. static int
  2810. srom_map_media(struct net_device *dev)
  2811. {
  2812. struct de4x5_private *lp = netdev_priv(dev);
  2813. lp->fdx = false;
  2814. if (lp->infoblock_media == lp->media)
  2815. return 0;
  2816. switch(lp->infoblock_media) {
  2817. case SROM_10BASETF:
  2818. if (!lp->params.fdx) return -1;
  2819. lp->fdx = true;
  2820. /* fall through */
  2821. case SROM_10BASET:
  2822. if (lp->params.fdx && !lp->fdx) return -1;
  2823. if ((lp->chipset == DC21140) || ((lp->chipset & ~0x00ff) == DC2114x)) {
  2824. lp->media = _10Mb;
  2825. } else {
  2826. lp->media = TP;
  2827. }
  2828. break;
  2829. case SROM_10BASE2:
  2830. lp->media = BNC;
  2831. break;
  2832. case SROM_10BASE5:
  2833. lp->media = AUI;
  2834. break;
  2835. case SROM_100BASETF:
  2836. if (!lp->params.fdx) return -1;
  2837. lp->fdx = true;
  2838. /* fall through */
  2839. case SROM_100BASET:
  2840. if (lp->params.fdx && !lp->fdx) return -1;
  2841. lp->media = _100Mb;
  2842. break;
  2843. case SROM_100BASET4:
  2844. lp->media = _100Mb;
  2845. break;
  2846. case SROM_100BASEFF:
  2847. if (!lp->params.fdx) return -1;
  2848. lp->fdx = true;
  2849. /* fall through */
  2850. case SROM_100BASEF:
  2851. if (lp->params.fdx && !lp->fdx) return -1;
  2852. lp->media = _100Mb;
  2853. break;
  2854. case ANS:
  2855. lp->media = ANS;
  2856. lp->fdx = lp->params.fdx;
  2857. break;
  2858. default:
  2859. printk("%s: Bad media code [%d] detected in SROM!\n", dev->name,
  2860. lp->infoblock_media);
  2861. return -1;
  2862. }
  2863. return 0;
  2864. }
  2865. static void
  2866. de4x5_init_connection(struct net_device *dev)
  2867. {
  2868. struct de4x5_private *lp = netdev_priv(dev);
  2869. u_long iobase = dev->base_addr;
  2870. u_long flags = 0;
  2871. if (lp->media != lp->c_media) {
  2872. de4x5_dbg_media(dev);
  2873. lp->c_media = lp->media; /* Stop scrolling media messages */
  2874. }
  2875. spin_lock_irqsave(&lp->lock, flags);
  2876. de4x5_rst_desc_ring(dev);
  2877. de4x5_setup_intr(dev);
  2878. lp->tx_enable = true;
  2879. spin_unlock_irqrestore(&lp->lock, flags);
  2880. outl(POLL_DEMAND, DE4X5_TPD);
  2881. netif_wake_queue(dev);
  2882. }
  2883. /*
  2884. ** General PHY reset function. Some MII devices don't reset correctly
  2885. ** since their MII address pins can float at voltages that are dependent
  2886. ** on the signal pin use. Do a double reset to ensure a reset.
  2887. */
  2888. static int
  2889. de4x5_reset_phy(struct net_device *dev)
  2890. {
  2891. struct de4x5_private *lp = netdev_priv(dev);
  2892. u_long iobase = dev->base_addr;
  2893. int next_tick = 0;
  2894. if ((lp->useSROM) || (lp->phy[lp->active].id)) {
  2895. if (lp->timeout < 0) {
  2896. if (lp->useSROM) {
  2897. if (lp->phy[lp->active].rst) {
  2898. srom_exec(dev, lp->phy[lp->active].rst);
  2899. srom_exec(dev, lp->phy[lp->active].rst);
  2900. } else if (lp->rst) { /* Type 5 infoblock reset */
  2901. srom_exec(dev, lp->rst);
  2902. srom_exec(dev, lp->rst);
  2903. }
  2904. } else {
  2905. PHY_HARD_RESET;
  2906. }
  2907. if (lp->useMII) {
  2908. mii_wr(MII_CR_RST, MII_CR, lp->phy[lp->active].addr, DE4X5_MII);
  2909. }
  2910. }
  2911. if (lp->useMII) {
  2912. next_tick = test_mii_reg(dev, MII_CR, MII_CR_RST, false, 500);
  2913. }
  2914. } else if (lp->chipset == DC21140) {
  2915. PHY_HARD_RESET;
  2916. }
  2917. return next_tick;
  2918. }
  2919. static int
  2920. test_media(struct net_device *dev, s32 irqs, s32 irq_mask, s32 csr13, s32 csr14, s32 csr15, s32 msec)
  2921. {
  2922. struct de4x5_private *lp = netdev_priv(dev);
  2923. u_long iobase = dev->base_addr;
  2924. s32 sts, csr12;
  2925. if (lp->timeout < 0) {
  2926. lp->timeout = msec/100;
  2927. if (!lp->useSROM) { /* Already done if by SROM, else dc2104[01] */
  2928. reset_init_sia(dev, csr13, csr14, csr15);
  2929. }
  2930. /* set up the interrupt mask */
  2931. outl(irq_mask, DE4X5_IMR);
  2932. /* clear all pending interrupts */
  2933. sts = inl(DE4X5_STS);
  2934. outl(sts, DE4X5_STS);
  2935. /* clear csr12 NRA and SRA bits */
  2936. if ((lp->chipset == DC21041) || lp->useSROM) {
  2937. csr12 = inl(DE4X5_SISR);
  2938. outl(csr12, DE4X5_SISR);
  2939. }
  2940. }
  2941. sts = inl(DE4X5_STS) & ~TIMER_CB;
  2942. if (!(sts & irqs) && --lp->timeout) {
  2943. sts = 100 | TIMER_CB;
  2944. } else {
  2945. lp->timeout = -1;
  2946. }
  2947. return sts;
  2948. }
  2949. static int
  2950. test_tp(struct net_device *dev, s32 msec)
  2951. {
  2952. struct de4x5_private *lp = netdev_priv(dev);
  2953. u_long iobase = dev->base_addr;
  2954. int sisr;
  2955. if (lp->timeout < 0) {
  2956. lp->timeout = msec/100;
  2957. }
  2958. sisr = (inl(DE4X5_SISR) & ~TIMER_CB) & (SISR_LKF | SISR_NCR);
  2959. if (sisr && --lp->timeout) {
  2960. sisr = 100 | TIMER_CB;
  2961. } else {
  2962. lp->timeout = -1;
  2963. }
  2964. return sisr;
  2965. }
  2966. /*
  2967. ** Samples the 100Mb Link State Signal. The sample interval is important
  2968. ** because too fast a rate can give erroneous results and confuse the
  2969. ** speed sense algorithm.
  2970. */
  2971. #define SAMPLE_INTERVAL 500 /* ms */
  2972. #define SAMPLE_DELAY 2000 /* ms */
  2973. static int
  2974. test_for_100Mb(struct net_device *dev, int msec)
  2975. {
  2976. struct de4x5_private *lp = netdev_priv(dev);
  2977. int gep = 0, ret = ((lp->chipset & ~0x00ff)==DC2114x? -1 :GEP_SLNK);
  2978. if (lp->timeout < 0) {
  2979. if ((msec/SAMPLE_INTERVAL) <= 0) return 0;
  2980. if (msec > SAMPLE_DELAY) {
  2981. lp->timeout = (msec - SAMPLE_DELAY)/SAMPLE_INTERVAL;
  2982. gep = SAMPLE_DELAY | TIMER_CB;
  2983. return gep;
  2984. } else {
  2985. lp->timeout = msec/SAMPLE_INTERVAL;
  2986. }
  2987. }
  2988. if (lp->phy[lp->active].id || lp->useSROM) {
  2989. gep = is_100_up(dev) | is_spd_100(dev);
  2990. } else {
  2991. gep = (~gep_rd(dev) & (GEP_SLNK | GEP_LNP));
  2992. }
  2993. if (!(gep & ret) && --lp->timeout) {
  2994. gep = SAMPLE_INTERVAL | TIMER_CB;
  2995. } else {
  2996. lp->timeout = -1;
  2997. }
  2998. return gep;
  2999. }
  3000. static int
  3001. wait_for_link(struct net_device *dev)
  3002. {
  3003. struct de4x5_private *lp = netdev_priv(dev);
  3004. if (lp->timeout < 0) {
  3005. lp->timeout = 1;
  3006. }
  3007. if (lp->timeout--) {
  3008. return TIMER_CB;
  3009. } else {
  3010. lp->timeout = -1;
  3011. }
  3012. return 0;
  3013. }
  3014. /*
  3015. **
  3016. **
  3017. */
  3018. static int
  3019. test_mii_reg(struct net_device *dev, int reg, int mask, bool pol, long msec)
  3020. {
  3021. struct de4x5_private *lp = netdev_priv(dev);
  3022. int test;
  3023. u_long iobase = dev->base_addr;
  3024. if (lp->timeout < 0) {
  3025. lp->timeout = msec/100;
  3026. }
  3027. reg = mii_rd((u_char)reg, lp->phy[lp->active].addr, DE4X5_MII) & mask;
  3028. test = (reg ^ (pol ? ~0 : 0)) & mask;
  3029. if (test && --lp->timeout) {
  3030. reg = 100 | TIMER_CB;
  3031. } else {
  3032. lp->timeout = -1;
  3033. }
  3034. return reg;
  3035. }
  3036. static int
  3037. is_spd_100(struct net_device *dev)
  3038. {
  3039. struct de4x5_private *lp = netdev_priv(dev);
  3040. u_long iobase = dev->base_addr;
  3041. int spd;
  3042. if (lp->useMII) {
  3043. spd = mii_rd(lp->phy[lp->active].spd.reg, lp->phy[lp->active].addr, DE4X5_MII);
  3044. spd = ~(spd ^ lp->phy[lp->active].spd.value);
  3045. spd &= lp->phy[lp->active].spd.mask;
  3046. } else if (!lp->useSROM) { /* de500-xa */
  3047. spd = ((~gep_rd(dev)) & GEP_SLNK);
  3048. } else {
  3049. if ((lp->ibn == 2) || !lp->asBitValid)
  3050. return (lp->chipset == DC21143) ? (~inl(DE4X5_SISR)&SISR_LS100) : 0;
  3051. spd = (lp->asBitValid & (lp->asPolarity ^ (gep_rd(dev) & lp->asBit))) |
  3052. (lp->linkOK & ~lp->asBitValid);
  3053. }
  3054. return spd;
  3055. }
  3056. static int
  3057. is_100_up(struct net_device *dev)
  3058. {
  3059. struct de4x5_private *lp = netdev_priv(dev);
  3060. u_long iobase = dev->base_addr;
  3061. if (lp->useMII) {
  3062. /* Double read for sticky bits & temporary drops */
  3063. mii_rd(MII_SR, lp->phy[lp->active].addr, DE4X5_MII);
  3064. return mii_rd(MII_SR, lp->phy[lp->active].addr, DE4X5_MII) & MII_SR_LKS;
  3065. } else if (!lp->useSROM) { /* de500-xa */
  3066. return (~gep_rd(dev)) & GEP_SLNK;
  3067. } else {
  3068. if ((lp->ibn == 2) || !lp->asBitValid)
  3069. return (lp->chipset == DC21143) ? (~inl(DE4X5_SISR)&SISR_LS100) : 0;
  3070. return (lp->asBitValid&(lp->asPolarity^(gep_rd(dev)&lp->asBit))) |
  3071. (lp->linkOK & ~lp->asBitValid);
  3072. }
  3073. }
  3074. static int
  3075. is_10_up(struct net_device *dev)
  3076. {
  3077. struct de4x5_private *lp = netdev_priv(dev);
  3078. u_long iobase = dev->base_addr;
  3079. if (lp->useMII) {
  3080. /* Double read for sticky bits & temporary drops */
  3081. mii_rd(MII_SR, lp->phy[lp->active].addr, DE4X5_MII);
  3082. return mii_rd(MII_SR, lp->phy[lp->active].addr, DE4X5_MII) & MII_SR_LKS;
  3083. } else if (!lp->useSROM) { /* de500-xa */
  3084. return (~gep_rd(dev)) & GEP_LNP;
  3085. } else {
  3086. if ((lp->ibn == 2) || !lp->asBitValid)
  3087. return ((lp->chipset & ~0x00ff) == DC2114x) ?
  3088. (~inl(DE4X5_SISR)&SISR_LS10):
  3089. 0;
  3090. return (lp->asBitValid&(lp->asPolarity^(gep_rd(dev)&lp->asBit))) |
  3091. (lp->linkOK & ~lp->asBitValid);
  3092. }
  3093. }
  3094. static int
  3095. is_anc_capable(struct net_device *dev)
  3096. {
  3097. struct de4x5_private *lp = netdev_priv(dev);
  3098. u_long iobase = dev->base_addr;
  3099. if (lp->phy[lp->active].id && (!lp->useSROM || lp->useMII)) {
  3100. return mii_rd(MII_SR, lp->phy[lp->active].addr, DE4X5_MII);
  3101. } else if ((lp->chipset & ~0x00ff) == DC2114x) {
  3102. return (inl(DE4X5_SISR) & SISR_LPN) >> 12;
  3103. } else {
  3104. return 0;
  3105. }
  3106. }
  3107. /*
  3108. ** Send a packet onto the media and watch for send errors that indicate the
  3109. ** media is bad or unconnected.
  3110. */
  3111. static int
  3112. ping_media(struct net_device *dev, int msec)
  3113. {
  3114. struct de4x5_private *lp = netdev_priv(dev);
  3115. u_long iobase = dev->base_addr;
  3116. int sisr;
  3117. if (lp->timeout < 0) {
  3118. lp->timeout = msec/100;
  3119. lp->tmp = lp->tx_new; /* Remember the ring position */
  3120. load_packet(dev, lp->frame, TD_LS | TD_FS | sizeof(lp->frame), (struct sk_buff *)1);
  3121. lp->tx_new = (lp->tx_new + 1) % lp->txRingSize;
  3122. outl(POLL_DEMAND, DE4X5_TPD);
  3123. }
  3124. sisr = inl(DE4X5_SISR);
  3125. if ((!(sisr & SISR_NCR)) &&
  3126. ((s32)le32_to_cpu(lp->tx_ring[lp->tmp].status) < 0) &&
  3127. (--lp->timeout)) {
  3128. sisr = 100 | TIMER_CB;
  3129. } else {
  3130. if ((!(sisr & SISR_NCR)) &&
  3131. !(le32_to_cpu(lp->tx_ring[lp->tmp].status) & (T_OWN | TD_ES)) &&
  3132. lp->timeout) {
  3133. sisr = 0;
  3134. } else {
  3135. sisr = 1;
  3136. }
  3137. lp->timeout = -1;
  3138. }
  3139. return sisr;
  3140. }
  3141. /*
  3142. ** This function does 2 things: on Intels it kmalloc's another buffer to
  3143. ** replace the one about to be passed up. On Alpha's it kmallocs a buffer
  3144. ** into which the packet is copied.
  3145. */
  3146. static struct sk_buff *
  3147. de4x5_alloc_rx_buff(struct net_device *dev, int index, int len)
  3148. {
  3149. struct de4x5_private *lp = netdev_priv(dev);
  3150. struct sk_buff *p;
  3151. #if !defined(__alpha__) && !defined(__powerpc__) && !defined(CONFIG_SPARC) && !defined(DE4X5_DO_MEMCPY)
  3152. struct sk_buff *ret;
  3153. u_long i=0, tmp;
  3154. p = netdev_alloc_skb(dev, IEEE802_3_SZ + DE4X5_ALIGN + 2);
  3155. if (!p) return NULL;
  3156. tmp = virt_to_bus(p->data);
  3157. i = ((tmp + DE4X5_ALIGN) & ~DE4X5_ALIGN) - tmp;
  3158. skb_reserve(p, i);
  3159. lp->rx_ring[index].buf = cpu_to_le32(tmp + i);
  3160. ret = lp->rx_skb[index];
  3161. lp->rx_skb[index] = p;
  3162. if ((u_long) ret > 1) {
  3163. skb_put(ret, len);
  3164. }
  3165. return ret;
  3166. #else
  3167. if (lp->state != OPEN) return (struct sk_buff *)1; /* Fake out the open */
  3168. p = netdev_alloc_skb(dev, len + 2);
  3169. if (!p) return NULL;
  3170. skb_reserve(p, 2); /* Align */
  3171. if (index < lp->rx_old) { /* Wrapped buffer */
  3172. short tlen = (lp->rxRingSize - lp->rx_old) * RX_BUFF_SZ;
  3173. skb_put_data(p, lp->rx_bufs + lp->rx_old * RX_BUFF_SZ, tlen);
  3174. skb_put_data(p, lp->rx_bufs, len - tlen);
  3175. } else { /* Linear buffer */
  3176. skb_put_data(p, lp->rx_bufs + lp->rx_old * RX_BUFF_SZ, len);
  3177. }
  3178. return p;
  3179. #endif
  3180. }
  3181. static void
  3182. de4x5_free_rx_buffs(struct net_device *dev)
  3183. {
  3184. struct de4x5_private *lp = netdev_priv(dev);
  3185. int i;
  3186. for (i=0; i<lp->rxRingSize; i++) {
  3187. if ((u_long) lp->rx_skb[i] > 1) {
  3188. dev_kfree_skb(lp->rx_skb[i]);
  3189. }
  3190. lp->rx_ring[i].status = 0;
  3191. lp->rx_skb[i] = (struct sk_buff *)1; /* Dummy entry */
  3192. }
  3193. }
  3194. static void
  3195. de4x5_free_tx_buffs(struct net_device *dev)
  3196. {
  3197. struct de4x5_private *lp = netdev_priv(dev);
  3198. int i;
  3199. for (i=0; i<lp->txRingSize; i++) {
  3200. if (lp->tx_skb[i])
  3201. de4x5_free_tx_buff(lp, i);
  3202. lp->tx_ring[i].status = 0;
  3203. }
  3204. /* Unload the locally queued packets */
  3205. __skb_queue_purge(&lp->cache.queue);
  3206. }
  3207. /*
  3208. ** When a user pulls a connection, the DECchip can end up in a
  3209. ** 'running - waiting for end of transmission' state. This means that we
  3210. ** have to perform a chip soft reset to ensure that we can synchronize
  3211. ** the hardware and software and make any media probes using a loopback
  3212. ** packet meaningful.
  3213. */
  3214. static void
  3215. de4x5_save_skbs(struct net_device *dev)
  3216. {
  3217. struct de4x5_private *lp = netdev_priv(dev);
  3218. u_long iobase = dev->base_addr;
  3219. s32 omr;
  3220. if (!lp->cache.save_cnt) {
  3221. STOP_DE4X5;
  3222. de4x5_tx(dev); /* Flush any sent skb's */
  3223. de4x5_free_tx_buffs(dev);
  3224. de4x5_cache_state(dev, DE4X5_SAVE_STATE);
  3225. de4x5_sw_reset(dev);
  3226. de4x5_cache_state(dev, DE4X5_RESTORE_STATE);
  3227. lp->cache.save_cnt++;
  3228. START_DE4X5;
  3229. }
  3230. }
  3231. static void
  3232. de4x5_rst_desc_ring(struct net_device *dev)
  3233. {
  3234. struct de4x5_private *lp = netdev_priv(dev);
  3235. u_long iobase = dev->base_addr;
  3236. int i;
  3237. s32 omr;
  3238. if (lp->cache.save_cnt) {
  3239. STOP_DE4X5;
  3240. outl(lp->dma_rings, DE4X5_RRBA);
  3241. outl(lp->dma_rings + NUM_RX_DESC * sizeof(struct de4x5_desc),
  3242. DE4X5_TRBA);
  3243. lp->rx_new = lp->rx_old = 0;
  3244. lp->tx_new = lp->tx_old = 0;
  3245. for (i = 0; i < lp->rxRingSize; i++) {
  3246. lp->rx_ring[i].status = cpu_to_le32(R_OWN);
  3247. }
  3248. for (i = 0; i < lp->txRingSize; i++) {
  3249. lp->tx_ring[i].status = cpu_to_le32(0);
  3250. }
  3251. barrier();
  3252. lp->cache.save_cnt--;
  3253. START_DE4X5;
  3254. }
  3255. }
  3256. static void
  3257. de4x5_cache_state(struct net_device *dev, int flag)
  3258. {
  3259. struct de4x5_private *lp = netdev_priv(dev);
  3260. u_long iobase = dev->base_addr;
  3261. switch(flag) {
  3262. case DE4X5_SAVE_STATE:
  3263. lp->cache.csr0 = inl(DE4X5_BMR);
  3264. lp->cache.csr6 = (inl(DE4X5_OMR) & ~(OMR_ST | OMR_SR));
  3265. lp->cache.csr7 = inl(DE4X5_IMR);
  3266. break;
  3267. case DE4X5_RESTORE_STATE:
  3268. outl(lp->cache.csr0, DE4X5_BMR);
  3269. outl(lp->cache.csr6, DE4X5_OMR);
  3270. outl(lp->cache.csr7, DE4X5_IMR);
  3271. if (lp->chipset == DC21140) {
  3272. gep_wr(lp->cache.gepc, dev);
  3273. gep_wr(lp->cache.gep, dev);
  3274. } else {
  3275. reset_init_sia(dev, lp->cache.csr13, lp->cache.csr14,
  3276. lp->cache.csr15);
  3277. }
  3278. break;
  3279. }
  3280. }
  3281. static void
  3282. de4x5_put_cache(struct net_device *dev, struct sk_buff *skb)
  3283. {
  3284. struct de4x5_private *lp = netdev_priv(dev);
  3285. __skb_queue_tail(&lp->cache.queue, skb);
  3286. }
  3287. static void
  3288. de4x5_putb_cache(struct net_device *dev, struct sk_buff *skb)
  3289. {
  3290. struct de4x5_private *lp = netdev_priv(dev);
  3291. __skb_queue_head(&lp->cache.queue, skb);
  3292. }
  3293. static struct sk_buff *
  3294. de4x5_get_cache(struct net_device *dev)
  3295. {
  3296. struct de4x5_private *lp = netdev_priv(dev);
  3297. return __skb_dequeue(&lp->cache.queue);
  3298. }
  3299. /*
  3300. ** Check the Auto Negotiation State. Return OK when a link pass interrupt
  3301. ** is received and the auto-negotiation status is NWAY OK.
  3302. */
  3303. static int
  3304. test_ans(struct net_device *dev, s32 irqs, s32 irq_mask, s32 msec)
  3305. {
  3306. struct de4x5_private *lp = netdev_priv(dev);
  3307. u_long iobase = dev->base_addr;
  3308. s32 sts, ans;
  3309. if (lp->timeout < 0) {
  3310. lp->timeout = msec/100;
  3311. outl(irq_mask, DE4X5_IMR);
  3312. /* clear all pending interrupts */
  3313. sts = inl(DE4X5_STS);
  3314. outl(sts, DE4X5_STS);
  3315. }
  3316. ans = inl(DE4X5_SISR) & SISR_ANS;
  3317. sts = inl(DE4X5_STS) & ~TIMER_CB;
  3318. if (!(sts & irqs) && (ans ^ ANS_NWOK) && --lp->timeout) {
  3319. sts = 100 | TIMER_CB;
  3320. } else {
  3321. lp->timeout = -1;
  3322. }
  3323. return sts;
  3324. }
  3325. static void
  3326. de4x5_setup_intr(struct net_device *dev)
  3327. {
  3328. struct de4x5_private *lp = netdev_priv(dev);
  3329. u_long iobase = dev->base_addr;
  3330. s32 imr, sts;
  3331. if (inl(DE4X5_OMR) & OMR_SR) { /* Only unmask if TX/RX is enabled */
  3332. imr = 0;
  3333. UNMASK_IRQs;
  3334. sts = inl(DE4X5_STS); /* Reset any pending (stale) interrupts */
  3335. outl(sts, DE4X5_STS);
  3336. ENABLE_IRQs;
  3337. }
  3338. }
  3339. /*
  3340. **
  3341. */
  3342. static void
  3343. reset_init_sia(struct net_device *dev, s32 csr13, s32 csr14, s32 csr15)
  3344. {
  3345. struct de4x5_private *lp = netdev_priv(dev);
  3346. u_long iobase = dev->base_addr;
  3347. RESET_SIA;
  3348. if (lp->useSROM) {
  3349. if (lp->ibn == 3) {
  3350. srom_exec(dev, lp->phy[lp->active].rst);
  3351. srom_exec(dev, lp->phy[lp->active].gep);
  3352. outl(1, DE4X5_SICR);
  3353. return;
  3354. } else {
  3355. csr15 = lp->cache.csr15;
  3356. csr14 = lp->cache.csr14;
  3357. csr13 = lp->cache.csr13;
  3358. outl(csr15 | lp->cache.gepc, DE4X5_SIGR);
  3359. outl(csr15 | lp->cache.gep, DE4X5_SIGR);
  3360. }
  3361. } else {
  3362. outl(csr15, DE4X5_SIGR);
  3363. }
  3364. outl(csr14, DE4X5_STRR);
  3365. outl(csr13, DE4X5_SICR);
  3366. mdelay(10);
  3367. }
  3368. /*
  3369. ** Create a loopback ethernet packet
  3370. */
  3371. static void
  3372. create_packet(struct net_device *dev, char *frame, int len)
  3373. {
  3374. int i;
  3375. char *buf = frame;
  3376. for (i=0; i<ETH_ALEN; i++) { /* Use this source address */
  3377. *buf++ = dev->dev_addr[i];
  3378. }
  3379. for (i=0; i<ETH_ALEN; i++) { /* Use this destination address */
  3380. *buf++ = dev->dev_addr[i];
  3381. }
  3382. *buf++ = 0; /* Packet length (2 bytes) */
  3383. *buf++ = 1;
  3384. }
  3385. /*
  3386. ** Look for a particular board name in the EISA configuration space
  3387. */
  3388. static int
  3389. EISA_signature(char *name, struct device *device)
  3390. {
  3391. int i, status = 0, siglen = ARRAY_SIZE(de4x5_signatures);
  3392. struct eisa_device *edev;
  3393. *name = '\0';
  3394. edev = to_eisa_device (device);
  3395. i = edev->id.driver_data;
  3396. if (i >= 0 && i < siglen) {
  3397. strcpy (name, de4x5_signatures[i]);
  3398. status = 1;
  3399. }
  3400. return status; /* return the device name string */
  3401. }
  3402. /*
  3403. ** Look for a particular board name in the PCI configuration space
  3404. */
  3405. static int
  3406. PCI_signature(char *name, struct de4x5_private *lp)
  3407. {
  3408. int i, status = 0, siglen = ARRAY_SIZE(de4x5_signatures);
  3409. if (lp->chipset == DC21040) {
  3410. strcpy(name, "DE434/5");
  3411. return status;
  3412. } else { /* Search for a DEC name in the SROM */
  3413. int tmp = *((char *)&lp->srom + 19) * 3;
  3414. strncpy(name, (char *)&lp->srom + 26 + tmp, 8);
  3415. }
  3416. name[8] = '\0';
  3417. for (i=0; i<siglen; i++) {
  3418. if (strstr(name,de4x5_signatures[i])!=NULL) break;
  3419. }
  3420. if (i == siglen) {
  3421. if (dec_only) {
  3422. *name = '\0';
  3423. } else { /* Use chip name to avoid confusion */
  3424. strcpy(name, (((lp->chipset == DC21040) ? "DC21040" :
  3425. ((lp->chipset == DC21041) ? "DC21041" :
  3426. ((lp->chipset == DC21140) ? "DC21140" :
  3427. ((lp->chipset == DC21142) ? "DC21142" :
  3428. ((lp->chipset == DC21143) ? "DC21143" : "UNKNOWN"
  3429. )))))));
  3430. }
  3431. if (lp->chipset != DC21041) {
  3432. lp->useSROM = true; /* card is not recognisably DEC */
  3433. }
  3434. } else if ((lp->chipset & ~0x00ff) == DC2114x) {
  3435. lp->useSROM = true;
  3436. }
  3437. return status;
  3438. }
  3439. /*
  3440. ** Set up the Ethernet PROM counter to the start of the Ethernet address on
  3441. ** the DC21040, else read the SROM for the other chips.
  3442. ** The SROM may not be present in a multi-MAC card, so first read the
  3443. ** MAC address and check for a bad address. If there is a bad one then exit
  3444. ** immediately with the prior srom contents intact (the h/w address will
  3445. ** be fixed up later).
  3446. */
  3447. static void
  3448. DevicePresent(struct net_device *dev, u_long aprom_addr)
  3449. {
  3450. int i, j=0;
  3451. struct de4x5_private *lp = netdev_priv(dev);
  3452. if (lp->chipset == DC21040) {
  3453. if (lp->bus == EISA) {
  3454. enet_addr_rst(aprom_addr); /* Reset Ethernet Address ROM Pointer */
  3455. } else {
  3456. outl(0, aprom_addr); /* Reset Ethernet Address ROM Pointer */
  3457. }
  3458. } else { /* Read new srom */
  3459. u_short tmp;
  3460. __le16 *p = (__le16 *)((char *)&lp->srom + SROM_HWADD);
  3461. for (i=0; i<(ETH_ALEN>>1); i++) {
  3462. tmp = srom_rd(aprom_addr, (SROM_HWADD>>1) + i);
  3463. j += tmp; /* for check for 0:0:0:0:0:0 or ff:ff:ff:ff:ff:ff */
  3464. *p = cpu_to_le16(tmp);
  3465. }
  3466. if (j == 0 || j == 3 * 0xffff) {
  3467. /* could get 0 only from all-0 and 3 * 0xffff only from all-1 */
  3468. return;
  3469. }
  3470. p = (__le16 *)&lp->srom;
  3471. for (i=0; i<(sizeof(struct de4x5_srom)>>1); i++) {
  3472. tmp = srom_rd(aprom_addr, i);
  3473. *p++ = cpu_to_le16(tmp);
  3474. }
  3475. de4x5_dbg_srom(&lp->srom);
  3476. }
  3477. }
  3478. /*
  3479. ** Since the write on the Enet PROM register doesn't seem to reset the PROM
  3480. ** pointer correctly (at least on my DE425 EISA card), this routine should do
  3481. ** it...from depca.c.
  3482. */
  3483. static void
  3484. enet_addr_rst(u_long aprom_addr)
  3485. {
  3486. union {
  3487. struct {
  3488. u32 a;
  3489. u32 b;
  3490. } llsig;
  3491. char Sig[sizeof(u32) << 1];
  3492. } dev;
  3493. short sigLength=0;
  3494. s8 data;
  3495. int i, j;
  3496. dev.llsig.a = ETH_PROM_SIG;
  3497. dev.llsig.b = ETH_PROM_SIG;
  3498. sigLength = sizeof(u32) << 1;
  3499. for (i=0,j=0;j<sigLength && i<PROBE_LENGTH+sigLength-1;i++) {
  3500. data = inb(aprom_addr);
  3501. if (dev.Sig[j] == data) { /* track signature */
  3502. j++;
  3503. } else { /* lost signature; begin search again */
  3504. if (data == dev.Sig[0]) { /* rare case.... */
  3505. j=1;
  3506. } else {
  3507. j=0;
  3508. }
  3509. }
  3510. }
  3511. }
  3512. /*
  3513. ** For the bad status case and no SROM, then add one to the previous
  3514. ** address. However, need to add one backwards in case we have 0xff
  3515. ** as one or more of the bytes. Only the last 3 bytes should be checked
  3516. ** as the first three are invariant - assigned to an organisation.
  3517. */
  3518. static int
  3519. get_hw_addr(struct net_device *dev)
  3520. {
  3521. u_long iobase = dev->base_addr;
  3522. int broken, i, k, tmp, status = 0;
  3523. u_short j,chksum;
  3524. struct de4x5_private *lp = netdev_priv(dev);
  3525. broken = de4x5_bad_srom(lp);
  3526. for (i=0,k=0,j=0;j<3;j++) {
  3527. k <<= 1;
  3528. if (k > 0xffff) k-=0xffff;
  3529. if (lp->bus == PCI) {
  3530. if (lp->chipset == DC21040) {
  3531. while ((tmp = inl(DE4X5_APROM)) < 0);
  3532. k += (u_char) tmp;
  3533. dev->dev_addr[i++] = (u_char) tmp;
  3534. while ((tmp = inl(DE4X5_APROM)) < 0);
  3535. k += (u_short) (tmp << 8);
  3536. dev->dev_addr[i++] = (u_char) tmp;
  3537. } else if (!broken) {
  3538. dev->dev_addr[i] = (u_char) lp->srom.ieee_addr[i]; i++;
  3539. dev->dev_addr[i] = (u_char) lp->srom.ieee_addr[i]; i++;
  3540. } else if ((broken == SMC) || (broken == ACCTON)) {
  3541. dev->dev_addr[i] = *((u_char *)&lp->srom + i); i++;
  3542. dev->dev_addr[i] = *((u_char *)&lp->srom + i); i++;
  3543. }
  3544. } else {
  3545. k += (u_char) (tmp = inb(EISA_APROM));
  3546. dev->dev_addr[i++] = (u_char) tmp;
  3547. k += (u_short) ((tmp = inb(EISA_APROM)) << 8);
  3548. dev->dev_addr[i++] = (u_char) tmp;
  3549. }
  3550. if (k > 0xffff) k-=0xffff;
  3551. }
  3552. if (k == 0xffff) k=0;
  3553. if (lp->bus == PCI) {
  3554. if (lp->chipset == DC21040) {
  3555. while ((tmp = inl(DE4X5_APROM)) < 0);
  3556. chksum = (u_char) tmp;
  3557. while ((tmp = inl(DE4X5_APROM)) < 0);
  3558. chksum |= (u_short) (tmp << 8);
  3559. if ((k != chksum) && (dec_only)) status = -1;
  3560. }
  3561. } else {
  3562. chksum = (u_char) inb(EISA_APROM);
  3563. chksum |= (u_short) (inb(EISA_APROM) << 8);
  3564. if ((k != chksum) && (dec_only)) status = -1;
  3565. }
  3566. /* If possible, try to fix a broken card - SMC only so far */
  3567. srom_repair(dev, broken);
  3568. #ifdef CONFIG_PPC_PMAC
  3569. /*
  3570. ** If the address starts with 00 a0, we have to bit-reverse
  3571. ** each byte of the address.
  3572. */
  3573. if ( machine_is(powermac) &&
  3574. (dev->dev_addr[0] == 0) &&
  3575. (dev->dev_addr[1] == 0xa0) )
  3576. {
  3577. for (i = 0; i < ETH_ALEN; ++i)
  3578. {
  3579. int x = dev->dev_addr[i];
  3580. x = ((x & 0xf) << 4) + ((x & 0xf0) >> 4);
  3581. x = ((x & 0x33) << 2) + ((x & 0xcc) >> 2);
  3582. dev->dev_addr[i] = ((x & 0x55) << 1) + ((x & 0xaa) >> 1);
  3583. }
  3584. }
  3585. #endif /* CONFIG_PPC_PMAC */
  3586. /* Test for a bad enet address */
  3587. status = test_bad_enet(dev, status);
  3588. return status;
  3589. }
  3590. /*
  3591. ** Test for enet addresses in the first 32 bytes.
  3592. */
  3593. static int
  3594. de4x5_bad_srom(struct de4x5_private *lp)
  3595. {
  3596. int i, status = 0;
  3597. for (i = 0; i < ARRAY_SIZE(enet_det); i++) {
  3598. if (!memcmp(&lp->srom, &enet_det[i], 3) &&
  3599. !memcmp((char *)&lp->srom+0x10, &enet_det[i], 3)) {
  3600. if (i == 0) {
  3601. status = SMC;
  3602. } else if (i == 1) {
  3603. status = ACCTON;
  3604. }
  3605. break;
  3606. }
  3607. }
  3608. return status;
  3609. }
  3610. static void
  3611. srom_repair(struct net_device *dev, int card)
  3612. {
  3613. struct de4x5_private *lp = netdev_priv(dev);
  3614. switch(card) {
  3615. case SMC:
  3616. memset((char *)&lp->srom, 0, sizeof(struct de4x5_srom));
  3617. memcpy(lp->srom.ieee_addr, (char *)dev->dev_addr, ETH_ALEN);
  3618. memcpy(lp->srom.info, (char *)&srom_repair_info[SMC-1], 100);
  3619. lp->useSROM = true;
  3620. break;
  3621. }
  3622. }
  3623. /*
  3624. ** Assume that the irq's do not follow the PCI spec - this is seems
  3625. ** to be true so far (2 for 2).
  3626. */
  3627. static int
  3628. test_bad_enet(struct net_device *dev, int status)
  3629. {
  3630. struct de4x5_private *lp = netdev_priv(dev);
  3631. int i, tmp;
  3632. for (tmp=0,i=0; i<ETH_ALEN; i++) tmp += (u_char)dev->dev_addr[i];
  3633. if ((tmp == 0) || (tmp == 0x5fa)) {
  3634. if ((lp->chipset == last.chipset) &&
  3635. (lp->bus_num == last.bus) && (lp->bus_num > 0)) {
  3636. for (i=0; i<ETH_ALEN; i++) dev->dev_addr[i] = last.addr[i];
  3637. for (i=ETH_ALEN-1; i>2; --i) {
  3638. dev->dev_addr[i] += 1;
  3639. if (dev->dev_addr[i] != 0) break;
  3640. }
  3641. for (i=0; i<ETH_ALEN; i++) last.addr[i] = dev->dev_addr[i];
  3642. if (!an_exception(lp)) {
  3643. dev->irq = last.irq;
  3644. }
  3645. status = 0;
  3646. }
  3647. } else if (!status) {
  3648. last.chipset = lp->chipset;
  3649. last.bus = lp->bus_num;
  3650. last.irq = dev->irq;
  3651. for (i=0; i<ETH_ALEN; i++) last.addr[i] = dev->dev_addr[i];
  3652. }
  3653. return status;
  3654. }
  3655. /*
  3656. ** List of board exceptions with correctly wired IRQs
  3657. */
  3658. static int
  3659. an_exception(struct de4x5_private *lp)
  3660. {
  3661. if ((*(u_short *)lp->srom.sub_vendor_id == 0x00c0) &&
  3662. (*(u_short *)lp->srom.sub_system_id == 0x95e0)) {
  3663. return -1;
  3664. }
  3665. return 0;
  3666. }
  3667. /*
  3668. ** SROM Read
  3669. */
  3670. static short
  3671. srom_rd(u_long addr, u_char offset)
  3672. {
  3673. sendto_srom(SROM_RD | SROM_SR, addr);
  3674. srom_latch(SROM_RD | SROM_SR | DT_CS, addr);
  3675. srom_command(SROM_RD | SROM_SR | DT_IN | DT_CS, addr);
  3676. srom_address(SROM_RD | SROM_SR | DT_CS, addr, offset);
  3677. return srom_data(SROM_RD | SROM_SR | DT_CS, addr);
  3678. }
  3679. static void
  3680. srom_latch(u_int command, u_long addr)
  3681. {
  3682. sendto_srom(command, addr);
  3683. sendto_srom(command | DT_CLK, addr);
  3684. sendto_srom(command, addr);
  3685. }
  3686. static void
  3687. srom_command(u_int command, u_long addr)
  3688. {
  3689. srom_latch(command, addr);
  3690. srom_latch(command, addr);
  3691. srom_latch((command & 0x0000ff00) | DT_CS, addr);
  3692. }
  3693. static void
  3694. srom_address(u_int command, u_long addr, u_char offset)
  3695. {
  3696. int i, a;
  3697. a = offset << 2;
  3698. for (i=0; i<6; i++, a <<= 1) {
  3699. srom_latch(command | ((a & 0x80) ? DT_IN : 0), addr);
  3700. }
  3701. udelay(1);
  3702. i = (getfrom_srom(addr) >> 3) & 0x01;
  3703. }
  3704. static short
  3705. srom_data(u_int command, u_long addr)
  3706. {
  3707. int i;
  3708. short word = 0;
  3709. s32 tmp;
  3710. for (i=0; i<16; i++) {
  3711. sendto_srom(command | DT_CLK, addr);
  3712. tmp = getfrom_srom(addr);
  3713. sendto_srom(command, addr);
  3714. word = (word << 1) | ((tmp >> 3) & 0x01);
  3715. }
  3716. sendto_srom(command & 0x0000ff00, addr);
  3717. return word;
  3718. }
  3719. /*
  3720. static void
  3721. srom_busy(u_int command, u_long addr)
  3722. {
  3723. sendto_srom((command & 0x0000ff00) | DT_CS, addr);
  3724. while (!((getfrom_srom(addr) >> 3) & 0x01)) {
  3725. mdelay(1);
  3726. }
  3727. sendto_srom(command & 0x0000ff00, addr);
  3728. }
  3729. */
  3730. static void
  3731. sendto_srom(u_int command, u_long addr)
  3732. {
  3733. outl(command, addr);
  3734. udelay(1);
  3735. }
  3736. static int
  3737. getfrom_srom(u_long addr)
  3738. {
  3739. s32 tmp;
  3740. tmp = inl(addr);
  3741. udelay(1);
  3742. return tmp;
  3743. }
  3744. static int
  3745. srom_infoleaf_info(struct net_device *dev)
  3746. {
  3747. struct de4x5_private *lp = netdev_priv(dev);
  3748. int i, count;
  3749. u_char *p;
  3750. /* Find the infoleaf decoder function that matches this chipset */
  3751. for (i=0; i<INFOLEAF_SIZE; i++) {
  3752. if (lp->chipset == infoleaf_array[i].chipset) break;
  3753. }
  3754. if (i == INFOLEAF_SIZE) {
  3755. lp->useSROM = false;
  3756. printk("%s: Cannot find correct chipset for SROM decoding!\n",
  3757. dev->name);
  3758. return -ENXIO;
  3759. }
  3760. lp->infoleaf_fn = infoleaf_array[i].fn;
  3761. /* Find the information offset that this function should use */
  3762. count = *((u_char *)&lp->srom + 19);
  3763. p = (u_char *)&lp->srom + 26;
  3764. if (count > 1) {
  3765. for (i=count; i; --i, p+=3) {
  3766. if (lp->device == *p) break;
  3767. }
  3768. if (i == 0) {
  3769. lp->useSROM = false;
  3770. printk("%s: Cannot find correct PCI device [%d] for SROM decoding!\n",
  3771. dev->name, lp->device);
  3772. return -ENXIO;
  3773. }
  3774. }
  3775. lp->infoleaf_offset = get_unaligned_le16(p + 1);
  3776. return 0;
  3777. }
  3778. /*
  3779. ** This routine loads any type 1 or 3 MII info into the mii device
  3780. ** struct and executes any type 5 code to reset PHY devices for this
  3781. ** controller.
  3782. ** The info for the MII devices will be valid since the index used
  3783. ** will follow the discovery process from MII address 1-31 then 0.
  3784. */
  3785. static void
  3786. srom_init(struct net_device *dev)
  3787. {
  3788. struct de4x5_private *lp = netdev_priv(dev);
  3789. u_char *p = (u_char *)&lp->srom + lp->infoleaf_offset;
  3790. u_char count;
  3791. p+=2;
  3792. if (lp->chipset == DC21140) {
  3793. lp->cache.gepc = (*p++ | GEP_CTRL);
  3794. gep_wr(lp->cache.gepc, dev);
  3795. }
  3796. /* Block count */
  3797. count = *p++;
  3798. /* Jump the infoblocks to find types */
  3799. for (;count; --count) {
  3800. if (*p < 128) {
  3801. p += COMPACT_LEN;
  3802. } else if (*(p+1) == 5) {
  3803. type5_infoblock(dev, 1, p);
  3804. p += ((*p & BLOCK_LEN) + 1);
  3805. } else if (*(p+1) == 4) {
  3806. p += ((*p & BLOCK_LEN) + 1);
  3807. } else if (*(p+1) == 3) {
  3808. type3_infoblock(dev, 1, p);
  3809. p += ((*p & BLOCK_LEN) + 1);
  3810. } else if (*(p+1) == 2) {
  3811. p += ((*p & BLOCK_LEN) + 1);
  3812. } else if (*(p+1) == 1) {
  3813. type1_infoblock(dev, 1, p);
  3814. p += ((*p & BLOCK_LEN) + 1);
  3815. } else {
  3816. p += ((*p & BLOCK_LEN) + 1);
  3817. }
  3818. }
  3819. }
  3820. /*
  3821. ** A generic routine that writes GEP control, data and reset information
  3822. ** to the GEP register (21140) or csr15 GEP portion (2114[23]).
  3823. */
  3824. static void
  3825. srom_exec(struct net_device *dev, u_char *p)
  3826. {
  3827. struct de4x5_private *lp = netdev_priv(dev);
  3828. u_long iobase = dev->base_addr;
  3829. u_char count = (p ? *p++ : 0);
  3830. u_short *w = (u_short *)p;
  3831. if (((lp->ibn != 1) && (lp->ibn != 3) && (lp->ibn != 5)) || !count) return;
  3832. if (lp->chipset != DC21140) RESET_SIA;
  3833. while (count--) {
  3834. gep_wr(((lp->chipset==DC21140) && (lp->ibn!=5) ?
  3835. *p++ : get_unaligned_le16(w++)), dev);
  3836. mdelay(2); /* 2ms per action */
  3837. }
  3838. if (lp->chipset != DC21140) {
  3839. outl(lp->cache.csr14, DE4X5_STRR);
  3840. outl(lp->cache.csr13, DE4X5_SICR);
  3841. }
  3842. }
  3843. /*
  3844. ** Basically this function is a NOP since it will never be called,
  3845. ** unless I implement the DC21041 SROM functions. There's no need
  3846. ** since the existing code will be satisfactory for all boards.
  3847. */
  3848. static int
  3849. dc21041_infoleaf(struct net_device *dev)
  3850. {
  3851. return DE4X5_AUTOSENSE_MS;
  3852. }
  3853. static int
  3854. dc21140_infoleaf(struct net_device *dev)
  3855. {
  3856. struct de4x5_private *lp = netdev_priv(dev);
  3857. u_char count = 0;
  3858. u_char *p = (u_char *)&lp->srom + lp->infoleaf_offset;
  3859. int next_tick = DE4X5_AUTOSENSE_MS;
  3860. /* Read the connection type */
  3861. p+=2;
  3862. /* GEP control */
  3863. lp->cache.gepc = (*p++ | GEP_CTRL);
  3864. /* Block count */
  3865. count = *p++;
  3866. /* Recursively figure out the info blocks */
  3867. if (*p < 128) {
  3868. next_tick = dc_infoblock[COMPACT](dev, count, p);
  3869. } else {
  3870. next_tick = dc_infoblock[*(p+1)](dev, count, p);
  3871. }
  3872. if (lp->tcount == count) {
  3873. lp->media = NC;
  3874. if (lp->media != lp->c_media) {
  3875. de4x5_dbg_media(dev);
  3876. lp->c_media = lp->media;
  3877. }
  3878. lp->media = INIT;
  3879. lp->tcount = 0;
  3880. lp->tx_enable = false;
  3881. }
  3882. return next_tick & ~TIMER_CB;
  3883. }
  3884. static int
  3885. dc21142_infoleaf(struct net_device *dev)
  3886. {
  3887. struct de4x5_private *lp = netdev_priv(dev);
  3888. u_char count = 0;
  3889. u_char *p = (u_char *)&lp->srom + lp->infoleaf_offset;
  3890. int next_tick = DE4X5_AUTOSENSE_MS;
  3891. /* Read the connection type */
  3892. p+=2;
  3893. /* Block count */
  3894. count = *p++;
  3895. /* Recursively figure out the info blocks */
  3896. if (*p < 128) {
  3897. next_tick = dc_infoblock[COMPACT](dev, count, p);
  3898. } else {
  3899. next_tick = dc_infoblock[*(p+1)](dev, count, p);
  3900. }
  3901. if (lp->tcount == count) {
  3902. lp->media = NC;
  3903. if (lp->media != lp->c_media) {
  3904. de4x5_dbg_media(dev);
  3905. lp->c_media = lp->media;
  3906. }
  3907. lp->media = INIT;
  3908. lp->tcount = 0;
  3909. lp->tx_enable = false;
  3910. }
  3911. return next_tick & ~TIMER_CB;
  3912. }
  3913. static int
  3914. dc21143_infoleaf(struct net_device *dev)
  3915. {
  3916. struct de4x5_private *lp = netdev_priv(dev);
  3917. u_char count = 0;
  3918. u_char *p = (u_char *)&lp->srom + lp->infoleaf_offset;
  3919. int next_tick = DE4X5_AUTOSENSE_MS;
  3920. /* Read the connection type */
  3921. p+=2;
  3922. /* Block count */
  3923. count = *p++;
  3924. /* Recursively figure out the info blocks */
  3925. if (*p < 128) {
  3926. next_tick = dc_infoblock[COMPACT](dev, count, p);
  3927. } else {
  3928. next_tick = dc_infoblock[*(p+1)](dev, count, p);
  3929. }
  3930. if (lp->tcount == count) {
  3931. lp->media = NC;
  3932. if (lp->media != lp->c_media) {
  3933. de4x5_dbg_media(dev);
  3934. lp->c_media = lp->media;
  3935. }
  3936. lp->media = INIT;
  3937. lp->tcount = 0;
  3938. lp->tx_enable = false;
  3939. }
  3940. return next_tick & ~TIMER_CB;
  3941. }
  3942. /*
  3943. ** The compact infoblock is only designed for DC21140[A] chips, so
  3944. ** we'll reuse the dc21140m_autoconf function. Non MII media only.
  3945. */
  3946. static int
  3947. compact_infoblock(struct net_device *dev, u_char count, u_char *p)
  3948. {
  3949. struct de4x5_private *lp = netdev_priv(dev);
  3950. u_char flags, csr6;
  3951. /* Recursively figure out the info blocks */
  3952. if (--count > lp->tcount) {
  3953. if (*(p+COMPACT_LEN) < 128) {
  3954. return dc_infoblock[COMPACT](dev, count, p+COMPACT_LEN);
  3955. } else {
  3956. return dc_infoblock[*(p+COMPACT_LEN+1)](dev, count, p+COMPACT_LEN);
  3957. }
  3958. }
  3959. if ((lp->media == INIT) && (lp->timeout < 0)) {
  3960. lp->ibn = COMPACT;
  3961. lp->active = 0;
  3962. gep_wr(lp->cache.gepc, dev);
  3963. lp->infoblock_media = (*p++) & COMPACT_MC;
  3964. lp->cache.gep = *p++;
  3965. csr6 = *p++;
  3966. flags = *p++;
  3967. lp->asBitValid = (flags & 0x80) ? 0 : -1;
  3968. lp->defMedium = (flags & 0x40) ? -1 : 0;
  3969. lp->asBit = 1 << ((csr6 >> 1) & 0x07);
  3970. lp->asPolarity = ((csr6 & 0x80) ? -1 : 0) & lp->asBit;
  3971. lp->infoblock_csr6 = OMR_DEF | ((csr6 & 0x71) << 18);
  3972. lp->useMII = false;
  3973. de4x5_switch_mac_port(dev);
  3974. }
  3975. return dc21140m_autoconf(dev);
  3976. }
  3977. /*
  3978. ** This block describes non MII media for the DC21140[A] only.
  3979. */
  3980. static int
  3981. type0_infoblock(struct net_device *dev, u_char count, u_char *p)
  3982. {
  3983. struct de4x5_private *lp = netdev_priv(dev);
  3984. u_char flags, csr6, len = (*p & BLOCK_LEN)+1;
  3985. /* Recursively figure out the info blocks */
  3986. if (--count > lp->tcount) {
  3987. if (*(p+len) < 128) {
  3988. return dc_infoblock[COMPACT](dev, count, p+len);
  3989. } else {
  3990. return dc_infoblock[*(p+len+1)](dev, count, p+len);
  3991. }
  3992. }
  3993. if ((lp->media == INIT) && (lp->timeout < 0)) {
  3994. lp->ibn = 0;
  3995. lp->active = 0;
  3996. gep_wr(lp->cache.gepc, dev);
  3997. p+=2;
  3998. lp->infoblock_media = (*p++) & BLOCK0_MC;
  3999. lp->cache.gep = *p++;
  4000. csr6 = *p++;
  4001. flags = *p++;
  4002. lp->asBitValid = (flags & 0x80) ? 0 : -1;
  4003. lp->defMedium = (flags & 0x40) ? -1 : 0;
  4004. lp->asBit = 1 << ((csr6 >> 1) & 0x07);
  4005. lp->asPolarity = ((csr6 & 0x80) ? -1 : 0) & lp->asBit;
  4006. lp->infoblock_csr6 = OMR_DEF | ((csr6 & 0x71) << 18);
  4007. lp->useMII = false;
  4008. de4x5_switch_mac_port(dev);
  4009. }
  4010. return dc21140m_autoconf(dev);
  4011. }
  4012. /* These functions are under construction! */
  4013. static int
  4014. type1_infoblock(struct net_device *dev, u_char count, u_char *p)
  4015. {
  4016. struct de4x5_private *lp = netdev_priv(dev);
  4017. u_char len = (*p & BLOCK_LEN)+1;
  4018. /* Recursively figure out the info blocks */
  4019. if (--count > lp->tcount) {
  4020. if (*(p+len) < 128) {
  4021. return dc_infoblock[COMPACT](dev, count, p+len);
  4022. } else {
  4023. return dc_infoblock[*(p+len+1)](dev, count, p+len);
  4024. }
  4025. }
  4026. p += 2;
  4027. if (lp->state == INITIALISED) {
  4028. lp->ibn = 1;
  4029. lp->active = *p++;
  4030. lp->phy[lp->active].gep = (*p ? p : NULL); p += (*p + 1);
  4031. lp->phy[lp->active].rst = (*p ? p : NULL); p += (*p + 1);
  4032. lp->phy[lp->active].mc = get_unaligned_le16(p); p += 2;
  4033. lp->phy[lp->active].ana = get_unaligned_le16(p); p += 2;
  4034. lp->phy[lp->active].fdx = get_unaligned_le16(p); p += 2;
  4035. lp->phy[lp->active].ttm = get_unaligned_le16(p);
  4036. return 0;
  4037. } else if ((lp->media == INIT) && (lp->timeout < 0)) {
  4038. lp->ibn = 1;
  4039. lp->active = *p;
  4040. lp->infoblock_csr6 = OMR_MII_100;
  4041. lp->useMII = true;
  4042. lp->infoblock_media = ANS;
  4043. de4x5_switch_mac_port(dev);
  4044. }
  4045. return dc21140m_autoconf(dev);
  4046. }
  4047. static int
  4048. type2_infoblock(struct net_device *dev, u_char count, u_char *p)
  4049. {
  4050. struct de4x5_private *lp = netdev_priv(dev);
  4051. u_char len = (*p & BLOCK_LEN)+1;
  4052. /* Recursively figure out the info blocks */
  4053. if (--count > lp->tcount) {
  4054. if (*(p+len) < 128) {
  4055. return dc_infoblock[COMPACT](dev, count, p+len);
  4056. } else {
  4057. return dc_infoblock[*(p+len+1)](dev, count, p+len);
  4058. }
  4059. }
  4060. if ((lp->media == INIT) && (lp->timeout < 0)) {
  4061. lp->ibn = 2;
  4062. lp->active = 0;
  4063. p += 2;
  4064. lp->infoblock_media = (*p) & MEDIA_CODE;
  4065. if ((*p++) & EXT_FIELD) {
  4066. lp->cache.csr13 = get_unaligned_le16(p); p += 2;
  4067. lp->cache.csr14 = get_unaligned_le16(p); p += 2;
  4068. lp->cache.csr15 = get_unaligned_le16(p); p += 2;
  4069. } else {
  4070. lp->cache.csr13 = CSR13;
  4071. lp->cache.csr14 = CSR14;
  4072. lp->cache.csr15 = CSR15;
  4073. }
  4074. lp->cache.gepc = ((s32)(get_unaligned_le16(p)) << 16); p += 2;
  4075. lp->cache.gep = ((s32)(get_unaligned_le16(p)) << 16);
  4076. lp->infoblock_csr6 = OMR_SIA;
  4077. lp->useMII = false;
  4078. de4x5_switch_mac_port(dev);
  4079. }
  4080. return dc2114x_autoconf(dev);
  4081. }
  4082. static int
  4083. type3_infoblock(struct net_device *dev, u_char count, u_char *p)
  4084. {
  4085. struct de4x5_private *lp = netdev_priv(dev);
  4086. u_char len = (*p & BLOCK_LEN)+1;
  4087. /* Recursively figure out the info blocks */
  4088. if (--count > lp->tcount) {
  4089. if (*(p+len) < 128) {
  4090. return dc_infoblock[COMPACT](dev, count, p+len);
  4091. } else {
  4092. return dc_infoblock[*(p+len+1)](dev, count, p+len);
  4093. }
  4094. }
  4095. p += 2;
  4096. if (lp->state == INITIALISED) {
  4097. lp->ibn = 3;
  4098. lp->active = *p++;
  4099. if (MOTO_SROM_BUG) lp->active = 0;
  4100. lp->phy[lp->active].gep = (*p ? p : NULL); p += (2 * (*p) + 1);
  4101. lp->phy[lp->active].rst = (*p ? p : NULL); p += (2 * (*p) + 1);
  4102. lp->phy[lp->active].mc = get_unaligned_le16(p); p += 2;
  4103. lp->phy[lp->active].ana = get_unaligned_le16(p); p += 2;
  4104. lp->phy[lp->active].fdx = get_unaligned_le16(p); p += 2;
  4105. lp->phy[lp->active].ttm = get_unaligned_le16(p); p += 2;
  4106. lp->phy[lp->active].mci = *p;
  4107. return 0;
  4108. } else if ((lp->media == INIT) && (lp->timeout < 0)) {
  4109. lp->ibn = 3;
  4110. lp->active = *p;
  4111. if (MOTO_SROM_BUG) lp->active = 0;
  4112. lp->infoblock_csr6 = OMR_MII_100;
  4113. lp->useMII = true;
  4114. lp->infoblock_media = ANS;
  4115. de4x5_switch_mac_port(dev);
  4116. }
  4117. return dc2114x_autoconf(dev);
  4118. }
  4119. static int
  4120. type4_infoblock(struct net_device *dev, u_char count, u_char *p)
  4121. {
  4122. struct de4x5_private *lp = netdev_priv(dev);
  4123. u_char flags, csr6, len = (*p & BLOCK_LEN)+1;
  4124. /* Recursively figure out the info blocks */
  4125. if (--count > lp->tcount) {
  4126. if (*(p+len) < 128) {
  4127. return dc_infoblock[COMPACT](dev, count, p+len);
  4128. } else {
  4129. return dc_infoblock[*(p+len+1)](dev, count, p+len);
  4130. }
  4131. }
  4132. if ((lp->media == INIT) && (lp->timeout < 0)) {
  4133. lp->ibn = 4;
  4134. lp->active = 0;
  4135. p+=2;
  4136. lp->infoblock_media = (*p++) & MEDIA_CODE;
  4137. lp->cache.csr13 = CSR13; /* Hard coded defaults */
  4138. lp->cache.csr14 = CSR14;
  4139. lp->cache.csr15 = CSR15;
  4140. lp->cache.gepc = ((s32)(get_unaligned_le16(p)) << 16); p += 2;
  4141. lp->cache.gep = ((s32)(get_unaligned_le16(p)) << 16); p += 2;
  4142. csr6 = *p++;
  4143. flags = *p++;
  4144. lp->asBitValid = (flags & 0x80) ? 0 : -1;
  4145. lp->defMedium = (flags & 0x40) ? -1 : 0;
  4146. lp->asBit = 1 << ((csr6 >> 1) & 0x07);
  4147. lp->asPolarity = ((csr6 & 0x80) ? -1 : 0) & lp->asBit;
  4148. lp->infoblock_csr6 = OMR_DEF | ((csr6 & 0x71) << 18);
  4149. lp->useMII = false;
  4150. de4x5_switch_mac_port(dev);
  4151. }
  4152. return dc2114x_autoconf(dev);
  4153. }
  4154. /*
  4155. ** This block type provides information for resetting external devices
  4156. ** (chips) through the General Purpose Register.
  4157. */
  4158. static int
  4159. type5_infoblock(struct net_device *dev, u_char count, u_char *p)
  4160. {
  4161. struct de4x5_private *lp = netdev_priv(dev);
  4162. u_char len = (*p & BLOCK_LEN)+1;
  4163. /* Recursively figure out the info blocks */
  4164. if (--count > lp->tcount) {
  4165. if (*(p+len) < 128) {
  4166. return dc_infoblock[COMPACT](dev, count, p+len);
  4167. } else {
  4168. return dc_infoblock[*(p+len+1)](dev, count, p+len);
  4169. }
  4170. }
  4171. /* Must be initializing to run this code */
  4172. if ((lp->state == INITIALISED) || (lp->media == INIT)) {
  4173. p+=2;
  4174. lp->rst = p;
  4175. srom_exec(dev, lp->rst);
  4176. }
  4177. return DE4X5_AUTOSENSE_MS;
  4178. }
  4179. /*
  4180. ** MII Read/Write
  4181. */
  4182. static int
  4183. mii_rd(u_char phyreg, u_char phyaddr, u_long ioaddr)
  4184. {
  4185. mii_wdata(MII_PREAMBLE, 2, ioaddr); /* Start of 34 bit preamble... */
  4186. mii_wdata(MII_PREAMBLE, 32, ioaddr); /* ...continued */
  4187. mii_wdata(MII_STRD, 4, ioaddr); /* SFD and Read operation */
  4188. mii_address(phyaddr, ioaddr); /* PHY address to be accessed */
  4189. mii_address(phyreg, ioaddr); /* PHY Register to read */
  4190. mii_ta(MII_STRD, ioaddr); /* Turn around time - 2 MDC */
  4191. return mii_rdata(ioaddr); /* Read data */
  4192. }
  4193. static void
  4194. mii_wr(int data, u_char phyreg, u_char phyaddr, u_long ioaddr)
  4195. {
  4196. mii_wdata(MII_PREAMBLE, 2, ioaddr); /* Start of 34 bit preamble... */
  4197. mii_wdata(MII_PREAMBLE, 32, ioaddr); /* ...continued */
  4198. mii_wdata(MII_STWR, 4, ioaddr); /* SFD and Write operation */
  4199. mii_address(phyaddr, ioaddr); /* PHY address to be accessed */
  4200. mii_address(phyreg, ioaddr); /* PHY Register to write */
  4201. mii_ta(MII_STWR, ioaddr); /* Turn around time - 2 MDC */
  4202. data = mii_swap(data, 16); /* Swap data bit ordering */
  4203. mii_wdata(data, 16, ioaddr); /* Write data */
  4204. }
  4205. static int
  4206. mii_rdata(u_long ioaddr)
  4207. {
  4208. int i;
  4209. s32 tmp = 0;
  4210. for (i=0; i<16; i++) {
  4211. tmp <<= 1;
  4212. tmp |= getfrom_mii(MII_MRD | MII_RD, ioaddr);
  4213. }
  4214. return tmp;
  4215. }
  4216. static void
  4217. mii_wdata(int data, int len, u_long ioaddr)
  4218. {
  4219. int i;
  4220. for (i=0; i<len; i++) {
  4221. sendto_mii(MII_MWR | MII_WR, data, ioaddr);
  4222. data >>= 1;
  4223. }
  4224. }
  4225. static void
  4226. mii_address(u_char addr, u_long ioaddr)
  4227. {
  4228. int i;
  4229. addr = mii_swap(addr, 5);
  4230. for (i=0; i<5; i++) {
  4231. sendto_mii(MII_MWR | MII_WR, addr, ioaddr);
  4232. addr >>= 1;
  4233. }
  4234. }
  4235. static void
  4236. mii_ta(u_long rw, u_long ioaddr)
  4237. {
  4238. if (rw == MII_STWR) {
  4239. sendto_mii(MII_MWR | MII_WR, 1, ioaddr);
  4240. sendto_mii(MII_MWR | MII_WR, 0, ioaddr);
  4241. } else {
  4242. getfrom_mii(MII_MRD | MII_RD, ioaddr); /* Tri-state MDIO */
  4243. }
  4244. }
  4245. static int
  4246. mii_swap(int data, int len)
  4247. {
  4248. int i, tmp = 0;
  4249. for (i=0; i<len; i++) {
  4250. tmp <<= 1;
  4251. tmp |= (data & 1);
  4252. data >>= 1;
  4253. }
  4254. return tmp;
  4255. }
  4256. static void
  4257. sendto_mii(u32 command, int data, u_long ioaddr)
  4258. {
  4259. u32 j;
  4260. j = (data & 1) << 17;
  4261. outl(command | j, ioaddr);
  4262. udelay(1);
  4263. outl(command | MII_MDC | j, ioaddr);
  4264. udelay(1);
  4265. }
  4266. static int
  4267. getfrom_mii(u32 command, u_long ioaddr)
  4268. {
  4269. outl(command, ioaddr);
  4270. udelay(1);
  4271. outl(command | MII_MDC, ioaddr);
  4272. udelay(1);
  4273. return (inl(ioaddr) >> 19) & 1;
  4274. }
  4275. /*
  4276. ** Here's 3 ways to calculate the OUI from the ID registers.
  4277. */
  4278. static int
  4279. mii_get_oui(u_char phyaddr, u_long ioaddr)
  4280. {
  4281. /*
  4282. union {
  4283. u_short reg;
  4284. u_char breg[2];
  4285. } a;
  4286. int i, r2, r3, ret=0;*/
  4287. int r2, r3;
  4288. /* Read r2 and r3 */
  4289. r2 = mii_rd(MII_ID0, phyaddr, ioaddr);
  4290. r3 = mii_rd(MII_ID1, phyaddr, ioaddr);
  4291. /* SEEQ and Cypress way * /
  4292. / * Shuffle r2 and r3 * /
  4293. a.reg=0;
  4294. r3 = ((r3>>10)|(r2<<6))&0x0ff;
  4295. r2 = ((r2>>2)&0x3fff);
  4296. / * Bit reverse r3 * /
  4297. for (i=0;i<8;i++) {
  4298. ret<<=1;
  4299. ret |= (r3&1);
  4300. r3>>=1;
  4301. }
  4302. / * Bit reverse r2 * /
  4303. for (i=0;i<16;i++) {
  4304. a.reg<<=1;
  4305. a.reg |= (r2&1);
  4306. r2>>=1;
  4307. }
  4308. / * Swap r2 bytes * /
  4309. i=a.breg[0];
  4310. a.breg[0]=a.breg[1];
  4311. a.breg[1]=i;
  4312. return (a.reg<<8)|ret; */ /* SEEQ and Cypress way */
  4313. /* return (r2<<6)|(u_int)(r3>>10); */ /* NATIONAL and BROADCOM way */
  4314. return r2; /* (I did it) My way */
  4315. }
  4316. /*
  4317. ** The SROM spec forces us to search addresses [1-31 0]. Bummer.
  4318. */
  4319. static int
  4320. mii_get_phy(struct net_device *dev)
  4321. {
  4322. struct de4x5_private *lp = netdev_priv(dev);
  4323. u_long iobase = dev->base_addr;
  4324. int i, j, k, n, limit=ARRAY_SIZE(phy_info);
  4325. int id;
  4326. lp->active = 0;
  4327. lp->useMII = true;
  4328. /* Search the MII address space for possible PHY devices */
  4329. for (n=0, lp->mii_cnt=0, i=1; !((i==1) && (n==1)); i=(i+1)%DE4X5_MAX_MII) {
  4330. lp->phy[lp->active].addr = i;
  4331. if (i==0) n++; /* Count cycles */
  4332. while (de4x5_reset_phy(dev)<0) udelay(100);/* Wait for reset */
  4333. id = mii_get_oui(i, DE4X5_MII);
  4334. if ((id == 0) || (id == 65535)) continue; /* Valid ID? */
  4335. for (j=0; j<limit; j++) { /* Search PHY table */
  4336. if (id != phy_info[j].id) continue; /* ID match? */
  4337. for (k=0; k < DE4X5_MAX_PHY && lp->phy[k].id; k++);
  4338. if (k < DE4X5_MAX_PHY) {
  4339. memcpy((char *)&lp->phy[k],
  4340. (char *)&phy_info[j], sizeof(struct phy_table));
  4341. lp->phy[k].addr = i;
  4342. lp->mii_cnt++;
  4343. lp->active++;
  4344. } else {
  4345. goto purgatory; /* Stop the search */
  4346. }
  4347. break;
  4348. }
  4349. if ((j == limit) && (i < DE4X5_MAX_MII)) {
  4350. for (k=0; k < DE4X5_MAX_PHY && lp->phy[k].id; k++);
  4351. lp->phy[k].addr = i;
  4352. lp->phy[k].id = id;
  4353. lp->phy[k].spd.reg = GENERIC_REG; /* ANLPA register */
  4354. lp->phy[k].spd.mask = GENERIC_MASK; /* 100Mb/s technologies */
  4355. lp->phy[k].spd.value = GENERIC_VALUE; /* TX & T4, H/F Duplex */
  4356. lp->mii_cnt++;
  4357. lp->active++;
  4358. printk("%s: Using generic MII device control. If the board doesn't operate,\nplease mail the following dump to the author:\n", dev->name);
  4359. j = de4x5_debug;
  4360. de4x5_debug |= DEBUG_MII;
  4361. de4x5_dbg_mii(dev, k);
  4362. de4x5_debug = j;
  4363. printk("\n");
  4364. }
  4365. }
  4366. purgatory:
  4367. lp->active = 0;
  4368. if (lp->phy[0].id) { /* Reset the PHY devices */
  4369. for (k=0; k < DE4X5_MAX_PHY && lp->phy[k].id; k++) { /*For each PHY*/
  4370. mii_wr(MII_CR_RST, MII_CR, lp->phy[k].addr, DE4X5_MII);
  4371. while (mii_rd(MII_CR, lp->phy[k].addr, DE4X5_MII) & MII_CR_RST);
  4372. de4x5_dbg_mii(dev, k);
  4373. }
  4374. }
  4375. if (!lp->mii_cnt) lp->useMII = false;
  4376. return lp->mii_cnt;
  4377. }
  4378. static char *
  4379. build_setup_frame(struct net_device *dev, int mode)
  4380. {
  4381. struct de4x5_private *lp = netdev_priv(dev);
  4382. int i;
  4383. char *pa = lp->setup_frame;
  4384. /* Initialise the setup frame */
  4385. if (mode == ALL) {
  4386. memset(lp->setup_frame, 0, SETUP_FRAME_LEN);
  4387. }
  4388. if (lp->setup_f == HASH_PERF) {
  4389. for (pa=lp->setup_frame+IMPERF_PA_OFFSET, i=0; i<ETH_ALEN; i++) {
  4390. *(pa + i) = dev->dev_addr[i]; /* Host address */
  4391. if (i & 0x01) pa += 2;
  4392. }
  4393. *(lp->setup_frame + (DE4X5_HASH_TABLE_LEN >> 3) - 3) = 0x80;
  4394. } else {
  4395. for (i=0; i<ETH_ALEN; i++) { /* Host address */
  4396. *(pa + (i&1)) = dev->dev_addr[i];
  4397. if (i & 0x01) pa += 4;
  4398. }
  4399. for (i=0; i<ETH_ALEN; i++) { /* Broadcast address */
  4400. *(pa + (i&1)) = (char) 0xff;
  4401. if (i & 0x01) pa += 4;
  4402. }
  4403. }
  4404. return pa; /* Points to the next entry */
  4405. }
  4406. static void
  4407. disable_ast(struct net_device *dev)
  4408. {
  4409. struct de4x5_private *lp = netdev_priv(dev);
  4410. del_timer_sync(&lp->timer);
  4411. }
  4412. static long
  4413. de4x5_switch_mac_port(struct net_device *dev)
  4414. {
  4415. struct de4x5_private *lp = netdev_priv(dev);
  4416. u_long iobase = dev->base_addr;
  4417. s32 omr;
  4418. STOP_DE4X5;
  4419. /* Assert the OMR_PS bit in CSR6 */
  4420. omr = (inl(DE4X5_OMR) & ~(OMR_PS | OMR_HBD | OMR_TTM | OMR_PCS | OMR_SCR |
  4421. OMR_FDX));
  4422. omr |= lp->infoblock_csr6;
  4423. if (omr & OMR_PS) omr |= OMR_HBD;
  4424. outl(omr, DE4X5_OMR);
  4425. /* Soft Reset */
  4426. RESET_DE4X5;
  4427. /* Restore the GEP - especially for COMPACT and Type 0 Infoblocks */
  4428. if (lp->chipset == DC21140) {
  4429. gep_wr(lp->cache.gepc, dev);
  4430. gep_wr(lp->cache.gep, dev);
  4431. } else if ((lp->chipset & ~0x0ff) == DC2114x) {
  4432. reset_init_sia(dev, lp->cache.csr13, lp->cache.csr14, lp->cache.csr15);
  4433. }
  4434. /* Restore CSR6 */
  4435. outl(omr, DE4X5_OMR);
  4436. /* Reset CSR8 */
  4437. inl(DE4X5_MFC);
  4438. return omr;
  4439. }
  4440. static void
  4441. gep_wr(s32 data, struct net_device *dev)
  4442. {
  4443. struct de4x5_private *lp = netdev_priv(dev);
  4444. u_long iobase = dev->base_addr;
  4445. if (lp->chipset == DC21140) {
  4446. outl(data, DE4X5_GEP);
  4447. } else if ((lp->chipset & ~0x00ff) == DC2114x) {
  4448. outl((data<<16) | lp->cache.csr15, DE4X5_SIGR);
  4449. }
  4450. }
  4451. static int
  4452. gep_rd(struct net_device *dev)
  4453. {
  4454. struct de4x5_private *lp = netdev_priv(dev);
  4455. u_long iobase = dev->base_addr;
  4456. if (lp->chipset == DC21140) {
  4457. return inl(DE4X5_GEP);
  4458. } else if ((lp->chipset & ~0x00ff) == DC2114x) {
  4459. return inl(DE4X5_SIGR) & 0x000fffff;
  4460. }
  4461. return 0;
  4462. }
  4463. static void
  4464. yawn(struct net_device *dev, int state)
  4465. {
  4466. struct de4x5_private *lp = netdev_priv(dev);
  4467. u_long iobase = dev->base_addr;
  4468. if ((lp->chipset == DC21040) || (lp->chipset == DC21140)) return;
  4469. if(lp->bus == EISA) {
  4470. switch(state) {
  4471. case WAKEUP:
  4472. outb(WAKEUP, PCI_CFPM);
  4473. mdelay(10);
  4474. break;
  4475. case SNOOZE:
  4476. outb(SNOOZE, PCI_CFPM);
  4477. break;
  4478. case SLEEP:
  4479. outl(0, DE4X5_SICR);
  4480. outb(SLEEP, PCI_CFPM);
  4481. break;
  4482. }
  4483. } else {
  4484. struct pci_dev *pdev = to_pci_dev (lp->gendev);
  4485. switch(state) {
  4486. case WAKEUP:
  4487. pci_write_config_byte(pdev, PCI_CFDA_PSM, WAKEUP);
  4488. mdelay(10);
  4489. break;
  4490. case SNOOZE:
  4491. pci_write_config_byte(pdev, PCI_CFDA_PSM, SNOOZE);
  4492. break;
  4493. case SLEEP:
  4494. outl(0, DE4X5_SICR);
  4495. pci_write_config_byte(pdev, PCI_CFDA_PSM, SLEEP);
  4496. break;
  4497. }
  4498. }
  4499. }
  4500. static void
  4501. de4x5_parse_params(struct net_device *dev)
  4502. {
  4503. struct de4x5_private *lp = netdev_priv(dev);
  4504. char *p, *q, t;
  4505. lp->params.fdx = false;
  4506. lp->params.autosense = AUTO;
  4507. if (args == NULL) return;
  4508. if ((p = strstr(args, dev->name))) {
  4509. if (!(q = strstr(p+strlen(dev->name), "eth"))) q = p + strlen(p);
  4510. t = *q;
  4511. *q = '\0';
  4512. if (strstr(p, "fdx") || strstr(p, "FDX")) lp->params.fdx = true;
  4513. if (strstr(p, "autosense") || strstr(p, "AUTOSENSE")) {
  4514. if (strstr(p, "TP_NW")) {
  4515. lp->params.autosense = TP_NW;
  4516. } else if (strstr(p, "TP")) {
  4517. lp->params.autosense = TP;
  4518. } else if (strstr(p, "BNC_AUI")) {
  4519. lp->params.autosense = BNC;
  4520. } else if (strstr(p, "BNC")) {
  4521. lp->params.autosense = BNC;
  4522. } else if (strstr(p, "AUI")) {
  4523. lp->params.autosense = AUI;
  4524. } else if (strstr(p, "10Mb")) {
  4525. lp->params.autosense = _10Mb;
  4526. } else if (strstr(p, "100Mb")) {
  4527. lp->params.autosense = _100Mb;
  4528. } else if (strstr(p, "AUTO")) {
  4529. lp->params.autosense = AUTO;
  4530. }
  4531. }
  4532. *q = t;
  4533. }
  4534. }
  4535. static void
  4536. de4x5_dbg_open(struct net_device *dev)
  4537. {
  4538. struct de4x5_private *lp = netdev_priv(dev);
  4539. int i;
  4540. if (de4x5_debug & DEBUG_OPEN) {
  4541. printk("%s: de4x5 opening with irq %d\n",dev->name,dev->irq);
  4542. printk("\tphysical address: %pM\n", dev->dev_addr);
  4543. printk("Descriptor head addresses:\n");
  4544. printk("\t0x%8.8lx 0x%8.8lx\n",(u_long)lp->rx_ring,(u_long)lp->tx_ring);
  4545. printk("Descriptor addresses:\nRX: ");
  4546. for (i=0;i<lp->rxRingSize-1;i++){
  4547. if (i < 3) {
  4548. printk("0x%8.8lx ",(u_long)&lp->rx_ring[i].status);
  4549. }
  4550. }
  4551. printk("...0x%8.8lx\n",(u_long)&lp->rx_ring[i].status);
  4552. printk("TX: ");
  4553. for (i=0;i<lp->txRingSize-1;i++){
  4554. if (i < 3) {
  4555. printk("0x%8.8lx ", (u_long)&lp->tx_ring[i].status);
  4556. }
  4557. }
  4558. printk("...0x%8.8lx\n", (u_long)&lp->tx_ring[i].status);
  4559. printk("Descriptor buffers:\nRX: ");
  4560. for (i=0;i<lp->rxRingSize-1;i++){
  4561. if (i < 3) {
  4562. printk("0x%8.8x ",le32_to_cpu(lp->rx_ring[i].buf));
  4563. }
  4564. }
  4565. printk("...0x%8.8x\n",le32_to_cpu(lp->rx_ring[i].buf));
  4566. printk("TX: ");
  4567. for (i=0;i<lp->txRingSize-1;i++){
  4568. if (i < 3) {
  4569. printk("0x%8.8x ", le32_to_cpu(lp->tx_ring[i].buf));
  4570. }
  4571. }
  4572. printk("...0x%8.8x\n", le32_to_cpu(lp->tx_ring[i].buf));
  4573. printk("Ring size:\nRX: %d\nTX: %d\n",
  4574. (short)lp->rxRingSize,
  4575. (short)lp->txRingSize);
  4576. }
  4577. }
  4578. static void
  4579. de4x5_dbg_mii(struct net_device *dev, int k)
  4580. {
  4581. struct de4x5_private *lp = netdev_priv(dev);
  4582. u_long iobase = dev->base_addr;
  4583. if (de4x5_debug & DEBUG_MII) {
  4584. printk("\nMII device address: %d\n", lp->phy[k].addr);
  4585. printk("MII CR: %x\n",mii_rd(MII_CR,lp->phy[k].addr,DE4X5_MII));
  4586. printk("MII SR: %x\n",mii_rd(MII_SR,lp->phy[k].addr,DE4X5_MII));
  4587. printk("MII ID0: %x\n",mii_rd(MII_ID0,lp->phy[k].addr,DE4X5_MII));
  4588. printk("MII ID1: %x\n",mii_rd(MII_ID1,lp->phy[k].addr,DE4X5_MII));
  4589. if (lp->phy[k].id != BROADCOM_T4) {
  4590. printk("MII ANA: %x\n",mii_rd(0x04,lp->phy[k].addr,DE4X5_MII));
  4591. printk("MII ANC: %x\n",mii_rd(0x05,lp->phy[k].addr,DE4X5_MII));
  4592. }
  4593. printk("MII 16: %x\n",mii_rd(0x10,lp->phy[k].addr,DE4X5_MII));
  4594. if (lp->phy[k].id != BROADCOM_T4) {
  4595. printk("MII 17: %x\n",mii_rd(0x11,lp->phy[k].addr,DE4X5_MII));
  4596. printk("MII 18: %x\n",mii_rd(0x12,lp->phy[k].addr,DE4X5_MII));
  4597. } else {
  4598. printk("MII 20: %x\n",mii_rd(0x14,lp->phy[k].addr,DE4X5_MII));
  4599. }
  4600. }
  4601. }
  4602. static void
  4603. de4x5_dbg_media(struct net_device *dev)
  4604. {
  4605. struct de4x5_private *lp = netdev_priv(dev);
  4606. if (lp->media != lp->c_media) {
  4607. if (de4x5_debug & DEBUG_MEDIA) {
  4608. printk("%s: media is %s%s\n", dev->name,
  4609. (lp->media == NC ? "unconnected, link down or incompatible connection" :
  4610. (lp->media == TP ? "TP" :
  4611. (lp->media == ANS ? "TP/Nway" :
  4612. (lp->media == BNC ? "BNC" :
  4613. (lp->media == AUI ? "AUI" :
  4614. (lp->media == BNC_AUI ? "BNC/AUI" :
  4615. (lp->media == EXT_SIA ? "EXT SIA" :
  4616. (lp->media == _100Mb ? "100Mb/s" :
  4617. (lp->media == _10Mb ? "10Mb/s" :
  4618. "???"
  4619. ))))))))), (lp->fdx?" full duplex.":"."));
  4620. }
  4621. lp->c_media = lp->media;
  4622. }
  4623. }
  4624. static void
  4625. de4x5_dbg_srom(struct de4x5_srom *p)
  4626. {
  4627. int i;
  4628. if (de4x5_debug & DEBUG_SROM) {
  4629. printk("Sub-system Vendor ID: %04x\n", *((u_short *)p->sub_vendor_id));
  4630. printk("Sub-system ID: %04x\n", *((u_short *)p->sub_system_id));
  4631. printk("ID Block CRC: %02x\n", (u_char)(p->id_block_crc));
  4632. printk("SROM version: %02x\n", (u_char)(p->version));
  4633. printk("# controllers: %02x\n", (u_char)(p->num_controllers));
  4634. printk("Hardware Address: %pM\n", p->ieee_addr);
  4635. printk("CRC checksum: %04x\n", (u_short)(p->chksum));
  4636. for (i=0; i<64; i++) {
  4637. printk("%3d %04x\n", i<<1, (u_short)*((u_short *)p+i));
  4638. }
  4639. }
  4640. }
  4641. static void
  4642. de4x5_dbg_rx(struct sk_buff *skb, int len)
  4643. {
  4644. int i, j;
  4645. if (de4x5_debug & DEBUG_RX) {
  4646. printk("R: %pM <- %pM len/SAP:%02x%02x [%d]\n",
  4647. skb->data, &skb->data[6],
  4648. (u_char)skb->data[12],
  4649. (u_char)skb->data[13],
  4650. len);
  4651. for (j=0; len>0;j+=16, len-=16) {
  4652. printk(" %03x: ",j);
  4653. for (i=0; i<16 && i<len; i++) {
  4654. printk("%02x ",(u_char)skb->data[i+j]);
  4655. }
  4656. printk("\n");
  4657. }
  4658. }
  4659. }
  4660. /*
  4661. ** Perform IOCTL call functions here. Some are privileged operations and the
  4662. ** effective uid is checked in those cases. In the normal course of events
  4663. ** this function is only used for my testing.
  4664. */
  4665. static int
  4666. de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  4667. {
  4668. struct de4x5_private *lp = netdev_priv(dev);
  4669. struct de4x5_ioctl *ioc = (struct de4x5_ioctl *) &rq->ifr_ifru;
  4670. u_long iobase = dev->base_addr;
  4671. int i, j, status = 0;
  4672. s32 omr;
  4673. union {
  4674. u8 addr[144];
  4675. u16 sval[72];
  4676. u32 lval[36];
  4677. } tmp;
  4678. u_long flags = 0;
  4679. switch(ioc->cmd) {
  4680. case DE4X5_GET_HWADDR: /* Get the hardware address */
  4681. ioc->len = ETH_ALEN;
  4682. for (i=0; i<ETH_ALEN; i++) {
  4683. tmp.addr[i] = dev->dev_addr[i];
  4684. }
  4685. if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
  4686. break;
  4687. case DE4X5_SET_HWADDR: /* Set the hardware address */
  4688. if (!capable(CAP_NET_ADMIN)) return -EPERM;
  4689. if (copy_from_user(tmp.addr, ioc->data, ETH_ALEN)) return -EFAULT;
  4690. if (netif_queue_stopped(dev))
  4691. return -EBUSY;
  4692. netif_stop_queue(dev);
  4693. for (i=0; i<ETH_ALEN; i++) {
  4694. dev->dev_addr[i] = tmp.addr[i];
  4695. }
  4696. build_setup_frame(dev, PHYS_ADDR_ONLY);
  4697. /* Set up the descriptor and give ownership to the card */
  4698. load_packet(dev, lp->setup_frame, TD_IC | PERFECT_F | TD_SET |
  4699. SETUP_FRAME_LEN, (struct sk_buff *)1);
  4700. lp->tx_new = (lp->tx_new + 1) % lp->txRingSize;
  4701. outl(POLL_DEMAND, DE4X5_TPD); /* Start the TX */
  4702. netif_wake_queue(dev); /* Unlock the TX ring */
  4703. break;
  4704. case DE4X5_SAY_BOO: /* Say "Boo!" to the kernel log file */
  4705. if (!capable(CAP_NET_ADMIN)) return -EPERM;
  4706. printk("%s: Boo!\n", dev->name);
  4707. break;
  4708. case DE4X5_MCA_EN: /* Enable pass all multicast addressing */
  4709. if (!capable(CAP_NET_ADMIN)) return -EPERM;
  4710. omr = inl(DE4X5_OMR);
  4711. omr |= OMR_PM;
  4712. outl(omr, DE4X5_OMR);
  4713. break;
  4714. case DE4X5_GET_STATS: /* Get the driver statistics */
  4715. {
  4716. struct pkt_stats statbuf;
  4717. ioc->len = sizeof(statbuf);
  4718. spin_lock_irqsave(&lp->lock, flags);
  4719. memcpy(&statbuf, &lp->pktStats, ioc->len);
  4720. spin_unlock_irqrestore(&lp->lock, flags);
  4721. if (copy_to_user(ioc->data, &statbuf, ioc->len))
  4722. return -EFAULT;
  4723. break;
  4724. }
  4725. case DE4X5_CLR_STATS: /* Zero out the driver statistics */
  4726. if (!capable(CAP_NET_ADMIN)) return -EPERM;
  4727. spin_lock_irqsave(&lp->lock, flags);
  4728. memset(&lp->pktStats, 0, sizeof(lp->pktStats));
  4729. spin_unlock_irqrestore(&lp->lock, flags);
  4730. break;
  4731. case DE4X5_GET_OMR: /* Get the OMR Register contents */
  4732. tmp.addr[0] = inl(DE4X5_OMR);
  4733. if (copy_to_user(ioc->data, tmp.addr, 1)) return -EFAULT;
  4734. break;
  4735. case DE4X5_SET_OMR: /* Set the OMR Register contents */
  4736. if (!capable(CAP_NET_ADMIN)) return -EPERM;
  4737. if (copy_from_user(tmp.addr, ioc->data, 1)) return -EFAULT;
  4738. outl(tmp.addr[0], DE4X5_OMR);
  4739. break;
  4740. case DE4X5_GET_REG: /* Get the DE4X5 Registers */
  4741. j = 0;
  4742. tmp.lval[0] = inl(DE4X5_STS); j+=4;
  4743. tmp.lval[1] = inl(DE4X5_BMR); j+=4;
  4744. tmp.lval[2] = inl(DE4X5_IMR); j+=4;
  4745. tmp.lval[3] = inl(DE4X5_OMR); j+=4;
  4746. tmp.lval[4] = inl(DE4X5_SISR); j+=4;
  4747. tmp.lval[5] = inl(DE4X5_SICR); j+=4;
  4748. tmp.lval[6] = inl(DE4X5_STRR); j+=4;
  4749. tmp.lval[7] = inl(DE4X5_SIGR); j+=4;
  4750. ioc->len = j;
  4751. if (copy_to_user(ioc->data, tmp.lval, ioc->len))
  4752. return -EFAULT;
  4753. break;
  4754. #define DE4X5_DUMP 0x0f /* Dump the DE4X5 Status */
  4755. /*
  4756. case DE4X5_DUMP:
  4757. j = 0;
  4758. tmp.addr[j++] = dev->irq;
  4759. for (i=0; i<ETH_ALEN; i++) {
  4760. tmp.addr[j++] = dev->dev_addr[i];
  4761. }
  4762. tmp.addr[j++] = lp->rxRingSize;
  4763. tmp.lval[j>>2] = (long)lp->rx_ring; j+=4;
  4764. tmp.lval[j>>2] = (long)lp->tx_ring; j+=4;
  4765. for (i=0;i<lp->rxRingSize-1;i++){
  4766. if (i < 3) {
  4767. tmp.lval[j>>2] = (long)&lp->rx_ring[i].status; j+=4;
  4768. }
  4769. }
  4770. tmp.lval[j>>2] = (long)&lp->rx_ring[i].status; j+=4;
  4771. for (i=0;i<lp->txRingSize-1;i++){
  4772. if (i < 3) {
  4773. tmp.lval[j>>2] = (long)&lp->tx_ring[i].status; j+=4;
  4774. }
  4775. }
  4776. tmp.lval[j>>2] = (long)&lp->tx_ring[i].status; j+=4;
  4777. for (i=0;i<lp->rxRingSize-1;i++){
  4778. if (i < 3) {
  4779. tmp.lval[j>>2] = (s32)le32_to_cpu(lp->rx_ring[i].buf); j+=4;
  4780. }
  4781. }
  4782. tmp.lval[j>>2] = (s32)le32_to_cpu(lp->rx_ring[i].buf); j+=4;
  4783. for (i=0;i<lp->txRingSize-1;i++){
  4784. if (i < 3) {
  4785. tmp.lval[j>>2] = (s32)le32_to_cpu(lp->tx_ring[i].buf); j+=4;
  4786. }
  4787. }
  4788. tmp.lval[j>>2] = (s32)le32_to_cpu(lp->tx_ring[i].buf); j+=4;
  4789. for (i=0;i<lp->rxRingSize;i++){
  4790. tmp.lval[j>>2] = le32_to_cpu(lp->rx_ring[i].status); j+=4;
  4791. }
  4792. for (i=0;i<lp->txRingSize;i++){
  4793. tmp.lval[j>>2] = le32_to_cpu(lp->tx_ring[i].status); j+=4;
  4794. }
  4795. tmp.lval[j>>2] = inl(DE4X5_BMR); j+=4;
  4796. tmp.lval[j>>2] = inl(DE4X5_TPD); j+=4;
  4797. tmp.lval[j>>2] = inl(DE4X5_RPD); j+=4;
  4798. tmp.lval[j>>2] = inl(DE4X5_RRBA); j+=4;
  4799. tmp.lval[j>>2] = inl(DE4X5_TRBA); j+=4;
  4800. tmp.lval[j>>2] = inl(DE4X5_STS); j+=4;
  4801. tmp.lval[j>>2] = inl(DE4X5_OMR); j+=4;
  4802. tmp.lval[j>>2] = inl(DE4X5_IMR); j+=4;
  4803. tmp.lval[j>>2] = lp->chipset; j+=4;
  4804. if (lp->chipset == DC21140) {
  4805. tmp.lval[j>>2] = gep_rd(dev); j+=4;
  4806. } else {
  4807. tmp.lval[j>>2] = inl(DE4X5_SISR); j+=4;
  4808. tmp.lval[j>>2] = inl(DE4X5_SICR); j+=4;
  4809. tmp.lval[j>>2] = inl(DE4X5_STRR); j+=4;
  4810. tmp.lval[j>>2] = inl(DE4X5_SIGR); j+=4;
  4811. }
  4812. tmp.lval[j>>2] = lp->phy[lp->active].id; j+=4;
  4813. if (lp->phy[lp->active].id && (!lp->useSROM || lp->useMII)) {
  4814. tmp.lval[j>>2] = lp->active; j+=4;
  4815. tmp.lval[j>>2]=mii_rd(MII_CR,lp->phy[lp->active].addr,DE4X5_MII); j+=4;
  4816. tmp.lval[j>>2]=mii_rd(MII_SR,lp->phy[lp->active].addr,DE4X5_MII); j+=4;
  4817. tmp.lval[j>>2]=mii_rd(MII_ID0,lp->phy[lp->active].addr,DE4X5_MII); j+=4;
  4818. tmp.lval[j>>2]=mii_rd(MII_ID1,lp->phy[lp->active].addr,DE4X5_MII); j+=4;
  4819. if (lp->phy[lp->active].id != BROADCOM_T4) {
  4820. tmp.lval[j>>2]=mii_rd(MII_ANA,lp->phy[lp->active].addr,DE4X5_MII); j+=4;
  4821. tmp.lval[j>>2]=mii_rd(MII_ANLPA,lp->phy[lp->active].addr,DE4X5_MII); j+=4;
  4822. }
  4823. tmp.lval[j>>2]=mii_rd(0x10,lp->phy[lp->active].addr,DE4X5_MII); j+=4;
  4824. if (lp->phy[lp->active].id != BROADCOM_T4) {
  4825. tmp.lval[j>>2]=mii_rd(0x11,lp->phy[lp->active].addr,DE4X5_MII); j+=4;
  4826. tmp.lval[j>>2]=mii_rd(0x12,lp->phy[lp->active].addr,DE4X5_MII); j+=4;
  4827. } else {
  4828. tmp.lval[j>>2]=mii_rd(0x14,lp->phy[lp->active].addr,DE4X5_MII); j+=4;
  4829. }
  4830. }
  4831. tmp.addr[j++] = lp->txRingSize;
  4832. tmp.addr[j++] = netif_queue_stopped(dev);
  4833. ioc->len = j;
  4834. if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
  4835. break;
  4836. */
  4837. default:
  4838. return -EOPNOTSUPP;
  4839. }
  4840. return status;
  4841. }
  4842. static int __init de4x5_module_init (void)
  4843. {
  4844. int err = 0;
  4845. #ifdef CONFIG_PCI
  4846. err = pci_register_driver(&de4x5_pci_driver);
  4847. #endif
  4848. #ifdef CONFIG_EISA
  4849. err |= eisa_driver_register (&de4x5_eisa_driver);
  4850. #endif
  4851. return err;
  4852. }
  4853. static void __exit de4x5_module_exit (void)
  4854. {
  4855. #ifdef CONFIG_PCI
  4856. pci_unregister_driver (&de4x5_pci_driver);
  4857. #endif
  4858. #ifdef CONFIG_EISA
  4859. eisa_driver_unregister (&de4x5_eisa_driver);
  4860. #endif
  4861. }
  4862. module_init (de4x5_module_init);
  4863. module_exit (de4x5_module_exit);