OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [drivers/] [net/] [wan/] [sdla_ft1.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/*****************************************************************************
2
* sdla_chdlc.c  WANPIPE(tm) Multiprotocol WAN Link Driver. Cisco HDLC module.
3
*
4
* Authors:      Nenad Corbic <ncorbic@sangoma.com>
5
*               Gideon Hack
6
*
7
* Copyright:    (c) 1995-1999 Sangoma Technologies Inc.
8
*
9
*               This program is free software; you can redistribute it and/or
10
*               modify it under the terms of the GNU General Public License
11
*               as published by the Free Software Foundation; either version
12
*               2 of the License, or (at your option) any later version.
13
* ============================================================================
14
* Sep 30, 1999  Nenad Corbic    Fixed dynamic IP and route setup.
15
* Sep 23, 1999  Nenad Corbic    Added SMP support, fixed tracing
16
* Sep 13, 1999  Nenad Corbic    Split up Port 0 and 1 into separate devices.
17
* Jun 02, 1999  Gideon Hack     Added support for the S514 adapter.
18
* Oct 30, 1998  Jaspreet Singh  Added Support for CHDLC API (HDLC STREAMING).
19
* Oct 28, 1998  Jaspreet Singh  Added Support for Dual Port CHDLC.
20
* Aug 07, 1998  David Fong      Initial version.
21
*****************************************************************************/
22
 
23
#include <linux/module.h>
24
#include <linux/version.h>
25
#include <linux/kernel.h>       /* printk(), and other useful stuff */
26
#include <linux/stddef.h>       /* offsetof(), etc. */
27
#include <linux/errno.h>        /* return codes */
28
#include <linux/string.h>       /* inline memset(), etc. */
29
#include <linux/slab.h>         /* kmalloc(), kfree() */
30
#include <linux/wanrouter.h>    /* WAN router definitions */
31
#include <linux/wanpipe.h>      /* WANPIPE common user API definitions */
32
#include <linux/if_arp.h>       /* ARPHRD_* defines */
33
 
34
#include <linux/inetdevice.h>
35
#include <asm/uaccess.h>
36
 
37
#include <linux/in.h>           /* sockaddr_in */
38
#include <linux/inet.h> 
39
#include <linux/if.h>
40
#include <asm/byteorder.h>      /* htons(), etc. */
41
#include <linux/sdlapci.h>
42
#include <asm/io.h>
43
 
44
#include <linux/sdla_chdlc.h>           /* CHDLC firmware API definitions */
45
 
46
/****** Defines & Macros ****************************************************/
47
 
48
/* reasons for enabling the timer interrupt on the adapter */
49
#define TMR_INT_ENABLED_UDP     0x0001
50
#define TMR_INT_ENABLED_UPDATE  0x0002
51
 
52
#define CHDLC_DFLT_DATA_LEN     1500            /* default MTU */
53
#define CHDLC_HDR_LEN           1
54
 
55
#define IFF_POINTTOPOINT 0x10
56
 
57
#define WANPIPE 0x00
58
#define API     0x01
59
#define CHDLC_API 0x01
60
 
61
#define PORT(x)   (x == 0 ? "PRIMARY" : "SECONDARY" )
62
 
63
 
64
/******Data Structures*****************************************************/
65
 
66
/* This structure is placed in the private data area of the device structure.
67
 * The card structure used to occupy the private area but now the following
68
 * structure will incorporate the card structure along with CHDLC specific data
69
 */
70
 
71
typedef struct chdlc_private_area
72
{
73
        netdevice_t     *slave;
74
        sdla_t          *card;
75
        int             TracingEnabled;         /* For enabling Tracing */
76
        unsigned long   curr_trace_addr;        /* Used for Tracing */
77
        unsigned long   start_trace_addr;
78
        unsigned long   end_trace_addr;
79
        unsigned long   base_addr_trace_buffer;
80
        unsigned long   end_addr_trace_buffer;
81
        unsigned short  number_trace_elements;
82
        unsigned        available_buffer_space;
83
        unsigned long   router_start_time;
84
        unsigned char   route_status;
85
        unsigned char   route_removed;
86
        unsigned long   tick_counter;           /* For 5s timeout counter */
87
        unsigned long   router_up_time;
88
        u32             IP_address;             /* IP addressing */
89
        u32             IP_netmask;
90
        unsigned char  mc;                      /* Mulitcast support on/off */
91
        unsigned short udp_pkt_lgth;            /* udp packet processing */
92
        char udp_pkt_src;
93
        char udp_pkt_data[MAX_LGTH_UDP_MGNT_PKT];
94
        unsigned short timer_int_enabled;
95
        char update_comms_stats;                /* updating comms stats */
96
        //FIXME: add driver stats as per frame relay!
97
 
98
} chdlc_private_area_t;
99
 
100
/* Route Status options */
101
#define NO_ROUTE        0x00
102
#define ADD_ROUTE       0x01
103
#define ROUTE_ADDED     0x02
104
#define REMOVE_ROUTE    0x03
105
 
106
 
107
/****** Function Prototypes *************************************************/
108
/* WAN link driver entry points. These are called by the WAN router module. */
109
static int wpft1_exec (struct sdla *card, void *u_cmd, void *u_data);
110
static int chdlc_read_version (sdla_t* card, char* str);
111
static int chdlc_error (sdla_t *card, int err, CHDLC_MAILBOX_STRUCT *mb);
112
 
113
/****** Public Functions ****************************************************/
114
 
115
/*============================================================================
116
 * Cisco HDLC protocol initialization routine.
117
 *
118
 * This routine is called by the main WANPIPE module during setup.  At this
119
 * point adapter is completely initialized and firmware is running.
120
 *  o read firmware version (to make sure it's alive)
121
 *  o configure adapter
122
 *  o initialize protocol-specific fields of the adapter data space.
123
 *
124
 * Return:      0        o.k.
125
 *              < 0     failure.
126
 */
127
int wpft1_init (sdla_t* card, wandev_conf_t* conf)
128
{
129
        unsigned char port_num;
130
        int err;
131
 
132
        union
133
                {
134
                char str[80];
135
                } u;
136
        volatile CHDLC_MAILBOX_STRUCT* mb;
137
        CHDLC_MAILBOX_STRUCT* mb1;
138
        unsigned long timeout;
139
 
140
        /* Verify configuration ID */
141
        if (conf->config_id != WANCONFIG_CHDLC) {
142
                printk(KERN_INFO "%s: invalid configuration ID %u!\n",
143
                                  card->devname, conf->config_id);
144
                return -EINVAL;
145
        }
146
 
147
        /* Use primary port */
148
        card->u.c.comm_port = 0;
149
 
150
 
151
        /* Initialize protocol-specific fields */
152
        if(card->hw.type != SDLA_S514){
153
                card->mbox  = (void *) card->hw.dpmbase;
154
        }else{
155
                card->mbox = (void *) card->hw.dpmbase + PRI_BASE_ADDR_MB_STRUCT;
156
        }
157
 
158
        mb = mb1 = card->mbox;
159
 
160
        if (!card->configured){
161
 
162
                /* The board will place an 'I' in the return code to indicate that it is
163
                ready to accept commands.  We expect this to be completed in less
164
                than 1 second. */
165
 
166
                timeout = jiffies;
167
                while (mb->return_code != 'I')  /* Wait 1s for board to initialize */
168
                        if ((jiffies - timeout) > 1*HZ) break;
169
 
170
                if (mb->return_code != 'I') {
171
                        printk(KERN_INFO
172
                                "%s: Initialization not completed by adapter\n",
173
                                card->devname);
174
                        printk(KERN_INFO "Please contact Sangoma representative.\n");
175
                        return -EIO;
176
                }
177
        }
178
 
179
        /* Read firmware version.  Note that when adapter initializes, it
180
         * clears the mailbox, so it may appear that the first command was
181
         * executed successfully when in fact it was merely erased. To work
182
         * around this, we execute the first command twice.
183
         */
184
 
185
        if (chdlc_read_version(card, u.str))
186
                return -EIO;
187
 
188
        printk(KERN_INFO "%s: Running FT1 Configuration firmware v%s\n",
189
                card->devname, u.str);
190
 
191
        card->isr                       = NULL;
192
        card->poll                      = NULL;
193
        card->exec                      = &wpft1_exec;
194
        card->wandev.update             = NULL;
195
        card->wandev.new_if             = NULL;
196
        card->wandev.del_if             = NULL;
197
        card->wandev.state              = WAN_DUALPORT;
198
        card->wandev.udp_port           = conf->udp_port;
199
 
200
        card->wandev.new_if_cnt = 0;
201
 
202
        /* This is for the ports link state */
203
        card->u.c.state = WAN_DISCONNECTED;
204
 
205
        /* reset the number of times the 'update()' proc has been called */
206
        card->u.c.update_call_count = 0;
207
 
208
        card->wandev.ttl = 0x7F;
209
        card->wandev.interface = 0;
210
 
211
        card->wandev.clocking = 0;
212
 
213
        port_num = card->u.c.comm_port;
214
 
215
        /* Setup Port Bps */
216
 
217
        card->wandev.bps = 0;
218
 
219
        card->wandev.mtu = MIN_LGTH_CHDLC_DATA_CFG;
220
 
221
        /* Set up the interrupt status area */
222
        /* Read the CHDLC Configuration and obtain:
223
         *      Ptr to shared memory infor struct
224
         * Use this pointer to calculate the value of card->u.c.flags !
225
         */
226
        mb1->buffer_length = 0;
227
        mb1->command = READ_CHDLC_CONFIGURATION;
228
        err = sdla_exec(mb1) ? mb1->return_code : CMD_TIMEOUT;
229
        if(err != COMMAND_OK) {
230
                chdlc_error(card, err, mb1);
231
                return -EIO;
232
        }
233
 
234
        if(card->hw.type == SDLA_S514){
235
                card->u.c.flags = (void *)(card->hw.dpmbase +
236
                        (((CHDLC_CONFIGURATION_STRUCT *)mb1->data)->
237
                        ptr_shared_mem_info_struct));
238
        }else{
239
                card->u.c.flags = (void *)(card->hw.dpmbase +
240
                        (((CHDLC_CONFIGURATION_STRUCT *)mb1->data)->
241
                        ptr_shared_mem_info_struct % SDLA_WINDOWSIZE));
242
        }
243
 
244
        card->wandev.state = WAN_FT1_READY;
245
        printk(KERN_INFO "%s: FT1 Config Ready !\n",card->devname);
246
 
247
        return 0;
248
}
249
 
250
static int wpft1_exec(sdla_t *card, void *u_cmd, void *u_data)
251
{
252
        CHDLC_MAILBOX_STRUCT* mbox = card->mbox;
253
        int len;
254
 
255
 
256
#if defined(LINUX_2_1) || defined(LINUX_2_4)
257
        if (copy_from_user((void*)&mbox->command, u_cmd, sizeof(ft1_exec_cmd_t))){
258
                return -EFAULT;
259
        }
260
 
261
        len = mbox->buffer_length;
262
 
263
        if (len) {
264
                if( copy_from_user((void*)&mbox->data, u_data, len)){
265
                        return -EFAULT;
266
                }
267
        }
268
 
269
        /* execute command */
270
        if (!sdla_exec(mbox)){
271
                return -EIO;
272
        }
273
 
274
        /* return result */
275
        if( copy_to_user(u_cmd, (void*)&mbox->command, sizeof(ft1_exec_cmd_t))){
276
                return -EFAULT;
277
        }
278
 
279
        len = mbox->buffer_length;
280
 
281
        if (len && u_data && copy_to_user(u_data, (void*)&mbox->data, len)){
282
                return -EFAULT;
283
        }
284
 
285
#else
286
 
287
        if (!u_cmd || verify_area(VERIFY_WRITE, u_cmd, sizeof(ft1_exec_cmd_t))){
288
                return -EFAULT;
289
        }
290
 
291
        memcpy_fromfs((void*)&mbox->command, u_cmd, sizeof(ft1_exec_cmd_t));
292
 
293
        len = mbox->buffer_length;
294
 
295
        if (len) {
296
                if (!u_data || verify_area(VERIFY_READ, u_data, len))
297
                        return -EFAULT;
298
                memcpy_fromfs((void*)&mbox->data, u_data, len);
299
        }
300
 
301
        /* execute command */
302
        if (!sdla_exec(mbox))
303
                return -EIO;
304
 
305
        /* return result */
306
        memcpy_tofs(u_cmd, (void*)&mbox->command, sizeof(ft1_exec_cmd_t));
307
        len = mbox->buffer_length;
308
 
309
        if (len && u_data && !verify_area(VERIFY_WRITE, u_data, len)){
310
                memcpy_tofs(u_data, (void*)&mbox->data, len);
311
        }
312
 
313
#endif
314
 
315
        return 0;
316
 
317
}
318
 
319
/*============================================================================
320
 * Read firmware code version.
321
 *      Put code version as ASCII string in str.
322
 */
323
static int chdlc_read_version (sdla_t* card, char* str)
324
{
325
        CHDLC_MAILBOX_STRUCT* mb = card->mbox;
326
        int len;
327
        char err;
328
        mb->buffer_length = 0;
329
        mb->command = READ_CHDLC_CODE_VERSION;
330
        err = sdla_exec(mb) ? mb->return_code : CMD_TIMEOUT;
331
 
332
        if(err != COMMAND_OK) {
333
                chdlc_error(card,err,mb);
334
        }
335
        else if (str) {  /* is not null */
336
                len = mb->buffer_length;
337
                memcpy(str, mb->data, len);
338
                str[len] = '\0';
339
        }
340
        return (err);
341
}
342
 
343
/*============================================================================
344
 * Firmware error handler.
345
 *      This routine is called whenever firmware command returns non-zero
346
 *      return code.
347
 *
348
 * Return zero if previous command has to be cancelled.
349
 */
350
static int chdlc_error (sdla_t *card, int err, CHDLC_MAILBOX_STRUCT *mb)
351
{
352
        unsigned cmd = mb->command;
353
 
354
        switch (err) {
355
 
356
        case CMD_TIMEOUT:
357
                printk(KERN_ERR "%s: command 0x%02X timed out!\n",
358
                        card->devname, cmd);
359
                break;
360
 
361
        case S514_BOTH_PORTS_SAME_CLK_MODE:
362
                if(cmd == SET_CHDLC_CONFIGURATION) {
363
                        printk(KERN_INFO
364
                         "%s: Configure both ports for the same clock source\n",
365
                                card->devname);
366
                        break;
367
                }
368
 
369
        default:
370
                printk(KERN_INFO "%s: command 0x%02X returned 0x%02X!\n",
371
                        card->devname, cmd, err);
372
        }
373
 
374
        return 0;
375
}
376
 
377
MODULE_LICENSE("GPL");

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.