2 * Synchronous PPP / Cisco-HDLC driver for the COMX boards
4 * Author: Gergely Madarasz <gorgo@itc.hu>
6 * based on skeleton code by Tivadar Szemethy <tiv@itc.hu>
8 * Copyright (C) 1999 ITConsult-Pro Co. <info@itc.hu>
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.
16 * Version 0.10 (99/06/10):
17 * - written the first code :)
19 * Version 0.20 (99/06/16):
20 * - added hdlc protocol
21 * - protocol up is IFF_RUNNING
23 * Version 0.21 (99/07/15):
24 * - some small fixes with the line status
26 * Version 0.22 (99/08/05):
27 * - don't test IFF_RUNNING but the pp_link_state of the sppp
29 * Version 0.23 (99/12/02):
34 #define VERSION "0.23"
36 #include <linux/module.h>
37 #include <linux/types.h>
38 #include <linux/jiffies.h>
39 #include <linux/netdevice.h>
40 #include <linux/proc_fs.h>
41 #include <linux/if_arp.h>
42 #include <linux/inetdevice.h>
43 #include <asm/uaccess.h>
44 #include <linux/init.h>
46 #include <net/syncppp.h>
49 MODULE_AUTHOR("Author: Gergely Madarasz <gorgo@itc.hu>");
50 MODULE_DESCRIPTION("Cisco-HDLC / Synchronous PPP driver for the COMX sync serial boards");
51 MODULE_LICENSE("GPL");
53 static struct comx_protocol syncppp_protocol;
54 static struct comx_protocol hdlc_protocol;
57 struct timer_list status_timer;
60 static void syncppp_status_timerfun(unsigned long d) {
61 struct net_device *dev=(struct net_device *)d;
62 struct comx_channel *ch=dev->priv;
63 struct syncppp_data *spch=ch->LINE_privdata;
64 struct sppp *sp = (struct sppp *)sppp_of(dev);
66 if(!(ch->line_status & PROTO_UP) &&
67 (sp->pp_link_state==SPPP_LINK_UP)) {
68 comx_status(dev, ch->line_status | PROTO_UP);
70 if((ch->line_status & PROTO_UP) &&
71 (sp->pp_link_state==SPPP_LINK_DOWN)) {
72 comx_status(dev, ch->line_status & ~PROTO_UP);
74 mod_timer(&spch->status_timer,jiffies + HZ*3);
77 static int syncppp_tx(struct net_device *dev)
79 struct comx_channel *ch=dev->priv;
81 if(ch->line_status & LINE_UP) {
82 netif_wake_queue(dev);
87 static void syncppp_status(struct net_device *dev, unsigned short status)
89 status &= ~(PROTO_UP | PROTO_LOOP);
90 if(status & LINE_UP) {
91 netif_wake_queue(dev);
95 netif_stop_queue(dev);
98 comx_status(dev, status);
101 static int syncppp_open(struct net_device *dev)
103 struct comx_channel *ch = dev->priv;
104 struct syncppp_data *spch = ch->LINE_privdata;
106 if (!(ch->init_status & HW_OPEN)) return -ENODEV;
108 ch->init_status |= LINE_OPEN;
109 ch->line_status &= ~(PROTO_UP | PROTO_LOOP);
111 if(ch->line_status & LINE_UP) {
115 init_timer(&spch->status_timer);
116 spch->status_timer.function=syncppp_status_timerfun;
117 spch->status_timer.data=(unsigned long)dev;
118 spch->status_timer.expires=jiffies + HZ*3;
119 add_timer(&spch->status_timer);
124 static int syncppp_close(struct net_device *dev)
126 struct comx_channel *ch = dev->priv;
127 struct syncppp_data *spch = ch->LINE_privdata;
129 if (!(ch->init_status & HW_OPEN)) return -ENODEV;
130 del_timer(&spch->status_timer);
134 ch->init_status &= ~LINE_OPEN;
135 ch->line_status &= ~(PROTO_UP | PROTO_LOOP);
140 static int syncppp_xmit(struct sk_buff *skb, struct net_device *dev)
142 struct comx_channel *ch = dev->priv;
144 netif_stop_queue(dev);
145 switch(ch->HW_send_packet(dev, skb)) {
147 netif_wake_queue(dev);
153 printk(KERN_ERR "%s: Transmit frame error (len %d)\n",
154 dev->name, skb->len);
161 static int syncppp_statistics(struct net_device *dev, char *page)
165 len += sprintf(page + len, " ");
170 static int syncppp_exit(struct net_device *dev)
172 struct comx_channel *ch = dev->priv;
182 ch->LINE_status = NULL;
183 ch->LINE_open = NULL;
184 ch->LINE_close = NULL;
185 ch->LINE_xmit = NULL;
186 ch->LINE_header = NULL;
187 ch->LINE_rebuild_header = NULL;
188 ch->LINE_statistics = NULL;
190 kfree(ch->LINE_privdata);
191 ch->LINE_privdata = NULL;
197 static int syncppp_init(struct net_device *dev)
199 struct comx_channel *ch = dev->priv;
200 struct ppp_device *pppdev = (struct ppp_device *)ch->if_ptr;
202 ch->LINE_privdata = kmalloc(sizeof(struct syncppp_data), GFP_KERNEL);
203 if (!ch->LINE_privdata)
209 if(ch->protocol == &hdlc_protocol) {
210 pppdev->sppp.pp_flags |= PP_CISCO;
211 dev->type = ARPHRD_HDLC;
213 pppdev->sppp.pp_flags &= ~PP_CISCO;
214 dev->type = ARPHRD_PPP;
217 ch->LINE_rx = sppp_input;
218 ch->LINE_tx = syncppp_tx;
219 ch->LINE_status = syncppp_status;
220 ch->LINE_open = syncppp_open;
221 ch->LINE_close = syncppp_close;
222 ch->LINE_xmit = syncppp_xmit;
223 ch->LINE_header = NULL;
224 ch->LINE_statistics = syncppp_statistics;
231 static struct comx_protocol syncppp_protocol = {
240 static struct comx_protocol hdlc_protocol = {
249 static int __init comx_proto_ppp_init(void)
253 ret = comx_register_protocol(&hdlc_protocol);
255 ret = comx_register_protocol(&syncppp_protocol);
257 comx_unregister_protocol(hdlc_protocol.name);
262 static void __exit comx_proto_ppp_exit(void)
264 comx_unregister_protocol(syncppp_protocol.name);
265 comx_unregister_protocol(hdlc_protocol.name);
268 module_init(comx_proto_ppp_init);
269 module_exit(comx_proto_ppp_exit);