pegasos_eth.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /*
  2. * Copyright (C) 2005 Sven Luther <sl@bplan-gmbh.de>
  3. * Thanks to :
  4. * Dale Farnsworth <dale@farnsworth.org>
  5. * Mark A. Greer <mgreer@mvista.com>
  6. * Nicolas DET <nd@bplan-gmbh.de>
  7. * Benjamin Herrenschmidt <benh@kernel.crashing.org>
  8. * And anyone else who helped me on this.
  9. */
  10. #include <linux/types.h>
  11. #include <linux/init.h>
  12. #include <linux/ioport.h>
  13. #include <linux/device.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/mv643xx.h>
  16. #include <linux/pci.h>
  17. #define PEGASOS2_MARVELL_REGBASE (0xf1000000)
  18. #define PEGASOS2_MARVELL_REGSIZE (0x00004000)
  19. #define PEGASOS2_SRAM_BASE (0xf2000000)
  20. #define PEGASOS2_SRAM_SIZE (256*1024)
  21. #define PEGASOS2_SRAM_BASE_ETH0 (PEGASOS2_SRAM_BASE)
  22. #define PEGASOS2_SRAM_BASE_ETH1 (PEGASOS2_SRAM_BASE_ETH0 + (PEGASOS2_SRAM_SIZE / 2) )
  23. #define PEGASOS2_SRAM_RXRING_SIZE (PEGASOS2_SRAM_SIZE/4)
  24. #define PEGASOS2_SRAM_TXRING_SIZE (PEGASOS2_SRAM_SIZE/4)
  25. #undef BE_VERBOSE
  26. static struct resource mv643xx_eth_shared_resources[] = {
  27. [0] = {
  28. .name = "ethernet shared base",
  29. .start = 0xf1000000 + MV643XX_ETH_SHARED_REGS,
  30. .end = 0xf1000000 + MV643XX_ETH_SHARED_REGS +
  31. MV643XX_ETH_SHARED_REGS_SIZE - 1,
  32. .flags = IORESOURCE_MEM,
  33. },
  34. };
  35. static struct platform_device mv643xx_eth_shared_device = {
  36. .name = MV643XX_ETH_SHARED_NAME,
  37. .id = 0,
  38. .num_resources = ARRAY_SIZE(mv643xx_eth_shared_resources),
  39. .resource = mv643xx_eth_shared_resources,
  40. };
  41. static struct resource mv643xx_eth0_resources[] = {
  42. [0] = {
  43. .name = "eth0 irq",
  44. .start = 9,
  45. .end = 9,
  46. .flags = IORESOURCE_IRQ,
  47. },
  48. };
  49. static struct mv643xx_eth_platform_data eth0_pd = {
  50. .shared = &mv643xx_eth_shared_device,
  51. .port_number = 0,
  52. .tx_sram_addr = PEGASOS2_SRAM_BASE_ETH0,
  53. .tx_sram_size = PEGASOS2_SRAM_TXRING_SIZE,
  54. .tx_queue_size = PEGASOS2_SRAM_TXRING_SIZE/16,
  55. .rx_sram_addr = PEGASOS2_SRAM_BASE_ETH0 + PEGASOS2_SRAM_TXRING_SIZE,
  56. .rx_sram_size = PEGASOS2_SRAM_RXRING_SIZE,
  57. .rx_queue_size = PEGASOS2_SRAM_RXRING_SIZE/16,
  58. };
  59. static struct platform_device eth0_device = {
  60. .name = MV643XX_ETH_NAME,
  61. .id = 0,
  62. .num_resources = ARRAY_SIZE(mv643xx_eth0_resources),
  63. .resource = mv643xx_eth0_resources,
  64. .dev = {
  65. .platform_data = &eth0_pd,
  66. },
  67. };
  68. static struct resource mv643xx_eth1_resources[] = {
  69. [0] = {
  70. .name = "eth1 irq",
  71. .start = 9,
  72. .end = 9,
  73. .flags = IORESOURCE_IRQ,
  74. },
  75. };
  76. static struct mv643xx_eth_platform_data eth1_pd = {
  77. .shared = &mv643xx_eth_shared_device,
  78. .port_number = 1,
  79. .tx_sram_addr = PEGASOS2_SRAM_BASE_ETH1,
  80. .tx_sram_size = PEGASOS2_SRAM_TXRING_SIZE,
  81. .tx_queue_size = PEGASOS2_SRAM_TXRING_SIZE/16,
  82. .rx_sram_addr = PEGASOS2_SRAM_BASE_ETH1 + PEGASOS2_SRAM_TXRING_SIZE,
  83. .rx_sram_size = PEGASOS2_SRAM_RXRING_SIZE,
  84. .rx_queue_size = PEGASOS2_SRAM_RXRING_SIZE/16,
  85. };
  86. static struct platform_device eth1_device = {
  87. .name = MV643XX_ETH_NAME,
  88. .id = 1,
  89. .num_resources = ARRAY_SIZE(mv643xx_eth1_resources),
  90. .resource = mv643xx_eth1_resources,
  91. .dev = {
  92. .platform_data = &eth1_pd,
  93. },
  94. };
  95. static struct platform_device *mv643xx_eth_pd_devs[] __initdata = {
  96. &mv643xx_eth_shared_device,
  97. &eth0_device,
  98. &eth1_device,
  99. };
  100. /***********/
  101. /***********/
  102. #define MV_READ(offset,val) { val = readl(mv643xx_reg_base + offset); }
  103. #define MV_WRITE(offset,data) writel(data, mv643xx_reg_base + offset)
  104. static void __iomem *mv643xx_reg_base;
  105. static int Enable_SRAM(void)
  106. {
  107. u32 ALong;
  108. if (mv643xx_reg_base == NULL)
  109. mv643xx_reg_base = ioremap(PEGASOS2_MARVELL_REGBASE,
  110. PEGASOS2_MARVELL_REGSIZE);
  111. if (mv643xx_reg_base == NULL)
  112. return -ENOMEM;
  113. #ifdef BE_VERBOSE
  114. printk("Pegasos II/Marvell MV64361: register remapped from %p to %p\n",
  115. (void *)PEGASOS2_MARVELL_REGBASE, (void *)mv643xx_reg_base);
  116. #endif
  117. MV_WRITE(MV64340_SRAM_CONFIG, 0);
  118. MV_WRITE(MV64340_INTEGRATED_SRAM_BASE_ADDR, PEGASOS2_SRAM_BASE >> 16);
  119. MV_READ(MV64340_BASE_ADDR_ENABLE, ALong);
  120. ALong &= ~(1 << 19);
  121. MV_WRITE(MV64340_BASE_ADDR_ENABLE, ALong);
  122. ALong = 0x02;
  123. ALong |= PEGASOS2_SRAM_BASE & 0xffff0000;
  124. MV_WRITE(MV643XX_ETH_BAR_4, ALong);
  125. MV_WRITE(MV643XX_ETH_SIZE_REG_4, (PEGASOS2_SRAM_SIZE-1) & 0xffff0000);
  126. MV_READ(MV643XX_ETH_BASE_ADDR_ENABLE_REG, ALong);
  127. ALong &= ~(1 << 4);
  128. MV_WRITE(MV643XX_ETH_BASE_ADDR_ENABLE_REG, ALong);
  129. #ifdef BE_VERBOSE
  130. printk("Pegasos II/Marvell MV64361: register unmapped\n");
  131. printk("Pegasos II/Marvell MV64361: SRAM at %p, size=%x\n", (void*) PEGASOS2_SRAM_BASE, PEGASOS2_SRAM_SIZE);
  132. #endif
  133. iounmap(mv643xx_reg_base);
  134. mv643xx_reg_base = NULL;
  135. return 1;
  136. }
  137. /***********/
  138. /***********/
  139. static int __init mv643xx_eth_add_pds(void)
  140. {
  141. int ret = 0;
  142. static struct pci_device_id pci_marvell_mv64360[] = {
  143. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, PCI_DEVICE_ID_MARVELL_MV64360) },
  144. { }
  145. };
  146. #ifdef BE_VERBOSE
  147. printk("Pegasos II/Marvell MV64361: init\n");
  148. #endif
  149. if (pci_dev_present(pci_marvell_mv64360)) {
  150. ret = platform_add_devices(mv643xx_eth_pd_devs,
  151. ARRAY_SIZE(mv643xx_eth_pd_devs));
  152. if ( Enable_SRAM() < 0)
  153. {
  154. eth0_pd.tx_sram_addr = 0;
  155. eth0_pd.tx_sram_size = 0;
  156. eth0_pd.rx_sram_addr = 0;
  157. eth0_pd.rx_sram_size = 0;
  158. eth1_pd.tx_sram_addr = 0;
  159. eth1_pd.tx_sram_size = 0;
  160. eth1_pd.rx_sram_addr = 0;
  161. eth1_pd.rx_sram_size = 0;
  162. #ifdef BE_VERBOSE
  163. printk("Pegasos II/Marvell MV64361: Can't enable the "
  164. "SRAM\n");
  165. #endif
  166. }
  167. }
  168. #ifdef BE_VERBOSE
  169. printk("Pegasos II/Marvell MV64361: init is over\n");
  170. #endif
  171. return ret;
  172. }
  173. device_initcall(mv643xx_eth_add_pds);