1 /* $Id: tpam.h,v 1.1.2.3 2001/11/06 20:58:30 kai Exp $
3 * Turbo PAM ISDN driver for Linux. (Kernel Driver)
5 * Copyright 2001 Stelian Pop <stelian.pop@fr.alcove.com>, AlcĂ´ve
7 * This software may be used and distributed according to the terms
8 * of the GNU General Public License, incorporated herein by reference.
10 * For all support questions please contact: <support@auvertech.fr>
17 //#define DEBUG /* uncomment if you want debugging output */
18 #include <linux/kernel.h>
19 #include <linux/isdnif.h>
20 #include <linux/init.h>
21 #include <linux/workqueue.h>
22 #include <linux/interrupt.h>
24 /* Maximum number of channels for this board */
25 #define TPAM_NBCHANNEL 30
26 /* Maximum size of data */
27 #define TPAM_MAXBUFSIZE 2032
28 /* Size of a page of board memory */
29 #define TPAM_PAGE_SIZE 0x003ffffc /* 4 MB */
30 /* Magic number present if the board was successfully started */
31 #define TPAM_MAGICNUMBER 0x2a343242
33 /* Registers in the PCI BAR0 */
34 #define TPAM_PAGE_REGISTER 0x00400000 /* Select page */
35 #define TPAM_DSPINT_REGISTER 0x00400004 /* Interrupt board */
36 #define TPAM_RESETPAM_REGISTER 0x00400008 /* Reset board */
37 #define TPAM_HINTACK_REGISTER 0x0040000c /* Ack interrupt */
38 #define TPAM_HPIC_REGISTER 0x00400014 /* Board ready */
40 /* Registers in the board memory */
41 #define TPAM_MAGICNUMBER_REGISTER 0x80008000 /* Magic number */
42 #define TPAM_EXID_REGISTER 0x80008004 /* EXID - not used */
43 #define TPAM_UPLOADPTR_REGISTER 0x80008008 /* Upload data ptr */
44 #define TPAM_DOWNLOADPTR_REGISTER 0x8000800c /* Download data ptr */
45 #define TPAM_ACKUPLOAD_REGISTER 0x80008010 /* Ack upload */
46 #define TPAM_ACKDOWNLOAD_REGISTER 0x80008014 /* Ack download */
47 #define TPAM_INTERRUPTACK_REGISTER 0x80008018 /* Ack interrupt */
49 /* Reserved areas in the board memory */
50 #define TPAM_RESERVEDAREA1_START 0x00000000
51 #define TPAM_RESERVEDAREA1_END 0x003FFFFF
52 #define TPAM_RESERVEDAREA2_START 0x01C00000
53 #define TPAM_RESERVEDAREA2_END 0x01FFFFFF
54 #define TPAM_RESERVEDAREA3_START 0x04000000
55 #define TPAM_RESERVEDAREA3_END 0x7FFFFFFF
56 #define TPAM_RESERVEDAREA4_START 0x80010000
57 #define TPAM_RESERVEDAREA4_END 0xFFFFFFFF
60 #define TPAM_NCOID_INVALID 0xffff
61 /* channel number invalid */
62 #define TPAM_CHANNEL_INVALID 0xffff
64 /* Channel structure */
65 typedef struct tpam_channel {
66 int num; /* channel number */
67 struct tpam_card *card; /* channel's card */
68 u32 ncoid; /* ncoid */
69 u8 hdlc; /* hdlc mode (set by user level) */
70 u8 realhdlc; /* hdlc mode (negociated with peer) */
71 u32 hdlcshift; /* hdlc shift */
72 u8 readytoreceive; /* channel ready to receive data */
73 struct sk_buff_head sendq; /* Send queue */
77 typedef struct tpam_card {
78 struct tpam_card *next; /* next card in list */
79 unsigned int irq; /* IRQ used by this board */
80 void __iomem *bar0; /* ioremapped bar0 */
81 int id; /* id of the board */
82 isdn_if interface; /* isdn link-level pointer */
83 int channels_used; /* number of channels actually used */
84 int channels_tested; /* number of channels being tested */
85 u8 loopmode; /* board in looptest mode */
86 tpam_channel channels[TPAM_NBCHANNEL];/* channels tab */
87 int running; /* card is running */
88 int busy; /* waiting for ack from card */
89 int roundrobin; /* round robin between channels */
90 struct sk_buff_head sendq; /* send queue */
91 struct sk_buff_head recvq; /* receive queue */
92 struct work_struct send_tq; /* send task queue */
93 struct work_struct recv_tq; /* receive task queue */
94 spinlock_t lock; /* lock for the card */
97 /* Timeout waiting for signature to become available */
98 #define SIGNATURE_TIMEOUT (5*HZ)
99 /* Timeout waiting for receiving all the ACreateNCOCnf */
100 #define NCOCREATE_TIMEOUT (30*HZ)
102 /* Maximum size of the TLV block */
103 #define MPB_MAXIMUMBLOCKTLVSIZE 128
104 /* Maximum size of the data block */
105 #define MPB_MAXIMUMDATASIZE 4904
106 /* Maximum size of a phone number */
107 #define PHONE_MAXIMUMSIZE 32
109 /* Header for a sk_buff structure */
110 typedef struct skb_header {
111 u16 size; /* size of pci_mpb block + size of tlv block */
112 u16 data_size; /* size of the data block */
113 u16 ack; /* packet needs to send ack upon send */
114 u16 ack_size; /* size of data to be acknowledged upon send */
117 /* PCI message header structure */
118 typedef struct pci_mpb {
119 u16 exID; /* exID - not used */
120 u16 flags; /* flags - not used */
121 u32 errorCode; /* errorCode - not used */
122 u16 messageID; /* message ID - one of ID_XXX */
123 u16 maximumBlockTLVSize; /* MPB_MAXIMUMBLOCKTLVSIZE */
124 u16 actualBlockTLVSize; /* size of the tlv block */
125 u16 maximumDataSize; /* MPB_MAXIMUMDATASIZE */
126 u16 actualDataSize; /* size of the data block */
127 u16 dummy; /* padding */
130 /* Types of PCI messages */
131 #define ID_ACreateNCOReq 101
132 #define ID_ACreateNCOCnf 102
133 #define ID_ADestroyNCOReq 103
134 #define ID_ADestroyNCOCnf 104
135 #define ID_CConnectReq 203
136 #define ID_CConnectInd 204
137 #define ID_CConnectRsp 205
138 #define ID_CConnectCnf 206
139 #define ID_CDisconnectReq 207
140 #define ID_CDisconnectInd 208
141 #define ID_CDisconnectRsp 209
142 #define ID_CDisconnectCnf 210
143 #define ID_U3DataReq 307
144 #define ID_U3DataInd 308
145 #define ID_U3ReadyToReceiveInd 318
147 /* Parameters for the PCI message TLV block */
148 #define PAR_BearerCap 3
149 #define PAR_CalledNumber 7
150 #define PAR_CallingNumber 11
151 #define PAR_CauseToPUF 15
152 #define PAR_Cdirection 16
153 #define PAR_CompletionStatus 19
154 #define PAR_Facility 30
157 #define PAR_NCOType 50
158 #define PAR_ReadyFlag 55
159 #define PAR_U3Protocol 62
160 #define PAR_Udirection 64
162 /* Delayed statcallb structure */
163 typedef struct tpam_statcallb_data {
164 tpam_card *card; /* card issuing the statcallb */
165 struct timer_list *timer; /* timer launching the statcallb */
166 isdn_ctrl ctrl; /* isdn command */
167 } tpam_statcallb_data;
169 /* Function prototypes from tpam_main.c */
170 extern tpam_card *tpam_findcard(int);
171 extern u32 tpam_findchannel(tpam_card *, u32);
173 /* Function prototypes from tpam_memory.c */
174 extern void copy_to_pam_dword(tpam_card *, u32, u32);
175 extern void copy_to_pam(tpam_card *, u32, const void *, u32);
176 extern u32 copy_from_pam_dword(tpam_card *, u32);
177 extern void copy_from_pam(tpam_card *, void *, u32, u32);
178 extern int copy_from_pam_to_user(tpam_card *, void __user *, u32, u32);
179 extern int copy_from_user_to_pam(tpam_card *, u32, const void __user *, u32);
180 extern int tpam_verify_area(u32, u32);
182 /* Function prototypes from tpam_nco.c */
183 extern struct sk_buff *build_ACreateNCOReq(const u8 *);
184 extern struct sk_buff *build_ADestroyNCOReq(u32);
185 extern struct sk_buff *build_CConnectReq(u32, const u8 *, u8);
186 extern struct sk_buff *build_CConnectRsp(u32);
187 extern struct sk_buff *build_CDisconnectReq(u32);
188 extern struct sk_buff *build_CDisconnectRsp(u32);
189 extern struct sk_buff *build_U3DataReq(u32, void *, u16, u16, u16);
190 extern int parse_ACreateNCOCnf(struct sk_buff *, u8 *, u32 *);
191 extern int parse_ADestroyNCOCnf(struct sk_buff *, u8 *, u32 *);
192 extern int parse_CConnectCnf(struct sk_buff *, u32 *);
193 extern int parse_CConnectInd(struct sk_buff *, u32 *, u8 *, u8 *,
195 extern int parse_CDisconnectCnf(struct sk_buff *, u32 *, u32 *);
196 extern int parse_CDisconnectInd(struct sk_buff *, u32 *, u32 *);
197 extern int parse_U3ReadyToReceiveInd(struct sk_buff *, u32 *, u8 *);
198 extern int parse_U3DataInd(struct sk_buff *, u32 *, u8 **, u16 *);
200 /* Function prototypes from tpam_queues.c */
201 extern void tpam_enqueue(tpam_card *, struct sk_buff *);
202 extern void tpam_enqueue_data(tpam_channel *, struct sk_buff *);
203 extern irqreturn_t tpam_irq(int, void *, struct pt_regs *);
204 extern void tpam_recv_tq(tpam_card *);
205 extern void tpam_send_tq(tpam_card *);
207 /* Function prototypes from tpam_commands.c */
208 extern int tpam_command(isdn_ctrl *);
209 extern int tpam_writebuf_skb(int, int, int, struct sk_buff *);
210 extern void tpam_recv_ACreateNCOCnf(tpam_card *, struct sk_buff *);
211 extern void tpam_recv_ADestroyNCOCnf(tpam_card *, struct sk_buff *);
212 extern void tpam_recv_CConnectCnf(tpam_card *, struct sk_buff *);
213 extern void tpam_recv_CConnectInd(tpam_card *, struct sk_buff *);
214 extern void tpam_recv_CDisconnectInd(tpam_card *, struct sk_buff *);
215 extern void tpam_recv_CDisconnectCnf(tpam_card *, struct sk_buff *);
216 extern void tpam_recv_U3DataInd(tpam_card *, struct sk_buff *);
217 extern void tpam_recv_U3ReadyToReceiveInd(tpam_card *, struct sk_buff *);
219 /* Function prototypes from tpam_hdlc.c */
220 extern u32 tpam_hdlc_encode(u8 *, u8 *, u32 *, u32);
221 extern u32 tpam_hdlc_decode(u8 *, u8 *, u32);
223 /* Function prototypes from tpam_crcpc.c */
224 extern void init_CRC(void);
225 extern void hdlc_encode_modem(u8 *, u32, u8 *, u32 *);
226 extern void hdlc_no_accm_encode(u8 *, u32, u8 *, u32 *);
227 extern u32 hdlc_no_accm_decode(u8 *, u32);
229 #endif /* _TPAM_H_ */