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