2 * Cronyx-Tau-PCI adapter driver for FreeBSD.
3 * Supports PPP/HDLC, Cisco/HDLC and FrameRelay protocol in synchronous mode,
4 * and asynchronous channels with full modem control.
5 * Keepalive protocol implemented in both Cisco and PPP modes.
7 * Copyright (C) 1999-2004 Cronyx Engineering.
8 * Author: Kurakin Roman, <rik@cronyx.ru>
10 * Copyright (C) 1999-2002 Cronyx Engineering.
11 * Author: Serge Vakulenko, <vak@cronyx.ru>
13 * This software is distributed with NO WARRANTIES, not even the implied
14 * warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 * Authors grant any other persons or organisations a permission to use,
17 * modify and redistribute this software in source and binary forms,
18 * as long as this message is kept with the software, all derivative
19 * works or modified versions.
21 * Cronyx Id: if_cp.c,v 1.1.2.41 2004/06/23 17:09:13 rik Exp $
24 #include <sys/cdefs.h>
25 __FBSDID("$FreeBSD$");
27 #include <sys/param.h>
28 #include <sys/ucred.h>
30 #include <sys/systm.h>
32 #include <sys/kernel.h>
33 #include <sys/module.h>
35 #include <sys/malloc.h>
37 #include <sys/socket.h>
38 #include <sys/sockio.h>
39 #include <sys/sysctl.h>
45 #include <net/if_var.h>
46 #include <dev/pci/pcivar.h>
47 #include <dev/pci/pcireg.h>
48 #include <machine/bus.h>
50 #include <netgraph/ng_message.h>
51 #include <netgraph/netgraph.h>
52 #include <dev/cp/ng_cp.h>
53 #include <dev/cp/machdep.h>
54 #include <dev/cp/cpddk.h>
55 #include <dev/cp/cserial.h>
56 #include <machine/resource.h>
58 #define CP_DEBUG(d,s) ({if (d->chan->debug) {\
59 printf ("%s: ", d->name); printf s;}})
60 #define CP_DEBUG2(d,s) ({if (d->chan->debug>1) {\
61 printf ("%s: ", d->name); printf s;}})
62 #define CP_LOCK_NAME "cpX"
64 #define CP_LOCK(_bd) mtx_lock (&(_bd)->cp_mtx)
65 #define CP_UNLOCK(_bd) mtx_unlock (&(_bd)->cp_mtx)
66 #define CP_LOCK_ASSERT(_bd) mtx_assert (&(_bd)->cp_mtx, MA_OWNED)
68 static int cp_probe __P((device_t));
69 static int cp_attach __P((device_t));
70 static int cp_detach __P((device_t));
72 static device_method_t cp_methods[] = {
73 /* Device interface */
74 DEVMETHOD(device_probe, cp_probe),
75 DEVMETHOD(device_attach, cp_attach),
76 DEVMETHOD(device_detach, cp_detach),
81 typedef struct _cp_dma_mem_t {
89 typedef struct _drv_t {
95 char nodename [NG_NODESIZ];
100 struct ifqueue hi_queue;
102 struct callout timeout_handle;
106 typedef struct _bdrv_t {
108 struct resource *cp_res;
109 struct resource *cp_irq;
112 drv_t channel [NCHAN];
116 static driver_t cp_driver = {
122 static devclass_t cp_devclass;
124 static void cp_receive (cp_chan_t *c, unsigned char *data, int len);
125 static void cp_transmit (cp_chan_t *c, void *attachment, int len);
126 static void cp_error (cp_chan_t *c, int data);
127 static void cp_up (drv_t *d);
128 static void cp_start (drv_t *d);
129 static void cp_down (drv_t *d);
130 static void cp_watchdog (drv_t *d);
131 static void cp_watchdog_timer (void *arg);
132 static struct ng_type typestruct;
134 static cp_board_t *adapter [NBRD];
135 static drv_t *channel [NBRD*NCHAN];
136 static struct callout led_timo [NBRD];
137 static struct callout timeout_handle;
139 static int cp_destroy = 0;
141 static int cp_open (struct cdev *dev, int oflags, int devtype, struct thread *td);
142 static int cp_close (struct cdev *dev, int fflag, int devtype, struct thread *td);
143 static int cp_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td);
144 static struct cdevsw cp_cdevsw = {
145 .d_version = D_VERSION,
153 * Make an mbuf from data.
155 static struct mbuf *makembuf (void *buf, unsigned len)
159 MGETHDR (m, M_NOWAIT, MT_DATA);
162 if (!(MCLGET (m, M_NOWAIT))) {
166 m->m_pkthdr.len = m->m_len = len;
167 bcopy (buf, mtod (m, caddr_t), len);
171 static int cp_probe (device_t dev)
173 if ((pci_get_vendor (dev) == cp_vendor_id) &&
174 (pci_get_device (dev) == cp_device_id)) {
175 device_set_desc (dev, "Cronyx-Tau-PCI serial adapter");
176 return BUS_PROBE_DEFAULT;
181 static void cp_timeout (void *arg)
186 for (i = 0; i < NBRD; ++i) {
187 if (adapter[i] == NULL)
189 for (k = 0; k < NCHAN; ++k) {
195 d = channel[i * NCHAN + k];
200 CP_LOCK ((bdrv_t *)d->board->sys);
201 switch (d->chan->type) {
203 cp_g703_timer (d->chan);
206 cp_e1_timer (d->chan);
211 cp_e3_timer (d->chan);
216 CP_UNLOCK ((bdrv_t *)d->board->sys);
222 callout_reset (&timeout_handle, hz, cp_timeout, 0);
226 static void cp_led_off (void *arg)
229 bdrv_t *bd = (bdrv_t *) b->sys;
242 static void cp_intr (void *arg)
245 cp_board_t *b = bd->board;
252 /* Check if we are ready */
253 if (b->sys == NULL) {
254 /* Not we are not, just cleanup. */
255 cp_interrupt_poll (b, 1);
264 /* Turn LED off 50 msec later. */
265 callout_reset (&led_timo[b->num], hz/20, cp_led_off, b);
272 cp_bus_dmamap_addr (void *arg, bus_dma_segment_t *segs, int nseg, int error)
279 KASSERT(nseg == 1, ("too many DMA segments, %d should be 1", nseg));
281 *addr = segs->ds_addr;
285 cp_bus_dma_mem_alloc (int bnum, int cnum, cp_dma_mem_t *dmem)
289 error = bus_dma_tag_create (NULL, 16, 0, BUS_SPACE_MAXADDR_32BIT,
290 BUS_SPACE_MAXADDR, NULL, NULL, dmem->size, 1,
291 dmem->size, 0, NULL, NULL, &dmem->dmat);
293 if (cnum >= 0) printf ("cp%d-%d: ", bnum, cnum);
294 else printf ("cp%d: ", bnum);
295 printf ("couldn't allocate tag for dma memory\n");
298 error = bus_dmamem_alloc (dmem->dmat, (void **)&dmem->virt,
299 BUS_DMA_NOWAIT | BUS_DMA_ZERO, &dmem->mapp);
301 if (cnum >= 0) printf ("cp%d-%d: ", bnum, cnum);
302 else printf ("cp%d: ", bnum);
303 printf ("couldn't allocate mem for dma memory\n");
304 bus_dma_tag_destroy (dmem->dmat);
307 error = bus_dmamap_load (dmem->dmat, dmem->mapp, dmem->virt,
308 dmem->size, cp_bus_dmamap_addr, &dmem->phys, 0);
310 if (cnum >= 0) printf ("cp%d-%d: ", bnum, cnum);
311 else printf ("cp%d: ", bnum);
312 printf ("couldn't load mem map for dma memory\n");
313 bus_dmamem_free (dmem->dmat, dmem->virt, dmem->mapp);
314 bus_dma_tag_destroy (dmem->dmat);
321 cp_bus_dma_mem_free (cp_dma_mem_t *dmem)
323 bus_dmamap_unload (dmem->dmat, dmem->mapp);
324 bus_dmamem_free (dmem->dmat, dmem->virt, dmem->mapp);
325 bus_dma_tag_destroy (dmem->dmat);
329 * Called if the probe succeeded.
331 static int cp_attach (device_t dev)
333 bdrv_t *bd = device_get_softc (dev);
334 int unit = device_get_unit (dev);
335 char *cp_ln = CP_LOCK_NAME;
344 b = malloc (sizeof(cp_board_t), M_DEVBUF, M_WAITOK);
346 printf ("cp%d: couldn't allocate memory\n", unit);
350 bzero (b, sizeof(cp_board_t));
354 bd->cp_res = bus_alloc_resource (dev, SYS_RES_MEMORY, &rid,
355 0, ~0, 1, RF_ACTIVE);
357 printf ("cp%d: cannot map memory\n", unit);
362 vbase = (vm_offset_t) rman_get_virtual (bd->cp_res);
364 cp_ln[2] = '0' + unit;
365 mtx_init (&bd->cp_mtx, cp_ln, MTX_NETWORK_LOCK, MTX_DEF|MTX_RECURSE);
366 res = cp_init (b, unit, (u_char*) vbase);
368 printf ("cp%d: can't init, error code:%x\n", unit, res);
369 bus_release_resource (dev, SYS_RES_MEMORY, PCIR_BAR(0), bd->cp_res);
375 bd->dmamem.size = sizeof(cp_qbuf_t);
376 if (! cp_bus_dma_mem_alloc (unit, -1, &bd->dmamem)) {
382 cp_reset (b, bd->dmamem.virt, bd->dmamem.phys);
386 bd->cp_irq = bus_alloc_resource (dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
387 RF_SHAREABLE | RF_ACTIVE);
390 printf ("cp%d: cannot map interrupt\n", unit);
391 bus_release_resource (dev, SYS_RES_MEMORY,
392 PCIR_BAR(0), bd->cp_res);
393 mtx_destroy (&bd->cp_mtx);
398 callout_init (&led_timo[unit], 1);
399 error = bus_setup_intr (dev, bd->cp_irq,
400 INTR_TYPE_NET|INTR_MPSAFE,
401 NULL, cp_intr, bd, &bd->cp_intrhand);
404 printf ("cp%d: cannot set up irq\n", unit);
405 bus_release_resource (dev, SYS_RES_IRQ, 0, bd->cp_irq);
406 bus_release_resource (dev, SYS_RES_MEMORY,
407 PCIR_BAR(0), bd->cp_res);
408 mtx_destroy (&bd->cp_mtx);
413 printf ("cp%d: %s, clock %ld MHz\n", unit, b->name, b->osc / 1000000);
415 for (c = b->chan; c < b->chan + NCHAN; ++c) {
418 d = &bd->channel[c->num];
419 d->dmamem.size = sizeof(cp_buf_t);
420 if (! cp_bus_dma_mem_alloc (unit, c->num, &d->dmamem))
422 channel [b->num*NCHAN + c->num] = d;
423 sprintf (d->name, "cp%d.%d", b->num, c->num);
427 callout_init (&d->timeout_handle, 1);
428 if (ng_make_node_common (&typestruct, &d->node) != 0) {
429 printf ("%s: cannot make common node\n", d->name);
433 NG_NODE_SET_PRIVATE (d->node, d);
434 sprintf (d->nodename, "%s%d", NG_CP_NODE_TYPE,
435 c->board->num*NCHAN + c->num);
436 if (ng_name_node (d->node, d->nodename)) {
437 printf ("%s: cannot name node\n", d->nodename);
438 NG_NODE_UNREF (d->node);
441 d->queue.ifq_maxlen = ifqmaxlen;
442 d->hi_queue.ifq_maxlen = ifqmaxlen;
443 mtx_init (&d->queue.ifq_mtx, "cp_queue", NULL, MTX_DEF);
444 mtx_init (&d->hi_queue.ifq_mtx, "cp_queue_hi", NULL, MTX_DEF);
446 cp_start_chan (c, 1, 1, d->dmamem.virt, d->dmamem.phys);
448 /* Register callback functions. */
449 cp_register_transmit (c, &cp_transmit);
450 cp_register_receive (c, &cp_receive);
451 cp_register_error (c, &cp_error);
452 d->devt = make_dev (&cp_cdevsw, b->num*NCHAN+c->num, UID_ROOT,
453 GID_WHEEL, 0600, "cp%d", b->num*NCHAN+c->num);
463 static int cp_detach (device_t dev)
465 bdrv_t *bd = device_get_softc (dev);
466 cp_board_t *b = bd->board;
470 KASSERT (mtx_initialized (&bd->cp_mtx), ("cp mutex not initialized"));
473 /* Check if the device is busy (open). */
474 for (c = b->chan; c < b->chan + NCHAN; ++c) {
475 drv_t *d = (drv_t*) c->sys;
477 if (! d || ! d->chan->type)
486 /* Ok, we can unload driver */
487 /* At first we should stop all channels */
488 for (c = b->chan; c < b->chan + NCHAN; ++c) {
489 drv_t *d = (drv_t*) c->sys;
491 if (! d || ! d->chan->type)
496 cp_set_dtr (d->chan, 0);
497 cp_set_rts (d->chan, 0);
500 /* Reset the adapter. */
502 cp_interrupt_poll (b, 1);
505 callout_stop (&led_timo[b->num]);
507 /* Disable the interrupt request. */
508 bus_teardown_intr (dev, bd->cp_irq, bd->cp_intrhand);
510 for (c=b->chan; c<b->chan+NCHAN; ++c) {
511 drv_t *d = (drv_t*) c->sys;
513 if (! d || ! d->chan->type)
515 callout_stop (&d->timeout_handle);
517 ng_rmnode_self (d->node);
518 NG_NODE_UNREF (d->node);
521 mtx_destroy (&d->queue.ifq_mtx);
522 mtx_destroy (&d->hi_queue.ifq_mtx);
523 destroy_dev (d->devt);
529 bus_release_resource (dev, SYS_RES_IRQ, 0, bd->cp_irq);
530 bus_release_resource (dev, SYS_RES_MEMORY, PCIR_BAR(0), bd->cp_res);
535 callout_drain (&led_timo[b->num]);
538 for (c = b->chan; c < b->chan + NCHAN; ++c) {
539 drv_t *d = (drv_t*) c->sys;
541 if (! d || ! d->chan->type)
543 callout_drain (&d->timeout_handle);
544 channel [b->num*NCHAN + c->num] = NULL;
545 /* Deallocate buffers. */
546 cp_bus_dma_mem_free (&d->dmamem);
548 adapter [b->num] = NULL;
549 cp_bus_dma_mem_free (&bd->dmamem);
551 mtx_destroy (&bd->cp_mtx);
557 * Stop the interface. Called on splimp().
559 static void cp_down (drv_t *d)
561 CP_DEBUG (d, ("cp_down\n"));
562 /* Interface is going down -- stop it. */
563 cp_set_dtr (d->chan, 0);
564 cp_set_rts (d->chan, 0);
567 callout_stop (&d->timeout_handle);
571 * Start the interface. Called on splimp().
573 static void cp_up (drv_t *d)
575 CP_DEBUG (d, ("cp_up\n"));
576 cp_set_dtr (d->chan, 1);
577 cp_set_rts (d->chan, 1);
582 * Start output on the interface. Get another datagram to send
583 * off of the interface queue, and copy it to the interface
584 * before starting the output.
586 static void cp_send (drv_t *d)
591 CP_DEBUG2 (d, ("cp_send, tn=%d te=%d\n", d->chan->tn, d->chan->te));
593 /* No output if the interface is down. */
597 /* No output if the modem is off. */
598 if (! (d->chan->lloop || d->chan->type != T_SERIAL ||
599 cp_get_dsr (d->chan)))
602 while (cp_transmit_space (d->chan)) {
603 /* Get the packet to send. */
604 IF_DEQUEUE (&d->hi_queue, m);
606 IF_DEQUEUE (&d->queue, m);
609 len = m_length (m, NULL);
611 printf ("%s: too long packet: %d bytes: ",
613 else if (! m->m_next)
614 cp_send_packet (d->chan, (u_char*) mtod (m, caddr_t), len, 0);
616 u_char *buf = d->chan->tbuf[d->chan->te];
617 m_copydata (m, 0, len, buf);
618 cp_send_packet (d->chan, buf, len, 0);
621 /* Set up transmit timeout, if the transmit ring is not empty.*/
627 * Start output on the interface.
628 * Always called on splimp().
630 static void cp_start (drv_t *d)
634 cp_set_dtr (d->chan, 1);
636 cp_set_rts (d->chan, 1);
638 callout_reset (&d->timeout_handle, hz, cp_watchdog_timer, d);
643 * Handle transmit timeouts.
644 * Recover after lost transmit interrupts.
645 * Always called on splimp().
647 static void cp_watchdog (drv_t *d)
649 CP_DEBUG (d, ("device timeout\n"));
651 cp_stop_chan (d->chan);
652 cp_stop_e1 (d->chan);
653 cp_start_e1 (d->chan);
654 cp_start_chan (d->chan, 1, 1, 0, 0);
655 cp_set_dtr (d->chan, 1);
656 cp_set_rts (d->chan, 1);
661 static void cp_watchdog_timer (void *arg)
664 bdrv_t *bd = d->board->sys;
671 callout_reset (&d->timeout_handle, hz, cp_watchdog_timer, d);
675 static void cp_transmit (cp_chan_t *c, void *attachment, int len)
683 static void cp_receive (cp_chan_t *c, unsigned char *data, int len)
692 m = makembuf (data, len);
694 CP_DEBUG (d, ("no memory for packet\n"));
699 m->m_pkthdr.rcvif = 0;
700 NG_SEND_DATA_ONLY (error, d->hook, m);
703 static void cp_error (cp_chan_t *c, int data)
709 CP_DEBUG (d, ("frame error\n"));
712 CP_DEBUG (d, ("crc error\n"));
715 CP_DEBUG (d, ("overrun error\n"));
718 CP_DEBUG (d, ("overflow error\n"));
721 CP_DEBUG (d, ("underrun error\n"));
726 CP_DEBUG (d, ("error #%d\n", data));
732 * You also need read, write, open, close routines.
733 * This should get you started
735 static int cp_open (struct cdev *dev, int oflags, int devtype, struct thread *td)
737 int unit = dev2unit (dev);
740 if (unit >= NBRD*NCHAN || ! (d = channel[unit]))
742 CP_DEBUG2 (d, ("cp_open\n"));
747 * Only called on the LAST close.
749 static int cp_close (struct cdev *dev, int fflag, int devtype, struct thread *td)
751 drv_t *d = channel [dev2unit (dev)];
753 CP_DEBUG2 (d, ("cp_close\n"));
757 static int cp_modem_status (cp_chan_t *c)
760 bdrv_t *bd = d->board->sys;
763 status = d->running ? TIOCM_LE : 0;
766 if (cp_get_cd (c)) status |= TIOCM_CD;
767 if (cp_get_cts (c)) status |= TIOCM_CTS;
768 if (cp_get_dsr (c)) status |= TIOCM_DSR;
769 if (c->dtr) status |= TIOCM_DTR;
770 if (c->rts) status |= TIOCM_RTS;
776 static int cp_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td)
778 drv_t *d = channel [dev2unit (dev)];
779 bdrv_t *bd = d->board->sys;
780 cp_chan_t *c = d->chan;
781 struct serial_statistics *st;
782 struct e1_statistics *opte1;
783 struct e3_statistics *opte3;
788 case SERIAL_GETREGISTERED:
789 CP_DEBUG2 (d, ("ioctl: getregistered\n"));
790 bzero (mask, sizeof(mask));
791 for (s=0; s<NBRD*NCHAN; ++s)
793 mask [s/8] |= 1 << (s & 7);
794 bcopy (mask, data, sizeof (mask));
799 CP_DEBUG2 (d, ("ioctl: getmode\n"));
800 *(int*)data = SERIAL_HDLC;
804 /* Only for superuser! */
805 error = priv_check (td, PRIV_DRIVER);
808 if (*(int*)data != SERIAL_HDLC)
813 CP_DEBUG2 (d, ("ioctl: getcfg\n"));
814 if (c->type != T_E1 || c->unfram)
816 *(char*)data = c->board->mux ? 'c' : 'a';
820 CP_DEBUG2 (d, ("ioctl: setcfg\n"));
821 error = priv_check (td, PRIV_DRIVER);
828 cp_set_mux (c->board, *((char*)data) == 'c');
834 CP_DEBUG2 (d, ("ioctl: getstat\n"));
835 st = (struct serial_statistics*) data;
836 st->rintr = c->rintr;
837 st->tintr = c->tintr;
839 st->ibytes = c->ibytes;
840 st->ipkts = c->ipkts;
841 st->obytes = c->obytes;
842 st->opkts = c->opkts;
843 st->ierrs = c->overrun + c->frame + c->crc;
844 st->oerrs = c->underrun;
847 case SERIAL_GETESTAT:
848 CP_DEBUG2 (d, ("ioctl: getestat\n"));
849 if (c->type != T_E1 && c->type != T_G703)
851 opte1 = (struct e1_statistics*) data;
852 opte1->status = c->status;
853 opte1->cursec = c->cursec;
854 opte1->totsec = c->totsec + c->cursec;
856 opte1->currnt.bpv = c->currnt.bpv;
857 opte1->currnt.fse = c->currnt.fse;
858 opte1->currnt.crce = c->currnt.crce;
859 opte1->currnt.rcrce = c->currnt.rcrce;
860 opte1->currnt.uas = c->currnt.uas;
861 opte1->currnt.les = c->currnt.les;
862 opte1->currnt.es = c->currnt.es;
863 opte1->currnt.bes = c->currnt.bes;
864 opte1->currnt.ses = c->currnt.ses;
865 opte1->currnt.oofs = c->currnt.oofs;
866 opte1->currnt.css = c->currnt.css;
867 opte1->currnt.dm = c->currnt.dm;
869 opte1->total.bpv = c->total.bpv + c->currnt.bpv;
870 opte1->total.fse = c->total.fse + c->currnt.fse;
871 opte1->total.crce = c->total.crce + c->currnt.crce;
872 opte1->total.rcrce = c->total.rcrce + c->currnt.rcrce;
873 opte1->total.uas = c->total.uas + c->currnt.uas;
874 opte1->total.les = c->total.les + c->currnt.les;
875 opte1->total.es = c->total.es + c->currnt.es;
876 opte1->total.bes = c->total.bes + c->currnt.bes;
877 opte1->total.ses = c->total.ses + c->currnt.ses;
878 opte1->total.oofs = c->total.oofs + c->currnt.oofs;
879 opte1->total.css = c->total.css + c->currnt.css;
880 opte1->total.dm = c->total.dm + c->currnt.dm;
881 for (s=0; s<48; ++s) {
882 opte1->interval[s].bpv = c->interval[s].bpv;
883 opte1->interval[s].fse = c->interval[s].fse;
884 opte1->interval[s].crce = c->interval[s].crce;
885 opte1->interval[s].rcrce = c->interval[s].rcrce;
886 opte1->interval[s].uas = c->interval[s].uas;
887 opte1->interval[s].les = c->interval[s].les;
888 opte1->interval[s].es = c->interval[s].es;
889 opte1->interval[s].bes = c->interval[s].bes;
890 opte1->interval[s].ses = c->interval[s].ses;
891 opte1->interval[s].oofs = c->interval[s].oofs;
892 opte1->interval[s].css = c->interval[s].css;
893 opte1->interval[s].dm = c->interval[s].dm;
897 case SERIAL_GETE3STAT:
898 CP_DEBUG2 (d, ("ioctl: gete3stat\n"));
899 if (c->type != T_E3 && c->type != T_T3 && c->type != T_STS1)
901 opte3 = (struct e3_statistics*) data;
903 opte3->status = c->e3status;
904 opte3->cursec = (c->e3csec_5 * 2 + 1) / 10;
905 opte3->totsec = c->e3tsec + opte3->cursec;
907 opte3->ccv = c->e3ccv;
908 opte3->tcv = c->e3tcv + opte3->ccv;
910 for (s = 0; s < 48; ++s) {
911 opte3->icv[s] = c->e3icv[s];
916 CP_DEBUG2 (d, ("ioctl: clrstat\n"));
917 /* Only for superuser! */
918 error = priv_check (td, PRIV_DRIVER);
931 bzero (&c->currnt, sizeof (c->currnt));
932 bzero (&c->total, sizeof (c->total));
933 bzero (c->interval, sizeof (c->interval));
936 bzero (c->e3icv, sizeof (c->e3icv));
940 CP_DEBUG2 (d, ("ioctl: getbaud\n"));
941 *(long*)data = c->baud;
945 CP_DEBUG2 (d, ("ioctl: setbaud\n"));
946 /* Only for superuser! */
947 error = priv_check (td, PRIV_DRIVER);
952 cp_set_baud (c, *(long*)data);
958 CP_DEBUG2 (d, ("ioctl: getloop\n"));
959 *(int*)data = c->lloop;
963 CP_DEBUG2 (d, ("ioctl: setloop\n"));
964 /* Only for superuser! */
965 error = priv_check (td, PRIV_DRIVER);
970 cp_set_lloop (c, *(int*)data);
976 CP_DEBUG2 (d, ("ioctl: getdpll\n"));
977 if (c->type != T_SERIAL)
979 *(int*)data = c->dpll;
983 CP_DEBUG2 (d, ("ioctl: setdpll\n"));
984 /* Only for superuser! */
985 error = priv_check (td, PRIV_DRIVER);
988 if (c->type != T_SERIAL)
992 cp_set_dpll (c, *(int*)data);
998 CP_DEBUG2 (d, ("ioctl: getnrzi\n"));
999 if (c->type != T_SERIAL)
1001 *(int*)data = c->nrzi;
1004 case SERIAL_SETNRZI:
1005 CP_DEBUG2 (d, ("ioctl: setnrzi\n"));
1006 /* Only for superuser! */
1007 error = priv_check (td, PRIV_DRIVER);
1010 if (c->type != T_SERIAL)
1014 cp_set_nrzi (c, *(int*)data);
1019 case SERIAL_GETDEBUG:
1020 CP_DEBUG2 (d, ("ioctl: getdebug\n"));
1021 *(int*)data = d->chan->debug;
1024 case SERIAL_SETDEBUG:
1025 CP_DEBUG2 (d, ("ioctl: setdebug\n"));
1026 /* Only for superuser! */
1027 error = priv_check (td, PRIV_DRIVER);
1030 d->chan->debug = *(int*)data;
1033 case SERIAL_GETHIGAIN:
1034 CP_DEBUG2 (d, ("ioctl: gethigain\n"));
1035 if (c->type != T_E1)
1037 *(int*)data = c->higain;
1040 case SERIAL_SETHIGAIN:
1041 CP_DEBUG2 (d, ("ioctl: sethigain\n"));
1042 /* Only for superuser! */
1043 error = priv_check (td, PRIV_DRIVER);
1046 if (c->type != T_E1)
1050 cp_set_higain (c, *(int*)data);
1055 case SERIAL_GETPHONY:
1056 CP_DEBUG2 (d, ("ioctl: getphony\n"));
1057 if (c->type != T_E1)
1059 *(int*)data = c->phony;
1062 case SERIAL_SETPHONY:
1063 CP_DEBUG2 (d, ("ioctl: setphony\n"));
1064 /* Only for superuser! */
1065 error = priv_check (td, PRIV_DRIVER);
1068 if (c->type != T_E1)
1072 cp_set_phony (c, *(int*)data);
1077 case SERIAL_GETUNFRAM:
1078 CP_DEBUG2 (d, ("ioctl: getunfram\n"));
1079 if (c->type != T_E1)
1081 *(int*)data = c->unfram;
1084 case SERIAL_SETUNFRAM:
1085 CP_DEBUG2 (d, ("ioctl: setunfram\n"));
1086 /* Only for superuser! */
1087 error = priv_check (td, PRIV_DRIVER);
1090 if (c->type != T_E1)
1094 cp_set_unfram (c, *(int*)data);
1099 case SERIAL_GETSCRAMBLER:
1100 CP_DEBUG2 (d, ("ioctl: getscrambler\n"));
1101 if (c->type != T_G703 && !c->unfram)
1103 *(int*)data = c->scrambler;
1106 case SERIAL_SETSCRAMBLER:
1107 CP_DEBUG2 (d, ("ioctl: setscrambler\n"));
1108 /* Only for superuser! */
1109 error = priv_check (td, PRIV_DRIVER);
1112 if (c->type != T_G703 && !c->unfram)
1116 cp_set_scrambler (c, *(int*)data);
1121 case SERIAL_GETMONITOR:
1122 CP_DEBUG2 (d, ("ioctl: getmonitor\n"));
1123 if (c->type != T_E1 &&
1128 *(int*)data = c->monitor;
1131 case SERIAL_SETMONITOR:
1132 CP_DEBUG2 (d, ("ioctl: setmonitor\n"));
1133 /* Only for superuser! */
1134 error = priv_check (td, PRIV_DRIVER);
1137 if (c->type != T_E1)
1141 cp_set_monitor (c, *(int*)data);
1146 case SERIAL_GETUSE16:
1147 CP_DEBUG2 (d, ("ioctl: getuse16\n"));
1148 if (c->type != T_E1 || c->unfram)
1150 *(int*)data = c->use16;
1153 case SERIAL_SETUSE16:
1154 CP_DEBUG2 (d, ("ioctl: setuse16\n"));
1155 /* Only for superuser! */
1156 error = priv_check (td, PRIV_DRIVER);
1159 if (c->type != T_E1)
1163 cp_set_use16 (c, *(int*)data);
1168 case SERIAL_GETCRC4:
1169 CP_DEBUG2 (d, ("ioctl: getcrc4\n"));
1170 if (c->type != T_E1 || c->unfram)
1172 *(int*)data = c->crc4;
1175 case SERIAL_SETCRC4:
1176 CP_DEBUG2 (d, ("ioctl: setcrc4\n"));
1177 /* Only for superuser! */
1178 error = priv_check (td, PRIV_DRIVER);
1181 if (c->type != T_E1)
1185 cp_set_crc4 (c, *(int*)data);
1191 CP_DEBUG2 (d, ("ioctl: getclk\n"));
1192 if (c->type != T_E1 &&
1193 c->type != T_G703 &&
1199 default: *(int*)data = E1CLK_INTERNAL; break;
1200 case GSYN_RCV: *(int*)data = E1CLK_RECEIVE; break;
1201 case GSYN_RCV0: *(int*)data = E1CLK_RECEIVE_CHAN0; break;
1202 case GSYN_RCV1: *(int*)data = E1CLK_RECEIVE_CHAN1; break;
1203 case GSYN_RCV2: *(int*)data = E1CLK_RECEIVE_CHAN2; break;
1204 case GSYN_RCV3: *(int*)data = E1CLK_RECEIVE_CHAN3; break;
1209 CP_DEBUG2 (d, ("ioctl: setclk\n"));
1210 /* Only for superuser! */
1211 error = priv_check (td, PRIV_DRIVER);
1214 if (c->type != T_E1 &&
1215 c->type != T_G703 &&
1222 switch (*(int*)data) {
1223 default: cp_set_gsyn (c, GSYN_INT); break;
1224 case E1CLK_RECEIVE: cp_set_gsyn (c, GSYN_RCV); break;
1225 case E1CLK_RECEIVE_CHAN0: cp_set_gsyn (c, GSYN_RCV0); break;
1226 case E1CLK_RECEIVE_CHAN1: cp_set_gsyn (c, GSYN_RCV1); break;
1227 case E1CLK_RECEIVE_CHAN2: cp_set_gsyn (c, GSYN_RCV2); break;
1228 case E1CLK_RECEIVE_CHAN3: cp_set_gsyn (c, GSYN_RCV3); break;
1234 case SERIAL_GETTIMESLOTS:
1235 CP_DEBUG2 (d, ("ioctl: gettimeslots\n"));
1236 if ((c->type != T_E1 || c->unfram) && c->type != T_DATA)
1238 *(u_long*)data = c->ts;
1241 case SERIAL_SETTIMESLOTS:
1242 CP_DEBUG2 (d, ("ioctl: settimeslots\n"));
1243 /* Only for superuser! */
1244 error = priv_check (td, PRIV_DRIVER);
1247 if ((c->type != T_E1 || c->unfram) && c->type != T_DATA)
1251 cp_set_ts (c, *(u_long*)data);
1256 case SERIAL_GETINVCLK:
1257 CP_DEBUG2 (d, ("ioctl: getinvclk\n"));
1261 if (c->type != T_SERIAL)
1263 *(int*)data = c->invtxc;
1267 case SERIAL_SETINVCLK:
1268 CP_DEBUG2 (d, ("ioctl: setinvclk\n"));
1269 /* Only for superuser! */
1270 error = priv_check (td, PRIV_DRIVER);
1273 if (c->type != T_SERIAL)
1277 cp_set_invtxc (c, *(int*)data);
1278 cp_set_invrxc (c, *(int*)data);
1283 case SERIAL_GETINVTCLK:
1284 CP_DEBUG2 (d, ("ioctl: getinvtclk\n"));
1285 if (c->type != T_SERIAL)
1287 *(int*)data = c->invtxc;
1290 case SERIAL_SETINVTCLK:
1291 CP_DEBUG2 (d, ("ioctl: setinvtclk\n"));
1292 /* Only for superuser! */
1293 error = priv_check (td, PRIV_DRIVER);
1296 if (c->type != T_SERIAL)
1300 cp_set_invtxc (c, *(int*)data);
1305 case SERIAL_GETINVRCLK:
1306 CP_DEBUG2 (d, ("ioctl: getinvrclk\n"));
1307 if (c->type != T_SERIAL)
1309 *(int*)data = c->invrxc;
1312 case SERIAL_SETINVRCLK:
1313 CP_DEBUG2 (d, ("ioctl: setinvrclk\n"));
1314 /* Only for superuser! */
1315 error = priv_check (td, PRIV_DRIVER);
1318 if (c->type != T_SERIAL)
1322 cp_set_invrxc (c, *(int*)data);
1327 case SERIAL_GETLEVEL:
1328 CP_DEBUG2 (d, ("ioctl: getlevel\n"));
1329 if (c->type != T_G703)
1333 *(int*)data = cp_get_lq (c);
1340 CP_DEBUG2 (d, ("ioctl: reset\n"));
1341 /* Only for superuser! */
1342 error = priv_check (td, PRIV_DRIVER);
1347 cp_reset (c->board, 0, 0);
1352 case SERIAL_HARDRESET:
1353 CP_DEBUG2 (d, ("ioctl: hardreset\n"));
1354 /* Only for superuser! */
1355 error = priv_check (td, PRIV_DRIVER);
1360 /* hard_reset (c->board); */
1366 case SERIAL_GETCABLE:
1367 CP_DEBUG2 (d, ("ioctl: getcable\n"));
1368 if (c->type != T_SERIAL)
1372 *(int*)data = cp_get_cable (c);
1378 CP_DEBUG2 (d, ("ioctl: getdir\n"));
1379 if (c->type != T_E1 && c->type != T_DATA)
1381 *(int*)data = c->dir;
1385 CP_DEBUG2 (d, ("ioctl: setdir\n"));
1386 /* Only for superuser! */
1387 error = priv_check (td, PRIV_DRIVER);
1392 cp_set_dir (c, *(int*)data);
1397 case SERIAL_GETRLOOP:
1398 CP_DEBUG2 (d, ("ioctl: getrloop\n"));
1399 if (c->type != T_G703 &&
1404 *(int*)data = cp_get_rloop (c);
1407 case SERIAL_SETRLOOP:
1408 CP_DEBUG2 (d, ("ioctl: setloop\n"));
1409 if (c->type != T_E3 && c->type != T_T3 && c->type != T_STS1)
1411 /* Only for superuser! */
1412 error = priv_check (td, PRIV_DRIVER);
1417 cp_set_rloop (c, *(int*)data);
1422 case SERIAL_GETCABLEN:
1423 CP_DEBUG2 (d, ("ioctl: getcablen\n"));
1424 if (c->type != T_T3 && c->type != T_STS1)
1426 *(int*)data = c->cablen;
1429 case SERIAL_SETCABLEN:
1430 CP_DEBUG2 (d, ("ioctl: setloop\n"));
1431 if (c->type != T_T3 && c->type != T_STS1)
1433 /* Only for superuser! */
1434 error = priv_check (td, PRIV_DRIVER);
1439 cp_set_cablen (c, *(int*)data);
1444 case TIOCSDTR: /* Set DTR */
1452 case TIOCCDTR: /* Clear DTR */
1460 case TIOCMSET: /* Set DTR/RTS */
1463 cp_set_dtr (c, (*(int*)data & TIOCM_DTR) ? 1 : 0);
1464 cp_set_rts (c, (*(int*)data & TIOCM_RTS) ? 1 : 0);
1469 case TIOCMBIS: /* Add DTR/RTS */
1472 if (*(int*)data & TIOCM_DTR) cp_set_dtr (c, 1);
1473 if (*(int*)data & TIOCM_RTS) cp_set_rts (c, 1);
1478 case TIOCMBIC: /* Clear DTR/RTS */
1481 if (*(int*)data & TIOCM_DTR) cp_set_dtr (c, 0);
1482 if (*(int*)data & TIOCM_RTS) cp_set_rts (c, 0);
1487 case TIOCMGET: /* Get modem status */
1488 *(int*)data = cp_modem_status (c);
1494 static int ng_cp_constructor (node_p node)
1496 drv_t *d = NG_NODE_PRIVATE (node);
1497 CP_DEBUG (d, ("Constructor\n"));
1501 static int ng_cp_newhook (node_p node, hook_p hook, const char *name)
1504 drv_t *d = NG_NODE_PRIVATE (node);
1505 bdrv_t *bd = d->board->sys;
1507 CP_DEBUG (d, ("Newhook\n"));
1508 /* Attach debug hook */
1509 if (strcmp (name, NG_CP_HOOK_DEBUG) == 0) {
1510 NG_HOOK_SET_PRIVATE (hook, NULL);
1511 d->debug_hook = hook;
1515 /* Check for raw hook */
1516 if (strcmp (name, NG_CP_HOOK_RAW) != 0)
1519 NG_HOOK_SET_PRIVATE (hook, d);
1529 static char *format_timeslots (u_long s)
1531 static char buf [100];
1535 for (i=1; i<32; ++i)
1537 int prev = (i > 1) & (s >> (i-1));
1538 int next = (i < 31) & (s >> (i+1));
1548 *p++ = '0' + i / 10;
1549 *p++ = '0' + i % 10;
1555 static int print_modems (char *s, cp_chan_t *c, int need_header)
1557 int status = cp_modem_status (c);
1561 length += sprintf (s + length, " LE DTR DSR RTS CTS CD\n");
1562 length += sprintf (s + length, "%4s %4s %4s %4s %4s %4s\n",
1563 status & TIOCM_LE ? "On" : "-",
1564 status & TIOCM_DTR ? "On" : "-",
1565 status & TIOCM_DSR ? "On" : "-",
1566 status & TIOCM_RTS ? "On" : "-",
1567 status & TIOCM_CTS ? "On" : "-",
1568 status & TIOCM_CD ? "On" : "-");
1572 static int print_stats (char *s, cp_chan_t *c, int need_header)
1577 length += sprintf (s + length, " Rintr Tintr Mintr Ibytes Ipkts Ierrs Obytes Opkts Oerrs\n");
1578 length += sprintf (s + length, "%7ld %7ld %7ld %8lu %7ld %7ld %8lu %7ld %7ld\n",
1579 c->rintr, c->tintr, 0l, (unsigned long) c->ibytes,
1580 c->ipkts, c->overrun + c->frame + c->crc,
1581 (unsigned long) c->obytes, c->opkts, c->underrun);
1585 static char *format_e1_status (u_char status)
1587 static char buf [80];
1589 if (status & E1_NOALARM)
1592 if (status & E1_LOS) strcat (buf, ",LOS");
1593 if (status & E1_AIS) strcat (buf, ",AIS");
1594 if (status & E1_LOF) strcat (buf, ",LOF");
1595 if (status & E1_LOMF) strcat (buf, ",LOMF");
1596 if (status & E1_FARLOF) strcat (buf, ",FARLOF");
1597 if (status & E1_AIS16) strcat (buf, ",AIS16");
1598 if (status & E1_FARLOMF) strcat (buf, ",FARLOMF");
1599 if (status & E1_TSTREQ) strcat (buf, ",TSTREQ");
1600 if (status & E1_TSTERR) strcat (buf, ",TSTERR");
1606 static int print_frac (char *s, int leftalign, u_long numerator, u_long divider)
1610 if (numerator < 1 || divider < 1) {
1611 length += sprintf (s+length, leftalign ? "/- " : " -");
1614 n = (int) (0.5 + 1000.0 * numerator / divider);
1616 length += sprintf (s+length, leftalign ? "/.%-3d" : " .%03d", n);
1619 *(s + length) = leftalign ? '/' : ' ';
1622 if (n >= 1000000) n = (n+500) / 1000 * 1000;
1623 else if (n >= 100000) n = (n+50) / 100 * 100;
1624 else if (n >= 10000) n = (n+5) / 10 * 10;
1627 case 1000: length += printf (s+length, ".999"); return length;
1628 case 10000: n = 9990; break;
1629 case 100000: n = 99900; break;
1630 case 1000000: n = 999000; break;
1632 if (n < 10000) length += sprintf (s+length, "%d.%d", n/1000, n/10%100);
1633 else if (n < 100000) length += sprintf (s+length, "%d.%d", n/1000, n/100%10);
1634 else if (n < 1000000) length += sprintf (s+length, "%d.", n/1000);
1635 else length += sprintf (s+length, "%d", n/1000);
1640 static int print_e1_stats (char *s, cp_chan_t *c)
1642 struct e1_counters total;
1646 totsec = c->totsec + c->cursec;
1647 total.bpv = c->total.bpv + c->currnt.bpv;
1648 total.fse = c->total.fse + c->currnt.fse;
1649 total.crce = c->total.crce + c->currnt.crce;
1650 total.rcrce = c->total.rcrce + c->currnt.rcrce;
1651 total.uas = c->total.uas + c->currnt.uas;
1652 total.les = c->total.les + c->currnt.les;
1653 total.es = c->total.es + c->currnt.es;
1654 total.bes = c->total.bes + c->currnt.bes;
1655 total.ses = c->total.ses + c->currnt.ses;
1656 total.oofs = c->total.oofs + c->currnt.oofs;
1657 total.css = c->total.css + c->currnt.css;
1658 total.dm = c->total.dm + c->currnt.dm;
1660 length += sprintf (s + length, " Unav/Degr Bpv/Fsyn CRC/RCRC Err/Lerr Sev/Bur Oof/Slp Status\n");
1662 /* Unavailable seconds, degraded minutes */
1663 length += print_frac (s + length, 0, c->currnt.uas, c->cursec);
1664 length += print_frac (s + length, 1, 60 * c->currnt.dm, c->cursec);
1666 /* Bipolar violations, frame sync errors */
1667 length += print_frac (s + length, 0, c->currnt.bpv, c->cursec);
1668 length += print_frac (s + length, 1, c->currnt.fse, c->cursec);
1670 /* CRC errors, remote CRC errors (E-bit) */
1671 length += print_frac (s + length, 0, c->currnt.crce, c->cursec);
1672 length += print_frac (s + length, 1, c->currnt.rcrce, c->cursec);
1674 /* Errored seconds, line errored seconds */
1675 length += print_frac (s + length, 0, c->currnt.es, c->cursec);
1676 length += print_frac (s + length, 1, c->currnt.les, c->cursec);
1678 /* Severely errored seconds, burst errored seconds */
1679 length += print_frac (s + length, 0, c->currnt.ses, c->cursec);
1680 length += print_frac (s + length, 1, c->currnt.bes, c->cursec);
1682 /* Out of frame seconds, controlled slip seconds */
1683 length += print_frac (s + length, 0, c->currnt.oofs, c->cursec);
1684 length += print_frac (s + length, 1, c->currnt.css, c->cursec);
1686 length += sprintf (s + length, " %s\n", format_e1_status (c->status));
1688 /* Print total statistics. */
1689 length += print_frac (s + length, 0, total.uas, totsec);
1690 length += print_frac (s + length, 1, 60 * total.dm, totsec);
1692 length += print_frac (s + length, 0, total.bpv, totsec);
1693 length += print_frac (s + length, 1, total.fse, totsec);
1695 length += print_frac (s + length, 0, total.crce, totsec);
1696 length += print_frac (s + length, 1, total.rcrce, totsec);
1698 length += print_frac (s + length, 0, total.es, totsec);
1699 length += print_frac (s + length, 1, total.les, totsec);
1701 length += print_frac (s + length, 0, total.ses, totsec);
1702 length += print_frac (s + length, 1, total.bes, totsec);
1704 length += print_frac (s + length, 0, total.oofs, totsec);
1705 length += print_frac (s + length, 1, total.css, totsec);
1707 length += sprintf (s + length, " -- Total\n");
1711 static int print_chan (char *s, cp_chan_t *c)
1714 bdrv_t *bd = d->board->sys;
1717 length += sprintf (s + length, "cp%d", c->board->num * NCHAN + c->num);
1719 length += sprintf (s + length, " debug=%d", d->chan->debug);
1721 if (c->board->mux) {
1722 length += sprintf (s + length, " cfg=C");
1724 length += sprintf (s + length, " cfg=A");
1728 length += sprintf (s + length, " %ld", c->baud);
1730 length += sprintf (s + length, " extclock");
1732 if (c->type == T_E1 || c->type == T_G703)
1734 case GSYN_INT : length += sprintf (s + length, " syn=int"); break;
1735 case GSYN_RCV : length += sprintf (s + length, " syn=rcv"); break;
1736 case GSYN_RCV0 : length += sprintf (s + length, " syn=rcv0"); break;
1737 case GSYN_RCV1 : length += sprintf (s + length, " syn=rcv1"); break;
1738 case GSYN_RCV2 : length += sprintf (s + length, " syn=rcv2"); break;
1739 case GSYN_RCV3 : length += sprintf (s + length, " syn=rcv3"); break;
1741 if (c->type == T_SERIAL) {
1742 length += sprintf (s + length, " dpll=%s", c->dpll ? "on" : "off");
1743 length += sprintf (s + length, " nrzi=%s", c->nrzi ? "on" : "off");
1744 length += sprintf (s + length, " invclk=%s", c->invtxc ? "on" : "off");
1746 if (c->type == T_E1)
1747 length += sprintf (s + length, " higain=%s", c->higain ? "on" : "off");
1749 length += sprintf (s + length, " loop=%s", c->lloop ? "on" : "off");
1751 if (c->type == T_E1)
1752 length += sprintf (s + length, " ts=%s", format_timeslots (c->ts));
1753 if (c->type == T_G703) {
1761 length += sprintf (s + length, " (level=-%.1fdB)", lq / 10.0);
1763 length += sprintf (s + length, "\n");
1767 static int ng_cp_rcvmsg (node_p node, item_p item, hook_p lasthook)
1769 drv_t *d = NG_NODE_PRIVATE (node);
1770 struct ng_mesg *msg;
1771 struct ng_mesg *resp = NULL;
1774 CP_DEBUG (d, ("Rcvmsg\n"));
1775 NGI_GET_MSG (item, msg);
1776 switch (msg->header.typecookie) {
1782 printf ("Not implemented yet\n");
1786 case NGM_GENERIC_COOKIE:
1787 switch (msg->header.cmd) {
1792 case NGM_TEXT_STATUS: {
1795 int dl = sizeof (struct ng_mesg) + 730;
1797 NG_MKRESPONSE (resp, msg, dl, M_NOWAIT);
1804 l += print_chan (s + l, d->chan);
1805 l += print_stats (s + l, d->chan, 1);
1806 l += print_modems (s + l, d->chan, 1);
1807 l += print_e1_stats (s + l, d->chan);
1809 l += sprintf (s + l, "Error: node not connect to channel");
1810 strncpy ((resp)->header.cmdstr, "status", NG_CMDSTRSIZ);
1816 NG_RESPOND_MSG (error, node, item, resp);
1821 static int ng_cp_rcvdata (hook_p hook, item_p item)
1823 drv_t *d = NG_NODE_PRIVATE (NG_HOOK_NODE(hook));
1825 struct ng_tag_prio *ptag;
1826 bdrv_t *bd = d->board->sys;
1830 CP_DEBUG2 (d, ("Rcvdata\n"));
1831 NGI_GET_M (item, m);
1832 NG_FREE_ITEM (item);
1833 if (! NG_HOOK_PRIVATE (hook) || ! d) {
1838 /* Check for high priority data */
1839 if ((ptag = (struct ng_tag_prio *)m_tag_locate(m, NGM_GENERIC_COOKIE,
1840 NG_TAG_PRIO, NULL)) != NULL && (ptag->priority > NG_PRIO_CUTOFF) )
1848 if (_IF_QFULL (q)) {
1863 static int ng_cp_rmnode (node_p node)
1865 drv_t *d = NG_NODE_PRIVATE (node);
1867 CP_DEBUG (d, ("Rmnode\n"));
1868 if (d && d->running) {
1869 bdrv_t *bd = d->board->sys;
1877 if (node->nd_flags & NGF_REALLY_DIE) {
1878 NG_NODE_SET_PRIVATE (node, NULL);
1879 NG_NODE_UNREF (node);
1881 NG_NODE_REVIVE(node); /* Persistent node */
1886 static int ng_cp_connect (hook_p hook)
1888 drv_t *d = NG_NODE_PRIVATE (NG_HOOK_NODE (hook));
1891 CP_DEBUG (d, ("Connect\n"));
1892 callout_reset (&d->timeout_handle, hz, cp_watchdog_timer, d);
1898 static int ng_cp_disconnect (hook_p hook)
1900 drv_t *d = NG_NODE_PRIVATE (NG_HOOK_NODE (hook));
1903 CP_DEBUG (d, ("Disconnect\n"));
1904 if (NG_HOOK_PRIVATE (hook))
1906 bdrv_t *bd = d->board->sys;
1913 /* If we were wait it than it reasserted now, just stop it. */
1914 if (!callout_drain (&d->timeout_handle))
1915 callout_stop (&d->timeout_handle);
1920 static int cp_modevent (module_t mod, int type, void *unused)
1922 static int load_count = 0;
1926 if (ng_newtype (&typestruct))
1927 printf ("Failed to register ng_cp\n");
1929 callout_init (&timeout_handle, 1);
1930 callout_reset (&timeout_handle, hz*5, cp_timeout, 0);
1933 if (load_count == 1) {
1934 printf ("Removing device entry for Tau-PCI\n");
1935 ng_rmtype (&typestruct);
1937 /* If we were wait it than it reasserted now, just stop it.
1938 * Actually we shouldn't get this condition. But code could be
1939 * changed in the future, so just be a litle paranoid.
1941 if (!callout_drain (&timeout_handle))
1942 callout_stop (&timeout_handle);
1951 static struct ng_type typestruct = {
1952 .version = NG_ABI_VERSION,
1953 .name = NG_CP_NODE_TYPE,
1954 .constructor = ng_cp_constructor,
1955 .rcvmsg = ng_cp_rcvmsg,
1956 .shutdown = ng_cp_rmnode,
1957 .newhook = ng_cp_newhook,
1958 .connect = ng_cp_connect,
1959 .rcvdata = ng_cp_rcvdata,
1960 .disconnect = ng_cp_disconnect,
1963 MODULE_DEPEND (ng_cp, netgraph, NG_ABI_VERSION, NG_ABI_VERSION, NG_ABI_VERSION);
1964 DRIVER_MODULE (cp, pci, cp_driver, cp_devclass, cp_modevent, NULL);
1965 MODULE_VERSION (cp, 1);