sky2.c 137 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271
  1. /*
  2. * New driver for Marvell Yukon 2 chipset.
  3. * Based on earlier sk98lin, and skge driver.
  4. *
  5. * This driver intentionally does not support all the features
  6. * of the original driver such as link fail-over and link management because
  7. * those should be done at higher levels.
  8. *
  9. * Copyright (C) 2005 Stephen Hemminger <shemminger@osdl.org>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. */
  24. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  25. #include <linux/crc32.h>
  26. #include <linux/kernel.h>
  27. #include <linux/module.h>
  28. #include <linux/netdevice.h>
  29. #include <linux/dma-mapping.h>
  30. #include <linux/etherdevice.h>
  31. #include <linux/ethtool.h>
  32. #include <linux/pci.h>
  33. #include <linux/interrupt.h>
  34. #include <linux/ip.h>
  35. #include <linux/slab.h>
  36. #include <net/ip.h>
  37. #include <linux/tcp.h>
  38. #include <linux/in.h>
  39. #include <linux/delay.h>
  40. #include <linux/workqueue.h>
  41. #include <linux/if_vlan.h>
  42. #include <linux/prefetch.h>
  43. #include <linux/debugfs.h>
  44. #include <linux/mii.h>
  45. #include <linux/of_device.h>
  46. #include <linux/of_net.h>
  47. #include <asm/irq.h>
  48. #include "sky2.h"
  49. #define DRV_NAME "sky2"
  50. #define DRV_VERSION "1.30"
  51. /*
  52. * The Yukon II chipset takes 64 bit command blocks (called list elements)
  53. * that are organized into three (receive, transmit, status) different rings
  54. * similar to Tigon3.
  55. */
  56. #define RX_LE_SIZE 1024
  57. #define RX_LE_BYTES (RX_LE_SIZE*sizeof(struct sky2_rx_le))
  58. #define RX_MAX_PENDING (RX_LE_SIZE/6 - 2)
  59. #define RX_DEF_PENDING RX_MAX_PENDING
  60. /* This is the worst case number of transmit list elements for a single skb:
  61. VLAN:GSO + CKSUM + Data + skb_frags * DMA */
  62. #define MAX_SKB_TX_LE (2 + (sizeof(dma_addr_t)/sizeof(u32))*(MAX_SKB_FRAGS+1))
  63. #define TX_MIN_PENDING (MAX_SKB_TX_LE+1)
  64. #define TX_MAX_PENDING 1024
  65. #define TX_DEF_PENDING 63
  66. #define TX_WATCHDOG (5 * HZ)
  67. #define NAPI_WEIGHT 64
  68. #define PHY_RETRIES 1000
  69. #define SKY2_EEPROM_MAGIC 0x9955aabb
  70. #define RING_NEXT(x, s) (((x)+1) & ((s)-1))
  71. static const u32 default_msg =
  72. NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK
  73. | NETIF_MSG_TIMER | NETIF_MSG_TX_ERR | NETIF_MSG_RX_ERR
  74. | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN;
  75. static int debug = -1; /* defaults above */
  76. module_param(debug, int, 0);
  77. MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
  78. static int copybreak __read_mostly = 128;
  79. module_param(copybreak, int, 0);
  80. MODULE_PARM_DESC(copybreak, "Receive copy threshold");
  81. static int disable_msi = 0;
  82. module_param(disable_msi, int, 0);
  83. MODULE_PARM_DESC(disable_msi, "Disable Message Signaled Interrupt (MSI)");
  84. static int legacy_pme = 0;
  85. module_param(legacy_pme, int, 0);
  86. MODULE_PARM_DESC(legacy_pme, "Legacy power management");
  87. static const struct pci_device_id sky2_id_table[] = {
  88. { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, 0x9000) }, /* SK-9Sxx */
  89. { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, 0x9E00) }, /* SK-9Exx */
  90. { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, 0x9E01) }, /* SK-9E21M */
  91. { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4b00) }, /* DGE-560T */
  92. { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4001) }, /* DGE-550SX */
  93. { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4B02) }, /* DGE-560SX */
  94. { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4B03) }, /* DGE-550T */
  95. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4340) }, /* 88E8021 */
  96. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4341) }, /* 88E8022 */
  97. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4342) }, /* 88E8061 */
  98. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4343) }, /* 88E8062 */
  99. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4344) }, /* 88E8021 */
  100. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4345) }, /* 88E8022 */
  101. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4346) }, /* 88E8061 */
  102. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4347) }, /* 88E8062 */
  103. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4350) }, /* 88E8035 */
  104. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4351) }, /* 88E8036 */
  105. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4352) }, /* 88E8038 */
  106. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4353) }, /* 88E8039 */
  107. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4354) }, /* 88E8040 */
  108. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4355) }, /* 88E8040T */
  109. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4356) }, /* 88EC033 */
  110. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4357) }, /* 88E8042 */
  111. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x435A) }, /* 88E8048 */
  112. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4360) }, /* 88E8052 */
  113. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4361) }, /* 88E8050 */
  114. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4362) }, /* 88E8053 */
  115. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4363) }, /* 88E8055 */
  116. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4364) }, /* 88E8056 */
  117. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4365) }, /* 88E8070 */
  118. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4366) }, /* 88EC036 */
  119. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4367) }, /* 88EC032 */
  120. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4368) }, /* 88EC034 */
  121. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4369) }, /* 88EC042 */
  122. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x436A) }, /* 88E8058 */
  123. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x436B) }, /* 88E8071 */
  124. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x436C) }, /* 88E8072 */
  125. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x436D) }, /* 88E8055 */
  126. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4370) }, /* 88E8075 */
  127. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4380) }, /* 88E8057 */
  128. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4381) }, /* 88E8059 */
  129. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4382) }, /* 88E8079 */
  130. { 0 }
  131. };
  132. MODULE_DEVICE_TABLE(pci, sky2_id_table);
  133. /* Avoid conditionals by using array */
  134. static const unsigned txqaddr[] = { Q_XA1, Q_XA2 };
  135. static const unsigned rxqaddr[] = { Q_R1, Q_R2 };
  136. static const u32 portirq_msk[] = { Y2_IS_PORT_1, Y2_IS_PORT_2 };
  137. static void sky2_set_multicast(struct net_device *dev);
  138. static irqreturn_t sky2_intr(int irq, void *dev_id);
  139. /* Access to PHY via serial interconnect */
  140. static int gm_phy_write(struct sky2_hw *hw, unsigned port, u16 reg, u16 val)
  141. {
  142. int i;
  143. gma_write16(hw, port, GM_SMI_DATA, val);
  144. gma_write16(hw, port, GM_SMI_CTRL,
  145. GM_SMI_CT_PHY_AD(PHY_ADDR_MARV) | GM_SMI_CT_REG_AD(reg));
  146. for (i = 0; i < PHY_RETRIES; i++) {
  147. u16 ctrl = gma_read16(hw, port, GM_SMI_CTRL);
  148. if (ctrl == 0xffff)
  149. goto io_error;
  150. if (!(ctrl & GM_SMI_CT_BUSY))
  151. return 0;
  152. udelay(10);
  153. }
  154. dev_warn(&hw->pdev->dev, "%s: phy write timeout\n", hw->dev[port]->name);
  155. return -ETIMEDOUT;
  156. io_error:
  157. dev_err(&hw->pdev->dev, "%s: phy I/O error\n", hw->dev[port]->name);
  158. return -EIO;
  159. }
  160. static int __gm_phy_read(struct sky2_hw *hw, unsigned port, u16 reg, u16 *val)
  161. {
  162. int i;
  163. gma_write16(hw, port, GM_SMI_CTRL, GM_SMI_CT_PHY_AD(PHY_ADDR_MARV)
  164. | GM_SMI_CT_REG_AD(reg) | GM_SMI_CT_OP_RD);
  165. for (i = 0; i < PHY_RETRIES; i++) {
  166. u16 ctrl = gma_read16(hw, port, GM_SMI_CTRL);
  167. if (ctrl == 0xffff)
  168. goto io_error;
  169. if (ctrl & GM_SMI_CT_RD_VAL) {
  170. *val = gma_read16(hw, port, GM_SMI_DATA);
  171. return 0;
  172. }
  173. udelay(10);
  174. }
  175. dev_warn(&hw->pdev->dev, "%s: phy read timeout\n", hw->dev[port]->name);
  176. return -ETIMEDOUT;
  177. io_error:
  178. dev_err(&hw->pdev->dev, "%s: phy I/O error\n", hw->dev[port]->name);
  179. return -EIO;
  180. }
  181. static inline u16 gm_phy_read(struct sky2_hw *hw, unsigned port, u16 reg)
  182. {
  183. u16 v;
  184. __gm_phy_read(hw, port, reg, &v);
  185. return v;
  186. }
  187. static void sky2_power_on(struct sky2_hw *hw)
  188. {
  189. /* switch power to VCC (WA for VAUX problem) */
  190. sky2_write8(hw, B0_POWER_CTRL,
  191. PC_VAUX_ENA | PC_VCC_ENA | PC_VAUX_OFF | PC_VCC_ON);
  192. /* disable Core Clock Division, */
  193. sky2_write32(hw, B2_Y2_CLK_CTRL, Y2_CLK_DIV_DIS);
  194. if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > CHIP_REV_YU_XL_A1)
  195. /* enable bits are inverted */
  196. sky2_write8(hw, B2_Y2_CLK_GATE,
  197. Y2_PCI_CLK_LNK1_DIS | Y2_COR_CLK_LNK1_DIS |
  198. Y2_CLK_GAT_LNK1_DIS | Y2_PCI_CLK_LNK2_DIS |
  199. Y2_COR_CLK_LNK2_DIS | Y2_CLK_GAT_LNK2_DIS);
  200. else
  201. sky2_write8(hw, B2_Y2_CLK_GATE, 0);
  202. if (hw->flags & SKY2_HW_ADV_POWER_CTL) {
  203. u32 reg;
  204. sky2_pci_write32(hw, PCI_DEV_REG3, 0);
  205. reg = sky2_pci_read32(hw, PCI_DEV_REG4);
  206. /* set all bits to 0 except bits 15..12 and 8 */
  207. reg &= P_ASPM_CONTROL_MSK;
  208. sky2_pci_write32(hw, PCI_DEV_REG4, reg);
  209. reg = sky2_pci_read32(hw, PCI_DEV_REG5);
  210. /* set all bits to 0 except bits 28 & 27 */
  211. reg &= P_CTL_TIM_VMAIN_AV_MSK;
  212. sky2_pci_write32(hw, PCI_DEV_REG5, reg);
  213. sky2_pci_write32(hw, PCI_CFG_REG_1, 0);
  214. sky2_write16(hw, B0_CTST, Y2_HW_WOL_ON);
  215. /* Enable workaround for dev 4.107 on Yukon-Ultra & Extreme */
  216. reg = sky2_read32(hw, B2_GP_IO);
  217. reg |= GLB_GPIO_STAT_RACE_DIS;
  218. sky2_write32(hw, B2_GP_IO, reg);
  219. sky2_read32(hw, B2_GP_IO);
  220. }
  221. /* Turn on "driver loaded" LED */
  222. sky2_write16(hw, B0_CTST, Y2_LED_STAT_ON);
  223. }
  224. static void sky2_power_aux(struct sky2_hw *hw)
  225. {
  226. if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > CHIP_REV_YU_XL_A1)
  227. sky2_write8(hw, B2_Y2_CLK_GATE, 0);
  228. else
  229. /* enable bits are inverted */
  230. sky2_write8(hw, B2_Y2_CLK_GATE,
  231. Y2_PCI_CLK_LNK1_DIS | Y2_COR_CLK_LNK1_DIS |
  232. Y2_CLK_GAT_LNK1_DIS | Y2_PCI_CLK_LNK2_DIS |
  233. Y2_COR_CLK_LNK2_DIS | Y2_CLK_GAT_LNK2_DIS);
  234. /* switch power to VAUX if supported and PME from D3cold */
  235. if ( (sky2_read32(hw, B0_CTST) & Y2_VAUX_AVAIL) &&
  236. pci_pme_capable(hw->pdev, PCI_D3cold))
  237. sky2_write8(hw, B0_POWER_CTRL,
  238. (PC_VAUX_ENA | PC_VCC_ENA |
  239. PC_VAUX_ON | PC_VCC_OFF));
  240. /* turn off "driver loaded LED" */
  241. sky2_write16(hw, B0_CTST, Y2_LED_STAT_OFF);
  242. }
  243. static void sky2_gmac_reset(struct sky2_hw *hw, unsigned port)
  244. {
  245. u16 reg;
  246. /* disable all GMAC IRQ's */
  247. sky2_write8(hw, SK_REG(port, GMAC_IRQ_MSK), 0);
  248. gma_write16(hw, port, GM_MC_ADDR_H1, 0); /* clear MC hash */
  249. gma_write16(hw, port, GM_MC_ADDR_H2, 0);
  250. gma_write16(hw, port, GM_MC_ADDR_H3, 0);
  251. gma_write16(hw, port, GM_MC_ADDR_H4, 0);
  252. reg = gma_read16(hw, port, GM_RX_CTRL);
  253. reg |= GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA;
  254. gma_write16(hw, port, GM_RX_CTRL, reg);
  255. }
  256. /* flow control to advertise bits */
  257. static const u16 copper_fc_adv[] = {
  258. [FC_NONE] = 0,
  259. [FC_TX] = PHY_M_AN_ASP,
  260. [FC_RX] = PHY_M_AN_PC,
  261. [FC_BOTH] = PHY_M_AN_PC | PHY_M_AN_ASP,
  262. };
  263. /* flow control to advertise bits when using 1000BaseX */
  264. static const u16 fiber_fc_adv[] = {
  265. [FC_NONE] = PHY_M_P_NO_PAUSE_X,
  266. [FC_TX] = PHY_M_P_ASYM_MD_X,
  267. [FC_RX] = PHY_M_P_SYM_MD_X,
  268. [FC_BOTH] = PHY_M_P_BOTH_MD_X,
  269. };
  270. /* flow control to GMA disable bits */
  271. static const u16 gm_fc_disable[] = {
  272. [FC_NONE] = GM_GPCR_FC_RX_DIS | GM_GPCR_FC_TX_DIS,
  273. [FC_TX] = GM_GPCR_FC_RX_DIS,
  274. [FC_RX] = GM_GPCR_FC_TX_DIS,
  275. [FC_BOTH] = 0,
  276. };
  277. static void sky2_phy_init(struct sky2_hw *hw, unsigned port)
  278. {
  279. struct sky2_port *sky2 = netdev_priv(hw->dev[port]);
  280. u16 ctrl, ct1000, adv, pg, ledctrl, ledover, reg;
  281. if ( (sky2->flags & SKY2_FLAG_AUTO_SPEED) &&
  282. !(hw->flags & SKY2_HW_NEWER_PHY)) {
  283. u16 ectrl = gm_phy_read(hw, port, PHY_MARV_EXT_CTRL);
  284. ectrl &= ~(PHY_M_EC_M_DSC_MSK | PHY_M_EC_S_DSC_MSK |
  285. PHY_M_EC_MAC_S_MSK);
  286. ectrl |= PHY_M_EC_MAC_S(MAC_TX_CLK_25_MHZ);
  287. /* on PHY 88E1040 Rev.D0 (and newer) downshift control changed */
  288. if (hw->chip_id == CHIP_ID_YUKON_EC)
  289. /* set downshift counter to 3x and enable downshift */
  290. ectrl |= PHY_M_EC_DSC_2(2) | PHY_M_EC_DOWN_S_ENA;
  291. else
  292. /* set master & slave downshift counter to 1x */
  293. ectrl |= PHY_M_EC_M_DSC(0) | PHY_M_EC_S_DSC(1);
  294. gm_phy_write(hw, port, PHY_MARV_EXT_CTRL, ectrl);
  295. }
  296. ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL);
  297. if (sky2_is_copper(hw)) {
  298. if (!(hw->flags & SKY2_HW_GIGABIT)) {
  299. /* enable automatic crossover */
  300. ctrl |= PHY_M_PC_MDI_XMODE(PHY_M_PC_ENA_AUTO) >> 1;
  301. if (hw->chip_id == CHIP_ID_YUKON_FE_P &&
  302. hw->chip_rev == CHIP_REV_YU_FE2_A0) {
  303. u16 spec;
  304. /* Enable Class A driver for FE+ A0 */
  305. spec = gm_phy_read(hw, port, PHY_MARV_FE_SPEC_2);
  306. spec |= PHY_M_FESC_SEL_CL_A;
  307. gm_phy_write(hw, port, PHY_MARV_FE_SPEC_2, spec);
  308. }
  309. } else {
  310. /* disable energy detect */
  311. ctrl &= ~PHY_M_PC_EN_DET_MSK;
  312. /* enable automatic crossover */
  313. ctrl |= PHY_M_PC_MDI_XMODE(PHY_M_PC_ENA_AUTO);
  314. /* downshift on PHY 88E1112 and 88E1149 is changed */
  315. if ( (sky2->flags & SKY2_FLAG_AUTO_SPEED) &&
  316. (hw->flags & SKY2_HW_NEWER_PHY)) {
  317. /* set downshift counter to 3x and enable downshift */
  318. ctrl &= ~PHY_M_PC_DSC_MSK;
  319. ctrl |= PHY_M_PC_DSC(2) | PHY_M_PC_DOWN_S_ENA;
  320. }
  321. }
  322. } else {
  323. /* workaround for deviation #4.88 (CRC errors) */
  324. /* disable Automatic Crossover */
  325. ctrl &= ~PHY_M_PC_MDIX_MSK;
  326. }
  327. gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl);
  328. /* special setup for PHY 88E1112 Fiber */
  329. if (hw->chip_id == CHIP_ID_YUKON_XL && (hw->flags & SKY2_HW_FIBRE_PHY)) {
  330. pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR);
  331. /* Fiber: select 1000BASE-X only mode MAC Specific Ctrl Reg. */
  332. gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 2);
  333. ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL);
  334. ctrl &= ~PHY_M_MAC_MD_MSK;
  335. ctrl |= PHY_M_MAC_MODE_SEL(PHY_M_MAC_MD_1000BX);
  336. gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl);
  337. if (hw->pmd_type == 'P') {
  338. /* select page 1 to access Fiber registers */
  339. gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 1);
  340. /* for SFP-module set SIGDET polarity to low */
  341. ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL);
  342. ctrl |= PHY_M_FIB_SIGD_POL;
  343. gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl);
  344. }
  345. gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg);
  346. }
  347. ctrl = PHY_CT_RESET;
  348. ct1000 = 0;
  349. adv = PHY_AN_CSMA;
  350. reg = 0;
  351. if (sky2->flags & SKY2_FLAG_AUTO_SPEED) {
  352. if (sky2_is_copper(hw)) {
  353. if (sky2->advertising & ADVERTISED_1000baseT_Full)
  354. ct1000 |= PHY_M_1000C_AFD;
  355. if (sky2->advertising & ADVERTISED_1000baseT_Half)
  356. ct1000 |= PHY_M_1000C_AHD;
  357. if (sky2->advertising & ADVERTISED_100baseT_Full)
  358. adv |= PHY_M_AN_100_FD;
  359. if (sky2->advertising & ADVERTISED_100baseT_Half)
  360. adv |= PHY_M_AN_100_HD;
  361. if (sky2->advertising & ADVERTISED_10baseT_Full)
  362. adv |= PHY_M_AN_10_FD;
  363. if (sky2->advertising & ADVERTISED_10baseT_Half)
  364. adv |= PHY_M_AN_10_HD;
  365. } else { /* special defines for FIBER (88E1040S only) */
  366. if (sky2->advertising & ADVERTISED_1000baseT_Full)
  367. adv |= PHY_M_AN_1000X_AFD;
  368. if (sky2->advertising & ADVERTISED_1000baseT_Half)
  369. adv |= PHY_M_AN_1000X_AHD;
  370. }
  371. /* Restart Auto-negotiation */
  372. ctrl |= PHY_CT_ANE | PHY_CT_RE_CFG;
  373. } else {
  374. /* forced speed/duplex settings */
  375. ct1000 = PHY_M_1000C_MSE;
  376. /* Disable auto update for duplex flow control and duplex */
  377. reg |= GM_GPCR_AU_DUP_DIS | GM_GPCR_AU_SPD_DIS;
  378. switch (sky2->speed) {
  379. case SPEED_1000:
  380. ctrl |= PHY_CT_SP1000;
  381. reg |= GM_GPCR_SPEED_1000;
  382. break;
  383. case SPEED_100:
  384. ctrl |= PHY_CT_SP100;
  385. reg |= GM_GPCR_SPEED_100;
  386. break;
  387. }
  388. if (sky2->duplex == DUPLEX_FULL) {
  389. reg |= GM_GPCR_DUP_FULL;
  390. ctrl |= PHY_CT_DUP_MD;
  391. } else if (sky2->speed < SPEED_1000)
  392. sky2->flow_mode = FC_NONE;
  393. }
  394. if (sky2->flags & SKY2_FLAG_AUTO_PAUSE) {
  395. if (sky2_is_copper(hw))
  396. adv |= copper_fc_adv[sky2->flow_mode];
  397. else
  398. adv |= fiber_fc_adv[sky2->flow_mode];
  399. } else {
  400. reg |= GM_GPCR_AU_FCT_DIS;
  401. reg |= gm_fc_disable[sky2->flow_mode];
  402. /* Forward pause packets to GMAC? */
  403. if (sky2->flow_mode & FC_RX)
  404. sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_ON);
  405. else
  406. sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF);
  407. }
  408. gma_write16(hw, port, GM_GP_CTRL, reg);
  409. if (hw->flags & SKY2_HW_GIGABIT)
  410. gm_phy_write(hw, port, PHY_MARV_1000T_CTRL, ct1000);
  411. gm_phy_write(hw, port, PHY_MARV_AUNE_ADV, adv);
  412. gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl);
  413. /* Setup Phy LED's */
  414. ledctrl = PHY_M_LED_PULS_DUR(PULS_170MS);
  415. ledover = 0;
  416. switch (hw->chip_id) {
  417. case CHIP_ID_YUKON_FE:
  418. /* on 88E3082 these bits are at 11..9 (shifted left) */
  419. ledctrl |= PHY_M_LED_BLINK_RT(BLINK_84MS) << 1;
  420. ctrl = gm_phy_read(hw, port, PHY_MARV_FE_LED_PAR);
  421. /* delete ACT LED control bits */
  422. ctrl &= ~PHY_M_FELP_LED1_MSK;
  423. /* change ACT LED control to blink mode */
  424. ctrl |= PHY_M_FELP_LED1_CTRL(LED_PAR_CTRL_ACT_BL);
  425. gm_phy_write(hw, port, PHY_MARV_FE_LED_PAR, ctrl);
  426. break;
  427. case CHIP_ID_YUKON_FE_P:
  428. /* Enable Link Partner Next Page */
  429. ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL);
  430. ctrl |= PHY_M_PC_ENA_LIP_NP;
  431. /* disable Energy Detect and enable scrambler */
  432. ctrl &= ~(PHY_M_PC_ENA_ENE_DT | PHY_M_PC_DIS_SCRAMB);
  433. gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl);
  434. /* set LED2 -> ACT, LED1 -> LINK, LED0 -> SPEED */
  435. ctrl = PHY_M_FELP_LED2_CTRL(LED_PAR_CTRL_ACT_BL) |
  436. PHY_M_FELP_LED1_CTRL(LED_PAR_CTRL_LINK) |
  437. PHY_M_FELP_LED0_CTRL(LED_PAR_CTRL_SPEED);
  438. gm_phy_write(hw, port, PHY_MARV_FE_LED_PAR, ctrl);
  439. break;
  440. case CHIP_ID_YUKON_XL:
  441. pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR);
  442. /* select page 3 to access LED control register */
  443. gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 3);
  444. /* set LED Function Control register */
  445. gm_phy_write(hw, port, PHY_MARV_PHY_CTRL,
  446. (PHY_M_LEDC_LOS_CTRL(1) | /* LINK/ACT */
  447. PHY_M_LEDC_INIT_CTRL(7) | /* 10 Mbps */
  448. PHY_M_LEDC_STA1_CTRL(7) | /* 100 Mbps */
  449. PHY_M_LEDC_STA0_CTRL(7))); /* 1000 Mbps */
  450. /* set Polarity Control register */
  451. gm_phy_write(hw, port, PHY_MARV_PHY_STAT,
  452. (PHY_M_POLC_LS1_P_MIX(4) |
  453. PHY_M_POLC_IS0_P_MIX(4) |
  454. PHY_M_POLC_LOS_CTRL(2) |
  455. PHY_M_POLC_INIT_CTRL(2) |
  456. PHY_M_POLC_STA1_CTRL(2) |
  457. PHY_M_POLC_STA0_CTRL(2)));
  458. /* restore page register */
  459. gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg);
  460. break;
  461. case CHIP_ID_YUKON_EC_U:
  462. case CHIP_ID_YUKON_EX:
  463. case CHIP_ID_YUKON_SUPR:
  464. pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR);
  465. /* select page 3 to access LED control register */
  466. gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 3);
  467. /* set LED Function Control register */
  468. gm_phy_write(hw, port, PHY_MARV_PHY_CTRL,
  469. (PHY_M_LEDC_LOS_CTRL(1) | /* LINK/ACT */
  470. PHY_M_LEDC_INIT_CTRL(8) | /* 10 Mbps */
  471. PHY_M_LEDC_STA1_CTRL(7) | /* 100 Mbps */
  472. PHY_M_LEDC_STA0_CTRL(7)));/* 1000 Mbps */
  473. /* set Blink Rate in LED Timer Control Register */
  474. gm_phy_write(hw, port, PHY_MARV_INT_MASK,
  475. ledctrl | PHY_M_LED_BLINK_RT(BLINK_84MS));
  476. /* restore page register */
  477. gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg);
  478. break;
  479. default:
  480. /* set Tx LED (LED_TX) to blink mode on Rx OR Tx activity */
  481. ledctrl |= PHY_M_LED_BLINK_RT(BLINK_84MS) | PHY_M_LEDC_TX_CTRL;
  482. /* turn off the Rx LED (LED_RX) */
  483. ledover |= PHY_M_LED_MO_RX(MO_LED_OFF);
  484. }
  485. if (hw->chip_id == CHIP_ID_YUKON_EC_U || hw->chip_id == CHIP_ID_YUKON_UL_2) {
  486. /* apply fixes in PHY AFE */
  487. gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 255);
  488. /* increase differential signal amplitude in 10BASE-T */
  489. gm_phy_write(hw, port, 0x18, 0xaa99);
  490. gm_phy_write(hw, port, 0x17, 0x2011);
  491. if (hw->chip_id == CHIP_ID_YUKON_EC_U) {
  492. /* fix for IEEE A/B Symmetry failure in 1000BASE-T */
  493. gm_phy_write(hw, port, 0x18, 0xa204);
  494. gm_phy_write(hw, port, 0x17, 0x2002);
  495. }
  496. /* set page register to 0 */
  497. gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 0);
  498. } else if (hw->chip_id == CHIP_ID_YUKON_FE_P &&
  499. hw->chip_rev == CHIP_REV_YU_FE2_A0) {
  500. /* apply workaround for integrated resistors calibration */
  501. gm_phy_write(hw, port, PHY_MARV_PAGE_ADDR, 17);
  502. gm_phy_write(hw, port, PHY_MARV_PAGE_DATA, 0x3f60);
  503. } else if (hw->chip_id == CHIP_ID_YUKON_OPT && hw->chip_rev == 0) {
  504. /* apply fixes in PHY AFE */
  505. gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 0x00ff);
  506. /* apply RDAC termination workaround */
  507. gm_phy_write(hw, port, 24, 0x2800);
  508. gm_phy_write(hw, port, 23, 0x2001);
  509. /* set page register back to 0 */
  510. gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 0);
  511. } else if (hw->chip_id != CHIP_ID_YUKON_EX &&
  512. hw->chip_id < CHIP_ID_YUKON_SUPR) {
  513. /* no effect on Yukon-XL */
  514. gm_phy_write(hw, port, PHY_MARV_LED_CTRL, ledctrl);
  515. if (!(sky2->flags & SKY2_FLAG_AUTO_SPEED) ||
  516. sky2->speed == SPEED_100) {
  517. /* turn on 100 Mbps LED (LED_LINK100) */
  518. ledover |= PHY_M_LED_MO_100(MO_LED_ON);
  519. }
  520. if (ledover)
  521. gm_phy_write(hw, port, PHY_MARV_LED_OVER, ledover);
  522. } else if (hw->chip_id == CHIP_ID_YUKON_PRM &&
  523. (sky2_read8(hw, B2_MAC_CFG) & 0xf) == 0x7) {
  524. int i;
  525. /* This a phy register setup workaround copied from vendor driver. */
  526. static const struct {
  527. u16 reg, val;
  528. } eee_afe[] = {
  529. { 0x156, 0x58ce },
  530. { 0x153, 0x99eb },
  531. { 0x141, 0x8064 },
  532. /* { 0x155, 0x130b },*/
  533. { 0x000, 0x0000 },
  534. { 0x151, 0x8433 },
  535. { 0x14b, 0x8c44 },
  536. { 0x14c, 0x0f90 },
  537. { 0x14f, 0x39aa },
  538. /* { 0x154, 0x2f39 },*/
  539. { 0x14d, 0xba33 },
  540. { 0x144, 0x0048 },
  541. { 0x152, 0x2010 },
  542. /* { 0x158, 0x1223 },*/
  543. { 0x140, 0x4444 },
  544. { 0x154, 0x2f3b },
  545. { 0x158, 0xb203 },
  546. { 0x157, 0x2029 },
  547. };
  548. /* Start Workaround for OptimaEEE Rev.Z0 */
  549. gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 0x00fb);
  550. gm_phy_write(hw, port, 1, 0x4099);
  551. gm_phy_write(hw, port, 3, 0x1120);
  552. gm_phy_write(hw, port, 11, 0x113c);
  553. gm_phy_write(hw, port, 14, 0x8100);
  554. gm_phy_write(hw, port, 15, 0x112a);
  555. gm_phy_write(hw, port, 17, 0x1008);
  556. gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 0x00fc);
  557. gm_phy_write(hw, port, 1, 0x20b0);
  558. gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 0x00ff);
  559. for (i = 0; i < ARRAY_SIZE(eee_afe); i++) {
  560. /* apply AFE settings */
  561. gm_phy_write(hw, port, 17, eee_afe[i].val);
  562. gm_phy_write(hw, port, 16, eee_afe[i].reg | 1u<<13);
  563. }
  564. /* End Workaround for OptimaEEE */
  565. gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 0);
  566. /* Enable 10Base-Te (EEE) */
  567. if (hw->chip_id >= CHIP_ID_YUKON_PRM) {
  568. reg = gm_phy_read(hw, port, PHY_MARV_EXT_CTRL);
  569. gm_phy_write(hw, port, PHY_MARV_EXT_CTRL,
  570. reg | PHY_M_10B_TE_ENABLE);
  571. }
  572. }
  573. /* Enable phy interrupt on auto-negotiation complete (or link up) */
  574. if (sky2->flags & SKY2_FLAG_AUTO_SPEED)
  575. gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_IS_AN_COMPL);
  576. else
  577. gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_DEF_MSK);
  578. }
  579. static const u32 phy_power[] = { PCI_Y2_PHY1_POWD, PCI_Y2_PHY2_POWD };
  580. static const u32 coma_mode[] = { PCI_Y2_PHY1_COMA, PCI_Y2_PHY2_COMA };
  581. static void sky2_phy_power_up(struct sky2_hw *hw, unsigned port)
  582. {
  583. u32 reg1;
  584. sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
  585. reg1 = sky2_pci_read32(hw, PCI_DEV_REG1);
  586. reg1 &= ~phy_power[port];
  587. if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > CHIP_REV_YU_XL_A1)
  588. reg1 |= coma_mode[port];
  589. sky2_pci_write32(hw, PCI_DEV_REG1, reg1);
  590. sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
  591. sky2_pci_read32(hw, PCI_DEV_REG1);
  592. if (hw->chip_id == CHIP_ID_YUKON_FE)
  593. gm_phy_write(hw, port, PHY_MARV_CTRL, PHY_CT_ANE);
  594. else if (hw->flags & SKY2_HW_ADV_POWER_CTL)
  595. sky2_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_CLR);
  596. }
  597. static void sky2_phy_power_down(struct sky2_hw *hw, unsigned port)
  598. {
  599. u32 reg1;
  600. u16 ctrl;
  601. /* release GPHY Control reset */
  602. sky2_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_CLR);
  603. /* release GMAC reset */
  604. sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_RST_CLR);
  605. if (hw->flags & SKY2_HW_NEWER_PHY) {
  606. /* select page 2 to access MAC control register */
  607. gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 2);
  608. ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL);
  609. /* allow GMII Power Down */
  610. ctrl &= ~PHY_M_MAC_GMIF_PUP;
  611. gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl);
  612. /* set page register back to 0 */
  613. gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 0);
  614. }
  615. /* setup General Purpose Control Register */
  616. gma_write16(hw, port, GM_GP_CTRL,
  617. GM_GPCR_FL_PASS | GM_GPCR_SPEED_100 |
  618. GM_GPCR_AU_DUP_DIS | GM_GPCR_AU_FCT_DIS |
  619. GM_GPCR_AU_SPD_DIS);
  620. if (hw->chip_id != CHIP_ID_YUKON_EC) {
  621. if (hw->chip_id == CHIP_ID_YUKON_EC_U) {
  622. /* select page 2 to access MAC control register */
  623. gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 2);
  624. ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL);
  625. /* enable Power Down */
  626. ctrl |= PHY_M_PC_POW_D_ENA;
  627. gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl);
  628. /* set page register back to 0 */
  629. gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 0);
  630. }
  631. /* set IEEE compatible Power Down Mode (dev. #4.99) */
  632. gm_phy_write(hw, port, PHY_MARV_CTRL, PHY_CT_PDOWN);
  633. }
  634. sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
  635. reg1 = sky2_pci_read32(hw, PCI_DEV_REG1);
  636. reg1 |= phy_power[port]; /* set PHY to PowerDown/COMA Mode */
  637. sky2_pci_write32(hw, PCI_DEV_REG1, reg1);
  638. sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
  639. }
  640. /* configure IPG according to used link speed */
  641. static void sky2_set_ipg(struct sky2_port *sky2)
  642. {
  643. u16 reg;
  644. reg = gma_read16(sky2->hw, sky2->port, GM_SERIAL_MODE);
  645. reg &= ~GM_SMOD_IPG_MSK;
  646. if (sky2->speed > SPEED_100)
  647. reg |= IPG_DATA_VAL(IPG_DATA_DEF_1000);
  648. else
  649. reg |= IPG_DATA_VAL(IPG_DATA_DEF_10_100);
  650. gma_write16(sky2->hw, sky2->port, GM_SERIAL_MODE, reg);
  651. }
  652. /* Enable Rx/Tx */
  653. static void sky2_enable_rx_tx(struct sky2_port *sky2)
  654. {
  655. struct sky2_hw *hw = sky2->hw;
  656. unsigned port = sky2->port;
  657. u16 reg;
  658. reg = gma_read16(hw, port, GM_GP_CTRL);
  659. reg |= GM_GPCR_RX_ENA | GM_GPCR_TX_ENA;
  660. gma_write16(hw, port, GM_GP_CTRL, reg);
  661. }
  662. /* Force a renegotiation */
  663. static void sky2_phy_reinit(struct sky2_port *sky2)
  664. {
  665. spin_lock_bh(&sky2->phy_lock);
  666. sky2_phy_init(sky2->hw, sky2->port);
  667. sky2_enable_rx_tx(sky2);
  668. spin_unlock_bh(&sky2->phy_lock);
  669. }
  670. /* Put device in state to listen for Wake On Lan */
  671. static void sky2_wol_init(struct sky2_port *sky2)
  672. {
  673. struct sky2_hw *hw = sky2->hw;
  674. unsigned port = sky2->port;
  675. enum flow_control save_mode;
  676. u16 ctrl;
  677. /* Bring hardware out of reset */
  678. sky2_write16(hw, B0_CTST, CS_RST_CLR);
  679. sky2_write16(hw, SK_REG(port, GMAC_LINK_CTRL), GMLC_RST_CLR);
  680. sky2_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_CLR);
  681. sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_RST_CLR);
  682. /* Force to 10/100
  683. * sky2_reset will re-enable on resume
  684. */
  685. save_mode = sky2->flow_mode;
  686. ctrl = sky2->advertising;
  687. sky2->advertising &= ~(ADVERTISED_1000baseT_Half|ADVERTISED_1000baseT_Full);
  688. sky2->flow_mode = FC_NONE;
  689. spin_lock_bh(&sky2->phy_lock);
  690. sky2_phy_power_up(hw, port);
  691. sky2_phy_init(hw, port);
  692. spin_unlock_bh(&sky2->phy_lock);
  693. sky2->flow_mode = save_mode;
  694. sky2->advertising = ctrl;
  695. /* Set GMAC to no flow control and auto update for speed/duplex */
  696. gma_write16(hw, port, GM_GP_CTRL,
  697. GM_GPCR_FC_TX_DIS|GM_GPCR_TX_ENA|GM_GPCR_RX_ENA|
  698. GM_GPCR_DUP_FULL|GM_GPCR_FC_RX_DIS|GM_GPCR_AU_FCT_DIS);
  699. /* Set WOL address */
  700. memcpy_toio(hw->regs + WOL_REGS(port, WOL_MAC_ADDR),
  701. sky2->netdev->dev_addr, ETH_ALEN);
  702. /* Turn on appropriate WOL control bits */
  703. sky2_write16(hw, WOL_REGS(port, WOL_CTRL_STAT), WOL_CTL_CLEAR_RESULT);
  704. ctrl = 0;
  705. if (sky2->wol & WAKE_PHY)
  706. ctrl |= WOL_CTL_ENA_PME_ON_LINK_CHG|WOL_CTL_ENA_LINK_CHG_UNIT;
  707. else
  708. ctrl |= WOL_CTL_DIS_PME_ON_LINK_CHG|WOL_CTL_DIS_LINK_CHG_UNIT;
  709. if (sky2->wol & WAKE_MAGIC)
  710. ctrl |= WOL_CTL_ENA_PME_ON_MAGIC_PKT|WOL_CTL_ENA_MAGIC_PKT_UNIT;
  711. else
  712. ctrl |= WOL_CTL_DIS_PME_ON_MAGIC_PKT|WOL_CTL_DIS_MAGIC_PKT_UNIT;
  713. ctrl |= WOL_CTL_DIS_PME_ON_PATTERN|WOL_CTL_DIS_PATTERN_UNIT;
  714. sky2_write16(hw, WOL_REGS(port, WOL_CTRL_STAT), ctrl);
  715. /* Disable PiG firmware */
  716. sky2_write16(hw, B0_CTST, Y2_HW_WOL_OFF);
  717. /* Needed by some broken BIOSes, use PCI rather than PCI-e for WOL */
  718. if (legacy_pme) {
  719. u32 reg1 = sky2_pci_read32(hw, PCI_DEV_REG1);
  720. reg1 |= PCI_Y2_PME_LEGACY;
  721. sky2_pci_write32(hw, PCI_DEV_REG1, reg1);
  722. }
  723. /* block receiver */
  724. sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET);
  725. sky2_read32(hw, B0_CTST);
  726. }
  727. static void sky2_set_tx_stfwd(struct sky2_hw *hw, unsigned port)
  728. {
  729. struct net_device *dev = hw->dev[port];
  730. if ( (hw->chip_id == CHIP_ID_YUKON_EX &&
  731. hw->chip_rev != CHIP_REV_YU_EX_A0) ||
  732. hw->chip_id >= CHIP_ID_YUKON_FE_P) {
  733. /* Yukon-Extreme B0 and further Extreme devices */
  734. sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), TX_STFW_ENA);
  735. } else if (dev->mtu > ETH_DATA_LEN) {
  736. /* set Tx GMAC FIFO Almost Empty Threshold */
  737. sky2_write32(hw, SK_REG(port, TX_GMF_AE_THR),
  738. (ECU_JUMBO_WM << 16) | ECU_AE_THR);
  739. sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), TX_STFW_DIS);
  740. } else
  741. sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), TX_STFW_ENA);
  742. }
  743. static void sky2_mac_init(struct sky2_hw *hw, unsigned port)
  744. {
  745. struct sky2_port *sky2 = netdev_priv(hw->dev[port]);
  746. u16 reg;
  747. u32 rx_reg;
  748. int i;
  749. const u8 *addr = hw->dev[port]->dev_addr;
  750. sky2_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_SET);
  751. sky2_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_CLR);
  752. sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_RST_CLR);
  753. if (hw->chip_id == CHIP_ID_YUKON_XL &&
  754. hw->chip_rev == CHIP_REV_YU_XL_A0 &&
  755. port == 1) {
  756. /* WA DEV_472 -- looks like crossed wires on port 2 */
  757. /* clear GMAC 1 Control reset */
  758. sky2_write8(hw, SK_REG(0, GMAC_CTRL), GMC_RST_CLR);
  759. do {
  760. sky2_write8(hw, SK_REG(1, GMAC_CTRL), GMC_RST_SET);
  761. sky2_write8(hw, SK_REG(1, GMAC_CTRL), GMC_RST_CLR);
  762. } while (gm_phy_read(hw, 1, PHY_MARV_ID0) != PHY_MARV_ID0_VAL ||
  763. gm_phy_read(hw, 1, PHY_MARV_ID1) != PHY_MARV_ID1_Y2 ||
  764. gm_phy_read(hw, 1, PHY_MARV_INT_MASK) != 0);
  765. }
  766. sky2_read16(hw, SK_REG(port, GMAC_IRQ_SRC));
  767. /* Enable Transmit FIFO Underrun */
  768. sky2_write8(hw, SK_REG(port, GMAC_IRQ_MSK), GMAC_DEF_MSK);
  769. spin_lock_bh(&sky2->phy_lock);
  770. sky2_phy_power_up(hw, port);
  771. sky2_phy_init(hw, port);
  772. spin_unlock_bh(&sky2->phy_lock);
  773. /* MIB clear */
  774. reg = gma_read16(hw, port, GM_PHY_ADDR);
  775. gma_write16(hw, port, GM_PHY_ADDR, reg | GM_PAR_MIB_CLR);
  776. for (i = GM_MIB_CNT_BASE; i <= GM_MIB_CNT_END; i += 4)
  777. gma_read16(hw, port, i);
  778. gma_write16(hw, port, GM_PHY_ADDR, reg);
  779. /* transmit control */
  780. gma_write16(hw, port, GM_TX_CTRL, TX_COL_THR(TX_COL_DEF));
  781. /* receive control reg: unicast + multicast + no FCS */
  782. gma_write16(hw, port, GM_RX_CTRL,
  783. GM_RXCR_UCF_ENA | GM_RXCR_CRC_DIS | GM_RXCR_MCF_ENA);
  784. /* transmit flow control */
  785. gma_write16(hw, port, GM_TX_FLOW_CTRL, 0xffff);
  786. /* transmit parameter */
  787. gma_write16(hw, port, GM_TX_PARAM,
  788. TX_JAM_LEN_VAL(TX_JAM_LEN_DEF) |
  789. TX_JAM_IPG_VAL(TX_JAM_IPG_DEF) |
  790. TX_IPG_JAM_DATA(TX_IPG_JAM_DEF) |
  791. TX_BACK_OFF_LIM(TX_BOF_LIM_DEF));
  792. /* serial mode register */
  793. reg = DATA_BLIND_VAL(DATA_BLIND_DEF) |
  794. GM_SMOD_VLAN_ENA | IPG_DATA_VAL(IPG_DATA_DEF_1000);
  795. if (hw->dev[port]->mtu > ETH_DATA_LEN)
  796. reg |= GM_SMOD_JUMBO_ENA;
  797. if (hw->chip_id == CHIP_ID_YUKON_EC_U &&
  798. hw->chip_rev == CHIP_REV_YU_EC_U_B1)
  799. reg |= GM_NEW_FLOW_CTRL;
  800. gma_write16(hw, port, GM_SERIAL_MODE, reg);
  801. /* virtual address for data */
  802. gma_set_addr(hw, port, GM_SRC_ADDR_2L, addr);
  803. /* physical address: used for pause frames */
  804. gma_set_addr(hw, port, GM_SRC_ADDR_1L, addr);
  805. /* ignore counter overflows */
  806. gma_write16(hw, port, GM_TX_IRQ_MSK, 0);
  807. gma_write16(hw, port, GM_RX_IRQ_MSK, 0);
  808. gma_write16(hw, port, GM_TR_IRQ_MSK, 0);
  809. /* Configure Rx MAC FIFO */
  810. sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_CLR);
  811. rx_reg = GMF_OPER_ON | GMF_RX_F_FL_ON;
  812. if (hw->chip_id == CHIP_ID_YUKON_EX ||
  813. hw->chip_id == CHIP_ID_YUKON_FE_P)
  814. rx_reg |= GMF_RX_OVER_ON;
  815. sky2_write32(hw, SK_REG(port, RX_GMF_CTRL_T), rx_reg);
  816. if (hw->chip_id == CHIP_ID_YUKON_XL) {
  817. /* Hardware errata - clear flush mask */
  818. sky2_write16(hw, SK_REG(port, RX_GMF_FL_MSK), 0);
  819. } else {
  820. /* Flush Rx MAC FIFO on any flow control or error */
  821. sky2_write16(hw, SK_REG(port, RX_GMF_FL_MSK), GMR_FS_ANY_ERR);
  822. }
  823. /* Set threshold to 0xa (64 bytes) + 1 to workaround pause bug */
  824. reg = RX_GMF_FL_THR_DEF + 1;
  825. /* Another magic mystery workaround from sk98lin */
  826. if (hw->chip_id == CHIP_ID_YUKON_FE_P &&
  827. hw->chip_rev == CHIP_REV_YU_FE2_A0)
  828. reg = 0x178;
  829. sky2_write16(hw, SK_REG(port, RX_GMF_FL_THR), reg);
  830. /* Configure Tx MAC FIFO */
  831. sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_CLR);
  832. sky2_write16(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_OPER_ON);
  833. /* On chips without ram buffer, pause is controlled by MAC level */
  834. if (!(hw->flags & SKY2_HW_RAM_BUFFER)) {
  835. /* Pause threshold is scaled by 8 in bytes */
  836. if (hw->chip_id == CHIP_ID_YUKON_FE_P &&
  837. hw->chip_rev == CHIP_REV_YU_FE2_A0)
  838. reg = 1568 / 8;
  839. else
  840. reg = 1024 / 8;
  841. sky2_write16(hw, SK_REG(port, RX_GMF_UP_THR), reg);
  842. sky2_write16(hw, SK_REG(port, RX_GMF_LP_THR), 768 / 8);
  843. sky2_set_tx_stfwd(hw, port);
  844. }
  845. if (hw->chip_id == CHIP_ID_YUKON_FE_P &&
  846. hw->chip_rev == CHIP_REV_YU_FE2_A0) {
  847. /* disable dynamic watermark */
  848. reg = sky2_read16(hw, SK_REG(port, TX_GMF_EA));
  849. reg &= ~TX_DYN_WM_ENA;
  850. sky2_write16(hw, SK_REG(port, TX_GMF_EA), reg);
  851. }
  852. }
  853. /* Assign Ram Buffer allocation to queue */
  854. static void sky2_ramset(struct sky2_hw *hw, u16 q, u32 start, u32 space)
  855. {
  856. u32 end;
  857. /* convert from K bytes to qwords used for hw register */
  858. start *= 1024/8;
  859. space *= 1024/8;
  860. end = start + space - 1;
  861. sky2_write8(hw, RB_ADDR(q, RB_CTRL), RB_RST_CLR);
  862. sky2_write32(hw, RB_ADDR(q, RB_START), start);
  863. sky2_write32(hw, RB_ADDR(q, RB_END), end);
  864. sky2_write32(hw, RB_ADDR(q, RB_WP), start);
  865. sky2_write32(hw, RB_ADDR(q, RB_RP), start);
  866. if (q == Q_R1 || q == Q_R2) {
  867. u32 tp = space - space/4;
  868. /* On receive queue's set the thresholds
  869. * give receiver priority when > 3/4 full
  870. * send pause when down to 2K
  871. */
  872. sky2_write32(hw, RB_ADDR(q, RB_RX_UTHP), tp);
  873. sky2_write32(hw, RB_ADDR(q, RB_RX_LTHP), space/2);
  874. tp = space - 8192/8;
  875. sky2_write32(hw, RB_ADDR(q, RB_RX_UTPP), tp);
  876. sky2_write32(hw, RB_ADDR(q, RB_RX_LTPP), space/4);
  877. } else {
  878. /* Enable store & forward on Tx queue's because
  879. * Tx FIFO is only 1K on Yukon
  880. */
  881. sky2_write8(hw, RB_ADDR(q, RB_CTRL), RB_ENA_STFWD);
  882. }
  883. sky2_write8(hw, RB_ADDR(q, RB_CTRL), RB_ENA_OP_MD);
  884. sky2_read8(hw, RB_ADDR(q, RB_CTRL));
  885. }
  886. /* Setup Bus Memory Interface */
  887. static void sky2_qset(struct sky2_hw *hw, u16 q)
  888. {
  889. sky2_write32(hw, Q_ADDR(q, Q_CSR), BMU_CLR_RESET);
  890. sky2_write32(hw, Q_ADDR(q, Q_CSR), BMU_OPER_INIT);
  891. sky2_write32(hw, Q_ADDR(q, Q_CSR), BMU_FIFO_OP_ON);
  892. sky2_write32(hw, Q_ADDR(q, Q_WM), BMU_WM_DEFAULT);
  893. }
  894. /* Setup prefetch unit registers. This is the interface between
  895. * hardware and driver list elements
  896. */
  897. static void sky2_prefetch_init(struct sky2_hw *hw, u32 qaddr,
  898. dma_addr_t addr, u32 last)
  899. {
  900. sky2_write32(hw, Y2_QADDR(qaddr, PREF_UNIT_CTRL), PREF_UNIT_RST_SET);
  901. sky2_write32(hw, Y2_QADDR(qaddr, PREF_UNIT_CTRL), PREF_UNIT_RST_CLR);
  902. sky2_write32(hw, Y2_QADDR(qaddr, PREF_UNIT_ADDR_HI), upper_32_bits(addr));
  903. sky2_write32(hw, Y2_QADDR(qaddr, PREF_UNIT_ADDR_LO), lower_32_bits(addr));
  904. sky2_write16(hw, Y2_QADDR(qaddr, PREF_UNIT_LAST_IDX), last);
  905. sky2_write32(hw, Y2_QADDR(qaddr, PREF_UNIT_CTRL), PREF_UNIT_OP_ON);
  906. sky2_read32(hw, Y2_QADDR(qaddr, PREF_UNIT_CTRL));
  907. }
  908. static inline struct sky2_tx_le *get_tx_le(struct sky2_port *sky2, u16 *slot)
  909. {
  910. struct sky2_tx_le *le = sky2->tx_le + *slot;
  911. *slot = RING_NEXT(*slot, sky2->tx_ring_size);
  912. le->ctrl = 0;
  913. return le;
  914. }
  915. static void tx_init(struct sky2_port *sky2)
  916. {
  917. struct sky2_tx_le *le;
  918. sky2->tx_prod = sky2->tx_cons = 0;
  919. sky2->tx_tcpsum = 0;
  920. sky2->tx_last_mss = 0;
  921. netdev_reset_queue(sky2->netdev);
  922. le = get_tx_le(sky2, &sky2->tx_prod);
  923. le->addr = 0;
  924. le->opcode = OP_ADDR64 | HW_OWNER;
  925. sky2->tx_last_upper = 0;
  926. }
  927. /* Update chip's next pointer */
  928. static inline void sky2_put_idx(struct sky2_hw *hw, unsigned q, u16 idx)
  929. {
  930. /* Make sure write' to descriptors are complete before we tell hardware */
  931. wmb();
  932. sky2_write16(hw, Y2_QADDR(q, PREF_UNIT_PUT_IDX), idx);
  933. /* Synchronize I/O on since next processor may write to tail */
  934. mmiowb();
  935. }
  936. static inline struct sky2_rx_le *sky2_next_rx(struct sky2_port *sky2)
  937. {
  938. struct sky2_rx_le *le = sky2->rx_le + sky2->rx_put;
  939. sky2->rx_put = RING_NEXT(sky2->rx_put, RX_LE_SIZE);
  940. le->ctrl = 0;
  941. return le;
  942. }
  943. static unsigned sky2_get_rx_threshold(struct sky2_port *sky2)
  944. {
  945. unsigned size;
  946. /* Space needed for frame data + headers rounded up */
  947. size = roundup(sky2->netdev->mtu + ETH_HLEN + VLAN_HLEN, 8);
  948. /* Stopping point for hardware truncation */
  949. return (size - 8) / sizeof(u32);
  950. }
  951. static unsigned sky2_get_rx_data_size(struct sky2_port *sky2)
  952. {
  953. struct rx_ring_info *re;
  954. unsigned size;
  955. /* Space needed for frame data + headers rounded up */
  956. size = roundup(sky2->netdev->mtu + ETH_HLEN + VLAN_HLEN, 8);
  957. sky2->rx_nfrags = size >> PAGE_SHIFT;
  958. BUG_ON(sky2->rx_nfrags > ARRAY_SIZE(re->frag_addr));
  959. /* Compute residue after pages */
  960. size -= sky2->rx_nfrags << PAGE_SHIFT;
  961. /* Optimize to handle small packets and headers */
  962. if (size < copybreak)
  963. size = copybreak;
  964. if (size < ETH_HLEN)
  965. size = ETH_HLEN;
  966. return size;
  967. }
  968. /* Build description to hardware for one receive segment */
  969. static void sky2_rx_add(struct sky2_port *sky2, u8 op,
  970. dma_addr_t map, unsigned len)
  971. {
  972. struct sky2_rx_le *le;
  973. if (sizeof(dma_addr_t) > sizeof(u32)) {
  974. le = sky2_next_rx(sky2);
  975. le->addr = cpu_to_le32(upper_32_bits(map));
  976. le->opcode = OP_ADDR64 | HW_OWNER;
  977. }
  978. le = sky2_next_rx(sky2);
  979. le->addr = cpu_to_le32(lower_32_bits(map));
  980. le->length = cpu_to_le16(len);
  981. le->opcode = op | HW_OWNER;
  982. }
  983. /* Build description to hardware for one possibly fragmented skb */
  984. static void sky2_rx_submit(struct sky2_port *sky2,
  985. const struct rx_ring_info *re)
  986. {
  987. int i;
  988. sky2_rx_add(sky2, OP_PACKET, re->data_addr, sky2->rx_data_size);
  989. for (i = 0; i < skb_shinfo(re->skb)->nr_frags; i++)
  990. sky2_rx_add(sky2, OP_BUFFER, re->frag_addr[i], PAGE_SIZE);
  991. }
  992. static int sky2_rx_map_skb(struct pci_dev *pdev, struct rx_ring_info *re,
  993. unsigned size)
  994. {
  995. struct sk_buff *skb = re->skb;
  996. int i;
  997. re->data_addr = pci_map_single(pdev, skb->data, size, PCI_DMA_FROMDEVICE);
  998. if (pci_dma_mapping_error(pdev, re->data_addr))
  999. goto mapping_error;
  1000. dma_unmap_len_set(re, data_size, size);
  1001. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  1002. const skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  1003. re->frag_addr[i] = skb_frag_dma_map(&pdev->dev, frag, 0,
  1004. skb_frag_size(frag),
  1005. DMA_FROM_DEVICE);
  1006. if (dma_mapping_error(&pdev->dev, re->frag_addr[i]))
  1007. goto map_page_error;
  1008. }
  1009. return 0;
  1010. map_page_error:
  1011. while (--i >= 0) {
  1012. pci_unmap_page(pdev, re->frag_addr[i],
  1013. skb_frag_size(&skb_shinfo(skb)->frags[i]),
  1014. PCI_DMA_FROMDEVICE);
  1015. }
  1016. pci_unmap_single(pdev, re->data_addr, dma_unmap_len(re, data_size),
  1017. PCI_DMA_FROMDEVICE);
  1018. mapping_error:
  1019. if (net_ratelimit())
  1020. dev_warn(&pdev->dev, "%s: rx mapping error\n",
  1021. skb->dev->name);
  1022. return -EIO;
  1023. }
  1024. static void sky2_rx_unmap_skb(struct pci_dev *pdev, struct rx_ring_info *re)
  1025. {
  1026. struct sk_buff *skb = re->skb;
  1027. int i;
  1028. pci_unmap_single(pdev, re->data_addr, dma_unmap_len(re, data_size),
  1029. PCI_DMA_FROMDEVICE);
  1030. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
  1031. pci_unmap_page(pdev, re->frag_addr[i],
  1032. skb_frag_size(&skb_shinfo(skb)->frags[i]),
  1033. PCI_DMA_FROMDEVICE);
  1034. }
  1035. /* Tell chip where to start receive checksum.
  1036. * Actually has two checksums, but set both same to avoid possible byte
  1037. * order problems.
  1038. */
  1039. static void rx_set_checksum(struct sky2_port *sky2)
  1040. {
  1041. struct sky2_rx_le *le = sky2_next_rx(sky2);
  1042. le->addr = cpu_to_le32((ETH_HLEN << 16) | ETH_HLEN);
  1043. le->ctrl = 0;
  1044. le->opcode = OP_TCPSTART | HW_OWNER;
  1045. sky2_write32(sky2->hw,
  1046. Q_ADDR(rxqaddr[sky2->port], Q_CSR),
  1047. (sky2->netdev->features & NETIF_F_RXCSUM)
  1048. ? BMU_ENA_RX_CHKSUM : BMU_DIS_RX_CHKSUM);
  1049. }
  1050. /* Enable/disable receive hash calculation (RSS) */
  1051. static void rx_set_rss(struct net_device *dev, netdev_features_t features)
  1052. {
  1053. struct sky2_port *sky2 = netdev_priv(dev);
  1054. struct sky2_hw *hw = sky2->hw;
  1055. int i, nkeys = 4;
  1056. /* Supports IPv6 and other modes */
  1057. if (hw->flags & SKY2_HW_NEW_LE) {
  1058. nkeys = 10;
  1059. sky2_write32(hw, SK_REG(sky2->port, RSS_CFG), HASH_ALL);
  1060. }
  1061. /* Program RSS initial values */
  1062. if (features & NETIF_F_RXHASH) {
  1063. u32 rss_key[10];
  1064. netdev_rss_key_fill(rss_key, sizeof(rss_key));
  1065. for (i = 0; i < nkeys; i++)
  1066. sky2_write32(hw, SK_REG(sky2->port, RSS_KEY + i * 4),
  1067. rss_key[i]);
  1068. /* Need to turn on (undocumented) flag to make hashing work */
  1069. sky2_write32(hw, SK_REG(sky2->port, RX_GMF_CTRL_T),
  1070. RX_STFW_ENA);
  1071. sky2_write32(hw, Q_ADDR(rxqaddr[sky2->port], Q_CSR),
  1072. BMU_ENA_RX_RSS_HASH);
  1073. } else
  1074. sky2_write32(hw, Q_ADDR(rxqaddr[sky2->port], Q_CSR),
  1075. BMU_DIS_RX_RSS_HASH);
  1076. }
  1077. /*
  1078. * The RX Stop command will not work for Yukon-2 if the BMU does not
  1079. * reach the end of packet and since we can't make sure that we have
  1080. * incoming data, we must reset the BMU while it is not doing a DMA
  1081. * transfer. Since it is possible that the RX path is still active,
  1082. * the RX RAM buffer will be stopped first, so any possible incoming
  1083. * data will not trigger a DMA. After the RAM buffer is stopped, the
  1084. * BMU is polled until any DMA in progress is ended and only then it
  1085. * will be reset.
  1086. */
  1087. static void sky2_rx_stop(struct sky2_port *sky2)
  1088. {
  1089. struct sky2_hw *hw = sky2->hw;
  1090. unsigned rxq = rxqaddr[sky2->port];
  1091. int i;
  1092. /* disable the RAM Buffer receive queue */
  1093. sky2_write8(hw, RB_ADDR(rxq, RB_CTRL), RB_DIS_OP_MD);
  1094. for (i = 0; i < 0xffff; i++)
  1095. if (sky2_read8(hw, RB_ADDR(rxq, Q_RSL))
  1096. == sky2_read8(hw, RB_ADDR(rxq, Q_RL)))
  1097. goto stopped;
  1098. netdev_warn(sky2->netdev, "receiver stop failed\n");
  1099. stopped:
  1100. sky2_write32(hw, Q_ADDR(rxq, Q_CSR), BMU_RST_SET | BMU_FIFO_RST);
  1101. /* reset the Rx prefetch unit */
  1102. sky2_write32(hw, Y2_QADDR(rxq, PREF_UNIT_CTRL), PREF_UNIT_RST_SET);
  1103. mmiowb();
  1104. }
  1105. /* Clean out receive buffer area, assumes receiver hardware stopped */
  1106. static void sky2_rx_clean(struct sky2_port *sky2)
  1107. {
  1108. unsigned i;
  1109. if (sky2->rx_le)
  1110. memset(sky2->rx_le, 0, RX_LE_BYTES);
  1111. for (i = 0; i < sky2->rx_pending; i++) {
  1112. struct rx_ring_info *re = sky2->rx_ring + i;
  1113. if (re->skb) {
  1114. sky2_rx_unmap_skb(sky2->hw->pdev, re);
  1115. kfree_skb(re->skb);
  1116. re->skb = NULL;
  1117. }
  1118. }
  1119. }
  1120. /* Basic MII support */
  1121. static int sky2_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  1122. {
  1123. struct mii_ioctl_data *data = if_mii(ifr);
  1124. struct sky2_port *sky2 = netdev_priv(dev);
  1125. struct sky2_hw *hw = sky2->hw;
  1126. int err = -EOPNOTSUPP;
  1127. if (!netif_running(dev))
  1128. return -ENODEV; /* Phy still in reset */
  1129. switch (cmd) {
  1130. case SIOCGMIIPHY:
  1131. data->phy_id = PHY_ADDR_MARV;
  1132. /* fallthru */
  1133. case SIOCGMIIREG: {
  1134. u16 val = 0;
  1135. spin_lock_bh(&sky2->phy_lock);
  1136. err = __gm_phy_read(hw, sky2->port, data->reg_num & 0x1f, &val);
  1137. spin_unlock_bh(&sky2->phy_lock);
  1138. data->val_out = val;
  1139. break;
  1140. }
  1141. case SIOCSMIIREG:
  1142. spin_lock_bh(&sky2->phy_lock);
  1143. err = gm_phy_write(hw, sky2->port, data->reg_num & 0x1f,
  1144. data->val_in);
  1145. spin_unlock_bh(&sky2->phy_lock);
  1146. break;
  1147. }
  1148. return err;
  1149. }
  1150. #define SKY2_VLAN_OFFLOADS (NETIF_F_IP_CSUM | NETIF_F_SG | NETIF_F_TSO)
  1151. static void sky2_vlan_mode(struct net_device *dev, netdev_features_t features)
  1152. {
  1153. struct sky2_port *sky2 = netdev_priv(dev);
  1154. struct sky2_hw *hw = sky2->hw;
  1155. u16 port = sky2->port;
  1156. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  1157. sky2_write32(hw, SK_REG(port, RX_GMF_CTRL_T),
  1158. RX_VLAN_STRIP_ON);
  1159. else
  1160. sky2_write32(hw, SK_REG(port, RX_GMF_CTRL_T),
  1161. RX_VLAN_STRIP_OFF);
  1162. if (features & NETIF_F_HW_VLAN_CTAG_TX) {
  1163. sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T),
  1164. TX_VLAN_TAG_ON);
  1165. dev->vlan_features |= SKY2_VLAN_OFFLOADS;
  1166. } else {
  1167. sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T),
  1168. TX_VLAN_TAG_OFF);
  1169. /* Can't do transmit offload of vlan without hw vlan */
  1170. dev->vlan_features &= ~SKY2_VLAN_OFFLOADS;
  1171. }
  1172. }
  1173. /* Amount of required worst case padding in rx buffer */
  1174. static inline unsigned sky2_rx_pad(const struct sky2_hw *hw)
  1175. {
  1176. return (hw->flags & SKY2_HW_RAM_BUFFER) ? 8 : 2;
  1177. }
  1178. /*
  1179. * Allocate an skb for receiving. If the MTU is large enough
  1180. * make the skb non-linear with a fragment list of pages.
  1181. */
  1182. static struct sk_buff *sky2_rx_alloc(struct sky2_port *sky2, gfp_t gfp)
  1183. {
  1184. struct sk_buff *skb;
  1185. int i;
  1186. skb = __netdev_alloc_skb(sky2->netdev,
  1187. sky2->rx_data_size + sky2_rx_pad(sky2->hw),
  1188. gfp);
  1189. if (!skb)
  1190. goto nomem;
  1191. if (sky2->hw->flags & SKY2_HW_RAM_BUFFER) {
  1192. unsigned char *start;
  1193. /*
  1194. * Workaround for a bug in FIFO that cause hang
  1195. * if the FIFO if the receive buffer is not 64 byte aligned.
  1196. * The buffer returned from netdev_alloc_skb is
  1197. * aligned except if slab debugging is enabled.
  1198. */
  1199. start = PTR_ALIGN(skb->data, 8);
  1200. skb_reserve(skb, start - skb->data);
  1201. } else
  1202. skb_reserve(skb, NET_IP_ALIGN);
  1203. for (i = 0; i < sky2->rx_nfrags; i++) {
  1204. struct page *page = alloc_page(gfp);
  1205. if (!page)
  1206. goto free_partial;
  1207. skb_fill_page_desc(skb, i, page, 0, PAGE_SIZE);
  1208. }
  1209. return skb;
  1210. free_partial:
  1211. kfree_skb(skb);
  1212. nomem:
  1213. return NULL;
  1214. }
  1215. static inline void sky2_rx_update(struct sky2_port *sky2, unsigned rxq)
  1216. {
  1217. sky2_put_idx(sky2->hw, rxq, sky2->rx_put);
  1218. }
  1219. static int sky2_alloc_rx_skbs(struct sky2_port *sky2)
  1220. {
  1221. struct sky2_hw *hw = sky2->hw;
  1222. unsigned i;
  1223. sky2->rx_data_size = sky2_get_rx_data_size(sky2);
  1224. /* Fill Rx ring */
  1225. for (i = 0; i < sky2->rx_pending; i++) {
  1226. struct rx_ring_info *re = sky2->rx_ring + i;
  1227. re->skb = sky2_rx_alloc(sky2, GFP_KERNEL);
  1228. if (!re->skb)
  1229. return -ENOMEM;
  1230. if (sky2_rx_map_skb(hw->pdev, re, sky2->rx_data_size)) {
  1231. dev_kfree_skb(re->skb);
  1232. re->skb = NULL;
  1233. return -ENOMEM;
  1234. }
  1235. }
  1236. return 0;
  1237. }
  1238. /*
  1239. * Setup receiver buffer pool.
  1240. * Normal case this ends up creating one list element for skb
  1241. * in the receive ring. Worst case if using large MTU and each
  1242. * allocation falls on a different 64 bit region, that results
  1243. * in 6 list elements per ring entry.
  1244. * One element is used for checksum enable/disable, and one
  1245. * extra to avoid wrap.
  1246. */
  1247. static void sky2_rx_start(struct sky2_port *sky2)
  1248. {
  1249. struct sky2_hw *hw = sky2->hw;
  1250. struct rx_ring_info *re;
  1251. unsigned rxq = rxqaddr[sky2->port];
  1252. unsigned i, thresh;
  1253. sky2->rx_put = sky2->rx_next = 0;
  1254. sky2_qset(hw, rxq);
  1255. /* On PCI express lowering the watermark gives better performance */
  1256. if (pci_is_pcie(hw->pdev))
  1257. sky2_write32(hw, Q_ADDR(rxq, Q_WM), BMU_WM_PEX);
  1258. /* These chips have no ram buffer?
  1259. * MAC Rx RAM Read is controlled by hardware */
  1260. if (hw->chip_id == CHIP_ID_YUKON_EC_U &&
  1261. hw->chip_rev > CHIP_REV_YU_EC_U_A0)
  1262. sky2_write32(hw, Q_ADDR(rxq, Q_TEST), F_M_RX_RAM_DIS);
  1263. sky2_prefetch_init(hw, rxq, sky2->rx_le_map, RX_LE_SIZE - 1);
  1264. if (!(hw->flags & SKY2_HW_NEW_LE))
  1265. rx_set_checksum(sky2);
  1266. if (!(hw->flags & SKY2_HW_RSS_BROKEN))
  1267. rx_set_rss(sky2->netdev, sky2->netdev->features);
  1268. /* submit Rx ring */
  1269. for (i = 0; i < sky2->rx_pending; i++) {
  1270. re = sky2->rx_ring + i;
  1271. sky2_rx_submit(sky2, re);
  1272. }
  1273. /*
  1274. * The receiver hangs if it receives frames larger than the
  1275. * packet buffer. As a workaround, truncate oversize frames, but
  1276. * the register is limited to 9 bits, so if you do frames > 2052
  1277. * you better get the MTU right!
  1278. */
  1279. thresh = sky2_get_rx_threshold(sky2);
  1280. if (thresh > 0x1ff)
  1281. sky2_write32(hw, SK_REG(sky2->port, RX_GMF_CTRL_T), RX_TRUNC_OFF);
  1282. else {
  1283. sky2_write16(hw, SK_REG(sky2->port, RX_GMF_TR_THR), thresh);
  1284. sky2_write32(hw, SK_REG(sky2->port, RX_GMF_CTRL_T), RX_TRUNC_ON);
  1285. }
  1286. /* Tell chip about available buffers */
  1287. sky2_rx_update(sky2, rxq);
  1288. if (hw->chip_id == CHIP_ID_YUKON_EX ||
  1289. hw->chip_id == CHIP_ID_YUKON_SUPR) {
  1290. /*
  1291. * Disable flushing of non ASF packets;
  1292. * must be done after initializing the BMUs;
  1293. * drivers without ASF support should do this too, otherwise
  1294. * it may happen that they cannot run on ASF devices;
  1295. * remember that the MAC FIFO isn't reset during initialization.
  1296. */
  1297. sky2_write32(hw, SK_REG(sky2->port, RX_GMF_CTRL_T), RX_MACSEC_FLUSH_OFF);
  1298. }
  1299. if (hw->chip_id >= CHIP_ID_YUKON_SUPR) {
  1300. /* Enable RX Home Address & Routing Header checksum fix */
  1301. sky2_write16(hw, SK_REG(sky2->port, RX_GMF_FL_CTRL),
  1302. RX_IPV6_SA_MOB_ENA | RX_IPV6_DA_MOB_ENA);
  1303. /* Enable TX Home Address & Routing Header checksum fix */
  1304. sky2_write32(hw, Q_ADDR(txqaddr[sky2->port], Q_TEST),
  1305. TBMU_TEST_HOME_ADD_FIX_EN | TBMU_TEST_ROUTING_ADD_FIX_EN);
  1306. }
  1307. }
  1308. static int sky2_alloc_buffers(struct sky2_port *sky2)
  1309. {
  1310. struct sky2_hw *hw = sky2->hw;
  1311. /* must be power of 2 */
  1312. sky2->tx_le = pci_alloc_consistent(hw->pdev,
  1313. sky2->tx_ring_size *
  1314. sizeof(struct sky2_tx_le),
  1315. &sky2->tx_le_map);
  1316. if (!sky2->tx_le)
  1317. goto nomem;
  1318. sky2->tx_ring = kcalloc(sky2->tx_ring_size, sizeof(struct tx_ring_info),
  1319. GFP_KERNEL);
  1320. if (!sky2->tx_ring)
  1321. goto nomem;
  1322. sky2->rx_le = pci_zalloc_consistent(hw->pdev, RX_LE_BYTES,
  1323. &sky2->rx_le_map);
  1324. if (!sky2->rx_le)
  1325. goto nomem;
  1326. sky2->rx_ring = kcalloc(sky2->rx_pending, sizeof(struct rx_ring_info),
  1327. GFP_KERNEL);
  1328. if (!sky2->rx_ring)
  1329. goto nomem;
  1330. return sky2_alloc_rx_skbs(sky2);
  1331. nomem:
  1332. return -ENOMEM;
  1333. }
  1334. static void sky2_free_buffers(struct sky2_port *sky2)
  1335. {
  1336. struct sky2_hw *hw = sky2->hw;
  1337. sky2_rx_clean(sky2);
  1338. if (sky2->rx_le) {
  1339. pci_free_consistent(hw->pdev, RX_LE_BYTES,
  1340. sky2->rx_le, sky2->rx_le_map);
  1341. sky2->rx_le = NULL;
  1342. }
  1343. if (sky2->tx_le) {
  1344. pci_free_consistent(hw->pdev,
  1345. sky2->tx_ring_size * sizeof(struct sky2_tx_le),
  1346. sky2->tx_le, sky2->tx_le_map);
  1347. sky2->tx_le = NULL;
  1348. }
  1349. kfree(sky2->tx_ring);
  1350. kfree(sky2->rx_ring);
  1351. sky2->tx_ring = NULL;
  1352. sky2->rx_ring = NULL;
  1353. }
  1354. static void sky2_hw_up(struct sky2_port *sky2)
  1355. {
  1356. struct sky2_hw *hw = sky2->hw;
  1357. unsigned port = sky2->port;
  1358. u32 ramsize;
  1359. int cap;
  1360. struct net_device *otherdev = hw->dev[sky2->port^1];
  1361. tx_init(sky2);
  1362. /*
  1363. * On dual port PCI-X card, there is an problem where status
  1364. * can be received out of order due to split transactions
  1365. */
  1366. if (otherdev && netif_running(otherdev) &&
  1367. (cap = pci_find_capability(hw->pdev, PCI_CAP_ID_PCIX))) {
  1368. u16 cmd;
  1369. cmd = sky2_pci_read16(hw, cap + PCI_X_CMD);
  1370. cmd &= ~PCI_X_CMD_MAX_SPLIT;
  1371. sky2_pci_write16(hw, cap + PCI_X_CMD, cmd);
  1372. }
  1373. sky2_mac_init(hw, port);
  1374. /* Register is number of 4K blocks on internal RAM buffer. */
  1375. ramsize = sky2_read8(hw, B2_E_0) * 4;
  1376. if (ramsize > 0) {
  1377. u32 rxspace;
  1378. netdev_dbg(sky2->netdev, "ram buffer %dK\n", ramsize);
  1379. if (ramsize < 16)
  1380. rxspace = ramsize / 2;
  1381. else
  1382. rxspace = 8 + (2*(ramsize - 16))/3;
  1383. sky2_ramset(hw, rxqaddr[port], 0, rxspace);
  1384. sky2_ramset(hw, txqaddr[port], rxspace, ramsize - rxspace);
  1385. /* Make sure SyncQ is disabled */
  1386. sky2_write8(hw, RB_ADDR(port == 0 ? Q_XS1 : Q_XS2, RB_CTRL),
  1387. RB_RST_SET);
  1388. }
  1389. sky2_qset(hw, txqaddr[port]);
  1390. /* This is copied from sk98lin 10.0.5.3; no one tells me about erratta's */
  1391. if (hw->chip_id == CHIP_ID_YUKON_EX && hw->chip_rev == CHIP_REV_YU_EX_B0)
  1392. sky2_write32(hw, Q_ADDR(txqaddr[port], Q_TEST), F_TX_CHK_AUTO_OFF);
  1393. /* Set almost empty threshold */
  1394. if (hw->chip_id == CHIP_ID_YUKON_EC_U &&
  1395. hw->chip_rev == CHIP_REV_YU_EC_U_A0)
  1396. sky2_write16(hw, Q_ADDR(txqaddr[port], Q_AL), ECU_TXFF_LEV);
  1397. sky2_prefetch_init(hw, txqaddr[port], sky2->tx_le_map,
  1398. sky2->tx_ring_size - 1);
  1399. sky2_vlan_mode(sky2->netdev, sky2->netdev->features);
  1400. netdev_update_features(sky2->netdev);
  1401. sky2_rx_start(sky2);
  1402. }
  1403. /* Setup device IRQ and enable napi to process */
  1404. static int sky2_setup_irq(struct sky2_hw *hw, const char *name)
  1405. {
  1406. struct pci_dev *pdev = hw->pdev;
  1407. int err;
  1408. err = request_irq(pdev->irq, sky2_intr,
  1409. (hw->flags & SKY2_HW_USE_MSI) ? 0 : IRQF_SHARED,
  1410. name, hw);
  1411. if (err)
  1412. dev_err(&pdev->dev, "cannot assign irq %d\n", pdev->irq);
  1413. else {
  1414. hw->flags |= SKY2_HW_IRQ_SETUP;
  1415. napi_enable(&hw->napi);
  1416. sky2_write32(hw, B0_IMSK, Y2_IS_BASE);
  1417. sky2_read32(hw, B0_IMSK);
  1418. }
  1419. return err;
  1420. }
  1421. /* Bring up network interface. */
  1422. static int sky2_open(struct net_device *dev)
  1423. {
  1424. struct sky2_port *sky2 = netdev_priv(dev);
  1425. struct sky2_hw *hw = sky2->hw;
  1426. unsigned port = sky2->port;
  1427. u32 imask;
  1428. int err;
  1429. netif_carrier_off(dev);
  1430. err = sky2_alloc_buffers(sky2);
  1431. if (err)
  1432. goto err_out;
  1433. /* With single port, IRQ is setup when device is brought up */
  1434. if (hw->ports == 1 && (err = sky2_setup_irq(hw, dev->name)))
  1435. goto err_out;
  1436. sky2_hw_up(sky2);
  1437. /* Enable interrupts from phy/mac for port */
  1438. imask = sky2_read32(hw, B0_IMSK);
  1439. if (hw->chip_id == CHIP_ID_YUKON_OPT ||
  1440. hw->chip_id == CHIP_ID_YUKON_PRM ||
  1441. hw->chip_id == CHIP_ID_YUKON_OP_2)
  1442. imask |= Y2_IS_PHY_QLNK; /* enable PHY Quick Link */
  1443. imask |= portirq_msk[port];
  1444. sky2_write32(hw, B0_IMSK, imask);
  1445. sky2_read32(hw, B0_IMSK);
  1446. netif_info(sky2, ifup, dev, "enabling interface\n");
  1447. return 0;
  1448. err_out:
  1449. sky2_free_buffers(sky2);
  1450. return err;
  1451. }
  1452. /* Modular subtraction in ring */
  1453. static inline int tx_inuse(const struct sky2_port *sky2)
  1454. {
  1455. return (sky2->tx_prod - sky2->tx_cons) & (sky2->tx_ring_size - 1);
  1456. }
  1457. /* Number of list elements available for next tx */
  1458. static inline int tx_avail(const struct sky2_port *sky2)
  1459. {
  1460. return sky2->tx_pending - tx_inuse(sky2);
  1461. }
  1462. /* Estimate of number of transmit list elements required */
  1463. static unsigned tx_le_req(const struct sk_buff *skb)
  1464. {
  1465. unsigned count;
  1466. count = (skb_shinfo(skb)->nr_frags + 1)
  1467. * (sizeof(dma_addr_t) / sizeof(u32));
  1468. if (skb_is_gso(skb))
  1469. ++count;
  1470. else if (sizeof(dma_addr_t) == sizeof(u32))
  1471. ++count; /* possible vlan */
  1472. if (skb->ip_summed == CHECKSUM_PARTIAL)
  1473. ++count;
  1474. return count;
  1475. }
  1476. static void sky2_tx_unmap(struct pci_dev *pdev, struct tx_ring_info *re)
  1477. {
  1478. if (re->flags & TX_MAP_SINGLE)
  1479. pci_unmap_single(pdev, dma_unmap_addr(re, mapaddr),
  1480. dma_unmap_len(re, maplen),
  1481. PCI_DMA_TODEVICE);
  1482. else if (re->flags & TX_MAP_PAGE)
  1483. pci_unmap_page(pdev, dma_unmap_addr(re, mapaddr),
  1484. dma_unmap_len(re, maplen),
  1485. PCI_DMA_TODEVICE);
  1486. re->flags = 0;
  1487. }
  1488. /*
  1489. * Put one packet in ring for transmit.
  1490. * A single packet can generate multiple list elements, and
  1491. * the number of ring elements will probably be less than the number
  1492. * of list elements used.
  1493. */
  1494. static netdev_tx_t sky2_xmit_frame(struct sk_buff *skb,
  1495. struct net_device *dev)
  1496. {
  1497. struct sky2_port *sky2 = netdev_priv(dev);
  1498. struct sky2_hw *hw = sky2->hw;
  1499. struct sky2_tx_le *le = NULL;
  1500. struct tx_ring_info *re;
  1501. unsigned i, len;
  1502. dma_addr_t mapping;
  1503. u32 upper;
  1504. u16 slot;
  1505. u16 mss;
  1506. u8 ctrl;
  1507. if (unlikely(tx_avail(sky2) < tx_le_req(skb)))
  1508. return NETDEV_TX_BUSY;
  1509. len = skb_headlen(skb);
  1510. mapping = pci_map_single(hw->pdev, skb->data, len, PCI_DMA_TODEVICE);
  1511. if (pci_dma_mapping_error(hw->pdev, mapping))
  1512. goto mapping_error;
  1513. slot = sky2->tx_prod;
  1514. netif_printk(sky2, tx_queued, KERN_DEBUG, dev,
  1515. "tx queued, slot %u, len %d\n", slot, skb->len);
  1516. /* Send high bits if needed */
  1517. upper = upper_32_bits(mapping);
  1518. if (upper != sky2->tx_last_upper) {
  1519. le = get_tx_le(sky2, &slot);
  1520. le->addr = cpu_to_le32(upper);
  1521. sky2->tx_last_upper = upper;
  1522. le->opcode = OP_ADDR64 | HW_OWNER;
  1523. }
  1524. /* Check for TCP Segmentation Offload */
  1525. mss = skb_shinfo(skb)->gso_size;
  1526. if (mss != 0) {
  1527. if (!(hw->flags & SKY2_HW_NEW_LE))
  1528. mss += ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
  1529. if (mss != sky2->tx_last_mss) {
  1530. le = get_tx_le(sky2, &slot);
  1531. le->addr = cpu_to_le32(mss);
  1532. if (hw->flags & SKY2_HW_NEW_LE)
  1533. le->opcode = OP_MSS | HW_OWNER;
  1534. else
  1535. le->opcode = OP_LRGLEN | HW_OWNER;
  1536. sky2->tx_last_mss = mss;
  1537. }
  1538. }
  1539. ctrl = 0;
  1540. /* Add VLAN tag, can piggyback on LRGLEN or ADDR64 */
  1541. if (skb_vlan_tag_present(skb)) {
  1542. if (!le) {
  1543. le = get_tx_le(sky2, &slot);
  1544. le->addr = 0;
  1545. le->opcode = OP_VLAN|HW_OWNER;
  1546. } else
  1547. le->opcode |= OP_VLAN;
  1548. le->length = cpu_to_be16(skb_vlan_tag_get(skb));
  1549. ctrl |= INS_VLAN;
  1550. }
  1551. /* Handle TCP checksum offload */
  1552. if (skb->ip_summed == CHECKSUM_PARTIAL) {
  1553. /* On Yukon EX (some versions) encoding change. */
  1554. if (hw->flags & SKY2_HW_AUTO_TX_SUM)
  1555. ctrl |= CALSUM; /* auto checksum */
  1556. else {
  1557. const unsigned offset = skb_transport_offset(skb);
  1558. u32 tcpsum;
  1559. tcpsum = offset << 16; /* sum start */
  1560. tcpsum |= offset + skb->csum_offset; /* sum write */
  1561. ctrl |= CALSUM | WR_SUM | INIT_SUM | LOCK_SUM;
  1562. if (ip_hdr(skb)->protocol == IPPROTO_UDP)
  1563. ctrl |= UDPTCP;
  1564. if (tcpsum != sky2->tx_tcpsum) {
  1565. sky2->tx_tcpsum = tcpsum;
  1566. le = get_tx_le(sky2, &slot);
  1567. le->addr = cpu_to_le32(tcpsum);
  1568. le->length = 0; /* initial checksum value */
  1569. le->ctrl = 1; /* one packet */
  1570. le->opcode = OP_TCPLISW | HW_OWNER;
  1571. }
  1572. }
  1573. }
  1574. re = sky2->tx_ring + slot;
  1575. re->flags = TX_MAP_SINGLE;
  1576. dma_unmap_addr_set(re, mapaddr, mapping);
  1577. dma_unmap_len_set(re, maplen, len);
  1578. le = get_tx_le(sky2, &slot);
  1579. le->addr = cpu_to_le32(lower_32_bits(mapping));
  1580. le->length = cpu_to_le16(len);
  1581. le->ctrl = ctrl;
  1582. le->opcode = mss ? (OP_LARGESEND | HW_OWNER) : (OP_PACKET | HW_OWNER);
  1583. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  1584. const skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  1585. mapping = skb_frag_dma_map(&hw->pdev->dev, frag, 0,
  1586. skb_frag_size(frag), DMA_TO_DEVICE);
  1587. if (dma_mapping_error(&hw->pdev->dev, mapping))
  1588. goto mapping_unwind;
  1589. upper = upper_32_bits(mapping);
  1590. if (upper != sky2->tx_last_upper) {
  1591. le = get_tx_le(sky2, &slot);
  1592. le->addr = cpu_to_le32(upper);
  1593. sky2->tx_last_upper = upper;
  1594. le->opcode = OP_ADDR64 | HW_OWNER;
  1595. }
  1596. re = sky2->tx_ring + slot;
  1597. re->flags = TX_MAP_PAGE;
  1598. dma_unmap_addr_set(re, mapaddr, mapping);
  1599. dma_unmap_len_set(re, maplen, skb_frag_size(frag));
  1600. le = get_tx_le(sky2, &slot);
  1601. le->addr = cpu_to_le32(lower_32_bits(mapping));
  1602. le->length = cpu_to_le16(skb_frag_size(frag));
  1603. le->ctrl = ctrl;
  1604. le->opcode = OP_BUFFER | HW_OWNER;
  1605. }
  1606. re->skb = skb;
  1607. le->ctrl |= EOP;
  1608. sky2->tx_prod = slot;
  1609. if (tx_avail(sky2) <= MAX_SKB_TX_LE)
  1610. netif_stop_queue(dev);
  1611. netdev_sent_queue(dev, skb->len);
  1612. sky2_put_idx(hw, txqaddr[sky2->port], sky2->tx_prod);
  1613. return NETDEV_TX_OK;
  1614. mapping_unwind:
  1615. for (i = sky2->tx_prod; i != slot; i = RING_NEXT(i, sky2->tx_ring_size)) {
  1616. re = sky2->tx_ring + i;
  1617. sky2_tx_unmap(hw->pdev, re);
  1618. }
  1619. mapping_error:
  1620. if (net_ratelimit())
  1621. dev_warn(&hw->pdev->dev, "%s: tx mapping error\n", dev->name);
  1622. dev_kfree_skb_any(skb);
  1623. return NETDEV_TX_OK;
  1624. }
  1625. /*
  1626. * Free ring elements from starting at tx_cons until "done"
  1627. *
  1628. * NB:
  1629. * 1. The hardware will tell us about partial completion of multi-part
  1630. * buffers so make sure not to free skb to early.
  1631. * 2. This may run in parallel start_xmit because the it only
  1632. * looks at the tail of the queue of FIFO (tx_cons), not
  1633. * the head (tx_prod)
  1634. */
  1635. static void sky2_tx_complete(struct sky2_port *sky2, u16 done)
  1636. {
  1637. struct net_device *dev = sky2->netdev;
  1638. u16 idx;
  1639. unsigned int bytes_compl = 0, pkts_compl = 0;
  1640. BUG_ON(done >= sky2->tx_ring_size);
  1641. for (idx = sky2->tx_cons; idx != done;
  1642. idx = RING_NEXT(idx, sky2->tx_ring_size)) {
  1643. struct tx_ring_info *re = sky2->tx_ring + idx;
  1644. struct sk_buff *skb = re->skb;
  1645. sky2_tx_unmap(sky2->hw->pdev, re);
  1646. if (skb) {
  1647. netif_printk(sky2, tx_done, KERN_DEBUG, dev,
  1648. "tx done %u\n", idx);
  1649. pkts_compl++;
  1650. bytes_compl += skb->len;
  1651. re->skb = NULL;
  1652. dev_kfree_skb_any(skb);
  1653. sky2->tx_next = RING_NEXT(idx, sky2->tx_ring_size);
  1654. }
  1655. }
  1656. sky2->tx_cons = idx;
  1657. smp_mb();
  1658. netdev_completed_queue(dev, pkts_compl, bytes_compl);
  1659. u64_stats_update_begin(&sky2->tx_stats.syncp);
  1660. sky2->tx_stats.packets += pkts_compl;
  1661. sky2->tx_stats.bytes += bytes_compl;
  1662. u64_stats_update_end(&sky2->tx_stats.syncp);
  1663. }
  1664. static void sky2_tx_reset(struct sky2_hw *hw, unsigned port)
  1665. {
  1666. /* Disable Force Sync bit and Enable Alloc bit */
  1667. sky2_write8(hw, SK_REG(port, TXA_CTRL),
  1668. TXA_DIS_FSYNC | TXA_DIS_ALLOC | TXA_STOP_RC);
  1669. /* Stop Interval Timer and Limit Counter of Tx Arbiter */
  1670. sky2_write32(hw, SK_REG(port, TXA_ITI_INI), 0L);
  1671. sky2_write32(hw, SK_REG(port, TXA_LIM_INI), 0L);
  1672. /* Reset the PCI FIFO of the async Tx queue */
  1673. sky2_write32(hw, Q_ADDR(txqaddr[port], Q_CSR),
  1674. BMU_RST_SET | BMU_FIFO_RST);
  1675. /* Reset the Tx prefetch units */
  1676. sky2_write32(hw, Y2_QADDR(txqaddr[port], PREF_UNIT_CTRL),
  1677. PREF_UNIT_RST_SET);
  1678. sky2_write32(hw, RB_ADDR(txqaddr[port], RB_CTRL), RB_RST_SET);
  1679. sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_SET);
  1680. sky2_read32(hw, B0_CTST);
  1681. }
  1682. static void sky2_hw_down(struct sky2_port *sky2)
  1683. {
  1684. struct sky2_hw *hw = sky2->hw;
  1685. unsigned port = sky2->port;
  1686. u16 ctrl;
  1687. /* Force flow control off */
  1688. sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF);
  1689. /* Stop transmitter */
  1690. sky2_write32(hw, Q_ADDR(txqaddr[port], Q_CSR), BMU_STOP);
  1691. sky2_read32(hw, Q_ADDR(txqaddr[port], Q_CSR));
  1692. sky2_write32(hw, RB_ADDR(txqaddr[port], RB_CTRL),
  1693. RB_RST_SET | RB_DIS_OP_MD);
  1694. ctrl = gma_read16(hw, port, GM_GP_CTRL);
  1695. ctrl &= ~(GM_GPCR_TX_ENA | GM_GPCR_RX_ENA);
  1696. gma_write16(hw, port, GM_GP_CTRL, ctrl);
  1697. sky2_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_SET);
  1698. /* Workaround shared GMAC reset */
  1699. if (!(hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev == 0 &&
  1700. port == 0 && hw->dev[1] && netif_running(hw->dev[1])))
  1701. sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_RST_SET);
  1702. sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET);
  1703. /* Force any delayed status interrupt and NAPI */
  1704. sky2_write32(hw, STAT_LEV_TIMER_CNT, 0);
  1705. sky2_write32(hw, STAT_TX_TIMER_CNT, 0);
  1706. sky2_write32(hw, STAT_ISR_TIMER_CNT, 0);
  1707. sky2_read8(hw, STAT_ISR_TIMER_CTRL);
  1708. sky2_rx_stop(sky2);
  1709. spin_lock_bh(&sky2->phy_lock);
  1710. sky2_phy_power_down(hw, port);
  1711. spin_unlock_bh(&sky2->phy_lock);
  1712. sky2_tx_reset(hw, port);
  1713. /* Free any pending frames stuck in HW queue */
  1714. sky2_tx_complete(sky2, sky2->tx_prod);
  1715. }
  1716. /* Network shutdown */
  1717. static int sky2_close(struct net_device *dev)
  1718. {
  1719. struct sky2_port *sky2 = netdev_priv(dev);
  1720. struct sky2_hw *hw = sky2->hw;
  1721. /* Never really got started! */
  1722. if (!sky2->tx_le)
  1723. return 0;
  1724. netif_info(sky2, ifdown, dev, "disabling interface\n");
  1725. if (hw->ports == 1) {
  1726. sky2_write32(hw, B0_IMSK, 0);
  1727. sky2_read32(hw, B0_IMSK);
  1728. napi_disable(&hw->napi);
  1729. free_irq(hw->pdev->irq, hw);
  1730. hw->flags &= ~SKY2_HW_IRQ_SETUP;
  1731. } else {
  1732. u32 imask;
  1733. /* Disable port IRQ */
  1734. imask = sky2_read32(hw, B0_IMSK);
  1735. imask &= ~portirq_msk[sky2->port];
  1736. sky2_write32(hw, B0_IMSK, imask);
  1737. sky2_read32(hw, B0_IMSK);
  1738. synchronize_irq(hw->pdev->irq);
  1739. napi_synchronize(&hw->napi);
  1740. }
  1741. sky2_hw_down(sky2);
  1742. sky2_free_buffers(sky2);
  1743. return 0;
  1744. }
  1745. static u16 sky2_phy_speed(const struct sky2_hw *hw, u16 aux)
  1746. {
  1747. if (hw->flags & SKY2_HW_FIBRE_PHY)
  1748. return SPEED_1000;
  1749. if (!(hw->flags & SKY2_HW_GIGABIT)) {
  1750. if (aux & PHY_M_PS_SPEED_100)
  1751. return SPEED_100;
  1752. else
  1753. return SPEED_10;
  1754. }
  1755. switch (aux & PHY_M_PS_SPEED_MSK) {
  1756. case PHY_M_PS_SPEED_1000:
  1757. return SPEED_1000;
  1758. case PHY_M_PS_SPEED_100:
  1759. return SPEED_100;
  1760. default:
  1761. return SPEED_10;
  1762. }
  1763. }
  1764. static void sky2_link_up(struct sky2_port *sky2)
  1765. {
  1766. struct sky2_hw *hw = sky2->hw;
  1767. unsigned port = sky2->port;
  1768. static const char *fc_name[] = {
  1769. [FC_NONE] = "none",
  1770. [FC_TX] = "tx",
  1771. [FC_RX] = "rx",
  1772. [FC_BOTH] = "both",
  1773. };
  1774. sky2_set_ipg(sky2);
  1775. sky2_enable_rx_tx(sky2);
  1776. gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_DEF_MSK);
  1777. netif_carrier_on(sky2->netdev);
  1778. mod_timer(&hw->watchdog_timer, jiffies + 1);
  1779. /* Turn on link LED */
  1780. sky2_write8(hw, SK_REG(port, LNK_LED_REG),
  1781. LINKLED_ON | LINKLED_BLINK_OFF | LINKLED_LINKSYNC_OFF);
  1782. netif_info(sky2, link, sky2->netdev,
  1783. "Link is up at %d Mbps, %s duplex, flow control %s\n",
  1784. sky2->speed,
  1785. sky2->duplex == DUPLEX_FULL ? "full" : "half",
  1786. fc_name[sky2->flow_status]);
  1787. }
  1788. static void sky2_link_down(struct sky2_port *sky2)
  1789. {
  1790. struct sky2_hw *hw = sky2->hw;
  1791. unsigned port = sky2->port;
  1792. u16 reg;
  1793. gm_phy_write(hw, port, PHY_MARV_INT_MASK, 0);
  1794. reg = gma_read16(hw, port, GM_GP_CTRL);
  1795. reg &= ~(GM_GPCR_RX_ENA | GM_GPCR_TX_ENA);
  1796. gma_write16(hw, port, GM_GP_CTRL, reg);
  1797. netif_carrier_off(sky2->netdev);
  1798. /* Turn off link LED */
  1799. sky2_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_OFF);
  1800. netif_info(sky2, link, sky2->netdev, "Link is down\n");
  1801. sky2_phy_init(hw, port);
  1802. }
  1803. static enum flow_control sky2_flow(int rx, int tx)
  1804. {
  1805. if (rx)
  1806. return tx ? FC_BOTH : FC_RX;
  1807. else
  1808. return tx ? FC_TX : FC_NONE;
  1809. }
  1810. static int sky2_autoneg_done(struct sky2_port *sky2, u16 aux)
  1811. {
  1812. struct sky2_hw *hw = sky2->hw;
  1813. unsigned port = sky2->port;
  1814. u16 advert, lpa;
  1815. advert = gm_phy_read(hw, port, PHY_MARV_AUNE_ADV);
  1816. lpa = gm_phy_read(hw, port, PHY_MARV_AUNE_LP);
  1817. if (lpa & PHY_M_AN_RF) {
  1818. netdev_err(sky2->netdev, "remote fault\n");
  1819. return -1;
  1820. }
  1821. if (!(aux & PHY_M_PS_SPDUP_RES)) {
  1822. netdev_err(sky2->netdev, "speed/duplex mismatch\n");
  1823. return -1;
  1824. }
  1825. sky2->speed = sky2_phy_speed(hw, aux);
  1826. sky2->duplex = (aux & PHY_M_PS_FULL_DUP) ? DUPLEX_FULL : DUPLEX_HALF;
  1827. /* Since the pause result bits seem to in different positions on
  1828. * different chips. look at registers.
  1829. */
  1830. if (hw->flags & SKY2_HW_FIBRE_PHY) {
  1831. /* Shift for bits in fiber PHY */
  1832. advert &= ~(ADVERTISE_PAUSE_CAP|ADVERTISE_PAUSE_ASYM);
  1833. lpa &= ~(LPA_PAUSE_CAP|LPA_PAUSE_ASYM);
  1834. if (advert & ADVERTISE_1000XPAUSE)
  1835. advert |= ADVERTISE_PAUSE_CAP;
  1836. if (advert & ADVERTISE_1000XPSE_ASYM)
  1837. advert |= ADVERTISE_PAUSE_ASYM;
  1838. if (lpa & LPA_1000XPAUSE)
  1839. lpa |= LPA_PAUSE_CAP;
  1840. if (lpa & LPA_1000XPAUSE_ASYM)
  1841. lpa |= LPA_PAUSE_ASYM;
  1842. }
  1843. sky2->flow_status = FC_NONE;
  1844. if (advert & ADVERTISE_PAUSE_CAP) {
  1845. if (lpa & LPA_PAUSE_CAP)
  1846. sky2->flow_status = FC_BOTH;
  1847. else if (advert & ADVERTISE_PAUSE_ASYM)
  1848. sky2->flow_status = FC_RX;
  1849. } else if (advert & ADVERTISE_PAUSE_ASYM) {
  1850. if ((lpa & LPA_PAUSE_CAP) && (lpa & LPA_PAUSE_ASYM))
  1851. sky2->flow_status = FC_TX;
  1852. }
  1853. if (sky2->duplex == DUPLEX_HALF && sky2->speed < SPEED_1000 &&
  1854. !(hw->chip_id == CHIP_ID_YUKON_EC_U || hw->chip_id == CHIP_ID_YUKON_EX))
  1855. sky2->flow_status = FC_NONE;
  1856. if (sky2->flow_status & FC_TX)
  1857. sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_ON);
  1858. else
  1859. sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF);
  1860. return 0;
  1861. }
  1862. /* Interrupt from PHY */
  1863. static void sky2_phy_intr(struct sky2_hw *hw, unsigned port)
  1864. {
  1865. struct net_device *dev = hw->dev[port];
  1866. struct sky2_port *sky2 = netdev_priv(dev);
  1867. u16 istatus, phystat;
  1868. if (!netif_running(dev))
  1869. return;
  1870. spin_lock(&sky2->phy_lock);
  1871. istatus = gm_phy_read(hw, port, PHY_MARV_INT_STAT);
  1872. phystat = gm_phy_read(hw, port, PHY_MARV_PHY_STAT);
  1873. netif_info(sky2, intr, sky2->netdev, "phy interrupt status 0x%x 0x%x\n",
  1874. istatus, phystat);
  1875. if (istatus & PHY_M_IS_AN_COMPL) {
  1876. if (sky2_autoneg_done(sky2, phystat) == 0 &&
  1877. !netif_carrier_ok(dev))
  1878. sky2_link_up(sky2);
  1879. goto out;
  1880. }
  1881. if (istatus & PHY_M_IS_LSP_CHANGE)
  1882. sky2->speed = sky2_phy_speed(hw, phystat);
  1883. if (istatus & PHY_M_IS_DUP_CHANGE)
  1884. sky2->duplex =
  1885. (phystat & PHY_M_PS_FULL_DUP) ? DUPLEX_FULL : DUPLEX_HALF;
  1886. if (istatus & PHY_M_IS_LST_CHANGE) {
  1887. if (phystat & PHY_M_PS_LINK_UP)
  1888. sky2_link_up(sky2);
  1889. else
  1890. sky2_link_down(sky2);
  1891. }
  1892. out:
  1893. spin_unlock(&sky2->phy_lock);
  1894. }
  1895. /* Special quick link interrupt (Yukon-2 Optima only) */
  1896. static void sky2_qlink_intr(struct sky2_hw *hw)
  1897. {
  1898. struct sky2_port *sky2 = netdev_priv(hw->dev[0]);
  1899. u32 imask;
  1900. u16 phy;
  1901. /* disable irq */
  1902. imask = sky2_read32(hw, B0_IMSK);
  1903. imask &= ~Y2_IS_PHY_QLNK;
  1904. sky2_write32(hw, B0_IMSK, imask);
  1905. /* reset PHY Link Detect */
  1906. phy = sky2_pci_read16(hw, PSM_CONFIG_REG4);
  1907. sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
  1908. sky2_pci_write16(hw, PSM_CONFIG_REG4, phy | 1);
  1909. sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
  1910. sky2_link_up(sky2);
  1911. }
  1912. /* Transmit timeout is only called if we are running, carrier is up
  1913. * and tx queue is full (stopped).
  1914. */
  1915. static void sky2_tx_timeout(struct net_device *dev)
  1916. {
  1917. struct sky2_port *sky2 = netdev_priv(dev);
  1918. struct sky2_hw *hw = sky2->hw;
  1919. netif_err(sky2, timer, dev, "tx timeout\n");
  1920. netdev_printk(KERN_DEBUG, dev, "transmit ring %u .. %u report=%u done=%u\n",
  1921. sky2->tx_cons, sky2->tx_prod,
  1922. sky2_read16(hw, sky2->port == 0 ? STAT_TXA1_RIDX : STAT_TXA2_RIDX),
  1923. sky2_read16(hw, Q_ADDR(txqaddr[sky2->port], Q_DONE)));
  1924. /* can't restart safely under softirq */
  1925. schedule_work(&hw->restart_work);
  1926. }
  1927. static int sky2_change_mtu(struct net_device *dev, int new_mtu)
  1928. {
  1929. struct sky2_port *sky2 = netdev_priv(dev);
  1930. struct sky2_hw *hw = sky2->hw;
  1931. unsigned port = sky2->port;
  1932. int err;
  1933. u16 ctl, mode;
  1934. u32 imask;
  1935. /* MTU size outside the spec */
  1936. if (new_mtu < ETH_ZLEN || new_mtu > ETH_JUMBO_MTU)
  1937. return -EINVAL;
  1938. /* MTU > 1500 on yukon FE and FE+ not allowed */
  1939. if (new_mtu > ETH_DATA_LEN &&
  1940. (hw->chip_id == CHIP_ID_YUKON_FE ||
  1941. hw->chip_id == CHIP_ID_YUKON_FE_P))
  1942. return -EINVAL;
  1943. if (!netif_running(dev)) {
  1944. dev->mtu = new_mtu;
  1945. netdev_update_features(dev);
  1946. return 0;
  1947. }
  1948. imask = sky2_read32(hw, B0_IMSK);
  1949. sky2_write32(hw, B0_IMSK, 0);
  1950. sky2_read32(hw, B0_IMSK);
  1951. netif_trans_update(dev); /* prevent tx timeout */
  1952. napi_disable(&hw->napi);
  1953. netif_tx_disable(dev);
  1954. synchronize_irq(hw->pdev->irq);
  1955. if (!(hw->flags & SKY2_HW_RAM_BUFFER))
  1956. sky2_set_tx_stfwd(hw, port);
  1957. ctl = gma_read16(hw, port, GM_GP_CTRL);
  1958. gma_write16(hw, port, GM_GP_CTRL, ctl & ~GM_GPCR_RX_ENA);
  1959. sky2_rx_stop(sky2);
  1960. sky2_rx_clean(sky2);
  1961. dev->mtu = new_mtu;
  1962. netdev_update_features(dev);
  1963. mode = DATA_BLIND_VAL(DATA_BLIND_DEF) | GM_SMOD_VLAN_ENA;
  1964. if (sky2->speed > SPEED_100)
  1965. mode |= IPG_DATA_VAL(IPG_DATA_DEF_1000);
  1966. else
  1967. mode |= IPG_DATA_VAL(IPG_DATA_DEF_10_100);
  1968. if (dev->mtu > ETH_DATA_LEN)
  1969. mode |= GM_SMOD_JUMBO_ENA;
  1970. gma_write16(hw, port, GM_SERIAL_MODE, mode);
  1971. sky2_write8(hw, RB_ADDR(rxqaddr[port], RB_CTRL), RB_ENA_OP_MD);
  1972. err = sky2_alloc_rx_skbs(sky2);
  1973. if (!err)
  1974. sky2_rx_start(sky2);
  1975. else
  1976. sky2_rx_clean(sky2);
  1977. sky2_write32(hw, B0_IMSK, imask);
  1978. sky2_read32(hw, B0_Y2_SP_LISR);
  1979. napi_enable(&hw->napi);
  1980. if (err)
  1981. dev_close(dev);
  1982. else {
  1983. gma_write16(hw, port, GM_GP_CTRL, ctl);
  1984. netif_wake_queue(dev);
  1985. }
  1986. return err;
  1987. }
  1988. static inline bool needs_copy(const struct rx_ring_info *re,
  1989. unsigned length)
  1990. {
  1991. #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
  1992. /* Some architectures need the IP header to be aligned */
  1993. if (!IS_ALIGNED(re->data_addr + ETH_HLEN, sizeof(u32)))
  1994. return true;
  1995. #endif
  1996. return length < copybreak;
  1997. }
  1998. /* For small just reuse existing skb for next receive */
  1999. static struct sk_buff *receive_copy(struct sky2_port *sky2,
  2000. const struct rx_ring_info *re,
  2001. unsigned length)
  2002. {
  2003. struct sk_buff *skb;
  2004. skb = netdev_alloc_skb_ip_align(sky2->netdev, length);
  2005. if (likely(skb)) {
  2006. pci_dma_sync_single_for_cpu(sky2->hw->pdev, re->data_addr,
  2007. length, PCI_DMA_FROMDEVICE);
  2008. skb_copy_from_linear_data(re->skb, skb->data, length);
  2009. skb->ip_summed = re->skb->ip_summed;
  2010. skb->csum = re->skb->csum;
  2011. skb_copy_hash(skb, re->skb);
  2012. skb->vlan_proto = re->skb->vlan_proto;
  2013. skb->vlan_tci = re->skb->vlan_tci;
  2014. pci_dma_sync_single_for_device(sky2->hw->pdev, re->data_addr,
  2015. length, PCI_DMA_FROMDEVICE);
  2016. re->skb->vlan_proto = 0;
  2017. re->skb->vlan_tci = 0;
  2018. skb_clear_hash(re->skb);
  2019. re->skb->ip_summed = CHECKSUM_NONE;
  2020. skb_put(skb, length);
  2021. }
  2022. return skb;
  2023. }
  2024. /* Adjust length of skb with fragments to match received data */
  2025. static void skb_put_frags(struct sk_buff *skb, unsigned int hdr_space,
  2026. unsigned int length)
  2027. {
  2028. int i, num_frags;
  2029. unsigned int size;
  2030. /* put header into skb */
  2031. size = min(length, hdr_space);
  2032. skb->tail += size;
  2033. skb->len += size;
  2034. length -= size;
  2035. num_frags = skb_shinfo(skb)->nr_frags;
  2036. for (i = 0; i < num_frags; i++) {
  2037. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  2038. if (length == 0) {
  2039. /* don't need this page */
  2040. __skb_frag_unref(frag);
  2041. --skb_shinfo(skb)->nr_frags;
  2042. } else {
  2043. size = min(length, (unsigned) PAGE_SIZE);
  2044. skb_frag_size_set(frag, size);
  2045. skb->data_len += size;
  2046. skb->truesize += PAGE_SIZE;
  2047. skb->len += size;
  2048. length -= size;
  2049. }
  2050. }
  2051. }
  2052. /* Normal packet - take skb from ring element and put in a new one */
  2053. static struct sk_buff *receive_new(struct sky2_port *sky2,
  2054. struct rx_ring_info *re,
  2055. unsigned int length)
  2056. {
  2057. struct sk_buff *skb;
  2058. struct rx_ring_info nre;
  2059. unsigned hdr_space = sky2->rx_data_size;
  2060. nre.skb = sky2_rx_alloc(sky2, GFP_ATOMIC);
  2061. if (unlikely(!nre.skb))
  2062. goto nobuf;
  2063. if (sky2_rx_map_skb(sky2->hw->pdev, &nre, hdr_space))
  2064. goto nomap;
  2065. skb = re->skb;
  2066. sky2_rx_unmap_skb(sky2->hw->pdev, re);
  2067. prefetch(skb->data);
  2068. *re = nre;
  2069. if (skb_shinfo(skb)->nr_frags)
  2070. skb_put_frags(skb, hdr_space, length);
  2071. else
  2072. skb_put(skb, length);
  2073. return skb;
  2074. nomap:
  2075. dev_kfree_skb(nre.skb);
  2076. nobuf:
  2077. return NULL;
  2078. }
  2079. /*
  2080. * Receive one packet.
  2081. * For larger packets, get new buffer.
  2082. */
  2083. static struct sk_buff *sky2_receive(struct net_device *dev,
  2084. u16 length, u32 status)
  2085. {
  2086. struct sky2_port *sky2 = netdev_priv(dev);
  2087. struct rx_ring_info *re = sky2->rx_ring + sky2->rx_next;
  2088. struct sk_buff *skb = NULL;
  2089. u16 count = (status & GMR_FS_LEN) >> 16;
  2090. netif_printk(sky2, rx_status, KERN_DEBUG, dev,
  2091. "rx slot %u status 0x%x len %d\n",
  2092. sky2->rx_next, status, length);
  2093. sky2->rx_next = (sky2->rx_next + 1) % sky2->rx_pending;
  2094. prefetch(sky2->rx_ring + sky2->rx_next);
  2095. if (skb_vlan_tag_present(re->skb))
  2096. count -= VLAN_HLEN; /* Account for vlan tag */
  2097. /* This chip has hardware problems that generates bogus status.
  2098. * So do only marginal checking and expect higher level protocols
  2099. * to handle crap frames.
  2100. */
  2101. if (sky2->hw->chip_id == CHIP_ID_YUKON_FE_P &&
  2102. sky2->hw->chip_rev == CHIP_REV_YU_FE2_A0 &&
  2103. length != count)
  2104. goto okay;
  2105. if (status & GMR_FS_ANY_ERR)
  2106. goto error;
  2107. if (!(status & GMR_FS_RX_OK))
  2108. goto resubmit;
  2109. /* if length reported by DMA does not match PHY, packet was truncated */
  2110. if (length != count)
  2111. goto error;
  2112. okay:
  2113. if (needs_copy(re, length))
  2114. skb = receive_copy(sky2, re, length);
  2115. else
  2116. skb = receive_new(sky2, re, length);
  2117. dev->stats.rx_dropped += (skb == NULL);
  2118. resubmit:
  2119. sky2_rx_submit(sky2, re);
  2120. return skb;
  2121. error:
  2122. ++dev->stats.rx_errors;
  2123. if (net_ratelimit())
  2124. netif_info(sky2, rx_err, dev,
  2125. "rx error, status 0x%x length %d\n", status, length);
  2126. goto resubmit;
  2127. }
  2128. /* Transmit complete */
  2129. static inline void sky2_tx_done(struct net_device *dev, u16 last)
  2130. {
  2131. struct sky2_port *sky2 = netdev_priv(dev);
  2132. if (netif_running(dev)) {
  2133. sky2_tx_complete(sky2, last);
  2134. /* Wake unless it's detached, and called e.g. from sky2_close() */
  2135. if (tx_avail(sky2) > MAX_SKB_TX_LE + 4)
  2136. netif_wake_queue(dev);
  2137. }
  2138. }
  2139. static inline void sky2_skb_rx(const struct sky2_port *sky2,
  2140. struct sk_buff *skb)
  2141. {
  2142. if (skb->ip_summed == CHECKSUM_NONE)
  2143. netif_receive_skb(skb);
  2144. else
  2145. napi_gro_receive(&sky2->hw->napi, skb);
  2146. }
  2147. static inline void sky2_rx_done(struct sky2_hw *hw, unsigned port,
  2148. unsigned packets, unsigned bytes)
  2149. {
  2150. struct net_device *dev = hw->dev[port];
  2151. struct sky2_port *sky2 = netdev_priv(dev);
  2152. if (packets == 0)
  2153. return;
  2154. u64_stats_update_begin(&sky2->rx_stats.syncp);
  2155. sky2->rx_stats.packets += packets;
  2156. sky2->rx_stats.bytes += bytes;
  2157. u64_stats_update_end(&sky2->rx_stats.syncp);
  2158. dev->last_rx = jiffies;
  2159. sky2_rx_update(netdev_priv(dev), rxqaddr[port]);
  2160. }
  2161. static void sky2_rx_checksum(struct sky2_port *sky2, u32 status)
  2162. {
  2163. /* If this happens then driver assuming wrong format for chip type */
  2164. BUG_ON(sky2->hw->flags & SKY2_HW_NEW_LE);
  2165. /* Both checksum counters are programmed to start at
  2166. * the same offset, so unless there is a problem they
  2167. * should match. This failure is an early indication that
  2168. * hardware receive checksumming won't work.
  2169. */
  2170. if (likely((u16)(status >> 16) == (u16)status)) {
  2171. struct sk_buff *skb = sky2->rx_ring[sky2->rx_next].skb;
  2172. skb->ip_summed = CHECKSUM_COMPLETE;
  2173. skb->csum = le16_to_cpu(status);
  2174. } else {
  2175. dev_notice(&sky2->hw->pdev->dev,
  2176. "%s: receive checksum problem (status = %#x)\n",
  2177. sky2->netdev->name, status);
  2178. /* Disable checksum offload
  2179. * It will be reenabled on next ndo_set_features, but if it's
  2180. * really broken, will get disabled again
  2181. */
  2182. sky2->netdev->features &= ~NETIF_F_RXCSUM;
  2183. sky2_write32(sky2->hw, Q_ADDR(rxqaddr[sky2->port], Q_CSR),
  2184. BMU_DIS_RX_CHKSUM);
  2185. }
  2186. }
  2187. static void sky2_rx_tag(struct sky2_port *sky2, u16 length)
  2188. {
  2189. struct sk_buff *skb;
  2190. skb = sky2->rx_ring[sky2->rx_next].skb;
  2191. __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), be16_to_cpu(length));
  2192. }
  2193. static void sky2_rx_hash(struct sky2_port *sky2, u32 status)
  2194. {
  2195. struct sk_buff *skb;
  2196. skb = sky2->rx_ring[sky2->rx_next].skb;
  2197. skb_set_hash(skb, le32_to_cpu(status), PKT_HASH_TYPE_L3);
  2198. }
  2199. /* Process status response ring */
  2200. static int sky2_status_intr(struct sky2_hw *hw, int to_do, u16 idx)
  2201. {
  2202. int work_done = 0;
  2203. unsigned int total_bytes[2] = { 0 };
  2204. unsigned int total_packets[2] = { 0 };
  2205. if (to_do <= 0)
  2206. return work_done;
  2207. rmb();
  2208. do {
  2209. struct sky2_port *sky2;
  2210. struct sky2_status_le *le = hw->st_le + hw->st_idx;
  2211. unsigned port;
  2212. struct net_device *dev;
  2213. struct sk_buff *skb;
  2214. u32 status;
  2215. u16 length;
  2216. u8 opcode = le->opcode;
  2217. if (!(opcode & HW_OWNER))
  2218. break;
  2219. hw->st_idx = RING_NEXT(hw->st_idx, hw->st_size);
  2220. port = le->css & CSS_LINK_BIT;
  2221. dev = hw->dev[port];
  2222. sky2 = netdev_priv(dev);
  2223. length = le16_to_cpu(le->length);
  2224. status = le32_to_cpu(le->status);
  2225. le->opcode = 0;
  2226. switch (opcode & ~HW_OWNER) {
  2227. case OP_RXSTAT:
  2228. total_packets[port]++;
  2229. total_bytes[port] += length;
  2230. skb = sky2_receive(dev, length, status);
  2231. if (!skb)
  2232. break;
  2233. /* This chip reports checksum status differently */
  2234. if (hw->flags & SKY2_HW_NEW_LE) {
  2235. if ((dev->features & NETIF_F_RXCSUM) &&
  2236. (le->css & (CSS_ISIPV4 | CSS_ISIPV6)) &&
  2237. (le->css & CSS_TCPUDPCSOK))
  2238. skb->ip_summed = CHECKSUM_UNNECESSARY;
  2239. else
  2240. skb->ip_summed = CHECKSUM_NONE;
  2241. }
  2242. skb->protocol = eth_type_trans(skb, dev);
  2243. sky2_skb_rx(sky2, skb);
  2244. /* Stop after net poll weight */
  2245. if (++work_done >= to_do)
  2246. goto exit_loop;
  2247. break;
  2248. case OP_RXVLAN:
  2249. sky2_rx_tag(sky2, length);
  2250. break;
  2251. case OP_RXCHKSVLAN:
  2252. sky2_rx_tag(sky2, length);
  2253. /* fall through */
  2254. case OP_RXCHKS:
  2255. if (likely(dev->features & NETIF_F_RXCSUM))
  2256. sky2_rx_checksum(sky2, status);
  2257. break;
  2258. case OP_RSS_HASH:
  2259. sky2_rx_hash(sky2, status);
  2260. break;
  2261. case OP_TXINDEXLE:
  2262. /* TX index reports status for both ports */
  2263. sky2_tx_done(hw->dev[0], status & 0xfff);
  2264. if (hw->dev[1])
  2265. sky2_tx_done(hw->dev[1],
  2266. ((status >> 24) & 0xff)
  2267. | (u16)(length & 0xf) << 8);
  2268. break;
  2269. default:
  2270. if (net_ratelimit())
  2271. pr_warn("unknown status opcode 0x%x\n", opcode);
  2272. }
  2273. } while (hw->st_idx != idx);
  2274. /* Fully processed status ring so clear irq */
  2275. sky2_write32(hw, STAT_CTRL, SC_STAT_CLR_IRQ);
  2276. exit_loop:
  2277. sky2_rx_done(hw, 0, total_packets[0], total_bytes[0]);
  2278. sky2_rx_done(hw, 1, total_packets[1], total_bytes[1]);
  2279. return work_done;
  2280. }
  2281. static void sky2_hw_error(struct sky2_hw *hw, unsigned port, u32 status)
  2282. {
  2283. struct net_device *dev = hw->dev[port];
  2284. if (net_ratelimit())
  2285. netdev_info(dev, "hw error interrupt status 0x%x\n", status);
  2286. if (status & Y2_IS_PAR_RD1) {
  2287. if (net_ratelimit())
  2288. netdev_err(dev, "ram data read parity error\n");
  2289. /* Clear IRQ */
  2290. sky2_write16(hw, RAM_BUFFER(port, B3_RI_CTRL), RI_CLR_RD_PERR);
  2291. }
  2292. if (status & Y2_IS_PAR_WR1) {
  2293. if (net_ratelimit())
  2294. netdev_err(dev, "ram data write parity error\n");
  2295. sky2_write16(hw, RAM_BUFFER(port, B3_RI_CTRL), RI_CLR_WR_PERR);
  2296. }
  2297. if (status & Y2_IS_PAR_MAC1) {
  2298. if (net_ratelimit())
  2299. netdev_err(dev, "MAC parity error\n");
  2300. sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_CLI_TX_PE);
  2301. }
  2302. if (status & Y2_IS_PAR_RX1) {
  2303. if (net_ratelimit())
  2304. netdev_err(dev, "RX parity error\n");
  2305. sky2_write32(hw, Q_ADDR(rxqaddr[port], Q_CSR), BMU_CLR_IRQ_PAR);
  2306. }
  2307. if (status & Y2_IS_TCP_TXA1) {
  2308. if (net_ratelimit())
  2309. netdev_err(dev, "TCP segmentation error\n");
  2310. sky2_write32(hw, Q_ADDR(txqaddr[port], Q_CSR), BMU_CLR_IRQ_TCP);
  2311. }
  2312. }
  2313. static void sky2_hw_intr(struct sky2_hw *hw)
  2314. {
  2315. struct pci_dev *pdev = hw->pdev;
  2316. u32 status = sky2_read32(hw, B0_HWE_ISRC);
  2317. u32 hwmsk = sky2_read32(hw, B0_HWE_IMSK);
  2318. status &= hwmsk;
  2319. if (status & Y2_IS_TIST_OV)
  2320. sky2_write8(hw, GMAC_TI_ST_CTRL, GMT_ST_CLR_IRQ);
  2321. if (status & (Y2_IS_MST_ERR | Y2_IS_IRQ_STAT)) {
  2322. u16 pci_err;
  2323. sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
  2324. pci_err = sky2_pci_read16(hw, PCI_STATUS);
  2325. if (net_ratelimit())
  2326. dev_err(&pdev->dev, "PCI hardware error (0x%x)\n",
  2327. pci_err);
  2328. sky2_pci_write16(hw, PCI_STATUS,
  2329. pci_err | PCI_STATUS_ERROR_BITS);
  2330. sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
  2331. }
  2332. if (status & Y2_IS_PCI_EXP) {
  2333. /* PCI-Express uncorrectable Error occurred */
  2334. u32 err;
  2335. sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
  2336. err = sky2_read32(hw, Y2_CFG_AER + PCI_ERR_UNCOR_STATUS);
  2337. sky2_write32(hw, Y2_CFG_AER + PCI_ERR_UNCOR_STATUS,
  2338. 0xfffffffful);
  2339. if (net_ratelimit())
  2340. dev_err(&pdev->dev, "PCI Express error (0x%x)\n", err);
  2341. sky2_read32(hw, Y2_CFG_AER + PCI_ERR_UNCOR_STATUS);
  2342. sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
  2343. }
  2344. if (status & Y2_HWE_L1_MASK)
  2345. sky2_hw_error(hw, 0, status);
  2346. status >>= 8;
  2347. if (status & Y2_HWE_L1_MASK)
  2348. sky2_hw_error(hw, 1, status);
  2349. }
  2350. static void sky2_mac_intr(struct sky2_hw *hw, unsigned port)
  2351. {
  2352. struct net_device *dev = hw->dev[port];
  2353. struct sky2_port *sky2 = netdev_priv(dev);
  2354. u8 status = sky2_read8(hw, SK_REG(port, GMAC_IRQ_SRC));
  2355. netif_info(sky2, intr, dev, "mac interrupt status 0x%x\n", status);
  2356. if (status & GM_IS_RX_CO_OV)
  2357. gma_read16(hw, port, GM_RX_IRQ_SRC);
  2358. if (status & GM_IS_TX_CO_OV)
  2359. gma_read16(hw, port, GM_TX_IRQ_SRC);
  2360. if (status & GM_IS_RX_FF_OR) {
  2361. ++dev->stats.rx_fifo_errors;
  2362. sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_CLI_RX_FO);
  2363. }
  2364. if (status & GM_IS_TX_FF_UR) {
  2365. ++dev->stats.tx_fifo_errors;
  2366. sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_CLI_TX_FU);
  2367. }
  2368. }
  2369. /* This should never happen it is a bug. */
  2370. static void sky2_le_error(struct sky2_hw *hw, unsigned port, u16 q)
  2371. {
  2372. struct net_device *dev = hw->dev[port];
  2373. u16 idx = sky2_read16(hw, Y2_QADDR(q, PREF_UNIT_GET_IDX));
  2374. dev_err(&hw->pdev->dev, "%s: descriptor error q=%#x get=%u put=%u\n",
  2375. dev->name, (unsigned) q, (unsigned) idx,
  2376. (unsigned) sky2_read16(hw, Y2_QADDR(q, PREF_UNIT_PUT_IDX)));
  2377. sky2_write32(hw, Q_ADDR(q, Q_CSR), BMU_CLR_IRQ_CHK);
  2378. }
  2379. static int sky2_rx_hung(struct net_device *dev)
  2380. {
  2381. struct sky2_port *sky2 = netdev_priv(dev);
  2382. struct sky2_hw *hw = sky2->hw;
  2383. unsigned port = sky2->port;
  2384. unsigned rxq = rxqaddr[port];
  2385. u32 mac_rp = sky2_read32(hw, SK_REG(port, RX_GMF_RP));
  2386. u8 mac_lev = sky2_read8(hw, SK_REG(port, RX_GMF_RLEV));
  2387. u8 fifo_rp = sky2_read8(hw, Q_ADDR(rxq, Q_RP));
  2388. u8 fifo_lev = sky2_read8(hw, Q_ADDR(rxq, Q_RL));
  2389. /* If idle and MAC or PCI is stuck */
  2390. if (sky2->check.last == dev->last_rx &&
  2391. ((mac_rp == sky2->check.mac_rp &&
  2392. mac_lev != 0 && mac_lev >= sky2->check.mac_lev) ||
  2393. /* Check if the PCI RX hang */
  2394. (fifo_rp == sky2->check.fifo_rp &&
  2395. fifo_lev != 0 && fifo_lev >= sky2->check.fifo_lev))) {
  2396. netdev_printk(KERN_DEBUG, dev,
  2397. "hung mac %d:%d fifo %d (%d:%d)\n",
  2398. mac_lev, mac_rp, fifo_lev,
  2399. fifo_rp, sky2_read8(hw, Q_ADDR(rxq, Q_WP)));
  2400. return 1;
  2401. } else {
  2402. sky2->check.last = dev->last_rx;
  2403. sky2->check.mac_rp = mac_rp;
  2404. sky2->check.mac_lev = mac_lev;
  2405. sky2->check.fifo_rp = fifo_rp;
  2406. sky2->check.fifo_lev = fifo_lev;
  2407. return 0;
  2408. }
  2409. }
  2410. static void sky2_watchdog(unsigned long arg)
  2411. {
  2412. struct sky2_hw *hw = (struct sky2_hw *) arg;
  2413. /* Check for lost IRQ once a second */
  2414. if (sky2_read32(hw, B0_ISRC)) {
  2415. napi_schedule(&hw->napi);
  2416. } else {
  2417. int i, active = 0;
  2418. for (i = 0; i < hw->ports; i++) {
  2419. struct net_device *dev = hw->dev[i];
  2420. if (!netif_running(dev))
  2421. continue;
  2422. ++active;
  2423. /* For chips with Rx FIFO, check if stuck */
  2424. if ((hw->flags & SKY2_HW_RAM_BUFFER) &&
  2425. sky2_rx_hung(dev)) {
  2426. netdev_info(dev, "receiver hang detected\n");
  2427. schedule_work(&hw->restart_work);
  2428. return;
  2429. }
  2430. }
  2431. if (active == 0)
  2432. return;
  2433. }
  2434. mod_timer(&hw->watchdog_timer, round_jiffies(jiffies + HZ));
  2435. }
  2436. /* Hardware/software error handling */
  2437. static void sky2_err_intr(struct sky2_hw *hw, u32 status)
  2438. {
  2439. if (net_ratelimit())
  2440. dev_warn(&hw->pdev->dev, "error interrupt status=%#x\n", status);
  2441. if (status & Y2_IS_HW_ERR)
  2442. sky2_hw_intr(hw);
  2443. if (status & Y2_IS_IRQ_MAC1)
  2444. sky2_mac_intr(hw, 0);
  2445. if (status & Y2_IS_IRQ_MAC2)
  2446. sky2_mac_intr(hw, 1);
  2447. if (status & Y2_IS_CHK_RX1)
  2448. sky2_le_error(hw, 0, Q_R1);
  2449. if (status & Y2_IS_CHK_RX2)
  2450. sky2_le_error(hw, 1, Q_R2);
  2451. if (status & Y2_IS_CHK_TXA1)
  2452. sky2_le_error(hw, 0, Q_XA1);
  2453. if (status & Y2_IS_CHK_TXA2)
  2454. sky2_le_error(hw, 1, Q_XA2);
  2455. }
  2456. static int sky2_poll(struct napi_struct *napi, int work_limit)
  2457. {
  2458. struct sky2_hw *hw = container_of(napi, struct sky2_hw, napi);
  2459. u32 status = sky2_read32(hw, B0_Y2_SP_EISR);
  2460. int work_done = 0;
  2461. u16 idx;
  2462. if (unlikely(status & Y2_IS_ERROR))
  2463. sky2_err_intr(hw, status);
  2464. if (status & Y2_IS_IRQ_PHY1)
  2465. sky2_phy_intr(hw, 0);
  2466. if (status & Y2_IS_IRQ_PHY2)
  2467. sky2_phy_intr(hw, 1);
  2468. if (status & Y2_IS_PHY_QLNK)
  2469. sky2_qlink_intr(hw);
  2470. while ((idx = sky2_read16(hw, STAT_PUT_IDX)) != hw->st_idx) {
  2471. work_done += sky2_status_intr(hw, work_limit - work_done, idx);
  2472. if (work_done >= work_limit)
  2473. goto done;
  2474. }
  2475. napi_complete_done(napi, work_done);
  2476. sky2_read32(hw, B0_Y2_SP_LISR);
  2477. done:
  2478. return work_done;
  2479. }
  2480. static irqreturn_t sky2_intr(int irq, void *dev_id)
  2481. {
  2482. struct sky2_hw *hw = dev_id;
  2483. u32 status;
  2484. /* Reading this mask interrupts as side effect */
  2485. status = sky2_read32(hw, B0_Y2_SP_ISRC2);
  2486. if (status == 0 || status == ~0) {
  2487. sky2_write32(hw, B0_Y2_SP_ICR, 2);
  2488. return IRQ_NONE;
  2489. }
  2490. prefetch(&hw->st_le[hw->st_idx]);
  2491. napi_schedule(&hw->napi);
  2492. return IRQ_HANDLED;
  2493. }
  2494. #ifdef CONFIG_NET_POLL_CONTROLLER
  2495. static void sky2_netpoll(struct net_device *dev)
  2496. {
  2497. struct sky2_port *sky2 = netdev_priv(dev);
  2498. napi_schedule(&sky2->hw->napi);
  2499. }
  2500. #endif
  2501. /* Chip internal frequency for clock calculations */
  2502. static u32 sky2_mhz(const struct sky2_hw *hw)
  2503. {
  2504. switch (hw->chip_id) {
  2505. case CHIP_ID_YUKON_EC:
  2506. case CHIP_ID_YUKON_EC_U:
  2507. case CHIP_ID_YUKON_EX:
  2508. case CHIP_ID_YUKON_SUPR:
  2509. case CHIP_ID_YUKON_UL_2:
  2510. case CHIP_ID_YUKON_OPT:
  2511. case CHIP_ID_YUKON_PRM:
  2512. case CHIP_ID_YUKON_OP_2:
  2513. return 125;
  2514. case CHIP_ID_YUKON_FE:
  2515. return 100;
  2516. case CHIP_ID_YUKON_FE_P:
  2517. return 50;
  2518. case CHIP_ID_YUKON_XL:
  2519. return 156;
  2520. default:
  2521. BUG();
  2522. }
  2523. }
  2524. static inline u32 sky2_us2clk(const struct sky2_hw *hw, u32 us)
  2525. {
  2526. return sky2_mhz(hw) * us;
  2527. }
  2528. static inline u32 sky2_clk2us(const struct sky2_hw *hw, u32 clk)
  2529. {
  2530. return clk / sky2_mhz(hw);
  2531. }
  2532. static int sky2_init(struct sky2_hw *hw)
  2533. {
  2534. u8 t8;
  2535. /* Enable all clocks and check for bad PCI access */
  2536. sky2_pci_write32(hw, PCI_DEV_REG3, 0);
  2537. sky2_write8(hw, B0_CTST, CS_RST_CLR);
  2538. hw->chip_id = sky2_read8(hw, B2_CHIP_ID);
  2539. hw->chip_rev = (sky2_read8(hw, B2_MAC_CFG) & CFG_CHIP_R_MSK) >> 4;
  2540. switch (hw->chip_id) {
  2541. case CHIP_ID_YUKON_XL:
  2542. hw->flags = SKY2_HW_GIGABIT | SKY2_HW_NEWER_PHY;
  2543. if (hw->chip_rev < CHIP_REV_YU_XL_A2)
  2544. hw->flags |= SKY2_HW_RSS_BROKEN;
  2545. break;
  2546. case CHIP_ID_YUKON_EC_U:
  2547. hw->flags = SKY2_HW_GIGABIT
  2548. | SKY2_HW_NEWER_PHY
  2549. | SKY2_HW_ADV_POWER_CTL;
  2550. break;
  2551. case CHIP_ID_YUKON_EX:
  2552. hw->flags = SKY2_HW_GIGABIT
  2553. | SKY2_HW_NEWER_PHY
  2554. | SKY2_HW_NEW_LE
  2555. | SKY2_HW_ADV_POWER_CTL
  2556. | SKY2_HW_RSS_CHKSUM;
  2557. /* New transmit checksum */
  2558. if (hw->chip_rev != CHIP_REV_YU_EX_B0)
  2559. hw->flags |= SKY2_HW_AUTO_TX_SUM;
  2560. break;
  2561. case CHIP_ID_YUKON_EC:
  2562. /* This rev is really old, and requires untested workarounds */
  2563. if (hw->chip_rev == CHIP_REV_YU_EC_A1) {
  2564. dev_err(&hw->pdev->dev, "unsupported revision Yukon-EC rev A1\n");
  2565. return -EOPNOTSUPP;
  2566. }
  2567. hw->flags = SKY2_HW_GIGABIT | SKY2_HW_RSS_BROKEN;
  2568. break;
  2569. case CHIP_ID_YUKON_FE:
  2570. hw->flags = SKY2_HW_RSS_BROKEN;
  2571. break;
  2572. case CHIP_ID_YUKON_FE_P:
  2573. hw->flags = SKY2_HW_NEWER_PHY
  2574. | SKY2_HW_NEW_LE
  2575. | SKY2_HW_AUTO_TX_SUM
  2576. | SKY2_HW_ADV_POWER_CTL;
  2577. /* The workaround for status conflicts VLAN tag detection. */
  2578. if (hw->chip_rev == CHIP_REV_YU_FE2_A0)
  2579. hw->flags |= SKY2_HW_VLAN_BROKEN | SKY2_HW_RSS_CHKSUM;
  2580. break;
  2581. case CHIP_ID_YUKON_SUPR:
  2582. hw->flags = SKY2_HW_GIGABIT
  2583. | SKY2_HW_NEWER_PHY
  2584. | SKY2_HW_NEW_LE
  2585. | SKY2_HW_AUTO_TX_SUM
  2586. | SKY2_HW_ADV_POWER_CTL;
  2587. if (hw->chip_rev == CHIP_REV_YU_SU_A0)
  2588. hw->flags |= SKY2_HW_RSS_CHKSUM;
  2589. break;
  2590. case CHIP_ID_YUKON_UL_2:
  2591. hw->flags = SKY2_HW_GIGABIT
  2592. | SKY2_HW_ADV_POWER_CTL;
  2593. break;
  2594. case CHIP_ID_YUKON_OPT:
  2595. case CHIP_ID_YUKON_PRM:
  2596. case CHIP_ID_YUKON_OP_2:
  2597. hw->flags = SKY2_HW_GIGABIT
  2598. | SKY2_HW_NEW_LE
  2599. | SKY2_HW_ADV_POWER_CTL;
  2600. break;
  2601. default:
  2602. dev_err(&hw->pdev->dev, "unsupported chip type 0x%x\n",
  2603. hw->chip_id);
  2604. return -EOPNOTSUPP;
  2605. }
  2606. hw->pmd_type = sky2_read8(hw, B2_PMD_TYP);
  2607. if (hw->pmd_type == 'L' || hw->pmd_type == 'S' || hw->pmd_type == 'P')
  2608. hw->flags |= SKY2_HW_FIBRE_PHY;
  2609. hw->ports = 1;
  2610. t8 = sky2_read8(hw, B2_Y2_HW_RES);
  2611. if ((t8 & CFG_DUAL_MAC_MSK) == CFG_DUAL_MAC_MSK) {
  2612. if (!(sky2_read8(hw, B2_Y2_CLK_GATE) & Y2_STATUS_LNK2_INAC))
  2613. ++hw->ports;
  2614. }
  2615. if (sky2_read8(hw, B2_E_0))
  2616. hw->flags |= SKY2_HW_RAM_BUFFER;
  2617. return 0;
  2618. }
  2619. static void sky2_reset(struct sky2_hw *hw)
  2620. {
  2621. struct pci_dev *pdev = hw->pdev;
  2622. u16 status;
  2623. int i;
  2624. u32 hwe_mask = Y2_HWE_ALL_MASK;
  2625. /* disable ASF */
  2626. if (hw->chip_id == CHIP_ID_YUKON_EX
  2627. || hw->chip_id == CHIP_ID_YUKON_SUPR) {
  2628. sky2_write32(hw, CPU_WDOG, 0);
  2629. status = sky2_read16(hw, HCU_CCSR);
  2630. status &= ~(HCU_CCSR_AHB_RST | HCU_CCSR_CPU_RST_MODE |
  2631. HCU_CCSR_UC_STATE_MSK);
  2632. /*
  2633. * CPU clock divider shouldn't be used because
  2634. * - ASF firmware may malfunction
  2635. * - Yukon-Supreme: Parallel FLASH doesn't support divided clocks
  2636. */
  2637. status &= ~HCU_CCSR_CPU_CLK_DIVIDE_MSK;
  2638. sky2_write16(hw, HCU_CCSR, status);
  2639. sky2_write32(hw, CPU_WDOG, 0);
  2640. } else
  2641. sky2_write8(hw, B28_Y2_ASF_STAT_CMD, Y2_ASF_RESET);
  2642. sky2_write16(hw, B0_CTST, Y2_ASF_DISABLE);
  2643. /* do a SW reset */
  2644. sky2_write8(hw, B0_CTST, CS_RST_SET);
  2645. sky2_write8(hw, B0_CTST, CS_RST_CLR);
  2646. /* allow writes to PCI config */
  2647. sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
  2648. /* clear PCI errors, if any */
  2649. status = sky2_pci_read16(hw, PCI_STATUS);
  2650. status |= PCI_STATUS_ERROR_BITS;
  2651. sky2_pci_write16(hw, PCI_STATUS, status);
  2652. sky2_write8(hw, B0_CTST, CS_MRST_CLR);
  2653. if (pci_is_pcie(pdev)) {
  2654. sky2_write32(hw, Y2_CFG_AER + PCI_ERR_UNCOR_STATUS,
  2655. 0xfffffffful);
  2656. /* If error bit is stuck on ignore it */
  2657. if (sky2_read32(hw, B0_HWE_ISRC) & Y2_IS_PCI_EXP)
  2658. dev_info(&pdev->dev, "ignoring stuck error report bit\n");
  2659. else
  2660. hwe_mask |= Y2_IS_PCI_EXP;
  2661. }
  2662. sky2_power_on(hw);
  2663. sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
  2664. for (i = 0; i < hw->ports; i++) {
  2665. sky2_write8(hw, SK_REG(i, GMAC_LINK_CTRL), GMLC_RST_SET);
  2666. sky2_write8(hw, SK_REG(i, GMAC_LINK_CTRL), GMLC_RST_CLR);
  2667. if (hw->chip_id == CHIP_ID_YUKON_EX ||
  2668. hw->chip_id == CHIP_ID_YUKON_SUPR)
  2669. sky2_write16(hw, SK_REG(i, GMAC_CTRL),
  2670. GMC_BYP_MACSECRX_ON | GMC_BYP_MACSECTX_ON
  2671. | GMC_BYP_RETR_ON);
  2672. }
  2673. if (hw->chip_id == CHIP_ID_YUKON_SUPR && hw->chip_rev > CHIP_REV_YU_SU_B0) {
  2674. /* enable MACSec clock gating */
  2675. sky2_pci_write32(hw, PCI_DEV_REG3, P_CLK_MACSEC_DIS);
  2676. }
  2677. if (hw->chip_id == CHIP_ID_YUKON_OPT ||
  2678. hw->chip_id == CHIP_ID_YUKON_PRM ||
  2679. hw->chip_id == CHIP_ID_YUKON_OP_2) {
  2680. u16 reg;
  2681. if (hw->chip_id == CHIP_ID_YUKON_OPT && hw->chip_rev == 0) {
  2682. /* disable PCI-E PHY power down (set PHY reg 0x80, bit 7 */
  2683. sky2_write32(hw, Y2_PEX_PHY_DATA, (0x80UL << 16) | (1 << 7));
  2684. /* set PHY Link Detect Timer to 1.1 second (11x 100ms) */
  2685. reg = 10;
  2686. /* re-enable PEX PM in PEX PHY debug reg. 8 (clear bit 12) */
  2687. sky2_write32(hw, Y2_PEX_PHY_DATA, PEX_DB_ACCESS | (0x08UL << 16));
  2688. } else {
  2689. /* set PHY Link Detect Timer to 0.4 second (4x 100ms) */
  2690. reg = 3;
  2691. }
  2692. reg <<= PSM_CONFIG_REG4_TIMER_PHY_LINK_DETECT_BASE;
  2693. reg |= PSM_CONFIG_REG4_RST_PHY_LINK_DETECT;
  2694. /* reset PHY Link Detect */
  2695. sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
  2696. sky2_pci_write16(hw, PSM_CONFIG_REG4, reg);
  2697. /* check if PSMv2 was running before */
  2698. reg = sky2_pci_read16(hw, PSM_CONFIG_REG3);
  2699. if (reg & PCI_EXP_LNKCTL_ASPMC)
  2700. /* restore the PCIe Link Control register */
  2701. sky2_pci_write16(hw, pdev->pcie_cap + PCI_EXP_LNKCTL,
  2702. reg);
  2703. if (hw->chip_id == CHIP_ID_YUKON_PRM &&
  2704. hw->chip_rev == CHIP_REV_YU_PRM_A0) {
  2705. /* change PHY Interrupt polarity to low active */
  2706. reg = sky2_read16(hw, GPHY_CTRL);
  2707. sky2_write16(hw, GPHY_CTRL, reg | GPC_INTPOL);
  2708. /* adapt HW for low active PHY Interrupt */
  2709. reg = sky2_read16(hw, Y2_CFG_SPC + PCI_LDO_CTRL);
  2710. sky2_write16(hw, Y2_CFG_SPC + PCI_LDO_CTRL, reg | PHY_M_UNDOC1);
  2711. }
  2712. sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
  2713. /* re-enable PEX PM in PEX PHY debug reg. 8 (clear bit 12) */
  2714. sky2_write32(hw, Y2_PEX_PHY_DATA, PEX_DB_ACCESS | (0x08UL << 16));
  2715. }
  2716. /* Clear I2C IRQ noise */
  2717. sky2_write32(hw, B2_I2C_IRQ, 1);
  2718. /* turn off hardware timer (unused) */
  2719. sky2_write8(hw, B2_TI_CTRL, TIM_STOP);
  2720. sky2_write8(hw, B2_TI_CTRL, TIM_CLR_IRQ);
  2721. /* Turn off descriptor polling */
  2722. sky2_write32(hw, B28_DPT_CTRL, DPT_STOP);
  2723. /* Turn off receive timestamp */
  2724. sky2_write8(hw, GMAC_TI_ST_CTRL, GMT_ST_STOP);
  2725. sky2_write8(hw, GMAC_TI_ST_CTRL, GMT_ST_CLR_IRQ);
  2726. /* enable the Tx Arbiters */
  2727. for (i = 0; i < hw->ports; i++)
  2728. sky2_write8(hw, SK_REG(i, TXA_CTRL), TXA_ENA_ARB);
  2729. /* Initialize ram interface */
  2730. for (i = 0; i < hw->ports; i++) {
  2731. sky2_write8(hw, RAM_BUFFER(i, B3_RI_CTRL), RI_RST_CLR);
  2732. sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_R1), SK_RI_TO_53);
  2733. sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_XA1), SK_RI_TO_53);
  2734. sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_XS1), SK_RI_TO_53);
  2735. sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_R1), SK_RI_TO_53);
  2736. sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_XA1), SK_RI_TO_53);
  2737. sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_XS1), SK_RI_TO_53);
  2738. sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_R2), SK_RI_TO_53);
  2739. sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_XA2), SK_RI_TO_53);
  2740. sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_XS2), SK_RI_TO_53);
  2741. sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_R2), SK_RI_TO_53);
  2742. sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_XA2), SK_RI_TO_53);
  2743. sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_XS2), SK_RI_TO_53);
  2744. }
  2745. sky2_write32(hw, B0_HWE_IMSK, hwe_mask);
  2746. for (i = 0; i < hw->ports; i++)
  2747. sky2_gmac_reset(hw, i);
  2748. memset(hw->st_le, 0, hw->st_size * sizeof(struct sky2_status_le));
  2749. hw->st_idx = 0;
  2750. sky2_write32(hw, STAT_CTRL, SC_STAT_RST_SET);
  2751. sky2_write32(hw, STAT_CTRL, SC_STAT_RST_CLR);
  2752. sky2_write32(hw, STAT_LIST_ADDR_LO, hw->st_dma);
  2753. sky2_write32(hw, STAT_LIST_ADDR_HI, (u64) hw->st_dma >> 32);
  2754. /* Set the list last index */
  2755. sky2_write16(hw, STAT_LAST_IDX, hw->st_size - 1);
  2756. sky2_write16(hw, STAT_TX_IDX_TH, 10);
  2757. sky2_write8(hw, STAT_FIFO_WM, 16);
  2758. /* set Status-FIFO ISR watermark */
  2759. if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev == 0)
  2760. sky2_write8(hw, STAT_FIFO_ISR_WM, 4);
  2761. else
  2762. sky2_write8(hw, STAT_FIFO_ISR_WM, 16);
  2763. sky2_write32(hw, STAT_TX_TIMER_INI, sky2_us2clk(hw, 1000));
  2764. sky2_write32(hw, STAT_ISR_TIMER_INI, sky2_us2clk(hw, 20));
  2765. sky2_write32(hw, STAT_LEV_TIMER_INI, sky2_us2clk(hw, 100));
  2766. /* enable status unit */
  2767. sky2_write32(hw, STAT_CTRL, SC_STAT_OP_ON);
  2768. sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_START);
  2769. sky2_write8(hw, STAT_LEV_TIMER_CTRL, TIM_START);
  2770. sky2_write8(hw, STAT_ISR_TIMER_CTRL, TIM_START);
  2771. }
  2772. /* Take device down (offline).
  2773. * Equivalent to doing dev_stop() but this does not
  2774. * inform upper layers of the transition.
  2775. */
  2776. static void sky2_detach(struct net_device *dev)
  2777. {
  2778. if (netif_running(dev)) {
  2779. netif_tx_lock(dev);
  2780. netif_device_detach(dev); /* stop txq */
  2781. netif_tx_unlock(dev);
  2782. sky2_close(dev);
  2783. }
  2784. }
  2785. /* Bring device back after doing sky2_detach */
  2786. static int sky2_reattach(struct net_device *dev)
  2787. {
  2788. int err = 0;
  2789. if (netif_running(dev)) {
  2790. err = sky2_open(dev);
  2791. if (err) {
  2792. netdev_info(dev, "could not restart %d\n", err);
  2793. dev_close(dev);
  2794. } else {
  2795. netif_device_attach(dev);
  2796. sky2_set_multicast(dev);
  2797. }
  2798. }
  2799. return err;
  2800. }
  2801. static void sky2_all_down(struct sky2_hw *hw)
  2802. {
  2803. int i;
  2804. if (hw->flags & SKY2_HW_IRQ_SETUP) {
  2805. sky2_write32(hw, B0_IMSK, 0);
  2806. sky2_read32(hw, B0_IMSK);
  2807. synchronize_irq(hw->pdev->irq);
  2808. napi_disable(&hw->napi);
  2809. }
  2810. for (i = 0; i < hw->ports; i++) {
  2811. struct net_device *dev = hw->dev[i];
  2812. struct sky2_port *sky2 = netdev_priv(dev);
  2813. if (!netif_running(dev))
  2814. continue;
  2815. netif_carrier_off(dev);
  2816. netif_tx_disable(dev);
  2817. sky2_hw_down(sky2);
  2818. }
  2819. }
  2820. static void sky2_all_up(struct sky2_hw *hw)
  2821. {
  2822. u32 imask = Y2_IS_BASE;
  2823. int i;
  2824. for (i = 0; i < hw->ports; i++) {
  2825. struct net_device *dev = hw->dev[i];
  2826. struct sky2_port *sky2 = netdev_priv(dev);
  2827. if (!netif_running(dev))
  2828. continue;
  2829. sky2_hw_up(sky2);
  2830. sky2_set_multicast(dev);
  2831. imask |= portirq_msk[i];
  2832. netif_wake_queue(dev);
  2833. }
  2834. if (hw->flags & SKY2_HW_IRQ_SETUP) {
  2835. sky2_write32(hw, B0_IMSK, imask);
  2836. sky2_read32(hw, B0_IMSK);
  2837. sky2_read32(hw, B0_Y2_SP_LISR);
  2838. napi_enable(&hw->napi);
  2839. }
  2840. }
  2841. static void sky2_restart(struct work_struct *work)
  2842. {
  2843. struct sky2_hw *hw = container_of(work, struct sky2_hw, restart_work);
  2844. rtnl_lock();
  2845. sky2_all_down(hw);
  2846. sky2_reset(hw);
  2847. sky2_all_up(hw);
  2848. rtnl_unlock();
  2849. }
  2850. static inline u8 sky2_wol_supported(const struct sky2_hw *hw)
  2851. {
  2852. return sky2_is_copper(hw) ? (WAKE_PHY | WAKE_MAGIC) : 0;
  2853. }
  2854. static void sky2_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  2855. {
  2856. const struct sky2_port *sky2 = netdev_priv(dev);
  2857. wol->supported = sky2_wol_supported(sky2->hw);
  2858. wol->wolopts = sky2->wol;
  2859. }
  2860. static int sky2_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  2861. {
  2862. struct sky2_port *sky2 = netdev_priv(dev);
  2863. struct sky2_hw *hw = sky2->hw;
  2864. bool enable_wakeup = false;
  2865. int i;
  2866. if ((wol->wolopts & ~sky2_wol_supported(sky2->hw)) ||
  2867. !device_can_wakeup(&hw->pdev->dev))
  2868. return -EOPNOTSUPP;
  2869. sky2->wol = wol->wolopts;
  2870. for (i = 0; i < hw->ports; i++) {
  2871. struct net_device *dev = hw->dev[i];
  2872. struct sky2_port *sky2 = netdev_priv(dev);
  2873. if (sky2->wol)
  2874. enable_wakeup = true;
  2875. }
  2876. device_set_wakeup_enable(&hw->pdev->dev, enable_wakeup);
  2877. return 0;
  2878. }
  2879. static u32 sky2_supported_modes(const struct sky2_hw *hw)
  2880. {
  2881. if (sky2_is_copper(hw)) {
  2882. u32 modes = SUPPORTED_10baseT_Half
  2883. | SUPPORTED_10baseT_Full
  2884. | SUPPORTED_100baseT_Half
  2885. | SUPPORTED_100baseT_Full;
  2886. if (hw->flags & SKY2_HW_GIGABIT)
  2887. modes |= SUPPORTED_1000baseT_Half
  2888. | SUPPORTED_1000baseT_Full;
  2889. return modes;
  2890. } else
  2891. return SUPPORTED_1000baseT_Half
  2892. | SUPPORTED_1000baseT_Full;
  2893. }
  2894. static int sky2_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
  2895. {
  2896. struct sky2_port *sky2 = netdev_priv(dev);
  2897. struct sky2_hw *hw = sky2->hw;
  2898. ecmd->transceiver = XCVR_INTERNAL;
  2899. ecmd->supported = sky2_supported_modes(hw);
  2900. ecmd->phy_address = PHY_ADDR_MARV;
  2901. if (sky2_is_copper(hw)) {
  2902. ecmd->port = PORT_TP;
  2903. ethtool_cmd_speed_set(ecmd, sky2->speed);
  2904. ecmd->supported |= SUPPORTED_Autoneg | SUPPORTED_TP;
  2905. } else {
  2906. ethtool_cmd_speed_set(ecmd, SPEED_1000);
  2907. ecmd->port = PORT_FIBRE;
  2908. ecmd->supported |= SUPPORTED_Autoneg | SUPPORTED_FIBRE;
  2909. }
  2910. ecmd->advertising = sky2->advertising;
  2911. ecmd->autoneg = (sky2->flags & SKY2_FLAG_AUTO_SPEED)
  2912. ? AUTONEG_ENABLE : AUTONEG_DISABLE;
  2913. ecmd->duplex = sky2->duplex;
  2914. return 0;
  2915. }
  2916. static int sky2_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
  2917. {
  2918. struct sky2_port *sky2 = netdev_priv(dev);
  2919. const struct sky2_hw *hw = sky2->hw;
  2920. u32 supported = sky2_supported_modes(hw);
  2921. if (ecmd->autoneg == AUTONEG_ENABLE) {
  2922. if (ecmd->advertising & ~supported)
  2923. return -EINVAL;
  2924. if (sky2_is_copper(hw))
  2925. sky2->advertising = ecmd->advertising |
  2926. ADVERTISED_TP |
  2927. ADVERTISED_Autoneg;
  2928. else
  2929. sky2->advertising = ecmd->advertising |
  2930. ADVERTISED_FIBRE |
  2931. ADVERTISED_Autoneg;
  2932. sky2->flags |= SKY2_FLAG_AUTO_SPEED;
  2933. sky2->duplex = -1;
  2934. sky2->speed = -1;
  2935. } else {
  2936. u32 setting;
  2937. u32 speed = ethtool_cmd_speed(ecmd);
  2938. switch (speed) {
  2939. case SPEED_1000:
  2940. if (ecmd->duplex == DUPLEX_FULL)
  2941. setting = SUPPORTED_1000baseT_Full;
  2942. else if (ecmd->duplex == DUPLEX_HALF)
  2943. setting = SUPPORTED_1000baseT_Half;
  2944. else
  2945. return -EINVAL;
  2946. break;
  2947. case SPEED_100:
  2948. if (ecmd->duplex == DUPLEX_FULL)
  2949. setting = SUPPORTED_100baseT_Full;
  2950. else if (ecmd->duplex == DUPLEX_HALF)
  2951. setting = SUPPORTED_100baseT_Half;
  2952. else
  2953. return -EINVAL;
  2954. break;
  2955. case SPEED_10:
  2956. if (ecmd->duplex == DUPLEX_FULL)
  2957. setting = SUPPORTED_10baseT_Full;
  2958. else if (ecmd->duplex == DUPLEX_HALF)
  2959. setting = SUPPORTED_10baseT_Half;
  2960. else
  2961. return -EINVAL;
  2962. break;
  2963. default:
  2964. return -EINVAL;
  2965. }
  2966. if ((setting & supported) == 0)
  2967. return -EINVAL;
  2968. sky2->speed = speed;
  2969. sky2->duplex = ecmd->duplex;
  2970. sky2->flags &= ~SKY2_FLAG_AUTO_SPEED;
  2971. }
  2972. if (netif_running(dev)) {
  2973. sky2_phy_reinit(sky2);
  2974. sky2_set_multicast(dev);
  2975. }
  2976. return 0;
  2977. }
  2978. static void sky2_get_drvinfo(struct net_device *dev,
  2979. struct ethtool_drvinfo *info)
  2980. {
  2981. struct sky2_port *sky2 = netdev_priv(dev);
  2982. strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
  2983. strlcpy(info->version, DRV_VERSION, sizeof(info->version));
  2984. strlcpy(info->bus_info, pci_name(sky2->hw->pdev),
  2985. sizeof(info->bus_info));
  2986. }
  2987. static const struct sky2_stat {
  2988. char name[ETH_GSTRING_LEN];
  2989. u16 offset;
  2990. } sky2_stats[] = {
  2991. { "tx_bytes", GM_TXO_OK_HI },
  2992. { "rx_bytes", GM_RXO_OK_HI },
  2993. { "tx_broadcast", GM_TXF_BC_OK },
  2994. { "rx_broadcast", GM_RXF_BC_OK },
  2995. { "tx_multicast", GM_TXF_MC_OK },
  2996. { "rx_multicast", GM_RXF_MC_OK },
  2997. { "tx_unicast", GM_TXF_UC_OK },
  2998. { "rx_unicast", GM_RXF_UC_OK },
  2999. { "tx_mac_pause", GM_TXF_MPAUSE },
  3000. { "rx_mac_pause", GM_RXF_MPAUSE },
  3001. { "collisions", GM_TXF_COL },
  3002. { "late_collision",GM_TXF_LAT_COL },
  3003. { "aborted", GM_TXF_ABO_COL },
  3004. { "single_collisions", GM_TXF_SNG_COL },
  3005. { "multi_collisions", GM_TXF_MUL_COL },
  3006. { "rx_short", GM_RXF_SHT },
  3007. { "rx_runt", GM_RXE_FRAG },
  3008. { "rx_64_byte_packets", GM_RXF_64B },
  3009. { "rx_65_to_127_byte_packets", GM_RXF_127B },
  3010. { "rx_128_to_255_byte_packets", GM_RXF_255B },
  3011. { "rx_256_to_511_byte_packets", GM_RXF_511B },
  3012. { "rx_512_to_1023_byte_packets", GM_RXF_1023B },
  3013. { "rx_1024_to_1518_byte_packets", GM_RXF_1518B },
  3014. { "rx_1518_to_max_byte_packets", GM_RXF_MAX_SZ },
  3015. { "rx_too_long", GM_RXF_LNG_ERR },
  3016. { "rx_fifo_overflow", GM_RXE_FIFO_OV },
  3017. { "rx_jabber", GM_RXF_JAB_PKT },
  3018. { "rx_fcs_error", GM_RXF_FCS_ERR },
  3019. { "tx_64_byte_packets", GM_TXF_64B },
  3020. { "tx_65_to_127_byte_packets", GM_TXF_127B },
  3021. { "tx_128_to_255_byte_packets", GM_TXF_255B },
  3022. { "tx_256_to_511_byte_packets", GM_TXF_511B },
  3023. { "tx_512_to_1023_byte_packets", GM_TXF_1023B },
  3024. { "tx_1024_to_1518_byte_packets", GM_TXF_1518B },
  3025. { "tx_1519_to_max_byte_packets", GM_TXF_MAX_SZ },
  3026. { "tx_fifo_underrun", GM_TXE_FIFO_UR },
  3027. };
  3028. static u32 sky2_get_msglevel(struct net_device *netdev)
  3029. {
  3030. struct sky2_port *sky2 = netdev_priv(netdev);
  3031. return sky2->msg_enable;
  3032. }
  3033. static int sky2_nway_reset(struct net_device *dev)
  3034. {
  3035. struct sky2_port *sky2 = netdev_priv(dev);
  3036. if (!netif_running(dev) || !(sky2->flags & SKY2_FLAG_AUTO_SPEED))
  3037. return -EINVAL;
  3038. sky2_phy_reinit(sky2);
  3039. sky2_set_multicast(dev);
  3040. return 0;
  3041. }
  3042. static void sky2_phy_stats(struct sky2_port *sky2, u64 * data, unsigned count)
  3043. {
  3044. struct sky2_hw *hw = sky2->hw;
  3045. unsigned port = sky2->port;
  3046. int i;
  3047. data[0] = get_stats64(hw, port, GM_TXO_OK_LO);
  3048. data[1] = get_stats64(hw, port, GM_RXO_OK_LO);
  3049. for (i = 2; i < count; i++)
  3050. data[i] = get_stats32(hw, port, sky2_stats[i].offset);
  3051. }
  3052. static void sky2_set_msglevel(struct net_device *netdev, u32 value)
  3053. {
  3054. struct sky2_port *sky2 = netdev_priv(netdev);
  3055. sky2->msg_enable = value;
  3056. }
  3057. static int sky2_get_sset_count(struct net_device *dev, int sset)
  3058. {
  3059. switch (sset) {
  3060. case ETH_SS_STATS:
  3061. return ARRAY_SIZE(sky2_stats);
  3062. default:
  3063. return -EOPNOTSUPP;
  3064. }
  3065. }
  3066. static void sky2_get_ethtool_stats(struct net_device *dev,
  3067. struct ethtool_stats *stats, u64 * data)
  3068. {
  3069. struct sky2_port *sky2 = netdev_priv(dev);
  3070. sky2_phy_stats(sky2, data, ARRAY_SIZE(sky2_stats));
  3071. }
  3072. static void sky2_get_strings(struct net_device *dev, u32 stringset, u8 * data)
  3073. {
  3074. int i;
  3075. switch (stringset) {
  3076. case ETH_SS_STATS:
  3077. for (i = 0; i < ARRAY_SIZE(sky2_stats); i++)
  3078. memcpy(data + i * ETH_GSTRING_LEN,
  3079. sky2_stats[i].name, ETH_GSTRING_LEN);
  3080. break;
  3081. }
  3082. }
  3083. static int sky2_set_mac_address(struct net_device *dev, void *p)
  3084. {
  3085. struct sky2_port *sky2 = netdev_priv(dev);
  3086. struct sky2_hw *hw = sky2->hw;
  3087. unsigned port = sky2->port;
  3088. const struct sockaddr *addr = p;
  3089. if (!is_valid_ether_addr(addr->sa_data))
  3090. return -EADDRNOTAVAIL;
  3091. memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
  3092. memcpy_toio(hw->regs + B2_MAC_1 + port * 8,
  3093. dev->dev_addr, ETH_ALEN);
  3094. memcpy_toio(hw->regs + B2_MAC_2 + port * 8,
  3095. dev->dev_addr, ETH_ALEN);
  3096. /* virtual address for data */
  3097. gma_set_addr(hw, port, GM_SRC_ADDR_2L, dev->dev_addr);
  3098. /* physical address: used for pause frames */
  3099. gma_set_addr(hw, port, GM_SRC_ADDR_1L, dev->dev_addr);
  3100. return 0;
  3101. }
  3102. static inline void sky2_add_filter(u8 filter[8], const u8 *addr)
  3103. {
  3104. u32 bit;
  3105. bit = ether_crc(ETH_ALEN, addr) & 63;
  3106. filter[bit >> 3] |= 1 << (bit & 7);
  3107. }
  3108. static void sky2_set_multicast(struct net_device *dev)
  3109. {
  3110. struct sky2_port *sky2 = netdev_priv(dev);
  3111. struct sky2_hw *hw = sky2->hw;
  3112. unsigned port = sky2->port;
  3113. struct netdev_hw_addr *ha;
  3114. u16 reg;
  3115. u8 filter[8];
  3116. int rx_pause;
  3117. static const u8 pause_mc_addr[ETH_ALEN] = { 0x1, 0x80, 0xc2, 0x0, 0x0, 0x1 };
  3118. rx_pause = (sky2->flow_status == FC_RX || sky2->flow_status == FC_BOTH);
  3119. memset(filter, 0, sizeof(filter));
  3120. reg = gma_read16(hw, port, GM_RX_CTRL);
  3121. reg |= GM_RXCR_UCF_ENA;
  3122. if (dev->flags & IFF_PROMISC) /* promiscuous */
  3123. reg &= ~(GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA);
  3124. else if (dev->flags & IFF_ALLMULTI)
  3125. memset(filter, 0xff, sizeof(filter));
  3126. else if (netdev_mc_empty(dev) && !rx_pause)
  3127. reg &= ~GM_RXCR_MCF_ENA;
  3128. else {
  3129. reg |= GM_RXCR_MCF_ENA;
  3130. if (rx_pause)
  3131. sky2_add_filter(filter, pause_mc_addr);
  3132. netdev_for_each_mc_addr(ha, dev)
  3133. sky2_add_filter(filter, ha->addr);
  3134. }
  3135. gma_write16(hw, port, GM_MC_ADDR_H1,
  3136. (u16) filter[0] | ((u16) filter[1] << 8));
  3137. gma_write16(hw, port, GM_MC_ADDR_H2,
  3138. (u16) filter[2] | ((u16) filter[3] << 8));
  3139. gma_write16(hw, port, GM_MC_ADDR_H3,
  3140. (u16) filter[4] | ((u16) filter[5] << 8));
  3141. gma_write16(hw, port, GM_MC_ADDR_H4,
  3142. (u16) filter[6] | ((u16) filter[7] << 8));
  3143. gma_write16(hw, port, GM_RX_CTRL, reg);
  3144. }
  3145. static struct rtnl_link_stats64 *sky2_get_stats(struct net_device *dev,
  3146. struct rtnl_link_stats64 *stats)
  3147. {
  3148. struct sky2_port *sky2 = netdev_priv(dev);
  3149. struct sky2_hw *hw = sky2->hw;
  3150. unsigned port = sky2->port;
  3151. unsigned int start;
  3152. u64 _bytes, _packets;
  3153. do {
  3154. start = u64_stats_fetch_begin_irq(&sky2->rx_stats.syncp);
  3155. _bytes = sky2->rx_stats.bytes;
  3156. _packets = sky2->rx_stats.packets;
  3157. } while (u64_stats_fetch_retry_irq(&sky2->rx_stats.syncp, start));
  3158. stats->rx_packets = _packets;
  3159. stats->rx_bytes = _bytes;
  3160. do {
  3161. start = u64_stats_fetch_begin_irq(&sky2->tx_stats.syncp);
  3162. _bytes = sky2->tx_stats.bytes;
  3163. _packets = sky2->tx_stats.packets;
  3164. } while (u64_stats_fetch_retry_irq(&sky2->tx_stats.syncp, start));
  3165. stats->tx_packets = _packets;
  3166. stats->tx_bytes = _bytes;
  3167. stats->multicast = get_stats32(hw, port, GM_RXF_MC_OK)
  3168. + get_stats32(hw, port, GM_RXF_BC_OK);
  3169. stats->collisions = get_stats32(hw, port, GM_TXF_COL);
  3170. stats->rx_length_errors = get_stats32(hw, port, GM_RXF_LNG_ERR);
  3171. stats->rx_crc_errors = get_stats32(hw, port, GM_RXF_FCS_ERR);
  3172. stats->rx_frame_errors = get_stats32(hw, port, GM_RXF_SHT)
  3173. + get_stats32(hw, port, GM_RXE_FRAG);
  3174. stats->rx_over_errors = get_stats32(hw, port, GM_RXE_FIFO_OV);
  3175. stats->rx_dropped = dev->stats.rx_dropped;
  3176. stats->rx_fifo_errors = dev->stats.rx_fifo_errors;
  3177. stats->tx_fifo_errors = dev->stats.tx_fifo_errors;
  3178. return stats;
  3179. }
  3180. /* Can have one global because blinking is controlled by
  3181. * ethtool and that is always under RTNL mutex
  3182. */
  3183. static void sky2_led(struct sky2_port *sky2, enum led_mode mode)
  3184. {
  3185. struct sky2_hw *hw = sky2->hw;
  3186. unsigned port = sky2->port;
  3187. spin_lock_bh(&sky2->phy_lock);
  3188. if (hw->chip_id == CHIP_ID_YUKON_EC_U ||
  3189. hw->chip_id == CHIP_ID_YUKON_EX ||
  3190. hw->chip_id == CHIP_ID_YUKON_SUPR) {
  3191. u16 pg;
  3192. pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR);
  3193. gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 3);
  3194. switch (mode) {
  3195. case MO_LED_OFF:
  3196. gm_phy_write(hw, port, PHY_MARV_PHY_CTRL,
  3197. PHY_M_LEDC_LOS_CTRL(8) |
  3198. PHY_M_LEDC_INIT_CTRL(8) |
  3199. PHY_M_LEDC_STA1_CTRL(8) |
  3200. PHY_M_LEDC_STA0_CTRL(8));
  3201. break;
  3202. case MO_LED_ON:
  3203. gm_phy_write(hw, port, PHY_MARV_PHY_CTRL,
  3204. PHY_M_LEDC_LOS_CTRL(9) |
  3205. PHY_M_LEDC_INIT_CTRL(9) |
  3206. PHY_M_LEDC_STA1_CTRL(9) |
  3207. PHY_M_LEDC_STA0_CTRL(9));
  3208. break;
  3209. case MO_LED_BLINK:
  3210. gm_phy_write(hw, port, PHY_MARV_PHY_CTRL,
  3211. PHY_M_LEDC_LOS_CTRL(0xa) |
  3212. PHY_M_LEDC_INIT_CTRL(0xa) |
  3213. PHY_M_LEDC_STA1_CTRL(0xa) |
  3214. PHY_M_LEDC_STA0_CTRL(0xa));
  3215. break;
  3216. case MO_LED_NORM:
  3217. gm_phy_write(hw, port, PHY_MARV_PHY_CTRL,
  3218. PHY_M_LEDC_LOS_CTRL(1) |
  3219. PHY_M_LEDC_INIT_CTRL(8) |
  3220. PHY_M_LEDC_STA1_CTRL(7) |
  3221. PHY_M_LEDC_STA0_CTRL(7));
  3222. }
  3223. gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg);
  3224. } else
  3225. gm_phy_write(hw, port, PHY_MARV_LED_OVER,
  3226. PHY_M_LED_MO_DUP(mode) |
  3227. PHY_M_LED_MO_10(mode) |
  3228. PHY_M_LED_MO_100(mode) |
  3229. PHY_M_LED_MO_1000(mode) |
  3230. PHY_M_LED_MO_RX(mode) |
  3231. PHY_M_LED_MO_TX(mode));
  3232. spin_unlock_bh(&sky2->phy_lock);
  3233. }
  3234. /* blink LED's for finding board */
  3235. static int sky2_set_phys_id(struct net_device *dev,
  3236. enum ethtool_phys_id_state state)
  3237. {
  3238. struct sky2_port *sky2 = netdev_priv(dev);
  3239. switch (state) {
  3240. case ETHTOOL_ID_ACTIVE:
  3241. return 1; /* cycle on/off once per second */
  3242. case ETHTOOL_ID_INACTIVE:
  3243. sky2_led(sky2, MO_LED_NORM);
  3244. break;
  3245. case ETHTOOL_ID_ON:
  3246. sky2_led(sky2, MO_LED_ON);
  3247. break;
  3248. case ETHTOOL_ID_OFF:
  3249. sky2_led(sky2, MO_LED_OFF);
  3250. break;
  3251. }
  3252. return 0;
  3253. }
  3254. static void sky2_get_pauseparam(struct net_device *dev,
  3255. struct ethtool_pauseparam *ecmd)
  3256. {
  3257. struct sky2_port *sky2 = netdev_priv(dev);
  3258. switch (sky2->flow_mode) {
  3259. case FC_NONE:
  3260. ecmd->tx_pause = ecmd->rx_pause = 0;
  3261. break;
  3262. case FC_TX:
  3263. ecmd->tx_pause = 1, ecmd->rx_pause = 0;
  3264. break;
  3265. case FC_RX:
  3266. ecmd->tx_pause = 0, ecmd->rx_pause = 1;
  3267. break;
  3268. case FC_BOTH:
  3269. ecmd->tx_pause = ecmd->rx_pause = 1;
  3270. }
  3271. ecmd->autoneg = (sky2->flags & SKY2_FLAG_AUTO_PAUSE)
  3272. ? AUTONEG_ENABLE : AUTONEG_DISABLE;
  3273. }
  3274. static int sky2_set_pauseparam(struct net_device *dev,
  3275. struct ethtool_pauseparam *ecmd)
  3276. {
  3277. struct sky2_port *sky2 = netdev_priv(dev);
  3278. if (ecmd->autoneg == AUTONEG_ENABLE)
  3279. sky2->flags |= SKY2_FLAG_AUTO_PAUSE;
  3280. else
  3281. sky2->flags &= ~SKY2_FLAG_AUTO_PAUSE;
  3282. sky2->flow_mode = sky2_flow(ecmd->rx_pause, ecmd->tx_pause);
  3283. if (netif_running(dev))
  3284. sky2_phy_reinit(sky2);
  3285. return 0;
  3286. }
  3287. static int sky2_get_coalesce(struct net_device *dev,
  3288. struct ethtool_coalesce *ecmd)
  3289. {
  3290. struct sky2_port *sky2 = netdev_priv(dev);
  3291. struct sky2_hw *hw = sky2->hw;
  3292. if (sky2_read8(hw, STAT_TX_TIMER_CTRL) == TIM_STOP)
  3293. ecmd->tx_coalesce_usecs = 0;
  3294. else {
  3295. u32 clks = sky2_read32(hw, STAT_TX_TIMER_INI);
  3296. ecmd->tx_coalesce_usecs = sky2_clk2us(hw, clks);
  3297. }
  3298. ecmd->tx_max_coalesced_frames = sky2_read16(hw, STAT_TX_IDX_TH);
  3299. if (sky2_read8(hw, STAT_LEV_TIMER_CTRL) == TIM_STOP)
  3300. ecmd->rx_coalesce_usecs = 0;
  3301. else {
  3302. u32 clks = sky2_read32(hw, STAT_LEV_TIMER_INI);
  3303. ecmd->rx_coalesce_usecs = sky2_clk2us(hw, clks);
  3304. }
  3305. ecmd->rx_max_coalesced_frames = sky2_read8(hw, STAT_FIFO_WM);
  3306. if (sky2_read8(hw, STAT_ISR_TIMER_CTRL) == TIM_STOP)
  3307. ecmd->rx_coalesce_usecs_irq = 0;
  3308. else {
  3309. u32 clks = sky2_read32(hw, STAT_ISR_TIMER_INI);
  3310. ecmd->rx_coalesce_usecs_irq = sky2_clk2us(hw, clks);
  3311. }
  3312. ecmd->rx_max_coalesced_frames_irq = sky2_read8(hw, STAT_FIFO_ISR_WM);
  3313. return 0;
  3314. }
  3315. /* Note: this affect both ports */
  3316. static int sky2_set_coalesce(struct net_device *dev,
  3317. struct ethtool_coalesce *ecmd)
  3318. {
  3319. struct sky2_port *sky2 = netdev_priv(dev);
  3320. struct sky2_hw *hw = sky2->hw;
  3321. const u32 tmax = sky2_clk2us(hw, 0x0ffffff);
  3322. if (ecmd->tx_coalesce_usecs > tmax ||
  3323. ecmd->rx_coalesce_usecs > tmax ||
  3324. ecmd->rx_coalesce_usecs_irq > tmax)
  3325. return -EINVAL;
  3326. if (ecmd->tx_max_coalesced_frames >= sky2->tx_ring_size-1)
  3327. return -EINVAL;
  3328. if (ecmd->rx_max_coalesced_frames > RX_MAX_PENDING)
  3329. return -EINVAL;
  3330. if (ecmd->rx_max_coalesced_frames_irq > RX_MAX_PENDING)
  3331. return -EINVAL;
  3332. if (ecmd->tx_coalesce_usecs == 0)
  3333. sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_STOP);
  3334. else {
  3335. sky2_write32(hw, STAT_TX_TIMER_INI,
  3336. sky2_us2clk(hw, ecmd->tx_coalesce_usecs));
  3337. sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_START);
  3338. }
  3339. sky2_write16(hw, STAT_TX_IDX_TH, ecmd->tx_max_coalesced_frames);
  3340. if (ecmd->rx_coalesce_usecs == 0)
  3341. sky2_write8(hw, STAT_LEV_TIMER_CTRL, TIM_STOP);
  3342. else {
  3343. sky2_write32(hw, STAT_LEV_TIMER_INI,
  3344. sky2_us2clk(hw, ecmd->rx_coalesce_usecs));
  3345. sky2_write8(hw, STAT_LEV_TIMER_CTRL, TIM_START);
  3346. }
  3347. sky2_write8(hw, STAT_FIFO_WM, ecmd->rx_max_coalesced_frames);
  3348. if (ecmd->rx_coalesce_usecs_irq == 0)
  3349. sky2_write8(hw, STAT_ISR_TIMER_CTRL, TIM_STOP);
  3350. else {
  3351. sky2_write32(hw, STAT_ISR_TIMER_INI,
  3352. sky2_us2clk(hw, ecmd->rx_coalesce_usecs_irq));
  3353. sky2_write8(hw, STAT_ISR_TIMER_CTRL, TIM_START);
  3354. }
  3355. sky2_write8(hw, STAT_FIFO_ISR_WM, ecmd->rx_max_coalesced_frames_irq);
  3356. return 0;
  3357. }
  3358. /*
  3359. * Hardware is limited to min of 128 and max of 2048 for ring size
  3360. * and rounded up to next power of two
  3361. * to avoid division in modulus calclation
  3362. */
  3363. static unsigned long roundup_ring_size(unsigned long pending)
  3364. {
  3365. return max(128ul, roundup_pow_of_two(pending+1));
  3366. }
  3367. static void sky2_get_ringparam(struct net_device *dev,
  3368. struct ethtool_ringparam *ering)
  3369. {
  3370. struct sky2_port *sky2 = netdev_priv(dev);
  3371. ering->rx_max_pending = RX_MAX_PENDING;
  3372. ering->tx_max_pending = TX_MAX_PENDING;
  3373. ering->rx_pending = sky2->rx_pending;
  3374. ering->tx_pending = sky2->tx_pending;
  3375. }
  3376. static int sky2_set_ringparam(struct net_device *dev,
  3377. struct ethtool_ringparam *ering)
  3378. {
  3379. struct sky2_port *sky2 = netdev_priv(dev);
  3380. if (ering->rx_pending > RX_MAX_PENDING ||
  3381. ering->rx_pending < 8 ||
  3382. ering->tx_pending < TX_MIN_PENDING ||
  3383. ering->tx_pending > TX_MAX_PENDING)
  3384. return -EINVAL;
  3385. sky2_detach(dev);
  3386. sky2->rx_pending = ering->rx_pending;
  3387. sky2->tx_pending = ering->tx_pending;
  3388. sky2->tx_ring_size = roundup_ring_size(sky2->tx_pending);
  3389. return sky2_reattach(dev);
  3390. }
  3391. static int sky2_get_regs_len(struct net_device *dev)
  3392. {
  3393. return 0x4000;
  3394. }
  3395. static int sky2_reg_access_ok(struct sky2_hw *hw, unsigned int b)
  3396. {
  3397. /* This complicated switch statement is to make sure and
  3398. * only access regions that are unreserved.
  3399. * Some blocks are only valid on dual port cards.
  3400. */
  3401. switch (b) {
  3402. /* second port */
  3403. case 5: /* Tx Arbiter 2 */
  3404. case 9: /* RX2 */
  3405. case 14 ... 15: /* TX2 */
  3406. case 17: case 19: /* Ram Buffer 2 */
  3407. case 22 ... 23: /* Tx Ram Buffer 2 */
  3408. case 25: /* Rx MAC Fifo 1 */
  3409. case 27: /* Tx MAC Fifo 2 */
  3410. case 31: /* GPHY 2 */
  3411. case 40 ... 47: /* Pattern Ram 2 */
  3412. case 52: case 54: /* TCP Segmentation 2 */
  3413. case 112 ... 116: /* GMAC 2 */
  3414. return hw->ports > 1;
  3415. case 0: /* Control */
  3416. case 2: /* Mac address */
  3417. case 4: /* Tx Arbiter 1 */
  3418. case 7: /* PCI express reg */
  3419. case 8: /* RX1 */
  3420. case 12 ... 13: /* TX1 */
  3421. case 16: case 18:/* Rx Ram Buffer 1 */
  3422. case 20 ... 21: /* Tx Ram Buffer 1 */
  3423. case 24: /* Rx MAC Fifo 1 */
  3424. case 26: /* Tx MAC Fifo 1 */
  3425. case 28 ... 29: /* Descriptor and status unit */
  3426. case 30: /* GPHY 1*/
  3427. case 32 ... 39: /* Pattern Ram 1 */
  3428. case 48: case 50: /* TCP Segmentation 1 */
  3429. case 56 ... 60: /* PCI space */
  3430. case 80 ... 84: /* GMAC 1 */
  3431. return 1;
  3432. default:
  3433. return 0;
  3434. }
  3435. }
  3436. /*
  3437. * Returns copy of control register region
  3438. * Note: ethtool_get_regs always provides full size (16k) buffer
  3439. */
  3440. static void sky2_get_regs(struct net_device *dev, struct ethtool_regs *regs,
  3441. void *p)
  3442. {
  3443. const struct sky2_port *sky2 = netdev_priv(dev);
  3444. const void __iomem *io = sky2->hw->regs;
  3445. unsigned int b;
  3446. regs->version = 1;
  3447. for (b = 0; b < 128; b++) {
  3448. /* skip poisonous diagnostic ram region in block 3 */
  3449. if (b == 3)
  3450. memcpy_fromio(p + 0x10, io + 0x10, 128 - 0x10);
  3451. else if (sky2_reg_access_ok(sky2->hw, b))
  3452. memcpy_fromio(p, io, 128);
  3453. else
  3454. memset(p, 0, 128);
  3455. p += 128;
  3456. io += 128;
  3457. }
  3458. }
  3459. static int sky2_get_eeprom_len(struct net_device *dev)
  3460. {
  3461. struct sky2_port *sky2 = netdev_priv(dev);
  3462. struct sky2_hw *hw = sky2->hw;
  3463. u16 reg2;
  3464. reg2 = sky2_pci_read16(hw, PCI_DEV_REG2);
  3465. return 1 << ( ((reg2 & PCI_VPD_ROM_SZ) >> 14) + 8);
  3466. }
  3467. static int sky2_vpd_wait(const struct sky2_hw *hw, int cap, u16 busy)
  3468. {
  3469. unsigned long start = jiffies;
  3470. while ( (sky2_pci_read16(hw, cap + PCI_VPD_ADDR) & PCI_VPD_ADDR_F) == busy) {
  3471. /* Can take up to 10.6 ms for write */
  3472. if (time_after(jiffies, start + HZ/4)) {
  3473. dev_err(&hw->pdev->dev, "VPD cycle timed out\n");
  3474. return -ETIMEDOUT;
  3475. }
  3476. mdelay(1);
  3477. }
  3478. return 0;
  3479. }
  3480. static int sky2_vpd_read(struct sky2_hw *hw, int cap, void *data,
  3481. u16 offset, size_t length)
  3482. {
  3483. int rc = 0;
  3484. while (length > 0) {
  3485. u32 val;
  3486. sky2_pci_write16(hw, cap + PCI_VPD_ADDR, offset);
  3487. rc = sky2_vpd_wait(hw, cap, 0);
  3488. if (rc)
  3489. break;
  3490. val = sky2_pci_read32(hw, cap + PCI_VPD_DATA);
  3491. memcpy(data, &val, min(sizeof(val), length));
  3492. offset += sizeof(u32);
  3493. data += sizeof(u32);
  3494. length -= sizeof(u32);
  3495. }
  3496. return rc;
  3497. }
  3498. static int sky2_vpd_write(struct sky2_hw *hw, int cap, const void *data,
  3499. u16 offset, unsigned int length)
  3500. {
  3501. unsigned int i;
  3502. int rc = 0;
  3503. for (i = 0; i < length; i += sizeof(u32)) {
  3504. u32 val = *(u32 *)(data + i);
  3505. sky2_pci_write32(hw, cap + PCI_VPD_DATA, val);
  3506. sky2_pci_write32(hw, cap + PCI_VPD_ADDR, offset | PCI_VPD_ADDR_F);
  3507. rc = sky2_vpd_wait(hw, cap, PCI_VPD_ADDR_F);
  3508. if (rc)
  3509. break;
  3510. }
  3511. return rc;
  3512. }
  3513. static int sky2_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
  3514. u8 *data)
  3515. {
  3516. struct sky2_port *sky2 = netdev_priv(dev);
  3517. int cap = pci_find_capability(sky2->hw->pdev, PCI_CAP_ID_VPD);
  3518. if (!cap)
  3519. return -EINVAL;
  3520. eeprom->magic = SKY2_EEPROM_MAGIC;
  3521. return sky2_vpd_read(sky2->hw, cap, data, eeprom->offset, eeprom->len);
  3522. }
  3523. static int sky2_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
  3524. u8 *data)
  3525. {
  3526. struct sky2_port *sky2 = netdev_priv(dev);
  3527. int cap = pci_find_capability(sky2->hw->pdev, PCI_CAP_ID_VPD);
  3528. if (!cap)
  3529. return -EINVAL;
  3530. if (eeprom->magic != SKY2_EEPROM_MAGIC)
  3531. return -EINVAL;
  3532. /* Partial writes not supported */
  3533. if ((eeprom->offset & 3) || (eeprom->len & 3))
  3534. return -EINVAL;
  3535. return sky2_vpd_write(sky2->hw, cap, data, eeprom->offset, eeprom->len);
  3536. }
  3537. static netdev_features_t sky2_fix_features(struct net_device *dev,
  3538. netdev_features_t features)
  3539. {
  3540. const struct sky2_port *sky2 = netdev_priv(dev);
  3541. const struct sky2_hw *hw = sky2->hw;
  3542. /* In order to do Jumbo packets on these chips, need to turn off the
  3543. * transmit store/forward. Therefore checksum offload won't work.
  3544. */
  3545. if (dev->mtu > ETH_DATA_LEN && hw->chip_id == CHIP_ID_YUKON_EC_U) {
  3546. netdev_info(dev, "checksum offload not possible with jumbo frames\n");
  3547. features &= ~(NETIF_F_TSO | NETIF_F_SG | NETIF_F_CSUM_MASK);
  3548. }
  3549. /* Some hardware requires receive checksum for RSS to work. */
  3550. if ( (features & NETIF_F_RXHASH) &&
  3551. !(features & NETIF_F_RXCSUM) &&
  3552. (sky2->hw->flags & SKY2_HW_RSS_CHKSUM)) {
  3553. netdev_info(dev, "receive hashing forces receive checksum\n");
  3554. features |= NETIF_F_RXCSUM;
  3555. }
  3556. return features;
  3557. }
  3558. static int sky2_set_features(struct net_device *dev, netdev_features_t features)
  3559. {
  3560. struct sky2_port *sky2 = netdev_priv(dev);
  3561. netdev_features_t changed = dev->features ^ features;
  3562. if ((changed & NETIF_F_RXCSUM) &&
  3563. !(sky2->hw->flags & SKY2_HW_NEW_LE)) {
  3564. sky2_write32(sky2->hw,
  3565. Q_ADDR(rxqaddr[sky2->port], Q_CSR),
  3566. (features & NETIF_F_RXCSUM)
  3567. ? BMU_ENA_RX_CHKSUM : BMU_DIS_RX_CHKSUM);
  3568. }
  3569. if (changed & NETIF_F_RXHASH)
  3570. rx_set_rss(dev, features);
  3571. if (changed & (NETIF_F_HW_VLAN_CTAG_TX|NETIF_F_HW_VLAN_CTAG_RX))
  3572. sky2_vlan_mode(dev, features);
  3573. return 0;
  3574. }
  3575. static const struct ethtool_ops sky2_ethtool_ops = {
  3576. .get_settings = sky2_get_settings,
  3577. .set_settings = sky2_set_settings,
  3578. .get_drvinfo = sky2_get_drvinfo,
  3579. .get_wol = sky2_get_wol,
  3580. .set_wol = sky2_set_wol,
  3581. .get_msglevel = sky2_get_msglevel,
  3582. .set_msglevel = sky2_set_msglevel,
  3583. .nway_reset = sky2_nway_reset,
  3584. .get_regs_len = sky2_get_regs_len,
  3585. .get_regs = sky2_get_regs,
  3586. .get_link = ethtool_op_get_link,
  3587. .get_eeprom_len = sky2_get_eeprom_len,
  3588. .get_eeprom = sky2_get_eeprom,
  3589. .set_eeprom = sky2_set_eeprom,
  3590. .get_strings = sky2_get_strings,
  3591. .get_coalesce = sky2_get_coalesce,
  3592. .set_coalesce = sky2_set_coalesce,
  3593. .get_ringparam = sky2_get_ringparam,
  3594. .set_ringparam = sky2_set_ringparam,
  3595. .get_pauseparam = sky2_get_pauseparam,
  3596. .set_pauseparam = sky2_set_pauseparam,
  3597. .set_phys_id = sky2_set_phys_id,
  3598. .get_sset_count = sky2_get_sset_count,
  3599. .get_ethtool_stats = sky2_get_ethtool_stats,
  3600. };
  3601. #ifdef CONFIG_SKY2_DEBUG
  3602. static struct dentry *sky2_debug;
  3603. /*
  3604. * Read and parse the first part of Vital Product Data
  3605. */
  3606. #define VPD_SIZE 128
  3607. #define VPD_MAGIC 0x82
  3608. static const struct vpd_tag {
  3609. char tag[2];
  3610. char *label;
  3611. } vpd_tags[] = {
  3612. { "PN", "Part Number" },
  3613. { "EC", "Engineering Level" },
  3614. { "MN", "Manufacturer" },
  3615. { "SN", "Serial Number" },
  3616. { "YA", "Asset Tag" },
  3617. { "VL", "First Error Log Message" },
  3618. { "VF", "Second Error Log Message" },
  3619. { "VB", "Boot Agent ROM Configuration" },
  3620. { "VE", "EFI UNDI Configuration" },
  3621. };
  3622. static void sky2_show_vpd(struct seq_file *seq, struct sky2_hw *hw)
  3623. {
  3624. size_t vpd_size;
  3625. loff_t offs;
  3626. u8 len;
  3627. unsigned char *buf;
  3628. u16 reg2;
  3629. reg2 = sky2_pci_read16(hw, PCI_DEV_REG2);
  3630. vpd_size = 1 << ( ((reg2 & PCI_VPD_ROM_SZ) >> 14) + 8);
  3631. seq_printf(seq, "%s Product Data\n", pci_name(hw->pdev));
  3632. buf = kmalloc(vpd_size, GFP_KERNEL);
  3633. if (!buf) {
  3634. seq_puts(seq, "no memory!\n");
  3635. return;
  3636. }
  3637. if (pci_read_vpd(hw->pdev, 0, vpd_size, buf) < 0) {
  3638. seq_puts(seq, "VPD read failed\n");
  3639. goto out;
  3640. }
  3641. if (buf[0] != VPD_MAGIC) {
  3642. seq_printf(seq, "VPD tag mismatch: %#x\n", buf[0]);
  3643. goto out;
  3644. }
  3645. len = buf[1];
  3646. if (len == 0 || len > vpd_size - 4) {
  3647. seq_printf(seq, "Invalid id length: %d\n", len);
  3648. goto out;
  3649. }
  3650. seq_printf(seq, "%.*s\n", len, buf + 3);
  3651. offs = len + 3;
  3652. while (offs < vpd_size - 4) {
  3653. int i;
  3654. if (!memcmp("RW", buf + offs, 2)) /* end marker */
  3655. break;
  3656. len = buf[offs + 2];
  3657. if (offs + len + 3 >= vpd_size)
  3658. break;
  3659. for (i = 0; i < ARRAY_SIZE(vpd_tags); i++) {
  3660. if (!memcmp(vpd_tags[i].tag, buf + offs, 2)) {
  3661. seq_printf(seq, " %s: %.*s\n",
  3662. vpd_tags[i].label, len, buf + offs + 3);
  3663. break;
  3664. }
  3665. }
  3666. offs += len + 3;
  3667. }
  3668. out:
  3669. kfree(buf);
  3670. }
  3671. static int sky2_debug_show(struct seq_file *seq, void *v)
  3672. {
  3673. struct net_device *dev = seq->private;
  3674. const struct sky2_port *sky2 = netdev_priv(dev);
  3675. struct sky2_hw *hw = sky2->hw;
  3676. unsigned port = sky2->port;
  3677. unsigned idx, last;
  3678. int sop;
  3679. sky2_show_vpd(seq, hw);
  3680. seq_printf(seq, "\nIRQ src=%x mask=%x control=%x\n",
  3681. sky2_read32(hw, B0_ISRC),
  3682. sky2_read32(hw, B0_IMSK),
  3683. sky2_read32(hw, B0_Y2_SP_ICR));
  3684. if (!netif_running(dev)) {
  3685. seq_printf(seq, "network not running\n");
  3686. return 0;
  3687. }
  3688. napi_disable(&hw->napi);
  3689. last = sky2_read16(hw, STAT_PUT_IDX);
  3690. seq_printf(seq, "Status ring %u\n", hw->st_size);
  3691. if (hw->st_idx == last)
  3692. seq_puts(seq, "Status ring (empty)\n");
  3693. else {
  3694. seq_puts(seq, "Status ring\n");
  3695. for (idx = hw->st_idx; idx != last && idx < hw->st_size;
  3696. idx = RING_NEXT(idx, hw->st_size)) {
  3697. const struct sky2_status_le *le = hw->st_le + idx;
  3698. seq_printf(seq, "[%d] %#x %d %#x\n",
  3699. idx, le->opcode, le->length, le->status);
  3700. }
  3701. seq_puts(seq, "\n");
  3702. }
  3703. seq_printf(seq, "Tx ring pending=%u...%u report=%d done=%d\n",
  3704. sky2->tx_cons, sky2->tx_prod,
  3705. sky2_read16(hw, port == 0 ? STAT_TXA1_RIDX : STAT_TXA2_RIDX),
  3706. sky2_read16(hw, Q_ADDR(txqaddr[port], Q_DONE)));
  3707. /* Dump contents of tx ring */
  3708. sop = 1;
  3709. for (idx = sky2->tx_next; idx != sky2->tx_prod && idx < sky2->tx_ring_size;
  3710. idx = RING_NEXT(idx, sky2->tx_ring_size)) {
  3711. const struct sky2_tx_le *le = sky2->tx_le + idx;
  3712. u32 a = le32_to_cpu(le->addr);
  3713. if (sop)
  3714. seq_printf(seq, "%u:", idx);
  3715. sop = 0;
  3716. switch (le->opcode & ~HW_OWNER) {
  3717. case OP_ADDR64:
  3718. seq_printf(seq, " %#x:", a);
  3719. break;
  3720. case OP_LRGLEN:
  3721. seq_printf(seq, " mtu=%d", a);
  3722. break;
  3723. case OP_VLAN:
  3724. seq_printf(seq, " vlan=%d", be16_to_cpu(le->length));
  3725. break;
  3726. case OP_TCPLISW:
  3727. seq_printf(seq, " csum=%#x", a);
  3728. break;
  3729. case OP_LARGESEND:
  3730. seq_printf(seq, " tso=%#x(%d)", a, le16_to_cpu(le->length));
  3731. break;
  3732. case OP_PACKET:
  3733. seq_printf(seq, " %#x(%d)", a, le16_to_cpu(le->length));
  3734. break;
  3735. case OP_BUFFER:
  3736. seq_printf(seq, " frag=%#x(%d)", a, le16_to_cpu(le->length));
  3737. break;
  3738. default:
  3739. seq_printf(seq, " op=%#x,%#x(%d)", le->opcode,
  3740. a, le16_to_cpu(le->length));
  3741. }
  3742. if (le->ctrl & EOP) {
  3743. seq_putc(seq, '\n');
  3744. sop = 1;
  3745. }
  3746. }
  3747. seq_printf(seq, "\nRx ring hw get=%d put=%d last=%d\n",
  3748. sky2_read16(hw, Y2_QADDR(rxqaddr[port], PREF_UNIT_GET_IDX)),
  3749. sky2_read16(hw, Y2_QADDR(rxqaddr[port], PREF_UNIT_PUT_IDX)),
  3750. sky2_read16(hw, Y2_QADDR(rxqaddr[port], PREF_UNIT_LAST_IDX)));
  3751. sky2_read32(hw, B0_Y2_SP_LISR);
  3752. napi_enable(&hw->napi);
  3753. return 0;
  3754. }
  3755. static int sky2_debug_open(struct inode *inode, struct file *file)
  3756. {
  3757. return single_open(file, sky2_debug_show, inode->i_private);
  3758. }
  3759. static const struct file_operations sky2_debug_fops = {
  3760. .owner = THIS_MODULE,
  3761. .open = sky2_debug_open,
  3762. .read = seq_read,
  3763. .llseek = seq_lseek,
  3764. .release = single_release,
  3765. };
  3766. /*
  3767. * Use network device events to create/remove/rename
  3768. * debugfs file entries
  3769. */
  3770. static int sky2_device_event(struct notifier_block *unused,
  3771. unsigned long event, void *ptr)
  3772. {
  3773. struct net_device *dev = netdev_notifier_info_to_dev(ptr);
  3774. struct sky2_port *sky2 = netdev_priv(dev);
  3775. if (dev->netdev_ops->ndo_open != sky2_open || !sky2_debug)
  3776. return NOTIFY_DONE;
  3777. switch (event) {
  3778. case NETDEV_CHANGENAME:
  3779. if (sky2->debugfs) {
  3780. sky2->debugfs = debugfs_rename(sky2_debug, sky2->debugfs,
  3781. sky2_debug, dev->name);
  3782. }
  3783. break;
  3784. case NETDEV_GOING_DOWN:
  3785. if (sky2->debugfs) {
  3786. netdev_printk(KERN_DEBUG, dev, "remove debugfs\n");
  3787. debugfs_remove(sky2->debugfs);
  3788. sky2->debugfs = NULL;
  3789. }
  3790. break;
  3791. case NETDEV_UP:
  3792. sky2->debugfs = debugfs_create_file(dev->name, S_IRUGO,
  3793. sky2_debug, dev,
  3794. &sky2_debug_fops);
  3795. if (IS_ERR(sky2->debugfs))
  3796. sky2->debugfs = NULL;
  3797. }
  3798. return NOTIFY_DONE;
  3799. }
  3800. static struct notifier_block sky2_notifier = {
  3801. .notifier_call = sky2_device_event,
  3802. };
  3803. static __init void sky2_debug_init(void)
  3804. {
  3805. struct dentry *ent;
  3806. ent = debugfs_create_dir("sky2", NULL);
  3807. if (!ent || IS_ERR(ent))
  3808. return;
  3809. sky2_debug = ent;
  3810. register_netdevice_notifier(&sky2_notifier);
  3811. }
  3812. static __exit void sky2_debug_cleanup(void)
  3813. {
  3814. if (sky2_debug) {
  3815. unregister_netdevice_notifier(&sky2_notifier);
  3816. debugfs_remove(sky2_debug);
  3817. sky2_debug = NULL;
  3818. }
  3819. }
  3820. #else
  3821. #define sky2_debug_init()
  3822. #define sky2_debug_cleanup()
  3823. #endif
  3824. /* Two copies of network device operations to handle special case of
  3825. not allowing netpoll on second port */
  3826. static const struct net_device_ops sky2_netdev_ops[2] = {
  3827. {
  3828. .ndo_open = sky2_open,
  3829. .ndo_stop = sky2_close,
  3830. .ndo_start_xmit = sky2_xmit_frame,
  3831. .ndo_do_ioctl = sky2_ioctl,
  3832. .ndo_validate_addr = eth_validate_addr,
  3833. .ndo_set_mac_address = sky2_set_mac_address,
  3834. .ndo_set_rx_mode = sky2_set_multicast,
  3835. .ndo_change_mtu = sky2_change_mtu,
  3836. .ndo_fix_features = sky2_fix_features,
  3837. .ndo_set_features = sky2_set_features,
  3838. .ndo_tx_timeout = sky2_tx_timeout,
  3839. .ndo_get_stats64 = sky2_get_stats,
  3840. #ifdef CONFIG_NET_POLL_CONTROLLER
  3841. .ndo_poll_controller = sky2_netpoll,
  3842. #endif
  3843. },
  3844. {
  3845. .ndo_open = sky2_open,
  3846. .ndo_stop = sky2_close,
  3847. .ndo_start_xmit = sky2_xmit_frame,
  3848. .ndo_do_ioctl = sky2_ioctl,
  3849. .ndo_validate_addr = eth_validate_addr,
  3850. .ndo_set_mac_address = sky2_set_mac_address,
  3851. .ndo_set_rx_mode = sky2_set_multicast,
  3852. .ndo_change_mtu = sky2_change_mtu,
  3853. .ndo_fix_features = sky2_fix_features,
  3854. .ndo_set_features = sky2_set_features,
  3855. .ndo_tx_timeout = sky2_tx_timeout,
  3856. .ndo_get_stats64 = sky2_get_stats,
  3857. },
  3858. };
  3859. /* Initialize network device */
  3860. static struct net_device *sky2_init_netdev(struct sky2_hw *hw, unsigned port,
  3861. int highmem, int wol)
  3862. {
  3863. struct sky2_port *sky2;
  3864. struct net_device *dev = alloc_etherdev(sizeof(*sky2));
  3865. const void *iap;
  3866. if (!dev)
  3867. return NULL;
  3868. SET_NETDEV_DEV(dev, &hw->pdev->dev);
  3869. dev->irq = hw->pdev->irq;
  3870. dev->ethtool_ops = &sky2_ethtool_ops;
  3871. dev->watchdog_timeo = TX_WATCHDOG;
  3872. dev->netdev_ops = &sky2_netdev_ops[port];
  3873. sky2 = netdev_priv(dev);
  3874. sky2->netdev = dev;
  3875. sky2->hw = hw;
  3876. sky2->msg_enable = netif_msg_init(debug, default_msg);
  3877. u64_stats_init(&sky2->tx_stats.syncp);
  3878. u64_stats_init(&sky2->rx_stats.syncp);
  3879. /* Auto speed and flow control */
  3880. sky2->flags = SKY2_FLAG_AUTO_SPEED | SKY2_FLAG_AUTO_PAUSE;
  3881. if (hw->chip_id != CHIP_ID_YUKON_XL)
  3882. dev->hw_features |= NETIF_F_RXCSUM;
  3883. sky2->flow_mode = FC_BOTH;
  3884. sky2->duplex = -1;
  3885. sky2->speed = -1;
  3886. sky2->advertising = sky2_supported_modes(hw);
  3887. sky2->wol = wol;
  3888. spin_lock_init(&sky2->phy_lock);
  3889. sky2->tx_pending = TX_DEF_PENDING;
  3890. sky2->tx_ring_size = roundup_ring_size(TX_DEF_PENDING);
  3891. sky2->rx_pending = RX_DEF_PENDING;
  3892. hw->dev[port] = dev;
  3893. sky2->port = port;
  3894. dev->hw_features |= NETIF_F_IP_CSUM | NETIF_F_SG | NETIF_F_TSO;
  3895. if (highmem)
  3896. dev->features |= NETIF_F_HIGHDMA;
  3897. /* Enable receive hashing unless hardware is known broken */
  3898. if (!(hw->flags & SKY2_HW_RSS_BROKEN))
  3899. dev->hw_features |= NETIF_F_RXHASH;
  3900. if (!(hw->flags & SKY2_HW_VLAN_BROKEN)) {
  3901. dev->hw_features |= NETIF_F_HW_VLAN_CTAG_TX |
  3902. NETIF_F_HW_VLAN_CTAG_RX;
  3903. dev->vlan_features |= SKY2_VLAN_OFFLOADS;
  3904. }
  3905. dev->features |= dev->hw_features;
  3906. /* try to get mac address in the following order:
  3907. * 1) from device tree data
  3908. * 2) from internal registers set by bootloader
  3909. */
  3910. iap = of_get_mac_address(hw->pdev->dev.of_node);
  3911. if (iap)
  3912. memcpy(dev->dev_addr, iap, ETH_ALEN);
  3913. else
  3914. memcpy_fromio(dev->dev_addr, hw->regs + B2_MAC_1 + port * 8,
  3915. ETH_ALEN);
  3916. /* if the address is invalid, use a random value */
  3917. if (!is_valid_ether_addr(dev->dev_addr)) {
  3918. struct sockaddr sa = { AF_UNSPEC };
  3919. netdev_warn(dev,
  3920. "Invalid MAC address, defaulting to random\n");
  3921. eth_hw_addr_random(dev);
  3922. memcpy(sa.sa_data, dev->dev_addr, ETH_ALEN);
  3923. if (sky2_set_mac_address(dev, &sa))
  3924. netdev_warn(dev, "Failed to set MAC address.\n");
  3925. }
  3926. return dev;
  3927. }
  3928. static void sky2_show_addr(struct net_device *dev)
  3929. {
  3930. const struct sky2_port *sky2 = netdev_priv(dev);
  3931. netif_info(sky2, probe, dev, "addr %pM\n", dev->dev_addr);
  3932. }
  3933. /* Handle software interrupt used during MSI test */
  3934. static irqreturn_t sky2_test_intr(int irq, void *dev_id)
  3935. {
  3936. struct sky2_hw *hw = dev_id;
  3937. u32 status = sky2_read32(hw, B0_Y2_SP_ISRC2);
  3938. if (status == 0)
  3939. return IRQ_NONE;
  3940. if (status & Y2_IS_IRQ_SW) {
  3941. hw->flags |= SKY2_HW_USE_MSI;
  3942. wake_up(&hw->msi_wait);
  3943. sky2_write8(hw, B0_CTST, CS_CL_SW_IRQ);
  3944. }
  3945. sky2_write32(hw, B0_Y2_SP_ICR, 2);
  3946. return IRQ_HANDLED;
  3947. }
  3948. /* Test interrupt path by forcing a a software IRQ */
  3949. static int sky2_test_msi(struct sky2_hw *hw)
  3950. {
  3951. struct pci_dev *pdev = hw->pdev;
  3952. int err;
  3953. init_waitqueue_head(&hw->msi_wait);
  3954. err = request_irq(pdev->irq, sky2_test_intr, 0, DRV_NAME, hw);
  3955. if (err) {
  3956. dev_err(&pdev->dev, "cannot assign irq %d\n", pdev->irq);
  3957. return err;
  3958. }
  3959. sky2_write32(hw, B0_IMSK, Y2_IS_IRQ_SW);
  3960. sky2_write8(hw, B0_CTST, CS_ST_SW_IRQ);
  3961. sky2_read8(hw, B0_CTST);
  3962. wait_event_timeout(hw->msi_wait, (hw->flags & SKY2_HW_USE_MSI), HZ/10);
  3963. if (!(hw->flags & SKY2_HW_USE_MSI)) {
  3964. /* MSI test failed, go back to INTx mode */
  3965. dev_info(&pdev->dev, "No interrupt generated using MSI, "
  3966. "switching to INTx mode.\n");
  3967. err = -EOPNOTSUPP;
  3968. sky2_write8(hw, B0_CTST, CS_CL_SW_IRQ);
  3969. }
  3970. sky2_write32(hw, B0_IMSK, 0);
  3971. sky2_read32(hw, B0_IMSK);
  3972. free_irq(pdev->irq, hw);
  3973. return err;
  3974. }
  3975. /* This driver supports yukon2 chipset only */
  3976. static const char *sky2_name(u8 chipid, char *buf, int sz)
  3977. {
  3978. const char *name[] = {
  3979. "XL", /* 0xb3 */
  3980. "EC Ultra", /* 0xb4 */
  3981. "Extreme", /* 0xb5 */
  3982. "EC", /* 0xb6 */
  3983. "FE", /* 0xb7 */
  3984. "FE+", /* 0xb8 */
  3985. "Supreme", /* 0xb9 */
  3986. "UL 2", /* 0xba */
  3987. "Unknown", /* 0xbb */
  3988. "Optima", /* 0xbc */
  3989. "OptimaEEE", /* 0xbd */
  3990. "Optima 2", /* 0xbe */
  3991. };
  3992. if (chipid >= CHIP_ID_YUKON_XL && chipid <= CHIP_ID_YUKON_OP_2)
  3993. strncpy(buf, name[chipid - CHIP_ID_YUKON_XL], sz);
  3994. else
  3995. snprintf(buf, sz, "(chip %#x)", chipid);
  3996. return buf;
  3997. }
  3998. static int sky2_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  3999. {
  4000. struct net_device *dev, *dev1;
  4001. struct sky2_hw *hw;
  4002. int err, using_dac = 0, wol_default;
  4003. u32 reg;
  4004. char buf1[16];
  4005. err = pci_enable_device(pdev);
  4006. if (err) {
  4007. dev_err(&pdev->dev, "cannot enable PCI device\n");
  4008. goto err_out;
  4009. }
  4010. /* Get configuration information
  4011. * Note: only regular PCI config access once to test for HW issues
  4012. * other PCI access through shared memory for speed and to
  4013. * avoid MMCONFIG problems.
  4014. */
  4015. err = pci_read_config_dword(pdev, PCI_DEV_REG2, &reg);
  4016. if (err) {
  4017. dev_err(&pdev->dev, "PCI read config failed\n");
  4018. goto err_out_disable;
  4019. }
  4020. if (~reg == 0) {
  4021. dev_err(&pdev->dev, "PCI configuration read error\n");
  4022. err = -EIO;
  4023. goto err_out_disable;
  4024. }
  4025. err = pci_request_regions(pdev, DRV_NAME);
  4026. if (err) {
  4027. dev_err(&pdev->dev, "cannot obtain PCI resources\n");
  4028. goto err_out_disable;
  4029. }
  4030. pci_set_master(pdev);
  4031. if (sizeof(dma_addr_t) > sizeof(u32) &&
  4032. !(err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64)))) {
  4033. using_dac = 1;
  4034. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
  4035. if (err < 0) {
  4036. dev_err(&pdev->dev, "unable to obtain 64 bit DMA "
  4037. "for consistent allocations\n");
  4038. goto err_out_free_regions;
  4039. }
  4040. } else {
  4041. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  4042. if (err) {
  4043. dev_err(&pdev->dev, "no usable DMA configuration\n");
  4044. goto err_out_free_regions;
  4045. }
  4046. }
  4047. #ifdef __BIG_ENDIAN
  4048. /* The sk98lin vendor driver uses hardware byte swapping but
  4049. * this driver uses software swapping.
  4050. */
  4051. reg &= ~PCI_REV_DESC;
  4052. err = pci_write_config_dword(pdev, PCI_DEV_REG2, reg);
  4053. if (err) {
  4054. dev_err(&pdev->dev, "PCI write config failed\n");
  4055. goto err_out_free_regions;
  4056. }
  4057. #endif
  4058. wol_default = device_may_wakeup(&pdev->dev) ? WAKE_MAGIC : 0;
  4059. err = -ENOMEM;
  4060. hw = kzalloc(sizeof(*hw) + strlen(DRV_NAME "@pci:")
  4061. + strlen(pci_name(pdev)) + 1, GFP_KERNEL);
  4062. if (!hw)
  4063. goto err_out_free_regions;
  4064. hw->pdev = pdev;
  4065. sprintf(hw->irq_name, DRV_NAME "@pci:%s", pci_name(pdev));
  4066. hw->regs = ioremap_nocache(pci_resource_start(pdev, 0), 0x4000);
  4067. if (!hw->regs) {
  4068. dev_err(&pdev->dev, "cannot map device registers\n");
  4069. goto err_out_free_hw;
  4070. }
  4071. err = sky2_init(hw);
  4072. if (err)
  4073. goto err_out_iounmap;
  4074. /* ring for status responses */
  4075. hw->st_size = hw->ports * roundup_pow_of_two(3*RX_MAX_PENDING + TX_MAX_PENDING);
  4076. hw->st_le = pci_alloc_consistent(pdev, hw->st_size * sizeof(struct sky2_status_le),
  4077. &hw->st_dma);
  4078. if (!hw->st_le) {
  4079. err = -ENOMEM;
  4080. goto err_out_reset;
  4081. }
  4082. dev_info(&pdev->dev, "Yukon-2 %s chip revision %d\n",
  4083. sky2_name(hw->chip_id, buf1, sizeof(buf1)), hw->chip_rev);
  4084. sky2_reset(hw);
  4085. dev = sky2_init_netdev(hw, 0, using_dac, wol_default);
  4086. if (!dev) {
  4087. err = -ENOMEM;
  4088. goto err_out_free_pci;
  4089. }
  4090. if (!disable_msi && pci_enable_msi(pdev) == 0) {
  4091. err = sky2_test_msi(hw);
  4092. if (err) {
  4093. pci_disable_msi(pdev);
  4094. if (err != -EOPNOTSUPP)
  4095. goto err_out_free_netdev;
  4096. }
  4097. }
  4098. netif_napi_add(dev, &hw->napi, sky2_poll, NAPI_WEIGHT);
  4099. err = register_netdev(dev);
  4100. if (err) {
  4101. dev_err(&pdev->dev, "cannot register net device\n");
  4102. goto err_out_free_netdev;
  4103. }
  4104. netif_carrier_off(dev);
  4105. sky2_show_addr(dev);
  4106. if (hw->ports > 1) {
  4107. dev1 = sky2_init_netdev(hw, 1, using_dac, wol_default);
  4108. if (!dev1) {
  4109. err = -ENOMEM;
  4110. goto err_out_unregister;
  4111. }
  4112. err = register_netdev(dev1);
  4113. if (err) {
  4114. dev_err(&pdev->dev, "cannot register second net device\n");
  4115. goto err_out_free_dev1;
  4116. }
  4117. err = sky2_setup_irq(hw, hw->irq_name);
  4118. if (err)
  4119. goto err_out_unregister_dev1;
  4120. sky2_show_addr(dev1);
  4121. }
  4122. setup_timer(&hw->watchdog_timer, sky2_watchdog, (unsigned long) hw);
  4123. INIT_WORK(&hw->restart_work, sky2_restart);
  4124. pci_set_drvdata(pdev, hw);
  4125. pdev->d3_delay = 200;
  4126. return 0;
  4127. err_out_unregister_dev1:
  4128. unregister_netdev(dev1);
  4129. err_out_free_dev1:
  4130. free_netdev(dev1);
  4131. err_out_unregister:
  4132. unregister_netdev(dev);
  4133. err_out_free_netdev:
  4134. if (hw->flags & SKY2_HW_USE_MSI)
  4135. pci_disable_msi(pdev);
  4136. free_netdev(dev);
  4137. err_out_free_pci:
  4138. pci_free_consistent(pdev, hw->st_size * sizeof(struct sky2_status_le),
  4139. hw->st_le, hw->st_dma);
  4140. err_out_reset:
  4141. sky2_write8(hw, B0_CTST, CS_RST_SET);
  4142. err_out_iounmap:
  4143. iounmap(hw->regs);
  4144. err_out_free_hw:
  4145. kfree(hw);
  4146. err_out_free_regions:
  4147. pci_release_regions(pdev);
  4148. err_out_disable:
  4149. pci_disable_device(pdev);
  4150. err_out:
  4151. return err;
  4152. }
  4153. static void sky2_remove(struct pci_dev *pdev)
  4154. {
  4155. struct sky2_hw *hw = pci_get_drvdata(pdev);
  4156. int i;
  4157. if (!hw)
  4158. return;
  4159. del_timer_sync(&hw->watchdog_timer);
  4160. cancel_work_sync(&hw->restart_work);
  4161. for (i = hw->ports-1; i >= 0; --i)
  4162. unregister_netdev(hw->dev[i]);
  4163. sky2_write32(hw, B0_IMSK, 0);
  4164. sky2_read32(hw, B0_IMSK);
  4165. sky2_power_aux(hw);
  4166. sky2_write8(hw, B0_CTST, CS_RST_SET);
  4167. sky2_read8(hw, B0_CTST);
  4168. if (hw->ports > 1) {
  4169. napi_disable(&hw->napi);
  4170. free_irq(pdev->irq, hw);
  4171. }
  4172. if (hw->flags & SKY2_HW_USE_MSI)
  4173. pci_disable_msi(pdev);
  4174. pci_free_consistent(pdev, hw->st_size * sizeof(struct sky2_status_le),
  4175. hw->st_le, hw->st_dma);
  4176. pci_release_regions(pdev);
  4177. pci_disable_device(pdev);
  4178. for (i = hw->ports-1; i >= 0; --i)
  4179. free_netdev(hw->dev[i]);
  4180. iounmap(hw->regs);
  4181. kfree(hw);
  4182. }
  4183. static int sky2_suspend(struct device *dev)
  4184. {
  4185. struct pci_dev *pdev = to_pci_dev(dev);
  4186. struct sky2_hw *hw = pci_get_drvdata(pdev);
  4187. int i;
  4188. if (!hw)
  4189. return 0;
  4190. del_timer_sync(&hw->watchdog_timer);
  4191. cancel_work_sync(&hw->restart_work);
  4192. rtnl_lock();
  4193. sky2_all_down(hw);
  4194. for (i = 0; i < hw->ports; i++) {
  4195. struct net_device *dev = hw->dev[i];
  4196. struct sky2_port *sky2 = netdev_priv(dev);
  4197. if (sky2->wol)
  4198. sky2_wol_init(sky2);
  4199. }
  4200. sky2_power_aux(hw);
  4201. rtnl_unlock();
  4202. return 0;
  4203. }
  4204. #ifdef CONFIG_PM_SLEEP
  4205. static int sky2_resume(struct device *dev)
  4206. {
  4207. struct pci_dev *pdev = to_pci_dev(dev);
  4208. struct sky2_hw *hw = pci_get_drvdata(pdev);
  4209. int err;
  4210. if (!hw)
  4211. return 0;
  4212. /* Re-enable all clocks */
  4213. err = pci_write_config_dword(pdev, PCI_DEV_REG3, 0);
  4214. if (err) {
  4215. dev_err(&pdev->dev, "PCI write config failed\n");
  4216. goto out;
  4217. }
  4218. rtnl_lock();
  4219. sky2_reset(hw);
  4220. sky2_all_up(hw);
  4221. rtnl_unlock();
  4222. return 0;
  4223. out:
  4224. dev_err(&pdev->dev, "resume failed (%d)\n", err);
  4225. pci_disable_device(pdev);
  4226. return err;
  4227. }
  4228. static SIMPLE_DEV_PM_OPS(sky2_pm_ops, sky2_suspend, sky2_resume);
  4229. #define SKY2_PM_OPS (&sky2_pm_ops)
  4230. #else
  4231. #define SKY2_PM_OPS NULL
  4232. #endif
  4233. static void sky2_shutdown(struct pci_dev *pdev)
  4234. {
  4235. struct sky2_hw *hw = pci_get_drvdata(pdev);
  4236. int port;
  4237. for (port = 0; port < hw->ports; port++) {
  4238. struct net_device *ndev = hw->dev[port];
  4239. rtnl_lock();
  4240. if (netif_running(ndev)) {
  4241. dev_close(ndev);
  4242. netif_device_detach(ndev);
  4243. }
  4244. rtnl_unlock();
  4245. }
  4246. sky2_suspend(&pdev->dev);
  4247. pci_wake_from_d3(pdev, device_may_wakeup(&pdev->dev));
  4248. pci_set_power_state(pdev, PCI_D3hot);
  4249. }
  4250. static struct pci_driver sky2_driver = {
  4251. .name = DRV_NAME,
  4252. .id_table = sky2_id_table,
  4253. .probe = sky2_probe,
  4254. .remove = sky2_remove,
  4255. .shutdown = sky2_shutdown,
  4256. .driver.pm = SKY2_PM_OPS,
  4257. };
  4258. static int __init sky2_init_module(void)
  4259. {
  4260. pr_info("driver version " DRV_VERSION "\n");
  4261. sky2_debug_init();
  4262. return pci_register_driver(&sky2_driver);
  4263. }
  4264. static void __exit sky2_cleanup_module(void)
  4265. {
  4266. pci_unregister_driver(&sky2_driver);
  4267. sky2_debug_cleanup();
  4268. }
  4269. module_init(sky2_init_module);
  4270. module_exit(sky2_cleanup_module);
  4271. MODULE_DESCRIPTION("Marvell Yukon 2 Gigabit Ethernet driver");
  4272. MODULE_AUTHOR("Stephen Hemminger <shemminger@linux-foundation.org>");
  4273. MODULE_LICENSE("GPL");
  4274. MODULE_VERSION(DRV_VERSION);