lpc_eth.c 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607
  1. /*
  2. * drivers/net/ethernet/nxp/lpc_eth.c
  3. *
  4. * Author: Kevin Wells <kevin.wells@nxp.com>
  5. *
  6. * Copyright (C) 2010 NXP Semiconductors
  7. * Copyright (C) 2012 Roland Stigge <stigge@antcom.de>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. */
  19. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  20. #include <linux/init.h>
  21. #include <linux/module.h>
  22. #include <linux/kernel.h>
  23. #include <linux/sched.h>
  24. #include <linux/slab.h>
  25. #include <linux/delay.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/errno.h>
  28. #include <linux/ioport.h>
  29. #include <linux/crc32.h>
  30. #include <linux/platform_device.h>
  31. #include <linux/spinlock.h>
  32. #include <linux/ethtool.h>
  33. #include <linux/mii.h>
  34. #include <linux/clk.h>
  35. #include <linux/workqueue.h>
  36. #include <linux/netdevice.h>
  37. #include <linux/etherdevice.h>
  38. #include <linux/skbuff.h>
  39. #include <linux/phy.h>
  40. #include <linux/dma-mapping.h>
  41. #include <linux/of_net.h>
  42. #include <linux/types.h>
  43. #include <linux/delay.h>
  44. #include <linux/io.h>
  45. #include <mach/board.h>
  46. #include <mach/platform.h>
  47. #include <mach/hardware.h>
  48. #define MODNAME "lpc-eth"
  49. #define DRV_VERSION "1.00"
  50. #define PHYDEF_ADDR 0x00
  51. #define ENET_MAXF_SIZE 1536
  52. #define ENET_RX_DESC 48
  53. #define ENET_TX_DESC 16
  54. #define NAPI_WEIGHT 16
  55. /*
  56. * Ethernet MAC controller Register offsets
  57. */
  58. #define LPC_ENET_MAC1(x) (x + 0x000)
  59. #define LPC_ENET_MAC2(x) (x + 0x004)
  60. #define LPC_ENET_IPGT(x) (x + 0x008)
  61. #define LPC_ENET_IPGR(x) (x + 0x00C)
  62. #define LPC_ENET_CLRT(x) (x + 0x010)
  63. #define LPC_ENET_MAXF(x) (x + 0x014)
  64. #define LPC_ENET_SUPP(x) (x + 0x018)
  65. #define LPC_ENET_TEST(x) (x + 0x01C)
  66. #define LPC_ENET_MCFG(x) (x + 0x020)
  67. #define LPC_ENET_MCMD(x) (x + 0x024)
  68. #define LPC_ENET_MADR(x) (x + 0x028)
  69. #define LPC_ENET_MWTD(x) (x + 0x02C)
  70. #define LPC_ENET_MRDD(x) (x + 0x030)
  71. #define LPC_ENET_MIND(x) (x + 0x034)
  72. #define LPC_ENET_SA0(x) (x + 0x040)
  73. #define LPC_ENET_SA1(x) (x + 0x044)
  74. #define LPC_ENET_SA2(x) (x + 0x048)
  75. #define LPC_ENET_COMMAND(x) (x + 0x100)
  76. #define LPC_ENET_STATUS(x) (x + 0x104)
  77. #define LPC_ENET_RXDESCRIPTOR(x) (x + 0x108)
  78. #define LPC_ENET_RXSTATUS(x) (x + 0x10C)
  79. #define LPC_ENET_RXDESCRIPTORNUMBER(x) (x + 0x110)
  80. #define LPC_ENET_RXPRODUCEINDEX(x) (x + 0x114)
  81. #define LPC_ENET_RXCONSUMEINDEX(x) (x + 0x118)
  82. #define LPC_ENET_TXDESCRIPTOR(x) (x + 0x11C)
  83. #define LPC_ENET_TXSTATUS(x) (x + 0x120)
  84. #define LPC_ENET_TXDESCRIPTORNUMBER(x) (x + 0x124)
  85. #define LPC_ENET_TXPRODUCEINDEX(x) (x + 0x128)
  86. #define LPC_ENET_TXCONSUMEINDEX(x) (x + 0x12C)
  87. #define LPC_ENET_TSV0(x) (x + 0x158)
  88. #define LPC_ENET_TSV1(x) (x + 0x15C)
  89. #define LPC_ENET_RSV(x) (x + 0x160)
  90. #define LPC_ENET_FLOWCONTROLCOUNTER(x) (x + 0x170)
  91. #define LPC_ENET_FLOWCONTROLSTATUS(x) (x + 0x174)
  92. #define LPC_ENET_RXFILTER_CTRL(x) (x + 0x200)
  93. #define LPC_ENET_RXFILTERWOLSTATUS(x) (x + 0x204)
  94. #define LPC_ENET_RXFILTERWOLCLEAR(x) (x + 0x208)
  95. #define LPC_ENET_HASHFILTERL(x) (x + 0x210)
  96. #define LPC_ENET_HASHFILTERH(x) (x + 0x214)
  97. #define LPC_ENET_INTSTATUS(x) (x + 0xFE0)
  98. #define LPC_ENET_INTENABLE(x) (x + 0xFE4)
  99. #define LPC_ENET_INTCLEAR(x) (x + 0xFE8)
  100. #define LPC_ENET_INTSET(x) (x + 0xFEC)
  101. #define LPC_ENET_POWERDOWN(x) (x + 0xFF4)
  102. /*
  103. * mac1 register definitions
  104. */
  105. #define LPC_MAC1_RECV_ENABLE (1 << 0)
  106. #define LPC_MAC1_PASS_ALL_RX_FRAMES (1 << 1)
  107. #define LPC_MAC1_RX_FLOW_CONTROL (1 << 2)
  108. #define LPC_MAC1_TX_FLOW_CONTROL (1 << 3)
  109. #define LPC_MAC1_LOOPBACK (1 << 4)
  110. #define LPC_MAC1_RESET_TX (1 << 8)
  111. #define LPC_MAC1_RESET_MCS_TX (1 << 9)
  112. #define LPC_MAC1_RESET_RX (1 << 10)
  113. #define LPC_MAC1_RESET_MCS_RX (1 << 11)
  114. #define LPC_MAC1_SIMULATION_RESET (1 << 14)
  115. #define LPC_MAC1_SOFT_RESET (1 << 15)
  116. /*
  117. * mac2 register definitions
  118. */
  119. #define LPC_MAC2_FULL_DUPLEX (1 << 0)
  120. #define LPC_MAC2_FRAME_LENGTH_CHECKING (1 << 1)
  121. #define LPC_MAC2_HUGH_LENGTH_CHECKING (1 << 2)
  122. #define LPC_MAC2_DELAYED_CRC (1 << 3)
  123. #define LPC_MAC2_CRC_ENABLE (1 << 4)
  124. #define LPC_MAC2_PAD_CRC_ENABLE (1 << 5)
  125. #define LPC_MAC2_VLAN_PAD_ENABLE (1 << 6)
  126. #define LPC_MAC2_AUTO_DETECT_PAD_ENABLE (1 << 7)
  127. #define LPC_MAC2_PURE_PREAMBLE_ENFORCEMENT (1 << 8)
  128. #define LPC_MAC2_LONG_PREAMBLE_ENFORCEMENT (1 << 9)
  129. #define LPC_MAC2_NO_BACKOFF (1 << 12)
  130. #define LPC_MAC2_BACK_PRESSURE (1 << 13)
  131. #define LPC_MAC2_EXCESS_DEFER (1 << 14)
  132. /*
  133. * ipgt register definitions
  134. */
  135. #define LPC_IPGT_LOAD(n) ((n) & 0x7F)
  136. /*
  137. * ipgr register definitions
  138. */
  139. #define LPC_IPGR_LOAD_PART2(n) ((n) & 0x7F)
  140. #define LPC_IPGR_LOAD_PART1(n) (((n) & 0x7F) << 8)
  141. /*
  142. * clrt register definitions
  143. */
  144. #define LPC_CLRT_LOAD_RETRY_MAX(n) ((n) & 0xF)
  145. #define LPC_CLRT_LOAD_COLLISION_WINDOW(n) (((n) & 0x3F) << 8)
  146. /*
  147. * maxf register definitions
  148. */
  149. #define LPC_MAXF_LOAD_MAX_FRAME_LEN(n) ((n) & 0xFFFF)
  150. /*
  151. * supp register definitions
  152. */
  153. #define LPC_SUPP_SPEED (1 << 8)
  154. #define LPC_SUPP_RESET_RMII (1 << 11)
  155. /*
  156. * test register definitions
  157. */
  158. #define LPC_TEST_SHORTCUT_PAUSE_QUANTA (1 << 0)
  159. #define LPC_TEST_PAUSE (1 << 1)
  160. #define LPC_TEST_BACKPRESSURE (1 << 2)
  161. /*
  162. * mcfg register definitions
  163. */
  164. #define LPC_MCFG_SCAN_INCREMENT (1 << 0)
  165. #define LPC_MCFG_SUPPRESS_PREAMBLE (1 << 1)
  166. #define LPC_MCFG_CLOCK_SELECT(n) (((n) & 0x7) << 2)
  167. #define LPC_MCFG_CLOCK_HOST_DIV_4 0
  168. #define LPC_MCFG_CLOCK_HOST_DIV_6 2
  169. #define LPC_MCFG_CLOCK_HOST_DIV_8 3
  170. #define LPC_MCFG_CLOCK_HOST_DIV_10 4
  171. #define LPC_MCFG_CLOCK_HOST_DIV_14 5
  172. #define LPC_MCFG_CLOCK_HOST_DIV_20 6
  173. #define LPC_MCFG_CLOCK_HOST_DIV_28 7
  174. #define LPC_MCFG_RESET_MII_MGMT (1 << 15)
  175. /*
  176. * mcmd register definitions
  177. */
  178. #define LPC_MCMD_READ (1 << 0)
  179. #define LPC_MCMD_SCAN (1 << 1)
  180. /*
  181. * madr register definitions
  182. */
  183. #define LPC_MADR_REGISTER_ADDRESS(n) ((n) & 0x1F)
  184. #define LPC_MADR_PHY_0ADDRESS(n) (((n) & 0x1F) << 8)
  185. /*
  186. * mwtd register definitions
  187. */
  188. #define LPC_MWDT_WRITE(n) ((n) & 0xFFFF)
  189. /*
  190. * mrdd register definitions
  191. */
  192. #define LPC_MRDD_READ_MASK 0xFFFF
  193. /*
  194. * mind register definitions
  195. */
  196. #define LPC_MIND_BUSY (1 << 0)
  197. #define LPC_MIND_SCANNING (1 << 1)
  198. #define LPC_MIND_NOT_VALID (1 << 2)
  199. #define LPC_MIND_MII_LINK_FAIL (1 << 3)
  200. /*
  201. * command register definitions
  202. */
  203. #define LPC_COMMAND_RXENABLE (1 << 0)
  204. #define LPC_COMMAND_TXENABLE (1 << 1)
  205. #define LPC_COMMAND_REG_RESET (1 << 3)
  206. #define LPC_COMMAND_TXRESET (1 << 4)
  207. #define LPC_COMMAND_RXRESET (1 << 5)
  208. #define LPC_COMMAND_PASSRUNTFRAME (1 << 6)
  209. #define LPC_COMMAND_PASSRXFILTER (1 << 7)
  210. #define LPC_COMMAND_TXFLOWCONTROL (1 << 8)
  211. #define LPC_COMMAND_RMII (1 << 9)
  212. #define LPC_COMMAND_FULLDUPLEX (1 << 10)
  213. /*
  214. * status register definitions
  215. */
  216. #define LPC_STATUS_RXACTIVE (1 << 0)
  217. #define LPC_STATUS_TXACTIVE (1 << 1)
  218. /*
  219. * tsv0 register definitions
  220. */
  221. #define LPC_TSV0_CRC_ERROR (1 << 0)
  222. #define LPC_TSV0_LENGTH_CHECK_ERROR (1 << 1)
  223. #define LPC_TSV0_LENGTH_OUT_OF_RANGE (1 << 2)
  224. #define LPC_TSV0_DONE (1 << 3)
  225. #define LPC_TSV0_MULTICAST (1 << 4)
  226. #define LPC_TSV0_BROADCAST (1 << 5)
  227. #define LPC_TSV0_PACKET_DEFER (1 << 6)
  228. #define LPC_TSV0_ESCESSIVE_DEFER (1 << 7)
  229. #define LPC_TSV0_ESCESSIVE_COLLISION (1 << 8)
  230. #define LPC_TSV0_LATE_COLLISION (1 << 9)
  231. #define LPC_TSV0_GIANT (1 << 10)
  232. #define LPC_TSV0_UNDERRUN (1 << 11)
  233. #define LPC_TSV0_TOTAL_BYTES(n) (((n) >> 12) & 0xFFFF)
  234. #define LPC_TSV0_CONTROL_FRAME (1 << 28)
  235. #define LPC_TSV0_PAUSE (1 << 29)
  236. #define LPC_TSV0_BACKPRESSURE (1 << 30)
  237. #define LPC_TSV0_VLAN (1 << 31)
  238. /*
  239. * tsv1 register definitions
  240. */
  241. #define LPC_TSV1_TRANSMIT_BYTE_COUNT(n) ((n) & 0xFFFF)
  242. #define LPC_TSV1_COLLISION_COUNT(n) (((n) >> 16) & 0xF)
  243. /*
  244. * rsv register definitions
  245. */
  246. #define LPC_RSV_RECEIVED_BYTE_COUNT(n) ((n) & 0xFFFF)
  247. #define LPC_RSV_RXDV_EVENT_IGNORED (1 << 16)
  248. #define LPC_RSV_RXDV_EVENT_PREVIOUSLY_SEEN (1 << 17)
  249. #define LPC_RSV_CARRIER_EVNT_PREVIOUS_SEEN (1 << 18)
  250. #define LPC_RSV_RECEIVE_CODE_VIOLATION (1 << 19)
  251. #define LPC_RSV_CRC_ERROR (1 << 20)
  252. #define LPC_RSV_LENGTH_CHECK_ERROR (1 << 21)
  253. #define LPC_RSV_LENGTH_OUT_OF_RANGE (1 << 22)
  254. #define LPC_RSV_RECEIVE_OK (1 << 23)
  255. #define LPC_RSV_MULTICAST (1 << 24)
  256. #define LPC_RSV_BROADCAST (1 << 25)
  257. #define LPC_RSV_DRIBBLE_NIBBLE (1 << 26)
  258. #define LPC_RSV_CONTROL_FRAME (1 << 27)
  259. #define LPC_RSV_PAUSE (1 << 28)
  260. #define LPC_RSV_UNSUPPORTED_OPCODE (1 << 29)
  261. #define LPC_RSV_VLAN (1 << 30)
  262. /*
  263. * flowcontrolcounter register definitions
  264. */
  265. #define LPC_FCCR_MIRRORCOUNTER(n) ((n) & 0xFFFF)
  266. #define LPC_FCCR_PAUSETIMER(n) (((n) >> 16) & 0xFFFF)
  267. /*
  268. * flowcontrolstatus register definitions
  269. */
  270. #define LPC_FCCR_MIRRORCOUNTERCURRENT(n) ((n) & 0xFFFF)
  271. /*
  272. * rxfliterctrl, rxfilterwolstatus, and rxfilterwolclear shared
  273. * register definitions
  274. */
  275. #define LPC_RXFLTRW_ACCEPTUNICAST (1 << 0)
  276. #define LPC_RXFLTRW_ACCEPTUBROADCAST (1 << 1)
  277. #define LPC_RXFLTRW_ACCEPTUMULTICAST (1 << 2)
  278. #define LPC_RXFLTRW_ACCEPTUNICASTHASH (1 << 3)
  279. #define LPC_RXFLTRW_ACCEPTUMULTICASTHASH (1 << 4)
  280. #define LPC_RXFLTRW_ACCEPTPERFECT (1 << 5)
  281. /*
  282. * rxfliterctrl register definitions
  283. */
  284. #define LPC_RXFLTRWSTS_MAGICPACKETENWOL (1 << 12)
  285. #define LPC_RXFLTRWSTS_RXFILTERENWOL (1 << 13)
  286. /*
  287. * rxfilterwolstatus/rxfilterwolclear register definitions
  288. */
  289. #define LPC_RXFLTRWSTS_RXFILTERWOL (1 << 7)
  290. #define LPC_RXFLTRWSTS_MAGICPACKETWOL (1 << 8)
  291. /*
  292. * intstatus, intenable, intclear, and Intset shared register
  293. * definitions
  294. */
  295. #define LPC_MACINT_RXOVERRUNINTEN (1 << 0)
  296. #define LPC_MACINT_RXERRORONINT (1 << 1)
  297. #define LPC_MACINT_RXFINISHEDINTEN (1 << 2)
  298. #define LPC_MACINT_RXDONEINTEN (1 << 3)
  299. #define LPC_MACINT_TXUNDERRUNINTEN (1 << 4)
  300. #define LPC_MACINT_TXERRORINTEN (1 << 5)
  301. #define LPC_MACINT_TXFINISHEDINTEN (1 << 6)
  302. #define LPC_MACINT_TXDONEINTEN (1 << 7)
  303. #define LPC_MACINT_SOFTINTEN (1 << 12)
  304. #define LPC_MACINT_WAKEUPINTEN (1 << 13)
  305. /*
  306. * powerdown register definitions
  307. */
  308. #define LPC_POWERDOWN_MACAHB (1 << 31)
  309. /* Upon the upcoming introduction of device tree usage in LPC32xx,
  310. * lpc_phy_interface_mode() and use_iram_for_net() will be extended with a
  311. * device parameter for access to device tree information at runtime, instead
  312. * of defining the values at compile time
  313. */
  314. static inline phy_interface_t lpc_phy_interface_mode(void)
  315. {
  316. #ifdef CONFIG_ARCH_LPC32XX_MII_SUPPORT
  317. return PHY_INTERFACE_MODE_MII;
  318. #else
  319. return PHY_INTERFACE_MODE_RMII;
  320. #endif
  321. }
  322. static inline int use_iram_for_net(void)
  323. {
  324. #ifdef CONFIG_ARCH_LPC32XX_IRAM_FOR_NET
  325. return 1;
  326. #else
  327. return 0;
  328. #endif
  329. }
  330. /* Receive Status information word */
  331. #define RXSTATUS_SIZE 0x000007FF
  332. #define RXSTATUS_CONTROL (1 << 18)
  333. #define RXSTATUS_VLAN (1 << 19)
  334. #define RXSTATUS_FILTER (1 << 20)
  335. #define RXSTATUS_MULTICAST (1 << 21)
  336. #define RXSTATUS_BROADCAST (1 << 22)
  337. #define RXSTATUS_CRC (1 << 23)
  338. #define RXSTATUS_SYMBOL (1 << 24)
  339. #define RXSTATUS_LENGTH (1 << 25)
  340. #define RXSTATUS_RANGE (1 << 26)
  341. #define RXSTATUS_ALIGN (1 << 27)
  342. #define RXSTATUS_OVERRUN (1 << 28)
  343. #define RXSTATUS_NODESC (1 << 29)
  344. #define RXSTATUS_LAST (1 << 30)
  345. #define RXSTATUS_ERROR (1 << 31)
  346. #define RXSTATUS_STATUS_ERROR \
  347. (RXSTATUS_NODESC | RXSTATUS_OVERRUN | RXSTATUS_ALIGN | \
  348. RXSTATUS_RANGE | RXSTATUS_LENGTH | RXSTATUS_SYMBOL | RXSTATUS_CRC)
  349. /* Receive Descriptor control word */
  350. #define RXDESC_CONTROL_SIZE 0x000007FF
  351. #define RXDESC_CONTROL_INT (1 << 31)
  352. /* Transmit Status information word */
  353. #define TXSTATUS_COLLISIONS_GET(x) (((x) >> 21) & 0xF)
  354. #define TXSTATUS_DEFER (1 << 25)
  355. #define TXSTATUS_EXCESSDEFER (1 << 26)
  356. #define TXSTATUS_EXCESSCOLL (1 << 27)
  357. #define TXSTATUS_LATECOLL (1 << 28)
  358. #define TXSTATUS_UNDERRUN (1 << 29)
  359. #define TXSTATUS_NODESC (1 << 30)
  360. #define TXSTATUS_ERROR (1 << 31)
  361. /* Transmit Descriptor control word */
  362. #define TXDESC_CONTROL_SIZE 0x000007FF
  363. #define TXDESC_CONTROL_OVERRIDE (1 << 26)
  364. #define TXDESC_CONTROL_HUGE (1 << 27)
  365. #define TXDESC_CONTROL_PAD (1 << 28)
  366. #define TXDESC_CONTROL_CRC (1 << 29)
  367. #define TXDESC_CONTROL_LAST (1 << 30)
  368. #define TXDESC_CONTROL_INT (1 << 31)
  369. static int lpc_eth_hard_start_xmit(struct sk_buff *skb,
  370. struct net_device *ndev);
  371. /*
  372. * Structure of a TX/RX descriptors and RX status
  373. */
  374. struct txrx_desc_t {
  375. __le32 packet;
  376. __le32 control;
  377. };
  378. struct rx_status_t {
  379. __le32 statusinfo;
  380. __le32 statushashcrc;
  381. };
  382. /*
  383. * Device driver data structure
  384. */
  385. struct netdata_local {
  386. struct platform_device *pdev;
  387. struct net_device *ndev;
  388. spinlock_t lock;
  389. void __iomem *net_base;
  390. u32 msg_enable;
  391. struct sk_buff *skb[ENET_TX_DESC];
  392. unsigned int last_tx_idx;
  393. unsigned int num_used_tx_buffs;
  394. struct mii_bus *mii_bus;
  395. struct phy_device *phy_dev;
  396. struct clk *clk;
  397. dma_addr_t dma_buff_base_p;
  398. void *dma_buff_base_v;
  399. size_t dma_buff_size;
  400. struct txrx_desc_t *tx_desc_v;
  401. u32 *tx_stat_v;
  402. void *tx_buff_v;
  403. struct txrx_desc_t *rx_desc_v;
  404. struct rx_status_t *rx_stat_v;
  405. void *rx_buff_v;
  406. int link;
  407. int speed;
  408. int duplex;
  409. struct napi_struct napi;
  410. };
  411. /*
  412. * MAC support functions
  413. */
  414. static void __lpc_set_mac(struct netdata_local *pldat, u8 *mac)
  415. {
  416. u32 tmp;
  417. /* Set station address */
  418. tmp = mac[0] | ((u32)mac[1] << 8);
  419. writel(tmp, LPC_ENET_SA2(pldat->net_base));
  420. tmp = mac[2] | ((u32)mac[3] << 8);
  421. writel(tmp, LPC_ENET_SA1(pldat->net_base));
  422. tmp = mac[4] | ((u32)mac[5] << 8);
  423. writel(tmp, LPC_ENET_SA0(pldat->net_base));
  424. netdev_dbg(pldat->ndev, "Ethernet MAC address %pM\n", mac);
  425. }
  426. static void __lpc_get_mac(struct netdata_local *pldat, u8 *mac)
  427. {
  428. u32 tmp;
  429. /* Get station address */
  430. tmp = readl(LPC_ENET_SA2(pldat->net_base));
  431. mac[0] = tmp & 0xFF;
  432. mac[1] = tmp >> 8;
  433. tmp = readl(LPC_ENET_SA1(pldat->net_base));
  434. mac[2] = tmp & 0xFF;
  435. mac[3] = tmp >> 8;
  436. tmp = readl(LPC_ENET_SA0(pldat->net_base));
  437. mac[4] = tmp & 0xFF;
  438. mac[5] = tmp >> 8;
  439. }
  440. static void __lpc_eth_clock_enable(struct netdata_local *pldat,
  441. bool enable)
  442. {
  443. if (enable)
  444. clk_enable(pldat->clk);
  445. else
  446. clk_disable(pldat->clk);
  447. }
  448. static void __lpc_params_setup(struct netdata_local *pldat)
  449. {
  450. u32 tmp;
  451. if (pldat->duplex == DUPLEX_FULL) {
  452. tmp = readl(LPC_ENET_MAC2(pldat->net_base));
  453. tmp |= LPC_MAC2_FULL_DUPLEX;
  454. writel(tmp, LPC_ENET_MAC2(pldat->net_base));
  455. tmp = readl(LPC_ENET_COMMAND(pldat->net_base));
  456. tmp |= LPC_COMMAND_FULLDUPLEX;
  457. writel(tmp, LPC_ENET_COMMAND(pldat->net_base));
  458. writel(LPC_IPGT_LOAD(0x15), LPC_ENET_IPGT(pldat->net_base));
  459. } else {
  460. tmp = readl(LPC_ENET_MAC2(pldat->net_base));
  461. tmp &= ~LPC_MAC2_FULL_DUPLEX;
  462. writel(tmp, LPC_ENET_MAC2(pldat->net_base));
  463. tmp = readl(LPC_ENET_COMMAND(pldat->net_base));
  464. tmp &= ~LPC_COMMAND_FULLDUPLEX;
  465. writel(tmp, LPC_ENET_COMMAND(pldat->net_base));
  466. writel(LPC_IPGT_LOAD(0x12), LPC_ENET_IPGT(pldat->net_base));
  467. }
  468. if (pldat->speed == SPEED_100)
  469. writel(LPC_SUPP_SPEED, LPC_ENET_SUPP(pldat->net_base));
  470. else
  471. writel(0, LPC_ENET_SUPP(pldat->net_base));
  472. }
  473. static void __lpc_eth_reset(struct netdata_local *pldat)
  474. {
  475. /* Reset all MAC logic */
  476. writel((LPC_MAC1_RESET_TX | LPC_MAC1_RESET_MCS_TX | LPC_MAC1_RESET_RX |
  477. LPC_MAC1_RESET_MCS_RX | LPC_MAC1_SIMULATION_RESET |
  478. LPC_MAC1_SOFT_RESET), LPC_ENET_MAC1(pldat->net_base));
  479. writel((LPC_COMMAND_REG_RESET | LPC_COMMAND_TXRESET |
  480. LPC_COMMAND_RXRESET), LPC_ENET_COMMAND(pldat->net_base));
  481. }
  482. static int __lpc_mii_mngt_reset(struct netdata_local *pldat)
  483. {
  484. /* Reset MII management hardware */
  485. writel(LPC_MCFG_RESET_MII_MGMT, LPC_ENET_MCFG(pldat->net_base));
  486. /* Setup MII clock to slowest rate with a /28 divider */
  487. writel(LPC_MCFG_CLOCK_SELECT(LPC_MCFG_CLOCK_HOST_DIV_28),
  488. LPC_ENET_MCFG(pldat->net_base));
  489. return 0;
  490. }
  491. static inline phys_addr_t __va_to_pa(void *addr, struct netdata_local *pldat)
  492. {
  493. phys_addr_t phaddr;
  494. phaddr = addr - pldat->dma_buff_base_v;
  495. phaddr += pldat->dma_buff_base_p;
  496. return phaddr;
  497. }
  498. static void lpc_eth_enable_int(void __iomem *regbase)
  499. {
  500. writel((LPC_MACINT_RXDONEINTEN | LPC_MACINT_TXDONEINTEN),
  501. LPC_ENET_INTENABLE(regbase));
  502. }
  503. static void lpc_eth_disable_int(void __iomem *regbase)
  504. {
  505. writel(0, LPC_ENET_INTENABLE(regbase));
  506. }
  507. /* Setup TX/RX descriptors */
  508. static void __lpc_txrx_desc_setup(struct netdata_local *pldat)
  509. {
  510. u32 *ptxstat;
  511. void *tbuff;
  512. int i;
  513. struct txrx_desc_t *ptxrxdesc;
  514. struct rx_status_t *prxstat;
  515. tbuff = PTR_ALIGN(pldat->dma_buff_base_v, 16);
  516. /* Setup TX descriptors, status, and buffers */
  517. pldat->tx_desc_v = tbuff;
  518. tbuff += sizeof(struct txrx_desc_t) * ENET_TX_DESC;
  519. pldat->tx_stat_v = tbuff;
  520. tbuff += sizeof(u32) * ENET_TX_DESC;
  521. tbuff = PTR_ALIGN(tbuff, 16);
  522. pldat->tx_buff_v = tbuff;
  523. tbuff += ENET_MAXF_SIZE * ENET_TX_DESC;
  524. /* Setup RX descriptors, status, and buffers */
  525. pldat->rx_desc_v = tbuff;
  526. tbuff += sizeof(struct txrx_desc_t) * ENET_RX_DESC;
  527. tbuff = PTR_ALIGN(tbuff, 16);
  528. pldat->rx_stat_v = tbuff;
  529. tbuff += sizeof(struct rx_status_t) * ENET_RX_DESC;
  530. tbuff = PTR_ALIGN(tbuff, 16);
  531. pldat->rx_buff_v = tbuff;
  532. tbuff += ENET_MAXF_SIZE * ENET_RX_DESC;
  533. /* Map the TX descriptors to the TX buffers in hardware */
  534. for (i = 0; i < ENET_TX_DESC; i++) {
  535. ptxstat = &pldat->tx_stat_v[i];
  536. ptxrxdesc = &pldat->tx_desc_v[i];
  537. ptxrxdesc->packet = __va_to_pa(
  538. pldat->tx_buff_v + i * ENET_MAXF_SIZE, pldat);
  539. ptxrxdesc->control = 0;
  540. *ptxstat = 0;
  541. }
  542. /* Map the RX descriptors to the RX buffers in hardware */
  543. for (i = 0; i < ENET_RX_DESC; i++) {
  544. prxstat = &pldat->rx_stat_v[i];
  545. ptxrxdesc = &pldat->rx_desc_v[i];
  546. ptxrxdesc->packet = __va_to_pa(
  547. pldat->rx_buff_v + i * ENET_MAXF_SIZE, pldat);
  548. ptxrxdesc->control = RXDESC_CONTROL_INT | (ENET_MAXF_SIZE - 1);
  549. prxstat->statusinfo = 0;
  550. prxstat->statushashcrc = 0;
  551. }
  552. /* Setup base addresses in hardware to point to buffers and
  553. * descriptors
  554. */
  555. writel((ENET_TX_DESC - 1),
  556. LPC_ENET_TXDESCRIPTORNUMBER(pldat->net_base));
  557. writel(__va_to_pa(pldat->tx_desc_v, pldat),
  558. LPC_ENET_TXDESCRIPTOR(pldat->net_base));
  559. writel(__va_to_pa(pldat->tx_stat_v, pldat),
  560. LPC_ENET_TXSTATUS(pldat->net_base));
  561. writel((ENET_RX_DESC - 1),
  562. LPC_ENET_RXDESCRIPTORNUMBER(pldat->net_base));
  563. writel(__va_to_pa(pldat->rx_desc_v, pldat),
  564. LPC_ENET_RXDESCRIPTOR(pldat->net_base));
  565. writel(__va_to_pa(pldat->rx_stat_v, pldat),
  566. LPC_ENET_RXSTATUS(pldat->net_base));
  567. }
  568. static void __lpc_eth_init(struct netdata_local *pldat)
  569. {
  570. u32 tmp;
  571. /* Disable controller and reset */
  572. tmp = readl(LPC_ENET_COMMAND(pldat->net_base));
  573. tmp &= ~LPC_COMMAND_RXENABLE | LPC_COMMAND_TXENABLE;
  574. writel(tmp, LPC_ENET_COMMAND(pldat->net_base));
  575. tmp = readl(LPC_ENET_MAC1(pldat->net_base));
  576. tmp &= ~LPC_MAC1_RECV_ENABLE;
  577. writel(tmp, LPC_ENET_MAC1(pldat->net_base));
  578. /* Initial MAC setup */
  579. writel(LPC_MAC1_PASS_ALL_RX_FRAMES, LPC_ENET_MAC1(pldat->net_base));
  580. writel((LPC_MAC2_PAD_CRC_ENABLE | LPC_MAC2_CRC_ENABLE),
  581. LPC_ENET_MAC2(pldat->net_base));
  582. writel(ENET_MAXF_SIZE, LPC_ENET_MAXF(pldat->net_base));
  583. /* Collision window, gap */
  584. writel((LPC_CLRT_LOAD_RETRY_MAX(0xF) |
  585. LPC_CLRT_LOAD_COLLISION_WINDOW(0x37)),
  586. LPC_ENET_CLRT(pldat->net_base));
  587. writel(LPC_IPGR_LOAD_PART2(0x12), LPC_ENET_IPGR(pldat->net_base));
  588. if (lpc_phy_interface_mode() == PHY_INTERFACE_MODE_MII)
  589. writel(LPC_COMMAND_PASSRUNTFRAME,
  590. LPC_ENET_COMMAND(pldat->net_base));
  591. else {
  592. writel((LPC_COMMAND_PASSRUNTFRAME | LPC_COMMAND_RMII),
  593. LPC_ENET_COMMAND(pldat->net_base));
  594. writel(LPC_SUPP_RESET_RMII, LPC_ENET_SUPP(pldat->net_base));
  595. }
  596. __lpc_params_setup(pldat);
  597. /* Setup TX and RX descriptors */
  598. __lpc_txrx_desc_setup(pldat);
  599. /* Setup packet filtering */
  600. writel((LPC_RXFLTRW_ACCEPTUBROADCAST | LPC_RXFLTRW_ACCEPTPERFECT),
  601. LPC_ENET_RXFILTER_CTRL(pldat->net_base));
  602. /* Get the next TX buffer output index */
  603. pldat->num_used_tx_buffs = 0;
  604. pldat->last_tx_idx =
  605. readl(LPC_ENET_TXCONSUMEINDEX(pldat->net_base));
  606. /* Clear and enable interrupts */
  607. writel(0xFFFF, LPC_ENET_INTCLEAR(pldat->net_base));
  608. smp_wmb();
  609. lpc_eth_enable_int(pldat->net_base);
  610. /* Enable controller */
  611. tmp = readl(LPC_ENET_COMMAND(pldat->net_base));
  612. tmp |= LPC_COMMAND_RXENABLE | LPC_COMMAND_TXENABLE;
  613. writel(tmp, LPC_ENET_COMMAND(pldat->net_base));
  614. tmp = readl(LPC_ENET_MAC1(pldat->net_base));
  615. tmp |= LPC_MAC1_RECV_ENABLE;
  616. writel(tmp, LPC_ENET_MAC1(pldat->net_base));
  617. }
  618. static void __lpc_eth_shutdown(struct netdata_local *pldat)
  619. {
  620. /* Reset ethernet and power down PHY */
  621. __lpc_eth_reset(pldat);
  622. writel(0, LPC_ENET_MAC1(pldat->net_base));
  623. writel(0, LPC_ENET_MAC2(pldat->net_base));
  624. }
  625. /*
  626. * MAC<--->PHY support functions
  627. */
  628. static int lpc_mdio_read(struct mii_bus *bus, int phy_id, int phyreg)
  629. {
  630. struct netdata_local *pldat = bus->priv;
  631. unsigned long timeout = jiffies + msecs_to_jiffies(100);
  632. int lps;
  633. writel(((phy_id << 8) | phyreg), LPC_ENET_MADR(pldat->net_base));
  634. writel(LPC_MCMD_READ, LPC_ENET_MCMD(pldat->net_base));
  635. /* Wait for unbusy status */
  636. while (readl(LPC_ENET_MIND(pldat->net_base)) & LPC_MIND_BUSY) {
  637. if (time_after(jiffies, timeout))
  638. return -EIO;
  639. cpu_relax();
  640. }
  641. lps = readl(LPC_ENET_MRDD(pldat->net_base));
  642. writel(0, LPC_ENET_MCMD(pldat->net_base));
  643. return lps;
  644. }
  645. static int lpc_mdio_write(struct mii_bus *bus, int phy_id, int phyreg,
  646. u16 phydata)
  647. {
  648. struct netdata_local *pldat = bus->priv;
  649. unsigned long timeout = jiffies + msecs_to_jiffies(100);
  650. writel(((phy_id << 8) | phyreg), LPC_ENET_MADR(pldat->net_base));
  651. writel(phydata, LPC_ENET_MWTD(pldat->net_base));
  652. /* Wait for completion */
  653. while (readl(LPC_ENET_MIND(pldat->net_base)) & LPC_MIND_BUSY) {
  654. if (time_after(jiffies, timeout))
  655. return -EIO;
  656. cpu_relax();
  657. }
  658. return 0;
  659. }
  660. static int lpc_mdio_reset(struct mii_bus *bus)
  661. {
  662. return __lpc_mii_mngt_reset((struct netdata_local *)bus->priv);
  663. }
  664. static void lpc_handle_link_change(struct net_device *ndev)
  665. {
  666. struct netdata_local *pldat = netdev_priv(ndev);
  667. struct phy_device *phydev = pldat->phy_dev;
  668. unsigned long flags;
  669. bool status_change = false;
  670. spin_lock_irqsave(&pldat->lock, flags);
  671. if (phydev->link) {
  672. if ((pldat->speed != phydev->speed) ||
  673. (pldat->duplex != phydev->duplex)) {
  674. pldat->speed = phydev->speed;
  675. pldat->duplex = phydev->duplex;
  676. status_change = true;
  677. }
  678. }
  679. if (phydev->link != pldat->link) {
  680. if (!phydev->link) {
  681. pldat->speed = 0;
  682. pldat->duplex = -1;
  683. }
  684. pldat->link = phydev->link;
  685. status_change = true;
  686. }
  687. spin_unlock_irqrestore(&pldat->lock, flags);
  688. if (status_change)
  689. __lpc_params_setup(pldat);
  690. }
  691. static int lpc_mii_probe(struct net_device *ndev)
  692. {
  693. struct netdata_local *pldat = netdev_priv(ndev);
  694. struct phy_device *phydev = phy_find_first(pldat->mii_bus);
  695. if (!phydev) {
  696. netdev_err(ndev, "no PHY found\n");
  697. return -ENODEV;
  698. }
  699. /* Attach to the PHY */
  700. if (lpc_phy_interface_mode() == PHY_INTERFACE_MODE_MII)
  701. netdev_info(ndev, "using MII interface\n");
  702. else
  703. netdev_info(ndev, "using RMII interface\n");
  704. phydev = phy_connect(ndev, dev_name(&phydev->dev),
  705. &lpc_handle_link_change, 0, lpc_phy_interface_mode());
  706. if (IS_ERR(phydev)) {
  707. netdev_err(ndev, "Could not attach to PHY\n");
  708. return PTR_ERR(phydev);
  709. }
  710. /* mask with MAC supported features */
  711. phydev->supported &= PHY_BASIC_FEATURES;
  712. phydev->advertising = phydev->supported;
  713. pldat->link = 0;
  714. pldat->speed = 0;
  715. pldat->duplex = -1;
  716. pldat->phy_dev = phydev;
  717. netdev_info(ndev,
  718. "attached PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n",
  719. phydev->drv->name, dev_name(&phydev->dev), phydev->irq);
  720. return 0;
  721. }
  722. static int lpc_mii_init(struct netdata_local *pldat)
  723. {
  724. int err = -ENXIO, i;
  725. pldat->mii_bus = mdiobus_alloc();
  726. if (!pldat->mii_bus) {
  727. err = -ENOMEM;
  728. goto err_out;
  729. }
  730. /* Setup MII mode */
  731. if (lpc_phy_interface_mode() == PHY_INTERFACE_MODE_MII)
  732. writel(LPC_COMMAND_PASSRUNTFRAME,
  733. LPC_ENET_COMMAND(pldat->net_base));
  734. else {
  735. writel((LPC_COMMAND_PASSRUNTFRAME | LPC_COMMAND_RMII),
  736. LPC_ENET_COMMAND(pldat->net_base));
  737. writel(LPC_SUPP_RESET_RMII, LPC_ENET_SUPP(pldat->net_base));
  738. }
  739. pldat->mii_bus->name = "lpc_mii_bus";
  740. pldat->mii_bus->read = &lpc_mdio_read;
  741. pldat->mii_bus->write = &lpc_mdio_write;
  742. pldat->mii_bus->reset = &lpc_mdio_reset;
  743. snprintf(pldat->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
  744. pldat->pdev->name, pldat->pdev->id);
  745. pldat->mii_bus->priv = pldat;
  746. pldat->mii_bus->parent = &pldat->pdev->dev;
  747. pldat->mii_bus->irq = kmalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL);
  748. if (!pldat->mii_bus->irq) {
  749. err = -ENOMEM;
  750. goto err_out_1;
  751. }
  752. for (i = 0; i < PHY_MAX_ADDR; i++)
  753. pldat->mii_bus->irq[i] = PHY_POLL;
  754. platform_set_drvdata(pldat->pdev, pldat->mii_bus);
  755. if (mdiobus_register(pldat->mii_bus))
  756. goto err_out_free_mdio_irq;
  757. if (lpc_mii_probe(pldat->ndev) != 0)
  758. goto err_out_unregister_bus;
  759. return 0;
  760. err_out_unregister_bus:
  761. mdiobus_unregister(pldat->mii_bus);
  762. err_out_free_mdio_irq:
  763. kfree(pldat->mii_bus->irq);
  764. err_out_1:
  765. mdiobus_free(pldat->mii_bus);
  766. err_out:
  767. return err;
  768. }
  769. static void __lpc_handle_xmit(struct net_device *ndev)
  770. {
  771. struct netdata_local *pldat = netdev_priv(ndev);
  772. struct sk_buff *skb;
  773. u32 txcidx, *ptxstat, txstat;
  774. txcidx = readl(LPC_ENET_TXCONSUMEINDEX(pldat->net_base));
  775. while (pldat->last_tx_idx != txcidx) {
  776. skb = pldat->skb[pldat->last_tx_idx];
  777. /* A buffer is available, get buffer status */
  778. ptxstat = &pldat->tx_stat_v[pldat->last_tx_idx];
  779. txstat = *ptxstat;
  780. /* Next buffer and decrement used buffer counter */
  781. pldat->num_used_tx_buffs--;
  782. pldat->last_tx_idx++;
  783. if (pldat->last_tx_idx >= ENET_TX_DESC)
  784. pldat->last_tx_idx = 0;
  785. /* Update collision counter */
  786. ndev->stats.collisions += TXSTATUS_COLLISIONS_GET(txstat);
  787. /* Any errors occurred? */
  788. if (txstat & TXSTATUS_ERROR) {
  789. if (txstat & TXSTATUS_UNDERRUN) {
  790. /* FIFO underrun */
  791. ndev->stats.tx_fifo_errors++;
  792. }
  793. if (txstat & TXSTATUS_LATECOLL) {
  794. /* Late collision */
  795. ndev->stats.tx_aborted_errors++;
  796. }
  797. if (txstat & TXSTATUS_EXCESSCOLL) {
  798. /* Excessive collision */
  799. ndev->stats.tx_aborted_errors++;
  800. }
  801. if (txstat & TXSTATUS_EXCESSDEFER) {
  802. /* Defer limit */
  803. ndev->stats.tx_aborted_errors++;
  804. }
  805. ndev->stats.tx_errors++;
  806. } else {
  807. /* Update stats */
  808. ndev->stats.tx_packets++;
  809. ndev->stats.tx_bytes += skb->len;
  810. }
  811. dev_kfree_skb_irq(skb);
  812. txcidx = readl(LPC_ENET_TXCONSUMEINDEX(pldat->net_base));
  813. }
  814. if (pldat->num_used_tx_buffs <= ENET_TX_DESC/2) {
  815. if (netif_queue_stopped(ndev))
  816. netif_wake_queue(ndev);
  817. }
  818. }
  819. static int __lpc_handle_recv(struct net_device *ndev, int budget)
  820. {
  821. struct netdata_local *pldat = netdev_priv(ndev);
  822. struct sk_buff *skb;
  823. u32 rxconsidx, len, ethst;
  824. struct rx_status_t *prxstat;
  825. u8 *prdbuf;
  826. int rx_done = 0;
  827. /* Get the current RX buffer indexes */
  828. rxconsidx = readl(LPC_ENET_RXCONSUMEINDEX(pldat->net_base));
  829. while (rx_done < budget && rxconsidx !=
  830. readl(LPC_ENET_RXPRODUCEINDEX(pldat->net_base))) {
  831. /* Get pointer to receive status */
  832. prxstat = &pldat->rx_stat_v[rxconsidx];
  833. len = (prxstat->statusinfo & RXSTATUS_SIZE) + 1;
  834. /* Status error? */
  835. ethst = prxstat->statusinfo;
  836. if ((ethst & (RXSTATUS_ERROR | RXSTATUS_STATUS_ERROR)) ==
  837. (RXSTATUS_ERROR | RXSTATUS_RANGE))
  838. ethst &= ~RXSTATUS_ERROR;
  839. if (ethst & RXSTATUS_ERROR) {
  840. int si = prxstat->statusinfo;
  841. /* Check statuses */
  842. if (si & RXSTATUS_OVERRUN) {
  843. /* Overrun error */
  844. ndev->stats.rx_fifo_errors++;
  845. } else if (si & RXSTATUS_CRC) {
  846. /* CRC error */
  847. ndev->stats.rx_crc_errors++;
  848. } else if (si & RXSTATUS_LENGTH) {
  849. /* Length error */
  850. ndev->stats.rx_length_errors++;
  851. } else if (si & RXSTATUS_ERROR) {
  852. /* Other error */
  853. ndev->stats.rx_length_errors++;
  854. }
  855. ndev->stats.rx_errors++;
  856. } else {
  857. /* Packet is good */
  858. skb = dev_alloc_skb(len + 8);
  859. if (!skb)
  860. ndev->stats.rx_dropped++;
  861. else {
  862. prdbuf = skb_put(skb, len);
  863. /* Copy packet from buffer */
  864. memcpy(prdbuf, pldat->rx_buff_v +
  865. rxconsidx * ENET_MAXF_SIZE, len);
  866. /* Pass to upper layer */
  867. skb->protocol = eth_type_trans(skb, ndev);
  868. netif_receive_skb(skb);
  869. ndev->stats.rx_packets++;
  870. ndev->stats.rx_bytes += len;
  871. }
  872. }
  873. /* Increment consume index */
  874. rxconsidx = rxconsidx + 1;
  875. if (rxconsidx >= ENET_RX_DESC)
  876. rxconsidx = 0;
  877. writel(rxconsidx,
  878. LPC_ENET_RXCONSUMEINDEX(pldat->net_base));
  879. rx_done++;
  880. }
  881. return rx_done;
  882. }
  883. static int lpc_eth_poll(struct napi_struct *napi, int budget)
  884. {
  885. struct netdata_local *pldat = container_of(napi,
  886. struct netdata_local, napi);
  887. struct net_device *ndev = pldat->ndev;
  888. int rx_done = 0;
  889. struct netdev_queue *txq = netdev_get_tx_queue(ndev, 0);
  890. __netif_tx_lock(txq, smp_processor_id());
  891. __lpc_handle_xmit(ndev);
  892. __netif_tx_unlock(txq);
  893. rx_done = __lpc_handle_recv(ndev, budget);
  894. if (rx_done < budget) {
  895. napi_complete(napi);
  896. lpc_eth_enable_int(pldat->net_base);
  897. }
  898. return rx_done;
  899. }
  900. static irqreturn_t __lpc_eth_interrupt(int irq, void *dev_id)
  901. {
  902. struct net_device *ndev = dev_id;
  903. struct netdata_local *pldat = netdev_priv(ndev);
  904. u32 tmp;
  905. spin_lock(&pldat->lock);
  906. tmp = readl(LPC_ENET_INTSTATUS(pldat->net_base));
  907. /* Clear interrupts */
  908. writel(tmp, LPC_ENET_INTCLEAR(pldat->net_base));
  909. lpc_eth_disable_int(pldat->net_base);
  910. if (likely(napi_schedule_prep(&pldat->napi)))
  911. __napi_schedule(&pldat->napi);
  912. spin_unlock(&pldat->lock);
  913. return IRQ_HANDLED;
  914. }
  915. static int lpc_eth_close(struct net_device *ndev)
  916. {
  917. unsigned long flags;
  918. struct netdata_local *pldat = netdev_priv(ndev);
  919. if (netif_msg_ifdown(pldat))
  920. dev_dbg(&pldat->pdev->dev, "shutting down %s\n", ndev->name);
  921. napi_disable(&pldat->napi);
  922. netif_stop_queue(ndev);
  923. if (pldat->phy_dev)
  924. phy_stop(pldat->phy_dev);
  925. spin_lock_irqsave(&pldat->lock, flags);
  926. __lpc_eth_reset(pldat);
  927. netif_carrier_off(ndev);
  928. writel(0, LPC_ENET_MAC1(pldat->net_base));
  929. writel(0, LPC_ENET_MAC2(pldat->net_base));
  930. spin_unlock_irqrestore(&pldat->lock, flags);
  931. __lpc_eth_clock_enable(pldat, false);
  932. return 0;
  933. }
  934. static int lpc_eth_hard_start_xmit(struct sk_buff *skb, struct net_device *ndev)
  935. {
  936. struct netdata_local *pldat = netdev_priv(ndev);
  937. u32 len, txidx;
  938. u32 *ptxstat;
  939. struct txrx_desc_t *ptxrxdesc;
  940. len = skb->len;
  941. spin_lock_irq(&pldat->lock);
  942. if (pldat->num_used_tx_buffs >= (ENET_TX_DESC - 1)) {
  943. /* This function should never be called when there are no
  944. buffers */
  945. netif_stop_queue(ndev);
  946. spin_unlock_irq(&pldat->lock);
  947. WARN(1, "BUG! TX request when no free TX buffers!\n");
  948. return NETDEV_TX_BUSY;
  949. }
  950. /* Get the next TX descriptor index */
  951. txidx = readl(LPC_ENET_TXPRODUCEINDEX(pldat->net_base));
  952. /* Setup control for the transfer */
  953. ptxstat = &pldat->tx_stat_v[txidx];
  954. *ptxstat = 0;
  955. ptxrxdesc = &pldat->tx_desc_v[txidx];
  956. ptxrxdesc->control =
  957. (len - 1) | TXDESC_CONTROL_LAST | TXDESC_CONTROL_INT;
  958. /* Copy data to the DMA buffer */
  959. memcpy(pldat->tx_buff_v + txidx * ENET_MAXF_SIZE, skb->data, len);
  960. /* Save the buffer and increment the buffer counter */
  961. pldat->skb[txidx] = skb;
  962. pldat->num_used_tx_buffs++;
  963. /* Start transmit */
  964. txidx++;
  965. if (txidx >= ENET_TX_DESC)
  966. txidx = 0;
  967. writel(txidx, LPC_ENET_TXPRODUCEINDEX(pldat->net_base));
  968. /* Stop queue if no more TX buffers */
  969. if (pldat->num_used_tx_buffs >= (ENET_TX_DESC - 1))
  970. netif_stop_queue(ndev);
  971. spin_unlock_irq(&pldat->lock);
  972. return NETDEV_TX_OK;
  973. }
  974. static int lpc_set_mac_address(struct net_device *ndev, void *p)
  975. {
  976. struct sockaddr *addr = p;
  977. struct netdata_local *pldat = netdev_priv(ndev);
  978. unsigned long flags;
  979. if (!is_valid_ether_addr(addr->sa_data))
  980. return -EADDRNOTAVAIL;
  981. memcpy(ndev->dev_addr, addr->sa_data, ETH_ALEN);
  982. spin_lock_irqsave(&pldat->lock, flags);
  983. /* Set station address */
  984. __lpc_set_mac(pldat, ndev->dev_addr);
  985. spin_unlock_irqrestore(&pldat->lock, flags);
  986. return 0;
  987. }
  988. static void lpc_eth_set_multicast_list(struct net_device *ndev)
  989. {
  990. struct netdata_local *pldat = netdev_priv(ndev);
  991. struct netdev_hw_addr_list *mcptr = &ndev->mc;
  992. struct netdev_hw_addr *ha;
  993. u32 tmp32, hash_val, hashlo, hashhi;
  994. unsigned long flags;
  995. spin_lock_irqsave(&pldat->lock, flags);
  996. /* Set station address */
  997. __lpc_set_mac(pldat, ndev->dev_addr);
  998. tmp32 = LPC_RXFLTRW_ACCEPTUBROADCAST | LPC_RXFLTRW_ACCEPTPERFECT;
  999. if (ndev->flags & IFF_PROMISC)
  1000. tmp32 |= LPC_RXFLTRW_ACCEPTUNICAST |
  1001. LPC_RXFLTRW_ACCEPTUMULTICAST;
  1002. if (ndev->flags & IFF_ALLMULTI)
  1003. tmp32 |= LPC_RXFLTRW_ACCEPTUMULTICAST;
  1004. if (netdev_hw_addr_list_count(mcptr))
  1005. tmp32 |= LPC_RXFLTRW_ACCEPTUMULTICASTHASH;
  1006. writel(tmp32, LPC_ENET_RXFILTER_CTRL(pldat->net_base));
  1007. /* Set initial hash table */
  1008. hashlo = 0x0;
  1009. hashhi = 0x0;
  1010. /* 64 bits : multicast address in hash table */
  1011. netdev_hw_addr_list_for_each(ha, mcptr) {
  1012. hash_val = (ether_crc(6, ha->addr) >> 23) & 0x3F;
  1013. if (hash_val >= 32)
  1014. hashhi |= 1 << (hash_val - 32);
  1015. else
  1016. hashlo |= 1 << hash_val;
  1017. }
  1018. writel(hashlo, LPC_ENET_HASHFILTERL(pldat->net_base));
  1019. writel(hashhi, LPC_ENET_HASHFILTERH(pldat->net_base));
  1020. spin_unlock_irqrestore(&pldat->lock, flags);
  1021. }
  1022. static int lpc_eth_ioctl(struct net_device *ndev, struct ifreq *req, int cmd)
  1023. {
  1024. struct netdata_local *pldat = netdev_priv(ndev);
  1025. struct phy_device *phydev = pldat->phy_dev;
  1026. if (!netif_running(ndev))
  1027. return -EINVAL;
  1028. if (!phydev)
  1029. return -ENODEV;
  1030. return phy_mii_ioctl(phydev, req, cmd);
  1031. }
  1032. static int lpc_eth_open(struct net_device *ndev)
  1033. {
  1034. struct netdata_local *pldat = netdev_priv(ndev);
  1035. if (netif_msg_ifup(pldat))
  1036. dev_dbg(&pldat->pdev->dev, "enabling %s\n", ndev->name);
  1037. if (!is_valid_ether_addr(ndev->dev_addr))
  1038. return -EADDRNOTAVAIL;
  1039. __lpc_eth_clock_enable(pldat, true);
  1040. /* Reset and initialize */
  1041. __lpc_eth_reset(pldat);
  1042. __lpc_eth_init(pldat);
  1043. /* schedule a link state check */
  1044. phy_start(pldat->phy_dev);
  1045. netif_start_queue(ndev);
  1046. napi_enable(&pldat->napi);
  1047. return 0;
  1048. }
  1049. /*
  1050. * Ethtool ops
  1051. */
  1052. static void lpc_eth_ethtool_getdrvinfo(struct net_device *ndev,
  1053. struct ethtool_drvinfo *info)
  1054. {
  1055. strcpy(info->driver, MODNAME);
  1056. strcpy(info->version, DRV_VERSION);
  1057. strcpy(info->bus_info, dev_name(ndev->dev.parent));
  1058. }
  1059. static u32 lpc_eth_ethtool_getmsglevel(struct net_device *ndev)
  1060. {
  1061. struct netdata_local *pldat = netdev_priv(ndev);
  1062. return pldat->msg_enable;
  1063. }
  1064. static void lpc_eth_ethtool_setmsglevel(struct net_device *ndev, u32 level)
  1065. {
  1066. struct netdata_local *pldat = netdev_priv(ndev);
  1067. pldat->msg_enable = level;
  1068. }
  1069. static int lpc_eth_ethtool_getsettings(struct net_device *ndev,
  1070. struct ethtool_cmd *cmd)
  1071. {
  1072. struct netdata_local *pldat = netdev_priv(ndev);
  1073. struct phy_device *phydev = pldat->phy_dev;
  1074. if (!phydev)
  1075. return -EOPNOTSUPP;
  1076. return phy_ethtool_gset(phydev, cmd);
  1077. }
  1078. static int lpc_eth_ethtool_setsettings(struct net_device *ndev,
  1079. struct ethtool_cmd *cmd)
  1080. {
  1081. struct netdata_local *pldat = netdev_priv(ndev);
  1082. struct phy_device *phydev = pldat->phy_dev;
  1083. if (!phydev)
  1084. return -EOPNOTSUPP;
  1085. return phy_ethtool_sset(phydev, cmd);
  1086. }
  1087. static const struct ethtool_ops lpc_eth_ethtool_ops = {
  1088. .get_drvinfo = lpc_eth_ethtool_getdrvinfo,
  1089. .get_settings = lpc_eth_ethtool_getsettings,
  1090. .set_settings = lpc_eth_ethtool_setsettings,
  1091. .get_msglevel = lpc_eth_ethtool_getmsglevel,
  1092. .set_msglevel = lpc_eth_ethtool_setmsglevel,
  1093. .get_link = ethtool_op_get_link,
  1094. };
  1095. static const struct net_device_ops lpc_netdev_ops = {
  1096. .ndo_open = lpc_eth_open,
  1097. .ndo_stop = lpc_eth_close,
  1098. .ndo_start_xmit = lpc_eth_hard_start_xmit,
  1099. .ndo_set_rx_mode = lpc_eth_set_multicast_list,
  1100. .ndo_do_ioctl = lpc_eth_ioctl,
  1101. .ndo_set_mac_address = lpc_set_mac_address,
  1102. .ndo_change_mtu = eth_change_mtu,
  1103. };
  1104. static int lpc_eth_drv_probe(struct platform_device *pdev)
  1105. {
  1106. struct resource *res;
  1107. struct resource *dma_res;
  1108. struct net_device *ndev;
  1109. struct netdata_local *pldat;
  1110. struct phy_device *phydev;
  1111. dma_addr_t dma_handle;
  1112. int irq, ret;
  1113. /* Get platform resources */
  1114. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1115. dma_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  1116. irq = platform_get_irq(pdev, 0);
  1117. if ((!res) || (!dma_res) || (irq < 0) || (irq >= NR_IRQS)) {
  1118. dev_err(&pdev->dev, "error getting resources.\n");
  1119. ret = -ENXIO;
  1120. goto err_exit;
  1121. }
  1122. /* Allocate net driver data structure */
  1123. ndev = alloc_etherdev(sizeof(struct netdata_local));
  1124. if (!ndev) {
  1125. dev_err(&pdev->dev, "could not allocate device.\n");
  1126. ret = -ENOMEM;
  1127. goto err_exit;
  1128. }
  1129. SET_NETDEV_DEV(ndev, &pdev->dev);
  1130. pldat = netdev_priv(ndev);
  1131. pldat->pdev = pdev;
  1132. pldat->ndev = ndev;
  1133. spin_lock_init(&pldat->lock);
  1134. /* Save resources */
  1135. ndev->irq = irq;
  1136. /* Get clock for the device */
  1137. pldat->clk = clk_get(&pdev->dev, NULL);
  1138. if (IS_ERR(pldat->clk)) {
  1139. dev_err(&pdev->dev, "error getting clock.\n");
  1140. ret = PTR_ERR(pldat->clk);
  1141. goto err_out_free_dev;
  1142. }
  1143. /* Enable network clock */
  1144. __lpc_eth_clock_enable(pldat, true);
  1145. /* Map IO space */
  1146. pldat->net_base = ioremap(res->start, res->end - res->start + 1);
  1147. if (!pldat->net_base) {
  1148. dev_err(&pdev->dev, "failed to map registers\n");
  1149. ret = -ENOMEM;
  1150. goto err_out_disable_clocks;
  1151. }
  1152. ret = request_irq(ndev->irq, __lpc_eth_interrupt, 0,
  1153. ndev->name, ndev);
  1154. if (ret) {
  1155. dev_err(&pdev->dev, "error requesting interrupt.\n");
  1156. goto err_out_iounmap;
  1157. }
  1158. /* Fill in the fields of the device structure with ethernet values. */
  1159. ether_setup(ndev);
  1160. /* Setup driver functions */
  1161. ndev->netdev_ops = &lpc_netdev_ops;
  1162. ndev->ethtool_ops = &lpc_eth_ethtool_ops;
  1163. ndev->watchdog_timeo = msecs_to_jiffies(2500);
  1164. /* Get size of DMA buffers/descriptors region */
  1165. pldat->dma_buff_size = (ENET_TX_DESC + ENET_RX_DESC) * (ENET_MAXF_SIZE +
  1166. sizeof(struct txrx_desc_t) + sizeof(struct rx_status_t));
  1167. pldat->dma_buff_base_v = 0;
  1168. if (use_iram_for_net()) {
  1169. dma_handle = dma_res->start;
  1170. if (pldat->dma_buff_size <= lpc32xx_return_iram_size())
  1171. pldat->dma_buff_base_v =
  1172. io_p2v(dma_res->start);
  1173. else
  1174. netdev_err(ndev,
  1175. "IRAM not big enough for net buffers, using SDRAM instead.\n");
  1176. }
  1177. if (pldat->dma_buff_base_v == 0) {
  1178. pldat->dma_buff_size = PAGE_ALIGN(pldat->dma_buff_size);
  1179. /* Allocate a chunk of memory for the DMA ethernet buffers
  1180. and descriptors */
  1181. pldat->dma_buff_base_v =
  1182. dma_alloc_coherent(&pldat->pdev->dev,
  1183. pldat->dma_buff_size, &dma_handle,
  1184. GFP_KERNEL);
  1185. if (pldat->dma_buff_base_v == NULL) {
  1186. dev_err(&pdev->dev, "error getting DMA region.\n");
  1187. ret = -ENOMEM;
  1188. goto err_out_free_irq;
  1189. }
  1190. }
  1191. pldat->dma_buff_base_p = dma_handle;
  1192. netdev_dbg(ndev, "IO address start :0x%08x\n",
  1193. res->start);
  1194. netdev_dbg(ndev, "IO address size :%d\n",
  1195. res->end - res->start + 1);
  1196. netdev_err(ndev, "IO address (mapped) :0x%p\n",
  1197. pldat->net_base);
  1198. netdev_dbg(ndev, "IRQ number :%d\n", ndev->irq);
  1199. netdev_dbg(ndev, "DMA buffer size :%d\n", pldat->dma_buff_size);
  1200. netdev_dbg(ndev, "DMA buffer P address :0x%08x\n",
  1201. pldat->dma_buff_base_p);
  1202. netdev_dbg(ndev, "DMA buffer V address :0x%p\n",
  1203. pldat->dma_buff_base_v);
  1204. /* Get MAC address from current HW setting (POR state is all zeros) */
  1205. __lpc_get_mac(pldat, ndev->dev_addr);
  1206. #ifdef CONFIG_OF_NET
  1207. if (!is_valid_ether_addr(ndev->dev_addr)) {
  1208. const char *macaddr = of_get_mac_address(pdev->dev.of_node);
  1209. if (macaddr)
  1210. memcpy(ndev->dev_addr, macaddr, ETH_ALEN);
  1211. }
  1212. #endif
  1213. if (!is_valid_ether_addr(ndev->dev_addr))
  1214. eth_hw_addr_random(ndev);
  1215. /* Reset the ethernet controller */
  1216. __lpc_eth_reset(pldat);
  1217. /* then shut everything down to save power */
  1218. __lpc_eth_shutdown(pldat);
  1219. /* Set default parameters */
  1220. pldat->msg_enable = NETIF_MSG_LINK;
  1221. /* Force an MII interface reset and clock setup */
  1222. __lpc_mii_mngt_reset(pldat);
  1223. /* Force default PHY interface setup in chip, this will probably be
  1224. changed by the PHY driver */
  1225. pldat->link = 0;
  1226. pldat->speed = 100;
  1227. pldat->duplex = DUPLEX_FULL;
  1228. __lpc_params_setup(pldat);
  1229. netif_napi_add(ndev, &pldat->napi, lpc_eth_poll, NAPI_WEIGHT);
  1230. ret = register_netdev(ndev);
  1231. if (ret) {
  1232. dev_err(&pdev->dev, "Cannot register net device, aborting.\n");
  1233. goto err_out_dma_unmap;
  1234. }
  1235. platform_set_drvdata(pdev, ndev);
  1236. if (lpc_mii_init(pldat) != 0)
  1237. goto err_out_unregister_netdev;
  1238. netdev_info(ndev, "LPC mac at 0x%08x irq %d\n",
  1239. res->start, ndev->irq);
  1240. phydev = pldat->phy_dev;
  1241. device_init_wakeup(&pdev->dev, 1);
  1242. device_set_wakeup_enable(&pdev->dev, 0);
  1243. return 0;
  1244. err_out_unregister_netdev:
  1245. platform_set_drvdata(pdev, NULL);
  1246. unregister_netdev(ndev);
  1247. err_out_dma_unmap:
  1248. if (!use_iram_for_net() ||
  1249. pldat->dma_buff_size > lpc32xx_return_iram_size())
  1250. dma_free_coherent(&pldat->pdev->dev, pldat->dma_buff_size,
  1251. pldat->dma_buff_base_v,
  1252. pldat->dma_buff_base_p);
  1253. err_out_free_irq:
  1254. free_irq(ndev->irq, ndev);
  1255. err_out_iounmap:
  1256. iounmap(pldat->net_base);
  1257. err_out_disable_clocks:
  1258. clk_disable(pldat->clk);
  1259. clk_put(pldat->clk);
  1260. err_out_free_dev:
  1261. free_netdev(ndev);
  1262. err_exit:
  1263. pr_err("%s: not found (%d).\n", MODNAME, ret);
  1264. return ret;
  1265. }
  1266. static int lpc_eth_drv_remove(struct platform_device *pdev)
  1267. {
  1268. struct net_device *ndev = platform_get_drvdata(pdev);
  1269. struct netdata_local *pldat = netdev_priv(ndev);
  1270. unregister_netdev(ndev);
  1271. platform_set_drvdata(pdev, NULL);
  1272. if (!use_iram_for_net() ||
  1273. pldat->dma_buff_size > lpc32xx_return_iram_size())
  1274. dma_free_coherent(&pldat->pdev->dev, pldat->dma_buff_size,
  1275. pldat->dma_buff_base_v,
  1276. pldat->dma_buff_base_p);
  1277. free_irq(ndev->irq, ndev);
  1278. iounmap(pldat->net_base);
  1279. mdiobus_unregister(pldat->mii_bus);
  1280. mdiobus_free(pldat->mii_bus);
  1281. clk_disable(pldat->clk);
  1282. clk_put(pldat->clk);
  1283. free_netdev(ndev);
  1284. return 0;
  1285. }
  1286. #ifdef CONFIG_PM
  1287. static int lpc_eth_drv_suspend(struct platform_device *pdev,
  1288. pm_message_t state)
  1289. {
  1290. struct net_device *ndev = platform_get_drvdata(pdev);
  1291. struct netdata_local *pldat = netdev_priv(ndev);
  1292. if (device_may_wakeup(&pdev->dev))
  1293. enable_irq_wake(ndev->irq);
  1294. if (ndev) {
  1295. if (netif_running(ndev)) {
  1296. netif_device_detach(ndev);
  1297. __lpc_eth_shutdown(pldat);
  1298. clk_disable(pldat->clk);
  1299. /*
  1300. * Reset again now clock is disable to be sure
  1301. * EMC_MDC is down
  1302. */
  1303. __lpc_eth_reset(pldat);
  1304. }
  1305. }
  1306. return 0;
  1307. }
  1308. static int lpc_eth_drv_resume(struct platform_device *pdev)
  1309. {
  1310. struct net_device *ndev = platform_get_drvdata(pdev);
  1311. struct netdata_local *pldat;
  1312. if (device_may_wakeup(&pdev->dev))
  1313. disable_irq_wake(ndev->irq);
  1314. if (ndev) {
  1315. if (netif_running(ndev)) {
  1316. pldat = netdev_priv(ndev);
  1317. /* Enable interface clock */
  1318. clk_enable(pldat->clk);
  1319. /* Reset and initialize */
  1320. __lpc_eth_reset(pldat);
  1321. __lpc_eth_init(pldat);
  1322. netif_device_attach(ndev);
  1323. }
  1324. }
  1325. return 0;
  1326. }
  1327. #endif
  1328. static struct platform_driver lpc_eth_driver = {
  1329. .probe = lpc_eth_drv_probe,
  1330. .remove = __devexit_p(lpc_eth_drv_remove),
  1331. #ifdef CONFIG_PM
  1332. .suspend = lpc_eth_drv_suspend,
  1333. .resume = lpc_eth_drv_resume,
  1334. #endif
  1335. .driver = {
  1336. .name = MODNAME,
  1337. },
  1338. };
  1339. module_platform_driver(lpc_eth_driver);
  1340. MODULE_AUTHOR("Kevin Wells <kevin.wells@nxp.com>");
  1341. MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>");
  1342. MODULE_DESCRIPTION("LPC Ethernet Driver");
  1343. MODULE_LICENSE("GPL");