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