mvme147.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /* mvme147.c : the Linux/mvme147/lance ethernet driver
  2. *
  3. * Copyright (C) 05/1998 Peter Maydell <pmaydell@chiark.greenend.org.uk>
  4. * Based on the Sun Lance driver and the NetBSD HP Lance driver
  5. * Uses the generic 7990.c LANCE code.
  6. */
  7. #include <linux/module.h>
  8. #include <linux/kernel.h>
  9. #include <linux/types.h>
  10. #include <linux/interrupt.h>
  11. #include <linux/ioport.h>
  12. #include <linux/slab.h>
  13. #include <linux/string.h>
  14. #include <linux/delay.h>
  15. #include <linux/init.h>
  16. #include <linux/errno.h>
  17. /* Used for the temporal inet entries and routing */
  18. #include <linux/socket.h>
  19. #include <linux/route.h>
  20. #include <linux/netdevice.h>
  21. #include <linux/etherdevice.h>
  22. #include <linux/skbuff.h>
  23. #include <asm/system.h>
  24. #include <asm/io.h>
  25. #include <asm/pgtable.h>
  26. #include <asm/mvme147hw.h>
  27. /* We have 16834 bytes of RAM for the init block and buffers. This places
  28. * an upper limit on the number of buffers we can use. NetBSD uses 8 Rx
  29. * buffers and 2 Tx buffers.
  30. */
  31. #define LANCE_LOG_TX_BUFFERS 1
  32. #define LANCE_LOG_RX_BUFFERS 3
  33. #include "7990.h" /* use generic LANCE code */
  34. /* Our private data structure */
  35. struct m147lance_private {
  36. struct lance_private lance;
  37. unsigned long ram;
  38. };
  39. /* function prototypes... This is easy because all the grot is in the
  40. * generic LANCE support. All we have to support is probing for boards,
  41. * plus board-specific init, open and close actions.
  42. * Oh, and we need to tell the generic code how to read and write LANCE registers...
  43. */
  44. static int m147lance_open(struct net_device *dev);
  45. static int m147lance_close(struct net_device *dev);
  46. static void m147lance_writerap(struct lance_private *lp, unsigned short value);
  47. static void m147lance_writerdp(struct lance_private *lp, unsigned short value);
  48. static unsigned short m147lance_readrdp(struct lance_private *lp);
  49. typedef void (*writerap_t)(void *, unsigned short);
  50. typedef void (*writerdp_t)(void *, unsigned short);
  51. typedef unsigned short (*readrdp_t)(void *);
  52. /* Initialise the one and only on-board 7990 */
  53. struct net_device * __init mvme147lance_probe(int unit)
  54. {
  55. struct net_device *dev;
  56. static int called;
  57. static const char name[] = "MVME147 LANCE";
  58. struct m147lance_private *lp;
  59. u_long *addr;
  60. u_long address;
  61. int err;
  62. if (!MACH_IS_MVME147 || called)
  63. return ERR_PTR(-ENODEV);
  64. called++;
  65. dev = alloc_etherdev(sizeof(struct m147lance_private));
  66. if (!dev)
  67. return ERR_PTR(-ENOMEM);
  68. if (unit >= 0)
  69. sprintf(dev->name, "eth%d", unit);
  70. /* Fill the dev fields */
  71. dev->base_addr = (unsigned long)MVME147_LANCE_BASE;
  72. dev->open = &m147lance_open;
  73. dev->stop = &m147lance_close;
  74. dev->hard_start_xmit = &lance_start_xmit;
  75. dev->set_multicast_list = &lance_set_multicast;
  76. dev->tx_timeout = &lance_tx_timeout;
  77. dev->dma = 0;
  78. addr=(u_long *)ETHERNET_ADDRESS;
  79. address = *addr;
  80. dev->dev_addr[0]=0x08;
  81. dev->dev_addr[1]=0x00;
  82. dev->dev_addr[2]=0x3e;
  83. address=address>>8;
  84. dev->dev_addr[5]=address&0xff;
  85. address=address>>8;
  86. dev->dev_addr[4]=address&0xff;
  87. address=address>>8;
  88. dev->dev_addr[3]=address&0xff;
  89. printk("%s: MVME147 at 0x%08lx, irq %d, "
  90. "Hardware Address %pM\n",
  91. dev->name, dev->base_addr, MVME147_LANCE_IRQ,
  92. dev->dev_addr);
  93. lp = netdev_priv(dev);
  94. lp->ram = __get_dma_pages(GFP_ATOMIC, 3); /* 16K */
  95. if (!lp->ram)
  96. {
  97. printk("%s: No memory for LANCE buffers\n", dev->name);
  98. free_netdev(dev);
  99. return ERR_PTR(-ENOMEM);
  100. }
  101. lp->lance.name = (char*)name; /* discards const, shut up gcc */
  102. lp->lance.base = dev->base_addr;
  103. lp->lance.init_block = (struct lance_init_block *)(lp->ram); /* CPU addr */
  104. lp->lance.lance_init_block = (struct lance_init_block *)(lp->ram); /* LANCE addr of same RAM */
  105. lp->lance.busmaster_regval = LE_C3_BSWP; /* we're bigendian */
  106. lp->lance.irq = MVME147_LANCE_IRQ;
  107. lp->lance.writerap = (writerap_t)m147lance_writerap;
  108. lp->lance.writerdp = (writerdp_t)m147lance_writerdp;
  109. lp->lance.readrdp = (readrdp_t)m147lance_readrdp;
  110. lp->lance.lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS;
  111. lp->lance.lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS;
  112. lp->lance.rx_ring_mod_mask = RX_RING_MOD_MASK;
  113. lp->lance.tx_ring_mod_mask = TX_RING_MOD_MASK;
  114. err = register_netdev(dev);
  115. if (err) {
  116. free_pages(lp->ram, 3);
  117. free_netdev(dev);
  118. return ERR_PTR(err);
  119. }
  120. return dev;
  121. }
  122. static void m147lance_writerap(struct lance_private *lp, unsigned short value)
  123. {
  124. out_be16(lp->base + LANCE_RAP, value);
  125. }
  126. static void m147lance_writerdp(struct lance_private *lp, unsigned short value)
  127. {
  128. out_be16(lp->base + LANCE_RDP, value);
  129. }
  130. static unsigned short m147lance_readrdp(struct lance_private *lp)
  131. {
  132. return in_be16(lp->base + LANCE_RDP);
  133. }
  134. static int m147lance_open(struct net_device *dev)
  135. {
  136. int status;
  137. status = lance_open(dev); /* call generic lance open code */
  138. if (status)
  139. return status;
  140. /* enable interrupts at board level. */
  141. m147_pcc->lan_cntrl=0; /* clear the interrupts (if any) */
  142. m147_pcc->lan_cntrl=0x08 | 0x04; /* Enable irq 4 */
  143. return 0;
  144. }
  145. static int m147lance_close(struct net_device *dev)
  146. {
  147. /* disable interrupts at boardlevel */
  148. m147_pcc->lan_cntrl=0x0; /* disable interrupts */
  149. lance_close(dev);
  150. return 0;
  151. }
  152. #ifdef MODULE
  153. MODULE_LICENSE("GPL");
  154. static struct net_device *dev_mvme147_lance;
  155. int __init init_module(void)
  156. {
  157. dev_mvme147_lance = mvme147lance_probe(-1);
  158. if (IS_ERR(dev_mvme147_lance))
  159. return PTR_ERR(dev_mvme147_lance);
  160. return 0;
  161. }
  162. void __exit cleanup_module(void)
  163. {
  164. struct m147lance_private *lp = netdev_priv(dev_mvme147_lance);
  165. unregister_netdev(dev_mvme147_lance);
  166. free_pages(lp->ram, 3);
  167. free_netdev(dev_mvme147_lance);
  168. }
  169. #endif /* MODULE */