skge.c 107 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238
  1. /*
  2. * New driver for Marvell Yukon chipset and SysKonnect Gigabit
  3. * Ethernet adapters. Based on earlier sk98lin, e100 and
  4. * FreeBSD if_sk drivers.
  5. *
  6. * This driver intentionally does not support all the features
  7. * of the original driver such as link fail-over and link management because
  8. * those should be done at higher levels.
  9. *
  10. * Copyright (C) 2004, 2005 Stephen Hemminger <shemminger@osdl.org>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24. */
  25. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  26. #include <linux/in.h>
  27. #include <linux/kernel.h>
  28. #include <linux/module.h>
  29. #include <linux/moduleparam.h>
  30. #include <linux/netdevice.h>
  31. #include <linux/etherdevice.h>
  32. #include <linux/ethtool.h>
  33. #include <linux/pci.h>
  34. #include <linux/if_vlan.h>
  35. #include <linux/ip.h>
  36. #include <linux/delay.h>
  37. #include <linux/crc32.h>
  38. #include <linux/dma-mapping.h>
  39. #include <linux/debugfs.h>
  40. #include <linux/sched.h>
  41. #include <linux/seq_file.h>
  42. #include <linux/mii.h>
  43. #include <linux/slab.h>
  44. #include <linux/dmi.h>
  45. #include <linux/prefetch.h>
  46. #include <asm/irq.h>
  47. #include "skge.h"
  48. #define DRV_NAME "skge"
  49. #define DRV_VERSION "1.14"
  50. #define DEFAULT_TX_RING_SIZE 128
  51. #define DEFAULT_RX_RING_SIZE 512
  52. #define MAX_TX_RING_SIZE 1024
  53. #define TX_LOW_WATER (MAX_SKB_FRAGS + 1)
  54. #define MAX_RX_RING_SIZE 4096
  55. #define RX_COPY_THRESHOLD 128
  56. #define RX_BUF_SIZE 1536
  57. #define PHY_RETRIES 1000
  58. #define ETH_JUMBO_MTU 9000
  59. #define TX_WATCHDOG (5 * HZ)
  60. #define NAPI_WEIGHT 64
  61. #define BLINK_MS 250
  62. #define LINK_HZ HZ
  63. #define SKGE_EEPROM_MAGIC 0x9933aabb
  64. MODULE_DESCRIPTION("SysKonnect Gigabit Ethernet driver");
  65. MODULE_AUTHOR("Stephen Hemminger <shemminger@linux-foundation.org>");
  66. MODULE_LICENSE("GPL");
  67. MODULE_VERSION(DRV_VERSION);
  68. static const u32 default_msg = (NETIF_MSG_DRV | NETIF_MSG_PROBE |
  69. NETIF_MSG_LINK | NETIF_MSG_IFUP |
  70. NETIF_MSG_IFDOWN);
  71. static int debug = -1; /* defaults above */
  72. module_param(debug, int, 0);
  73. MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
  74. static const struct pci_device_id skge_id_table[] = {
  75. { PCI_DEVICE(PCI_VENDOR_ID_3COM, 0x1700) }, /* 3Com 3C940 */
  76. { PCI_DEVICE(PCI_VENDOR_ID_3COM, 0x80EB) }, /* 3Com 3C940B */
  77. #ifdef CONFIG_SKGE_GENESIS
  78. { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, 0x4300) }, /* SK-9xx */
  79. #endif
  80. { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, 0x4320) }, /* SK-98xx V2.0 */
  81. { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4b01) }, /* D-Link DGE-530T (rev.B) */
  82. { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4c00) }, /* D-Link DGE-530T */
  83. { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4302) }, /* D-Link DGE-530T Rev C1 */
  84. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4320) }, /* Marvell Yukon 88E8001/8003/8010 */
  85. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x5005) }, /* Belkin */
  86. { PCI_DEVICE(PCI_VENDOR_ID_CNET, 0x434E) }, /* CNet PowerG-2000 */
  87. { PCI_DEVICE(PCI_VENDOR_ID_LINKSYS, 0x1064) }, /* Linksys EG1064 v2 */
  88. { PCI_VENDOR_ID_LINKSYS, 0x1032, PCI_ANY_ID, 0x0015 }, /* Linksys EG1032 v2 */
  89. { 0 }
  90. };
  91. MODULE_DEVICE_TABLE(pci, skge_id_table);
  92. static int skge_up(struct net_device *dev);
  93. static int skge_down(struct net_device *dev);
  94. static void skge_phy_reset(struct skge_port *skge);
  95. static void skge_tx_clean(struct net_device *dev);
  96. static int xm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val);
  97. static int gm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val);
  98. static void genesis_get_stats(struct skge_port *skge, u64 *data);
  99. static void yukon_get_stats(struct skge_port *skge, u64 *data);
  100. static void yukon_init(struct skge_hw *hw, int port);
  101. static void genesis_mac_init(struct skge_hw *hw, int port);
  102. static void genesis_link_up(struct skge_port *skge);
  103. static void skge_set_multicast(struct net_device *dev);
  104. static irqreturn_t skge_intr(int irq, void *dev_id);
  105. /* Avoid conditionals by using array */
  106. static const int txqaddr[] = { Q_XA1, Q_XA2 };
  107. static const int rxqaddr[] = { Q_R1, Q_R2 };
  108. static const u32 rxirqmask[] = { IS_R1_F, IS_R2_F };
  109. static const u32 txirqmask[] = { IS_XA1_F, IS_XA2_F };
  110. static const u32 napimask[] = { IS_R1_F|IS_XA1_F, IS_R2_F|IS_XA2_F };
  111. static const u32 portmask[] = { IS_PORT_1, IS_PORT_2 };
  112. static inline bool is_genesis(const struct skge_hw *hw)
  113. {
  114. #ifdef CONFIG_SKGE_GENESIS
  115. return hw->chip_id == CHIP_ID_GENESIS;
  116. #else
  117. return false;
  118. #endif
  119. }
  120. static int skge_get_regs_len(struct net_device *dev)
  121. {
  122. return 0x4000;
  123. }
  124. /*
  125. * Returns copy of whole control register region
  126. * Note: skip RAM address register because accessing it will
  127. * cause bus hangs!
  128. */
  129. static void skge_get_regs(struct net_device *dev, struct ethtool_regs *regs,
  130. void *p)
  131. {
  132. const struct skge_port *skge = netdev_priv(dev);
  133. const void __iomem *io = skge->hw->regs;
  134. regs->version = 1;
  135. memset(p, 0, regs->len);
  136. memcpy_fromio(p, io, B3_RAM_ADDR);
  137. if (regs->len > B3_RI_WTO_R1) {
  138. memcpy_fromio(p + B3_RI_WTO_R1, io + B3_RI_WTO_R1,
  139. regs->len - B3_RI_WTO_R1);
  140. }
  141. }
  142. /* Wake on Lan only supported on Yukon chips with rev 1 or above */
  143. static u32 wol_supported(const struct skge_hw *hw)
  144. {
  145. if (is_genesis(hw))
  146. return 0;
  147. if (hw->chip_id == CHIP_ID_YUKON && hw->chip_rev == 0)
  148. return 0;
  149. return WAKE_MAGIC | WAKE_PHY;
  150. }
  151. static void skge_wol_init(struct skge_port *skge)
  152. {
  153. struct skge_hw *hw = skge->hw;
  154. int port = skge->port;
  155. u16 ctrl;
  156. skge_write16(hw, B0_CTST, CS_RST_CLR);
  157. skge_write16(hw, SK_REG(port, GMAC_LINK_CTRL), GMLC_RST_CLR);
  158. /* Turn on Vaux */
  159. skge_write8(hw, B0_POWER_CTRL,
  160. PC_VAUX_ENA | PC_VCC_ENA | PC_VAUX_ON | PC_VCC_OFF);
  161. /* WA code for COMA mode -- clear PHY reset */
  162. if (hw->chip_id == CHIP_ID_YUKON_LITE &&
  163. hw->chip_rev >= CHIP_REV_YU_LITE_A3) {
  164. u32 reg = skge_read32(hw, B2_GP_IO);
  165. reg |= GP_DIR_9;
  166. reg &= ~GP_IO_9;
  167. skge_write32(hw, B2_GP_IO, reg);
  168. }
  169. skge_write32(hw, SK_REG(port, GPHY_CTRL),
  170. GPC_DIS_SLEEP |
  171. GPC_HWCFG_M_3 | GPC_HWCFG_M_2 | GPC_HWCFG_M_1 | GPC_HWCFG_M_0 |
  172. GPC_ANEG_1 | GPC_RST_SET);
  173. skge_write32(hw, SK_REG(port, GPHY_CTRL),
  174. GPC_DIS_SLEEP |
  175. GPC_HWCFG_M_3 | GPC_HWCFG_M_2 | GPC_HWCFG_M_1 | GPC_HWCFG_M_0 |
  176. GPC_ANEG_1 | GPC_RST_CLR);
  177. skge_write32(hw, SK_REG(port, GMAC_CTRL), GMC_RST_CLR);
  178. /* Force to 10/100 skge_reset will re-enable on resume */
  179. gm_phy_write(hw, port, PHY_MARV_AUNE_ADV,
  180. (PHY_AN_100FULL | PHY_AN_100HALF |
  181. PHY_AN_10FULL | PHY_AN_10HALF | PHY_AN_CSMA));
  182. /* no 1000 HD/FD */
  183. gm_phy_write(hw, port, PHY_MARV_1000T_CTRL, 0);
  184. gm_phy_write(hw, port, PHY_MARV_CTRL,
  185. PHY_CT_RESET | PHY_CT_SPS_LSB | PHY_CT_ANE |
  186. PHY_CT_RE_CFG | PHY_CT_DUP_MD);
  187. /* Set GMAC to no flow control and auto update for speed/duplex */
  188. gma_write16(hw, port, GM_GP_CTRL,
  189. GM_GPCR_FC_TX_DIS|GM_GPCR_TX_ENA|GM_GPCR_RX_ENA|
  190. GM_GPCR_DUP_FULL|GM_GPCR_FC_RX_DIS|GM_GPCR_AU_FCT_DIS);
  191. /* Set WOL address */
  192. memcpy_toio(hw->regs + WOL_REGS(port, WOL_MAC_ADDR),
  193. skge->netdev->dev_addr, ETH_ALEN);
  194. /* Turn on appropriate WOL control bits */
  195. skge_write16(hw, WOL_REGS(port, WOL_CTRL_STAT), WOL_CTL_CLEAR_RESULT);
  196. ctrl = 0;
  197. if (skge->wol & WAKE_PHY)
  198. ctrl |= WOL_CTL_ENA_PME_ON_LINK_CHG|WOL_CTL_ENA_LINK_CHG_UNIT;
  199. else
  200. ctrl |= WOL_CTL_DIS_PME_ON_LINK_CHG|WOL_CTL_DIS_LINK_CHG_UNIT;
  201. if (skge->wol & WAKE_MAGIC)
  202. ctrl |= WOL_CTL_ENA_PME_ON_MAGIC_PKT|WOL_CTL_ENA_MAGIC_PKT_UNIT;
  203. else
  204. ctrl |= WOL_CTL_DIS_PME_ON_MAGIC_PKT|WOL_CTL_DIS_MAGIC_PKT_UNIT;
  205. ctrl |= WOL_CTL_DIS_PME_ON_PATTERN|WOL_CTL_DIS_PATTERN_UNIT;
  206. skge_write16(hw, WOL_REGS(port, WOL_CTRL_STAT), ctrl);
  207. /* block receiver */
  208. skge_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET);
  209. }
  210. static void skge_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  211. {
  212. struct skge_port *skge = netdev_priv(dev);
  213. wol->supported = wol_supported(skge->hw);
  214. wol->wolopts = skge->wol;
  215. }
  216. static int skge_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  217. {
  218. struct skge_port *skge = netdev_priv(dev);
  219. struct skge_hw *hw = skge->hw;
  220. if ((wol->wolopts & ~wol_supported(hw)) ||
  221. !device_can_wakeup(&hw->pdev->dev))
  222. return -EOPNOTSUPP;
  223. skge->wol = wol->wolopts;
  224. device_set_wakeup_enable(&hw->pdev->dev, skge->wol);
  225. return 0;
  226. }
  227. /* Determine supported/advertised modes based on hardware.
  228. * Note: ethtool ADVERTISED_xxx == SUPPORTED_xxx
  229. */
  230. static u32 skge_supported_modes(const struct skge_hw *hw)
  231. {
  232. u32 supported;
  233. if (hw->copper) {
  234. supported = (SUPPORTED_10baseT_Half |
  235. SUPPORTED_10baseT_Full |
  236. SUPPORTED_100baseT_Half |
  237. SUPPORTED_100baseT_Full |
  238. SUPPORTED_1000baseT_Half |
  239. SUPPORTED_1000baseT_Full |
  240. SUPPORTED_Autoneg |
  241. SUPPORTED_TP);
  242. if (is_genesis(hw))
  243. supported &= ~(SUPPORTED_10baseT_Half |
  244. SUPPORTED_10baseT_Full |
  245. SUPPORTED_100baseT_Half |
  246. SUPPORTED_100baseT_Full);
  247. else if (hw->chip_id == CHIP_ID_YUKON)
  248. supported &= ~SUPPORTED_1000baseT_Half;
  249. } else
  250. supported = (SUPPORTED_1000baseT_Full |
  251. SUPPORTED_1000baseT_Half |
  252. SUPPORTED_FIBRE |
  253. SUPPORTED_Autoneg);
  254. return supported;
  255. }
  256. static int skge_get_link_ksettings(struct net_device *dev,
  257. struct ethtool_link_ksettings *cmd)
  258. {
  259. struct skge_port *skge = netdev_priv(dev);
  260. struct skge_hw *hw = skge->hw;
  261. u32 supported, advertising;
  262. supported = skge_supported_modes(hw);
  263. if (hw->copper) {
  264. cmd->base.port = PORT_TP;
  265. cmd->base.phy_address = hw->phy_addr;
  266. } else
  267. cmd->base.port = PORT_FIBRE;
  268. advertising = skge->advertising;
  269. cmd->base.autoneg = skge->autoneg;
  270. cmd->base.speed = skge->speed;
  271. cmd->base.duplex = skge->duplex;
  272. ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
  273. supported);
  274. ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising,
  275. advertising);
  276. return 0;
  277. }
  278. static int skge_set_link_ksettings(struct net_device *dev,
  279. const struct ethtool_link_ksettings *cmd)
  280. {
  281. struct skge_port *skge = netdev_priv(dev);
  282. const struct skge_hw *hw = skge->hw;
  283. u32 supported = skge_supported_modes(hw);
  284. int err = 0;
  285. u32 advertising;
  286. ethtool_convert_link_mode_to_legacy_u32(&advertising,
  287. cmd->link_modes.advertising);
  288. if (cmd->base.autoneg == AUTONEG_ENABLE) {
  289. advertising = supported;
  290. skge->duplex = -1;
  291. skge->speed = -1;
  292. } else {
  293. u32 setting;
  294. u32 speed = cmd->base.speed;
  295. switch (speed) {
  296. case SPEED_1000:
  297. if (cmd->base.duplex == DUPLEX_FULL)
  298. setting = SUPPORTED_1000baseT_Full;
  299. else if (cmd->base.duplex == DUPLEX_HALF)
  300. setting = SUPPORTED_1000baseT_Half;
  301. else
  302. return -EINVAL;
  303. break;
  304. case SPEED_100:
  305. if (cmd->base.duplex == DUPLEX_FULL)
  306. setting = SUPPORTED_100baseT_Full;
  307. else if (cmd->base.duplex == DUPLEX_HALF)
  308. setting = SUPPORTED_100baseT_Half;
  309. else
  310. return -EINVAL;
  311. break;
  312. case SPEED_10:
  313. if (cmd->base.duplex == DUPLEX_FULL)
  314. setting = SUPPORTED_10baseT_Full;
  315. else if (cmd->base.duplex == DUPLEX_HALF)
  316. setting = SUPPORTED_10baseT_Half;
  317. else
  318. return -EINVAL;
  319. break;
  320. default:
  321. return -EINVAL;
  322. }
  323. if ((setting & supported) == 0)
  324. return -EINVAL;
  325. skge->speed = speed;
  326. skge->duplex = cmd->base.duplex;
  327. }
  328. skge->autoneg = cmd->base.autoneg;
  329. skge->advertising = advertising;
  330. if (netif_running(dev)) {
  331. skge_down(dev);
  332. err = skge_up(dev);
  333. if (err) {
  334. dev_close(dev);
  335. return err;
  336. }
  337. }
  338. return 0;
  339. }
  340. static void skge_get_drvinfo(struct net_device *dev,
  341. struct ethtool_drvinfo *info)
  342. {
  343. struct skge_port *skge = netdev_priv(dev);
  344. strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
  345. strlcpy(info->version, DRV_VERSION, sizeof(info->version));
  346. strlcpy(info->bus_info, pci_name(skge->hw->pdev),
  347. sizeof(info->bus_info));
  348. }
  349. static const struct skge_stat {
  350. char name[ETH_GSTRING_LEN];
  351. u16 xmac_offset;
  352. u16 gma_offset;
  353. } skge_stats[] = {
  354. { "tx_bytes", XM_TXO_OK_HI, GM_TXO_OK_HI },
  355. { "rx_bytes", XM_RXO_OK_HI, GM_RXO_OK_HI },
  356. { "tx_broadcast", XM_TXF_BC_OK, GM_TXF_BC_OK },
  357. { "rx_broadcast", XM_RXF_BC_OK, GM_RXF_BC_OK },
  358. { "tx_multicast", XM_TXF_MC_OK, GM_TXF_MC_OK },
  359. { "rx_multicast", XM_RXF_MC_OK, GM_RXF_MC_OK },
  360. { "tx_unicast", XM_TXF_UC_OK, GM_TXF_UC_OK },
  361. { "rx_unicast", XM_RXF_UC_OK, GM_RXF_UC_OK },
  362. { "tx_mac_pause", XM_TXF_MPAUSE, GM_TXF_MPAUSE },
  363. { "rx_mac_pause", XM_RXF_MPAUSE, GM_RXF_MPAUSE },
  364. { "collisions", XM_TXF_SNG_COL, GM_TXF_SNG_COL },
  365. { "multi_collisions", XM_TXF_MUL_COL, GM_TXF_MUL_COL },
  366. { "aborted", XM_TXF_ABO_COL, GM_TXF_ABO_COL },
  367. { "late_collision", XM_TXF_LAT_COL, GM_TXF_LAT_COL },
  368. { "fifo_underrun", XM_TXE_FIFO_UR, GM_TXE_FIFO_UR },
  369. { "fifo_overflow", XM_RXE_FIFO_OV, GM_RXE_FIFO_OV },
  370. { "rx_toolong", XM_RXF_LNG_ERR, GM_RXF_LNG_ERR },
  371. { "rx_jabber", XM_RXF_JAB_PKT, GM_RXF_JAB_PKT },
  372. { "rx_runt", XM_RXE_RUNT, GM_RXE_FRAG },
  373. { "rx_too_long", XM_RXF_LNG_ERR, GM_RXF_LNG_ERR },
  374. { "rx_fcs_error", XM_RXF_FCS_ERR, GM_RXF_FCS_ERR },
  375. };
  376. static int skge_get_sset_count(struct net_device *dev, int sset)
  377. {
  378. switch (sset) {
  379. case ETH_SS_STATS:
  380. return ARRAY_SIZE(skge_stats);
  381. default:
  382. return -EOPNOTSUPP;
  383. }
  384. }
  385. static void skge_get_ethtool_stats(struct net_device *dev,
  386. struct ethtool_stats *stats, u64 *data)
  387. {
  388. struct skge_port *skge = netdev_priv(dev);
  389. if (is_genesis(skge->hw))
  390. genesis_get_stats(skge, data);
  391. else
  392. yukon_get_stats(skge, data);
  393. }
  394. /* Use hardware MIB variables for critical path statistics and
  395. * transmit feedback not reported at interrupt.
  396. * Other errors are accounted for in interrupt handler.
  397. */
  398. static struct net_device_stats *skge_get_stats(struct net_device *dev)
  399. {
  400. struct skge_port *skge = netdev_priv(dev);
  401. u64 data[ARRAY_SIZE(skge_stats)];
  402. if (is_genesis(skge->hw))
  403. genesis_get_stats(skge, data);
  404. else
  405. yukon_get_stats(skge, data);
  406. dev->stats.tx_bytes = data[0];
  407. dev->stats.rx_bytes = data[1];
  408. dev->stats.tx_packets = data[2] + data[4] + data[6];
  409. dev->stats.rx_packets = data[3] + data[5] + data[7];
  410. dev->stats.multicast = data[3] + data[5];
  411. dev->stats.collisions = data[10];
  412. dev->stats.tx_aborted_errors = data[12];
  413. return &dev->stats;
  414. }
  415. static void skge_get_strings(struct net_device *dev, u32 stringset, u8 *data)
  416. {
  417. int i;
  418. switch (stringset) {
  419. case ETH_SS_STATS:
  420. for (i = 0; i < ARRAY_SIZE(skge_stats); i++)
  421. memcpy(data + i * ETH_GSTRING_LEN,
  422. skge_stats[i].name, ETH_GSTRING_LEN);
  423. break;
  424. }
  425. }
  426. static void skge_get_ring_param(struct net_device *dev,
  427. struct ethtool_ringparam *p)
  428. {
  429. struct skge_port *skge = netdev_priv(dev);
  430. p->rx_max_pending = MAX_RX_RING_SIZE;
  431. p->tx_max_pending = MAX_TX_RING_SIZE;
  432. p->rx_pending = skge->rx_ring.count;
  433. p->tx_pending = skge->tx_ring.count;
  434. }
  435. static int skge_set_ring_param(struct net_device *dev,
  436. struct ethtool_ringparam *p)
  437. {
  438. struct skge_port *skge = netdev_priv(dev);
  439. int err = 0;
  440. if (p->rx_pending == 0 || p->rx_pending > MAX_RX_RING_SIZE ||
  441. p->tx_pending < TX_LOW_WATER || p->tx_pending > MAX_TX_RING_SIZE)
  442. return -EINVAL;
  443. skge->rx_ring.count = p->rx_pending;
  444. skge->tx_ring.count = p->tx_pending;
  445. if (netif_running(dev)) {
  446. skge_down(dev);
  447. err = skge_up(dev);
  448. if (err)
  449. dev_close(dev);
  450. }
  451. return err;
  452. }
  453. static u32 skge_get_msglevel(struct net_device *netdev)
  454. {
  455. struct skge_port *skge = netdev_priv(netdev);
  456. return skge->msg_enable;
  457. }
  458. static void skge_set_msglevel(struct net_device *netdev, u32 value)
  459. {
  460. struct skge_port *skge = netdev_priv(netdev);
  461. skge->msg_enable = value;
  462. }
  463. static int skge_nway_reset(struct net_device *dev)
  464. {
  465. struct skge_port *skge = netdev_priv(dev);
  466. if (skge->autoneg != AUTONEG_ENABLE || !netif_running(dev))
  467. return -EINVAL;
  468. skge_phy_reset(skge);
  469. return 0;
  470. }
  471. static void skge_get_pauseparam(struct net_device *dev,
  472. struct ethtool_pauseparam *ecmd)
  473. {
  474. struct skge_port *skge = netdev_priv(dev);
  475. ecmd->rx_pause = ((skge->flow_control == FLOW_MODE_SYMMETRIC) ||
  476. (skge->flow_control == FLOW_MODE_SYM_OR_REM));
  477. ecmd->tx_pause = (ecmd->rx_pause ||
  478. (skge->flow_control == FLOW_MODE_LOC_SEND));
  479. ecmd->autoneg = ecmd->rx_pause || ecmd->tx_pause;
  480. }
  481. static int skge_set_pauseparam(struct net_device *dev,
  482. struct ethtool_pauseparam *ecmd)
  483. {
  484. struct skge_port *skge = netdev_priv(dev);
  485. struct ethtool_pauseparam old;
  486. int err = 0;
  487. skge_get_pauseparam(dev, &old);
  488. if (ecmd->autoneg != old.autoneg)
  489. skge->flow_control = ecmd->autoneg ? FLOW_MODE_NONE : FLOW_MODE_SYMMETRIC;
  490. else {
  491. if (ecmd->rx_pause && ecmd->tx_pause)
  492. skge->flow_control = FLOW_MODE_SYMMETRIC;
  493. else if (ecmd->rx_pause && !ecmd->tx_pause)
  494. skge->flow_control = FLOW_MODE_SYM_OR_REM;
  495. else if (!ecmd->rx_pause && ecmd->tx_pause)
  496. skge->flow_control = FLOW_MODE_LOC_SEND;
  497. else
  498. skge->flow_control = FLOW_MODE_NONE;
  499. }
  500. if (netif_running(dev)) {
  501. skge_down(dev);
  502. err = skge_up(dev);
  503. if (err) {
  504. dev_close(dev);
  505. return err;
  506. }
  507. }
  508. return 0;
  509. }
  510. /* Chip internal frequency for clock calculations */
  511. static inline u32 hwkhz(const struct skge_hw *hw)
  512. {
  513. return is_genesis(hw) ? 53125 : 78125;
  514. }
  515. /* Chip HZ to microseconds */
  516. static inline u32 skge_clk2usec(const struct skge_hw *hw, u32 ticks)
  517. {
  518. return (ticks * 1000) / hwkhz(hw);
  519. }
  520. /* Microseconds to chip HZ */
  521. static inline u32 skge_usecs2clk(const struct skge_hw *hw, u32 usec)
  522. {
  523. return hwkhz(hw) * usec / 1000;
  524. }
  525. static int skge_get_coalesce(struct net_device *dev,
  526. struct ethtool_coalesce *ecmd)
  527. {
  528. struct skge_port *skge = netdev_priv(dev);
  529. struct skge_hw *hw = skge->hw;
  530. int port = skge->port;
  531. ecmd->rx_coalesce_usecs = 0;
  532. ecmd->tx_coalesce_usecs = 0;
  533. if (skge_read32(hw, B2_IRQM_CTRL) & TIM_START) {
  534. u32 delay = skge_clk2usec(hw, skge_read32(hw, B2_IRQM_INI));
  535. u32 msk = skge_read32(hw, B2_IRQM_MSK);
  536. if (msk & rxirqmask[port])
  537. ecmd->rx_coalesce_usecs = delay;
  538. if (msk & txirqmask[port])
  539. ecmd->tx_coalesce_usecs = delay;
  540. }
  541. return 0;
  542. }
  543. /* Note: interrupt timer is per board, but can turn on/off per port */
  544. static int skge_set_coalesce(struct net_device *dev,
  545. struct ethtool_coalesce *ecmd)
  546. {
  547. struct skge_port *skge = netdev_priv(dev);
  548. struct skge_hw *hw = skge->hw;
  549. int port = skge->port;
  550. u32 msk = skge_read32(hw, B2_IRQM_MSK);
  551. u32 delay = 25;
  552. if (ecmd->rx_coalesce_usecs == 0)
  553. msk &= ~rxirqmask[port];
  554. else if (ecmd->rx_coalesce_usecs < 25 ||
  555. ecmd->rx_coalesce_usecs > 33333)
  556. return -EINVAL;
  557. else {
  558. msk |= rxirqmask[port];
  559. delay = ecmd->rx_coalesce_usecs;
  560. }
  561. if (ecmd->tx_coalesce_usecs == 0)
  562. msk &= ~txirqmask[port];
  563. else if (ecmd->tx_coalesce_usecs < 25 ||
  564. ecmd->tx_coalesce_usecs > 33333)
  565. return -EINVAL;
  566. else {
  567. msk |= txirqmask[port];
  568. delay = min(delay, ecmd->rx_coalesce_usecs);
  569. }
  570. skge_write32(hw, B2_IRQM_MSK, msk);
  571. if (msk == 0)
  572. skge_write32(hw, B2_IRQM_CTRL, TIM_STOP);
  573. else {
  574. skge_write32(hw, B2_IRQM_INI, skge_usecs2clk(hw, delay));
  575. skge_write32(hw, B2_IRQM_CTRL, TIM_START);
  576. }
  577. return 0;
  578. }
  579. enum led_mode { LED_MODE_OFF, LED_MODE_ON, LED_MODE_TST };
  580. static void skge_led(struct skge_port *skge, enum led_mode mode)
  581. {
  582. struct skge_hw *hw = skge->hw;
  583. int port = skge->port;
  584. spin_lock_bh(&hw->phy_lock);
  585. if (is_genesis(hw)) {
  586. switch (mode) {
  587. case LED_MODE_OFF:
  588. if (hw->phy_type == SK_PHY_BCOM)
  589. xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL, PHY_B_PEC_LED_OFF);
  590. else {
  591. skge_write32(hw, SK_REG(port, TX_LED_VAL), 0);
  592. skge_write8(hw, SK_REG(port, TX_LED_CTRL), LED_T_OFF);
  593. }
  594. skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_OFF);
  595. skge_write32(hw, SK_REG(port, RX_LED_VAL), 0);
  596. skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_T_OFF);
  597. break;
  598. case LED_MODE_ON:
  599. skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_ON);
  600. skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_LINKSYNC_ON);
  601. skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_START);
  602. skge_write8(hw, SK_REG(port, TX_LED_CTRL), LED_START);
  603. break;
  604. case LED_MODE_TST:
  605. skge_write8(hw, SK_REG(port, RX_LED_TST), LED_T_ON);
  606. skge_write32(hw, SK_REG(port, RX_LED_VAL), 100);
  607. skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_START);
  608. if (hw->phy_type == SK_PHY_BCOM)
  609. xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL, PHY_B_PEC_LED_ON);
  610. else {
  611. skge_write8(hw, SK_REG(port, TX_LED_TST), LED_T_ON);
  612. skge_write32(hw, SK_REG(port, TX_LED_VAL), 100);
  613. skge_write8(hw, SK_REG(port, TX_LED_CTRL), LED_START);
  614. }
  615. }
  616. } else {
  617. switch (mode) {
  618. case LED_MODE_OFF:
  619. gm_phy_write(hw, port, PHY_MARV_LED_CTRL, 0);
  620. gm_phy_write(hw, port, PHY_MARV_LED_OVER,
  621. PHY_M_LED_MO_DUP(MO_LED_OFF) |
  622. PHY_M_LED_MO_10(MO_LED_OFF) |
  623. PHY_M_LED_MO_100(MO_LED_OFF) |
  624. PHY_M_LED_MO_1000(MO_LED_OFF) |
  625. PHY_M_LED_MO_RX(MO_LED_OFF));
  626. break;
  627. case LED_MODE_ON:
  628. gm_phy_write(hw, port, PHY_MARV_LED_CTRL,
  629. PHY_M_LED_PULS_DUR(PULS_170MS) |
  630. PHY_M_LED_BLINK_RT(BLINK_84MS) |
  631. PHY_M_LEDC_TX_CTRL |
  632. PHY_M_LEDC_DP_CTRL);
  633. gm_phy_write(hw, port, PHY_MARV_LED_OVER,
  634. PHY_M_LED_MO_RX(MO_LED_OFF) |
  635. (skge->speed == SPEED_100 ?
  636. PHY_M_LED_MO_100(MO_LED_ON) : 0));
  637. break;
  638. case LED_MODE_TST:
  639. gm_phy_write(hw, port, PHY_MARV_LED_CTRL, 0);
  640. gm_phy_write(hw, port, PHY_MARV_LED_OVER,
  641. PHY_M_LED_MO_DUP(MO_LED_ON) |
  642. PHY_M_LED_MO_10(MO_LED_ON) |
  643. PHY_M_LED_MO_100(MO_LED_ON) |
  644. PHY_M_LED_MO_1000(MO_LED_ON) |
  645. PHY_M_LED_MO_RX(MO_LED_ON));
  646. }
  647. }
  648. spin_unlock_bh(&hw->phy_lock);
  649. }
  650. /* blink LED's for finding board */
  651. static int skge_set_phys_id(struct net_device *dev,
  652. enum ethtool_phys_id_state state)
  653. {
  654. struct skge_port *skge = netdev_priv(dev);
  655. switch (state) {
  656. case ETHTOOL_ID_ACTIVE:
  657. return 2; /* cycle on/off twice per second */
  658. case ETHTOOL_ID_ON:
  659. skge_led(skge, LED_MODE_TST);
  660. break;
  661. case ETHTOOL_ID_OFF:
  662. skge_led(skge, LED_MODE_OFF);
  663. break;
  664. case ETHTOOL_ID_INACTIVE:
  665. /* back to regular LED state */
  666. skge_led(skge, netif_running(dev) ? LED_MODE_ON : LED_MODE_OFF);
  667. }
  668. return 0;
  669. }
  670. static int skge_get_eeprom_len(struct net_device *dev)
  671. {
  672. struct skge_port *skge = netdev_priv(dev);
  673. u32 reg2;
  674. pci_read_config_dword(skge->hw->pdev, PCI_DEV_REG2, &reg2);
  675. return 1 << (((reg2 & PCI_VPD_ROM_SZ) >> 14) + 8);
  676. }
  677. static u32 skge_vpd_read(struct pci_dev *pdev, int cap, u16 offset)
  678. {
  679. u32 val;
  680. pci_write_config_word(pdev, cap + PCI_VPD_ADDR, offset);
  681. do {
  682. pci_read_config_word(pdev, cap + PCI_VPD_ADDR, &offset);
  683. } while (!(offset & PCI_VPD_ADDR_F));
  684. pci_read_config_dword(pdev, cap + PCI_VPD_DATA, &val);
  685. return val;
  686. }
  687. static void skge_vpd_write(struct pci_dev *pdev, int cap, u16 offset, u32 val)
  688. {
  689. pci_write_config_dword(pdev, cap + PCI_VPD_DATA, val);
  690. pci_write_config_word(pdev, cap + PCI_VPD_ADDR,
  691. offset | PCI_VPD_ADDR_F);
  692. do {
  693. pci_read_config_word(pdev, cap + PCI_VPD_ADDR, &offset);
  694. } while (offset & PCI_VPD_ADDR_F);
  695. }
  696. static int skge_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
  697. u8 *data)
  698. {
  699. struct skge_port *skge = netdev_priv(dev);
  700. struct pci_dev *pdev = skge->hw->pdev;
  701. int cap = pci_find_capability(pdev, PCI_CAP_ID_VPD);
  702. int length = eeprom->len;
  703. u16 offset = eeprom->offset;
  704. if (!cap)
  705. return -EINVAL;
  706. eeprom->magic = SKGE_EEPROM_MAGIC;
  707. while (length > 0) {
  708. u32 val = skge_vpd_read(pdev, cap, offset);
  709. int n = min_t(int, length, sizeof(val));
  710. memcpy(data, &val, n);
  711. length -= n;
  712. data += n;
  713. offset += n;
  714. }
  715. return 0;
  716. }
  717. static int skge_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
  718. u8 *data)
  719. {
  720. struct skge_port *skge = netdev_priv(dev);
  721. struct pci_dev *pdev = skge->hw->pdev;
  722. int cap = pci_find_capability(pdev, PCI_CAP_ID_VPD);
  723. int length = eeprom->len;
  724. u16 offset = eeprom->offset;
  725. if (!cap)
  726. return -EINVAL;
  727. if (eeprom->magic != SKGE_EEPROM_MAGIC)
  728. return -EINVAL;
  729. while (length > 0) {
  730. u32 val;
  731. int n = min_t(int, length, sizeof(val));
  732. if (n < sizeof(val))
  733. val = skge_vpd_read(pdev, cap, offset);
  734. memcpy(&val, data, n);
  735. skge_vpd_write(pdev, cap, offset, val);
  736. length -= n;
  737. data += n;
  738. offset += n;
  739. }
  740. return 0;
  741. }
  742. static const struct ethtool_ops skge_ethtool_ops = {
  743. .get_drvinfo = skge_get_drvinfo,
  744. .get_regs_len = skge_get_regs_len,
  745. .get_regs = skge_get_regs,
  746. .get_wol = skge_get_wol,
  747. .set_wol = skge_set_wol,
  748. .get_msglevel = skge_get_msglevel,
  749. .set_msglevel = skge_set_msglevel,
  750. .nway_reset = skge_nway_reset,
  751. .get_link = ethtool_op_get_link,
  752. .get_eeprom_len = skge_get_eeprom_len,
  753. .get_eeprom = skge_get_eeprom,
  754. .set_eeprom = skge_set_eeprom,
  755. .get_ringparam = skge_get_ring_param,
  756. .set_ringparam = skge_set_ring_param,
  757. .get_pauseparam = skge_get_pauseparam,
  758. .set_pauseparam = skge_set_pauseparam,
  759. .get_coalesce = skge_get_coalesce,
  760. .set_coalesce = skge_set_coalesce,
  761. .get_strings = skge_get_strings,
  762. .set_phys_id = skge_set_phys_id,
  763. .get_sset_count = skge_get_sset_count,
  764. .get_ethtool_stats = skge_get_ethtool_stats,
  765. .get_link_ksettings = skge_get_link_ksettings,
  766. .set_link_ksettings = skge_set_link_ksettings,
  767. };
  768. /*
  769. * Allocate ring elements and chain them together
  770. * One-to-one association of board descriptors with ring elements
  771. */
  772. static int skge_ring_alloc(struct skge_ring *ring, void *vaddr, u32 base)
  773. {
  774. struct skge_tx_desc *d;
  775. struct skge_element *e;
  776. int i;
  777. ring->start = kcalloc(ring->count, sizeof(*e), GFP_KERNEL);
  778. if (!ring->start)
  779. return -ENOMEM;
  780. for (i = 0, e = ring->start, d = vaddr; i < ring->count; i++, e++, d++) {
  781. e->desc = d;
  782. if (i == ring->count - 1) {
  783. e->next = ring->start;
  784. d->next_offset = base;
  785. } else {
  786. e->next = e + 1;
  787. d->next_offset = base + (i+1) * sizeof(*d);
  788. }
  789. }
  790. ring->to_use = ring->to_clean = ring->start;
  791. return 0;
  792. }
  793. /* Allocate and setup a new buffer for receiving */
  794. static int skge_rx_setup(struct skge_port *skge, struct skge_element *e,
  795. struct sk_buff *skb, unsigned int bufsize)
  796. {
  797. struct skge_rx_desc *rd = e->desc;
  798. dma_addr_t map;
  799. map = pci_map_single(skge->hw->pdev, skb->data, bufsize,
  800. PCI_DMA_FROMDEVICE);
  801. if (pci_dma_mapping_error(skge->hw->pdev, map))
  802. return -1;
  803. rd->dma_lo = lower_32_bits(map);
  804. rd->dma_hi = upper_32_bits(map);
  805. e->skb = skb;
  806. rd->csum1_start = ETH_HLEN;
  807. rd->csum2_start = ETH_HLEN;
  808. rd->csum1 = 0;
  809. rd->csum2 = 0;
  810. wmb();
  811. rd->control = BMU_OWN | BMU_STF | BMU_IRQ_EOF | BMU_TCP_CHECK | bufsize;
  812. dma_unmap_addr_set(e, mapaddr, map);
  813. dma_unmap_len_set(e, maplen, bufsize);
  814. return 0;
  815. }
  816. /* Resume receiving using existing skb,
  817. * Note: DMA address is not changed by chip.
  818. * MTU not changed while receiver active.
  819. */
  820. static inline void skge_rx_reuse(struct skge_element *e, unsigned int size)
  821. {
  822. struct skge_rx_desc *rd = e->desc;
  823. rd->csum2 = 0;
  824. rd->csum2_start = ETH_HLEN;
  825. wmb();
  826. rd->control = BMU_OWN | BMU_STF | BMU_IRQ_EOF | BMU_TCP_CHECK | size;
  827. }
  828. /* Free all buffers in receive ring, assumes receiver stopped */
  829. static void skge_rx_clean(struct skge_port *skge)
  830. {
  831. struct skge_hw *hw = skge->hw;
  832. struct skge_ring *ring = &skge->rx_ring;
  833. struct skge_element *e;
  834. e = ring->start;
  835. do {
  836. struct skge_rx_desc *rd = e->desc;
  837. rd->control = 0;
  838. if (e->skb) {
  839. pci_unmap_single(hw->pdev,
  840. dma_unmap_addr(e, mapaddr),
  841. dma_unmap_len(e, maplen),
  842. PCI_DMA_FROMDEVICE);
  843. dev_kfree_skb(e->skb);
  844. e->skb = NULL;
  845. }
  846. } while ((e = e->next) != ring->start);
  847. }
  848. /* Allocate buffers for receive ring
  849. * For receive: to_clean is next received frame.
  850. */
  851. static int skge_rx_fill(struct net_device *dev)
  852. {
  853. struct skge_port *skge = netdev_priv(dev);
  854. struct skge_ring *ring = &skge->rx_ring;
  855. struct skge_element *e;
  856. e = ring->start;
  857. do {
  858. struct sk_buff *skb;
  859. skb = __netdev_alloc_skb(dev, skge->rx_buf_size + NET_IP_ALIGN,
  860. GFP_KERNEL);
  861. if (!skb)
  862. return -ENOMEM;
  863. skb_reserve(skb, NET_IP_ALIGN);
  864. if (skge_rx_setup(skge, e, skb, skge->rx_buf_size) < 0) {
  865. dev_kfree_skb(skb);
  866. return -EIO;
  867. }
  868. } while ((e = e->next) != ring->start);
  869. ring->to_clean = ring->start;
  870. return 0;
  871. }
  872. static const char *skge_pause(enum pause_status status)
  873. {
  874. switch (status) {
  875. case FLOW_STAT_NONE:
  876. return "none";
  877. case FLOW_STAT_REM_SEND:
  878. return "rx only";
  879. case FLOW_STAT_LOC_SEND:
  880. return "tx_only";
  881. case FLOW_STAT_SYMMETRIC: /* Both station may send PAUSE */
  882. return "both";
  883. default:
  884. return "indeterminated";
  885. }
  886. }
  887. static void skge_link_up(struct skge_port *skge)
  888. {
  889. skge_write8(skge->hw, SK_REG(skge->port, LNK_LED_REG),
  890. LED_BLK_OFF|LED_SYNC_OFF|LED_REG_ON);
  891. netif_carrier_on(skge->netdev);
  892. netif_wake_queue(skge->netdev);
  893. netif_info(skge, link, skge->netdev,
  894. "Link is up at %d Mbps, %s duplex, flow control %s\n",
  895. skge->speed,
  896. skge->duplex == DUPLEX_FULL ? "full" : "half",
  897. skge_pause(skge->flow_status));
  898. }
  899. static void skge_link_down(struct skge_port *skge)
  900. {
  901. skge_write8(skge->hw, SK_REG(skge->port, LNK_LED_REG), LED_REG_OFF);
  902. netif_carrier_off(skge->netdev);
  903. netif_stop_queue(skge->netdev);
  904. netif_info(skge, link, skge->netdev, "Link is down\n");
  905. }
  906. static void xm_link_down(struct skge_hw *hw, int port)
  907. {
  908. struct net_device *dev = hw->dev[port];
  909. struct skge_port *skge = netdev_priv(dev);
  910. xm_write16(hw, port, XM_IMSK, XM_IMSK_DISABLE);
  911. if (netif_carrier_ok(dev))
  912. skge_link_down(skge);
  913. }
  914. static int __xm_phy_read(struct skge_hw *hw, int port, u16 reg, u16 *val)
  915. {
  916. int i;
  917. xm_write16(hw, port, XM_PHY_ADDR, reg | hw->phy_addr);
  918. *val = xm_read16(hw, port, XM_PHY_DATA);
  919. if (hw->phy_type == SK_PHY_XMAC)
  920. goto ready;
  921. for (i = 0; i < PHY_RETRIES; i++) {
  922. if (xm_read16(hw, port, XM_MMU_CMD) & XM_MMU_PHY_RDY)
  923. goto ready;
  924. udelay(1);
  925. }
  926. return -ETIMEDOUT;
  927. ready:
  928. *val = xm_read16(hw, port, XM_PHY_DATA);
  929. return 0;
  930. }
  931. static u16 xm_phy_read(struct skge_hw *hw, int port, u16 reg)
  932. {
  933. u16 v = 0;
  934. if (__xm_phy_read(hw, port, reg, &v))
  935. pr_warn("%s: phy read timed out\n", hw->dev[port]->name);
  936. return v;
  937. }
  938. static int xm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val)
  939. {
  940. int i;
  941. xm_write16(hw, port, XM_PHY_ADDR, reg | hw->phy_addr);
  942. for (i = 0; i < PHY_RETRIES; i++) {
  943. if (!(xm_read16(hw, port, XM_MMU_CMD) & XM_MMU_PHY_BUSY))
  944. goto ready;
  945. udelay(1);
  946. }
  947. return -EIO;
  948. ready:
  949. xm_write16(hw, port, XM_PHY_DATA, val);
  950. for (i = 0; i < PHY_RETRIES; i++) {
  951. if (!(xm_read16(hw, port, XM_MMU_CMD) & XM_MMU_PHY_BUSY))
  952. return 0;
  953. udelay(1);
  954. }
  955. return -ETIMEDOUT;
  956. }
  957. static void genesis_init(struct skge_hw *hw)
  958. {
  959. /* set blink source counter */
  960. skge_write32(hw, B2_BSC_INI, (SK_BLK_DUR * SK_FACT_53) / 100);
  961. skge_write8(hw, B2_BSC_CTRL, BSC_START);
  962. /* configure mac arbiter */
  963. skge_write16(hw, B3_MA_TO_CTRL, MA_RST_CLR);
  964. /* configure mac arbiter timeout values */
  965. skge_write8(hw, B3_MA_TOINI_RX1, SK_MAC_TO_53);
  966. skge_write8(hw, B3_MA_TOINI_RX2, SK_MAC_TO_53);
  967. skge_write8(hw, B3_MA_TOINI_TX1, SK_MAC_TO_53);
  968. skge_write8(hw, B3_MA_TOINI_TX2, SK_MAC_TO_53);
  969. skge_write8(hw, B3_MA_RCINI_RX1, 0);
  970. skge_write8(hw, B3_MA_RCINI_RX2, 0);
  971. skge_write8(hw, B3_MA_RCINI_TX1, 0);
  972. skge_write8(hw, B3_MA_RCINI_TX2, 0);
  973. /* configure packet arbiter timeout */
  974. skge_write16(hw, B3_PA_CTRL, PA_RST_CLR);
  975. skge_write16(hw, B3_PA_TOINI_RX1, SK_PKT_TO_MAX);
  976. skge_write16(hw, B3_PA_TOINI_TX1, SK_PKT_TO_MAX);
  977. skge_write16(hw, B3_PA_TOINI_RX2, SK_PKT_TO_MAX);
  978. skge_write16(hw, B3_PA_TOINI_TX2, SK_PKT_TO_MAX);
  979. }
  980. static void genesis_reset(struct skge_hw *hw, int port)
  981. {
  982. static const u8 zero[8] = { 0 };
  983. u32 reg;
  984. skge_write8(hw, SK_REG(port, GMAC_IRQ_MSK), 0);
  985. /* reset the statistics module */
  986. xm_write32(hw, port, XM_GP_PORT, XM_GP_RES_STAT);
  987. xm_write16(hw, port, XM_IMSK, XM_IMSK_DISABLE);
  988. xm_write32(hw, port, XM_MODE, 0); /* clear Mode Reg */
  989. xm_write16(hw, port, XM_TX_CMD, 0); /* reset TX CMD Reg */
  990. xm_write16(hw, port, XM_RX_CMD, 0); /* reset RX CMD Reg */
  991. /* disable Broadcom PHY IRQ */
  992. if (hw->phy_type == SK_PHY_BCOM)
  993. xm_write16(hw, port, PHY_BCOM_INT_MASK, 0xffff);
  994. xm_outhash(hw, port, XM_HSM, zero);
  995. /* Flush TX and RX fifo */
  996. reg = xm_read32(hw, port, XM_MODE);
  997. xm_write32(hw, port, XM_MODE, reg | XM_MD_FTF);
  998. xm_write32(hw, port, XM_MODE, reg | XM_MD_FRF);
  999. }
  1000. /* Convert mode to MII values */
  1001. static const u16 phy_pause_map[] = {
  1002. [FLOW_MODE_NONE] = 0,
  1003. [FLOW_MODE_LOC_SEND] = PHY_AN_PAUSE_ASYM,
  1004. [FLOW_MODE_SYMMETRIC] = PHY_AN_PAUSE_CAP,
  1005. [FLOW_MODE_SYM_OR_REM] = PHY_AN_PAUSE_CAP | PHY_AN_PAUSE_ASYM,
  1006. };
  1007. /* special defines for FIBER (88E1011S only) */
  1008. static const u16 fiber_pause_map[] = {
  1009. [FLOW_MODE_NONE] = PHY_X_P_NO_PAUSE,
  1010. [FLOW_MODE_LOC_SEND] = PHY_X_P_ASYM_MD,
  1011. [FLOW_MODE_SYMMETRIC] = PHY_X_P_SYM_MD,
  1012. [FLOW_MODE_SYM_OR_REM] = PHY_X_P_BOTH_MD,
  1013. };
  1014. /* Check status of Broadcom phy link */
  1015. static void bcom_check_link(struct skge_hw *hw, int port)
  1016. {
  1017. struct net_device *dev = hw->dev[port];
  1018. struct skge_port *skge = netdev_priv(dev);
  1019. u16 status;
  1020. /* read twice because of latch */
  1021. xm_phy_read(hw, port, PHY_BCOM_STAT);
  1022. status = xm_phy_read(hw, port, PHY_BCOM_STAT);
  1023. if ((status & PHY_ST_LSYNC) == 0) {
  1024. xm_link_down(hw, port);
  1025. return;
  1026. }
  1027. if (skge->autoneg == AUTONEG_ENABLE) {
  1028. u16 lpa, aux;
  1029. if (!(status & PHY_ST_AN_OVER))
  1030. return;
  1031. lpa = xm_phy_read(hw, port, PHY_XMAC_AUNE_LP);
  1032. if (lpa & PHY_B_AN_RF) {
  1033. netdev_notice(dev, "remote fault\n");
  1034. return;
  1035. }
  1036. aux = xm_phy_read(hw, port, PHY_BCOM_AUX_STAT);
  1037. /* Check Duplex mismatch */
  1038. switch (aux & PHY_B_AS_AN_RES_MSK) {
  1039. case PHY_B_RES_1000FD:
  1040. skge->duplex = DUPLEX_FULL;
  1041. break;
  1042. case PHY_B_RES_1000HD:
  1043. skge->duplex = DUPLEX_HALF;
  1044. break;
  1045. default:
  1046. netdev_notice(dev, "duplex mismatch\n");
  1047. return;
  1048. }
  1049. /* We are using IEEE 802.3z/D5.0 Table 37-4 */
  1050. switch (aux & PHY_B_AS_PAUSE_MSK) {
  1051. case PHY_B_AS_PAUSE_MSK:
  1052. skge->flow_status = FLOW_STAT_SYMMETRIC;
  1053. break;
  1054. case PHY_B_AS_PRR:
  1055. skge->flow_status = FLOW_STAT_REM_SEND;
  1056. break;
  1057. case PHY_B_AS_PRT:
  1058. skge->flow_status = FLOW_STAT_LOC_SEND;
  1059. break;
  1060. default:
  1061. skge->flow_status = FLOW_STAT_NONE;
  1062. }
  1063. skge->speed = SPEED_1000;
  1064. }
  1065. if (!netif_carrier_ok(dev))
  1066. genesis_link_up(skge);
  1067. }
  1068. /* Broadcom 5400 only supports giagabit! SysKonnect did not put an additional
  1069. * Phy on for 100 or 10Mbit operation
  1070. */
  1071. static void bcom_phy_init(struct skge_port *skge)
  1072. {
  1073. struct skge_hw *hw = skge->hw;
  1074. int port = skge->port;
  1075. int i;
  1076. u16 id1, r, ext, ctl;
  1077. /* magic workaround patterns for Broadcom */
  1078. static const struct {
  1079. u16 reg;
  1080. u16 val;
  1081. } A1hack[] = {
  1082. { 0x18, 0x0c20 }, { 0x17, 0x0012 }, { 0x15, 0x1104 },
  1083. { 0x17, 0x0013 }, { 0x15, 0x0404 }, { 0x17, 0x8006 },
  1084. { 0x15, 0x0132 }, { 0x17, 0x8006 }, { 0x15, 0x0232 },
  1085. { 0x17, 0x800D }, { 0x15, 0x000F }, { 0x18, 0x0420 },
  1086. }, C0hack[] = {
  1087. { 0x18, 0x0c20 }, { 0x17, 0x0012 }, { 0x15, 0x1204 },
  1088. { 0x17, 0x0013 }, { 0x15, 0x0A04 }, { 0x18, 0x0420 },
  1089. };
  1090. /* read Id from external PHY (all have the same address) */
  1091. id1 = xm_phy_read(hw, port, PHY_XMAC_ID1);
  1092. /* Optimize MDIO transfer by suppressing preamble. */
  1093. r = xm_read16(hw, port, XM_MMU_CMD);
  1094. r |= XM_MMU_NO_PRE;
  1095. xm_write16(hw, port, XM_MMU_CMD, r);
  1096. switch (id1) {
  1097. case PHY_BCOM_ID1_C0:
  1098. /*
  1099. * Workaround BCOM Errata for the C0 type.
  1100. * Write magic patterns to reserved registers.
  1101. */
  1102. for (i = 0; i < ARRAY_SIZE(C0hack); i++)
  1103. xm_phy_write(hw, port,
  1104. C0hack[i].reg, C0hack[i].val);
  1105. break;
  1106. case PHY_BCOM_ID1_A1:
  1107. /*
  1108. * Workaround BCOM Errata for the A1 type.
  1109. * Write magic patterns to reserved registers.
  1110. */
  1111. for (i = 0; i < ARRAY_SIZE(A1hack); i++)
  1112. xm_phy_write(hw, port,
  1113. A1hack[i].reg, A1hack[i].val);
  1114. break;
  1115. }
  1116. /*
  1117. * Workaround BCOM Errata (#10523) for all BCom PHYs.
  1118. * Disable Power Management after reset.
  1119. */
  1120. r = xm_phy_read(hw, port, PHY_BCOM_AUX_CTRL);
  1121. r |= PHY_B_AC_DIS_PM;
  1122. xm_phy_write(hw, port, PHY_BCOM_AUX_CTRL, r);
  1123. /* Dummy read */
  1124. xm_read16(hw, port, XM_ISRC);
  1125. ext = PHY_B_PEC_EN_LTR; /* enable tx led */
  1126. ctl = PHY_CT_SP1000; /* always 1000mbit */
  1127. if (skge->autoneg == AUTONEG_ENABLE) {
  1128. /*
  1129. * Workaround BCOM Errata #1 for the C5 type.
  1130. * 1000Base-T Link Acquisition Failure in Slave Mode
  1131. * Set Repeater/DTE bit 10 of the 1000Base-T Control Register
  1132. */
  1133. u16 adv = PHY_B_1000C_RD;
  1134. if (skge->advertising & ADVERTISED_1000baseT_Half)
  1135. adv |= PHY_B_1000C_AHD;
  1136. if (skge->advertising & ADVERTISED_1000baseT_Full)
  1137. adv |= PHY_B_1000C_AFD;
  1138. xm_phy_write(hw, port, PHY_BCOM_1000T_CTRL, adv);
  1139. ctl |= PHY_CT_ANE | PHY_CT_RE_CFG;
  1140. } else {
  1141. if (skge->duplex == DUPLEX_FULL)
  1142. ctl |= PHY_CT_DUP_MD;
  1143. /* Force to slave */
  1144. xm_phy_write(hw, port, PHY_BCOM_1000T_CTRL, PHY_B_1000C_MSE);
  1145. }
  1146. /* Set autonegotiation pause parameters */
  1147. xm_phy_write(hw, port, PHY_BCOM_AUNE_ADV,
  1148. phy_pause_map[skge->flow_control] | PHY_AN_CSMA);
  1149. /* Handle Jumbo frames */
  1150. if (hw->dev[port]->mtu > ETH_DATA_LEN) {
  1151. xm_phy_write(hw, port, PHY_BCOM_AUX_CTRL,
  1152. PHY_B_AC_TX_TST | PHY_B_AC_LONG_PACK);
  1153. ext |= PHY_B_PEC_HIGH_LA;
  1154. }
  1155. xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL, ext);
  1156. xm_phy_write(hw, port, PHY_BCOM_CTRL, ctl);
  1157. /* Use link status change interrupt */
  1158. xm_phy_write(hw, port, PHY_BCOM_INT_MASK, PHY_B_DEF_MSK);
  1159. }
  1160. static void xm_phy_init(struct skge_port *skge)
  1161. {
  1162. struct skge_hw *hw = skge->hw;
  1163. int port = skge->port;
  1164. u16 ctrl = 0;
  1165. if (skge->autoneg == AUTONEG_ENABLE) {
  1166. if (skge->advertising & ADVERTISED_1000baseT_Half)
  1167. ctrl |= PHY_X_AN_HD;
  1168. if (skge->advertising & ADVERTISED_1000baseT_Full)
  1169. ctrl |= PHY_X_AN_FD;
  1170. ctrl |= fiber_pause_map[skge->flow_control];
  1171. xm_phy_write(hw, port, PHY_XMAC_AUNE_ADV, ctrl);
  1172. /* Restart Auto-negotiation */
  1173. ctrl = PHY_CT_ANE | PHY_CT_RE_CFG;
  1174. } else {
  1175. /* Set DuplexMode in Config register */
  1176. if (skge->duplex == DUPLEX_FULL)
  1177. ctrl |= PHY_CT_DUP_MD;
  1178. /*
  1179. * Do NOT enable Auto-negotiation here. This would hold
  1180. * the link down because no IDLEs are transmitted
  1181. */
  1182. }
  1183. xm_phy_write(hw, port, PHY_XMAC_CTRL, ctrl);
  1184. /* Poll PHY for status changes */
  1185. mod_timer(&skge->link_timer, jiffies + LINK_HZ);
  1186. }
  1187. static int xm_check_link(struct net_device *dev)
  1188. {
  1189. struct skge_port *skge = netdev_priv(dev);
  1190. struct skge_hw *hw = skge->hw;
  1191. int port = skge->port;
  1192. u16 status;
  1193. /* read twice because of latch */
  1194. xm_phy_read(hw, port, PHY_XMAC_STAT);
  1195. status = xm_phy_read(hw, port, PHY_XMAC_STAT);
  1196. if ((status & PHY_ST_LSYNC) == 0) {
  1197. xm_link_down(hw, port);
  1198. return 0;
  1199. }
  1200. if (skge->autoneg == AUTONEG_ENABLE) {
  1201. u16 lpa, res;
  1202. if (!(status & PHY_ST_AN_OVER))
  1203. return 0;
  1204. lpa = xm_phy_read(hw, port, PHY_XMAC_AUNE_LP);
  1205. if (lpa & PHY_B_AN_RF) {
  1206. netdev_notice(dev, "remote fault\n");
  1207. return 0;
  1208. }
  1209. res = xm_phy_read(hw, port, PHY_XMAC_RES_ABI);
  1210. /* Check Duplex mismatch */
  1211. switch (res & (PHY_X_RS_HD | PHY_X_RS_FD)) {
  1212. case PHY_X_RS_FD:
  1213. skge->duplex = DUPLEX_FULL;
  1214. break;
  1215. case PHY_X_RS_HD:
  1216. skge->duplex = DUPLEX_HALF;
  1217. break;
  1218. default:
  1219. netdev_notice(dev, "duplex mismatch\n");
  1220. return 0;
  1221. }
  1222. /* We are using IEEE 802.3z/D5.0 Table 37-4 */
  1223. if ((skge->flow_control == FLOW_MODE_SYMMETRIC ||
  1224. skge->flow_control == FLOW_MODE_SYM_OR_REM) &&
  1225. (lpa & PHY_X_P_SYM_MD))
  1226. skge->flow_status = FLOW_STAT_SYMMETRIC;
  1227. else if (skge->flow_control == FLOW_MODE_SYM_OR_REM &&
  1228. (lpa & PHY_X_RS_PAUSE) == PHY_X_P_ASYM_MD)
  1229. /* Enable PAUSE receive, disable PAUSE transmit */
  1230. skge->flow_status = FLOW_STAT_REM_SEND;
  1231. else if (skge->flow_control == FLOW_MODE_LOC_SEND &&
  1232. (lpa & PHY_X_RS_PAUSE) == PHY_X_P_BOTH_MD)
  1233. /* Disable PAUSE receive, enable PAUSE transmit */
  1234. skge->flow_status = FLOW_STAT_LOC_SEND;
  1235. else
  1236. skge->flow_status = FLOW_STAT_NONE;
  1237. skge->speed = SPEED_1000;
  1238. }
  1239. if (!netif_carrier_ok(dev))
  1240. genesis_link_up(skge);
  1241. return 1;
  1242. }
  1243. /* Poll to check for link coming up.
  1244. *
  1245. * Since internal PHY is wired to a level triggered pin, can't
  1246. * get an interrupt when carrier is detected, need to poll for
  1247. * link coming up.
  1248. */
  1249. static void xm_link_timer(struct timer_list *t)
  1250. {
  1251. struct skge_port *skge = from_timer(skge, t, link_timer);
  1252. struct net_device *dev = skge->netdev;
  1253. struct skge_hw *hw = skge->hw;
  1254. int port = skge->port;
  1255. int i;
  1256. unsigned long flags;
  1257. if (!netif_running(dev))
  1258. return;
  1259. spin_lock_irqsave(&hw->phy_lock, flags);
  1260. /*
  1261. * Verify that the link by checking GPIO register three times.
  1262. * This pin has the signal from the link_sync pin connected to it.
  1263. */
  1264. for (i = 0; i < 3; i++) {
  1265. if (xm_read16(hw, port, XM_GP_PORT) & XM_GP_INP_ASS)
  1266. goto link_down;
  1267. }
  1268. /* Re-enable interrupt to detect link down */
  1269. if (xm_check_link(dev)) {
  1270. u16 msk = xm_read16(hw, port, XM_IMSK);
  1271. msk &= ~XM_IS_INP_ASS;
  1272. xm_write16(hw, port, XM_IMSK, msk);
  1273. xm_read16(hw, port, XM_ISRC);
  1274. } else {
  1275. link_down:
  1276. mod_timer(&skge->link_timer,
  1277. round_jiffies(jiffies + LINK_HZ));
  1278. }
  1279. spin_unlock_irqrestore(&hw->phy_lock, flags);
  1280. }
  1281. static void genesis_mac_init(struct skge_hw *hw, int port)
  1282. {
  1283. struct net_device *dev = hw->dev[port];
  1284. struct skge_port *skge = netdev_priv(dev);
  1285. int jumbo = hw->dev[port]->mtu > ETH_DATA_LEN;
  1286. int i;
  1287. u32 r;
  1288. static const u8 zero[6] = { 0 };
  1289. for (i = 0; i < 10; i++) {
  1290. skge_write16(hw, SK_REG(port, TX_MFF_CTRL1),
  1291. MFF_SET_MAC_RST);
  1292. if (skge_read16(hw, SK_REG(port, TX_MFF_CTRL1)) & MFF_SET_MAC_RST)
  1293. goto reset_ok;
  1294. udelay(1);
  1295. }
  1296. netdev_warn(dev, "genesis reset failed\n");
  1297. reset_ok:
  1298. /* Unreset the XMAC. */
  1299. skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_CLR_MAC_RST);
  1300. /*
  1301. * Perform additional initialization for external PHYs,
  1302. * namely for the 1000baseTX cards that use the XMAC's
  1303. * GMII mode.
  1304. */
  1305. if (hw->phy_type != SK_PHY_XMAC) {
  1306. /* Take external Phy out of reset */
  1307. r = skge_read32(hw, B2_GP_IO);
  1308. if (port == 0)
  1309. r |= GP_DIR_0|GP_IO_0;
  1310. else
  1311. r |= GP_DIR_2|GP_IO_2;
  1312. skge_write32(hw, B2_GP_IO, r);
  1313. /* Enable GMII interface */
  1314. xm_write16(hw, port, XM_HW_CFG, XM_HW_GMII_MD);
  1315. }
  1316. switch (hw->phy_type) {
  1317. case SK_PHY_XMAC:
  1318. xm_phy_init(skge);
  1319. break;
  1320. case SK_PHY_BCOM:
  1321. bcom_phy_init(skge);
  1322. bcom_check_link(hw, port);
  1323. }
  1324. /* Set Station Address */
  1325. xm_outaddr(hw, port, XM_SA, dev->dev_addr);
  1326. /* We don't use match addresses so clear */
  1327. for (i = 1; i < 16; i++)
  1328. xm_outaddr(hw, port, XM_EXM(i), zero);
  1329. /* Clear MIB counters */
  1330. xm_write16(hw, port, XM_STAT_CMD,
  1331. XM_SC_CLR_RXC | XM_SC_CLR_TXC);
  1332. /* Clear two times according to Errata #3 */
  1333. xm_write16(hw, port, XM_STAT_CMD,
  1334. XM_SC_CLR_RXC | XM_SC_CLR_TXC);
  1335. /* configure Rx High Water Mark (XM_RX_HI_WM) */
  1336. xm_write16(hw, port, XM_RX_HI_WM, 1450);
  1337. /* We don't need the FCS appended to the packet. */
  1338. r = XM_RX_LENERR_OK | XM_RX_STRIP_FCS;
  1339. if (jumbo)
  1340. r |= XM_RX_BIG_PK_OK;
  1341. if (skge->duplex == DUPLEX_HALF) {
  1342. /*
  1343. * If in manual half duplex mode the other side might be in
  1344. * full duplex mode, so ignore if a carrier extension is not seen
  1345. * on frames received
  1346. */
  1347. r |= XM_RX_DIS_CEXT;
  1348. }
  1349. xm_write16(hw, port, XM_RX_CMD, r);
  1350. /* We want short frames padded to 60 bytes. */
  1351. xm_write16(hw, port, XM_TX_CMD, XM_TX_AUTO_PAD);
  1352. /* Increase threshold for jumbo frames on dual port */
  1353. if (hw->ports > 1 && jumbo)
  1354. xm_write16(hw, port, XM_TX_THR, 1020);
  1355. else
  1356. xm_write16(hw, port, XM_TX_THR, 512);
  1357. /*
  1358. * Enable the reception of all error frames. This is is
  1359. * a necessary evil due to the design of the XMAC. The
  1360. * XMAC's receive FIFO is only 8K in size, however jumbo
  1361. * frames can be up to 9000 bytes in length. When bad
  1362. * frame filtering is enabled, the XMAC's RX FIFO operates
  1363. * in 'store and forward' mode. For this to work, the
  1364. * entire frame has to fit into the FIFO, but that means
  1365. * that jumbo frames larger than 8192 bytes will be
  1366. * truncated. Disabling all bad frame filtering causes
  1367. * the RX FIFO to operate in streaming mode, in which
  1368. * case the XMAC will start transferring frames out of the
  1369. * RX FIFO as soon as the FIFO threshold is reached.
  1370. */
  1371. xm_write32(hw, port, XM_MODE, XM_DEF_MODE);
  1372. /*
  1373. * Initialize the Receive Counter Event Mask (XM_RX_EV_MSK)
  1374. * - Enable all bits excepting 'Octets Rx OK Low CntOv'
  1375. * and 'Octets Rx OK Hi Cnt Ov'.
  1376. */
  1377. xm_write32(hw, port, XM_RX_EV_MSK, XMR_DEF_MSK);
  1378. /*
  1379. * Initialize the Transmit Counter Event Mask (XM_TX_EV_MSK)
  1380. * - Enable all bits excepting 'Octets Tx OK Low CntOv'
  1381. * and 'Octets Tx OK Hi Cnt Ov'.
  1382. */
  1383. xm_write32(hw, port, XM_TX_EV_MSK, XMT_DEF_MSK);
  1384. /* Configure MAC arbiter */
  1385. skge_write16(hw, B3_MA_TO_CTRL, MA_RST_CLR);
  1386. /* configure timeout values */
  1387. skge_write8(hw, B3_MA_TOINI_RX1, 72);
  1388. skge_write8(hw, B3_MA_TOINI_RX2, 72);
  1389. skge_write8(hw, B3_MA_TOINI_TX1, 72);
  1390. skge_write8(hw, B3_MA_TOINI_TX2, 72);
  1391. skge_write8(hw, B3_MA_RCINI_RX1, 0);
  1392. skge_write8(hw, B3_MA_RCINI_RX2, 0);
  1393. skge_write8(hw, B3_MA_RCINI_TX1, 0);
  1394. skge_write8(hw, B3_MA_RCINI_TX2, 0);
  1395. /* Configure Rx MAC FIFO */
  1396. skge_write8(hw, SK_REG(port, RX_MFF_CTRL2), MFF_RST_CLR);
  1397. skge_write16(hw, SK_REG(port, RX_MFF_CTRL1), MFF_ENA_TIM_PAT);
  1398. skge_write8(hw, SK_REG(port, RX_MFF_CTRL2), MFF_ENA_OP_MD);
  1399. /* Configure Tx MAC FIFO */
  1400. skge_write8(hw, SK_REG(port, TX_MFF_CTRL2), MFF_RST_CLR);
  1401. skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_TX_CTRL_DEF);
  1402. skge_write8(hw, SK_REG(port, TX_MFF_CTRL2), MFF_ENA_OP_MD);
  1403. if (jumbo) {
  1404. /* Enable frame flushing if jumbo frames used */
  1405. skge_write16(hw, SK_REG(port, RX_MFF_CTRL1), MFF_ENA_FLUSH);
  1406. } else {
  1407. /* enable timeout timers if normal frames */
  1408. skge_write16(hw, B3_PA_CTRL,
  1409. (port == 0) ? PA_ENA_TO_TX1 : PA_ENA_TO_TX2);
  1410. }
  1411. }
  1412. static void genesis_stop(struct skge_port *skge)
  1413. {
  1414. struct skge_hw *hw = skge->hw;
  1415. int port = skge->port;
  1416. unsigned retries = 1000;
  1417. u16 cmd;
  1418. /* Disable Tx and Rx */
  1419. cmd = xm_read16(hw, port, XM_MMU_CMD);
  1420. cmd &= ~(XM_MMU_ENA_RX | XM_MMU_ENA_TX);
  1421. xm_write16(hw, port, XM_MMU_CMD, cmd);
  1422. genesis_reset(hw, port);
  1423. /* Clear Tx packet arbiter timeout IRQ */
  1424. skge_write16(hw, B3_PA_CTRL,
  1425. port == 0 ? PA_CLR_TO_TX1 : PA_CLR_TO_TX2);
  1426. /* Reset the MAC */
  1427. skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_CLR_MAC_RST);
  1428. do {
  1429. skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_SET_MAC_RST);
  1430. if (!(skge_read16(hw, SK_REG(port, TX_MFF_CTRL1)) & MFF_SET_MAC_RST))
  1431. break;
  1432. } while (--retries > 0);
  1433. /* For external PHYs there must be special handling */
  1434. if (hw->phy_type != SK_PHY_XMAC) {
  1435. u32 reg = skge_read32(hw, B2_GP_IO);
  1436. if (port == 0) {
  1437. reg |= GP_DIR_0;
  1438. reg &= ~GP_IO_0;
  1439. } else {
  1440. reg |= GP_DIR_2;
  1441. reg &= ~GP_IO_2;
  1442. }
  1443. skge_write32(hw, B2_GP_IO, reg);
  1444. skge_read32(hw, B2_GP_IO);
  1445. }
  1446. xm_write16(hw, port, XM_MMU_CMD,
  1447. xm_read16(hw, port, XM_MMU_CMD)
  1448. & ~(XM_MMU_ENA_RX | XM_MMU_ENA_TX));
  1449. xm_read16(hw, port, XM_MMU_CMD);
  1450. }
  1451. static void genesis_get_stats(struct skge_port *skge, u64 *data)
  1452. {
  1453. struct skge_hw *hw = skge->hw;
  1454. int port = skge->port;
  1455. int i;
  1456. unsigned long timeout = jiffies + HZ;
  1457. xm_write16(hw, port,
  1458. XM_STAT_CMD, XM_SC_SNP_TXC | XM_SC_SNP_RXC);
  1459. /* wait for update to complete */
  1460. while (xm_read16(hw, port, XM_STAT_CMD)
  1461. & (XM_SC_SNP_TXC | XM_SC_SNP_RXC)) {
  1462. if (time_after(jiffies, timeout))
  1463. break;
  1464. udelay(10);
  1465. }
  1466. /* special case for 64 bit octet counter */
  1467. data[0] = (u64) xm_read32(hw, port, XM_TXO_OK_HI) << 32
  1468. | xm_read32(hw, port, XM_TXO_OK_LO);
  1469. data[1] = (u64) xm_read32(hw, port, XM_RXO_OK_HI) << 32
  1470. | xm_read32(hw, port, XM_RXO_OK_LO);
  1471. for (i = 2; i < ARRAY_SIZE(skge_stats); i++)
  1472. data[i] = xm_read32(hw, port, skge_stats[i].xmac_offset);
  1473. }
  1474. static void genesis_mac_intr(struct skge_hw *hw, int port)
  1475. {
  1476. struct net_device *dev = hw->dev[port];
  1477. struct skge_port *skge = netdev_priv(dev);
  1478. u16 status = xm_read16(hw, port, XM_ISRC);
  1479. netif_printk(skge, intr, KERN_DEBUG, skge->netdev,
  1480. "mac interrupt status 0x%x\n", status);
  1481. if (hw->phy_type == SK_PHY_XMAC && (status & XM_IS_INP_ASS)) {
  1482. xm_link_down(hw, port);
  1483. mod_timer(&skge->link_timer, jiffies + 1);
  1484. }
  1485. if (status & XM_IS_TXF_UR) {
  1486. xm_write32(hw, port, XM_MODE, XM_MD_FTF);
  1487. ++dev->stats.tx_fifo_errors;
  1488. }
  1489. }
  1490. static void genesis_link_up(struct skge_port *skge)
  1491. {
  1492. struct skge_hw *hw = skge->hw;
  1493. int port = skge->port;
  1494. u16 cmd, msk;
  1495. u32 mode;
  1496. cmd = xm_read16(hw, port, XM_MMU_CMD);
  1497. /*
  1498. * enabling pause frame reception is required for 1000BT
  1499. * because the XMAC is not reset if the link is going down
  1500. */
  1501. if (skge->flow_status == FLOW_STAT_NONE ||
  1502. skge->flow_status == FLOW_STAT_LOC_SEND)
  1503. /* Disable Pause Frame Reception */
  1504. cmd |= XM_MMU_IGN_PF;
  1505. else
  1506. /* Enable Pause Frame Reception */
  1507. cmd &= ~XM_MMU_IGN_PF;
  1508. xm_write16(hw, port, XM_MMU_CMD, cmd);
  1509. mode = xm_read32(hw, port, XM_MODE);
  1510. if (skge->flow_status == FLOW_STAT_SYMMETRIC ||
  1511. skge->flow_status == FLOW_STAT_LOC_SEND) {
  1512. /*
  1513. * Configure Pause Frame Generation
  1514. * Use internal and external Pause Frame Generation.
  1515. * Sending pause frames is edge triggered.
  1516. * Send a Pause frame with the maximum pause time if
  1517. * internal oder external FIFO full condition occurs.
  1518. * Send a zero pause time frame to re-start transmission.
  1519. */
  1520. /* XM_PAUSE_DA = '010000C28001' (default) */
  1521. /* XM_MAC_PTIME = 0xffff (maximum) */
  1522. /* remember this value is defined in big endian (!) */
  1523. xm_write16(hw, port, XM_MAC_PTIME, 0xffff);
  1524. mode |= XM_PAUSE_MODE;
  1525. skge_write16(hw, SK_REG(port, RX_MFF_CTRL1), MFF_ENA_PAUSE);
  1526. } else {
  1527. /*
  1528. * disable pause frame generation is required for 1000BT
  1529. * because the XMAC is not reset if the link is going down
  1530. */
  1531. /* Disable Pause Mode in Mode Register */
  1532. mode &= ~XM_PAUSE_MODE;
  1533. skge_write16(hw, SK_REG(port, RX_MFF_CTRL1), MFF_DIS_PAUSE);
  1534. }
  1535. xm_write32(hw, port, XM_MODE, mode);
  1536. /* Turn on detection of Tx underrun */
  1537. msk = xm_read16(hw, port, XM_IMSK);
  1538. msk &= ~XM_IS_TXF_UR;
  1539. xm_write16(hw, port, XM_IMSK, msk);
  1540. xm_read16(hw, port, XM_ISRC);
  1541. /* get MMU Command Reg. */
  1542. cmd = xm_read16(hw, port, XM_MMU_CMD);
  1543. if (hw->phy_type != SK_PHY_XMAC && skge->duplex == DUPLEX_FULL)
  1544. cmd |= XM_MMU_GMII_FD;
  1545. /*
  1546. * Workaround BCOM Errata (#10523) for all BCom Phys
  1547. * Enable Power Management after link up
  1548. */
  1549. if (hw->phy_type == SK_PHY_BCOM) {
  1550. xm_phy_write(hw, port, PHY_BCOM_AUX_CTRL,
  1551. xm_phy_read(hw, port, PHY_BCOM_AUX_CTRL)
  1552. & ~PHY_B_AC_DIS_PM);
  1553. xm_phy_write(hw, port, PHY_BCOM_INT_MASK, PHY_B_DEF_MSK);
  1554. }
  1555. /* enable Rx/Tx */
  1556. xm_write16(hw, port, XM_MMU_CMD,
  1557. cmd | XM_MMU_ENA_RX | XM_MMU_ENA_TX);
  1558. skge_link_up(skge);
  1559. }
  1560. static inline void bcom_phy_intr(struct skge_port *skge)
  1561. {
  1562. struct skge_hw *hw = skge->hw;
  1563. int port = skge->port;
  1564. u16 isrc;
  1565. isrc = xm_phy_read(hw, port, PHY_BCOM_INT_STAT);
  1566. netif_printk(skge, intr, KERN_DEBUG, skge->netdev,
  1567. "phy interrupt status 0x%x\n", isrc);
  1568. if (isrc & PHY_B_IS_PSE)
  1569. pr_err("%s: uncorrectable pair swap error\n",
  1570. hw->dev[port]->name);
  1571. /* Workaround BCom Errata:
  1572. * enable and disable loopback mode if "NO HCD" occurs.
  1573. */
  1574. if (isrc & PHY_B_IS_NO_HDCL) {
  1575. u16 ctrl = xm_phy_read(hw, port, PHY_BCOM_CTRL);
  1576. xm_phy_write(hw, port, PHY_BCOM_CTRL,
  1577. ctrl | PHY_CT_LOOP);
  1578. xm_phy_write(hw, port, PHY_BCOM_CTRL,
  1579. ctrl & ~PHY_CT_LOOP);
  1580. }
  1581. if (isrc & (PHY_B_IS_AN_PR | PHY_B_IS_LST_CHANGE))
  1582. bcom_check_link(hw, port);
  1583. }
  1584. static int gm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val)
  1585. {
  1586. int i;
  1587. gma_write16(hw, port, GM_SMI_DATA, val);
  1588. gma_write16(hw, port, GM_SMI_CTRL,
  1589. GM_SMI_CT_PHY_AD(hw->phy_addr) | GM_SMI_CT_REG_AD(reg));
  1590. for (i = 0; i < PHY_RETRIES; i++) {
  1591. udelay(1);
  1592. if (!(gma_read16(hw, port, GM_SMI_CTRL) & GM_SMI_CT_BUSY))
  1593. return 0;
  1594. }
  1595. pr_warn("%s: phy write timeout\n", hw->dev[port]->name);
  1596. return -EIO;
  1597. }
  1598. static int __gm_phy_read(struct skge_hw *hw, int port, u16 reg, u16 *val)
  1599. {
  1600. int i;
  1601. gma_write16(hw, port, GM_SMI_CTRL,
  1602. GM_SMI_CT_PHY_AD(hw->phy_addr)
  1603. | GM_SMI_CT_REG_AD(reg) | GM_SMI_CT_OP_RD);
  1604. for (i = 0; i < PHY_RETRIES; i++) {
  1605. udelay(1);
  1606. if (gma_read16(hw, port, GM_SMI_CTRL) & GM_SMI_CT_RD_VAL)
  1607. goto ready;
  1608. }
  1609. return -ETIMEDOUT;
  1610. ready:
  1611. *val = gma_read16(hw, port, GM_SMI_DATA);
  1612. return 0;
  1613. }
  1614. static u16 gm_phy_read(struct skge_hw *hw, int port, u16 reg)
  1615. {
  1616. u16 v = 0;
  1617. if (__gm_phy_read(hw, port, reg, &v))
  1618. pr_warn("%s: phy read timeout\n", hw->dev[port]->name);
  1619. return v;
  1620. }
  1621. /* Marvell Phy Initialization */
  1622. static void yukon_init(struct skge_hw *hw, int port)
  1623. {
  1624. struct skge_port *skge = netdev_priv(hw->dev[port]);
  1625. u16 ctrl, ct1000, adv;
  1626. if (skge->autoneg == AUTONEG_ENABLE) {
  1627. u16 ectrl = gm_phy_read(hw, port, PHY_MARV_EXT_CTRL);
  1628. ectrl &= ~(PHY_M_EC_M_DSC_MSK | PHY_M_EC_S_DSC_MSK |
  1629. PHY_M_EC_MAC_S_MSK);
  1630. ectrl |= PHY_M_EC_MAC_S(MAC_TX_CLK_25_MHZ);
  1631. ectrl |= PHY_M_EC_M_DSC(0) | PHY_M_EC_S_DSC(1);
  1632. gm_phy_write(hw, port, PHY_MARV_EXT_CTRL, ectrl);
  1633. }
  1634. ctrl = gm_phy_read(hw, port, PHY_MARV_CTRL);
  1635. if (skge->autoneg == AUTONEG_DISABLE)
  1636. ctrl &= ~PHY_CT_ANE;
  1637. ctrl |= PHY_CT_RESET;
  1638. gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl);
  1639. ctrl = 0;
  1640. ct1000 = 0;
  1641. adv = PHY_AN_CSMA;
  1642. if (skge->autoneg == AUTONEG_ENABLE) {
  1643. if (hw->copper) {
  1644. if (skge->advertising & ADVERTISED_1000baseT_Full)
  1645. ct1000 |= PHY_M_1000C_AFD;
  1646. if (skge->advertising & ADVERTISED_1000baseT_Half)
  1647. ct1000 |= PHY_M_1000C_AHD;
  1648. if (skge->advertising & ADVERTISED_100baseT_Full)
  1649. adv |= PHY_M_AN_100_FD;
  1650. if (skge->advertising & ADVERTISED_100baseT_Half)
  1651. adv |= PHY_M_AN_100_HD;
  1652. if (skge->advertising & ADVERTISED_10baseT_Full)
  1653. adv |= PHY_M_AN_10_FD;
  1654. if (skge->advertising & ADVERTISED_10baseT_Half)
  1655. adv |= PHY_M_AN_10_HD;
  1656. /* Set Flow-control capabilities */
  1657. adv |= phy_pause_map[skge->flow_control];
  1658. } else {
  1659. if (skge->advertising & ADVERTISED_1000baseT_Full)
  1660. adv |= PHY_M_AN_1000X_AFD;
  1661. if (skge->advertising & ADVERTISED_1000baseT_Half)
  1662. adv |= PHY_M_AN_1000X_AHD;
  1663. adv |= fiber_pause_map[skge->flow_control];
  1664. }
  1665. /* Restart Auto-negotiation */
  1666. ctrl |= PHY_CT_ANE | PHY_CT_RE_CFG;
  1667. } else {
  1668. /* forced speed/duplex settings */
  1669. ct1000 = PHY_M_1000C_MSE;
  1670. if (skge->duplex == DUPLEX_FULL)
  1671. ctrl |= PHY_CT_DUP_MD;
  1672. switch (skge->speed) {
  1673. case SPEED_1000:
  1674. ctrl |= PHY_CT_SP1000;
  1675. break;
  1676. case SPEED_100:
  1677. ctrl |= PHY_CT_SP100;
  1678. break;
  1679. }
  1680. ctrl |= PHY_CT_RESET;
  1681. }
  1682. gm_phy_write(hw, port, PHY_MARV_1000T_CTRL, ct1000);
  1683. gm_phy_write(hw, port, PHY_MARV_AUNE_ADV, adv);
  1684. gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl);
  1685. /* Enable phy interrupt on autonegotiation complete (or link up) */
  1686. if (skge->autoneg == AUTONEG_ENABLE)
  1687. gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_IS_AN_MSK);
  1688. else
  1689. gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_IS_DEF_MSK);
  1690. }
  1691. static void yukon_reset(struct skge_hw *hw, int port)
  1692. {
  1693. gm_phy_write(hw, port, PHY_MARV_INT_MASK, 0);/* disable PHY IRQs */
  1694. gma_write16(hw, port, GM_MC_ADDR_H1, 0); /* clear MC hash */
  1695. gma_write16(hw, port, GM_MC_ADDR_H2, 0);
  1696. gma_write16(hw, port, GM_MC_ADDR_H3, 0);
  1697. gma_write16(hw, port, GM_MC_ADDR_H4, 0);
  1698. gma_write16(hw, port, GM_RX_CTRL,
  1699. gma_read16(hw, port, GM_RX_CTRL)
  1700. | GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA);
  1701. }
  1702. /* Apparently, early versions of Yukon-Lite had wrong chip_id? */
  1703. static int is_yukon_lite_a0(struct skge_hw *hw)
  1704. {
  1705. u32 reg;
  1706. int ret;
  1707. if (hw->chip_id != CHIP_ID_YUKON)
  1708. return 0;
  1709. reg = skge_read32(hw, B2_FAR);
  1710. skge_write8(hw, B2_FAR + 3, 0xff);
  1711. ret = (skge_read8(hw, B2_FAR + 3) != 0);
  1712. skge_write32(hw, B2_FAR, reg);
  1713. return ret;
  1714. }
  1715. static void yukon_mac_init(struct skge_hw *hw, int port)
  1716. {
  1717. struct skge_port *skge = netdev_priv(hw->dev[port]);
  1718. int i;
  1719. u32 reg;
  1720. const u8 *addr = hw->dev[port]->dev_addr;
  1721. /* WA code for COMA mode -- set PHY reset */
  1722. if (hw->chip_id == CHIP_ID_YUKON_LITE &&
  1723. hw->chip_rev >= CHIP_REV_YU_LITE_A3) {
  1724. reg = skge_read32(hw, B2_GP_IO);
  1725. reg |= GP_DIR_9 | GP_IO_9;
  1726. skge_write32(hw, B2_GP_IO, reg);
  1727. }
  1728. /* hard reset */
  1729. skge_write32(hw, SK_REG(port, GPHY_CTRL), GPC_RST_SET);
  1730. skge_write32(hw, SK_REG(port, GMAC_CTRL), GMC_RST_SET);
  1731. /* WA code for COMA mode -- clear PHY reset */
  1732. if (hw->chip_id == CHIP_ID_YUKON_LITE &&
  1733. hw->chip_rev >= CHIP_REV_YU_LITE_A3) {
  1734. reg = skge_read32(hw, B2_GP_IO);
  1735. reg |= GP_DIR_9;
  1736. reg &= ~GP_IO_9;
  1737. skge_write32(hw, B2_GP_IO, reg);
  1738. }
  1739. /* Set hardware config mode */
  1740. reg = GPC_INT_POL_HI | GPC_DIS_FC | GPC_DIS_SLEEP |
  1741. GPC_ENA_XC | GPC_ANEG_ADV_ALL_M | GPC_ENA_PAUSE;
  1742. reg |= hw->copper ? GPC_HWCFG_GMII_COP : GPC_HWCFG_GMII_FIB;
  1743. /* Clear GMC reset */
  1744. skge_write32(hw, SK_REG(port, GPHY_CTRL), reg | GPC_RST_SET);
  1745. skge_write32(hw, SK_REG(port, GPHY_CTRL), reg | GPC_RST_CLR);
  1746. skge_write32(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_ON | GMC_RST_CLR);
  1747. if (skge->autoneg == AUTONEG_DISABLE) {
  1748. reg = GM_GPCR_AU_ALL_DIS;
  1749. gma_write16(hw, port, GM_GP_CTRL,
  1750. gma_read16(hw, port, GM_GP_CTRL) | reg);
  1751. switch (skge->speed) {
  1752. case SPEED_1000:
  1753. reg &= ~GM_GPCR_SPEED_100;
  1754. reg |= GM_GPCR_SPEED_1000;
  1755. break;
  1756. case SPEED_100:
  1757. reg &= ~GM_GPCR_SPEED_1000;
  1758. reg |= GM_GPCR_SPEED_100;
  1759. break;
  1760. case SPEED_10:
  1761. reg &= ~(GM_GPCR_SPEED_1000 | GM_GPCR_SPEED_100);
  1762. break;
  1763. }
  1764. if (skge->duplex == DUPLEX_FULL)
  1765. reg |= GM_GPCR_DUP_FULL;
  1766. } else
  1767. reg = GM_GPCR_SPEED_1000 | GM_GPCR_SPEED_100 | GM_GPCR_DUP_FULL;
  1768. switch (skge->flow_control) {
  1769. case FLOW_MODE_NONE:
  1770. skge_write32(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF);
  1771. reg |= GM_GPCR_FC_TX_DIS | GM_GPCR_FC_RX_DIS | GM_GPCR_AU_FCT_DIS;
  1772. break;
  1773. case FLOW_MODE_LOC_SEND:
  1774. /* disable Rx flow-control */
  1775. reg |= GM_GPCR_FC_RX_DIS | GM_GPCR_AU_FCT_DIS;
  1776. break;
  1777. case FLOW_MODE_SYMMETRIC:
  1778. case FLOW_MODE_SYM_OR_REM:
  1779. /* enable Tx & Rx flow-control */
  1780. break;
  1781. }
  1782. gma_write16(hw, port, GM_GP_CTRL, reg);
  1783. skge_read16(hw, SK_REG(port, GMAC_IRQ_SRC));
  1784. yukon_init(hw, port);
  1785. /* MIB clear */
  1786. reg = gma_read16(hw, port, GM_PHY_ADDR);
  1787. gma_write16(hw, port, GM_PHY_ADDR, reg | GM_PAR_MIB_CLR);
  1788. for (i = 0; i < GM_MIB_CNT_SIZE; i++)
  1789. gma_read16(hw, port, GM_MIB_CNT_BASE + 8*i);
  1790. gma_write16(hw, port, GM_PHY_ADDR, reg);
  1791. /* transmit control */
  1792. gma_write16(hw, port, GM_TX_CTRL, TX_COL_THR(TX_COL_DEF));
  1793. /* receive control reg: unicast + multicast + no FCS */
  1794. gma_write16(hw, port, GM_RX_CTRL,
  1795. GM_RXCR_UCF_ENA | GM_RXCR_CRC_DIS | GM_RXCR_MCF_ENA);
  1796. /* transmit flow control */
  1797. gma_write16(hw, port, GM_TX_FLOW_CTRL, 0xffff);
  1798. /* transmit parameter */
  1799. gma_write16(hw, port, GM_TX_PARAM,
  1800. TX_JAM_LEN_VAL(TX_JAM_LEN_DEF) |
  1801. TX_JAM_IPG_VAL(TX_JAM_IPG_DEF) |
  1802. TX_IPG_JAM_DATA(TX_IPG_JAM_DEF));
  1803. /* configure the Serial Mode Register */
  1804. reg = DATA_BLIND_VAL(DATA_BLIND_DEF)
  1805. | GM_SMOD_VLAN_ENA
  1806. | IPG_DATA_VAL(IPG_DATA_DEF);
  1807. if (hw->dev[port]->mtu > ETH_DATA_LEN)
  1808. reg |= GM_SMOD_JUMBO_ENA;
  1809. gma_write16(hw, port, GM_SERIAL_MODE, reg);
  1810. /* physical address: used for pause frames */
  1811. gma_set_addr(hw, port, GM_SRC_ADDR_1L, addr);
  1812. /* virtual address for data */
  1813. gma_set_addr(hw, port, GM_SRC_ADDR_2L, addr);
  1814. /* enable interrupt mask for counter overflows */
  1815. gma_write16(hw, port, GM_TX_IRQ_MSK, 0);
  1816. gma_write16(hw, port, GM_RX_IRQ_MSK, 0);
  1817. gma_write16(hw, port, GM_TR_IRQ_MSK, 0);
  1818. /* Initialize Mac Fifo */
  1819. /* Configure Rx MAC FIFO */
  1820. skge_write16(hw, SK_REG(port, RX_GMF_FL_MSK), RX_FF_FL_DEF_MSK);
  1821. reg = GMF_OPER_ON | GMF_RX_F_FL_ON;
  1822. /* disable Rx GMAC FIFO Flush for YUKON-Lite Rev. A0 only */
  1823. if (is_yukon_lite_a0(hw))
  1824. reg &= ~GMF_RX_F_FL_ON;
  1825. skge_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_CLR);
  1826. skge_write16(hw, SK_REG(port, RX_GMF_CTRL_T), reg);
  1827. /*
  1828. * because Pause Packet Truncation in GMAC is not working
  1829. * we have to increase the Flush Threshold to 64 bytes
  1830. * in order to flush pause packets in Rx FIFO on Yukon-1
  1831. */
  1832. skge_write16(hw, SK_REG(port, RX_GMF_FL_THR), RX_GMF_FL_THR_DEF+1);
  1833. /* Configure Tx MAC FIFO */
  1834. skge_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_CLR);
  1835. skge_write16(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_OPER_ON);
  1836. }
  1837. /* Go into power down mode */
  1838. static void yukon_suspend(struct skge_hw *hw, int port)
  1839. {
  1840. u16 ctrl;
  1841. ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL);
  1842. ctrl |= PHY_M_PC_POL_R_DIS;
  1843. gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl);
  1844. ctrl = gm_phy_read(hw, port, PHY_MARV_CTRL);
  1845. ctrl |= PHY_CT_RESET;
  1846. gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl);
  1847. /* switch IEEE compatible power down mode on */
  1848. ctrl = gm_phy_read(hw, port, PHY_MARV_CTRL);
  1849. ctrl |= PHY_CT_PDOWN;
  1850. gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl);
  1851. }
  1852. static void yukon_stop(struct skge_port *skge)
  1853. {
  1854. struct skge_hw *hw = skge->hw;
  1855. int port = skge->port;
  1856. skge_write8(hw, SK_REG(port, GMAC_IRQ_MSK), 0);
  1857. yukon_reset(hw, port);
  1858. gma_write16(hw, port, GM_GP_CTRL,
  1859. gma_read16(hw, port, GM_GP_CTRL)
  1860. & ~(GM_GPCR_TX_ENA|GM_GPCR_RX_ENA));
  1861. gma_read16(hw, port, GM_GP_CTRL);
  1862. yukon_suspend(hw, port);
  1863. /* set GPHY Control reset */
  1864. skge_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_SET);
  1865. skge_write8(hw, SK_REG(port, GMAC_CTRL), GMC_RST_SET);
  1866. }
  1867. static void yukon_get_stats(struct skge_port *skge, u64 *data)
  1868. {
  1869. struct skge_hw *hw = skge->hw;
  1870. int port = skge->port;
  1871. int i;
  1872. data[0] = (u64) gma_read32(hw, port, GM_TXO_OK_HI) << 32
  1873. | gma_read32(hw, port, GM_TXO_OK_LO);
  1874. data[1] = (u64) gma_read32(hw, port, GM_RXO_OK_HI) << 32
  1875. | gma_read32(hw, port, GM_RXO_OK_LO);
  1876. for (i = 2; i < ARRAY_SIZE(skge_stats); i++)
  1877. data[i] = gma_read32(hw, port,
  1878. skge_stats[i].gma_offset);
  1879. }
  1880. static void yukon_mac_intr(struct skge_hw *hw, int port)
  1881. {
  1882. struct net_device *dev = hw->dev[port];
  1883. struct skge_port *skge = netdev_priv(dev);
  1884. u8 status = skge_read8(hw, SK_REG(port, GMAC_IRQ_SRC));
  1885. netif_printk(skge, intr, KERN_DEBUG, skge->netdev,
  1886. "mac interrupt status 0x%x\n", status);
  1887. if (status & GM_IS_RX_FF_OR) {
  1888. ++dev->stats.rx_fifo_errors;
  1889. skge_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_CLI_RX_FO);
  1890. }
  1891. if (status & GM_IS_TX_FF_UR) {
  1892. ++dev->stats.tx_fifo_errors;
  1893. skge_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_CLI_TX_FU);
  1894. }
  1895. }
  1896. static u16 yukon_speed(const struct skge_hw *hw, u16 aux)
  1897. {
  1898. switch (aux & PHY_M_PS_SPEED_MSK) {
  1899. case PHY_M_PS_SPEED_1000:
  1900. return SPEED_1000;
  1901. case PHY_M_PS_SPEED_100:
  1902. return SPEED_100;
  1903. default:
  1904. return SPEED_10;
  1905. }
  1906. }
  1907. static void yukon_link_up(struct skge_port *skge)
  1908. {
  1909. struct skge_hw *hw = skge->hw;
  1910. int port = skge->port;
  1911. u16 reg;
  1912. /* Enable Transmit FIFO Underrun */
  1913. skge_write8(hw, SK_REG(port, GMAC_IRQ_MSK), GMAC_DEF_MSK);
  1914. reg = gma_read16(hw, port, GM_GP_CTRL);
  1915. if (skge->duplex == DUPLEX_FULL || skge->autoneg == AUTONEG_ENABLE)
  1916. reg |= GM_GPCR_DUP_FULL;
  1917. /* enable Rx/Tx */
  1918. reg |= GM_GPCR_RX_ENA | GM_GPCR_TX_ENA;
  1919. gma_write16(hw, port, GM_GP_CTRL, reg);
  1920. gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_IS_DEF_MSK);
  1921. skge_link_up(skge);
  1922. }
  1923. static void yukon_link_down(struct skge_port *skge)
  1924. {
  1925. struct skge_hw *hw = skge->hw;
  1926. int port = skge->port;
  1927. u16 ctrl;
  1928. ctrl = gma_read16(hw, port, GM_GP_CTRL);
  1929. ctrl &= ~(GM_GPCR_RX_ENA | GM_GPCR_TX_ENA);
  1930. gma_write16(hw, port, GM_GP_CTRL, ctrl);
  1931. if (skge->flow_status == FLOW_STAT_REM_SEND) {
  1932. ctrl = gm_phy_read(hw, port, PHY_MARV_AUNE_ADV);
  1933. ctrl |= PHY_M_AN_ASP;
  1934. /* restore Asymmetric Pause bit */
  1935. gm_phy_write(hw, port, PHY_MARV_AUNE_ADV, ctrl);
  1936. }
  1937. skge_link_down(skge);
  1938. yukon_init(hw, port);
  1939. }
  1940. static void yukon_phy_intr(struct skge_port *skge)
  1941. {
  1942. struct skge_hw *hw = skge->hw;
  1943. int port = skge->port;
  1944. const char *reason = NULL;
  1945. u16 istatus, phystat;
  1946. istatus = gm_phy_read(hw, port, PHY_MARV_INT_STAT);
  1947. phystat = gm_phy_read(hw, port, PHY_MARV_PHY_STAT);
  1948. netif_printk(skge, intr, KERN_DEBUG, skge->netdev,
  1949. "phy interrupt status 0x%x 0x%x\n", istatus, phystat);
  1950. if (istatus & PHY_M_IS_AN_COMPL) {
  1951. if (gm_phy_read(hw, port, PHY_MARV_AUNE_LP)
  1952. & PHY_M_AN_RF) {
  1953. reason = "remote fault";
  1954. goto failed;
  1955. }
  1956. if (gm_phy_read(hw, port, PHY_MARV_1000T_STAT) & PHY_B_1000S_MSF) {
  1957. reason = "master/slave fault";
  1958. goto failed;
  1959. }
  1960. if (!(phystat & PHY_M_PS_SPDUP_RES)) {
  1961. reason = "speed/duplex";
  1962. goto failed;
  1963. }
  1964. skge->duplex = (phystat & PHY_M_PS_FULL_DUP)
  1965. ? DUPLEX_FULL : DUPLEX_HALF;
  1966. skge->speed = yukon_speed(hw, phystat);
  1967. /* We are using IEEE 802.3z/D5.0 Table 37-4 */
  1968. switch (phystat & PHY_M_PS_PAUSE_MSK) {
  1969. case PHY_M_PS_PAUSE_MSK:
  1970. skge->flow_status = FLOW_STAT_SYMMETRIC;
  1971. break;
  1972. case PHY_M_PS_RX_P_EN:
  1973. skge->flow_status = FLOW_STAT_REM_SEND;
  1974. break;
  1975. case PHY_M_PS_TX_P_EN:
  1976. skge->flow_status = FLOW_STAT_LOC_SEND;
  1977. break;
  1978. default:
  1979. skge->flow_status = FLOW_STAT_NONE;
  1980. }
  1981. if (skge->flow_status == FLOW_STAT_NONE ||
  1982. (skge->speed < SPEED_1000 && skge->duplex == DUPLEX_HALF))
  1983. skge_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF);
  1984. else
  1985. skge_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_ON);
  1986. yukon_link_up(skge);
  1987. return;
  1988. }
  1989. if (istatus & PHY_M_IS_LSP_CHANGE)
  1990. skge->speed = yukon_speed(hw, phystat);
  1991. if (istatus & PHY_M_IS_DUP_CHANGE)
  1992. skge->duplex = (phystat & PHY_M_PS_FULL_DUP) ? DUPLEX_FULL : DUPLEX_HALF;
  1993. if (istatus & PHY_M_IS_LST_CHANGE) {
  1994. if (phystat & PHY_M_PS_LINK_UP)
  1995. yukon_link_up(skge);
  1996. else
  1997. yukon_link_down(skge);
  1998. }
  1999. return;
  2000. failed:
  2001. pr_err("%s: autonegotiation failed (%s)\n", skge->netdev->name, reason);
  2002. /* XXX restart autonegotiation? */
  2003. }
  2004. static void skge_phy_reset(struct skge_port *skge)
  2005. {
  2006. struct skge_hw *hw = skge->hw;
  2007. int port = skge->port;
  2008. struct net_device *dev = hw->dev[port];
  2009. netif_stop_queue(skge->netdev);
  2010. netif_carrier_off(skge->netdev);
  2011. spin_lock_bh(&hw->phy_lock);
  2012. if (is_genesis(hw)) {
  2013. genesis_reset(hw, port);
  2014. genesis_mac_init(hw, port);
  2015. } else {
  2016. yukon_reset(hw, port);
  2017. yukon_init(hw, port);
  2018. }
  2019. spin_unlock_bh(&hw->phy_lock);
  2020. skge_set_multicast(dev);
  2021. }
  2022. /* Basic MII support */
  2023. static int skge_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  2024. {
  2025. struct mii_ioctl_data *data = if_mii(ifr);
  2026. struct skge_port *skge = netdev_priv(dev);
  2027. struct skge_hw *hw = skge->hw;
  2028. int err = -EOPNOTSUPP;
  2029. if (!netif_running(dev))
  2030. return -ENODEV; /* Phy still in reset */
  2031. switch (cmd) {
  2032. case SIOCGMIIPHY:
  2033. data->phy_id = hw->phy_addr;
  2034. /* fallthru */
  2035. case SIOCGMIIREG: {
  2036. u16 val = 0;
  2037. spin_lock_bh(&hw->phy_lock);
  2038. if (is_genesis(hw))
  2039. err = __xm_phy_read(hw, skge->port, data->reg_num & 0x1f, &val);
  2040. else
  2041. err = __gm_phy_read(hw, skge->port, data->reg_num & 0x1f, &val);
  2042. spin_unlock_bh(&hw->phy_lock);
  2043. data->val_out = val;
  2044. break;
  2045. }
  2046. case SIOCSMIIREG:
  2047. spin_lock_bh(&hw->phy_lock);
  2048. if (is_genesis(hw))
  2049. err = xm_phy_write(hw, skge->port, data->reg_num & 0x1f,
  2050. data->val_in);
  2051. else
  2052. err = gm_phy_write(hw, skge->port, data->reg_num & 0x1f,
  2053. data->val_in);
  2054. spin_unlock_bh(&hw->phy_lock);
  2055. break;
  2056. }
  2057. return err;
  2058. }
  2059. static void skge_ramset(struct skge_hw *hw, u16 q, u32 start, size_t len)
  2060. {
  2061. u32 end;
  2062. start /= 8;
  2063. len /= 8;
  2064. end = start + len - 1;
  2065. skge_write8(hw, RB_ADDR(q, RB_CTRL), RB_RST_CLR);
  2066. skge_write32(hw, RB_ADDR(q, RB_START), start);
  2067. skge_write32(hw, RB_ADDR(q, RB_WP), start);
  2068. skge_write32(hw, RB_ADDR(q, RB_RP), start);
  2069. skge_write32(hw, RB_ADDR(q, RB_END), end);
  2070. if (q == Q_R1 || q == Q_R2) {
  2071. /* Set thresholds on receive queue's */
  2072. skge_write32(hw, RB_ADDR(q, RB_RX_UTPP),
  2073. start + (2*len)/3);
  2074. skge_write32(hw, RB_ADDR(q, RB_RX_LTPP),
  2075. start + (len/3));
  2076. } else {
  2077. /* Enable store & forward on Tx queue's because
  2078. * Tx FIFO is only 4K on Genesis and 1K on Yukon
  2079. */
  2080. skge_write8(hw, RB_ADDR(q, RB_CTRL), RB_ENA_STFWD);
  2081. }
  2082. skge_write8(hw, RB_ADDR(q, RB_CTRL), RB_ENA_OP_MD);
  2083. }
  2084. /* Setup Bus Memory Interface */
  2085. static void skge_qset(struct skge_port *skge, u16 q,
  2086. const struct skge_element *e)
  2087. {
  2088. struct skge_hw *hw = skge->hw;
  2089. u32 watermark = 0x600;
  2090. u64 base = skge->dma + (e->desc - skge->mem);
  2091. /* optimization to reduce window on 32bit/33mhz */
  2092. if ((skge_read16(hw, B0_CTST) & (CS_BUS_CLOCK | CS_BUS_SLOT_SZ)) == 0)
  2093. watermark /= 2;
  2094. skge_write32(hw, Q_ADDR(q, Q_CSR), CSR_CLR_RESET);
  2095. skge_write32(hw, Q_ADDR(q, Q_F), watermark);
  2096. skge_write32(hw, Q_ADDR(q, Q_DA_H), (u32)(base >> 32));
  2097. skge_write32(hw, Q_ADDR(q, Q_DA_L), (u32)base);
  2098. }
  2099. static int skge_up(struct net_device *dev)
  2100. {
  2101. struct skge_port *skge = netdev_priv(dev);
  2102. struct skge_hw *hw = skge->hw;
  2103. int port = skge->port;
  2104. u32 chunk, ram_addr;
  2105. size_t rx_size, tx_size;
  2106. int err;
  2107. if (!is_valid_ether_addr(dev->dev_addr))
  2108. return -EINVAL;
  2109. netif_info(skge, ifup, skge->netdev, "enabling interface\n");
  2110. if (dev->mtu > RX_BUF_SIZE)
  2111. skge->rx_buf_size = dev->mtu + ETH_HLEN;
  2112. else
  2113. skge->rx_buf_size = RX_BUF_SIZE;
  2114. rx_size = skge->rx_ring.count * sizeof(struct skge_rx_desc);
  2115. tx_size = skge->tx_ring.count * sizeof(struct skge_tx_desc);
  2116. skge->mem_size = tx_size + rx_size;
  2117. skge->mem = pci_alloc_consistent(hw->pdev, skge->mem_size, &skge->dma);
  2118. if (!skge->mem)
  2119. return -ENOMEM;
  2120. BUG_ON(skge->dma & 7);
  2121. if (upper_32_bits(skge->dma) != upper_32_bits(skge->dma + skge->mem_size)) {
  2122. dev_err(&hw->pdev->dev, "pci_alloc_consistent region crosses 4G boundary\n");
  2123. err = -EINVAL;
  2124. goto free_pci_mem;
  2125. }
  2126. memset(skge->mem, 0, skge->mem_size);
  2127. err = skge_ring_alloc(&skge->rx_ring, skge->mem, skge->dma);
  2128. if (err)
  2129. goto free_pci_mem;
  2130. err = skge_rx_fill(dev);
  2131. if (err)
  2132. goto free_rx_ring;
  2133. err = skge_ring_alloc(&skge->tx_ring, skge->mem + rx_size,
  2134. skge->dma + rx_size);
  2135. if (err)
  2136. goto free_rx_ring;
  2137. if (hw->ports == 1) {
  2138. err = request_irq(hw->pdev->irq, skge_intr, IRQF_SHARED,
  2139. dev->name, hw);
  2140. if (err) {
  2141. netdev_err(dev, "Unable to allocate interrupt %d error: %d\n",
  2142. hw->pdev->irq, err);
  2143. goto free_tx_ring;
  2144. }
  2145. }
  2146. /* Initialize MAC */
  2147. netif_carrier_off(dev);
  2148. spin_lock_bh(&hw->phy_lock);
  2149. if (is_genesis(hw))
  2150. genesis_mac_init(hw, port);
  2151. else
  2152. yukon_mac_init(hw, port);
  2153. spin_unlock_bh(&hw->phy_lock);
  2154. /* Configure RAMbuffers - equally between ports and tx/rx */
  2155. chunk = (hw->ram_size - hw->ram_offset) / (hw->ports * 2);
  2156. ram_addr = hw->ram_offset + 2 * chunk * port;
  2157. skge_ramset(hw, rxqaddr[port], ram_addr, chunk);
  2158. skge_qset(skge, rxqaddr[port], skge->rx_ring.to_clean);
  2159. BUG_ON(skge->tx_ring.to_use != skge->tx_ring.to_clean);
  2160. skge_ramset(hw, txqaddr[port], ram_addr+chunk, chunk);
  2161. skge_qset(skge, txqaddr[port], skge->tx_ring.to_use);
  2162. /* Start receiver BMU */
  2163. wmb();
  2164. skge_write8(hw, Q_ADDR(rxqaddr[port], Q_CSR), CSR_START | CSR_IRQ_CL_F);
  2165. skge_led(skge, LED_MODE_ON);
  2166. spin_lock_irq(&hw->hw_lock);
  2167. hw->intr_mask |= portmask[port];
  2168. skge_write32(hw, B0_IMSK, hw->intr_mask);
  2169. skge_read32(hw, B0_IMSK);
  2170. spin_unlock_irq(&hw->hw_lock);
  2171. napi_enable(&skge->napi);
  2172. skge_set_multicast(dev);
  2173. return 0;
  2174. free_tx_ring:
  2175. kfree(skge->tx_ring.start);
  2176. free_rx_ring:
  2177. skge_rx_clean(skge);
  2178. kfree(skge->rx_ring.start);
  2179. free_pci_mem:
  2180. pci_free_consistent(hw->pdev, skge->mem_size, skge->mem, skge->dma);
  2181. skge->mem = NULL;
  2182. return err;
  2183. }
  2184. /* stop receiver */
  2185. static void skge_rx_stop(struct skge_hw *hw, int port)
  2186. {
  2187. skge_write8(hw, Q_ADDR(rxqaddr[port], Q_CSR), CSR_STOP);
  2188. skge_write32(hw, RB_ADDR(port ? Q_R2 : Q_R1, RB_CTRL),
  2189. RB_RST_SET|RB_DIS_OP_MD);
  2190. skge_write32(hw, Q_ADDR(rxqaddr[port], Q_CSR), CSR_SET_RESET);
  2191. }
  2192. static int skge_down(struct net_device *dev)
  2193. {
  2194. struct skge_port *skge = netdev_priv(dev);
  2195. struct skge_hw *hw = skge->hw;
  2196. int port = skge->port;
  2197. if (!skge->mem)
  2198. return 0;
  2199. netif_info(skge, ifdown, skge->netdev, "disabling interface\n");
  2200. netif_tx_disable(dev);
  2201. if (is_genesis(hw) && hw->phy_type == SK_PHY_XMAC)
  2202. del_timer_sync(&skge->link_timer);
  2203. napi_disable(&skge->napi);
  2204. netif_carrier_off(dev);
  2205. spin_lock_irq(&hw->hw_lock);
  2206. hw->intr_mask &= ~portmask[port];
  2207. skge_write32(hw, B0_IMSK, (hw->ports == 1) ? 0 : hw->intr_mask);
  2208. skge_read32(hw, B0_IMSK);
  2209. spin_unlock_irq(&hw->hw_lock);
  2210. if (hw->ports == 1)
  2211. free_irq(hw->pdev->irq, hw);
  2212. skge_write8(skge->hw, SK_REG(skge->port, LNK_LED_REG), LED_REG_OFF);
  2213. if (is_genesis(hw))
  2214. genesis_stop(skge);
  2215. else
  2216. yukon_stop(skge);
  2217. /* Stop transmitter */
  2218. skge_write8(hw, Q_ADDR(txqaddr[port], Q_CSR), CSR_STOP);
  2219. skge_write32(hw, RB_ADDR(txqaddr[port], RB_CTRL),
  2220. RB_RST_SET|RB_DIS_OP_MD);
  2221. /* Disable Force Sync bit and Enable Alloc bit */
  2222. skge_write8(hw, SK_REG(port, TXA_CTRL),
  2223. TXA_DIS_FSYNC | TXA_DIS_ALLOC | TXA_STOP_RC);
  2224. /* Stop Interval Timer and Limit Counter of Tx Arbiter */
  2225. skge_write32(hw, SK_REG(port, TXA_ITI_INI), 0L);
  2226. skge_write32(hw, SK_REG(port, TXA_LIM_INI), 0L);
  2227. /* Reset PCI FIFO */
  2228. skge_write32(hw, Q_ADDR(txqaddr[port], Q_CSR), CSR_SET_RESET);
  2229. skge_write32(hw, RB_ADDR(txqaddr[port], RB_CTRL), RB_RST_SET);
  2230. /* Reset the RAM Buffer async Tx queue */
  2231. skge_write8(hw, RB_ADDR(port == 0 ? Q_XA1 : Q_XA2, RB_CTRL), RB_RST_SET);
  2232. skge_rx_stop(hw, port);
  2233. if (is_genesis(hw)) {
  2234. skge_write8(hw, SK_REG(port, TX_MFF_CTRL2), MFF_RST_SET);
  2235. skge_write8(hw, SK_REG(port, RX_MFF_CTRL2), MFF_RST_SET);
  2236. } else {
  2237. skge_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET);
  2238. skge_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_SET);
  2239. }
  2240. skge_led(skge, LED_MODE_OFF);
  2241. netif_tx_lock_bh(dev);
  2242. skge_tx_clean(dev);
  2243. netif_tx_unlock_bh(dev);
  2244. skge_rx_clean(skge);
  2245. kfree(skge->rx_ring.start);
  2246. kfree(skge->tx_ring.start);
  2247. pci_free_consistent(hw->pdev, skge->mem_size, skge->mem, skge->dma);
  2248. skge->mem = NULL;
  2249. return 0;
  2250. }
  2251. static inline int skge_avail(const struct skge_ring *ring)
  2252. {
  2253. smp_mb();
  2254. return ((ring->to_clean > ring->to_use) ? 0 : ring->count)
  2255. + (ring->to_clean - ring->to_use) - 1;
  2256. }
  2257. static netdev_tx_t skge_xmit_frame(struct sk_buff *skb,
  2258. struct net_device *dev)
  2259. {
  2260. struct skge_port *skge = netdev_priv(dev);
  2261. struct skge_hw *hw = skge->hw;
  2262. struct skge_element *e;
  2263. struct skge_tx_desc *td;
  2264. int i;
  2265. u32 control, len;
  2266. dma_addr_t map;
  2267. if (skb_padto(skb, ETH_ZLEN))
  2268. return NETDEV_TX_OK;
  2269. if (unlikely(skge_avail(&skge->tx_ring) < skb_shinfo(skb)->nr_frags + 1))
  2270. return NETDEV_TX_BUSY;
  2271. e = skge->tx_ring.to_use;
  2272. td = e->desc;
  2273. BUG_ON(td->control & BMU_OWN);
  2274. e->skb = skb;
  2275. len = skb_headlen(skb);
  2276. map = pci_map_single(hw->pdev, skb->data, len, PCI_DMA_TODEVICE);
  2277. if (pci_dma_mapping_error(hw->pdev, map))
  2278. goto mapping_error;
  2279. dma_unmap_addr_set(e, mapaddr, map);
  2280. dma_unmap_len_set(e, maplen, len);
  2281. td->dma_lo = lower_32_bits(map);
  2282. td->dma_hi = upper_32_bits(map);
  2283. if (skb->ip_summed == CHECKSUM_PARTIAL) {
  2284. const int offset = skb_checksum_start_offset(skb);
  2285. /* This seems backwards, but it is what the sk98lin
  2286. * does. Looks like hardware is wrong?
  2287. */
  2288. if (ipip_hdr(skb)->protocol == IPPROTO_UDP &&
  2289. hw->chip_rev == 0 && hw->chip_id == CHIP_ID_YUKON)
  2290. control = BMU_TCP_CHECK;
  2291. else
  2292. control = BMU_UDP_CHECK;
  2293. td->csum_offs = 0;
  2294. td->csum_start = offset;
  2295. td->csum_write = offset + skb->csum_offset;
  2296. } else
  2297. control = BMU_CHECK;
  2298. if (!skb_shinfo(skb)->nr_frags) /* single buffer i.e. no fragments */
  2299. control |= BMU_EOF | BMU_IRQ_EOF;
  2300. else {
  2301. struct skge_tx_desc *tf = td;
  2302. control |= BMU_STFWD;
  2303. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  2304. const skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  2305. map = skb_frag_dma_map(&hw->pdev->dev, frag, 0,
  2306. skb_frag_size(frag), DMA_TO_DEVICE);
  2307. if (dma_mapping_error(&hw->pdev->dev, map))
  2308. goto mapping_unwind;
  2309. e = e->next;
  2310. e->skb = skb;
  2311. tf = e->desc;
  2312. BUG_ON(tf->control & BMU_OWN);
  2313. tf->dma_lo = lower_32_bits(map);
  2314. tf->dma_hi = upper_32_bits(map);
  2315. dma_unmap_addr_set(e, mapaddr, map);
  2316. dma_unmap_len_set(e, maplen, skb_frag_size(frag));
  2317. tf->control = BMU_OWN | BMU_SW | control | skb_frag_size(frag);
  2318. }
  2319. tf->control |= BMU_EOF | BMU_IRQ_EOF;
  2320. }
  2321. /* Make sure all the descriptors written */
  2322. wmb();
  2323. td->control = BMU_OWN | BMU_SW | BMU_STF | control | len;
  2324. wmb();
  2325. netdev_sent_queue(dev, skb->len);
  2326. skge_write8(hw, Q_ADDR(txqaddr[skge->port], Q_CSR), CSR_START);
  2327. netif_printk(skge, tx_queued, KERN_DEBUG, skge->netdev,
  2328. "tx queued, slot %td, len %d\n",
  2329. e - skge->tx_ring.start, skb->len);
  2330. skge->tx_ring.to_use = e->next;
  2331. smp_wmb();
  2332. if (skge_avail(&skge->tx_ring) <= TX_LOW_WATER) {
  2333. netdev_dbg(dev, "transmit queue full\n");
  2334. netif_stop_queue(dev);
  2335. }
  2336. return NETDEV_TX_OK;
  2337. mapping_unwind:
  2338. e = skge->tx_ring.to_use;
  2339. pci_unmap_single(hw->pdev,
  2340. dma_unmap_addr(e, mapaddr),
  2341. dma_unmap_len(e, maplen),
  2342. PCI_DMA_TODEVICE);
  2343. while (i-- > 0) {
  2344. e = e->next;
  2345. pci_unmap_page(hw->pdev,
  2346. dma_unmap_addr(e, mapaddr),
  2347. dma_unmap_len(e, maplen),
  2348. PCI_DMA_TODEVICE);
  2349. }
  2350. mapping_error:
  2351. if (net_ratelimit())
  2352. dev_warn(&hw->pdev->dev, "%s: tx mapping error\n", dev->name);
  2353. dev_kfree_skb_any(skb);
  2354. return NETDEV_TX_OK;
  2355. }
  2356. /* Free resources associated with this reing element */
  2357. static inline void skge_tx_unmap(struct pci_dev *pdev, struct skge_element *e,
  2358. u32 control)
  2359. {
  2360. /* skb header vs. fragment */
  2361. if (control & BMU_STF)
  2362. pci_unmap_single(pdev, dma_unmap_addr(e, mapaddr),
  2363. dma_unmap_len(e, maplen),
  2364. PCI_DMA_TODEVICE);
  2365. else
  2366. pci_unmap_page(pdev, dma_unmap_addr(e, mapaddr),
  2367. dma_unmap_len(e, maplen),
  2368. PCI_DMA_TODEVICE);
  2369. }
  2370. /* Free all buffers in transmit ring */
  2371. static void skge_tx_clean(struct net_device *dev)
  2372. {
  2373. struct skge_port *skge = netdev_priv(dev);
  2374. struct skge_element *e;
  2375. for (e = skge->tx_ring.to_clean; e != skge->tx_ring.to_use; e = e->next) {
  2376. struct skge_tx_desc *td = e->desc;
  2377. skge_tx_unmap(skge->hw->pdev, e, td->control);
  2378. if (td->control & BMU_EOF)
  2379. dev_kfree_skb(e->skb);
  2380. td->control = 0;
  2381. }
  2382. netdev_reset_queue(dev);
  2383. skge->tx_ring.to_clean = e;
  2384. }
  2385. static void skge_tx_timeout(struct net_device *dev)
  2386. {
  2387. struct skge_port *skge = netdev_priv(dev);
  2388. netif_printk(skge, timer, KERN_DEBUG, skge->netdev, "tx timeout\n");
  2389. skge_write8(skge->hw, Q_ADDR(txqaddr[skge->port], Q_CSR), CSR_STOP);
  2390. skge_tx_clean(dev);
  2391. netif_wake_queue(dev);
  2392. }
  2393. static int skge_change_mtu(struct net_device *dev, int new_mtu)
  2394. {
  2395. int err;
  2396. if (!netif_running(dev)) {
  2397. dev->mtu = new_mtu;
  2398. return 0;
  2399. }
  2400. skge_down(dev);
  2401. dev->mtu = new_mtu;
  2402. err = skge_up(dev);
  2403. if (err)
  2404. dev_close(dev);
  2405. return err;
  2406. }
  2407. static const u8 pause_mc_addr[ETH_ALEN] = { 0x1, 0x80, 0xc2, 0x0, 0x0, 0x1 };
  2408. static void genesis_add_filter(u8 filter[8], const u8 *addr)
  2409. {
  2410. u32 crc, bit;
  2411. crc = ether_crc_le(ETH_ALEN, addr);
  2412. bit = ~crc & 0x3f;
  2413. filter[bit/8] |= 1 << (bit%8);
  2414. }
  2415. static void genesis_set_multicast(struct net_device *dev)
  2416. {
  2417. struct skge_port *skge = netdev_priv(dev);
  2418. struct skge_hw *hw = skge->hw;
  2419. int port = skge->port;
  2420. struct netdev_hw_addr *ha;
  2421. u32 mode;
  2422. u8 filter[8];
  2423. mode = xm_read32(hw, port, XM_MODE);
  2424. mode |= XM_MD_ENA_HASH;
  2425. if (dev->flags & IFF_PROMISC)
  2426. mode |= XM_MD_ENA_PROM;
  2427. else
  2428. mode &= ~XM_MD_ENA_PROM;
  2429. if (dev->flags & IFF_ALLMULTI)
  2430. memset(filter, 0xff, sizeof(filter));
  2431. else {
  2432. memset(filter, 0, sizeof(filter));
  2433. if (skge->flow_status == FLOW_STAT_REM_SEND ||
  2434. skge->flow_status == FLOW_STAT_SYMMETRIC)
  2435. genesis_add_filter(filter, pause_mc_addr);
  2436. netdev_for_each_mc_addr(ha, dev)
  2437. genesis_add_filter(filter, ha->addr);
  2438. }
  2439. xm_write32(hw, port, XM_MODE, mode);
  2440. xm_outhash(hw, port, XM_HSM, filter);
  2441. }
  2442. static void yukon_add_filter(u8 filter[8], const u8 *addr)
  2443. {
  2444. u32 bit = ether_crc(ETH_ALEN, addr) & 0x3f;
  2445. filter[bit/8] |= 1 << (bit%8);
  2446. }
  2447. static void yukon_set_multicast(struct net_device *dev)
  2448. {
  2449. struct skge_port *skge = netdev_priv(dev);
  2450. struct skge_hw *hw = skge->hw;
  2451. int port = skge->port;
  2452. struct netdev_hw_addr *ha;
  2453. int rx_pause = (skge->flow_status == FLOW_STAT_REM_SEND ||
  2454. skge->flow_status == FLOW_STAT_SYMMETRIC);
  2455. u16 reg;
  2456. u8 filter[8];
  2457. memset(filter, 0, sizeof(filter));
  2458. reg = gma_read16(hw, port, GM_RX_CTRL);
  2459. reg |= GM_RXCR_UCF_ENA;
  2460. if (dev->flags & IFF_PROMISC) /* promiscuous */
  2461. reg &= ~(GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA);
  2462. else if (dev->flags & IFF_ALLMULTI) /* all multicast */
  2463. memset(filter, 0xff, sizeof(filter));
  2464. else if (netdev_mc_empty(dev) && !rx_pause)/* no multicast */
  2465. reg &= ~GM_RXCR_MCF_ENA;
  2466. else {
  2467. reg |= GM_RXCR_MCF_ENA;
  2468. if (rx_pause)
  2469. yukon_add_filter(filter, pause_mc_addr);
  2470. netdev_for_each_mc_addr(ha, dev)
  2471. yukon_add_filter(filter, ha->addr);
  2472. }
  2473. gma_write16(hw, port, GM_MC_ADDR_H1,
  2474. (u16)filter[0] | ((u16)filter[1] << 8));
  2475. gma_write16(hw, port, GM_MC_ADDR_H2,
  2476. (u16)filter[2] | ((u16)filter[3] << 8));
  2477. gma_write16(hw, port, GM_MC_ADDR_H3,
  2478. (u16)filter[4] | ((u16)filter[5] << 8));
  2479. gma_write16(hw, port, GM_MC_ADDR_H4,
  2480. (u16)filter[6] | ((u16)filter[7] << 8));
  2481. gma_write16(hw, port, GM_RX_CTRL, reg);
  2482. }
  2483. static inline u16 phy_length(const struct skge_hw *hw, u32 status)
  2484. {
  2485. if (is_genesis(hw))
  2486. return status >> XMR_FS_LEN_SHIFT;
  2487. else
  2488. return status >> GMR_FS_LEN_SHIFT;
  2489. }
  2490. static inline int bad_phy_status(const struct skge_hw *hw, u32 status)
  2491. {
  2492. if (is_genesis(hw))
  2493. return (status & (XMR_FS_ERR | XMR_FS_2L_VLAN)) != 0;
  2494. else
  2495. return (status & GMR_FS_ANY_ERR) ||
  2496. (status & GMR_FS_RX_OK) == 0;
  2497. }
  2498. static void skge_set_multicast(struct net_device *dev)
  2499. {
  2500. struct skge_port *skge = netdev_priv(dev);
  2501. if (is_genesis(skge->hw))
  2502. genesis_set_multicast(dev);
  2503. else
  2504. yukon_set_multicast(dev);
  2505. }
  2506. /* Get receive buffer from descriptor.
  2507. * Handles copy of small buffers and reallocation failures
  2508. */
  2509. static struct sk_buff *skge_rx_get(struct net_device *dev,
  2510. struct skge_element *e,
  2511. u32 control, u32 status, u16 csum)
  2512. {
  2513. struct skge_port *skge = netdev_priv(dev);
  2514. struct sk_buff *skb;
  2515. u16 len = control & BMU_BBC;
  2516. netif_printk(skge, rx_status, KERN_DEBUG, skge->netdev,
  2517. "rx slot %td status 0x%x len %d\n",
  2518. e - skge->rx_ring.start, status, len);
  2519. if (len > skge->rx_buf_size)
  2520. goto error;
  2521. if ((control & (BMU_EOF|BMU_STF)) != (BMU_STF|BMU_EOF))
  2522. goto error;
  2523. if (bad_phy_status(skge->hw, status))
  2524. goto error;
  2525. if (phy_length(skge->hw, status) != len)
  2526. goto error;
  2527. if (len < RX_COPY_THRESHOLD) {
  2528. skb = netdev_alloc_skb_ip_align(dev, len);
  2529. if (!skb)
  2530. goto resubmit;
  2531. pci_dma_sync_single_for_cpu(skge->hw->pdev,
  2532. dma_unmap_addr(e, mapaddr),
  2533. dma_unmap_len(e, maplen),
  2534. PCI_DMA_FROMDEVICE);
  2535. skb_copy_from_linear_data(e->skb, skb->data, len);
  2536. pci_dma_sync_single_for_device(skge->hw->pdev,
  2537. dma_unmap_addr(e, mapaddr),
  2538. dma_unmap_len(e, maplen),
  2539. PCI_DMA_FROMDEVICE);
  2540. skge_rx_reuse(e, skge->rx_buf_size);
  2541. } else {
  2542. struct skge_element ee;
  2543. struct sk_buff *nskb;
  2544. nskb = netdev_alloc_skb_ip_align(dev, skge->rx_buf_size);
  2545. if (!nskb)
  2546. goto resubmit;
  2547. ee = *e;
  2548. skb = ee.skb;
  2549. prefetch(skb->data);
  2550. if (skge_rx_setup(skge, e, nskb, skge->rx_buf_size) < 0) {
  2551. dev_kfree_skb(nskb);
  2552. goto resubmit;
  2553. }
  2554. pci_unmap_single(skge->hw->pdev,
  2555. dma_unmap_addr(&ee, mapaddr),
  2556. dma_unmap_len(&ee, maplen),
  2557. PCI_DMA_FROMDEVICE);
  2558. }
  2559. skb_put(skb, len);
  2560. if (dev->features & NETIF_F_RXCSUM) {
  2561. skb->csum = le16_to_cpu(csum);
  2562. skb->ip_summed = CHECKSUM_COMPLETE;
  2563. }
  2564. skb->protocol = eth_type_trans(skb, dev);
  2565. return skb;
  2566. error:
  2567. netif_printk(skge, rx_err, KERN_DEBUG, skge->netdev,
  2568. "rx err, slot %td control 0x%x status 0x%x\n",
  2569. e - skge->rx_ring.start, control, status);
  2570. if (is_genesis(skge->hw)) {
  2571. if (status & (XMR_FS_RUNT|XMR_FS_LNG_ERR))
  2572. dev->stats.rx_length_errors++;
  2573. if (status & XMR_FS_FRA_ERR)
  2574. dev->stats.rx_frame_errors++;
  2575. if (status & XMR_FS_FCS_ERR)
  2576. dev->stats.rx_crc_errors++;
  2577. } else {
  2578. if (status & (GMR_FS_LONG_ERR|GMR_FS_UN_SIZE))
  2579. dev->stats.rx_length_errors++;
  2580. if (status & GMR_FS_FRAGMENT)
  2581. dev->stats.rx_frame_errors++;
  2582. if (status & GMR_FS_CRC_ERR)
  2583. dev->stats.rx_crc_errors++;
  2584. }
  2585. resubmit:
  2586. skge_rx_reuse(e, skge->rx_buf_size);
  2587. return NULL;
  2588. }
  2589. /* Free all buffers in Tx ring which are no longer owned by device */
  2590. static void skge_tx_done(struct net_device *dev)
  2591. {
  2592. struct skge_port *skge = netdev_priv(dev);
  2593. struct skge_ring *ring = &skge->tx_ring;
  2594. struct skge_element *e;
  2595. unsigned int bytes_compl = 0, pkts_compl = 0;
  2596. skge_write8(skge->hw, Q_ADDR(txqaddr[skge->port], Q_CSR), CSR_IRQ_CL_F);
  2597. for (e = ring->to_clean; e != ring->to_use; e = e->next) {
  2598. u32 control = ((const struct skge_tx_desc *) e->desc)->control;
  2599. if (control & BMU_OWN)
  2600. break;
  2601. skge_tx_unmap(skge->hw->pdev, e, control);
  2602. if (control & BMU_EOF) {
  2603. netif_printk(skge, tx_done, KERN_DEBUG, skge->netdev,
  2604. "tx done slot %td\n",
  2605. e - skge->tx_ring.start);
  2606. pkts_compl++;
  2607. bytes_compl += e->skb->len;
  2608. dev_consume_skb_any(e->skb);
  2609. }
  2610. }
  2611. netdev_completed_queue(dev, pkts_compl, bytes_compl);
  2612. skge->tx_ring.to_clean = e;
  2613. /* Can run lockless until we need to synchronize to restart queue. */
  2614. smp_mb();
  2615. if (unlikely(netif_queue_stopped(dev) &&
  2616. skge_avail(&skge->tx_ring) > TX_LOW_WATER)) {
  2617. netif_tx_lock(dev);
  2618. if (unlikely(netif_queue_stopped(dev) &&
  2619. skge_avail(&skge->tx_ring) > TX_LOW_WATER)) {
  2620. netif_wake_queue(dev);
  2621. }
  2622. netif_tx_unlock(dev);
  2623. }
  2624. }
  2625. static int skge_poll(struct napi_struct *napi, int budget)
  2626. {
  2627. struct skge_port *skge = container_of(napi, struct skge_port, napi);
  2628. struct net_device *dev = skge->netdev;
  2629. struct skge_hw *hw = skge->hw;
  2630. struct skge_ring *ring = &skge->rx_ring;
  2631. struct skge_element *e;
  2632. int work_done = 0;
  2633. skge_tx_done(dev);
  2634. skge_write8(hw, Q_ADDR(rxqaddr[skge->port], Q_CSR), CSR_IRQ_CL_F);
  2635. for (e = ring->to_clean; prefetch(e->next), work_done < budget; e = e->next) {
  2636. struct skge_rx_desc *rd = e->desc;
  2637. struct sk_buff *skb;
  2638. u32 control;
  2639. rmb();
  2640. control = rd->control;
  2641. if (control & BMU_OWN)
  2642. break;
  2643. skb = skge_rx_get(dev, e, control, rd->status, rd->csum2);
  2644. if (likely(skb)) {
  2645. napi_gro_receive(napi, skb);
  2646. ++work_done;
  2647. }
  2648. }
  2649. ring->to_clean = e;
  2650. /* restart receiver */
  2651. wmb();
  2652. skge_write8(hw, Q_ADDR(rxqaddr[skge->port], Q_CSR), CSR_START);
  2653. if (work_done < budget && napi_complete_done(napi, work_done)) {
  2654. unsigned long flags;
  2655. spin_lock_irqsave(&hw->hw_lock, flags);
  2656. hw->intr_mask |= napimask[skge->port];
  2657. skge_write32(hw, B0_IMSK, hw->intr_mask);
  2658. skge_read32(hw, B0_IMSK);
  2659. spin_unlock_irqrestore(&hw->hw_lock, flags);
  2660. }
  2661. return work_done;
  2662. }
  2663. /* Parity errors seem to happen when Genesis is connected to a switch
  2664. * with no other ports present. Heartbeat error??
  2665. */
  2666. static void skge_mac_parity(struct skge_hw *hw, int port)
  2667. {
  2668. struct net_device *dev = hw->dev[port];
  2669. ++dev->stats.tx_heartbeat_errors;
  2670. if (is_genesis(hw))
  2671. skge_write16(hw, SK_REG(port, TX_MFF_CTRL1),
  2672. MFF_CLR_PERR);
  2673. else
  2674. /* HW-Bug #8: cleared by GMF_CLI_TX_FC instead of GMF_CLI_TX_PE */
  2675. skge_write8(hw, SK_REG(port, TX_GMF_CTRL_T),
  2676. (hw->chip_id == CHIP_ID_YUKON && hw->chip_rev == 0)
  2677. ? GMF_CLI_TX_FC : GMF_CLI_TX_PE);
  2678. }
  2679. static void skge_mac_intr(struct skge_hw *hw, int port)
  2680. {
  2681. if (is_genesis(hw))
  2682. genesis_mac_intr(hw, port);
  2683. else
  2684. yukon_mac_intr(hw, port);
  2685. }
  2686. /* Handle device specific framing and timeout interrupts */
  2687. static void skge_error_irq(struct skge_hw *hw)
  2688. {
  2689. struct pci_dev *pdev = hw->pdev;
  2690. u32 hwstatus = skge_read32(hw, B0_HWE_ISRC);
  2691. if (is_genesis(hw)) {
  2692. /* clear xmac errors */
  2693. if (hwstatus & (IS_NO_STAT_M1|IS_NO_TIST_M1))
  2694. skge_write16(hw, RX_MFF_CTRL1, MFF_CLR_INSTAT);
  2695. if (hwstatus & (IS_NO_STAT_M2|IS_NO_TIST_M2))
  2696. skge_write16(hw, RX_MFF_CTRL2, MFF_CLR_INSTAT);
  2697. } else {
  2698. /* Timestamp (unused) overflow */
  2699. if (hwstatus & IS_IRQ_TIST_OV)
  2700. skge_write8(hw, GMAC_TI_ST_CTRL, GMT_ST_CLR_IRQ);
  2701. }
  2702. if (hwstatus & IS_RAM_RD_PAR) {
  2703. dev_err(&pdev->dev, "Ram read data parity error\n");
  2704. skge_write16(hw, B3_RI_CTRL, RI_CLR_RD_PERR);
  2705. }
  2706. if (hwstatus & IS_RAM_WR_PAR) {
  2707. dev_err(&pdev->dev, "Ram write data parity error\n");
  2708. skge_write16(hw, B3_RI_CTRL, RI_CLR_WR_PERR);
  2709. }
  2710. if (hwstatus & IS_M1_PAR_ERR)
  2711. skge_mac_parity(hw, 0);
  2712. if (hwstatus & IS_M2_PAR_ERR)
  2713. skge_mac_parity(hw, 1);
  2714. if (hwstatus & IS_R1_PAR_ERR) {
  2715. dev_err(&pdev->dev, "%s: receive queue parity error\n",
  2716. hw->dev[0]->name);
  2717. skge_write32(hw, B0_R1_CSR, CSR_IRQ_CL_P);
  2718. }
  2719. if (hwstatus & IS_R2_PAR_ERR) {
  2720. dev_err(&pdev->dev, "%s: receive queue parity error\n",
  2721. hw->dev[1]->name);
  2722. skge_write32(hw, B0_R2_CSR, CSR_IRQ_CL_P);
  2723. }
  2724. if (hwstatus & (IS_IRQ_MST_ERR|IS_IRQ_STAT)) {
  2725. u16 pci_status, pci_cmd;
  2726. pci_read_config_word(pdev, PCI_COMMAND, &pci_cmd);
  2727. pci_read_config_word(pdev, PCI_STATUS, &pci_status);
  2728. dev_err(&pdev->dev, "PCI error cmd=%#x status=%#x\n",
  2729. pci_cmd, pci_status);
  2730. /* Write the error bits back to clear them. */
  2731. pci_status &= PCI_STATUS_ERROR_BITS;
  2732. skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
  2733. pci_write_config_word(pdev, PCI_COMMAND,
  2734. pci_cmd | PCI_COMMAND_SERR | PCI_COMMAND_PARITY);
  2735. pci_write_config_word(pdev, PCI_STATUS, pci_status);
  2736. skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
  2737. /* if error still set then just ignore it */
  2738. hwstatus = skge_read32(hw, B0_HWE_ISRC);
  2739. if (hwstatus & IS_IRQ_STAT) {
  2740. dev_warn(&hw->pdev->dev, "unable to clear error (so ignoring them)\n");
  2741. hw->intr_mask &= ~IS_HW_ERR;
  2742. }
  2743. }
  2744. }
  2745. /*
  2746. * Interrupt from PHY are handled in tasklet (softirq)
  2747. * because accessing phy registers requires spin wait which might
  2748. * cause excess interrupt latency.
  2749. */
  2750. static void skge_extirq(unsigned long arg)
  2751. {
  2752. struct skge_hw *hw = (struct skge_hw *) arg;
  2753. int port;
  2754. for (port = 0; port < hw->ports; port++) {
  2755. struct net_device *dev = hw->dev[port];
  2756. if (netif_running(dev)) {
  2757. struct skge_port *skge = netdev_priv(dev);
  2758. spin_lock(&hw->phy_lock);
  2759. if (!is_genesis(hw))
  2760. yukon_phy_intr(skge);
  2761. else if (hw->phy_type == SK_PHY_BCOM)
  2762. bcom_phy_intr(skge);
  2763. spin_unlock(&hw->phy_lock);
  2764. }
  2765. }
  2766. spin_lock_irq(&hw->hw_lock);
  2767. hw->intr_mask |= IS_EXT_REG;
  2768. skge_write32(hw, B0_IMSK, hw->intr_mask);
  2769. skge_read32(hw, B0_IMSK);
  2770. spin_unlock_irq(&hw->hw_lock);
  2771. }
  2772. static irqreturn_t skge_intr(int irq, void *dev_id)
  2773. {
  2774. struct skge_hw *hw = dev_id;
  2775. u32 status;
  2776. int handled = 0;
  2777. spin_lock(&hw->hw_lock);
  2778. /* Reading this register masks IRQ */
  2779. status = skge_read32(hw, B0_SP_ISRC);
  2780. if (status == 0 || status == ~0)
  2781. goto out;
  2782. handled = 1;
  2783. status &= hw->intr_mask;
  2784. if (status & IS_EXT_REG) {
  2785. hw->intr_mask &= ~IS_EXT_REG;
  2786. tasklet_schedule(&hw->phy_task);
  2787. }
  2788. if (status & (IS_XA1_F|IS_R1_F)) {
  2789. struct skge_port *skge = netdev_priv(hw->dev[0]);
  2790. hw->intr_mask &= ~(IS_XA1_F|IS_R1_F);
  2791. napi_schedule(&skge->napi);
  2792. }
  2793. if (status & IS_PA_TO_TX1)
  2794. skge_write16(hw, B3_PA_CTRL, PA_CLR_TO_TX1);
  2795. if (status & IS_PA_TO_RX1) {
  2796. ++hw->dev[0]->stats.rx_over_errors;
  2797. skge_write16(hw, B3_PA_CTRL, PA_CLR_TO_RX1);
  2798. }
  2799. if (status & IS_MAC1)
  2800. skge_mac_intr(hw, 0);
  2801. if (hw->dev[1]) {
  2802. struct skge_port *skge = netdev_priv(hw->dev[1]);
  2803. if (status & (IS_XA2_F|IS_R2_F)) {
  2804. hw->intr_mask &= ~(IS_XA2_F|IS_R2_F);
  2805. napi_schedule(&skge->napi);
  2806. }
  2807. if (status & IS_PA_TO_RX2) {
  2808. ++hw->dev[1]->stats.rx_over_errors;
  2809. skge_write16(hw, B3_PA_CTRL, PA_CLR_TO_RX2);
  2810. }
  2811. if (status & IS_PA_TO_TX2)
  2812. skge_write16(hw, B3_PA_CTRL, PA_CLR_TO_TX2);
  2813. if (status & IS_MAC2)
  2814. skge_mac_intr(hw, 1);
  2815. }
  2816. if (status & IS_HW_ERR)
  2817. skge_error_irq(hw);
  2818. out:
  2819. skge_write32(hw, B0_IMSK, hw->intr_mask);
  2820. skge_read32(hw, B0_IMSK);
  2821. spin_unlock(&hw->hw_lock);
  2822. return IRQ_RETVAL(handled);
  2823. }
  2824. #ifdef CONFIG_NET_POLL_CONTROLLER
  2825. static void skge_netpoll(struct net_device *dev)
  2826. {
  2827. struct skge_port *skge = netdev_priv(dev);
  2828. disable_irq(dev->irq);
  2829. skge_intr(dev->irq, skge->hw);
  2830. enable_irq(dev->irq);
  2831. }
  2832. #endif
  2833. static int skge_set_mac_address(struct net_device *dev, void *p)
  2834. {
  2835. struct skge_port *skge = netdev_priv(dev);
  2836. struct skge_hw *hw = skge->hw;
  2837. unsigned port = skge->port;
  2838. const struct sockaddr *addr = p;
  2839. u16 ctrl;
  2840. if (!is_valid_ether_addr(addr->sa_data))
  2841. return -EADDRNOTAVAIL;
  2842. memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
  2843. if (!netif_running(dev)) {
  2844. memcpy_toio(hw->regs + B2_MAC_1 + port*8, dev->dev_addr, ETH_ALEN);
  2845. memcpy_toio(hw->regs + B2_MAC_2 + port*8, dev->dev_addr, ETH_ALEN);
  2846. } else {
  2847. /* disable Rx */
  2848. spin_lock_bh(&hw->phy_lock);
  2849. ctrl = gma_read16(hw, port, GM_GP_CTRL);
  2850. gma_write16(hw, port, GM_GP_CTRL, ctrl & ~GM_GPCR_RX_ENA);
  2851. memcpy_toio(hw->regs + B2_MAC_1 + port*8, dev->dev_addr, ETH_ALEN);
  2852. memcpy_toio(hw->regs + B2_MAC_2 + port*8, dev->dev_addr, ETH_ALEN);
  2853. if (is_genesis(hw))
  2854. xm_outaddr(hw, port, XM_SA, dev->dev_addr);
  2855. else {
  2856. gma_set_addr(hw, port, GM_SRC_ADDR_1L, dev->dev_addr);
  2857. gma_set_addr(hw, port, GM_SRC_ADDR_2L, dev->dev_addr);
  2858. }
  2859. gma_write16(hw, port, GM_GP_CTRL, ctrl);
  2860. spin_unlock_bh(&hw->phy_lock);
  2861. }
  2862. return 0;
  2863. }
  2864. static const struct {
  2865. u8 id;
  2866. const char *name;
  2867. } skge_chips[] = {
  2868. { CHIP_ID_GENESIS, "Genesis" },
  2869. { CHIP_ID_YUKON, "Yukon" },
  2870. { CHIP_ID_YUKON_LITE, "Yukon-Lite"},
  2871. { CHIP_ID_YUKON_LP, "Yukon-LP"},
  2872. };
  2873. static const char *skge_board_name(const struct skge_hw *hw)
  2874. {
  2875. int i;
  2876. static char buf[16];
  2877. for (i = 0; i < ARRAY_SIZE(skge_chips); i++)
  2878. if (skge_chips[i].id == hw->chip_id)
  2879. return skge_chips[i].name;
  2880. snprintf(buf, sizeof(buf), "chipid 0x%x", hw->chip_id);
  2881. return buf;
  2882. }
  2883. /*
  2884. * Setup the board data structure, but don't bring up
  2885. * the port(s)
  2886. */
  2887. static int skge_reset(struct skge_hw *hw)
  2888. {
  2889. u32 reg;
  2890. u16 ctst, pci_status;
  2891. u8 t8, mac_cfg, pmd_type;
  2892. int i;
  2893. ctst = skge_read16(hw, B0_CTST);
  2894. /* do a SW reset */
  2895. skge_write8(hw, B0_CTST, CS_RST_SET);
  2896. skge_write8(hw, B0_CTST, CS_RST_CLR);
  2897. /* clear PCI errors, if any */
  2898. skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
  2899. skge_write8(hw, B2_TST_CTRL2, 0);
  2900. pci_read_config_word(hw->pdev, PCI_STATUS, &pci_status);
  2901. pci_write_config_word(hw->pdev, PCI_STATUS,
  2902. pci_status | PCI_STATUS_ERROR_BITS);
  2903. skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
  2904. skge_write8(hw, B0_CTST, CS_MRST_CLR);
  2905. /* restore CLK_RUN bits (for Yukon-Lite) */
  2906. skge_write16(hw, B0_CTST,
  2907. ctst & (CS_CLK_RUN_HOT|CS_CLK_RUN_RST|CS_CLK_RUN_ENA));
  2908. hw->chip_id = skge_read8(hw, B2_CHIP_ID);
  2909. hw->phy_type = skge_read8(hw, B2_E_1) & 0xf;
  2910. pmd_type = skge_read8(hw, B2_PMD_TYP);
  2911. hw->copper = (pmd_type == 'T' || pmd_type == '1');
  2912. switch (hw->chip_id) {
  2913. case CHIP_ID_GENESIS:
  2914. #ifdef CONFIG_SKGE_GENESIS
  2915. switch (hw->phy_type) {
  2916. case SK_PHY_XMAC:
  2917. hw->phy_addr = PHY_ADDR_XMAC;
  2918. break;
  2919. case SK_PHY_BCOM:
  2920. hw->phy_addr = PHY_ADDR_BCOM;
  2921. break;
  2922. default:
  2923. dev_err(&hw->pdev->dev, "unsupported phy type 0x%x\n",
  2924. hw->phy_type);
  2925. return -EOPNOTSUPP;
  2926. }
  2927. break;
  2928. #else
  2929. dev_err(&hw->pdev->dev, "Genesis chip detected but not configured\n");
  2930. return -EOPNOTSUPP;
  2931. #endif
  2932. case CHIP_ID_YUKON:
  2933. case CHIP_ID_YUKON_LITE:
  2934. case CHIP_ID_YUKON_LP:
  2935. if (hw->phy_type < SK_PHY_MARV_COPPER && pmd_type != 'S')
  2936. hw->copper = 1;
  2937. hw->phy_addr = PHY_ADDR_MARV;
  2938. break;
  2939. default:
  2940. dev_err(&hw->pdev->dev, "unsupported chip type 0x%x\n",
  2941. hw->chip_id);
  2942. return -EOPNOTSUPP;
  2943. }
  2944. mac_cfg = skge_read8(hw, B2_MAC_CFG);
  2945. hw->ports = (mac_cfg & CFG_SNG_MAC) ? 1 : 2;
  2946. hw->chip_rev = (mac_cfg & CFG_CHIP_R_MSK) >> 4;
  2947. /* read the adapters RAM size */
  2948. t8 = skge_read8(hw, B2_E_0);
  2949. if (is_genesis(hw)) {
  2950. if (t8 == 3) {
  2951. /* special case: 4 x 64k x 36, offset = 0x80000 */
  2952. hw->ram_size = 0x100000;
  2953. hw->ram_offset = 0x80000;
  2954. } else
  2955. hw->ram_size = t8 * 512;
  2956. } else if (t8 == 0)
  2957. hw->ram_size = 0x20000;
  2958. else
  2959. hw->ram_size = t8 * 4096;
  2960. hw->intr_mask = IS_HW_ERR;
  2961. /* Use PHY IRQ for all but fiber based Genesis board */
  2962. if (!(is_genesis(hw) && hw->phy_type == SK_PHY_XMAC))
  2963. hw->intr_mask |= IS_EXT_REG;
  2964. if (is_genesis(hw))
  2965. genesis_init(hw);
  2966. else {
  2967. /* switch power to VCC (WA for VAUX problem) */
  2968. skge_write8(hw, B0_POWER_CTRL,
  2969. PC_VAUX_ENA | PC_VCC_ENA | PC_VAUX_OFF | PC_VCC_ON);
  2970. /* avoid boards with stuck Hardware error bits */
  2971. if ((skge_read32(hw, B0_ISRC) & IS_HW_ERR) &&
  2972. (skge_read32(hw, B0_HWE_ISRC) & IS_IRQ_SENSOR)) {
  2973. dev_warn(&hw->pdev->dev, "stuck hardware sensor bit\n");
  2974. hw->intr_mask &= ~IS_HW_ERR;
  2975. }
  2976. /* Clear PHY COMA */
  2977. skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
  2978. pci_read_config_dword(hw->pdev, PCI_DEV_REG1, &reg);
  2979. reg &= ~PCI_PHY_COMA;
  2980. pci_write_config_dword(hw->pdev, PCI_DEV_REG1, reg);
  2981. skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
  2982. for (i = 0; i < hw->ports; i++) {
  2983. skge_write16(hw, SK_REG(i, GMAC_LINK_CTRL), GMLC_RST_SET);
  2984. skge_write16(hw, SK_REG(i, GMAC_LINK_CTRL), GMLC_RST_CLR);
  2985. }
  2986. }
  2987. /* turn off hardware timer (unused) */
  2988. skge_write8(hw, B2_TI_CTRL, TIM_STOP);
  2989. skge_write8(hw, B2_TI_CTRL, TIM_CLR_IRQ);
  2990. skge_write8(hw, B0_LED, LED_STAT_ON);
  2991. /* enable the Tx Arbiters */
  2992. for (i = 0; i < hw->ports; i++)
  2993. skge_write8(hw, SK_REG(i, TXA_CTRL), TXA_ENA_ARB);
  2994. /* Initialize ram interface */
  2995. skge_write16(hw, B3_RI_CTRL, RI_RST_CLR);
  2996. skge_write8(hw, B3_RI_WTO_R1, SK_RI_TO_53);
  2997. skge_write8(hw, B3_RI_WTO_XA1, SK_RI_TO_53);
  2998. skge_write8(hw, B3_RI_WTO_XS1, SK_RI_TO_53);
  2999. skge_write8(hw, B3_RI_RTO_R1, SK_RI_TO_53);
  3000. skge_write8(hw, B3_RI_RTO_XA1, SK_RI_TO_53);
  3001. skge_write8(hw, B3_RI_RTO_XS1, SK_RI_TO_53);
  3002. skge_write8(hw, B3_RI_WTO_R2, SK_RI_TO_53);
  3003. skge_write8(hw, B3_RI_WTO_XA2, SK_RI_TO_53);
  3004. skge_write8(hw, B3_RI_WTO_XS2, SK_RI_TO_53);
  3005. skge_write8(hw, B3_RI_RTO_R2, SK_RI_TO_53);
  3006. skge_write8(hw, B3_RI_RTO_XA2, SK_RI_TO_53);
  3007. skge_write8(hw, B3_RI_RTO_XS2, SK_RI_TO_53);
  3008. skge_write32(hw, B0_HWE_IMSK, IS_ERR_MSK);
  3009. /* Set interrupt moderation for Transmit only
  3010. * Receive interrupts avoided by NAPI
  3011. */
  3012. skge_write32(hw, B2_IRQM_MSK, IS_XA1_F|IS_XA2_F);
  3013. skge_write32(hw, B2_IRQM_INI, skge_usecs2clk(hw, 100));
  3014. skge_write32(hw, B2_IRQM_CTRL, TIM_START);
  3015. /* Leave irq disabled until first port is brought up. */
  3016. skge_write32(hw, B0_IMSK, 0);
  3017. for (i = 0; i < hw->ports; i++) {
  3018. if (is_genesis(hw))
  3019. genesis_reset(hw, i);
  3020. else
  3021. yukon_reset(hw, i);
  3022. }
  3023. return 0;
  3024. }
  3025. #ifdef CONFIG_SKGE_DEBUG
  3026. static struct dentry *skge_debug;
  3027. static int skge_debug_show(struct seq_file *seq, void *v)
  3028. {
  3029. struct net_device *dev = seq->private;
  3030. const struct skge_port *skge = netdev_priv(dev);
  3031. const struct skge_hw *hw = skge->hw;
  3032. const struct skge_element *e;
  3033. if (!netif_running(dev))
  3034. return -ENETDOWN;
  3035. seq_printf(seq, "IRQ src=%x mask=%x\n", skge_read32(hw, B0_ISRC),
  3036. skge_read32(hw, B0_IMSK));
  3037. seq_printf(seq, "Tx Ring: (%d)\n", skge_avail(&skge->tx_ring));
  3038. for (e = skge->tx_ring.to_clean; e != skge->tx_ring.to_use; e = e->next) {
  3039. const struct skge_tx_desc *t = e->desc;
  3040. seq_printf(seq, "%#x dma=%#x%08x %#x csum=%#x/%x/%x\n",
  3041. t->control, t->dma_hi, t->dma_lo, t->status,
  3042. t->csum_offs, t->csum_write, t->csum_start);
  3043. }
  3044. seq_puts(seq, "\nRx Ring:\n");
  3045. for (e = skge->rx_ring.to_clean; ; e = e->next) {
  3046. const struct skge_rx_desc *r = e->desc;
  3047. if (r->control & BMU_OWN)
  3048. break;
  3049. seq_printf(seq, "%#x dma=%#x%08x %#x %#x csum=%#x/%x\n",
  3050. r->control, r->dma_hi, r->dma_lo, r->status,
  3051. r->timestamp, r->csum1, r->csum1_start);
  3052. }
  3053. return 0;
  3054. }
  3055. static int skge_debug_open(struct inode *inode, struct file *file)
  3056. {
  3057. return single_open(file, skge_debug_show, inode->i_private);
  3058. }
  3059. static const struct file_operations skge_debug_fops = {
  3060. .owner = THIS_MODULE,
  3061. .open = skge_debug_open,
  3062. .read = seq_read,
  3063. .llseek = seq_lseek,
  3064. .release = single_release,
  3065. };
  3066. /*
  3067. * Use network device events to create/remove/rename
  3068. * debugfs file entries
  3069. */
  3070. static int skge_device_event(struct notifier_block *unused,
  3071. unsigned long event, void *ptr)
  3072. {
  3073. struct net_device *dev = netdev_notifier_info_to_dev(ptr);
  3074. struct skge_port *skge;
  3075. struct dentry *d;
  3076. if (dev->netdev_ops->ndo_open != &skge_up || !skge_debug)
  3077. goto done;
  3078. skge = netdev_priv(dev);
  3079. switch (event) {
  3080. case NETDEV_CHANGENAME:
  3081. if (skge->debugfs) {
  3082. d = debugfs_rename(skge_debug, skge->debugfs,
  3083. skge_debug, dev->name);
  3084. if (d)
  3085. skge->debugfs = d;
  3086. else {
  3087. netdev_info(dev, "rename failed\n");
  3088. debugfs_remove(skge->debugfs);
  3089. }
  3090. }
  3091. break;
  3092. case NETDEV_GOING_DOWN:
  3093. if (skge->debugfs) {
  3094. debugfs_remove(skge->debugfs);
  3095. skge->debugfs = NULL;
  3096. }
  3097. break;
  3098. case NETDEV_UP:
  3099. d = debugfs_create_file(dev->name, 0444,
  3100. skge_debug, dev,
  3101. &skge_debug_fops);
  3102. if (!d || IS_ERR(d))
  3103. netdev_info(dev, "debugfs create failed\n");
  3104. else
  3105. skge->debugfs = d;
  3106. break;
  3107. }
  3108. done:
  3109. return NOTIFY_DONE;
  3110. }
  3111. static struct notifier_block skge_notifier = {
  3112. .notifier_call = skge_device_event,
  3113. };
  3114. static __init void skge_debug_init(void)
  3115. {
  3116. struct dentry *ent;
  3117. ent = debugfs_create_dir("skge", NULL);
  3118. if (!ent || IS_ERR(ent)) {
  3119. pr_info("debugfs create directory failed\n");
  3120. return;
  3121. }
  3122. skge_debug = ent;
  3123. register_netdevice_notifier(&skge_notifier);
  3124. }
  3125. static __exit void skge_debug_cleanup(void)
  3126. {
  3127. if (skge_debug) {
  3128. unregister_netdevice_notifier(&skge_notifier);
  3129. debugfs_remove(skge_debug);
  3130. skge_debug = NULL;
  3131. }
  3132. }
  3133. #else
  3134. #define skge_debug_init()
  3135. #define skge_debug_cleanup()
  3136. #endif
  3137. static const struct net_device_ops skge_netdev_ops = {
  3138. .ndo_open = skge_up,
  3139. .ndo_stop = skge_down,
  3140. .ndo_start_xmit = skge_xmit_frame,
  3141. .ndo_do_ioctl = skge_ioctl,
  3142. .ndo_get_stats = skge_get_stats,
  3143. .ndo_tx_timeout = skge_tx_timeout,
  3144. .ndo_change_mtu = skge_change_mtu,
  3145. .ndo_validate_addr = eth_validate_addr,
  3146. .ndo_set_rx_mode = skge_set_multicast,
  3147. .ndo_set_mac_address = skge_set_mac_address,
  3148. #ifdef CONFIG_NET_POLL_CONTROLLER
  3149. .ndo_poll_controller = skge_netpoll,
  3150. #endif
  3151. };
  3152. /* Initialize network device */
  3153. static struct net_device *skge_devinit(struct skge_hw *hw, int port,
  3154. int highmem)
  3155. {
  3156. struct skge_port *skge;
  3157. struct net_device *dev = alloc_etherdev(sizeof(*skge));
  3158. if (!dev)
  3159. return NULL;
  3160. SET_NETDEV_DEV(dev, &hw->pdev->dev);
  3161. dev->netdev_ops = &skge_netdev_ops;
  3162. dev->ethtool_ops = &skge_ethtool_ops;
  3163. dev->watchdog_timeo = TX_WATCHDOG;
  3164. dev->irq = hw->pdev->irq;
  3165. /* MTU range: 60 - 9000 */
  3166. dev->min_mtu = ETH_ZLEN;
  3167. dev->max_mtu = ETH_JUMBO_MTU;
  3168. if (highmem)
  3169. dev->features |= NETIF_F_HIGHDMA;
  3170. skge = netdev_priv(dev);
  3171. netif_napi_add(dev, &skge->napi, skge_poll, NAPI_WEIGHT);
  3172. skge->netdev = dev;
  3173. skge->hw = hw;
  3174. skge->msg_enable = netif_msg_init(debug, default_msg);
  3175. skge->tx_ring.count = DEFAULT_TX_RING_SIZE;
  3176. skge->rx_ring.count = DEFAULT_RX_RING_SIZE;
  3177. /* Auto speed and flow control */
  3178. skge->autoneg = AUTONEG_ENABLE;
  3179. skge->flow_control = FLOW_MODE_SYM_OR_REM;
  3180. skge->duplex = -1;
  3181. skge->speed = -1;
  3182. skge->advertising = skge_supported_modes(hw);
  3183. if (device_can_wakeup(&hw->pdev->dev)) {
  3184. skge->wol = wol_supported(hw) & WAKE_MAGIC;
  3185. device_set_wakeup_enable(&hw->pdev->dev, skge->wol);
  3186. }
  3187. hw->dev[port] = dev;
  3188. skge->port = port;
  3189. /* Only used for Genesis XMAC */
  3190. if (is_genesis(hw))
  3191. timer_setup(&skge->link_timer, xm_link_timer, 0);
  3192. else {
  3193. dev->hw_features = NETIF_F_IP_CSUM | NETIF_F_SG |
  3194. NETIF_F_RXCSUM;
  3195. dev->features |= dev->hw_features;
  3196. }
  3197. /* read the mac address */
  3198. memcpy_fromio(dev->dev_addr, hw->regs + B2_MAC_1 + port*8, ETH_ALEN);
  3199. return dev;
  3200. }
  3201. static void skge_show_addr(struct net_device *dev)
  3202. {
  3203. const struct skge_port *skge = netdev_priv(dev);
  3204. netif_info(skge, probe, skge->netdev, "addr %pM\n", dev->dev_addr);
  3205. }
  3206. static int only_32bit_dma;
  3207. static int skge_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  3208. {
  3209. struct net_device *dev, *dev1;
  3210. struct skge_hw *hw;
  3211. int err, using_dac = 0;
  3212. err = pci_enable_device(pdev);
  3213. if (err) {
  3214. dev_err(&pdev->dev, "cannot enable PCI device\n");
  3215. goto err_out;
  3216. }
  3217. err = pci_request_regions(pdev, DRV_NAME);
  3218. if (err) {
  3219. dev_err(&pdev->dev, "cannot obtain PCI resources\n");
  3220. goto err_out_disable_pdev;
  3221. }
  3222. pci_set_master(pdev);
  3223. if (!only_32bit_dma && !pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
  3224. using_dac = 1;
  3225. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
  3226. } else if (!(err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)))) {
  3227. using_dac = 0;
  3228. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  3229. }
  3230. if (err) {
  3231. dev_err(&pdev->dev, "no usable DMA configuration\n");
  3232. goto err_out_free_regions;
  3233. }
  3234. #ifdef __BIG_ENDIAN
  3235. /* byte swap descriptors in hardware */
  3236. {
  3237. u32 reg;
  3238. pci_read_config_dword(pdev, PCI_DEV_REG2, &reg);
  3239. reg |= PCI_REV_DESC;
  3240. pci_write_config_dword(pdev, PCI_DEV_REG2, reg);
  3241. }
  3242. #endif
  3243. err = -ENOMEM;
  3244. /* space for skge@pci:0000:04:00.0 */
  3245. hw = kzalloc(sizeof(*hw) + strlen(DRV_NAME "@pci:")
  3246. + strlen(pci_name(pdev)) + 1, GFP_KERNEL);
  3247. if (!hw)
  3248. goto err_out_free_regions;
  3249. sprintf(hw->irq_name, DRV_NAME "@pci:%s", pci_name(pdev));
  3250. hw->pdev = pdev;
  3251. spin_lock_init(&hw->hw_lock);
  3252. spin_lock_init(&hw->phy_lock);
  3253. tasklet_init(&hw->phy_task, skge_extirq, (unsigned long) hw);
  3254. hw->regs = ioremap_nocache(pci_resource_start(pdev, 0), 0x4000);
  3255. if (!hw->regs) {
  3256. dev_err(&pdev->dev, "cannot map device registers\n");
  3257. goto err_out_free_hw;
  3258. }
  3259. err = skge_reset(hw);
  3260. if (err)
  3261. goto err_out_iounmap;
  3262. pr_info("%s addr 0x%llx irq %d chip %s rev %d\n",
  3263. DRV_VERSION,
  3264. (unsigned long long)pci_resource_start(pdev, 0), pdev->irq,
  3265. skge_board_name(hw), hw->chip_rev);
  3266. dev = skge_devinit(hw, 0, using_dac);
  3267. if (!dev) {
  3268. err = -ENOMEM;
  3269. goto err_out_led_off;
  3270. }
  3271. /* Some motherboards are broken and has zero in ROM. */
  3272. if (!is_valid_ether_addr(dev->dev_addr))
  3273. dev_warn(&pdev->dev, "bad (zero?) ethernet address in rom\n");
  3274. err = register_netdev(dev);
  3275. if (err) {
  3276. dev_err(&pdev->dev, "cannot register net device\n");
  3277. goto err_out_free_netdev;
  3278. }
  3279. skge_show_addr(dev);
  3280. if (hw->ports > 1) {
  3281. dev1 = skge_devinit(hw, 1, using_dac);
  3282. if (!dev1) {
  3283. err = -ENOMEM;
  3284. goto err_out_unregister;
  3285. }
  3286. err = register_netdev(dev1);
  3287. if (err) {
  3288. dev_err(&pdev->dev, "cannot register second net device\n");
  3289. goto err_out_free_dev1;
  3290. }
  3291. err = request_irq(pdev->irq, skge_intr, IRQF_SHARED,
  3292. hw->irq_name, hw);
  3293. if (err) {
  3294. dev_err(&pdev->dev, "cannot assign irq %d\n",
  3295. pdev->irq);
  3296. goto err_out_unregister_dev1;
  3297. }
  3298. skge_show_addr(dev1);
  3299. }
  3300. pci_set_drvdata(pdev, hw);
  3301. return 0;
  3302. err_out_unregister_dev1:
  3303. unregister_netdev(dev1);
  3304. err_out_free_dev1:
  3305. free_netdev(dev1);
  3306. err_out_unregister:
  3307. unregister_netdev(dev);
  3308. err_out_free_netdev:
  3309. free_netdev(dev);
  3310. err_out_led_off:
  3311. skge_write16(hw, B0_LED, LED_STAT_OFF);
  3312. err_out_iounmap:
  3313. iounmap(hw->regs);
  3314. err_out_free_hw:
  3315. kfree(hw);
  3316. err_out_free_regions:
  3317. pci_release_regions(pdev);
  3318. err_out_disable_pdev:
  3319. pci_disable_device(pdev);
  3320. err_out:
  3321. return err;
  3322. }
  3323. static void skge_remove(struct pci_dev *pdev)
  3324. {
  3325. struct skge_hw *hw = pci_get_drvdata(pdev);
  3326. struct net_device *dev0, *dev1;
  3327. if (!hw)
  3328. return;
  3329. dev1 = hw->dev[1];
  3330. if (dev1)
  3331. unregister_netdev(dev1);
  3332. dev0 = hw->dev[0];
  3333. unregister_netdev(dev0);
  3334. tasklet_kill(&hw->phy_task);
  3335. spin_lock_irq(&hw->hw_lock);
  3336. hw->intr_mask = 0;
  3337. if (hw->ports > 1) {
  3338. skge_write32(hw, B0_IMSK, 0);
  3339. skge_read32(hw, B0_IMSK);
  3340. }
  3341. spin_unlock_irq(&hw->hw_lock);
  3342. skge_write16(hw, B0_LED, LED_STAT_OFF);
  3343. skge_write8(hw, B0_CTST, CS_RST_SET);
  3344. if (hw->ports > 1)
  3345. free_irq(pdev->irq, hw);
  3346. pci_release_regions(pdev);
  3347. pci_disable_device(pdev);
  3348. if (dev1)
  3349. free_netdev(dev1);
  3350. free_netdev(dev0);
  3351. iounmap(hw->regs);
  3352. kfree(hw);
  3353. }
  3354. #ifdef CONFIG_PM_SLEEP
  3355. static int skge_suspend(struct device *dev)
  3356. {
  3357. struct pci_dev *pdev = to_pci_dev(dev);
  3358. struct skge_hw *hw = pci_get_drvdata(pdev);
  3359. int i;
  3360. if (!hw)
  3361. return 0;
  3362. for (i = 0; i < hw->ports; i++) {
  3363. struct net_device *dev = hw->dev[i];
  3364. struct skge_port *skge = netdev_priv(dev);
  3365. if (netif_running(dev))
  3366. skge_down(dev);
  3367. if (skge->wol)
  3368. skge_wol_init(skge);
  3369. }
  3370. skge_write32(hw, B0_IMSK, 0);
  3371. return 0;
  3372. }
  3373. static int skge_resume(struct device *dev)
  3374. {
  3375. struct pci_dev *pdev = to_pci_dev(dev);
  3376. struct skge_hw *hw = pci_get_drvdata(pdev);
  3377. int i, err;
  3378. if (!hw)
  3379. return 0;
  3380. err = skge_reset(hw);
  3381. if (err)
  3382. goto out;
  3383. for (i = 0; i < hw->ports; i++) {
  3384. struct net_device *dev = hw->dev[i];
  3385. if (netif_running(dev)) {
  3386. err = skge_up(dev);
  3387. if (err) {
  3388. netdev_err(dev, "could not up: %d\n", err);
  3389. dev_close(dev);
  3390. goto out;
  3391. }
  3392. }
  3393. }
  3394. out:
  3395. return err;
  3396. }
  3397. static SIMPLE_DEV_PM_OPS(skge_pm_ops, skge_suspend, skge_resume);
  3398. #define SKGE_PM_OPS (&skge_pm_ops)
  3399. #else
  3400. #define SKGE_PM_OPS NULL
  3401. #endif /* CONFIG_PM_SLEEP */
  3402. static void skge_shutdown(struct pci_dev *pdev)
  3403. {
  3404. struct skge_hw *hw = pci_get_drvdata(pdev);
  3405. int i;
  3406. if (!hw)
  3407. return;
  3408. for (i = 0; i < hw->ports; i++) {
  3409. struct net_device *dev = hw->dev[i];
  3410. struct skge_port *skge = netdev_priv(dev);
  3411. if (skge->wol)
  3412. skge_wol_init(skge);
  3413. }
  3414. pci_wake_from_d3(pdev, device_may_wakeup(&pdev->dev));
  3415. pci_set_power_state(pdev, PCI_D3hot);
  3416. }
  3417. static struct pci_driver skge_driver = {
  3418. .name = DRV_NAME,
  3419. .id_table = skge_id_table,
  3420. .probe = skge_probe,
  3421. .remove = skge_remove,
  3422. .shutdown = skge_shutdown,
  3423. .driver.pm = SKGE_PM_OPS,
  3424. };
  3425. static const struct dmi_system_id skge_32bit_dma_boards[] = {
  3426. {
  3427. .ident = "Gigabyte nForce boards",
  3428. .matches = {
  3429. DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co"),
  3430. DMI_MATCH(DMI_BOARD_NAME, "nForce"),
  3431. },
  3432. },
  3433. {
  3434. .ident = "ASUS P5NSLI",
  3435. .matches = {
  3436. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
  3437. DMI_MATCH(DMI_BOARD_NAME, "P5NSLI")
  3438. },
  3439. },
  3440. {
  3441. .ident = "FUJITSU SIEMENS A8NE-FM",
  3442. .matches = {
  3443. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTek Computer INC."),
  3444. DMI_MATCH(DMI_BOARD_NAME, "A8NE-FM")
  3445. },
  3446. },
  3447. {}
  3448. };
  3449. static int __init skge_init_module(void)
  3450. {
  3451. if (dmi_check_system(skge_32bit_dma_boards))
  3452. only_32bit_dma = 1;
  3453. skge_debug_init();
  3454. return pci_register_driver(&skge_driver);
  3455. }
  3456. static void __exit skge_cleanup_module(void)
  3457. {
  3458. pci_unregister_driver(&skge_driver);
  3459. skge_debug_cleanup();
  3460. }
  3461. module_init(skge_init_module);
  3462. module_exit(skge_cleanup_module);