fec.c 67 KB

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