18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci Madge Horizon ATM Adapter driver. 48c2ecf20Sopenharmony_ci Copyright (C) 1995-1999 Madge Networks Ltd. 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci*/ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci/* 98c2ecf20Sopenharmony_ci IMPORTANT NOTE: Madge Networks no longer makes the adapters 108c2ecf20Sopenharmony_ci supported by this driver and makes no commitment to maintain it. 118c2ecf20Sopenharmony_ci*/ 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include <linux/module.h> 148c2ecf20Sopenharmony_ci#include <linux/kernel.h> 158c2ecf20Sopenharmony_ci#include <linux/sched/signal.h> 168c2ecf20Sopenharmony_ci#include <linux/mm.h> 178c2ecf20Sopenharmony_ci#include <linux/pci.h> 188c2ecf20Sopenharmony_ci#include <linux/errno.h> 198c2ecf20Sopenharmony_ci#include <linux/atm.h> 208c2ecf20Sopenharmony_ci#include <linux/atmdev.h> 218c2ecf20Sopenharmony_ci#include <linux/sonet.h> 228c2ecf20Sopenharmony_ci#include <linux/skbuff.h> 238c2ecf20Sopenharmony_ci#include <linux/time.h> 248c2ecf20Sopenharmony_ci#include <linux/delay.h> 258c2ecf20Sopenharmony_ci#include <linux/uio.h> 268c2ecf20Sopenharmony_ci#include <linux/init.h> 278c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 288c2ecf20Sopenharmony_ci#include <linux/ioport.h> 298c2ecf20Sopenharmony_ci#include <linux/wait.h> 308c2ecf20Sopenharmony_ci#include <linux/slab.h> 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci#include <asm/io.h> 338c2ecf20Sopenharmony_ci#include <linux/atomic.h> 348c2ecf20Sopenharmony_ci#include <linux/uaccess.h> 358c2ecf20Sopenharmony_ci#include <asm/string.h> 368c2ecf20Sopenharmony_ci#include <asm/byteorder.h> 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci#include "horizon.h" 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci#define maintainer_string "Giuliano Procida at Madge Networks <gprocida@madge.com>" 418c2ecf20Sopenharmony_ci#define description_string "Madge ATM Horizon [Ultra] driver" 428c2ecf20Sopenharmony_ci#define version_string "1.2.1" 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_cistatic inline void __init show_version (void) { 458c2ecf20Sopenharmony_ci printk ("%s version %s\n", description_string, version_string); 468c2ecf20Sopenharmony_ci} 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci/* 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci CREDITS 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci Driver and documentation by: 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci Chris Aston Madge Networks 558c2ecf20Sopenharmony_ci Giuliano Procida Madge Networks 568c2ecf20Sopenharmony_ci Simon Benham Madge Networks 578c2ecf20Sopenharmony_ci Simon Johnson Madge Networks 588c2ecf20Sopenharmony_ci Various Others Madge Networks 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci Some inspiration taken from other drivers by: 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci Alexandru Cucos UTBv 638c2ecf20Sopenharmony_ci Kari Mettinen University of Helsinki 648c2ecf20Sopenharmony_ci Werner Almesberger EPFL LRC 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci Theory of Operation 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci I Hardware, detection, initialisation and shutdown. 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci 1. Supported Hardware 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci This driver should handle all variants of the PCI Madge ATM adapters 738c2ecf20Sopenharmony_ci with the Horizon chipset. These are all PCI cards supporting PIO, BM 748c2ecf20Sopenharmony_ci DMA and a form of MMIO (registers only, not internal RAM). 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci The driver is only known to work with SONET and UTP Horizon Ultra 778c2ecf20Sopenharmony_ci cards at 155Mb/s. However, code is in place to deal with both the 788c2ecf20Sopenharmony_ci original Horizon and 25Mb/s operation. 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci There are two revisions of the Horizon ASIC: the original and the 818c2ecf20Sopenharmony_ci Ultra. Details of hardware bugs are in section III. 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci The ASIC version can be distinguished by chip markings but is NOT 848c2ecf20Sopenharmony_ci indicated by the PCI revision (all adapters seem to have PCI rev 1). 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci I believe that: 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci Horizon => Collage 25 PCI Adapter (UTP and STP) 898c2ecf20Sopenharmony_ci Horizon Ultra => Collage 155 PCI Client (UTP or SONET) 908c2ecf20Sopenharmony_ci Ambassador x => Collage 155 PCI Server (completely different) 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci Horizon (25Mb/s) is fitted with UTP and STP connectors. It seems to 938c2ecf20Sopenharmony_ci have a Madge B154 plus glue logic serializer. I have also found a 948c2ecf20Sopenharmony_ci really ancient version of this with slightly different glue. It 958c2ecf20Sopenharmony_ci comes with the revision 0 (140-025-01) ASIC. 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci Horizon Ultra (155Mb/s) is fitted with either a Pulse Medialink 988c2ecf20Sopenharmony_ci output (UTP) or an HP HFBR 5205 output (SONET). It has either 998c2ecf20Sopenharmony_ci Madge's SAMBA framer or a SUNI-lite device (early versions). It 1008c2ecf20Sopenharmony_ci comes with the revision 1 (140-027-01) ASIC. 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci 2. Detection 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci All Horizon-based cards present with the same PCI Vendor and Device 1058c2ecf20Sopenharmony_ci IDs. The standard Linux 2.2 PCI API is used to locate any cards and 1068c2ecf20Sopenharmony_ci to enable bus-mastering (with appropriate latency). 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ci ATM_LAYER_STATUS in the control register distinguishes between the 1098c2ecf20Sopenharmony_ci two possible physical layers (25 and 155). It is not clear whether 1108c2ecf20Sopenharmony_ci the 155 cards can also operate at 25Mbps. We rely on the fact that a 1118c2ecf20Sopenharmony_ci card operates at 155 if and only if it has the newer Horizon Ultra 1128c2ecf20Sopenharmony_ci ASIC. 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci For 155 cards the two possible framers are probed for and then set 1158c2ecf20Sopenharmony_ci up for loop-timing. 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci 3. Initialisation 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ci The card is reset and then put into a known state. The physical 1208c2ecf20Sopenharmony_ci layer is configured for normal operation at the appropriate speed; 1218c2ecf20Sopenharmony_ci in the case of the 155 cards, the framer is initialised with 1228c2ecf20Sopenharmony_ci line-based timing; the internal RAM is zeroed and the allocation of 1238c2ecf20Sopenharmony_ci buffers for RX and TX is made; the Burnt In Address is read and 1248c2ecf20Sopenharmony_ci copied to the ATM ESI; various policy settings for RX (VPI bits, 1258c2ecf20Sopenharmony_ci unknown VCs, oam cells) are made. Ideally all policy items should be 1268c2ecf20Sopenharmony_ci configurable at module load (if not actually on-demand), however, 1278c2ecf20Sopenharmony_ci only the vpi vs vci bit allocation can be specified at insmod. 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci 4. Shutdown 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci This is in response to module_cleaup. No VCs are in use and the card 1328c2ecf20Sopenharmony_ci should be idle; it is reset. 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ci II Driver software (as it should be) 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci 0. Traffic Parameters 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ci The traffic classes (not an enumeration) are currently: ATM_NONE (no 1398c2ecf20Sopenharmony_ci traffic), ATM_UBR, ATM_CBR, ATM_VBR and ATM_ABR, ATM_ANYCLASS 1408c2ecf20Sopenharmony_ci (compatible with everything). Together with (perhaps only some of) 1418c2ecf20Sopenharmony_ci the following items they make up the traffic specification. 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ci struct atm_trafprm { 1448c2ecf20Sopenharmony_ci unsigned char traffic_class; traffic class (ATM_UBR, ...) 1458c2ecf20Sopenharmony_ci int max_pcr; maximum PCR in cells per second 1468c2ecf20Sopenharmony_ci int pcr; desired PCR in cells per second 1478c2ecf20Sopenharmony_ci int min_pcr; minimum PCR in cells per second 1488c2ecf20Sopenharmony_ci int max_cdv; maximum CDV in microseconds 1498c2ecf20Sopenharmony_ci int max_sdu; maximum SDU in bytes 1508c2ecf20Sopenharmony_ci }; 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ci Note that these denote bandwidth available not bandwidth used; the 1538c2ecf20Sopenharmony_ci possibilities according to ATMF are: 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci Real Time (cdv and max CDT given) 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_ci CBR(pcr) pcr bandwidth always available 1588c2ecf20Sopenharmony_ci rtVBR(pcr,scr,mbs) scr bandwidth always available, up to pcr at mbs too 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ci Non Real Time 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_ci nrtVBR(pcr,scr,mbs) scr bandwidth always available, up to pcr at mbs too 1638c2ecf20Sopenharmony_ci UBR() 1648c2ecf20Sopenharmony_ci ABR(mcr,pcr) mcr bandwidth always available, up to pcr (depending) too 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_ci mbs is max burst size (bucket) 1678c2ecf20Sopenharmony_ci pcr and scr have associated cdvt values 1688c2ecf20Sopenharmony_ci mcr is like scr but has no cdtv 1698c2ecf20Sopenharmony_ci cdtv may differ at each hop 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_ci Some of the above items are qos items (as opposed to traffic 1728c2ecf20Sopenharmony_ci parameters). We have nothing to do with qos. All except ABR can have 1738c2ecf20Sopenharmony_ci their traffic parameters converted to GCRA parameters. The GCRA may 1748c2ecf20Sopenharmony_ci be implemented as a (real-number) leaky bucket. The GCRA can be used 1758c2ecf20Sopenharmony_ci in complicated ways by switches and in simpler ways by end-stations. 1768c2ecf20Sopenharmony_ci It can be used both to filter incoming cells and shape out-going 1778c2ecf20Sopenharmony_ci cells. 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_ci ATM Linux actually supports: 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_ci ATM_NONE() (no traffic in this direction) 1828c2ecf20Sopenharmony_ci ATM_UBR(max_frame_size) 1838c2ecf20Sopenharmony_ci ATM_CBR(max/min_pcr, max_cdv, max_frame_size) 1848c2ecf20Sopenharmony_ci 1858c2ecf20Sopenharmony_ci 0 or ATM_MAX_PCR are used to indicate maximum available PCR 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_ci A traffic specification consists of the AAL type and separate 1888c2ecf20Sopenharmony_ci traffic specifications for either direction. In ATM Linux it is: 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_ci struct atm_qos { 1918c2ecf20Sopenharmony_ci struct atm_trafprm txtp; 1928c2ecf20Sopenharmony_ci struct atm_trafprm rxtp; 1938c2ecf20Sopenharmony_ci unsigned char aal; 1948c2ecf20Sopenharmony_ci }; 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_ci AAL types are: 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_ci ATM_NO_AAL AAL not specified 1998c2ecf20Sopenharmony_ci ATM_AAL0 "raw" ATM cells 2008c2ecf20Sopenharmony_ci ATM_AAL1 AAL1 (CBR) 2018c2ecf20Sopenharmony_ci ATM_AAL2 AAL2 (VBR) 2028c2ecf20Sopenharmony_ci ATM_AAL34 AAL3/4 (data) 2038c2ecf20Sopenharmony_ci ATM_AAL5 AAL5 (data) 2048c2ecf20Sopenharmony_ci ATM_SAAL signaling AAL 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ci The Horizon has support for AAL frame types: 0, 3/4 and 5. However, 2078c2ecf20Sopenharmony_ci it does not implement AAL 3/4 SAR and it has a different notion of 2088c2ecf20Sopenharmony_ci "raw cell" to ATM Linux's (48 bytes vs. 52 bytes) so neither are 2098c2ecf20Sopenharmony_ci supported by this driver. 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_ci The Horizon has limited support for ABR (including UBR), VBR and 2128c2ecf20Sopenharmony_ci CBR. Each TX channel has a bucket (containing up to 31 cell units) 2138c2ecf20Sopenharmony_ci and two timers (PCR and SCR) associated with it that can be used to 2148c2ecf20Sopenharmony_ci govern cell emissions and host notification (in the case of ABR this 2158c2ecf20Sopenharmony_ci is presumably so that RM cells may be emitted at appropriate times). 2168c2ecf20Sopenharmony_ci The timers may either be disabled or may be set to any of 240 values 2178c2ecf20Sopenharmony_ci (determined by the clock crystal, a fixed (?) per-device divider, a 2188c2ecf20Sopenharmony_ci configurable divider and a configurable timer preload value). 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_ci At the moment only UBR and CBR are supported by the driver. VBR will 2218c2ecf20Sopenharmony_ci be supported as soon as ATM for Linux supports it. ABR support is 2228c2ecf20Sopenharmony_ci very unlikely as RM cell handling is completely up to the driver. 2238c2ecf20Sopenharmony_ci 2248c2ecf20Sopenharmony_ci 1. TX (TX channel setup and TX transfer) 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_ci The TX half of the driver owns the TX Horizon registers. The TX 2278c2ecf20Sopenharmony_ci component in the IRQ handler is the BM completion handler. This can 2288c2ecf20Sopenharmony_ci only be entered when tx_busy is true (enforced by hardware). The 2298c2ecf20Sopenharmony_ci other TX component can only be entered when tx_busy is false 2308c2ecf20Sopenharmony_ci (enforced by driver). So TX is single-threaded. 2318c2ecf20Sopenharmony_ci 2328c2ecf20Sopenharmony_ci Apart from a minor optimisation to not re-select the last channel, 2338c2ecf20Sopenharmony_ci the TX send component works as follows: 2348c2ecf20Sopenharmony_ci 2358c2ecf20Sopenharmony_ci Atomic test and set tx_busy until we succeed; we should implement 2368c2ecf20Sopenharmony_ci some sort of timeout so that tx_busy will never be stuck at true. 2378c2ecf20Sopenharmony_ci 2388c2ecf20Sopenharmony_ci If no TX channel is set up for this VC we wait for an idle one (if 2398c2ecf20Sopenharmony_ci necessary) and set it up. 2408c2ecf20Sopenharmony_ci 2418c2ecf20Sopenharmony_ci At this point we have a TX channel ready for use. We wait for enough 2428c2ecf20Sopenharmony_ci buffers to become available then start a TX transmit (set the TX 2438c2ecf20Sopenharmony_ci descriptor, schedule transfer, exit). 2448c2ecf20Sopenharmony_ci 2458c2ecf20Sopenharmony_ci The IRQ component handles TX completion (stats, free buffer, tx_busy 2468c2ecf20Sopenharmony_ci unset, exit). We also re-schedule further transfers for the same 2478c2ecf20Sopenharmony_ci frame if needed. 2488c2ecf20Sopenharmony_ci 2498c2ecf20Sopenharmony_ci TX setup in more detail: 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_ci TX open is a nop, the relevant information is held in the hrz_vcc 2528c2ecf20Sopenharmony_ci (vcc->dev_data) structure and is "cached" on the card. 2538c2ecf20Sopenharmony_ci 2548c2ecf20Sopenharmony_ci TX close gets the TX lock and clears the channel from the "cache". 2558c2ecf20Sopenharmony_ci 2568c2ecf20Sopenharmony_ci 2. RX (Data Available and RX transfer) 2578c2ecf20Sopenharmony_ci 2588c2ecf20Sopenharmony_ci The RX half of the driver owns the RX registers. There are two RX 2598c2ecf20Sopenharmony_ci components in the IRQ handler: the data available handler deals with 2608c2ecf20Sopenharmony_ci fresh data that has arrived on the card, the BM completion handler 2618c2ecf20Sopenharmony_ci is very similar to the TX completion handler. The data available 2628c2ecf20Sopenharmony_ci handler grabs the rx_lock and it is only released once the data has 2638c2ecf20Sopenharmony_ci been discarded or completely transferred to the host. The BM 2648c2ecf20Sopenharmony_ci completion handler only runs when the lock is held; the data 2658c2ecf20Sopenharmony_ci available handler is locked out over the same period. 2668c2ecf20Sopenharmony_ci 2678c2ecf20Sopenharmony_ci Data available on the card triggers an interrupt. If the data is not 2688c2ecf20Sopenharmony_ci suitable for our existing RX channels or we cannot allocate a buffer 2698c2ecf20Sopenharmony_ci it is flushed. Otherwise an RX receive is scheduled. Multiple RX 2708c2ecf20Sopenharmony_ci transfers may be scheduled for the same frame. 2718c2ecf20Sopenharmony_ci 2728c2ecf20Sopenharmony_ci RX setup in more detail: 2738c2ecf20Sopenharmony_ci 2748c2ecf20Sopenharmony_ci RX open... 2758c2ecf20Sopenharmony_ci RX close... 2768c2ecf20Sopenharmony_ci 2778c2ecf20Sopenharmony_ci III Hardware Bugs 2788c2ecf20Sopenharmony_ci 2798c2ecf20Sopenharmony_ci 0. Byte vs Word addressing of adapter RAM. 2808c2ecf20Sopenharmony_ci 2818c2ecf20Sopenharmony_ci A design feature; see the .h file (especially the memory map). 2828c2ecf20Sopenharmony_ci 2838c2ecf20Sopenharmony_ci 1. Bus Master Data Transfers (original Horizon only, fixed in Ultra) 2848c2ecf20Sopenharmony_ci 2858c2ecf20Sopenharmony_ci The host must not start a transmit direction transfer at a 2868c2ecf20Sopenharmony_ci non-four-byte boundary in host memory. Instead the host should 2878c2ecf20Sopenharmony_ci perform a byte, or a two byte, or one byte followed by two byte 2888c2ecf20Sopenharmony_ci transfer in order to start the rest of the transfer on a four byte 2898c2ecf20Sopenharmony_ci boundary. RX is OK. 2908c2ecf20Sopenharmony_ci 2918c2ecf20Sopenharmony_ci Simultaneous transmit and receive direction bus master transfers are 2928c2ecf20Sopenharmony_ci not allowed. 2938c2ecf20Sopenharmony_ci 2948c2ecf20Sopenharmony_ci The simplest solution to these two is to always do PIO (never DMA) 2958c2ecf20Sopenharmony_ci in the TX direction on the original Horizon. More complicated 2968c2ecf20Sopenharmony_ci solutions are likely to hurt my brain. 2978c2ecf20Sopenharmony_ci 2988c2ecf20Sopenharmony_ci 2. Loss of buffer on close VC 2998c2ecf20Sopenharmony_ci 3008c2ecf20Sopenharmony_ci When a VC is being closed, the buffer associated with it is not 3018c2ecf20Sopenharmony_ci returned to the pool. The host must store the reference to this 3028c2ecf20Sopenharmony_ci buffer and when opening a new VC then give it to that new VC. 3038c2ecf20Sopenharmony_ci 3048c2ecf20Sopenharmony_ci The host intervention currently consists of stacking such a buffer 3058c2ecf20Sopenharmony_ci pointer at VC close and checking the stack at VC open. 3068c2ecf20Sopenharmony_ci 3078c2ecf20Sopenharmony_ci 3. Failure to close a VC 3088c2ecf20Sopenharmony_ci 3098c2ecf20Sopenharmony_ci If a VC is currently receiving a frame then closing the VC may fail 3108c2ecf20Sopenharmony_ci and the frame continues to be received. 3118c2ecf20Sopenharmony_ci 3128c2ecf20Sopenharmony_ci The solution is to make sure any received frames are flushed when 3138c2ecf20Sopenharmony_ci ready. This is currently done just before the solution to 2. 3148c2ecf20Sopenharmony_ci 3158c2ecf20Sopenharmony_ci 4. PCI bus (original Horizon only, fixed in Ultra) 3168c2ecf20Sopenharmony_ci 3178c2ecf20Sopenharmony_ci Reading from the data port prior to initialisation will hang the PCI 3188c2ecf20Sopenharmony_ci bus. Just don't do that then! We don't. 3198c2ecf20Sopenharmony_ci 3208c2ecf20Sopenharmony_ci IV To Do List 3218c2ecf20Sopenharmony_ci 3228c2ecf20Sopenharmony_ci . Timer code may be broken. 3238c2ecf20Sopenharmony_ci 3248c2ecf20Sopenharmony_ci . Allow users to specify buffer allocation split for TX and RX. 3258c2ecf20Sopenharmony_ci 3268c2ecf20Sopenharmony_ci . Deal once and for all with buggy VC close. 3278c2ecf20Sopenharmony_ci 3288c2ecf20Sopenharmony_ci . Handle interrupted and/or non-blocking operations. 3298c2ecf20Sopenharmony_ci 3308c2ecf20Sopenharmony_ci . Change some macros to functions and move from .h to .c. 3318c2ecf20Sopenharmony_ci 3328c2ecf20Sopenharmony_ci . Try to limit the number of TX frames each VC may have queued, in 3338c2ecf20Sopenharmony_ci order to reduce the chances of TX buffer exhaustion. 3348c2ecf20Sopenharmony_ci 3358c2ecf20Sopenharmony_ci . Implement VBR (bucket and timers not understood) and ABR (need to 3368c2ecf20Sopenharmony_ci do RM cells manually); also no Linux support for either. 3378c2ecf20Sopenharmony_ci 3388c2ecf20Sopenharmony_ci . Implement QoS changes on open VCs (involves extracting parts of VC open 3398c2ecf20Sopenharmony_ci and close into separate functions and using them to make changes). 3408c2ecf20Sopenharmony_ci 3418c2ecf20Sopenharmony_ci*/ 3428c2ecf20Sopenharmony_ci 3438c2ecf20Sopenharmony_ci/********** globals **********/ 3448c2ecf20Sopenharmony_ci 3458c2ecf20Sopenharmony_cistatic void do_housekeeping (struct timer_list *t); 3468c2ecf20Sopenharmony_ci 3478c2ecf20Sopenharmony_cistatic unsigned short debug = 0; 3488c2ecf20Sopenharmony_cistatic unsigned short vpi_bits = 0; 3498c2ecf20Sopenharmony_cistatic int max_tx_size = 9000; 3508c2ecf20Sopenharmony_cistatic int max_rx_size = 9000; 3518c2ecf20Sopenharmony_cistatic unsigned char pci_lat = 0; 3528c2ecf20Sopenharmony_ci 3538c2ecf20Sopenharmony_ci/********** access functions **********/ 3548c2ecf20Sopenharmony_ci 3558c2ecf20Sopenharmony_ci/* Read / Write Horizon registers */ 3568c2ecf20Sopenharmony_cistatic inline void wr_regl (const hrz_dev * dev, unsigned char reg, u32 data) { 3578c2ecf20Sopenharmony_ci outl (cpu_to_le32 (data), dev->iobase + reg); 3588c2ecf20Sopenharmony_ci} 3598c2ecf20Sopenharmony_ci 3608c2ecf20Sopenharmony_cistatic inline u32 rd_regl (const hrz_dev * dev, unsigned char reg) { 3618c2ecf20Sopenharmony_ci return le32_to_cpu (inl (dev->iobase + reg)); 3628c2ecf20Sopenharmony_ci} 3638c2ecf20Sopenharmony_ci 3648c2ecf20Sopenharmony_cistatic inline void wr_regw (const hrz_dev * dev, unsigned char reg, u16 data) { 3658c2ecf20Sopenharmony_ci outw (cpu_to_le16 (data), dev->iobase + reg); 3668c2ecf20Sopenharmony_ci} 3678c2ecf20Sopenharmony_ci 3688c2ecf20Sopenharmony_cistatic inline u16 rd_regw (const hrz_dev * dev, unsigned char reg) { 3698c2ecf20Sopenharmony_ci return le16_to_cpu (inw (dev->iobase + reg)); 3708c2ecf20Sopenharmony_ci} 3718c2ecf20Sopenharmony_ci 3728c2ecf20Sopenharmony_cistatic inline void wrs_regb (const hrz_dev * dev, unsigned char reg, void * addr, u32 len) { 3738c2ecf20Sopenharmony_ci outsb (dev->iobase + reg, addr, len); 3748c2ecf20Sopenharmony_ci} 3758c2ecf20Sopenharmony_ci 3768c2ecf20Sopenharmony_cistatic inline void rds_regb (const hrz_dev * dev, unsigned char reg, void * addr, u32 len) { 3778c2ecf20Sopenharmony_ci insb (dev->iobase + reg, addr, len); 3788c2ecf20Sopenharmony_ci} 3798c2ecf20Sopenharmony_ci 3808c2ecf20Sopenharmony_ci/* Read / Write to a given address in Horizon buffer memory. 3818c2ecf20Sopenharmony_ci Interrupts must be disabled between the address register and data 3828c2ecf20Sopenharmony_ci port accesses as these must form an atomic operation. */ 3838c2ecf20Sopenharmony_cistatic inline void wr_mem (const hrz_dev * dev, HDW * addr, u32 data) { 3848c2ecf20Sopenharmony_ci // wr_regl (dev, MEM_WR_ADDR_REG_OFF, (u32) addr); 3858c2ecf20Sopenharmony_ci wr_regl (dev, MEM_WR_ADDR_REG_OFF, (addr - (HDW *) 0) * sizeof(HDW)); 3868c2ecf20Sopenharmony_ci wr_regl (dev, MEMORY_PORT_OFF, data); 3878c2ecf20Sopenharmony_ci} 3888c2ecf20Sopenharmony_ci 3898c2ecf20Sopenharmony_cistatic inline u32 rd_mem (const hrz_dev * dev, HDW * addr) { 3908c2ecf20Sopenharmony_ci // wr_regl (dev, MEM_RD_ADDR_REG_OFF, (u32) addr); 3918c2ecf20Sopenharmony_ci wr_regl (dev, MEM_RD_ADDR_REG_OFF, (addr - (HDW *) 0) * sizeof(HDW)); 3928c2ecf20Sopenharmony_ci return rd_regl (dev, MEMORY_PORT_OFF); 3938c2ecf20Sopenharmony_ci} 3948c2ecf20Sopenharmony_ci 3958c2ecf20Sopenharmony_cistatic inline void wr_framer (const hrz_dev * dev, u32 addr, u32 data) { 3968c2ecf20Sopenharmony_ci wr_regl (dev, MEM_WR_ADDR_REG_OFF, (u32) addr | 0x80000000); 3978c2ecf20Sopenharmony_ci wr_regl (dev, MEMORY_PORT_OFF, data); 3988c2ecf20Sopenharmony_ci} 3998c2ecf20Sopenharmony_ci 4008c2ecf20Sopenharmony_cistatic inline u32 rd_framer (const hrz_dev * dev, u32 addr) { 4018c2ecf20Sopenharmony_ci wr_regl (dev, MEM_RD_ADDR_REG_OFF, (u32) addr | 0x80000000); 4028c2ecf20Sopenharmony_ci return rd_regl (dev, MEMORY_PORT_OFF); 4038c2ecf20Sopenharmony_ci} 4048c2ecf20Sopenharmony_ci 4058c2ecf20Sopenharmony_ci/********** specialised access functions **********/ 4068c2ecf20Sopenharmony_ci 4078c2ecf20Sopenharmony_ci/* RX */ 4088c2ecf20Sopenharmony_ci 4098c2ecf20Sopenharmony_cistatic inline void FLUSH_RX_CHANNEL (hrz_dev * dev, u16 channel) { 4108c2ecf20Sopenharmony_ci wr_regw (dev, RX_CHANNEL_PORT_OFF, FLUSH_CHANNEL | channel); 4118c2ecf20Sopenharmony_ci return; 4128c2ecf20Sopenharmony_ci} 4138c2ecf20Sopenharmony_ci 4148c2ecf20Sopenharmony_cistatic void WAIT_FLUSH_RX_COMPLETE (hrz_dev * dev) { 4158c2ecf20Sopenharmony_ci while (rd_regw (dev, RX_CHANNEL_PORT_OFF) & FLUSH_CHANNEL) 4168c2ecf20Sopenharmony_ci ; 4178c2ecf20Sopenharmony_ci return; 4188c2ecf20Sopenharmony_ci} 4198c2ecf20Sopenharmony_ci 4208c2ecf20Sopenharmony_cistatic inline void SELECT_RX_CHANNEL (hrz_dev * dev, u16 channel) { 4218c2ecf20Sopenharmony_ci wr_regw (dev, RX_CHANNEL_PORT_OFF, channel); 4228c2ecf20Sopenharmony_ci return; 4238c2ecf20Sopenharmony_ci} 4248c2ecf20Sopenharmony_ci 4258c2ecf20Sopenharmony_cistatic void WAIT_UPDATE_COMPLETE (hrz_dev * dev) { 4268c2ecf20Sopenharmony_ci while (rd_regw (dev, RX_CHANNEL_PORT_OFF) & RX_CHANNEL_UPDATE_IN_PROGRESS) 4278c2ecf20Sopenharmony_ci ; 4288c2ecf20Sopenharmony_ci return; 4298c2ecf20Sopenharmony_ci} 4308c2ecf20Sopenharmony_ci 4318c2ecf20Sopenharmony_ci/* TX */ 4328c2ecf20Sopenharmony_ci 4338c2ecf20Sopenharmony_cistatic inline void SELECT_TX_CHANNEL (hrz_dev * dev, u16 tx_channel) { 4348c2ecf20Sopenharmony_ci wr_regl (dev, TX_CHANNEL_PORT_OFF, tx_channel); 4358c2ecf20Sopenharmony_ci return; 4368c2ecf20Sopenharmony_ci} 4378c2ecf20Sopenharmony_ci 4388c2ecf20Sopenharmony_ci/* Update or query one configuration parameter of a particular channel. */ 4398c2ecf20Sopenharmony_ci 4408c2ecf20Sopenharmony_cistatic inline void update_tx_channel_config (hrz_dev * dev, short chan, u8 mode, u16 value) { 4418c2ecf20Sopenharmony_ci wr_regw (dev, TX_CHANNEL_CONFIG_COMMAND_OFF, 4428c2ecf20Sopenharmony_ci chan * TX_CHANNEL_CONFIG_MULT | mode); 4438c2ecf20Sopenharmony_ci wr_regw (dev, TX_CHANNEL_CONFIG_DATA_OFF, value); 4448c2ecf20Sopenharmony_ci return; 4458c2ecf20Sopenharmony_ci} 4468c2ecf20Sopenharmony_ci 4478c2ecf20Sopenharmony_ci/********** dump functions **********/ 4488c2ecf20Sopenharmony_ci 4498c2ecf20Sopenharmony_cistatic inline void dump_skb (char * prefix, unsigned int vc, struct sk_buff * skb) { 4508c2ecf20Sopenharmony_ci#ifdef DEBUG_HORIZON 4518c2ecf20Sopenharmony_ci unsigned int i; 4528c2ecf20Sopenharmony_ci unsigned char * data = skb->data; 4538c2ecf20Sopenharmony_ci PRINTDB (DBG_DATA, "%s(%u) ", prefix, vc); 4548c2ecf20Sopenharmony_ci for (i=0; i<skb->len && i < 256;i++) 4558c2ecf20Sopenharmony_ci PRINTDM (DBG_DATA, "%02x ", data[i]); 4568c2ecf20Sopenharmony_ci PRINTDE (DBG_DATA,""); 4578c2ecf20Sopenharmony_ci#else 4588c2ecf20Sopenharmony_ci (void) prefix; 4598c2ecf20Sopenharmony_ci (void) vc; 4608c2ecf20Sopenharmony_ci (void) skb; 4618c2ecf20Sopenharmony_ci#endif 4628c2ecf20Sopenharmony_ci return; 4638c2ecf20Sopenharmony_ci} 4648c2ecf20Sopenharmony_ci 4658c2ecf20Sopenharmony_cistatic inline void dump_regs (hrz_dev * dev) { 4668c2ecf20Sopenharmony_ci#ifdef DEBUG_HORIZON 4678c2ecf20Sopenharmony_ci PRINTD (DBG_REGS, "CONTROL 0: %#x", rd_regl (dev, CONTROL_0_REG)); 4688c2ecf20Sopenharmony_ci PRINTD (DBG_REGS, "RX CONFIG: %#x", rd_regw (dev, RX_CONFIG_OFF)); 4698c2ecf20Sopenharmony_ci PRINTD (DBG_REGS, "TX CONFIG: %#x", rd_regw (dev, TX_CONFIG_OFF)); 4708c2ecf20Sopenharmony_ci PRINTD (DBG_REGS, "TX STATUS: %#x", rd_regw (dev, TX_STATUS_OFF)); 4718c2ecf20Sopenharmony_ci PRINTD (DBG_REGS, "IRQ ENBLE: %#x", rd_regl (dev, INT_ENABLE_REG_OFF)); 4728c2ecf20Sopenharmony_ci PRINTD (DBG_REGS, "IRQ SORCE: %#x", rd_regl (dev, INT_SOURCE_REG_OFF)); 4738c2ecf20Sopenharmony_ci#else 4748c2ecf20Sopenharmony_ci (void) dev; 4758c2ecf20Sopenharmony_ci#endif 4768c2ecf20Sopenharmony_ci return; 4778c2ecf20Sopenharmony_ci} 4788c2ecf20Sopenharmony_ci 4798c2ecf20Sopenharmony_cistatic inline void dump_framer (hrz_dev * dev) { 4808c2ecf20Sopenharmony_ci#ifdef DEBUG_HORIZON 4818c2ecf20Sopenharmony_ci unsigned int i; 4828c2ecf20Sopenharmony_ci PRINTDB (DBG_REGS, "framer registers:"); 4838c2ecf20Sopenharmony_ci for (i = 0; i < 0x10; ++i) 4848c2ecf20Sopenharmony_ci PRINTDM (DBG_REGS, " %02x", rd_framer (dev, i)); 4858c2ecf20Sopenharmony_ci PRINTDE (DBG_REGS,""); 4868c2ecf20Sopenharmony_ci#else 4878c2ecf20Sopenharmony_ci (void) dev; 4888c2ecf20Sopenharmony_ci#endif 4898c2ecf20Sopenharmony_ci return; 4908c2ecf20Sopenharmony_ci} 4918c2ecf20Sopenharmony_ci 4928c2ecf20Sopenharmony_ci/********** VPI/VCI <-> (RX) channel conversions **********/ 4938c2ecf20Sopenharmony_ci 4948c2ecf20Sopenharmony_ci/* RX channels are 10 bit integers, these fns are quite paranoid */ 4958c2ecf20Sopenharmony_ci 4968c2ecf20Sopenharmony_cistatic inline int vpivci_to_channel (u16 * channel, const short vpi, const int vci) { 4978c2ecf20Sopenharmony_ci unsigned short vci_bits = 10 - vpi_bits; 4988c2ecf20Sopenharmony_ci if (0 <= vpi && vpi < 1<<vpi_bits && 0 <= vci && vci < 1<<vci_bits) { 4998c2ecf20Sopenharmony_ci *channel = vpi<<vci_bits | vci; 5008c2ecf20Sopenharmony_ci return *channel ? 0 : -EINVAL; 5018c2ecf20Sopenharmony_ci } 5028c2ecf20Sopenharmony_ci return -EINVAL; 5038c2ecf20Sopenharmony_ci} 5048c2ecf20Sopenharmony_ci 5058c2ecf20Sopenharmony_ci/********** decode RX queue entries **********/ 5068c2ecf20Sopenharmony_ci 5078c2ecf20Sopenharmony_cistatic inline u16 rx_q_entry_to_length (u32 x) { 5088c2ecf20Sopenharmony_ci return x & RX_Q_ENTRY_LENGTH_MASK; 5098c2ecf20Sopenharmony_ci} 5108c2ecf20Sopenharmony_ci 5118c2ecf20Sopenharmony_cistatic inline u16 rx_q_entry_to_rx_channel (u32 x) { 5128c2ecf20Sopenharmony_ci return (x>>RX_Q_ENTRY_CHANNEL_SHIFT) & RX_CHANNEL_MASK; 5138c2ecf20Sopenharmony_ci} 5148c2ecf20Sopenharmony_ci 5158c2ecf20Sopenharmony_ci/* Cell Transmit Rate Values 5168c2ecf20Sopenharmony_ci * 5178c2ecf20Sopenharmony_ci * the cell transmit rate (cells per sec) can be set to a variety of 5188c2ecf20Sopenharmony_ci * different values by specifying two parameters: a timer preload from 5198c2ecf20Sopenharmony_ci * 1 to 16 (stored as 0 to 15) and a clock divider (2 to the power of 5208c2ecf20Sopenharmony_ci * an exponent from 0 to 14; the special value 15 disables the timer). 5218c2ecf20Sopenharmony_ci * 5228c2ecf20Sopenharmony_ci * cellrate = baserate / (preload * 2^divider) 5238c2ecf20Sopenharmony_ci * 5248c2ecf20Sopenharmony_ci * The maximum cell rate that can be specified is therefore just the 5258c2ecf20Sopenharmony_ci * base rate. Halving the preload is equivalent to adding 1 to the 5268c2ecf20Sopenharmony_ci * divider and so values 1 to 8 of the preload are redundant except 5278c2ecf20Sopenharmony_ci * in the case of a maximal divider (14). 5288c2ecf20Sopenharmony_ci * 5298c2ecf20Sopenharmony_ci * Given a desired cell rate, an algorithm to determine the preload 5308c2ecf20Sopenharmony_ci * and divider is: 5318c2ecf20Sopenharmony_ci * 5328c2ecf20Sopenharmony_ci * a) x = baserate / cellrate, want p * 2^d = x (as far as possible) 5338c2ecf20Sopenharmony_ci * b) if x > 16 * 2^14 then set p = 16, d = 14 (min rate), done 5348c2ecf20Sopenharmony_ci * if x <= 16 then set p = x, d = 0 (high rates), done 5358c2ecf20Sopenharmony_ci * c) now have 16 < x <= 2^18, or 1 < x/16 <= 2^14 and we want to 5368c2ecf20Sopenharmony_ci * know n such that 2^(n-1) < x/16 <= 2^n, so slide a bit until 5378c2ecf20Sopenharmony_ci * we find the range (n will be between 1 and 14), set d = n 5388c2ecf20Sopenharmony_ci * d) Also have 8 < x/2^n <= 16, so set p nearest x/2^n 5398c2ecf20Sopenharmony_ci * 5408c2ecf20Sopenharmony_ci * The algorithm used below is a minor variant of the above. 5418c2ecf20Sopenharmony_ci * 5428c2ecf20Sopenharmony_ci * The base rate is derived from the oscillator frequency (Hz) using a 5438c2ecf20Sopenharmony_ci * fixed divider: 5448c2ecf20Sopenharmony_ci * 5458c2ecf20Sopenharmony_ci * baserate = freq / 32 in the case of some Unknown Card 5468c2ecf20Sopenharmony_ci * baserate = freq / 8 in the case of the Horizon 25 5478c2ecf20Sopenharmony_ci * baserate = freq / 8 in the case of the Horizon Ultra 155 5488c2ecf20Sopenharmony_ci * 5498c2ecf20Sopenharmony_ci * The Horizon cards have oscillators and base rates as follows: 5508c2ecf20Sopenharmony_ci * 5518c2ecf20Sopenharmony_ci * Card Oscillator Base Rate 5528c2ecf20Sopenharmony_ci * Unknown Card 33 MHz 1.03125 MHz (33 MHz = PCI freq) 5538c2ecf20Sopenharmony_ci * Horizon 25 32 MHz 4 MHz 5548c2ecf20Sopenharmony_ci * Horizon Ultra 155 40 MHz 5 MHz 5558c2ecf20Sopenharmony_ci * 5568c2ecf20Sopenharmony_ci * The following defines give the base rates in Hz. These were 5578c2ecf20Sopenharmony_ci * previously a factor of 100 larger, no doubt someone was using 5588c2ecf20Sopenharmony_ci * cps*100. 5598c2ecf20Sopenharmony_ci */ 5608c2ecf20Sopenharmony_ci 5618c2ecf20Sopenharmony_ci#define BR_UKN 1031250l 5628c2ecf20Sopenharmony_ci#define BR_HRZ 4000000l 5638c2ecf20Sopenharmony_ci#define BR_ULT 5000000l 5648c2ecf20Sopenharmony_ci 5658c2ecf20Sopenharmony_ci// d is an exponent 5668c2ecf20Sopenharmony_ci#define CR_MIND 0 5678c2ecf20Sopenharmony_ci#define CR_MAXD 14 5688c2ecf20Sopenharmony_ci 5698c2ecf20Sopenharmony_ci// p ranges from 1 to a power of 2 5708c2ecf20Sopenharmony_ci#define CR_MAXPEXP 4 5718c2ecf20Sopenharmony_ci 5728c2ecf20Sopenharmony_cistatic int make_rate (const hrz_dev * dev, u32 c, rounding r, 5738c2ecf20Sopenharmony_ci u16 * bits, unsigned int * actual) 5748c2ecf20Sopenharmony_ci{ 5758c2ecf20Sopenharmony_ci // note: rounding the rate down means rounding 'p' up 5768c2ecf20Sopenharmony_ci const unsigned long br = test_bit(ultra, &dev->flags) ? BR_ULT : BR_HRZ; 5778c2ecf20Sopenharmony_ci 5788c2ecf20Sopenharmony_ci u32 div = CR_MIND; 5798c2ecf20Sopenharmony_ci u32 pre; 5808c2ecf20Sopenharmony_ci 5818c2ecf20Sopenharmony_ci // br_exp and br_man are used to avoid overflowing (c*maxp*2^d) in 5828c2ecf20Sopenharmony_ci // the tests below. We could think harder about exact possibilities 5838c2ecf20Sopenharmony_ci // of failure... 5848c2ecf20Sopenharmony_ci 5858c2ecf20Sopenharmony_ci unsigned long br_man = br; 5868c2ecf20Sopenharmony_ci unsigned int br_exp = 0; 5878c2ecf20Sopenharmony_ci 5888c2ecf20Sopenharmony_ci PRINTD (DBG_QOS|DBG_FLOW, "make_rate b=%lu, c=%u, %s", br, c, 5898c2ecf20Sopenharmony_ci r == round_up ? "up" : r == round_down ? "down" : "nearest"); 5908c2ecf20Sopenharmony_ci 5918c2ecf20Sopenharmony_ci // avoid div by zero 5928c2ecf20Sopenharmony_ci if (!c) { 5938c2ecf20Sopenharmony_ci PRINTD (DBG_QOS|DBG_ERR, "zero rate is not allowed!"); 5948c2ecf20Sopenharmony_ci return -EINVAL; 5958c2ecf20Sopenharmony_ci } 5968c2ecf20Sopenharmony_ci 5978c2ecf20Sopenharmony_ci while (br_exp < CR_MAXPEXP + CR_MIND && (br_man % 2 == 0)) { 5988c2ecf20Sopenharmony_ci br_man = br_man >> 1; 5998c2ecf20Sopenharmony_ci ++br_exp; 6008c2ecf20Sopenharmony_ci } 6018c2ecf20Sopenharmony_ci // (br >>br_exp) <<br_exp == br and 6028c2ecf20Sopenharmony_ci // br_exp <= CR_MAXPEXP+CR_MIND 6038c2ecf20Sopenharmony_ci 6048c2ecf20Sopenharmony_ci if (br_man <= (c << (CR_MAXPEXP+CR_MIND-br_exp))) { 6058c2ecf20Sopenharmony_ci // Equivalent to: B <= (c << (MAXPEXP+MIND)) 6068c2ecf20Sopenharmony_ci // take care of rounding 6078c2ecf20Sopenharmony_ci switch (r) { 6088c2ecf20Sopenharmony_ci case round_down: 6098c2ecf20Sopenharmony_ci pre = DIV_ROUND_UP(br, c<<div); 6108c2ecf20Sopenharmony_ci // but p must be non-zero 6118c2ecf20Sopenharmony_ci if (!pre) 6128c2ecf20Sopenharmony_ci pre = 1; 6138c2ecf20Sopenharmony_ci break; 6148c2ecf20Sopenharmony_ci case round_nearest: 6158c2ecf20Sopenharmony_ci pre = DIV_ROUND_CLOSEST(br, c<<div); 6168c2ecf20Sopenharmony_ci // but p must be non-zero 6178c2ecf20Sopenharmony_ci if (!pre) 6188c2ecf20Sopenharmony_ci pre = 1; 6198c2ecf20Sopenharmony_ci break; 6208c2ecf20Sopenharmony_ci default: /* round_up */ 6218c2ecf20Sopenharmony_ci pre = br/(c<<div); 6228c2ecf20Sopenharmony_ci // but p must be non-zero 6238c2ecf20Sopenharmony_ci if (!pre) 6248c2ecf20Sopenharmony_ci return -EINVAL; 6258c2ecf20Sopenharmony_ci } 6268c2ecf20Sopenharmony_ci PRINTD (DBG_QOS, "A: p=%u, d=%u", pre, div); 6278c2ecf20Sopenharmony_ci goto got_it; 6288c2ecf20Sopenharmony_ci } 6298c2ecf20Sopenharmony_ci 6308c2ecf20Sopenharmony_ci // at this point we have 6318c2ecf20Sopenharmony_ci // d == MIND and (c << (MAXPEXP+MIND)) < B 6328c2ecf20Sopenharmony_ci while (div < CR_MAXD) { 6338c2ecf20Sopenharmony_ci div++; 6348c2ecf20Sopenharmony_ci if (br_man <= (c << (CR_MAXPEXP+div-br_exp))) { 6358c2ecf20Sopenharmony_ci // Equivalent to: B <= (c << (MAXPEXP+d)) 6368c2ecf20Sopenharmony_ci // c << (MAXPEXP+d-1) < B <= c << (MAXPEXP+d) 6378c2ecf20Sopenharmony_ci // 1 << (MAXPEXP-1) < B/2^d/c <= 1 << MAXPEXP 6388c2ecf20Sopenharmony_ci // MAXP/2 < B/c2^d <= MAXP 6398c2ecf20Sopenharmony_ci // take care of rounding 6408c2ecf20Sopenharmony_ci switch (r) { 6418c2ecf20Sopenharmony_ci case round_down: 6428c2ecf20Sopenharmony_ci pre = DIV_ROUND_UP(br, c<<div); 6438c2ecf20Sopenharmony_ci break; 6448c2ecf20Sopenharmony_ci case round_nearest: 6458c2ecf20Sopenharmony_ci pre = DIV_ROUND_CLOSEST(br, c<<div); 6468c2ecf20Sopenharmony_ci break; 6478c2ecf20Sopenharmony_ci default: /* round_up */ 6488c2ecf20Sopenharmony_ci pre = br/(c<<div); 6498c2ecf20Sopenharmony_ci } 6508c2ecf20Sopenharmony_ci PRINTD (DBG_QOS, "B: p=%u, d=%u", pre, div); 6518c2ecf20Sopenharmony_ci goto got_it; 6528c2ecf20Sopenharmony_ci } 6538c2ecf20Sopenharmony_ci } 6548c2ecf20Sopenharmony_ci // at this point we have 6558c2ecf20Sopenharmony_ci // d == MAXD and (c << (MAXPEXP+MAXD)) < B 6568c2ecf20Sopenharmony_ci // but we cannot go any higher 6578c2ecf20Sopenharmony_ci // take care of rounding 6588c2ecf20Sopenharmony_ci if (r == round_down) 6598c2ecf20Sopenharmony_ci return -EINVAL; 6608c2ecf20Sopenharmony_ci pre = 1 << CR_MAXPEXP; 6618c2ecf20Sopenharmony_ci PRINTD (DBG_QOS, "C: p=%u, d=%u", pre, div); 6628c2ecf20Sopenharmony_cigot_it: 6638c2ecf20Sopenharmony_ci // paranoia 6648c2ecf20Sopenharmony_ci if (div > CR_MAXD || (!pre) || pre > 1<<CR_MAXPEXP) { 6658c2ecf20Sopenharmony_ci PRINTD (DBG_QOS, "set_cr internal failure: d=%u p=%u", 6668c2ecf20Sopenharmony_ci div, pre); 6678c2ecf20Sopenharmony_ci return -EINVAL; 6688c2ecf20Sopenharmony_ci } else { 6698c2ecf20Sopenharmony_ci if (bits) 6708c2ecf20Sopenharmony_ci *bits = (div<<CLOCK_SELECT_SHIFT) | (pre-1); 6718c2ecf20Sopenharmony_ci if (actual) { 6728c2ecf20Sopenharmony_ci *actual = DIV_ROUND_UP(br, pre<<div); 6738c2ecf20Sopenharmony_ci PRINTD (DBG_QOS, "actual rate: %u", *actual); 6748c2ecf20Sopenharmony_ci } 6758c2ecf20Sopenharmony_ci return 0; 6768c2ecf20Sopenharmony_ci } 6778c2ecf20Sopenharmony_ci} 6788c2ecf20Sopenharmony_ci 6798c2ecf20Sopenharmony_cistatic int make_rate_with_tolerance (const hrz_dev * dev, u32 c, rounding r, unsigned int tol, 6808c2ecf20Sopenharmony_ci u16 * bit_pattern, unsigned int * actual) { 6818c2ecf20Sopenharmony_ci unsigned int my_actual; 6828c2ecf20Sopenharmony_ci 6838c2ecf20Sopenharmony_ci PRINTD (DBG_QOS|DBG_FLOW, "make_rate_with_tolerance c=%u, %s, tol=%u", 6848c2ecf20Sopenharmony_ci c, (r == round_up) ? "up" : (r == round_down) ? "down" : "nearest", tol); 6858c2ecf20Sopenharmony_ci 6868c2ecf20Sopenharmony_ci if (!actual) 6878c2ecf20Sopenharmony_ci // actual rate is not returned 6888c2ecf20Sopenharmony_ci actual = &my_actual; 6898c2ecf20Sopenharmony_ci 6908c2ecf20Sopenharmony_ci if (make_rate (dev, c, round_nearest, bit_pattern, actual)) 6918c2ecf20Sopenharmony_ci // should never happen as round_nearest always succeeds 6928c2ecf20Sopenharmony_ci return -1; 6938c2ecf20Sopenharmony_ci 6948c2ecf20Sopenharmony_ci if (c - tol <= *actual && *actual <= c + tol) 6958c2ecf20Sopenharmony_ci // within tolerance 6968c2ecf20Sopenharmony_ci return 0; 6978c2ecf20Sopenharmony_ci else 6988c2ecf20Sopenharmony_ci // intolerant, try rounding instead 6998c2ecf20Sopenharmony_ci return make_rate (dev, c, r, bit_pattern, actual); 7008c2ecf20Sopenharmony_ci} 7018c2ecf20Sopenharmony_ci 7028c2ecf20Sopenharmony_ci/********** Listen on a VC **********/ 7038c2ecf20Sopenharmony_ci 7048c2ecf20Sopenharmony_cistatic int hrz_open_rx (hrz_dev * dev, u16 channel) { 7058c2ecf20Sopenharmony_ci // is there any guarantee that we don't get two simulataneous 7068c2ecf20Sopenharmony_ci // identical calls of this function from different processes? yes 7078c2ecf20Sopenharmony_ci // rate_lock 7088c2ecf20Sopenharmony_ci unsigned long flags; 7098c2ecf20Sopenharmony_ci u32 channel_type; // u16? 7108c2ecf20Sopenharmony_ci 7118c2ecf20Sopenharmony_ci u16 buf_ptr = RX_CHANNEL_IDLE; 7128c2ecf20Sopenharmony_ci 7138c2ecf20Sopenharmony_ci rx_ch_desc * rx_desc = &memmap->rx_descs[channel]; 7148c2ecf20Sopenharmony_ci 7158c2ecf20Sopenharmony_ci PRINTD (DBG_FLOW, "hrz_open_rx %x", channel); 7168c2ecf20Sopenharmony_ci 7178c2ecf20Sopenharmony_ci spin_lock_irqsave (&dev->mem_lock, flags); 7188c2ecf20Sopenharmony_ci channel_type = rd_mem (dev, &rx_desc->wr_buf_type) & BUFFER_PTR_MASK; 7198c2ecf20Sopenharmony_ci spin_unlock_irqrestore (&dev->mem_lock, flags); 7208c2ecf20Sopenharmony_ci 7218c2ecf20Sopenharmony_ci // very serious error, should never occur 7228c2ecf20Sopenharmony_ci if (channel_type != RX_CHANNEL_DISABLED) { 7238c2ecf20Sopenharmony_ci PRINTD (DBG_ERR|DBG_VCC, "RX channel for VC already open"); 7248c2ecf20Sopenharmony_ci return -EBUSY; // clean up? 7258c2ecf20Sopenharmony_ci } 7268c2ecf20Sopenharmony_ci 7278c2ecf20Sopenharmony_ci // Give back spare buffer 7288c2ecf20Sopenharmony_ci if (dev->noof_spare_buffers) { 7298c2ecf20Sopenharmony_ci buf_ptr = dev->spare_buffers[--dev->noof_spare_buffers]; 7308c2ecf20Sopenharmony_ci PRINTD (DBG_VCC, "using a spare buffer: %u", buf_ptr); 7318c2ecf20Sopenharmony_ci // should never occur 7328c2ecf20Sopenharmony_ci if (buf_ptr == RX_CHANNEL_DISABLED || buf_ptr == RX_CHANNEL_IDLE) { 7338c2ecf20Sopenharmony_ci // but easy to recover from 7348c2ecf20Sopenharmony_ci PRINTD (DBG_ERR|DBG_VCC, "bad spare buffer pointer, using IDLE"); 7358c2ecf20Sopenharmony_ci buf_ptr = RX_CHANNEL_IDLE; 7368c2ecf20Sopenharmony_ci } 7378c2ecf20Sopenharmony_ci } else { 7388c2ecf20Sopenharmony_ci PRINTD (DBG_VCC, "using IDLE buffer pointer"); 7398c2ecf20Sopenharmony_ci } 7408c2ecf20Sopenharmony_ci 7418c2ecf20Sopenharmony_ci // Channel is currently disabled so change its status to idle 7428c2ecf20Sopenharmony_ci 7438c2ecf20Sopenharmony_ci // do we really need to save the flags again? 7448c2ecf20Sopenharmony_ci spin_lock_irqsave (&dev->mem_lock, flags); 7458c2ecf20Sopenharmony_ci 7468c2ecf20Sopenharmony_ci wr_mem (dev, &rx_desc->wr_buf_type, 7478c2ecf20Sopenharmony_ci buf_ptr | CHANNEL_TYPE_AAL5 | FIRST_CELL_OF_AAL5_FRAME); 7488c2ecf20Sopenharmony_ci if (buf_ptr != RX_CHANNEL_IDLE) 7498c2ecf20Sopenharmony_ci wr_mem (dev, &rx_desc->rd_buf_type, buf_ptr); 7508c2ecf20Sopenharmony_ci 7518c2ecf20Sopenharmony_ci spin_unlock_irqrestore (&dev->mem_lock, flags); 7528c2ecf20Sopenharmony_ci 7538c2ecf20Sopenharmony_ci // rxer->rate = make_rate (qos->peak_cells); 7548c2ecf20Sopenharmony_ci 7558c2ecf20Sopenharmony_ci PRINTD (DBG_FLOW, "hrz_open_rx ok"); 7568c2ecf20Sopenharmony_ci 7578c2ecf20Sopenharmony_ci return 0; 7588c2ecf20Sopenharmony_ci} 7598c2ecf20Sopenharmony_ci 7608c2ecf20Sopenharmony_ci#if 0 7618c2ecf20Sopenharmony_ci/********** change vc rate for a given vc **********/ 7628c2ecf20Sopenharmony_ci 7638c2ecf20Sopenharmony_cistatic void hrz_change_vc_qos (ATM_RXER * rxer, MAAL_QOS * qos) { 7648c2ecf20Sopenharmony_ci rxer->rate = make_rate (qos->peak_cells); 7658c2ecf20Sopenharmony_ci} 7668c2ecf20Sopenharmony_ci#endif 7678c2ecf20Sopenharmony_ci 7688c2ecf20Sopenharmony_ci/********** free an skb (as per ATM device driver documentation) **********/ 7698c2ecf20Sopenharmony_ci 7708c2ecf20Sopenharmony_cistatic void hrz_kfree_skb (struct sk_buff * skb) { 7718c2ecf20Sopenharmony_ci if (ATM_SKB(skb)->vcc->pop) { 7728c2ecf20Sopenharmony_ci ATM_SKB(skb)->vcc->pop (ATM_SKB(skb)->vcc, skb); 7738c2ecf20Sopenharmony_ci } else { 7748c2ecf20Sopenharmony_ci dev_kfree_skb_any (skb); 7758c2ecf20Sopenharmony_ci } 7768c2ecf20Sopenharmony_ci} 7778c2ecf20Sopenharmony_ci 7788c2ecf20Sopenharmony_ci/********** cancel listen on a VC **********/ 7798c2ecf20Sopenharmony_ci 7808c2ecf20Sopenharmony_cistatic void hrz_close_rx (hrz_dev * dev, u16 vc) { 7818c2ecf20Sopenharmony_ci unsigned long flags; 7828c2ecf20Sopenharmony_ci 7838c2ecf20Sopenharmony_ci u32 value; 7848c2ecf20Sopenharmony_ci 7858c2ecf20Sopenharmony_ci u32 r1, r2; 7868c2ecf20Sopenharmony_ci 7878c2ecf20Sopenharmony_ci rx_ch_desc * rx_desc = &memmap->rx_descs[vc]; 7888c2ecf20Sopenharmony_ci 7898c2ecf20Sopenharmony_ci int was_idle = 0; 7908c2ecf20Sopenharmony_ci 7918c2ecf20Sopenharmony_ci spin_lock_irqsave (&dev->mem_lock, flags); 7928c2ecf20Sopenharmony_ci value = rd_mem (dev, &rx_desc->wr_buf_type) & BUFFER_PTR_MASK; 7938c2ecf20Sopenharmony_ci spin_unlock_irqrestore (&dev->mem_lock, flags); 7948c2ecf20Sopenharmony_ci 7958c2ecf20Sopenharmony_ci if (value == RX_CHANNEL_DISABLED) { 7968c2ecf20Sopenharmony_ci // I suppose this could happen once we deal with _NONE traffic properly 7978c2ecf20Sopenharmony_ci PRINTD (DBG_VCC, "closing VC: RX channel %u already disabled", vc); 7988c2ecf20Sopenharmony_ci return; 7998c2ecf20Sopenharmony_ci } 8008c2ecf20Sopenharmony_ci if (value == RX_CHANNEL_IDLE) 8018c2ecf20Sopenharmony_ci was_idle = 1; 8028c2ecf20Sopenharmony_ci 8038c2ecf20Sopenharmony_ci spin_lock_irqsave (&dev->mem_lock, flags); 8048c2ecf20Sopenharmony_ci 8058c2ecf20Sopenharmony_ci for (;;) { 8068c2ecf20Sopenharmony_ci wr_mem (dev, &rx_desc->wr_buf_type, RX_CHANNEL_DISABLED); 8078c2ecf20Sopenharmony_ci 8088c2ecf20Sopenharmony_ci if ((rd_mem (dev, &rx_desc->wr_buf_type) & BUFFER_PTR_MASK) == RX_CHANNEL_DISABLED) 8098c2ecf20Sopenharmony_ci break; 8108c2ecf20Sopenharmony_ci 8118c2ecf20Sopenharmony_ci was_idle = 0; 8128c2ecf20Sopenharmony_ci } 8138c2ecf20Sopenharmony_ci 8148c2ecf20Sopenharmony_ci if (was_idle) { 8158c2ecf20Sopenharmony_ci spin_unlock_irqrestore (&dev->mem_lock, flags); 8168c2ecf20Sopenharmony_ci return; 8178c2ecf20Sopenharmony_ci } 8188c2ecf20Sopenharmony_ci 8198c2ecf20Sopenharmony_ci WAIT_FLUSH_RX_COMPLETE(dev); 8208c2ecf20Sopenharmony_ci 8218c2ecf20Sopenharmony_ci // XXX Is this all really necessary? We can rely on the rx_data_av 8228c2ecf20Sopenharmony_ci // handler to discard frames that remain queued for delivery. If the 8238c2ecf20Sopenharmony_ci // worry is that immediately reopening the channel (perhaps by a 8248c2ecf20Sopenharmony_ci // different process) may cause some data to be mis-delivered then 8258c2ecf20Sopenharmony_ci // there may still be a simpler solution (such as busy-waiting on 8268c2ecf20Sopenharmony_ci // rx_busy once the channel is disabled or before a new one is 8278c2ecf20Sopenharmony_ci // opened - does this leave any holes?). Arguably setting up and 8288c2ecf20Sopenharmony_ci // tearing down the TX and RX halves of each virtual circuit could 8298c2ecf20Sopenharmony_ci // most safely be done within ?x_busy protected regions. 8308c2ecf20Sopenharmony_ci 8318c2ecf20Sopenharmony_ci // OK, current changes are that Simon's marker is disabled and we DO 8328c2ecf20Sopenharmony_ci // look for NULL rxer elsewhere. The code here seems flush frames 8338c2ecf20Sopenharmony_ci // and then remember the last dead cell belonging to the channel 8348c2ecf20Sopenharmony_ci // just disabled - the cell gets relinked at the next vc_open. 8358c2ecf20Sopenharmony_ci // However, when all VCs are closed or only a few opened there are a 8368c2ecf20Sopenharmony_ci // handful of buffers that are unusable. 8378c2ecf20Sopenharmony_ci 8388c2ecf20Sopenharmony_ci // Does anyone feel like documenting spare_buffers properly? 8398c2ecf20Sopenharmony_ci // Does anyone feel like fixing this in a nicer way? 8408c2ecf20Sopenharmony_ci 8418c2ecf20Sopenharmony_ci // Flush any data which is left in the channel 8428c2ecf20Sopenharmony_ci for (;;) { 8438c2ecf20Sopenharmony_ci // Change the rx channel port to something different to the RX 8448c2ecf20Sopenharmony_ci // channel we are trying to close to force Horizon to flush the rx 8458c2ecf20Sopenharmony_ci // channel read and write pointers. 8468c2ecf20Sopenharmony_ci 8478c2ecf20Sopenharmony_ci u16 other = vc^(RX_CHANS/2); 8488c2ecf20Sopenharmony_ci 8498c2ecf20Sopenharmony_ci SELECT_RX_CHANNEL (dev, other); 8508c2ecf20Sopenharmony_ci WAIT_UPDATE_COMPLETE (dev); 8518c2ecf20Sopenharmony_ci 8528c2ecf20Sopenharmony_ci r1 = rd_mem (dev, &rx_desc->rd_buf_type); 8538c2ecf20Sopenharmony_ci 8548c2ecf20Sopenharmony_ci // Select this RX channel. Flush doesn't seem to work unless we 8558c2ecf20Sopenharmony_ci // select an RX channel before hand 8568c2ecf20Sopenharmony_ci 8578c2ecf20Sopenharmony_ci SELECT_RX_CHANNEL (dev, vc); 8588c2ecf20Sopenharmony_ci WAIT_UPDATE_COMPLETE (dev); 8598c2ecf20Sopenharmony_ci 8608c2ecf20Sopenharmony_ci // Attempt to flush a frame on this RX channel 8618c2ecf20Sopenharmony_ci 8628c2ecf20Sopenharmony_ci FLUSH_RX_CHANNEL (dev, vc); 8638c2ecf20Sopenharmony_ci WAIT_FLUSH_RX_COMPLETE (dev); 8648c2ecf20Sopenharmony_ci 8658c2ecf20Sopenharmony_ci // Force Horizon to flush rx channel read and write pointers as before 8668c2ecf20Sopenharmony_ci 8678c2ecf20Sopenharmony_ci SELECT_RX_CHANNEL (dev, other); 8688c2ecf20Sopenharmony_ci WAIT_UPDATE_COMPLETE (dev); 8698c2ecf20Sopenharmony_ci 8708c2ecf20Sopenharmony_ci r2 = rd_mem (dev, &rx_desc->rd_buf_type); 8718c2ecf20Sopenharmony_ci 8728c2ecf20Sopenharmony_ci PRINTD (DBG_VCC|DBG_RX, "r1 = %u, r2 = %u", r1, r2); 8738c2ecf20Sopenharmony_ci 8748c2ecf20Sopenharmony_ci if (r1 == r2) { 8758c2ecf20Sopenharmony_ci dev->spare_buffers[dev->noof_spare_buffers++] = (u16)r1; 8768c2ecf20Sopenharmony_ci break; 8778c2ecf20Sopenharmony_ci } 8788c2ecf20Sopenharmony_ci } 8798c2ecf20Sopenharmony_ci 8808c2ecf20Sopenharmony_ci#if 0 8818c2ecf20Sopenharmony_ci { 8828c2ecf20Sopenharmony_ci rx_q_entry * wr_ptr = &memmap->rx_q_entries[rd_regw (dev, RX_QUEUE_WR_PTR_OFF)]; 8838c2ecf20Sopenharmony_ci rx_q_entry * rd_ptr = dev->rx_q_entry; 8848c2ecf20Sopenharmony_ci 8858c2ecf20Sopenharmony_ci PRINTD (DBG_VCC|DBG_RX, "rd_ptr = %u, wr_ptr = %u", rd_ptr, wr_ptr); 8868c2ecf20Sopenharmony_ci 8878c2ecf20Sopenharmony_ci while (rd_ptr != wr_ptr) { 8888c2ecf20Sopenharmony_ci u32 x = rd_mem (dev, (HDW *) rd_ptr); 8898c2ecf20Sopenharmony_ci 8908c2ecf20Sopenharmony_ci if (vc == rx_q_entry_to_rx_channel (x)) { 8918c2ecf20Sopenharmony_ci x |= SIMONS_DODGEY_MARKER; 8928c2ecf20Sopenharmony_ci 8938c2ecf20Sopenharmony_ci PRINTD (DBG_RX|DBG_VCC|DBG_WARN, "marking a frame as dodgey"); 8948c2ecf20Sopenharmony_ci 8958c2ecf20Sopenharmony_ci wr_mem (dev, (HDW *) rd_ptr, x); 8968c2ecf20Sopenharmony_ci } 8978c2ecf20Sopenharmony_ci 8988c2ecf20Sopenharmony_ci if (rd_ptr == dev->rx_q_wrap) 8998c2ecf20Sopenharmony_ci rd_ptr = dev->rx_q_reset; 9008c2ecf20Sopenharmony_ci else 9018c2ecf20Sopenharmony_ci rd_ptr++; 9028c2ecf20Sopenharmony_ci } 9038c2ecf20Sopenharmony_ci } 9048c2ecf20Sopenharmony_ci#endif 9058c2ecf20Sopenharmony_ci 9068c2ecf20Sopenharmony_ci spin_unlock_irqrestore (&dev->mem_lock, flags); 9078c2ecf20Sopenharmony_ci 9088c2ecf20Sopenharmony_ci return; 9098c2ecf20Sopenharmony_ci} 9108c2ecf20Sopenharmony_ci 9118c2ecf20Sopenharmony_ci/********** schedule RX transfers **********/ 9128c2ecf20Sopenharmony_ci 9138c2ecf20Sopenharmony_ci// Note on tail recursion: a GCC developer said that it is not likely 9148c2ecf20Sopenharmony_ci// to be fixed soon, so do not define TAILRECUSRIONWORKS unless you 9158c2ecf20Sopenharmony_ci// are sure it does as you may otherwise overflow the kernel stack. 9168c2ecf20Sopenharmony_ci 9178c2ecf20Sopenharmony_ci// giving this fn a return value would help GCC, allegedly 9188c2ecf20Sopenharmony_ci 9198c2ecf20Sopenharmony_cistatic void rx_schedule (hrz_dev * dev, int irq) { 9208c2ecf20Sopenharmony_ci unsigned int rx_bytes; 9218c2ecf20Sopenharmony_ci 9228c2ecf20Sopenharmony_ci int pio_instead = 0; 9238c2ecf20Sopenharmony_ci#ifndef TAILRECURSIONWORKS 9248c2ecf20Sopenharmony_ci pio_instead = 1; 9258c2ecf20Sopenharmony_ci while (pio_instead) { 9268c2ecf20Sopenharmony_ci#endif 9278c2ecf20Sopenharmony_ci // bytes waiting for RX transfer 9288c2ecf20Sopenharmony_ci rx_bytes = dev->rx_bytes; 9298c2ecf20Sopenharmony_ci 9308c2ecf20Sopenharmony_ci#if 0 9318c2ecf20Sopenharmony_ci spin_count = 0; 9328c2ecf20Sopenharmony_ci while (rd_regl (dev, MASTER_RX_COUNT_REG_OFF)) { 9338c2ecf20Sopenharmony_ci PRINTD (DBG_RX|DBG_WARN, "RX error: other PCI Bus Master RX still in progress!"); 9348c2ecf20Sopenharmony_ci if (++spin_count > 10) { 9358c2ecf20Sopenharmony_ci PRINTD (DBG_RX|DBG_ERR, "spun out waiting PCI Bus Master RX completion"); 9368c2ecf20Sopenharmony_ci wr_regl (dev, MASTER_RX_COUNT_REG_OFF, 0); 9378c2ecf20Sopenharmony_ci clear_bit (rx_busy, &dev->flags); 9388c2ecf20Sopenharmony_ci hrz_kfree_skb (dev->rx_skb); 9398c2ecf20Sopenharmony_ci return; 9408c2ecf20Sopenharmony_ci } 9418c2ecf20Sopenharmony_ci } 9428c2ecf20Sopenharmony_ci#endif 9438c2ecf20Sopenharmony_ci 9448c2ecf20Sopenharmony_ci // this code follows the TX code but (at the moment) there is only 9458c2ecf20Sopenharmony_ci // one region - the skb itself. I don't know if this will change, 9468c2ecf20Sopenharmony_ci // but it doesn't hurt to have the code here, disabled. 9478c2ecf20Sopenharmony_ci 9488c2ecf20Sopenharmony_ci if (rx_bytes) { 9498c2ecf20Sopenharmony_ci // start next transfer within same region 9508c2ecf20Sopenharmony_ci if (rx_bytes <= MAX_PIO_COUNT) { 9518c2ecf20Sopenharmony_ci PRINTD (DBG_RX|DBG_BUS, "(pio)"); 9528c2ecf20Sopenharmony_ci pio_instead = 1; 9538c2ecf20Sopenharmony_ci } 9548c2ecf20Sopenharmony_ci if (rx_bytes <= MAX_TRANSFER_COUNT) { 9558c2ecf20Sopenharmony_ci PRINTD (DBG_RX|DBG_BUS, "(simple or last multi)"); 9568c2ecf20Sopenharmony_ci dev->rx_bytes = 0; 9578c2ecf20Sopenharmony_ci } else { 9588c2ecf20Sopenharmony_ci PRINTD (DBG_RX|DBG_BUS, "(continuing multi)"); 9598c2ecf20Sopenharmony_ci dev->rx_bytes = rx_bytes - MAX_TRANSFER_COUNT; 9608c2ecf20Sopenharmony_ci rx_bytes = MAX_TRANSFER_COUNT; 9618c2ecf20Sopenharmony_ci } 9628c2ecf20Sopenharmony_ci } else { 9638c2ecf20Sopenharmony_ci // rx_bytes == 0 -- we're between regions 9648c2ecf20Sopenharmony_ci // regions remaining to transfer 9658c2ecf20Sopenharmony_ci#if 0 9668c2ecf20Sopenharmony_ci unsigned int rx_regions = dev->rx_regions; 9678c2ecf20Sopenharmony_ci#else 9688c2ecf20Sopenharmony_ci unsigned int rx_regions = 0; 9698c2ecf20Sopenharmony_ci#endif 9708c2ecf20Sopenharmony_ci 9718c2ecf20Sopenharmony_ci if (rx_regions) { 9728c2ecf20Sopenharmony_ci#if 0 9738c2ecf20Sopenharmony_ci // start a new region 9748c2ecf20Sopenharmony_ci dev->rx_addr = dev->rx_iovec->iov_base; 9758c2ecf20Sopenharmony_ci rx_bytes = dev->rx_iovec->iov_len; 9768c2ecf20Sopenharmony_ci ++dev->rx_iovec; 9778c2ecf20Sopenharmony_ci dev->rx_regions = rx_regions - 1; 9788c2ecf20Sopenharmony_ci 9798c2ecf20Sopenharmony_ci if (rx_bytes <= MAX_PIO_COUNT) { 9808c2ecf20Sopenharmony_ci PRINTD (DBG_RX|DBG_BUS, "(pio)"); 9818c2ecf20Sopenharmony_ci pio_instead = 1; 9828c2ecf20Sopenharmony_ci } 9838c2ecf20Sopenharmony_ci if (rx_bytes <= MAX_TRANSFER_COUNT) { 9848c2ecf20Sopenharmony_ci PRINTD (DBG_RX|DBG_BUS, "(full region)"); 9858c2ecf20Sopenharmony_ci dev->rx_bytes = 0; 9868c2ecf20Sopenharmony_ci } else { 9878c2ecf20Sopenharmony_ci PRINTD (DBG_RX|DBG_BUS, "(start multi region)"); 9888c2ecf20Sopenharmony_ci dev->rx_bytes = rx_bytes - MAX_TRANSFER_COUNT; 9898c2ecf20Sopenharmony_ci rx_bytes = MAX_TRANSFER_COUNT; 9908c2ecf20Sopenharmony_ci } 9918c2ecf20Sopenharmony_ci#endif 9928c2ecf20Sopenharmony_ci } else { 9938c2ecf20Sopenharmony_ci // rx_regions == 0 9948c2ecf20Sopenharmony_ci // that's all folks - end of frame 9958c2ecf20Sopenharmony_ci struct sk_buff * skb = dev->rx_skb; 9968c2ecf20Sopenharmony_ci // dev->rx_iovec = 0; 9978c2ecf20Sopenharmony_ci 9988c2ecf20Sopenharmony_ci FLUSH_RX_CHANNEL (dev, dev->rx_channel); 9998c2ecf20Sopenharmony_ci 10008c2ecf20Sopenharmony_ci dump_skb ("<<<", dev->rx_channel, skb); 10018c2ecf20Sopenharmony_ci 10028c2ecf20Sopenharmony_ci PRINTD (DBG_RX|DBG_SKB, "push %p %u", skb->data, skb->len); 10038c2ecf20Sopenharmony_ci 10048c2ecf20Sopenharmony_ci { 10058c2ecf20Sopenharmony_ci struct atm_vcc * vcc = ATM_SKB(skb)->vcc; 10068c2ecf20Sopenharmony_ci // VC layer stats 10078c2ecf20Sopenharmony_ci atomic_inc(&vcc->stats->rx); 10088c2ecf20Sopenharmony_ci __net_timestamp(skb); 10098c2ecf20Sopenharmony_ci // end of our responsibility 10108c2ecf20Sopenharmony_ci vcc->push (vcc, skb); 10118c2ecf20Sopenharmony_ci } 10128c2ecf20Sopenharmony_ci } 10138c2ecf20Sopenharmony_ci } 10148c2ecf20Sopenharmony_ci 10158c2ecf20Sopenharmony_ci // note: writing RX_COUNT clears any interrupt condition 10168c2ecf20Sopenharmony_ci if (rx_bytes) { 10178c2ecf20Sopenharmony_ci if (pio_instead) { 10188c2ecf20Sopenharmony_ci if (irq) 10198c2ecf20Sopenharmony_ci wr_regl (dev, MASTER_RX_COUNT_REG_OFF, 0); 10208c2ecf20Sopenharmony_ci rds_regb (dev, DATA_PORT_OFF, dev->rx_addr, rx_bytes); 10218c2ecf20Sopenharmony_ci } else { 10228c2ecf20Sopenharmony_ci wr_regl (dev, MASTER_RX_ADDR_REG_OFF, virt_to_bus (dev->rx_addr)); 10238c2ecf20Sopenharmony_ci wr_regl (dev, MASTER_RX_COUNT_REG_OFF, rx_bytes); 10248c2ecf20Sopenharmony_ci } 10258c2ecf20Sopenharmony_ci dev->rx_addr += rx_bytes; 10268c2ecf20Sopenharmony_ci } else { 10278c2ecf20Sopenharmony_ci if (irq) 10288c2ecf20Sopenharmony_ci wr_regl (dev, MASTER_RX_COUNT_REG_OFF, 0); 10298c2ecf20Sopenharmony_ci // allow another RX thread to start 10308c2ecf20Sopenharmony_ci YELLOW_LED_ON(dev); 10318c2ecf20Sopenharmony_ci clear_bit (rx_busy, &dev->flags); 10328c2ecf20Sopenharmony_ci PRINTD (DBG_RX, "cleared rx_busy for dev %p", dev); 10338c2ecf20Sopenharmony_ci } 10348c2ecf20Sopenharmony_ci 10358c2ecf20Sopenharmony_ci#ifdef TAILRECURSIONWORKS 10368c2ecf20Sopenharmony_ci // and we all bless optimised tail calls 10378c2ecf20Sopenharmony_ci if (pio_instead) 10388c2ecf20Sopenharmony_ci return rx_schedule (dev, 0); 10398c2ecf20Sopenharmony_ci return; 10408c2ecf20Sopenharmony_ci#else 10418c2ecf20Sopenharmony_ci // grrrrrrr! 10428c2ecf20Sopenharmony_ci irq = 0; 10438c2ecf20Sopenharmony_ci } 10448c2ecf20Sopenharmony_ci return; 10458c2ecf20Sopenharmony_ci#endif 10468c2ecf20Sopenharmony_ci} 10478c2ecf20Sopenharmony_ci 10488c2ecf20Sopenharmony_ci/********** handle RX bus master complete events **********/ 10498c2ecf20Sopenharmony_ci 10508c2ecf20Sopenharmony_cistatic void rx_bus_master_complete_handler (hrz_dev * dev) { 10518c2ecf20Sopenharmony_ci if (test_bit (rx_busy, &dev->flags)) { 10528c2ecf20Sopenharmony_ci rx_schedule (dev, 1); 10538c2ecf20Sopenharmony_ci } else { 10548c2ecf20Sopenharmony_ci PRINTD (DBG_RX|DBG_ERR, "unexpected RX bus master completion"); 10558c2ecf20Sopenharmony_ci // clear interrupt condition on adapter 10568c2ecf20Sopenharmony_ci wr_regl (dev, MASTER_RX_COUNT_REG_OFF, 0); 10578c2ecf20Sopenharmony_ci } 10588c2ecf20Sopenharmony_ci return; 10598c2ecf20Sopenharmony_ci} 10608c2ecf20Sopenharmony_ci 10618c2ecf20Sopenharmony_ci/********** (queue to) become the next TX thread **********/ 10628c2ecf20Sopenharmony_ci 10638c2ecf20Sopenharmony_cistatic int tx_hold (hrz_dev * dev) { 10648c2ecf20Sopenharmony_ci PRINTD (DBG_TX, "sleeping at tx lock %p %lu", dev, dev->flags); 10658c2ecf20Sopenharmony_ci wait_event_interruptible(dev->tx_queue, (!test_and_set_bit(tx_busy, &dev->flags))); 10668c2ecf20Sopenharmony_ci PRINTD (DBG_TX, "woken at tx lock %p %lu", dev, dev->flags); 10678c2ecf20Sopenharmony_ci if (signal_pending (current)) 10688c2ecf20Sopenharmony_ci return -1; 10698c2ecf20Sopenharmony_ci PRINTD (DBG_TX, "set tx_busy for dev %p", dev); 10708c2ecf20Sopenharmony_ci return 0; 10718c2ecf20Sopenharmony_ci} 10728c2ecf20Sopenharmony_ci 10738c2ecf20Sopenharmony_ci/********** allow another TX thread to start **********/ 10748c2ecf20Sopenharmony_ci 10758c2ecf20Sopenharmony_cistatic inline void tx_release (hrz_dev * dev) { 10768c2ecf20Sopenharmony_ci clear_bit (tx_busy, &dev->flags); 10778c2ecf20Sopenharmony_ci PRINTD (DBG_TX, "cleared tx_busy for dev %p", dev); 10788c2ecf20Sopenharmony_ci wake_up_interruptible (&dev->tx_queue); 10798c2ecf20Sopenharmony_ci} 10808c2ecf20Sopenharmony_ci 10818c2ecf20Sopenharmony_ci/********** schedule TX transfers **********/ 10828c2ecf20Sopenharmony_ci 10838c2ecf20Sopenharmony_cistatic void tx_schedule (hrz_dev * const dev, int irq) { 10848c2ecf20Sopenharmony_ci unsigned int tx_bytes; 10858c2ecf20Sopenharmony_ci 10868c2ecf20Sopenharmony_ci int append_desc = 0; 10878c2ecf20Sopenharmony_ci 10888c2ecf20Sopenharmony_ci int pio_instead = 0; 10898c2ecf20Sopenharmony_ci#ifndef TAILRECURSIONWORKS 10908c2ecf20Sopenharmony_ci pio_instead = 1; 10918c2ecf20Sopenharmony_ci while (pio_instead) { 10928c2ecf20Sopenharmony_ci#endif 10938c2ecf20Sopenharmony_ci // bytes in current region waiting for TX transfer 10948c2ecf20Sopenharmony_ci tx_bytes = dev->tx_bytes; 10958c2ecf20Sopenharmony_ci 10968c2ecf20Sopenharmony_ci#if 0 10978c2ecf20Sopenharmony_ci spin_count = 0; 10988c2ecf20Sopenharmony_ci while (rd_regl (dev, MASTER_TX_COUNT_REG_OFF)) { 10998c2ecf20Sopenharmony_ci PRINTD (DBG_TX|DBG_WARN, "TX error: other PCI Bus Master TX still in progress!"); 11008c2ecf20Sopenharmony_ci if (++spin_count > 10) { 11018c2ecf20Sopenharmony_ci PRINTD (DBG_TX|DBG_ERR, "spun out waiting PCI Bus Master TX completion"); 11028c2ecf20Sopenharmony_ci wr_regl (dev, MASTER_TX_COUNT_REG_OFF, 0); 11038c2ecf20Sopenharmony_ci tx_release (dev); 11048c2ecf20Sopenharmony_ci hrz_kfree_skb (dev->tx_skb); 11058c2ecf20Sopenharmony_ci return; 11068c2ecf20Sopenharmony_ci } 11078c2ecf20Sopenharmony_ci } 11088c2ecf20Sopenharmony_ci#endif 11098c2ecf20Sopenharmony_ci 11108c2ecf20Sopenharmony_ci if (tx_bytes) { 11118c2ecf20Sopenharmony_ci // start next transfer within same region 11128c2ecf20Sopenharmony_ci if (!test_bit (ultra, &dev->flags) || tx_bytes <= MAX_PIO_COUNT) { 11138c2ecf20Sopenharmony_ci PRINTD (DBG_TX|DBG_BUS, "(pio)"); 11148c2ecf20Sopenharmony_ci pio_instead = 1; 11158c2ecf20Sopenharmony_ci } 11168c2ecf20Sopenharmony_ci if (tx_bytes <= MAX_TRANSFER_COUNT) { 11178c2ecf20Sopenharmony_ci PRINTD (DBG_TX|DBG_BUS, "(simple or last multi)"); 11188c2ecf20Sopenharmony_ci if (!dev->tx_iovec) { 11198c2ecf20Sopenharmony_ci // end of last region 11208c2ecf20Sopenharmony_ci append_desc = 1; 11218c2ecf20Sopenharmony_ci } 11228c2ecf20Sopenharmony_ci dev->tx_bytes = 0; 11238c2ecf20Sopenharmony_ci } else { 11248c2ecf20Sopenharmony_ci PRINTD (DBG_TX|DBG_BUS, "(continuing multi)"); 11258c2ecf20Sopenharmony_ci dev->tx_bytes = tx_bytes - MAX_TRANSFER_COUNT; 11268c2ecf20Sopenharmony_ci tx_bytes = MAX_TRANSFER_COUNT; 11278c2ecf20Sopenharmony_ci } 11288c2ecf20Sopenharmony_ci } else { 11298c2ecf20Sopenharmony_ci // tx_bytes == 0 -- we're between regions 11308c2ecf20Sopenharmony_ci // regions remaining to transfer 11318c2ecf20Sopenharmony_ci unsigned int tx_regions = dev->tx_regions; 11328c2ecf20Sopenharmony_ci 11338c2ecf20Sopenharmony_ci if (tx_regions) { 11348c2ecf20Sopenharmony_ci // start a new region 11358c2ecf20Sopenharmony_ci dev->tx_addr = dev->tx_iovec->iov_base; 11368c2ecf20Sopenharmony_ci tx_bytes = dev->tx_iovec->iov_len; 11378c2ecf20Sopenharmony_ci ++dev->tx_iovec; 11388c2ecf20Sopenharmony_ci dev->tx_regions = tx_regions - 1; 11398c2ecf20Sopenharmony_ci 11408c2ecf20Sopenharmony_ci if (!test_bit (ultra, &dev->flags) || tx_bytes <= MAX_PIO_COUNT) { 11418c2ecf20Sopenharmony_ci PRINTD (DBG_TX|DBG_BUS, "(pio)"); 11428c2ecf20Sopenharmony_ci pio_instead = 1; 11438c2ecf20Sopenharmony_ci } 11448c2ecf20Sopenharmony_ci if (tx_bytes <= MAX_TRANSFER_COUNT) { 11458c2ecf20Sopenharmony_ci PRINTD (DBG_TX|DBG_BUS, "(full region)"); 11468c2ecf20Sopenharmony_ci dev->tx_bytes = 0; 11478c2ecf20Sopenharmony_ci } else { 11488c2ecf20Sopenharmony_ci PRINTD (DBG_TX|DBG_BUS, "(start multi region)"); 11498c2ecf20Sopenharmony_ci dev->tx_bytes = tx_bytes - MAX_TRANSFER_COUNT; 11508c2ecf20Sopenharmony_ci tx_bytes = MAX_TRANSFER_COUNT; 11518c2ecf20Sopenharmony_ci } 11528c2ecf20Sopenharmony_ci } else { 11538c2ecf20Sopenharmony_ci // tx_regions == 0 11548c2ecf20Sopenharmony_ci // that's all folks - end of frame 11558c2ecf20Sopenharmony_ci struct sk_buff * skb = dev->tx_skb; 11568c2ecf20Sopenharmony_ci dev->tx_iovec = NULL; 11578c2ecf20Sopenharmony_ci 11588c2ecf20Sopenharmony_ci // VC layer stats 11598c2ecf20Sopenharmony_ci atomic_inc(&ATM_SKB(skb)->vcc->stats->tx); 11608c2ecf20Sopenharmony_ci 11618c2ecf20Sopenharmony_ci // free the skb 11628c2ecf20Sopenharmony_ci hrz_kfree_skb (skb); 11638c2ecf20Sopenharmony_ci } 11648c2ecf20Sopenharmony_ci } 11658c2ecf20Sopenharmony_ci 11668c2ecf20Sopenharmony_ci // note: writing TX_COUNT clears any interrupt condition 11678c2ecf20Sopenharmony_ci if (tx_bytes) { 11688c2ecf20Sopenharmony_ci if (pio_instead) { 11698c2ecf20Sopenharmony_ci if (irq) 11708c2ecf20Sopenharmony_ci wr_regl (dev, MASTER_TX_COUNT_REG_OFF, 0); 11718c2ecf20Sopenharmony_ci wrs_regb (dev, DATA_PORT_OFF, dev->tx_addr, tx_bytes); 11728c2ecf20Sopenharmony_ci if (append_desc) 11738c2ecf20Sopenharmony_ci wr_regl (dev, TX_DESCRIPTOR_PORT_OFF, cpu_to_be32 (dev->tx_skb->len)); 11748c2ecf20Sopenharmony_ci } else { 11758c2ecf20Sopenharmony_ci wr_regl (dev, MASTER_TX_ADDR_REG_OFF, virt_to_bus (dev->tx_addr)); 11768c2ecf20Sopenharmony_ci if (append_desc) 11778c2ecf20Sopenharmony_ci wr_regl (dev, TX_DESCRIPTOR_REG_OFF, cpu_to_be32 (dev->tx_skb->len)); 11788c2ecf20Sopenharmony_ci wr_regl (dev, MASTER_TX_COUNT_REG_OFF, 11798c2ecf20Sopenharmony_ci append_desc 11808c2ecf20Sopenharmony_ci ? tx_bytes | MASTER_TX_AUTO_APPEND_DESC 11818c2ecf20Sopenharmony_ci : tx_bytes); 11828c2ecf20Sopenharmony_ci } 11838c2ecf20Sopenharmony_ci dev->tx_addr += tx_bytes; 11848c2ecf20Sopenharmony_ci } else { 11858c2ecf20Sopenharmony_ci if (irq) 11868c2ecf20Sopenharmony_ci wr_regl (dev, MASTER_TX_COUNT_REG_OFF, 0); 11878c2ecf20Sopenharmony_ci YELLOW_LED_ON(dev); 11888c2ecf20Sopenharmony_ci tx_release (dev); 11898c2ecf20Sopenharmony_ci } 11908c2ecf20Sopenharmony_ci 11918c2ecf20Sopenharmony_ci#ifdef TAILRECURSIONWORKS 11928c2ecf20Sopenharmony_ci // and we all bless optimised tail calls 11938c2ecf20Sopenharmony_ci if (pio_instead) 11948c2ecf20Sopenharmony_ci return tx_schedule (dev, 0); 11958c2ecf20Sopenharmony_ci return; 11968c2ecf20Sopenharmony_ci#else 11978c2ecf20Sopenharmony_ci // grrrrrrr! 11988c2ecf20Sopenharmony_ci irq = 0; 11998c2ecf20Sopenharmony_ci } 12008c2ecf20Sopenharmony_ci return; 12018c2ecf20Sopenharmony_ci#endif 12028c2ecf20Sopenharmony_ci} 12038c2ecf20Sopenharmony_ci 12048c2ecf20Sopenharmony_ci/********** handle TX bus master complete events **********/ 12058c2ecf20Sopenharmony_ci 12068c2ecf20Sopenharmony_cistatic void tx_bus_master_complete_handler (hrz_dev * dev) { 12078c2ecf20Sopenharmony_ci if (test_bit (tx_busy, &dev->flags)) { 12088c2ecf20Sopenharmony_ci tx_schedule (dev, 1); 12098c2ecf20Sopenharmony_ci } else { 12108c2ecf20Sopenharmony_ci PRINTD (DBG_TX|DBG_ERR, "unexpected TX bus master completion"); 12118c2ecf20Sopenharmony_ci // clear interrupt condition on adapter 12128c2ecf20Sopenharmony_ci wr_regl (dev, MASTER_TX_COUNT_REG_OFF, 0); 12138c2ecf20Sopenharmony_ci } 12148c2ecf20Sopenharmony_ci return; 12158c2ecf20Sopenharmony_ci} 12168c2ecf20Sopenharmony_ci 12178c2ecf20Sopenharmony_ci/********** move RX Q pointer to next item in circular buffer **********/ 12188c2ecf20Sopenharmony_ci 12198c2ecf20Sopenharmony_ci// called only from IRQ sub-handler 12208c2ecf20Sopenharmony_cistatic u32 rx_queue_entry_next (hrz_dev * dev) { 12218c2ecf20Sopenharmony_ci u32 rx_queue_entry; 12228c2ecf20Sopenharmony_ci spin_lock (&dev->mem_lock); 12238c2ecf20Sopenharmony_ci rx_queue_entry = rd_mem (dev, &dev->rx_q_entry->entry); 12248c2ecf20Sopenharmony_ci if (dev->rx_q_entry == dev->rx_q_wrap) 12258c2ecf20Sopenharmony_ci dev->rx_q_entry = dev->rx_q_reset; 12268c2ecf20Sopenharmony_ci else 12278c2ecf20Sopenharmony_ci dev->rx_q_entry++; 12288c2ecf20Sopenharmony_ci wr_regw (dev, RX_QUEUE_RD_PTR_OFF, dev->rx_q_entry - dev->rx_q_reset); 12298c2ecf20Sopenharmony_ci spin_unlock (&dev->mem_lock); 12308c2ecf20Sopenharmony_ci return rx_queue_entry; 12318c2ecf20Sopenharmony_ci} 12328c2ecf20Sopenharmony_ci 12338c2ecf20Sopenharmony_ci/********** handle RX data received by device **********/ 12348c2ecf20Sopenharmony_ci 12358c2ecf20Sopenharmony_ci// called from IRQ handler 12368c2ecf20Sopenharmony_cistatic void rx_data_av_handler (hrz_dev * dev) { 12378c2ecf20Sopenharmony_ci u32 rx_queue_entry; 12388c2ecf20Sopenharmony_ci u32 rx_queue_entry_flags; 12398c2ecf20Sopenharmony_ci u16 rx_len; 12408c2ecf20Sopenharmony_ci u16 rx_channel; 12418c2ecf20Sopenharmony_ci 12428c2ecf20Sopenharmony_ci PRINTD (DBG_FLOW, "hrz_data_av_handler"); 12438c2ecf20Sopenharmony_ci 12448c2ecf20Sopenharmony_ci // try to grab rx lock (not possible during RX bus mastering) 12458c2ecf20Sopenharmony_ci if (test_and_set_bit (rx_busy, &dev->flags)) { 12468c2ecf20Sopenharmony_ci PRINTD (DBG_RX, "locked out of rx lock"); 12478c2ecf20Sopenharmony_ci return; 12488c2ecf20Sopenharmony_ci } 12498c2ecf20Sopenharmony_ci PRINTD (DBG_RX, "set rx_busy for dev %p", dev); 12508c2ecf20Sopenharmony_ci // lock is cleared if we fail now, o/w after bus master completion 12518c2ecf20Sopenharmony_ci 12528c2ecf20Sopenharmony_ci YELLOW_LED_OFF(dev); 12538c2ecf20Sopenharmony_ci 12548c2ecf20Sopenharmony_ci rx_queue_entry = rx_queue_entry_next (dev); 12558c2ecf20Sopenharmony_ci 12568c2ecf20Sopenharmony_ci rx_len = rx_q_entry_to_length (rx_queue_entry); 12578c2ecf20Sopenharmony_ci rx_channel = rx_q_entry_to_rx_channel (rx_queue_entry); 12588c2ecf20Sopenharmony_ci 12598c2ecf20Sopenharmony_ci WAIT_FLUSH_RX_COMPLETE (dev); 12608c2ecf20Sopenharmony_ci 12618c2ecf20Sopenharmony_ci SELECT_RX_CHANNEL (dev, rx_channel); 12628c2ecf20Sopenharmony_ci 12638c2ecf20Sopenharmony_ci PRINTD (DBG_RX, "rx_queue_entry is: %#x", rx_queue_entry); 12648c2ecf20Sopenharmony_ci rx_queue_entry_flags = rx_queue_entry & (RX_CRC_32_OK|RX_COMPLETE_FRAME|SIMONS_DODGEY_MARKER); 12658c2ecf20Sopenharmony_ci 12668c2ecf20Sopenharmony_ci if (!rx_len) { 12678c2ecf20Sopenharmony_ci // (at least) bus-mastering breaks if we try to handle a 12688c2ecf20Sopenharmony_ci // zero-length frame, besides AAL5 does not support them 12698c2ecf20Sopenharmony_ci PRINTK (KERN_ERR, "zero-length frame!"); 12708c2ecf20Sopenharmony_ci rx_queue_entry_flags &= ~RX_COMPLETE_FRAME; 12718c2ecf20Sopenharmony_ci } 12728c2ecf20Sopenharmony_ci 12738c2ecf20Sopenharmony_ci if (rx_queue_entry_flags & SIMONS_DODGEY_MARKER) { 12748c2ecf20Sopenharmony_ci PRINTD (DBG_RX|DBG_ERR, "Simon's marker detected!"); 12758c2ecf20Sopenharmony_ci } 12768c2ecf20Sopenharmony_ci if (rx_queue_entry_flags == (RX_CRC_32_OK | RX_COMPLETE_FRAME)) { 12778c2ecf20Sopenharmony_ci struct atm_vcc * atm_vcc; 12788c2ecf20Sopenharmony_ci 12798c2ecf20Sopenharmony_ci PRINTD (DBG_RX, "got a frame on rx_channel %x len %u", rx_channel, rx_len); 12808c2ecf20Sopenharmony_ci 12818c2ecf20Sopenharmony_ci atm_vcc = dev->rxer[rx_channel]; 12828c2ecf20Sopenharmony_ci // if no vcc is assigned to this channel, we should drop the frame 12838c2ecf20Sopenharmony_ci // (is this what SIMONS etc. was trying to achieve?) 12848c2ecf20Sopenharmony_ci 12858c2ecf20Sopenharmony_ci if (atm_vcc) { 12868c2ecf20Sopenharmony_ci 12878c2ecf20Sopenharmony_ci if (atm_vcc->qos.rxtp.traffic_class != ATM_NONE) { 12888c2ecf20Sopenharmony_ci 12898c2ecf20Sopenharmony_ci if (rx_len <= atm_vcc->qos.rxtp.max_sdu) { 12908c2ecf20Sopenharmony_ci 12918c2ecf20Sopenharmony_ci struct sk_buff * skb = atm_alloc_charge (atm_vcc, rx_len, GFP_ATOMIC); 12928c2ecf20Sopenharmony_ci if (skb) { 12938c2ecf20Sopenharmony_ci // remember this so we can push it later 12948c2ecf20Sopenharmony_ci dev->rx_skb = skb; 12958c2ecf20Sopenharmony_ci // remember this so we can flush it later 12968c2ecf20Sopenharmony_ci dev->rx_channel = rx_channel; 12978c2ecf20Sopenharmony_ci 12988c2ecf20Sopenharmony_ci // prepare socket buffer 12998c2ecf20Sopenharmony_ci skb_put (skb, rx_len); 13008c2ecf20Sopenharmony_ci ATM_SKB(skb)->vcc = atm_vcc; 13018c2ecf20Sopenharmony_ci 13028c2ecf20Sopenharmony_ci // simple transfer 13038c2ecf20Sopenharmony_ci // dev->rx_regions = 0; 13048c2ecf20Sopenharmony_ci // dev->rx_iovec = 0; 13058c2ecf20Sopenharmony_ci dev->rx_bytes = rx_len; 13068c2ecf20Sopenharmony_ci dev->rx_addr = skb->data; 13078c2ecf20Sopenharmony_ci PRINTD (DBG_RX, "RX start simple transfer (addr %p, len %d)", 13088c2ecf20Sopenharmony_ci skb->data, rx_len); 13098c2ecf20Sopenharmony_ci 13108c2ecf20Sopenharmony_ci // do the business 13118c2ecf20Sopenharmony_ci rx_schedule (dev, 0); 13128c2ecf20Sopenharmony_ci return; 13138c2ecf20Sopenharmony_ci 13148c2ecf20Sopenharmony_ci } else { 13158c2ecf20Sopenharmony_ci PRINTD (DBG_SKB|DBG_WARN, "failed to get skb"); 13168c2ecf20Sopenharmony_ci } 13178c2ecf20Sopenharmony_ci 13188c2ecf20Sopenharmony_ci } else { 13198c2ecf20Sopenharmony_ci PRINTK (KERN_INFO, "frame received on TX-only VC %x", rx_channel); 13208c2ecf20Sopenharmony_ci // do we count this? 13218c2ecf20Sopenharmony_ci } 13228c2ecf20Sopenharmony_ci 13238c2ecf20Sopenharmony_ci } else { 13248c2ecf20Sopenharmony_ci PRINTK (KERN_WARNING, "dropped over-size frame"); 13258c2ecf20Sopenharmony_ci // do we count this? 13268c2ecf20Sopenharmony_ci } 13278c2ecf20Sopenharmony_ci 13288c2ecf20Sopenharmony_ci } else { 13298c2ecf20Sopenharmony_ci PRINTD (DBG_WARN|DBG_VCC|DBG_RX, "no VCC for this frame (VC closed)"); 13308c2ecf20Sopenharmony_ci // do we count this? 13318c2ecf20Sopenharmony_ci } 13328c2ecf20Sopenharmony_ci 13338c2ecf20Sopenharmony_ci } else { 13348c2ecf20Sopenharmony_ci // Wait update complete ? SPONG 13358c2ecf20Sopenharmony_ci } 13368c2ecf20Sopenharmony_ci 13378c2ecf20Sopenharmony_ci // RX was aborted 13388c2ecf20Sopenharmony_ci YELLOW_LED_ON(dev); 13398c2ecf20Sopenharmony_ci 13408c2ecf20Sopenharmony_ci FLUSH_RX_CHANNEL (dev,rx_channel); 13418c2ecf20Sopenharmony_ci clear_bit (rx_busy, &dev->flags); 13428c2ecf20Sopenharmony_ci 13438c2ecf20Sopenharmony_ci return; 13448c2ecf20Sopenharmony_ci} 13458c2ecf20Sopenharmony_ci 13468c2ecf20Sopenharmony_ci/********** interrupt handler **********/ 13478c2ecf20Sopenharmony_ci 13488c2ecf20Sopenharmony_cistatic irqreturn_t interrupt_handler(int irq, void *dev_id) 13498c2ecf20Sopenharmony_ci{ 13508c2ecf20Sopenharmony_ci hrz_dev *dev = dev_id; 13518c2ecf20Sopenharmony_ci u32 int_source; 13528c2ecf20Sopenharmony_ci unsigned int irq_ok; 13538c2ecf20Sopenharmony_ci 13548c2ecf20Sopenharmony_ci PRINTD (DBG_FLOW, "interrupt_handler: %p", dev_id); 13558c2ecf20Sopenharmony_ci 13568c2ecf20Sopenharmony_ci // definitely for us 13578c2ecf20Sopenharmony_ci irq_ok = 0; 13588c2ecf20Sopenharmony_ci while ((int_source = rd_regl (dev, INT_SOURCE_REG_OFF) 13598c2ecf20Sopenharmony_ci & INTERESTING_INTERRUPTS)) { 13608c2ecf20Sopenharmony_ci // In the interests of fairness, the handlers below are 13618c2ecf20Sopenharmony_ci // called in sequence and without immediate return to the head of 13628c2ecf20Sopenharmony_ci // the while loop. This is only of issue for slow hosts (or when 13638c2ecf20Sopenharmony_ci // debugging messages are on). Really slow hosts may find a fast 13648c2ecf20Sopenharmony_ci // sender keeps them permanently in the IRQ handler. :( 13658c2ecf20Sopenharmony_ci 13668c2ecf20Sopenharmony_ci // (only an issue for slow hosts) RX completion goes before 13678c2ecf20Sopenharmony_ci // rx_data_av as the former implies rx_busy and so the latter 13688c2ecf20Sopenharmony_ci // would just abort. If it reschedules another transfer 13698c2ecf20Sopenharmony_ci // (continuing the same frame) then it will not clear rx_busy. 13708c2ecf20Sopenharmony_ci 13718c2ecf20Sopenharmony_ci // (only an issue for slow hosts) TX completion goes before RX 13728c2ecf20Sopenharmony_ci // data available as it is a much shorter routine - there is the 13738c2ecf20Sopenharmony_ci // chance that any further transfers it schedules will be complete 13748c2ecf20Sopenharmony_ci // by the time of the return to the head of the while loop 13758c2ecf20Sopenharmony_ci 13768c2ecf20Sopenharmony_ci if (int_source & RX_BUS_MASTER_COMPLETE) { 13778c2ecf20Sopenharmony_ci ++irq_ok; 13788c2ecf20Sopenharmony_ci PRINTD (DBG_IRQ|DBG_BUS|DBG_RX, "rx_bus_master_complete asserted"); 13798c2ecf20Sopenharmony_ci rx_bus_master_complete_handler (dev); 13808c2ecf20Sopenharmony_ci } 13818c2ecf20Sopenharmony_ci if (int_source & TX_BUS_MASTER_COMPLETE) { 13828c2ecf20Sopenharmony_ci ++irq_ok; 13838c2ecf20Sopenharmony_ci PRINTD (DBG_IRQ|DBG_BUS|DBG_TX, "tx_bus_master_complete asserted"); 13848c2ecf20Sopenharmony_ci tx_bus_master_complete_handler (dev); 13858c2ecf20Sopenharmony_ci } 13868c2ecf20Sopenharmony_ci if (int_source & RX_DATA_AV) { 13878c2ecf20Sopenharmony_ci ++irq_ok; 13888c2ecf20Sopenharmony_ci PRINTD (DBG_IRQ|DBG_RX, "rx_data_av asserted"); 13898c2ecf20Sopenharmony_ci rx_data_av_handler (dev); 13908c2ecf20Sopenharmony_ci } 13918c2ecf20Sopenharmony_ci } 13928c2ecf20Sopenharmony_ci if (irq_ok) { 13938c2ecf20Sopenharmony_ci PRINTD (DBG_IRQ, "work done: %u", irq_ok); 13948c2ecf20Sopenharmony_ci } else { 13958c2ecf20Sopenharmony_ci PRINTD (DBG_IRQ|DBG_WARN, "spurious interrupt source: %#x", int_source); 13968c2ecf20Sopenharmony_ci } 13978c2ecf20Sopenharmony_ci 13988c2ecf20Sopenharmony_ci PRINTD (DBG_IRQ|DBG_FLOW, "interrupt_handler done: %p", dev_id); 13998c2ecf20Sopenharmony_ci if (irq_ok) 14008c2ecf20Sopenharmony_ci return IRQ_HANDLED; 14018c2ecf20Sopenharmony_ci return IRQ_NONE; 14028c2ecf20Sopenharmony_ci} 14038c2ecf20Sopenharmony_ci 14048c2ecf20Sopenharmony_ci/********** housekeeping **********/ 14058c2ecf20Sopenharmony_ci 14068c2ecf20Sopenharmony_cistatic void do_housekeeping (struct timer_list *t) { 14078c2ecf20Sopenharmony_ci // just stats at the moment 14088c2ecf20Sopenharmony_ci hrz_dev * dev = from_timer(dev, t, housekeeping); 14098c2ecf20Sopenharmony_ci 14108c2ecf20Sopenharmony_ci // collect device-specific (not driver/atm-linux) stats here 14118c2ecf20Sopenharmony_ci dev->tx_cell_count += rd_regw (dev, TX_CELL_COUNT_OFF); 14128c2ecf20Sopenharmony_ci dev->rx_cell_count += rd_regw (dev, RX_CELL_COUNT_OFF); 14138c2ecf20Sopenharmony_ci dev->hec_error_count += rd_regw (dev, HEC_ERROR_COUNT_OFF); 14148c2ecf20Sopenharmony_ci dev->unassigned_cell_count += rd_regw (dev, UNASSIGNED_CELL_COUNT_OFF); 14158c2ecf20Sopenharmony_ci 14168c2ecf20Sopenharmony_ci mod_timer (&dev->housekeeping, jiffies + HZ/10); 14178c2ecf20Sopenharmony_ci 14188c2ecf20Sopenharmony_ci return; 14198c2ecf20Sopenharmony_ci} 14208c2ecf20Sopenharmony_ci 14218c2ecf20Sopenharmony_ci/********** find an idle channel for TX and set it up **********/ 14228c2ecf20Sopenharmony_ci 14238c2ecf20Sopenharmony_ci// called with tx_busy set 14248c2ecf20Sopenharmony_cistatic short setup_idle_tx_channel (hrz_dev * dev, hrz_vcc * vcc) { 14258c2ecf20Sopenharmony_ci unsigned short idle_channels; 14268c2ecf20Sopenharmony_ci short tx_channel = -1; 14278c2ecf20Sopenharmony_ci unsigned int spin_count; 14288c2ecf20Sopenharmony_ci PRINTD (DBG_FLOW|DBG_TX, "setup_idle_tx_channel %p", dev); 14298c2ecf20Sopenharmony_ci 14308c2ecf20Sopenharmony_ci // better would be to fail immediately, the caller can then decide whether 14318c2ecf20Sopenharmony_ci // to wait or drop (depending on whether this is UBR etc.) 14328c2ecf20Sopenharmony_ci spin_count = 0; 14338c2ecf20Sopenharmony_ci while (!(idle_channels = rd_regw (dev, TX_STATUS_OFF) & IDLE_CHANNELS_MASK)) { 14348c2ecf20Sopenharmony_ci PRINTD (DBG_TX|DBG_WARN, "waiting for idle TX channel"); 14358c2ecf20Sopenharmony_ci // delay a bit here 14368c2ecf20Sopenharmony_ci if (++spin_count > 100) { 14378c2ecf20Sopenharmony_ci PRINTD (DBG_TX|DBG_ERR, "spun out waiting for idle TX channel"); 14388c2ecf20Sopenharmony_ci return -EBUSY; 14398c2ecf20Sopenharmony_ci } 14408c2ecf20Sopenharmony_ci } 14418c2ecf20Sopenharmony_ci 14428c2ecf20Sopenharmony_ci // got an idle channel 14438c2ecf20Sopenharmony_ci { 14448c2ecf20Sopenharmony_ci // tx_idle ensures we look for idle channels in RR order 14458c2ecf20Sopenharmony_ci int chan = dev->tx_idle; 14468c2ecf20Sopenharmony_ci 14478c2ecf20Sopenharmony_ci int keep_going = 1; 14488c2ecf20Sopenharmony_ci while (keep_going) { 14498c2ecf20Sopenharmony_ci if (idle_channels & (1<<chan)) { 14508c2ecf20Sopenharmony_ci tx_channel = chan; 14518c2ecf20Sopenharmony_ci keep_going = 0; 14528c2ecf20Sopenharmony_ci } 14538c2ecf20Sopenharmony_ci ++chan; 14548c2ecf20Sopenharmony_ci if (chan == TX_CHANS) 14558c2ecf20Sopenharmony_ci chan = 0; 14568c2ecf20Sopenharmony_ci } 14578c2ecf20Sopenharmony_ci 14588c2ecf20Sopenharmony_ci dev->tx_idle = chan; 14598c2ecf20Sopenharmony_ci } 14608c2ecf20Sopenharmony_ci 14618c2ecf20Sopenharmony_ci // set up the channel we found 14628c2ecf20Sopenharmony_ci { 14638c2ecf20Sopenharmony_ci // Initialise the cell header in the transmit channel descriptor 14648c2ecf20Sopenharmony_ci // a.k.a. prepare the channel and remember that we have done so. 14658c2ecf20Sopenharmony_ci 14668c2ecf20Sopenharmony_ci tx_ch_desc * tx_desc = &memmap->tx_descs[tx_channel]; 14678c2ecf20Sopenharmony_ci u32 rd_ptr; 14688c2ecf20Sopenharmony_ci u32 wr_ptr; 14698c2ecf20Sopenharmony_ci u16 channel = vcc->channel; 14708c2ecf20Sopenharmony_ci 14718c2ecf20Sopenharmony_ci unsigned long flags; 14728c2ecf20Sopenharmony_ci spin_lock_irqsave (&dev->mem_lock, flags); 14738c2ecf20Sopenharmony_ci 14748c2ecf20Sopenharmony_ci // Update the transmit channel record. 14758c2ecf20Sopenharmony_ci dev->tx_channel_record[tx_channel] = channel; 14768c2ecf20Sopenharmony_ci 14778c2ecf20Sopenharmony_ci // xBR channel 14788c2ecf20Sopenharmony_ci update_tx_channel_config (dev, tx_channel, RATE_TYPE_ACCESS, 14798c2ecf20Sopenharmony_ci vcc->tx_xbr_bits); 14808c2ecf20Sopenharmony_ci 14818c2ecf20Sopenharmony_ci // Update the PCR counter preload value etc. 14828c2ecf20Sopenharmony_ci update_tx_channel_config (dev, tx_channel, PCR_TIMER_ACCESS, 14838c2ecf20Sopenharmony_ci vcc->tx_pcr_bits); 14848c2ecf20Sopenharmony_ci 14858c2ecf20Sopenharmony_ci#if 0 14868c2ecf20Sopenharmony_ci if (vcc->tx_xbr_bits == VBR_RATE_TYPE) { 14878c2ecf20Sopenharmony_ci // SCR timer 14888c2ecf20Sopenharmony_ci update_tx_channel_config (dev, tx_channel, SCR_TIMER_ACCESS, 14898c2ecf20Sopenharmony_ci vcc->tx_scr_bits); 14908c2ecf20Sopenharmony_ci 14918c2ecf20Sopenharmony_ci // Bucket size... 14928c2ecf20Sopenharmony_ci update_tx_channel_config (dev, tx_channel, BUCKET_CAPACITY_ACCESS, 14938c2ecf20Sopenharmony_ci vcc->tx_bucket_bits); 14948c2ecf20Sopenharmony_ci 14958c2ecf20Sopenharmony_ci // ... and fullness 14968c2ecf20Sopenharmony_ci update_tx_channel_config (dev, tx_channel, BUCKET_FULLNESS_ACCESS, 14978c2ecf20Sopenharmony_ci vcc->tx_bucket_bits); 14988c2ecf20Sopenharmony_ci } 14998c2ecf20Sopenharmony_ci#endif 15008c2ecf20Sopenharmony_ci 15018c2ecf20Sopenharmony_ci // Initialise the read and write buffer pointers 15028c2ecf20Sopenharmony_ci rd_ptr = rd_mem (dev, &tx_desc->rd_buf_type) & BUFFER_PTR_MASK; 15038c2ecf20Sopenharmony_ci wr_ptr = rd_mem (dev, &tx_desc->wr_buf_type) & BUFFER_PTR_MASK; 15048c2ecf20Sopenharmony_ci 15058c2ecf20Sopenharmony_ci // idle TX channels should have identical pointers 15068c2ecf20Sopenharmony_ci if (rd_ptr != wr_ptr) { 15078c2ecf20Sopenharmony_ci PRINTD (DBG_TX|DBG_ERR, "TX buffer pointers are broken!"); 15088c2ecf20Sopenharmony_ci // spin_unlock... return -E... 15098c2ecf20Sopenharmony_ci // I wonder if gcc would get rid of one of the pointer aliases 15108c2ecf20Sopenharmony_ci } 15118c2ecf20Sopenharmony_ci PRINTD (DBG_TX, "TX buffer pointers are: rd %x, wr %x.", 15128c2ecf20Sopenharmony_ci rd_ptr, wr_ptr); 15138c2ecf20Sopenharmony_ci 15148c2ecf20Sopenharmony_ci switch (vcc->aal) { 15158c2ecf20Sopenharmony_ci case aal0: 15168c2ecf20Sopenharmony_ci PRINTD (DBG_QOS|DBG_TX, "tx_channel: aal0"); 15178c2ecf20Sopenharmony_ci rd_ptr |= CHANNEL_TYPE_RAW_CELLS; 15188c2ecf20Sopenharmony_ci wr_ptr |= CHANNEL_TYPE_RAW_CELLS; 15198c2ecf20Sopenharmony_ci break; 15208c2ecf20Sopenharmony_ci case aal34: 15218c2ecf20Sopenharmony_ci PRINTD (DBG_QOS|DBG_TX, "tx_channel: aal34"); 15228c2ecf20Sopenharmony_ci rd_ptr |= CHANNEL_TYPE_AAL3_4; 15238c2ecf20Sopenharmony_ci wr_ptr |= CHANNEL_TYPE_AAL3_4; 15248c2ecf20Sopenharmony_ci break; 15258c2ecf20Sopenharmony_ci case aal5: 15268c2ecf20Sopenharmony_ci rd_ptr |= CHANNEL_TYPE_AAL5; 15278c2ecf20Sopenharmony_ci wr_ptr |= CHANNEL_TYPE_AAL5; 15288c2ecf20Sopenharmony_ci // Initialise the CRC 15298c2ecf20Sopenharmony_ci wr_mem (dev, &tx_desc->partial_crc, INITIAL_CRC); 15308c2ecf20Sopenharmony_ci break; 15318c2ecf20Sopenharmony_ci } 15328c2ecf20Sopenharmony_ci 15338c2ecf20Sopenharmony_ci wr_mem (dev, &tx_desc->rd_buf_type, rd_ptr); 15348c2ecf20Sopenharmony_ci wr_mem (dev, &tx_desc->wr_buf_type, wr_ptr); 15358c2ecf20Sopenharmony_ci 15368c2ecf20Sopenharmony_ci // Write the Cell Header 15378c2ecf20Sopenharmony_ci // Payload Type, CLP and GFC would go here if non-zero 15388c2ecf20Sopenharmony_ci wr_mem (dev, &tx_desc->cell_header, channel); 15398c2ecf20Sopenharmony_ci 15408c2ecf20Sopenharmony_ci spin_unlock_irqrestore (&dev->mem_lock, flags); 15418c2ecf20Sopenharmony_ci } 15428c2ecf20Sopenharmony_ci 15438c2ecf20Sopenharmony_ci return tx_channel; 15448c2ecf20Sopenharmony_ci} 15458c2ecf20Sopenharmony_ci 15468c2ecf20Sopenharmony_ci/********** send a frame **********/ 15478c2ecf20Sopenharmony_ci 15488c2ecf20Sopenharmony_cistatic int hrz_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) { 15498c2ecf20Sopenharmony_ci unsigned int spin_count; 15508c2ecf20Sopenharmony_ci int free_buffers; 15518c2ecf20Sopenharmony_ci hrz_dev * dev = HRZ_DEV(atm_vcc->dev); 15528c2ecf20Sopenharmony_ci hrz_vcc * vcc = HRZ_VCC(atm_vcc); 15538c2ecf20Sopenharmony_ci u16 channel = vcc->channel; 15548c2ecf20Sopenharmony_ci 15558c2ecf20Sopenharmony_ci u32 buffers_required; 15568c2ecf20Sopenharmony_ci 15578c2ecf20Sopenharmony_ci /* signed for error return */ 15588c2ecf20Sopenharmony_ci short tx_channel; 15598c2ecf20Sopenharmony_ci 15608c2ecf20Sopenharmony_ci PRINTD (DBG_FLOW|DBG_TX, "hrz_send vc %x data %p len %u", 15618c2ecf20Sopenharmony_ci channel, skb->data, skb->len); 15628c2ecf20Sopenharmony_ci 15638c2ecf20Sopenharmony_ci dump_skb (">>>", channel, skb); 15648c2ecf20Sopenharmony_ci 15658c2ecf20Sopenharmony_ci if (atm_vcc->qos.txtp.traffic_class == ATM_NONE) { 15668c2ecf20Sopenharmony_ci PRINTK (KERN_ERR, "attempt to send on RX-only VC %x", channel); 15678c2ecf20Sopenharmony_ci hrz_kfree_skb (skb); 15688c2ecf20Sopenharmony_ci return -EIO; 15698c2ecf20Sopenharmony_ci } 15708c2ecf20Sopenharmony_ci 15718c2ecf20Sopenharmony_ci // don't understand this 15728c2ecf20Sopenharmony_ci ATM_SKB(skb)->vcc = atm_vcc; 15738c2ecf20Sopenharmony_ci 15748c2ecf20Sopenharmony_ci if (skb->len > atm_vcc->qos.txtp.max_sdu) { 15758c2ecf20Sopenharmony_ci PRINTK (KERN_ERR, "sk_buff length greater than agreed max_sdu, dropping..."); 15768c2ecf20Sopenharmony_ci hrz_kfree_skb (skb); 15778c2ecf20Sopenharmony_ci return -EIO; 15788c2ecf20Sopenharmony_ci } 15798c2ecf20Sopenharmony_ci 15808c2ecf20Sopenharmony_ci if (!channel) { 15818c2ecf20Sopenharmony_ci PRINTD (DBG_ERR|DBG_TX, "attempt to transmit on zero (rx_)channel"); 15828c2ecf20Sopenharmony_ci hrz_kfree_skb (skb); 15838c2ecf20Sopenharmony_ci return -EIO; 15848c2ecf20Sopenharmony_ci } 15858c2ecf20Sopenharmony_ci 15868c2ecf20Sopenharmony_ci#if 0 15878c2ecf20Sopenharmony_ci { 15888c2ecf20Sopenharmony_ci // where would be a better place for this? housekeeping? 15898c2ecf20Sopenharmony_ci u16 status; 15908c2ecf20Sopenharmony_ci pci_read_config_word (dev->pci_dev, PCI_STATUS, &status); 15918c2ecf20Sopenharmony_ci if (status & PCI_STATUS_REC_MASTER_ABORT) { 15928c2ecf20Sopenharmony_ci PRINTD (DBG_BUS|DBG_ERR, "Clearing PCI Master Abort (and cleaning up)"); 15938c2ecf20Sopenharmony_ci status &= ~PCI_STATUS_REC_MASTER_ABORT; 15948c2ecf20Sopenharmony_ci pci_write_config_word (dev->pci_dev, PCI_STATUS, status); 15958c2ecf20Sopenharmony_ci if (test_bit (tx_busy, &dev->flags)) { 15968c2ecf20Sopenharmony_ci hrz_kfree_skb (dev->tx_skb); 15978c2ecf20Sopenharmony_ci tx_release (dev); 15988c2ecf20Sopenharmony_ci } 15998c2ecf20Sopenharmony_ci } 16008c2ecf20Sopenharmony_ci } 16018c2ecf20Sopenharmony_ci#endif 16028c2ecf20Sopenharmony_ci 16038c2ecf20Sopenharmony_ci#ifdef DEBUG_HORIZON 16048c2ecf20Sopenharmony_ci /* wey-hey! */ 16058c2ecf20Sopenharmony_ci if (channel == 1023) { 16068c2ecf20Sopenharmony_ci unsigned int i; 16078c2ecf20Sopenharmony_ci unsigned short d = 0; 16088c2ecf20Sopenharmony_ci char * s = skb->data; 16098c2ecf20Sopenharmony_ci if (*s++ == 'D') { 16108c2ecf20Sopenharmony_ci for (i = 0; i < 4; ++i) 16118c2ecf20Sopenharmony_ci d = (d << 4) | hex_to_bin(*s++); 16128c2ecf20Sopenharmony_ci PRINTK (KERN_INFO, "debug bitmap is now %hx", debug = d); 16138c2ecf20Sopenharmony_ci } 16148c2ecf20Sopenharmony_ci } 16158c2ecf20Sopenharmony_ci#endif 16168c2ecf20Sopenharmony_ci 16178c2ecf20Sopenharmony_ci // wait until TX is free and grab lock 16188c2ecf20Sopenharmony_ci if (tx_hold (dev)) { 16198c2ecf20Sopenharmony_ci hrz_kfree_skb (skb); 16208c2ecf20Sopenharmony_ci return -ERESTARTSYS; 16218c2ecf20Sopenharmony_ci } 16228c2ecf20Sopenharmony_ci 16238c2ecf20Sopenharmony_ci // Wait for enough space to be available in transmit buffer memory. 16248c2ecf20Sopenharmony_ci 16258c2ecf20Sopenharmony_ci // should be number of cells needed + 2 (according to hardware docs) 16268c2ecf20Sopenharmony_ci // = ((framelen+8)+47) / 48 + 2 16278c2ecf20Sopenharmony_ci // = (framelen+7) / 48 + 3, hmm... faster to put addition inside XXX 16288c2ecf20Sopenharmony_ci buffers_required = (skb->len+(ATM_AAL5_TRAILER-1)) / ATM_CELL_PAYLOAD + 3; 16298c2ecf20Sopenharmony_ci 16308c2ecf20Sopenharmony_ci // replace with timer and sleep, add dev->tx_buffers_queue (max 1 entry) 16318c2ecf20Sopenharmony_ci spin_count = 0; 16328c2ecf20Sopenharmony_ci while ((free_buffers = rd_regw (dev, TX_FREE_BUFFER_COUNT_OFF)) < buffers_required) { 16338c2ecf20Sopenharmony_ci PRINTD (DBG_TX, "waiting for free TX buffers, got %d of %d", 16348c2ecf20Sopenharmony_ci free_buffers, buffers_required); 16358c2ecf20Sopenharmony_ci // what is the appropriate delay? implement a timeout? (depending on line speed?) 16368c2ecf20Sopenharmony_ci // mdelay (1); 16378c2ecf20Sopenharmony_ci // what happens if we kill (current_pid, SIGKILL) ? 16388c2ecf20Sopenharmony_ci schedule(); 16398c2ecf20Sopenharmony_ci if (++spin_count > 1000) { 16408c2ecf20Sopenharmony_ci PRINTD (DBG_TX|DBG_ERR, "spun out waiting for tx buffers, got %d of %d", 16418c2ecf20Sopenharmony_ci free_buffers, buffers_required); 16428c2ecf20Sopenharmony_ci tx_release (dev); 16438c2ecf20Sopenharmony_ci hrz_kfree_skb (skb); 16448c2ecf20Sopenharmony_ci return -ERESTARTSYS; 16458c2ecf20Sopenharmony_ci } 16468c2ecf20Sopenharmony_ci } 16478c2ecf20Sopenharmony_ci 16488c2ecf20Sopenharmony_ci // Select a channel to transmit the frame on. 16498c2ecf20Sopenharmony_ci if (channel == dev->last_vc) { 16508c2ecf20Sopenharmony_ci PRINTD (DBG_TX, "last vc hack: hit"); 16518c2ecf20Sopenharmony_ci tx_channel = dev->tx_last; 16528c2ecf20Sopenharmony_ci } else { 16538c2ecf20Sopenharmony_ci PRINTD (DBG_TX, "last vc hack: miss"); 16548c2ecf20Sopenharmony_ci // Are we currently transmitting this VC on one of the channels? 16558c2ecf20Sopenharmony_ci for (tx_channel = 0; tx_channel < TX_CHANS; ++tx_channel) 16568c2ecf20Sopenharmony_ci if (dev->tx_channel_record[tx_channel] == channel) { 16578c2ecf20Sopenharmony_ci PRINTD (DBG_TX, "vc already on channel: hit"); 16588c2ecf20Sopenharmony_ci break; 16598c2ecf20Sopenharmony_ci } 16608c2ecf20Sopenharmony_ci if (tx_channel == TX_CHANS) { 16618c2ecf20Sopenharmony_ci PRINTD (DBG_TX, "vc already on channel: miss"); 16628c2ecf20Sopenharmony_ci // Find and set up an idle channel. 16638c2ecf20Sopenharmony_ci tx_channel = setup_idle_tx_channel (dev, vcc); 16648c2ecf20Sopenharmony_ci if (tx_channel < 0) { 16658c2ecf20Sopenharmony_ci PRINTD (DBG_TX|DBG_ERR, "failed to get channel"); 16668c2ecf20Sopenharmony_ci tx_release (dev); 16678c2ecf20Sopenharmony_ci return tx_channel; 16688c2ecf20Sopenharmony_ci } 16698c2ecf20Sopenharmony_ci } 16708c2ecf20Sopenharmony_ci 16718c2ecf20Sopenharmony_ci PRINTD (DBG_TX, "got channel"); 16728c2ecf20Sopenharmony_ci SELECT_TX_CHANNEL(dev, tx_channel); 16738c2ecf20Sopenharmony_ci 16748c2ecf20Sopenharmony_ci dev->last_vc = channel; 16758c2ecf20Sopenharmony_ci dev->tx_last = tx_channel; 16768c2ecf20Sopenharmony_ci } 16778c2ecf20Sopenharmony_ci 16788c2ecf20Sopenharmony_ci PRINTD (DBG_TX, "using channel %u", tx_channel); 16798c2ecf20Sopenharmony_ci 16808c2ecf20Sopenharmony_ci YELLOW_LED_OFF(dev); 16818c2ecf20Sopenharmony_ci 16828c2ecf20Sopenharmony_ci // TX start transfer 16838c2ecf20Sopenharmony_ci 16848c2ecf20Sopenharmony_ci { 16858c2ecf20Sopenharmony_ci unsigned int tx_len = skb->len; 16868c2ecf20Sopenharmony_ci unsigned int tx_iovcnt = skb_shinfo(skb)->nr_frags; 16878c2ecf20Sopenharmony_ci // remember this so we can free it later 16888c2ecf20Sopenharmony_ci dev->tx_skb = skb; 16898c2ecf20Sopenharmony_ci 16908c2ecf20Sopenharmony_ci if (tx_iovcnt) { 16918c2ecf20Sopenharmony_ci // scatter gather transfer 16928c2ecf20Sopenharmony_ci dev->tx_regions = tx_iovcnt; 16938c2ecf20Sopenharmony_ci dev->tx_iovec = NULL; /* @@@ needs rewritten */ 16948c2ecf20Sopenharmony_ci dev->tx_bytes = 0; 16958c2ecf20Sopenharmony_ci PRINTD (DBG_TX|DBG_BUS, "TX start scatter-gather transfer (iovec %p, len %d)", 16968c2ecf20Sopenharmony_ci skb->data, tx_len); 16978c2ecf20Sopenharmony_ci tx_release (dev); 16988c2ecf20Sopenharmony_ci hrz_kfree_skb (skb); 16998c2ecf20Sopenharmony_ci return -EIO; 17008c2ecf20Sopenharmony_ci } else { 17018c2ecf20Sopenharmony_ci // simple transfer 17028c2ecf20Sopenharmony_ci dev->tx_regions = 0; 17038c2ecf20Sopenharmony_ci dev->tx_iovec = NULL; 17048c2ecf20Sopenharmony_ci dev->tx_bytes = tx_len; 17058c2ecf20Sopenharmony_ci dev->tx_addr = skb->data; 17068c2ecf20Sopenharmony_ci PRINTD (DBG_TX|DBG_BUS, "TX start simple transfer (addr %p, len %d)", 17078c2ecf20Sopenharmony_ci skb->data, tx_len); 17088c2ecf20Sopenharmony_ci } 17098c2ecf20Sopenharmony_ci 17108c2ecf20Sopenharmony_ci // and do the business 17118c2ecf20Sopenharmony_ci tx_schedule (dev, 0); 17128c2ecf20Sopenharmony_ci 17138c2ecf20Sopenharmony_ci } 17148c2ecf20Sopenharmony_ci 17158c2ecf20Sopenharmony_ci return 0; 17168c2ecf20Sopenharmony_ci} 17178c2ecf20Sopenharmony_ci 17188c2ecf20Sopenharmony_ci/********** reset a card **********/ 17198c2ecf20Sopenharmony_ci 17208c2ecf20Sopenharmony_cistatic void hrz_reset (const hrz_dev * dev) { 17218c2ecf20Sopenharmony_ci u32 control_0_reg = rd_regl (dev, CONTROL_0_REG); 17228c2ecf20Sopenharmony_ci 17238c2ecf20Sopenharmony_ci // why not set RESET_HORIZON to one and wait for the card to 17248c2ecf20Sopenharmony_ci // reassert that bit as zero? Like so: 17258c2ecf20Sopenharmony_ci control_0_reg = control_0_reg & RESET_HORIZON; 17268c2ecf20Sopenharmony_ci wr_regl (dev, CONTROL_0_REG, control_0_reg); 17278c2ecf20Sopenharmony_ci while (control_0_reg & RESET_HORIZON) 17288c2ecf20Sopenharmony_ci control_0_reg = rd_regl (dev, CONTROL_0_REG); 17298c2ecf20Sopenharmony_ci 17308c2ecf20Sopenharmony_ci // old reset code retained: 17318c2ecf20Sopenharmony_ci wr_regl (dev, CONTROL_0_REG, control_0_reg | 17328c2ecf20Sopenharmony_ci RESET_ATM | RESET_RX | RESET_TX | RESET_HOST); 17338c2ecf20Sopenharmony_ci // just guessing here 17348c2ecf20Sopenharmony_ci udelay (1000); 17358c2ecf20Sopenharmony_ci 17368c2ecf20Sopenharmony_ci wr_regl (dev, CONTROL_0_REG, control_0_reg); 17378c2ecf20Sopenharmony_ci} 17388c2ecf20Sopenharmony_ci 17398c2ecf20Sopenharmony_ci/********** read the burnt in address **********/ 17408c2ecf20Sopenharmony_ci 17418c2ecf20Sopenharmony_cistatic void WRITE_IT_WAIT (const hrz_dev *dev, u32 ctrl) 17428c2ecf20Sopenharmony_ci{ 17438c2ecf20Sopenharmony_ci wr_regl (dev, CONTROL_0_REG, ctrl); 17448c2ecf20Sopenharmony_ci udelay (5); 17458c2ecf20Sopenharmony_ci} 17468c2ecf20Sopenharmony_ci 17478c2ecf20Sopenharmony_cistatic void CLOCK_IT (const hrz_dev *dev, u32 ctrl) 17488c2ecf20Sopenharmony_ci{ 17498c2ecf20Sopenharmony_ci // DI must be valid around rising SK edge 17508c2ecf20Sopenharmony_ci WRITE_IT_WAIT(dev, ctrl & ~SEEPROM_SK); 17518c2ecf20Sopenharmony_ci WRITE_IT_WAIT(dev, ctrl | SEEPROM_SK); 17528c2ecf20Sopenharmony_ci} 17538c2ecf20Sopenharmony_ci 17548c2ecf20Sopenharmony_cistatic u16 read_bia(const hrz_dev *dev, u16 addr) 17558c2ecf20Sopenharmony_ci{ 17568c2ecf20Sopenharmony_ci u32 ctrl = rd_regl (dev, CONTROL_0_REG); 17578c2ecf20Sopenharmony_ci 17588c2ecf20Sopenharmony_ci const unsigned int addr_bits = 6; 17598c2ecf20Sopenharmony_ci const unsigned int data_bits = 16; 17608c2ecf20Sopenharmony_ci 17618c2ecf20Sopenharmony_ci unsigned int i; 17628c2ecf20Sopenharmony_ci 17638c2ecf20Sopenharmony_ci u16 res; 17648c2ecf20Sopenharmony_ci 17658c2ecf20Sopenharmony_ci ctrl &= ~(SEEPROM_CS | SEEPROM_SK | SEEPROM_DI); 17668c2ecf20Sopenharmony_ci WRITE_IT_WAIT(dev, ctrl); 17678c2ecf20Sopenharmony_ci 17688c2ecf20Sopenharmony_ci // wake Serial EEPROM and send 110 (READ) command 17698c2ecf20Sopenharmony_ci ctrl |= (SEEPROM_CS | SEEPROM_DI); 17708c2ecf20Sopenharmony_ci CLOCK_IT(dev, ctrl); 17718c2ecf20Sopenharmony_ci 17728c2ecf20Sopenharmony_ci ctrl |= SEEPROM_DI; 17738c2ecf20Sopenharmony_ci CLOCK_IT(dev, ctrl); 17748c2ecf20Sopenharmony_ci 17758c2ecf20Sopenharmony_ci ctrl &= ~SEEPROM_DI; 17768c2ecf20Sopenharmony_ci CLOCK_IT(dev, ctrl); 17778c2ecf20Sopenharmony_ci 17788c2ecf20Sopenharmony_ci for (i=0; i<addr_bits; i++) { 17798c2ecf20Sopenharmony_ci if (addr & (1 << (addr_bits-1))) 17808c2ecf20Sopenharmony_ci ctrl |= SEEPROM_DI; 17818c2ecf20Sopenharmony_ci else 17828c2ecf20Sopenharmony_ci ctrl &= ~SEEPROM_DI; 17838c2ecf20Sopenharmony_ci 17848c2ecf20Sopenharmony_ci CLOCK_IT(dev, ctrl); 17858c2ecf20Sopenharmony_ci 17868c2ecf20Sopenharmony_ci addr = addr << 1; 17878c2ecf20Sopenharmony_ci } 17888c2ecf20Sopenharmony_ci 17898c2ecf20Sopenharmony_ci // we could check that we have DO = 0 here 17908c2ecf20Sopenharmony_ci ctrl &= ~SEEPROM_DI; 17918c2ecf20Sopenharmony_ci 17928c2ecf20Sopenharmony_ci res = 0; 17938c2ecf20Sopenharmony_ci for (i=0;i<data_bits;i++) { 17948c2ecf20Sopenharmony_ci res = res >> 1; 17958c2ecf20Sopenharmony_ci 17968c2ecf20Sopenharmony_ci CLOCK_IT(dev, ctrl); 17978c2ecf20Sopenharmony_ci 17988c2ecf20Sopenharmony_ci if (rd_regl (dev, CONTROL_0_REG) & SEEPROM_DO) 17998c2ecf20Sopenharmony_ci res |= (1 << (data_bits-1)); 18008c2ecf20Sopenharmony_ci } 18018c2ecf20Sopenharmony_ci 18028c2ecf20Sopenharmony_ci ctrl &= ~(SEEPROM_SK | SEEPROM_CS); 18038c2ecf20Sopenharmony_ci WRITE_IT_WAIT(dev, ctrl); 18048c2ecf20Sopenharmony_ci 18058c2ecf20Sopenharmony_ci return res; 18068c2ecf20Sopenharmony_ci} 18078c2ecf20Sopenharmony_ci 18088c2ecf20Sopenharmony_ci/********** initialise a card **********/ 18098c2ecf20Sopenharmony_ci 18108c2ecf20Sopenharmony_cistatic int hrz_init(hrz_dev *dev) 18118c2ecf20Sopenharmony_ci{ 18128c2ecf20Sopenharmony_ci int onefivefive; 18138c2ecf20Sopenharmony_ci 18148c2ecf20Sopenharmony_ci u16 chan; 18158c2ecf20Sopenharmony_ci 18168c2ecf20Sopenharmony_ci int buff_count; 18178c2ecf20Sopenharmony_ci 18188c2ecf20Sopenharmony_ci HDW * mem; 18198c2ecf20Sopenharmony_ci 18208c2ecf20Sopenharmony_ci cell_buf * tx_desc; 18218c2ecf20Sopenharmony_ci cell_buf * rx_desc; 18228c2ecf20Sopenharmony_ci 18238c2ecf20Sopenharmony_ci u32 ctrl; 18248c2ecf20Sopenharmony_ci 18258c2ecf20Sopenharmony_ci ctrl = rd_regl (dev, CONTROL_0_REG); 18268c2ecf20Sopenharmony_ci PRINTD (DBG_INFO, "ctrl0reg is %#x", ctrl); 18278c2ecf20Sopenharmony_ci onefivefive = ctrl & ATM_LAYER_STATUS; 18288c2ecf20Sopenharmony_ci 18298c2ecf20Sopenharmony_ci if (onefivefive) 18308c2ecf20Sopenharmony_ci printk (DEV_LABEL ": Horizon Ultra (at 155.52 MBps)"); 18318c2ecf20Sopenharmony_ci else 18328c2ecf20Sopenharmony_ci printk (DEV_LABEL ": Horizon (at 25 MBps)"); 18338c2ecf20Sopenharmony_ci 18348c2ecf20Sopenharmony_ci printk (":"); 18358c2ecf20Sopenharmony_ci // Reset the card to get everything in a known state 18368c2ecf20Sopenharmony_ci 18378c2ecf20Sopenharmony_ci printk (" reset"); 18388c2ecf20Sopenharmony_ci hrz_reset (dev); 18398c2ecf20Sopenharmony_ci 18408c2ecf20Sopenharmony_ci // Clear all the buffer memory 18418c2ecf20Sopenharmony_ci 18428c2ecf20Sopenharmony_ci printk (" clearing memory"); 18438c2ecf20Sopenharmony_ci 18448c2ecf20Sopenharmony_ci for (mem = (HDW *) memmap; mem < (HDW *) (memmap + 1); ++mem) 18458c2ecf20Sopenharmony_ci wr_mem (dev, mem, 0); 18468c2ecf20Sopenharmony_ci 18478c2ecf20Sopenharmony_ci printk (" tx channels"); 18488c2ecf20Sopenharmony_ci 18498c2ecf20Sopenharmony_ci // All transmit eight channels are set up as AAL5 ABR channels with 18508c2ecf20Sopenharmony_ci // a 16us cell spacing. Why? 18518c2ecf20Sopenharmony_ci 18528c2ecf20Sopenharmony_ci // Channel 0 gets the free buffer at 100h, channel 1 gets the free 18538c2ecf20Sopenharmony_ci // buffer at 110h etc. 18548c2ecf20Sopenharmony_ci 18558c2ecf20Sopenharmony_ci for (chan = 0; chan < TX_CHANS; ++chan) { 18568c2ecf20Sopenharmony_ci tx_ch_desc * tx_desc = &memmap->tx_descs[chan]; 18578c2ecf20Sopenharmony_ci cell_buf * buf = &memmap->inittxbufs[chan]; 18588c2ecf20Sopenharmony_ci 18598c2ecf20Sopenharmony_ci // initialise the read and write buffer pointers 18608c2ecf20Sopenharmony_ci wr_mem (dev, &tx_desc->rd_buf_type, BUF_PTR(buf)); 18618c2ecf20Sopenharmony_ci wr_mem (dev, &tx_desc->wr_buf_type, BUF_PTR(buf)); 18628c2ecf20Sopenharmony_ci 18638c2ecf20Sopenharmony_ci // set the status of the initial buffers to empty 18648c2ecf20Sopenharmony_ci wr_mem (dev, &buf->next, BUFF_STATUS_EMPTY); 18658c2ecf20Sopenharmony_ci } 18668c2ecf20Sopenharmony_ci 18678c2ecf20Sopenharmony_ci // Use space bufn3 at the moment for tx buffers 18688c2ecf20Sopenharmony_ci 18698c2ecf20Sopenharmony_ci printk (" tx buffers"); 18708c2ecf20Sopenharmony_ci 18718c2ecf20Sopenharmony_ci tx_desc = memmap->bufn3; 18728c2ecf20Sopenharmony_ci 18738c2ecf20Sopenharmony_ci wr_mem (dev, &memmap->txfreebufstart.next, BUF_PTR(tx_desc) | BUFF_STATUS_EMPTY); 18748c2ecf20Sopenharmony_ci 18758c2ecf20Sopenharmony_ci for (buff_count = 0; buff_count < BUFN3_SIZE-1; buff_count++) { 18768c2ecf20Sopenharmony_ci wr_mem (dev, &tx_desc->next, BUF_PTR(tx_desc+1) | BUFF_STATUS_EMPTY); 18778c2ecf20Sopenharmony_ci tx_desc++; 18788c2ecf20Sopenharmony_ci } 18798c2ecf20Sopenharmony_ci 18808c2ecf20Sopenharmony_ci wr_mem (dev, &tx_desc->next, BUF_PTR(&memmap->txfreebufend) | BUFF_STATUS_EMPTY); 18818c2ecf20Sopenharmony_ci 18828c2ecf20Sopenharmony_ci // Initialise the transmit free buffer count 18838c2ecf20Sopenharmony_ci wr_regw (dev, TX_FREE_BUFFER_COUNT_OFF, BUFN3_SIZE); 18848c2ecf20Sopenharmony_ci 18858c2ecf20Sopenharmony_ci printk (" rx channels"); 18868c2ecf20Sopenharmony_ci 18878c2ecf20Sopenharmony_ci // Initialise all of the receive channels to be AAL5 disabled with 18888c2ecf20Sopenharmony_ci // an interrupt threshold of 0 18898c2ecf20Sopenharmony_ci 18908c2ecf20Sopenharmony_ci for (chan = 0; chan < RX_CHANS; ++chan) { 18918c2ecf20Sopenharmony_ci rx_ch_desc * rx_desc = &memmap->rx_descs[chan]; 18928c2ecf20Sopenharmony_ci 18938c2ecf20Sopenharmony_ci wr_mem (dev, &rx_desc->wr_buf_type, CHANNEL_TYPE_AAL5 | RX_CHANNEL_DISABLED); 18948c2ecf20Sopenharmony_ci } 18958c2ecf20Sopenharmony_ci 18968c2ecf20Sopenharmony_ci printk (" rx buffers"); 18978c2ecf20Sopenharmony_ci 18988c2ecf20Sopenharmony_ci // Use space bufn4 at the moment for rx buffers 18998c2ecf20Sopenharmony_ci 19008c2ecf20Sopenharmony_ci rx_desc = memmap->bufn4; 19018c2ecf20Sopenharmony_ci 19028c2ecf20Sopenharmony_ci wr_mem (dev, &memmap->rxfreebufstart.next, BUF_PTR(rx_desc) | BUFF_STATUS_EMPTY); 19038c2ecf20Sopenharmony_ci 19048c2ecf20Sopenharmony_ci for (buff_count = 0; buff_count < BUFN4_SIZE-1; buff_count++) { 19058c2ecf20Sopenharmony_ci wr_mem (dev, &rx_desc->next, BUF_PTR(rx_desc+1) | BUFF_STATUS_EMPTY); 19068c2ecf20Sopenharmony_ci 19078c2ecf20Sopenharmony_ci rx_desc++; 19088c2ecf20Sopenharmony_ci } 19098c2ecf20Sopenharmony_ci 19108c2ecf20Sopenharmony_ci wr_mem (dev, &rx_desc->next, BUF_PTR(&memmap->rxfreebufend) | BUFF_STATUS_EMPTY); 19118c2ecf20Sopenharmony_ci 19128c2ecf20Sopenharmony_ci // Initialise the receive free buffer count 19138c2ecf20Sopenharmony_ci wr_regw (dev, RX_FREE_BUFFER_COUNT_OFF, BUFN4_SIZE); 19148c2ecf20Sopenharmony_ci 19158c2ecf20Sopenharmony_ci // Initialize Horizons registers 19168c2ecf20Sopenharmony_ci 19178c2ecf20Sopenharmony_ci // TX config 19188c2ecf20Sopenharmony_ci wr_regw (dev, TX_CONFIG_OFF, 19198c2ecf20Sopenharmony_ci ABR_ROUND_ROBIN | TX_NORMAL_OPERATION | DRVR_DRVRBAR_ENABLE); 19208c2ecf20Sopenharmony_ci 19218c2ecf20Sopenharmony_ci // RX config. Use 10-x VC bits, x VP bits, non user cells in channel 0. 19228c2ecf20Sopenharmony_ci wr_regw (dev, RX_CONFIG_OFF, 19238c2ecf20Sopenharmony_ci DISCARD_UNUSED_VPI_VCI_BITS_SET | NON_USER_CELLS_IN_ONE_CHANNEL | vpi_bits); 19248c2ecf20Sopenharmony_ci 19258c2ecf20Sopenharmony_ci // RX line config 19268c2ecf20Sopenharmony_ci wr_regw (dev, RX_LINE_CONFIG_OFF, 19278c2ecf20Sopenharmony_ci LOCK_DETECT_ENABLE | FREQUENCY_DETECT_ENABLE | GXTALOUT_SELECT_DIV4); 19288c2ecf20Sopenharmony_ci 19298c2ecf20Sopenharmony_ci // Set the max AAL5 cell count to be just enough to contain the 19308c2ecf20Sopenharmony_ci // largest AAL5 frame that the user wants to receive 19318c2ecf20Sopenharmony_ci wr_regw (dev, MAX_AAL5_CELL_COUNT_OFF, 19328c2ecf20Sopenharmony_ci DIV_ROUND_UP(max_rx_size + ATM_AAL5_TRAILER, ATM_CELL_PAYLOAD)); 19338c2ecf20Sopenharmony_ci 19348c2ecf20Sopenharmony_ci // Enable receive 19358c2ecf20Sopenharmony_ci wr_regw (dev, RX_CONFIG_OFF, rd_regw (dev, RX_CONFIG_OFF) | RX_ENABLE); 19368c2ecf20Sopenharmony_ci 19378c2ecf20Sopenharmony_ci printk (" control"); 19388c2ecf20Sopenharmony_ci 19398c2ecf20Sopenharmony_ci // Drive the OE of the LEDs then turn the green LED on 19408c2ecf20Sopenharmony_ci ctrl |= GREEN_LED_OE | YELLOW_LED_OE | GREEN_LED | YELLOW_LED; 19418c2ecf20Sopenharmony_ci wr_regl (dev, CONTROL_0_REG, ctrl); 19428c2ecf20Sopenharmony_ci 19438c2ecf20Sopenharmony_ci // Test for a 155-capable card 19448c2ecf20Sopenharmony_ci 19458c2ecf20Sopenharmony_ci if (onefivefive) { 19468c2ecf20Sopenharmony_ci // Select 155 mode... make this a choice (or: how do we detect 19478c2ecf20Sopenharmony_ci // external line speed and switch?) 19488c2ecf20Sopenharmony_ci ctrl |= ATM_LAYER_SELECT; 19498c2ecf20Sopenharmony_ci wr_regl (dev, CONTROL_0_REG, ctrl); 19508c2ecf20Sopenharmony_ci 19518c2ecf20Sopenharmony_ci // test SUNI-lite vs SAMBA 19528c2ecf20Sopenharmony_ci 19538c2ecf20Sopenharmony_ci // Register 0x00 in the SUNI will have some of bits 3-7 set, and 19548c2ecf20Sopenharmony_ci // they will always be zero for the SAMBA. Ha! Bloody hardware 19558c2ecf20Sopenharmony_ci // engineers. It'll never work. 19568c2ecf20Sopenharmony_ci 19578c2ecf20Sopenharmony_ci if (rd_framer (dev, 0) & 0x00f0) { 19588c2ecf20Sopenharmony_ci // SUNI 19598c2ecf20Sopenharmony_ci printk (" SUNI"); 19608c2ecf20Sopenharmony_ci 19618c2ecf20Sopenharmony_ci // Reset, just in case 19628c2ecf20Sopenharmony_ci wr_framer (dev, 0x00, 0x0080); 19638c2ecf20Sopenharmony_ci wr_framer (dev, 0x00, 0x0000); 19648c2ecf20Sopenharmony_ci 19658c2ecf20Sopenharmony_ci // Configure transmit FIFO 19668c2ecf20Sopenharmony_ci wr_framer (dev, 0x63, rd_framer (dev, 0x63) | 0x0002); 19678c2ecf20Sopenharmony_ci 19688c2ecf20Sopenharmony_ci // Set line timed mode 19698c2ecf20Sopenharmony_ci wr_framer (dev, 0x05, rd_framer (dev, 0x05) | 0x0001); 19708c2ecf20Sopenharmony_ci } else { 19718c2ecf20Sopenharmony_ci // SAMBA 19728c2ecf20Sopenharmony_ci printk (" SAMBA"); 19738c2ecf20Sopenharmony_ci 19748c2ecf20Sopenharmony_ci // Reset, just in case 19758c2ecf20Sopenharmony_ci wr_framer (dev, 0, rd_framer (dev, 0) | 0x0001); 19768c2ecf20Sopenharmony_ci wr_framer (dev, 0, rd_framer (dev, 0) &~ 0x0001); 19778c2ecf20Sopenharmony_ci 19788c2ecf20Sopenharmony_ci // Turn off diagnostic loopback and enable line-timed mode 19798c2ecf20Sopenharmony_ci wr_framer (dev, 0, 0x0002); 19808c2ecf20Sopenharmony_ci 19818c2ecf20Sopenharmony_ci // Turn on transmit outputs 19828c2ecf20Sopenharmony_ci wr_framer (dev, 2, 0x0B80); 19838c2ecf20Sopenharmony_ci } 19848c2ecf20Sopenharmony_ci } else { 19858c2ecf20Sopenharmony_ci // Select 25 mode 19868c2ecf20Sopenharmony_ci ctrl &= ~ATM_LAYER_SELECT; 19878c2ecf20Sopenharmony_ci 19888c2ecf20Sopenharmony_ci // Madge B154 setup 19898c2ecf20Sopenharmony_ci // none required? 19908c2ecf20Sopenharmony_ci } 19918c2ecf20Sopenharmony_ci 19928c2ecf20Sopenharmony_ci printk (" LEDs"); 19938c2ecf20Sopenharmony_ci 19948c2ecf20Sopenharmony_ci GREEN_LED_ON(dev); 19958c2ecf20Sopenharmony_ci YELLOW_LED_ON(dev); 19968c2ecf20Sopenharmony_ci 19978c2ecf20Sopenharmony_ci printk (" ESI="); 19988c2ecf20Sopenharmony_ci 19998c2ecf20Sopenharmony_ci { 20008c2ecf20Sopenharmony_ci u16 b = 0; 20018c2ecf20Sopenharmony_ci int i; 20028c2ecf20Sopenharmony_ci u8 * esi = dev->atm_dev->esi; 20038c2ecf20Sopenharmony_ci 20048c2ecf20Sopenharmony_ci // in the card I have, EEPROM 20058c2ecf20Sopenharmony_ci // addresses 0, 1, 2 contain 0 20068c2ecf20Sopenharmony_ci // addresess 5, 6 etc. contain ffff 20078c2ecf20Sopenharmony_ci // NB: Madge prefix is 00 00 f6 (which is 00 00 6f in Ethernet bit order) 20088c2ecf20Sopenharmony_ci // the read_bia routine gets the BIA in Ethernet bit order 20098c2ecf20Sopenharmony_ci 20108c2ecf20Sopenharmony_ci for (i=0; i < ESI_LEN; ++i) { 20118c2ecf20Sopenharmony_ci if (i % 2 == 0) 20128c2ecf20Sopenharmony_ci b = read_bia (dev, i/2 + 2); 20138c2ecf20Sopenharmony_ci else 20148c2ecf20Sopenharmony_ci b = b >> 8; 20158c2ecf20Sopenharmony_ci esi[i] = b & 0xFF; 20168c2ecf20Sopenharmony_ci printk ("%02x", esi[i]); 20178c2ecf20Sopenharmony_ci } 20188c2ecf20Sopenharmony_ci } 20198c2ecf20Sopenharmony_ci 20208c2ecf20Sopenharmony_ci // Enable RX_Q and ?X_COMPLETE interrupts only 20218c2ecf20Sopenharmony_ci wr_regl (dev, INT_ENABLE_REG_OFF, INTERESTING_INTERRUPTS); 20228c2ecf20Sopenharmony_ci printk (" IRQ on"); 20238c2ecf20Sopenharmony_ci 20248c2ecf20Sopenharmony_ci printk (".\n"); 20258c2ecf20Sopenharmony_ci 20268c2ecf20Sopenharmony_ci return onefivefive; 20278c2ecf20Sopenharmony_ci} 20288c2ecf20Sopenharmony_ci 20298c2ecf20Sopenharmony_ci/********** check max_sdu **********/ 20308c2ecf20Sopenharmony_ci 20318c2ecf20Sopenharmony_cistatic int check_max_sdu (hrz_aal aal, struct atm_trafprm * tp, unsigned int max_frame_size) { 20328c2ecf20Sopenharmony_ci PRINTD (DBG_FLOW|DBG_QOS, "check_max_sdu"); 20338c2ecf20Sopenharmony_ci 20348c2ecf20Sopenharmony_ci switch (aal) { 20358c2ecf20Sopenharmony_ci case aal0: 20368c2ecf20Sopenharmony_ci if (!(tp->max_sdu)) { 20378c2ecf20Sopenharmony_ci PRINTD (DBG_QOS, "defaulting max_sdu"); 20388c2ecf20Sopenharmony_ci tp->max_sdu = ATM_AAL0_SDU; 20398c2ecf20Sopenharmony_ci } else if (tp->max_sdu != ATM_AAL0_SDU) { 20408c2ecf20Sopenharmony_ci PRINTD (DBG_QOS|DBG_ERR, "rejecting max_sdu"); 20418c2ecf20Sopenharmony_ci return -EINVAL; 20428c2ecf20Sopenharmony_ci } 20438c2ecf20Sopenharmony_ci break; 20448c2ecf20Sopenharmony_ci case aal34: 20458c2ecf20Sopenharmony_ci if (tp->max_sdu == 0 || tp->max_sdu > ATM_MAX_AAL34_PDU) { 20468c2ecf20Sopenharmony_ci PRINTD (DBG_QOS, "%sing max_sdu", tp->max_sdu ? "capp" : "default"); 20478c2ecf20Sopenharmony_ci tp->max_sdu = ATM_MAX_AAL34_PDU; 20488c2ecf20Sopenharmony_ci } 20498c2ecf20Sopenharmony_ci break; 20508c2ecf20Sopenharmony_ci case aal5: 20518c2ecf20Sopenharmony_ci if (tp->max_sdu == 0 || tp->max_sdu > max_frame_size) { 20528c2ecf20Sopenharmony_ci PRINTD (DBG_QOS, "%sing max_sdu", tp->max_sdu ? "capp" : "default"); 20538c2ecf20Sopenharmony_ci tp->max_sdu = max_frame_size; 20548c2ecf20Sopenharmony_ci } 20558c2ecf20Sopenharmony_ci break; 20568c2ecf20Sopenharmony_ci } 20578c2ecf20Sopenharmony_ci return 0; 20588c2ecf20Sopenharmony_ci} 20598c2ecf20Sopenharmony_ci 20608c2ecf20Sopenharmony_ci/********** check pcr **********/ 20618c2ecf20Sopenharmony_ci 20628c2ecf20Sopenharmony_ci// something like this should be part of ATM Linux 20638c2ecf20Sopenharmony_cistatic int atm_pcr_check (struct atm_trafprm * tp, unsigned int pcr) { 20648c2ecf20Sopenharmony_ci // we are assuming non-UBR, and non-special values of pcr 20658c2ecf20Sopenharmony_ci if (tp->min_pcr == ATM_MAX_PCR) 20668c2ecf20Sopenharmony_ci PRINTD (DBG_QOS, "luser gave min_pcr = ATM_MAX_PCR"); 20678c2ecf20Sopenharmony_ci else if (tp->min_pcr < 0) 20688c2ecf20Sopenharmony_ci PRINTD (DBG_QOS, "luser gave negative min_pcr"); 20698c2ecf20Sopenharmony_ci else if (tp->min_pcr && tp->min_pcr > pcr) 20708c2ecf20Sopenharmony_ci PRINTD (DBG_QOS, "pcr less than min_pcr"); 20718c2ecf20Sopenharmony_ci else 20728c2ecf20Sopenharmony_ci // !! max_pcr = UNSPEC (0) is equivalent to max_pcr = MAX (-1) 20738c2ecf20Sopenharmony_ci // easier to #define ATM_MAX_PCR 0 and have all rates unsigned? 20748c2ecf20Sopenharmony_ci // [this would get rid of next two conditionals] 20758c2ecf20Sopenharmony_ci if ((0) && tp->max_pcr == ATM_MAX_PCR) 20768c2ecf20Sopenharmony_ci PRINTD (DBG_QOS, "luser gave max_pcr = ATM_MAX_PCR"); 20778c2ecf20Sopenharmony_ci else if ((tp->max_pcr != ATM_MAX_PCR) && tp->max_pcr < 0) 20788c2ecf20Sopenharmony_ci PRINTD (DBG_QOS, "luser gave negative max_pcr"); 20798c2ecf20Sopenharmony_ci else if (tp->max_pcr && tp->max_pcr != ATM_MAX_PCR && tp->max_pcr < pcr) 20808c2ecf20Sopenharmony_ci PRINTD (DBG_QOS, "pcr greater than max_pcr"); 20818c2ecf20Sopenharmony_ci else { 20828c2ecf20Sopenharmony_ci // each limit unspecified or not violated 20838c2ecf20Sopenharmony_ci PRINTD (DBG_QOS, "xBR(pcr) OK"); 20848c2ecf20Sopenharmony_ci return 0; 20858c2ecf20Sopenharmony_ci } 20868c2ecf20Sopenharmony_ci PRINTD (DBG_QOS, "pcr=%u, tp: min_pcr=%d, pcr=%d, max_pcr=%d", 20878c2ecf20Sopenharmony_ci pcr, tp->min_pcr, tp->pcr, tp->max_pcr); 20888c2ecf20Sopenharmony_ci return -EINVAL; 20898c2ecf20Sopenharmony_ci} 20908c2ecf20Sopenharmony_ci 20918c2ecf20Sopenharmony_ci/********** open VC **********/ 20928c2ecf20Sopenharmony_ci 20938c2ecf20Sopenharmony_cistatic int hrz_open (struct atm_vcc *atm_vcc) 20948c2ecf20Sopenharmony_ci{ 20958c2ecf20Sopenharmony_ci int error; 20968c2ecf20Sopenharmony_ci u16 channel; 20978c2ecf20Sopenharmony_ci 20988c2ecf20Sopenharmony_ci struct atm_qos * qos; 20998c2ecf20Sopenharmony_ci struct atm_trafprm * txtp; 21008c2ecf20Sopenharmony_ci struct atm_trafprm * rxtp; 21018c2ecf20Sopenharmony_ci 21028c2ecf20Sopenharmony_ci hrz_dev * dev = HRZ_DEV(atm_vcc->dev); 21038c2ecf20Sopenharmony_ci hrz_vcc vcc; 21048c2ecf20Sopenharmony_ci hrz_vcc * vccp; // allocated late 21058c2ecf20Sopenharmony_ci short vpi = atm_vcc->vpi; 21068c2ecf20Sopenharmony_ci int vci = atm_vcc->vci; 21078c2ecf20Sopenharmony_ci PRINTD (DBG_FLOW|DBG_VCC, "hrz_open %x %x", vpi, vci); 21088c2ecf20Sopenharmony_ci 21098c2ecf20Sopenharmony_ci#ifdef ATM_VPI_UNSPEC 21108c2ecf20Sopenharmony_ci // UNSPEC is deprecated, remove this code eventually 21118c2ecf20Sopenharmony_ci if (vpi == ATM_VPI_UNSPEC || vci == ATM_VCI_UNSPEC) { 21128c2ecf20Sopenharmony_ci PRINTK (KERN_WARNING, "rejecting open with unspecified VPI/VCI (deprecated)"); 21138c2ecf20Sopenharmony_ci return -EINVAL; 21148c2ecf20Sopenharmony_ci } 21158c2ecf20Sopenharmony_ci#endif 21168c2ecf20Sopenharmony_ci 21178c2ecf20Sopenharmony_ci error = vpivci_to_channel (&channel, vpi, vci); 21188c2ecf20Sopenharmony_ci if (error) { 21198c2ecf20Sopenharmony_ci PRINTD (DBG_WARN|DBG_VCC, "VPI/VCI out of range: %hd/%d", vpi, vci); 21208c2ecf20Sopenharmony_ci return error; 21218c2ecf20Sopenharmony_ci } 21228c2ecf20Sopenharmony_ci 21238c2ecf20Sopenharmony_ci vcc.channel = channel; 21248c2ecf20Sopenharmony_ci // max speed for the moment 21258c2ecf20Sopenharmony_ci vcc.tx_rate = 0x0; 21268c2ecf20Sopenharmony_ci 21278c2ecf20Sopenharmony_ci qos = &atm_vcc->qos; 21288c2ecf20Sopenharmony_ci 21298c2ecf20Sopenharmony_ci // check AAL and remember it 21308c2ecf20Sopenharmony_ci switch (qos->aal) { 21318c2ecf20Sopenharmony_ci case ATM_AAL0: 21328c2ecf20Sopenharmony_ci // we would if it were 48 bytes and not 52! 21338c2ecf20Sopenharmony_ci PRINTD (DBG_QOS|DBG_VCC, "AAL0"); 21348c2ecf20Sopenharmony_ci vcc.aal = aal0; 21358c2ecf20Sopenharmony_ci break; 21368c2ecf20Sopenharmony_ci case ATM_AAL34: 21378c2ecf20Sopenharmony_ci // we would if I knew how do the SAR! 21388c2ecf20Sopenharmony_ci PRINTD (DBG_QOS|DBG_VCC, "AAL3/4"); 21398c2ecf20Sopenharmony_ci vcc.aal = aal34; 21408c2ecf20Sopenharmony_ci break; 21418c2ecf20Sopenharmony_ci case ATM_AAL5: 21428c2ecf20Sopenharmony_ci PRINTD (DBG_QOS|DBG_VCC, "AAL5"); 21438c2ecf20Sopenharmony_ci vcc.aal = aal5; 21448c2ecf20Sopenharmony_ci break; 21458c2ecf20Sopenharmony_ci default: 21468c2ecf20Sopenharmony_ci PRINTD (DBG_QOS|DBG_VCC, "Bad AAL!"); 21478c2ecf20Sopenharmony_ci return -EINVAL; 21488c2ecf20Sopenharmony_ci } 21498c2ecf20Sopenharmony_ci 21508c2ecf20Sopenharmony_ci // TX traffic parameters 21518c2ecf20Sopenharmony_ci 21528c2ecf20Sopenharmony_ci // there are two, interrelated problems here: 1. the reservation of 21538c2ecf20Sopenharmony_ci // PCR is not a binary choice, we are given bounds and/or a 21548c2ecf20Sopenharmony_ci // desirable value; 2. the device is only capable of certain values, 21558c2ecf20Sopenharmony_ci // most of which are not integers. It is almost certainly acceptable 21568c2ecf20Sopenharmony_ci // to be off by a maximum of 1 to 10 cps. 21578c2ecf20Sopenharmony_ci 21588c2ecf20Sopenharmony_ci // Pragmatic choice: always store an integral PCR as that which has 21598c2ecf20Sopenharmony_ci // been allocated, even if we allocate a little (or a lot) less, 21608c2ecf20Sopenharmony_ci // after rounding. The actual allocation depends on what we can 21618c2ecf20Sopenharmony_ci // manage with our rate selection algorithm. The rate selection 21628c2ecf20Sopenharmony_ci // algorithm is given an integral PCR and a tolerance and told 21638c2ecf20Sopenharmony_ci // whether it should round the value up or down if the tolerance is 21648c2ecf20Sopenharmony_ci // exceeded; it returns: a) the actual rate selected (rounded up to 21658c2ecf20Sopenharmony_ci // the nearest integer), b) a bit pattern to feed to the timer 21668c2ecf20Sopenharmony_ci // register, and c) a failure value if no applicable rate exists. 21678c2ecf20Sopenharmony_ci 21688c2ecf20Sopenharmony_ci // Part of the job is done by atm_pcr_goal which gives us a PCR 21698c2ecf20Sopenharmony_ci // specification which says: EITHER grab the maximum available PCR 21708c2ecf20Sopenharmony_ci // (and perhaps a lower bound which we musn't pass), OR grab this 21718c2ecf20Sopenharmony_ci // amount, rounding down if you have to (and perhaps a lower bound 21728c2ecf20Sopenharmony_ci // which we musn't pass) OR grab this amount, rounding up if you 21738c2ecf20Sopenharmony_ci // have to (and perhaps an upper bound which we musn't pass). If any 21748c2ecf20Sopenharmony_ci // bounds ARE passed we fail. Note that rounding is only rounding to 21758c2ecf20Sopenharmony_ci // match device limitations, we do not round down to satisfy 21768c2ecf20Sopenharmony_ci // bandwidth availability even if this would not violate any given 21778c2ecf20Sopenharmony_ci // lower bound. 21788c2ecf20Sopenharmony_ci 21798c2ecf20Sopenharmony_ci // Note: telephony = 64kb/s = 48 byte cell payload @ 500/3 cells/s 21808c2ecf20Sopenharmony_ci // (say) so this is not even a binary fixpoint cell rate (but this 21818c2ecf20Sopenharmony_ci // device can do it). To avoid this sort of hassle we use a 21828c2ecf20Sopenharmony_ci // tolerance parameter (currently fixed at 10 cps). 21838c2ecf20Sopenharmony_ci 21848c2ecf20Sopenharmony_ci PRINTD (DBG_QOS, "TX:"); 21858c2ecf20Sopenharmony_ci 21868c2ecf20Sopenharmony_ci txtp = &qos->txtp; 21878c2ecf20Sopenharmony_ci 21888c2ecf20Sopenharmony_ci // set up defaults for no traffic 21898c2ecf20Sopenharmony_ci vcc.tx_rate = 0; 21908c2ecf20Sopenharmony_ci // who knows what would actually happen if you try and send on this? 21918c2ecf20Sopenharmony_ci vcc.tx_xbr_bits = IDLE_RATE_TYPE; 21928c2ecf20Sopenharmony_ci vcc.tx_pcr_bits = CLOCK_DISABLE; 21938c2ecf20Sopenharmony_ci#if 0 21948c2ecf20Sopenharmony_ci vcc.tx_scr_bits = CLOCK_DISABLE; 21958c2ecf20Sopenharmony_ci vcc.tx_bucket_bits = 0; 21968c2ecf20Sopenharmony_ci#endif 21978c2ecf20Sopenharmony_ci 21988c2ecf20Sopenharmony_ci if (txtp->traffic_class != ATM_NONE) { 21998c2ecf20Sopenharmony_ci error = check_max_sdu (vcc.aal, txtp, max_tx_size); 22008c2ecf20Sopenharmony_ci if (error) { 22018c2ecf20Sopenharmony_ci PRINTD (DBG_QOS, "TX max_sdu check failed"); 22028c2ecf20Sopenharmony_ci return error; 22038c2ecf20Sopenharmony_ci } 22048c2ecf20Sopenharmony_ci 22058c2ecf20Sopenharmony_ci switch (txtp->traffic_class) { 22068c2ecf20Sopenharmony_ci case ATM_UBR: { 22078c2ecf20Sopenharmony_ci // we take "the PCR" as a rate-cap 22088c2ecf20Sopenharmony_ci // not reserved 22098c2ecf20Sopenharmony_ci vcc.tx_rate = 0; 22108c2ecf20Sopenharmony_ci make_rate (dev, 1<<30, round_nearest, &vcc.tx_pcr_bits, NULL); 22118c2ecf20Sopenharmony_ci vcc.tx_xbr_bits = ABR_RATE_TYPE; 22128c2ecf20Sopenharmony_ci break; 22138c2ecf20Sopenharmony_ci } 22148c2ecf20Sopenharmony_ci#if 0 22158c2ecf20Sopenharmony_ci case ATM_ABR: { 22168c2ecf20Sopenharmony_ci // reserve min, allow up to max 22178c2ecf20Sopenharmony_ci vcc.tx_rate = 0; // ? 22188c2ecf20Sopenharmony_ci make_rate (dev, 1<<30, round_nearest, &vcc.tx_pcr_bits, 0); 22198c2ecf20Sopenharmony_ci vcc.tx_xbr_bits = ABR_RATE_TYPE; 22208c2ecf20Sopenharmony_ci break; 22218c2ecf20Sopenharmony_ci } 22228c2ecf20Sopenharmony_ci#endif 22238c2ecf20Sopenharmony_ci case ATM_CBR: { 22248c2ecf20Sopenharmony_ci int pcr = atm_pcr_goal (txtp); 22258c2ecf20Sopenharmony_ci rounding r; 22268c2ecf20Sopenharmony_ci if (!pcr) { 22278c2ecf20Sopenharmony_ci // down vs. up, remaining bandwidth vs. unlimited bandwidth!! 22288c2ecf20Sopenharmony_ci // should really have: once someone gets unlimited bandwidth 22298c2ecf20Sopenharmony_ci // that no more non-UBR channels can be opened until the 22308c2ecf20Sopenharmony_ci // unlimited one closes?? For the moment, round_down means 22318c2ecf20Sopenharmony_ci // greedy people actually get something and not nothing 22328c2ecf20Sopenharmony_ci r = round_down; 22338c2ecf20Sopenharmony_ci // slight race (no locking) here so we may get -EAGAIN 22348c2ecf20Sopenharmony_ci // later; the greedy bastards would deserve it :) 22358c2ecf20Sopenharmony_ci PRINTD (DBG_QOS, "snatching all remaining TX bandwidth"); 22368c2ecf20Sopenharmony_ci pcr = dev->tx_avail; 22378c2ecf20Sopenharmony_ci } else if (pcr < 0) { 22388c2ecf20Sopenharmony_ci r = round_down; 22398c2ecf20Sopenharmony_ci pcr = -pcr; 22408c2ecf20Sopenharmony_ci } else { 22418c2ecf20Sopenharmony_ci r = round_up; 22428c2ecf20Sopenharmony_ci } 22438c2ecf20Sopenharmony_ci error = make_rate_with_tolerance (dev, pcr, r, 10, 22448c2ecf20Sopenharmony_ci &vcc.tx_pcr_bits, &vcc.tx_rate); 22458c2ecf20Sopenharmony_ci if (error) { 22468c2ecf20Sopenharmony_ci PRINTD (DBG_QOS, "could not make rate from TX PCR"); 22478c2ecf20Sopenharmony_ci return error; 22488c2ecf20Sopenharmony_ci } 22498c2ecf20Sopenharmony_ci // not really clear what further checking is needed 22508c2ecf20Sopenharmony_ci error = atm_pcr_check (txtp, vcc.tx_rate); 22518c2ecf20Sopenharmony_ci if (error) { 22528c2ecf20Sopenharmony_ci PRINTD (DBG_QOS, "TX PCR failed consistency check"); 22538c2ecf20Sopenharmony_ci return error; 22548c2ecf20Sopenharmony_ci } 22558c2ecf20Sopenharmony_ci vcc.tx_xbr_bits = CBR_RATE_TYPE; 22568c2ecf20Sopenharmony_ci break; 22578c2ecf20Sopenharmony_ci } 22588c2ecf20Sopenharmony_ci#if 0 22598c2ecf20Sopenharmony_ci case ATM_VBR: { 22608c2ecf20Sopenharmony_ci int pcr = atm_pcr_goal (txtp); 22618c2ecf20Sopenharmony_ci // int scr = atm_scr_goal (txtp); 22628c2ecf20Sopenharmony_ci int scr = pcr/2; // just for fun 22638c2ecf20Sopenharmony_ci unsigned int mbs = 60; // just for fun 22648c2ecf20Sopenharmony_ci rounding pr; 22658c2ecf20Sopenharmony_ci rounding sr; 22668c2ecf20Sopenharmony_ci unsigned int bucket; 22678c2ecf20Sopenharmony_ci if (!pcr) { 22688c2ecf20Sopenharmony_ci pr = round_nearest; 22698c2ecf20Sopenharmony_ci pcr = 1<<30; 22708c2ecf20Sopenharmony_ci } else if (pcr < 0) { 22718c2ecf20Sopenharmony_ci pr = round_down; 22728c2ecf20Sopenharmony_ci pcr = -pcr; 22738c2ecf20Sopenharmony_ci } else { 22748c2ecf20Sopenharmony_ci pr = round_up; 22758c2ecf20Sopenharmony_ci } 22768c2ecf20Sopenharmony_ci error = make_rate_with_tolerance (dev, pcr, pr, 10, 22778c2ecf20Sopenharmony_ci &vcc.tx_pcr_bits, 0); 22788c2ecf20Sopenharmony_ci if (!scr) { 22798c2ecf20Sopenharmony_ci // see comments for PCR with CBR above 22808c2ecf20Sopenharmony_ci sr = round_down; 22818c2ecf20Sopenharmony_ci // slight race (no locking) here so we may get -EAGAIN 22828c2ecf20Sopenharmony_ci // later; the greedy bastards would deserve it :) 22838c2ecf20Sopenharmony_ci PRINTD (DBG_QOS, "snatching all remaining TX bandwidth"); 22848c2ecf20Sopenharmony_ci scr = dev->tx_avail; 22858c2ecf20Sopenharmony_ci } else if (scr < 0) { 22868c2ecf20Sopenharmony_ci sr = round_down; 22878c2ecf20Sopenharmony_ci scr = -scr; 22888c2ecf20Sopenharmony_ci } else { 22898c2ecf20Sopenharmony_ci sr = round_up; 22908c2ecf20Sopenharmony_ci } 22918c2ecf20Sopenharmony_ci error = make_rate_with_tolerance (dev, scr, sr, 10, 22928c2ecf20Sopenharmony_ci &vcc.tx_scr_bits, &vcc.tx_rate); 22938c2ecf20Sopenharmony_ci if (error) { 22948c2ecf20Sopenharmony_ci PRINTD (DBG_QOS, "could not make rate from TX SCR"); 22958c2ecf20Sopenharmony_ci return error; 22968c2ecf20Sopenharmony_ci } 22978c2ecf20Sopenharmony_ci // not really clear what further checking is needed 22988c2ecf20Sopenharmony_ci // error = atm_scr_check (txtp, vcc.tx_rate); 22998c2ecf20Sopenharmony_ci if (error) { 23008c2ecf20Sopenharmony_ci PRINTD (DBG_QOS, "TX SCR failed consistency check"); 23018c2ecf20Sopenharmony_ci return error; 23028c2ecf20Sopenharmony_ci } 23038c2ecf20Sopenharmony_ci // bucket calculations (from a piece of paper...) cell bucket 23048c2ecf20Sopenharmony_ci // capacity must be largest integer smaller than m(p-s)/p + 1 23058c2ecf20Sopenharmony_ci // where m = max burst size, p = pcr, s = scr 23068c2ecf20Sopenharmony_ci bucket = mbs*(pcr-scr)/pcr; 23078c2ecf20Sopenharmony_ci if (bucket*pcr != mbs*(pcr-scr)) 23088c2ecf20Sopenharmony_ci bucket += 1; 23098c2ecf20Sopenharmony_ci if (bucket > BUCKET_MAX_SIZE) { 23108c2ecf20Sopenharmony_ci PRINTD (DBG_QOS, "shrinking bucket from %u to %u", 23118c2ecf20Sopenharmony_ci bucket, BUCKET_MAX_SIZE); 23128c2ecf20Sopenharmony_ci bucket = BUCKET_MAX_SIZE; 23138c2ecf20Sopenharmony_ci } 23148c2ecf20Sopenharmony_ci vcc.tx_xbr_bits = VBR_RATE_TYPE; 23158c2ecf20Sopenharmony_ci vcc.tx_bucket_bits = bucket; 23168c2ecf20Sopenharmony_ci break; 23178c2ecf20Sopenharmony_ci } 23188c2ecf20Sopenharmony_ci#endif 23198c2ecf20Sopenharmony_ci default: { 23208c2ecf20Sopenharmony_ci PRINTD (DBG_QOS, "unsupported TX traffic class"); 23218c2ecf20Sopenharmony_ci return -EINVAL; 23228c2ecf20Sopenharmony_ci } 23238c2ecf20Sopenharmony_ci } 23248c2ecf20Sopenharmony_ci } 23258c2ecf20Sopenharmony_ci 23268c2ecf20Sopenharmony_ci // RX traffic parameters 23278c2ecf20Sopenharmony_ci 23288c2ecf20Sopenharmony_ci PRINTD (DBG_QOS, "RX:"); 23298c2ecf20Sopenharmony_ci 23308c2ecf20Sopenharmony_ci rxtp = &qos->rxtp; 23318c2ecf20Sopenharmony_ci 23328c2ecf20Sopenharmony_ci // set up defaults for no traffic 23338c2ecf20Sopenharmony_ci vcc.rx_rate = 0; 23348c2ecf20Sopenharmony_ci 23358c2ecf20Sopenharmony_ci if (rxtp->traffic_class != ATM_NONE) { 23368c2ecf20Sopenharmony_ci error = check_max_sdu (vcc.aal, rxtp, max_rx_size); 23378c2ecf20Sopenharmony_ci if (error) { 23388c2ecf20Sopenharmony_ci PRINTD (DBG_QOS, "RX max_sdu check failed"); 23398c2ecf20Sopenharmony_ci return error; 23408c2ecf20Sopenharmony_ci } 23418c2ecf20Sopenharmony_ci switch (rxtp->traffic_class) { 23428c2ecf20Sopenharmony_ci case ATM_UBR: { 23438c2ecf20Sopenharmony_ci // not reserved 23448c2ecf20Sopenharmony_ci break; 23458c2ecf20Sopenharmony_ci } 23468c2ecf20Sopenharmony_ci#if 0 23478c2ecf20Sopenharmony_ci case ATM_ABR: { 23488c2ecf20Sopenharmony_ci // reserve min 23498c2ecf20Sopenharmony_ci vcc.rx_rate = 0; // ? 23508c2ecf20Sopenharmony_ci break; 23518c2ecf20Sopenharmony_ci } 23528c2ecf20Sopenharmony_ci#endif 23538c2ecf20Sopenharmony_ci case ATM_CBR: { 23548c2ecf20Sopenharmony_ci int pcr = atm_pcr_goal (rxtp); 23558c2ecf20Sopenharmony_ci if (!pcr) { 23568c2ecf20Sopenharmony_ci // slight race (no locking) here so we may get -EAGAIN 23578c2ecf20Sopenharmony_ci // later; the greedy bastards would deserve it :) 23588c2ecf20Sopenharmony_ci PRINTD (DBG_QOS, "snatching all remaining RX bandwidth"); 23598c2ecf20Sopenharmony_ci pcr = dev->rx_avail; 23608c2ecf20Sopenharmony_ci } else if (pcr < 0) { 23618c2ecf20Sopenharmony_ci pcr = -pcr; 23628c2ecf20Sopenharmony_ci } 23638c2ecf20Sopenharmony_ci vcc.rx_rate = pcr; 23648c2ecf20Sopenharmony_ci // not really clear what further checking is needed 23658c2ecf20Sopenharmony_ci error = atm_pcr_check (rxtp, vcc.rx_rate); 23668c2ecf20Sopenharmony_ci if (error) { 23678c2ecf20Sopenharmony_ci PRINTD (DBG_QOS, "RX PCR failed consistency check"); 23688c2ecf20Sopenharmony_ci return error; 23698c2ecf20Sopenharmony_ci } 23708c2ecf20Sopenharmony_ci break; 23718c2ecf20Sopenharmony_ci } 23728c2ecf20Sopenharmony_ci#if 0 23738c2ecf20Sopenharmony_ci case ATM_VBR: { 23748c2ecf20Sopenharmony_ci // int scr = atm_scr_goal (rxtp); 23758c2ecf20Sopenharmony_ci int scr = 1<<16; // just for fun 23768c2ecf20Sopenharmony_ci if (!scr) { 23778c2ecf20Sopenharmony_ci // slight race (no locking) here so we may get -EAGAIN 23788c2ecf20Sopenharmony_ci // later; the greedy bastards would deserve it :) 23798c2ecf20Sopenharmony_ci PRINTD (DBG_QOS, "snatching all remaining RX bandwidth"); 23808c2ecf20Sopenharmony_ci scr = dev->rx_avail; 23818c2ecf20Sopenharmony_ci } else if (scr < 0) { 23828c2ecf20Sopenharmony_ci scr = -scr; 23838c2ecf20Sopenharmony_ci } 23848c2ecf20Sopenharmony_ci vcc.rx_rate = scr; 23858c2ecf20Sopenharmony_ci // not really clear what further checking is needed 23868c2ecf20Sopenharmony_ci // error = atm_scr_check (rxtp, vcc.rx_rate); 23878c2ecf20Sopenharmony_ci if (error) { 23888c2ecf20Sopenharmony_ci PRINTD (DBG_QOS, "RX SCR failed consistency check"); 23898c2ecf20Sopenharmony_ci return error; 23908c2ecf20Sopenharmony_ci } 23918c2ecf20Sopenharmony_ci break; 23928c2ecf20Sopenharmony_ci } 23938c2ecf20Sopenharmony_ci#endif 23948c2ecf20Sopenharmony_ci default: { 23958c2ecf20Sopenharmony_ci PRINTD (DBG_QOS, "unsupported RX traffic class"); 23968c2ecf20Sopenharmony_ci return -EINVAL; 23978c2ecf20Sopenharmony_ci } 23988c2ecf20Sopenharmony_ci } 23998c2ecf20Sopenharmony_ci } 24008c2ecf20Sopenharmony_ci 24018c2ecf20Sopenharmony_ci 24028c2ecf20Sopenharmony_ci // late abort useful for diagnostics 24038c2ecf20Sopenharmony_ci if (vcc.aal != aal5) { 24048c2ecf20Sopenharmony_ci PRINTD (DBG_QOS, "AAL not supported"); 24058c2ecf20Sopenharmony_ci return -EINVAL; 24068c2ecf20Sopenharmony_ci } 24078c2ecf20Sopenharmony_ci 24088c2ecf20Sopenharmony_ci // get space for our vcc stuff and copy parameters into it 24098c2ecf20Sopenharmony_ci vccp = kmalloc (sizeof(hrz_vcc), GFP_KERNEL); 24108c2ecf20Sopenharmony_ci if (!vccp) { 24118c2ecf20Sopenharmony_ci PRINTK (KERN_ERR, "out of memory!"); 24128c2ecf20Sopenharmony_ci return -ENOMEM; 24138c2ecf20Sopenharmony_ci } 24148c2ecf20Sopenharmony_ci *vccp = vcc; 24158c2ecf20Sopenharmony_ci 24168c2ecf20Sopenharmony_ci // clear error and grab cell rate resource lock 24178c2ecf20Sopenharmony_ci error = 0; 24188c2ecf20Sopenharmony_ci spin_lock (&dev->rate_lock); 24198c2ecf20Sopenharmony_ci 24208c2ecf20Sopenharmony_ci if (vcc.tx_rate > dev->tx_avail) { 24218c2ecf20Sopenharmony_ci PRINTD (DBG_QOS, "not enough TX PCR left"); 24228c2ecf20Sopenharmony_ci error = -EAGAIN; 24238c2ecf20Sopenharmony_ci } 24248c2ecf20Sopenharmony_ci 24258c2ecf20Sopenharmony_ci if (vcc.rx_rate > dev->rx_avail) { 24268c2ecf20Sopenharmony_ci PRINTD (DBG_QOS, "not enough RX PCR left"); 24278c2ecf20Sopenharmony_ci error = -EAGAIN; 24288c2ecf20Sopenharmony_ci } 24298c2ecf20Sopenharmony_ci 24308c2ecf20Sopenharmony_ci if (!error) { 24318c2ecf20Sopenharmony_ci // really consume cell rates 24328c2ecf20Sopenharmony_ci dev->tx_avail -= vcc.tx_rate; 24338c2ecf20Sopenharmony_ci dev->rx_avail -= vcc.rx_rate; 24348c2ecf20Sopenharmony_ci PRINTD (DBG_QOS|DBG_VCC, "reserving %u TX PCR and %u RX PCR", 24358c2ecf20Sopenharmony_ci vcc.tx_rate, vcc.rx_rate); 24368c2ecf20Sopenharmony_ci } 24378c2ecf20Sopenharmony_ci 24388c2ecf20Sopenharmony_ci // release lock and exit on error 24398c2ecf20Sopenharmony_ci spin_unlock (&dev->rate_lock); 24408c2ecf20Sopenharmony_ci if (error) { 24418c2ecf20Sopenharmony_ci PRINTD (DBG_QOS|DBG_VCC, "insufficient cell rate resources"); 24428c2ecf20Sopenharmony_ci kfree (vccp); 24438c2ecf20Sopenharmony_ci return error; 24448c2ecf20Sopenharmony_ci } 24458c2ecf20Sopenharmony_ci 24468c2ecf20Sopenharmony_ci // this is "immediately before allocating the connection identifier 24478c2ecf20Sopenharmony_ci // in hardware" - so long as the next call does not fail :) 24488c2ecf20Sopenharmony_ci set_bit(ATM_VF_ADDR,&atm_vcc->flags); 24498c2ecf20Sopenharmony_ci 24508c2ecf20Sopenharmony_ci // any errors here are very serious and should never occur 24518c2ecf20Sopenharmony_ci 24528c2ecf20Sopenharmony_ci if (rxtp->traffic_class != ATM_NONE) { 24538c2ecf20Sopenharmony_ci if (dev->rxer[channel]) { 24548c2ecf20Sopenharmony_ci PRINTD (DBG_ERR|DBG_VCC, "VC already open for RX"); 24558c2ecf20Sopenharmony_ci error = -EBUSY; 24568c2ecf20Sopenharmony_ci } 24578c2ecf20Sopenharmony_ci if (!error) 24588c2ecf20Sopenharmony_ci error = hrz_open_rx (dev, channel); 24598c2ecf20Sopenharmony_ci if (error) { 24608c2ecf20Sopenharmony_ci kfree (vccp); 24618c2ecf20Sopenharmony_ci return error; 24628c2ecf20Sopenharmony_ci } 24638c2ecf20Sopenharmony_ci // this link allows RX frames through 24648c2ecf20Sopenharmony_ci dev->rxer[channel] = atm_vcc; 24658c2ecf20Sopenharmony_ci } 24668c2ecf20Sopenharmony_ci 24678c2ecf20Sopenharmony_ci // success, set elements of atm_vcc 24688c2ecf20Sopenharmony_ci atm_vcc->dev_data = (void *) vccp; 24698c2ecf20Sopenharmony_ci 24708c2ecf20Sopenharmony_ci // indicate readiness 24718c2ecf20Sopenharmony_ci set_bit(ATM_VF_READY,&atm_vcc->flags); 24728c2ecf20Sopenharmony_ci 24738c2ecf20Sopenharmony_ci return 0; 24748c2ecf20Sopenharmony_ci} 24758c2ecf20Sopenharmony_ci 24768c2ecf20Sopenharmony_ci/********** close VC **********/ 24778c2ecf20Sopenharmony_ci 24788c2ecf20Sopenharmony_cistatic void hrz_close (struct atm_vcc * atm_vcc) { 24798c2ecf20Sopenharmony_ci hrz_dev * dev = HRZ_DEV(atm_vcc->dev); 24808c2ecf20Sopenharmony_ci hrz_vcc * vcc = HRZ_VCC(atm_vcc); 24818c2ecf20Sopenharmony_ci u16 channel = vcc->channel; 24828c2ecf20Sopenharmony_ci PRINTD (DBG_VCC|DBG_FLOW, "hrz_close"); 24838c2ecf20Sopenharmony_ci 24848c2ecf20Sopenharmony_ci // indicate unreadiness 24858c2ecf20Sopenharmony_ci clear_bit(ATM_VF_READY,&atm_vcc->flags); 24868c2ecf20Sopenharmony_ci 24878c2ecf20Sopenharmony_ci if (atm_vcc->qos.txtp.traffic_class != ATM_NONE) { 24888c2ecf20Sopenharmony_ci unsigned int i; 24898c2ecf20Sopenharmony_ci 24908c2ecf20Sopenharmony_ci // let any TX on this channel that has started complete 24918c2ecf20Sopenharmony_ci // no restart, just keep trying 24928c2ecf20Sopenharmony_ci while (tx_hold (dev)) 24938c2ecf20Sopenharmony_ci ; 24948c2ecf20Sopenharmony_ci // remove record of any tx_channel having been setup for this channel 24958c2ecf20Sopenharmony_ci for (i = 0; i < TX_CHANS; ++i) 24968c2ecf20Sopenharmony_ci if (dev->tx_channel_record[i] == channel) { 24978c2ecf20Sopenharmony_ci dev->tx_channel_record[i] = -1; 24988c2ecf20Sopenharmony_ci break; 24998c2ecf20Sopenharmony_ci } 25008c2ecf20Sopenharmony_ci if (dev->last_vc == channel) 25018c2ecf20Sopenharmony_ci dev->tx_last = -1; 25028c2ecf20Sopenharmony_ci tx_release (dev); 25038c2ecf20Sopenharmony_ci } 25048c2ecf20Sopenharmony_ci 25058c2ecf20Sopenharmony_ci if (atm_vcc->qos.rxtp.traffic_class != ATM_NONE) { 25068c2ecf20Sopenharmony_ci // disable RXing - it tries quite hard 25078c2ecf20Sopenharmony_ci hrz_close_rx (dev, channel); 25088c2ecf20Sopenharmony_ci // forget the vcc - no more skbs will be pushed 25098c2ecf20Sopenharmony_ci if (atm_vcc != dev->rxer[channel]) 25108c2ecf20Sopenharmony_ci PRINTK (KERN_ERR, "%s atm_vcc=%p rxer[channel]=%p", 25118c2ecf20Sopenharmony_ci "arghhh! we're going to die!", 25128c2ecf20Sopenharmony_ci atm_vcc, dev->rxer[channel]); 25138c2ecf20Sopenharmony_ci dev->rxer[channel] = NULL; 25148c2ecf20Sopenharmony_ci } 25158c2ecf20Sopenharmony_ci 25168c2ecf20Sopenharmony_ci // atomically release our rate reservation 25178c2ecf20Sopenharmony_ci spin_lock (&dev->rate_lock); 25188c2ecf20Sopenharmony_ci PRINTD (DBG_QOS|DBG_VCC, "releasing %u TX PCR and %u RX PCR", 25198c2ecf20Sopenharmony_ci vcc->tx_rate, vcc->rx_rate); 25208c2ecf20Sopenharmony_ci dev->tx_avail += vcc->tx_rate; 25218c2ecf20Sopenharmony_ci dev->rx_avail += vcc->rx_rate; 25228c2ecf20Sopenharmony_ci spin_unlock (&dev->rate_lock); 25238c2ecf20Sopenharmony_ci 25248c2ecf20Sopenharmony_ci // free our structure 25258c2ecf20Sopenharmony_ci kfree (vcc); 25268c2ecf20Sopenharmony_ci // say the VPI/VCI is free again 25278c2ecf20Sopenharmony_ci clear_bit(ATM_VF_ADDR,&atm_vcc->flags); 25288c2ecf20Sopenharmony_ci} 25298c2ecf20Sopenharmony_ci 25308c2ecf20Sopenharmony_ci#if 0 25318c2ecf20Sopenharmony_cistatic int hrz_ioctl (struct atm_dev * atm_dev, unsigned int cmd, void *arg) { 25328c2ecf20Sopenharmony_ci hrz_dev * dev = HRZ_DEV(atm_dev); 25338c2ecf20Sopenharmony_ci PRINTD (DBG_FLOW, "hrz_ioctl"); 25348c2ecf20Sopenharmony_ci return -1; 25358c2ecf20Sopenharmony_ci} 25368c2ecf20Sopenharmony_ci 25378c2ecf20Sopenharmony_ciunsigned char hrz_phy_get (struct atm_dev * atm_dev, unsigned long addr) { 25388c2ecf20Sopenharmony_ci hrz_dev * dev = HRZ_DEV(atm_dev); 25398c2ecf20Sopenharmony_ci PRINTD (DBG_FLOW, "hrz_phy_get"); 25408c2ecf20Sopenharmony_ci return 0; 25418c2ecf20Sopenharmony_ci} 25428c2ecf20Sopenharmony_ci 25438c2ecf20Sopenharmony_cistatic void hrz_phy_put (struct atm_dev * atm_dev, unsigned char value, 25448c2ecf20Sopenharmony_ci unsigned long addr) { 25458c2ecf20Sopenharmony_ci hrz_dev * dev = HRZ_DEV(atm_dev); 25468c2ecf20Sopenharmony_ci PRINTD (DBG_FLOW, "hrz_phy_put"); 25478c2ecf20Sopenharmony_ci} 25488c2ecf20Sopenharmony_ci 25498c2ecf20Sopenharmony_cistatic int hrz_change_qos (struct atm_vcc * atm_vcc, struct atm_qos *qos, int flgs) { 25508c2ecf20Sopenharmony_ci hrz_dev * dev = HRZ_DEV(vcc->dev); 25518c2ecf20Sopenharmony_ci PRINTD (DBG_FLOW, "hrz_change_qos"); 25528c2ecf20Sopenharmony_ci return -1; 25538c2ecf20Sopenharmony_ci} 25548c2ecf20Sopenharmony_ci#endif 25558c2ecf20Sopenharmony_ci 25568c2ecf20Sopenharmony_ci/********** proc file contents **********/ 25578c2ecf20Sopenharmony_ci 25588c2ecf20Sopenharmony_cistatic int hrz_proc_read (struct atm_dev * atm_dev, loff_t * pos, char * page) { 25598c2ecf20Sopenharmony_ci hrz_dev * dev = HRZ_DEV(atm_dev); 25608c2ecf20Sopenharmony_ci int left = *pos; 25618c2ecf20Sopenharmony_ci PRINTD (DBG_FLOW, "hrz_proc_read"); 25628c2ecf20Sopenharmony_ci 25638c2ecf20Sopenharmony_ci /* more diagnostics here? */ 25648c2ecf20Sopenharmony_ci 25658c2ecf20Sopenharmony_ci#if 0 25668c2ecf20Sopenharmony_ci if (!left--) { 25678c2ecf20Sopenharmony_ci unsigned int count = sprintf (page, "vbr buckets:"); 25688c2ecf20Sopenharmony_ci unsigned int i; 25698c2ecf20Sopenharmony_ci for (i = 0; i < TX_CHANS; ++i) 25708c2ecf20Sopenharmony_ci count += sprintf (page, " %u/%u", 25718c2ecf20Sopenharmony_ci query_tx_channel_config (dev, i, BUCKET_FULLNESS_ACCESS), 25728c2ecf20Sopenharmony_ci query_tx_channel_config (dev, i, BUCKET_CAPACITY_ACCESS)); 25738c2ecf20Sopenharmony_ci count += sprintf (page+count, ".\n"); 25748c2ecf20Sopenharmony_ci return count; 25758c2ecf20Sopenharmony_ci } 25768c2ecf20Sopenharmony_ci#endif 25778c2ecf20Sopenharmony_ci 25788c2ecf20Sopenharmony_ci if (!left--) 25798c2ecf20Sopenharmony_ci return sprintf (page, 25808c2ecf20Sopenharmony_ci "cells: TX %lu, RX %lu, HEC errors %lu, unassigned %lu.\n", 25818c2ecf20Sopenharmony_ci dev->tx_cell_count, dev->rx_cell_count, 25828c2ecf20Sopenharmony_ci dev->hec_error_count, dev->unassigned_cell_count); 25838c2ecf20Sopenharmony_ci 25848c2ecf20Sopenharmony_ci if (!left--) 25858c2ecf20Sopenharmony_ci return sprintf (page, 25868c2ecf20Sopenharmony_ci "free cell buffers: TX %hu, RX %hu+%hu.\n", 25878c2ecf20Sopenharmony_ci rd_regw (dev, TX_FREE_BUFFER_COUNT_OFF), 25888c2ecf20Sopenharmony_ci rd_regw (dev, RX_FREE_BUFFER_COUNT_OFF), 25898c2ecf20Sopenharmony_ci dev->noof_spare_buffers); 25908c2ecf20Sopenharmony_ci 25918c2ecf20Sopenharmony_ci if (!left--) 25928c2ecf20Sopenharmony_ci return sprintf (page, 25938c2ecf20Sopenharmony_ci "cps remaining: TX %u, RX %u\n", 25948c2ecf20Sopenharmony_ci dev->tx_avail, dev->rx_avail); 25958c2ecf20Sopenharmony_ci 25968c2ecf20Sopenharmony_ci return 0; 25978c2ecf20Sopenharmony_ci} 25988c2ecf20Sopenharmony_ci 25998c2ecf20Sopenharmony_cistatic const struct atmdev_ops hrz_ops = { 26008c2ecf20Sopenharmony_ci .open = hrz_open, 26018c2ecf20Sopenharmony_ci .close = hrz_close, 26028c2ecf20Sopenharmony_ci .send = hrz_send, 26038c2ecf20Sopenharmony_ci .proc_read = hrz_proc_read, 26048c2ecf20Sopenharmony_ci .owner = THIS_MODULE, 26058c2ecf20Sopenharmony_ci}; 26068c2ecf20Sopenharmony_ci 26078c2ecf20Sopenharmony_cistatic int hrz_probe(struct pci_dev *pci_dev, 26088c2ecf20Sopenharmony_ci const struct pci_device_id *pci_ent) 26098c2ecf20Sopenharmony_ci{ 26108c2ecf20Sopenharmony_ci hrz_dev * dev; 26118c2ecf20Sopenharmony_ci int err = 0; 26128c2ecf20Sopenharmony_ci 26138c2ecf20Sopenharmony_ci // adapter slot free, read resources from PCI configuration space 26148c2ecf20Sopenharmony_ci u32 iobase = pci_resource_start (pci_dev, 0); 26158c2ecf20Sopenharmony_ci u32 * membase = bus_to_virt (pci_resource_start (pci_dev, 1)); 26168c2ecf20Sopenharmony_ci unsigned int irq; 26178c2ecf20Sopenharmony_ci unsigned char lat; 26188c2ecf20Sopenharmony_ci 26198c2ecf20Sopenharmony_ci PRINTD (DBG_FLOW, "hrz_probe"); 26208c2ecf20Sopenharmony_ci 26218c2ecf20Sopenharmony_ci if (pci_enable_device(pci_dev)) 26228c2ecf20Sopenharmony_ci return -EINVAL; 26238c2ecf20Sopenharmony_ci 26248c2ecf20Sopenharmony_ci /* XXX DEV_LABEL is a guess */ 26258c2ecf20Sopenharmony_ci if (!request_region(iobase, HRZ_IO_EXTENT, DEV_LABEL)) { 26268c2ecf20Sopenharmony_ci err = -EINVAL; 26278c2ecf20Sopenharmony_ci goto out_disable; 26288c2ecf20Sopenharmony_ci } 26298c2ecf20Sopenharmony_ci 26308c2ecf20Sopenharmony_ci dev = kzalloc(sizeof(hrz_dev), GFP_KERNEL); 26318c2ecf20Sopenharmony_ci if (!dev) { 26328c2ecf20Sopenharmony_ci // perhaps we should be nice: deregister all adapters and abort? 26338c2ecf20Sopenharmony_ci PRINTD(DBG_ERR, "out of memory"); 26348c2ecf20Sopenharmony_ci err = -ENOMEM; 26358c2ecf20Sopenharmony_ci goto out_release; 26368c2ecf20Sopenharmony_ci } 26378c2ecf20Sopenharmony_ci 26388c2ecf20Sopenharmony_ci pci_set_drvdata(pci_dev, dev); 26398c2ecf20Sopenharmony_ci 26408c2ecf20Sopenharmony_ci // grab IRQ and install handler - move this someplace more sensible 26418c2ecf20Sopenharmony_ci irq = pci_dev->irq; 26428c2ecf20Sopenharmony_ci if (request_irq(irq, 26438c2ecf20Sopenharmony_ci interrupt_handler, 26448c2ecf20Sopenharmony_ci IRQF_SHARED, /* irqflags guess */ 26458c2ecf20Sopenharmony_ci DEV_LABEL, /* name guess */ 26468c2ecf20Sopenharmony_ci dev)) { 26478c2ecf20Sopenharmony_ci PRINTD(DBG_WARN, "request IRQ failed!"); 26488c2ecf20Sopenharmony_ci err = -EINVAL; 26498c2ecf20Sopenharmony_ci goto out_free; 26508c2ecf20Sopenharmony_ci } 26518c2ecf20Sopenharmony_ci 26528c2ecf20Sopenharmony_ci PRINTD(DBG_INFO, "found Madge ATM adapter (hrz) at: IO %x, IRQ %u, MEM %p", 26538c2ecf20Sopenharmony_ci iobase, irq, membase); 26548c2ecf20Sopenharmony_ci 26558c2ecf20Sopenharmony_ci dev->atm_dev = atm_dev_register(DEV_LABEL, &pci_dev->dev, &hrz_ops, -1, 26568c2ecf20Sopenharmony_ci NULL); 26578c2ecf20Sopenharmony_ci if (!(dev->atm_dev)) { 26588c2ecf20Sopenharmony_ci PRINTD(DBG_ERR, "failed to register Madge ATM adapter"); 26598c2ecf20Sopenharmony_ci err = -EINVAL; 26608c2ecf20Sopenharmony_ci goto out_free_irq; 26618c2ecf20Sopenharmony_ci } 26628c2ecf20Sopenharmony_ci 26638c2ecf20Sopenharmony_ci PRINTD(DBG_INFO, "registered Madge ATM adapter (no. %d) (%p) at %p", 26648c2ecf20Sopenharmony_ci dev->atm_dev->number, dev, dev->atm_dev); 26658c2ecf20Sopenharmony_ci dev->atm_dev->dev_data = (void *) dev; 26668c2ecf20Sopenharmony_ci dev->pci_dev = pci_dev; 26678c2ecf20Sopenharmony_ci 26688c2ecf20Sopenharmony_ci // enable bus master accesses 26698c2ecf20Sopenharmony_ci pci_set_master(pci_dev); 26708c2ecf20Sopenharmony_ci 26718c2ecf20Sopenharmony_ci // frobnicate latency (upwards, usually) 26728c2ecf20Sopenharmony_ci pci_read_config_byte(pci_dev, PCI_LATENCY_TIMER, &lat); 26738c2ecf20Sopenharmony_ci if (pci_lat) { 26748c2ecf20Sopenharmony_ci PRINTD(DBG_INFO, "%s PCI latency timer from %hu to %hu", 26758c2ecf20Sopenharmony_ci "changing", lat, pci_lat); 26768c2ecf20Sopenharmony_ci pci_write_config_byte(pci_dev, PCI_LATENCY_TIMER, pci_lat); 26778c2ecf20Sopenharmony_ci } else if (lat < MIN_PCI_LATENCY) { 26788c2ecf20Sopenharmony_ci PRINTK(KERN_INFO, "%s PCI latency timer from %hu to %hu", 26798c2ecf20Sopenharmony_ci "increasing", lat, MIN_PCI_LATENCY); 26808c2ecf20Sopenharmony_ci pci_write_config_byte(pci_dev, PCI_LATENCY_TIMER, MIN_PCI_LATENCY); 26818c2ecf20Sopenharmony_ci } 26828c2ecf20Sopenharmony_ci 26838c2ecf20Sopenharmony_ci dev->iobase = iobase; 26848c2ecf20Sopenharmony_ci dev->irq = irq; 26858c2ecf20Sopenharmony_ci dev->membase = membase; 26868c2ecf20Sopenharmony_ci 26878c2ecf20Sopenharmony_ci dev->rx_q_entry = dev->rx_q_reset = &memmap->rx_q_entries[0]; 26888c2ecf20Sopenharmony_ci dev->rx_q_wrap = &memmap->rx_q_entries[RX_CHANS-1]; 26898c2ecf20Sopenharmony_ci 26908c2ecf20Sopenharmony_ci // these next three are performance hacks 26918c2ecf20Sopenharmony_ci dev->last_vc = -1; 26928c2ecf20Sopenharmony_ci dev->tx_last = -1; 26938c2ecf20Sopenharmony_ci dev->tx_idle = 0; 26948c2ecf20Sopenharmony_ci 26958c2ecf20Sopenharmony_ci dev->tx_regions = 0; 26968c2ecf20Sopenharmony_ci dev->tx_bytes = 0; 26978c2ecf20Sopenharmony_ci dev->tx_skb = NULL; 26988c2ecf20Sopenharmony_ci dev->tx_iovec = NULL; 26998c2ecf20Sopenharmony_ci 27008c2ecf20Sopenharmony_ci dev->tx_cell_count = 0; 27018c2ecf20Sopenharmony_ci dev->rx_cell_count = 0; 27028c2ecf20Sopenharmony_ci dev->hec_error_count = 0; 27038c2ecf20Sopenharmony_ci dev->unassigned_cell_count = 0; 27048c2ecf20Sopenharmony_ci 27058c2ecf20Sopenharmony_ci dev->noof_spare_buffers = 0; 27068c2ecf20Sopenharmony_ci 27078c2ecf20Sopenharmony_ci { 27088c2ecf20Sopenharmony_ci unsigned int i; 27098c2ecf20Sopenharmony_ci for (i = 0; i < TX_CHANS; ++i) 27108c2ecf20Sopenharmony_ci dev->tx_channel_record[i] = -1; 27118c2ecf20Sopenharmony_ci } 27128c2ecf20Sopenharmony_ci 27138c2ecf20Sopenharmony_ci dev->flags = 0; 27148c2ecf20Sopenharmony_ci 27158c2ecf20Sopenharmony_ci // Allocate cell rates and remember ASIC version 27168c2ecf20Sopenharmony_ci // Fibre: ATM_OC3_PCR = 1555200000/8/270*260/53 - 29/53 27178c2ecf20Sopenharmony_ci // Copper: (WRONG) we want 6 into the above, close to 25Mb/s 27188c2ecf20Sopenharmony_ci // Copper: (plagarise!) 25600000/8/270*260/53 - n/53 27198c2ecf20Sopenharmony_ci 27208c2ecf20Sopenharmony_ci if (hrz_init(dev)) { 27218c2ecf20Sopenharmony_ci // to be really pedantic, this should be ATM_OC3c_PCR 27228c2ecf20Sopenharmony_ci dev->tx_avail = ATM_OC3_PCR; 27238c2ecf20Sopenharmony_ci dev->rx_avail = ATM_OC3_PCR; 27248c2ecf20Sopenharmony_ci set_bit(ultra, &dev->flags); // NOT "|= ultra" ! 27258c2ecf20Sopenharmony_ci } else { 27268c2ecf20Sopenharmony_ci dev->tx_avail = ((25600000/8)*26)/(27*53); 27278c2ecf20Sopenharmony_ci dev->rx_avail = ((25600000/8)*26)/(27*53); 27288c2ecf20Sopenharmony_ci PRINTD(DBG_WARN, "Buggy ASIC: no TX bus-mastering."); 27298c2ecf20Sopenharmony_ci } 27308c2ecf20Sopenharmony_ci 27318c2ecf20Sopenharmony_ci // rate changes spinlock 27328c2ecf20Sopenharmony_ci spin_lock_init(&dev->rate_lock); 27338c2ecf20Sopenharmony_ci 27348c2ecf20Sopenharmony_ci // on-board memory access spinlock; we want atomic reads and 27358c2ecf20Sopenharmony_ci // writes to adapter memory (handles IRQ and SMP) 27368c2ecf20Sopenharmony_ci spin_lock_init(&dev->mem_lock); 27378c2ecf20Sopenharmony_ci 27388c2ecf20Sopenharmony_ci init_waitqueue_head(&dev->tx_queue); 27398c2ecf20Sopenharmony_ci 27408c2ecf20Sopenharmony_ci // vpi in 0..4, vci in 6..10 27418c2ecf20Sopenharmony_ci dev->atm_dev->ci_range.vpi_bits = vpi_bits; 27428c2ecf20Sopenharmony_ci dev->atm_dev->ci_range.vci_bits = 10-vpi_bits; 27438c2ecf20Sopenharmony_ci 27448c2ecf20Sopenharmony_ci timer_setup(&dev->housekeeping, do_housekeeping, 0); 27458c2ecf20Sopenharmony_ci mod_timer(&dev->housekeeping, jiffies); 27468c2ecf20Sopenharmony_ci 27478c2ecf20Sopenharmony_ciout: 27488c2ecf20Sopenharmony_ci return err; 27498c2ecf20Sopenharmony_ci 27508c2ecf20Sopenharmony_ciout_free_irq: 27518c2ecf20Sopenharmony_ci free_irq(irq, dev); 27528c2ecf20Sopenharmony_ciout_free: 27538c2ecf20Sopenharmony_ci kfree(dev); 27548c2ecf20Sopenharmony_ciout_release: 27558c2ecf20Sopenharmony_ci release_region(iobase, HRZ_IO_EXTENT); 27568c2ecf20Sopenharmony_ciout_disable: 27578c2ecf20Sopenharmony_ci pci_disable_device(pci_dev); 27588c2ecf20Sopenharmony_ci goto out; 27598c2ecf20Sopenharmony_ci} 27608c2ecf20Sopenharmony_ci 27618c2ecf20Sopenharmony_cistatic void hrz_remove_one(struct pci_dev *pci_dev) 27628c2ecf20Sopenharmony_ci{ 27638c2ecf20Sopenharmony_ci hrz_dev *dev; 27648c2ecf20Sopenharmony_ci 27658c2ecf20Sopenharmony_ci dev = pci_get_drvdata(pci_dev); 27668c2ecf20Sopenharmony_ci 27678c2ecf20Sopenharmony_ci PRINTD(DBG_INFO, "closing %p (atm_dev = %p)", dev, dev->atm_dev); 27688c2ecf20Sopenharmony_ci del_timer_sync(&dev->housekeeping); 27698c2ecf20Sopenharmony_ci hrz_reset(dev); 27708c2ecf20Sopenharmony_ci atm_dev_deregister(dev->atm_dev); 27718c2ecf20Sopenharmony_ci free_irq(dev->irq, dev); 27728c2ecf20Sopenharmony_ci release_region(dev->iobase, HRZ_IO_EXTENT); 27738c2ecf20Sopenharmony_ci kfree(dev); 27748c2ecf20Sopenharmony_ci 27758c2ecf20Sopenharmony_ci pci_disable_device(pci_dev); 27768c2ecf20Sopenharmony_ci} 27778c2ecf20Sopenharmony_ci 27788c2ecf20Sopenharmony_cistatic void __init hrz_check_args (void) { 27798c2ecf20Sopenharmony_ci#ifdef DEBUG_HORIZON 27808c2ecf20Sopenharmony_ci PRINTK (KERN_NOTICE, "debug bitmap is %hx", debug &= DBG_MASK); 27818c2ecf20Sopenharmony_ci#else 27828c2ecf20Sopenharmony_ci if (debug) 27838c2ecf20Sopenharmony_ci PRINTK (KERN_NOTICE, "no debug support in this image"); 27848c2ecf20Sopenharmony_ci#endif 27858c2ecf20Sopenharmony_ci 27868c2ecf20Sopenharmony_ci if (vpi_bits > HRZ_MAX_VPI) 27878c2ecf20Sopenharmony_ci PRINTK (KERN_ERR, "vpi_bits has been limited to %hu", 27888c2ecf20Sopenharmony_ci vpi_bits = HRZ_MAX_VPI); 27898c2ecf20Sopenharmony_ci 27908c2ecf20Sopenharmony_ci if (max_tx_size < 0 || max_tx_size > TX_AAL5_LIMIT) 27918c2ecf20Sopenharmony_ci PRINTK (KERN_NOTICE, "max_tx_size has been limited to %hu", 27928c2ecf20Sopenharmony_ci max_tx_size = TX_AAL5_LIMIT); 27938c2ecf20Sopenharmony_ci 27948c2ecf20Sopenharmony_ci if (max_rx_size < 0 || max_rx_size > RX_AAL5_LIMIT) 27958c2ecf20Sopenharmony_ci PRINTK (KERN_NOTICE, "max_rx_size has been limited to %hu", 27968c2ecf20Sopenharmony_ci max_rx_size = RX_AAL5_LIMIT); 27978c2ecf20Sopenharmony_ci 27988c2ecf20Sopenharmony_ci return; 27998c2ecf20Sopenharmony_ci} 28008c2ecf20Sopenharmony_ci 28018c2ecf20Sopenharmony_ciMODULE_AUTHOR(maintainer_string); 28028c2ecf20Sopenharmony_ciMODULE_DESCRIPTION(description_string); 28038c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 28048c2ecf20Sopenharmony_cimodule_param(debug, ushort, 0644); 28058c2ecf20Sopenharmony_cimodule_param(vpi_bits, ushort, 0); 28068c2ecf20Sopenharmony_cimodule_param(max_tx_size, int, 0); 28078c2ecf20Sopenharmony_cimodule_param(max_rx_size, int, 0); 28088c2ecf20Sopenharmony_cimodule_param(pci_lat, byte, 0); 28098c2ecf20Sopenharmony_ciMODULE_PARM_DESC(debug, "debug bitmap, see .h file"); 28108c2ecf20Sopenharmony_ciMODULE_PARM_DESC(vpi_bits, "number of bits (0..4) to allocate to VPIs"); 28118c2ecf20Sopenharmony_ciMODULE_PARM_DESC(max_tx_size, "maximum size of TX AAL5 frames"); 28128c2ecf20Sopenharmony_ciMODULE_PARM_DESC(max_rx_size, "maximum size of RX AAL5 frames"); 28138c2ecf20Sopenharmony_ciMODULE_PARM_DESC(pci_lat, "PCI latency in bus cycles"); 28148c2ecf20Sopenharmony_ci 28158c2ecf20Sopenharmony_cistatic const struct pci_device_id hrz_pci_tbl[] = { 28168c2ecf20Sopenharmony_ci { PCI_VENDOR_ID_MADGE, PCI_DEVICE_ID_MADGE_HORIZON, PCI_ANY_ID, PCI_ANY_ID, 28178c2ecf20Sopenharmony_ci 0, 0, 0 }, 28188c2ecf20Sopenharmony_ci { 0, } 28198c2ecf20Sopenharmony_ci}; 28208c2ecf20Sopenharmony_ci 28218c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(pci, hrz_pci_tbl); 28228c2ecf20Sopenharmony_ci 28238c2ecf20Sopenharmony_cistatic struct pci_driver hrz_driver = { 28248c2ecf20Sopenharmony_ci .name = "horizon", 28258c2ecf20Sopenharmony_ci .probe = hrz_probe, 28268c2ecf20Sopenharmony_ci .remove = hrz_remove_one, 28278c2ecf20Sopenharmony_ci .id_table = hrz_pci_tbl, 28288c2ecf20Sopenharmony_ci}; 28298c2ecf20Sopenharmony_ci 28308c2ecf20Sopenharmony_ci/********** module entry **********/ 28318c2ecf20Sopenharmony_ci 28328c2ecf20Sopenharmony_cistatic int __init hrz_module_init (void) { 28338c2ecf20Sopenharmony_ci BUILD_BUG_ON(sizeof(struct MEMMAP) != 128*1024/4); 28348c2ecf20Sopenharmony_ci 28358c2ecf20Sopenharmony_ci show_version(); 28368c2ecf20Sopenharmony_ci 28378c2ecf20Sopenharmony_ci // check arguments 28388c2ecf20Sopenharmony_ci hrz_check_args(); 28398c2ecf20Sopenharmony_ci 28408c2ecf20Sopenharmony_ci // get the juice 28418c2ecf20Sopenharmony_ci return pci_register_driver(&hrz_driver); 28428c2ecf20Sopenharmony_ci} 28438c2ecf20Sopenharmony_ci 28448c2ecf20Sopenharmony_ci/********** module exit **********/ 28458c2ecf20Sopenharmony_ci 28468c2ecf20Sopenharmony_cistatic void __exit hrz_module_exit (void) { 28478c2ecf20Sopenharmony_ci PRINTD (DBG_FLOW, "cleanup_module"); 28488c2ecf20Sopenharmony_ci 28498c2ecf20Sopenharmony_ci pci_unregister_driver(&hrz_driver); 28508c2ecf20Sopenharmony_ci} 28518c2ecf20Sopenharmony_ci 28528c2ecf20Sopenharmony_cimodule_init(hrz_module_init); 28538c2ecf20Sopenharmony_cimodule_exit(hrz_module_exit); 2854