fec.c 67 KB

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