fcc_enet.c 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397
  1. /*
  2. * Fast Ethernet Controller (FCC) driver for Motorola MPC8260.
  3. * Copyright (c) 2000 MontaVista Software, Inc. Dan Malek (dmalek@jlc.net)
  4. *
  5. * This version of the driver is a combination of the 8xx fec and
  6. * 8260 SCC Ethernet drivers. This version has some additional
  7. * configuration options, which should probably be moved out of
  8. * here. This driver currently works for the EST SBC8260,
  9. * SBS Diablo/BCM, Embedded Planet RPX6, TQM8260, and others.
  10. *
  11. * Right now, I am very watseful with the buffers. I allocate memory
  12. * pages and then divide them into 2K frame buffers. This way I know I
  13. * have buffers large enough to hold one frame within one buffer descriptor.
  14. * Once I get this working, I will use 64 or 128 byte CPM buffers, which
  15. * will be much more memory efficient and will easily handle lots of
  16. * small packets. Since this is a cache coherent processor and CPM,
  17. * I could also preallocate SKB's and use them directly on the interface.
  18. *
  19. * 2004-12 Leo Li (leoli@freescale.com)
  20. * - Rework the FCC clock configuration part, make it easier to configure.
  21. *
  22. */
  23. #include <linux/kernel.h>
  24. #include <linux/sched.h>
  25. #include <linux/string.h>
  26. #include <linux/ptrace.h>
  27. #include <linux/errno.h>
  28. #include <linux/ioport.h>
  29. #include <linux/slab.h>
  30. #include <linux/interrupt.h>
  31. #include <linux/pci.h>
  32. #include <linux/init.h>
  33. #include <linux/delay.h>
  34. #include <linux/netdevice.h>
  35. #include <linux/etherdevice.h>
  36. #include <linux/skbuff.h>
  37. #include <linux/spinlock.h>
  38. #include <linux/mii.h>
  39. #include <linux/workqueue.h>
  40. #include <linux/bitops.h>
  41. #include <asm/immap_cpm2.h>
  42. #include <asm/pgtable.h>
  43. #include <asm/mpc8260.h>
  44. #include <asm/irq.h>
  45. #include <asm/uaccess.h>
  46. #include <asm/signal.h>
  47. /* We can't use the PHY interrupt if we aren't using MDIO. */
  48. #if !defined(CONFIG_USE_MDIO)
  49. #undef PHY_INTERRUPT
  50. #endif
  51. /* If we have a PHY interrupt, we will advertise both full-duplex and half-
  52. * duplex capabilities. If we don't have a PHY interrupt, then we will only
  53. * advertise half-duplex capabilities.
  54. */
  55. #define MII_ADVERTISE_HALF (ADVERTISE_100HALF | ADVERTISE_10HALF | \
  56. ADVERTISE_CSMA)
  57. #define MII_ADVERTISE_ALL (ADVERTISE_100FULL | ADVERTISE_10FULL | \
  58. MII_ADVERTISE_HALF)
  59. #ifdef PHY_INTERRUPT
  60. #define MII_ADVERTISE_DEFAULT MII_ADVERTISE_ALL
  61. #else
  62. #define MII_ADVERTISE_DEFAULT MII_ADVERTISE_HALF
  63. #endif
  64. #include <asm/cpm2.h>
  65. /* The transmitter timeout
  66. */
  67. #define TX_TIMEOUT (2*HZ)
  68. #ifdef CONFIG_USE_MDIO
  69. /* Forward declarations of some structures to support different PHYs */
  70. typedef struct {
  71. uint mii_data;
  72. void (*funct)(uint mii_reg, struct net_device *dev);
  73. } phy_cmd_t;
  74. typedef struct {
  75. uint id;
  76. char *name;
  77. const phy_cmd_t *config;
  78. const phy_cmd_t *startup;
  79. const phy_cmd_t *ack_int;
  80. const phy_cmd_t *shutdown;
  81. } phy_info_t;
  82. /* values for phy_status */
  83. #define PHY_CONF_ANE 0x0001 /* 1 auto-negotiation enabled */
  84. #define PHY_CONF_LOOP 0x0002 /* 1 loopback mode enabled */
  85. #define PHY_CONF_SPMASK 0x00f0 /* mask for speed */
  86. #define PHY_CONF_10HDX 0x0010 /* 10 Mbit half duplex supported */
  87. #define PHY_CONF_10FDX 0x0020 /* 10 Mbit full duplex supported */
  88. #define PHY_CONF_100HDX 0x0040 /* 100 Mbit half duplex supported */
  89. #define PHY_CONF_100FDX 0x0080 /* 100 Mbit full duplex supported */
  90. #define PHY_STAT_LINK 0x0100 /* 1 up - 0 down */
  91. #define PHY_STAT_FAULT 0x0200 /* 1 remote fault */
  92. #define PHY_STAT_ANC 0x0400 /* 1 auto-negotiation complete */
  93. #define PHY_STAT_SPMASK 0xf000 /* mask for speed */
  94. #define PHY_STAT_10HDX 0x1000 /* 10 Mbit half duplex selected */
  95. #define PHY_STAT_10FDX 0x2000 /* 10 Mbit full duplex selected */
  96. #define PHY_STAT_100HDX 0x4000 /* 100 Mbit half duplex selected */
  97. #define PHY_STAT_100FDX 0x8000 /* 100 Mbit full duplex selected */
  98. #endif /* CONFIG_USE_MDIO */
  99. /* The number of Tx and Rx buffers. These are allocated from the page
  100. * pool. The code may assume these are power of two, so it is best
  101. * to keep them that size.
  102. * We don't need to allocate pages for the transmitter. We just use
  103. * the skbuffer directly.
  104. */
  105. #define FCC_ENET_RX_PAGES 16
  106. #define FCC_ENET_RX_FRSIZE 2048
  107. #define FCC_ENET_RX_FRPPG (PAGE_SIZE / FCC_ENET_RX_FRSIZE)
  108. #define RX_RING_SIZE (FCC_ENET_RX_FRPPG * FCC_ENET_RX_PAGES)
  109. #define TX_RING_SIZE 16 /* Must be power of two */
  110. #define TX_RING_MOD_MASK 15 /* for this to work */
  111. /* The FCC stores dest/src/type, data, and checksum for receive packets.
  112. * size includes support for VLAN
  113. */
  114. #define PKT_MAXBUF_SIZE 1522
  115. #define PKT_MINBUF_SIZE 64
  116. /* Maximum input DMA size. Must be a should(?) be a multiple of 4.
  117. * size includes support for VLAN
  118. */
  119. #define PKT_MAXDMA_SIZE 1524
  120. /* Maximum input buffer size. Must be a multiple of 32.
  121. */
  122. #define PKT_MAXBLR_SIZE 1536
  123. static int fcc_enet_open(struct net_device *dev);
  124. static int fcc_enet_start_xmit(struct sk_buff *skb, struct net_device *dev);
  125. static int fcc_enet_rx(struct net_device *dev);
  126. static irqreturn_t fcc_enet_interrupt(int irq, void *dev_id);
  127. static int fcc_enet_close(struct net_device *dev);
  128. static struct net_device_stats *fcc_enet_get_stats(struct net_device *dev);
  129. /* static void set_multicast_list(struct net_device *dev); */
  130. static void fcc_restart(struct net_device *dev, int duplex);
  131. static void fcc_stop(struct net_device *dev);
  132. static int fcc_enet_set_mac_address(struct net_device *dev, void *addr);
  133. /* These will be configurable for the FCC choice.
  134. * Multiple ports can be configured. There is little choice among the
  135. * I/O pins to the PHY, except the clocks. We will need some board
  136. * dependent clock selection.
  137. * Why in the hell did I put these inside #ifdef's? I dunno, maybe to
  138. * help show what pins are used for each device.
  139. */
  140. /* Since the CLK setting changes greatly from board to board, I changed
  141. * it to a easy way. You just need to specify which CLK number to use.
  142. * Note that only limited choices can be make on each port.
  143. */
  144. /* FCC1 Clock Source Configuration. There are board specific.
  145. Can only choose from CLK9-12 */
  146. #ifdef CONFIG_SBC82xx
  147. #define F1_RXCLK 9
  148. #define F1_TXCLK 10
  149. #elif defined(CONFIG_ADS8272)
  150. #define F1_RXCLK 11
  151. #define F1_TXCLK 10
  152. #else
  153. #define F1_RXCLK 12
  154. #define F1_TXCLK 11
  155. #endif
  156. /* FCC2 Clock Source Configuration. There are board specific.
  157. Can only choose from CLK13-16 */
  158. #ifdef CONFIG_ADS8272
  159. #define F2_RXCLK 15
  160. #define F2_TXCLK 16
  161. #else
  162. #define F2_RXCLK 13
  163. #define F2_TXCLK 14
  164. #endif
  165. /* FCC3 Clock Source Configuration. There are board specific.
  166. Can only choose from CLK13-16 */
  167. #define F3_RXCLK 15
  168. #define F3_TXCLK 16
  169. /* Automatically generates register configurations */
  170. #define PC_CLK(x) ((uint)(1<<(x-1))) /* FCC CLK I/O ports */
  171. #define CMXFCR_RF1CS(x) ((uint)((x-5)<<27)) /* FCC1 Receive Clock Source */
  172. #define CMXFCR_TF1CS(x) ((uint)((x-5)<<24)) /* FCC1 Transmit Clock Source */
  173. #define CMXFCR_RF2CS(x) ((uint)((x-9)<<19)) /* FCC2 Receive Clock Source */
  174. #define CMXFCR_TF2CS(x) ((uint)((x-9)<<16)) /* FCC2 Transmit Clock Source */
  175. #define CMXFCR_RF3CS(x) ((uint)((x-9)<<11)) /* FCC3 Receive Clock Source */
  176. #define CMXFCR_TF3CS(x) ((uint)((x-9)<<8)) /* FCC3 Transmit Clock Source */
  177. #define PC_F1RXCLK PC_CLK(F1_RXCLK)
  178. #define PC_F1TXCLK PC_CLK(F1_TXCLK)
  179. #define CMX1_CLK_ROUTE (CMXFCR_RF1CS(F1_RXCLK) | CMXFCR_TF1CS(F1_TXCLK))
  180. #define CMX1_CLK_MASK ((uint)0xff000000)
  181. #define PC_F2RXCLK PC_CLK(F2_RXCLK)
  182. #define PC_F2TXCLK PC_CLK(F2_TXCLK)
  183. #define CMX2_CLK_ROUTE (CMXFCR_RF2CS(F2_RXCLK) | CMXFCR_TF2CS(F2_TXCLK))
  184. #define CMX2_CLK_MASK ((uint)0x00ff0000)
  185. #define PC_F3RXCLK PC_CLK(F3_RXCLK)
  186. #define PC_F3TXCLK PC_CLK(F3_TXCLK)
  187. #define CMX3_CLK_ROUTE (CMXFCR_RF3CS(F3_RXCLK) | CMXFCR_TF3CS(F3_TXCLK))
  188. #define CMX3_CLK_MASK ((uint)0x0000ff00)
  189. /* I/O Pin assignment for FCC1. I don't yet know the best way to do this,
  190. * but there is little variation among the choices.
  191. */
  192. #define PA1_COL ((uint)0x00000001)
  193. #define PA1_CRS ((uint)0x00000002)
  194. #define PA1_TXER ((uint)0x00000004)
  195. #define PA1_TXEN ((uint)0x00000008)
  196. #define PA1_RXDV ((uint)0x00000010)
  197. #define PA1_RXER ((uint)0x00000020)
  198. #define PA1_TXDAT ((uint)0x00003c00)
  199. #define PA1_RXDAT ((uint)0x0003c000)
  200. #define PA1_PSORA_BOUT (PA1_RXDAT | PA1_TXDAT)
  201. #define PA1_PSORA_BIN (PA1_COL | PA1_CRS | PA1_TXER | PA1_TXEN | \
  202. PA1_RXDV | PA1_RXER)
  203. #define PA1_DIRA_BOUT (PA1_RXDAT | PA1_CRS | PA1_COL | PA1_RXER | PA1_RXDV)
  204. #define PA1_DIRA_BIN (PA1_TXDAT | PA1_TXEN | PA1_TXER)
  205. /* I/O Pin assignment for FCC2. I don't yet know the best way to do this,
  206. * but there is little variation among the choices.
  207. */
  208. #define PB2_TXER ((uint)0x00000001)
  209. #define PB2_RXDV ((uint)0x00000002)
  210. #define PB2_TXEN ((uint)0x00000004)
  211. #define PB2_RXER ((uint)0x00000008)
  212. #define PB2_COL ((uint)0x00000010)
  213. #define PB2_CRS ((uint)0x00000020)
  214. #define PB2_TXDAT ((uint)0x000003c0)
  215. #define PB2_RXDAT ((uint)0x00003c00)
  216. #define PB2_PSORB_BOUT (PB2_RXDAT | PB2_TXDAT | PB2_CRS | PB2_COL | \
  217. PB2_RXER | PB2_RXDV | PB2_TXER)
  218. #define PB2_PSORB_BIN (PB2_TXEN)
  219. #define PB2_DIRB_BOUT (PB2_RXDAT | PB2_CRS | PB2_COL | PB2_RXER | PB2_RXDV)
  220. #define PB2_DIRB_BIN (PB2_TXDAT | PB2_TXEN | PB2_TXER)
  221. /* I/O Pin assignment for FCC3. I don't yet know the best way to do this,
  222. * but there is little variation among the choices.
  223. */
  224. #define PB3_RXDV ((uint)0x00004000)
  225. #define PB3_RXER ((uint)0x00008000)
  226. #define PB3_TXER ((uint)0x00010000)
  227. #define PB3_TXEN ((uint)0x00020000)
  228. #define PB3_COL ((uint)0x00040000)
  229. #define PB3_CRS ((uint)0x00080000)
  230. #ifndef CONFIG_RPX8260
  231. #define PB3_TXDAT ((uint)0x0f000000)
  232. #define PC3_TXDAT ((uint)0x00000000)
  233. #else
  234. #define PB3_TXDAT ((uint)0x0f000000)
  235. #define PC3_TXDAT 0
  236. #endif
  237. #define PB3_RXDAT ((uint)0x00f00000)
  238. #define PB3_PSORB_BOUT (PB3_RXDAT | PB3_TXDAT | PB3_CRS | PB3_COL | \
  239. PB3_RXER | PB3_RXDV | PB3_TXER | PB3_TXEN)
  240. #define PB3_PSORB_BIN (0)
  241. #define PB3_DIRB_BOUT (PB3_RXDAT | PB3_CRS | PB3_COL | PB3_RXER | PB3_RXDV)
  242. #define PB3_DIRB_BIN (PB3_TXDAT | PB3_TXEN | PB3_TXER)
  243. #define PC3_PSORC_BOUT (PC3_TXDAT)
  244. #define PC3_PSORC_BIN (0)
  245. #define PC3_DIRC_BOUT (0)
  246. #define PC3_DIRC_BIN (PC3_TXDAT)
  247. /* MII status/control serial interface.
  248. */
  249. #if defined(CONFIG_RPX8260)
  250. /* The EP8260 doesn't use Port C for MDIO */
  251. #define PC_MDIO ((uint)0x00000000)
  252. #define PC_MDCK ((uint)0x00000000)
  253. #elif defined(CONFIG_TQM8260)
  254. /* TQM8260 has MDIO and MDCK on PC30 and PC31 respectively */
  255. #define PC_MDIO ((uint)0x00000002)
  256. #define PC_MDCK ((uint)0x00000001)
  257. #elif defined(CONFIG_ADS8272)
  258. #define PC_MDIO ((uint)0x00002000)
  259. #define PC_MDCK ((uint)0x00001000)
  260. #elif defined(CONFIG_EST8260) || defined(CONFIG_ADS8260) || defined(CONFIG_PQ2FADS)
  261. #define PC_MDIO ((uint)0x00400000)
  262. #define PC_MDCK ((uint)0x00200000)
  263. #else
  264. #define PC_MDIO ((uint)0x00000004)
  265. #define PC_MDCK ((uint)0x00000020)
  266. #endif
  267. #if defined(CONFIG_USE_MDIO) && (!defined(PC_MDIO) || !defined(PC_MDCK))
  268. #error "Must define PC_MDIO and PC_MDCK if using MDIO"
  269. #endif
  270. /* PHY addresses */
  271. /* default to dynamic config of phy addresses */
  272. #define FCC1_PHY_ADDR 0
  273. #ifdef CONFIG_PQ2FADS
  274. #define FCC2_PHY_ADDR 0
  275. #else
  276. #define FCC2_PHY_ADDR 2
  277. #endif
  278. #define FCC3_PHY_ADDR 3
  279. /* A table of information for supporting FCCs. This does two things.
  280. * First, we know how many FCCs we have and they are always externally
  281. * numbered from zero. Second, it holds control register and I/O
  282. * information that could be different among board designs.
  283. */
  284. typedef struct fcc_info {
  285. uint fc_fccnum;
  286. uint fc_phyaddr;
  287. uint fc_cpmblock;
  288. uint fc_cpmpage;
  289. uint fc_proff;
  290. uint fc_interrupt;
  291. uint fc_trxclocks;
  292. uint fc_clockroute;
  293. uint fc_clockmask;
  294. uint fc_mdio;
  295. uint fc_mdck;
  296. } fcc_info_t;
  297. static fcc_info_t fcc_ports[] = {
  298. #ifdef CONFIG_FCC1_ENET
  299. { 0, FCC1_PHY_ADDR, CPM_CR_FCC1_SBLOCK, CPM_CR_FCC1_PAGE, PROFF_FCC1, SIU_INT_FCC1,
  300. (PC_F1RXCLK | PC_F1TXCLK), CMX1_CLK_ROUTE, CMX1_CLK_MASK,
  301. PC_MDIO, PC_MDCK },
  302. #endif
  303. #ifdef CONFIG_FCC2_ENET
  304. { 1, FCC2_PHY_ADDR, CPM_CR_FCC2_SBLOCK, CPM_CR_FCC2_PAGE, PROFF_FCC2, SIU_INT_FCC2,
  305. (PC_F2RXCLK | PC_F2TXCLK), CMX2_CLK_ROUTE, CMX2_CLK_MASK,
  306. PC_MDIO, PC_MDCK },
  307. #endif
  308. #ifdef CONFIG_FCC3_ENET
  309. { 2, FCC3_PHY_ADDR, CPM_CR_FCC3_SBLOCK, CPM_CR_FCC3_PAGE, PROFF_FCC3, SIU_INT_FCC3,
  310. (PC_F3RXCLK | PC_F3TXCLK), CMX3_CLK_ROUTE, CMX3_CLK_MASK,
  311. PC_MDIO, PC_MDCK },
  312. #endif
  313. };
  314. /* The FCC buffer descriptors track the ring buffers. The rx_bd_base and
  315. * tx_bd_base always point to the base of the buffer descriptors. The
  316. * cur_rx and cur_tx point to the currently available buffer.
  317. * The dirty_tx tracks the current buffer that is being sent by the
  318. * controller. The cur_tx and dirty_tx are equal under both completely
  319. * empty and completely full conditions. The empty/ready indicator in
  320. * the buffer descriptor determines the actual condition.
  321. */
  322. struct fcc_enet_private {
  323. /* The saved address of a sent-in-place packet/buffer, for skfree(). */
  324. struct sk_buff* tx_skbuff[TX_RING_SIZE];
  325. ushort skb_cur;
  326. ushort skb_dirty;
  327. /* CPM dual port RAM relative addresses.
  328. */
  329. cbd_t *rx_bd_base; /* Address of Rx and Tx buffers. */
  330. cbd_t *tx_bd_base;
  331. cbd_t *cur_rx, *cur_tx; /* The next free ring entry */
  332. cbd_t *dirty_tx; /* The ring entries to be free()ed. */
  333. volatile fcc_t *fccp;
  334. volatile fcc_enet_t *ep;
  335. struct net_device_stats stats;
  336. uint tx_free;
  337. spinlock_t lock;
  338. #ifdef CONFIG_USE_MDIO
  339. uint phy_id;
  340. uint phy_id_done;
  341. uint phy_status;
  342. phy_info_t *phy;
  343. struct work_struct phy_relink;
  344. struct work_struct phy_display_config;
  345. struct net_device *dev;
  346. uint sequence_done;
  347. uint phy_addr;
  348. #endif /* CONFIG_USE_MDIO */
  349. int link;
  350. int old_link;
  351. int full_duplex;
  352. fcc_info_t *fip;
  353. };
  354. static void init_fcc_shutdown(fcc_info_t *fip, struct fcc_enet_private *cep,
  355. volatile cpm2_map_t *immap);
  356. static void init_fcc_startup(fcc_info_t *fip, struct net_device *dev);
  357. static void init_fcc_ioports(fcc_info_t *fip, volatile iop_cpm2_t *io,
  358. volatile cpm2_map_t *immap);
  359. static void init_fcc_param(fcc_info_t *fip, struct net_device *dev,
  360. volatile cpm2_map_t *immap);
  361. #ifdef CONFIG_USE_MDIO
  362. static int mii_queue(struct net_device *dev, int request, void (*func)(uint, struct net_device *));
  363. static uint mii_send_receive(fcc_info_t *fip, uint cmd);
  364. static void mii_do_cmd(struct net_device *dev, const phy_cmd_t *c);
  365. /* Make MII read/write commands for the FCC.
  366. */
  367. #define mk_mii_read(REG) (0x60020000 | (((REG) & 0x1f) << 18))
  368. #define mk_mii_write(REG, VAL) (0x50020000 | (((REG) & 0x1f) << 18) | \
  369. ((VAL) & 0xffff))
  370. #define mk_mii_end 0
  371. #endif /* CONFIG_USE_MDIO */
  372. static int
  373. fcc_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
  374. {
  375. struct fcc_enet_private *cep = (struct fcc_enet_private *)dev->priv;
  376. volatile cbd_t *bdp;
  377. /* Fill in a Tx ring entry */
  378. bdp = cep->cur_tx;
  379. #ifndef final_version
  380. if (!cep->tx_free || (bdp->cbd_sc & BD_ENET_TX_READY)) {
  381. /* Ooops. All transmit buffers are full. Bail out.
  382. * This should not happen, since the tx queue should be stopped.
  383. */
  384. printk("%s: tx queue full!.\n", dev->name);
  385. return 1;
  386. }
  387. #endif
  388. /* Clear all of the status flags. */
  389. bdp->cbd_sc &= ~BD_ENET_TX_STATS;
  390. /* If the frame is short, tell CPM to pad it. */
  391. if (skb->len <= ETH_ZLEN)
  392. bdp->cbd_sc |= BD_ENET_TX_PAD;
  393. else
  394. bdp->cbd_sc &= ~BD_ENET_TX_PAD;
  395. /* Set buffer length and buffer pointer. */
  396. bdp->cbd_datlen = skb->len;
  397. bdp->cbd_bufaddr = __pa(skb->data);
  398. spin_lock_irq(&cep->lock);
  399. /* Save skb pointer. */
  400. cep->tx_skbuff[cep->skb_cur] = skb;
  401. cep->stats.tx_bytes += skb->len;
  402. cep->skb_cur = (cep->skb_cur+1) & TX_RING_MOD_MASK;
  403. /* Send it on its way. Tell CPM its ready, interrupt when done,
  404. * its the last BD of the frame, and to put the CRC on the end.
  405. */
  406. bdp->cbd_sc |= (BD_ENET_TX_READY | BD_ENET_TX_INTR | BD_ENET_TX_LAST | BD_ENET_TX_TC);
  407. #if 0
  408. /* Errata says don't do this. */
  409. cep->fccp->fcc_ftodr = 0x8000;
  410. #endif
  411. dev->trans_start = jiffies;
  412. /* If this was the last BD in the ring, start at the beginning again. */
  413. if (bdp->cbd_sc & BD_ENET_TX_WRAP)
  414. bdp = cep->tx_bd_base;
  415. else
  416. bdp++;
  417. if (!--cep->tx_free)
  418. netif_stop_queue(dev);
  419. cep->cur_tx = (cbd_t *)bdp;
  420. spin_unlock_irq(&cep->lock);
  421. return 0;
  422. }
  423. static void
  424. fcc_enet_timeout(struct net_device *dev)
  425. {
  426. struct fcc_enet_private *cep = (struct fcc_enet_private *)dev->priv;
  427. printk("%s: transmit timed out.\n", dev->name);
  428. cep->stats.tx_errors++;
  429. #ifndef final_version
  430. {
  431. int i;
  432. cbd_t *bdp;
  433. printk(" Ring data dump: cur_tx %p tx_free %d cur_rx %p.\n",
  434. cep->cur_tx, cep->tx_free,
  435. cep->cur_rx);
  436. bdp = cep->tx_bd_base;
  437. printk(" Tx @base %p :\n", bdp);
  438. for (i = 0 ; i < TX_RING_SIZE; i++, bdp++)
  439. printk("%04x %04x %08x\n",
  440. bdp->cbd_sc,
  441. bdp->cbd_datlen,
  442. bdp->cbd_bufaddr);
  443. bdp = cep->rx_bd_base;
  444. printk(" Rx @base %p :\n", bdp);
  445. for (i = 0 ; i < RX_RING_SIZE; i++, bdp++)
  446. printk("%04x %04x %08x\n",
  447. bdp->cbd_sc,
  448. bdp->cbd_datlen,
  449. bdp->cbd_bufaddr);
  450. }
  451. #endif
  452. if (cep->tx_free)
  453. netif_wake_queue(dev);
  454. }
  455. /* The interrupt handler. */
  456. static irqreturn_t
  457. fcc_enet_interrupt(int irq, void * dev_id)
  458. {
  459. struct net_device *dev = dev_id;
  460. volatile struct fcc_enet_private *cep;
  461. volatile cbd_t *bdp;
  462. ushort int_events;
  463. int must_restart;
  464. cep = (struct fcc_enet_private *)dev->priv;
  465. /* Get the interrupt events that caused us to be here.
  466. */
  467. int_events = cep->fccp->fcc_fcce;
  468. cep->fccp->fcc_fcce = (int_events & cep->fccp->fcc_fccm);
  469. must_restart = 0;
  470. #ifdef PHY_INTERRUPT
  471. /* We have to be careful here to make sure that we aren't
  472. * interrupted by a PHY interrupt.
  473. */
  474. disable_irq_nosync(PHY_INTERRUPT);
  475. #endif
  476. /* Handle receive event in its own function.
  477. */
  478. if (int_events & FCC_ENET_RXF)
  479. fcc_enet_rx(dev_id);
  480. /* Check for a transmit error. The manual is a little unclear
  481. * about this, so the debug code until I get it figured out. It
  482. * appears that if TXE is set, then TXB is not set. However,
  483. * if carrier sense is lost during frame transmission, the TXE
  484. * bit is set, "and continues the buffer transmission normally."
  485. * I don't know if "normally" implies TXB is set when the buffer
  486. * descriptor is closed.....trial and error :-).
  487. */
  488. /* Transmit OK, or non-fatal error. Update the buffer descriptors.
  489. */
  490. if (int_events & (FCC_ENET_TXE | FCC_ENET_TXB)) {
  491. spin_lock(&cep->lock);
  492. bdp = cep->dirty_tx;
  493. while ((bdp->cbd_sc&BD_ENET_TX_READY)==0) {
  494. if (cep->tx_free == TX_RING_SIZE)
  495. break;
  496. if (bdp->cbd_sc & BD_ENET_TX_HB) /* No heartbeat */
  497. cep->stats.tx_heartbeat_errors++;
  498. if (bdp->cbd_sc & BD_ENET_TX_LC) /* Late collision */
  499. cep->stats.tx_window_errors++;
  500. if (bdp->cbd_sc & BD_ENET_TX_RL) /* Retrans limit */
  501. cep->stats.tx_aborted_errors++;
  502. if (bdp->cbd_sc & BD_ENET_TX_UN) /* Underrun */
  503. cep->stats.tx_fifo_errors++;
  504. if (bdp->cbd_sc & BD_ENET_TX_CSL) /* Carrier lost */
  505. cep->stats.tx_carrier_errors++;
  506. /* No heartbeat or Lost carrier are not really bad errors.
  507. * The others require a restart transmit command.
  508. */
  509. if (bdp->cbd_sc &
  510. (BD_ENET_TX_LC | BD_ENET_TX_RL | BD_ENET_TX_UN)) {
  511. must_restart = 1;
  512. cep->stats.tx_errors++;
  513. }
  514. cep->stats.tx_packets++;
  515. /* Deferred means some collisions occurred during transmit,
  516. * but we eventually sent the packet OK.
  517. */
  518. if (bdp->cbd_sc & BD_ENET_TX_DEF)
  519. cep->stats.collisions++;
  520. /* Free the sk buffer associated with this last transmit. */
  521. dev_kfree_skb_irq(cep->tx_skbuff[cep->skb_dirty]);
  522. cep->tx_skbuff[cep->skb_dirty] = NULL;
  523. cep->skb_dirty = (cep->skb_dirty + 1) & TX_RING_MOD_MASK;
  524. /* Update pointer to next buffer descriptor to be transmitted. */
  525. if (bdp->cbd_sc & BD_ENET_TX_WRAP)
  526. bdp = cep->tx_bd_base;
  527. else
  528. bdp++;
  529. /* I don't know if we can be held off from processing these
  530. * interrupts for more than one frame time. I really hope
  531. * not. In such a case, we would now want to check the
  532. * currently available BD (cur_tx) and determine if any
  533. * buffers between the dirty_tx and cur_tx have also been
  534. * sent. We would want to process anything in between that
  535. * does not have BD_ENET_TX_READY set.
  536. */
  537. /* Since we have freed up a buffer, the ring is no longer
  538. * full.
  539. */
  540. if (!cep->tx_free++) {
  541. if (netif_queue_stopped(dev)) {
  542. netif_wake_queue(dev);
  543. }
  544. }
  545. cep->dirty_tx = (cbd_t *)bdp;
  546. }
  547. if (must_restart) {
  548. volatile cpm_cpm2_t *cp;
  549. /* Some transmit errors cause the transmitter to shut
  550. * down. We now issue a restart transmit. Since the
  551. * errors close the BD and update the pointers, the restart
  552. * _should_ pick up without having to reset any of our
  553. * pointers either. Also, To workaround 8260 device erratum
  554. * CPM37, we must disable and then re-enable the transmitter
  555. * following a Late Collision, Underrun, or Retry Limit error.
  556. */
  557. cep->fccp->fcc_gfmr &= ~FCC_GFMR_ENT;
  558. udelay(10); /* wait a few microseconds just on principle */
  559. cep->fccp->fcc_gfmr |= FCC_GFMR_ENT;
  560. cp = cpmp;
  561. cp->cp_cpcr =
  562. mk_cr_cmd(cep->fip->fc_cpmpage, cep->fip->fc_cpmblock,
  563. 0x0c, CPM_CR_RESTART_TX) | CPM_CR_FLG;
  564. while (cp->cp_cpcr & CPM_CR_FLG);
  565. }
  566. spin_unlock(&cep->lock);
  567. }
  568. /* Check for receive busy, i.e. packets coming but no place to
  569. * put them.
  570. */
  571. if (int_events & FCC_ENET_BSY) {
  572. cep->fccp->fcc_fcce = FCC_ENET_BSY;
  573. cep->stats.rx_dropped++;
  574. }
  575. #ifdef PHY_INTERRUPT
  576. enable_irq(PHY_INTERRUPT);
  577. #endif
  578. return IRQ_HANDLED;
  579. }
  580. /* During a receive, the cur_rx points to the current incoming buffer.
  581. * When we update through the ring, if the next incoming buffer has
  582. * not been given to the system, we just set the empty indicator,
  583. * effectively tossing the packet.
  584. */
  585. static int
  586. fcc_enet_rx(struct net_device *dev)
  587. {
  588. struct fcc_enet_private *cep;
  589. volatile cbd_t *bdp;
  590. struct sk_buff *skb;
  591. ushort pkt_len;
  592. cep = (struct fcc_enet_private *)dev->priv;
  593. /* First, grab all of the stats for the incoming packet.
  594. * These get messed up if we get called due to a busy condition.
  595. */
  596. bdp = cep->cur_rx;
  597. for (;;) {
  598. if (bdp->cbd_sc & BD_ENET_RX_EMPTY)
  599. break;
  600. #ifndef final_version
  601. /* Since we have allocated space to hold a complete frame, both
  602. * the first and last indicators should be set.
  603. */
  604. if ((bdp->cbd_sc & (BD_ENET_RX_FIRST | BD_ENET_RX_LAST)) !=
  605. (BD_ENET_RX_FIRST | BD_ENET_RX_LAST))
  606. printk("CPM ENET: rcv is not first+last\n");
  607. #endif
  608. /* Frame too long or too short. */
  609. if (bdp->cbd_sc & (BD_ENET_RX_LG | BD_ENET_RX_SH))
  610. cep->stats.rx_length_errors++;
  611. if (bdp->cbd_sc & BD_ENET_RX_NO) /* Frame alignment */
  612. cep->stats.rx_frame_errors++;
  613. if (bdp->cbd_sc & BD_ENET_RX_CR) /* CRC Error */
  614. cep->stats.rx_crc_errors++;
  615. if (bdp->cbd_sc & BD_ENET_RX_OV) /* FIFO overrun */
  616. cep->stats.rx_crc_errors++;
  617. if (bdp->cbd_sc & BD_ENET_RX_CL) /* Late Collision */
  618. cep->stats.rx_frame_errors++;
  619. if (!(bdp->cbd_sc &
  620. (BD_ENET_RX_LG | BD_ENET_RX_SH | BD_ENET_RX_NO | BD_ENET_RX_CR
  621. | BD_ENET_RX_OV | BD_ENET_RX_CL)))
  622. {
  623. /* Process the incoming frame. */
  624. cep->stats.rx_packets++;
  625. /* Remove the FCS from the packet length. */
  626. pkt_len = bdp->cbd_datlen - 4;
  627. cep->stats.rx_bytes += pkt_len;
  628. /* This does 16 byte alignment, much more than we need. */
  629. skb = dev_alloc_skb(pkt_len);
  630. if (skb == NULL) {
  631. printk("%s: Memory squeeze, dropping packet.\n", dev->name);
  632. cep->stats.rx_dropped++;
  633. }
  634. else {
  635. skb_put(skb,pkt_len); /* Make room */
  636. eth_copy_and_sum(skb,
  637. (unsigned char *)__va(bdp->cbd_bufaddr),
  638. pkt_len, 0);
  639. skb->protocol=eth_type_trans(skb,dev);
  640. netif_rx(skb);
  641. }
  642. }
  643. /* Clear the status flags for this buffer. */
  644. bdp->cbd_sc &= ~BD_ENET_RX_STATS;
  645. /* Mark the buffer empty. */
  646. bdp->cbd_sc |= BD_ENET_RX_EMPTY;
  647. /* Update BD pointer to next entry. */
  648. if (bdp->cbd_sc & BD_ENET_RX_WRAP)
  649. bdp = cep->rx_bd_base;
  650. else
  651. bdp++;
  652. }
  653. cep->cur_rx = (cbd_t *)bdp;
  654. return 0;
  655. }
  656. static int
  657. fcc_enet_close(struct net_device *dev)
  658. {
  659. #ifdef CONFIG_USE_MDIO
  660. struct fcc_enet_private *fep = dev->priv;
  661. #endif
  662. netif_stop_queue(dev);
  663. fcc_stop(dev);
  664. #ifdef CONFIG_USE_MDIO
  665. if (fep->phy)
  666. mii_do_cmd(dev, fep->phy->shutdown);
  667. #endif
  668. return 0;
  669. }
  670. static struct net_device_stats *fcc_enet_get_stats(struct net_device *dev)
  671. {
  672. struct fcc_enet_private *cep = (struct fcc_enet_private *)dev->priv;
  673. return &cep->stats;
  674. }
  675. #ifdef CONFIG_USE_MDIO
  676. /* NOTE: Most of the following comes from the FEC driver for 860. The
  677. * overall structure of MII code has been retained (as it's proved stable
  678. * and well-tested), but actual transfer requests are processed "at once"
  679. * instead of being queued (there's no interrupt-driven MII transfer
  680. * mechanism, one has to toggle the data/clock bits manually).
  681. */
  682. static int
  683. mii_queue(struct net_device *dev, int regval, void (*func)(uint, struct net_device *))
  684. {
  685. struct fcc_enet_private *fep;
  686. int retval, tmp;
  687. /* Add PHY address to register command. */
  688. fep = dev->priv;
  689. regval |= fep->phy_addr << 23;
  690. retval = 0;
  691. tmp = mii_send_receive(fep->fip, regval);
  692. if (func)
  693. func(tmp, dev);
  694. return retval;
  695. }
  696. static void mii_do_cmd(struct net_device *dev, const phy_cmd_t *c)
  697. {
  698. int k;
  699. if(!c)
  700. return;
  701. for(k = 0; (c+k)->mii_data != mk_mii_end; k++)
  702. mii_queue(dev, (c+k)->mii_data, (c+k)->funct);
  703. }
  704. static void mii_parse_sr(uint mii_reg, struct net_device *dev)
  705. {
  706. volatile struct fcc_enet_private *fep = dev->priv;
  707. uint s = fep->phy_status;
  708. s &= ~(PHY_STAT_LINK | PHY_STAT_FAULT | PHY_STAT_ANC);
  709. if (mii_reg & BMSR_LSTATUS)
  710. s |= PHY_STAT_LINK;
  711. if (mii_reg & BMSR_RFAULT)
  712. s |= PHY_STAT_FAULT;
  713. if (mii_reg & BMSR_ANEGCOMPLETE)
  714. s |= PHY_STAT_ANC;
  715. fep->phy_status = s;
  716. }
  717. static void mii_parse_cr(uint mii_reg, struct net_device *dev)
  718. {
  719. volatile struct fcc_enet_private *fep = dev->priv;
  720. uint s = fep->phy_status;
  721. s &= ~(PHY_CONF_ANE | PHY_CONF_LOOP);
  722. if (mii_reg & BMCR_ANENABLE)
  723. s |= PHY_CONF_ANE;
  724. if (mii_reg & BMCR_LOOPBACK)
  725. s |= PHY_CONF_LOOP;
  726. fep->phy_status = s;
  727. }
  728. static void mii_parse_anar(uint mii_reg, struct net_device *dev)
  729. {
  730. volatile struct fcc_enet_private *fep = dev->priv;
  731. uint s = fep->phy_status;
  732. s &= ~(PHY_CONF_SPMASK);
  733. if (mii_reg & ADVERTISE_10HALF)
  734. s |= PHY_CONF_10HDX;
  735. if (mii_reg & ADVERTISE_10FULL)
  736. s |= PHY_CONF_10FDX;
  737. if (mii_reg & ADVERTISE_100HALF)
  738. s |= PHY_CONF_100HDX;
  739. if (mii_reg & ADVERTISE_100FULL)
  740. s |= PHY_CONF_100FDX;
  741. fep->phy_status = s;
  742. }
  743. /* ------------------------------------------------------------------------- */
  744. /* Generic PHY support. Should work for all PHYs, but does not support link
  745. * change interrupts.
  746. */
  747. #ifdef CONFIG_FCC_GENERIC_PHY
  748. static phy_info_t phy_info_generic = {
  749. 0x00000000, /* 0-->match any PHY */
  750. "GENERIC",
  751. (const phy_cmd_t []) { /* config */
  752. /* advertise only half-duplex capabilities */
  753. { mk_mii_write(MII_ADVERTISE, MII_ADVERTISE_HALF),
  754. mii_parse_anar },
  755. /* enable auto-negotiation */
  756. { mk_mii_write(MII_BMCR, BMCR_ANENABLE), mii_parse_cr },
  757. { mk_mii_end, }
  758. },
  759. (const phy_cmd_t []) { /* startup */
  760. /* restart auto-negotiation */
  761. { mk_mii_write(MII_BMCR, BMCR_ANENABLE | BMCR_ANRESTART),
  762. NULL },
  763. { mk_mii_end, }
  764. },
  765. (const phy_cmd_t []) { /* ack_int */
  766. /* We don't actually use the ack_int table with a generic
  767. * PHY, but putting a reference to mii_parse_sr here keeps
  768. * us from getting a compiler warning about unused static
  769. * functions in the case where we only compile in generic
  770. * PHY support.
  771. */
  772. { mk_mii_read(MII_BMSR), mii_parse_sr },
  773. { mk_mii_end, }
  774. },
  775. (const phy_cmd_t []) { /* shutdown */
  776. { mk_mii_end, }
  777. },
  778. };
  779. #endif /* ifdef CONFIG_FCC_GENERIC_PHY */
  780. /* ------------------------------------------------------------------------- */
  781. /* The Level one LXT970 is used by many boards */
  782. #ifdef CONFIG_FCC_LXT970
  783. #define MII_LXT970_MIRROR 16 /* Mirror register */
  784. #define MII_LXT970_IER 17 /* Interrupt Enable Register */
  785. #define MII_LXT970_ISR 18 /* Interrupt Status Register */
  786. #define MII_LXT970_CONFIG 19 /* Configuration Register */
  787. #define MII_LXT970_CSR 20 /* Chip Status Register */
  788. static void mii_parse_lxt970_csr(uint mii_reg, struct net_device *dev)
  789. {
  790. volatile struct fcc_enet_private *fep = dev->priv;
  791. uint s = fep->phy_status;
  792. s &= ~(PHY_STAT_SPMASK);
  793. if (mii_reg & 0x0800) {
  794. if (mii_reg & 0x1000)
  795. s |= PHY_STAT_100FDX;
  796. else
  797. s |= PHY_STAT_100HDX;
  798. } else {
  799. if (mii_reg & 0x1000)
  800. s |= PHY_STAT_10FDX;
  801. else
  802. s |= PHY_STAT_10HDX;
  803. }
  804. fep->phy_status = s;
  805. }
  806. static phy_info_t phy_info_lxt970 = {
  807. 0x07810000,
  808. "LXT970",
  809. (const phy_cmd_t []) { /* config */
  810. #if 0
  811. // { mk_mii_write(MII_ADVERTISE, 0x0021), NULL },
  812. /* Set default operation of 100-TX....for some reason
  813. * some of these bits are set on power up, which is wrong.
  814. */
  815. { mk_mii_write(MII_LXT970_CONFIG, 0), NULL },
  816. #endif
  817. { mk_mii_read(MII_BMCR), mii_parse_cr },
  818. { mk_mii_read(MII_ADVERTISE), mii_parse_anar },
  819. { mk_mii_end, }
  820. },
  821. (const phy_cmd_t []) { /* startup - enable interrupts */
  822. { mk_mii_write(MII_LXT970_IER, 0x0002), NULL },
  823. { mk_mii_write(MII_BMCR, 0x1200), NULL }, /* autonegotiate */
  824. { mk_mii_end, }
  825. },
  826. (const phy_cmd_t []) { /* ack_int */
  827. /* read SR and ISR to acknowledge */
  828. { mk_mii_read(MII_BMSR), mii_parse_sr },
  829. { mk_mii_read(MII_LXT970_ISR), NULL },
  830. /* find out the current status */
  831. { mk_mii_read(MII_LXT970_CSR), mii_parse_lxt970_csr },
  832. { mk_mii_end, }
  833. },
  834. (const phy_cmd_t []) { /* shutdown - disable interrupts */
  835. { mk_mii_write(MII_LXT970_IER, 0x0000), NULL },
  836. { mk_mii_end, }
  837. },
  838. };
  839. #endif /* CONFIG_FEC_LXT970 */
  840. /* ------------------------------------------------------------------------- */
  841. /* The Level one LXT971 is used on some of my custom boards */
  842. #ifdef CONFIG_FCC_LXT971
  843. /* register definitions for the 971 */
  844. #define MII_LXT971_PCR 16 /* Port Control Register */
  845. #define MII_LXT971_SR2 17 /* Status Register 2 */
  846. #define MII_LXT971_IER 18 /* Interrupt Enable Register */
  847. #define MII_LXT971_ISR 19 /* Interrupt Status Register */
  848. #define MII_LXT971_LCR 20 /* LED Control Register */
  849. #define MII_LXT971_TCR 30 /* Transmit Control Register */
  850. /*
  851. * I had some nice ideas of running the MDIO faster...
  852. * The 971 should support 8MHz and I tried it, but things acted really
  853. * weird, so 2.5 MHz ought to be enough for anyone...
  854. */
  855. static void mii_parse_lxt971_sr2(uint mii_reg, struct net_device *dev)
  856. {
  857. volatile struct fcc_enet_private *fep = dev->priv;
  858. uint s = fep->phy_status;
  859. s &= ~(PHY_STAT_SPMASK);
  860. if (mii_reg & 0x4000) {
  861. if (mii_reg & 0x0200)
  862. s |= PHY_STAT_100FDX;
  863. else
  864. s |= PHY_STAT_100HDX;
  865. } else {
  866. if (mii_reg & 0x0200)
  867. s |= PHY_STAT_10FDX;
  868. else
  869. s |= PHY_STAT_10HDX;
  870. }
  871. if (mii_reg & 0x0008)
  872. s |= PHY_STAT_FAULT;
  873. fep->phy_status = s;
  874. }
  875. static phy_info_t phy_info_lxt971 = {
  876. 0x0001378e,
  877. "LXT971",
  878. (const phy_cmd_t []) { /* config */
  879. /* configure link capabilities to advertise */
  880. { mk_mii_write(MII_ADVERTISE, MII_ADVERTISE_DEFAULT),
  881. mii_parse_anar },
  882. /* enable auto-negotiation */
  883. { mk_mii_write(MII_BMCR, BMCR_ANENABLE), mii_parse_cr },
  884. { mk_mii_end, }
  885. },
  886. (const phy_cmd_t []) { /* startup - enable interrupts */
  887. { mk_mii_write(MII_LXT971_IER, 0x00f2), NULL },
  888. /* restart auto-negotiation */
  889. { mk_mii_write(MII_BMCR, BMCR_ANENABLE | BMCR_ANRESTART),
  890. NULL },
  891. { mk_mii_end, }
  892. },
  893. (const phy_cmd_t []) { /* ack_int */
  894. /* find out the current status */
  895. { mk_mii_read(MII_BMSR), NULL },
  896. { mk_mii_read(MII_BMSR), mii_parse_sr },
  897. { mk_mii_read(MII_LXT971_SR2), mii_parse_lxt971_sr2 },
  898. /* we only need to read ISR to acknowledge */
  899. { mk_mii_read(MII_LXT971_ISR), NULL },
  900. { mk_mii_end, }
  901. },
  902. (const phy_cmd_t []) { /* shutdown - disable interrupts */
  903. { mk_mii_write(MII_LXT971_IER, 0x0000), NULL },
  904. { mk_mii_end, }
  905. },
  906. };
  907. #endif /* CONFIG_FCC_LXT971 */
  908. /* ------------------------------------------------------------------------- */
  909. /* The Quality Semiconductor QS6612 is used on the RPX CLLF */
  910. #ifdef CONFIG_FCC_QS6612
  911. /* register definitions */
  912. #define MII_QS6612_MCR 17 /* Mode Control Register */
  913. #define MII_QS6612_FTR 27 /* Factory Test Register */
  914. #define MII_QS6612_MCO 28 /* Misc. Control Register */
  915. #define MII_QS6612_ISR 29 /* Interrupt Source Register */
  916. #define MII_QS6612_IMR 30 /* Interrupt Mask Register */
  917. #define MII_QS6612_PCR 31 /* 100BaseTx PHY Control Reg. */
  918. static void mii_parse_qs6612_pcr(uint mii_reg, struct net_device *dev)
  919. {
  920. volatile struct fcc_enet_private *fep = dev->priv;
  921. uint s = fep->phy_status;
  922. s &= ~(PHY_STAT_SPMASK);
  923. switch((mii_reg >> 2) & 7) {
  924. case 1: s |= PHY_STAT_10HDX; break;
  925. case 2: s |= PHY_STAT_100HDX; break;
  926. case 5: s |= PHY_STAT_10FDX; break;
  927. case 6: s |= PHY_STAT_100FDX; break;
  928. }
  929. fep->phy_status = s;
  930. }
  931. static phy_info_t phy_info_qs6612 = {
  932. 0x00181440,
  933. "QS6612",
  934. (const phy_cmd_t []) { /* config */
  935. // { mk_mii_write(MII_ADVERTISE, 0x061), NULL }, /* 10 Mbps */
  936. /* The PHY powers up isolated on the RPX,
  937. * so send a command to allow operation.
  938. */
  939. { mk_mii_write(MII_QS6612_PCR, 0x0dc0), NULL },
  940. /* parse cr and anar to get some info */
  941. { mk_mii_read(MII_BMCR), mii_parse_cr },
  942. { mk_mii_read(MII_ADVERTISE), mii_parse_anar },
  943. { mk_mii_end, }
  944. },
  945. (const phy_cmd_t []) { /* startup - enable interrupts */
  946. { mk_mii_write(MII_QS6612_IMR, 0x003a), NULL },
  947. { mk_mii_write(MII_BMCR, 0x1200), NULL }, /* autonegotiate */
  948. { mk_mii_end, }
  949. },
  950. (const phy_cmd_t []) { /* ack_int */
  951. /* we need to read ISR, SR and ANER to acknowledge */
  952. { mk_mii_read(MII_QS6612_ISR), NULL },
  953. { mk_mii_read(MII_BMSR), mii_parse_sr },
  954. { mk_mii_read(MII_EXPANSION), NULL },
  955. /* read pcr to get info */
  956. { mk_mii_read(MII_QS6612_PCR), mii_parse_qs6612_pcr },
  957. { mk_mii_end, }
  958. },
  959. (const phy_cmd_t []) { /* shutdown - disable interrupts */
  960. { mk_mii_write(MII_QS6612_IMR, 0x0000), NULL },
  961. { mk_mii_end, }
  962. },
  963. };
  964. #endif /* CONFIG_FEC_QS6612 */
  965. /* ------------------------------------------------------------------------- */
  966. /* The Davicom DM9131 is used on the HYMOD board */
  967. #ifdef CONFIG_FCC_DM9131
  968. /* register definitions */
  969. #define MII_DM9131_ACR 16 /* Aux. Config Register */
  970. #define MII_DM9131_ACSR 17 /* Aux. Config/Status Register */
  971. #define MII_DM9131_10TCSR 18 /* 10BaseT Config/Status Reg. */
  972. #define MII_DM9131_INTR 21 /* Interrupt Register */
  973. #define MII_DM9131_RECR 22 /* Receive Error Counter Reg. */
  974. #define MII_DM9131_DISCR 23 /* Disconnect Counter Register */
  975. static void mii_parse_dm9131_acsr(uint mii_reg, struct net_device *dev)
  976. {
  977. volatile struct fcc_enet_private *fep = dev->priv;
  978. uint s = fep->phy_status;
  979. s &= ~(PHY_STAT_SPMASK);
  980. switch ((mii_reg >> 12) & 0xf) {
  981. case 1: s |= PHY_STAT_10HDX; break;
  982. case 2: s |= PHY_STAT_10FDX; break;
  983. case 4: s |= PHY_STAT_100HDX; break;
  984. case 8: s |= PHY_STAT_100FDX; break;
  985. }
  986. fep->phy_status = s;
  987. }
  988. static phy_info_t phy_info_dm9131 = {
  989. 0x00181b80,
  990. "DM9131",
  991. (const phy_cmd_t []) { /* config */
  992. /* parse cr and anar to get some info */
  993. { mk_mii_read(MII_BMCR), mii_parse_cr },
  994. { mk_mii_read(MII_ADVERTISE), mii_parse_anar },
  995. { mk_mii_end, }
  996. },
  997. (const phy_cmd_t []) { /* startup - enable interrupts */
  998. { mk_mii_write(MII_DM9131_INTR, 0x0002), NULL },
  999. { mk_mii_write(MII_BMCR, 0x1200), NULL }, /* autonegotiate */
  1000. { mk_mii_end, }
  1001. },
  1002. (const phy_cmd_t []) { /* ack_int */
  1003. /* we need to read INTR, SR and ANER to acknowledge */
  1004. { mk_mii_read(MII_DM9131_INTR), NULL },
  1005. { mk_mii_read(MII_BMSR), mii_parse_sr },
  1006. { mk_mii_read(MII_EXPANSION), NULL },
  1007. /* read acsr to get info */
  1008. { mk_mii_read(MII_DM9131_ACSR), mii_parse_dm9131_acsr },
  1009. { mk_mii_end, }
  1010. },
  1011. (const phy_cmd_t []) { /* shutdown - disable interrupts */
  1012. { mk_mii_write(MII_DM9131_INTR, 0x0f00), NULL },
  1013. { mk_mii_end, }
  1014. },
  1015. };
  1016. #endif /* CONFIG_FEC_DM9131 */
  1017. #ifdef CONFIG_FCC_DM9161
  1018. /* ------------------------------------------------------------------------- */
  1019. /* DM9161 Control register values */
  1020. #define MIIM_DM9161_CR_STOP 0x0400
  1021. #define MIIM_DM9161_CR_RSTAN 0x1200
  1022. #define MIIM_DM9161_SCR 0x10
  1023. #define MIIM_DM9161_SCR_INIT 0x0610
  1024. /* DM9161 Specified Configuration and Status Register */
  1025. #define MIIM_DM9161_SCSR 0x11
  1026. #define MIIM_DM9161_SCSR_100F 0x8000
  1027. #define MIIM_DM9161_SCSR_100H 0x4000
  1028. #define MIIM_DM9161_SCSR_10F 0x2000
  1029. #define MIIM_DM9161_SCSR_10H 0x1000
  1030. /* DM9161 10BT register */
  1031. #define MIIM_DM9161_10BTCSR 0x12
  1032. #define MIIM_DM9161_10BTCSR_INIT 0x7800
  1033. /* DM9161 Interrupt Register */
  1034. #define MIIM_DM9161_INTR 0x15
  1035. #define MIIM_DM9161_INTR_PEND 0x8000
  1036. #define MIIM_DM9161_INTR_DPLX_MASK 0x0800
  1037. #define MIIM_DM9161_INTR_SPD_MASK 0x0400
  1038. #define MIIM_DM9161_INTR_LINK_MASK 0x0200
  1039. #define MIIM_DM9161_INTR_MASK 0x0100
  1040. #define MIIM_DM9161_INTR_DPLX_CHANGE 0x0010
  1041. #define MIIM_DM9161_INTR_SPD_CHANGE 0x0008
  1042. #define MIIM_DM9161_INTR_LINK_CHANGE 0x0004
  1043. #define MIIM_DM9161_INTR_INIT 0x0000
  1044. #define MIIM_DM9161_INTR_STOP \
  1045. (MIIM_DM9161_INTR_DPLX_MASK | MIIM_DM9161_INTR_SPD_MASK \
  1046. | MIIM_DM9161_INTR_LINK_MASK | MIIM_DM9161_INTR_MASK)
  1047. static void mii_parse_dm9161_sr(uint mii_reg, struct net_device * dev)
  1048. {
  1049. volatile struct fcc_enet_private *fep = dev->priv;
  1050. uint regstat, timeout=0xffff;
  1051. while(!(mii_reg & 0x0020) && timeout--)
  1052. {
  1053. regstat=mk_mii_read(MII_BMSR);
  1054. regstat |= fep->phy_addr <<23;
  1055. mii_reg = mii_send_receive(fep->fip,regstat);
  1056. }
  1057. mii_parse_sr(mii_reg, dev);
  1058. }
  1059. static void mii_parse_dm9161_scsr(uint mii_reg, struct net_device * dev)
  1060. {
  1061. volatile struct fcc_enet_private *fep = dev->priv;
  1062. uint s = fep->phy_status;
  1063. s &= ~(PHY_STAT_SPMASK);
  1064. switch((mii_reg >>12) & 0xf) {
  1065. case 1:
  1066. {
  1067. s |= PHY_STAT_10HDX;
  1068. printk("10BaseT Half Duplex\n");
  1069. break;
  1070. }
  1071. case 2:
  1072. {
  1073. s |= PHY_STAT_10FDX;
  1074. printk("10BaseT Full Duplex\n");
  1075. break;
  1076. }
  1077. case 4:
  1078. {
  1079. s |= PHY_STAT_100HDX;
  1080. printk("100BaseT Half Duplex\n");
  1081. break;
  1082. }
  1083. case 8:
  1084. {
  1085. s |= PHY_STAT_100FDX;
  1086. printk("100BaseT Full Duplex\n");
  1087. break;
  1088. }
  1089. }
  1090. fep->phy_status = s;
  1091. }
  1092. static void mii_dm9161_wait(uint mii_reg, struct net_device *dev)
  1093. {
  1094. int timeout = HZ;
  1095. /* Davicom takes a bit to come up after a reset,
  1096. * so wait here for a bit */
  1097. schedule_timeout_uninterruptible(timeout);
  1098. }
  1099. static phy_info_t phy_info_dm9161 = {
  1100. 0x00181b88,
  1101. "Davicom DM9161E",
  1102. (const phy_cmd_t[]) { /* config */
  1103. { mk_mii_write(MII_BMCR, MIIM_DM9161_CR_STOP), NULL},
  1104. /* Do not bypass the scrambler/descrambler */
  1105. { mk_mii_write(MIIM_DM9161_SCR, MIIM_DM9161_SCR_INIT), NULL},
  1106. /* Configure 10BTCSR register */
  1107. { mk_mii_write(MIIM_DM9161_10BTCSR, MIIM_DM9161_10BTCSR_INIT),NULL},
  1108. /* Configure some basic stuff */
  1109. { mk_mii_write(MII_BMCR, 0x1000), NULL},
  1110. { mk_mii_read(MII_BMCR), mii_parse_cr },
  1111. { mk_mii_read(MII_ADVERTISE), mii_parse_anar },
  1112. { mk_mii_end,}
  1113. },
  1114. (const phy_cmd_t[]) { /* startup */
  1115. /* Restart Auto Negotiation */
  1116. { mk_mii_write(MII_BMCR, MIIM_DM9161_CR_RSTAN), NULL},
  1117. /* Status is read once to clear old link state */
  1118. { mk_mii_read(MII_BMSR), mii_dm9161_wait},
  1119. /* Auto-negotiate */
  1120. { mk_mii_read(MII_BMSR), mii_parse_dm9161_sr},
  1121. /* Read the status */
  1122. { mk_mii_read(MIIM_DM9161_SCSR), mii_parse_dm9161_scsr},
  1123. /* Clear any pending interrupts */
  1124. { mk_mii_read(MIIM_DM9161_INTR), NULL},
  1125. /* Enable Interrupts */
  1126. { mk_mii_write(MIIM_DM9161_INTR, MIIM_DM9161_INTR_INIT), NULL},
  1127. { mk_mii_end,}
  1128. },
  1129. (const phy_cmd_t[]) { /* ack_int */
  1130. { mk_mii_read(MIIM_DM9161_INTR), NULL},
  1131. #if 0
  1132. { mk_mii_read(MII_BMSR), NULL},
  1133. { mk_mii_read(MII_BMSR), mii_parse_dm9161_sr},
  1134. { mk_mii_read(MIIM_DM9161_SCSR), mii_parse_dm9161_scsr},
  1135. #endif
  1136. { mk_mii_end,}
  1137. },
  1138. (const phy_cmd_t[]) { /* shutdown */
  1139. { mk_mii_read(MIIM_DM9161_INTR),NULL},
  1140. { mk_mii_write(MIIM_DM9161_INTR, MIIM_DM9161_INTR_STOP), NULL},
  1141. { mk_mii_end,}
  1142. },
  1143. };
  1144. #endif /* CONFIG_FCC_DM9161 */
  1145. static phy_info_t *phy_info[] = {
  1146. #ifdef CONFIG_FCC_LXT970
  1147. &phy_info_lxt970,
  1148. #endif /* CONFIG_FEC_LXT970 */
  1149. #ifdef CONFIG_FCC_LXT971
  1150. &phy_info_lxt971,
  1151. #endif /* CONFIG_FEC_LXT971 */
  1152. #ifdef CONFIG_FCC_QS6612
  1153. &phy_info_qs6612,
  1154. #endif /* CONFIG_FEC_QS6612 */
  1155. #ifdef CONFIG_FCC_DM9131
  1156. &phy_info_dm9131,
  1157. #endif /* CONFIG_FEC_DM9131 */
  1158. #ifdef CONFIG_FCC_DM9161
  1159. &phy_info_dm9161,
  1160. #endif /* CONFIG_FCC_DM9161 */
  1161. #ifdef CONFIG_FCC_GENERIC_PHY
  1162. /* Generic PHY support. This must be the last PHY in the table.
  1163. * It will be used to support any PHY that doesn't match a previous
  1164. * entry in the table.
  1165. */
  1166. &phy_info_generic,
  1167. #endif /* CONFIG_FCC_GENERIC_PHY */
  1168. NULL
  1169. };
  1170. static void mii_display_status(struct work_struct *work)
  1171. {
  1172. volatile struct fcc_enet_private *fep =
  1173. container_of(work, struct fcc_enet_private, phy_relink);
  1174. struct net_device *dev = fep->dev;
  1175. uint s = fep->phy_status;
  1176. if (!fep->link && !fep->old_link) {
  1177. /* Link is still down - don't print anything */
  1178. return;
  1179. }
  1180. printk("%s: status: ", dev->name);
  1181. if (!fep->link) {
  1182. printk("link down");
  1183. } else {
  1184. printk("link up");
  1185. switch(s & PHY_STAT_SPMASK) {
  1186. case PHY_STAT_100FDX: printk(", 100 Mbps Full Duplex"); break;
  1187. case PHY_STAT_100HDX: printk(", 100 Mbps Half Duplex"); break;
  1188. case PHY_STAT_10FDX: printk(", 10 Mbps Full Duplex"); break;
  1189. case PHY_STAT_10HDX: printk(", 10 Mbps Half Duplex"); break;
  1190. default:
  1191. printk(", Unknown speed/duplex");
  1192. }
  1193. if (s & PHY_STAT_ANC)
  1194. printk(", auto-negotiation complete");
  1195. }
  1196. if (s & PHY_STAT_FAULT)
  1197. printk(", remote fault");
  1198. printk(".\n");
  1199. }
  1200. static void mii_display_config(struct work_struct *work)
  1201. {
  1202. volatile struct fcc_enet_private *fep =
  1203. container_of(work, struct fcc_enet_private,
  1204. phy_display_config);
  1205. struct net_device *dev = fep->dev;
  1206. uint s = fep->phy_status;
  1207. printk("%s: config: auto-negotiation ", dev->name);
  1208. if (s & PHY_CONF_ANE)
  1209. printk("on");
  1210. else
  1211. printk("off");
  1212. if (s & PHY_CONF_100FDX)
  1213. printk(", 100FDX");
  1214. if (s & PHY_CONF_100HDX)
  1215. printk(", 100HDX");
  1216. if (s & PHY_CONF_10FDX)
  1217. printk(", 10FDX");
  1218. if (s & PHY_CONF_10HDX)
  1219. printk(", 10HDX");
  1220. if (!(s & PHY_CONF_SPMASK))
  1221. printk(", No speed/duplex selected?");
  1222. if (s & PHY_CONF_LOOP)
  1223. printk(", loopback enabled");
  1224. printk(".\n");
  1225. fep->sequence_done = 1;
  1226. }
  1227. static void mii_relink(struct net_device *dev)
  1228. {
  1229. struct fcc_enet_private *fep = dev->priv;
  1230. int duplex = 0;
  1231. fep->old_link = fep->link;
  1232. fep->link = (fep->phy_status & PHY_STAT_LINK) ? 1 : 0;
  1233. #ifdef MDIO_DEBUG
  1234. printk(" mii_relink: link=%d\n", fep->link);
  1235. #endif
  1236. if (fep->link) {
  1237. if (fep->phy_status
  1238. & (PHY_STAT_100FDX | PHY_STAT_10FDX))
  1239. duplex = 1;
  1240. fcc_restart(dev, duplex);
  1241. #ifdef MDIO_DEBUG
  1242. printk(" mii_relink: duplex=%d\n", duplex);
  1243. #endif
  1244. }
  1245. }
  1246. static void mii_queue_relink(uint mii_reg, struct net_device *dev)
  1247. {
  1248. struct fcc_enet_private *fep = dev->priv;
  1249. mii_relink(dev);
  1250. schedule_work(&fep->phy_relink);
  1251. }
  1252. static void mii_queue_config(uint mii_reg, struct net_device *dev)
  1253. {
  1254. struct fcc_enet_private *fep = dev->priv;
  1255. schedule_work(&fep->phy_display_config);
  1256. }
  1257. phy_cmd_t phy_cmd_relink[] = { { mk_mii_read(MII_BMCR), mii_queue_relink },
  1258. { mk_mii_end, } };
  1259. phy_cmd_t phy_cmd_config[] = { { mk_mii_read(MII_BMCR), mii_queue_config },
  1260. { mk_mii_end, } };
  1261. /* Read remainder of PHY ID.
  1262. */
  1263. static void
  1264. mii_discover_phy3(uint mii_reg, struct net_device *dev)
  1265. {
  1266. struct fcc_enet_private *fep;
  1267. int i;
  1268. fep = dev->priv;
  1269. printk("mii_reg: %08x\n", mii_reg);
  1270. fep->phy_id |= (mii_reg & 0xffff);
  1271. for(i = 0; phy_info[i]; i++)
  1272. if((phy_info[i]->id == (fep->phy_id >> 4)) || !phy_info[i]->id)
  1273. break;
  1274. if(!phy_info[i])
  1275. panic("%s: PHY id 0x%08x is not supported!\n",
  1276. dev->name, fep->phy_id);
  1277. fep->phy = phy_info[i];
  1278. fep->phy_id_done = 1;
  1279. printk("%s: Phy @ 0x%x, type %s (0x%08x)\n",
  1280. dev->name, fep->phy_addr, fep->phy->name, fep->phy_id);
  1281. }
  1282. /* Scan all of the MII PHY addresses looking for someone to respond
  1283. * with a valid ID. This usually happens quickly.
  1284. */
  1285. static void
  1286. mii_discover_phy(uint mii_reg, struct net_device *dev)
  1287. {
  1288. struct fcc_enet_private *fep;
  1289. uint phytype;
  1290. fep = dev->priv;
  1291. if ((phytype = (mii_reg & 0xffff)) != 0xffff) {
  1292. /* Got first part of ID, now get remainder. */
  1293. fep->phy_id = phytype << 16;
  1294. mii_queue(dev, mk_mii_read(MII_PHYSID2), mii_discover_phy3);
  1295. } else {
  1296. fep->phy_addr++;
  1297. if (fep->phy_addr < 32) {
  1298. mii_queue(dev, mk_mii_read(MII_PHYSID1),
  1299. mii_discover_phy);
  1300. } else {
  1301. printk("fec: No PHY device found.\n");
  1302. }
  1303. }
  1304. }
  1305. #endif /* CONFIG_USE_MDIO */
  1306. #ifdef PHY_INTERRUPT
  1307. /* This interrupt occurs when the PHY detects a link change. */
  1308. static irqreturn_t
  1309. mii_link_interrupt(int irq, void * dev_id)
  1310. {
  1311. struct net_device *dev = dev_id;
  1312. struct fcc_enet_private *fep = dev->priv;
  1313. fcc_info_t *fip = fep->fip;
  1314. if (fep->phy) {
  1315. /* We don't want to be interrupted by an FCC
  1316. * interrupt here.
  1317. */
  1318. disable_irq_nosync(fip->fc_interrupt);
  1319. mii_do_cmd(dev, fep->phy->ack_int);
  1320. /* restart and display status */
  1321. mii_do_cmd(dev, phy_cmd_relink);
  1322. enable_irq(fip->fc_interrupt);
  1323. }
  1324. return IRQ_HANDLED;
  1325. }
  1326. #endif /* ifdef PHY_INTERRUPT */
  1327. #if 0 /* This should be fixed someday */
  1328. /* Set or clear the multicast filter for this adaptor.
  1329. * Skeleton taken from sunlance driver.
  1330. * The CPM Ethernet implementation allows Multicast as well as individual
  1331. * MAC address filtering. Some of the drivers check to make sure it is
  1332. * a group multicast address, and discard those that are not. I guess I
  1333. * will do the same for now, but just remove the test if you want
  1334. * individual filtering as well (do the upper net layers want or support
  1335. * this kind of feature?).
  1336. */
  1337. static void
  1338. set_multicast_list(struct net_device *dev)
  1339. {
  1340. struct fcc_enet_private *cep;
  1341. struct dev_mc_list *dmi;
  1342. u_char *mcptr, *tdptr;
  1343. volatile fcc_enet_t *ep;
  1344. int i, j;
  1345. cep = (struct fcc_enet_private *)dev->priv;
  1346. return;
  1347. /* Get pointer to FCC area in parameter RAM.
  1348. */
  1349. ep = (fcc_enet_t *)dev->base_addr;
  1350. if (dev->flags&IFF_PROMISC) {
  1351. /* Log any net taps. */
  1352. printk("%s: Promiscuous mode enabled.\n", dev->name);
  1353. cep->fccp->fcc_fpsmr |= FCC_PSMR_PRO;
  1354. } else {
  1355. cep->fccp->fcc_fpsmr &= ~FCC_PSMR_PRO;
  1356. if (dev->flags & IFF_ALLMULTI) {
  1357. /* Catch all multicast addresses, so set the
  1358. * filter to all 1's.
  1359. */
  1360. ep->fen_gaddrh = 0xffffffff;
  1361. ep->fen_gaddrl = 0xffffffff;
  1362. }
  1363. else {
  1364. /* Clear filter and add the addresses in the list.
  1365. */
  1366. ep->fen_gaddrh = 0;
  1367. ep->fen_gaddrl = 0;
  1368. dmi = dev->mc_list;
  1369. for (i=0; i<dev->mc_count; i++, dmi = dmi->next) {
  1370. /* Only support group multicast for now.
  1371. */
  1372. if (!(dmi->dmi_addr[0] & 1))
  1373. continue;
  1374. /* The address in dmi_addr is LSB first,
  1375. * and taddr is MSB first. We have to
  1376. * copy bytes MSB first from dmi_addr.
  1377. */
  1378. mcptr = (u_char *)dmi->dmi_addr + 5;
  1379. tdptr = (u_char *)&ep->fen_taddrh;
  1380. for (j=0; j<6; j++)
  1381. *tdptr++ = *mcptr--;
  1382. /* Ask CPM to run CRC and set bit in
  1383. * filter mask.
  1384. */
  1385. cpmp->cp_cpcr = mk_cr_cmd(cep->fip->fc_cpmpage,
  1386. cep->fip->fc_cpmblock, 0x0c,
  1387. CPM_CR_SET_GADDR) | CPM_CR_FLG;
  1388. udelay(10);
  1389. while (cpmp->cp_cpcr & CPM_CR_FLG);
  1390. }
  1391. }
  1392. }
  1393. }
  1394. #endif /* if 0 */
  1395. /* Set the individual MAC address.
  1396. */
  1397. int fcc_enet_set_mac_address(struct net_device *dev, void *p)
  1398. {
  1399. struct sockaddr *addr= (struct sockaddr *) p;
  1400. struct fcc_enet_private *cep;
  1401. volatile fcc_enet_t *ep;
  1402. unsigned char *eap;
  1403. int i;
  1404. cep = (struct fcc_enet_private *)(dev->priv);
  1405. ep = cep->ep;
  1406. if (netif_running(dev))
  1407. return -EBUSY;
  1408. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  1409. eap = (unsigned char *) &(ep->fen_paddrh);
  1410. for (i=5; i>=0; i--)
  1411. *eap++ = addr->sa_data[i];
  1412. return 0;
  1413. }
  1414. /* Initialize the CPM Ethernet on FCC.
  1415. */
  1416. static int __init fec_enet_init(void)
  1417. {
  1418. struct net_device *dev;
  1419. struct fcc_enet_private *cep;
  1420. fcc_info_t *fip;
  1421. int i, np, err;
  1422. volatile cpm2_map_t *immap;
  1423. volatile iop_cpm2_t *io;
  1424. immap = (cpm2_map_t *)CPM_MAP_ADDR; /* and to internal registers */
  1425. io = &immap->im_ioport;
  1426. np = sizeof(fcc_ports) / sizeof(fcc_info_t);
  1427. fip = fcc_ports;
  1428. while (np-- > 0) {
  1429. /* Create an Ethernet device instance.
  1430. */
  1431. dev = alloc_etherdev(sizeof(*cep));
  1432. if (!dev)
  1433. return -ENOMEM;
  1434. cep = dev->priv;
  1435. spin_lock_init(&cep->lock);
  1436. cep->fip = fip;
  1437. init_fcc_shutdown(fip, cep, immap);
  1438. init_fcc_ioports(fip, io, immap);
  1439. init_fcc_param(fip, dev, immap);
  1440. dev->base_addr = (unsigned long)(cep->ep);
  1441. /* The CPM Ethernet specific entries in the device
  1442. * structure.
  1443. */
  1444. dev->open = fcc_enet_open;
  1445. dev->hard_start_xmit = fcc_enet_start_xmit;
  1446. dev->tx_timeout = fcc_enet_timeout;
  1447. dev->watchdog_timeo = TX_TIMEOUT;
  1448. dev->stop = fcc_enet_close;
  1449. dev->get_stats = fcc_enet_get_stats;
  1450. /* dev->set_multicast_list = set_multicast_list; */
  1451. dev->set_mac_address = fcc_enet_set_mac_address;
  1452. init_fcc_startup(fip, dev);
  1453. err = register_netdev(dev);
  1454. if (err) {
  1455. free_netdev(dev);
  1456. return err;
  1457. }
  1458. printk("%s: FCC ENET Version 0.3, ", dev->name);
  1459. for (i=0; i<5; i++)
  1460. printk("%02x:", dev->dev_addr[i]);
  1461. printk("%02x\n", dev->dev_addr[5]);
  1462. #ifdef CONFIG_USE_MDIO
  1463. /* Queue up command to detect the PHY and initialize the
  1464. * remainder of the interface.
  1465. */
  1466. cep->phy_id_done = 0;
  1467. cep->phy_addr = fip->fc_phyaddr;
  1468. mii_queue(dev, mk_mii_read(MII_PHYSID1), mii_discover_phy);
  1469. INIT_WORK(&cep->phy_relink, mii_display_status);
  1470. INIT_WORK(&cep->phy_display_config, mii_display_config);
  1471. cep->dev = dev;
  1472. #endif /* CONFIG_USE_MDIO */
  1473. fip++;
  1474. }
  1475. return 0;
  1476. }
  1477. module_init(fec_enet_init);
  1478. /* Make sure the device is shut down during initialization.
  1479. */
  1480. static void __init
  1481. init_fcc_shutdown(fcc_info_t *fip, struct fcc_enet_private *cep,
  1482. volatile cpm2_map_t *immap)
  1483. {
  1484. volatile fcc_enet_t *ep;
  1485. volatile fcc_t *fccp;
  1486. /* Get pointer to FCC area in parameter RAM.
  1487. */
  1488. ep = (fcc_enet_t *)(&immap->im_dprambase[fip->fc_proff]);
  1489. /* And another to the FCC register area.
  1490. */
  1491. fccp = (volatile fcc_t *)(&immap->im_fcc[fip->fc_fccnum]);
  1492. cep->fccp = fccp; /* Keep the pointers handy */
  1493. cep->ep = ep;
  1494. /* Disable receive and transmit in case someone left it running.
  1495. */
  1496. fccp->fcc_gfmr &= ~(FCC_GFMR_ENR | FCC_GFMR_ENT);
  1497. }
  1498. /* Initialize the I/O pins for the FCC Ethernet.
  1499. */
  1500. static void __init
  1501. init_fcc_ioports(fcc_info_t *fip, volatile iop_cpm2_t *io,
  1502. volatile cpm2_map_t *immap)
  1503. {
  1504. /* FCC1 pins are on port A/C. FCC2/3 are port B/C.
  1505. */
  1506. if (fip->fc_proff == PROFF_FCC1) {
  1507. /* Configure port A and C pins for FCC1 Ethernet.
  1508. */
  1509. io->iop_pdira &= ~PA1_DIRA_BOUT;
  1510. io->iop_pdira |= PA1_DIRA_BIN;
  1511. io->iop_psora &= ~PA1_PSORA_BOUT;
  1512. io->iop_psora |= PA1_PSORA_BIN;
  1513. io->iop_ppara |= (PA1_DIRA_BOUT | PA1_DIRA_BIN);
  1514. }
  1515. if (fip->fc_proff == PROFF_FCC2) {
  1516. /* Configure port B and C pins for FCC Ethernet.
  1517. */
  1518. io->iop_pdirb &= ~PB2_DIRB_BOUT;
  1519. io->iop_pdirb |= PB2_DIRB_BIN;
  1520. io->iop_psorb &= ~PB2_PSORB_BOUT;
  1521. io->iop_psorb |= PB2_PSORB_BIN;
  1522. io->iop_pparb |= (PB2_DIRB_BOUT | PB2_DIRB_BIN);
  1523. }
  1524. if (fip->fc_proff == PROFF_FCC3) {
  1525. /* Configure port B and C pins for FCC Ethernet.
  1526. */
  1527. io->iop_pdirb &= ~PB3_DIRB_BOUT;
  1528. io->iop_pdirb |= PB3_DIRB_BIN;
  1529. io->iop_psorb &= ~PB3_PSORB_BOUT;
  1530. io->iop_psorb |= PB3_PSORB_BIN;
  1531. io->iop_pparb |= (PB3_DIRB_BOUT | PB3_DIRB_BIN);
  1532. io->iop_pdirc &= ~PC3_DIRC_BOUT;
  1533. io->iop_pdirc |= PC3_DIRC_BIN;
  1534. io->iop_psorc &= ~PC3_PSORC_BOUT;
  1535. io->iop_psorc |= PC3_PSORC_BIN;
  1536. io->iop_pparc |= (PC3_DIRC_BOUT | PC3_DIRC_BIN);
  1537. }
  1538. /* Port C has clocks......
  1539. */
  1540. io->iop_psorc &= ~(fip->fc_trxclocks);
  1541. io->iop_pdirc &= ~(fip->fc_trxclocks);
  1542. io->iop_pparc |= fip->fc_trxclocks;
  1543. #ifdef CONFIG_USE_MDIO
  1544. /* ....and the MII serial clock/data.
  1545. */
  1546. io->iop_pdatc |= (fip->fc_mdio | fip->fc_mdck);
  1547. io->iop_podrc &= ~(fip->fc_mdio | fip->fc_mdck);
  1548. io->iop_pdirc |= (fip->fc_mdio | fip->fc_mdck);
  1549. io->iop_pparc &= ~(fip->fc_mdio | fip->fc_mdck);
  1550. #endif /* CONFIG_USE_MDIO */
  1551. /* Configure Serial Interface clock routing.
  1552. * First, clear all FCC bits to zero,
  1553. * then set the ones we want.
  1554. */
  1555. immap->im_cpmux.cmx_fcr &= ~(fip->fc_clockmask);
  1556. immap->im_cpmux.cmx_fcr |= fip->fc_clockroute;
  1557. }
  1558. static void __init
  1559. init_fcc_param(fcc_info_t *fip, struct net_device *dev,
  1560. volatile cpm2_map_t *immap)
  1561. {
  1562. unsigned char *eap;
  1563. unsigned long mem_addr;
  1564. bd_t *bd;
  1565. int i, j;
  1566. struct fcc_enet_private *cep;
  1567. volatile fcc_enet_t *ep;
  1568. volatile cbd_t *bdp;
  1569. volatile cpm_cpm2_t *cp;
  1570. cep = (struct fcc_enet_private *)(dev->priv);
  1571. ep = cep->ep;
  1572. cp = cpmp;
  1573. bd = (bd_t *)__res;
  1574. /* Zero the whole thing.....I must have missed some individually.
  1575. * It works when I do this.
  1576. */
  1577. memset((char *)ep, 0, sizeof(fcc_enet_t));
  1578. /* Allocate space for the buffer descriptors from regular memory.
  1579. * Initialize base addresses for the buffer descriptors.
  1580. */
  1581. cep->rx_bd_base = kmalloc(sizeof(cbd_t) * RX_RING_SIZE,
  1582. GFP_KERNEL | GFP_DMA);
  1583. ep->fen_genfcc.fcc_rbase = __pa(cep->rx_bd_base);
  1584. cep->tx_bd_base = kmalloc(sizeof(cbd_t) * TX_RING_SIZE,
  1585. GFP_KERNEL | GFP_DMA);
  1586. ep->fen_genfcc.fcc_tbase = __pa(cep->tx_bd_base);
  1587. cep->dirty_tx = cep->cur_tx = cep->tx_bd_base;
  1588. cep->cur_rx = cep->rx_bd_base;
  1589. ep->fen_genfcc.fcc_rstate = (CPMFCR_GBL | CPMFCR_EB) << 24;
  1590. ep->fen_genfcc.fcc_tstate = (CPMFCR_GBL | CPMFCR_EB) << 24;
  1591. /* Set maximum bytes per receive buffer.
  1592. * It must be a multiple of 32.
  1593. */
  1594. ep->fen_genfcc.fcc_mrblr = PKT_MAXBLR_SIZE;
  1595. /* Allocate space in the reserved FCC area of DPRAM for the
  1596. * internal buffers. No one uses this space (yet), so we
  1597. * can do this. Later, we will add resource management for
  1598. * this area.
  1599. */
  1600. mem_addr = CPM_FCC_SPECIAL_BASE + (fip->fc_fccnum * 128);
  1601. ep->fen_genfcc.fcc_riptr = mem_addr;
  1602. ep->fen_genfcc.fcc_tiptr = mem_addr+32;
  1603. ep->fen_padptr = mem_addr+64;
  1604. memset((char *)(&(immap->im_dprambase[(mem_addr+64)])), 0x88, 32);
  1605. ep->fen_genfcc.fcc_rbptr = 0;
  1606. ep->fen_genfcc.fcc_tbptr = 0;
  1607. ep->fen_genfcc.fcc_rcrc = 0;
  1608. ep->fen_genfcc.fcc_tcrc = 0;
  1609. ep->fen_genfcc.fcc_res1 = 0;
  1610. ep->fen_genfcc.fcc_res2 = 0;
  1611. ep->fen_camptr = 0; /* CAM isn't used in this driver */
  1612. /* Set CRC preset and mask.
  1613. */
  1614. ep->fen_cmask = 0xdebb20e3;
  1615. ep->fen_cpres = 0xffffffff;
  1616. ep->fen_crcec = 0; /* CRC Error counter */
  1617. ep->fen_alec = 0; /* alignment error counter */
  1618. ep->fen_disfc = 0; /* discard frame counter */
  1619. ep->fen_retlim = 15; /* Retry limit threshold */
  1620. ep->fen_pper = 0; /* Normal persistence */
  1621. /* Clear hash filter tables.
  1622. */
  1623. ep->fen_gaddrh = 0;
  1624. ep->fen_gaddrl = 0;
  1625. ep->fen_iaddrh = 0;
  1626. ep->fen_iaddrl = 0;
  1627. /* Clear the Out-of-sequence TxBD.
  1628. */
  1629. ep->fen_tfcstat = 0;
  1630. ep->fen_tfclen = 0;
  1631. ep->fen_tfcptr = 0;
  1632. ep->fen_mflr = PKT_MAXBUF_SIZE; /* maximum frame length register */
  1633. ep->fen_minflr = PKT_MINBUF_SIZE; /* minimum frame length register */
  1634. /* Set Ethernet station address.
  1635. *
  1636. * This is supplied in the board information structure, so we
  1637. * copy that into the controller.
  1638. * So, far we have only been given one Ethernet address. We make
  1639. * it unique by setting a few bits in the upper byte of the
  1640. * non-static part of the address.
  1641. */
  1642. eap = (unsigned char *)&(ep->fen_paddrh);
  1643. for (i=5; i>=0; i--) {
  1644. /*
  1645. * The EP8260 only uses FCC3, so we can safely give it the real
  1646. * MAC address.
  1647. */
  1648. #ifdef CONFIG_SBC82xx
  1649. if (i == 5) {
  1650. /* bd->bi_enetaddr holds the SCC0 address; the FCC
  1651. devices count up from there */
  1652. dev->dev_addr[i] = bd->bi_enetaddr[i] & ~3;
  1653. dev->dev_addr[i] += 1 + fip->fc_fccnum;
  1654. *eap++ = dev->dev_addr[i];
  1655. }
  1656. #else
  1657. #ifndef CONFIG_RPX8260
  1658. if (i == 3) {
  1659. dev->dev_addr[i] = bd->bi_enetaddr[i];
  1660. dev->dev_addr[i] |= (1 << (7 - fip->fc_fccnum));
  1661. *eap++ = dev->dev_addr[i];
  1662. } else
  1663. #endif
  1664. {
  1665. *eap++ = dev->dev_addr[i] = bd->bi_enetaddr[i];
  1666. }
  1667. #endif
  1668. }
  1669. ep->fen_taddrh = 0;
  1670. ep->fen_taddrm = 0;
  1671. ep->fen_taddrl = 0;
  1672. ep->fen_maxd1 = PKT_MAXDMA_SIZE; /* maximum DMA1 length */
  1673. ep->fen_maxd2 = PKT_MAXDMA_SIZE; /* maximum DMA2 length */
  1674. /* Clear stat counters, in case we ever enable RMON.
  1675. */
  1676. ep->fen_octc = 0;
  1677. ep->fen_colc = 0;
  1678. ep->fen_broc = 0;
  1679. ep->fen_mulc = 0;
  1680. ep->fen_uspc = 0;
  1681. ep->fen_frgc = 0;
  1682. ep->fen_ospc = 0;
  1683. ep->fen_jbrc = 0;
  1684. ep->fen_p64c = 0;
  1685. ep->fen_p65c = 0;
  1686. ep->fen_p128c = 0;
  1687. ep->fen_p256c = 0;
  1688. ep->fen_p512c = 0;
  1689. ep->fen_p1024c = 0;
  1690. ep->fen_rfthr = 0; /* Suggested by manual */
  1691. ep->fen_rfcnt = 0;
  1692. ep->fen_cftype = 0;
  1693. /* Now allocate the host memory pages and initialize the
  1694. * buffer descriptors.
  1695. */
  1696. bdp = cep->tx_bd_base;
  1697. for (i=0; i<TX_RING_SIZE; i++) {
  1698. /* Initialize the BD for every fragment in the page.
  1699. */
  1700. bdp->cbd_sc = 0;
  1701. bdp->cbd_datlen = 0;
  1702. bdp->cbd_bufaddr = 0;
  1703. bdp++;
  1704. }
  1705. /* Set the last buffer to wrap.
  1706. */
  1707. bdp--;
  1708. bdp->cbd_sc |= BD_SC_WRAP;
  1709. bdp = cep->rx_bd_base;
  1710. for (i=0; i<FCC_ENET_RX_PAGES; i++) {
  1711. /* Allocate a page.
  1712. */
  1713. mem_addr = __get_free_page(GFP_KERNEL);
  1714. /* Initialize the BD for every fragment in the page.
  1715. */
  1716. for (j=0; j<FCC_ENET_RX_FRPPG; j++) {
  1717. bdp->cbd_sc = BD_ENET_RX_EMPTY | BD_ENET_RX_INTR;
  1718. bdp->cbd_datlen = 0;
  1719. bdp->cbd_bufaddr = __pa(mem_addr);
  1720. mem_addr += FCC_ENET_RX_FRSIZE;
  1721. bdp++;
  1722. }
  1723. }
  1724. /* Set the last buffer to wrap.
  1725. */
  1726. bdp--;
  1727. bdp->cbd_sc |= BD_SC_WRAP;
  1728. /* Let's re-initialize the channel now. We have to do it later
  1729. * than the manual describes because we have just now finished
  1730. * the BD initialization.
  1731. */
  1732. cp->cp_cpcr = mk_cr_cmd(fip->fc_cpmpage, fip->fc_cpmblock, 0x0c,
  1733. CPM_CR_INIT_TRX) | CPM_CR_FLG;
  1734. while (cp->cp_cpcr & CPM_CR_FLG);
  1735. cep->skb_cur = cep->skb_dirty = 0;
  1736. }
  1737. /* Let 'er rip.
  1738. */
  1739. static void __init
  1740. init_fcc_startup(fcc_info_t *fip, struct net_device *dev)
  1741. {
  1742. volatile fcc_t *fccp;
  1743. struct fcc_enet_private *cep;
  1744. cep = (struct fcc_enet_private *)(dev->priv);
  1745. fccp = cep->fccp;
  1746. #ifdef CONFIG_RPX8260
  1747. #ifdef PHY_INTERRUPT
  1748. /* Route PHY interrupt to IRQ. The following code only works for
  1749. * IRQ1 - IRQ7. It does not work for Port C interrupts.
  1750. */
  1751. *((volatile u_char *) (RPX_CSR_ADDR + 13)) &= ~BCSR13_FETH_IRQMASK;
  1752. *((volatile u_char *) (RPX_CSR_ADDR + 13)) |=
  1753. ((PHY_INTERRUPT - SIU_INT_IRQ1 + 1) << 4);
  1754. #endif
  1755. /* Initialize MDIO pins. */
  1756. *((volatile u_char *) (RPX_CSR_ADDR + 4)) &= ~BCSR4_MII_MDC;
  1757. *((volatile u_char *) (RPX_CSR_ADDR + 4)) |=
  1758. BCSR4_MII_READ | BCSR4_MII_MDIO;
  1759. /* Enable external LXT971 PHY. */
  1760. *((volatile u_char *) (RPX_CSR_ADDR + 4)) |= BCSR4_EN_PHY;
  1761. udelay(1000);
  1762. *((volatile u_char *) (RPX_CSR_ADDR+ 4)) |= BCSR4_EN_MII;
  1763. udelay(1000);
  1764. #endif /* ifdef CONFIG_RPX8260 */
  1765. fccp->fcc_fcce = 0xffff; /* Clear any pending events */
  1766. /* Leave FCC interrupts masked for now. Will be unmasked by
  1767. * fcc_restart().
  1768. */
  1769. fccp->fcc_fccm = 0;
  1770. /* Install our interrupt handler.
  1771. */
  1772. if (request_irq(fip->fc_interrupt, fcc_enet_interrupt, 0, "fenet",
  1773. dev) < 0)
  1774. printk("Can't get FCC IRQ %d\n", fip->fc_interrupt);
  1775. #ifdef PHY_INTERRUPT
  1776. #ifdef CONFIG_ADS8272
  1777. if (request_irq(PHY_INTERRUPT, mii_link_interrupt, IRQF_SHARED,
  1778. "mii", dev) < 0)
  1779. printk(KERN_CRIT "Can't get MII IRQ %d\n", PHY_INTERRUPT);
  1780. #else
  1781. /* Make IRQn edge triggered. This does not work if PHY_INTERRUPT is
  1782. * on Port C.
  1783. */
  1784. ((volatile cpm2_map_t *) CPM_MAP_ADDR)->im_intctl.ic_siexr |=
  1785. (1 << (14 - (PHY_INTERRUPT - SIU_INT_IRQ1)));
  1786. if (request_irq(PHY_INTERRUPT, mii_link_interrupt, 0,
  1787. "mii", dev) < 0)
  1788. printk(KERN_CRIT "Can't get MII IRQ %d\n", PHY_INTERRUPT);
  1789. #endif
  1790. #endif /* PHY_INTERRUPT */
  1791. /* Set GFMR to enable Ethernet operating mode.
  1792. */
  1793. fccp->fcc_gfmr = (FCC_GFMR_TCI | FCC_GFMR_MODE_ENET);
  1794. /* Set sync/delimiters.
  1795. */
  1796. fccp->fcc_fdsr = 0xd555;
  1797. /* Set protocol specific processing mode for Ethernet.
  1798. * This has to be adjusted for Full Duplex operation after we can
  1799. * determine how to detect that.
  1800. */
  1801. fccp->fcc_fpsmr = FCC_PSMR_ENCRC;
  1802. #ifdef CONFIG_PQ2ADS
  1803. /* Enable the PHY. */
  1804. *(volatile uint *)(BCSR_ADDR + 4) &= ~BCSR1_FETHIEN;
  1805. *(volatile uint *)(BCSR_ADDR + 4) |= BCSR1_FETH_RST;
  1806. #endif
  1807. #if defined(CONFIG_PQ2ADS) || defined(CONFIG_PQ2FADS)
  1808. /* Enable the 2nd PHY. */
  1809. *(volatile uint *)(BCSR_ADDR + 12) &= ~BCSR3_FETHIEN2;
  1810. *(volatile uint *)(BCSR_ADDR + 12) |= BCSR3_FETH2_RST;
  1811. #endif
  1812. #if defined(CONFIG_USE_MDIO) || defined(CONFIG_TQM8260)
  1813. /* start in full duplex mode, and negotiate speed
  1814. */
  1815. fcc_restart (dev, 1);
  1816. #else
  1817. /* start in half duplex mode
  1818. */
  1819. fcc_restart (dev, 0);
  1820. #endif
  1821. }
  1822. #ifdef CONFIG_USE_MDIO
  1823. /* MII command/status interface.
  1824. * I'm not going to describe all of the details. You can find the
  1825. * protocol definition in many other places, including the data sheet
  1826. * of most PHY parts.
  1827. * I wonder what "they" were thinking (maybe weren't) when they leave
  1828. * the I2C in the CPM but I have to toggle these bits......
  1829. */
  1830. #ifdef CONFIG_RPX8260
  1831. /* The EP8260 has the MDIO pins in a BCSR instead of on Port C
  1832. * like most other boards.
  1833. */
  1834. #define MDIO_ADDR ((volatile u_char *)(RPX_CSR_ADDR + 4))
  1835. #define MAKE_MDIO_OUTPUT *MDIO_ADDR &= ~BCSR4_MII_READ
  1836. #define MAKE_MDIO_INPUT *MDIO_ADDR |= BCSR4_MII_READ | BCSR4_MII_MDIO
  1837. #define OUT_MDIO(bit) \
  1838. if (bit) \
  1839. *MDIO_ADDR |= BCSR4_MII_MDIO; \
  1840. else \
  1841. *MDIO_ADDR &= ~BCSR4_MII_MDIO;
  1842. #define IN_MDIO (*MDIO_ADDR & BCSR4_MII_MDIO)
  1843. #define OUT_MDC(bit) \
  1844. if (bit) \
  1845. *MDIO_ADDR |= BCSR4_MII_MDC; \
  1846. else \
  1847. *MDIO_ADDR &= ~BCSR4_MII_MDC;
  1848. #else /* ifdef CONFIG_RPX8260 */
  1849. /* This is for the usual case where the MDIO pins are on Port C.
  1850. */
  1851. #define MDIO_ADDR (((volatile cpm2_map_t *)CPM_MAP_ADDR)->im_ioport)
  1852. #define MAKE_MDIO_OUTPUT MDIO_ADDR.iop_pdirc |= fip->fc_mdio
  1853. #define MAKE_MDIO_INPUT MDIO_ADDR.iop_pdirc &= ~fip->fc_mdio
  1854. #define OUT_MDIO(bit) \
  1855. if (bit) \
  1856. MDIO_ADDR.iop_pdatc |= fip->fc_mdio; \
  1857. else \
  1858. MDIO_ADDR.iop_pdatc &= ~fip->fc_mdio;
  1859. #define IN_MDIO ((MDIO_ADDR.iop_pdatc) & fip->fc_mdio)
  1860. #define OUT_MDC(bit) \
  1861. if (bit) \
  1862. MDIO_ADDR.iop_pdatc |= fip->fc_mdck; \
  1863. else \
  1864. MDIO_ADDR.iop_pdatc &= ~fip->fc_mdck;
  1865. #endif /* ifdef CONFIG_RPX8260 */
  1866. static uint
  1867. mii_send_receive(fcc_info_t *fip, uint cmd)
  1868. {
  1869. uint retval;
  1870. int read_op, i, off;
  1871. const int us = 1;
  1872. read_op = ((cmd & 0xf0000000) == 0x60000000);
  1873. /* Write preamble
  1874. */
  1875. OUT_MDIO(1);
  1876. MAKE_MDIO_OUTPUT;
  1877. OUT_MDIO(1);
  1878. for (i = 0; i < 32; i++)
  1879. {
  1880. udelay(us);
  1881. OUT_MDC(1);
  1882. udelay(us);
  1883. OUT_MDC(0);
  1884. }
  1885. /* Write data
  1886. */
  1887. for (i = 0, off = 31; i < (read_op ? 14 : 32); i++, --off)
  1888. {
  1889. OUT_MDIO((cmd >> off) & 0x00000001);
  1890. udelay(us);
  1891. OUT_MDC(1);
  1892. udelay(us);
  1893. OUT_MDC(0);
  1894. }
  1895. retval = cmd;
  1896. if (read_op)
  1897. {
  1898. retval >>= 16;
  1899. MAKE_MDIO_INPUT;
  1900. udelay(us);
  1901. OUT_MDC(1);
  1902. udelay(us);
  1903. OUT_MDC(0);
  1904. for (i = 0; i < 16; i++)
  1905. {
  1906. udelay(us);
  1907. OUT_MDC(1);
  1908. udelay(us);
  1909. retval <<= 1;
  1910. if (IN_MDIO)
  1911. retval++;
  1912. OUT_MDC(0);
  1913. }
  1914. }
  1915. MAKE_MDIO_INPUT;
  1916. udelay(us);
  1917. OUT_MDC(1);
  1918. udelay(us);
  1919. OUT_MDC(0);
  1920. return retval;
  1921. }
  1922. #endif /* CONFIG_USE_MDIO */
  1923. static void
  1924. fcc_stop(struct net_device *dev)
  1925. {
  1926. struct fcc_enet_private *fep= (struct fcc_enet_private *)(dev->priv);
  1927. volatile fcc_t *fccp = fep->fccp;
  1928. fcc_info_t *fip = fep->fip;
  1929. volatile fcc_enet_t *ep = fep->ep;
  1930. volatile cpm_cpm2_t *cp = cpmp;
  1931. volatile cbd_t *bdp;
  1932. int i;
  1933. if ((fccp->fcc_gfmr & (FCC_GFMR_ENR | FCC_GFMR_ENT)) == 0)
  1934. return; /* already down */
  1935. fccp->fcc_fccm = 0;
  1936. /* issue the graceful stop tx command */
  1937. while (cp->cp_cpcr & CPM_CR_FLG);
  1938. cp->cp_cpcr = mk_cr_cmd(fip->fc_cpmpage, fip->fc_cpmblock,
  1939. 0x0c, CPM_CR_GRA_STOP_TX) | CPM_CR_FLG;
  1940. while (cp->cp_cpcr & CPM_CR_FLG);
  1941. /* Disable transmit/receive */
  1942. fccp->fcc_gfmr &= ~(FCC_GFMR_ENR | FCC_GFMR_ENT);
  1943. /* issue the restart tx command */
  1944. fccp->fcc_fcce = FCC_ENET_GRA;
  1945. while (cp->cp_cpcr & CPM_CR_FLG);
  1946. cp->cp_cpcr = mk_cr_cmd(fip->fc_cpmpage, fip->fc_cpmblock,
  1947. 0x0c, CPM_CR_RESTART_TX) | CPM_CR_FLG;
  1948. while (cp->cp_cpcr & CPM_CR_FLG);
  1949. /* free tx buffers */
  1950. fep->skb_cur = fep->skb_dirty = 0;
  1951. for (i=0; i<=TX_RING_MOD_MASK; i++) {
  1952. if (fep->tx_skbuff[i] != NULL) {
  1953. dev_kfree_skb(fep->tx_skbuff[i]);
  1954. fep->tx_skbuff[i] = NULL;
  1955. }
  1956. }
  1957. fep->dirty_tx = fep->cur_tx = fep->tx_bd_base;
  1958. fep->tx_free = TX_RING_SIZE;
  1959. ep->fen_genfcc.fcc_tbptr = ep->fen_genfcc.fcc_tbase;
  1960. /* Initialize the tx buffer descriptors. */
  1961. bdp = fep->tx_bd_base;
  1962. for (i=0; i<TX_RING_SIZE; i++) {
  1963. bdp->cbd_sc = 0;
  1964. bdp->cbd_datlen = 0;
  1965. bdp->cbd_bufaddr = 0;
  1966. bdp++;
  1967. }
  1968. /* Set the last buffer to wrap. */
  1969. bdp--;
  1970. bdp->cbd_sc |= BD_SC_WRAP;
  1971. }
  1972. static void
  1973. fcc_restart(struct net_device *dev, int duplex)
  1974. {
  1975. struct fcc_enet_private *fep = (struct fcc_enet_private *)(dev->priv);
  1976. volatile fcc_t *fccp = fep->fccp;
  1977. /* stop any transmissions in progress */
  1978. fcc_stop(dev);
  1979. if (duplex)
  1980. fccp->fcc_fpsmr |= FCC_PSMR_FDE | FCC_PSMR_LPB;
  1981. else
  1982. fccp->fcc_fpsmr &= ~(FCC_PSMR_FDE | FCC_PSMR_LPB);
  1983. /* Enable interrupts for transmit error, complete frame
  1984. * received, and any transmit buffer we have also set the
  1985. * interrupt flag.
  1986. */
  1987. fccp->fcc_fccm = (FCC_ENET_TXE | FCC_ENET_RXF | FCC_ENET_TXB);
  1988. /* Enable transmit/receive */
  1989. fccp->fcc_gfmr |= FCC_GFMR_ENR | FCC_GFMR_ENT;
  1990. }
  1991. static int
  1992. fcc_enet_open(struct net_device *dev)
  1993. {
  1994. struct fcc_enet_private *fep = dev->priv;
  1995. #ifdef CONFIG_USE_MDIO
  1996. fep->sequence_done = 0;
  1997. fep->link = 0;
  1998. if (fep->phy) {
  1999. fcc_restart(dev, 0); /* always start in half-duplex */
  2000. mii_do_cmd(dev, fep->phy->ack_int);
  2001. mii_do_cmd(dev, fep->phy->config);
  2002. mii_do_cmd(dev, phy_cmd_config); /* display configuration */
  2003. while(!fep->sequence_done)
  2004. schedule();
  2005. mii_do_cmd(dev, fep->phy->startup);
  2006. netif_start_queue(dev);
  2007. return 0; /* Success */
  2008. }
  2009. return -ENODEV; /* No PHY we understand */
  2010. #else
  2011. fep->link = 1;
  2012. fcc_restart(dev, 0); /* always start in half-duplex */
  2013. netif_start_queue(dev);
  2014. return 0; /* Always succeed */
  2015. #endif /* CONFIG_USE_MDIO */
  2016. }