2 * $Id: pmcc4_drv.c,v 3.1 2007/08/15 23:32:17 rickd PMCC4_3_1B $
6 /*-----------------------------------------------------------------------------
9 * Copyright (C) 2007 One Stop Systems, Inc.
10 * Copyright (C) 2002-2006 SBE, Inc.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * For further information, contact via email: support@onestopsystems.com
23 * One Stop Systems, Inc. Escondido, California U.S.A.
24 *-----------------------------------------------------------------------------
26 * RCS revision: $Revision: 3.1 $
27 * Last changed on $Date: 2007/08/15 23:32:17 $
28 * Changed by $Author: rickd $
29 *-----------------------------------------------------------------------------
30 * $Log: pmcc4_drv.c,v $
31 * Revision 3.1 2007/08/15 23:32:17 rickd
32 * Use 'if 0' instead of GNU comment delimeter to avoid line wrap induced compiler errors.
34 * Revision 3.0 2007/08/15 22:19:55 rickd
35 * Correct sizeof() castings and pi->regram to support 64bit compatibility.
37 * Revision 2.10 2006/04/21 00:56:40 rickd
38 * workqueue files now prefixed with <sbecom> prefix.
40 * Revision 2.9 2005/11/01 19:22:49 rickd
41 * Add sanity checks against max_port for ioctl functions.
43 * Revision 2.8 2005/10/27 18:59:25 rickd
44 * Code cleanup. Default channel config to HDLC_FCS16.
46 * Revision 2.7 2005/10/18 18:16:30 rickd
47 * Further NCOMM code repairs - (1) interrupt matrix usage inconsistant
48 * for indexing into nciInterrupt[][], code missing double parameters.
49 * (2) check input of ncomm interrupt registration cardID for correct
52 * Revision 2.6 2005/10/17 23:55:28 rickd
53 * Initial port of NCOMM support patches from original work found
54 * in pmc_c4t1e1 as updated by NCOMM. Ref: CONFIG_SBE_PMCC4_NCOMM.
55 * Corrected NCOMMs wanpmcC4T1E1_getBaseAddress() to correctly handle
58 * Revision 2.5 2005/10/13 23:01:28 rickd
59 * Correct panic for illegal address reference w/in get_brdinfo on
60 * first_if/last_if name acquistion under Linux 2.6
62 * Revision 2.4 2005/10/13 21:20:19 rickd
63 * Correction of c4_cleanup() wherein next should be acquired before
64 * ci_t structure is free'd.
66 * Revision 2.3 2005/10/13 19:20:10 rickd
67 * Correct driver removal cleanup code for multiple boards.
69 * Revision 2.2 2005/10/11 18:34:04 rickd
70 * New routine added to determine number of ports (comets) on board.
72 * Revision 2.1 2005/10/05 00:48:13 rickd
73 * Add some RX activation trace code.
75 * Revision 2.0 2005/09/28 00:10:06 rickd
76 * Implement 2.6 workqueue for TX/RX restart. Correction to
77 * hardware register boundary checks allows expanded access of MUSYCC.
78 * Implement new musycc reg&bits namings.
80 *-----------------------------------------------------------------------------
83 char OSSIid_pmcc4_drvc
[] =
84 "@(#)pmcc4_drv.c - $Revision: 3.1 $ (c) Copyright 2002-2007 One Stop Systems, Inc.";
86 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
88 #if defined (__FreeBSD__) || defined (__NetBSD__)
89 #include <sys/param.h>
90 #include <sys/systm.h>
91 #include <sys/errno.h>
93 #include <linux/types.h>
94 #include "pmcc4_sysdep.h"
95 #include <linux/errno.h>
96 #include <linux/kernel.h>
97 #include <linux/sched.h> /* include for timer */
98 #include <linux/timer.h> /* include for timer */
99 #include <linux/hdlc.h>
103 #include "sbecom_inline_linux.h"
105 #include "pmcc4_private.h"
107 #include "pmcc4_ioctls.h"
112 #ifdef SBE_INCLUDE_SYMBOLS
115 #define STATIC static
119 #define KERN_WARN KERN_WARNING
121 /* forward references */
122 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,41)
123 status_t
c4_wk_chan_init (mpi_t
*, mch_t
*);
124 void c4_wq_port_cleanup (mpi_t
*);
125 status_t
c4_wq_port_init (mpi_t
*);
128 int c4_loop_port (ci_t
*, int, u_int8_t
);
129 status_t
c4_set_port (ci_t
*, int);
130 status_t
musycc_chan_down (ci_t
*, int);
132 u_int32_t
musycc_chan_proto (int);
133 status_t
musycc_dump_ring (ci_t
*, unsigned int);
134 status_t __init
musycc_init (ci_t
*);
135 void musycc_init_mdt (mpi_t
*);
136 void musycc_serv_req (mpi_t
*, u_int32_t
);
137 void musycc_update_timeslots (mpi_t
*);
139 extern void musycc_update_tx_thp (mch_t
*);
140 extern int log_level
;
143 extern int max_rxdesc_used
, max_rxdesc_default
;
144 extern int max_txdesc_used
, max_txdesc_default
;
146 #if defined (__powerpc__)
147 extern void *memset (void *s
, int c
, size_t n
);
151 int drvr_state
= SBE_DRVR_INIT
;
153 ci_t
*CI
; /* dummy pointer to board ZEROE's data -
158 sbecom_set_loglevel (int d
)
161 * The code within the following -if- clause is a backdoor debug facility
162 * which can be used to display the state of a board's channel.
166 unsigned int channum
= d
- (LOG_DEBUG
+ 1); /* convert to ZERO
169 (void) musycc_dump_ring ((ci_t
*) CI
, channum
); /* CI implies support
175 pr_info("log level changed from %d to %d\n", log_level
, d
);
176 log_level
= d
; /* set new */
178 pr_info("log level is %d\n", log_level
);
184 c4_find_chan (int channum
)
190 for (ci
= c4_list
; ci
; ci
= ci
->next
)
191 for (portnum
= 0; portnum
< ci
->max_port
; portnum
++)
192 for (gchan
= 0; gchan
< MUSYCC_NCHANS
; gchan
++)
194 if ((ch
= ci
->port
[portnum
].chan
[gchan
]))
196 if ((ch
->state
!= UNASSIGNED
) &&
197 (ch
->channum
== channum
))
211 pr_warning("c4_new() entered, ci needs %u.\n",
212 (unsigned int) sizeof (ci_t
));
215 ci
= (ci_t
*) OS_kmalloc (sizeof (ci_t
));
219 ci
->state
= C_INIT
; /* mark as hardware not available */
222 ci
->brdno
= ci
->next
? ci
->next
->brdno
+ 1 : 0;
224 pr_warning("failed CI malloc, size %u.\n",
225 (unsigned int) sizeof (ci_t
));
228 CI
= ci
; /* DEBUG, only board 0 usage */
234 * Check port state and set LED states using watchdog or ioctl...
235 * also check for in-band SF loopback commands (& cause results if they are there)
237 * Alarm function depends on comet bits indicating change in
238 * link status (linkMask) to keep the link status indication straight.
240 * Indications are only LED and system log -- except when ioctl is invoked.
242 * "alarmed" record (a.k.a. copyVal, in some cases below) decodes as:
244 * RMAI (E1 only) 0x100
247 * link returned 0x20 (link was down, now it's back and 'port get' hasn't run)
248 * change in LED 0x10 (update LED register because value has changed)
254 * note "link has returned" indication is reset on read
255 * (e.g. by use of the c4_control port get command)
258 #define sbeLinkMask 0x41 /* change in signal status (lost/recovered) +
260 #define sbeLinkChange 0x40
261 #define sbeLinkDown 0x01
262 #define sbeAlarmsMask 0x07 /* red / yellow / blue alarm conditions */
263 #define sbeE1AlarmsMask 0x107 /* alarm conditions */
265 #define COMET_LBCMD_READ 0x80 /* read only (do not set, return read value) */
268 checkPorts (ci_t
* ci
)
270 #ifndef CONFIG_SBE_PMCC4_NCOMM
272 * PORT POINT - NCOMM needs to avoid this code since the polling of
273 * alarms conflicts with NCOMM's interrupt servicing implementation.
277 volatile u_int32_t value
;
278 u_int32_t copyVal
, LEDval
;
283 for (portnum
= 0; portnum
< ci
->max_port
; portnum
++)
285 copyVal
= 0x12f & (ci
->alarmed
[portnum
]); /* port's alarm record */
286 comet
= ci
->port
[portnum
].cometbase
;
287 value
= pci_read_32 ((u_int32_t
*) &comet
->cdrc_ists
) & sbeLinkMask
; /* link loss reg */
289 if (value
& sbeLinkChange
) /* is there a change in the link stuff */
291 /* if there's been a change (above) and yet it's the same (below) */
292 if (!(((copyVal
>> 3) & sbeLinkDown
) ^ (value
& sbeLinkDown
)))
294 if (value
& sbeLinkDown
)
295 pr_warning("%s: Port %d momentarily recovered.\n",
296 ci
->devname
, portnum
);
298 pr_warning("%s: Warning: Port %d link was briefly down.\n",
299 ci
->devname
, portnum
);
300 } else if (value
& sbeLinkDown
)
301 pr_warning("%s: Warning: Port %d link is down.\n",
302 ci
->devname
, portnum
);
305 pr_warning("%s: Port %d link has recovered.\n",
306 ci
->devname
, portnum
);
307 copyVal
|= 0x20; /* record link transition to up */
309 copyVal
|= 0x10; /* change (link) --> update LEDs */
311 copyVal
&= 0x137; /* clear LED & link old history bits &
313 if (value
& sbeLinkDown
)
314 copyVal
|= 0x08; /* record link status (now) */
316 { /* if link is up, do this */
317 copyVal
|= 0x40; /* LED indicate link is up */
318 /* Alarm things & the like ... first if E1, then if T1 */
319 if (IS_FRAME_ANY_E1 (ci
->port
[portnum
].p
.port_mode
))
322 * first check Codeword (SaX) changes & CRC and
323 * sub-multi-frame errors
326 * note these errors are printed every time they are detected
329 value
= pci_read_32 ((u_int32_t
*) &comet
->e1_frmr_nat_ists
); /* codeword */
331 { /* if errors (crc or smf only) */
333 pr_warning("%s: E1 Port %d Codeword Sa4 change detected.\n",
334 ci
->devname
, portnum
);
336 pr_warning("%s: E1 Port %d Codeword Sa5 change detected.\n",
337 ci
->devname
, portnum
);
339 pr_warning("%s: E1 Port %d Codeword Sa6 change detected.\n",
340 ci
->devname
, portnum
);
342 pr_warning("%s: E1 Port %d Codeword Sa7 change detected.\n",
343 ci
->devname
, portnum
);
345 pr_warning("%s: E1 Port %d Codeword Sa8 change detected.\n",
346 ci
->devname
, portnum
);
348 value
= pci_read_32 ((u_int32_t
*) &comet
->e1_frmr_mists
); /* crc & smf */
350 { /* if errors (crc or smf only) */
351 if (value
& sbeE1CRC
)
352 pr_warning("%s: E1 Port %d CRC-4 error(s) detected.\n",
353 ci
->devname
, portnum
);
354 if (value
& sbeE1errSMF
) /* error in sub-multiframe */
355 pr_warning("%s: E1 Port %d received errored SMF.\n",
356 ci
->devname
, portnum
);
358 value
= pci_read_32 ((u_int32_t
*) &comet
->e1_frmr_masts
) & 0xcc; /* alarms */
360 * pack alarms together (bitmiser), and construct similar to
363 /* RAI,RMAI,.,.,LOF,AIS,.,. ==> RMAI,.,.,.,.,.,RAI,LOF,AIS */
365 value
= (value
>> 2);
369 value
|= 0x40; /* RAI */
371 value
|= 0x100; /* RMAI */
373 } /* finished packing alarm in handy order */
374 if (value
!= (copyVal
& sbeE1AlarmsMask
))
375 { /* if alarms changed */
376 copyVal
|= 0x10;/* change LED status */
377 if ((copyVal
& sbeRedAlm
) && !(value
& sbeRedAlm
))
379 copyVal
&= ~sbeRedAlm
;
380 pr_warning("%s: E1 Port %d LOF alarm ended.\n",
381 ci
->devname
, portnum
);
382 } else if (!(copyVal
& sbeRedAlm
) && (value
& sbeRedAlm
))
384 copyVal
|= sbeRedAlm
;
385 pr_warning("%s: E1 Warning: Port %d LOF alarm.\n",
386 ci
->devname
, portnum
);
387 } else if ((copyVal
& sbeYelAlm
) && !(value
& sbeYelAlm
))
389 copyVal
&= ~sbeYelAlm
;
390 pr_warning("%s: E1 Port %d RAI alarm ended.\n",
391 ci
->devname
, portnum
);
392 } else if (!(copyVal
& sbeYelAlm
) && (value
& sbeYelAlm
))
394 copyVal
|= sbeYelAlm
;
395 pr_warning("%s: E1 Warning: Port %d RAI alarm.\n",
396 ci
->devname
, portnum
);
397 } else if ((copyVal
& sbeE1RMAI
) && !(value
& sbeE1RMAI
))
399 copyVal
&= ~sbeE1RMAI
;
400 pr_warning("%s: E1 Port %d RMAI alarm ended.\n",
401 ci
->devname
, portnum
);
402 } else if (!(copyVal
& sbeE1RMAI
) && (value
& sbeE1RMAI
))
404 copyVal
|= sbeE1RMAI
;
405 pr_warning("%s: E1 Warning: Port %d RMAI alarm.\n",
406 ci
->devname
, portnum
);
407 } else if ((copyVal
& sbeAISAlm
) && !(value
& sbeAISAlm
))
409 copyVal
&= ~sbeAISAlm
;
410 pr_warning("%s: E1 Port %d AIS alarm ended.\n",
411 ci
->devname
, portnum
);
412 } else if (!(copyVal
& sbeAISAlm
) && (value
& sbeAISAlm
))
414 copyVal
|= sbeAISAlm
;
415 pr_warning("%s: E1 Warning: Port %d AIS alarm.\n",
416 ci
->devname
, portnum
);
419 /* end of E1 alarm code */
422 value
= pci_read_32 ((u_int32_t
*) &comet
->t1_almi_ists
); /* alarms */
423 value
&= sbeAlarmsMask
;
424 if (value
!= (copyVal
& sbeAlarmsMask
))
425 { /* if alarms changed */
426 copyVal
|= 0x10;/* change LED status */
427 if ((copyVal
& sbeRedAlm
) && !(value
& sbeRedAlm
))
429 copyVal
&= ~sbeRedAlm
;
430 pr_warning("%s: Port %d red alarm ended.\n",
431 ci
->devname
, portnum
);
432 } else if (!(copyVal
& sbeRedAlm
) && (value
& sbeRedAlm
))
434 copyVal
|= sbeRedAlm
;
435 pr_warning("%s: Warning: Port %d red alarm.\n",
436 ci
->devname
, portnum
);
437 } else if ((copyVal
& sbeYelAlm
) && !(value
& sbeYelAlm
))
439 copyVal
&= ~sbeYelAlm
;
440 pr_warning("%s: Port %d yellow (RAI) alarm ended.\n",
441 ci
->devname
, portnum
);
442 } else if (!(copyVal
& sbeYelAlm
) && (value
& sbeYelAlm
))
444 copyVal
|= sbeYelAlm
;
445 pr_warning("%s: Warning: Port %d yellow (RAI) alarm.\n",
446 ci
->devname
, portnum
);
447 } else if ((copyVal
& sbeAISAlm
) && !(value
& sbeAISAlm
))
449 copyVal
&= ~sbeAISAlm
;
450 pr_warning("%s: Port %d blue (AIS) alarm ended.\n",
451 ci
->devname
, portnum
);
452 } else if (!(copyVal
& sbeAISAlm
) && (value
& sbeAISAlm
))
454 copyVal
|= sbeAISAlm
;
455 pr_warning("%s: Warning: Port %d blue (AIS) alarm.\n",
456 ci
->devname
, portnum
);
459 } /* end T1 mode alarm checks */
461 if (copyVal
& sbeAlarmsMask
)
462 copyVal
|= 0x80; /* if alarm turn yel LED on */
464 LEDval
|= 0x100; /* tag if LED values have changed */
465 LEDval
|= ((copyVal
& 0xc0) >> (6 - (portnum
* 2)));
467 ci
->alarmed
[portnum
] &= 0xfffff000; /* out with the old (it's fff
469 ci
->alarmed
[portnum
] |= (copyVal
); /* in with the new */
472 * enough with the alarms and LED's, now let's check for loopback
476 if (IS_FRAME_ANY_T1 (ci
->port
[portnum
].p
.port_mode
))
479 * begin in-band (SF) loopback code detection -- start by reading
482 value
= pci_read_32 ((u_int32_t
*) &comet
->ibcd_ies
); /* detect reg. */
483 value
&= 0x3; /* trim to handy bits */
485 { /* activate loopback (sets for deactivate
487 copyVal
= c4_loop_port (ci
, portnum
, COMET_LBCMD_READ
); /* read line loopback
489 if (copyVal
!= COMET_MDIAG_LINELB
) /* don't do it again if
490 * already in that mode */
491 c4_loop_port (ci
, portnum
, COMET_MDIAG_LINELB
); /* put port in line
495 { /* deactivate loopback (sets for activate
497 copyVal
= c4_loop_port (ci
, portnum
, COMET_LBCMD_READ
); /* read line loopback
499 if (copyVal
!= COMET_MDIAG_LBOFF
) /* don't do it again if
500 * already in that mode */
501 c4_loop_port (ci
, portnum
, COMET_MDIAG_LBOFF
); /* take port out of any
505 if (IS_FRAME_ANY_T1ESF (ci
->port
[portnum
].p
.port_mode
))
506 { /* if a T1 ESF mode */
507 /* begin ESF loopback code */
508 value
= pci_read_32 ((u_int32_t
*) &comet
->t1_rboc_sts
) & 0x3f; /* read command */
510 c4_loop_port (ci
, portnum
, COMET_MDIAG_LINELB
); /* put port in line
513 c4_loop_port (ci
, portnum
, COMET_MDIAG_PAYLB
); /* put port in payload
515 if ((value
== 0x1c) || (value
== 0x19) || (value
== 0x12))
516 c4_loop_port (ci
, portnum
, COMET_MDIAG_LBOFF
); /* take port out of any
518 if (log_level
>= LOG_DEBUG
)
520 pr_warning("%s: BOC value = %x on Port %d\n",
521 ci
->devname
, value
, portnum
);
522 /* end ESF loopback code */
526 /* if something is new, update LED's */
528 pci_write_32 ((u_int32_t
*) &ci
->cpldbase
->leds
, LEDval
& 0xff);
529 #endif /*** CONFIG_SBE_PMCC4_NCOMM ***/
534 c4_watchdog (ci_t
* ci
)
537 //unsigned long flags;
540 if (drvr_state
!= SBE_DRVR_AVAILABLE
)
542 if (log_level
>= LOG_MONITOR
)
543 pr_info("drvr not available (%x)\n", drvr_state
);
547 SD_SEM_TAKE (&ci
->sem_wdbusy
, "_wd_"); /* only 1 thru here, per
553 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,5,41)
555 { /* is there a state change to search for */
558 ci
->wd_notify
= 0; /* reset notification */
559 for (gchan
= 0; gchan
< MUSYCC_NCHANS
; gchan
++)
561 for (port
= 0; port
< ci
->max_port
; port
++)
563 mch_t
*ch
= ci
->port
[port
].chan
[gchan
];
565 if (!ch
|| ci
->state
!= C_RUNNING
) /* state changed while
566 * acquiring semaphore */
568 if (ch
->state
== UP
)/* channel must be set up */
571 #ifdef RLD_TRANS_DEBUG
572 if (1 || log_level
>= LOG_MONITOR
)
574 if (log_level
>= LOG_MONITOR
)
576 pr_info("%s: watchdog reviving Port %d Channel %d [%d] sts %x/%x, start_TX %x free %x start_RX %x\n",
577 ci
->devname
, ch
->channum
, port
, gchan
, ch
->channum
,
578 ch
->p
.status
, ch
->status
,
579 ch
->ch_start_tx
, ch
->txd_free
, ch
->ch_start_rx
);
582 /**********************************/
583 /** check for RX restart request **/
584 /**********************************/
586 if (ch
->ch_start_rx
&&
587 (ch
->status
& RX_ENABLED
)) /* requires start on
590 ch
->ch_start_rx
= 0; /* we are restarting RX... */
591 #ifdef RLD_TRANS_DEBUG
592 pr_info("++ c4_watchdog() CHAN RX ACTIVATE: chan %d\n",
595 #ifdef RLD_RXACT_DEBUG
598 static int hereb4
= 7;
603 md
= &ch
->mdr
[ch
->rxix_irq_srv
];
604 pr_info("++ c4_watchdog[%d] CHAN RX ACTIVATE: rxix_irq_srv %d, md %p sts %x, rxpkt %lu\n",
605 ch
->channum
, ch
->rxix_irq_srv
, md
, le32_to_cpu (md
->status
), ch
->s
.rx_packets
);
606 musycc_dump_rxbuffer_ring (ch
, 1); /* RLD DEBUG */
610 musycc_serv_req (ch
->up
, SR_CHANNEL_ACTIVATE
| SR_RX_DIRECTION
| gchan
);
612 /**********************************/
613 /** check for TX restart request **/
614 /**********************************/
616 if (ch
->ch_start_tx
&&
617 (ch
->status
& TX_ENABLED
)) /* requires start on
623 * find next unprocessed message, then set TX thp to
626 musycc_update_tx_thp (ch
);
629 spin_lock_irqsave (&ch
->ch_txlock
, flags
);
631 md
= ch
->txd_irq_srv
;
634 pr_info("-- c4_watchdog[%d]: WARNING, starting NULL md\n",
636 pr_info("-- chan %d txd_irq_srv %p sts %x usr_add %p sts %x, txpkt %lu\n",
637 ch
->channum
, ch
->txd_irq_srv
, le32_to_cpu ((struct mdesc
*) (ch
->txd_irq_srv
)->status
),
638 ch
->txd_usr_add
, le32_to_cpu ((struct mdesc
*) (ch
->txd_usr_add
)->status
),
641 spin_unlock_irqrestore (&ch
->ch_txlock
, flags
);
643 } else if (md
->data
&& ((le32_to_cpu (md
->status
)) & MUSYCC_TX_OWNED
))
645 #ifdef RLD_TRANS_DEBUG
646 pr_info("++ c4_watchdog[%d] CHAN TX ACTIVATE: start_tx %x\n",
647 ch
->channum
, ch
->ch_start_tx
);
649 ch
->ch_start_tx
= 0; /* we are restarting
652 spin_unlock_irqrestore (&ch
->ch_txlock
, flags
); /* allow interrupts for
655 musycc_serv_req (ch
->up
, SR_CHANNEL_ACTIVATE
| SR_TX_DIRECTION
| gchan
);
656 #ifdef RLD_TRANS_DEBUG
657 if (1 || log_level
>= LOG_MONITOR
)
659 if (log_level
>= LOG_MONITOR
)
661 pr_info("++ SACK[P%d/C%d] ack'd, continuing...\n",
662 ch
->up
->portnum
, ch
->channum
);
673 SD_SEM_GIVE (&ci
->sem_wdbusy
);/* release per-board hold */
688 next
= ci
->next
; /* protect <next> from upcoming <free> */
689 pci_write_32 ((u_int32_t
*) &ci
->cpldbase
->leds
, PMCC4_CPLD_LED_OFF
);
690 for (portnum
= 0; portnum
< ci
->max_port
; portnum
++)
692 pi
= &ci
->port
[portnum
];
693 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,41)
694 c4_wq_port_cleanup (pi
);
696 for (j
= 0; j
< MUSYCC_NCHANS
; j
++)
699 OS_kfree (pi
->chan
[j
]); /* free mch_t struct */
701 OS_kfree (pi
->regram_saved
);
704 /* obsolete - watchdog is now static w/in ci_t */
705 OS_free_watchdog (ci
->wd
);
707 OS_kfree (ci
->iqd_p_saved
);
709 ci
= next
; /* cleanup next board, if any */
715 * This function issues a write to all comet chips and expects the same data
716 * to be returned from the subsequent read. This determines the board build
717 * to be a 1-port, 2-port, or 4-port build. The value returned represents a
718 * bit-mask of the found ports. Only certain configurations are considered
719 * VALID or LEGAL builds.
723 c4_get_portcfg (ci_t
* ci
)
727 u_int32_t wdata
, rdata
;
729 wdata
= COMET_MDIAG_LBOFF
; /* take port out of any loopback mode */
732 for (portnum
= 0; portnum
< MUSYCC_NPORTS
; portnum
++)
734 comet
= ci
->port
[portnum
].cometbase
;
735 pci_write_32 ((u_int32_t
*) &comet
->mdiag
, wdata
);
736 rdata
= pci_read_32 ((u_int32_t
*) &comet
->mdiag
) & COMET_MDIAG_LBMASK
;
738 mask
|= 1 << portnum
;
744 /* nothing herein should generate interrupts */
747 c4_init (ci_t
* ci
, u_char
*func0
, u_char
*func1
)
751 static u_int32_t count
= 0;
756 ci
->intlog
.this_status_new
= 0;
757 atomic_set (&ci
->bh_pending
, 0);
759 ci
->reg
= (struct musycc_globalr
*) func0
;
760 ci
->eeprombase
= (u_int32_t
*) (func1
+ EEPROM_OFFSET
);
761 ci
->cpldbase
= (c4cpld_t
*) ((u_int32_t
*) (func1
+ ISPLD_OFFSET
));
763 /*** PORT POINT - the following is the first access of any type to the hardware ***/
764 #ifdef CONFIG_SBE_PMCC4_NCOMM
765 /* NCOMM driver uses INTB interrupt to monitor CPLD register */
766 pci_write_32 ((u_int32_t
*) &ci
->reg
->glcd
, GCD_MAGIC
);
768 /* standard driver POLLS for INTB via CPLD register */
769 pci_write_32 ((u_int32_t
*) &ci
->reg
->glcd
, GCD_MAGIC
| MUSYCC_GCD_INTB_DISABLE
);
775 /* need comet addresses available for determination of hardware build */
776 for (portnum
= 0; portnum
< MUSYCC_NPORTS
; portnum
++)
778 pi
= &ci
->port
[portnum
];
779 pi
->cometbase
= (comet_t
*) ((u_int32_t
*) (func1
+ COMET_OFFSET (portnum
)));
780 pi
->reg
= (struct musycc_globalr
*) ((u_char
*) ci
->reg
+ (portnum
* 0x800));
781 pi
->portnum
= portnum
;
782 pi
->p
.portnum
= portnum
;
785 pr_info("Comet-%d: addr = %p\n", portnum
, pi
->cometbase
);
788 pmsk
= c4_get_portcfg (ci
);
798 case 0x7: /* not built, but could be... */
807 pr_warning("%s: illegal port configuration (%x)\n",
809 return SBE_DRVR_FAIL
;
812 pr_info(">> %s: c4_get_build - pmsk %x max_port %x\n",
813 ci
->devname
, pmsk
, ci
->max_port
);
817 for (portnum
= 0; portnum
< ci
->max_port
; portnum
++)
819 pi
= &ci
->port
[portnum
];
821 pi
->sr_last
= 0xffffffff;
822 pi
->p
.port_mode
= CFG_FRAME_SF
; /* T1 B8ZS, the default */
823 pi
->p
.portP
= (CFG_CLK_PORT_EXTERNAL
| CFG_LBO_LH0
); /* T1 defaults */
825 OS_sem_init (&pi
->sr_sem_busy
, SEM_AVAILABLE
);
826 OS_sem_init (&pi
->sr_sem_wait
, SEM_TAKEN
);
828 for (j
= 0; j
< 32; j
++)
831 pi
->tsm
[j
] = 0; /* no assignments, all available */
834 /* allocate channel structures for this port */
835 for (j
= 0; j
< MUSYCC_NCHANS
; j
++)
837 ch
= OS_kmalloc (sizeof (mch_t
));
841 ch
->state
= UNASSIGNED
;
843 ch
->gchan
= (-1); /* channel assignment not yet known */
844 ch
->channum
= (-1); /* channel assignment not yet known */
845 ch
->p
.card
= ci
->brdno
;
846 ch
->p
.port
= portnum
;
847 ch
->p
.channum
= (-1); /* channel assignment not yet known */
848 ch
->p
.mode_56k
= 0; /* default is 64kbps mode */
851 pr_warning("failed mch_t malloc, port %d channel %d size %u.\n",
852 portnum
, j
, (unsigned int) sizeof (mch_t
));
861 * Set LEDs through their paces to supply visual proof that LEDs are
862 * functional and not burnt out nor broken.
864 * YELLOW + GREEN -> OFF.
867 pci_write_32 ((u_int32_t
*) &ci
->cpldbase
->leds
,
868 PMCC4_CPLD_LED_GREEN
| PMCC4_CPLD_LED_YELLOW
);
869 OS_uwait (750000, "leds");
870 pci_write_32 ((u_int32_t
*) &ci
->cpldbase
->leds
, PMCC4_CPLD_LED_OFF
);
873 OS_init_watchdog (&ci
->wd
, (void (*) (void *)) c4_watchdog
, ci
, WATCHDOG_TIMEOUT
);
874 return SBE_DRVR_SUCCESS
;
878 /* better be fully setup to handle interrupts when you call this */
885 /* PORT POINT: this routine generates first interrupt */
886 if ((ret
= musycc_init (ci
)) != SBE_DRVR_SUCCESS
)
890 ci
->p
.framing_type
= FRAMING_CBP
;
891 ci
->p
.h110enable
= 1;
897 ci
->p
.clock
= 0; /* Use internal clocking until set to
899 c4_card_set_params (ci
, &ci
->p
);
901 OS_start_watchdog (&ci
->wd
);
902 return SBE_DRVR_SUCCESS
;
906 /* This function sets the loopback mode (or clears it, as the case may be). */
909 c4_loop_port (ci_t
* ci
, int portnum
, u_int8_t cmd
)
912 volatile u_int32_t loopValue
;
914 comet
= ci
->port
[portnum
].cometbase
;
915 loopValue
= pci_read_32 ((u_int32_t
*) &comet
->mdiag
) & COMET_MDIAG_LBMASK
;
917 if (cmd
& COMET_LBCMD_READ
)
918 return loopValue
; /* return the read value */
920 if (loopValue
!= cmd
)
924 case COMET_MDIAG_LINELB
:
925 /* set(SF)loopback down (turn off) code length to 6 bits */
926 pci_write_32 ((u_int32_t
*) &comet
->ibcd_cfg
, 0x05);
928 case COMET_MDIAG_LBOFF
:
929 /* set (SF) loopback up (turn on) code length to 5 bits */
930 pci_write_32 ((u_int32_t
*) &comet
->ibcd_cfg
, 0x00);
934 pci_write_32 ((u_int32_t
*) &comet
->mdiag
, cmd
);
935 if (log_level
>= LOG_WARN
)
936 pr_info("%s: loopback mode changed to %2x from %2x on Port %d\n",
937 ci
->devname
, cmd
, loopValue
, portnum
);
938 loopValue
= pci_read_32 ((u_int32_t
*) &comet
->mdiag
) & COMET_MDIAG_LBMASK
;
939 if (loopValue
!= cmd
)
941 if (log_level
>= LOG_ERROR
)
942 pr_info("%s: write to loop register failed, unknown state for Port %d\n",
943 ci
->devname
, portnum
);
947 if (log_level
>= LOG_WARN
)
948 pr_info("%s: loopback already in that mode (%2x)\n",
949 ci
->devname
, loopValue
);
955 /* c4_frame_rw: read or write the comet register specified
956 * (modifies use of port_param to non-standard use of struct)
958 * pp.portnum (one guess)
959 * pp.port_mode offset of register
960 * pp.portP write (or not, i.e. read)
961 * pp.portStatus write value
963 * pp.portStatus also used to return read value
964 * pp.portP also used during write, to return old reg value
968 c4_frame_rw (ci_t
* ci
, struct sbecom_port_param
* pp
)
971 volatile u_int32_t data
;
973 if (pp
->portnum
>= ci
->max_port
)/* sanity check */
976 comet
= ci
->port
[pp
->portnum
].cometbase
;
977 data
= pci_read_32 ((u_int32_t
*) comet
+ pp
->port_mode
) & 0xff;
980 { /* control says this is a register
982 if (pp
->portStatus
== data
)
983 pr_info("%s: Port %d already that value! Writing again anyhow.\n",
984 ci
->devname
, pp
->portnum
);
985 pp
->portP
= (u_int8_t
) data
;
986 pci_write_32 ((u_int32_t
*) comet
+ pp
->port_mode
,
988 data
= pci_read_32 ((u_int32_t
*) comet
+ pp
->port_mode
) & 0xff;
990 pp
->portStatus
= (u_int8_t
) data
;
995 /* c4_pld_rw: read or write the pld register specified
996 * (modifies use of port_param to non-standard use of struct)
998 * pp.port_mode offset of register
999 * pp.portP write (or not, i.e. read)
1000 * pp.portStatus write value
1002 * pp.portStatus also used to return read value
1003 * pp.portP also used during write, to return old reg value
1007 c4_pld_rw (ci_t
* ci
, struct sbecom_port_param
* pp
)
1009 volatile u_int32_t
*regaddr
;
1010 volatile u_int32_t data
;
1011 int regnum
= pp
->port_mode
;
1013 regaddr
= (u_int32_t
*) ci
->cpldbase
+ regnum
;
1014 data
= pci_read_32 ((u_int32_t
*) regaddr
) & 0xff;
1017 { /* control says this is a register
1019 pp
->portP
= (u_int8_t
) data
;
1020 pci_write_32 ((u_int32_t
*) regaddr
, pp
->portStatus
);
1021 data
= pci_read_32 ((u_int32_t
*) regaddr
) & 0xff;
1023 pp
->portStatus
= (u_int8_t
) data
;
1027 /* c4_musycc_rw: read or write the musycc register specified
1028 * (modifies use of port_param to non-standard use of struct)
1030 * mcp.RWportnum port number and write indication bit (0x80)
1031 * mcp.offset offset of register
1032 * mcp.value write value going in and read value returning
1035 /* PORT POINT: TX Subchannel Map registers are write-only
1036 * areas within the MUSYCC and always return FF */
1037 /* PORT POINT: regram and reg structures are minorly different and <offset> ioctl
1038 * settings are aligned with the <reg> struct musycc_globalr{} usage.
1039 * Also, regram is separately allocated shared memory, allocated for each port.
1040 * PORT POINT: access offsets of 0x6000 for Msg Cfg Desc Tbl are for 4-port MUSYCC
1041 * only. (An 8-port MUSYCC has 0x16000 offsets for accessing its upper 4 tables.)
1045 c4_musycc_rw (ci_t
* ci
, struct c4_musycc_param
* mcp
)
1048 volatile u_int32_t
*dph
; /* hardware implemented register */
1049 u_int32_t
*dpr
= 0; /* RAM image of registers for group command
1051 int offset
= mcp
->offset
% 0x800; /* group relative address
1052 * offset, mcp->portnum is
1054 int portnum
, ramread
= 0;
1055 volatile u_int32_t data
;
1058 * Sanity check hardware accessibility. The 0x6000 portion handles port
1059 * numbers associated with Msg Descr Tbl decoding.
1061 portnum
= (mcp
->offset
% 0x6000) / 0x800;
1062 if (portnum
>= ci
->max_port
)
1064 pi
= &ci
->port
[portnum
];
1065 if (mcp
->offset
>= 0x6000)
1066 offset
+= 0x6000; /* put back in MsgCfgDesc address offset */
1067 dph
= (u_int32_t
*) ((u_long
) pi
->reg
+ offset
);
1069 /* read of TX are from RAM image, since hardware returns FF */
1070 dpr
= (u_int32_t
*) ((u_long
) pi
->regram
+ offset
);
1071 if (mcp
->offset
< 0x6000) /* non MsgDesc Tbl accesses might require
1074 if (offset
>= 0x200 && offset
< 0x380)
1076 if (offset
>= 0x10 && offset
< 0x200)
1079 /* read register from RAM or hardware, depending... */
1083 //pr_info("c4_musycc_rw: RAM addr %p read data %x (portno %x offset %x RAM ramread %x)\n", dpr, data, portnum, offset, ramread); /* RLD DEBUG */
1086 data
= pci_read_32 ((u_int32_t
*) dph
);
1087 //pr_info("c4_musycc_rw: REG addr %p read data %x (portno %x offset %x RAM ramread %x)\n", dph, data, portnum, offset, ramread); /* RLD DEBUG */
1091 if (mcp
->RWportnum
& 0x80)
1092 { /* control says this is a register
1094 if (mcp
->value
== data
)
1095 pr_info("%s: musycc grp%d already that value! writing again anyhow.\n",
1096 ci
->devname
, (mcp
->RWportnum
& 0x7));
1097 /* write register RAM */
1100 /* write hardware register */
1101 pci_write_32 ((u_int32_t
*) dph
, mcp
->value
);
1103 mcp
->value
= data
; /* return the read value (or the 'old
1104 * value', if is write) */
1109 c4_get_port (ci_t
* ci
, int portnum
)
1111 if (portnum
>= ci
->max_port
) /* sanity check */
1114 SD_SEM_TAKE (&ci
->sem_wdbusy
, "_wd_"); /* only 1 thru here, per
1117 ci
->port
[portnum
].p
.portStatus
= (u_int8_t
) ci
->alarmed
[portnum
];
1118 ci
->alarmed
[portnum
] &= 0xdf;
1119 SD_SEM_GIVE (&ci
->sem_wdbusy
); /* release per-board hold */
1124 c4_set_port (ci_t
* ci
, int portnum
)
1127 struct sbecom_port_param
*pp
;
1132 if (portnum
>= ci
->max_port
) /* sanity check */
1135 pi
= &ci
->port
[portnum
];
1136 pp
= &ci
->port
[portnum
].p
;
1137 e1mode
= IS_FRAME_ANY_E1 (pp
->port_mode
);
1138 if (log_level
>= LOG_MONITOR2
)
1140 pr_info("%s: c4_set_port[%d]: entered, e1mode = %x, openchans %d.\n",
1142 portnum
, e1mode
, pi
->openchans
);
1145 return EBUSY
; /* group needs initialization only for
1146 * first channel of a group */
1148 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,41)
1152 if ((ret
= c4_wq_port_init (pi
))) /* create/init
1153 * workqueue_struct */
1158 init_comet (ci
, pi
->cometbase
, pp
->port_mode
, 1 /* clockmaster == true */ , pp
->portP
);
1159 clck
= pci_read_32 ((u_int32_t
*) &ci
->cpldbase
->mclk
) & PMCC4_CPLD_MCLK_MASK
;
1161 clck
|= 1 << portnum
;
1163 clck
&= 0xf ^ (1 << portnum
);
1165 pci_write_32 ((u_int32_t
*) &ci
->cpldbase
->mclk
, clck
);
1166 pci_write_32 ((u_int32_t
*) &ci
->cpldbase
->mcsr
, PMCC4_CPLD_MCSR_IND
);
1167 pci_write_32 ((u_int32_t
*) &pi
->reg
->gbp
, OS_vtophys (pi
->regram
));
1169 /*********************************************************************/
1170 /* ERRATA: If transparent mode is used, do not set OOFMP_DISABLE bit */
1171 /*********************************************************************/
1174 __constant_cpu_to_le32 (MUSYCC_GRCD_RX_ENABLE
|
1175 MUSYCC_GRCD_TX_ENABLE
|
1176 MUSYCC_GRCD_OOFMP_DISABLE
|
1177 MUSYCC_GRCD_SF_ALIGN
| /* per MUSYCC ERRATA,
1179 MUSYCC_GRCD_COFAIRQ_DISABLE
|
1180 MUSYCC_GRCD_MC_ENABLE
|
1181 (MUSYCC_GRCD_POLLTH_32
<< MUSYCC_GRCD_POLLTH_SHIFT
));
1184 __constant_cpu_to_le32 ((e1mode
? 1 : 0) |
1185 MUSYCC_PCD_TXSYNC_RISING
|
1186 MUSYCC_PCD_RXSYNC_RISING
|
1187 MUSYCC_PCD_RXDATA_RISING
);
1189 /* Message length descriptor */
1190 pi
->regram
->mld
= __constant_cpu_to_le32 (max_mru
| (max_mru
<< 16));
1193 for (i
= 0; i
< 32; i
++)
1196 /*** ASSIGNMENT NOTES: ***/
1197 /*** Group's channel ZERO unavailable if E1. ***/
1198 /*** Group's channel 16 unavailable if E1 CAS. ***/
1199 /*** Group's channels 24-31 unavailable if T1. ***/
1201 if (((i
== 0) && e1mode
) ||
1202 ((i
== 16) && ((pp
->port_mode
== CFG_FRAME_E1CRC_CAS
) || (pp
->port_mode
== CFG_FRAME_E1CRC_CAS_AMI
)))
1203 || ((i
> 23) && (!e1mode
)))
1205 pi
->tsm
[i
] = 0xff; /* make tslot unavailable for this mode */
1208 pi
->tsm
[i
] = 0x00; /* make tslot available for assignment */
1211 for (i
= 0; i
< MUSYCC_NCHANS
; i
++)
1213 pi
->regram
->ttsm
[i
] = 0;
1214 pi
->regram
->rtsm
[i
] = 0;
1217 musycc_serv_req (pi
, SR_GROUP_INIT
| SR_RX_DIRECTION
);
1218 musycc_serv_req (pi
, SR_GROUP_INIT
| SR_TX_DIRECTION
);
1220 musycc_init_mdt (pi
);
1222 pi
->group_is_set
= 1;
1228 unsigned int max_int
= 0;
1231 c4_new_chan (ci_t
* ci
, int portnum
, int channum
, void *user
)
1237 if (c4_find_chan (channum
)) /* a new channel shouldn't already exist */
1240 if (portnum
>= ci
->max_port
) /* sanity check */
1243 pi
= &(ci
->port
[portnum
]);
1244 /* find any available channel within this port */
1245 for (gchan
= 0; gchan
< MUSYCC_NCHANS
; gchan
++)
1247 ch
= pi
->chan
[gchan
];
1248 if (ch
&& ch
->state
== UNASSIGNED
) /* no assignment is good! */
1251 if (gchan
== MUSYCC_NCHANS
) /* exhausted table, all were assigned */
1256 /* NOTE: mch_t already cleared during OS_kmalloc() */
1260 ch
->channum
= channum
; /* mark our channel assignment */
1261 ch
->p
.channum
= channum
;
1263 ch
->p
.card
= ci
->brdno
;
1264 ch
->p
.port
= portnum
;
1266 ch
->p
.chan_mode
= CFG_CH_PROTO_HDLC_FCS16
;
1267 ch
->p
.idlecode
= CFG_CH_FLAG_7E
;
1268 ch
->p
.pad_fill_count
= 2;
1269 spin_lock_init (&ch
->ch_rxlock
);
1270 spin_lock_init (&ch
->ch_txlock
);
1272 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,41)
1276 if ((ret
= c4_wk_chan_init (pi
, ch
)))
1281 /* save off interface assignments which bound a board */
1282 if (ci
->first_if
== 0) /* first channel registered is assumed to
1283 * be the lowest channel */
1285 ci
->first_if
= ci
->last_if
= user
;
1286 ci
->first_channum
= ci
->last_channum
= channum
;
1290 if (ci
->last_channum
< channum
) /* higher number channel found */
1291 ci
->last_channum
= channum
;
1297 c4_del_chan (int channum
)
1301 if (!(ch
= c4_find_chan (channum
)))
1303 if (ch
->state
== UP
)
1304 musycc_chan_down ((ci_t
*) 0, channum
);
1305 ch
->state
= UNASSIGNED
;
1308 ch
->p
.channum
= (-1);
1313 c4_del_chan_stats (int channum
)
1317 if (!(ch
= c4_find_chan (channum
)))
1320 memset (&ch
->s
, 0, sizeof (struct sbecom_chan_stats
));
1326 c4_set_chan (int channum
, struct sbecom_chan_param
* p
)
1331 if (!(ch
= c4_find_chan (channum
)))
1335 if (ch
->p
.card
!= p
->card
||
1336 ch
->p
.port
!= p
->port
||
1337 ch
->p
.channum
!= p
->channum
)
1341 if (!(ch
->up
->group_is_set
))
1343 return EIO
; /* out of order, SET_PORT command
1344 * required prior to first group's
1345 * SET_CHAN command */
1348 * Check for change of parameter settings in order to invoke closing of
1349 * channel prior to hardware poking.
1352 if (ch
->p
.status
!= p
->status
|| ch
->p
.chan_mode
!= p
->chan_mode
||
1353 ch
->p
.data_inv
!= p
->data_inv
|| ch
->p
.intr_mask
!= p
->intr_mask
||
1354 ch
->txd_free
< ch
->txd_num
) /* to clear out queued messages */
1355 x
= 1; /* we have a change requested */
1356 for (i
= 0; i
< 32; i
++) /* check for timeslot mapping changes */
1357 if (ch
->p
.bitmask
[i
] != p
->bitmask
[i
])
1358 x
= 1; /* we have a change requested */
1360 if (x
&& (ch
->state
== UP
)) /* if change request and channel is
1365 if ((ret
= musycc_chan_down ((ci_t
*) 0, channum
)))
1367 if ((ret
= c4_chan_up (ch
->up
->up
, channum
)))
1369 sd_enable_xmit (ch
->user
); /* re-enable to catch flow controlled
1377 c4_get_chan (int channum
, struct sbecom_chan_param
* p
)
1381 if (!(ch
= c4_find_chan (channum
)))
1388 c4_get_chan_stats (int channum
, struct sbecom_chan_stats
* p
)
1392 if (!(ch
= c4_find_chan (channum
)))
1395 p
->tx_pending
= atomic_read (&ch
->tx_pending
);
1400 c4_fifo_alloc (mpi_t
* pi
, int chan
, int *len
)
1402 int i
, l
= 0, start
= 0, max
= 0, maxstart
= 0;
1404 for (i
= 0; i
< 32; i
++)
1406 if (pi
->fifomap
[i
] != -1)
1423 if (log_level
>= LOG_WARN
)
1424 pr_info("%s: wanted to allocate %d fifo space, but got only %d\n",
1425 pi
->up
->devname
, *len
, max
);
1428 if (log_level
>= LOG_DEBUG
)
1429 pr_info("%s: allocated %d fifo at %d for channel %d/%d\n",
1430 pi
->up
->devname
, max
, start
, chan
, pi
->p
.portnum
);
1431 for (i
= maxstart
; i
< (maxstart
+ max
); i
++)
1432 pi
->fifomap
[i
] = chan
;
1437 c4_fifo_free (mpi_t
* pi
, int chan
)
1441 if (log_level
>= LOG_DEBUG
)
1442 pr_info("%s: deallocated fifo for channel %d/%d\n",
1443 pi
->up
->devname
, chan
, pi
->p
.portnum
);
1444 for (i
= 0; i
< 32; i
++)
1445 if (pi
->fifomap
[i
] == chan
)
1446 pi
->fifomap
[i
] = -1;
1451 c4_chan_up (ci_t
* ci
, int channum
)
1457 int nts
, nbuf
, txnum
, rxnum
;
1458 int addr
, i
, j
, gchan
;
1459 u_int32_t tmp
; /* for optimizing conversion across BE
1462 if (!(ch
= c4_find_chan (channum
)))
1464 if (ch
->state
== UP
)
1466 if (log_level
>= LOG_MONITOR
)
1467 pr_info("%s: channel already UP, graceful early exit\n",
1473 /* find nts ('number of timeslots') */
1475 for (i
= 0; i
< 32; i
++)
1477 if (ch
->p
.bitmask
[i
] & pi
->tsm
[i
])
1479 if (1 || log_level
>= LOG_WARN
)
1481 pr_info("%s: c4_chan_up[%d] EINVAL (attempt to cfg in-use or unavailable TimeSlot[%d])\n",
1482 ci
->devname
, channum
, i
);
1483 pr_info("+ ask4 %x, currently %x\n",
1484 ch
->p
.bitmask
[i
], pi
->tsm
[i
]);
1488 for (j
= 0; j
< 8; j
++)
1489 if (ch
->p
.bitmask
[i
] & (1 << j
))
1493 nbuf
= nts
/ 8 ? nts
/ 8 : 1;
1496 /* if( log_level >= LOG_WARN) */
1497 pr_info("%s: c4_chan_up[%d] ENOBUFS (no TimeSlots assigned)\n",
1498 ci
->devname
, channum
);
1499 return ENOBUFS
; /* this should not happen */
1501 addr
= c4_fifo_alloc (pi
, gchan
, &nbuf
);
1504 /* Setup the Time Slot Map */
1505 musycc_update_timeslots (pi
);
1507 /* ch->tx_limit = nts; */
1508 ch
->s
.tx_pending
= 0;
1510 /* Set Channel Configuration Descriptors */
1514 ccd
= musycc_chan_proto (ch
->p
.chan_mode
) << MUSYCC_CCD_PROTO_SHIFT
;
1515 if ((ch
->p
.chan_mode
== CFG_CH_PROTO_ISLP_MODE
) ||
1516 (ch
->p
.chan_mode
== CFG_CH_PROTO_TRANS
))
1518 ccd
|= MUSYCC_CCD_FCS_XFER
; /* Non FSC Mode */
1520 ccd
|= 2 << MUSYCC_CCD_MAX_LENGTH
; /* Select second MTU */
1521 ccd
|= ch
->p
.intr_mask
;
1522 ccd
|= addr
<< MUSYCC_CCD_BUFFER_LOC
;
1523 if (ch
->p
.chan_mode
== CFG_CH_PROTO_TRANS
)
1524 ccd
|= (nbuf
) << MUSYCC_CCD_BUFFER_LENGTH
;
1526 ccd
|= (nbuf
- 1) << MUSYCC_CCD_BUFFER_LENGTH
;
1528 if (ch
->p
.data_inv
& CFG_CH_DINV_TX
)
1529 ccd
|= MUSYCC_CCD_INVERT_DATA
; /* Invert data */
1530 pi
->regram
->tcct
[gchan
] = cpu_to_le32 (ccd
);
1532 if (ch
->p
.data_inv
& CFG_CH_DINV_RX
)
1533 ccd
|= MUSYCC_CCD_INVERT_DATA
; /* Invert data */
1535 ccd
&= ~MUSYCC_CCD_INVERT_DATA
; /* take away data inversion */
1536 pi
->regram
->rcct
[gchan
] = cpu_to_le32 (ccd
);
1540 /* Reread the Channel Configuration Descriptor for this channel */
1541 musycc_serv_req (pi
, SR_CHANNEL_CONFIG
| SR_RX_DIRECTION
| gchan
);
1542 musycc_serv_req (pi
, SR_CHANNEL_CONFIG
| SR_TX_DIRECTION
| gchan
);
1545 * Figure out how many buffers we want. If the customer has changed from
1546 * the defaults, then use the changed values. Otherwise, use Transparent
1547 * mode's specific minimum default settings.
1549 if (ch
->p
.chan_mode
== CFG_CH_PROTO_TRANS
)
1551 if (max_rxdesc_used
== max_rxdesc_default
) /* use default setting */
1552 max_rxdesc_used
= MUSYCC_RXDESC_TRANS
;
1553 if (max_txdesc_used
== max_txdesc_default
) /* use default setting */
1554 max_txdesc_used
= MUSYCC_TXDESC_TRANS
;
1557 * Increase counts when hyperchanneling, since this implies an increase
1558 * in throughput per channel
1560 rxnum
= max_rxdesc_used
+ (nts
/ 4);
1561 txnum
= max_txdesc_used
+ (nts
/ 4);
1565 if (log_level
>= LOG_MONITOR
)
1566 pr_info("%s: mode %x rxnum %d (rxused %d def %d) txnum %d (txused %d def %d)\n",
1567 ci
->devname
, ch
->p
.chan_mode
,
1568 rxnum
, max_rxdesc_used
, max_rxdesc_default
,
1569 txnum
, max_txdesc_used
, max_txdesc_default
);
1572 ch
->rxd_num
= rxnum
;
1573 ch
->txd_num
= txnum
;
1574 ch
->rxix_irq_srv
= 0;
1576 ch
->mdr
= OS_kmalloc (sizeof (struct mdesc
) * rxnum
);
1577 ch
->mdt
= OS_kmalloc (sizeof (struct mdesc
) * txnum
);
1578 if (ch
->p
.chan_mode
== CFG_CH_PROTO_TRANS
)
1579 tmp
= __constant_cpu_to_le32 (max_mru
| EOBIRQ_ENABLE
);
1581 tmp
= __constant_cpu_to_le32 (max_mru
);
1583 for (i
= 0, md
= ch
->mdr
; i
< rxnum
; i
++, md
++)
1585 if (i
== (rxnum
- 1))
1587 md
->snext
= &ch
->mdr
[0];/* wrapness */
1590 md
->snext
= &ch
->mdr
[i
+ 1];
1592 md
->next
= cpu_to_le32 (OS_vtophys (md
->snext
));
1594 if (!(m
= OS_mem_token_alloc (max_mru
)))
1596 if (log_level
>= LOG_MONITOR
)
1597 pr_info("%s: c4_chan_up[%d] - token alloc failure, size = %d.\n",
1598 ci
->devname
, channum
, max_mru
);
1602 md
->data
= cpu_to_le32 (OS_vtophys (OS_mem_token_data (m
)));
1603 md
->status
= tmp
| MUSYCC_RX_OWNED
; /* MUSYCC owns RX descriptor **
1605 * MUSYCC_RX_OWNED = 0 so no
1606 * need to byteSwap */
1609 for (i
= 0, md
= ch
->mdt
; i
< txnum
; i
++, md
++)
1611 md
->status
= HOST_TX_OWNED
; /* Host owns TX descriptor ** CODING
1612 * NOTE: HOST_TX_OWNED = 0 so no need to
1616 if (i
== (txnum
- 1))
1618 md
->snext
= &ch
->mdt
[0];/* wrapness */
1621 md
->snext
= &ch
->mdt
[i
+ 1];
1623 md
->next
= cpu_to_le32 (OS_vtophys (md
->snext
));
1625 ch
->txd_irq_srv
= ch
->txd_usr_add
= &ch
->mdt
[0];
1626 ch
->txd_free
= txnum
;
1628 ch
->txd_required
= 0;
1630 /* Configure it into the chip */
1631 tmp
= cpu_to_le32 (OS_vtophys (&ch
->mdt
[0]));
1632 pi
->regram
->thp
[gchan
] = tmp
;
1633 pi
->regram
->tmp
[gchan
] = tmp
;
1635 tmp
= cpu_to_le32 (OS_vtophys (&ch
->mdr
[0]));
1636 pi
->regram
->rhp
[gchan
] = tmp
;
1637 pi
->regram
->rmp
[gchan
] = tmp
;
1639 /* Activate the Channel */
1641 if (ch
->p
.status
& RX_ENABLED
)
1643 #ifdef RLD_TRANS_DEBUG
1644 pr_info("++ c4_chan_up() CHAN RX ACTIVATE: chan %d\n", ch
->channum
);
1646 ch
->ch_start_rx
= 0; /* we are restarting RX... */
1647 musycc_serv_req (pi
, SR_CHANNEL_ACTIVATE
| SR_RX_DIRECTION
| gchan
);
1649 if (ch
->p
.status
& TX_ENABLED
)
1651 #ifdef RLD_TRANS_DEBUG
1652 pr_info("++ c4_chan_up() CHAN TX ACTIVATE: chan %d <delayed>\n", ch
->channum
);
1654 ch
->ch_start_tx
= CH_START_TX_1ST
; /* we are delaying start
1655 * until receipt from user of
1656 * first packet to transmit. */
1658 ch
->status
= ch
->p
.status
;
1665 /* Don't leak all the previously allocated mbufs in this loop */
1667 OS_mem_token_free (ch
->mdr
[i
].mem_token
);
1679 /* stop the hardware from servicing & interrupting */
1682 c4_stopwd (ci_t
* ci
)
1684 OS_stop_watchdog (&ci
->wd
);
1685 SD_SEM_TAKE (&ci
->sem_wdbusy
, "_stop_"); /* ensure WD not running */
1686 SD_SEM_GIVE (&ci
->sem_wdbusy
);
1691 sbecom_get_brdinfo (ci_t
* ci
, struct sbe_brd_info
* bip
, u_int8_t
*bsn
)
1697 bip
->brdno
= ci
->brdno
; /* our board number */
1698 bip
->brd_id
= ci
->brd_id
;
1699 bip
->brd_hdw_id
= ci
->hdw_bid
;
1700 bip
->brd_chan_cnt
= MUSYCC_NCHANS
* ci
->max_port
; /* number of channels
1702 bip
->brd_port_cnt
= ci
->max_port
; /* number of ports being used */
1703 bip
->brd_pci_speed
= BINFO_PCI_SPEED_unk
; /* PCI speed not yet
1708 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1709 np
= (char *) hdlc_to_name (ci
->first_if
);
1712 struct net_device
*dev
;
1714 dev
= (struct net_device
*) ci
->first_if
;
1715 np
= (char *) dev
->name
;
1718 strncpy (bip
->first_iname
, np
, CHNM_STRLEN
- 1);
1720 strcpy (bip
->first_iname
, "<NULL>");
1723 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1724 np
= (char *) hdlc_to_name (ci
->last_if
);
1727 struct net_device
*dev
;
1729 dev
= (struct net_device
*) ci
->last_if
;
1730 np
= (char *) dev
->name
;
1733 strncpy (bip
->last_iname
, np
, CHNM_STRLEN
- 1);
1735 strcpy (bip
->last_iname
, "<NULL>");
1739 for (i
= 0; i
< 3; i
++)
1741 bip
->brd_mac_addr
[i
] = *bsn
++;
1745 bip
->brd_mac_addr
[i
] = *bsn
;
1746 sn
= (sn
<< 8) | *bsn
++;
1750 for (i
= 0; i
< 6; i
++)
1751 bip
->brd_mac_addr
[i
] = 0;
1758 c4_get_iidinfo (ci_t
* ci
, struct sbe_iid_info
* iip
)
1760 struct net_device
*dev
;
1763 if (!(dev
= getuserbychan (iip
->channum
)))
1766 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1767 np
= (char *) hdlc_to_name (dev_to_hdlc (dev
));
1771 strncpy (iip
->iname
, np
, CHNM_STRLEN
- 1);
1776 #ifdef CONFIG_SBE_PMCC4_NCOMM
1777 void (*nciInterrupt
[MAX_BOARDS
][4]) (void);
1778 extern void wanpmcC4T1E1_hookInterrupt (int cardID
, int deviceID
, void *handler
);
1781 wanpmcC4T1E1_hookInterrupt (int cardID
, int deviceID
, void *handler
)
1783 if (cardID
< MAX_BOARDS
) /* sanity check */
1784 nciInterrupt
[cardID
][deviceID
] = handler
;
1788 c4_ebus_intr_th_handler (void *devp
)
1790 ci_t
*ci
= (ci_t
*) devp
;
1791 volatile u_int32_t ists
;
1795 /* which COMET caused the interrupt */
1797 ists
= pci_read_32 ((u_int32_t
*) &ci
->cpldbase
->intr
);
1798 if (ists
& PMCC4_CPLD_INTR_CMT_1
)
1801 if (nciInterrupt
[brdno
][0] != NULL
)
1802 (*nciInterrupt
[brdno
][0]) ();
1804 if (ists
& PMCC4_CPLD_INTR_CMT_2
)
1807 if (nciInterrupt
[brdno
][1] != NULL
)
1808 (*nciInterrupt
[brdno
][1]) ();
1810 if (ists
& PMCC4_CPLD_INTR_CMT_3
)
1813 if (nciInterrupt
[brdno
][2] != NULL
)
1814 (*nciInterrupt
[brdno
][2]) ();
1816 if (ists
& PMCC4_CPLD_INTR_CMT_4
)
1819 if (nciInterrupt
[brdno
][3] != NULL
)
1820 (*nciInterrupt
[brdno
][3]) ();
1823 /*** Test code just de-implements the asserted interrupt. Alternate
1824 vendor will supply COMET interrupt handling code herein or such.
1826 pci_write_32 ((u_int32_t
*) &ci
->reg
->glcd
, GCD_MAGIC
| MUSYCC_GCD_INTB_DISABLE
);
1829 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,4,20)
1832 return IRQ_RETVAL (handled
);
1838 wanpmcC4T1E1_getBaseAddress (int cardID
, int deviceID
)
1841 unsigned long base
= 0;
1846 if (ci
->brdno
== cardID
) /* found valid device */
1848 if (deviceID
< ci
->max_port
) /* comet is supported */
1849 base
= ((unsigned long) ci
->port
[deviceID
].cometbase
);
1852 ci
= ci
->next
; /* next board, if any */
1857 #endif /*** CONFIG_SBE_PMCC4_NCOMM ***/
1860 /*** End-of-File ***/