z8530book.tmpl 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" []>
  4. <book id="Z85230Guide">
  5. <bookinfo>
  6. <title>Z8530 Programming Guide</title>
  7. <authorgroup>
  8. <author>
  9. <firstname>Alan</firstname>
  10. <surname>Cox</surname>
  11. <affiliation>
  12. <address>
  13. <email>alan@lxorguk.ukuu.org.uk</email>
  14. </address>
  15. </affiliation>
  16. </author>
  17. </authorgroup>
  18. <copyright>
  19. <year>2000</year>
  20. <holder>Alan Cox</holder>
  21. </copyright>
  22. <legalnotice>
  23. <para>
  24. This documentation is free software; you can redistribute
  25. it and/or modify it under the terms of the GNU General Public
  26. License as published by the Free Software Foundation; either
  27. version 2 of the License, or (at your option) any later
  28. version.
  29. </para>
  30. <para>
  31. This program is distributed in the hope that it will be
  32. useful, but WITHOUT ANY WARRANTY; without even the implied
  33. warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  34. See the GNU General Public License for more details.
  35. </para>
  36. <para>
  37. You should have received a copy of the GNU General Public
  38. License along with this program; if not, write to the Free
  39. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  40. MA 02111-1307 USA
  41. </para>
  42. <para>
  43. For more details see the file COPYING in the source
  44. distribution of Linux.
  45. </para>
  46. </legalnotice>
  47. </bookinfo>
  48. <toc></toc>
  49. <chapter id="intro">
  50. <title>Introduction</title>
  51. <para>
  52. The Z85x30 family synchronous/asynchronous controller chips are
  53. used on a large number of cheap network interface cards. The
  54. kernel provides a core interface layer that is designed to make
  55. it easy to provide WAN services using this chip.
  56. </para>
  57. <para>
  58. The current driver only support synchronous operation. Merging the
  59. asynchronous driver support into this code to allow any Z85x30
  60. device to be used as both a tty interface and as a synchronous
  61. controller is a project for Linux post the 2.4 release
  62. </para>
  63. </chapter>
  64. <chapter id="Driver_Modes">
  65. <title>Driver Modes</title>
  66. <para>
  67. The Z85230 driver layer can drive Z8530, Z85C30 and Z85230 devices
  68. in three different modes. Each mode can be applied to an individual
  69. channel on the chip (each chip has two channels).
  70. </para>
  71. <para>
  72. The PIO synchronous mode supports the most common Z8530 wiring. Here
  73. the chip is interface to the I/O and interrupt facilities of the
  74. host machine but not to the DMA subsystem. When running PIO the
  75. Z8530 has extremely tight timing requirements. Doing high speeds,
  76. even with a Z85230 will be tricky. Typically you should expect to
  77. achieve at best 9600 baud with a Z8C530 and 64Kbits with a Z85230.
  78. </para>
  79. <para>
  80. The DMA mode supports the chip when it is configured to use dual DMA
  81. channels on an ISA bus. The better cards tend to support this mode
  82. of operation for a single channel. With DMA running the Z85230 tops
  83. out when it starts to hit ISA DMA constraints at about 512Kbits. It
  84. is worth noting here that many PC machines hang or crash when the
  85. chip is driven fast enough to hold the ISA bus solid.
  86. </para>
  87. <para>
  88. Transmit DMA mode uses a single DMA channel. The DMA channel is used
  89. for transmission as the transmit FIFO is smaller than the receive
  90. FIFO. it gives better performance than pure PIO mode but is nowhere
  91. near as ideal as pure DMA mode.
  92. </para>
  93. </chapter>
  94. <chapter id="Using_the_Z85230_driver">
  95. <title>Using the Z85230 driver</title>
  96. <para>
  97. The Z85230 driver provides the back end interface to your board. To
  98. configure a Z8530 interface you need to detect the board and to
  99. identify its ports and interrupt resources. It is also your problem
  100. to verify the resources are available.
  101. </para>
  102. <para>
  103. Having identified the chip you need to fill in a struct z8530_dev,
  104. which describes each chip. This object must exist until you finally
  105. shutdown the board. Firstly zero the active field. This ensures
  106. nothing goes off without you intending it. The irq field should
  107. be set to the interrupt number of the chip. (Each chip has a single
  108. interrupt source rather than each channel). You are responsible
  109. for allocating the interrupt line. The interrupt handler should be
  110. set to <function>z8530_interrupt</function>. The device id should
  111. be set to the z8530_dev structure pointer. Whether the interrupt can
  112. be shared or not is board dependent, and up to you to initialise.
  113. </para>
  114. <para>
  115. The structure holds two channel structures.
  116. Initialise chanA.ctrlio and chanA.dataio with the address of the
  117. control and data ports. You can or this with Z8530_PORT_SLEEP to
  118. indicate your interface needs the 5uS delay for chip settling done
  119. in software. The PORT_SLEEP option is architecture specific. Other
  120. flags may become available on future platforms, eg for MMIO.
  121. Initialise the chanA.irqs to &amp;z8530_nop to start the chip up
  122. as disabled and discarding interrupt events. This ensures that
  123. stray interrupts will be mopped up and not hang the bus. Set
  124. chanA.dev to point to the device structure itself. The
  125. private and name field you may use as you wish. The private field
  126. is unused by the Z85230 layer. The name is used for error reporting
  127. and it may thus make sense to make it match the network name.
  128. </para>
  129. <para>
  130. Repeat the same operation with the B channel if your chip has
  131. both channels wired to something useful. This isn't always the
  132. case. If it is not wired then the I/O values do not matter, but
  133. you must initialise chanB.dev.
  134. </para>
  135. <para>
  136. If your board has DMA facilities then initialise the txdma and
  137. rxdma fields for the relevant channels. You must also allocate the
  138. ISA DMA channels and do any necessary board level initialisation
  139. to configure them. The low level driver will do the Z8530 and
  140. DMA controller programming but not board specific magic.
  141. </para>
  142. <para>
  143. Having initialised the device you can then call
  144. <function>z8530_init</function>. This will probe the chip and
  145. reset it into a known state. An identification sequence is then
  146. run to identify the chip type. If the checks fail to pass the
  147. function returns a non zero error code. Typically this indicates
  148. that the port given is not valid. After this call the
  149. type field of the z8530_dev structure is initialised to either
  150. Z8530, Z85C30 or Z85230 according to the chip found.
  151. </para>
  152. <para>
  153. Once you have called z8530_init you can also make use of the utility
  154. function <function>z8530_describe</function>. This provides a
  155. consistent reporting format for the Z8530 devices, and allows all
  156. the drivers to provide consistent reporting.
  157. </para>
  158. </chapter>
  159. <chapter id="Attaching_Network_Interfaces">
  160. <title>Attaching Network Interfaces</title>
  161. <para>
  162. If you wish to use the network interface facilities of the driver,
  163. then you need to attach a network device to each channel that is
  164. present and in use. In addition to use the generic HDLC
  165. you need to follow some additional plumbing rules. They may seem
  166. complex but a look at the example hostess_sv11 driver should
  167. reassure you.
  168. </para>
  169. <para>
  170. The network device used for each channel should be pointed to by
  171. the netdevice field of each channel. The hdlc-&gt; priv field of the
  172. network device points to your private data - you will need to be
  173. able to find your private data from this.
  174. </para>
  175. <para>
  176. The way most drivers approach this particular problem is to
  177. create a structure holding the Z8530 device definition and
  178. put that into the private field of the network device. The
  179. network device fields of the channels then point back to the
  180. network devices.
  181. </para>
  182. <para>
  183. If you wish to use the generic HDLC then you need to register
  184. the HDLC device.
  185. </para>
  186. <para>
  187. Before you register your network device you will also need to
  188. provide suitable handlers for most of the network device callbacks.
  189. See the network device documentation for more details on this.
  190. </para>
  191. </chapter>
  192. <chapter id="Configuring_And_Activating_The_Port">
  193. <title>Configuring And Activating The Port</title>
  194. <para>
  195. The Z85230 driver provides helper functions and tables to load the
  196. port registers on the Z8530 chips. When programming the register
  197. settings for a channel be aware that the documentation recommends
  198. initialisation orders. Strange things happen when these are not
  199. followed.
  200. </para>
  201. <para>
  202. <function>z8530_channel_load</function> takes an array of
  203. pairs of initialisation values in an array of u8 type. The first
  204. value is the Z8530 register number. Add 16 to indicate the alternate
  205. register bank on the later chips. The array is terminated by a 255.
  206. </para>
  207. <para>
  208. The driver provides a pair of public tables. The
  209. z8530_hdlc_kilostream table is for the UK 'Kilostream' service and
  210. also happens to cover most other end host configurations. The
  211. z8530_hdlc_kilostream_85230 table is the same configuration using
  212. the enhancements of the 85230 chip. The configuration loaded is
  213. standard NRZ encoded synchronous data with HDLC bitstuffing. All
  214. of the timing is taken from the other end of the link.
  215. </para>
  216. <para>
  217. When writing your own tables be aware that the driver internally
  218. tracks register values. It may need to reload values. You should
  219. therefore be sure to set registers 1-7, 9-11, 14 and 15 in all
  220. configurations. Where the register settings depend on DMA selection
  221. the driver will update the bits itself when you open or close.
  222. Loading a new table with the interface open is not recommended.
  223. </para>
  224. <para>
  225. There are three standard configurations supported by the core
  226. code. In PIO mode the interface is programmed up to use
  227. interrupt driven PIO. This places high demands on the host processor
  228. to avoid latency. The driver is written to take account of latency
  229. issues but it cannot avoid latencies caused by other drivers,
  230. notably IDE in PIO mode. Because the drivers allocate buffers you
  231. must also prevent MTU changes while the port is open.
  232. </para>
  233. <para>
  234. Once the port is open it will call the rx_function of each channel
  235. whenever a completed packet arrived. This is invoked from
  236. interrupt context and passes you the channel and a network
  237. buffer (struct sk_buff) holding the data. The data includes
  238. the CRC bytes so most users will want to trim the last two
  239. bytes before processing the data. This function is very timing
  240. critical. When you wish to simply discard data the support
  241. code provides the function <function>z8530_null_rx</function>
  242. to discard the data.
  243. </para>
  244. <para>
  245. To active PIO mode sending and receiving the <function>
  246. z8530_sync_open</function> is called. This expects to be passed
  247. the network device and the channel. Typically this is called from
  248. your network device open callback. On a failure a non zero error
  249. status is returned. The <function>z8530_sync_close</function>
  250. function shuts down a PIO channel. This must be done before the
  251. channel is opened again and before the driver shuts down
  252. and unloads.
  253. </para>
  254. <para>
  255. The ideal mode of operation is dual channel DMA mode. Here the
  256. kernel driver will configure the board for DMA in both directions.
  257. The driver also handles ISA DMA issues such as controller
  258. programming and the memory range limit for you. This mode is
  259. activated by calling the <function>z8530_sync_dma_open</function>
  260. function. On failure a non zero error value is returned.
  261. Once this mode is activated it can be shut down by calling the
  262. <function>z8530_sync_dma_close</function>. You must call the close
  263. function matching the open mode you used.
  264. </para>
  265. <para>
  266. The final supported mode uses a single DMA channel to drive the
  267. transmit side. As the Z85C30 has a larger FIFO on the receive
  268. channel this tends to increase the maximum speed a little.
  269. This is activated by calling the <function>z8530_sync_txdma_open
  270. </function>. This returns a non zero error code on failure. The
  271. <function>z8530_sync_txdma_close</function> function closes down
  272. the Z8530 interface from this mode.
  273. </para>
  274. </chapter>
  275. <chapter id="Network_Layer_Functions">
  276. <title>Network Layer Functions</title>
  277. <para>
  278. The Z8530 layer provides functions to queue packets for
  279. transmission. The driver internally buffers the frame currently
  280. being transmitted and one further frame (in order to keep back
  281. to back transmission running). Any further buffering is up to
  282. the caller.
  283. </para>
  284. <para>
  285. The function <function>z8530_queue_xmit</function> takes a network
  286. buffer in sk_buff format and queues it for transmission. The
  287. caller must provide the entire packet with the exception of the
  288. bitstuffing and CRC. This is normally done by the caller via
  289. the generic HDLC interface layer. It returns 0 if the buffer has been
  290. queued and non zero values for queue full. If the function accepts
  291. the buffer it becomes property of the Z8530 layer and the caller
  292. should not free it.
  293. </para>
  294. <para>
  295. The function <function>z8530_get_stats</function> returns a pointer
  296. to an internally maintained per interface statistics block. This
  297. provides most of the interface code needed to implement the network
  298. layer get_stats callback.
  299. </para>
  300. </chapter>
  301. <chapter id="Porting_The_Z8530_Driver">
  302. <title>Porting The Z8530 Driver</title>
  303. <para>
  304. The Z8530 driver is written to be portable. In DMA mode it makes
  305. assumptions about the use of ISA DMA. These are probably warranted
  306. in most cases as the Z85230 in particular was designed to glue to PC
  307. type machines. The PIO mode makes no real assumptions.
  308. </para>
  309. <para>
  310. Should you need to retarget the Z8530 driver to another architecture
  311. the only code that should need changing are the port I/O functions.
  312. At the moment these assume PC I/O port accesses. This may not be
  313. appropriate for all platforms. Replacing
  314. <function>z8530_read_port</function> and <function>z8530_write_port
  315. </function> is intended to be all that is required to port this
  316. driver layer.
  317. </para>
  318. </chapter>
  319. <chapter id="bugs">
  320. <title>Known Bugs And Assumptions</title>
  321. <para>
  322. <variablelist>
  323. <varlistentry><term>Interrupt Locking</term>
  324. <listitem>
  325. <para>
  326. The locking in the driver is done via the global cli/sti lock. This
  327. makes for relatively poor SMP performance. Switching this to use a
  328. per device spin lock would probably materially improve performance.
  329. </para>
  330. </listitem></varlistentry>
  331. <varlistentry><term>Occasional Failures</term>
  332. <listitem>
  333. <para>
  334. We have reports of occasional failures when run for very long
  335. periods of time and the driver starts to receive junk frames. At
  336. the moment the cause of this is not clear.
  337. </para>
  338. </listitem></varlistentry>
  339. </variablelist>
  340. </para>
  341. </chapter>
  342. <chapter id="pubfunctions">
  343. <title>Public Functions Provided</title>
  344. !Edrivers/net/wan/z85230.c
  345. </chapter>
  346. <chapter id="intfunctions">
  347. <title>Internal Functions</title>
  348. !Idrivers/net/wan/z85230.c
  349. </chapter>
  350. </book>