fec.c 63 KB

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