Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: wan: remove support for Z85230-based devices

Looks like all the changes to this driver had been automated
churn since git era begun. The driver is using virt_to_bus(),
it's just a maintenance burden unlikely to have any users.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Jakub Kicinski and committed by
David S. Miller
bc6df26f 89fbca33

-3035
-1
Documentation/networking/device_drivers/index.rst
··· 17 17 fddi/index 18 18 hamradio/index 19 19 qlogic/index 20 - wan/index 21 20 wifi/index 22 21 wwan/index 23 22
-18
Documentation/networking/device_drivers/wan/index.rst
··· 1 - .. SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 - 3 - Classic WAN Device Drivers 4 - ========================== 5 - 6 - Contents: 7 - 8 - .. toctree:: 9 - :maxdepth: 2 10 - 11 - z8530book 12 - 13 - .. only:: subproject and html 14 - 15 - Indices 16 - ======= 17 - 18 - * :ref:`genindex`
-256
Documentation/networking/device_drivers/wan/z8530book.rst
··· 1 - ======================= 2 - Z8530 Programming Guide 3 - ======================= 4 - 5 - :Author: Alan Cox 6 - 7 - Introduction 8 - ============ 9 - 10 - The Z85x30 family synchronous/asynchronous controller chips are used on 11 - a large number of cheap network interface cards. The kernel provides a 12 - core interface layer that is designed to make it easy to provide WAN 13 - services using this chip. 14 - 15 - The current driver only support synchronous operation. Merging the 16 - asynchronous driver support into this code to allow any Z85x30 device to 17 - be used as both a tty interface and as a synchronous controller is a 18 - project for Linux post the 2.4 release 19 - 20 - Driver Modes 21 - ============ 22 - 23 - The Z85230 driver layer can drive Z8530, Z85C30 and Z85230 devices in 24 - three different modes. Each mode can be applied to an individual channel 25 - on the chip (each chip has two channels). 26 - 27 - The PIO synchronous mode supports the most common Z8530 wiring. Here the 28 - chip is interface to the I/O and interrupt facilities of the host 29 - machine but not to the DMA subsystem. When running PIO the Z8530 has 30 - extremely tight timing requirements. Doing high speeds, even with a 31 - Z85230 will be tricky. Typically you should expect to achieve at best 32 - 9600 baud with a Z8C530 and 64Kbits with a Z85230. 33 - 34 - The DMA mode supports the chip when it is configured to use dual DMA 35 - channels on an ISA bus. The better cards tend to support this mode of 36 - operation for a single channel. With DMA running the Z85230 tops out 37 - when it starts to hit ISA DMA constraints at about 512Kbits. It is worth 38 - noting here that many PC machines hang or crash when the chip is driven 39 - fast enough to hold the ISA bus solid. 40 - 41 - Transmit DMA mode uses a single DMA channel. The DMA channel is used for 42 - transmission as the transmit FIFO is smaller than the receive FIFO. it 43 - gives better performance than pure PIO mode but is nowhere near as ideal 44 - as pure DMA mode. 45 - 46 - Using the Z85230 driver 47 - ======================= 48 - 49 - The Z85230 driver provides the back end interface to your board. To 50 - configure a Z8530 interface you need to detect the board and to identify 51 - its ports and interrupt resources. It is also your problem to verify the 52 - resources are available. 53 - 54 - Having identified the chip you need to fill in a struct z8530_dev, 55 - which describes each chip. This object must exist until you finally 56 - shutdown the board. Firstly zero the active field. This ensures nothing 57 - goes off without you intending it. The irq field should be set to the 58 - interrupt number of the chip. (Each chip has a single interrupt source 59 - rather than each channel). You are responsible for allocating the 60 - interrupt line. The interrupt handler should be set to 61 - :c:func:`z8530_interrupt()`. The device id should be set to the 62 - z8530_dev structure pointer. Whether the interrupt can be shared or not 63 - is board dependent, and up to you to initialise. 64 - 65 - The structure holds two channel structures. Initialise chanA.ctrlio and 66 - chanA.dataio with the address of the control and data ports. You can or 67 - this with Z8530_PORT_SLEEP to indicate your interface needs the 5uS 68 - delay for chip settling done in software. The PORT_SLEEP option is 69 - architecture specific. Other flags may become available on future 70 - platforms, eg for MMIO. Initialise the chanA.irqs to &z8530_nop to 71 - start the chip up as disabled and discarding interrupt events. This 72 - ensures that stray interrupts will be mopped up and not hang the bus. 73 - Set chanA.dev to point to the device structure itself. The private and 74 - name field you may use as you wish. The private field is unused by the 75 - Z85230 layer. The name is used for error reporting and it may thus make 76 - sense to make it match the network name. 77 - 78 - Repeat the same operation with the B channel if your chip has both 79 - channels wired to something useful. This isn't always the case. If it is 80 - not wired then the I/O values do not matter, but you must initialise 81 - chanB.dev. 82 - 83 - If your board has DMA facilities then initialise the txdma and rxdma 84 - fields for the relevant channels. You must also allocate the ISA DMA 85 - channels and do any necessary board level initialisation to configure 86 - them. The low level driver will do the Z8530 and DMA controller 87 - programming but not board specific magic. 88 - 89 - Having initialised the device you can then call 90 - :c:func:`z8530_init()`. This will probe the chip and reset it into 91 - a known state. An identification sequence is then run to identify the 92 - chip type. If the checks fail to pass the function returns a non zero 93 - error code. Typically this indicates that the port given is not valid. 94 - After this call the type field of the z8530_dev structure is 95 - initialised to either Z8530, Z85C30 or Z85230 according to the chip 96 - found. 97 - 98 - Once you have called z8530_init you can also make use of the utility 99 - function :c:func:`z8530_describe()`. This provides a consistent 100 - reporting format for the Z8530 devices, and allows all the drivers to 101 - provide consistent reporting. 102 - 103 - Attaching Network Interfaces 104 - ============================ 105 - 106 - If you wish to use the network interface facilities of the driver, then 107 - you need to attach a network device to each channel that is present and 108 - in use. In addition to use the generic HDLC you need to follow some 109 - additional plumbing rules. They may seem complex but a look at the 110 - example hostess_sv11 driver should reassure you. 111 - 112 - The network device used for each channel should be pointed to by the 113 - netdevice field of each channel. The hdlc-> priv field of the network 114 - device points to your private data - you will need to be able to find 115 - your private data from this. 116 - 117 - The way most drivers approach this particular problem is to create a 118 - structure holding the Z8530 device definition and put that into the 119 - private field of the network device. The network device fields of the 120 - channels then point back to the network devices. 121 - 122 - If you wish to use the generic HDLC then you need to register the HDLC 123 - device. 124 - 125 - Before you register your network device you will also need to provide 126 - suitable handlers for most of the network device callbacks. See the 127 - network device documentation for more details on this. 128 - 129 - Configuring And Activating The Port 130 - =================================== 131 - 132 - The Z85230 driver provides helper functions and tables to load the port 133 - registers on the Z8530 chips. When programming the register settings for 134 - a channel be aware that the documentation recommends initialisation 135 - orders. Strange things happen when these are not followed. 136 - 137 - :c:func:`z8530_channel_load()` takes an array of pairs of 138 - initialisation values in an array of u8 type. The first value is the 139 - Z8530 register number. Add 16 to indicate the alternate register bank on 140 - the later chips. The array is terminated by a 255. 141 - 142 - The driver provides a pair of public tables. The z8530_hdlc_kilostream 143 - table is for the UK 'Kilostream' service and also happens to cover most 144 - other end host configurations. The z8530_hdlc_kilostream_85230 table 145 - is the same configuration using the enhancements of the 85230 chip. The 146 - configuration loaded is standard NRZ encoded synchronous data with HDLC 147 - bitstuffing. All of the timing is taken from the other end of the link. 148 - 149 - When writing your own tables be aware that the driver internally tracks 150 - register values. It may need to reload values. You should therefore be 151 - sure to set registers 1-7, 9-11, 14 and 15 in all configurations. Where 152 - the register settings depend on DMA selection the driver will update the 153 - bits itself when you open or close. Loading a new table with the 154 - interface open is not recommended. 155 - 156 - There are three standard configurations supported by the core code. In 157 - PIO mode the interface is programmed up to use interrupt driven PIO. 158 - This places high demands on the host processor to avoid latency. The 159 - driver is written to take account of latency issues but it cannot avoid 160 - latencies caused by other drivers, notably IDE in PIO mode. Because the 161 - drivers allocate buffers you must also prevent MTU changes while the 162 - port is open. 163 - 164 - Once the port is open it will call the rx_function of each channel 165 - whenever a completed packet arrived. This is invoked from interrupt 166 - context and passes you the channel and a network buffer (struct 167 - sk_buff) holding the data. The data includes the CRC bytes so most 168 - users will want to trim the last two bytes before processing the data. 169 - This function is very timing critical. When you wish to simply discard 170 - data the support code provides the function 171 - :c:func:`z8530_null_rx()` to discard the data. 172 - 173 - To active PIO mode sending and receiving the ``z8530_sync_open`` is called. 174 - This expects to be passed the network device and the channel. Typically 175 - this is called from your network device open callback. On a failure a 176 - non zero error status is returned. 177 - The :c:func:`z8530_sync_close()` function shuts down a PIO 178 - channel. This must be done before the channel is opened again and before 179 - the driver shuts down and unloads. 180 - 181 - The ideal mode of operation is dual channel DMA mode. Here the kernel 182 - driver will configure the board for DMA in both directions. The driver 183 - also handles ISA DMA issues such as controller programming and the 184 - memory range limit for you. This mode is activated by calling the 185 - :c:func:`z8530_sync_dma_open()` function. On failure a non zero 186 - error value is returned. Once this mode is activated it can be shut down 187 - by calling the :c:func:`z8530_sync_dma_close()`. You must call 188 - the close function matching the open mode you used. 189 - 190 - The final supported mode uses a single DMA channel to drive the transmit 191 - side. As the Z85C30 has a larger FIFO on the receive channel this tends 192 - to 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 195 - interface from this mode. 196 - 197 - Network Layer Functions 198 - ======================= 199 - 200 - The Z8530 layer provides functions to queue packets for transmission. 201 - The driver internally buffers the frame currently being transmitted and 202 - one further frame (in order to keep back to back transmission running). 203 - Any further buffering is up to the caller. 204 - 205 - The function :c:func:`z8530_queue_xmit()` takes a network buffer 206 - in sk_buff format and queues it for transmission. The caller must 207 - provide the entire packet with the exception of the bitstuffing and CRC. 208 - This is normally done by the caller via the generic HDLC interface 209 - layer. It returns 0 if the buffer has been queued and non zero values 210 - for queue full. If the function accepts the buffer it becomes property 211 - of the Z8530 layer and the caller should not free it. 212 - 213 - The function :c:func:`z8530_get_stats()` returns a pointer to an 214 - internally maintained per interface statistics block. This provides most 215 - of the interface code needed to implement the network layer get_stats 216 - callback. 217 - 218 - Porting The Z8530 Driver 219 - ======================== 220 - 221 - The Z8530 driver is written to be portable. In DMA mode it makes 222 - assumptions about the use of ISA DMA. These are probably warranted in 223 - most cases as the Z85230 in particular was designed to glue to PC type 224 - machines. The PIO mode makes no real assumptions. 225 - 226 - Should you need to retarget the Z8530 driver to another architecture the 227 - only code that should need changing are the port I/O functions. At the 228 - moment these assume PC I/O port accesses. This may not be appropriate 229 - for all platforms. Replacing :c:func:`z8530_read_port()` and 230 - ``z8530_write_port`` is intended to be all that is required to port 231 - this driver layer. 232 - 233 - Known Bugs And Assumptions 234 - ========================== 235 - 236 - Interrupt 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 - 241 - Occasional 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 - 246 - Public Functions Provided 247 - ========================= 248 - 249 - .. kernel-doc:: drivers/net/wan/z85230.c 250 - :export: 251 - 252 - Internal Functions 253 - ================== 254 - 255 - .. kernel-doc:: drivers/net/wan/z85230.c 256 - :internal:
-22
drivers/net/wan/Kconfig
··· 23 23 24 24 if WAN 25 25 26 - # There is no way to detect a comtrol sv11 - force it modular for now. 27 - config HOSTESS_SV11 28 - tristate "Comtrol Hostess SV-11 support" 29 - depends on ISA && m && ISA_DMA_API && INET && HDLC && VIRT_TO_BUS 30 - help 31 - Driver for Comtrol Hostess SV-11 network card which 32 - operates on low speed synchronous serial links at up to 33 - 256Kbps, supporting PPP and Cisco HDLC. 34 - 35 - The driver will be compiled as a module: the 36 - module will be called hostess_sv11. 37 - 38 - # There is no way to detect a Sealevel board. Force it modular 39 - config SEALEVEL_4021 40 - tristate "Sealevel Systems 4021 support" 41 - depends on ISA && m && ISA_DMA_API && INET && HDLC && VIRT_TO_BUS 42 - help 43 - This is a driver for the Sealevel Systems ACB 56 serial I/O adapter. 44 - 45 - The driver will be compiled as a module: the 46 - module will be called sealevel. 47 - 48 26 # Generic HDLC 49 27 config HDLC 50 28 tristate "Generic HDLC layer"
-2
drivers/net/wan/Makefile
··· 14 14 obj-$(CONFIG_HDLC_PPP) += hdlc_ppp.o 15 15 obj-$(CONFIG_HDLC_X25) += hdlc_x25.o 16 16 17 - obj-$(CONFIG_HOSTESS_SV11) += z85230.o hostess_sv11.o 18 - obj-$(CONFIG_SEALEVEL_4021) += z85230.o sealevel.o 19 17 obj-$(CONFIG_FARSYNC) += farsync.o 20 18 21 19 obj-$(CONFIG_LAPBETHER) += lapbether.o
-336
drivers/net/wan/hostess_sv11.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only 2 - /* Comtrol SV11 card driver 3 - * 4 - * This is a slightly odd Z85230 synchronous driver. All you need to 5 - * know basically is 6 - * 7 - * Its a genuine Z85230 8 - * 9 - * It supports DMA using two DMA channels in SYNC mode. The driver doesn't 10 - * use these facilities 11 - * 12 - * The control port is at io+1, the data at io+3 and turning off the DMA 13 - * is done by writing 0 to io+4 14 - * 15 - * The hardware does the bus handling to avoid the need for delays between 16 - * touching control registers. 17 - * 18 - * Port B isn't wired (why - beats me) 19 - * 20 - * Generic HDLC port Copyright (C) 2008 Krzysztof Halasa <khc@pm.waw.pl> 21 - */ 22 - 23 - #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 24 - 25 - #include <linux/module.h> 26 - #include <linux/kernel.h> 27 - #include <linux/mm.h> 28 - #include <linux/net.h> 29 - #include <linux/skbuff.h> 30 - #include <linux/netdevice.h> 31 - #include <linux/if_arp.h> 32 - #include <linux/delay.h> 33 - #include <linux/hdlc.h> 34 - #include <linux/ioport.h> 35 - #include <linux/slab.h> 36 - #include <net/arp.h> 37 - 38 - #include <asm/irq.h> 39 - #include <asm/io.h> 40 - #include <asm/dma.h> 41 - #include <asm/byteorder.h> 42 - #include "z85230.h" 43 - 44 - static int dma; 45 - 46 - /* Network driver support routines 47 - */ 48 - 49 - static inline struct z8530_dev *dev_to_sv(struct net_device *dev) 50 - { 51 - return (struct z8530_dev *)dev_to_hdlc(dev)->priv; 52 - } 53 - 54 - /* Frame receive. Simple for our card as we do HDLC and there 55 - * is no funny garbage involved 56 - */ 57 - 58 - static void hostess_input(struct z8530_channel *c, struct sk_buff *skb) 59 - { 60 - /* Drop the CRC - it's not a good idea to try and negotiate it ;) */ 61 - skb_trim(skb, skb->len - 2); 62 - skb->protocol = hdlc_type_trans(skb, c->netdevice); 63 - skb_reset_mac_header(skb); 64 - skb->dev = c->netdevice; 65 - /* Send it to the PPP layer. We don't have time to process 66 - * it right now. 67 - */ 68 - netif_rx(skb); 69 - } 70 - 71 - /* We've been placed in the UP state 72 - */ 73 - 74 - static int hostess_open(struct net_device *d) 75 - { 76 - struct z8530_dev *sv11 = dev_to_sv(d); 77 - int err = -1; 78 - 79 - /* Link layer up 80 - */ 81 - switch (dma) { 82 - case 0: 83 - err = z8530_sync_open(d, &sv11->chanA); 84 - break; 85 - case 1: 86 - err = z8530_sync_dma_open(d, &sv11->chanA); 87 - break; 88 - case 2: 89 - err = z8530_sync_txdma_open(d, &sv11->chanA); 90 - break; 91 - } 92 - 93 - if (err) 94 - return err; 95 - 96 - err = hdlc_open(d); 97 - if (err) { 98 - switch (dma) { 99 - case 0: 100 - z8530_sync_close(d, &sv11->chanA); 101 - break; 102 - case 1: 103 - z8530_sync_dma_close(d, &sv11->chanA); 104 - break; 105 - case 2: 106 - z8530_sync_txdma_close(d, &sv11->chanA); 107 - break; 108 - } 109 - return err; 110 - } 111 - sv11->chanA.rx_function = hostess_input; 112 - 113 - /* 114 - * Go go go 115 - */ 116 - 117 - netif_start_queue(d); 118 - return 0; 119 - } 120 - 121 - static int hostess_close(struct net_device *d) 122 - { 123 - struct z8530_dev *sv11 = dev_to_sv(d); 124 - /* Discard new frames 125 - */ 126 - sv11->chanA.rx_function = z8530_null_rx; 127 - 128 - hdlc_close(d); 129 - netif_stop_queue(d); 130 - 131 - switch (dma) { 132 - case 0: 133 - z8530_sync_close(d, &sv11->chanA); 134 - break; 135 - case 1: 136 - z8530_sync_dma_close(d, &sv11->chanA); 137 - break; 138 - case 2: 139 - z8530_sync_txdma_close(d, &sv11->chanA); 140 - break; 141 - } 142 - return 0; 143 - } 144 - 145 - /* Passed network frames, fire them downwind. 146 - */ 147 - 148 - static netdev_tx_t hostess_queue_xmit(struct sk_buff *skb, 149 - struct net_device *d) 150 - { 151 - return z8530_queue_xmit(&dev_to_sv(d)->chanA, skb); 152 - } 153 - 154 - static int hostess_attach(struct net_device *dev, unsigned short encoding, 155 - unsigned short parity) 156 - { 157 - if (encoding == ENCODING_NRZ && parity == PARITY_CRC16_PR1_CCITT) 158 - return 0; 159 - return -EINVAL; 160 - } 161 - 162 - /* Description block for a Comtrol Hostess SV11 card 163 - */ 164 - 165 - static const struct net_device_ops hostess_ops = { 166 - .ndo_open = hostess_open, 167 - .ndo_stop = hostess_close, 168 - .ndo_start_xmit = hdlc_start_xmit, 169 - .ndo_siocwandev = hdlc_ioctl, 170 - }; 171 - 172 - static struct z8530_dev *sv11_init(int iobase, int irq) 173 - { 174 - struct z8530_dev *sv; 175 - struct net_device *netdev; 176 - /* Get the needed I/O space 177 - */ 178 - 179 - if (!request_region(iobase, 8, "Comtrol SV11")) { 180 - pr_warn("I/O 0x%X already in use\n", iobase); 181 - return NULL; 182 - } 183 - 184 - sv = kzalloc(sizeof(struct z8530_dev), GFP_KERNEL); 185 - if (!sv) 186 - goto err_kzalloc; 187 - 188 - /* Stuff in the I/O addressing 189 - */ 190 - 191 - sv->active = 0; 192 - 193 - sv->chanA.ctrlio = iobase + 1; 194 - sv->chanA.dataio = iobase + 3; 195 - sv->chanB.ctrlio = -1; 196 - sv->chanB.dataio = -1; 197 - sv->chanA.irqs = &z8530_nop; 198 - sv->chanB.irqs = &z8530_nop; 199 - 200 - outb(0, iobase + 4); /* DMA off */ 201 - 202 - /* We want a fast IRQ for this device. Actually we'd like an even faster 203 - * IRQ ;) - This is one driver RtLinux is made for 204 - */ 205 - 206 - if (request_irq(irq, z8530_interrupt, 0, 207 - "Hostess SV11", sv) < 0) { 208 - pr_warn("IRQ %d already in use\n", irq); 209 - goto err_irq; 210 - } 211 - 212 - sv->irq = irq; 213 - sv->chanA.private = sv; 214 - sv->chanA.dev = sv; 215 - sv->chanB.dev = sv; 216 - 217 - if (dma) { 218 - /* You can have DMA off or 1 and 3 thats the lot 219 - * on the Comtrol. 220 - */ 221 - sv->chanA.txdma = 3; 222 - sv->chanA.rxdma = 1; 223 - outb(0x03 | 0x08, iobase + 4); /* DMA on */ 224 - if (request_dma(sv->chanA.txdma, "Hostess SV/11 (TX)")) 225 - goto err_txdma; 226 - 227 - if (dma == 1) 228 - if (request_dma(sv->chanA.rxdma, "Hostess SV/11 (RX)")) 229 - goto err_rxdma; 230 - } 231 - 232 - /* Kill our private IRQ line the hostess can end up chattering 233 - * until the configuration is set 234 - */ 235 - disable_irq(irq); 236 - 237 - /* Begin normal initialise 238 - */ 239 - 240 - if (z8530_init(sv)) { 241 - pr_err("Z8530 series device not found\n"); 242 - enable_irq(irq); 243 - goto free_dma; 244 - } 245 - z8530_channel_load(&sv->chanB, z8530_dead_port); 246 - if (sv->type == Z85C30) 247 - z8530_channel_load(&sv->chanA, z8530_hdlc_kilostream); 248 - else 249 - z8530_channel_load(&sv->chanA, z8530_hdlc_kilostream_85230); 250 - 251 - enable_irq(irq); 252 - 253 - /* Now we can take the IRQ 254 - */ 255 - 256 - sv->chanA.netdevice = netdev = alloc_hdlcdev(sv); 257 - if (!netdev) 258 - goto free_dma; 259 - 260 - dev_to_hdlc(netdev)->attach = hostess_attach; 261 - dev_to_hdlc(netdev)->xmit = hostess_queue_xmit; 262 - netdev->netdev_ops = &hostess_ops; 263 - netdev->base_addr = iobase; 264 - netdev->irq = irq; 265 - 266 - if (register_hdlc_device(netdev)) { 267 - pr_err("unable to register HDLC device\n"); 268 - free_netdev(netdev); 269 - goto free_dma; 270 - } 271 - 272 - z8530_describe(sv, "I/O", iobase); 273 - sv->active = 1; 274 - return sv; 275 - 276 - free_dma: 277 - if (dma == 1) 278 - free_dma(sv->chanA.rxdma); 279 - err_rxdma: 280 - if (dma) 281 - free_dma(sv->chanA.txdma); 282 - err_txdma: 283 - free_irq(irq, sv); 284 - err_irq: 285 - kfree(sv); 286 - err_kzalloc: 287 - release_region(iobase, 8); 288 - return NULL; 289 - } 290 - 291 - static void sv11_shutdown(struct z8530_dev *dev) 292 - { 293 - unregister_hdlc_device(dev->chanA.netdevice); 294 - z8530_shutdown(dev); 295 - free_irq(dev->irq, dev); 296 - if (dma) { 297 - if (dma == 1) 298 - free_dma(dev->chanA.rxdma); 299 - free_dma(dev->chanA.txdma); 300 - } 301 - release_region(dev->chanA.ctrlio - 1, 8); 302 - free_netdev(dev->chanA.netdevice); 303 - kfree(dev); 304 - } 305 - 306 - static int io = 0x200; 307 - static int irq = 9; 308 - 309 - module_param_hw(io, int, ioport, 0); 310 - MODULE_PARM_DESC(io, "The I/O base of the Comtrol Hostess SV11 card"); 311 - module_param_hw(dma, int, dma, 0); 312 - MODULE_PARM_DESC(dma, "Set this to 1 to use DMA1/DMA3 for TX/RX"); 313 - module_param_hw(irq, int, irq, 0); 314 - MODULE_PARM_DESC(irq, "The interrupt line setting for the Comtrol Hostess SV11 card"); 315 - 316 - MODULE_AUTHOR("Alan Cox"); 317 - MODULE_LICENSE("GPL"); 318 - MODULE_DESCRIPTION("Modular driver for the Comtrol Hostess SV11"); 319 - 320 - static struct z8530_dev *sv11_unit; 321 - 322 - static int sv11_module_init(void) 323 - { 324 - sv11_unit = sv11_init(io, irq); 325 - if (!sv11_unit) 326 - return -ENODEV; 327 - return 0; 328 - } 329 - module_init(sv11_module_init); 330 - 331 - static void sv11_module_cleanup(void) 332 - { 333 - if (sv11_unit) 334 - sv11_shutdown(sv11_unit); 335 - } 336 - module_exit(sv11_module_cleanup);
-352
drivers/net/wan/sealevel.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-or-later 2 - /* Sealevel Systems 4021 driver. 3 - * 4 - * (c) Copyright 1999, 2001 Alan Cox 5 - * (c) Copyright 2001 Red Hat Inc. 6 - * Generic HDLC port Copyright (C) 2008 Krzysztof Halasa <khc@pm.waw.pl> 7 - */ 8 - 9 - #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 10 - 11 - #include <linux/module.h> 12 - #include <linux/kernel.h> 13 - #include <linux/mm.h> 14 - #include <linux/net.h> 15 - #include <linux/skbuff.h> 16 - #include <linux/netdevice.h> 17 - #include <linux/if_arp.h> 18 - #include <linux/delay.h> 19 - #include <linux/hdlc.h> 20 - #include <linux/ioport.h> 21 - #include <linux/init.h> 22 - #include <linux/slab.h> 23 - #include <net/arp.h> 24 - 25 - #include <asm/irq.h> 26 - #include <asm/io.h> 27 - #include <asm/dma.h> 28 - #include <asm/byteorder.h> 29 - #include "z85230.h" 30 - 31 - struct slvl_device { 32 - struct z8530_channel *chan; 33 - int channel; 34 - }; 35 - 36 - struct slvl_board { 37 - struct slvl_device dev[2]; 38 - struct z8530_dev board; 39 - int iobase; 40 - }; 41 - 42 - /* Network driver support routines */ 43 - 44 - static inline struct slvl_device *dev_to_chan(struct net_device *dev) 45 - { 46 - return (struct slvl_device *)dev_to_hdlc(dev)->priv; 47 - } 48 - 49 - /* Frame receive. Simple for our card as we do HDLC and there 50 - * is no funny garbage involved 51 - */ 52 - 53 - static void sealevel_input(struct z8530_channel *c, struct sk_buff *skb) 54 - { 55 - /* Drop the CRC - it's not a good idea to try and negotiate it ;) */ 56 - skb_trim(skb, skb->len - 2); 57 - skb->protocol = hdlc_type_trans(skb, c->netdevice); 58 - skb_reset_mac_header(skb); 59 - skb->dev = c->netdevice; 60 - netif_rx(skb); 61 - } 62 - 63 - /* We've been placed in the UP state */ 64 - 65 - static int sealevel_open(struct net_device *d) 66 - { 67 - struct slvl_device *slvl = dev_to_chan(d); 68 - int err = -1; 69 - int unit = slvl->channel; 70 - 71 - /* Link layer up. */ 72 - 73 - switch (unit) { 74 - case 0: 75 - err = z8530_sync_dma_open(d, slvl->chan); 76 - break; 77 - case 1: 78 - err = z8530_sync_open(d, slvl->chan); 79 - break; 80 - } 81 - 82 - if (err) 83 - return err; 84 - 85 - err = hdlc_open(d); 86 - if (err) { 87 - switch (unit) { 88 - case 0: 89 - z8530_sync_dma_close(d, slvl->chan); 90 - break; 91 - case 1: 92 - z8530_sync_close(d, slvl->chan); 93 - break; 94 - } 95 - return err; 96 - } 97 - 98 - slvl->chan->rx_function = sealevel_input; 99 - 100 - netif_start_queue(d); 101 - return 0; 102 - } 103 - 104 - static int sealevel_close(struct net_device *d) 105 - { 106 - struct slvl_device *slvl = dev_to_chan(d); 107 - int unit = slvl->channel; 108 - 109 - /* Discard new frames */ 110 - 111 - slvl->chan->rx_function = z8530_null_rx; 112 - 113 - hdlc_close(d); 114 - netif_stop_queue(d); 115 - 116 - switch (unit) { 117 - case 0: 118 - z8530_sync_dma_close(d, slvl->chan); 119 - break; 120 - case 1: 121 - z8530_sync_close(d, slvl->chan); 122 - break; 123 - } 124 - return 0; 125 - } 126 - 127 - /* Passed network frames, fire them downwind. */ 128 - 129 - static netdev_tx_t sealevel_queue_xmit(struct sk_buff *skb, 130 - struct net_device *d) 131 - { 132 - return z8530_queue_xmit(dev_to_chan(d)->chan, skb); 133 - } 134 - 135 - static int sealevel_attach(struct net_device *dev, unsigned short encoding, 136 - unsigned short parity) 137 - { 138 - if (encoding == ENCODING_NRZ && parity == PARITY_CRC16_PR1_CCITT) 139 - return 0; 140 - return -EINVAL; 141 - } 142 - 143 - static const struct net_device_ops sealevel_ops = { 144 - .ndo_open = sealevel_open, 145 - .ndo_stop = sealevel_close, 146 - .ndo_start_xmit = hdlc_start_xmit, 147 - .ndo_siocwandev = hdlc_ioctl, 148 - }; 149 - 150 - static int slvl_setup(struct slvl_device *sv, int iobase, int irq) 151 - { 152 - struct net_device *dev = alloc_hdlcdev(sv); 153 - 154 - if (!dev) 155 - return -1; 156 - 157 - dev_to_hdlc(dev)->attach = sealevel_attach; 158 - dev_to_hdlc(dev)->xmit = sealevel_queue_xmit; 159 - dev->netdev_ops = &sealevel_ops; 160 - dev->base_addr = iobase; 161 - dev->irq = irq; 162 - 163 - if (register_hdlc_device(dev)) { 164 - pr_err("unable to register HDLC device\n"); 165 - free_netdev(dev); 166 - return -1; 167 - } 168 - 169 - sv->chan->netdevice = dev; 170 - return 0; 171 - } 172 - 173 - /* Allocate and setup Sealevel board. */ 174 - 175 - static __init struct slvl_board *slvl_init(int iobase, int irq, 176 - int txdma, int rxdma, int slow) 177 - { 178 - struct z8530_dev *dev; 179 - struct slvl_board *b; 180 - 181 - /* Get the needed I/O space */ 182 - 183 - if (!request_region(iobase, 8, "Sealevel 4021")) { 184 - pr_warn("I/O 0x%X already in use\n", iobase); 185 - return NULL; 186 - } 187 - 188 - b = kzalloc(sizeof(struct slvl_board), GFP_KERNEL); 189 - if (!b) 190 - goto err_kzalloc; 191 - 192 - b->dev[0].chan = &b->board.chanA; 193 - b->dev[0].channel = 0; 194 - 195 - b->dev[1].chan = &b->board.chanB; 196 - b->dev[1].channel = 1; 197 - 198 - dev = &b->board; 199 - 200 - /* Stuff in the I/O addressing */ 201 - 202 - dev->active = 0; 203 - 204 - b->iobase = iobase; 205 - 206 - /* Select 8530 delays for the old board */ 207 - 208 - if (slow) 209 - iobase |= Z8530_PORT_SLEEP; 210 - 211 - dev->chanA.ctrlio = iobase + 1; 212 - dev->chanA.dataio = iobase; 213 - dev->chanB.ctrlio = iobase + 3; 214 - dev->chanB.dataio = iobase + 2; 215 - 216 - dev->chanA.irqs = &z8530_nop; 217 - dev->chanB.irqs = &z8530_nop; 218 - 219 - /* Assert DTR enable DMA */ 220 - 221 - outb(3 | (1 << 7), b->iobase + 4); 222 - 223 - /* We want a fast IRQ for this device. Actually we'd like an even faster 224 - * IRQ ;) - This is one driver RtLinux is made for 225 - */ 226 - 227 - if (request_irq(irq, z8530_interrupt, 0, 228 - "SeaLevel", dev) < 0) { 229 - pr_warn("IRQ %d already in use\n", irq); 230 - goto err_request_irq; 231 - } 232 - 233 - dev->irq = irq; 234 - dev->chanA.private = &b->dev[0]; 235 - dev->chanB.private = &b->dev[1]; 236 - dev->chanA.dev = dev; 237 - dev->chanB.dev = dev; 238 - 239 - dev->chanA.txdma = 3; 240 - dev->chanA.rxdma = 1; 241 - if (request_dma(dev->chanA.txdma, "SeaLevel (TX)")) 242 - goto err_dma_tx; 243 - 244 - if (request_dma(dev->chanA.rxdma, "SeaLevel (RX)")) 245 - goto err_dma_rx; 246 - 247 - disable_irq(irq); 248 - 249 - /* Begin normal initialise */ 250 - 251 - if (z8530_init(dev) != 0) { 252 - pr_err("Z8530 series device not found\n"); 253 - enable_irq(irq); 254 - goto free_hw; 255 - } 256 - if (dev->type == Z85C30) { 257 - z8530_channel_load(&dev->chanA, z8530_hdlc_kilostream); 258 - z8530_channel_load(&dev->chanB, z8530_hdlc_kilostream); 259 - } else { 260 - z8530_channel_load(&dev->chanA, z8530_hdlc_kilostream_85230); 261 - z8530_channel_load(&dev->chanB, z8530_hdlc_kilostream_85230); 262 - } 263 - 264 - /* Now we can take the IRQ */ 265 - 266 - enable_irq(irq); 267 - 268 - if (slvl_setup(&b->dev[0], iobase, irq)) 269 - goto free_hw; 270 - if (slvl_setup(&b->dev[1], iobase, irq)) 271 - goto free_netdev0; 272 - 273 - z8530_describe(dev, "I/O", iobase); 274 - dev->active = 1; 275 - return b; 276 - 277 - free_netdev0: 278 - unregister_hdlc_device(b->dev[0].chan->netdevice); 279 - free_netdev(b->dev[0].chan->netdevice); 280 - free_hw: 281 - free_dma(dev->chanA.rxdma); 282 - err_dma_rx: 283 - free_dma(dev->chanA.txdma); 284 - err_dma_tx: 285 - free_irq(irq, dev); 286 - err_request_irq: 287 - kfree(b); 288 - err_kzalloc: 289 - release_region(iobase, 8); 290 - return NULL; 291 - } 292 - 293 - static void __exit slvl_shutdown(struct slvl_board *b) 294 - { 295 - int u; 296 - 297 - z8530_shutdown(&b->board); 298 - 299 - for (u = 0; u < 2; u++) { 300 - struct net_device *d = b->dev[u].chan->netdevice; 301 - 302 - unregister_hdlc_device(d); 303 - free_netdev(d); 304 - } 305 - 306 - free_irq(b->board.irq, &b->board); 307 - free_dma(b->board.chanA.rxdma); 308 - free_dma(b->board.chanA.txdma); 309 - /* DMA off on the card, drop DTR */ 310 - outb(0, b->iobase); 311 - release_region(b->iobase, 8); 312 - kfree(b); 313 - } 314 - 315 - static int io = 0x238; 316 - static int txdma = 1; 317 - static int rxdma = 3; 318 - static int irq = 5; 319 - static bool slow; 320 - 321 - module_param_hw(io, int, ioport, 0); 322 - MODULE_PARM_DESC(io, "The I/O base of the Sealevel card"); 323 - module_param_hw(txdma, int, dma, 0); 324 - MODULE_PARM_DESC(txdma, "Transmit DMA channel"); 325 - module_param_hw(rxdma, int, dma, 0); 326 - MODULE_PARM_DESC(rxdma, "Receive DMA channel"); 327 - module_param_hw(irq, int, irq, 0); 328 - MODULE_PARM_DESC(irq, "The interrupt line setting for the SeaLevel card"); 329 - module_param(slow, bool, 0); 330 - MODULE_PARM_DESC(slow, "Set this for an older Sealevel card such as the 4012"); 331 - 332 - MODULE_AUTHOR("Alan Cox"); 333 - MODULE_LICENSE("GPL"); 334 - MODULE_DESCRIPTION("Modular driver for the SeaLevel 4021"); 335 - 336 - static struct slvl_board *slvl_unit; 337 - 338 - static int __init slvl_init_module(void) 339 - { 340 - slvl_unit = slvl_init(io, irq, txdma, rxdma, slow); 341 - 342 - return slvl_unit ? 0 : -ENODEV; 343 - } 344 - 345 - static void __exit slvl_cleanup_module(void) 346 - { 347 - if (slvl_unit) 348 - slvl_shutdown(slvl_unit); 349 - } 350 - 351 - module_init(slvl_init_module); 352 - module_exit(slvl_cleanup_module);
-1641
drivers/net/wan/z85230.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-or-later 2 - /* (c) Copyright 1998 Alan Cox <alan@lxorguk.ukuu.org.uk> 3 - * (c) Copyright 2000, 2001 Red Hat Inc 4 - * 5 - * Development of this driver was funded by Equiinet Ltd 6 - * http://www.equiinet.com 7 - * 8 - * ChangeLog: 9 - * 10 - * Asynchronous mode dropped for 2.2. For 2.5 we will attempt the 11 - * unification of all the Z85x30 asynchronous drivers for real. 12 - * 13 - * DMA now uses get_free_page as kmalloc buffers may span a 64K 14 - * boundary. 15 - * 16 - * Modified for SMP safety and SMP locking by Alan Cox 17 - * <alan@lxorguk.ukuu.org.uk> 18 - * 19 - * Performance 20 - * 21 - * Z85230: 22 - * Non DMA you want a 486DX50 or better to do 64Kbits. 9600 baud 23 - * X.25 is not unrealistic on all machines. DMA mode can in theory 24 - * handle T1/E1 quite nicely. In practice the limit seems to be about 25 - * 512Kbit->1Mbit depending on motherboard. 26 - * 27 - * Z85C30: 28 - * 64K will take DMA, 9600 baud X.25 should be ok. 29 - * 30 - * Z8530: 31 - * Synchronous mode without DMA is unlikely to pass about 2400 baud. 32 - */ 33 - 34 - #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 35 - 36 - #include <linux/module.h> 37 - #include <linux/kernel.h> 38 - #include <linux/mm.h> 39 - #include <linux/net.h> 40 - #include <linux/skbuff.h> 41 - #include <linux/netdevice.h> 42 - #include <linux/if_arp.h> 43 - #include <linux/delay.h> 44 - #include <linux/hdlc.h> 45 - #include <linux/ioport.h> 46 - #include <linux/init.h> 47 - #include <linux/gfp.h> 48 - #include <asm/dma.h> 49 - #include <asm/io.h> 50 - #define RT_LOCK 51 - #define RT_UNLOCK 52 - #include <linux/spinlock.h> 53 - 54 - #include "z85230.h" 55 - 56 - /** 57 - * z8530_read_port - Architecture specific interface function 58 - * @p: port to read 59 - * 60 - * Provided port access methods. The Comtrol SV11 requires no delays 61 - * between accesses and uses PC I/O. Some drivers may need a 5uS delay 62 - * 63 - * In the longer term this should become an architecture specific 64 - * section so that this can become a generic driver interface for all 65 - * platforms. For now we only handle PC I/O ports with or without the 66 - * dread 5uS sanity delay. 67 - * 68 - * The caller must hold sufficient locks to avoid violating the horrible 69 - * 5uS delay rule. 70 - */ 71 - 72 - static inline int z8530_read_port(unsigned long p) 73 - { 74 - u8 r = inb(Z8530_PORT_OF(p)); 75 - 76 - if (p & Z8530_PORT_SLEEP) /* gcc should figure this out efficiently ! */ 77 - udelay(5); 78 - return r; 79 - } 80 - 81 - /** 82 - * z8530_write_port - Architecture specific interface function 83 - * @p: port to write 84 - * @d: value to write 85 - * 86 - * Write a value to a port with delays if need be. Note that the 87 - * caller must hold locks to avoid read/writes from other contexts 88 - * violating the 5uS rule 89 - * 90 - * In the longer term this should become an architecture specific 91 - * section so that this can become a generic driver interface for all 92 - * platforms. For now we only handle PC I/O ports with or without the 93 - * dread 5uS sanity delay. 94 - */ 95 - 96 - static inline void z8530_write_port(unsigned long p, u8 d) 97 - { 98 - outb(d, Z8530_PORT_OF(p)); 99 - if (p & Z8530_PORT_SLEEP) 100 - udelay(5); 101 - } 102 - 103 - static void z8530_rx_done(struct z8530_channel *c); 104 - static void z8530_tx_done(struct z8530_channel *c); 105 - 106 - /** 107 - * read_zsreg - Read a register from a Z85230 108 - * @c: Z8530 channel to read from (2 per chip) 109 - * @reg: Register to read 110 - * FIXME: Use a spinlock. 111 - * 112 - * Most of the Z8530 registers are indexed off the control registers. 113 - * A read is done by writing to the control register and reading the 114 - * register back. The caller must hold the lock 115 - */ 116 - 117 - static inline u8 read_zsreg(struct z8530_channel *c, u8 reg) 118 - { 119 - if (reg) 120 - z8530_write_port(c->ctrlio, reg); 121 - return z8530_read_port(c->ctrlio); 122 - } 123 - 124 - /** 125 - * read_zsdata - Read the data port of a Z8530 channel 126 - * @c: The Z8530 channel to read the data port from 127 - * 128 - * The data port provides fast access to some things. We still 129 - * have all the 5uS delays to worry about. 130 - */ 131 - 132 - static inline u8 read_zsdata(struct z8530_channel *c) 133 - { 134 - u8 r; 135 - 136 - r = z8530_read_port(c->dataio); 137 - return r; 138 - } 139 - 140 - /** 141 - * write_zsreg - Write to a Z8530 channel register 142 - * @c: The Z8530 channel 143 - * @reg: Register number 144 - * @val: Value to write 145 - * 146 - * Write a value to an indexed register. The caller must hold the lock 147 - * to honour the irritating delay rules. We know about register 0 148 - * being fast to access. 149 - * 150 - * Assumes c->lock is held. 151 - */ 152 - static inline void write_zsreg(struct z8530_channel *c, u8 reg, u8 val) 153 - { 154 - if (reg) 155 - z8530_write_port(c->ctrlio, reg); 156 - z8530_write_port(c->ctrlio, val); 157 - } 158 - 159 - /** 160 - * write_zsctrl - Write to a Z8530 control register 161 - * @c: The Z8530 channel 162 - * @val: Value to write 163 - * 164 - * Write directly to the control register on the Z8530 165 - */ 166 - 167 - static inline void write_zsctrl(struct z8530_channel *c, u8 val) 168 - { 169 - z8530_write_port(c->ctrlio, val); 170 - } 171 - 172 - /** 173 - * write_zsdata - Write to a Z8530 control register 174 - * @c: The Z8530 channel 175 - * @val: Value to write 176 - * 177 - * Write directly to the data register on the Z8530 178 - */ 179 - static inline void write_zsdata(struct z8530_channel *c, u8 val) 180 - { 181 - z8530_write_port(c->dataio, val); 182 - } 183 - 184 - /* Register loading parameters for a dead port 185 - */ 186 - 187 - u8 z8530_dead_port[] = { 188 - 255 189 - }; 190 - EXPORT_SYMBOL(z8530_dead_port); 191 - 192 - /* Register loading parameters for currently supported circuit types 193 - */ 194 - 195 - /* Data clocked by telco end. This is the correct data for the UK 196 - * "kilostream" service, and most other similar services. 197 - */ 198 - 199 - u8 z8530_hdlc_kilostream[] = { 200 - 4, SYNC_ENAB | SDLC | X1CLK, 201 - 2, 0, /* No vector */ 202 - 1, 0, 203 - 3, ENT_HM | RxCRC_ENAB | Rx8, 204 - 5, TxCRC_ENAB | RTS | TxENAB | Tx8 | DTR, 205 - 9, 0, /* Disable interrupts */ 206 - 6, 0xFF, 207 - 7, FLAG, 208 - 10, ABUNDER | NRZ | CRCPS,/*MARKIDLE ??*/ 209 - 11, TCTRxCP, 210 - 14, DISDPLL, 211 - 15, DCDIE | SYNCIE | CTSIE | TxUIE | BRKIE, 212 - 1, EXT_INT_ENAB | TxINT_ENAB | INT_ALL_Rx, 213 - 9, NV | MIE | NORESET, 214 - 255 215 - }; 216 - EXPORT_SYMBOL(z8530_hdlc_kilostream); 217 - 218 - /* As above but for enhanced chips. 219 - */ 220 - 221 - u8 z8530_hdlc_kilostream_85230[] = { 222 - 4, SYNC_ENAB | SDLC | X1CLK, 223 - 2, 0, /* No vector */ 224 - 1, 0, 225 - 3, ENT_HM | RxCRC_ENAB | Rx8, 226 - 5, TxCRC_ENAB | RTS | TxENAB | Tx8 | DTR, 227 - 9, 0, /* Disable interrupts */ 228 - 6, 0xFF, 229 - 7, FLAG, 230 - 10, ABUNDER | NRZ | CRCPS, /* MARKIDLE?? */ 231 - 11, TCTRxCP, 232 - 14, DISDPLL, 233 - 15, DCDIE | SYNCIE | CTSIE | TxUIE | BRKIE, 234 - 1, EXT_INT_ENAB | TxINT_ENAB | INT_ALL_Rx, 235 - 9, NV | MIE | NORESET, 236 - 23, 3, /* Extended mode AUTO TX and EOM*/ 237 - 238 - 255 239 - }; 240 - EXPORT_SYMBOL(z8530_hdlc_kilostream_85230); 241 - 242 - /** 243 - * z8530_flush_fifo - Flush on chip RX FIFO 244 - * @c: Channel to flush 245 - * 246 - * Flush the receive FIFO. There is no specific option for this, we 247 - * blindly read bytes and discard them. Reading when there is no data 248 - * is harmless. The 8530 has a 4 byte FIFO, the 85230 has 8 bytes. 249 - * 250 - * All locking is handled for the caller. On return data may still be 251 - * present if it arrived during the flush. 252 - */ 253 - 254 - static void z8530_flush_fifo(struct z8530_channel *c) 255 - { 256 - read_zsreg(c, R1); 257 - read_zsreg(c, R1); 258 - read_zsreg(c, R1); 259 - read_zsreg(c, R1); 260 - if (c->dev->type == Z85230) { 261 - read_zsreg(c, R1); 262 - read_zsreg(c, R1); 263 - read_zsreg(c, R1); 264 - read_zsreg(c, R1); 265 - } 266 - } 267 - 268 - /** 269 - * z8530_rtsdtr - Control the outgoing DTS/RTS line 270 - * @c: The Z8530 channel to control; 271 - * @set: 1 to set, 0 to clear 272 - * 273 - * Sets or clears DTR/RTS on the requested line. All locking is handled 274 - * by the caller. For now we assume all boards use the actual RTS/DTR 275 - * on the chip. Apparently one or two don't. We'll scream about them 276 - * later. 277 - */ 278 - 279 - static void z8530_rtsdtr(struct z8530_channel *c, int set) 280 - { 281 - if (set) 282 - c->regs[5] |= (RTS | DTR); 283 - else 284 - c->regs[5] &= ~(RTS | DTR); 285 - write_zsreg(c, R5, c->regs[5]); 286 - } 287 - 288 - /** 289 - * z8530_rx - Handle a PIO receive event 290 - * @c: Z8530 channel to process 291 - * 292 - * Receive handler for receiving in PIO mode. This is much like the 293 - * async one but not quite the same or as complex 294 - * 295 - * Note: Its intended that this handler can easily be separated from 296 - * the main code to run realtime. That'll be needed for some machines 297 - * (eg to ever clock 64kbits on a sparc ;)). 298 - * 299 - * The RT_LOCK macros don't do anything now. Keep the code covered 300 - * by them as short as possible in all circumstances - clocks cost 301 - * baud. The interrupt handler is assumed to be atomic w.r.t. to 302 - * other code - this is true in the RT case too. 303 - * 304 - * We only cover the sync cases for this. If you want 2Mbit async 305 - * do it yourself but consider medical assistance first. This non DMA 306 - * synchronous mode is portable code. The DMA mode assumes PCI like 307 - * ISA DMA 308 - * 309 - * Called with the device lock held 310 - */ 311 - 312 - static void z8530_rx(struct z8530_channel *c) 313 - { 314 - u8 ch, stat; 315 - 316 - while (1) { 317 - /* FIFO empty ? */ 318 - if (!(read_zsreg(c, R0) & 1)) 319 - break; 320 - ch = read_zsdata(c); 321 - stat = read_zsreg(c, R1); 322 - 323 - /* Overrun ? 324 - */ 325 - if (c->count < c->max) { 326 - *c->dptr++ = ch; 327 - c->count++; 328 - } 329 - 330 - if (stat & END_FR) { 331 - /* Error ? 332 - */ 333 - if (stat & (Rx_OVR | CRC_ERR)) { 334 - /* Rewind the buffer and return */ 335 - if (c->skb) 336 - c->dptr = c->skb->data; 337 - c->count = 0; 338 - if (stat & Rx_OVR) { 339 - pr_warn("%s: overrun\n", c->dev->name); 340 - c->rx_overrun++; 341 - } 342 - if (stat & CRC_ERR) { 343 - c->rx_crc_err++; 344 - /* printk("crc error\n"); */ 345 - } 346 - /* Shove the frame upstream */ 347 - } else { 348 - /* Drop the lock for RX processing, or 349 - * there are deadlocks 350 - */ 351 - z8530_rx_done(c); 352 - write_zsctrl(c, RES_Rx_CRC); 353 - } 354 - } 355 - } 356 - /* Clear irq 357 - */ 358 - write_zsctrl(c, ERR_RES); 359 - write_zsctrl(c, RES_H_IUS); 360 - } 361 - 362 - /** 363 - * z8530_tx - Handle a PIO transmit event 364 - * @c: Z8530 channel to process 365 - * 366 - * Z8530 transmit interrupt handler for the PIO mode. The basic 367 - * idea is to attempt to keep the FIFO fed. We fill as many bytes 368 - * in as possible, its quite possible that we won't keep up with the 369 - * data rate otherwise. 370 - */ 371 - 372 - static void z8530_tx(struct z8530_channel *c) 373 - { 374 - while (c->txcount) { 375 - /* FIFO full ? */ 376 - if (!(read_zsreg(c, R0) & 4)) 377 - return; 378 - c->txcount--; 379 - /* Shovel out the byte 380 - */ 381 - write_zsreg(c, R8, *c->tx_ptr++); 382 - write_zsctrl(c, RES_H_IUS); 383 - /* We are about to underflow */ 384 - if (c->txcount == 0) { 385 - write_zsctrl(c, RES_EOM_L); 386 - write_zsreg(c, R10, c->regs[10] & ~ABUNDER); 387 - } 388 - } 389 - 390 - /* End of frame TX - fire another one 391 - */ 392 - 393 - write_zsctrl(c, RES_Tx_P); 394 - 395 - z8530_tx_done(c); 396 - write_zsctrl(c, RES_H_IUS); 397 - } 398 - 399 - /** 400 - * z8530_status - Handle a PIO status exception 401 - * @chan: Z8530 channel to process 402 - * 403 - * A status event occurred in PIO synchronous mode. There are several 404 - * reasons the chip will bother us here. A transmit underrun means we 405 - * failed to feed the chip fast enough and just broke a packet. A DCD 406 - * change is a line up or down. 407 - */ 408 - 409 - static void z8530_status(struct z8530_channel *chan) 410 - { 411 - u8 status, altered; 412 - 413 - status = read_zsreg(chan, R0); 414 - altered = chan->status ^ status; 415 - 416 - chan->status = status; 417 - 418 - if (status & TxEOM) { 419 - /* printk("%s: Tx underrun.\n", chan->dev->name); */ 420 - chan->netdevice->stats.tx_fifo_errors++; 421 - write_zsctrl(chan, ERR_RES); 422 - z8530_tx_done(chan); 423 - } 424 - 425 - if (altered & chan->dcdcheck) { 426 - if (status & chan->dcdcheck) { 427 - pr_info("%s: DCD raised\n", chan->dev->name); 428 - write_zsreg(chan, R3, chan->regs[3] | RxENABLE); 429 - if (chan->netdevice) 430 - netif_carrier_on(chan->netdevice); 431 - } else { 432 - pr_info("%s: DCD lost\n", chan->dev->name); 433 - write_zsreg(chan, R3, chan->regs[3] & ~RxENABLE); 434 - z8530_flush_fifo(chan); 435 - if (chan->netdevice) 436 - netif_carrier_off(chan->netdevice); 437 - } 438 - } 439 - write_zsctrl(chan, RES_EXT_INT); 440 - write_zsctrl(chan, RES_H_IUS); 441 - } 442 - 443 - struct z8530_irqhandler z8530_sync = { 444 - .rx = z8530_rx, 445 - .tx = z8530_tx, 446 - .status = z8530_status, 447 - }; 448 - EXPORT_SYMBOL(z8530_sync); 449 - 450 - /** 451 - * z8530_dma_rx - Handle a DMA RX event 452 - * @chan: Channel to handle 453 - * 454 - * Non bus mastering DMA interfaces for the Z8x30 devices. This 455 - * is really pretty PC specific. The DMA mode means that most receive 456 - * events are handled by the DMA hardware. We get a kick here only if 457 - * a frame ended. 458 - */ 459 - 460 - static void z8530_dma_rx(struct z8530_channel *chan) 461 - { 462 - if (chan->rxdma_on) { 463 - /* Special condition check only */ 464 - u8 status; 465 - 466 - read_zsreg(chan, R7); 467 - read_zsreg(chan, R6); 468 - 469 - status = read_zsreg(chan, R1); 470 - 471 - if (status & END_FR) 472 - z8530_rx_done(chan); /* Fire up the next one */ 473 - 474 - write_zsctrl(chan, ERR_RES); 475 - write_zsctrl(chan, RES_H_IUS); 476 - } else { 477 - /* DMA is off right now, drain the slow way */ 478 - z8530_rx(chan); 479 - } 480 - } 481 - 482 - /** 483 - * z8530_dma_tx - Handle a DMA TX event 484 - * @chan: The Z8530 channel to handle 485 - * 486 - * We have received an interrupt while doing DMA transmissions. It 487 - * shouldn't happen. Scream loudly if it does. 488 - */ 489 - static void z8530_dma_tx(struct z8530_channel *chan) 490 - { 491 - if (!chan->dma_tx) { 492 - pr_warn("Hey who turned the DMA off?\n"); 493 - z8530_tx(chan); 494 - return; 495 - } 496 - /* This shouldn't occur in DMA mode */ 497 - pr_err("DMA tx - bogus event!\n"); 498 - z8530_tx(chan); 499 - } 500 - 501 - /** 502 - * z8530_dma_status - Handle a DMA status exception 503 - * @chan: Z8530 channel to process 504 - * 505 - * A status event occurred on the Z8530. We receive these for two reasons 506 - * when in DMA mode. Firstly if we finished a packet transfer we get one 507 - * and kick the next packet out. Secondly we may see a DCD change. 508 - * 509 - */ 510 - static void z8530_dma_status(struct z8530_channel *chan) 511 - { 512 - u8 status, altered; 513 - 514 - status = read_zsreg(chan, R0); 515 - altered = chan->status ^ status; 516 - 517 - chan->status = status; 518 - 519 - if (chan->dma_tx) { 520 - if (status & TxEOM) { 521 - unsigned long flags; 522 - 523 - flags = claim_dma_lock(); 524 - disable_dma(chan->txdma); 525 - clear_dma_ff(chan->txdma); 526 - chan->txdma_on = 0; 527 - release_dma_lock(flags); 528 - z8530_tx_done(chan); 529 - } 530 - } 531 - 532 - if (altered & chan->dcdcheck) { 533 - if (status & chan->dcdcheck) { 534 - pr_info("%s: DCD raised\n", chan->dev->name); 535 - write_zsreg(chan, R3, chan->regs[3] | RxENABLE); 536 - if (chan->netdevice) 537 - netif_carrier_on(chan->netdevice); 538 - } else { 539 - pr_info("%s: DCD lost\n", chan->dev->name); 540 - write_zsreg(chan, R3, chan->regs[3] & ~RxENABLE); 541 - z8530_flush_fifo(chan); 542 - if (chan->netdevice) 543 - netif_carrier_off(chan->netdevice); 544 - } 545 - } 546 - 547 - write_zsctrl(chan, RES_EXT_INT); 548 - write_zsctrl(chan, RES_H_IUS); 549 - } 550 - 551 - static struct z8530_irqhandler z8530_dma_sync = { 552 - .rx = z8530_dma_rx, 553 - .tx = z8530_dma_tx, 554 - .status = z8530_dma_status, 555 - }; 556 - 557 - static struct z8530_irqhandler z8530_txdma_sync = { 558 - .rx = z8530_rx, 559 - .tx = z8530_dma_tx, 560 - .status = z8530_dma_status, 561 - }; 562 - 563 - /** 564 - * z8530_rx_clear - Handle RX events from a stopped chip 565 - * @c: Z8530 channel to shut up 566 - * 567 - * Receive interrupt vectors for a Z8530 that is in 'parked' mode. 568 - * For machines with PCI Z85x30 cards, or level triggered interrupts 569 - * (eg the MacII) we must clear the interrupt cause or die. 570 - */ 571 - 572 - static void z8530_rx_clear(struct z8530_channel *c) 573 - { 574 - /* Data and status bytes 575 - */ 576 - u8 stat; 577 - 578 - read_zsdata(c); 579 - stat = read_zsreg(c, R1); 580 - 581 - if (stat & END_FR) 582 - write_zsctrl(c, RES_Rx_CRC); 583 - /* Clear irq 584 - */ 585 - write_zsctrl(c, ERR_RES); 586 - write_zsctrl(c, RES_H_IUS); 587 - } 588 - 589 - /** 590 - * z8530_tx_clear - Handle TX events from a stopped chip 591 - * @c: Z8530 channel to shut up 592 - * 593 - * Transmit interrupt vectors for a Z8530 that is in 'parked' mode. 594 - * For machines with PCI Z85x30 cards, or level triggered interrupts 595 - * (eg the MacII) we must clear the interrupt cause or die. 596 - */ 597 - 598 - static void z8530_tx_clear(struct z8530_channel *c) 599 - { 600 - write_zsctrl(c, RES_Tx_P); 601 - write_zsctrl(c, RES_H_IUS); 602 - } 603 - 604 - /** 605 - * z8530_status_clear - Handle status events from a stopped chip 606 - * @chan: Z8530 channel to shut up 607 - * 608 - * Status interrupt vectors for a Z8530 that is in 'parked' mode. 609 - * For machines with PCI Z85x30 cards, or level triggered interrupts 610 - * (eg the MacII) we must clear the interrupt cause or die. 611 - */ 612 - 613 - static void z8530_status_clear(struct z8530_channel *chan) 614 - { 615 - u8 status = read_zsreg(chan, R0); 616 - 617 - if (status & TxEOM) 618 - write_zsctrl(chan, ERR_RES); 619 - write_zsctrl(chan, RES_EXT_INT); 620 - write_zsctrl(chan, RES_H_IUS); 621 - } 622 - 623 - struct z8530_irqhandler z8530_nop = { 624 - .rx = z8530_rx_clear, 625 - .tx = z8530_tx_clear, 626 - .status = z8530_status_clear, 627 - }; 628 - EXPORT_SYMBOL(z8530_nop); 629 - 630 - /** 631 - * z8530_interrupt - Handle an interrupt from a Z8530 632 - * @irq: Interrupt number 633 - * @dev_id: The Z8530 device that is interrupting. 634 - * 635 - * A Z85[2]30 device has stuck its hand in the air for attention. 636 - * We scan both the channels on the chip for events and then call 637 - * the channel specific call backs for each channel that has events. 638 - * We have to use callback functions because the two channels can be 639 - * in different modes. 640 - * 641 - * Locking is done for the handlers. Note that locking is done 642 - * at the chip level (the 5uS delay issue is per chip not per 643 - * channel). c->lock for both channels points to dev->lock 644 - */ 645 - 646 - irqreturn_t z8530_interrupt(int irq, void *dev_id) 647 - { 648 - struct z8530_dev *dev = dev_id; 649 - u8 intr; 650 - static volatile int locker=0; 651 - int work = 0; 652 - struct z8530_irqhandler *irqs; 653 - 654 - if (locker) { 655 - pr_err("IRQ re-enter\n"); 656 - return IRQ_NONE; 657 - } 658 - locker = 1; 659 - 660 - spin_lock(&dev->lock); 661 - 662 - while (++work < 5000) { 663 - intr = read_zsreg(&dev->chanA, R3); 664 - if (!(intr & 665 - (CHARxIP | CHATxIP | CHAEXT | CHBRxIP | CHBTxIP | CHBEXT))) 666 - break; 667 - 668 - /* This holds the IRQ status. On the 8530 you must read it 669 - * from chan A even though it applies to the whole chip 670 - */ 671 - 672 - /* Now walk the chip and see what it is wanting - it may be 673 - * an IRQ for someone else remember 674 - */ 675 - 676 - irqs = dev->chanA.irqs; 677 - 678 - if (intr & (CHARxIP | CHATxIP | CHAEXT)) { 679 - if (intr & CHARxIP) 680 - irqs->rx(&dev->chanA); 681 - if (intr & CHATxIP) 682 - irqs->tx(&dev->chanA); 683 - if (intr & CHAEXT) 684 - irqs->status(&dev->chanA); 685 - } 686 - 687 - irqs = dev->chanB.irqs; 688 - 689 - if (intr & (CHBRxIP | CHBTxIP | CHBEXT)) { 690 - if (intr & CHBRxIP) 691 - irqs->rx(&dev->chanB); 692 - if (intr & CHBTxIP) 693 - irqs->tx(&dev->chanB); 694 - if (intr & CHBEXT) 695 - irqs->status(&dev->chanB); 696 - } 697 - } 698 - spin_unlock(&dev->lock); 699 - if (work == 5000) 700 - pr_err("%s: interrupt jammed - abort(0x%X)!\n", 701 - dev->name, intr); 702 - /* Ok all done */ 703 - locker = 0; 704 - return IRQ_HANDLED; 705 - } 706 - EXPORT_SYMBOL(z8530_interrupt); 707 - 708 - static const u8 reg_init[16] = { 709 - 0, 0, 0, 0, 710 - 0, 0, 0, 0, 711 - 0, 0, 0, 0, 712 - 0x55, 0, 0, 0 713 - }; 714 - 715 - /** 716 - * z8530_sync_open - Open a Z8530 channel for PIO 717 - * @dev: The network interface we are using 718 - * @c: The Z8530 channel to open in synchronous PIO mode 719 - * 720 - * Switch a Z8530 into synchronous mode without DMA assist. We 721 - * raise the RTS/DTR and commence network operation. 722 - */ 723 - int z8530_sync_open(struct net_device *dev, struct z8530_channel *c) 724 - { 725 - unsigned long flags; 726 - 727 - spin_lock_irqsave(c->lock, flags); 728 - 729 - c->sync = 1; 730 - c->mtu = dev->mtu + 64; 731 - c->count = 0; 732 - c->skb = NULL; 733 - c->skb2 = NULL; 734 - c->irqs = &z8530_sync; 735 - 736 - /* This loads the double buffer up */ 737 - z8530_rx_done(c); /* Load the frame ring */ 738 - z8530_rx_done(c); /* Load the backup frame */ 739 - z8530_rtsdtr(c, 1); 740 - c->dma_tx = 0; 741 - c->regs[R1] |= TxINT_ENAB; 742 - write_zsreg(c, R1, c->regs[R1]); 743 - write_zsreg(c, R3, c->regs[R3] | RxENABLE); 744 - 745 - spin_unlock_irqrestore(c->lock, flags); 746 - return 0; 747 - } 748 - EXPORT_SYMBOL(z8530_sync_open); 749 - 750 - /** 751 - * z8530_sync_close - Close a PIO Z8530 channel 752 - * @dev: Network device to close 753 - * @c: Z8530 channel to disassociate and move to idle 754 - * 755 - * Close down a Z8530 interface and switch its interrupt handlers 756 - * to discard future events. 757 - */ 758 - int z8530_sync_close(struct net_device *dev, struct z8530_channel *c) 759 - { 760 - u8 chk; 761 - unsigned long flags; 762 - 763 - spin_lock_irqsave(c->lock, flags); 764 - c->irqs = &z8530_nop; 765 - c->max = 0; 766 - c->sync = 0; 767 - 768 - chk = read_zsreg(c, R0); 769 - write_zsreg(c, R3, c->regs[R3]); 770 - z8530_rtsdtr(c, 0); 771 - 772 - spin_unlock_irqrestore(c->lock, flags); 773 - return 0; 774 - } 775 - EXPORT_SYMBOL(z8530_sync_close); 776 - 777 - /** 778 - * z8530_sync_dma_open - Open a Z8530 for DMA I/O 779 - * @dev: The network device to attach 780 - * @c: The Z8530 channel to configure in sync DMA mode. 781 - * 782 - * Set up a Z85x30 device for synchronous DMA in both directions. Two 783 - * ISA DMA channels must be available for this to work. We assume ISA 784 - * DMA driven I/O and PC limits on access. 785 - */ 786 - int z8530_sync_dma_open(struct net_device *dev, struct z8530_channel *c) 787 - { 788 - unsigned long cflags, dflags; 789 - 790 - c->sync = 1; 791 - c->mtu = dev->mtu + 64; 792 - c->count = 0; 793 - c->skb = NULL; 794 - c->skb2 = NULL; 795 - 796 - /* Load the DMA interfaces up 797 - */ 798 - c->rxdma_on = 0; 799 - c->txdma_on = 0; 800 - 801 - /* Allocate the DMA flip buffers. Limit by page size. 802 - * Everyone runs 1500 mtu or less on wan links so this 803 - * should be fine. 804 - */ 805 - 806 - if (c->mtu > PAGE_SIZE / 2) 807 - return -EMSGSIZE; 808 - 809 - c->rx_buf[0] = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA); 810 - if (!c->rx_buf[0]) 811 - return -ENOBUFS; 812 - c->rx_buf[1] = c->rx_buf[0] + PAGE_SIZE / 2; 813 - 814 - c->tx_dma_buf[0] = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA); 815 - if (!c->tx_dma_buf[0]) { 816 - free_page((unsigned long)c->rx_buf[0]); 817 - c->rx_buf[0] = NULL; 818 - return -ENOBUFS; 819 - } 820 - c->tx_dma_buf[1] = c->tx_dma_buf[0] + PAGE_SIZE / 2; 821 - 822 - c->tx_dma_used = 0; 823 - c->dma_tx = 1; 824 - c->dma_num = 0; 825 - c->dma_ready = 1; 826 - 827 - /* Enable DMA control mode 828 - */ 829 - 830 - spin_lock_irqsave(c->lock, cflags); 831 - 832 - /* TX DMA via DIR/REQ 833 - */ 834 - 835 - c->regs[R14] |= DTRREQ; 836 - write_zsreg(c, R14, c->regs[R14]); 837 - 838 - c->regs[R1] &= ~TxINT_ENAB; 839 - write_zsreg(c, R1, c->regs[R1]); 840 - 841 - /* RX DMA via W/Req 842 - */ 843 - 844 - c->regs[R1] |= WT_FN_RDYFN; 845 - c->regs[R1] |= WT_RDY_RT; 846 - c->regs[R1] |= INT_ERR_Rx; 847 - c->regs[R1] &= ~TxINT_ENAB; 848 - write_zsreg(c, R1, c->regs[R1]); 849 - c->regs[R1] |= WT_RDY_ENAB; 850 - write_zsreg(c, R1, c->regs[R1]); 851 - 852 - /* DMA interrupts 853 - */ 854 - 855 - /* Set up the DMA configuration 856 - */ 857 - 858 - dflags = claim_dma_lock(); 859 - 860 - disable_dma(c->rxdma); 861 - clear_dma_ff(c->rxdma); 862 - set_dma_mode(c->rxdma, DMA_MODE_READ | 0x10); 863 - set_dma_addr(c->rxdma, virt_to_bus(c->rx_buf[0])); 864 - set_dma_count(c->rxdma, c->mtu); 865 - enable_dma(c->rxdma); 866 - 867 - disable_dma(c->txdma); 868 - clear_dma_ff(c->txdma); 869 - set_dma_mode(c->txdma, DMA_MODE_WRITE); 870 - disable_dma(c->txdma); 871 - 872 - release_dma_lock(dflags); 873 - 874 - /* Select the DMA interrupt handlers 875 - */ 876 - 877 - c->rxdma_on = 1; 878 - c->txdma_on = 1; 879 - c->tx_dma_used = 1; 880 - 881 - c->irqs = &z8530_dma_sync; 882 - z8530_rtsdtr(c, 1); 883 - write_zsreg(c, R3, c->regs[R3] | RxENABLE); 884 - 885 - spin_unlock_irqrestore(c->lock, cflags); 886 - 887 - return 0; 888 - } 889 - EXPORT_SYMBOL(z8530_sync_dma_open); 890 - 891 - /** 892 - * z8530_sync_dma_close - Close down DMA I/O 893 - * @dev: Network device to detach 894 - * @c: Z8530 channel to move into discard mode 895 - * 896 - * Shut down a DMA mode synchronous interface. Halt the DMA, and 897 - * free the buffers. 898 - */ 899 - int z8530_sync_dma_close(struct net_device *dev, struct z8530_channel *c) 900 - { 901 - u8 chk; 902 - unsigned long flags; 903 - 904 - c->irqs = &z8530_nop; 905 - c->max = 0; 906 - c->sync = 0; 907 - 908 - /* Disable the PC DMA channels 909 - */ 910 - 911 - flags = claim_dma_lock(); 912 - disable_dma(c->rxdma); 913 - clear_dma_ff(c->rxdma); 914 - 915 - c->rxdma_on = 0; 916 - 917 - disable_dma(c->txdma); 918 - clear_dma_ff(c->txdma); 919 - release_dma_lock(flags); 920 - 921 - c->txdma_on = 0; 922 - c->tx_dma_used = 0; 923 - 924 - spin_lock_irqsave(c->lock, flags); 925 - 926 - /* Disable DMA control mode 927 - */ 928 - 929 - c->regs[R1] &= ~WT_RDY_ENAB; 930 - write_zsreg(c, R1, c->regs[R1]); 931 - c->regs[R1] &= ~(WT_RDY_RT | WT_FN_RDYFN | INT_ERR_Rx); 932 - c->regs[R1] |= INT_ALL_Rx; 933 - write_zsreg(c, R1, c->regs[R1]); 934 - c->regs[R14] &= ~DTRREQ; 935 - write_zsreg(c, R14, c->regs[R14]); 936 - 937 - if (c->rx_buf[0]) { 938 - free_page((unsigned long)c->rx_buf[0]); 939 - c->rx_buf[0] = NULL; 940 - } 941 - if (c->tx_dma_buf[0]) { 942 - free_page((unsigned long)c->tx_dma_buf[0]); 943 - c->tx_dma_buf[0] = NULL; 944 - } 945 - chk = read_zsreg(c, R0); 946 - write_zsreg(c, R3, c->regs[R3]); 947 - z8530_rtsdtr(c, 0); 948 - 949 - spin_unlock_irqrestore(c->lock, flags); 950 - 951 - return 0; 952 - } 953 - EXPORT_SYMBOL(z8530_sync_dma_close); 954 - 955 - /** 956 - * z8530_sync_txdma_open - Open a Z8530 for TX driven DMA 957 - * @dev: The network device to attach 958 - * @c: The Z8530 channel to configure in sync DMA mode. 959 - * 960 - * Set up a Z85x30 device for synchronous DMA transmission. One 961 - * ISA DMA channel must be available for this to work. The receive 962 - * side is run in PIO mode, but then it has the bigger FIFO. 963 - */ 964 - 965 - int z8530_sync_txdma_open(struct net_device *dev, struct z8530_channel *c) 966 - { 967 - unsigned long cflags, dflags; 968 - 969 - printk("Opening sync interface for TX-DMA\n"); 970 - c->sync = 1; 971 - c->mtu = dev->mtu + 64; 972 - c->count = 0; 973 - c->skb = NULL; 974 - c->skb2 = NULL; 975 - 976 - /* Allocate the DMA flip buffers. Limit by page size. 977 - * Everyone runs 1500 mtu or less on wan links so this 978 - * should be fine. 979 - */ 980 - 981 - if (c->mtu > PAGE_SIZE / 2) 982 - return -EMSGSIZE; 983 - 984 - c->tx_dma_buf[0] = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA); 985 - if (!c->tx_dma_buf[0]) 986 - return -ENOBUFS; 987 - 988 - c->tx_dma_buf[1] = c->tx_dma_buf[0] + PAGE_SIZE / 2; 989 - 990 - spin_lock_irqsave(c->lock, cflags); 991 - 992 - /* Load the PIO receive ring 993 - */ 994 - 995 - z8530_rx_done(c); 996 - z8530_rx_done(c); 997 - 998 - /* Load the DMA interfaces up 999 - */ 1000 - 1001 - c->rxdma_on = 0; 1002 - c->txdma_on = 0; 1003 - 1004 - c->tx_dma_used = 0; 1005 - c->dma_num = 0; 1006 - c->dma_ready = 1; 1007 - c->dma_tx = 1; 1008 - 1009 - /* Enable DMA control mode 1010 - */ 1011 - 1012 - /* TX DMA via DIR/REQ 1013 - */ 1014 - c->regs[R14] |= DTRREQ; 1015 - write_zsreg(c, R14, c->regs[R14]); 1016 - 1017 - c->regs[R1] &= ~TxINT_ENAB; 1018 - write_zsreg(c, R1, c->regs[R1]); 1019 - 1020 - /* Set up the DMA configuration 1021 - */ 1022 - 1023 - dflags = claim_dma_lock(); 1024 - 1025 - disable_dma(c->txdma); 1026 - clear_dma_ff(c->txdma); 1027 - set_dma_mode(c->txdma, DMA_MODE_WRITE); 1028 - disable_dma(c->txdma); 1029 - 1030 - release_dma_lock(dflags); 1031 - 1032 - /* Select the DMA interrupt handlers 1033 - */ 1034 - 1035 - c->rxdma_on = 0; 1036 - c->txdma_on = 1; 1037 - c->tx_dma_used = 1; 1038 - 1039 - c->irqs = &z8530_txdma_sync; 1040 - z8530_rtsdtr(c, 1); 1041 - write_zsreg(c, R3, c->regs[R3] | RxENABLE); 1042 - spin_unlock_irqrestore(c->lock, cflags); 1043 - 1044 - return 0; 1045 - } 1046 - EXPORT_SYMBOL(z8530_sync_txdma_open); 1047 - 1048 - /** 1049 - * z8530_sync_txdma_close - Close down a TX driven DMA channel 1050 - * @dev: Network device to detach 1051 - * @c: Z8530 channel to move into discard mode 1052 - * 1053 - * Shut down a DMA/PIO split mode synchronous interface. Halt the DMA, 1054 - * and free the buffers. 1055 - */ 1056 - 1057 - int z8530_sync_txdma_close(struct net_device *dev, struct z8530_channel *c) 1058 - { 1059 - unsigned long dflags, cflags; 1060 - u8 chk; 1061 - 1062 - spin_lock_irqsave(c->lock, cflags); 1063 - 1064 - c->irqs = &z8530_nop; 1065 - c->max = 0; 1066 - c->sync = 0; 1067 - 1068 - /* Disable the PC DMA channels 1069 - */ 1070 - 1071 - dflags = claim_dma_lock(); 1072 - 1073 - disable_dma(c->txdma); 1074 - clear_dma_ff(c->txdma); 1075 - c->txdma_on = 0; 1076 - c->tx_dma_used = 0; 1077 - 1078 - release_dma_lock(dflags); 1079 - 1080 - /* Disable DMA control mode 1081 - */ 1082 - 1083 - c->regs[R1] &= ~WT_RDY_ENAB; 1084 - write_zsreg(c, R1, c->regs[R1]); 1085 - c->regs[R1] &= ~(WT_RDY_RT | WT_FN_RDYFN | INT_ERR_Rx); 1086 - c->regs[R1] |= INT_ALL_Rx; 1087 - write_zsreg(c, R1, c->regs[R1]); 1088 - c->regs[R14] &= ~DTRREQ; 1089 - write_zsreg(c, R14, c->regs[R14]); 1090 - 1091 - if (c->tx_dma_buf[0]) { 1092 - free_page((unsigned long)c->tx_dma_buf[0]); 1093 - c->tx_dma_buf[0] = NULL; 1094 - } 1095 - chk = read_zsreg(c, R0); 1096 - write_zsreg(c, R3, c->regs[R3]); 1097 - z8530_rtsdtr(c, 0); 1098 - 1099 - spin_unlock_irqrestore(c->lock, cflags); 1100 - return 0; 1101 - } 1102 - EXPORT_SYMBOL(z8530_sync_txdma_close); 1103 - 1104 - /* Name strings for Z8530 chips. SGI claim to have a 130, Zilog deny 1105 - * it exists... 1106 - */ 1107 - static const char * const z8530_type_name[] = { 1108 - "Z8530", 1109 - "Z85C30", 1110 - "Z85230" 1111 - }; 1112 - 1113 - /** 1114 - * z8530_describe - Uniformly describe a Z8530 port 1115 - * @dev: Z8530 device to describe 1116 - * @mapping: string holding mapping type (eg "I/O" or "Mem") 1117 - * @io: the port value in question 1118 - * 1119 - * Describe a Z8530 in a standard format. We must pass the I/O as 1120 - * the port offset isn't predictable. The main reason for this function 1121 - * is to try and get a common format of report. 1122 - */ 1123 - 1124 - void z8530_describe(struct z8530_dev *dev, char *mapping, unsigned long io) 1125 - { 1126 - pr_info("%s: %s found at %s 0x%lX, IRQ %d\n", 1127 - dev->name, 1128 - z8530_type_name[dev->type], 1129 - mapping, 1130 - Z8530_PORT_OF(io), 1131 - dev->irq); 1132 - } 1133 - EXPORT_SYMBOL(z8530_describe); 1134 - 1135 - /* Locked operation part of the z8530 init code 1136 - */ 1137 - static inline int do_z8530_init(struct z8530_dev *dev) 1138 - { 1139 - /* NOP the interrupt handlers first - we might get a 1140 - * floating IRQ transition when we reset the chip 1141 - */ 1142 - dev->chanA.irqs = &z8530_nop; 1143 - dev->chanB.irqs = &z8530_nop; 1144 - dev->chanA.dcdcheck = DCD; 1145 - dev->chanB.dcdcheck = DCD; 1146 - 1147 - /* Reset the chip */ 1148 - write_zsreg(&dev->chanA, R9, 0xC0); 1149 - udelay(200); 1150 - /* Now check its valid */ 1151 - write_zsreg(&dev->chanA, R12, 0xAA); 1152 - if (read_zsreg(&dev->chanA, R12) != 0xAA) 1153 - return -ENODEV; 1154 - write_zsreg(&dev->chanA, R12, 0x55); 1155 - if (read_zsreg(&dev->chanA, R12) != 0x55) 1156 - return -ENODEV; 1157 - 1158 - dev->type = Z8530; 1159 - 1160 - /* See the application note. 1161 - */ 1162 - 1163 - write_zsreg(&dev->chanA, R15, 0x01); 1164 - 1165 - /* If we can set the low bit of R15 then 1166 - * the chip is enhanced. 1167 - */ 1168 - 1169 - if (read_zsreg(&dev->chanA, R15) == 0x01) { 1170 - /* This C30 versus 230 detect is from Klaus Kudielka's dmascc */ 1171 - /* Put a char in the fifo */ 1172 - write_zsreg(&dev->chanA, R8, 0); 1173 - if (read_zsreg(&dev->chanA, R0) & Tx_BUF_EMP) 1174 - dev->type = Z85230; /* Has a FIFO */ 1175 - else 1176 - dev->type = Z85C30; /* Z85C30, 1 byte FIFO */ 1177 - } 1178 - 1179 - /* The code assumes R7' and friends are 1180 - * off. Use write_zsext() for these and keep 1181 - * this bit clear. 1182 - */ 1183 - 1184 - write_zsreg(&dev->chanA, R15, 0); 1185 - 1186 - /* At this point it looks like the chip is behaving 1187 - */ 1188 - 1189 - memcpy(dev->chanA.regs, reg_init, 16); 1190 - memcpy(dev->chanB.regs, reg_init, 16); 1191 - 1192 - return 0; 1193 - } 1194 - 1195 - /** 1196 - * z8530_init - Initialise a Z8530 device 1197 - * @dev: Z8530 device to initialise. 1198 - * 1199 - * Configure up a Z8530/Z85C30 or Z85230 chip. We check the device 1200 - * is present, identify the type and then program it to hopefully 1201 - * keep quite and behave. This matters a lot, a Z8530 in the wrong 1202 - * state will sometimes get into stupid modes generating 10Khz 1203 - * interrupt streams and the like. 1204 - * 1205 - * We set the interrupt handler up to discard any events, in case 1206 - * we get them during reset or setp. 1207 - * 1208 - * Return 0 for success, or a negative value indicating the problem 1209 - * in errno form. 1210 - */ 1211 - 1212 - int z8530_init(struct z8530_dev *dev) 1213 - { 1214 - unsigned long flags; 1215 - int ret; 1216 - 1217 - /* Set up the chip level lock */ 1218 - spin_lock_init(&dev->lock); 1219 - dev->chanA.lock = &dev->lock; 1220 - dev->chanB.lock = &dev->lock; 1221 - 1222 - spin_lock_irqsave(&dev->lock, flags); 1223 - ret = do_z8530_init(dev); 1224 - spin_unlock_irqrestore(&dev->lock, flags); 1225 - 1226 - return ret; 1227 - } 1228 - EXPORT_SYMBOL(z8530_init); 1229 - 1230 - /** 1231 - * z8530_shutdown - Shutdown a Z8530 device 1232 - * @dev: The Z8530 chip to shutdown 1233 - * 1234 - * We set the interrupt handlers to silence any interrupts. We then 1235 - * reset the chip and wait 100uS to be sure the reset completed. Just 1236 - * in case the caller then tries to do stuff. 1237 - * 1238 - * This is called without the lock held 1239 - */ 1240 - int z8530_shutdown(struct z8530_dev *dev) 1241 - { 1242 - unsigned long flags; 1243 - /* Reset the chip */ 1244 - 1245 - spin_lock_irqsave(&dev->lock, flags); 1246 - dev->chanA.irqs = &z8530_nop; 1247 - dev->chanB.irqs = &z8530_nop; 1248 - write_zsreg(&dev->chanA, R9, 0xC0); 1249 - /* We must lock the udelay, the chip is offlimits here */ 1250 - udelay(100); 1251 - spin_unlock_irqrestore(&dev->lock, flags); 1252 - return 0; 1253 - } 1254 - EXPORT_SYMBOL(z8530_shutdown); 1255 - 1256 - /** 1257 - * z8530_channel_load - Load channel data 1258 - * @c: Z8530 channel to configure 1259 - * @rtable: table of register, value pairs 1260 - * FIXME: ioctl to allow user uploaded tables 1261 - * 1262 - * Load a Z8530 channel up from the system data. We use +16 to 1263 - * indicate the "prime" registers. The value 255 terminates the 1264 - * table. 1265 - */ 1266 - 1267 - int z8530_channel_load(struct z8530_channel *c, u8 *rtable) 1268 - { 1269 - unsigned long flags; 1270 - 1271 - spin_lock_irqsave(c->lock, flags); 1272 - 1273 - while (*rtable != 255) { 1274 - int reg = *rtable++; 1275 - 1276 - if (reg > 0x0F) 1277 - write_zsreg(c, R15, c->regs[15] | 1); 1278 - write_zsreg(c, reg & 0x0F, *rtable); 1279 - if (reg > 0x0F) 1280 - write_zsreg(c, R15, c->regs[15] & ~1); 1281 - c->regs[reg] = *rtable++; 1282 - } 1283 - c->rx_function = z8530_null_rx; 1284 - c->skb = NULL; 1285 - c->tx_skb = NULL; 1286 - c->tx_next_skb = NULL; 1287 - c->mtu = 1500; 1288 - c->max = 0; 1289 - c->count = 0; 1290 - c->status = read_zsreg(c, R0); 1291 - c->sync = 1; 1292 - write_zsreg(c, R3, c->regs[R3] | RxENABLE); 1293 - 1294 - spin_unlock_irqrestore(c->lock, flags); 1295 - return 0; 1296 - } 1297 - EXPORT_SYMBOL(z8530_channel_load); 1298 - 1299 - /** 1300 - * z8530_tx_begin - Begin packet transmission 1301 - * @c: The Z8530 channel to kick 1302 - * 1303 - * This is the speed sensitive side of transmission. If we are called 1304 - * and no buffer is being transmitted we commence the next buffer. If 1305 - * nothing is queued we idle the sync. 1306 - * 1307 - * Note: We are handling this code path in the interrupt path, keep it 1308 - * fast or bad things will happen. 1309 - * 1310 - * Called with the lock held. 1311 - */ 1312 - 1313 - static void z8530_tx_begin(struct z8530_channel *c) 1314 - { 1315 - unsigned long flags; 1316 - 1317 - if (c->tx_skb) 1318 - return; 1319 - 1320 - c->tx_skb = c->tx_next_skb; 1321 - c->tx_next_skb = NULL; 1322 - c->tx_ptr = c->tx_next_ptr; 1323 - 1324 - if (!c->tx_skb) { 1325 - /* Idle on */ 1326 - if (c->dma_tx) { 1327 - flags = claim_dma_lock(); 1328 - disable_dma(c->txdma); 1329 - /* Check if we crapped out. 1330 - */ 1331 - if (get_dma_residue(c->txdma)) { 1332 - c->netdevice->stats.tx_dropped++; 1333 - c->netdevice->stats.tx_fifo_errors++; 1334 - } 1335 - release_dma_lock(flags); 1336 - } 1337 - c->txcount = 0; 1338 - } else { 1339 - c->txcount = c->tx_skb->len; 1340 - 1341 - if (c->dma_tx) { 1342 - /* FIXME. DMA is broken for the original 8530, 1343 - * on the older parts we need to set a flag and 1344 - * wait for a further TX interrupt to fire this 1345 - * stage off 1346 - */ 1347 - 1348 - flags = claim_dma_lock(); 1349 - disable_dma(c->txdma); 1350 - 1351 - /* These two are needed by the 8530/85C30 1352 - * and must be issued when idling. 1353 - */ 1354 - if (c->dev->type != Z85230) { 1355 - write_zsctrl(c, RES_Tx_CRC); 1356 - write_zsctrl(c, RES_EOM_L); 1357 - } 1358 - write_zsreg(c, R10, c->regs[10] & ~ABUNDER); 1359 - clear_dma_ff(c->txdma); 1360 - set_dma_addr(c->txdma, virt_to_bus(c->tx_ptr)); 1361 - set_dma_count(c->txdma, c->txcount); 1362 - enable_dma(c->txdma); 1363 - release_dma_lock(flags); 1364 - write_zsctrl(c, RES_EOM_L); 1365 - write_zsreg(c, R5, c->regs[R5] | TxENAB); 1366 - } else { 1367 - /* ABUNDER off */ 1368 - write_zsreg(c, R10, c->regs[10]); 1369 - write_zsctrl(c, RES_Tx_CRC); 1370 - 1371 - while (c->txcount && (read_zsreg(c, R0) & Tx_BUF_EMP)) { 1372 - write_zsreg(c, R8, *c->tx_ptr++); 1373 - c->txcount--; 1374 - } 1375 - } 1376 - } 1377 - /* Since we emptied tx_skb we can ask for more 1378 - */ 1379 - netif_wake_queue(c->netdevice); 1380 - } 1381 - 1382 - /** 1383 - * z8530_tx_done - TX complete callback 1384 - * @c: The channel that completed a transmit. 1385 - * 1386 - * This is called when we complete a packet send. We wake the queue, 1387 - * start the next packet going and then free the buffer of the existing 1388 - * packet. This code is fairly timing sensitive. 1389 - * 1390 - * Called with the register lock held. 1391 - */ 1392 - 1393 - static void z8530_tx_done(struct z8530_channel *c) 1394 - { 1395 - struct sk_buff *skb; 1396 - 1397 - /* Actually this can happen.*/ 1398 - if (!c->tx_skb) 1399 - return; 1400 - 1401 - skb = c->tx_skb; 1402 - c->tx_skb = NULL; 1403 - z8530_tx_begin(c); 1404 - c->netdevice->stats.tx_packets++; 1405 - c->netdevice->stats.tx_bytes += skb->len; 1406 - dev_consume_skb_irq(skb); 1407 - } 1408 - 1409 - /** 1410 - * z8530_null_rx - Discard a packet 1411 - * @c: The channel the packet arrived on 1412 - * @skb: The buffer 1413 - * 1414 - * We point the receive handler at this function when idle. Instead 1415 - * of processing the frames we get to throw them away. 1416 - */ 1417 - void z8530_null_rx(struct z8530_channel *c, struct sk_buff *skb) 1418 - { 1419 - dev_kfree_skb_any(skb); 1420 - } 1421 - EXPORT_SYMBOL(z8530_null_rx); 1422 - 1423 - /** 1424 - * z8530_rx_done - Receive completion callback 1425 - * @c: The channel that completed a receive 1426 - * 1427 - * A new packet is complete. Our goal here is to get back into receive 1428 - * mode as fast as possible. On the Z85230 we could change to using 1429 - * ESCC mode, but on the older chips we have no choice. We flip to the 1430 - * new buffer immediately in DMA mode so that the DMA of the next 1431 - * frame can occur while we are copying the previous buffer to an sk_buff 1432 - * 1433 - * Called with the lock held 1434 - */ 1435 - static void z8530_rx_done(struct z8530_channel *c) 1436 - { 1437 - struct sk_buff *skb; 1438 - int ct; 1439 - 1440 - /* Is our receive engine in DMA mode 1441 - */ 1442 - if (c->rxdma_on) { 1443 - /* Save the ready state and the buffer currently 1444 - * being used as the DMA target 1445 - */ 1446 - int ready = c->dma_ready; 1447 - unsigned char *rxb = c->rx_buf[c->dma_num]; 1448 - unsigned long flags; 1449 - 1450 - /* Complete this DMA. Necessary to find the length 1451 - */ 1452 - flags = claim_dma_lock(); 1453 - 1454 - disable_dma(c->rxdma); 1455 - clear_dma_ff(c->rxdma); 1456 - c->rxdma_on = 0; 1457 - ct = c->mtu - get_dma_residue(c->rxdma); 1458 - if (ct < 0) 1459 - ct = 2; /* Shit happens.. */ 1460 - c->dma_ready = 0; 1461 - 1462 - /* Normal case: the other slot is free, start the next DMA 1463 - * into it immediately. 1464 - */ 1465 - 1466 - if (ready) { 1467 - c->dma_num ^= 1; 1468 - set_dma_mode(c->rxdma, DMA_MODE_READ | 0x10); 1469 - set_dma_addr(c->rxdma, virt_to_bus(c->rx_buf[c->dma_num])); 1470 - set_dma_count(c->rxdma, c->mtu); 1471 - c->rxdma_on = 1; 1472 - enable_dma(c->rxdma); 1473 - /* Stop any frames that we missed the head of 1474 - * from passing 1475 - */ 1476 - write_zsreg(c, R0, RES_Rx_CRC); 1477 - } else { 1478 - /* Can't occur as we dont reenable the DMA irq until 1479 - * after the flip is done 1480 - */ 1481 - netdev_warn(c->netdevice, "DMA flip overrun!\n"); 1482 - } 1483 - 1484 - release_dma_lock(flags); 1485 - 1486 - /* Shove the old buffer into an sk_buff. We can't DMA 1487 - * directly into one on a PC - it might be above the 16Mb 1488 - * boundary. Optimisation - we could check to see if we 1489 - * can avoid the copy. Optimisation 2 - make the memcpy 1490 - * a copychecksum. 1491 - */ 1492 - 1493 - skb = dev_alloc_skb(ct); 1494 - if (!skb) { 1495 - c->netdevice->stats.rx_dropped++; 1496 - netdev_warn(c->netdevice, "Memory squeeze\n"); 1497 - } else { 1498 - skb_put(skb, ct); 1499 - skb_copy_to_linear_data(skb, rxb, ct); 1500 - c->netdevice->stats.rx_packets++; 1501 - c->netdevice->stats.rx_bytes += ct; 1502 - } 1503 - c->dma_ready = 1; 1504 - } else { 1505 - RT_LOCK; 1506 - skb = c->skb; 1507 - 1508 - /* The game we play for non DMA is similar. We want to 1509 - * get the controller set up for the next packet as fast 1510 - * as possible. We potentially only have one byte + the 1511 - * fifo length for this. Thus we want to flip to the new 1512 - * buffer and then mess around copying and allocating 1513 - * things. For the current case it doesn't matter but 1514 - * if you build a system where the sync irq isn't blocked 1515 - * by the kernel IRQ disable then you need only block the 1516 - * sync IRQ for the RT_LOCK area. 1517 - * 1518 - */ 1519 - ct = c->count; 1520 - 1521 - c->skb = c->skb2; 1522 - c->count = 0; 1523 - c->max = c->mtu; 1524 - if (c->skb) { 1525 - c->dptr = c->skb->data; 1526 - c->max = c->mtu; 1527 - } else { 1528 - c->count = 0; 1529 - c->max = 0; 1530 - } 1531 - RT_UNLOCK; 1532 - 1533 - c->skb2 = dev_alloc_skb(c->mtu); 1534 - if (c->skb2) 1535 - skb_put(c->skb2, c->mtu); 1536 - 1537 - c->netdevice->stats.rx_packets++; 1538 - c->netdevice->stats.rx_bytes += ct; 1539 - } 1540 - /* If we received a frame we must now process it. 1541 - */ 1542 - if (skb) { 1543 - skb_trim(skb, ct); 1544 - c->rx_function(c, skb); 1545 - } else { 1546 - c->netdevice->stats.rx_dropped++; 1547 - netdev_err(c->netdevice, "Lost a frame\n"); 1548 - } 1549 - } 1550 - 1551 - /** 1552 - * spans_boundary - Check a packet can be ISA DMA'd 1553 - * @skb: The buffer to check 1554 - * 1555 - * Returns true if the buffer cross a DMA boundary on a PC. The poor 1556 - * thing can only DMA within a 64K block not across the edges of it. 1557 - */ 1558 - 1559 - static inline int spans_boundary(struct sk_buff *skb) 1560 - { 1561 - unsigned long a = (unsigned long)skb->data; 1562 - 1563 - a ^= (a + skb->len); 1564 - if (a & 0x00010000) /* If the 64K bit is different.. */ 1565 - return 1; 1566 - return 0; 1567 - } 1568 - 1569 - /** 1570 - * z8530_queue_xmit - Queue a packet 1571 - * @c: The channel to use 1572 - * @skb: The packet to kick down the channel 1573 - * 1574 - * Queue a packet for transmission. Because we have rather 1575 - * hard to hit interrupt latencies for the Z85230 per packet 1576 - * even in DMA mode we do the flip to DMA buffer if needed here 1577 - * not in the IRQ. 1578 - * 1579 - * Called from the network code. The lock is not held at this 1580 - * point. 1581 - */ 1582 - netdev_tx_t z8530_queue_xmit(struct z8530_channel *c, struct sk_buff *skb) 1583 - { 1584 - unsigned long flags; 1585 - 1586 - netif_stop_queue(c->netdevice); 1587 - if (c->tx_next_skb) 1588 - return NETDEV_TX_BUSY; 1589 - 1590 - /* PC SPECIFIC - DMA limits */ 1591 - /* If we will DMA the transmit and its gone over the ISA bus 1592 - * limit, then copy to the flip buffer 1593 - */ 1594 - 1595 - if (c->dma_tx && 1596 - ((unsigned long)(virt_to_bus(skb->data + skb->len)) >= 1597 - 16 * 1024 * 1024 || spans_boundary(skb))) { 1598 - /* Send the flip buffer, and flip the flippy bit. 1599 - * We don't care which is used when just so long as 1600 - * we never use the same buffer twice in a row. Since 1601 - * only one buffer can be going out at a time the other 1602 - * has to be safe. 1603 - */ 1604 - c->tx_next_ptr = c->tx_dma_buf[c->tx_dma_used]; 1605 - c->tx_dma_used ^= 1; /* Flip temp buffer */ 1606 - skb_copy_from_linear_data(skb, c->tx_next_ptr, skb->len); 1607 - } else { 1608 - c->tx_next_ptr = skb->data; 1609 - } 1610 - RT_LOCK; 1611 - c->tx_next_skb = skb; 1612 - RT_UNLOCK; 1613 - 1614 - spin_lock_irqsave(c->lock, flags); 1615 - z8530_tx_begin(c); 1616 - spin_unlock_irqrestore(c->lock, flags); 1617 - 1618 - return NETDEV_TX_OK; 1619 - } 1620 - EXPORT_SYMBOL(z8530_queue_xmit); 1621 - 1622 - /* Module support 1623 - */ 1624 - static const char banner[] __initconst = 1625 - KERN_INFO "Generic Z85C30/Z85230 interface driver v0.02\n"; 1626 - 1627 - static int __init z85230_init_driver(void) 1628 - { 1629 - printk(banner); 1630 - return 0; 1631 - } 1632 - module_init(z85230_init_driver); 1633 - 1634 - static void __exit z85230_cleanup_driver(void) 1635 - { 1636 - } 1637 - module_exit(z85230_cleanup_driver); 1638 - 1639 - MODULE_AUTHOR("Red Hat Inc."); 1640 - MODULE_DESCRIPTION("Z85x30 synchronous driver core"); 1641 - MODULE_LICENSE("GPL");
-407
drivers/net/wan/z85230.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 */ 2 - /* 3 - * Description of Z8530 Z85C30 and Z85230 communications chips 4 - * 5 - * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) 6 - * Copyright (C) 1998 Alan Cox <alan@lxorguk.ukuu.org.uk> 7 - */ 8 - 9 - #ifndef _Z8530_H 10 - #define _Z8530_H 11 - 12 - #include <linux/tty.h> 13 - #include <linux/interrupt.h> 14 - 15 - /* Conversion routines to/from brg time constants from/to bits 16 - * per second. 17 - */ 18 - #define BRG_TO_BPS(brg, freq) ((freq) / 2 / ((brg) + 2)) 19 - #define BPS_TO_BRG(bps, freq) ((((freq) + (bps)) / (2 * (bps))) - 2) 20 - 21 - /* The Zilog register set */ 22 - 23 - #define FLAG 0x7e 24 - 25 - /* Write Register 0 */ 26 - #define R0 0 /* Register selects */ 27 - #define R1 1 28 - #define R2 2 29 - #define R3 3 30 - #define R4 4 31 - #define R5 5 32 - #define R6 6 33 - #define R7 7 34 - #define R8 8 35 - #define R9 9 36 - #define R10 10 37 - #define R11 11 38 - #define R12 12 39 - #define R13 13 40 - #define R14 14 41 - #define R15 15 42 - 43 - #define RPRIME 16 /* Indicate a prime register access on 230 */ 44 - 45 - #define NULLCODE 0 /* Null Code */ 46 - #define POINT_HIGH 0x8 /* Select upper half of registers */ 47 - #define RES_EXT_INT 0x10 /* Reset Ext. Status Interrupts */ 48 - #define SEND_ABORT 0x18 /* HDLC Abort */ 49 - #define RES_RxINT_FC 0x20 /* Reset RxINT on First Character */ 50 - #define RES_Tx_P 0x28 /* Reset TxINT Pending */ 51 - #define ERR_RES 0x30 /* Error Reset */ 52 - #define RES_H_IUS 0x38 /* Reset highest IUS */ 53 - 54 - #define RES_Rx_CRC 0x40 /* Reset Rx CRC Checker */ 55 - #define RES_Tx_CRC 0x80 /* Reset Tx CRC Checker */ 56 - #define RES_EOM_L 0xC0 /* Reset EOM latch */ 57 - 58 - /* Write Register 1 */ 59 - 60 - #define EXT_INT_ENAB 0x1 /* Ext Int Enable */ 61 - #define TxINT_ENAB 0x2 /* Tx Int Enable */ 62 - #define PAR_SPEC 0x4 /* Parity is special condition */ 63 - 64 - #define RxINT_DISAB 0 /* Rx Int Disable */ 65 - #define RxINT_FCERR 0x8 /* Rx Int on First Character Only or Error */ 66 - #define INT_ALL_Rx 0x10 /* Int on all Rx Characters or error */ 67 - #define INT_ERR_Rx 0x18 /* Int on error only */ 68 - 69 - #define WT_RDY_RT 0x20 /* Wait/Ready on R/T */ 70 - #define WT_FN_RDYFN 0x40 /* Wait/FN/Ready FN */ 71 - #define WT_RDY_ENAB 0x80 /* Wait/Ready Enable */ 72 - 73 - /* Write Register #2 (Interrupt Vector) */ 74 - 75 - /* Write Register 3 */ 76 - 77 - #define RxENABLE 0x1 /* Rx Enable */ 78 - #define SYNC_L_INH 0x2 /* Sync Character Load Inhibit */ 79 - #define ADD_SM 0x4 /* Address Search Mode (SDLC) */ 80 - #define RxCRC_ENAB 0x8 /* Rx CRC Enable */ 81 - #define ENT_HM 0x10 /* Enter Hunt Mode */ 82 - #define AUTO_ENAB 0x20 /* Auto Enables */ 83 - #define Rx5 0x0 /* Rx 5 Bits/Character */ 84 - #define Rx7 0x40 /* Rx 7 Bits/Character */ 85 - #define Rx6 0x80 /* Rx 6 Bits/Character */ 86 - #define Rx8 0xc0 /* Rx 8 Bits/Character */ 87 - 88 - /* Write Register 4 */ 89 - 90 - #define PAR_ENA 0x1 /* Parity Enable */ 91 - #define PAR_EVEN 0x2 /* Parity Even/Odd* */ 92 - 93 - #define SYNC_ENAB 0 /* Sync Modes Enable */ 94 - #define SB1 0x4 /* 1 stop bit/char */ 95 - #define SB15 0x8 /* 1.5 stop bits/char */ 96 - #define SB2 0xc /* 2 stop bits/char */ 97 - 98 - #define MONSYNC 0 /* 8 Bit Sync character */ 99 - #define BISYNC 0x10 /* 16 bit sync character */ 100 - #define SDLC 0x20 /* SDLC Mode (01111110 Sync Flag) */ 101 - #define EXTSYNC 0x30 /* External Sync Mode */ 102 - 103 - #define X1CLK 0x0 /* x1 clock mode */ 104 - #define X16CLK 0x40 /* x16 clock mode */ 105 - #define X32CLK 0x80 /* x32 clock mode */ 106 - #define X64CLK 0xC0 /* x64 clock mode */ 107 - 108 - /* Write Register 5 */ 109 - 110 - #define TxCRC_ENAB 0x1 /* Tx CRC Enable */ 111 - #define RTS 0x2 /* RTS */ 112 - #define SDLC_CRC 0x4 /* SDLC/CRC-16 */ 113 - #define TxENAB 0x8 /* Tx Enable */ 114 - #define SND_BRK 0x10 /* Send Break */ 115 - #define Tx5 0x0 /* Tx 5 bits (or less)/character */ 116 - #define Tx7 0x20 /* Tx 7 bits/character */ 117 - #define Tx6 0x40 /* Tx 6 bits/character */ 118 - #define Tx8 0x60 /* Tx 8 bits/character */ 119 - #define DTR 0x80 /* DTR */ 120 - 121 - /* Write Register 6 (Sync bits 0-7/SDLC Address Field) */ 122 - 123 - /* Write Register 7 (Sync bits 8-15/SDLC 01111110) */ 124 - 125 - /* Write Register 8 (transmit buffer) */ 126 - 127 - /* Write Register 9 (Master interrupt control) */ 128 - #define VIS 1 /* Vector Includes Status */ 129 - #define NV 2 /* No Vector */ 130 - #define DLC 4 /* Disable Lower Chain */ 131 - #define MIE 8 /* Master Interrupt Enable */ 132 - #define STATHI 0x10 /* Status high */ 133 - #define NORESET 0 /* No reset on write to R9 */ 134 - #define CHRB 0x40 /* Reset channel B */ 135 - #define CHRA 0x80 /* Reset channel A */ 136 - #define FHWRES 0xc0 /* Force hardware reset */ 137 - 138 - /* Write Register 10 (misc control bits) */ 139 - #define BIT6 1 /* 6 bit/8bit sync */ 140 - #define LOOPMODE 2 /* SDLC Loop mode */ 141 - #define ABUNDER 4 /* Abort/flag on SDLC xmit underrun */ 142 - #define MARKIDLE 8 /* Mark/flag on idle */ 143 - #define GAOP 0x10 /* Go active on poll */ 144 - #define NRZ 0 /* NRZ mode */ 145 - #define NRZI 0x20 /* NRZI mode */ 146 - #define FM1 0x40 /* FM1 (transition = 1) */ 147 - #define FM0 0x60 /* FM0 (transition = 0) */ 148 - #define CRCPS 0x80 /* CRC Preset I/O */ 149 - 150 - /* Write Register 11 (Clock Mode control) */ 151 - #define TRxCXT 0 /* TRxC = Xtal output */ 152 - #define TRxCTC 1 /* TRxC = Transmit clock */ 153 - #define TRxCBR 2 /* TRxC = BR Generator Output */ 154 - #define TRxCDP 3 /* TRxC = DPLL output */ 155 - #define TRxCOI 4 /* TRxC O/I */ 156 - #define TCRTxCP 0 /* Transmit clock = RTxC pin */ 157 - #define TCTRxCP 8 /* Transmit clock = TRxC pin */ 158 - #define TCBR 0x10 /* Transmit clock = BR Generator output */ 159 - #define TCDPLL 0x18 /* Transmit clock = DPLL output */ 160 - #define RCRTxCP 0 /* Receive clock = RTxC pin */ 161 - #define RCTRxCP 0x20 /* Receive clock = TRxC pin */ 162 - #define RCBR 0x40 /* Receive clock = BR Generator output */ 163 - #define RCDPLL 0x60 /* Receive clock = DPLL output */ 164 - #define RTxCX 0x80 /* RTxC Xtal/No Xtal */ 165 - 166 - /* Write Register 12 (lower byte of baud rate generator time constant) */ 167 - 168 - /* Write Register 13 (upper byte of baud rate generator time constant) */ 169 - 170 - /* Write Register 14 (Misc control bits) */ 171 - #define BRENABL 1 /* Baud rate generator enable */ 172 - #define BRSRC 2 /* Baud rate generator source */ 173 - #define DTRREQ 4 /* DTR/Request function */ 174 - #define AUTOECHO 8 /* Auto Echo */ 175 - #define LOOPBAK 0x10 /* Local loopback */ 176 - #define SEARCH 0x20 /* Enter search mode */ 177 - #define RMC 0x40 /* Reset missing clock */ 178 - #define DISDPLL 0x60 /* Disable DPLL */ 179 - #define SSBR 0x80 /* Set DPLL source = BR generator */ 180 - #define SSRTxC 0xa0 /* Set DPLL source = RTxC */ 181 - #define SFMM 0xc0 /* Set FM mode */ 182 - #define SNRZI 0xe0 /* Set NRZI mode */ 183 - 184 - /* Write Register 15 (external/status interrupt control) */ 185 - #define PRIME 1 /* R5' etc register access (Z85C30/230 only) */ 186 - #define ZCIE 2 /* Zero count IE */ 187 - #define FIFOE 4 /* Z85230 only */ 188 - #define DCDIE 8 /* DCD IE */ 189 - #define SYNCIE 0x10 /* Sync/hunt IE */ 190 - #define CTSIE 0x20 /* CTS IE */ 191 - #define TxUIE 0x40 /* Tx Underrun/EOM IE */ 192 - #define BRKIE 0x80 /* Break/Abort IE */ 193 - 194 - 195 - /* Read Register 0 */ 196 - #define Rx_CH_AV 0x1 /* Rx Character Available */ 197 - #define ZCOUNT 0x2 /* Zero count */ 198 - #define Tx_BUF_EMP 0x4 /* Tx Buffer empty */ 199 - #define DCD 0x8 /* DCD */ 200 - #define SYNC_HUNT 0x10 /* Sync/hunt */ 201 - #define CTS 0x20 /* CTS */ 202 - #define TxEOM 0x40 /* Tx underrun */ 203 - #define BRK_ABRT 0x80 /* Break/Abort */ 204 - 205 - /* Read Register 1 */ 206 - #define ALL_SNT 0x1 /* All sent */ 207 - /* Residue Data for 8 Rx bits/char programmed */ 208 - #define RES3 0x8 /* 0/3 */ 209 - #define RES4 0x4 /* 0/4 */ 210 - #define RES5 0xc /* 0/5 */ 211 - #define RES6 0x2 /* 0/6 */ 212 - #define RES7 0xa /* 0/7 */ 213 - #define RES8 0x6 /* 0/8 */ 214 - #define RES18 0xe /* 1/8 */ 215 - #define RES28 0x0 /* 2/8 */ 216 - /* Special Rx Condition Interrupts */ 217 - #define PAR_ERR 0x10 /* Parity error */ 218 - #define Rx_OVR 0x20 /* Rx Overrun Error */ 219 - #define CRC_ERR 0x40 /* CRC/Framing Error */ 220 - #define END_FR 0x80 /* End of Frame (SDLC) */ 221 - 222 - /* Read Register 2 (channel b only) - Interrupt vector */ 223 - 224 - /* Read Register 3 (interrupt pending register) ch a only */ 225 - #define CHBEXT 0x1 /* Channel B Ext/Stat IP */ 226 - #define CHBTxIP 0x2 /* Channel B Tx IP */ 227 - #define CHBRxIP 0x4 /* Channel B Rx IP */ 228 - #define CHAEXT 0x8 /* Channel A Ext/Stat IP */ 229 - #define CHATxIP 0x10 /* Channel A Tx IP */ 230 - #define CHARxIP 0x20 /* Channel A Rx IP */ 231 - 232 - /* Read Register 8 (receive data register) */ 233 - 234 - /* Read Register 10 (misc status bits) */ 235 - #define ONLOOP 2 /* On loop */ 236 - #define LOOPSEND 0x10 /* Loop sending */ 237 - #define CLK2MIS 0x40 /* Two clocks missing */ 238 - #define CLK1MIS 0x80 /* One clock missing */ 239 - 240 - /* Read Register 12 (lower byte of baud rate generator constant) */ 241 - 242 - /* Read Register 13 (upper byte of baud rate generator constant) */ 243 - 244 - /* Read Register 15 (value of WR 15) */ 245 - 246 - 247 - /* 248 - * Interrupt handling functions for this SCC 249 - */ 250 - 251 - struct z8530_channel; 252 - 253 - struct z8530_irqhandler 254 - { 255 - void (*rx)(struct z8530_channel *); 256 - void (*tx)(struct z8530_channel *); 257 - void (*status)(struct z8530_channel *); 258 - }; 259 - 260 - /* 261 - * A channel of the Z8530 262 - */ 263 - 264 - struct z8530_channel 265 - { 266 - struct z8530_irqhandler *irqs; /* IRQ handlers */ 267 - /* 268 - * Synchronous 269 - */ 270 - u16 count; /* Buyes received */ 271 - u16 max; /* Most we can receive this frame */ 272 - u16 mtu; /* MTU of the device */ 273 - u8 *dptr; /* Pointer into rx buffer */ 274 - struct sk_buff *skb; /* Buffer dptr points into */ 275 - struct sk_buff *skb2; /* Pending buffer */ 276 - u8 status; /* Current DCD */ 277 - u8 dcdcheck; /* which bit to check for line */ 278 - u8 sync; /* Set if in sync mode */ 279 - 280 - u8 regs[32]; /* Register map for the chip */ 281 - u8 pendregs[32]; /* Pending register values */ 282 - 283 - struct sk_buff *tx_skb; /* Buffer being transmitted */ 284 - struct sk_buff *tx_next_skb; /* Next transmit buffer */ 285 - u8 *tx_ptr; /* Byte pointer into the buffer */ 286 - u8 *tx_next_ptr; /* Next pointer to use */ 287 - u8 *tx_dma_buf[2]; /* TX flip buffers for DMA */ 288 - u8 tx_dma_used; /* Flip buffer usage toggler */ 289 - u16 txcount; /* Count of bytes to transmit */ 290 - 291 - void (*rx_function)(struct z8530_channel *, struct sk_buff *); 292 - 293 - /* 294 - * Sync DMA 295 - */ 296 - 297 - u8 rxdma; /* DMA channels */ 298 - u8 txdma; 299 - u8 rxdma_on; /* DMA active if flag set */ 300 - u8 txdma_on; 301 - u8 dma_num; /* Buffer we are DMAing into */ 302 - u8 dma_ready; /* Is the other buffer free */ 303 - u8 dma_tx; /* TX is to use DMA */ 304 - u8 *rx_buf[2]; /* The flip buffers */ 305 - 306 - /* 307 - * System 308 - */ 309 - 310 - struct z8530_dev *dev; /* Z85230 chip instance we are from */ 311 - unsigned long ctrlio; /* I/O ports */ 312 - unsigned long dataio; 313 - 314 - /* 315 - * For PC we encode this way. 316 - */ 317 - #define Z8530_PORT_SLEEP 0x80000000 318 - #define Z8530_PORT_OF(x) ((x)&0xFFFF) 319 - 320 - u32 rx_overrun; /* Overruns - not done yet */ 321 - u32 rx_crc_err; 322 - 323 - /* 324 - * Bound device pointers 325 - */ 326 - 327 - void *private; /* For our owner */ 328 - struct net_device *netdevice; /* Network layer device */ 329 - 330 - spinlock_t *lock; /* Device lock */ 331 - }; 332 - 333 - /* 334 - * Each Z853x0 device. 335 - */ 336 - 337 - struct z8530_dev 338 - { 339 - char *name; /* Device instance name */ 340 - struct z8530_channel chanA; /* SCC channel A */ 341 - struct z8530_channel chanB; /* SCC channel B */ 342 - int type; 343 - #define Z8530 0 /* NMOS dinosaur */ 344 - #define Z85C30 1 /* CMOS - better */ 345 - #define Z85230 2 /* CMOS with real FIFO */ 346 - int irq; /* Interrupt for the device */ 347 - int active; /* Soft interrupt enable - the Mac doesn't 348 - always have a hard disable on its 8530s... */ 349 - spinlock_t lock; 350 - }; 351 - 352 - 353 - /* 354 - * Functions 355 - */ 356 - 357 - extern u8 z8530_dead_port[]; 358 - extern u8 z8530_hdlc_kilostream_85230[]; 359 - extern u8 z8530_hdlc_kilostream[]; 360 - irqreturn_t z8530_interrupt(int, void *); 361 - void z8530_describe(struct z8530_dev *, char *mapping, unsigned long io); 362 - int z8530_init(struct z8530_dev *); 363 - int z8530_shutdown(struct z8530_dev *); 364 - int z8530_sync_open(struct net_device *, struct z8530_channel *); 365 - int z8530_sync_close(struct net_device *, struct z8530_channel *); 366 - int z8530_sync_dma_open(struct net_device *, struct z8530_channel *); 367 - int z8530_sync_dma_close(struct net_device *, struct z8530_channel *); 368 - int z8530_sync_txdma_open(struct net_device *, struct z8530_channel *); 369 - int z8530_sync_txdma_close(struct net_device *, struct z8530_channel *); 370 - int z8530_channel_load(struct z8530_channel *, u8 *); 371 - netdev_tx_t z8530_queue_xmit(struct z8530_channel *c, struct sk_buff *skb); 372 - void z8530_null_rx(struct z8530_channel *c, struct sk_buff *skb); 373 - 374 - 375 - /* 376 - * Standard interrupt vector sets 377 - */ 378 - 379 - extern struct z8530_irqhandler z8530_sync, z8530_async, z8530_nop; 380 - 381 - /* 382 - * Asynchronous Interfacing 383 - */ 384 - 385 - /* 386 - * The size of the serial xmit buffer is 1 page, or 4096 bytes 387 - */ 388 - 389 - #define SERIAL_XMIT_SIZE 4096 390 - #define WAKEUP_CHARS 256 391 - 392 - /* 393 - * Events are used to schedule things to happen at timer-interrupt 394 - * time, instead of at rs interrupt time. 395 - */ 396 - #define RS_EVENT_WRITE_WAKEUP 0 397 - 398 - /* Internal flags used only by kernel/chr_drv/serial.c */ 399 - #define ZILOG_INITIALIZED 0x80000000 /* Serial port was initialized */ 400 - #define ZILOG_CALLOUT_ACTIVE 0x40000000 /* Call out device is active */ 401 - #define ZILOG_NORMAL_ACTIVE 0x20000000 /* Normal device is active */ 402 - #define ZILOG_BOOT_AUTOCONF 0x10000000 /* Autoconfigure port on bootup */ 403 - #define ZILOG_CLOSING 0x08000000 /* Serial port is closing */ 404 - #define ZILOG_CTS_FLOW 0x04000000 /* Do CTS flow control */ 405 - #define ZILOG_CHECK_CD 0x02000000 /* i.e., CLOCAL */ 406 - 407 - #endif /* !(_Z8530_H) */