fcc_enet.c 65 KB

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