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