2 * cycx_main.c Cyclades Cyclom 2X WAN Link Driver. Main module.
4 * Author: Arnaldo Carvalho de Melo <acme@conectiva.com.br>
6 * Copyright: (c) 1998-2003 Arnaldo Carvalho de Melo
8 * Based on sdlamain.c by Gene Kozin <genek@compuserve.com> &
9 * Jaspreet Singh <jaspreet@sangoma.com>
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version
14 * 2 of the License, or (at your option) any later version.
15 * ============================================================================
16 * Please look at the bitkeeper changelog (or any other scm tool that ends up
17 * importing bitkeeper changelog or that replaces bitkeeper in the future as
18 * main tool for linux development).
20 * 2001/05/09 acme Fix MODULE_DESC for debug, .bss nitpicks,
22 * 2000/07/13 acme remove useless #ifdef MODULE and crap
23 * #if KERNEL_VERSION > blah
24 * 2000/07/06 acme __exit at cyclomx_cleanup
25 * 2000/04/02 acme dprintk and cycx_debug
26 * module_init/module_exit
27 * 2000/01/21 acme rename cyclomx_open to cyclomx_mod_inc_use_count
28 * and cyclomx_close to cyclomx_mod_dec_use_count
29 * 2000/01/08 acme cleanup
30 * 1999/11/06 acme cycx_down back to life (it needs to be
31 * called to iounmap the dpmbase)
32 * 1999/08/09 acme removed references to enable_tx_int
33 * use spinlocks instead of cli/sti in
35 * 1999/05/19 acme works directly linked into the kernel
36 * init_waitqueue_head for 2.3.* kernel
37 * 1999/05/18 acme major cleanup (polling not needed), etc
38 * 1998/08/28 acme minor cleanup (ioctls for firmware deleted)
39 * queue_task activated
40 * 1998/08/08 acme Initial version.
43 #include <linux/stddef.h> /* offsetof(), etc. */
44 #include <linux/errno.h> /* return codes */
45 #include <linux/string.h> /* inline memset(), etc. */
46 #include <linux/slab.h> /* kmalloc(), kfree() */
47 #include <linux/kernel.h> /* printk(), and other useful stuff */
48 #include <linux/module.h> /* support for loadable modules */
49 #include <linux/ioport.h> /* request_region(), release_region() */
50 #include <linux/wanrouter.h> /* WAN router definitions */
51 #include <linux/cyclomx.h> /* cyclomx common user API definitions */
52 #include <linux/init.h> /* __init (when not using as a module) */
53 #include <linux/interrupt.h>
55 unsigned int cycx_debug
;
57 MODULE_AUTHOR("Arnaldo Carvalho de Melo");
58 MODULE_DESCRIPTION("Cyclom 2X Sync Card Driver.");
59 MODULE_LICENSE("GPL");
60 module_param(cycx_debug
, int, 0);
61 MODULE_PARM_DESC(cycx_debug
, "cyclomx debug level");
63 /* Defines & Macros */
65 #define CYCX_DRV_VERSION 0 /* version number */
66 #define CYCX_DRV_RELEASE 11 /* release (minor version) number */
67 #define CYCX_MAX_CARDS 1 /* max number of adapters */
69 #define CONFIG_CYCX_CARDS 1
71 /* Function Prototypes */
73 /* WAN link driver entry points */
74 static int cycx_wan_setup(struct wan_device
*wandev
, wandev_conf_t
*conf
);
75 static int cycx_wan_shutdown(struct wan_device
*wandev
);
77 /* Miscellaneous functions */
78 static irqreturn_t
cycx_isr(int irq
, void *dev_id
);
81 * Note: All data must be explicitly initialized!!!
85 static const char cycx_drvname
[] = "cyclomx";
86 static const char cycx_fullname
[] = "CYCLOM 2X(tm) Sync Card Driver";
87 static const char cycx_copyright
[] = "(c) 1998-2003 Arnaldo Carvalho de Melo "
88 "<acme@conectiva.com.br>";
89 static int cycx_ncards
= CONFIG_CYCX_CARDS
;
90 static struct cycx_device
*cycx_card_array
; /* adapter data space */
92 /* Kernel Loadable Module Entry Points */
95 * Module 'insert' entry point.
96 * o print announcement
97 * o allocate adapter data space
98 * o initialize static data
99 * o register all cards with WAN router
100 * o calibrate Cyclom 2X shared memory access delay.
106 static int __init
cycx_init(void)
108 int cnt
, err
= -ENOMEM
;
110 printk(KERN_INFO
"%s v%u.%u %s\n",
111 cycx_fullname
, CYCX_DRV_VERSION
, CYCX_DRV_RELEASE
,
114 /* Verify number of cards and allocate adapter data space */
115 cycx_ncards
= min_t(int, cycx_ncards
, CYCX_MAX_CARDS
);
116 cycx_ncards
= max_t(int, cycx_ncards
, 1);
117 cycx_card_array
= kcalloc(cycx_ncards
, sizeof(struct cycx_device
), GFP_KERNEL
);
118 if (!cycx_card_array
)
122 /* Register adapters with WAN router */
123 for (cnt
= 0; cnt
< cycx_ncards
; ++cnt
) {
124 struct cycx_device
*card
= &cycx_card_array
[cnt
];
125 struct wan_device
*wandev
= &card
->wandev
;
127 sprintf(card
->devname
, "%s%d", cycx_drvname
, cnt
+ 1);
128 wandev
->magic
= ROUTER_MAGIC
;
129 wandev
->name
= card
->devname
;
130 wandev
->private = card
;
131 wandev
->setup
= cycx_wan_setup
;
132 wandev
->shutdown
= cycx_wan_shutdown
;
133 err
= register_wan_device(wandev
);
136 printk(KERN_ERR
"%s: %s registration failed with "
138 cycx_drvname
, card
->devname
, err
);
145 kfree(cycx_card_array
);
149 cycx_ncards
= cnt
; /* adjust actual number of cards */
154 * Module 'remove' entry point.
155 * o unregister all adapters from the WAN router
156 * o release all remaining system resources
158 static void __exit
cycx_exit(void)
162 for (; i
< cycx_ncards
; ++i
) {
163 struct cycx_device
*card
= &cycx_card_array
[i
];
164 unregister_wan_device(card
->devname
);
167 kfree(cycx_card_array
);
170 /* WAN Device Driver Entry Points */
172 * Setup/configure WAN link driver.
173 * o check adapter state
174 * o make sure firmware is present in configuration
175 * o allocate interrupt vector
176 * o setup Cyclom 2X hardware
177 * o call appropriate routine to perform protocol-specific initialization
179 * This function is called when router handles ROUTER_SETUP IOCTL. The
180 * configuration structure is in kernel memory (including extended data, if
183 static int cycx_wan_setup(struct wan_device
*wandev
, wandev_conf_t
*conf
)
186 struct cycx_device
*card
;
191 if (!wandev
|| !wandev
->private || !conf
)
194 card
= wandev
->private;
196 if (wandev
->state
!= WAN_UNCONFIGURED
)
200 if (!conf
->data_size
|| !conf
->data
) {
201 printk(KERN_ERR
"%s: firmware not found in configuration "
202 "data!\n", wandev
->name
);
206 if (conf
->irq
<= 0) {
207 printk(KERN_ERR
"%s: can't configure without IRQ!\n",
213 irq
= conf
->irq
== 2 ? 9 : conf
->irq
; /* IRQ2 -> IRQ9 */
215 if (request_irq(irq
, cycx_isr
, 0, wandev
->name
, card
)) {
216 printk(KERN_ERR
"%s: can't reserve IRQ %d!\n",
221 /* Configure hardware, load firmware, etc. */
222 memset(&card
->hw
, 0, sizeof(card
->hw
));
224 card
->hw
.dpmsize
= CYCX_WINDOWSIZE
;
225 card
->hw
.fwid
= CFID_X25_2X
;
226 spin_lock_init(&card
->lock
);
227 init_waitqueue_head(&card
->wait_stats
);
229 rc
= cycx_setup(&card
->hw
, conf
->data
, conf
->data_size
, conf
->maddr
);
233 /* Initialize WAN device data space */
235 wandev
->dma
= wandev
->ioport
= 0;
236 wandev
->maddr
= (unsigned long)card
->hw
.dpmbase
;
237 wandev
->msize
= card
->hw
.dpmsize
;
238 wandev
->hw_opt
[2] = 0;
239 wandev
->hw_opt
[3] = card
->hw
.fwid
;
241 /* Protocol-specific initialization */
242 switch (card
->hw
.fwid
) {
243 #ifdef CONFIG_CYCLOMX_X25
245 rc
= cycx_x25_wan_init(card
, conf
);
249 printk(KERN_ERR
"%s: this firmware is not supported!\n",
255 cycx_down(&card
->hw
);
268 * Shut down WAN link driver.
269 * o shut down adapter hardware
270 * o release system resources.
272 * This function is called by the router when device is being unregistered or
273 * when it handles ROUTER_DOWN IOCTL.
275 static int cycx_wan_shutdown(struct wan_device
*wandev
)
278 struct cycx_device
*card
;
281 if (!wandev
|| !wandev
->private)
285 if (wandev
->state
== WAN_UNCONFIGURED
)
288 card
= wandev
->private;
289 wandev
->state
= WAN_UNCONFIGURED
;
290 cycx_down(&card
->hw
);
291 printk(KERN_INFO
"%s: irq %d being freed!\n", wandev
->name
,
293 free_irq(wandev
->irq
, card
);
299 * Cyclom 2X Interrupt Service Routine.
300 * o acknowledge Cyclom 2X hardware interrupt.
301 * o call protocol-specific interrupt service routine, if any.
303 static irqreturn_t
cycx_isr(int irq
, void *dev_id
)
305 struct cycx_device
*card
= dev_id
;
307 if (card
->wandev
.state
== WAN_UNCONFIGURED
)
311 printk(KERN_WARNING
"%s: interrupt re-entrancy on IRQ %d!\n",
312 card
->devname
, card
->wandev
.irq
);
323 /* Set WAN device state. */
324 void cycx_set_state(struct cycx_device
*card
, int state
)
327 char *string_state
= NULL
;
329 spin_lock_irqsave(&card
->lock
, flags
);
331 if (card
->wandev
.state
!= state
) {
334 string_state
= "connected!";
336 case WAN_DISCONNECTED
:
337 string_state
= "disconnected!";
340 printk(KERN_INFO
"%s: link %s\n", card
->devname
, string_state
);
341 card
->wandev
.state
= state
;
344 card
->state_tick
= jiffies
;
345 spin_unlock_irqrestore(&card
->lock
, flags
);
348 module_init(cycx_init
);
349 module_exit(cycx_exit
);
This page took 0.09207 seconds and 5 git commands to generate.