25 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
27 #include <linux/types.h>
29 #include <linux/kernel.h>
30 #include <linux/errno.h>
38 #ifdef SBE_INCLUDE_SYMBOLS
44 #define sd_find_chan(ci,ch) c4_find_chan(ch)
80 unsigned long flags = 0;
91 pr_info(
" ZERO receive buffers allocated for this channel.");
100 pr_info(
"%c %08lx[%2d]: sts %08x (%c%c%c%c:%d.) Data [%08x] Next [%08x]\n",
102 (
unsigned long) m, n,
110 #ifdef RLD_DUMP_BUFDATA
116 if (m->data && (status & HOST_RX_OWNED))
125 *dp, *(dp + 1), *(dp + 2), *(dp + 3));
126 else if (len >= 0x08)
142 spin_unlock_irqrestore (&ch->
ch_rxlock, flags);
153 unsigned long flags = 0;
163 pr_info(
" ZERO transmit buffers allocated for this channel.");
172 pr_info(
"%c%c %08lx[%2d]: sts %08x (%c%c%c%c:%d.) Data [%08x] Next [%08x]\n",
175 (
unsigned long) m, n,
183 #ifdef RLD_DUMP_BUFDATA
193 *dp, *(dp + 1), *(dp + 2), *(dp + 3));
194 else if (len >= 0x08)
210 spin_unlock_irqrestore (&ch->
ch_txlock, flags);
235 pr_info(
">> bh_pend %d [%d] ihead %d itail %d [%d] th_cnt %d bh_cnt %d wdcnt %d note %d\n",
237 ci->
intlog.drvr_intr_thcount,
238 ci->
intlog.drvr_intr_bhcount,
246 pr_info(
">> musycc_dump_ring: channel %d not up.\n", chan);
249 pr_info(
">> CI %p CHANNEL %3d @ %p: state %x status/p %x/%x\n", ci, chan, ch, ch->
state,
251 pr_info(
"--------------------------------\nTX Buffer Ring - Channel %d, txd_num %d. (bd/ch pend %d %d), TXD required %d, txpkt %lu\n",
254 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",
259 pr_info(
"RX Buffer Ring - Channel %d, rxd_num %d. IRQ_SRV[%d] 0x%p, start_rx %x rxpkt %lu\n",
273 for (chan = start_chan; chan < (start_chan + 5); chan++)
301 for (i = 0; i < 32; addr++, i++)
324 spin_unlock_irqrestore (&ch->
ch_txlock, flags);
351 spin_unlock_irqrestore (&ch->
ch_txlock, flags);
353 #ifdef RLD_TRANS_DEBUG
354 pr_info(
"++ musycc_update_tx_thp[%d]: setting thp = %p, sts %x\n", ch->
channum, md, md->
status);
381 #ifdef RLD_TRANS_DEBUG
382 pr_info(
"wq_chan_restart[%d]: start_RT[%d/%d] status %x\n",
395 #if defined(RLD_TRANS_DEBUG) || defined(RLD_RXACT_DEBUG)
397 static int hereb4 = 7;
402 #ifdef RLD_TRANS_DEBUG
404 pr_info(
"++ musycc_wq_chan_restart[%d] CHAN RX ACTIVATE: rxix_irq_srv %d, md %p sts %x, rxpkt %lu\n",
407 #elif defined(RLD_RXACT_DEBUG)
409 pr_info(
"++ musycc_wq_chan_restart[%d] CHAN RX ACTIVATE: rxix_irq_srv %d, md %p sts %x, rxpkt %lu\n",
434 #ifdef RLD_TRANS_DEBUG
435 pr_info(
"-- musycc_wq_chan_restart[%d]: WARNING, starting NULL md\n", ch->
channum);
438 spin_unlock_irqrestore (&ch->
ch_txlock, flags);
444 spin_unlock_irqrestore (&ch->
ch_txlock, flags);
446 #ifdef RLD_TRANS_DEBUG
447 pr_info(
"++ musycc_wq_chan_restart() CHAN TX ACTIVATE: chan %d txd_irq_srv %p = sts %x, txpkt %lu\n",
452 #ifdef RLD_RESTART_DEBUG
456 pr_info(
"-- musycc_wq_chan_restart[%d]: DELAYED due to md %p sts %x data %x, start_tx %x\n",
462 spin_unlock_irqrestore (&ch->
ch_txlock, flags);
478 #ifdef RLD_RESTART_DEBUG
479 pr_info(
"++ musycc_chan_restart[%d]: txd_irq_srv @ %p = sts %x\n",
484 #ifdef RLD_RESTART_DEBUG
507 #define MUSYCC_SR_RETRY_CNT 9
528 #ifdef RLD_TRANS_DEBUG
544 #ifdef RLD_TRANS_DEBUG
545 pr_info(
">> same CHAN ACT SR, Port %d Req %x => issue SR_NOOP CMD\n", pi->
portnum, req);
554 #ifdef RLD_TRANS_DEBUG
582 pr_info(
"%s: %d - reissue srv req/last %x/%x (hdw reads %x), Chan %d.\n",
583 pi->
up->devname, rcnt, req, pi->
sr_last, r,
591 pr_warning(
"%s: failed service request (#%d)= %x, group %d.\n",
616 #ifdef SBE_PMCC4_ENABLE
623 for (i = 0; i < 32; i++)
629 if (((i == 0) && e1mode) ||
631 || ((i > 23) && (!e1mode)))
638 for (j = 0; j < 8; j++)
646 lastval = pi->
chan[ch]->
p.bitmask[
i];
647 for (j = 0; j < 8; j++)
648 if (lastval & (1 << j))
650 pi->
tsm[
i] |= lastval;
655 else if ((usedby == 1) && (lastval == 0xff))
656 ts = (4 << 5) | last;
657 else if ((usedby == 1) && (lastval == 0x7f))
658 ts = (5 << 5) | last;
664 ts = (6 << 5) | (idx = last);
666 ts = (7 << 5) | (idx = bits[0]);
667 for (j = 1; j < 8; j++)
669 pi->
regram->rscm[idx * 8 +
j] = (bits[
j] < 0) ? 0 : (0x80 | bits[j]);
670 pi->
regram->tscm[idx * 8 +
j] = (bits[
j] < 0) ? 0 : (0x80 | bits[j]);
686 #ifdef SBE_WAN256T3_ENABLE
696 #ifdef SBE_PMCC4_ENABLE
697 hmask = (0x1f << pi->
up->p.hypersize) & 0x1f;
699 #ifdef SBE_WAN256T3_ENABLE
700 hmask = (0x1f << hyperdummy) & 0x1f;
702 for (i = 0; i < 128; i++)
705 ch = pi->
chan[gchan];
710 ts = ((pi->
portnum % 4) == (i / 32)) ? (tsen << 5) | (i & hmask) : 0;
751 #ifdef SBE_WAN256T3_ENABLE
799 #define INT_QUEUE_BOUNDARY 4
823 #define GROUP_BOUNDARY 0x800
828 for (gchan = 0; gchan <
i; gchan++)
830 pi = &ci->
port[gchan];
848 #ifdef CONFIG_SBE_PMCC4_NCOMM
860 ci->
state = C_RUNNING;
869 pr_warning(
"Maximum allowed MRU exceeded, resetting %d to %d.\n",
875 pr_warning(
"Maximum allowed MTU exceeded, resetting %d to %d.\n",
879 #ifdef SBE_WAN256T3_ENABLE
880 for (i = 0; i < MUSYCC_NPORTS; i++)
895 #ifndef SBE_ISR_INLINE
902 ch = pi->
chan[gchan];
903 if (ch == 0 || ch->
state !=
UP)
906 pr_info(
"%s: intr: xmit EOM on uninitialized channel %d\n",
907 pi->
up->devname, gchan);
909 if (ch == 0 || ch->
mdt == 0)
914 #ifdef SBE_ISR_INLINE
932 int readCount, loopCount;
944 while (status & MUSYCC_TX_OWNED)
946 for (loopCount = 0; loopCount < 0x30; loopCount++)
951 if (readCount++ > 40)
954 if (status & MUSYCC_TX_OWNED)
958 pr_info(
"%s: Port %d Chan %2d - unexpected TX msg ownership intr (md %p sts %x)\n",
961 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",
971 pr_info(
"%s: Port %d Chan %2d - recovered TX msg ownership [%d] (md %p sts %x)\n",
984 #ifdef SBE_WAN256T3_ENABLE
986 wan256t3_led (pi->
up, LED_TX, 0);
989 #ifdef CONFIG_SBE_WAN256T3_NCOMM
992 int hdlcnum = (pi->
portnum * 32 + gchan);
996 if (nciProcess_TX_complete)
997 (*nciProcess_TX_complete) (hdlcnum,
1007 #ifdef RLD_TXFULL_DEBUG
1009 pr_info(
"~~ tx_eom: tx_full %x txd_free %d -> %d\n",
1018 pr_info(
"%s: Mode (%x) incorrect EOB status (%x)\n",
1019 pi->
up->devname, ch->
p.chan_mode, status);
1047 #ifdef RLD_TXFULL_DEBUG
1049 pr_info(
"tx_eom[%d]: enable xmit tx_full no more, txd_free %d txd_num/2 %d\n",
1059 #ifdef RLD_TXFULL_DEBUG
1063 pr_info(
"tx_eom[%d]: bypass TX enable though room available? (txd_free %d txd_num/2 %d)\n",
1071 #ifdef SBE_ISR_INLINE
1074 spin_unlock_irqrestore (&ch->
ch_txlock, flags);
1089 ch = pi->
chan[gchan];
1090 if (ch == 0 || ch->
state !=
UP)
1093 pr_info(
"%s: intr: receive EOM on uninitialized channel %d\n",
1094 pi->
up->devname, gchan);
1108 error = (status >> 16) & 0xf;
1111 #ifdef CONFIG_SBE_WAN256T3_NCOMM
1112 int hdlcnum = (pi->
portnum * 32 + gchan);
1120 if (nciProcess_RX_packet)
1121 (*nciProcess_RX_packet) (hdlcnum, status & 0x3fff,
m, ch->
user);
1143 ch->
s.rx_crc_errors++;
1146 ch->
s.rx_missed_errors++;
1149 ch->
s.rx_missed_errors++;
1152 ch->
s.rx_length_errors++;
1155 ch->
s.rx_length_errors++;
1191 if (ci->
state == C_IDLE)
1205 ci->
intlog.drvr_intr_thcount++;
1225 pr_info(
"%s: note - updated ISD from %08x to %08x\n",
1279 pr_info(
">> %s: intCnt NULL, sts %x, possibly a chained interrupt!\n",
1288 ci->
intlog.last_status_new = ci->
intlog.this_status_new;
1289 ci->
intlog.this_status_new = currInt;
1293 pr_info(
"%s: Interrupt queue full condition occurred\n", ci->
devname);
1296 pr_info(
"%s: interrupts pending, isd @ 0x%p: %x curr %d cnt %d NEXT %d\n",
1298 status, nextInt, intCnt, (intCnt + nextInt) & (
INT_QUEUE_SIZE - 1));
1301 #if defined(SBE_ISR_TASKLET)
1305 #elif defined(SBE_ISR_IMMEDIATE)
1308 queue_task (&ci->ci_musycc_isr_tq, &tq_immediate);
1309 mark_bh (IMMEDIATE_BH);
1310 #elif defined(SBE_ISR_INLINE)
1318 #if defined(SBE_ISR_IMMEDIATE)
1327 unsigned int intCnt;
1329 volatile unsigned int headx, tailx;
1330 int readCount, loopCount;
1341 #if defined(SBE_ISR_IMMEDIATE)
1347 #if defined(SBE_ISR_TASKLET) || defined(SBE_ISR_IMMEDIATE)
1350 #if defined(SBE_ISR_TASKLET)
1352 #elif defined(SBE_ISR_IMMEDIATE)
1356 #elif defined(SBE_ISR_INLINE)
1360 ci->
intlog.drvr_intr_bhcount++;
1370 intCnt = (tailx >= headx) ? (tailx - headx) : (tailx - headx +
INT_QUEUE_SIZE);
1385 if ((currInt == badInt) || (currInt == badInt2))
1386 ci->
intlog.drvr_int_failure++;
1388 while ((currInt == badInt) || (currInt == badInt2))
1390 for (loopCount = 0; loopCount < 0x30; loopCount++)
1395 if (readCount++ > 20)
1399 if ((currInt == badInt) || (currInt == badInt2))
1403 pr_info(
"%s: Illegal Interrupt Detected @ 0x%p, mod %d.)\n",
1416 if (currInt == badInt)
1440 pr_info(
" %08x -> err: %2d,", currInt, err);
1442 pr_info(
"+ interrupt event: %d, grp: %d, chan: %2d, side: %cX\n",
1443 event, group, gchan, tx ?
'T' :
'R');
1447 ch = pi->
chan[gchan];
1484 ch->
s.rx_length_errors++;
1489 pr_info(
"%s: unexpected interrupt event: %d, iqd[%d]: %08x, port: %d\n", ci->
devname,
1490 event, headx, currInt, group);
1526 #ifdef RLD_TRANS_DEBUG
1532 pr_info(
"%s: TX buffer underflow [ONR] on channel %d, mode %x QStopped %x free %d\n",
1535 if (ch->
p.chan_mode == 2)
1538 pr_info(
"++ Failed Last %x Next %x QStopped %x, start_tx %x tx_full %d txd_free %d mode %x\n",
1556 ch->
s.rx_over_errors++;
1561 pr_info(
"%s: RX buffer overflow [ONR] on channel %d, mode %x\n",
1571 ch->
s.tx_fifo_errors++;
1578 pr_info(
"%s: TX buffer underrun [BUFF] on channel %d, mode %x\n",
1582 ch->
s.rx_over_errors++;
1591 pr_info(
"%s: RX buffer overrun [BUFF] on channel %d, mode %x\n",
1614 pr_info(
"%s: Interrupt queue overflow - ILOST asserted\n",
1626 pr_info(
"_bh_: late arrivals, head %d != tail %d, pending %d\n",
1629 #if defined(SBE_ISR_IMMEDIATE)
1637 musycc_new_chan (
ci_t * ci,
int channum,
void *
user)
1651 ch->
p.intr_mask = 0;
1655 ch->
p.pad_fill_count = 2;
1664 #ifdef SBE_PMCC4_ENABLE
1687 pi->
regram->thp[gchan] = 0;
1688 pi->
regram->tmp[gchan] = 0;
1689 pi->
regram->rhp[gchan] = 0;
1690 pi->
regram->rmp[gchan] = 0;
1692 for (i = 0; i < ch->
txd_num; i++)
1694 if (ch->
mdt[i].mem_token != 0)
1695 OS_mem_token_free (ch->
mdt[i].mem_token);
1698 for (i = 0; i < ch->
rxd_num; i++)
1700 if (ch->
mdr[i].mem_token != 0)
1701 OS_mem_token_free (ch->
mdr[i].mem_token);
1725 if ((channum < 0) || (channum >= (MUSYCC_NPORTS * MUSYCC_NCHANS)))
1741 if (channum < 0 || channum >= (MUSYCC_NPORTS * MUSYCC_NCHANS))
1758 unsigned long flags;
1766 if (ci->
state != C_RUNNING)
1774 #ifdef RLD_TRANS_DEBUGx
1780 pr_info(
"++ start_xmt[%d]: state %x start %x full %d free %d required %d stopped %x\n",
1789 for (len = OS_mem_token_tlen (m2); len > 0;
1790 m2 = (
void *) OS_mem_token_next (m2))
1792 if (!OS_mem_token_len (m2))
1795 len -= OS_mem_token_len (m2);
1798 if (txd_need_cnt == 0)
1801 pr_info(
"%s channel %d: no TX data in User buffer\n", ci->
devname, channum);
1802 OS_mem_token_free (mem_token);
1808 if (txd_need_cnt > ch->
txd_num)
1813 pr_info(
"start_xmit: discarding buffer, insufficient descriptor cnt %d, need %d.\n",
1814 ch->
txd_num, txd_need_cnt + 1);
1817 OS_mem_token_free (mem_token);
1830 pr_info(
"start_xmit[%d]: EBUSY - need more descriptors, have %d of %d need %d\n",
1837 spin_unlock_irqrestore (&ch->
ch_txlock, flags);
1847 for (len = OS_mem_token_tlen (m2); len > 0; m2 = OS_mem_token_next (m2))
1849 int u = OS_mem_token_len (m2);
1878 if (ch->
p.pad_fill_count)
1912 len = OS_mem_token_tlen (mem_token);
1916 ch->
s.tx_bytes += len;
1925 #ifdef SBE_WAN256T3_ENABLE
1926 wan256t3_led (ci, LED_TX, LEDV_G);