ext4: reduce contention on s_orphan_lock
[linux/fpc-iii.git] / drivers / staging / cxt1e1 / musycc.c
blob7b4f6f2108e3b9015a9c8b2de81c5998c06a6216
1 static unsigned int max_intcnt = 0;
2 static unsigned int max_bh = 0;
4 /*-----------------------------------------------------------------------------
5 * musycc.c -
7 * Copyright (C) 2007 One Stop Systems, Inc.
8 * Copyright (C) 2003-2006 SBE, Inc.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * For further information, contact via email: support@onestopsystems.com
21 * One Stop Systems, Inc. Escondido, California U.S.A.
22 *-----------------------------------------------------------------------------
25 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
27 #include <linux/types.h>
28 #include "pmcc4_sysdep.h"
29 #include <linux/kernel.h>
30 #include <linux/errno.h>
31 #include <linux/init.h>
32 #include "sbecom_inline_linux.h"
33 #include "libsbew.h"
34 #include "pmcc4_private.h"
35 #include "pmcc4.h"
36 #include "musycc.h"
38 #define sd_find_chan(ci,ch) c4_find_chan(ch)
41 /*******************************************************************/
42 /* global driver variables */
43 extern ci_t *c4_list;
44 extern int drvr_state;
46 extern int cxt1e1_max_mru;
47 extern int cxt1e1_max_mtu;
48 extern int max_rxdesc_used;
49 extern int max_txdesc_used;
50 extern ci_t *CI; /* dummy pointr to board ZEROE's data - DEBUG
51 * USAGE */
54 /*******************************************************************/
55 /* forward references */
56 void c4_fifo_free(mpi_t *, int);
57 void c4_wk_chan_restart(mch_t *);
58 void musycc_bh_tx_eom(mpi_t *, int);
59 int musycc_chan_up(ci_t *, int);
60 status_t __init musycc_init(ci_t *);
61 void musycc_intr_bh_tasklet(ci_t *);
62 void musycc_serv_req(mpi_t *, u_int32_t);
63 void musycc_update_timeslots(mpi_t *);
65 /*******************************************************************/
67 #if 1
68 static int
69 musycc_dump_rxbuffer_ring(mch_t *ch, int lockit)
71 struct mdesc *m;
72 unsigned long flags = 0;
74 u_int32_t status;
75 int n;
77 if (lockit)
78 spin_lock_irqsave(&ch->ch_rxlock, flags);
79 if (ch->rxd_num == 0)
80 pr_info(" ZERO receive buffers allocated for this channel.");
81 else {
82 FLUSH_MEM_READ();
83 m = &ch->mdr[ch->rxix_irq_srv];
84 for (n = ch->rxd_num; n; n--) {
85 status = le32_to_cpu(m->status);
87 pr_info("%c %08lx[%2d]: sts %08x (%c%c%c%c:%d.) Data [%08x] Next [%08x]\n",
88 (m == &ch->mdr[ch->rxix_irq_srv]) ? 'F' : ' ',
89 (unsigned long) m, n,
90 status,
91 m->data ? (status & HOST_RX_OWNED ? 'H' : 'M') : '-',
92 status & POLL_DISABLED ? 'P' : '-',
93 status & EOBIRQ_ENABLE ? 'b' : '-',
94 status & EOMIRQ_ENABLE ? 'm' : '-',
95 status & LENGTH_MASK,
96 le32_to_cpu(m->data), le32_to_cpu(m->next));
97 #ifdef RLD_DUMP_BUFDATA
99 u_int32_t *dp;
100 int len = status & LENGTH_MASK;
102 #if 1
103 if (m->data && (status & HOST_RX_OWNED))
104 #else
105 if (m->data) /* always dump regardless of valid RX
106 * data */
107 #endif
109 dp = (u_int32_t *) OS_phystov((void *) (le32_to_cpu(m->data)));
110 if (len >= 0x10)
111 pr_info(" %x[%x]: %08X %08X %08X %08x\n", (u_int32_t) dp, len,
112 *dp, *(dp + 1), *(dp + 2), *(dp + 3));
113 else if (len >= 0x08)
114 pr_info(" %x[%x]: %08X %08X\n", (u_int32_t) dp, len,
115 *dp, *(dp + 1));
116 else
117 pr_info(" %x[%x]: %08X\n", (u_int32_t) dp, len, *dp);
120 #endif
122 m = m->snext;
124 } /* -for- */
125 pr_info("\n");
127 if (lockit)
128 spin_unlock_irqrestore(&ch->ch_rxlock, flags);
129 return 0;
131 #endif
133 #if 1
134 static int
135 musycc_dump_txbuffer_ring(mch_t *ch, int lockit)
137 struct mdesc *m;
138 unsigned long flags = 0;
139 u_int32_t status;
140 int n;
142 if (lockit)
143 spin_lock_irqsave(&ch->ch_txlock, flags);
144 if (ch->txd_num == 0)
145 pr_info(" ZERO transmit buffers allocated for this channel.");
146 else {
147 FLUSH_MEM_READ();
148 m = ch->txd_irq_srv;
149 for (n = ch->txd_num; n; n--) {
150 status = le32_to_cpu(m->status);
152 pr_info("%c%c %08lx[%2d]: sts %08x (%c%c%c%c:%d.) Data [%08x] Next [%08x]\n",
153 (m == ch->txd_usr_add) ? 'F' : ' ',
154 (m == ch->txd_irq_srv) ? 'L' : ' ',
155 (unsigned long) m, n,
156 status,
157 m->data ? (status & MUSYCC_TX_OWNED ? 'M' : 'H') : '-',
158 status & POLL_DISABLED ? 'P' : '-',
159 status & EOBIRQ_ENABLE ? 'b' : '-',
160 status & EOMIRQ_ENABLE ? 'm' : '-',
161 status & LENGTH_MASK,
162 le32_to_cpu(m->data), le32_to_cpu(m->next));
163 #ifdef RLD_DUMP_BUFDATA
165 u_int32_t *dp;
166 int len = status & LENGTH_MASK;
168 if (m->data) {
169 dp = (u_int32_t *) OS_phystov((void *) (le32_to_cpu(m->data)));
170 if (len >= 0x10)
171 pr_info(" %x[%x]: %08X %08X %08X %08x\n", (u_int32_t) dp, len,
172 *dp, *(dp + 1), *(dp + 2), *(dp + 3));
173 else if (len >= 0x08)
174 pr_info(" %x[%x]: %08X %08X\n", (u_int32_t) dp, len,
175 *dp, *(dp + 1));
176 else
177 pr_info(" %x[%x]: %08X\n", (u_int32_t) dp, len, *dp);
180 #endif
182 m = m->snext;
184 } /* -for- */
185 pr_info("\n");
187 if (lockit)
188 spin_unlock_irqrestore(&ch->ch_txlock, flags);
189 return 0;
191 #endif
195 * The following supports a backdoor debug facility which can be used to
196 * display the state of a board's channel.
199 status_t
200 musycc_dump_ring(ci_t *ci, unsigned int chan)
202 mch_t *ch;
204 if (chan >= MAX_CHANS_USED)
205 return SBE_DRVR_FAIL; /* E2BIG */
207 int bh;
209 bh = atomic_read(&ci->bh_pending);
210 pr_info(">> bh_pend %d [%d] ihead %d itail %d [%d] th_cnt %d bh_cnt %d wdcnt %d note %d\n",
211 bh, max_bh, ci->iqp_headx, ci->iqp_tailx, max_intcnt,
212 ci->intlog.drvr_intr_thcount,
213 ci->intlog.drvr_intr_bhcount,
214 ci->wdcount, ci->wd_notify);
215 max_bh = 0; /* reset counter */
216 max_intcnt = 0; /* reset counter */
219 ch = sd_find_chan(dummy, chan);
220 if (!ch) {
221 pr_info(">> musycc_dump_ring: channel %d not up.\n", chan);
222 return ENOENT;
224 pr_info(">> CI %p CHANNEL %3d @ %p: state %x status/p %x/%x\n", ci, chan, ch, ch->state,
225 ch->status, ch->p.status);
226 pr_info("--------------------------------\nTX Buffer Ring - Channel %d, txd_num %d. (bd/ch pend %d %d), TXD required %d, txpkt %lu\n",
227 chan, ch->txd_num,
228 (u_int32_t) atomic_read(&ci->tx_pending), (u_int32_t) atomic_read(&ch->tx_pending), ch->txd_required, ch->s.tx_packets);
229 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",
230 ch->user, ch->txd_irq_srv, ch->txd_usr_add,
231 sd_queue_stopped(ch->user),
232 ch->ch_start_tx, ch->tx_full, ch->txd_free, ch->p.chan_mode);
233 musycc_dump_txbuffer_ring(ch, 1);
234 pr_info("RX Buffer Ring - Channel %d, rxd_num %d. IRQ_SRV[%d] 0x%p, start_rx %x rxpkt %lu\n",
235 chan, ch->rxd_num, ch->rxix_irq_srv,
236 &ch->mdr[ch->rxix_irq_srv], ch->ch_start_rx, ch->s.rx_packets);
237 musycc_dump_rxbuffer_ring(ch, 1);
239 return SBE_DRVR_SUCCESS;
243 status_t
244 musycc_dump_rings(ci_t *ci, unsigned int start_chan)
246 unsigned int chan;
248 for (chan = start_chan; chan < (start_chan + 5); chan++)
249 musycc_dump_ring(ci, chan);
250 return SBE_DRVR_SUCCESS;
255 * NOTE on musycc_init_mdt(): These MUSYCC writes are only operational after
256 * a MUSYCC GROUP_INIT command has been issued.
259 void
260 musycc_init_mdt(mpi_t *pi)
262 u_int32_t *addr, cfg;
263 int i;
266 * This Idle Code insertion takes effect prior to channel's first
267 * transmitted message. After that, each message contains its own Idle
268 * Code information which is to be issued after the message is
269 * transmitted (Ref.MUSYCC 5.2.2.3: MCENBL bit in Group Configuration
270 * Descriptor).
273 addr = (u_int32_t *) ((u_long) pi->reg + MUSYCC_MDT_BASE03_ADDR);
274 cfg = CFG_CH_FLAG_7E << IDLE_CODE;
276 for (i = 0; i < 32; addr++, i++)
277 pci_write_32(addr, cfg);
281 /* Set TX thp to the next unprocessed md */
283 void
284 musycc_update_tx_thp(mch_t *ch)
286 struct mdesc *md;
287 unsigned long flags;
289 spin_lock_irqsave(&ch->ch_txlock, flags);
290 while (1) {
291 md = ch->txd_irq_srv;
292 FLUSH_MEM_READ();
293 if (!md->data) {
294 /* No MDs with buffers to process */
295 spin_unlock_irqrestore(&ch->ch_txlock, flags);
296 return;
298 if ((le32_to_cpu(md->status)) & MUSYCC_TX_OWNED) {
299 /* this is the MD to restart TX with */
300 break;
303 * Otherwise, we have a valid, host-owned message descriptor which
304 * has been successfully transmitted and whose buffer can be freed,
305 * so... process this MD, it's owned by the host. (This might give
306 * as a new, updated txd_irq_srv.)
308 musycc_bh_tx_eom(ch->up, ch->gchan);
310 md = ch->txd_irq_srv;
311 ch->up->regram->thp[ch->gchan] = cpu_to_le32(OS_vtophys(md));
312 FLUSH_MEM_WRITE();
314 if (ch->tx_full) {
315 ch->tx_full = 0;
316 ch->txd_required = 0;
317 sd_enable_xmit(ch->user); /* re-enable to catch flow controlled
318 * channel */
320 spin_unlock_irqrestore(&ch->ch_txlock, flags);
322 #ifdef RLD_TRANS_DEBUG
323 pr_info("++ musycc_update_tx_thp[%d]: setting thp = %p, sts %x\n", ch->channum, md, md->status);
324 #endif
329 * This is the workq task executed by the OS when our queue_work() is
330 * scheduled and run. It can fire off either RX or TX ACTIVATION depending
331 * upon the channel's ch_start_tx and ch_start_rx variables. This routine
332 * is implemented as a work queue so that the call to the service request is
333 * able to sleep, awaiting an interrupt acknowledgment response (SACK) from
334 * the hardware.
337 void
338 musycc_wq_chan_restart(void *arg) /* channel private structure */
340 mch_t *ch;
341 mpi_t *pi;
342 struct mdesc *md;
343 #if 0
344 unsigned long flags;
345 #endif
347 ch = container_of(arg, struct c4_chan_info, ch_work);
348 pi = ch->up;
350 #ifdef RLD_TRANS_DEBUG
351 pr_info("wq_chan_restart[%d]: start_RT[%d/%d] status %x\n",
352 ch->channum, ch->ch_start_rx, ch->ch_start_tx, ch->status);
354 #endif
356 /**********************************/
357 /** check for RX restart request **/
358 /**********************************/
360 if ((ch->ch_start_rx) && (ch->status & RX_ENABLED)) {
362 ch->ch_start_rx = 0;
363 #if defined(RLD_TRANS_DEBUG) || defined(RLD_RXACT_DEBUG)
365 static int hereb4 = 7;
367 if (hereb4) { /* RLD DEBUG */
368 hereb4--;
369 #ifdef RLD_TRANS_DEBUG
370 md = &ch->mdr[ch->rxix_irq_srv];
371 pr_info("++ musycc_wq_chan_restart[%d] CHAN RX ACTIVATE: rxix_irq_srv %d, md %p sts %x, rxpkt %lu\n",
372 ch->channum, ch->rxix_irq_srv, md, le32_to_cpu(md->status),
373 ch->s.rx_packets);
374 #elif defined(RLD_RXACT_DEBUG)
375 md = &ch->mdr[ch->rxix_irq_srv];
376 pr_info("++ musycc_wq_chan_restart[%d] CHAN RX ACTIVATE: rxix_irq_srv %d, md %p sts %x, rxpkt %lu\n",
377 ch->channum, ch->rxix_irq_srv, md, le32_to_cpu(md->status),
378 ch->s.rx_packets);
379 musycc_dump_rxbuffer_ring(ch, 1); /* RLD DEBUG */
380 #endif
383 #endif
384 musycc_serv_req(pi, SR_CHANNEL_ACTIVATE | SR_RX_DIRECTION | ch->gchan);
386 /**********************************/
387 /** check for TX restart request **/
388 /**********************************/
390 if ((ch->ch_start_tx) && (ch->status & TX_ENABLED)) {
391 /* find next unprocessed message, then set TX thp to it */
392 musycc_update_tx_thp(ch);
394 #if 0
395 spin_lock_irqsave(&ch->ch_txlock, flags);
396 #endif
397 md = ch->txd_irq_srv;
398 if (!md) {
399 #ifdef RLD_TRANS_DEBUG
400 pr_info("-- musycc_wq_chan_restart[%d]: WARNING, starting NULL md\n", ch->channum);
401 #endif
402 #if 0
403 spin_unlock_irqrestore(&ch->ch_txlock, flags);
404 #endif
405 } else if (md->data && ((le32_to_cpu(md->status)) & MUSYCC_TX_OWNED)) {
406 ch->ch_start_tx = 0;
407 #if 0
408 spin_unlock_irqrestore(&ch->ch_txlock, flags); /* allow interrupts for service request */
409 #endif
410 #ifdef RLD_TRANS_DEBUG
411 pr_info("++ musycc_wq_chan_restart() CHAN TX ACTIVATE: chan %d txd_irq_srv %p = sts %x, txpkt %lu\n",
412 ch->channum, ch->txd_irq_srv, ch->txd_irq_srv->status, ch->s.tx_packets);
413 #endif
414 musycc_serv_req(pi, SR_CHANNEL_ACTIVATE | SR_TX_DIRECTION | ch->gchan);
416 #ifdef RLD_RESTART_DEBUG
417 else {
418 /* retain request to start until retried and we have data to xmit */
419 pr_info("-- musycc_wq_chan_restart[%d]: DELAYED due to md %p sts %x data %x, start_tx %x\n",
420 ch->channum, md,
421 le32_to_cpu(md->status),
422 le32_to_cpu(md->data), ch->ch_start_tx);
423 musycc_dump_txbuffer_ring(ch, 0);
424 #if 0
425 spin_unlock_irqrestore(&ch->ch_txlock, flags); /* allow interrupts for service request */
426 #endif
428 #endif
434 * Channel restart either fires of a workqueue request (2.6) or lodges a
435 * watchdog activation sequence (2.4).
438 void
439 musycc_chan_restart(mch_t *ch)
441 #ifdef RLD_RESTART_DEBUG
442 pr_info("++ musycc_chan_restart[%d]: txd_irq_srv @ %p = sts %x\n",
443 ch->channum, ch->txd_irq_srv, ch->txd_irq_srv->status);
444 #endif
446 /* 2.6 - find next unprocessed message, then set TX thp to it */
447 #ifdef RLD_RESTART_DEBUG
448 pr_info(">> musycc_chan_restart: scheduling Chan %x workQ @ %p\n", ch->channum, &ch->ch_work);
449 #endif
450 c4_wk_chan_restart(ch); /* work queue mechanism fires off: Ref:
451 * musycc_wq_chan_restart () */
456 void
457 rld_put_led(mpi_t *pi, u_int32_t ledval)
459 static u_int32_t led = 0;
461 if (ledval == 0)
462 led = 0;
463 else
464 led |= ledval;
466 pci_write_32((u_int32_t *) &pi->up->cpldbase->leds, led); /* RLD DEBUG TRANHANG */
470 #define MUSYCC_SR_RETRY_CNT 9
472 void
473 musycc_serv_req(mpi_t *pi, u_int32_t req)
475 volatile u_int32_t r;
476 int rcnt;
479 * PORT NOTE: Semaphore protect service loop guarantees only a single
480 * operation at a time. Per MUSYCC Manual - "Issuing service requests to
481 * the same channel group without first receiving ACK from each request
482 * may cause the host to lose track of which service request has been
483 * acknowledged."
486 SD_SEM_TAKE(&pi->sr_sem_busy, "serv"); /* only 1 thru here, per
487 * group */
489 if (pi->sr_last == req) {
490 #ifdef RLD_TRANS_DEBUG
491 pr_info(">> same SR, Port %d Req %x\n", pi->portnum, req);
492 #endif
495 * The most likely repeated request is the channel activation command
496 * which follows the occurrence of a Transparent mode TX ONR or a
497 * BUFF error. If the previous command was a CHANNEL ACTIVATE,
498 * precede it with a NOOP command in order maintain coherent control
499 * of this current (re)ACTIVATE.
502 r = (pi->sr_last & ~SR_GCHANNEL_MASK);
503 if ((r == (SR_CHANNEL_ACTIVATE | SR_TX_DIRECTION)) ||
504 (r == (SR_CHANNEL_ACTIVATE | SR_RX_DIRECTION))) {
505 #ifdef RLD_TRANS_DEBUG
506 pr_info(">> same CHAN ACT SR, Port %d Req %x => issue SR_NOOP CMD\n", pi->portnum, req);
507 #endif
508 SD_SEM_GIVE(&pi->sr_sem_busy); /* allow this next request */
509 musycc_serv_req(pi, SR_NOOP);
510 SD_SEM_TAKE(&pi->sr_sem_busy, "serv"); /* relock & continue w/
511 * original req */
512 } else if (req == SR_NOOP) {
513 /* no need to issue back-to-back SR_NOOP commands at this time */
514 #ifdef RLD_TRANS_DEBUG
515 pr_info(">> same Port SR_NOOP skipped, Port %d\n", pi->portnum);
516 #endif
517 SD_SEM_GIVE(&pi->sr_sem_busy); /* allow this next request */
518 return;
521 rcnt = 0;
522 pi->sr_last = req;
523 rewrite:
524 pci_write_32((u_int32_t *) &pi->reg->srd, req);
525 FLUSH_MEM_WRITE();
528 * Per MUSYCC Manual, Section 6.1,2 - "When writing an SCR service
529 * request, the host must ensure at least one PCI bus clock cycle has
530 * elapsed before writing another service request. To meet this minimum
531 * elapsed service request write timing interval, it is recommended that
532 * the host follow any SCR write with another operation which reads from
533 * the same address."
535 r = pci_read_32((u_int32_t *) &pi->reg->srd); /* adhere to write
536 * timing imposition */
539 if ((r != req) && (req != SR_CHIP_RESET) && (++rcnt <= MUSYCC_SR_RETRY_CNT)) {
540 if (cxt1e1_log_level >= LOG_MONITOR)
541 pr_info("%s: %d - reissue srv req/last %x/%x (hdw reads %x), Chan %d.\n",
542 pi->up->devname, rcnt, req, pi->sr_last, r,
543 (pi->portnum * MUSYCC_NCHANS) + (req & 0x1f));
544 OS_uwait_dummy(); /* this delay helps reduce reissue counts
545 * (reason not yet researched) */
546 goto rewrite;
548 if (rcnt > MUSYCC_SR_RETRY_CNT) {
549 pr_warning("%s: failed service request (#%d)= %x, group %d.\n",
550 pi->up->devname, MUSYCC_SR_RETRY_CNT, req, pi->portnum);
551 SD_SEM_GIVE(&pi->sr_sem_busy); /* allow any next request */
552 return;
554 if (req == SR_CHIP_RESET) {
556 * PORT NOTE: the CHIP_RESET command is NOT ack'd by the MUSYCC, thus
557 * the upcoming delay is used. Though the MUSYCC documentation
558 * suggests a read-after-write would supply the required delay, it's
559 * unclear what CPU/BUS clock speeds might have been assumed when
560 * suggesting this 'lack of ACK' workaround. Thus the use of uwait.
562 OS_uwait(100000, "icard"); /* 100ms */
563 } else {
564 FLUSH_MEM_READ();
565 SD_SEM_TAKE(&pi->sr_sem_wait, "sakack"); /* sleep until SACK
566 * interrupt occurs */
568 SD_SEM_GIVE(&pi->sr_sem_busy); /* allow any next request */
572 #ifdef SBE_PMCC4_ENABLE
573 void
574 musycc_update_timeslots(mpi_t *pi)
576 int i, ch;
577 char e1mode = IS_FRAME_ANY_E1(pi->p.port_mode);
579 for (i = 0; i < 32; i++) {
580 int usedby = 0, last = 0, ts, j, bits[8];
582 u_int8_t lastval = 0;
584 if (((i == 0) && e1mode) || /* disable if E1 mode */
585 ((i == 16) && ((pi->p.port_mode == CFG_FRAME_E1CRC_CAS) || (pi->p.port_mode == CFG_FRAME_E1CRC_CAS_AMI)))
586 || ((i > 23) && (!e1mode))) /* disable if T1 mode */
587 pi->tsm[i] = 0xff; /* make tslot unavailable for this mode */
588 else
589 pi->tsm[i] = 0x00; /* make tslot available for assignment */
590 for (j = 0; j < 8; j++)
591 bits[j] = -1;
592 for (ch = 0; ch < MUSYCC_NCHANS; ch++) {
593 if ((pi->chan[ch]->state == UP) && (pi->chan[ch]->p.bitmask[i])) {
594 usedby++;
595 last = ch;
596 lastval = pi->chan[ch]->p.bitmask[i];
597 for (j = 0; j < 8; j++)
598 if (lastval & (1 << j))
599 bits[j] = ch;
600 pi->tsm[i] |= lastval;
603 if (!usedby)
604 ts = 0;
605 else if ((usedby == 1) && (lastval == 0xff))
606 ts = (4 << 5) | last;
607 else if ((usedby == 1) && (lastval == 0x7f))
608 ts = (5 << 5) | last;
609 else {
610 int idx;
612 if (bits[0] < 0)
613 ts = (6 << 5) | (idx = last);
614 else
615 ts = (7 << 5) | (idx = bits[0]);
616 for (j = 1; j < 8; j++) {
617 pi->regram->rscm[idx * 8 + j] = (bits[j] < 0) ? 0 : (0x80 | bits[j]);
618 pi->regram->tscm[idx * 8 + j] = (bits[j] < 0) ? 0 : (0x80 | bits[j]);
621 pi->regram->rtsm[i] = ts;
622 pi->regram->ttsm[i] = ts;
624 FLUSH_MEM_WRITE();
626 musycc_serv_req(pi, SR_TIMESLOT_MAP | SR_RX_DIRECTION);
627 musycc_serv_req(pi, SR_TIMESLOT_MAP | SR_TX_DIRECTION);
628 musycc_serv_req(pi, SR_SUBCHANNEL_MAP | SR_RX_DIRECTION);
629 musycc_serv_req(pi, SR_SUBCHANNEL_MAP | SR_TX_DIRECTION);
631 #endif
634 #ifdef SBE_WAN256T3_ENABLE
635 void
636 musycc_update_timeslots(mpi_t *pi)
638 mch_t *ch;
640 u_int8_t ts, hmask, tsen;
641 int gchan;
642 int i;
644 #ifdef SBE_PMCC4_ENABLE
645 hmask = (0x1f << pi->up->p.hypersize) & 0x1f;
646 #endif
647 #ifdef SBE_WAN256T3_ENABLE
648 hmask = (0x1f << hyperdummy) & 0x1f;
649 #endif
650 for (i = 0; i < 128; i++) {
651 gchan = ((pi->portnum * MUSYCC_NCHANS) + (i & hmask)) % MUSYCC_NCHANS;
652 ch = pi->chan[gchan];
653 if (ch->p.mode_56k)
654 tsen = MODE_56KBPS;
655 else
656 tsen = MODE_64KBPS; /* also the default */
657 ts = ((pi->portnum % 4) == (i / 32)) ? (tsen << 5) | (i & hmask) : 0;
658 pi->regram->rtsm[i] = ts;
659 pi->regram->ttsm[i] = ts;
661 FLUSH_MEM_WRITE();
662 musycc_serv_req(pi, SR_TIMESLOT_MAP | SR_RX_DIRECTION);
663 musycc_serv_req(pi, SR_TIMESLOT_MAP | SR_TX_DIRECTION);
665 #endif
669 * This routine converts a generic library channel configuration parameter
670 * into a hardware specific register value (IE. MUSYCC CCD Register).
672 u_int32_t
673 musycc_chan_proto(int proto)
675 int reg;
677 switch (proto) {
678 case CFG_CH_PROTO_TRANS: /* 0 */
679 reg = MUSYCC_CCD_TRANS;
680 break;
681 case CFG_CH_PROTO_SS7: /* 1 */
682 reg = MUSYCC_CCD_SS7;
683 break;
684 default:
685 case CFG_CH_PROTO_ISLP_MODE: /* 4 */
686 case CFG_CH_PROTO_HDLC_FCS16: /* 2 */
687 reg = MUSYCC_CCD_HDLC_FCS16;
688 break;
689 case CFG_CH_PROTO_HDLC_FCS32: /* 3 */
690 reg = MUSYCC_CCD_HDLC_FCS32;
691 break;
694 return reg;
697 #ifdef SBE_WAN256T3_ENABLE
698 static void __init
699 musycc_init_port(mpi_t *pi)
701 pci_write_32((u_int32_t *) &pi->reg->gbp, OS_vtophys(pi->regram));
703 pi->regram->grcd =
704 __constant_cpu_to_le32(MUSYCC_GRCD_RX_ENABLE |
705 MUSYCC_GRCD_TX_ENABLE |
706 MUSYCC_GRCD_SF_ALIGN |
707 MUSYCC_GRCD_SUBCHAN_DISABLE |
708 MUSYCC_GRCD_OOFMP_DISABLE |
709 MUSYCC_GRCD_COFAIRQ_DISABLE |
710 MUSYCC_GRCD_MC_ENABLE |
711 (MUSYCC_GRCD_POLLTH_32 << MUSYCC_GRCD_POLLTH_SHIFT));
713 pi->regram->pcd =
714 __constant_cpu_to_le32(MUSYCC_PCD_E1X4_MODE |
715 MUSYCC_PCD_TXDATA_RISING |
716 MUSYCC_PCD_TX_DRIVEN);
718 /* Message length descriptor */
719 pi->regram->mld = __constant_cpu_to_le32(cxt1e1_max_mru | (cxt1e1_max_mru << 16));
720 FLUSH_MEM_WRITE();
722 musycc_serv_req(pi, SR_GROUP_INIT | SR_RX_DIRECTION);
723 musycc_serv_req(pi, SR_GROUP_INIT | SR_TX_DIRECTION);
725 musycc_init_mdt(pi);
727 musycc_update_timeslots(pi);
729 #endif
732 status_t __init
733 musycc_init(ci_t *ci)
735 char *regaddr; /* temp for address boundary calculations */
736 int i, gchan;
738 OS_sem_init(&ci->sem_wdbusy, SEM_AVAILABLE); /* watchdog exclusion */
741 * Per MUSYCC manual, Section 6.3.4 - "The host must allocate a dword
742 * aligned memory segment for interrupt queue pointers."
745 #define INT_QUEUE_BOUNDARY 4
747 regaddr = OS_kmalloc((INT_QUEUE_SIZE + 1) * sizeof(u_int32_t));
748 if (!regaddr)
749 return -ENOMEM;
750 ci->iqd_p_saved = regaddr; /* save orig value for free's usage */
751 ci->iqd_p = (u_int32_t *) ((unsigned long) (regaddr + INT_QUEUE_BOUNDARY - 1) &
752 (~(INT_QUEUE_BOUNDARY - 1))); /* this calculates
753 * closest boundary */
755 for (i = 0; i < INT_QUEUE_SIZE; i++)
756 ci->iqd_p[i] = __constant_cpu_to_le32(INT_EMPTY_ENTRY);
758 for (i = 0; i < ci->max_port; i++) {
759 mpi_t *pi = &ci->port[i];
762 * Per MUSYCC manual, Section 6.3.2 - "The host must allocate a 2KB
763 * bound memory segment for Channel Group 0."
766 #define GROUP_BOUNDARY 0x800
768 regaddr = OS_kmalloc(sizeof(struct musycc_groupr) + GROUP_BOUNDARY);
769 if (!regaddr) {
770 for (gchan = 0; gchan < i; gchan++) {
771 pi = &ci->port[gchan];
772 OS_kfree(pi->reg);
773 pi->reg = NULL;
775 return -ENOMEM;
777 pi->regram_saved = regaddr; /* save orig value for free's usage */
778 pi->regram = (struct musycc_groupr *) ((unsigned long) (regaddr + GROUP_BOUNDARY - 1) &
779 (~(GROUP_BOUNDARY - 1))); /* this calculates
780 * closest boundary */
783 /* any board centric MUSYCC commands will use group ZERO as its "home" */
784 ci->regram = ci->port[0].regram;
785 musycc_serv_req(&ci->port[0], SR_CHIP_RESET);
787 pci_write_32((u_int32_t *) &ci->reg->gbp, OS_vtophys(ci->regram));
788 pci_flush_write(ci);
789 #ifdef CONFIG_SBE_PMCC4_NCOMM
790 ci->regram->__glcd = __constant_cpu_to_le32(GCD_MAGIC);
791 #else
792 /* standard driver POLLS for INTB via CPLD register */
793 ci->regram->__glcd = __constant_cpu_to_le32(GCD_MAGIC | MUSYCC_GCD_INTB_DISABLE);
794 #endif
796 ci->regram->__iqp = cpu_to_le32(OS_vtophys(&ci->iqd_p[0]));
797 ci->regram->__iql = __constant_cpu_to_le32(INT_QUEUE_SIZE - 1);
798 pci_write_32((u_int32_t *) &ci->reg->dacbp, 0);
799 FLUSH_MEM_WRITE();
801 ci->state = C_RUNNING; /* mark as full interrupt processing
802 * available */
804 musycc_serv_req(&ci->port[0], SR_GLOBAL_INIT); /* FIRST INTERRUPT ! */
806 /* sanity check settable parameters */
808 if (cxt1e1_max_mru > 0xffe) {
809 pr_warning("Maximum allowed MRU exceeded, resetting %d to %d.\n",
810 cxt1e1_max_mru, 0xffe);
811 cxt1e1_max_mru = 0xffe;
813 if (cxt1e1_max_mtu > 0xffe) {
814 pr_warning("Maximum allowed MTU exceeded, resetting %d to %d.\n",
815 cxt1e1_max_mtu, 0xffe);
816 cxt1e1_max_mtu = 0xffe;
818 #ifdef SBE_WAN256T3_ENABLE
819 for (i = 0; i < MUSYCC_NPORTS; i++)
820 musycc_init_port(&ci->port[i]);
821 #endif
823 return SBE_DRVR_SUCCESS; /* no error */
827 void
828 musycc_bh_tx_eom(mpi_t *pi, int gchan)
830 mch_t *ch;
831 struct mdesc *md;
833 #if 0
834 #ifndef SBE_ISR_INLINE
835 unsigned long flags;
837 #endif
838 #endif
839 volatile u_int32_t status;
841 ch = pi->chan[gchan];
842 if (!ch || ch->state != UP) {
843 if (cxt1e1_log_level >= LOG_ERROR)
844 pr_info("%s: intr: xmit EOM on uninitialized channel %d\n",
845 pi->up->devname, gchan);
847 if (!ch || !ch->mdt)
848 return; /* note: mdt==0 implies a malloc()
849 * failure w/in chan_up() routine */
851 #if 0
852 #ifdef SBE_ISR_INLINE
853 spin_lock_irq(&ch->ch_txlock);
854 #else
855 spin_lock_irqsave(&ch->ch_txlock, flags);
856 #endif
857 #endif
858 do {
859 FLUSH_MEM_READ();
860 md = ch->txd_irq_srv;
861 status = le32_to_cpu(md->status);
864 * Note: Per MUSYCC Ref 6.4.9, the host does not poll a host-owned
865 * Transmit Buffer Descriptor during Transparent Mode.
867 if (status & MUSYCC_TX_OWNED) {
868 int readCount, loopCount;
870 /***********************************************************/
871 /* HW Bug Fix */
872 /* ---------- */
873 /* Under certain PCI Bus loading conditions, the data */
874 /* associated with an update of Shared Memory is delayed */
875 /* relative to its PCI Interrupt. This is caught when */
876 /* the host determines it does not yet OWN the descriptor. */
877 /***********************************************************/
879 readCount = 0;
880 while (status & MUSYCC_TX_OWNED) {
881 for (loopCount = 0; loopCount < 0x30; loopCount++)
882 OS_uwait_dummy(); /* use call to avoid optimization
883 * removal of dummy delay */
884 FLUSH_MEM_READ();
885 status = le32_to_cpu(md->status);
886 if (readCount++ > 40)
887 break; /* don't wait any longer */
889 if (status & MUSYCC_TX_OWNED) {
890 if (cxt1e1_log_level >= LOG_MONITOR) {
891 pr_info("%s: Port %d Chan %2d - unexpected TX msg ownership intr (md %p sts %x)\n",
892 pi->up->devname, pi->portnum, ch->channum,
893 md, status);
894 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",
895 ch->user, ch->txd_irq_srv, ch->txd_usr_add,
896 sd_queue_stopped(ch->user),
897 ch->ch_start_tx, ch->tx_full, ch->txd_free, ch->p.chan_mode);
898 musycc_dump_txbuffer_ring(ch, 0);
900 break; /* Not our mdesc, done */
901 } else {
902 if (cxt1e1_log_level >= LOG_MONITOR)
903 pr_info("%s: Port %d Chan %2d - recovered TX msg ownership [%d] (md %p sts %x)\n",
904 pi->up->devname, pi->portnum, ch->channum, readCount, md, status);
907 ch->txd_irq_srv = md->snext;
909 md->data = 0;
910 if (md->mem_token) {
911 /* upcount channel */
912 atomic_sub(OS_mem_token_tlen(md->mem_token), &ch->tx_pending);
913 /* upcount card */
914 atomic_sub(OS_mem_token_tlen(md->mem_token), &pi->up->tx_pending);
915 #ifdef SBE_WAN256T3_ENABLE
916 if (!atomic_read(&pi->up->tx_pending))
917 wan256t3_led(pi->up, LED_TX, 0);
918 #endif
920 #ifdef CONFIG_SBE_WAN256T3_NCOMM
921 /* callback that our packet was sent */
923 int hdlcnum = (pi->portnum * 32 + gchan);
925 if (hdlcnum >= 228) {
926 if (nciProcess_TX_complete)
927 (*nciProcess_TX_complete) (hdlcnum,
928 getuserbychan(gchan));
931 #endif /*** CONFIG_SBE_WAN256T3_NCOMM ***/
933 OS_mem_token_free_irq(md->mem_token);
934 md->mem_token = NULL;
936 md->status = 0;
937 #ifdef RLD_TXFULL_DEBUG
938 if (cxt1e1_log_level >= LOG_MONITOR2)
939 pr_info("~~ tx_eom: tx_full %x txd_free %d -> %d\n",
940 ch->tx_full, ch->txd_free, ch->txd_free + 1);
941 #endif
942 ++ch->txd_free;
943 FLUSH_MEM_WRITE();
945 if ((ch->p.chan_mode != CFG_CH_PROTO_TRANS) && (status & EOBIRQ_ENABLE)) {
946 if (cxt1e1_log_level >= LOG_MONITOR)
947 pr_info("%s: Mode (%x) incorrect EOB status (%x)\n",
948 pi->up->devname, ch->p.chan_mode, status);
949 if ((status & EOMIRQ_ENABLE) == 0)
950 break;
952 } while ((ch->p.chan_mode != CFG_CH_PROTO_TRANS) && ((status & EOMIRQ_ENABLE) == 0));
954 * NOTE: (The above 'while' is coupled w/ previous 'do', way above.) Each
955 * Transparent data buffer has the EOB bit, and NOT the EOM bit, set and
956 * will furthermore have a separate IQD associated with each messages
957 * buffer.
960 FLUSH_MEM_READ();
962 * Smooth flow control hysterisis by maintaining task stoppage until half
963 * the available write buffers are available.
965 if (ch->tx_full && (ch->txd_free >= (ch->txd_num / 2))) {
967 * Then, only releave task stoppage if we actually have enough
968 * buffers to service the last requested packet. It may require MORE
969 * than half the available!
971 if (ch->txd_free >= ch->txd_required) {
973 #ifdef RLD_TXFULL_DEBUG
974 if (cxt1e1_log_level >= LOG_MONITOR2)
975 pr_info("tx_eom[%d]: enable xmit tx_full no more, txd_free %d txd_num/2 %d\n",
976 ch->channum,
977 ch->txd_free, ch->txd_num / 2);
978 #endif
979 ch->tx_full = 0;
980 ch->txd_required = 0;
981 sd_enable_xmit(ch->user); /* re-enable to catch flow controlled
982 * channel */
985 #ifdef RLD_TXFULL_DEBUG
986 else if (ch->tx_full) {
987 if (cxt1e1_log_level >= LOG_MONITOR2)
988 pr_info("tx_eom[%d]: bypass TX enable though room available? (txd_free %d txd_num/2 %d)\n",
989 ch->channum,
990 ch->txd_free, ch->txd_num / 2);
992 #endif
994 FLUSH_MEM_WRITE();
995 #if 0
996 #ifdef SBE_ISR_INLINE
997 spin_unlock_irq(&ch->ch_txlock);
998 #else
999 spin_unlock_irqrestore(&ch->ch_txlock, flags);
1000 #endif
1001 #endif
1005 static void
1006 musycc_bh_rx_eom(mpi_t *pi, int gchan)
1008 mch_t *ch;
1009 void *m, *m2;
1010 struct mdesc *md;
1011 volatile u_int32_t status;
1012 u_int32_t error;
1014 ch = pi->chan[gchan];
1015 if (!ch || ch->state != UP) {
1016 if (cxt1e1_log_level > LOG_ERROR)
1017 pr_info("%s: intr: receive EOM on uninitialized channel %d\n",
1018 pi->up->devname, gchan);
1019 return;
1021 if (!ch->mdr)
1022 return; /* can this happen ? */
1024 for (;;) {
1025 FLUSH_MEM_READ();
1026 md = &ch->mdr[ch->rxix_irq_srv];
1027 status = le32_to_cpu(md->status);
1028 if (!(status & HOST_RX_OWNED))
1029 break; /* Not our mdesc, done */
1030 m = md->mem_token;
1031 error = (status >> 16) & 0xf;
1032 if (error == 0) {
1033 #ifdef CONFIG_SBE_WAN256T3_NCOMM
1034 int hdlcnum = (pi->portnum * 32 + gchan);
1037 * if the packet number belongs to NCOMM, then send it to the TMS
1038 * driver
1040 if (hdlcnum >= 228) {
1041 if (nciProcess_RX_packet)
1042 (*nciProcess_RX_packet) (hdlcnum, status & 0x3fff, m, ch->user);
1043 } else
1044 #endif /*** CONFIG_SBE_WAN256T3_NCOMM ***/
1047 m2 = OS_mem_token_alloc(cxt1e1_max_mru);
1048 if (m2) {
1049 /* substitute the mbuf+cluster */
1050 md->mem_token = m2;
1051 md->data = cpu_to_le32(OS_vtophys(
1052 OS_mem_token_data(m2)));
1054 /* pass the received mbuf upward */
1055 sd_recv_consume(m, status & LENGTH_MASK, ch->user);
1056 ch->s.rx_packets++;
1057 ch->s.rx_bytes += status & LENGTH_MASK;
1058 } else
1059 ch->s.rx_dropped++;
1061 } else if (error == ERR_FCS)
1062 ch->s.rx_crc_errors++;
1063 else if (error == ERR_ALIGN)
1064 ch->s.rx_missed_errors++;
1065 else if (error == ERR_ABT)
1066 ch->s.rx_missed_errors++;
1067 else if (error == ERR_LNG)
1068 ch->s.rx_length_errors++;
1069 else if (error == ERR_SHT)
1070 ch->s.rx_length_errors++;
1071 FLUSH_MEM_WRITE();
1072 status = cxt1e1_max_mru;
1073 if (ch->p.chan_mode == CFG_CH_PROTO_TRANS)
1074 status |= EOBIRQ_ENABLE;
1075 md->status = cpu_to_le32(status);
1077 /* Check next mdesc in the ring */
1078 if (++ch->rxix_irq_srv >= ch->rxd_num)
1079 ch->rxix_irq_srv = 0;
1080 FLUSH_MEM_WRITE();
1085 irqreturn_t
1086 musycc_intr_th_handler(void *devp)
1088 ci_t *ci = (ci_t *) devp;
1089 volatile u_int32_t status, currInt = 0;
1090 u_int32_t nextInt, intCnt;
1093 * Hardware not available, potential interrupt hang. But since interrupt
1094 * might be shared, just return.
1096 if (ci->state == C_INIT)
1097 return IRQ_NONE;
1099 * Marked as hardware available. Don't service interrupts, just clear the
1100 * event.
1103 if (ci->state == C_IDLE) {
1104 status = pci_read_32((u_int32_t *) &ci->reg->isd);
1106 /* clear the interrupt but process nothing else */
1107 pci_write_32((u_int32_t *) &ci->reg->isd, status);
1108 return IRQ_HANDLED;
1110 FLUSH_PCI_READ();
1111 FLUSH_MEM_READ();
1113 status = pci_read_32((u_int32_t *) &ci->reg->isd);
1114 nextInt = INTRPTS_NEXTINT(status);
1115 intCnt = INTRPTS_INTCNT(status);
1116 ci->intlog.drvr_intr_thcount++;
1118 /*********************************************************/
1119 /* HW Bug Fix */
1120 /* ---------- */
1121 /* Under certain PCI Bus loading conditions, the */
1122 /* MUSYCC looses the data associated with an update */
1123 /* of its ISD and erroneously returns the immediately */
1124 /* preceding 'nextInt' value. However, the 'intCnt' */
1125 /* value appears to be correct. By not starting service */
1126 /* where the 'missing' 'nextInt' SHOULD point causes */
1127 /* the IQD not to be serviced - the 'not serviced' */
1128 /* entries then remain and continue to increase as more */
1129 /* incorrect ISD's are encountered. */
1130 /*********************************************************/
1132 if (nextInt != INTRPTS_NEXTINT(ci->intlog.this_status_new)) {
1133 if (cxt1e1_log_level >= LOG_MONITOR) {
1134 pr_info("%s: note - updated ISD from %08x to %08x\n",
1135 ci->devname, status,
1136 (status & (~INTRPTS_NEXTINT_M)) | ci->intlog.this_status_new);
1139 * Replace bogus status with software corrected value.
1141 * It's not known whether, during this problem occurrence, if the
1142 * INTFULL bit is correctly reported or not.
1144 status = (status & (~INTRPTS_NEXTINT_M)) | (ci->intlog.this_status_new);
1145 nextInt = INTRPTS_NEXTINT(status);
1147 /**********************************************/
1148 /* Cn847x Bug Fix */
1149 /* -------------- */
1150 /* Fix for inability to write back same index */
1151 /* as read for a full interrupt queue. */
1152 /**********************************************/
1154 if (intCnt == INT_QUEUE_SIZE)
1155 currInt = ((intCnt - 1) + nextInt) & (INT_QUEUE_SIZE - 1);
1156 else
1157 /************************************************/
1158 /* Interrupt Write Location Issues */
1159 /* ------------------------------- */
1160 /* When the interrupt status descriptor is */
1161 /* written, the interrupt line is de-asserted */
1162 /* by the Cn847x. In the case of MIPS */
1163 /* microprocessors, this must occur at the */
1164 /* beginning of the interrupt handler so that */
1165 /* the interrupt handle is not re-entered due */
1166 /* to interrupt dis-assertion latency. */
1167 /* In the case of all other processors, this */
1168 /* action should occur at the end of the */
1169 /* interrupt handler to avoid overwriting the */
1170 /* interrupt queue. */
1171 /************************************************/
1173 if (intCnt)
1174 currInt = (intCnt + nextInt) & (INT_QUEUE_SIZE - 1);
1175 else {
1177 * NOTE: Servicing an interrupt whose ISD contains a count of ZERO
1178 * can be indicative of a Shared Interrupt chain. Our driver can be
1179 * called from the system's interrupt handler as a matter of the OS
1180 * walking the chain. As the chain is walked, the interrupt will
1181 * eventually be serviced by the correct driver/handler.
1183 #if 0
1184 /* chained interrupt = not ours */
1185 pr_info(">> %s: intCnt NULL, sts %x, possibly a chained interrupt!\n",
1186 ci->devname, status);
1187 #endif
1188 return IRQ_NONE;
1191 ci->iqp_tailx = currInt;
1193 currInt <<= INTRPTS_NEXTINT_S;
1194 ci->intlog.last_status_new = ci->intlog.this_status_new;
1195 ci->intlog.this_status_new = currInt;
1197 if ((cxt1e1_log_level >= LOG_WARN) && (status & INTRPTS_INTFULL_M))
1198 pr_info("%s: Interrupt queue full condition occurred\n", ci->devname);
1199 if (cxt1e1_log_level >= LOG_DEBUG)
1200 pr_info("%s: interrupts pending, isd @ 0x%p: %x curr %d cnt %d NEXT %d\n",
1201 ci->devname, &ci->reg->isd,
1202 status, nextInt, intCnt, (intCnt + nextInt) & (INT_QUEUE_SIZE - 1));
1204 FLUSH_MEM_WRITE();
1205 #if defined(SBE_ISR_TASKLET)
1206 pci_write_32((u_int32_t *) &ci->reg->isd, currInt);
1207 atomic_inc(&ci->bh_pending);
1208 tasklet_schedule(&ci->ci_musycc_isr_tasklet);
1209 #elif defined(SBE_ISR_IMMEDIATE)
1210 pci_write_32((u_int32_t *) &ci->reg->isd, currInt);
1211 atomic_inc(&ci->bh_pending);
1212 queue_task(&ci->ci_musycc_isr_tq, &tq_immediate);
1213 mark_bh(IMMEDIATE_BH);
1214 #elif defined(SBE_ISR_INLINE)
1215 (void) musycc_intr_bh_tasklet(ci);
1216 pci_write_32((u_int32_t *) &ci->reg->isd, currInt);
1217 #endif
1218 return IRQ_HANDLED;
1222 #if defined(SBE_ISR_IMMEDIATE)
1223 unsigned long
1224 #else
1225 void
1226 #endif
1227 musycc_intr_bh_tasklet(ci_t *ci)
1229 mpi_t *pi;
1230 mch_t *ch;
1231 unsigned int intCnt;
1232 volatile u_int32_t currInt = 0;
1233 volatile unsigned int headx, tailx;
1234 int readCount, loopCount;
1235 int group, gchan, event, err, tx;
1236 u_int32_t badInt = INT_EMPTY_ENTRY;
1237 u_int32_t badInt2 = INT_EMPTY_ENTRY2;
1240 * Hardware not available, potential interrupt hang. But since interrupt
1241 * might be shared, just return.
1243 if ((drvr_state != SBE_DRVR_AVAILABLE) || (ci->state == C_INIT)) {
1244 #if defined(SBE_ISR_IMMEDIATE)
1245 return 0L;
1246 #else
1247 return;
1248 #endif
1250 #if defined(SBE_ISR_TASKLET) || defined(SBE_ISR_IMMEDIATE)
1251 if (drvr_state != SBE_DRVR_AVAILABLE) {
1252 #if defined(SBE_ISR_TASKLET)
1253 return;
1254 #elif defined(SBE_ISR_IMMEDIATE)
1255 return 0L;
1256 #endif
1258 #elif defined(SBE_ISR_INLINE)
1259 /* no semaphore taken, no double checks */
1260 #endif
1262 ci->intlog.drvr_intr_bhcount++;
1263 FLUSH_MEM_READ();
1265 unsigned int bh = atomic_read(&ci->bh_pending);
1267 max_bh = max(bh, max_bh);
1269 atomic_set(&ci->bh_pending, 0);/* if here, no longer pending */
1270 while ((headx = ci->iqp_headx) != (tailx = ci->iqp_tailx)) {
1271 intCnt = (tailx >= headx) ? (tailx - headx) : (tailx - headx + INT_QUEUE_SIZE);
1272 currInt = le32_to_cpu(ci->iqd_p[headx]);
1274 max_intcnt = max(intCnt, max_intcnt); /* RLD DEBUG */
1276 /**************************************************/
1277 /* HW Bug Fix */
1278 /* ---------- */
1279 /* The following code checks for the condition */
1280 /* of interrupt assertion before interrupt */
1281 /* queue update. This is a problem on several */
1282 /* PCI-Local bridge chips found on some products. */
1283 /**************************************************/
1285 readCount = 0;
1286 if ((currInt == badInt) || (currInt == badInt2))
1287 ci->intlog.drvr_int_failure++;
1289 while ((currInt == badInt) || (currInt == badInt2)) {
1290 for (loopCount = 0; loopCount < 0x30; loopCount++)
1291 OS_uwait_dummy(); /* use call to avoid optimization removal
1292 * of dummy delay */
1293 FLUSH_MEM_READ();
1294 currInt = le32_to_cpu(ci->iqd_p[headx]);
1295 if (readCount++ > 20)
1296 break;
1299 if ((currInt == badInt) || (currInt == badInt2)) { /* catch failure of Bug
1300 * Fix checking */
1301 if (cxt1e1_log_level >= LOG_WARN)
1302 pr_info("%s: Illegal Interrupt Detected @ 0x%p, mod %d.)\n",
1303 ci->devname, &ci->iqd_p[headx], headx);
1306 * If the descriptor has not recovered, then leaving the EMPTY
1307 * entry set will not signal to the MUSYCC that this descriptor
1308 * has been serviced. The Interrupt Queue can then start losing
1309 * available descriptors and MUSYCC eventually encounters and
1310 * reports the INTFULL condition. Per manual, changing any bit
1311 * marks descriptor as available, thus the use of different
1312 * EMPTY_ENTRY values.
1315 if (currInt == badInt)
1316 ci->iqd_p[headx] = __constant_cpu_to_le32(INT_EMPTY_ENTRY2);
1317 else
1318 ci->iqd_p[headx] = __constant_cpu_to_le32(INT_EMPTY_ENTRY);
1319 ci->iqp_headx = (headx + 1) & (INT_QUEUE_SIZE - 1); /* insure wrapness */
1320 FLUSH_MEM_WRITE();
1321 FLUSH_MEM_READ();
1322 continue;
1324 group = INTRPT_GRP(currInt);
1325 gchan = INTRPT_CH(currInt);
1326 event = INTRPT_EVENT(currInt);
1327 err = INTRPT_ERROR(currInt);
1328 tx = currInt & INTRPT_DIR_M;
1330 ci->iqd_p[headx] = __constant_cpu_to_le32(INT_EMPTY_ENTRY);
1331 FLUSH_MEM_WRITE();
1333 if (cxt1e1_log_level >= LOG_DEBUG) {
1334 if (err != 0)
1335 pr_info(" %08x -> err: %2d,", currInt, err);
1337 pr_info("+ interrupt event: %d, grp: %d, chan: %2d, side: %cX\n",
1338 event, group, gchan, tx ? 'T' : 'R');
1340 pi = &ci->port[group]; /* notice that here we assume 1-1 group -
1341 * port mapping */
1342 ch = pi->chan[gchan];
1343 switch (event) {
1344 case EVE_SACK: /* Service Request Acknowledge */
1345 if (cxt1e1_log_level >= LOG_DEBUG) {
1346 volatile u_int32_t r;
1348 r = pci_read_32((u_int32_t *) &pi->reg->srd);
1349 pr_info("- SACK cmd: %08x (hdw= %08x)\n", pi->sr_last, r);
1351 SD_SEM_GIVE(&pi->sr_sem_wait); /* wake up waiting process */
1352 break;
1353 case EVE_CHABT: /* Change To Abort Code (0x7e -> 0xff) */
1354 case EVE_CHIC: /* Change To Idle Code (0xff -> 0x7e) */
1355 break;
1356 case EVE_EOM: /* End Of Message */
1357 case EVE_EOB: /* End Of Buffer (Transparent mode) */
1358 if (tx)
1359 musycc_bh_tx_eom(pi, gchan);
1360 else
1361 musycc_bh_rx_eom(pi, gchan);
1362 #if 0
1363 break;
1364 #else
1366 * MUSYCC Interrupt Descriptor section states that EOB and EOM
1367 * can be combined with the NONE error (as well as others). So
1368 * drop thru to catch this...
1370 #endif
1371 case EVE_NONE:
1372 if (err == ERR_SHT)
1373 ch->s.rx_length_errors++;
1374 break;
1375 default:
1376 if (cxt1e1_log_level >= LOG_WARN)
1377 pr_info("%s: unexpected interrupt event: %d, iqd[%d]: %08x, port: %d\n", ci->devname,
1378 event, headx, currInt, group);
1379 break;
1380 } /* switch on event */
1384 * Per MUSYCC Manual, Section 6.4.8.3 [Transmit Errors], TX errors
1385 * are service-affecting and require action to resume normal
1386 * bit-level processing.
1389 switch (err) {
1390 case ERR_ONR:
1392 * Per MUSYCC manual, Section 6.4.8.3 [Transmit Errors], this
1393 * error requires Transmit channel reactivation.
1395 * Per MUSYCC manual, Section 6.4.8.4 [Receive Errors], this error
1396 * requires Receive channel reactivation.
1398 if (tx) {
1401 * TX ONR Error only occurs when channel is configured for
1402 * Transparent Mode. However, this code will catch and
1403 * re-activate on ANY TX ONR error.
1407 * Set flag to re-enable on any next transmit attempt.
1409 ch->ch_start_tx = CH_START_TX_ONR;
1412 #ifdef RLD_TRANS_DEBUG
1413 if (1 || cxt1e1_log_level >= LOG_MONITOR)
1414 #else
1415 if (cxt1e1_log_level >= LOG_MONITOR)
1416 #endif
1418 pr_info("%s: TX buffer underflow [ONR] on channel %d, mode %x QStopped %x free %d\n",
1419 ci->devname, ch->channum, ch->p.chan_mode, sd_queue_stopped(ch->user), ch->txd_free);
1420 #ifdef RLD_DEBUG
1421 if (ch->p.chan_mode == 2) { /* problem = ONR on HDLC
1422 * mode */
1423 pr_info("++ Failed Last %x Next %x QStopped %x, start_tx %x tx_full %d txd_free %d mode %x\n",
1424 (u_int32_t) ch->txd_irq_srv, (u_int32_t) ch->txd_usr_add,
1425 sd_queue_stopped(ch->user),
1426 ch->ch_start_tx, ch->tx_full, ch->txd_free, ch->p.chan_mode);
1427 musycc_dump_txbuffer_ring(ch, 0);
1429 #endif
1432 } else { /* RX buffer overrun */
1434 * Per MUSYCC manual, Section 6.4.8.4 [Receive Errors],
1435 * channel recovery for this RX ONR error IS required. It is
1436 * also suggested to increase the number of receive buffers
1437 * for this channel. Receive channel reactivation IS
1438 * required, and data has been lost.
1440 ch->s.rx_over_errors++;
1441 ch->ch_start_rx = CH_START_RX_ONR;
1443 if (cxt1e1_log_level >= LOG_WARN) {
1444 pr_info("%s: RX buffer overflow [ONR] on channel %d, mode %x\n",
1445 ci->devname, ch->channum, ch->p.chan_mode);
1446 //musycc_dump_rxbuffer_ring (ch, 0); /* RLD DEBUG */
1449 musycc_chan_restart(ch);
1450 break;
1451 case ERR_BUF:
1452 if (tx) {
1453 ch->s.tx_fifo_errors++;
1454 ch->ch_start_tx = CH_START_TX_BUF;
1456 * Per MUSYCC manual, Section 6.4.8.3 [Transmit Errors],
1457 * this BUFF error requires Transmit channel reactivation.
1459 if (cxt1e1_log_level >= LOG_MONITOR)
1460 pr_info("%s: TX buffer underrun [BUFF] on channel %d, mode %x\n",
1461 ci->devname, ch->channum, ch->p.chan_mode);
1462 } else { /* RX buffer overrun */
1463 ch->s.rx_over_errors++;
1465 * Per MUSYCC manual, Section 6.4.8.4 [Receive Errors], HDLC
1466 * mode requires NO recovery for this RX BUFF error is
1467 * required. It is suggested to increase the FIFO buffer
1468 * space for this channel. Receive channel reactivation is
1469 * not required, but data has been lost.
1471 if (cxt1e1_log_level >= LOG_WARN)
1472 pr_info("%s: RX buffer overrun [BUFF] on channel %d, mode %x\n",
1473 ci->devname, ch->channum, ch->p.chan_mode);
1475 * Per MUSYCC manual, Section 6.4.9.4 [Receive Errors],
1476 * Transparent mode DOES require recovery for the RX BUFF
1477 * error. It is suggested to increase the FIFO buffer space
1478 * for this channel. Receive channel reactivation IS
1479 * required and data has been lost.
1481 if (ch->p.chan_mode == CFG_CH_PROTO_TRANS)
1482 ch->ch_start_rx = CH_START_RX_BUF;
1485 if (tx || (ch->p.chan_mode == CFG_CH_PROTO_TRANS))
1486 musycc_chan_restart(ch);
1487 break;
1488 default:
1489 break;
1490 } /* switch on err */
1492 /* Check for interrupt lost condition */
1493 if ((currInt & INTRPT_ILOST_M) && (cxt1e1_log_level >= LOG_ERROR))
1494 pr_info("%s: Interrupt queue overflow - ILOST asserted\n",
1495 ci->devname);
1496 ci->iqp_headx = (headx + 1) & (INT_QUEUE_SIZE - 1); /* insure wrapness */
1497 FLUSH_MEM_WRITE();
1498 FLUSH_MEM_READ();
1499 } /* while */
1500 if ((cxt1e1_log_level >= LOG_MONITOR2) && (ci->iqp_headx != ci->iqp_tailx)) {
1501 int bh;
1503 bh = atomic_read(&CI->bh_pending);
1504 pr_info("_bh_: late arrivals, head %d != tail %d, pending %d\n",
1505 ci->iqp_headx, ci->iqp_tailx, bh);
1507 #if defined(SBE_ISR_IMMEDIATE)
1508 return 0L;
1509 #endif
1510 /* else, nothing returned */
1513 #if 0
1514 int __init
1515 musycc_new_chan(ci_t *ci, int channum, void *user)
1517 mch_t *ch;
1519 ch = ci->port[channum / MUSYCC_NCHANS].chan[channum % MUSYCC_NCHANS];
1521 if (ch->state != UNASSIGNED)
1522 return EEXIST;
1523 /* NOTE: mch_t already cleared during OS_kmalloc() */
1524 ch->state = DOWN;
1525 ch->user = user;
1526 #if 0
1527 ch->status = 0;
1528 ch->p.status = 0;
1529 ch->p.intr_mask = 0;
1530 #endif
1531 ch->p.chan_mode = CFG_CH_PROTO_HDLC_FCS16;
1532 ch->p.idlecode = CFG_CH_FLAG_7E;
1533 ch->p.pad_fill_count = 2;
1534 spin_lock_init(&ch->ch_rxlock);
1535 spin_lock_init(&ch->ch_txlock);
1537 return 0;
1539 #endif
1542 #ifdef SBE_PMCC4_ENABLE
1543 status_t
1544 musycc_chan_down(ci_t *dummy, int channum)
1546 mpi_t *pi;
1547 mch_t *ch;
1548 int i, gchan;
1550 ch = sd_find_chan(dummy, channum);
1551 if (!ch)
1552 return -EINVAL;
1553 pi = ch->up;
1554 gchan = ch->gchan;
1556 /* Deactivate the channel */
1557 musycc_serv_req(pi, SR_CHANNEL_DEACTIVATE | SR_RX_DIRECTION | gchan);
1558 ch->ch_start_rx = 0;
1559 musycc_serv_req(pi, SR_CHANNEL_DEACTIVATE | SR_TX_DIRECTION | gchan);
1560 ch->ch_start_tx = 0;
1562 if (ch->state == DOWN)
1563 return 0;
1564 ch->state = DOWN;
1566 pi->regram->thp[gchan] = 0;
1567 pi->regram->tmp[gchan] = 0;
1568 pi->regram->rhp[gchan] = 0;
1569 pi->regram->rmp[gchan] = 0;
1570 FLUSH_MEM_WRITE();
1571 for (i = 0; i < ch->txd_num; i++)
1572 if (ch->mdt[i].mem_token)
1573 OS_mem_token_free(ch->mdt[i].mem_token);
1575 for (i = 0; i < ch->rxd_num; i++)
1576 if (ch->mdr[i].mem_token)
1577 OS_mem_token_free(ch->mdr[i].mem_token);
1579 OS_kfree(ch->mdr);
1580 ch->mdr = NULL;
1581 ch->rxd_num = 0;
1582 OS_kfree(ch->mdt);
1583 ch->mdt = NULL;
1584 ch->txd_num = 0;
1586 musycc_update_timeslots(pi);
1587 c4_fifo_free(pi, ch->gchan);
1589 pi->openchans--;
1590 return 0;
1592 #endif
1595 #if 0
1596 /* TODO: determine if these functions will not be needed and can be removed */
1598 musycc_del_chan(ci_t *ci, int channum)
1600 mch_t *ch;
1602 if ((channum < 0) || (channum >= (MUSYCC_NPORTS * MUSYCC_NCHANS))) /* sanity chk param */
1603 return ECHRNG;
1604 ch = sd_find_chan(ci, channum);
1605 if (!ch)
1606 return ENOENT;
1607 if (ch->state == UP)
1608 musycc_chan_down(ci, channum);
1609 ch->state = UNASSIGNED;
1610 return 0;
1615 musycc_del_chan_stats(ci_t *ci, int channum)
1617 mch_t *ch;
1619 if (channum < 0 || channum >= (MUSYCC_NPORTS * MUSYCC_NCHANS)) /* sanity chk param */
1620 return ECHRNG;
1621 ch = sd_find_chan(ci, channum);
1622 if (!ch)
1623 return ENOENT;
1625 memset(&ch->s, 0, sizeof(struct sbecom_chan_stats));
1626 return 0;
1628 #endif
1632 musycc_start_xmit(ci_t *ci, int channum, void *mem_token)
1634 mch_t *ch;
1635 struct mdesc *md;
1636 void *m2;
1637 #if 0
1638 unsigned long flags;
1639 #endif
1640 int txd_need_cnt;
1641 u_int32_t len;
1643 ch = sd_find_chan(ci, channum);
1644 if (!ch)
1645 return -ENOENT;
1647 if (ci->state != C_RUNNING) /* full interrupt processing available */
1648 return -EINVAL;
1649 if (ch->state != UP)
1650 return -EINVAL;
1652 if (!(ch->status & TX_ENABLED))
1653 return -EROFS; /* how else to flag unwritable state ? */
1655 #ifdef RLD_TRANS_DEBUGx
1656 if (1 || cxt1e1_log_level >= LOG_MONITOR2)
1657 #else
1658 if (cxt1e1_log_level >= LOG_MONITOR2)
1659 #endif
1661 pr_info("++ start_xmt[%d]: state %x start %x full %d free %d required %d stopped %x\n",
1662 channum, ch->state, ch->ch_start_tx, ch->tx_full,
1663 ch->txd_free, ch->txd_required, sd_queue_stopped(ch->user));
1665 /***********************************************/
1666 /** Determine total amount of data to be sent **/
1667 /***********************************************/
1668 m2 = mem_token;
1669 txd_need_cnt = 0;
1670 for (len = OS_mem_token_tlen(m2); len > 0;
1671 m2 = (void *) OS_mem_token_next(m2)) {
1672 if (!OS_mem_token_len(m2))
1673 continue;
1674 txd_need_cnt++;
1675 len -= OS_mem_token_len(m2);
1678 if (txd_need_cnt == 0) {
1679 if (cxt1e1_log_level >= LOG_MONITOR2)
1680 pr_info("%s channel %d: no TX data in User buffer\n", ci->devname, channum);
1681 OS_mem_token_free(mem_token);
1682 return 0; /* no data to send */
1684 /*************************************************/
1685 /** Are there sufficient descriptors available? **/
1686 /*************************************************/
1687 if (txd_need_cnt > ch->txd_num) { /* never enough descriptors for this
1688 * large a buffer */
1689 if (cxt1e1_log_level >= LOG_DEBUG)
1690 pr_info("start_xmit: discarding buffer, insufficient descriptor cnt %d, need %d.\n",
1691 ch->txd_num, txd_need_cnt + 1);
1692 ch->s.tx_dropped++;
1693 OS_mem_token_free(mem_token);
1694 return 0;
1696 #if 0
1697 spin_lock_irqsave(&ch->ch_txlock, flags);
1698 #endif
1699 /************************************************************/
1700 /** flow control the line if not enough descriptors remain **/
1701 /************************************************************/
1702 if (txd_need_cnt > ch->txd_free) {
1703 if (cxt1e1_log_level >= LOG_MONITOR2)
1704 pr_info("start_xmit[%d]: EBUSY - need more descriptors, have %d of %d need %d\n",
1705 channum, ch->txd_free, ch->txd_num, txd_need_cnt);
1706 ch->tx_full = 1;
1707 ch->txd_required = txd_need_cnt;
1708 sd_disable_xmit(ch->user);
1709 #if 0
1710 spin_unlock_irqrestore(&ch->ch_txlock, flags);
1711 #endif
1712 return -EBUSY; /* tell user to try again later */
1714 /**************************************************/
1715 /** Put the user data into MUSYCC data buffer(s) **/
1716 /**************************************************/
1717 m2 = mem_token;
1718 md = ch->txd_usr_add; /* get current available descriptor */
1720 for (len = OS_mem_token_tlen(m2); len > 0; m2 = OS_mem_token_next(m2)) {
1721 int u = OS_mem_token_len(m2);
1723 if (!u)
1724 continue;
1725 len -= u;
1728 * Enable following chunks, yet wait to enable the FIRST chunk until
1729 * after ALL subsequent chunks are setup.
1731 if (md != ch->txd_usr_add) /* not first chunk */
1732 u |= MUSYCC_TX_OWNED; /* transfer ownership from HOST to MUSYCC */
1734 if (len) /* not last chunk */
1735 u |= EOBIRQ_ENABLE;
1736 else if (ch->p.chan_mode == CFG_CH_PROTO_TRANS) {
1738 * Per MUSYCC Ref 6.4.9 for Transparent Mode, the host must
1739 * always clear EOMIRQ_ENABLE in every Transmit Buffer Descriptor
1740 * (IE. don't set herein).
1742 u |= EOBIRQ_ENABLE;
1743 } else
1744 u |= EOMIRQ_ENABLE; /* EOM, last HDLC chunk */
1747 /* last chunk in hdlc mode */
1748 u |= (ch->p.idlecode << IDLE_CODE);
1749 if (ch->p.pad_fill_count) {
1750 #if 0
1751 /* NOOP NOTE: u_int8_t cannot be > 0xFF */
1752 /* sanitize pad_fill_count for maximums allowed by hardware */
1753 if (ch->p.pad_fill_count > EXTRA_FLAGS_MASK)
1754 ch->p.pad_fill_count = EXTRA_FLAGS_MASK;
1755 #endif
1756 u |= (PADFILL_ENABLE | (ch->p.pad_fill_count << EXTRA_FLAGS));
1758 md->mem_token = len ? NULL : mem_token; /* Fill in mds on last
1759 * segment, others set ZERO
1760 * so that entire token is
1761 * removed ONLY when ALL
1762 * segments have been
1763 * transmitted. */
1765 md->data = cpu_to_le32(OS_vtophys(OS_mem_token_data(m2)));
1766 FLUSH_MEM_WRITE();
1767 md->status = cpu_to_le32(u);
1768 --ch->txd_free;
1769 md = md->snext;
1771 FLUSH_MEM_WRITE();
1775 * Now transfer ownership of first chunk from HOST to MUSYCC in order to
1776 * fire-off this XMIT.
1778 ch->txd_usr_add->status |= __constant_cpu_to_le32(MUSYCC_TX_OWNED);
1779 FLUSH_MEM_WRITE();
1780 ch->txd_usr_add = md;
1782 len = OS_mem_token_tlen(mem_token);
1783 atomic_add(len, &ch->tx_pending);
1784 atomic_add(len, &ci->tx_pending);
1785 ch->s.tx_packets++;
1786 ch->s.tx_bytes += len;
1788 * If an ONR was seen, then channel requires poking to restart
1789 * transmission.
1791 if (ch->ch_start_tx)
1792 musycc_chan_restart(ch);
1793 #ifdef SBE_WAN256T3_ENABLE
1794 wan256t3_led(ci, LED_TX, LEDV_G);
1795 #endif
1796 return 0;
1800 /*** End-of-File ***/