mvme147.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. DECLARE_MAC_BUF(mac);
  63. if (!MACH_IS_MVME147 || called)
  64. return ERR_PTR(-ENODEV);
  65. called++;
  66. dev = alloc_etherdev(sizeof(struct m147lance_private));
  67. if (!dev)
  68. return ERR_PTR(-ENOMEM);
  69. if (unit >= 0)
  70. sprintf(dev->name, "eth%d", unit);
  71. /* Fill the dev fields */
  72. dev->base_addr = (unsigned long)MVME147_LANCE_BASE;
  73. dev->open = &m147lance_open;
  74. dev->stop = &m147lance_close;
  75. dev->hard_start_xmit = &lance_start_xmit;
  76. dev->set_multicast_list = &lance_set_multicast;
  77. dev->tx_timeout = &lance_tx_timeout;
  78. dev->dma = 0;
  79. addr=(u_long *)ETHERNET_ADDRESS;
  80. address = *addr;
  81. dev->dev_addr[0]=0x08;
  82. dev->dev_addr[1]=0x00;
  83. dev->dev_addr[2]=0x3e;
  84. address=address>>8;
  85. dev->dev_addr[5]=address&0xff;
  86. address=address>>8;
  87. dev->dev_addr[4]=address&0xff;
  88. address=address>>8;
  89. dev->dev_addr[3]=address&0xff;
  90. printk("%s: MVME147 at 0x%08lx, irq %d, "
  91. "Hardware Address %s\n",
  92. dev->name, dev->base_addr, MVME147_LANCE_IRQ,
  93. print_mac(mac, dev->dev_addr));
  94. lp = (struct m147lance_private *)dev->priv;
  95. lp->ram = __get_dma_pages(GFP_ATOMIC, 3); /* 16K */
  96. if (!lp->ram)
  97. {
  98. printk("%s: No memory for LANCE buffers\n", dev->name);
  99. free_netdev(dev);
  100. return ERR_PTR(-ENOMEM);
  101. }
  102. lp->lance.name = (char*)name; /* discards const, shut up gcc */
  103. lp->lance.base = dev->base_addr;
  104. lp->lance.init_block = (struct lance_init_block *)(lp->ram); /* CPU addr */
  105. lp->lance.lance_init_block = (struct lance_init_block *)(lp->ram); /* LANCE addr of same RAM */
  106. lp->lance.busmaster_regval = LE_C3_BSWP; /* we're bigendian */
  107. lp->lance.irq = MVME147_LANCE_IRQ;
  108. lp->lance.writerap = (writerap_t)m147lance_writerap;
  109. lp->lance.writerdp = (writerdp_t)m147lance_writerdp;
  110. lp->lance.readrdp = (readrdp_t)m147lance_readrdp;
  111. lp->lance.lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS;
  112. lp->lance.lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS;
  113. lp->lance.rx_ring_mod_mask = RX_RING_MOD_MASK;
  114. lp->lance.tx_ring_mod_mask = TX_RING_MOD_MASK;
  115. err = register_netdev(dev);
  116. if (err) {
  117. free_pages(lp->ram, 3);
  118. free_netdev(dev);
  119. return ERR_PTR(err);
  120. }
  121. return dev;
  122. }
  123. static void m147lance_writerap(struct lance_private *lp, unsigned short value)
  124. {
  125. out_be16(lp->base + LANCE_RAP, value);
  126. }
  127. static void m147lance_writerdp(struct lance_private *lp, unsigned short value)
  128. {
  129. out_be16(lp->base + LANCE_RDP, value);
  130. }
  131. static unsigned short m147lance_readrdp(struct lance_private *lp)
  132. {
  133. return in_be16(lp->base + LANCE_RDP);
  134. }
  135. static int m147lance_open(struct net_device *dev)
  136. {
  137. int status;
  138. status = lance_open(dev); /* call generic lance open code */
  139. if (status)
  140. return status;
  141. /* enable interrupts at board level. */
  142. m147_pcc->lan_cntrl=0; /* clear the interrupts (if any) */
  143. m147_pcc->lan_cntrl=0x08 | 0x04; /* Enable irq 4 */
  144. return 0;
  145. }
  146. static int m147lance_close(struct net_device *dev)
  147. {
  148. /* disable interrupts at boardlevel */
  149. m147_pcc->lan_cntrl=0x0; /* disable interrupts */
  150. lance_close(dev);
  151. return 0;
  152. }
  153. #ifdef MODULE
  154. MODULE_LICENSE("GPL");
  155. static struct net_device *dev_mvme147_lance;
  156. int __init init_module(void)
  157. {
  158. dev_mvme147_lance = mvme147lance_probe(-1);
  159. if (IS_ERR(dev_mvme147_lance))
  160. return PTR_ERR(dev_mvme147_lance);
  161. return 0;
  162. }
  163. void __exit cleanup_module(void)
  164. {
  165. struct m147lance_private *lp = dev_mvme147_lance->priv;
  166. unregister_netdev(dev_mvme147_lance);
  167. free_pages(lp->ram, 3);
  168. free_netdev(dev_mvme147_lance);
  169. }
  170. #endif /* MODULE */