1 /*****************************************************************************
2 * wanpipe.h WANPIPE(tm) Multiprotocol WAN Link Driver.
3 * User-level API definitions.
5 * Author: Nenad Corbic <ncorbic@sangoma.com>
8 * Copyright: (c) 1995-2000 Sangoma Technologies Inc.
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
14 * ============================================================================
15 * Nov 3, 2000 Nenad Corbic Added config_id to sdla_t structure.
16 * Used to determine the protocol running.
17 * Jul 13, 2000 Nenad Corbic Added SyncPPP Support
18 * Feb 24, 2000 Nenad Corbic Added support for x25api driver
19 * Oct 04, 1999 Nenad Corbic New CHDLC and FRAME RELAY code, SMP support
20 * Jun 02, 1999 Gideon Hack Added 'update_call_count' for Cisco HDLC
22 * Jun 26, 1998 David Fong Added 'ip_mode' in sdla_t.u.p for dynamic IP
23 * routing mode configuration
24 * Jun 12, 1998 David Fong Added Cisco HDLC union member in sdla_t
25 * Dec 08, 1997 Jaspreet Singh Added 'authenticator' in union of 'sdla_t'
26 * Nov 26, 1997 Jaspreet Singh Added 'load_sharing' structure. Also added
27 * 'devs_struct','dev_to_devtint_next' to 'sdla_t'
28 * Nov 24, 1997 Jaspreet Singh Added 'irq_dis_if_send_count',
29 * 'irq_dis_poll_count' to 'sdla_t'.
30 * Nov 06, 1997 Jaspreet Singh Added a define called 'INTR_TEST_MODE'
31 * Oct 20, 1997 Jaspreet Singh Added 'buff_intr_mode_unbusy' and
32 * 'dlci_intr_mode_unbusy' to 'sdla_t'
33 * Oct 18, 1997 Jaspreet Singh Added structure to maintain global driver
35 * Jan 15, 1997 Gene Kozin Version 3.1.0
36 * o added UDP management stuff
37 * Jan 02, 1997 Gene Kozin Version 3.0.0
38 *****************************************************************************/
42 #include <linux/version.h>
44 #ifndef KERNEL_VERSION
45 #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
48 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
51 #define netdevice_t struct net_device
56 #define stop_net_queue(a) netif_stop_queue(a)
57 #define start_net_queue(a) netif_start_queue(a)
58 #define is_queue_stopped(a) netif_queue_stopped(a)
59 #define wake_net_dev(a) netif_wake_queue(a)
60 #define is_dev_running(a) netif_running(a)
61 #define wan_dev_kfree_skb(a,b) dev_kfree_skb_any(a)
64 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,0)
67 #define netdevice_t struct device
71 #define stop_net_queue(a) (set_bit(0, &##a->tbusy))
72 #define start_net_queue(a) (clear_bit(0,&##a->tbusy))
73 #define is_queue_stopped(a) (##a->tbusy)
74 #define wake_net_dev(a) {clear_bit(0,&##a->tbusy);mark_bh(NET_BH);}
75 #define is_dev_running(a) (test_bit(0,&##a->start))
76 #define wan_dev_kfree_skb(a,b) dev_kfree_skb(a)
80 #define netdevice_t struct device
82 #define test_and_set_bit set_bit
83 #define net_ratelimit() 1
85 #define stop_net_queue(a) (set_bit(0, &##a->tbusy))
86 #define start_net_queue(a) (clear_bit(0,&##a->tbusy))
87 #define is_queue_stopped(a) (##a->tbusy)
88 #define wake_net_dev(a) {clear_bit(0,&##a->tbusy);mark_bh(NET_BH);}
89 #define is_dev_running(a) (test_bit(0,(void*)&##a->start))
90 #define wan_dev_kfree_skb(a,b) dev_kfree_skb(a,b)
91 #define spin_lock_init(a)
93 #define spin_unlock(a)
96 #include <linux/wanrouter.h>
101 #define PACKED __attribute__((packed))
104 #define WANPIPE_MAGIC 0x414C4453L /* signature: 'SDLA' reversed */
106 /* IOCTL numbers (up to 16) */
107 #define WANPIPE_DUMP (ROUTER_USER+0) /* dump adapter's memory */
108 #define WANPIPE_EXEC (ROUTER_USER+1) /* execute firmware command */
110 #define TRACE_ALL 0x00
111 #define TRACE_PROT 0x01
112 #define TRACE_DATA 0x02
114 /* values for request/reply byte */
115 #define UDPMGMT_REQUEST 0x01
116 #define UDPMGMT_REPLY 0x02
117 #define UDP_OFFSET 12
119 #define MAX_CMD_BUFF 10
120 #define MAX_X25_LCN 255 /* Maximum number of x25 channels */
121 #define MAX_LCN_NUM 4095 /* Maximum lcn number */
122 #define MAX_FT1_RETRY 100
126 #define AF_WANPIPE 25
128 #define PF_WANPIPE AF_WANPIPE
134 #define AF_WANPIPE 24
136 #define PF_WANPIPE AF_WANPIPE
142 #define TX_TIMEOUT 5*HZ
144 /* General Critical Flags */
145 #define SEND_CRIT 0x00
146 #define PERI_CRIT 0x01
148 /* Chdlc and PPP polling critical flag */
149 #define POLL_CRIT 0x03
151 /* Frame Relay Tx IRQ send critical flag */
152 #define SEND_TXIRQ_CRIT 0x02
154 /* Frame Relay ARP critical flag */
155 #define ARP_CRIT 0x03
157 /* Bit maps for dynamic interface configuration
158 * DYN_OPT_ON : turns this option on/off
159 * DEV_DOWN : device was shutdown by the driver not
162 #define DYN_OPT_ON 0x00
163 #define DEV_DOWN 0x01
166 * Data structures for IOCTL calls.
169 typedef struct sdla_dump /* WANPIPE_DUMP */
171 unsigned long magic; /* for verification */
172 unsigned long offset; /* absolute adapter memory address */
173 unsigned long length; /* block length */
174 void* ptr; /* -> buffer */
177 typedef struct sdla_exec /* WANPIPE_EXEC */
179 unsigned long magic; /* for verification */
180 void* cmd; /* -> command structure */
181 void* data; /* -> data buffer */
184 /* UDP management stuff */
186 typedef struct wum_header
188 unsigned char signature[8]; /* 00h: signature */
189 unsigned char type; /* 08h: request/reply */
190 unsigned char command; /* 09h: commnand */
191 unsigned char reserved[6]; /* 0Ah: reserved */
194 /*************************************************************************
195 Data Structure for global statistics
196 *************************************************************************/
198 typedef struct global_stats
200 unsigned long isr_entry;
201 unsigned long isr_already_critical;
202 unsigned long isr_rx;
203 unsigned long isr_tx;
204 unsigned long isr_intr_test;
205 unsigned long isr_spurious;
206 unsigned long isr_enable_tx_int;
207 unsigned long rx_intr_corrupt_rx_bfr;
208 unsigned long rx_intr_on_orphaned_DLCI;
209 unsigned long rx_intr_dev_not_started;
210 unsigned long tx_intr_dev_not_started;
211 unsigned long poll_entry;
212 unsigned long poll_already_critical;
213 unsigned long poll_processed;
214 unsigned long poll_tbusy_bad_status;
215 unsigned long poll_host_disable_irq;
216 unsigned long poll_host_enable_irq;
222 unsigned short udp_src_port PACKED;
223 unsigned short udp_dst_port PACKED;
224 unsigned short udp_length PACKED;
225 unsigned short udp_checksum PACKED;
230 unsigned char ver_inet_hdr_length;
231 unsigned char service_type;
232 unsigned short total_length PACKED;
233 unsigned short identifier PACKED;
234 unsigned short flags_frag_offset PACKED;
236 unsigned char protocol;
237 unsigned short hdr_checksum PACKED;
238 unsigned long ip_src_address PACKED;
239 unsigned long ip_dst_address PACKED;
244 unsigned char signature[8];
245 unsigned char request_reply;
247 unsigned char reserved[6];
250 /*************************************************************************
251 Data Structure for if_send statistics
252 *************************************************************************/
253 typedef struct if_send_stat{
254 unsigned long if_send_entry;
255 unsigned long if_send_skb_null;
256 unsigned long if_send_broadcast;
257 unsigned long if_send_multicast;
258 unsigned long if_send_critical_ISR;
259 unsigned long if_send_critical_non_ISR;
260 unsigned long if_send_tbusy;
261 unsigned long if_send_tbusy_timeout;
262 unsigned long if_send_PIPE_request;
263 unsigned long if_send_wan_disconnected;
264 unsigned long if_send_dlci_disconnected;
265 unsigned long if_send_no_bfrs;
266 unsigned long if_send_adptr_bfrs_full;
267 unsigned long if_send_bfr_passed_to_adptr;
268 unsigned long if_send_protocol_error;
269 unsigned long if_send_bfr_not_passed_to_adptr;
270 unsigned long if_send_tx_int_enabled;
271 unsigned long if_send_consec_send_fail;
274 typedef struct rx_intr_stat{
275 unsigned long rx_intr_no_socket;
276 unsigned long rx_intr_dev_not_started;
277 unsigned long rx_intr_PIPE_request;
278 unsigned long rx_intr_bfr_not_passed_to_stack;
279 unsigned long rx_intr_bfr_passed_to_stack;
282 typedef struct pipe_mgmt_stat{
283 unsigned long UDP_PIPE_mgmt_kmalloc_err;
284 unsigned long UDP_PIPE_mgmt_direction_err;
285 unsigned long UDP_PIPE_mgmt_adptr_type_err;
286 unsigned long UDP_PIPE_mgmt_adptr_cmnd_OK;
287 unsigned long UDP_PIPE_mgmt_adptr_cmnd_timeout;
288 unsigned long UDP_PIPE_mgmt_adptr_send_passed;
289 unsigned long UDP_PIPE_mgmt_adptr_send_failed;
290 unsigned long UDP_PIPE_mgmt_not_passed_to_stack;
291 unsigned long UDP_PIPE_mgmt_passed_to_stack;
292 unsigned long UDP_PIPE_mgmt_no_socket;
293 unsigned long UDP_PIPE_mgmt_passed_to_adptr;
299 } bh_data_t, cmd_data_t;
301 #define MAX_LGTH_UDP_MGNT_PKT 2000
304 /* This is used for interrupt testing */
305 #define INTR_TEST_MODE 0x02
307 #define WUM_SIGNATURE_L 0x50495046
308 #define WUM_SIGNATURE_H 0x444E3845
310 #define WUM_KILL 0x50
311 #define WUM_EXEC 0x51
316 #define BRIDGE_NODE 0x03
319 /****** Kernel Interface ****************************************************/
321 #include <linux/sdladrv.h> /* SDLA support module API definitions */
322 #include <linux/sdlasfm.h> /* SDLA firmware module definitions */
323 #include <linux/tqueue.h>
325 #include <linux/serial.h>
326 #include <linux/serialP.h>
327 #include <linux/serial_reg.h>
328 #include <asm/serial.h>
330 #include <linux/tty.h>
331 #include <linux/tty_driver.h>
332 #include <linux/tty_flip.h>
335 #define is_digit(ch) (((ch)>=(unsigned)'0'&&(ch)<=(unsigned)'9')?1:0)
336 #define is_alpha(ch) ((((ch)>=(unsigned)'a'&&(ch)<=(unsigned)'z')||\
337 ((ch)>=(unsigned)'A'&&(ch)<=(unsigned)'Z'))?1:0)
338 #define is_hex_digit(ch) ((((ch)>=(unsigned)'0'&&(ch)<=(unsigned)'9')||\
339 ((ch)>=(unsigned)'a'&&(ch)<=(unsigned)'f')||\
340 ((ch)>=(unsigned)'A'&&(ch)<=(unsigned)'F'))?1:0)
343 /****** Data Structures *****************************************************/
345 /* Adapter Data Space.
346 * This structure is needed because we handle multiple cards, otherwise
347 * static data would do it.
351 char devname[WAN_DRVNAME_SZ+1]; /* card name */
352 sdlahw_t hw; /* hardware configuration */
353 wan_device_t wandev; /* WAN device data space */
355 unsigned open_cnt; /* number of open interfaces */
356 unsigned long state_tick; /* link state timestamp */
357 unsigned intr_mode; /* Type of Interrupt Mode */
358 char in_isr; /* interrupt-in-service flag */
359 char buff_int_mode_unbusy; /* flag for carrying out dev_tint */
360 char dlci_int_mode_unbusy; /* flag for carrying out dev_tint */
361 char configured; /* flag for previous configurations */
363 unsigned short irq_dis_if_send_count; /* Disabling irqs in if_send*/
364 unsigned short irq_dis_poll_count; /* Disabling irqs in poll routine*/
365 unsigned short force_enable_irq;
366 char TracingEnabled; /* flag for enabling trace */
367 global_stats_t statistics; /* global statistics */
368 void* mbox; /* -> mailbox */
369 void* rxmb; /* -> receive mailbox */
370 void* flags; /* -> adapter status flags */
371 void (*isr)(struct sdla* card); /* interrupt service routine */
372 void (*poll)(struct sdla* card); /* polling routine */
373 int (*exec)(struct sdla* card, void* u_cmd, void* u_data);
374 /* Used by the listen() system call */
375 /* Wanpipe Socket Interface */
376 int (*func) (struct sk_buff *, struct sock *);
379 /* Shutdown function */
380 void (*disable_comm) (struct sdla *card);
382 /* Secondary Port Device: Piggibacking */
385 /* TTY driver variables */
386 unsigned char tty_opt;
387 struct tty_struct *tty;
388 unsigned int tty_minor;
389 unsigned int tty_open;
390 unsigned char *tty_buf;
391 unsigned char *tty_rx;
392 struct tq_struct tty_task_queue;
397 { /****** X.25 specific data **********/
402 netdevice_t *svc_to_dev_map[MAX_X25_LCN];
403 netdevice_t *pvc_to_dev_map[MAX_X25_LCN];
405 netdevice_t *cmd_dev;
407 volatile u8 *hdlc_buf_status;
408 u32 tx_interrupts_pending;
409 u16 timer_int_enabled;
410 netdevice_t *poll_device;
411 atomic_t command_busy;
417 netdevice_t * udp_dev;
418 s8 udp_pkt_data[MAX_LGTH_UDP_MGNT_PKT];
420 u8 LAPB_hdlc; /* Option to turn off X25 and run only LAPB */
421 u8 logging; /* Option to log call messages */
422 u8 oob_on_modem; /* Option to send modem status to the api */
423 u16 num_of_ch; /* Number of channels configured by the user */
425 struct tq_struct x25_poll_task;
426 struct timer_list x25_timer;
429 { /****** frame relay specific data ***/
430 void* rxmb_base; /* -> first Rx buffer */
431 void* rxmb_last; /* -> last Rx buffer */
432 unsigned rx_base; /* S508 receive buffer base */
433 unsigned rx_top; /* S508 receive buffer end */
434 unsigned short node_dlci[100];
435 unsigned short dlci_num;
436 netdevice_t *dlci_to_dev_map[991 + 1];
437 unsigned tx_interrupts_pending;
438 unsigned short timer_int_enabled;
439 unsigned short udp_pkt_lgth;
443 char udp_pkt_data[MAX_LGTH_UDP_MGNT_PKT];
444 void* trc_el_base; /* first trace element */
445 void* trc_el_last; /* last trace element */
446 void *curr_trc_el; /* current trace element */
447 unsigned short trc_bfr_space; /* trace buffer space */
448 unsigned char update_comms_stats;
449 netdevice_t *arp_dev;
450 spinlock_t if_send_lock;
452 struct /****** PPP-specific data ***********/
454 char if_name[WAN_IFNAME_SZ+1]; /* interface name */
455 void* txbuf; /* -> current Tx buffer */
456 void* txbuf_base; /* -> first Tx buffer */
457 void* txbuf_last; /* -> last Tx buffer */
458 void* rxbuf_base; /* -> first Rx buffer */
459 void* rxbuf_last; /* -> last Rx buffer */
460 unsigned rx_base; /* S508 receive buffer base */
461 unsigned rx_top; /* S508 receive buffer end */
462 char ip_mode; /* STATIC/HOST/PEER IP Mode */
463 char authenticator; /* Authenticator for PAP/CHAP */
464 unsigned char comm_enabled; /* Is comm enabled or not */
465 unsigned char peer_route; /* Process Peer Route */
466 unsigned long *txbuf_next; /* Next Tx buffer to use */
467 unsigned long *rxbuf_next; /* Next Rx buffer to use */
469 struct /* Cisco HDLC-specific data */
471 char if_name[WAN_IFNAME_SZ+1]; /* interface name */
472 unsigned char comm_port;/* Communication Port O or 1 */
473 unsigned char usedby; /* Used by WANPIPE or API */
474 void* rxmb; /* Receive mail box */
475 void* flags; /* flags */
476 void* tx_status; /* Tx status element */
477 void* rx_status; /* Rx status element */
478 void* txbuf; /* -> current Tx buffer */
479 void* txbuf_base; /* -> first Tx buffer */
480 void* txbuf_last; /* -> last Tx buffer */
481 void* rxbuf_base; /* -> first Rx buffer */
482 void* rxbuf_last; /* -> last Rx buffer */
483 unsigned rx_base; /* S508 receive buffer base */
484 unsigned rx_top; /* S508 receive buffer end */
485 unsigned char receive_only; /* high speed receivers */
486 unsigned short protocol_options;
487 unsigned short kpalv_tx; /* Tx kpalv timer */
488 unsigned short kpalv_rx; /* Rx kpalv timer */
489 unsigned short kpalv_err; /* Error tolerance */
490 unsigned short slarp_timer; /* SLARP req timer */
491 unsigned state; /* state of the link */
492 unsigned char api_status;
493 unsigned char update_call_count;
494 unsigned short api_options; /* for async config */
495 unsigned char async_mode;
496 unsigned short tx_bits_per_char;
497 unsigned short rx_bits_per_char;
498 unsigned short stop_bits;
499 unsigned short parity;
500 unsigned short break_timer;
501 unsigned short inter_char_timer;
502 unsigned short rx_complete_length;
503 unsigned short xon_char;
504 unsigned short xoff_char;
505 unsigned char comm_enabled; /* Is comm enabled or not */
506 unsigned char backup;
510 void* tx_status; /* Tx status element */
511 void* rx_status; /* Rx status element */
512 void* trace_status; /* Trace status element */
513 void* txbuf; /* -> current Tx buffer */
514 void* txbuf_base; /* -> first Tx buffer */
515 void* txbuf_last; /* -> last Tx buffer */
516 void* rxbuf_base; /* -> first Rx buffer */
517 void* rxbuf_last; /* -> last Rx buffer */
518 void* tracebuf; /* -> current Trace buffer */
519 void* tracebuf_base; /* -> current Trace buffer */
520 void* tracebuf_last; /* -> current Trace buffer */
521 unsigned rx_base; /* receive buffer base */
522 unsigned rx_end; /* receive buffer end */
523 unsigned trace_base; /* trace buffer base */
524 unsigned trace_end; /* trace buffer end */
530 /****** Public Functions ****************************************************/
532 void wanpipe_open (sdla_t* card); /* wpmain.c */
533 void wanpipe_close (sdla_t* card); /* wpmain.c */
534 void wanpipe_set_state (sdla_t* card, int state); /* wpmain.c */
536 int wpx_init (sdla_t* card, wandev_conf_t* conf); /* wpx.c */
537 int wpf_init (sdla_t* card, wandev_conf_t* conf); /* wpf.c */
538 int wpp_init (sdla_t* card, wandev_conf_t* conf); /* wpp.c */
539 int wpc_init (sdla_t* card, wandev_conf_t* conf); /* Cisco HDLC */
540 int bsc_init (sdla_t* card, wandev_conf_t* conf); /* BSC streaming */
541 int hdlc_init(sdla_t* card, wandev_conf_t* conf); /* HDLC support */
542 int wpft1_init (sdla_t* card, wandev_conf_t* conf); /* FT1 Config support */
543 int wsppp_init (sdla_t* card, wandev_conf_t* conf); /* Sync PPP on top of RAW CHDLC */
545 extern sdla_t * wanpipe_find_card(char *);
546 extern sdla_t * wanpipe_find_card_num (int);
548 extern void wanpipe_queue_tq (struct tq_struct *);
549 extern void wanpipe_mark_bh (void);
550 extern void wakeup_sk_bh (netdevice_t *);
551 extern int change_dev_flags (netdevice_t *, unsigned);
552 extern unsigned long get_ip_address (netdevice_t *dev, int option);
553 extern void add_gateway(sdla_t *, netdevice_t *);
556 #endif /* __KERNEL__ */
557 #endif /* _WANPIPE_H */