if_cx.c (130971) | if_cx.c (130985) |
---|---|
1/* 2 * Cronyx-Sigma adapter driver for FreeBSD. 3 * Supports PPP/HDLC and Cisco/HDLC protocol in synchronous mode, 4 * and asyncronous channels with full modem control. 5 * Keepalive protocol implemented in both Cisco and PPP modes. 6 * 7 * Copyright (C) 1994-2002 Cronyx Engineering. 8 * Author: Serge Vakulenko, <vak@cronyx.ru> --- 5 unchanged lines hidden (view full) --- 14 * This software is distributed with NO WARRANTIES, not even the implied 15 * warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 16 * 17 * Authors grant any other persons or organisations a permission to use, 18 * modify and redistribute this software in source and binary forms, 19 * as long as this message is kept with the software, all derivative 20 * works or modified versions. 21 * | 1/* 2 * Cronyx-Sigma adapter driver for FreeBSD. 3 * Supports PPP/HDLC and Cisco/HDLC protocol in synchronous mode, 4 * and asyncronous channels with full modem control. 5 * Keepalive protocol implemented in both Cisco and PPP modes. 6 * 7 * Copyright (C) 1994-2002 Cronyx Engineering. 8 * Author: Serge Vakulenko, <vak@cronyx.ru> --- 5 unchanged lines hidden (view full) --- 14 * This software is distributed with NO WARRANTIES, not even the implied 15 * warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 16 * 17 * Authors grant any other persons or organisations a permission to use, 18 * modify and redistribute this software in source and binary forms, 19 * as long as this message is kept with the software, all derivative 20 * works or modified versions. 21 * |
22 * Cronyx Id: if_cx.c,v 1.1.2.23 2004/02/26 17:56:40 rik Exp $ | 22 * Cronyx Id: if_cx.c,v 1.1.2.34 2004/06/23 17:09:13 rik Exp $ |
23 */ | 23 */ |
24 |
|
24#include <sys/cdefs.h> | 25#include <sys/cdefs.h> |
25__FBSDID("$FreeBSD: head/sys/dev/cx/if_cx.c 130971 2004-06-23 11:23:54Z rik $"); | 26__FBSDID("$FreeBSD: head/sys/dev/cx/if_cx.c 130985 2004-06-23 18:13:10Z rik $"); |
26 27#include <sys/param.h> 28 29#if __FreeBSD_version >= 500000 30# define NCX 1 31#else 32# include "cx.h" 33#endif --- 18 unchanged lines hidden (view full) --- 52#include <sys/interrupt.h> 53#include <vm/vm.h> 54#include <vm/pmap.h> 55#include <net/if.h> 56#include <machine/cpufunc.h> 57#include <machine/cserial.h> 58#include <machine/clock.h> 59#if __FreeBSD_version < 500000 | 27 28#include <sys/param.h> 29 30#if __FreeBSD_version >= 500000 31# define NCX 1 32#else 33# include "cx.h" 34#endif --- 18 unchanged lines hidden (view full) --- 53#include <sys/interrupt.h> 54#include <vm/vm.h> 55#include <vm/pmap.h> 56#include <net/if.h> 57#include <machine/cpufunc.h> 58#include <machine/cserial.h> 59#include <machine/clock.h> 60#if __FreeBSD_version < 500000 |
60#include 61#include | 61# include <machine/ipl.h> 62# include <i386/isa/isa_device.h> |
62#endif 63#include <machine/resource.h> 64#if __FreeBSD_version <= 501000 65# include <i386/isa/intr_machdep.h> 66#endif 67#include <dev/cx/machdep.h> 68#include <dev/cx/cxddk.h> 69#include <dev/cx/cronyxfw.h> --- 67 unchanged lines hidden (view full) --- 137static device_method_t cx_isa_methods [] = { 138 DEVMETHOD(device_identify, cx_identify), 139 DEVMETHOD(device_probe, cx_probe), 140 DEVMETHOD(device_attach, cx_attach), 141 DEVMETHOD(device_detach, cx_detach), 142 {0, 0} 143}; 144 | 63#endif 64#include <machine/resource.h> 65#if __FreeBSD_version <= 501000 66# include <i386/isa/intr_machdep.h> 67#endif 68#include <dev/cx/machdep.h> 69#include <dev/cx/cxddk.h> 70#include <dev/cx/cronyxfw.h> --- 67 unchanged lines hidden (view full) --- 138static device_method_t cx_isa_methods [] = { 139 DEVMETHOD(device_identify, cx_identify), 140 DEVMETHOD(device_probe, cx_probe), 141 DEVMETHOD(device_attach, cx_attach), 142 DEVMETHOD(device_detach, cx_detach), 143 {0, 0} 144}; 145 |
145typedef struct _bdrv_t { 146 cx_board_t *board; 147 struct resource *base_res; 148 struct resource *drq_res; 149 struct resource *irq_res; 150 int base_rid; 151 int drq_rid; 152 int irq_rid; 153 void *intrhand; 154} bdrv_t; | 146typedef struct _cx_dma_mem_t { 147 unsigned long phys; 148 void *virt; 149 size_t size; 150#if __FreeBSD_version >= 500000 151 bus_dma_tag_t dmat; 152 bus_dmamap_t mapp; 153#endif 154} cx_dma_mem_t; |
155 | 155 |
156static driver_t cx_isa_driver = { 157 "cx", 158 cx_isa_methods, 159 sizeof (bdrv_t), 160}; 161 162static devclass_t cx_devclass; 163 | |
164typedef struct _drv_t { 165 char name [8]; 166 cx_chan_t *chan; 167 cx_board_t *board; | 156typedef struct _drv_t { 157 char name [8]; 158 cx_chan_t *chan; 159 cx_board_t *board; |
168 cx_buf_t buf; | 160 cx_dma_mem_t dmamem; |
169 struct tty *tty; 170 struct callout_handle dcd_timeout_handle; 171 unsigned dtrwait; 172 unsigned dtroff; 173 unsigned callout; 174 unsigned lock; 175 int open_dev; 176 int cd; --- 14 unchanged lines hidden (view full) --- 191 struct cdev *devt[3]; 192 async_q aqueue; 193#define CX_READ 1 194#define CX_WRITE 2 195 int intr_action; 196 short atimeout; 197} drv_t; 198 | 161 struct tty *tty; 162 struct callout_handle dcd_timeout_handle; 163 unsigned dtrwait; 164 unsigned dtroff; 165 unsigned callout; 166 unsigned lock; 167 int open_dev; 168 int cd; --- 14 unchanged lines hidden (view full) --- 183 struct cdev *devt[3]; 184 async_q aqueue; 185#define CX_READ 1 186#define CX_WRITE 2 187 int intr_action; 188 short atimeout; 189} drv_t; 190 |
191typedef struct _bdrv_t { 192 cx_board_t *board; 193 struct resource *base_res; 194 struct resource *drq_res; 195 struct resource *irq_res; 196 int base_rid; 197 int drq_rid; 198 int irq_rid; 199 void *intrhand; 200 drv_t channel [NCHAN]; 201} bdrv_t; 202 203static driver_t cx_isa_driver = { 204 "cx", 205 cx_isa_methods, 206 sizeof (bdrv_t), 207}; 208 209static devclass_t cx_devclass; 210 |
|
199extern long csigma_fw_len; 200extern const char *csigma_fw_version; 201extern const char *csigma_fw_date; 202extern const char *csigma_fw_copyright; 203extern const cr_dat_tst_t csigma_fw_tvec[]; 204extern const u_char csigma_fw_data[]; 205static void cx_oproc (struct tty *tp); 206static int cx_param (struct tty *tp, struct termios *t); --- 359 unchanged lines hidden (view full) --- 566 if (!cx_probe_board (iobase, -1, -1)) { 567 printf ("cx%d: probing for Sigma at %lx faild\n", unit, iobase); 568 return ENXIO; 569 } 570 571 return 0; 572} 573 | 211extern long csigma_fw_len; 212extern const char *csigma_fw_version; 213extern const char *csigma_fw_date; 214extern const char *csigma_fw_copyright; 215extern const cr_dat_tst_t csigma_fw_tvec[]; 216extern const u_char csigma_fw_data[]; 217static void cx_oproc (struct tty *tp); 218static int cx_param (struct tty *tp, struct termios *t); --- 359 unchanged lines hidden (view full) --- 578 if (!cx_probe_board (iobase, -1, -1)) { 579 printf ("cx%d: probing for Sigma at %lx faild\n", unit, iobase); 580 return ENXIO; 581 } 582 583 return 0; 584} 585 |
586#if __FreeBSD_version >= 500000 587static void 588cx_bus_dmamap_addr (void *arg, bus_dma_segment_t *segs, int nseg, int error) 589{ 590 unsigned long *addr; 591 592 if (error) 593 return; 594 595 KASSERT(nseg == 1, ("too many DMA segments, %d should be 1", nseg)); 596 addr = arg; 597 *addr = segs->ds_addr; 598} 599 600static int 601cx_bus_dma_mem_alloc (int bnum, int cnum, cx_dma_mem_t *dmem) 602{ 603 int error; 604 605 error = bus_dma_tag_create (NULL, 16, 0, BUS_SPACE_MAXADDR_24BIT, 606 BUS_SPACE_MAXADDR, NULL, NULL, dmem->size, 1, 607 dmem->size, 0, NULL, NULL, &dmem->dmat); 608 if (error) { 609 if (cnum >= 0) printf ("cx%d-%d: ", bnum, cnum); 610 else printf ("cx%d: ", bnum); 611 printf ("couldn't allocate tag for dma memory\n"); 612 return 0; 613 } 614 error = bus_dmamem_alloc (dmem->dmat, (void **)&dmem->virt, 615 BUS_DMA_NOWAIT | BUS_DMA_ZERO, &dmem->mapp); 616 if (error) { 617 if (cnum >= 0) printf ("cx%d-%d: ", bnum, cnum); 618 else printf ("cx%d: ", bnum); 619 printf ("couldn't allocate mem for dma memory\n"); 620 bus_dma_tag_destroy (dmem->dmat); 621 return 0; 622 } 623 error = bus_dmamap_load (dmem->dmat, dmem->mapp, dmem->virt, 624 dmem->size, cx_bus_dmamap_addr, &dmem->phys, 0); 625 if (error) { 626 if (cnum >= 0) printf ("cx%d-%d: ", bnum, cnum); 627 else printf ("cx%d: ", bnum); 628 printf ("couldn't load mem map for dma memory\n"); 629 bus_dmamem_free (dmem->dmat, dmem->virt, dmem->mapp); 630 bus_dma_tag_destroy (dmem->dmat); 631 return 0; 632 } 633 return 1; 634} 635 636static void 637cx_bus_dma_mem_free (cx_dma_mem_t *dmem) 638{ 639 bus_dmamap_unload (dmem->dmat, dmem->mapp); 640 bus_dmamem_free (dmem->dmat, dmem->virt, dmem->mapp); 641 bus_dma_tag_destroy (dmem->dmat); 642} 643#else 644static int 645cx_bus_dma_mem_alloc (int bnum, int cnum, cx_dma_mem_t *dmem) 646{ 647 dmem->virt = contigmalloc (dmem->size, M_DEVBUF, M_WAITOK, 648 0x100000, 0x1000000, 16, 0); 649 if (dmem->virt == NULL) { 650 if (cnum >= 0) printf ("cx%d-%d: ", bnum, cnum); 651 else printf ("cx%d: ", bnum); 652 printf ("couldn't allocate memory for dma memory\n", unit); 653 return 0; 654 } 655 dmem->phys = vtophys (dmem->virt); 656 return 1; 657} 658 659static void 660cx_bus_dma_mem_free (cx_dma_mem_t *dmem) 661{ 662 contigfree (dmem->virt, dmem->size, M_DEVBUF); 663} 664#endif 665 |
|
574/* 575 * The adapter is present, initialize the driver structures. 576 */ 577static int cx_attach (device_t dev) 578{ 579 bdrv_t *bd = device_get_softc (dev); 580 u_long iobase, drq, irq, rescount; 581 int unit = device_get_unit (dev); --- 130 unchanged lines hidden (view full) --- 712 713 printf ("cx%d: <Cronyx-Sigma-%s>\n", b->num, b->name); 714 715 for (c=b->chan; c<b->chan+NCHAN; ++c) { 716 char *dnmt="tty %x"; 717 char *dnmc="cua %x"; 718 if (c->type == T_NONE) 719 continue; | 666/* 667 * The adapter is present, initialize the driver structures. 668 */ 669static int cx_attach (device_t dev) 670{ 671 bdrv_t *bd = device_get_softc (dev); 672 u_long iobase, drq, irq, rescount; 673 int unit = device_get_unit (dev); --- 130 unchanged lines hidden (view full) --- 804 805 printf ("cx%d: <Cronyx-Sigma-%s>\n", b->num, b->name); 806 807 for (c=b->chan; c<b->chan+NCHAN; ++c) { 808 char *dnmt="tty %x"; 809 char *dnmc="cua %x"; 810 if (c->type == T_NONE) 811 continue; |
720 d = contigmalloc (sizeof(drv_t), M_DEVBUF, M_WAITOK, 721 0x100000, 0x1000000, 16, 0); | 812 d = &bd->channel[c->num]; 813 d->dmamem.size = sizeof(cx_buf_t); 814 if (! cx_bus_dma_mem_alloc (unit, c->num, &d->dmamem)) 815 continue; |
722 channel [b->num*NCHAN + c->num] = d; | 816 channel [b->num*NCHAN + c->num] = d; |
723 bzero (d, sizeof(drv_t)); | |
724 sprintf (d->name, "cx%d.%d", b->num, c->num); 725 d->board = b; 726 d->chan = c; 727 d->dtrwait = 3 * hz; /* Default DTR off timeout is 3 seconds. */ 728 d->open_dev = 0; 729 c->sys = d; 730 731 switch (c->type) { --- 4 unchanged lines hidden (view full) --- 736 case T_UNIV_RS232: 737 case T_UNIV_RS449: 738 case T_UNIV_V35: 739#ifdef NETGRAPH 740 if (ng_make_node_common (&typestruct, &d->node) != 0) { 741 printf ("%s: cannot make common node\n", d->name); 742 channel [b->num*NCHAN + c->num] = 0; 743 c->sys = 0; | 817 sprintf (d->name, "cx%d.%d", b->num, c->num); 818 d->board = b; 819 d->chan = c; 820 d->dtrwait = 3 * hz; /* Default DTR off timeout is 3 seconds. */ 821 d->open_dev = 0; 822 c->sys = d; 823 824 switch (c->type) { --- 4 unchanged lines hidden (view full) --- 829 case T_UNIV_RS232: 830 case T_UNIV_RS449: 831 case T_UNIV_V35: 832#ifdef NETGRAPH 833 if (ng_make_node_common (&typestruct, &d->node) != 0) { 834 printf ("%s: cannot make common node\n", d->name); 835 channel [b->num*NCHAN + c->num] = 0; 836 c->sys = 0; |
744 contigfree (d, sizeof (*d), M_DEVBUF); | 837 cx_bus_dma_mem_free (&d->dmamem); |
745 continue; 746 } 747#if __FreeBSD_version >= 500000 748 NG_NODE_SET_PRIVATE (d->node, d); 749#else 750 d->node->private = d; 751#endif 752 sprintf (d->nodename, "%s%d", NG_CX_NODE_TYPE, 753 c->board->num*NCHAN + c->num); 754 if (ng_name_node (d->node, d->nodename)) { 755 printf ("%s: cannot name node\n", d->nodename); 756#if __FreeBSD_version >= 500000 757 NG_NODE_UNREF (d->node); 758#else 759 ng_rmnode (d->node); 760 ng_unref (d->node); 761#endif 762 channel [b->num*NCHAN + c->num] = 0; 763 c->sys = 0; | 838 continue; 839 } 840#if __FreeBSD_version >= 500000 841 NG_NODE_SET_PRIVATE (d->node, d); 842#else 843 d->node->private = d; 844#endif 845 sprintf (d->nodename, "%s%d", NG_CX_NODE_TYPE, 846 c->board->num*NCHAN + c->num); 847 if (ng_name_node (d->node, d->nodename)) { 848 printf ("%s: cannot name node\n", d->nodename); 849#if __FreeBSD_version >= 500000 850 NG_NODE_UNREF (d->node); 851#else 852 ng_rmnode (d->node); 853 ng_unref (d->node); 854#endif 855 channel [b->num*NCHAN + c->num] = 0; 856 c->sys = 0; |
764 contigfree (d, sizeof (*d), M_DEVBUF); | 857 cx_bus_dma_mem_free (&d->dmamem); |
765 continue; 766 } 767 d->lo_queue.ifq_maxlen = IFQ_MAXLEN; 768 d->hi_queue.ifq_maxlen = IFQ_MAXLEN; 769#if __FreeBSD_version >= 500000 770 mtx_init (&d->lo_queue.ifq_mtx, "cx_queue_lo", NULL, MTX_DEF); 771 mtx_init (&d->hi_queue.ifq_mtx, "cx_queue_hi", NULL, MTX_DEF); 772#endif --- 15 unchanged lines hidden (view full) --- 788 if_attach (&d->pp.pp_if); 789 d->pp.pp_tlf = cx_tlf; 790 d->pp.pp_tls = cx_tls; 791 /* If BPF is in the kernel, call the attach for it. 792 * Size of PPP header is 4 bytes. */ 793 bpfattach (&d->pp.pp_if, DLT_PPP, 4); 794#endif /*NETGRAPH*/ 795 } | 858 continue; 859 } 860 d->lo_queue.ifq_maxlen = IFQ_MAXLEN; 861 d->hi_queue.ifq_maxlen = IFQ_MAXLEN; 862#if __FreeBSD_version >= 500000 863 mtx_init (&d->lo_queue.ifq_mtx, "cx_queue_lo", NULL, MTX_DEF); 864 mtx_init (&d->hi_queue.ifq_mtx, "cx_queue_hi", NULL, MTX_DEF); 865#endif --- 15 unchanged lines hidden (view full) --- 881 if_attach (&d->pp.pp_if); 882 d->pp.pp_tlf = cx_tlf; 883 d->pp.pp_tls = cx_tls; 884 /* If BPF is in the kernel, call the attach for it. 885 * Size of PPP header is 4 bytes. */ 886 bpfattach (&d->pp.pp_if, DLT_PPP, 4); 887#endif /*NETGRAPH*/ 888 } |
796 cx_start_chan (c, &d->buf, vtophys (&d->buf)); | 889 cx_start_chan (c, d->dmamem.virt, d->dmamem.phys); |
797 cx_register_receive (c, &cx_receive); 798 cx_register_transmit (c, &cx_transmit); 799 cx_register_error (c, &cx_error); 800 cx_register_modem (c, &cx_modem); 801 dnmt[3] = 'x'+b->num; 802 dnmc[3] = 'x'+b->num; 803 d->devt[0] = make_dev (&cx_cdevsw, b->num*NCHAN + c->num, UID_ROOT, GID_WHEEL, 0644, dnmt, b->num*NCHAN + c->num); 804 d->devt[1] = make_dev (&cx_cdevsw, b->num*NCHAN + c->num + 64, UID_ROOT, GID_WHEEL, 0600, "cx%d", b->num*NCHAN + c->num); --- 109 unchanged lines hidden (view full) --- 914 s = splhigh (); 915 for (c = b->chan; c < b->chan + NCHAN; ++c) { 916 drv_t *d = (drv_t*) c->sys; 917 918 if (!d || d->chan->type == T_NONE) 919 continue; 920 921 /* Deallocate buffers. */ | 890 cx_register_receive (c, &cx_receive); 891 cx_register_transmit (c, &cx_transmit); 892 cx_register_error (c, &cx_error); 893 cx_register_modem (c, &cx_modem); 894 dnmt[3] = 'x'+b->num; 895 dnmc[3] = 'x'+b->num; 896 d->devt[0] = make_dev (&cx_cdevsw, b->num*NCHAN + c->num, UID_ROOT, GID_WHEEL, 0644, dnmt, b->num*NCHAN + c->num); 897 d->devt[1] = make_dev (&cx_cdevsw, b->num*NCHAN + c->num + 64, UID_ROOT, GID_WHEEL, 0600, "cx%d", b->num*NCHAN + c->num); --- 109 unchanged lines hidden (view full) --- 1007 s = splhigh (); 1008 for (c = b->chan; c < b->chan + NCHAN; ++c) { 1009 drv_t *d = (drv_t*) c->sys; 1010 1011 if (!d || d->chan->type == T_NONE) 1012 continue; 1013 1014 /* Deallocate buffers. */ |
922 contigfree (d, sizeof (*d), M_DEVBUF); | 1015 cx_bus_dma_mem_free (&d->dmamem); |
923 } 924 bd->board = 0; 925 adapter [b->num] = 0; 926 free (b, M_DEVBUF); 927 splx (s); 928 929 return 0; 930} --- 1879 unchanged lines hidden (view full) --- 2810 .version = NG_ABI_VERSION, 2811 .name = NG_CX_NODE_TYPE, 2812 .constructor = ng_cx_constructor, 2813 .rcvmsg = ng_cx_rcvmsg, 2814 .shutdown = ng_cx_rmnode, 2815 .newhook = ng_cx_newhook, 2816 .connect = ng_cx_connect, 2817 .rcvdata = ng_cx_rcvdata, | 1016 } 1017 bd->board = 0; 1018 adapter [b->num] = 0; 1019 free (b, M_DEVBUF); 1020 splx (s); 1021 1022 return 0; 1023} --- 1879 unchanged lines hidden (view full) --- 2903 .version = NG_ABI_VERSION, 2904 .name = NG_CX_NODE_TYPE, 2905 .constructor = ng_cx_constructor, 2906 .rcvmsg = ng_cx_rcvmsg, 2907 .shutdown = ng_cx_rmnode, 2908 .newhook = ng_cx_newhook, 2909 .connect = ng_cx_connect, 2910 .rcvdata = ng_cx_rcvdata, |
2818 .disconnect = ng_cx_disconnect | 2911 .disconnect = ng_cx_disconnect, |
2819}; | 2912}; |
2820 | |
2821#endif /*NETGRAPH*/ 2822 2823#if __FreeBSD_version >= 500000 2824#ifdef NETGRAPH 2825MODULE_DEPEND (ng_cx, netgraph, NG_ABI_VERSION, NG_ABI_VERSION, NG_ABI_VERSION); 2826#else 2827MODULE_DEPEND (isa_cx, sppp, 1, 1, 1); 2828#endif --- 13 unchanged lines hidden --- | 2913#endif /*NETGRAPH*/ 2914 2915#if __FreeBSD_version >= 500000 2916#ifdef NETGRAPH 2917MODULE_DEPEND (ng_cx, netgraph, NG_ABI_VERSION, NG_ABI_VERSION, NG_ABI_VERSION); 2918#else 2919MODULE_DEPEND (isa_cx, sppp, 1, 1, 1); 2920#endif --- 13 unchanged lines hidden --- |