22 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
24 #include <linux/types.h>
26 #include <linux/errno.h>
27 #include <linux/kernel.h>
28 #include <linux/sched.h>
30 #include <linux/hdlc.h>
42 #ifdef SBE_INCLUDE_SYMBOLS
49 #define KERN_WARN KERN_WARNING
74 #if defined (__powerpc__)
75 extern void *
memset (
void *
s,
int c,
size_t n);
94 unsigned int channum = d - (
LOG_DEBUG + 1);
118 for (ci = c4_list; ci; ci = ci->
next)
119 for (portnum = 0; portnum < ci->
max_port; portnum++)
122 if ((ch = ci->
port[portnum].
chan[gchan]))
139 pr_warning(
"c4_new() entered, ci needs %u.\n",
140 (
unsigned int)
sizeof (
ci_t));
143 ci = (
ci_t *) OS_kmalloc (
sizeof (
ci_t));
153 (
unsigned int)
sizeof (
ci_t));
186 #define sbeLinkMask 0x41
188 #define sbeLinkChange 0x40
189 #define sbeLinkDown 0x01
190 #define sbeAlarmsMask 0x07
191 #define sbeE1AlarmsMask 0x107
193 #define COMET_LBCMD_READ 0x80
198 #ifndef CONFIG_SBE_PMCC4_NCOMM
211 for (portnum = 0; portnum < ci->
max_port; portnum++)
213 copyVal = 0x12f & (ci->
alarmed[portnum]);
222 if (value & sbeLinkDown)
223 pr_warning(
"%s: Port %d momentarily recovered.\n",
226 pr_warning(
"%s: Warning: Port %d link was briefly down.\n",
228 }
else if (value & sbeLinkDown)
229 pr_warning(
"%s: Warning: Port %d link is down.\n",
233 pr_warning(
"%s: Port %d link has recovered.\n",
261 pr_warning(
"%s: E1 Port %d Codeword Sa4 change detected.\n",
264 pr_warning(
"%s: E1 Port %d Codeword Sa5 change detected.\n",
267 pr_warning(
"%s: E1 Port %d Codeword Sa6 change detected.\n",
270 pr_warning(
"%s: E1 Port %d Codeword Sa7 change detected.\n",
273 pr_warning(
"%s: E1 Port %d Codeword Sa8 change detected.\n",
280 pr_warning(
"%s: E1 Port %d CRC-4 error(s) detected.\n",
283 pr_warning(
"%s: E1 Port %d received errored SMF.\n",
293 value = (value >> 2);
307 copyVal &= ~sbeRedAlm;
308 pr_warning(
"%s: E1 Port %d LOF alarm ended.\n",
310 }
else if (!(copyVal & sbeRedAlm) && (value & sbeRedAlm))
313 pr_warning(
"%s: E1 Warning: Port %d LOF alarm.\n",
315 }
else if ((copyVal &
sbeYelAlm) && !(value & sbeYelAlm))
317 copyVal &= ~sbeYelAlm;
318 pr_warning(
"%s: E1 Port %d RAI alarm ended.\n",
320 }
else if (!(copyVal & sbeYelAlm) && (value & sbeYelAlm))
323 pr_warning(
"%s: E1 Warning: Port %d RAI alarm.\n",
325 }
else if ((copyVal &
sbeE1RMAI) && !(value & sbeE1RMAI))
327 copyVal &= ~sbeE1RMAI;
328 pr_warning(
"%s: E1 Port %d RMAI alarm ended.\n",
330 }
else if (!(copyVal & sbeE1RMAI) && (value & sbeE1RMAI))
333 pr_warning(
"%s: E1 Warning: Port %d RMAI alarm.\n",
335 }
else if ((copyVal &
sbeAISAlm) && !(value & sbeAISAlm))
337 copyVal &= ~sbeAISAlm;
338 pr_warning(
"%s: E1 Port %d AIS alarm ended.\n",
340 }
else if (!(copyVal & sbeAISAlm) && (value & sbeAISAlm))
343 pr_warning(
"%s: E1 Warning: Port %d AIS alarm.\n",
355 if ((copyVal &
sbeRedAlm) && !(value & sbeRedAlm))
357 copyVal &= ~sbeRedAlm;
360 }
else if (!(copyVal & sbeRedAlm) && (value & sbeRedAlm))
363 pr_warning(
"%s: Warning: Port %d red alarm.\n",
365 }
else if ((copyVal &
sbeYelAlm) && !(value & sbeYelAlm))
367 copyVal &= ~sbeYelAlm;
368 pr_warning(
"%s: Port %d yellow (RAI) alarm ended.\n",
370 }
else if (!(copyVal & sbeYelAlm) && (value & sbeYelAlm))
373 pr_warning(
"%s: Warning: Port %d yellow (RAI) alarm.\n",
375 }
else if ((copyVal &
sbeAISAlm) && !(value & sbeAISAlm))
377 copyVal &= ~sbeAISAlm;
378 pr_warning(
"%s: Port %d blue (AIS) alarm ended.\n",
380 }
else if (!(copyVal & sbeAISAlm) && (value & sbeAISAlm))
383 pr_warning(
"%s: Warning: Port %d blue (AIS) alarm.\n",
393 LEDval |= ((copyVal & 0xc0) >> (6 - (portnum * 2)));
395 ci->
alarmed[portnum] &= 0xfffff000;
397 ci->
alarmed[portnum] |= (copyVal);
443 if ((value == 0x1c) || (value == 0x19) || (value == 0x12))
488 for (portnum = 0; portnum < ci->
max_port; portnum++)
490 pi = &ci->
port[portnum];
495 OS_kfree (pi->
chan[j]);
524 for (portnum = 0; portnum < MUSYCC_NPORTS; portnum++)
530 mask |= 1 << portnum;
548 ci->
intlog.this_status_new = 0;
556 #ifdef CONFIG_SBE_PMCC4_NCOMM
568 for (portnum = 0; portnum < MUSYCC_NPORTS; portnum++)
570 pi = &ci->
port[portnum];
574 pi->
p.portnum = portnum;
599 pr_warning(
"%s: illegal port configuration (%x)\n",
604 pr_info(
">> %s: c4_get_build - pmsk %x max_port %x\n",
609 for (portnum = 0; portnum < ci->
max_port; portnum++)
611 pi = &ci->
port[portnum];
620 for (j = 0; j < 32; j++)
629 ch = OS_kmalloc (
sizeof (
mch_t));
638 ch->
p.port = portnum;
639 ch->
p.channum = (-1);
643 pr_warning(
"failed mch_t malloc, port %d channel %d size %u.\n",
644 portnum, j, (
unsigned int)
sizeof (
mch_t));
683 ci->p.h110enable = 1;
691 c4_card_set_params (ci, &ci->p);
693 OS_start_watchdog (&ci->
wd);
712 if (loopValue != cmd)
728 pr_info(
"%s: loopback mode changed to %2x from %2x on Port %d\n",
729 ci->
devname, cmd, loopValue, portnum);
731 if (loopValue != cmd)
734 pr_info(
"%s: write to loop register failed, unknown state for Port %d\n",
740 pr_info(
"%s: loopback already in that mode (%2x)\n",
775 pr_info(
"%s: Port %d already that value! Writing again anyhow.\n",
846 int portnum, ramread = 0;
853 portnum = (mcp->
offset % 0x6000) / 0x800;
856 pi = &ci->
port[portnum];
857 if (mcp->
offset >= 0x6000)
866 if (offset >= 0x200 && offset < 0x380)
868 if (offset >= 0x10 && offset < 0x200)
886 if (mcp->
value == data)
887 pr_info(
"%s: musycc grp%d already that value! writing again anyhow.\n",
932 pr_info(
"%s: c4_set_port[%d]: entered, e1mode = %x, openchans %d.\n",
983 for (i = 0; i < 32; i++)
991 if (((i == 0) && e1mode) ||
993 || ((i > 23) && (!e1mode)))
1037 ch = pi->
chan[gchan];
1041 if (gchan == MUSYCC_NCHANS)
1051 ch->
p.channum = channum;
1058 ch->
p.pad_fill_count = 2;
1096 ch->
p.channum = (-1);
1123 if (ch->
p.card != p->card ||
1124 ch->
p.port != p->port ||
1129 if (!(ch->
up->group_is_set))
1144 for (i = 0; i < 32; i++)
1145 if (ch->
p.bitmask[i] != p->bitmask[i])
1190 int i,
l = 0,
start = 0,
max = 0, maxstart = 0;
1192 for (i = 0; i < 32; i++)
1212 pr_info(
"%s: wanted to allocate %d fifo space, but got only %d\n",
1213 pi->
up->devname, *len,
max);
1217 pr_info(
"%s: allocated %d fifo at %d for channel %d/%d\n",
1218 pi->
up->devname,
max,
start, chan, pi->
p.portnum);
1219 for (i = maxstart; i < (maxstart +
max); i++)
1230 pr_info(
"%s: deallocated fifo for channel %d/%d\n",
1231 pi->
up->devname, chan, pi->
p.portnum);
1232 for (i = 0; i < 32; i++)
1245 int nts, nbuf, txnum, rxnum;
1255 pr_info(
"%s: channel already UP, graceful early exit\n",
1263 for (i = 0; i < 32; i++)
1265 if (ch->
p.bitmask[i] & pi->
tsm[i])
1269 pr_info(
"%s: c4_chan_up[%d] EINVAL (attempt to cfg in-use or unavailable TimeSlot[%d])\n",
1271 pr_info(
"+ ask4 %x, currently %x\n",
1272 ch->
p.bitmask[i], pi->
tsm[i]);
1276 for (j = 0; j < 8; j++)
1277 if (ch->
p.bitmask[i] & (1 << j))
1281 nbuf = nts / 8 ? nts / 8 : 1;
1285 pr_info(
"%s: c4_chan_up[%d] ENOBUFS (no TimeSlots assigned)\n",
1296 ch->
s.tx_pending = 0;
1309 ccd |= ch->
p.intr_mask;
1354 pr_info(
"%s: mode %x rxnum %d (rxused %d def %d) txnum %d (txused %d def %d)\n",
1364 ch->
mdr = OS_kmalloc (
sizeof (
struct mdesc) * rxnum);
1365 ch->
mdt = OS_kmalloc (
sizeof (
struct mdesc) * txnum);
1371 for (i = 0, md = ch->
mdr; i < rxnum; i++, md++)
1373 if (i == (rxnum - 1))
1385 pr_info(
"%s: c4_chan_up[%d] - token alloc failure, size = %d.\n",
1397 for (i = 0, md = ch->
mdt; i < txnum; i++, md++)
1404 if (i == (txnum - 1))
1431 #ifdef RLD_TRANS_DEBUG
1432 pr_info(
"++ c4_chan_up() CHAN RX ACTIVATE: chan %d\n", ch->
channum);
1439 #ifdef RLD_TRANS_DEBUG
1440 pr_info(
"++ c4_chan_up() CHAN TX ACTIVATE: chan %d <delayed>\n", ch->
channum);
1455 OS_mem_token_free (ch->
mdr[i].mem_token);
1472 OS_stop_watchdog (&ci->
wd);
1500 np = (
char *) dev->
name;
1511 np = (
char *) dev->
name;
1519 for (i = 0; i < 3; i++)
1526 sn = (sn << 8) | *bsn++;
1530 for (i = 0; i < 6; i++)
1552 #ifdef CONFIG_SBE_PMCC4_NCOMM
1554 extern void wanpmcC4T1E1_hookInterrupt (
int cardID,
int deviceID,
void *handler);
1557 wanpmcC4T1E1_hookInterrupt (
int cardID,
int deviceID,
void *handler)
1560 nciInterrupt[cardID][deviceID] = handler;
1564 c4_ebus_intr_th_handler (
void *devp)
1577 if (nciInterrupt[brdno][0] !=
NULL)
1578 (*nciInterrupt[brdno][0]) ();
1583 if (nciInterrupt[brdno][1] !=
NULL)
1584 (*nciInterrupt[brdno][1]) ();
1589 if (nciInterrupt[brdno][2] !=
NULL)
1590 (*nciInterrupt[brdno][2]) ();
1595 if (nciInterrupt[brdno][3] !=
NULL)
1596 (*nciInterrupt[brdno][3]) ();
1610 wanpmcC4T1E1_getBaseAddress (
int cardID,
int deviceID)
1613 unsigned long base = 0;
1618 if (ci->
brdno == cardID)
1620 if (deviceID < ci->max_port)