hydra.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /* New Hydra driver using generic 8390 core */
  2. /* Based on old hydra driver by Topi Kanerva (topi@susanna.oulu.fi) */
  3. /* This file is subject to the terms and conditions of the GNU General */
  4. /* Public License. See the file COPYING in the main directory of the */
  5. /* Linux distribution for more details. */
  6. /* Peter De Schrijver (p2@mind.be) */
  7. /* Oldenburg 2000 */
  8. /* The Amiganet is a Zorro-II board made by Hydra Systems. It contains a */
  9. /* NS8390 NIC (network interface controller) clone, 16 or 64K on-board RAM */
  10. /* and 10BASE-2 (thin coax) and AUI connectors. */
  11. #include <linux/module.h>
  12. #include <linux/kernel.h>
  13. #include <linux/string.h>
  14. #include <linux/errno.h>
  15. #include <linux/ioport.h>
  16. #include <linux/slab.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/netdevice.h>
  19. #include <linux/etherdevice.h>
  20. #include <linux/skbuff.h>
  21. #include <linux/init.h>
  22. #include <linux/bitops.h>
  23. #include <asm/io.h>
  24. #include <asm/irq.h>
  25. #include <asm/amigaints.h>
  26. #include <asm/amigahw.h>
  27. #include <linux/zorro.h>
  28. #include "8390.h"
  29. #define NE_EN0_DCFG (0x0e*2)
  30. #define NESM_START_PG 0x0 /* First page of TX buffer */
  31. #define NESM_STOP_PG 0x40 /* Last page +1 of RX ring */
  32. #define HYDRA_NIC_BASE 0xffe1
  33. #define HYDRA_ADDRPROM 0xffc0
  34. #define HYDRA_VERSION "v3.0alpha"
  35. #define WORDSWAP(a) ((((a)>>8)&0xff) | ((a)<<8))
  36. static int __devinit hydra_init_one(struct zorro_dev *z,
  37. const struct zorro_device_id *ent);
  38. static int __devinit hydra_init(struct zorro_dev *z);
  39. static int hydra_open(struct net_device *dev);
  40. static int hydra_close(struct net_device *dev);
  41. static void hydra_reset_8390(struct net_device *dev);
  42. static void hydra_get_8390_hdr(struct net_device *dev,
  43. struct e8390_pkt_hdr *hdr, int ring_page);
  44. static void hydra_block_input(struct net_device *dev, int count,
  45. struct sk_buff *skb, int ring_offset);
  46. static void hydra_block_output(struct net_device *dev, int count,
  47. const unsigned char *buf, int start_page);
  48. static void __devexit hydra_remove_one(struct zorro_dev *z);
  49. static struct zorro_device_id hydra_zorro_tbl[] __devinitdata = {
  50. { ZORRO_PROD_HYDRA_SYSTEMS_AMIGANET },
  51. { 0 }
  52. };
  53. static struct zorro_driver hydra_driver = {
  54. .name = "hydra",
  55. .id_table = hydra_zorro_tbl,
  56. .probe = hydra_init_one,
  57. .remove = __devexit_p(hydra_remove_one),
  58. };
  59. static int __devinit hydra_init_one(struct zorro_dev *z,
  60. const struct zorro_device_id *ent)
  61. {
  62. int err;
  63. if (!request_mem_region(z->resource.start, 0x10000, "Hydra"))
  64. return -EBUSY;
  65. if ((err = hydra_init(z))) {
  66. release_mem_region(z->resource.start, 0x10000);
  67. return -EBUSY;
  68. }
  69. return 0;
  70. }
  71. static int __devinit hydra_init(struct zorro_dev *z)
  72. {
  73. struct net_device *dev;
  74. unsigned long board = ZTWO_VADDR(z->resource.start);
  75. unsigned long ioaddr = board+HYDRA_NIC_BASE;
  76. const char name[] = "NE2000";
  77. int start_page, stop_page;
  78. int j;
  79. int err;
  80. static u32 hydra_offsets[16] = {
  81. 0x00, 0x02, 0x04, 0x06, 0x08, 0x0a, 0x0c, 0x0e,
  82. 0x10, 0x12, 0x14, 0x16, 0x18, 0x1a, 0x1c, 0x1e,
  83. };
  84. dev = alloc_ei_netdev();
  85. if (!dev)
  86. return -ENOMEM;
  87. SET_MODULE_OWNER(dev);
  88. for(j = 0; j < ETHER_ADDR_LEN; j++)
  89. dev->dev_addr[j] = *((u8 *)(board + HYDRA_ADDRPROM + 2*j));
  90. /* We must set the 8390 for word mode. */
  91. z_writeb(0x4b, ioaddr + NE_EN0_DCFG);
  92. start_page = NESM_START_PG;
  93. stop_page = NESM_STOP_PG;
  94. dev->base_addr = ioaddr;
  95. dev->irq = IRQ_AMIGA_PORTS;
  96. /* Install the Interrupt handler */
  97. if (request_irq(IRQ_AMIGA_PORTS, ei_interrupt, SA_SHIRQ, "Hydra Ethernet",
  98. dev)) {
  99. free_netdev(dev);
  100. return -EAGAIN;
  101. }
  102. ei_status.name = name;
  103. ei_status.tx_start_page = start_page;
  104. ei_status.stop_page = stop_page;
  105. ei_status.word16 = 1;
  106. ei_status.bigendian = 1;
  107. ei_status.rx_start_page = start_page + TX_PAGES;
  108. ei_status.reset_8390 = &hydra_reset_8390;
  109. ei_status.block_input = &hydra_block_input;
  110. ei_status.block_output = &hydra_block_output;
  111. ei_status.get_8390_hdr = &hydra_get_8390_hdr;
  112. ei_status.reg_offset = hydra_offsets;
  113. dev->open = &hydra_open;
  114. dev->stop = &hydra_close;
  115. #ifdef CONFIG_NET_POLL_CONTROLLER
  116. dev->poll_controller = ei_poll;
  117. #endif
  118. NS8390_init(dev, 0);
  119. err = register_netdev(dev);
  120. if (err) {
  121. free_irq(IRQ_AMIGA_PORTS, dev);
  122. free_netdev(dev);
  123. return err;
  124. }
  125. zorro_set_drvdata(z, dev);
  126. printk(KERN_INFO "%s: Hydra at 0x%08lx, address "
  127. "%02x:%02x:%02x:%02x:%02x:%02x (hydra.c " HYDRA_VERSION ")\n",
  128. dev->name, z->resource.start, dev->dev_addr[0], dev->dev_addr[1],
  129. dev->dev_addr[2], dev->dev_addr[3], dev->dev_addr[4],
  130. dev->dev_addr[5]);
  131. return 0;
  132. }
  133. static int hydra_open(struct net_device *dev)
  134. {
  135. ei_open(dev);
  136. return 0;
  137. }
  138. static int hydra_close(struct net_device *dev)
  139. {
  140. if (ei_debug > 1)
  141. printk(KERN_DEBUG "%s: Shutting down ethercard.\n", dev->name);
  142. ei_close(dev);
  143. return 0;
  144. }
  145. static void hydra_reset_8390(struct net_device *dev)
  146. {
  147. printk(KERN_INFO "Hydra hw reset not there\n");
  148. }
  149. static void hydra_get_8390_hdr(struct net_device *dev,
  150. struct e8390_pkt_hdr *hdr, int ring_page)
  151. {
  152. int nic_base = dev->base_addr;
  153. short *ptrs;
  154. unsigned long hdr_start= (nic_base-HYDRA_NIC_BASE) +
  155. ((ring_page - NESM_START_PG)<<8);
  156. ptrs = (short *)hdr;
  157. *(ptrs++) = z_readw(hdr_start);
  158. *((short *)hdr) = WORDSWAP(*((short *)hdr));
  159. hdr_start += 2;
  160. *(ptrs++) = z_readw(hdr_start);
  161. *((short *)hdr+1) = WORDSWAP(*((short *)hdr+1));
  162. }
  163. static void hydra_block_input(struct net_device *dev, int count,
  164. struct sk_buff *skb, int ring_offset)
  165. {
  166. unsigned long nic_base = dev->base_addr;
  167. unsigned long mem_base = nic_base - HYDRA_NIC_BASE;
  168. unsigned long xfer_start = mem_base + ring_offset - (NESM_START_PG<<8);
  169. if (count&1)
  170. count++;
  171. if (xfer_start+count > mem_base + (NESM_STOP_PG<<8)) {
  172. int semi_count = (mem_base + (NESM_STOP_PG<<8)) - xfer_start;
  173. z_memcpy_fromio(skb->data,xfer_start,semi_count);
  174. count -= semi_count;
  175. z_memcpy_fromio(skb->data+semi_count, mem_base, count);
  176. } else
  177. z_memcpy_fromio(skb->data, xfer_start,count);
  178. }
  179. static void hydra_block_output(struct net_device *dev, int count,
  180. const unsigned char *buf, int start_page)
  181. {
  182. unsigned long nic_base = dev->base_addr;
  183. unsigned long mem_base = nic_base - HYDRA_NIC_BASE;
  184. if (count&1)
  185. count++;
  186. z_memcpy_toio(mem_base+((start_page - NESM_START_PG)<<8), buf, count);
  187. }
  188. static void __devexit hydra_remove_one(struct zorro_dev *z)
  189. {
  190. struct net_device *dev = zorro_get_drvdata(z);
  191. unregister_netdev(dev);
  192. free_irq(IRQ_AMIGA_PORTS, dev);
  193. release_mem_region(ZTWO_PADDR(dev->base_addr)-HYDRA_NIC_BASE, 0x10000);
  194. free_netdev(dev);
  195. }
  196. static int __init hydra_init_module(void)
  197. {
  198. return zorro_register_driver(&hydra_driver);
  199. }
  200. static void __exit hydra_cleanup_module(void)
  201. {
  202. zorro_unregister_driver(&hydra_driver);
  203. }
  204. module_init(hydra_init_module);
  205. module_exit(hydra_cleanup_module);
  206. MODULE_LICENSE("GPL");