11da177e4SLinus Torvalds /****************************************************************************** 21da177e4SLinus Torvalds iphase.c: Device driver for Interphase ATM PCI adapter cards 31da177e4SLinus Torvalds Author: Peter Wang <pwang@iphase.com> 41da177e4SLinus Torvalds Some fixes: Arnaldo Carvalho de Melo <acme@conectiva.com.br> 51da177e4SLinus Torvalds Interphase Corporation <www.iphase.com> 61da177e4SLinus Torvalds Version: 1.0 71da177e4SLinus Torvalds ******************************************************************************* 81da177e4SLinus Torvalds 91da177e4SLinus Torvalds This software may be used and distributed according to the terms 101da177e4SLinus Torvalds of the GNU General Public License (GPL), incorporated herein by reference. 111da177e4SLinus Torvalds Drivers based on this skeleton fall under the GPL and must retain 121da177e4SLinus Torvalds the authorship (implicit copyright) notice. 131da177e4SLinus Torvalds 141da177e4SLinus Torvalds This program is distributed in the hope that it will be useful, but 151da177e4SLinus Torvalds WITHOUT ANY WARRANTY; without even the implied warranty of 161da177e4SLinus Torvalds MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 171da177e4SLinus Torvalds General Public License for more details. 181da177e4SLinus Torvalds 191da177e4SLinus Torvalds Modified from an incomplete driver for Interphase 5575 1KVC 1M card which 201da177e4SLinus Torvalds was originally written by Monalisa Agrawal at UNH. Now this driver 211da177e4SLinus Torvalds supports a variety of varients of Interphase ATM PCI (i)Chip adapter 221da177e4SLinus Torvalds card family (See www.iphase.com/products/ClassSheet.cfm?ClassID=ATM) 231da177e4SLinus Torvalds in terms of PHY type, the size of control memory and the size of 241da177e4SLinus Torvalds packet memory. The followings are the change log and history: 251da177e4SLinus Torvalds 261da177e4SLinus Torvalds Bugfix the Mona's UBR driver. 271da177e4SLinus Torvalds Modify the basic memory allocation and dma logic. 281da177e4SLinus Torvalds Port the driver to the latest kernel from 2.0.46. 291da177e4SLinus Torvalds Complete the ABR logic of the driver, and added the ABR work- 301da177e4SLinus Torvalds around for the hardware anormalies. 311da177e4SLinus Torvalds Add the CBR support. 321da177e4SLinus Torvalds Add the flow control logic to the driver to allow rate-limit VC. 331da177e4SLinus Torvalds Add 4K VC support to the board with 512K control memory. 341da177e4SLinus Torvalds Add the support of all the variants of the Interphase ATM PCI 351da177e4SLinus Torvalds (i)Chip adapter cards including x575 (155M OC3 and UTP155), x525 361da177e4SLinus Torvalds (25M UTP25) and x531 (DS3 and E3). 371da177e4SLinus Torvalds Add SMP support. 381da177e4SLinus Torvalds 391da177e4SLinus Torvalds Support and updates available at: ftp://ftp.iphase.com/pub/atm 401da177e4SLinus Torvalds 411da177e4SLinus Torvalds *******************************************************************************/ 421da177e4SLinus Torvalds 431da177e4SLinus Torvalds #include <linux/module.h> 441da177e4SLinus Torvalds #include <linux/kernel.h> 451da177e4SLinus Torvalds #include <linux/mm.h> 461da177e4SLinus Torvalds #include <linux/pci.h> 471da177e4SLinus Torvalds #include <linux/errno.h> 481da177e4SLinus Torvalds #include <linux/atm.h> 491da177e4SLinus Torvalds #include <linux/atmdev.h> 501da177e4SLinus Torvalds #include <linux/sonet.h> 511da177e4SLinus Torvalds #include <linux/skbuff.h> 521da177e4SLinus Torvalds #include <linux/time.h> 531da177e4SLinus Torvalds #include <linux/delay.h> 541da177e4SLinus Torvalds #include <linux/uio.h> 551da177e4SLinus Torvalds #include <linux/init.h> 56a6b7a407SAlexey Dobriyan #include <linux/interrupt.h> 571da177e4SLinus Torvalds #include <linux/wait.h> 585a0e3ad6STejun Heo #include <linux/slab.h> 591da177e4SLinus Torvalds #include <asm/io.h> 6060063497SArun Sharma #include <linux/atomic.h> 611da177e4SLinus Torvalds #include <asm/uaccess.h> 621da177e4SLinus Torvalds #include <asm/string.h> 631da177e4SLinus Torvalds #include <asm/byteorder.h> 641da177e4SLinus Torvalds #include <linux/vmalloc.h> 65420635f5SJulia Lawall #include <linux/jiffies.h> 661da177e4SLinus Torvalds #include "iphase.h" 671da177e4SLinus Torvalds #include "suni.h" 68b67445fcSWu Fengguang #define swap_byte_order(x) (((x & 0xff) << 8) | ((x & 0xff00) >> 8)) 692be63b87SJorge Boncompte [DTI2] 701da177e4SLinus Torvalds #define PRIV(dev) ((struct suni_priv *) dev->phy_data) 711da177e4SLinus Torvalds 721da177e4SLinus Torvalds static unsigned char ia_phy_get(struct atm_dev *dev, unsigned long addr); 731da177e4SLinus Torvalds static void desc_dbg(IADEV *iadev); 741da177e4SLinus Torvalds 751da177e4SLinus Torvalds static IADEV *ia_dev[8]; 761da177e4SLinus Torvalds static struct atm_dev *_ia_dev[8]; 771da177e4SLinus Torvalds static int iadev_count; 781da177e4SLinus Torvalds static void ia_led_timer(unsigned long arg); 798d06afabSIngo Molnar static DEFINE_TIMER(ia_timer, ia_led_timer, 0, 0); 801da177e4SLinus Torvalds static int IA_TX_BUF = DFL_TX_BUFFERS, IA_TX_BUF_SZ = DFL_TX_BUF_SZ; 811da177e4SLinus Torvalds static int IA_RX_BUF = DFL_RX_BUFFERS, IA_RX_BUF_SZ = DFL_RX_BUF_SZ; 821da177e4SLinus Torvalds static uint IADebugFlag = /* IF_IADBG_ERR | IF_IADBG_CBR| IF_IADBG_INIT_ADAPTER 831da177e4SLinus Torvalds |IF_IADBG_ABR | IF_IADBG_EVENT*/ 0; 841da177e4SLinus Torvalds 851da177e4SLinus Torvalds module_param(IA_TX_BUF, int, 0); 861da177e4SLinus Torvalds module_param(IA_TX_BUF_SZ, int, 0); 871da177e4SLinus Torvalds module_param(IA_RX_BUF, int, 0); 881da177e4SLinus Torvalds module_param(IA_RX_BUF_SZ, int, 0); 891da177e4SLinus Torvalds module_param(IADebugFlag, uint, 0644); 901da177e4SLinus Torvalds 911da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 921da177e4SLinus Torvalds 931da177e4SLinus Torvalds /**************************** IA_LIB **********************************/ 941da177e4SLinus Torvalds 951da177e4SLinus Torvalds static void ia_init_rtn_q (IARTN_Q *que) 961da177e4SLinus Torvalds { 971da177e4SLinus Torvalds que->next = NULL; 981da177e4SLinus Torvalds que->tail = NULL; 991da177e4SLinus Torvalds } 1001da177e4SLinus Torvalds 1011da177e4SLinus Torvalds static void ia_enque_head_rtn_q (IARTN_Q *que, IARTN_Q * data) 1021da177e4SLinus Torvalds { 1031da177e4SLinus Torvalds data->next = NULL; 1041da177e4SLinus Torvalds if (que->next == NULL) 1051da177e4SLinus Torvalds que->next = que->tail = data; 1061da177e4SLinus Torvalds else { 1071da177e4SLinus Torvalds data->next = que->next; 1081da177e4SLinus Torvalds que->next = data; 1091da177e4SLinus Torvalds } 1101da177e4SLinus Torvalds return; 1111da177e4SLinus Torvalds } 1121da177e4SLinus Torvalds 1131da177e4SLinus Torvalds static int ia_enque_rtn_q (IARTN_Q *que, struct desc_tbl_t data) { 1141da177e4SLinus Torvalds IARTN_Q *entry = kmalloc(sizeof(*entry), GFP_ATOMIC); 1151da177e4SLinus Torvalds if (!entry) return -1; 1161da177e4SLinus Torvalds entry->data = data; 1171da177e4SLinus Torvalds entry->next = NULL; 1181da177e4SLinus Torvalds if (que->next == NULL) 1191da177e4SLinus Torvalds que->next = que->tail = entry; 1201da177e4SLinus Torvalds else { 1211da177e4SLinus Torvalds que->tail->next = entry; 1221da177e4SLinus Torvalds que->tail = que->tail->next; 1231da177e4SLinus Torvalds } 1241da177e4SLinus Torvalds return 1; 1251da177e4SLinus Torvalds } 1261da177e4SLinus Torvalds 1271da177e4SLinus Torvalds static IARTN_Q * ia_deque_rtn_q (IARTN_Q *que) { 1281da177e4SLinus Torvalds IARTN_Q *tmpdata; 1291da177e4SLinus Torvalds if (que->next == NULL) 1301da177e4SLinus Torvalds return NULL; 1311da177e4SLinus Torvalds tmpdata = que->next; 1321da177e4SLinus Torvalds if ( que->next == que->tail) 1331da177e4SLinus Torvalds que->next = que->tail = NULL; 1341da177e4SLinus Torvalds else 1351da177e4SLinus Torvalds que->next = que->next->next; 1361da177e4SLinus Torvalds return tmpdata; 1371da177e4SLinus Torvalds } 1381da177e4SLinus Torvalds 1391da177e4SLinus Torvalds static void ia_hack_tcq(IADEV *dev) { 1401da177e4SLinus Torvalds 1411da177e4SLinus Torvalds u_short desc1; 1421da177e4SLinus Torvalds u_short tcq_wr; 1431da177e4SLinus Torvalds struct ia_vcc *iavcc_r = NULL; 1441da177e4SLinus Torvalds 1451da177e4SLinus Torvalds tcq_wr = readl(dev->seg_reg+TCQ_WR_PTR) & 0xffff; 1461da177e4SLinus Torvalds while (dev->host_tcq_wr != tcq_wr) { 1471da177e4SLinus Torvalds desc1 = *(u_short *)(dev->seg_ram + dev->host_tcq_wr); 1481da177e4SLinus Torvalds if (!desc1) ; 1491da177e4SLinus Torvalds else if (!dev->desc_tbl[desc1 -1].timestamp) { 1501da177e4SLinus Torvalds IF_ABR(printk(" Desc %d is reset at %ld\n", desc1 -1, jiffies);) 1511da177e4SLinus Torvalds *(u_short *) (dev->seg_ram + dev->host_tcq_wr) = 0; 1521da177e4SLinus Torvalds } 1531da177e4SLinus Torvalds else if (dev->desc_tbl[desc1 -1].timestamp) { 1541da177e4SLinus Torvalds if (!(iavcc_r = dev->desc_tbl[desc1 -1].iavcc)) { 1551da177e4SLinus Torvalds printk("IA: Fatal err in get_desc\n"); 1561da177e4SLinus Torvalds continue; 1571da177e4SLinus Torvalds } 1581da177e4SLinus Torvalds iavcc_r->vc_desc_cnt--; 1591da177e4SLinus Torvalds dev->desc_tbl[desc1 -1].timestamp = 0; 160849e8caaSDavid Howells IF_EVENT(printk("ia_hack: return_q skb = 0x%p desc = %d\n", 161849e8caaSDavid Howells dev->desc_tbl[desc1 -1].txskb, desc1);) 1621da177e4SLinus Torvalds if (iavcc_r->pcr < dev->rate_limit) { 1631da177e4SLinus Torvalds IA_SKB_STATE (dev->desc_tbl[desc1-1].txskb) |= IA_TX_DONE; 1641da177e4SLinus Torvalds if (ia_enque_rtn_q(&dev->tx_return_q, dev->desc_tbl[desc1 -1]) < 0) 1651da177e4SLinus Torvalds printk("ia_hack_tcq: No memory available\n"); 1661da177e4SLinus Torvalds } 1671da177e4SLinus Torvalds dev->desc_tbl[desc1 -1].iavcc = NULL; 1681da177e4SLinus Torvalds dev->desc_tbl[desc1 -1].txskb = NULL; 1691da177e4SLinus Torvalds } 1701da177e4SLinus Torvalds dev->host_tcq_wr += 2; 1711da177e4SLinus Torvalds if (dev->host_tcq_wr > dev->ffL.tcq_ed) 1721da177e4SLinus Torvalds dev->host_tcq_wr = dev->ffL.tcq_st; 1731da177e4SLinus Torvalds } 1741da177e4SLinus Torvalds } /* ia_hack_tcq */ 1751da177e4SLinus Torvalds 1761da177e4SLinus Torvalds static u16 get_desc (IADEV *dev, struct ia_vcc *iavcc) { 1771da177e4SLinus Torvalds u_short desc_num, i; 1781da177e4SLinus Torvalds struct sk_buff *skb; 1791da177e4SLinus Torvalds struct ia_vcc *iavcc_r = NULL; 1801da177e4SLinus Torvalds unsigned long delta; 1811da177e4SLinus Torvalds static unsigned long timer = 0; 1821da177e4SLinus Torvalds int ltimeout; 1831da177e4SLinus Torvalds 1841da177e4SLinus Torvalds ia_hack_tcq (dev); 185420635f5SJulia Lawall if((time_after(jiffies,timer+50)) || ((dev->ffL.tcq_rd==dev->host_tcq_wr))) { 1861da177e4SLinus Torvalds timer = jiffies; 1871da177e4SLinus Torvalds i=0; 1881da177e4SLinus Torvalds while (i < dev->num_tx_desc) { 1891da177e4SLinus Torvalds if (!dev->desc_tbl[i].timestamp) { 1901da177e4SLinus Torvalds i++; 1911da177e4SLinus Torvalds continue; 1921da177e4SLinus Torvalds } 1931da177e4SLinus Torvalds ltimeout = dev->desc_tbl[i].iavcc->ltimeout; 1941da177e4SLinus Torvalds delta = jiffies - dev->desc_tbl[i].timestamp; 1951da177e4SLinus Torvalds if (delta >= ltimeout) { 1961da177e4SLinus Torvalds IF_ABR(printk("RECOVER run!! desc_tbl %d = %d delta = %ld, time = %ld\n", i,dev->desc_tbl[i].timestamp, delta, jiffies);) 1971da177e4SLinus Torvalds if (dev->ffL.tcq_rd == dev->ffL.tcq_st) 1981da177e4SLinus Torvalds dev->ffL.tcq_rd = dev->ffL.tcq_ed; 1991da177e4SLinus Torvalds else 2001da177e4SLinus Torvalds dev->ffL.tcq_rd -= 2; 2011da177e4SLinus Torvalds *(u_short *)(dev->seg_ram + dev->ffL.tcq_rd) = i+1; 2021da177e4SLinus Torvalds if (!(skb = dev->desc_tbl[i].txskb) || 2031da177e4SLinus Torvalds !(iavcc_r = dev->desc_tbl[i].iavcc)) 2041da177e4SLinus Torvalds printk("Fatal err, desc table vcc or skb is NULL\n"); 2051da177e4SLinus Torvalds else 2061da177e4SLinus Torvalds iavcc_r->vc_desc_cnt--; 2071da177e4SLinus Torvalds dev->desc_tbl[i].timestamp = 0; 2081da177e4SLinus Torvalds dev->desc_tbl[i].iavcc = NULL; 2091da177e4SLinus Torvalds dev->desc_tbl[i].txskb = NULL; 2101da177e4SLinus Torvalds } 2111da177e4SLinus Torvalds i++; 2121da177e4SLinus Torvalds } /* while */ 2131da177e4SLinus Torvalds } 2141da177e4SLinus Torvalds if (dev->ffL.tcq_rd == dev->host_tcq_wr) 2151da177e4SLinus Torvalds return 0xFFFF; 2161da177e4SLinus Torvalds 2171da177e4SLinus Torvalds /* Get the next available descriptor number from TCQ */ 2181da177e4SLinus Torvalds desc_num = *(u_short *)(dev->seg_ram + dev->ffL.tcq_rd); 2191da177e4SLinus Torvalds 2201da177e4SLinus Torvalds while (!desc_num || (dev->desc_tbl[desc_num -1]).timestamp) { 2211da177e4SLinus Torvalds dev->ffL.tcq_rd += 2; 2221da177e4SLinus Torvalds if (dev->ffL.tcq_rd > dev->ffL.tcq_ed) 2231da177e4SLinus Torvalds dev->ffL.tcq_rd = dev->ffL.tcq_st; 2241da177e4SLinus Torvalds if (dev->ffL.tcq_rd == dev->host_tcq_wr) 2251da177e4SLinus Torvalds return 0xFFFF; 2261da177e4SLinus Torvalds desc_num = *(u_short *)(dev->seg_ram + dev->ffL.tcq_rd); 2271da177e4SLinus Torvalds } 2281da177e4SLinus Torvalds 2291da177e4SLinus Torvalds /* get system time */ 2301da177e4SLinus Torvalds dev->desc_tbl[desc_num -1].timestamp = jiffies; 2311da177e4SLinus Torvalds return desc_num; 2321da177e4SLinus Torvalds } 2331da177e4SLinus Torvalds 2341da177e4SLinus Torvalds static void clear_lockup (struct atm_vcc *vcc, IADEV *dev) { 2351da177e4SLinus Torvalds u_char foundLockUp; 2361da177e4SLinus Torvalds vcstatus_t *vcstatus; 2371da177e4SLinus Torvalds u_short *shd_tbl; 2381da177e4SLinus Torvalds u_short tempCellSlot, tempFract; 2391da177e4SLinus Torvalds struct main_vc *abr_vc = (struct main_vc *)dev->MAIN_VC_TABLE_ADDR; 2401da177e4SLinus Torvalds struct ext_vc *eabr_vc = (struct ext_vc *)dev->EXT_VC_TABLE_ADDR; 2411da177e4SLinus Torvalds u_int i; 2421da177e4SLinus Torvalds 2431da177e4SLinus Torvalds if (vcc->qos.txtp.traffic_class == ATM_ABR) { 2441da177e4SLinus Torvalds vcstatus = (vcstatus_t *) &(dev->testTable[vcc->vci]->vc_status); 2451da177e4SLinus Torvalds vcstatus->cnt++; 2461da177e4SLinus Torvalds foundLockUp = 0; 2471da177e4SLinus Torvalds if( vcstatus->cnt == 0x05 ) { 2481da177e4SLinus Torvalds abr_vc += vcc->vci; 2491da177e4SLinus Torvalds eabr_vc += vcc->vci; 2501da177e4SLinus Torvalds if( eabr_vc->last_desc ) { 2511da177e4SLinus Torvalds if( (abr_vc->status & 0x07) == ABR_STATE /* 0x2 */ ) { 2521da177e4SLinus Torvalds /* Wait for 10 Micro sec */ 2531da177e4SLinus Torvalds udelay(10); 2541da177e4SLinus Torvalds if ((eabr_vc->last_desc)&&((abr_vc->status & 0x07)==ABR_STATE)) 2551da177e4SLinus Torvalds foundLockUp = 1; 2561da177e4SLinus Torvalds } 2571da177e4SLinus Torvalds else { 2581da177e4SLinus Torvalds tempCellSlot = abr_vc->last_cell_slot; 2591da177e4SLinus Torvalds tempFract = abr_vc->fraction; 2601da177e4SLinus Torvalds if((tempCellSlot == dev->testTable[vcc->vci]->lastTime) 2611da177e4SLinus Torvalds && (tempFract == dev->testTable[vcc->vci]->fract)) 2621da177e4SLinus Torvalds foundLockUp = 1; 2631da177e4SLinus Torvalds dev->testTable[vcc->vci]->lastTime = tempCellSlot; 2641da177e4SLinus Torvalds dev->testTable[vcc->vci]->fract = tempFract; 2651da177e4SLinus Torvalds } 2661da177e4SLinus Torvalds } /* last descriptor */ 2671da177e4SLinus Torvalds vcstatus->cnt = 0; 2681da177e4SLinus Torvalds } /* vcstatus->cnt */ 2691da177e4SLinus Torvalds 2701da177e4SLinus Torvalds if (foundLockUp) { 2711da177e4SLinus Torvalds IF_ABR(printk("LOCK UP found\n");) 2721da177e4SLinus Torvalds writew(0xFFFD, dev->seg_reg+MODE_REG_0); 2731da177e4SLinus Torvalds /* Wait for 10 Micro sec */ 2741da177e4SLinus Torvalds udelay(10); 2751da177e4SLinus Torvalds abr_vc->status &= 0xFFF8; 2761da177e4SLinus Torvalds abr_vc->status |= 0x0001; /* state is idle */ 2771da177e4SLinus Torvalds shd_tbl = (u_short *)dev->ABR_SCHED_TABLE_ADDR; 2781da177e4SLinus Torvalds for( i = 0; ((i < dev->num_vc) && (shd_tbl[i])); i++ ); 2791da177e4SLinus Torvalds if (i < dev->num_vc) 2801da177e4SLinus Torvalds shd_tbl[i] = vcc->vci; 2811da177e4SLinus Torvalds else 2821da177e4SLinus Torvalds IF_ERR(printk("ABR Seg. may not continue on VC %x\n",vcc->vci);) 2831da177e4SLinus Torvalds writew(T_ONLINE, dev->seg_reg+MODE_REG_0); 2841da177e4SLinus Torvalds writew(~(TRANSMIT_DONE|TCQ_NOT_EMPTY), dev->seg_reg+SEG_MASK_REG); 2851da177e4SLinus Torvalds writew(TRANSMIT_DONE, dev->seg_reg+SEG_INTR_STATUS_REG); 2861da177e4SLinus Torvalds vcstatus->cnt = 0; 2871da177e4SLinus Torvalds } /* foundLockUp */ 2881da177e4SLinus Torvalds 2891da177e4SLinus Torvalds } /* if an ABR VC */ 2901da177e4SLinus Torvalds 2911da177e4SLinus Torvalds 2921da177e4SLinus Torvalds } 2931da177e4SLinus Torvalds 2941da177e4SLinus Torvalds /* 2951da177e4SLinus Torvalds ** Conversion of 24-bit cellrate (cells/sec) to 16-bit floating point format. 2961da177e4SLinus Torvalds ** 2971da177e4SLinus Torvalds ** +----+----+------------------+-------------------------------+ 2981da177e4SLinus Torvalds ** | R | NZ | 5-bit exponent | 9-bit mantissa | 2991da177e4SLinus Torvalds ** +----+----+------------------+-------------------------------+ 3001da177e4SLinus Torvalds ** 3010779bf2dSMatt LaPlante ** R = reserved (written as 0) 3021da177e4SLinus Torvalds ** NZ = 0 if 0 cells/sec; 1 otherwise 3031da177e4SLinus Torvalds ** 3041da177e4SLinus Torvalds ** if NZ = 1, rate = 1.mmmmmmmmm x 2^(eeeee) cells/sec 3051da177e4SLinus Torvalds */ 3061da177e4SLinus Torvalds static u16 3071da177e4SLinus Torvalds cellrate_to_float(u32 cr) 3081da177e4SLinus Torvalds { 3091da177e4SLinus Torvalds 3101da177e4SLinus Torvalds #define NZ 0x4000 3111da177e4SLinus Torvalds #define M_BITS 9 /* Number of bits in mantissa */ 3121da177e4SLinus Torvalds #define E_BITS 5 /* Number of bits in exponent */ 3131da177e4SLinus Torvalds #define M_MASK 0x1ff 3141da177e4SLinus Torvalds #define E_MASK 0x1f 3151da177e4SLinus Torvalds u16 flot; 3161da177e4SLinus Torvalds u32 tmp = cr & 0x00ffffff; 3171da177e4SLinus Torvalds int i = 0; 3181da177e4SLinus Torvalds if (cr == 0) 3191da177e4SLinus Torvalds return 0; 3201da177e4SLinus Torvalds while (tmp != 1) { 3211da177e4SLinus Torvalds tmp >>= 1; 3221da177e4SLinus Torvalds i++; 3231da177e4SLinus Torvalds } 3241da177e4SLinus Torvalds if (i == M_BITS) 3251da177e4SLinus Torvalds flot = NZ | (i << M_BITS) | (cr & M_MASK); 3261da177e4SLinus Torvalds else if (i < M_BITS) 3271da177e4SLinus Torvalds flot = NZ | (i << M_BITS) | ((cr << (M_BITS - i)) & M_MASK); 3281da177e4SLinus Torvalds else 3291da177e4SLinus Torvalds flot = NZ | (i << M_BITS) | ((cr >> (i - M_BITS)) & M_MASK); 3301da177e4SLinus Torvalds return flot; 3311da177e4SLinus Torvalds } 3321da177e4SLinus Torvalds 3331da177e4SLinus Torvalds #if 0 3341da177e4SLinus Torvalds /* 3351da177e4SLinus Torvalds ** Conversion of 16-bit floating point format to 24-bit cellrate (cells/sec). 3361da177e4SLinus Torvalds */ 3371da177e4SLinus Torvalds static u32 3381da177e4SLinus Torvalds float_to_cellrate(u16 rate) 3391da177e4SLinus Torvalds { 3401da177e4SLinus Torvalds u32 exp, mantissa, cps; 3411da177e4SLinus Torvalds if ((rate & NZ) == 0) 3421da177e4SLinus Torvalds return 0; 3431da177e4SLinus Torvalds exp = (rate >> M_BITS) & E_MASK; 3441da177e4SLinus Torvalds mantissa = rate & M_MASK; 3451da177e4SLinus Torvalds if (exp == 0) 3461da177e4SLinus Torvalds return 1; 3471da177e4SLinus Torvalds cps = (1 << M_BITS) | mantissa; 3481da177e4SLinus Torvalds if (exp == M_BITS) 3491da177e4SLinus Torvalds cps = cps; 3501da177e4SLinus Torvalds else if (exp > M_BITS) 3511da177e4SLinus Torvalds cps <<= (exp - M_BITS); 3521da177e4SLinus Torvalds else 3531da177e4SLinus Torvalds cps >>= (M_BITS - exp); 3541da177e4SLinus Torvalds return cps; 3551da177e4SLinus Torvalds } 3561da177e4SLinus Torvalds #endif 3571da177e4SLinus Torvalds 3581da177e4SLinus Torvalds static void init_abr_vc (IADEV *dev, srv_cls_param_t *srv_p) { 3591da177e4SLinus Torvalds srv_p->class_type = ATM_ABR; 3601da177e4SLinus Torvalds srv_p->pcr = dev->LineRate; 3611da177e4SLinus Torvalds srv_p->mcr = 0; 3621da177e4SLinus Torvalds srv_p->icr = 0x055cb7; 3631da177e4SLinus Torvalds srv_p->tbe = 0xffffff; 3641da177e4SLinus Torvalds srv_p->frtt = 0x3a; 3651da177e4SLinus Torvalds srv_p->rif = 0xf; 3661da177e4SLinus Torvalds srv_p->rdf = 0xb; 3671da177e4SLinus Torvalds srv_p->nrm = 0x4; 3681da177e4SLinus Torvalds srv_p->trm = 0x7; 3691da177e4SLinus Torvalds srv_p->cdf = 0x3; 3701da177e4SLinus Torvalds srv_p->adtf = 50; 3711da177e4SLinus Torvalds } 3721da177e4SLinus Torvalds 3731da177e4SLinus Torvalds static int 3741da177e4SLinus Torvalds ia_open_abr_vc(IADEV *dev, srv_cls_param_t *srv_p, 3751da177e4SLinus Torvalds struct atm_vcc *vcc, u8 flag) 3761da177e4SLinus Torvalds { 3771da177e4SLinus Torvalds f_vc_abr_entry *f_abr_vc; 3781da177e4SLinus Torvalds r_vc_abr_entry *r_abr_vc; 3791da177e4SLinus Torvalds u32 icr; 3801da177e4SLinus Torvalds u8 trm, nrm, crm; 3811da177e4SLinus Torvalds u16 adtf, air, *ptr16; 3821da177e4SLinus Torvalds f_abr_vc =(f_vc_abr_entry *)dev->MAIN_VC_TABLE_ADDR; 3831da177e4SLinus Torvalds f_abr_vc += vcc->vci; 3841da177e4SLinus Torvalds switch (flag) { 3851da177e4SLinus Torvalds case 1: /* FFRED initialization */ 3861da177e4SLinus Torvalds #if 0 /* sanity check */ 3871da177e4SLinus Torvalds if (srv_p->pcr == 0) 3881da177e4SLinus Torvalds return INVALID_PCR; 3891da177e4SLinus Torvalds if (srv_p->pcr > dev->LineRate) 3901da177e4SLinus Torvalds srv_p->pcr = dev->LineRate; 3911da177e4SLinus Torvalds if ((srv_p->mcr + dev->sum_mcr) > dev->LineRate) 3921da177e4SLinus Torvalds return MCR_UNAVAILABLE; 3931da177e4SLinus Torvalds if (srv_p->mcr > srv_p->pcr) 3941da177e4SLinus Torvalds return INVALID_MCR; 3951da177e4SLinus Torvalds if (!(srv_p->icr)) 3961da177e4SLinus Torvalds srv_p->icr = srv_p->pcr; 3971da177e4SLinus Torvalds if ((srv_p->icr < srv_p->mcr) || (srv_p->icr > srv_p->pcr)) 3981da177e4SLinus Torvalds return INVALID_ICR; 3991da177e4SLinus Torvalds if ((srv_p->tbe < MIN_TBE) || (srv_p->tbe > MAX_TBE)) 4001da177e4SLinus Torvalds return INVALID_TBE; 4011da177e4SLinus Torvalds if ((srv_p->frtt < MIN_FRTT) || (srv_p->frtt > MAX_FRTT)) 4021da177e4SLinus Torvalds return INVALID_FRTT; 4031da177e4SLinus Torvalds if (srv_p->nrm > MAX_NRM) 4041da177e4SLinus Torvalds return INVALID_NRM; 4051da177e4SLinus Torvalds if (srv_p->trm > MAX_TRM) 4061da177e4SLinus Torvalds return INVALID_TRM; 4071da177e4SLinus Torvalds if (srv_p->adtf > MAX_ADTF) 4081da177e4SLinus Torvalds return INVALID_ADTF; 4091da177e4SLinus Torvalds else if (srv_p->adtf == 0) 4101da177e4SLinus Torvalds srv_p->adtf = 1; 4111da177e4SLinus Torvalds if (srv_p->cdf > MAX_CDF) 4121da177e4SLinus Torvalds return INVALID_CDF; 4131da177e4SLinus Torvalds if (srv_p->rif > MAX_RIF) 4141da177e4SLinus Torvalds return INVALID_RIF; 4151da177e4SLinus Torvalds if (srv_p->rdf > MAX_RDF) 4161da177e4SLinus Torvalds return INVALID_RDF; 4171da177e4SLinus Torvalds #endif 4181da177e4SLinus Torvalds memset ((caddr_t)f_abr_vc, 0, sizeof(*f_abr_vc)); 4191da177e4SLinus Torvalds f_abr_vc->f_vc_type = ABR; 4201da177e4SLinus Torvalds nrm = 2 << srv_p->nrm; /* (2 ** (srv_p->nrm +1)) */ 4211da177e4SLinus Torvalds /* i.e 2**n = 2 << (n-1) */ 4221da177e4SLinus Torvalds f_abr_vc->f_nrm = nrm << 8 | nrm; 4231da177e4SLinus Torvalds trm = 100000/(2 << (16 - srv_p->trm)); 4241da177e4SLinus Torvalds if ( trm == 0) trm = 1; 4251da177e4SLinus Torvalds f_abr_vc->f_nrmexp =(((srv_p->nrm +1) & 0x0f) << 12)|(MRM << 8) | trm; 4261da177e4SLinus Torvalds crm = srv_p->tbe / nrm; 4271da177e4SLinus Torvalds if (crm == 0) crm = 1; 4281da177e4SLinus Torvalds f_abr_vc->f_crm = crm & 0xff; 4291da177e4SLinus Torvalds f_abr_vc->f_pcr = cellrate_to_float(srv_p->pcr); 4301da177e4SLinus Torvalds icr = min( srv_p->icr, (srv_p->tbe > srv_p->frtt) ? 4311da177e4SLinus Torvalds ((srv_p->tbe/srv_p->frtt)*1000000) : 4321da177e4SLinus Torvalds (1000000/(srv_p->frtt/srv_p->tbe))); 4331da177e4SLinus Torvalds f_abr_vc->f_icr = cellrate_to_float(icr); 4341da177e4SLinus Torvalds adtf = (10000 * srv_p->adtf)/8192; 4351da177e4SLinus Torvalds if (adtf == 0) adtf = 1; 4361da177e4SLinus Torvalds f_abr_vc->f_cdf = ((7 - srv_p->cdf) << 12 | adtf) & 0xfff; 4371da177e4SLinus Torvalds f_abr_vc->f_mcr = cellrate_to_float(srv_p->mcr); 4381da177e4SLinus Torvalds f_abr_vc->f_acr = f_abr_vc->f_icr; 4391da177e4SLinus Torvalds f_abr_vc->f_status = 0x0042; 4401da177e4SLinus Torvalds break; 4411da177e4SLinus Torvalds case 0: /* RFRED initialization */ 4421da177e4SLinus Torvalds ptr16 = (u_short *)(dev->reass_ram + REASS_TABLE*dev->memSize); 4431da177e4SLinus Torvalds *(ptr16 + vcc->vci) = NO_AAL5_PKT | REASS_ABR; 4441da177e4SLinus Torvalds r_abr_vc = (r_vc_abr_entry*)(dev->reass_ram+ABR_VC_TABLE*dev->memSize); 4451da177e4SLinus Torvalds r_abr_vc += vcc->vci; 4461da177e4SLinus Torvalds r_abr_vc->r_status_rdf = (15 - srv_p->rdf) & 0x000f; 4471da177e4SLinus Torvalds air = srv_p->pcr << (15 - srv_p->rif); 4481da177e4SLinus Torvalds if (air == 0) air = 1; 4491da177e4SLinus Torvalds r_abr_vc->r_air = cellrate_to_float(air); 4501da177e4SLinus Torvalds dev->testTable[vcc->vci]->vc_status = VC_ACTIVE | VC_ABR; 4511da177e4SLinus Torvalds dev->sum_mcr += srv_p->mcr; 4521da177e4SLinus Torvalds dev->n_abr++; 4531da177e4SLinus Torvalds break; 4541da177e4SLinus Torvalds default: 4551da177e4SLinus Torvalds break; 4561da177e4SLinus Torvalds } 4571da177e4SLinus Torvalds return 0; 4581da177e4SLinus Torvalds } 4591da177e4SLinus Torvalds static int ia_cbr_setup (IADEV *dev, struct atm_vcc *vcc) { 4601da177e4SLinus Torvalds u32 rateLow=0, rateHigh, rate; 4611da177e4SLinus Torvalds int entries; 4621da177e4SLinus Torvalds struct ia_vcc *ia_vcc; 4631da177e4SLinus Torvalds 4641da177e4SLinus Torvalds int idealSlot =0, testSlot, toBeAssigned, inc; 4651da177e4SLinus Torvalds u32 spacing; 4661da177e4SLinus Torvalds u16 *SchedTbl, *TstSchedTbl; 4671da177e4SLinus Torvalds u16 cbrVC, vcIndex; 4681da177e4SLinus Torvalds u32 fracSlot = 0; 4691da177e4SLinus Torvalds u32 sp_mod = 0; 4701da177e4SLinus Torvalds u32 sp_mod2 = 0; 4711da177e4SLinus Torvalds 4721da177e4SLinus Torvalds /* IpAdjustTrafficParams */ 4731da177e4SLinus Torvalds if (vcc->qos.txtp.max_pcr <= 0) { 4741da177e4SLinus Torvalds IF_ERR(printk("PCR for CBR not defined\n");) 4751da177e4SLinus Torvalds return -1; 4761da177e4SLinus Torvalds } 4771da177e4SLinus Torvalds rate = vcc->qos.txtp.max_pcr; 4781da177e4SLinus Torvalds entries = rate / dev->Granularity; 4791da177e4SLinus Torvalds IF_CBR(printk("CBR: CBR entries=0x%x for rate=0x%x & Gran=0x%x\n", 4801da177e4SLinus Torvalds entries, rate, dev->Granularity);) 4811da177e4SLinus Torvalds if (entries < 1) 4821da177e4SLinus Torvalds IF_CBR(printk("CBR: Bandwidth smaller than granularity of CBR table\n");) 4831da177e4SLinus Torvalds rateLow = entries * dev->Granularity; 4841da177e4SLinus Torvalds rateHigh = (entries + 1) * dev->Granularity; 4851da177e4SLinus Torvalds if (3*(rate - rateLow) > (rateHigh - rate)) 4861da177e4SLinus Torvalds entries++; 4871da177e4SLinus Torvalds if (entries > dev->CbrRemEntries) { 4881da177e4SLinus Torvalds IF_CBR(printk("CBR: Not enough bandwidth to support this PCR.\n");) 4891da177e4SLinus Torvalds IF_CBR(printk("Entries = 0x%x, CbrRemEntries = 0x%x.\n", 4901da177e4SLinus Torvalds entries, dev->CbrRemEntries);) 4911da177e4SLinus Torvalds return -EBUSY; 4921da177e4SLinus Torvalds } 4931da177e4SLinus Torvalds 4941da177e4SLinus Torvalds ia_vcc = INPH_IA_VCC(vcc); 4951da177e4SLinus Torvalds ia_vcc->NumCbrEntry = entries; 4961da177e4SLinus Torvalds dev->sum_mcr += entries * dev->Granularity; 4971da177e4SLinus Torvalds /* IaFFrednInsertCbrSched */ 4981da177e4SLinus Torvalds // Starting at an arbitrary location, place the entries into the table 4991da177e4SLinus Torvalds // as smoothly as possible 5001da177e4SLinus Torvalds cbrVC = 0; 5011da177e4SLinus Torvalds spacing = dev->CbrTotEntries / entries; 5021da177e4SLinus Torvalds sp_mod = dev->CbrTotEntries % entries; // get modulo 5031da177e4SLinus Torvalds toBeAssigned = entries; 5041da177e4SLinus Torvalds fracSlot = 0; 5051da177e4SLinus Torvalds vcIndex = vcc->vci; 5061da177e4SLinus Torvalds IF_CBR(printk("Vci=0x%x,Spacing=0x%x,Sp_mod=0x%x\n",vcIndex,spacing,sp_mod);) 5071da177e4SLinus Torvalds while (toBeAssigned) 5081da177e4SLinus Torvalds { 5091da177e4SLinus Torvalds // If this is the first time, start the table loading for this connection 5101da177e4SLinus Torvalds // as close to entryPoint as possible. 5111da177e4SLinus Torvalds if (toBeAssigned == entries) 5121da177e4SLinus Torvalds { 5131da177e4SLinus Torvalds idealSlot = dev->CbrEntryPt; 5141da177e4SLinus Torvalds dev->CbrEntryPt += 2; // Adding 2 helps to prevent clumping 5151da177e4SLinus Torvalds if (dev->CbrEntryPt >= dev->CbrTotEntries) 5161da177e4SLinus Torvalds dev->CbrEntryPt -= dev->CbrTotEntries;// Wrap if necessary 5171da177e4SLinus Torvalds } else { 5181da177e4SLinus Torvalds idealSlot += (u32)(spacing + fracSlot); // Point to the next location 5191da177e4SLinus Torvalds // in the table that would be smoothest 5201da177e4SLinus Torvalds fracSlot = ((sp_mod + sp_mod2) / entries); // get new integer part 5211da177e4SLinus Torvalds sp_mod2 = ((sp_mod + sp_mod2) % entries); // calc new fractional part 5221da177e4SLinus Torvalds } 5231da177e4SLinus Torvalds if (idealSlot >= (int)dev->CbrTotEntries) 5241da177e4SLinus Torvalds idealSlot -= dev->CbrTotEntries; 5251da177e4SLinus Torvalds // Continuously check around this ideal value until a null 5261da177e4SLinus Torvalds // location is encountered. 5271da177e4SLinus Torvalds SchedTbl = (u16*)(dev->seg_ram+CBR_SCHED_TABLE*dev->memSize); 5281da177e4SLinus Torvalds inc = 0; 5291da177e4SLinus Torvalds testSlot = idealSlot; 5301da177e4SLinus Torvalds TstSchedTbl = (u16*)(SchedTbl+testSlot); //set index and read in value 531849e8caaSDavid Howells IF_CBR(printk("CBR Testslot 0x%x AT Location 0x%p, NumToAssign=%d\n", 532849e8caaSDavid Howells testSlot, TstSchedTbl,toBeAssigned);) 5331da177e4SLinus Torvalds memcpy((caddr_t)&cbrVC,(caddr_t)TstSchedTbl,sizeof(cbrVC)); 5341da177e4SLinus Torvalds while (cbrVC) // If another VC at this location, we have to keep looking 5351da177e4SLinus Torvalds { 5361da177e4SLinus Torvalds inc++; 5371da177e4SLinus Torvalds testSlot = idealSlot - inc; 5381da177e4SLinus Torvalds if (testSlot < 0) { // Wrap if necessary 5391da177e4SLinus Torvalds testSlot += dev->CbrTotEntries; 540849e8caaSDavid Howells IF_CBR(printk("Testslot Wrap. STable Start=0x%p,Testslot=%d\n", 541849e8caaSDavid Howells SchedTbl,testSlot);) 5421da177e4SLinus Torvalds } 5431da177e4SLinus Torvalds TstSchedTbl = (u16 *)(SchedTbl + testSlot); // set table index 5441da177e4SLinus Torvalds memcpy((caddr_t)&cbrVC,(caddr_t)TstSchedTbl,sizeof(cbrVC)); 5451da177e4SLinus Torvalds if (!cbrVC) 5461da177e4SLinus Torvalds break; 5471da177e4SLinus Torvalds testSlot = idealSlot + inc; 5481da177e4SLinus Torvalds if (testSlot >= (int)dev->CbrTotEntries) { // Wrap if necessary 5491da177e4SLinus Torvalds testSlot -= dev->CbrTotEntries; 5501da177e4SLinus Torvalds IF_CBR(printk("TotCbrEntries=%d",dev->CbrTotEntries);) 5511da177e4SLinus Torvalds IF_CBR(printk(" Testslot=0x%x ToBeAssgned=%d\n", 5521da177e4SLinus Torvalds testSlot, toBeAssigned);) 5531da177e4SLinus Torvalds } 5541da177e4SLinus Torvalds // set table index and read in value 5551da177e4SLinus Torvalds TstSchedTbl = (u16*)(SchedTbl + testSlot); 556849e8caaSDavid Howells IF_CBR(printk("Reading CBR Tbl from 0x%p, CbrVal=0x%x Iteration %d\n", 557849e8caaSDavid Howells TstSchedTbl,cbrVC,inc);) 5581da177e4SLinus Torvalds memcpy((caddr_t)&cbrVC,(caddr_t)TstSchedTbl,sizeof(cbrVC)); 5591da177e4SLinus Torvalds } /* while */ 5601da177e4SLinus Torvalds // Move this VCI number into this location of the CBR Sched table. 561710708e8SJulia Lawall memcpy((caddr_t)TstSchedTbl, (caddr_t)&vcIndex, sizeof(*TstSchedTbl)); 5621da177e4SLinus Torvalds dev->CbrRemEntries--; 5631da177e4SLinus Torvalds toBeAssigned--; 5641da177e4SLinus Torvalds } /* while */ 5651da177e4SLinus Torvalds 5661da177e4SLinus Torvalds /* IaFFrednCbrEnable */ 5671da177e4SLinus Torvalds dev->NumEnabledCBR++; 5681da177e4SLinus Torvalds if (dev->NumEnabledCBR == 1) { 5691da177e4SLinus Torvalds writew((CBR_EN | UBR_EN | ABR_EN | (0x23 << 2)), dev->seg_reg+STPARMS); 5701da177e4SLinus Torvalds IF_CBR(printk("CBR is enabled\n");) 5711da177e4SLinus Torvalds } 5721da177e4SLinus Torvalds return 0; 5731da177e4SLinus Torvalds } 5741da177e4SLinus Torvalds static void ia_cbrVc_close (struct atm_vcc *vcc) { 5751da177e4SLinus Torvalds IADEV *iadev; 5761da177e4SLinus Torvalds u16 *SchedTbl, NullVci = 0; 5771da177e4SLinus Torvalds u32 i, NumFound; 5781da177e4SLinus Torvalds 5791da177e4SLinus Torvalds iadev = INPH_IA_DEV(vcc->dev); 5801da177e4SLinus Torvalds iadev->NumEnabledCBR--; 5811da177e4SLinus Torvalds SchedTbl = (u16*)(iadev->seg_ram+CBR_SCHED_TABLE*iadev->memSize); 5821da177e4SLinus Torvalds if (iadev->NumEnabledCBR == 0) { 5831da177e4SLinus Torvalds writew((UBR_EN | ABR_EN | (0x23 << 2)), iadev->seg_reg+STPARMS); 5841da177e4SLinus Torvalds IF_CBR (printk("CBR support disabled\n");) 5851da177e4SLinus Torvalds } 5861da177e4SLinus Torvalds NumFound = 0; 5871da177e4SLinus Torvalds for (i=0; i < iadev->CbrTotEntries; i++) 5881da177e4SLinus Torvalds { 5891da177e4SLinus Torvalds if (*SchedTbl == vcc->vci) { 5901da177e4SLinus Torvalds iadev->CbrRemEntries++; 5911da177e4SLinus Torvalds *SchedTbl = NullVci; 5921da177e4SLinus Torvalds IF_CBR(NumFound++;) 5931da177e4SLinus Torvalds } 5941da177e4SLinus Torvalds SchedTbl++; 5951da177e4SLinus Torvalds } 5961da177e4SLinus Torvalds IF_CBR(printk("Exit ia_cbrVc_close, NumRemoved=%d\n",NumFound);) 5971da177e4SLinus Torvalds } 5981da177e4SLinus Torvalds 5991da177e4SLinus Torvalds static int ia_avail_descs(IADEV *iadev) { 6001da177e4SLinus Torvalds int tmp = 0; 6011da177e4SLinus Torvalds ia_hack_tcq(iadev); 6021da177e4SLinus Torvalds if (iadev->host_tcq_wr >= iadev->ffL.tcq_rd) 6031da177e4SLinus Torvalds tmp = (iadev->host_tcq_wr - iadev->ffL.tcq_rd) / 2; 6041da177e4SLinus Torvalds else 6051da177e4SLinus Torvalds tmp = (iadev->ffL.tcq_ed - iadev->ffL.tcq_rd + 2 + iadev->host_tcq_wr - 6061da177e4SLinus Torvalds iadev->ffL.tcq_st) / 2; 6071da177e4SLinus Torvalds return tmp; 6081da177e4SLinus Torvalds } 6091da177e4SLinus Torvalds 6101da177e4SLinus Torvalds static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb); 6111da177e4SLinus Torvalds 6121da177e4SLinus Torvalds static int ia_que_tx (IADEV *iadev) { 6131da177e4SLinus Torvalds struct sk_buff *skb; 6141da177e4SLinus Torvalds int num_desc; 6151da177e4SLinus Torvalds struct atm_vcc *vcc; 6161da177e4SLinus Torvalds num_desc = ia_avail_descs(iadev); 6171da177e4SLinus Torvalds 6181da177e4SLinus Torvalds while (num_desc && (skb = skb_dequeue(&iadev->tx_backlog))) { 6191da177e4SLinus Torvalds if (!(vcc = ATM_SKB(skb)->vcc)) { 6201da177e4SLinus Torvalds dev_kfree_skb_any(skb); 6211da177e4SLinus Torvalds printk("ia_que_tx: Null vcc\n"); 6221da177e4SLinus Torvalds break; 6231da177e4SLinus Torvalds } 6241da177e4SLinus Torvalds if (!test_bit(ATM_VF_READY,&vcc->flags)) { 6251da177e4SLinus Torvalds dev_kfree_skb_any(skb); 6261da177e4SLinus Torvalds printk("Free the SKB on closed vci %d \n", vcc->vci); 6271da177e4SLinus Torvalds break; 6281da177e4SLinus Torvalds } 6291da177e4SLinus Torvalds if (ia_pkt_tx (vcc, skb)) { 6301da177e4SLinus Torvalds skb_queue_head(&iadev->tx_backlog, skb); 6311da177e4SLinus Torvalds } 6321da177e4SLinus Torvalds num_desc--; 6331da177e4SLinus Torvalds } 6341da177e4SLinus Torvalds return 0; 6351da177e4SLinus Torvalds } 6361da177e4SLinus Torvalds 6371da177e4SLinus Torvalds static void ia_tx_poll (IADEV *iadev) { 6381da177e4SLinus Torvalds struct atm_vcc *vcc = NULL; 6391da177e4SLinus Torvalds struct sk_buff *skb = NULL, *skb1 = NULL; 6401da177e4SLinus Torvalds struct ia_vcc *iavcc; 6411da177e4SLinus Torvalds IARTN_Q * rtne; 6421da177e4SLinus Torvalds 6431da177e4SLinus Torvalds ia_hack_tcq(iadev); 6441da177e4SLinus Torvalds while ( (rtne = ia_deque_rtn_q(&iadev->tx_return_q))) { 6451da177e4SLinus Torvalds skb = rtne->data.txskb; 6461da177e4SLinus Torvalds if (!skb) { 6471da177e4SLinus Torvalds printk("ia_tx_poll: skb is null\n"); 6481da177e4SLinus Torvalds goto out; 6491da177e4SLinus Torvalds } 6501da177e4SLinus Torvalds vcc = ATM_SKB(skb)->vcc; 6511da177e4SLinus Torvalds if (!vcc) { 6521da177e4SLinus Torvalds printk("ia_tx_poll: vcc is null\n"); 6531da177e4SLinus Torvalds dev_kfree_skb_any(skb); 6541da177e4SLinus Torvalds goto out; 6551da177e4SLinus Torvalds } 6561da177e4SLinus Torvalds 6571da177e4SLinus Torvalds iavcc = INPH_IA_VCC(vcc); 6581da177e4SLinus Torvalds if (!iavcc) { 6591da177e4SLinus Torvalds printk("ia_tx_poll: iavcc is null\n"); 6601da177e4SLinus Torvalds dev_kfree_skb_any(skb); 6611da177e4SLinus Torvalds goto out; 6621da177e4SLinus Torvalds } 6631da177e4SLinus Torvalds 6641da177e4SLinus Torvalds skb1 = skb_dequeue(&iavcc->txing_skb); 6651da177e4SLinus Torvalds while (skb1 && (skb1 != skb)) { 6661da177e4SLinus Torvalds if (!(IA_SKB_STATE(skb1) & IA_TX_DONE)) { 6671da177e4SLinus Torvalds printk("IA_tx_intr: Vci %d lost pkt!!!\n", vcc->vci); 6681da177e4SLinus Torvalds } 6691da177e4SLinus Torvalds IF_ERR(printk("Release the SKB not match\n");) 6701da177e4SLinus Torvalds if ((vcc->pop) && (skb1->len != 0)) 6711da177e4SLinus Torvalds { 6721da177e4SLinus Torvalds vcc->pop(vcc, skb1); 6731da177e4SLinus Torvalds IF_EVENT(printk("Tansmit Done - skb 0x%lx return\n", 6741da177e4SLinus Torvalds (long)skb1);) 6751da177e4SLinus Torvalds } 6761da177e4SLinus Torvalds else 6771da177e4SLinus Torvalds dev_kfree_skb_any(skb1); 6781da177e4SLinus Torvalds skb1 = skb_dequeue(&iavcc->txing_skb); 6791da177e4SLinus Torvalds } 6801da177e4SLinus Torvalds if (!skb1) { 6811da177e4SLinus Torvalds IF_EVENT(printk("IA: Vci %d - skb not found requed\n",vcc->vci);) 6821da177e4SLinus Torvalds ia_enque_head_rtn_q (&iadev->tx_return_q, rtne); 6831da177e4SLinus Torvalds break; 6841da177e4SLinus Torvalds } 6851da177e4SLinus Torvalds if ((vcc->pop) && (skb->len != 0)) 6861da177e4SLinus Torvalds { 6871da177e4SLinus Torvalds vcc->pop(vcc, skb); 6881da177e4SLinus Torvalds IF_EVENT(printk("Tx Done - skb 0x%lx return\n",(long)skb);) 6891da177e4SLinus Torvalds } 6901da177e4SLinus Torvalds else 6911da177e4SLinus Torvalds dev_kfree_skb_any(skb); 6921da177e4SLinus Torvalds kfree(rtne); 6931da177e4SLinus Torvalds } 6941da177e4SLinus Torvalds ia_que_tx(iadev); 6951da177e4SLinus Torvalds out: 6961da177e4SLinus Torvalds return; 6971da177e4SLinus Torvalds } 6981da177e4SLinus Torvalds #if 0 6991da177e4SLinus Torvalds static void ia_eeprom_put (IADEV *iadev, u32 addr, u_short val) 7001da177e4SLinus Torvalds { 7011da177e4SLinus Torvalds u32 t; 7021da177e4SLinus Torvalds int i; 7031da177e4SLinus Torvalds /* 7041da177e4SLinus Torvalds * Issue a command to enable writes to the NOVRAM 7051da177e4SLinus Torvalds */ 7061da177e4SLinus Torvalds NVRAM_CMD (EXTEND + EWEN); 7071da177e4SLinus Torvalds NVRAM_CLR_CE; 7081da177e4SLinus Torvalds /* 7091da177e4SLinus Torvalds * issue the write command 7101da177e4SLinus Torvalds */ 7111da177e4SLinus Torvalds NVRAM_CMD(IAWRITE + addr); 7121da177e4SLinus Torvalds /* 7131da177e4SLinus Torvalds * Send the data, starting with D15, then D14, and so on for 16 bits 7141da177e4SLinus Torvalds */ 7151da177e4SLinus Torvalds for (i=15; i>=0; i--) { 7161da177e4SLinus Torvalds NVRAM_CLKOUT (val & 0x8000); 7171da177e4SLinus Torvalds val <<= 1; 7181da177e4SLinus Torvalds } 7191da177e4SLinus Torvalds NVRAM_CLR_CE; 7201da177e4SLinus Torvalds CFG_OR(NVCE); 7211da177e4SLinus Torvalds t = readl(iadev->reg+IPHASE5575_EEPROM_ACCESS); 7221da177e4SLinus Torvalds while (!(t & NVDO)) 7231da177e4SLinus Torvalds t = readl(iadev->reg+IPHASE5575_EEPROM_ACCESS); 7241da177e4SLinus Torvalds 7251da177e4SLinus Torvalds NVRAM_CLR_CE; 7261da177e4SLinus Torvalds /* 7271da177e4SLinus Torvalds * disable writes again 7281da177e4SLinus Torvalds */ 7291da177e4SLinus Torvalds NVRAM_CMD(EXTEND + EWDS) 7301da177e4SLinus Torvalds NVRAM_CLR_CE; 7311da177e4SLinus Torvalds CFG_AND(~NVDI); 7321da177e4SLinus Torvalds } 7331da177e4SLinus Torvalds #endif 7341da177e4SLinus Torvalds 7351da177e4SLinus Torvalds static u16 ia_eeprom_get (IADEV *iadev, u32 addr) 7361da177e4SLinus Torvalds { 7371da177e4SLinus Torvalds u_short val; 7381da177e4SLinus Torvalds u32 t; 7391da177e4SLinus Torvalds int i; 7401da177e4SLinus Torvalds /* 7411da177e4SLinus Torvalds * Read the first bit that was clocked with the falling edge of the 7421da177e4SLinus Torvalds * the last command data clock 7431da177e4SLinus Torvalds */ 7441da177e4SLinus Torvalds NVRAM_CMD(IAREAD + addr); 7451da177e4SLinus Torvalds /* 7461da177e4SLinus Torvalds * Now read the rest of the bits, the next bit read is D14, then D13, 7471da177e4SLinus Torvalds * and so on. 7481da177e4SLinus Torvalds */ 7491da177e4SLinus Torvalds val = 0; 7501da177e4SLinus Torvalds for (i=15; i>=0; i--) { 7511da177e4SLinus Torvalds NVRAM_CLKIN(t); 7521da177e4SLinus Torvalds val |= (t << i); 7531da177e4SLinus Torvalds } 7541da177e4SLinus Torvalds NVRAM_CLR_CE; 7551da177e4SLinus Torvalds CFG_AND(~NVDI); 7561da177e4SLinus Torvalds return val; 7571da177e4SLinus Torvalds } 7581da177e4SLinus Torvalds 7591da177e4SLinus Torvalds static void ia_hw_type(IADEV *iadev) { 7601da177e4SLinus Torvalds u_short memType = ia_eeprom_get(iadev, 25); 7611da177e4SLinus Torvalds iadev->memType = memType; 7621da177e4SLinus Torvalds if ((memType & MEM_SIZE_MASK) == MEM_SIZE_1M) { 7631da177e4SLinus Torvalds iadev->num_tx_desc = IA_TX_BUF; 7641da177e4SLinus Torvalds iadev->tx_buf_sz = IA_TX_BUF_SZ; 7651da177e4SLinus Torvalds iadev->num_rx_desc = IA_RX_BUF; 7661da177e4SLinus Torvalds iadev->rx_buf_sz = IA_RX_BUF_SZ; 7671da177e4SLinus Torvalds } else if ((memType & MEM_SIZE_MASK) == MEM_SIZE_512K) { 7681da177e4SLinus Torvalds if (IA_TX_BUF == DFL_TX_BUFFERS) 7691da177e4SLinus Torvalds iadev->num_tx_desc = IA_TX_BUF / 2; 7701da177e4SLinus Torvalds else 7711da177e4SLinus Torvalds iadev->num_tx_desc = IA_TX_BUF; 7721da177e4SLinus Torvalds iadev->tx_buf_sz = IA_TX_BUF_SZ; 7731da177e4SLinus Torvalds if (IA_RX_BUF == DFL_RX_BUFFERS) 7741da177e4SLinus Torvalds iadev->num_rx_desc = IA_RX_BUF / 2; 7751da177e4SLinus Torvalds else 7761da177e4SLinus Torvalds iadev->num_rx_desc = IA_RX_BUF; 7771da177e4SLinus Torvalds iadev->rx_buf_sz = IA_RX_BUF_SZ; 7781da177e4SLinus Torvalds } 7791da177e4SLinus Torvalds else { 7801da177e4SLinus Torvalds if (IA_TX_BUF == DFL_TX_BUFFERS) 7811da177e4SLinus Torvalds iadev->num_tx_desc = IA_TX_BUF / 8; 7821da177e4SLinus Torvalds else 7831da177e4SLinus Torvalds iadev->num_tx_desc = IA_TX_BUF; 7841da177e4SLinus Torvalds iadev->tx_buf_sz = IA_TX_BUF_SZ; 7851da177e4SLinus Torvalds if (IA_RX_BUF == DFL_RX_BUFFERS) 7861da177e4SLinus Torvalds iadev->num_rx_desc = IA_RX_BUF / 8; 7871da177e4SLinus Torvalds else 7881da177e4SLinus Torvalds iadev->num_rx_desc = IA_RX_BUF; 7891da177e4SLinus Torvalds iadev->rx_buf_sz = IA_RX_BUF_SZ; 7901da177e4SLinus Torvalds } 7911da177e4SLinus Torvalds iadev->rx_pkt_ram = TX_PACKET_RAM + (iadev->num_tx_desc * iadev->tx_buf_sz); 7921da177e4SLinus Torvalds IF_INIT(printk("BUF: tx=%d,sz=%d rx=%d sz= %d rx_pkt_ram=%d\n", 7931da177e4SLinus Torvalds iadev->num_tx_desc, iadev->tx_buf_sz, iadev->num_rx_desc, 7941da177e4SLinus Torvalds iadev->rx_buf_sz, iadev->rx_pkt_ram);) 7951da177e4SLinus Torvalds 7961da177e4SLinus Torvalds #if 0 7971da177e4SLinus Torvalds if ((memType & FE_MASK) == FE_SINGLE_MODE) { 7981da177e4SLinus Torvalds iadev->phy_type = PHY_OC3C_S; 7991da177e4SLinus Torvalds else if ((memType & FE_MASK) == FE_UTP_OPTION) 8001da177e4SLinus Torvalds iadev->phy_type = PHY_UTP155; 8011da177e4SLinus Torvalds else 8021da177e4SLinus Torvalds iadev->phy_type = PHY_OC3C_M; 8031da177e4SLinus Torvalds #endif 8041da177e4SLinus Torvalds 8051da177e4SLinus Torvalds iadev->phy_type = memType & FE_MASK; 8061da177e4SLinus Torvalds IF_INIT(printk("memType = 0x%x iadev->phy_type = 0x%x\n", 8071da177e4SLinus Torvalds memType,iadev->phy_type);) 8081da177e4SLinus Torvalds if (iadev->phy_type == FE_25MBIT_PHY) 8091da177e4SLinus Torvalds iadev->LineRate = (u32)(((25600000/8)*26)/(27*53)); 8101da177e4SLinus Torvalds else if (iadev->phy_type == FE_DS3_PHY) 8111da177e4SLinus Torvalds iadev->LineRate = (u32)(((44736000/8)*26)/(27*53)); 8121da177e4SLinus Torvalds else if (iadev->phy_type == FE_E3_PHY) 8131da177e4SLinus Torvalds iadev->LineRate = (u32)(((34368000/8)*26)/(27*53)); 8141da177e4SLinus Torvalds else 8151da177e4SLinus Torvalds iadev->LineRate = (u32)(ATM_OC3_PCR); 8161da177e4SLinus Torvalds IF_INIT(printk("iadev->LineRate = %d \n", iadev->LineRate);) 8171da177e4SLinus Torvalds 8181da177e4SLinus Torvalds } 8191da177e4SLinus Torvalds 82026c5c44dSfrançois romieu static u32 ia_phy_read32(struct iadev_priv *ia, unsigned int reg) 82126c5c44dSfrançois romieu { 82226c5c44dSfrançois romieu return readl(ia->phy + (reg >> 2)); 82326c5c44dSfrançois romieu } 82426c5c44dSfrançois romieu 82526c5c44dSfrançois romieu static void ia_phy_write32(struct iadev_priv *ia, unsigned int reg, u32 val) 82626c5c44dSfrançois romieu { 82726c5c44dSfrançois romieu writel(val, ia->phy + (reg >> 2)); 82826c5c44dSfrançois romieu } 82926c5c44dSfrançois romieu 83026c5c44dSfrançois romieu static void ia_frontend_intr(struct iadev_priv *iadev) 83126c5c44dSfrançois romieu { 83226c5c44dSfrançois romieu u32 status; 8331da177e4SLinus Torvalds 8341da177e4SLinus Torvalds if (iadev->phy_type & FE_25MBIT_PHY) { 83526c5c44dSfrançois romieu status = ia_phy_read32(iadev, MB25_INTR_STATUS); 83626c5c44dSfrançois romieu iadev->carrier_detect = (status & MB25_IS_GSB) ? 1 : 0; 8371da177e4SLinus Torvalds } else if (iadev->phy_type & FE_DS3_PHY) { 83826c5c44dSfrançois romieu ia_phy_read32(iadev, SUNI_DS3_FRM_INTR_STAT); 83926c5c44dSfrançois romieu status = ia_phy_read32(iadev, SUNI_DS3_FRM_STAT); 84026c5c44dSfrançois romieu iadev->carrier_detect = (status & SUNI_DS3_LOSV) ? 0 : 1; 8411da177e4SLinus Torvalds } else if (iadev->phy_type & FE_E3_PHY) { 84226c5c44dSfrançois romieu ia_phy_read32(iadev, SUNI_E3_FRM_MAINT_INTR_IND); 84326c5c44dSfrançois romieu status = ia_phy_read32(iadev, SUNI_E3_FRM_FRAM_INTR_IND_STAT); 84426c5c44dSfrançois romieu iadev->carrier_detect = (status & SUNI_E3_LOS) ? 0 : 1; 84526c5c44dSfrançois romieu } else { 84626c5c44dSfrançois romieu status = ia_phy_read32(iadev, SUNI_RSOP_STATUS); 84726c5c44dSfrançois romieu iadev->carrier_detect = (status & SUNI_LOSV) ? 0 : 1; 8481da177e4SLinus Torvalds } 8491da177e4SLinus Torvalds 85026c5c44dSfrançois romieu printk(KERN_INFO "IA: SUNI carrier %s\n", 85126c5c44dSfrançois romieu iadev->carrier_detect ? "detected" : "lost signal"); 85226c5c44dSfrançois romieu } 85326c5c44dSfrançois romieu 85426c5c44dSfrançois romieu static void ia_mb25_init(struct iadev_priv *iadev) 8551da177e4SLinus Torvalds { 8561da177e4SLinus Torvalds #if 0 8571da177e4SLinus Torvalds mb25->mb25_master_ctrl = MB25_MC_DRIC | MB25_MC_DREC | MB25_MC_ENABLED; 8581da177e4SLinus Torvalds #endif 85926c5c44dSfrançois romieu ia_phy_write32(iadev, MB25_MASTER_CTRL, MB25_MC_DRIC | MB25_MC_DREC); 86026c5c44dSfrançois romieu ia_phy_write32(iadev, MB25_DIAG_CONTROL, 0); 86126c5c44dSfrançois romieu 86226c5c44dSfrançois romieu iadev->carrier_detect = 86326c5c44dSfrançois romieu (ia_phy_read32(iadev, MB25_INTR_STATUS) & MB25_IS_GSB) ? 1 : 0; 8641da177e4SLinus Torvalds } 8651da177e4SLinus Torvalds 86626c5c44dSfrançois romieu struct ia_reg { 86726c5c44dSfrançois romieu u16 reg; 86826c5c44dSfrançois romieu u16 val; 86926c5c44dSfrançois romieu }; 87026c5c44dSfrançois romieu 87126c5c44dSfrançois romieu static void ia_phy_write(struct iadev_priv *iadev, 87226c5c44dSfrançois romieu const struct ia_reg *regs, int len) 8731da177e4SLinus Torvalds { 87426c5c44dSfrançois romieu while (len--) { 87526c5c44dSfrançois romieu ia_phy_write32(iadev, regs->reg, regs->val); 87626c5c44dSfrançois romieu regs++; 87726c5c44dSfrançois romieu } 87826c5c44dSfrançois romieu } 87926c5c44dSfrançois romieu 88026c5c44dSfrançois romieu static void ia_suni_pm7345_init_ds3(struct iadev_priv *iadev) 88126c5c44dSfrançois romieu { 88226c5c44dSfrançois romieu static const struct ia_reg suni_ds3_init [] = { 88326c5c44dSfrançois romieu { SUNI_DS3_FRM_INTR_ENBL, 0x17 }, 88426c5c44dSfrançois romieu { SUNI_DS3_FRM_CFG, 0x01 }, 88526c5c44dSfrançois romieu { SUNI_DS3_TRAN_CFG, 0x01 }, 88626c5c44dSfrançois romieu { SUNI_CONFIG, 0 }, 88726c5c44dSfrançois romieu { SUNI_SPLR_CFG, 0 }, 88826c5c44dSfrançois romieu { SUNI_SPLT_CFG, 0 } 88926c5c44dSfrançois romieu }; 89026c5c44dSfrançois romieu u32 status; 89126c5c44dSfrançois romieu 89226c5c44dSfrançois romieu status = ia_phy_read32(iadev, SUNI_DS3_FRM_STAT); 89326c5c44dSfrançois romieu iadev->carrier_detect = (status & SUNI_DS3_LOSV) ? 0 : 1; 89426c5c44dSfrançois romieu 89526c5c44dSfrançois romieu ia_phy_write(iadev, suni_ds3_init, ARRAY_SIZE(suni_ds3_init)); 89626c5c44dSfrançois romieu } 89726c5c44dSfrançois romieu 89826c5c44dSfrançois romieu static void ia_suni_pm7345_init_e3(struct iadev_priv *iadev) 89926c5c44dSfrançois romieu { 90026c5c44dSfrançois romieu static const struct ia_reg suni_e3_init [] = { 90126c5c44dSfrançois romieu { SUNI_E3_FRM_FRAM_OPTIONS, 0x04 }, 90226c5c44dSfrançois romieu { SUNI_E3_FRM_MAINT_OPTIONS, 0x20 }, 90326c5c44dSfrançois romieu { SUNI_E3_FRM_FRAM_INTR_ENBL, 0x1d }, 90426c5c44dSfrançois romieu { SUNI_E3_FRM_MAINT_INTR_ENBL, 0x30 }, 90526c5c44dSfrançois romieu { SUNI_E3_TRAN_STAT_DIAG_OPTIONS, 0 }, 90626c5c44dSfrançois romieu { SUNI_E3_TRAN_FRAM_OPTIONS, 0x01 }, 90726c5c44dSfrançois romieu { SUNI_CONFIG, SUNI_PM7345_E3ENBL }, 90826c5c44dSfrançois romieu { SUNI_SPLR_CFG, 0x41 }, 90926c5c44dSfrançois romieu { SUNI_SPLT_CFG, 0x41 } 91026c5c44dSfrançois romieu }; 91126c5c44dSfrançois romieu u32 status; 91226c5c44dSfrançois romieu 91326c5c44dSfrançois romieu status = ia_phy_read32(iadev, SUNI_E3_FRM_FRAM_INTR_IND_STAT); 91426c5c44dSfrançois romieu iadev->carrier_detect = (status & SUNI_E3_LOS) ? 0 : 1; 91526c5c44dSfrançois romieu ia_phy_write(iadev, suni_e3_init, ARRAY_SIZE(suni_e3_init)); 91626c5c44dSfrançois romieu } 91726c5c44dSfrançois romieu 91826c5c44dSfrançois romieu static void ia_suni_pm7345_init(struct iadev_priv *iadev) 91926c5c44dSfrançois romieu { 92026c5c44dSfrançois romieu static const struct ia_reg suni_init [] = { 92126c5c44dSfrançois romieu /* Enable RSOP loss of signal interrupt. */ 92226c5c44dSfrançois romieu { SUNI_INTR_ENBL, 0x28 }, 92326c5c44dSfrançois romieu /* Clear error counters. */ 92426c5c44dSfrançois romieu { SUNI_ID_RESET, 0 }, 92526c5c44dSfrançois romieu /* Clear "PMCTST" in master test register. */ 92626c5c44dSfrançois romieu { SUNI_MASTER_TEST, 0 }, 92726c5c44dSfrançois romieu 92826c5c44dSfrançois romieu { SUNI_RXCP_CTRL, 0x2c }, 92926c5c44dSfrançois romieu { SUNI_RXCP_FCTRL, 0x81 }, 93026c5c44dSfrançois romieu 93126c5c44dSfrançois romieu { SUNI_RXCP_IDLE_PAT_H1, 0 }, 93226c5c44dSfrançois romieu { SUNI_RXCP_IDLE_PAT_H2, 0 }, 93326c5c44dSfrançois romieu { SUNI_RXCP_IDLE_PAT_H3, 0 }, 93426c5c44dSfrançois romieu { SUNI_RXCP_IDLE_PAT_H4, 0x01 }, 93526c5c44dSfrançois romieu 93626c5c44dSfrançois romieu { SUNI_RXCP_IDLE_MASK_H1, 0xff }, 93726c5c44dSfrançois romieu { SUNI_RXCP_IDLE_MASK_H2, 0xff }, 93826c5c44dSfrançois romieu { SUNI_RXCP_IDLE_MASK_H3, 0xff }, 93926c5c44dSfrançois romieu { SUNI_RXCP_IDLE_MASK_H4, 0xfe }, 94026c5c44dSfrançois romieu 94126c5c44dSfrançois romieu { SUNI_RXCP_CELL_PAT_H1, 0 }, 94226c5c44dSfrançois romieu { SUNI_RXCP_CELL_PAT_H2, 0 }, 94326c5c44dSfrançois romieu { SUNI_RXCP_CELL_PAT_H3, 0 }, 94426c5c44dSfrançois romieu { SUNI_RXCP_CELL_PAT_H4, 0x01 }, 94526c5c44dSfrançois romieu 94626c5c44dSfrançois romieu { SUNI_RXCP_CELL_MASK_H1, 0xff }, 94726c5c44dSfrançois romieu { SUNI_RXCP_CELL_MASK_H2, 0xff }, 94826c5c44dSfrançois romieu { SUNI_RXCP_CELL_MASK_H3, 0xff }, 94926c5c44dSfrançois romieu { SUNI_RXCP_CELL_MASK_H4, 0xff }, 95026c5c44dSfrançois romieu 95126c5c44dSfrançois romieu { SUNI_TXCP_CTRL, 0xa4 }, 95226c5c44dSfrançois romieu { SUNI_TXCP_INTR_EN_STS, 0x10 }, 95326c5c44dSfrançois romieu { SUNI_TXCP_IDLE_PAT_H5, 0x55 } 95426c5c44dSfrançois romieu }; 95526c5c44dSfrançois romieu 9561da177e4SLinus Torvalds if (iadev->phy_type & FE_DS3_PHY) 95726c5c44dSfrançois romieu ia_suni_pm7345_init_ds3(iadev); 9581da177e4SLinus Torvalds else 95926c5c44dSfrançois romieu ia_suni_pm7345_init_e3(iadev); 9601da177e4SLinus Torvalds 96126c5c44dSfrançois romieu ia_phy_write(iadev, suni_init, ARRAY_SIZE(suni_init)); 9621da177e4SLinus Torvalds 96326c5c44dSfrançois romieu ia_phy_write32(iadev, SUNI_CONFIG, ia_phy_read32(iadev, SUNI_CONFIG) & 96426c5c44dSfrançois romieu ~(SUNI_PM7345_LLB | SUNI_PM7345_CLB | 96526c5c44dSfrançois romieu SUNI_PM7345_DLB | SUNI_PM7345_PLB)); 9661da177e4SLinus Torvalds #ifdef __SNMP__ 9671da177e4SLinus Torvalds suni_pm7345->suni_rxcp_intr_en_sts |= SUNI_OOCDE; 9681da177e4SLinus Torvalds #endif /* __SNMP__ */ 9691da177e4SLinus Torvalds return; 9701da177e4SLinus Torvalds } 9711da177e4SLinus Torvalds 9721da177e4SLinus Torvalds 9731da177e4SLinus Torvalds /***************************** IA_LIB END *****************************/ 9741da177e4SLinus Torvalds 975a22eb6faSLeonardo Potenza #ifdef CONFIG_ATM_IA_DEBUG 9761da177e4SLinus Torvalds static int tcnter = 0; 9771da177e4SLinus Torvalds static void xdump( u_char* cp, int length, char* prefix ) 9781da177e4SLinus Torvalds { 9791da177e4SLinus Torvalds int col, count; 9801da177e4SLinus Torvalds u_char prntBuf[120]; 9811da177e4SLinus Torvalds u_char* pBuf = prntBuf; 9821da177e4SLinus Torvalds count = 0; 9831da177e4SLinus Torvalds while(count < length){ 9841da177e4SLinus Torvalds pBuf += sprintf( pBuf, "%s", prefix ); 9851da177e4SLinus Torvalds for(col = 0;count + col < length && col < 16; col++){ 9861da177e4SLinus Torvalds if (col != 0 && (col % 4) == 0) 9871da177e4SLinus Torvalds pBuf += sprintf( pBuf, " " ); 9881da177e4SLinus Torvalds pBuf += sprintf( pBuf, "%02X ", cp[count + col] ); 9891da177e4SLinus Torvalds } 9901da177e4SLinus Torvalds while(col++ < 16){ /* pad end of buffer with blanks */ 9911da177e4SLinus Torvalds if ((col % 4) == 0) 9921da177e4SLinus Torvalds sprintf( pBuf, " " ); 9931da177e4SLinus Torvalds pBuf += sprintf( pBuf, " " ); 9941da177e4SLinus Torvalds } 9951da177e4SLinus Torvalds pBuf += sprintf( pBuf, " " ); 9961da177e4SLinus Torvalds for(col = 0;count + col < length && col < 16; col++){ 9971da177e4SLinus Torvalds if (isprint((int)cp[count + col])) 9981da177e4SLinus Torvalds pBuf += sprintf( pBuf, "%c", cp[count + col] ); 9991da177e4SLinus Torvalds else 10001da177e4SLinus Torvalds pBuf += sprintf( pBuf, "." ); 10011da177e4SLinus Torvalds } 100232f3dde5SStephen Hemminger printk("%s\n", prntBuf); 10031da177e4SLinus Torvalds count += col; 10041da177e4SLinus Torvalds pBuf = prntBuf; 10051da177e4SLinus Torvalds } 10061da177e4SLinus Torvalds 10071da177e4SLinus Torvalds } /* close xdump(... */ 1008a22eb6faSLeonardo Potenza #endif /* CONFIG_ATM_IA_DEBUG */ 10091da177e4SLinus Torvalds 10101da177e4SLinus Torvalds 10111da177e4SLinus Torvalds static struct atm_dev *ia_boards = NULL; 10121da177e4SLinus Torvalds 10131da177e4SLinus Torvalds #define ACTUAL_RAM_BASE \ 10141da177e4SLinus Torvalds RAM_BASE*((iadev->mem)/(128 * 1024)) 10151da177e4SLinus Torvalds #define ACTUAL_SEG_RAM_BASE \ 10161da177e4SLinus Torvalds IPHASE5575_FRAG_CONTROL_RAM_BASE*((iadev->mem)/(128 * 1024)) 10171da177e4SLinus Torvalds #define ACTUAL_REASS_RAM_BASE \ 10181da177e4SLinus Torvalds IPHASE5575_REASS_CONTROL_RAM_BASE*((iadev->mem)/(128 * 1024)) 10191da177e4SLinus Torvalds 10201da177e4SLinus Torvalds 10211da177e4SLinus Torvalds /*-- some utilities and memory allocation stuff will come here -------------*/ 10221da177e4SLinus Torvalds 10231da177e4SLinus Torvalds static void desc_dbg(IADEV *iadev) { 10241da177e4SLinus Torvalds 10251da177e4SLinus Torvalds u_short tcq_wr_ptr, tcq_st_ptr, tcq_ed_ptr; 10261da177e4SLinus Torvalds u32 i; 10271da177e4SLinus Torvalds void __iomem *tmp; 10281da177e4SLinus Torvalds // regval = readl((u32)ia_cmds->maddr); 10291da177e4SLinus Torvalds tcq_wr_ptr = readw(iadev->seg_reg+TCQ_WR_PTR); 10301da177e4SLinus Torvalds printk("B_tcq_wr = 0x%x desc = %d last desc = %d\n", 10311da177e4SLinus Torvalds tcq_wr_ptr, readw(iadev->seg_ram+tcq_wr_ptr), 10321da177e4SLinus Torvalds readw(iadev->seg_ram+tcq_wr_ptr-2)); 10331da177e4SLinus Torvalds printk(" host_tcq_wr = 0x%x host_tcq_rd = 0x%x \n", iadev->host_tcq_wr, 10341da177e4SLinus Torvalds iadev->ffL.tcq_rd); 10351da177e4SLinus Torvalds tcq_st_ptr = readw(iadev->seg_reg+TCQ_ST_ADR); 10361da177e4SLinus Torvalds tcq_ed_ptr = readw(iadev->seg_reg+TCQ_ED_ADR); 10371da177e4SLinus Torvalds printk("tcq_st_ptr = 0x%x tcq_ed_ptr = 0x%x \n", tcq_st_ptr, tcq_ed_ptr); 10381da177e4SLinus Torvalds i = 0; 10391da177e4SLinus Torvalds while (tcq_st_ptr != tcq_ed_ptr) { 10401da177e4SLinus Torvalds tmp = iadev->seg_ram+tcq_st_ptr; 10411da177e4SLinus Torvalds printk("TCQ slot %d desc = %d Addr = %p\n", i++, readw(tmp), tmp); 10421da177e4SLinus Torvalds tcq_st_ptr += 2; 10431da177e4SLinus Torvalds } 10441da177e4SLinus Torvalds for(i=0; i <iadev->num_tx_desc; i++) 10451da177e4SLinus Torvalds printk("Desc_tbl[%d] = %d \n", i, iadev->desc_tbl[i].timestamp); 10461da177e4SLinus Torvalds } 10471da177e4SLinus Torvalds 10481da177e4SLinus Torvalds 104925985edcSLucas De Marchi /*----------------------------- Receiving side stuff --------------------------*/ 10501da177e4SLinus Torvalds 10511da177e4SLinus Torvalds static void rx_excp_rcvd(struct atm_dev *dev) 10521da177e4SLinus Torvalds { 10531da177e4SLinus Torvalds #if 0 /* closing the receiving size will cause too many excp int */ 10541da177e4SLinus Torvalds IADEV *iadev; 10551da177e4SLinus Torvalds u_short state; 10561da177e4SLinus Torvalds u_short excpq_rd_ptr; 10571da177e4SLinus Torvalds //u_short *ptr; 10581da177e4SLinus Torvalds int vci, error = 1; 10591da177e4SLinus Torvalds iadev = INPH_IA_DEV(dev); 10601da177e4SLinus Torvalds state = readl(iadev->reass_reg + STATE_REG) & 0xffff; 10611da177e4SLinus Torvalds while((state & EXCPQ_EMPTY) != EXCPQ_EMPTY) 10621da177e4SLinus Torvalds { printk("state = %x \n", state); 10631da177e4SLinus Torvalds excpq_rd_ptr = readw(iadev->reass_reg + EXCP_Q_RD_PTR) & 0xffff; 10641da177e4SLinus Torvalds printk("state = %x excpq_rd_ptr = %x \n", state, excpq_rd_ptr); 10651da177e4SLinus Torvalds if (excpq_rd_ptr == *(u16*)(iadev->reass_reg + EXCP_Q_WR_PTR)) 10661da177e4SLinus Torvalds IF_ERR(printk("excpq_rd_ptr is wrong!!!\n");) 10671da177e4SLinus Torvalds // TODO: update exception stat 10681da177e4SLinus Torvalds vci = readw(iadev->reass_ram+excpq_rd_ptr); 10691da177e4SLinus Torvalds error = readw(iadev->reass_ram+excpq_rd_ptr+2) & 0x0007; 10701da177e4SLinus Torvalds // pwang_test 10711da177e4SLinus Torvalds excpq_rd_ptr += 4; 10721da177e4SLinus Torvalds if (excpq_rd_ptr > (readw(iadev->reass_reg + EXCP_Q_ED_ADR)& 0xffff)) 10731da177e4SLinus Torvalds excpq_rd_ptr = readw(iadev->reass_reg + EXCP_Q_ST_ADR)& 0xffff; 10741da177e4SLinus Torvalds writew( excpq_rd_ptr, iadev->reass_reg + EXCP_Q_RD_PTR); 10751da177e4SLinus Torvalds state = readl(iadev->reass_reg + STATE_REG) & 0xffff; 10761da177e4SLinus Torvalds } 10771da177e4SLinus Torvalds #endif 10781da177e4SLinus Torvalds } 10791da177e4SLinus Torvalds 10801da177e4SLinus Torvalds static void free_desc(struct atm_dev *dev, int desc) 10811da177e4SLinus Torvalds { 10821da177e4SLinus Torvalds IADEV *iadev; 10831da177e4SLinus Torvalds iadev = INPH_IA_DEV(dev); 10841da177e4SLinus Torvalds writew(desc, iadev->reass_ram+iadev->rfL.fdq_wr); 10851da177e4SLinus Torvalds iadev->rfL.fdq_wr +=2; 10861da177e4SLinus Torvalds if (iadev->rfL.fdq_wr > iadev->rfL.fdq_ed) 10871da177e4SLinus Torvalds iadev->rfL.fdq_wr = iadev->rfL.fdq_st; 10881da177e4SLinus Torvalds writew(iadev->rfL.fdq_wr, iadev->reass_reg+FREEQ_WR_PTR); 10891da177e4SLinus Torvalds } 10901da177e4SLinus Torvalds 10911da177e4SLinus Torvalds 10921da177e4SLinus Torvalds static int rx_pkt(struct atm_dev *dev) 10931da177e4SLinus Torvalds { 10941da177e4SLinus Torvalds IADEV *iadev; 10951da177e4SLinus Torvalds struct atm_vcc *vcc; 10961da177e4SLinus Torvalds unsigned short status; 10971da177e4SLinus Torvalds struct rx_buf_desc __iomem *buf_desc_ptr; 10981da177e4SLinus Torvalds int desc; 10991da177e4SLinus Torvalds struct dle* wr_ptr; 11001da177e4SLinus Torvalds int len; 11011da177e4SLinus Torvalds struct sk_buff *skb; 11021da177e4SLinus Torvalds u_int buf_addr, dma_addr; 11031da177e4SLinus Torvalds 11041da177e4SLinus Torvalds iadev = INPH_IA_DEV(dev); 11051da177e4SLinus Torvalds if (iadev->rfL.pcq_rd == (readw(iadev->reass_reg+PCQ_WR_PTR)&0xffff)) 11061da177e4SLinus Torvalds { 11071da177e4SLinus Torvalds printk(KERN_ERR DEV_LABEL "(itf %d) Receive queue empty\n", dev->number); 11081da177e4SLinus Torvalds return -EINVAL; 11091da177e4SLinus Torvalds } 11101da177e4SLinus Torvalds /* mask 1st 3 bits to get the actual descno. */ 11111da177e4SLinus Torvalds desc = readw(iadev->reass_ram+iadev->rfL.pcq_rd) & 0x1fff; 11121da177e4SLinus Torvalds IF_RX(printk("reass_ram = %p iadev->rfL.pcq_rd = 0x%x desc = %d\n", 11131da177e4SLinus Torvalds iadev->reass_ram, iadev->rfL.pcq_rd, desc); 11141da177e4SLinus Torvalds printk(" pcq_wr_ptr = 0x%x\n", 11151da177e4SLinus Torvalds readw(iadev->reass_reg+PCQ_WR_PTR)&0xffff);) 11161da177e4SLinus Torvalds /* update the read pointer - maybe we shud do this in the end*/ 11171da177e4SLinus Torvalds if ( iadev->rfL.pcq_rd== iadev->rfL.pcq_ed) 11181da177e4SLinus Torvalds iadev->rfL.pcq_rd = iadev->rfL.pcq_st; 11191da177e4SLinus Torvalds else 11201da177e4SLinus Torvalds iadev->rfL.pcq_rd += 2; 11211da177e4SLinus Torvalds writew(iadev->rfL.pcq_rd, iadev->reass_reg+PCQ_RD_PTR); 11221da177e4SLinus Torvalds 11231da177e4SLinus Torvalds /* get the buffer desc entry. 11241da177e4SLinus Torvalds update stuff. - doesn't seem to be any update necessary 11251da177e4SLinus Torvalds */ 11261da177e4SLinus Torvalds buf_desc_ptr = iadev->RX_DESC_BASE_ADDR; 11271da177e4SLinus Torvalds /* make the ptr point to the corresponding buffer desc entry */ 11281da177e4SLinus Torvalds buf_desc_ptr += desc; 11291da177e4SLinus Torvalds if (!desc || (desc > iadev->num_rx_desc) || 11301da177e4SLinus Torvalds ((buf_desc_ptr->vc_index & 0xffff) > iadev->num_vc)) { 11311da177e4SLinus Torvalds free_desc(dev, desc); 11321da177e4SLinus Torvalds IF_ERR(printk("IA: bad descriptor desc = %d \n", desc);) 11331da177e4SLinus Torvalds return -1; 11341da177e4SLinus Torvalds } 11351da177e4SLinus Torvalds vcc = iadev->rx_open[buf_desc_ptr->vc_index & 0xffff]; 11361da177e4SLinus Torvalds if (!vcc) 11371da177e4SLinus Torvalds { 11381da177e4SLinus Torvalds free_desc(dev, desc); 11391da177e4SLinus Torvalds printk("IA: null vcc, drop PDU\n"); 11401da177e4SLinus Torvalds return -1; 11411da177e4SLinus Torvalds } 11421da177e4SLinus Torvalds 11431da177e4SLinus Torvalds 11441da177e4SLinus Torvalds /* might want to check the status bits for errors */ 11451da177e4SLinus Torvalds status = (u_short) (buf_desc_ptr->desc_mode); 11461da177e4SLinus Torvalds if (status & (RX_CER | RX_PTE | RX_OFL)) 11471da177e4SLinus Torvalds { 11481da177e4SLinus Torvalds atomic_inc(&vcc->stats->rx_err); 11491da177e4SLinus Torvalds IF_ERR(printk("IA: bad packet, dropping it");) 11501da177e4SLinus Torvalds if (status & RX_CER) { 11511da177e4SLinus Torvalds IF_ERR(printk(" cause: packet CRC error\n");) 11521da177e4SLinus Torvalds } 11531da177e4SLinus Torvalds else if (status & RX_PTE) { 11541da177e4SLinus Torvalds IF_ERR(printk(" cause: packet time out\n");) 11551da177e4SLinus Torvalds } 11561da177e4SLinus Torvalds else { 11571da177e4SLinus Torvalds IF_ERR(printk(" cause: buffer overflow\n");) 11581da177e4SLinus Torvalds } 11591da177e4SLinus Torvalds goto out_free_desc; 11601da177e4SLinus Torvalds } 11611da177e4SLinus Torvalds 11621da177e4SLinus Torvalds /* 11631da177e4SLinus Torvalds build DLE. 11641da177e4SLinus Torvalds */ 11651da177e4SLinus Torvalds 11661da177e4SLinus Torvalds buf_addr = (buf_desc_ptr->buf_start_hi << 16) | buf_desc_ptr->buf_start_lo; 11671da177e4SLinus Torvalds dma_addr = (buf_desc_ptr->dma_start_hi << 16) | buf_desc_ptr->dma_start_lo; 11681da177e4SLinus Torvalds len = dma_addr - buf_addr; 11691da177e4SLinus Torvalds if (len > iadev->rx_buf_sz) { 11701da177e4SLinus Torvalds printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz); 11711da177e4SLinus Torvalds atomic_inc(&vcc->stats->rx_err); 11721da177e4SLinus Torvalds goto out_free_desc; 11731da177e4SLinus Torvalds } 11741da177e4SLinus Torvalds 11751da177e4SLinus Torvalds if (!(skb = atm_alloc_charge(vcc, len, GFP_ATOMIC))) { 11761da177e4SLinus Torvalds if (vcc->vci < 32) 11771da177e4SLinus Torvalds printk("Drop control packets\n"); 11781da177e4SLinus Torvalds goto out_free_desc; 11791da177e4SLinus Torvalds } 11801da177e4SLinus Torvalds skb_put(skb,len); 11811da177e4SLinus Torvalds // pwang_test 11821da177e4SLinus Torvalds ATM_SKB(skb)->vcc = vcc; 11831da177e4SLinus Torvalds ATM_DESC(skb) = desc; 11841da177e4SLinus Torvalds skb_queue_tail(&iadev->rx_dma_q, skb); 11851da177e4SLinus Torvalds 11861da177e4SLinus Torvalds /* Build the DLE structure */ 11871da177e4SLinus Torvalds wr_ptr = iadev->rx_dle_q.write; 11881da177e4SLinus Torvalds wr_ptr->sys_pkt_addr = pci_map_single(iadev->pci, skb->data, 11891da177e4SLinus Torvalds len, PCI_DMA_FROMDEVICE); 11901da177e4SLinus Torvalds wr_ptr->local_pkt_addr = buf_addr; 11911da177e4SLinus Torvalds wr_ptr->bytes = len; /* We don't know this do we ?? */ 11921da177e4SLinus Torvalds wr_ptr->mode = DMA_INT_ENABLE; 11931da177e4SLinus Torvalds 11941da177e4SLinus Torvalds /* shud take care of wrap around here too. */ 11951da177e4SLinus Torvalds if(++wr_ptr == iadev->rx_dle_q.end) 11961da177e4SLinus Torvalds wr_ptr = iadev->rx_dle_q.start; 11971da177e4SLinus Torvalds iadev->rx_dle_q.write = wr_ptr; 11981da177e4SLinus Torvalds udelay(1); 11991da177e4SLinus Torvalds /* Increment transaction counter */ 12001da177e4SLinus Torvalds writel(1, iadev->dma+IPHASE5575_RX_COUNTER); 12011da177e4SLinus Torvalds out: return 0; 12021da177e4SLinus Torvalds out_free_desc: 12031da177e4SLinus Torvalds free_desc(dev, desc); 12041da177e4SLinus Torvalds goto out; 12051da177e4SLinus Torvalds } 12061da177e4SLinus Torvalds 12071da177e4SLinus Torvalds static void rx_intr(struct atm_dev *dev) 12081da177e4SLinus Torvalds { 12091da177e4SLinus Torvalds IADEV *iadev; 12101da177e4SLinus Torvalds u_short status; 12111da177e4SLinus Torvalds u_short state, i; 12121da177e4SLinus Torvalds 12131da177e4SLinus Torvalds iadev = INPH_IA_DEV(dev); 12141da177e4SLinus Torvalds status = readl(iadev->reass_reg+REASS_INTR_STATUS_REG) & 0xffff; 12151da177e4SLinus Torvalds IF_EVENT(printk("rx_intr: status = 0x%x\n", status);) 12161da177e4SLinus Torvalds if (status & RX_PKT_RCVD) 12171da177e4SLinus Torvalds { 12181da177e4SLinus Torvalds /* do something */ 121925985edcSLucas De Marchi /* Basically recvd an interrupt for receiving a packet. 12201da177e4SLinus Torvalds A descriptor would have been written to the packet complete 12211da177e4SLinus Torvalds queue. Get all the descriptors and set up dma to move the 12221da177e4SLinus Torvalds packets till the packet complete queue is empty.. 12231da177e4SLinus Torvalds */ 12241da177e4SLinus Torvalds state = readl(iadev->reass_reg + STATE_REG) & 0xffff; 12251da177e4SLinus Torvalds IF_EVENT(printk("Rx intr status: RX_PKT_RCVD %08x\n", status);) 12261da177e4SLinus Torvalds while(!(state & PCQ_EMPTY)) 12271da177e4SLinus Torvalds { 12281da177e4SLinus Torvalds rx_pkt(dev); 12291da177e4SLinus Torvalds state = readl(iadev->reass_reg + STATE_REG) & 0xffff; 12301da177e4SLinus Torvalds } 12311da177e4SLinus Torvalds iadev->rxing = 1; 12321da177e4SLinus Torvalds } 12331da177e4SLinus Torvalds if (status & RX_FREEQ_EMPT) 12341da177e4SLinus Torvalds { 12351da177e4SLinus Torvalds if (iadev->rxing) { 12361da177e4SLinus Torvalds iadev->rx_tmp_cnt = iadev->rx_pkt_cnt; 12371da177e4SLinus Torvalds iadev->rx_tmp_jif = jiffies; 12381da177e4SLinus Torvalds iadev->rxing = 0; 12391da177e4SLinus Torvalds } 1240420635f5SJulia Lawall else if ((time_after(jiffies, iadev->rx_tmp_jif + 50)) && 12411da177e4SLinus Torvalds ((iadev->rx_pkt_cnt - iadev->rx_tmp_cnt) == 0)) { 12421da177e4SLinus Torvalds for (i = 1; i <= iadev->num_rx_desc; i++) 12431da177e4SLinus Torvalds free_desc(dev, i); 12441da177e4SLinus Torvalds printk("Test logic RUN!!!!\n"); 12451da177e4SLinus Torvalds writew( ~(RX_FREEQ_EMPT|RX_EXCP_RCVD),iadev->reass_reg+REASS_MASK_REG); 12461da177e4SLinus Torvalds iadev->rxing = 1; 12471da177e4SLinus Torvalds } 12481da177e4SLinus Torvalds IF_EVENT(printk("Rx intr status: RX_FREEQ_EMPT %08x\n", status);) 12491da177e4SLinus Torvalds } 12501da177e4SLinus Torvalds 12511da177e4SLinus Torvalds if (status & RX_EXCP_RCVD) 12521da177e4SLinus Torvalds { 12531da177e4SLinus Torvalds /* probably need to handle the exception queue also. */ 12541da177e4SLinus Torvalds IF_EVENT(printk("Rx intr status: RX_EXCP_RCVD %08x\n", status);) 12551da177e4SLinus Torvalds rx_excp_rcvd(dev); 12561da177e4SLinus Torvalds } 12571da177e4SLinus Torvalds 12581da177e4SLinus Torvalds 12591da177e4SLinus Torvalds if (status & RX_RAW_RCVD) 12601da177e4SLinus Torvalds { 12611da177e4SLinus Torvalds /* need to handle the raw incoming cells. This deepnds on 12621da177e4SLinus Torvalds whether we have programmed to receive the raw cells or not. 12631da177e4SLinus Torvalds Else ignore. */ 12641da177e4SLinus Torvalds IF_EVENT(printk("Rx intr status: RX_RAW_RCVD %08x\n", status);) 12651da177e4SLinus Torvalds } 12661da177e4SLinus Torvalds } 12671da177e4SLinus Torvalds 12681da177e4SLinus Torvalds 12691da177e4SLinus Torvalds static void rx_dle_intr(struct atm_dev *dev) 12701da177e4SLinus Torvalds { 12711da177e4SLinus Torvalds IADEV *iadev; 12721da177e4SLinus Torvalds struct atm_vcc *vcc; 12731da177e4SLinus Torvalds struct sk_buff *skb; 12741da177e4SLinus Torvalds int desc; 12751da177e4SLinus Torvalds u_short state; 12761da177e4SLinus Torvalds struct dle *dle, *cur_dle; 12771da177e4SLinus Torvalds u_int dle_lp; 12781da177e4SLinus Torvalds int len; 12791da177e4SLinus Torvalds iadev = INPH_IA_DEV(dev); 12801da177e4SLinus Torvalds 12811da177e4SLinus Torvalds /* free all the dles done, that is just update our own dle read pointer 12821da177e4SLinus Torvalds - do we really need to do this. Think not. */ 12831da177e4SLinus Torvalds /* DMA is done, just get all the recevie buffers from the rx dma queue 12841da177e4SLinus Torvalds and push them up to the higher layer protocol. Also free the desc 12851da177e4SLinus Torvalds associated with the buffer. */ 12861da177e4SLinus Torvalds dle = iadev->rx_dle_q.read; 12871da177e4SLinus Torvalds dle_lp = readl(iadev->dma+IPHASE5575_RX_LIST_ADDR) & (sizeof(struct dle)*DLE_ENTRIES - 1); 12881da177e4SLinus Torvalds cur_dle = (struct dle*)(iadev->rx_dle_q.start + (dle_lp >> 4)); 12891da177e4SLinus Torvalds while(dle != cur_dle) 12901da177e4SLinus Torvalds { 12911da177e4SLinus Torvalds /* free the DMAed skb */ 12921da177e4SLinus Torvalds skb = skb_dequeue(&iadev->rx_dma_q); 12931da177e4SLinus Torvalds if (!skb) 12941da177e4SLinus Torvalds goto INCR_DLE; 12951da177e4SLinus Torvalds desc = ATM_DESC(skb); 12961da177e4SLinus Torvalds free_desc(dev, desc); 12971da177e4SLinus Torvalds 12981da177e4SLinus Torvalds if (!(len = skb->len)) 12991da177e4SLinus Torvalds { 13001da177e4SLinus Torvalds printk("rx_dle_intr: skb len 0\n"); 13011da177e4SLinus Torvalds dev_kfree_skb_any(skb); 13021da177e4SLinus Torvalds } 13031da177e4SLinus Torvalds else 13041da177e4SLinus Torvalds { 13051da177e4SLinus Torvalds struct cpcs_trailer *trailer; 13061da177e4SLinus Torvalds u_short length; 13071da177e4SLinus Torvalds struct ia_vcc *ia_vcc; 13081da177e4SLinus Torvalds 13091da177e4SLinus Torvalds pci_unmap_single(iadev->pci, iadev->rx_dle_q.write->sys_pkt_addr, 13101da177e4SLinus Torvalds len, PCI_DMA_FROMDEVICE); 13111da177e4SLinus Torvalds /* no VCC related housekeeping done as yet. lets see */ 13121da177e4SLinus Torvalds vcc = ATM_SKB(skb)->vcc; 13131da177e4SLinus Torvalds if (!vcc) { 13141da177e4SLinus Torvalds printk("IA: null vcc\n"); 13151da177e4SLinus Torvalds dev_kfree_skb_any(skb); 13161da177e4SLinus Torvalds goto INCR_DLE; 13171da177e4SLinus Torvalds } 13181da177e4SLinus Torvalds ia_vcc = INPH_IA_VCC(vcc); 13191da177e4SLinus Torvalds if (ia_vcc == NULL) 13201da177e4SLinus Torvalds { 13211da177e4SLinus Torvalds atomic_inc(&vcc->stats->rx_err); 132249f5ed42Schas williams - CONTRACTOR atm_return(vcc, skb->truesize); 13231da177e4SLinus Torvalds dev_kfree_skb_any(skb); 13241da177e4SLinus Torvalds goto INCR_DLE; 13251da177e4SLinus Torvalds } 13261da177e4SLinus Torvalds // get real pkt length pwang_test 13271da177e4SLinus Torvalds trailer = (struct cpcs_trailer*)((u_char *)skb->data + 13281da177e4SLinus Torvalds skb->len - sizeof(*trailer)); 1329b67445fcSWu Fengguang length = swap_byte_order(trailer->length); 13301da177e4SLinus Torvalds if ((length > iadev->rx_buf_sz) || (length > 13311da177e4SLinus Torvalds (skb->len - sizeof(struct cpcs_trailer)))) 13321da177e4SLinus Torvalds { 13331da177e4SLinus Torvalds atomic_inc(&vcc->stats->rx_err); 13341da177e4SLinus Torvalds IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)", 13351da177e4SLinus Torvalds length, skb->len);) 133649f5ed42Schas williams - CONTRACTOR atm_return(vcc, skb->truesize); 13371da177e4SLinus Torvalds dev_kfree_skb_any(skb); 13381da177e4SLinus Torvalds goto INCR_DLE; 13391da177e4SLinus Torvalds } 13401da177e4SLinus Torvalds skb_trim(skb, length); 13411da177e4SLinus Torvalds 13421da177e4SLinus Torvalds /* Display the packet */ 13431da177e4SLinus Torvalds IF_RXPKT(printk("\nDmad Recvd data: len = %d \n", skb->len); 13441da177e4SLinus Torvalds xdump(skb->data, skb->len, "RX: "); 13451da177e4SLinus Torvalds printk("\n");) 13461da177e4SLinus Torvalds 13471da177e4SLinus Torvalds IF_RX(printk("rx_dle_intr: skb push");) 13481da177e4SLinus Torvalds vcc->push(vcc,skb); 13491da177e4SLinus Torvalds atomic_inc(&vcc->stats->rx); 13501da177e4SLinus Torvalds iadev->rx_pkt_cnt++; 13511da177e4SLinus Torvalds } 13521da177e4SLinus Torvalds INCR_DLE: 13531da177e4SLinus Torvalds if (++dle == iadev->rx_dle_q.end) 13541da177e4SLinus Torvalds dle = iadev->rx_dle_q.start; 13551da177e4SLinus Torvalds } 13561da177e4SLinus Torvalds iadev->rx_dle_q.read = dle; 13571da177e4SLinus Torvalds 13581da177e4SLinus Torvalds /* if the interrupts are masked because there were no free desc available, 13591da177e4SLinus Torvalds unmask them now. */ 13601da177e4SLinus Torvalds if (!iadev->rxing) { 13611da177e4SLinus Torvalds state = readl(iadev->reass_reg + STATE_REG) & 0xffff; 13621da177e4SLinus Torvalds if (!(state & FREEQ_EMPTY)) { 13631da177e4SLinus Torvalds state = readl(iadev->reass_reg + REASS_MASK_REG) & 0xffff; 13641da177e4SLinus Torvalds writel(state & ~(RX_FREEQ_EMPT |/* RX_EXCP_RCVD |*/ RX_PKT_RCVD), 13651da177e4SLinus Torvalds iadev->reass_reg+REASS_MASK_REG); 13661da177e4SLinus Torvalds iadev->rxing++; 13671da177e4SLinus Torvalds } 13681da177e4SLinus Torvalds } 13691da177e4SLinus Torvalds } 13701da177e4SLinus Torvalds 13711da177e4SLinus Torvalds 13721da177e4SLinus Torvalds static int open_rx(struct atm_vcc *vcc) 13731da177e4SLinus Torvalds { 13741da177e4SLinus Torvalds IADEV *iadev; 13751da177e4SLinus Torvalds u_short __iomem *vc_table; 13761da177e4SLinus Torvalds u_short __iomem *reass_ptr; 13771da177e4SLinus Torvalds IF_EVENT(printk("iadev: open_rx %d.%d\n", vcc->vpi, vcc->vci);) 13781da177e4SLinus Torvalds 13791da177e4SLinus Torvalds if (vcc->qos.rxtp.traffic_class == ATM_NONE) return 0; 13801da177e4SLinus Torvalds iadev = INPH_IA_DEV(vcc->dev); 13811da177e4SLinus Torvalds if (vcc->qos.rxtp.traffic_class == ATM_ABR) { 13821da177e4SLinus Torvalds if (iadev->phy_type & FE_25MBIT_PHY) { 13831da177e4SLinus Torvalds printk("IA: ABR not support\n"); 13841da177e4SLinus Torvalds return -EINVAL; 13851da177e4SLinus Torvalds } 13861da177e4SLinus Torvalds } 13871da177e4SLinus Torvalds /* Make only this VCI in the vc table valid and let all 13881da177e4SLinus Torvalds others be invalid entries */ 13891da177e4SLinus Torvalds vc_table = iadev->reass_ram+RX_VC_TABLE*iadev->memSize; 13901da177e4SLinus Torvalds vc_table += vcc->vci; 13911da177e4SLinus Torvalds /* mask the last 6 bits and OR it with 3 for 1K VCs */ 13921da177e4SLinus Torvalds 13931da177e4SLinus Torvalds *vc_table = vcc->vci << 6; 13941da177e4SLinus Torvalds /* Also keep a list of open rx vcs so that we can attach them with 13951da177e4SLinus Torvalds incoming PDUs later. */ 13961da177e4SLinus Torvalds if ((vcc->qos.rxtp.traffic_class == ATM_ABR) || 13971da177e4SLinus Torvalds (vcc->qos.txtp.traffic_class == ATM_ABR)) 13981da177e4SLinus Torvalds { 13991da177e4SLinus Torvalds srv_cls_param_t srv_p; 14001da177e4SLinus Torvalds init_abr_vc(iadev, &srv_p); 14011da177e4SLinus Torvalds ia_open_abr_vc(iadev, &srv_p, vcc, 0); 14021da177e4SLinus Torvalds } 14031da177e4SLinus Torvalds else { /* for UBR later may need to add CBR logic */ 14041da177e4SLinus Torvalds reass_ptr = iadev->reass_ram+REASS_TABLE*iadev->memSize; 14051da177e4SLinus Torvalds reass_ptr += vcc->vci; 14061da177e4SLinus Torvalds *reass_ptr = NO_AAL5_PKT; 14071da177e4SLinus Torvalds } 14081da177e4SLinus Torvalds 14091da177e4SLinus Torvalds if (iadev->rx_open[vcc->vci]) 14101da177e4SLinus Torvalds printk(KERN_CRIT DEV_LABEL "(itf %d): VCI %d already open\n", 14111da177e4SLinus Torvalds vcc->dev->number, vcc->vci); 14121da177e4SLinus Torvalds iadev->rx_open[vcc->vci] = vcc; 14131da177e4SLinus Torvalds return 0; 14141da177e4SLinus Torvalds } 14151da177e4SLinus Torvalds 14161da177e4SLinus Torvalds static int rx_init(struct atm_dev *dev) 14171da177e4SLinus Torvalds { 14181da177e4SLinus Torvalds IADEV *iadev; 14191da177e4SLinus Torvalds struct rx_buf_desc __iomem *buf_desc_ptr; 14201da177e4SLinus Torvalds unsigned long rx_pkt_start = 0; 14211da177e4SLinus Torvalds void *dle_addr; 14221da177e4SLinus Torvalds struct abr_vc_table *abr_vc_table; 14231da177e4SLinus Torvalds u16 *vc_table; 14241da177e4SLinus Torvalds u16 *reass_table; 14251da177e4SLinus Torvalds int i,j, vcsize_sel; 14261da177e4SLinus Torvalds u_short freeq_st_adr; 14271da177e4SLinus Torvalds u_short *freeq_start; 14281da177e4SLinus Torvalds 14291da177e4SLinus Torvalds iadev = INPH_IA_DEV(dev); 14301da177e4SLinus Torvalds // spin_lock_init(&iadev->rx_lock); 14311da177e4SLinus Torvalds 14321da177e4SLinus Torvalds /* Allocate 4k bytes - more aligned than needed (4k boundary) */ 14331da177e4SLinus Torvalds dle_addr = pci_alloc_consistent(iadev->pci, DLE_TOTAL_SIZE, 14341da177e4SLinus Torvalds &iadev->rx_dle_dma); 14351da177e4SLinus Torvalds if (!dle_addr) { 14361da177e4SLinus Torvalds printk(KERN_ERR DEV_LABEL "can't allocate DLEs\n"); 14371da177e4SLinus Torvalds goto err_out; 14381da177e4SLinus Torvalds } 14391da177e4SLinus Torvalds iadev->rx_dle_q.start = (struct dle *)dle_addr; 14401da177e4SLinus Torvalds iadev->rx_dle_q.read = iadev->rx_dle_q.start; 14411da177e4SLinus Torvalds iadev->rx_dle_q.write = iadev->rx_dle_q.start; 144297928f70SAlan Cox iadev->rx_dle_q.end = (struct dle*)((unsigned long)dle_addr+sizeof(struct dle)*DLE_ENTRIES); 14431da177e4SLinus Torvalds /* the end of the dle q points to the entry after the last 14441da177e4SLinus Torvalds DLE that can be used. */ 14451da177e4SLinus Torvalds 14461da177e4SLinus Torvalds /* write the upper 20 bits of the start address to rx list address register */ 144797928f70SAlan Cox /* We know this is 32bit bus addressed so the following is safe */ 14481da177e4SLinus Torvalds writel(iadev->rx_dle_dma & 0xfffff000, 14491da177e4SLinus Torvalds iadev->dma + IPHASE5575_RX_LIST_ADDR); 1450849e8caaSDavid Howells IF_INIT(printk("Tx Dle list addr: 0x%p value: 0x%0x\n", 1451849e8caaSDavid Howells iadev->dma+IPHASE5575_TX_LIST_ADDR, 145226c5c44dSfrançois romieu readl(iadev->dma + IPHASE5575_TX_LIST_ADDR)); 1453849e8caaSDavid Howells printk("Rx Dle list addr: 0x%p value: 0x%0x\n", 1454849e8caaSDavid Howells iadev->dma+IPHASE5575_RX_LIST_ADDR, 145526c5c44dSfrançois romieu readl(iadev->dma + IPHASE5575_RX_LIST_ADDR));) 14561da177e4SLinus Torvalds 14571da177e4SLinus Torvalds writew(0xffff, iadev->reass_reg+REASS_MASK_REG); 14581da177e4SLinus Torvalds writew(0, iadev->reass_reg+MODE_REG); 14591da177e4SLinus Torvalds writew(RESET_REASS, iadev->reass_reg+REASS_COMMAND_REG); 14601da177e4SLinus Torvalds 14611da177e4SLinus Torvalds /* Receive side control memory map 14621da177e4SLinus Torvalds ------------------------------- 14631da177e4SLinus Torvalds 14641da177e4SLinus Torvalds Buffer descr 0x0000 (736 - 23K) 14651da177e4SLinus Torvalds VP Table 0x5c00 (256 - 512) 14661da177e4SLinus Torvalds Except q 0x5e00 (128 - 512) 14671da177e4SLinus Torvalds Free buffer q 0x6000 (1K - 2K) 14681da177e4SLinus Torvalds Packet comp q 0x6800 (1K - 2K) 14691da177e4SLinus Torvalds Reass Table 0x7000 (1K - 2K) 14701da177e4SLinus Torvalds VC Table 0x7800 (1K - 2K) 14711da177e4SLinus Torvalds ABR VC Table 0x8000 (1K - 32K) 14721da177e4SLinus Torvalds */ 14731da177e4SLinus Torvalds 14741da177e4SLinus Torvalds /* Base address for Buffer Descriptor Table */ 14751da177e4SLinus Torvalds writew(RX_DESC_BASE >> 16, iadev->reass_reg+REASS_DESC_BASE); 14761da177e4SLinus Torvalds /* Set the buffer size register */ 14771da177e4SLinus Torvalds writew(iadev->rx_buf_sz, iadev->reass_reg+BUF_SIZE); 14781da177e4SLinus Torvalds 14791da177e4SLinus Torvalds /* Initialize each entry in the Buffer Descriptor Table */ 14801da177e4SLinus Torvalds iadev->RX_DESC_BASE_ADDR = iadev->reass_ram+RX_DESC_BASE*iadev->memSize; 14811da177e4SLinus Torvalds buf_desc_ptr = iadev->RX_DESC_BASE_ADDR; 14821da177e4SLinus Torvalds memset_io(buf_desc_ptr, 0, sizeof(*buf_desc_ptr)); 14831da177e4SLinus Torvalds buf_desc_ptr++; 14841da177e4SLinus Torvalds rx_pkt_start = iadev->rx_pkt_ram; 14851da177e4SLinus Torvalds for(i=1; i<=iadev->num_rx_desc; i++) 14861da177e4SLinus Torvalds { 14871da177e4SLinus Torvalds memset_io(buf_desc_ptr, 0, sizeof(*buf_desc_ptr)); 14881da177e4SLinus Torvalds buf_desc_ptr->buf_start_hi = rx_pkt_start >> 16; 14891da177e4SLinus Torvalds buf_desc_ptr->buf_start_lo = rx_pkt_start & 0x0000ffff; 14901da177e4SLinus Torvalds buf_desc_ptr++; 14911da177e4SLinus Torvalds rx_pkt_start += iadev->rx_buf_sz; 14921da177e4SLinus Torvalds } 1493849e8caaSDavid Howells IF_INIT(printk("Rx Buffer desc ptr: 0x%p\n", buf_desc_ptr);) 14941da177e4SLinus Torvalds i = FREE_BUF_DESC_Q*iadev->memSize; 14951da177e4SLinus Torvalds writew(i >> 16, iadev->reass_reg+REASS_QUEUE_BASE); 14961da177e4SLinus Torvalds writew(i, iadev->reass_reg+FREEQ_ST_ADR); 14971da177e4SLinus Torvalds writew(i+iadev->num_rx_desc*sizeof(u_short), 14981da177e4SLinus Torvalds iadev->reass_reg+FREEQ_ED_ADR); 14991da177e4SLinus Torvalds writew(i, iadev->reass_reg+FREEQ_RD_PTR); 15001da177e4SLinus Torvalds writew(i+iadev->num_rx_desc*sizeof(u_short), 15011da177e4SLinus Torvalds iadev->reass_reg+FREEQ_WR_PTR); 15021da177e4SLinus Torvalds /* Fill the FREEQ with all the free descriptors. */ 15031da177e4SLinus Torvalds freeq_st_adr = readw(iadev->reass_reg+FREEQ_ST_ADR); 15041da177e4SLinus Torvalds freeq_start = (u_short *)(iadev->reass_ram+freeq_st_adr); 15051da177e4SLinus Torvalds for(i=1; i<=iadev->num_rx_desc; i++) 15061da177e4SLinus Torvalds { 15071da177e4SLinus Torvalds *freeq_start = (u_short)i; 15081da177e4SLinus Torvalds freeq_start++; 15091da177e4SLinus Torvalds } 1510849e8caaSDavid Howells IF_INIT(printk("freeq_start: 0x%p\n", freeq_start);) 15111da177e4SLinus Torvalds /* Packet Complete Queue */ 15121da177e4SLinus Torvalds i = (PKT_COMP_Q * iadev->memSize) & 0xffff; 15131da177e4SLinus Torvalds writew(i, iadev->reass_reg+PCQ_ST_ADR); 15141da177e4SLinus Torvalds writew(i+iadev->num_vc*sizeof(u_short), iadev->reass_reg+PCQ_ED_ADR); 15151da177e4SLinus Torvalds writew(i, iadev->reass_reg+PCQ_RD_PTR); 15161da177e4SLinus Torvalds writew(i, iadev->reass_reg+PCQ_WR_PTR); 15171da177e4SLinus Torvalds 15181da177e4SLinus Torvalds /* Exception Queue */ 15191da177e4SLinus Torvalds i = (EXCEPTION_Q * iadev->memSize) & 0xffff; 15201da177e4SLinus Torvalds writew(i, iadev->reass_reg+EXCP_Q_ST_ADR); 15211da177e4SLinus Torvalds writew(i + NUM_RX_EXCP * sizeof(RX_ERROR_Q), 15221da177e4SLinus Torvalds iadev->reass_reg+EXCP_Q_ED_ADR); 15231da177e4SLinus Torvalds writew(i, iadev->reass_reg+EXCP_Q_RD_PTR); 15241da177e4SLinus Torvalds writew(i, iadev->reass_reg+EXCP_Q_WR_PTR); 15251da177e4SLinus Torvalds 15261da177e4SLinus Torvalds /* Load local copy of FREEQ and PCQ ptrs */ 15271da177e4SLinus Torvalds iadev->rfL.fdq_st = readw(iadev->reass_reg+FREEQ_ST_ADR) & 0xffff; 15281da177e4SLinus Torvalds iadev->rfL.fdq_ed = readw(iadev->reass_reg+FREEQ_ED_ADR) & 0xffff ; 15291da177e4SLinus Torvalds iadev->rfL.fdq_rd = readw(iadev->reass_reg+FREEQ_RD_PTR) & 0xffff; 15301da177e4SLinus Torvalds iadev->rfL.fdq_wr = readw(iadev->reass_reg+FREEQ_WR_PTR) & 0xffff; 15311da177e4SLinus Torvalds iadev->rfL.pcq_st = readw(iadev->reass_reg+PCQ_ST_ADR) & 0xffff; 15321da177e4SLinus Torvalds iadev->rfL.pcq_ed = readw(iadev->reass_reg+PCQ_ED_ADR) & 0xffff; 15331da177e4SLinus Torvalds iadev->rfL.pcq_rd = readw(iadev->reass_reg+PCQ_RD_PTR) & 0xffff; 15341da177e4SLinus Torvalds iadev->rfL.pcq_wr = readw(iadev->reass_reg+PCQ_WR_PTR) & 0xffff; 15351da177e4SLinus Torvalds 15361da177e4SLinus Torvalds IF_INIT(printk("INIT:pcq_st:0x%x pcq_ed:0x%x pcq_rd:0x%x pcq_wr:0x%x", 15371da177e4SLinus Torvalds iadev->rfL.pcq_st, iadev->rfL.pcq_ed, iadev->rfL.pcq_rd, 15381da177e4SLinus Torvalds iadev->rfL.pcq_wr);) 15391da177e4SLinus Torvalds /* just for check - no VP TBL */ 15401da177e4SLinus Torvalds /* VP Table */ 15411da177e4SLinus Torvalds /* writew(0x0b80, iadev->reass_reg+VP_LKUP_BASE); */ 15421da177e4SLinus Torvalds /* initialize VP Table for invalid VPIs 15431da177e4SLinus Torvalds - I guess we can write all 1s or 0x000f in the entire memory 15441da177e4SLinus Torvalds space or something similar. 15451da177e4SLinus Torvalds */ 15461da177e4SLinus Torvalds 15471da177e4SLinus Torvalds /* This seems to work and looks right to me too !!! */ 15481da177e4SLinus Torvalds i = REASS_TABLE * iadev->memSize; 15491da177e4SLinus Torvalds writew((i >> 3), iadev->reass_reg+REASS_TABLE_BASE); 15501da177e4SLinus Torvalds /* initialize Reassembly table to I don't know what ???? */ 15511da177e4SLinus Torvalds reass_table = (u16 *)(iadev->reass_ram+i); 15521da177e4SLinus Torvalds j = REASS_TABLE_SZ * iadev->memSize; 15531da177e4SLinus Torvalds for(i=0; i < j; i++) 15541da177e4SLinus Torvalds *reass_table++ = NO_AAL5_PKT; 15551da177e4SLinus Torvalds i = 8*1024; 15561da177e4SLinus Torvalds vcsize_sel = 0; 15571da177e4SLinus Torvalds while (i != iadev->num_vc) { 15581da177e4SLinus Torvalds i /= 2; 15591da177e4SLinus Torvalds vcsize_sel++; 15601da177e4SLinus Torvalds } 15611da177e4SLinus Torvalds i = RX_VC_TABLE * iadev->memSize; 15621da177e4SLinus Torvalds writew(((i>>3) & 0xfff8) | vcsize_sel, iadev->reass_reg+VC_LKUP_BASE); 15631da177e4SLinus Torvalds vc_table = (u16 *)(iadev->reass_ram+RX_VC_TABLE*iadev->memSize); 15641da177e4SLinus Torvalds j = RX_VC_TABLE_SZ * iadev->memSize; 15651da177e4SLinus Torvalds for(i = 0; i < j; i++) 15661da177e4SLinus Torvalds { 15671da177e4SLinus Torvalds /* shift the reassembly pointer by 3 + lower 3 bits of 15681da177e4SLinus Torvalds vc_lkup_base register (=3 for 1K VCs) and the last byte 15691da177e4SLinus Torvalds is those low 3 bits. 15701da177e4SLinus Torvalds Shall program this later. 15711da177e4SLinus Torvalds */ 15721da177e4SLinus Torvalds *vc_table = (i << 6) | 15; /* for invalid VCI */ 15731da177e4SLinus Torvalds vc_table++; 15741da177e4SLinus Torvalds } 15751da177e4SLinus Torvalds /* ABR VC table */ 15761da177e4SLinus Torvalds i = ABR_VC_TABLE * iadev->memSize; 15771da177e4SLinus Torvalds writew(i >> 3, iadev->reass_reg+ABR_LKUP_BASE); 15781da177e4SLinus Torvalds 15791da177e4SLinus Torvalds i = ABR_VC_TABLE * iadev->memSize; 15801da177e4SLinus Torvalds abr_vc_table = (struct abr_vc_table *)(iadev->reass_ram+i); 15811da177e4SLinus Torvalds j = REASS_TABLE_SZ * iadev->memSize; 15821da177e4SLinus Torvalds memset ((char*)abr_vc_table, 0, j * sizeof(*abr_vc_table)); 15831da177e4SLinus Torvalds for(i = 0; i < j; i++) { 15841da177e4SLinus Torvalds abr_vc_table->rdf = 0x0003; 15851da177e4SLinus Torvalds abr_vc_table->air = 0x5eb1; 15861da177e4SLinus Torvalds abr_vc_table++; 15871da177e4SLinus Torvalds } 15881da177e4SLinus Torvalds 15891da177e4SLinus Torvalds /* Initialize other registers */ 15901da177e4SLinus Torvalds 15911da177e4SLinus Torvalds /* VP Filter Register set for VC Reassembly only */ 15921da177e4SLinus Torvalds writew(0xff00, iadev->reass_reg+VP_FILTER); 15931da177e4SLinus Torvalds writew(0, iadev->reass_reg+XTRA_RM_OFFSET); 15941da177e4SLinus Torvalds writew(0x1, iadev->reass_reg+PROTOCOL_ID); 15951da177e4SLinus Torvalds 15961da177e4SLinus Torvalds /* Packet Timeout Count related Registers : 15971da177e4SLinus Torvalds Set packet timeout to occur in about 3 seconds 15981da177e4SLinus Torvalds Set Packet Aging Interval count register to overflow in about 4 us 15991da177e4SLinus Torvalds */ 16001da177e4SLinus Torvalds writew(0xF6F8, iadev->reass_reg+PKT_TM_CNT ); 160197928f70SAlan Cox 160297928f70SAlan Cox i = (j >> 6) & 0xFF; 160397928f70SAlan Cox j += 2 * (j - 1); 160497928f70SAlan Cox i |= ((j << 2) & 0xFF00); 16051da177e4SLinus Torvalds writew(i, iadev->reass_reg+TMOUT_RANGE); 160697928f70SAlan Cox 16071da177e4SLinus Torvalds /* initiate the desc_tble */ 16081da177e4SLinus Torvalds for(i=0; i<iadev->num_tx_desc;i++) 16091da177e4SLinus Torvalds iadev->desc_tbl[i].timestamp = 0; 16101da177e4SLinus Torvalds 16111da177e4SLinus Torvalds /* to clear the interrupt status register - read it */ 16121da177e4SLinus Torvalds readw(iadev->reass_reg+REASS_INTR_STATUS_REG); 16131da177e4SLinus Torvalds 16141da177e4SLinus Torvalds /* Mask Register - clear it */ 16151da177e4SLinus Torvalds writew(~(RX_FREEQ_EMPT|RX_PKT_RCVD), iadev->reass_reg+REASS_MASK_REG); 16161da177e4SLinus Torvalds 16171da177e4SLinus Torvalds skb_queue_head_init(&iadev->rx_dma_q); 16181da177e4SLinus Torvalds iadev->rx_free_desc_qhead = NULL; 1619f7141761SMariusz Kozlowski 1620f7141761SMariusz Kozlowski iadev->rx_open = kzalloc(4 * iadev->num_vc, GFP_KERNEL); 1621f7141761SMariusz Kozlowski if (!iadev->rx_open) { 16221da177e4SLinus Torvalds printk(KERN_ERR DEV_LABEL "itf %d couldn't get free page\n", 16231da177e4SLinus Torvalds dev->number); 16241da177e4SLinus Torvalds goto err_free_dle; 16251da177e4SLinus Torvalds } 1626f7141761SMariusz Kozlowski 16271da177e4SLinus Torvalds iadev->rxing = 1; 16281da177e4SLinus Torvalds iadev->rx_pkt_cnt = 0; 16291da177e4SLinus Torvalds /* Mode Register */ 16301da177e4SLinus Torvalds writew(R_ONLINE, iadev->reass_reg+MODE_REG); 16311da177e4SLinus Torvalds return 0; 16321da177e4SLinus Torvalds 16331da177e4SLinus Torvalds err_free_dle: 16341da177e4SLinus Torvalds pci_free_consistent(iadev->pci, DLE_TOTAL_SIZE, iadev->rx_dle_q.start, 16351da177e4SLinus Torvalds iadev->rx_dle_dma); 16361da177e4SLinus Torvalds err_out: 16371da177e4SLinus Torvalds return -ENOMEM; 16381da177e4SLinus Torvalds } 16391da177e4SLinus Torvalds 16401da177e4SLinus Torvalds 16411da177e4SLinus Torvalds /* 16421da177e4SLinus Torvalds The memory map suggested in appendix A and the coding for it. 16431da177e4SLinus Torvalds Keeping it around just in case we change our mind later. 16441da177e4SLinus Torvalds 16451da177e4SLinus Torvalds Buffer descr 0x0000 (128 - 4K) 16461da177e4SLinus Torvalds UBR sched 0x1000 (1K - 4K) 16471da177e4SLinus Torvalds UBR Wait q 0x2000 (1K - 4K) 16481da177e4SLinus Torvalds Commn queues 0x3000 Packet Ready, Trasmit comp(0x3100) 16491da177e4SLinus Torvalds (128 - 256) each 16501da177e4SLinus Torvalds extended VC 0x4000 (1K - 8K) 16511da177e4SLinus Torvalds ABR sched 0x6000 and ABR wait queue (1K - 2K) each 16521da177e4SLinus Torvalds CBR sched 0x7000 (as needed) 16531da177e4SLinus Torvalds VC table 0x8000 (1K - 32K) 16541da177e4SLinus Torvalds */ 16551da177e4SLinus Torvalds 16561da177e4SLinus Torvalds static void tx_intr(struct atm_dev *dev) 16571da177e4SLinus Torvalds { 16581da177e4SLinus Torvalds IADEV *iadev; 16591da177e4SLinus Torvalds unsigned short status; 16601da177e4SLinus Torvalds unsigned long flags; 16611da177e4SLinus Torvalds 16621da177e4SLinus Torvalds iadev = INPH_IA_DEV(dev); 16631da177e4SLinus Torvalds 16641da177e4SLinus Torvalds status = readl(iadev->seg_reg+SEG_INTR_STATUS_REG); 16651da177e4SLinus Torvalds if (status & TRANSMIT_DONE){ 16661da177e4SLinus Torvalds 16671da177e4SLinus Torvalds IF_EVENT(printk("Tansmit Done Intr logic run\n");) 16681da177e4SLinus Torvalds spin_lock_irqsave(&iadev->tx_lock, flags); 16691da177e4SLinus Torvalds ia_tx_poll(iadev); 16701da177e4SLinus Torvalds spin_unlock_irqrestore(&iadev->tx_lock, flags); 16711da177e4SLinus Torvalds writew(TRANSMIT_DONE, iadev->seg_reg+SEG_INTR_STATUS_REG); 16721da177e4SLinus Torvalds if (iadev->close_pending) 16731da177e4SLinus Torvalds wake_up(&iadev->close_wait); 16741da177e4SLinus Torvalds } 16751da177e4SLinus Torvalds if (status & TCQ_NOT_EMPTY) 16761da177e4SLinus Torvalds { 16771da177e4SLinus Torvalds IF_EVENT(printk("TCQ_NOT_EMPTY int received\n");) 16781da177e4SLinus Torvalds } 16791da177e4SLinus Torvalds } 16801da177e4SLinus Torvalds 16811da177e4SLinus Torvalds static void tx_dle_intr(struct atm_dev *dev) 16821da177e4SLinus Torvalds { 16831da177e4SLinus Torvalds IADEV *iadev; 16841da177e4SLinus Torvalds struct dle *dle, *cur_dle; 16851da177e4SLinus Torvalds struct sk_buff *skb; 16861da177e4SLinus Torvalds struct atm_vcc *vcc; 16871da177e4SLinus Torvalds struct ia_vcc *iavcc; 16881da177e4SLinus Torvalds u_int dle_lp; 16891da177e4SLinus Torvalds unsigned long flags; 16901da177e4SLinus Torvalds 16911da177e4SLinus Torvalds iadev = INPH_IA_DEV(dev); 16921da177e4SLinus Torvalds spin_lock_irqsave(&iadev->tx_lock, flags); 16931da177e4SLinus Torvalds dle = iadev->tx_dle_q.read; 16941da177e4SLinus Torvalds dle_lp = readl(iadev->dma+IPHASE5575_TX_LIST_ADDR) & 16951da177e4SLinus Torvalds (sizeof(struct dle)*DLE_ENTRIES - 1); 16961da177e4SLinus Torvalds cur_dle = (struct dle*)(iadev->tx_dle_q.start + (dle_lp >> 4)); 16971da177e4SLinus Torvalds while (dle != cur_dle) 16981da177e4SLinus Torvalds { 16991da177e4SLinus Torvalds /* free the DMAed skb */ 17001da177e4SLinus Torvalds skb = skb_dequeue(&iadev->tx_dma_q); 17011da177e4SLinus Torvalds if (!skb) break; 17021da177e4SLinus Torvalds 17031da177e4SLinus Torvalds /* Revenge of the 2 dle (skb + trailer) used in ia_pkt_tx() */ 17041da177e4SLinus Torvalds if (!((dle - iadev->tx_dle_q.start)%(2*sizeof(struct dle)))) { 17051da177e4SLinus Torvalds pci_unmap_single(iadev->pci, dle->sys_pkt_addr, skb->len, 17061da177e4SLinus Torvalds PCI_DMA_TODEVICE); 17071da177e4SLinus Torvalds } 17081da177e4SLinus Torvalds vcc = ATM_SKB(skb)->vcc; 17091da177e4SLinus Torvalds if (!vcc) { 17101da177e4SLinus Torvalds printk("tx_dle_intr: vcc is null\n"); 17111da177e4SLinus Torvalds spin_unlock_irqrestore(&iadev->tx_lock, flags); 17121da177e4SLinus Torvalds dev_kfree_skb_any(skb); 17131da177e4SLinus Torvalds 17141da177e4SLinus Torvalds return; 17151da177e4SLinus Torvalds } 17161da177e4SLinus Torvalds iavcc = INPH_IA_VCC(vcc); 17171da177e4SLinus Torvalds if (!iavcc) { 17181da177e4SLinus Torvalds printk("tx_dle_intr: iavcc is null\n"); 17191da177e4SLinus Torvalds spin_unlock_irqrestore(&iadev->tx_lock, flags); 17201da177e4SLinus Torvalds dev_kfree_skb_any(skb); 17211da177e4SLinus Torvalds return; 17221da177e4SLinus Torvalds } 17231da177e4SLinus Torvalds if (vcc->qos.txtp.pcr >= iadev->rate_limit) { 17241da177e4SLinus Torvalds if ((vcc->pop) && (skb->len != 0)) 17251da177e4SLinus Torvalds { 17261da177e4SLinus Torvalds vcc->pop(vcc, skb); 17271da177e4SLinus Torvalds } 17281da177e4SLinus Torvalds else { 17291da177e4SLinus Torvalds dev_kfree_skb_any(skb); 17301da177e4SLinus Torvalds } 17311da177e4SLinus Torvalds } 17321da177e4SLinus Torvalds else { /* Hold the rate-limited skb for flow control */ 17331da177e4SLinus Torvalds IA_SKB_STATE(skb) |= IA_DLED; 17341da177e4SLinus Torvalds skb_queue_tail(&iavcc->txing_skb, skb); 17351da177e4SLinus Torvalds } 1736849e8caaSDavid Howells IF_EVENT(printk("tx_dle_intr: enque skb = 0x%p \n", skb);) 17371da177e4SLinus Torvalds if (++dle == iadev->tx_dle_q.end) 17381da177e4SLinus Torvalds dle = iadev->tx_dle_q.start; 17391da177e4SLinus Torvalds } 17401da177e4SLinus Torvalds iadev->tx_dle_q.read = dle; 17411da177e4SLinus Torvalds spin_unlock_irqrestore(&iadev->tx_lock, flags); 17421da177e4SLinus Torvalds } 17431da177e4SLinus Torvalds 17441da177e4SLinus Torvalds static int open_tx(struct atm_vcc *vcc) 17451da177e4SLinus Torvalds { 17461da177e4SLinus Torvalds struct ia_vcc *ia_vcc; 17471da177e4SLinus Torvalds IADEV *iadev; 17481da177e4SLinus Torvalds struct main_vc *vc; 17491da177e4SLinus Torvalds struct ext_vc *evc; 17501da177e4SLinus Torvalds int ret; 17511da177e4SLinus Torvalds IF_EVENT(printk("iadev: open_tx entered vcc->vci = %d\n", vcc->vci);) 17521da177e4SLinus Torvalds if (vcc->qos.txtp.traffic_class == ATM_NONE) return 0; 17531da177e4SLinus Torvalds iadev = INPH_IA_DEV(vcc->dev); 17541da177e4SLinus Torvalds 17551da177e4SLinus Torvalds if (iadev->phy_type & FE_25MBIT_PHY) { 17561da177e4SLinus Torvalds if (vcc->qos.txtp.traffic_class == ATM_ABR) { 17571da177e4SLinus Torvalds printk("IA: ABR not support\n"); 17581da177e4SLinus Torvalds return -EINVAL; 17591da177e4SLinus Torvalds } 17601da177e4SLinus Torvalds if (vcc->qos.txtp.traffic_class == ATM_CBR) { 17611da177e4SLinus Torvalds printk("IA: CBR not support\n"); 17621da177e4SLinus Torvalds return -EINVAL; 17631da177e4SLinus Torvalds } 17641da177e4SLinus Torvalds } 17651da177e4SLinus Torvalds ia_vcc = INPH_IA_VCC(vcc); 17661da177e4SLinus Torvalds memset((caddr_t)ia_vcc, 0, sizeof(*ia_vcc)); 17671da177e4SLinus Torvalds if (vcc->qos.txtp.max_sdu > 17681da177e4SLinus Torvalds (iadev->tx_buf_sz - sizeof(struct cpcs_trailer))){ 17691da177e4SLinus Torvalds printk("IA: SDU size over (%d) the configured SDU size %d\n", 17701da177e4SLinus Torvalds vcc->qos.txtp.max_sdu,iadev->tx_buf_sz); 17711da177e4SLinus Torvalds vcc->dev_data = NULL; 17721da177e4SLinus Torvalds kfree(ia_vcc); 17731da177e4SLinus Torvalds return -EINVAL; 17741da177e4SLinus Torvalds } 17751da177e4SLinus Torvalds ia_vcc->vc_desc_cnt = 0; 17761da177e4SLinus Torvalds ia_vcc->txing = 1; 17771da177e4SLinus Torvalds 17781da177e4SLinus Torvalds /* find pcr */ 17791da177e4SLinus Torvalds if (vcc->qos.txtp.max_pcr == ATM_MAX_PCR) 17801da177e4SLinus Torvalds vcc->qos.txtp.pcr = iadev->LineRate; 17811da177e4SLinus Torvalds else if ((vcc->qos.txtp.max_pcr == 0)&&( vcc->qos.txtp.pcr <= 0)) 17821da177e4SLinus Torvalds vcc->qos.txtp.pcr = iadev->LineRate; 17831da177e4SLinus Torvalds else if ((vcc->qos.txtp.max_pcr > vcc->qos.txtp.pcr) && (vcc->qos.txtp.max_pcr> 0)) 17841da177e4SLinus Torvalds vcc->qos.txtp.pcr = vcc->qos.txtp.max_pcr; 17851da177e4SLinus Torvalds if (vcc->qos.txtp.pcr > iadev->LineRate) 17861da177e4SLinus Torvalds vcc->qos.txtp.pcr = iadev->LineRate; 17871da177e4SLinus Torvalds ia_vcc->pcr = vcc->qos.txtp.pcr; 17881da177e4SLinus Torvalds 17891da177e4SLinus Torvalds if (ia_vcc->pcr > (iadev->LineRate / 6) ) ia_vcc->ltimeout = HZ / 10; 17901da177e4SLinus Torvalds else if (ia_vcc->pcr > (iadev->LineRate / 130)) ia_vcc->ltimeout = HZ; 17911da177e4SLinus Torvalds else if (ia_vcc->pcr <= 170) ia_vcc->ltimeout = 16 * HZ; 17921da177e4SLinus Torvalds else ia_vcc->ltimeout = 2700 * HZ / ia_vcc->pcr; 17931da177e4SLinus Torvalds if (ia_vcc->pcr < iadev->rate_limit) 17941da177e4SLinus Torvalds skb_queue_head_init (&ia_vcc->txing_skb); 17951da177e4SLinus Torvalds if (ia_vcc->pcr < iadev->rate_limit) { 17961da177e4SLinus Torvalds struct sock *sk = sk_atm(vcc); 17971da177e4SLinus Torvalds 17981da177e4SLinus Torvalds if (vcc->qos.txtp.max_sdu != 0) { 17991da177e4SLinus Torvalds if (ia_vcc->pcr > 60000) 18001da177e4SLinus Torvalds sk->sk_sndbuf = vcc->qos.txtp.max_sdu * 5; 18011da177e4SLinus Torvalds else if (ia_vcc->pcr > 2000) 18021da177e4SLinus Torvalds sk->sk_sndbuf = vcc->qos.txtp.max_sdu * 4; 18031da177e4SLinus Torvalds else 18041da177e4SLinus Torvalds sk->sk_sndbuf = vcc->qos.txtp.max_sdu * 3; 18051da177e4SLinus Torvalds } 18061da177e4SLinus Torvalds else 18071da177e4SLinus Torvalds sk->sk_sndbuf = 24576; 18081da177e4SLinus Torvalds } 18091da177e4SLinus Torvalds 18101da177e4SLinus Torvalds vc = (struct main_vc *)iadev->MAIN_VC_TABLE_ADDR; 18111da177e4SLinus Torvalds evc = (struct ext_vc *)iadev->EXT_VC_TABLE_ADDR; 18121da177e4SLinus Torvalds vc += vcc->vci; 18131da177e4SLinus Torvalds evc += vcc->vci; 18141da177e4SLinus Torvalds memset((caddr_t)vc, 0, sizeof(*vc)); 18151da177e4SLinus Torvalds memset((caddr_t)evc, 0, sizeof(*evc)); 18161da177e4SLinus Torvalds 18171da177e4SLinus Torvalds /* store the most significant 4 bits of vci as the last 4 bits 18181da177e4SLinus Torvalds of first part of atm header. 18191da177e4SLinus Torvalds store the last 12 bits of vci as first 12 bits of the second 18201da177e4SLinus Torvalds part of the atm header. 18211da177e4SLinus Torvalds */ 18221da177e4SLinus Torvalds evc->atm_hdr1 = (vcc->vci >> 12) & 0x000f; 18231da177e4SLinus Torvalds evc->atm_hdr2 = (vcc->vci & 0x0fff) << 4; 18241da177e4SLinus Torvalds 18251da177e4SLinus Torvalds /* check the following for different traffic classes */ 18261da177e4SLinus Torvalds if (vcc->qos.txtp.traffic_class == ATM_UBR) 18271da177e4SLinus Torvalds { 18281da177e4SLinus Torvalds vc->type = UBR; 18291da177e4SLinus Torvalds vc->status = CRC_APPEND; 18301da177e4SLinus Torvalds vc->acr = cellrate_to_float(iadev->LineRate); 18311da177e4SLinus Torvalds if (vcc->qos.txtp.pcr > 0) 18321da177e4SLinus Torvalds vc->acr = cellrate_to_float(vcc->qos.txtp.pcr); 18331da177e4SLinus Torvalds IF_UBR(printk("UBR: txtp.pcr = 0x%x f_rate = 0x%x\n", 18341da177e4SLinus Torvalds vcc->qos.txtp.max_pcr,vc->acr);) 18351da177e4SLinus Torvalds } 18361da177e4SLinus Torvalds else if (vcc->qos.txtp.traffic_class == ATM_ABR) 18371da177e4SLinus Torvalds { srv_cls_param_t srv_p; 18381da177e4SLinus Torvalds IF_ABR(printk("Tx ABR VCC\n");) 18391da177e4SLinus Torvalds init_abr_vc(iadev, &srv_p); 18401da177e4SLinus Torvalds if (vcc->qos.txtp.pcr > 0) 18411da177e4SLinus Torvalds srv_p.pcr = vcc->qos.txtp.pcr; 18421da177e4SLinus Torvalds if (vcc->qos.txtp.min_pcr > 0) { 18431da177e4SLinus Torvalds int tmpsum = iadev->sum_mcr+iadev->sum_cbr+vcc->qos.txtp.min_pcr; 18441da177e4SLinus Torvalds if (tmpsum > iadev->LineRate) 18451da177e4SLinus Torvalds return -EBUSY; 18461da177e4SLinus Torvalds srv_p.mcr = vcc->qos.txtp.min_pcr; 18471da177e4SLinus Torvalds iadev->sum_mcr += vcc->qos.txtp.min_pcr; 18481da177e4SLinus Torvalds } 18491da177e4SLinus Torvalds else srv_p.mcr = 0; 18501da177e4SLinus Torvalds if (vcc->qos.txtp.icr) 18511da177e4SLinus Torvalds srv_p.icr = vcc->qos.txtp.icr; 18521da177e4SLinus Torvalds if (vcc->qos.txtp.tbe) 18531da177e4SLinus Torvalds srv_p.tbe = vcc->qos.txtp.tbe; 18541da177e4SLinus Torvalds if (vcc->qos.txtp.frtt) 18551da177e4SLinus Torvalds srv_p.frtt = vcc->qos.txtp.frtt; 18561da177e4SLinus Torvalds if (vcc->qos.txtp.rif) 18571da177e4SLinus Torvalds srv_p.rif = vcc->qos.txtp.rif; 18581da177e4SLinus Torvalds if (vcc->qos.txtp.rdf) 18591da177e4SLinus Torvalds srv_p.rdf = vcc->qos.txtp.rdf; 18601da177e4SLinus Torvalds if (vcc->qos.txtp.nrm_pres) 18611da177e4SLinus Torvalds srv_p.nrm = vcc->qos.txtp.nrm; 18621da177e4SLinus Torvalds if (vcc->qos.txtp.trm_pres) 18631da177e4SLinus Torvalds srv_p.trm = vcc->qos.txtp.trm; 18641da177e4SLinus Torvalds if (vcc->qos.txtp.adtf_pres) 18651da177e4SLinus Torvalds srv_p.adtf = vcc->qos.txtp.adtf; 18661da177e4SLinus Torvalds if (vcc->qos.txtp.cdf_pres) 18671da177e4SLinus Torvalds srv_p.cdf = vcc->qos.txtp.cdf; 18681da177e4SLinus Torvalds if (srv_p.icr > srv_p.pcr) 18691da177e4SLinus Torvalds srv_p.icr = srv_p.pcr; 18701da177e4SLinus Torvalds IF_ABR(printk("ABR:vcc->qos.txtp.max_pcr = %d mcr = %d\n", 18711da177e4SLinus Torvalds srv_p.pcr, srv_p.mcr);) 18721da177e4SLinus Torvalds ia_open_abr_vc(iadev, &srv_p, vcc, 1); 18731da177e4SLinus Torvalds } else if (vcc->qos.txtp.traffic_class == ATM_CBR) { 18741da177e4SLinus Torvalds if (iadev->phy_type & FE_25MBIT_PHY) { 18751da177e4SLinus Torvalds printk("IA: CBR not support\n"); 18761da177e4SLinus Torvalds return -EINVAL; 18771da177e4SLinus Torvalds } 18781da177e4SLinus Torvalds if (vcc->qos.txtp.max_pcr > iadev->LineRate) { 187925985edcSLucas De Marchi IF_CBR(printk("PCR is not available\n");) 18801da177e4SLinus Torvalds return -1; 18811da177e4SLinus Torvalds } 18821da177e4SLinus Torvalds vc->type = CBR; 18831da177e4SLinus Torvalds vc->status = CRC_APPEND; 18841da177e4SLinus Torvalds if ((ret = ia_cbr_setup (iadev, vcc)) < 0) { 18851da177e4SLinus Torvalds return ret; 18861da177e4SLinus Torvalds } 18871da177e4SLinus Torvalds } 18881da177e4SLinus Torvalds else 18891da177e4SLinus Torvalds printk("iadev: Non UBR, ABR and CBR traffic not supportedn"); 18901da177e4SLinus Torvalds 18911da177e4SLinus Torvalds iadev->testTable[vcc->vci]->vc_status |= VC_ACTIVE; 18921da177e4SLinus Torvalds IF_EVENT(printk("ia open_tx returning \n");) 18931da177e4SLinus Torvalds return 0; 18941da177e4SLinus Torvalds } 18951da177e4SLinus Torvalds 18961da177e4SLinus Torvalds 18971da177e4SLinus Torvalds static int tx_init(struct atm_dev *dev) 18981da177e4SLinus Torvalds { 18991da177e4SLinus Torvalds IADEV *iadev; 19001da177e4SLinus Torvalds struct tx_buf_desc *buf_desc_ptr; 19011da177e4SLinus Torvalds unsigned int tx_pkt_start; 19021da177e4SLinus Torvalds void *dle_addr; 19031da177e4SLinus Torvalds int i; 19041da177e4SLinus Torvalds u_short tcq_st_adr; 19051da177e4SLinus Torvalds u_short *tcq_start; 19061da177e4SLinus Torvalds u_short prq_st_adr; 19071da177e4SLinus Torvalds u_short *prq_start; 19081da177e4SLinus Torvalds struct main_vc *vc; 19091da177e4SLinus Torvalds struct ext_vc *evc; 19101da177e4SLinus Torvalds u_short tmp16; 19111da177e4SLinus Torvalds u32 vcsize_sel; 19121da177e4SLinus Torvalds 19131da177e4SLinus Torvalds iadev = INPH_IA_DEV(dev); 19141da177e4SLinus Torvalds spin_lock_init(&iadev->tx_lock); 19151da177e4SLinus Torvalds 19161da177e4SLinus Torvalds IF_INIT(printk("Tx MASK REG: 0x%0x\n", 19171da177e4SLinus Torvalds readw(iadev->seg_reg+SEG_MASK_REG));) 19181da177e4SLinus Torvalds 19191da177e4SLinus Torvalds /* Allocate 4k (boundary aligned) bytes */ 19201da177e4SLinus Torvalds dle_addr = pci_alloc_consistent(iadev->pci, DLE_TOTAL_SIZE, 19211da177e4SLinus Torvalds &iadev->tx_dle_dma); 19221da177e4SLinus Torvalds if (!dle_addr) { 19231da177e4SLinus Torvalds printk(KERN_ERR DEV_LABEL "can't allocate DLEs\n"); 19241da177e4SLinus Torvalds goto err_out; 19251da177e4SLinus Torvalds } 19261da177e4SLinus Torvalds iadev->tx_dle_q.start = (struct dle*)dle_addr; 19271da177e4SLinus Torvalds iadev->tx_dle_q.read = iadev->tx_dle_q.start; 19281da177e4SLinus Torvalds iadev->tx_dle_q.write = iadev->tx_dle_q.start; 192997928f70SAlan Cox iadev->tx_dle_q.end = (struct dle*)((unsigned long)dle_addr+sizeof(struct dle)*DLE_ENTRIES); 19301da177e4SLinus Torvalds 19311da177e4SLinus Torvalds /* write the upper 20 bits of the start address to tx list address register */ 19321da177e4SLinus Torvalds writel(iadev->tx_dle_dma & 0xfffff000, 19331da177e4SLinus Torvalds iadev->dma + IPHASE5575_TX_LIST_ADDR); 19341da177e4SLinus Torvalds writew(0xffff, iadev->seg_reg+SEG_MASK_REG); 19351da177e4SLinus Torvalds writew(0, iadev->seg_reg+MODE_REG_0); 19361da177e4SLinus Torvalds writew(RESET_SEG, iadev->seg_reg+SEG_COMMAND_REG); 19371da177e4SLinus Torvalds iadev->MAIN_VC_TABLE_ADDR = iadev->seg_ram+MAIN_VC_TABLE*iadev->memSize; 19381da177e4SLinus Torvalds iadev->EXT_VC_TABLE_ADDR = iadev->seg_ram+EXT_VC_TABLE*iadev->memSize; 19391da177e4SLinus Torvalds iadev->ABR_SCHED_TABLE_ADDR=iadev->seg_ram+ABR_SCHED_TABLE*iadev->memSize; 19401da177e4SLinus Torvalds 19411da177e4SLinus Torvalds /* 19421da177e4SLinus Torvalds Transmit side control memory map 19431da177e4SLinus Torvalds -------------------------------- 19441da177e4SLinus Torvalds Buffer descr 0x0000 (128 - 4K) 19451da177e4SLinus Torvalds Commn queues 0x1000 Transmit comp, Packet ready(0x1400) 19461da177e4SLinus Torvalds (512 - 1K) each 19471da177e4SLinus Torvalds TCQ - 4K, PRQ - 5K 19481da177e4SLinus Torvalds CBR Table 0x1800 (as needed) - 6K 19491da177e4SLinus Torvalds UBR Table 0x3000 (1K - 4K) - 12K 19501da177e4SLinus Torvalds UBR Wait queue 0x4000 (1K - 4K) - 16K 19511da177e4SLinus Torvalds ABR sched 0x5000 and ABR wait queue (1K - 2K) each 19521da177e4SLinus Torvalds ABR Tbl - 20K, ABR Wq - 22K 19531da177e4SLinus Torvalds extended VC 0x6000 (1K - 8K) - 24K 19541da177e4SLinus Torvalds VC Table 0x8000 (1K - 32K) - 32K 19551da177e4SLinus Torvalds 19561da177e4SLinus Torvalds Between 0x2000 (8K) and 0x3000 (12K) there is 4K space left for VBR Tbl 19571da177e4SLinus Torvalds and Wait q, which can be allotted later. 19581da177e4SLinus Torvalds */ 19591da177e4SLinus Torvalds 19601da177e4SLinus Torvalds /* Buffer Descriptor Table Base address */ 19611da177e4SLinus Torvalds writew(TX_DESC_BASE, iadev->seg_reg+SEG_DESC_BASE); 19621da177e4SLinus Torvalds 19631da177e4SLinus Torvalds /* initialize each entry in the buffer descriptor table */ 19641da177e4SLinus Torvalds buf_desc_ptr =(struct tx_buf_desc *)(iadev->seg_ram+TX_DESC_BASE); 19651da177e4SLinus Torvalds memset((caddr_t)buf_desc_ptr, 0, sizeof(*buf_desc_ptr)); 19661da177e4SLinus Torvalds buf_desc_ptr++; 19671da177e4SLinus Torvalds tx_pkt_start = TX_PACKET_RAM; 19681da177e4SLinus Torvalds for(i=1; i<=iadev->num_tx_desc; i++) 19691da177e4SLinus Torvalds { 19701da177e4SLinus Torvalds memset((caddr_t)buf_desc_ptr, 0, sizeof(*buf_desc_ptr)); 19711da177e4SLinus Torvalds buf_desc_ptr->desc_mode = AAL5; 19721da177e4SLinus Torvalds buf_desc_ptr->buf_start_hi = tx_pkt_start >> 16; 19731da177e4SLinus Torvalds buf_desc_ptr->buf_start_lo = tx_pkt_start & 0x0000ffff; 19741da177e4SLinus Torvalds buf_desc_ptr++; 19751da177e4SLinus Torvalds tx_pkt_start += iadev->tx_buf_sz; 19761da177e4SLinus Torvalds } 19771da177e4SLinus Torvalds iadev->tx_buf = kmalloc(iadev->num_tx_desc*sizeof(struct cpcs_trailer_desc), GFP_KERNEL); 19781da177e4SLinus Torvalds if (!iadev->tx_buf) { 19791da177e4SLinus Torvalds printk(KERN_ERR DEV_LABEL " couldn't get mem\n"); 19801da177e4SLinus Torvalds goto err_free_dle; 19811da177e4SLinus Torvalds } 19821da177e4SLinus Torvalds for (i= 0; i< iadev->num_tx_desc; i++) 19831da177e4SLinus Torvalds { 19841da177e4SLinus Torvalds struct cpcs_trailer *cpcs; 19851da177e4SLinus Torvalds 19861da177e4SLinus Torvalds cpcs = kmalloc(sizeof(*cpcs), GFP_KERNEL|GFP_DMA); 19871da177e4SLinus Torvalds if(!cpcs) { 19881da177e4SLinus Torvalds printk(KERN_ERR DEV_LABEL " couldn't get freepage\n"); 19891da177e4SLinus Torvalds goto err_free_tx_bufs; 19901da177e4SLinus Torvalds } 19911da177e4SLinus Torvalds iadev->tx_buf[i].cpcs = cpcs; 19921da177e4SLinus Torvalds iadev->tx_buf[i].dma_addr = pci_map_single(iadev->pci, 19931da177e4SLinus Torvalds cpcs, sizeof(*cpcs), PCI_DMA_TODEVICE); 19941da177e4SLinus Torvalds } 19951da177e4SLinus Torvalds iadev->desc_tbl = kmalloc(iadev->num_tx_desc * 19961da177e4SLinus Torvalds sizeof(struct desc_tbl_t), GFP_KERNEL); 19971da177e4SLinus Torvalds if (!iadev->desc_tbl) { 19981da177e4SLinus Torvalds printk(KERN_ERR DEV_LABEL " couldn't get mem\n"); 19991da177e4SLinus Torvalds goto err_free_all_tx_bufs; 20001da177e4SLinus Torvalds } 20011da177e4SLinus Torvalds 20021da177e4SLinus Torvalds /* Communication Queues base address */ 20031da177e4SLinus Torvalds i = TX_COMP_Q * iadev->memSize; 20041da177e4SLinus Torvalds writew(i >> 16, iadev->seg_reg+SEG_QUEUE_BASE); 20051da177e4SLinus Torvalds 20061da177e4SLinus Torvalds /* Transmit Complete Queue */ 20071da177e4SLinus Torvalds writew(i, iadev->seg_reg+TCQ_ST_ADR); 20081da177e4SLinus Torvalds writew(i, iadev->seg_reg+TCQ_RD_PTR); 20091da177e4SLinus Torvalds writew(i+iadev->num_tx_desc*sizeof(u_short),iadev->seg_reg+TCQ_WR_PTR); 20101da177e4SLinus Torvalds iadev->host_tcq_wr = i + iadev->num_tx_desc*sizeof(u_short); 20111da177e4SLinus Torvalds writew(i+2 * iadev->num_tx_desc * sizeof(u_short), 20121da177e4SLinus Torvalds iadev->seg_reg+TCQ_ED_ADR); 20131da177e4SLinus Torvalds /* Fill the TCQ with all the free descriptors. */ 20141da177e4SLinus Torvalds tcq_st_adr = readw(iadev->seg_reg+TCQ_ST_ADR); 20151da177e4SLinus Torvalds tcq_start = (u_short *)(iadev->seg_ram+tcq_st_adr); 20161da177e4SLinus Torvalds for(i=1; i<=iadev->num_tx_desc; i++) 20171da177e4SLinus Torvalds { 20181da177e4SLinus Torvalds *tcq_start = (u_short)i; 20191da177e4SLinus Torvalds tcq_start++; 20201da177e4SLinus Torvalds } 20211da177e4SLinus Torvalds 20221da177e4SLinus Torvalds /* Packet Ready Queue */ 20231da177e4SLinus Torvalds i = PKT_RDY_Q * iadev->memSize; 20241da177e4SLinus Torvalds writew(i, iadev->seg_reg+PRQ_ST_ADR); 20251da177e4SLinus Torvalds writew(i+2 * iadev->num_tx_desc * sizeof(u_short), 20261da177e4SLinus Torvalds iadev->seg_reg+PRQ_ED_ADR); 20271da177e4SLinus Torvalds writew(i, iadev->seg_reg+PRQ_RD_PTR); 20281da177e4SLinus Torvalds writew(i, iadev->seg_reg+PRQ_WR_PTR); 20291da177e4SLinus Torvalds 20301da177e4SLinus Torvalds /* Load local copy of PRQ and TCQ ptrs */ 20311da177e4SLinus Torvalds iadev->ffL.prq_st = readw(iadev->seg_reg+PRQ_ST_ADR) & 0xffff; 20321da177e4SLinus Torvalds iadev->ffL.prq_ed = readw(iadev->seg_reg+PRQ_ED_ADR) & 0xffff; 20331da177e4SLinus Torvalds iadev->ffL.prq_wr = readw(iadev->seg_reg+PRQ_WR_PTR) & 0xffff; 20341da177e4SLinus Torvalds 20351da177e4SLinus Torvalds iadev->ffL.tcq_st = readw(iadev->seg_reg+TCQ_ST_ADR) & 0xffff; 20361da177e4SLinus Torvalds iadev->ffL.tcq_ed = readw(iadev->seg_reg+TCQ_ED_ADR) & 0xffff; 20371da177e4SLinus Torvalds iadev->ffL.tcq_rd = readw(iadev->seg_reg+TCQ_RD_PTR) & 0xffff; 20381da177e4SLinus Torvalds 20391da177e4SLinus Torvalds /* Just for safety initializing the queue to have desc 1 always */ 20401da177e4SLinus Torvalds /* Fill the PRQ with all the free descriptors. */ 20411da177e4SLinus Torvalds prq_st_adr = readw(iadev->seg_reg+PRQ_ST_ADR); 20421da177e4SLinus Torvalds prq_start = (u_short *)(iadev->seg_ram+prq_st_adr); 20431da177e4SLinus Torvalds for(i=1; i<=iadev->num_tx_desc; i++) 20441da177e4SLinus Torvalds { 20451da177e4SLinus Torvalds *prq_start = (u_short)0; /* desc 1 in all entries */ 20461da177e4SLinus Torvalds prq_start++; 20471da177e4SLinus Torvalds } 20481da177e4SLinus Torvalds /* CBR Table */ 20491da177e4SLinus Torvalds IF_INIT(printk("Start CBR Init\n");) 20501da177e4SLinus Torvalds #if 1 /* for 1K VC board, CBR_PTR_BASE is 0 */ 20511da177e4SLinus Torvalds writew(0,iadev->seg_reg+CBR_PTR_BASE); 20521da177e4SLinus Torvalds #else /* Charlie's logic is wrong ? */ 20531da177e4SLinus Torvalds tmp16 = (iadev->seg_ram+CBR_SCHED_TABLE*iadev->memSize)>>17; 20541da177e4SLinus Torvalds IF_INIT(printk("cbr_ptr_base = 0x%x ", tmp16);) 20551da177e4SLinus Torvalds writew(tmp16,iadev->seg_reg+CBR_PTR_BASE); 20561da177e4SLinus Torvalds #endif 20571da177e4SLinus Torvalds 20581da177e4SLinus Torvalds IF_INIT(printk("value in register = 0x%x\n", 20591da177e4SLinus Torvalds readw(iadev->seg_reg+CBR_PTR_BASE));) 20601da177e4SLinus Torvalds tmp16 = (CBR_SCHED_TABLE*iadev->memSize) >> 1; 20611da177e4SLinus Torvalds writew(tmp16, iadev->seg_reg+CBR_TAB_BEG); 20621da177e4SLinus Torvalds IF_INIT(printk("cbr_tab_beg = 0x%x in reg = 0x%x \n", tmp16, 20631da177e4SLinus Torvalds readw(iadev->seg_reg+CBR_TAB_BEG));) 20641da177e4SLinus Torvalds writew(tmp16, iadev->seg_reg+CBR_TAB_END+1); // CBR_PTR; 20651da177e4SLinus Torvalds tmp16 = (CBR_SCHED_TABLE*iadev->memSize + iadev->num_vc*6 - 2) >> 1; 20661da177e4SLinus Torvalds writew(tmp16, iadev->seg_reg+CBR_TAB_END); 2067849e8caaSDavid Howells IF_INIT(printk("iadev->seg_reg = 0x%p CBR_PTR_BASE = 0x%x\n", 2068849e8caaSDavid Howells iadev->seg_reg, readw(iadev->seg_reg+CBR_PTR_BASE));) 20691da177e4SLinus Torvalds IF_INIT(printk("CBR_TAB_BEG = 0x%x, CBR_TAB_END = 0x%x, CBR_PTR = 0x%x\n", 20701da177e4SLinus Torvalds readw(iadev->seg_reg+CBR_TAB_BEG), readw(iadev->seg_reg+CBR_TAB_END), 20711da177e4SLinus Torvalds readw(iadev->seg_reg+CBR_TAB_END+1));) 20721da177e4SLinus Torvalds 20731da177e4SLinus Torvalds /* Initialize the CBR Schedualing Table */ 20741da177e4SLinus Torvalds memset_io(iadev->seg_ram+CBR_SCHED_TABLE*iadev->memSize, 20751da177e4SLinus Torvalds 0, iadev->num_vc*6); 20761da177e4SLinus Torvalds iadev->CbrRemEntries = iadev->CbrTotEntries = iadev->num_vc*3; 20771da177e4SLinus Torvalds iadev->CbrEntryPt = 0; 20781da177e4SLinus Torvalds iadev->Granularity = MAX_ATM_155 / iadev->CbrTotEntries; 20791da177e4SLinus Torvalds iadev->NumEnabledCBR = 0; 20801da177e4SLinus Torvalds 20811da177e4SLinus Torvalds /* UBR scheduling Table and wait queue */ 20821da177e4SLinus Torvalds /* initialize all bytes of UBR scheduler table and wait queue to 0 20831da177e4SLinus Torvalds - SCHEDSZ is 1K (# of entries). 20841da177e4SLinus Torvalds - UBR Table size is 4K 20851da177e4SLinus Torvalds - UBR wait queue is 4K 20861da177e4SLinus Torvalds since the table and wait queues are contiguous, all the bytes 20871da177e4SLinus Torvalds can be initialized by one memeset. 20881da177e4SLinus Torvalds */ 20891da177e4SLinus Torvalds 20901da177e4SLinus Torvalds vcsize_sel = 0; 20911da177e4SLinus Torvalds i = 8*1024; 20921da177e4SLinus Torvalds while (i != iadev->num_vc) { 20931da177e4SLinus Torvalds i /= 2; 20941da177e4SLinus Torvalds vcsize_sel++; 20951da177e4SLinus Torvalds } 20961da177e4SLinus Torvalds 20971da177e4SLinus Torvalds i = MAIN_VC_TABLE * iadev->memSize; 20981da177e4SLinus Torvalds writew(vcsize_sel | ((i >> 8) & 0xfff8),iadev->seg_reg+VCT_BASE); 20991da177e4SLinus Torvalds i = EXT_VC_TABLE * iadev->memSize; 21001da177e4SLinus Torvalds writew((i >> 8) & 0xfffe, iadev->seg_reg+VCTE_BASE); 21011da177e4SLinus Torvalds i = UBR_SCHED_TABLE * iadev->memSize; 21021da177e4SLinus Torvalds writew((i & 0xffff) >> 11, iadev->seg_reg+UBR_SBPTR_BASE); 21031da177e4SLinus Torvalds i = UBR_WAIT_Q * iadev->memSize; 21041da177e4SLinus Torvalds writew((i >> 7) & 0xffff, iadev->seg_reg+UBRWQ_BASE); 21051da177e4SLinus Torvalds memset((caddr_t)(iadev->seg_ram+UBR_SCHED_TABLE*iadev->memSize), 21061da177e4SLinus Torvalds 0, iadev->num_vc*8); 21071da177e4SLinus Torvalds /* ABR scheduling Table(0x5000-0x57ff) and wait queue(0x5800-0x5fff)*/ 21081da177e4SLinus Torvalds /* initialize all bytes of ABR scheduler table and wait queue to 0 21091da177e4SLinus Torvalds - SCHEDSZ is 1K (# of entries). 21101da177e4SLinus Torvalds - ABR Table size is 2K 21111da177e4SLinus Torvalds - ABR wait queue is 2K 21121da177e4SLinus Torvalds since the table and wait queues are contiguous, all the bytes 2113b595076aSUwe Kleine-König can be initialized by one memeset. 21141da177e4SLinus Torvalds */ 21151da177e4SLinus Torvalds i = ABR_SCHED_TABLE * iadev->memSize; 21161da177e4SLinus Torvalds writew((i >> 11) & 0xffff, iadev->seg_reg+ABR_SBPTR_BASE); 21171da177e4SLinus Torvalds i = ABR_WAIT_Q * iadev->memSize; 21181da177e4SLinus Torvalds writew((i >> 7) & 0xffff, iadev->seg_reg+ABRWQ_BASE); 21191da177e4SLinus Torvalds 21201da177e4SLinus Torvalds i = ABR_SCHED_TABLE*iadev->memSize; 21211da177e4SLinus Torvalds memset((caddr_t)(iadev->seg_ram+i), 0, iadev->num_vc*4); 21221da177e4SLinus Torvalds vc = (struct main_vc *)iadev->MAIN_VC_TABLE_ADDR; 21231da177e4SLinus Torvalds evc = (struct ext_vc *)iadev->EXT_VC_TABLE_ADDR; 21241da177e4SLinus Torvalds iadev->testTable = kmalloc(sizeof(long)*iadev->num_vc, GFP_KERNEL); 21251da177e4SLinus Torvalds if (!iadev->testTable) { 21261da177e4SLinus Torvalds printk("Get freepage failed\n"); 21271da177e4SLinus Torvalds goto err_free_desc_tbl; 21281da177e4SLinus Torvalds } 21291da177e4SLinus Torvalds for(i=0; i<iadev->num_vc; i++) 21301da177e4SLinus Torvalds { 21311da177e4SLinus Torvalds memset((caddr_t)vc, 0, sizeof(*vc)); 21321da177e4SLinus Torvalds memset((caddr_t)evc, 0, sizeof(*evc)); 21331da177e4SLinus Torvalds iadev->testTable[i] = kmalloc(sizeof(struct testTable_t), 21341da177e4SLinus Torvalds GFP_KERNEL); 21351da177e4SLinus Torvalds if (!iadev->testTable[i]) 21361da177e4SLinus Torvalds goto err_free_test_tables; 21371da177e4SLinus Torvalds iadev->testTable[i]->lastTime = 0; 21381da177e4SLinus Torvalds iadev->testTable[i]->fract = 0; 21391da177e4SLinus Torvalds iadev->testTable[i]->vc_status = VC_UBR; 21401da177e4SLinus Torvalds vc++; 21411da177e4SLinus Torvalds evc++; 21421da177e4SLinus Torvalds } 21431da177e4SLinus Torvalds 21441da177e4SLinus Torvalds /* Other Initialization */ 21451da177e4SLinus Torvalds 21461da177e4SLinus Torvalds /* Max Rate Register */ 21471da177e4SLinus Torvalds if (iadev->phy_type & FE_25MBIT_PHY) { 21481da177e4SLinus Torvalds writew(RATE25, iadev->seg_reg+MAXRATE); 21491da177e4SLinus Torvalds writew((UBR_EN | (0x23 << 2)), iadev->seg_reg+STPARMS); 21501da177e4SLinus Torvalds } 21511da177e4SLinus Torvalds else { 21521da177e4SLinus Torvalds writew(cellrate_to_float(iadev->LineRate),iadev->seg_reg+MAXRATE); 21531da177e4SLinus Torvalds writew((UBR_EN | ABR_EN | (0x23 << 2)), iadev->seg_reg+STPARMS); 21541da177e4SLinus Torvalds } 21551da177e4SLinus Torvalds /* Set Idle Header Reigisters to be sure */ 21561da177e4SLinus Torvalds writew(0, iadev->seg_reg+IDLEHEADHI); 21571da177e4SLinus Torvalds writew(0, iadev->seg_reg+IDLEHEADLO); 21581da177e4SLinus Torvalds 21591da177e4SLinus Torvalds /* Program ABR UBR Priority Register as PRI_ABR_UBR_EQUAL */ 21601da177e4SLinus Torvalds writew(0xaa00, iadev->seg_reg+ABRUBR_ARB); 21611da177e4SLinus Torvalds 21621da177e4SLinus Torvalds iadev->close_pending = 0; 21631da177e4SLinus Torvalds init_waitqueue_head(&iadev->close_wait); 21641da177e4SLinus Torvalds init_waitqueue_head(&iadev->timeout_wait); 21651da177e4SLinus Torvalds skb_queue_head_init(&iadev->tx_dma_q); 21661da177e4SLinus Torvalds ia_init_rtn_q(&iadev->tx_return_q); 21671da177e4SLinus Torvalds 21681da177e4SLinus Torvalds /* RM Cell Protocol ID and Message Type */ 21691da177e4SLinus Torvalds writew(RM_TYPE_4_0, iadev->seg_reg+RM_TYPE); 21701da177e4SLinus Torvalds skb_queue_head_init (&iadev->tx_backlog); 21711da177e4SLinus Torvalds 21721da177e4SLinus Torvalds /* Mode Register 1 */ 21731da177e4SLinus Torvalds writew(MODE_REG_1_VAL, iadev->seg_reg+MODE_REG_1); 21741da177e4SLinus Torvalds 21751da177e4SLinus Torvalds /* Mode Register 0 */ 21761da177e4SLinus Torvalds writew(T_ONLINE, iadev->seg_reg+MODE_REG_0); 21771da177e4SLinus Torvalds 21781da177e4SLinus Torvalds /* Interrupt Status Register - read to clear */ 21791da177e4SLinus Torvalds readw(iadev->seg_reg+SEG_INTR_STATUS_REG); 21801da177e4SLinus Torvalds 21811da177e4SLinus Torvalds /* Interrupt Mask Reg- don't mask TCQ_NOT_EMPTY interrupt generation */ 21821da177e4SLinus Torvalds writew(~(TRANSMIT_DONE | TCQ_NOT_EMPTY), iadev->seg_reg+SEG_MASK_REG); 21831da177e4SLinus Torvalds writew(TRANSMIT_DONE, iadev->seg_reg+SEG_INTR_STATUS_REG); 21841da177e4SLinus Torvalds iadev->tx_pkt_cnt = 0; 21851da177e4SLinus Torvalds iadev->rate_limit = iadev->LineRate / 3; 21861da177e4SLinus Torvalds 21871da177e4SLinus Torvalds return 0; 21881da177e4SLinus Torvalds 21891da177e4SLinus Torvalds err_free_test_tables: 21901da177e4SLinus Torvalds while (--i >= 0) 21911da177e4SLinus Torvalds kfree(iadev->testTable[i]); 21921da177e4SLinus Torvalds kfree(iadev->testTable); 21931da177e4SLinus Torvalds err_free_desc_tbl: 21941da177e4SLinus Torvalds kfree(iadev->desc_tbl); 21951da177e4SLinus Torvalds err_free_all_tx_bufs: 21961da177e4SLinus Torvalds i = iadev->num_tx_desc; 21971da177e4SLinus Torvalds err_free_tx_bufs: 21981da177e4SLinus Torvalds while (--i >= 0) { 21991da177e4SLinus Torvalds struct cpcs_trailer_desc *desc = iadev->tx_buf + i; 22001da177e4SLinus Torvalds 22011da177e4SLinus Torvalds pci_unmap_single(iadev->pci, desc->dma_addr, 22021da177e4SLinus Torvalds sizeof(*desc->cpcs), PCI_DMA_TODEVICE); 22031da177e4SLinus Torvalds kfree(desc->cpcs); 22041da177e4SLinus Torvalds } 22051da177e4SLinus Torvalds kfree(iadev->tx_buf); 22061da177e4SLinus Torvalds err_free_dle: 22071da177e4SLinus Torvalds pci_free_consistent(iadev->pci, DLE_TOTAL_SIZE, iadev->tx_dle_q.start, 22081da177e4SLinus Torvalds iadev->tx_dle_dma); 22091da177e4SLinus Torvalds err_out: 22101da177e4SLinus Torvalds return -ENOMEM; 22111da177e4SLinus Torvalds } 22121da177e4SLinus Torvalds 22137d12e780SDavid Howells static irqreturn_t ia_int(int irq, void *dev_id) 22141da177e4SLinus Torvalds { 22151da177e4SLinus Torvalds struct atm_dev *dev; 22161da177e4SLinus Torvalds IADEV *iadev; 22171da177e4SLinus Torvalds unsigned int status; 22181da177e4SLinus Torvalds int handled = 0; 22191da177e4SLinus Torvalds 22201da177e4SLinus Torvalds dev = dev_id; 22211da177e4SLinus Torvalds iadev = INPH_IA_DEV(dev); 22221da177e4SLinus Torvalds while( (status = readl(iadev->reg+IPHASE5575_BUS_STATUS_REG) & 0x7f)) 22231da177e4SLinus Torvalds { 22241da177e4SLinus Torvalds handled = 1; 22251da177e4SLinus Torvalds IF_EVENT(printk("ia_int: status = 0x%x\n", status);) 22261da177e4SLinus Torvalds if (status & STAT_REASSINT) 22271da177e4SLinus Torvalds { 22281da177e4SLinus Torvalds /* do something */ 22291da177e4SLinus Torvalds IF_EVENT(printk("REASSINT Bus status reg: %08x\n", status);) 22301da177e4SLinus Torvalds rx_intr(dev); 22311da177e4SLinus Torvalds } 22321da177e4SLinus Torvalds if (status & STAT_DLERINT) 22331da177e4SLinus Torvalds { 22341da177e4SLinus Torvalds /* Clear this bit by writing a 1 to it. */ 223526c5c44dSfrançois romieu writel(STAT_DLERINT, iadev->reg + IPHASE5575_BUS_STATUS_REG); 22361da177e4SLinus Torvalds rx_dle_intr(dev); 22371da177e4SLinus Torvalds } 22381da177e4SLinus Torvalds if (status & STAT_SEGINT) 22391da177e4SLinus Torvalds { 22401da177e4SLinus Torvalds /* do something */ 22411da177e4SLinus Torvalds IF_EVENT(printk("IA: tx_intr \n");) 22421da177e4SLinus Torvalds tx_intr(dev); 22431da177e4SLinus Torvalds } 22441da177e4SLinus Torvalds if (status & STAT_DLETINT) 22451da177e4SLinus Torvalds { 224626c5c44dSfrançois romieu writel(STAT_DLETINT, iadev->reg + IPHASE5575_BUS_STATUS_REG); 22471da177e4SLinus Torvalds tx_dle_intr(dev); 22481da177e4SLinus Torvalds } 22491da177e4SLinus Torvalds if (status & (STAT_FEINT | STAT_ERRINT | STAT_MARKINT)) 22501da177e4SLinus Torvalds { 22511da177e4SLinus Torvalds if (status & STAT_FEINT) 225226c5c44dSfrançois romieu ia_frontend_intr(iadev); 22531da177e4SLinus Torvalds } 22541da177e4SLinus Torvalds } 22551da177e4SLinus Torvalds return IRQ_RETVAL(handled); 22561da177e4SLinus Torvalds } 22571da177e4SLinus Torvalds 22581da177e4SLinus Torvalds 22591da177e4SLinus Torvalds 22601da177e4SLinus Torvalds /*----------------------------- entries --------------------------------*/ 22611da177e4SLinus Torvalds static int get_esi(struct atm_dev *dev) 22621da177e4SLinus Torvalds { 22631da177e4SLinus Torvalds IADEV *iadev; 22641da177e4SLinus Torvalds int i; 22651da177e4SLinus Torvalds u32 mac1; 22661da177e4SLinus Torvalds u16 mac2; 22671da177e4SLinus Torvalds 22681da177e4SLinus Torvalds iadev = INPH_IA_DEV(dev); 22691da177e4SLinus Torvalds mac1 = cpu_to_be32(le32_to_cpu(readl( 22701da177e4SLinus Torvalds iadev->reg+IPHASE5575_MAC1))); 22711da177e4SLinus Torvalds mac2 = cpu_to_be16(le16_to_cpu(readl(iadev->reg+IPHASE5575_MAC2))); 22721da177e4SLinus Torvalds IF_INIT(printk("ESI: 0x%08x%04x\n", mac1, mac2);) 22731da177e4SLinus Torvalds for (i=0; i<MAC1_LEN; i++) 22741da177e4SLinus Torvalds dev->esi[i] = mac1 >>(8*(MAC1_LEN-1-i)); 22751da177e4SLinus Torvalds 22761da177e4SLinus Torvalds for (i=0; i<MAC2_LEN; i++) 22771da177e4SLinus Torvalds dev->esi[i+MAC1_LEN] = mac2 >>(8*(MAC2_LEN - 1 -i)); 22781da177e4SLinus Torvalds return 0; 22791da177e4SLinus Torvalds } 22801da177e4SLinus Torvalds 22811da177e4SLinus Torvalds static int reset_sar(struct atm_dev *dev) 22821da177e4SLinus Torvalds { 22831da177e4SLinus Torvalds IADEV *iadev; 22841da177e4SLinus Torvalds int i, error = 1; 22851da177e4SLinus Torvalds unsigned int pci[64]; 22861da177e4SLinus Torvalds 22871da177e4SLinus Torvalds iadev = INPH_IA_DEV(dev); 22881da177e4SLinus Torvalds for(i=0; i<64; i++) 22891da177e4SLinus Torvalds if ((error = pci_read_config_dword(iadev->pci, 22901da177e4SLinus Torvalds i*4, &pci[i])) != PCIBIOS_SUCCESSFUL) 22911da177e4SLinus Torvalds return error; 22921da177e4SLinus Torvalds writel(0, iadev->reg+IPHASE5575_EXT_RESET); 22931da177e4SLinus Torvalds for(i=0; i<64; i++) 22941da177e4SLinus Torvalds if ((error = pci_write_config_dword(iadev->pci, 22951da177e4SLinus Torvalds i*4, pci[i])) != PCIBIOS_SUCCESSFUL) 22961da177e4SLinus Torvalds return error; 22971da177e4SLinus Torvalds udelay(5); 22981da177e4SLinus Torvalds return 0; 22991da177e4SLinus Torvalds } 23001da177e4SLinus Torvalds 23011da177e4SLinus Torvalds 2302249c14b5SChas Williams static int __devinit ia_init(struct atm_dev *dev) 23031da177e4SLinus Torvalds { 23041da177e4SLinus Torvalds IADEV *iadev; 23051da177e4SLinus Torvalds unsigned long real_base; 23061da177e4SLinus Torvalds void __iomem *base; 23071da177e4SLinus Torvalds unsigned short command; 23081da177e4SLinus Torvalds int error, i; 23091da177e4SLinus Torvalds 23101da177e4SLinus Torvalds /* The device has been identified and registered. Now we read 23111da177e4SLinus Torvalds necessary configuration info like memory base address, 23121da177e4SLinus Torvalds interrupt number etc */ 23131da177e4SLinus Torvalds 23141da177e4SLinus Torvalds IF_INIT(printk(">ia_init\n");) 23151da177e4SLinus Torvalds dev->ci_range.vpi_bits = 0; 23161da177e4SLinus Torvalds dev->ci_range.vci_bits = NR_VCI_LD; 23171da177e4SLinus Torvalds 23181da177e4SLinus Torvalds iadev = INPH_IA_DEV(dev); 23191da177e4SLinus Torvalds real_base = pci_resource_start (iadev->pci, 0); 23201da177e4SLinus Torvalds iadev->irq = iadev->pci->irq; 23211da177e4SLinus Torvalds 232244c10138SAuke Kok error = pci_read_config_word(iadev->pci, PCI_COMMAND, &command); 232344c10138SAuke Kok if (error) { 23241da177e4SLinus Torvalds printk(KERN_ERR DEV_LABEL "(itf %d): init error 0x%x\n", 23251da177e4SLinus Torvalds dev->number,error); 23261da177e4SLinus Torvalds return -EINVAL; 23271da177e4SLinus Torvalds } 23281da177e4SLinus Torvalds IF_INIT(printk(DEV_LABEL "(itf %d): rev.%d,realbase=0x%lx,irq=%d\n", 232944c10138SAuke Kok dev->number, iadev->pci->revision, real_base, iadev->irq);) 23301da177e4SLinus Torvalds 23311da177e4SLinus Torvalds /* find mapping size of board */ 23321da177e4SLinus Torvalds 23331da177e4SLinus Torvalds iadev->pci_map_size = pci_resource_len(iadev->pci, 0); 23341da177e4SLinus Torvalds 23351da177e4SLinus Torvalds if (iadev->pci_map_size == 0x100000){ 23361da177e4SLinus Torvalds iadev->num_vc = 4096; 23371da177e4SLinus Torvalds dev->ci_range.vci_bits = NR_VCI_4K_LD; 23381da177e4SLinus Torvalds iadev->memSize = 4; 23391da177e4SLinus Torvalds } 23401da177e4SLinus Torvalds else if (iadev->pci_map_size == 0x40000) { 23411da177e4SLinus Torvalds iadev->num_vc = 1024; 23421da177e4SLinus Torvalds iadev->memSize = 1; 23431da177e4SLinus Torvalds } 23441da177e4SLinus Torvalds else { 23451da177e4SLinus Torvalds printk("Unknown pci_map_size = 0x%x\n", iadev->pci_map_size); 23461da177e4SLinus Torvalds return -EINVAL; 23471da177e4SLinus Torvalds } 23481da177e4SLinus Torvalds IF_INIT(printk (DEV_LABEL "map size: %i\n", iadev->pci_map_size);) 23491da177e4SLinus Torvalds 23501da177e4SLinus Torvalds /* enable bus mastering */ 23511da177e4SLinus Torvalds pci_set_master(iadev->pci); 23521da177e4SLinus Torvalds 23531da177e4SLinus Torvalds /* 23541da177e4SLinus Torvalds * Delay at least 1us before doing any mem accesses (how 'bout 10?) 23551da177e4SLinus Torvalds */ 23561da177e4SLinus Torvalds udelay(10); 23571da177e4SLinus Torvalds 23581da177e4SLinus Torvalds /* mapping the physical address to a virtual address in address space */ 23591da177e4SLinus Torvalds base = ioremap(real_base,iadev->pci_map_size); /* ioremap is not resolved ??? */ 23601da177e4SLinus Torvalds 23611da177e4SLinus Torvalds if (!base) 23621da177e4SLinus Torvalds { 23631da177e4SLinus Torvalds printk(DEV_LABEL " (itf %d): can't set up page mapping\n", 23641da177e4SLinus Torvalds dev->number); 2365*f716168bSJulia Lawall return -ENOMEM; 23661da177e4SLinus Torvalds } 23671da177e4SLinus Torvalds IF_INIT(printk(DEV_LABEL " (itf %d): rev.%d,base=%p,irq=%d\n", 236844c10138SAuke Kok dev->number, iadev->pci->revision, base, iadev->irq);) 23691da177e4SLinus Torvalds 23701da177e4SLinus Torvalds /* filling the iphase dev structure */ 23711da177e4SLinus Torvalds iadev->mem = iadev->pci_map_size /2; 23721da177e4SLinus Torvalds iadev->real_base = real_base; 23731da177e4SLinus Torvalds iadev->base = base; 23741da177e4SLinus Torvalds 23751da177e4SLinus Torvalds /* Bus Interface Control Registers */ 23761da177e4SLinus Torvalds iadev->reg = base + REG_BASE; 23771da177e4SLinus Torvalds /* Segmentation Control Registers */ 23781da177e4SLinus Torvalds iadev->seg_reg = base + SEG_BASE; 23791da177e4SLinus Torvalds /* Reassembly Control Registers */ 23801da177e4SLinus Torvalds iadev->reass_reg = base + REASS_BASE; 23811da177e4SLinus Torvalds /* Front end/ DMA control registers */ 23821da177e4SLinus Torvalds iadev->phy = base + PHY_BASE; 23831da177e4SLinus Torvalds iadev->dma = base + PHY_BASE; 23841da177e4SLinus Torvalds /* RAM - Segmentation RAm and Reassembly RAM */ 23851da177e4SLinus Torvalds iadev->ram = base + ACTUAL_RAM_BASE; 23861da177e4SLinus Torvalds iadev->seg_ram = base + ACTUAL_SEG_RAM_BASE; 23871da177e4SLinus Torvalds iadev->reass_ram = base + ACTUAL_REASS_RAM_BASE; 23881da177e4SLinus Torvalds 23891da177e4SLinus Torvalds /* lets print out the above */ 23901da177e4SLinus Torvalds IF_INIT(printk("Base addrs: %p %p %p \n %p %p %p %p\n", 23911da177e4SLinus Torvalds iadev->reg,iadev->seg_reg,iadev->reass_reg, 23921da177e4SLinus Torvalds iadev->phy, iadev->ram, iadev->seg_ram, 23931da177e4SLinus Torvalds iadev->reass_ram);) 23941da177e4SLinus Torvalds 23951da177e4SLinus Torvalds /* lets try reading the MAC address */ 23961da177e4SLinus Torvalds error = get_esi(dev); 23971da177e4SLinus Torvalds if (error) { 23981da177e4SLinus Torvalds iounmap(iadev->base); 23991da177e4SLinus Torvalds return error; 24001da177e4SLinus Torvalds } 24011da177e4SLinus Torvalds printk("IA: "); 24021da177e4SLinus Torvalds for (i=0; i < ESI_LEN; i++) 24031da177e4SLinus Torvalds printk("%s%02X",i ? "-" : "",dev->esi[i]); 24041da177e4SLinus Torvalds printk("\n"); 24051da177e4SLinus Torvalds 24061da177e4SLinus Torvalds /* reset SAR */ 24071da177e4SLinus Torvalds if (reset_sar(dev)) { 24081da177e4SLinus Torvalds iounmap(iadev->base); 24091da177e4SLinus Torvalds printk("IA: reset SAR fail, please try again\n"); 24101da177e4SLinus Torvalds return 1; 24111da177e4SLinus Torvalds } 24121da177e4SLinus Torvalds return 0; 24131da177e4SLinus Torvalds } 24141da177e4SLinus Torvalds 24151da177e4SLinus Torvalds static void ia_update_stats(IADEV *iadev) { 24161da177e4SLinus Torvalds if (!iadev->carrier_detect) 24171da177e4SLinus Torvalds return; 24181da177e4SLinus Torvalds iadev->rx_cell_cnt += readw(iadev->reass_reg+CELL_CTR0)&0xffff; 24191da177e4SLinus Torvalds iadev->rx_cell_cnt += (readw(iadev->reass_reg+CELL_CTR1) & 0xffff) << 16; 24201da177e4SLinus Torvalds iadev->drop_rxpkt += readw(iadev->reass_reg + DRP_PKT_CNTR ) & 0xffff; 24211da177e4SLinus Torvalds iadev->drop_rxcell += readw(iadev->reass_reg + ERR_CNTR) & 0xffff; 24221da177e4SLinus Torvalds iadev->tx_cell_cnt += readw(iadev->seg_reg + CELL_CTR_LO_AUTO)&0xffff; 24231da177e4SLinus Torvalds iadev->tx_cell_cnt += (readw(iadev->seg_reg+CELL_CTR_HIGH_AUTO)&0xffff)<<16; 24241da177e4SLinus Torvalds return; 24251da177e4SLinus Torvalds } 24261da177e4SLinus Torvalds 24271da177e4SLinus Torvalds static void ia_led_timer(unsigned long arg) { 24281da177e4SLinus Torvalds unsigned long flags; 24291da177e4SLinus Torvalds static u_char blinking[8] = {0, 0, 0, 0, 0, 0, 0, 0}; 24301da177e4SLinus Torvalds u_char i; 24311da177e4SLinus Torvalds static u32 ctrl_reg; 24321da177e4SLinus Torvalds for (i = 0; i < iadev_count; i++) { 24331da177e4SLinus Torvalds if (ia_dev[i]) { 24341da177e4SLinus Torvalds ctrl_reg = readl(ia_dev[i]->reg+IPHASE5575_BUS_CONTROL_REG); 24351da177e4SLinus Torvalds if (blinking[i] == 0) { 24361da177e4SLinus Torvalds blinking[i]++; 24371da177e4SLinus Torvalds ctrl_reg &= (~CTRL_LED); 24381da177e4SLinus Torvalds writel(ctrl_reg, ia_dev[i]->reg+IPHASE5575_BUS_CONTROL_REG); 24391da177e4SLinus Torvalds ia_update_stats(ia_dev[i]); 24401da177e4SLinus Torvalds } 24411da177e4SLinus Torvalds else { 24421da177e4SLinus Torvalds blinking[i] = 0; 24431da177e4SLinus Torvalds ctrl_reg |= CTRL_LED; 24441da177e4SLinus Torvalds writel(ctrl_reg, ia_dev[i]->reg+IPHASE5575_BUS_CONTROL_REG); 24451da177e4SLinus Torvalds spin_lock_irqsave(&ia_dev[i]->tx_lock, flags); 24461da177e4SLinus Torvalds if (ia_dev[i]->close_pending) 24471da177e4SLinus Torvalds wake_up(&ia_dev[i]->close_wait); 24481da177e4SLinus Torvalds ia_tx_poll(ia_dev[i]); 24491da177e4SLinus Torvalds spin_unlock_irqrestore(&ia_dev[i]->tx_lock, flags); 24501da177e4SLinus Torvalds } 24511da177e4SLinus Torvalds } 24521da177e4SLinus Torvalds } 24531da177e4SLinus Torvalds mod_timer(&ia_timer, jiffies + HZ / 4); 24541da177e4SLinus Torvalds return; 24551da177e4SLinus Torvalds } 24561da177e4SLinus Torvalds 24571da177e4SLinus Torvalds static void ia_phy_put(struct atm_dev *dev, unsigned char value, 24581da177e4SLinus Torvalds unsigned long addr) 24591da177e4SLinus Torvalds { 24601da177e4SLinus Torvalds writel(value, INPH_IA_DEV(dev)->phy+addr); 24611da177e4SLinus Torvalds } 24621da177e4SLinus Torvalds 24631da177e4SLinus Torvalds static unsigned char ia_phy_get(struct atm_dev *dev, unsigned long addr) 24641da177e4SLinus Torvalds { 24651da177e4SLinus Torvalds return readl(INPH_IA_DEV(dev)->phy+addr); 24661da177e4SLinus Torvalds } 24671da177e4SLinus Torvalds 24681da177e4SLinus Torvalds static void ia_free_tx(IADEV *iadev) 24691da177e4SLinus Torvalds { 24701da177e4SLinus Torvalds int i; 24711da177e4SLinus Torvalds 24721da177e4SLinus Torvalds kfree(iadev->desc_tbl); 24731da177e4SLinus Torvalds for (i = 0; i < iadev->num_vc; i++) 24741da177e4SLinus Torvalds kfree(iadev->testTable[i]); 24751da177e4SLinus Torvalds kfree(iadev->testTable); 24761da177e4SLinus Torvalds for (i = 0; i < iadev->num_tx_desc; i++) { 24771da177e4SLinus Torvalds struct cpcs_trailer_desc *desc = iadev->tx_buf + i; 24781da177e4SLinus Torvalds 24791da177e4SLinus Torvalds pci_unmap_single(iadev->pci, desc->dma_addr, 24801da177e4SLinus Torvalds sizeof(*desc->cpcs), PCI_DMA_TODEVICE); 24811da177e4SLinus Torvalds kfree(desc->cpcs); 24821da177e4SLinus Torvalds } 24831da177e4SLinus Torvalds kfree(iadev->tx_buf); 24841da177e4SLinus Torvalds pci_free_consistent(iadev->pci, DLE_TOTAL_SIZE, iadev->tx_dle_q.start, 24851da177e4SLinus Torvalds iadev->tx_dle_dma); 24861da177e4SLinus Torvalds } 24871da177e4SLinus Torvalds 24881da177e4SLinus Torvalds static void ia_free_rx(IADEV *iadev) 24891da177e4SLinus Torvalds { 24901da177e4SLinus Torvalds kfree(iadev->rx_open); 24911da177e4SLinus Torvalds pci_free_consistent(iadev->pci, DLE_TOTAL_SIZE, iadev->rx_dle_q.start, 24921da177e4SLinus Torvalds iadev->rx_dle_dma); 24931da177e4SLinus Torvalds } 24941da177e4SLinus Torvalds 2495249c14b5SChas Williams static int __devinit ia_start(struct atm_dev *dev) 24961da177e4SLinus Torvalds { 24971da177e4SLinus Torvalds IADEV *iadev; 24981da177e4SLinus Torvalds int error; 24991da177e4SLinus Torvalds unsigned char phy; 25001da177e4SLinus Torvalds u32 ctrl_reg; 25011da177e4SLinus Torvalds IF_EVENT(printk(">ia_start\n");) 25021da177e4SLinus Torvalds iadev = INPH_IA_DEV(dev); 2503dace1453SThomas Gleixner if (request_irq(iadev->irq, &ia_int, IRQF_SHARED, DEV_LABEL, dev)) { 25041da177e4SLinus Torvalds printk(KERN_ERR DEV_LABEL "(itf %d): IRQ%d is already in use\n", 25051da177e4SLinus Torvalds dev->number, iadev->irq); 25061da177e4SLinus Torvalds error = -EAGAIN; 25071da177e4SLinus Torvalds goto err_out; 25081da177e4SLinus Torvalds } 25091da177e4SLinus Torvalds /* @@@ should release IRQ on error */ 25101da177e4SLinus Torvalds /* enabling memory + master */ 25111da177e4SLinus Torvalds if ((error = pci_write_config_word(iadev->pci, 25121da177e4SLinus Torvalds PCI_COMMAND, 25131da177e4SLinus Torvalds PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER ))) 25141da177e4SLinus Torvalds { 25151da177e4SLinus Torvalds printk(KERN_ERR DEV_LABEL "(itf %d): can't enable memory+" 25161da177e4SLinus Torvalds "master (0x%x)\n",dev->number, error); 25171da177e4SLinus Torvalds error = -EIO; 25181da177e4SLinus Torvalds goto err_free_irq; 25191da177e4SLinus Torvalds } 25201da177e4SLinus Torvalds udelay(10); 25211da177e4SLinus Torvalds 25221da177e4SLinus Torvalds /* Maybe we should reset the front end, initialize Bus Interface Control 25231da177e4SLinus Torvalds Registers and see. */ 25241da177e4SLinus Torvalds 25251da177e4SLinus Torvalds IF_INIT(printk("Bus ctrl reg: %08x\n", 25261da177e4SLinus Torvalds readl(iadev->reg+IPHASE5575_BUS_CONTROL_REG));) 25271da177e4SLinus Torvalds ctrl_reg = readl(iadev->reg+IPHASE5575_BUS_CONTROL_REG); 25281da177e4SLinus Torvalds ctrl_reg = (ctrl_reg & (CTRL_LED | CTRL_FE_RST)) 25291da177e4SLinus Torvalds | CTRL_B8 25301da177e4SLinus Torvalds | CTRL_B16 25311da177e4SLinus Torvalds | CTRL_B32 25321da177e4SLinus Torvalds | CTRL_B48 25331da177e4SLinus Torvalds | CTRL_B64 25341da177e4SLinus Torvalds | CTRL_B128 25351da177e4SLinus Torvalds | CTRL_ERRMASK 25361da177e4SLinus Torvalds | CTRL_DLETMASK /* shud be removed l8r */ 25371da177e4SLinus Torvalds | CTRL_DLERMASK 25381da177e4SLinus Torvalds | CTRL_SEGMASK 25391da177e4SLinus Torvalds | CTRL_REASSMASK 25401da177e4SLinus Torvalds | CTRL_FEMASK 25411da177e4SLinus Torvalds | CTRL_CSPREEMPT; 25421da177e4SLinus Torvalds 25431da177e4SLinus Torvalds writel(ctrl_reg, iadev->reg+IPHASE5575_BUS_CONTROL_REG); 25441da177e4SLinus Torvalds 25451da177e4SLinus Torvalds IF_INIT(printk("Bus ctrl reg after initializing: %08x\n", 25461da177e4SLinus Torvalds readl(iadev->reg+IPHASE5575_BUS_CONTROL_REG)); 25471da177e4SLinus Torvalds printk("Bus status reg after init: %08x\n", 25481da177e4SLinus Torvalds readl(iadev->reg+IPHASE5575_BUS_STATUS_REG));) 25491da177e4SLinus Torvalds 25501da177e4SLinus Torvalds ia_hw_type(iadev); 25511da177e4SLinus Torvalds error = tx_init(dev); 25521da177e4SLinus Torvalds if (error) 25531da177e4SLinus Torvalds goto err_free_irq; 25541da177e4SLinus Torvalds error = rx_init(dev); 25551da177e4SLinus Torvalds if (error) 25561da177e4SLinus Torvalds goto err_free_tx; 25571da177e4SLinus Torvalds 25581da177e4SLinus Torvalds ctrl_reg = readl(iadev->reg+IPHASE5575_BUS_CONTROL_REG); 25591da177e4SLinus Torvalds writel(ctrl_reg | CTRL_FE_RST, iadev->reg+IPHASE5575_BUS_CONTROL_REG); 25601da177e4SLinus Torvalds IF_INIT(printk("Bus ctrl reg after initializing: %08x\n", 25611da177e4SLinus Torvalds readl(iadev->reg+IPHASE5575_BUS_CONTROL_REG));) 25621da177e4SLinus Torvalds phy = 0; /* resolve compiler complaint */ 25631da177e4SLinus Torvalds IF_INIT ( 25641da177e4SLinus Torvalds if ((phy=ia_phy_get(dev,0)) == 0x30) 25651da177e4SLinus Torvalds printk("IA: pm5346,rev.%d\n",phy&0x0f); 25661da177e4SLinus Torvalds else 25671da177e4SLinus Torvalds printk("IA: utopia,rev.%0x\n",phy);) 25681da177e4SLinus Torvalds 25691da177e4SLinus Torvalds if (iadev->phy_type & FE_25MBIT_PHY) 25701da177e4SLinus Torvalds ia_mb25_init(iadev); 25711da177e4SLinus Torvalds else if (iadev->phy_type & (FE_DS3_PHY | FE_E3_PHY)) 25721da177e4SLinus Torvalds ia_suni_pm7345_init(iadev); 25731da177e4SLinus Torvalds else { 25741da177e4SLinus Torvalds error = suni_init(dev); 25751da177e4SLinus Torvalds if (error) 25761da177e4SLinus Torvalds goto err_free_rx; 2577d6c1d704SJorge Boncompte [DTI2] if (dev->phy->start) { 25781da177e4SLinus Torvalds error = dev->phy->start(dev); 25791da177e4SLinus Torvalds if (error) 25801da177e4SLinus Torvalds goto err_free_rx; 2581d6c1d704SJorge Boncompte [DTI2] } 25821da177e4SLinus Torvalds /* Get iadev->carrier_detect status */ 258326c5c44dSfrançois romieu ia_frontend_intr(iadev); 25841da177e4SLinus Torvalds } 25851da177e4SLinus Torvalds return 0; 25861da177e4SLinus Torvalds 25871da177e4SLinus Torvalds err_free_rx: 25881da177e4SLinus Torvalds ia_free_rx(iadev); 25891da177e4SLinus Torvalds err_free_tx: 25901da177e4SLinus Torvalds ia_free_tx(iadev); 25911da177e4SLinus Torvalds err_free_irq: 25921da177e4SLinus Torvalds free_irq(iadev->irq, dev); 25931da177e4SLinus Torvalds err_out: 25941da177e4SLinus Torvalds return error; 25951da177e4SLinus Torvalds } 25961da177e4SLinus Torvalds 25971da177e4SLinus Torvalds static void ia_close(struct atm_vcc *vcc) 25981da177e4SLinus Torvalds { 25991da177e4SLinus Torvalds DEFINE_WAIT(wait); 26001da177e4SLinus Torvalds u16 *vc_table; 26011da177e4SLinus Torvalds IADEV *iadev; 26021da177e4SLinus Torvalds struct ia_vcc *ia_vcc; 26031da177e4SLinus Torvalds struct sk_buff *skb = NULL; 26041da177e4SLinus Torvalds struct sk_buff_head tmp_tx_backlog, tmp_vcc_backlog; 26051da177e4SLinus Torvalds unsigned long closetime, flags; 26061da177e4SLinus Torvalds 26071da177e4SLinus Torvalds iadev = INPH_IA_DEV(vcc->dev); 26081da177e4SLinus Torvalds ia_vcc = INPH_IA_VCC(vcc); 26091da177e4SLinus Torvalds if (!ia_vcc) return; 26101da177e4SLinus Torvalds 26111da177e4SLinus Torvalds IF_EVENT(printk("ia_close: ia_vcc->vc_desc_cnt = %d vci = %d\n", 26121da177e4SLinus Torvalds ia_vcc->vc_desc_cnt,vcc->vci);) 26131da177e4SLinus Torvalds clear_bit(ATM_VF_READY,&vcc->flags); 26141da177e4SLinus Torvalds skb_queue_head_init (&tmp_tx_backlog); 26151da177e4SLinus Torvalds skb_queue_head_init (&tmp_vcc_backlog); 26161da177e4SLinus Torvalds if (vcc->qos.txtp.traffic_class != ATM_NONE) { 26171da177e4SLinus Torvalds iadev->close_pending++; 26181da177e4SLinus Torvalds prepare_to_wait(&iadev->timeout_wait, &wait, TASK_UNINTERRUPTIBLE); 26191da177e4SLinus Torvalds schedule_timeout(50); 26201da177e4SLinus Torvalds finish_wait(&iadev->timeout_wait, &wait); 26211da177e4SLinus Torvalds spin_lock_irqsave(&iadev->tx_lock, flags); 26221da177e4SLinus Torvalds while((skb = skb_dequeue(&iadev->tx_backlog))) { 26231da177e4SLinus Torvalds if (ATM_SKB(skb)->vcc == vcc){ 26241da177e4SLinus Torvalds if (vcc->pop) vcc->pop(vcc, skb); 26251da177e4SLinus Torvalds else dev_kfree_skb_any(skb); 26261da177e4SLinus Torvalds } 26271da177e4SLinus Torvalds else 26281da177e4SLinus Torvalds skb_queue_tail(&tmp_tx_backlog, skb); 26291da177e4SLinus Torvalds } 26301da177e4SLinus Torvalds while((skb = skb_dequeue(&tmp_tx_backlog))) 26311da177e4SLinus Torvalds skb_queue_tail(&iadev->tx_backlog, skb); 26321da177e4SLinus Torvalds IF_EVENT(printk("IA TX Done decs_cnt = %d\n", ia_vcc->vc_desc_cnt);) 26331da177e4SLinus Torvalds closetime = 300000 / ia_vcc->pcr; 26341da177e4SLinus Torvalds if (closetime == 0) 26351da177e4SLinus Torvalds closetime = 1; 26361da177e4SLinus Torvalds spin_unlock_irqrestore(&iadev->tx_lock, flags); 26371da177e4SLinus Torvalds wait_event_timeout(iadev->close_wait, (ia_vcc->vc_desc_cnt <= 0), closetime); 26381da177e4SLinus Torvalds spin_lock_irqsave(&iadev->tx_lock, flags); 26391da177e4SLinus Torvalds iadev->close_pending--; 26401da177e4SLinus Torvalds iadev->testTable[vcc->vci]->lastTime = 0; 26411da177e4SLinus Torvalds iadev->testTable[vcc->vci]->fract = 0; 26421da177e4SLinus Torvalds iadev->testTable[vcc->vci]->vc_status = VC_UBR; 26431da177e4SLinus Torvalds if (vcc->qos.txtp.traffic_class == ATM_ABR) { 26441da177e4SLinus Torvalds if (vcc->qos.txtp.min_pcr > 0) 26451da177e4SLinus Torvalds iadev->sum_mcr -= vcc->qos.txtp.min_pcr; 26461da177e4SLinus Torvalds } 26471da177e4SLinus Torvalds if (vcc->qos.txtp.traffic_class == ATM_CBR) { 26481da177e4SLinus Torvalds ia_vcc = INPH_IA_VCC(vcc); 26491da177e4SLinus Torvalds iadev->sum_mcr -= ia_vcc->NumCbrEntry*iadev->Granularity; 26501da177e4SLinus Torvalds ia_cbrVc_close (vcc); 26511da177e4SLinus Torvalds } 26521da177e4SLinus Torvalds spin_unlock_irqrestore(&iadev->tx_lock, flags); 26531da177e4SLinus Torvalds } 26541da177e4SLinus Torvalds 26551da177e4SLinus Torvalds if (vcc->qos.rxtp.traffic_class != ATM_NONE) { 26561da177e4SLinus Torvalds // reset reass table 26571da177e4SLinus Torvalds vc_table = (u16 *)(iadev->reass_ram+REASS_TABLE*iadev->memSize); 26581da177e4SLinus Torvalds vc_table += vcc->vci; 26591da177e4SLinus Torvalds *vc_table = NO_AAL5_PKT; 26601da177e4SLinus Torvalds // reset vc table 26611da177e4SLinus Torvalds vc_table = (u16 *)(iadev->reass_ram+RX_VC_TABLE*iadev->memSize); 26621da177e4SLinus Torvalds vc_table += vcc->vci; 26631da177e4SLinus Torvalds *vc_table = (vcc->vci << 6) | 15; 26641da177e4SLinus Torvalds if (vcc->qos.rxtp.traffic_class == ATM_ABR) { 26651da177e4SLinus Torvalds struct abr_vc_table __iomem *abr_vc_table = 26661da177e4SLinus Torvalds (iadev->reass_ram+ABR_VC_TABLE*iadev->memSize); 26671da177e4SLinus Torvalds abr_vc_table += vcc->vci; 26681da177e4SLinus Torvalds abr_vc_table->rdf = 0x0003; 26691da177e4SLinus Torvalds abr_vc_table->air = 0x5eb1; 26701da177e4SLinus Torvalds } 26711da177e4SLinus Torvalds // Drain the packets 26721da177e4SLinus Torvalds rx_dle_intr(vcc->dev); 26731da177e4SLinus Torvalds iadev->rx_open[vcc->vci] = NULL; 26741da177e4SLinus Torvalds } 26751da177e4SLinus Torvalds kfree(INPH_IA_VCC(vcc)); 26761da177e4SLinus Torvalds ia_vcc = NULL; 26771da177e4SLinus Torvalds vcc->dev_data = NULL; 26781da177e4SLinus Torvalds clear_bit(ATM_VF_ADDR,&vcc->flags); 26791da177e4SLinus Torvalds return; 26801da177e4SLinus Torvalds } 26811da177e4SLinus Torvalds 26821da177e4SLinus Torvalds static int ia_open(struct atm_vcc *vcc) 26831da177e4SLinus Torvalds { 26841da177e4SLinus Torvalds struct ia_vcc *ia_vcc; 26851da177e4SLinus Torvalds int error; 26861da177e4SLinus Torvalds if (!test_bit(ATM_VF_PARTIAL,&vcc->flags)) 26871da177e4SLinus Torvalds { 26881da177e4SLinus Torvalds IF_EVENT(printk("ia: not partially allocated resources\n");) 26891da177e4SLinus Torvalds vcc->dev_data = NULL; 26901da177e4SLinus Torvalds } 26911da177e4SLinus Torvalds if (vcc->vci != ATM_VPI_UNSPEC && vcc->vpi != ATM_VCI_UNSPEC) 26921da177e4SLinus Torvalds { 26931da177e4SLinus Torvalds IF_EVENT(printk("iphase open: unspec part\n");) 26941da177e4SLinus Torvalds set_bit(ATM_VF_ADDR,&vcc->flags); 26951da177e4SLinus Torvalds } 26961da177e4SLinus Torvalds if (vcc->qos.aal != ATM_AAL5) 26971da177e4SLinus Torvalds return -EINVAL; 26981da177e4SLinus Torvalds IF_EVENT(printk(DEV_LABEL "(itf %d): open %d.%d\n", 26991da177e4SLinus Torvalds vcc->dev->number, vcc->vpi, vcc->vci);) 27001da177e4SLinus Torvalds 27011da177e4SLinus Torvalds /* Device dependent initialization */ 27021da177e4SLinus Torvalds ia_vcc = kmalloc(sizeof(*ia_vcc), GFP_KERNEL); 27031da177e4SLinus Torvalds if (!ia_vcc) return -ENOMEM; 27041da177e4SLinus Torvalds vcc->dev_data = ia_vcc; 27051da177e4SLinus Torvalds 27061da177e4SLinus Torvalds if ((error = open_rx(vcc))) 27071da177e4SLinus Torvalds { 27081da177e4SLinus Torvalds IF_EVENT(printk("iadev: error in open_rx, closing\n");) 27091da177e4SLinus Torvalds ia_close(vcc); 27101da177e4SLinus Torvalds return error; 27111da177e4SLinus Torvalds } 27121da177e4SLinus Torvalds 27131da177e4SLinus Torvalds if ((error = open_tx(vcc))) 27141da177e4SLinus Torvalds { 27151da177e4SLinus Torvalds IF_EVENT(printk("iadev: error in open_tx, closing\n");) 27161da177e4SLinus Torvalds ia_close(vcc); 27171da177e4SLinus Torvalds return error; 27181da177e4SLinus Torvalds } 27191da177e4SLinus Torvalds 27201da177e4SLinus Torvalds set_bit(ATM_VF_READY,&vcc->flags); 27211da177e4SLinus Torvalds 27221da177e4SLinus Torvalds #if 0 27231da177e4SLinus Torvalds { 27241da177e4SLinus Torvalds static u8 first = 1; 27251da177e4SLinus Torvalds if (first) { 27261da177e4SLinus Torvalds ia_timer.expires = jiffies + 3*HZ; 27271da177e4SLinus Torvalds add_timer(&ia_timer); 27281da177e4SLinus Torvalds first = 0; 27291da177e4SLinus Torvalds } 27301da177e4SLinus Torvalds } 27311da177e4SLinus Torvalds #endif 27321da177e4SLinus Torvalds IF_EVENT(printk("ia open returning\n");) 27331da177e4SLinus Torvalds return 0; 27341da177e4SLinus Torvalds } 27351da177e4SLinus Torvalds 27361da177e4SLinus Torvalds static int ia_change_qos(struct atm_vcc *vcc, struct atm_qos *qos, int flags) 27371da177e4SLinus Torvalds { 27381da177e4SLinus Torvalds IF_EVENT(printk(">ia_change_qos\n");) 27391da177e4SLinus Torvalds return 0; 27401da177e4SLinus Torvalds } 27411da177e4SLinus Torvalds 27421da177e4SLinus Torvalds static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg) 27431da177e4SLinus Torvalds { 27441da177e4SLinus Torvalds IA_CMDBUF ia_cmds; 27451da177e4SLinus Torvalds IADEV *iadev; 27461da177e4SLinus Torvalds int i, board; 27471da177e4SLinus Torvalds u16 __user *tmps; 27481da177e4SLinus Torvalds IF_EVENT(printk(">ia_ioctl\n");) 27491da177e4SLinus Torvalds if (cmd != IA_CMD) { 27501da177e4SLinus Torvalds if (!dev->phy->ioctl) return -EINVAL; 27511da177e4SLinus Torvalds return dev->phy->ioctl(dev,cmd,arg); 27521da177e4SLinus Torvalds } 27531da177e4SLinus Torvalds if (copy_from_user(&ia_cmds, arg, sizeof ia_cmds)) return -EFAULT; 27541da177e4SLinus Torvalds board = ia_cmds.status; 27551da177e4SLinus Torvalds if ((board < 0) || (board > iadev_count)) 27561da177e4SLinus Torvalds board = 0; 27571da177e4SLinus Torvalds iadev = ia_dev[board]; 27581da177e4SLinus Torvalds switch (ia_cmds.cmd) { 27591da177e4SLinus Torvalds case MEMDUMP: 27601da177e4SLinus Torvalds { 27611da177e4SLinus Torvalds switch (ia_cmds.sub_cmd) { 27621da177e4SLinus Torvalds case MEMDUMP_DEV: 27631da177e4SLinus Torvalds if (!capable(CAP_NET_ADMIN)) return -EPERM; 27641da177e4SLinus Torvalds if (copy_to_user(ia_cmds.buf, iadev, sizeof(IADEV))) 27651da177e4SLinus Torvalds return -EFAULT; 27661da177e4SLinus Torvalds ia_cmds.status = 0; 27671da177e4SLinus Torvalds break; 27681da177e4SLinus Torvalds case MEMDUMP_SEGREG: 27691da177e4SLinus Torvalds if (!capable(CAP_NET_ADMIN)) return -EPERM; 27701da177e4SLinus Torvalds tmps = (u16 __user *)ia_cmds.buf; 27711da177e4SLinus Torvalds for(i=0; i<0x80; i+=2, tmps++) 27721da177e4SLinus Torvalds if(put_user((u16)(readl(iadev->seg_reg+i) & 0xffff), tmps)) return -EFAULT; 27731da177e4SLinus Torvalds ia_cmds.status = 0; 27741da177e4SLinus Torvalds ia_cmds.len = 0x80; 27751da177e4SLinus Torvalds break; 27761da177e4SLinus Torvalds case MEMDUMP_REASSREG: 27771da177e4SLinus Torvalds if (!capable(CAP_NET_ADMIN)) return -EPERM; 27781da177e4SLinus Torvalds tmps = (u16 __user *)ia_cmds.buf; 27791da177e4SLinus Torvalds for(i=0; i<0x80; i+=2, tmps++) 27801da177e4SLinus Torvalds if(put_user((u16)(readl(iadev->reass_reg+i) & 0xffff), tmps)) return -EFAULT; 27811da177e4SLinus Torvalds ia_cmds.status = 0; 27821da177e4SLinus Torvalds ia_cmds.len = 0x80; 27831da177e4SLinus Torvalds break; 27841da177e4SLinus Torvalds case MEMDUMP_FFL: 27851da177e4SLinus Torvalds { 27861da177e4SLinus Torvalds ia_regs_t *regs_local; 27871da177e4SLinus Torvalds ffredn_t *ffL; 27881da177e4SLinus Torvalds rfredn_t *rfL; 27891da177e4SLinus Torvalds 27901da177e4SLinus Torvalds if (!capable(CAP_NET_ADMIN)) return -EPERM; 27911da177e4SLinus Torvalds regs_local = kmalloc(sizeof(*regs_local), GFP_KERNEL); 27921da177e4SLinus Torvalds if (!regs_local) return -ENOMEM; 27931da177e4SLinus Torvalds ffL = ®s_local->ffredn; 27941da177e4SLinus Torvalds rfL = ®s_local->rfredn; 27951da177e4SLinus Torvalds /* Copy real rfred registers into the local copy */ 27961da177e4SLinus Torvalds for (i=0; i<(sizeof (rfredn_t))/4; i++) 27971da177e4SLinus Torvalds ((u_int *)rfL)[i] = readl(iadev->reass_reg + i) & 0xffff; 27981da177e4SLinus Torvalds /* Copy real ffred registers into the local copy */ 27991da177e4SLinus Torvalds for (i=0; i<(sizeof (ffredn_t))/4; i++) 28001da177e4SLinus Torvalds ((u_int *)ffL)[i] = readl(iadev->seg_reg + i) & 0xffff; 28011da177e4SLinus Torvalds 28021da177e4SLinus Torvalds if (copy_to_user(ia_cmds.buf, regs_local,sizeof(ia_regs_t))) { 28031da177e4SLinus Torvalds kfree(regs_local); 28041da177e4SLinus Torvalds return -EFAULT; 28051da177e4SLinus Torvalds } 28061da177e4SLinus Torvalds kfree(regs_local); 28071da177e4SLinus Torvalds printk("Board %d registers dumped\n", board); 28081da177e4SLinus Torvalds ia_cmds.status = 0; 28091da177e4SLinus Torvalds } 28101da177e4SLinus Torvalds break; 28111da177e4SLinus Torvalds case READ_REG: 28121da177e4SLinus Torvalds { 28131da177e4SLinus Torvalds if (!capable(CAP_NET_ADMIN)) return -EPERM; 28141da177e4SLinus Torvalds desc_dbg(iadev); 28151da177e4SLinus Torvalds ia_cmds.status = 0; 28161da177e4SLinus Torvalds } 28171da177e4SLinus Torvalds break; 28181da177e4SLinus Torvalds case 0x6: 28191da177e4SLinus Torvalds { 28201da177e4SLinus Torvalds ia_cmds.status = 0; 28211da177e4SLinus Torvalds printk("skb = 0x%lx\n", (long)skb_peek(&iadev->tx_backlog)); 28221da177e4SLinus Torvalds printk("rtn_q: 0x%lx\n",(long)ia_deque_rtn_q(&iadev->tx_return_q)); 28231da177e4SLinus Torvalds } 28241da177e4SLinus Torvalds break; 28251da177e4SLinus Torvalds case 0x8: 28261da177e4SLinus Torvalds { 28271da177e4SLinus Torvalds struct k_sonet_stats *stats; 28281da177e4SLinus Torvalds stats = &PRIV(_ia_dev[board])->sonet_stats; 28291da177e4SLinus Torvalds printk("section_bip: %d\n", atomic_read(&stats->section_bip)); 28301da177e4SLinus Torvalds printk("line_bip : %d\n", atomic_read(&stats->line_bip)); 28311da177e4SLinus Torvalds printk("path_bip : %d\n", atomic_read(&stats->path_bip)); 28321da177e4SLinus Torvalds printk("line_febe : %d\n", atomic_read(&stats->line_febe)); 28331da177e4SLinus Torvalds printk("path_febe : %d\n", atomic_read(&stats->path_febe)); 28341da177e4SLinus Torvalds printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs)); 28351da177e4SLinus Torvalds printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs)); 28361da177e4SLinus Torvalds printk("tx_cells : %d\n", atomic_read(&stats->tx_cells)); 28371da177e4SLinus Torvalds printk("rx_cells : %d\n", atomic_read(&stats->rx_cells)); 28381da177e4SLinus Torvalds } 28391da177e4SLinus Torvalds ia_cmds.status = 0; 28401da177e4SLinus Torvalds break; 28411da177e4SLinus Torvalds case 0x9: 28421da177e4SLinus Torvalds if (!capable(CAP_NET_ADMIN)) return -EPERM; 28431da177e4SLinus Torvalds for (i = 1; i <= iadev->num_rx_desc; i++) 28441da177e4SLinus Torvalds free_desc(_ia_dev[board], i); 28451da177e4SLinus Torvalds writew( ~(RX_FREEQ_EMPT | RX_EXCP_RCVD), 28461da177e4SLinus Torvalds iadev->reass_reg+REASS_MASK_REG); 28471da177e4SLinus Torvalds iadev->rxing = 1; 28481da177e4SLinus Torvalds 28491da177e4SLinus Torvalds ia_cmds.status = 0; 28501da177e4SLinus Torvalds break; 28511da177e4SLinus Torvalds 28521da177e4SLinus Torvalds case 0xb: 28531da177e4SLinus Torvalds if (!capable(CAP_NET_ADMIN)) return -EPERM; 285426c5c44dSfrançois romieu ia_frontend_intr(iadev); 28551da177e4SLinus Torvalds break; 28561da177e4SLinus Torvalds case 0xa: 28571da177e4SLinus Torvalds if (!capable(CAP_NET_ADMIN)) return -EPERM; 28581da177e4SLinus Torvalds { 28591da177e4SLinus Torvalds ia_cmds.status = 0; 28601da177e4SLinus Torvalds IADebugFlag = ia_cmds.maddr; 28611da177e4SLinus Torvalds printk("New debug option loaded\n"); 28621da177e4SLinus Torvalds } 28631da177e4SLinus Torvalds break; 28641da177e4SLinus Torvalds default: 28651da177e4SLinus Torvalds ia_cmds.status = 0; 28661da177e4SLinus Torvalds break; 28671da177e4SLinus Torvalds } 28681da177e4SLinus Torvalds } 28691da177e4SLinus Torvalds break; 28701da177e4SLinus Torvalds default: 28711da177e4SLinus Torvalds break; 28721da177e4SLinus Torvalds 28731da177e4SLinus Torvalds } 28741da177e4SLinus Torvalds return 0; 28751da177e4SLinus Torvalds } 28761da177e4SLinus Torvalds 28771da177e4SLinus Torvalds static int ia_getsockopt(struct atm_vcc *vcc, int level, int optname, 28781da177e4SLinus Torvalds void __user *optval, int optlen) 28791da177e4SLinus Torvalds { 28801da177e4SLinus Torvalds IF_EVENT(printk(">ia_getsockopt\n");) 28811da177e4SLinus Torvalds return -EINVAL; 28821da177e4SLinus Torvalds } 28831da177e4SLinus Torvalds 28841da177e4SLinus Torvalds static int ia_setsockopt(struct atm_vcc *vcc, int level, int optname, 2885b7058842SDavid S. Miller void __user *optval, unsigned int optlen) 28861da177e4SLinus Torvalds { 28871da177e4SLinus Torvalds IF_EVENT(printk(">ia_setsockopt\n");) 28881da177e4SLinus Torvalds return -EINVAL; 28891da177e4SLinus Torvalds } 28901da177e4SLinus Torvalds 28911da177e4SLinus Torvalds static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) { 28921da177e4SLinus Torvalds IADEV *iadev; 28931da177e4SLinus Torvalds struct dle *wr_ptr; 28941da177e4SLinus Torvalds struct tx_buf_desc __iomem *buf_desc_ptr; 28951da177e4SLinus Torvalds int desc; 28961da177e4SLinus Torvalds int comp_code; 28971da177e4SLinus Torvalds int total_len; 28981da177e4SLinus Torvalds struct cpcs_trailer *trailer; 28991da177e4SLinus Torvalds struct ia_vcc *iavcc; 29001da177e4SLinus Torvalds 29011da177e4SLinus Torvalds iadev = INPH_IA_DEV(vcc->dev); 29021da177e4SLinus Torvalds iavcc = INPH_IA_VCC(vcc); 29031da177e4SLinus Torvalds if (!iavcc->txing) { 29041da177e4SLinus Torvalds printk("discard packet on closed VC\n"); 29051da177e4SLinus Torvalds if (vcc->pop) 29061da177e4SLinus Torvalds vcc->pop(vcc, skb); 29071da177e4SLinus Torvalds else 29081da177e4SLinus Torvalds dev_kfree_skb_any(skb); 29091da177e4SLinus Torvalds return 0; 29101da177e4SLinus Torvalds } 29111da177e4SLinus Torvalds 29121da177e4SLinus Torvalds if (skb->len > iadev->tx_buf_sz - 8) { 29131da177e4SLinus Torvalds printk("Transmit size over tx buffer size\n"); 29141da177e4SLinus Torvalds if (vcc->pop) 29151da177e4SLinus Torvalds vcc->pop(vcc, skb); 29161da177e4SLinus Torvalds else 29171da177e4SLinus Torvalds dev_kfree_skb_any(skb); 29181da177e4SLinus Torvalds return 0; 29191da177e4SLinus Torvalds } 292097928f70SAlan Cox if ((unsigned long)skb->data & 3) { 29211da177e4SLinus Torvalds printk("Misaligned SKB\n"); 29221da177e4SLinus Torvalds if (vcc->pop) 29231da177e4SLinus Torvalds vcc->pop(vcc, skb); 29241da177e4SLinus Torvalds else 29251da177e4SLinus Torvalds dev_kfree_skb_any(skb); 29261da177e4SLinus Torvalds return 0; 29271da177e4SLinus Torvalds } 29281da177e4SLinus Torvalds /* Get a descriptor number from our free descriptor queue 29291da177e4SLinus Torvalds We get the descr number from the TCQ now, since I am using 29301da177e4SLinus Torvalds the TCQ as a free buffer queue. Initially TCQ will be 29311da177e4SLinus Torvalds initialized with all the descriptors and is hence, full. 29321da177e4SLinus Torvalds */ 29331da177e4SLinus Torvalds desc = get_desc (iadev, iavcc); 29341da177e4SLinus Torvalds if (desc == 0xffff) 29351da177e4SLinus Torvalds return 1; 29361da177e4SLinus Torvalds comp_code = desc >> 13; 29371da177e4SLinus Torvalds desc &= 0x1fff; 29381da177e4SLinus Torvalds 29391da177e4SLinus Torvalds if ((desc == 0) || (desc > iadev->num_tx_desc)) 29401da177e4SLinus Torvalds { 29411da177e4SLinus Torvalds IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);) 29421da177e4SLinus Torvalds atomic_inc(&vcc->stats->tx); 29431da177e4SLinus Torvalds if (vcc->pop) 29441da177e4SLinus Torvalds vcc->pop(vcc, skb); 29451da177e4SLinus Torvalds else 29461da177e4SLinus Torvalds dev_kfree_skb_any(skb); 29471da177e4SLinus Torvalds return 0; /* return SUCCESS */ 29481da177e4SLinus Torvalds } 29491da177e4SLinus Torvalds 29501da177e4SLinus Torvalds if (comp_code) 29511da177e4SLinus Torvalds { 29521da177e4SLinus Torvalds IF_ERR(printk(DEV_LABEL "send desc:%d completion code %d error\n", 29531da177e4SLinus Torvalds desc, comp_code);) 29541da177e4SLinus Torvalds } 29551da177e4SLinus Torvalds 29561da177e4SLinus Torvalds /* remember the desc and vcc mapping */ 29571da177e4SLinus Torvalds iavcc->vc_desc_cnt++; 29581da177e4SLinus Torvalds iadev->desc_tbl[desc-1].iavcc = iavcc; 29591da177e4SLinus Torvalds iadev->desc_tbl[desc-1].txskb = skb; 29601da177e4SLinus Torvalds IA_SKB_STATE(skb) = 0; 29611da177e4SLinus Torvalds 29621da177e4SLinus Torvalds iadev->ffL.tcq_rd += 2; 29631da177e4SLinus Torvalds if (iadev->ffL.tcq_rd > iadev->ffL.tcq_ed) 29641da177e4SLinus Torvalds iadev->ffL.tcq_rd = iadev->ffL.tcq_st; 29651da177e4SLinus Torvalds writew(iadev->ffL.tcq_rd, iadev->seg_reg+TCQ_RD_PTR); 29661da177e4SLinus Torvalds 29671da177e4SLinus Torvalds /* Put the descriptor number in the packet ready queue 29681da177e4SLinus Torvalds and put the updated write pointer in the DLE field 29691da177e4SLinus Torvalds */ 29701da177e4SLinus Torvalds *(u16*)(iadev->seg_ram+iadev->ffL.prq_wr) = desc; 29711da177e4SLinus Torvalds 29721da177e4SLinus Torvalds iadev->ffL.prq_wr += 2; 29731da177e4SLinus Torvalds if (iadev->ffL.prq_wr > iadev->ffL.prq_ed) 29741da177e4SLinus Torvalds iadev->ffL.prq_wr = iadev->ffL.prq_st; 29751da177e4SLinus Torvalds 29761da177e4SLinus Torvalds /* Figure out the exact length of the packet and padding required to 29771da177e4SLinus Torvalds make it aligned on a 48 byte boundary. */ 29781da177e4SLinus Torvalds total_len = skb->len + sizeof(struct cpcs_trailer); 29791da177e4SLinus Torvalds total_len = ((total_len + 47) / 48) * 48; 29801da177e4SLinus Torvalds IF_TX(printk("ia packet len:%d padding:%d\n", total_len, total_len - skb->len);) 29811da177e4SLinus Torvalds 29821da177e4SLinus Torvalds /* Put the packet in a tx buffer */ 29831da177e4SLinus Torvalds trailer = iadev->tx_buf[desc-1].cpcs; 2984849e8caaSDavid Howells IF_TX(printk("Sent: skb = 0x%p skb->data: 0x%p len: %d, desc: %d\n", 2985849e8caaSDavid Howells skb, skb->data, skb->len, desc);) 29861da177e4SLinus Torvalds trailer->control = 0; 29871da177e4SLinus Torvalds /*big endian*/ 29881da177e4SLinus Torvalds trailer->length = ((skb->len & 0xff) << 8) | ((skb->len & 0xff00) >> 8); 29891da177e4SLinus Torvalds trailer->crc32 = 0; /* not needed - dummy bytes */ 29901da177e4SLinus Torvalds 29911da177e4SLinus Torvalds /* Display the packet */ 29921da177e4SLinus Torvalds IF_TXPKT(printk("Sent data: len = %d MsgNum = %d\n", 29931da177e4SLinus Torvalds skb->len, tcnter++); 29941da177e4SLinus Torvalds xdump(skb->data, skb->len, "TX: "); 29951da177e4SLinus Torvalds printk("\n");) 29961da177e4SLinus Torvalds 29971da177e4SLinus Torvalds /* Build the buffer descriptor */ 29981da177e4SLinus Torvalds buf_desc_ptr = iadev->seg_ram+TX_DESC_BASE; 29991da177e4SLinus Torvalds buf_desc_ptr += desc; /* points to the corresponding entry */ 30001da177e4SLinus Torvalds buf_desc_ptr->desc_mode = AAL5 | EOM_EN | APP_CRC32 | CMPL_INT; 30011da177e4SLinus Torvalds /* Huh ? p.115 of users guide describes this as a read-only register */ 30021da177e4SLinus Torvalds writew(TRANSMIT_DONE, iadev->seg_reg+SEG_INTR_STATUS_REG); 30031da177e4SLinus Torvalds buf_desc_ptr->vc_index = vcc->vci; 30041da177e4SLinus Torvalds buf_desc_ptr->bytes = total_len; 30051da177e4SLinus Torvalds 30061da177e4SLinus Torvalds if (vcc->qos.txtp.traffic_class == ATM_ABR) 30071da177e4SLinus Torvalds clear_lockup (vcc, iadev); 30081da177e4SLinus Torvalds 30091da177e4SLinus Torvalds /* Build the DLE structure */ 30101da177e4SLinus Torvalds wr_ptr = iadev->tx_dle_q.write; 30111da177e4SLinus Torvalds memset((caddr_t)wr_ptr, 0, sizeof(*wr_ptr)); 30121da177e4SLinus Torvalds wr_ptr->sys_pkt_addr = pci_map_single(iadev->pci, skb->data, 30131da177e4SLinus Torvalds skb->len, PCI_DMA_TODEVICE); 30141da177e4SLinus Torvalds wr_ptr->local_pkt_addr = (buf_desc_ptr->buf_start_hi << 16) | 30151da177e4SLinus Torvalds buf_desc_ptr->buf_start_lo; 3016b67445fcSWu Fengguang /* wr_ptr->bytes = swap_byte_order(total_len); didn't seem to affect?? */ 30171da177e4SLinus Torvalds wr_ptr->bytes = skb->len; 30181da177e4SLinus Torvalds 30191da177e4SLinus Torvalds /* hw bug - DLEs of 0x2d, 0x2e, 0x2f cause DMA lockup */ 30201da177e4SLinus Torvalds if ((wr_ptr->bytes >> 2) == 0xb) 30211da177e4SLinus Torvalds wr_ptr->bytes = 0x30; 30221da177e4SLinus Torvalds 30231da177e4SLinus Torvalds wr_ptr->mode = TX_DLE_PSI; 30241da177e4SLinus Torvalds wr_ptr->prq_wr_ptr_data = 0; 30251da177e4SLinus Torvalds 30261da177e4SLinus Torvalds /* end is not to be used for the DLE q */ 30271da177e4SLinus Torvalds if (++wr_ptr == iadev->tx_dle_q.end) 30281da177e4SLinus Torvalds wr_ptr = iadev->tx_dle_q.start; 30291da177e4SLinus Torvalds 30301da177e4SLinus Torvalds /* Build trailer dle */ 30311da177e4SLinus Torvalds wr_ptr->sys_pkt_addr = iadev->tx_buf[desc-1].dma_addr; 30321da177e4SLinus Torvalds wr_ptr->local_pkt_addr = ((buf_desc_ptr->buf_start_hi << 16) | 30331da177e4SLinus Torvalds buf_desc_ptr->buf_start_lo) + total_len - sizeof(struct cpcs_trailer); 30341da177e4SLinus Torvalds 30351da177e4SLinus Torvalds wr_ptr->bytes = sizeof(struct cpcs_trailer); 30361da177e4SLinus Torvalds wr_ptr->mode = DMA_INT_ENABLE; 30371da177e4SLinus Torvalds wr_ptr->prq_wr_ptr_data = iadev->ffL.prq_wr; 30381da177e4SLinus Torvalds 30391da177e4SLinus Torvalds /* end is not to be used for the DLE q */ 30401da177e4SLinus Torvalds if (++wr_ptr == iadev->tx_dle_q.end) 30411da177e4SLinus Torvalds wr_ptr = iadev->tx_dle_q.start; 30421da177e4SLinus Torvalds 30431da177e4SLinus Torvalds iadev->tx_dle_q.write = wr_ptr; 30441da177e4SLinus Torvalds ATM_DESC(skb) = vcc->vci; 30451da177e4SLinus Torvalds skb_queue_tail(&iadev->tx_dma_q, skb); 30461da177e4SLinus Torvalds 30471da177e4SLinus Torvalds atomic_inc(&vcc->stats->tx); 30481da177e4SLinus Torvalds iadev->tx_pkt_cnt++; 30491da177e4SLinus Torvalds /* Increment transaction counter */ 30501da177e4SLinus Torvalds writel(2, iadev->dma+IPHASE5575_TX_COUNTER); 30511da177e4SLinus Torvalds 30521da177e4SLinus Torvalds #if 0 30531da177e4SLinus Torvalds /* add flow control logic */ 30541da177e4SLinus Torvalds if (atomic_read(&vcc->stats->tx) % 20 == 0) { 30551da177e4SLinus Torvalds if (iavcc->vc_desc_cnt > 10) { 30561da177e4SLinus Torvalds vcc->tx_quota = vcc->tx_quota * 3 / 4; 30571da177e4SLinus Torvalds printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota ); 30581da177e4SLinus Torvalds iavcc->flow_inc = -1; 30591da177e4SLinus Torvalds iavcc->saved_tx_quota = vcc->tx_quota; 30601da177e4SLinus Torvalds } else if ((iavcc->flow_inc < 0) && (iavcc->vc_desc_cnt < 3)) { 30611da177e4SLinus Torvalds // vcc->tx_quota = 3 * iavcc->saved_tx_quota / 4; 30621da177e4SLinus Torvalds printk("Tx2: vcc->tx_quota = %d \n", (u32)vcc->tx_quota ); 30631da177e4SLinus Torvalds iavcc->flow_inc = 0; 30641da177e4SLinus Torvalds } 30651da177e4SLinus Torvalds } 30661da177e4SLinus Torvalds #endif 30671da177e4SLinus Torvalds IF_TX(printk("ia send done\n");) 30681da177e4SLinus Torvalds return 0; 30691da177e4SLinus Torvalds } 30701da177e4SLinus Torvalds 30711da177e4SLinus Torvalds static int ia_send(struct atm_vcc *vcc, struct sk_buff *skb) 30721da177e4SLinus Torvalds { 30731da177e4SLinus Torvalds IADEV *iadev; 30741da177e4SLinus Torvalds unsigned long flags; 30751da177e4SLinus Torvalds 30761da177e4SLinus Torvalds iadev = INPH_IA_DEV(vcc->dev); 30771da177e4SLinus Torvalds if ((!skb)||(skb->len>(iadev->tx_buf_sz-sizeof(struct cpcs_trailer)))) 30781da177e4SLinus Torvalds { 30791da177e4SLinus Torvalds if (!skb) 30801da177e4SLinus Torvalds printk(KERN_CRIT "null skb in ia_send\n"); 30811da177e4SLinus Torvalds else dev_kfree_skb_any(skb); 30821da177e4SLinus Torvalds return -EINVAL; 30831da177e4SLinus Torvalds } 30841da177e4SLinus Torvalds spin_lock_irqsave(&iadev->tx_lock, flags); 30851da177e4SLinus Torvalds if (!test_bit(ATM_VF_READY,&vcc->flags)){ 30861da177e4SLinus Torvalds dev_kfree_skb_any(skb); 30871da177e4SLinus Torvalds spin_unlock_irqrestore(&iadev->tx_lock, flags); 30881da177e4SLinus Torvalds return -EINVAL; 30891da177e4SLinus Torvalds } 30901da177e4SLinus Torvalds ATM_SKB(skb)->vcc = vcc; 30911da177e4SLinus Torvalds 30921da177e4SLinus Torvalds if (skb_peek(&iadev->tx_backlog)) { 30931da177e4SLinus Torvalds skb_queue_tail(&iadev->tx_backlog, skb); 30941da177e4SLinus Torvalds } 30951da177e4SLinus Torvalds else { 30961da177e4SLinus Torvalds if (ia_pkt_tx (vcc, skb)) { 30971da177e4SLinus Torvalds skb_queue_tail(&iadev->tx_backlog, skb); 30981da177e4SLinus Torvalds } 30991da177e4SLinus Torvalds } 31001da177e4SLinus Torvalds spin_unlock_irqrestore(&iadev->tx_lock, flags); 31011da177e4SLinus Torvalds return 0; 31021da177e4SLinus Torvalds 31031da177e4SLinus Torvalds } 31041da177e4SLinus Torvalds 31051da177e4SLinus Torvalds static int ia_proc_read(struct atm_dev *dev,loff_t *pos,char *page) 31061da177e4SLinus Torvalds { 31071da177e4SLinus Torvalds int left = *pos, n; 31081da177e4SLinus Torvalds char *tmpPtr; 31091da177e4SLinus Torvalds IADEV *iadev = INPH_IA_DEV(dev); 31101da177e4SLinus Torvalds if(!left--) { 31111da177e4SLinus Torvalds if (iadev->phy_type == FE_25MBIT_PHY) { 31121da177e4SLinus Torvalds n = sprintf(page, " Board Type : Iphase5525-1KVC-128K\n"); 31131da177e4SLinus Torvalds return n; 31141da177e4SLinus Torvalds } 31151da177e4SLinus Torvalds if (iadev->phy_type == FE_DS3_PHY) 31161da177e4SLinus Torvalds n = sprintf(page, " Board Type : Iphase-ATM-DS3"); 31171da177e4SLinus Torvalds else if (iadev->phy_type == FE_E3_PHY) 31181da177e4SLinus Torvalds n = sprintf(page, " Board Type : Iphase-ATM-E3"); 31191da177e4SLinus Torvalds else if (iadev->phy_type == FE_UTP_OPTION) 31201da177e4SLinus Torvalds n = sprintf(page, " Board Type : Iphase-ATM-UTP155"); 31211da177e4SLinus Torvalds else 31221da177e4SLinus Torvalds n = sprintf(page, " Board Type : Iphase-ATM-OC3"); 31231da177e4SLinus Torvalds tmpPtr = page + n; 31241da177e4SLinus Torvalds if (iadev->pci_map_size == 0x40000) 31251da177e4SLinus Torvalds n += sprintf(tmpPtr, "-1KVC-"); 31261da177e4SLinus Torvalds else 31271da177e4SLinus Torvalds n += sprintf(tmpPtr, "-4KVC-"); 31281da177e4SLinus Torvalds tmpPtr = page + n; 31291da177e4SLinus Torvalds if ((iadev->memType & MEM_SIZE_MASK) == MEM_SIZE_1M) 31301da177e4SLinus Torvalds n += sprintf(tmpPtr, "1M \n"); 31311da177e4SLinus Torvalds else if ((iadev->memType & MEM_SIZE_MASK) == MEM_SIZE_512K) 31321da177e4SLinus Torvalds n += sprintf(tmpPtr, "512K\n"); 31331da177e4SLinus Torvalds else 31341da177e4SLinus Torvalds n += sprintf(tmpPtr, "128K\n"); 31351da177e4SLinus Torvalds return n; 31361da177e4SLinus Torvalds } 31371da177e4SLinus Torvalds if (!left) { 31381da177e4SLinus Torvalds return sprintf(page, " Number of Tx Buffer: %u\n" 31391da177e4SLinus Torvalds " Size of Tx Buffer : %u\n" 31401da177e4SLinus Torvalds " Number of Rx Buffer: %u\n" 31411da177e4SLinus Torvalds " Size of Rx Buffer : %u\n" 31421da177e4SLinus Torvalds " Packets Receiverd : %u\n" 31431da177e4SLinus Torvalds " Packets Transmitted: %u\n" 31441da177e4SLinus Torvalds " Cells Received : %u\n" 31451da177e4SLinus Torvalds " Cells Transmitted : %u\n" 31461da177e4SLinus Torvalds " Board Dropped Cells: %u\n" 31471da177e4SLinus Torvalds " Board Dropped Pkts : %u\n", 31481da177e4SLinus Torvalds iadev->num_tx_desc, iadev->tx_buf_sz, 31491da177e4SLinus Torvalds iadev->num_rx_desc, iadev->rx_buf_sz, 31501da177e4SLinus Torvalds iadev->rx_pkt_cnt, iadev->tx_pkt_cnt, 31511da177e4SLinus Torvalds iadev->rx_cell_cnt, iadev->tx_cell_cnt, 31521da177e4SLinus Torvalds iadev->drop_rxcell, iadev->drop_rxpkt); 31531da177e4SLinus Torvalds } 31541da177e4SLinus Torvalds return 0; 31551da177e4SLinus Torvalds } 31561da177e4SLinus Torvalds 31571da177e4SLinus Torvalds static const struct atmdev_ops ops = { 31581da177e4SLinus Torvalds .open = ia_open, 31591da177e4SLinus Torvalds .close = ia_close, 31601da177e4SLinus Torvalds .ioctl = ia_ioctl, 31611da177e4SLinus Torvalds .getsockopt = ia_getsockopt, 31621da177e4SLinus Torvalds .setsockopt = ia_setsockopt, 31631da177e4SLinus Torvalds .send = ia_send, 31641da177e4SLinus Torvalds .phy_put = ia_phy_put, 31651da177e4SLinus Torvalds .phy_get = ia_phy_get, 31661da177e4SLinus Torvalds .change_qos = ia_change_qos, 31671da177e4SLinus Torvalds .proc_read = ia_proc_read, 31681da177e4SLinus Torvalds .owner = THIS_MODULE, 31691da177e4SLinus Torvalds }; 31701da177e4SLinus Torvalds 31711da177e4SLinus Torvalds static int __devinit ia_init_one(struct pci_dev *pdev, 31721da177e4SLinus Torvalds const struct pci_device_id *ent) 31731da177e4SLinus Torvalds { 31741da177e4SLinus Torvalds struct atm_dev *dev; 31751da177e4SLinus Torvalds IADEV *iadev; 31761da177e4SLinus Torvalds int ret; 31771da177e4SLinus Torvalds 3178f7141761SMariusz Kozlowski iadev = kzalloc(sizeof(*iadev), GFP_KERNEL); 31791da177e4SLinus Torvalds if (!iadev) { 31801da177e4SLinus Torvalds ret = -ENOMEM; 31811da177e4SLinus Torvalds goto err_out; 31821da177e4SLinus Torvalds } 3183f7141761SMariusz Kozlowski 31841da177e4SLinus Torvalds iadev->pci = pdev; 31851da177e4SLinus Torvalds 31861da177e4SLinus Torvalds IF_INIT(printk("ia detected at bus:%d dev: %d function:%d\n", 31871da177e4SLinus Torvalds pdev->bus->number, PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));) 31881da177e4SLinus Torvalds if (pci_enable_device(pdev)) { 31891da177e4SLinus Torvalds ret = -ENODEV; 31901da177e4SLinus Torvalds goto err_out_free_iadev; 31911da177e4SLinus Torvalds } 3192d9ca676bSDan Williams dev = atm_dev_register(DEV_LABEL, &pdev->dev, &ops, -1, NULL); 31931da177e4SLinus Torvalds if (!dev) { 31941da177e4SLinus Torvalds ret = -ENOMEM; 31951da177e4SLinus Torvalds goto err_out_disable_dev; 31961da177e4SLinus Torvalds } 31971da177e4SLinus Torvalds dev->dev_data = iadev; 31981da177e4SLinus Torvalds IF_INIT(printk(DEV_LABEL "registered at (itf :%d)\n", dev->number);) 3199849e8caaSDavid Howells IF_INIT(printk("dev_id = 0x%p iadev->LineRate = %d \n", dev, 32001da177e4SLinus Torvalds iadev->LineRate);) 32011da177e4SLinus Torvalds 3202c0ed0b60SJorge Boncompte [DTI2] pci_set_drvdata(pdev, dev); 3203c0ed0b60SJorge Boncompte [DTI2] 32041da177e4SLinus Torvalds ia_dev[iadev_count] = iadev; 32051da177e4SLinus Torvalds _ia_dev[iadev_count] = dev; 32061da177e4SLinus Torvalds iadev_count++; 32071da177e4SLinus Torvalds if (ia_init(dev) || ia_start(dev)) { 32081da177e4SLinus Torvalds IF_INIT(printk("IA register failed!\n");) 32091da177e4SLinus Torvalds iadev_count--; 32101da177e4SLinus Torvalds ia_dev[iadev_count] = NULL; 32111da177e4SLinus Torvalds _ia_dev[iadev_count] = NULL; 32121da177e4SLinus Torvalds ret = -EINVAL; 32131da177e4SLinus Torvalds goto err_out_deregister_dev; 32141da177e4SLinus Torvalds } 32151da177e4SLinus Torvalds IF_EVENT(printk("iadev_count = %d\n", iadev_count);) 32161da177e4SLinus Torvalds 32171da177e4SLinus Torvalds iadev->next_board = ia_boards; 32181da177e4SLinus Torvalds ia_boards = dev; 32191da177e4SLinus Torvalds 32201da177e4SLinus Torvalds return 0; 32211da177e4SLinus Torvalds 32221da177e4SLinus Torvalds err_out_deregister_dev: 32231da177e4SLinus Torvalds atm_dev_deregister(dev); 32241da177e4SLinus Torvalds err_out_disable_dev: 32251da177e4SLinus Torvalds pci_disable_device(pdev); 32261da177e4SLinus Torvalds err_out_free_iadev: 32271da177e4SLinus Torvalds kfree(iadev); 32281da177e4SLinus Torvalds err_out: 32291da177e4SLinus Torvalds return ret; 32301da177e4SLinus Torvalds } 32311da177e4SLinus Torvalds 32321da177e4SLinus Torvalds static void __devexit ia_remove_one(struct pci_dev *pdev) 32331da177e4SLinus Torvalds { 32341da177e4SLinus Torvalds struct atm_dev *dev = pci_get_drvdata(pdev); 32351da177e4SLinus Torvalds IADEV *iadev = INPH_IA_DEV(dev); 32361da177e4SLinus Torvalds 3237d6c1d704SJorge Boncompte [DTI2] /* Disable phy interrupts */ 3238d6c1d704SJorge Boncompte [DTI2] ia_phy_put(dev, ia_phy_get(dev, SUNI_RSOP_CIE) & ~(SUNI_RSOP_CIE_LOSE), 3239d6c1d704SJorge Boncompte [DTI2] SUNI_RSOP_CIE); 32401da177e4SLinus Torvalds udelay(1); 32411da177e4SLinus Torvalds 3242d6c1d704SJorge Boncompte [DTI2] if (dev->phy && dev->phy->stop) 3243d6c1d704SJorge Boncompte [DTI2] dev->phy->stop(dev); 3244d6c1d704SJorge Boncompte [DTI2] 32451da177e4SLinus Torvalds /* De-register device */ 32461da177e4SLinus Torvalds free_irq(iadev->irq, dev); 32471da177e4SLinus Torvalds iadev_count--; 32481da177e4SLinus Torvalds ia_dev[iadev_count] = NULL; 32491da177e4SLinus Torvalds _ia_dev[iadev_count] = NULL; 32501da177e4SLinus Torvalds IF_EVENT(printk("deregistering iav at (itf:%d)\n", dev->number);) 32511da177e4SLinus Torvalds atm_dev_deregister(dev); 32521da177e4SLinus Torvalds 32531da177e4SLinus Torvalds iounmap(iadev->base); 32541da177e4SLinus Torvalds pci_disable_device(pdev); 32551da177e4SLinus Torvalds 32561da177e4SLinus Torvalds ia_free_rx(iadev); 32571da177e4SLinus Torvalds ia_free_tx(iadev); 32581da177e4SLinus Torvalds 32591da177e4SLinus Torvalds kfree(iadev); 32601da177e4SLinus Torvalds } 32611da177e4SLinus Torvalds 32621da177e4SLinus Torvalds static struct pci_device_id ia_pci_tbl[] = { 32631da177e4SLinus Torvalds { PCI_VENDOR_ID_IPHASE, 0x0008, PCI_ANY_ID, PCI_ANY_ID, }, 32641da177e4SLinus Torvalds { PCI_VENDOR_ID_IPHASE, 0x0009, PCI_ANY_ID, PCI_ANY_ID, }, 32651da177e4SLinus Torvalds { 0,} 32661da177e4SLinus Torvalds }; 32671da177e4SLinus Torvalds MODULE_DEVICE_TABLE(pci, ia_pci_tbl); 32681da177e4SLinus Torvalds 32691da177e4SLinus Torvalds static struct pci_driver ia_driver = { 32701da177e4SLinus Torvalds .name = DEV_LABEL, 32711da177e4SLinus Torvalds .id_table = ia_pci_tbl, 32721da177e4SLinus Torvalds .probe = ia_init_one, 32731da177e4SLinus Torvalds .remove = __devexit_p(ia_remove_one), 32741da177e4SLinus Torvalds }; 32751da177e4SLinus Torvalds 32761da177e4SLinus Torvalds static int __init ia_module_init(void) 32771da177e4SLinus Torvalds { 32781da177e4SLinus Torvalds int ret; 32791da177e4SLinus Torvalds 32801da177e4SLinus Torvalds ret = pci_register_driver(&ia_driver); 32811da177e4SLinus Torvalds if (ret >= 0) { 32821da177e4SLinus Torvalds ia_timer.expires = jiffies + 3*HZ; 32831da177e4SLinus Torvalds add_timer(&ia_timer); 32841da177e4SLinus Torvalds } else 32851da177e4SLinus Torvalds printk(KERN_ERR DEV_LABEL ": no adapter found\n"); 32861da177e4SLinus Torvalds return ret; 32871da177e4SLinus Torvalds } 32881da177e4SLinus Torvalds 32891da177e4SLinus Torvalds static void __exit ia_module_exit(void) 32901da177e4SLinus Torvalds { 32911da177e4SLinus Torvalds pci_unregister_driver(&ia_driver); 32921da177e4SLinus Torvalds 32931da177e4SLinus Torvalds del_timer(&ia_timer); 32941da177e4SLinus Torvalds } 32951da177e4SLinus Torvalds 32961da177e4SLinus Torvalds module_init(ia_module_init); 32971da177e4SLinus Torvalds module_exit(ia_module_exit); 3298