43 #include <linux/module.h>
44 #include <linux/kernel.h>
46 #include <linux/pci.h>
47 #include <linux/errno.h>
48 #include <linux/atm.h>
49 #include <linux/atmdev.h>
50 #include <linux/sonet.h>
52 #include <linux/time.h>
54 #include <linux/uio.h>
57 #include <linux/wait.h>
58 #include <linux/slab.h>
61 #include <asm/uaccess.h>
62 #include <asm/string.h>
63 #include <asm/byteorder.h>
68 #define swap_byte_order(x) (((x & 0xff) << 8) | ((x & 0xff00) >> 8))
70 #define PRIV(dev) ((struct suni_priv *) dev->phy_data)
72 static unsigned char ia_phy_get(
struct atm_dev *
dev,
unsigned long addr);
73 static void desc_dbg(
IADEV *iadev);
75 static IADEV *ia_dev[8];
76 static struct atm_dev *_ia_dev[8];
77 static int iadev_count;
78 static void ia_led_timer(
unsigned long arg);
82 static uint IADebugFlag =
95 static void ia_init_rtn_q (
IARTN_Q *que)
115 if (!entry)
return -1;
139 static void ia_hack_tcq(
IADEV *
dev) {
149 else if (!dev->
desc_tbl[desc1 -1].timestamp) {
150 IF_ABR(
printk(
" Desc %d is reset at %ld\n", desc1 -1, jiffies);)
153 else if (dev->
desc_tbl[desc1 -1].timestamp) {
154 if (!(iavcc_r = dev->
desc_tbl[desc1 -1].iavcc)) {
155 printk(
"IA: Fatal err in get_desc\n");
159 dev->
desc_tbl[desc1 -1].timestamp = 0;
161 dev->
desc_tbl[desc1 -1].txskb, desc1);)
162 if (iavcc_r->
pcr < dev->rate_limit) {
165 printk(
"ia_hack_tcq: No memory available\n");
181 static unsigned long timer = 0;
188 while (i < dev->num_tx_desc) {
193 ltimeout = dev->
desc_tbl[
i].iavcc->ltimeout;
195 if (delta >= ltimeout) {
196 IF_ABR(
printk(
"RECOVER run!! desc_tbl %d = %d delta = %ld, time = %ld\n", i,dev->
desc_tbl[i].timestamp, delta, jiffies);)
197 if (dev->ffL.tcq_rd == dev->ffL.tcq_st)
198 dev->ffL.tcq_rd = dev->ffL.tcq_ed;
200 dev->ffL.tcq_rd -= 2;
201 *(
u_short *)(dev->seg_ram + dev->ffL.tcq_rd) = i+1;
202 if (!(skb = dev->desc_tbl[i].txskb) ||
203 !(iavcc_r = dev->desc_tbl[i].iavcc))
208 dev->desc_tbl[i].iavcc =
NULL;
209 dev->desc_tbl[i].txskb = NULL;
214 if (dev->ffL.tcq_rd == dev->host_tcq_wr)
218 desc_num = *(
u_short *)(dev->seg_ram + dev->ffL.tcq_rd);
220 while (!desc_num || (dev->desc_tbl[desc_num -1]).timestamp) {
221 dev->
ffL.tcq_rd += 2;
222 if (dev->
ffL.tcq_rd > dev->
ffL.tcq_ed)
223 dev->
ffL.tcq_rd = dev->
ffL.tcq_st;
238 u_short tempCellSlot, tempFract;
247 if( vcstatus->
cnt == 0x05 ) {
250 if( eabr_vc->last_desc ) {
278 for( i = 0; ((i < dev->num_vc) && (shd_tbl[i])); i++ );
280 shd_tbl[
i] = vcc->
vci;
307 cellrate_to_float(
u32 cr)
316 u32 tmp = cr & 0x00ffffff;
325 flot =
NZ | (i <<
M_BITS) | (cr & M_MASK);
327 flot =
NZ | (i <<
M_BITS) | ((cr << (M_BITS - i)) & M_MASK);
329 flot =
NZ | (i << M_BITS) | ((cr >> (i -
M_BITS)) & M_MASK);
341 if ((rate & NZ) == 0)
343 exp = (rate >>
M_BITS) & E_MASK;
344 mantissa = rate & M_MASK;
347 cps = (1 <<
M_BITS) | mantissa;
350 else if (exp > M_BITS)
362 srv_p->
icr = 0x055cb7;
363 srv_p->
tbe = 0xffffff;
381 u16 adtf, air, *ptr16;
383 f_abr_vc += vcc->
vci;
392 return MCR_UNAVAILABLE;
393 if (srv_p->
mcr > srv_p->
pcr)
399 if ((srv_p->
tbe < MIN_TBE) || (srv_p->
tbe > MAX_TBE))
401 if ((srv_p->
frtt < MIN_FRTT) || (srv_p->
frtt > MAX_FRTT))
403 if (srv_p->
nrm > MAX_NRM)
405 if (srv_p->
trm > MAX_TRM)
407 if (srv_p->
adtf > MAX_ADTF)
409 else if (srv_p->
adtf == 0)
411 if (srv_p->
cdf > MAX_CDF)
413 if (srv_p->
rif > MAX_RIF)
415 if (srv_p->
rdf > MAX_RDF)
419 f_abr_vc->f_vc_type =
ABR;
420 nrm = 2 << srv_p->
nrm;
422 f_abr_vc->f_nrm = nrm << 8 |
nrm;
423 trm = 100000/(2 << (16 - srv_p->
trm));
424 if ( trm == 0) trm = 1;
425 f_abr_vc->f_nrmexp =(((srv_p->
nrm +1) & 0x0f) << 12)|(
MRM << 8) |
trm;
427 if (crm == 0) crm = 1;
428 f_abr_vc->f_crm = crm & 0xff;
429 f_abr_vc->f_pcr = cellrate_to_float(srv_p->
pcr);
431 ((srv_p->
tbe/srv_p->
frtt)*1000000) :
432 (1000000/(srv_p->
frtt/srv_p->
tbe)));
433 f_abr_vc->f_icr = cellrate_to_float(icr);
434 adtf = (10000 * srv_p->
adtf)/8192;
435 if (adtf == 0) adtf = 1;
436 f_abr_vc->f_cdf = ((7 - srv_p->
cdf) << 12 | adtf) & 0xfff;
437 f_abr_vc->f_mcr = cellrate_to_float(srv_p->
mcr);
438 f_abr_vc->f_acr = f_abr_vc->f_icr;
439 f_abr_vc->f_status = 0x0042;
445 r_abr_vc += vcc->
vci;
447 air = srv_p->
pcr << (15 - srv_p->
rif);
448 if (air == 0) air = 1;
449 r_abr_vc->
r_air = cellrate_to_float(air);
459 static int ia_cbr_setup (
IADEV *dev,
struct atm_vcc *vcc) {
464 int idealSlot =0, testSlot, toBeAssigned,
inc;
466 u16 *SchedTbl, *TstSchedTbl;
473 if (vcc->
qos.txtp.max_pcr <= 0) {
477 rate = vcc->
qos.txtp.max_pcr;
479 IF_CBR(
printk(
"CBR: CBR entries=0x%x for rate=0x%x & Gran=0x%x\n",
483 rateLow = entries * dev->Granularity;
484 rateHigh = (entries + 1) * dev->Granularity;
485 if (3*(rate - rateLow) > (rateHigh - rate))
487 if (entries > dev->CbrRemEntries) {
488 IF_CBR(
printk(
"CBR: Not enough bandwidth to support this PCR.\n");)
489 IF_CBR(
printk(
"Entries = 0x%x, CbrRemEntries = 0x%x.\n",
496 dev->sum_mcr += entries * dev->Granularity;
501 spacing = dev->CbrTotEntries / entries;
502 sp_mod = dev->CbrTotEntries % entries;
503 toBeAssigned = entries;
506 IF_CBR(
printk("Vci=0
x%
x,Spacing=0x%x,Sp_mod=0x%x\n",vcIndex,spacing,sp_mod);)
511 if (toBeAssigned == entries)
518 idealSlot += (
u32)(spacing + fracSlot);
520 fracSlot = ((sp_mod + sp_mod2) / entries);
521 sp_mod2 = ((sp_mod + sp_mod2) % entries);
529 testSlot = idealSlot;
530 TstSchedTbl = (
u16*)(SchedTbl+testSlot);
531 IF_CBR(
printk(
"CBR Testslot 0x%x AT Location 0x%p, NumToAssign=%d\n",
532 testSlot, TstSchedTbl,toBeAssigned);)
537 testSlot = idealSlot -
inc;
540 IF_CBR(
printk(
"Testslot Wrap. STable Start=0x%p,Testslot=%d\n",
543 TstSchedTbl = (
u16 *)(SchedTbl + testSlot);
547 testSlot = idealSlot +
inc;
552 testSlot, toBeAssigned);)
555 TstSchedTbl = (
u16*)(SchedTbl + testSlot);
557 TstSchedTbl,cbrVC,inc);)
562 dev->CbrRemEntries--;
567 dev->NumEnabledCBR++;
568 if (dev->NumEnabledCBR == 1) {
574 static void ia_cbrVc_close (
struct atm_vcc *vcc) {
576 u16 *SchedTbl, NullVci = 0;
589 if (*SchedTbl == vcc->
vci) {
596 IF_CBR(
printk(
"Exit ia_cbrVc_close, NumRemoved=%d\n",NumFound);)
599 static int ia_avail_descs(
IADEV *iadev) {
606 iadev->
ffL.tcq_st) / 2;
612 static int ia_que_tx (
IADEV *iadev) {
616 num_desc = ia_avail_descs(iadev);
619 if (!(vcc =
ATM_SKB(skb)->vcc)) {
621 printk(
"ia_que_tx: Null vcc\n");
626 printk(
"Free the SKB on closed vci %d \n", vcc->
vci);
629 if (ia_pkt_tx (vcc, skb)) {
637 static void ia_tx_poll (
IADEV *iadev) {
640 struct ia_vcc *iavcc;
644 while ( (rtne = ia_deque_rtn_q(&iadev->
tx_return_q))) {
645 skb = rtne->
data.txskb;
647 printk(
"ia_tx_poll: skb is null\n");
652 printk(
"ia_tx_poll: vcc is null\n");
659 printk(
"ia_tx_poll: iavcc is null\n");
665 while (skb1 && (skb1 != skb)) {
667 printk(
"IA_tx_intr: Vci %d lost pkt!!!\n", vcc->
vci);
670 if ((vcc->
pop) && (skb1->len != 0))
682 ia_enque_head_rtn_q (&iadev->tx_return_q, rtne);
685 if ((vcc->
pop) && (skb->len != 0))
715 for (i=15; i>=0; i--) {
750 for (i=15; i>=0; i--) {
759 static void ia_hw_type(
IADEV *iadev) {
760 u_short memType = ia_eeprom_get(iadev, 25);
792 IF_INIT(
printk(
"BUF: tx=%d,sz=%d rx=%d sz= %d rx_pkt_ram=%d\n",
809 iadev->LineRate = (
u32)(((25600000/8)*26)/(27*53));
811 iadev->LineRate = (u32)(((44736000/8)*26)/(27*53));
813 iadev->LineRate = (u32)(((34368000/8)*26)/(27*53));
822 return readl(ia->phy + (reg >> 2));
825 static void ia_phy_write32(
struct iadev_priv *ia,
unsigned int reg,
u32 val)
830 static void ia_frontend_intr(
struct iadev_priv *iadev)
854 static void ia_mb25_init(
struct iadev_priv *iadev)
871 static void ia_phy_write(
struct iadev_priv *iadev,
875 ia_phy_write32(iadev, regs->
reg, regs->
val);
880 static void ia_suni_pm7345_init_ds3(
struct iadev_priv *iadev)
882 static const struct ia_reg suni_ds3_init [] = {
895 ia_phy_write(iadev, suni_ds3_init,
ARRAY_SIZE(suni_ds3_init));
898 static void ia_suni_pm7345_init_e3(
struct iadev_priv *iadev)
900 static const struct ia_reg suni_e3_init [] = {
915 ia_phy_write(iadev, suni_e3_init,
ARRAY_SIZE(suni_e3_init));
918 static void ia_suni_pm7345_init(
struct iadev_priv *iadev)
957 ia_suni_pm7345_init_ds3(iadev);
959 ia_suni_pm7345_init_e3(iadev);
961 ia_phy_write(iadev, suni_init,
ARRAY_SIZE(suni_init));
975 #ifdef CONFIG_ATM_IA_DEBUG
976 static int tcnter = 0;
983 while(count < length){
984 pBuf +=
sprintf( pBuf,
"%s", prefix );
985 for(col = 0;count + col < length && col < 16; col++){
986 if (col != 0 && (col % 4) == 0)
988 pBuf +=
sprintf( pBuf,
"%02X ", cp[count + col] );
996 for(col = 0;count + col < length && col < 16; col++){
997 if (
isprint((
int)cp[count + col]))
998 pBuf +=
sprintf( pBuf,
"%c", cp[count + col] );
1013 #define ACTUAL_RAM_BASE \
1014 RAM_BASE*((iadev->mem)/(128 * 1024))
1015 #define ACTUAL_SEG_RAM_BASE \
1016 IPHASE5575_FRAG_CONTROL_RAM_BASE*((iadev->mem)/(128 * 1024))
1017 #define ACTUAL_REASS_RAM_BASE \
1018 IPHASE5575_REASS_CONTROL_RAM_BASE*((iadev->mem)/(128 * 1024))
1023 static void desc_dbg(
IADEV *iadev) {
1025 u_short tcq_wr_ptr, tcq_st_ptr, tcq_ed_ptr;
1030 printk(
"B_tcq_wr = 0x%x desc = %d last desc = %d\n",
1037 printk(
"tcq_st_ptr = 0x%x tcq_ed_ptr = 0x%x \n", tcq_st_ptr, tcq_ed_ptr);
1039 while (tcq_st_ptr != tcq_ed_ptr) {
1040 tmp = iadev->
seg_ram+tcq_st_ptr;
1041 printk(
"TCQ slot %d desc = %d Addr = %p\n", i++,
readw(tmp), tmp);
1051 static void rx_excp_rcvd(
struct atm_dev *dev)
1062 {
printk(
"state = %x \n", state);
1064 printk(
"state = %x excpq_rd_ptr = %x \n", state, excpq_rd_ptr);
1080 static void free_desc(
struct atm_dev *dev,
int desc)
1085 iadev->
rfL.fdq_wr +=2;
1086 if (iadev->
rfL.fdq_wr > iadev->
rfL.fdq_ed)
1087 iadev->
rfL.fdq_wr = iadev->
rfL.fdq_st;
1092 static int rx_pkt(
struct atm_dev *dev)
1112 IF_RX(
printk(
"reass_ram = %p iadev->rfL.pcq_rd = 0x%x desc = %d\n",
1114 printk(
" pcq_wr_ptr = 0x%x\n",
1117 if ( iadev->
rfL.pcq_rd== iadev->
rfL.pcq_ed)
1118 iadev->
rfL.pcq_rd = iadev->
rfL.pcq_st;
1120 iadev->
rfL.pcq_rd += 2;
1128 buf_desc_ptr += desc;
1131 free_desc(dev, desc);
1132 IF_ERR(
printk(
"IA: bad descriptor desc = %d \n", desc);)
1138 free_desc(dev, desc);
1139 printk(
"IA: null vcc, drop PDU\n");
1153 else if (status &
RX_PTE) {
1177 printk(
"Drop control packets\n");
1195 if(++wr_ptr == iadev->
rx_dle_q.end)
1203 free_desc(dev, desc);
1207 static void rx_intr(
struct atm_dev *dev)
1244 printk(
"Test logic RUN!!!!\n");
1248 IF_EVENT(
printk(
"Rx intr status: RX_FREEQ_EMPT %08x\n", status);)
1269 static void rx_dle_intr(
struct atm_dev *dev)
1276 struct dle *
dle, *cur_dle;
1288 cur_dle = (
struct dle*)(iadev->
rx_dle_q.start + (dle_lp >> 4));
1289 while(dle != cur_dle)
1296 free_desc(dev, desc);
1298 if (!(len = skb->
len))
1300 printk(
"rx_dle_intr: skb len 0\n");
1307 struct ia_vcc *ia_vcc;
1309 pci_unmap_single(iadev->
pci, iadev->
rx_dle_q.write->sys_pkt_addr,
1314 printk(
"IA: null vcc\n");
1328 skb->
len -
sizeof(*trailer));
1330 if ((length > iadev->
rx_buf_sz) || (length >
1334 IF_ERR(
printk(
"rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
1336 atm_return(vcc, skb->truesize);
1344 xdump(skb->data, skb->len, "
RX: ");
1350 iadev->rx_pkt_cnt++;
1353 if (++dle == iadev->rx_dle_q.
end)
1354 dle = iadev->rx_dle_q.
start;
1356 iadev->rx_dle_q.
read = dle;
1360 if (!iadev->rxing) {
1364 writel(state & ~(RX_FREEQ_EMPT | RX_PKT_RCVD),
1372 static int open_rx(
struct atm_vcc *vcc)
1381 if (vcc->qos.rxtp.traffic_class ==
ATM_ABR) {
1383 printk(
"IA: ABR not support\n");
1390 vc_table += vcc->
vci;
1393 *vc_table = vcc->
vci << 6;
1396 if ((vcc->
qos.rxtp.traffic_class == ATM_ABR) ||
1397 (vcc->
qos.txtp.traffic_class == ATM_ABR))
1400 init_abr_vc(iadev, &srv_p);
1401 ia_open_abr_vc(iadev, &srv_p, vcc, 0);
1405 reass_ptr += vcc->
vci;
1411 vcc->
dev->number, vcc->
vci);
1416 static int rx_init(
struct atm_dev *dev)
1420 unsigned long rx_pkt_start = 0;
1425 int i,
j, vcsize_sel;
1439 iadev->
rx_dle_q.start = (
struct dle *)dle_addr;
1442 iadev->
rx_dle_q.end = (
struct dle*)((
unsigned long)dle_addr+
sizeof(
struct dle)*
DLE_ENTRIES);
1453 printk(
"Rx Dle list addr: 0x%p value: 0x%0x\n",
1480 iadev->RX_DESC_BASE_ADDR = iadev->reass_ram+RX_DESC_BASE*iadev->memSize;
1481 buf_desc_ptr = iadev->RX_DESC_BASE_ADDR;
1484 rx_pkt_start = iadev->rx_pkt_ram;
1485 for(i=1; i<=iadev->num_rx_desc; i++)
1487 memset_io(buf_desc_ptr, 0,
sizeof(*buf_desc_ptr));
1488 buf_desc_ptr->buf_start_hi = rx_pkt_start >> 16;
1489 buf_desc_ptr->buf_start_lo = rx_pkt_start & 0x0000ffff;
1493 IF_INIT(
printk(
"Rx Buffer desc ptr: 0x%p\n", buf_desc_ptr);)
1536 IF_INIT(
printk(
"INIT:pcq_st:0x%x pcq_ed:0x%x pcq_rd:0x%x pcq_wr:0x%x",
1537 iadev->
rfL.pcq_st, iadev->
rfL.pcq_ed, iadev->
rfL.pcq_rd,
1538 iadev->
rfL.pcq_wr);)
1551 reass_table = (
u16 *)(iadev->reass_ram+i);
1553 for(i=0; i < j; i++)
1557 while (i != iadev->num_vc) {
1565 for(i = 0; i <
j; i++)
1572 *vc_table = (i << 6) | 15;
1580 abr_vc_table = (
struct abr_vc_table *)(iadev->
reass_ram+i);
1582 memset ((
char*)abr_vc_table, 0, j *
sizeof(*abr_vc_table));
1583 for(i = 0; i <
j; i++) {
1584 abr_vc_table->
rdf = 0x0003;
1585 abr_vc_table->
air = 0x5eb1;
1602 i = (j >> 6) & 0xFF;
1604 i |= ((j << 2) & 0xFF00);
1615 writew(~(RX_FREEQ_EMPT|RX_PKT_RCVD), iadev->
reass_reg+REASS_MASK_REG);
1617 skb_queue_head_init(&iadev->
rx_dma_q);
1656 static void tx_intr(
struct atm_dev *dev)
1660 unsigned long flags;
1665 if (status & TRANSMIT_DONE){
1670 spin_unlock_irqrestore(&iadev->
tx_lock, flags);
1675 if (status & TCQ_NOT_EMPTY)
1681 static void tx_dle_intr(
struct atm_dev *dev)
1684 struct dle *dle, *cur_dle;
1687 struct ia_vcc *iavcc;
1689 unsigned long flags;
1696 cur_dle = (
struct dle*)(iadev->
tx_dle_q.start + (dle_lp >> 4));
1697 while (dle != cur_dle)
1704 if (!((dle - iadev->
tx_dle_q.start)%(2*
sizeof(
struct dle)))) {
1710 printk(
"tx_dle_intr: vcc is null\n");
1711 spin_unlock_irqrestore(&iadev->
tx_lock, flags);
1718 printk(
"tx_dle_intr: iavcc is null\n");
1719 spin_unlock_irqrestore(&iadev->
tx_lock, flags);
1724 if ((vcc->
pop) && (skb->
len != 0))
1738 dle = iadev->tx_dle_q.start;
1740 iadev->tx_dle_q.
read = dle;
1741 spin_unlock_irqrestore(&iadev->
tx_lock, flags);
1746 struct ia_vcc *ia_vcc;
1751 IF_EVENT(
printk(
"iadev: open_tx entered vcc->vci = %d\n", vcc->vci);)
1752 if (vcc->qos.txtp.traffic_class ==
ATM_NONE) return 0;
1756 if (vcc->qos.txtp.traffic_class == ATM_ABR) {
1757 printk(
"IA: ABR not support\n");
1760 if (vcc->qos.txtp.traffic_class ==
ATM_CBR) {
1761 printk(
"IA: CBR not support\n");
1767 if (vcc->qos.txtp.max_sdu >
1769 printk(
"IA: SDU size over (%d) the configured SDU size %d\n",
1770 vcc->qos.txtp.max_sdu,iadev->
tx_buf_sz);
1771 vcc->dev_data =
NULL;
1775 ia_vcc->vc_desc_cnt = 0;
1780 vcc->qos.txtp.pcr = iadev->
LineRate;
1781 else if ((vcc->qos.txtp.max_pcr == 0)&&( vcc->qos.txtp.pcr <= 0))
1782 vcc->qos.txtp.pcr = iadev->
LineRate;
1783 else if ((vcc->qos.txtp.max_pcr > vcc->qos.txtp.pcr) && (vcc->qos.txtp.max_pcr> 0))
1784 vcc->qos.txtp.pcr = vcc->qos.txtp.max_pcr;
1785 if (vcc->qos.txtp.pcr > iadev->
LineRate)
1786 vcc->qos.txtp.pcr = iadev->
LineRate;
1787 ia_vcc->pcr = vcc->qos.txtp.pcr;
1789 if (ia_vcc->pcr > (iadev->
LineRate / 6) ) ia_vcc->ltimeout =
HZ / 10;
1790 else if (ia_vcc->pcr > (iadev->
LineRate / 130)) ia_vcc->ltimeout =
HZ;
1791 else if (ia_vcc->pcr <= 170) ia_vcc->ltimeout = 16 *
HZ;
1792 else ia_vcc->ltimeout = 2700 *
HZ / ia_vcc->pcr;
1794 skb_queue_head_init (&ia_vcc->txing_skb);
1796 struct sock *
sk = sk_atm(vcc);
1798 if (vcc->qos.txtp.max_sdu != 0) {
1799 if (ia_vcc->pcr > 60000)
1800 sk->
sk_sndbuf = vcc->qos.txtp.max_sdu * 5;
1801 else if (ia_vcc->pcr > 2000)
1802 sk->
sk_sndbuf = vcc->qos.txtp.max_sdu * 4;
1804 sk->
sk_sndbuf = vcc->qos.txtp.max_sdu * 3;
1822 evc->atm_hdr1 = (vcc->vci >> 12) & 0x000f;
1823 evc->atm_hdr2 = (vcc->vci & 0x0fff) << 4;
1826 if (vcc->qos.txtp.traffic_class ==
ATM_UBR)
1830 vc->acr = cellrate_to_float(iadev->
LineRate);
1831 if (vcc->qos.txtp.pcr > 0)
1832 vc->acr = cellrate_to_float(vcc->qos.txtp.pcr);
1834 vcc->qos.txtp.max_pcr,vc->acr);)
1836 else if (vcc->qos.txtp.traffic_class == ATM_ABR)
1839 init_abr_vc(iadev, &srv_p);
1840 if (vcc->qos.txtp.pcr > 0)
1841 srv_p.
pcr = vcc->qos.txtp.pcr;
1842 if (vcc->qos.txtp.min_pcr > 0) {
1843 int tmpsum = iadev->
sum_mcr+iadev->
sum_cbr+vcc->qos.txtp.min_pcr;
1846 srv_p.
mcr = vcc->qos.txtp.min_pcr;
1847 iadev->
sum_mcr += vcc->qos.txtp.min_pcr;
1850 if (vcc->qos.txtp.icr)
1851 srv_p.
icr = vcc->qos.txtp.icr;
1852 if (vcc->qos.txtp.tbe)
1853 srv_p.
tbe = vcc->qos.txtp.tbe;
1854 if (vcc->qos.txtp.frtt)
1855 srv_p.
frtt = vcc->qos.txtp.frtt;
1856 if (vcc->qos.txtp.rif)
1857 srv_p.
rif = vcc->qos.txtp.rif;
1858 if (vcc->qos.txtp.rdf)
1859 srv_p.
rdf = vcc->qos.txtp.rdf;
1860 if (vcc->qos.txtp.nrm_pres)
1861 srv_p.
nrm = vcc->qos.txtp.nrm;
1862 if (vcc->qos.txtp.trm_pres)
1863 srv_p.
trm = vcc->qos.txtp.trm;
1864 if (vcc->qos.txtp.adtf_pres)
1865 srv_p.
adtf = vcc->qos.txtp.adtf;
1866 if (vcc->qos.txtp.cdf_pres)
1867 srv_p.
cdf = vcc->qos.txtp.cdf;
1868 if (srv_p.
icr > srv_p.
pcr)
1870 IF_ABR(
printk(
"ABR:vcc->qos.txtp.max_pcr = %d mcr = %d\n",
1872 ia_open_abr_vc(iadev, &srv_p, vcc, 1);
1874 if (iadev->phy_type & FE_25MBIT_PHY) {
1875 printk(
"IA: CBR not support\n");
1878 if (vcc->qos.txtp.max_pcr > iadev->LineRate) {
1884 if ((ret = ia_cbr_setup (iadev, vcc)) < 0) {
1889 printk(
"iadev: Non UBR, ABR and CBR traffic not supportedn");
1891 iadev->testTable[vcc->vci]->vc_status |=
VC_ACTIVE;
1897 static int tx_init(
struct atm_dev *dev)
1901 unsigned int tx_pkt_start;
1921 &iadev->tx_dle_dma);
1926 iadev->
tx_dle_q.start = (
struct dle*)dle_addr;
1929 iadev->
tx_dle_q.end = (
struct dle*)((
unsigned long)dle_addr+
sizeof(
struct dle)*
DLE_ENTRIES);
1971 buf_desc_ptr->desc_mode =
AAL5;
1972 buf_desc_ptr->buf_start_hi = tx_pkt_start >> 16;
1973 buf_desc_ptr->buf_start_lo = tx_pkt_start & 0x0000ffff;
1989 goto err_free_tx_bufs;
1992 iadev->
tx_buf[
i].dma_addr = pci_map_single(iadev->
pci,
1999 goto err_free_all_tx_bufs;
2063 readw(iadev->seg_reg+CBR_TAB_BEG));)
2066 writew(tmp16, iadev->seg_reg+CBR_TAB_END);
2069 IF_INIT(
printk("CBR_TAB_BEG = 0x%x, CBR_TAB_END = 0x%x, CBR_PTR = 0x%x\n",
2070 readw(iadev->seg_reg+CBR_TAB_BEG),
readw(iadev->seg_reg+CBR_TAB_END),
2071 readw(iadev->seg_reg+CBR_TAB_END+1));)
2075 0, iadev->num_vc*6);
2076 iadev->CbrRemEntries = iadev->CbrTotEntries = iadev->num_vc*3;
2077 iadev->CbrEntryPt = 0;
2078 iadev->Granularity =
MAX_ATM_155 / iadev->CbrTotEntries;
2079 iadev->NumEnabledCBR = 0;
2092 while (i != iadev->num_vc) {
2126 printk(
"Get freepage failed\n");
2127 goto err_free_desc_tbl;
2129 for(i=0; i<iadev->
num_vc; i++)
2136 goto err_free_test_tables;
2147 if (iadev->
phy_type & FE_25MBIT_PHY) {
2165 skb_queue_head_init(&iadev->tx_dma_q);
2182 writew(~(TRANSMIT_DONE | TCQ_NOT_EMPTY), iadev->
seg_reg+SEG_MASK_REG);
2189 err_free_test_tables:
2195 err_free_all_tx_bufs:
2252 ia_frontend_intr(iadev);
2261 static int get_esi(
struct atm_dev *dev)
2274 dev->
esi[i] = mac1 >>(8*(MAC1_LEN-1-i));
2277 dev->
esi[i+MAC1_LEN] = mac2 >>(8*(MAC2_LEN - 1 -i));
2281 static int reset_sar(
struct atm_dev *dev)
2285 unsigned int pci[64];
2289 if ((error = pci_read_config_dword(iadev->
pci,
2294 if ((error = pci_write_config_dword(iadev->
pci,
2305 unsigned long real_base;
2320 iadev->
irq = iadev->
pci->irq;
2329 dev->
number, iadev->
pci->revision, real_base, iadev->
irq);)
2335 if (iadev->pci_map_size == 0x100000){
2359 base =
ioremap(real_base,iadev->pci_map_size);
2371 iadev->
mem = iadev->pci_map_size /2;
2372 iadev->real_base = real_base;
2383 iadev->
dma = base + PHY_BASE;
2391 iadev->
reg,iadev->seg_reg,iadev->reass_reg,
2392 iadev->
phy, iadev->ram, iadev->seg_ram,
2396 error = get_esi(dev);
2403 printk(
"%s%02X",i ?
"-" :
"",dev->
esi[i]);
2407 if (reset_sar(dev)) {
2409 printk(
"IA: reset SAR fail, please try again\n");
2415 static void ia_update_stats(
IADEV *iadev) {
2427 static void ia_led_timer(
unsigned long arg) {
2428 unsigned long flags;
2429 static u_char blinking[8] = {0, 0, 0, 0, 0, 0, 0, 0};
2432 for (i = 0; i < iadev_count; i++) {
2435 if (blinking[i] == 0) {
2439 ia_update_stats(ia_dev[i]);
2446 if (ia_dev[i]->close_pending)
2447 wake_up(&ia_dev[i]->close_wait);
2448 ia_tx_poll(ia_dev[i]);
2449 spin_unlock_irqrestore(&ia_dev[i]->tx_lock, flags);
2457 static void ia_phy_put(
struct atm_dev *dev,
unsigned char value,
2463 static unsigned char ia_phy_get(
struct atm_dev *dev,
unsigned long addr)
2468 static void ia_free_tx(
IADEV *iadev)
2473 for (i = 0; i < iadev->
num_vc; i++)
2488 static void ia_free_rx(
IADEV *iadev)
2511 if ((error = pci_write_config_word(iadev->
pci,
2516 "master (0x%x)\n",dev->
number, error);
2543 writel(ctrl_reg, iadev->
reg+IPHASE5575_BUS_CONTROL_REG);
2546 readl(iadev->
reg+IPHASE5575_BUS_CONTROL_REG));
2551 error = tx_init(dev);
2554 error = rx_init(dev);
2558 ctrl_reg =
readl(iadev->
reg+IPHASE5575_BUS_CONTROL_REG);
2561 readl(iadev->
reg+IPHASE5575_BUS_CONTROL_REG));)
2564 if ((phy=ia_phy_get(dev,0)) == 0x30)
2569 if (iadev->phy_type & FE_25MBIT_PHY)
2570 ia_mb25_init(iadev);
2572 ia_suni_pm7345_init(iadev);
2577 if (dev->phy->start) {
2578 error = dev->phy->start(dev);
2583 ia_frontend_intr(iadev);
2597 static void ia_close(
struct atm_vcc *vcc)
2602 struct ia_vcc *ia_vcc;
2605 unsigned long closetime,
flags;
2609 if (!ia_vcc)
return;
2614 skb_queue_head_init (&tmp_tx_backlog);
2615 skb_queue_head_init (&tmp_vcc_backlog);
2616 if (vcc->qos.txtp.traffic_class !=
ATM_NONE) {
2623 if (
ATM_SKB(skb)->vcc == vcc){
2624 if (vcc->
pop) vcc->
pop(vcc, skb);
2633 closetime = 300000 / ia_vcc->pcr;
2636 spin_unlock_irqrestore(&iadev->tx_lock, flags);
2639 iadev->close_pending--;
2640 iadev->testTable[vcc->vci]->lastTime = 0;
2641 iadev->testTable[vcc->vci]->fract = 0;
2642 iadev->testTable[vcc->vci]->vc_status =
VC_UBR;
2643 if (vcc->qos.txtp.traffic_class == ATM_ABR) {
2644 if (vcc->
qos.txtp.min_pcr > 0)
2647 if (vcc->
qos.txtp.traffic_class == ATM_CBR) {
2650 ia_cbrVc_close (vcc);
2652 spin_unlock_irqrestore(&iadev->
tx_lock, flags);
2655 if (vcc->
qos.rxtp.traffic_class != ATM_NONE) {
2658 vc_table += vcc->
vci;
2662 vc_table += vcc->
vci;
2663 *vc_table = (vcc->
vci << 6) | 15;
2664 if (vcc->
qos.rxtp.traffic_class == ATM_ABR) {
2665 struct abr_vc_table
__iomem *abr_vc_table =
2667 abr_vc_table += vcc->
vci;
2668 abr_vc_table->
rdf = 0x0003;
2669 abr_vc_table->
air = 0x5eb1;
2672 rx_dle_intr(vcc->
dev);
2682 static int ia_open(
struct atm_vcc *vcc)
2684 struct ia_vcc *ia_vcc;
2706 if ((error = open_rx(vcc)))
2713 if ((error = open_tx(vcc)))
2720 set_bit(ATM_VF_READY,&vcc->flags);
2736 static int ia_change_qos(
struct atm_vcc *vcc,
struct atm_qos *qos,
int flags)
2742 static int ia_ioctl(
struct atm_dev *dev,
unsigned int cmd,
void __user *arg)
2751 return dev->
phy->ioctl(dev,cmd,arg);
2755 if ((board < 0) || (board > iadev_count))
2757 iadev = ia_dev[board];
2758 switch (ia_cmds.
cmd) {
2771 for(i=0; i<0x80; i+=2, tmps++)
2779 for(i=0; i<0x80; i+=2, tmps++)
2791 regs_local =
kmalloc(
sizeof(*regs_local), GFP_KERNEL);
2792 if (!regs_local)
return -
ENOMEM;
2793 ffL = ®s_local->
ffredn;
2794 rfL = ®s_local->
rfredn;
2796 for (i=0; i<(
sizeof (
rfredn_t))/4; i++)
2799 for (i=0; i<(
sizeof (
ffredn_t))/4; i++)
2807 printk(
"Board %d registers dumped\n", board);
2828 stats = &
PRIV(_ia_dev[board])->sonet_stats;
2844 free_desc(_ia_dev[board], i);
2845 writew( ~(RX_FREEQ_EMPT | RX_EXCP_RCVD),
2854 ia_frontend_intr(iadev);
2860 IADebugFlag = ia_cmds.
maddr;
2861 printk(
"New debug option loaded\n");
2877 static int ia_getsockopt(
struct atm_vcc *vcc,
int level,
int optname,
2878 void __user *optval,
int optlen)
2884 static int ia_setsockopt(
struct atm_vcc *vcc,
int level,
int optname,
2885 void __user *optval,
unsigned int optlen)
2891 static int ia_pkt_tx (
struct atm_vcc *vcc,
struct sk_buff *skb) {
2899 struct ia_vcc *iavcc;
2903 if (!iavcc->
txing) {
2904 printk(
"discard packet on closed VC\n");
2913 printk(
"Transmit size over tx buffer size\n");
2920 if ((
unsigned long)skb->
data & 3) {
2921 printk(
"Misaligned SKB\n");
2933 desc = get_desc (iadev, iavcc);
2936 comp_code = desc >> 13;
2958 iadev->
desc_tbl[desc-1].iavcc = iavcc;
2959 iadev->
desc_tbl[desc-1].txskb = skb;
2962 iadev->
ffL.tcq_rd += 2;
2963 if (iadev->
ffL.tcq_rd > iadev->
ffL.tcq_ed)
2964 iadev->
ffL.tcq_rd = iadev->
ffL.tcq_st;
2972 iadev->
ffL.prq_wr += 2;
2973 if (iadev->
ffL.prq_wr > iadev->
ffL.prq_ed)
2974 iadev->
ffL.prq_wr = iadev->
ffL.prq_st;
2979 total_len = ((total_len + 47) / 48) * 48;
2980 IF_TX(
printk(
"ia packet len:%d padding:%d\n", total_len, total_len - skb->
len);)
2983 trailer = iadev->
tx_buf[desc-1].cpcs;
2984 IF_TX(
printk("Sent: skb = 0x%p skb->data: 0x%p len: %
d, desc: %d\n",
2985 skb, skb->data, skb->len, desc);)
2988 trailer->length = ((skb->len & 0xff) << 8) | ((skb->len & 0xff00) >> 8);
2993 skb->len, tcnter++);
2994 xdump(skb->data, skb->len, "
TX: ");
2999 buf_desc_ptr += desc;
3002 writew(TRANSMIT_DONE, iadev->seg_reg+SEG_INTR_STATUS_REG);
3003 buf_desc_ptr->vc_index = vcc->vci;
3004 buf_desc_ptr->
bytes = total_len;
3006 if (vcc->qos.txtp.traffic_class == ATM_ABR)
3007 clear_lockup (vcc, iadev);
3010 wr_ptr = iadev->tx_dle_q.
write;
3012 wr_ptr->sys_pkt_addr = pci_map_single(iadev->pci, skb->data,
3014 wr_ptr->local_pkt_addr = (buf_desc_ptr->buf_start_hi << 16) |
3015 buf_desc_ptr->buf_start_lo;
3017 wr_ptr->
bytes = skb->len;
3021 wr_ptr->
bytes = 0x30;
3024 wr_ptr->prq_wr_ptr_data = 0;
3027 if (++wr_ptr == iadev->tx_dle_q.
end)
3028 wr_ptr = iadev->tx_dle_q.start;
3031 wr_ptr->sys_pkt_addr = iadev->
tx_buf[desc-1].dma_addr;
3032 wr_ptr->local_pkt_addr = ((buf_desc_ptr->buf_start_hi << 16) |
3037 wr_ptr->prq_wr_ptr_data = iadev->ffL.prq_wr;
3040 if (++wr_ptr == iadev->tx_dle_q.
end)
3041 wr_ptr = iadev->tx_dle_q.start;
3043 iadev->tx_dle_q.write = wr_ptr;
3048 iadev->tx_pkt_cnt++;
3056 vcc->tx_quota = vcc->tx_quota * 3 / 4;
3057 printk(
"Tx1: vcc->tx_quota = %d \n", (
u32)vcc->tx_quota );
3062 printk(
"Tx2: vcc->tx_quota = %d \n", (
u32)vcc->tx_quota );
3074 unsigned long flags;
3077 if ((!skb)||(skb->
len>(iadev->
tx_buf_sz-
sizeof(
struct cpcs_trailer))))
3087 spin_unlock_irqrestore(&iadev->
tx_lock, flags);
3096 if (ia_pkt_tx (vcc, skb)) {
3100 spin_unlock_irqrestore(&iadev->
tx_lock, flags);
3105 static int ia_proc_read(
struct atm_dev *dev,loff_t *
pos,
char *
page)
3111 if (iadev->
phy_type == FE_25MBIT_PHY) {
3112 n =
sprintf(page,
" Board Type : Iphase5525-1KVC-128K\n");
3116 n =
sprintf(page,
" Board Type : Iphase-ATM-DS3");
3118 n =
sprintf(page,
" Board Type : Iphase-ATM-E3");
3120 n =
sprintf(page,
" Board Type : Iphase-ATM-UTP155");
3122 n =
sprintf(page,
" Board Type : Iphase-ATM-OC3");
3125 n +=
sprintf(tmpPtr,
"-1KVC-");
3127 n +=
sprintf(tmpPtr,
"-4KVC-");
3130 n +=
sprintf(tmpPtr,
"1M \n");
3132 n +=
sprintf(tmpPtr,
"512K\n");
3134 n +=
sprintf(tmpPtr,
"128K\n");
3138 return sprintf(page,
" Number of Tx Buffer: %u\n"
3139 " Size of Tx Buffer : %u\n"
3140 " Number of Rx Buffer: %u\n"
3141 " Size of Rx Buffer : %u\n"
3142 " Packets Receiverd : %u\n"
3143 " Packets Transmitted: %u\n"
3144 " Cells Received : %u\n"
3145 " Cells Transmitted : %u\n"
3146 " Board Dropped Cells: %u\n"
3147 " Board Dropped Pkts : %u\n",
3161 .getsockopt = ia_getsockopt,
3162 .setsockopt = ia_setsockopt,
3164 .phy_put = ia_phy_put,
3165 .phy_get = ia_phy_get,
3166 .change_qos = ia_change_qos,
3167 .proc_read = ia_proc_read,
3178 iadev = kzalloc(
sizeof(*iadev), GFP_KERNEL);
3186 IF_INIT(
printk(
"ia detected at bus:%d dev: %d function:%d\n",
3190 goto err_out_free_iadev;
3195 goto err_out_disable_dev;
3199 IF_INIT(
printk("dev_id = 0x%p iadev->LineRate = %d \n", dev,
3202 pci_set_drvdata(pdev, dev);
3204 ia_dev[iadev_count] = iadev;
3205 _ia_dev[iadev_count] = dev;
3207 if (ia_init(dev) || ia_start(dev)) {
3210 ia_dev[iadev_count] =
NULL;
3211 _ia_dev[iadev_count] =
NULL;
3213 goto err_out_deregister_dev;
3217 iadev->next_board = ia_boards;
3222 err_out_deregister_dev:
3224 err_out_disable_dev:
3234 struct atm_dev *dev = pci_get_drvdata(pdev);
3242 if (dev->
phy && dev->
phy->stop)
3243 dev->
phy->stop(dev);
3248 ia_dev[iadev_count] =
NULL;
3249 _ia_dev[iadev_count] =
NULL;
3271 .id_table = ia_pci_tbl,
3272 .probe = ia_init_one,
3276 static int __init ia_module_init(
void)
3280 ret = pci_register_driver(&ia_driver);
3289 static void __exit ia_module_exit(
void)