ll_temac_main.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190
  1. /*
  2. * Driver for Xilinx TEMAC Ethernet device
  3. *
  4. * Copyright (c) 2008 Nissin Systems Co., Ltd., Yoshio Kashiwagi
  5. * Copyright (c) 2005-2008 DLA Systems, David H. Lynch Jr. <dhlii@dlasys.net>
  6. * Copyright (c) 2008-2009 Secret Lab Technologies Ltd.
  7. *
  8. * This is a driver for the Xilinx ll_temac ipcore which is often used
  9. * in the Virtex and Spartan series of chips.
  10. *
  11. * Notes:
  12. * - The ll_temac hardware uses indirect access for many of the TEMAC
  13. * registers, include the MDIO bus. However, indirect access to MDIO
  14. * registers take considerably more clock cycles than to TEMAC registers.
  15. * MDIO accesses are long, so threads doing them should probably sleep
  16. * rather than busywait. However, since only one indirect access can be
  17. * in progress at any given time, that means that *all* indirect accesses
  18. * could end up sleeping (to wait for an MDIO access to complete).
  19. * Fortunately none of the indirect accesses are on the 'hot' path for tx
  20. * or rx, so this should be okay.
  21. *
  22. * TODO:
  23. * - Factor out locallink DMA code into separate driver
  24. * - Fix multicast assignment.
  25. * - Fix support for hardware checksumming.
  26. * - Testing. Lots and lots of testing.
  27. *
  28. */
  29. #include <linux/delay.h>
  30. #include <linux/etherdevice.h>
  31. #include <linux/init.h>
  32. #include <linux/mii.h>
  33. #include <linux/module.h>
  34. #include <linux/mutex.h>
  35. #include <linux/netdevice.h>
  36. #include <linux/of.h>
  37. #include <linux/of_device.h>
  38. #include <linux/of_mdio.h>
  39. #include <linux/of_platform.h>
  40. #include <linux/of_address.h>
  41. #include <linux/skbuff.h>
  42. #include <linux/spinlock.h>
  43. #include <linux/tcp.h> /* needed for sizeof(tcphdr) */
  44. #include <linux/udp.h> /* needed for sizeof(udphdr) */
  45. #include <linux/phy.h>
  46. #include <linux/in.h>
  47. #include <linux/io.h>
  48. #include <linux/ip.h>
  49. #include <linux/slab.h>
  50. #include <linux/interrupt.h>
  51. #include <linux/dma-mapping.h>
  52. #include "ll_temac.h"
  53. #define TX_BD_NUM 64
  54. #define RX_BD_NUM 128
  55. /* ---------------------------------------------------------------------
  56. * Low level register access functions
  57. */
  58. u32 temac_ior(struct temac_local *lp, int offset)
  59. {
  60. return in_be32((u32 *)(lp->regs + offset));
  61. }
  62. void temac_iow(struct temac_local *lp, int offset, u32 value)
  63. {
  64. out_be32((u32 *) (lp->regs + offset), value);
  65. }
  66. int temac_indirect_busywait(struct temac_local *lp)
  67. {
  68. long end = jiffies + 2;
  69. while (!(temac_ior(lp, XTE_RDY0_OFFSET) & XTE_RDY0_HARD_ACS_RDY_MASK)) {
  70. if (end - jiffies <= 0) {
  71. WARN_ON(1);
  72. return -ETIMEDOUT;
  73. }
  74. msleep(1);
  75. }
  76. return 0;
  77. }
  78. /**
  79. * temac_indirect_in32
  80. *
  81. * lp->indirect_mutex must be held when calling this function
  82. */
  83. u32 temac_indirect_in32(struct temac_local *lp, int reg)
  84. {
  85. u32 val;
  86. if (temac_indirect_busywait(lp))
  87. return -ETIMEDOUT;
  88. temac_iow(lp, XTE_CTL0_OFFSET, reg);
  89. if (temac_indirect_busywait(lp))
  90. return -ETIMEDOUT;
  91. val = temac_ior(lp, XTE_LSW0_OFFSET);
  92. return val;
  93. }
  94. /**
  95. * temac_indirect_out32
  96. *
  97. * lp->indirect_mutex must be held when calling this function
  98. */
  99. void temac_indirect_out32(struct temac_local *lp, int reg, u32 value)
  100. {
  101. if (temac_indirect_busywait(lp))
  102. return;
  103. temac_iow(lp, XTE_LSW0_OFFSET, value);
  104. temac_iow(lp, XTE_CTL0_OFFSET, CNTLREG_WRITE_ENABLE_MASK | reg);
  105. temac_indirect_busywait(lp);
  106. }
  107. /**
  108. * temac_dma_in32 - Memory mapped DMA read, this function expects a
  109. * register input that is based on DCR word addresses which
  110. * are then converted to memory mapped byte addresses
  111. */
  112. static u32 temac_dma_in32(struct temac_local *lp, int reg)
  113. {
  114. return in_be32((u32 *)(lp->sdma_regs + (reg << 2)));
  115. }
  116. /**
  117. * temac_dma_out32 - Memory mapped DMA read, this function expects a
  118. * register input that is based on DCR word addresses which
  119. * are then converted to memory mapped byte addresses
  120. */
  121. static void temac_dma_out32(struct temac_local *lp, int reg, u32 value)
  122. {
  123. out_be32((u32 *)(lp->sdma_regs + (reg << 2)), value);
  124. }
  125. /* DMA register access functions can be DCR based or memory mapped.
  126. * The PowerPC 440 is DCR based, the PowerPC 405 and MicroBlaze are both
  127. * memory mapped.
  128. */
  129. #ifdef CONFIG_PPC_DCR
  130. /**
  131. * temac_dma_dcr_in32 - DCR based DMA read
  132. */
  133. static u32 temac_dma_dcr_in(struct temac_local *lp, int reg)
  134. {
  135. return dcr_read(lp->sdma_dcrs, reg);
  136. }
  137. /**
  138. * temac_dma_dcr_out32 - DCR based DMA write
  139. */
  140. static void temac_dma_dcr_out(struct temac_local *lp, int reg, u32 value)
  141. {
  142. dcr_write(lp->sdma_dcrs, reg, value);
  143. }
  144. /**
  145. * temac_dcr_setup - If the DMA is DCR based, then setup the address and
  146. * I/O functions
  147. */
  148. static int temac_dcr_setup(struct temac_local *lp, struct platform_device *op,
  149. struct device_node *np)
  150. {
  151. unsigned int dcrs;
  152. /* setup the dcr address mapping if it's in the device tree */
  153. dcrs = dcr_resource_start(np, 0);
  154. if (dcrs != 0) {
  155. lp->sdma_dcrs = dcr_map(np, dcrs, dcr_resource_len(np, 0));
  156. lp->dma_in = temac_dma_dcr_in;
  157. lp->dma_out = temac_dma_dcr_out;
  158. dev_dbg(&op->dev, "DCR base: %x\n", dcrs);
  159. return 0;
  160. }
  161. /* no DCR in the device tree, indicate a failure */
  162. return -1;
  163. }
  164. #else
  165. /*
  166. * temac_dcr_setup - This is a stub for when DCR is not supported,
  167. * such as with MicroBlaze
  168. */
  169. static int temac_dcr_setup(struct temac_local *lp, struct platform_device *op,
  170. struct device_node *np)
  171. {
  172. return -1;
  173. }
  174. #endif
  175. /**
  176. * * temac_dma_bd_release - Release buffer descriptor rings
  177. */
  178. static void temac_dma_bd_release(struct net_device *ndev)
  179. {
  180. struct temac_local *lp = netdev_priv(ndev);
  181. int i;
  182. /* Reset Local Link (DMA) */
  183. lp->dma_out(lp, DMA_CONTROL_REG, DMA_CONTROL_RST);
  184. for (i = 0; i < RX_BD_NUM; i++) {
  185. if (!lp->rx_skb[i])
  186. break;
  187. else {
  188. dma_unmap_single(ndev->dev.parent, lp->rx_bd_v[i].phys,
  189. XTE_MAX_JUMBO_FRAME_SIZE, DMA_FROM_DEVICE);
  190. dev_kfree_skb(lp->rx_skb[i]);
  191. }
  192. }
  193. if (lp->rx_bd_v)
  194. dma_free_coherent(ndev->dev.parent,
  195. sizeof(*lp->rx_bd_v) * RX_BD_NUM,
  196. lp->rx_bd_v, lp->rx_bd_p);
  197. if (lp->tx_bd_v)
  198. dma_free_coherent(ndev->dev.parent,
  199. sizeof(*lp->tx_bd_v) * TX_BD_NUM,
  200. lp->tx_bd_v, lp->tx_bd_p);
  201. if (lp->rx_skb)
  202. kfree(lp->rx_skb);
  203. }
  204. /**
  205. * temac_dma_bd_init - Setup buffer descriptor rings
  206. */
  207. static int temac_dma_bd_init(struct net_device *ndev)
  208. {
  209. struct temac_local *lp = netdev_priv(ndev);
  210. struct sk_buff *skb;
  211. int i;
  212. lp->rx_skb = kcalloc(RX_BD_NUM, sizeof(*lp->rx_skb), GFP_KERNEL);
  213. if (!lp->rx_skb) {
  214. dev_err(&ndev->dev,
  215. "can't allocate memory for DMA RX buffer\n");
  216. goto out;
  217. }
  218. /* allocate the tx and rx ring buffer descriptors. */
  219. /* returns a virtual address and a physical address. */
  220. lp->tx_bd_v = dma_alloc_coherent(ndev->dev.parent,
  221. sizeof(*lp->tx_bd_v) * TX_BD_NUM,
  222. &lp->tx_bd_p, GFP_KERNEL);
  223. if (!lp->tx_bd_v) {
  224. dev_err(&ndev->dev,
  225. "unable to allocate DMA TX buffer descriptors");
  226. goto out;
  227. }
  228. lp->rx_bd_v = dma_alloc_coherent(ndev->dev.parent,
  229. sizeof(*lp->rx_bd_v) * RX_BD_NUM,
  230. &lp->rx_bd_p, GFP_KERNEL);
  231. if (!lp->rx_bd_v) {
  232. dev_err(&ndev->dev,
  233. "unable to allocate DMA RX buffer descriptors");
  234. goto out;
  235. }
  236. memset(lp->tx_bd_v, 0, sizeof(*lp->tx_bd_v) * TX_BD_NUM);
  237. for (i = 0; i < TX_BD_NUM; i++) {
  238. lp->tx_bd_v[i].next = lp->tx_bd_p +
  239. sizeof(*lp->tx_bd_v) * ((i + 1) % TX_BD_NUM);
  240. }
  241. memset(lp->rx_bd_v, 0, sizeof(*lp->rx_bd_v) * RX_BD_NUM);
  242. for (i = 0; i < RX_BD_NUM; i++) {
  243. lp->rx_bd_v[i].next = lp->rx_bd_p +
  244. sizeof(*lp->rx_bd_v) * ((i + 1) % RX_BD_NUM);
  245. skb = netdev_alloc_skb_ip_align(ndev,
  246. XTE_MAX_JUMBO_FRAME_SIZE);
  247. if (skb == 0) {
  248. dev_err(&ndev->dev, "alloc_skb error %d\n", i);
  249. goto out;
  250. }
  251. lp->rx_skb[i] = skb;
  252. /* returns physical address of skb->data */
  253. lp->rx_bd_v[i].phys = dma_map_single(ndev->dev.parent,
  254. skb->data,
  255. XTE_MAX_JUMBO_FRAME_SIZE,
  256. DMA_FROM_DEVICE);
  257. lp->rx_bd_v[i].len = XTE_MAX_JUMBO_FRAME_SIZE;
  258. lp->rx_bd_v[i].app0 = STS_CTRL_APP0_IRQONEND;
  259. }
  260. lp->dma_out(lp, TX_CHNL_CTRL, 0x10220400 |
  261. CHNL_CTRL_IRQ_EN |
  262. CHNL_CTRL_IRQ_DLY_EN |
  263. CHNL_CTRL_IRQ_COAL_EN);
  264. /* 0x10220483 */
  265. /* 0x00100483 */
  266. lp->dma_out(lp, RX_CHNL_CTRL, 0xff070000 |
  267. CHNL_CTRL_IRQ_EN |
  268. CHNL_CTRL_IRQ_DLY_EN |
  269. CHNL_CTRL_IRQ_COAL_EN |
  270. CHNL_CTRL_IRQ_IOE);
  271. /* 0xff010283 */
  272. lp->dma_out(lp, RX_CURDESC_PTR, lp->rx_bd_p);
  273. lp->dma_out(lp, RX_TAILDESC_PTR,
  274. lp->rx_bd_p + (sizeof(*lp->rx_bd_v) * (RX_BD_NUM - 1)));
  275. lp->dma_out(lp, TX_CURDESC_PTR, lp->tx_bd_p);
  276. return 0;
  277. out:
  278. temac_dma_bd_release(ndev);
  279. return -ENOMEM;
  280. }
  281. /* ---------------------------------------------------------------------
  282. * net_device_ops
  283. */
  284. static int temac_set_mac_address(struct net_device *ndev, void *address)
  285. {
  286. struct temac_local *lp = netdev_priv(ndev);
  287. if (address)
  288. memcpy(ndev->dev_addr, address, ETH_ALEN);
  289. if (!is_valid_ether_addr(ndev->dev_addr))
  290. eth_hw_addr_random(ndev);
  291. else
  292. ndev->addr_assign_type &= ~NET_ADDR_RANDOM;
  293. /* set up unicast MAC address filter set its mac address */
  294. mutex_lock(&lp->indirect_mutex);
  295. temac_indirect_out32(lp, XTE_UAW0_OFFSET,
  296. (ndev->dev_addr[0]) |
  297. (ndev->dev_addr[1] << 8) |
  298. (ndev->dev_addr[2] << 16) |
  299. (ndev->dev_addr[3] << 24));
  300. /* There are reserved bits in EUAW1
  301. * so don't affect them Set MAC bits [47:32] in EUAW1 */
  302. temac_indirect_out32(lp, XTE_UAW1_OFFSET,
  303. (ndev->dev_addr[4] & 0x000000ff) |
  304. (ndev->dev_addr[5] << 8));
  305. mutex_unlock(&lp->indirect_mutex);
  306. return 0;
  307. }
  308. static int netdev_set_mac_address(struct net_device *ndev, void *p)
  309. {
  310. struct sockaddr *addr = p;
  311. return temac_set_mac_address(ndev, addr->sa_data);
  312. }
  313. static void temac_set_multicast_list(struct net_device *ndev)
  314. {
  315. struct temac_local *lp = netdev_priv(ndev);
  316. u32 multi_addr_msw, multi_addr_lsw, val;
  317. int i;
  318. mutex_lock(&lp->indirect_mutex);
  319. if (ndev->flags & (IFF_ALLMULTI | IFF_PROMISC) ||
  320. netdev_mc_count(ndev) > MULTICAST_CAM_TABLE_NUM) {
  321. /*
  322. * We must make the kernel realise we had to move
  323. * into promisc mode or we start all out war on
  324. * the cable. If it was a promisc request the
  325. * flag is already set. If not we assert it.
  326. */
  327. ndev->flags |= IFF_PROMISC;
  328. temac_indirect_out32(lp, XTE_AFM_OFFSET, XTE_AFM_EPPRM_MASK);
  329. dev_info(&ndev->dev, "Promiscuous mode enabled.\n");
  330. } else if (!netdev_mc_empty(ndev)) {
  331. struct netdev_hw_addr *ha;
  332. i = 0;
  333. netdev_for_each_mc_addr(ha, ndev) {
  334. if (i >= MULTICAST_CAM_TABLE_NUM)
  335. break;
  336. multi_addr_msw = ((ha->addr[3] << 24) |
  337. (ha->addr[2] << 16) |
  338. (ha->addr[1] << 8) |
  339. (ha->addr[0]));
  340. temac_indirect_out32(lp, XTE_MAW0_OFFSET,
  341. multi_addr_msw);
  342. multi_addr_lsw = ((ha->addr[5] << 8) |
  343. (ha->addr[4]) | (i << 16));
  344. temac_indirect_out32(lp, XTE_MAW1_OFFSET,
  345. multi_addr_lsw);
  346. i++;
  347. }
  348. } else {
  349. val = temac_indirect_in32(lp, XTE_AFM_OFFSET);
  350. temac_indirect_out32(lp, XTE_AFM_OFFSET,
  351. val & ~XTE_AFM_EPPRM_MASK);
  352. temac_indirect_out32(lp, XTE_MAW0_OFFSET, 0);
  353. temac_indirect_out32(lp, XTE_MAW1_OFFSET, 0);
  354. dev_info(&ndev->dev, "Promiscuous mode disabled.\n");
  355. }
  356. mutex_unlock(&lp->indirect_mutex);
  357. }
  358. struct temac_option {
  359. int flg;
  360. u32 opt;
  361. u32 reg;
  362. u32 m_or;
  363. u32 m_and;
  364. } temac_options[] = {
  365. /* Turn on jumbo packet support for both Rx and Tx */
  366. {
  367. .opt = XTE_OPTION_JUMBO,
  368. .reg = XTE_TXC_OFFSET,
  369. .m_or = XTE_TXC_TXJMBO_MASK,
  370. },
  371. {
  372. .opt = XTE_OPTION_JUMBO,
  373. .reg = XTE_RXC1_OFFSET,
  374. .m_or =XTE_RXC1_RXJMBO_MASK,
  375. },
  376. /* Turn on VLAN packet support for both Rx and Tx */
  377. {
  378. .opt = XTE_OPTION_VLAN,
  379. .reg = XTE_TXC_OFFSET,
  380. .m_or =XTE_TXC_TXVLAN_MASK,
  381. },
  382. {
  383. .opt = XTE_OPTION_VLAN,
  384. .reg = XTE_RXC1_OFFSET,
  385. .m_or =XTE_RXC1_RXVLAN_MASK,
  386. },
  387. /* Turn on FCS stripping on receive packets */
  388. {
  389. .opt = XTE_OPTION_FCS_STRIP,
  390. .reg = XTE_RXC1_OFFSET,
  391. .m_or =XTE_RXC1_RXFCS_MASK,
  392. },
  393. /* Turn on FCS insertion on transmit packets */
  394. {
  395. .opt = XTE_OPTION_FCS_INSERT,
  396. .reg = XTE_TXC_OFFSET,
  397. .m_or =XTE_TXC_TXFCS_MASK,
  398. },
  399. /* Turn on length/type field checking on receive packets */
  400. {
  401. .opt = XTE_OPTION_LENTYPE_ERR,
  402. .reg = XTE_RXC1_OFFSET,
  403. .m_or =XTE_RXC1_RXLT_MASK,
  404. },
  405. /* Turn on flow control */
  406. {
  407. .opt = XTE_OPTION_FLOW_CONTROL,
  408. .reg = XTE_FCC_OFFSET,
  409. .m_or =XTE_FCC_RXFLO_MASK,
  410. },
  411. /* Turn on flow control */
  412. {
  413. .opt = XTE_OPTION_FLOW_CONTROL,
  414. .reg = XTE_FCC_OFFSET,
  415. .m_or =XTE_FCC_TXFLO_MASK,
  416. },
  417. /* Turn on promiscuous frame filtering (all frames are received ) */
  418. {
  419. .opt = XTE_OPTION_PROMISC,
  420. .reg = XTE_AFM_OFFSET,
  421. .m_or =XTE_AFM_EPPRM_MASK,
  422. },
  423. /* Enable transmitter if not already enabled */
  424. {
  425. .opt = XTE_OPTION_TXEN,
  426. .reg = XTE_TXC_OFFSET,
  427. .m_or =XTE_TXC_TXEN_MASK,
  428. },
  429. /* Enable receiver? */
  430. {
  431. .opt = XTE_OPTION_RXEN,
  432. .reg = XTE_RXC1_OFFSET,
  433. .m_or =XTE_RXC1_RXEN_MASK,
  434. },
  435. {}
  436. };
  437. /**
  438. * temac_setoptions
  439. */
  440. static u32 temac_setoptions(struct net_device *ndev, u32 options)
  441. {
  442. struct temac_local *lp = netdev_priv(ndev);
  443. struct temac_option *tp = &temac_options[0];
  444. int reg;
  445. mutex_lock(&lp->indirect_mutex);
  446. while (tp->opt) {
  447. reg = temac_indirect_in32(lp, tp->reg) & ~tp->m_or;
  448. if (options & tp->opt)
  449. reg |= tp->m_or;
  450. temac_indirect_out32(lp, tp->reg, reg);
  451. tp++;
  452. }
  453. lp->options |= options;
  454. mutex_unlock(&lp->indirect_mutex);
  455. return 0;
  456. }
  457. /* Initialize temac */
  458. static void temac_device_reset(struct net_device *ndev)
  459. {
  460. struct temac_local *lp = netdev_priv(ndev);
  461. u32 timeout;
  462. u32 val;
  463. /* Perform a software reset */
  464. /* 0x300 host enable bit ? */
  465. /* reset PHY through control register ?:1 */
  466. dev_dbg(&ndev->dev, "%s()\n", __func__);
  467. mutex_lock(&lp->indirect_mutex);
  468. /* Reset the receiver and wait for it to finish reset */
  469. temac_indirect_out32(lp, XTE_RXC1_OFFSET, XTE_RXC1_RXRST_MASK);
  470. timeout = 1000;
  471. while (temac_indirect_in32(lp, XTE_RXC1_OFFSET) & XTE_RXC1_RXRST_MASK) {
  472. udelay(1);
  473. if (--timeout == 0) {
  474. dev_err(&ndev->dev,
  475. "temac_device_reset RX reset timeout!!\n");
  476. break;
  477. }
  478. }
  479. /* Reset the transmitter and wait for it to finish reset */
  480. temac_indirect_out32(lp, XTE_TXC_OFFSET, XTE_TXC_TXRST_MASK);
  481. timeout = 1000;
  482. while (temac_indirect_in32(lp, XTE_TXC_OFFSET) & XTE_TXC_TXRST_MASK) {
  483. udelay(1);
  484. if (--timeout == 0) {
  485. dev_err(&ndev->dev,
  486. "temac_device_reset TX reset timeout!!\n");
  487. break;
  488. }
  489. }
  490. /* Disable the receiver */
  491. val = temac_indirect_in32(lp, XTE_RXC1_OFFSET);
  492. temac_indirect_out32(lp, XTE_RXC1_OFFSET, val & ~XTE_RXC1_RXEN_MASK);
  493. /* Reset Local Link (DMA) */
  494. lp->dma_out(lp, DMA_CONTROL_REG, DMA_CONTROL_RST);
  495. timeout = 1000;
  496. while (lp->dma_in(lp, DMA_CONTROL_REG) & DMA_CONTROL_RST) {
  497. udelay(1);
  498. if (--timeout == 0) {
  499. dev_err(&ndev->dev,
  500. "temac_device_reset DMA reset timeout!!\n");
  501. break;
  502. }
  503. }
  504. lp->dma_out(lp, DMA_CONTROL_REG, DMA_TAIL_ENABLE);
  505. if (temac_dma_bd_init(ndev)) {
  506. dev_err(&ndev->dev,
  507. "temac_device_reset descriptor allocation failed\n");
  508. }
  509. temac_indirect_out32(lp, XTE_RXC0_OFFSET, 0);
  510. temac_indirect_out32(lp, XTE_RXC1_OFFSET, 0);
  511. temac_indirect_out32(lp, XTE_TXC_OFFSET, 0);
  512. temac_indirect_out32(lp, XTE_FCC_OFFSET, XTE_FCC_RXFLO_MASK);
  513. mutex_unlock(&lp->indirect_mutex);
  514. /* Sync default options with HW
  515. * but leave receiver and transmitter disabled. */
  516. temac_setoptions(ndev,
  517. lp->options & ~(XTE_OPTION_TXEN | XTE_OPTION_RXEN));
  518. temac_set_mac_address(ndev, NULL);
  519. /* Set address filter table */
  520. temac_set_multicast_list(ndev);
  521. if (temac_setoptions(ndev, lp->options))
  522. dev_err(&ndev->dev, "Error setting TEMAC options\n");
  523. /* Init Driver variable */
  524. ndev->trans_start = jiffies; /* prevent tx timeout */
  525. }
  526. void temac_adjust_link(struct net_device *ndev)
  527. {
  528. struct temac_local *lp = netdev_priv(ndev);
  529. struct phy_device *phy = lp->phy_dev;
  530. u32 mii_speed;
  531. int link_state;
  532. /* hash together the state values to decide if something has changed */
  533. link_state = phy->speed | (phy->duplex << 1) | phy->link;
  534. mutex_lock(&lp->indirect_mutex);
  535. if (lp->last_link != link_state) {
  536. mii_speed = temac_indirect_in32(lp, XTE_EMCFG_OFFSET);
  537. mii_speed &= ~XTE_EMCFG_LINKSPD_MASK;
  538. switch (phy->speed) {
  539. case SPEED_1000: mii_speed |= XTE_EMCFG_LINKSPD_1000; break;
  540. case SPEED_100: mii_speed |= XTE_EMCFG_LINKSPD_100; break;
  541. case SPEED_10: mii_speed |= XTE_EMCFG_LINKSPD_10; break;
  542. }
  543. /* Write new speed setting out to TEMAC */
  544. temac_indirect_out32(lp, XTE_EMCFG_OFFSET, mii_speed);
  545. lp->last_link = link_state;
  546. phy_print_status(phy);
  547. }
  548. mutex_unlock(&lp->indirect_mutex);
  549. }
  550. static void temac_start_xmit_done(struct net_device *ndev)
  551. {
  552. struct temac_local *lp = netdev_priv(ndev);
  553. struct cdmac_bd *cur_p;
  554. unsigned int stat = 0;
  555. cur_p = &lp->tx_bd_v[lp->tx_bd_ci];
  556. stat = cur_p->app0;
  557. while (stat & STS_CTRL_APP0_CMPLT) {
  558. dma_unmap_single(ndev->dev.parent, cur_p->phys, cur_p->len,
  559. DMA_TO_DEVICE);
  560. if (cur_p->app4)
  561. dev_kfree_skb_irq((struct sk_buff *)cur_p->app4);
  562. cur_p->app0 = 0;
  563. cur_p->app1 = 0;
  564. cur_p->app2 = 0;
  565. cur_p->app3 = 0;
  566. cur_p->app4 = 0;
  567. ndev->stats.tx_packets++;
  568. ndev->stats.tx_bytes += cur_p->len;
  569. lp->tx_bd_ci++;
  570. if (lp->tx_bd_ci >= TX_BD_NUM)
  571. lp->tx_bd_ci = 0;
  572. cur_p = &lp->tx_bd_v[lp->tx_bd_ci];
  573. stat = cur_p->app0;
  574. }
  575. netif_wake_queue(ndev);
  576. }
  577. static inline int temac_check_tx_bd_space(struct temac_local *lp, int num_frag)
  578. {
  579. struct cdmac_bd *cur_p;
  580. int tail;
  581. tail = lp->tx_bd_tail;
  582. cur_p = &lp->tx_bd_v[tail];
  583. do {
  584. if (cur_p->app0)
  585. return NETDEV_TX_BUSY;
  586. tail++;
  587. if (tail >= TX_BD_NUM)
  588. tail = 0;
  589. cur_p = &lp->tx_bd_v[tail];
  590. num_frag--;
  591. } while (num_frag >= 0);
  592. return 0;
  593. }
  594. static int temac_start_xmit(struct sk_buff *skb, struct net_device *ndev)
  595. {
  596. struct temac_local *lp = netdev_priv(ndev);
  597. struct cdmac_bd *cur_p;
  598. dma_addr_t start_p, tail_p;
  599. int ii;
  600. unsigned long num_frag;
  601. skb_frag_t *frag;
  602. num_frag = skb_shinfo(skb)->nr_frags;
  603. frag = &skb_shinfo(skb)->frags[0];
  604. start_p = lp->tx_bd_p + sizeof(*lp->tx_bd_v) * lp->tx_bd_tail;
  605. cur_p = &lp->tx_bd_v[lp->tx_bd_tail];
  606. if (temac_check_tx_bd_space(lp, num_frag)) {
  607. if (!netif_queue_stopped(ndev)) {
  608. netif_stop_queue(ndev);
  609. return NETDEV_TX_BUSY;
  610. }
  611. return NETDEV_TX_BUSY;
  612. }
  613. cur_p->app0 = 0;
  614. if (skb->ip_summed == CHECKSUM_PARTIAL) {
  615. unsigned int csum_start_off = skb_checksum_start_offset(skb);
  616. unsigned int csum_index_off = csum_start_off + skb->csum_offset;
  617. cur_p->app0 |= 1; /* TX Checksum Enabled */
  618. cur_p->app1 = (csum_start_off << 16) | csum_index_off;
  619. cur_p->app2 = 0; /* initial checksum seed */
  620. }
  621. cur_p->app0 |= STS_CTRL_APP0_SOP;
  622. cur_p->len = skb_headlen(skb);
  623. cur_p->phys = dma_map_single(ndev->dev.parent, skb->data, skb->len,
  624. DMA_TO_DEVICE);
  625. cur_p->app4 = (unsigned long)skb;
  626. for (ii = 0; ii < num_frag; ii++) {
  627. lp->tx_bd_tail++;
  628. if (lp->tx_bd_tail >= TX_BD_NUM)
  629. lp->tx_bd_tail = 0;
  630. cur_p = &lp->tx_bd_v[lp->tx_bd_tail];
  631. cur_p->phys = dma_map_single(ndev->dev.parent,
  632. skb_frag_address(frag),
  633. skb_frag_size(frag), DMA_TO_DEVICE);
  634. cur_p->len = skb_frag_size(frag);
  635. cur_p->app0 = 0;
  636. frag++;
  637. }
  638. cur_p->app0 |= STS_CTRL_APP0_EOP;
  639. tail_p = lp->tx_bd_p + sizeof(*lp->tx_bd_v) * lp->tx_bd_tail;
  640. lp->tx_bd_tail++;
  641. if (lp->tx_bd_tail >= TX_BD_NUM)
  642. lp->tx_bd_tail = 0;
  643. skb_tx_timestamp(skb);
  644. /* Kick off the transfer */
  645. lp->dma_out(lp, TX_TAILDESC_PTR, tail_p); /* DMA start */
  646. return NETDEV_TX_OK;
  647. }
  648. static void ll_temac_recv(struct net_device *ndev)
  649. {
  650. struct temac_local *lp = netdev_priv(ndev);
  651. struct sk_buff *skb, *new_skb;
  652. unsigned int bdstat;
  653. struct cdmac_bd *cur_p;
  654. dma_addr_t tail_p;
  655. int length;
  656. unsigned long flags;
  657. spin_lock_irqsave(&lp->rx_lock, flags);
  658. tail_p = lp->rx_bd_p + sizeof(*lp->rx_bd_v) * lp->rx_bd_ci;
  659. cur_p = &lp->rx_bd_v[lp->rx_bd_ci];
  660. bdstat = cur_p->app0;
  661. while ((bdstat & STS_CTRL_APP0_CMPLT)) {
  662. skb = lp->rx_skb[lp->rx_bd_ci];
  663. length = cur_p->app4 & 0x3FFF;
  664. dma_unmap_single(ndev->dev.parent, cur_p->phys, length,
  665. DMA_FROM_DEVICE);
  666. skb_put(skb, length);
  667. skb->dev = ndev;
  668. skb->protocol = eth_type_trans(skb, ndev);
  669. skb_checksum_none_assert(skb);
  670. /* if we're doing rx csum offload, set it up */
  671. if (((lp->temac_features & TEMAC_FEATURE_RX_CSUM) != 0) &&
  672. (skb->protocol == __constant_htons(ETH_P_IP)) &&
  673. (skb->len > 64)) {
  674. skb->csum = cur_p->app3 & 0xFFFF;
  675. skb->ip_summed = CHECKSUM_COMPLETE;
  676. }
  677. if (!skb_defer_rx_timestamp(skb))
  678. netif_rx(skb);
  679. ndev->stats.rx_packets++;
  680. ndev->stats.rx_bytes += length;
  681. new_skb = netdev_alloc_skb_ip_align(ndev,
  682. XTE_MAX_JUMBO_FRAME_SIZE);
  683. if (new_skb == 0) {
  684. dev_err(&ndev->dev, "no memory for new sk_buff\n");
  685. spin_unlock_irqrestore(&lp->rx_lock, flags);
  686. return;
  687. }
  688. cur_p->app0 = STS_CTRL_APP0_IRQONEND;
  689. cur_p->phys = dma_map_single(ndev->dev.parent, new_skb->data,
  690. XTE_MAX_JUMBO_FRAME_SIZE,
  691. DMA_FROM_DEVICE);
  692. cur_p->len = XTE_MAX_JUMBO_FRAME_SIZE;
  693. lp->rx_skb[lp->rx_bd_ci] = new_skb;
  694. lp->rx_bd_ci++;
  695. if (lp->rx_bd_ci >= RX_BD_NUM)
  696. lp->rx_bd_ci = 0;
  697. cur_p = &lp->rx_bd_v[lp->rx_bd_ci];
  698. bdstat = cur_p->app0;
  699. }
  700. lp->dma_out(lp, RX_TAILDESC_PTR, tail_p);
  701. spin_unlock_irqrestore(&lp->rx_lock, flags);
  702. }
  703. static irqreturn_t ll_temac_tx_irq(int irq, void *_ndev)
  704. {
  705. struct net_device *ndev = _ndev;
  706. struct temac_local *lp = netdev_priv(ndev);
  707. unsigned int status;
  708. status = lp->dma_in(lp, TX_IRQ_REG);
  709. lp->dma_out(lp, TX_IRQ_REG, status);
  710. if (status & (IRQ_COAL | IRQ_DLY))
  711. temac_start_xmit_done(lp->ndev);
  712. if (status & 0x080)
  713. dev_err(&ndev->dev, "DMA error 0x%x\n", status);
  714. return IRQ_HANDLED;
  715. }
  716. static irqreturn_t ll_temac_rx_irq(int irq, void *_ndev)
  717. {
  718. struct net_device *ndev = _ndev;
  719. struct temac_local *lp = netdev_priv(ndev);
  720. unsigned int status;
  721. /* Read and clear the status registers */
  722. status = lp->dma_in(lp, RX_IRQ_REG);
  723. lp->dma_out(lp, RX_IRQ_REG, status);
  724. if (status & (IRQ_COAL | IRQ_DLY))
  725. ll_temac_recv(lp->ndev);
  726. return IRQ_HANDLED;
  727. }
  728. static int temac_open(struct net_device *ndev)
  729. {
  730. struct temac_local *lp = netdev_priv(ndev);
  731. int rc;
  732. dev_dbg(&ndev->dev, "temac_open()\n");
  733. if (lp->phy_node) {
  734. lp->phy_dev = of_phy_connect(lp->ndev, lp->phy_node,
  735. temac_adjust_link, 0, 0);
  736. if (!lp->phy_dev) {
  737. dev_err(lp->dev, "of_phy_connect() failed\n");
  738. return -ENODEV;
  739. }
  740. phy_start(lp->phy_dev);
  741. }
  742. temac_device_reset(ndev);
  743. rc = request_irq(lp->tx_irq, ll_temac_tx_irq, 0, ndev->name, ndev);
  744. if (rc)
  745. goto err_tx_irq;
  746. rc = request_irq(lp->rx_irq, ll_temac_rx_irq, 0, ndev->name, ndev);
  747. if (rc)
  748. goto err_rx_irq;
  749. return 0;
  750. err_rx_irq:
  751. free_irq(lp->tx_irq, ndev);
  752. err_tx_irq:
  753. if (lp->phy_dev)
  754. phy_disconnect(lp->phy_dev);
  755. lp->phy_dev = NULL;
  756. dev_err(lp->dev, "request_irq() failed\n");
  757. return rc;
  758. }
  759. static int temac_stop(struct net_device *ndev)
  760. {
  761. struct temac_local *lp = netdev_priv(ndev);
  762. dev_dbg(&ndev->dev, "temac_close()\n");
  763. free_irq(lp->tx_irq, ndev);
  764. free_irq(lp->rx_irq, ndev);
  765. if (lp->phy_dev)
  766. phy_disconnect(lp->phy_dev);
  767. lp->phy_dev = NULL;
  768. temac_dma_bd_release(ndev);
  769. return 0;
  770. }
  771. #ifdef CONFIG_NET_POLL_CONTROLLER
  772. static void
  773. temac_poll_controller(struct net_device *ndev)
  774. {
  775. struct temac_local *lp = netdev_priv(ndev);
  776. disable_irq(lp->tx_irq);
  777. disable_irq(lp->rx_irq);
  778. ll_temac_rx_irq(lp->tx_irq, ndev);
  779. ll_temac_tx_irq(lp->rx_irq, ndev);
  780. enable_irq(lp->tx_irq);
  781. enable_irq(lp->rx_irq);
  782. }
  783. #endif
  784. static int temac_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd)
  785. {
  786. struct temac_local *lp = netdev_priv(ndev);
  787. if (!netif_running(ndev))
  788. return -EINVAL;
  789. if (!lp->phy_dev)
  790. return -EINVAL;
  791. return phy_mii_ioctl(lp->phy_dev, rq, cmd);
  792. }
  793. static const struct net_device_ops temac_netdev_ops = {
  794. .ndo_open = temac_open,
  795. .ndo_stop = temac_stop,
  796. .ndo_start_xmit = temac_start_xmit,
  797. .ndo_set_mac_address = netdev_set_mac_address,
  798. .ndo_validate_addr = eth_validate_addr,
  799. .ndo_do_ioctl = temac_ioctl,
  800. #ifdef CONFIG_NET_POLL_CONTROLLER
  801. .ndo_poll_controller = temac_poll_controller,
  802. #endif
  803. };
  804. /* ---------------------------------------------------------------------
  805. * SYSFS device attributes
  806. */
  807. static ssize_t temac_show_llink_regs(struct device *dev,
  808. struct device_attribute *attr, char *buf)
  809. {
  810. struct net_device *ndev = dev_get_drvdata(dev);
  811. struct temac_local *lp = netdev_priv(ndev);
  812. int i, len = 0;
  813. for (i = 0; i < 0x11; i++)
  814. len += sprintf(buf + len, "%.8x%s", lp->dma_in(lp, i),
  815. (i % 8) == 7 ? "\n" : " ");
  816. len += sprintf(buf + len, "\n");
  817. return len;
  818. }
  819. static DEVICE_ATTR(llink_regs, 0440, temac_show_llink_regs, NULL);
  820. static struct attribute *temac_device_attrs[] = {
  821. &dev_attr_llink_regs.attr,
  822. NULL,
  823. };
  824. static const struct attribute_group temac_attr_group = {
  825. .attrs = temac_device_attrs,
  826. };
  827. /* ethtool support */
  828. static int temac_get_settings(struct net_device *ndev, struct ethtool_cmd *cmd)
  829. {
  830. struct temac_local *lp = netdev_priv(ndev);
  831. return phy_ethtool_gset(lp->phy_dev, cmd);
  832. }
  833. static int temac_set_settings(struct net_device *ndev, struct ethtool_cmd *cmd)
  834. {
  835. struct temac_local *lp = netdev_priv(ndev);
  836. return phy_ethtool_sset(lp->phy_dev, cmd);
  837. }
  838. static int temac_nway_reset(struct net_device *ndev)
  839. {
  840. struct temac_local *lp = netdev_priv(ndev);
  841. return phy_start_aneg(lp->phy_dev);
  842. }
  843. static const struct ethtool_ops temac_ethtool_ops = {
  844. .get_settings = temac_get_settings,
  845. .set_settings = temac_set_settings,
  846. .nway_reset = temac_nway_reset,
  847. .get_link = ethtool_op_get_link,
  848. .get_ts_info = ethtool_op_get_ts_info,
  849. };
  850. static int __devinit temac_of_probe(struct platform_device *op)
  851. {
  852. struct device_node *np;
  853. struct temac_local *lp;
  854. struct net_device *ndev;
  855. const void *addr;
  856. __be32 *p;
  857. int size, rc = 0;
  858. /* Init network device structure */
  859. ndev = alloc_etherdev(sizeof(*lp));
  860. if (!ndev)
  861. return -ENOMEM;
  862. ether_setup(ndev);
  863. dev_set_drvdata(&op->dev, ndev);
  864. SET_NETDEV_DEV(ndev, &op->dev);
  865. ndev->flags &= ~IFF_MULTICAST; /* clear multicast */
  866. ndev->features = NETIF_F_SG | NETIF_F_FRAGLIST;
  867. ndev->netdev_ops = &temac_netdev_ops;
  868. ndev->ethtool_ops = &temac_ethtool_ops;
  869. #if 0
  870. ndev->features |= NETIF_F_IP_CSUM; /* Can checksum TCP/UDP over IPv4. */
  871. ndev->features |= NETIF_F_HW_CSUM; /* Can checksum all the packets. */
  872. ndev->features |= NETIF_F_IPV6_CSUM; /* Can checksum IPV6 TCP/UDP */
  873. ndev->features |= NETIF_F_HIGHDMA; /* Can DMA to high memory. */
  874. ndev->features |= NETIF_F_HW_VLAN_TX; /* Transmit VLAN hw accel */
  875. ndev->features |= NETIF_F_HW_VLAN_RX; /* Receive VLAN hw acceleration */
  876. ndev->features |= NETIF_F_HW_VLAN_FILTER; /* Receive VLAN filtering */
  877. ndev->features |= NETIF_F_VLAN_CHALLENGED; /* cannot handle VLAN pkts */
  878. ndev->features |= NETIF_F_GSO; /* Enable software GSO. */
  879. ndev->features |= NETIF_F_MULTI_QUEUE; /* Has multiple TX/RX queues */
  880. ndev->features |= NETIF_F_LRO; /* large receive offload */
  881. #endif
  882. /* setup temac private info structure */
  883. lp = netdev_priv(ndev);
  884. lp->ndev = ndev;
  885. lp->dev = &op->dev;
  886. lp->options = XTE_OPTION_DEFAULTS;
  887. spin_lock_init(&lp->rx_lock);
  888. mutex_init(&lp->indirect_mutex);
  889. /* map device registers */
  890. lp->regs = of_iomap(op->dev.of_node, 0);
  891. if (!lp->regs) {
  892. dev_err(&op->dev, "could not map temac regs.\n");
  893. goto nodev;
  894. }
  895. /* Setup checksum offload, but default to off if not specified */
  896. lp->temac_features = 0;
  897. p = (__be32 *)of_get_property(op->dev.of_node, "xlnx,txcsum", NULL);
  898. if (p && be32_to_cpu(*p)) {
  899. lp->temac_features |= TEMAC_FEATURE_TX_CSUM;
  900. /* Can checksum TCP/UDP over IPv4. */
  901. ndev->features |= NETIF_F_IP_CSUM;
  902. }
  903. p = (__be32 *)of_get_property(op->dev.of_node, "xlnx,rxcsum", NULL);
  904. if (p && be32_to_cpu(*p))
  905. lp->temac_features |= TEMAC_FEATURE_RX_CSUM;
  906. /* Find the DMA node, map the DMA registers, and decode the DMA IRQs */
  907. np = of_parse_phandle(op->dev.of_node, "llink-connected", 0);
  908. if (!np) {
  909. dev_err(&op->dev, "could not find DMA node\n");
  910. goto err_iounmap;
  911. }
  912. /* Setup the DMA register accesses, could be DCR or memory mapped */
  913. if (temac_dcr_setup(lp, op, np)) {
  914. /* no DCR in the device tree, try non-DCR */
  915. lp->sdma_regs = of_iomap(np, 0);
  916. if (lp->sdma_regs) {
  917. lp->dma_in = temac_dma_in32;
  918. lp->dma_out = temac_dma_out32;
  919. dev_dbg(&op->dev, "MEM base: %p\n", lp->sdma_regs);
  920. } else {
  921. dev_err(&op->dev, "unable to map DMA registers\n");
  922. of_node_put(np);
  923. goto err_iounmap;
  924. }
  925. }
  926. lp->rx_irq = irq_of_parse_and_map(np, 0);
  927. lp->tx_irq = irq_of_parse_and_map(np, 1);
  928. of_node_put(np); /* Finished with the DMA node; drop the reference */
  929. if (!lp->rx_irq || !lp->tx_irq) {
  930. dev_err(&op->dev, "could not determine irqs\n");
  931. rc = -ENOMEM;
  932. goto err_iounmap_2;
  933. }
  934. /* Retrieve the MAC address */
  935. addr = of_get_property(op->dev.of_node, "local-mac-address", &size);
  936. if ((!addr) || (size != 6)) {
  937. dev_err(&op->dev, "could not find MAC address\n");
  938. rc = -ENODEV;
  939. goto err_iounmap_2;
  940. }
  941. temac_set_mac_address(ndev, (void *)addr);
  942. rc = temac_mdio_setup(lp, op->dev.of_node);
  943. if (rc)
  944. dev_warn(&op->dev, "error registering MDIO bus\n");
  945. lp->phy_node = of_parse_phandle(op->dev.of_node, "phy-handle", 0);
  946. if (lp->phy_node)
  947. dev_dbg(lp->dev, "using PHY node %s (%p)\n", np->full_name, np);
  948. /* Add the device attributes */
  949. rc = sysfs_create_group(&lp->dev->kobj, &temac_attr_group);
  950. if (rc) {
  951. dev_err(lp->dev, "Error creating sysfs files\n");
  952. goto err_iounmap_2;
  953. }
  954. rc = register_netdev(lp->ndev);
  955. if (rc) {
  956. dev_err(lp->dev, "register_netdev() error (%i)\n", rc);
  957. goto err_register_ndev;
  958. }
  959. return 0;
  960. err_register_ndev:
  961. sysfs_remove_group(&lp->dev->kobj, &temac_attr_group);
  962. err_iounmap_2:
  963. if (lp->sdma_regs)
  964. iounmap(lp->sdma_regs);
  965. err_iounmap:
  966. iounmap(lp->regs);
  967. nodev:
  968. free_netdev(ndev);
  969. ndev = NULL;
  970. return rc;
  971. }
  972. static int __devexit temac_of_remove(struct platform_device *op)
  973. {
  974. struct net_device *ndev = dev_get_drvdata(&op->dev);
  975. struct temac_local *lp = netdev_priv(ndev);
  976. temac_mdio_teardown(lp);
  977. unregister_netdev(ndev);
  978. sysfs_remove_group(&lp->dev->kobj, &temac_attr_group);
  979. if (lp->phy_node)
  980. of_node_put(lp->phy_node);
  981. lp->phy_node = NULL;
  982. dev_set_drvdata(&op->dev, NULL);
  983. iounmap(lp->regs);
  984. if (lp->sdma_regs)
  985. iounmap(lp->sdma_regs);
  986. free_netdev(ndev);
  987. return 0;
  988. }
  989. static struct of_device_id temac_of_match[] __devinitdata = {
  990. { .compatible = "xlnx,xps-ll-temac-1.01.b", },
  991. { .compatible = "xlnx,xps-ll-temac-2.00.a", },
  992. { .compatible = "xlnx,xps-ll-temac-2.02.a", },
  993. { .compatible = "xlnx,xps-ll-temac-2.03.a", },
  994. {},
  995. };
  996. MODULE_DEVICE_TABLE(of, temac_of_match);
  997. static struct platform_driver temac_of_driver = {
  998. .probe = temac_of_probe,
  999. .remove = __devexit_p(temac_of_remove),
  1000. .driver = {
  1001. .owner = THIS_MODULE,
  1002. .name = "xilinx_temac",
  1003. .of_match_table = temac_of_match,
  1004. },
  1005. };
  1006. module_platform_driver(temac_of_driver);
  1007. MODULE_DESCRIPTION("Xilinx LL_TEMAC Ethernet driver");
  1008. MODULE_AUTHOR("Yoshio Kashiwagi");
  1009. MODULE_LICENSE("GPL");