18c2ecf20Sopenharmony_ci======================= 28c2ecf20Sopenharmony_ciZ8530 Programming Guide 38c2ecf20Sopenharmony_ci======================= 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci:Author: Alan Cox 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ciIntroduction 88c2ecf20Sopenharmony_ci============ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ciThe Z85x30 family synchronous/asynchronous controller chips are used on 118c2ecf20Sopenharmony_cia large number of cheap network interface cards. The kernel provides a 128c2ecf20Sopenharmony_cicore interface layer that is designed to make it easy to provide WAN 138c2ecf20Sopenharmony_ciservices using this chip. 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ciThe current driver only support synchronous operation. Merging the 168c2ecf20Sopenharmony_ciasynchronous driver support into this code to allow any Z85x30 device to 178c2ecf20Sopenharmony_cibe used as both a tty interface and as a synchronous controller is a 188c2ecf20Sopenharmony_ciproject for Linux post the 2.4 release 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ciDriver Modes 218c2ecf20Sopenharmony_ci============ 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ciThe Z85230 driver layer can drive Z8530, Z85C30 and Z85230 devices in 248c2ecf20Sopenharmony_cithree different modes. Each mode can be applied to an individual channel 258c2ecf20Sopenharmony_cion the chip (each chip has two channels). 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ciThe PIO synchronous mode supports the most common Z8530 wiring. Here the 288c2ecf20Sopenharmony_cichip is interface to the I/O and interrupt facilities of the host 298c2ecf20Sopenharmony_cimachine but not to the DMA subsystem. When running PIO the Z8530 has 308c2ecf20Sopenharmony_ciextremely tight timing requirements. Doing high speeds, even with a 318c2ecf20Sopenharmony_ciZ85230 will be tricky. Typically you should expect to achieve at best 328c2ecf20Sopenharmony_ci9600 baud with a Z8C530 and 64Kbits with a Z85230. 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ciThe DMA mode supports the chip when it is configured to use dual DMA 358c2ecf20Sopenharmony_cichannels on an ISA bus. The better cards tend to support this mode of 368c2ecf20Sopenharmony_cioperation for a single channel. With DMA running the Z85230 tops out 378c2ecf20Sopenharmony_ciwhen it starts to hit ISA DMA constraints at about 512Kbits. It is worth 388c2ecf20Sopenharmony_cinoting here that many PC machines hang or crash when the chip is driven 398c2ecf20Sopenharmony_cifast enough to hold the ISA bus solid. 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ciTransmit DMA mode uses a single DMA channel. The DMA channel is used for 428c2ecf20Sopenharmony_citransmission as the transmit FIFO is smaller than the receive FIFO. it 438c2ecf20Sopenharmony_cigives better performance than pure PIO mode but is nowhere near as ideal 448c2ecf20Sopenharmony_cias pure DMA mode. 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ciUsing the Z85230 driver 478c2ecf20Sopenharmony_ci======================= 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ciThe Z85230 driver provides the back end interface to your board. To 508c2ecf20Sopenharmony_ciconfigure a Z8530 interface you need to detect the board and to identify 518c2ecf20Sopenharmony_ciits ports and interrupt resources. It is also your problem to verify the 528c2ecf20Sopenharmony_ciresources are available. 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ciHaving identified the chip you need to fill in a struct z8530_dev, 558c2ecf20Sopenharmony_ciwhich describes each chip. This object must exist until you finally 568c2ecf20Sopenharmony_cishutdown the board. Firstly zero the active field. This ensures nothing 578c2ecf20Sopenharmony_cigoes off without you intending it. The irq field should be set to the 588c2ecf20Sopenharmony_ciinterrupt number of the chip. (Each chip has a single interrupt source 598c2ecf20Sopenharmony_cirather than each channel). You are responsible for allocating the 608c2ecf20Sopenharmony_ciinterrupt line. The interrupt handler should be set to 618c2ecf20Sopenharmony_ci:c:func:`z8530_interrupt()`. The device id should be set to the 628c2ecf20Sopenharmony_ciz8530_dev structure pointer. Whether the interrupt can be shared or not 638c2ecf20Sopenharmony_ciis board dependent, and up to you to initialise. 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ciThe structure holds two channel structures. Initialise chanA.ctrlio and 668c2ecf20Sopenharmony_cichanA.dataio with the address of the control and data ports. You can or 678c2ecf20Sopenharmony_cithis with Z8530_PORT_SLEEP to indicate your interface needs the 5uS 688c2ecf20Sopenharmony_cidelay for chip settling done in software. The PORT_SLEEP option is 698c2ecf20Sopenharmony_ciarchitecture specific. Other flags may become available on future 708c2ecf20Sopenharmony_ciplatforms, eg for MMIO. Initialise the chanA.irqs to &z8530_nop to 718c2ecf20Sopenharmony_cistart the chip up as disabled and discarding interrupt events. This 728c2ecf20Sopenharmony_ciensures that stray interrupts will be mopped up and not hang the bus. 738c2ecf20Sopenharmony_ciSet chanA.dev to point to the device structure itself. The private and 748c2ecf20Sopenharmony_ciname field you may use as you wish. The private field is unused by the 758c2ecf20Sopenharmony_ciZ85230 layer. The name is used for error reporting and it may thus make 768c2ecf20Sopenharmony_cisense to make it match the network name. 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ciRepeat the same operation with the B channel if your chip has both 798c2ecf20Sopenharmony_cichannels wired to something useful. This isn't always the case. If it is 808c2ecf20Sopenharmony_cinot wired then the I/O values do not matter, but you must initialise 818c2ecf20Sopenharmony_cichanB.dev. 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ciIf your board has DMA facilities then initialise the txdma and rxdma 848c2ecf20Sopenharmony_cifields for the relevant channels. You must also allocate the ISA DMA 858c2ecf20Sopenharmony_cichannels and do any necessary board level initialisation to configure 868c2ecf20Sopenharmony_cithem. The low level driver will do the Z8530 and DMA controller 878c2ecf20Sopenharmony_ciprogramming but not board specific magic. 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ciHaving initialised the device you can then call 908c2ecf20Sopenharmony_ci:c:func:`z8530_init()`. This will probe the chip and reset it into 918c2ecf20Sopenharmony_cia known state. An identification sequence is then run to identify the 928c2ecf20Sopenharmony_cichip type. If the checks fail to pass the function returns a non zero 938c2ecf20Sopenharmony_cierror code. Typically this indicates that the port given is not valid. 948c2ecf20Sopenharmony_ciAfter this call the type field of the z8530_dev structure is 958c2ecf20Sopenharmony_ciinitialised to either Z8530, Z85C30 or Z85230 according to the chip 968c2ecf20Sopenharmony_cifound. 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ciOnce you have called z8530_init you can also make use of the utility 998c2ecf20Sopenharmony_cifunction :c:func:`z8530_describe()`. This provides a consistent 1008c2ecf20Sopenharmony_cireporting format for the Z8530 devices, and allows all the drivers to 1018c2ecf20Sopenharmony_ciprovide consistent reporting. 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ciAttaching Network Interfaces 1048c2ecf20Sopenharmony_ci============================ 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ciIf you wish to use the network interface facilities of the driver, then 1078c2ecf20Sopenharmony_ciyou need to attach a network device to each channel that is present and 1088c2ecf20Sopenharmony_ciin use. In addition to use the generic HDLC you need to follow some 1098c2ecf20Sopenharmony_ciadditional plumbing rules. They may seem complex but a look at the 1108c2ecf20Sopenharmony_ciexample hostess_sv11 driver should reassure you. 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ciThe network device used for each channel should be pointed to by the 1138c2ecf20Sopenharmony_cinetdevice field of each channel. The hdlc-> priv field of the network 1148c2ecf20Sopenharmony_cidevice points to your private data - you will need to be able to find 1158c2ecf20Sopenharmony_ciyour private data from this. 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ciThe way most drivers approach this particular problem is to create a 1188c2ecf20Sopenharmony_cistructure holding the Z8530 device definition and put that into the 1198c2ecf20Sopenharmony_ciprivate field of the network device. The network device fields of the 1208c2ecf20Sopenharmony_cichannels then point back to the network devices. 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ciIf you wish to use the generic HDLC then you need to register the HDLC 1238c2ecf20Sopenharmony_cidevice. 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ciBefore you register your network device you will also need to provide 1268c2ecf20Sopenharmony_cisuitable handlers for most of the network device callbacks. See the 1278c2ecf20Sopenharmony_cinetwork device documentation for more details on this. 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ciConfiguring And Activating The Port 1308c2ecf20Sopenharmony_ci=================================== 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ciThe Z85230 driver provides helper functions and tables to load the port 1338c2ecf20Sopenharmony_ciregisters on the Z8530 chips. When programming the register settings for 1348c2ecf20Sopenharmony_cia channel be aware that the documentation recommends initialisation 1358c2ecf20Sopenharmony_ciorders. Strange things happen when these are not followed. 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ci:c:func:`z8530_channel_load()` takes an array of pairs of 1388c2ecf20Sopenharmony_ciinitialisation values in an array of u8 type. The first value is the 1398c2ecf20Sopenharmony_ciZ8530 register number. Add 16 to indicate the alternate register bank on 1408c2ecf20Sopenharmony_cithe later chips. The array is terminated by a 255. 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ciThe driver provides a pair of public tables. The z8530_hdlc_kilostream 1438c2ecf20Sopenharmony_citable is for the UK 'Kilostream' service and also happens to cover most 1448c2ecf20Sopenharmony_ciother end host configurations. The z8530_hdlc_kilostream_85230 table 1458c2ecf20Sopenharmony_ciis the same configuration using the enhancements of the 85230 chip. The 1468c2ecf20Sopenharmony_ciconfiguration loaded is standard NRZ encoded synchronous data with HDLC 1478c2ecf20Sopenharmony_cibitstuffing. All of the timing is taken from the other end of the link. 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_ciWhen writing your own tables be aware that the driver internally tracks 1508c2ecf20Sopenharmony_ciregister values. It may need to reload values. You should therefore be 1518c2ecf20Sopenharmony_cisure to set registers 1-7, 9-11, 14 and 15 in all configurations. Where 1528c2ecf20Sopenharmony_cithe register settings depend on DMA selection the driver will update the 1538c2ecf20Sopenharmony_cibits itself when you open or close. Loading a new table with the 1548c2ecf20Sopenharmony_ciinterface open is not recommended. 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_ciThere are three standard configurations supported by the core code. In 1578c2ecf20Sopenharmony_ciPIO mode the interface is programmed up to use interrupt driven PIO. 1588c2ecf20Sopenharmony_ciThis places high demands on the host processor to avoid latency. The 1598c2ecf20Sopenharmony_cidriver is written to take account of latency issues but it cannot avoid 1608c2ecf20Sopenharmony_cilatencies caused by other drivers, notably IDE in PIO mode. Because the 1618c2ecf20Sopenharmony_cidrivers allocate buffers you must also prevent MTU changes while the 1628c2ecf20Sopenharmony_ciport is open. 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ciOnce the port is open it will call the rx_function of each channel 1658c2ecf20Sopenharmony_ciwhenever a completed packet arrived. This is invoked from interrupt 1668c2ecf20Sopenharmony_cicontext and passes you the channel and a network buffer (struct 1678c2ecf20Sopenharmony_cisk_buff) holding the data. The data includes the CRC bytes so most 1688c2ecf20Sopenharmony_ciusers will want to trim the last two bytes before processing the data. 1698c2ecf20Sopenharmony_ciThis function is very timing critical. When you wish to simply discard 1708c2ecf20Sopenharmony_cidata the support code provides the function 1718c2ecf20Sopenharmony_ci:c:func:`z8530_null_rx()` to discard the data. 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_ciTo active PIO mode sending and receiving the ``z8530_sync_open`` is called. 1748c2ecf20Sopenharmony_ciThis expects to be passed the network device and the channel. Typically 1758c2ecf20Sopenharmony_cithis is called from your network device open callback. On a failure a 1768c2ecf20Sopenharmony_cinon zero error status is returned. 1778c2ecf20Sopenharmony_ciThe :c:func:`z8530_sync_close()` function shuts down a PIO 1788c2ecf20Sopenharmony_cichannel. This must be done before the channel is opened again and before 1798c2ecf20Sopenharmony_cithe driver shuts down and unloads. 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_ciThe ideal mode of operation is dual channel DMA mode. Here the kernel 1828c2ecf20Sopenharmony_cidriver will configure the board for DMA in both directions. The driver 1838c2ecf20Sopenharmony_cialso handles ISA DMA issues such as controller programming and the 1848c2ecf20Sopenharmony_cimemory range limit for you. This mode is activated by calling the 1858c2ecf20Sopenharmony_ci:c:func:`z8530_sync_dma_open()` function. On failure a non zero 1868c2ecf20Sopenharmony_cierror value is returned. Once this mode is activated it can be shut down 1878c2ecf20Sopenharmony_ciby calling the :c:func:`z8530_sync_dma_close()`. You must call 1888c2ecf20Sopenharmony_cithe close function matching the open mode you used. 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_ciThe final supported mode uses a single DMA channel to drive the transmit 1918c2ecf20Sopenharmony_ciside. As the Z85C30 has a larger FIFO on the receive channel this tends 1928c2ecf20Sopenharmony_cito increase the maximum speed a little. This is activated by calling the 1938c2ecf20Sopenharmony_ci``z8530_sync_txdma_open``. This returns a non zero error code on failure. The 1948c2ecf20Sopenharmony_ci:c:func:`z8530_sync_txdma_close()` function closes down the Z8530 1958c2ecf20Sopenharmony_ciinterface from this mode. 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ciNetwork Layer Functions 1988c2ecf20Sopenharmony_ci======================= 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ciThe Z8530 layer provides functions to queue packets for transmission. 2018c2ecf20Sopenharmony_ciThe driver internally buffers the frame currently being transmitted and 2028c2ecf20Sopenharmony_cione further frame (in order to keep back to back transmission running). 2038c2ecf20Sopenharmony_ciAny further buffering is up to the caller. 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_ciThe function :c:func:`z8530_queue_xmit()` takes a network buffer 2068c2ecf20Sopenharmony_ciin sk_buff format and queues it for transmission. The caller must 2078c2ecf20Sopenharmony_ciprovide the entire packet with the exception of the bitstuffing and CRC. 2088c2ecf20Sopenharmony_ciThis is normally done by the caller via the generic HDLC interface 2098c2ecf20Sopenharmony_cilayer. It returns 0 if the buffer has been queued and non zero values 2108c2ecf20Sopenharmony_cifor queue full. If the function accepts the buffer it becomes property 2118c2ecf20Sopenharmony_ciof the Z8530 layer and the caller should not free it. 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_ciThe function :c:func:`z8530_get_stats()` returns a pointer to an 2148c2ecf20Sopenharmony_ciinternally maintained per interface statistics block. This provides most 2158c2ecf20Sopenharmony_ciof the interface code needed to implement the network layer get_stats 2168c2ecf20Sopenharmony_cicallback. 2178c2ecf20Sopenharmony_ci 2188c2ecf20Sopenharmony_ciPorting The Z8530 Driver 2198c2ecf20Sopenharmony_ci======================== 2208c2ecf20Sopenharmony_ci 2218c2ecf20Sopenharmony_ciThe Z8530 driver is written to be portable. In DMA mode it makes 2228c2ecf20Sopenharmony_ciassumptions about the use of ISA DMA. These are probably warranted in 2238c2ecf20Sopenharmony_cimost cases as the Z85230 in particular was designed to glue to PC type 2248c2ecf20Sopenharmony_cimachines. The PIO mode makes no real assumptions. 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_ciShould you need to retarget the Z8530 driver to another architecture the 2278c2ecf20Sopenharmony_cionly code that should need changing are the port I/O functions. At the 2288c2ecf20Sopenharmony_cimoment these assume PC I/O port accesses. This may not be appropriate 2298c2ecf20Sopenharmony_cifor all platforms. Replacing :c:func:`z8530_read_port()` and 2308c2ecf20Sopenharmony_ci``z8530_write_port`` is intended to be all that is required to port 2318c2ecf20Sopenharmony_cithis driver layer. 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_ciKnown Bugs And Assumptions 2348c2ecf20Sopenharmony_ci========================== 2358c2ecf20Sopenharmony_ci 2368c2ecf20Sopenharmony_ciInterrupt Locking 2378c2ecf20Sopenharmony_ci The locking in the driver is done via the global cli/sti lock. This 2388c2ecf20Sopenharmony_ci makes for relatively poor SMP performance. Switching this to use a 2398c2ecf20Sopenharmony_ci per device spin lock would probably materially improve performance. 2408c2ecf20Sopenharmony_ci 2418c2ecf20Sopenharmony_ciOccasional Failures 2428c2ecf20Sopenharmony_ci We have reports of occasional failures when run for very long 2438c2ecf20Sopenharmony_ci periods of time and the driver starts to receive junk frames. At the 2448c2ecf20Sopenharmony_ci moment the cause of this is not clear. 2458c2ecf20Sopenharmony_ci 2468c2ecf20Sopenharmony_ciPublic Functions Provided 2478c2ecf20Sopenharmony_ci========================= 2488c2ecf20Sopenharmony_ci 2498c2ecf20Sopenharmony_ci.. kernel-doc:: drivers/net/wan/z85230.c 2508c2ecf20Sopenharmony_ci :export: 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_ciInternal Functions 2538c2ecf20Sopenharmony_ci================== 2548c2ecf20Sopenharmony_ci 2558c2ecf20Sopenharmony_ci.. kernel-doc:: drivers/net/wan/z85230.c 2568c2ecf20Sopenharmony_ci :internal: 257