005-tulip_platform.patch 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. --- a/drivers/net/ethernet/dec/tulip/Kconfig
  2. +++ b/drivers/net/ethernet/dec/tulip/Kconfig
  3. @@ -60,6 +60,14 @@ config TULIP_PCI
  4. To compile this driver as a module, choose M here. The module will
  5. be called tulip.
  6. +config TULIP_PLATFORM
  7. + tristate "DECchip Tulip (dc2114x) Platform support"
  8. + depends on HAS_IOMEM
  9. + select TULIP
  10. + select CRC32
  11. + ---help---
  12. + This driver is for the platform variant.
  13. +
  14. config TULIP_MWI
  15. bool "New bus configuration (EXPERIMENTAL)"
  16. depends on TULIP_PCI && EXPERIMENTAL
  17. --- a/drivers/net/ethernet/dec/tulip/tulip_core.c
  18. +++ b/drivers/net/ethernet/dec/tulip/tulip_core.c
  19. @@ -27,6 +27,8 @@
  20. #include <linux/init.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/etherdevice.h>
  23. +#include <linux/platform_device.h>
  24. +#include <linux/platform_data/tulip.h>
  25. #include <linux/delay.h>
  26. #include <linux/mii.h>
  27. #include <linux/crc32.h>
  28. @@ -204,6 +206,9 @@ struct tulip_chip_table tulip_tbl[] = {
  29. { "Conexant LANfinity", 256, 0x0001ebef,
  30. HAS_MII | HAS_ACPI, tulip_timer, tulip_media_task },
  31. + { "Infineon ADM8668", 256, 0x0001a451,
  32. + MC_HASH_ONLY | COMET_MAC_ADDR, tulip_timer, tulip_media_task, },
  33. +
  34. };
  35. #ifdef CONFIG_TULIP_PCI
  36. @@ -395,6 +400,7 @@ static void tulip_up(struct net_device *
  37. i = 0;
  38. if (tp->mtable == NULL)
  39. goto media_picked;
  40. +
  41. if (dev->if_port) {
  42. int looking_for = tulip_media_cap[dev->if_port] & MediaIsMII ? 11 :
  43. (dev->if_port == 12 ? 0 : dev->if_port);
  44. @@ -488,6 +494,10 @@ media_picked:
  45. iowrite32(ioread32(ioaddr + 0x88) | 1, ioaddr + 0x88);
  46. dev->if_port = tp->mii_cnt ? 11 : 0;
  47. tp->csr6 = 0x00040000;
  48. + } else if (tp->chip_id == ADM8668) {
  49. + /* Enable automatic Tx underrun recovery. */
  50. + iowrite32(ioread32(ioaddr + 0x88) | 1, ioaddr + 0x88);
  51. + tp->csr6 = 0x00040000;
  52. } else if (tp->chip_id == AX88140) {
  53. tp->csr6 = tp->mii_cnt ? 0x00040100 : 0x00000100;
  54. } else
  55. @@ -657,6 +667,10 @@ static void tulip_init_ring(struct net_d
  56. mapping = pci_map_single(tp->pdev, skb->data,
  57. PKT_BUF_SZ, PCI_DMA_FROMDEVICE);
  58. #endif
  59. +#ifdef CONFIG_TULIP_PLATFORM
  60. + mapping = dma_map_single(&tp->pldev->dev, skb->data,
  61. + PKT_BUF_SZ, DMA_FROM_DEVICE);
  62. +#endif
  63. tp->rx_buffers[i].mapping = mapping;
  64. skb->dev = dev; /* Mark as being used by this device. */
  65. tp->rx_ring[i].status = cpu_to_le32(DescOwned); /* Owned by Tulip chip */
  66. @@ -694,6 +708,11 @@ tulip_start_xmit(struct sk_buff *skb, st
  67. mapping = pci_map_single(tp->pdev, skb->data,
  68. skb->len, PCI_DMA_TODEVICE);
  69. #endif
  70. +#ifdef CONFIG_TULIP_PLATFORM
  71. + mapping = dma_map_single(&tp->pldev->dev, skb->data,
  72. + skb->len,
  73. + DMA_TO_DEVICE);
  74. +#endif
  75. tp->tx_buffers[entry].mapping = mapping;
  76. tp->tx_ring[entry].buffer1 = cpu_to_le32(mapping);
  77. @@ -757,6 +776,11 @@ static void tulip_clean_tx_ring(struct t
  78. tp->tx_buffers[entry].skb->len,
  79. PCI_DMA_TODEVICE);
  80. #endif
  81. +#ifdef CONFIG_TULIP_PLATFORM
  82. + dma_unmap_single(&tp->pldev->dev, tp->tx_buffers[entry].mapping,
  83. + tp->tx_buffers[entry].skb->len,
  84. + DMA_TO_DEVICE);
  85. +#endif
  86. /* Free the original skb. */
  87. dev_kfree_skb_irq(tp->tx_buffers[entry].skb);
  88. @@ -834,6 +858,10 @@ static void tulip_free_ring (struct net_
  89. pci_unmap_single(tp->pdev, mapping, PKT_BUF_SZ,
  90. PCI_DMA_FROMDEVICE);
  91. #endif
  92. +#ifdef CONFIG_TULIP_PLATFORM
  93. + dma_unmap_single(&tp->pldev->dev, mapping, PKT_BUF_SZ,
  94. + DMA_FROM_DEVICE);
  95. +#endif
  96. dev_kfree_skb (skb);
  97. }
  98. }
  99. @@ -846,6 +874,10 @@ static void tulip_free_ring (struct net_
  100. pci_unmap_single(tp->pdev, tp->tx_buffers[i].mapping,
  101. skb->len, PCI_DMA_TODEVICE);
  102. #endif
  103. +#ifdef CONFIG_TULIP_PLATFORM
  104. + dma_unmap_single(&tp->pldev->dev, tp->tx_buffers[i].mapping,
  105. + skb->len, DMA_TO_DEVICE);
  106. +#endif
  107. dev_kfree_skb (skb);
  108. }
  109. tp->tx_buffers[i].skb = NULL;
  110. @@ -900,6 +932,9 @@ static void tulip_get_drvinfo(struct net
  111. #ifdef CONFIG_TULIP_PCI
  112. strlcpy(info->bus_info, pci_name(np->pdev), sizeof(info->bus_info));
  113. #endif
  114. +#ifdef CONFIG_TULIP_PLATFORM
  115. + strlcpy(info->bus_info, "platform", sizeof(info->bus_info));
  116. +#endif
  117. }
  118. @@ -915,6 +950,9 @@ static int tulip_ethtool_set_wol(struct
  119. #ifdef CONFIG_TULIP_PCI
  120. device_set_wakeup_enable(&tp->pdev->dev, tp->wolinfo.wolopts);
  121. #endif
  122. +#ifdef CONFIG_TULIP_PLATFORM
  123. + device_set_wakeup_enable(&tp->pldev->dev, tp->wolinfo.wolopts);
  124. +#endif
  125. return 0;
  126. }
  127. @@ -1193,9 +1231,9 @@ static void set_rx_mode(struct net_devic
  128. }
  129. +#ifdef CONFIG_TULIP_PCI
  130. tp->tx_buffers[entry].skb = NULL;
  131. tp->tx_buffers[entry].mapping =
  132. -#ifdef CONFIG_TULIP_PCI
  133. pci_map_single(tp->pdev, tp->setup_frame,
  134. sizeof(tp->setup_frame),
  135. PCI_DMA_TODEVICE);
  136. @@ -1219,6 +1257,9 @@ static void set_rx_mode(struct net_devic
  137. spin_unlock_irqrestore(&tp->lock, flags);
  138. }
  139. + if (tp->chip_id == ADM8668)
  140. + csr6 |= (1 << 9); /* force 100Mbps full duplex */
  141. +
  142. iowrite32(csr6, ioaddr + CSR6);
  143. }
  144. @@ -1991,6 +2032,124 @@ static void __devexit tulip_remove_one (
  145. }
  146. #endif /* CONFIG_TULIP_PCI */
  147. +#ifdef CONFIG_TULIP_PLATFORM
  148. +static int __devinit tulip_probe(struct platform_device *pdev)
  149. +{
  150. + struct tulip_private *tp;
  151. + struct tulip_platform_data *pdata;
  152. + struct net_device *dev;
  153. + struct resource *res;
  154. + void __iomem *ioaddr;
  155. + int irq;
  156. +
  157. + if (pdev->id < 0 || pdev->id >= MAX_UNITS)
  158. + return -EINVAL;
  159. +
  160. + if (!(res = platform_get_resource(pdev, IORESOURCE_IRQ, 0)))
  161. + return -ENODEV;
  162. + irq = res->start;
  163. + if (!(res = platform_get_resource(pdev, IORESOURCE_MEM, 0)))
  164. + return -ENODEV;
  165. + if (!(ioaddr = ioremap(res->start, res->end - res->start)))
  166. + return -ENODEV;
  167. +
  168. + pdata = pdev->dev.platform_data;
  169. + if (!pdata)
  170. + return -ENODEV;
  171. +
  172. + if (!(dev = alloc_etherdev(sizeof (*tp))))
  173. + return -ENOMEM;
  174. +
  175. + /* setup net dev */
  176. + dev->base_addr = (unsigned long)res->start;
  177. + dev->irq = irq;
  178. + SET_NETDEV_DEV(dev, &pdev->dev);
  179. +
  180. + /* tulip private struct */
  181. + tp = netdev_priv(dev);
  182. + tp->dev = dev;
  183. + tp->base_addr = ioaddr;
  184. + tp->csr0 = 0;
  185. + tp->pldev = pdev;
  186. + tp->rx_ring = dma_alloc_coherent(&pdev->dev,
  187. + sizeof(struct tulip_rx_desc) * RX_RING_SIZE +
  188. + sizeof(struct tulip_tx_desc) * TX_RING_SIZE,
  189. + &tp->rx_ring_dma, GFP_KERNEL);
  190. + if (!tp->rx_ring)
  191. + return -ENODEV;
  192. + tp->tx_ring = (struct tulip_tx_desc *)(tp->rx_ring + RX_RING_SIZE);
  193. + tp->tx_ring_dma = tp->rx_ring_dma + sizeof(struct tulip_rx_desc) * RX_RING_SIZE;
  194. +
  195. + tp->chip_id = pdata->chip_id;
  196. + tp->flags = tulip_tbl[tp->chip_id].flags;
  197. +
  198. + spin_lock_init(&tp->lock);
  199. + spin_lock_init(&tp->mii_lock);
  200. +
  201. + init_timer(&tp->timer);
  202. + tp->timer.data = (unsigned long)dev;
  203. + tp->timer.function = tulip_tbl[tp->chip_id].media_timer;
  204. +
  205. + INIT_WORK(&tp->media_work, tulip_tbl[tp->chip_id].media_task);
  206. +
  207. + /* Stop the chip's Tx and Rx processes. */
  208. + tulip_stop_rxtx(tp);
  209. +
  210. + /* Clear the missed-packet counter. */
  211. + ioread32(ioaddr + CSR8);
  212. +
  213. + if (!is_valid_ether_addr(pdata->mac)) {
  214. + dev_info(&pdev->dev, "generating random ethernet MAC\n");
  215. + random_ether_addr(dev->dev_addr);
  216. + } else
  217. + memcpy(dev->dev_addr, pdata->mac, ETH_ALEN);
  218. +
  219. + /* The Tulip-specific entries in the device structure. */
  220. + dev->netdev_ops = &tulip_netdev_ops;
  221. + dev->watchdog_timeo = TX_TIMEOUT;
  222. + netif_napi_add(dev, &tp->napi, tulip_poll, 16);
  223. + SET_ETHTOOL_OPS(dev, &ops);
  224. +
  225. + if (register_netdev(dev))
  226. + goto err_out_free_ring;
  227. +
  228. + dev_info(&dev->dev,
  229. + "tulip_platform (%s) at MMIO %#lx %pM, IRQ %d\n",
  230. + tulip_tbl[tp->chip_id].chip_name,
  231. + (unsigned long)dev->base_addr, dev->dev_addr, irq);
  232. +
  233. + platform_set_drvdata(pdev, dev);
  234. + return 0;
  235. +
  236. +err_out_free_ring:
  237. + dma_free_coherent(&pdev->dev,
  238. + sizeof (struct tulip_rx_desc) * RX_RING_SIZE +
  239. + sizeof (struct tulip_tx_desc) * TX_RING_SIZE,
  240. + tp->rx_ring, tp->rx_ring_dma);
  241. + return -ENODEV;
  242. +}
  243. +
  244. +static int __devexit tulip_remove(struct platform_device *pdev)
  245. +{
  246. + struct net_device *dev = platform_get_drvdata (pdev);
  247. + struct tulip_private *tp;
  248. +
  249. + if (!dev)
  250. + return -ENODEV;
  251. +
  252. + tp = netdev_priv(dev);
  253. + unregister_netdev(dev);
  254. + dma_free_coherent(&pdev->dev,
  255. + sizeof (struct tulip_rx_desc) * RX_RING_SIZE +
  256. + sizeof (struct tulip_tx_desc) * TX_RING_SIZE,
  257. + tp->rx_ring, tp->rx_ring_dma);
  258. + iounmap(tp->base_addr);
  259. + free_netdev(dev);
  260. + platform_set_drvdata(pdev, NULL);
  261. + return 0;
  262. +}
  263. +#endif
  264. +
  265. #ifdef CONFIG_NET_POLL_CONTROLLER
  266. /*
  267. * Polling 'interrupt' - used by things like netconsole to send skbs
  268. @@ -2021,6 +2180,17 @@ static struct pci_driver tulip_pci_drive
  269. };
  270. #endif
  271. +#ifdef CONFIG_TULIP_PLATFORM
  272. +static struct platform_driver tulip_platform_driver = {
  273. + .probe = tulip_probe,
  274. + .remove = __devexit_p(tulip_remove),
  275. + .driver = {
  276. + .owner = THIS_MODULE,
  277. + .name = DRV_NAME,
  278. + },
  279. +};
  280. +#endif
  281. +
  282. static int __init tulip_init (void)
  283. {
  284. @@ -2037,6 +2207,9 @@ static int __init tulip_init (void)
  285. #ifdef CONFIG_TULIP_PCI
  286. ret = pci_register_driver(&tulip_pci_driver);
  287. #endif
  288. +#ifdef CONFIG_TULIP_PLATFORM
  289. + ret = platform_driver_register(&tulip_platform_driver);
  290. +#endif
  291. return ret;
  292. }
  293. @@ -2046,6 +2219,9 @@ static void __exit tulip_cleanup (void)
  294. #ifdef CONFIG_TULIP_PCI
  295. pci_unregister_driver (&tulip_pci_driver);
  296. #endif
  297. +#ifdef CONFIG_TULIP_PLATFORM
  298. + platform_driver_unregister (&tulip_platform_driver);
  299. +#endif
  300. }
  301. --- a/drivers/net/ethernet/dec/tulip/tulip.h
  302. +++ b/drivers/net/ethernet/dec/tulip/tulip.h
  303. @@ -21,6 +21,8 @@
  304. #include <linux/timer.h>
  305. #include <linux/delay.h>
  306. #include <linux/pci.h>
  307. +#include <linux/platform_device.h>
  308. +#include <linux/platform_data/tulip.h>
  309. #include <asm/io.h>
  310. #include <asm/irq.h>
  311. #include <asm/unaligned.h>
  312. @@ -69,28 +71,6 @@ enum tbl_flag {
  313. };
  314. -/* chip types. careful! order is VERY IMPORTANT here, as these
  315. - * are used throughout the driver as indices into arrays */
  316. -/* Note 21142 == 21143. */
  317. -enum chips {
  318. - DC21040 = 0,
  319. - DC21041 = 1,
  320. - DC21140 = 2,
  321. - DC21142 = 3, DC21143 = 3,
  322. - LC82C168,
  323. - MX98713,
  324. - MX98715,
  325. - MX98725,
  326. - AX88140,
  327. - PNIC2,
  328. - COMET,
  329. - COMPEX9881,
  330. - I21145,
  331. - DM910X,
  332. - CONEXANT,
  333. -};
  334. -
  335. -
  336. enum MediaIs {
  337. MediaIsFD = 1,
  338. MediaAlwaysFD = 2,
  339. @@ -446,7 +426,12 @@ struct tulip_private {
  340. struct mediatable *mtable;
  341. int cur_index; /* Current media index. */
  342. int saved_if_port;
  343. +#ifdef CONFIG_TULIP_PCI
  344. struct pci_dev *pdev;
  345. +#endif
  346. +#ifdef CONFIG_TULIP_PLATFORM
  347. + struct platform_device *pldev;
  348. +#endif
  349. int ttimer;
  350. int susp_rx;
  351. unsigned long nir;
  352. --- a/drivers/net/ethernet/dec/tulip/interrupt.c
  353. +++ b/drivers/net/ethernet/dec/tulip/interrupt.c
  354. @@ -76,6 +76,10 @@ int tulip_refill_rx(struct net_device *d
  355. mapping = pci_map_single(tp->pdev, skb->data, PKT_BUF_SZ,
  356. PCI_DMA_FROMDEVICE);
  357. #endif
  358. +#ifdef CONFIG_TULIP_PLATFORM
  359. + mapping = dma_map_single(&tp->pldev->dev, skb->data, PKT_BUF_SZ,
  360. + DMA_FROM_DEVICE);
  361. +#endif
  362. tp->rx_buffers[entry].mapping = mapping;
  363. skb->dev = dev; /* Mark as being used by this device. */
  364. @@ -198,8 +202,7 @@ int tulip_poll(struct napi_struct *napi,
  365. dev->stats.rx_fifo_errors++;
  366. }
  367. } else {
  368. - struct sk_buff *skb;
  369. -
  370. + struct sk_buff *skb;
  371. /* Check if the packet is long enough to accept without copying
  372. to a minimally-sized skbuff. */
  373. if (pkt_len < tulip_rx_copybreak &&
  374. @@ -242,6 +245,10 @@ int tulip_poll(struct napi_struct *napi,
  375. pci_unmap_single(tp->pdev, tp->rx_buffers[entry].mapping,
  376. PKT_BUF_SZ, PCI_DMA_FROMDEVICE);
  377. #endif
  378. +#ifdef CONFIG_TULIP_PLATFORM
  379. + dma_unmap_single(&tp->pldev->dev, tp->rx_buffers[entry].mapping,
  380. + PKT_BUF_SZ, DMA_FROM_DEVICE);
  381. +#endif
  382. tp->rx_buffers[entry].skb = NULL;
  383. tp->rx_buffers[entry].mapping = 0;
  384. @@ -635,6 +642,11 @@ irqreturn_t tulip_interrupt(int irq, voi
  385. tp->tx_buffers[entry].skb->len,
  386. PCI_DMA_TODEVICE);
  387. #endif
  388. +#ifdef CONFIG_TULIP_PLATFORM
  389. + dma_unmap_single(&tp->pldev->dev, tp->tx_buffers[entry].mapping,
  390. + tp->tx_buffers[entry].skb->len,
  391. + DMA_TO_DEVICE);
  392. +#endif
  393. /* Free the original skb. */
  394. dev_kfree_skb_irq(tp->tx_buffers[entry].skb);
  395. --- /dev/null
  396. +++ b/include/linux/platform_data/tulip.h
  397. @@ -0,0 +1,31 @@
  398. +#ifndef _LINUX_TULIP_PDATA_H
  399. +#define _LINUX_TULIP_PDATA_H
  400. +
  401. +/* chip types. careful! order is VERY IMPORTANT here, as these
  402. + * are used throughout the driver as indices into arrays */
  403. +/* Note 21142 == 21143. */
  404. +enum chips {
  405. + DC21040 = 0,
  406. + DC21041 = 1,
  407. + DC21140 = 2,
  408. + DC21142 = 3, DC21143 = 3,
  409. + LC82C168,
  410. + MX98713,
  411. + MX98715,
  412. + MX98725,
  413. + AX88140,
  414. + PNIC2,
  415. + COMET,
  416. + COMPEX9881,
  417. + I21145,
  418. + DM910X,
  419. + CONEXANT,
  420. + ADM8668,
  421. +};
  422. +
  423. +struct tulip_platform_data {
  424. + u8 mac[6];
  425. + enum chips chip_id;
  426. +};
  427. +
  428. +#endif