1 /* $Id: hysdn_defs.h,v 1.1.4.1 2001/11/20 14:19:37 kai Exp $
2  *
3  * Linux driver for HYSDN cards
4  * global definitions and exported vars and functions.
5  *
6  * Author    Werner Cornelius (werner@titro.de) for Hypercope GmbH
7  * Copyright 1999 by Werner Cornelius (werner@titro.de)
8  *
9  * This software may be used and distributed according to the terms
10  * of the GNU General Public License, incorporated herein by reference.
11  *
12  */
13 
14 #ifndef HYSDN_DEFS_H
15 #define HYSDN_DEFS_H
16 
17 #include <linux/config.h>
18 #include <linux/hysdn_if.h>
19 #include <linux/interrupt.h>
20 #include <linux/tqueue.h>
21 #include <linux/skbuff.h>
22 
23 /****************************/
24 /* storage type definitions */
25 /****************************/
26 #define uchar unsigned char
27 #define uint unsigned int
28 #define ulong unsigned long
29 #define word unsigned short
30 
31 #include "ince1pc.h"
32 
33 #ifdef CONFIG_HYSDN_CAPI
34 #include <linux/capi.h>
35 #include "../avmb1/capicmd.h"
36 #include "../avmb1/capiutil.h"
37 #include "../avmb1/capilli.h"
38 
39 /***************************/
40 /*   CAPI-Profile values.  */
41 /***************************/
42 
43 #define GLOBAL_OPTION_INTERNAL_CONTROLLER 0x0001
44 #define GLOBAL_OPTION_EXTERNAL_CONTROLLER 0x0002
45 #define GLOBAL_OPTION_HANDSET             0x0004
46 #define GLOBAL_OPTION_DTMF                0x0008
47 #define GLOBAL_OPTION_SUPPL_SERVICES      0x0010
48 #define GLOBAL_OPTION_CHANNEL_ALLOCATION  0x0020
49 #define GLOBAL_OPTION_B_CHANNEL_OPERATION 0x0040
50 
51 #define B1_PROT_64KBIT_HDLC        0x0001
52 #define B1_PROT_64KBIT_TRANSPARENT 0x0002
53 #define B1_PROT_V110_ASYNCH        0x0004
54 #define B1_PROT_V110_SYNCH         0x0008
55 #define B1_PROT_T30                0x0010
56 #define B1_PROT_64KBIT_INV_HDLC    0x0020
57 #define B1_PROT_56KBIT_TRANSPARENT 0x0040
58 
59 #define B2_PROT_ISO7776            0x0001
60 #define B2_PROT_TRANSPARENT        0x0002
61 #define B2_PROT_SDLC               0x0004
62 #define B2_PROT_LAPD               0x0008
63 #define B2_PROT_T30                0x0010
64 #define B2_PROT_PPP                0x0020
65 #define B2_PROT_TRANSPARENT_IGNORE_B1_FRAMING_ERRORS 0x0040
66 
67 #define B3_PROT_TRANSPARENT        0x0001
68 #define B3_PROT_T90NL              0x0002
69 #define B3_PROT_ISO8208            0x0004
70 #define B3_PROT_X25_DCE            0x0008
71 #define B3_PROT_T30                0x0010
72 #define B3_PROT_T30EXT             0x0020
73 
74 #define HYSDN_MAXVERSION		8
75 
76 /* Number of sendbuffers in CAPI-queue */
77 #define HYSDN_MAX_CAPI_SKB             20
78 
79 #endif /* CONFIG_HYSDN_CAPI*/
80 
81 /************************************************/
82 /* constants and bits for debugging/log outputs */
83 /************************************************/
84 #define LOG_MAX_LINELEN 120
85 #define DEB_OUT_SYSLOG  0x80000000	/* output to syslog instead of proc fs */
86 #define LOG_MEM_ERR     0x00000001	/* log memory errors like kmalloc failure */
87 #define LOG_POF_OPEN    0x00000010	/* log pof open and close activities */
88 #define LOG_POF_RECORD  0x00000020	/* log pof record parser */
89 #define LOG_POF_WRITE   0x00000040	/* log detailed pof write operation */
90 #define LOG_POF_CARD    0x00000080	/* log pof related card functions */
91 #define LOG_CNF_LINE    0x00000100	/* all conf lines are put to procfs */
92 #define LOG_CNF_DATA    0x00000200	/* non comment conf lines are shown with channel */
93 #define LOG_CNF_MISC    0x00000400	/* additional conf line debug outputs */
94 #define LOG_SCHED_ASYN  0x00001000	/* debug schedulers async tx routines */
95 #define LOG_PROC_OPEN   0x00100000	/* open and close from procfs are logged */
96 #define LOG_PROC_ALL    0x00200000	/* all actions from procfs are logged */
97 #define LOG_NET_INIT    0x00010000	/* network init and deinit logging */
98 
99 #define DEF_DEB_FLAGS   0x7fff000f	/* everything is logged to procfs */
100 
101 /**********************************/
102 /* proc filesystem name constants */
103 /**********************************/
104 #define PROC_SUBDIR_NAME "hysdn"
105 #define PROC_CONF_BASENAME "cardconf"
106 #define PROC_LOG_BASENAME "cardlog"
107 
108 /***********************************/
109 /* PCI 32 bit parms for IO and MEM */
110 /***********************************/
111 #define PCI_REG_PLX_MEM_BASE    0
112 #define PCI_REG_PLX_IO_BASE     1
113 #define PCI_REG_MEMORY_BASE     3
114 
115 /**************/
116 /* card types */
117 /**************/
118 #define BD_NONE         0U
119 #define BD_PERFORMANCE  1U
120 #define BD_VALUE        2U
121 #define BD_PCCARD       3U
122 #define BD_ERGO         4U
123 #define BD_METRO        5U
124 #define BD_CHAMP2       6U
125 #define BD_PLEXUS       7U
126 
127 /******************************************************/
128 /* defined states for cards shown by reading cardconf */
129 /******************************************************/
130 #define CARD_STATE_UNUSED   0	/* never been used or booted */
131 #define CARD_STATE_BOOTING  1	/* booting is in progress */
132 #define CARD_STATE_BOOTERR  2	/* a previous boot was aborted */
133 #define CARD_STATE_RUN      3	/* card is active */
134 
135 /*******************************/
136 /* defines for error_log_state */
137 /*******************************/
138 #define ERRLOG_STATE_OFF   0	/* error log is switched off, nothing to do */
139 #define ERRLOG_STATE_ON    1	/* error log is switched on, wait for data */
140 #define ERRLOG_STATE_START 2	/* start error logging */
141 #define ERRLOG_STATE_STOP  3	/* stop error logging */
142 
143 /*******************************/
144 /* data structure for one card */
145 /*******************************/
146 typedef struct HYSDN_CARD {
147 
148 	/* general variables for the cards */
149 	int myid;		/* own driver card id */
150 	uchar bus;		/* pci bus the card is connected to */
151 	uchar devfn;		/* slot+function bit encoded */
152 	word subsysid;		/* PCI subsystem id */
153 	uchar brdtype;		/* type of card */
154 	uint bchans;		/* number of available B-channels */
155 	uint faxchans;		/* number of available fax-channels */
156 	uchar mac_addr[6];	/* MAC Address read from card */
157 	uint irq;		/* interrupt number */
158 	uint iobase;		/* IO-port base address */
159 	ulong plxbase;		/* PLX memory base */
160 	ulong membase;		/* DPRAM memory base */
161 	ulong memend;		/* DPRAM memory end */
162 	void *dpram;		/* mapped dpram */
163 	int state;		/* actual state of card -> CARD_STATE_** */
164 	struct HYSDN_CARD *next;	/* pointer to next card */
165 
166 	/* data areas for the /proc file system */
167 	void *proclog;		/* pointer to proclog filesystem specific data */
168 	void *procconf;		/* pointer to procconf filesystem specific data */
169 
170 	/* debugging and logging */
171 	uchar err_log_state;	/* actual error log state of the card */
172 	ulong debug_flags;	/* tells what should be debugged and where */
173 	void (*set_errlog_state) (struct HYSDN_CARD *, int);
174 
175 	/* interrupt handler + interrupt synchronisation */
176 	struct tq_struct irq_queue;	/* interrupt task queue */
177 	uchar volatile irq_enabled;	/* interrupt enabled if != 0 */
178 	uchar volatile hw_lock;	/* hardware is currently locked -> no access */
179 
180 	/* boot process */
181 	void *boot;		/* pointer to boot private data */
182 	int (*writebootimg) (struct HYSDN_CARD *, uchar *, ulong);
183 	int (*writebootseq) (struct HYSDN_CARD *, uchar *, int);
184 	int (*waitpofready) (struct HYSDN_CARD *);
185 	int (*testram) (struct HYSDN_CARD *);
186 
187 	/* scheduler for data transfer (only async parts) */
188 	uchar async_data[256];	/* async data to be sent (normally for config) */
189 	word volatile async_len;	/* length of data to sent */
190 	word volatile async_channel;	/* channel number for async transfer */
191 	int volatile async_busy;	/* flag != 0 sending in progress */
192 	int volatile net_tx_busy;	/* a network packet tx is in progress */
193 
194 	/* network interface */
195 	void *netif;		/* pointer to network structure */
196 
197 	/* init and deinit stopcard for booting, too */
198 	void (*stopcard) (struct HYSDN_CARD *);
199 	void (*releasehardware) (struct HYSDN_CARD *);
200 #ifdef CONFIG_HYSDN_CAPI
201 	struct hycapictrl_info {
202 		char cardname[32];
203 		spinlock_t lock;
204 		int versionlen;
205 		char versionbuf[1024];
206 		char *version[HYSDN_MAXVERSION];
207 
208 		char infobuf[128];	/* for function procinfo */
209 
210 		struct HYSDN_CARD  *card;
211 		struct capi_ctr *capi_ctrl;
212 		struct sk_buff *skbs[HYSDN_MAX_CAPI_SKB];
213 		int in_idx, out_idx;	/* indexes to buffer ring */
214 		int sk_count;		/* number of buffers currently in ring */
215 		struct sk_buff *tx_skb;	/* buffer for tx operation */
216 	} *hyctrlinfo;
217 #endif /* CONFIG_HYSDN_CAPI */
218 } hysdn_card;
219 
220 #ifdef CONFIG_HYSDN_CAPI
221 typedef struct hycapictrl_info hycapictrl_info;
222 #endif /* CONFIG_HYSDN_CAPI */
223 
224 
225 /*****************/
226 /* exported vars */
227 /*****************/
228 extern int cardmax;		/* number of found cards */
229 extern hysdn_card *card_root;	/* pointer to first card */
230 
231 
232 
233 /*************************/
234 /* im/exported functions */
235 /*************************/
236 extern int printk(const char *fmt,...);
237 extern char *hysdn_getrev(const char *);
238 
239 /* hysdn_procconf.c */
240 extern int hysdn_procconf_init(void);	/* init proc config filesys */
241 extern void hysdn_procconf_release(void);	/* deinit proc config filesys */
242 
243 /* hysdn_proclog.c */
244 extern int hysdn_proclog_init(hysdn_card *);	/* init proc log entry */
245 extern void hysdn_proclog_release(hysdn_card *);	/* deinit proc log entry */
246 extern void put_log_buffer(hysdn_card *, char *);	/* output log data */
247 extern void hysdn_addlog(hysdn_card *, char *,...);	/* output data to log */
248 extern void hysdn_card_errlog(hysdn_card *, tErrLogEntry *, int);	/* output card log */
249 
250 /* boardergo.c */
251 extern int ergo_inithardware(hysdn_card * card);	/* get hardware -> module init */
252 
253 /* hysdn_boot.c */
254 extern int pof_write_close(hysdn_card *);	/* close proc file after writing pof */
255 extern int pof_write_open(hysdn_card *, uchar **);	/* open proc file for writing pof */
256 extern int pof_write_buffer(hysdn_card *, int);		/* write boot data to card */
257 extern int EvalSysrTokData(hysdn_card *, uchar *, int);		/* Check Sysready Token Data */
258 
259 /* hysdn_sched.c */
260 extern int hysdn_sched_tx(hysdn_card *, uchar *, word volatile *, word volatile *,
261 			  word);
262 extern int hysdn_sched_rx(hysdn_card *, uchar *, word, word);
263 extern int hysdn_tx_cfgline(hysdn_card *, uchar *, word);	/* send one cfg line */
264 
265 /* hysdn_net.c */
266 extern unsigned int hynet_enable;
267 extern char *hysdn_net_revision;
268 extern int hysdn_net_create(hysdn_card *);	/* create a new net device */
269 extern int hysdn_net_release(hysdn_card *);	/* delete the device */
270 extern char *hysdn_net_getname(hysdn_card *);	/* get name of net interface */
271 extern void hysdn_tx_netack(hysdn_card *);	/* acknowledge a packet tx */
272 extern struct sk_buff *hysdn_tx_netget(hysdn_card *);	/* get next network packet */
273 extern void hysdn_rx_netpkt(hysdn_card *, uchar *, word);	/* rxed packet from network */
274 
275 #ifdef CONFIG_HYSDN_CAPI
276 extern unsigned int hycapi_enable;
277 extern struct capi_driver_interface *hy_di;
278 extern int hycapi_capi_create(hysdn_card *);	/* create a new capi device */
279 extern int hycapi_capi_release(hysdn_card *);	/* delete the device */
280 extern int hycapi_capi_stop(hysdn_card *card);   /* suspend */
281 extern int hycapi_load_firmware(struct capi_ctr *, capiloaddata *);
282 extern void hycapi_reset_ctr(struct capi_ctr *);
283 extern void hycapi_remove_ctr(struct capi_ctr *);
284 extern void hycapi_register_appl(struct capi_ctr *, __u16 appl,
285 				 capi_register_params *);
286 extern void hycapi_release_appl(struct capi_ctr *, __u16 appl);
287 extern void hycapi_send_message(struct capi_ctr *, struct sk_buff *skb);
288 extern char *hycapi_procinfo(struct capi_ctr *);
289 extern int hycapi_read_proc(char *page, char **start, off_t off,
290 			    int count, int *eof, struct capi_ctr *card);
291 extern void hycapi_rx_capipkt(hysdn_card * card, uchar * buf, word len);
292 extern void hycapi_tx_capiack(hysdn_card * card);
293 extern struct sk_buff *hycapi_tx_capiget(hysdn_card *card);
294 extern int hycapi_init(void);
295 extern void hycapi_cleanup(void);
296 #endif /* CONFIG_HYSDN_CAPI */
297 
298 #endif /* HYSDN_DEFS_H */
299