fcc_enet.c 64 KB

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