2 * $Id: musycc.c,v 2.1 2007/08/15 23:32:17 rickd PMCC4_3_1B $
5 unsigned int max_intcnt
= 0;
6 unsigned int max_bh
= 0;
8 /*-----------------------------------------------------------------------------
11 * Copyright (C) 2007 One Stop Systems, Inc.
12 * Copyright (C) 2003-2006 SBE, Inc.
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * For further information, contact via email: support@onestopsystems.com
25 * One Stop Systems, Inc. Escondido, California U.S.A.
26 *-----------------------------------------------------------------------------
28 * RCS revision: $Revision: 2.1 $
29 * Last changed on $Date: 2007/08/15 23:32:17 $
30 * Changed by $Author: rickd $
31 *-----------------------------------------------------------------------------
33 * Revision 2.1 2007/08/15 23:32:17 rickd
34 * Use 'if 0' instead of GNU comment delimeter to avoid line wrap induced compiler errors.
36 * Revision 2.0 2007/08/15 22:13:20 rickd
37 * Update to printf pointer %p usage and correct some UINT to ULONG for
40 * Revision 1.7 2006/04/21 00:56:40 rickd
41 * workqueue files now prefixed with <sbecom> prefix.
43 * Revision 1.6 2005/10/27 18:54:19 rickd
44 * Clean out old code. Default to HDLC_FCS16, not TRANS.
46 * Revision 1.5 2005/10/17 23:55:28 rickd
47 * Initial port of NCOMM support patches from original work found
48 * in pmc_c4t1e1 as updated by NCOMM. Ref: CONFIG_SBE_PMCC4_NCOMM.
50 * Revision 1.4 2005/10/13 20:35:25 rickd
51 * Cleanup warning for unused <flags> variable.
53 * Revision 1.3 2005/10/13 19:19:22 rickd
54 * Disable redundant driver removal cleanup code.
56 * Revision 1.2 2005/10/11 18:36:16 rickd
57 * Clean up warning messages caused by de-implemented some <flags> associated
58 * with spin_lock() removals.
60 * Revision 1.1 2005/10/05 00:45:28 rickd
61 * Re-enable xmit on flow-controlled and full channel to fix restart hang.
62 * Add some temp spin-lock debug code (rld_spin_owner).
64 * Revision 1.0 2005/09/28 00:10:06 rickd
65 * Initial release for C4T1E1 support. Lots of transparent
68 *-----------------------------------------------------------------------------
71 char SBEid_pmcc4_musyccc
[] =
72 "@(#)musycc.c - $Revision: 2.1 $ (c) Copyright 2004-2006 SBE, Inc.";
74 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
76 #include <linux/types.h>
77 #include "pmcc4_sysdep.h"
78 #include <linux/kernel.h>
79 #include <linux/errno.h>
80 #include <linux/init.h>
81 #include "sbecom_inline_linux.h"
83 #include "pmcc4_private.h"
87 #ifdef SBE_INCLUDE_SYMBOLS
93 #define sd_find_chan(ci,ch) c4_find_chan(ch)
96 /*******************************************************************/
97 /* global driver variables */
99 extern int drvr_state
;
100 extern int log_level
;
104 extern int max_rxdesc_used
;
105 extern int max_txdesc_used
;
106 extern ci_t
*CI
; /* dummy pointr to board ZEROE's data - DEBUG
110 /*******************************************************************/
111 /* forward references */
112 void c4_fifo_free (mpi_t
*, int);
113 void c4_wk_chan_restart (mch_t
*);
114 void musycc_bh_tx_eom (mpi_t
*, int);
115 int musycc_chan_up (ci_t
*, int);
116 status_t __init
musycc_init (ci_t
*);
117 STATIC
void __init
musycc_init_port (mpi_t
*);
118 void musycc_intr_bh_tasklet (ci_t
*);
119 void musycc_serv_req (mpi_t
*, u_int32_t
);
120 void musycc_update_timeslots (mpi_t
*);
122 /*******************************************************************/
126 musycc_dump_rxbuffer_ring (mch_t
* ch
, int lockit
)
129 unsigned long flags
= 0;
136 spin_lock_irqsave (&ch
->ch_rxlock
, flags
);
138 if (ch
->rxd_num
== 0)
140 pr_info(" ZERO receive buffers allocated for this channel.");
144 m
= &ch
->mdr
[ch
->rxix_irq_srv
];
145 for (n
= ch
->rxd_num
; n
; n
--)
147 status
= le32_to_cpu (m
->status
);
149 pr_info("%c %08lx[%2d]: sts %08x (%c%c%c%c:%d.) Data [%08x] Next [%08x]\n",
150 (m
== &ch
->mdr
[ch
->rxix_irq_srv
]) ? 'F' : ' ',
151 (unsigned long) m
, n
,
153 m
->data
? (status
& HOST_RX_OWNED
? 'H' : 'M') : '-',
154 status
& POLL_DISABLED
? 'P' : '-',
155 status
& EOBIRQ_ENABLE
? 'b' : '-',
156 status
& EOMIRQ_ENABLE
? 'm' : '-',
157 status
& LENGTH_MASK
,
158 le32_to_cpu (m
->data
), le32_to_cpu (m
->next
));
159 #ifdef RLD_DUMP_BUFDATA
162 int len
= status
& LENGTH_MASK
;
165 if (m
->data
&& (status
& HOST_RX_OWNED
))
167 if (m
->data
) /* always dump regardless of valid RX
171 dp
= (u_int32_t
*) OS_phystov ((void *) (le32_to_cpu (m
->data
)));
173 pr_info(" %x[%x]: %08X %08X %08X %08x\n", (u_int32_t
) dp
, len
,
174 *dp
, *(dp
+ 1), *(dp
+ 2), *(dp
+ 3));
175 else if (len
>= 0x08)
176 pr_info(" %x[%x]: %08X %08X\n", (u_int32_t
) dp
, len
,
179 pr_info(" %x[%x]: %08X\n", (u_int32_t
) dp
, len
, *dp
);
191 spin_unlock_irqrestore (&ch
->ch_rxlock
, flags
);
199 musycc_dump_txbuffer_ring (mch_t
* ch
, int lockit
)
202 unsigned long flags
= 0;
208 spin_lock_irqsave (&ch
->ch_txlock
, flags
);
210 if (ch
->txd_num
== 0)
212 pr_info(" ZERO transmit buffers allocated for this channel.");
217 for (n
= ch
->txd_num
; n
; n
--)
219 status
= le32_to_cpu (m
->status
);
221 pr_info("%c%c %08lx[%2d]: sts %08x (%c%c%c%c:%d.) Data [%08x] Next [%08x]\n",
222 (m
== ch
->txd_usr_add
) ? 'F' : ' ',
223 (m
== ch
->txd_irq_srv
) ? 'L' : ' ',
224 (unsigned long) m
, n
,
226 m
->data
? (status
& MUSYCC_TX_OWNED
? 'M' : 'H') : '-',
227 status
& POLL_DISABLED
? 'P' : '-',
228 status
& EOBIRQ_ENABLE
? 'b' : '-',
229 status
& EOMIRQ_ENABLE
? 'm' : '-',
230 status
& LENGTH_MASK
,
231 le32_to_cpu (m
->data
), le32_to_cpu (m
->next
));
232 #ifdef RLD_DUMP_BUFDATA
235 int len
= status
& LENGTH_MASK
;
239 dp
= (u_int32_t
*) OS_phystov ((void *) (le32_to_cpu (m
->data
)));
241 pr_info(" %x[%x]: %08X %08X %08X %08x\n", (u_int32_t
) dp
, len
,
242 *dp
, *(dp
+ 1), *(dp
+ 2), *(dp
+ 3));
243 else if (len
>= 0x08)
244 pr_info(" %x[%x]: %08X %08X\n", (u_int32_t
) dp
, len
,
247 pr_info(" %x[%x]: %08X\n", (u_int32_t
) dp
, len
, *dp
);
259 spin_unlock_irqrestore (&ch
->ch_txlock
, flags
);
267 * The following supports a backdoor debug facility which can be used to
268 * display the state of a board's channel.
272 musycc_dump_ring (ci_t
* ci
, unsigned int chan
)
276 if (chan
>= MAX_CHANS_USED
)
278 return SBE_DRVR_FAIL
; /* E2BIG */
283 bh
= atomic_read (&ci
->bh_pending
);
284 pr_info(">> bh_pend %d [%d] ihead %d itail %d [%d] th_cnt %d bh_cnt %d wdcnt %d note %d\n",
285 bh
, max_bh
, ci
->iqp_headx
, ci
->iqp_tailx
, max_intcnt
,
286 ci
->intlog
.drvr_intr_thcount
,
287 ci
->intlog
.drvr_intr_bhcount
,
288 ci
->wdcount
, ci
->wd_notify
);
289 max_bh
= 0; /* reset counter */
290 max_intcnt
= 0; /* reset counter */
293 if (!(ch
= sd_find_chan (dummy
, chan
)))
295 pr_info(">> musycc_dump_ring: channel %d not up.\n", chan
);
298 pr_info(">> CI %p CHANNEL %3d @ %p: state %x status/p %x/%x\n", ci
, chan
, ch
, ch
->state
,
299 ch
->status
, ch
->p
.status
);
300 pr_info("--------------------------------\nTX Buffer Ring - Channel %d, txd_num %d. (bd/ch pend %d %d), TXD required %d, txpkt %lu\n",
302 (u_int32_t
) atomic_read (&ci
->tx_pending
), (u_int32_t
) atomic_read (&ch
->tx_pending
), ch
->txd_required
, ch
->s
.tx_packets
);
303 pr_info("++ User 0x%p IRQ_SRV 0x%p USR_ADD 0x%p QStopped %x, start_tx %x tx_full %d txd_free %d mode %x\n",
304 ch
->user
, ch
->txd_irq_srv
, ch
->txd_usr_add
,
305 sd_queue_stopped (ch
->user
),
306 ch
->ch_start_tx
, ch
->tx_full
, ch
->txd_free
, ch
->p
.chan_mode
);
307 musycc_dump_txbuffer_ring (ch
, 1);
308 pr_info("RX Buffer Ring - Channel %d, rxd_num %d. IRQ_SRV[%d] 0x%p, start_rx %x rxpkt %lu\n",
309 chan
, ch
->rxd_num
, ch
->rxix_irq_srv
,
310 &ch
->mdr
[ch
->rxix_irq_srv
], ch
->ch_start_rx
, ch
->s
.rx_packets
);
311 musycc_dump_rxbuffer_ring (ch
, 1);
313 return SBE_DRVR_SUCCESS
;
318 musycc_dump_rings (ci_t
* ci
, unsigned int start_chan
)
322 for (chan
= start_chan
; chan
< (start_chan
+ 5); chan
++)
323 musycc_dump_ring (ci
, chan
);
324 return SBE_DRVR_SUCCESS
;
329 * NOTE on musycc_init_mdt(): These MUSYCC writes are only operational after
330 * a MUSYCC GROUP_INIT command has been issued.
334 musycc_init_mdt (mpi_t
* pi
)
336 u_int32_t
*addr
, cfg
;
340 * This Idle Code insertion takes effect prior to channel's first
341 * transmitted message. After that, each message contains its own Idle
342 * Code information which is to be issued after the message is
343 * transmitted (Ref.MUSYCC 5.2.2.3: MCENBL bit in Group Configuration
347 addr
= (u_int32_t
*) ((u_long
) pi
->reg
+ MUSYCC_MDT_BASE03_ADDR
);
348 cfg
= CFG_CH_FLAG_7E
<< IDLE_CODE
;
350 for (i
= 0; i
< 32; addr
++, i
++)
352 pci_write_32 (addr
, cfg
);
357 /* Set TX thp to the next unprocessed md */
360 musycc_update_tx_thp (mch_t
* ch
)
365 spin_lock_irqsave (&ch
->ch_txlock
, flags
);
368 md
= ch
->txd_irq_srv
;
372 /* No MDs with buffers to process */
373 spin_unlock_irqrestore (&ch
->ch_txlock
, flags
);
376 if ((le32_to_cpu (md
->status
)) & MUSYCC_TX_OWNED
)
378 /* this is the MD to restart TX with */
382 * Otherwise, we have a valid, host-owned message descriptor which
383 * has been successfully transmitted and whose buffer can be freed,
384 * so... process this MD, it's owned by the host. (This might give
385 * as a new, updated txd_irq_srv.)
387 musycc_bh_tx_eom (ch
->up
, ch
->gchan
);
389 md
= ch
->txd_irq_srv
;
390 ch
->up
->regram
->thp
[ch
->gchan
] = cpu_to_le32 (OS_vtophys (md
));
396 ch
->txd_required
= 0;
397 sd_enable_xmit (ch
->user
); /* re-enable to catch flow controlled
400 spin_unlock_irqrestore (&ch
->ch_txlock
, flags
);
402 #ifdef RLD_TRANS_DEBUG
403 pr_info("++ musycc_update_tx_thp[%d]: setting thp = %p, sts %x\n", ch
->channum
, md
, md
->status
);
408 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,41)
410 * This is the workq task executed by the OS when our queue_work() is
411 * scheduled and run. It can fire off either RX or TX ACTIVATION depending
412 * upon the channel's ch_start_tx and ch_start_rx variables. This routine
413 * is implemented as a work queue so that the call to the service request is
414 * able to sleep, awaiting an interrupt acknowledgment response (SACK) from
419 musycc_wq_chan_restart (void *arg
) /* channel private structure */
428 ch
= container_of(arg
, struct c4_chan_info
, ch_work
);
431 #ifdef RLD_TRANS_DEBUG
432 pr_info("wq_chan_restart[%d]: start_RT[%d/%d] status %x\n",
433 ch
->channum
, ch
->ch_start_rx
, ch
->ch_start_tx
, ch
->status
);
437 /**********************************/
438 /** check for RX restart request **/
439 /**********************************/
441 if ((ch
->ch_start_rx
) && (ch
->status
& RX_ENABLED
))
445 #if defined(RLD_TRANS_DEBUG) || defined(RLD_RXACT_DEBUG)
447 static int hereb4
= 7;
449 if (hereb4
) /* RLD DEBUG */
452 #ifdef RLD_TRANS_DEBUG
453 md
= &ch
->mdr
[ch
->rxix_irq_srv
];
454 pr_info("++ musycc_wq_chan_restart[%d] CHAN RX ACTIVATE: rxix_irq_srv %d, md %p sts %x, rxpkt %lu\n",
455 ch
->channum
, ch
->rxix_irq_srv
, md
, le32_to_cpu (md
->status
),
457 #elif defined(RLD_RXACT_DEBUG)
458 md
= &ch
->mdr
[ch
->rxix_irq_srv
];
459 pr_info("++ musycc_wq_chan_restart[%d] CHAN RX ACTIVATE: rxix_irq_srv %d, md %p sts %x, rxpkt %lu\n",
460 ch
->channum
, ch
->rxix_irq_srv
, md
, le32_to_cpu (md
->status
),
462 musycc_dump_rxbuffer_ring (ch
, 1); /* RLD DEBUG */
467 musycc_serv_req (pi
, SR_CHANNEL_ACTIVATE
| SR_RX_DIRECTION
| ch
->gchan
);
469 /**********************************/
470 /** check for TX restart request **/
471 /**********************************/
473 if ((ch
->ch_start_tx
) && (ch
->status
& TX_ENABLED
))
475 /* find next unprocessed message, then set TX thp to it */
476 musycc_update_tx_thp (ch
);
479 spin_lock_irqsave (&ch
->ch_txlock
, flags
);
481 md
= ch
->txd_irq_srv
;
484 #ifdef RLD_TRANS_DEBUG
485 pr_info("-- musycc_wq_chan_restart[%d]: WARNING, starting NULL md\n", ch
->channum
);
488 spin_unlock_irqrestore (&ch
->ch_txlock
, flags
);
490 } else if (md
->data
&& ((le32_to_cpu (md
->status
)) & MUSYCC_TX_OWNED
))
494 spin_unlock_irqrestore (&ch
->ch_txlock
, flags
); /* allow interrupts for service request */
496 #ifdef RLD_TRANS_DEBUG
497 pr_info("++ musycc_wq_chan_restart() CHAN TX ACTIVATE: chan %d txd_irq_srv %p = sts %x, txpkt %lu\n",
498 ch
->channum
, ch
->txd_irq_srv
, ch
->txd_irq_srv
->status
, ch
->s
.tx_packets
);
500 musycc_serv_req (pi
, SR_CHANNEL_ACTIVATE
| SR_TX_DIRECTION
| ch
->gchan
);
502 #ifdef RLD_RESTART_DEBUG
505 /* retain request to start until retried and we have data to xmit */
506 pr_info("-- musycc_wq_chan_restart[%d]: DELAYED due to md %p sts %x data %x, start_tx %x\n",
508 le32_to_cpu (md
->status
),
509 le32_to_cpu (md
->data
), ch
->ch_start_tx
);
510 musycc_dump_txbuffer_ring (ch
, 0);
512 spin_unlock_irqrestore (&ch
->ch_txlock
, flags
); /* allow interrupts for service request */
522 * Channel restart either fires of a workqueue request (2.6) or lodges a
523 * watchdog activation sequence (2.4).
527 musycc_chan_restart (mch_t
* ch
)
529 #ifdef RLD_RESTART_DEBUG
530 pr_info("++ musycc_chan_restart[%d]: txd_irq_srv @ %p = sts %x\n",
531 ch
->channum
, ch
->txd_irq_srv
, ch
->txd_irq_srv
->status
);
534 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,41)
535 /* 2.6 - find next unprocessed message, then set TX thp to it */
536 #ifdef RLD_RESTART_DEBUG
537 pr_info(">> musycc_chan_restart: scheduling Chan %x workQ @ %p\n", ch
->channum
, &ch
->ch_work
);
539 c4_wk_chan_restart (ch
); /* work queue mechanism fires off: Ref:
540 * musycc_wq_chan_restart () */
545 /* 2.4 - find next unprocessed message, then set TX thp to it */
546 #ifdef RLD_RESTART_DEBUG
547 pr_info(">> musycc_chan_restart: scheduling Chan %x start_tx %x\n", ch
->channum
, ch
->ch_start_tx
);
549 /* restart transmission from background loop */
550 ch
->up
->up
->wd_notify
= WD_NOTIFY_1TX
;
557 musycc_cleanup (ci_t
* ci
)
562 /* free up driver resources */
563 ci
->state
= C_INIT
; /* mark as hardware not available */
565 for (i
= 0; i
< ci
->max_ports
; i
++)
568 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,41)
569 c4_wq_port_cleanup (pi
);
571 for (j
= 0; j
< MUSYCC_NCHANS
; j
++)
574 OS_kfree (pi
->chan
[j
]); /* free mch_t struct */
576 OS_kfree (pi
->regram_saved
);
579 /* obsolete - watchdog is now static w/in ci_t */
580 OS_free_watchdog (ci
->wd
);
582 OS_kfree (ci
->iqd_p_saved
);
588 rld_put_led (mpi_t
* pi
, u_int32_t ledval
)
590 static u_int32_t led
= 0;
597 pci_write_32 ((u_int32_t
*) &pi
->up
->cpldbase
->leds
, led
); /* RLD DEBUG TRANHANG */
601 #define MUSYCC_SR_RETRY_CNT 9
604 musycc_serv_req (mpi_t
* pi
, u_int32_t req
)
606 volatile u_int32_t r
;
610 * PORT NOTE: Semaphore protect service loop guarantees only a single
611 * operation at a time. Per MUSYCC Manual - "Issuing service requests to
612 * the same channel group without first receiving ACK from each request
613 * may cause the host to lose track of which service request has been
617 SD_SEM_TAKE (&pi
->sr_sem_busy
, "serv"); /* only 1 thru here, per
620 if (pi
->sr_last
== req
)
622 #ifdef RLD_TRANS_DEBUG
623 pr_info(">> same SR, Port %d Req %x\n", pi
->portnum
, req
);
627 * The most likely repeated request is the channel activation command
628 * which follows the occurrence of a Transparent mode TX ONR or a
629 * BUFF error. If the previous command was a CHANNEL ACTIVATE,
630 * precede it with a NOOP command in order maintain coherent control
631 * of this current (re)ACTIVATE.
634 r
= (pi
->sr_last
& ~SR_GCHANNEL_MASK
);
635 if ((r
== (SR_CHANNEL_ACTIVATE
| SR_TX_DIRECTION
)) ||
636 (r
== (SR_CHANNEL_ACTIVATE
| SR_RX_DIRECTION
)))
638 #ifdef RLD_TRANS_DEBUG
639 pr_info(">> same CHAN ACT SR, Port %d Req %x => issue SR_NOOP CMD\n", pi
->portnum
, req
);
641 SD_SEM_GIVE (&pi
->sr_sem_busy
); /* allow this next request */
642 musycc_serv_req (pi
, SR_NOOP
);
643 SD_SEM_TAKE (&pi
->sr_sem_busy
, "serv"); /* relock & continue w/
645 } else if (req
== SR_NOOP
)
647 /* no need to issue back-to-back SR_NOOP commands at this time */
648 #ifdef RLD_TRANS_DEBUG
649 pr_info(">> same Port SR_NOOP skipped, Port %d\n", pi
->portnum
);
651 SD_SEM_GIVE (&pi
->sr_sem_busy
); /* allow this next request */
658 pci_write_32 ((u_int32_t
*) &pi
->reg
->srd
, req
);
662 * Per MUSYCC Manual, Section 6.1,2 - "When writing an SCR service
663 * request, the host must ensure at least one PCI bus clock cycle has
664 * elapsed before writing another service request. To meet this minimum
665 * elapsed service request write timing interval, it is recommended that
666 * the host follow any SCR write with another operation which reads from
669 r
= pci_read_32 ((u_int32_t
*) &pi
->reg
->srd
); /* adhere to write
670 * timing imposition */
673 if ((r
!= req
) && (req
!= SR_CHIP_RESET
) && (++rcnt
<= MUSYCC_SR_RETRY_CNT
))
675 if (log_level
>= LOG_MONITOR
)
676 pr_info("%s: %d - reissue srv req/last %x/%x (hdw reads %x), Chan %d.\n",
677 pi
->up
->devname
, rcnt
, req
, pi
->sr_last
, r
,
678 (pi
->portnum
* MUSYCC_NCHANS
) + (req
& 0x1f));
679 OS_uwait_dummy (); /* this delay helps reduce reissue counts
680 * (reason not yet researched) */
683 if (rcnt
> MUSYCC_SR_RETRY_CNT
)
685 pr_warning("%s: failed service request (#%d)= %x, group %d.\n",
686 pi
->up
->devname
, MUSYCC_SR_RETRY_CNT
, req
, pi
->portnum
);
687 SD_SEM_GIVE (&pi
->sr_sem_busy
); /* allow any next request */
690 if (req
== SR_CHIP_RESET
)
693 * PORT NOTE: the CHIP_RESET command is NOT ack'd by the MUSYCC, thus
694 * the upcoming delay is used. Though the MUSYCC documentation
695 * suggests a read-after-write would supply the required delay, it's
696 * unclear what CPU/BUS clock speeds might have been assumed when
697 * suggesting this 'lack of ACK' workaround. Thus the use of uwait.
699 OS_uwait (100000, "icard"); /* 100ms */
703 SD_SEM_TAKE (&pi
->sr_sem_wait
, "sakack"); /* sleep until SACK
704 * interrupt occurs */
706 SD_SEM_GIVE (&pi
->sr_sem_busy
); /* allow any next request */
710 #ifdef SBE_PMCC4_ENABLE
712 musycc_update_timeslots (mpi_t
* pi
)
715 char e1mode
= IS_FRAME_ANY_E1 (pi
->p
.port_mode
);
717 for (i
= 0; i
< 32; i
++)
719 int usedby
= 0, last
= 0, ts
, j
, bits
[8];
721 u_int8_t lastval
= 0;
723 if (((i
== 0) && e1mode
) || /* disable if E1 mode */
724 ((i
== 16) && ((pi
->p
.port_mode
== CFG_FRAME_E1CRC_CAS
) || (pi
->p
.port_mode
== CFG_FRAME_E1CRC_CAS_AMI
)))
725 || ((i
> 23) && (!e1mode
))) /* disable if T1 mode */
727 pi
->tsm
[i
] = 0xff; /* make tslot unavailable for this mode */
730 pi
->tsm
[i
] = 0x00; /* make tslot available for assignment */
732 for (j
= 0; j
< 8; j
++)
734 for (ch
= 0; ch
< MUSYCC_NCHANS
; ch
++)
736 if ((pi
->chan
[ch
]->state
== UP
) && (pi
->chan
[ch
]->p
.bitmask
[i
]))
740 lastval
= pi
->chan
[ch
]->p
.bitmask
[i
];
741 for (j
= 0; j
< 8; j
++)
742 if (lastval
& (1 << j
))
744 pi
->tsm
[i
] |= lastval
;
749 else if ((usedby
== 1) && (lastval
== 0xff))
750 ts
= (4 << 5) | last
;
751 else if ((usedby
== 1) && (lastval
== 0x7f))
752 ts
= (5 << 5) | last
;
758 ts
= (6 << 5) | (idx
= last
);
760 ts
= (7 << 5) | (idx
= bits
[0]);
761 for (j
= 1; j
< 8; j
++)
763 pi
->regram
->rscm
[idx
* 8 + j
] = (bits
[j
] < 0) ? 0 : (0x80 | bits
[j
]);
764 pi
->regram
->tscm
[idx
* 8 + j
] = (bits
[j
] < 0) ? 0 : (0x80 | bits
[j
]);
767 pi
->regram
->rtsm
[i
] = ts
;
768 pi
->regram
->ttsm
[i
] = ts
;
772 musycc_serv_req (pi
, SR_TIMESLOT_MAP
| SR_RX_DIRECTION
);
773 musycc_serv_req (pi
, SR_TIMESLOT_MAP
| SR_TX_DIRECTION
);
774 musycc_serv_req (pi
, SR_SUBCHANNEL_MAP
| SR_RX_DIRECTION
);
775 musycc_serv_req (pi
, SR_SUBCHANNEL_MAP
| SR_TX_DIRECTION
);
780 #ifdef SBE_WAN256T3_ENABLE
782 musycc_update_timeslots (mpi_t
* pi
)
786 u_int8_t ts
, hmask
, tsen
;
790 #ifdef SBE_PMCC4_ENABLE
791 hmask
= (0x1f << pi
->up
->p
.hypersize
) & 0x1f;
793 #ifdef SBE_WAN256T3_ENABLE
794 hmask
= (0x1f << hyperdummy
) & 0x1f;
796 for (i
= 0; i
< 128; i
++)
798 gchan
= ((pi
->portnum
* MUSYCC_NCHANS
) + (i
& hmask
)) % MUSYCC_NCHANS
;
799 ch
= pi
->chan
[gchan
];
803 tsen
= MODE_64KBPS
; /* also the default */
804 ts
= ((pi
->portnum
% 4) == (i
/ 32)) ? (tsen
<< 5) | (i
& hmask
) : 0;
805 pi
->regram
->rtsm
[i
] = ts
;
806 pi
->regram
->ttsm
[i
] = ts
;
809 musycc_serv_req (pi
, SR_TIMESLOT_MAP
| SR_RX_DIRECTION
);
810 musycc_serv_req (pi
, SR_TIMESLOT_MAP
| SR_TX_DIRECTION
);
816 * This routine converts a generic library channel configuration parameter
817 * into a hardware specific register value (IE. MUSYCC CCD Register).
820 musycc_chan_proto (int proto
)
826 case CFG_CH_PROTO_TRANS
: /* 0 */
827 reg
= MUSYCC_CCD_TRANS
;
829 case CFG_CH_PROTO_SS7
: /* 1 */
830 reg
= MUSYCC_CCD_SS7
;
833 case CFG_CH_PROTO_ISLP_MODE
: /* 4 */
834 case CFG_CH_PROTO_HDLC_FCS16
: /* 2 */
835 reg
= MUSYCC_CCD_HDLC_FCS16
;
837 case CFG_CH_PROTO_HDLC_FCS32
: /* 3 */
838 reg
= MUSYCC_CCD_HDLC_FCS32
;
845 #ifdef SBE_WAN256T3_ENABLE
847 musycc_init_port (mpi_t
* pi
)
849 pci_write_32 ((u_int32_t
*) &pi
->reg
->gbp
, OS_vtophys (pi
->regram
));
852 __constant_cpu_to_le32 (MUSYCC_GRCD_RX_ENABLE
|
853 MUSYCC_GRCD_TX_ENABLE
|
854 MUSYCC_GRCD_SF_ALIGN
|
855 MUSYCC_GRCD_SUBCHAN_DISABLE
|
856 MUSYCC_GRCD_OOFMP_DISABLE
|
857 MUSYCC_GRCD_COFAIRQ_DISABLE
|
858 MUSYCC_GRCD_MC_ENABLE
|
859 (MUSYCC_GRCD_POLLTH_32
<< MUSYCC_GRCD_POLLTH_SHIFT
));
862 __constant_cpu_to_le32 (MUSYCC_PCD_E1X4_MODE
|
863 MUSYCC_PCD_TXDATA_RISING
|
864 MUSYCC_PCD_TX_DRIVEN
);
866 /* Message length descriptor */
867 pi
->regram
->mld
= __constant_cpu_to_le32 (max_mru
| (max_mru
<< 16));
870 musycc_serv_req (pi
, SR_GROUP_INIT
| SR_RX_DIRECTION
);
871 musycc_serv_req (pi
, SR_GROUP_INIT
| SR_TX_DIRECTION
);
873 musycc_init_mdt (pi
);
875 musycc_update_timeslots (pi
);
881 musycc_init (ci_t
* ci
)
883 char *regaddr
; /* temp for address boundary calculations */
886 OS_sem_init (&ci
->sem_wdbusy
, SEM_AVAILABLE
); /* watchdog exclusion */
889 * Per MUSYCC manual, Section 6.3.4 - "The host must allocate a dword
890 * aligned memory segment for interrupt queue pointers."
893 #define INT_QUEUE_BOUNDARY 4
895 regaddr
= OS_kmalloc ((INT_QUEUE_SIZE
+ 1) * sizeof (u_int32_t
));
898 ci
->iqd_p_saved
= regaddr
; /* save orig value for free's usage */
899 ci
->iqd_p
= (u_int32_t
*) ((unsigned long) (regaddr
+ INT_QUEUE_BOUNDARY
- 1) &
900 (~(INT_QUEUE_BOUNDARY
- 1))); /* this calculates
901 * closest boundary */
903 for (i
= 0; i
< INT_QUEUE_SIZE
; i
++)
905 ci
->iqd_p
[i
] = __constant_cpu_to_le32 (INT_EMPTY_ENTRY
);
908 for (i
= 0; i
< ci
->max_port
; i
++)
910 mpi_t
*pi
= &ci
->port
[i
];
913 * Per MUSYCC manual, Section 6.3.2 - "The host must allocate a 2KB
914 * bound memory segment for Channel Group 0."
917 #define GROUP_BOUNDARY 0x800
919 regaddr
= OS_kmalloc (sizeof (struct musycc_groupr
) + GROUP_BOUNDARY
);
922 for (gchan
= 0; gchan
< i
; gchan
++)
924 pi
= &ci
->port
[gchan
];
930 pi
->regram_saved
= regaddr
; /* save orig value for free's usage */
931 pi
->regram
= (struct musycc_groupr
*) ((unsigned long) (regaddr
+ GROUP_BOUNDARY
- 1) &
932 (~(GROUP_BOUNDARY
- 1))); /* this calculates
933 * closest boundary */
936 /* any board centric MUSYCC commands will use group ZERO as its "home" */
937 ci
->regram
= ci
->port
[0].regram
;
938 musycc_serv_req (&ci
->port
[0], SR_CHIP_RESET
);
940 pci_write_32 ((u_int32_t
*) &ci
->reg
->gbp
, OS_vtophys (ci
->regram
));
941 pci_flush_write (ci
);
942 #ifdef CONFIG_SBE_PMCC4_NCOMM
943 ci
->regram
->__glcd
= __constant_cpu_to_le32 (GCD_MAGIC
);
945 /* standard driver POLLS for INTB via CPLD register */
946 ci
->regram
->__glcd
= __constant_cpu_to_le32 (GCD_MAGIC
| MUSYCC_GCD_INTB_DISABLE
);
949 ci
->regram
->__iqp
= cpu_to_le32 (OS_vtophys (&ci
->iqd_p
[0]));
950 ci
->regram
->__iql
= __constant_cpu_to_le32 (INT_QUEUE_SIZE
- 1);
951 pci_write_32 ((u_int32_t
*) &ci
->reg
->dacbp
, 0);
954 ci
->state
= C_RUNNING
; /* mark as full interrupt processing
957 musycc_serv_req (&ci
->port
[0], SR_GLOBAL_INIT
); /* FIRST INTERRUPT ! */
959 /* sanity check settable parameters */
963 pr_warning("Maximum allowed MRU exceeded, resetting %d to %d.\n",
969 pr_warning("Maximum allowed MTU exceeded, resetting %d to %d.\n",
973 #ifdef SBE_WAN256T3_ENABLE
974 for (i
= 0; i
< MUSYCC_NPORTS
; i
++)
975 musycc_init_port (&ci
->port
[i
]);
978 return SBE_DRVR_SUCCESS
; /* no error */
983 musycc_bh_tx_eom (mpi_t
* pi
, int gchan
)
989 #ifndef SBE_ISR_INLINE
994 volatile u_int32_t status
;
996 ch
= pi
->chan
[gchan
];
997 if (ch
== 0 || ch
->state
!= UP
)
999 if (log_level
>= LOG_ERROR
)
1000 pr_info("%s: intr: xmit EOM on uninitialized channel %d\n",
1001 pi
->up
->devname
, gchan
);
1003 if (ch
== 0 || ch
->mdt
== 0)
1004 return; /* note: mdt==0 implies a malloc()
1005 * failure w/in chan_up() routine */
1008 #ifdef SBE_ISR_INLINE
1009 spin_lock_irq (&ch
->ch_txlock
);
1011 spin_lock_irqsave (&ch
->ch_txlock
, flags
);
1017 md
= ch
->txd_irq_srv
;
1018 status
= le32_to_cpu (md
->status
);
1021 * Note: Per MUSYCC Ref 6.4.9, the host does not poll a host-owned
1022 * Transmit Buffer Descriptor during Transparent Mode.
1024 if (status
& MUSYCC_TX_OWNED
)
1026 int readCount
, loopCount
;
1028 /***********************************************************/
1031 /* Under certain PCI Bus loading conditions, the data */
1032 /* associated with an update of Shared Memory is delayed */
1033 /* relative to its PCI Interrupt. This is caught when */
1034 /* the host determines it does not yet OWN the descriptor. */
1035 /***********************************************************/
1038 while (status
& MUSYCC_TX_OWNED
)
1040 for (loopCount
= 0; loopCount
< 0x30; loopCount
++)
1041 OS_uwait_dummy (); /* use call to avoid optimization
1042 * removal of dummy delay */
1044 status
= le32_to_cpu (md
->status
);
1045 if (readCount
++ > 40)
1046 break; /* don't wait any longer */
1048 if (status
& MUSYCC_TX_OWNED
)
1050 if (log_level
>= LOG_MONITOR
)
1052 pr_info("%s: Port %d Chan %2d - unexpected TX msg ownership intr (md %p sts %x)\n",
1053 pi
->up
->devname
, pi
->portnum
, ch
->channum
,
1055 pr_info("++ User 0x%p IRQ_SRV 0x%p USR_ADD 0x%p QStopped %x, start_tx %x tx_full %d txd_free %d mode %x\n",
1056 ch
->user
, ch
->txd_irq_srv
, ch
->txd_usr_add
,
1057 sd_queue_stopped (ch
->user
),
1058 ch
->ch_start_tx
, ch
->tx_full
, ch
->txd_free
, ch
->p
.chan_mode
);
1059 musycc_dump_txbuffer_ring (ch
, 0);
1061 break; /* Not our mdesc, done */
1064 if (log_level
>= LOG_MONITOR
)
1065 pr_info("%s: Port %d Chan %2d - recovered TX msg ownership [%d] (md %p sts %x)\n",
1066 pi
->up
->devname
, pi
->portnum
, ch
->channum
, readCount
, md
, status
);
1069 ch
->txd_irq_srv
= md
->snext
;
1072 if (md
->mem_token
!= 0)
1074 /* upcount channel */
1075 atomic_sub (OS_mem_token_tlen (md
->mem_token
), &ch
->tx_pending
);
1077 atomic_sub (OS_mem_token_tlen (md
->mem_token
), &pi
->up
->tx_pending
);
1078 #ifdef SBE_WAN256T3_ENABLE
1079 if (!atomic_read (&pi
->up
->tx_pending
))
1080 wan256t3_led (pi
->up
, LED_TX
, 0);
1083 #ifdef CONFIG_SBE_WAN256T3_NCOMM
1084 /* callback that our packet was sent */
1086 int hdlcnum
= (pi
->portnum
* 32 + gchan
);
1090 if (nciProcess_TX_complete
)
1091 (*nciProcess_TX_complete
) (hdlcnum
,
1092 getuserbychan (gchan
));
1095 #endif /*** CONFIG_SBE_WAN256T3_NCOMM ***/
1097 OS_mem_token_free_irq (md
->mem_token
);
1101 #ifdef RLD_TXFULL_DEBUG
1102 if (log_level
>= LOG_MONITOR2
)
1103 pr_info("~~ tx_eom: tx_full %x txd_free %d -> %d\n",
1104 ch
->tx_full
, ch
->txd_free
, ch
->txd_free
+ 1);
1109 if ((ch
->p
.chan_mode
!= CFG_CH_PROTO_TRANS
) && (status
& EOBIRQ_ENABLE
))
1111 if (log_level
>= LOG_MONITOR
)
1112 pr_info("%s: Mode (%x) incorrect EOB status (%x)\n",
1113 pi
->up
->devname
, ch
->p
.chan_mode
, status
);
1114 if ((status
& EOMIRQ_ENABLE
) == 0)
1118 while ((ch
->p
.chan_mode
!= CFG_CH_PROTO_TRANS
) && ((status
& EOMIRQ_ENABLE
) == 0));
1120 * NOTE: (The above 'while' is coupled w/ previous 'do', way above.) Each
1121 * Transparent data buffer has the EOB bit, and NOT the EOM bit, set and
1122 * will furthermore have a separate IQD associated with each messages
1128 * Smooth flow control hysterisis by maintaining task stoppage until half
1129 * the available write buffers are available.
1131 if (ch
->tx_full
&& (ch
->txd_free
>= (ch
->txd_num
/ 2)))
1134 * Then, only releave task stoppage if we actually have enough
1135 * buffers to service the last requested packet. It may require MORE
1136 * than half the available!
1138 if (ch
->txd_free
>= ch
->txd_required
)
1141 #ifdef RLD_TXFULL_DEBUG
1142 if (log_level
>= LOG_MONITOR2
)
1143 pr_info("tx_eom[%d]: enable xmit tx_full no more, txd_free %d txd_num/2 %d\n",
1145 ch
->txd_free
, ch
->txd_num
/ 2);
1148 ch
->txd_required
= 0;
1149 sd_enable_xmit (ch
->user
); /* re-enable to catch flow controlled
1153 #ifdef RLD_TXFULL_DEBUG
1154 else if (ch
->tx_full
)
1156 if (log_level
>= LOG_MONITOR2
)
1157 pr_info("tx_eom[%d]: bypass TX enable though room available? (txd_free %d txd_num/2 %d)\n",
1159 ch
->txd_free
, ch
->txd_num
/ 2);
1165 #ifdef SBE_ISR_INLINE
1166 spin_unlock_irq (&ch
->ch_txlock
);
1168 spin_unlock_irqrestore (&ch
->ch_txlock
, flags
);
1175 musycc_bh_rx_eom (mpi_t
* pi
, int gchan
)
1180 volatile u_int32_t status
;
1183 ch
= pi
->chan
[gchan
];
1184 if (ch
== 0 || ch
->state
!= UP
)
1186 if (log_level
> LOG_ERROR
)
1187 pr_info("%s: intr: receive EOM on uninitialized channel %d\n",
1188 pi
->up
->devname
, gchan
);
1192 return; /* can this happen ? */
1197 md
= &ch
->mdr
[ch
->rxix_irq_srv
];
1198 status
= le32_to_cpu (md
->status
);
1199 if (!(status
& HOST_RX_OWNED
))
1200 break; /* Not our mdesc, done */
1202 error
= (status
>> 16) & 0xf;
1205 #ifdef CONFIG_SBE_WAN256T3_NCOMM
1206 int hdlcnum
= (pi
->portnum
* 32 + gchan
);
1209 * if the packet number belongs to NCOMM, then send it to the TMS
1214 if (nciProcess_RX_packet
)
1215 (*nciProcess_RX_packet
) (hdlcnum
, status
& 0x3fff, m
, ch
->user
);
1217 #endif /*** CONFIG_SBE_WAN256T3_NCOMM ***/
1220 if ((m2
= OS_mem_token_alloc (max_mru
)))
1222 /* substitute the mbuf+cluster */
1224 md
->data
= cpu_to_le32 (OS_vtophys (OS_mem_token_data (m2
)));
1226 /* pass the received mbuf upward */
1227 sd_recv_consume (m
, status
& LENGTH_MASK
, ch
->user
);
1229 ch
->s
.rx_bytes
+= status
& LENGTH_MASK
;
1235 } else if (error
== ERR_FCS
)
1237 ch
->s
.rx_crc_errors
++;
1238 } else if (error
== ERR_ALIGN
)
1240 ch
->s
.rx_missed_errors
++;
1241 } else if (error
== ERR_ABT
)
1243 ch
->s
.rx_missed_errors
++;
1244 } else if (error
== ERR_LNG
)
1246 ch
->s
.rx_length_errors
++;
1247 } else if (error
== ERR_SHT
)
1249 ch
->s
.rx_length_errors
++;
1253 if (ch
->p
.chan_mode
== CFG_CH_PROTO_TRANS
)
1254 status
|= EOBIRQ_ENABLE
;
1255 md
->status
= cpu_to_le32 (status
);
1257 /* Check next mdesc in the ring */
1258 if (++ch
->rxix_irq_srv
>= ch
->rxd_num
)
1259 ch
->rxix_irq_srv
= 0;
1266 musycc_intr_th_handler (void *devp
)
1268 ci_t
*ci
= (ci_t
*) devp
;
1269 volatile u_int32_t status
, currInt
= 0;
1270 u_int32_t nextInt
, intCnt
;
1273 * Hardware not available, potential interrupt hang. But since interrupt
1274 * might be shared, just return.
1276 if (ci
->state
== C_INIT
)
1281 * Marked as hardware available. Don't service interrupts, just clear the
1285 if (ci
->state
== C_IDLE
)
1287 status
= pci_read_32 ((u_int32_t
*) &ci
->reg
->isd
);
1289 /* clear the interrupt but process nothing else */
1290 pci_write_32 ((u_int32_t
*) &ci
->reg
->isd
, status
);
1296 status
= pci_read_32 ((u_int32_t
*) &ci
->reg
->isd
);
1297 nextInt
= INTRPTS_NEXTINT (status
);
1298 intCnt
= INTRPTS_INTCNT (status
);
1299 ci
->intlog
.drvr_intr_thcount
++;
1301 /*********************************************************/
1304 /* Under certain PCI Bus loading conditions, the */
1305 /* MUSYCC looses the data associated with an update */
1306 /* of its ISD and erroneously returns the immediately */
1307 /* preceding 'nextInt' value. However, the 'intCnt' */
1308 /* value appears to be correct. By not starting service */
1309 /* where the 'missing' 'nextInt' SHOULD point causes */
1310 /* the IQD not to be serviced - the 'not serviced' */
1311 /* entries then remain and continue to increase as more */
1312 /* incorrect ISD's are encountered. */
1313 /*********************************************************/
1315 if (nextInt
!= INTRPTS_NEXTINT (ci
->intlog
.this_status_new
))
1317 if (log_level
>= LOG_MONITOR
)
1319 pr_info("%s: note - updated ISD from %08x to %08x\n",
1320 ci
->devname
, status
,
1321 (status
& (~INTRPTS_NEXTINT_M
)) | ci
->intlog
.this_status_new
);
1324 * Replace bogus status with software corrected value.
1326 * It's not known whether, during this problem occurrence, if the
1327 * INTFULL bit is correctly reported or not.
1329 status
= (status
& (~INTRPTS_NEXTINT_M
)) | (ci
->intlog
.this_status_new
);
1330 nextInt
= INTRPTS_NEXTINT (status
);
1332 /**********************************************/
1333 /* Cn847x Bug Fix */
1334 /* -------------- */
1335 /* Fix for inability to write back same index */
1336 /* as read for a full interrupt queue. */
1337 /**********************************************/
1339 if (intCnt
== INT_QUEUE_SIZE
)
1341 currInt
= ((intCnt
- 1) + nextInt
) & (INT_QUEUE_SIZE
- 1);
1343 /************************************************/
1344 /* Interrupt Write Location Issues */
1345 /* ------------------------------- */
1346 /* When the interrupt status descriptor is */
1347 /* written, the interrupt line is de-asserted */
1348 /* by the Cn847x. In the case of MIPS */
1349 /* microprocessors, this must occur at the */
1350 /* beginning of the interrupt handler so that */
1351 /* the interrupt handle is not re-entered due */
1352 /* to interrupt dis-assertion latency. */
1353 /* In the case of all other processors, this */
1354 /* action should occur at the end of the */
1355 /* interrupt handler to avoid overwriting the */
1356 /* interrupt queue. */
1357 /************************************************/
1361 currInt
= (intCnt
+ nextInt
) & (INT_QUEUE_SIZE
- 1);
1365 * NOTE: Servicing an interrupt whose ISD contains a count of ZERO
1366 * can be indicative of a Shared Interrupt chain. Our driver can be
1367 * called from the system's interrupt handler as a matter of the OS
1368 * walking the chain. As the chain is walked, the interrupt will
1369 * eventually be serviced by the correct driver/handler.
1372 /* chained interrupt = not ours */
1373 pr_info(">> %s: intCnt NULL, sts %x, possibly a chained interrupt!\n",
1374 ci
->devname
, status
);
1379 ci
->iqp_tailx
= currInt
;
1381 currInt
<<= INTRPTS_NEXTINT_S
;
1382 ci
->intlog
.last_status_new
= ci
->intlog
.this_status_new
;
1383 ci
->intlog
.this_status_new
= currInt
;
1385 if ((log_level
>= LOG_WARN
) && (status
& INTRPTS_INTFULL_M
))
1387 pr_info("%s: Interrupt queue full condition occurred\n", ci
->devname
);
1389 if (log_level
>= LOG_DEBUG
)
1390 pr_info("%s: interrupts pending, isd @ 0x%p: %x curr %d cnt %d NEXT %d\n",
1391 ci
->devname
, &ci
->reg
->isd
,
1392 status
, nextInt
, intCnt
, (intCnt
+ nextInt
) & (INT_QUEUE_SIZE
- 1));
1395 #if defined(SBE_ISR_TASKLET)
1396 pci_write_32 ((u_int32_t
*) &ci
->reg
->isd
, currInt
);
1397 atomic_inc (&ci
->bh_pending
);
1398 tasklet_schedule (&ci
->ci_musycc_isr_tasklet
);
1399 #elif defined(SBE_ISR_IMMEDIATE)
1400 pci_write_32 ((u_int32_t
*) &ci
->reg
->isd
, currInt
);
1401 atomic_inc (&ci
->bh_pending
);
1402 queue_task (&ci
->ci_musycc_isr_tq
, &tq_immediate
);
1403 mark_bh (IMMEDIATE_BH
);
1404 #elif defined(SBE_ISR_INLINE)
1405 (void) musycc_intr_bh_tasklet (ci
);
1406 pci_write_32 ((u_int32_t
*) &ci
->reg
->isd
, currInt
);
1412 #if defined(SBE_ISR_IMMEDIATE)
1417 musycc_intr_bh_tasklet (ci_t
* ci
)
1421 unsigned int intCnt
;
1422 volatile u_int32_t currInt
= 0;
1423 volatile unsigned int headx
, tailx
;
1424 int readCount
, loopCount
;
1425 int group
, gchan
, event
, err
, tx
;
1426 u_int32_t badInt
= INT_EMPTY_ENTRY
;
1427 u_int32_t badInt2
= INT_EMPTY_ENTRY2
;
1430 * Hardware not available, potential interrupt hang. But since interrupt
1431 * might be shared, just return.
1433 if ((drvr_state
!= SBE_DRVR_AVAILABLE
) || (ci
->state
== C_INIT
))
1435 #if defined(SBE_ISR_IMMEDIATE)
1441 #if defined(SBE_ISR_TASKLET) || defined(SBE_ISR_IMMEDIATE)
1442 if (drvr_state
!= SBE_DRVR_AVAILABLE
)
1444 #if defined(SBE_ISR_TASKLET)
1446 #elif defined(SBE_ISR_IMMEDIATE)
1450 #elif defined(SBE_ISR_INLINE)
1451 /* no semaphore taken, no double checks */
1454 ci
->intlog
.drvr_intr_bhcount
++;
1457 unsigned int bh
= atomic_read (&ci
->bh_pending
);
1459 max_bh
= max (bh
, max_bh
);
1461 atomic_set (&ci
->bh_pending
, 0);/* if here, no longer pending */
1462 while ((headx
= ci
->iqp_headx
) != (tailx
= ci
->iqp_tailx
))
1464 intCnt
= (tailx
>= headx
) ? (tailx
- headx
) : (tailx
- headx
+ INT_QUEUE_SIZE
);
1465 currInt
= le32_to_cpu (ci
->iqd_p
[headx
]);
1467 max_intcnt
= max (intCnt
, max_intcnt
); /* RLD DEBUG */
1469 /**************************************************/
1472 /* The following code checks for the condition */
1473 /* of interrupt assertion before interrupt */
1474 /* queue update. This is a problem on several */
1475 /* PCI-Local bridge chips found on some products. */
1476 /**************************************************/
1479 if ((currInt
== badInt
) || (currInt
== badInt2
))
1480 ci
->intlog
.drvr_int_failure
++;
1482 while ((currInt
== badInt
) || (currInt
== badInt2
))
1484 for (loopCount
= 0; loopCount
< 0x30; loopCount
++)
1485 OS_uwait_dummy (); /* use call to avoid optimization removal
1488 currInt
= le32_to_cpu (ci
->iqd_p
[headx
]);
1489 if (readCount
++ > 20)
1493 if ((currInt
== badInt
) || (currInt
== badInt2
)) /* catch failure of Bug
1496 if (log_level
>= LOG_WARN
)
1497 pr_info("%s: Illegal Interrupt Detected @ 0x%p, mod %d.)\n",
1498 ci
->devname
, &ci
->iqd_p
[headx
], headx
);
1501 * If the descriptor has not recovered, then leaving the EMPTY
1502 * entry set will not signal to the MUSYCC that this descriptor
1503 * has been serviced. The Interrupt Queue can then start loosing
1504 * available descriptors and MUSYCC eventually encounters and
1505 * reports the INTFULL condition. Per manual, changing any bit
1506 * marks descriptor as available, thus the use of different
1507 * EMPTY_ENTRY values.
1510 if (currInt
== badInt
)
1512 ci
->iqd_p
[headx
] = __constant_cpu_to_le32 (INT_EMPTY_ENTRY2
);
1515 ci
->iqd_p
[headx
] = __constant_cpu_to_le32 (INT_EMPTY_ENTRY
);
1517 ci
->iqp_headx
= (headx
+ 1) & (INT_QUEUE_SIZE
- 1); /* insure wrapness */
1522 group
= INTRPT_GRP (currInt
);
1523 gchan
= INTRPT_CH (currInt
);
1524 event
= INTRPT_EVENT (currInt
);
1525 err
= INTRPT_ERROR (currInt
);
1526 tx
= currInt
& INTRPT_DIR_M
;
1528 ci
->iqd_p
[headx
] = __constant_cpu_to_le32 (INT_EMPTY_ENTRY
);
1531 if (log_level
>= LOG_DEBUG
)
1534 pr_info(" %08x -> err: %2d,", currInt
, err
);
1536 pr_info("+ interrupt event: %d, grp: %d, chan: %2d, side: %cX\n",
1537 event
, group
, gchan
, tx
? 'T' : 'R');
1539 pi
= &ci
->port
[group
]; /* notice that here we assume 1-1 group -
1541 ch
= pi
->chan
[gchan
];
1544 case EVE_SACK
: /* Service Request Acknowledge */
1545 if (log_level
>= LOG_DEBUG
)
1547 volatile u_int32_t r
;
1549 r
= pci_read_32 ((u_int32_t
*) &pi
->reg
->srd
);
1550 pr_info("- SACK cmd: %08x (hdw= %08x)\n", pi
->sr_last
, r
);
1552 SD_SEM_GIVE (&pi
->sr_sem_wait
); /* wake up waiting process */
1554 case EVE_CHABT
: /* Change To Abort Code (0x7e -> 0xff) */
1555 case EVE_CHIC
: /* Change To Idle Code (0xff -> 0x7e) */
1557 case EVE_EOM
: /* End Of Message */
1558 case EVE_EOB
: /* End Of Buffer (Transparent mode) */
1561 musycc_bh_tx_eom (pi
, gchan
);
1564 musycc_bh_rx_eom (pi
, gchan
);
1570 * MUSYCC Interrupt Descriptor section states that EOB and EOM
1571 * can be combined with the NONE error (as well as others). So
1572 * drop thru to catch this...
1578 ch
->s
.rx_length_errors
++;
1582 if (log_level
>= LOG_WARN
)
1583 pr_info("%s: unexpected interrupt event: %d, iqd[%d]: %08x, port: %d\n", ci
->devname
,
1584 event
, headx
, currInt
, group
);
1586 } /* switch on event */
1590 * Per MUSYCC Manual, Section 6.4.8.3 [Transmit Errors], TX errors
1591 * are service-affecting and require action to resume normal
1592 * bit-level processing.
1599 * Per MUSYCC manual, Section 6.4.8.3 [Transmit Errors], this
1600 * error requires Transmit channel reactivation.
1602 * Per MUSYCC manual, Section 6.4.8.4 [Receive Errors], this error
1603 * requires Receive channel reactivation.
1609 * TX ONR Error only occurs when channel is configured for
1610 * Transparent Mode. However, this code will catch and
1611 * re-activate on ANY TX ONR error.
1615 * Set flag to re-enable on any next transmit attempt.
1617 ch
->ch_start_tx
= CH_START_TX_ONR
;
1620 #ifdef RLD_TRANS_DEBUG
1621 if (1 || log_level
>= LOG_MONITOR
)
1623 if (log_level
>= LOG_MONITOR
)
1626 pr_info("%s: TX buffer underflow [ONR] on channel %d, mode %x QStopped %x free %d\n",
1627 ci
->devname
, ch
->channum
, ch
->p
.chan_mode
, sd_queue_stopped (ch
->user
), ch
->txd_free
);
1629 if (ch
->p
.chan_mode
== 2) /* problem = ONR on HDLC
1632 pr_info("++ Failed Last %x Next %x QStopped %x, start_tx %x tx_full %d txd_free %d mode %x\n",
1633 (u_int32_t
) ch
->txd_irq_srv
, (u_int32_t
) ch
->txd_usr_add
,
1634 sd_queue_stopped (ch
->user
),
1635 ch
->ch_start_tx
, ch
->tx_full
, ch
->txd_free
, ch
->p
.chan_mode
);
1636 musycc_dump_txbuffer_ring (ch
, 0);
1641 } else /* RX buffer overrun */
1644 * Per MUSYCC manual, Section 6.4.8.4 [Receive Errors],
1645 * channel recovery for this RX ONR error IS required. It is
1646 * also suggested to increase the number of receive buffers
1647 * for this channel. Receive channel reactivation IS
1648 * required, and data has been lost.
1650 ch
->s
.rx_over_errors
++;
1651 ch
->ch_start_rx
= CH_START_RX_ONR
;
1653 if (log_level
>= LOG_WARN
)
1655 pr_info("%s: RX buffer overflow [ONR] on channel %d, mode %x\n",
1656 ci
->devname
, ch
->channum
, ch
->p
.chan_mode
);
1657 //musycc_dump_rxbuffer_ring (ch, 0); /* RLD DEBUG */
1660 musycc_chan_restart (ch
);
1665 ch
->s
.tx_fifo_errors
++;
1666 ch
->ch_start_tx
= CH_START_TX_BUF
;
1668 * Per MUSYCC manual, Section 6.4.8.3 [Transmit Errors],
1669 * this BUFF error requires Transmit channel reactivation.
1671 if (log_level
>= LOG_MONITOR
)
1672 pr_info("%s: TX buffer underrun [BUFF] on channel %d, mode %x\n",
1673 ci
->devname
, ch
->channum
, ch
->p
.chan_mode
);
1674 } else /* RX buffer overrun */
1676 ch
->s
.rx_over_errors
++;
1678 * Per MUSYCC manual, Section 6.4.8.4 [Receive Errors], HDLC
1679 * mode requires NO recovery for this RX BUFF error is
1680 * required. It is suggested to increase the FIFO buffer
1681 * space for this channel. Receive channel reactivation is
1682 * not required, but data has been lost.
1684 if (log_level
>= LOG_WARN
)
1685 pr_info("%s: RX buffer overrun [BUFF] on channel %d, mode %x\n",
1686 ci
->devname
, ch
->channum
, ch
->p
.chan_mode
);
1688 * Per MUSYCC manual, Section 6.4.9.4 [Receive Errors],
1689 * Transparent mode DOES require recovery for the RX BUFF
1690 * error. It is suggested to increase the FIFO buffer space
1691 * for this channel. Receive channel reactivation IS
1692 * required and data has been lost.
1694 if (ch
->p
.chan_mode
== CFG_CH_PROTO_TRANS
)
1695 ch
->ch_start_rx
= CH_START_RX_BUF
;
1698 if (tx
|| (ch
->p
.chan_mode
== CFG_CH_PROTO_TRANS
))
1699 musycc_chan_restart (ch
);
1703 } /* switch on err */
1705 /* Check for interrupt lost condition */
1706 if ((currInt
& INTRPT_ILOST_M
) && (log_level
>= LOG_ERROR
))
1708 pr_info("%s: Interrupt queue overflow - ILOST asserted\n",
1711 ci
->iqp_headx
= (headx
+ 1) & (INT_QUEUE_SIZE
- 1); /* insure wrapness */
1715 if ((log_level
>= LOG_MONITOR2
) && (ci
->iqp_headx
!= ci
->iqp_tailx
))
1719 bh
= atomic_read (&CI
->bh_pending
);
1720 pr_info("_bh_: late arrivals, head %d != tail %d, pending %d\n",
1721 ci
->iqp_headx
, ci
->iqp_tailx
, bh
);
1723 #if defined(SBE_ISR_IMMEDIATE)
1726 /* else, nothing returned */
1731 musycc_new_chan (ci_t
* ci
, int channum
, void *user
)
1735 ch
= ci
->port
[channum
/ MUSYCC_NCHANS
].chan
[channum
% MUSYCC_NCHANS
];
1737 if (ch
->state
!= UNASSIGNED
)
1739 /* NOTE: mch_t already cleared during OS_kmalloc() */
1745 ch
->p
.intr_mask
= 0;
1747 ch
->p
.chan_mode
= CFG_CH_PROTO_HDLC_FCS16
;
1748 ch
->p
.idlecode
= CFG_CH_FLAG_7E
;
1749 ch
->p
.pad_fill_count
= 2;
1750 spin_lock_init (&ch
->ch_rxlock
);
1751 spin_lock_init (&ch
->ch_txlock
);
1758 #ifdef SBE_PMCC4_ENABLE
1760 musycc_chan_down (ci_t
* dummy
, int channum
)
1766 if (!(ch
= sd_find_chan (dummy
, channum
)))
1771 /* Deactivate the channel */
1772 musycc_serv_req (pi
, SR_CHANNEL_DEACTIVATE
| SR_RX_DIRECTION
| gchan
);
1773 ch
->ch_start_rx
= 0;
1774 musycc_serv_req (pi
, SR_CHANNEL_DEACTIVATE
| SR_TX_DIRECTION
| gchan
);
1775 ch
->ch_start_tx
= 0;
1777 if (ch
->state
== DOWN
)
1781 pi
->regram
->thp
[gchan
] = 0;
1782 pi
->regram
->tmp
[gchan
] = 0;
1783 pi
->regram
->rhp
[gchan
] = 0;
1784 pi
->regram
->rmp
[gchan
] = 0;
1786 for (i
= 0; i
< ch
->txd_num
; i
++)
1788 if (ch
->mdt
[i
].mem_token
!= 0)
1789 OS_mem_token_free (ch
->mdt
[i
].mem_token
);
1792 for (i
= 0; i
< ch
->rxd_num
; i
++)
1794 if (ch
->mdr
[i
].mem_token
!= 0)
1795 OS_mem_token_free (ch
->mdr
[i
].mem_token
);
1805 musycc_update_timeslots (pi
);
1806 c4_fifo_free (pi
, ch
->gchan
);
1815 musycc_del_chan (ci_t
* ci
, int channum
)
1819 if ((channum
< 0) || (channum
>= (MUSYCC_NPORTS
* MUSYCC_NCHANS
))) /* sanity chk param */
1821 if (!(ch
= sd_find_chan (ci
, channum
)))
1823 if (ch
->state
== UP
)
1824 musycc_chan_down (ci
, channum
);
1825 ch
->state
= UNASSIGNED
;
1831 musycc_del_chan_stats (ci_t
* ci
, int channum
)
1835 if (channum
< 0 || channum
>= (MUSYCC_NPORTS
* MUSYCC_NCHANS
)) /* sanity chk param */
1837 if (!(ch
= sd_find_chan (ci
, channum
)))
1840 memset (&ch
->s
, 0, sizeof (struct sbecom_chan_stats
));
1846 musycc_start_xmit (ci_t
* ci
, int channum
, void *mem_token
)
1852 unsigned long flags
;
1857 if (!(ch
= sd_find_chan (ci
, channum
)))
1860 if (ci
->state
!= C_RUNNING
) /* full interrupt processing available */
1862 if (ch
->state
!= UP
)
1865 if (!(ch
->status
& TX_ENABLED
))
1866 return EROFS
; /* how else to flag unwritable state ? */
1868 #ifdef RLD_TRANS_DEBUGx
1869 if (1 || log_level
>= LOG_MONITOR2
)
1871 if (log_level
>= LOG_MONITOR2
)
1874 pr_info("++ start_xmt[%d]: state %x start %x full %d free %d required %d stopped %x\n",
1875 channum
, ch
->state
, ch
->ch_start_tx
, ch
->tx_full
,
1876 ch
->txd_free
, ch
->txd_required
, sd_queue_stopped (ch
->user
));
1878 /***********************************************/
1879 /** Determine total amount of data to be sent **/
1880 /***********************************************/
1883 for (len
= OS_mem_token_tlen (m2
); len
> 0;
1884 m2
= (void *) OS_mem_token_next (m2
))
1886 if (!OS_mem_token_len (m2
))
1889 len
-= OS_mem_token_len (m2
);
1892 if (txd_need_cnt
== 0)
1894 if (log_level
>= LOG_MONITOR2
)
1895 pr_info("%s channel %d: no TX data in User buffer\n", ci
->devname
, channum
);
1896 OS_mem_token_free (mem_token
);
1897 return 0; /* no data to send */
1899 /*************************************************/
1900 /** Are there sufficient descriptors available? **/
1901 /*************************************************/
1902 if (txd_need_cnt
> ch
->txd_num
) /* never enough descriptors for this
1905 if (log_level
>= LOG_DEBUG
)
1907 pr_info("start_xmit: discarding buffer, insufficient descriptor cnt %d, need %d.\n",
1908 ch
->txd_num
, txd_need_cnt
+ 1);
1911 OS_mem_token_free (mem_token
);
1915 spin_lock_irqsave (&ch
->ch_txlock
, flags
);
1917 /************************************************************/
1918 /** flow control the line if not enough descriptors remain **/
1919 /************************************************************/
1920 if (txd_need_cnt
> ch
->txd_free
)
1922 if (log_level
>= LOG_MONITOR2
)
1924 pr_info("start_xmit[%d]: EBUSY - need more descriptors, have %d of %d need %d\n",
1925 channum
, ch
->txd_free
, ch
->txd_num
, txd_need_cnt
);
1928 ch
->txd_required
= txd_need_cnt
;
1929 sd_disable_xmit (ch
->user
);
1931 spin_unlock_irqrestore (&ch
->ch_txlock
, flags
);
1933 return EBUSY
; /* tell user to try again later */
1935 /**************************************************/
1936 /** Put the user data into MUSYCC data buffer(s) **/
1937 /**************************************************/
1939 md
= ch
->txd_usr_add
; /* get current available descriptor */
1941 for (len
= OS_mem_token_tlen (m2
); len
> 0; m2
= OS_mem_token_next (m2
))
1943 int u
= OS_mem_token_len (m2
);
1950 * Enable following chunks, yet wait to enable the FIRST chunk until
1951 * after ALL subsequent chunks are setup.
1953 if (md
!= ch
->txd_usr_add
) /* not first chunk */
1954 u
|= MUSYCC_TX_OWNED
; /* transfer ownership from HOST to MUSYCC */
1956 if (len
) /* not last chunk */
1958 else if (ch
->p
.chan_mode
== CFG_CH_PROTO_TRANS
)
1961 * Per MUSYCC Ref 6.4.9 for Transparent Mode, the host must
1962 * always clear EOMIRQ_ENABLE in every Transmit Buffer Descriptor
1963 * (IE. don't set herein).
1967 u
|= EOMIRQ_ENABLE
; /* EOM, last HDLC chunk */
1970 /* last chunk in hdlc mode */
1971 u
|= (ch
->p
.idlecode
<< IDLE_CODE
);
1972 if (ch
->p
.pad_fill_count
)
1975 /* NOOP NOTE: u_int8_t cannot be > 0xFF */
1976 /* sanitize pad_fill_count for maximums allowed by hardware */
1977 if (ch
->p
.pad_fill_count
> EXTRA_FLAGS_MASK
)
1978 ch
->p
.pad_fill_count
= EXTRA_FLAGS_MASK
;
1980 u
|= (PADFILL_ENABLE
| (ch
->p
.pad_fill_count
<< EXTRA_FLAGS
));
1982 md
->mem_token
= len
? 0 : mem_token
; /* Fill in mds on last
1983 * segment, others set ZERO
1984 * so that entire token is
1985 * removed ONLY when ALL
1986 * segments have been
1989 md
->data
= cpu_to_le32 (OS_vtophys (OS_mem_token_data (m2
)));
1991 md
->status
= cpu_to_le32 (u
);
1999 * Now transfer ownership of first chunk from HOST to MUSYCC in order to
2000 * fire-off this XMIT.
2002 ch
->txd_usr_add
->status
|= __constant_cpu_to_le32 (MUSYCC_TX_OWNED
);
2004 ch
->txd_usr_add
= md
;
2006 len
= OS_mem_token_tlen (mem_token
);
2007 atomic_add (len
, &ch
->tx_pending
);
2008 atomic_add (len
, &ci
->tx_pending
);
2010 ch
->s
.tx_bytes
+= len
;
2012 spin_unlock_irqrestore (&ch
->ch_txlock
, flags
); /* allow pending
2013 * interrupt to sneak
2018 * If an ONR was seen, then channel requires poking to restart
2021 if (ch
->ch_start_tx
)
2023 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,5,41)
2024 SD_SEM_TAKE (&ci
->sem_wdbusy
, "_wd_"); /* only 1 thru here, per
2026 if ((ch
->ch_start_tx
== CH_START_TX_ONR
) && (ch
->p
.chan_mode
== CFG_CH_PROTO_TRANS
))
2028 /* ONR restart transmission from background loop */
2029 ci
->wd_notify
= WD_NOTIFY_ONR
; /* enabled global watchdog
2033 /* start first transmission from background loop */
2034 ci
->wd_notify
= WD_NOTIFY_1TX
; /* enabled global watchdog
2037 musycc_chan_restart (ch
);
2038 SD_SEM_GIVE (&ci
->sem_wdbusy
);
2040 musycc_chan_restart (ch
);
2043 #ifdef SBE_WAN256T3_ENABLE
2044 wan256t3_led (ci
, LED_TX
, LEDV_G
);
2052 musycc_set_chan (ci_t
* ci
, int channum
, struct sbecom_chan_param
* p
)
2058 if (channum
< 0 || channum
>= (MUSYCC_NPORTS
* MUSYCC_NCHANS
)) /* sanity chk param */
2060 if (!(ch
= sd_find_chan (ci
, channum
)))
2062 if (ch
->channum
!= p
->channum
)
2064 if (sd_line_is_ok (ch
->user
))
2067 sd_line_is_down (ch
->user
);
2069 if (ch
->state
== UP
&& /* bring down in current configuration */
2070 (ch
->p
.status
!= p
->status
||
2071 ch
->p
.chan_mode
!= p
->chan_mode
||
2072 ch
->p
.intr_mask
!= p
->intr_mask
||
2073 ch
->txd_free
< ch
->txd_num
))
2075 if ((n
= musycc_chan_down (ci
, channum
)))
2077 if (ch
->p
.mode_56k
!= p
->mode_56k
)
2079 ch
->p
= *p
; /* copy in new parameters */
2080 musycc_update_timeslots (&ci
->port
[ch
->channum
/ MUSYCC_NCHANS
]);
2082 ch
->p
= *p
; /* copy in new parameters */
2083 if ((n
= musycc_chan_up (ci
, channum
)))
2085 sd_enable_xmit (ch
->user
); /* re-enable to catch flow controlled
2089 if (ch
->p
.mode_56k
!= p
->mode_56k
)
2091 ch
->p
= *p
; /* copy in new parameters */
2092 musycc_update_timeslots (&ci
->port
[ch
->channum
/ MUSYCC_NCHANS
]);
2094 ch
->p
= *p
; /* copy in new parameters */
2098 sd_line_is_up (ch
->user
);
2105 musycc_get_chan (ci_t
* ci
, int channum
, struct sbecom_chan_param
* p
)
2110 if (channum
< 0 || channum
>= (MUSYCC_NPORTS
* MUSYCC_NCHANS
)) /* sanity chk param */
2113 if (!(ch
= sd_find_chan (ci
, channum
)))
2121 musycc_get_chan_stats (ci_t
* ci
, int channum
, struct sbecom_chan_stats
* p
)
2125 if (channum
< 0 || channum
>= (MUSYCC_NPORTS
* MUSYCC_NCHANS
)) /* sanity chk param */
2127 if (!(ch
= sd_find_chan (ci
, channum
)))
2130 p
->tx_pending
= atomic_read (&ch
->tx_pending
);
2136 #ifdef SBE_WAN256T3_ENABLE
2138 musycc_chan_down (ci_t
* ci
, int channum
)
2144 if (!(ch
= sd_find_chan (ci
, channum
)))
2149 /* Deactivate the channel */
2150 musycc_serv_req (pi
, SR_CHANNEL_DEACTIVATE
| SR_RX_DIRECTION
| gchan
);
2151 ch
->ch_start_rx
= 0;
2152 musycc_serv_req (pi
, SR_CHANNEL_DEACTIVATE
| SR_TX_DIRECTION
| gchan
);
2153 ch
->ch_start_tx
= 0;
2155 if (ch
->state
== DOWN
)
2159 pi
->regram
->thp
[gchan
] = 0;
2160 pi
->regram
->tmp
[gchan
] = 0;
2161 pi
->regram
->rhp
[gchan
] = 0;
2162 pi
->regram
->rmp
[gchan
] = 0;
2164 for (i
= 0; i
< ch
->txd_num
; i
++)
2166 if (ch
->mdt
[i
].mem_token
!= 0)
2167 OS_mem_token_free (ch
->mdt
[i
].mem_token
);
2170 for (i
= 0; i
< ch
->rxd_num
; i
++)
2172 if (ch
->mdr
[i
].mem_token
!= 0)
2173 OS_mem_token_free (ch
->mdr
[i
].mem_token
);
2185 /*** End-of-File ***/