fec.c 67 KB

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