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