fcc_enet.c 64 KB

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