de600.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /**************************************************
  2. * *
  3. * Definition of D-Link Ethernet Pocket adapter *
  4. * *
  5. **************************************************/
  6. /*
  7. * D-Link Ethernet pocket adapter ports
  8. */
  9. /*
  10. * OK, so I'm cheating, but there are an awful lot of
  11. * reads and writes in order to get anything in and out
  12. * of the DE-600 with 4 bits at a time in the parallel port,
  13. * so every saved instruction really helps :-)
  14. */
  15. #ifndef DE600_IO
  16. #define DE600_IO 0x378
  17. #endif
  18. #define DATA_PORT (DE600_IO)
  19. #define STATUS_PORT (DE600_IO + 1)
  20. #define COMMAND_PORT (DE600_IO + 2)
  21. #ifndef DE600_IRQ
  22. #define DE600_IRQ 7
  23. #endif
  24. /*
  25. * It really should look like this, and autoprobing as well...
  26. *
  27. #define DATA_PORT (dev->base_addr + 0)
  28. #define STATUS_PORT (dev->base_addr + 1)
  29. #define COMMAND_PORT (dev->base_addr + 2)
  30. #define DE600_IRQ dev->irq
  31. */
  32. /*
  33. * D-Link COMMAND_PORT commands
  34. */
  35. #define SELECT_NIC 0x04 /* select Network Interface Card */
  36. #define SELECT_PRN 0x1c /* select Printer */
  37. #define NML_PRN 0xec /* normal Printer situation */
  38. #define IRQEN 0x10 /* enable IRQ line */
  39. /*
  40. * D-Link STATUS_PORT
  41. */
  42. #define RX_BUSY 0x80
  43. #define RX_GOOD 0x40
  44. #define TX_FAILED16 0x10
  45. #define TX_BUSY 0x08
  46. /*
  47. * D-Link DATA_PORT commands
  48. * command in low 4 bits
  49. * data in high 4 bits
  50. * select current data nibble with HI_NIBBLE bit
  51. */
  52. #define WRITE_DATA 0x00 /* write memory */
  53. #define READ_DATA 0x01 /* read memory */
  54. #define STATUS 0x02 /* read status register */
  55. #define COMMAND 0x03 /* write command register (see COMMAND below) */
  56. #define NULL_COMMAND 0x04 /* null command */
  57. #define RX_LEN 0x05 /* read received packet length */
  58. #define TX_ADDR 0x06 /* set adapter transmit memory address */
  59. #define RW_ADDR 0x07 /* set adapter read/write memory address */
  60. #define HI_NIBBLE 0x08 /* read/write the high nibble of data,
  61. or-ed with rest of command */
  62. /*
  63. * command register, accessed through DATA_PORT with low bits = COMMAND
  64. */
  65. #define RX_ALL 0x01 /* PROMISCUOUS */
  66. #define RX_BP 0x02 /* default: BROADCAST & PHYSICAL ADDRESS */
  67. #define RX_MBP 0x03 /* MULTICAST, BROADCAST & PHYSICAL ADDRESS */
  68. #define TX_ENABLE 0x04 /* bit 2 */
  69. #define RX_ENABLE 0x08 /* bit 3 */
  70. #define RESET 0x80 /* set bit 7 high */
  71. #define STOP_RESET 0x00 /* set bit 7 low */
  72. /*
  73. * data to command register
  74. * (high 4 bits in write to DATA_PORT)
  75. */
  76. #define RX_PAGE2_SELECT 0x10 /* bit 4, only 2 pages to select */
  77. #define RX_BASE_PAGE 0x20 /* bit 5, always set when specifying RX_ADDR */
  78. #define FLIP_IRQ 0x40 /* bit 6 */
  79. /*
  80. * D-Link adapter internal memory:
  81. *
  82. * 0-2K 1:st transmit page (send from pointer up to 2K)
  83. * 2-4K 2:nd transmit page (send from pointer up to 4K)
  84. *
  85. * 4-6K 1:st receive page (data from 4K upwards)
  86. * 6-8K 2:nd receive page (data from 6K upwards)
  87. *
  88. * 8K+ Adapter ROM (contains magic code and last 3 bytes of Ethernet address)
  89. */
  90. #define MEM_2K 0x0800 /* 2048 */
  91. #define MEM_4K 0x1000 /* 4096 */
  92. #define MEM_6K 0x1800 /* 6144 */
  93. #define NODE_ADDRESS 0x2000 /* 8192 */
  94. #define RUNT 60 /* Too small Ethernet packet */
  95. /**************************************************
  96. * *
  97. * End of definition *
  98. * *
  99. **************************************************/
  100. /*
  101. * Index to functions, as function prototypes.
  102. */
  103. /* Routines used internally. (See "convenience macros") */
  104. static u8 de600_read_status(struct net_device *dev);
  105. static u8 de600_read_byte(unsigned char type, struct net_device *dev);
  106. /* Put in the device structure. */
  107. static int de600_open(struct net_device *dev);
  108. static int de600_close(struct net_device *dev);
  109. static int de600_start_xmit(struct sk_buff *skb, struct net_device *dev);
  110. /* Dispatch from interrupts. */
  111. static irqreturn_t de600_interrupt(int irq, void *dev_id);
  112. static int de600_tx_intr(struct net_device *dev, int irq_status);
  113. static void de600_rx_intr(struct net_device *dev);
  114. /* Initialization */
  115. static void trigger_interrupt(struct net_device *dev);
  116. static int adapter_init(struct net_device *dev);
  117. /*
  118. * Convenience macros/functions for D-Link adapter
  119. */
  120. #define select_prn() outb_p(SELECT_PRN, COMMAND_PORT); DE600_SLOW_DOWN
  121. #define select_nic() outb_p(SELECT_NIC, COMMAND_PORT); DE600_SLOW_DOWN
  122. /* Thanks for hints from Mark Burton <markb@ordern.demon.co.uk> */
  123. #define de600_put_byte(data) ( \
  124. outb_p(((data) << 4) | WRITE_DATA , DATA_PORT), \
  125. outb_p(((data) & 0xf0) | WRITE_DATA | HI_NIBBLE, DATA_PORT))
  126. /*
  127. * The first two outb_p()'s below could perhaps be deleted if there
  128. * would be more delay in the last two. Not certain about it yet...
  129. */
  130. #define de600_put_command(cmd) ( \
  131. outb_p(( rx_page << 4) | COMMAND , DATA_PORT), \
  132. outb_p(( rx_page & 0xf0) | COMMAND | HI_NIBBLE, DATA_PORT), \
  133. outb_p(((rx_page | cmd) << 4) | COMMAND , DATA_PORT), \
  134. outb_p(((rx_page | cmd) & 0xf0) | COMMAND | HI_NIBBLE, DATA_PORT))
  135. #define de600_setup_address(addr,type) ( \
  136. outb_p((((addr) << 4) & 0xf0) | type , DATA_PORT), \
  137. outb_p(( (addr) & 0xf0) | type | HI_NIBBLE, DATA_PORT), \
  138. outb_p((((addr) >> 4) & 0xf0) | type , DATA_PORT), \
  139. outb_p((((addr) >> 8) & 0xf0) | type | HI_NIBBLE, DATA_PORT))
  140. #define rx_page_adr() ((rx_page & RX_PAGE2_SELECT)?(MEM_6K):(MEM_4K))
  141. /* Flip bit, only 2 pages */
  142. #define next_rx_page() (rx_page ^= RX_PAGE2_SELECT)
  143. #define tx_page_adr(a) (((a) + 1) * MEM_2K)