fec.c 67 KB

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