sky2.c 138 KB

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