fcc_enet.c 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395
  1. /*
  2. * Fast Ethernet Controller (FCC) driver for Motorola MPC8260.
  3. * Copyright (c) 2000 MontaVista Software, Inc. Dan Malek (dmalek@jlc.net)
  4. *
  5. * This version of the driver is a combination of the 8xx fec and
  6. * 8260 SCC Ethernet drivers. This version has some additional
  7. * configuration options, which should probably be moved out of
  8. * here. This driver currently works for the EST SBC8260,
  9. * SBS Diablo/BCM, Embedded Planet RPX6, TQM8260, and others.
  10. *
  11. * Right now, I am very watseful 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. Since this is a cache coherent processor and CPM,
  17. * I could also preallocate SKB's and use them directly on the interface.
  18. *
  19. * 2004-12 Leo Li (leoli@freescale.com)
  20. * - Rework the FCC clock configuration part, make it easier to configure.
  21. *
  22. */
  23. #include <linux/config.h>
  24. #include <linux/kernel.h>
  25. #include <linux/sched.h>
  26. #include <linux/string.h>
  27. #include <linux/ptrace.h>
  28. #include <linux/errno.h>
  29. #include <linux/ioport.h>
  30. #include <linux/slab.h>
  31. #include <linux/interrupt.h>
  32. #include <linux/pci.h>
  33. #include <linux/init.h>
  34. #include <linux/delay.h>
  35. #include <linux/netdevice.h>
  36. #include <linux/etherdevice.h>
  37. #include <linux/skbuff.h>
  38. #include <linux/spinlock.h>
  39. #include <linux/mii.h>
  40. #include <linux/workqueue.h>
  41. #include <linux/bitops.h>
  42. #include <asm/immap_cpm2.h>
  43. #include <asm/pgtable.h>
  44. #include <asm/mpc8260.h>
  45. #include <asm/irq.h>
  46. #include <asm/uaccess.h>
  47. #include <asm/signal.h>
  48. /* We can't use the PHY interrupt if we aren't using MDIO. */
  49. #if !defined(CONFIG_USE_MDIO)
  50. #undef PHY_INTERRUPT
  51. #endif
  52. /* If we have a PHY interrupt, we will advertise both full-duplex and half-
  53. * duplex capabilities. If we don't have a PHY interrupt, then we will only
  54. * advertise half-duplex capabilities.
  55. */
  56. #define MII_ADVERTISE_HALF (ADVERTISE_100HALF | ADVERTISE_10HALF | \
  57. ADVERTISE_CSMA)
  58. #define MII_ADVERTISE_ALL (ADVERTISE_100FULL | ADVERTISE_10FULL | \
  59. MII_ADVERTISE_HALF)
  60. #ifdef PHY_INTERRUPT
  61. #define MII_ADVERTISE_DEFAULT MII_ADVERTISE_ALL
  62. #else
  63. #define MII_ADVERTISE_DEFAULT MII_ADVERTISE_HALF
  64. #endif
  65. #include <asm/cpm2.h>
  66. /* The transmitter timeout
  67. */
  68. #define TX_TIMEOUT (2*HZ)
  69. #ifdef CONFIG_USE_MDIO
  70. /* Forward declarations of some structures to support different PHYs */
  71. typedef struct {
  72. uint mii_data;
  73. void (*funct)(uint mii_reg, struct net_device *dev);
  74. } phy_cmd_t;
  75. typedef struct {
  76. uint id;
  77. char *name;
  78. const phy_cmd_t *config;
  79. const phy_cmd_t *startup;
  80. const phy_cmd_t *ack_int;
  81. const phy_cmd_t *shutdown;
  82. } phy_info_t;
  83. /* values for phy_status */
  84. #define PHY_CONF_ANE 0x0001 /* 1 auto-negotiation enabled */
  85. #define PHY_CONF_LOOP 0x0002 /* 1 loopback mode enabled */
  86. #define PHY_CONF_SPMASK 0x00f0 /* mask for speed */
  87. #define PHY_CONF_10HDX 0x0010 /* 10 Mbit half duplex supported */
  88. #define PHY_CONF_10FDX 0x0020 /* 10 Mbit full duplex supported */
  89. #define PHY_CONF_100HDX 0x0040 /* 100 Mbit half duplex supported */
  90. #define PHY_CONF_100FDX 0x0080 /* 100 Mbit full duplex supported */
  91. #define PHY_STAT_LINK 0x0100 /* 1 up - 0 down */
  92. #define PHY_STAT_FAULT 0x0200 /* 1 remote fault */
  93. #define PHY_STAT_ANC 0x0400 /* 1 auto-negotiation complete */
  94. #define PHY_STAT_SPMASK 0xf000 /* mask for speed */
  95. #define PHY_STAT_10HDX 0x1000 /* 10 Mbit half duplex selected */
  96. #define PHY_STAT_10FDX 0x2000 /* 10 Mbit full duplex selected */
  97. #define PHY_STAT_100HDX 0x4000 /* 100 Mbit half duplex selected */
  98. #define PHY_STAT_100FDX 0x8000 /* 100 Mbit full duplex selected */
  99. #endif /* CONFIG_USE_MDIO */
  100. /* The number of Tx and Rx buffers. These are allocated from the page
  101. * pool. The code may assume these are power of two, so it is best
  102. * to keep them that size.
  103. * We don't need to allocate pages for the transmitter. We just use
  104. * the skbuffer directly.
  105. */
  106. #define FCC_ENET_RX_PAGES 16
  107. #define FCC_ENET_RX_FRSIZE 2048
  108. #define FCC_ENET_RX_FRPPG (PAGE_SIZE / FCC_ENET_RX_FRSIZE)
  109. #define RX_RING_SIZE (FCC_ENET_RX_FRPPG * FCC_ENET_RX_PAGES)
  110. #define TX_RING_SIZE 16 /* Must be power of two */
  111. #define TX_RING_MOD_MASK 15 /* for this to work */
  112. /* The FCC stores dest/src/type, data, and checksum for receive packets.
  113. * size includes support for VLAN
  114. */
  115. #define PKT_MAXBUF_SIZE 1522
  116. #define PKT_MINBUF_SIZE 64
  117. /* Maximum input DMA size. Must be a should(?) be a multiple of 4.
  118. * size includes support for VLAN
  119. */
  120. #define PKT_MAXDMA_SIZE 1524
  121. /* Maximum input buffer size. Must be a multiple of 32.
  122. */
  123. #define PKT_MAXBLR_SIZE 1536
  124. static int fcc_enet_open(struct net_device *dev);
  125. static int fcc_enet_start_xmit(struct sk_buff *skb, struct net_device *dev);
  126. static int fcc_enet_rx(struct net_device *dev);
  127. static irqreturn_t fcc_enet_interrupt(int irq, void *dev_id, struct pt_regs *);
  128. static int fcc_enet_close(struct net_device *dev);
  129. static struct net_device_stats *fcc_enet_get_stats(struct net_device *dev);
  130. /* static void set_multicast_list(struct net_device *dev); */
  131. static void fcc_restart(struct net_device *dev, int duplex);
  132. static void fcc_stop(struct net_device *dev);
  133. static int fcc_enet_set_mac_address(struct net_device *dev, void *addr);
  134. /* These will be configurable for the FCC choice.
  135. * Multiple ports can be configured. There is little choice among the
  136. * I/O pins to the PHY, except the clocks. We will need some board
  137. * dependent clock selection.
  138. * Why in the hell did I put these inside #ifdef's? I dunno, maybe to
  139. * help show what pins are used for each device.
  140. */
  141. /* Since the CLK setting changes greatly from board to board, I changed
  142. * it to a easy way. You just need to specify which CLK number to use.
  143. * Note that only limited choices can be make on each port.
  144. */
  145. /* FCC1 Clock Source Configuration. There are board specific.
  146. Can only choose from CLK9-12 */
  147. #ifdef CONFIG_SBC82xx
  148. #define F1_RXCLK 9
  149. #define F1_TXCLK 10
  150. #elif defined(CONFIG_ADS8272)
  151. #define F1_RXCLK 11
  152. #define F1_TXCLK 10
  153. #else
  154. #define F1_RXCLK 12
  155. #define F1_TXCLK 11
  156. #endif
  157. /* FCC2 Clock Source Configuration. There are board specific.
  158. Can only choose from CLK13-16 */
  159. #ifdef CONFIG_ADS8272
  160. #define F2_RXCLK 15
  161. #define F2_TXCLK 16
  162. #else
  163. #define F2_RXCLK 13
  164. #define F2_TXCLK 14
  165. #endif
  166. /* FCC3 Clock Source Configuration. There are board specific.
  167. Can only choose from CLK13-16 */
  168. #define F3_RXCLK 15
  169. #define F3_TXCLK 16
  170. /* Automatically generates register configurations */
  171. #define PC_CLK(x) ((uint)(1<<(x-1))) /* FCC CLK I/O ports */
  172. #define CMXFCR_RF1CS(x) ((uint)((x-5)<<27)) /* FCC1 Receive Clock Source */
  173. #define CMXFCR_TF1CS(x) ((uint)((x-5)<<24)) /* FCC1 Transmit Clock Source */
  174. #define CMXFCR_RF2CS(x) ((uint)((x-9)<<19)) /* FCC2 Receive Clock Source */
  175. #define CMXFCR_TF2CS(x) ((uint)((x-9)<<16)) /* FCC2 Transmit Clock Source */
  176. #define CMXFCR_RF3CS(x) ((uint)((x-9)<<11)) /* FCC3 Receive Clock Source */
  177. #define CMXFCR_TF3CS(x) ((uint)((x-9)<<8)) /* FCC3 Transmit Clock Source */
  178. #define PC_F1RXCLK PC_CLK(F1_RXCLK)
  179. #define PC_F1TXCLK PC_CLK(F1_TXCLK)
  180. #define CMX1_CLK_ROUTE (CMXFCR_RF1CS(F1_RXCLK) | CMXFCR_TF1CS(F1_TXCLK))
  181. #define CMX1_CLK_MASK ((uint)0xff000000)
  182. #define PC_F2RXCLK PC_CLK(F2_RXCLK)
  183. #define PC_F2TXCLK PC_CLK(F2_TXCLK)
  184. #define CMX2_CLK_ROUTE (CMXFCR_RF2CS(F2_RXCLK) | CMXFCR_TF2CS(F2_TXCLK))
  185. #define CMX2_CLK_MASK ((uint)0x00ff0000)
  186. #define PC_F3RXCLK PC_CLK(F3_RXCLK)
  187. #define PC_F3TXCLK PC_CLK(F3_TXCLK)
  188. #define CMX3_CLK_ROUTE (CMXFCR_RF3CS(F3_RXCLK) | CMXFCR_TF3CS(F3_TXCLK))
  189. #define CMX3_CLK_MASK ((uint)0x0000ff00)
  190. /* I/O Pin assignment for FCC1. I don't yet know the best way to do this,
  191. * but there is little variation among the choices.
  192. */
  193. #define PA1_COL ((uint)0x00000001)
  194. #define PA1_CRS ((uint)0x00000002)
  195. #define PA1_TXER ((uint)0x00000004)
  196. #define PA1_TXEN ((uint)0x00000008)
  197. #define PA1_RXDV ((uint)0x00000010)
  198. #define PA1_RXER ((uint)0x00000020)
  199. #define PA1_TXDAT ((uint)0x00003c00)
  200. #define PA1_RXDAT ((uint)0x0003c000)
  201. #define PA1_PSORA_BOUT (PA1_RXDAT | PA1_TXDAT)
  202. #define PA1_PSORA_BIN (PA1_COL | PA1_CRS | PA1_TXER | PA1_TXEN | \
  203. PA1_RXDV | PA1_RXER)
  204. #define PA1_DIRA_BOUT (PA1_RXDAT | PA1_CRS | PA1_COL | PA1_RXER | PA1_RXDV)
  205. #define PA1_DIRA_BIN (PA1_TXDAT | PA1_TXEN | PA1_TXER)
  206. /* I/O Pin assignment for FCC2. I don't yet know the best way to do this,
  207. * but there is little variation among the choices.
  208. */
  209. #define PB2_TXER ((uint)0x00000001)
  210. #define PB2_RXDV ((uint)0x00000002)
  211. #define PB2_TXEN ((uint)0x00000004)
  212. #define PB2_RXER ((uint)0x00000008)
  213. #define PB2_COL ((uint)0x00000010)
  214. #define PB2_CRS ((uint)0x00000020)
  215. #define PB2_TXDAT ((uint)0x000003c0)
  216. #define PB2_RXDAT ((uint)0x00003c00)
  217. #define PB2_PSORB_BOUT (PB2_RXDAT | PB2_TXDAT | PB2_CRS | PB2_COL | \
  218. PB2_RXER | PB2_RXDV | PB2_TXER)
  219. #define PB2_PSORB_BIN (PB2_TXEN)
  220. #define PB2_DIRB_BOUT (PB2_RXDAT | PB2_CRS | PB2_COL | PB2_RXER | PB2_RXDV)
  221. #define PB2_DIRB_BIN (PB2_TXDAT | PB2_TXEN | PB2_TXER)
  222. /* I/O Pin assignment for FCC3. I don't yet know the best way to do this,
  223. * but there is little variation among the choices.
  224. */
  225. #define PB3_RXDV ((uint)0x00004000)
  226. #define PB3_RXER ((uint)0x00008000)
  227. #define PB3_TXER ((uint)0x00010000)
  228. #define PB3_TXEN ((uint)0x00020000)
  229. #define PB3_COL ((uint)0x00040000)
  230. #define PB3_CRS ((uint)0x00080000)
  231. #ifndef CONFIG_RPX8260
  232. #define PB3_TXDAT ((uint)0x0f000000)
  233. #define PC3_TXDAT ((uint)0x00000000)
  234. #else
  235. #define PB3_TXDAT ((uint)0x0f000000)
  236. #define PC3_TXDAT 0
  237. #endif
  238. #define PB3_RXDAT ((uint)0x00f00000)
  239. #define PB3_PSORB_BOUT (PB3_RXDAT | PB3_TXDAT | PB3_CRS | PB3_COL | \
  240. PB3_RXER | PB3_RXDV | PB3_TXER | PB3_TXEN)
  241. #define PB3_PSORB_BIN (0)
  242. #define PB3_DIRB_BOUT (PB3_RXDAT | PB3_CRS | PB3_COL | PB3_RXER | PB3_RXDV)
  243. #define PB3_DIRB_BIN (PB3_TXDAT | PB3_TXEN | PB3_TXER)
  244. #define PC3_PSORC_BOUT (PC3_TXDAT)
  245. #define PC3_PSORC_BIN (0)
  246. #define PC3_DIRC_BOUT (0)
  247. #define PC3_DIRC_BIN (PC3_TXDAT)
  248. /* MII status/control serial interface.
  249. */
  250. #if defined(CONFIG_RPX8260)
  251. /* The EP8260 doesn't use Port C for MDIO */
  252. #define PC_MDIO ((uint)0x00000000)
  253. #define PC_MDCK ((uint)0x00000000)
  254. #elif defined(CONFIG_TQM8260)
  255. /* TQM8260 has MDIO and MDCK on PC30 and PC31 respectively */
  256. #define PC_MDIO ((uint)0x00000002)
  257. #define PC_MDCK ((uint)0x00000001)
  258. #elif defined(CONFIG_ADS8272)
  259. #define PC_MDIO ((uint)0x00002000)
  260. #define PC_MDCK ((uint)0x00001000)
  261. #elif defined(CONFIG_EST8260) || defined(CONFIG_ADS8260) || defined(CONFIG_PQ2FADS)
  262. #define PC_MDIO ((uint)0x00400000)
  263. #define PC_MDCK ((uint)0x00200000)
  264. #else
  265. #define PC_MDIO ((uint)0x00000004)
  266. #define PC_MDCK ((uint)0x00000020)
  267. #endif
  268. #if defined(CONFIG_USE_MDIO) && (!defined(PC_MDIO) || !defined(PC_MDCK))
  269. #error "Must define PC_MDIO and PC_MDCK if using MDIO"
  270. #endif
  271. /* PHY addresses */
  272. /* default to dynamic config of phy addresses */
  273. #define FCC1_PHY_ADDR 0
  274. #ifdef CONFIG_PQ2FADS
  275. #define FCC2_PHY_ADDR 0
  276. #else
  277. #define FCC2_PHY_ADDR 2
  278. #endif
  279. #define FCC3_PHY_ADDR 3
  280. /* A table of information for supporting FCCs. This does two things.
  281. * First, we know how many FCCs we have and they are always externally
  282. * numbered from zero. Second, it holds control register and I/O
  283. * information that could be different among board designs.
  284. */
  285. typedef struct fcc_info {
  286. uint fc_fccnum;
  287. uint fc_phyaddr;
  288. uint fc_cpmblock;
  289. uint fc_cpmpage;
  290. uint fc_proff;
  291. uint fc_interrupt;
  292. uint fc_trxclocks;
  293. uint fc_clockroute;
  294. uint fc_clockmask;
  295. uint fc_mdio;
  296. uint fc_mdck;
  297. } fcc_info_t;
  298. static fcc_info_t fcc_ports[] = {
  299. #ifdef CONFIG_FCC1_ENET
  300. { 0, FCC1_PHY_ADDR, CPM_CR_FCC1_SBLOCK, CPM_CR_FCC1_PAGE, PROFF_FCC1, SIU_INT_FCC1,
  301. (PC_F1RXCLK | PC_F1TXCLK), CMX1_CLK_ROUTE, CMX1_CLK_MASK,
  302. PC_MDIO, PC_MDCK },
  303. #endif
  304. #ifdef CONFIG_FCC2_ENET
  305. { 1, FCC2_PHY_ADDR, CPM_CR_FCC2_SBLOCK, CPM_CR_FCC2_PAGE, PROFF_FCC2, SIU_INT_FCC2,
  306. (PC_F2RXCLK | PC_F2TXCLK), CMX2_CLK_ROUTE, CMX2_CLK_MASK,
  307. PC_MDIO, PC_MDCK },
  308. #endif
  309. #ifdef CONFIG_FCC3_ENET
  310. { 2, FCC3_PHY_ADDR, CPM_CR_FCC3_SBLOCK, CPM_CR_FCC3_PAGE, PROFF_FCC3, SIU_INT_FCC3,
  311. (PC_F3RXCLK | PC_F3TXCLK), CMX3_CLK_ROUTE, CMX3_CLK_MASK,
  312. PC_MDIO, PC_MDCK },
  313. #endif
  314. };
  315. /* The FCC buffer descriptors track the ring buffers. The rx_bd_base and
  316. * tx_bd_base always point to the base of the buffer descriptors. The
  317. * cur_rx and cur_tx point to the currently available buffer.
  318. * The dirty_tx tracks the current buffer that is being sent by the
  319. * controller. The cur_tx and dirty_tx are equal under both completely
  320. * empty and completely full conditions. The empty/ready indicator in
  321. * the buffer descriptor determines the actual condition.
  322. */
  323. struct fcc_enet_private {
  324. /* The saved address of a sent-in-place packet/buffer, for skfree(). */
  325. struct sk_buff* tx_skbuff[TX_RING_SIZE];
  326. ushort skb_cur;
  327. ushort skb_dirty;
  328. /* CPM dual port RAM relative addresses.
  329. */
  330. cbd_t *rx_bd_base; /* Address of Rx and Tx buffers. */
  331. cbd_t *tx_bd_base;
  332. cbd_t *cur_rx, *cur_tx; /* The next free ring entry */
  333. cbd_t *dirty_tx; /* The ring entries to be free()ed. */
  334. volatile fcc_t *fccp;
  335. volatile fcc_enet_t *ep;
  336. struct net_device_stats stats;
  337. uint tx_free;
  338. spinlock_t lock;
  339. #ifdef CONFIG_USE_MDIO
  340. uint phy_id;
  341. uint phy_id_done;
  342. uint phy_status;
  343. phy_info_t *phy;
  344. struct work_struct phy_relink;
  345. struct work_struct phy_display_config;
  346. uint sequence_done;
  347. uint phy_addr;
  348. #endif /* CONFIG_USE_MDIO */
  349. int link;
  350. int old_link;
  351. int full_duplex;
  352. fcc_info_t *fip;
  353. };
  354. static void init_fcc_shutdown(fcc_info_t *fip, struct fcc_enet_private *cep,
  355. volatile cpm2_map_t *immap);
  356. static void init_fcc_startup(fcc_info_t *fip, struct net_device *dev);
  357. static void init_fcc_ioports(fcc_info_t *fip, volatile iop_cpm2_t *io,
  358. volatile cpm2_map_t *immap);
  359. static void init_fcc_param(fcc_info_t *fip, struct net_device *dev,
  360. volatile cpm2_map_t *immap);
  361. #ifdef CONFIG_USE_MDIO
  362. static int mii_queue(struct net_device *dev, int request, void (*func)(uint, struct net_device *));
  363. static uint mii_send_receive(fcc_info_t *fip, uint cmd);
  364. static void mii_do_cmd(struct net_device *dev, const phy_cmd_t *c);
  365. /* Make MII read/write commands for the FCC.
  366. */
  367. #define mk_mii_read(REG) (0x60020000 | (((REG) & 0x1f) << 18))
  368. #define mk_mii_write(REG, VAL) (0x50020000 | (((REG) & 0x1f) << 18) | \
  369. ((VAL) & 0xffff))
  370. #define mk_mii_end 0
  371. #endif /* CONFIG_USE_MDIO */
  372. static int
  373. fcc_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
  374. {
  375. struct fcc_enet_private *cep = (struct fcc_enet_private *)dev->priv;
  376. volatile cbd_t *bdp;
  377. /* Fill in a Tx ring entry */
  378. bdp = cep->cur_tx;
  379. #ifndef final_version
  380. if (!cep->tx_free || (bdp->cbd_sc & BD_ENET_TX_READY)) {
  381. /* Ooops. All transmit buffers are full. Bail out.
  382. * This should not happen, since the tx queue should be stopped.
  383. */
  384. printk("%s: tx queue full!.\n", dev->name);
  385. return 1;
  386. }
  387. #endif
  388. /* Clear all of the status flags. */
  389. bdp->cbd_sc &= ~BD_ENET_TX_STATS;
  390. /* If the frame is short, tell CPM to pad it. */
  391. if (skb->len <= ETH_ZLEN)
  392. bdp->cbd_sc |= BD_ENET_TX_PAD;
  393. else
  394. bdp->cbd_sc &= ~BD_ENET_TX_PAD;
  395. /* Set buffer length and buffer pointer. */
  396. bdp->cbd_datlen = skb->len;
  397. bdp->cbd_bufaddr = __pa(skb->data);
  398. spin_lock_irq(&cep->lock);
  399. /* Save skb pointer. */
  400. cep->tx_skbuff[cep->skb_cur] = skb;
  401. cep->stats.tx_bytes += skb->len;
  402. cep->skb_cur = (cep->skb_cur+1) & TX_RING_MOD_MASK;
  403. /* Send it on its way. Tell CPM its ready, interrupt when done,
  404. * its the last BD of the frame, and to put the CRC on the end.
  405. */
  406. bdp->cbd_sc |= (BD_ENET_TX_READY | BD_ENET_TX_INTR | BD_ENET_TX_LAST | BD_ENET_TX_TC);
  407. #if 0
  408. /* Errata says don't do this. */
  409. cep->fccp->fcc_ftodr = 0x8000;
  410. #endif
  411. dev->trans_start = jiffies;
  412. /* If this was the last BD in the ring, start at the beginning again. */
  413. if (bdp->cbd_sc & BD_ENET_TX_WRAP)
  414. bdp = cep->tx_bd_base;
  415. else
  416. bdp++;
  417. if (!--cep->tx_free)
  418. netif_stop_queue(dev);
  419. cep->cur_tx = (cbd_t *)bdp;
  420. spin_unlock_irq(&cep->lock);
  421. return 0;
  422. }
  423. static void
  424. fcc_enet_timeout(struct net_device *dev)
  425. {
  426. struct fcc_enet_private *cep = (struct fcc_enet_private *)dev->priv;
  427. printk("%s: transmit timed out.\n", dev->name);
  428. cep->stats.tx_errors++;
  429. #ifndef final_version
  430. {
  431. int i;
  432. cbd_t *bdp;
  433. printk(" Ring data dump: cur_tx %p tx_free %d cur_rx %p.\n",
  434. cep->cur_tx, cep->tx_free,
  435. cep->cur_rx);
  436. bdp = cep->tx_bd_base;
  437. printk(" Tx @base %p :\n", bdp);
  438. for (i = 0 ; i < TX_RING_SIZE; i++, bdp++)
  439. printk("%04x %04x %08x\n",
  440. bdp->cbd_sc,
  441. bdp->cbd_datlen,
  442. bdp->cbd_bufaddr);
  443. bdp = cep->rx_bd_base;
  444. printk(" Rx @base %p :\n", bdp);
  445. for (i = 0 ; i < RX_RING_SIZE; i++, bdp++)
  446. printk("%04x %04x %08x\n",
  447. bdp->cbd_sc,
  448. bdp->cbd_datlen,
  449. bdp->cbd_bufaddr);
  450. }
  451. #endif
  452. if (cep->tx_free)
  453. netif_wake_queue(dev);
  454. }
  455. /* The interrupt handler. */
  456. static irqreturn_t
  457. fcc_enet_interrupt(int irq, void * dev_id, struct pt_regs * regs)
  458. {
  459. struct net_device *dev = dev_id;
  460. volatile struct fcc_enet_private *cep;
  461. volatile cbd_t *bdp;
  462. ushort int_events;
  463. int must_restart;
  464. cep = (struct fcc_enet_private *)dev->priv;
  465. /* Get the interrupt events that caused us to be here.
  466. */
  467. int_events = cep->fccp->fcc_fcce;
  468. cep->fccp->fcc_fcce = (int_events & cep->fccp->fcc_fccm);
  469. must_restart = 0;
  470. #ifdef PHY_INTERRUPT
  471. /* We have to be careful here to make sure that we aren't
  472. * interrupted by a PHY interrupt.
  473. */
  474. disable_irq_nosync(PHY_INTERRUPT);
  475. #endif
  476. /* Handle receive event in its own function.
  477. */
  478. if (int_events & FCC_ENET_RXF)
  479. fcc_enet_rx(dev_id);
  480. /* Check for a transmit error. The manual is a little unclear
  481. * about this, so the debug code until I get it figured out. It
  482. * appears that if TXE is set, then TXB is not set. However,
  483. * if carrier sense is lost during frame transmission, the TXE
  484. * bit is set, "and continues the buffer transmission normally."
  485. * I don't know if "normally" implies TXB is set when the buffer
  486. * descriptor is closed.....trial and error :-).
  487. */
  488. /* Transmit OK, or non-fatal error. Update the buffer descriptors.
  489. */
  490. if (int_events & (FCC_ENET_TXE | FCC_ENET_TXB)) {
  491. spin_lock(&cep->lock);
  492. bdp = cep->dirty_tx;
  493. while ((bdp->cbd_sc&BD_ENET_TX_READY)==0) {
  494. if (cep->tx_free == TX_RING_SIZE)
  495. break;
  496. if (bdp->cbd_sc & BD_ENET_TX_HB) /* No heartbeat */
  497. cep->stats.tx_heartbeat_errors++;
  498. if (bdp->cbd_sc & BD_ENET_TX_LC) /* Late collision */
  499. cep->stats.tx_window_errors++;
  500. if (bdp->cbd_sc & BD_ENET_TX_RL) /* Retrans limit */
  501. cep->stats.tx_aborted_errors++;
  502. if (bdp->cbd_sc & BD_ENET_TX_UN) /* Underrun */
  503. cep->stats.tx_fifo_errors++;
  504. if (bdp->cbd_sc & BD_ENET_TX_CSL) /* Carrier lost */
  505. cep->stats.tx_carrier_errors++;
  506. /* No heartbeat or Lost carrier are not really bad errors.
  507. * The others require a restart transmit command.
  508. */
  509. if (bdp->cbd_sc &
  510. (BD_ENET_TX_LC | BD_ENET_TX_RL | BD_ENET_TX_UN)) {
  511. must_restart = 1;
  512. cep->stats.tx_errors++;
  513. }
  514. cep->stats.tx_packets++;
  515. /* Deferred means some collisions occurred during transmit,
  516. * but we eventually sent the packet OK.
  517. */
  518. if (bdp->cbd_sc & BD_ENET_TX_DEF)
  519. cep->stats.collisions++;
  520. /* Free the sk buffer associated with this last transmit. */
  521. dev_kfree_skb_irq(cep->tx_skbuff[cep->skb_dirty]);
  522. cep->tx_skbuff[cep->skb_dirty] = NULL;
  523. cep->skb_dirty = (cep->skb_dirty + 1) & TX_RING_MOD_MASK;
  524. /* Update pointer to next buffer descriptor to be transmitted. */
  525. if (bdp->cbd_sc & BD_ENET_TX_WRAP)
  526. bdp = cep->tx_bd_base;
  527. else
  528. bdp++;
  529. /* I don't know if we can be held off from processing these
  530. * interrupts for more than one frame time. I really hope
  531. * not. In such a case, we would now want to check the
  532. * currently available BD (cur_tx) and determine if any
  533. * buffers between the dirty_tx and cur_tx have also been
  534. * sent. We would want to process anything in between that
  535. * does not have BD_ENET_TX_READY set.
  536. */
  537. /* Since we have freed up a buffer, the ring is no longer
  538. * full.
  539. */
  540. if (!cep->tx_free++) {
  541. if (netif_queue_stopped(dev)) {
  542. netif_wake_queue(dev);
  543. }
  544. }
  545. cep->dirty_tx = (cbd_t *)bdp;
  546. }
  547. if (must_restart) {
  548. volatile cpm_cpm2_t *cp;
  549. /* Some transmit errors cause the transmitter to shut
  550. * down. We now issue a restart transmit. Since the
  551. * errors close the BD and update the pointers, the restart
  552. * _should_ pick up without having to reset any of our
  553. * pointers either. Also, To workaround 8260 device erratum
  554. * CPM37, we must disable and then re-enable the transmitter
  555. * following a Late Collision, Underrun, or Retry Limit error.
  556. */
  557. cep->fccp->fcc_gfmr &= ~FCC_GFMR_ENT;
  558. udelay(10); /* wait a few microseconds just on principle */
  559. cep->fccp->fcc_gfmr |= FCC_GFMR_ENT;
  560. cp = cpmp;
  561. cp->cp_cpcr =
  562. mk_cr_cmd(cep->fip->fc_cpmpage, cep->fip->fc_cpmblock,
  563. 0x0c, CPM_CR_RESTART_TX) | CPM_CR_FLG;
  564. while (cp->cp_cpcr & CPM_CR_FLG);
  565. }
  566. spin_unlock(&cep->lock);
  567. }
  568. /* Check for receive busy, i.e. packets coming but no place to
  569. * put them.
  570. */
  571. if (int_events & FCC_ENET_BSY) {
  572. cep->fccp->fcc_fcce = FCC_ENET_BSY;
  573. cep->stats.rx_dropped++;
  574. }
  575. #ifdef PHY_INTERRUPT
  576. enable_irq(PHY_INTERRUPT);
  577. #endif
  578. return IRQ_HANDLED;
  579. }
  580. /* During a receive, the cur_rx points to the current incoming buffer.
  581. * When we update through the ring, if the next incoming buffer has
  582. * not been given to the system, we just set the empty indicator,
  583. * effectively tossing the packet.
  584. */
  585. static int
  586. fcc_enet_rx(struct net_device *dev)
  587. {
  588. struct fcc_enet_private *cep;
  589. volatile cbd_t *bdp;
  590. struct sk_buff *skb;
  591. ushort pkt_len;
  592. cep = (struct fcc_enet_private *)dev->priv;
  593. /* First, grab all of the stats for the incoming packet.
  594. * These get messed up if we get called due to a busy condition.
  595. */
  596. bdp = cep->cur_rx;
  597. for (;;) {
  598. if (bdp->cbd_sc & BD_ENET_RX_EMPTY)
  599. break;
  600. #ifndef final_version
  601. /* Since we have allocated space to hold a complete frame, both
  602. * the first and last indicators should be set.
  603. */
  604. if ((bdp->cbd_sc & (BD_ENET_RX_FIRST | BD_ENET_RX_LAST)) !=
  605. (BD_ENET_RX_FIRST | BD_ENET_RX_LAST))
  606. printk("CPM ENET: rcv is not first+last\n");
  607. #endif
  608. /* Frame too long or too short. */
  609. if (bdp->cbd_sc & (BD_ENET_RX_LG | BD_ENET_RX_SH))
  610. cep->stats.rx_length_errors++;
  611. if (bdp->cbd_sc & BD_ENET_RX_NO) /* Frame alignment */
  612. cep->stats.rx_frame_errors++;
  613. if (bdp->cbd_sc & BD_ENET_RX_CR) /* CRC Error */
  614. cep->stats.rx_crc_errors++;
  615. if (bdp->cbd_sc & BD_ENET_RX_OV) /* FIFO overrun */
  616. cep->stats.rx_crc_errors++;
  617. if (bdp->cbd_sc & BD_ENET_RX_CL) /* Late Collision */
  618. cep->stats.rx_frame_errors++;
  619. if (!(bdp->cbd_sc &
  620. (BD_ENET_RX_LG | BD_ENET_RX_SH | BD_ENET_RX_NO | BD_ENET_RX_CR
  621. | BD_ENET_RX_OV | BD_ENET_RX_CL)))
  622. {
  623. /* Process the incoming frame. */
  624. cep->stats.rx_packets++;
  625. /* Remove the FCS from the packet length. */
  626. pkt_len = bdp->cbd_datlen - 4;
  627. cep->stats.rx_bytes += pkt_len;
  628. /* This does 16 byte alignment, much more than we need. */
  629. skb = dev_alloc_skb(pkt_len);
  630. if (skb == NULL) {
  631. printk("%s: Memory squeeze, dropping packet.\n", dev->name);
  632. cep->stats.rx_dropped++;
  633. }
  634. else {
  635. skb->dev = dev;
  636. skb_put(skb,pkt_len); /* Make room */
  637. eth_copy_and_sum(skb,
  638. (unsigned char *)__va(bdp->cbd_bufaddr),
  639. pkt_len, 0);
  640. skb->protocol=eth_type_trans(skb,dev);
  641. netif_rx(skb);
  642. }
  643. }
  644. /* Clear the status flags for this buffer. */
  645. bdp->cbd_sc &= ~BD_ENET_RX_STATS;
  646. /* Mark the buffer empty. */
  647. bdp->cbd_sc |= BD_ENET_RX_EMPTY;
  648. /* Update BD pointer to next entry. */
  649. if (bdp->cbd_sc & BD_ENET_RX_WRAP)
  650. bdp = cep->rx_bd_base;
  651. else
  652. bdp++;
  653. }
  654. cep->cur_rx = (cbd_t *)bdp;
  655. return 0;
  656. }
  657. static int
  658. fcc_enet_close(struct net_device *dev)
  659. {
  660. #ifdef CONFIG_USE_MDIO
  661. struct fcc_enet_private *fep = dev->priv;
  662. #endif
  663. netif_stop_queue(dev);
  664. fcc_stop(dev);
  665. #ifdef CONFIG_USE_MDIO
  666. if (fep->phy)
  667. mii_do_cmd(dev, fep->phy->shutdown);
  668. #endif
  669. return 0;
  670. }
  671. static struct net_device_stats *fcc_enet_get_stats(struct net_device *dev)
  672. {
  673. struct fcc_enet_private *cep = (struct fcc_enet_private *)dev->priv;
  674. return &cep->stats;
  675. }
  676. #ifdef CONFIG_USE_MDIO
  677. /* NOTE: Most of the following comes from the FEC driver for 860. The
  678. * overall structure of MII code has been retained (as it's proved stable
  679. * and well-tested), but actual transfer requests are processed "at once"
  680. * instead of being queued (there's no interrupt-driven MII transfer
  681. * mechanism, one has to toggle the data/clock bits manually).
  682. */
  683. static int
  684. mii_queue(struct net_device *dev, int regval, void (*func)(uint, struct net_device *))
  685. {
  686. struct fcc_enet_private *fep;
  687. int retval, tmp;
  688. /* Add PHY address to register command. */
  689. fep = dev->priv;
  690. regval |= fep->phy_addr << 23;
  691. retval = 0;
  692. tmp = mii_send_receive(fep->fip, regval);
  693. if (func)
  694. func(tmp, dev);
  695. return retval;
  696. }
  697. static void mii_do_cmd(struct net_device *dev, const phy_cmd_t *c)
  698. {
  699. int k;
  700. if(!c)
  701. return;
  702. for(k = 0; (c+k)->mii_data != mk_mii_end; k++)
  703. mii_queue(dev, (c+k)->mii_data, (c+k)->funct);
  704. }
  705. static void mii_parse_sr(uint mii_reg, struct net_device *dev)
  706. {
  707. volatile struct fcc_enet_private *fep = dev->priv;
  708. uint s = fep->phy_status;
  709. s &= ~(PHY_STAT_LINK | PHY_STAT_FAULT | PHY_STAT_ANC);
  710. if (mii_reg & BMSR_LSTATUS)
  711. s |= PHY_STAT_LINK;
  712. if (mii_reg & BMSR_RFAULT)
  713. s |= PHY_STAT_FAULT;
  714. if (mii_reg & BMSR_ANEGCOMPLETE)
  715. s |= PHY_STAT_ANC;
  716. fep->phy_status = s;
  717. }
  718. static void mii_parse_cr(uint mii_reg, struct net_device *dev)
  719. {
  720. volatile struct fcc_enet_private *fep = dev->priv;
  721. uint s = fep->phy_status;
  722. s &= ~(PHY_CONF_ANE | PHY_CONF_LOOP);
  723. if (mii_reg & BMCR_ANENABLE)
  724. s |= PHY_CONF_ANE;
  725. if (mii_reg & BMCR_LOOPBACK)
  726. s |= PHY_CONF_LOOP;
  727. fep->phy_status = s;
  728. }
  729. static void mii_parse_anar(uint mii_reg, struct net_device *dev)
  730. {
  731. volatile struct fcc_enet_private *fep = dev->priv;
  732. uint s = fep->phy_status;
  733. s &= ~(PHY_CONF_SPMASK);
  734. if (mii_reg & ADVERTISE_10HALF)
  735. s |= PHY_CONF_10HDX;
  736. if (mii_reg & ADVERTISE_10FULL)
  737. s |= PHY_CONF_10FDX;
  738. if (mii_reg & ADVERTISE_100HALF)
  739. s |= PHY_CONF_100HDX;
  740. if (mii_reg & ADVERTISE_100FULL)
  741. s |= PHY_CONF_100FDX;
  742. fep->phy_status = s;
  743. }
  744. /* ------------------------------------------------------------------------- */
  745. /* Generic PHY support. Should work for all PHYs, but does not support link
  746. * change interrupts.
  747. */
  748. #ifdef CONFIG_FCC_GENERIC_PHY
  749. static phy_info_t phy_info_generic = {
  750. 0x00000000, /* 0-->match any PHY */
  751. "GENERIC",
  752. (const phy_cmd_t []) { /* config */
  753. /* advertise only half-duplex capabilities */
  754. { mk_mii_write(MII_ADVERTISE, MII_ADVERTISE_HALF),
  755. mii_parse_anar },
  756. /* enable auto-negotiation */
  757. { mk_mii_write(MII_BMCR, BMCR_ANENABLE), mii_parse_cr },
  758. { mk_mii_end, }
  759. },
  760. (const phy_cmd_t []) { /* startup */
  761. /* restart auto-negotiation */
  762. { mk_mii_write(MII_BMCR, BMCR_ANENABLE | BMCR_ANRESTART),
  763. NULL },
  764. { mk_mii_end, }
  765. },
  766. (const phy_cmd_t []) { /* ack_int */
  767. /* We don't actually use the ack_int table with a generic
  768. * PHY, but putting a reference to mii_parse_sr here keeps
  769. * us from getting a compiler warning about unused static
  770. * functions in the case where we only compile in generic
  771. * PHY support.
  772. */
  773. { mk_mii_read(MII_BMSR), mii_parse_sr },
  774. { mk_mii_end, }
  775. },
  776. (const phy_cmd_t []) { /* shutdown */
  777. { mk_mii_end, }
  778. },
  779. };
  780. #endif /* ifdef CONFIG_FCC_GENERIC_PHY */
  781. /* ------------------------------------------------------------------------- */
  782. /* The Level one LXT970 is used by many boards */
  783. #ifdef CONFIG_FCC_LXT970
  784. #define MII_LXT970_MIRROR 16 /* Mirror register */
  785. #define MII_LXT970_IER 17 /* Interrupt Enable Register */
  786. #define MII_LXT970_ISR 18 /* Interrupt Status Register */
  787. #define MII_LXT970_CONFIG 19 /* Configuration Register */
  788. #define MII_LXT970_CSR 20 /* Chip Status Register */
  789. static void mii_parse_lxt970_csr(uint mii_reg, struct net_device *dev)
  790. {
  791. volatile struct fcc_enet_private *fep = dev->priv;
  792. uint s = fep->phy_status;
  793. s &= ~(PHY_STAT_SPMASK);
  794. if (mii_reg & 0x0800) {
  795. if (mii_reg & 0x1000)
  796. s |= PHY_STAT_100FDX;
  797. else
  798. s |= PHY_STAT_100HDX;
  799. } else {
  800. if (mii_reg & 0x1000)
  801. s |= PHY_STAT_10FDX;
  802. else
  803. s |= PHY_STAT_10HDX;
  804. }
  805. fep->phy_status = s;
  806. }
  807. static phy_info_t phy_info_lxt970 = {
  808. 0x07810000,
  809. "LXT970",
  810. (const phy_cmd_t []) { /* config */
  811. #if 0
  812. // { mk_mii_write(MII_ADVERTISE, 0x0021), NULL },
  813. /* Set default operation of 100-TX....for some reason
  814. * some of these bits are set on power up, which is wrong.
  815. */
  816. { mk_mii_write(MII_LXT970_CONFIG, 0), NULL },
  817. #endif
  818. { mk_mii_read(MII_BMCR), mii_parse_cr },
  819. { mk_mii_read(MII_ADVERTISE), mii_parse_anar },
  820. { mk_mii_end, }
  821. },
  822. (const phy_cmd_t []) { /* startup - enable interrupts */
  823. { mk_mii_write(MII_LXT970_IER, 0x0002), NULL },
  824. { mk_mii_write(MII_BMCR, 0x1200), NULL }, /* autonegotiate */
  825. { mk_mii_end, }
  826. },
  827. (const phy_cmd_t []) { /* ack_int */
  828. /* read SR and ISR to acknowledge */
  829. { mk_mii_read(MII_BMSR), mii_parse_sr },
  830. { mk_mii_read(MII_LXT970_ISR), NULL },
  831. /* find out the current status */
  832. { mk_mii_read(MII_LXT970_CSR), mii_parse_lxt970_csr },
  833. { mk_mii_end, }
  834. },
  835. (const phy_cmd_t []) { /* shutdown - disable interrupts */
  836. { mk_mii_write(MII_LXT970_IER, 0x0000), NULL },
  837. { mk_mii_end, }
  838. },
  839. };
  840. #endif /* CONFIG_FEC_LXT970 */
  841. /* ------------------------------------------------------------------------- */
  842. /* The Level one LXT971 is used on some of my custom boards */
  843. #ifdef CONFIG_FCC_LXT971
  844. /* register definitions for the 971 */
  845. #define MII_LXT971_PCR 16 /* Port Control Register */
  846. #define MII_LXT971_SR2 17 /* Status Register 2 */
  847. #define MII_LXT971_IER 18 /* Interrupt Enable Register */
  848. #define MII_LXT971_ISR 19 /* Interrupt Status Register */
  849. #define MII_LXT971_LCR 20 /* LED Control Register */
  850. #define MII_LXT971_TCR 30 /* Transmit Control Register */
  851. /*
  852. * I had some nice ideas of running the MDIO faster...
  853. * The 971 should support 8MHz and I tried it, but things acted really
  854. * weird, so 2.5 MHz ought to be enough for anyone...
  855. */
  856. static void mii_parse_lxt971_sr2(uint mii_reg, struct net_device *dev)
  857. {
  858. volatile struct fcc_enet_private *fep = dev->priv;
  859. uint s = fep->phy_status;
  860. s &= ~(PHY_STAT_SPMASK);
  861. if (mii_reg & 0x4000) {
  862. if (mii_reg & 0x0200)
  863. s |= PHY_STAT_100FDX;
  864. else
  865. s |= PHY_STAT_100HDX;
  866. } else {
  867. if (mii_reg & 0x0200)
  868. s |= PHY_STAT_10FDX;
  869. else
  870. s |= PHY_STAT_10HDX;
  871. }
  872. if (mii_reg & 0x0008)
  873. s |= PHY_STAT_FAULT;
  874. fep->phy_status = s;
  875. }
  876. static phy_info_t phy_info_lxt971 = {
  877. 0x0001378e,
  878. "LXT971",
  879. (const phy_cmd_t []) { /* config */
  880. /* configure link capabilities to advertise */
  881. { mk_mii_write(MII_ADVERTISE, MII_ADVERTISE_DEFAULT),
  882. mii_parse_anar },
  883. /* enable auto-negotiation */
  884. { mk_mii_write(MII_BMCR, BMCR_ANENABLE), mii_parse_cr },
  885. { mk_mii_end, }
  886. },
  887. (const phy_cmd_t []) { /* startup - enable interrupts */
  888. { mk_mii_write(MII_LXT971_IER, 0x00f2), NULL },
  889. /* restart auto-negotiation */
  890. { mk_mii_write(MII_BMCR, BMCR_ANENABLE | BMCR_ANRESTART),
  891. NULL },
  892. { mk_mii_end, }
  893. },
  894. (const phy_cmd_t []) { /* ack_int */
  895. /* find out the current status */
  896. { mk_mii_read(MII_BMSR), NULL },
  897. { mk_mii_read(MII_BMSR), mii_parse_sr },
  898. { mk_mii_read(MII_LXT971_SR2), mii_parse_lxt971_sr2 },
  899. /* we only need to read ISR to acknowledge */
  900. { mk_mii_read(MII_LXT971_ISR), NULL },
  901. { mk_mii_end, }
  902. },
  903. (const phy_cmd_t []) { /* shutdown - disable interrupts */
  904. { mk_mii_write(MII_LXT971_IER, 0x0000), NULL },
  905. { mk_mii_end, }
  906. },
  907. };
  908. #endif /* CONFIG_FCC_LXT971 */
  909. /* ------------------------------------------------------------------------- */
  910. /* The Quality Semiconductor QS6612 is used on the RPX CLLF */
  911. #ifdef CONFIG_FCC_QS6612
  912. /* register definitions */
  913. #define MII_QS6612_MCR 17 /* Mode Control Register */
  914. #define MII_QS6612_FTR 27 /* Factory Test Register */
  915. #define MII_QS6612_MCO 28 /* Misc. Control Register */
  916. #define MII_QS6612_ISR 29 /* Interrupt Source Register */
  917. #define MII_QS6612_IMR 30 /* Interrupt Mask Register */
  918. #define MII_QS6612_PCR 31 /* 100BaseTx PHY Control Reg. */
  919. static void mii_parse_qs6612_pcr(uint mii_reg, struct net_device *dev)
  920. {
  921. volatile struct fcc_enet_private *fep = dev->priv;
  922. uint s = fep->phy_status;
  923. s &= ~(PHY_STAT_SPMASK);
  924. switch((mii_reg >> 2) & 7) {
  925. case 1: s |= PHY_STAT_10HDX; break;
  926. case 2: s |= PHY_STAT_100HDX; break;
  927. case 5: s |= PHY_STAT_10FDX; break;
  928. case 6: s |= PHY_STAT_100FDX; break;
  929. }
  930. fep->phy_status = s;
  931. }
  932. static phy_info_t phy_info_qs6612 = {
  933. 0x00181440,
  934. "QS6612",
  935. (const phy_cmd_t []) { /* config */
  936. // { mk_mii_write(MII_ADVERTISE, 0x061), NULL }, /* 10 Mbps */
  937. /* The PHY powers up isolated on the RPX,
  938. * so send a command to allow operation.
  939. */
  940. { mk_mii_write(MII_QS6612_PCR, 0x0dc0), NULL },
  941. /* parse cr and anar to get some info */
  942. { mk_mii_read(MII_BMCR), mii_parse_cr },
  943. { mk_mii_read(MII_ADVERTISE), mii_parse_anar },
  944. { mk_mii_end, }
  945. },
  946. (const phy_cmd_t []) { /* startup - enable interrupts */
  947. { mk_mii_write(MII_QS6612_IMR, 0x003a), NULL },
  948. { mk_mii_write(MII_BMCR, 0x1200), NULL }, /* autonegotiate */
  949. { mk_mii_end, }
  950. },
  951. (const phy_cmd_t []) { /* ack_int */
  952. /* we need to read ISR, SR and ANER to acknowledge */
  953. { mk_mii_read(MII_QS6612_ISR), NULL },
  954. { mk_mii_read(MII_BMSR), mii_parse_sr },
  955. { mk_mii_read(MII_EXPANSION), NULL },
  956. /* read pcr to get info */
  957. { mk_mii_read(MII_QS6612_PCR), mii_parse_qs6612_pcr },
  958. { mk_mii_end, }
  959. },
  960. (const phy_cmd_t []) { /* shutdown - disable interrupts */
  961. { mk_mii_write(MII_QS6612_IMR, 0x0000), NULL },
  962. { mk_mii_end, }
  963. },
  964. };
  965. #endif /* CONFIG_FEC_QS6612 */
  966. /* ------------------------------------------------------------------------- */
  967. /* The Davicom DM9131 is used on the HYMOD board */
  968. #ifdef CONFIG_FCC_DM9131
  969. /* register definitions */
  970. #define MII_DM9131_ACR 16 /* Aux. Config Register */
  971. #define MII_DM9131_ACSR 17 /* Aux. Config/Status Register */
  972. #define MII_DM9131_10TCSR 18 /* 10BaseT Config/Status Reg. */
  973. #define MII_DM9131_INTR 21 /* Interrupt Register */
  974. #define MII_DM9131_RECR 22 /* Receive Error Counter Reg. */
  975. #define MII_DM9131_DISCR 23 /* Disconnect Counter Register */
  976. static void mii_parse_dm9131_acsr(uint mii_reg, struct net_device *dev)
  977. {
  978. volatile struct fcc_enet_private *fep = dev->priv;
  979. uint s = fep->phy_status;
  980. s &= ~(PHY_STAT_SPMASK);
  981. switch ((mii_reg >> 12) & 0xf) {
  982. case 1: s |= PHY_STAT_10HDX; break;
  983. case 2: s |= PHY_STAT_10FDX; break;
  984. case 4: s |= PHY_STAT_100HDX; break;
  985. case 8: s |= PHY_STAT_100FDX; break;
  986. }
  987. fep->phy_status = s;
  988. }
  989. static phy_info_t phy_info_dm9131 = {
  990. 0x00181b80,
  991. "DM9131",
  992. (const phy_cmd_t []) { /* config */
  993. /* parse cr and anar to get some info */
  994. { mk_mii_read(MII_BMCR), mii_parse_cr },
  995. { mk_mii_read(MII_ADVERTISE), mii_parse_anar },
  996. { mk_mii_end, }
  997. },
  998. (const phy_cmd_t []) { /* startup - enable interrupts */
  999. { mk_mii_write(MII_DM9131_INTR, 0x0002), NULL },
  1000. { mk_mii_write(MII_BMCR, 0x1200), NULL }, /* autonegotiate */
  1001. { mk_mii_end, }
  1002. },
  1003. (const phy_cmd_t []) { /* ack_int */
  1004. /* we need to read INTR, SR and ANER to acknowledge */
  1005. { mk_mii_read(MII_DM9131_INTR), NULL },
  1006. { mk_mii_read(MII_BMSR), mii_parse_sr },
  1007. { mk_mii_read(MII_EXPANSION), NULL },
  1008. /* read acsr to get info */
  1009. { mk_mii_read(MII_DM9131_ACSR), mii_parse_dm9131_acsr },
  1010. { mk_mii_end, }
  1011. },
  1012. (const phy_cmd_t []) { /* shutdown - disable interrupts */
  1013. { mk_mii_write(MII_DM9131_INTR, 0x0f00), NULL },
  1014. { mk_mii_end, }
  1015. },
  1016. };
  1017. #endif /* CONFIG_FEC_DM9131 */
  1018. #ifdef CONFIG_FCC_DM9161
  1019. /* ------------------------------------------------------------------------- */
  1020. /* DM9161 Control register values */
  1021. #define MIIM_DM9161_CR_STOP 0x0400
  1022. #define MIIM_DM9161_CR_RSTAN 0x1200
  1023. #define MIIM_DM9161_SCR 0x10
  1024. #define MIIM_DM9161_SCR_INIT 0x0610
  1025. /* DM9161 Specified Configuration and Status Register */
  1026. #define MIIM_DM9161_SCSR 0x11
  1027. #define MIIM_DM9161_SCSR_100F 0x8000
  1028. #define MIIM_DM9161_SCSR_100H 0x4000
  1029. #define MIIM_DM9161_SCSR_10F 0x2000
  1030. #define MIIM_DM9161_SCSR_10H 0x1000
  1031. /* DM9161 10BT register */
  1032. #define MIIM_DM9161_10BTCSR 0x12
  1033. #define MIIM_DM9161_10BTCSR_INIT 0x7800
  1034. /* DM9161 Interrupt Register */
  1035. #define MIIM_DM9161_INTR 0x15
  1036. #define MIIM_DM9161_INTR_PEND 0x8000
  1037. #define MIIM_DM9161_INTR_DPLX_MASK 0x0800
  1038. #define MIIM_DM9161_INTR_SPD_MASK 0x0400
  1039. #define MIIM_DM9161_INTR_LINK_MASK 0x0200
  1040. #define MIIM_DM9161_INTR_MASK 0x0100
  1041. #define MIIM_DM9161_INTR_DPLX_CHANGE 0x0010
  1042. #define MIIM_DM9161_INTR_SPD_CHANGE 0x0008
  1043. #define MIIM_DM9161_INTR_LINK_CHANGE 0x0004
  1044. #define MIIM_DM9161_INTR_INIT 0x0000
  1045. #define MIIM_DM9161_INTR_STOP \
  1046. (MIIM_DM9161_INTR_DPLX_MASK | MIIM_DM9161_INTR_SPD_MASK \
  1047. | MIIM_DM9161_INTR_LINK_MASK | MIIM_DM9161_INTR_MASK)
  1048. static void mii_parse_dm9161_sr(uint mii_reg, struct net_device * dev)
  1049. {
  1050. volatile struct fcc_enet_private *fep = dev->priv;
  1051. uint regstat, timeout=0xffff;
  1052. while(!(mii_reg & 0x0020) && timeout--)
  1053. {
  1054. regstat=mk_mii_read(MII_BMSR);
  1055. regstat |= fep->phy_addr <<23;
  1056. mii_reg = mii_send_receive(fep->fip,regstat);
  1057. }
  1058. mii_parse_sr(mii_reg, dev);
  1059. }
  1060. static void mii_parse_dm9161_scsr(uint mii_reg, struct net_device * dev)
  1061. {
  1062. volatile struct fcc_enet_private *fep = dev->priv;
  1063. uint s = fep->phy_status;
  1064. s &= ~(PHY_STAT_SPMASK);
  1065. switch((mii_reg >>12) & 0xf) {
  1066. case 1:
  1067. {
  1068. s |= PHY_STAT_10HDX;
  1069. printk("10BaseT Half Duplex\n");
  1070. break;
  1071. }
  1072. case 2:
  1073. {
  1074. s |= PHY_STAT_10FDX;
  1075. printk("10BaseT Full Duplex\n");
  1076. break;
  1077. }
  1078. case 4:
  1079. {
  1080. s |= PHY_STAT_100HDX;
  1081. printk("100BaseT Half Duplex\n");
  1082. break;
  1083. }
  1084. case 8:
  1085. {
  1086. s |= PHY_STAT_100FDX;
  1087. printk("100BaseT Full Duplex\n");
  1088. break;
  1089. }
  1090. }
  1091. fep->phy_status = s;
  1092. }
  1093. static void mii_dm9161_wait(uint mii_reg, struct net_device *dev)
  1094. {
  1095. int timeout = HZ;
  1096. /* Davicom takes a bit to come up after a reset,
  1097. * so wait here for a bit */
  1098. set_current_state(TASK_UNINTERRUPTIBLE);
  1099. schedule_timeout(timeout);
  1100. }
  1101. static phy_info_t phy_info_dm9161 = {
  1102. 0x00181b88,
  1103. "Davicom DM9161E",
  1104. (const phy_cmd_t[]) { /* config */
  1105. { mk_mii_write(MII_BMCR, MIIM_DM9161_CR_STOP), NULL},
  1106. /* Do not bypass the scrambler/descrambler */
  1107. { mk_mii_write(MIIM_DM9161_SCR, MIIM_DM9161_SCR_INIT), NULL},
  1108. /* Configure 10BTCSR register */
  1109. { mk_mii_write(MIIM_DM9161_10BTCSR, MIIM_DM9161_10BTCSR_INIT),NULL},
  1110. /* Configure some basic stuff */
  1111. { mk_mii_write(MII_BMCR, 0x1000), NULL},
  1112. { mk_mii_read(MII_BMCR), mii_parse_cr },
  1113. { mk_mii_read(MII_ADVERTISE), mii_parse_anar },
  1114. { mk_mii_end,}
  1115. },
  1116. (const phy_cmd_t[]) { /* startup */
  1117. /* Restart Auto Negotiation */
  1118. { mk_mii_write(MII_BMCR, MIIM_DM9161_CR_RSTAN), NULL},
  1119. /* Status is read once to clear old link state */
  1120. { mk_mii_read(MII_BMSR), mii_dm9161_wait},
  1121. /* Auto-negotiate */
  1122. { mk_mii_read(MII_BMSR), mii_parse_dm9161_sr},
  1123. /* Read the status */
  1124. { mk_mii_read(MIIM_DM9161_SCSR), mii_parse_dm9161_scsr},
  1125. /* Clear any pending interrupts */
  1126. { mk_mii_read(MIIM_DM9161_INTR), NULL},
  1127. /* Enable Interrupts */
  1128. { mk_mii_write(MIIM_DM9161_INTR, MIIM_DM9161_INTR_INIT), NULL},
  1129. { mk_mii_end,}
  1130. },
  1131. (const phy_cmd_t[]) { /* ack_int */
  1132. { mk_mii_read(MIIM_DM9161_INTR), NULL},
  1133. #if 0
  1134. { mk_mii_read(MII_BMSR), NULL},
  1135. { mk_mii_read(MII_BMSR), mii_parse_dm9161_sr},
  1136. { mk_mii_read(MIIM_DM9161_SCSR), mii_parse_dm9161_scsr},
  1137. #endif
  1138. { mk_mii_end,}
  1139. },
  1140. (const phy_cmd_t[]) { /* shutdown */
  1141. { mk_mii_read(MIIM_DM9161_INTR),NULL},
  1142. { mk_mii_write(MIIM_DM9161_INTR, MIIM_DM9161_INTR_STOP), NULL},
  1143. { mk_mii_end,}
  1144. },
  1145. };
  1146. #endif /* CONFIG_FCC_DM9161 */
  1147. static phy_info_t *phy_info[] = {
  1148. #ifdef CONFIG_FCC_LXT970
  1149. &phy_info_lxt970,
  1150. #endif /* CONFIG_FEC_LXT970 */
  1151. #ifdef CONFIG_FCC_LXT971
  1152. &phy_info_lxt971,
  1153. #endif /* CONFIG_FEC_LXT971 */
  1154. #ifdef CONFIG_FCC_QS6612
  1155. &phy_info_qs6612,
  1156. #endif /* CONFIG_FEC_QS6612 */
  1157. #ifdef CONFIG_FCC_DM9131
  1158. &phy_info_dm9131,
  1159. #endif /* CONFIG_FEC_DM9131 */
  1160. #ifdef CONFIG_FCC_DM9161
  1161. &phy_info_dm9161,
  1162. #endif /* CONFIG_FCC_DM9161 */
  1163. #ifdef CONFIG_FCC_GENERIC_PHY
  1164. /* Generic PHY support. This must be the last PHY in the table.
  1165. * It will be used to support any PHY that doesn't match a previous
  1166. * entry in the table.
  1167. */
  1168. &phy_info_generic,
  1169. #endif /* CONFIG_FCC_GENERIC_PHY */
  1170. NULL
  1171. };
  1172. static void mii_display_status(void *data)
  1173. {
  1174. struct net_device *dev = data;
  1175. volatile struct fcc_enet_private *fep = dev->priv;
  1176. uint s = fep->phy_status;
  1177. if (!fep->link && !fep->old_link) {
  1178. /* Link is still down - don't print anything */
  1179. return;
  1180. }
  1181. printk("%s: status: ", dev->name);
  1182. if (!fep->link) {
  1183. printk("link down");
  1184. } else {
  1185. printk("link up");
  1186. switch(s & PHY_STAT_SPMASK) {
  1187. case PHY_STAT_100FDX: printk(", 100 Mbps Full Duplex"); break;
  1188. case PHY_STAT_100HDX: printk(", 100 Mbps Half Duplex"); break;
  1189. case PHY_STAT_10FDX: printk(", 10 Mbps Full Duplex"); break;
  1190. case PHY_STAT_10HDX: printk(", 10 Mbps Half Duplex"); break;
  1191. default:
  1192. printk(", Unknown speed/duplex");
  1193. }
  1194. if (s & PHY_STAT_ANC)
  1195. printk(", auto-negotiation complete");
  1196. }
  1197. if (s & PHY_STAT_FAULT)
  1198. printk(", remote fault");
  1199. printk(".\n");
  1200. }
  1201. static void mii_display_config(void *data)
  1202. {
  1203. struct net_device *dev = data;
  1204. volatile struct fcc_enet_private *fep = dev->priv;
  1205. uint s = fep->phy_status;
  1206. printk("%s: config: auto-negotiation ", dev->name);
  1207. if (s & PHY_CONF_ANE)
  1208. printk("on");
  1209. else
  1210. printk("off");
  1211. if (s & PHY_CONF_100FDX)
  1212. printk(", 100FDX");
  1213. if (s & PHY_CONF_100HDX)
  1214. printk(", 100HDX");
  1215. if (s & PHY_CONF_10FDX)
  1216. printk(", 10FDX");
  1217. if (s & PHY_CONF_10HDX)
  1218. printk(", 10HDX");
  1219. if (!(s & PHY_CONF_SPMASK))
  1220. printk(", No speed/duplex selected?");
  1221. if (s & PHY_CONF_LOOP)
  1222. printk(", loopback enabled");
  1223. printk(".\n");
  1224. fep->sequence_done = 1;
  1225. }
  1226. static void mii_relink(struct net_device *dev)
  1227. {
  1228. struct fcc_enet_private *fep = dev->priv;
  1229. int duplex = 0;
  1230. fep->old_link = fep->link;
  1231. fep->link = (fep->phy_status & PHY_STAT_LINK) ? 1 : 0;
  1232. #ifdef MDIO_DEBUG
  1233. printk(" mii_relink: link=%d\n", fep->link);
  1234. #endif
  1235. if (fep->link) {
  1236. if (fep->phy_status
  1237. & (PHY_STAT_100FDX | PHY_STAT_10FDX))
  1238. duplex = 1;
  1239. fcc_restart(dev, duplex);
  1240. #ifdef MDIO_DEBUG
  1241. printk(" mii_relink: duplex=%d\n", duplex);
  1242. #endif
  1243. }
  1244. }
  1245. static void mii_queue_relink(uint mii_reg, struct net_device *dev)
  1246. {
  1247. struct fcc_enet_private *fep = dev->priv;
  1248. mii_relink(dev);
  1249. schedule_work(&fep->phy_relink);
  1250. }
  1251. static void mii_queue_config(uint mii_reg, struct net_device *dev)
  1252. {
  1253. struct fcc_enet_private *fep = dev->priv;
  1254. schedule_work(&fep->phy_display_config);
  1255. }
  1256. phy_cmd_t phy_cmd_relink[] = { { mk_mii_read(MII_BMCR), mii_queue_relink },
  1257. { mk_mii_end, } };
  1258. phy_cmd_t phy_cmd_config[] = { { mk_mii_read(MII_BMCR), mii_queue_config },
  1259. { mk_mii_end, } };
  1260. /* Read remainder of PHY ID.
  1261. */
  1262. static void
  1263. mii_discover_phy3(uint mii_reg, struct net_device *dev)
  1264. {
  1265. struct fcc_enet_private *fep;
  1266. int i;
  1267. fep = dev->priv;
  1268. printk("mii_reg: %08x\n", mii_reg);
  1269. fep->phy_id |= (mii_reg & 0xffff);
  1270. for(i = 0; phy_info[i]; i++)
  1271. if((phy_info[i]->id == (fep->phy_id >> 4)) || !phy_info[i]->id)
  1272. break;
  1273. if(!phy_info[i])
  1274. panic("%s: PHY id 0x%08x is not supported!\n",
  1275. dev->name, fep->phy_id);
  1276. fep->phy = phy_info[i];
  1277. fep->phy_id_done = 1;
  1278. printk("%s: Phy @ 0x%x, type %s (0x%08x)\n",
  1279. dev->name, fep->phy_addr, fep->phy->name, fep->phy_id);
  1280. }
  1281. /* Scan all of the MII PHY addresses looking for someone to respond
  1282. * with a valid ID. This usually happens quickly.
  1283. */
  1284. static void
  1285. mii_discover_phy(uint mii_reg, struct net_device *dev)
  1286. {
  1287. struct fcc_enet_private *fep;
  1288. uint phytype;
  1289. fep = dev->priv;
  1290. if ((phytype = (mii_reg & 0xffff)) != 0xffff) {
  1291. /* Got first part of ID, now get remainder. */
  1292. fep->phy_id = phytype << 16;
  1293. mii_queue(dev, mk_mii_read(MII_PHYSID2), mii_discover_phy3);
  1294. } else {
  1295. fep->phy_addr++;
  1296. if (fep->phy_addr < 32) {
  1297. mii_queue(dev, mk_mii_read(MII_PHYSID1),
  1298. mii_discover_phy);
  1299. } else {
  1300. printk("fec: No PHY device found.\n");
  1301. }
  1302. }
  1303. }
  1304. #endif /* CONFIG_USE_MDIO */
  1305. #ifdef PHY_INTERRUPT
  1306. /* This interrupt occurs when the PHY detects a link change. */
  1307. static irqreturn_t
  1308. mii_link_interrupt(int irq, void * dev_id, struct pt_regs * regs)
  1309. {
  1310. struct net_device *dev = dev_id;
  1311. struct fcc_enet_private *fep = dev->priv;
  1312. fcc_info_t *fip = fep->fip;
  1313. if (fep->phy) {
  1314. /* We don't want to be interrupted by an FCC
  1315. * interrupt here.
  1316. */
  1317. disable_irq_nosync(fip->fc_interrupt);
  1318. mii_do_cmd(dev, fep->phy->ack_int);
  1319. /* restart and display status */
  1320. mii_do_cmd(dev, phy_cmd_relink);
  1321. enable_irq(fip->fc_interrupt);
  1322. }
  1323. return IRQ_HANDLED;
  1324. }
  1325. #endif /* ifdef PHY_INTERRUPT */
  1326. #if 0 /* This should be fixed someday */
  1327. /* Set or clear the multicast filter for this adaptor.
  1328. * Skeleton taken from sunlance driver.
  1329. * The CPM Ethernet implementation allows Multicast as well as individual
  1330. * MAC address filtering. Some of the drivers check to make sure it is
  1331. * a group multicast address, and discard those that are not. I guess I
  1332. * will do the same for now, but just remove the test if you want
  1333. * individual filtering as well (do the upper net layers want or support
  1334. * this kind of feature?).
  1335. */
  1336. static void
  1337. set_multicast_list(struct net_device *dev)
  1338. {
  1339. struct fcc_enet_private *cep;
  1340. struct dev_mc_list *dmi;
  1341. u_char *mcptr, *tdptr;
  1342. volatile fcc_enet_t *ep;
  1343. int i, j;
  1344. cep = (struct fcc_enet_private *)dev->priv;
  1345. return;
  1346. /* Get pointer to FCC area in parameter RAM.
  1347. */
  1348. ep = (fcc_enet_t *)dev->base_addr;
  1349. if (dev->flags&IFF_PROMISC) {
  1350. /* Log any net taps. */
  1351. printk("%s: Promiscuous mode enabled.\n", dev->name);
  1352. cep->fccp->fcc_fpsmr |= FCC_PSMR_PRO;
  1353. } else {
  1354. cep->fccp->fcc_fpsmr &= ~FCC_PSMR_PRO;
  1355. if (dev->flags & IFF_ALLMULTI) {
  1356. /* Catch all multicast addresses, so set the
  1357. * filter to all 1's.
  1358. */
  1359. ep->fen_gaddrh = 0xffffffff;
  1360. ep->fen_gaddrl = 0xffffffff;
  1361. }
  1362. else {
  1363. /* Clear filter and add the addresses in the list.
  1364. */
  1365. ep->fen_gaddrh = 0;
  1366. ep->fen_gaddrl = 0;
  1367. dmi = dev->mc_list;
  1368. for (i=0; i<dev->mc_count; i++, dmi = dmi->next) {
  1369. /* Only support group multicast for now.
  1370. */
  1371. if (!(dmi->dmi_addr[0] & 1))
  1372. continue;
  1373. /* The address in dmi_addr is LSB first,
  1374. * and taddr is MSB first. We have to
  1375. * copy bytes MSB first from dmi_addr.
  1376. */
  1377. mcptr = (u_char *)dmi->dmi_addr + 5;
  1378. tdptr = (u_char *)&ep->fen_taddrh;
  1379. for (j=0; j<6; j++)
  1380. *tdptr++ = *mcptr--;
  1381. /* Ask CPM to run CRC and set bit in
  1382. * filter mask.
  1383. */
  1384. cpmp->cp_cpcr = mk_cr_cmd(cep->fip->fc_cpmpage,
  1385. cep->fip->fc_cpmblock, 0x0c,
  1386. CPM_CR_SET_GADDR) | CPM_CR_FLG;
  1387. udelay(10);
  1388. while (cpmp->cp_cpcr & CPM_CR_FLG);
  1389. }
  1390. }
  1391. }
  1392. }
  1393. #endif /* if 0 */
  1394. /* Set the individual MAC address.
  1395. */
  1396. int fcc_enet_set_mac_address(struct net_device *dev, void *p)
  1397. {
  1398. struct sockaddr *addr= (struct sockaddr *) p;
  1399. struct fcc_enet_private *cep;
  1400. volatile fcc_enet_t *ep;
  1401. unsigned char *eap;
  1402. int i;
  1403. cep = (struct fcc_enet_private *)(dev->priv);
  1404. ep = cep->ep;
  1405. if (netif_running(dev))
  1406. return -EBUSY;
  1407. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  1408. eap = (unsigned char *) &(ep->fen_paddrh);
  1409. for (i=5; i>=0; i--)
  1410. *eap++ = addr->sa_data[i];
  1411. return 0;
  1412. }
  1413. /* Initialize the CPM Ethernet on FCC.
  1414. */
  1415. static int __init fec_enet_init(void)
  1416. {
  1417. struct net_device *dev;
  1418. struct fcc_enet_private *cep;
  1419. fcc_info_t *fip;
  1420. int i, np, err;
  1421. volatile cpm2_map_t *immap;
  1422. volatile iop_cpm2_t *io;
  1423. immap = (cpm2_map_t *)CPM_MAP_ADDR; /* and to internal registers */
  1424. io = &immap->im_ioport;
  1425. np = sizeof(fcc_ports) / sizeof(fcc_info_t);
  1426. fip = fcc_ports;
  1427. while (np-- > 0) {
  1428. /* Create an Ethernet device instance.
  1429. */
  1430. dev = alloc_etherdev(sizeof(*cep));
  1431. if (!dev)
  1432. return -ENOMEM;
  1433. cep = dev->priv;
  1434. spin_lock_init(&cep->lock);
  1435. cep->fip = fip;
  1436. init_fcc_shutdown(fip, cep, immap);
  1437. init_fcc_ioports(fip, io, immap);
  1438. init_fcc_param(fip, dev, immap);
  1439. dev->base_addr = (unsigned long)(cep->ep);
  1440. /* The CPM Ethernet specific entries in the device
  1441. * structure.
  1442. */
  1443. dev->open = fcc_enet_open;
  1444. dev->hard_start_xmit = fcc_enet_start_xmit;
  1445. dev->tx_timeout = fcc_enet_timeout;
  1446. dev->watchdog_timeo = TX_TIMEOUT;
  1447. dev->stop = fcc_enet_close;
  1448. dev->get_stats = fcc_enet_get_stats;
  1449. /* dev->set_multicast_list = set_multicast_list; */
  1450. dev->set_mac_address = fcc_enet_set_mac_address;
  1451. init_fcc_startup(fip, dev);
  1452. err = register_netdev(dev);
  1453. if (err) {
  1454. free_netdev(dev);
  1455. return err;
  1456. }
  1457. printk("%s: FCC ENET Version 0.3, ", dev->name);
  1458. for (i=0; i<5; i++)
  1459. printk("%02x:", dev->dev_addr[i]);
  1460. printk("%02x\n", dev->dev_addr[5]);
  1461. #ifdef CONFIG_USE_MDIO
  1462. /* Queue up command to detect the PHY and initialize the
  1463. * remainder of the interface.
  1464. */
  1465. cep->phy_id_done = 0;
  1466. cep->phy_addr = fip->fc_phyaddr;
  1467. mii_queue(dev, mk_mii_read(MII_PHYSID1), mii_discover_phy);
  1468. INIT_WORK(&cep->phy_relink, mii_display_status, dev);
  1469. INIT_WORK(&cep->phy_display_config, mii_display_config, dev);
  1470. #endif /* CONFIG_USE_MDIO */
  1471. fip++;
  1472. }
  1473. return 0;
  1474. }
  1475. module_init(fec_enet_init);
  1476. /* Make sure the device is shut down during initialization.
  1477. */
  1478. static void __init
  1479. init_fcc_shutdown(fcc_info_t *fip, struct fcc_enet_private *cep,
  1480. volatile cpm2_map_t *immap)
  1481. {
  1482. volatile fcc_enet_t *ep;
  1483. volatile fcc_t *fccp;
  1484. /* Get pointer to FCC area in parameter RAM.
  1485. */
  1486. ep = (fcc_enet_t *)(&immap->im_dprambase[fip->fc_proff]);
  1487. /* And another to the FCC register area.
  1488. */
  1489. fccp = (volatile fcc_t *)(&immap->im_fcc[fip->fc_fccnum]);
  1490. cep->fccp = fccp; /* Keep the pointers handy */
  1491. cep->ep = ep;
  1492. /* Disable receive and transmit in case someone left it running.
  1493. */
  1494. fccp->fcc_gfmr &= ~(FCC_GFMR_ENR | FCC_GFMR_ENT);
  1495. }
  1496. /* Initialize the I/O pins for the FCC Ethernet.
  1497. */
  1498. static void __init
  1499. init_fcc_ioports(fcc_info_t *fip, volatile iop_cpm2_t *io,
  1500. volatile cpm2_map_t *immap)
  1501. {
  1502. /* FCC1 pins are on port A/C. FCC2/3 are port B/C.
  1503. */
  1504. if (fip->fc_proff == PROFF_FCC1) {
  1505. /* Configure port A and C pins for FCC1 Ethernet.
  1506. */
  1507. io->iop_pdira &= ~PA1_DIRA_BOUT;
  1508. io->iop_pdira |= PA1_DIRA_BIN;
  1509. io->iop_psora &= ~PA1_PSORA_BOUT;
  1510. io->iop_psora |= PA1_PSORA_BIN;
  1511. io->iop_ppara |= (PA1_DIRA_BOUT | PA1_DIRA_BIN);
  1512. }
  1513. if (fip->fc_proff == PROFF_FCC2) {
  1514. /* Configure port B and C pins for FCC Ethernet.
  1515. */
  1516. io->iop_pdirb &= ~PB2_DIRB_BOUT;
  1517. io->iop_pdirb |= PB2_DIRB_BIN;
  1518. io->iop_psorb &= ~PB2_PSORB_BOUT;
  1519. io->iop_psorb |= PB2_PSORB_BIN;
  1520. io->iop_pparb |= (PB2_DIRB_BOUT | PB2_DIRB_BIN);
  1521. }
  1522. if (fip->fc_proff == PROFF_FCC3) {
  1523. /* Configure port B and C pins for FCC Ethernet.
  1524. */
  1525. io->iop_pdirb &= ~PB3_DIRB_BOUT;
  1526. io->iop_pdirb |= PB3_DIRB_BIN;
  1527. io->iop_psorb &= ~PB3_PSORB_BOUT;
  1528. io->iop_psorb |= PB3_PSORB_BIN;
  1529. io->iop_pparb |= (PB3_DIRB_BOUT | PB3_DIRB_BIN);
  1530. io->iop_pdirc &= ~PC3_DIRC_BOUT;
  1531. io->iop_pdirc |= PC3_DIRC_BIN;
  1532. io->iop_psorc &= ~PC3_PSORC_BOUT;
  1533. io->iop_psorc |= PC3_PSORC_BIN;
  1534. io->iop_pparc |= (PC3_DIRC_BOUT | PC3_DIRC_BIN);
  1535. }
  1536. /* Port C has clocks......
  1537. */
  1538. io->iop_psorc &= ~(fip->fc_trxclocks);
  1539. io->iop_pdirc &= ~(fip->fc_trxclocks);
  1540. io->iop_pparc |= fip->fc_trxclocks;
  1541. #ifdef CONFIG_USE_MDIO
  1542. /* ....and the MII serial clock/data.
  1543. */
  1544. io->iop_pdatc |= (fip->fc_mdio | fip->fc_mdck);
  1545. io->iop_podrc &= ~(fip->fc_mdio | fip->fc_mdck);
  1546. io->iop_pdirc |= (fip->fc_mdio | fip->fc_mdck);
  1547. io->iop_pparc &= ~(fip->fc_mdio | fip->fc_mdck);
  1548. #endif /* CONFIG_USE_MDIO */
  1549. /* Configure Serial Interface clock routing.
  1550. * First, clear all FCC bits to zero,
  1551. * then set the ones we want.
  1552. */
  1553. immap->im_cpmux.cmx_fcr &= ~(fip->fc_clockmask);
  1554. immap->im_cpmux.cmx_fcr |= fip->fc_clockroute;
  1555. }
  1556. static void __init
  1557. init_fcc_param(fcc_info_t *fip, struct net_device *dev,
  1558. volatile cpm2_map_t *immap)
  1559. {
  1560. unsigned char *eap;
  1561. unsigned long mem_addr;
  1562. bd_t *bd;
  1563. int i, j;
  1564. struct fcc_enet_private *cep;
  1565. volatile fcc_enet_t *ep;
  1566. volatile cbd_t *bdp;
  1567. volatile cpm_cpm2_t *cp;
  1568. cep = (struct fcc_enet_private *)(dev->priv);
  1569. ep = cep->ep;
  1570. cp = cpmp;
  1571. bd = (bd_t *)__res;
  1572. /* Zero the whole thing.....I must have missed some individually.
  1573. * It works when I do this.
  1574. */
  1575. memset((char *)ep, 0, sizeof(fcc_enet_t));
  1576. /* Allocate space for the buffer descriptors from regular memory.
  1577. * Initialize base addresses for the buffer descriptors.
  1578. */
  1579. cep->rx_bd_base = (cbd_t *)kmalloc(sizeof(cbd_t) * RX_RING_SIZE,
  1580. GFP_KERNEL | GFP_DMA);
  1581. ep->fen_genfcc.fcc_rbase = __pa(cep->rx_bd_base);
  1582. cep->tx_bd_base = (cbd_t *)kmalloc(sizeof(cbd_t) * TX_RING_SIZE,
  1583. GFP_KERNEL | GFP_DMA);
  1584. ep->fen_genfcc.fcc_tbase = __pa(cep->tx_bd_base);
  1585. cep->dirty_tx = cep->cur_tx = cep->tx_bd_base;
  1586. cep->cur_rx = cep->rx_bd_base;
  1587. ep->fen_genfcc.fcc_rstate = (CPMFCR_GBL | CPMFCR_EB) << 24;
  1588. ep->fen_genfcc.fcc_tstate = (CPMFCR_GBL | CPMFCR_EB) << 24;
  1589. /* Set maximum bytes per receive buffer.
  1590. * It must be a multiple of 32.
  1591. */
  1592. ep->fen_genfcc.fcc_mrblr = PKT_MAXBLR_SIZE;
  1593. /* Allocate space in the reserved FCC area of DPRAM for the
  1594. * internal buffers. No one uses this space (yet), so we
  1595. * can do this. Later, we will add resource management for
  1596. * this area.
  1597. */
  1598. mem_addr = CPM_FCC_SPECIAL_BASE + (fip->fc_fccnum * 128);
  1599. ep->fen_genfcc.fcc_riptr = mem_addr;
  1600. ep->fen_genfcc.fcc_tiptr = mem_addr+32;
  1601. ep->fen_padptr = mem_addr+64;
  1602. memset((char *)(&(immap->im_dprambase[(mem_addr+64)])), 0x88, 32);
  1603. ep->fen_genfcc.fcc_rbptr = 0;
  1604. ep->fen_genfcc.fcc_tbptr = 0;
  1605. ep->fen_genfcc.fcc_rcrc = 0;
  1606. ep->fen_genfcc.fcc_tcrc = 0;
  1607. ep->fen_genfcc.fcc_res1 = 0;
  1608. ep->fen_genfcc.fcc_res2 = 0;
  1609. ep->fen_camptr = 0; /* CAM isn't used in this driver */
  1610. /* Set CRC preset and mask.
  1611. */
  1612. ep->fen_cmask = 0xdebb20e3;
  1613. ep->fen_cpres = 0xffffffff;
  1614. ep->fen_crcec = 0; /* CRC Error counter */
  1615. ep->fen_alec = 0; /* alignment error counter */
  1616. ep->fen_disfc = 0; /* discard frame counter */
  1617. ep->fen_retlim = 15; /* Retry limit threshold */
  1618. ep->fen_pper = 0; /* Normal persistence */
  1619. /* Clear hash filter tables.
  1620. */
  1621. ep->fen_gaddrh = 0;
  1622. ep->fen_gaddrl = 0;
  1623. ep->fen_iaddrh = 0;
  1624. ep->fen_iaddrl = 0;
  1625. /* Clear the Out-of-sequence TxBD.
  1626. */
  1627. ep->fen_tfcstat = 0;
  1628. ep->fen_tfclen = 0;
  1629. ep->fen_tfcptr = 0;
  1630. ep->fen_mflr = PKT_MAXBUF_SIZE; /* maximum frame length register */
  1631. ep->fen_minflr = PKT_MINBUF_SIZE; /* minimum frame length register */
  1632. /* Set Ethernet station address.
  1633. *
  1634. * This is supplied in the board information structure, so we
  1635. * copy that into the controller.
  1636. * So, far we have only been given one Ethernet address. We make
  1637. * it unique by setting a few bits in the upper byte of the
  1638. * non-static part of the address.
  1639. */
  1640. eap = (unsigned char *)&(ep->fen_paddrh);
  1641. for (i=5; i>=0; i--) {
  1642. /*
  1643. * The EP8260 only uses FCC3, so we can safely give it the real
  1644. * MAC address.
  1645. */
  1646. #ifdef CONFIG_SBC82xx
  1647. if (i == 5) {
  1648. /* bd->bi_enetaddr holds the SCC0 address; the FCC
  1649. devices count up from there */
  1650. dev->dev_addr[i] = bd->bi_enetaddr[i] & ~3;
  1651. dev->dev_addr[i] += 1 + fip->fc_fccnum;
  1652. *eap++ = dev->dev_addr[i];
  1653. }
  1654. #else
  1655. #ifndef CONFIG_RPX8260
  1656. if (i == 3) {
  1657. dev->dev_addr[i] = bd->bi_enetaddr[i];
  1658. dev->dev_addr[i] |= (1 << (7 - fip->fc_fccnum));
  1659. *eap++ = dev->dev_addr[i];
  1660. } else
  1661. #endif
  1662. {
  1663. *eap++ = dev->dev_addr[i] = bd->bi_enetaddr[i];
  1664. }
  1665. #endif
  1666. }
  1667. ep->fen_taddrh = 0;
  1668. ep->fen_taddrm = 0;
  1669. ep->fen_taddrl = 0;
  1670. ep->fen_maxd1 = PKT_MAXDMA_SIZE; /* maximum DMA1 length */
  1671. ep->fen_maxd2 = PKT_MAXDMA_SIZE; /* maximum DMA2 length */
  1672. /* Clear stat counters, in case we ever enable RMON.
  1673. */
  1674. ep->fen_octc = 0;
  1675. ep->fen_colc = 0;
  1676. ep->fen_broc = 0;
  1677. ep->fen_mulc = 0;
  1678. ep->fen_uspc = 0;
  1679. ep->fen_frgc = 0;
  1680. ep->fen_ospc = 0;
  1681. ep->fen_jbrc = 0;
  1682. ep->fen_p64c = 0;
  1683. ep->fen_p65c = 0;
  1684. ep->fen_p128c = 0;
  1685. ep->fen_p256c = 0;
  1686. ep->fen_p512c = 0;
  1687. ep->fen_p1024c = 0;
  1688. ep->fen_rfthr = 0; /* Suggested by manual */
  1689. ep->fen_rfcnt = 0;
  1690. ep->fen_cftype = 0;
  1691. /* Now allocate the host memory pages and initialize the
  1692. * buffer descriptors.
  1693. */
  1694. bdp = cep->tx_bd_base;
  1695. for (i=0; i<TX_RING_SIZE; i++) {
  1696. /* Initialize the BD for every fragment in the page.
  1697. */
  1698. bdp->cbd_sc = 0;
  1699. bdp->cbd_datlen = 0;
  1700. bdp->cbd_bufaddr = 0;
  1701. bdp++;
  1702. }
  1703. /* Set the last buffer to wrap.
  1704. */
  1705. bdp--;
  1706. bdp->cbd_sc |= BD_SC_WRAP;
  1707. bdp = cep->rx_bd_base;
  1708. for (i=0; i<FCC_ENET_RX_PAGES; i++) {
  1709. /* Allocate a page.
  1710. */
  1711. mem_addr = __get_free_page(GFP_KERNEL);
  1712. /* Initialize the BD for every fragment in the page.
  1713. */
  1714. for (j=0; j<FCC_ENET_RX_FRPPG; j++) {
  1715. bdp->cbd_sc = BD_ENET_RX_EMPTY | BD_ENET_RX_INTR;
  1716. bdp->cbd_datlen = 0;
  1717. bdp->cbd_bufaddr = __pa(mem_addr);
  1718. mem_addr += FCC_ENET_RX_FRSIZE;
  1719. bdp++;
  1720. }
  1721. }
  1722. /* Set the last buffer to wrap.
  1723. */
  1724. bdp--;
  1725. bdp->cbd_sc |= BD_SC_WRAP;
  1726. /* Let's re-initialize the channel now. We have to do it later
  1727. * than the manual describes because we have just now finished
  1728. * the BD initialization.
  1729. */
  1730. cp->cp_cpcr = mk_cr_cmd(fip->fc_cpmpage, fip->fc_cpmblock, 0x0c,
  1731. CPM_CR_INIT_TRX) | CPM_CR_FLG;
  1732. while (cp->cp_cpcr & CPM_CR_FLG);
  1733. cep->skb_cur = cep->skb_dirty = 0;
  1734. }
  1735. /* Let 'er rip.
  1736. */
  1737. static void __init
  1738. init_fcc_startup(fcc_info_t *fip, struct net_device *dev)
  1739. {
  1740. volatile fcc_t *fccp;
  1741. struct fcc_enet_private *cep;
  1742. cep = (struct fcc_enet_private *)(dev->priv);
  1743. fccp = cep->fccp;
  1744. #ifdef CONFIG_RPX8260
  1745. #ifdef PHY_INTERRUPT
  1746. /* Route PHY interrupt to IRQ. The following code only works for
  1747. * IRQ1 - IRQ7. It does not work for Port C interrupts.
  1748. */
  1749. *((volatile u_char *) (RPX_CSR_ADDR + 13)) &= ~BCSR13_FETH_IRQMASK;
  1750. *((volatile u_char *) (RPX_CSR_ADDR + 13)) |=
  1751. ((PHY_INTERRUPT - SIU_INT_IRQ1 + 1) << 4);
  1752. #endif
  1753. /* Initialize MDIO pins. */
  1754. *((volatile u_char *) (RPX_CSR_ADDR + 4)) &= ~BCSR4_MII_MDC;
  1755. *((volatile u_char *) (RPX_CSR_ADDR + 4)) |=
  1756. BCSR4_MII_READ | BCSR4_MII_MDIO;
  1757. /* Enable external LXT971 PHY. */
  1758. *((volatile u_char *) (RPX_CSR_ADDR + 4)) |= BCSR4_EN_PHY;
  1759. udelay(1000);
  1760. *((volatile u_char *) (RPX_CSR_ADDR+ 4)) |= BCSR4_EN_MII;
  1761. udelay(1000);
  1762. #endif /* ifdef CONFIG_RPX8260 */
  1763. fccp->fcc_fcce = 0xffff; /* Clear any pending events */
  1764. /* Leave FCC interrupts masked for now. Will be unmasked by
  1765. * fcc_restart().
  1766. */
  1767. fccp->fcc_fccm = 0;
  1768. /* Install our interrupt handler.
  1769. */
  1770. if (request_irq(fip->fc_interrupt, fcc_enet_interrupt, 0, "fenet",
  1771. dev) < 0)
  1772. printk("Can't get FCC IRQ %d\n", fip->fc_interrupt);
  1773. #ifdef PHY_INTERRUPT
  1774. #ifdef CONFIG_ADS8272
  1775. if (request_irq(PHY_INTERRUPT, mii_link_interrupt, SA_SHIRQ,
  1776. "mii", dev) < 0)
  1777. printk(KERN_CRIT "Can't get MII IRQ %d\n", PHY_INTERRUPT);
  1778. #else
  1779. /* Make IRQn edge triggered. This does not work if PHY_INTERRUPT is
  1780. * on Port C.
  1781. */
  1782. ((volatile cpm2_map_t *) CPM_MAP_ADDR)->im_intctl.ic_siexr |=
  1783. (1 << (14 - (PHY_INTERRUPT - SIU_INT_IRQ1)));
  1784. if (request_irq(PHY_INTERRUPT, mii_link_interrupt, 0,
  1785. "mii", dev) < 0)
  1786. printk(KERN_CRIT "Can't get MII IRQ %d\n", PHY_INTERRUPT);
  1787. #endif
  1788. #endif /* PHY_INTERRUPT */
  1789. /* Set GFMR to enable Ethernet operating mode.
  1790. */
  1791. fccp->fcc_gfmr = (FCC_GFMR_TCI | FCC_GFMR_MODE_ENET);
  1792. /* Set sync/delimiters.
  1793. */
  1794. fccp->fcc_fdsr = 0xd555;
  1795. /* Set protocol specific processing mode for Ethernet.
  1796. * This has to be adjusted for Full Duplex operation after we can
  1797. * determine how to detect that.
  1798. */
  1799. fccp->fcc_fpsmr = FCC_PSMR_ENCRC;
  1800. #ifdef CONFIG_PQ2ADS
  1801. /* Enable the PHY. */
  1802. *(volatile uint *)(BCSR_ADDR + 4) &= ~BCSR1_FETHIEN;
  1803. *(volatile uint *)(BCSR_ADDR + 4) |= BCSR1_FETH_RST;
  1804. #endif
  1805. #if defined(CONFIG_PQ2ADS) || defined(CONFIG_PQ2FADS)
  1806. /* Enable the 2nd PHY. */
  1807. *(volatile uint *)(BCSR_ADDR + 12) &= ~BCSR3_FETHIEN2;
  1808. *(volatile uint *)(BCSR_ADDR + 12) |= BCSR3_FETH2_RST;
  1809. #endif
  1810. #if defined(CONFIG_USE_MDIO) || defined(CONFIG_TQM8260)
  1811. /* start in full duplex mode, and negotiate speed
  1812. */
  1813. fcc_restart (dev, 1);
  1814. #else
  1815. /* start in half duplex mode
  1816. */
  1817. fcc_restart (dev, 0);
  1818. #endif
  1819. }
  1820. #ifdef CONFIG_USE_MDIO
  1821. /* MII command/status interface.
  1822. * I'm not going to describe all of the details. You can find the
  1823. * protocol definition in many other places, including the data sheet
  1824. * of most PHY parts.
  1825. * I wonder what "they" were thinking (maybe weren't) when they leave
  1826. * the I2C in the CPM but I have to toggle these bits......
  1827. */
  1828. #ifdef CONFIG_RPX8260
  1829. /* The EP8260 has the MDIO pins in a BCSR instead of on Port C
  1830. * like most other boards.
  1831. */
  1832. #define MDIO_ADDR ((volatile u_char *)(RPX_CSR_ADDR + 4))
  1833. #define MAKE_MDIO_OUTPUT *MDIO_ADDR &= ~BCSR4_MII_READ
  1834. #define MAKE_MDIO_INPUT *MDIO_ADDR |= BCSR4_MII_READ | BCSR4_MII_MDIO
  1835. #define OUT_MDIO(bit) \
  1836. if (bit) \
  1837. *MDIO_ADDR |= BCSR4_MII_MDIO; \
  1838. else \
  1839. *MDIO_ADDR &= ~BCSR4_MII_MDIO;
  1840. #define IN_MDIO (*MDIO_ADDR & BCSR4_MII_MDIO)
  1841. #define OUT_MDC(bit) \
  1842. if (bit) \
  1843. *MDIO_ADDR |= BCSR4_MII_MDC; \
  1844. else \
  1845. *MDIO_ADDR &= ~BCSR4_MII_MDC;
  1846. #else /* ifdef CONFIG_RPX8260 */
  1847. /* This is for the usual case where the MDIO pins are on Port C.
  1848. */
  1849. #define MDIO_ADDR (((volatile cpm2_map_t *)CPM_MAP_ADDR)->im_ioport)
  1850. #define MAKE_MDIO_OUTPUT MDIO_ADDR.iop_pdirc |= fip->fc_mdio
  1851. #define MAKE_MDIO_INPUT MDIO_ADDR.iop_pdirc &= ~fip->fc_mdio
  1852. #define OUT_MDIO(bit) \
  1853. if (bit) \
  1854. MDIO_ADDR.iop_pdatc |= fip->fc_mdio; \
  1855. else \
  1856. MDIO_ADDR.iop_pdatc &= ~fip->fc_mdio;
  1857. #define IN_MDIO ((MDIO_ADDR.iop_pdatc) & fip->fc_mdio)
  1858. #define OUT_MDC(bit) \
  1859. if (bit) \
  1860. MDIO_ADDR.iop_pdatc |= fip->fc_mdck; \
  1861. else \
  1862. MDIO_ADDR.iop_pdatc &= ~fip->fc_mdck;
  1863. #endif /* ifdef CONFIG_RPX8260 */
  1864. static uint
  1865. mii_send_receive(fcc_info_t *fip, uint cmd)
  1866. {
  1867. uint retval;
  1868. int read_op, i, off;
  1869. const int us = 1;
  1870. read_op = ((cmd & 0xf0000000) == 0x60000000);
  1871. /* Write preamble
  1872. */
  1873. OUT_MDIO(1);
  1874. MAKE_MDIO_OUTPUT;
  1875. OUT_MDIO(1);
  1876. for (i = 0; i < 32; i++)
  1877. {
  1878. udelay(us);
  1879. OUT_MDC(1);
  1880. udelay(us);
  1881. OUT_MDC(0);
  1882. }
  1883. /* Write data
  1884. */
  1885. for (i = 0, off = 31; i < (read_op ? 14 : 32); i++, --off)
  1886. {
  1887. OUT_MDIO((cmd >> off) & 0x00000001);
  1888. udelay(us);
  1889. OUT_MDC(1);
  1890. udelay(us);
  1891. OUT_MDC(0);
  1892. }
  1893. retval = cmd;
  1894. if (read_op)
  1895. {
  1896. retval >>= 16;
  1897. MAKE_MDIO_INPUT;
  1898. udelay(us);
  1899. OUT_MDC(1);
  1900. udelay(us);
  1901. OUT_MDC(0);
  1902. for (i = 0; i < 16; i++)
  1903. {
  1904. udelay(us);
  1905. OUT_MDC(1);
  1906. udelay(us);
  1907. retval <<= 1;
  1908. if (IN_MDIO)
  1909. retval++;
  1910. OUT_MDC(0);
  1911. }
  1912. }
  1913. MAKE_MDIO_INPUT;
  1914. udelay(us);
  1915. OUT_MDC(1);
  1916. udelay(us);
  1917. OUT_MDC(0);
  1918. return retval;
  1919. }
  1920. #endif /* CONFIG_USE_MDIO */
  1921. static void
  1922. fcc_stop(struct net_device *dev)
  1923. {
  1924. struct fcc_enet_private *fep= (struct fcc_enet_private *)(dev->priv);
  1925. volatile fcc_t *fccp = fep->fccp;
  1926. fcc_info_t *fip = fep->fip;
  1927. volatile fcc_enet_t *ep = fep->ep;
  1928. volatile cpm_cpm2_t *cp = cpmp;
  1929. volatile cbd_t *bdp;
  1930. int i;
  1931. if ((fccp->fcc_gfmr & (FCC_GFMR_ENR | FCC_GFMR_ENT)) == 0)
  1932. return; /* already down */
  1933. fccp->fcc_fccm = 0;
  1934. /* issue the graceful stop tx command */
  1935. while (cp->cp_cpcr & CPM_CR_FLG);
  1936. cp->cp_cpcr = mk_cr_cmd(fip->fc_cpmpage, fip->fc_cpmblock,
  1937. 0x0c, CPM_CR_GRA_STOP_TX) | CPM_CR_FLG;
  1938. while (cp->cp_cpcr & CPM_CR_FLG);
  1939. /* Disable transmit/receive */
  1940. fccp->fcc_gfmr &= ~(FCC_GFMR_ENR | FCC_GFMR_ENT);
  1941. /* issue the restart tx command */
  1942. fccp->fcc_fcce = FCC_ENET_GRA;
  1943. while (cp->cp_cpcr & CPM_CR_FLG);
  1944. cp->cp_cpcr = mk_cr_cmd(fip->fc_cpmpage, fip->fc_cpmblock,
  1945. 0x0c, CPM_CR_RESTART_TX) | CPM_CR_FLG;
  1946. while (cp->cp_cpcr & CPM_CR_FLG);
  1947. /* free tx buffers */
  1948. fep->skb_cur = fep->skb_dirty = 0;
  1949. for (i=0; i<=TX_RING_MOD_MASK; i++) {
  1950. if (fep->tx_skbuff[i] != NULL) {
  1951. dev_kfree_skb(fep->tx_skbuff[i]);
  1952. fep->tx_skbuff[i] = NULL;
  1953. }
  1954. }
  1955. fep->dirty_tx = fep->cur_tx = fep->tx_bd_base;
  1956. fep->tx_free = TX_RING_SIZE;
  1957. ep->fen_genfcc.fcc_tbptr = ep->fen_genfcc.fcc_tbase;
  1958. /* Initialize the tx buffer descriptors. */
  1959. bdp = fep->tx_bd_base;
  1960. for (i=0; i<TX_RING_SIZE; i++) {
  1961. bdp->cbd_sc = 0;
  1962. bdp->cbd_datlen = 0;
  1963. bdp->cbd_bufaddr = 0;
  1964. bdp++;
  1965. }
  1966. /* Set the last buffer to wrap. */
  1967. bdp--;
  1968. bdp->cbd_sc |= BD_SC_WRAP;
  1969. }
  1970. static void
  1971. fcc_restart(struct net_device *dev, int duplex)
  1972. {
  1973. struct fcc_enet_private *fep = (struct fcc_enet_private *)(dev->priv);
  1974. volatile fcc_t *fccp = fep->fccp;
  1975. /* stop any transmissions in progress */
  1976. fcc_stop(dev);
  1977. if (duplex)
  1978. fccp->fcc_fpsmr |= FCC_PSMR_FDE | FCC_PSMR_LPB;
  1979. else
  1980. fccp->fcc_fpsmr &= ~(FCC_PSMR_FDE | FCC_PSMR_LPB);
  1981. /* Enable interrupts for transmit error, complete frame
  1982. * received, and any transmit buffer we have also set the
  1983. * interrupt flag.
  1984. */
  1985. fccp->fcc_fccm = (FCC_ENET_TXE | FCC_ENET_RXF | FCC_ENET_TXB);
  1986. /* Enable transmit/receive */
  1987. fccp->fcc_gfmr |= FCC_GFMR_ENR | FCC_GFMR_ENT;
  1988. }
  1989. static int
  1990. fcc_enet_open(struct net_device *dev)
  1991. {
  1992. struct fcc_enet_private *fep = dev->priv;
  1993. #ifdef CONFIG_USE_MDIO
  1994. fep->sequence_done = 0;
  1995. fep->link = 0;
  1996. if (fep->phy) {
  1997. fcc_restart(dev, 0); /* always start in half-duplex */
  1998. mii_do_cmd(dev, fep->phy->ack_int);
  1999. mii_do_cmd(dev, fep->phy->config);
  2000. mii_do_cmd(dev, phy_cmd_config); /* display configuration */
  2001. while(!fep->sequence_done)
  2002. schedule();
  2003. mii_do_cmd(dev, fep->phy->startup);
  2004. netif_start_queue(dev);
  2005. return 0; /* Success */
  2006. }
  2007. return -ENODEV; /* No PHY we understand */
  2008. #else
  2009. fep->link = 1;
  2010. fcc_restart(dev, 0); /* always start in half-duplex */
  2011. netif_start_queue(dev);
  2012. return 0; /* Always succeed */
  2013. #endif /* CONFIG_USE_MDIO */
  2014. }