hydra.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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/interrupt.h>
  17. #include <linux/netdevice.h>
  18. #include <linux/etherdevice.h>
  19. #include <linux/skbuff.h>
  20. #include <linux/init.h>
  21. #include <linux/bitops.h>
  22. #include <asm/io.h>
  23. #include <asm/irq.h>
  24. #include <asm/amigaints.h>
  25. #include <asm/amigahw.h>
  26. #include <linux/zorro.h>
  27. #define EI_SHIFT(x) (ei_local->reg_offset[x])
  28. #define ei_inb(port) in_8(port)
  29. #define ei_outb(val,port) out_8(port,val)
  30. #define ei_inb_p(port) in_8(port)
  31. #define ei_outb_p(val,port) out_8(port,val)
  32. static const char version[] =
  33. "8390.c:v1.10cvs 9/23/94 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n";
  34. #include "lib8390.c"
  35. #define NE_EN0_DCFG (0x0e*2)
  36. #define NESM_START_PG 0x0 /* First page of TX buffer */
  37. #define NESM_STOP_PG 0x40 /* Last page +1 of RX ring */
  38. #define HYDRA_NIC_BASE 0xffe1
  39. #define HYDRA_ADDRPROM 0xffc0
  40. #define HYDRA_VERSION "v3.0alpha"
  41. #define WORDSWAP(a) ((((a)>>8)&0xff) | ((a)<<8))
  42. static int __devinit hydra_init_one(struct zorro_dev *z,
  43. const struct zorro_device_id *ent);
  44. static int __devinit hydra_init(struct zorro_dev *z);
  45. static int hydra_open(struct net_device *dev);
  46. static int hydra_close(struct net_device *dev);
  47. static void hydra_reset_8390(struct net_device *dev);
  48. static void hydra_get_8390_hdr(struct net_device *dev,
  49. struct e8390_pkt_hdr *hdr, int ring_page);
  50. static void hydra_block_input(struct net_device *dev, int count,
  51. struct sk_buff *skb, int ring_offset);
  52. static void hydra_block_output(struct net_device *dev, int count,
  53. const unsigned char *buf, int start_page);
  54. static void __devexit hydra_remove_one(struct zorro_dev *z);
  55. static struct zorro_device_id hydra_zorro_tbl[] __devinitdata = {
  56. { ZORRO_PROD_HYDRA_SYSTEMS_AMIGANET },
  57. { 0 }
  58. };
  59. MODULE_DEVICE_TABLE(zorro, hydra_zorro_tbl);
  60. static struct zorro_driver hydra_driver = {
  61. .name = "hydra",
  62. .id_table = hydra_zorro_tbl,
  63. .probe = hydra_init_one,
  64. .remove = __devexit_p(hydra_remove_one),
  65. };
  66. static int __devinit hydra_init_one(struct zorro_dev *z,
  67. const struct zorro_device_id *ent)
  68. {
  69. int err;
  70. if (!request_mem_region(z->resource.start, 0x10000, "Hydra"))
  71. return -EBUSY;
  72. if ((err = hydra_init(z))) {
  73. release_mem_region(z->resource.start, 0x10000);
  74. return -EBUSY;
  75. }
  76. return 0;
  77. }
  78. static const struct net_device_ops hydra_netdev_ops = {
  79. .ndo_open = hydra_open,
  80. .ndo_stop = hydra_close,
  81. .ndo_start_xmit = __ei_start_xmit,
  82. .ndo_tx_timeout = __ei_tx_timeout,
  83. .ndo_get_stats = __ei_get_stats,
  84. .ndo_set_multicast_list = __ei_set_multicast_list,
  85. .ndo_validate_addr = eth_validate_addr,
  86. .ndo_set_mac_address = eth_mac_addr,
  87. .ndo_change_mtu = eth_change_mtu,
  88. #ifdef CONFIG_NET_POLL_CONTROLLER
  89. .ndo_poll_controller = __ei_poll,
  90. #endif
  91. };
  92. static int __devinit hydra_init(struct zorro_dev *z)
  93. {
  94. struct net_device *dev;
  95. unsigned long board = ZTWO_VADDR(z->resource.start);
  96. unsigned long ioaddr = board+HYDRA_NIC_BASE;
  97. const char name[] = "NE2000";
  98. int start_page, stop_page;
  99. int j;
  100. int err;
  101. static u32 hydra_offsets[16] = {
  102. 0x00, 0x02, 0x04, 0x06, 0x08, 0x0a, 0x0c, 0x0e,
  103. 0x10, 0x12, 0x14, 0x16, 0x18, 0x1a, 0x1c, 0x1e,
  104. };
  105. dev = ____alloc_ei_netdev(0);
  106. if (!dev)
  107. return -ENOMEM;
  108. for(j = 0; j < ETHER_ADDR_LEN; j++)
  109. dev->dev_addr[j] = *((u8 *)(board + HYDRA_ADDRPROM + 2*j));
  110. /* We must set the 8390 for word mode. */
  111. z_writeb(0x4b, ioaddr + NE_EN0_DCFG);
  112. start_page = NESM_START_PG;
  113. stop_page = NESM_STOP_PG;
  114. dev->base_addr = ioaddr;
  115. dev->irq = IRQ_AMIGA_PORTS;
  116. /* Install the Interrupt handler */
  117. if (request_irq(IRQ_AMIGA_PORTS, __ei_interrupt, IRQF_SHARED, "Hydra Ethernet",
  118. dev)) {
  119. free_netdev(dev);
  120. return -EAGAIN;
  121. }
  122. ei_status.name = name;
  123. ei_status.tx_start_page = start_page;
  124. ei_status.stop_page = stop_page;
  125. ei_status.word16 = 1;
  126. ei_status.bigendian = 1;
  127. ei_status.rx_start_page = start_page + TX_PAGES;
  128. ei_status.reset_8390 = hydra_reset_8390;
  129. ei_status.block_input = hydra_block_input;
  130. ei_status.block_output = hydra_block_output;
  131. ei_status.get_8390_hdr = hydra_get_8390_hdr;
  132. ei_status.reg_offset = hydra_offsets;
  133. dev->netdev_ops = &hydra_netdev_ops;
  134. __NS8390_init(dev, 0);
  135. err = register_netdev(dev);
  136. if (err) {
  137. free_irq(IRQ_AMIGA_PORTS, dev);
  138. free_netdev(dev);
  139. return err;
  140. }
  141. zorro_set_drvdata(z, dev);
  142. pr_info("%s: Hydra at %pR, address %pM (hydra.c " HYDRA_VERSION ")\n",
  143. dev->name, &z->resource, dev->dev_addr);
  144. return 0;
  145. }
  146. static int hydra_open(struct net_device *dev)
  147. {
  148. __ei_open(dev);
  149. return 0;
  150. }
  151. static int hydra_close(struct net_device *dev)
  152. {
  153. if (ei_debug > 1)
  154. printk(KERN_DEBUG "%s: Shutting down ethercard.\n", dev->name);
  155. __ei_close(dev);
  156. return 0;
  157. }
  158. static void hydra_reset_8390(struct net_device *dev)
  159. {
  160. printk(KERN_INFO "Hydra hw reset not there\n");
  161. }
  162. static void hydra_get_8390_hdr(struct net_device *dev,
  163. struct e8390_pkt_hdr *hdr, int ring_page)
  164. {
  165. int nic_base = dev->base_addr;
  166. short *ptrs;
  167. unsigned long hdr_start= (nic_base-HYDRA_NIC_BASE) +
  168. ((ring_page - NESM_START_PG)<<8);
  169. ptrs = (short *)hdr;
  170. *(ptrs++) = z_readw(hdr_start);
  171. *((short *)hdr) = WORDSWAP(*((short *)hdr));
  172. hdr_start += 2;
  173. *(ptrs++) = z_readw(hdr_start);
  174. *((short *)hdr+1) = WORDSWAP(*((short *)hdr+1));
  175. }
  176. static void hydra_block_input(struct net_device *dev, int count,
  177. struct sk_buff *skb, int ring_offset)
  178. {
  179. unsigned long nic_base = dev->base_addr;
  180. unsigned long mem_base = nic_base - HYDRA_NIC_BASE;
  181. unsigned long xfer_start = mem_base + ring_offset - (NESM_START_PG<<8);
  182. if (count&1)
  183. count++;
  184. if (xfer_start+count > mem_base + (NESM_STOP_PG<<8)) {
  185. int semi_count = (mem_base + (NESM_STOP_PG<<8)) - xfer_start;
  186. z_memcpy_fromio(skb->data,xfer_start,semi_count);
  187. count -= semi_count;
  188. z_memcpy_fromio(skb->data+semi_count, mem_base, count);
  189. } else
  190. z_memcpy_fromio(skb->data, xfer_start,count);
  191. }
  192. static void hydra_block_output(struct net_device *dev, int count,
  193. const unsigned char *buf, int start_page)
  194. {
  195. unsigned long nic_base = dev->base_addr;
  196. unsigned long mem_base = nic_base - HYDRA_NIC_BASE;
  197. if (count&1)
  198. count++;
  199. z_memcpy_toio(mem_base+((start_page - NESM_START_PG)<<8), buf, count);
  200. }
  201. static void __devexit hydra_remove_one(struct zorro_dev *z)
  202. {
  203. struct net_device *dev = zorro_get_drvdata(z);
  204. unregister_netdev(dev);
  205. free_irq(IRQ_AMIGA_PORTS, dev);
  206. release_mem_region(ZTWO_PADDR(dev->base_addr)-HYDRA_NIC_BASE, 0x10000);
  207. free_netdev(dev);
  208. }
  209. static int __init hydra_init_module(void)
  210. {
  211. return zorro_register_driver(&hydra_driver);
  212. }
  213. static void __exit hydra_cleanup_module(void)
  214. {
  215. zorro_unregister_driver(&hydra_driver);
  216. }
  217. module_init(hydra_init_module);
  218. module_exit(hydra_cleanup_module);
  219. MODULE_LICENSE("GPL");