z8530book.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. =======================
  2. Z8530 Programming Guide
  3. =======================
  4. :Author: Alan Cox
  5. Introduction
  6. ============
  7. The Z85x30 family synchronous/asynchronous controller chips are used on
  8. a large number of cheap network interface cards. The kernel provides a
  9. core interface layer that is designed to make it easy to provide WAN
  10. services using this chip.
  11. The current driver only support synchronous operation. Merging the
  12. asynchronous driver support into this code to allow any Z85x30 device to
  13. be used as both a tty interface and as a synchronous controller is a
  14. project for Linux post the 2.4 release
  15. Driver Modes
  16. ============
  17. The Z85230 driver layer can drive Z8530, Z85C30 and Z85230 devices in
  18. three different modes. Each mode can be applied to an individual channel
  19. on the chip (each chip has two channels).
  20. The PIO synchronous mode supports the most common Z8530 wiring. Here the
  21. chip is interface to the I/O and interrupt facilities of the host
  22. machine but not to the DMA subsystem. When running PIO the Z8530 has
  23. extremely tight timing requirements. Doing high speeds, even with a
  24. Z85230 will be tricky. Typically you should expect to achieve at best
  25. 9600 baud with a Z8C530 and 64Kbits with a Z85230.
  26. The DMA mode supports the chip when it is configured to use dual DMA
  27. channels on an ISA bus. The better cards tend to support this mode of
  28. operation for a single channel. With DMA running the Z85230 tops out
  29. when it starts to hit ISA DMA constraints at about 512Kbits. It is worth
  30. noting here that many PC machines hang or crash when the chip is driven
  31. fast enough to hold the ISA bus solid.
  32. Transmit DMA mode uses a single DMA channel. The DMA channel is used for
  33. transmission as the transmit FIFO is smaller than the receive FIFO. it
  34. gives better performance than pure PIO mode but is nowhere near as ideal
  35. as pure DMA mode.
  36. Using the Z85230 driver
  37. =======================
  38. The Z85230 driver provides the back end interface to your board. To
  39. configure a Z8530 interface you need to detect the board and to identify
  40. its ports and interrupt resources. It is also your problem to verify the
  41. resources are available.
  42. Having identified the chip you need to fill in a struct z8530_dev,
  43. which describes each chip. This object must exist until you finally
  44. shutdown the board. Firstly zero the active field. This ensures nothing
  45. goes off without you intending it. The irq field should be set to the
  46. interrupt number of the chip. (Each chip has a single interrupt source
  47. rather than each channel). You are responsible for allocating the
  48. interrupt line. The interrupt handler should be set to
  49. :c:func:`z8530_interrupt()`. The device id should be set to the
  50. z8530_dev structure pointer. Whether the interrupt can be shared or not
  51. is board dependent, and up to you to initialise.
  52. The structure holds two channel structures. Initialise chanA.ctrlio and
  53. chanA.dataio with the address of the control and data ports. You can or
  54. this with Z8530_PORT_SLEEP to indicate your interface needs the 5uS
  55. delay for chip settling done in software. The PORT_SLEEP option is
  56. architecture specific. Other flags may become available on future
  57. platforms, eg for MMIO. Initialise the chanA.irqs to &z8530_nop to
  58. start the chip up as disabled and discarding interrupt events. This
  59. ensures that stray interrupts will be mopped up and not hang the bus.
  60. Set chanA.dev to point to the device structure itself. The private and
  61. name field you may use as you wish. The private field is unused by the
  62. Z85230 layer. The name is used for error reporting and it may thus make
  63. sense to make it match the network name.
  64. Repeat the same operation with the B channel if your chip has both
  65. channels wired to something useful. This isn't always the case. If it is
  66. not wired then the I/O values do not matter, but you must initialise
  67. chanB.dev.
  68. If your board has DMA facilities then initialise the txdma and rxdma
  69. fields for the relevant channels. You must also allocate the ISA DMA
  70. channels and do any necessary board level initialisation to configure
  71. them. The low level driver will do the Z8530 and DMA controller
  72. programming but not board specific magic.
  73. Having initialised the device you can then call
  74. :c:func:`z8530_init()`. This will probe the chip and reset it into
  75. a known state. An identification sequence is then run to identify the
  76. chip type. If the checks fail to pass the function returns a non zero
  77. error code. Typically this indicates that the port given is not valid.
  78. After this call the type field of the z8530_dev structure is
  79. initialised to either Z8530, Z85C30 or Z85230 according to the chip
  80. found.
  81. Once you have called z8530_init you can also make use of the utility
  82. function :c:func:`z8530_describe()`. This provides a consistent
  83. reporting format for the Z8530 devices, and allows all the drivers to
  84. provide consistent reporting.
  85. Attaching Network Interfaces
  86. ============================
  87. If you wish to use the network interface facilities of the driver, then
  88. you need to attach a network device to each channel that is present and
  89. in use. In addition to use the generic HDLC you need to follow some
  90. additional plumbing rules. They may seem complex but a look at the
  91. example hostess_sv11 driver should reassure you.
  92. The network device used for each channel should be pointed to by the
  93. netdevice field of each channel. The hdlc-> priv field of the network
  94. device points to your private data - you will need to be able to find
  95. your private data from this.
  96. The way most drivers approach this particular problem is to create a
  97. structure holding the Z8530 device definition and put that into the
  98. private field of the network device. The network device fields of the
  99. channels then point back to the network devices.
  100. If you wish to use the generic HDLC then you need to register the HDLC
  101. device.
  102. Before you register your network device you will also need to provide
  103. suitable handlers for most of the network device callbacks. See the
  104. network device documentation for more details on this.
  105. Configuring And Activating The Port
  106. ===================================
  107. The Z85230 driver provides helper functions and tables to load the port
  108. registers on the Z8530 chips. When programming the register settings for
  109. a channel be aware that the documentation recommends initialisation
  110. orders. Strange things happen when these are not followed.
  111. :c:func:`z8530_channel_load()` takes an array of pairs of
  112. initialisation values in an array of u8 type. The first value is the
  113. Z8530 register number. Add 16 to indicate the alternate register bank on
  114. the later chips. The array is terminated by a 255.
  115. The driver provides a pair of public tables. The z8530_hdlc_kilostream
  116. table is for the UK 'Kilostream' service and also happens to cover most
  117. other end host configurations. The z8530_hdlc_kilostream_85230 table
  118. is the same configuration using the enhancements of the 85230 chip. The
  119. configuration loaded is standard NRZ encoded synchronous data with HDLC
  120. bitstuffing. All of the timing is taken from the other end of the link.
  121. When writing your own tables be aware that the driver internally tracks
  122. register values. It may need to reload values. You should therefore be
  123. sure to set registers 1-7, 9-11, 14 and 15 in all configurations. Where
  124. the register settings depend on DMA selection the driver will update the
  125. bits itself when you open or close. Loading a new table with the
  126. interface open is not recommended.
  127. There are three standard configurations supported by the core code. In
  128. PIO mode the interface is programmed up to use interrupt driven PIO.
  129. This places high demands on the host processor to avoid latency. The
  130. driver is written to take account of latency issues but it cannot avoid
  131. latencies caused by other drivers, notably IDE in PIO mode. Because the
  132. drivers allocate buffers you must also prevent MTU changes while the
  133. port is open.
  134. Once the port is open it will call the rx_function of each channel
  135. whenever a completed packet arrived. This is invoked from interrupt
  136. context and passes you the channel and a network buffer (struct
  137. sk_buff) holding the data. The data includes the CRC bytes so most
  138. users will want to trim the last two bytes before processing the data.
  139. This function is very timing critical. When you wish to simply discard
  140. data the support code provides the function
  141. :c:func:`z8530_null_rx()` to discard the data.
  142. To active PIO mode sending and receiving the ``z8530_sync_open`` is called.
  143. This expects to be passed the network device and the channel. Typically
  144. this is called from your network device open callback. On a failure a
  145. non zero error status is returned.
  146. The :c:func:`z8530_sync_close()` function shuts down a PIO
  147. channel. This must be done before the channel is opened again and before
  148. the driver shuts down and unloads.
  149. The ideal mode of operation is dual channel DMA mode. Here the kernel
  150. driver will configure the board for DMA in both directions. The driver
  151. also handles ISA DMA issues such as controller programming and the
  152. memory range limit for you. This mode is activated by calling the
  153. :c:func:`z8530_sync_dma_open()` function. On failure a non zero
  154. error value is returned. Once this mode is activated it can be shut down
  155. by calling the :c:func:`z8530_sync_dma_close()`. You must call
  156. the close function matching the open mode you used.
  157. The final supported mode uses a single DMA channel to drive the transmit
  158. side. As the Z85C30 has a larger FIFO on the receive channel this tends
  159. to increase the maximum speed a little. This is activated by calling the
  160. ``z8530_sync_txdma_open``. This returns a non zero error code on failure. The
  161. :c:func:`z8530_sync_txdma_close()` function closes down the Z8530
  162. interface from this mode.
  163. Network Layer Functions
  164. =======================
  165. The Z8530 layer provides functions to queue packets for transmission.
  166. The driver internally buffers the frame currently being transmitted and
  167. one further frame (in order to keep back to back transmission running).
  168. Any further buffering is up to the caller.
  169. The function :c:func:`z8530_queue_xmit()` takes a network buffer
  170. in sk_buff format and queues it for transmission. The caller must
  171. provide the entire packet with the exception of the bitstuffing and CRC.
  172. This is normally done by the caller via the generic HDLC interface
  173. layer. It returns 0 if the buffer has been queued and non zero values
  174. for queue full. If the function accepts the buffer it becomes property
  175. of the Z8530 layer and the caller should not free it.
  176. The function :c:func:`z8530_get_stats()` returns a pointer to an
  177. internally maintained per interface statistics block. This provides most
  178. of the interface code needed to implement the network layer get_stats
  179. callback.
  180. Porting The Z8530 Driver
  181. ========================
  182. The Z8530 driver is written to be portable. In DMA mode it makes
  183. assumptions about the use of ISA DMA. These are probably warranted in
  184. most cases as the Z85230 in particular was designed to glue to PC type
  185. machines. The PIO mode makes no real assumptions.
  186. Should you need to retarget the Z8530 driver to another architecture the
  187. only code that should need changing are the port I/O functions. At the
  188. moment these assume PC I/O port accesses. This may not be appropriate
  189. for all platforms. Replacing :c:func:`z8530_read_port()` and
  190. ``z8530_write_port`` is intended to be all that is required to port
  191. this driver layer.
  192. Known Bugs And Assumptions
  193. ==========================
  194. Interrupt Locking
  195. The locking in the driver is done via the global cli/sti lock. This
  196. makes for relatively poor SMP performance. Switching this to use a
  197. per device spin lock would probably materially improve performance.
  198. Occasional Failures
  199. We have reports of occasional failures when run for very long
  200. periods of time and the driver starts to receive junk frames. At the
  201. moment the cause of this is not clear.
  202. Public Functions Provided
  203. =========================
  204. .. kernel-doc:: drivers/net/wan/z85230.c
  205. :export:
  206. Internal Functions
  207. ==================
  208. .. kernel-doc:: drivers/net/wan/z85230.c
  209. :internal: