005-tulip_platform.patch 14 KB

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