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> 481da177e4SLinus Torvalds #include <asm/uaccess.h> 491da177e4SLinus Torvalds #include <asm/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; 6441da177e4SLinus Torvalds scq->base = pci_alloc_consistent(card->pcidev, SCQ_SIZE, 6451da177e4SLinus Torvalds &scq->paddr); 6461da177e4SLinus Torvalds if (scq->base == NULL) { 6471da177e4SLinus Torvalds kfree(scq); 6481da177e4SLinus Torvalds return NULL; 6491da177e4SLinus Torvalds } 6501da177e4SLinus Torvalds memset(scq->base, 0, SCQ_SIZE); 6511da177e4SLinus Torvalds 6521da177e4SLinus Torvalds scq->next = scq->base; 6531da177e4SLinus Torvalds scq->last = scq->base + (SCQ_ENTRIES - 1); 6541da177e4SLinus Torvalds atomic_set(&scq->used, 0); 6551da177e4SLinus Torvalds 6561da177e4SLinus Torvalds spin_lock_init(&scq->lock); 6571da177e4SLinus Torvalds spin_lock_init(&scq->skblock); 6581da177e4SLinus Torvalds 6591da177e4SLinus Torvalds skb_queue_head_init(&scq->transmit); 6601da177e4SLinus Torvalds skb_queue_head_init(&scq->pending); 6611da177e4SLinus Torvalds 6621da177e4SLinus Torvalds TXPRINTK("idt77252: SCQ: base 0x%p, next 0x%p, last 0x%p, paddr %08llx\n", 6631da177e4SLinus Torvalds scq->base, scq->next, scq->last, (unsigned long long)scq->paddr); 6641da177e4SLinus Torvalds 6651da177e4SLinus Torvalds return scq; 6661da177e4SLinus Torvalds } 6671da177e4SLinus Torvalds 6681da177e4SLinus Torvalds static void 6691da177e4SLinus Torvalds free_scq(struct idt77252_dev *card, struct scq_info *scq) 6701da177e4SLinus Torvalds { 6711da177e4SLinus Torvalds struct sk_buff *skb; 6721da177e4SLinus Torvalds struct atm_vcc *vcc; 6731da177e4SLinus Torvalds 6741da177e4SLinus Torvalds pci_free_consistent(card->pcidev, SCQ_SIZE, 6751da177e4SLinus Torvalds scq->base, scq->paddr); 6761da177e4SLinus Torvalds 6771da177e4SLinus Torvalds while ((skb = skb_dequeue(&scq->transmit))) { 6781da177e4SLinus Torvalds pci_unmap_single(card->pcidev, IDT77252_PRV_PADDR(skb), 6791da177e4SLinus Torvalds skb->len, PCI_DMA_TODEVICE); 6801da177e4SLinus Torvalds 6811da177e4SLinus Torvalds vcc = ATM_SKB(skb)->vcc; 6821da177e4SLinus Torvalds if (vcc->pop) 6831da177e4SLinus Torvalds vcc->pop(vcc, skb); 6841da177e4SLinus Torvalds else 6851da177e4SLinus Torvalds dev_kfree_skb(skb); 6861da177e4SLinus Torvalds } 6871da177e4SLinus Torvalds 6881da177e4SLinus Torvalds while ((skb = skb_dequeue(&scq->pending))) { 6891da177e4SLinus Torvalds pci_unmap_single(card->pcidev, IDT77252_PRV_PADDR(skb), 6901da177e4SLinus Torvalds skb->len, PCI_DMA_TODEVICE); 6911da177e4SLinus Torvalds 6921da177e4SLinus Torvalds vcc = ATM_SKB(skb)->vcc; 6931da177e4SLinus Torvalds if (vcc->pop) 6941da177e4SLinus Torvalds vcc->pop(vcc, skb); 6951da177e4SLinus Torvalds else 6961da177e4SLinus Torvalds dev_kfree_skb(skb); 6971da177e4SLinus Torvalds } 6981da177e4SLinus Torvalds 6991da177e4SLinus Torvalds kfree(scq); 7001da177e4SLinus Torvalds } 7011da177e4SLinus Torvalds 7021da177e4SLinus Torvalds 7031da177e4SLinus Torvalds static int 7041da177e4SLinus Torvalds push_on_scq(struct idt77252_dev *card, struct vc_map *vc, struct sk_buff *skb) 7051da177e4SLinus Torvalds { 7061da177e4SLinus Torvalds struct scq_info *scq = vc->scq; 7071da177e4SLinus Torvalds unsigned long flags; 7081da177e4SLinus Torvalds struct scqe *tbd; 7091da177e4SLinus Torvalds int entries; 7101da177e4SLinus Torvalds 7111da177e4SLinus Torvalds TXPRINTK("%s: SCQ: next 0x%p\n", card->name, scq->next); 7121da177e4SLinus Torvalds 7131da177e4SLinus Torvalds atomic_inc(&scq->used); 7141da177e4SLinus Torvalds entries = atomic_read(&scq->used); 7151da177e4SLinus Torvalds if (entries > (SCQ_ENTRIES - 1)) { 7161da177e4SLinus Torvalds atomic_dec(&scq->used); 7171da177e4SLinus Torvalds goto out; 7181da177e4SLinus Torvalds } 7191da177e4SLinus Torvalds 7201da177e4SLinus Torvalds skb_queue_tail(&scq->transmit, skb); 7211da177e4SLinus Torvalds 7221da177e4SLinus Torvalds spin_lock_irqsave(&vc->lock, flags); 7231da177e4SLinus Torvalds if (vc->estimator) { 7241da177e4SLinus Torvalds struct atm_vcc *vcc = vc->tx_vcc; 7251da177e4SLinus Torvalds struct sock *sk = sk_atm(vcc); 7261da177e4SLinus Torvalds 7271da177e4SLinus Torvalds vc->estimator->cells += (skb->len + 47) / 48; 7281da177e4SLinus Torvalds if (atomic_read(&sk->sk_wmem_alloc) > 7291da177e4SLinus Torvalds (sk->sk_sndbuf >> 1)) { 7301da177e4SLinus Torvalds u32 cps = vc->estimator->maxcps; 7311da177e4SLinus Torvalds 7321da177e4SLinus Torvalds vc->estimator->cps = cps; 7331da177e4SLinus Torvalds vc->estimator->avcps = cps << 5; 7341da177e4SLinus Torvalds if (vc->lacr < vc->init_er) { 7351da177e4SLinus Torvalds vc->lacr = vc->init_er; 7361da177e4SLinus Torvalds writel(TCMDQ_LACR | (vc->lacr << 16) | 7371da177e4SLinus Torvalds vc->index, SAR_REG_TCMDQ); 7381da177e4SLinus Torvalds } 7391da177e4SLinus Torvalds } 7401da177e4SLinus Torvalds } 7411da177e4SLinus Torvalds spin_unlock_irqrestore(&vc->lock, flags); 7421da177e4SLinus Torvalds 7431da177e4SLinus Torvalds tbd = &IDT77252_PRV_TBD(skb); 7441da177e4SLinus Torvalds 7451da177e4SLinus Torvalds spin_lock_irqsave(&scq->lock, flags); 7461da177e4SLinus Torvalds scq->next->word_1 = cpu_to_le32(tbd->word_1 | 7471da177e4SLinus Torvalds SAR_TBD_TSIF | SAR_TBD_GTSI); 7481da177e4SLinus Torvalds scq->next->word_2 = cpu_to_le32(tbd->word_2); 7491da177e4SLinus Torvalds scq->next->word_3 = cpu_to_le32(tbd->word_3); 7501da177e4SLinus Torvalds scq->next->word_4 = cpu_to_le32(tbd->word_4); 7511da177e4SLinus Torvalds 7521da177e4SLinus Torvalds if (scq->next == scq->last) 7531da177e4SLinus Torvalds scq->next = scq->base; 7541da177e4SLinus Torvalds else 7551da177e4SLinus Torvalds scq->next++; 7561da177e4SLinus Torvalds 7571da177e4SLinus Torvalds write_sram(card, scq->scd, 7581da177e4SLinus Torvalds scq->paddr + 7591da177e4SLinus Torvalds (u32)((unsigned long)scq->next - (unsigned long)scq->base)); 7601da177e4SLinus Torvalds spin_unlock_irqrestore(&scq->lock, flags); 7611da177e4SLinus Torvalds 7621da177e4SLinus Torvalds scq->trans_start = jiffies; 7631da177e4SLinus Torvalds 7641da177e4SLinus Torvalds if (test_and_clear_bit(VCF_IDLE, &vc->flags)) { 7651da177e4SLinus Torvalds writel(TCMDQ_START_LACR | (vc->lacr << 16) | vc->index, 7661da177e4SLinus Torvalds SAR_REG_TCMDQ); 7671da177e4SLinus Torvalds } 7681da177e4SLinus Torvalds 7691da177e4SLinus Torvalds TXPRINTK("%d entries in SCQ used (push).\n", atomic_read(&scq->used)); 7701da177e4SLinus Torvalds 7711da177e4SLinus Torvalds XPRINTK("%s: SCQ (after push %2d) head = 0x%x, next = 0x%p.\n", 7721da177e4SLinus Torvalds card->name, atomic_read(&scq->used), 7731da177e4SLinus Torvalds read_sram(card, scq->scd + 1), scq->next); 7741da177e4SLinus Torvalds 7751da177e4SLinus Torvalds return 0; 7761da177e4SLinus Torvalds 7771da177e4SLinus Torvalds out: 778e1bd232bSMarcelo Feitoza Parisi if (time_after(jiffies, scq->trans_start + HZ)) { 7791da177e4SLinus Torvalds printk("%s: Error pushing TBD for %d.%d\n", 7801da177e4SLinus Torvalds card->name, vc->tx_vcc->vpi, vc->tx_vcc->vci); 7811da177e4SLinus Torvalds #ifdef CONFIG_ATM_IDT77252_DEBUG 7821da177e4SLinus Torvalds idt77252_tx_dump(card); 7831da177e4SLinus Torvalds #endif 7841da177e4SLinus Torvalds scq->trans_start = jiffies; 7851da177e4SLinus Torvalds } 7861da177e4SLinus Torvalds 7871da177e4SLinus Torvalds return -ENOBUFS; 7881da177e4SLinus Torvalds } 7891da177e4SLinus Torvalds 7901da177e4SLinus Torvalds 7911da177e4SLinus Torvalds static void 7921da177e4SLinus Torvalds drain_scq(struct idt77252_dev *card, struct vc_map *vc) 7931da177e4SLinus Torvalds { 7941da177e4SLinus Torvalds struct scq_info *scq = vc->scq; 7951da177e4SLinus Torvalds struct sk_buff *skb; 7961da177e4SLinus Torvalds struct atm_vcc *vcc; 7971da177e4SLinus Torvalds 7981da177e4SLinus Torvalds TXPRINTK("%s: SCQ (before drain %2d) next = 0x%p.\n", 7991da177e4SLinus Torvalds card->name, atomic_read(&scq->used), scq->next); 8001da177e4SLinus Torvalds 8011da177e4SLinus Torvalds skb = skb_dequeue(&scq->transmit); 8021da177e4SLinus Torvalds if (skb) { 8031da177e4SLinus Torvalds TXPRINTK("%s: freeing skb at %p.\n", card->name, skb); 8041da177e4SLinus Torvalds 8051da177e4SLinus Torvalds pci_unmap_single(card->pcidev, IDT77252_PRV_PADDR(skb), 8061da177e4SLinus Torvalds skb->len, PCI_DMA_TODEVICE); 8071da177e4SLinus Torvalds 8081da177e4SLinus Torvalds vcc = ATM_SKB(skb)->vcc; 8091da177e4SLinus Torvalds 8101da177e4SLinus Torvalds if (vcc->pop) 8111da177e4SLinus Torvalds vcc->pop(vcc, skb); 8121da177e4SLinus Torvalds else 8131da177e4SLinus Torvalds dev_kfree_skb(skb); 8141da177e4SLinus Torvalds 8151da177e4SLinus Torvalds atomic_inc(&vcc->stats->tx); 8161da177e4SLinus Torvalds } 8171da177e4SLinus Torvalds 8181da177e4SLinus Torvalds atomic_dec(&scq->used); 8191da177e4SLinus Torvalds 8201da177e4SLinus Torvalds spin_lock(&scq->skblock); 8211da177e4SLinus Torvalds while ((skb = skb_dequeue(&scq->pending))) { 8221da177e4SLinus Torvalds if (push_on_scq(card, vc, skb)) { 8231da177e4SLinus Torvalds skb_queue_head(&vc->scq->pending, skb); 8241da177e4SLinus Torvalds break; 8251da177e4SLinus Torvalds } 8261da177e4SLinus Torvalds } 8271da177e4SLinus Torvalds spin_unlock(&scq->skblock); 8281da177e4SLinus Torvalds } 8291da177e4SLinus Torvalds 8301da177e4SLinus Torvalds static int 8311da177e4SLinus Torvalds queue_skb(struct idt77252_dev *card, struct vc_map *vc, 8321da177e4SLinus Torvalds struct sk_buff *skb, int oam) 8331da177e4SLinus Torvalds { 8341da177e4SLinus Torvalds struct atm_vcc *vcc; 8351da177e4SLinus Torvalds struct scqe *tbd; 8361da177e4SLinus Torvalds unsigned long flags; 8371da177e4SLinus Torvalds int error; 8381da177e4SLinus Torvalds int aal; 8391da177e4SLinus Torvalds 8401da177e4SLinus Torvalds if (skb->len == 0) { 8411da177e4SLinus Torvalds printk("%s: invalid skb->len (%d)\n", card->name, skb->len); 8421da177e4SLinus Torvalds return -EINVAL; 8431da177e4SLinus Torvalds } 8441da177e4SLinus Torvalds 8451da177e4SLinus Torvalds TXPRINTK("%s: Sending %d bytes of data.\n", 8461da177e4SLinus Torvalds card->name, skb->len); 8471da177e4SLinus Torvalds 8481da177e4SLinus Torvalds tbd = &IDT77252_PRV_TBD(skb); 8491da177e4SLinus Torvalds vcc = ATM_SKB(skb)->vcc; 8501da177e4SLinus Torvalds 8511da177e4SLinus Torvalds IDT77252_PRV_PADDR(skb) = pci_map_single(card->pcidev, skb->data, 8521da177e4SLinus Torvalds skb->len, PCI_DMA_TODEVICE); 8531da177e4SLinus Torvalds 8541da177e4SLinus Torvalds error = -EINVAL; 8551da177e4SLinus Torvalds 8561da177e4SLinus Torvalds if (oam) { 8571da177e4SLinus Torvalds if (skb->len != 52) 8581da177e4SLinus Torvalds goto errout; 8591da177e4SLinus Torvalds 8601da177e4SLinus Torvalds tbd->word_1 = SAR_TBD_OAM | ATM_CELL_PAYLOAD | SAR_TBD_EPDU; 8611da177e4SLinus Torvalds tbd->word_2 = IDT77252_PRV_PADDR(skb) + 4; 8621da177e4SLinus Torvalds tbd->word_3 = 0x00000000; 8631da177e4SLinus Torvalds tbd->word_4 = (skb->data[0] << 24) | (skb->data[1] << 16) | 8641da177e4SLinus Torvalds (skb->data[2] << 8) | (skb->data[3] << 0); 8651da177e4SLinus Torvalds 8661da177e4SLinus Torvalds if (test_bit(VCF_RSV, &vc->flags)) 8671da177e4SLinus Torvalds vc = card->vcs[0]; 8681da177e4SLinus Torvalds 8691da177e4SLinus Torvalds goto done; 8701da177e4SLinus Torvalds } 8711da177e4SLinus Torvalds 8721da177e4SLinus Torvalds if (test_bit(VCF_RSV, &vc->flags)) { 8731da177e4SLinus Torvalds printk("%s: Trying to transmit on reserved VC\n", card->name); 8741da177e4SLinus Torvalds goto errout; 8751da177e4SLinus Torvalds } 8761da177e4SLinus Torvalds 8771da177e4SLinus Torvalds aal = vcc->qos.aal; 8781da177e4SLinus Torvalds 8791da177e4SLinus Torvalds switch (aal) { 8801da177e4SLinus Torvalds case ATM_AAL0: 8811da177e4SLinus Torvalds case ATM_AAL34: 8821da177e4SLinus Torvalds if (skb->len > 52) 8831da177e4SLinus Torvalds goto errout; 8841da177e4SLinus Torvalds 8851da177e4SLinus Torvalds if (aal == ATM_AAL0) 8861da177e4SLinus Torvalds tbd->word_1 = SAR_TBD_EPDU | SAR_TBD_AAL0 | 8871da177e4SLinus Torvalds ATM_CELL_PAYLOAD; 8881da177e4SLinus Torvalds else 8891da177e4SLinus Torvalds tbd->word_1 = SAR_TBD_EPDU | SAR_TBD_AAL34 | 8901da177e4SLinus Torvalds ATM_CELL_PAYLOAD; 8911da177e4SLinus Torvalds 8921da177e4SLinus Torvalds tbd->word_2 = IDT77252_PRV_PADDR(skb) + 4; 8931da177e4SLinus Torvalds tbd->word_3 = 0x00000000; 8941da177e4SLinus Torvalds tbd->word_4 = (skb->data[0] << 24) | (skb->data[1] << 16) | 8951da177e4SLinus Torvalds (skb->data[2] << 8) | (skb->data[3] << 0); 8961da177e4SLinus Torvalds break; 8971da177e4SLinus Torvalds 8981da177e4SLinus Torvalds case ATM_AAL5: 8991da177e4SLinus Torvalds tbd->word_1 = SAR_TBD_EPDU | SAR_TBD_AAL5 | skb->len; 9001da177e4SLinus Torvalds tbd->word_2 = IDT77252_PRV_PADDR(skb); 9011da177e4SLinus Torvalds tbd->word_3 = skb->len; 9021da177e4SLinus Torvalds tbd->word_4 = (vcc->vpi << SAR_TBD_VPI_SHIFT) | 9031da177e4SLinus Torvalds (vcc->vci << SAR_TBD_VCI_SHIFT); 9041da177e4SLinus Torvalds break; 9051da177e4SLinus Torvalds 9061da177e4SLinus Torvalds case ATM_AAL1: 9071da177e4SLinus Torvalds case ATM_AAL2: 9081da177e4SLinus Torvalds default: 9091da177e4SLinus Torvalds printk("%s: Traffic type not supported.\n", card->name); 9101da177e4SLinus Torvalds error = -EPROTONOSUPPORT; 9111da177e4SLinus Torvalds goto errout; 9121da177e4SLinus Torvalds } 9131da177e4SLinus Torvalds 9141da177e4SLinus Torvalds done: 9151da177e4SLinus Torvalds spin_lock_irqsave(&vc->scq->skblock, flags); 9161da177e4SLinus Torvalds skb_queue_tail(&vc->scq->pending, skb); 9171da177e4SLinus Torvalds 9181da177e4SLinus Torvalds while ((skb = skb_dequeue(&vc->scq->pending))) { 9191da177e4SLinus Torvalds if (push_on_scq(card, vc, skb)) { 9201da177e4SLinus Torvalds skb_queue_head(&vc->scq->pending, skb); 9211da177e4SLinus Torvalds break; 9221da177e4SLinus Torvalds } 9231da177e4SLinus Torvalds } 9241da177e4SLinus Torvalds spin_unlock_irqrestore(&vc->scq->skblock, flags); 9251da177e4SLinus Torvalds 9261da177e4SLinus Torvalds return 0; 9271da177e4SLinus Torvalds 9281da177e4SLinus Torvalds errout: 9291da177e4SLinus Torvalds pci_unmap_single(card->pcidev, IDT77252_PRV_PADDR(skb), 9301da177e4SLinus Torvalds skb->len, PCI_DMA_TODEVICE); 9311da177e4SLinus Torvalds return error; 9321da177e4SLinus Torvalds } 9331da177e4SLinus Torvalds 9341da177e4SLinus Torvalds static unsigned long 9351da177e4SLinus Torvalds get_free_scd(struct idt77252_dev *card, struct vc_map *vc) 9361da177e4SLinus Torvalds { 9371da177e4SLinus Torvalds int i; 9381da177e4SLinus Torvalds 9391da177e4SLinus Torvalds for (i = 0; i < card->scd_size; i++) { 9401da177e4SLinus Torvalds if (!card->scd2vc[i]) { 9411da177e4SLinus Torvalds card->scd2vc[i] = vc; 9421da177e4SLinus Torvalds vc->scd_index = i; 9431da177e4SLinus Torvalds return card->scd_base + i * SAR_SRAM_SCD_SIZE; 9441da177e4SLinus Torvalds } 9451da177e4SLinus Torvalds } 9461da177e4SLinus Torvalds return 0; 9471da177e4SLinus Torvalds } 9481da177e4SLinus Torvalds 9491da177e4SLinus Torvalds static void 9501da177e4SLinus Torvalds fill_scd(struct idt77252_dev *card, struct scq_info *scq, int class) 9511da177e4SLinus Torvalds { 9521da177e4SLinus Torvalds write_sram(card, scq->scd, scq->paddr); 9531da177e4SLinus Torvalds write_sram(card, scq->scd + 1, 0x00000000); 9541da177e4SLinus Torvalds write_sram(card, scq->scd + 2, 0xffffffff); 9551da177e4SLinus Torvalds write_sram(card, scq->scd + 3, 0x00000000); 9561da177e4SLinus Torvalds } 9571da177e4SLinus Torvalds 9581da177e4SLinus Torvalds static void 9591da177e4SLinus Torvalds clear_scd(struct idt77252_dev *card, struct scq_info *scq, int class) 9601da177e4SLinus Torvalds { 9611da177e4SLinus Torvalds return; 9621da177e4SLinus Torvalds } 9631da177e4SLinus Torvalds 9641da177e4SLinus Torvalds /*****************************************************************************/ 9651da177e4SLinus Torvalds /* */ 9661da177e4SLinus Torvalds /* RSQ Handling */ 9671da177e4SLinus Torvalds /* */ 9681da177e4SLinus Torvalds /*****************************************************************************/ 9691da177e4SLinus Torvalds 9701da177e4SLinus Torvalds static int 9711da177e4SLinus Torvalds init_rsq(struct idt77252_dev *card) 9721da177e4SLinus Torvalds { 9731da177e4SLinus Torvalds struct rsq_entry *rsqe; 9741da177e4SLinus Torvalds 9751da177e4SLinus Torvalds card->rsq.base = pci_alloc_consistent(card->pcidev, RSQSIZE, 9761da177e4SLinus Torvalds &card->rsq.paddr); 9771da177e4SLinus Torvalds if (card->rsq.base == NULL) { 9781da177e4SLinus Torvalds printk("%s: can't allocate RSQ.\n", card->name); 9791da177e4SLinus Torvalds return -1; 9801da177e4SLinus Torvalds } 9811da177e4SLinus Torvalds memset(card->rsq.base, 0, RSQSIZE); 9821da177e4SLinus Torvalds 9831da177e4SLinus Torvalds card->rsq.last = card->rsq.base + RSQ_NUM_ENTRIES - 1; 9841da177e4SLinus Torvalds card->rsq.next = card->rsq.last; 9851da177e4SLinus Torvalds for (rsqe = card->rsq.base; rsqe <= card->rsq.last; rsqe++) 9861da177e4SLinus Torvalds rsqe->word_4 = 0; 9871da177e4SLinus Torvalds 9881da177e4SLinus Torvalds writel((unsigned long) card->rsq.last - (unsigned long) card->rsq.base, 9891da177e4SLinus Torvalds SAR_REG_RSQH); 9901da177e4SLinus Torvalds writel(card->rsq.paddr, SAR_REG_RSQB); 9911da177e4SLinus Torvalds 9921da177e4SLinus Torvalds IPRINTK("%s: RSQ base at 0x%lx (0x%x).\n", card->name, 9931da177e4SLinus Torvalds (unsigned long) card->rsq.base, 9941da177e4SLinus Torvalds readl(SAR_REG_RSQB)); 9951da177e4SLinus Torvalds IPRINTK("%s: RSQ head = 0x%x, base = 0x%x, tail = 0x%x.\n", 9961da177e4SLinus Torvalds card->name, 9971da177e4SLinus Torvalds readl(SAR_REG_RSQH), 9981da177e4SLinus Torvalds readl(SAR_REG_RSQB), 9991da177e4SLinus Torvalds readl(SAR_REG_RSQT)); 10001da177e4SLinus Torvalds 10011da177e4SLinus Torvalds return 0; 10021da177e4SLinus Torvalds } 10031da177e4SLinus Torvalds 10041da177e4SLinus Torvalds static void 10051da177e4SLinus Torvalds deinit_rsq(struct idt77252_dev *card) 10061da177e4SLinus Torvalds { 10071da177e4SLinus Torvalds pci_free_consistent(card->pcidev, RSQSIZE, 10081da177e4SLinus Torvalds card->rsq.base, card->rsq.paddr); 10091da177e4SLinus Torvalds } 10101da177e4SLinus Torvalds 10111da177e4SLinus Torvalds static void 10121da177e4SLinus Torvalds dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe) 10131da177e4SLinus Torvalds { 10141da177e4SLinus Torvalds struct atm_vcc *vcc; 10151da177e4SLinus Torvalds struct sk_buff *skb; 10161da177e4SLinus Torvalds struct rx_pool *rpp; 10171da177e4SLinus Torvalds struct vc_map *vc; 10181da177e4SLinus Torvalds u32 header, vpi, vci; 10191da177e4SLinus Torvalds u32 stat; 10201da177e4SLinus Torvalds int i; 10211da177e4SLinus Torvalds 10221da177e4SLinus Torvalds stat = le32_to_cpu(rsqe->word_4); 10231da177e4SLinus Torvalds 10241da177e4SLinus Torvalds if (stat & SAR_RSQE_IDLE) { 10251da177e4SLinus Torvalds RXPRINTK("%s: message about inactive connection.\n", 10261da177e4SLinus Torvalds card->name); 10271da177e4SLinus Torvalds return; 10281da177e4SLinus Torvalds } 10291da177e4SLinus Torvalds 10301da177e4SLinus Torvalds skb = sb_pool_skb(card, le32_to_cpu(rsqe->word_2)); 10311da177e4SLinus Torvalds if (skb == NULL) { 10321da177e4SLinus Torvalds printk("%s: NULL skb in %s, rsqe: %08x %08x %08x %08x\n", 10335a346a10SHarvey Harrison card->name, __func__, 10341da177e4SLinus Torvalds le32_to_cpu(rsqe->word_1), le32_to_cpu(rsqe->word_2), 10351da177e4SLinus Torvalds le32_to_cpu(rsqe->word_3), le32_to_cpu(rsqe->word_4)); 10361da177e4SLinus Torvalds return; 10371da177e4SLinus Torvalds } 10381da177e4SLinus Torvalds 10391da177e4SLinus Torvalds header = le32_to_cpu(rsqe->word_1); 10401da177e4SLinus Torvalds vpi = (header >> 16) & 0x00ff; 10411da177e4SLinus Torvalds vci = (header >> 0) & 0xffff; 10421da177e4SLinus Torvalds 10431da177e4SLinus Torvalds RXPRINTK("%s: SDU for %d.%d received in buffer 0x%p (data 0x%p).\n", 10441da177e4SLinus Torvalds card->name, vpi, vci, skb, skb->data); 10451da177e4SLinus Torvalds 10461da177e4SLinus Torvalds if ((vpi >= (1 << card->vpibits)) || (vci != (vci & card->vcimask))) { 10471da177e4SLinus Torvalds printk("%s: SDU received for out-of-range vc %u.%u\n", 10481da177e4SLinus Torvalds card->name, vpi, vci); 10491da177e4SLinus Torvalds recycle_rx_skb(card, skb); 10501da177e4SLinus Torvalds return; 10511da177e4SLinus Torvalds } 10521da177e4SLinus Torvalds 10531da177e4SLinus Torvalds vc = card->vcs[VPCI2VC(card, vpi, vci)]; 10541da177e4SLinus Torvalds if (!vc || !test_bit(VCF_RX, &vc->flags)) { 10551da177e4SLinus Torvalds printk("%s: SDU received on non RX vc %u.%u\n", 10561da177e4SLinus Torvalds card->name, vpi, vci); 10571da177e4SLinus Torvalds recycle_rx_skb(card, skb); 10581da177e4SLinus Torvalds return; 10591da177e4SLinus Torvalds } 10601da177e4SLinus Torvalds 10611da177e4SLinus Torvalds vcc = vc->rx_vcc; 10621da177e4SLinus Torvalds 10631da177e4SLinus Torvalds pci_dma_sync_single_for_cpu(card->pcidev, IDT77252_PRV_PADDR(skb), 10644305b541SArnaldo Carvalho de Melo skb_end_pointer(skb) - skb->data, 10654305b541SArnaldo Carvalho de Melo PCI_DMA_FROMDEVICE); 10661da177e4SLinus Torvalds 10671da177e4SLinus Torvalds if ((vcc->qos.aal == ATM_AAL0) || 10681da177e4SLinus Torvalds (vcc->qos.aal == ATM_AAL34)) { 10691da177e4SLinus Torvalds struct sk_buff *sb; 10701da177e4SLinus Torvalds unsigned char *cell; 10711da177e4SLinus Torvalds u32 aal0; 10721da177e4SLinus Torvalds 10731da177e4SLinus Torvalds cell = skb->data; 10741da177e4SLinus Torvalds for (i = (stat & SAR_RSQE_CELLCNT); i; i--) { 10751da177e4SLinus Torvalds if ((sb = dev_alloc_skb(64)) == NULL) { 10761da177e4SLinus Torvalds printk("%s: Can't allocate buffers for aal0.\n", 10771da177e4SLinus Torvalds card->name); 10781da177e4SLinus Torvalds atomic_add(i, &vcc->stats->rx_drop); 10791da177e4SLinus Torvalds break; 10801da177e4SLinus Torvalds } 10811da177e4SLinus Torvalds if (!atm_charge(vcc, sb->truesize)) { 10821da177e4SLinus Torvalds RXPRINTK("%s: atm_charge() dropped aal0 packets.\n", 10831da177e4SLinus Torvalds card->name); 10841da177e4SLinus Torvalds atomic_add(i - 1, &vcc->stats->rx_drop); 10851da177e4SLinus Torvalds dev_kfree_skb(sb); 10861da177e4SLinus Torvalds break; 10871da177e4SLinus Torvalds } 10881da177e4SLinus Torvalds aal0 = (vpi << ATM_HDR_VPI_SHIFT) | 10891da177e4SLinus Torvalds (vci << ATM_HDR_VCI_SHIFT); 10901da177e4SLinus Torvalds aal0 |= (stat & SAR_RSQE_EPDU) ? 0x00000002 : 0; 10911da177e4SLinus Torvalds aal0 |= (stat & SAR_RSQE_CLP) ? 0x00000001 : 0; 10921da177e4SLinus Torvalds 10931da177e4SLinus Torvalds *((u32 *) sb->data) = aal0; 10941da177e4SLinus Torvalds skb_put(sb, sizeof(u32)); 10951da177e4SLinus Torvalds memcpy(skb_put(sb, ATM_CELL_PAYLOAD), 10961da177e4SLinus Torvalds cell, ATM_CELL_PAYLOAD); 10971da177e4SLinus Torvalds 10981da177e4SLinus Torvalds ATM_SKB(sb)->vcc = vcc; 1099a61bbcf2SPatrick McHardy __net_timestamp(sb); 11001da177e4SLinus Torvalds vcc->push(vcc, sb); 11011da177e4SLinus Torvalds atomic_inc(&vcc->stats->rx); 11021da177e4SLinus Torvalds 11031da177e4SLinus Torvalds cell += ATM_CELL_PAYLOAD; 11041da177e4SLinus Torvalds } 11051da177e4SLinus Torvalds 11061da177e4SLinus Torvalds recycle_rx_skb(card, skb); 11071da177e4SLinus Torvalds return; 11081da177e4SLinus Torvalds } 11091da177e4SLinus Torvalds if (vcc->qos.aal != ATM_AAL5) { 11101da177e4SLinus Torvalds printk("%s: Unexpected AAL type in dequeue_rx(): %d.\n", 11111da177e4SLinus Torvalds card->name, vcc->qos.aal); 11121da177e4SLinus Torvalds recycle_rx_skb(card, skb); 11131da177e4SLinus Torvalds return; 11141da177e4SLinus Torvalds } 11151da177e4SLinus Torvalds skb->len = (stat & SAR_RSQE_CELLCNT) * ATM_CELL_PAYLOAD; 11161da177e4SLinus Torvalds 11171da177e4SLinus Torvalds rpp = &vc->rcv.rx_pool; 11181da177e4SLinus Torvalds 1119ceade961SDavid S. Miller __skb_queue_tail(&rpp->queue, skb); 11201da177e4SLinus Torvalds rpp->len += skb->len; 11211da177e4SLinus Torvalds 11221da177e4SLinus Torvalds if (stat & SAR_RSQE_EPDU) { 11231da177e4SLinus Torvalds unsigned char *l1l2; 11241da177e4SLinus Torvalds unsigned int len; 11251da177e4SLinus Torvalds 11261da177e4SLinus Torvalds l1l2 = (unsigned char *) ((unsigned long) skb->data + skb->len - 6); 11271da177e4SLinus Torvalds 11281da177e4SLinus Torvalds len = (l1l2[0] << 8) | l1l2[1]; 11291da177e4SLinus Torvalds len = len ? len : 0x10000; 11301da177e4SLinus Torvalds 11311da177e4SLinus Torvalds RXPRINTK("%s: PDU has %d bytes.\n", card->name, len); 11321da177e4SLinus Torvalds 11331da177e4SLinus Torvalds if ((len + 8 > rpp->len) || (len + (47 + 8) < rpp->len)) { 11341da177e4SLinus Torvalds RXPRINTK("%s: AAL5 PDU size mismatch: %d != %d. " 11351da177e4SLinus Torvalds "(CDC: %08x)\n", 11361da177e4SLinus Torvalds card->name, len, rpp->len, readl(SAR_REG_CDC)); 11371da177e4SLinus Torvalds recycle_rx_pool_skb(card, rpp); 11381da177e4SLinus Torvalds atomic_inc(&vcc->stats->rx_err); 11391da177e4SLinus Torvalds return; 11401da177e4SLinus Torvalds } 11411da177e4SLinus Torvalds if (stat & SAR_RSQE_CRC) { 11421da177e4SLinus Torvalds RXPRINTK("%s: AAL5 CRC error.\n", card->name); 11431da177e4SLinus Torvalds recycle_rx_pool_skb(card, rpp); 11441da177e4SLinus Torvalds atomic_inc(&vcc->stats->rx_err); 11451da177e4SLinus Torvalds return; 11461da177e4SLinus Torvalds } 1147ceade961SDavid S. Miller if (skb_queue_len(&rpp->queue) > 1) { 11481da177e4SLinus Torvalds struct sk_buff *sb; 11491da177e4SLinus Torvalds 11501da177e4SLinus Torvalds skb = dev_alloc_skb(rpp->len); 11511da177e4SLinus Torvalds if (!skb) { 11521da177e4SLinus Torvalds RXPRINTK("%s: Can't alloc RX skb.\n", 11531da177e4SLinus Torvalds card->name); 11541da177e4SLinus Torvalds recycle_rx_pool_skb(card, rpp); 11551da177e4SLinus Torvalds atomic_inc(&vcc->stats->rx_err); 11561da177e4SLinus Torvalds return; 11571da177e4SLinus Torvalds } 11581da177e4SLinus Torvalds if (!atm_charge(vcc, skb->truesize)) { 11591da177e4SLinus Torvalds recycle_rx_pool_skb(card, rpp); 11601da177e4SLinus Torvalds dev_kfree_skb(skb); 11611da177e4SLinus Torvalds return; 11621da177e4SLinus Torvalds } 1163ceade961SDavid S. Miller skb_queue_walk(&rpp->queue, sb) 11641da177e4SLinus Torvalds memcpy(skb_put(skb, sb->len), 11651da177e4SLinus Torvalds sb->data, sb->len); 11661da177e4SLinus Torvalds 11671da177e4SLinus Torvalds recycle_rx_pool_skb(card, rpp); 11681da177e4SLinus Torvalds 11691da177e4SLinus Torvalds skb_trim(skb, len); 11701da177e4SLinus Torvalds ATM_SKB(skb)->vcc = vcc; 1171a61bbcf2SPatrick McHardy __net_timestamp(skb); 11721da177e4SLinus Torvalds 11731da177e4SLinus Torvalds vcc->push(vcc, skb); 11741da177e4SLinus Torvalds atomic_inc(&vcc->stats->rx); 11751da177e4SLinus Torvalds 11761da177e4SLinus Torvalds return; 11771da177e4SLinus Torvalds } 11781da177e4SLinus Torvalds 11791da177e4SLinus Torvalds flush_rx_pool(card, rpp); 11801da177e4SLinus Torvalds 11811da177e4SLinus Torvalds if (!atm_charge(vcc, skb->truesize)) { 11821da177e4SLinus Torvalds recycle_rx_skb(card, skb); 11831da177e4SLinus Torvalds return; 11841da177e4SLinus Torvalds } 11851da177e4SLinus Torvalds 11861da177e4SLinus Torvalds pci_unmap_single(card->pcidev, IDT77252_PRV_PADDR(skb), 11874305b541SArnaldo Carvalho de Melo skb_end_pointer(skb) - skb->data, 11884305b541SArnaldo Carvalho de Melo PCI_DMA_FROMDEVICE); 11891da177e4SLinus Torvalds sb_pool_remove(card, skb); 11901da177e4SLinus Torvalds 11911da177e4SLinus Torvalds skb_trim(skb, len); 11921da177e4SLinus Torvalds ATM_SKB(skb)->vcc = vcc; 1193a61bbcf2SPatrick McHardy __net_timestamp(skb); 11941da177e4SLinus Torvalds 11951da177e4SLinus Torvalds vcc->push(vcc, skb); 11961da177e4SLinus Torvalds atomic_inc(&vcc->stats->rx); 11971da177e4SLinus Torvalds 11981da177e4SLinus Torvalds if (skb->truesize > SAR_FB_SIZE_3) 11991da177e4SLinus Torvalds add_rx_skb(card, 3, SAR_FB_SIZE_3, 1); 12001da177e4SLinus Torvalds else if (skb->truesize > SAR_FB_SIZE_2) 12011da177e4SLinus Torvalds add_rx_skb(card, 2, SAR_FB_SIZE_2, 1); 12021da177e4SLinus Torvalds else if (skb->truesize > SAR_FB_SIZE_1) 12031da177e4SLinus Torvalds add_rx_skb(card, 1, SAR_FB_SIZE_1, 1); 12041da177e4SLinus Torvalds else 12051da177e4SLinus Torvalds add_rx_skb(card, 0, SAR_FB_SIZE_0, 1); 12061da177e4SLinus Torvalds return; 12071da177e4SLinus Torvalds } 12081da177e4SLinus Torvalds } 12091da177e4SLinus Torvalds 12101da177e4SLinus Torvalds static void 12111da177e4SLinus Torvalds idt77252_rx(struct idt77252_dev *card) 12121da177e4SLinus Torvalds { 12131da177e4SLinus Torvalds struct rsq_entry *rsqe; 12141da177e4SLinus Torvalds 12151da177e4SLinus Torvalds if (card->rsq.next == card->rsq.last) 12161da177e4SLinus Torvalds rsqe = card->rsq.base; 12171da177e4SLinus Torvalds else 12181da177e4SLinus Torvalds rsqe = card->rsq.next + 1; 12191da177e4SLinus Torvalds 12201da177e4SLinus Torvalds if (!(le32_to_cpu(rsqe->word_4) & SAR_RSQE_VALID)) { 12211da177e4SLinus Torvalds RXPRINTK("%s: no entry in RSQ.\n", card->name); 12221da177e4SLinus Torvalds return; 12231da177e4SLinus Torvalds } 12241da177e4SLinus Torvalds 12251da177e4SLinus Torvalds do { 12261da177e4SLinus Torvalds dequeue_rx(card, rsqe); 12271da177e4SLinus Torvalds rsqe->word_4 = 0; 12281da177e4SLinus Torvalds card->rsq.next = rsqe; 12291da177e4SLinus Torvalds if (card->rsq.next == card->rsq.last) 12301da177e4SLinus Torvalds rsqe = card->rsq.base; 12311da177e4SLinus Torvalds else 12321da177e4SLinus Torvalds rsqe = card->rsq.next + 1; 12331da177e4SLinus Torvalds } while (le32_to_cpu(rsqe->word_4) & SAR_RSQE_VALID); 12341da177e4SLinus Torvalds 12351da177e4SLinus Torvalds writel((unsigned long) card->rsq.next - (unsigned long) card->rsq.base, 12361da177e4SLinus Torvalds SAR_REG_RSQH); 12371da177e4SLinus Torvalds } 12381da177e4SLinus Torvalds 12391da177e4SLinus Torvalds static void 12401da177e4SLinus Torvalds idt77252_rx_raw(struct idt77252_dev *card) 12411da177e4SLinus Torvalds { 12421da177e4SLinus Torvalds struct sk_buff *queue; 12431da177e4SLinus Torvalds u32 head, tail; 12441da177e4SLinus Torvalds struct atm_vcc *vcc; 12451da177e4SLinus Torvalds struct vc_map *vc; 12461da177e4SLinus Torvalds struct sk_buff *sb; 12471da177e4SLinus Torvalds 12481da177e4SLinus Torvalds if (card->raw_cell_head == NULL) { 12491da177e4SLinus Torvalds u32 handle = le32_to_cpu(*(card->raw_cell_hnd + 1)); 12501da177e4SLinus Torvalds card->raw_cell_head = sb_pool_skb(card, handle); 12511da177e4SLinus Torvalds } 12521da177e4SLinus Torvalds 12531da177e4SLinus Torvalds queue = card->raw_cell_head; 12541da177e4SLinus Torvalds if (!queue) 12551da177e4SLinus Torvalds return; 12561da177e4SLinus Torvalds 12571da177e4SLinus Torvalds head = IDT77252_PRV_PADDR(queue) + (queue->data - queue->head - 16); 12581da177e4SLinus Torvalds tail = readl(SAR_REG_RAWCT); 12591da177e4SLinus Torvalds 12601da177e4SLinus Torvalds pci_dma_sync_single_for_cpu(card->pcidev, IDT77252_PRV_PADDR(queue), 12614305b541SArnaldo Carvalho de Melo skb_end_pointer(queue) - queue->head - 16, 12621da177e4SLinus Torvalds PCI_DMA_FROMDEVICE); 12631da177e4SLinus Torvalds 12641da177e4SLinus Torvalds while (head != tail) { 1265edb4dcb7SDavid S. Miller unsigned int vpi, vci; 12661da177e4SLinus Torvalds u32 header; 12671da177e4SLinus Torvalds 12681da177e4SLinus Torvalds header = le32_to_cpu(*(u32 *) &queue->data[0]); 12691da177e4SLinus Torvalds 12701da177e4SLinus Torvalds vpi = (header & ATM_HDR_VPI_MASK) >> ATM_HDR_VPI_SHIFT; 12711da177e4SLinus Torvalds vci = (header & ATM_HDR_VCI_MASK) >> ATM_HDR_VCI_SHIFT; 12721da177e4SLinus Torvalds 12731da177e4SLinus Torvalds #ifdef CONFIG_ATM_IDT77252_DEBUG 12741da177e4SLinus Torvalds if (debug & DBG_RAW_CELL) { 12751da177e4SLinus Torvalds int i; 12761da177e4SLinus Torvalds 12771da177e4SLinus Torvalds printk("%s: raw cell %x.%02x.%04x.%x.%x\n", 12781da177e4SLinus Torvalds card->name, (header >> 28) & 0x000f, 12791da177e4SLinus Torvalds (header >> 20) & 0x00ff, 12801da177e4SLinus Torvalds (header >> 4) & 0xffff, 12811da177e4SLinus Torvalds (header >> 1) & 0x0007, 12821da177e4SLinus Torvalds (header >> 0) & 0x0001); 12831da177e4SLinus Torvalds for (i = 16; i < 64; i++) 12841da177e4SLinus Torvalds printk(" %02x", queue->data[i]); 12851da177e4SLinus Torvalds printk("\n"); 12861da177e4SLinus Torvalds } 12871da177e4SLinus Torvalds #endif 12881da177e4SLinus Torvalds 12891da177e4SLinus Torvalds if (vpi >= (1<<card->vpibits) || vci >= (1<<card->vcibits)) { 12901da177e4SLinus Torvalds RPRINTK("%s: SDU received for out-of-range vc %u.%u\n", 12911da177e4SLinus Torvalds card->name, vpi, vci); 12921da177e4SLinus Torvalds goto drop; 12931da177e4SLinus Torvalds } 12941da177e4SLinus Torvalds 12951da177e4SLinus Torvalds vc = card->vcs[VPCI2VC(card, vpi, vci)]; 12961da177e4SLinus Torvalds if (!vc || !test_bit(VCF_RX, &vc->flags)) { 12971da177e4SLinus Torvalds RPRINTK("%s: SDU received on non RX vc %u.%u\n", 12981da177e4SLinus Torvalds card->name, vpi, vci); 12991da177e4SLinus Torvalds goto drop; 13001da177e4SLinus Torvalds } 13011da177e4SLinus Torvalds 13021da177e4SLinus Torvalds vcc = vc->rx_vcc; 13031da177e4SLinus Torvalds 13041da177e4SLinus Torvalds if (vcc->qos.aal != ATM_AAL0) { 13051da177e4SLinus Torvalds RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n", 13061da177e4SLinus Torvalds card->name, vpi, vci); 13071da177e4SLinus Torvalds atomic_inc(&vcc->stats->rx_drop); 13081da177e4SLinus Torvalds goto drop; 13091da177e4SLinus Torvalds } 13101da177e4SLinus Torvalds 13111da177e4SLinus Torvalds if ((sb = dev_alloc_skb(64)) == NULL) { 13121da177e4SLinus Torvalds printk("%s: Can't allocate buffers for AAL0.\n", 13131da177e4SLinus Torvalds card->name); 13141da177e4SLinus Torvalds atomic_inc(&vcc->stats->rx_err); 13151da177e4SLinus Torvalds goto drop; 13161da177e4SLinus Torvalds } 13171da177e4SLinus Torvalds 13181da177e4SLinus Torvalds if (!atm_charge(vcc, sb->truesize)) { 13191da177e4SLinus Torvalds RXPRINTK("%s: atm_charge() dropped AAL0 packets.\n", 13201da177e4SLinus Torvalds card->name); 13211da177e4SLinus Torvalds dev_kfree_skb(sb); 13221da177e4SLinus Torvalds goto drop; 13231da177e4SLinus Torvalds } 13241da177e4SLinus Torvalds 13251da177e4SLinus Torvalds *((u32 *) sb->data) = header; 13261da177e4SLinus Torvalds skb_put(sb, sizeof(u32)); 13271da177e4SLinus Torvalds memcpy(skb_put(sb, ATM_CELL_PAYLOAD), &(queue->data[16]), 13281da177e4SLinus Torvalds ATM_CELL_PAYLOAD); 13291da177e4SLinus Torvalds 13301da177e4SLinus Torvalds ATM_SKB(sb)->vcc = vcc; 1331a61bbcf2SPatrick McHardy __net_timestamp(sb); 13321da177e4SLinus Torvalds vcc->push(vcc, sb); 13331da177e4SLinus Torvalds atomic_inc(&vcc->stats->rx); 13341da177e4SLinus Torvalds 13351da177e4SLinus Torvalds drop: 13361da177e4SLinus Torvalds skb_pull(queue, 64); 13371da177e4SLinus Torvalds 13381da177e4SLinus Torvalds head = IDT77252_PRV_PADDR(queue) 13391da177e4SLinus Torvalds + (queue->data - queue->head - 16); 13401da177e4SLinus Torvalds 13411da177e4SLinus Torvalds if (queue->len < 128) { 13421da177e4SLinus Torvalds struct sk_buff *next; 13431da177e4SLinus Torvalds u32 handle; 13441da177e4SLinus Torvalds 13451da177e4SLinus Torvalds head = le32_to_cpu(*(u32 *) &queue->data[0]); 13461da177e4SLinus Torvalds handle = le32_to_cpu(*(u32 *) &queue->data[4]); 13471da177e4SLinus Torvalds 13481da177e4SLinus Torvalds next = sb_pool_skb(card, handle); 13491da177e4SLinus Torvalds recycle_rx_skb(card, queue); 13501da177e4SLinus Torvalds 13511da177e4SLinus Torvalds if (next) { 13521da177e4SLinus Torvalds card->raw_cell_head = next; 13531da177e4SLinus Torvalds queue = card->raw_cell_head; 13541da177e4SLinus Torvalds pci_dma_sync_single_for_cpu(card->pcidev, 13551da177e4SLinus Torvalds IDT77252_PRV_PADDR(queue), 13564305b541SArnaldo Carvalho de Melo (skb_end_pointer(queue) - 13574305b541SArnaldo Carvalho de Melo queue->data), 13581da177e4SLinus Torvalds PCI_DMA_FROMDEVICE); 13591da177e4SLinus Torvalds } else { 13601da177e4SLinus Torvalds card->raw_cell_head = NULL; 13611da177e4SLinus Torvalds printk("%s: raw cell queue overrun\n", 13621da177e4SLinus Torvalds card->name); 13631da177e4SLinus Torvalds break; 13641da177e4SLinus Torvalds } 13651da177e4SLinus Torvalds } 13661da177e4SLinus Torvalds } 13671da177e4SLinus Torvalds } 13681da177e4SLinus Torvalds 13691da177e4SLinus Torvalds 13701da177e4SLinus Torvalds /*****************************************************************************/ 13711da177e4SLinus Torvalds /* */ 13721da177e4SLinus Torvalds /* TSQ Handling */ 13731da177e4SLinus Torvalds /* */ 13741da177e4SLinus Torvalds /*****************************************************************************/ 13751da177e4SLinus Torvalds 13761da177e4SLinus Torvalds static int 13771da177e4SLinus Torvalds init_tsq(struct idt77252_dev *card) 13781da177e4SLinus Torvalds { 13791da177e4SLinus Torvalds struct tsq_entry *tsqe; 13801da177e4SLinus Torvalds 13811da177e4SLinus Torvalds card->tsq.base = pci_alloc_consistent(card->pcidev, RSQSIZE, 13821da177e4SLinus Torvalds &card->tsq.paddr); 13831da177e4SLinus Torvalds if (card->tsq.base == NULL) { 13841da177e4SLinus Torvalds printk("%s: can't allocate TSQ.\n", card->name); 13851da177e4SLinus Torvalds return -1; 13861da177e4SLinus Torvalds } 13871da177e4SLinus Torvalds memset(card->tsq.base, 0, TSQSIZE); 13881da177e4SLinus Torvalds 13891da177e4SLinus Torvalds card->tsq.last = card->tsq.base + TSQ_NUM_ENTRIES - 1; 13901da177e4SLinus Torvalds card->tsq.next = card->tsq.last; 13911da177e4SLinus Torvalds for (tsqe = card->tsq.base; tsqe <= card->tsq.last; tsqe++) 13921da177e4SLinus Torvalds tsqe->word_2 = cpu_to_le32(SAR_TSQE_INVALID); 13931da177e4SLinus Torvalds 13941da177e4SLinus Torvalds writel(card->tsq.paddr, SAR_REG_TSQB); 13951da177e4SLinus Torvalds writel((unsigned long) card->tsq.next - (unsigned long) card->tsq.base, 13961da177e4SLinus Torvalds SAR_REG_TSQH); 13971da177e4SLinus Torvalds 13981da177e4SLinus Torvalds return 0; 13991da177e4SLinus Torvalds } 14001da177e4SLinus Torvalds 14011da177e4SLinus Torvalds static void 14021da177e4SLinus Torvalds deinit_tsq(struct idt77252_dev *card) 14031da177e4SLinus Torvalds { 14041da177e4SLinus Torvalds pci_free_consistent(card->pcidev, TSQSIZE, 14051da177e4SLinus Torvalds card->tsq.base, card->tsq.paddr); 14061da177e4SLinus Torvalds } 14071da177e4SLinus Torvalds 14081da177e4SLinus Torvalds static void 14091da177e4SLinus Torvalds idt77252_tx(struct idt77252_dev *card) 14101da177e4SLinus Torvalds { 14111da177e4SLinus Torvalds struct tsq_entry *tsqe; 14121da177e4SLinus Torvalds unsigned int vpi, vci; 14131da177e4SLinus Torvalds struct vc_map *vc; 14141da177e4SLinus Torvalds u32 conn, stat; 14151da177e4SLinus Torvalds 14161da177e4SLinus Torvalds if (card->tsq.next == card->tsq.last) 14171da177e4SLinus Torvalds tsqe = card->tsq.base; 14181da177e4SLinus Torvalds else 14191da177e4SLinus Torvalds tsqe = card->tsq.next + 1; 14201da177e4SLinus Torvalds 14211da177e4SLinus Torvalds TXPRINTK("idt77252_tx: tsq %p: base %p, next %p, last %p\n", tsqe, 14221da177e4SLinus Torvalds card->tsq.base, card->tsq.next, card->tsq.last); 14231da177e4SLinus Torvalds TXPRINTK("idt77252_tx: tsqb %08x, tsqt %08x, tsqh %08x, \n", 14241da177e4SLinus Torvalds readl(SAR_REG_TSQB), 14251da177e4SLinus Torvalds readl(SAR_REG_TSQT), 14261da177e4SLinus Torvalds readl(SAR_REG_TSQH)); 14271da177e4SLinus Torvalds 14281da177e4SLinus Torvalds stat = le32_to_cpu(tsqe->word_2); 14291da177e4SLinus Torvalds 14301da177e4SLinus Torvalds if (stat & SAR_TSQE_INVALID) 14311da177e4SLinus Torvalds return; 14321da177e4SLinus Torvalds 14331da177e4SLinus Torvalds do { 14341da177e4SLinus Torvalds TXPRINTK("tsqe: 0x%p [0x%08x 0x%08x]\n", tsqe, 14351da177e4SLinus Torvalds le32_to_cpu(tsqe->word_1), 14361da177e4SLinus Torvalds le32_to_cpu(tsqe->word_2)); 14371da177e4SLinus Torvalds 14381da177e4SLinus Torvalds switch (stat & SAR_TSQE_TYPE) { 14391da177e4SLinus Torvalds case SAR_TSQE_TYPE_TIMER: 14401da177e4SLinus Torvalds TXPRINTK("%s: Timer RollOver detected.\n", card->name); 14411da177e4SLinus Torvalds break; 14421da177e4SLinus Torvalds 14431da177e4SLinus Torvalds case SAR_TSQE_TYPE_IDLE: 14441da177e4SLinus Torvalds 14451da177e4SLinus Torvalds conn = le32_to_cpu(tsqe->word_1); 14461da177e4SLinus Torvalds 14471da177e4SLinus Torvalds if (SAR_TSQE_TAG(stat) == 0x10) { 14481da177e4SLinus Torvalds #ifdef NOTDEF 14491da177e4SLinus Torvalds printk("%s: Connection %d halted.\n", 14501da177e4SLinus Torvalds card->name, 14511da177e4SLinus Torvalds le32_to_cpu(tsqe->word_1) & 0x1fff); 14521da177e4SLinus Torvalds #endif 14531da177e4SLinus Torvalds break; 14541da177e4SLinus Torvalds } 14551da177e4SLinus Torvalds 14561da177e4SLinus Torvalds vc = card->vcs[conn & 0x1fff]; 14571da177e4SLinus Torvalds if (!vc) { 14581da177e4SLinus Torvalds printk("%s: could not find VC from conn %d\n", 14591da177e4SLinus Torvalds card->name, conn & 0x1fff); 14601da177e4SLinus Torvalds break; 14611da177e4SLinus Torvalds } 14621da177e4SLinus Torvalds 14631da177e4SLinus Torvalds printk("%s: Connection %d IDLE.\n", 14641da177e4SLinus Torvalds card->name, vc->index); 14651da177e4SLinus Torvalds 14661da177e4SLinus Torvalds set_bit(VCF_IDLE, &vc->flags); 14671da177e4SLinus Torvalds break; 14681da177e4SLinus Torvalds 14691da177e4SLinus Torvalds case SAR_TSQE_TYPE_TSR: 14701da177e4SLinus Torvalds 14711da177e4SLinus Torvalds conn = le32_to_cpu(tsqe->word_1); 14721da177e4SLinus Torvalds 14731da177e4SLinus Torvalds vc = card->vcs[conn & 0x1fff]; 14741da177e4SLinus Torvalds if (!vc) { 14751da177e4SLinus Torvalds printk("%s: no VC at index %d\n", 14761da177e4SLinus Torvalds card->name, 14771da177e4SLinus Torvalds le32_to_cpu(tsqe->word_1) & 0x1fff); 14781da177e4SLinus Torvalds break; 14791da177e4SLinus Torvalds } 14801da177e4SLinus Torvalds 14811da177e4SLinus Torvalds drain_scq(card, vc); 14821da177e4SLinus Torvalds break; 14831da177e4SLinus Torvalds 14841da177e4SLinus Torvalds case SAR_TSQE_TYPE_TBD_COMP: 14851da177e4SLinus Torvalds 14861da177e4SLinus Torvalds conn = le32_to_cpu(tsqe->word_1); 14871da177e4SLinus Torvalds 14881da177e4SLinus Torvalds vpi = (conn >> SAR_TBD_VPI_SHIFT) & 0x00ff; 14891da177e4SLinus Torvalds vci = (conn >> SAR_TBD_VCI_SHIFT) & 0xffff; 14901da177e4SLinus Torvalds 14911da177e4SLinus Torvalds if (vpi >= (1 << card->vpibits) || 14921da177e4SLinus Torvalds vci >= (1 << card->vcibits)) { 14931da177e4SLinus Torvalds printk("%s: TBD complete: " 14941da177e4SLinus Torvalds "out of range VPI.VCI %u.%u\n", 14951da177e4SLinus Torvalds card->name, vpi, vci); 14961da177e4SLinus Torvalds break; 14971da177e4SLinus Torvalds } 14981da177e4SLinus Torvalds 14991da177e4SLinus Torvalds vc = card->vcs[VPCI2VC(card, vpi, vci)]; 15001da177e4SLinus Torvalds if (!vc) { 15011da177e4SLinus Torvalds printk("%s: TBD complete: " 15021da177e4SLinus Torvalds "no VC at VPI.VCI %u.%u\n", 15031da177e4SLinus Torvalds card->name, vpi, vci); 15041da177e4SLinus Torvalds break; 15051da177e4SLinus Torvalds } 15061da177e4SLinus Torvalds 15071da177e4SLinus Torvalds drain_scq(card, vc); 15081da177e4SLinus Torvalds break; 15091da177e4SLinus Torvalds } 15101da177e4SLinus Torvalds 15111da177e4SLinus Torvalds tsqe->word_2 = cpu_to_le32(SAR_TSQE_INVALID); 15121da177e4SLinus Torvalds 15131da177e4SLinus Torvalds card->tsq.next = tsqe; 15141da177e4SLinus Torvalds if (card->tsq.next == card->tsq.last) 15151da177e4SLinus Torvalds tsqe = card->tsq.base; 15161da177e4SLinus Torvalds else 15171da177e4SLinus Torvalds tsqe = card->tsq.next + 1; 15181da177e4SLinus Torvalds 15191da177e4SLinus Torvalds TXPRINTK("tsqe: %p: base %p, next %p, last %p\n", tsqe, 15201da177e4SLinus Torvalds card->tsq.base, card->tsq.next, card->tsq.last); 15211da177e4SLinus Torvalds 15221da177e4SLinus Torvalds stat = le32_to_cpu(tsqe->word_2); 15231da177e4SLinus Torvalds 15241da177e4SLinus Torvalds } while (!(stat & SAR_TSQE_INVALID)); 15251da177e4SLinus Torvalds 15261da177e4SLinus Torvalds writel((unsigned long)card->tsq.next - (unsigned long)card->tsq.base, 15271da177e4SLinus Torvalds SAR_REG_TSQH); 15281da177e4SLinus Torvalds 15291da177e4SLinus Torvalds XPRINTK("idt77252_tx-after writel%d: TSQ head = 0x%x, tail = 0x%x, next = 0x%p.\n", 15301da177e4SLinus Torvalds card->index, readl(SAR_REG_TSQH), 15311da177e4SLinus Torvalds readl(SAR_REG_TSQT), card->tsq.next); 15321da177e4SLinus Torvalds } 15331da177e4SLinus Torvalds 15341da177e4SLinus Torvalds 15351da177e4SLinus Torvalds static void 15361da177e4SLinus Torvalds tst_timer(unsigned long data) 15371da177e4SLinus Torvalds { 15381da177e4SLinus Torvalds struct idt77252_dev *card = (struct idt77252_dev *)data; 15391da177e4SLinus Torvalds unsigned long base, idle, jump; 15401da177e4SLinus Torvalds unsigned long flags; 15411da177e4SLinus Torvalds u32 pc; 15421da177e4SLinus Torvalds int e; 15431da177e4SLinus Torvalds 15441da177e4SLinus Torvalds spin_lock_irqsave(&card->tst_lock, flags); 15451da177e4SLinus Torvalds 15461da177e4SLinus Torvalds base = card->tst[card->tst_index]; 15471da177e4SLinus Torvalds idle = card->tst[card->tst_index ^ 1]; 15481da177e4SLinus Torvalds 15491da177e4SLinus Torvalds if (test_bit(TST_SWITCH_WAIT, &card->tst_state)) { 15501da177e4SLinus Torvalds jump = base + card->tst_size - 2; 15511da177e4SLinus Torvalds 15521da177e4SLinus Torvalds pc = readl(SAR_REG_NOW) >> 2; 15531da177e4SLinus Torvalds if ((pc ^ idle) & ~(card->tst_size - 1)) { 15541da177e4SLinus Torvalds mod_timer(&card->tst_timer, jiffies + 1); 15551da177e4SLinus Torvalds goto out; 15561da177e4SLinus Torvalds } 15571da177e4SLinus Torvalds 15581da177e4SLinus Torvalds clear_bit(TST_SWITCH_WAIT, &card->tst_state); 15591da177e4SLinus Torvalds 15601da177e4SLinus Torvalds card->tst_index ^= 1; 15611da177e4SLinus Torvalds write_sram(card, jump, TSTE_OPC_JMP | (base << 2)); 15621da177e4SLinus Torvalds 15631da177e4SLinus Torvalds base = card->tst[card->tst_index]; 15641da177e4SLinus Torvalds idle = card->tst[card->tst_index ^ 1]; 15651da177e4SLinus Torvalds 15661da177e4SLinus Torvalds for (e = 0; e < card->tst_size - 2; e++) { 15671da177e4SLinus Torvalds if (card->soft_tst[e].tste & TSTE_PUSH_IDLE) { 15681da177e4SLinus Torvalds write_sram(card, idle + e, 15691da177e4SLinus Torvalds card->soft_tst[e].tste & TSTE_MASK); 15701da177e4SLinus Torvalds card->soft_tst[e].tste &= ~(TSTE_PUSH_IDLE); 15711da177e4SLinus Torvalds } 15721da177e4SLinus Torvalds } 15731da177e4SLinus Torvalds } 15741da177e4SLinus Torvalds 15751da177e4SLinus Torvalds if (test_and_clear_bit(TST_SWITCH_PENDING, &card->tst_state)) { 15761da177e4SLinus Torvalds 15771da177e4SLinus Torvalds for (e = 0; e < card->tst_size - 2; e++) { 15781da177e4SLinus Torvalds if (card->soft_tst[e].tste & TSTE_PUSH_ACTIVE) { 15791da177e4SLinus Torvalds write_sram(card, idle + e, 15801da177e4SLinus Torvalds card->soft_tst[e].tste & TSTE_MASK); 15811da177e4SLinus Torvalds card->soft_tst[e].tste &= ~(TSTE_PUSH_ACTIVE); 15821da177e4SLinus Torvalds card->soft_tst[e].tste |= TSTE_PUSH_IDLE; 15831da177e4SLinus Torvalds } 15841da177e4SLinus Torvalds } 15851da177e4SLinus Torvalds 15861da177e4SLinus Torvalds jump = base + card->tst_size - 2; 15871da177e4SLinus Torvalds 15881da177e4SLinus Torvalds write_sram(card, jump, TSTE_OPC_NULL); 15891da177e4SLinus Torvalds set_bit(TST_SWITCH_WAIT, &card->tst_state); 15901da177e4SLinus Torvalds 15911da177e4SLinus Torvalds mod_timer(&card->tst_timer, jiffies + 1); 15921da177e4SLinus Torvalds } 15931da177e4SLinus Torvalds 15941da177e4SLinus Torvalds out: 15951da177e4SLinus Torvalds spin_unlock_irqrestore(&card->tst_lock, flags); 15961da177e4SLinus Torvalds } 15971da177e4SLinus Torvalds 15981da177e4SLinus Torvalds static int 15991da177e4SLinus Torvalds __fill_tst(struct idt77252_dev *card, struct vc_map *vc, 16001da177e4SLinus Torvalds int n, unsigned int opc) 16011da177e4SLinus Torvalds { 16021da177e4SLinus Torvalds unsigned long cl, avail; 16031da177e4SLinus Torvalds unsigned long idle; 16041da177e4SLinus Torvalds int e, r; 16051da177e4SLinus Torvalds u32 data; 16061da177e4SLinus Torvalds 16071da177e4SLinus Torvalds avail = card->tst_size - 2; 16081da177e4SLinus Torvalds for (e = 0; e < avail; e++) { 16091da177e4SLinus Torvalds if (card->soft_tst[e].vc == NULL) 16101da177e4SLinus Torvalds break; 16111da177e4SLinus Torvalds } 16121da177e4SLinus Torvalds if (e >= avail) { 16131da177e4SLinus Torvalds printk("%s: No free TST entries found\n", card->name); 16141da177e4SLinus Torvalds return -1; 16151da177e4SLinus Torvalds } 16161da177e4SLinus Torvalds 16171da177e4SLinus Torvalds NPRINTK("%s: conn %d: first TST entry at %d.\n", 16181da177e4SLinus Torvalds card->name, vc ? vc->index : -1, e); 16191da177e4SLinus Torvalds 16201da177e4SLinus Torvalds r = n; 16211da177e4SLinus Torvalds cl = avail; 16221da177e4SLinus Torvalds data = opc & TSTE_OPC_MASK; 16231da177e4SLinus Torvalds if (vc && (opc != TSTE_OPC_NULL)) 16241da177e4SLinus Torvalds data = opc | vc->index; 16251da177e4SLinus Torvalds 16261da177e4SLinus Torvalds idle = card->tst[card->tst_index ^ 1]; 16271da177e4SLinus Torvalds 16281da177e4SLinus Torvalds /* 16291da177e4SLinus Torvalds * Fill Soft TST. 16301da177e4SLinus Torvalds */ 16311da177e4SLinus Torvalds while (r > 0) { 16321da177e4SLinus Torvalds if ((cl >= avail) && (card->soft_tst[e].vc == NULL)) { 16331da177e4SLinus Torvalds if (vc) 16341da177e4SLinus Torvalds card->soft_tst[e].vc = vc; 16351da177e4SLinus Torvalds else 16361da177e4SLinus Torvalds card->soft_tst[e].vc = (void *)-1; 16371da177e4SLinus Torvalds 16381da177e4SLinus Torvalds card->soft_tst[e].tste = data; 16391da177e4SLinus Torvalds if (timer_pending(&card->tst_timer)) 16401da177e4SLinus Torvalds card->soft_tst[e].tste |= TSTE_PUSH_ACTIVE; 16411da177e4SLinus Torvalds else { 16421da177e4SLinus Torvalds write_sram(card, idle + e, data); 16431da177e4SLinus Torvalds card->soft_tst[e].tste |= TSTE_PUSH_IDLE; 16441da177e4SLinus Torvalds } 16451da177e4SLinus Torvalds 16461da177e4SLinus Torvalds cl -= card->tst_size; 16471da177e4SLinus Torvalds r--; 16481da177e4SLinus Torvalds } 16491da177e4SLinus Torvalds 16501da177e4SLinus Torvalds if (++e == avail) 16511da177e4SLinus Torvalds e = 0; 16521da177e4SLinus Torvalds cl += n; 16531da177e4SLinus Torvalds } 16541da177e4SLinus Torvalds 16551da177e4SLinus Torvalds return 0; 16561da177e4SLinus Torvalds } 16571da177e4SLinus Torvalds 16581da177e4SLinus Torvalds static int 16591da177e4SLinus Torvalds fill_tst(struct idt77252_dev *card, struct vc_map *vc, int n, unsigned int opc) 16601da177e4SLinus Torvalds { 16611da177e4SLinus Torvalds unsigned long flags; 16621da177e4SLinus Torvalds int res; 16631da177e4SLinus Torvalds 16641da177e4SLinus Torvalds spin_lock_irqsave(&card->tst_lock, flags); 16651da177e4SLinus Torvalds 16661da177e4SLinus Torvalds res = __fill_tst(card, vc, n, opc); 16671da177e4SLinus Torvalds 16681da177e4SLinus Torvalds set_bit(TST_SWITCH_PENDING, &card->tst_state); 16691da177e4SLinus Torvalds if (!timer_pending(&card->tst_timer)) 16701da177e4SLinus Torvalds mod_timer(&card->tst_timer, jiffies + 1); 16711da177e4SLinus Torvalds 16721da177e4SLinus Torvalds spin_unlock_irqrestore(&card->tst_lock, flags); 16731da177e4SLinus Torvalds return res; 16741da177e4SLinus Torvalds } 16751da177e4SLinus Torvalds 16761da177e4SLinus Torvalds static int 16771da177e4SLinus Torvalds __clear_tst(struct idt77252_dev *card, struct vc_map *vc) 16781da177e4SLinus Torvalds { 16791da177e4SLinus Torvalds unsigned long idle; 16801da177e4SLinus Torvalds int e; 16811da177e4SLinus Torvalds 16821da177e4SLinus Torvalds idle = card->tst[card->tst_index ^ 1]; 16831da177e4SLinus Torvalds 16841da177e4SLinus Torvalds for (e = 0; e < card->tst_size - 2; e++) { 16851da177e4SLinus Torvalds if (card->soft_tst[e].vc == vc) { 16861da177e4SLinus Torvalds card->soft_tst[e].vc = NULL; 16871da177e4SLinus Torvalds 16881da177e4SLinus Torvalds card->soft_tst[e].tste = TSTE_OPC_VAR; 16891da177e4SLinus Torvalds if (timer_pending(&card->tst_timer)) 16901da177e4SLinus Torvalds card->soft_tst[e].tste |= TSTE_PUSH_ACTIVE; 16911da177e4SLinus Torvalds else { 16921da177e4SLinus Torvalds write_sram(card, idle + e, TSTE_OPC_VAR); 16931da177e4SLinus Torvalds card->soft_tst[e].tste |= TSTE_PUSH_IDLE; 16941da177e4SLinus Torvalds } 16951da177e4SLinus Torvalds } 16961da177e4SLinus Torvalds } 16971da177e4SLinus Torvalds 16981da177e4SLinus Torvalds return 0; 16991da177e4SLinus Torvalds } 17001da177e4SLinus Torvalds 17011da177e4SLinus Torvalds static int 17021da177e4SLinus Torvalds clear_tst(struct idt77252_dev *card, struct vc_map *vc) 17031da177e4SLinus Torvalds { 17041da177e4SLinus Torvalds unsigned long flags; 17051da177e4SLinus Torvalds int res; 17061da177e4SLinus Torvalds 17071da177e4SLinus Torvalds spin_lock_irqsave(&card->tst_lock, flags); 17081da177e4SLinus Torvalds 17091da177e4SLinus Torvalds res = __clear_tst(card, vc); 17101da177e4SLinus Torvalds 17111da177e4SLinus Torvalds set_bit(TST_SWITCH_PENDING, &card->tst_state); 17121da177e4SLinus Torvalds if (!timer_pending(&card->tst_timer)) 17131da177e4SLinus Torvalds mod_timer(&card->tst_timer, jiffies + 1); 17141da177e4SLinus Torvalds 17151da177e4SLinus Torvalds spin_unlock_irqrestore(&card->tst_lock, flags); 17161da177e4SLinus Torvalds return res; 17171da177e4SLinus Torvalds } 17181da177e4SLinus Torvalds 17191da177e4SLinus Torvalds static int 17201da177e4SLinus Torvalds change_tst(struct idt77252_dev *card, struct vc_map *vc, 17211da177e4SLinus Torvalds int n, unsigned int opc) 17221da177e4SLinus Torvalds { 17231da177e4SLinus Torvalds unsigned long flags; 17241da177e4SLinus Torvalds int res; 17251da177e4SLinus Torvalds 17261da177e4SLinus Torvalds spin_lock_irqsave(&card->tst_lock, flags); 17271da177e4SLinus Torvalds 17281da177e4SLinus Torvalds __clear_tst(card, vc); 17291da177e4SLinus Torvalds res = __fill_tst(card, vc, n, opc); 17301da177e4SLinus Torvalds 17311da177e4SLinus Torvalds set_bit(TST_SWITCH_PENDING, &card->tst_state); 17321da177e4SLinus Torvalds if (!timer_pending(&card->tst_timer)) 17331da177e4SLinus Torvalds mod_timer(&card->tst_timer, jiffies + 1); 17341da177e4SLinus Torvalds 17351da177e4SLinus Torvalds spin_unlock_irqrestore(&card->tst_lock, flags); 17361da177e4SLinus Torvalds return res; 17371da177e4SLinus Torvalds } 17381da177e4SLinus Torvalds 17391da177e4SLinus Torvalds 17401da177e4SLinus Torvalds static int 17411da177e4SLinus Torvalds set_tct(struct idt77252_dev *card, struct vc_map *vc) 17421da177e4SLinus Torvalds { 17431da177e4SLinus Torvalds unsigned long tct; 17441da177e4SLinus Torvalds 17451da177e4SLinus Torvalds tct = (unsigned long) (card->tct_base + vc->index * SAR_SRAM_TCT_SIZE); 17461da177e4SLinus Torvalds 17471da177e4SLinus Torvalds switch (vc->class) { 17481da177e4SLinus Torvalds case SCHED_CBR: 17491da177e4SLinus Torvalds OPRINTK("%s: writing TCT at 0x%lx, SCD 0x%lx.\n", 17501da177e4SLinus Torvalds card->name, tct, vc->scq->scd); 17511da177e4SLinus Torvalds 17521da177e4SLinus Torvalds write_sram(card, tct + 0, TCT_CBR | vc->scq->scd); 17531da177e4SLinus Torvalds write_sram(card, tct + 1, 0); 17541da177e4SLinus Torvalds write_sram(card, tct + 2, 0); 17551da177e4SLinus Torvalds write_sram(card, tct + 3, 0); 17561da177e4SLinus Torvalds write_sram(card, tct + 4, 0); 17571da177e4SLinus Torvalds write_sram(card, tct + 5, 0); 17581da177e4SLinus Torvalds write_sram(card, tct + 6, 0); 17591da177e4SLinus Torvalds write_sram(card, tct + 7, 0); 17601da177e4SLinus Torvalds break; 17611da177e4SLinus Torvalds 17621da177e4SLinus Torvalds case SCHED_UBR: 17631da177e4SLinus Torvalds OPRINTK("%s: writing TCT at 0x%lx, SCD 0x%lx.\n", 17641da177e4SLinus Torvalds card->name, tct, vc->scq->scd); 17651da177e4SLinus Torvalds 17661da177e4SLinus Torvalds write_sram(card, tct + 0, TCT_UBR | vc->scq->scd); 17671da177e4SLinus Torvalds write_sram(card, tct + 1, 0); 17681da177e4SLinus Torvalds write_sram(card, tct + 2, TCT_TSIF); 17691da177e4SLinus Torvalds write_sram(card, tct + 3, TCT_HALT | TCT_IDLE); 17701da177e4SLinus Torvalds write_sram(card, tct + 4, 0); 17711da177e4SLinus Torvalds write_sram(card, tct + 5, vc->init_er); 17721da177e4SLinus Torvalds write_sram(card, tct + 6, 0); 17731da177e4SLinus Torvalds write_sram(card, tct + 7, TCT_FLAG_UBR); 17741da177e4SLinus Torvalds break; 17751da177e4SLinus Torvalds 17761da177e4SLinus Torvalds case SCHED_VBR: 17771da177e4SLinus Torvalds case SCHED_ABR: 17781da177e4SLinus Torvalds default: 17791da177e4SLinus Torvalds return -ENOSYS; 17801da177e4SLinus Torvalds } 17811da177e4SLinus Torvalds 17821da177e4SLinus Torvalds return 0; 17831da177e4SLinus Torvalds } 17841da177e4SLinus Torvalds 17851da177e4SLinus Torvalds /*****************************************************************************/ 17861da177e4SLinus Torvalds /* */ 17871da177e4SLinus Torvalds /* FBQ Handling */ 17881da177e4SLinus Torvalds /* */ 17891da177e4SLinus Torvalds /*****************************************************************************/ 17901da177e4SLinus Torvalds 17911da177e4SLinus Torvalds static __inline__ int 17921da177e4SLinus Torvalds idt77252_fbq_level(struct idt77252_dev *card, int queue) 17931da177e4SLinus Torvalds { 17941da177e4SLinus Torvalds return (readl(SAR_REG_STAT) >> (16 + (queue << 2))) & 0x0f; 17951da177e4SLinus Torvalds } 17961da177e4SLinus Torvalds 17971da177e4SLinus Torvalds static __inline__ int 17981da177e4SLinus Torvalds idt77252_fbq_full(struct idt77252_dev *card, int queue) 17991da177e4SLinus Torvalds { 18001da177e4SLinus Torvalds return (readl(SAR_REG_STAT) >> (16 + (queue << 2))) == 0x0f; 18011da177e4SLinus Torvalds } 18021da177e4SLinus Torvalds 18031da177e4SLinus Torvalds static int 18041da177e4SLinus Torvalds push_rx_skb(struct idt77252_dev *card, struct sk_buff *skb, int queue) 18051da177e4SLinus Torvalds { 18061da177e4SLinus Torvalds unsigned long flags; 18071da177e4SLinus Torvalds u32 handle; 18081da177e4SLinus Torvalds u32 addr; 18091da177e4SLinus Torvalds 181027a884dcSArnaldo Carvalho de Melo skb->data = skb->head; 181127a884dcSArnaldo Carvalho de Melo skb_reset_tail_pointer(skb); 18121da177e4SLinus Torvalds skb->len = 0; 18131da177e4SLinus Torvalds 18141da177e4SLinus Torvalds skb_reserve(skb, 16); 18151da177e4SLinus Torvalds 18161da177e4SLinus Torvalds switch (queue) { 18171da177e4SLinus Torvalds case 0: 18181da177e4SLinus Torvalds skb_put(skb, SAR_FB_SIZE_0); 18191da177e4SLinus Torvalds break; 18201da177e4SLinus Torvalds case 1: 18211da177e4SLinus Torvalds skb_put(skb, SAR_FB_SIZE_1); 18221da177e4SLinus Torvalds break; 18231da177e4SLinus Torvalds case 2: 18241da177e4SLinus Torvalds skb_put(skb, SAR_FB_SIZE_2); 18251da177e4SLinus Torvalds break; 18261da177e4SLinus Torvalds case 3: 18271da177e4SLinus Torvalds skb_put(skb, SAR_FB_SIZE_3); 18281da177e4SLinus Torvalds break; 18291da177e4SLinus Torvalds default: 18301da177e4SLinus Torvalds return -1; 18311da177e4SLinus Torvalds } 18321da177e4SLinus Torvalds 18331da177e4SLinus Torvalds if (idt77252_fbq_full(card, queue)) 18341da177e4SLinus Torvalds return -1; 18351da177e4SLinus Torvalds 18361da177e4SLinus Torvalds memset(&skb->data[(skb->len & ~(0x3f)) - 64], 0, 2 * sizeof(u32)); 18371da177e4SLinus Torvalds 18381da177e4SLinus Torvalds handle = IDT77252_PRV_POOL(skb); 18391da177e4SLinus Torvalds addr = IDT77252_PRV_PADDR(skb); 18401da177e4SLinus Torvalds 18411da177e4SLinus Torvalds spin_lock_irqsave(&card->cmd_lock, flags); 18421da177e4SLinus Torvalds writel(handle, card->fbq[queue]); 18431da177e4SLinus Torvalds writel(addr, card->fbq[queue]); 18441da177e4SLinus Torvalds spin_unlock_irqrestore(&card->cmd_lock, flags); 18451da177e4SLinus Torvalds 18461da177e4SLinus Torvalds return 0; 18471da177e4SLinus Torvalds } 18481da177e4SLinus Torvalds 18491da177e4SLinus Torvalds static void 18501da177e4SLinus Torvalds add_rx_skb(struct idt77252_dev *card, int queue, 18511da177e4SLinus Torvalds unsigned int size, unsigned int count) 18521da177e4SLinus Torvalds { 18531da177e4SLinus Torvalds struct sk_buff *skb; 18541da177e4SLinus Torvalds dma_addr_t paddr; 18551da177e4SLinus Torvalds u32 handle; 18561da177e4SLinus Torvalds 18571da177e4SLinus Torvalds while (count--) { 18581da177e4SLinus Torvalds skb = dev_alloc_skb(size); 18591da177e4SLinus Torvalds if (!skb) 18601da177e4SLinus Torvalds return; 18611da177e4SLinus Torvalds 18621da177e4SLinus Torvalds if (sb_pool_add(card, skb, queue)) { 18635a346a10SHarvey Harrison printk("%s: SB POOL full\n", __func__); 18641da177e4SLinus Torvalds goto outfree; 18651da177e4SLinus Torvalds } 18661da177e4SLinus Torvalds 18671da177e4SLinus Torvalds paddr = pci_map_single(card->pcidev, skb->data, 18684305b541SArnaldo Carvalho de Melo skb_end_pointer(skb) - skb->data, 18691da177e4SLinus Torvalds PCI_DMA_FROMDEVICE); 18701da177e4SLinus Torvalds IDT77252_PRV_PADDR(skb) = paddr; 18711da177e4SLinus Torvalds 18721da177e4SLinus Torvalds if (push_rx_skb(card, skb, queue)) { 18735a346a10SHarvey Harrison printk("%s: FB QUEUE full\n", __func__); 18741da177e4SLinus Torvalds goto outunmap; 18751da177e4SLinus Torvalds } 18761da177e4SLinus Torvalds } 18771da177e4SLinus Torvalds 18781da177e4SLinus Torvalds return; 18791da177e4SLinus Torvalds 18801da177e4SLinus Torvalds outunmap: 18811da177e4SLinus Torvalds pci_unmap_single(card->pcidev, IDT77252_PRV_PADDR(skb), 18824305b541SArnaldo Carvalho de Melo skb_end_pointer(skb) - skb->data, PCI_DMA_FROMDEVICE); 18831da177e4SLinus Torvalds 18841da177e4SLinus Torvalds handle = IDT77252_PRV_POOL(skb); 18851da177e4SLinus Torvalds card->sbpool[POOL_QUEUE(handle)].skb[POOL_INDEX(handle)] = NULL; 18861da177e4SLinus Torvalds 18871da177e4SLinus Torvalds outfree: 18881da177e4SLinus Torvalds dev_kfree_skb(skb); 18891da177e4SLinus Torvalds } 18901da177e4SLinus Torvalds 18911da177e4SLinus Torvalds 18921da177e4SLinus Torvalds static void 18931da177e4SLinus Torvalds recycle_rx_skb(struct idt77252_dev *card, struct sk_buff *skb) 18941da177e4SLinus Torvalds { 18951da177e4SLinus Torvalds u32 handle = IDT77252_PRV_POOL(skb); 18961da177e4SLinus Torvalds int err; 18971da177e4SLinus Torvalds 18981da177e4SLinus Torvalds pci_dma_sync_single_for_device(card->pcidev, IDT77252_PRV_PADDR(skb), 18994305b541SArnaldo Carvalho de Melo skb_end_pointer(skb) - skb->data, 19004305b541SArnaldo Carvalho de Melo PCI_DMA_FROMDEVICE); 19011da177e4SLinus Torvalds 19021da177e4SLinus Torvalds err = push_rx_skb(card, skb, POOL_QUEUE(handle)); 19031da177e4SLinus Torvalds if (err) { 19041da177e4SLinus Torvalds pci_unmap_single(card->pcidev, IDT77252_PRV_PADDR(skb), 19054305b541SArnaldo Carvalho de Melo skb_end_pointer(skb) - skb->data, 19064305b541SArnaldo Carvalho de Melo PCI_DMA_FROMDEVICE); 19071da177e4SLinus Torvalds sb_pool_remove(card, skb); 19081da177e4SLinus Torvalds dev_kfree_skb(skb); 19091da177e4SLinus Torvalds } 19101da177e4SLinus Torvalds } 19111da177e4SLinus Torvalds 19121da177e4SLinus Torvalds static void 19131da177e4SLinus Torvalds flush_rx_pool(struct idt77252_dev *card, struct rx_pool *rpp) 19141da177e4SLinus Torvalds { 1915ceade961SDavid S. Miller skb_queue_head_init(&rpp->queue); 19161da177e4SLinus Torvalds rpp->len = 0; 19171da177e4SLinus Torvalds } 19181da177e4SLinus Torvalds 19191da177e4SLinus Torvalds static void 19201da177e4SLinus Torvalds recycle_rx_pool_skb(struct idt77252_dev *card, struct rx_pool *rpp) 19211da177e4SLinus Torvalds { 1922ceade961SDavid S. Miller struct sk_buff *skb, *tmp; 19231da177e4SLinus Torvalds 1924ceade961SDavid S. Miller skb_queue_walk_safe(&rpp->queue, skb, tmp) 19251da177e4SLinus Torvalds recycle_rx_skb(card, skb); 1926ceade961SDavid S. Miller 19271da177e4SLinus Torvalds flush_rx_pool(card, rpp); 19281da177e4SLinus Torvalds } 19291da177e4SLinus Torvalds 19301da177e4SLinus Torvalds /*****************************************************************************/ 19311da177e4SLinus Torvalds /* */ 19321da177e4SLinus Torvalds /* ATM Interface */ 19331da177e4SLinus Torvalds /* */ 19341da177e4SLinus Torvalds /*****************************************************************************/ 19351da177e4SLinus Torvalds 19361da177e4SLinus Torvalds static void 19371da177e4SLinus Torvalds idt77252_phy_put(struct atm_dev *dev, unsigned char value, unsigned long addr) 19381da177e4SLinus Torvalds { 19391da177e4SLinus Torvalds write_utility(dev->dev_data, 0x100 + (addr & 0x1ff), value); 19401da177e4SLinus Torvalds } 19411da177e4SLinus Torvalds 19421da177e4SLinus Torvalds static unsigned char 19431da177e4SLinus Torvalds idt77252_phy_get(struct atm_dev *dev, unsigned long addr) 19441da177e4SLinus Torvalds { 19451da177e4SLinus Torvalds return read_utility(dev->dev_data, 0x100 + (addr & 0x1ff)); 19461da177e4SLinus Torvalds } 19471da177e4SLinus Torvalds 19481da177e4SLinus Torvalds static inline int 19491da177e4SLinus Torvalds idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam) 19501da177e4SLinus Torvalds { 19511da177e4SLinus Torvalds struct atm_dev *dev = vcc->dev; 19521da177e4SLinus Torvalds struct idt77252_dev *card = dev->dev_data; 19531da177e4SLinus Torvalds struct vc_map *vc = vcc->dev_data; 19541da177e4SLinus Torvalds int err; 19551da177e4SLinus Torvalds 19561da177e4SLinus Torvalds if (vc == NULL) { 19571da177e4SLinus Torvalds printk("%s: NULL connection in send().\n", card->name); 19581da177e4SLinus Torvalds atomic_inc(&vcc->stats->tx_err); 19591da177e4SLinus Torvalds dev_kfree_skb(skb); 19601da177e4SLinus Torvalds return -EINVAL; 19611da177e4SLinus Torvalds } 19621da177e4SLinus Torvalds if (!test_bit(VCF_TX, &vc->flags)) { 19631da177e4SLinus Torvalds printk("%s: Trying to transmit on a non-tx VC.\n", card->name); 19641da177e4SLinus Torvalds atomic_inc(&vcc->stats->tx_err); 19651da177e4SLinus Torvalds dev_kfree_skb(skb); 19661da177e4SLinus Torvalds return -EINVAL; 19671da177e4SLinus Torvalds } 19681da177e4SLinus Torvalds 19691da177e4SLinus Torvalds switch (vcc->qos.aal) { 19701da177e4SLinus Torvalds case ATM_AAL0: 19711da177e4SLinus Torvalds case ATM_AAL1: 19721da177e4SLinus Torvalds case ATM_AAL5: 19731da177e4SLinus Torvalds break; 19741da177e4SLinus Torvalds default: 19751da177e4SLinus Torvalds printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal); 19761da177e4SLinus Torvalds atomic_inc(&vcc->stats->tx_err); 19771da177e4SLinus Torvalds dev_kfree_skb(skb); 19781da177e4SLinus Torvalds return -EINVAL; 19791da177e4SLinus Torvalds } 19801da177e4SLinus Torvalds 19811da177e4SLinus Torvalds if (skb_shinfo(skb)->nr_frags != 0) { 19821da177e4SLinus Torvalds printk("%s: No scatter-gather yet.\n", card->name); 19831da177e4SLinus Torvalds atomic_inc(&vcc->stats->tx_err); 19841da177e4SLinus Torvalds dev_kfree_skb(skb); 19851da177e4SLinus Torvalds return -EINVAL; 19861da177e4SLinus Torvalds } 19871da177e4SLinus Torvalds ATM_SKB(skb)->vcc = vcc; 19881da177e4SLinus Torvalds 19891da177e4SLinus Torvalds err = queue_skb(card, vc, skb, oam); 19901da177e4SLinus Torvalds if (err) { 19911da177e4SLinus Torvalds atomic_inc(&vcc->stats->tx_err); 19921da177e4SLinus Torvalds dev_kfree_skb(skb); 19931da177e4SLinus Torvalds return err; 19941da177e4SLinus Torvalds } 19951da177e4SLinus Torvalds 19961da177e4SLinus Torvalds return 0; 19971da177e4SLinus Torvalds } 19981da177e4SLinus Torvalds 1999f4c4b4a6SAdrian Bunk static int idt77252_send(struct atm_vcc *vcc, struct sk_buff *skb) 20001da177e4SLinus Torvalds { 20011da177e4SLinus Torvalds return idt77252_send_skb(vcc, skb, 0); 20021da177e4SLinus Torvalds } 20031da177e4SLinus Torvalds 20041da177e4SLinus Torvalds static int 20051da177e4SLinus Torvalds idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags) 20061da177e4SLinus Torvalds { 20071da177e4SLinus Torvalds struct atm_dev *dev = vcc->dev; 20081da177e4SLinus Torvalds struct idt77252_dev *card = dev->dev_data; 20091da177e4SLinus Torvalds struct sk_buff *skb; 20101da177e4SLinus Torvalds 20111da177e4SLinus Torvalds skb = dev_alloc_skb(64); 20121da177e4SLinus Torvalds if (!skb) { 20131da177e4SLinus Torvalds printk("%s: Out of memory in send_oam().\n", card->name); 20141da177e4SLinus Torvalds atomic_inc(&vcc->stats->tx_err); 20151da177e4SLinus Torvalds return -ENOMEM; 20161da177e4SLinus Torvalds } 20171da177e4SLinus Torvalds atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc); 20181da177e4SLinus Torvalds 20191da177e4SLinus Torvalds memcpy(skb_put(skb, 52), cell, 52); 20201da177e4SLinus Torvalds 20211da177e4SLinus Torvalds return idt77252_send_skb(vcc, skb, 1); 20221da177e4SLinus Torvalds } 20231da177e4SLinus Torvalds 20241da177e4SLinus Torvalds static __inline__ unsigned int 20251da177e4SLinus Torvalds idt77252_fls(unsigned int x) 20261da177e4SLinus Torvalds { 20271da177e4SLinus Torvalds int r = 1; 20281da177e4SLinus Torvalds 20291da177e4SLinus Torvalds if (x == 0) 20301da177e4SLinus Torvalds return 0; 20311da177e4SLinus Torvalds if (x & 0xffff0000) { 20321da177e4SLinus Torvalds x >>= 16; 20331da177e4SLinus Torvalds r += 16; 20341da177e4SLinus Torvalds } 20351da177e4SLinus Torvalds if (x & 0xff00) { 20361da177e4SLinus Torvalds x >>= 8; 20371da177e4SLinus Torvalds r += 8; 20381da177e4SLinus Torvalds } 20391da177e4SLinus Torvalds if (x & 0xf0) { 20401da177e4SLinus Torvalds x >>= 4; 20411da177e4SLinus Torvalds r += 4; 20421da177e4SLinus Torvalds } 20431da177e4SLinus Torvalds if (x & 0xc) { 20441da177e4SLinus Torvalds x >>= 2; 20451da177e4SLinus Torvalds r += 2; 20461da177e4SLinus Torvalds } 20471da177e4SLinus Torvalds if (x & 0x2) 20481da177e4SLinus Torvalds r += 1; 20491da177e4SLinus Torvalds return r; 20501da177e4SLinus Torvalds } 20511da177e4SLinus Torvalds 20521da177e4SLinus Torvalds static u16 20531da177e4SLinus Torvalds idt77252_int_to_atmfp(unsigned int rate) 20541da177e4SLinus Torvalds { 20551da177e4SLinus Torvalds u16 m, e; 20561da177e4SLinus Torvalds 20571da177e4SLinus Torvalds if (rate == 0) 20581da177e4SLinus Torvalds return 0; 20591da177e4SLinus Torvalds e = idt77252_fls(rate) - 1; 20601da177e4SLinus Torvalds if (e < 9) 20611da177e4SLinus Torvalds m = (rate - (1 << e)) << (9 - e); 20621da177e4SLinus Torvalds else if (e == 9) 20631da177e4SLinus Torvalds m = (rate - (1 << e)); 20641da177e4SLinus Torvalds else /* e > 9 */ 20651da177e4SLinus Torvalds m = (rate - (1 << e)) >> (e - 9); 20661da177e4SLinus Torvalds return 0x4000 | (e << 9) | m; 20671da177e4SLinus Torvalds } 20681da177e4SLinus Torvalds 20691da177e4SLinus Torvalds static u8 20701da177e4SLinus Torvalds idt77252_rate_logindex(struct idt77252_dev *card, int pcr) 20711da177e4SLinus Torvalds { 20721da177e4SLinus Torvalds u16 afp; 20731da177e4SLinus Torvalds 20741da177e4SLinus Torvalds afp = idt77252_int_to_atmfp(pcr < 0 ? -pcr : pcr); 20751da177e4SLinus Torvalds if (pcr < 0) 20761da177e4SLinus Torvalds return rate_to_log[(afp >> 5) & 0x1ff]; 20771da177e4SLinus Torvalds return rate_to_log[((afp >> 5) + 1) & 0x1ff]; 20781da177e4SLinus Torvalds } 20791da177e4SLinus Torvalds 20801da177e4SLinus Torvalds static void 20811da177e4SLinus Torvalds idt77252_est_timer(unsigned long data) 20821da177e4SLinus Torvalds { 20831da177e4SLinus Torvalds struct vc_map *vc = (struct vc_map *)data; 20841da177e4SLinus Torvalds struct idt77252_dev *card = vc->card; 20851da177e4SLinus Torvalds struct rate_estimator *est; 20861da177e4SLinus Torvalds unsigned long flags; 20871da177e4SLinus Torvalds u32 rate, cps; 20881da177e4SLinus Torvalds u64 ncells; 20891da177e4SLinus Torvalds u8 lacr; 20901da177e4SLinus Torvalds 20911da177e4SLinus Torvalds spin_lock_irqsave(&vc->lock, flags); 20921da177e4SLinus Torvalds est = vc->estimator; 20931da177e4SLinus Torvalds if (!est) 20941da177e4SLinus Torvalds goto out; 20951da177e4SLinus Torvalds 20961da177e4SLinus Torvalds ncells = est->cells; 20971da177e4SLinus Torvalds 20981da177e4SLinus Torvalds rate = ((u32)(ncells - est->last_cells)) << (7 - est->interval); 20991da177e4SLinus Torvalds est->last_cells = ncells; 21001da177e4SLinus Torvalds est->avcps += ((long)rate - (long)est->avcps) >> est->ewma_log; 21011da177e4SLinus Torvalds est->cps = (est->avcps + 0x1f) >> 5; 21021da177e4SLinus Torvalds 21031da177e4SLinus Torvalds cps = est->cps; 21041da177e4SLinus Torvalds if (cps < (est->maxcps >> 4)) 21051da177e4SLinus Torvalds cps = est->maxcps >> 4; 21061da177e4SLinus Torvalds 21071da177e4SLinus Torvalds lacr = idt77252_rate_logindex(card, cps); 21081da177e4SLinus Torvalds if (lacr > vc->max_er) 21091da177e4SLinus Torvalds lacr = vc->max_er; 21101da177e4SLinus Torvalds 21111da177e4SLinus Torvalds if (lacr != vc->lacr) { 21121da177e4SLinus Torvalds vc->lacr = lacr; 21131da177e4SLinus Torvalds writel(TCMDQ_LACR|(vc->lacr << 16)|vc->index, SAR_REG_TCMDQ); 21141da177e4SLinus Torvalds } 21151da177e4SLinus Torvalds 21161da177e4SLinus Torvalds est->timer.expires = jiffies + ((HZ / 4) << est->interval); 21171da177e4SLinus Torvalds add_timer(&est->timer); 21181da177e4SLinus Torvalds 21191da177e4SLinus Torvalds out: 21201da177e4SLinus Torvalds spin_unlock_irqrestore(&vc->lock, flags); 21211da177e4SLinus Torvalds } 21221da177e4SLinus Torvalds 21231da177e4SLinus Torvalds static struct rate_estimator * 21241da177e4SLinus Torvalds idt77252_init_est(struct vc_map *vc, int pcr) 21251da177e4SLinus Torvalds { 21261da177e4SLinus Torvalds struct rate_estimator *est; 21271da177e4SLinus Torvalds 21280c1cca1dSOm Narasimhan est = kzalloc(sizeof(struct rate_estimator), GFP_KERNEL); 21291da177e4SLinus Torvalds if (!est) 21301da177e4SLinus Torvalds return NULL; 21311da177e4SLinus Torvalds est->maxcps = pcr < 0 ? -pcr : pcr; 21321da177e4SLinus Torvalds est->cps = est->maxcps; 21331da177e4SLinus Torvalds est->avcps = est->cps << 5; 21341da177e4SLinus Torvalds 21351da177e4SLinus Torvalds est->interval = 2; /* XXX: make this configurable */ 21361da177e4SLinus Torvalds est->ewma_log = 2; /* XXX: make this configurable */ 21371da177e4SLinus Torvalds init_timer(&est->timer); 21381da177e4SLinus Torvalds est->timer.data = (unsigned long)vc; 21391da177e4SLinus Torvalds est->timer.function = idt77252_est_timer; 21401da177e4SLinus Torvalds 21411da177e4SLinus Torvalds est->timer.expires = jiffies + ((HZ / 4) << est->interval); 21421da177e4SLinus Torvalds add_timer(&est->timer); 21431da177e4SLinus Torvalds 21441da177e4SLinus Torvalds return est; 21451da177e4SLinus Torvalds } 21461da177e4SLinus Torvalds 21471da177e4SLinus Torvalds static int 21481da177e4SLinus Torvalds idt77252_init_cbr(struct idt77252_dev *card, struct vc_map *vc, 21491da177e4SLinus Torvalds struct atm_vcc *vcc, struct atm_qos *qos) 21501da177e4SLinus Torvalds { 21511da177e4SLinus Torvalds int tst_free, tst_used, tst_entries; 21521da177e4SLinus Torvalds unsigned long tmpl, modl; 21531da177e4SLinus Torvalds int tcr, tcra; 21541da177e4SLinus Torvalds 21551da177e4SLinus Torvalds if ((qos->txtp.max_pcr == 0) && 21561da177e4SLinus Torvalds (qos->txtp.pcr == 0) && (qos->txtp.min_pcr == 0)) { 21571da177e4SLinus Torvalds printk("%s: trying to open a CBR VC with cell rate = 0\n", 21581da177e4SLinus Torvalds card->name); 21591da177e4SLinus Torvalds return -EINVAL; 21601da177e4SLinus Torvalds } 21611da177e4SLinus Torvalds 21621da177e4SLinus Torvalds tst_used = 0; 21631da177e4SLinus Torvalds tst_free = card->tst_free; 21641da177e4SLinus Torvalds if (test_bit(VCF_TX, &vc->flags)) 21651da177e4SLinus Torvalds tst_used = vc->ntste; 21661da177e4SLinus Torvalds tst_free += tst_used; 21671da177e4SLinus Torvalds 21681da177e4SLinus Torvalds tcr = atm_pcr_goal(&qos->txtp); 21691da177e4SLinus Torvalds tcra = tcr >= 0 ? tcr : -tcr; 21701da177e4SLinus Torvalds 21711da177e4SLinus Torvalds TXPRINTK("%s: CBR target cell rate = %d\n", card->name, tcra); 21721da177e4SLinus Torvalds 21731da177e4SLinus Torvalds tmpl = (unsigned long) tcra * ((unsigned long) card->tst_size - 2); 21741da177e4SLinus Torvalds modl = tmpl % (unsigned long)card->utopia_pcr; 21751da177e4SLinus Torvalds 21761da177e4SLinus Torvalds tst_entries = (int) (tmpl / card->utopia_pcr); 21771da177e4SLinus Torvalds if (tcr > 0) { 21781da177e4SLinus Torvalds if (modl > 0) 21791da177e4SLinus Torvalds tst_entries++; 21801da177e4SLinus Torvalds } else if (tcr == 0) { 21811da177e4SLinus Torvalds tst_entries = tst_free - SAR_TST_RESERVED; 21821da177e4SLinus Torvalds if (tst_entries <= 0) { 21831da177e4SLinus Torvalds printk("%s: no CBR bandwidth free.\n", card->name); 21841da177e4SLinus Torvalds return -ENOSR; 21851da177e4SLinus Torvalds } 21861da177e4SLinus Torvalds } 21871da177e4SLinus Torvalds 21881da177e4SLinus Torvalds if (tst_entries == 0) { 21891da177e4SLinus Torvalds printk("%s: selected CBR bandwidth < granularity.\n", 21901da177e4SLinus Torvalds card->name); 21911da177e4SLinus Torvalds return -EINVAL; 21921da177e4SLinus Torvalds } 21931da177e4SLinus Torvalds 21941da177e4SLinus Torvalds if (tst_entries > (tst_free - SAR_TST_RESERVED)) { 21951da177e4SLinus Torvalds printk("%s: not enough CBR bandwidth free.\n", card->name); 21961da177e4SLinus Torvalds return -ENOSR; 21971da177e4SLinus Torvalds } 21981da177e4SLinus Torvalds 21991da177e4SLinus Torvalds vc->ntste = tst_entries; 22001da177e4SLinus Torvalds 22011da177e4SLinus Torvalds card->tst_free = tst_free - tst_entries; 22021da177e4SLinus Torvalds if (test_bit(VCF_TX, &vc->flags)) { 22031da177e4SLinus Torvalds if (tst_used == tst_entries) 22041da177e4SLinus Torvalds return 0; 22051da177e4SLinus Torvalds 22061da177e4SLinus Torvalds OPRINTK("%s: modify %d -> %d entries in TST.\n", 22071da177e4SLinus Torvalds card->name, tst_used, tst_entries); 22081da177e4SLinus Torvalds change_tst(card, vc, tst_entries, TSTE_OPC_CBR); 22091da177e4SLinus Torvalds return 0; 22101da177e4SLinus Torvalds } 22111da177e4SLinus Torvalds 22121da177e4SLinus Torvalds OPRINTK("%s: setting %d entries in TST.\n", card->name, tst_entries); 22131da177e4SLinus Torvalds fill_tst(card, vc, tst_entries, TSTE_OPC_CBR); 22141da177e4SLinus Torvalds return 0; 22151da177e4SLinus Torvalds } 22161da177e4SLinus Torvalds 22171da177e4SLinus Torvalds static int 22181da177e4SLinus Torvalds idt77252_init_ubr(struct idt77252_dev *card, struct vc_map *vc, 22191da177e4SLinus Torvalds struct atm_vcc *vcc, struct atm_qos *qos) 22201da177e4SLinus Torvalds { 22211da177e4SLinus Torvalds unsigned long flags; 22221da177e4SLinus Torvalds int tcr; 22231da177e4SLinus Torvalds 22241da177e4SLinus Torvalds spin_lock_irqsave(&vc->lock, flags); 22251da177e4SLinus Torvalds if (vc->estimator) { 22261da177e4SLinus Torvalds del_timer(&vc->estimator->timer); 22271da177e4SLinus Torvalds kfree(vc->estimator); 22281da177e4SLinus Torvalds vc->estimator = NULL; 22291da177e4SLinus Torvalds } 22301da177e4SLinus Torvalds spin_unlock_irqrestore(&vc->lock, flags); 22311da177e4SLinus Torvalds 22321da177e4SLinus Torvalds tcr = atm_pcr_goal(&qos->txtp); 22331da177e4SLinus Torvalds if (tcr == 0) 22341da177e4SLinus Torvalds tcr = card->link_pcr; 22351da177e4SLinus Torvalds 22361da177e4SLinus Torvalds vc->estimator = idt77252_init_est(vc, tcr); 22371da177e4SLinus Torvalds 22381da177e4SLinus Torvalds vc->class = SCHED_UBR; 22391da177e4SLinus Torvalds vc->init_er = idt77252_rate_logindex(card, tcr); 22401da177e4SLinus Torvalds vc->lacr = vc->init_er; 22411da177e4SLinus Torvalds if (tcr < 0) 22421da177e4SLinus Torvalds vc->max_er = vc->init_er; 22431da177e4SLinus Torvalds else 22441da177e4SLinus Torvalds vc->max_er = 0xff; 22451da177e4SLinus Torvalds 22461da177e4SLinus Torvalds return 0; 22471da177e4SLinus Torvalds } 22481da177e4SLinus Torvalds 22491da177e4SLinus Torvalds static int 22501da177e4SLinus Torvalds idt77252_init_tx(struct idt77252_dev *card, struct vc_map *vc, 22511da177e4SLinus Torvalds struct atm_vcc *vcc, struct atm_qos *qos) 22521da177e4SLinus Torvalds { 22531da177e4SLinus Torvalds int error; 22541da177e4SLinus Torvalds 22551da177e4SLinus Torvalds if (test_bit(VCF_TX, &vc->flags)) 22561da177e4SLinus Torvalds return -EBUSY; 22571da177e4SLinus Torvalds 22581da177e4SLinus Torvalds switch (qos->txtp.traffic_class) { 22591da177e4SLinus Torvalds case ATM_CBR: 22601da177e4SLinus Torvalds vc->class = SCHED_CBR; 22611da177e4SLinus Torvalds break; 22621da177e4SLinus Torvalds 22631da177e4SLinus Torvalds case ATM_UBR: 22641da177e4SLinus Torvalds vc->class = SCHED_UBR; 22651da177e4SLinus Torvalds break; 22661da177e4SLinus Torvalds 22671da177e4SLinus Torvalds case ATM_VBR: 22681da177e4SLinus Torvalds case ATM_ABR: 22691da177e4SLinus Torvalds default: 22701da177e4SLinus Torvalds return -EPROTONOSUPPORT; 22711da177e4SLinus Torvalds } 22721da177e4SLinus Torvalds 22731da177e4SLinus Torvalds vc->scq = alloc_scq(card, vc->class); 22741da177e4SLinus Torvalds if (!vc->scq) { 22751da177e4SLinus Torvalds printk("%s: can't get SCQ.\n", card->name); 22761da177e4SLinus Torvalds return -ENOMEM; 22771da177e4SLinus Torvalds } 22781da177e4SLinus Torvalds 22791da177e4SLinus Torvalds vc->scq->scd = get_free_scd(card, vc); 22801da177e4SLinus Torvalds if (vc->scq->scd == 0) { 22811da177e4SLinus Torvalds printk("%s: no SCD available.\n", card->name); 22821da177e4SLinus Torvalds free_scq(card, vc->scq); 22831da177e4SLinus Torvalds return -ENOMEM; 22841da177e4SLinus Torvalds } 22851da177e4SLinus Torvalds 22861da177e4SLinus Torvalds fill_scd(card, vc->scq, vc->class); 22871da177e4SLinus Torvalds 22881da177e4SLinus Torvalds if (set_tct(card, vc)) { 22891da177e4SLinus Torvalds printk("%s: class %d not supported.\n", 22901da177e4SLinus Torvalds card->name, qos->txtp.traffic_class); 22911da177e4SLinus Torvalds 22921da177e4SLinus Torvalds card->scd2vc[vc->scd_index] = NULL; 22931da177e4SLinus Torvalds free_scq(card, vc->scq); 22941da177e4SLinus Torvalds return -EPROTONOSUPPORT; 22951da177e4SLinus Torvalds } 22961da177e4SLinus Torvalds 22971da177e4SLinus Torvalds switch (vc->class) { 22981da177e4SLinus Torvalds case SCHED_CBR: 22991da177e4SLinus Torvalds error = idt77252_init_cbr(card, vc, vcc, qos); 23001da177e4SLinus Torvalds if (error) { 23011da177e4SLinus Torvalds card->scd2vc[vc->scd_index] = NULL; 23021da177e4SLinus Torvalds free_scq(card, vc->scq); 23031da177e4SLinus Torvalds return error; 23041da177e4SLinus Torvalds } 23051da177e4SLinus Torvalds 23061da177e4SLinus Torvalds clear_bit(VCF_IDLE, &vc->flags); 23071da177e4SLinus Torvalds writel(TCMDQ_START | vc->index, SAR_REG_TCMDQ); 23081da177e4SLinus Torvalds break; 23091da177e4SLinus Torvalds 23101da177e4SLinus Torvalds case SCHED_UBR: 23111da177e4SLinus Torvalds error = idt77252_init_ubr(card, vc, vcc, qos); 23121da177e4SLinus Torvalds if (error) { 23131da177e4SLinus Torvalds card->scd2vc[vc->scd_index] = NULL; 23141da177e4SLinus Torvalds free_scq(card, vc->scq); 23151da177e4SLinus Torvalds return error; 23161da177e4SLinus Torvalds } 23171da177e4SLinus Torvalds 23181da177e4SLinus Torvalds set_bit(VCF_IDLE, &vc->flags); 23191da177e4SLinus Torvalds break; 23201da177e4SLinus Torvalds } 23211da177e4SLinus Torvalds 23221da177e4SLinus Torvalds vc->tx_vcc = vcc; 23231da177e4SLinus Torvalds set_bit(VCF_TX, &vc->flags); 23241da177e4SLinus Torvalds return 0; 23251da177e4SLinus Torvalds } 23261da177e4SLinus Torvalds 23271da177e4SLinus Torvalds static int 23281da177e4SLinus Torvalds idt77252_init_rx(struct idt77252_dev *card, struct vc_map *vc, 23291da177e4SLinus Torvalds struct atm_vcc *vcc, struct atm_qos *qos) 23301da177e4SLinus Torvalds { 23311da177e4SLinus Torvalds unsigned long flags; 23321da177e4SLinus Torvalds unsigned long addr; 23331da177e4SLinus Torvalds u32 rcte = 0; 23341da177e4SLinus Torvalds 23351da177e4SLinus Torvalds if (test_bit(VCF_RX, &vc->flags)) 23361da177e4SLinus Torvalds return -EBUSY; 23371da177e4SLinus Torvalds 23381da177e4SLinus Torvalds vc->rx_vcc = vcc; 23391da177e4SLinus Torvalds set_bit(VCF_RX, &vc->flags); 23401da177e4SLinus Torvalds 23411da177e4SLinus Torvalds if ((vcc->vci == 3) || (vcc->vci == 4)) 23421da177e4SLinus Torvalds return 0; 23431da177e4SLinus Torvalds 23441da177e4SLinus Torvalds flush_rx_pool(card, &vc->rcv.rx_pool); 23451da177e4SLinus Torvalds 23461da177e4SLinus Torvalds rcte |= SAR_RCTE_CONNECTOPEN; 23471da177e4SLinus Torvalds rcte |= SAR_RCTE_RAWCELLINTEN; 23481da177e4SLinus Torvalds 23491da177e4SLinus Torvalds switch (qos->aal) { 23501da177e4SLinus Torvalds case ATM_AAL0: 23511da177e4SLinus Torvalds rcte |= SAR_RCTE_RCQ; 23521da177e4SLinus Torvalds break; 23531da177e4SLinus Torvalds case ATM_AAL1: 23541da177e4SLinus Torvalds rcte |= SAR_RCTE_OAM; /* Let SAR drop Video */ 23551da177e4SLinus Torvalds break; 23561da177e4SLinus Torvalds case ATM_AAL34: 23571da177e4SLinus Torvalds rcte |= SAR_RCTE_AAL34; 23581da177e4SLinus Torvalds break; 23591da177e4SLinus Torvalds case ATM_AAL5: 23601da177e4SLinus Torvalds rcte |= SAR_RCTE_AAL5; 23611da177e4SLinus Torvalds break; 23621da177e4SLinus Torvalds default: 23631da177e4SLinus Torvalds rcte |= SAR_RCTE_RCQ; 23641da177e4SLinus Torvalds break; 23651da177e4SLinus Torvalds } 23661da177e4SLinus Torvalds 23671da177e4SLinus Torvalds if (qos->aal != ATM_AAL5) 23681da177e4SLinus Torvalds rcte |= SAR_RCTE_FBP_1; 23691da177e4SLinus Torvalds else if (qos->rxtp.max_sdu > SAR_FB_SIZE_2) 23701da177e4SLinus Torvalds rcte |= SAR_RCTE_FBP_3; 23711da177e4SLinus Torvalds else if (qos->rxtp.max_sdu > SAR_FB_SIZE_1) 23721da177e4SLinus Torvalds rcte |= SAR_RCTE_FBP_2; 23731da177e4SLinus Torvalds else if (qos->rxtp.max_sdu > SAR_FB_SIZE_0) 23741da177e4SLinus Torvalds rcte |= SAR_RCTE_FBP_1; 23751da177e4SLinus Torvalds else 23761da177e4SLinus Torvalds rcte |= SAR_RCTE_FBP_01; 23771da177e4SLinus Torvalds 23781da177e4SLinus Torvalds addr = card->rct_base + (vc->index << 2); 23791da177e4SLinus Torvalds 23801da177e4SLinus Torvalds OPRINTK("%s: writing RCT at 0x%lx\n", card->name, addr); 23811da177e4SLinus Torvalds write_sram(card, addr, rcte); 23821da177e4SLinus Torvalds 23831da177e4SLinus Torvalds spin_lock_irqsave(&card->cmd_lock, flags); 23841da177e4SLinus Torvalds writel(SAR_CMD_OPEN_CONNECTION | (addr << 2), SAR_REG_CMD); 23851da177e4SLinus Torvalds waitfor_idle(card); 23861da177e4SLinus Torvalds spin_unlock_irqrestore(&card->cmd_lock, flags); 23871da177e4SLinus Torvalds 23881da177e4SLinus Torvalds return 0; 23891da177e4SLinus Torvalds } 23901da177e4SLinus Torvalds 23911da177e4SLinus Torvalds static int 23921da177e4SLinus Torvalds idt77252_open(struct atm_vcc *vcc) 23931da177e4SLinus Torvalds { 23941da177e4SLinus Torvalds struct atm_dev *dev = vcc->dev; 23951da177e4SLinus Torvalds struct idt77252_dev *card = dev->dev_data; 23961da177e4SLinus Torvalds struct vc_map *vc; 23971da177e4SLinus Torvalds unsigned int index; 23981da177e4SLinus Torvalds unsigned int inuse; 23991da177e4SLinus Torvalds int error; 24001da177e4SLinus Torvalds int vci = vcc->vci; 24011da177e4SLinus Torvalds short vpi = vcc->vpi; 24021da177e4SLinus Torvalds 24031da177e4SLinus Torvalds if (vpi == ATM_VPI_UNSPEC || vci == ATM_VCI_UNSPEC) 24041da177e4SLinus Torvalds return 0; 24051da177e4SLinus Torvalds 24061da177e4SLinus Torvalds if (vpi >= (1 << card->vpibits)) { 24071da177e4SLinus Torvalds printk("%s: unsupported VPI: %d\n", card->name, vpi); 24081da177e4SLinus Torvalds return -EINVAL; 24091da177e4SLinus Torvalds } 24101da177e4SLinus Torvalds 24111da177e4SLinus Torvalds if (vci >= (1 << card->vcibits)) { 24121da177e4SLinus Torvalds printk("%s: unsupported VCI: %d\n", card->name, vci); 24131da177e4SLinus Torvalds return -EINVAL; 24141da177e4SLinus Torvalds } 24151da177e4SLinus Torvalds 24161da177e4SLinus Torvalds set_bit(ATM_VF_ADDR, &vcc->flags); 24171da177e4SLinus Torvalds 24187e7a2d07SMatthias Kaehlcke mutex_lock(&card->mutex); 24191da177e4SLinus Torvalds 24201da177e4SLinus Torvalds OPRINTK("%s: opening vpi.vci: %d.%d\n", card->name, vpi, vci); 24211da177e4SLinus Torvalds 24221da177e4SLinus Torvalds switch (vcc->qos.aal) { 24231da177e4SLinus Torvalds case ATM_AAL0: 24241da177e4SLinus Torvalds case ATM_AAL1: 24251da177e4SLinus Torvalds case ATM_AAL5: 24261da177e4SLinus Torvalds break; 24271da177e4SLinus Torvalds default: 24281da177e4SLinus Torvalds printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal); 24297e7a2d07SMatthias Kaehlcke mutex_unlock(&card->mutex); 24301da177e4SLinus Torvalds return -EPROTONOSUPPORT; 24311da177e4SLinus Torvalds } 24321da177e4SLinus Torvalds 24331da177e4SLinus Torvalds index = VPCI2VC(card, vpi, vci); 24341da177e4SLinus Torvalds if (!card->vcs[index]) { 24350c1cca1dSOm Narasimhan card->vcs[index] = kzalloc(sizeof(struct vc_map), GFP_KERNEL); 24361da177e4SLinus Torvalds if (!card->vcs[index]) { 24371da177e4SLinus Torvalds printk("%s: can't alloc vc in open()\n", card->name); 24387e7a2d07SMatthias Kaehlcke mutex_unlock(&card->mutex); 24391da177e4SLinus Torvalds return -ENOMEM; 24401da177e4SLinus Torvalds } 24411da177e4SLinus Torvalds card->vcs[index]->card = card; 24421da177e4SLinus Torvalds card->vcs[index]->index = index; 24431da177e4SLinus Torvalds 24441da177e4SLinus Torvalds spin_lock_init(&card->vcs[index]->lock); 24451da177e4SLinus Torvalds } 24461da177e4SLinus Torvalds vc = card->vcs[index]; 24471da177e4SLinus Torvalds 24481da177e4SLinus Torvalds vcc->dev_data = vc; 24491da177e4SLinus Torvalds 24501da177e4SLinus Torvalds IPRINTK("%s: idt77252_open: vc = %d (%d.%d) %s/%s (max RX SDU: %u)\n", 24511da177e4SLinus Torvalds card->name, vc->index, vcc->vpi, vcc->vci, 24521da177e4SLinus Torvalds vcc->qos.rxtp.traffic_class != ATM_NONE ? "rx" : "--", 24531da177e4SLinus Torvalds vcc->qos.txtp.traffic_class != ATM_NONE ? "tx" : "--", 24541da177e4SLinus Torvalds vcc->qos.rxtp.max_sdu); 24551da177e4SLinus Torvalds 24561da177e4SLinus Torvalds inuse = 0; 24571da177e4SLinus Torvalds if (vcc->qos.txtp.traffic_class != ATM_NONE && 24581da177e4SLinus Torvalds test_bit(VCF_TX, &vc->flags)) 24591da177e4SLinus Torvalds inuse = 1; 24601da177e4SLinus Torvalds if (vcc->qos.rxtp.traffic_class != ATM_NONE && 24611da177e4SLinus Torvalds test_bit(VCF_RX, &vc->flags)) 24621da177e4SLinus Torvalds inuse += 2; 24631da177e4SLinus Torvalds 24641da177e4SLinus Torvalds if (inuse) { 24651da177e4SLinus Torvalds printk("%s: %s vci already in use.\n", card->name, 24661da177e4SLinus Torvalds inuse == 1 ? "tx" : inuse == 2 ? "rx" : "tx and rx"); 24677e7a2d07SMatthias Kaehlcke mutex_unlock(&card->mutex); 24681da177e4SLinus Torvalds return -EADDRINUSE; 24691da177e4SLinus Torvalds } 24701da177e4SLinus Torvalds 24711da177e4SLinus Torvalds if (vcc->qos.txtp.traffic_class != ATM_NONE) { 24721da177e4SLinus Torvalds error = idt77252_init_tx(card, vc, vcc, &vcc->qos); 24731da177e4SLinus Torvalds if (error) { 24747e7a2d07SMatthias Kaehlcke mutex_unlock(&card->mutex); 24751da177e4SLinus Torvalds return error; 24761da177e4SLinus Torvalds } 24771da177e4SLinus Torvalds } 24781da177e4SLinus Torvalds 24791da177e4SLinus Torvalds if (vcc->qos.rxtp.traffic_class != ATM_NONE) { 24801da177e4SLinus Torvalds error = idt77252_init_rx(card, vc, vcc, &vcc->qos); 24811da177e4SLinus Torvalds if (error) { 24827e7a2d07SMatthias Kaehlcke mutex_unlock(&card->mutex); 24831da177e4SLinus Torvalds return error; 24841da177e4SLinus Torvalds } 24851da177e4SLinus Torvalds } 24861da177e4SLinus Torvalds 24871da177e4SLinus Torvalds set_bit(ATM_VF_READY, &vcc->flags); 24881da177e4SLinus Torvalds 24897e7a2d07SMatthias Kaehlcke mutex_unlock(&card->mutex); 24901da177e4SLinus Torvalds return 0; 24911da177e4SLinus Torvalds } 24921da177e4SLinus Torvalds 24931da177e4SLinus Torvalds static void 24941da177e4SLinus Torvalds idt77252_close(struct atm_vcc *vcc) 24951da177e4SLinus Torvalds { 24961da177e4SLinus Torvalds struct atm_dev *dev = vcc->dev; 24971da177e4SLinus Torvalds struct idt77252_dev *card = dev->dev_data; 24981da177e4SLinus Torvalds struct vc_map *vc = vcc->dev_data; 24991da177e4SLinus Torvalds unsigned long flags; 25001da177e4SLinus Torvalds unsigned long addr; 25011da177e4SLinus Torvalds unsigned long timeout; 25021da177e4SLinus Torvalds 25037e7a2d07SMatthias Kaehlcke mutex_lock(&card->mutex); 25041da177e4SLinus Torvalds 25051da177e4SLinus Torvalds IPRINTK("%s: idt77252_close: vc = %d (%d.%d)\n", 25061da177e4SLinus Torvalds card->name, vc->index, vcc->vpi, vcc->vci); 25071da177e4SLinus Torvalds 25081da177e4SLinus Torvalds clear_bit(ATM_VF_READY, &vcc->flags); 25091da177e4SLinus Torvalds 25101da177e4SLinus Torvalds if (vcc->qos.rxtp.traffic_class != ATM_NONE) { 25111da177e4SLinus Torvalds 25121da177e4SLinus Torvalds spin_lock_irqsave(&vc->lock, flags); 25131da177e4SLinus Torvalds clear_bit(VCF_RX, &vc->flags); 25141da177e4SLinus Torvalds vc->rx_vcc = NULL; 25151da177e4SLinus Torvalds spin_unlock_irqrestore(&vc->lock, flags); 25161da177e4SLinus Torvalds 25171da177e4SLinus Torvalds if ((vcc->vci == 3) || (vcc->vci == 4)) 25181da177e4SLinus Torvalds goto done; 25191da177e4SLinus Torvalds 25201da177e4SLinus Torvalds addr = card->rct_base + vc->index * SAR_SRAM_RCT_SIZE; 25211da177e4SLinus Torvalds 25221da177e4SLinus Torvalds spin_lock_irqsave(&card->cmd_lock, flags); 25231da177e4SLinus Torvalds writel(SAR_CMD_CLOSE_CONNECTION | (addr << 2), SAR_REG_CMD); 25241da177e4SLinus Torvalds waitfor_idle(card); 25251da177e4SLinus Torvalds spin_unlock_irqrestore(&card->cmd_lock, flags); 25261da177e4SLinus Torvalds 2527ceade961SDavid S. Miller if (skb_queue_len(&vc->rcv.rx_pool.queue) != 0) { 25281da177e4SLinus Torvalds DPRINTK("%s: closing a VC with pending rx buffers.\n", 25291da177e4SLinus Torvalds card->name); 25301da177e4SLinus Torvalds 25311da177e4SLinus Torvalds recycle_rx_pool_skb(card, &vc->rcv.rx_pool); 25321da177e4SLinus Torvalds } 25331da177e4SLinus Torvalds } 25341da177e4SLinus Torvalds 25351da177e4SLinus Torvalds done: 25361da177e4SLinus Torvalds if (vcc->qos.txtp.traffic_class != ATM_NONE) { 25371da177e4SLinus Torvalds 25381da177e4SLinus Torvalds spin_lock_irqsave(&vc->lock, flags); 25391da177e4SLinus Torvalds clear_bit(VCF_TX, &vc->flags); 25401da177e4SLinus Torvalds clear_bit(VCF_IDLE, &vc->flags); 25411da177e4SLinus Torvalds clear_bit(VCF_RSV, &vc->flags); 25421da177e4SLinus Torvalds vc->tx_vcc = NULL; 25431da177e4SLinus Torvalds 25441da177e4SLinus Torvalds if (vc->estimator) { 25451da177e4SLinus Torvalds del_timer(&vc->estimator->timer); 25461da177e4SLinus Torvalds kfree(vc->estimator); 25471da177e4SLinus Torvalds vc->estimator = NULL; 25481da177e4SLinus Torvalds } 25491da177e4SLinus Torvalds spin_unlock_irqrestore(&vc->lock, flags); 25501da177e4SLinus Torvalds 25511da177e4SLinus Torvalds timeout = 5 * 1000; 25521da177e4SLinus Torvalds while (atomic_read(&vc->scq->used) > 0) { 25531da177e4SLinus Torvalds timeout = msleep_interruptible(timeout); 25541da177e4SLinus Torvalds if (!timeout) 25551da177e4SLinus Torvalds break; 25561da177e4SLinus Torvalds } 25571da177e4SLinus Torvalds if (!timeout) 25581da177e4SLinus Torvalds printk("%s: SCQ drain timeout: %u used\n", 25591da177e4SLinus Torvalds card->name, atomic_read(&vc->scq->used)); 25601da177e4SLinus Torvalds 25611da177e4SLinus Torvalds writel(TCMDQ_HALT | vc->index, SAR_REG_TCMDQ); 25621da177e4SLinus Torvalds clear_scd(card, vc->scq, vc->class); 25631da177e4SLinus Torvalds 25641da177e4SLinus Torvalds if (vc->class == SCHED_CBR) { 25651da177e4SLinus Torvalds clear_tst(card, vc); 25661da177e4SLinus Torvalds card->tst_free += vc->ntste; 25671da177e4SLinus Torvalds vc->ntste = 0; 25681da177e4SLinus Torvalds } 25691da177e4SLinus Torvalds 25701da177e4SLinus Torvalds card->scd2vc[vc->scd_index] = NULL; 25711da177e4SLinus Torvalds free_scq(card, vc->scq); 25721da177e4SLinus Torvalds } 25731da177e4SLinus Torvalds 25747e7a2d07SMatthias Kaehlcke mutex_unlock(&card->mutex); 25751da177e4SLinus Torvalds } 25761da177e4SLinus Torvalds 25771da177e4SLinus Torvalds static int 25781da177e4SLinus Torvalds idt77252_change_qos(struct atm_vcc *vcc, struct atm_qos *qos, int flags) 25791da177e4SLinus Torvalds { 25801da177e4SLinus Torvalds struct atm_dev *dev = vcc->dev; 25811da177e4SLinus Torvalds struct idt77252_dev *card = dev->dev_data; 25821da177e4SLinus Torvalds struct vc_map *vc = vcc->dev_data; 25831da177e4SLinus Torvalds int error = 0; 25841da177e4SLinus Torvalds 25857e7a2d07SMatthias Kaehlcke mutex_lock(&card->mutex); 25861da177e4SLinus Torvalds 25871da177e4SLinus Torvalds if (qos->txtp.traffic_class != ATM_NONE) { 25881da177e4SLinus Torvalds if (!test_bit(VCF_TX, &vc->flags)) { 25891da177e4SLinus Torvalds error = idt77252_init_tx(card, vc, vcc, qos); 25901da177e4SLinus Torvalds if (error) 25911da177e4SLinus Torvalds goto out; 25921da177e4SLinus Torvalds } else { 25931da177e4SLinus Torvalds switch (qos->txtp.traffic_class) { 25941da177e4SLinus Torvalds case ATM_CBR: 25951da177e4SLinus Torvalds error = idt77252_init_cbr(card, vc, vcc, qos); 25961da177e4SLinus Torvalds if (error) 25971da177e4SLinus Torvalds goto out; 25981da177e4SLinus Torvalds break; 25991da177e4SLinus Torvalds 26001da177e4SLinus Torvalds case ATM_UBR: 26011da177e4SLinus Torvalds error = idt77252_init_ubr(card, vc, vcc, qos); 26021da177e4SLinus Torvalds if (error) 26031da177e4SLinus Torvalds goto out; 26041da177e4SLinus Torvalds 26051da177e4SLinus Torvalds if (!test_bit(VCF_IDLE, &vc->flags)) { 26061da177e4SLinus Torvalds writel(TCMDQ_LACR | (vc->lacr << 16) | 26071da177e4SLinus Torvalds vc->index, SAR_REG_TCMDQ); 26081da177e4SLinus Torvalds } 26091da177e4SLinus Torvalds break; 26101da177e4SLinus Torvalds 26111da177e4SLinus Torvalds case ATM_VBR: 26121da177e4SLinus Torvalds case ATM_ABR: 26131da177e4SLinus Torvalds error = -EOPNOTSUPP; 26141da177e4SLinus Torvalds goto out; 26151da177e4SLinus Torvalds } 26161da177e4SLinus Torvalds } 26171da177e4SLinus Torvalds } 26181da177e4SLinus Torvalds 26191da177e4SLinus Torvalds if ((qos->rxtp.traffic_class != ATM_NONE) && 26201da177e4SLinus Torvalds !test_bit(VCF_RX, &vc->flags)) { 26211da177e4SLinus Torvalds error = idt77252_init_rx(card, vc, vcc, qos); 26221da177e4SLinus Torvalds if (error) 26231da177e4SLinus Torvalds goto out; 26241da177e4SLinus Torvalds } 26251da177e4SLinus Torvalds 26261da177e4SLinus Torvalds memcpy(&vcc->qos, qos, sizeof(struct atm_qos)); 26271da177e4SLinus Torvalds 26281da177e4SLinus Torvalds set_bit(ATM_VF_HASQOS, &vcc->flags); 26291da177e4SLinus Torvalds 26301da177e4SLinus Torvalds out: 26317e7a2d07SMatthias Kaehlcke mutex_unlock(&card->mutex); 26321da177e4SLinus Torvalds return error; 26331da177e4SLinus Torvalds } 26341da177e4SLinus Torvalds 26351da177e4SLinus Torvalds static int 26361da177e4SLinus Torvalds idt77252_proc_read(struct atm_dev *dev, loff_t * pos, char *page) 26371da177e4SLinus Torvalds { 26381da177e4SLinus Torvalds struct idt77252_dev *card = dev->dev_data; 26391da177e4SLinus Torvalds int i, left; 26401da177e4SLinus Torvalds 26411da177e4SLinus Torvalds left = (int) *pos; 26421da177e4SLinus Torvalds if (!left--) 26431da177e4SLinus Torvalds return sprintf(page, "IDT77252 Interrupts:\n"); 26441da177e4SLinus Torvalds if (!left--) 26451da177e4SLinus Torvalds return sprintf(page, "TSIF: %lu\n", card->irqstat[15]); 26461da177e4SLinus Torvalds if (!left--) 26471da177e4SLinus Torvalds return sprintf(page, "TXICP: %lu\n", card->irqstat[14]); 26481da177e4SLinus Torvalds if (!left--) 26491da177e4SLinus Torvalds return sprintf(page, "TSQF: %lu\n", card->irqstat[12]); 26501da177e4SLinus Torvalds if (!left--) 26511da177e4SLinus Torvalds return sprintf(page, "TMROF: %lu\n", card->irqstat[11]); 26521da177e4SLinus Torvalds if (!left--) 26531da177e4SLinus Torvalds return sprintf(page, "PHYI: %lu\n", card->irqstat[10]); 26541da177e4SLinus Torvalds if (!left--) 26551da177e4SLinus Torvalds return sprintf(page, "FBQ3A: %lu\n", card->irqstat[8]); 26561da177e4SLinus Torvalds if (!left--) 26571da177e4SLinus Torvalds return sprintf(page, "FBQ2A: %lu\n", card->irqstat[7]); 26581da177e4SLinus Torvalds if (!left--) 26591da177e4SLinus Torvalds return sprintf(page, "RSQF: %lu\n", card->irqstat[6]); 26601da177e4SLinus Torvalds if (!left--) 26611da177e4SLinus Torvalds return sprintf(page, "EPDU: %lu\n", card->irqstat[5]); 26621da177e4SLinus Torvalds if (!left--) 26631da177e4SLinus Torvalds return sprintf(page, "RAWCF: %lu\n", card->irqstat[4]); 26641da177e4SLinus Torvalds if (!left--) 26651da177e4SLinus Torvalds return sprintf(page, "FBQ1A: %lu\n", card->irqstat[3]); 26661da177e4SLinus Torvalds if (!left--) 26671da177e4SLinus Torvalds return sprintf(page, "FBQ0A: %lu\n", card->irqstat[2]); 26681da177e4SLinus Torvalds if (!left--) 26691da177e4SLinus Torvalds return sprintf(page, "RSQAF: %lu\n", card->irqstat[1]); 26701da177e4SLinus Torvalds if (!left--) 26711da177e4SLinus Torvalds return sprintf(page, "IDT77252 Transmit Connection Table:\n"); 26721da177e4SLinus Torvalds 26731da177e4SLinus Torvalds for (i = 0; i < card->tct_size; i++) { 26741da177e4SLinus Torvalds unsigned long tct; 26751da177e4SLinus Torvalds struct atm_vcc *vcc; 26761da177e4SLinus Torvalds struct vc_map *vc; 26771da177e4SLinus Torvalds char *p; 26781da177e4SLinus Torvalds 26791da177e4SLinus Torvalds vc = card->vcs[i]; 26801da177e4SLinus Torvalds if (!vc) 26811da177e4SLinus Torvalds continue; 26821da177e4SLinus Torvalds 26831da177e4SLinus Torvalds vcc = NULL; 26841da177e4SLinus Torvalds if (vc->tx_vcc) 26851da177e4SLinus Torvalds vcc = vc->tx_vcc; 26861da177e4SLinus Torvalds if (!vcc) 26871da177e4SLinus Torvalds continue; 26881da177e4SLinus Torvalds if (left--) 26891da177e4SLinus Torvalds continue; 26901da177e4SLinus Torvalds 26911da177e4SLinus Torvalds p = page; 26921da177e4SLinus Torvalds p += sprintf(p, " %4u: %u.%u: ", i, vcc->vpi, vcc->vci); 26931da177e4SLinus Torvalds tct = (unsigned long) (card->tct_base + i * SAR_SRAM_TCT_SIZE); 26941da177e4SLinus Torvalds 26951da177e4SLinus Torvalds for (i = 0; i < 8; i++) 26961da177e4SLinus Torvalds p += sprintf(p, " %08x", read_sram(card, tct + i)); 26971da177e4SLinus Torvalds p += sprintf(p, "\n"); 26981da177e4SLinus Torvalds return p - page; 26991da177e4SLinus Torvalds } 27001da177e4SLinus Torvalds return 0; 27011da177e4SLinus Torvalds } 27021da177e4SLinus Torvalds 27031da177e4SLinus Torvalds /*****************************************************************************/ 27041da177e4SLinus Torvalds /* */ 27051da177e4SLinus Torvalds /* Interrupt handler */ 27061da177e4SLinus Torvalds /* */ 27071da177e4SLinus Torvalds /*****************************************************************************/ 27081da177e4SLinus Torvalds 27091da177e4SLinus Torvalds static void 27101da177e4SLinus Torvalds idt77252_collect_stat(struct idt77252_dev *card) 27111da177e4SLinus Torvalds { 2712edb4dcb7SDavid S. Miller (void) readl(SAR_REG_CDC); 2713edb4dcb7SDavid S. Miller (void) readl(SAR_REG_VPEC); 2714edb4dcb7SDavid S. Miller (void) readl(SAR_REG_ICC); 27151da177e4SLinus Torvalds 27161da177e4SLinus Torvalds } 27171da177e4SLinus Torvalds 27181da177e4SLinus Torvalds static irqreturn_t 27197d12e780SDavid Howells idt77252_interrupt(int irq, void *dev_id) 27201da177e4SLinus Torvalds { 27211da177e4SLinus Torvalds struct idt77252_dev *card = dev_id; 27221da177e4SLinus Torvalds u32 stat; 27231da177e4SLinus Torvalds 27241da177e4SLinus Torvalds stat = readl(SAR_REG_STAT) & 0xffff; 27251da177e4SLinus Torvalds if (!stat) /* no interrupt for us */ 27261da177e4SLinus Torvalds return IRQ_NONE; 27271da177e4SLinus Torvalds 27281da177e4SLinus Torvalds if (test_and_set_bit(IDT77252_BIT_INTERRUPT, &card->flags)) { 27291da177e4SLinus Torvalds printk("%s: Re-entering irq_handler()\n", card->name); 27301da177e4SLinus Torvalds goto out; 27311da177e4SLinus Torvalds } 27321da177e4SLinus Torvalds 27331da177e4SLinus Torvalds writel(stat, SAR_REG_STAT); /* reset interrupt */ 27341da177e4SLinus Torvalds 27351da177e4SLinus Torvalds if (stat & SAR_STAT_TSIF) { /* entry written to TSQ */ 27361da177e4SLinus Torvalds INTPRINTK("%s: TSIF\n", card->name); 27371da177e4SLinus Torvalds card->irqstat[15]++; 27381da177e4SLinus Torvalds idt77252_tx(card); 27391da177e4SLinus Torvalds } 27401da177e4SLinus Torvalds if (stat & SAR_STAT_TXICP) { /* Incomplete CS-PDU has */ 27411da177e4SLinus Torvalds INTPRINTK("%s: TXICP\n", card->name); 27421da177e4SLinus Torvalds card->irqstat[14]++; 27431da177e4SLinus Torvalds #ifdef CONFIG_ATM_IDT77252_DEBUG 27441da177e4SLinus Torvalds idt77252_tx_dump(card); 27451da177e4SLinus Torvalds #endif 27461da177e4SLinus Torvalds } 27471da177e4SLinus Torvalds if (stat & SAR_STAT_TSQF) { /* TSQ 7/8 full */ 27481da177e4SLinus Torvalds INTPRINTK("%s: TSQF\n", card->name); 27491da177e4SLinus Torvalds card->irqstat[12]++; 27501da177e4SLinus Torvalds idt77252_tx(card); 27511da177e4SLinus Torvalds } 27521da177e4SLinus Torvalds if (stat & SAR_STAT_TMROF) { /* Timer overflow */ 27531da177e4SLinus Torvalds INTPRINTK("%s: TMROF\n", card->name); 27541da177e4SLinus Torvalds card->irqstat[11]++; 27551da177e4SLinus Torvalds idt77252_collect_stat(card); 27561da177e4SLinus Torvalds } 27571da177e4SLinus Torvalds 27581da177e4SLinus Torvalds if (stat & SAR_STAT_EPDU) { /* Got complete CS-PDU */ 27591da177e4SLinus Torvalds INTPRINTK("%s: EPDU\n", card->name); 27601da177e4SLinus Torvalds card->irqstat[5]++; 27611da177e4SLinus Torvalds idt77252_rx(card); 27621da177e4SLinus Torvalds } 27631da177e4SLinus Torvalds if (stat & SAR_STAT_RSQAF) { /* RSQ is 7/8 full */ 27641da177e4SLinus Torvalds INTPRINTK("%s: RSQAF\n", card->name); 27651da177e4SLinus Torvalds card->irqstat[1]++; 27661da177e4SLinus Torvalds idt77252_rx(card); 27671da177e4SLinus Torvalds } 27681da177e4SLinus Torvalds if (stat & SAR_STAT_RSQF) { /* RSQ is full */ 27691da177e4SLinus Torvalds INTPRINTK("%s: RSQF\n", card->name); 27701da177e4SLinus Torvalds card->irqstat[6]++; 27711da177e4SLinus Torvalds idt77252_rx(card); 27721da177e4SLinus Torvalds } 27731da177e4SLinus Torvalds if (stat & SAR_STAT_RAWCF) { /* Raw cell received */ 27741da177e4SLinus Torvalds INTPRINTK("%s: RAWCF\n", card->name); 27751da177e4SLinus Torvalds card->irqstat[4]++; 27761da177e4SLinus Torvalds idt77252_rx_raw(card); 27771da177e4SLinus Torvalds } 27781da177e4SLinus Torvalds 27791da177e4SLinus Torvalds if (stat & SAR_STAT_PHYI) { /* PHY device interrupt */ 27801da177e4SLinus Torvalds INTPRINTK("%s: PHYI", card->name); 27811da177e4SLinus Torvalds card->irqstat[10]++; 27821da177e4SLinus Torvalds if (card->atmdev->phy && card->atmdev->phy->interrupt) 27831da177e4SLinus Torvalds card->atmdev->phy->interrupt(card->atmdev); 27841da177e4SLinus Torvalds } 27851da177e4SLinus Torvalds 27861da177e4SLinus Torvalds if (stat & (SAR_STAT_FBQ0A | SAR_STAT_FBQ1A | 27871da177e4SLinus Torvalds SAR_STAT_FBQ2A | SAR_STAT_FBQ3A)) { 27881da177e4SLinus Torvalds 27891da177e4SLinus Torvalds writel(readl(SAR_REG_CFG) & ~(SAR_CFG_FBIE), SAR_REG_CFG); 27901da177e4SLinus Torvalds 27911da177e4SLinus Torvalds INTPRINTK("%s: FBQA: %04x\n", card->name, stat); 27921da177e4SLinus Torvalds 27931da177e4SLinus Torvalds if (stat & SAR_STAT_FBQ0A) 27941da177e4SLinus Torvalds card->irqstat[2]++; 27951da177e4SLinus Torvalds if (stat & SAR_STAT_FBQ1A) 27961da177e4SLinus Torvalds card->irqstat[3]++; 27971da177e4SLinus Torvalds if (stat & SAR_STAT_FBQ2A) 27981da177e4SLinus Torvalds card->irqstat[7]++; 27991da177e4SLinus Torvalds if (stat & SAR_STAT_FBQ3A) 28001da177e4SLinus Torvalds card->irqstat[8]++; 28011da177e4SLinus Torvalds 28021da177e4SLinus Torvalds schedule_work(&card->tqueue); 28031da177e4SLinus Torvalds } 28041da177e4SLinus Torvalds 28051da177e4SLinus Torvalds out: 28061da177e4SLinus Torvalds clear_bit(IDT77252_BIT_INTERRUPT, &card->flags); 28071da177e4SLinus Torvalds return IRQ_HANDLED; 28081da177e4SLinus Torvalds } 28091da177e4SLinus Torvalds 28101da177e4SLinus Torvalds static void 2811c4028958SDavid Howells idt77252_softint(struct work_struct *work) 28121da177e4SLinus Torvalds { 2813c4028958SDavid Howells struct idt77252_dev *card = 2814c4028958SDavid Howells container_of(work, struct idt77252_dev, tqueue); 28151da177e4SLinus Torvalds u32 stat; 28161da177e4SLinus Torvalds int done; 28171da177e4SLinus Torvalds 28181da177e4SLinus Torvalds for (done = 1; ; done = 1) { 28191da177e4SLinus Torvalds stat = readl(SAR_REG_STAT) >> 16; 28201da177e4SLinus Torvalds 28211da177e4SLinus Torvalds if ((stat & 0x0f) < SAR_FBQ0_HIGH) { 28221da177e4SLinus Torvalds add_rx_skb(card, 0, SAR_FB_SIZE_0, 32); 28231da177e4SLinus Torvalds done = 0; 28241da177e4SLinus Torvalds } 28251da177e4SLinus Torvalds 28261da177e4SLinus Torvalds stat >>= 4; 28271da177e4SLinus Torvalds if ((stat & 0x0f) < SAR_FBQ1_HIGH) { 28281da177e4SLinus Torvalds add_rx_skb(card, 1, SAR_FB_SIZE_1, 32); 28291da177e4SLinus Torvalds done = 0; 28301da177e4SLinus Torvalds } 28311da177e4SLinus Torvalds 28321da177e4SLinus Torvalds stat >>= 4; 28331da177e4SLinus Torvalds if ((stat & 0x0f) < SAR_FBQ2_HIGH) { 28341da177e4SLinus Torvalds add_rx_skb(card, 2, SAR_FB_SIZE_2, 32); 28351da177e4SLinus Torvalds done = 0; 28361da177e4SLinus Torvalds } 28371da177e4SLinus Torvalds 28381da177e4SLinus Torvalds stat >>= 4; 28391da177e4SLinus Torvalds if ((stat & 0x0f) < SAR_FBQ3_HIGH) { 28401da177e4SLinus Torvalds add_rx_skb(card, 3, SAR_FB_SIZE_3, 32); 28411da177e4SLinus Torvalds done = 0; 28421da177e4SLinus Torvalds } 28431da177e4SLinus Torvalds 28441da177e4SLinus Torvalds if (done) 28451da177e4SLinus Torvalds break; 28461da177e4SLinus Torvalds } 28471da177e4SLinus Torvalds 28481da177e4SLinus Torvalds writel(readl(SAR_REG_CFG) | SAR_CFG_FBIE, SAR_REG_CFG); 28491da177e4SLinus Torvalds } 28501da177e4SLinus Torvalds 28511da177e4SLinus Torvalds 28521da177e4SLinus Torvalds static int 28531da177e4SLinus Torvalds open_card_oam(struct idt77252_dev *card) 28541da177e4SLinus Torvalds { 28551da177e4SLinus Torvalds unsigned long flags; 28561da177e4SLinus Torvalds unsigned long addr; 28571da177e4SLinus Torvalds struct vc_map *vc; 28581da177e4SLinus Torvalds int vpi, vci; 28591da177e4SLinus Torvalds int index; 28601da177e4SLinus Torvalds u32 rcte; 28611da177e4SLinus Torvalds 28621da177e4SLinus Torvalds for (vpi = 0; vpi < (1 << card->vpibits); vpi++) { 28631da177e4SLinus Torvalds for (vci = 3; vci < 5; vci++) { 28641da177e4SLinus Torvalds index = VPCI2VC(card, vpi, vci); 28651da177e4SLinus Torvalds 28660c1cca1dSOm Narasimhan vc = kzalloc(sizeof(struct vc_map), GFP_KERNEL); 28671da177e4SLinus Torvalds if (!vc) { 28681da177e4SLinus Torvalds printk("%s: can't alloc vc\n", card->name); 28691da177e4SLinus Torvalds return -ENOMEM; 28701da177e4SLinus Torvalds } 28711da177e4SLinus Torvalds vc->index = index; 28721da177e4SLinus Torvalds card->vcs[index] = vc; 28731da177e4SLinus Torvalds 28741da177e4SLinus Torvalds flush_rx_pool(card, &vc->rcv.rx_pool); 28751da177e4SLinus Torvalds 28761da177e4SLinus Torvalds rcte = SAR_RCTE_CONNECTOPEN | 28771da177e4SLinus Torvalds SAR_RCTE_RAWCELLINTEN | 28781da177e4SLinus Torvalds SAR_RCTE_RCQ | 28791da177e4SLinus Torvalds SAR_RCTE_FBP_1; 28801da177e4SLinus Torvalds 28811da177e4SLinus Torvalds addr = card->rct_base + (vc->index << 2); 28821da177e4SLinus Torvalds write_sram(card, addr, rcte); 28831da177e4SLinus Torvalds 28841da177e4SLinus Torvalds spin_lock_irqsave(&card->cmd_lock, flags); 28851da177e4SLinus Torvalds writel(SAR_CMD_OPEN_CONNECTION | (addr << 2), 28861da177e4SLinus Torvalds SAR_REG_CMD); 28871da177e4SLinus Torvalds waitfor_idle(card); 28881da177e4SLinus Torvalds spin_unlock_irqrestore(&card->cmd_lock, flags); 28891da177e4SLinus Torvalds } 28901da177e4SLinus Torvalds } 28911da177e4SLinus Torvalds 28921da177e4SLinus Torvalds return 0; 28931da177e4SLinus Torvalds } 28941da177e4SLinus Torvalds 28951da177e4SLinus Torvalds static void 28961da177e4SLinus Torvalds close_card_oam(struct idt77252_dev *card) 28971da177e4SLinus Torvalds { 28981da177e4SLinus Torvalds unsigned long flags; 28991da177e4SLinus Torvalds unsigned long addr; 29001da177e4SLinus Torvalds struct vc_map *vc; 29011da177e4SLinus Torvalds int vpi, vci; 29021da177e4SLinus Torvalds int index; 29031da177e4SLinus Torvalds 29041da177e4SLinus Torvalds for (vpi = 0; vpi < (1 << card->vpibits); vpi++) { 29051da177e4SLinus Torvalds for (vci = 3; vci < 5; vci++) { 29061da177e4SLinus Torvalds index = VPCI2VC(card, vpi, vci); 29071da177e4SLinus Torvalds vc = card->vcs[index]; 29081da177e4SLinus Torvalds 29091da177e4SLinus Torvalds addr = card->rct_base + vc->index * SAR_SRAM_RCT_SIZE; 29101da177e4SLinus Torvalds 29111da177e4SLinus Torvalds spin_lock_irqsave(&card->cmd_lock, flags); 29121da177e4SLinus Torvalds writel(SAR_CMD_CLOSE_CONNECTION | (addr << 2), 29131da177e4SLinus Torvalds SAR_REG_CMD); 29141da177e4SLinus Torvalds waitfor_idle(card); 29151da177e4SLinus Torvalds spin_unlock_irqrestore(&card->cmd_lock, flags); 29161da177e4SLinus Torvalds 2917ceade961SDavid S. Miller if (skb_queue_len(&vc->rcv.rx_pool.queue) != 0) { 29181da177e4SLinus Torvalds DPRINTK("%s: closing a VC " 29191da177e4SLinus Torvalds "with pending rx buffers.\n", 29201da177e4SLinus Torvalds card->name); 29211da177e4SLinus Torvalds 29221da177e4SLinus Torvalds recycle_rx_pool_skb(card, &vc->rcv.rx_pool); 29231da177e4SLinus Torvalds } 29241da177e4SLinus Torvalds } 29251da177e4SLinus Torvalds } 29261da177e4SLinus Torvalds } 29271da177e4SLinus Torvalds 29281da177e4SLinus Torvalds static int 29291da177e4SLinus Torvalds open_card_ubr0(struct idt77252_dev *card) 29301da177e4SLinus Torvalds { 29311da177e4SLinus Torvalds struct vc_map *vc; 29321da177e4SLinus Torvalds 29330c1cca1dSOm Narasimhan vc = kzalloc(sizeof(struct vc_map), GFP_KERNEL); 29341da177e4SLinus Torvalds if (!vc) { 29351da177e4SLinus Torvalds printk("%s: can't alloc vc\n", card->name); 29361da177e4SLinus Torvalds return -ENOMEM; 29371da177e4SLinus Torvalds } 29381da177e4SLinus Torvalds card->vcs[0] = vc; 29391da177e4SLinus Torvalds vc->class = SCHED_UBR0; 29401da177e4SLinus Torvalds 29411da177e4SLinus Torvalds vc->scq = alloc_scq(card, vc->class); 29421da177e4SLinus Torvalds if (!vc->scq) { 29431da177e4SLinus Torvalds printk("%s: can't get SCQ.\n", card->name); 29441da177e4SLinus Torvalds return -ENOMEM; 29451da177e4SLinus Torvalds } 29461da177e4SLinus Torvalds 29471da177e4SLinus Torvalds card->scd2vc[0] = vc; 29481da177e4SLinus Torvalds vc->scd_index = 0; 29491da177e4SLinus Torvalds vc->scq->scd = card->scd_base; 29501da177e4SLinus Torvalds 29511da177e4SLinus Torvalds fill_scd(card, vc->scq, vc->class); 29521da177e4SLinus Torvalds 29531da177e4SLinus Torvalds write_sram(card, card->tct_base + 0, TCT_UBR | card->scd_base); 29541da177e4SLinus Torvalds write_sram(card, card->tct_base + 1, 0); 29551da177e4SLinus Torvalds write_sram(card, card->tct_base + 2, 0); 29561da177e4SLinus Torvalds write_sram(card, card->tct_base + 3, 0); 29571da177e4SLinus Torvalds write_sram(card, card->tct_base + 4, 0); 29581da177e4SLinus Torvalds write_sram(card, card->tct_base + 5, 0); 29591da177e4SLinus Torvalds write_sram(card, card->tct_base + 6, 0); 29601da177e4SLinus Torvalds write_sram(card, card->tct_base + 7, TCT_FLAG_UBR); 29611da177e4SLinus Torvalds 29621da177e4SLinus Torvalds clear_bit(VCF_IDLE, &vc->flags); 29631da177e4SLinus Torvalds writel(TCMDQ_START | 0, SAR_REG_TCMDQ); 29641da177e4SLinus Torvalds return 0; 29651da177e4SLinus Torvalds } 29661da177e4SLinus Torvalds 29671da177e4SLinus Torvalds static int 29681da177e4SLinus Torvalds idt77252_dev_open(struct idt77252_dev *card) 29691da177e4SLinus Torvalds { 29701da177e4SLinus Torvalds u32 conf; 29711da177e4SLinus Torvalds 29721da177e4SLinus Torvalds if (!test_bit(IDT77252_BIT_INIT, &card->flags)) { 29731da177e4SLinus Torvalds printk("%s: SAR not yet initialized.\n", card->name); 29741da177e4SLinus Torvalds return -1; 29751da177e4SLinus Torvalds } 29761da177e4SLinus Torvalds 29771da177e4SLinus Torvalds conf = SAR_CFG_RXPTH| /* enable receive path */ 29781da177e4SLinus Torvalds SAR_RX_DELAY | /* interrupt on complete PDU */ 29791da177e4SLinus Torvalds SAR_CFG_RAWIE | /* interrupt enable on raw cells */ 29801da177e4SLinus Torvalds SAR_CFG_RQFIE | /* interrupt on RSQ almost full */ 29811da177e4SLinus Torvalds SAR_CFG_TMOIE | /* interrupt on timer overflow */ 29821da177e4SLinus Torvalds SAR_CFG_FBIE | /* interrupt on low free buffers */ 29831da177e4SLinus Torvalds SAR_CFG_TXEN | /* transmit operation enable */ 29841da177e4SLinus Torvalds SAR_CFG_TXINT | /* interrupt on transmit status */ 29851da177e4SLinus Torvalds SAR_CFG_TXUIE | /* interrupt on transmit underrun */ 29861da177e4SLinus Torvalds SAR_CFG_TXSFI | /* interrupt on TSQ almost full */ 29871da177e4SLinus Torvalds SAR_CFG_PHYIE /* enable PHY interrupts */ 29881da177e4SLinus Torvalds ; 29891da177e4SLinus Torvalds 29901da177e4SLinus Torvalds #ifdef CONFIG_ATM_IDT77252_RCV_ALL 29911da177e4SLinus Torvalds /* Test RAW cell receive. */ 29921da177e4SLinus Torvalds conf |= SAR_CFG_VPECA; 29931da177e4SLinus Torvalds #endif 29941da177e4SLinus Torvalds 29951da177e4SLinus Torvalds writel(readl(SAR_REG_CFG) | conf, SAR_REG_CFG); 29961da177e4SLinus Torvalds 29971da177e4SLinus Torvalds if (open_card_oam(card)) { 29981da177e4SLinus Torvalds printk("%s: Error initializing OAM.\n", card->name); 29991da177e4SLinus Torvalds return -1; 30001da177e4SLinus Torvalds } 30011da177e4SLinus Torvalds 30021da177e4SLinus Torvalds if (open_card_ubr0(card)) { 30031da177e4SLinus Torvalds printk("%s: Error initializing UBR0.\n", card->name); 30041da177e4SLinus Torvalds return -1; 30051da177e4SLinus Torvalds } 30061da177e4SLinus Torvalds 30071da177e4SLinus Torvalds IPRINTK("%s: opened IDT77252 ABR SAR.\n", card->name); 30081da177e4SLinus Torvalds return 0; 30091da177e4SLinus Torvalds } 30101da177e4SLinus Torvalds 3011f4c4b4a6SAdrian Bunk static void idt77252_dev_close(struct atm_dev *dev) 30121da177e4SLinus Torvalds { 30131da177e4SLinus Torvalds struct idt77252_dev *card = dev->dev_data; 30141da177e4SLinus Torvalds u32 conf; 30151da177e4SLinus Torvalds 30161da177e4SLinus Torvalds close_card_oam(card); 30171da177e4SLinus Torvalds 30181da177e4SLinus Torvalds conf = SAR_CFG_RXPTH | /* enable receive path */ 30191da177e4SLinus Torvalds SAR_RX_DELAY | /* interrupt on complete PDU */ 30201da177e4SLinus Torvalds SAR_CFG_RAWIE | /* interrupt enable on raw cells */ 30211da177e4SLinus Torvalds SAR_CFG_RQFIE | /* interrupt on RSQ almost full */ 30221da177e4SLinus Torvalds SAR_CFG_TMOIE | /* interrupt on timer overflow */ 30231da177e4SLinus Torvalds SAR_CFG_FBIE | /* interrupt on low free buffers */ 30241da177e4SLinus Torvalds SAR_CFG_TXEN | /* transmit operation enable */ 30251da177e4SLinus Torvalds SAR_CFG_TXINT | /* interrupt on transmit status */ 30261da177e4SLinus Torvalds SAR_CFG_TXUIE | /* interrupt on xmit underrun */ 30271da177e4SLinus Torvalds SAR_CFG_TXSFI /* interrupt on TSQ almost full */ 30281da177e4SLinus Torvalds ; 30291da177e4SLinus Torvalds 30301da177e4SLinus Torvalds writel(readl(SAR_REG_CFG) & ~(conf), SAR_REG_CFG); 30311da177e4SLinus Torvalds 30321da177e4SLinus Torvalds DIPRINTK("%s: closed IDT77252 ABR SAR.\n", card->name); 30331da177e4SLinus Torvalds } 30341da177e4SLinus Torvalds 30351da177e4SLinus Torvalds 30361da177e4SLinus Torvalds /*****************************************************************************/ 30371da177e4SLinus Torvalds /* */ 30381da177e4SLinus Torvalds /* Initialisation and Deinitialization of IDT77252 */ 30391da177e4SLinus Torvalds /* */ 30401da177e4SLinus Torvalds /*****************************************************************************/ 30411da177e4SLinus Torvalds 30421da177e4SLinus Torvalds 30431da177e4SLinus Torvalds static void 30441da177e4SLinus Torvalds deinit_card(struct idt77252_dev *card) 30451da177e4SLinus Torvalds { 30461da177e4SLinus Torvalds struct sk_buff *skb; 30471da177e4SLinus Torvalds int i, j; 30481da177e4SLinus Torvalds 30491da177e4SLinus Torvalds if (!test_bit(IDT77252_BIT_INIT, &card->flags)) { 30501da177e4SLinus Torvalds printk("%s: SAR not yet initialized.\n", card->name); 30511da177e4SLinus Torvalds return; 30521da177e4SLinus Torvalds } 30531da177e4SLinus Torvalds DIPRINTK("idt77252: deinitialize card %u\n", card->index); 30541da177e4SLinus Torvalds 30551da177e4SLinus Torvalds writel(0, SAR_REG_CFG); 30561da177e4SLinus Torvalds 30571da177e4SLinus Torvalds if (card->atmdev) 30581da177e4SLinus Torvalds atm_dev_deregister(card->atmdev); 30591da177e4SLinus Torvalds 30601da177e4SLinus Torvalds for (i = 0; i < 4; i++) { 30611da177e4SLinus Torvalds for (j = 0; j < FBQ_SIZE; j++) { 30621da177e4SLinus Torvalds skb = card->sbpool[i].skb[j]; 30631da177e4SLinus Torvalds if (skb) { 30641da177e4SLinus Torvalds pci_unmap_single(card->pcidev, 30651da177e4SLinus Torvalds IDT77252_PRV_PADDR(skb), 30664305b541SArnaldo Carvalho de Melo (skb_end_pointer(skb) - 30674305b541SArnaldo Carvalho de Melo skb->data), 30681da177e4SLinus Torvalds PCI_DMA_FROMDEVICE); 30691da177e4SLinus Torvalds card->sbpool[i].skb[j] = NULL; 30701da177e4SLinus Torvalds dev_kfree_skb(skb); 30711da177e4SLinus Torvalds } 30721da177e4SLinus Torvalds } 30731da177e4SLinus Torvalds } 30741da177e4SLinus Torvalds 30751da177e4SLinus Torvalds vfree(card->soft_tst); 30761da177e4SLinus Torvalds 30771da177e4SLinus Torvalds vfree(card->scd2vc); 30781da177e4SLinus Torvalds 30791da177e4SLinus Torvalds vfree(card->vcs); 30801da177e4SLinus Torvalds 30811da177e4SLinus Torvalds if (card->raw_cell_hnd) { 30821da177e4SLinus Torvalds pci_free_consistent(card->pcidev, 2 * sizeof(u32), 30831da177e4SLinus Torvalds card->raw_cell_hnd, card->raw_cell_paddr); 30841da177e4SLinus Torvalds } 30851da177e4SLinus Torvalds 30861da177e4SLinus Torvalds if (card->rsq.base) { 30871da177e4SLinus Torvalds DIPRINTK("%s: Release RSQ ...\n", card->name); 30881da177e4SLinus Torvalds deinit_rsq(card); 30891da177e4SLinus Torvalds } 30901da177e4SLinus Torvalds 30911da177e4SLinus Torvalds if (card->tsq.base) { 30921da177e4SLinus Torvalds DIPRINTK("%s: Release TSQ ...\n", card->name); 30931da177e4SLinus Torvalds deinit_tsq(card); 30941da177e4SLinus Torvalds } 30951da177e4SLinus Torvalds 30961da177e4SLinus Torvalds DIPRINTK("idt77252: Release IRQ.\n"); 30971da177e4SLinus Torvalds free_irq(card->pcidev->irq, card); 30981da177e4SLinus Torvalds 30991da177e4SLinus Torvalds for (i = 0; i < 4; i++) { 31001da177e4SLinus Torvalds if (card->fbq[i]) 31011da177e4SLinus Torvalds iounmap(card->fbq[i]); 31021da177e4SLinus Torvalds } 31031da177e4SLinus Torvalds 31041da177e4SLinus Torvalds if (card->membase) 31051da177e4SLinus Torvalds iounmap(card->membase); 31061da177e4SLinus Torvalds 31071da177e4SLinus Torvalds clear_bit(IDT77252_BIT_INIT, &card->flags); 31081da177e4SLinus Torvalds DIPRINTK("%s: Card deinitialized.\n", card->name); 31091da177e4SLinus Torvalds } 31101da177e4SLinus Torvalds 31111da177e4SLinus Torvalds 31121790c228SJulia Lawall static void __devinit 31131da177e4SLinus Torvalds init_sram(struct idt77252_dev *card) 31141da177e4SLinus Torvalds { 31151da177e4SLinus Torvalds int i; 31161da177e4SLinus Torvalds 31171da177e4SLinus Torvalds for (i = 0; i < card->sramsize; i += 4) 31181da177e4SLinus Torvalds write_sram(card, (i >> 2), 0); 31191da177e4SLinus Torvalds 31201da177e4SLinus Torvalds /* set SRAM layout for THIS card */ 31211da177e4SLinus Torvalds if (card->sramsize == (512 * 1024)) { 31221da177e4SLinus Torvalds card->tct_base = SAR_SRAM_TCT_128_BASE; 31231da177e4SLinus Torvalds card->tct_size = (SAR_SRAM_TCT_128_TOP - card->tct_base + 1) 31241da177e4SLinus Torvalds / SAR_SRAM_TCT_SIZE; 31251da177e4SLinus Torvalds card->rct_base = SAR_SRAM_RCT_128_BASE; 31261da177e4SLinus Torvalds card->rct_size = (SAR_SRAM_RCT_128_TOP - card->rct_base + 1) 31271da177e4SLinus Torvalds / SAR_SRAM_RCT_SIZE; 31281da177e4SLinus Torvalds card->rt_base = SAR_SRAM_RT_128_BASE; 31291da177e4SLinus Torvalds card->scd_base = SAR_SRAM_SCD_128_BASE; 31301da177e4SLinus Torvalds card->scd_size = (SAR_SRAM_SCD_128_TOP - card->scd_base + 1) 31311da177e4SLinus Torvalds / SAR_SRAM_SCD_SIZE; 31321da177e4SLinus Torvalds card->tst[0] = SAR_SRAM_TST1_128_BASE; 31331da177e4SLinus Torvalds card->tst[1] = SAR_SRAM_TST2_128_BASE; 31341da177e4SLinus Torvalds card->tst_size = SAR_SRAM_TST1_128_TOP - card->tst[0] + 1; 31351da177e4SLinus Torvalds card->abrst_base = SAR_SRAM_ABRSTD_128_BASE; 31361da177e4SLinus Torvalds card->abrst_size = SAR_ABRSTD_SIZE_8K; 31371da177e4SLinus Torvalds card->fifo_base = SAR_SRAM_FIFO_128_BASE; 31381da177e4SLinus Torvalds card->fifo_size = SAR_RXFD_SIZE_32K; 31391da177e4SLinus Torvalds } else { 31401da177e4SLinus Torvalds card->tct_base = SAR_SRAM_TCT_32_BASE; 31411da177e4SLinus Torvalds card->tct_size = (SAR_SRAM_TCT_32_TOP - card->tct_base + 1) 31421da177e4SLinus Torvalds / SAR_SRAM_TCT_SIZE; 31431da177e4SLinus Torvalds card->rct_base = SAR_SRAM_RCT_32_BASE; 31441da177e4SLinus Torvalds card->rct_size = (SAR_SRAM_RCT_32_TOP - card->rct_base + 1) 31451da177e4SLinus Torvalds / SAR_SRAM_RCT_SIZE; 31461da177e4SLinus Torvalds card->rt_base = SAR_SRAM_RT_32_BASE; 31471da177e4SLinus Torvalds card->scd_base = SAR_SRAM_SCD_32_BASE; 31481da177e4SLinus Torvalds card->scd_size = (SAR_SRAM_SCD_32_TOP - card->scd_base + 1) 31491da177e4SLinus Torvalds / SAR_SRAM_SCD_SIZE; 31501da177e4SLinus Torvalds card->tst[0] = SAR_SRAM_TST1_32_BASE; 31511da177e4SLinus Torvalds card->tst[1] = SAR_SRAM_TST2_32_BASE; 31521da177e4SLinus Torvalds card->tst_size = (SAR_SRAM_TST1_32_TOP - card->tst[0] + 1); 31531da177e4SLinus Torvalds card->abrst_base = SAR_SRAM_ABRSTD_32_BASE; 31541da177e4SLinus Torvalds card->abrst_size = SAR_ABRSTD_SIZE_1K; 31551da177e4SLinus Torvalds card->fifo_base = SAR_SRAM_FIFO_32_BASE; 31561da177e4SLinus Torvalds card->fifo_size = SAR_RXFD_SIZE_4K; 31571da177e4SLinus Torvalds } 31581da177e4SLinus Torvalds 31591da177e4SLinus Torvalds /* Initialize TCT */ 31601da177e4SLinus Torvalds for (i = 0; i < card->tct_size; i++) { 31611da177e4SLinus Torvalds write_sram(card, i * SAR_SRAM_TCT_SIZE + 0, 0); 31621da177e4SLinus Torvalds write_sram(card, i * SAR_SRAM_TCT_SIZE + 1, 0); 31631da177e4SLinus Torvalds write_sram(card, i * SAR_SRAM_TCT_SIZE + 2, 0); 31641da177e4SLinus Torvalds write_sram(card, i * SAR_SRAM_TCT_SIZE + 3, 0); 31651da177e4SLinus Torvalds write_sram(card, i * SAR_SRAM_TCT_SIZE + 4, 0); 31661da177e4SLinus Torvalds write_sram(card, i * SAR_SRAM_TCT_SIZE + 5, 0); 31671da177e4SLinus Torvalds write_sram(card, i * SAR_SRAM_TCT_SIZE + 6, 0); 31681da177e4SLinus Torvalds write_sram(card, i * SAR_SRAM_TCT_SIZE + 7, 0); 31691da177e4SLinus Torvalds } 31701da177e4SLinus Torvalds 31711da177e4SLinus Torvalds /* Initialize RCT */ 31721da177e4SLinus Torvalds for (i = 0; i < card->rct_size; i++) { 31731da177e4SLinus Torvalds write_sram(card, card->rct_base + i * SAR_SRAM_RCT_SIZE, 31741da177e4SLinus Torvalds (u32) SAR_RCTE_RAWCELLINTEN); 31751da177e4SLinus Torvalds write_sram(card, card->rct_base + i * SAR_SRAM_RCT_SIZE + 1, 31761da177e4SLinus Torvalds (u32) 0); 31771da177e4SLinus Torvalds write_sram(card, card->rct_base + i * SAR_SRAM_RCT_SIZE + 2, 31781da177e4SLinus Torvalds (u32) 0); 31791da177e4SLinus Torvalds write_sram(card, card->rct_base + i * SAR_SRAM_RCT_SIZE + 3, 31801da177e4SLinus Torvalds (u32) 0xffffffff); 31811da177e4SLinus Torvalds } 31821da177e4SLinus Torvalds 31831da177e4SLinus Torvalds writel((SAR_FBQ0_LOW << 28) | 0x00000000 | 0x00000000 | 31841da177e4SLinus Torvalds (SAR_FB_SIZE_0 / 48), SAR_REG_FBQS0); 31851da177e4SLinus Torvalds writel((SAR_FBQ1_LOW << 28) | 0x00000000 | 0x00000000 | 31861da177e4SLinus Torvalds (SAR_FB_SIZE_1 / 48), SAR_REG_FBQS1); 31871da177e4SLinus Torvalds writel((SAR_FBQ2_LOW << 28) | 0x00000000 | 0x00000000 | 31881da177e4SLinus Torvalds (SAR_FB_SIZE_2 / 48), SAR_REG_FBQS2); 31891da177e4SLinus Torvalds writel((SAR_FBQ3_LOW << 28) | 0x00000000 | 0x00000000 | 31901da177e4SLinus Torvalds (SAR_FB_SIZE_3 / 48), SAR_REG_FBQS3); 31911da177e4SLinus Torvalds 31921da177e4SLinus Torvalds /* Initialize rate table */ 31931da177e4SLinus Torvalds for (i = 0; i < 256; i++) { 31941da177e4SLinus Torvalds write_sram(card, card->rt_base + i, log_to_rate[i]); 31951da177e4SLinus Torvalds } 31961da177e4SLinus Torvalds 31971da177e4SLinus Torvalds for (i = 0; i < 128; i++) { 31981da177e4SLinus Torvalds unsigned int tmp; 31991da177e4SLinus Torvalds 32001da177e4SLinus Torvalds tmp = rate_to_log[(i << 2) + 0] << 0; 32011da177e4SLinus Torvalds tmp |= rate_to_log[(i << 2) + 1] << 8; 32021da177e4SLinus Torvalds tmp |= rate_to_log[(i << 2) + 2] << 16; 32031da177e4SLinus Torvalds tmp |= rate_to_log[(i << 2) + 3] << 24; 32041da177e4SLinus Torvalds write_sram(card, card->rt_base + 256 + i, tmp); 32051da177e4SLinus Torvalds } 32061da177e4SLinus Torvalds 32071da177e4SLinus Torvalds #if 0 /* Fill RDF and AIR tables. */ 32081da177e4SLinus Torvalds for (i = 0; i < 128; i++) { 32091da177e4SLinus Torvalds unsigned int tmp; 32101da177e4SLinus Torvalds 32111da177e4SLinus Torvalds tmp = RDF[0][(i << 1) + 0] << 16; 32121da177e4SLinus Torvalds tmp |= RDF[0][(i << 1) + 1] << 0; 32131da177e4SLinus Torvalds write_sram(card, card->rt_base + 512 + i, tmp); 32141da177e4SLinus Torvalds } 32151da177e4SLinus Torvalds 32161da177e4SLinus Torvalds for (i = 0; i < 128; i++) { 32171da177e4SLinus Torvalds unsigned int tmp; 32181da177e4SLinus Torvalds 32191da177e4SLinus Torvalds tmp = AIR[0][(i << 1) + 0] << 16; 32201da177e4SLinus Torvalds tmp |= AIR[0][(i << 1) + 1] << 0; 32211da177e4SLinus Torvalds write_sram(card, card->rt_base + 640 + i, tmp); 32221da177e4SLinus Torvalds } 32231da177e4SLinus Torvalds #endif 32241da177e4SLinus Torvalds 32251da177e4SLinus Torvalds IPRINTK("%s: initialize rate table ...\n", card->name); 32261da177e4SLinus Torvalds writel(card->rt_base << 2, SAR_REG_RTBL); 32271da177e4SLinus Torvalds 32281da177e4SLinus Torvalds /* Initialize TSTs */ 32291da177e4SLinus Torvalds IPRINTK("%s: initialize TST ...\n", card->name); 32301da177e4SLinus Torvalds card->tst_free = card->tst_size - 2; /* last two are jumps */ 32311da177e4SLinus Torvalds 32321da177e4SLinus Torvalds for (i = card->tst[0]; i < card->tst[0] + card->tst_size - 2; i++) 32331da177e4SLinus Torvalds write_sram(card, i, TSTE_OPC_VAR); 32341da177e4SLinus Torvalds write_sram(card, i++, TSTE_OPC_JMP | (card->tst[0] << 2)); 32351da177e4SLinus Torvalds idt77252_sram_write_errors = 1; 32361da177e4SLinus Torvalds write_sram(card, i++, TSTE_OPC_JMP | (card->tst[1] << 2)); 32371da177e4SLinus Torvalds idt77252_sram_write_errors = 0; 32381da177e4SLinus Torvalds for (i = card->tst[1]; i < card->tst[1] + card->tst_size - 2; i++) 32391da177e4SLinus Torvalds write_sram(card, i, TSTE_OPC_VAR); 32401da177e4SLinus Torvalds write_sram(card, i++, TSTE_OPC_JMP | (card->tst[1] << 2)); 32411da177e4SLinus Torvalds idt77252_sram_write_errors = 1; 32421da177e4SLinus Torvalds write_sram(card, i++, TSTE_OPC_JMP | (card->tst[0] << 2)); 32431da177e4SLinus Torvalds idt77252_sram_write_errors = 0; 32441da177e4SLinus Torvalds 32451da177e4SLinus Torvalds card->tst_index = 0; 32461da177e4SLinus Torvalds writel(card->tst[0] << 2, SAR_REG_TSTB); 32471da177e4SLinus Torvalds 32481da177e4SLinus Torvalds /* Initialize ABRSTD and Receive FIFO */ 32491da177e4SLinus Torvalds IPRINTK("%s: initialize ABRSTD ...\n", card->name); 32501da177e4SLinus Torvalds writel(card->abrst_size | (card->abrst_base << 2), 32511da177e4SLinus Torvalds SAR_REG_ABRSTD); 32521da177e4SLinus Torvalds 32531da177e4SLinus Torvalds IPRINTK("%s: initialize receive fifo ...\n", card->name); 32541da177e4SLinus Torvalds writel(card->fifo_size | (card->fifo_base << 2), 32551da177e4SLinus Torvalds SAR_REG_RXFD); 32561da177e4SLinus Torvalds 32571da177e4SLinus Torvalds IPRINTK("%s: SRAM initialization complete.\n", card->name); 32581da177e4SLinus Torvalds } 32591da177e4SLinus Torvalds 32601da177e4SLinus Torvalds static int __devinit 32611da177e4SLinus Torvalds init_card(struct atm_dev *dev) 32621da177e4SLinus Torvalds { 32631da177e4SLinus Torvalds struct idt77252_dev *card = dev->dev_data; 32641da177e4SLinus Torvalds struct pci_dev *pcidev = card->pcidev; 32651da177e4SLinus Torvalds unsigned long tmpl, modl; 32661da177e4SLinus Torvalds unsigned int linkrate, rsvdcr; 32671da177e4SLinus Torvalds unsigned int tst_entries; 32681da177e4SLinus Torvalds struct net_device *tmp; 32691da177e4SLinus Torvalds char tname[10]; 32701da177e4SLinus Torvalds 32711da177e4SLinus Torvalds u32 size; 32721da177e4SLinus Torvalds u_char pci_byte; 32731da177e4SLinus Torvalds u32 conf; 32741da177e4SLinus Torvalds int i, k; 32751da177e4SLinus Torvalds 32761da177e4SLinus Torvalds if (test_bit(IDT77252_BIT_INIT, &card->flags)) { 32771da177e4SLinus Torvalds printk("Error: SAR already initialized.\n"); 32781da177e4SLinus Torvalds return -1; 32791da177e4SLinus Torvalds } 32801da177e4SLinus Torvalds 32811da177e4SLinus Torvalds /*****************************************************************/ 32821da177e4SLinus Torvalds /* P C I C O N F I G U R A T I O N */ 32831da177e4SLinus Torvalds /*****************************************************************/ 32841da177e4SLinus Torvalds 32851da177e4SLinus Torvalds /* Set PCI Retry-Timeout and TRDY timeout */ 32861da177e4SLinus Torvalds IPRINTK("%s: Checking PCI retries.\n", card->name); 32871da177e4SLinus Torvalds if (pci_read_config_byte(pcidev, 0x40, &pci_byte) != 0) { 32881da177e4SLinus Torvalds printk("%s: can't read PCI retry timeout.\n", card->name); 32891da177e4SLinus Torvalds deinit_card(card); 32901da177e4SLinus Torvalds return -1; 32911da177e4SLinus Torvalds } 32921da177e4SLinus Torvalds if (pci_byte != 0) { 32931da177e4SLinus Torvalds IPRINTK("%s: PCI retry timeout: %d, set to 0.\n", 32941da177e4SLinus Torvalds card->name, pci_byte); 32951da177e4SLinus Torvalds if (pci_write_config_byte(pcidev, 0x40, 0) != 0) { 32961da177e4SLinus Torvalds printk("%s: can't set PCI retry timeout.\n", 32971da177e4SLinus Torvalds card->name); 32981da177e4SLinus Torvalds deinit_card(card); 32991da177e4SLinus Torvalds return -1; 33001da177e4SLinus Torvalds } 33011da177e4SLinus Torvalds } 33021da177e4SLinus Torvalds IPRINTK("%s: Checking PCI TRDY.\n", card->name); 33031da177e4SLinus Torvalds if (pci_read_config_byte(pcidev, 0x41, &pci_byte) != 0) { 33041da177e4SLinus Torvalds printk("%s: can't read PCI TRDY timeout.\n", card->name); 33051da177e4SLinus Torvalds deinit_card(card); 33061da177e4SLinus Torvalds return -1; 33071da177e4SLinus Torvalds } 33081da177e4SLinus Torvalds if (pci_byte != 0) { 33091da177e4SLinus Torvalds IPRINTK("%s: PCI TRDY timeout: %d, set to 0.\n", 33101da177e4SLinus Torvalds card->name, pci_byte); 33111da177e4SLinus Torvalds if (pci_write_config_byte(pcidev, 0x41, 0) != 0) { 33121da177e4SLinus Torvalds printk("%s: can't set PCI TRDY timeout.\n", card->name); 33131da177e4SLinus Torvalds deinit_card(card); 33141da177e4SLinus Torvalds return -1; 33151da177e4SLinus Torvalds } 33161da177e4SLinus Torvalds } 33171da177e4SLinus Torvalds /* Reset Timer register */ 33181da177e4SLinus Torvalds if (readl(SAR_REG_STAT) & SAR_STAT_TMROF) { 33191da177e4SLinus Torvalds printk("%s: resetting timer overflow.\n", card->name); 33201da177e4SLinus Torvalds writel(SAR_STAT_TMROF, SAR_REG_STAT); 33211da177e4SLinus Torvalds } 33221da177e4SLinus Torvalds IPRINTK("%s: Request IRQ ... ", card->name); 332306df277aSchas williams - CONTRACTOR if (request_irq(pcidev->irq, idt77252_interrupt, IRQF_SHARED, 33241da177e4SLinus Torvalds card->name, card) != 0) { 33251da177e4SLinus Torvalds printk("%s: can't allocate IRQ.\n", card->name); 33261da177e4SLinus Torvalds deinit_card(card); 33271da177e4SLinus Torvalds return -1; 33281da177e4SLinus Torvalds } 33291da177e4SLinus Torvalds IPRINTK("got %d.\n", pcidev->irq); 33301da177e4SLinus Torvalds 33311da177e4SLinus Torvalds /*****************************************************************/ 33321da177e4SLinus Torvalds /* C H E C K A N D I N I T S R A M */ 33331da177e4SLinus Torvalds /*****************************************************************/ 33341da177e4SLinus Torvalds 33351da177e4SLinus Torvalds IPRINTK("%s: Initializing SRAM\n", card->name); 33361da177e4SLinus Torvalds 33371da177e4SLinus Torvalds /* preset size of connecton table, so that init_sram() knows about it */ 33381da177e4SLinus Torvalds conf = SAR_CFG_TX_FIFO_SIZE_9 | /* Use maximum fifo size */ 33391da177e4SLinus Torvalds SAR_CFG_RXSTQ_SIZE_8k | /* Receive Status Queue is 8k */ 33401da177e4SLinus Torvalds SAR_CFG_IDLE_CLP | /* Set CLP on idle cells */ 334144beac00SRobert P. J. Day #ifndef ATM_IDT77252_SEND_IDLE 33421da177e4SLinus Torvalds SAR_CFG_NO_IDLE | /* Do not send idle cells */ 33431da177e4SLinus Torvalds #endif 33441da177e4SLinus Torvalds 0; 33451da177e4SLinus Torvalds 33461da177e4SLinus Torvalds if (card->sramsize == (512 * 1024)) 33471da177e4SLinus Torvalds conf |= SAR_CFG_CNTBL_1k; 33481da177e4SLinus Torvalds else 33491da177e4SLinus Torvalds conf |= SAR_CFG_CNTBL_512; 33501da177e4SLinus Torvalds 33511da177e4SLinus Torvalds switch (vpibits) { 33521da177e4SLinus Torvalds case 0: 33531da177e4SLinus Torvalds conf |= SAR_CFG_VPVCS_0; 33541da177e4SLinus Torvalds break; 33551da177e4SLinus Torvalds default: 33561da177e4SLinus Torvalds case 1: 33571da177e4SLinus Torvalds conf |= SAR_CFG_VPVCS_1; 33581da177e4SLinus Torvalds break; 33591da177e4SLinus Torvalds case 2: 33601da177e4SLinus Torvalds conf |= SAR_CFG_VPVCS_2; 33611da177e4SLinus Torvalds break; 33621da177e4SLinus Torvalds case 8: 33631da177e4SLinus Torvalds conf |= SAR_CFG_VPVCS_8; 33641da177e4SLinus Torvalds break; 33651da177e4SLinus Torvalds } 33661da177e4SLinus Torvalds 33671da177e4SLinus Torvalds writel(readl(SAR_REG_CFG) | conf, SAR_REG_CFG); 33681da177e4SLinus Torvalds 33691790c228SJulia Lawall init_sram(card); 33701da177e4SLinus Torvalds 33711da177e4SLinus Torvalds /********************************************************************/ 33721da177e4SLinus 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 */ 33731da177e4SLinus Torvalds /********************************************************************/ 33741da177e4SLinus Torvalds /* Initialize TSQ */ 33751da177e4SLinus Torvalds if (0 != init_tsq(card)) { 33761da177e4SLinus Torvalds deinit_card(card); 33771da177e4SLinus Torvalds return -1; 33781da177e4SLinus Torvalds } 33791da177e4SLinus Torvalds /* Initialize RSQ */ 33801da177e4SLinus Torvalds if (0 != init_rsq(card)) { 33811da177e4SLinus Torvalds deinit_card(card); 33821da177e4SLinus Torvalds return -1; 33831da177e4SLinus Torvalds } 33841da177e4SLinus Torvalds 33851da177e4SLinus Torvalds card->vpibits = vpibits; 33861da177e4SLinus Torvalds if (card->sramsize == (512 * 1024)) { 33871da177e4SLinus Torvalds card->vcibits = 10 - card->vpibits; 33881da177e4SLinus Torvalds } else { 33891da177e4SLinus Torvalds card->vcibits = 9 - card->vpibits; 33901da177e4SLinus Torvalds } 33911da177e4SLinus Torvalds 33921da177e4SLinus Torvalds card->vcimask = 0; 33931da177e4SLinus Torvalds for (k = 0, i = 1; k < card->vcibits; k++) { 33941da177e4SLinus Torvalds card->vcimask |= i; 33951da177e4SLinus Torvalds i <<= 1; 33961da177e4SLinus Torvalds } 33971da177e4SLinus Torvalds 33981da177e4SLinus Torvalds IPRINTK("%s: Setting VPI/VCI mask to zero.\n", card->name); 33991da177e4SLinus Torvalds writel(0, SAR_REG_VPM); 34001da177e4SLinus Torvalds 34011da177e4SLinus Torvalds /* Little Endian Order */ 34021da177e4SLinus Torvalds writel(0, SAR_REG_GP); 34031da177e4SLinus Torvalds 34041da177e4SLinus Torvalds /* Initialize RAW Cell Handle Register */ 34051da177e4SLinus Torvalds card->raw_cell_hnd = pci_alloc_consistent(card->pcidev, 2 * sizeof(u32), 34061da177e4SLinus Torvalds &card->raw_cell_paddr); 34071da177e4SLinus Torvalds if (!card->raw_cell_hnd) { 34081da177e4SLinus Torvalds printk("%s: memory allocation failure.\n", card->name); 34091da177e4SLinus Torvalds deinit_card(card); 34101da177e4SLinus Torvalds return -1; 34111da177e4SLinus Torvalds } 34121da177e4SLinus Torvalds memset(card->raw_cell_hnd, 0, 2 * sizeof(u32)); 34131da177e4SLinus Torvalds writel(card->raw_cell_paddr, SAR_REG_RAWHND); 34141da177e4SLinus Torvalds IPRINTK("%s: raw cell handle is at 0x%p.\n", card->name, 34151da177e4SLinus Torvalds card->raw_cell_hnd); 34161da177e4SLinus Torvalds 34171da177e4SLinus Torvalds size = sizeof(struct vc_map *) * card->tct_size; 34181da177e4SLinus Torvalds IPRINTK("%s: allocate %d byte for VC map.\n", card->name, size); 3419*3a816054SJoe Perches card->vcs = vzalloc(size); 3420*3a816054SJoe Perches if (!card->vcs) { 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 vc_map *) * card->scd_size; 34271da177e4SLinus Torvalds IPRINTK("%s: allocate %d byte for SCD to VC mapping.\n", 34281da177e4SLinus Torvalds card->name, size); 3429*3a816054SJoe Perches card->scd2vc = vzalloc(size); 3430*3a816054SJoe Perches if (!card->scd2vc) { 34311da177e4SLinus Torvalds printk("%s: memory allocation failure.\n", card->name); 34321da177e4SLinus Torvalds deinit_card(card); 34331da177e4SLinus Torvalds return -1; 34341da177e4SLinus Torvalds } 34351da177e4SLinus Torvalds 34361da177e4SLinus Torvalds size = sizeof(struct tst_info) * (card->tst_size - 2); 34371da177e4SLinus Torvalds IPRINTK("%s: allocate %d byte for TST to VC mapping.\n", 34381da177e4SLinus Torvalds card->name, size); 3439*3a816054SJoe Perches card->soft_tst = vmalloc(size); 3440*3a816054SJoe Perches if (!card->soft_tst) { 34411da177e4SLinus Torvalds printk("%s: memory allocation failure.\n", card->name); 34421da177e4SLinus Torvalds deinit_card(card); 34431da177e4SLinus Torvalds return -1; 34441da177e4SLinus Torvalds } 34451da177e4SLinus Torvalds for (i = 0; i < card->tst_size - 2; i++) { 34461da177e4SLinus Torvalds card->soft_tst[i].tste = TSTE_OPC_VAR; 34471da177e4SLinus Torvalds card->soft_tst[i].vc = NULL; 34481da177e4SLinus Torvalds } 34491da177e4SLinus Torvalds 34501da177e4SLinus Torvalds if (dev->phy == NULL) { 34511da177e4SLinus Torvalds printk("%s: No LT device defined.\n", card->name); 34521da177e4SLinus Torvalds deinit_card(card); 34531da177e4SLinus Torvalds return -1; 34541da177e4SLinus Torvalds } 34551da177e4SLinus Torvalds if (dev->phy->ioctl == NULL) { 345625985edcSLucas De Marchi printk("%s: LT had no IOCTL function defined.\n", card->name); 34571da177e4SLinus Torvalds deinit_card(card); 34581da177e4SLinus Torvalds return -1; 34591da177e4SLinus Torvalds } 34601da177e4SLinus Torvalds 34611da177e4SLinus Torvalds #ifdef CONFIG_ATM_IDT77252_USE_SUNI 34621da177e4SLinus Torvalds /* 34631da177e4SLinus Torvalds * this is a jhs hack to get around special functionality in the 34641da177e4SLinus Torvalds * phy driver for the atecom hardware; the functionality doesn't 34651da177e4SLinus Torvalds * exist in the linux atm suni driver 34661da177e4SLinus Torvalds * 34671da177e4SLinus Torvalds * it isn't the right way to do things, but as the guy from NIST 34681da177e4SLinus Torvalds * said, talking about their measurement of the fine structure 34691da177e4SLinus Torvalds * constant, "it's good enough for government work." 34701da177e4SLinus Torvalds */ 34711da177e4SLinus Torvalds linkrate = 149760000; 34721da177e4SLinus Torvalds #endif 34731da177e4SLinus Torvalds 34741da177e4SLinus Torvalds card->link_pcr = (linkrate / 8 / 53); 34751da177e4SLinus Torvalds printk("%s: Linkrate on ATM line : %u bit/s, %u cell/s.\n", 34761da177e4SLinus Torvalds card->name, linkrate, card->link_pcr); 34771da177e4SLinus Torvalds 347844beac00SRobert P. J. Day #ifdef ATM_IDT77252_SEND_IDLE 34791da177e4SLinus Torvalds card->utopia_pcr = card->link_pcr; 34801da177e4SLinus Torvalds #else 34811da177e4SLinus Torvalds card->utopia_pcr = (160000000 / 8 / 54); 34821da177e4SLinus Torvalds #endif 34831da177e4SLinus Torvalds 34841da177e4SLinus Torvalds rsvdcr = 0; 34851da177e4SLinus Torvalds if (card->utopia_pcr > card->link_pcr) 34861da177e4SLinus Torvalds rsvdcr = card->utopia_pcr - card->link_pcr; 34871da177e4SLinus Torvalds 34881da177e4SLinus Torvalds tmpl = (unsigned long) rsvdcr * ((unsigned long) card->tst_size - 2); 34891da177e4SLinus Torvalds modl = tmpl % (unsigned long)card->utopia_pcr; 34901da177e4SLinus Torvalds tst_entries = (int) (tmpl / (unsigned long)card->utopia_pcr); 34911da177e4SLinus Torvalds if (modl) 34921da177e4SLinus Torvalds tst_entries++; 34931da177e4SLinus Torvalds card->tst_free -= tst_entries; 34941da177e4SLinus Torvalds fill_tst(card, NULL, tst_entries, TSTE_OPC_NULL); 34951da177e4SLinus Torvalds 34961da177e4SLinus Torvalds #ifdef HAVE_EEPROM 34971da177e4SLinus Torvalds idt77252_eeprom_init(card); 34981da177e4SLinus Torvalds printk("%s: EEPROM: %02x:", card->name, 34991da177e4SLinus Torvalds idt77252_eeprom_read_status(card)); 35001da177e4SLinus Torvalds 35011da177e4SLinus Torvalds for (i = 0; i < 0x80; i++) { 35021da177e4SLinus Torvalds printk(" %02x", 35031da177e4SLinus Torvalds idt77252_eeprom_read_byte(card, i) 35041da177e4SLinus Torvalds ); 35051da177e4SLinus Torvalds } 35061da177e4SLinus Torvalds printk("\n"); 35071da177e4SLinus Torvalds #endif /* HAVE_EEPROM */ 35081da177e4SLinus Torvalds 35091da177e4SLinus Torvalds /* 35101da177e4SLinus Torvalds * XXX: <hack> 35111da177e4SLinus Torvalds */ 35121da177e4SLinus Torvalds sprintf(tname, "eth%d", card->index); 3513881d966bSEric W. Biederman tmp = dev_get_by_name(&init_net, tname); /* jhs: was "tmp = dev_get(tname);" */ 35141da177e4SLinus Torvalds if (tmp) { 35151da177e4SLinus Torvalds memcpy(card->atmdev->esi, tmp->dev_addr, 6); 35161da177e4SLinus Torvalds 3517aaa09ee7Shartleys printk("%s: ESI %pM\n", card->name, card->atmdev->esi); 35181da177e4SLinus Torvalds } 35191da177e4SLinus Torvalds /* 35201da177e4SLinus Torvalds * XXX: </hack> 35211da177e4SLinus Torvalds */ 35221da177e4SLinus Torvalds 35231da177e4SLinus Torvalds /* Set Maximum Deficit Count for now. */ 35241da177e4SLinus Torvalds writel(0xffff, SAR_REG_MDFCT); 35251da177e4SLinus Torvalds 35261da177e4SLinus Torvalds set_bit(IDT77252_BIT_INIT, &card->flags); 35271da177e4SLinus Torvalds 35281da177e4SLinus Torvalds XPRINTK("%s: IDT77252 ABR SAR initialization complete.\n", card->name); 35291da177e4SLinus Torvalds return 0; 35301da177e4SLinus Torvalds } 35311da177e4SLinus Torvalds 35321da177e4SLinus Torvalds 35331da177e4SLinus Torvalds /*****************************************************************************/ 35341da177e4SLinus Torvalds /* */ 35351da177e4SLinus Torvalds /* Probing of IDT77252 ABR SAR */ 35361da177e4SLinus Torvalds /* */ 35371da177e4SLinus Torvalds /*****************************************************************************/ 35381da177e4SLinus Torvalds 35391da177e4SLinus Torvalds 35401da177e4SLinus Torvalds static int __devinit 35411da177e4SLinus Torvalds idt77252_preset(struct idt77252_dev *card) 35421da177e4SLinus Torvalds { 35431da177e4SLinus Torvalds u16 pci_command; 35441da177e4SLinus Torvalds 35451da177e4SLinus Torvalds /*****************************************************************/ 35461da177e4SLinus Torvalds /* P C I C O N F I G U R A T I O N */ 35471da177e4SLinus Torvalds /*****************************************************************/ 35481da177e4SLinus Torvalds 35491da177e4SLinus Torvalds XPRINTK("%s: Enable PCI master and memory access for SAR.\n", 35501da177e4SLinus Torvalds card->name); 35511da177e4SLinus Torvalds if (pci_read_config_word(card->pcidev, PCI_COMMAND, &pci_command)) { 35521da177e4SLinus Torvalds printk("%s: can't read PCI_COMMAND.\n", card->name); 35531da177e4SLinus Torvalds deinit_card(card); 35541da177e4SLinus Torvalds return -1; 35551da177e4SLinus Torvalds } 35561da177e4SLinus Torvalds if (!(pci_command & PCI_COMMAND_IO)) { 35571da177e4SLinus Torvalds printk("%s: PCI_COMMAND: %04x (???)\n", 35581da177e4SLinus Torvalds card->name, pci_command); 35591da177e4SLinus Torvalds deinit_card(card); 35601da177e4SLinus Torvalds return (-1); 35611da177e4SLinus Torvalds } 35621da177e4SLinus Torvalds pci_command |= (PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER); 35631da177e4SLinus Torvalds if (pci_write_config_word(card->pcidev, PCI_COMMAND, pci_command)) { 35641da177e4SLinus Torvalds printk("%s: can't write PCI_COMMAND.\n", card->name); 35651da177e4SLinus Torvalds deinit_card(card); 35661da177e4SLinus Torvalds return -1; 35671da177e4SLinus Torvalds } 35681da177e4SLinus Torvalds /*****************************************************************/ 35691da177e4SLinus Torvalds /* G E N E R I C R E S E T */ 35701da177e4SLinus Torvalds /*****************************************************************/ 35711da177e4SLinus Torvalds 35721da177e4SLinus Torvalds /* Software reset */ 35731da177e4SLinus Torvalds writel(SAR_CFG_SWRST, SAR_REG_CFG); 35741da177e4SLinus Torvalds mdelay(1); 35751da177e4SLinus Torvalds writel(0, SAR_REG_CFG); 35761da177e4SLinus Torvalds 35771da177e4SLinus Torvalds IPRINTK("%s: Software resetted.\n", card->name); 35781da177e4SLinus Torvalds return 0; 35791da177e4SLinus Torvalds } 35801da177e4SLinus Torvalds 35811da177e4SLinus Torvalds 35821da177e4SLinus Torvalds static unsigned long __devinit 35831da177e4SLinus Torvalds probe_sram(struct idt77252_dev *card) 35841da177e4SLinus Torvalds { 35851da177e4SLinus Torvalds u32 data, addr; 35861da177e4SLinus Torvalds 35871da177e4SLinus Torvalds writel(0, SAR_REG_DR0); 35881da177e4SLinus Torvalds writel(SAR_CMD_WRITE_SRAM | (0 << 2), SAR_REG_CMD); 35891da177e4SLinus Torvalds 35901da177e4SLinus Torvalds for (addr = 0x4000; addr < 0x80000; addr += 0x4000) { 35913c6b3773SRandy Dunlap writel(ATM_POISON, SAR_REG_DR0); 35921da177e4SLinus Torvalds writel(SAR_CMD_WRITE_SRAM | (addr << 2), SAR_REG_CMD); 35931da177e4SLinus Torvalds 35941da177e4SLinus Torvalds writel(SAR_CMD_READ_SRAM | (0 << 2), SAR_REG_CMD); 35951da177e4SLinus Torvalds data = readl(SAR_REG_DR0); 35961da177e4SLinus Torvalds 35971da177e4SLinus Torvalds if (data != 0) 35981da177e4SLinus Torvalds break; 35991da177e4SLinus Torvalds } 36001da177e4SLinus Torvalds 36011da177e4SLinus Torvalds return addr * sizeof(u32); 36021da177e4SLinus Torvalds } 36031da177e4SLinus Torvalds 36041da177e4SLinus Torvalds static int __devinit 36051da177e4SLinus Torvalds idt77252_init_one(struct pci_dev *pcidev, const struct pci_device_id *id) 36061da177e4SLinus Torvalds { 36071da177e4SLinus Torvalds static struct idt77252_dev **last = &idt77252_chain; 36081da177e4SLinus Torvalds static int index = 0; 36091da177e4SLinus Torvalds 36101da177e4SLinus Torvalds unsigned long membase, srambase; 36111da177e4SLinus Torvalds struct idt77252_dev *card; 36121da177e4SLinus Torvalds struct atm_dev *dev; 36131da177e4SLinus Torvalds int i, err; 36141da177e4SLinus Torvalds 36151da177e4SLinus Torvalds 36161da177e4SLinus Torvalds if ((err = pci_enable_device(pcidev))) { 36171da177e4SLinus Torvalds printk("idt77252: can't enable PCI device at %s\n", pci_name(pcidev)); 36181da177e4SLinus Torvalds return err; 36191da177e4SLinus Torvalds } 36201da177e4SLinus Torvalds 36210c1cca1dSOm Narasimhan card = kzalloc(sizeof(struct idt77252_dev), GFP_KERNEL); 36221da177e4SLinus Torvalds if (!card) { 36231da177e4SLinus Torvalds printk("idt77252-%d: can't allocate private data\n", index); 36241da177e4SLinus Torvalds err = -ENOMEM; 36251da177e4SLinus Torvalds goto err_out_disable_pdev; 36261da177e4SLinus Torvalds } 362744c10138SAuke Kok card->revision = pcidev->revision; 36281da177e4SLinus Torvalds card->index = index; 36291da177e4SLinus Torvalds card->pcidev = pcidev; 36301da177e4SLinus Torvalds sprintf(card->name, "idt77252-%d", card->index); 36311da177e4SLinus Torvalds 3632c4028958SDavid Howells INIT_WORK(&card->tqueue, idt77252_softint); 36331da177e4SLinus Torvalds 36341da177e4SLinus Torvalds membase = pci_resource_start(pcidev, 1); 36351da177e4SLinus Torvalds srambase = pci_resource_start(pcidev, 2); 36361da177e4SLinus Torvalds 36377e7a2d07SMatthias Kaehlcke mutex_init(&card->mutex); 36381da177e4SLinus Torvalds spin_lock_init(&card->cmd_lock); 36391da177e4SLinus Torvalds spin_lock_init(&card->tst_lock); 36401da177e4SLinus Torvalds 36411da177e4SLinus Torvalds init_timer(&card->tst_timer); 36421da177e4SLinus Torvalds card->tst_timer.data = (unsigned long)card; 36431da177e4SLinus Torvalds card->tst_timer.function = tst_timer; 36441da177e4SLinus Torvalds 36451da177e4SLinus Torvalds /* Do the I/O remapping... */ 36461da177e4SLinus Torvalds card->membase = ioremap(membase, 1024); 36471da177e4SLinus Torvalds if (!card->membase) { 36481da177e4SLinus Torvalds printk("%s: can't ioremap() membase\n", card->name); 36491da177e4SLinus Torvalds err = -EIO; 36501da177e4SLinus Torvalds goto err_out_free_card; 36511da177e4SLinus Torvalds } 36521da177e4SLinus Torvalds 36531da177e4SLinus Torvalds if (idt77252_preset(card)) { 36541da177e4SLinus Torvalds printk("%s: preset failed\n", card->name); 36551da177e4SLinus Torvalds err = -EIO; 36561da177e4SLinus Torvalds goto err_out_iounmap; 36571da177e4SLinus Torvalds } 36581da177e4SLinus Torvalds 3659d9ca676bSDan Williams dev = atm_dev_register("idt77252", &pcidev->dev, &idt77252_ops, -1, 3660d9ca676bSDan Williams NULL); 36611da177e4SLinus Torvalds if (!dev) { 36621da177e4SLinus Torvalds printk("%s: can't register atm device\n", card->name); 36631da177e4SLinus Torvalds err = -EIO; 36641da177e4SLinus Torvalds goto err_out_iounmap; 36651da177e4SLinus Torvalds } 36661da177e4SLinus Torvalds dev->dev_data = card; 36671da177e4SLinus Torvalds card->atmdev = dev; 36681da177e4SLinus Torvalds 36691da177e4SLinus Torvalds #ifdef CONFIG_ATM_IDT77252_USE_SUNI 36701da177e4SLinus Torvalds suni_init(dev); 36711da177e4SLinus Torvalds if (!dev->phy) { 36721da177e4SLinus Torvalds printk("%s: can't init SUNI\n", card->name); 36731da177e4SLinus Torvalds err = -EIO; 36741da177e4SLinus Torvalds goto err_out_deinit_card; 36751da177e4SLinus Torvalds } 36761da177e4SLinus Torvalds #endif /* CONFIG_ATM_IDT77252_USE_SUNI */ 36771da177e4SLinus Torvalds 36781da177e4SLinus Torvalds card->sramsize = probe_sram(card); 36791da177e4SLinus Torvalds 36801da177e4SLinus Torvalds for (i = 0; i < 4; i++) { 36811da177e4SLinus Torvalds card->fbq[i] = ioremap(srambase | 0x200000 | (i << 18), 4); 36821da177e4SLinus Torvalds if (!card->fbq[i]) { 36831da177e4SLinus Torvalds printk("%s: can't ioremap() FBQ%d\n", card->name, i); 36841da177e4SLinus Torvalds err = -EIO; 36851da177e4SLinus Torvalds goto err_out_deinit_card; 36861da177e4SLinus Torvalds } 36871da177e4SLinus Torvalds } 36881da177e4SLinus Torvalds 36891da177e4SLinus Torvalds printk("%s: ABR SAR (Rev %c): MEM %08lx SRAM %08lx [%u KB]\n", 369044c10138SAuke Kok card->name, ((card->revision > 1) && (card->revision < 25)) ? 369144c10138SAuke Kok 'A' + card->revision - 1 : '?', membase, srambase, 36921da177e4SLinus Torvalds card->sramsize / 1024); 36931da177e4SLinus Torvalds 36941da177e4SLinus Torvalds if (init_card(dev)) { 36951da177e4SLinus Torvalds printk("%s: init_card failed\n", card->name); 36961da177e4SLinus Torvalds err = -EIO; 36971da177e4SLinus Torvalds goto err_out_deinit_card; 36981da177e4SLinus Torvalds } 36991da177e4SLinus Torvalds 37001da177e4SLinus Torvalds dev->ci_range.vpi_bits = card->vpibits; 37011da177e4SLinus Torvalds dev->ci_range.vci_bits = card->vcibits; 37021da177e4SLinus Torvalds dev->link_rate = card->link_pcr; 37031da177e4SLinus Torvalds 37041da177e4SLinus Torvalds if (dev->phy->start) 37051da177e4SLinus Torvalds dev->phy->start(dev); 37061da177e4SLinus Torvalds 37071da177e4SLinus Torvalds if (idt77252_dev_open(card)) { 37081da177e4SLinus Torvalds printk("%s: dev_open failed\n", card->name); 37091da177e4SLinus Torvalds err = -EIO; 37101da177e4SLinus Torvalds goto err_out_stop; 37111da177e4SLinus Torvalds } 37121da177e4SLinus Torvalds 37131da177e4SLinus Torvalds *last = card; 37141da177e4SLinus Torvalds last = &card->next; 37151da177e4SLinus Torvalds index++; 37161da177e4SLinus Torvalds 37171da177e4SLinus Torvalds return 0; 37181da177e4SLinus Torvalds 37191da177e4SLinus Torvalds err_out_stop: 37201da177e4SLinus Torvalds if (dev->phy->stop) 37211da177e4SLinus Torvalds dev->phy->stop(dev); 37221da177e4SLinus Torvalds 37231da177e4SLinus Torvalds err_out_deinit_card: 37241da177e4SLinus Torvalds deinit_card(card); 37251da177e4SLinus Torvalds 37261da177e4SLinus Torvalds err_out_iounmap: 37271da177e4SLinus Torvalds iounmap(card->membase); 37281da177e4SLinus Torvalds 37291da177e4SLinus Torvalds err_out_free_card: 37301da177e4SLinus Torvalds kfree(card); 37311da177e4SLinus Torvalds 37321da177e4SLinus Torvalds err_out_disable_pdev: 37331da177e4SLinus Torvalds pci_disable_device(pcidev); 37341da177e4SLinus Torvalds return err; 37351da177e4SLinus Torvalds } 37361da177e4SLinus Torvalds 37371da177e4SLinus Torvalds static struct pci_device_id idt77252_pci_tbl[] = 37381da177e4SLinus Torvalds { 3739e80d3f08SPeter Huewe { PCI_VDEVICE(IDT, PCI_DEVICE_ID_IDT_IDT77252), 0 }, 37401da177e4SLinus Torvalds { 0, } 37411da177e4SLinus Torvalds }; 37421da177e4SLinus Torvalds 37431da177e4SLinus Torvalds MODULE_DEVICE_TABLE(pci, idt77252_pci_tbl); 37441da177e4SLinus Torvalds 37451da177e4SLinus Torvalds static struct pci_driver idt77252_driver = { 37461da177e4SLinus Torvalds .name = "idt77252", 37471da177e4SLinus Torvalds .id_table = idt77252_pci_tbl, 37481da177e4SLinus Torvalds .probe = idt77252_init_one, 37491da177e4SLinus Torvalds }; 37501da177e4SLinus Torvalds 37511da177e4SLinus Torvalds static int __init idt77252_init(void) 37521da177e4SLinus Torvalds { 37531da177e4SLinus Torvalds struct sk_buff *skb; 37541da177e4SLinus Torvalds 37555a346a10SHarvey Harrison printk("%s: at %p\n", __func__, idt77252_init); 37561da177e4SLinus Torvalds 37571da177e4SLinus Torvalds if (sizeof(skb->cb) < sizeof(struct atm_skb_data) + 37581da177e4SLinus Torvalds sizeof(struct idt77252_skb_prv)) { 37591da177e4SLinus Torvalds printk(KERN_ERR "%s: skb->cb is too small (%lu < %lu)\n", 37605a346a10SHarvey Harrison __func__, (unsigned long) sizeof(skb->cb), 37611da177e4SLinus Torvalds (unsigned long) sizeof(struct atm_skb_data) + 37621da177e4SLinus Torvalds sizeof(struct idt77252_skb_prv)); 37631da177e4SLinus Torvalds return -EIO; 37641da177e4SLinus Torvalds } 37651da177e4SLinus Torvalds 37661da177e4SLinus Torvalds return pci_register_driver(&idt77252_driver); 37671da177e4SLinus Torvalds } 37681da177e4SLinus Torvalds 37691da177e4SLinus Torvalds static void __exit idt77252_exit(void) 37701da177e4SLinus Torvalds { 37711da177e4SLinus Torvalds struct idt77252_dev *card; 37721da177e4SLinus Torvalds struct atm_dev *dev; 37731da177e4SLinus Torvalds 37741da177e4SLinus Torvalds pci_unregister_driver(&idt77252_driver); 37751da177e4SLinus Torvalds 37761da177e4SLinus Torvalds while (idt77252_chain) { 37771da177e4SLinus Torvalds card = idt77252_chain; 37781da177e4SLinus Torvalds dev = card->atmdev; 37791da177e4SLinus Torvalds idt77252_chain = card->next; 37801da177e4SLinus Torvalds 37811da177e4SLinus Torvalds if (dev->phy->stop) 37821da177e4SLinus Torvalds dev->phy->stop(dev); 37831da177e4SLinus Torvalds deinit_card(card); 37841da177e4SLinus Torvalds pci_disable_device(card->pcidev); 37851da177e4SLinus Torvalds kfree(card); 37861da177e4SLinus Torvalds } 37871da177e4SLinus Torvalds 37881da177e4SLinus Torvalds DIPRINTK("idt77252: finished cleanup-module().\n"); 37891da177e4SLinus Torvalds } 37901da177e4SLinus Torvalds 37911da177e4SLinus Torvalds module_init(idt77252_init); 37921da177e4SLinus Torvalds module_exit(idt77252_exit); 37931da177e4SLinus Torvalds 37941da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 37951da177e4SLinus Torvalds 37961da177e4SLinus Torvalds module_param(vpibits, uint, 0); 37971da177e4SLinus Torvalds MODULE_PARM_DESC(vpibits, "number of VPI bits supported (0, 1, or 2)"); 37981da177e4SLinus Torvalds #ifdef CONFIG_ATM_IDT77252_DEBUG 37991da177e4SLinus Torvalds module_param(debug, ulong, 0644); 38001da177e4SLinus Torvalds MODULE_PARM_DESC(debug, "debug bitmap, see drivers/atm/idt77252.h"); 38011da177e4SLinus Torvalds #endif 38021da177e4SLinus Torvalds 38031da177e4SLinus Torvalds MODULE_AUTHOR("Eddie C. Dost <ecd@atecom.com>"); 38041da177e4SLinus Torvalds MODULE_DESCRIPTION("IDT77252 ABR SAR Driver"); 3805