11da177e4SLinus Torvalds /******************************************************************* 21da177e4SLinus Torvalds * ident "$Id: idt77252.c,v 1.2 2001/11/11 08:13:54 ecd Exp $" 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * $Author: ecd $ 51da177e4SLinus Torvalds * $Date: 2001/11/11 08:13:54 $ 61da177e4SLinus Torvalds * 71da177e4SLinus Torvalds * Copyright (c) 2000 ATecoM GmbH 81da177e4SLinus Torvalds * 91da177e4SLinus Torvalds * The author may be reached at ecd@atecom.com. 101da177e4SLinus Torvalds * 111da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify it 121da177e4SLinus Torvalds * under the terms of the GNU General Public License as published by the 131da177e4SLinus Torvalds * Free Software Foundation; either version 2 of the License, or (at your 141da177e4SLinus Torvalds * option) any later version. 151da177e4SLinus Torvalds * 161da177e4SLinus Torvalds * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 171da177e4SLinus Torvalds * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 181da177e4SLinus Torvalds * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 191da177e4SLinus Torvalds * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 201da177e4SLinus Torvalds * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 211da177e4SLinus Torvalds * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 221da177e4SLinus Torvalds * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 231da177e4SLinus Torvalds * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 241da177e4SLinus Torvalds * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 251da177e4SLinus Torvalds * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 261da177e4SLinus Torvalds * 271da177e4SLinus Torvalds * You should have received a copy of the GNU General Public License along 281da177e4SLinus Torvalds * with this program; if not, write to the Free Software Foundation, Inc., 291da177e4SLinus Torvalds * 675 Mass Ave, Cambridge, MA 02139, USA. 301da177e4SLinus Torvalds * 311da177e4SLinus Torvalds *******************************************************************/ 321da177e4SLinus Torvalds static char const rcsid[] = 331da177e4SLinus Torvalds "$Id: idt77252.c,v 1.2 2001/11/11 08:13:54 ecd Exp $"; 341da177e4SLinus Torvalds 351da177e4SLinus Torvalds 361da177e4SLinus Torvalds #include <linux/module.h> 371da177e4SLinus Torvalds #include <linux/pci.h> 383c6b3773SRandy Dunlap #include <linux/poison.h> 391da177e4SLinus Torvalds #include <linux/skbuff.h> 401da177e4SLinus Torvalds #include <linux/kernel.h> 411da177e4SLinus Torvalds #include <linux/vmalloc.h> 421da177e4SLinus Torvalds #include <linux/netdevice.h> 431da177e4SLinus Torvalds #include <linux/atmdev.h> 441da177e4SLinus Torvalds #include <linux/atm.h> 451da177e4SLinus Torvalds #include <linux/delay.h> 461da177e4SLinus Torvalds #include <linux/init.h> 471da177e4SLinus Torvalds #include <linux/bitops.h> 481da177e4SLinus Torvalds #include <linux/wait.h> 49e1bd232bSMarcelo Feitoza Parisi #include <linux/jiffies.h> 501da177e4SLinus Torvalds #include <asm/semaphore.h> 511da177e4SLinus Torvalds #include <asm/io.h> 521da177e4SLinus Torvalds #include <asm/uaccess.h> 531da177e4SLinus Torvalds #include <asm/atomic.h> 541da177e4SLinus Torvalds #include <asm/byteorder.h> 551da177e4SLinus Torvalds 561da177e4SLinus Torvalds #ifdef CONFIG_ATM_IDT77252_USE_SUNI 571da177e4SLinus Torvalds #include "suni.h" 581da177e4SLinus Torvalds #endif /* CONFIG_ATM_IDT77252_USE_SUNI */ 591da177e4SLinus Torvalds 601da177e4SLinus Torvalds 611da177e4SLinus Torvalds #include "idt77252.h" 621da177e4SLinus Torvalds #include "idt77252_tables.h" 631da177e4SLinus Torvalds 641da177e4SLinus Torvalds static unsigned int vpibits = 1; 651da177e4SLinus Torvalds 661da177e4SLinus Torvalds 671da177e4SLinus Torvalds #define CONFIG_ATM_IDT77252_SEND_IDLE 1 681da177e4SLinus Torvalds 691da177e4SLinus Torvalds 701da177e4SLinus Torvalds /* 711da177e4SLinus Torvalds * Debug HACKs. 721da177e4SLinus Torvalds */ 731da177e4SLinus Torvalds #define DEBUG_MODULE 1 741da177e4SLinus Torvalds #undef HAVE_EEPROM /* does not work, yet. */ 751da177e4SLinus Torvalds 761da177e4SLinus Torvalds #ifdef CONFIG_ATM_IDT77252_DEBUG 771da177e4SLinus Torvalds static unsigned long debug = DBG_GENERAL; 781da177e4SLinus Torvalds #endif 791da177e4SLinus Torvalds 801da177e4SLinus Torvalds 811da177e4SLinus Torvalds #define SAR_RX_DELAY (SAR_CFG_RXINT_NODELAY) 821da177e4SLinus Torvalds 831da177e4SLinus Torvalds 841da177e4SLinus Torvalds /* 851da177e4SLinus Torvalds * SCQ Handling. 861da177e4SLinus Torvalds */ 871da177e4SLinus Torvalds static struct scq_info *alloc_scq(struct idt77252_dev *, int); 881da177e4SLinus Torvalds static void free_scq(struct idt77252_dev *, struct scq_info *); 891da177e4SLinus Torvalds static int queue_skb(struct idt77252_dev *, struct vc_map *, 901da177e4SLinus Torvalds struct sk_buff *, int oam); 911da177e4SLinus Torvalds static void drain_scq(struct idt77252_dev *, struct vc_map *); 921da177e4SLinus Torvalds static unsigned long get_free_scd(struct idt77252_dev *, struct vc_map *); 931da177e4SLinus Torvalds static void fill_scd(struct idt77252_dev *, struct scq_info *, int); 941da177e4SLinus Torvalds 951da177e4SLinus Torvalds /* 961da177e4SLinus Torvalds * FBQ Handling. 971da177e4SLinus Torvalds */ 981da177e4SLinus Torvalds static int push_rx_skb(struct idt77252_dev *, 991da177e4SLinus Torvalds struct sk_buff *, int queue); 1001da177e4SLinus Torvalds static void recycle_rx_skb(struct idt77252_dev *, struct sk_buff *); 1011da177e4SLinus Torvalds static void flush_rx_pool(struct idt77252_dev *, struct rx_pool *); 1021da177e4SLinus Torvalds static void recycle_rx_pool_skb(struct idt77252_dev *, 1031da177e4SLinus Torvalds struct rx_pool *); 1041da177e4SLinus Torvalds static void add_rx_skb(struct idt77252_dev *, int queue, 1051da177e4SLinus Torvalds unsigned int size, unsigned int count); 1061da177e4SLinus Torvalds 1071da177e4SLinus Torvalds /* 1081da177e4SLinus Torvalds * RSQ Handling. 1091da177e4SLinus Torvalds */ 1101da177e4SLinus Torvalds static int init_rsq(struct idt77252_dev *); 1111da177e4SLinus Torvalds static void deinit_rsq(struct idt77252_dev *); 1121da177e4SLinus Torvalds static void idt77252_rx(struct idt77252_dev *); 1131da177e4SLinus Torvalds 1141da177e4SLinus Torvalds /* 1151da177e4SLinus Torvalds * TSQ handling. 1161da177e4SLinus Torvalds */ 1171da177e4SLinus Torvalds static int init_tsq(struct idt77252_dev *); 1181da177e4SLinus Torvalds static void deinit_tsq(struct idt77252_dev *); 1191da177e4SLinus Torvalds static void idt77252_tx(struct idt77252_dev *); 1201da177e4SLinus Torvalds 1211da177e4SLinus Torvalds 1221da177e4SLinus Torvalds /* 1231da177e4SLinus Torvalds * ATM Interface. 1241da177e4SLinus Torvalds */ 1251da177e4SLinus Torvalds static void idt77252_dev_close(struct atm_dev *dev); 1261da177e4SLinus Torvalds static int idt77252_open(struct atm_vcc *vcc); 1271da177e4SLinus Torvalds static void idt77252_close(struct atm_vcc *vcc); 1281da177e4SLinus Torvalds static int idt77252_send(struct atm_vcc *vcc, struct sk_buff *skb); 1291da177e4SLinus Torvalds static int idt77252_send_oam(struct atm_vcc *vcc, void *cell, 1301da177e4SLinus Torvalds int flags); 1311da177e4SLinus Torvalds static void idt77252_phy_put(struct atm_dev *dev, unsigned char value, 1321da177e4SLinus Torvalds unsigned long addr); 1331da177e4SLinus Torvalds static unsigned char idt77252_phy_get(struct atm_dev *dev, unsigned long addr); 1341da177e4SLinus Torvalds static int idt77252_change_qos(struct atm_vcc *vcc, struct atm_qos *qos, 1351da177e4SLinus Torvalds int flags); 1361da177e4SLinus Torvalds static int idt77252_proc_read(struct atm_dev *dev, loff_t * pos, 1371da177e4SLinus Torvalds char *page); 1381da177e4SLinus Torvalds static void idt77252_softint(void *dev_id); 1391da177e4SLinus Torvalds 1401da177e4SLinus Torvalds 1411da177e4SLinus Torvalds static struct atmdev_ops idt77252_ops = 1421da177e4SLinus Torvalds { 1431da177e4SLinus Torvalds .dev_close = idt77252_dev_close, 1441da177e4SLinus Torvalds .open = idt77252_open, 1451da177e4SLinus Torvalds .close = idt77252_close, 1461da177e4SLinus Torvalds .send = idt77252_send, 1471da177e4SLinus Torvalds .send_oam = idt77252_send_oam, 1481da177e4SLinus Torvalds .phy_put = idt77252_phy_put, 1491da177e4SLinus Torvalds .phy_get = idt77252_phy_get, 1501da177e4SLinus Torvalds .change_qos = idt77252_change_qos, 1511da177e4SLinus Torvalds .proc_read = idt77252_proc_read, 1521da177e4SLinus Torvalds .owner = THIS_MODULE 1531da177e4SLinus Torvalds }; 1541da177e4SLinus Torvalds 1551da177e4SLinus Torvalds static struct idt77252_dev *idt77252_chain = NULL; 1561da177e4SLinus Torvalds static unsigned int idt77252_sram_write_errors = 0; 1571da177e4SLinus Torvalds 1581da177e4SLinus Torvalds /*****************************************************************************/ 1591da177e4SLinus Torvalds /* */ 1601da177e4SLinus Torvalds /* I/O and Utility Bus */ 1611da177e4SLinus Torvalds /* */ 1621da177e4SLinus Torvalds /*****************************************************************************/ 1631da177e4SLinus Torvalds 1641da177e4SLinus Torvalds static void 1651da177e4SLinus Torvalds waitfor_idle(struct idt77252_dev *card) 1661da177e4SLinus Torvalds { 1671da177e4SLinus Torvalds u32 stat; 1681da177e4SLinus Torvalds 1691da177e4SLinus Torvalds stat = readl(SAR_REG_STAT); 1701da177e4SLinus Torvalds while (stat & SAR_STAT_CMDBZ) 1711da177e4SLinus Torvalds stat = readl(SAR_REG_STAT); 1721da177e4SLinus Torvalds } 1731da177e4SLinus Torvalds 1741da177e4SLinus Torvalds static u32 1751da177e4SLinus Torvalds read_sram(struct idt77252_dev *card, unsigned long addr) 1761da177e4SLinus Torvalds { 1771da177e4SLinus Torvalds unsigned long flags; 1781da177e4SLinus Torvalds u32 value; 1791da177e4SLinus Torvalds 1801da177e4SLinus Torvalds spin_lock_irqsave(&card->cmd_lock, flags); 1811da177e4SLinus Torvalds writel(SAR_CMD_READ_SRAM | (addr << 2), SAR_REG_CMD); 1821da177e4SLinus Torvalds waitfor_idle(card); 1831da177e4SLinus Torvalds value = readl(SAR_REG_DR0); 1841da177e4SLinus Torvalds spin_unlock_irqrestore(&card->cmd_lock, flags); 1851da177e4SLinus Torvalds return value; 1861da177e4SLinus Torvalds } 1871da177e4SLinus Torvalds 1881da177e4SLinus Torvalds static void 1891da177e4SLinus Torvalds write_sram(struct idt77252_dev *card, unsigned long addr, u32 value) 1901da177e4SLinus Torvalds { 1911da177e4SLinus Torvalds unsigned long flags; 1921da177e4SLinus Torvalds 1931da177e4SLinus Torvalds if ((idt77252_sram_write_errors == 0) && 1941da177e4SLinus Torvalds (((addr > card->tst[0] + card->tst_size - 2) && 1951da177e4SLinus Torvalds (addr < card->tst[0] + card->tst_size)) || 1961da177e4SLinus Torvalds ((addr > card->tst[1] + card->tst_size - 2) && 1971da177e4SLinus Torvalds (addr < card->tst[1] + card->tst_size)))) { 1981da177e4SLinus Torvalds printk("%s: ERROR: TST JMP section at %08lx written: %08x\n", 1991da177e4SLinus Torvalds card->name, addr, value); 2001da177e4SLinus Torvalds } 2011da177e4SLinus Torvalds 2021da177e4SLinus Torvalds spin_lock_irqsave(&card->cmd_lock, flags); 2031da177e4SLinus Torvalds writel(value, SAR_REG_DR0); 2041da177e4SLinus Torvalds writel(SAR_CMD_WRITE_SRAM | (addr << 2), SAR_REG_CMD); 2051da177e4SLinus Torvalds waitfor_idle(card); 2061da177e4SLinus Torvalds spin_unlock_irqrestore(&card->cmd_lock, flags); 2071da177e4SLinus Torvalds } 2081da177e4SLinus Torvalds 2091da177e4SLinus Torvalds static u8 2101da177e4SLinus Torvalds read_utility(void *dev, unsigned long ubus_addr) 2111da177e4SLinus Torvalds { 2121da177e4SLinus Torvalds struct idt77252_dev *card = dev; 2131da177e4SLinus Torvalds unsigned long flags; 2141da177e4SLinus Torvalds u8 value; 2151da177e4SLinus Torvalds 2161da177e4SLinus Torvalds if (!card) { 2171da177e4SLinus Torvalds printk("Error: No such device.\n"); 2181da177e4SLinus Torvalds return -1; 2191da177e4SLinus Torvalds } 2201da177e4SLinus Torvalds 2211da177e4SLinus Torvalds spin_lock_irqsave(&card->cmd_lock, flags); 2221da177e4SLinus Torvalds writel(SAR_CMD_READ_UTILITY + ubus_addr, SAR_REG_CMD); 2231da177e4SLinus Torvalds waitfor_idle(card); 2241da177e4SLinus Torvalds value = readl(SAR_REG_DR0); 2251da177e4SLinus Torvalds spin_unlock_irqrestore(&card->cmd_lock, flags); 2261da177e4SLinus Torvalds return value; 2271da177e4SLinus Torvalds } 2281da177e4SLinus Torvalds 2291da177e4SLinus Torvalds static void 2301da177e4SLinus Torvalds write_utility(void *dev, unsigned long ubus_addr, u8 value) 2311da177e4SLinus Torvalds { 2321da177e4SLinus Torvalds struct idt77252_dev *card = dev; 2331da177e4SLinus Torvalds unsigned long flags; 2341da177e4SLinus Torvalds 2351da177e4SLinus Torvalds if (!card) { 2361da177e4SLinus Torvalds printk("Error: No such device.\n"); 2371da177e4SLinus Torvalds return; 2381da177e4SLinus Torvalds } 2391da177e4SLinus Torvalds 2401da177e4SLinus Torvalds spin_lock_irqsave(&card->cmd_lock, flags); 2411da177e4SLinus Torvalds writel((u32) value, SAR_REG_DR0); 2421da177e4SLinus Torvalds writel(SAR_CMD_WRITE_UTILITY + ubus_addr, SAR_REG_CMD); 2431da177e4SLinus Torvalds waitfor_idle(card); 2441da177e4SLinus Torvalds spin_unlock_irqrestore(&card->cmd_lock, flags); 2451da177e4SLinus Torvalds } 2461da177e4SLinus Torvalds 2471da177e4SLinus Torvalds #ifdef HAVE_EEPROM 2481da177e4SLinus Torvalds static u32 rdsrtab[] = 2491da177e4SLinus Torvalds { 2501da177e4SLinus Torvalds SAR_GP_EECS | SAR_GP_EESCLK, 2511da177e4SLinus Torvalds 0, 2521da177e4SLinus Torvalds SAR_GP_EESCLK, /* 0 */ 2531da177e4SLinus Torvalds 0, 2541da177e4SLinus Torvalds SAR_GP_EESCLK, /* 0 */ 2551da177e4SLinus Torvalds 0, 2561da177e4SLinus Torvalds SAR_GP_EESCLK, /* 0 */ 2571da177e4SLinus Torvalds 0, 2581da177e4SLinus Torvalds SAR_GP_EESCLK, /* 0 */ 2591da177e4SLinus Torvalds 0, 2601da177e4SLinus Torvalds SAR_GP_EESCLK, /* 0 */ 2611da177e4SLinus Torvalds SAR_GP_EEDO, 2621da177e4SLinus Torvalds SAR_GP_EESCLK | SAR_GP_EEDO, /* 1 */ 2631da177e4SLinus Torvalds 0, 2641da177e4SLinus Torvalds SAR_GP_EESCLK, /* 0 */ 2651da177e4SLinus Torvalds SAR_GP_EEDO, 2661da177e4SLinus Torvalds SAR_GP_EESCLK | SAR_GP_EEDO /* 1 */ 2671da177e4SLinus Torvalds }; 2681da177e4SLinus Torvalds 2691da177e4SLinus Torvalds static u32 wrentab[] = 2701da177e4SLinus Torvalds { 2711da177e4SLinus Torvalds SAR_GP_EECS | SAR_GP_EESCLK, 2721da177e4SLinus Torvalds 0, 2731da177e4SLinus Torvalds SAR_GP_EESCLK, /* 0 */ 2741da177e4SLinus Torvalds 0, 2751da177e4SLinus Torvalds SAR_GP_EESCLK, /* 0 */ 2761da177e4SLinus Torvalds 0, 2771da177e4SLinus Torvalds SAR_GP_EESCLK, /* 0 */ 2781da177e4SLinus Torvalds 0, 2791da177e4SLinus Torvalds SAR_GP_EESCLK, /* 0 */ 2801da177e4SLinus Torvalds SAR_GP_EEDO, 2811da177e4SLinus Torvalds SAR_GP_EESCLK | SAR_GP_EEDO, /* 1 */ 2821da177e4SLinus Torvalds SAR_GP_EEDO, 2831da177e4SLinus Torvalds SAR_GP_EESCLK | SAR_GP_EEDO, /* 1 */ 2841da177e4SLinus Torvalds 0, 2851da177e4SLinus Torvalds SAR_GP_EESCLK, /* 0 */ 2861da177e4SLinus Torvalds 0, 2871da177e4SLinus Torvalds SAR_GP_EESCLK /* 0 */ 2881da177e4SLinus Torvalds }; 2891da177e4SLinus Torvalds 2901da177e4SLinus Torvalds static u32 rdtab[] = 2911da177e4SLinus Torvalds { 2921da177e4SLinus Torvalds SAR_GP_EECS | SAR_GP_EESCLK, 2931da177e4SLinus Torvalds 0, 2941da177e4SLinus Torvalds SAR_GP_EESCLK, /* 0 */ 2951da177e4SLinus Torvalds 0, 2961da177e4SLinus Torvalds SAR_GP_EESCLK, /* 0 */ 2971da177e4SLinus Torvalds 0, 2981da177e4SLinus Torvalds SAR_GP_EESCLK, /* 0 */ 2991da177e4SLinus Torvalds 0, 3001da177e4SLinus Torvalds SAR_GP_EESCLK, /* 0 */ 3011da177e4SLinus Torvalds 0, 3021da177e4SLinus Torvalds SAR_GP_EESCLK, /* 0 */ 3031da177e4SLinus Torvalds 0, 3041da177e4SLinus Torvalds SAR_GP_EESCLK, /* 0 */ 3051da177e4SLinus Torvalds SAR_GP_EEDO, 3061da177e4SLinus Torvalds SAR_GP_EESCLK | SAR_GP_EEDO, /* 1 */ 3071da177e4SLinus Torvalds SAR_GP_EEDO, 3081da177e4SLinus Torvalds SAR_GP_EESCLK | SAR_GP_EEDO /* 1 */ 3091da177e4SLinus Torvalds }; 3101da177e4SLinus Torvalds 3111da177e4SLinus Torvalds static u32 wrtab[] = 3121da177e4SLinus Torvalds { 3131da177e4SLinus Torvalds SAR_GP_EECS | SAR_GP_EESCLK, 3141da177e4SLinus Torvalds 0, 3151da177e4SLinus Torvalds SAR_GP_EESCLK, /* 0 */ 3161da177e4SLinus Torvalds 0, 3171da177e4SLinus Torvalds SAR_GP_EESCLK, /* 0 */ 3181da177e4SLinus Torvalds 0, 3191da177e4SLinus Torvalds SAR_GP_EESCLK, /* 0 */ 3201da177e4SLinus Torvalds 0, 3211da177e4SLinus Torvalds SAR_GP_EESCLK, /* 0 */ 3221da177e4SLinus Torvalds 0, 3231da177e4SLinus Torvalds SAR_GP_EESCLK, /* 0 */ 3241da177e4SLinus Torvalds 0, 3251da177e4SLinus Torvalds SAR_GP_EESCLK, /* 0 */ 3261da177e4SLinus Torvalds SAR_GP_EEDO, 3271da177e4SLinus Torvalds SAR_GP_EESCLK | SAR_GP_EEDO, /* 1 */ 3281da177e4SLinus Torvalds 0, 3291da177e4SLinus Torvalds SAR_GP_EESCLK /* 0 */ 3301da177e4SLinus Torvalds }; 3311da177e4SLinus Torvalds 3321da177e4SLinus Torvalds static u32 clktab[] = 3331da177e4SLinus Torvalds { 3341da177e4SLinus Torvalds 0, 3351da177e4SLinus Torvalds SAR_GP_EESCLK, 3361da177e4SLinus Torvalds 0, 3371da177e4SLinus Torvalds SAR_GP_EESCLK, 3381da177e4SLinus Torvalds 0, 3391da177e4SLinus Torvalds SAR_GP_EESCLK, 3401da177e4SLinus Torvalds 0, 3411da177e4SLinus Torvalds SAR_GP_EESCLK, 3421da177e4SLinus Torvalds 0, 3431da177e4SLinus Torvalds SAR_GP_EESCLK, 3441da177e4SLinus Torvalds 0, 3451da177e4SLinus Torvalds SAR_GP_EESCLK, 3461da177e4SLinus Torvalds 0, 3471da177e4SLinus Torvalds SAR_GP_EESCLK, 3481da177e4SLinus Torvalds 0, 3491da177e4SLinus Torvalds SAR_GP_EESCLK, 3501da177e4SLinus Torvalds 0 3511da177e4SLinus Torvalds }; 3521da177e4SLinus Torvalds 3531da177e4SLinus Torvalds static u32 3541da177e4SLinus Torvalds idt77252_read_gp(struct idt77252_dev *card) 3551da177e4SLinus Torvalds { 3561da177e4SLinus Torvalds u32 gp; 3571da177e4SLinus Torvalds 3581da177e4SLinus Torvalds gp = readl(SAR_REG_GP); 3591da177e4SLinus Torvalds #if 0 3601da177e4SLinus Torvalds printk("RD: %s\n", gp & SAR_GP_EEDI ? "1" : "0"); 3611da177e4SLinus Torvalds #endif 3621da177e4SLinus Torvalds return gp; 3631da177e4SLinus Torvalds } 3641da177e4SLinus Torvalds 3651da177e4SLinus Torvalds static void 3661da177e4SLinus Torvalds idt77252_write_gp(struct idt77252_dev *card, u32 value) 3671da177e4SLinus Torvalds { 3681da177e4SLinus Torvalds unsigned long flags; 3691da177e4SLinus Torvalds 3701da177e4SLinus Torvalds #if 0 3711da177e4SLinus Torvalds printk("WR: %s %s %s\n", value & SAR_GP_EECS ? " " : "/CS", 3721da177e4SLinus Torvalds value & SAR_GP_EESCLK ? "HIGH" : "LOW ", 3731da177e4SLinus Torvalds value & SAR_GP_EEDO ? "1" : "0"); 3741da177e4SLinus Torvalds #endif 3751da177e4SLinus Torvalds 3761da177e4SLinus Torvalds spin_lock_irqsave(&card->cmd_lock, flags); 3771da177e4SLinus Torvalds waitfor_idle(card); 3781da177e4SLinus Torvalds writel(value, SAR_REG_GP); 3791da177e4SLinus Torvalds spin_unlock_irqrestore(&card->cmd_lock, flags); 3801da177e4SLinus Torvalds } 3811da177e4SLinus Torvalds 3821da177e4SLinus Torvalds static u8 3831da177e4SLinus Torvalds idt77252_eeprom_read_status(struct idt77252_dev *card) 3841da177e4SLinus Torvalds { 3851da177e4SLinus Torvalds u8 byte; 3861da177e4SLinus Torvalds u32 gp; 3871da177e4SLinus Torvalds int i, j; 3881da177e4SLinus Torvalds 3891da177e4SLinus Torvalds gp = idt77252_read_gp(card) & ~(SAR_GP_EESCLK|SAR_GP_EECS|SAR_GP_EEDO); 3901da177e4SLinus Torvalds 3911da177e4SLinus Torvalds for (i = 0; i < sizeof(rdsrtab)/sizeof(rdsrtab[0]); i++) { 3921da177e4SLinus Torvalds idt77252_write_gp(card, gp | rdsrtab[i]); 3931da177e4SLinus Torvalds udelay(5); 3941da177e4SLinus Torvalds } 3951da177e4SLinus Torvalds idt77252_write_gp(card, gp | SAR_GP_EECS); 3961da177e4SLinus Torvalds udelay(5); 3971da177e4SLinus Torvalds 3981da177e4SLinus Torvalds byte = 0; 3991da177e4SLinus Torvalds for (i = 0, j = 0; i < 8; i++) { 4001da177e4SLinus Torvalds byte <<= 1; 4011da177e4SLinus Torvalds 4021da177e4SLinus Torvalds idt77252_write_gp(card, gp | clktab[j++]); 4031da177e4SLinus Torvalds udelay(5); 4041da177e4SLinus Torvalds 4051da177e4SLinus Torvalds byte |= idt77252_read_gp(card) & SAR_GP_EEDI ? 1 : 0; 4061da177e4SLinus Torvalds 4071da177e4SLinus Torvalds idt77252_write_gp(card, gp | clktab[j++]); 4081da177e4SLinus Torvalds udelay(5); 4091da177e4SLinus Torvalds } 4101da177e4SLinus Torvalds idt77252_write_gp(card, gp | SAR_GP_EECS); 4111da177e4SLinus Torvalds udelay(5); 4121da177e4SLinus Torvalds 4131da177e4SLinus Torvalds return byte; 4141da177e4SLinus Torvalds } 4151da177e4SLinus Torvalds 4161da177e4SLinus Torvalds static u8 4171da177e4SLinus Torvalds idt77252_eeprom_read_byte(struct idt77252_dev *card, u8 offset) 4181da177e4SLinus Torvalds { 4191da177e4SLinus Torvalds u8 byte; 4201da177e4SLinus Torvalds u32 gp; 4211da177e4SLinus Torvalds int i, j; 4221da177e4SLinus Torvalds 4231da177e4SLinus Torvalds gp = idt77252_read_gp(card) & ~(SAR_GP_EESCLK|SAR_GP_EECS|SAR_GP_EEDO); 4241da177e4SLinus Torvalds 4251da177e4SLinus Torvalds for (i = 0; i < sizeof(rdtab)/sizeof(rdtab[0]); i++) { 4261da177e4SLinus Torvalds idt77252_write_gp(card, gp | rdtab[i]); 4271da177e4SLinus Torvalds udelay(5); 4281da177e4SLinus Torvalds } 4291da177e4SLinus Torvalds idt77252_write_gp(card, gp | SAR_GP_EECS); 4301da177e4SLinus Torvalds udelay(5); 4311da177e4SLinus Torvalds 4321da177e4SLinus Torvalds for (i = 0, j = 0; i < 8; i++) { 4331da177e4SLinus Torvalds idt77252_write_gp(card, gp | clktab[j++] | 4341da177e4SLinus Torvalds (offset & 1 ? SAR_GP_EEDO : 0)); 4351da177e4SLinus Torvalds udelay(5); 4361da177e4SLinus Torvalds 4371da177e4SLinus Torvalds idt77252_write_gp(card, gp | clktab[j++] | 4381da177e4SLinus Torvalds (offset & 1 ? SAR_GP_EEDO : 0)); 4391da177e4SLinus Torvalds udelay(5); 4401da177e4SLinus Torvalds 4411da177e4SLinus Torvalds offset >>= 1; 4421da177e4SLinus Torvalds } 4431da177e4SLinus Torvalds idt77252_write_gp(card, gp | SAR_GP_EECS); 4441da177e4SLinus Torvalds udelay(5); 4451da177e4SLinus Torvalds 4461da177e4SLinus Torvalds byte = 0; 4471da177e4SLinus Torvalds for (i = 0, j = 0; i < 8; i++) { 4481da177e4SLinus Torvalds byte <<= 1; 4491da177e4SLinus Torvalds 4501da177e4SLinus Torvalds idt77252_write_gp(card, gp | clktab[j++]); 4511da177e4SLinus Torvalds udelay(5); 4521da177e4SLinus Torvalds 4531da177e4SLinus Torvalds byte |= idt77252_read_gp(card) & SAR_GP_EEDI ? 1 : 0; 4541da177e4SLinus Torvalds 4551da177e4SLinus Torvalds idt77252_write_gp(card, gp | clktab[j++]); 4561da177e4SLinus Torvalds udelay(5); 4571da177e4SLinus Torvalds } 4581da177e4SLinus Torvalds idt77252_write_gp(card, gp | SAR_GP_EECS); 4591da177e4SLinus Torvalds udelay(5); 4601da177e4SLinus Torvalds 4611da177e4SLinus Torvalds return byte; 4621da177e4SLinus Torvalds } 4631da177e4SLinus Torvalds 4641da177e4SLinus Torvalds static void 4651da177e4SLinus Torvalds idt77252_eeprom_write_byte(struct idt77252_dev *card, u8 offset, u8 data) 4661da177e4SLinus Torvalds { 4671da177e4SLinus Torvalds u32 gp; 4681da177e4SLinus Torvalds int i, j; 4691da177e4SLinus Torvalds 4701da177e4SLinus Torvalds gp = idt77252_read_gp(card) & ~(SAR_GP_EESCLK|SAR_GP_EECS|SAR_GP_EEDO); 4711da177e4SLinus Torvalds 4721da177e4SLinus Torvalds for (i = 0; i < sizeof(wrentab)/sizeof(wrentab[0]); i++) { 4731da177e4SLinus Torvalds idt77252_write_gp(card, gp | wrentab[i]); 4741da177e4SLinus Torvalds udelay(5); 4751da177e4SLinus Torvalds } 4761da177e4SLinus Torvalds idt77252_write_gp(card, gp | SAR_GP_EECS); 4771da177e4SLinus Torvalds udelay(5); 4781da177e4SLinus Torvalds 4791da177e4SLinus Torvalds for (i = 0; i < sizeof(wrtab)/sizeof(wrtab[0]); i++) { 4801da177e4SLinus Torvalds idt77252_write_gp(card, gp | wrtab[i]); 4811da177e4SLinus Torvalds udelay(5); 4821da177e4SLinus Torvalds } 4831da177e4SLinus Torvalds idt77252_write_gp(card, gp | SAR_GP_EECS); 4841da177e4SLinus Torvalds udelay(5); 4851da177e4SLinus Torvalds 4861da177e4SLinus Torvalds for (i = 0, j = 0; i < 8; i++) { 4871da177e4SLinus Torvalds idt77252_write_gp(card, gp | clktab[j++] | 4881da177e4SLinus Torvalds (offset & 1 ? SAR_GP_EEDO : 0)); 4891da177e4SLinus Torvalds udelay(5); 4901da177e4SLinus Torvalds 4911da177e4SLinus Torvalds idt77252_write_gp(card, gp | clktab[j++] | 4921da177e4SLinus Torvalds (offset & 1 ? SAR_GP_EEDO : 0)); 4931da177e4SLinus Torvalds udelay(5); 4941da177e4SLinus Torvalds 4951da177e4SLinus Torvalds offset >>= 1; 4961da177e4SLinus Torvalds } 4971da177e4SLinus Torvalds idt77252_write_gp(card, gp | SAR_GP_EECS); 4981da177e4SLinus Torvalds udelay(5); 4991da177e4SLinus Torvalds 5001da177e4SLinus Torvalds for (i = 0, j = 0; i < 8; i++) { 5011da177e4SLinus Torvalds idt77252_write_gp(card, gp | clktab[j++] | 5021da177e4SLinus Torvalds (data & 1 ? SAR_GP_EEDO : 0)); 5031da177e4SLinus Torvalds udelay(5); 5041da177e4SLinus Torvalds 5051da177e4SLinus Torvalds idt77252_write_gp(card, gp | clktab[j++] | 5061da177e4SLinus Torvalds (data & 1 ? SAR_GP_EEDO : 0)); 5071da177e4SLinus Torvalds udelay(5); 5081da177e4SLinus Torvalds 5091da177e4SLinus Torvalds data >>= 1; 5101da177e4SLinus Torvalds } 5111da177e4SLinus Torvalds idt77252_write_gp(card, gp | SAR_GP_EECS); 5121da177e4SLinus Torvalds udelay(5); 5131da177e4SLinus Torvalds } 5141da177e4SLinus Torvalds 5151da177e4SLinus Torvalds static void 5161da177e4SLinus Torvalds idt77252_eeprom_init(struct idt77252_dev *card) 5171da177e4SLinus Torvalds { 5181da177e4SLinus Torvalds u32 gp; 5191da177e4SLinus Torvalds 5201da177e4SLinus Torvalds gp = idt77252_read_gp(card) & ~(SAR_GP_EESCLK|SAR_GP_EECS|SAR_GP_EEDO); 5211da177e4SLinus Torvalds 5221da177e4SLinus Torvalds idt77252_write_gp(card, gp | SAR_GP_EECS | SAR_GP_EESCLK); 5231da177e4SLinus Torvalds udelay(5); 5241da177e4SLinus Torvalds idt77252_write_gp(card, gp | SAR_GP_EECS); 5251da177e4SLinus Torvalds udelay(5); 5261da177e4SLinus Torvalds idt77252_write_gp(card, gp | SAR_GP_EECS | SAR_GP_EESCLK); 5271da177e4SLinus Torvalds udelay(5); 5281da177e4SLinus Torvalds idt77252_write_gp(card, gp | SAR_GP_EECS); 5291da177e4SLinus Torvalds udelay(5); 5301da177e4SLinus Torvalds } 5311da177e4SLinus Torvalds #endif /* HAVE_EEPROM */ 5321da177e4SLinus Torvalds 5331da177e4SLinus Torvalds 5341da177e4SLinus Torvalds #ifdef CONFIG_ATM_IDT77252_DEBUG 5351da177e4SLinus Torvalds static void 5361da177e4SLinus Torvalds dump_tct(struct idt77252_dev *card, int index) 5371da177e4SLinus Torvalds { 5381da177e4SLinus Torvalds unsigned long tct; 5391da177e4SLinus Torvalds int i; 5401da177e4SLinus Torvalds 5411da177e4SLinus Torvalds tct = (unsigned long) (card->tct_base + index * SAR_SRAM_TCT_SIZE); 5421da177e4SLinus Torvalds 5431da177e4SLinus Torvalds printk("%s: TCT %x:", card->name, index); 5441da177e4SLinus Torvalds for (i = 0; i < 8; i++) { 5451da177e4SLinus Torvalds printk(" %08x", read_sram(card, tct + i)); 5461da177e4SLinus Torvalds } 5471da177e4SLinus Torvalds printk("\n"); 5481da177e4SLinus Torvalds } 5491da177e4SLinus Torvalds 5501da177e4SLinus Torvalds static void 5511da177e4SLinus Torvalds idt77252_tx_dump(struct idt77252_dev *card) 5521da177e4SLinus Torvalds { 5531da177e4SLinus Torvalds struct atm_vcc *vcc; 5541da177e4SLinus Torvalds struct vc_map *vc; 5551da177e4SLinus Torvalds int i; 5561da177e4SLinus Torvalds 5571da177e4SLinus Torvalds printk("%s\n", __FUNCTION__); 5581da177e4SLinus Torvalds for (i = 0; i < card->tct_size; i++) { 5591da177e4SLinus Torvalds vc = card->vcs[i]; 5601da177e4SLinus Torvalds if (!vc) 5611da177e4SLinus Torvalds continue; 5621da177e4SLinus Torvalds 5631da177e4SLinus Torvalds vcc = NULL; 5641da177e4SLinus Torvalds if (vc->rx_vcc) 5651da177e4SLinus Torvalds vcc = vc->rx_vcc; 5661da177e4SLinus Torvalds else if (vc->tx_vcc) 5671da177e4SLinus Torvalds vcc = vc->tx_vcc; 5681da177e4SLinus Torvalds 5691da177e4SLinus Torvalds if (!vcc) 5701da177e4SLinus Torvalds continue; 5711da177e4SLinus Torvalds 5721da177e4SLinus Torvalds printk("%s: Connection %d:\n", card->name, vc->index); 5731da177e4SLinus Torvalds dump_tct(card, vc->index); 5741da177e4SLinus Torvalds } 5751da177e4SLinus Torvalds } 5761da177e4SLinus Torvalds #endif 5771da177e4SLinus Torvalds 5781da177e4SLinus Torvalds 5791da177e4SLinus Torvalds /*****************************************************************************/ 5801da177e4SLinus Torvalds /* */ 5811da177e4SLinus Torvalds /* SCQ Handling */ 5821da177e4SLinus Torvalds /* */ 5831da177e4SLinus Torvalds /*****************************************************************************/ 5841da177e4SLinus Torvalds 5851da177e4SLinus Torvalds static int 5861da177e4SLinus Torvalds sb_pool_add(struct idt77252_dev *card, struct sk_buff *skb, int queue) 5871da177e4SLinus Torvalds { 5881da177e4SLinus Torvalds struct sb_pool *pool = &card->sbpool[queue]; 5891da177e4SLinus Torvalds int index; 5901da177e4SLinus Torvalds 5911da177e4SLinus Torvalds index = pool->index; 5921da177e4SLinus Torvalds while (pool->skb[index]) { 5931da177e4SLinus Torvalds index = (index + 1) & FBQ_MASK; 5941da177e4SLinus Torvalds if (index == pool->index) 5951da177e4SLinus Torvalds return -ENOBUFS; 5961da177e4SLinus Torvalds } 5971da177e4SLinus Torvalds 5981da177e4SLinus Torvalds pool->skb[index] = skb; 5991da177e4SLinus Torvalds IDT77252_PRV_POOL(skb) = POOL_HANDLE(queue, index); 6001da177e4SLinus Torvalds 6011da177e4SLinus Torvalds pool->index = (index + 1) & FBQ_MASK; 6021da177e4SLinus Torvalds return 0; 6031da177e4SLinus Torvalds } 6041da177e4SLinus Torvalds 6051da177e4SLinus Torvalds static void 6061da177e4SLinus Torvalds sb_pool_remove(struct idt77252_dev *card, struct sk_buff *skb) 6071da177e4SLinus Torvalds { 6081da177e4SLinus Torvalds unsigned int queue, index; 6091da177e4SLinus Torvalds u32 handle; 6101da177e4SLinus Torvalds 6111da177e4SLinus Torvalds handle = IDT77252_PRV_POOL(skb); 6121da177e4SLinus Torvalds 6131da177e4SLinus Torvalds queue = POOL_QUEUE(handle); 6141da177e4SLinus Torvalds if (queue > 3) 6151da177e4SLinus Torvalds return; 6161da177e4SLinus Torvalds 6171da177e4SLinus Torvalds index = POOL_INDEX(handle); 6181da177e4SLinus Torvalds if (index > FBQ_SIZE - 1) 6191da177e4SLinus Torvalds return; 6201da177e4SLinus Torvalds 6211da177e4SLinus Torvalds card->sbpool[queue].skb[index] = NULL; 6221da177e4SLinus Torvalds } 6231da177e4SLinus Torvalds 6241da177e4SLinus Torvalds static struct sk_buff * 6251da177e4SLinus Torvalds sb_pool_skb(struct idt77252_dev *card, u32 handle) 6261da177e4SLinus Torvalds { 6271da177e4SLinus Torvalds unsigned int queue, index; 6281da177e4SLinus Torvalds 6291da177e4SLinus Torvalds queue = POOL_QUEUE(handle); 6301da177e4SLinus Torvalds if (queue > 3) 6311da177e4SLinus Torvalds return NULL; 6321da177e4SLinus Torvalds 6331da177e4SLinus Torvalds index = POOL_INDEX(handle); 6341da177e4SLinus Torvalds if (index > FBQ_SIZE - 1) 6351da177e4SLinus Torvalds return NULL; 6361da177e4SLinus Torvalds 6371da177e4SLinus Torvalds return card->sbpool[queue].skb[index]; 6381da177e4SLinus Torvalds } 6391da177e4SLinus Torvalds 6401da177e4SLinus Torvalds static struct scq_info * 6411da177e4SLinus Torvalds alloc_scq(struct idt77252_dev *card, int class) 6421da177e4SLinus Torvalds { 6431da177e4SLinus Torvalds struct scq_info *scq; 6441da177e4SLinus Torvalds 645*0c1cca1dSOm Narasimhan scq = kzalloc(sizeof(struct scq_info), GFP_KERNEL); 6461da177e4SLinus Torvalds if (!scq) 6471da177e4SLinus Torvalds return NULL; 6481da177e4SLinus Torvalds scq->base = pci_alloc_consistent(card->pcidev, SCQ_SIZE, 6491da177e4SLinus Torvalds &scq->paddr); 6501da177e4SLinus Torvalds if (scq->base == NULL) { 6511da177e4SLinus Torvalds kfree(scq); 6521da177e4SLinus Torvalds return NULL; 6531da177e4SLinus Torvalds } 6541da177e4SLinus Torvalds memset(scq->base, 0, SCQ_SIZE); 6551da177e4SLinus Torvalds 6561da177e4SLinus Torvalds scq->next = scq->base; 6571da177e4SLinus Torvalds scq->last = scq->base + (SCQ_ENTRIES - 1); 6581da177e4SLinus Torvalds atomic_set(&scq->used, 0); 6591da177e4SLinus Torvalds 6601da177e4SLinus Torvalds spin_lock_init(&scq->lock); 6611da177e4SLinus Torvalds spin_lock_init(&scq->skblock); 6621da177e4SLinus Torvalds 6631da177e4SLinus Torvalds skb_queue_head_init(&scq->transmit); 6641da177e4SLinus Torvalds skb_queue_head_init(&scq->pending); 6651da177e4SLinus Torvalds 6661da177e4SLinus Torvalds TXPRINTK("idt77252: SCQ: base 0x%p, next 0x%p, last 0x%p, paddr %08llx\n", 6671da177e4SLinus Torvalds scq->base, scq->next, scq->last, (unsigned long long)scq->paddr); 6681da177e4SLinus Torvalds 6691da177e4SLinus Torvalds return scq; 6701da177e4SLinus Torvalds } 6711da177e4SLinus Torvalds 6721da177e4SLinus Torvalds static void 6731da177e4SLinus Torvalds free_scq(struct idt77252_dev *card, struct scq_info *scq) 6741da177e4SLinus Torvalds { 6751da177e4SLinus Torvalds struct sk_buff *skb; 6761da177e4SLinus Torvalds struct atm_vcc *vcc; 6771da177e4SLinus Torvalds 6781da177e4SLinus Torvalds pci_free_consistent(card->pcidev, SCQ_SIZE, 6791da177e4SLinus Torvalds scq->base, scq->paddr); 6801da177e4SLinus Torvalds 6811da177e4SLinus Torvalds while ((skb = skb_dequeue(&scq->transmit))) { 6821da177e4SLinus Torvalds pci_unmap_single(card->pcidev, IDT77252_PRV_PADDR(skb), 6831da177e4SLinus Torvalds skb->len, PCI_DMA_TODEVICE); 6841da177e4SLinus Torvalds 6851da177e4SLinus Torvalds vcc = ATM_SKB(skb)->vcc; 6861da177e4SLinus Torvalds if (vcc->pop) 6871da177e4SLinus Torvalds vcc->pop(vcc, skb); 6881da177e4SLinus Torvalds else 6891da177e4SLinus Torvalds dev_kfree_skb(skb); 6901da177e4SLinus Torvalds } 6911da177e4SLinus Torvalds 6921da177e4SLinus Torvalds while ((skb = skb_dequeue(&scq->pending))) { 6931da177e4SLinus Torvalds pci_unmap_single(card->pcidev, IDT77252_PRV_PADDR(skb), 6941da177e4SLinus Torvalds skb->len, PCI_DMA_TODEVICE); 6951da177e4SLinus Torvalds 6961da177e4SLinus Torvalds vcc = ATM_SKB(skb)->vcc; 6971da177e4SLinus Torvalds if (vcc->pop) 6981da177e4SLinus Torvalds vcc->pop(vcc, skb); 6991da177e4SLinus Torvalds else 7001da177e4SLinus Torvalds dev_kfree_skb(skb); 7011da177e4SLinus Torvalds } 7021da177e4SLinus Torvalds 7031da177e4SLinus Torvalds kfree(scq); 7041da177e4SLinus Torvalds } 7051da177e4SLinus Torvalds 7061da177e4SLinus Torvalds 7071da177e4SLinus Torvalds static int 7081da177e4SLinus Torvalds push_on_scq(struct idt77252_dev *card, struct vc_map *vc, struct sk_buff *skb) 7091da177e4SLinus Torvalds { 7101da177e4SLinus Torvalds struct scq_info *scq = vc->scq; 7111da177e4SLinus Torvalds unsigned long flags; 7121da177e4SLinus Torvalds struct scqe *tbd; 7131da177e4SLinus Torvalds int entries; 7141da177e4SLinus Torvalds 7151da177e4SLinus Torvalds TXPRINTK("%s: SCQ: next 0x%p\n", card->name, scq->next); 7161da177e4SLinus Torvalds 7171da177e4SLinus Torvalds atomic_inc(&scq->used); 7181da177e4SLinus Torvalds entries = atomic_read(&scq->used); 7191da177e4SLinus Torvalds if (entries > (SCQ_ENTRIES - 1)) { 7201da177e4SLinus Torvalds atomic_dec(&scq->used); 7211da177e4SLinus Torvalds goto out; 7221da177e4SLinus Torvalds } 7231da177e4SLinus Torvalds 7241da177e4SLinus Torvalds skb_queue_tail(&scq->transmit, skb); 7251da177e4SLinus Torvalds 7261da177e4SLinus Torvalds spin_lock_irqsave(&vc->lock, flags); 7271da177e4SLinus Torvalds if (vc->estimator) { 7281da177e4SLinus Torvalds struct atm_vcc *vcc = vc->tx_vcc; 7291da177e4SLinus Torvalds struct sock *sk = sk_atm(vcc); 7301da177e4SLinus Torvalds 7311da177e4SLinus Torvalds vc->estimator->cells += (skb->len + 47) / 48; 7321da177e4SLinus Torvalds if (atomic_read(&sk->sk_wmem_alloc) > 7331da177e4SLinus Torvalds (sk->sk_sndbuf >> 1)) { 7341da177e4SLinus Torvalds u32 cps = vc->estimator->maxcps; 7351da177e4SLinus Torvalds 7361da177e4SLinus Torvalds vc->estimator->cps = cps; 7371da177e4SLinus Torvalds vc->estimator->avcps = cps << 5; 7381da177e4SLinus Torvalds if (vc->lacr < vc->init_er) { 7391da177e4SLinus Torvalds vc->lacr = vc->init_er; 7401da177e4SLinus Torvalds writel(TCMDQ_LACR | (vc->lacr << 16) | 7411da177e4SLinus Torvalds vc->index, SAR_REG_TCMDQ); 7421da177e4SLinus Torvalds } 7431da177e4SLinus Torvalds } 7441da177e4SLinus Torvalds } 7451da177e4SLinus Torvalds spin_unlock_irqrestore(&vc->lock, flags); 7461da177e4SLinus Torvalds 7471da177e4SLinus Torvalds tbd = &IDT77252_PRV_TBD(skb); 7481da177e4SLinus Torvalds 7491da177e4SLinus Torvalds spin_lock_irqsave(&scq->lock, flags); 7501da177e4SLinus Torvalds scq->next->word_1 = cpu_to_le32(tbd->word_1 | 7511da177e4SLinus Torvalds SAR_TBD_TSIF | SAR_TBD_GTSI); 7521da177e4SLinus Torvalds scq->next->word_2 = cpu_to_le32(tbd->word_2); 7531da177e4SLinus Torvalds scq->next->word_3 = cpu_to_le32(tbd->word_3); 7541da177e4SLinus Torvalds scq->next->word_4 = cpu_to_le32(tbd->word_4); 7551da177e4SLinus Torvalds 7561da177e4SLinus Torvalds if (scq->next == scq->last) 7571da177e4SLinus Torvalds scq->next = scq->base; 7581da177e4SLinus Torvalds else 7591da177e4SLinus Torvalds scq->next++; 7601da177e4SLinus Torvalds 7611da177e4SLinus Torvalds write_sram(card, scq->scd, 7621da177e4SLinus Torvalds scq->paddr + 7631da177e4SLinus Torvalds (u32)((unsigned long)scq->next - (unsigned long)scq->base)); 7641da177e4SLinus Torvalds spin_unlock_irqrestore(&scq->lock, flags); 7651da177e4SLinus Torvalds 7661da177e4SLinus Torvalds scq->trans_start = jiffies; 7671da177e4SLinus Torvalds 7681da177e4SLinus Torvalds if (test_and_clear_bit(VCF_IDLE, &vc->flags)) { 7691da177e4SLinus Torvalds writel(TCMDQ_START_LACR | (vc->lacr << 16) | vc->index, 7701da177e4SLinus Torvalds SAR_REG_TCMDQ); 7711da177e4SLinus Torvalds } 7721da177e4SLinus Torvalds 7731da177e4SLinus Torvalds TXPRINTK("%d entries in SCQ used (push).\n", atomic_read(&scq->used)); 7741da177e4SLinus Torvalds 7751da177e4SLinus Torvalds XPRINTK("%s: SCQ (after push %2d) head = 0x%x, next = 0x%p.\n", 7761da177e4SLinus Torvalds card->name, atomic_read(&scq->used), 7771da177e4SLinus Torvalds read_sram(card, scq->scd + 1), scq->next); 7781da177e4SLinus Torvalds 7791da177e4SLinus Torvalds return 0; 7801da177e4SLinus Torvalds 7811da177e4SLinus Torvalds out: 782e1bd232bSMarcelo Feitoza Parisi if (time_after(jiffies, scq->trans_start + HZ)) { 7831da177e4SLinus Torvalds printk("%s: Error pushing TBD for %d.%d\n", 7841da177e4SLinus Torvalds card->name, vc->tx_vcc->vpi, vc->tx_vcc->vci); 7851da177e4SLinus Torvalds #ifdef CONFIG_ATM_IDT77252_DEBUG 7861da177e4SLinus Torvalds idt77252_tx_dump(card); 7871da177e4SLinus Torvalds #endif 7881da177e4SLinus Torvalds scq->trans_start = jiffies; 7891da177e4SLinus Torvalds } 7901da177e4SLinus Torvalds 7911da177e4SLinus Torvalds return -ENOBUFS; 7921da177e4SLinus Torvalds } 7931da177e4SLinus Torvalds 7941da177e4SLinus Torvalds 7951da177e4SLinus Torvalds static void 7961da177e4SLinus Torvalds drain_scq(struct idt77252_dev *card, struct vc_map *vc) 7971da177e4SLinus Torvalds { 7981da177e4SLinus Torvalds struct scq_info *scq = vc->scq; 7991da177e4SLinus Torvalds struct sk_buff *skb; 8001da177e4SLinus Torvalds struct atm_vcc *vcc; 8011da177e4SLinus Torvalds 8021da177e4SLinus Torvalds TXPRINTK("%s: SCQ (before drain %2d) next = 0x%p.\n", 8031da177e4SLinus Torvalds card->name, atomic_read(&scq->used), scq->next); 8041da177e4SLinus Torvalds 8051da177e4SLinus Torvalds skb = skb_dequeue(&scq->transmit); 8061da177e4SLinus Torvalds if (skb) { 8071da177e4SLinus Torvalds TXPRINTK("%s: freeing skb at %p.\n", card->name, skb); 8081da177e4SLinus Torvalds 8091da177e4SLinus Torvalds pci_unmap_single(card->pcidev, IDT77252_PRV_PADDR(skb), 8101da177e4SLinus Torvalds skb->len, PCI_DMA_TODEVICE); 8111da177e4SLinus Torvalds 8121da177e4SLinus Torvalds vcc = ATM_SKB(skb)->vcc; 8131da177e4SLinus Torvalds 8141da177e4SLinus Torvalds if (vcc->pop) 8151da177e4SLinus Torvalds vcc->pop(vcc, skb); 8161da177e4SLinus Torvalds else 8171da177e4SLinus Torvalds dev_kfree_skb(skb); 8181da177e4SLinus Torvalds 8191da177e4SLinus Torvalds atomic_inc(&vcc->stats->tx); 8201da177e4SLinus Torvalds } 8211da177e4SLinus Torvalds 8221da177e4SLinus Torvalds atomic_dec(&scq->used); 8231da177e4SLinus Torvalds 8241da177e4SLinus Torvalds spin_lock(&scq->skblock); 8251da177e4SLinus Torvalds while ((skb = skb_dequeue(&scq->pending))) { 8261da177e4SLinus Torvalds if (push_on_scq(card, vc, skb)) { 8271da177e4SLinus Torvalds skb_queue_head(&vc->scq->pending, skb); 8281da177e4SLinus Torvalds break; 8291da177e4SLinus Torvalds } 8301da177e4SLinus Torvalds } 8311da177e4SLinus Torvalds spin_unlock(&scq->skblock); 8321da177e4SLinus Torvalds } 8331da177e4SLinus Torvalds 8341da177e4SLinus Torvalds static int 8351da177e4SLinus Torvalds queue_skb(struct idt77252_dev *card, struct vc_map *vc, 8361da177e4SLinus Torvalds struct sk_buff *skb, int oam) 8371da177e4SLinus Torvalds { 8381da177e4SLinus Torvalds struct atm_vcc *vcc; 8391da177e4SLinus Torvalds struct scqe *tbd; 8401da177e4SLinus Torvalds unsigned long flags; 8411da177e4SLinus Torvalds int error; 8421da177e4SLinus Torvalds int aal; 8431da177e4SLinus Torvalds 8441da177e4SLinus Torvalds if (skb->len == 0) { 8451da177e4SLinus Torvalds printk("%s: invalid skb->len (%d)\n", card->name, skb->len); 8461da177e4SLinus Torvalds return -EINVAL; 8471da177e4SLinus Torvalds } 8481da177e4SLinus Torvalds 8491da177e4SLinus Torvalds TXPRINTK("%s: Sending %d bytes of data.\n", 8501da177e4SLinus Torvalds card->name, skb->len); 8511da177e4SLinus Torvalds 8521da177e4SLinus Torvalds tbd = &IDT77252_PRV_TBD(skb); 8531da177e4SLinus Torvalds vcc = ATM_SKB(skb)->vcc; 8541da177e4SLinus Torvalds 8551da177e4SLinus Torvalds IDT77252_PRV_PADDR(skb) = pci_map_single(card->pcidev, skb->data, 8561da177e4SLinus Torvalds skb->len, PCI_DMA_TODEVICE); 8571da177e4SLinus Torvalds 8581da177e4SLinus Torvalds error = -EINVAL; 8591da177e4SLinus Torvalds 8601da177e4SLinus Torvalds if (oam) { 8611da177e4SLinus Torvalds if (skb->len != 52) 8621da177e4SLinus Torvalds goto errout; 8631da177e4SLinus Torvalds 8641da177e4SLinus Torvalds tbd->word_1 = SAR_TBD_OAM | ATM_CELL_PAYLOAD | SAR_TBD_EPDU; 8651da177e4SLinus Torvalds tbd->word_2 = IDT77252_PRV_PADDR(skb) + 4; 8661da177e4SLinus Torvalds tbd->word_3 = 0x00000000; 8671da177e4SLinus Torvalds tbd->word_4 = (skb->data[0] << 24) | (skb->data[1] << 16) | 8681da177e4SLinus Torvalds (skb->data[2] << 8) | (skb->data[3] << 0); 8691da177e4SLinus Torvalds 8701da177e4SLinus Torvalds if (test_bit(VCF_RSV, &vc->flags)) 8711da177e4SLinus Torvalds vc = card->vcs[0]; 8721da177e4SLinus Torvalds 8731da177e4SLinus Torvalds goto done; 8741da177e4SLinus Torvalds } 8751da177e4SLinus Torvalds 8761da177e4SLinus Torvalds if (test_bit(VCF_RSV, &vc->flags)) { 8771da177e4SLinus Torvalds printk("%s: Trying to transmit on reserved VC\n", card->name); 8781da177e4SLinus Torvalds goto errout; 8791da177e4SLinus Torvalds } 8801da177e4SLinus Torvalds 8811da177e4SLinus Torvalds aal = vcc->qos.aal; 8821da177e4SLinus Torvalds 8831da177e4SLinus Torvalds switch (aal) { 8841da177e4SLinus Torvalds case ATM_AAL0: 8851da177e4SLinus Torvalds case ATM_AAL34: 8861da177e4SLinus Torvalds if (skb->len > 52) 8871da177e4SLinus Torvalds goto errout; 8881da177e4SLinus Torvalds 8891da177e4SLinus Torvalds if (aal == ATM_AAL0) 8901da177e4SLinus Torvalds tbd->word_1 = SAR_TBD_EPDU | SAR_TBD_AAL0 | 8911da177e4SLinus Torvalds ATM_CELL_PAYLOAD; 8921da177e4SLinus Torvalds else 8931da177e4SLinus Torvalds tbd->word_1 = SAR_TBD_EPDU | SAR_TBD_AAL34 | 8941da177e4SLinus Torvalds ATM_CELL_PAYLOAD; 8951da177e4SLinus Torvalds 8961da177e4SLinus Torvalds tbd->word_2 = IDT77252_PRV_PADDR(skb) + 4; 8971da177e4SLinus Torvalds tbd->word_3 = 0x00000000; 8981da177e4SLinus Torvalds tbd->word_4 = (skb->data[0] << 24) | (skb->data[1] << 16) | 8991da177e4SLinus Torvalds (skb->data[2] << 8) | (skb->data[3] << 0); 9001da177e4SLinus Torvalds break; 9011da177e4SLinus Torvalds 9021da177e4SLinus Torvalds case ATM_AAL5: 9031da177e4SLinus Torvalds tbd->word_1 = SAR_TBD_EPDU | SAR_TBD_AAL5 | skb->len; 9041da177e4SLinus Torvalds tbd->word_2 = IDT77252_PRV_PADDR(skb); 9051da177e4SLinus Torvalds tbd->word_3 = skb->len; 9061da177e4SLinus Torvalds tbd->word_4 = (vcc->vpi << SAR_TBD_VPI_SHIFT) | 9071da177e4SLinus Torvalds (vcc->vci << SAR_TBD_VCI_SHIFT); 9081da177e4SLinus Torvalds break; 9091da177e4SLinus Torvalds 9101da177e4SLinus Torvalds case ATM_AAL1: 9111da177e4SLinus Torvalds case ATM_AAL2: 9121da177e4SLinus Torvalds default: 9131da177e4SLinus Torvalds printk("%s: Traffic type not supported.\n", card->name); 9141da177e4SLinus Torvalds error = -EPROTONOSUPPORT; 9151da177e4SLinus Torvalds goto errout; 9161da177e4SLinus Torvalds } 9171da177e4SLinus Torvalds 9181da177e4SLinus Torvalds done: 9191da177e4SLinus Torvalds spin_lock_irqsave(&vc->scq->skblock, flags); 9201da177e4SLinus Torvalds skb_queue_tail(&vc->scq->pending, skb); 9211da177e4SLinus Torvalds 9221da177e4SLinus Torvalds while ((skb = skb_dequeue(&vc->scq->pending))) { 9231da177e4SLinus Torvalds if (push_on_scq(card, vc, skb)) { 9241da177e4SLinus Torvalds skb_queue_head(&vc->scq->pending, skb); 9251da177e4SLinus Torvalds break; 9261da177e4SLinus Torvalds } 9271da177e4SLinus Torvalds } 9281da177e4SLinus Torvalds spin_unlock_irqrestore(&vc->scq->skblock, flags); 9291da177e4SLinus Torvalds 9301da177e4SLinus Torvalds return 0; 9311da177e4SLinus Torvalds 9321da177e4SLinus Torvalds errout: 9331da177e4SLinus Torvalds pci_unmap_single(card->pcidev, IDT77252_PRV_PADDR(skb), 9341da177e4SLinus Torvalds skb->len, PCI_DMA_TODEVICE); 9351da177e4SLinus Torvalds return error; 9361da177e4SLinus Torvalds } 9371da177e4SLinus Torvalds 9381da177e4SLinus Torvalds static unsigned long 9391da177e4SLinus Torvalds get_free_scd(struct idt77252_dev *card, struct vc_map *vc) 9401da177e4SLinus Torvalds { 9411da177e4SLinus Torvalds int i; 9421da177e4SLinus Torvalds 9431da177e4SLinus Torvalds for (i = 0; i < card->scd_size; i++) { 9441da177e4SLinus Torvalds if (!card->scd2vc[i]) { 9451da177e4SLinus Torvalds card->scd2vc[i] = vc; 9461da177e4SLinus Torvalds vc->scd_index = i; 9471da177e4SLinus Torvalds return card->scd_base + i * SAR_SRAM_SCD_SIZE; 9481da177e4SLinus Torvalds } 9491da177e4SLinus Torvalds } 9501da177e4SLinus Torvalds return 0; 9511da177e4SLinus Torvalds } 9521da177e4SLinus Torvalds 9531da177e4SLinus Torvalds static void 9541da177e4SLinus Torvalds fill_scd(struct idt77252_dev *card, struct scq_info *scq, int class) 9551da177e4SLinus Torvalds { 9561da177e4SLinus Torvalds write_sram(card, scq->scd, scq->paddr); 9571da177e4SLinus Torvalds write_sram(card, scq->scd + 1, 0x00000000); 9581da177e4SLinus Torvalds write_sram(card, scq->scd + 2, 0xffffffff); 9591da177e4SLinus Torvalds write_sram(card, scq->scd + 3, 0x00000000); 9601da177e4SLinus Torvalds } 9611da177e4SLinus Torvalds 9621da177e4SLinus Torvalds static void 9631da177e4SLinus Torvalds clear_scd(struct idt77252_dev *card, struct scq_info *scq, int class) 9641da177e4SLinus Torvalds { 9651da177e4SLinus Torvalds return; 9661da177e4SLinus Torvalds } 9671da177e4SLinus Torvalds 9681da177e4SLinus Torvalds /*****************************************************************************/ 9691da177e4SLinus Torvalds /* */ 9701da177e4SLinus Torvalds /* RSQ Handling */ 9711da177e4SLinus Torvalds /* */ 9721da177e4SLinus Torvalds /*****************************************************************************/ 9731da177e4SLinus Torvalds 9741da177e4SLinus Torvalds static int 9751da177e4SLinus Torvalds init_rsq(struct idt77252_dev *card) 9761da177e4SLinus Torvalds { 9771da177e4SLinus Torvalds struct rsq_entry *rsqe; 9781da177e4SLinus Torvalds 9791da177e4SLinus Torvalds card->rsq.base = pci_alloc_consistent(card->pcidev, RSQSIZE, 9801da177e4SLinus Torvalds &card->rsq.paddr); 9811da177e4SLinus Torvalds if (card->rsq.base == NULL) { 9821da177e4SLinus Torvalds printk("%s: can't allocate RSQ.\n", card->name); 9831da177e4SLinus Torvalds return -1; 9841da177e4SLinus Torvalds } 9851da177e4SLinus Torvalds memset(card->rsq.base, 0, RSQSIZE); 9861da177e4SLinus Torvalds 9871da177e4SLinus Torvalds card->rsq.last = card->rsq.base + RSQ_NUM_ENTRIES - 1; 9881da177e4SLinus Torvalds card->rsq.next = card->rsq.last; 9891da177e4SLinus Torvalds for (rsqe = card->rsq.base; rsqe <= card->rsq.last; rsqe++) 9901da177e4SLinus Torvalds rsqe->word_4 = 0; 9911da177e4SLinus Torvalds 9921da177e4SLinus Torvalds writel((unsigned long) card->rsq.last - (unsigned long) card->rsq.base, 9931da177e4SLinus Torvalds SAR_REG_RSQH); 9941da177e4SLinus Torvalds writel(card->rsq.paddr, SAR_REG_RSQB); 9951da177e4SLinus Torvalds 9961da177e4SLinus Torvalds IPRINTK("%s: RSQ base at 0x%lx (0x%x).\n", card->name, 9971da177e4SLinus Torvalds (unsigned long) card->rsq.base, 9981da177e4SLinus Torvalds readl(SAR_REG_RSQB)); 9991da177e4SLinus Torvalds IPRINTK("%s: RSQ head = 0x%x, base = 0x%x, tail = 0x%x.\n", 10001da177e4SLinus Torvalds card->name, 10011da177e4SLinus Torvalds readl(SAR_REG_RSQH), 10021da177e4SLinus Torvalds readl(SAR_REG_RSQB), 10031da177e4SLinus Torvalds readl(SAR_REG_RSQT)); 10041da177e4SLinus Torvalds 10051da177e4SLinus Torvalds return 0; 10061da177e4SLinus Torvalds } 10071da177e4SLinus Torvalds 10081da177e4SLinus Torvalds static void 10091da177e4SLinus Torvalds deinit_rsq(struct idt77252_dev *card) 10101da177e4SLinus Torvalds { 10111da177e4SLinus Torvalds pci_free_consistent(card->pcidev, RSQSIZE, 10121da177e4SLinus Torvalds card->rsq.base, card->rsq.paddr); 10131da177e4SLinus Torvalds } 10141da177e4SLinus Torvalds 10151da177e4SLinus Torvalds static void 10161da177e4SLinus Torvalds dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe) 10171da177e4SLinus Torvalds { 10181da177e4SLinus Torvalds struct atm_vcc *vcc; 10191da177e4SLinus Torvalds struct sk_buff *skb; 10201da177e4SLinus Torvalds struct rx_pool *rpp; 10211da177e4SLinus Torvalds struct vc_map *vc; 10221da177e4SLinus Torvalds u32 header, vpi, vci; 10231da177e4SLinus Torvalds u32 stat; 10241da177e4SLinus Torvalds int i; 10251da177e4SLinus Torvalds 10261da177e4SLinus Torvalds stat = le32_to_cpu(rsqe->word_4); 10271da177e4SLinus Torvalds 10281da177e4SLinus Torvalds if (stat & SAR_RSQE_IDLE) { 10291da177e4SLinus Torvalds RXPRINTK("%s: message about inactive connection.\n", 10301da177e4SLinus Torvalds card->name); 10311da177e4SLinus Torvalds return; 10321da177e4SLinus Torvalds } 10331da177e4SLinus Torvalds 10341da177e4SLinus Torvalds skb = sb_pool_skb(card, le32_to_cpu(rsqe->word_2)); 10351da177e4SLinus Torvalds if (skb == NULL) { 10361da177e4SLinus Torvalds printk("%s: NULL skb in %s, rsqe: %08x %08x %08x %08x\n", 10371da177e4SLinus Torvalds card->name, __FUNCTION__, 10381da177e4SLinus Torvalds le32_to_cpu(rsqe->word_1), le32_to_cpu(rsqe->word_2), 10391da177e4SLinus Torvalds le32_to_cpu(rsqe->word_3), le32_to_cpu(rsqe->word_4)); 10401da177e4SLinus Torvalds return; 10411da177e4SLinus Torvalds } 10421da177e4SLinus Torvalds 10431da177e4SLinus Torvalds header = le32_to_cpu(rsqe->word_1); 10441da177e4SLinus Torvalds vpi = (header >> 16) & 0x00ff; 10451da177e4SLinus Torvalds vci = (header >> 0) & 0xffff; 10461da177e4SLinus Torvalds 10471da177e4SLinus Torvalds RXPRINTK("%s: SDU for %d.%d received in buffer 0x%p (data 0x%p).\n", 10481da177e4SLinus Torvalds card->name, vpi, vci, skb, skb->data); 10491da177e4SLinus Torvalds 10501da177e4SLinus Torvalds if ((vpi >= (1 << card->vpibits)) || (vci != (vci & card->vcimask))) { 10511da177e4SLinus Torvalds printk("%s: SDU received for out-of-range vc %u.%u\n", 10521da177e4SLinus Torvalds card->name, vpi, vci); 10531da177e4SLinus Torvalds recycle_rx_skb(card, skb); 10541da177e4SLinus Torvalds return; 10551da177e4SLinus Torvalds } 10561da177e4SLinus Torvalds 10571da177e4SLinus Torvalds vc = card->vcs[VPCI2VC(card, vpi, vci)]; 10581da177e4SLinus Torvalds if (!vc || !test_bit(VCF_RX, &vc->flags)) { 10591da177e4SLinus Torvalds printk("%s: SDU received on non RX vc %u.%u\n", 10601da177e4SLinus Torvalds card->name, vpi, vci); 10611da177e4SLinus Torvalds recycle_rx_skb(card, skb); 10621da177e4SLinus Torvalds return; 10631da177e4SLinus Torvalds } 10641da177e4SLinus Torvalds 10651da177e4SLinus Torvalds vcc = vc->rx_vcc; 10661da177e4SLinus Torvalds 10671da177e4SLinus Torvalds pci_dma_sync_single_for_cpu(card->pcidev, IDT77252_PRV_PADDR(skb), 10681da177e4SLinus Torvalds skb->end - skb->data, PCI_DMA_FROMDEVICE); 10691da177e4SLinus Torvalds 10701da177e4SLinus Torvalds if ((vcc->qos.aal == ATM_AAL0) || 10711da177e4SLinus Torvalds (vcc->qos.aal == ATM_AAL34)) { 10721da177e4SLinus Torvalds struct sk_buff *sb; 10731da177e4SLinus Torvalds unsigned char *cell; 10741da177e4SLinus Torvalds u32 aal0; 10751da177e4SLinus Torvalds 10761da177e4SLinus Torvalds cell = skb->data; 10771da177e4SLinus Torvalds for (i = (stat & SAR_RSQE_CELLCNT); i; i--) { 10781da177e4SLinus Torvalds if ((sb = dev_alloc_skb(64)) == NULL) { 10791da177e4SLinus Torvalds printk("%s: Can't allocate buffers for aal0.\n", 10801da177e4SLinus Torvalds card->name); 10811da177e4SLinus Torvalds atomic_add(i, &vcc->stats->rx_drop); 10821da177e4SLinus Torvalds break; 10831da177e4SLinus Torvalds } 10841da177e4SLinus Torvalds if (!atm_charge(vcc, sb->truesize)) { 10851da177e4SLinus Torvalds RXPRINTK("%s: atm_charge() dropped aal0 packets.\n", 10861da177e4SLinus Torvalds card->name); 10871da177e4SLinus Torvalds atomic_add(i - 1, &vcc->stats->rx_drop); 10881da177e4SLinus Torvalds dev_kfree_skb(sb); 10891da177e4SLinus Torvalds break; 10901da177e4SLinus Torvalds } 10911da177e4SLinus Torvalds aal0 = (vpi << ATM_HDR_VPI_SHIFT) | 10921da177e4SLinus Torvalds (vci << ATM_HDR_VCI_SHIFT); 10931da177e4SLinus Torvalds aal0 |= (stat & SAR_RSQE_EPDU) ? 0x00000002 : 0; 10941da177e4SLinus Torvalds aal0 |= (stat & SAR_RSQE_CLP) ? 0x00000001 : 0; 10951da177e4SLinus Torvalds 10961da177e4SLinus Torvalds *((u32 *) sb->data) = aal0; 10971da177e4SLinus Torvalds skb_put(sb, sizeof(u32)); 10981da177e4SLinus Torvalds memcpy(skb_put(sb, ATM_CELL_PAYLOAD), 10991da177e4SLinus Torvalds cell, ATM_CELL_PAYLOAD); 11001da177e4SLinus Torvalds 11011da177e4SLinus Torvalds ATM_SKB(sb)->vcc = vcc; 1102a61bbcf2SPatrick McHardy __net_timestamp(sb); 11031da177e4SLinus Torvalds vcc->push(vcc, sb); 11041da177e4SLinus Torvalds atomic_inc(&vcc->stats->rx); 11051da177e4SLinus Torvalds 11061da177e4SLinus Torvalds cell += ATM_CELL_PAYLOAD; 11071da177e4SLinus Torvalds } 11081da177e4SLinus Torvalds 11091da177e4SLinus Torvalds recycle_rx_skb(card, skb); 11101da177e4SLinus Torvalds return; 11111da177e4SLinus Torvalds } 11121da177e4SLinus Torvalds if (vcc->qos.aal != ATM_AAL5) { 11131da177e4SLinus Torvalds printk("%s: Unexpected AAL type in dequeue_rx(): %d.\n", 11141da177e4SLinus Torvalds card->name, vcc->qos.aal); 11151da177e4SLinus Torvalds recycle_rx_skb(card, skb); 11161da177e4SLinus Torvalds return; 11171da177e4SLinus Torvalds } 11181da177e4SLinus Torvalds skb->len = (stat & SAR_RSQE_CELLCNT) * ATM_CELL_PAYLOAD; 11191da177e4SLinus Torvalds 11201da177e4SLinus Torvalds rpp = &vc->rcv.rx_pool; 11211da177e4SLinus Torvalds 11221da177e4SLinus Torvalds rpp->len += skb->len; 11231da177e4SLinus Torvalds if (!rpp->count++) 11241da177e4SLinus Torvalds rpp->first = skb; 11251da177e4SLinus Torvalds *rpp->last = skb; 11261da177e4SLinus Torvalds rpp->last = &skb->next; 11271da177e4SLinus Torvalds 11281da177e4SLinus Torvalds if (stat & SAR_RSQE_EPDU) { 11291da177e4SLinus Torvalds unsigned char *l1l2; 11301da177e4SLinus Torvalds unsigned int len; 11311da177e4SLinus Torvalds 11321da177e4SLinus Torvalds l1l2 = (unsigned char *) ((unsigned long) skb->data + skb->len - 6); 11331da177e4SLinus Torvalds 11341da177e4SLinus Torvalds len = (l1l2[0] << 8) | l1l2[1]; 11351da177e4SLinus Torvalds len = len ? len : 0x10000; 11361da177e4SLinus Torvalds 11371da177e4SLinus Torvalds RXPRINTK("%s: PDU has %d bytes.\n", card->name, len); 11381da177e4SLinus Torvalds 11391da177e4SLinus Torvalds if ((len + 8 > rpp->len) || (len + (47 + 8) < rpp->len)) { 11401da177e4SLinus Torvalds RXPRINTK("%s: AAL5 PDU size mismatch: %d != %d. " 11411da177e4SLinus Torvalds "(CDC: %08x)\n", 11421da177e4SLinus Torvalds card->name, len, rpp->len, readl(SAR_REG_CDC)); 11431da177e4SLinus Torvalds recycle_rx_pool_skb(card, rpp); 11441da177e4SLinus Torvalds atomic_inc(&vcc->stats->rx_err); 11451da177e4SLinus Torvalds return; 11461da177e4SLinus Torvalds } 11471da177e4SLinus Torvalds if (stat & SAR_RSQE_CRC) { 11481da177e4SLinus Torvalds RXPRINTK("%s: AAL5 CRC error.\n", card->name); 11491da177e4SLinus Torvalds recycle_rx_pool_skb(card, rpp); 11501da177e4SLinus Torvalds atomic_inc(&vcc->stats->rx_err); 11511da177e4SLinus Torvalds return; 11521da177e4SLinus Torvalds } 11531da177e4SLinus Torvalds if (rpp->count > 1) { 11541da177e4SLinus Torvalds struct sk_buff *sb; 11551da177e4SLinus Torvalds 11561da177e4SLinus Torvalds skb = dev_alloc_skb(rpp->len); 11571da177e4SLinus Torvalds if (!skb) { 11581da177e4SLinus Torvalds RXPRINTK("%s: Can't alloc RX skb.\n", 11591da177e4SLinus Torvalds card->name); 11601da177e4SLinus Torvalds recycle_rx_pool_skb(card, rpp); 11611da177e4SLinus Torvalds atomic_inc(&vcc->stats->rx_err); 11621da177e4SLinus Torvalds return; 11631da177e4SLinus Torvalds } 11641da177e4SLinus Torvalds if (!atm_charge(vcc, skb->truesize)) { 11651da177e4SLinus Torvalds recycle_rx_pool_skb(card, rpp); 11661da177e4SLinus Torvalds dev_kfree_skb(skb); 11671da177e4SLinus Torvalds return; 11681da177e4SLinus Torvalds } 11691da177e4SLinus Torvalds sb = rpp->first; 11701da177e4SLinus Torvalds for (i = 0; i < rpp->count; i++) { 11711da177e4SLinus Torvalds memcpy(skb_put(skb, sb->len), 11721da177e4SLinus Torvalds sb->data, sb->len); 11731da177e4SLinus Torvalds sb = sb->next; 11741da177e4SLinus Torvalds } 11751da177e4SLinus Torvalds 11761da177e4SLinus Torvalds recycle_rx_pool_skb(card, rpp); 11771da177e4SLinus Torvalds 11781da177e4SLinus Torvalds skb_trim(skb, len); 11791da177e4SLinus Torvalds ATM_SKB(skb)->vcc = vcc; 1180a61bbcf2SPatrick McHardy __net_timestamp(skb); 11811da177e4SLinus Torvalds 11821da177e4SLinus Torvalds vcc->push(vcc, skb); 11831da177e4SLinus Torvalds atomic_inc(&vcc->stats->rx); 11841da177e4SLinus Torvalds 11851da177e4SLinus Torvalds return; 11861da177e4SLinus Torvalds } 11871da177e4SLinus Torvalds 11881da177e4SLinus Torvalds skb->next = NULL; 11891da177e4SLinus Torvalds flush_rx_pool(card, rpp); 11901da177e4SLinus Torvalds 11911da177e4SLinus Torvalds if (!atm_charge(vcc, skb->truesize)) { 11921da177e4SLinus Torvalds recycle_rx_skb(card, skb); 11931da177e4SLinus Torvalds return; 11941da177e4SLinus Torvalds } 11951da177e4SLinus Torvalds 11961da177e4SLinus Torvalds pci_unmap_single(card->pcidev, IDT77252_PRV_PADDR(skb), 11971da177e4SLinus Torvalds skb->end - skb->data, PCI_DMA_FROMDEVICE); 11981da177e4SLinus Torvalds sb_pool_remove(card, skb); 11991da177e4SLinus Torvalds 12001da177e4SLinus Torvalds skb_trim(skb, len); 12011da177e4SLinus Torvalds ATM_SKB(skb)->vcc = vcc; 1202a61bbcf2SPatrick McHardy __net_timestamp(skb); 12031da177e4SLinus Torvalds 12041da177e4SLinus Torvalds vcc->push(vcc, skb); 12051da177e4SLinus Torvalds atomic_inc(&vcc->stats->rx); 12061da177e4SLinus Torvalds 12071da177e4SLinus Torvalds if (skb->truesize > SAR_FB_SIZE_3) 12081da177e4SLinus Torvalds add_rx_skb(card, 3, SAR_FB_SIZE_3, 1); 12091da177e4SLinus Torvalds else if (skb->truesize > SAR_FB_SIZE_2) 12101da177e4SLinus Torvalds add_rx_skb(card, 2, SAR_FB_SIZE_2, 1); 12111da177e4SLinus Torvalds else if (skb->truesize > SAR_FB_SIZE_1) 12121da177e4SLinus Torvalds add_rx_skb(card, 1, SAR_FB_SIZE_1, 1); 12131da177e4SLinus Torvalds else 12141da177e4SLinus Torvalds add_rx_skb(card, 0, SAR_FB_SIZE_0, 1); 12151da177e4SLinus Torvalds return; 12161da177e4SLinus Torvalds } 12171da177e4SLinus Torvalds } 12181da177e4SLinus Torvalds 12191da177e4SLinus Torvalds static void 12201da177e4SLinus Torvalds idt77252_rx(struct idt77252_dev *card) 12211da177e4SLinus Torvalds { 12221da177e4SLinus Torvalds struct rsq_entry *rsqe; 12231da177e4SLinus Torvalds 12241da177e4SLinus Torvalds if (card->rsq.next == card->rsq.last) 12251da177e4SLinus Torvalds rsqe = card->rsq.base; 12261da177e4SLinus Torvalds else 12271da177e4SLinus Torvalds rsqe = card->rsq.next + 1; 12281da177e4SLinus Torvalds 12291da177e4SLinus Torvalds if (!(le32_to_cpu(rsqe->word_4) & SAR_RSQE_VALID)) { 12301da177e4SLinus Torvalds RXPRINTK("%s: no entry in RSQ.\n", card->name); 12311da177e4SLinus Torvalds return; 12321da177e4SLinus Torvalds } 12331da177e4SLinus Torvalds 12341da177e4SLinus Torvalds do { 12351da177e4SLinus Torvalds dequeue_rx(card, rsqe); 12361da177e4SLinus Torvalds rsqe->word_4 = 0; 12371da177e4SLinus Torvalds card->rsq.next = rsqe; 12381da177e4SLinus Torvalds if (card->rsq.next == card->rsq.last) 12391da177e4SLinus Torvalds rsqe = card->rsq.base; 12401da177e4SLinus Torvalds else 12411da177e4SLinus Torvalds rsqe = card->rsq.next + 1; 12421da177e4SLinus Torvalds } while (le32_to_cpu(rsqe->word_4) & SAR_RSQE_VALID); 12431da177e4SLinus Torvalds 12441da177e4SLinus Torvalds writel((unsigned long) card->rsq.next - (unsigned long) card->rsq.base, 12451da177e4SLinus Torvalds SAR_REG_RSQH); 12461da177e4SLinus Torvalds } 12471da177e4SLinus Torvalds 12481da177e4SLinus Torvalds static void 12491da177e4SLinus Torvalds idt77252_rx_raw(struct idt77252_dev *card) 12501da177e4SLinus Torvalds { 12511da177e4SLinus Torvalds struct sk_buff *queue; 12521da177e4SLinus Torvalds u32 head, tail; 12531da177e4SLinus Torvalds struct atm_vcc *vcc; 12541da177e4SLinus Torvalds struct vc_map *vc; 12551da177e4SLinus Torvalds struct sk_buff *sb; 12561da177e4SLinus Torvalds 12571da177e4SLinus Torvalds if (card->raw_cell_head == NULL) { 12581da177e4SLinus Torvalds u32 handle = le32_to_cpu(*(card->raw_cell_hnd + 1)); 12591da177e4SLinus Torvalds card->raw_cell_head = sb_pool_skb(card, handle); 12601da177e4SLinus Torvalds } 12611da177e4SLinus Torvalds 12621da177e4SLinus Torvalds queue = card->raw_cell_head; 12631da177e4SLinus Torvalds if (!queue) 12641da177e4SLinus Torvalds return; 12651da177e4SLinus Torvalds 12661da177e4SLinus Torvalds head = IDT77252_PRV_PADDR(queue) + (queue->data - queue->head - 16); 12671da177e4SLinus Torvalds tail = readl(SAR_REG_RAWCT); 12681da177e4SLinus Torvalds 12691da177e4SLinus Torvalds pci_dma_sync_single_for_cpu(card->pcidev, IDT77252_PRV_PADDR(queue), 12701da177e4SLinus Torvalds queue->end - queue->head - 16, 12711da177e4SLinus Torvalds PCI_DMA_FROMDEVICE); 12721da177e4SLinus Torvalds 12731da177e4SLinus Torvalds while (head != tail) { 12741da177e4SLinus Torvalds unsigned int vpi, vci, pti; 12751da177e4SLinus Torvalds u32 header; 12761da177e4SLinus Torvalds 12771da177e4SLinus Torvalds header = le32_to_cpu(*(u32 *) &queue->data[0]); 12781da177e4SLinus Torvalds 12791da177e4SLinus Torvalds vpi = (header & ATM_HDR_VPI_MASK) >> ATM_HDR_VPI_SHIFT; 12801da177e4SLinus Torvalds vci = (header & ATM_HDR_VCI_MASK) >> ATM_HDR_VCI_SHIFT; 12811da177e4SLinus Torvalds pti = (header & ATM_HDR_PTI_MASK) >> ATM_HDR_PTI_SHIFT; 12821da177e4SLinus Torvalds 12831da177e4SLinus Torvalds #ifdef CONFIG_ATM_IDT77252_DEBUG 12841da177e4SLinus Torvalds if (debug & DBG_RAW_CELL) { 12851da177e4SLinus Torvalds int i; 12861da177e4SLinus Torvalds 12871da177e4SLinus Torvalds printk("%s: raw cell %x.%02x.%04x.%x.%x\n", 12881da177e4SLinus Torvalds card->name, (header >> 28) & 0x000f, 12891da177e4SLinus Torvalds (header >> 20) & 0x00ff, 12901da177e4SLinus Torvalds (header >> 4) & 0xffff, 12911da177e4SLinus Torvalds (header >> 1) & 0x0007, 12921da177e4SLinus Torvalds (header >> 0) & 0x0001); 12931da177e4SLinus Torvalds for (i = 16; i < 64; i++) 12941da177e4SLinus Torvalds printk(" %02x", queue->data[i]); 12951da177e4SLinus Torvalds printk("\n"); 12961da177e4SLinus Torvalds } 12971da177e4SLinus Torvalds #endif 12981da177e4SLinus Torvalds 12991da177e4SLinus Torvalds if (vpi >= (1<<card->vpibits) || vci >= (1<<card->vcibits)) { 13001da177e4SLinus Torvalds RPRINTK("%s: SDU received for out-of-range vc %u.%u\n", 13011da177e4SLinus Torvalds card->name, vpi, vci); 13021da177e4SLinus Torvalds goto drop; 13031da177e4SLinus Torvalds } 13041da177e4SLinus Torvalds 13051da177e4SLinus Torvalds vc = card->vcs[VPCI2VC(card, vpi, vci)]; 13061da177e4SLinus Torvalds if (!vc || !test_bit(VCF_RX, &vc->flags)) { 13071da177e4SLinus Torvalds RPRINTK("%s: SDU received on non RX vc %u.%u\n", 13081da177e4SLinus Torvalds card->name, vpi, vci); 13091da177e4SLinus Torvalds goto drop; 13101da177e4SLinus Torvalds } 13111da177e4SLinus Torvalds 13121da177e4SLinus Torvalds vcc = vc->rx_vcc; 13131da177e4SLinus Torvalds 13141da177e4SLinus Torvalds if (vcc->qos.aal != ATM_AAL0) { 13151da177e4SLinus Torvalds RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n", 13161da177e4SLinus Torvalds card->name, vpi, vci); 13171da177e4SLinus Torvalds atomic_inc(&vcc->stats->rx_drop); 13181da177e4SLinus Torvalds goto drop; 13191da177e4SLinus Torvalds } 13201da177e4SLinus Torvalds 13211da177e4SLinus Torvalds if ((sb = dev_alloc_skb(64)) == NULL) { 13221da177e4SLinus Torvalds printk("%s: Can't allocate buffers for AAL0.\n", 13231da177e4SLinus Torvalds card->name); 13241da177e4SLinus Torvalds atomic_inc(&vcc->stats->rx_err); 13251da177e4SLinus Torvalds goto drop; 13261da177e4SLinus Torvalds } 13271da177e4SLinus Torvalds 13281da177e4SLinus Torvalds if (!atm_charge(vcc, sb->truesize)) { 13291da177e4SLinus Torvalds RXPRINTK("%s: atm_charge() dropped AAL0 packets.\n", 13301da177e4SLinus Torvalds card->name); 13311da177e4SLinus Torvalds dev_kfree_skb(sb); 13321da177e4SLinus Torvalds goto drop; 13331da177e4SLinus Torvalds } 13341da177e4SLinus Torvalds 13351da177e4SLinus Torvalds *((u32 *) sb->data) = header; 13361da177e4SLinus Torvalds skb_put(sb, sizeof(u32)); 13371da177e4SLinus Torvalds memcpy(skb_put(sb, ATM_CELL_PAYLOAD), &(queue->data[16]), 13381da177e4SLinus Torvalds ATM_CELL_PAYLOAD); 13391da177e4SLinus Torvalds 13401da177e4SLinus Torvalds ATM_SKB(sb)->vcc = vcc; 1341a61bbcf2SPatrick McHardy __net_timestamp(sb); 13421da177e4SLinus Torvalds vcc->push(vcc, sb); 13431da177e4SLinus Torvalds atomic_inc(&vcc->stats->rx); 13441da177e4SLinus Torvalds 13451da177e4SLinus Torvalds drop: 13461da177e4SLinus Torvalds skb_pull(queue, 64); 13471da177e4SLinus Torvalds 13481da177e4SLinus Torvalds head = IDT77252_PRV_PADDR(queue) 13491da177e4SLinus Torvalds + (queue->data - queue->head - 16); 13501da177e4SLinus Torvalds 13511da177e4SLinus Torvalds if (queue->len < 128) { 13521da177e4SLinus Torvalds struct sk_buff *next; 13531da177e4SLinus Torvalds u32 handle; 13541da177e4SLinus Torvalds 13551da177e4SLinus Torvalds head = le32_to_cpu(*(u32 *) &queue->data[0]); 13561da177e4SLinus Torvalds handle = le32_to_cpu(*(u32 *) &queue->data[4]); 13571da177e4SLinus Torvalds 13581da177e4SLinus Torvalds next = sb_pool_skb(card, handle); 13591da177e4SLinus Torvalds recycle_rx_skb(card, queue); 13601da177e4SLinus Torvalds 13611da177e4SLinus Torvalds if (next) { 13621da177e4SLinus Torvalds card->raw_cell_head = next; 13631da177e4SLinus Torvalds queue = card->raw_cell_head; 13641da177e4SLinus Torvalds pci_dma_sync_single_for_cpu(card->pcidev, 13651da177e4SLinus Torvalds IDT77252_PRV_PADDR(queue), 13661da177e4SLinus Torvalds queue->end - queue->data, 13671da177e4SLinus Torvalds PCI_DMA_FROMDEVICE); 13681da177e4SLinus Torvalds } else { 13691da177e4SLinus Torvalds card->raw_cell_head = NULL; 13701da177e4SLinus Torvalds printk("%s: raw cell queue overrun\n", 13711da177e4SLinus Torvalds card->name); 13721da177e4SLinus Torvalds break; 13731da177e4SLinus Torvalds } 13741da177e4SLinus Torvalds } 13751da177e4SLinus Torvalds } 13761da177e4SLinus Torvalds } 13771da177e4SLinus Torvalds 13781da177e4SLinus Torvalds 13791da177e4SLinus Torvalds /*****************************************************************************/ 13801da177e4SLinus Torvalds /* */ 13811da177e4SLinus Torvalds /* TSQ Handling */ 13821da177e4SLinus Torvalds /* */ 13831da177e4SLinus Torvalds /*****************************************************************************/ 13841da177e4SLinus Torvalds 13851da177e4SLinus Torvalds static int 13861da177e4SLinus Torvalds init_tsq(struct idt77252_dev *card) 13871da177e4SLinus Torvalds { 13881da177e4SLinus Torvalds struct tsq_entry *tsqe; 13891da177e4SLinus Torvalds 13901da177e4SLinus Torvalds card->tsq.base = pci_alloc_consistent(card->pcidev, RSQSIZE, 13911da177e4SLinus Torvalds &card->tsq.paddr); 13921da177e4SLinus Torvalds if (card->tsq.base == NULL) { 13931da177e4SLinus Torvalds printk("%s: can't allocate TSQ.\n", card->name); 13941da177e4SLinus Torvalds return -1; 13951da177e4SLinus Torvalds } 13961da177e4SLinus Torvalds memset(card->tsq.base, 0, TSQSIZE); 13971da177e4SLinus Torvalds 13981da177e4SLinus Torvalds card->tsq.last = card->tsq.base + TSQ_NUM_ENTRIES - 1; 13991da177e4SLinus Torvalds card->tsq.next = card->tsq.last; 14001da177e4SLinus Torvalds for (tsqe = card->tsq.base; tsqe <= card->tsq.last; tsqe++) 14011da177e4SLinus Torvalds tsqe->word_2 = cpu_to_le32(SAR_TSQE_INVALID); 14021da177e4SLinus Torvalds 14031da177e4SLinus Torvalds writel(card->tsq.paddr, SAR_REG_TSQB); 14041da177e4SLinus Torvalds writel((unsigned long) card->tsq.next - (unsigned long) card->tsq.base, 14051da177e4SLinus Torvalds SAR_REG_TSQH); 14061da177e4SLinus Torvalds 14071da177e4SLinus Torvalds return 0; 14081da177e4SLinus Torvalds } 14091da177e4SLinus Torvalds 14101da177e4SLinus Torvalds static void 14111da177e4SLinus Torvalds deinit_tsq(struct idt77252_dev *card) 14121da177e4SLinus Torvalds { 14131da177e4SLinus Torvalds pci_free_consistent(card->pcidev, TSQSIZE, 14141da177e4SLinus Torvalds card->tsq.base, card->tsq.paddr); 14151da177e4SLinus Torvalds } 14161da177e4SLinus Torvalds 14171da177e4SLinus Torvalds static void 14181da177e4SLinus Torvalds idt77252_tx(struct idt77252_dev *card) 14191da177e4SLinus Torvalds { 14201da177e4SLinus Torvalds struct tsq_entry *tsqe; 14211da177e4SLinus Torvalds unsigned int vpi, vci; 14221da177e4SLinus Torvalds struct vc_map *vc; 14231da177e4SLinus Torvalds u32 conn, stat; 14241da177e4SLinus Torvalds 14251da177e4SLinus Torvalds if (card->tsq.next == card->tsq.last) 14261da177e4SLinus Torvalds tsqe = card->tsq.base; 14271da177e4SLinus Torvalds else 14281da177e4SLinus Torvalds tsqe = card->tsq.next + 1; 14291da177e4SLinus Torvalds 14301da177e4SLinus Torvalds TXPRINTK("idt77252_tx: tsq %p: base %p, next %p, last %p\n", tsqe, 14311da177e4SLinus Torvalds card->tsq.base, card->tsq.next, card->tsq.last); 14321da177e4SLinus Torvalds TXPRINTK("idt77252_tx: tsqb %08x, tsqt %08x, tsqh %08x, \n", 14331da177e4SLinus Torvalds readl(SAR_REG_TSQB), 14341da177e4SLinus Torvalds readl(SAR_REG_TSQT), 14351da177e4SLinus Torvalds readl(SAR_REG_TSQH)); 14361da177e4SLinus Torvalds 14371da177e4SLinus Torvalds stat = le32_to_cpu(tsqe->word_2); 14381da177e4SLinus Torvalds 14391da177e4SLinus Torvalds if (stat & SAR_TSQE_INVALID) 14401da177e4SLinus Torvalds return; 14411da177e4SLinus Torvalds 14421da177e4SLinus Torvalds do { 14431da177e4SLinus Torvalds TXPRINTK("tsqe: 0x%p [0x%08x 0x%08x]\n", tsqe, 14441da177e4SLinus Torvalds le32_to_cpu(tsqe->word_1), 14451da177e4SLinus Torvalds le32_to_cpu(tsqe->word_2)); 14461da177e4SLinus Torvalds 14471da177e4SLinus Torvalds switch (stat & SAR_TSQE_TYPE) { 14481da177e4SLinus Torvalds case SAR_TSQE_TYPE_TIMER: 14491da177e4SLinus Torvalds TXPRINTK("%s: Timer RollOver detected.\n", card->name); 14501da177e4SLinus Torvalds break; 14511da177e4SLinus Torvalds 14521da177e4SLinus Torvalds case SAR_TSQE_TYPE_IDLE: 14531da177e4SLinus Torvalds 14541da177e4SLinus Torvalds conn = le32_to_cpu(tsqe->word_1); 14551da177e4SLinus Torvalds 14561da177e4SLinus Torvalds if (SAR_TSQE_TAG(stat) == 0x10) { 14571da177e4SLinus Torvalds #ifdef NOTDEF 14581da177e4SLinus Torvalds printk("%s: Connection %d halted.\n", 14591da177e4SLinus Torvalds card->name, 14601da177e4SLinus Torvalds le32_to_cpu(tsqe->word_1) & 0x1fff); 14611da177e4SLinus Torvalds #endif 14621da177e4SLinus Torvalds break; 14631da177e4SLinus Torvalds } 14641da177e4SLinus Torvalds 14651da177e4SLinus Torvalds vc = card->vcs[conn & 0x1fff]; 14661da177e4SLinus Torvalds if (!vc) { 14671da177e4SLinus Torvalds printk("%s: could not find VC from conn %d\n", 14681da177e4SLinus Torvalds card->name, conn & 0x1fff); 14691da177e4SLinus Torvalds break; 14701da177e4SLinus Torvalds } 14711da177e4SLinus Torvalds 14721da177e4SLinus Torvalds printk("%s: Connection %d IDLE.\n", 14731da177e4SLinus Torvalds card->name, vc->index); 14741da177e4SLinus Torvalds 14751da177e4SLinus Torvalds set_bit(VCF_IDLE, &vc->flags); 14761da177e4SLinus Torvalds break; 14771da177e4SLinus Torvalds 14781da177e4SLinus Torvalds case SAR_TSQE_TYPE_TSR: 14791da177e4SLinus Torvalds 14801da177e4SLinus Torvalds conn = le32_to_cpu(tsqe->word_1); 14811da177e4SLinus Torvalds 14821da177e4SLinus Torvalds vc = card->vcs[conn & 0x1fff]; 14831da177e4SLinus Torvalds if (!vc) { 14841da177e4SLinus Torvalds printk("%s: no VC at index %d\n", 14851da177e4SLinus Torvalds card->name, 14861da177e4SLinus Torvalds le32_to_cpu(tsqe->word_1) & 0x1fff); 14871da177e4SLinus Torvalds break; 14881da177e4SLinus Torvalds } 14891da177e4SLinus Torvalds 14901da177e4SLinus Torvalds drain_scq(card, vc); 14911da177e4SLinus Torvalds break; 14921da177e4SLinus Torvalds 14931da177e4SLinus Torvalds case SAR_TSQE_TYPE_TBD_COMP: 14941da177e4SLinus Torvalds 14951da177e4SLinus Torvalds conn = le32_to_cpu(tsqe->word_1); 14961da177e4SLinus Torvalds 14971da177e4SLinus Torvalds vpi = (conn >> SAR_TBD_VPI_SHIFT) & 0x00ff; 14981da177e4SLinus Torvalds vci = (conn >> SAR_TBD_VCI_SHIFT) & 0xffff; 14991da177e4SLinus Torvalds 15001da177e4SLinus Torvalds if (vpi >= (1 << card->vpibits) || 15011da177e4SLinus Torvalds vci >= (1 << card->vcibits)) { 15021da177e4SLinus Torvalds printk("%s: TBD complete: " 15031da177e4SLinus Torvalds "out of range VPI.VCI %u.%u\n", 15041da177e4SLinus Torvalds card->name, vpi, vci); 15051da177e4SLinus Torvalds break; 15061da177e4SLinus Torvalds } 15071da177e4SLinus Torvalds 15081da177e4SLinus Torvalds vc = card->vcs[VPCI2VC(card, vpi, vci)]; 15091da177e4SLinus Torvalds if (!vc) { 15101da177e4SLinus Torvalds printk("%s: TBD complete: " 15111da177e4SLinus Torvalds "no VC at VPI.VCI %u.%u\n", 15121da177e4SLinus Torvalds card->name, vpi, vci); 15131da177e4SLinus Torvalds break; 15141da177e4SLinus Torvalds } 15151da177e4SLinus Torvalds 15161da177e4SLinus Torvalds drain_scq(card, vc); 15171da177e4SLinus Torvalds break; 15181da177e4SLinus Torvalds } 15191da177e4SLinus Torvalds 15201da177e4SLinus Torvalds tsqe->word_2 = cpu_to_le32(SAR_TSQE_INVALID); 15211da177e4SLinus Torvalds 15221da177e4SLinus Torvalds card->tsq.next = tsqe; 15231da177e4SLinus Torvalds if (card->tsq.next == card->tsq.last) 15241da177e4SLinus Torvalds tsqe = card->tsq.base; 15251da177e4SLinus Torvalds else 15261da177e4SLinus Torvalds tsqe = card->tsq.next + 1; 15271da177e4SLinus Torvalds 15281da177e4SLinus Torvalds TXPRINTK("tsqe: %p: base %p, next %p, last %p\n", tsqe, 15291da177e4SLinus Torvalds card->tsq.base, card->tsq.next, card->tsq.last); 15301da177e4SLinus Torvalds 15311da177e4SLinus Torvalds stat = le32_to_cpu(tsqe->word_2); 15321da177e4SLinus Torvalds 15331da177e4SLinus Torvalds } while (!(stat & SAR_TSQE_INVALID)); 15341da177e4SLinus Torvalds 15351da177e4SLinus Torvalds writel((unsigned long)card->tsq.next - (unsigned long)card->tsq.base, 15361da177e4SLinus Torvalds SAR_REG_TSQH); 15371da177e4SLinus Torvalds 15381da177e4SLinus Torvalds XPRINTK("idt77252_tx-after writel%d: TSQ head = 0x%x, tail = 0x%x, next = 0x%p.\n", 15391da177e4SLinus Torvalds card->index, readl(SAR_REG_TSQH), 15401da177e4SLinus Torvalds readl(SAR_REG_TSQT), card->tsq.next); 15411da177e4SLinus Torvalds } 15421da177e4SLinus Torvalds 15431da177e4SLinus Torvalds 15441da177e4SLinus Torvalds static void 15451da177e4SLinus Torvalds tst_timer(unsigned long data) 15461da177e4SLinus Torvalds { 15471da177e4SLinus Torvalds struct idt77252_dev *card = (struct idt77252_dev *)data; 15481da177e4SLinus Torvalds unsigned long base, idle, jump; 15491da177e4SLinus Torvalds unsigned long flags; 15501da177e4SLinus Torvalds u32 pc; 15511da177e4SLinus Torvalds int e; 15521da177e4SLinus Torvalds 15531da177e4SLinus Torvalds spin_lock_irqsave(&card->tst_lock, flags); 15541da177e4SLinus Torvalds 15551da177e4SLinus Torvalds base = card->tst[card->tst_index]; 15561da177e4SLinus Torvalds idle = card->tst[card->tst_index ^ 1]; 15571da177e4SLinus Torvalds 15581da177e4SLinus Torvalds if (test_bit(TST_SWITCH_WAIT, &card->tst_state)) { 15591da177e4SLinus Torvalds jump = base + card->tst_size - 2; 15601da177e4SLinus Torvalds 15611da177e4SLinus Torvalds pc = readl(SAR_REG_NOW) >> 2; 15621da177e4SLinus Torvalds if ((pc ^ idle) & ~(card->tst_size - 1)) { 15631da177e4SLinus Torvalds mod_timer(&card->tst_timer, jiffies + 1); 15641da177e4SLinus Torvalds goto out; 15651da177e4SLinus Torvalds } 15661da177e4SLinus Torvalds 15671da177e4SLinus Torvalds clear_bit(TST_SWITCH_WAIT, &card->tst_state); 15681da177e4SLinus Torvalds 15691da177e4SLinus Torvalds card->tst_index ^= 1; 15701da177e4SLinus Torvalds write_sram(card, jump, TSTE_OPC_JMP | (base << 2)); 15711da177e4SLinus Torvalds 15721da177e4SLinus Torvalds base = card->tst[card->tst_index]; 15731da177e4SLinus Torvalds idle = card->tst[card->tst_index ^ 1]; 15741da177e4SLinus Torvalds 15751da177e4SLinus Torvalds for (e = 0; e < card->tst_size - 2; e++) { 15761da177e4SLinus Torvalds if (card->soft_tst[e].tste & TSTE_PUSH_IDLE) { 15771da177e4SLinus Torvalds write_sram(card, idle + e, 15781da177e4SLinus Torvalds card->soft_tst[e].tste & TSTE_MASK); 15791da177e4SLinus Torvalds card->soft_tst[e].tste &= ~(TSTE_PUSH_IDLE); 15801da177e4SLinus Torvalds } 15811da177e4SLinus Torvalds } 15821da177e4SLinus Torvalds } 15831da177e4SLinus Torvalds 15841da177e4SLinus Torvalds if (test_and_clear_bit(TST_SWITCH_PENDING, &card->tst_state)) { 15851da177e4SLinus Torvalds 15861da177e4SLinus Torvalds for (e = 0; e < card->tst_size - 2; e++) { 15871da177e4SLinus Torvalds if (card->soft_tst[e].tste & TSTE_PUSH_ACTIVE) { 15881da177e4SLinus Torvalds write_sram(card, idle + e, 15891da177e4SLinus Torvalds card->soft_tst[e].tste & TSTE_MASK); 15901da177e4SLinus Torvalds card->soft_tst[e].tste &= ~(TSTE_PUSH_ACTIVE); 15911da177e4SLinus Torvalds card->soft_tst[e].tste |= TSTE_PUSH_IDLE; 15921da177e4SLinus Torvalds } 15931da177e4SLinus Torvalds } 15941da177e4SLinus Torvalds 15951da177e4SLinus Torvalds jump = base + card->tst_size - 2; 15961da177e4SLinus Torvalds 15971da177e4SLinus Torvalds write_sram(card, jump, TSTE_OPC_NULL); 15981da177e4SLinus Torvalds set_bit(TST_SWITCH_WAIT, &card->tst_state); 15991da177e4SLinus Torvalds 16001da177e4SLinus Torvalds mod_timer(&card->tst_timer, jiffies + 1); 16011da177e4SLinus Torvalds } 16021da177e4SLinus Torvalds 16031da177e4SLinus Torvalds out: 16041da177e4SLinus Torvalds spin_unlock_irqrestore(&card->tst_lock, flags); 16051da177e4SLinus Torvalds } 16061da177e4SLinus Torvalds 16071da177e4SLinus Torvalds static int 16081da177e4SLinus Torvalds __fill_tst(struct idt77252_dev *card, struct vc_map *vc, 16091da177e4SLinus Torvalds int n, unsigned int opc) 16101da177e4SLinus Torvalds { 16111da177e4SLinus Torvalds unsigned long cl, avail; 16121da177e4SLinus Torvalds unsigned long idle; 16131da177e4SLinus Torvalds int e, r; 16141da177e4SLinus Torvalds u32 data; 16151da177e4SLinus Torvalds 16161da177e4SLinus Torvalds avail = card->tst_size - 2; 16171da177e4SLinus Torvalds for (e = 0; e < avail; e++) { 16181da177e4SLinus Torvalds if (card->soft_tst[e].vc == NULL) 16191da177e4SLinus Torvalds break; 16201da177e4SLinus Torvalds } 16211da177e4SLinus Torvalds if (e >= avail) { 16221da177e4SLinus Torvalds printk("%s: No free TST entries found\n", card->name); 16231da177e4SLinus Torvalds return -1; 16241da177e4SLinus Torvalds } 16251da177e4SLinus Torvalds 16261da177e4SLinus Torvalds NPRINTK("%s: conn %d: first TST entry at %d.\n", 16271da177e4SLinus Torvalds card->name, vc ? vc->index : -1, e); 16281da177e4SLinus Torvalds 16291da177e4SLinus Torvalds r = n; 16301da177e4SLinus Torvalds cl = avail; 16311da177e4SLinus Torvalds data = opc & TSTE_OPC_MASK; 16321da177e4SLinus Torvalds if (vc && (opc != TSTE_OPC_NULL)) 16331da177e4SLinus Torvalds data = opc | vc->index; 16341da177e4SLinus Torvalds 16351da177e4SLinus Torvalds idle = card->tst[card->tst_index ^ 1]; 16361da177e4SLinus Torvalds 16371da177e4SLinus Torvalds /* 16381da177e4SLinus Torvalds * Fill Soft TST. 16391da177e4SLinus Torvalds */ 16401da177e4SLinus Torvalds while (r > 0) { 16411da177e4SLinus Torvalds if ((cl >= avail) && (card->soft_tst[e].vc == NULL)) { 16421da177e4SLinus Torvalds if (vc) 16431da177e4SLinus Torvalds card->soft_tst[e].vc = vc; 16441da177e4SLinus Torvalds else 16451da177e4SLinus Torvalds card->soft_tst[e].vc = (void *)-1; 16461da177e4SLinus Torvalds 16471da177e4SLinus Torvalds card->soft_tst[e].tste = data; 16481da177e4SLinus Torvalds if (timer_pending(&card->tst_timer)) 16491da177e4SLinus Torvalds card->soft_tst[e].tste |= TSTE_PUSH_ACTIVE; 16501da177e4SLinus Torvalds else { 16511da177e4SLinus Torvalds write_sram(card, idle + e, data); 16521da177e4SLinus Torvalds card->soft_tst[e].tste |= TSTE_PUSH_IDLE; 16531da177e4SLinus Torvalds } 16541da177e4SLinus Torvalds 16551da177e4SLinus Torvalds cl -= card->tst_size; 16561da177e4SLinus Torvalds r--; 16571da177e4SLinus Torvalds } 16581da177e4SLinus Torvalds 16591da177e4SLinus Torvalds if (++e == avail) 16601da177e4SLinus Torvalds e = 0; 16611da177e4SLinus Torvalds cl += n; 16621da177e4SLinus Torvalds } 16631da177e4SLinus Torvalds 16641da177e4SLinus Torvalds return 0; 16651da177e4SLinus Torvalds } 16661da177e4SLinus Torvalds 16671da177e4SLinus Torvalds static int 16681da177e4SLinus Torvalds fill_tst(struct idt77252_dev *card, struct vc_map *vc, int n, unsigned int opc) 16691da177e4SLinus Torvalds { 16701da177e4SLinus Torvalds unsigned long flags; 16711da177e4SLinus Torvalds int res; 16721da177e4SLinus Torvalds 16731da177e4SLinus Torvalds spin_lock_irqsave(&card->tst_lock, flags); 16741da177e4SLinus Torvalds 16751da177e4SLinus Torvalds res = __fill_tst(card, vc, n, opc); 16761da177e4SLinus Torvalds 16771da177e4SLinus Torvalds set_bit(TST_SWITCH_PENDING, &card->tst_state); 16781da177e4SLinus Torvalds if (!timer_pending(&card->tst_timer)) 16791da177e4SLinus Torvalds mod_timer(&card->tst_timer, jiffies + 1); 16801da177e4SLinus Torvalds 16811da177e4SLinus Torvalds spin_unlock_irqrestore(&card->tst_lock, flags); 16821da177e4SLinus Torvalds return res; 16831da177e4SLinus Torvalds } 16841da177e4SLinus Torvalds 16851da177e4SLinus Torvalds static int 16861da177e4SLinus Torvalds __clear_tst(struct idt77252_dev *card, struct vc_map *vc) 16871da177e4SLinus Torvalds { 16881da177e4SLinus Torvalds unsigned long idle; 16891da177e4SLinus Torvalds int e; 16901da177e4SLinus Torvalds 16911da177e4SLinus Torvalds idle = card->tst[card->tst_index ^ 1]; 16921da177e4SLinus Torvalds 16931da177e4SLinus Torvalds for (e = 0; e < card->tst_size - 2; e++) { 16941da177e4SLinus Torvalds if (card->soft_tst[e].vc == vc) { 16951da177e4SLinus Torvalds card->soft_tst[e].vc = NULL; 16961da177e4SLinus Torvalds 16971da177e4SLinus Torvalds card->soft_tst[e].tste = TSTE_OPC_VAR; 16981da177e4SLinus Torvalds if (timer_pending(&card->tst_timer)) 16991da177e4SLinus Torvalds card->soft_tst[e].tste |= TSTE_PUSH_ACTIVE; 17001da177e4SLinus Torvalds else { 17011da177e4SLinus Torvalds write_sram(card, idle + e, TSTE_OPC_VAR); 17021da177e4SLinus Torvalds card->soft_tst[e].tste |= TSTE_PUSH_IDLE; 17031da177e4SLinus Torvalds } 17041da177e4SLinus Torvalds } 17051da177e4SLinus Torvalds } 17061da177e4SLinus Torvalds 17071da177e4SLinus Torvalds return 0; 17081da177e4SLinus Torvalds } 17091da177e4SLinus Torvalds 17101da177e4SLinus Torvalds static int 17111da177e4SLinus Torvalds clear_tst(struct idt77252_dev *card, struct vc_map *vc) 17121da177e4SLinus Torvalds { 17131da177e4SLinus Torvalds unsigned long flags; 17141da177e4SLinus Torvalds int res; 17151da177e4SLinus Torvalds 17161da177e4SLinus Torvalds spin_lock_irqsave(&card->tst_lock, flags); 17171da177e4SLinus Torvalds 17181da177e4SLinus Torvalds res = __clear_tst(card, vc); 17191da177e4SLinus Torvalds 17201da177e4SLinus Torvalds set_bit(TST_SWITCH_PENDING, &card->tst_state); 17211da177e4SLinus Torvalds if (!timer_pending(&card->tst_timer)) 17221da177e4SLinus Torvalds mod_timer(&card->tst_timer, jiffies + 1); 17231da177e4SLinus Torvalds 17241da177e4SLinus Torvalds spin_unlock_irqrestore(&card->tst_lock, flags); 17251da177e4SLinus Torvalds return res; 17261da177e4SLinus Torvalds } 17271da177e4SLinus Torvalds 17281da177e4SLinus Torvalds static int 17291da177e4SLinus Torvalds change_tst(struct idt77252_dev *card, struct vc_map *vc, 17301da177e4SLinus Torvalds int n, unsigned int opc) 17311da177e4SLinus Torvalds { 17321da177e4SLinus Torvalds unsigned long flags; 17331da177e4SLinus Torvalds int res; 17341da177e4SLinus Torvalds 17351da177e4SLinus Torvalds spin_lock_irqsave(&card->tst_lock, flags); 17361da177e4SLinus Torvalds 17371da177e4SLinus Torvalds __clear_tst(card, vc); 17381da177e4SLinus Torvalds res = __fill_tst(card, vc, n, opc); 17391da177e4SLinus Torvalds 17401da177e4SLinus Torvalds set_bit(TST_SWITCH_PENDING, &card->tst_state); 17411da177e4SLinus Torvalds if (!timer_pending(&card->tst_timer)) 17421da177e4SLinus Torvalds mod_timer(&card->tst_timer, jiffies + 1); 17431da177e4SLinus Torvalds 17441da177e4SLinus Torvalds spin_unlock_irqrestore(&card->tst_lock, flags); 17451da177e4SLinus Torvalds return res; 17461da177e4SLinus Torvalds } 17471da177e4SLinus Torvalds 17481da177e4SLinus Torvalds 17491da177e4SLinus Torvalds static int 17501da177e4SLinus Torvalds set_tct(struct idt77252_dev *card, struct vc_map *vc) 17511da177e4SLinus Torvalds { 17521da177e4SLinus Torvalds unsigned long tct; 17531da177e4SLinus Torvalds 17541da177e4SLinus Torvalds tct = (unsigned long) (card->tct_base + vc->index * SAR_SRAM_TCT_SIZE); 17551da177e4SLinus Torvalds 17561da177e4SLinus Torvalds switch (vc->class) { 17571da177e4SLinus Torvalds case SCHED_CBR: 17581da177e4SLinus Torvalds OPRINTK("%s: writing TCT at 0x%lx, SCD 0x%lx.\n", 17591da177e4SLinus Torvalds card->name, tct, vc->scq->scd); 17601da177e4SLinus Torvalds 17611da177e4SLinus Torvalds write_sram(card, tct + 0, TCT_CBR | vc->scq->scd); 17621da177e4SLinus Torvalds write_sram(card, tct + 1, 0); 17631da177e4SLinus Torvalds write_sram(card, tct + 2, 0); 17641da177e4SLinus Torvalds write_sram(card, tct + 3, 0); 17651da177e4SLinus Torvalds write_sram(card, tct + 4, 0); 17661da177e4SLinus Torvalds write_sram(card, tct + 5, 0); 17671da177e4SLinus Torvalds write_sram(card, tct + 6, 0); 17681da177e4SLinus Torvalds write_sram(card, tct + 7, 0); 17691da177e4SLinus Torvalds break; 17701da177e4SLinus Torvalds 17711da177e4SLinus Torvalds case SCHED_UBR: 17721da177e4SLinus Torvalds OPRINTK("%s: writing TCT at 0x%lx, SCD 0x%lx.\n", 17731da177e4SLinus Torvalds card->name, tct, vc->scq->scd); 17741da177e4SLinus Torvalds 17751da177e4SLinus Torvalds write_sram(card, tct + 0, TCT_UBR | vc->scq->scd); 17761da177e4SLinus Torvalds write_sram(card, tct + 1, 0); 17771da177e4SLinus Torvalds write_sram(card, tct + 2, TCT_TSIF); 17781da177e4SLinus Torvalds write_sram(card, tct + 3, TCT_HALT | TCT_IDLE); 17791da177e4SLinus Torvalds write_sram(card, tct + 4, 0); 17801da177e4SLinus Torvalds write_sram(card, tct + 5, vc->init_er); 17811da177e4SLinus Torvalds write_sram(card, tct + 6, 0); 17821da177e4SLinus Torvalds write_sram(card, tct + 7, TCT_FLAG_UBR); 17831da177e4SLinus Torvalds break; 17841da177e4SLinus Torvalds 17851da177e4SLinus Torvalds case SCHED_VBR: 17861da177e4SLinus Torvalds case SCHED_ABR: 17871da177e4SLinus Torvalds default: 17881da177e4SLinus Torvalds return -ENOSYS; 17891da177e4SLinus Torvalds } 17901da177e4SLinus Torvalds 17911da177e4SLinus Torvalds return 0; 17921da177e4SLinus Torvalds } 17931da177e4SLinus Torvalds 17941da177e4SLinus Torvalds /*****************************************************************************/ 17951da177e4SLinus Torvalds /* */ 17961da177e4SLinus Torvalds /* FBQ Handling */ 17971da177e4SLinus Torvalds /* */ 17981da177e4SLinus Torvalds /*****************************************************************************/ 17991da177e4SLinus Torvalds 18001da177e4SLinus Torvalds static __inline__ int 18011da177e4SLinus Torvalds idt77252_fbq_level(struct idt77252_dev *card, int queue) 18021da177e4SLinus Torvalds { 18031da177e4SLinus Torvalds return (readl(SAR_REG_STAT) >> (16 + (queue << 2))) & 0x0f; 18041da177e4SLinus Torvalds } 18051da177e4SLinus Torvalds 18061da177e4SLinus Torvalds static __inline__ int 18071da177e4SLinus Torvalds idt77252_fbq_full(struct idt77252_dev *card, int queue) 18081da177e4SLinus Torvalds { 18091da177e4SLinus Torvalds return (readl(SAR_REG_STAT) >> (16 + (queue << 2))) == 0x0f; 18101da177e4SLinus Torvalds } 18111da177e4SLinus Torvalds 18121da177e4SLinus Torvalds static int 18131da177e4SLinus Torvalds push_rx_skb(struct idt77252_dev *card, struct sk_buff *skb, int queue) 18141da177e4SLinus Torvalds { 18151da177e4SLinus Torvalds unsigned long flags; 18161da177e4SLinus Torvalds u32 handle; 18171da177e4SLinus Torvalds u32 addr; 18181da177e4SLinus Torvalds 18191da177e4SLinus Torvalds skb->data = skb->tail = skb->head; 18201da177e4SLinus Torvalds skb->len = 0; 18211da177e4SLinus Torvalds 18221da177e4SLinus Torvalds skb_reserve(skb, 16); 18231da177e4SLinus Torvalds 18241da177e4SLinus Torvalds switch (queue) { 18251da177e4SLinus Torvalds case 0: 18261da177e4SLinus Torvalds skb_put(skb, SAR_FB_SIZE_0); 18271da177e4SLinus Torvalds break; 18281da177e4SLinus Torvalds case 1: 18291da177e4SLinus Torvalds skb_put(skb, SAR_FB_SIZE_1); 18301da177e4SLinus Torvalds break; 18311da177e4SLinus Torvalds case 2: 18321da177e4SLinus Torvalds skb_put(skb, SAR_FB_SIZE_2); 18331da177e4SLinus Torvalds break; 18341da177e4SLinus Torvalds case 3: 18351da177e4SLinus Torvalds skb_put(skb, SAR_FB_SIZE_3); 18361da177e4SLinus Torvalds break; 18371da177e4SLinus Torvalds default: 18381da177e4SLinus Torvalds dev_kfree_skb(skb); 18391da177e4SLinus Torvalds return -1; 18401da177e4SLinus Torvalds } 18411da177e4SLinus Torvalds 18421da177e4SLinus Torvalds if (idt77252_fbq_full(card, queue)) 18431da177e4SLinus Torvalds return -1; 18441da177e4SLinus Torvalds 18451da177e4SLinus Torvalds memset(&skb->data[(skb->len & ~(0x3f)) - 64], 0, 2 * sizeof(u32)); 18461da177e4SLinus Torvalds 18471da177e4SLinus Torvalds handle = IDT77252_PRV_POOL(skb); 18481da177e4SLinus Torvalds addr = IDT77252_PRV_PADDR(skb); 18491da177e4SLinus Torvalds 18501da177e4SLinus Torvalds spin_lock_irqsave(&card->cmd_lock, flags); 18511da177e4SLinus Torvalds writel(handle, card->fbq[queue]); 18521da177e4SLinus Torvalds writel(addr, card->fbq[queue]); 18531da177e4SLinus Torvalds spin_unlock_irqrestore(&card->cmd_lock, flags); 18541da177e4SLinus Torvalds 18551da177e4SLinus Torvalds return 0; 18561da177e4SLinus Torvalds } 18571da177e4SLinus Torvalds 18581da177e4SLinus Torvalds static void 18591da177e4SLinus Torvalds add_rx_skb(struct idt77252_dev *card, int queue, 18601da177e4SLinus Torvalds unsigned int size, unsigned int count) 18611da177e4SLinus Torvalds { 18621da177e4SLinus Torvalds struct sk_buff *skb; 18631da177e4SLinus Torvalds dma_addr_t paddr; 18641da177e4SLinus Torvalds u32 handle; 18651da177e4SLinus Torvalds 18661da177e4SLinus Torvalds while (count--) { 18671da177e4SLinus Torvalds skb = dev_alloc_skb(size); 18681da177e4SLinus Torvalds if (!skb) 18691da177e4SLinus Torvalds return; 18701da177e4SLinus Torvalds 18711da177e4SLinus Torvalds if (sb_pool_add(card, skb, queue)) { 18721da177e4SLinus Torvalds printk("%s: SB POOL full\n", __FUNCTION__); 18731da177e4SLinus Torvalds goto outfree; 18741da177e4SLinus Torvalds } 18751da177e4SLinus Torvalds 18761da177e4SLinus Torvalds paddr = pci_map_single(card->pcidev, skb->data, 18771da177e4SLinus Torvalds skb->end - skb->data, 18781da177e4SLinus Torvalds PCI_DMA_FROMDEVICE); 18791da177e4SLinus Torvalds IDT77252_PRV_PADDR(skb) = paddr; 18801da177e4SLinus Torvalds 18811da177e4SLinus Torvalds if (push_rx_skb(card, skb, queue)) { 18821da177e4SLinus Torvalds printk("%s: FB QUEUE full\n", __FUNCTION__); 18831da177e4SLinus Torvalds goto outunmap; 18841da177e4SLinus Torvalds } 18851da177e4SLinus Torvalds } 18861da177e4SLinus Torvalds 18871da177e4SLinus Torvalds return; 18881da177e4SLinus Torvalds 18891da177e4SLinus Torvalds outunmap: 18901da177e4SLinus Torvalds pci_unmap_single(card->pcidev, IDT77252_PRV_PADDR(skb), 18911da177e4SLinus Torvalds skb->end - skb->data, PCI_DMA_FROMDEVICE); 18921da177e4SLinus Torvalds 18931da177e4SLinus Torvalds handle = IDT77252_PRV_POOL(skb); 18941da177e4SLinus Torvalds card->sbpool[POOL_QUEUE(handle)].skb[POOL_INDEX(handle)] = NULL; 18951da177e4SLinus Torvalds 18961da177e4SLinus Torvalds outfree: 18971da177e4SLinus Torvalds dev_kfree_skb(skb); 18981da177e4SLinus Torvalds } 18991da177e4SLinus Torvalds 19001da177e4SLinus Torvalds 19011da177e4SLinus Torvalds static void 19021da177e4SLinus Torvalds recycle_rx_skb(struct idt77252_dev *card, struct sk_buff *skb) 19031da177e4SLinus Torvalds { 19041da177e4SLinus Torvalds u32 handle = IDT77252_PRV_POOL(skb); 19051da177e4SLinus Torvalds int err; 19061da177e4SLinus Torvalds 19071da177e4SLinus Torvalds pci_dma_sync_single_for_device(card->pcidev, IDT77252_PRV_PADDR(skb), 19081da177e4SLinus Torvalds skb->end - skb->data, PCI_DMA_FROMDEVICE); 19091da177e4SLinus Torvalds 19101da177e4SLinus Torvalds err = push_rx_skb(card, skb, POOL_QUEUE(handle)); 19111da177e4SLinus Torvalds if (err) { 19121da177e4SLinus Torvalds pci_unmap_single(card->pcidev, IDT77252_PRV_PADDR(skb), 19131da177e4SLinus Torvalds skb->end - skb->data, PCI_DMA_FROMDEVICE); 19141da177e4SLinus Torvalds sb_pool_remove(card, skb); 19151da177e4SLinus Torvalds dev_kfree_skb(skb); 19161da177e4SLinus Torvalds } 19171da177e4SLinus Torvalds } 19181da177e4SLinus Torvalds 19191da177e4SLinus Torvalds static void 19201da177e4SLinus Torvalds flush_rx_pool(struct idt77252_dev *card, struct rx_pool *rpp) 19211da177e4SLinus Torvalds { 19221da177e4SLinus Torvalds rpp->len = 0; 19231da177e4SLinus Torvalds rpp->count = 0; 19241da177e4SLinus Torvalds rpp->first = NULL; 19251da177e4SLinus Torvalds rpp->last = &rpp->first; 19261da177e4SLinus Torvalds } 19271da177e4SLinus Torvalds 19281da177e4SLinus Torvalds static void 19291da177e4SLinus Torvalds recycle_rx_pool_skb(struct idt77252_dev *card, struct rx_pool *rpp) 19301da177e4SLinus Torvalds { 19311da177e4SLinus Torvalds struct sk_buff *skb, *next; 19321da177e4SLinus Torvalds int i; 19331da177e4SLinus Torvalds 19341da177e4SLinus Torvalds skb = rpp->first; 19351da177e4SLinus Torvalds for (i = 0; i < rpp->count; i++) { 19361da177e4SLinus Torvalds next = skb->next; 19371da177e4SLinus Torvalds skb->next = NULL; 19381da177e4SLinus Torvalds recycle_rx_skb(card, skb); 19391da177e4SLinus Torvalds skb = next; 19401da177e4SLinus Torvalds } 19411da177e4SLinus Torvalds flush_rx_pool(card, rpp); 19421da177e4SLinus Torvalds } 19431da177e4SLinus Torvalds 19441da177e4SLinus Torvalds /*****************************************************************************/ 19451da177e4SLinus Torvalds /* */ 19461da177e4SLinus Torvalds /* ATM Interface */ 19471da177e4SLinus Torvalds /* */ 19481da177e4SLinus Torvalds /*****************************************************************************/ 19491da177e4SLinus Torvalds 19501da177e4SLinus Torvalds static void 19511da177e4SLinus Torvalds idt77252_phy_put(struct atm_dev *dev, unsigned char value, unsigned long addr) 19521da177e4SLinus Torvalds { 19531da177e4SLinus Torvalds write_utility(dev->dev_data, 0x100 + (addr & 0x1ff), value); 19541da177e4SLinus Torvalds } 19551da177e4SLinus Torvalds 19561da177e4SLinus Torvalds static unsigned char 19571da177e4SLinus Torvalds idt77252_phy_get(struct atm_dev *dev, unsigned long addr) 19581da177e4SLinus Torvalds { 19591da177e4SLinus Torvalds return read_utility(dev->dev_data, 0x100 + (addr & 0x1ff)); 19601da177e4SLinus Torvalds } 19611da177e4SLinus Torvalds 19621da177e4SLinus Torvalds static inline int 19631da177e4SLinus Torvalds idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam) 19641da177e4SLinus Torvalds { 19651da177e4SLinus Torvalds struct atm_dev *dev = vcc->dev; 19661da177e4SLinus Torvalds struct idt77252_dev *card = dev->dev_data; 19671da177e4SLinus Torvalds struct vc_map *vc = vcc->dev_data; 19681da177e4SLinus Torvalds int err; 19691da177e4SLinus Torvalds 19701da177e4SLinus Torvalds if (vc == NULL) { 19711da177e4SLinus Torvalds printk("%s: NULL connection in send().\n", card->name); 19721da177e4SLinus Torvalds atomic_inc(&vcc->stats->tx_err); 19731da177e4SLinus Torvalds dev_kfree_skb(skb); 19741da177e4SLinus Torvalds return -EINVAL; 19751da177e4SLinus Torvalds } 19761da177e4SLinus Torvalds if (!test_bit(VCF_TX, &vc->flags)) { 19771da177e4SLinus Torvalds printk("%s: Trying to transmit on a non-tx VC.\n", card->name); 19781da177e4SLinus Torvalds atomic_inc(&vcc->stats->tx_err); 19791da177e4SLinus Torvalds dev_kfree_skb(skb); 19801da177e4SLinus Torvalds return -EINVAL; 19811da177e4SLinus Torvalds } 19821da177e4SLinus Torvalds 19831da177e4SLinus Torvalds switch (vcc->qos.aal) { 19841da177e4SLinus Torvalds case ATM_AAL0: 19851da177e4SLinus Torvalds case ATM_AAL1: 19861da177e4SLinus Torvalds case ATM_AAL5: 19871da177e4SLinus Torvalds break; 19881da177e4SLinus Torvalds default: 19891da177e4SLinus Torvalds printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal); 19901da177e4SLinus Torvalds atomic_inc(&vcc->stats->tx_err); 19911da177e4SLinus Torvalds dev_kfree_skb(skb); 19921da177e4SLinus Torvalds return -EINVAL; 19931da177e4SLinus Torvalds } 19941da177e4SLinus Torvalds 19951da177e4SLinus Torvalds if (skb_shinfo(skb)->nr_frags != 0) { 19961da177e4SLinus Torvalds printk("%s: No scatter-gather yet.\n", card->name); 19971da177e4SLinus Torvalds atomic_inc(&vcc->stats->tx_err); 19981da177e4SLinus Torvalds dev_kfree_skb(skb); 19991da177e4SLinus Torvalds return -EINVAL; 20001da177e4SLinus Torvalds } 20011da177e4SLinus Torvalds ATM_SKB(skb)->vcc = vcc; 20021da177e4SLinus Torvalds 20031da177e4SLinus Torvalds err = queue_skb(card, vc, skb, oam); 20041da177e4SLinus Torvalds if (err) { 20051da177e4SLinus Torvalds atomic_inc(&vcc->stats->tx_err); 20061da177e4SLinus Torvalds dev_kfree_skb(skb); 20071da177e4SLinus Torvalds return err; 20081da177e4SLinus Torvalds } 20091da177e4SLinus Torvalds 20101da177e4SLinus Torvalds return 0; 20111da177e4SLinus Torvalds } 20121da177e4SLinus Torvalds 20131da177e4SLinus Torvalds int 20141da177e4SLinus Torvalds idt77252_send(struct atm_vcc *vcc, struct sk_buff *skb) 20151da177e4SLinus Torvalds { 20161da177e4SLinus Torvalds return idt77252_send_skb(vcc, skb, 0); 20171da177e4SLinus Torvalds } 20181da177e4SLinus Torvalds 20191da177e4SLinus Torvalds static int 20201da177e4SLinus Torvalds idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags) 20211da177e4SLinus Torvalds { 20221da177e4SLinus Torvalds struct atm_dev *dev = vcc->dev; 20231da177e4SLinus Torvalds struct idt77252_dev *card = dev->dev_data; 20241da177e4SLinus Torvalds struct sk_buff *skb; 20251da177e4SLinus Torvalds 20261da177e4SLinus Torvalds skb = dev_alloc_skb(64); 20271da177e4SLinus Torvalds if (!skb) { 20281da177e4SLinus Torvalds printk("%s: Out of memory in send_oam().\n", card->name); 20291da177e4SLinus Torvalds atomic_inc(&vcc->stats->tx_err); 20301da177e4SLinus Torvalds return -ENOMEM; 20311da177e4SLinus Torvalds } 20321da177e4SLinus Torvalds atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc); 20331da177e4SLinus Torvalds 20341da177e4SLinus Torvalds memcpy(skb_put(skb, 52), cell, 52); 20351da177e4SLinus Torvalds 20361da177e4SLinus Torvalds return idt77252_send_skb(vcc, skb, 1); 20371da177e4SLinus Torvalds } 20381da177e4SLinus Torvalds 20391da177e4SLinus Torvalds static __inline__ unsigned int 20401da177e4SLinus Torvalds idt77252_fls(unsigned int x) 20411da177e4SLinus Torvalds { 20421da177e4SLinus Torvalds int r = 1; 20431da177e4SLinus Torvalds 20441da177e4SLinus Torvalds if (x == 0) 20451da177e4SLinus Torvalds return 0; 20461da177e4SLinus Torvalds if (x & 0xffff0000) { 20471da177e4SLinus Torvalds x >>= 16; 20481da177e4SLinus Torvalds r += 16; 20491da177e4SLinus Torvalds } 20501da177e4SLinus Torvalds if (x & 0xff00) { 20511da177e4SLinus Torvalds x >>= 8; 20521da177e4SLinus Torvalds r += 8; 20531da177e4SLinus Torvalds } 20541da177e4SLinus Torvalds if (x & 0xf0) { 20551da177e4SLinus Torvalds x >>= 4; 20561da177e4SLinus Torvalds r += 4; 20571da177e4SLinus Torvalds } 20581da177e4SLinus Torvalds if (x & 0xc) { 20591da177e4SLinus Torvalds x >>= 2; 20601da177e4SLinus Torvalds r += 2; 20611da177e4SLinus Torvalds } 20621da177e4SLinus Torvalds if (x & 0x2) 20631da177e4SLinus Torvalds r += 1; 20641da177e4SLinus Torvalds return r; 20651da177e4SLinus Torvalds } 20661da177e4SLinus Torvalds 20671da177e4SLinus Torvalds static u16 20681da177e4SLinus Torvalds idt77252_int_to_atmfp(unsigned int rate) 20691da177e4SLinus Torvalds { 20701da177e4SLinus Torvalds u16 m, e; 20711da177e4SLinus Torvalds 20721da177e4SLinus Torvalds if (rate == 0) 20731da177e4SLinus Torvalds return 0; 20741da177e4SLinus Torvalds e = idt77252_fls(rate) - 1; 20751da177e4SLinus Torvalds if (e < 9) 20761da177e4SLinus Torvalds m = (rate - (1 << e)) << (9 - e); 20771da177e4SLinus Torvalds else if (e == 9) 20781da177e4SLinus Torvalds m = (rate - (1 << e)); 20791da177e4SLinus Torvalds else /* e > 9 */ 20801da177e4SLinus Torvalds m = (rate - (1 << e)) >> (e - 9); 20811da177e4SLinus Torvalds return 0x4000 | (e << 9) | m; 20821da177e4SLinus Torvalds } 20831da177e4SLinus Torvalds 20841da177e4SLinus Torvalds static u8 20851da177e4SLinus Torvalds idt77252_rate_logindex(struct idt77252_dev *card, int pcr) 20861da177e4SLinus Torvalds { 20871da177e4SLinus Torvalds u16 afp; 20881da177e4SLinus Torvalds 20891da177e4SLinus Torvalds afp = idt77252_int_to_atmfp(pcr < 0 ? -pcr : pcr); 20901da177e4SLinus Torvalds if (pcr < 0) 20911da177e4SLinus Torvalds return rate_to_log[(afp >> 5) & 0x1ff]; 20921da177e4SLinus Torvalds return rate_to_log[((afp >> 5) + 1) & 0x1ff]; 20931da177e4SLinus Torvalds } 20941da177e4SLinus Torvalds 20951da177e4SLinus Torvalds static void 20961da177e4SLinus Torvalds idt77252_est_timer(unsigned long data) 20971da177e4SLinus Torvalds { 20981da177e4SLinus Torvalds struct vc_map *vc = (struct vc_map *)data; 20991da177e4SLinus Torvalds struct idt77252_dev *card = vc->card; 21001da177e4SLinus Torvalds struct rate_estimator *est; 21011da177e4SLinus Torvalds unsigned long flags; 21021da177e4SLinus Torvalds u32 rate, cps; 21031da177e4SLinus Torvalds u64 ncells; 21041da177e4SLinus Torvalds u8 lacr; 21051da177e4SLinus Torvalds 21061da177e4SLinus Torvalds spin_lock_irqsave(&vc->lock, flags); 21071da177e4SLinus Torvalds est = vc->estimator; 21081da177e4SLinus Torvalds if (!est) 21091da177e4SLinus Torvalds goto out; 21101da177e4SLinus Torvalds 21111da177e4SLinus Torvalds ncells = est->cells; 21121da177e4SLinus Torvalds 21131da177e4SLinus Torvalds rate = ((u32)(ncells - est->last_cells)) << (7 - est->interval); 21141da177e4SLinus Torvalds est->last_cells = ncells; 21151da177e4SLinus Torvalds est->avcps += ((long)rate - (long)est->avcps) >> est->ewma_log; 21161da177e4SLinus Torvalds est->cps = (est->avcps + 0x1f) >> 5; 21171da177e4SLinus Torvalds 21181da177e4SLinus Torvalds cps = est->cps; 21191da177e4SLinus Torvalds if (cps < (est->maxcps >> 4)) 21201da177e4SLinus Torvalds cps = est->maxcps >> 4; 21211da177e4SLinus Torvalds 21221da177e4SLinus Torvalds lacr = idt77252_rate_logindex(card, cps); 21231da177e4SLinus Torvalds if (lacr > vc->max_er) 21241da177e4SLinus Torvalds lacr = vc->max_er; 21251da177e4SLinus Torvalds 21261da177e4SLinus Torvalds if (lacr != vc->lacr) { 21271da177e4SLinus Torvalds vc->lacr = lacr; 21281da177e4SLinus Torvalds writel(TCMDQ_LACR|(vc->lacr << 16)|vc->index, SAR_REG_TCMDQ); 21291da177e4SLinus Torvalds } 21301da177e4SLinus Torvalds 21311da177e4SLinus Torvalds est->timer.expires = jiffies + ((HZ / 4) << est->interval); 21321da177e4SLinus Torvalds add_timer(&est->timer); 21331da177e4SLinus Torvalds 21341da177e4SLinus Torvalds out: 21351da177e4SLinus Torvalds spin_unlock_irqrestore(&vc->lock, flags); 21361da177e4SLinus Torvalds } 21371da177e4SLinus Torvalds 21381da177e4SLinus Torvalds static struct rate_estimator * 21391da177e4SLinus Torvalds idt77252_init_est(struct vc_map *vc, int pcr) 21401da177e4SLinus Torvalds { 21411da177e4SLinus Torvalds struct rate_estimator *est; 21421da177e4SLinus Torvalds 2143*0c1cca1dSOm Narasimhan est = kzalloc(sizeof(struct rate_estimator), GFP_KERNEL); 21441da177e4SLinus Torvalds if (!est) 21451da177e4SLinus Torvalds return NULL; 21461da177e4SLinus Torvalds est->maxcps = pcr < 0 ? -pcr : pcr; 21471da177e4SLinus Torvalds est->cps = est->maxcps; 21481da177e4SLinus Torvalds est->avcps = est->cps << 5; 21491da177e4SLinus Torvalds 21501da177e4SLinus Torvalds est->interval = 2; /* XXX: make this configurable */ 21511da177e4SLinus Torvalds est->ewma_log = 2; /* XXX: make this configurable */ 21521da177e4SLinus Torvalds init_timer(&est->timer); 21531da177e4SLinus Torvalds est->timer.data = (unsigned long)vc; 21541da177e4SLinus Torvalds est->timer.function = idt77252_est_timer; 21551da177e4SLinus Torvalds 21561da177e4SLinus Torvalds est->timer.expires = jiffies + ((HZ / 4) << est->interval); 21571da177e4SLinus Torvalds add_timer(&est->timer); 21581da177e4SLinus Torvalds 21591da177e4SLinus Torvalds return est; 21601da177e4SLinus Torvalds } 21611da177e4SLinus Torvalds 21621da177e4SLinus Torvalds static int 21631da177e4SLinus Torvalds idt77252_init_cbr(struct idt77252_dev *card, struct vc_map *vc, 21641da177e4SLinus Torvalds struct atm_vcc *vcc, struct atm_qos *qos) 21651da177e4SLinus Torvalds { 21661da177e4SLinus Torvalds int tst_free, tst_used, tst_entries; 21671da177e4SLinus Torvalds unsigned long tmpl, modl; 21681da177e4SLinus Torvalds int tcr, tcra; 21691da177e4SLinus Torvalds 21701da177e4SLinus Torvalds if ((qos->txtp.max_pcr == 0) && 21711da177e4SLinus Torvalds (qos->txtp.pcr == 0) && (qos->txtp.min_pcr == 0)) { 21721da177e4SLinus Torvalds printk("%s: trying to open a CBR VC with cell rate = 0\n", 21731da177e4SLinus Torvalds card->name); 21741da177e4SLinus Torvalds return -EINVAL; 21751da177e4SLinus Torvalds } 21761da177e4SLinus Torvalds 21771da177e4SLinus Torvalds tst_used = 0; 21781da177e4SLinus Torvalds tst_free = card->tst_free; 21791da177e4SLinus Torvalds if (test_bit(VCF_TX, &vc->flags)) 21801da177e4SLinus Torvalds tst_used = vc->ntste; 21811da177e4SLinus Torvalds tst_free += tst_used; 21821da177e4SLinus Torvalds 21831da177e4SLinus Torvalds tcr = atm_pcr_goal(&qos->txtp); 21841da177e4SLinus Torvalds tcra = tcr >= 0 ? tcr : -tcr; 21851da177e4SLinus Torvalds 21861da177e4SLinus Torvalds TXPRINTK("%s: CBR target cell rate = %d\n", card->name, tcra); 21871da177e4SLinus Torvalds 21881da177e4SLinus Torvalds tmpl = (unsigned long) tcra * ((unsigned long) card->tst_size - 2); 21891da177e4SLinus Torvalds modl = tmpl % (unsigned long)card->utopia_pcr; 21901da177e4SLinus Torvalds 21911da177e4SLinus Torvalds tst_entries = (int) (tmpl / card->utopia_pcr); 21921da177e4SLinus Torvalds if (tcr > 0) { 21931da177e4SLinus Torvalds if (modl > 0) 21941da177e4SLinus Torvalds tst_entries++; 21951da177e4SLinus Torvalds } else if (tcr == 0) { 21961da177e4SLinus Torvalds tst_entries = tst_free - SAR_TST_RESERVED; 21971da177e4SLinus Torvalds if (tst_entries <= 0) { 21981da177e4SLinus Torvalds printk("%s: no CBR bandwidth free.\n", card->name); 21991da177e4SLinus Torvalds return -ENOSR; 22001da177e4SLinus Torvalds } 22011da177e4SLinus Torvalds } 22021da177e4SLinus Torvalds 22031da177e4SLinus Torvalds if (tst_entries == 0) { 22041da177e4SLinus Torvalds printk("%s: selected CBR bandwidth < granularity.\n", 22051da177e4SLinus Torvalds card->name); 22061da177e4SLinus Torvalds return -EINVAL; 22071da177e4SLinus Torvalds } 22081da177e4SLinus Torvalds 22091da177e4SLinus Torvalds if (tst_entries > (tst_free - SAR_TST_RESERVED)) { 22101da177e4SLinus Torvalds printk("%s: not enough CBR bandwidth free.\n", card->name); 22111da177e4SLinus Torvalds return -ENOSR; 22121da177e4SLinus Torvalds } 22131da177e4SLinus Torvalds 22141da177e4SLinus Torvalds vc->ntste = tst_entries; 22151da177e4SLinus Torvalds 22161da177e4SLinus Torvalds card->tst_free = tst_free - tst_entries; 22171da177e4SLinus Torvalds if (test_bit(VCF_TX, &vc->flags)) { 22181da177e4SLinus Torvalds if (tst_used == tst_entries) 22191da177e4SLinus Torvalds return 0; 22201da177e4SLinus Torvalds 22211da177e4SLinus Torvalds OPRINTK("%s: modify %d -> %d entries in TST.\n", 22221da177e4SLinus Torvalds card->name, tst_used, tst_entries); 22231da177e4SLinus Torvalds change_tst(card, vc, tst_entries, TSTE_OPC_CBR); 22241da177e4SLinus Torvalds return 0; 22251da177e4SLinus Torvalds } 22261da177e4SLinus Torvalds 22271da177e4SLinus Torvalds OPRINTK("%s: setting %d entries in TST.\n", card->name, tst_entries); 22281da177e4SLinus Torvalds fill_tst(card, vc, tst_entries, TSTE_OPC_CBR); 22291da177e4SLinus Torvalds return 0; 22301da177e4SLinus Torvalds } 22311da177e4SLinus Torvalds 22321da177e4SLinus Torvalds static int 22331da177e4SLinus Torvalds idt77252_init_ubr(struct idt77252_dev *card, struct vc_map *vc, 22341da177e4SLinus Torvalds struct atm_vcc *vcc, struct atm_qos *qos) 22351da177e4SLinus Torvalds { 22361da177e4SLinus Torvalds unsigned long flags; 22371da177e4SLinus Torvalds int tcr; 22381da177e4SLinus Torvalds 22391da177e4SLinus Torvalds spin_lock_irqsave(&vc->lock, flags); 22401da177e4SLinus Torvalds if (vc->estimator) { 22411da177e4SLinus Torvalds del_timer(&vc->estimator->timer); 22421da177e4SLinus Torvalds kfree(vc->estimator); 22431da177e4SLinus Torvalds vc->estimator = NULL; 22441da177e4SLinus Torvalds } 22451da177e4SLinus Torvalds spin_unlock_irqrestore(&vc->lock, flags); 22461da177e4SLinus Torvalds 22471da177e4SLinus Torvalds tcr = atm_pcr_goal(&qos->txtp); 22481da177e4SLinus Torvalds if (tcr == 0) 22491da177e4SLinus Torvalds tcr = card->link_pcr; 22501da177e4SLinus Torvalds 22511da177e4SLinus Torvalds vc->estimator = idt77252_init_est(vc, tcr); 22521da177e4SLinus Torvalds 22531da177e4SLinus Torvalds vc->class = SCHED_UBR; 22541da177e4SLinus Torvalds vc->init_er = idt77252_rate_logindex(card, tcr); 22551da177e4SLinus Torvalds vc->lacr = vc->init_er; 22561da177e4SLinus Torvalds if (tcr < 0) 22571da177e4SLinus Torvalds vc->max_er = vc->init_er; 22581da177e4SLinus Torvalds else 22591da177e4SLinus Torvalds vc->max_er = 0xff; 22601da177e4SLinus Torvalds 22611da177e4SLinus Torvalds return 0; 22621da177e4SLinus Torvalds } 22631da177e4SLinus Torvalds 22641da177e4SLinus Torvalds static int 22651da177e4SLinus Torvalds idt77252_init_tx(struct idt77252_dev *card, struct vc_map *vc, 22661da177e4SLinus Torvalds struct atm_vcc *vcc, struct atm_qos *qos) 22671da177e4SLinus Torvalds { 22681da177e4SLinus Torvalds int error; 22691da177e4SLinus Torvalds 22701da177e4SLinus Torvalds if (test_bit(VCF_TX, &vc->flags)) 22711da177e4SLinus Torvalds return -EBUSY; 22721da177e4SLinus Torvalds 22731da177e4SLinus Torvalds switch (qos->txtp.traffic_class) { 22741da177e4SLinus Torvalds case ATM_CBR: 22751da177e4SLinus Torvalds vc->class = SCHED_CBR; 22761da177e4SLinus Torvalds break; 22771da177e4SLinus Torvalds 22781da177e4SLinus Torvalds case ATM_UBR: 22791da177e4SLinus Torvalds vc->class = SCHED_UBR; 22801da177e4SLinus Torvalds break; 22811da177e4SLinus Torvalds 22821da177e4SLinus Torvalds case ATM_VBR: 22831da177e4SLinus Torvalds case ATM_ABR: 22841da177e4SLinus Torvalds default: 22851da177e4SLinus Torvalds return -EPROTONOSUPPORT; 22861da177e4SLinus Torvalds } 22871da177e4SLinus Torvalds 22881da177e4SLinus Torvalds vc->scq = alloc_scq(card, vc->class); 22891da177e4SLinus Torvalds if (!vc->scq) { 22901da177e4SLinus Torvalds printk("%s: can't get SCQ.\n", card->name); 22911da177e4SLinus Torvalds return -ENOMEM; 22921da177e4SLinus Torvalds } 22931da177e4SLinus Torvalds 22941da177e4SLinus Torvalds vc->scq->scd = get_free_scd(card, vc); 22951da177e4SLinus Torvalds if (vc->scq->scd == 0) { 22961da177e4SLinus Torvalds printk("%s: no SCD available.\n", card->name); 22971da177e4SLinus Torvalds free_scq(card, vc->scq); 22981da177e4SLinus Torvalds return -ENOMEM; 22991da177e4SLinus Torvalds } 23001da177e4SLinus Torvalds 23011da177e4SLinus Torvalds fill_scd(card, vc->scq, vc->class); 23021da177e4SLinus Torvalds 23031da177e4SLinus Torvalds if (set_tct(card, vc)) { 23041da177e4SLinus Torvalds printk("%s: class %d not supported.\n", 23051da177e4SLinus Torvalds card->name, qos->txtp.traffic_class); 23061da177e4SLinus Torvalds 23071da177e4SLinus Torvalds card->scd2vc[vc->scd_index] = NULL; 23081da177e4SLinus Torvalds free_scq(card, vc->scq); 23091da177e4SLinus Torvalds return -EPROTONOSUPPORT; 23101da177e4SLinus Torvalds } 23111da177e4SLinus Torvalds 23121da177e4SLinus Torvalds switch (vc->class) { 23131da177e4SLinus Torvalds case SCHED_CBR: 23141da177e4SLinus Torvalds error = idt77252_init_cbr(card, vc, vcc, qos); 23151da177e4SLinus Torvalds if (error) { 23161da177e4SLinus Torvalds card->scd2vc[vc->scd_index] = NULL; 23171da177e4SLinus Torvalds free_scq(card, vc->scq); 23181da177e4SLinus Torvalds return error; 23191da177e4SLinus Torvalds } 23201da177e4SLinus Torvalds 23211da177e4SLinus Torvalds clear_bit(VCF_IDLE, &vc->flags); 23221da177e4SLinus Torvalds writel(TCMDQ_START | vc->index, SAR_REG_TCMDQ); 23231da177e4SLinus Torvalds break; 23241da177e4SLinus Torvalds 23251da177e4SLinus Torvalds case SCHED_UBR: 23261da177e4SLinus Torvalds error = idt77252_init_ubr(card, vc, vcc, qos); 23271da177e4SLinus Torvalds if (error) { 23281da177e4SLinus Torvalds card->scd2vc[vc->scd_index] = NULL; 23291da177e4SLinus Torvalds free_scq(card, vc->scq); 23301da177e4SLinus Torvalds return error; 23311da177e4SLinus Torvalds } 23321da177e4SLinus Torvalds 23331da177e4SLinus Torvalds set_bit(VCF_IDLE, &vc->flags); 23341da177e4SLinus Torvalds break; 23351da177e4SLinus Torvalds } 23361da177e4SLinus Torvalds 23371da177e4SLinus Torvalds vc->tx_vcc = vcc; 23381da177e4SLinus Torvalds set_bit(VCF_TX, &vc->flags); 23391da177e4SLinus Torvalds return 0; 23401da177e4SLinus Torvalds } 23411da177e4SLinus Torvalds 23421da177e4SLinus Torvalds static int 23431da177e4SLinus Torvalds idt77252_init_rx(struct idt77252_dev *card, struct vc_map *vc, 23441da177e4SLinus Torvalds struct atm_vcc *vcc, struct atm_qos *qos) 23451da177e4SLinus Torvalds { 23461da177e4SLinus Torvalds unsigned long flags; 23471da177e4SLinus Torvalds unsigned long addr; 23481da177e4SLinus Torvalds u32 rcte = 0; 23491da177e4SLinus Torvalds 23501da177e4SLinus Torvalds if (test_bit(VCF_RX, &vc->flags)) 23511da177e4SLinus Torvalds return -EBUSY; 23521da177e4SLinus Torvalds 23531da177e4SLinus Torvalds vc->rx_vcc = vcc; 23541da177e4SLinus Torvalds set_bit(VCF_RX, &vc->flags); 23551da177e4SLinus Torvalds 23561da177e4SLinus Torvalds if ((vcc->vci == 3) || (vcc->vci == 4)) 23571da177e4SLinus Torvalds return 0; 23581da177e4SLinus Torvalds 23591da177e4SLinus Torvalds flush_rx_pool(card, &vc->rcv.rx_pool); 23601da177e4SLinus Torvalds 23611da177e4SLinus Torvalds rcte |= SAR_RCTE_CONNECTOPEN; 23621da177e4SLinus Torvalds rcte |= SAR_RCTE_RAWCELLINTEN; 23631da177e4SLinus Torvalds 23641da177e4SLinus Torvalds switch (qos->aal) { 23651da177e4SLinus Torvalds case ATM_AAL0: 23661da177e4SLinus Torvalds rcte |= SAR_RCTE_RCQ; 23671da177e4SLinus Torvalds break; 23681da177e4SLinus Torvalds case ATM_AAL1: 23691da177e4SLinus Torvalds rcte |= SAR_RCTE_OAM; /* Let SAR drop Video */ 23701da177e4SLinus Torvalds break; 23711da177e4SLinus Torvalds case ATM_AAL34: 23721da177e4SLinus Torvalds rcte |= SAR_RCTE_AAL34; 23731da177e4SLinus Torvalds break; 23741da177e4SLinus Torvalds case ATM_AAL5: 23751da177e4SLinus Torvalds rcte |= SAR_RCTE_AAL5; 23761da177e4SLinus Torvalds break; 23771da177e4SLinus Torvalds default: 23781da177e4SLinus Torvalds rcte |= SAR_RCTE_RCQ; 23791da177e4SLinus Torvalds break; 23801da177e4SLinus Torvalds } 23811da177e4SLinus Torvalds 23821da177e4SLinus Torvalds if (qos->aal != ATM_AAL5) 23831da177e4SLinus Torvalds rcte |= SAR_RCTE_FBP_1; 23841da177e4SLinus Torvalds else if (qos->rxtp.max_sdu > SAR_FB_SIZE_2) 23851da177e4SLinus Torvalds rcte |= SAR_RCTE_FBP_3; 23861da177e4SLinus Torvalds else if (qos->rxtp.max_sdu > SAR_FB_SIZE_1) 23871da177e4SLinus Torvalds rcte |= SAR_RCTE_FBP_2; 23881da177e4SLinus Torvalds else if (qos->rxtp.max_sdu > SAR_FB_SIZE_0) 23891da177e4SLinus Torvalds rcte |= SAR_RCTE_FBP_1; 23901da177e4SLinus Torvalds else 23911da177e4SLinus Torvalds rcte |= SAR_RCTE_FBP_01; 23921da177e4SLinus Torvalds 23931da177e4SLinus Torvalds addr = card->rct_base + (vc->index << 2); 23941da177e4SLinus Torvalds 23951da177e4SLinus Torvalds OPRINTK("%s: writing RCT at 0x%lx\n", card->name, addr); 23961da177e4SLinus Torvalds write_sram(card, addr, rcte); 23971da177e4SLinus Torvalds 23981da177e4SLinus Torvalds spin_lock_irqsave(&card->cmd_lock, flags); 23991da177e4SLinus Torvalds writel(SAR_CMD_OPEN_CONNECTION | (addr << 2), SAR_REG_CMD); 24001da177e4SLinus Torvalds waitfor_idle(card); 24011da177e4SLinus Torvalds spin_unlock_irqrestore(&card->cmd_lock, flags); 24021da177e4SLinus Torvalds 24031da177e4SLinus Torvalds return 0; 24041da177e4SLinus Torvalds } 24051da177e4SLinus Torvalds 24061da177e4SLinus Torvalds static int 24071da177e4SLinus Torvalds idt77252_open(struct atm_vcc *vcc) 24081da177e4SLinus Torvalds { 24091da177e4SLinus Torvalds struct atm_dev *dev = vcc->dev; 24101da177e4SLinus Torvalds struct idt77252_dev *card = dev->dev_data; 24111da177e4SLinus Torvalds struct vc_map *vc; 24121da177e4SLinus Torvalds unsigned int index; 24131da177e4SLinus Torvalds unsigned int inuse; 24141da177e4SLinus Torvalds int error; 24151da177e4SLinus Torvalds int vci = vcc->vci; 24161da177e4SLinus Torvalds short vpi = vcc->vpi; 24171da177e4SLinus Torvalds 24181da177e4SLinus Torvalds if (vpi == ATM_VPI_UNSPEC || vci == ATM_VCI_UNSPEC) 24191da177e4SLinus Torvalds return 0; 24201da177e4SLinus Torvalds 24211da177e4SLinus Torvalds if (vpi >= (1 << card->vpibits)) { 24221da177e4SLinus Torvalds printk("%s: unsupported VPI: %d\n", card->name, vpi); 24231da177e4SLinus Torvalds return -EINVAL; 24241da177e4SLinus Torvalds } 24251da177e4SLinus Torvalds 24261da177e4SLinus Torvalds if (vci >= (1 << card->vcibits)) { 24271da177e4SLinus Torvalds printk("%s: unsupported VCI: %d\n", card->name, vci); 24281da177e4SLinus Torvalds return -EINVAL; 24291da177e4SLinus Torvalds } 24301da177e4SLinus Torvalds 24311da177e4SLinus Torvalds set_bit(ATM_VF_ADDR, &vcc->flags); 24321da177e4SLinus Torvalds 24331da177e4SLinus Torvalds down(&card->mutex); 24341da177e4SLinus Torvalds 24351da177e4SLinus Torvalds OPRINTK("%s: opening vpi.vci: %d.%d\n", card->name, vpi, vci); 24361da177e4SLinus Torvalds 24371da177e4SLinus Torvalds switch (vcc->qos.aal) { 24381da177e4SLinus Torvalds case ATM_AAL0: 24391da177e4SLinus Torvalds case ATM_AAL1: 24401da177e4SLinus Torvalds case ATM_AAL5: 24411da177e4SLinus Torvalds break; 24421da177e4SLinus Torvalds default: 24431da177e4SLinus Torvalds printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal); 24441da177e4SLinus Torvalds up(&card->mutex); 24451da177e4SLinus Torvalds return -EPROTONOSUPPORT; 24461da177e4SLinus Torvalds } 24471da177e4SLinus Torvalds 24481da177e4SLinus Torvalds index = VPCI2VC(card, vpi, vci); 24491da177e4SLinus Torvalds if (!card->vcs[index]) { 2450*0c1cca1dSOm Narasimhan card->vcs[index] = kzalloc(sizeof(struct vc_map), GFP_KERNEL); 24511da177e4SLinus Torvalds if (!card->vcs[index]) { 24521da177e4SLinus Torvalds printk("%s: can't alloc vc in open()\n", card->name); 24531da177e4SLinus Torvalds up(&card->mutex); 24541da177e4SLinus Torvalds return -ENOMEM; 24551da177e4SLinus Torvalds } 24561da177e4SLinus Torvalds card->vcs[index]->card = card; 24571da177e4SLinus Torvalds card->vcs[index]->index = index; 24581da177e4SLinus Torvalds 24591da177e4SLinus Torvalds spin_lock_init(&card->vcs[index]->lock); 24601da177e4SLinus Torvalds } 24611da177e4SLinus Torvalds vc = card->vcs[index]; 24621da177e4SLinus Torvalds 24631da177e4SLinus Torvalds vcc->dev_data = vc; 24641da177e4SLinus Torvalds 24651da177e4SLinus Torvalds IPRINTK("%s: idt77252_open: vc = %d (%d.%d) %s/%s (max RX SDU: %u)\n", 24661da177e4SLinus Torvalds card->name, vc->index, vcc->vpi, vcc->vci, 24671da177e4SLinus Torvalds vcc->qos.rxtp.traffic_class != ATM_NONE ? "rx" : "--", 24681da177e4SLinus Torvalds vcc->qos.txtp.traffic_class != ATM_NONE ? "tx" : "--", 24691da177e4SLinus Torvalds vcc->qos.rxtp.max_sdu); 24701da177e4SLinus Torvalds 24711da177e4SLinus Torvalds inuse = 0; 24721da177e4SLinus Torvalds if (vcc->qos.txtp.traffic_class != ATM_NONE && 24731da177e4SLinus Torvalds test_bit(VCF_TX, &vc->flags)) 24741da177e4SLinus Torvalds inuse = 1; 24751da177e4SLinus Torvalds if (vcc->qos.rxtp.traffic_class != ATM_NONE && 24761da177e4SLinus Torvalds test_bit(VCF_RX, &vc->flags)) 24771da177e4SLinus Torvalds inuse += 2; 24781da177e4SLinus Torvalds 24791da177e4SLinus Torvalds if (inuse) { 24801da177e4SLinus Torvalds printk("%s: %s vci already in use.\n", card->name, 24811da177e4SLinus Torvalds inuse == 1 ? "tx" : inuse == 2 ? "rx" : "tx and rx"); 24821da177e4SLinus Torvalds up(&card->mutex); 24831da177e4SLinus Torvalds return -EADDRINUSE; 24841da177e4SLinus Torvalds } 24851da177e4SLinus Torvalds 24861da177e4SLinus Torvalds if (vcc->qos.txtp.traffic_class != ATM_NONE) { 24871da177e4SLinus Torvalds error = idt77252_init_tx(card, vc, vcc, &vcc->qos); 24881da177e4SLinus Torvalds if (error) { 24891da177e4SLinus Torvalds up(&card->mutex); 24901da177e4SLinus Torvalds return error; 24911da177e4SLinus Torvalds } 24921da177e4SLinus Torvalds } 24931da177e4SLinus Torvalds 24941da177e4SLinus Torvalds if (vcc->qos.rxtp.traffic_class != ATM_NONE) { 24951da177e4SLinus Torvalds error = idt77252_init_rx(card, vc, vcc, &vcc->qos); 24961da177e4SLinus Torvalds if (error) { 24971da177e4SLinus Torvalds up(&card->mutex); 24981da177e4SLinus Torvalds return error; 24991da177e4SLinus Torvalds } 25001da177e4SLinus Torvalds } 25011da177e4SLinus Torvalds 25021da177e4SLinus Torvalds set_bit(ATM_VF_READY, &vcc->flags); 25031da177e4SLinus Torvalds 25041da177e4SLinus Torvalds up(&card->mutex); 25051da177e4SLinus Torvalds return 0; 25061da177e4SLinus Torvalds } 25071da177e4SLinus Torvalds 25081da177e4SLinus Torvalds static void 25091da177e4SLinus Torvalds idt77252_close(struct atm_vcc *vcc) 25101da177e4SLinus Torvalds { 25111da177e4SLinus Torvalds struct atm_dev *dev = vcc->dev; 25121da177e4SLinus Torvalds struct idt77252_dev *card = dev->dev_data; 25131da177e4SLinus Torvalds struct vc_map *vc = vcc->dev_data; 25141da177e4SLinus Torvalds unsigned long flags; 25151da177e4SLinus Torvalds unsigned long addr; 25161da177e4SLinus Torvalds unsigned long timeout; 25171da177e4SLinus Torvalds 25181da177e4SLinus Torvalds down(&card->mutex); 25191da177e4SLinus Torvalds 25201da177e4SLinus Torvalds IPRINTK("%s: idt77252_close: vc = %d (%d.%d)\n", 25211da177e4SLinus Torvalds card->name, vc->index, vcc->vpi, vcc->vci); 25221da177e4SLinus Torvalds 25231da177e4SLinus Torvalds clear_bit(ATM_VF_READY, &vcc->flags); 25241da177e4SLinus Torvalds 25251da177e4SLinus Torvalds if (vcc->qos.rxtp.traffic_class != ATM_NONE) { 25261da177e4SLinus Torvalds 25271da177e4SLinus Torvalds spin_lock_irqsave(&vc->lock, flags); 25281da177e4SLinus Torvalds clear_bit(VCF_RX, &vc->flags); 25291da177e4SLinus Torvalds vc->rx_vcc = NULL; 25301da177e4SLinus Torvalds spin_unlock_irqrestore(&vc->lock, flags); 25311da177e4SLinus Torvalds 25321da177e4SLinus Torvalds if ((vcc->vci == 3) || (vcc->vci == 4)) 25331da177e4SLinus Torvalds goto done; 25341da177e4SLinus Torvalds 25351da177e4SLinus Torvalds addr = card->rct_base + vc->index * SAR_SRAM_RCT_SIZE; 25361da177e4SLinus Torvalds 25371da177e4SLinus Torvalds spin_lock_irqsave(&card->cmd_lock, flags); 25381da177e4SLinus Torvalds writel(SAR_CMD_CLOSE_CONNECTION | (addr << 2), SAR_REG_CMD); 25391da177e4SLinus Torvalds waitfor_idle(card); 25401da177e4SLinus Torvalds spin_unlock_irqrestore(&card->cmd_lock, flags); 25411da177e4SLinus Torvalds 25421da177e4SLinus Torvalds if (vc->rcv.rx_pool.count) { 25431da177e4SLinus Torvalds DPRINTK("%s: closing a VC with pending rx buffers.\n", 25441da177e4SLinus Torvalds card->name); 25451da177e4SLinus Torvalds 25461da177e4SLinus Torvalds recycle_rx_pool_skb(card, &vc->rcv.rx_pool); 25471da177e4SLinus Torvalds } 25481da177e4SLinus Torvalds } 25491da177e4SLinus Torvalds 25501da177e4SLinus Torvalds done: 25511da177e4SLinus Torvalds if (vcc->qos.txtp.traffic_class != ATM_NONE) { 25521da177e4SLinus Torvalds 25531da177e4SLinus Torvalds spin_lock_irqsave(&vc->lock, flags); 25541da177e4SLinus Torvalds clear_bit(VCF_TX, &vc->flags); 25551da177e4SLinus Torvalds clear_bit(VCF_IDLE, &vc->flags); 25561da177e4SLinus Torvalds clear_bit(VCF_RSV, &vc->flags); 25571da177e4SLinus Torvalds vc->tx_vcc = NULL; 25581da177e4SLinus Torvalds 25591da177e4SLinus Torvalds if (vc->estimator) { 25601da177e4SLinus Torvalds del_timer(&vc->estimator->timer); 25611da177e4SLinus Torvalds kfree(vc->estimator); 25621da177e4SLinus Torvalds vc->estimator = NULL; 25631da177e4SLinus Torvalds } 25641da177e4SLinus Torvalds spin_unlock_irqrestore(&vc->lock, flags); 25651da177e4SLinus Torvalds 25661da177e4SLinus Torvalds timeout = 5 * 1000; 25671da177e4SLinus Torvalds while (atomic_read(&vc->scq->used) > 0) { 25681da177e4SLinus Torvalds timeout = msleep_interruptible(timeout); 25691da177e4SLinus Torvalds if (!timeout) 25701da177e4SLinus Torvalds break; 25711da177e4SLinus Torvalds } 25721da177e4SLinus Torvalds if (!timeout) 25731da177e4SLinus Torvalds printk("%s: SCQ drain timeout: %u used\n", 25741da177e4SLinus Torvalds card->name, atomic_read(&vc->scq->used)); 25751da177e4SLinus Torvalds 25761da177e4SLinus Torvalds writel(TCMDQ_HALT | vc->index, SAR_REG_TCMDQ); 25771da177e4SLinus Torvalds clear_scd(card, vc->scq, vc->class); 25781da177e4SLinus Torvalds 25791da177e4SLinus Torvalds if (vc->class == SCHED_CBR) { 25801da177e4SLinus Torvalds clear_tst(card, vc); 25811da177e4SLinus Torvalds card->tst_free += vc->ntste; 25821da177e4SLinus Torvalds vc->ntste = 0; 25831da177e4SLinus Torvalds } 25841da177e4SLinus Torvalds 25851da177e4SLinus Torvalds card->scd2vc[vc->scd_index] = NULL; 25861da177e4SLinus Torvalds free_scq(card, vc->scq); 25871da177e4SLinus Torvalds } 25881da177e4SLinus Torvalds 25891da177e4SLinus Torvalds up(&card->mutex); 25901da177e4SLinus Torvalds } 25911da177e4SLinus Torvalds 25921da177e4SLinus Torvalds static int 25931da177e4SLinus Torvalds idt77252_change_qos(struct atm_vcc *vcc, struct atm_qos *qos, int flags) 25941da177e4SLinus Torvalds { 25951da177e4SLinus Torvalds struct atm_dev *dev = vcc->dev; 25961da177e4SLinus Torvalds struct idt77252_dev *card = dev->dev_data; 25971da177e4SLinus Torvalds struct vc_map *vc = vcc->dev_data; 25981da177e4SLinus Torvalds int error = 0; 25991da177e4SLinus Torvalds 26001da177e4SLinus Torvalds down(&card->mutex); 26011da177e4SLinus Torvalds 26021da177e4SLinus Torvalds if (qos->txtp.traffic_class != ATM_NONE) { 26031da177e4SLinus Torvalds if (!test_bit(VCF_TX, &vc->flags)) { 26041da177e4SLinus Torvalds error = idt77252_init_tx(card, vc, vcc, qos); 26051da177e4SLinus Torvalds if (error) 26061da177e4SLinus Torvalds goto out; 26071da177e4SLinus Torvalds } else { 26081da177e4SLinus Torvalds switch (qos->txtp.traffic_class) { 26091da177e4SLinus Torvalds case ATM_CBR: 26101da177e4SLinus Torvalds error = idt77252_init_cbr(card, vc, vcc, qos); 26111da177e4SLinus Torvalds if (error) 26121da177e4SLinus Torvalds goto out; 26131da177e4SLinus Torvalds break; 26141da177e4SLinus Torvalds 26151da177e4SLinus Torvalds case ATM_UBR: 26161da177e4SLinus Torvalds error = idt77252_init_ubr(card, vc, vcc, qos); 26171da177e4SLinus Torvalds if (error) 26181da177e4SLinus Torvalds goto out; 26191da177e4SLinus Torvalds 26201da177e4SLinus Torvalds if (!test_bit(VCF_IDLE, &vc->flags)) { 26211da177e4SLinus Torvalds writel(TCMDQ_LACR | (vc->lacr << 16) | 26221da177e4SLinus Torvalds vc->index, SAR_REG_TCMDQ); 26231da177e4SLinus Torvalds } 26241da177e4SLinus Torvalds break; 26251da177e4SLinus Torvalds 26261da177e4SLinus Torvalds case ATM_VBR: 26271da177e4SLinus Torvalds case ATM_ABR: 26281da177e4SLinus Torvalds error = -EOPNOTSUPP; 26291da177e4SLinus Torvalds goto out; 26301da177e4SLinus Torvalds } 26311da177e4SLinus Torvalds } 26321da177e4SLinus Torvalds } 26331da177e4SLinus Torvalds 26341da177e4SLinus Torvalds if ((qos->rxtp.traffic_class != ATM_NONE) && 26351da177e4SLinus Torvalds !test_bit(VCF_RX, &vc->flags)) { 26361da177e4SLinus Torvalds error = idt77252_init_rx(card, vc, vcc, qos); 26371da177e4SLinus Torvalds if (error) 26381da177e4SLinus Torvalds goto out; 26391da177e4SLinus Torvalds } 26401da177e4SLinus Torvalds 26411da177e4SLinus Torvalds memcpy(&vcc->qos, qos, sizeof(struct atm_qos)); 26421da177e4SLinus Torvalds 26431da177e4SLinus Torvalds set_bit(ATM_VF_HASQOS, &vcc->flags); 26441da177e4SLinus Torvalds 26451da177e4SLinus Torvalds out: 26461da177e4SLinus Torvalds up(&card->mutex); 26471da177e4SLinus Torvalds return error; 26481da177e4SLinus Torvalds } 26491da177e4SLinus Torvalds 26501da177e4SLinus Torvalds static int 26511da177e4SLinus Torvalds idt77252_proc_read(struct atm_dev *dev, loff_t * pos, char *page) 26521da177e4SLinus Torvalds { 26531da177e4SLinus Torvalds struct idt77252_dev *card = dev->dev_data; 26541da177e4SLinus Torvalds int i, left; 26551da177e4SLinus Torvalds 26561da177e4SLinus Torvalds left = (int) *pos; 26571da177e4SLinus Torvalds if (!left--) 26581da177e4SLinus Torvalds return sprintf(page, "IDT77252 Interrupts:\n"); 26591da177e4SLinus Torvalds if (!left--) 26601da177e4SLinus Torvalds return sprintf(page, "TSIF: %lu\n", card->irqstat[15]); 26611da177e4SLinus Torvalds if (!left--) 26621da177e4SLinus Torvalds return sprintf(page, "TXICP: %lu\n", card->irqstat[14]); 26631da177e4SLinus Torvalds if (!left--) 26641da177e4SLinus Torvalds return sprintf(page, "TSQF: %lu\n", card->irqstat[12]); 26651da177e4SLinus Torvalds if (!left--) 26661da177e4SLinus Torvalds return sprintf(page, "TMROF: %lu\n", card->irqstat[11]); 26671da177e4SLinus Torvalds if (!left--) 26681da177e4SLinus Torvalds return sprintf(page, "PHYI: %lu\n", card->irqstat[10]); 26691da177e4SLinus Torvalds if (!left--) 26701da177e4SLinus Torvalds return sprintf(page, "FBQ3A: %lu\n", card->irqstat[8]); 26711da177e4SLinus Torvalds if (!left--) 26721da177e4SLinus Torvalds return sprintf(page, "FBQ2A: %lu\n", card->irqstat[7]); 26731da177e4SLinus Torvalds if (!left--) 26741da177e4SLinus Torvalds return sprintf(page, "RSQF: %lu\n", card->irqstat[6]); 26751da177e4SLinus Torvalds if (!left--) 26761da177e4SLinus Torvalds return sprintf(page, "EPDU: %lu\n", card->irqstat[5]); 26771da177e4SLinus Torvalds if (!left--) 26781da177e4SLinus Torvalds return sprintf(page, "RAWCF: %lu\n", card->irqstat[4]); 26791da177e4SLinus Torvalds if (!left--) 26801da177e4SLinus Torvalds return sprintf(page, "FBQ1A: %lu\n", card->irqstat[3]); 26811da177e4SLinus Torvalds if (!left--) 26821da177e4SLinus Torvalds return sprintf(page, "FBQ0A: %lu\n", card->irqstat[2]); 26831da177e4SLinus Torvalds if (!left--) 26841da177e4SLinus Torvalds return sprintf(page, "RSQAF: %lu\n", card->irqstat[1]); 26851da177e4SLinus Torvalds if (!left--) 26861da177e4SLinus Torvalds return sprintf(page, "IDT77252 Transmit Connection Table:\n"); 26871da177e4SLinus Torvalds 26881da177e4SLinus Torvalds for (i = 0; i < card->tct_size; i++) { 26891da177e4SLinus Torvalds unsigned long tct; 26901da177e4SLinus Torvalds struct atm_vcc *vcc; 26911da177e4SLinus Torvalds struct vc_map *vc; 26921da177e4SLinus Torvalds char *p; 26931da177e4SLinus Torvalds 26941da177e4SLinus Torvalds vc = card->vcs[i]; 26951da177e4SLinus Torvalds if (!vc) 26961da177e4SLinus Torvalds continue; 26971da177e4SLinus Torvalds 26981da177e4SLinus Torvalds vcc = NULL; 26991da177e4SLinus Torvalds if (vc->tx_vcc) 27001da177e4SLinus Torvalds vcc = vc->tx_vcc; 27011da177e4SLinus Torvalds if (!vcc) 27021da177e4SLinus Torvalds continue; 27031da177e4SLinus Torvalds if (left--) 27041da177e4SLinus Torvalds continue; 27051da177e4SLinus Torvalds 27061da177e4SLinus Torvalds p = page; 27071da177e4SLinus Torvalds p += sprintf(p, " %4u: %u.%u: ", i, vcc->vpi, vcc->vci); 27081da177e4SLinus Torvalds tct = (unsigned long) (card->tct_base + i * SAR_SRAM_TCT_SIZE); 27091da177e4SLinus Torvalds 27101da177e4SLinus Torvalds for (i = 0; i < 8; i++) 27111da177e4SLinus Torvalds p += sprintf(p, " %08x", read_sram(card, tct + i)); 27121da177e4SLinus Torvalds p += sprintf(p, "\n"); 27131da177e4SLinus Torvalds return p - page; 27141da177e4SLinus Torvalds } 27151da177e4SLinus Torvalds return 0; 27161da177e4SLinus Torvalds } 27171da177e4SLinus Torvalds 27181da177e4SLinus Torvalds /*****************************************************************************/ 27191da177e4SLinus Torvalds /* */ 27201da177e4SLinus Torvalds /* Interrupt handler */ 27211da177e4SLinus Torvalds /* */ 27221da177e4SLinus Torvalds /*****************************************************************************/ 27231da177e4SLinus Torvalds 27241da177e4SLinus Torvalds static void 27251da177e4SLinus Torvalds idt77252_collect_stat(struct idt77252_dev *card) 27261da177e4SLinus Torvalds { 27271da177e4SLinus Torvalds u32 cdc, vpec, icc; 27281da177e4SLinus Torvalds 27291da177e4SLinus Torvalds cdc = readl(SAR_REG_CDC); 27301da177e4SLinus Torvalds vpec = readl(SAR_REG_VPEC); 27311da177e4SLinus Torvalds icc = readl(SAR_REG_ICC); 27321da177e4SLinus Torvalds 27331da177e4SLinus Torvalds #ifdef NOTDEF 27341da177e4SLinus Torvalds printk("%s:", card->name); 27351da177e4SLinus Torvalds 27361da177e4SLinus Torvalds if (cdc & 0x7f0000) { 27371da177e4SLinus Torvalds char *s = ""; 27381da177e4SLinus Torvalds 27391da177e4SLinus Torvalds printk(" ["); 27401da177e4SLinus Torvalds if (cdc & (1 << 22)) { 27411da177e4SLinus Torvalds printk("%sRM ID", s); 27421da177e4SLinus Torvalds s = " | "; 27431da177e4SLinus Torvalds } 27441da177e4SLinus Torvalds if (cdc & (1 << 21)) { 27451da177e4SLinus Torvalds printk("%sCON TAB", s); 27461da177e4SLinus Torvalds s = " | "; 27471da177e4SLinus Torvalds } 27481da177e4SLinus Torvalds if (cdc & (1 << 20)) { 27491da177e4SLinus Torvalds printk("%sNO FB", s); 27501da177e4SLinus Torvalds s = " | "; 27511da177e4SLinus Torvalds } 27521da177e4SLinus Torvalds if (cdc & (1 << 19)) { 27531da177e4SLinus Torvalds printk("%sOAM CRC", s); 27541da177e4SLinus Torvalds s = " | "; 27551da177e4SLinus Torvalds } 27561da177e4SLinus Torvalds if (cdc & (1 << 18)) { 27571da177e4SLinus Torvalds printk("%sRM CRC", s); 27581da177e4SLinus Torvalds s = " | "; 27591da177e4SLinus Torvalds } 27601da177e4SLinus Torvalds if (cdc & (1 << 17)) { 27611da177e4SLinus Torvalds printk("%sRM FIFO", s); 27621da177e4SLinus Torvalds s = " | "; 27631da177e4SLinus Torvalds } 27641da177e4SLinus Torvalds if (cdc & (1 << 16)) { 27651da177e4SLinus Torvalds printk("%sRX FIFO", s); 27661da177e4SLinus Torvalds s = " | "; 27671da177e4SLinus Torvalds } 27681da177e4SLinus Torvalds printk("]"); 27691da177e4SLinus Torvalds } 27701da177e4SLinus Torvalds 27711da177e4SLinus Torvalds printk(" CDC %04x, VPEC %04x, ICC: %04x\n", 27721da177e4SLinus Torvalds cdc & 0xffff, vpec & 0xffff, icc & 0xffff); 27731da177e4SLinus Torvalds #endif 27741da177e4SLinus Torvalds } 27751da177e4SLinus Torvalds 27761da177e4SLinus Torvalds static irqreturn_t 27771da177e4SLinus Torvalds idt77252_interrupt(int irq, void *dev_id, struct pt_regs *ptregs) 27781da177e4SLinus Torvalds { 27791da177e4SLinus Torvalds struct idt77252_dev *card = dev_id; 27801da177e4SLinus Torvalds u32 stat; 27811da177e4SLinus Torvalds 27821da177e4SLinus Torvalds stat = readl(SAR_REG_STAT) & 0xffff; 27831da177e4SLinus Torvalds if (!stat) /* no interrupt for us */ 27841da177e4SLinus Torvalds return IRQ_NONE; 27851da177e4SLinus Torvalds 27861da177e4SLinus Torvalds if (test_and_set_bit(IDT77252_BIT_INTERRUPT, &card->flags)) { 27871da177e4SLinus Torvalds printk("%s: Re-entering irq_handler()\n", card->name); 27881da177e4SLinus Torvalds goto out; 27891da177e4SLinus Torvalds } 27901da177e4SLinus Torvalds 27911da177e4SLinus Torvalds writel(stat, SAR_REG_STAT); /* reset interrupt */ 27921da177e4SLinus Torvalds 27931da177e4SLinus Torvalds if (stat & SAR_STAT_TSIF) { /* entry written to TSQ */ 27941da177e4SLinus Torvalds INTPRINTK("%s: TSIF\n", card->name); 27951da177e4SLinus Torvalds card->irqstat[15]++; 27961da177e4SLinus Torvalds idt77252_tx(card); 27971da177e4SLinus Torvalds } 27981da177e4SLinus Torvalds if (stat & SAR_STAT_TXICP) { /* Incomplete CS-PDU has */ 27991da177e4SLinus Torvalds INTPRINTK("%s: TXICP\n", card->name); 28001da177e4SLinus Torvalds card->irqstat[14]++; 28011da177e4SLinus Torvalds #ifdef CONFIG_ATM_IDT77252_DEBUG 28021da177e4SLinus Torvalds idt77252_tx_dump(card); 28031da177e4SLinus Torvalds #endif 28041da177e4SLinus Torvalds } 28051da177e4SLinus Torvalds if (stat & SAR_STAT_TSQF) { /* TSQ 7/8 full */ 28061da177e4SLinus Torvalds INTPRINTK("%s: TSQF\n", card->name); 28071da177e4SLinus Torvalds card->irqstat[12]++; 28081da177e4SLinus Torvalds idt77252_tx(card); 28091da177e4SLinus Torvalds } 28101da177e4SLinus Torvalds if (stat & SAR_STAT_TMROF) { /* Timer overflow */ 28111da177e4SLinus Torvalds INTPRINTK("%s: TMROF\n", card->name); 28121da177e4SLinus Torvalds card->irqstat[11]++; 28131da177e4SLinus Torvalds idt77252_collect_stat(card); 28141da177e4SLinus Torvalds } 28151da177e4SLinus Torvalds 28161da177e4SLinus Torvalds if (stat & SAR_STAT_EPDU) { /* Got complete CS-PDU */ 28171da177e4SLinus Torvalds INTPRINTK("%s: EPDU\n", card->name); 28181da177e4SLinus Torvalds card->irqstat[5]++; 28191da177e4SLinus Torvalds idt77252_rx(card); 28201da177e4SLinus Torvalds } 28211da177e4SLinus Torvalds if (stat & SAR_STAT_RSQAF) { /* RSQ is 7/8 full */ 28221da177e4SLinus Torvalds INTPRINTK("%s: RSQAF\n", card->name); 28231da177e4SLinus Torvalds card->irqstat[1]++; 28241da177e4SLinus Torvalds idt77252_rx(card); 28251da177e4SLinus Torvalds } 28261da177e4SLinus Torvalds if (stat & SAR_STAT_RSQF) { /* RSQ is full */ 28271da177e4SLinus Torvalds INTPRINTK("%s: RSQF\n", card->name); 28281da177e4SLinus Torvalds card->irqstat[6]++; 28291da177e4SLinus Torvalds idt77252_rx(card); 28301da177e4SLinus Torvalds } 28311da177e4SLinus Torvalds if (stat & SAR_STAT_RAWCF) { /* Raw cell received */ 28321da177e4SLinus Torvalds INTPRINTK("%s: RAWCF\n", card->name); 28331da177e4SLinus Torvalds card->irqstat[4]++; 28341da177e4SLinus Torvalds idt77252_rx_raw(card); 28351da177e4SLinus Torvalds } 28361da177e4SLinus Torvalds 28371da177e4SLinus Torvalds if (stat & SAR_STAT_PHYI) { /* PHY device interrupt */ 28381da177e4SLinus Torvalds INTPRINTK("%s: PHYI", card->name); 28391da177e4SLinus Torvalds card->irqstat[10]++; 28401da177e4SLinus Torvalds if (card->atmdev->phy && card->atmdev->phy->interrupt) 28411da177e4SLinus Torvalds card->atmdev->phy->interrupt(card->atmdev); 28421da177e4SLinus Torvalds } 28431da177e4SLinus Torvalds 28441da177e4SLinus Torvalds if (stat & (SAR_STAT_FBQ0A | SAR_STAT_FBQ1A | 28451da177e4SLinus Torvalds SAR_STAT_FBQ2A | SAR_STAT_FBQ3A)) { 28461da177e4SLinus Torvalds 28471da177e4SLinus Torvalds writel(readl(SAR_REG_CFG) & ~(SAR_CFG_FBIE), SAR_REG_CFG); 28481da177e4SLinus Torvalds 28491da177e4SLinus Torvalds INTPRINTK("%s: FBQA: %04x\n", card->name, stat); 28501da177e4SLinus Torvalds 28511da177e4SLinus Torvalds if (stat & SAR_STAT_FBQ0A) 28521da177e4SLinus Torvalds card->irqstat[2]++; 28531da177e4SLinus Torvalds if (stat & SAR_STAT_FBQ1A) 28541da177e4SLinus Torvalds card->irqstat[3]++; 28551da177e4SLinus Torvalds if (stat & SAR_STAT_FBQ2A) 28561da177e4SLinus Torvalds card->irqstat[7]++; 28571da177e4SLinus Torvalds if (stat & SAR_STAT_FBQ3A) 28581da177e4SLinus Torvalds card->irqstat[8]++; 28591da177e4SLinus Torvalds 28601da177e4SLinus Torvalds schedule_work(&card->tqueue); 28611da177e4SLinus Torvalds } 28621da177e4SLinus Torvalds 28631da177e4SLinus Torvalds out: 28641da177e4SLinus Torvalds clear_bit(IDT77252_BIT_INTERRUPT, &card->flags); 28651da177e4SLinus Torvalds return IRQ_HANDLED; 28661da177e4SLinus Torvalds } 28671da177e4SLinus Torvalds 28681da177e4SLinus Torvalds static void 28691da177e4SLinus Torvalds idt77252_softint(void *dev_id) 28701da177e4SLinus Torvalds { 28711da177e4SLinus Torvalds struct idt77252_dev *card = dev_id; 28721da177e4SLinus Torvalds u32 stat; 28731da177e4SLinus Torvalds int done; 28741da177e4SLinus Torvalds 28751da177e4SLinus Torvalds for (done = 1; ; done = 1) { 28761da177e4SLinus Torvalds stat = readl(SAR_REG_STAT) >> 16; 28771da177e4SLinus Torvalds 28781da177e4SLinus Torvalds if ((stat & 0x0f) < SAR_FBQ0_HIGH) { 28791da177e4SLinus Torvalds add_rx_skb(card, 0, SAR_FB_SIZE_0, 32); 28801da177e4SLinus Torvalds done = 0; 28811da177e4SLinus Torvalds } 28821da177e4SLinus Torvalds 28831da177e4SLinus Torvalds stat >>= 4; 28841da177e4SLinus Torvalds if ((stat & 0x0f) < SAR_FBQ1_HIGH) { 28851da177e4SLinus Torvalds add_rx_skb(card, 1, SAR_FB_SIZE_1, 32); 28861da177e4SLinus Torvalds done = 0; 28871da177e4SLinus Torvalds } 28881da177e4SLinus Torvalds 28891da177e4SLinus Torvalds stat >>= 4; 28901da177e4SLinus Torvalds if ((stat & 0x0f) < SAR_FBQ2_HIGH) { 28911da177e4SLinus Torvalds add_rx_skb(card, 2, SAR_FB_SIZE_2, 32); 28921da177e4SLinus Torvalds done = 0; 28931da177e4SLinus Torvalds } 28941da177e4SLinus Torvalds 28951da177e4SLinus Torvalds stat >>= 4; 28961da177e4SLinus Torvalds if ((stat & 0x0f) < SAR_FBQ3_HIGH) { 28971da177e4SLinus Torvalds add_rx_skb(card, 3, SAR_FB_SIZE_3, 32); 28981da177e4SLinus Torvalds done = 0; 28991da177e4SLinus Torvalds } 29001da177e4SLinus Torvalds 29011da177e4SLinus Torvalds if (done) 29021da177e4SLinus Torvalds break; 29031da177e4SLinus Torvalds } 29041da177e4SLinus Torvalds 29051da177e4SLinus Torvalds writel(readl(SAR_REG_CFG) | SAR_CFG_FBIE, SAR_REG_CFG); 29061da177e4SLinus Torvalds } 29071da177e4SLinus Torvalds 29081da177e4SLinus Torvalds 29091da177e4SLinus Torvalds static int 29101da177e4SLinus Torvalds open_card_oam(struct idt77252_dev *card) 29111da177e4SLinus Torvalds { 29121da177e4SLinus Torvalds unsigned long flags; 29131da177e4SLinus Torvalds unsigned long addr; 29141da177e4SLinus Torvalds struct vc_map *vc; 29151da177e4SLinus Torvalds int vpi, vci; 29161da177e4SLinus Torvalds int index; 29171da177e4SLinus Torvalds u32 rcte; 29181da177e4SLinus Torvalds 29191da177e4SLinus Torvalds for (vpi = 0; vpi < (1 << card->vpibits); vpi++) { 29201da177e4SLinus Torvalds for (vci = 3; vci < 5; vci++) { 29211da177e4SLinus Torvalds index = VPCI2VC(card, vpi, vci); 29221da177e4SLinus Torvalds 2923*0c1cca1dSOm Narasimhan vc = kzalloc(sizeof(struct vc_map), GFP_KERNEL); 29241da177e4SLinus Torvalds if (!vc) { 29251da177e4SLinus Torvalds printk("%s: can't alloc vc\n", card->name); 29261da177e4SLinus Torvalds return -ENOMEM; 29271da177e4SLinus Torvalds } 29281da177e4SLinus Torvalds vc->index = index; 29291da177e4SLinus Torvalds card->vcs[index] = vc; 29301da177e4SLinus Torvalds 29311da177e4SLinus Torvalds flush_rx_pool(card, &vc->rcv.rx_pool); 29321da177e4SLinus Torvalds 29331da177e4SLinus Torvalds rcte = SAR_RCTE_CONNECTOPEN | 29341da177e4SLinus Torvalds SAR_RCTE_RAWCELLINTEN | 29351da177e4SLinus Torvalds SAR_RCTE_RCQ | 29361da177e4SLinus Torvalds SAR_RCTE_FBP_1; 29371da177e4SLinus Torvalds 29381da177e4SLinus Torvalds addr = card->rct_base + (vc->index << 2); 29391da177e4SLinus Torvalds write_sram(card, addr, rcte); 29401da177e4SLinus Torvalds 29411da177e4SLinus Torvalds spin_lock_irqsave(&card->cmd_lock, flags); 29421da177e4SLinus Torvalds writel(SAR_CMD_OPEN_CONNECTION | (addr << 2), 29431da177e4SLinus Torvalds SAR_REG_CMD); 29441da177e4SLinus Torvalds waitfor_idle(card); 29451da177e4SLinus Torvalds spin_unlock_irqrestore(&card->cmd_lock, flags); 29461da177e4SLinus Torvalds } 29471da177e4SLinus Torvalds } 29481da177e4SLinus Torvalds 29491da177e4SLinus Torvalds return 0; 29501da177e4SLinus Torvalds } 29511da177e4SLinus Torvalds 29521da177e4SLinus Torvalds static void 29531da177e4SLinus Torvalds close_card_oam(struct idt77252_dev *card) 29541da177e4SLinus Torvalds { 29551da177e4SLinus Torvalds unsigned long flags; 29561da177e4SLinus Torvalds unsigned long addr; 29571da177e4SLinus Torvalds struct vc_map *vc; 29581da177e4SLinus Torvalds int vpi, vci; 29591da177e4SLinus Torvalds int index; 29601da177e4SLinus Torvalds 29611da177e4SLinus Torvalds for (vpi = 0; vpi < (1 << card->vpibits); vpi++) { 29621da177e4SLinus Torvalds for (vci = 3; vci < 5; vci++) { 29631da177e4SLinus Torvalds index = VPCI2VC(card, vpi, vci); 29641da177e4SLinus Torvalds vc = card->vcs[index]; 29651da177e4SLinus Torvalds 29661da177e4SLinus Torvalds addr = card->rct_base + vc->index * SAR_SRAM_RCT_SIZE; 29671da177e4SLinus Torvalds 29681da177e4SLinus Torvalds spin_lock_irqsave(&card->cmd_lock, flags); 29691da177e4SLinus Torvalds writel(SAR_CMD_CLOSE_CONNECTION | (addr << 2), 29701da177e4SLinus Torvalds SAR_REG_CMD); 29711da177e4SLinus Torvalds waitfor_idle(card); 29721da177e4SLinus Torvalds spin_unlock_irqrestore(&card->cmd_lock, flags); 29731da177e4SLinus Torvalds 29741da177e4SLinus Torvalds if (vc->rcv.rx_pool.count) { 29751da177e4SLinus Torvalds DPRINTK("%s: closing a VC " 29761da177e4SLinus Torvalds "with pending rx buffers.\n", 29771da177e4SLinus Torvalds card->name); 29781da177e4SLinus Torvalds 29791da177e4SLinus Torvalds recycle_rx_pool_skb(card, &vc->rcv.rx_pool); 29801da177e4SLinus Torvalds } 29811da177e4SLinus Torvalds } 29821da177e4SLinus Torvalds } 29831da177e4SLinus Torvalds } 29841da177e4SLinus Torvalds 29851da177e4SLinus Torvalds static int 29861da177e4SLinus Torvalds open_card_ubr0(struct idt77252_dev *card) 29871da177e4SLinus Torvalds { 29881da177e4SLinus Torvalds struct vc_map *vc; 29891da177e4SLinus Torvalds 2990*0c1cca1dSOm Narasimhan vc = kzalloc(sizeof(struct vc_map), GFP_KERNEL); 29911da177e4SLinus Torvalds if (!vc) { 29921da177e4SLinus Torvalds printk("%s: can't alloc vc\n", card->name); 29931da177e4SLinus Torvalds return -ENOMEM; 29941da177e4SLinus Torvalds } 29951da177e4SLinus Torvalds card->vcs[0] = vc; 29961da177e4SLinus Torvalds vc->class = SCHED_UBR0; 29971da177e4SLinus Torvalds 29981da177e4SLinus Torvalds vc->scq = alloc_scq(card, vc->class); 29991da177e4SLinus Torvalds if (!vc->scq) { 30001da177e4SLinus Torvalds printk("%s: can't get SCQ.\n", card->name); 30011da177e4SLinus Torvalds return -ENOMEM; 30021da177e4SLinus Torvalds } 30031da177e4SLinus Torvalds 30041da177e4SLinus Torvalds card->scd2vc[0] = vc; 30051da177e4SLinus Torvalds vc->scd_index = 0; 30061da177e4SLinus Torvalds vc->scq->scd = card->scd_base; 30071da177e4SLinus Torvalds 30081da177e4SLinus Torvalds fill_scd(card, vc->scq, vc->class); 30091da177e4SLinus Torvalds 30101da177e4SLinus Torvalds write_sram(card, card->tct_base + 0, TCT_UBR | card->scd_base); 30111da177e4SLinus Torvalds write_sram(card, card->tct_base + 1, 0); 30121da177e4SLinus Torvalds write_sram(card, card->tct_base + 2, 0); 30131da177e4SLinus Torvalds write_sram(card, card->tct_base + 3, 0); 30141da177e4SLinus Torvalds write_sram(card, card->tct_base + 4, 0); 30151da177e4SLinus Torvalds write_sram(card, card->tct_base + 5, 0); 30161da177e4SLinus Torvalds write_sram(card, card->tct_base + 6, 0); 30171da177e4SLinus Torvalds write_sram(card, card->tct_base + 7, TCT_FLAG_UBR); 30181da177e4SLinus Torvalds 30191da177e4SLinus Torvalds clear_bit(VCF_IDLE, &vc->flags); 30201da177e4SLinus Torvalds writel(TCMDQ_START | 0, SAR_REG_TCMDQ); 30211da177e4SLinus Torvalds return 0; 30221da177e4SLinus Torvalds } 30231da177e4SLinus Torvalds 30241da177e4SLinus Torvalds static int 30251da177e4SLinus Torvalds idt77252_dev_open(struct idt77252_dev *card) 30261da177e4SLinus Torvalds { 30271da177e4SLinus Torvalds u32 conf; 30281da177e4SLinus Torvalds 30291da177e4SLinus Torvalds if (!test_bit(IDT77252_BIT_INIT, &card->flags)) { 30301da177e4SLinus Torvalds printk("%s: SAR not yet initialized.\n", card->name); 30311da177e4SLinus Torvalds return -1; 30321da177e4SLinus Torvalds } 30331da177e4SLinus Torvalds 30341da177e4SLinus Torvalds conf = SAR_CFG_RXPTH| /* enable receive path */ 30351da177e4SLinus Torvalds SAR_RX_DELAY | /* interrupt on complete PDU */ 30361da177e4SLinus Torvalds SAR_CFG_RAWIE | /* interrupt enable on raw cells */ 30371da177e4SLinus Torvalds SAR_CFG_RQFIE | /* interrupt on RSQ almost full */ 30381da177e4SLinus Torvalds SAR_CFG_TMOIE | /* interrupt on timer overflow */ 30391da177e4SLinus Torvalds SAR_CFG_FBIE | /* interrupt on low free buffers */ 30401da177e4SLinus Torvalds SAR_CFG_TXEN | /* transmit operation enable */ 30411da177e4SLinus Torvalds SAR_CFG_TXINT | /* interrupt on transmit status */ 30421da177e4SLinus Torvalds SAR_CFG_TXUIE | /* interrupt on transmit underrun */ 30431da177e4SLinus Torvalds SAR_CFG_TXSFI | /* interrupt on TSQ almost full */ 30441da177e4SLinus Torvalds SAR_CFG_PHYIE /* enable PHY interrupts */ 30451da177e4SLinus Torvalds ; 30461da177e4SLinus Torvalds 30471da177e4SLinus Torvalds #ifdef CONFIG_ATM_IDT77252_RCV_ALL 30481da177e4SLinus Torvalds /* Test RAW cell receive. */ 30491da177e4SLinus Torvalds conf |= SAR_CFG_VPECA; 30501da177e4SLinus Torvalds #endif 30511da177e4SLinus Torvalds 30521da177e4SLinus Torvalds writel(readl(SAR_REG_CFG) | conf, SAR_REG_CFG); 30531da177e4SLinus Torvalds 30541da177e4SLinus Torvalds if (open_card_oam(card)) { 30551da177e4SLinus Torvalds printk("%s: Error initializing OAM.\n", card->name); 30561da177e4SLinus Torvalds return -1; 30571da177e4SLinus Torvalds } 30581da177e4SLinus Torvalds 30591da177e4SLinus Torvalds if (open_card_ubr0(card)) { 30601da177e4SLinus Torvalds printk("%s: Error initializing UBR0.\n", card->name); 30611da177e4SLinus Torvalds return -1; 30621da177e4SLinus Torvalds } 30631da177e4SLinus Torvalds 30641da177e4SLinus Torvalds IPRINTK("%s: opened IDT77252 ABR SAR.\n", card->name); 30651da177e4SLinus Torvalds return 0; 30661da177e4SLinus Torvalds } 30671da177e4SLinus Torvalds 30681da177e4SLinus Torvalds void 30691da177e4SLinus Torvalds idt77252_dev_close(struct atm_dev *dev) 30701da177e4SLinus Torvalds { 30711da177e4SLinus Torvalds struct idt77252_dev *card = dev->dev_data; 30721da177e4SLinus Torvalds u32 conf; 30731da177e4SLinus Torvalds 30741da177e4SLinus Torvalds close_card_oam(card); 30751da177e4SLinus Torvalds 30761da177e4SLinus Torvalds conf = SAR_CFG_RXPTH | /* enable receive path */ 30771da177e4SLinus Torvalds SAR_RX_DELAY | /* interrupt on complete PDU */ 30781da177e4SLinus Torvalds SAR_CFG_RAWIE | /* interrupt enable on raw cells */ 30791da177e4SLinus Torvalds SAR_CFG_RQFIE | /* interrupt on RSQ almost full */ 30801da177e4SLinus Torvalds SAR_CFG_TMOIE | /* interrupt on timer overflow */ 30811da177e4SLinus Torvalds SAR_CFG_FBIE | /* interrupt on low free buffers */ 30821da177e4SLinus Torvalds SAR_CFG_TXEN | /* transmit operation enable */ 30831da177e4SLinus Torvalds SAR_CFG_TXINT | /* interrupt on transmit status */ 30841da177e4SLinus Torvalds SAR_CFG_TXUIE | /* interrupt on xmit underrun */ 30851da177e4SLinus Torvalds SAR_CFG_TXSFI /* interrupt on TSQ almost full */ 30861da177e4SLinus Torvalds ; 30871da177e4SLinus Torvalds 30881da177e4SLinus Torvalds writel(readl(SAR_REG_CFG) & ~(conf), SAR_REG_CFG); 30891da177e4SLinus Torvalds 30901da177e4SLinus Torvalds DIPRINTK("%s: closed IDT77252 ABR SAR.\n", card->name); 30911da177e4SLinus Torvalds } 30921da177e4SLinus Torvalds 30931da177e4SLinus Torvalds 30941da177e4SLinus Torvalds /*****************************************************************************/ 30951da177e4SLinus Torvalds /* */ 30961da177e4SLinus Torvalds /* Initialisation and Deinitialization of IDT77252 */ 30971da177e4SLinus Torvalds /* */ 30981da177e4SLinus Torvalds /*****************************************************************************/ 30991da177e4SLinus Torvalds 31001da177e4SLinus Torvalds 31011da177e4SLinus Torvalds static void 31021da177e4SLinus Torvalds deinit_card(struct idt77252_dev *card) 31031da177e4SLinus Torvalds { 31041da177e4SLinus Torvalds struct sk_buff *skb; 31051da177e4SLinus Torvalds int i, j; 31061da177e4SLinus Torvalds 31071da177e4SLinus Torvalds if (!test_bit(IDT77252_BIT_INIT, &card->flags)) { 31081da177e4SLinus Torvalds printk("%s: SAR not yet initialized.\n", card->name); 31091da177e4SLinus Torvalds return; 31101da177e4SLinus Torvalds } 31111da177e4SLinus Torvalds DIPRINTK("idt77252: deinitialize card %u\n", card->index); 31121da177e4SLinus Torvalds 31131da177e4SLinus Torvalds writel(0, SAR_REG_CFG); 31141da177e4SLinus Torvalds 31151da177e4SLinus Torvalds if (card->atmdev) 31161da177e4SLinus Torvalds atm_dev_deregister(card->atmdev); 31171da177e4SLinus Torvalds 31181da177e4SLinus Torvalds for (i = 0; i < 4; i++) { 31191da177e4SLinus Torvalds for (j = 0; j < FBQ_SIZE; j++) { 31201da177e4SLinus Torvalds skb = card->sbpool[i].skb[j]; 31211da177e4SLinus Torvalds if (skb) { 31221da177e4SLinus Torvalds pci_unmap_single(card->pcidev, 31231da177e4SLinus Torvalds IDT77252_PRV_PADDR(skb), 31241da177e4SLinus Torvalds skb->end - skb->data, 31251da177e4SLinus Torvalds PCI_DMA_FROMDEVICE); 31261da177e4SLinus Torvalds card->sbpool[i].skb[j] = NULL; 31271da177e4SLinus Torvalds dev_kfree_skb(skb); 31281da177e4SLinus Torvalds } 31291da177e4SLinus Torvalds } 31301da177e4SLinus Torvalds } 31311da177e4SLinus Torvalds 31321da177e4SLinus Torvalds vfree(card->soft_tst); 31331da177e4SLinus Torvalds 31341da177e4SLinus Torvalds vfree(card->scd2vc); 31351da177e4SLinus Torvalds 31361da177e4SLinus Torvalds vfree(card->vcs); 31371da177e4SLinus Torvalds 31381da177e4SLinus Torvalds if (card->raw_cell_hnd) { 31391da177e4SLinus Torvalds pci_free_consistent(card->pcidev, 2 * sizeof(u32), 31401da177e4SLinus Torvalds card->raw_cell_hnd, card->raw_cell_paddr); 31411da177e4SLinus Torvalds } 31421da177e4SLinus Torvalds 31431da177e4SLinus Torvalds if (card->rsq.base) { 31441da177e4SLinus Torvalds DIPRINTK("%s: Release RSQ ...\n", card->name); 31451da177e4SLinus Torvalds deinit_rsq(card); 31461da177e4SLinus Torvalds } 31471da177e4SLinus Torvalds 31481da177e4SLinus Torvalds if (card->tsq.base) { 31491da177e4SLinus Torvalds DIPRINTK("%s: Release TSQ ...\n", card->name); 31501da177e4SLinus Torvalds deinit_tsq(card); 31511da177e4SLinus Torvalds } 31521da177e4SLinus Torvalds 31531da177e4SLinus Torvalds DIPRINTK("idt77252: Release IRQ.\n"); 31541da177e4SLinus Torvalds free_irq(card->pcidev->irq, card); 31551da177e4SLinus Torvalds 31561da177e4SLinus Torvalds for (i = 0; i < 4; i++) { 31571da177e4SLinus Torvalds if (card->fbq[i]) 31581da177e4SLinus Torvalds iounmap(card->fbq[i]); 31591da177e4SLinus Torvalds } 31601da177e4SLinus Torvalds 31611da177e4SLinus Torvalds if (card->membase) 31621da177e4SLinus Torvalds iounmap(card->membase); 31631da177e4SLinus Torvalds 31641da177e4SLinus Torvalds clear_bit(IDT77252_BIT_INIT, &card->flags); 31651da177e4SLinus Torvalds DIPRINTK("%s: Card deinitialized.\n", card->name); 31661da177e4SLinus Torvalds } 31671da177e4SLinus Torvalds 31681da177e4SLinus Torvalds 31691da177e4SLinus Torvalds static int __devinit 31701da177e4SLinus Torvalds init_sram(struct idt77252_dev *card) 31711da177e4SLinus Torvalds { 31721da177e4SLinus Torvalds int i; 31731da177e4SLinus Torvalds 31741da177e4SLinus Torvalds for (i = 0; i < card->sramsize; i += 4) 31751da177e4SLinus Torvalds write_sram(card, (i >> 2), 0); 31761da177e4SLinus Torvalds 31771da177e4SLinus Torvalds /* set SRAM layout for THIS card */ 31781da177e4SLinus Torvalds if (card->sramsize == (512 * 1024)) { 31791da177e4SLinus Torvalds card->tct_base = SAR_SRAM_TCT_128_BASE; 31801da177e4SLinus Torvalds card->tct_size = (SAR_SRAM_TCT_128_TOP - card->tct_base + 1) 31811da177e4SLinus Torvalds / SAR_SRAM_TCT_SIZE; 31821da177e4SLinus Torvalds card->rct_base = SAR_SRAM_RCT_128_BASE; 31831da177e4SLinus Torvalds card->rct_size = (SAR_SRAM_RCT_128_TOP - card->rct_base + 1) 31841da177e4SLinus Torvalds / SAR_SRAM_RCT_SIZE; 31851da177e4SLinus Torvalds card->rt_base = SAR_SRAM_RT_128_BASE; 31861da177e4SLinus Torvalds card->scd_base = SAR_SRAM_SCD_128_BASE; 31871da177e4SLinus Torvalds card->scd_size = (SAR_SRAM_SCD_128_TOP - card->scd_base + 1) 31881da177e4SLinus Torvalds / SAR_SRAM_SCD_SIZE; 31891da177e4SLinus Torvalds card->tst[0] = SAR_SRAM_TST1_128_BASE; 31901da177e4SLinus Torvalds card->tst[1] = SAR_SRAM_TST2_128_BASE; 31911da177e4SLinus Torvalds card->tst_size = SAR_SRAM_TST1_128_TOP - card->tst[0] + 1; 31921da177e4SLinus Torvalds card->abrst_base = SAR_SRAM_ABRSTD_128_BASE; 31931da177e4SLinus Torvalds card->abrst_size = SAR_ABRSTD_SIZE_8K; 31941da177e4SLinus Torvalds card->fifo_base = SAR_SRAM_FIFO_128_BASE; 31951da177e4SLinus Torvalds card->fifo_size = SAR_RXFD_SIZE_32K; 31961da177e4SLinus Torvalds } else { 31971da177e4SLinus Torvalds card->tct_base = SAR_SRAM_TCT_32_BASE; 31981da177e4SLinus Torvalds card->tct_size = (SAR_SRAM_TCT_32_TOP - card->tct_base + 1) 31991da177e4SLinus Torvalds / SAR_SRAM_TCT_SIZE; 32001da177e4SLinus Torvalds card->rct_base = SAR_SRAM_RCT_32_BASE; 32011da177e4SLinus Torvalds card->rct_size = (SAR_SRAM_RCT_32_TOP - card->rct_base + 1) 32021da177e4SLinus Torvalds / SAR_SRAM_RCT_SIZE; 32031da177e4SLinus Torvalds card->rt_base = SAR_SRAM_RT_32_BASE; 32041da177e4SLinus Torvalds card->scd_base = SAR_SRAM_SCD_32_BASE; 32051da177e4SLinus Torvalds card->scd_size = (SAR_SRAM_SCD_32_TOP - card->scd_base + 1) 32061da177e4SLinus Torvalds / SAR_SRAM_SCD_SIZE; 32071da177e4SLinus Torvalds card->tst[0] = SAR_SRAM_TST1_32_BASE; 32081da177e4SLinus Torvalds card->tst[1] = SAR_SRAM_TST2_32_BASE; 32091da177e4SLinus Torvalds card->tst_size = (SAR_SRAM_TST1_32_TOP - card->tst[0] + 1); 32101da177e4SLinus Torvalds card->abrst_base = SAR_SRAM_ABRSTD_32_BASE; 32111da177e4SLinus Torvalds card->abrst_size = SAR_ABRSTD_SIZE_1K; 32121da177e4SLinus Torvalds card->fifo_base = SAR_SRAM_FIFO_32_BASE; 32131da177e4SLinus Torvalds card->fifo_size = SAR_RXFD_SIZE_4K; 32141da177e4SLinus Torvalds } 32151da177e4SLinus Torvalds 32161da177e4SLinus Torvalds /* Initialize TCT */ 32171da177e4SLinus Torvalds for (i = 0; i < card->tct_size; i++) { 32181da177e4SLinus Torvalds write_sram(card, i * SAR_SRAM_TCT_SIZE + 0, 0); 32191da177e4SLinus Torvalds write_sram(card, i * SAR_SRAM_TCT_SIZE + 1, 0); 32201da177e4SLinus Torvalds write_sram(card, i * SAR_SRAM_TCT_SIZE + 2, 0); 32211da177e4SLinus Torvalds write_sram(card, i * SAR_SRAM_TCT_SIZE + 3, 0); 32221da177e4SLinus Torvalds write_sram(card, i * SAR_SRAM_TCT_SIZE + 4, 0); 32231da177e4SLinus Torvalds write_sram(card, i * SAR_SRAM_TCT_SIZE + 5, 0); 32241da177e4SLinus Torvalds write_sram(card, i * SAR_SRAM_TCT_SIZE + 6, 0); 32251da177e4SLinus Torvalds write_sram(card, i * SAR_SRAM_TCT_SIZE + 7, 0); 32261da177e4SLinus Torvalds } 32271da177e4SLinus Torvalds 32281da177e4SLinus Torvalds /* Initialize RCT */ 32291da177e4SLinus Torvalds for (i = 0; i < card->rct_size; i++) { 32301da177e4SLinus Torvalds write_sram(card, card->rct_base + i * SAR_SRAM_RCT_SIZE, 32311da177e4SLinus Torvalds (u32) SAR_RCTE_RAWCELLINTEN); 32321da177e4SLinus Torvalds write_sram(card, card->rct_base + i * SAR_SRAM_RCT_SIZE + 1, 32331da177e4SLinus Torvalds (u32) 0); 32341da177e4SLinus Torvalds write_sram(card, card->rct_base + i * SAR_SRAM_RCT_SIZE + 2, 32351da177e4SLinus Torvalds (u32) 0); 32361da177e4SLinus Torvalds write_sram(card, card->rct_base + i * SAR_SRAM_RCT_SIZE + 3, 32371da177e4SLinus Torvalds (u32) 0xffffffff); 32381da177e4SLinus Torvalds } 32391da177e4SLinus Torvalds 32401da177e4SLinus Torvalds writel((SAR_FBQ0_LOW << 28) | 0x00000000 | 0x00000000 | 32411da177e4SLinus Torvalds (SAR_FB_SIZE_0 / 48), SAR_REG_FBQS0); 32421da177e4SLinus Torvalds writel((SAR_FBQ1_LOW << 28) | 0x00000000 | 0x00000000 | 32431da177e4SLinus Torvalds (SAR_FB_SIZE_1 / 48), SAR_REG_FBQS1); 32441da177e4SLinus Torvalds writel((SAR_FBQ2_LOW << 28) | 0x00000000 | 0x00000000 | 32451da177e4SLinus Torvalds (SAR_FB_SIZE_2 / 48), SAR_REG_FBQS2); 32461da177e4SLinus Torvalds writel((SAR_FBQ3_LOW << 28) | 0x00000000 | 0x00000000 | 32471da177e4SLinus Torvalds (SAR_FB_SIZE_3 / 48), SAR_REG_FBQS3); 32481da177e4SLinus Torvalds 32491da177e4SLinus Torvalds /* Initialize rate table */ 32501da177e4SLinus Torvalds for (i = 0; i < 256; i++) { 32511da177e4SLinus Torvalds write_sram(card, card->rt_base + i, log_to_rate[i]); 32521da177e4SLinus Torvalds } 32531da177e4SLinus Torvalds 32541da177e4SLinus Torvalds for (i = 0; i < 128; i++) { 32551da177e4SLinus Torvalds unsigned int tmp; 32561da177e4SLinus Torvalds 32571da177e4SLinus Torvalds tmp = rate_to_log[(i << 2) + 0] << 0; 32581da177e4SLinus Torvalds tmp |= rate_to_log[(i << 2) + 1] << 8; 32591da177e4SLinus Torvalds tmp |= rate_to_log[(i << 2) + 2] << 16; 32601da177e4SLinus Torvalds tmp |= rate_to_log[(i << 2) + 3] << 24; 32611da177e4SLinus Torvalds write_sram(card, card->rt_base + 256 + i, tmp); 32621da177e4SLinus Torvalds } 32631da177e4SLinus Torvalds 32641da177e4SLinus Torvalds #if 0 /* Fill RDF and AIR tables. */ 32651da177e4SLinus Torvalds for (i = 0; i < 128; i++) { 32661da177e4SLinus Torvalds unsigned int tmp; 32671da177e4SLinus Torvalds 32681da177e4SLinus Torvalds tmp = RDF[0][(i << 1) + 0] << 16; 32691da177e4SLinus Torvalds tmp |= RDF[0][(i << 1) + 1] << 0; 32701da177e4SLinus Torvalds write_sram(card, card->rt_base + 512 + i, tmp); 32711da177e4SLinus Torvalds } 32721da177e4SLinus Torvalds 32731da177e4SLinus Torvalds for (i = 0; i < 128; i++) { 32741da177e4SLinus Torvalds unsigned int tmp; 32751da177e4SLinus Torvalds 32761da177e4SLinus Torvalds tmp = AIR[0][(i << 1) + 0] << 16; 32771da177e4SLinus Torvalds tmp |= AIR[0][(i << 1) + 1] << 0; 32781da177e4SLinus Torvalds write_sram(card, card->rt_base + 640 + i, tmp); 32791da177e4SLinus Torvalds } 32801da177e4SLinus Torvalds #endif 32811da177e4SLinus Torvalds 32821da177e4SLinus Torvalds IPRINTK("%s: initialize rate table ...\n", card->name); 32831da177e4SLinus Torvalds writel(card->rt_base << 2, SAR_REG_RTBL); 32841da177e4SLinus Torvalds 32851da177e4SLinus Torvalds /* Initialize TSTs */ 32861da177e4SLinus Torvalds IPRINTK("%s: initialize TST ...\n", card->name); 32871da177e4SLinus Torvalds card->tst_free = card->tst_size - 2; /* last two are jumps */ 32881da177e4SLinus Torvalds 32891da177e4SLinus Torvalds for (i = card->tst[0]; i < card->tst[0] + card->tst_size - 2; i++) 32901da177e4SLinus Torvalds write_sram(card, i, TSTE_OPC_VAR); 32911da177e4SLinus Torvalds write_sram(card, i++, TSTE_OPC_JMP | (card->tst[0] << 2)); 32921da177e4SLinus Torvalds idt77252_sram_write_errors = 1; 32931da177e4SLinus Torvalds write_sram(card, i++, TSTE_OPC_JMP | (card->tst[1] << 2)); 32941da177e4SLinus Torvalds idt77252_sram_write_errors = 0; 32951da177e4SLinus Torvalds for (i = card->tst[1]; i < card->tst[1] + card->tst_size - 2; i++) 32961da177e4SLinus Torvalds write_sram(card, i, TSTE_OPC_VAR); 32971da177e4SLinus Torvalds write_sram(card, i++, TSTE_OPC_JMP | (card->tst[1] << 2)); 32981da177e4SLinus Torvalds idt77252_sram_write_errors = 1; 32991da177e4SLinus Torvalds write_sram(card, i++, TSTE_OPC_JMP | (card->tst[0] << 2)); 33001da177e4SLinus Torvalds idt77252_sram_write_errors = 0; 33011da177e4SLinus Torvalds 33021da177e4SLinus Torvalds card->tst_index = 0; 33031da177e4SLinus Torvalds writel(card->tst[0] << 2, SAR_REG_TSTB); 33041da177e4SLinus Torvalds 33051da177e4SLinus Torvalds /* Initialize ABRSTD and Receive FIFO */ 33061da177e4SLinus Torvalds IPRINTK("%s: initialize ABRSTD ...\n", card->name); 33071da177e4SLinus Torvalds writel(card->abrst_size | (card->abrst_base << 2), 33081da177e4SLinus Torvalds SAR_REG_ABRSTD); 33091da177e4SLinus Torvalds 33101da177e4SLinus Torvalds IPRINTK("%s: initialize receive fifo ...\n", card->name); 33111da177e4SLinus Torvalds writel(card->fifo_size | (card->fifo_base << 2), 33121da177e4SLinus Torvalds SAR_REG_RXFD); 33131da177e4SLinus Torvalds 33141da177e4SLinus Torvalds IPRINTK("%s: SRAM initialization complete.\n", card->name); 33151da177e4SLinus Torvalds return 0; 33161da177e4SLinus Torvalds } 33171da177e4SLinus Torvalds 33181da177e4SLinus Torvalds static int __devinit 33191da177e4SLinus Torvalds init_card(struct atm_dev *dev) 33201da177e4SLinus Torvalds { 33211da177e4SLinus Torvalds struct idt77252_dev *card = dev->dev_data; 33221da177e4SLinus Torvalds struct pci_dev *pcidev = card->pcidev; 33231da177e4SLinus Torvalds unsigned long tmpl, modl; 33241da177e4SLinus Torvalds unsigned int linkrate, rsvdcr; 33251da177e4SLinus Torvalds unsigned int tst_entries; 33261da177e4SLinus Torvalds struct net_device *tmp; 33271da177e4SLinus Torvalds char tname[10]; 33281da177e4SLinus Torvalds 33291da177e4SLinus Torvalds u32 size; 33301da177e4SLinus Torvalds u_char pci_byte; 33311da177e4SLinus Torvalds u32 conf; 33321da177e4SLinus Torvalds int i, k; 33331da177e4SLinus Torvalds 33341da177e4SLinus Torvalds if (test_bit(IDT77252_BIT_INIT, &card->flags)) { 33351da177e4SLinus Torvalds printk("Error: SAR already initialized.\n"); 33361da177e4SLinus Torvalds return -1; 33371da177e4SLinus Torvalds } 33381da177e4SLinus Torvalds 33391da177e4SLinus Torvalds /*****************************************************************/ 33401da177e4SLinus Torvalds /* P C I C O N F I G U R A T I O N */ 33411da177e4SLinus Torvalds /*****************************************************************/ 33421da177e4SLinus Torvalds 33431da177e4SLinus Torvalds /* Set PCI Retry-Timeout and TRDY timeout */ 33441da177e4SLinus Torvalds IPRINTK("%s: Checking PCI retries.\n", card->name); 33451da177e4SLinus Torvalds if (pci_read_config_byte(pcidev, 0x40, &pci_byte) != 0) { 33461da177e4SLinus Torvalds printk("%s: can't read PCI retry timeout.\n", card->name); 33471da177e4SLinus Torvalds deinit_card(card); 33481da177e4SLinus Torvalds return -1; 33491da177e4SLinus Torvalds } 33501da177e4SLinus Torvalds if (pci_byte != 0) { 33511da177e4SLinus Torvalds IPRINTK("%s: PCI retry timeout: %d, set to 0.\n", 33521da177e4SLinus Torvalds card->name, pci_byte); 33531da177e4SLinus Torvalds if (pci_write_config_byte(pcidev, 0x40, 0) != 0) { 33541da177e4SLinus Torvalds printk("%s: can't set PCI retry timeout.\n", 33551da177e4SLinus Torvalds card->name); 33561da177e4SLinus Torvalds deinit_card(card); 33571da177e4SLinus Torvalds return -1; 33581da177e4SLinus Torvalds } 33591da177e4SLinus Torvalds } 33601da177e4SLinus Torvalds IPRINTK("%s: Checking PCI TRDY.\n", card->name); 33611da177e4SLinus Torvalds if (pci_read_config_byte(pcidev, 0x41, &pci_byte) != 0) { 33621da177e4SLinus Torvalds printk("%s: can't read PCI TRDY timeout.\n", card->name); 33631da177e4SLinus Torvalds deinit_card(card); 33641da177e4SLinus Torvalds return -1; 33651da177e4SLinus Torvalds } 33661da177e4SLinus Torvalds if (pci_byte != 0) { 33671da177e4SLinus Torvalds IPRINTK("%s: PCI TRDY timeout: %d, set to 0.\n", 33681da177e4SLinus Torvalds card->name, pci_byte); 33691da177e4SLinus Torvalds if (pci_write_config_byte(pcidev, 0x41, 0) != 0) { 33701da177e4SLinus Torvalds printk("%s: can't set PCI TRDY timeout.\n", card->name); 33711da177e4SLinus Torvalds deinit_card(card); 33721da177e4SLinus Torvalds return -1; 33731da177e4SLinus Torvalds } 33741da177e4SLinus Torvalds } 33751da177e4SLinus Torvalds /* Reset Timer register */ 33761da177e4SLinus Torvalds if (readl(SAR_REG_STAT) & SAR_STAT_TMROF) { 33771da177e4SLinus Torvalds printk("%s: resetting timer overflow.\n", card->name); 33781da177e4SLinus Torvalds writel(SAR_STAT_TMROF, SAR_REG_STAT); 33791da177e4SLinus Torvalds } 33801da177e4SLinus Torvalds IPRINTK("%s: Request IRQ ... ", card->name); 3381dace1453SThomas Gleixner if (request_irq(pcidev->irq, idt77252_interrupt, IRQF_DISABLED|IRQF_SHARED, 33821da177e4SLinus Torvalds card->name, card) != 0) { 33831da177e4SLinus Torvalds printk("%s: can't allocate IRQ.\n", card->name); 33841da177e4SLinus Torvalds deinit_card(card); 33851da177e4SLinus Torvalds return -1; 33861da177e4SLinus Torvalds } 33871da177e4SLinus Torvalds IPRINTK("got %d.\n", pcidev->irq); 33881da177e4SLinus Torvalds 33891da177e4SLinus Torvalds /*****************************************************************/ 33901da177e4SLinus Torvalds /* C H E C K A N D I N I T S R A M */ 33911da177e4SLinus Torvalds /*****************************************************************/ 33921da177e4SLinus Torvalds 33931da177e4SLinus Torvalds IPRINTK("%s: Initializing SRAM\n", card->name); 33941da177e4SLinus Torvalds 33951da177e4SLinus Torvalds /* preset size of connecton table, so that init_sram() knows about it */ 33961da177e4SLinus Torvalds conf = SAR_CFG_TX_FIFO_SIZE_9 | /* Use maximum fifo size */ 33971da177e4SLinus Torvalds SAR_CFG_RXSTQ_SIZE_8k | /* Receive Status Queue is 8k */ 33981da177e4SLinus Torvalds SAR_CFG_IDLE_CLP | /* Set CLP on idle cells */ 33991da177e4SLinus Torvalds #ifndef CONFIG_ATM_IDT77252_SEND_IDLE 34001da177e4SLinus Torvalds SAR_CFG_NO_IDLE | /* Do not send idle cells */ 34011da177e4SLinus Torvalds #endif 34021da177e4SLinus Torvalds 0; 34031da177e4SLinus Torvalds 34041da177e4SLinus Torvalds if (card->sramsize == (512 * 1024)) 34051da177e4SLinus Torvalds conf |= SAR_CFG_CNTBL_1k; 34061da177e4SLinus Torvalds else 34071da177e4SLinus Torvalds conf |= SAR_CFG_CNTBL_512; 34081da177e4SLinus Torvalds 34091da177e4SLinus Torvalds switch (vpibits) { 34101da177e4SLinus Torvalds case 0: 34111da177e4SLinus Torvalds conf |= SAR_CFG_VPVCS_0; 34121da177e4SLinus Torvalds break; 34131da177e4SLinus Torvalds default: 34141da177e4SLinus Torvalds case 1: 34151da177e4SLinus Torvalds conf |= SAR_CFG_VPVCS_1; 34161da177e4SLinus Torvalds break; 34171da177e4SLinus Torvalds case 2: 34181da177e4SLinus Torvalds conf |= SAR_CFG_VPVCS_2; 34191da177e4SLinus Torvalds break; 34201da177e4SLinus Torvalds case 8: 34211da177e4SLinus Torvalds conf |= SAR_CFG_VPVCS_8; 34221da177e4SLinus Torvalds break; 34231da177e4SLinus Torvalds } 34241da177e4SLinus Torvalds 34251da177e4SLinus Torvalds writel(readl(SAR_REG_CFG) | conf, SAR_REG_CFG); 34261da177e4SLinus Torvalds 34271da177e4SLinus Torvalds if (init_sram(card) < 0) 34281da177e4SLinus Torvalds return -1; 34291da177e4SLinus Torvalds 34301da177e4SLinus Torvalds /********************************************************************/ 34311da177e4SLinus Torvalds /* A L L O C R A M A N D S E T V A R I O U S T H I N G S */ 34321da177e4SLinus Torvalds /********************************************************************/ 34331da177e4SLinus Torvalds /* Initialize TSQ */ 34341da177e4SLinus Torvalds if (0 != init_tsq(card)) { 34351da177e4SLinus Torvalds deinit_card(card); 34361da177e4SLinus Torvalds return -1; 34371da177e4SLinus Torvalds } 34381da177e4SLinus Torvalds /* Initialize RSQ */ 34391da177e4SLinus Torvalds if (0 != init_rsq(card)) { 34401da177e4SLinus Torvalds deinit_card(card); 34411da177e4SLinus Torvalds return -1; 34421da177e4SLinus Torvalds } 34431da177e4SLinus Torvalds 34441da177e4SLinus Torvalds card->vpibits = vpibits; 34451da177e4SLinus Torvalds if (card->sramsize == (512 * 1024)) { 34461da177e4SLinus Torvalds card->vcibits = 10 - card->vpibits; 34471da177e4SLinus Torvalds } else { 34481da177e4SLinus Torvalds card->vcibits = 9 - card->vpibits; 34491da177e4SLinus Torvalds } 34501da177e4SLinus Torvalds 34511da177e4SLinus Torvalds card->vcimask = 0; 34521da177e4SLinus Torvalds for (k = 0, i = 1; k < card->vcibits; k++) { 34531da177e4SLinus Torvalds card->vcimask |= i; 34541da177e4SLinus Torvalds i <<= 1; 34551da177e4SLinus Torvalds } 34561da177e4SLinus Torvalds 34571da177e4SLinus Torvalds IPRINTK("%s: Setting VPI/VCI mask to zero.\n", card->name); 34581da177e4SLinus Torvalds writel(0, SAR_REG_VPM); 34591da177e4SLinus Torvalds 34601da177e4SLinus Torvalds /* Little Endian Order */ 34611da177e4SLinus Torvalds writel(0, SAR_REG_GP); 34621da177e4SLinus Torvalds 34631da177e4SLinus Torvalds /* Initialize RAW Cell Handle Register */ 34641da177e4SLinus Torvalds card->raw_cell_hnd = pci_alloc_consistent(card->pcidev, 2 * sizeof(u32), 34651da177e4SLinus Torvalds &card->raw_cell_paddr); 34661da177e4SLinus Torvalds if (!card->raw_cell_hnd) { 34671da177e4SLinus Torvalds printk("%s: memory allocation failure.\n", card->name); 34681da177e4SLinus Torvalds deinit_card(card); 34691da177e4SLinus Torvalds return -1; 34701da177e4SLinus Torvalds } 34711da177e4SLinus Torvalds memset(card->raw_cell_hnd, 0, 2 * sizeof(u32)); 34721da177e4SLinus Torvalds writel(card->raw_cell_paddr, SAR_REG_RAWHND); 34731da177e4SLinus Torvalds IPRINTK("%s: raw cell handle is at 0x%p.\n", card->name, 34741da177e4SLinus Torvalds card->raw_cell_hnd); 34751da177e4SLinus Torvalds 34761da177e4SLinus Torvalds size = sizeof(struct vc_map *) * card->tct_size; 34771da177e4SLinus Torvalds IPRINTK("%s: allocate %d byte for VC map.\n", card->name, size); 34781da177e4SLinus Torvalds if (NULL == (card->vcs = vmalloc(size))) { 34791da177e4SLinus Torvalds printk("%s: memory allocation failure.\n", card->name); 34801da177e4SLinus Torvalds deinit_card(card); 34811da177e4SLinus Torvalds return -1; 34821da177e4SLinus Torvalds } 34831da177e4SLinus Torvalds memset(card->vcs, 0, size); 34841da177e4SLinus Torvalds 34851da177e4SLinus Torvalds size = sizeof(struct vc_map *) * card->scd_size; 34861da177e4SLinus Torvalds IPRINTK("%s: allocate %d byte for SCD to VC mapping.\n", 34871da177e4SLinus Torvalds card->name, size); 34881da177e4SLinus Torvalds if (NULL == (card->scd2vc = vmalloc(size))) { 34891da177e4SLinus Torvalds printk("%s: memory allocation failure.\n", card->name); 34901da177e4SLinus Torvalds deinit_card(card); 34911da177e4SLinus Torvalds return -1; 34921da177e4SLinus Torvalds } 34931da177e4SLinus Torvalds memset(card->scd2vc, 0, size); 34941da177e4SLinus Torvalds 34951da177e4SLinus Torvalds size = sizeof(struct tst_info) * (card->tst_size - 2); 34961da177e4SLinus Torvalds IPRINTK("%s: allocate %d byte for TST to VC mapping.\n", 34971da177e4SLinus Torvalds card->name, size); 34981da177e4SLinus Torvalds if (NULL == (card->soft_tst = vmalloc(size))) { 34991da177e4SLinus Torvalds printk("%s: memory allocation failure.\n", card->name); 35001da177e4SLinus Torvalds deinit_card(card); 35011da177e4SLinus Torvalds return -1; 35021da177e4SLinus Torvalds } 35031da177e4SLinus Torvalds for (i = 0; i < card->tst_size - 2; i++) { 35041da177e4SLinus Torvalds card->soft_tst[i].tste = TSTE_OPC_VAR; 35051da177e4SLinus Torvalds card->soft_tst[i].vc = NULL; 35061da177e4SLinus Torvalds } 35071da177e4SLinus Torvalds 35081da177e4SLinus Torvalds if (dev->phy == NULL) { 35091da177e4SLinus Torvalds printk("%s: No LT device defined.\n", card->name); 35101da177e4SLinus Torvalds deinit_card(card); 35111da177e4SLinus Torvalds return -1; 35121da177e4SLinus Torvalds } 35131da177e4SLinus Torvalds if (dev->phy->ioctl == NULL) { 35141da177e4SLinus Torvalds printk("%s: LT had no IOCTL funtion defined.\n", card->name); 35151da177e4SLinus Torvalds deinit_card(card); 35161da177e4SLinus Torvalds return -1; 35171da177e4SLinus Torvalds } 35181da177e4SLinus Torvalds 35191da177e4SLinus Torvalds #ifdef CONFIG_ATM_IDT77252_USE_SUNI 35201da177e4SLinus Torvalds /* 35211da177e4SLinus Torvalds * this is a jhs hack to get around special functionality in the 35221da177e4SLinus Torvalds * phy driver for the atecom hardware; the functionality doesn't 35231da177e4SLinus Torvalds * exist in the linux atm suni driver 35241da177e4SLinus Torvalds * 35251da177e4SLinus Torvalds * it isn't the right way to do things, but as the guy from NIST 35261da177e4SLinus Torvalds * said, talking about their measurement of the fine structure 35271da177e4SLinus Torvalds * constant, "it's good enough for government work." 35281da177e4SLinus Torvalds */ 35291da177e4SLinus Torvalds linkrate = 149760000; 35301da177e4SLinus Torvalds #endif 35311da177e4SLinus Torvalds 35321da177e4SLinus Torvalds card->link_pcr = (linkrate / 8 / 53); 35331da177e4SLinus Torvalds printk("%s: Linkrate on ATM line : %u bit/s, %u cell/s.\n", 35341da177e4SLinus Torvalds card->name, linkrate, card->link_pcr); 35351da177e4SLinus Torvalds 35361da177e4SLinus Torvalds #ifdef CONFIG_ATM_IDT77252_SEND_IDLE 35371da177e4SLinus Torvalds card->utopia_pcr = card->link_pcr; 35381da177e4SLinus Torvalds #else 35391da177e4SLinus Torvalds card->utopia_pcr = (160000000 / 8 / 54); 35401da177e4SLinus Torvalds #endif 35411da177e4SLinus Torvalds 35421da177e4SLinus Torvalds rsvdcr = 0; 35431da177e4SLinus Torvalds if (card->utopia_pcr > card->link_pcr) 35441da177e4SLinus Torvalds rsvdcr = card->utopia_pcr - card->link_pcr; 35451da177e4SLinus Torvalds 35461da177e4SLinus Torvalds tmpl = (unsigned long) rsvdcr * ((unsigned long) card->tst_size - 2); 35471da177e4SLinus Torvalds modl = tmpl % (unsigned long)card->utopia_pcr; 35481da177e4SLinus Torvalds tst_entries = (int) (tmpl / (unsigned long)card->utopia_pcr); 35491da177e4SLinus Torvalds if (modl) 35501da177e4SLinus Torvalds tst_entries++; 35511da177e4SLinus Torvalds card->tst_free -= tst_entries; 35521da177e4SLinus Torvalds fill_tst(card, NULL, tst_entries, TSTE_OPC_NULL); 35531da177e4SLinus Torvalds 35541da177e4SLinus Torvalds #ifdef HAVE_EEPROM 35551da177e4SLinus Torvalds idt77252_eeprom_init(card); 35561da177e4SLinus Torvalds printk("%s: EEPROM: %02x:", card->name, 35571da177e4SLinus Torvalds idt77252_eeprom_read_status(card)); 35581da177e4SLinus Torvalds 35591da177e4SLinus Torvalds for (i = 0; i < 0x80; i++) { 35601da177e4SLinus Torvalds printk(" %02x", 35611da177e4SLinus Torvalds idt77252_eeprom_read_byte(card, i) 35621da177e4SLinus Torvalds ); 35631da177e4SLinus Torvalds } 35641da177e4SLinus Torvalds printk("\n"); 35651da177e4SLinus Torvalds #endif /* HAVE_EEPROM */ 35661da177e4SLinus Torvalds 35671da177e4SLinus Torvalds /* 35681da177e4SLinus Torvalds * XXX: <hack> 35691da177e4SLinus Torvalds */ 35701da177e4SLinus Torvalds sprintf(tname, "eth%d", card->index); 35711da177e4SLinus Torvalds tmp = dev_get_by_name(tname); /* jhs: was "tmp = dev_get(tname);" */ 35721da177e4SLinus Torvalds if (tmp) { 35731da177e4SLinus Torvalds memcpy(card->atmdev->esi, tmp->dev_addr, 6); 35741da177e4SLinus Torvalds 35751da177e4SLinus Torvalds printk("%s: ESI %02x:%02x:%02x:%02x:%02x:%02x\n", 35761da177e4SLinus Torvalds card->name, card->atmdev->esi[0], card->atmdev->esi[1], 35771da177e4SLinus Torvalds card->atmdev->esi[2], card->atmdev->esi[3], 35781da177e4SLinus Torvalds card->atmdev->esi[4], card->atmdev->esi[5]); 35791da177e4SLinus Torvalds } 35801da177e4SLinus Torvalds /* 35811da177e4SLinus Torvalds * XXX: </hack> 35821da177e4SLinus Torvalds */ 35831da177e4SLinus Torvalds 35841da177e4SLinus Torvalds /* Set Maximum Deficit Count for now. */ 35851da177e4SLinus Torvalds writel(0xffff, SAR_REG_MDFCT); 35861da177e4SLinus Torvalds 35871da177e4SLinus Torvalds set_bit(IDT77252_BIT_INIT, &card->flags); 35881da177e4SLinus Torvalds 35891da177e4SLinus Torvalds XPRINTK("%s: IDT77252 ABR SAR initialization complete.\n", card->name); 35901da177e4SLinus Torvalds return 0; 35911da177e4SLinus Torvalds } 35921da177e4SLinus Torvalds 35931da177e4SLinus Torvalds 35941da177e4SLinus Torvalds /*****************************************************************************/ 35951da177e4SLinus Torvalds /* */ 35961da177e4SLinus Torvalds /* Probing of IDT77252 ABR SAR */ 35971da177e4SLinus Torvalds /* */ 35981da177e4SLinus Torvalds /*****************************************************************************/ 35991da177e4SLinus Torvalds 36001da177e4SLinus Torvalds 36011da177e4SLinus Torvalds static int __devinit 36021da177e4SLinus Torvalds idt77252_preset(struct idt77252_dev *card) 36031da177e4SLinus Torvalds { 36041da177e4SLinus Torvalds u16 pci_command; 36051da177e4SLinus Torvalds 36061da177e4SLinus Torvalds /*****************************************************************/ 36071da177e4SLinus Torvalds /* P C I C O N F I G U R A T I O N */ 36081da177e4SLinus Torvalds /*****************************************************************/ 36091da177e4SLinus Torvalds 36101da177e4SLinus Torvalds XPRINTK("%s: Enable PCI master and memory access for SAR.\n", 36111da177e4SLinus Torvalds card->name); 36121da177e4SLinus Torvalds if (pci_read_config_word(card->pcidev, PCI_COMMAND, &pci_command)) { 36131da177e4SLinus Torvalds printk("%s: can't read PCI_COMMAND.\n", card->name); 36141da177e4SLinus Torvalds deinit_card(card); 36151da177e4SLinus Torvalds return -1; 36161da177e4SLinus Torvalds } 36171da177e4SLinus Torvalds if (!(pci_command & PCI_COMMAND_IO)) { 36181da177e4SLinus Torvalds printk("%s: PCI_COMMAND: %04x (???)\n", 36191da177e4SLinus Torvalds card->name, pci_command); 36201da177e4SLinus Torvalds deinit_card(card); 36211da177e4SLinus Torvalds return (-1); 36221da177e4SLinus Torvalds } 36231da177e4SLinus Torvalds pci_command |= (PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER); 36241da177e4SLinus Torvalds if (pci_write_config_word(card->pcidev, PCI_COMMAND, pci_command)) { 36251da177e4SLinus Torvalds printk("%s: can't write PCI_COMMAND.\n", card->name); 36261da177e4SLinus Torvalds deinit_card(card); 36271da177e4SLinus Torvalds return -1; 36281da177e4SLinus Torvalds } 36291da177e4SLinus Torvalds /*****************************************************************/ 36301da177e4SLinus Torvalds /* G E N E R I C R E S E T */ 36311da177e4SLinus Torvalds /*****************************************************************/ 36321da177e4SLinus Torvalds 36331da177e4SLinus Torvalds /* Software reset */ 36341da177e4SLinus Torvalds writel(SAR_CFG_SWRST, SAR_REG_CFG); 36351da177e4SLinus Torvalds mdelay(1); 36361da177e4SLinus Torvalds writel(0, SAR_REG_CFG); 36371da177e4SLinus Torvalds 36381da177e4SLinus Torvalds IPRINTK("%s: Software resetted.\n", card->name); 36391da177e4SLinus Torvalds return 0; 36401da177e4SLinus Torvalds } 36411da177e4SLinus Torvalds 36421da177e4SLinus Torvalds 36431da177e4SLinus Torvalds static unsigned long __devinit 36441da177e4SLinus Torvalds probe_sram(struct idt77252_dev *card) 36451da177e4SLinus Torvalds { 36461da177e4SLinus Torvalds u32 data, addr; 36471da177e4SLinus Torvalds 36481da177e4SLinus Torvalds writel(0, SAR_REG_DR0); 36491da177e4SLinus Torvalds writel(SAR_CMD_WRITE_SRAM | (0 << 2), SAR_REG_CMD); 36501da177e4SLinus Torvalds 36511da177e4SLinus Torvalds for (addr = 0x4000; addr < 0x80000; addr += 0x4000) { 36523c6b3773SRandy Dunlap writel(ATM_POISON, SAR_REG_DR0); 36531da177e4SLinus Torvalds writel(SAR_CMD_WRITE_SRAM | (addr << 2), SAR_REG_CMD); 36541da177e4SLinus Torvalds 36551da177e4SLinus Torvalds writel(SAR_CMD_READ_SRAM | (0 << 2), SAR_REG_CMD); 36561da177e4SLinus Torvalds data = readl(SAR_REG_DR0); 36571da177e4SLinus Torvalds 36581da177e4SLinus Torvalds if (data != 0) 36591da177e4SLinus Torvalds break; 36601da177e4SLinus Torvalds } 36611da177e4SLinus Torvalds 36621da177e4SLinus Torvalds return addr * sizeof(u32); 36631da177e4SLinus Torvalds } 36641da177e4SLinus Torvalds 36651da177e4SLinus Torvalds static int __devinit 36661da177e4SLinus Torvalds idt77252_init_one(struct pci_dev *pcidev, const struct pci_device_id *id) 36671da177e4SLinus Torvalds { 36681da177e4SLinus Torvalds static struct idt77252_dev **last = &idt77252_chain; 36691da177e4SLinus Torvalds static int index = 0; 36701da177e4SLinus Torvalds 36711da177e4SLinus Torvalds unsigned long membase, srambase; 36721da177e4SLinus Torvalds struct idt77252_dev *card; 36731da177e4SLinus Torvalds struct atm_dev *dev; 36741da177e4SLinus Torvalds ushort revision = 0; 36751da177e4SLinus Torvalds int i, err; 36761da177e4SLinus Torvalds 36771da177e4SLinus Torvalds 36781da177e4SLinus Torvalds if ((err = pci_enable_device(pcidev))) { 36791da177e4SLinus Torvalds printk("idt77252: can't enable PCI device at %s\n", pci_name(pcidev)); 36801da177e4SLinus Torvalds return err; 36811da177e4SLinus Torvalds } 36821da177e4SLinus Torvalds 36831da177e4SLinus Torvalds if (pci_read_config_word(pcidev, PCI_REVISION_ID, &revision)) { 36841da177e4SLinus Torvalds printk("idt77252-%d: can't read PCI_REVISION_ID\n", index); 36851da177e4SLinus Torvalds err = -ENODEV; 36861da177e4SLinus Torvalds goto err_out_disable_pdev; 36871da177e4SLinus Torvalds } 36881da177e4SLinus Torvalds 3689*0c1cca1dSOm Narasimhan card = kzalloc(sizeof(struct idt77252_dev), GFP_KERNEL); 36901da177e4SLinus Torvalds if (!card) { 36911da177e4SLinus Torvalds printk("idt77252-%d: can't allocate private data\n", index); 36921da177e4SLinus Torvalds err = -ENOMEM; 36931da177e4SLinus Torvalds goto err_out_disable_pdev; 36941da177e4SLinus Torvalds } 36951da177e4SLinus Torvalds card->revision = revision; 36961da177e4SLinus Torvalds card->index = index; 36971da177e4SLinus Torvalds card->pcidev = pcidev; 36981da177e4SLinus Torvalds sprintf(card->name, "idt77252-%d", card->index); 36991da177e4SLinus Torvalds 37001da177e4SLinus Torvalds INIT_WORK(&card->tqueue, idt77252_softint, (void *)card); 37011da177e4SLinus Torvalds 37021da177e4SLinus Torvalds membase = pci_resource_start(pcidev, 1); 37031da177e4SLinus Torvalds srambase = pci_resource_start(pcidev, 2); 37041da177e4SLinus Torvalds 37051da177e4SLinus Torvalds init_MUTEX(&card->mutex); 37061da177e4SLinus Torvalds spin_lock_init(&card->cmd_lock); 37071da177e4SLinus Torvalds spin_lock_init(&card->tst_lock); 37081da177e4SLinus Torvalds 37091da177e4SLinus Torvalds init_timer(&card->tst_timer); 37101da177e4SLinus Torvalds card->tst_timer.data = (unsigned long)card; 37111da177e4SLinus Torvalds card->tst_timer.function = tst_timer; 37121da177e4SLinus Torvalds 37131da177e4SLinus Torvalds /* Do the I/O remapping... */ 37141da177e4SLinus Torvalds card->membase = ioremap(membase, 1024); 37151da177e4SLinus Torvalds if (!card->membase) { 37161da177e4SLinus Torvalds printk("%s: can't ioremap() membase\n", card->name); 37171da177e4SLinus Torvalds err = -EIO; 37181da177e4SLinus Torvalds goto err_out_free_card; 37191da177e4SLinus Torvalds } 37201da177e4SLinus Torvalds 37211da177e4SLinus Torvalds if (idt77252_preset(card)) { 37221da177e4SLinus Torvalds printk("%s: preset failed\n", card->name); 37231da177e4SLinus Torvalds err = -EIO; 37241da177e4SLinus Torvalds goto err_out_iounmap; 37251da177e4SLinus Torvalds } 37261da177e4SLinus Torvalds 37271da177e4SLinus Torvalds dev = atm_dev_register("idt77252", &idt77252_ops, -1, NULL); 37281da177e4SLinus Torvalds if (!dev) { 37291da177e4SLinus Torvalds printk("%s: can't register atm device\n", card->name); 37301da177e4SLinus Torvalds err = -EIO; 37311da177e4SLinus Torvalds goto err_out_iounmap; 37321da177e4SLinus Torvalds } 37331da177e4SLinus Torvalds dev->dev_data = card; 37341da177e4SLinus Torvalds card->atmdev = dev; 37351da177e4SLinus Torvalds 37361da177e4SLinus Torvalds #ifdef CONFIG_ATM_IDT77252_USE_SUNI 37371da177e4SLinus Torvalds suni_init(dev); 37381da177e4SLinus Torvalds if (!dev->phy) { 37391da177e4SLinus Torvalds printk("%s: can't init SUNI\n", card->name); 37401da177e4SLinus Torvalds err = -EIO; 37411da177e4SLinus Torvalds goto err_out_deinit_card; 37421da177e4SLinus Torvalds } 37431da177e4SLinus Torvalds #endif /* CONFIG_ATM_IDT77252_USE_SUNI */ 37441da177e4SLinus Torvalds 37451da177e4SLinus Torvalds card->sramsize = probe_sram(card); 37461da177e4SLinus Torvalds 37471da177e4SLinus Torvalds for (i = 0; i < 4; i++) { 37481da177e4SLinus Torvalds card->fbq[i] = ioremap(srambase | 0x200000 | (i << 18), 4); 37491da177e4SLinus Torvalds if (!card->fbq[i]) { 37501da177e4SLinus Torvalds printk("%s: can't ioremap() FBQ%d\n", card->name, i); 37511da177e4SLinus Torvalds err = -EIO; 37521da177e4SLinus Torvalds goto err_out_deinit_card; 37531da177e4SLinus Torvalds } 37541da177e4SLinus Torvalds } 37551da177e4SLinus Torvalds 37561da177e4SLinus Torvalds printk("%s: ABR SAR (Rev %c): MEM %08lx SRAM %08lx [%u KB]\n", 37571da177e4SLinus Torvalds card->name, ((revision > 1) && (revision < 25)) ? 37581da177e4SLinus Torvalds 'A' + revision - 1 : '?', membase, srambase, 37591da177e4SLinus Torvalds card->sramsize / 1024); 37601da177e4SLinus Torvalds 37611da177e4SLinus Torvalds if (init_card(dev)) { 37621da177e4SLinus Torvalds printk("%s: init_card failed\n", card->name); 37631da177e4SLinus Torvalds err = -EIO; 37641da177e4SLinus Torvalds goto err_out_deinit_card; 37651da177e4SLinus Torvalds } 37661da177e4SLinus Torvalds 37671da177e4SLinus Torvalds dev->ci_range.vpi_bits = card->vpibits; 37681da177e4SLinus Torvalds dev->ci_range.vci_bits = card->vcibits; 37691da177e4SLinus Torvalds dev->link_rate = card->link_pcr; 37701da177e4SLinus Torvalds 37711da177e4SLinus Torvalds if (dev->phy->start) 37721da177e4SLinus Torvalds dev->phy->start(dev); 37731da177e4SLinus Torvalds 37741da177e4SLinus Torvalds if (idt77252_dev_open(card)) { 37751da177e4SLinus Torvalds printk("%s: dev_open failed\n", card->name); 37761da177e4SLinus Torvalds err = -EIO; 37771da177e4SLinus Torvalds goto err_out_stop; 37781da177e4SLinus Torvalds } 37791da177e4SLinus Torvalds 37801da177e4SLinus Torvalds *last = card; 37811da177e4SLinus Torvalds last = &card->next; 37821da177e4SLinus Torvalds index++; 37831da177e4SLinus Torvalds 37841da177e4SLinus Torvalds return 0; 37851da177e4SLinus Torvalds 37861da177e4SLinus Torvalds err_out_stop: 37871da177e4SLinus Torvalds if (dev->phy->stop) 37881da177e4SLinus Torvalds dev->phy->stop(dev); 37891da177e4SLinus Torvalds 37901da177e4SLinus Torvalds err_out_deinit_card: 37911da177e4SLinus Torvalds deinit_card(card); 37921da177e4SLinus Torvalds 37931da177e4SLinus Torvalds err_out_iounmap: 37941da177e4SLinus Torvalds iounmap(card->membase); 37951da177e4SLinus Torvalds 37961da177e4SLinus Torvalds err_out_free_card: 37971da177e4SLinus Torvalds kfree(card); 37981da177e4SLinus Torvalds 37991da177e4SLinus Torvalds err_out_disable_pdev: 38001da177e4SLinus Torvalds pci_disable_device(pcidev); 38011da177e4SLinus Torvalds return err; 38021da177e4SLinus Torvalds } 38031da177e4SLinus Torvalds 38041da177e4SLinus Torvalds static struct pci_device_id idt77252_pci_tbl[] = 38051da177e4SLinus Torvalds { 38061da177e4SLinus Torvalds { PCI_VENDOR_ID_IDT, PCI_DEVICE_ID_IDT_IDT77252, 38071da177e4SLinus Torvalds PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, 38081da177e4SLinus Torvalds { 0, } 38091da177e4SLinus Torvalds }; 38101da177e4SLinus Torvalds 38111da177e4SLinus Torvalds MODULE_DEVICE_TABLE(pci, idt77252_pci_tbl); 38121da177e4SLinus Torvalds 38131da177e4SLinus Torvalds static struct pci_driver idt77252_driver = { 38141da177e4SLinus Torvalds .name = "idt77252", 38151da177e4SLinus Torvalds .id_table = idt77252_pci_tbl, 38161da177e4SLinus Torvalds .probe = idt77252_init_one, 38171da177e4SLinus Torvalds }; 38181da177e4SLinus Torvalds 38191da177e4SLinus Torvalds static int __init idt77252_init(void) 38201da177e4SLinus Torvalds { 38211da177e4SLinus Torvalds struct sk_buff *skb; 38221da177e4SLinus Torvalds 38231da177e4SLinus Torvalds printk("%s: at %p\n", __FUNCTION__, idt77252_init); 38241da177e4SLinus Torvalds 38251da177e4SLinus Torvalds if (sizeof(skb->cb) < sizeof(struct atm_skb_data) + 38261da177e4SLinus Torvalds sizeof(struct idt77252_skb_prv)) { 38271da177e4SLinus Torvalds printk(KERN_ERR "%s: skb->cb is too small (%lu < %lu)\n", 38281da177e4SLinus Torvalds __FUNCTION__, (unsigned long) sizeof(skb->cb), 38291da177e4SLinus Torvalds (unsigned long) sizeof(struct atm_skb_data) + 38301da177e4SLinus Torvalds sizeof(struct idt77252_skb_prv)); 38311da177e4SLinus Torvalds return -EIO; 38321da177e4SLinus Torvalds } 38331da177e4SLinus Torvalds 38341da177e4SLinus Torvalds return pci_register_driver(&idt77252_driver); 38351da177e4SLinus Torvalds } 38361da177e4SLinus Torvalds 38371da177e4SLinus Torvalds static void __exit idt77252_exit(void) 38381da177e4SLinus Torvalds { 38391da177e4SLinus Torvalds struct idt77252_dev *card; 38401da177e4SLinus Torvalds struct atm_dev *dev; 38411da177e4SLinus Torvalds 38421da177e4SLinus Torvalds pci_unregister_driver(&idt77252_driver); 38431da177e4SLinus Torvalds 38441da177e4SLinus Torvalds while (idt77252_chain) { 38451da177e4SLinus Torvalds card = idt77252_chain; 38461da177e4SLinus Torvalds dev = card->atmdev; 38471da177e4SLinus Torvalds idt77252_chain = card->next; 38481da177e4SLinus Torvalds 38491da177e4SLinus Torvalds if (dev->phy->stop) 38501da177e4SLinus Torvalds dev->phy->stop(dev); 38511da177e4SLinus Torvalds deinit_card(card); 38521da177e4SLinus Torvalds pci_disable_device(card->pcidev); 38531da177e4SLinus Torvalds kfree(card); 38541da177e4SLinus Torvalds } 38551da177e4SLinus Torvalds 38561da177e4SLinus Torvalds DIPRINTK("idt77252: finished cleanup-module().\n"); 38571da177e4SLinus Torvalds } 38581da177e4SLinus Torvalds 38591da177e4SLinus Torvalds module_init(idt77252_init); 38601da177e4SLinus Torvalds module_exit(idt77252_exit); 38611da177e4SLinus Torvalds 38621da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 38631da177e4SLinus Torvalds 38641da177e4SLinus Torvalds module_param(vpibits, uint, 0); 38651da177e4SLinus Torvalds MODULE_PARM_DESC(vpibits, "number of VPI bits supported (0, 1, or 2)"); 38661da177e4SLinus Torvalds #ifdef CONFIG_ATM_IDT77252_DEBUG 38671da177e4SLinus Torvalds module_param(debug, ulong, 0644); 38681da177e4SLinus Torvalds MODULE_PARM_DESC(debug, "debug bitmap, see drivers/atm/idt77252.h"); 38691da177e4SLinus Torvalds #endif 38701da177e4SLinus Torvalds 38711da177e4SLinus Torvalds MODULE_AUTHOR("Eddie C. Dost <ecd@atecom.com>"); 38721da177e4SLinus Torvalds MODULE_DESCRIPTION("IDT77252 ABR SAR Driver"); 3873