ll_temac_main.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192
  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 void temac_do_set_mac_address(struct net_device *ndev)
  285. {
  286. struct temac_local *lp = netdev_priv(ndev);
  287. /* set up unicast MAC address filter set its mac address */
  288. mutex_lock(&lp->indirect_mutex);
  289. temac_indirect_out32(lp, XTE_UAW0_OFFSET,
  290. (ndev->dev_addr[0]) |
  291. (ndev->dev_addr[1] << 8) |
  292. (ndev->dev_addr[2] << 16) |
  293. (ndev->dev_addr[3] << 24));
  294. /* There are reserved bits in EUAW1
  295. * so don't affect them Set MAC bits [47:32] in EUAW1 */
  296. temac_indirect_out32(lp, XTE_UAW1_OFFSET,
  297. (ndev->dev_addr[4] & 0x000000ff) |
  298. (ndev->dev_addr[5] << 8));
  299. mutex_unlock(&lp->indirect_mutex);
  300. }
  301. static int temac_init_mac_address(struct net_device *ndev, void *address)
  302. {
  303. memcpy(ndev->dev_addr, address, ETH_ALEN);
  304. if (!is_valid_ether_addr(ndev->dev_addr))
  305. eth_hw_addr_random(ndev);
  306. temac_do_set_mac_address(ndev);
  307. return 0;
  308. }
  309. static int temac_set_mac_address(struct net_device *ndev, void *p)
  310. {
  311. struct sockaddr *addr = p;
  312. if (!is_valid_ether_addr(addr->sa_data))
  313. return -EADDRNOTAVAIL;
  314. memcpy(ndev->dev_addr, addr->sa_data, ETH_ALEN);
  315. temac_do_set_mac_address(ndev);
  316. return 0;
  317. }
  318. static void temac_set_multicast_list(struct net_device *ndev)
  319. {
  320. struct temac_local *lp = netdev_priv(ndev);
  321. u32 multi_addr_msw, multi_addr_lsw, val;
  322. int i;
  323. mutex_lock(&lp->indirect_mutex);
  324. if (ndev->flags & (IFF_ALLMULTI | IFF_PROMISC) ||
  325. netdev_mc_count(ndev) > MULTICAST_CAM_TABLE_NUM) {
  326. /*
  327. * We must make the kernel realise we had to move
  328. * into promisc mode or we start all out war on
  329. * the cable. If it was a promisc request the
  330. * flag is already set. If not we assert it.
  331. */
  332. ndev->flags |= IFF_PROMISC;
  333. temac_indirect_out32(lp, XTE_AFM_OFFSET, XTE_AFM_EPPRM_MASK);
  334. dev_info(&ndev->dev, "Promiscuous mode enabled.\n");
  335. } else if (!netdev_mc_empty(ndev)) {
  336. struct netdev_hw_addr *ha;
  337. i = 0;
  338. netdev_for_each_mc_addr(ha, ndev) {
  339. if (i >= MULTICAST_CAM_TABLE_NUM)
  340. break;
  341. multi_addr_msw = ((ha->addr[3] << 24) |
  342. (ha->addr[2] << 16) |
  343. (ha->addr[1] << 8) |
  344. (ha->addr[0]));
  345. temac_indirect_out32(lp, XTE_MAW0_OFFSET,
  346. multi_addr_msw);
  347. multi_addr_lsw = ((ha->addr[5] << 8) |
  348. (ha->addr[4]) | (i << 16));
  349. temac_indirect_out32(lp, XTE_MAW1_OFFSET,
  350. multi_addr_lsw);
  351. i++;
  352. }
  353. } else {
  354. val = temac_indirect_in32(lp, XTE_AFM_OFFSET);
  355. temac_indirect_out32(lp, XTE_AFM_OFFSET,
  356. val & ~XTE_AFM_EPPRM_MASK);
  357. temac_indirect_out32(lp, XTE_MAW0_OFFSET, 0);
  358. temac_indirect_out32(lp, XTE_MAW1_OFFSET, 0);
  359. dev_info(&ndev->dev, "Promiscuous mode disabled.\n");
  360. }
  361. mutex_unlock(&lp->indirect_mutex);
  362. }
  363. struct temac_option {
  364. int flg;
  365. u32 opt;
  366. u32 reg;
  367. u32 m_or;
  368. u32 m_and;
  369. } temac_options[] = {
  370. /* Turn on jumbo packet support for both Rx and Tx */
  371. {
  372. .opt = XTE_OPTION_JUMBO,
  373. .reg = XTE_TXC_OFFSET,
  374. .m_or = XTE_TXC_TXJMBO_MASK,
  375. },
  376. {
  377. .opt = XTE_OPTION_JUMBO,
  378. .reg = XTE_RXC1_OFFSET,
  379. .m_or =XTE_RXC1_RXJMBO_MASK,
  380. },
  381. /* Turn on VLAN packet support for both Rx and Tx */
  382. {
  383. .opt = XTE_OPTION_VLAN,
  384. .reg = XTE_TXC_OFFSET,
  385. .m_or =XTE_TXC_TXVLAN_MASK,
  386. },
  387. {
  388. .opt = XTE_OPTION_VLAN,
  389. .reg = XTE_RXC1_OFFSET,
  390. .m_or =XTE_RXC1_RXVLAN_MASK,
  391. },
  392. /* Turn on FCS stripping on receive packets */
  393. {
  394. .opt = XTE_OPTION_FCS_STRIP,
  395. .reg = XTE_RXC1_OFFSET,
  396. .m_or =XTE_RXC1_RXFCS_MASK,
  397. },
  398. /* Turn on FCS insertion on transmit packets */
  399. {
  400. .opt = XTE_OPTION_FCS_INSERT,
  401. .reg = XTE_TXC_OFFSET,
  402. .m_or =XTE_TXC_TXFCS_MASK,
  403. },
  404. /* Turn on length/type field checking on receive packets */
  405. {
  406. .opt = XTE_OPTION_LENTYPE_ERR,
  407. .reg = XTE_RXC1_OFFSET,
  408. .m_or =XTE_RXC1_RXLT_MASK,
  409. },
  410. /* Turn on flow control */
  411. {
  412. .opt = XTE_OPTION_FLOW_CONTROL,
  413. .reg = XTE_FCC_OFFSET,
  414. .m_or =XTE_FCC_RXFLO_MASK,
  415. },
  416. /* Turn on flow control */
  417. {
  418. .opt = XTE_OPTION_FLOW_CONTROL,
  419. .reg = XTE_FCC_OFFSET,
  420. .m_or =XTE_FCC_TXFLO_MASK,
  421. },
  422. /* Turn on promiscuous frame filtering (all frames are received ) */
  423. {
  424. .opt = XTE_OPTION_PROMISC,
  425. .reg = XTE_AFM_OFFSET,
  426. .m_or =XTE_AFM_EPPRM_MASK,
  427. },
  428. /* Enable transmitter if not already enabled */
  429. {
  430. .opt = XTE_OPTION_TXEN,
  431. .reg = XTE_TXC_OFFSET,
  432. .m_or =XTE_TXC_TXEN_MASK,
  433. },
  434. /* Enable receiver? */
  435. {
  436. .opt = XTE_OPTION_RXEN,
  437. .reg = XTE_RXC1_OFFSET,
  438. .m_or =XTE_RXC1_RXEN_MASK,
  439. },
  440. {}
  441. };
  442. /**
  443. * temac_setoptions
  444. */
  445. static u32 temac_setoptions(struct net_device *ndev, u32 options)
  446. {
  447. struct temac_local *lp = netdev_priv(ndev);
  448. struct temac_option *tp = &temac_options[0];
  449. int reg;
  450. mutex_lock(&lp->indirect_mutex);
  451. while (tp->opt) {
  452. reg = temac_indirect_in32(lp, tp->reg) & ~tp->m_or;
  453. if (options & tp->opt)
  454. reg |= tp->m_or;
  455. temac_indirect_out32(lp, tp->reg, reg);
  456. tp++;
  457. }
  458. lp->options |= options;
  459. mutex_unlock(&lp->indirect_mutex);
  460. return 0;
  461. }
  462. /* Initialize temac */
  463. static void temac_device_reset(struct net_device *ndev)
  464. {
  465. struct temac_local *lp = netdev_priv(ndev);
  466. u32 timeout;
  467. u32 val;
  468. /* Perform a software reset */
  469. /* 0x300 host enable bit ? */
  470. /* reset PHY through control register ?:1 */
  471. dev_dbg(&ndev->dev, "%s()\n", __func__);
  472. mutex_lock(&lp->indirect_mutex);
  473. /* Reset the receiver and wait for it to finish reset */
  474. temac_indirect_out32(lp, XTE_RXC1_OFFSET, XTE_RXC1_RXRST_MASK);
  475. timeout = 1000;
  476. while (temac_indirect_in32(lp, XTE_RXC1_OFFSET) & XTE_RXC1_RXRST_MASK) {
  477. udelay(1);
  478. if (--timeout == 0) {
  479. dev_err(&ndev->dev,
  480. "temac_device_reset RX reset timeout!!\n");
  481. break;
  482. }
  483. }
  484. /* Reset the transmitter and wait for it to finish reset */
  485. temac_indirect_out32(lp, XTE_TXC_OFFSET, XTE_TXC_TXRST_MASK);
  486. timeout = 1000;
  487. while (temac_indirect_in32(lp, XTE_TXC_OFFSET) & XTE_TXC_TXRST_MASK) {
  488. udelay(1);
  489. if (--timeout == 0) {
  490. dev_err(&ndev->dev,
  491. "temac_device_reset TX reset timeout!!\n");
  492. break;
  493. }
  494. }
  495. /* Disable the receiver */
  496. val = temac_indirect_in32(lp, XTE_RXC1_OFFSET);
  497. temac_indirect_out32(lp, XTE_RXC1_OFFSET, val & ~XTE_RXC1_RXEN_MASK);
  498. /* Reset Local Link (DMA) */
  499. lp->dma_out(lp, DMA_CONTROL_REG, DMA_CONTROL_RST);
  500. timeout = 1000;
  501. while (lp->dma_in(lp, DMA_CONTROL_REG) & DMA_CONTROL_RST) {
  502. udelay(1);
  503. if (--timeout == 0) {
  504. dev_err(&ndev->dev,
  505. "temac_device_reset DMA reset timeout!!\n");
  506. break;
  507. }
  508. }
  509. lp->dma_out(lp, DMA_CONTROL_REG, DMA_TAIL_ENABLE);
  510. if (temac_dma_bd_init(ndev)) {
  511. dev_err(&ndev->dev,
  512. "temac_device_reset descriptor allocation failed\n");
  513. }
  514. temac_indirect_out32(lp, XTE_RXC0_OFFSET, 0);
  515. temac_indirect_out32(lp, XTE_RXC1_OFFSET, 0);
  516. temac_indirect_out32(lp, XTE_TXC_OFFSET, 0);
  517. temac_indirect_out32(lp, XTE_FCC_OFFSET, XTE_FCC_RXFLO_MASK);
  518. mutex_unlock(&lp->indirect_mutex);
  519. /* Sync default options with HW
  520. * but leave receiver and transmitter disabled. */
  521. temac_setoptions(ndev,
  522. lp->options & ~(XTE_OPTION_TXEN | XTE_OPTION_RXEN));
  523. temac_do_set_mac_address(ndev);
  524. /* Set address filter table */
  525. temac_set_multicast_list(ndev);
  526. if (temac_setoptions(ndev, lp->options))
  527. dev_err(&ndev->dev, "Error setting TEMAC options\n");
  528. /* Init Driver variable */
  529. ndev->trans_start = jiffies; /* prevent tx timeout */
  530. }
  531. void temac_adjust_link(struct net_device *ndev)
  532. {
  533. struct temac_local *lp = netdev_priv(ndev);
  534. struct phy_device *phy = lp->phy_dev;
  535. u32 mii_speed;
  536. int link_state;
  537. /* hash together the state values to decide if something has changed */
  538. link_state = phy->speed | (phy->duplex << 1) | phy->link;
  539. mutex_lock(&lp->indirect_mutex);
  540. if (lp->last_link != link_state) {
  541. mii_speed = temac_indirect_in32(lp, XTE_EMCFG_OFFSET);
  542. mii_speed &= ~XTE_EMCFG_LINKSPD_MASK;
  543. switch (phy->speed) {
  544. case SPEED_1000: mii_speed |= XTE_EMCFG_LINKSPD_1000; break;
  545. case SPEED_100: mii_speed |= XTE_EMCFG_LINKSPD_100; break;
  546. case SPEED_10: mii_speed |= XTE_EMCFG_LINKSPD_10; break;
  547. }
  548. /* Write new speed setting out to TEMAC */
  549. temac_indirect_out32(lp, XTE_EMCFG_OFFSET, mii_speed);
  550. lp->last_link = link_state;
  551. phy_print_status(phy);
  552. }
  553. mutex_unlock(&lp->indirect_mutex);
  554. }
  555. static void temac_start_xmit_done(struct net_device *ndev)
  556. {
  557. struct temac_local *lp = netdev_priv(ndev);
  558. struct cdmac_bd *cur_p;
  559. unsigned int stat = 0;
  560. cur_p = &lp->tx_bd_v[lp->tx_bd_ci];
  561. stat = cur_p->app0;
  562. while (stat & STS_CTRL_APP0_CMPLT) {
  563. dma_unmap_single(ndev->dev.parent, cur_p->phys, cur_p->len,
  564. DMA_TO_DEVICE);
  565. if (cur_p->app4)
  566. dev_kfree_skb_irq((struct sk_buff *)cur_p->app4);
  567. cur_p->app0 = 0;
  568. cur_p->app1 = 0;
  569. cur_p->app2 = 0;
  570. cur_p->app3 = 0;
  571. cur_p->app4 = 0;
  572. ndev->stats.tx_packets++;
  573. ndev->stats.tx_bytes += cur_p->len;
  574. lp->tx_bd_ci++;
  575. if (lp->tx_bd_ci >= TX_BD_NUM)
  576. lp->tx_bd_ci = 0;
  577. cur_p = &lp->tx_bd_v[lp->tx_bd_ci];
  578. stat = cur_p->app0;
  579. }
  580. netif_wake_queue(ndev);
  581. }
  582. static inline int temac_check_tx_bd_space(struct temac_local *lp, int num_frag)
  583. {
  584. struct cdmac_bd *cur_p;
  585. int tail;
  586. tail = lp->tx_bd_tail;
  587. cur_p = &lp->tx_bd_v[tail];
  588. do {
  589. if (cur_p->app0)
  590. return NETDEV_TX_BUSY;
  591. tail++;
  592. if (tail >= TX_BD_NUM)
  593. tail = 0;
  594. cur_p = &lp->tx_bd_v[tail];
  595. num_frag--;
  596. } while (num_frag >= 0);
  597. return 0;
  598. }
  599. static int temac_start_xmit(struct sk_buff *skb, struct net_device *ndev)
  600. {
  601. struct temac_local *lp = netdev_priv(ndev);
  602. struct cdmac_bd *cur_p;
  603. dma_addr_t start_p, tail_p;
  604. int ii;
  605. unsigned long num_frag;
  606. skb_frag_t *frag;
  607. num_frag = skb_shinfo(skb)->nr_frags;
  608. frag = &skb_shinfo(skb)->frags[0];
  609. start_p = lp->tx_bd_p + sizeof(*lp->tx_bd_v) * lp->tx_bd_tail;
  610. cur_p = &lp->tx_bd_v[lp->tx_bd_tail];
  611. if (temac_check_tx_bd_space(lp, num_frag)) {
  612. if (!netif_queue_stopped(ndev)) {
  613. netif_stop_queue(ndev);
  614. return NETDEV_TX_BUSY;
  615. }
  616. return NETDEV_TX_BUSY;
  617. }
  618. cur_p->app0 = 0;
  619. if (skb->ip_summed == CHECKSUM_PARTIAL) {
  620. unsigned int csum_start_off = skb_checksum_start_offset(skb);
  621. unsigned int csum_index_off = csum_start_off + skb->csum_offset;
  622. cur_p->app0 |= 1; /* TX Checksum Enabled */
  623. cur_p->app1 = (csum_start_off << 16) | csum_index_off;
  624. cur_p->app2 = 0; /* initial checksum seed */
  625. }
  626. cur_p->app0 |= STS_CTRL_APP0_SOP;
  627. cur_p->len = skb_headlen(skb);
  628. cur_p->phys = dma_map_single(ndev->dev.parent, skb->data, skb->len,
  629. DMA_TO_DEVICE);
  630. cur_p->app4 = (unsigned long)skb;
  631. for (ii = 0; ii < num_frag; ii++) {
  632. lp->tx_bd_tail++;
  633. if (lp->tx_bd_tail >= TX_BD_NUM)
  634. lp->tx_bd_tail = 0;
  635. cur_p = &lp->tx_bd_v[lp->tx_bd_tail];
  636. cur_p->phys = dma_map_single(ndev->dev.parent,
  637. skb_frag_address(frag),
  638. skb_frag_size(frag), DMA_TO_DEVICE);
  639. cur_p->len = skb_frag_size(frag);
  640. cur_p->app0 = 0;
  641. frag++;
  642. }
  643. cur_p->app0 |= STS_CTRL_APP0_EOP;
  644. tail_p = lp->tx_bd_p + sizeof(*lp->tx_bd_v) * lp->tx_bd_tail;
  645. lp->tx_bd_tail++;
  646. if (lp->tx_bd_tail >= TX_BD_NUM)
  647. lp->tx_bd_tail = 0;
  648. skb_tx_timestamp(skb);
  649. /* Kick off the transfer */
  650. lp->dma_out(lp, TX_TAILDESC_PTR, tail_p); /* DMA start */
  651. return NETDEV_TX_OK;
  652. }
  653. static void ll_temac_recv(struct net_device *ndev)
  654. {
  655. struct temac_local *lp = netdev_priv(ndev);
  656. struct sk_buff *skb, *new_skb;
  657. unsigned int bdstat;
  658. struct cdmac_bd *cur_p;
  659. dma_addr_t tail_p;
  660. int length;
  661. unsigned long flags;
  662. spin_lock_irqsave(&lp->rx_lock, flags);
  663. tail_p = lp->rx_bd_p + sizeof(*lp->rx_bd_v) * lp->rx_bd_ci;
  664. cur_p = &lp->rx_bd_v[lp->rx_bd_ci];
  665. bdstat = cur_p->app0;
  666. while ((bdstat & STS_CTRL_APP0_CMPLT)) {
  667. skb = lp->rx_skb[lp->rx_bd_ci];
  668. length = cur_p->app4 & 0x3FFF;
  669. dma_unmap_single(ndev->dev.parent, cur_p->phys, length,
  670. DMA_FROM_DEVICE);
  671. skb_put(skb, length);
  672. skb->protocol = eth_type_trans(skb, ndev);
  673. skb_checksum_none_assert(skb);
  674. /* if we're doing rx csum offload, set it up */
  675. if (((lp->temac_features & TEMAC_FEATURE_RX_CSUM) != 0) &&
  676. (skb->protocol == __constant_htons(ETH_P_IP)) &&
  677. (skb->len > 64)) {
  678. skb->csum = cur_p->app3 & 0xFFFF;
  679. skb->ip_summed = CHECKSUM_COMPLETE;
  680. }
  681. if (!skb_defer_rx_timestamp(skb))
  682. netif_rx(skb);
  683. ndev->stats.rx_packets++;
  684. ndev->stats.rx_bytes += length;
  685. new_skb = netdev_alloc_skb_ip_align(ndev,
  686. XTE_MAX_JUMBO_FRAME_SIZE);
  687. if (new_skb == 0) {
  688. dev_err(&ndev->dev, "no memory for new sk_buff\n");
  689. spin_unlock_irqrestore(&lp->rx_lock, flags);
  690. return;
  691. }
  692. cur_p->app0 = STS_CTRL_APP0_IRQONEND;
  693. cur_p->phys = dma_map_single(ndev->dev.parent, new_skb->data,
  694. XTE_MAX_JUMBO_FRAME_SIZE,
  695. DMA_FROM_DEVICE);
  696. cur_p->len = XTE_MAX_JUMBO_FRAME_SIZE;
  697. lp->rx_skb[lp->rx_bd_ci] = new_skb;
  698. lp->rx_bd_ci++;
  699. if (lp->rx_bd_ci >= RX_BD_NUM)
  700. lp->rx_bd_ci = 0;
  701. cur_p = &lp->rx_bd_v[lp->rx_bd_ci];
  702. bdstat = cur_p->app0;
  703. }
  704. lp->dma_out(lp, RX_TAILDESC_PTR, tail_p);
  705. spin_unlock_irqrestore(&lp->rx_lock, flags);
  706. }
  707. static irqreturn_t ll_temac_tx_irq(int irq, void *_ndev)
  708. {
  709. struct net_device *ndev = _ndev;
  710. struct temac_local *lp = netdev_priv(ndev);
  711. unsigned int status;
  712. status = lp->dma_in(lp, TX_IRQ_REG);
  713. lp->dma_out(lp, TX_IRQ_REG, status);
  714. if (status & (IRQ_COAL | IRQ_DLY))
  715. temac_start_xmit_done(lp->ndev);
  716. if (status & 0x080)
  717. dev_err(&ndev->dev, "DMA error 0x%x\n", status);
  718. return IRQ_HANDLED;
  719. }
  720. static irqreturn_t ll_temac_rx_irq(int irq, void *_ndev)
  721. {
  722. struct net_device *ndev = _ndev;
  723. struct temac_local *lp = netdev_priv(ndev);
  724. unsigned int status;
  725. /* Read and clear the status registers */
  726. status = lp->dma_in(lp, RX_IRQ_REG);
  727. lp->dma_out(lp, RX_IRQ_REG, status);
  728. if (status & (IRQ_COAL | IRQ_DLY))
  729. ll_temac_recv(lp->ndev);
  730. return IRQ_HANDLED;
  731. }
  732. static int temac_open(struct net_device *ndev)
  733. {
  734. struct temac_local *lp = netdev_priv(ndev);
  735. int rc;
  736. dev_dbg(&ndev->dev, "temac_open()\n");
  737. if (lp->phy_node) {
  738. lp->phy_dev = of_phy_connect(lp->ndev, lp->phy_node,
  739. temac_adjust_link, 0, 0);
  740. if (!lp->phy_dev) {
  741. dev_err(lp->dev, "of_phy_connect() failed\n");
  742. return -ENODEV;
  743. }
  744. phy_start(lp->phy_dev);
  745. }
  746. temac_device_reset(ndev);
  747. rc = request_irq(lp->tx_irq, ll_temac_tx_irq, 0, ndev->name, ndev);
  748. if (rc)
  749. goto err_tx_irq;
  750. rc = request_irq(lp->rx_irq, ll_temac_rx_irq, 0, ndev->name, ndev);
  751. if (rc)
  752. goto err_rx_irq;
  753. return 0;
  754. err_rx_irq:
  755. free_irq(lp->tx_irq, ndev);
  756. err_tx_irq:
  757. if (lp->phy_dev)
  758. phy_disconnect(lp->phy_dev);
  759. lp->phy_dev = NULL;
  760. dev_err(lp->dev, "request_irq() failed\n");
  761. return rc;
  762. }
  763. static int temac_stop(struct net_device *ndev)
  764. {
  765. struct temac_local *lp = netdev_priv(ndev);
  766. dev_dbg(&ndev->dev, "temac_close()\n");
  767. free_irq(lp->tx_irq, ndev);
  768. free_irq(lp->rx_irq, ndev);
  769. if (lp->phy_dev)
  770. phy_disconnect(lp->phy_dev);
  771. lp->phy_dev = NULL;
  772. temac_dma_bd_release(ndev);
  773. return 0;
  774. }
  775. #ifdef CONFIG_NET_POLL_CONTROLLER
  776. static void
  777. temac_poll_controller(struct net_device *ndev)
  778. {
  779. struct temac_local *lp = netdev_priv(ndev);
  780. disable_irq(lp->tx_irq);
  781. disable_irq(lp->rx_irq);
  782. ll_temac_rx_irq(lp->tx_irq, ndev);
  783. ll_temac_tx_irq(lp->rx_irq, ndev);
  784. enable_irq(lp->tx_irq);
  785. enable_irq(lp->rx_irq);
  786. }
  787. #endif
  788. static int temac_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd)
  789. {
  790. struct temac_local *lp = netdev_priv(ndev);
  791. if (!netif_running(ndev))
  792. return -EINVAL;
  793. if (!lp->phy_dev)
  794. return -EINVAL;
  795. return phy_mii_ioctl(lp->phy_dev, rq, cmd);
  796. }
  797. static const struct net_device_ops temac_netdev_ops = {
  798. .ndo_open = temac_open,
  799. .ndo_stop = temac_stop,
  800. .ndo_start_xmit = temac_start_xmit,
  801. .ndo_set_mac_address = temac_set_mac_address,
  802. .ndo_validate_addr = eth_validate_addr,
  803. .ndo_do_ioctl = temac_ioctl,
  804. #ifdef CONFIG_NET_POLL_CONTROLLER
  805. .ndo_poll_controller = temac_poll_controller,
  806. #endif
  807. };
  808. /* ---------------------------------------------------------------------
  809. * SYSFS device attributes
  810. */
  811. static ssize_t temac_show_llink_regs(struct device *dev,
  812. struct device_attribute *attr, char *buf)
  813. {
  814. struct net_device *ndev = dev_get_drvdata(dev);
  815. struct temac_local *lp = netdev_priv(ndev);
  816. int i, len = 0;
  817. for (i = 0; i < 0x11; i++)
  818. len += sprintf(buf + len, "%.8x%s", lp->dma_in(lp, i),
  819. (i % 8) == 7 ? "\n" : " ");
  820. len += sprintf(buf + len, "\n");
  821. return len;
  822. }
  823. static DEVICE_ATTR(llink_regs, 0440, temac_show_llink_regs, NULL);
  824. static struct attribute *temac_device_attrs[] = {
  825. &dev_attr_llink_regs.attr,
  826. NULL,
  827. };
  828. static const struct attribute_group temac_attr_group = {
  829. .attrs = temac_device_attrs,
  830. };
  831. /* ethtool support */
  832. static int temac_get_settings(struct net_device *ndev, struct ethtool_cmd *cmd)
  833. {
  834. struct temac_local *lp = netdev_priv(ndev);
  835. return phy_ethtool_gset(lp->phy_dev, cmd);
  836. }
  837. static int temac_set_settings(struct net_device *ndev, struct ethtool_cmd *cmd)
  838. {
  839. struct temac_local *lp = netdev_priv(ndev);
  840. return phy_ethtool_sset(lp->phy_dev, cmd);
  841. }
  842. static int temac_nway_reset(struct net_device *ndev)
  843. {
  844. struct temac_local *lp = netdev_priv(ndev);
  845. return phy_start_aneg(lp->phy_dev);
  846. }
  847. static const struct ethtool_ops temac_ethtool_ops = {
  848. .get_settings = temac_get_settings,
  849. .set_settings = temac_set_settings,
  850. .nway_reset = temac_nway_reset,
  851. .get_link = ethtool_op_get_link,
  852. .get_ts_info = ethtool_op_get_ts_info,
  853. };
  854. static int temac_of_probe(struct platform_device *op)
  855. {
  856. struct device_node *np;
  857. struct temac_local *lp;
  858. struct net_device *ndev;
  859. const void *addr;
  860. __be32 *p;
  861. int size, rc = 0;
  862. /* Init network device structure */
  863. ndev = alloc_etherdev(sizeof(*lp));
  864. if (!ndev)
  865. return -ENOMEM;
  866. ether_setup(ndev);
  867. dev_set_drvdata(&op->dev, ndev);
  868. SET_NETDEV_DEV(ndev, &op->dev);
  869. ndev->flags &= ~IFF_MULTICAST; /* clear multicast */
  870. ndev->features = NETIF_F_SG | NETIF_F_FRAGLIST;
  871. ndev->netdev_ops = &temac_netdev_ops;
  872. ndev->ethtool_ops = &temac_ethtool_ops;
  873. #if 0
  874. ndev->features |= NETIF_F_IP_CSUM; /* Can checksum TCP/UDP over IPv4. */
  875. ndev->features |= NETIF_F_HW_CSUM; /* Can checksum all the packets. */
  876. ndev->features |= NETIF_F_IPV6_CSUM; /* Can checksum IPV6 TCP/UDP */
  877. ndev->features |= NETIF_F_HIGHDMA; /* Can DMA to high memory. */
  878. ndev->features |= NETIF_F_HW_VLAN_TX; /* Transmit VLAN hw accel */
  879. ndev->features |= NETIF_F_HW_VLAN_RX; /* Receive VLAN hw acceleration */
  880. ndev->features |= NETIF_F_HW_VLAN_FILTER; /* Receive VLAN filtering */
  881. ndev->features |= NETIF_F_VLAN_CHALLENGED; /* cannot handle VLAN pkts */
  882. ndev->features |= NETIF_F_GSO; /* Enable software GSO. */
  883. ndev->features |= NETIF_F_MULTI_QUEUE; /* Has multiple TX/RX queues */
  884. ndev->features |= NETIF_F_LRO; /* large receive offload */
  885. #endif
  886. /* setup temac private info structure */
  887. lp = netdev_priv(ndev);
  888. lp->ndev = ndev;
  889. lp->dev = &op->dev;
  890. lp->options = XTE_OPTION_DEFAULTS;
  891. spin_lock_init(&lp->rx_lock);
  892. mutex_init(&lp->indirect_mutex);
  893. /* map device registers */
  894. lp->regs = of_iomap(op->dev.of_node, 0);
  895. if (!lp->regs) {
  896. dev_err(&op->dev, "could not map temac regs.\n");
  897. goto nodev;
  898. }
  899. /* Setup checksum offload, but default to off if not specified */
  900. lp->temac_features = 0;
  901. p = (__be32 *)of_get_property(op->dev.of_node, "xlnx,txcsum", NULL);
  902. if (p && be32_to_cpu(*p)) {
  903. lp->temac_features |= TEMAC_FEATURE_TX_CSUM;
  904. /* Can checksum TCP/UDP over IPv4. */
  905. ndev->features |= NETIF_F_IP_CSUM;
  906. }
  907. p = (__be32 *)of_get_property(op->dev.of_node, "xlnx,rxcsum", NULL);
  908. if (p && be32_to_cpu(*p))
  909. lp->temac_features |= TEMAC_FEATURE_RX_CSUM;
  910. /* Find the DMA node, map the DMA registers, and decode the DMA IRQs */
  911. np = of_parse_phandle(op->dev.of_node, "llink-connected", 0);
  912. if (!np) {
  913. dev_err(&op->dev, "could not find DMA node\n");
  914. goto err_iounmap;
  915. }
  916. /* Setup the DMA register accesses, could be DCR or memory mapped */
  917. if (temac_dcr_setup(lp, op, np)) {
  918. /* no DCR in the device tree, try non-DCR */
  919. lp->sdma_regs = of_iomap(np, 0);
  920. if (lp->sdma_regs) {
  921. lp->dma_in = temac_dma_in32;
  922. lp->dma_out = temac_dma_out32;
  923. dev_dbg(&op->dev, "MEM base: %p\n", lp->sdma_regs);
  924. } else {
  925. dev_err(&op->dev, "unable to map DMA registers\n");
  926. of_node_put(np);
  927. goto err_iounmap;
  928. }
  929. }
  930. lp->rx_irq = irq_of_parse_and_map(np, 0);
  931. lp->tx_irq = irq_of_parse_and_map(np, 1);
  932. of_node_put(np); /* Finished with the DMA node; drop the reference */
  933. if (!lp->rx_irq || !lp->tx_irq) {
  934. dev_err(&op->dev, "could not determine irqs\n");
  935. rc = -ENOMEM;
  936. goto err_iounmap_2;
  937. }
  938. /* Retrieve the MAC address */
  939. addr = of_get_property(op->dev.of_node, "local-mac-address", &size);
  940. if ((!addr) || (size != 6)) {
  941. dev_err(&op->dev, "could not find MAC address\n");
  942. rc = -ENODEV;
  943. goto err_iounmap_2;
  944. }
  945. temac_init_mac_address(ndev, (void *)addr);
  946. rc = temac_mdio_setup(lp, op->dev.of_node);
  947. if (rc)
  948. dev_warn(&op->dev, "error registering MDIO bus\n");
  949. lp->phy_node = of_parse_phandle(op->dev.of_node, "phy-handle", 0);
  950. if (lp->phy_node)
  951. dev_dbg(lp->dev, "using PHY node %s (%p)\n", np->full_name, np);
  952. /* Add the device attributes */
  953. rc = sysfs_create_group(&lp->dev->kobj, &temac_attr_group);
  954. if (rc) {
  955. dev_err(lp->dev, "Error creating sysfs files\n");
  956. goto err_iounmap_2;
  957. }
  958. rc = register_netdev(lp->ndev);
  959. if (rc) {
  960. dev_err(lp->dev, "register_netdev() error (%i)\n", rc);
  961. goto err_register_ndev;
  962. }
  963. return 0;
  964. err_register_ndev:
  965. sysfs_remove_group(&lp->dev->kobj, &temac_attr_group);
  966. err_iounmap_2:
  967. if (lp->sdma_regs)
  968. iounmap(lp->sdma_regs);
  969. err_iounmap:
  970. iounmap(lp->regs);
  971. nodev:
  972. free_netdev(ndev);
  973. ndev = NULL;
  974. return rc;
  975. }
  976. static int temac_of_remove(struct platform_device *op)
  977. {
  978. struct net_device *ndev = dev_get_drvdata(&op->dev);
  979. struct temac_local *lp = netdev_priv(ndev);
  980. temac_mdio_teardown(lp);
  981. unregister_netdev(ndev);
  982. sysfs_remove_group(&lp->dev->kobj, &temac_attr_group);
  983. if (lp->phy_node)
  984. of_node_put(lp->phy_node);
  985. lp->phy_node = NULL;
  986. dev_set_drvdata(&op->dev, NULL);
  987. iounmap(lp->regs);
  988. if (lp->sdma_regs)
  989. iounmap(lp->sdma_regs);
  990. free_netdev(ndev);
  991. return 0;
  992. }
  993. static struct of_device_id temac_of_match[] = {
  994. { .compatible = "xlnx,xps-ll-temac-1.01.b", },
  995. { .compatible = "xlnx,xps-ll-temac-2.00.a", },
  996. { .compatible = "xlnx,xps-ll-temac-2.02.a", },
  997. { .compatible = "xlnx,xps-ll-temac-2.03.a", },
  998. {},
  999. };
  1000. MODULE_DEVICE_TABLE(of, temac_of_match);
  1001. static struct platform_driver temac_of_driver = {
  1002. .probe = temac_of_probe,
  1003. .remove = temac_of_remove,
  1004. .driver = {
  1005. .owner = THIS_MODULE,
  1006. .name = "xilinx_temac",
  1007. .of_match_table = temac_of_match,
  1008. },
  1009. };
  1010. module_platform_driver(temac_of_driver);
  1011. MODULE_DESCRIPTION("Xilinx LL_TEMAC Ethernet driver");
  1012. MODULE_AUTHOR("Yoshio Kashiwagi");
  1013. MODULE_LICENSE("GPL");