jazzsonic.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * jazzsonic.c
  4. *
  5. * (C) 2005 Finn Thain
  6. *
  7. * Converted to DMA API, and (from the mac68k project) introduced
  8. * dhd's support for 16-bit cards.
  9. *
  10. * (C) 1996,1998 by Thomas Bogendoerfer ([email protected])
  11. *
  12. * This driver is based on work from Andreas Busse, but most of
  13. * the code is rewritten.
  14. *
  15. * (C) 1995 by Andreas Busse ([email protected])
  16. *
  17. * A driver for the onboard Sonic ethernet controller on Mips Jazz
  18. * systems (Acer Pica-61, Mips Magnum 4000, Olivetti M700 and
  19. * perhaps others, too)
  20. */
  21. #include <linux/kernel.h>
  22. #include <linux/module.h>
  23. #include <linux/types.h>
  24. #include <linux/fcntl.h>
  25. #include <linux/gfp.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/ioport.h>
  28. #include <linux/in.h>
  29. #include <linux/string.h>
  30. #include <linux/delay.h>
  31. #include <linux/errno.h>
  32. #include <linux/netdevice.h>
  33. #include <linux/etherdevice.h>
  34. #include <linux/skbuff.h>
  35. #include <linux/platform_device.h>
  36. #include <linux/dma-mapping.h>
  37. #include <linux/slab.h>
  38. #include <linux/pgtable.h>
  39. #include <asm/bootinfo.h>
  40. #include <asm/io.h>
  41. #include <asm/dma.h>
  42. #include <asm/jazz.h>
  43. #include <asm/jazzdma.h>
  44. static char jazz_sonic_string[] = "jazzsonic";
  45. #define SONIC_MEM_SIZE 0x100
  46. #include "sonic.h"
  47. /*
  48. * Macros to access SONIC registers
  49. */
  50. #define SONIC_READ(reg) (*((volatile unsigned int *)dev->base_addr+reg))
  51. #define SONIC_WRITE(reg,val) \
  52. do { \
  53. *((volatile unsigned int *)dev->base_addr+(reg)) = (val); \
  54. } while (0)
  55. /*
  56. * We cannot use station (ethernet) address prefixes to detect the
  57. * sonic controller since these are board manufacturer depended.
  58. * So we check for known Silicon Revision IDs instead.
  59. */
  60. static unsigned short known_revisions[] =
  61. {
  62. 0x04, /* Mips Magnum 4000 */
  63. 0xffff /* end of list */
  64. };
  65. static int jazzsonic_open(struct net_device* dev)
  66. {
  67. int retval;
  68. retval = request_irq(dev->irq, sonic_interrupt, 0, "sonic", dev);
  69. if (retval) {
  70. printk(KERN_ERR "%s: unable to get IRQ %d.\n",
  71. dev->name, dev->irq);
  72. return retval;
  73. }
  74. retval = sonic_open(dev);
  75. if (retval)
  76. free_irq(dev->irq, dev);
  77. return retval;
  78. }
  79. static int jazzsonic_close(struct net_device* dev)
  80. {
  81. int err;
  82. err = sonic_close(dev);
  83. free_irq(dev->irq, dev);
  84. return err;
  85. }
  86. static const struct net_device_ops sonic_netdev_ops = {
  87. .ndo_open = jazzsonic_open,
  88. .ndo_stop = jazzsonic_close,
  89. .ndo_start_xmit = sonic_send_packet,
  90. .ndo_get_stats = sonic_get_stats,
  91. .ndo_set_rx_mode = sonic_multicast_list,
  92. .ndo_tx_timeout = sonic_tx_timeout,
  93. .ndo_validate_addr = eth_validate_addr,
  94. .ndo_set_mac_address = eth_mac_addr,
  95. };
  96. static int sonic_probe1(struct net_device *dev)
  97. {
  98. unsigned int silicon_revision;
  99. unsigned int val;
  100. struct sonic_local *lp = netdev_priv(dev);
  101. int err = -ENODEV;
  102. int i;
  103. unsigned char addr[ETH_ALEN];
  104. if (!request_mem_region(dev->base_addr, SONIC_MEM_SIZE, jazz_sonic_string))
  105. return -EBUSY;
  106. /*
  107. * get the Silicon Revision ID. If this is one of the known
  108. * one assume that we found a SONIC ethernet controller at
  109. * the expected location.
  110. */
  111. silicon_revision = SONIC_READ(SONIC_SR);
  112. i = 0;
  113. while (known_revisions[i] != 0xffff &&
  114. known_revisions[i] != silicon_revision)
  115. i++;
  116. if (known_revisions[i] == 0xffff) {
  117. pr_info("SONIC ethernet controller not found (0x%4x)\n",
  118. silicon_revision);
  119. goto out;
  120. }
  121. /*
  122. * Put the sonic into software reset, then
  123. * retrieve and print the ethernet address.
  124. */
  125. SONIC_WRITE(SONIC_CMD,SONIC_CR_RST);
  126. SONIC_WRITE(SONIC_CEP,0);
  127. for (i=0; i<3; i++) {
  128. val = SONIC_READ(SONIC_CAP0-i);
  129. addr[i*2] = val;
  130. addr[i*2+1] = val >> 8;
  131. }
  132. eth_hw_addr_set(dev, addr);
  133. lp->dma_bitmode = SONIC_BITMODE32;
  134. err = sonic_alloc_descriptors(dev);
  135. if (err)
  136. goto out;
  137. dev->netdev_ops = &sonic_netdev_ops;
  138. dev->watchdog_timeo = TX_TIMEOUT;
  139. /*
  140. * clear tally counter
  141. */
  142. SONIC_WRITE(SONIC_CRCT,0xffff);
  143. SONIC_WRITE(SONIC_FAET,0xffff);
  144. SONIC_WRITE(SONIC_MPT,0xffff);
  145. return 0;
  146. out:
  147. release_mem_region(dev->base_addr, SONIC_MEM_SIZE);
  148. return err;
  149. }
  150. /*
  151. * Probe for a SONIC ethernet controller on a Mips Jazz board.
  152. * Actually probing is superfluous but we're paranoid.
  153. */
  154. static int jazz_sonic_probe(struct platform_device *pdev)
  155. {
  156. struct net_device *dev;
  157. struct sonic_local *lp;
  158. struct resource *res;
  159. int err = 0;
  160. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  161. if (!res)
  162. return -ENODEV;
  163. dev = alloc_etherdev(sizeof(struct sonic_local));
  164. if (!dev)
  165. return -ENOMEM;
  166. lp = netdev_priv(dev);
  167. lp->device = &pdev->dev;
  168. SET_NETDEV_DEV(dev, &pdev->dev);
  169. platform_set_drvdata(pdev, dev);
  170. dev->base_addr = res->start;
  171. dev->irq = platform_get_irq(pdev, 0);
  172. err = sonic_probe1(dev);
  173. if (err)
  174. goto out;
  175. pr_info("SONIC ethernet @%08lx, MAC %pM, IRQ %d\n",
  176. dev->base_addr, dev->dev_addr, dev->irq);
  177. sonic_msg_init(dev);
  178. err = register_netdev(dev);
  179. if (err)
  180. goto undo_probe1;
  181. return 0;
  182. undo_probe1:
  183. dma_free_coherent(lp->device, SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode),
  184. lp->descriptors, lp->descriptors_laddr);
  185. release_mem_region(dev->base_addr, SONIC_MEM_SIZE);
  186. out:
  187. free_netdev(dev);
  188. return err;
  189. }
  190. MODULE_DESCRIPTION("Jazz SONIC ethernet driver");
  191. MODULE_ALIAS("platform:jazzsonic");
  192. #include "sonic.c"
  193. static int jazz_sonic_device_remove(struct platform_device *pdev)
  194. {
  195. struct net_device *dev = platform_get_drvdata(pdev);
  196. struct sonic_local* lp = netdev_priv(dev);
  197. unregister_netdev(dev);
  198. dma_free_coherent(lp->device, SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode),
  199. lp->descriptors, lp->descriptors_laddr);
  200. release_mem_region(dev->base_addr, SONIC_MEM_SIZE);
  201. free_netdev(dev);
  202. return 0;
  203. }
  204. static struct platform_driver jazz_sonic_driver = {
  205. .probe = jazz_sonic_probe,
  206. .remove = jazz_sonic_device_remove,
  207. .driver = {
  208. .name = jazz_sonic_string,
  209. },
  210. };
  211. module_platform_driver(jazz_sonic_driver);