fec.c 67 KB

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