hydra.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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 hydra_init_one(struct zorro_dev *z,
  43. const struct zorro_device_id *ent);
  44. static int 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 hydra_remove_one(struct zorro_dev *z);
  55. static u32 hydra_msg_enable;
  56. static struct zorro_device_id hydra_zorro_tbl[] = {
  57. { ZORRO_PROD_HYDRA_SYSTEMS_AMIGANET },
  58. { 0 }
  59. };
  60. MODULE_DEVICE_TABLE(zorro, hydra_zorro_tbl);
  61. static struct zorro_driver hydra_driver = {
  62. .name = "hydra",
  63. .id_table = hydra_zorro_tbl,
  64. .probe = hydra_init_one,
  65. .remove = hydra_remove_one,
  66. };
  67. static int hydra_init_one(struct zorro_dev *z,
  68. const struct zorro_device_id *ent)
  69. {
  70. int err;
  71. if (!request_mem_region(z->resource.start, 0x10000, "Hydra"))
  72. return -EBUSY;
  73. if ((err = hydra_init(z))) {
  74. release_mem_region(z->resource.start, 0x10000);
  75. return -EBUSY;
  76. }
  77. return 0;
  78. }
  79. static const struct net_device_ops hydra_netdev_ops = {
  80. .ndo_open = hydra_open,
  81. .ndo_stop = hydra_close,
  82. .ndo_start_xmit = __ei_start_xmit,
  83. .ndo_tx_timeout = __ei_tx_timeout,
  84. .ndo_get_stats = __ei_get_stats,
  85. .ndo_set_rx_mode = __ei_set_multicast_list,
  86. .ndo_validate_addr = eth_validate_addr,
  87. .ndo_set_mac_address = eth_mac_addr,
  88. .ndo_change_mtu = eth_change_mtu,
  89. #ifdef CONFIG_NET_POLL_CONTROLLER
  90. .ndo_poll_controller = __ei_poll,
  91. #endif
  92. };
  93. static int hydra_init(struct zorro_dev *z)
  94. {
  95. struct net_device *dev;
  96. unsigned long board = (unsigned long)ZTWO_VADDR(z->resource.start);
  97. unsigned long ioaddr = board+HYDRA_NIC_BASE;
  98. const char name[] = "NE2000";
  99. int start_page, stop_page;
  100. int j;
  101. int err;
  102. struct ei_device *ei_local;
  103. static u32 hydra_offsets[16] = {
  104. 0x00, 0x02, 0x04, 0x06, 0x08, 0x0a, 0x0c, 0x0e,
  105. 0x10, 0x12, 0x14, 0x16, 0x18, 0x1a, 0x1c, 0x1e,
  106. };
  107. dev = ____alloc_ei_netdev(0);
  108. if (!dev)
  109. return -ENOMEM;
  110. for (j = 0; j < ETH_ALEN; j++)
  111. dev->dev_addr[j] = *((u8 *)(board + HYDRA_ADDRPROM + 2*j));
  112. /* We must set the 8390 for word mode. */
  113. z_writeb(0x4b, ioaddr + NE_EN0_DCFG);
  114. start_page = NESM_START_PG;
  115. stop_page = NESM_STOP_PG;
  116. ei_local = netdev_priv(dev);
  117. ei_local->msg_enable = hydra_msg_enable;
  118. dev->base_addr = ioaddr;
  119. dev->irq = IRQ_AMIGA_PORTS;
  120. /* Install the Interrupt handler */
  121. if (request_irq(IRQ_AMIGA_PORTS, __ei_interrupt, IRQF_SHARED, "Hydra Ethernet",
  122. dev)) {
  123. free_netdev(dev);
  124. return -EAGAIN;
  125. }
  126. ei_status.name = name;
  127. ei_status.tx_start_page = start_page;
  128. ei_status.stop_page = stop_page;
  129. ei_status.word16 = 1;
  130. ei_status.bigendian = 1;
  131. ei_status.rx_start_page = start_page + TX_PAGES;
  132. ei_status.reset_8390 = hydra_reset_8390;
  133. ei_status.block_input = hydra_block_input;
  134. ei_status.block_output = hydra_block_output;
  135. ei_status.get_8390_hdr = hydra_get_8390_hdr;
  136. ei_status.reg_offset = hydra_offsets;
  137. dev->netdev_ops = &hydra_netdev_ops;
  138. __NS8390_init(dev, 0);
  139. err = register_netdev(dev);
  140. if (err) {
  141. free_irq(IRQ_AMIGA_PORTS, dev);
  142. free_netdev(dev);
  143. return err;
  144. }
  145. zorro_set_drvdata(z, dev);
  146. pr_info("%s: Hydra at %pR, address %pM (hydra.c " HYDRA_VERSION ")\n",
  147. dev->name, &z->resource, dev->dev_addr);
  148. return 0;
  149. }
  150. static int hydra_open(struct net_device *dev)
  151. {
  152. __ei_open(dev);
  153. return 0;
  154. }
  155. static int hydra_close(struct net_device *dev)
  156. {
  157. struct ei_device *ei_local = netdev_priv(dev);
  158. netif_dbg(ei_local, ifdown, dev, "Shutting down ethercard.\n");
  159. __ei_close(dev);
  160. return 0;
  161. }
  162. static void hydra_reset_8390(struct net_device *dev)
  163. {
  164. netdev_info(dev, "Hydra hw reset not there\n");
  165. }
  166. static void hydra_get_8390_hdr(struct net_device *dev,
  167. struct e8390_pkt_hdr *hdr, int ring_page)
  168. {
  169. int nic_base = dev->base_addr;
  170. short *ptrs;
  171. unsigned long hdr_start= (nic_base-HYDRA_NIC_BASE) +
  172. ((ring_page - NESM_START_PG)<<8);
  173. ptrs = (short *)hdr;
  174. *(ptrs++) = z_readw(hdr_start);
  175. *((short *)hdr) = WORDSWAP(*((short *)hdr));
  176. hdr_start += 2;
  177. *(ptrs++) = z_readw(hdr_start);
  178. *((short *)hdr+1) = WORDSWAP(*((short *)hdr+1));
  179. }
  180. static void hydra_block_input(struct net_device *dev, int count,
  181. struct sk_buff *skb, int ring_offset)
  182. {
  183. unsigned long nic_base = dev->base_addr;
  184. unsigned long mem_base = nic_base - HYDRA_NIC_BASE;
  185. unsigned long xfer_start = mem_base + ring_offset - (NESM_START_PG<<8);
  186. if (count&1)
  187. count++;
  188. if (xfer_start+count > mem_base + (NESM_STOP_PG<<8)) {
  189. int semi_count = (mem_base + (NESM_STOP_PG<<8)) - xfer_start;
  190. z_memcpy_fromio(skb->data,xfer_start,semi_count);
  191. count -= semi_count;
  192. z_memcpy_fromio(skb->data+semi_count, mem_base, count);
  193. } else
  194. z_memcpy_fromio(skb->data, xfer_start,count);
  195. }
  196. static void hydra_block_output(struct net_device *dev, int count,
  197. const unsigned char *buf, int start_page)
  198. {
  199. unsigned long nic_base = dev->base_addr;
  200. unsigned long mem_base = nic_base - HYDRA_NIC_BASE;
  201. if (count&1)
  202. count++;
  203. z_memcpy_toio(mem_base+((start_page - NESM_START_PG)<<8), buf, count);
  204. }
  205. static void hydra_remove_one(struct zorro_dev *z)
  206. {
  207. struct net_device *dev = zorro_get_drvdata(z);
  208. unregister_netdev(dev);
  209. free_irq(IRQ_AMIGA_PORTS, dev);
  210. release_mem_region(ZTWO_PADDR(dev->base_addr)-HYDRA_NIC_BASE, 0x10000);
  211. free_netdev(dev);
  212. }
  213. static int __init hydra_init_module(void)
  214. {
  215. return zorro_register_driver(&hydra_driver);
  216. }
  217. static void __exit hydra_cleanup_module(void)
  218. {
  219. zorro_unregister_driver(&hydra_driver);
  220. }
  221. module_init(hydra_init_module);
  222. module_exit(hydra_cleanup_module);
  223. MODULE_LICENSE("GPL");