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