fec.c 63 KB

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