1 /* ISDN4BSD code */ 2 /* $NetBSD: iwicvar.h,v 1.2 2003/07/08 10:06:32 itojun Exp $ */ 3 4 /* 5 * Copyright (c) 1999, 2000 Dave Boyce. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29 #ifndef _IWICVAR_H_ 30 #define _IWICVAR_H_ 31 32 #include <netisdn/i4b_debug.h> 33 #include <netisdn/i4b_ioctl.h> 34 #include <netisdn/i4b_trace.h> 35 36 #include <netisdn/i4b_l2.h> 37 #include <netisdn/i4b_l1l2.h> 38 #include <netisdn/i4b_l3l4.h> 39 40 /*---------------------------------------------------------------------------* 41 * state of a B channel 42 *---------------------------------------------------------------------------*/ 43 struct iwic_bchan { 44 int channel; /* channel number */ 45 int offset; /* offset from iobase */ 46 int bprot; /* b channel protocol used */ 47 int state; /* transceiver state: */ 48 #define ST_IDLE 0x00 /* channel idle */ 49 #define ST_TX_ACTIVE 0x01 /* tx running */ 50 51 unsigned int sc_trace_bcount; 52 53 /* receive data from ISDN */ 54 55 struct ifqueue rx_queue;/* receiver queue */ 56 int rxcount; /* rx statistics counter */ 57 struct mbuf *in_mbuf; /* rx input buffer */ 58 u_char *in_cbptr; /* curr buffer pointer */ 59 int in_len; /* rx input buffer len */ 60 61 /* transmit data to ISDN */ 62 63 struct ifqueue tx_queue;/* transmitter queue */ 64 int txcount; /* tx statistics counter */ 65 struct mbuf *out_mbuf_head; /* first mbuf in possible chain */ 66 struct mbuf *out_mbuf_cur; /* current mbuf in possbl chain */ 67 unsigned char *out_mbuf_cur_ptr; /* data pointer into mbuf */ 68 int out_mbuf_cur_len; /* remaining bytes in mbuf */ 69 70 /* linktab */ 71 72 isdn_link_t iwic_isdn_linktab; 73 const struct isdn_l4_driver_functions *l4_driver; 74 void *l4_driver_softc; 75 }; 76 /*---------------------------------------------------------------------------* 77 * state of a D channel 78 *---------------------------------------------------------------------------*/ 79 struct iwic_dchan { 80 int enabled; 81 int trace_count; 82 struct mbuf *ibuf; 83 u_char *ibuf_ptr; /* Input buffer pointer */ 84 int ibuf_len; /* Current length of input buffer */ 85 int ibuf_max_len; /* Max length in input buffer */ 86 int rx_count; 87 88 int tx_ready; /* Can send next 64 bytes of data. */ 89 int tx_count; 90 91 struct mbuf *obuf; 92 int free_obuf; 93 u_char *obuf_ptr; 94 int obuf_len; 95 96 struct mbuf *obuf2; 97 int free_obuf2; 98 }; 99 /*---------------------------------------------------------------------------* 100 * state of one iwic unit 101 *---------------------------------------------------------------------------*/ 102 struct iwic_softc { 103 struct device sc_dev; 104 105 const char *sc_cardname; 106 107 bus_addr_t sc_iobase; 108 bus_size_t sc_iosize; 109 bus_space_handle_t sc_io_bh; 110 bus_space_tag_t sc_io_bt; 111 112 struct iwic_dchan sc_dchan; 113 struct iwic_bchan sc_bchan[2]; 114 115 void *sc_ih; /* interrupt handler */ 116 pci_chipset_tag_t sc_pc; 117 118 void *sc_l3token; /* pointer to registered L3 instance */ 119 struct l2_softc sc_l2; /* D-channel variables */ 120 121 int sc_I430state; 122 int sc_I430T3; 123 124 int sc_trace; 125 }; 126 /*---------------------------------------------------------------------------* 127 * rd/wr register/fifo macros 128 *---------------------------------------------------------------------------*/ 129 130 #include <machine/bus.h> 131 132 #define IWIC_READ(sc,reg) bus_space_read_1((sc)->sc_io_bt,(sc)->sc_io_bh,(reg)) 133 #define IWIC_WRITE(sc,reg,val) bus_space_write_1((sc)->sc_io_bt,(sc)->sc_io_bh,(reg),(val)) 134 #define IWIC_WRDFIFO(sc,p,l) bus_space_write_multi_1((sc)->sc_io_bt,(sc)->sc_io_bh,D_XFIFO,(p),(l)) 135 #define IWIC_RDDFIFO(sc,p,l) bus_space_read_multi_1((sc)->sc_io_bt,(sc)->sc_io_bh,D_RFIFO,(p),(l)) 136 #define IWIC_WRBFIFO(sc,b,p,l) bus_space_write_multi_1((sc)->sc_io_bt,(sc)->sc_io_bh,(b)->offset + B_XFIFO,(p),(l)) 137 #define IWIC_RDBFIFO(sc,b,p,l) bus_space_read_multi_1((sc)->sc_io_bt,(sc)->sc_io_bh,(b)->offset + B_RFIFO,(p),(l)) 138 139 /*---------------------------------------------------------------------------* 140 * possible I.430 states 141 *---------------------------------------------------------------------------*/ 142 enum I430states { 143 ST_F3N, /* F3 Deactivated, no clock */ 144 ST_F3, /* F3 Deactivated */ 145 ST_F4, /* F4 Awaiting Signal */ 146 ST_F5, /* F5 Identifying Input */ 147 ST_F6, /* F6 Synchronized */ 148 ST_F7, /* F7 Activated */ 149 ST_F8, /* F8 Lost Framing */ 150 ST_ILL, /* Illegal State */ 151 N_STATES 152 }; 153 /*---------------------------------------------------------------------------* 154 * possible I.430 events 155 *---------------------------------------------------------------------------*/ 156 enum I430events { 157 EV_PHAR, /* PH ACTIVATE REQUEST */ 158 EV_CE, /* Clock enabled */ 159 EV_T3, /* Timer 3 expired */ 160 EV_INFO0, /* receiving INFO0 */ 161 EV_RSY, /* receiving any signal */ 162 EV_INFO2, /* receiving INFO2 */ 163 EV_INFO48, /* receiving INFO4 pri 8/9 */ 164 EV_INFO410, /* receiving INFO4 pri 10/11 */ 165 EV_DR, /* Deactivate Request */ 166 EV_PU, /* Power UP */ 167 EV_DIS, /* Disconnected (only 2085) */ 168 EV_EI, /* Error Indication */ 169 EV_ILL, /* Illegal Event */ 170 N_EVENTS 171 }; 172 /*---------------------------------------------------------------------------* 173 * available commands 174 *---------------------------------------------------------------------------*/ 175 enum I430commands { 176 CMD_ECK, /* Enable clock */ 177 CMD_TIM, /* Timing */ 178 CMD_RT, /* Reset */ 179 CMD_AR8, /* Activation request pri 8 */ 180 CMD_AR10, /* Activation request pri 10 */ 181 CMD_DIU, /* Deactivate Indication Upstream */ 182 CMD_ILL /* Illegal command */ 183 }; 184 185 extern void iwic_init(struct iwic_softc *); 186 extern void iwic_next_state(struct iwic_softc *, int); 187 188 extern void iwic_dchan_init(struct iwic_softc *); 189 extern void iwic_dchan_xirq(struct iwic_softc *); 190 extern void iwic_dchan_xfer_irq(struct iwic_softc *, int); 191 extern void iwic_dchan_disable(struct iwic_softc *); 192 extern int iwic_dchan_data_req(struct iwic_softc *, struct mbuf *, int); 193 extern void iwic_dchan_transmit(struct iwic_softc *); 194 195 char *iwic_printstate(struct iwic_softc *); 196 197 void iwic_init_linktab(struct iwic_softc *); 198 void iwic_bchan_xirq(struct iwic_softc *, int); 199 void iwic_bchannel_setup(isdn_layer1token, int, int, int); 200 201 #endif /* _IWICVAR_H_ */ 202