fec.c 63 KB

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