fec.c 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498
  1. /*
  2. * Fast Ethernet Controller (FEC) driver for Motorola MPC8xx.
  3. * Copyright (c) 1997 Dan Malek (dmalek@jlc.net)
  4. *
  5. * Right now, I am very wasteful with the buffers. I allocate memory
  6. * pages and then divide them into 2K frame buffers. This way I know I
  7. * have buffers large enough to hold one frame within one buffer descriptor.
  8. * Once I get this working, I will use 64 or 128 byte CPM buffers, which
  9. * will be much more memory efficient and will easily handle lots of
  10. * small packets.
  11. *
  12. * Much better multiple PHY support by Magnus Damm.
  13. * Copyright (c) 2000 Ericsson Radio Systems AB.
  14. *
  15. * Support for FEC controller of ColdFire processors.
  16. * Copyright (c) 2001-2005 Greg Ungerer (gerg@snapgear.com)
  17. *
  18. * Bug fixes and cleanup by Philippe De Muyter (phdm@macqel.be)
  19. * Copyright (c) 2004-2006 Macq Electronique SA.
  20. */
  21. #include <linux/module.h>
  22. #include <linux/kernel.h>
  23. #include <linux/string.h>
  24. #include <linux/ptrace.h>
  25. #include <linux/errno.h>
  26. #include <linux/ioport.h>
  27. #include <linux/slab.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/pci.h>
  30. #include <linux/init.h>
  31. #include <linux/delay.h>
  32. #include <linux/netdevice.h>
  33. #include <linux/etherdevice.h>
  34. #include <linux/skbuff.h>
  35. #include <linux/spinlock.h>
  36. #include <linux/workqueue.h>
  37. #include <linux/bitops.h>
  38. #include <asm/irq.h>
  39. #include <asm/uaccess.h>
  40. #include <asm/io.h>
  41. #include <asm/pgtable.h>
  42. #include <asm/cacheflush.h>
  43. #include <asm/coldfire.h>
  44. #include <asm/mcfsim.h>
  45. #include "fec.h"
  46. #if defined(CONFIG_FEC2)
  47. #define FEC_MAX_PORTS 2
  48. #else
  49. #define FEC_MAX_PORTS 1
  50. #endif
  51. #if defined(CONFIG_M5272)
  52. #define HAVE_mii_link_interrupt
  53. #endif
  54. /*
  55. * Define the fixed address of the FEC hardware.
  56. */
  57. static unsigned int fec_hw[] = {
  58. #if defined(CONFIG_M5272)
  59. (MCF_MBAR + 0x840),
  60. #elif defined(CONFIG_M527x)
  61. (MCF_MBAR + 0x1000),
  62. (MCF_MBAR + 0x1800),
  63. #elif defined(CONFIG_M523x) || defined(CONFIG_M528x)
  64. (MCF_MBAR + 0x1000),
  65. #elif defined(CONFIG_M520x)
  66. (MCF_MBAR+0x30000),
  67. #elif defined(CONFIG_M532x)
  68. (MCF_MBAR+0xfc030000),
  69. #endif
  70. };
  71. static unsigned char fec_mac_default[] = {
  72. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  73. };
  74. /*
  75. * Some hardware gets it MAC address out of local flash memory.
  76. * if this is non-zero then assume it is the address to get MAC from.
  77. */
  78. #if defined(CONFIG_NETtel)
  79. #define FEC_FLASHMAC 0xf0006006
  80. #elif defined(CONFIG_GILBARCONAP) || defined(CONFIG_SCALES)
  81. #define FEC_FLASHMAC 0xf0006000
  82. #elif defined(CONFIG_CANCam)
  83. #define FEC_FLASHMAC 0xf0020000
  84. #elif defined (CONFIG_M5272C3)
  85. #define FEC_FLASHMAC (0xffe04000 + 4)
  86. #elif defined(CONFIG_MOD5272)
  87. #define FEC_FLASHMAC 0xffc0406b
  88. #else
  89. #define FEC_FLASHMAC 0
  90. #endif
  91. /* Forward declarations of some structures to support different PHYs
  92. */
  93. typedef struct {
  94. uint mii_data;
  95. void (*funct)(uint mii_reg, struct net_device *dev);
  96. } phy_cmd_t;
  97. typedef struct {
  98. uint id;
  99. char *name;
  100. const phy_cmd_t *config;
  101. const phy_cmd_t *startup;
  102. const phy_cmd_t *ack_int;
  103. const phy_cmd_t *shutdown;
  104. } phy_info_t;
  105. /* The number of Tx and Rx buffers. These are allocated from the page
  106. * pool. The code may assume these are power of two, so it it best
  107. * to keep them that size.
  108. * We don't need to allocate pages for the transmitter. We just use
  109. * the skbuffer directly.
  110. */
  111. #define FEC_ENET_RX_PAGES 8
  112. #define FEC_ENET_RX_FRSIZE 2048
  113. #define FEC_ENET_RX_FRPPG (PAGE_SIZE / FEC_ENET_RX_FRSIZE)
  114. #define RX_RING_SIZE (FEC_ENET_RX_FRPPG * FEC_ENET_RX_PAGES)
  115. #define FEC_ENET_TX_FRSIZE 2048
  116. #define FEC_ENET_TX_FRPPG (PAGE_SIZE / FEC_ENET_TX_FRSIZE)
  117. #define TX_RING_SIZE 16 /* Must be power of two */
  118. #define TX_RING_MOD_MASK 15 /* for this to work */
  119. #if (((RX_RING_SIZE + TX_RING_SIZE) * 8) > PAGE_SIZE)
  120. #error "FEC: descriptor ring size constants too large"
  121. #endif
  122. /* Interrupt events/masks.
  123. */
  124. #define FEC_ENET_HBERR ((uint)0x80000000) /* Heartbeat error */
  125. #define FEC_ENET_BABR ((uint)0x40000000) /* Babbling receiver */
  126. #define FEC_ENET_BABT ((uint)0x20000000) /* Babbling transmitter */
  127. #define FEC_ENET_GRA ((uint)0x10000000) /* Graceful stop complete */
  128. #define FEC_ENET_TXF ((uint)0x08000000) /* Full frame transmitted */
  129. #define FEC_ENET_TXB ((uint)0x04000000) /* A buffer was transmitted */
  130. #define FEC_ENET_RXF ((uint)0x02000000) /* Full frame received */
  131. #define FEC_ENET_RXB ((uint)0x01000000) /* A buffer was received */
  132. #define FEC_ENET_MII ((uint)0x00800000) /* MII interrupt */
  133. #define FEC_ENET_EBERR ((uint)0x00400000) /* SDMA bus error */
  134. /* The FEC stores dest/src/type, data, and checksum for receive packets.
  135. */
  136. #define PKT_MAXBUF_SIZE 1518
  137. #define PKT_MINBUF_SIZE 64
  138. #define PKT_MAXBLR_SIZE 1520
  139. /*
  140. * The 5270/5271/5280/5282/532x RX control register also contains maximum frame
  141. * size bits. Other FEC hardware does not, so we need to take that into
  142. * account when setting it.
  143. */
  144. #if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x) || \
  145. defined(CONFIG_M520x) || defined(CONFIG_M532x)
  146. #define OPT_FRAME_SIZE (PKT_MAXBUF_SIZE << 16)
  147. #else
  148. #define OPT_FRAME_SIZE 0
  149. #endif
  150. /* The FEC buffer descriptors track the ring buffers. The rx_bd_base and
  151. * tx_bd_base always point to the base of the buffer descriptors. The
  152. * cur_rx and cur_tx point to the currently available buffer.
  153. * The dirty_tx tracks the current buffer that is being sent by the
  154. * controller. The cur_tx and dirty_tx are equal under both completely
  155. * empty and completely full conditions. The empty/ready indicator in
  156. * the buffer descriptor determines the actual condition.
  157. */
  158. struct fec_enet_private {
  159. /* Hardware registers of the FEC device */
  160. volatile fec_t *hwp;
  161. struct net_device *netdev;
  162. /* The saved address of a sent-in-place packet/buffer, for skfree(). */
  163. unsigned char *tx_bounce[TX_RING_SIZE];
  164. struct sk_buff* tx_skbuff[TX_RING_SIZE];
  165. ushort skb_cur;
  166. ushort skb_dirty;
  167. /* CPM dual port RAM relative addresses.
  168. */
  169. cbd_t *rx_bd_base; /* Address of Rx and Tx buffers. */
  170. cbd_t *tx_bd_base;
  171. cbd_t *cur_rx, *cur_tx; /* The next free ring entry */
  172. cbd_t *dirty_tx; /* The ring entries to be free()ed. */
  173. uint tx_full;
  174. /* hold while accessing the HW like ringbuffer for tx/rx but not MAC */
  175. spinlock_t hw_lock;
  176. /* hold while accessing the mii_list_t() elements */
  177. spinlock_t mii_lock;
  178. uint phy_id;
  179. uint phy_id_done;
  180. uint phy_status;
  181. uint phy_speed;
  182. phy_info_t const *phy;
  183. struct work_struct phy_task;
  184. uint sequence_done;
  185. uint mii_phy_task_queued;
  186. uint phy_addr;
  187. int index;
  188. int opened;
  189. int link;
  190. int old_link;
  191. int full_duplex;
  192. };
  193. static int fec_enet_open(struct net_device *dev);
  194. static int fec_enet_start_xmit(struct sk_buff *skb, struct net_device *dev);
  195. static void fec_enet_mii(struct net_device *dev);
  196. static irqreturn_t fec_enet_interrupt(int irq, void * dev_id);
  197. static void fec_enet_tx(struct net_device *dev);
  198. static void fec_enet_rx(struct net_device *dev);
  199. static int fec_enet_close(struct net_device *dev);
  200. static void set_multicast_list(struct net_device *dev);
  201. static void fec_restart(struct net_device *dev, int duplex);
  202. static void fec_stop(struct net_device *dev);
  203. static void fec_set_mac_address(struct net_device *dev);
  204. /* MII processing. We keep this as simple as possible. Requests are
  205. * placed on the list (if there is room). When the request is finished
  206. * by the MII, an optional function may be called.
  207. */
  208. typedef struct mii_list {
  209. uint mii_regval;
  210. void (*mii_func)(uint val, struct net_device *dev);
  211. struct mii_list *mii_next;
  212. } mii_list_t;
  213. #define NMII 20
  214. static mii_list_t mii_cmds[NMII];
  215. static mii_list_t *mii_free;
  216. static mii_list_t *mii_head;
  217. static mii_list_t *mii_tail;
  218. static int mii_queue(struct net_device *dev, int request,
  219. void (*func)(uint, struct net_device *));
  220. /* Make MII read/write commands for the FEC.
  221. */
  222. #define mk_mii_read(REG) (0x60020000 | ((REG & 0x1f) << 18))
  223. #define mk_mii_write(REG, VAL) (0x50020000 | ((REG & 0x1f) << 18) | \
  224. (VAL & 0xffff))
  225. #define mk_mii_end 0
  226. /* Transmitter timeout.
  227. */
  228. #define TX_TIMEOUT (2*HZ)
  229. /* Register definitions for the PHY.
  230. */
  231. #define MII_REG_CR 0 /* Control Register */
  232. #define MII_REG_SR 1 /* Status Register */
  233. #define MII_REG_PHYIR1 2 /* PHY Identification Register 1 */
  234. #define MII_REG_PHYIR2 3 /* PHY Identification Register 2 */
  235. #define MII_REG_ANAR 4 /* A-N Advertisement Register */
  236. #define MII_REG_ANLPAR 5 /* A-N Link Partner Ability Register */
  237. #define MII_REG_ANER 6 /* A-N Expansion Register */
  238. #define MII_REG_ANNPTR 7 /* A-N Next Page Transmit Register */
  239. #define MII_REG_ANLPRNPR 8 /* A-N Link Partner Received Next Page Reg. */
  240. /* values for phy_status */
  241. #define PHY_CONF_ANE 0x0001 /* 1 auto-negotiation enabled */
  242. #define PHY_CONF_LOOP 0x0002 /* 1 loopback mode enabled */
  243. #define PHY_CONF_SPMASK 0x00f0 /* mask for speed */
  244. #define PHY_CONF_10HDX 0x0010 /* 10 Mbit half duplex supported */
  245. #define PHY_CONF_10FDX 0x0020 /* 10 Mbit full duplex supported */
  246. #define PHY_CONF_100HDX 0x0040 /* 100 Mbit half duplex supported */
  247. #define PHY_CONF_100FDX 0x0080 /* 100 Mbit full duplex supported */
  248. #define PHY_STAT_LINK 0x0100 /* 1 up - 0 down */
  249. #define PHY_STAT_FAULT 0x0200 /* 1 remote fault */
  250. #define PHY_STAT_ANC 0x0400 /* 1 auto-negotiation complete */
  251. #define PHY_STAT_SPMASK 0xf000 /* mask for speed */
  252. #define PHY_STAT_10HDX 0x1000 /* 10 Mbit half duplex selected */
  253. #define PHY_STAT_10FDX 0x2000 /* 10 Mbit full duplex selected */
  254. #define PHY_STAT_100HDX 0x4000 /* 100 Mbit half duplex selected */
  255. #define PHY_STAT_100FDX 0x8000 /* 100 Mbit full duplex selected */
  256. static int
  257. fec_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
  258. {
  259. struct fec_enet_private *fep;
  260. volatile fec_t *fecp;
  261. volatile cbd_t *bdp;
  262. unsigned short status;
  263. unsigned long flags;
  264. fep = netdev_priv(dev);
  265. fecp = (volatile fec_t*)dev->base_addr;
  266. if (!fep->link) {
  267. /* Link is down or autonegotiation is in progress. */
  268. return 1;
  269. }
  270. spin_lock_irqsave(&fep->hw_lock, flags);
  271. /* Fill in a Tx ring entry */
  272. bdp = fep->cur_tx;
  273. status = bdp->cbd_sc;
  274. #ifndef final_version
  275. if (status & BD_ENET_TX_READY) {
  276. /* Ooops. All transmit buffers are full. Bail out.
  277. * This should not happen, since dev->tbusy should be set.
  278. */
  279. printk("%s: tx queue full!.\n", dev->name);
  280. spin_unlock_irqrestore(&fep->hw_lock, flags);
  281. return 1;
  282. }
  283. #endif
  284. /* Clear all of the status flags.
  285. */
  286. status &= ~BD_ENET_TX_STATS;
  287. /* Set buffer length and buffer pointer.
  288. */
  289. bdp->cbd_bufaddr = __pa(skb->data);
  290. bdp->cbd_datlen = skb->len;
  291. /*
  292. * On some FEC implementations data must be aligned on
  293. * 4-byte boundaries. Use bounce buffers to copy data
  294. * and get it aligned. Ugh.
  295. */
  296. if (bdp->cbd_bufaddr & 0x3) {
  297. unsigned int index;
  298. index = bdp - fep->tx_bd_base;
  299. memcpy(fep->tx_bounce[index], (void *) bdp->cbd_bufaddr, bdp->cbd_datlen);
  300. bdp->cbd_bufaddr = __pa(fep->tx_bounce[index]);
  301. }
  302. /* Save skb pointer.
  303. */
  304. fep->tx_skbuff[fep->skb_cur] = skb;
  305. dev->stats.tx_bytes += skb->len;
  306. fep->skb_cur = (fep->skb_cur+1) & TX_RING_MOD_MASK;
  307. /* Push the data cache so the CPM does not get stale memory
  308. * data.
  309. */
  310. flush_dcache_range((unsigned long)skb->data,
  311. (unsigned long)skb->data + skb->len);
  312. /* Send it on its way. Tell FEC it's ready, interrupt when done,
  313. * it's the last BD of the frame, and to put the CRC on the end.
  314. */
  315. status |= (BD_ENET_TX_READY | BD_ENET_TX_INTR
  316. | BD_ENET_TX_LAST | BD_ENET_TX_TC);
  317. bdp->cbd_sc = status;
  318. dev->trans_start = jiffies;
  319. /* Trigger transmission start */
  320. fecp->fec_x_des_active = 0;
  321. /* If this was the last BD in the ring, start at the beginning again.
  322. */
  323. if (status & BD_ENET_TX_WRAP) {
  324. bdp = fep->tx_bd_base;
  325. } else {
  326. bdp++;
  327. }
  328. if (bdp == fep->dirty_tx) {
  329. fep->tx_full = 1;
  330. netif_stop_queue(dev);
  331. }
  332. fep->cur_tx = (cbd_t *)bdp;
  333. spin_unlock_irqrestore(&fep->hw_lock, flags);
  334. return 0;
  335. }
  336. static void
  337. fec_timeout(struct net_device *dev)
  338. {
  339. struct fec_enet_private *fep = netdev_priv(dev);
  340. printk("%s: transmit timed out.\n", dev->name);
  341. dev->stats.tx_errors++;
  342. #ifndef final_version
  343. {
  344. int i;
  345. cbd_t *bdp;
  346. printk("Ring data dump: cur_tx %lx%s, dirty_tx %lx cur_rx: %lx\n",
  347. (unsigned long)fep->cur_tx, fep->tx_full ? " (full)" : "",
  348. (unsigned long)fep->dirty_tx,
  349. (unsigned long)fep->cur_rx);
  350. bdp = fep->tx_bd_base;
  351. printk(" tx: %u buffers\n", TX_RING_SIZE);
  352. for (i = 0 ; i < TX_RING_SIZE; i++) {
  353. printk(" %08x: %04x %04x %08x\n",
  354. (uint) bdp,
  355. bdp->cbd_sc,
  356. bdp->cbd_datlen,
  357. (int) bdp->cbd_bufaddr);
  358. bdp++;
  359. }
  360. bdp = fep->rx_bd_base;
  361. printk(" rx: %lu buffers\n", (unsigned long) RX_RING_SIZE);
  362. for (i = 0 ; i < RX_RING_SIZE; i++) {
  363. printk(" %08x: %04x %04x %08x\n",
  364. (uint) bdp,
  365. bdp->cbd_sc,
  366. bdp->cbd_datlen,
  367. (int) bdp->cbd_bufaddr);
  368. bdp++;
  369. }
  370. }
  371. #endif
  372. fec_restart(dev, fep->full_duplex);
  373. netif_wake_queue(dev);
  374. }
  375. /* The interrupt handler.
  376. * This is called from the MPC core interrupt.
  377. */
  378. static irqreturn_t
  379. fec_enet_interrupt(int irq, void * dev_id)
  380. {
  381. struct net_device *dev = dev_id;
  382. volatile fec_t *fecp;
  383. uint int_events;
  384. irqreturn_t ret = IRQ_NONE;
  385. fecp = (volatile fec_t*)dev->base_addr;
  386. /* Get the interrupt events that caused us to be here.
  387. */
  388. do {
  389. int_events = fecp->fec_ievent;
  390. fecp->fec_ievent = int_events;
  391. /* Handle receive event in its own function.
  392. */
  393. if (int_events & FEC_ENET_RXF) {
  394. ret = IRQ_HANDLED;
  395. fec_enet_rx(dev);
  396. }
  397. /* Transmit OK, or non-fatal error. Update the buffer
  398. descriptors. FEC handles all errors, we just discover
  399. them as part of the transmit process.
  400. */
  401. if (int_events & FEC_ENET_TXF) {
  402. ret = IRQ_HANDLED;
  403. fec_enet_tx(dev);
  404. }
  405. if (int_events & FEC_ENET_MII) {
  406. ret = IRQ_HANDLED;
  407. fec_enet_mii(dev);
  408. }
  409. } while (int_events);
  410. return ret;
  411. }
  412. static void
  413. fec_enet_tx(struct net_device *dev)
  414. {
  415. struct fec_enet_private *fep;
  416. volatile cbd_t *bdp;
  417. unsigned short status;
  418. struct sk_buff *skb;
  419. fep = netdev_priv(dev);
  420. spin_lock_irq(&fep->hw_lock);
  421. bdp = fep->dirty_tx;
  422. while (((status = bdp->cbd_sc) & BD_ENET_TX_READY) == 0) {
  423. if (bdp == fep->cur_tx && fep->tx_full == 0) break;
  424. skb = fep->tx_skbuff[fep->skb_dirty];
  425. /* Check for errors. */
  426. if (status & (BD_ENET_TX_HB | BD_ENET_TX_LC |
  427. BD_ENET_TX_RL | BD_ENET_TX_UN |
  428. BD_ENET_TX_CSL)) {
  429. dev->stats.tx_errors++;
  430. if (status & BD_ENET_TX_HB) /* No heartbeat */
  431. dev->stats.tx_heartbeat_errors++;
  432. if (status & BD_ENET_TX_LC) /* Late collision */
  433. dev->stats.tx_window_errors++;
  434. if (status & BD_ENET_TX_RL) /* Retrans limit */
  435. dev->stats.tx_aborted_errors++;
  436. if (status & BD_ENET_TX_UN) /* Underrun */
  437. dev->stats.tx_fifo_errors++;
  438. if (status & BD_ENET_TX_CSL) /* Carrier lost */
  439. dev->stats.tx_carrier_errors++;
  440. } else {
  441. dev->stats.tx_packets++;
  442. }
  443. #ifndef final_version
  444. if (status & BD_ENET_TX_READY)
  445. printk("HEY! Enet xmit interrupt and TX_READY.\n");
  446. #endif
  447. /* Deferred means some collisions occurred during transmit,
  448. * but we eventually sent the packet OK.
  449. */
  450. if (status & BD_ENET_TX_DEF)
  451. dev->stats.collisions++;
  452. /* Free the sk buffer associated with this last transmit.
  453. */
  454. dev_kfree_skb_any(skb);
  455. fep->tx_skbuff[fep->skb_dirty] = NULL;
  456. fep->skb_dirty = (fep->skb_dirty + 1) & TX_RING_MOD_MASK;
  457. /* Update pointer to next buffer descriptor to be transmitted.
  458. */
  459. if (status & BD_ENET_TX_WRAP)
  460. bdp = fep->tx_bd_base;
  461. else
  462. bdp++;
  463. /* Since we have freed up a buffer, the ring is no longer
  464. * full.
  465. */
  466. if (fep->tx_full) {
  467. fep->tx_full = 0;
  468. if (netif_queue_stopped(dev))
  469. netif_wake_queue(dev);
  470. }
  471. }
  472. fep->dirty_tx = (cbd_t *)bdp;
  473. spin_unlock_irq(&fep->hw_lock);
  474. }
  475. /* During a receive, the cur_rx points to the current incoming buffer.
  476. * When we update through the ring, if the next incoming buffer has
  477. * not been given to the system, we just set the empty indicator,
  478. * effectively tossing the packet.
  479. */
  480. static void
  481. fec_enet_rx(struct net_device *dev)
  482. {
  483. struct fec_enet_private *fep;
  484. volatile fec_t *fecp;
  485. volatile cbd_t *bdp;
  486. unsigned short status;
  487. struct sk_buff *skb;
  488. ushort pkt_len;
  489. __u8 *data;
  490. #ifdef CONFIG_M532x
  491. flush_cache_all();
  492. #endif
  493. fep = netdev_priv(dev);
  494. fecp = (volatile fec_t*)dev->base_addr;
  495. spin_lock_irq(&fep->hw_lock);
  496. /* First, grab all of the stats for the incoming packet.
  497. * These get messed up if we get called due to a busy condition.
  498. */
  499. bdp = fep->cur_rx;
  500. while (!((status = bdp->cbd_sc) & BD_ENET_RX_EMPTY)) {
  501. #ifndef final_version
  502. /* Since we have allocated space to hold a complete frame,
  503. * the last indicator should be set.
  504. */
  505. if ((status & BD_ENET_RX_LAST) == 0)
  506. printk("FEC ENET: rcv is not +last\n");
  507. #endif
  508. if (!fep->opened)
  509. goto rx_processing_done;
  510. /* Check for errors. */
  511. if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH | BD_ENET_RX_NO |
  512. BD_ENET_RX_CR | BD_ENET_RX_OV)) {
  513. dev->stats.rx_errors++;
  514. if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH)) {
  515. /* Frame too long or too short. */
  516. dev->stats.rx_length_errors++;
  517. }
  518. if (status & BD_ENET_RX_NO) /* Frame alignment */
  519. dev->stats.rx_frame_errors++;
  520. if (status & BD_ENET_RX_CR) /* CRC Error */
  521. dev->stats.rx_crc_errors++;
  522. if (status & BD_ENET_RX_OV) /* FIFO overrun */
  523. dev->stats.rx_fifo_errors++;
  524. }
  525. /* Report late collisions as a frame error.
  526. * On this error, the BD is closed, but we don't know what we
  527. * have in the buffer. So, just drop this frame on the floor.
  528. */
  529. if (status & BD_ENET_RX_CL) {
  530. dev->stats.rx_errors++;
  531. dev->stats.rx_frame_errors++;
  532. goto rx_processing_done;
  533. }
  534. /* Process the incoming frame.
  535. */
  536. dev->stats.rx_packets++;
  537. pkt_len = bdp->cbd_datlen;
  538. dev->stats.rx_bytes += pkt_len;
  539. data = (__u8*)__va(bdp->cbd_bufaddr);
  540. /* This does 16 byte alignment, exactly what we need.
  541. * The packet length includes FCS, but we don't want to
  542. * include that when passing upstream as it messes up
  543. * bridging applications.
  544. */
  545. skb = dev_alloc_skb(pkt_len-4);
  546. if (skb == NULL) {
  547. printk("%s: Memory squeeze, dropping packet.\n", dev->name);
  548. dev->stats.rx_dropped++;
  549. } else {
  550. skb_put(skb,pkt_len-4); /* Make room */
  551. skb_copy_to_linear_data(skb, data, pkt_len-4);
  552. skb->protocol=eth_type_trans(skb,dev);
  553. netif_rx(skb);
  554. }
  555. rx_processing_done:
  556. /* Clear the status flags for this buffer.
  557. */
  558. status &= ~BD_ENET_RX_STATS;
  559. /* Mark the buffer empty.
  560. */
  561. status |= BD_ENET_RX_EMPTY;
  562. bdp->cbd_sc = status;
  563. /* Update BD pointer to next entry.
  564. */
  565. if (status & BD_ENET_RX_WRAP)
  566. bdp = fep->rx_bd_base;
  567. else
  568. bdp++;
  569. #if 1
  570. /* Doing this here will keep the FEC running while we process
  571. * incoming frames. On a heavily loaded network, we should be
  572. * able to keep up at the expense of system resources.
  573. */
  574. fecp->fec_r_des_active = 0;
  575. #endif
  576. } /* while (!((status = bdp->cbd_sc) & BD_ENET_RX_EMPTY)) */
  577. fep->cur_rx = (cbd_t *)bdp;
  578. #if 0
  579. /* Doing this here will allow us to process all frames in the
  580. * ring before the FEC is allowed to put more there. On a heavily
  581. * loaded network, some frames may be lost. Unfortunately, this
  582. * increases the interrupt overhead since we can potentially work
  583. * our way back to the interrupt return only to come right back
  584. * here.
  585. */
  586. fecp->fec_r_des_active = 0;
  587. #endif
  588. spin_unlock_irq(&fep->hw_lock);
  589. }
  590. /* called from interrupt context */
  591. static void
  592. fec_enet_mii(struct net_device *dev)
  593. {
  594. struct fec_enet_private *fep;
  595. volatile fec_t *ep;
  596. mii_list_t *mip;
  597. uint mii_reg;
  598. fep = netdev_priv(dev);
  599. spin_lock_irq(&fep->mii_lock);
  600. ep = fep->hwp;
  601. mii_reg = ep->fec_mii_data;
  602. if ((mip = mii_head) == NULL) {
  603. printk("MII and no head!\n");
  604. goto unlock;
  605. }
  606. if (mip->mii_func != NULL)
  607. (*(mip->mii_func))(mii_reg, dev);
  608. mii_head = mip->mii_next;
  609. mip->mii_next = mii_free;
  610. mii_free = mip;
  611. if ((mip = mii_head) != NULL)
  612. ep->fec_mii_data = mip->mii_regval;
  613. unlock:
  614. spin_unlock_irq(&fep->mii_lock);
  615. }
  616. static int
  617. mii_queue(struct net_device *dev, int regval, void (*func)(uint, struct net_device *))
  618. {
  619. struct fec_enet_private *fep;
  620. unsigned long flags;
  621. mii_list_t *mip;
  622. int retval;
  623. /* Add PHY address to register command.
  624. */
  625. fep = netdev_priv(dev);
  626. spin_lock_irqsave(&fep->mii_lock, flags);
  627. regval |= fep->phy_addr << 23;
  628. retval = 0;
  629. if ((mip = mii_free) != NULL) {
  630. mii_free = mip->mii_next;
  631. mip->mii_regval = regval;
  632. mip->mii_func = func;
  633. mip->mii_next = NULL;
  634. if (mii_head) {
  635. mii_tail->mii_next = mip;
  636. mii_tail = mip;
  637. } else {
  638. mii_head = mii_tail = mip;
  639. fep->hwp->fec_mii_data = regval;
  640. }
  641. } else {
  642. retval = 1;
  643. }
  644. spin_unlock_irqrestore(&fep->mii_lock, flags);
  645. return retval;
  646. }
  647. static void mii_do_cmd(struct net_device *dev, const phy_cmd_t *c)
  648. {
  649. if(!c)
  650. return;
  651. for (; c->mii_data != mk_mii_end; c++)
  652. mii_queue(dev, c->mii_data, c->funct);
  653. }
  654. static void mii_parse_sr(uint mii_reg, struct net_device *dev)
  655. {
  656. struct fec_enet_private *fep = netdev_priv(dev);
  657. volatile uint *s = &(fep->phy_status);
  658. uint status;
  659. status = *s & ~(PHY_STAT_LINK | PHY_STAT_FAULT | PHY_STAT_ANC);
  660. if (mii_reg & 0x0004)
  661. status |= PHY_STAT_LINK;
  662. if (mii_reg & 0x0010)
  663. status |= PHY_STAT_FAULT;
  664. if (mii_reg & 0x0020)
  665. status |= PHY_STAT_ANC;
  666. *s = status;
  667. }
  668. static void mii_parse_cr(uint mii_reg, struct net_device *dev)
  669. {
  670. struct fec_enet_private *fep = netdev_priv(dev);
  671. volatile uint *s = &(fep->phy_status);
  672. uint status;
  673. status = *s & ~(PHY_CONF_ANE | PHY_CONF_LOOP);
  674. if (mii_reg & 0x1000)
  675. status |= PHY_CONF_ANE;
  676. if (mii_reg & 0x4000)
  677. status |= PHY_CONF_LOOP;
  678. *s = status;
  679. }
  680. static void mii_parse_anar(uint mii_reg, struct net_device *dev)
  681. {
  682. struct fec_enet_private *fep = netdev_priv(dev);
  683. volatile uint *s = &(fep->phy_status);
  684. uint status;
  685. status = *s & ~(PHY_CONF_SPMASK);
  686. if (mii_reg & 0x0020)
  687. status |= PHY_CONF_10HDX;
  688. if (mii_reg & 0x0040)
  689. status |= PHY_CONF_10FDX;
  690. if (mii_reg & 0x0080)
  691. status |= PHY_CONF_100HDX;
  692. if (mii_reg & 0x00100)
  693. status |= PHY_CONF_100FDX;
  694. *s = status;
  695. }
  696. /* ------------------------------------------------------------------------- */
  697. /* The Level one LXT970 is used by many boards */
  698. #define MII_LXT970_MIRROR 16 /* Mirror register */
  699. #define MII_LXT970_IER 17 /* Interrupt Enable Register */
  700. #define MII_LXT970_ISR 18 /* Interrupt Status Register */
  701. #define MII_LXT970_CONFIG 19 /* Configuration Register */
  702. #define MII_LXT970_CSR 20 /* Chip Status Register */
  703. static void mii_parse_lxt970_csr(uint mii_reg, struct net_device *dev)
  704. {
  705. struct fec_enet_private *fep = netdev_priv(dev);
  706. volatile uint *s = &(fep->phy_status);
  707. uint status;
  708. status = *s & ~(PHY_STAT_SPMASK);
  709. if (mii_reg & 0x0800) {
  710. if (mii_reg & 0x1000)
  711. status |= PHY_STAT_100FDX;
  712. else
  713. status |= PHY_STAT_100HDX;
  714. } else {
  715. if (mii_reg & 0x1000)
  716. status |= PHY_STAT_10FDX;
  717. else
  718. status |= PHY_STAT_10HDX;
  719. }
  720. *s = status;
  721. }
  722. static phy_cmd_t const phy_cmd_lxt970_config[] = {
  723. { mk_mii_read(MII_REG_CR), mii_parse_cr },
  724. { mk_mii_read(MII_REG_ANAR), mii_parse_anar },
  725. { mk_mii_end, }
  726. };
  727. static phy_cmd_t const phy_cmd_lxt970_startup[] = { /* enable interrupts */
  728. { mk_mii_write(MII_LXT970_IER, 0x0002), NULL },
  729. { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */
  730. { mk_mii_end, }
  731. };
  732. static phy_cmd_t const phy_cmd_lxt970_ack_int[] = {
  733. /* read SR and ISR to acknowledge */
  734. { mk_mii_read(MII_REG_SR), mii_parse_sr },
  735. { mk_mii_read(MII_LXT970_ISR), NULL },
  736. /* find out the current status */
  737. { mk_mii_read(MII_LXT970_CSR), mii_parse_lxt970_csr },
  738. { mk_mii_end, }
  739. };
  740. static phy_cmd_t const phy_cmd_lxt970_shutdown[] = { /* disable interrupts */
  741. { mk_mii_write(MII_LXT970_IER, 0x0000), NULL },
  742. { mk_mii_end, }
  743. };
  744. static phy_info_t const phy_info_lxt970 = {
  745. .id = 0x07810000,
  746. .name = "LXT970",
  747. .config = phy_cmd_lxt970_config,
  748. .startup = phy_cmd_lxt970_startup,
  749. .ack_int = phy_cmd_lxt970_ack_int,
  750. .shutdown = phy_cmd_lxt970_shutdown
  751. };
  752. /* ------------------------------------------------------------------------- */
  753. /* The Level one LXT971 is used on some of my custom boards */
  754. /* register definitions for the 971 */
  755. #define MII_LXT971_PCR 16 /* Port Control Register */
  756. #define MII_LXT971_SR2 17 /* Status Register 2 */
  757. #define MII_LXT971_IER 18 /* Interrupt Enable Register */
  758. #define MII_LXT971_ISR 19 /* Interrupt Status Register */
  759. #define MII_LXT971_LCR 20 /* LED Control Register */
  760. #define MII_LXT971_TCR 30 /* Transmit Control Register */
  761. /*
  762. * I had some nice ideas of running the MDIO faster...
  763. * The 971 should support 8MHz and I tried it, but things acted really
  764. * weird, so 2.5 MHz ought to be enough for anyone...
  765. */
  766. static void mii_parse_lxt971_sr2(uint mii_reg, struct net_device *dev)
  767. {
  768. struct fec_enet_private *fep = netdev_priv(dev);
  769. volatile uint *s = &(fep->phy_status);
  770. uint status;
  771. status = *s & ~(PHY_STAT_SPMASK | PHY_STAT_LINK | PHY_STAT_ANC);
  772. if (mii_reg & 0x0400) {
  773. fep->link = 1;
  774. status |= PHY_STAT_LINK;
  775. } else {
  776. fep->link = 0;
  777. }
  778. if (mii_reg & 0x0080)
  779. status |= PHY_STAT_ANC;
  780. if (mii_reg & 0x4000) {
  781. if (mii_reg & 0x0200)
  782. status |= PHY_STAT_100FDX;
  783. else
  784. status |= PHY_STAT_100HDX;
  785. } else {
  786. if (mii_reg & 0x0200)
  787. status |= PHY_STAT_10FDX;
  788. else
  789. status |= PHY_STAT_10HDX;
  790. }
  791. if (mii_reg & 0x0008)
  792. status |= PHY_STAT_FAULT;
  793. *s = status;
  794. }
  795. static phy_cmd_t const phy_cmd_lxt971_config[] = {
  796. /* limit to 10MBit because my prototype board
  797. * doesn't work with 100. */
  798. { mk_mii_read(MII_REG_CR), mii_parse_cr },
  799. { mk_mii_read(MII_REG_ANAR), mii_parse_anar },
  800. { mk_mii_read(MII_LXT971_SR2), mii_parse_lxt971_sr2 },
  801. { mk_mii_end, }
  802. };
  803. static phy_cmd_t const phy_cmd_lxt971_startup[] = { /* enable interrupts */
  804. { mk_mii_write(MII_LXT971_IER, 0x00f2), NULL },
  805. { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */
  806. { mk_mii_write(MII_LXT971_LCR, 0xd422), NULL }, /* LED config */
  807. /* Somehow does the 971 tell me that the link is down
  808. * the first read after power-up.
  809. * read here to get a valid value in ack_int */
  810. { mk_mii_read(MII_REG_SR), mii_parse_sr },
  811. { mk_mii_end, }
  812. };
  813. static phy_cmd_t const phy_cmd_lxt971_ack_int[] = {
  814. /* acknowledge the int before reading status ! */
  815. { mk_mii_read(MII_LXT971_ISR), NULL },
  816. /* find out the current status */
  817. { mk_mii_read(MII_REG_SR), mii_parse_sr },
  818. { mk_mii_read(MII_LXT971_SR2), mii_parse_lxt971_sr2 },
  819. { mk_mii_end, }
  820. };
  821. static phy_cmd_t const phy_cmd_lxt971_shutdown[] = { /* disable interrupts */
  822. { mk_mii_write(MII_LXT971_IER, 0x0000), NULL },
  823. { mk_mii_end, }
  824. };
  825. static phy_info_t const phy_info_lxt971 = {
  826. .id = 0x0001378e,
  827. .name = "LXT971",
  828. .config = phy_cmd_lxt971_config,
  829. .startup = phy_cmd_lxt971_startup,
  830. .ack_int = phy_cmd_lxt971_ack_int,
  831. .shutdown = phy_cmd_lxt971_shutdown
  832. };
  833. /* ------------------------------------------------------------------------- */
  834. /* The Quality Semiconductor QS6612 is used on the RPX CLLF */
  835. /* register definitions */
  836. #define MII_QS6612_MCR 17 /* Mode Control Register */
  837. #define MII_QS6612_FTR 27 /* Factory Test Register */
  838. #define MII_QS6612_MCO 28 /* Misc. Control Register */
  839. #define MII_QS6612_ISR 29 /* Interrupt Source Register */
  840. #define MII_QS6612_IMR 30 /* Interrupt Mask Register */
  841. #define MII_QS6612_PCR 31 /* 100BaseTx PHY Control Reg. */
  842. static void mii_parse_qs6612_pcr(uint mii_reg, struct net_device *dev)
  843. {
  844. struct fec_enet_private *fep = netdev_priv(dev);
  845. volatile uint *s = &(fep->phy_status);
  846. uint status;
  847. status = *s & ~(PHY_STAT_SPMASK);
  848. switch((mii_reg >> 2) & 7) {
  849. case 1: status |= PHY_STAT_10HDX; break;
  850. case 2: status |= PHY_STAT_100HDX; break;
  851. case 5: status |= PHY_STAT_10FDX; break;
  852. case 6: status |= PHY_STAT_100FDX; break;
  853. }
  854. *s = status;
  855. }
  856. static phy_cmd_t const phy_cmd_qs6612_config[] = {
  857. /* The PHY powers up isolated on the RPX,
  858. * so send a command to allow operation.
  859. */
  860. { mk_mii_write(MII_QS6612_PCR, 0x0dc0), NULL },
  861. /* parse cr and anar to get some info */
  862. { mk_mii_read(MII_REG_CR), mii_parse_cr },
  863. { mk_mii_read(MII_REG_ANAR), mii_parse_anar },
  864. { mk_mii_end, }
  865. };
  866. static phy_cmd_t const phy_cmd_qs6612_startup[] = { /* enable interrupts */
  867. { mk_mii_write(MII_QS6612_IMR, 0x003a), NULL },
  868. { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */
  869. { mk_mii_end, }
  870. };
  871. static phy_cmd_t const phy_cmd_qs6612_ack_int[] = {
  872. /* we need to read ISR, SR and ANER to acknowledge */
  873. { mk_mii_read(MII_QS6612_ISR), NULL },
  874. { mk_mii_read(MII_REG_SR), mii_parse_sr },
  875. { mk_mii_read(MII_REG_ANER), NULL },
  876. /* read pcr to get info */
  877. { mk_mii_read(MII_QS6612_PCR), mii_parse_qs6612_pcr },
  878. { mk_mii_end, }
  879. };
  880. static phy_cmd_t const phy_cmd_qs6612_shutdown[] = { /* disable interrupts */
  881. { mk_mii_write(MII_QS6612_IMR, 0x0000), NULL },
  882. { mk_mii_end, }
  883. };
  884. static phy_info_t const phy_info_qs6612 = {
  885. .id = 0x00181440,
  886. .name = "QS6612",
  887. .config = phy_cmd_qs6612_config,
  888. .startup = phy_cmd_qs6612_startup,
  889. .ack_int = phy_cmd_qs6612_ack_int,
  890. .shutdown = phy_cmd_qs6612_shutdown
  891. };
  892. /* ------------------------------------------------------------------------- */
  893. /* AMD AM79C874 phy */
  894. /* register definitions for the 874 */
  895. #define MII_AM79C874_MFR 16 /* Miscellaneous Feature Register */
  896. #define MII_AM79C874_ICSR 17 /* Interrupt/Status Register */
  897. #define MII_AM79C874_DR 18 /* Diagnostic Register */
  898. #define MII_AM79C874_PMLR 19 /* Power and Loopback Register */
  899. #define MII_AM79C874_MCR 21 /* ModeControl Register */
  900. #define MII_AM79C874_DC 23 /* Disconnect Counter */
  901. #define MII_AM79C874_REC 24 /* Recieve Error Counter */
  902. static void mii_parse_am79c874_dr(uint mii_reg, struct net_device *dev)
  903. {
  904. struct fec_enet_private *fep = netdev_priv(dev);
  905. volatile uint *s = &(fep->phy_status);
  906. uint status;
  907. status = *s & ~(PHY_STAT_SPMASK | PHY_STAT_ANC);
  908. if (mii_reg & 0x0080)
  909. status |= PHY_STAT_ANC;
  910. if (mii_reg & 0x0400)
  911. status |= ((mii_reg & 0x0800) ? PHY_STAT_100FDX : PHY_STAT_100HDX);
  912. else
  913. status |= ((mii_reg & 0x0800) ? PHY_STAT_10FDX : PHY_STAT_10HDX);
  914. *s = status;
  915. }
  916. static phy_cmd_t const phy_cmd_am79c874_config[] = {
  917. { mk_mii_read(MII_REG_CR), mii_parse_cr },
  918. { mk_mii_read(MII_REG_ANAR), mii_parse_anar },
  919. { mk_mii_read(MII_AM79C874_DR), mii_parse_am79c874_dr },
  920. { mk_mii_end, }
  921. };
  922. static phy_cmd_t const phy_cmd_am79c874_startup[] = { /* enable interrupts */
  923. { mk_mii_write(MII_AM79C874_ICSR, 0xff00), NULL },
  924. { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */
  925. { mk_mii_read(MII_REG_SR), mii_parse_sr },
  926. { mk_mii_end, }
  927. };
  928. static phy_cmd_t const phy_cmd_am79c874_ack_int[] = {
  929. /* find out the current status */
  930. { mk_mii_read(MII_REG_SR), mii_parse_sr },
  931. { mk_mii_read(MII_AM79C874_DR), mii_parse_am79c874_dr },
  932. /* we only need to read ISR to acknowledge */
  933. { mk_mii_read(MII_AM79C874_ICSR), NULL },
  934. { mk_mii_end, }
  935. };
  936. static phy_cmd_t const phy_cmd_am79c874_shutdown[] = { /* disable interrupts */
  937. { mk_mii_write(MII_AM79C874_ICSR, 0x0000), NULL },
  938. { mk_mii_end, }
  939. };
  940. static phy_info_t const phy_info_am79c874 = {
  941. .id = 0x00022561,
  942. .name = "AM79C874",
  943. .config = phy_cmd_am79c874_config,
  944. .startup = phy_cmd_am79c874_startup,
  945. .ack_int = phy_cmd_am79c874_ack_int,
  946. .shutdown = phy_cmd_am79c874_shutdown
  947. };
  948. /* ------------------------------------------------------------------------- */
  949. /* Kendin KS8721BL phy */
  950. /* register definitions for the 8721 */
  951. #define MII_KS8721BL_RXERCR 21
  952. #define MII_KS8721BL_ICSR 22
  953. #define MII_KS8721BL_PHYCR 31
  954. static phy_cmd_t const phy_cmd_ks8721bl_config[] = {
  955. { mk_mii_read(MII_REG_CR), mii_parse_cr },
  956. { mk_mii_read(MII_REG_ANAR), mii_parse_anar },
  957. { mk_mii_end, }
  958. };
  959. static phy_cmd_t const phy_cmd_ks8721bl_startup[] = { /* enable interrupts */
  960. { mk_mii_write(MII_KS8721BL_ICSR, 0xff00), NULL },
  961. { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */
  962. { mk_mii_read(MII_REG_SR), mii_parse_sr },
  963. { mk_mii_end, }
  964. };
  965. static phy_cmd_t const phy_cmd_ks8721bl_ack_int[] = {
  966. /* find out the current status */
  967. { mk_mii_read(MII_REG_SR), mii_parse_sr },
  968. /* we only need to read ISR to acknowledge */
  969. { mk_mii_read(MII_KS8721BL_ICSR), NULL },
  970. { mk_mii_end, }
  971. };
  972. static phy_cmd_t const phy_cmd_ks8721bl_shutdown[] = { /* disable interrupts */
  973. { mk_mii_write(MII_KS8721BL_ICSR, 0x0000), NULL },
  974. { mk_mii_end, }
  975. };
  976. static phy_info_t const phy_info_ks8721bl = {
  977. .id = 0x00022161,
  978. .name = "KS8721BL",
  979. .config = phy_cmd_ks8721bl_config,
  980. .startup = phy_cmd_ks8721bl_startup,
  981. .ack_int = phy_cmd_ks8721bl_ack_int,
  982. .shutdown = phy_cmd_ks8721bl_shutdown
  983. };
  984. /* ------------------------------------------------------------------------- */
  985. /* register definitions for the DP83848 */
  986. #define MII_DP8384X_PHYSTST 16 /* PHY Status Register */
  987. static void mii_parse_dp8384x_sr2(uint mii_reg, struct net_device *dev)
  988. {
  989. struct fec_enet_private *fep = netdev_priv(dev);
  990. volatile uint *s = &(fep->phy_status);
  991. *s &= ~(PHY_STAT_SPMASK | PHY_STAT_LINK | PHY_STAT_ANC);
  992. /* Link up */
  993. if (mii_reg & 0x0001) {
  994. fep->link = 1;
  995. *s |= PHY_STAT_LINK;
  996. } else
  997. fep->link = 0;
  998. /* Status of link */
  999. if (mii_reg & 0x0010) /* Autonegotioation complete */
  1000. *s |= PHY_STAT_ANC;
  1001. if (mii_reg & 0x0002) { /* 10MBps? */
  1002. if (mii_reg & 0x0004) /* Full Duplex? */
  1003. *s |= PHY_STAT_10FDX;
  1004. else
  1005. *s |= PHY_STAT_10HDX;
  1006. } else { /* 100 Mbps? */
  1007. if (mii_reg & 0x0004) /* Full Duplex? */
  1008. *s |= PHY_STAT_100FDX;
  1009. else
  1010. *s |= PHY_STAT_100HDX;
  1011. }
  1012. if (mii_reg & 0x0008)
  1013. *s |= PHY_STAT_FAULT;
  1014. }
  1015. static phy_info_t phy_info_dp83848= {
  1016. 0x020005c9,
  1017. "DP83848",
  1018. (const phy_cmd_t []) { /* config */
  1019. { mk_mii_read(MII_REG_CR), mii_parse_cr },
  1020. { mk_mii_read(MII_REG_ANAR), mii_parse_anar },
  1021. { mk_mii_read(MII_DP8384X_PHYSTST), mii_parse_dp8384x_sr2 },
  1022. { mk_mii_end, }
  1023. },
  1024. (const phy_cmd_t []) { /* startup - enable interrupts */
  1025. { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */
  1026. { mk_mii_read(MII_REG_SR), mii_parse_sr },
  1027. { mk_mii_end, }
  1028. },
  1029. (const phy_cmd_t []) { /* ack_int - never happens, no interrupt */
  1030. { mk_mii_end, }
  1031. },
  1032. (const phy_cmd_t []) { /* shutdown */
  1033. { mk_mii_end, }
  1034. },
  1035. };
  1036. /* ------------------------------------------------------------------------- */
  1037. static phy_info_t const * const phy_info[] = {
  1038. &phy_info_lxt970,
  1039. &phy_info_lxt971,
  1040. &phy_info_qs6612,
  1041. &phy_info_am79c874,
  1042. &phy_info_ks8721bl,
  1043. &phy_info_dp83848,
  1044. NULL
  1045. };
  1046. /* ------------------------------------------------------------------------- */
  1047. #ifdef HAVE_mii_link_interrupt
  1048. static irqreturn_t
  1049. mii_link_interrupt(int irq, void * dev_id);
  1050. #endif
  1051. #if defined(CONFIG_M5272)
  1052. /*
  1053. * Code specific to Coldfire 5272 setup.
  1054. */
  1055. static void __inline__ fec_request_intrs(struct net_device *dev)
  1056. {
  1057. volatile unsigned long *icrp;
  1058. static const struct idesc {
  1059. char *name;
  1060. unsigned short irq;
  1061. irq_handler_t handler;
  1062. } *idp, id[] = {
  1063. { "fec(RX)", 86, fec_enet_interrupt },
  1064. { "fec(TX)", 87, fec_enet_interrupt },
  1065. { "fec(OTHER)", 88, fec_enet_interrupt },
  1066. { "fec(MII)", 66, mii_link_interrupt },
  1067. { NULL },
  1068. };
  1069. /* Setup interrupt handlers. */
  1070. for (idp = id; idp->name; idp++) {
  1071. if (request_irq(idp->irq, idp->handler, IRQF_DISABLED, idp->name, dev) != 0)
  1072. printk("FEC: Could not allocate %s IRQ(%d)!\n", idp->name, idp->irq);
  1073. }
  1074. /* Unmask interrupt at ColdFire 5272 SIM */
  1075. icrp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_ICR3);
  1076. *icrp = 0x00000ddd;
  1077. icrp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_ICR1);
  1078. *icrp = 0x0d000000;
  1079. }
  1080. static void __inline__ fec_set_mii(struct net_device *dev, struct fec_enet_private *fep)
  1081. {
  1082. volatile fec_t *fecp;
  1083. fecp = fep->hwp;
  1084. fecp->fec_r_cntrl = OPT_FRAME_SIZE | 0x04;
  1085. fecp->fec_x_cntrl = 0x00;
  1086. /*
  1087. * Set MII speed to 2.5 MHz
  1088. * See 5272 manual section 11.5.8: MSCR
  1089. */
  1090. fep->phy_speed = ((((MCF_CLK / 4) / (2500000 / 10)) + 5) / 10) * 2;
  1091. fecp->fec_mii_speed = fep->phy_speed;
  1092. fec_restart(dev, 0);
  1093. }
  1094. static void __inline__ fec_get_mac(struct net_device *dev)
  1095. {
  1096. struct fec_enet_private *fep = netdev_priv(dev);
  1097. volatile fec_t *fecp;
  1098. unsigned char *iap, tmpaddr[ETH_ALEN];
  1099. fecp = fep->hwp;
  1100. if (FEC_FLASHMAC) {
  1101. /*
  1102. * Get MAC address from FLASH.
  1103. * If it is all 1's or 0's, use the default.
  1104. */
  1105. iap = (unsigned char *)FEC_FLASHMAC;
  1106. if ((iap[0] == 0) && (iap[1] == 0) && (iap[2] == 0) &&
  1107. (iap[3] == 0) && (iap[4] == 0) && (iap[5] == 0))
  1108. iap = fec_mac_default;
  1109. if ((iap[0] == 0xff) && (iap[1] == 0xff) && (iap[2] == 0xff) &&
  1110. (iap[3] == 0xff) && (iap[4] == 0xff) && (iap[5] == 0xff))
  1111. iap = fec_mac_default;
  1112. } else {
  1113. *((unsigned long *) &tmpaddr[0]) = fecp->fec_addr_low;
  1114. *((unsigned short *) &tmpaddr[4]) = (fecp->fec_addr_high >> 16);
  1115. iap = &tmpaddr[0];
  1116. }
  1117. memcpy(dev->dev_addr, iap, ETH_ALEN);
  1118. /* Adjust MAC if using default MAC address */
  1119. if (iap == fec_mac_default)
  1120. dev->dev_addr[ETH_ALEN-1] = fec_mac_default[ETH_ALEN-1] + fep->index;
  1121. }
  1122. static void __inline__ fec_enable_phy_intr(void)
  1123. {
  1124. }
  1125. static void __inline__ fec_disable_phy_intr(void)
  1126. {
  1127. volatile unsigned long *icrp;
  1128. icrp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_ICR1);
  1129. *icrp = 0x08000000;
  1130. }
  1131. static void __inline__ fec_phy_ack_intr(void)
  1132. {
  1133. volatile unsigned long *icrp;
  1134. /* Acknowledge the interrupt */
  1135. icrp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_ICR1);
  1136. *icrp = 0x0d000000;
  1137. }
  1138. static void __inline__ fec_localhw_setup(void)
  1139. {
  1140. }
  1141. /*
  1142. * Do not need to make region uncached on 5272.
  1143. */
  1144. static void __inline__ fec_uncache(unsigned long addr)
  1145. {
  1146. }
  1147. /* ------------------------------------------------------------------------- */
  1148. #elif defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x)
  1149. /*
  1150. * Code specific to Coldfire 5230/5231/5232/5234/5235,
  1151. * the 5270/5271/5274/5275 and 5280/5282 setups.
  1152. */
  1153. static void __inline__ fec_request_intrs(struct net_device *dev)
  1154. {
  1155. struct fec_enet_private *fep;
  1156. int b;
  1157. static const struct idesc {
  1158. char *name;
  1159. unsigned short irq;
  1160. } *idp, id[] = {
  1161. { "fec(TXF)", 23 },
  1162. { "fec(RXF)", 27 },
  1163. { "fec(MII)", 29 },
  1164. { NULL },
  1165. };
  1166. fep = netdev_priv(dev);
  1167. b = (fep->index) ? 128 : 64;
  1168. /* Setup interrupt handlers. */
  1169. for (idp = id; idp->name; idp++) {
  1170. if (request_irq(b+idp->irq, fec_enet_interrupt, IRQF_DISABLED, idp->name, dev) != 0)
  1171. printk("FEC: Could not allocate %s IRQ(%d)!\n", idp->name, b+idp->irq);
  1172. }
  1173. /* Unmask interrupts at ColdFire 5280/5282 interrupt controller */
  1174. {
  1175. volatile unsigned char *icrp;
  1176. volatile unsigned long *imrp;
  1177. int i, ilip;
  1178. b = (fep->index) ? MCFICM_INTC1 : MCFICM_INTC0;
  1179. icrp = (volatile unsigned char *) (MCF_IPSBAR + b +
  1180. MCFINTC_ICR0);
  1181. for (i = 23, ilip = 0x28; (i < 36); i++)
  1182. icrp[i] = ilip--;
  1183. imrp = (volatile unsigned long *) (MCF_IPSBAR + b +
  1184. MCFINTC_IMRH);
  1185. *imrp &= ~0x0000000f;
  1186. imrp = (volatile unsigned long *) (MCF_IPSBAR + b +
  1187. MCFINTC_IMRL);
  1188. *imrp &= ~0xff800001;
  1189. }
  1190. #if defined(CONFIG_M528x)
  1191. /* Set up gpio outputs for MII lines */
  1192. {
  1193. volatile u16 *gpio_paspar;
  1194. volatile u8 *gpio_pehlpar;
  1195. gpio_paspar = (volatile u16 *) (MCF_IPSBAR + 0x100056);
  1196. gpio_pehlpar = (volatile u16 *) (MCF_IPSBAR + 0x100058);
  1197. *gpio_paspar |= 0x0f00;
  1198. *gpio_pehlpar = 0xc0;
  1199. }
  1200. #endif
  1201. #if defined(CONFIG_M527x)
  1202. /* Set up gpio outputs for MII lines */
  1203. {
  1204. volatile u8 *gpio_par_fec;
  1205. volatile u16 *gpio_par_feci2c;
  1206. gpio_par_feci2c = (volatile u16 *)(MCF_IPSBAR + 0x100082);
  1207. /* Set up gpio outputs for FEC0 MII lines */
  1208. gpio_par_fec = (volatile u8 *)(MCF_IPSBAR + 0x100078);
  1209. *gpio_par_feci2c |= 0x0f00;
  1210. *gpio_par_fec |= 0xc0;
  1211. #if defined(CONFIG_FEC2)
  1212. /* Set up gpio outputs for FEC1 MII lines */
  1213. gpio_par_fec = (volatile u8 *)(MCF_IPSBAR + 0x100079);
  1214. *gpio_par_feci2c |= 0x00a0;
  1215. *gpio_par_fec |= 0xc0;
  1216. #endif /* CONFIG_FEC2 */
  1217. }
  1218. #endif /* CONFIG_M527x */
  1219. }
  1220. static void __inline__ fec_set_mii(struct net_device *dev, struct fec_enet_private *fep)
  1221. {
  1222. volatile fec_t *fecp;
  1223. fecp = fep->hwp;
  1224. fecp->fec_r_cntrl = OPT_FRAME_SIZE | 0x04;
  1225. fecp->fec_x_cntrl = 0x00;
  1226. /*
  1227. * Set MII speed to 2.5 MHz
  1228. * See 5282 manual section 17.5.4.7: MSCR
  1229. */
  1230. fep->phy_speed = ((((MCF_CLK / 2) / (2500000 / 10)) + 5) / 10) * 2;
  1231. fecp->fec_mii_speed = fep->phy_speed;
  1232. fec_restart(dev, 0);
  1233. }
  1234. static void __inline__ fec_get_mac(struct net_device *dev)
  1235. {
  1236. struct fec_enet_private *fep = netdev_priv(dev);
  1237. volatile fec_t *fecp;
  1238. unsigned char *iap, tmpaddr[ETH_ALEN];
  1239. fecp = fep->hwp;
  1240. if (FEC_FLASHMAC) {
  1241. /*
  1242. * Get MAC address from FLASH.
  1243. * If it is all 1's or 0's, use the default.
  1244. */
  1245. iap = FEC_FLASHMAC;
  1246. if ((iap[0] == 0) && (iap[1] == 0) && (iap[2] == 0) &&
  1247. (iap[3] == 0) && (iap[4] == 0) && (iap[5] == 0))
  1248. iap = fec_mac_default;
  1249. if ((iap[0] == 0xff) && (iap[1] == 0xff) && (iap[2] == 0xff) &&
  1250. (iap[3] == 0xff) && (iap[4] == 0xff) && (iap[5] == 0xff))
  1251. iap = fec_mac_default;
  1252. } else {
  1253. *((unsigned long *) &tmpaddr[0]) = fecp->fec_addr_low;
  1254. *((unsigned short *) &tmpaddr[4]) = (fecp->fec_addr_high >> 16);
  1255. iap = &tmpaddr[0];
  1256. }
  1257. memcpy(dev->dev_addr, iap, ETH_ALEN);
  1258. /* Adjust MAC if using default MAC address */
  1259. if (iap == fec_mac_default)
  1260. dev->dev_addr[ETH_ALEN-1] = fec_mac_default[ETH_ALEN-1] + fep->index;
  1261. }
  1262. static void __inline__ fec_enable_phy_intr(void)
  1263. {
  1264. }
  1265. static void __inline__ fec_disable_phy_intr(void)
  1266. {
  1267. }
  1268. static void __inline__ fec_phy_ack_intr(void)
  1269. {
  1270. }
  1271. static void __inline__ fec_localhw_setup(void)
  1272. {
  1273. }
  1274. /*
  1275. * Do not need to make region uncached on 5272.
  1276. */
  1277. static void __inline__ fec_uncache(unsigned long addr)
  1278. {
  1279. }
  1280. /* ------------------------------------------------------------------------- */
  1281. #elif defined(CONFIG_M520x)
  1282. /*
  1283. * Code specific to Coldfire 520x
  1284. */
  1285. static void __inline__ fec_request_intrs(struct net_device *dev)
  1286. {
  1287. struct fec_enet_private *fep;
  1288. int b;
  1289. static const struct idesc {
  1290. char *name;
  1291. unsigned short irq;
  1292. } *idp, id[] = {
  1293. { "fec(TXF)", 23 },
  1294. { "fec(RXF)", 27 },
  1295. { "fec(MII)", 29 },
  1296. { NULL },
  1297. };
  1298. fep = netdev_priv(dev);
  1299. b = 64 + 13;
  1300. /* Setup interrupt handlers. */
  1301. for (idp = id; idp->name; idp++) {
  1302. if (request_irq(b+idp->irq, fec_enet_interrupt, IRQF_DISABLED, idp->name,dev) != 0)
  1303. printk("FEC: Could not allocate %s IRQ(%d)!\n", idp->name, b+idp->irq);
  1304. }
  1305. /* Unmask interrupts at ColdFire interrupt controller */
  1306. {
  1307. volatile unsigned char *icrp;
  1308. volatile unsigned long *imrp;
  1309. icrp = (volatile unsigned char *) (MCF_IPSBAR + MCFICM_INTC0 +
  1310. MCFINTC_ICR0);
  1311. for (b = 36; (b < 49); b++)
  1312. icrp[b] = 0x04;
  1313. imrp = (volatile unsigned long *) (MCF_IPSBAR + MCFICM_INTC0 +
  1314. MCFINTC_IMRH);
  1315. *imrp &= ~0x0001FFF0;
  1316. }
  1317. *(volatile unsigned char *)(MCF_IPSBAR + MCF_GPIO_PAR_FEC) |= 0xf0;
  1318. *(volatile unsigned char *)(MCF_IPSBAR + MCF_GPIO_PAR_FECI2C) |= 0x0f;
  1319. }
  1320. static void __inline__ fec_set_mii(struct net_device *dev, struct fec_enet_private *fep)
  1321. {
  1322. volatile fec_t *fecp;
  1323. fecp = fep->hwp;
  1324. fecp->fec_r_cntrl = OPT_FRAME_SIZE | 0x04;
  1325. fecp->fec_x_cntrl = 0x00;
  1326. /*
  1327. * Set MII speed to 2.5 MHz
  1328. * See 5282 manual section 17.5.4.7: MSCR
  1329. */
  1330. fep->phy_speed = ((((MCF_CLK / 2) / (2500000 / 10)) + 5) / 10) * 2;
  1331. fecp->fec_mii_speed = fep->phy_speed;
  1332. fec_restart(dev, 0);
  1333. }
  1334. static void __inline__ fec_get_mac(struct net_device *dev)
  1335. {
  1336. struct fec_enet_private *fep = netdev_priv(dev);
  1337. volatile fec_t *fecp;
  1338. unsigned char *iap, tmpaddr[ETH_ALEN];
  1339. fecp = fep->hwp;
  1340. if (FEC_FLASHMAC) {
  1341. /*
  1342. * Get MAC address from FLASH.
  1343. * If it is all 1's or 0's, use the default.
  1344. */
  1345. iap = FEC_FLASHMAC;
  1346. if ((iap[0] == 0) && (iap[1] == 0) && (iap[2] == 0) &&
  1347. (iap[3] == 0) && (iap[4] == 0) && (iap[5] == 0))
  1348. iap = fec_mac_default;
  1349. if ((iap[0] == 0xff) && (iap[1] == 0xff) && (iap[2] == 0xff) &&
  1350. (iap[3] == 0xff) && (iap[4] == 0xff) && (iap[5] == 0xff))
  1351. iap = fec_mac_default;
  1352. } else {
  1353. *((unsigned long *) &tmpaddr[0]) = fecp->fec_addr_low;
  1354. *((unsigned short *) &tmpaddr[4]) = (fecp->fec_addr_high >> 16);
  1355. iap = &tmpaddr[0];
  1356. }
  1357. memcpy(dev->dev_addr, iap, ETH_ALEN);
  1358. /* Adjust MAC if using default MAC address */
  1359. if (iap == fec_mac_default)
  1360. dev->dev_addr[ETH_ALEN-1] = fec_mac_default[ETH_ALEN-1] + fep->index;
  1361. }
  1362. static void __inline__ fec_enable_phy_intr(void)
  1363. {
  1364. }
  1365. static void __inline__ fec_disable_phy_intr(void)
  1366. {
  1367. }
  1368. static void __inline__ fec_phy_ack_intr(void)
  1369. {
  1370. }
  1371. static void __inline__ fec_localhw_setup(void)
  1372. {
  1373. }
  1374. static void __inline__ fec_uncache(unsigned long addr)
  1375. {
  1376. }
  1377. /* ------------------------------------------------------------------------- */
  1378. #elif defined(CONFIG_M532x)
  1379. /*
  1380. * Code specific for M532x
  1381. */
  1382. static void __inline__ fec_request_intrs(struct net_device *dev)
  1383. {
  1384. struct fec_enet_private *fep;
  1385. int b;
  1386. static const struct idesc {
  1387. char *name;
  1388. unsigned short irq;
  1389. } *idp, id[] = {
  1390. { "fec(TXF)", 36 },
  1391. { "fec(RXF)", 40 },
  1392. { "fec(MII)", 42 },
  1393. { NULL },
  1394. };
  1395. fep = netdev_priv(dev);
  1396. b = (fep->index) ? 128 : 64;
  1397. /* Setup interrupt handlers. */
  1398. for (idp = id; idp->name; idp++) {
  1399. if (request_irq(b+idp->irq, fec_enet_interrupt, IRQF_DISABLED, idp->name,dev) != 0)
  1400. printk("FEC: Could not allocate %s IRQ(%d)!\n",
  1401. idp->name, b+idp->irq);
  1402. }
  1403. /* Unmask interrupts */
  1404. MCF_INTC0_ICR36 = 0x2;
  1405. MCF_INTC0_ICR37 = 0x2;
  1406. MCF_INTC0_ICR38 = 0x2;
  1407. MCF_INTC0_ICR39 = 0x2;
  1408. MCF_INTC0_ICR40 = 0x2;
  1409. MCF_INTC0_ICR41 = 0x2;
  1410. MCF_INTC0_ICR42 = 0x2;
  1411. MCF_INTC0_ICR43 = 0x2;
  1412. MCF_INTC0_ICR44 = 0x2;
  1413. MCF_INTC0_ICR45 = 0x2;
  1414. MCF_INTC0_ICR46 = 0x2;
  1415. MCF_INTC0_ICR47 = 0x2;
  1416. MCF_INTC0_ICR48 = 0x2;
  1417. MCF_INTC0_IMRH &= ~(
  1418. MCF_INTC_IMRH_INT_MASK36 |
  1419. MCF_INTC_IMRH_INT_MASK37 |
  1420. MCF_INTC_IMRH_INT_MASK38 |
  1421. MCF_INTC_IMRH_INT_MASK39 |
  1422. MCF_INTC_IMRH_INT_MASK40 |
  1423. MCF_INTC_IMRH_INT_MASK41 |
  1424. MCF_INTC_IMRH_INT_MASK42 |
  1425. MCF_INTC_IMRH_INT_MASK43 |
  1426. MCF_INTC_IMRH_INT_MASK44 |
  1427. MCF_INTC_IMRH_INT_MASK45 |
  1428. MCF_INTC_IMRH_INT_MASK46 |
  1429. MCF_INTC_IMRH_INT_MASK47 |
  1430. MCF_INTC_IMRH_INT_MASK48 );
  1431. /* Set up gpio outputs for MII lines */
  1432. MCF_GPIO_PAR_FECI2C |= (0 |
  1433. MCF_GPIO_PAR_FECI2C_PAR_MDC_EMDC |
  1434. MCF_GPIO_PAR_FECI2C_PAR_MDIO_EMDIO);
  1435. MCF_GPIO_PAR_FEC = (0 |
  1436. MCF_GPIO_PAR_FEC_PAR_FEC_7W_FEC |
  1437. MCF_GPIO_PAR_FEC_PAR_FEC_MII_FEC);
  1438. }
  1439. static void __inline__ fec_set_mii(struct net_device *dev, struct fec_enet_private *fep)
  1440. {
  1441. volatile fec_t *fecp;
  1442. fecp = fep->hwp;
  1443. fecp->fec_r_cntrl = OPT_FRAME_SIZE | 0x04;
  1444. fecp->fec_x_cntrl = 0x00;
  1445. /*
  1446. * Set MII speed to 2.5 MHz
  1447. */
  1448. fep->phy_speed = ((((MCF_CLK / 2) / (2500000 / 10)) + 5) / 10) * 2;
  1449. fecp->fec_mii_speed = fep->phy_speed;
  1450. fec_restart(dev, 0);
  1451. }
  1452. static void __inline__ fec_get_mac(struct net_device *dev)
  1453. {
  1454. struct fec_enet_private *fep = netdev_priv(dev);
  1455. volatile fec_t *fecp;
  1456. unsigned char *iap, tmpaddr[ETH_ALEN];
  1457. fecp = fep->hwp;
  1458. if (FEC_FLASHMAC) {
  1459. /*
  1460. * Get MAC address from FLASH.
  1461. * If it is all 1's or 0's, use the default.
  1462. */
  1463. iap = FEC_FLASHMAC;
  1464. if ((iap[0] == 0) && (iap[1] == 0) && (iap[2] == 0) &&
  1465. (iap[3] == 0) && (iap[4] == 0) && (iap[5] == 0))
  1466. iap = fec_mac_default;
  1467. if ((iap[0] == 0xff) && (iap[1] == 0xff) && (iap[2] == 0xff) &&
  1468. (iap[3] == 0xff) && (iap[4] == 0xff) && (iap[5] == 0xff))
  1469. iap = fec_mac_default;
  1470. } else {
  1471. *((unsigned long *) &tmpaddr[0]) = fecp->fec_addr_low;
  1472. *((unsigned short *) &tmpaddr[4]) = (fecp->fec_addr_high >> 16);
  1473. iap = &tmpaddr[0];
  1474. }
  1475. memcpy(dev->dev_addr, iap, ETH_ALEN);
  1476. /* Adjust MAC if using default MAC address */
  1477. if (iap == fec_mac_default)
  1478. dev->dev_addr[ETH_ALEN-1] = fec_mac_default[ETH_ALEN-1] + fep->index;
  1479. }
  1480. static void __inline__ fec_enable_phy_intr(void)
  1481. {
  1482. }
  1483. static void __inline__ fec_disable_phy_intr(void)
  1484. {
  1485. }
  1486. static void __inline__ fec_phy_ack_intr(void)
  1487. {
  1488. }
  1489. static void __inline__ fec_localhw_setup(void)
  1490. {
  1491. }
  1492. /*
  1493. * Do not need to make region uncached on 532x.
  1494. */
  1495. static void __inline__ fec_uncache(unsigned long addr)
  1496. {
  1497. }
  1498. #endif
  1499. /* ------------------------------------------------------------------------- */
  1500. static void mii_display_status(struct net_device *dev)
  1501. {
  1502. struct fec_enet_private *fep = netdev_priv(dev);
  1503. volatile uint *s = &(fep->phy_status);
  1504. if (!fep->link && !fep->old_link) {
  1505. /* Link is still down - don't print anything */
  1506. return;
  1507. }
  1508. printk("%s: status: ", dev->name);
  1509. if (!fep->link) {
  1510. printk("link down");
  1511. } else {
  1512. printk("link up");
  1513. switch(*s & PHY_STAT_SPMASK) {
  1514. case PHY_STAT_100FDX: printk(", 100MBit Full Duplex"); break;
  1515. case PHY_STAT_100HDX: printk(", 100MBit Half Duplex"); break;
  1516. case PHY_STAT_10FDX: printk(", 10MBit Full Duplex"); break;
  1517. case PHY_STAT_10HDX: printk(", 10MBit Half Duplex"); break;
  1518. default:
  1519. printk(", Unknown speed/duplex");
  1520. }
  1521. if (*s & PHY_STAT_ANC)
  1522. printk(", auto-negotiation complete");
  1523. }
  1524. if (*s & PHY_STAT_FAULT)
  1525. printk(", remote fault");
  1526. printk(".\n");
  1527. }
  1528. static void mii_display_config(struct work_struct *work)
  1529. {
  1530. struct fec_enet_private *fep = container_of(work, struct fec_enet_private, phy_task);
  1531. struct net_device *dev = fep->netdev;
  1532. uint status = fep->phy_status;
  1533. /*
  1534. ** When we get here, phy_task is already removed from
  1535. ** the workqueue. It is thus safe to allow to reuse it.
  1536. */
  1537. fep->mii_phy_task_queued = 0;
  1538. printk("%s: config: auto-negotiation ", dev->name);
  1539. if (status & PHY_CONF_ANE)
  1540. printk("on");
  1541. else
  1542. printk("off");
  1543. if (status & PHY_CONF_100FDX)
  1544. printk(", 100FDX");
  1545. if (status & PHY_CONF_100HDX)
  1546. printk(", 100HDX");
  1547. if (status & PHY_CONF_10FDX)
  1548. printk(", 10FDX");
  1549. if (status & PHY_CONF_10HDX)
  1550. printk(", 10HDX");
  1551. if (!(status & PHY_CONF_SPMASK))
  1552. printk(", No speed/duplex selected?");
  1553. if (status & PHY_CONF_LOOP)
  1554. printk(", loopback enabled");
  1555. printk(".\n");
  1556. fep->sequence_done = 1;
  1557. }
  1558. static void mii_relink(struct work_struct *work)
  1559. {
  1560. struct fec_enet_private *fep = container_of(work, struct fec_enet_private, phy_task);
  1561. struct net_device *dev = fep->netdev;
  1562. int duplex;
  1563. /*
  1564. ** When we get here, phy_task is already removed from
  1565. ** the workqueue. It is thus safe to allow to reuse it.
  1566. */
  1567. fep->mii_phy_task_queued = 0;
  1568. fep->link = (fep->phy_status & PHY_STAT_LINK) ? 1 : 0;
  1569. mii_display_status(dev);
  1570. fep->old_link = fep->link;
  1571. if (fep->link) {
  1572. duplex = 0;
  1573. if (fep->phy_status
  1574. & (PHY_STAT_100FDX | PHY_STAT_10FDX))
  1575. duplex = 1;
  1576. fec_restart(dev, duplex);
  1577. } else
  1578. fec_stop(dev);
  1579. #if 0
  1580. enable_irq(fep->mii_irq);
  1581. #endif
  1582. }
  1583. /* mii_queue_relink is called in interrupt context from mii_link_interrupt */
  1584. static void mii_queue_relink(uint mii_reg, struct net_device *dev)
  1585. {
  1586. struct fec_enet_private *fep = netdev_priv(dev);
  1587. /*
  1588. ** We cannot queue phy_task twice in the workqueue. It
  1589. ** would cause an endless loop in the workqueue.
  1590. ** Fortunately, if the last mii_relink entry has not yet been
  1591. ** executed now, it will do the job for the current interrupt,
  1592. ** which is just what we want.
  1593. */
  1594. if (fep->mii_phy_task_queued)
  1595. return;
  1596. fep->mii_phy_task_queued = 1;
  1597. INIT_WORK(&fep->phy_task, mii_relink);
  1598. schedule_work(&fep->phy_task);
  1599. }
  1600. /* mii_queue_config is called in interrupt context from fec_enet_mii */
  1601. static void mii_queue_config(uint mii_reg, struct net_device *dev)
  1602. {
  1603. struct fec_enet_private *fep = netdev_priv(dev);
  1604. if (fep->mii_phy_task_queued)
  1605. return;
  1606. fep->mii_phy_task_queued = 1;
  1607. INIT_WORK(&fep->phy_task, mii_display_config);
  1608. schedule_work(&fep->phy_task);
  1609. }
  1610. phy_cmd_t const phy_cmd_relink[] = {
  1611. { mk_mii_read(MII_REG_CR), mii_queue_relink },
  1612. { mk_mii_end, }
  1613. };
  1614. phy_cmd_t const phy_cmd_config[] = {
  1615. { mk_mii_read(MII_REG_CR), mii_queue_config },
  1616. { mk_mii_end, }
  1617. };
  1618. /* Read remainder of PHY ID.
  1619. */
  1620. static void
  1621. mii_discover_phy3(uint mii_reg, struct net_device *dev)
  1622. {
  1623. struct fec_enet_private *fep;
  1624. int i;
  1625. fep = netdev_priv(dev);
  1626. fep->phy_id |= (mii_reg & 0xffff);
  1627. printk("fec: PHY @ 0x%x, ID 0x%08x", fep->phy_addr, fep->phy_id);
  1628. for(i = 0; phy_info[i]; i++) {
  1629. if(phy_info[i]->id == (fep->phy_id >> 4))
  1630. break;
  1631. }
  1632. if (phy_info[i])
  1633. printk(" -- %s\n", phy_info[i]->name);
  1634. else
  1635. printk(" -- unknown PHY!\n");
  1636. fep->phy = phy_info[i];
  1637. fep->phy_id_done = 1;
  1638. }
  1639. /* Scan all of the MII PHY addresses looking for someone to respond
  1640. * with a valid ID. This usually happens quickly.
  1641. */
  1642. static void
  1643. mii_discover_phy(uint mii_reg, struct net_device *dev)
  1644. {
  1645. struct fec_enet_private *fep;
  1646. volatile fec_t *fecp;
  1647. uint phytype;
  1648. fep = netdev_priv(dev);
  1649. fecp = fep->hwp;
  1650. if (fep->phy_addr < 32) {
  1651. if ((phytype = (mii_reg & 0xffff)) != 0xffff && phytype != 0) {
  1652. /* Got first part of ID, now get remainder.
  1653. */
  1654. fep->phy_id = phytype << 16;
  1655. mii_queue(dev, mk_mii_read(MII_REG_PHYIR2),
  1656. mii_discover_phy3);
  1657. } else {
  1658. fep->phy_addr++;
  1659. mii_queue(dev, mk_mii_read(MII_REG_PHYIR1),
  1660. mii_discover_phy);
  1661. }
  1662. } else {
  1663. printk("FEC: No PHY device found.\n");
  1664. /* Disable external MII interface */
  1665. fecp->fec_mii_speed = fep->phy_speed = 0;
  1666. fec_disable_phy_intr();
  1667. }
  1668. }
  1669. /* This interrupt occurs when the PHY detects a link change.
  1670. */
  1671. #ifdef HAVE_mii_link_interrupt
  1672. static irqreturn_t
  1673. mii_link_interrupt(int irq, void * dev_id)
  1674. {
  1675. struct net_device *dev = dev_id;
  1676. struct fec_enet_private *fep = netdev_priv(dev);
  1677. fec_phy_ack_intr();
  1678. #if 0
  1679. disable_irq(fep->mii_irq); /* disable now, enable later */
  1680. #endif
  1681. mii_do_cmd(dev, fep->phy->ack_int);
  1682. mii_do_cmd(dev, phy_cmd_relink); /* restart and display status */
  1683. return IRQ_HANDLED;
  1684. }
  1685. #endif
  1686. static int
  1687. fec_enet_open(struct net_device *dev)
  1688. {
  1689. struct fec_enet_private *fep = netdev_priv(dev);
  1690. /* I should reset the ring buffers here, but I don't yet know
  1691. * a simple way to do that.
  1692. */
  1693. fec_set_mac_address(dev);
  1694. fep->sequence_done = 0;
  1695. fep->link = 0;
  1696. if (fep->phy) {
  1697. mii_do_cmd(dev, fep->phy->ack_int);
  1698. mii_do_cmd(dev, fep->phy->config);
  1699. mii_do_cmd(dev, phy_cmd_config); /* display configuration */
  1700. /* Poll until the PHY tells us its configuration
  1701. * (not link state).
  1702. * Request is initiated by mii_do_cmd above, but answer
  1703. * comes by interrupt.
  1704. * This should take about 25 usec per register at 2.5 MHz,
  1705. * and we read approximately 5 registers.
  1706. */
  1707. while(!fep->sequence_done)
  1708. schedule();
  1709. mii_do_cmd(dev, fep->phy->startup);
  1710. /* Set the initial link state to true. A lot of hardware
  1711. * based on this device does not implement a PHY interrupt,
  1712. * so we are never notified of link change.
  1713. */
  1714. fep->link = 1;
  1715. } else {
  1716. fep->link = 1; /* lets just try it and see */
  1717. /* no phy, go full duplex, it's most likely a hub chip */
  1718. fec_restart(dev, 1);
  1719. }
  1720. netif_start_queue(dev);
  1721. fep->opened = 1;
  1722. return 0; /* Success */
  1723. }
  1724. static int
  1725. fec_enet_close(struct net_device *dev)
  1726. {
  1727. struct fec_enet_private *fep = netdev_priv(dev);
  1728. /* Don't know what to do yet.
  1729. */
  1730. fep->opened = 0;
  1731. netif_stop_queue(dev);
  1732. fec_stop(dev);
  1733. return 0;
  1734. }
  1735. /* Set or clear the multicast filter for this adaptor.
  1736. * Skeleton taken from sunlance driver.
  1737. * The CPM Ethernet implementation allows Multicast as well as individual
  1738. * MAC address filtering. Some of the drivers check to make sure it is
  1739. * a group multicast address, and discard those that are not. I guess I
  1740. * will do the same for now, but just remove the test if you want
  1741. * individual filtering as well (do the upper net layers want or support
  1742. * this kind of feature?).
  1743. */
  1744. #define HASH_BITS 6 /* #bits in hash */
  1745. #define CRC32_POLY 0xEDB88320
  1746. static void set_multicast_list(struct net_device *dev)
  1747. {
  1748. struct fec_enet_private *fep;
  1749. volatile fec_t *ep;
  1750. struct dev_mc_list *dmi;
  1751. unsigned int i, j, bit, data, crc;
  1752. unsigned char hash;
  1753. fep = netdev_priv(dev);
  1754. ep = fep->hwp;
  1755. if (dev->flags&IFF_PROMISC) {
  1756. ep->fec_r_cntrl |= 0x0008;
  1757. } else {
  1758. ep->fec_r_cntrl &= ~0x0008;
  1759. if (dev->flags & IFF_ALLMULTI) {
  1760. /* Catch all multicast addresses, so set the
  1761. * filter to all 1's.
  1762. */
  1763. ep->fec_grp_hash_table_high = 0xffffffff;
  1764. ep->fec_grp_hash_table_low = 0xffffffff;
  1765. } else {
  1766. /* Clear filter and add the addresses in hash register.
  1767. */
  1768. ep->fec_grp_hash_table_high = 0;
  1769. ep->fec_grp_hash_table_low = 0;
  1770. dmi = dev->mc_list;
  1771. for (j = 0; j < dev->mc_count; j++, dmi = dmi->next)
  1772. {
  1773. /* Only support group multicast for now.
  1774. */
  1775. if (!(dmi->dmi_addr[0] & 1))
  1776. continue;
  1777. /* calculate crc32 value of mac address
  1778. */
  1779. crc = 0xffffffff;
  1780. for (i = 0; i < dmi->dmi_addrlen; i++)
  1781. {
  1782. data = dmi->dmi_addr[i];
  1783. for (bit = 0; bit < 8; bit++, data >>= 1)
  1784. {
  1785. crc = (crc >> 1) ^
  1786. (((crc ^ data) & 1) ? CRC32_POLY : 0);
  1787. }
  1788. }
  1789. /* only upper 6 bits (HASH_BITS) are used
  1790. which point to specific bit in he hash registers
  1791. */
  1792. hash = (crc >> (32 - HASH_BITS)) & 0x3f;
  1793. if (hash > 31)
  1794. ep->fec_grp_hash_table_high |= 1 << (hash - 32);
  1795. else
  1796. ep->fec_grp_hash_table_low |= 1 << hash;
  1797. }
  1798. }
  1799. }
  1800. }
  1801. /* Set a MAC change in hardware.
  1802. */
  1803. static void
  1804. fec_set_mac_address(struct net_device *dev)
  1805. {
  1806. volatile fec_t *fecp;
  1807. fecp = ((struct fec_enet_private *)netdev_priv(dev))->hwp;
  1808. /* Set station address. */
  1809. fecp->fec_addr_low = dev->dev_addr[3] | (dev->dev_addr[2] << 8) |
  1810. (dev->dev_addr[1] << 16) | (dev->dev_addr[0] << 24);
  1811. fecp->fec_addr_high = (dev->dev_addr[5] << 16) |
  1812. (dev->dev_addr[4] << 24);
  1813. }
  1814. /* Initialize the FEC Ethernet on 860T (or ColdFire 5272).
  1815. */
  1816. /*
  1817. * XXX: We need to clean up on failure exits here.
  1818. */
  1819. int __init fec_enet_init(struct net_device *dev)
  1820. {
  1821. struct fec_enet_private *fep = netdev_priv(dev);
  1822. unsigned long mem_addr;
  1823. volatile cbd_t *bdp;
  1824. cbd_t *cbd_base;
  1825. volatile fec_t *fecp;
  1826. int i, j;
  1827. static int index = 0;
  1828. /* Only allow us to be probed once. */
  1829. if (index >= FEC_MAX_PORTS)
  1830. return -ENXIO;
  1831. /* Allocate memory for buffer descriptors.
  1832. */
  1833. mem_addr = __get_free_page(GFP_KERNEL);
  1834. if (mem_addr == 0) {
  1835. printk("FEC: allocate descriptor memory failed?\n");
  1836. return -ENOMEM;
  1837. }
  1838. spin_lock_init(&fep->hw_lock);
  1839. spin_lock_init(&fep->mii_lock);
  1840. /* Create an Ethernet device instance.
  1841. */
  1842. fecp = (volatile fec_t *) fec_hw[index];
  1843. fep->index = index;
  1844. fep->hwp = fecp;
  1845. fep->netdev = dev;
  1846. /* Whack a reset. We should wait for this.
  1847. */
  1848. fecp->fec_ecntrl = 1;
  1849. udelay(10);
  1850. /* Set the Ethernet address. If using multiple Enets on the 8xx,
  1851. * this needs some work to get unique addresses.
  1852. *
  1853. * This is our default MAC address unless the user changes
  1854. * it via eth_mac_addr (our dev->set_mac_addr handler).
  1855. */
  1856. fec_get_mac(dev);
  1857. cbd_base = (cbd_t *)mem_addr;
  1858. /* XXX: missing check for allocation failure */
  1859. fec_uncache(mem_addr);
  1860. /* Set receive and transmit descriptor base.
  1861. */
  1862. fep->rx_bd_base = cbd_base;
  1863. fep->tx_bd_base = cbd_base + RX_RING_SIZE;
  1864. fep->dirty_tx = fep->cur_tx = fep->tx_bd_base;
  1865. fep->cur_rx = fep->rx_bd_base;
  1866. fep->skb_cur = fep->skb_dirty = 0;
  1867. /* Initialize the receive buffer descriptors.
  1868. */
  1869. bdp = fep->rx_bd_base;
  1870. for (i=0; i<FEC_ENET_RX_PAGES; i++) {
  1871. /* Allocate a page.
  1872. */
  1873. mem_addr = __get_free_page(GFP_KERNEL);
  1874. /* XXX: missing check for allocation failure */
  1875. fec_uncache(mem_addr);
  1876. /* Initialize the BD for every fragment in the page.
  1877. */
  1878. for (j=0; j<FEC_ENET_RX_FRPPG; j++) {
  1879. bdp->cbd_sc = BD_ENET_RX_EMPTY;
  1880. bdp->cbd_bufaddr = __pa(mem_addr);
  1881. mem_addr += FEC_ENET_RX_FRSIZE;
  1882. bdp++;
  1883. }
  1884. }
  1885. /* Set the last buffer to wrap.
  1886. */
  1887. bdp--;
  1888. bdp->cbd_sc |= BD_SC_WRAP;
  1889. /* ...and the same for transmmit.
  1890. */
  1891. bdp = fep->tx_bd_base;
  1892. for (i=0, j=FEC_ENET_TX_FRPPG; i<TX_RING_SIZE; i++) {
  1893. if (j >= FEC_ENET_TX_FRPPG) {
  1894. mem_addr = __get_free_page(GFP_KERNEL);
  1895. j = 1;
  1896. } else {
  1897. mem_addr += FEC_ENET_TX_FRSIZE;
  1898. j++;
  1899. }
  1900. fep->tx_bounce[i] = (unsigned char *) mem_addr;
  1901. /* Initialize the BD for every fragment in the page.
  1902. */
  1903. bdp->cbd_sc = 0;
  1904. bdp->cbd_bufaddr = 0;
  1905. bdp++;
  1906. }
  1907. /* Set the last buffer to wrap.
  1908. */
  1909. bdp--;
  1910. bdp->cbd_sc |= BD_SC_WRAP;
  1911. /* Set receive and transmit descriptor base.
  1912. */
  1913. fecp->fec_r_des_start = __pa((uint)(fep->rx_bd_base));
  1914. fecp->fec_x_des_start = __pa((uint)(fep->tx_bd_base));
  1915. /* Install our interrupt handlers. This varies depending on
  1916. * the architecture.
  1917. */
  1918. fec_request_intrs(dev);
  1919. fecp->fec_grp_hash_table_high = 0;
  1920. fecp->fec_grp_hash_table_low = 0;
  1921. fecp->fec_r_buff_size = PKT_MAXBLR_SIZE;
  1922. fecp->fec_ecntrl = 2;
  1923. fecp->fec_r_des_active = 0;
  1924. #ifndef CONFIG_M5272
  1925. fecp->fec_hash_table_high = 0;
  1926. fecp->fec_hash_table_low = 0;
  1927. #endif
  1928. dev->base_addr = (unsigned long)fecp;
  1929. /* The FEC Ethernet specific entries in the device structure. */
  1930. dev->open = fec_enet_open;
  1931. dev->hard_start_xmit = fec_enet_start_xmit;
  1932. dev->tx_timeout = fec_timeout;
  1933. dev->watchdog_timeo = TX_TIMEOUT;
  1934. dev->stop = fec_enet_close;
  1935. dev->set_multicast_list = set_multicast_list;
  1936. for (i=0; i<NMII-1; i++)
  1937. mii_cmds[i].mii_next = &mii_cmds[i+1];
  1938. mii_free = mii_cmds;
  1939. /* setup MII interface */
  1940. fec_set_mii(dev, fep);
  1941. /* Clear and enable interrupts */
  1942. fecp->fec_ievent = 0xffc00000;
  1943. fecp->fec_imask = (FEC_ENET_TXF | FEC_ENET_RXF | FEC_ENET_MII);
  1944. /* Queue up command to detect the PHY and initialize the
  1945. * remainder of the interface.
  1946. */
  1947. fep->phy_id_done = 0;
  1948. fep->phy_addr = 0;
  1949. mii_queue(dev, mk_mii_read(MII_REG_PHYIR1), mii_discover_phy);
  1950. index++;
  1951. return 0;
  1952. }
  1953. /* This function is called to start or restart the FEC during a link
  1954. * change. This only happens when switching between half and full
  1955. * duplex.
  1956. */
  1957. static void
  1958. fec_restart(struct net_device *dev, int duplex)
  1959. {
  1960. struct fec_enet_private *fep;
  1961. volatile cbd_t *bdp;
  1962. volatile fec_t *fecp;
  1963. int i;
  1964. fep = netdev_priv(dev);
  1965. fecp = fep->hwp;
  1966. /* Whack a reset. We should wait for this.
  1967. */
  1968. fecp->fec_ecntrl = 1;
  1969. udelay(10);
  1970. /* Clear any outstanding interrupt.
  1971. */
  1972. fecp->fec_ievent = 0xffc00000;
  1973. fec_enable_phy_intr();
  1974. /* Set station address.
  1975. */
  1976. fec_set_mac_address(dev);
  1977. /* Reset all multicast.
  1978. */
  1979. fecp->fec_grp_hash_table_high = 0;
  1980. fecp->fec_grp_hash_table_low = 0;
  1981. /* Set maximum receive buffer size.
  1982. */
  1983. fecp->fec_r_buff_size = PKT_MAXBLR_SIZE;
  1984. fec_localhw_setup();
  1985. /* Set receive and transmit descriptor base.
  1986. */
  1987. fecp->fec_r_des_start = __pa((uint)(fep->rx_bd_base));
  1988. fecp->fec_x_des_start = __pa((uint)(fep->tx_bd_base));
  1989. fep->dirty_tx = fep->cur_tx = fep->tx_bd_base;
  1990. fep->cur_rx = fep->rx_bd_base;
  1991. /* Reset SKB transmit buffers.
  1992. */
  1993. fep->skb_cur = fep->skb_dirty = 0;
  1994. for (i=0; i<=TX_RING_MOD_MASK; i++) {
  1995. if (fep->tx_skbuff[i] != NULL) {
  1996. dev_kfree_skb_any(fep->tx_skbuff[i]);
  1997. fep->tx_skbuff[i] = NULL;
  1998. }
  1999. }
  2000. /* Initialize the receive buffer descriptors.
  2001. */
  2002. bdp = fep->rx_bd_base;
  2003. for (i=0; i<RX_RING_SIZE; i++) {
  2004. /* Initialize the BD for every fragment in the page.
  2005. */
  2006. bdp->cbd_sc = BD_ENET_RX_EMPTY;
  2007. bdp++;
  2008. }
  2009. /* Set the last buffer to wrap.
  2010. */
  2011. bdp--;
  2012. bdp->cbd_sc |= BD_SC_WRAP;
  2013. /* ...and the same for transmmit.
  2014. */
  2015. bdp = fep->tx_bd_base;
  2016. for (i=0; i<TX_RING_SIZE; i++) {
  2017. /* Initialize the BD for every fragment in the page.
  2018. */
  2019. bdp->cbd_sc = 0;
  2020. bdp->cbd_bufaddr = 0;
  2021. bdp++;
  2022. }
  2023. /* Set the last buffer to wrap.
  2024. */
  2025. bdp--;
  2026. bdp->cbd_sc |= BD_SC_WRAP;
  2027. /* Enable MII mode.
  2028. */
  2029. if (duplex) {
  2030. fecp->fec_r_cntrl = OPT_FRAME_SIZE | 0x04;/* MII enable */
  2031. fecp->fec_x_cntrl = 0x04; /* FD enable */
  2032. } else {
  2033. /* MII enable|No Rcv on Xmit */
  2034. fecp->fec_r_cntrl = OPT_FRAME_SIZE | 0x06;
  2035. fecp->fec_x_cntrl = 0x00;
  2036. }
  2037. fep->full_duplex = duplex;
  2038. /* Set MII speed.
  2039. */
  2040. fecp->fec_mii_speed = fep->phy_speed;
  2041. /* And last, enable the transmit and receive processing.
  2042. */
  2043. fecp->fec_ecntrl = 2;
  2044. fecp->fec_r_des_active = 0;
  2045. /* Enable interrupts we wish to service.
  2046. */
  2047. fecp->fec_imask = (FEC_ENET_TXF | FEC_ENET_RXF | FEC_ENET_MII);
  2048. }
  2049. static void
  2050. fec_stop(struct net_device *dev)
  2051. {
  2052. volatile fec_t *fecp;
  2053. struct fec_enet_private *fep;
  2054. fep = netdev_priv(dev);
  2055. fecp = fep->hwp;
  2056. /*
  2057. ** We cannot expect a graceful transmit stop without link !!!
  2058. */
  2059. if (fep->link)
  2060. {
  2061. fecp->fec_x_cntrl = 0x01; /* Graceful transmit stop */
  2062. udelay(10);
  2063. if (!(fecp->fec_ievent & FEC_ENET_GRA))
  2064. printk("fec_stop : Graceful transmit stop did not complete !\n");
  2065. }
  2066. /* Whack a reset. We should wait for this.
  2067. */
  2068. fecp->fec_ecntrl = 1;
  2069. udelay(10);
  2070. /* Clear outstanding MII command interrupts.
  2071. */
  2072. fecp->fec_ievent = FEC_ENET_MII;
  2073. fec_enable_phy_intr();
  2074. fecp->fec_imask = FEC_ENET_MII;
  2075. fecp->fec_mii_speed = fep->phy_speed;
  2076. }
  2077. static int __init fec_enet_module_init(void)
  2078. {
  2079. struct net_device *dev;
  2080. int i, err;
  2081. printk("FEC ENET Version 0.2\n");
  2082. for (i = 0; (i < FEC_MAX_PORTS); i++) {
  2083. dev = alloc_etherdev(sizeof(struct fec_enet_private));
  2084. if (!dev)
  2085. return -ENOMEM;
  2086. err = fec_enet_init(dev);
  2087. if (err) {
  2088. free_netdev(dev);
  2089. continue;
  2090. }
  2091. if (register_netdev(dev) != 0) {
  2092. /* XXX: missing cleanup here */
  2093. free_netdev(dev);
  2094. return -EIO;
  2095. }
  2096. printk("%s: ethernet %pM\n", dev->name, dev->dev_addr);
  2097. }
  2098. return 0;
  2099. }
  2100. module_init(fec_enet_module_init);
  2101. MODULE_LICENSE("GPL");