fec.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778
  1. /*
  2. * Fast Ethernet Controller (FEC) driver for Motorola MPC8xx.
  3. * Copyright (c) 1997 Dan Malek (dmalek@jlc.net)
  4. *
  5. * Right now, I am very wasteful with the buffers. I allocate memory
  6. * pages and then divide them into 2K frame buffers. This way I know I
  7. * have buffers large enough to hold one frame within one buffer descriptor.
  8. * Once I get this working, I will use 64 or 128 byte CPM buffers, which
  9. * will be much more memory efficient and will easily handle lots of
  10. * small packets.
  11. *
  12. * Much better multiple PHY support by Magnus Damm.
  13. * Copyright (c) 2000 Ericsson Radio Systems AB.
  14. *
  15. * Support for FEC controller of ColdFire processors.
  16. * Copyright (c) 2001-2005 Greg Ungerer (gerg@snapgear.com)
  17. *
  18. * Bug fixes and cleanup by Philippe De Muyter (phdm@macqel.be)
  19. * Copyright (c) 2004-2006 Macq Electronique SA.
  20. *
  21. * Copyright (C) 2010-2011 Freescale Semiconductor, Inc.
  22. */
  23. #include <linux/module.h>
  24. #include <linux/kernel.h>
  25. #include <linux/string.h>
  26. #include <linux/ptrace.h>
  27. #include <linux/errno.h>
  28. #include <linux/ioport.h>
  29. #include <linux/slab.h>
  30. #include <linux/interrupt.h>
  31. #include <linux/pci.h>
  32. #include <linux/init.h>
  33. #include <linux/delay.h>
  34. #include <linux/netdevice.h>
  35. #include <linux/etherdevice.h>
  36. #include <linux/skbuff.h>
  37. #include <linux/spinlock.h>
  38. #include <linux/workqueue.h>
  39. #include <linux/bitops.h>
  40. #include <linux/io.h>
  41. #include <linux/irq.h>
  42. #include <linux/clk.h>
  43. #include <linux/platform_device.h>
  44. #include <linux/phy.h>
  45. #include <linux/fec.h>
  46. #include <linux/of.h>
  47. #include <linux/of_device.h>
  48. #include <linux/of_gpio.h>
  49. #include <linux/of_net.h>
  50. #include <linux/pinctrl/consumer.h>
  51. #include <linux/regulator/consumer.h>
  52. #include <asm/cacheflush.h>
  53. #ifndef CONFIG_ARM
  54. #include <asm/coldfire.h>
  55. #include <asm/mcfsim.h>
  56. #endif
  57. #include "fec.h"
  58. #if defined(CONFIG_ARM)
  59. #define FEC_ALIGNMENT 0xf
  60. #else
  61. #define FEC_ALIGNMENT 0x3
  62. #endif
  63. #define DRIVER_NAME "fec"
  64. /* Controller is ENET-MAC */
  65. #define FEC_QUIRK_ENET_MAC (1 << 0)
  66. /* Controller needs driver to swap frame */
  67. #define FEC_QUIRK_SWAP_FRAME (1 << 1)
  68. /* Controller uses gasket */
  69. #define FEC_QUIRK_USE_GASKET (1 << 2)
  70. /* Controller has GBIT support */
  71. #define FEC_QUIRK_HAS_GBIT (1 << 3)
  72. static struct platform_device_id fec_devtype[] = {
  73. {
  74. /* keep it for coldfire */
  75. .name = DRIVER_NAME,
  76. .driver_data = 0,
  77. }, {
  78. .name = "imx25-fec",
  79. .driver_data = FEC_QUIRK_USE_GASKET,
  80. }, {
  81. .name = "imx27-fec",
  82. .driver_data = 0,
  83. }, {
  84. .name = "imx28-fec",
  85. .driver_data = FEC_QUIRK_ENET_MAC | FEC_QUIRK_SWAP_FRAME,
  86. }, {
  87. .name = "imx6q-fec",
  88. .driver_data = FEC_QUIRK_ENET_MAC | FEC_QUIRK_HAS_GBIT,
  89. }, {
  90. /* sentinel */
  91. }
  92. };
  93. MODULE_DEVICE_TABLE(platform, fec_devtype);
  94. enum imx_fec_type {
  95. IMX25_FEC = 1, /* runs on i.mx25/50/53 */
  96. IMX27_FEC, /* runs on i.mx27/35/51 */
  97. IMX28_FEC,
  98. IMX6Q_FEC,
  99. };
  100. static const struct of_device_id fec_dt_ids[] = {
  101. { .compatible = "fsl,imx25-fec", .data = &fec_devtype[IMX25_FEC], },
  102. { .compatible = "fsl,imx27-fec", .data = &fec_devtype[IMX27_FEC], },
  103. { .compatible = "fsl,imx28-fec", .data = &fec_devtype[IMX28_FEC], },
  104. { .compatible = "fsl,imx6q-fec", .data = &fec_devtype[IMX6Q_FEC], },
  105. { /* sentinel */ }
  106. };
  107. MODULE_DEVICE_TABLE(of, fec_dt_ids);
  108. static unsigned char macaddr[ETH_ALEN];
  109. module_param_array(macaddr, byte, NULL, 0);
  110. MODULE_PARM_DESC(macaddr, "FEC Ethernet MAC address");
  111. #if defined(CONFIG_M5272)
  112. /*
  113. * Some hardware gets it MAC address out of local flash memory.
  114. * if this is non-zero then assume it is the address to get MAC from.
  115. */
  116. #if defined(CONFIG_NETtel)
  117. #define FEC_FLASHMAC 0xf0006006
  118. #elif defined(CONFIG_GILBARCONAP) || defined(CONFIG_SCALES)
  119. #define FEC_FLASHMAC 0xf0006000
  120. #elif defined(CONFIG_CANCam)
  121. #define FEC_FLASHMAC 0xf0020000
  122. #elif defined (CONFIG_M5272C3)
  123. #define FEC_FLASHMAC (0xffe04000 + 4)
  124. #elif defined(CONFIG_MOD5272)
  125. #define FEC_FLASHMAC 0xffc0406b
  126. #else
  127. #define FEC_FLASHMAC 0
  128. #endif
  129. #endif /* CONFIG_M5272 */
  130. /* The number of Tx and Rx buffers. These are allocated from the page
  131. * pool. The code may assume these are power of two, so it it best
  132. * to keep them that size.
  133. * We don't need to allocate pages for the transmitter. We just use
  134. * the skbuffer directly.
  135. */
  136. #define FEC_ENET_RX_PAGES 8
  137. #define FEC_ENET_RX_FRSIZE 2048
  138. #define FEC_ENET_RX_FRPPG (PAGE_SIZE / FEC_ENET_RX_FRSIZE)
  139. #define RX_RING_SIZE (FEC_ENET_RX_FRPPG * FEC_ENET_RX_PAGES)
  140. #define FEC_ENET_TX_FRSIZE 2048
  141. #define FEC_ENET_TX_FRPPG (PAGE_SIZE / FEC_ENET_TX_FRSIZE)
  142. #define TX_RING_SIZE 16 /* Must be power of two */
  143. #define TX_RING_MOD_MASK 15 /* for this to work */
  144. #if (((RX_RING_SIZE + TX_RING_SIZE) * 8) > PAGE_SIZE)
  145. #error "FEC: descriptor ring size constants too large"
  146. #endif
  147. /* Interrupt events/masks. */
  148. #define FEC_ENET_HBERR ((uint)0x80000000) /* Heartbeat error */
  149. #define FEC_ENET_BABR ((uint)0x40000000) /* Babbling receiver */
  150. #define FEC_ENET_BABT ((uint)0x20000000) /* Babbling transmitter */
  151. #define FEC_ENET_GRA ((uint)0x10000000) /* Graceful stop complete */
  152. #define FEC_ENET_TXF ((uint)0x08000000) /* Full frame transmitted */
  153. #define FEC_ENET_TXB ((uint)0x04000000) /* A buffer was transmitted */
  154. #define FEC_ENET_RXF ((uint)0x02000000) /* Full frame received */
  155. #define FEC_ENET_RXB ((uint)0x01000000) /* A buffer was received */
  156. #define FEC_ENET_MII ((uint)0x00800000) /* MII interrupt */
  157. #define FEC_ENET_EBERR ((uint)0x00400000) /* SDMA bus error */
  158. #define FEC_DEFAULT_IMASK (FEC_ENET_TXF | FEC_ENET_RXF | FEC_ENET_MII)
  159. /* The FEC stores dest/src/type, data, and checksum for receive packets.
  160. */
  161. #define PKT_MAXBUF_SIZE 1518
  162. #define PKT_MINBUF_SIZE 64
  163. #define PKT_MAXBLR_SIZE 1520
  164. /* This device has up to three irqs on some platforms */
  165. #define FEC_IRQ_NUM 3
  166. /*
  167. * The 5270/5271/5280/5282/532x RX control register also contains maximum frame
  168. * size bits. Other FEC hardware does not, so we need to take that into
  169. * account when setting it.
  170. */
  171. #if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x) || \
  172. defined(CONFIG_M520x) || defined(CONFIG_M532x) || defined(CONFIG_ARM)
  173. #define OPT_FRAME_SIZE (PKT_MAXBUF_SIZE << 16)
  174. #else
  175. #define OPT_FRAME_SIZE 0
  176. #endif
  177. /* The FEC buffer descriptors track the ring buffers. The rx_bd_base and
  178. * tx_bd_base always point to the base of the buffer descriptors. The
  179. * cur_rx and cur_tx point to the currently available buffer.
  180. * The dirty_tx tracks the current buffer that is being sent by the
  181. * controller. The cur_tx and dirty_tx are equal under both completely
  182. * empty and completely full conditions. The empty/ready indicator in
  183. * the buffer descriptor determines the actual condition.
  184. */
  185. struct fec_enet_private {
  186. /* Hardware registers of the FEC device */
  187. void __iomem *hwp;
  188. struct net_device *netdev;
  189. struct clk *clk_ipg;
  190. struct clk *clk_ahb;
  191. /* The saved address of a sent-in-place packet/buffer, for skfree(). */
  192. unsigned char *tx_bounce[TX_RING_SIZE];
  193. struct sk_buff* tx_skbuff[TX_RING_SIZE];
  194. struct sk_buff* rx_skbuff[RX_RING_SIZE];
  195. ushort skb_cur;
  196. ushort skb_dirty;
  197. /* CPM dual port RAM relative addresses */
  198. dma_addr_t bd_dma;
  199. /* Address of Rx and Tx buffers */
  200. struct bufdesc *rx_bd_base;
  201. struct bufdesc *tx_bd_base;
  202. /* The next free ring entry */
  203. struct bufdesc *cur_rx, *cur_tx;
  204. /* The ring entries to be free()ed */
  205. struct bufdesc *dirty_tx;
  206. uint tx_full;
  207. /* hold while accessing the HW like ringbuffer for tx/rx but not MAC */
  208. spinlock_t hw_lock;
  209. struct platform_device *pdev;
  210. int opened;
  211. int dev_id;
  212. /* Phylib and MDIO interface */
  213. struct mii_bus *mii_bus;
  214. struct phy_device *phy_dev;
  215. int mii_timeout;
  216. uint phy_speed;
  217. phy_interface_t phy_interface;
  218. int link;
  219. int full_duplex;
  220. struct completion mdio_done;
  221. int irq[FEC_IRQ_NUM];
  222. };
  223. /* FEC MII MMFR bits definition */
  224. #define FEC_MMFR_ST (1 << 30)
  225. #define FEC_MMFR_OP_READ (2 << 28)
  226. #define FEC_MMFR_OP_WRITE (1 << 28)
  227. #define FEC_MMFR_PA(v) ((v & 0x1f) << 23)
  228. #define FEC_MMFR_RA(v) ((v & 0x1f) << 18)
  229. #define FEC_MMFR_TA (2 << 16)
  230. #define FEC_MMFR_DATA(v) (v & 0xffff)
  231. #define FEC_MII_TIMEOUT 30000 /* us */
  232. /* Transmitter timeout */
  233. #define TX_TIMEOUT (2 * HZ)
  234. static int mii_cnt;
  235. static void *swap_buffer(void *bufaddr, int len)
  236. {
  237. int i;
  238. unsigned int *buf = bufaddr;
  239. for (i = 0; i < (len + 3) / 4; i++, buf++)
  240. *buf = cpu_to_be32(*buf);
  241. return bufaddr;
  242. }
  243. static netdev_tx_t
  244. fec_enet_start_xmit(struct sk_buff *skb, struct net_device *ndev)
  245. {
  246. struct fec_enet_private *fep = netdev_priv(ndev);
  247. const struct platform_device_id *id_entry =
  248. platform_get_device_id(fep->pdev);
  249. struct bufdesc *bdp;
  250. void *bufaddr;
  251. unsigned short status;
  252. unsigned long flags;
  253. if (!fep->link) {
  254. /* Link is down or autonegotiation is in progress. */
  255. return NETDEV_TX_BUSY;
  256. }
  257. spin_lock_irqsave(&fep->hw_lock, flags);
  258. /* Fill in a Tx ring entry */
  259. bdp = fep->cur_tx;
  260. status = bdp->cbd_sc;
  261. if (status & BD_ENET_TX_READY) {
  262. /* Ooops. All transmit buffers are full. Bail out.
  263. * This should not happen, since ndev->tbusy should be set.
  264. */
  265. printk("%s: tx queue full!.\n", ndev->name);
  266. spin_unlock_irqrestore(&fep->hw_lock, flags);
  267. return NETDEV_TX_BUSY;
  268. }
  269. /* Clear all of the status flags */
  270. status &= ~BD_ENET_TX_STATS;
  271. /* Set buffer length and buffer pointer */
  272. bufaddr = skb->data;
  273. bdp->cbd_datlen = skb->len;
  274. /*
  275. * On some FEC implementations data must be aligned on
  276. * 4-byte boundaries. Use bounce buffers to copy data
  277. * and get it aligned. Ugh.
  278. */
  279. if (((unsigned long) bufaddr) & FEC_ALIGNMENT) {
  280. unsigned int index;
  281. index = bdp - fep->tx_bd_base;
  282. memcpy(fep->tx_bounce[index], skb->data, skb->len);
  283. bufaddr = fep->tx_bounce[index];
  284. }
  285. /*
  286. * Some design made an incorrect assumption on endian mode of
  287. * the system that it's running on. As the result, driver has to
  288. * swap every frame going to and coming from the controller.
  289. */
  290. if (id_entry->driver_data & FEC_QUIRK_SWAP_FRAME)
  291. swap_buffer(bufaddr, skb->len);
  292. /* Save skb pointer */
  293. fep->tx_skbuff[fep->skb_cur] = skb;
  294. ndev->stats.tx_bytes += skb->len;
  295. fep->skb_cur = (fep->skb_cur+1) & TX_RING_MOD_MASK;
  296. /* Push the data cache so the CPM does not get stale memory
  297. * data.
  298. */
  299. bdp->cbd_bufaddr = dma_map_single(&fep->pdev->dev, bufaddr,
  300. FEC_ENET_TX_FRSIZE, DMA_TO_DEVICE);
  301. /* Send it on its way. Tell FEC it's ready, interrupt when done,
  302. * it's the last BD of the frame, and to put the CRC on the end.
  303. */
  304. status |= (BD_ENET_TX_READY | BD_ENET_TX_INTR
  305. | BD_ENET_TX_LAST | BD_ENET_TX_TC);
  306. bdp->cbd_sc = status;
  307. /* Trigger transmission start */
  308. writel(0, fep->hwp + FEC_X_DES_ACTIVE);
  309. /* If this was the last BD in the ring, start at the beginning again. */
  310. if (status & BD_ENET_TX_WRAP)
  311. bdp = fep->tx_bd_base;
  312. else
  313. bdp++;
  314. if (bdp == fep->dirty_tx) {
  315. fep->tx_full = 1;
  316. netif_stop_queue(ndev);
  317. }
  318. fep->cur_tx = bdp;
  319. skb_tx_timestamp(skb);
  320. spin_unlock_irqrestore(&fep->hw_lock, flags);
  321. return NETDEV_TX_OK;
  322. }
  323. /* This function is called to start or restart the FEC during a link
  324. * change. This only happens when switching between half and full
  325. * duplex.
  326. */
  327. static void
  328. fec_restart(struct net_device *ndev, int duplex)
  329. {
  330. struct fec_enet_private *fep = netdev_priv(ndev);
  331. const struct platform_device_id *id_entry =
  332. platform_get_device_id(fep->pdev);
  333. int i;
  334. u32 temp_mac[2];
  335. u32 rcntl = OPT_FRAME_SIZE | 0x04;
  336. u32 ecntl = 0x2; /* ETHEREN */
  337. /* Whack a reset. We should wait for this. */
  338. writel(1, fep->hwp + FEC_ECNTRL);
  339. udelay(10);
  340. /*
  341. * enet-mac reset will reset mac address registers too,
  342. * so need to reconfigure it.
  343. */
  344. if (id_entry->driver_data & FEC_QUIRK_ENET_MAC) {
  345. memcpy(&temp_mac, ndev->dev_addr, ETH_ALEN);
  346. writel(cpu_to_be32(temp_mac[0]), fep->hwp + FEC_ADDR_LOW);
  347. writel(cpu_to_be32(temp_mac[1]), fep->hwp + FEC_ADDR_HIGH);
  348. }
  349. /* Clear any outstanding interrupt. */
  350. writel(0xffc00000, fep->hwp + FEC_IEVENT);
  351. /* Reset all multicast. */
  352. writel(0, fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
  353. writel(0, fep->hwp + FEC_GRP_HASH_TABLE_LOW);
  354. #ifndef CONFIG_M5272
  355. writel(0, fep->hwp + FEC_HASH_TABLE_HIGH);
  356. writel(0, fep->hwp + FEC_HASH_TABLE_LOW);
  357. #endif
  358. /* Set maximum receive buffer size. */
  359. writel(PKT_MAXBLR_SIZE, fep->hwp + FEC_R_BUFF_SIZE);
  360. /* Set receive and transmit descriptor base. */
  361. writel(fep->bd_dma, fep->hwp + FEC_R_DES_START);
  362. writel((unsigned long)fep->bd_dma + sizeof(struct bufdesc) * RX_RING_SIZE,
  363. fep->hwp + FEC_X_DES_START);
  364. fep->dirty_tx = fep->cur_tx = fep->tx_bd_base;
  365. fep->cur_rx = fep->rx_bd_base;
  366. /* Reset SKB transmit buffers. */
  367. fep->skb_cur = fep->skb_dirty = 0;
  368. for (i = 0; i <= TX_RING_MOD_MASK; i++) {
  369. if (fep->tx_skbuff[i]) {
  370. dev_kfree_skb_any(fep->tx_skbuff[i]);
  371. fep->tx_skbuff[i] = NULL;
  372. }
  373. }
  374. /* Enable MII mode */
  375. if (duplex) {
  376. /* FD enable */
  377. writel(0x04, fep->hwp + FEC_X_CNTRL);
  378. } else {
  379. /* No Rcv on Xmit */
  380. rcntl |= 0x02;
  381. writel(0x0, fep->hwp + FEC_X_CNTRL);
  382. }
  383. fep->full_duplex = duplex;
  384. /* Set MII speed */
  385. writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED);
  386. /*
  387. * The phy interface and speed need to get configured
  388. * differently on enet-mac.
  389. */
  390. if (id_entry->driver_data & FEC_QUIRK_ENET_MAC) {
  391. /* Enable flow control and length check */
  392. rcntl |= 0x40000000 | 0x00000020;
  393. /* RGMII, RMII or MII */
  394. if (fep->phy_interface == PHY_INTERFACE_MODE_RGMII)
  395. rcntl |= (1 << 6);
  396. else if (fep->phy_interface == PHY_INTERFACE_MODE_RMII)
  397. rcntl |= (1 << 8);
  398. else
  399. rcntl &= ~(1 << 8);
  400. /* 1G, 100M or 10M */
  401. if (fep->phy_dev) {
  402. if (fep->phy_dev->speed == SPEED_1000)
  403. ecntl |= (1 << 5);
  404. else if (fep->phy_dev->speed == SPEED_100)
  405. rcntl &= ~(1 << 9);
  406. else
  407. rcntl |= (1 << 9);
  408. }
  409. } else {
  410. #ifdef FEC_MIIGSK_ENR
  411. if (id_entry->driver_data & FEC_QUIRK_USE_GASKET) {
  412. u32 cfgr;
  413. /* disable the gasket and wait */
  414. writel(0, fep->hwp + FEC_MIIGSK_ENR);
  415. while (readl(fep->hwp + FEC_MIIGSK_ENR) & 4)
  416. udelay(1);
  417. /*
  418. * configure the gasket:
  419. * RMII, 50 MHz, no loopback, no echo
  420. * MII, 25 MHz, no loopback, no echo
  421. */
  422. cfgr = (fep->phy_interface == PHY_INTERFACE_MODE_RMII)
  423. ? BM_MIIGSK_CFGR_RMII : BM_MIIGSK_CFGR_MII;
  424. if (fep->phy_dev && fep->phy_dev->speed == SPEED_10)
  425. cfgr |= BM_MIIGSK_CFGR_FRCONT_10M;
  426. writel(cfgr, fep->hwp + FEC_MIIGSK_CFGR);
  427. /* re-enable the gasket */
  428. writel(2, fep->hwp + FEC_MIIGSK_ENR);
  429. }
  430. #endif
  431. }
  432. writel(rcntl, fep->hwp + FEC_R_CNTRL);
  433. if (id_entry->driver_data & FEC_QUIRK_ENET_MAC) {
  434. /* enable ENET endian swap */
  435. ecntl |= (1 << 8);
  436. /* enable ENET store and forward mode */
  437. writel(1 << 8, fep->hwp + FEC_X_WMRK);
  438. }
  439. /* And last, enable the transmit and receive processing */
  440. writel(ecntl, fep->hwp + FEC_ECNTRL);
  441. writel(0, fep->hwp + FEC_R_DES_ACTIVE);
  442. /* Enable interrupts we wish to service */
  443. writel(FEC_DEFAULT_IMASK, fep->hwp + FEC_IMASK);
  444. }
  445. static void
  446. fec_stop(struct net_device *ndev)
  447. {
  448. struct fec_enet_private *fep = netdev_priv(ndev);
  449. const struct platform_device_id *id_entry =
  450. platform_get_device_id(fep->pdev);
  451. u32 rmii_mode = readl(fep->hwp + FEC_R_CNTRL) & (1 << 8);
  452. /* We cannot expect a graceful transmit stop without link !!! */
  453. if (fep->link) {
  454. writel(1, fep->hwp + FEC_X_CNTRL); /* Graceful transmit stop */
  455. udelay(10);
  456. if (!(readl(fep->hwp + FEC_IEVENT) & FEC_ENET_GRA))
  457. printk("fec_stop : Graceful transmit stop did not complete !\n");
  458. }
  459. /* Whack a reset. We should wait for this. */
  460. writel(1, fep->hwp + FEC_ECNTRL);
  461. udelay(10);
  462. writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED);
  463. writel(FEC_DEFAULT_IMASK, fep->hwp + FEC_IMASK);
  464. /* We have to keep ENET enabled to have MII interrupt stay working */
  465. if (id_entry->driver_data & FEC_QUIRK_ENET_MAC) {
  466. writel(2, fep->hwp + FEC_ECNTRL);
  467. writel(rmii_mode, fep->hwp + FEC_R_CNTRL);
  468. }
  469. }
  470. static void
  471. fec_timeout(struct net_device *ndev)
  472. {
  473. struct fec_enet_private *fep = netdev_priv(ndev);
  474. ndev->stats.tx_errors++;
  475. fec_restart(ndev, fep->full_duplex);
  476. netif_wake_queue(ndev);
  477. }
  478. static void
  479. fec_enet_tx(struct net_device *ndev)
  480. {
  481. struct fec_enet_private *fep;
  482. struct bufdesc *bdp;
  483. unsigned short status;
  484. struct sk_buff *skb;
  485. fep = netdev_priv(ndev);
  486. spin_lock(&fep->hw_lock);
  487. bdp = fep->dirty_tx;
  488. while (((status = bdp->cbd_sc) & BD_ENET_TX_READY) == 0) {
  489. if (bdp == fep->cur_tx && fep->tx_full == 0)
  490. break;
  491. dma_unmap_single(&fep->pdev->dev, bdp->cbd_bufaddr,
  492. FEC_ENET_TX_FRSIZE, DMA_TO_DEVICE);
  493. bdp->cbd_bufaddr = 0;
  494. skb = fep->tx_skbuff[fep->skb_dirty];
  495. /* Check for errors. */
  496. if (status & (BD_ENET_TX_HB | BD_ENET_TX_LC |
  497. BD_ENET_TX_RL | BD_ENET_TX_UN |
  498. BD_ENET_TX_CSL)) {
  499. ndev->stats.tx_errors++;
  500. if (status & BD_ENET_TX_HB) /* No heartbeat */
  501. ndev->stats.tx_heartbeat_errors++;
  502. if (status & BD_ENET_TX_LC) /* Late collision */
  503. ndev->stats.tx_window_errors++;
  504. if (status & BD_ENET_TX_RL) /* Retrans limit */
  505. ndev->stats.tx_aborted_errors++;
  506. if (status & BD_ENET_TX_UN) /* Underrun */
  507. ndev->stats.tx_fifo_errors++;
  508. if (status & BD_ENET_TX_CSL) /* Carrier lost */
  509. ndev->stats.tx_carrier_errors++;
  510. } else {
  511. ndev->stats.tx_packets++;
  512. }
  513. if (status & BD_ENET_TX_READY)
  514. printk("HEY! Enet xmit interrupt and TX_READY.\n");
  515. /* Deferred means some collisions occurred during transmit,
  516. * but we eventually sent the packet OK.
  517. */
  518. if (status & BD_ENET_TX_DEF)
  519. ndev->stats.collisions++;
  520. /* Free the sk buffer associated with this last transmit */
  521. dev_kfree_skb_any(skb);
  522. fep->tx_skbuff[fep->skb_dirty] = NULL;
  523. fep->skb_dirty = (fep->skb_dirty + 1) & TX_RING_MOD_MASK;
  524. /* Update pointer to next buffer descriptor to be transmitted */
  525. if (status & BD_ENET_TX_WRAP)
  526. bdp = fep->tx_bd_base;
  527. else
  528. bdp++;
  529. /* Since we have freed up a buffer, the ring is no longer full
  530. */
  531. if (fep->tx_full) {
  532. fep->tx_full = 0;
  533. if (netif_queue_stopped(ndev))
  534. netif_wake_queue(ndev);
  535. }
  536. }
  537. fep->dirty_tx = bdp;
  538. spin_unlock(&fep->hw_lock);
  539. }
  540. /* During a receive, the cur_rx points to the current incoming buffer.
  541. * When we update through the ring, if the next incoming buffer has
  542. * not been given to the system, we just set the empty indicator,
  543. * effectively tossing the packet.
  544. */
  545. static void
  546. fec_enet_rx(struct net_device *ndev)
  547. {
  548. struct fec_enet_private *fep = netdev_priv(ndev);
  549. const struct platform_device_id *id_entry =
  550. platform_get_device_id(fep->pdev);
  551. struct bufdesc *bdp;
  552. unsigned short status;
  553. struct sk_buff *skb;
  554. ushort pkt_len;
  555. __u8 *data;
  556. #ifdef CONFIG_M532x
  557. flush_cache_all();
  558. #endif
  559. spin_lock(&fep->hw_lock);
  560. /* First, grab all of the stats for the incoming packet.
  561. * These get messed up if we get called due to a busy condition.
  562. */
  563. bdp = fep->cur_rx;
  564. while (!((status = bdp->cbd_sc) & BD_ENET_RX_EMPTY)) {
  565. /* Since we have allocated space to hold a complete frame,
  566. * the last indicator should be set.
  567. */
  568. if ((status & BD_ENET_RX_LAST) == 0)
  569. printk("FEC ENET: rcv is not +last\n");
  570. if (!fep->opened)
  571. goto rx_processing_done;
  572. /* Check for errors. */
  573. if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH | BD_ENET_RX_NO |
  574. BD_ENET_RX_CR | BD_ENET_RX_OV)) {
  575. ndev->stats.rx_errors++;
  576. if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH)) {
  577. /* Frame too long or too short. */
  578. ndev->stats.rx_length_errors++;
  579. }
  580. if (status & BD_ENET_RX_NO) /* Frame alignment */
  581. ndev->stats.rx_frame_errors++;
  582. if (status & BD_ENET_RX_CR) /* CRC Error */
  583. ndev->stats.rx_crc_errors++;
  584. if (status & BD_ENET_RX_OV) /* FIFO overrun */
  585. ndev->stats.rx_fifo_errors++;
  586. }
  587. /* Report late collisions as a frame error.
  588. * On this error, the BD is closed, but we don't know what we
  589. * have in the buffer. So, just drop this frame on the floor.
  590. */
  591. if (status & BD_ENET_RX_CL) {
  592. ndev->stats.rx_errors++;
  593. ndev->stats.rx_frame_errors++;
  594. goto rx_processing_done;
  595. }
  596. /* Process the incoming frame. */
  597. ndev->stats.rx_packets++;
  598. pkt_len = bdp->cbd_datlen;
  599. ndev->stats.rx_bytes += pkt_len;
  600. data = (__u8*)__va(bdp->cbd_bufaddr);
  601. dma_unmap_single(&fep->pdev->dev, bdp->cbd_bufaddr,
  602. FEC_ENET_TX_FRSIZE, DMA_FROM_DEVICE);
  603. if (id_entry->driver_data & FEC_QUIRK_SWAP_FRAME)
  604. swap_buffer(data, pkt_len);
  605. /* This does 16 byte alignment, exactly what we need.
  606. * The packet length includes FCS, but we don't want to
  607. * include that when passing upstream as it messes up
  608. * bridging applications.
  609. */
  610. skb = netdev_alloc_skb(ndev, pkt_len - 4 + NET_IP_ALIGN);
  611. if (unlikely(!skb)) {
  612. printk("%s: Memory squeeze, dropping packet.\n",
  613. ndev->name);
  614. ndev->stats.rx_dropped++;
  615. } else {
  616. skb_reserve(skb, NET_IP_ALIGN);
  617. skb_put(skb, pkt_len - 4); /* Make room */
  618. skb_copy_to_linear_data(skb, data, pkt_len - 4);
  619. skb->protocol = eth_type_trans(skb, ndev);
  620. if (!skb_defer_rx_timestamp(skb))
  621. netif_rx(skb);
  622. }
  623. bdp->cbd_bufaddr = dma_map_single(&fep->pdev->dev, data,
  624. FEC_ENET_TX_FRSIZE, DMA_FROM_DEVICE);
  625. rx_processing_done:
  626. /* Clear the status flags for this buffer */
  627. status &= ~BD_ENET_RX_STATS;
  628. /* Mark the buffer empty */
  629. status |= BD_ENET_RX_EMPTY;
  630. bdp->cbd_sc = status;
  631. /* Update BD pointer to next entry */
  632. if (status & BD_ENET_RX_WRAP)
  633. bdp = fep->rx_bd_base;
  634. else
  635. bdp++;
  636. /* Doing this here will keep the FEC running while we process
  637. * incoming frames. On a heavily loaded network, we should be
  638. * able to keep up at the expense of system resources.
  639. */
  640. writel(0, fep->hwp + FEC_R_DES_ACTIVE);
  641. }
  642. fep->cur_rx = bdp;
  643. spin_unlock(&fep->hw_lock);
  644. }
  645. static irqreturn_t
  646. fec_enet_interrupt(int irq, void *dev_id)
  647. {
  648. struct net_device *ndev = dev_id;
  649. struct fec_enet_private *fep = netdev_priv(ndev);
  650. uint int_events;
  651. irqreturn_t ret = IRQ_NONE;
  652. do {
  653. int_events = readl(fep->hwp + FEC_IEVENT);
  654. writel(int_events, fep->hwp + FEC_IEVENT);
  655. if (int_events & FEC_ENET_RXF) {
  656. ret = IRQ_HANDLED;
  657. fec_enet_rx(ndev);
  658. }
  659. /* Transmit OK, or non-fatal error. Update the buffer
  660. * descriptors. FEC handles all errors, we just discover
  661. * them as part of the transmit process.
  662. */
  663. if (int_events & FEC_ENET_TXF) {
  664. ret = IRQ_HANDLED;
  665. fec_enet_tx(ndev);
  666. }
  667. if (int_events & FEC_ENET_MII) {
  668. ret = IRQ_HANDLED;
  669. complete(&fep->mdio_done);
  670. }
  671. } while (int_events);
  672. return ret;
  673. }
  674. /* ------------------------------------------------------------------------- */
  675. static void __inline__ fec_get_mac(struct net_device *ndev)
  676. {
  677. struct fec_enet_private *fep = netdev_priv(ndev);
  678. struct fec_platform_data *pdata = fep->pdev->dev.platform_data;
  679. unsigned char *iap, tmpaddr[ETH_ALEN];
  680. /*
  681. * try to get mac address in following order:
  682. *
  683. * 1) module parameter via kernel command line in form
  684. * fec.macaddr=0x00,0x04,0x9f,0x01,0x30,0xe0
  685. */
  686. iap = macaddr;
  687. #ifdef CONFIG_OF
  688. /*
  689. * 2) from device tree data
  690. */
  691. if (!is_valid_ether_addr(iap)) {
  692. struct device_node *np = fep->pdev->dev.of_node;
  693. if (np) {
  694. const char *mac = of_get_mac_address(np);
  695. if (mac)
  696. iap = (unsigned char *) mac;
  697. }
  698. }
  699. #endif
  700. /*
  701. * 3) from flash or fuse (via platform data)
  702. */
  703. if (!is_valid_ether_addr(iap)) {
  704. #ifdef CONFIG_M5272
  705. if (FEC_FLASHMAC)
  706. iap = (unsigned char *)FEC_FLASHMAC;
  707. #else
  708. if (pdata)
  709. iap = (unsigned char *)&pdata->mac;
  710. #endif
  711. }
  712. /*
  713. * 4) FEC mac registers set by bootloader
  714. */
  715. if (!is_valid_ether_addr(iap)) {
  716. *((unsigned long *) &tmpaddr[0]) =
  717. be32_to_cpu(readl(fep->hwp + FEC_ADDR_LOW));
  718. *((unsigned short *) &tmpaddr[4]) =
  719. be16_to_cpu(readl(fep->hwp + FEC_ADDR_HIGH) >> 16);
  720. iap = &tmpaddr[0];
  721. }
  722. memcpy(ndev->dev_addr, iap, ETH_ALEN);
  723. /* Adjust MAC if using macaddr */
  724. if (iap == macaddr)
  725. ndev->dev_addr[ETH_ALEN-1] = macaddr[ETH_ALEN-1] + fep->dev_id;
  726. }
  727. /* ------------------------------------------------------------------------- */
  728. /*
  729. * Phy section
  730. */
  731. static void fec_enet_adjust_link(struct net_device *ndev)
  732. {
  733. struct fec_enet_private *fep = netdev_priv(ndev);
  734. struct phy_device *phy_dev = fep->phy_dev;
  735. unsigned long flags;
  736. int status_change = 0;
  737. spin_lock_irqsave(&fep->hw_lock, flags);
  738. /* Prevent a state halted on mii error */
  739. if (fep->mii_timeout && phy_dev->state == PHY_HALTED) {
  740. phy_dev->state = PHY_RESUMING;
  741. goto spin_unlock;
  742. }
  743. /* Duplex link change */
  744. if (phy_dev->link) {
  745. if (fep->full_duplex != phy_dev->duplex) {
  746. fec_restart(ndev, phy_dev->duplex);
  747. /* prevent unnecessary second fec_restart() below */
  748. fep->link = phy_dev->link;
  749. status_change = 1;
  750. }
  751. }
  752. /* Link on or off change */
  753. if (phy_dev->link != fep->link) {
  754. fep->link = phy_dev->link;
  755. if (phy_dev->link)
  756. fec_restart(ndev, phy_dev->duplex);
  757. else
  758. fec_stop(ndev);
  759. status_change = 1;
  760. }
  761. spin_unlock:
  762. spin_unlock_irqrestore(&fep->hw_lock, flags);
  763. if (status_change)
  764. phy_print_status(phy_dev);
  765. }
  766. static int fec_enet_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
  767. {
  768. struct fec_enet_private *fep = bus->priv;
  769. unsigned long time_left;
  770. fep->mii_timeout = 0;
  771. init_completion(&fep->mdio_done);
  772. /* start a read op */
  773. writel(FEC_MMFR_ST | FEC_MMFR_OP_READ |
  774. FEC_MMFR_PA(mii_id) | FEC_MMFR_RA(regnum) |
  775. FEC_MMFR_TA, fep->hwp + FEC_MII_DATA);
  776. /* wait for end of transfer */
  777. time_left = wait_for_completion_timeout(&fep->mdio_done,
  778. usecs_to_jiffies(FEC_MII_TIMEOUT));
  779. if (time_left == 0) {
  780. fep->mii_timeout = 1;
  781. printk(KERN_ERR "FEC: MDIO read timeout\n");
  782. return -ETIMEDOUT;
  783. }
  784. /* return value */
  785. return FEC_MMFR_DATA(readl(fep->hwp + FEC_MII_DATA));
  786. }
  787. static int fec_enet_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
  788. u16 value)
  789. {
  790. struct fec_enet_private *fep = bus->priv;
  791. unsigned long time_left;
  792. fep->mii_timeout = 0;
  793. init_completion(&fep->mdio_done);
  794. /* start a write op */
  795. writel(FEC_MMFR_ST | FEC_MMFR_OP_WRITE |
  796. FEC_MMFR_PA(mii_id) | FEC_MMFR_RA(regnum) |
  797. FEC_MMFR_TA | FEC_MMFR_DATA(value),
  798. fep->hwp + FEC_MII_DATA);
  799. /* wait for end of transfer */
  800. time_left = wait_for_completion_timeout(&fep->mdio_done,
  801. usecs_to_jiffies(FEC_MII_TIMEOUT));
  802. if (time_left == 0) {
  803. fep->mii_timeout = 1;
  804. printk(KERN_ERR "FEC: MDIO write timeout\n");
  805. return -ETIMEDOUT;
  806. }
  807. return 0;
  808. }
  809. static int fec_enet_mdio_reset(struct mii_bus *bus)
  810. {
  811. return 0;
  812. }
  813. static int fec_enet_mii_probe(struct net_device *ndev)
  814. {
  815. struct fec_enet_private *fep = netdev_priv(ndev);
  816. const struct platform_device_id *id_entry =
  817. platform_get_device_id(fep->pdev);
  818. struct phy_device *phy_dev = NULL;
  819. char mdio_bus_id[MII_BUS_ID_SIZE];
  820. char phy_name[MII_BUS_ID_SIZE + 3];
  821. int phy_id;
  822. int dev_id = fep->dev_id;
  823. fep->phy_dev = NULL;
  824. /* check for attached phy */
  825. for (phy_id = 0; (phy_id < PHY_MAX_ADDR); phy_id++) {
  826. if ((fep->mii_bus->phy_mask & (1 << phy_id)))
  827. continue;
  828. if (fep->mii_bus->phy_map[phy_id] == NULL)
  829. continue;
  830. if (fep->mii_bus->phy_map[phy_id]->phy_id == 0)
  831. continue;
  832. if (dev_id--)
  833. continue;
  834. strncpy(mdio_bus_id, fep->mii_bus->id, MII_BUS_ID_SIZE);
  835. break;
  836. }
  837. if (phy_id >= PHY_MAX_ADDR) {
  838. printk(KERN_INFO
  839. "%s: no PHY, assuming direct connection to switch\n",
  840. ndev->name);
  841. strncpy(mdio_bus_id, "fixed-0", MII_BUS_ID_SIZE);
  842. phy_id = 0;
  843. }
  844. snprintf(phy_name, sizeof(phy_name), PHY_ID_FMT, mdio_bus_id, phy_id);
  845. phy_dev = phy_connect(ndev, phy_name, &fec_enet_adjust_link, 0,
  846. fep->phy_interface);
  847. if (IS_ERR(phy_dev)) {
  848. printk(KERN_ERR "%s: could not attach to PHY\n", ndev->name);
  849. return PTR_ERR(phy_dev);
  850. }
  851. /* mask with MAC supported features */
  852. if (id_entry->driver_data & FEC_QUIRK_HAS_GBIT)
  853. phy_dev->supported &= PHY_GBIT_FEATURES;
  854. else
  855. phy_dev->supported &= PHY_BASIC_FEATURES;
  856. phy_dev->advertising = phy_dev->supported;
  857. fep->phy_dev = phy_dev;
  858. fep->link = 0;
  859. fep->full_duplex = 0;
  860. printk(KERN_INFO
  861. "%s: Freescale FEC PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n",
  862. ndev->name,
  863. fep->phy_dev->drv->name, dev_name(&fep->phy_dev->dev),
  864. fep->phy_dev->irq);
  865. return 0;
  866. }
  867. static int fec_enet_mii_init(struct platform_device *pdev)
  868. {
  869. static struct mii_bus *fec0_mii_bus;
  870. struct net_device *ndev = platform_get_drvdata(pdev);
  871. struct fec_enet_private *fep = netdev_priv(ndev);
  872. const struct platform_device_id *id_entry =
  873. platform_get_device_id(fep->pdev);
  874. int err = -ENXIO, i;
  875. /*
  876. * The dual fec interfaces are not equivalent with enet-mac.
  877. * Here are the differences:
  878. *
  879. * - fec0 supports MII & RMII modes while fec1 only supports RMII
  880. * - fec0 acts as the 1588 time master while fec1 is slave
  881. * - external phys can only be configured by fec0
  882. *
  883. * That is to say fec1 can not work independently. It only works
  884. * when fec0 is working. The reason behind this design is that the
  885. * second interface is added primarily for Switch mode.
  886. *
  887. * Because of the last point above, both phys are attached on fec0
  888. * mdio interface in board design, and need to be configured by
  889. * fec0 mii_bus.
  890. */
  891. if ((id_entry->driver_data & FEC_QUIRK_ENET_MAC) && fep->dev_id > 0) {
  892. /* fec1 uses fec0 mii_bus */
  893. if (mii_cnt && fec0_mii_bus) {
  894. fep->mii_bus = fec0_mii_bus;
  895. mii_cnt++;
  896. return 0;
  897. }
  898. return -ENOENT;
  899. }
  900. fep->mii_timeout = 0;
  901. /*
  902. * Set MII speed to 2.5 MHz (= clk_get_rate() / 2 * phy_speed)
  903. *
  904. * The formula for FEC MDC is 'ref_freq / (MII_SPEED x 2)' while
  905. * for ENET-MAC is 'ref_freq / ((MII_SPEED + 1) x 2)'. The i.MX28
  906. * Reference Manual has an error on this, and gets fixed on i.MX6Q
  907. * document.
  908. */
  909. fep->phy_speed = DIV_ROUND_UP(clk_get_rate(fep->clk_ahb), 5000000);
  910. if (id_entry->driver_data & FEC_QUIRK_ENET_MAC)
  911. fep->phy_speed--;
  912. fep->phy_speed <<= 1;
  913. writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED);
  914. fep->mii_bus = mdiobus_alloc();
  915. if (fep->mii_bus == NULL) {
  916. err = -ENOMEM;
  917. goto err_out;
  918. }
  919. fep->mii_bus->name = "fec_enet_mii_bus";
  920. fep->mii_bus->read = fec_enet_mdio_read;
  921. fep->mii_bus->write = fec_enet_mdio_write;
  922. fep->mii_bus->reset = fec_enet_mdio_reset;
  923. snprintf(fep->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
  924. pdev->name, fep->dev_id + 1);
  925. fep->mii_bus->priv = fep;
  926. fep->mii_bus->parent = &pdev->dev;
  927. fep->mii_bus->irq = kmalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL);
  928. if (!fep->mii_bus->irq) {
  929. err = -ENOMEM;
  930. goto err_out_free_mdiobus;
  931. }
  932. for (i = 0; i < PHY_MAX_ADDR; i++)
  933. fep->mii_bus->irq[i] = PHY_POLL;
  934. if (mdiobus_register(fep->mii_bus))
  935. goto err_out_free_mdio_irq;
  936. mii_cnt++;
  937. /* save fec0 mii_bus */
  938. if (id_entry->driver_data & FEC_QUIRK_ENET_MAC)
  939. fec0_mii_bus = fep->mii_bus;
  940. return 0;
  941. err_out_free_mdio_irq:
  942. kfree(fep->mii_bus->irq);
  943. err_out_free_mdiobus:
  944. mdiobus_free(fep->mii_bus);
  945. err_out:
  946. return err;
  947. }
  948. static void fec_enet_mii_remove(struct fec_enet_private *fep)
  949. {
  950. if (--mii_cnt == 0) {
  951. mdiobus_unregister(fep->mii_bus);
  952. kfree(fep->mii_bus->irq);
  953. mdiobus_free(fep->mii_bus);
  954. }
  955. }
  956. static int fec_enet_get_settings(struct net_device *ndev,
  957. struct ethtool_cmd *cmd)
  958. {
  959. struct fec_enet_private *fep = netdev_priv(ndev);
  960. struct phy_device *phydev = fep->phy_dev;
  961. if (!phydev)
  962. return -ENODEV;
  963. return phy_ethtool_gset(phydev, cmd);
  964. }
  965. static int fec_enet_set_settings(struct net_device *ndev,
  966. struct ethtool_cmd *cmd)
  967. {
  968. struct fec_enet_private *fep = netdev_priv(ndev);
  969. struct phy_device *phydev = fep->phy_dev;
  970. if (!phydev)
  971. return -ENODEV;
  972. return phy_ethtool_sset(phydev, cmd);
  973. }
  974. static void fec_enet_get_drvinfo(struct net_device *ndev,
  975. struct ethtool_drvinfo *info)
  976. {
  977. struct fec_enet_private *fep = netdev_priv(ndev);
  978. strcpy(info->driver, fep->pdev->dev.driver->name);
  979. strcpy(info->version, "Revision: 1.0");
  980. strcpy(info->bus_info, dev_name(&ndev->dev));
  981. }
  982. static const struct ethtool_ops fec_enet_ethtool_ops = {
  983. .get_settings = fec_enet_get_settings,
  984. .set_settings = fec_enet_set_settings,
  985. .get_drvinfo = fec_enet_get_drvinfo,
  986. .get_link = ethtool_op_get_link,
  987. .get_ts_info = ethtool_op_get_ts_info,
  988. };
  989. static int fec_enet_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd)
  990. {
  991. struct fec_enet_private *fep = netdev_priv(ndev);
  992. struct phy_device *phydev = fep->phy_dev;
  993. if (!netif_running(ndev))
  994. return -EINVAL;
  995. if (!phydev)
  996. return -ENODEV;
  997. return phy_mii_ioctl(phydev, rq, cmd);
  998. }
  999. static void fec_enet_free_buffers(struct net_device *ndev)
  1000. {
  1001. struct fec_enet_private *fep = netdev_priv(ndev);
  1002. int i;
  1003. struct sk_buff *skb;
  1004. struct bufdesc *bdp;
  1005. bdp = fep->rx_bd_base;
  1006. for (i = 0; i < RX_RING_SIZE; i++) {
  1007. skb = fep->rx_skbuff[i];
  1008. if (bdp->cbd_bufaddr)
  1009. dma_unmap_single(&fep->pdev->dev, bdp->cbd_bufaddr,
  1010. FEC_ENET_RX_FRSIZE, DMA_FROM_DEVICE);
  1011. if (skb)
  1012. dev_kfree_skb(skb);
  1013. bdp++;
  1014. }
  1015. bdp = fep->tx_bd_base;
  1016. for (i = 0; i < TX_RING_SIZE; i++)
  1017. kfree(fep->tx_bounce[i]);
  1018. }
  1019. static int fec_enet_alloc_buffers(struct net_device *ndev)
  1020. {
  1021. struct fec_enet_private *fep = netdev_priv(ndev);
  1022. int i;
  1023. struct sk_buff *skb;
  1024. struct bufdesc *bdp;
  1025. bdp = fep->rx_bd_base;
  1026. for (i = 0; i < RX_RING_SIZE; i++) {
  1027. skb = netdev_alloc_skb(ndev, FEC_ENET_RX_FRSIZE);
  1028. if (!skb) {
  1029. fec_enet_free_buffers(ndev);
  1030. return -ENOMEM;
  1031. }
  1032. fep->rx_skbuff[i] = skb;
  1033. bdp->cbd_bufaddr = dma_map_single(&fep->pdev->dev, skb->data,
  1034. FEC_ENET_RX_FRSIZE, DMA_FROM_DEVICE);
  1035. bdp->cbd_sc = BD_ENET_RX_EMPTY;
  1036. bdp++;
  1037. }
  1038. /* Set the last buffer to wrap. */
  1039. bdp--;
  1040. bdp->cbd_sc |= BD_SC_WRAP;
  1041. bdp = fep->tx_bd_base;
  1042. for (i = 0; i < TX_RING_SIZE; i++) {
  1043. fep->tx_bounce[i] = kmalloc(FEC_ENET_TX_FRSIZE, GFP_KERNEL);
  1044. bdp->cbd_sc = 0;
  1045. bdp->cbd_bufaddr = 0;
  1046. bdp++;
  1047. }
  1048. /* Set the last buffer to wrap. */
  1049. bdp--;
  1050. bdp->cbd_sc |= BD_SC_WRAP;
  1051. return 0;
  1052. }
  1053. static int
  1054. fec_enet_open(struct net_device *ndev)
  1055. {
  1056. struct fec_enet_private *fep = netdev_priv(ndev);
  1057. int ret;
  1058. /* I should reset the ring buffers here, but I don't yet know
  1059. * a simple way to do that.
  1060. */
  1061. ret = fec_enet_alloc_buffers(ndev);
  1062. if (ret)
  1063. return ret;
  1064. /* Probe and connect to PHY when open the interface */
  1065. ret = fec_enet_mii_probe(ndev);
  1066. if (ret) {
  1067. fec_enet_free_buffers(ndev);
  1068. return ret;
  1069. }
  1070. phy_start(fep->phy_dev);
  1071. netif_start_queue(ndev);
  1072. fep->opened = 1;
  1073. return 0;
  1074. }
  1075. static int
  1076. fec_enet_close(struct net_device *ndev)
  1077. {
  1078. struct fec_enet_private *fep = netdev_priv(ndev);
  1079. /* Don't know what to do yet. */
  1080. fep->opened = 0;
  1081. netif_stop_queue(ndev);
  1082. fec_stop(ndev);
  1083. if (fep->phy_dev) {
  1084. phy_stop(fep->phy_dev);
  1085. phy_disconnect(fep->phy_dev);
  1086. }
  1087. fec_enet_free_buffers(ndev);
  1088. return 0;
  1089. }
  1090. /* Set or clear the multicast filter for this adaptor.
  1091. * Skeleton taken from sunlance driver.
  1092. * The CPM Ethernet implementation allows Multicast as well as individual
  1093. * MAC address filtering. Some of the drivers check to make sure it is
  1094. * a group multicast address, and discard those that are not. I guess I
  1095. * will do the same for now, but just remove the test if you want
  1096. * individual filtering as well (do the upper net layers want or support
  1097. * this kind of feature?).
  1098. */
  1099. #define HASH_BITS 6 /* #bits in hash */
  1100. #define CRC32_POLY 0xEDB88320
  1101. static void set_multicast_list(struct net_device *ndev)
  1102. {
  1103. struct fec_enet_private *fep = netdev_priv(ndev);
  1104. struct netdev_hw_addr *ha;
  1105. unsigned int i, bit, data, crc, tmp;
  1106. unsigned char hash;
  1107. if (ndev->flags & IFF_PROMISC) {
  1108. tmp = readl(fep->hwp + FEC_R_CNTRL);
  1109. tmp |= 0x8;
  1110. writel(tmp, fep->hwp + FEC_R_CNTRL);
  1111. return;
  1112. }
  1113. tmp = readl(fep->hwp + FEC_R_CNTRL);
  1114. tmp &= ~0x8;
  1115. writel(tmp, fep->hwp + FEC_R_CNTRL);
  1116. if (ndev->flags & IFF_ALLMULTI) {
  1117. /* Catch all multicast addresses, so set the
  1118. * filter to all 1's
  1119. */
  1120. writel(0xffffffff, fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
  1121. writel(0xffffffff, fep->hwp + FEC_GRP_HASH_TABLE_LOW);
  1122. return;
  1123. }
  1124. /* Clear filter and add the addresses in hash register
  1125. */
  1126. writel(0, fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
  1127. writel(0, fep->hwp + FEC_GRP_HASH_TABLE_LOW);
  1128. netdev_for_each_mc_addr(ha, ndev) {
  1129. /* calculate crc32 value of mac address */
  1130. crc = 0xffffffff;
  1131. for (i = 0; i < ndev->addr_len; i++) {
  1132. data = ha->addr[i];
  1133. for (bit = 0; bit < 8; bit++, data >>= 1) {
  1134. crc = (crc >> 1) ^
  1135. (((crc ^ data) & 1) ? CRC32_POLY : 0);
  1136. }
  1137. }
  1138. /* only upper 6 bits (HASH_BITS) are used
  1139. * which point to specific bit in he hash registers
  1140. */
  1141. hash = (crc >> (32 - HASH_BITS)) & 0x3f;
  1142. if (hash > 31) {
  1143. tmp = readl(fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
  1144. tmp |= 1 << (hash - 32);
  1145. writel(tmp, fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
  1146. } else {
  1147. tmp = readl(fep->hwp + FEC_GRP_HASH_TABLE_LOW);
  1148. tmp |= 1 << hash;
  1149. writel(tmp, fep->hwp + FEC_GRP_HASH_TABLE_LOW);
  1150. }
  1151. }
  1152. }
  1153. /* Set a MAC change in hardware. */
  1154. static int
  1155. fec_set_mac_address(struct net_device *ndev, void *p)
  1156. {
  1157. struct fec_enet_private *fep = netdev_priv(ndev);
  1158. struct sockaddr *addr = p;
  1159. if (!is_valid_ether_addr(addr->sa_data))
  1160. return -EADDRNOTAVAIL;
  1161. memcpy(ndev->dev_addr, addr->sa_data, ndev->addr_len);
  1162. writel(ndev->dev_addr[3] | (ndev->dev_addr[2] << 8) |
  1163. (ndev->dev_addr[1] << 16) | (ndev->dev_addr[0] << 24),
  1164. fep->hwp + FEC_ADDR_LOW);
  1165. writel((ndev->dev_addr[5] << 16) | (ndev->dev_addr[4] << 24),
  1166. fep->hwp + FEC_ADDR_HIGH);
  1167. return 0;
  1168. }
  1169. #ifdef CONFIG_NET_POLL_CONTROLLER
  1170. /*
  1171. * fec_poll_controller: FEC Poll controller function
  1172. * @dev: The FEC network adapter
  1173. *
  1174. * Polled functionality used by netconsole and others in non interrupt mode
  1175. *
  1176. */
  1177. void fec_poll_controller(struct net_device *dev)
  1178. {
  1179. int i;
  1180. struct fec_enet_private *fep = netdev_priv(dev);
  1181. for (i = 0; i < FEC_IRQ_NUM; i++) {
  1182. if (fep->irq[i] > 0) {
  1183. disable_irq(fep->irq[i]);
  1184. fec_enet_interrupt(fep->irq[i], dev);
  1185. enable_irq(fep->irq[i]);
  1186. }
  1187. }
  1188. }
  1189. #endif
  1190. static const struct net_device_ops fec_netdev_ops = {
  1191. .ndo_open = fec_enet_open,
  1192. .ndo_stop = fec_enet_close,
  1193. .ndo_start_xmit = fec_enet_start_xmit,
  1194. .ndo_set_rx_mode = set_multicast_list,
  1195. .ndo_change_mtu = eth_change_mtu,
  1196. .ndo_validate_addr = eth_validate_addr,
  1197. .ndo_tx_timeout = fec_timeout,
  1198. .ndo_set_mac_address = fec_set_mac_address,
  1199. .ndo_do_ioctl = fec_enet_ioctl,
  1200. #ifdef CONFIG_NET_POLL_CONTROLLER
  1201. .ndo_poll_controller = fec_poll_controller,
  1202. #endif
  1203. };
  1204. /*
  1205. * XXX: We need to clean up on failure exits here.
  1206. *
  1207. */
  1208. static int fec_enet_init(struct net_device *ndev)
  1209. {
  1210. struct fec_enet_private *fep = netdev_priv(ndev);
  1211. struct bufdesc *cbd_base;
  1212. struct bufdesc *bdp;
  1213. int i;
  1214. /* Allocate memory for buffer descriptors. */
  1215. cbd_base = dma_alloc_coherent(NULL, PAGE_SIZE, &fep->bd_dma,
  1216. GFP_KERNEL);
  1217. if (!cbd_base) {
  1218. printk("FEC: allocate descriptor memory failed?\n");
  1219. return -ENOMEM;
  1220. }
  1221. spin_lock_init(&fep->hw_lock);
  1222. fep->netdev = ndev;
  1223. /* Get the Ethernet address */
  1224. fec_get_mac(ndev);
  1225. /* Set receive and transmit descriptor base. */
  1226. fep->rx_bd_base = cbd_base;
  1227. fep->tx_bd_base = cbd_base + RX_RING_SIZE;
  1228. /* The FEC Ethernet specific entries in the device structure */
  1229. ndev->watchdog_timeo = TX_TIMEOUT;
  1230. ndev->netdev_ops = &fec_netdev_ops;
  1231. ndev->ethtool_ops = &fec_enet_ethtool_ops;
  1232. /* Initialize the receive buffer descriptors. */
  1233. bdp = fep->rx_bd_base;
  1234. for (i = 0; i < RX_RING_SIZE; i++) {
  1235. /* Initialize the BD for every fragment in the page. */
  1236. bdp->cbd_sc = 0;
  1237. bdp++;
  1238. }
  1239. /* Set the last buffer to wrap */
  1240. bdp--;
  1241. bdp->cbd_sc |= BD_SC_WRAP;
  1242. /* ...and the same for transmit */
  1243. bdp = fep->tx_bd_base;
  1244. for (i = 0; i < TX_RING_SIZE; i++) {
  1245. /* Initialize the BD for every fragment in the page. */
  1246. bdp->cbd_sc = 0;
  1247. bdp->cbd_bufaddr = 0;
  1248. bdp++;
  1249. }
  1250. /* Set the last buffer to wrap */
  1251. bdp--;
  1252. bdp->cbd_sc |= BD_SC_WRAP;
  1253. fec_restart(ndev, 0);
  1254. return 0;
  1255. }
  1256. #ifdef CONFIG_OF
  1257. static int __devinit fec_get_phy_mode_dt(struct platform_device *pdev)
  1258. {
  1259. struct device_node *np = pdev->dev.of_node;
  1260. if (np)
  1261. return of_get_phy_mode(np);
  1262. return -ENODEV;
  1263. }
  1264. static void __devinit fec_reset_phy(struct platform_device *pdev)
  1265. {
  1266. int err, phy_reset;
  1267. struct device_node *np = pdev->dev.of_node;
  1268. if (!np)
  1269. return;
  1270. phy_reset = of_get_named_gpio(np, "phy-reset-gpios", 0);
  1271. err = gpio_request_one(phy_reset, GPIOF_OUT_INIT_LOW, "phy-reset");
  1272. if (err) {
  1273. pr_debug("FEC: failed to get gpio phy-reset: %d\n", err);
  1274. return;
  1275. }
  1276. msleep(1);
  1277. gpio_set_value(phy_reset, 1);
  1278. }
  1279. #else /* CONFIG_OF */
  1280. static inline int fec_get_phy_mode_dt(struct platform_device *pdev)
  1281. {
  1282. return -ENODEV;
  1283. }
  1284. static inline void fec_reset_phy(struct platform_device *pdev)
  1285. {
  1286. /*
  1287. * In case of platform probe, the reset has been done
  1288. * by machine code.
  1289. */
  1290. }
  1291. #endif /* CONFIG_OF */
  1292. static int __devinit
  1293. fec_probe(struct platform_device *pdev)
  1294. {
  1295. struct fec_enet_private *fep;
  1296. struct fec_platform_data *pdata;
  1297. struct net_device *ndev;
  1298. int i, irq, ret = 0;
  1299. struct resource *r;
  1300. const struct of_device_id *of_id;
  1301. static int dev_id;
  1302. struct pinctrl *pinctrl;
  1303. struct regulator *reg_phy;
  1304. of_id = of_match_device(fec_dt_ids, &pdev->dev);
  1305. if (of_id)
  1306. pdev->id_entry = of_id->data;
  1307. r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1308. if (!r)
  1309. return -ENXIO;
  1310. r = request_mem_region(r->start, resource_size(r), pdev->name);
  1311. if (!r)
  1312. return -EBUSY;
  1313. /* Init network device */
  1314. ndev = alloc_etherdev(sizeof(struct fec_enet_private));
  1315. if (!ndev) {
  1316. ret = -ENOMEM;
  1317. goto failed_alloc_etherdev;
  1318. }
  1319. SET_NETDEV_DEV(ndev, &pdev->dev);
  1320. /* setup board info structure */
  1321. fep = netdev_priv(ndev);
  1322. fep->hwp = ioremap(r->start, resource_size(r));
  1323. fep->pdev = pdev;
  1324. fep->dev_id = dev_id++;
  1325. if (!fep->hwp) {
  1326. ret = -ENOMEM;
  1327. goto failed_ioremap;
  1328. }
  1329. platform_set_drvdata(pdev, ndev);
  1330. ret = fec_get_phy_mode_dt(pdev);
  1331. if (ret < 0) {
  1332. pdata = pdev->dev.platform_data;
  1333. if (pdata)
  1334. fep->phy_interface = pdata->phy;
  1335. else
  1336. fep->phy_interface = PHY_INTERFACE_MODE_MII;
  1337. } else {
  1338. fep->phy_interface = ret;
  1339. }
  1340. for (i = 0; i < FEC_IRQ_NUM; i++) {
  1341. irq = platform_get_irq(pdev, i);
  1342. if (irq < 0) {
  1343. if (i)
  1344. break;
  1345. ret = irq;
  1346. goto failed_irq;
  1347. }
  1348. ret = request_irq(irq, fec_enet_interrupt, IRQF_DISABLED, pdev->name, ndev);
  1349. if (ret) {
  1350. while (--i >= 0) {
  1351. irq = platform_get_irq(pdev, i);
  1352. free_irq(irq, ndev);
  1353. }
  1354. goto failed_irq;
  1355. }
  1356. }
  1357. pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
  1358. if (IS_ERR(pinctrl)) {
  1359. ret = PTR_ERR(pinctrl);
  1360. goto failed_pin;
  1361. }
  1362. fep->clk_ipg = devm_clk_get(&pdev->dev, "ipg");
  1363. if (IS_ERR(fep->clk_ipg)) {
  1364. ret = PTR_ERR(fep->clk_ipg);
  1365. goto failed_clk;
  1366. }
  1367. fep->clk_ahb = devm_clk_get(&pdev->dev, "ahb");
  1368. if (IS_ERR(fep->clk_ahb)) {
  1369. ret = PTR_ERR(fep->clk_ahb);
  1370. goto failed_clk;
  1371. }
  1372. clk_prepare_enable(fep->clk_ahb);
  1373. clk_prepare_enable(fep->clk_ipg);
  1374. reg_phy = devm_regulator_get(&pdev->dev, "phy");
  1375. if (!IS_ERR(reg_phy)) {
  1376. ret = regulator_enable(reg_phy);
  1377. if (ret) {
  1378. dev_err(&pdev->dev,
  1379. "Failed to enable phy regulator: %d\n", ret);
  1380. goto failed_regulator;
  1381. }
  1382. }
  1383. fec_reset_phy(pdev);
  1384. ret = fec_enet_init(ndev);
  1385. if (ret)
  1386. goto failed_init;
  1387. ret = fec_enet_mii_init(pdev);
  1388. if (ret)
  1389. goto failed_mii_init;
  1390. /* Carrier starts down, phylib will bring it up */
  1391. netif_carrier_off(ndev);
  1392. ret = register_netdev(ndev);
  1393. if (ret)
  1394. goto failed_register;
  1395. return 0;
  1396. failed_register:
  1397. fec_enet_mii_remove(fep);
  1398. failed_mii_init:
  1399. failed_init:
  1400. failed_regulator:
  1401. clk_disable_unprepare(fep->clk_ahb);
  1402. clk_disable_unprepare(fep->clk_ipg);
  1403. failed_pin:
  1404. failed_clk:
  1405. for (i = 0; i < FEC_IRQ_NUM; i++) {
  1406. irq = platform_get_irq(pdev, i);
  1407. if (irq > 0)
  1408. free_irq(irq, ndev);
  1409. }
  1410. failed_irq:
  1411. iounmap(fep->hwp);
  1412. failed_ioremap:
  1413. free_netdev(ndev);
  1414. failed_alloc_etherdev:
  1415. release_mem_region(r->start, resource_size(r));
  1416. return ret;
  1417. }
  1418. static int __devexit
  1419. fec_drv_remove(struct platform_device *pdev)
  1420. {
  1421. struct net_device *ndev = platform_get_drvdata(pdev);
  1422. struct fec_enet_private *fep = netdev_priv(ndev);
  1423. struct resource *r;
  1424. int i;
  1425. unregister_netdev(ndev);
  1426. fec_enet_mii_remove(fep);
  1427. for (i = 0; i < FEC_IRQ_NUM; i++) {
  1428. int irq = platform_get_irq(pdev, i);
  1429. if (irq > 0)
  1430. free_irq(irq, ndev);
  1431. }
  1432. clk_disable_unprepare(fep->clk_ahb);
  1433. clk_disable_unprepare(fep->clk_ipg);
  1434. iounmap(fep->hwp);
  1435. free_netdev(ndev);
  1436. r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1437. BUG_ON(!r);
  1438. release_mem_region(r->start, resource_size(r));
  1439. platform_set_drvdata(pdev, NULL);
  1440. return 0;
  1441. }
  1442. #ifdef CONFIG_PM
  1443. static int
  1444. fec_suspend(struct device *dev)
  1445. {
  1446. struct net_device *ndev = dev_get_drvdata(dev);
  1447. struct fec_enet_private *fep = netdev_priv(ndev);
  1448. if (netif_running(ndev)) {
  1449. fec_stop(ndev);
  1450. netif_device_detach(ndev);
  1451. }
  1452. clk_disable_unprepare(fep->clk_ahb);
  1453. clk_disable_unprepare(fep->clk_ipg);
  1454. return 0;
  1455. }
  1456. static int
  1457. fec_resume(struct device *dev)
  1458. {
  1459. struct net_device *ndev = dev_get_drvdata(dev);
  1460. struct fec_enet_private *fep = netdev_priv(ndev);
  1461. clk_prepare_enable(fep->clk_ahb);
  1462. clk_prepare_enable(fep->clk_ipg);
  1463. if (netif_running(ndev)) {
  1464. fec_restart(ndev, fep->full_duplex);
  1465. netif_device_attach(ndev);
  1466. }
  1467. return 0;
  1468. }
  1469. static const struct dev_pm_ops fec_pm_ops = {
  1470. .suspend = fec_suspend,
  1471. .resume = fec_resume,
  1472. .freeze = fec_suspend,
  1473. .thaw = fec_resume,
  1474. .poweroff = fec_suspend,
  1475. .restore = fec_resume,
  1476. };
  1477. #endif
  1478. static struct platform_driver fec_driver = {
  1479. .driver = {
  1480. .name = DRIVER_NAME,
  1481. .owner = THIS_MODULE,
  1482. #ifdef CONFIG_PM
  1483. .pm = &fec_pm_ops,
  1484. #endif
  1485. .of_match_table = fec_dt_ids,
  1486. },
  1487. .id_table = fec_devtype,
  1488. .probe = fec_probe,
  1489. .remove = __devexit_p(fec_drv_remove),
  1490. };
  1491. module_platform_driver(fec_driver);
  1492. MODULE_LICENSE("GPL");