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