1 /******************************************************************************
2 iphase.c: Device driver for Interphase ATM PCI adapter cards
3 Author: Peter Wang <pwang@iphase.com>
4 Some fixes: Arnaldo Carvalho de Melo <acme@conectiva.com.br>
5 Interphase Corporation <www.iphase.com>
7 *******************************************************************************
9 This software may be used and distributed according to the terms
10 of the GNU General Public License (GPL), incorporated herein by reference.
11 Drivers based on this skeleton fall under the GPL and must retain
12 the authorship (implicit copyright) notice.
14 This program is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 Modified from an incomplete driver for Interphase 5575 1KVC 1M card which
20 was originally written by Monalisa Agrawal at UNH. Now this driver
21 supports a variety of varients of Interphase ATM PCI (i)Chip adapter
22 card family (See www.iphase.com/products/ClassSheet.cfm?ClassID=ATM)
23 in terms of PHY type, the size of control memory and the size of
24 packet memory. The followings are the change log and history:
26 Bugfix the Mona's UBR driver.
27 Modify the basic memory allocation and dma logic.
28 Port the driver to the latest kernel from 2.0.46.
29 Complete the ABR logic of the driver, and added the ABR work-
30 around for the hardware anormalies.
32 Add the flow control logic to the driver to allow rate-limit VC.
33 Add 4K VC support to the board with 512K control memory.
34 Add the support of all the variants of the Interphase ATM PCI
35 (i)Chip adapter cards including x575 (155M OC3 and UTP155), x525
36 (25M UTP25) and x531 (DS3 and E3).
39 Support and updates available at: ftp://ftp.iphase.com/pub/atm
41 *******************************************************************************/
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>
51 #include <linux/skbuff.h>
52 #include <linux/time.h>
53 #include <linux/delay.h>
54 #include <linux/uio.h>
55 #include <linux/init.h>
56 #include <linux/interrupt.h>
57 #include <linux/wait.h>
58 #include <linux/slab.h>
60 #include <linux/atomic.h>
61 #include <asm/uaccess.h>
62 #include <asm/string.h>
63 #include <asm/byteorder.h>
64 #include <linux/vmalloc.h>
65 #include <linux/jiffies.h>
66 #include <linux/nospec.h>
69 #define swap_byte_order(x) (((x & 0xff) << 8) | ((x & 0xff00) >> 8))
71 #define PRIV(dev) ((struct suni_priv *) dev->phy_data)
73 static unsigned char ia_phy_get(struct atm_dev *dev, unsigned long addr);
74 static void desc_dbg(IADEV *iadev);
76 static IADEV *ia_dev[8];
77 static struct atm_dev *_ia_dev[8];
78 static int iadev_count;
79 static void ia_led_timer(unsigned long arg);
80 static DEFINE_TIMER(ia_timer, ia_led_timer, 0, 0);
81 static int IA_TX_BUF = DFL_TX_BUFFERS, IA_TX_BUF_SZ = DFL_TX_BUF_SZ;
82 static int IA_RX_BUF = DFL_RX_BUFFERS, IA_RX_BUF_SZ = DFL_RX_BUF_SZ;
83 static uint IADebugFlag = /* IF_IADBG_ERR | IF_IADBG_CBR| IF_IADBG_INIT_ADAPTER
84 |IF_IADBG_ABR | IF_IADBG_EVENT*/ 0;
86 module_param(IA_TX_BUF, int, 0);
87 module_param(IA_TX_BUF_SZ, int, 0);
88 module_param(IA_RX_BUF, int, 0);
89 module_param(IA_RX_BUF_SZ, int, 0);
90 module_param(IADebugFlag, uint, 0644);
92 MODULE_LICENSE("GPL");
94 /**************************** IA_LIB **********************************/
96 static void ia_init_rtn_q (IARTN_Q *que)
102 static void ia_enque_head_rtn_q (IARTN_Q *que, IARTN_Q * data)
105 if (que->next == NULL)
106 que->next = que->tail = data;
108 data->next = que->next;
114 static int ia_enque_rtn_q (IARTN_Q *que, struct desc_tbl_t data) {
115 IARTN_Q *entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
120 if (que->next == NULL)
121 que->next = que->tail = entry;
123 que->tail->next = entry;
124 que->tail = que->tail->next;
129 static IARTN_Q * ia_deque_rtn_q (IARTN_Q *que) {
131 if (que->next == NULL)
134 if ( que->next == que->tail)
135 que->next = que->tail = NULL;
137 que->next = que->next->next;
141 static void ia_hack_tcq(IADEV *dev) {
145 struct ia_vcc *iavcc_r = NULL;
147 tcq_wr = readl(dev->seg_reg+TCQ_WR_PTR) & 0xffff;
148 while (dev->host_tcq_wr != tcq_wr) {
149 desc1 = *(u_short *)(dev->seg_ram + dev->host_tcq_wr);
151 else if (!dev->desc_tbl[desc1 -1].timestamp) {
152 IF_ABR(printk(" Desc %d is reset at %ld\n", desc1 -1, jiffies);)
153 *(u_short *) (dev->seg_ram + dev->host_tcq_wr) = 0;
155 else if (dev->desc_tbl[desc1 -1].timestamp) {
156 if (!(iavcc_r = dev->desc_tbl[desc1 -1].iavcc)) {
157 printk("IA: Fatal err in get_desc\n");
160 iavcc_r->vc_desc_cnt--;
161 dev->desc_tbl[desc1 -1].timestamp = 0;
162 IF_EVENT(printk("ia_hack: return_q skb = 0x%p desc = %d\n",
163 dev->desc_tbl[desc1 -1].txskb, desc1);)
164 if (iavcc_r->pcr < dev->rate_limit) {
165 IA_SKB_STATE (dev->desc_tbl[desc1-1].txskb) |= IA_TX_DONE;
166 if (ia_enque_rtn_q(&dev->tx_return_q, dev->desc_tbl[desc1 -1]) < 0)
167 printk("ia_hack_tcq: No memory available\n");
169 dev->desc_tbl[desc1 -1].iavcc = NULL;
170 dev->desc_tbl[desc1 -1].txskb = NULL;
172 dev->host_tcq_wr += 2;
173 if (dev->host_tcq_wr > dev->ffL.tcq_ed)
174 dev->host_tcq_wr = dev->ffL.tcq_st;
178 static u16 get_desc (IADEV *dev, struct ia_vcc *iavcc) {
181 struct ia_vcc *iavcc_r = NULL;
183 static unsigned long timer = 0;
187 if((time_after(jiffies,timer+50)) || ((dev->ffL.tcq_rd==dev->host_tcq_wr))) {
190 while (i < dev->num_tx_desc) {
191 if (!dev->desc_tbl[i].timestamp) {
195 ltimeout = dev->desc_tbl[i].iavcc->ltimeout;
196 delta = jiffies - dev->desc_tbl[i].timestamp;
197 if (delta >= ltimeout) {
198 IF_ABR(printk("RECOVER run!! desc_tbl %d = %d delta = %ld, time = %ld\n", i,dev->desc_tbl[i].timestamp, delta, jiffies);)
199 if (dev->ffL.tcq_rd == dev->ffL.tcq_st)
200 dev->ffL.tcq_rd = dev->ffL.tcq_ed;
202 dev->ffL.tcq_rd -= 2;
203 *(u_short *)(dev->seg_ram + dev->ffL.tcq_rd) = i+1;
204 if (!(skb = dev->desc_tbl[i].txskb) ||
205 !(iavcc_r = dev->desc_tbl[i].iavcc))
206 printk("Fatal err, desc table vcc or skb is NULL\n");
208 iavcc_r->vc_desc_cnt--;
209 dev->desc_tbl[i].timestamp = 0;
210 dev->desc_tbl[i].iavcc = NULL;
211 dev->desc_tbl[i].txskb = NULL;
216 if (dev->ffL.tcq_rd == dev->host_tcq_wr)
219 /* Get the next available descriptor number from TCQ */
220 desc_num = *(u_short *)(dev->seg_ram + dev->ffL.tcq_rd);
222 while (!desc_num || (dev->desc_tbl[desc_num -1]).timestamp) {
223 dev->ffL.tcq_rd += 2;
224 if (dev->ffL.tcq_rd > dev->ffL.tcq_ed)
225 dev->ffL.tcq_rd = dev->ffL.tcq_st;
226 if (dev->ffL.tcq_rd == dev->host_tcq_wr)
228 desc_num = *(u_short *)(dev->seg_ram + dev->ffL.tcq_rd);
231 /* get system time */
232 dev->desc_tbl[desc_num -1].timestamp = jiffies;
236 static void clear_lockup (struct atm_vcc *vcc, IADEV *dev) {
238 vcstatus_t *vcstatus;
240 u_short tempCellSlot, tempFract;
241 struct main_vc *abr_vc = (struct main_vc *)dev->MAIN_VC_TABLE_ADDR;
242 struct ext_vc *eabr_vc = (struct ext_vc *)dev->EXT_VC_TABLE_ADDR;
245 if (vcc->qos.txtp.traffic_class == ATM_ABR) {
246 vcstatus = (vcstatus_t *) &(dev->testTable[vcc->vci]->vc_status);
249 if( vcstatus->cnt == 0x05 ) {
252 if( eabr_vc->last_desc ) {
253 if( (abr_vc->status & 0x07) == ABR_STATE /* 0x2 */ ) {
254 /* Wait for 10 Micro sec */
256 if ((eabr_vc->last_desc)&&((abr_vc->status & 0x07)==ABR_STATE))
260 tempCellSlot = abr_vc->last_cell_slot;
261 tempFract = abr_vc->fraction;
262 if((tempCellSlot == dev->testTable[vcc->vci]->lastTime)
263 && (tempFract == dev->testTable[vcc->vci]->fract))
265 dev->testTable[vcc->vci]->lastTime = tempCellSlot;
266 dev->testTable[vcc->vci]->fract = tempFract;
268 } /* last descriptor */
270 } /* vcstatus->cnt */
273 IF_ABR(printk("LOCK UP found\n");)
274 writew(0xFFFD, dev->seg_reg+MODE_REG_0);
275 /* Wait for 10 Micro sec */
277 abr_vc->status &= 0xFFF8;
278 abr_vc->status |= 0x0001; /* state is idle */
279 shd_tbl = (u_short *)dev->ABR_SCHED_TABLE_ADDR;
280 for( i = 0; ((i < dev->num_vc) && (shd_tbl[i])); i++ );
282 shd_tbl[i] = vcc->vci;
284 IF_ERR(printk("ABR Seg. may not continue on VC %x\n",vcc->vci);)
285 writew(T_ONLINE, dev->seg_reg+MODE_REG_0);
286 writew(~(TRANSMIT_DONE|TCQ_NOT_EMPTY), dev->seg_reg+SEG_MASK_REG);
287 writew(TRANSMIT_DONE, dev->seg_reg+SEG_INTR_STATUS_REG);
297 ** Conversion of 24-bit cellrate (cells/sec) to 16-bit floating point format.
299 ** +----+----+------------------+-------------------------------+
300 ** | R | NZ | 5-bit exponent | 9-bit mantissa |
301 ** +----+----+------------------+-------------------------------+
303 ** R = reserved (written as 0)
304 ** NZ = 0 if 0 cells/sec; 1 otherwise
306 ** if NZ = 1, rate = 1.mmmmmmmmm x 2^(eeeee) cells/sec
309 cellrate_to_float(u32 cr)
313 #define M_BITS 9 /* Number of bits in mantissa */
314 #define E_BITS 5 /* Number of bits in exponent */
318 u32 tmp = cr & 0x00ffffff;
327 flot = NZ | (i << M_BITS) | (cr & M_MASK);
329 flot = NZ | (i << M_BITS) | ((cr << (M_BITS - i)) & M_MASK);
331 flot = NZ | (i << M_BITS) | ((cr >> (i - M_BITS)) & M_MASK);
337 ** Conversion of 16-bit floating point format to 24-bit cellrate (cells/sec).
340 float_to_cellrate(u16 rate)
342 u32 exp, mantissa, cps;
343 if ((rate & NZ) == 0)
345 exp = (rate >> M_BITS) & E_MASK;
346 mantissa = rate & M_MASK;
349 cps = (1 << M_BITS) | mantissa;
352 else if (exp > M_BITS)
353 cps <<= (exp - M_BITS);
355 cps >>= (M_BITS - exp);
360 static void init_abr_vc (IADEV *dev, srv_cls_param_t *srv_p) {
361 srv_p->class_type = ATM_ABR;
362 srv_p->pcr = dev->LineRate;
364 srv_p->icr = 0x055cb7;
365 srv_p->tbe = 0xffffff;
376 ia_open_abr_vc(IADEV *dev, srv_cls_param_t *srv_p,
377 struct atm_vcc *vcc, u8 flag)
379 f_vc_abr_entry *f_abr_vc;
380 r_vc_abr_entry *r_abr_vc;
383 u16 adtf, air, *ptr16;
384 f_abr_vc =(f_vc_abr_entry *)dev->MAIN_VC_TABLE_ADDR;
385 f_abr_vc += vcc->vci;
387 case 1: /* FFRED initialization */
388 #if 0 /* sanity check */
391 if (srv_p->pcr > dev->LineRate)
392 srv_p->pcr = dev->LineRate;
393 if ((srv_p->mcr + dev->sum_mcr) > dev->LineRate)
394 return MCR_UNAVAILABLE;
395 if (srv_p->mcr > srv_p->pcr)
398 srv_p->icr = srv_p->pcr;
399 if ((srv_p->icr < srv_p->mcr) || (srv_p->icr > srv_p->pcr))
401 if ((srv_p->tbe < MIN_TBE) || (srv_p->tbe > MAX_TBE))
403 if ((srv_p->frtt < MIN_FRTT) || (srv_p->frtt > MAX_FRTT))
405 if (srv_p->nrm > MAX_NRM)
407 if (srv_p->trm > MAX_TRM)
409 if (srv_p->adtf > MAX_ADTF)
411 else if (srv_p->adtf == 0)
413 if (srv_p->cdf > MAX_CDF)
415 if (srv_p->rif > MAX_RIF)
417 if (srv_p->rdf > MAX_RDF)
420 memset ((caddr_t)f_abr_vc, 0, sizeof(*f_abr_vc));
421 f_abr_vc->f_vc_type = ABR;
422 nrm = 2 << srv_p->nrm; /* (2 ** (srv_p->nrm +1)) */
423 /* i.e 2**n = 2 << (n-1) */
424 f_abr_vc->f_nrm = nrm << 8 | nrm;
425 trm = 100000/(2 << (16 - srv_p->trm));
426 if ( trm == 0) trm = 1;
427 f_abr_vc->f_nrmexp =(((srv_p->nrm +1) & 0x0f) << 12)|(MRM << 8) | trm;
428 crm = srv_p->tbe / nrm;
429 if (crm == 0) crm = 1;
430 f_abr_vc->f_crm = crm & 0xff;
431 f_abr_vc->f_pcr = cellrate_to_float(srv_p->pcr);
432 icr = min( srv_p->icr, (srv_p->tbe > srv_p->frtt) ?
433 ((srv_p->tbe/srv_p->frtt)*1000000) :
434 (1000000/(srv_p->frtt/srv_p->tbe)));
435 f_abr_vc->f_icr = cellrate_to_float(icr);
436 adtf = (10000 * srv_p->adtf)/8192;
437 if (adtf == 0) adtf = 1;
438 f_abr_vc->f_cdf = ((7 - srv_p->cdf) << 12 | adtf) & 0xfff;
439 f_abr_vc->f_mcr = cellrate_to_float(srv_p->mcr);
440 f_abr_vc->f_acr = f_abr_vc->f_icr;
441 f_abr_vc->f_status = 0x0042;
443 case 0: /* RFRED initialization */
444 ptr16 = (u_short *)(dev->reass_ram + REASS_TABLE*dev->memSize);
445 *(ptr16 + vcc->vci) = NO_AAL5_PKT | REASS_ABR;
446 r_abr_vc = (r_vc_abr_entry*)(dev->reass_ram+ABR_VC_TABLE*dev->memSize);
447 r_abr_vc += vcc->vci;
448 r_abr_vc->r_status_rdf = (15 - srv_p->rdf) & 0x000f;
449 air = srv_p->pcr << (15 - srv_p->rif);
450 if (air == 0) air = 1;
451 r_abr_vc->r_air = cellrate_to_float(air);
452 dev->testTable[vcc->vci]->vc_status = VC_ACTIVE | VC_ABR;
453 dev->sum_mcr += srv_p->mcr;
461 static int ia_cbr_setup (IADEV *dev, struct atm_vcc *vcc) {
462 u32 rateLow=0, rateHigh, rate;
464 struct ia_vcc *ia_vcc;
466 int idealSlot =0, testSlot, toBeAssigned, inc;
468 u16 *SchedTbl, *TstSchedTbl;
474 /* IpAdjustTrafficParams */
475 if (vcc->qos.txtp.max_pcr <= 0) {
476 IF_ERR(printk("PCR for CBR not defined\n");)
479 rate = vcc->qos.txtp.max_pcr;
480 entries = rate / dev->Granularity;
481 IF_CBR(printk("CBR: CBR entries=0x%x for rate=0x%x & Gran=0x%x\n",
482 entries, rate, dev->Granularity);)
484 IF_CBR(printk("CBR: Bandwidth smaller than granularity of CBR table\n");)
485 rateLow = entries * dev->Granularity;
486 rateHigh = (entries + 1) * dev->Granularity;
487 if (3*(rate - rateLow) > (rateHigh - rate))
489 if (entries > dev->CbrRemEntries) {
490 IF_CBR(printk("CBR: Not enough bandwidth to support this PCR.\n");)
491 IF_CBR(printk("Entries = 0x%x, CbrRemEntries = 0x%x.\n",
492 entries, dev->CbrRemEntries);)
496 ia_vcc = INPH_IA_VCC(vcc);
497 ia_vcc->NumCbrEntry = entries;
498 dev->sum_mcr += entries * dev->Granularity;
499 /* IaFFrednInsertCbrSched */
500 // Starting at an arbitrary location, place the entries into the table
501 // as smoothly as possible
503 spacing = dev->CbrTotEntries / entries;
504 sp_mod = dev->CbrTotEntries % entries; // get modulo
505 toBeAssigned = entries;
508 IF_CBR(printk("Vci=0x%x,Spacing=0x%x,Sp_mod=0x%x\n",vcIndex,spacing,sp_mod);)
511 // If this is the first time, start the table loading for this connection
512 // as close to entryPoint as possible.
513 if (toBeAssigned == entries)
515 idealSlot = dev->CbrEntryPt;
516 dev->CbrEntryPt += 2; // Adding 2 helps to prevent clumping
517 if (dev->CbrEntryPt >= dev->CbrTotEntries)
518 dev->CbrEntryPt -= dev->CbrTotEntries;// Wrap if necessary
520 idealSlot += (u32)(spacing + fracSlot); // Point to the next location
521 // in the table that would be smoothest
522 fracSlot = ((sp_mod + sp_mod2) / entries); // get new integer part
523 sp_mod2 = ((sp_mod + sp_mod2) % entries); // calc new fractional part
525 if (idealSlot >= (int)dev->CbrTotEntries)
526 idealSlot -= dev->CbrTotEntries;
527 // Continuously check around this ideal value until a null
528 // location is encountered.
529 SchedTbl = (u16*)(dev->seg_ram+CBR_SCHED_TABLE*dev->memSize);
531 testSlot = idealSlot;
532 TstSchedTbl = (u16*)(SchedTbl+testSlot); //set index and read in value
533 IF_CBR(printk("CBR Testslot 0x%x AT Location 0x%p, NumToAssign=%d\n",
534 testSlot, TstSchedTbl,toBeAssigned);)
535 memcpy((caddr_t)&cbrVC,(caddr_t)TstSchedTbl,sizeof(cbrVC));
536 while (cbrVC) // If another VC at this location, we have to keep looking
539 testSlot = idealSlot - inc;
540 if (testSlot < 0) { // Wrap if necessary
541 testSlot += dev->CbrTotEntries;
542 IF_CBR(printk("Testslot Wrap. STable Start=0x%p,Testslot=%d\n",
545 TstSchedTbl = (u16 *)(SchedTbl + testSlot); // set table index
546 memcpy((caddr_t)&cbrVC,(caddr_t)TstSchedTbl,sizeof(cbrVC));
549 testSlot = idealSlot + inc;
550 if (testSlot >= (int)dev->CbrTotEntries) { // Wrap if necessary
551 testSlot -= dev->CbrTotEntries;
552 IF_CBR(printk("TotCbrEntries=%d",dev->CbrTotEntries);)
553 IF_CBR(printk(" Testslot=0x%x ToBeAssgned=%d\n",
554 testSlot, toBeAssigned);)
556 // set table index and read in value
557 TstSchedTbl = (u16*)(SchedTbl + testSlot);
558 IF_CBR(printk("Reading CBR Tbl from 0x%p, CbrVal=0x%x Iteration %d\n",
559 TstSchedTbl,cbrVC,inc);)
560 memcpy((caddr_t)&cbrVC,(caddr_t)TstSchedTbl,sizeof(cbrVC));
562 // Move this VCI number into this location of the CBR Sched table.
563 memcpy((caddr_t)TstSchedTbl, (caddr_t)&vcIndex, sizeof(*TstSchedTbl));
564 dev->CbrRemEntries--;
568 /* IaFFrednCbrEnable */
569 dev->NumEnabledCBR++;
570 if (dev->NumEnabledCBR == 1) {
571 writew((CBR_EN | UBR_EN | ABR_EN | (0x23 << 2)), dev->seg_reg+STPARMS);
572 IF_CBR(printk("CBR is enabled\n");)
576 static void ia_cbrVc_close (struct atm_vcc *vcc) {
578 u16 *SchedTbl, NullVci = 0;
581 iadev = INPH_IA_DEV(vcc->dev);
582 iadev->NumEnabledCBR--;
583 SchedTbl = (u16*)(iadev->seg_ram+CBR_SCHED_TABLE*iadev->memSize);
584 if (iadev->NumEnabledCBR == 0) {
585 writew((UBR_EN | ABR_EN | (0x23 << 2)), iadev->seg_reg+STPARMS);
586 IF_CBR (printk("CBR support disabled\n");)
589 for (i=0; i < iadev->CbrTotEntries; i++)
591 if (*SchedTbl == vcc->vci) {
592 iadev->CbrRemEntries++;
598 IF_CBR(printk("Exit ia_cbrVc_close, NumRemoved=%d\n",NumFound);)
601 static int ia_avail_descs(IADEV *iadev) {
604 if (iadev->host_tcq_wr >= iadev->ffL.tcq_rd)
605 tmp = (iadev->host_tcq_wr - iadev->ffL.tcq_rd) / 2;
607 tmp = (iadev->ffL.tcq_ed - iadev->ffL.tcq_rd + 2 + iadev->host_tcq_wr -
608 iadev->ffL.tcq_st) / 2;
612 static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb);
614 static int ia_que_tx (IADEV *iadev) {
618 num_desc = ia_avail_descs(iadev);
620 while (num_desc && (skb = skb_dequeue(&iadev->tx_backlog))) {
621 if (!(vcc = ATM_SKB(skb)->vcc)) {
622 dev_kfree_skb_any(skb);
623 printk("ia_que_tx: Null vcc\n");
626 if (!test_bit(ATM_VF_READY,&vcc->flags)) {
627 dev_kfree_skb_any(skb);
628 printk("Free the SKB on closed vci %d \n", vcc->vci);
631 if (ia_pkt_tx (vcc, skb)) {
632 skb_queue_head(&iadev->tx_backlog, skb);
639 static void ia_tx_poll (IADEV *iadev) {
640 struct atm_vcc *vcc = NULL;
641 struct sk_buff *skb = NULL, *skb1 = NULL;
642 struct ia_vcc *iavcc;
646 while ( (rtne = ia_deque_rtn_q(&iadev->tx_return_q))) {
647 skb = rtne->data.txskb;
649 printk("ia_tx_poll: skb is null\n");
652 vcc = ATM_SKB(skb)->vcc;
654 printk("ia_tx_poll: vcc is null\n");
655 dev_kfree_skb_any(skb);
659 iavcc = INPH_IA_VCC(vcc);
661 printk("ia_tx_poll: iavcc is null\n");
662 dev_kfree_skb_any(skb);
666 skb1 = skb_dequeue(&iavcc->txing_skb);
667 while (skb1 && (skb1 != skb)) {
668 if (!(IA_SKB_STATE(skb1) & IA_TX_DONE)) {
669 printk("IA_tx_intr: Vci %d lost pkt!!!\n", vcc->vci);
671 IF_ERR(printk("Release the SKB not match\n");)
672 if ((vcc->pop) && (skb1->len != 0))
675 IF_EVENT(printk("Tansmit Done - skb 0x%lx return\n",
679 dev_kfree_skb_any(skb1);
680 skb1 = skb_dequeue(&iavcc->txing_skb);
683 IF_EVENT(printk("IA: Vci %d - skb not found requed\n",vcc->vci);)
684 ia_enque_head_rtn_q (&iadev->tx_return_q, rtne);
687 if ((vcc->pop) && (skb->len != 0))
690 IF_EVENT(printk("Tx Done - skb 0x%lx return\n",(long)skb);)
693 dev_kfree_skb_any(skb);
701 static void ia_eeprom_put (IADEV *iadev, u32 addr, u_short val)
706 * Issue a command to enable writes to the NOVRAM
708 NVRAM_CMD (EXTEND + EWEN);
711 * issue the write command
713 NVRAM_CMD(IAWRITE + addr);
715 * Send the data, starting with D15, then D14, and so on for 16 bits
717 for (i=15; i>=0; i--) {
718 NVRAM_CLKOUT (val & 0x8000);
723 t = readl(iadev->reg+IPHASE5575_EEPROM_ACCESS);
725 t = readl(iadev->reg+IPHASE5575_EEPROM_ACCESS);
729 * disable writes again
731 NVRAM_CMD(EXTEND + EWDS)
737 static u16 ia_eeprom_get (IADEV *iadev, u32 addr)
743 * Read the first bit that was clocked with the falling edge of the
744 * the last command data clock
746 NVRAM_CMD(IAREAD + addr);
748 * Now read the rest of the bits, the next bit read is D14, then D13,
752 for (i=15; i>=0; i--) {
761 static void ia_hw_type(IADEV *iadev) {
762 u_short memType = ia_eeprom_get(iadev, 25);
763 iadev->memType = memType;
764 if ((memType & MEM_SIZE_MASK) == MEM_SIZE_1M) {
765 iadev->num_tx_desc = IA_TX_BUF;
766 iadev->tx_buf_sz = IA_TX_BUF_SZ;
767 iadev->num_rx_desc = IA_RX_BUF;
768 iadev->rx_buf_sz = IA_RX_BUF_SZ;
769 } else if ((memType & MEM_SIZE_MASK) == MEM_SIZE_512K) {
770 if (IA_TX_BUF == DFL_TX_BUFFERS)
771 iadev->num_tx_desc = IA_TX_BUF / 2;
773 iadev->num_tx_desc = IA_TX_BUF;
774 iadev->tx_buf_sz = IA_TX_BUF_SZ;
775 if (IA_RX_BUF == DFL_RX_BUFFERS)
776 iadev->num_rx_desc = IA_RX_BUF / 2;
778 iadev->num_rx_desc = IA_RX_BUF;
779 iadev->rx_buf_sz = IA_RX_BUF_SZ;
782 if (IA_TX_BUF == DFL_TX_BUFFERS)
783 iadev->num_tx_desc = IA_TX_BUF / 8;
785 iadev->num_tx_desc = IA_TX_BUF;
786 iadev->tx_buf_sz = IA_TX_BUF_SZ;
787 if (IA_RX_BUF == DFL_RX_BUFFERS)
788 iadev->num_rx_desc = IA_RX_BUF / 8;
790 iadev->num_rx_desc = IA_RX_BUF;
791 iadev->rx_buf_sz = IA_RX_BUF_SZ;
793 iadev->rx_pkt_ram = TX_PACKET_RAM + (iadev->num_tx_desc * iadev->tx_buf_sz);
794 IF_INIT(printk("BUF: tx=%d,sz=%d rx=%d sz= %d rx_pkt_ram=%d\n",
795 iadev->num_tx_desc, iadev->tx_buf_sz, iadev->num_rx_desc,
796 iadev->rx_buf_sz, iadev->rx_pkt_ram);)
799 if ((memType & FE_MASK) == FE_SINGLE_MODE) {
800 iadev->phy_type = PHY_OC3C_S;
801 else if ((memType & FE_MASK) == FE_UTP_OPTION)
802 iadev->phy_type = PHY_UTP155;
804 iadev->phy_type = PHY_OC3C_M;
807 iadev->phy_type = memType & FE_MASK;
808 IF_INIT(printk("memType = 0x%x iadev->phy_type = 0x%x\n",
809 memType,iadev->phy_type);)
810 if (iadev->phy_type == FE_25MBIT_PHY)
811 iadev->LineRate = (u32)(((25600000/8)*26)/(27*53));
812 else if (iadev->phy_type == FE_DS3_PHY)
813 iadev->LineRate = (u32)(((44736000/8)*26)/(27*53));
814 else if (iadev->phy_type == FE_E3_PHY)
815 iadev->LineRate = (u32)(((34368000/8)*26)/(27*53));
817 iadev->LineRate = (u32)(ATM_OC3_PCR);
818 IF_INIT(printk("iadev->LineRate = %d \n", iadev->LineRate);)
822 static u32 ia_phy_read32(struct iadev_priv *ia, unsigned int reg)
824 return readl(ia->phy + (reg >> 2));
827 static void ia_phy_write32(struct iadev_priv *ia, unsigned int reg, u32 val)
829 writel(val, ia->phy + (reg >> 2));
832 static void ia_frontend_intr(struct iadev_priv *iadev)
836 if (iadev->phy_type & FE_25MBIT_PHY) {
837 status = ia_phy_read32(iadev, MB25_INTR_STATUS);
838 iadev->carrier_detect = (status & MB25_IS_GSB) ? 1 : 0;
839 } else if (iadev->phy_type & FE_DS3_PHY) {
840 ia_phy_read32(iadev, SUNI_DS3_FRM_INTR_STAT);
841 status = ia_phy_read32(iadev, SUNI_DS3_FRM_STAT);
842 iadev->carrier_detect = (status & SUNI_DS3_LOSV) ? 0 : 1;
843 } else if (iadev->phy_type & FE_E3_PHY) {
844 ia_phy_read32(iadev, SUNI_E3_FRM_MAINT_INTR_IND);
845 status = ia_phy_read32(iadev, SUNI_E3_FRM_FRAM_INTR_IND_STAT);
846 iadev->carrier_detect = (status & SUNI_E3_LOS) ? 0 : 1;
848 status = ia_phy_read32(iadev, SUNI_RSOP_STATUS);
849 iadev->carrier_detect = (status & SUNI_LOSV) ? 0 : 1;
852 printk(KERN_INFO "IA: SUNI carrier %s\n",
853 iadev->carrier_detect ? "detected" : "lost signal");
856 static void ia_mb25_init(struct iadev_priv *iadev)
859 mb25->mb25_master_ctrl = MB25_MC_DRIC | MB25_MC_DREC | MB25_MC_ENABLED;
861 ia_phy_write32(iadev, MB25_MASTER_CTRL, MB25_MC_DRIC | MB25_MC_DREC);
862 ia_phy_write32(iadev, MB25_DIAG_CONTROL, 0);
864 iadev->carrier_detect =
865 (ia_phy_read32(iadev, MB25_INTR_STATUS) & MB25_IS_GSB) ? 1 : 0;
873 static void ia_phy_write(struct iadev_priv *iadev,
874 const struct ia_reg *regs, int len)
877 ia_phy_write32(iadev, regs->reg, regs->val);
882 static void ia_suni_pm7345_init_ds3(struct iadev_priv *iadev)
884 static const struct ia_reg suni_ds3_init [] = {
885 { SUNI_DS3_FRM_INTR_ENBL, 0x17 },
886 { SUNI_DS3_FRM_CFG, 0x01 },
887 { SUNI_DS3_TRAN_CFG, 0x01 },
889 { SUNI_SPLR_CFG, 0 },
894 status = ia_phy_read32(iadev, SUNI_DS3_FRM_STAT);
895 iadev->carrier_detect = (status & SUNI_DS3_LOSV) ? 0 : 1;
897 ia_phy_write(iadev, suni_ds3_init, ARRAY_SIZE(suni_ds3_init));
900 static void ia_suni_pm7345_init_e3(struct iadev_priv *iadev)
902 static const struct ia_reg suni_e3_init [] = {
903 { SUNI_E3_FRM_FRAM_OPTIONS, 0x04 },
904 { SUNI_E3_FRM_MAINT_OPTIONS, 0x20 },
905 { SUNI_E3_FRM_FRAM_INTR_ENBL, 0x1d },
906 { SUNI_E3_FRM_MAINT_INTR_ENBL, 0x30 },
907 { SUNI_E3_TRAN_STAT_DIAG_OPTIONS, 0 },
908 { SUNI_E3_TRAN_FRAM_OPTIONS, 0x01 },
909 { SUNI_CONFIG, SUNI_PM7345_E3ENBL },
910 { SUNI_SPLR_CFG, 0x41 },
911 { SUNI_SPLT_CFG, 0x41 }
915 status = ia_phy_read32(iadev, SUNI_E3_FRM_FRAM_INTR_IND_STAT);
916 iadev->carrier_detect = (status & SUNI_E3_LOS) ? 0 : 1;
917 ia_phy_write(iadev, suni_e3_init, ARRAY_SIZE(suni_e3_init));
920 static void ia_suni_pm7345_init(struct iadev_priv *iadev)
922 static const struct ia_reg suni_init [] = {
923 /* Enable RSOP loss of signal interrupt. */
924 { SUNI_INTR_ENBL, 0x28 },
925 /* Clear error counters. */
926 { SUNI_ID_RESET, 0 },
927 /* Clear "PMCTST" in master test register. */
928 { SUNI_MASTER_TEST, 0 },
930 { SUNI_RXCP_CTRL, 0x2c },
931 { SUNI_RXCP_FCTRL, 0x81 },
933 { SUNI_RXCP_IDLE_PAT_H1, 0 },
934 { SUNI_RXCP_IDLE_PAT_H2, 0 },
935 { SUNI_RXCP_IDLE_PAT_H3, 0 },
936 { SUNI_RXCP_IDLE_PAT_H4, 0x01 },
938 { SUNI_RXCP_IDLE_MASK_H1, 0xff },
939 { SUNI_RXCP_IDLE_MASK_H2, 0xff },
940 { SUNI_RXCP_IDLE_MASK_H3, 0xff },
941 { SUNI_RXCP_IDLE_MASK_H4, 0xfe },
943 { SUNI_RXCP_CELL_PAT_H1, 0 },
944 { SUNI_RXCP_CELL_PAT_H2, 0 },
945 { SUNI_RXCP_CELL_PAT_H3, 0 },
946 { SUNI_RXCP_CELL_PAT_H4, 0x01 },
948 { SUNI_RXCP_CELL_MASK_H1, 0xff },
949 { SUNI_RXCP_CELL_MASK_H2, 0xff },
950 { SUNI_RXCP_CELL_MASK_H3, 0xff },
951 { SUNI_RXCP_CELL_MASK_H4, 0xff },
953 { SUNI_TXCP_CTRL, 0xa4 },
954 { SUNI_TXCP_INTR_EN_STS, 0x10 },
955 { SUNI_TXCP_IDLE_PAT_H5, 0x55 }
958 if (iadev->phy_type & FE_DS3_PHY)
959 ia_suni_pm7345_init_ds3(iadev);
961 ia_suni_pm7345_init_e3(iadev);
963 ia_phy_write(iadev, suni_init, ARRAY_SIZE(suni_init));
965 ia_phy_write32(iadev, SUNI_CONFIG, ia_phy_read32(iadev, SUNI_CONFIG) &
966 ~(SUNI_PM7345_LLB | SUNI_PM7345_CLB |
967 SUNI_PM7345_DLB | SUNI_PM7345_PLB));
969 suni_pm7345->suni_rxcp_intr_en_sts |= SUNI_OOCDE;
970 #endif /* __SNMP__ */
975 /***************************** IA_LIB END *****************************/
977 #ifdef CONFIG_ATM_IA_DEBUG
978 static int tcnter = 0;
979 static void xdump( u_char* cp, int length, char* prefix )
983 u_char* pBuf = prntBuf;
985 while(count < length){
986 pBuf += sprintf( pBuf, "%s", prefix );
987 for(col = 0;count + col < length && col < 16; col++){
988 if (col != 0 && (col % 4) == 0)
989 pBuf += sprintf( pBuf, " " );
990 pBuf += sprintf( pBuf, "%02X ", cp[count + col] );
992 while(col++ < 16){ /* pad end of buffer with blanks */
994 sprintf( pBuf, " " );
995 pBuf += sprintf( pBuf, " " );
997 pBuf += sprintf( pBuf, " " );
998 for(col = 0;count + col < length && col < 16; col++){
999 if (isprint((int)cp[count + col]))
1000 pBuf += sprintf( pBuf, "%c", cp[count + col] );
1002 pBuf += sprintf( pBuf, "." );
1004 printk("%s\n", prntBuf);
1009 } /* close xdump(... */
1010 #endif /* CONFIG_ATM_IA_DEBUG */
1013 static struct atm_dev *ia_boards = NULL;
1015 #define ACTUAL_RAM_BASE \
1016 RAM_BASE*((iadev->mem)/(128 * 1024))
1017 #define ACTUAL_SEG_RAM_BASE \
1018 IPHASE5575_FRAG_CONTROL_RAM_BASE*((iadev->mem)/(128 * 1024))
1019 #define ACTUAL_REASS_RAM_BASE \
1020 IPHASE5575_REASS_CONTROL_RAM_BASE*((iadev->mem)/(128 * 1024))
1023 /*-- some utilities and memory allocation stuff will come here -------------*/
1025 static void desc_dbg(IADEV *iadev) {
1027 u_short tcq_wr_ptr, tcq_st_ptr, tcq_ed_ptr;
1030 // regval = readl((u32)ia_cmds->maddr);
1031 tcq_wr_ptr = readw(iadev->seg_reg+TCQ_WR_PTR);
1032 printk("B_tcq_wr = 0x%x desc = %d last desc = %d\n",
1033 tcq_wr_ptr, readw(iadev->seg_ram+tcq_wr_ptr),
1034 readw(iadev->seg_ram+tcq_wr_ptr-2));
1035 printk(" host_tcq_wr = 0x%x host_tcq_rd = 0x%x \n", iadev->host_tcq_wr,
1037 tcq_st_ptr = readw(iadev->seg_reg+TCQ_ST_ADR);
1038 tcq_ed_ptr = readw(iadev->seg_reg+TCQ_ED_ADR);
1039 printk("tcq_st_ptr = 0x%x tcq_ed_ptr = 0x%x \n", tcq_st_ptr, tcq_ed_ptr);
1041 while (tcq_st_ptr != tcq_ed_ptr) {
1042 tmp = iadev->seg_ram+tcq_st_ptr;
1043 printk("TCQ slot %d desc = %d Addr = %p\n", i++, readw(tmp), tmp);
1046 for(i=0; i <iadev->num_tx_desc; i++)
1047 printk("Desc_tbl[%d] = %d \n", i, iadev->desc_tbl[i].timestamp);
1051 /*----------------------------- Receiving side stuff --------------------------*/
1053 static void rx_excp_rcvd(struct atm_dev *dev)
1055 #if 0 /* closing the receiving size will cause too many excp int */
1058 u_short excpq_rd_ptr;
1061 iadev = INPH_IA_DEV(dev);
1062 state = readl(iadev->reass_reg + STATE_REG) & 0xffff;
1063 while((state & EXCPQ_EMPTY) != EXCPQ_EMPTY)
1064 { printk("state = %x \n", state);
1065 excpq_rd_ptr = readw(iadev->reass_reg + EXCP_Q_RD_PTR) & 0xffff;
1066 printk("state = %x excpq_rd_ptr = %x \n", state, excpq_rd_ptr);
1067 if (excpq_rd_ptr == *(u16*)(iadev->reass_reg + EXCP_Q_WR_PTR))
1068 IF_ERR(printk("excpq_rd_ptr is wrong!!!\n");)
1069 // TODO: update exception stat
1070 vci = readw(iadev->reass_ram+excpq_rd_ptr);
1071 error = readw(iadev->reass_ram+excpq_rd_ptr+2) & 0x0007;
1074 if (excpq_rd_ptr > (readw(iadev->reass_reg + EXCP_Q_ED_ADR)& 0xffff))
1075 excpq_rd_ptr = readw(iadev->reass_reg + EXCP_Q_ST_ADR)& 0xffff;
1076 writew( excpq_rd_ptr, iadev->reass_reg + EXCP_Q_RD_PTR);
1077 state = readl(iadev->reass_reg + STATE_REG) & 0xffff;
1082 static void free_desc(struct atm_dev *dev, int desc)
1085 iadev = INPH_IA_DEV(dev);
1086 writew(desc, iadev->reass_ram+iadev->rfL.fdq_wr);
1087 iadev->rfL.fdq_wr +=2;
1088 if (iadev->rfL.fdq_wr > iadev->rfL.fdq_ed)
1089 iadev->rfL.fdq_wr = iadev->rfL.fdq_st;
1090 writew(iadev->rfL.fdq_wr, iadev->reass_reg+FREEQ_WR_PTR);
1094 static int rx_pkt(struct atm_dev *dev)
1097 struct atm_vcc *vcc;
1098 unsigned short status;
1099 struct rx_buf_desc __iomem *buf_desc_ptr;
1103 struct sk_buff *skb;
1104 u_int buf_addr, dma_addr;
1106 iadev = INPH_IA_DEV(dev);
1107 if (iadev->rfL.pcq_rd == (readw(iadev->reass_reg+PCQ_WR_PTR)&0xffff))
1109 printk(KERN_ERR DEV_LABEL "(itf %d) Receive queue empty\n", dev->number);
1112 /* mask 1st 3 bits to get the actual descno. */
1113 desc = readw(iadev->reass_ram+iadev->rfL.pcq_rd) & 0x1fff;
1114 IF_RX(printk("reass_ram = %p iadev->rfL.pcq_rd = 0x%x desc = %d\n",
1115 iadev->reass_ram, iadev->rfL.pcq_rd, desc);
1116 printk(" pcq_wr_ptr = 0x%x\n",
1117 readw(iadev->reass_reg+PCQ_WR_PTR)&0xffff);)
1118 /* update the read pointer - maybe we shud do this in the end*/
1119 if ( iadev->rfL.pcq_rd== iadev->rfL.pcq_ed)
1120 iadev->rfL.pcq_rd = iadev->rfL.pcq_st;
1122 iadev->rfL.pcq_rd += 2;
1123 writew(iadev->rfL.pcq_rd, iadev->reass_reg+PCQ_RD_PTR);
1125 /* get the buffer desc entry.
1126 update stuff. - doesn't seem to be any update necessary
1128 buf_desc_ptr = iadev->RX_DESC_BASE_ADDR;
1129 /* make the ptr point to the corresponding buffer desc entry */
1130 buf_desc_ptr += desc;
1131 if (!desc || (desc > iadev->num_rx_desc) ||
1132 ((buf_desc_ptr->vc_index & 0xffff) > iadev->num_vc)) {
1133 free_desc(dev, desc);
1134 IF_ERR(printk("IA: bad descriptor desc = %d \n", desc);)
1137 vcc = iadev->rx_open[buf_desc_ptr->vc_index & 0xffff];
1140 free_desc(dev, desc);
1141 printk("IA: null vcc, drop PDU\n");
1146 /* might want to check the status bits for errors */
1147 status = (u_short) (buf_desc_ptr->desc_mode);
1148 if (status & (RX_CER | RX_PTE | RX_OFL))
1150 atomic_inc(&vcc->stats->rx_err);
1151 IF_ERR(printk("IA: bad packet, dropping it");)
1152 if (status & RX_CER) {
1153 IF_ERR(printk(" cause: packet CRC error\n");)
1155 else if (status & RX_PTE) {
1156 IF_ERR(printk(" cause: packet time out\n");)
1159 IF_ERR(printk(" cause: buffer overflow\n");)
1168 buf_addr = (buf_desc_ptr->buf_start_hi << 16) | buf_desc_ptr->buf_start_lo;
1169 dma_addr = (buf_desc_ptr->dma_start_hi << 16) | buf_desc_ptr->dma_start_lo;
1170 len = dma_addr - buf_addr;
1171 if (len > iadev->rx_buf_sz) {
1172 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
1173 atomic_inc(&vcc->stats->rx_err);
1177 if (!(skb = atm_alloc_charge(vcc, len, GFP_ATOMIC))) {
1179 printk("Drop control packets\n");
1184 ATM_SKB(skb)->vcc = vcc;
1185 ATM_DESC(skb) = desc;
1186 skb_queue_tail(&iadev->rx_dma_q, skb);
1188 /* Build the DLE structure */
1189 wr_ptr = iadev->rx_dle_q.write;
1190 wr_ptr->sys_pkt_addr = dma_map_single(&iadev->pci->dev, skb->data,
1191 len, DMA_FROM_DEVICE);
1192 wr_ptr->local_pkt_addr = buf_addr;
1193 wr_ptr->bytes = len; /* We don't know this do we ?? */
1194 wr_ptr->mode = DMA_INT_ENABLE;
1196 /* shud take care of wrap around here too. */
1197 if(++wr_ptr == iadev->rx_dle_q.end)
1198 wr_ptr = iadev->rx_dle_q.start;
1199 iadev->rx_dle_q.write = wr_ptr;
1201 /* Increment transaction counter */
1202 writel(1, iadev->dma+IPHASE5575_RX_COUNTER);
1205 free_desc(dev, desc);
1209 static void rx_intr(struct atm_dev *dev)
1215 iadev = INPH_IA_DEV(dev);
1216 status = readl(iadev->reass_reg+REASS_INTR_STATUS_REG) & 0xffff;
1217 IF_EVENT(printk("rx_intr: status = 0x%x\n", status);)
1218 if (status & RX_PKT_RCVD)
1221 /* Basically recvd an interrupt for receiving a packet.
1222 A descriptor would have been written to the packet complete
1223 queue. Get all the descriptors and set up dma to move the
1224 packets till the packet complete queue is empty..
1226 state = readl(iadev->reass_reg + STATE_REG) & 0xffff;
1227 IF_EVENT(printk("Rx intr status: RX_PKT_RCVD %08x\n", status);)
1228 while(!(state & PCQ_EMPTY))
1231 state = readl(iadev->reass_reg + STATE_REG) & 0xffff;
1235 if (status & RX_FREEQ_EMPT)
1238 iadev->rx_tmp_cnt = iadev->rx_pkt_cnt;
1239 iadev->rx_tmp_jif = jiffies;
1242 else if ((time_after(jiffies, iadev->rx_tmp_jif + 50)) &&
1243 ((iadev->rx_pkt_cnt - iadev->rx_tmp_cnt) == 0)) {
1244 for (i = 1; i <= iadev->num_rx_desc; i++)
1246 printk("Test logic RUN!!!!\n");
1247 writew( ~(RX_FREEQ_EMPT|RX_EXCP_RCVD),iadev->reass_reg+REASS_MASK_REG);
1250 IF_EVENT(printk("Rx intr status: RX_FREEQ_EMPT %08x\n", status);)
1253 if (status & RX_EXCP_RCVD)
1255 /* probably need to handle the exception queue also. */
1256 IF_EVENT(printk("Rx intr status: RX_EXCP_RCVD %08x\n", status);)
1261 if (status & RX_RAW_RCVD)
1263 /* need to handle the raw incoming cells. This deepnds on
1264 whether we have programmed to receive the raw cells or not.
1266 IF_EVENT(printk("Rx intr status: RX_RAW_RCVD %08x\n", status);)
1271 static void rx_dle_intr(struct atm_dev *dev)
1274 struct atm_vcc *vcc;
1275 struct sk_buff *skb;
1278 struct dle *dle, *cur_dle;
1281 iadev = INPH_IA_DEV(dev);
1283 /* free all the dles done, that is just update our own dle read pointer
1284 - do we really need to do this. Think not. */
1285 /* DMA is done, just get all the recevie buffers from the rx dma queue
1286 and push them up to the higher layer protocol. Also free the desc
1287 associated with the buffer. */
1288 dle = iadev->rx_dle_q.read;
1289 dle_lp = readl(iadev->dma+IPHASE5575_RX_LIST_ADDR) & (sizeof(struct dle)*DLE_ENTRIES - 1);
1290 cur_dle = (struct dle*)(iadev->rx_dle_q.start + (dle_lp >> 4));
1291 while(dle != cur_dle)
1293 /* free the DMAed skb */
1294 skb = skb_dequeue(&iadev->rx_dma_q);
1297 desc = ATM_DESC(skb);
1298 free_desc(dev, desc);
1300 if (!(len = skb->len))
1302 printk("rx_dle_intr: skb len 0\n");
1303 dev_kfree_skb_any(skb);
1307 struct cpcs_trailer *trailer;
1309 struct ia_vcc *ia_vcc;
1311 dma_unmap_single(&iadev->pci->dev, iadev->rx_dle_q.write->sys_pkt_addr,
1312 len, DMA_FROM_DEVICE);
1313 /* no VCC related housekeeping done as yet. lets see */
1314 vcc = ATM_SKB(skb)->vcc;
1316 printk("IA: null vcc\n");
1317 dev_kfree_skb_any(skb);
1320 ia_vcc = INPH_IA_VCC(vcc);
1323 atomic_inc(&vcc->stats->rx_err);
1324 atm_return(vcc, skb->truesize);
1325 dev_kfree_skb_any(skb);
1328 // get real pkt length pwang_test
1329 trailer = (struct cpcs_trailer*)((u_char *)skb->data +
1330 skb->len - sizeof(*trailer));
1331 length = swap_byte_order(trailer->length);
1332 if ((length > iadev->rx_buf_sz) || (length >
1333 (skb->len - sizeof(struct cpcs_trailer))))
1335 atomic_inc(&vcc->stats->rx_err);
1336 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
1338 atm_return(vcc, skb->truesize);
1339 dev_kfree_skb_any(skb);
1342 skb_trim(skb, length);
1344 /* Display the packet */
1345 IF_RXPKT(printk("\nDmad Recvd data: len = %d \n", skb->len);
1346 xdump(skb->data, skb->len, "RX: ");
1349 IF_RX(printk("rx_dle_intr: skb push");)
1351 atomic_inc(&vcc->stats->rx);
1352 iadev->rx_pkt_cnt++;
1355 if (++dle == iadev->rx_dle_q.end)
1356 dle = iadev->rx_dle_q.start;
1358 iadev->rx_dle_q.read = dle;
1360 /* if the interrupts are masked because there were no free desc available,
1362 if (!iadev->rxing) {
1363 state = readl(iadev->reass_reg + STATE_REG) & 0xffff;
1364 if (!(state & FREEQ_EMPTY)) {
1365 state = readl(iadev->reass_reg + REASS_MASK_REG) & 0xffff;
1366 writel(state & ~(RX_FREEQ_EMPT |/* RX_EXCP_RCVD |*/ RX_PKT_RCVD),
1367 iadev->reass_reg+REASS_MASK_REG);
1374 static int open_rx(struct atm_vcc *vcc)
1377 u_short __iomem *vc_table;
1378 u_short __iomem *reass_ptr;
1379 IF_EVENT(printk("iadev: open_rx %d.%d\n", vcc->vpi, vcc->vci);)
1381 if (vcc->qos.rxtp.traffic_class == ATM_NONE) return 0;
1382 iadev = INPH_IA_DEV(vcc->dev);
1383 if (vcc->qos.rxtp.traffic_class == ATM_ABR) {
1384 if (iadev->phy_type & FE_25MBIT_PHY) {
1385 printk("IA: ABR not support\n");
1389 /* Make only this VCI in the vc table valid and let all
1390 others be invalid entries */
1391 vc_table = iadev->reass_ram+RX_VC_TABLE*iadev->memSize;
1392 vc_table += vcc->vci;
1393 /* mask the last 6 bits and OR it with 3 for 1K VCs */
1395 *vc_table = vcc->vci << 6;
1396 /* Also keep a list of open rx vcs so that we can attach them with
1397 incoming PDUs later. */
1398 if ((vcc->qos.rxtp.traffic_class == ATM_ABR) ||
1399 (vcc->qos.txtp.traffic_class == ATM_ABR))
1401 srv_cls_param_t srv_p;
1402 init_abr_vc(iadev, &srv_p);
1403 ia_open_abr_vc(iadev, &srv_p, vcc, 0);
1405 else { /* for UBR later may need to add CBR logic */
1406 reass_ptr = iadev->reass_ram+REASS_TABLE*iadev->memSize;
1407 reass_ptr += vcc->vci;
1408 *reass_ptr = NO_AAL5_PKT;
1411 if (iadev->rx_open[vcc->vci])
1412 printk(KERN_CRIT DEV_LABEL "(itf %d): VCI %d already open\n",
1413 vcc->dev->number, vcc->vci);
1414 iadev->rx_open[vcc->vci] = vcc;
1418 static int rx_init(struct atm_dev *dev)
1421 struct rx_buf_desc __iomem *buf_desc_ptr;
1422 unsigned long rx_pkt_start = 0;
1424 struct abr_vc_table *abr_vc_table;
1427 int i,j, vcsize_sel;
1428 u_short freeq_st_adr;
1429 u_short *freeq_start;
1431 iadev = INPH_IA_DEV(dev);
1432 // spin_lock_init(&iadev->rx_lock);
1434 /* Allocate 4k bytes - more aligned than needed (4k boundary) */
1435 dle_addr = dma_alloc_coherent(&iadev->pci->dev, DLE_TOTAL_SIZE,
1436 &iadev->rx_dle_dma, GFP_KERNEL);
1438 printk(KERN_ERR DEV_LABEL "can't allocate DLEs\n");
1441 iadev->rx_dle_q.start = (struct dle *)dle_addr;
1442 iadev->rx_dle_q.read = iadev->rx_dle_q.start;
1443 iadev->rx_dle_q.write = iadev->rx_dle_q.start;
1444 iadev->rx_dle_q.end = (struct dle*)((unsigned long)dle_addr+sizeof(struct dle)*DLE_ENTRIES);
1445 /* the end of the dle q points to the entry after the last
1446 DLE that can be used. */
1448 /* write the upper 20 bits of the start address to rx list address register */
1449 /* We know this is 32bit bus addressed so the following is safe */
1450 writel(iadev->rx_dle_dma & 0xfffff000,
1451 iadev->dma + IPHASE5575_RX_LIST_ADDR);
1452 IF_INIT(printk("Tx Dle list addr: 0x%p value: 0x%0x\n",
1453 iadev->dma+IPHASE5575_TX_LIST_ADDR,
1454 readl(iadev->dma + IPHASE5575_TX_LIST_ADDR));
1455 printk("Rx Dle list addr: 0x%p value: 0x%0x\n",
1456 iadev->dma+IPHASE5575_RX_LIST_ADDR,
1457 readl(iadev->dma + IPHASE5575_RX_LIST_ADDR));)
1459 writew(0xffff, iadev->reass_reg+REASS_MASK_REG);
1460 writew(0, iadev->reass_reg+MODE_REG);
1461 writew(RESET_REASS, iadev->reass_reg+REASS_COMMAND_REG);
1463 /* Receive side control memory map
1464 -------------------------------
1466 Buffer descr 0x0000 (736 - 23K)
1467 VP Table 0x5c00 (256 - 512)
1468 Except q 0x5e00 (128 - 512)
1469 Free buffer q 0x6000 (1K - 2K)
1470 Packet comp q 0x6800 (1K - 2K)
1471 Reass Table 0x7000 (1K - 2K)
1472 VC Table 0x7800 (1K - 2K)
1473 ABR VC Table 0x8000 (1K - 32K)
1476 /* Base address for Buffer Descriptor Table */
1477 writew(RX_DESC_BASE >> 16, iadev->reass_reg+REASS_DESC_BASE);
1478 /* Set the buffer size register */
1479 writew(iadev->rx_buf_sz, iadev->reass_reg+BUF_SIZE);
1481 /* Initialize each entry in the Buffer Descriptor Table */
1482 iadev->RX_DESC_BASE_ADDR = iadev->reass_ram+RX_DESC_BASE*iadev->memSize;
1483 buf_desc_ptr = iadev->RX_DESC_BASE_ADDR;
1484 memset_io(buf_desc_ptr, 0, sizeof(*buf_desc_ptr));
1486 rx_pkt_start = iadev->rx_pkt_ram;
1487 for(i=1; i<=iadev->num_rx_desc; i++)
1489 memset_io(buf_desc_ptr, 0, sizeof(*buf_desc_ptr));
1490 buf_desc_ptr->buf_start_hi = rx_pkt_start >> 16;
1491 buf_desc_ptr->buf_start_lo = rx_pkt_start & 0x0000ffff;
1493 rx_pkt_start += iadev->rx_buf_sz;
1495 IF_INIT(printk("Rx Buffer desc ptr: 0x%p\n", buf_desc_ptr);)
1496 i = FREE_BUF_DESC_Q*iadev->memSize;
1497 writew(i >> 16, iadev->reass_reg+REASS_QUEUE_BASE);
1498 writew(i, iadev->reass_reg+FREEQ_ST_ADR);
1499 writew(i+iadev->num_rx_desc*sizeof(u_short),
1500 iadev->reass_reg+FREEQ_ED_ADR);
1501 writew(i, iadev->reass_reg+FREEQ_RD_PTR);
1502 writew(i+iadev->num_rx_desc*sizeof(u_short),
1503 iadev->reass_reg+FREEQ_WR_PTR);
1504 /* Fill the FREEQ with all the free descriptors. */
1505 freeq_st_adr = readw(iadev->reass_reg+FREEQ_ST_ADR);
1506 freeq_start = (u_short *)(iadev->reass_ram+freeq_st_adr);
1507 for(i=1; i<=iadev->num_rx_desc; i++)
1509 *freeq_start = (u_short)i;
1512 IF_INIT(printk("freeq_start: 0x%p\n", freeq_start);)
1513 /* Packet Complete Queue */
1514 i = (PKT_COMP_Q * iadev->memSize) & 0xffff;
1515 writew(i, iadev->reass_reg+PCQ_ST_ADR);
1516 writew(i+iadev->num_vc*sizeof(u_short), iadev->reass_reg+PCQ_ED_ADR);
1517 writew(i, iadev->reass_reg+PCQ_RD_PTR);
1518 writew(i, iadev->reass_reg+PCQ_WR_PTR);
1520 /* Exception Queue */
1521 i = (EXCEPTION_Q * iadev->memSize) & 0xffff;
1522 writew(i, iadev->reass_reg+EXCP_Q_ST_ADR);
1523 writew(i + NUM_RX_EXCP * sizeof(RX_ERROR_Q),
1524 iadev->reass_reg+EXCP_Q_ED_ADR);
1525 writew(i, iadev->reass_reg+EXCP_Q_RD_PTR);
1526 writew(i, iadev->reass_reg+EXCP_Q_WR_PTR);
1528 /* Load local copy of FREEQ and PCQ ptrs */
1529 iadev->rfL.fdq_st = readw(iadev->reass_reg+FREEQ_ST_ADR) & 0xffff;
1530 iadev->rfL.fdq_ed = readw(iadev->reass_reg+FREEQ_ED_ADR) & 0xffff ;
1531 iadev->rfL.fdq_rd = readw(iadev->reass_reg+FREEQ_RD_PTR) & 0xffff;
1532 iadev->rfL.fdq_wr = readw(iadev->reass_reg+FREEQ_WR_PTR) & 0xffff;
1533 iadev->rfL.pcq_st = readw(iadev->reass_reg+PCQ_ST_ADR) & 0xffff;
1534 iadev->rfL.pcq_ed = readw(iadev->reass_reg+PCQ_ED_ADR) & 0xffff;
1535 iadev->rfL.pcq_rd = readw(iadev->reass_reg+PCQ_RD_PTR) & 0xffff;
1536 iadev->rfL.pcq_wr = readw(iadev->reass_reg+PCQ_WR_PTR) & 0xffff;
1538 IF_INIT(printk("INIT:pcq_st:0x%x pcq_ed:0x%x pcq_rd:0x%x pcq_wr:0x%x",
1539 iadev->rfL.pcq_st, iadev->rfL.pcq_ed, iadev->rfL.pcq_rd,
1540 iadev->rfL.pcq_wr);)
1541 /* just for check - no VP TBL */
1543 /* writew(0x0b80, iadev->reass_reg+VP_LKUP_BASE); */
1544 /* initialize VP Table for invalid VPIs
1545 - I guess we can write all 1s or 0x000f in the entire memory
1546 space or something similar.
1549 /* This seems to work and looks right to me too !!! */
1550 i = REASS_TABLE * iadev->memSize;
1551 writew((i >> 3), iadev->reass_reg+REASS_TABLE_BASE);
1552 /* initialize Reassembly table to I don't know what ???? */
1553 reass_table = (u16 *)(iadev->reass_ram+i);
1554 j = REASS_TABLE_SZ * iadev->memSize;
1555 for(i=0; i < j; i++)
1556 *reass_table++ = NO_AAL5_PKT;
1559 while (i != iadev->num_vc) {
1563 i = RX_VC_TABLE * iadev->memSize;
1564 writew(((i>>3) & 0xfff8) | vcsize_sel, iadev->reass_reg+VC_LKUP_BASE);
1565 vc_table = (u16 *)(iadev->reass_ram+RX_VC_TABLE*iadev->memSize);
1566 j = RX_VC_TABLE_SZ * iadev->memSize;
1567 for(i = 0; i < j; i++)
1569 /* shift the reassembly pointer by 3 + lower 3 bits of
1570 vc_lkup_base register (=3 for 1K VCs) and the last byte
1571 is those low 3 bits.
1572 Shall program this later.
1574 *vc_table = (i << 6) | 15; /* for invalid VCI */
1578 i = ABR_VC_TABLE * iadev->memSize;
1579 writew(i >> 3, iadev->reass_reg+ABR_LKUP_BASE);
1581 i = ABR_VC_TABLE * iadev->memSize;
1582 abr_vc_table = (struct abr_vc_table *)(iadev->reass_ram+i);
1583 j = REASS_TABLE_SZ * iadev->memSize;
1584 memset ((char*)abr_vc_table, 0, j * sizeof(*abr_vc_table));
1585 for(i = 0; i < j; i++) {
1586 abr_vc_table->rdf = 0x0003;
1587 abr_vc_table->air = 0x5eb1;
1591 /* Initialize other registers */
1593 /* VP Filter Register set for VC Reassembly only */
1594 writew(0xff00, iadev->reass_reg+VP_FILTER);
1595 writew(0, iadev->reass_reg+XTRA_RM_OFFSET);
1596 writew(0x1, iadev->reass_reg+PROTOCOL_ID);
1598 /* Packet Timeout Count related Registers :
1599 Set packet timeout to occur in about 3 seconds
1600 Set Packet Aging Interval count register to overflow in about 4 us
1602 writew(0xF6F8, iadev->reass_reg+PKT_TM_CNT );
1604 i = (j >> 6) & 0xFF;
1606 i |= ((j << 2) & 0xFF00);
1607 writew(i, iadev->reass_reg+TMOUT_RANGE);
1609 /* initiate the desc_tble */
1610 for(i=0; i<iadev->num_tx_desc;i++)
1611 iadev->desc_tbl[i].timestamp = 0;
1613 /* to clear the interrupt status register - read it */
1614 readw(iadev->reass_reg+REASS_INTR_STATUS_REG);
1616 /* Mask Register - clear it */
1617 writew(~(RX_FREEQ_EMPT|RX_PKT_RCVD), iadev->reass_reg+REASS_MASK_REG);
1619 skb_queue_head_init(&iadev->rx_dma_q);
1620 iadev->rx_free_desc_qhead = NULL;
1622 iadev->rx_open = kzalloc(4 * iadev->num_vc, GFP_KERNEL);
1623 if (!iadev->rx_open) {
1624 printk(KERN_ERR DEV_LABEL "itf %d couldn't get free page\n",
1630 iadev->rx_pkt_cnt = 0;
1632 writew(R_ONLINE, iadev->reass_reg+MODE_REG);
1636 dma_free_coherent(&iadev->pci->dev, DLE_TOTAL_SIZE, iadev->rx_dle_q.start,
1644 The memory map suggested in appendix A and the coding for it.
1645 Keeping it around just in case we change our mind later.
1647 Buffer descr 0x0000 (128 - 4K)
1648 UBR sched 0x1000 (1K - 4K)
1649 UBR Wait q 0x2000 (1K - 4K)
1650 Commn queues 0x3000 Packet Ready, Trasmit comp(0x3100)
1652 extended VC 0x4000 (1K - 8K)
1653 ABR sched 0x6000 and ABR wait queue (1K - 2K) each
1654 CBR sched 0x7000 (as needed)
1655 VC table 0x8000 (1K - 32K)
1658 static void tx_intr(struct atm_dev *dev)
1661 unsigned short status;
1662 unsigned long flags;
1664 iadev = INPH_IA_DEV(dev);
1666 status = readl(iadev->seg_reg+SEG_INTR_STATUS_REG);
1667 if (status & TRANSMIT_DONE){
1669 IF_EVENT(printk("Tansmit Done Intr logic run\n");)
1670 spin_lock_irqsave(&iadev->tx_lock, flags);
1672 spin_unlock_irqrestore(&iadev->tx_lock, flags);
1673 writew(TRANSMIT_DONE, iadev->seg_reg+SEG_INTR_STATUS_REG);
1674 if (iadev->close_pending)
1675 wake_up(&iadev->close_wait);
1677 if (status & TCQ_NOT_EMPTY)
1679 IF_EVENT(printk("TCQ_NOT_EMPTY int received\n");)
1683 static void tx_dle_intr(struct atm_dev *dev)
1686 struct dle *dle, *cur_dle;
1687 struct sk_buff *skb;
1688 struct atm_vcc *vcc;
1689 struct ia_vcc *iavcc;
1691 unsigned long flags;
1693 iadev = INPH_IA_DEV(dev);
1694 spin_lock_irqsave(&iadev->tx_lock, flags);
1695 dle = iadev->tx_dle_q.read;
1696 dle_lp = readl(iadev->dma+IPHASE5575_TX_LIST_ADDR) &
1697 (sizeof(struct dle)*DLE_ENTRIES - 1);
1698 cur_dle = (struct dle*)(iadev->tx_dle_q.start + (dle_lp >> 4));
1699 while (dle != cur_dle)
1701 /* free the DMAed skb */
1702 skb = skb_dequeue(&iadev->tx_dma_q);
1705 /* Revenge of the 2 dle (skb + trailer) used in ia_pkt_tx() */
1706 if (!((dle - iadev->tx_dle_q.start)%(2*sizeof(struct dle)))) {
1707 dma_unmap_single(&iadev->pci->dev, dle->sys_pkt_addr, skb->len,
1710 vcc = ATM_SKB(skb)->vcc;
1712 printk("tx_dle_intr: vcc is null\n");
1713 spin_unlock_irqrestore(&iadev->tx_lock, flags);
1714 dev_kfree_skb_any(skb);
1718 iavcc = INPH_IA_VCC(vcc);
1720 printk("tx_dle_intr: iavcc is null\n");
1721 spin_unlock_irqrestore(&iadev->tx_lock, flags);
1722 dev_kfree_skb_any(skb);
1725 if (vcc->qos.txtp.pcr >= iadev->rate_limit) {
1726 if ((vcc->pop) && (skb->len != 0))
1731 dev_kfree_skb_any(skb);
1734 else { /* Hold the rate-limited skb for flow control */
1735 IA_SKB_STATE(skb) |= IA_DLED;
1736 skb_queue_tail(&iavcc->txing_skb, skb);
1738 IF_EVENT(printk("tx_dle_intr: enque skb = 0x%p \n", skb);)
1739 if (++dle == iadev->tx_dle_q.end)
1740 dle = iadev->tx_dle_q.start;
1742 iadev->tx_dle_q.read = dle;
1743 spin_unlock_irqrestore(&iadev->tx_lock, flags);
1746 static int open_tx(struct atm_vcc *vcc)
1748 struct ia_vcc *ia_vcc;
1753 IF_EVENT(printk("iadev: open_tx entered vcc->vci = %d\n", vcc->vci);)
1754 if (vcc->qos.txtp.traffic_class == ATM_NONE) return 0;
1755 iadev = INPH_IA_DEV(vcc->dev);
1757 if (iadev->phy_type & FE_25MBIT_PHY) {
1758 if (vcc->qos.txtp.traffic_class == ATM_ABR) {
1759 printk("IA: ABR not support\n");
1762 if (vcc->qos.txtp.traffic_class == ATM_CBR) {
1763 printk("IA: CBR not support\n");
1767 ia_vcc = INPH_IA_VCC(vcc);
1768 memset((caddr_t)ia_vcc, 0, sizeof(*ia_vcc));
1769 if (vcc->qos.txtp.max_sdu >
1770 (iadev->tx_buf_sz - sizeof(struct cpcs_trailer))){
1771 printk("IA: SDU size over (%d) the configured SDU size %d\n",
1772 vcc->qos.txtp.max_sdu,iadev->tx_buf_sz);
1773 vcc->dev_data = NULL;
1777 ia_vcc->vc_desc_cnt = 0;
1781 if (vcc->qos.txtp.max_pcr == ATM_MAX_PCR)
1782 vcc->qos.txtp.pcr = iadev->LineRate;
1783 else if ((vcc->qos.txtp.max_pcr == 0)&&( vcc->qos.txtp.pcr <= 0))
1784 vcc->qos.txtp.pcr = iadev->LineRate;
1785 else if ((vcc->qos.txtp.max_pcr > vcc->qos.txtp.pcr) && (vcc->qos.txtp.max_pcr> 0))
1786 vcc->qos.txtp.pcr = vcc->qos.txtp.max_pcr;
1787 if (vcc->qos.txtp.pcr > iadev->LineRate)
1788 vcc->qos.txtp.pcr = iadev->LineRate;
1789 ia_vcc->pcr = vcc->qos.txtp.pcr;
1791 if (ia_vcc->pcr > (iadev->LineRate / 6) ) ia_vcc->ltimeout = HZ / 10;
1792 else if (ia_vcc->pcr > (iadev->LineRate / 130)) ia_vcc->ltimeout = HZ;
1793 else if (ia_vcc->pcr <= 170) ia_vcc->ltimeout = 16 * HZ;
1794 else ia_vcc->ltimeout = 2700 * HZ / ia_vcc->pcr;
1795 if (ia_vcc->pcr < iadev->rate_limit)
1796 skb_queue_head_init (&ia_vcc->txing_skb);
1797 if (ia_vcc->pcr < iadev->rate_limit) {
1798 struct sock *sk = sk_atm(vcc);
1800 if (vcc->qos.txtp.max_sdu != 0) {
1801 if (ia_vcc->pcr > 60000)
1802 sk->sk_sndbuf = vcc->qos.txtp.max_sdu * 5;
1803 else if (ia_vcc->pcr > 2000)
1804 sk->sk_sndbuf = vcc->qos.txtp.max_sdu * 4;
1806 sk->sk_sndbuf = vcc->qos.txtp.max_sdu * 3;
1809 sk->sk_sndbuf = 24576;
1812 vc = (struct main_vc *)iadev->MAIN_VC_TABLE_ADDR;
1813 evc = (struct ext_vc *)iadev->EXT_VC_TABLE_ADDR;
1816 memset((caddr_t)vc, 0, sizeof(*vc));
1817 memset((caddr_t)evc, 0, sizeof(*evc));
1819 /* store the most significant 4 bits of vci as the last 4 bits
1820 of first part of atm header.
1821 store the last 12 bits of vci as first 12 bits of the second
1822 part of the atm header.
1824 evc->atm_hdr1 = (vcc->vci >> 12) & 0x000f;
1825 evc->atm_hdr2 = (vcc->vci & 0x0fff) << 4;
1827 /* check the following for different traffic classes */
1828 if (vcc->qos.txtp.traffic_class == ATM_UBR)
1831 vc->status = CRC_APPEND;
1832 vc->acr = cellrate_to_float(iadev->LineRate);
1833 if (vcc->qos.txtp.pcr > 0)
1834 vc->acr = cellrate_to_float(vcc->qos.txtp.pcr);
1835 IF_UBR(printk("UBR: txtp.pcr = 0x%x f_rate = 0x%x\n",
1836 vcc->qos.txtp.max_pcr,vc->acr);)
1838 else if (vcc->qos.txtp.traffic_class == ATM_ABR)
1839 { srv_cls_param_t srv_p;
1840 IF_ABR(printk("Tx ABR VCC\n");)
1841 init_abr_vc(iadev, &srv_p);
1842 if (vcc->qos.txtp.pcr > 0)
1843 srv_p.pcr = vcc->qos.txtp.pcr;
1844 if (vcc->qos.txtp.min_pcr > 0) {
1845 int tmpsum = iadev->sum_mcr+iadev->sum_cbr+vcc->qos.txtp.min_pcr;
1846 if (tmpsum > iadev->LineRate)
1848 srv_p.mcr = vcc->qos.txtp.min_pcr;
1849 iadev->sum_mcr += vcc->qos.txtp.min_pcr;
1852 if (vcc->qos.txtp.icr)
1853 srv_p.icr = vcc->qos.txtp.icr;
1854 if (vcc->qos.txtp.tbe)
1855 srv_p.tbe = vcc->qos.txtp.tbe;
1856 if (vcc->qos.txtp.frtt)
1857 srv_p.frtt = vcc->qos.txtp.frtt;
1858 if (vcc->qos.txtp.rif)
1859 srv_p.rif = vcc->qos.txtp.rif;
1860 if (vcc->qos.txtp.rdf)
1861 srv_p.rdf = vcc->qos.txtp.rdf;
1862 if (vcc->qos.txtp.nrm_pres)
1863 srv_p.nrm = vcc->qos.txtp.nrm;
1864 if (vcc->qos.txtp.trm_pres)
1865 srv_p.trm = vcc->qos.txtp.trm;
1866 if (vcc->qos.txtp.adtf_pres)
1867 srv_p.adtf = vcc->qos.txtp.adtf;
1868 if (vcc->qos.txtp.cdf_pres)
1869 srv_p.cdf = vcc->qos.txtp.cdf;
1870 if (srv_p.icr > srv_p.pcr)
1871 srv_p.icr = srv_p.pcr;
1872 IF_ABR(printk("ABR:vcc->qos.txtp.max_pcr = %d mcr = %d\n",
1873 srv_p.pcr, srv_p.mcr);)
1874 ia_open_abr_vc(iadev, &srv_p, vcc, 1);
1875 } else if (vcc->qos.txtp.traffic_class == ATM_CBR) {
1876 if (iadev->phy_type & FE_25MBIT_PHY) {
1877 printk("IA: CBR not support\n");
1880 if (vcc->qos.txtp.max_pcr > iadev->LineRate) {
1881 IF_CBR(printk("PCR is not available\n");)
1885 vc->status = CRC_APPEND;
1886 if ((ret = ia_cbr_setup (iadev, vcc)) < 0) {
1891 printk("iadev: Non UBR, ABR and CBR traffic not supportedn");
1893 iadev->testTable[vcc->vci]->vc_status |= VC_ACTIVE;
1894 IF_EVENT(printk("ia open_tx returning \n");)
1899 static int tx_init(struct atm_dev *dev)
1902 struct tx_buf_desc *buf_desc_ptr;
1903 unsigned int tx_pkt_start;
1915 iadev = INPH_IA_DEV(dev);
1916 spin_lock_init(&iadev->tx_lock);
1918 IF_INIT(printk("Tx MASK REG: 0x%0x\n",
1919 readw(iadev->seg_reg+SEG_MASK_REG));)
1921 /* Allocate 4k (boundary aligned) bytes */
1922 dle_addr = dma_alloc_coherent(&iadev->pci->dev, DLE_TOTAL_SIZE,
1923 &iadev->tx_dle_dma, GFP_KERNEL);
1925 printk(KERN_ERR DEV_LABEL "can't allocate DLEs\n");
1928 iadev->tx_dle_q.start = (struct dle*)dle_addr;
1929 iadev->tx_dle_q.read = iadev->tx_dle_q.start;
1930 iadev->tx_dle_q.write = iadev->tx_dle_q.start;
1931 iadev->tx_dle_q.end = (struct dle*)((unsigned long)dle_addr+sizeof(struct dle)*DLE_ENTRIES);
1933 /* write the upper 20 bits of the start address to tx list address register */
1934 writel(iadev->tx_dle_dma & 0xfffff000,
1935 iadev->dma + IPHASE5575_TX_LIST_ADDR);
1936 writew(0xffff, iadev->seg_reg+SEG_MASK_REG);
1937 writew(0, iadev->seg_reg+MODE_REG_0);
1938 writew(RESET_SEG, iadev->seg_reg+SEG_COMMAND_REG);
1939 iadev->MAIN_VC_TABLE_ADDR = iadev->seg_ram+MAIN_VC_TABLE*iadev->memSize;
1940 iadev->EXT_VC_TABLE_ADDR = iadev->seg_ram+EXT_VC_TABLE*iadev->memSize;
1941 iadev->ABR_SCHED_TABLE_ADDR=iadev->seg_ram+ABR_SCHED_TABLE*iadev->memSize;
1944 Transmit side control memory map
1945 --------------------------------
1946 Buffer descr 0x0000 (128 - 4K)
1947 Commn queues 0x1000 Transmit comp, Packet ready(0x1400)
1950 CBR Table 0x1800 (as needed) - 6K
1951 UBR Table 0x3000 (1K - 4K) - 12K
1952 UBR Wait queue 0x4000 (1K - 4K) - 16K
1953 ABR sched 0x5000 and ABR wait queue (1K - 2K) each
1954 ABR Tbl - 20K, ABR Wq - 22K
1955 extended VC 0x6000 (1K - 8K) - 24K
1956 VC Table 0x8000 (1K - 32K) - 32K
1958 Between 0x2000 (8K) and 0x3000 (12K) there is 4K space left for VBR Tbl
1959 and Wait q, which can be allotted later.
1962 /* Buffer Descriptor Table Base address */
1963 writew(TX_DESC_BASE, iadev->seg_reg+SEG_DESC_BASE);
1965 /* initialize each entry in the buffer descriptor table */
1966 buf_desc_ptr =(struct tx_buf_desc *)(iadev->seg_ram+TX_DESC_BASE);
1967 memset((caddr_t)buf_desc_ptr, 0, sizeof(*buf_desc_ptr));
1969 tx_pkt_start = TX_PACKET_RAM;
1970 for(i=1; i<=iadev->num_tx_desc; i++)
1972 memset((caddr_t)buf_desc_ptr, 0, sizeof(*buf_desc_ptr));
1973 buf_desc_ptr->desc_mode = AAL5;
1974 buf_desc_ptr->buf_start_hi = tx_pkt_start >> 16;
1975 buf_desc_ptr->buf_start_lo = tx_pkt_start & 0x0000ffff;
1977 tx_pkt_start += iadev->tx_buf_sz;
1979 iadev->tx_buf = kmalloc(iadev->num_tx_desc*sizeof(struct cpcs_trailer_desc), GFP_KERNEL);
1980 if (!iadev->tx_buf) {
1981 printk(KERN_ERR DEV_LABEL " couldn't get mem\n");
1984 for (i= 0; i< iadev->num_tx_desc; i++)
1986 struct cpcs_trailer *cpcs;
1988 cpcs = kmalloc(sizeof(*cpcs), GFP_KERNEL|GFP_DMA);
1990 printk(KERN_ERR DEV_LABEL " couldn't get freepage\n");
1991 goto err_free_tx_bufs;
1993 iadev->tx_buf[i].cpcs = cpcs;
1994 iadev->tx_buf[i].dma_addr = dma_map_single(&iadev->pci->dev,
1999 iadev->desc_tbl = kmalloc(iadev->num_tx_desc *
2000 sizeof(struct desc_tbl_t), GFP_KERNEL);
2001 if (!iadev->desc_tbl) {
2002 printk(KERN_ERR DEV_LABEL " couldn't get mem\n");
2003 goto err_free_all_tx_bufs;
2006 /* Communication Queues base address */
2007 i = TX_COMP_Q * iadev->memSize;
2008 writew(i >> 16, iadev->seg_reg+SEG_QUEUE_BASE);
2010 /* Transmit Complete Queue */
2011 writew(i, iadev->seg_reg+TCQ_ST_ADR);
2012 writew(i, iadev->seg_reg+TCQ_RD_PTR);
2013 writew(i+iadev->num_tx_desc*sizeof(u_short),iadev->seg_reg+TCQ_WR_PTR);
2014 iadev->host_tcq_wr = i + iadev->num_tx_desc*sizeof(u_short);
2015 writew(i+2 * iadev->num_tx_desc * sizeof(u_short),
2016 iadev->seg_reg+TCQ_ED_ADR);
2017 /* Fill the TCQ with all the free descriptors. */
2018 tcq_st_adr = readw(iadev->seg_reg+TCQ_ST_ADR);
2019 tcq_start = (u_short *)(iadev->seg_ram+tcq_st_adr);
2020 for(i=1; i<=iadev->num_tx_desc; i++)
2022 *tcq_start = (u_short)i;
2026 /* Packet Ready Queue */
2027 i = PKT_RDY_Q * iadev->memSize;
2028 writew(i, iadev->seg_reg+PRQ_ST_ADR);
2029 writew(i+2 * iadev->num_tx_desc * sizeof(u_short),
2030 iadev->seg_reg+PRQ_ED_ADR);
2031 writew(i, iadev->seg_reg+PRQ_RD_PTR);
2032 writew(i, iadev->seg_reg+PRQ_WR_PTR);
2034 /* Load local copy of PRQ and TCQ ptrs */
2035 iadev->ffL.prq_st = readw(iadev->seg_reg+PRQ_ST_ADR) & 0xffff;
2036 iadev->ffL.prq_ed = readw(iadev->seg_reg+PRQ_ED_ADR) & 0xffff;
2037 iadev->ffL.prq_wr = readw(iadev->seg_reg+PRQ_WR_PTR) & 0xffff;
2039 iadev->ffL.tcq_st = readw(iadev->seg_reg+TCQ_ST_ADR) & 0xffff;
2040 iadev->ffL.tcq_ed = readw(iadev->seg_reg+TCQ_ED_ADR) & 0xffff;
2041 iadev->ffL.tcq_rd = readw(iadev->seg_reg+TCQ_RD_PTR) & 0xffff;
2043 /* Just for safety initializing the queue to have desc 1 always */
2044 /* Fill the PRQ with all the free descriptors. */
2045 prq_st_adr = readw(iadev->seg_reg+PRQ_ST_ADR);
2046 prq_start = (u_short *)(iadev->seg_ram+prq_st_adr);
2047 for(i=1; i<=iadev->num_tx_desc; i++)
2049 *prq_start = (u_short)0; /* desc 1 in all entries */
2053 IF_INIT(printk("Start CBR Init\n");)
2054 #if 1 /* for 1K VC board, CBR_PTR_BASE is 0 */
2055 writew(0,iadev->seg_reg+CBR_PTR_BASE);
2056 #else /* Charlie's logic is wrong ? */
2057 tmp16 = (iadev->seg_ram+CBR_SCHED_TABLE*iadev->memSize)>>17;
2058 IF_INIT(printk("cbr_ptr_base = 0x%x ", tmp16);)
2059 writew(tmp16,iadev->seg_reg+CBR_PTR_BASE);
2062 IF_INIT(printk("value in register = 0x%x\n",
2063 readw(iadev->seg_reg+CBR_PTR_BASE));)
2064 tmp16 = (CBR_SCHED_TABLE*iadev->memSize) >> 1;
2065 writew(tmp16, iadev->seg_reg+CBR_TAB_BEG);
2066 IF_INIT(printk("cbr_tab_beg = 0x%x in reg = 0x%x \n", tmp16,
2067 readw(iadev->seg_reg+CBR_TAB_BEG));)
2068 writew(tmp16, iadev->seg_reg+CBR_TAB_END+1); // CBR_PTR;
2069 tmp16 = (CBR_SCHED_TABLE*iadev->memSize + iadev->num_vc*6 - 2) >> 1;
2070 writew(tmp16, iadev->seg_reg+CBR_TAB_END);
2071 IF_INIT(printk("iadev->seg_reg = 0x%p CBR_PTR_BASE = 0x%x\n",
2072 iadev->seg_reg, readw(iadev->seg_reg+CBR_PTR_BASE));)
2073 IF_INIT(printk("CBR_TAB_BEG = 0x%x, CBR_TAB_END = 0x%x, CBR_PTR = 0x%x\n",
2074 readw(iadev->seg_reg+CBR_TAB_BEG), readw(iadev->seg_reg+CBR_TAB_END),
2075 readw(iadev->seg_reg+CBR_TAB_END+1));)
2077 /* Initialize the CBR Schedualing Table */
2078 memset_io(iadev->seg_ram+CBR_SCHED_TABLE*iadev->memSize,
2079 0, iadev->num_vc*6);
2080 iadev->CbrRemEntries = iadev->CbrTotEntries = iadev->num_vc*3;
2081 iadev->CbrEntryPt = 0;
2082 iadev->Granularity = MAX_ATM_155 / iadev->CbrTotEntries;
2083 iadev->NumEnabledCBR = 0;
2085 /* UBR scheduling Table and wait queue */
2086 /* initialize all bytes of UBR scheduler table and wait queue to 0
2087 - SCHEDSZ is 1K (# of entries).
2088 - UBR Table size is 4K
2089 - UBR wait queue is 4K
2090 since the table and wait queues are contiguous, all the bytes
2091 can be initialized by one memeset.
2096 while (i != iadev->num_vc) {
2101 i = MAIN_VC_TABLE * iadev->memSize;
2102 writew(vcsize_sel | ((i >> 8) & 0xfff8),iadev->seg_reg+VCT_BASE);
2103 i = EXT_VC_TABLE * iadev->memSize;
2104 writew((i >> 8) & 0xfffe, iadev->seg_reg+VCTE_BASE);
2105 i = UBR_SCHED_TABLE * iadev->memSize;
2106 writew((i & 0xffff) >> 11, iadev->seg_reg+UBR_SBPTR_BASE);
2107 i = UBR_WAIT_Q * iadev->memSize;
2108 writew((i >> 7) & 0xffff, iadev->seg_reg+UBRWQ_BASE);
2109 memset((caddr_t)(iadev->seg_ram+UBR_SCHED_TABLE*iadev->memSize),
2110 0, iadev->num_vc*8);
2111 /* ABR scheduling Table(0x5000-0x57ff) and wait queue(0x5800-0x5fff)*/
2112 /* initialize all bytes of ABR scheduler table and wait queue to 0
2113 - SCHEDSZ is 1K (# of entries).
2114 - ABR Table size is 2K
2115 - ABR wait queue is 2K
2116 since the table and wait queues are contiguous, all the bytes
2117 can be initialized by one memeset.
2119 i = ABR_SCHED_TABLE * iadev->memSize;
2120 writew((i >> 11) & 0xffff, iadev->seg_reg+ABR_SBPTR_BASE);
2121 i = ABR_WAIT_Q * iadev->memSize;
2122 writew((i >> 7) & 0xffff, iadev->seg_reg+ABRWQ_BASE);
2124 i = ABR_SCHED_TABLE*iadev->memSize;
2125 memset((caddr_t)(iadev->seg_ram+i), 0, iadev->num_vc*4);
2126 vc = (struct main_vc *)iadev->MAIN_VC_TABLE_ADDR;
2127 evc = (struct ext_vc *)iadev->EXT_VC_TABLE_ADDR;
2128 iadev->testTable = kmalloc(sizeof(long)*iadev->num_vc, GFP_KERNEL);
2129 if (!iadev->testTable) {
2130 printk("Get freepage failed\n");
2131 goto err_free_desc_tbl;
2133 for(i=0; i<iadev->num_vc; i++)
2135 memset((caddr_t)vc, 0, sizeof(*vc));
2136 memset((caddr_t)evc, 0, sizeof(*evc));
2137 iadev->testTable[i] = kmalloc(sizeof(struct testTable_t),
2139 if (!iadev->testTable[i])
2140 goto err_free_test_tables;
2141 iadev->testTable[i]->lastTime = 0;
2142 iadev->testTable[i]->fract = 0;
2143 iadev->testTable[i]->vc_status = VC_UBR;
2148 /* Other Initialization */
2150 /* Max Rate Register */
2151 if (iadev->phy_type & FE_25MBIT_PHY) {
2152 writew(RATE25, iadev->seg_reg+MAXRATE);
2153 writew((UBR_EN | (0x23 << 2)), iadev->seg_reg+STPARMS);
2156 writew(cellrate_to_float(iadev->LineRate),iadev->seg_reg+MAXRATE);
2157 writew((UBR_EN | ABR_EN | (0x23 << 2)), iadev->seg_reg+STPARMS);
2159 /* Set Idle Header Reigisters to be sure */
2160 writew(0, iadev->seg_reg+IDLEHEADHI);
2161 writew(0, iadev->seg_reg+IDLEHEADLO);
2163 /* Program ABR UBR Priority Register as PRI_ABR_UBR_EQUAL */
2164 writew(0xaa00, iadev->seg_reg+ABRUBR_ARB);
2166 iadev->close_pending = 0;
2167 init_waitqueue_head(&iadev->close_wait);
2168 init_waitqueue_head(&iadev->timeout_wait);
2169 skb_queue_head_init(&iadev->tx_dma_q);
2170 ia_init_rtn_q(&iadev->tx_return_q);
2172 /* RM Cell Protocol ID and Message Type */
2173 writew(RM_TYPE_4_0, iadev->seg_reg+RM_TYPE);
2174 skb_queue_head_init (&iadev->tx_backlog);
2176 /* Mode Register 1 */
2177 writew(MODE_REG_1_VAL, iadev->seg_reg+MODE_REG_1);
2179 /* Mode Register 0 */
2180 writew(T_ONLINE, iadev->seg_reg+MODE_REG_0);
2182 /* Interrupt Status Register - read to clear */
2183 readw(iadev->seg_reg+SEG_INTR_STATUS_REG);
2185 /* Interrupt Mask Reg- don't mask TCQ_NOT_EMPTY interrupt generation */
2186 writew(~(TRANSMIT_DONE | TCQ_NOT_EMPTY), iadev->seg_reg+SEG_MASK_REG);
2187 writew(TRANSMIT_DONE, iadev->seg_reg+SEG_INTR_STATUS_REG);
2188 iadev->tx_pkt_cnt = 0;
2189 iadev->rate_limit = iadev->LineRate / 3;
2193 err_free_test_tables:
2195 kfree(iadev->testTable[i]);
2196 kfree(iadev->testTable);
2198 kfree(iadev->desc_tbl);
2199 err_free_all_tx_bufs:
2200 i = iadev->num_tx_desc;
2203 struct cpcs_trailer_desc *desc = iadev->tx_buf + i;
2205 dma_unmap_single(&iadev->pci->dev, desc->dma_addr,
2206 sizeof(*desc->cpcs), DMA_TO_DEVICE);
2209 kfree(iadev->tx_buf);
2211 dma_free_coherent(&iadev->pci->dev, DLE_TOTAL_SIZE, iadev->tx_dle_q.start,
2217 static irqreturn_t ia_int(int irq, void *dev_id)
2219 struct atm_dev *dev;
2221 unsigned int status;
2225 iadev = INPH_IA_DEV(dev);
2226 while( (status = readl(iadev->reg+IPHASE5575_BUS_STATUS_REG) & 0x7f))
2229 IF_EVENT(printk("ia_int: status = 0x%x\n", status);)
2230 if (status & STAT_REASSINT)
2233 IF_EVENT(printk("REASSINT Bus status reg: %08x\n", status);)
2236 if (status & STAT_DLERINT)
2238 /* Clear this bit by writing a 1 to it. */
2239 writel(STAT_DLERINT, iadev->reg + IPHASE5575_BUS_STATUS_REG);
2242 if (status & STAT_SEGINT)
2245 IF_EVENT(printk("IA: tx_intr \n");)
2248 if (status & STAT_DLETINT)
2250 writel(STAT_DLETINT, iadev->reg + IPHASE5575_BUS_STATUS_REG);
2253 if (status & (STAT_FEINT | STAT_ERRINT | STAT_MARKINT))
2255 if (status & STAT_FEINT)
2256 ia_frontend_intr(iadev);
2259 return IRQ_RETVAL(handled);
2264 /*----------------------------- entries --------------------------------*/
2265 static int get_esi(struct atm_dev *dev)
2272 iadev = INPH_IA_DEV(dev);
2273 mac1 = cpu_to_be32(le32_to_cpu(readl(
2274 iadev->reg+IPHASE5575_MAC1)));
2275 mac2 = cpu_to_be16(le16_to_cpu(readl(iadev->reg+IPHASE5575_MAC2)));
2276 IF_INIT(printk("ESI: 0x%08x%04x\n", mac1, mac2);)
2277 for (i=0; i<MAC1_LEN; i++)
2278 dev->esi[i] = mac1 >>(8*(MAC1_LEN-1-i));
2280 for (i=0; i<MAC2_LEN; i++)
2281 dev->esi[i+MAC1_LEN] = mac2 >>(8*(MAC2_LEN - 1 -i));
2285 static int reset_sar(struct atm_dev *dev)
2289 unsigned int pci[64];
2291 iadev = INPH_IA_DEV(dev);
2293 if ((error = pci_read_config_dword(iadev->pci,
2294 i*4, &pci[i])) != PCIBIOS_SUCCESSFUL)
2296 writel(0, iadev->reg+IPHASE5575_EXT_RESET);
2298 if ((error = pci_write_config_dword(iadev->pci,
2299 i*4, pci[i])) != PCIBIOS_SUCCESSFUL)
2306 static int ia_init(struct atm_dev *dev)
2309 unsigned long real_base;
2311 unsigned short command;
2314 /* The device has been identified and registered. Now we read
2315 necessary configuration info like memory base address,
2316 interrupt number etc */
2318 IF_INIT(printk(">ia_init\n");)
2319 dev->ci_range.vpi_bits = 0;
2320 dev->ci_range.vci_bits = NR_VCI_LD;
2322 iadev = INPH_IA_DEV(dev);
2323 real_base = pci_resource_start (iadev->pci, 0);
2324 iadev->irq = iadev->pci->irq;
2326 error = pci_read_config_word(iadev->pci, PCI_COMMAND, &command);
2328 printk(KERN_ERR DEV_LABEL "(itf %d): init error 0x%x\n",
2332 IF_INIT(printk(DEV_LABEL "(itf %d): rev.%d,realbase=0x%lx,irq=%d\n",
2333 dev->number, iadev->pci->revision, real_base, iadev->irq);)
2335 /* find mapping size of board */
2337 iadev->pci_map_size = pci_resource_len(iadev->pci, 0);
2339 if (iadev->pci_map_size == 0x100000){
2340 iadev->num_vc = 4096;
2341 dev->ci_range.vci_bits = NR_VCI_4K_LD;
2344 else if (iadev->pci_map_size == 0x40000) {
2345 iadev->num_vc = 1024;
2349 printk("Unknown pci_map_size = 0x%x\n", iadev->pci_map_size);
2352 IF_INIT(printk (DEV_LABEL "map size: %i\n", iadev->pci_map_size);)
2354 /* enable bus mastering */
2355 pci_set_master(iadev->pci);
2358 * Delay at least 1us before doing any mem accesses (how 'bout 10?)
2362 /* mapping the physical address to a virtual address in address space */
2363 base = ioremap(real_base,iadev->pci_map_size); /* ioremap is not resolved ??? */
2367 printk(DEV_LABEL " (itf %d): can't set up page mapping\n",
2371 IF_INIT(printk(DEV_LABEL " (itf %d): rev.%d,base=%p,irq=%d\n",
2372 dev->number, iadev->pci->revision, base, iadev->irq);)
2374 /* filling the iphase dev structure */
2375 iadev->mem = iadev->pci_map_size /2;
2376 iadev->real_base = real_base;
2379 /* Bus Interface Control Registers */
2380 iadev->reg = base + REG_BASE;
2381 /* Segmentation Control Registers */
2382 iadev->seg_reg = base + SEG_BASE;
2383 /* Reassembly Control Registers */
2384 iadev->reass_reg = base + REASS_BASE;
2385 /* Front end/ DMA control registers */
2386 iadev->phy = base + PHY_BASE;
2387 iadev->dma = base + PHY_BASE;
2388 /* RAM - Segmentation RAm and Reassembly RAM */
2389 iadev->ram = base + ACTUAL_RAM_BASE;
2390 iadev->seg_ram = base + ACTUAL_SEG_RAM_BASE;
2391 iadev->reass_ram = base + ACTUAL_REASS_RAM_BASE;
2393 /* lets print out the above */
2394 IF_INIT(printk("Base addrs: %p %p %p \n %p %p %p %p\n",
2395 iadev->reg,iadev->seg_reg,iadev->reass_reg,
2396 iadev->phy, iadev->ram, iadev->seg_ram,
2399 /* lets try reading the MAC address */
2400 error = get_esi(dev);
2402 iounmap(iadev->base);
2406 for (i=0; i < ESI_LEN; i++)
2407 printk("%s%02X",i ? "-" : "",dev->esi[i]);
2411 if (reset_sar(dev)) {
2412 iounmap(iadev->base);
2413 printk("IA: reset SAR fail, please try again\n");
2419 static void ia_update_stats(IADEV *iadev) {
2420 if (!iadev->carrier_detect)
2422 iadev->rx_cell_cnt += readw(iadev->reass_reg+CELL_CTR0)&0xffff;
2423 iadev->rx_cell_cnt += (readw(iadev->reass_reg+CELL_CTR1) & 0xffff) << 16;
2424 iadev->drop_rxpkt += readw(iadev->reass_reg + DRP_PKT_CNTR ) & 0xffff;
2425 iadev->drop_rxcell += readw(iadev->reass_reg + ERR_CNTR) & 0xffff;
2426 iadev->tx_cell_cnt += readw(iadev->seg_reg + CELL_CTR_LO_AUTO)&0xffff;
2427 iadev->tx_cell_cnt += (readw(iadev->seg_reg+CELL_CTR_HIGH_AUTO)&0xffff)<<16;
2431 static void ia_led_timer(unsigned long arg) {
2432 unsigned long flags;
2433 static u_char blinking[8] = {0, 0, 0, 0, 0, 0, 0, 0};
2435 static u32 ctrl_reg;
2436 for (i = 0; i < iadev_count; i++) {
2438 ctrl_reg = readl(ia_dev[i]->reg+IPHASE5575_BUS_CONTROL_REG);
2439 if (blinking[i] == 0) {
2441 ctrl_reg &= (~CTRL_LED);
2442 writel(ctrl_reg, ia_dev[i]->reg+IPHASE5575_BUS_CONTROL_REG);
2443 ia_update_stats(ia_dev[i]);
2447 ctrl_reg |= CTRL_LED;
2448 writel(ctrl_reg, ia_dev[i]->reg+IPHASE5575_BUS_CONTROL_REG);
2449 spin_lock_irqsave(&ia_dev[i]->tx_lock, flags);
2450 if (ia_dev[i]->close_pending)
2451 wake_up(&ia_dev[i]->close_wait);
2452 ia_tx_poll(ia_dev[i]);
2453 spin_unlock_irqrestore(&ia_dev[i]->tx_lock, flags);
2457 mod_timer(&ia_timer, jiffies + HZ / 4);
2461 static void ia_phy_put(struct atm_dev *dev, unsigned char value,
2464 writel(value, INPH_IA_DEV(dev)->phy+addr);
2467 static unsigned char ia_phy_get(struct atm_dev *dev, unsigned long addr)
2469 return readl(INPH_IA_DEV(dev)->phy+addr);
2472 static void ia_free_tx(IADEV *iadev)
2476 kfree(iadev->desc_tbl);
2477 for (i = 0; i < iadev->num_vc; i++)
2478 kfree(iadev->testTable[i]);
2479 kfree(iadev->testTable);
2480 for (i = 0; i < iadev->num_tx_desc; i++) {
2481 struct cpcs_trailer_desc *desc = iadev->tx_buf + i;
2483 dma_unmap_single(&iadev->pci->dev, desc->dma_addr,
2484 sizeof(*desc->cpcs), DMA_TO_DEVICE);
2487 kfree(iadev->tx_buf);
2488 dma_free_coherent(&iadev->pci->dev, DLE_TOTAL_SIZE, iadev->tx_dle_q.start,
2492 static void ia_free_rx(IADEV *iadev)
2494 kfree(iadev->rx_open);
2495 dma_free_coherent(&iadev->pci->dev, DLE_TOTAL_SIZE, iadev->rx_dle_q.start,
2499 static int ia_start(struct atm_dev *dev)
2505 IF_EVENT(printk(">ia_start\n");)
2506 iadev = INPH_IA_DEV(dev);
2507 if (request_irq(iadev->irq, &ia_int, IRQF_SHARED, DEV_LABEL, dev)) {
2508 printk(KERN_ERR DEV_LABEL "(itf %d): IRQ%d is already in use\n",
2509 dev->number, iadev->irq);
2513 /* @@@ should release IRQ on error */
2514 /* enabling memory + master */
2515 if ((error = pci_write_config_word(iadev->pci,
2517 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER )))
2519 printk(KERN_ERR DEV_LABEL "(itf %d): can't enable memory+"
2520 "master (0x%x)\n",dev->number, error);
2526 /* Maybe we should reset the front end, initialize Bus Interface Control
2527 Registers and see. */
2529 IF_INIT(printk("Bus ctrl reg: %08x\n",
2530 readl(iadev->reg+IPHASE5575_BUS_CONTROL_REG));)
2531 ctrl_reg = readl(iadev->reg+IPHASE5575_BUS_CONTROL_REG);
2532 ctrl_reg = (ctrl_reg & (CTRL_LED | CTRL_FE_RST))
2540 | CTRL_DLETMASK /* shud be removed l8r */
2547 writel(ctrl_reg, iadev->reg+IPHASE5575_BUS_CONTROL_REG);
2549 IF_INIT(printk("Bus ctrl reg after initializing: %08x\n",
2550 readl(iadev->reg+IPHASE5575_BUS_CONTROL_REG));
2551 printk("Bus status reg after init: %08x\n",
2552 readl(iadev->reg+IPHASE5575_BUS_STATUS_REG));)
2555 error = tx_init(dev);
2558 error = rx_init(dev);
2562 ctrl_reg = readl(iadev->reg+IPHASE5575_BUS_CONTROL_REG);
2563 writel(ctrl_reg | CTRL_FE_RST, iadev->reg+IPHASE5575_BUS_CONTROL_REG);
2564 IF_INIT(printk("Bus ctrl reg after initializing: %08x\n",
2565 readl(iadev->reg+IPHASE5575_BUS_CONTROL_REG));)
2566 phy = 0; /* resolve compiler complaint */
2568 if ((phy=ia_phy_get(dev,0)) == 0x30)
2569 printk("IA: pm5346,rev.%d\n",phy&0x0f);
2571 printk("IA: utopia,rev.%0x\n",phy);)
2573 if (iadev->phy_type & FE_25MBIT_PHY)
2574 ia_mb25_init(iadev);
2575 else if (iadev->phy_type & (FE_DS3_PHY | FE_E3_PHY))
2576 ia_suni_pm7345_init(iadev);
2578 error = suni_init(dev);
2581 if (dev->phy->start) {
2582 error = dev->phy->start(dev);
2586 /* Get iadev->carrier_detect status */
2587 ia_frontend_intr(iadev);
2596 free_irq(iadev->irq, dev);
2601 static void ia_close(struct atm_vcc *vcc)
2606 struct ia_vcc *ia_vcc;
2607 struct sk_buff *skb = NULL;
2608 struct sk_buff_head tmp_tx_backlog, tmp_vcc_backlog;
2609 unsigned long closetime, flags;
2611 iadev = INPH_IA_DEV(vcc->dev);
2612 ia_vcc = INPH_IA_VCC(vcc);
2613 if (!ia_vcc) return;
2615 IF_EVENT(printk("ia_close: ia_vcc->vc_desc_cnt = %d vci = %d\n",
2616 ia_vcc->vc_desc_cnt,vcc->vci);)
2617 clear_bit(ATM_VF_READY,&vcc->flags);
2618 skb_queue_head_init (&tmp_tx_backlog);
2619 skb_queue_head_init (&tmp_vcc_backlog);
2620 if (vcc->qos.txtp.traffic_class != ATM_NONE) {
2621 iadev->close_pending++;
2622 prepare_to_wait(&iadev->timeout_wait, &wait, TASK_UNINTERRUPTIBLE);
2623 schedule_timeout(msecs_to_jiffies(500));
2624 finish_wait(&iadev->timeout_wait, &wait);
2625 spin_lock_irqsave(&iadev->tx_lock, flags);
2626 while((skb = skb_dequeue(&iadev->tx_backlog))) {
2627 if (ATM_SKB(skb)->vcc == vcc){
2628 if (vcc->pop) vcc->pop(vcc, skb);
2629 else dev_kfree_skb_any(skb);
2632 skb_queue_tail(&tmp_tx_backlog, skb);
2634 while((skb = skb_dequeue(&tmp_tx_backlog)))
2635 skb_queue_tail(&iadev->tx_backlog, skb);
2636 IF_EVENT(printk("IA TX Done decs_cnt = %d\n", ia_vcc->vc_desc_cnt);)
2637 closetime = 300000 / ia_vcc->pcr;
2640 spin_unlock_irqrestore(&iadev->tx_lock, flags);
2641 wait_event_timeout(iadev->close_wait, (ia_vcc->vc_desc_cnt <= 0), closetime);
2642 spin_lock_irqsave(&iadev->tx_lock, flags);
2643 iadev->close_pending--;
2644 iadev->testTable[vcc->vci]->lastTime = 0;
2645 iadev->testTable[vcc->vci]->fract = 0;
2646 iadev->testTable[vcc->vci]->vc_status = VC_UBR;
2647 if (vcc->qos.txtp.traffic_class == ATM_ABR) {
2648 if (vcc->qos.txtp.min_pcr > 0)
2649 iadev->sum_mcr -= vcc->qos.txtp.min_pcr;
2651 if (vcc->qos.txtp.traffic_class == ATM_CBR) {
2652 ia_vcc = INPH_IA_VCC(vcc);
2653 iadev->sum_mcr -= ia_vcc->NumCbrEntry*iadev->Granularity;
2654 ia_cbrVc_close (vcc);
2656 spin_unlock_irqrestore(&iadev->tx_lock, flags);
2659 if (vcc->qos.rxtp.traffic_class != ATM_NONE) {
2660 // reset reass table
2661 vc_table = (u16 *)(iadev->reass_ram+REASS_TABLE*iadev->memSize);
2662 vc_table += vcc->vci;
2663 *vc_table = NO_AAL5_PKT;
2665 vc_table = (u16 *)(iadev->reass_ram+RX_VC_TABLE*iadev->memSize);
2666 vc_table += vcc->vci;
2667 *vc_table = (vcc->vci << 6) | 15;
2668 if (vcc->qos.rxtp.traffic_class == ATM_ABR) {
2669 struct abr_vc_table __iomem *abr_vc_table =
2670 (iadev->reass_ram+ABR_VC_TABLE*iadev->memSize);
2671 abr_vc_table += vcc->vci;
2672 abr_vc_table->rdf = 0x0003;
2673 abr_vc_table->air = 0x5eb1;
2675 // Drain the packets
2676 rx_dle_intr(vcc->dev);
2677 iadev->rx_open[vcc->vci] = NULL;
2679 kfree(INPH_IA_VCC(vcc));
2681 vcc->dev_data = NULL;
2682 clear_bit(ATM_VF_ADDR,&vcc->flags);
2686 static int ia_open(struct atm_vcc *vcc)
2688 struct ia_vcc *ia_vcc;
2690 if (!test_bit(ATM_VF_PARTIAL,&vcc->flags))
2692 IF_EVENT(printk("ia: not partially allocated resources\n");)
2693 vcc->dev_data = NULL;
2695 if (vcc->vci != ATM_VPI_UNSPEC && vcc->vpi != ATM_VCI_UNSPEC)
2697 IF_EVENT(printk("iphase open: unspec part\n");)
2698 set_bit(ATM_VF_ADDR,&vcc->flags);
2700 if (vcc->qos.aal != ATM_AAL5)
2702 IF_EVENT(printk(DEV_LABEL "(itf %d): open %d.%d\n",
2703 vcc->dev->number, vcc->vpi, vcc->vci);)
2705 /* Device dependent initialization */
2706 ia_vcc = kmalloc(sizeof(*ia_vcc), GFP_KERNEL);
2707 if (!ia_vcc) return -ENOMEM;
2708 vcc->dev_data = ia_vcc;
2710 if ((error = open_rx(vcc)))
2712 IF_EVENT(printk("iadev: error in open_rx, closing\n");)
2717 if ((error = open_tx(vcc)))
2719 IF_EVENT(printk("iadev: error in open_tx, closing\n");)
2724 set_bit(ATM_VF_READY,&vcc->flags);
2728 static u8 first = 1;
2730 ia_timer.expires = jiffies + 3*HZ;
2731 add_timer(&ia_timer);
2736 IF_EVENT(printk("ia open returning\n");)
2740 static int ia_change_qos(struct atm_vcc *vcc, struct atm_qos *qos, int flags)
2742 IF_EVENT(printk(">ia_change_qos\n");)
2746 static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
2752 IF_EVENT(printk(">ia_ioctl\n");)
2753 if (cmd != IA_CMD) {
2754 if (!dev->phy->ioctl) return -EINVAL;
2755 return dev->phy->ioctl(dev,cmd,arg);
2757 if (copy_from_user(&ia_cmds, arg, sizeof ia_cmds)) return -EFAULT;
2758 board = ia_cmds.status;
2760 if ((board < 0) || (board > iadev_count))
2762 board = array_index_nospec(board, iadev_count + 1);
2764 iadev = ia_dev[board];
2765 switch (ia_cmds.cmd) {
2768 switch (ia_cmds.sub_cmd) {
2770 if (!capable(CAP_NET_ADMIN)) return -EPERM;
2771 if (copy_to_user(ia_cmds.buf, iadev, sizeof(IADEV)))
2775 case MEMDUMP_SEGREG:
2776 if (!capable(CAP_NET_ADMIN)) return -EPERM;
2777 tmps = (u16 __user *)ia_cmds.buf;
2778 for(i=0; i<0x80; i+=2, tmps++)
2779 if(put_user((u16)(readl(iadev->seg_reg+i) & 0xffff), tmps)) return -EFAULT;
2783 case MEMDUMP_REASSREG:
2784 if (!capable(CAP_NET_ADMIN)) return -EPERM;
2785 tmps = (u16 __user *)ia_cmds.buf;
2786 for(i=0; i<0x80; i+=2, tmps++)
2787 if(put_user((u16)(readl(iadev->reass_reg+i) & 0xffff), tmps)) return -EFAULT;
2793 ia_regs_t *regs_local;
2797 if (!capable(CAP_NET_ADMIN)) return -EPERM;
2798 regs_local = kmalloc(sizeof(*regs_local), GFP_KERNEL);
2799 if (!regs_local) return -ENOMEM;
2800 ffL = ®s_local->ffredn;
2801 rfL = ®s_local->rfredn;
2802 /* Copy real rfred registers into the local copy */
2803 for (i=0; i<(sizeof (rfredn_t))/4; i++)
2804 ((u_int *)rfL)[i] = readl(iadev->reass_reg + i) & 0xffff;
2805 /* Copy real ffred registers into the local copy */
2806 for (i=0; i<(sizeof (ffredn_t))/4; i++)
2807 ((u_int *)ffL)[i] = readl(iadev->seg_reg + i) & 0xffff;
2809 if (copy_to_user(ia_cmds.buf, regs_local,sizeof(ia_regs_t))) {
2814 printk("Board %d registers dumped\n", board);
2820 if (!capable(CAP_NET_ADMIN)) return -EPERM;
2828 printk("skb = 0x%lx\n", (long)skb_peek(&iadev->tx_backlog));
2829 printk("rtn_q: 0x%lx\n",(long)ia_deque_rtn_q(&iadev->tx_return_q));
2834 struct k_sonet_stats *stats;
2835 stats = &PRIV(_ia_dev[board])->sonet_stats;
2836 printk("section_bip: %d\n", atomic_read(&stats->section_bip));
2837 printk("line_bip : %d\n", atomic_read(&stats->line_bip));
2838 printk("path_bip : %d\n", atomic_read(&stats->path_bip));
2839 printk("line_febe : %d\n", atomic_read(&stats->line_febe));
2840 printk("path_febe : %d\n", atomic_read(&stats->path_febe));
2841 printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
2842 printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
2843 printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
2844 printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
2849 if (!capable(CAP_NET_ADMIN)) return -EPERM;
2850 for (i = 1; i <= iadev->num_rx_desc; i++)
2851 free_desc(_ia_dev[board], i);
2852 writew( ~(RX_FREEQ_EMPT | RX_EXCP_RCVD),
2853 iadev->reass_reg+REASS_MASK_REG);
2860 if (!capable(CAP_NET_ADMIN)) return -EPERM;
2861 ia_frontend_intr(iadev);
2864 if (!capable(CAP_NET_ADMIN)) return -EPERM;
2867 IADebugFlag = ia_cmds.maddr;
2868 printk("New debug option loaded\n");
2884 static int ia_getsockopt(struct atm_vcc *vcc, int level, int optname,
2885 void __user *optval, int optlen)
2887 IF_EVENT(printk(">ia_getsockopt\n");)
2891 static int ia_setsockopt(struct atm_vcc *vcc, int level, int optname,
2892 void __user *optval, unsigned int optlen)
2894 IF_EVENT(printk(">ia_setsockopt\n");)
2898 static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
2901 struct tx_buf_desc __iomem *buf_desc_ptr;
2905 struct cpcs_trailer *trailer;
2906 struct ia_vcc *iavcc;
2908 iadev = INPH_IA_DEV(vcc->dev);
2909 iavcc = INPH_IA_VCC(vcc);
2910 if (!iavcc->txing) {
2911 printk("discard packet on closed VC\n");
2915 dev_kfree_skb_any(skb);
2919 if (skb->len > iadev->tx_buf_sz - 8) {
2920 printk("Transmit size over tx buffer size\n");
2924 dev_kfree_skb_any(skb);
2927 if ((unsigned long)skb->data & 3) {
2928 printk("Misaligned SKB\n");
2932 dev_kfree_skb_any(skb);
2935 /* Get a descriptor number from our free descriptor queue
2936 We get the descr number from the TCQ now, since I am using
2937 the TCQ as a free buffer queue. Initially TCQ will be
2938 initialized with all the descriptors and is hence, full.
2940 desc = get_desc (iadev, iavcc);
2943 comp_code = desc >> 13;
2946 if ((desc == 0) || (desc > iadev->num_tx_desc))
2948 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
2949 atomic_inc(&vcc->stats->tx);
2953 dev_kfree_skb_any(skb);
2954 return 0; /* return SUCCESS */
2959 IF_ERR(printk(DEV_LABEL "send desc:%d completion code %d error\n",
2963 /* remember the desc and vcc mapping */
2964 iavcc->vc_desc_cnt++;
2965 iadev->desc_tbl[desc-1].iavcc = iavcc;
2966 iadev->desc_tbl[desc-1].txskb = skb;
2967 IA_SKB_STATE(skb) = 0;
2969 iadev->ffL.tcq_rd += 2;
2970 if (iadev->ffL.tcq_rd > iadev->ffL.tcq_ed)
2971 iadev->ffL.tcq_rd = iadev->ffL.tcq_st;
2972 writew(iadev->ffL.tcq_rd, iadev->seg_reg+TCQ_RD_PTR);
2974 /* Put the descriptor number in the packet ready queue
2975 and put the updated write pointer in the DLE field
2977 *(u16*)(iadev->seg_ram+iadev->ffL.prq_wr) = desc;
2979 iadev->ffL.prq_wr += 2;
2980 if (iadev->ffL.prq_wr > iadev->ffL.prq_ed)
2981 iadev->ffL.prq_wr = iadev->ffL.prq_st;
2983 /* Figure out the exact length of the packet and padding required to
2984 make it aligned on a 48 byte boundary. */
2985 total_len = skb->len + sizeof(struct cpcs_trailer);
2986 total_len = ((total_len + 47) / 48) * 48;
2987 IF_TX(printk("ia packet len:%d padding:%d\n", total_len, total_len - skb->len);)
2989 /* Put the packet in a tx buffer */
2990 trailer = iadev->tx_buf[desc-1].cpcs;
2991 IF_TX(printk("Sent: skb = 0x%p skb->data: 0x%p len: %d, desc: %d\n",
2992 skb, skb->data, skb->len, desc);)
2993 trailer->control = 0;
2995 trailer->length = ((skb->len & 0xff) << 8) | ((skb->len & 0xff00) >> 8);
2996 trailer->crc32 = 0; /* not needed - dummy bytes */
2998 /* Display the packet */
2999 IF_TXPKT(printk("Sent data: len = %d MsgNum = %d\n",
3000 skb->len, tcnter++);
3001 xdump(skb->data, skb->len, "TX: ");
3004 /* Build the buffer descriptor */
3005 buf_desc_ptr = iadev->seg_ram+TX_DESC_BASE;
3006 buf_desc_ptr += desc; /* points to the corresponding entry */
3007 buf_desc_ptr->desc_mode = AAL5 | EOM_EN | APP_CRC32 | CMPL_INT;
3008 /* Huh ? p.115 of users guide describes this as a read-only register */
3009 writew(TRANSMIT_DONE, iadev->seg_reg+SEG_INTR_STATUS_REG);
3010 buf_desc_ptr->vc_index = vcc->vci;
3011 buf_desc_ptr->bytes = total_len;
3013 if (vcc->qos.txtp.traffic_class == ATM_ABR)
3014 clear_lockup (vcc, iadev);
3016 /* Build the DLE structure */
3017 wr_ptr = iadev->tx_dle_q.write;
3018 memset((caddr_t)wr_ptr, 0, sizeof(*wr_ptr));
3019 wr_ptr->sys_pkt_addr = dma_map_single(&iadev->pci->dev, skb->data,
3020 skb->len, DMA_TO_DEVICE);
3021 wr_ptr->local_pkt_addr = (buf_desc_ptr->buf_start_hi << 16) |
3022 buf_desc_ptr->buf_start_lo;
3023 /* wr_ptr->bytes = swap_byte_order(total_len); didn't seem to affect?? */
3024 wr_ptr->bytes = skb->len;
3026 /* hw bug - DLEs of 0x2d, 0x2e, 0x2f cause DMA lockup */
3027 if ((wr_ptr->bytes >> 2) == 0xb)
3028 wr_ptr->bytes = 0x30;
3030 wr_ptr->mode = TX_DLE_PSI;
3031 wr_ptr->prq_wr_ptr_data = 0;
3033 /* end is not to be used for the DLE q */
3034 if (++wr_ptr == iadev->tx_dle_q.end)
3035 wr_ptr = iadev->tx_dle_q.start;
3037 /* Build trailer dle */
3038 wr_ptr->sys_pkt_addr = iadev->tx_buf[desc-1].dma_addr;
3039 wr_ptr->local_pkt_addr = ((buf_desc_ptr->buf_start_hi << 16) |
3040 buf_desc_ptr->buf_start_lo) + total_len - sizeof(struct cpcs_trailer);
3042 wr_ptr->bytes = sizeof(struct cpcs_trailer);
3043 wr_ptr->mode = DMA_INT_ENABLE;
3044 wr_ptr->prq_wr_ptr_data = iadev->ffL.prq_wr;
3046 /* end is not to be used for the DLE q */
3047 if (++wr_ptr == iadev->tx_dle_q.end)
3048 wr_ptr = iadev->tx_dle_q.start;
3050 iadev->tx_dle_q.write = wr_ptr;
3051 ATM_DESC(skb) = vcc->vci;
3052 skb_queue_tail(&iadev->tx_dma_q, skb);
3054 atomic_inc(&vcc->stats->tx);
3055 iadev->tx_pkt_cnt++;
3056 /* Increment transaction counter */
3057 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
3060 /* add flow control logic */
3061 if (atomic_read(&vcc->stats->tx) % 20 == 0) {
3062 if (iavcc->vc_desc_cnt > 10) {
3063 vcc->tx_quota = vcc->tx_quota * 3 / 4;
3064 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
3065 iavcc->flow_inc = -1;
3066 iavcc->saved_tx_quota = vcc->tx_quota;
3067 } else if ((iavcc->flow_inc < 0) && (iavcc->vc_desc_cnt < 3)) {
3068 // vcc->tx_quota = 3 * iavcc->saved_tx_quota / 4;
3069 printk("Tx2: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
3070 iavcc->flow_inc = 0;
3074 IF_TX(printk("ia send done\n");)
3078 static int ia_send(struct atm_vcc *vcc, struct sk_buff *skb)
3081 unsigned long flags;
3083 iadev = INPH_IA_DEV(vcc->dev);
3084 if ((!skb)||(skb->len>(iadev->tx_buf_sz-sizeof(struct cpcs_trailer))))
3087 printk(KERN_CRIT "null skb in ia_send\n");
3088 else dev_kfree_skb_any(skb);
3091 spin_lock_irqsave(&iadev->tx_lock, flags);
3092 if (!test_bit(ATM_VF_READY,&vcc->flags)){
3093 dev_kfree_skb_any(skb);
3094 spin_unlock_irqrestore(&iadev->tx_lock, flags);
3097 ATM_SKB(skb)->vcc = vcc;
3099 if (skb_peek(&iadev->tx_backlog)) {
3100 skb_queue_tail(&iadev->tx_backlog, skb);
3103 if (ia_pkt_tx (vcc, skb)) {
3104 skb_queue_tail(&iadev->tx_backlog, skb);
3107 spin_unlock_irqrestore(&iadev->tx_lock, flags);
3112 static int ia_proc_read(struct atm_dev *dev,loff_t *pos,char *page)
3116 IADEV *iadev = INPH_IA_DEV(dev);
3118 if (iadev->phy_type == FE_25MBIT_PHY) {
3119 n = sprintf(page, " Board Type : Iphase5525-1KVC-128K\n");
3122 if (iadev->phy_type == FE_DS3_PHY)
3123 n = sprintf(page, " Board Type : Iphase-ATM-DS3");
3124 else if (iadev->phy_type == FE_E3_PHY)
3125 n = sprintf(page, " Board Type : Iphase-ATM-E3");
3126 else if (iadev->phy_type == FE_UTP_OPTION)
3127 n = sprintf(page, " Board Type : Iphase-ATM-UTP155");
3129 n = sprintf(page, " Board Type : Iphase-ATM-OC3");
3131 if (iadev->pci_map_size == 0x40000)
3132 n += sprintf(tmpPtr, "-1KVC-");
3134 n += sprintf(tmpPtr, "-4KVC-");
3136 if ((iadev->memType & MEM_SIZE_MASK) == MEM_SIZE_1M)
3137 n += sprintf(tmpPtr, "1M \n");
3138 else if ((iadev->memType & MEM_SIZE_MASK) == MEM_SIZE_512K)
3139 n += sprintf(tmpPtr, "512K\n");
3141 n += sprintf(tmpPtr, "128K\n");
3145 return sprintf(page, " Number of Tx Buffer: %u\n"
3146 " Size of Tx Buffer : %u\n"
3147 " Number of Rx Buffer: %u\n"
3148 " Size of Rx Buffer : %u\n"
3149 " Packets Receiverd : %u\n"
3150 " Packets Transmitted: %u\n"
3151 " Cells Received : %u\n"
3152 " Cells Transmitted : %u\n"
3153 " Board Dropped Cells: %u\n"
3154 " Board Dropped Pkts : %u\n",
3155 iadev->num_tx_desc, iadev->tx_buf_sz,
3156 iadev->num_rx_desc, iadev->rx_buf_sz,
3157 iadev->rx_pkt_cnt, iadev->tx_pkt_cnt,
3158 iadev->rx_cell_cnt, iadev->tx_cell_cnt,
3159 iadev->drop_rxcell, iadev->drop_rxpkt);
3164 static const struct atmdev_ops ops = {
3168 .getsockopt = ia_getsockopt,
3169 .setsockopt = ia_setsockopt,
3171 .phy_put = ia_phy_put,
3172 .phy_get = ia_phy_get,
3173 .change_qos = ia_change_qos,
3174 .proc_read = ia_proc_read,
3175 .owner = THIS_MODULE,
3178 static int ia_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
3180 struct atm_dev *dev;
3184 iadev = kzalloc(sizeof(*iadev), GFP_KERNEL);
3192 IF_INIT(printk("ia detected at bus:%d dev: %d function:%d\n",
3193 pdev->bus->number, PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));)
3194 if (pci_enable_device(pdev)) {
3196 goto err_out_free_iadev;
3198 dev = atm_dev_register(DEV_LABEL, &pdev->dev, &ops, -1, NULL);
3201 goto err_out_disable_dev;
3203 dev->dev_data = iadev;
3204 IF_INIT(printk(DEV_LABEL "registered at (itf :%d)\n", dev->number);)
3205 IF_INIT(printk("dev_id = 0x%p iadev->LineRate = %d \n", dev,
3208 pci_set_drvdata(pdev, dev);
3210 ia_dev[iadev_count] = iadev;
3211 _ia_dev[iadev_count] = dev;
3213 if (ia_init(dev) || ia_start(dev)) {
3214 IF_INIT(printk("IA register failed!\n");)
3216 ia_dev[iadev_count] = NULL;
3217 _ia_dev[iadev_count] = NULL;
3219 goto err_out_deregister_dev;
3221 IF_EVENT(printk("iadev_count = %d\n", iadev_count);)
3223 iadev->next_board = ia_boards;
3228 err_out_deregister_dev:
3229 atm_dev_deregister(dev);
3230 err_out_disable_dev:
3231 pci_disable_device(pdev);
3238 static void ia_remove_one(struct pci_dev *pdev)
3240 struct atm_dev *dev = pci_get_drvdata(pdev);
3241 IADEV *iadev = INPH_IA_DEV(dev);
3243 /* Disable phy interrupts */
3244 ia_phy_put(dev, ia_phy_get(dev, SUNI_RSOP_CIE) & ~(SUNI_RSOP_CIE_LOSE),
3248 if (dev->phy && dev->phy->stop)
3249 dev->phy->stop(dev);
3251 /* De-register device */
3252 free_irq(iadev->irq, dev);
3254 ia_dev[iadev_count] = NULL;
3255 _ia_dev[iadev_count] = NULL;
3256 IF_EVENT(printk("deregistering iav at (itf:%d)\n", dev->number);)
3257 atm_dev_deregister(dev);
3259 iounmap(iadev->base);
3260 pci_disable_device(pdev);
3268 static struct pci_device_id ia_pci_tbl[] = {
3269 { PCI_VENDOR_ID_IPHASE, 0x0008, PCI_ANY_ID, PCI_ANY_ID, },
3270 { PCI_VENDOR_ID_IPHASE, 0x0009, PCI_ANY_ID, PCI_ANY_ID, },
3273 MODULE_DEVICE_TABLE(pci, ia_pci_tbl);
3275 static struct pci_driver ia_driver = {
3277 .id_table = ia_pci_tbl,
3278 .probe = ia_init_one,
3279 .remove = ia_remove_one,
3282 static int __init ia_module_init(void)
3286 ret = pci_register_driver(&ia_driver);
3288 ia_timer.expires = jiffies + 3*HZ;
3289 add_timer(&ia_timer);
3291 printk(KERN_ERR DEV_LABEL ": no adapter found\n");
3295 static void __exit ia_module_exit(void)
3297 pci_unregister_driver(&ia_driver);
3299 del_timer_sync(&ia_timer);
3302 module_init(ia_module_init);
3303 module_exit(ia_module_exit);