* Timers in 2.6.x kernels
@ 2004-03-12 11:10 Jarmo
2004-03-12 19:09 ` Jeroen Vreeken
2004-03-13 14:19 ` Ralf Baechle DO1GRB
0 siblings, 2 replies; 8+ messages in thread
From: Jarmo @ 2004-03-12 11:10 UTC (permalink / raw)
To: linux-hams
Hi
We have still struggling with ax25 and especially with 6pack.
We get 6pack crashing randomly...
Have found that timerparameters have loud a much differences
between kernels 2.2-->2.4-->2.6.Now looked up,that there is
big change happened in kernels param.h file.
This is from 2.2.26 kernel..
#ifndef _ASMi386_PARAM_H
#define _ASMi386_PARAM_H
#ifndef HZ
#define HZ 100
#endif
This is from 2.6.4
#ifndef _ASMi386_PARAM_H
#define _ASMi386_PARAM_H
#ifdef __KERNEL__
# define HZ 1000 /* Internal kernel timer frequency */
# define USER_HZ 100 /* .. some user interfaces are in
"ticks# define CLOCKS_PER_SEC (USER_HZ) /* like times() */
#endif
#ifndef HZ
#define HZ 100
#endif
As can be seen fom 2.2 to 2.6 HZ is multiplied by 10.
OK,now ax25.h instead is same in all these kernels
#define AX25_DEF_T1 (10 * HZ) /* T1=10s */
#define AX25_DEF_T2 (3 * HZ) /* T2=3s */
#define AX25_DEF_T3 (300 * HZ) /* T3=300s */
#define AX25_DEF_N2 10 /* N2=10 */
#define AX25_DEF_IDLE (0 * 60 * HZ) /* Idle=None */
#define AX25_DEF_PACLEN 256 /* Paclen=256 */
#define AX25_DEF_PROTOCOL AX25_PROTO_STD_SIMPLEX /* Standard AX.25 */
#define AX25_DEF_DS_TIMEOUT (3 * 60 * HZ) /* DAMA timeout 3
minute
And 6pack,what we use here
/* default level 2 parameters */
#define SIXP_TXDELAY (HZ/4) /* in 1 s */
#define SIXP_PERSIST 50 /* in 256ths */
#define SIXP_SLOTTIME (HZ/10) /* in 1 s */
#define SIXP_INIT_RESYNC_TIMEOUT (3*HZ/2) /* in 1 s */
#define SIXP_RESYNC_TIMEOUT 5*HZ /* in 1 s */
Now if we take sixp_txdelay HZ/4 with this 2.6 kernel it gives
value 2,5 seconds!
So what we have done we have changed (HZ/4) to (HZ/40) and slottime
value (HZ/10) into (HZ/100).
A little bit more success to keep system up longer,but it crash still...
And what we get into syslog
Mar 5 16:46:58 oh1rbf kernel: 6pack: bad checksum f7
Mar 5 16:46:58 oh1rbf last message repeated 4 times
Mar 5 16:46:58 oh1rbf kernel: bad: scheduling while atomic!
Mar 5 16:46:58 oh1rbf kernel: Call Trace:
Mar 5 16:46:58 oh1rbf kernel: [schedule+1339/1408] schedule+0x53b/0x580
Mar 5 16:46:58 oh1rbf kernel: [<c011869b>] schedule+0x53b/0x580
Mar 5 16:46:58 oh1rbf kernel: [_stext+0/32] rest_init+0x0/0x20
Mar 5 16:46:58 oh1rbf kernel: [<c0105000>] rest_init+0x0/0x20
Mar 5 16:46:58 oh1rbf kernel: [apm_do_busy+22/48] apm_do_busy+0x16/0x30
Mar 5 16:46:58 oh1rbf kernel: [<c01148b6>] apm_do_busy+0x16/0x30
Mar 5 16:46:58 oh1rbf kernel: [_stext+0/32] rest_init+0x0/0x20
Mar 5 16:46:58 oh1rbf kernel: [<c0105000>] rest_init+0x0/0x20
Mar 5 16:46:58 oh1rbf kernel: [cpu_idle+57/64] cpu_idle+0x39/0x40
Mar 5 16:46:58 oh1rbf kernel: [<c0108be9>] cpu_idle+0x39/0x40
Mar 5 16:46:58 oh1rbf kernel: [start_kernel+345/400]
start_kernel+0x159/0x190 Mar 5 16:46:58 oh1rbf kernel: [<c02e06c9>]
start_kernel+0x159/0x190 Mar 5 16:46:58 oh1rbf kernel:
Mar 5 16:46:58 oh1rbf kernel: 6pack: resyncing TNC
Mar 5 16:46:58 oh1rbf last message repeated 2 times
Mar 5 16:46:58 oh1rbf kernel: 6pack: TNC found.
Mar 5 16:46:58 oh1rbf kernel: 6pack: bad checksum f7
Mar 5 16:46:58 oh1rbf kernel: 6pack: bad checksum f7
Question is.What we could do to get this mess working?
McGyver help!
Jarmo
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Timers in 2.6.x kernels
2004-03-12 11:10 Timers in 2.6.x kernels Jarmo
@ 2004-03-12 19:09 ` Jeroen Vreeken
2004-03-13 14:19 ` Ralf Baechle DO1GRB
1 sibling, 0 replies; 8+ messages in thread
From: Jeroen Vreeken @ 2004-03-12 19:09 UTC (permalink / raw)
To: linux-hams
On 2004.03.12 12:10:02 +0100 Jarmo wrote:
> As can be seen fom 2.2 to 2.6 HZ is multiplied by 10.
> And 6pack,what we use here
>
> /* default level 2 parameters */
>
> #define SIXP_TXDELAY (HZ/4) /* in 1 s */
>
> #define SIXP_PERSIST 50 /* in 256ths */
>
> #define SIXP_SLOTTIME (HZ/10) /* in 1 s */
>
> #define SIXP_INIT_RESYNC_TIMEOUT (3*HZ/2) /* in 1 s */
>
> #define SIXP_RESYNC_TIMEOUT 5*HZ /* in 1 s */
>
>
> Now if we take sixp_txdelay HZ/4 with this 2.6 kernel it gives
> value 2,5 seconds!
The kernel has an internal timer (called the jiffie counter) that counts in
a unit called a 'jiffie'.
HZ is the amount of jiffies that go in one second (and is thus the
frequency of the jiffie timer).
So HZ/4 should be 0.25 seconds.
If the 6pack driver does an 2.5 seconds wait it is either not due to the
HZ/4 counter or it has some pretty screwed up timing.
> So what we have done we have changed (HZ/4) to (HZ/40) and slottime
> value (HZ/10) into (HZ/100).
>
> A little bit more success to keep system up longer,but it crash still...
>
> And what we get into syslog
>
> Mar 5 16:46:58 oh1rbf kernel: [apm_do_busy+22/48] apm_do_busy+0x16/0x30
>
> Mar 5 16:46:58 oh1rbf kernel: [<c01148b6>] apm_do_busy+0x16/0x30
It might be coincedence, but could you try a kernel without apm?
>
>
> Question is.What we could do to get this mess working?
>
> McGyver help!
I have a pocket knife (and I have ductape lying within a few meters of me,
does that count? :)
Jeroen
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Timers in 2.6.x kernels
2004-03-12 11:10 Timers in 2.6.x kernels Jarmo
2004-03-12 19:09 ` Jeroen Vreeken
@ 2004-03-13 14:19 ` Ralf Baechle DO1GRB
2004-03-13 14:59 ` Jarmo
1 sibling, 1 reply; 8+ messages in thread
From: Ralf Baechle DO1GRB @ 2004-03-13 14:19 UTC (permalink / raw)
To: Jarmo; +Cc: linux-hams
On Fri, Mar 12, 2004 at 01:10:02PM +0200, Jarmo wrote:
> Have found that timerparameters have loud a much differences
> between kernels 2.2-->2.4-->2.6.Now looked up,that there is
> big change happened in kernels param.h file.
The change was long overdue but we didn't have the necessary infrastructure
in the kernel.org tree to increase HZ without affecting binary compatibility
with applications.
All properly written kernel code should now be used USER_HZ for any kind of
kernel interfaces that are user or application visible. Unfortunately quite
a bit of the ham code in the kernel still hasn't done that transitition
so now we've got a wild mix of time units.
I guess for consistence we should bit the bullet and standardize on one
unit, seconds or miliseconds as appropriate. HZ or USER_HZ require the
user to know what kind of system or even what kernel version he's running.
> A little bit more success to keep system up longer,but it crash still...
You're just putting less pressure on the buggy part of the system. Doesn't
mean your change is improving correctness, unfortunately.
> And what we get into syslog
>
> Mar 5 16:46:58 oh1rbf kernel: 6pack: bad checksum f7
> Mar 5 16:46:58 oh1rbf last message repeated 4 times
> Mar 5 16:46:58 oh1rbf kernel: bad: scheduling while atomic!
> Mar 5 16:46:58 oh1rbf kernel: Call Trace:
> Mar 5 16:46:58 oh1rbf kernel: [schedule+1339/1408] schedule+0x53b/0x580
> Mar 5 16:46:58 oh1rbf kernel: [<c011869b>] schedule+0x53b/0x580
> Mar 5 16:46:58 oh1rbf kernel: [_stext+0/32] rest_init+0x0/0x20
> Mar 5 16:46:58 oh1rbf kernel: [<c0105000>] rest_init+0x0/0x20
> Mar 5 16:46:58 oh1rbf kernel: [apm_do_busy+22/48] apm_do_busy+0x16/0x30
> Mar 5 16:46:58 oh1rbf kernel: [<c01148b6>] apm_do_busy+0x16/0x30
Do you happen to be running a CONFIG_SMP / CONFIG_PREEMPT kernel? The
locking stuff in the 6pack driver looks pretty broken and I wouldn't
expect it to survive for long with any of these two kernel options
enabled.
APM implementations tend to tamper with interrupts so disabling APM while
running data over the serial port may help.
Ralf
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Timers in 2.6.x kernels
2004-03-13 14:19 ` Ralf Baechle DO1GRB
@ 2004-03-13 14:59 ` Jarmo
2004-03-13 22:06 ` Ralf Baechle DO1GRB
0 siblings, 1 reply; 8+ messages in thread
From: Jarmo @ 2004-03-13 14:59 UTC (permalink / raw)
To: Ralf Baechle DO1GRB; +Cc: linux-hams
On Saturday 13 March 2004 16:19, you wrote:
> All properly written kernel code should now be used USER_HZ for any kind of
> kernel interfaces that are user or application visible. Unfortunately
> quite a bit of the ham code in the kernel still hasn't done that
> transitition so now we've got a wild mix of time units.
>
> I guess for consistence we should bit the bullet and standardize on one
> unit, seconds or miliseconds as appropriate. HZ or USER_HZ require the
> user to know what kind of system or even what kernel version he's running.
In 6pack driver here in linux,there's still 0.3.0 version,and if I remember
the end of 90' ,there was something 0.4.2 version for dos/windows.
It never came into kernel tree...
> Do you happen to be running a CONFIG_SMP / CONFIG_PREEMPT kernel? The
> locking stuff in the 6pack driver looks pretty broken and I wouldn't
> expect it to survive for long with any of these two kernel options
> enabled.
No
> APM implementations tend to tamper with interrupts so disabling APM while
> running data over the serial port may help.
This morning I compiled kernel without APM and it has been running
from since.
Hope,that get it running more stable..9 hours max uptime was quite
annoying.
Ofcourse possibilities to start use mkiss......Hope someone should
find intress to look code and make improvements..My knowledge
is below zero...;-)
Still have to remember,that this is a hobby..isn't it?
Jarmo
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Timers in 2.6.x kernels
2004-03-13 14:59 ` Jarmo
@ 2004-03-13 22:06 ` Ralf Baechle DO1GRB
2004-03-14 6:01 ` Jarmo
0 siblings, 1 reply; 8+ messages in thread
From: Ralf Baechle DO1GRB @ 2004-03-13 22:06 UTC (permalink / raw)
To: Jarmo; +Cc: linux-hams
On Sat, Mar 13, 2004 at 04:59:49PM +0200, Jarmo wrote:
> In 6pack driver here in linux,there's still 0.3.0 version,and if I remember
> the end of 90' ,there was something 0.4.2 version for dos/windows.
> It never came into kernel tree...
MS drivers and Linux drivers are technically very different. So quite
likely the version numbers are refering to different drivers. And anyway,
the Linux driver has been changed fairly often, just not the version
number of the driver. So in short, the content of information in the
version number is probably approximating that of cosmic noise ;-)
> > APM implementations tend to tamper with interrupts so disabling APM while
> > running data over the serial port may help.
>
> This morning I compiled kernel without APM and it has been running
> from since.
> Hope,that get it running more stable..9 hours max uptime was quite
> annoying.
>
> Ofcourse possibilities to start use mkiss......Hope someone should
> find intress to look code and make improvements..My knowledge
> is below zero...;-)
>
> Still have to remember,that this is a hobby..isn't it?
Maybe - but software that works less than reliable sucks.
73 de DO1GRB op Ralf
--
Loc. JN47BS / CQ 14 / ITU 28 / DOK A21
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Timers in 2.6.x kernels
2004-03-13 22:06 ` Ralf Baechle DO1GRB
@ 2004-03-14 6:01 ` Jarmo
2004-03-15 0:51 ` Ralf Baechle DO1GRB
0 siblings, 1 reply; 8+ messages in thread
From: Jarmo @ 2004-03-14 6:01 UTC (permalink / raw)
To: Ralf Baechle DO1GRB; +Cc: linux-hams
On Sunday 14 March 2004 00:06, you wrote:
> MS drivers and Linux drivers are technically very different. So quite
> likely the version numbers are refering to different drivers. And anyway,
> the Linux driver has been changed fairly often, just not the version
> number of the driver. So in short, the content of information in the
> version number is probably approximating that of cosmic noise ;-)
True...
But also true,that there is no maintainer for 6pack at the moment..
So we here,who use it,are in "liquid"...Want to modernize system,
hardware and software, but seems to take some time...
In a way this is fun,to try solve problems,but packetradio/cluster
users does not feel that way,when everything is crushed most
of the time...
> > Hope,that get it running more stable..9 hours max uptime was quite
> > annoying.
8 hours 14mins...AAARGGHHHH!
Still have to remember,that this is a hobby..isn't it?
>
> Maybe - but software that works less than reliable sucks.
>
> 73 de DO1GRB op Ralf
True,but this case I've started to think,that there sucks my linux
skills;-)
No...I'm not giving up...Next..... HW change...again..
Jarmo
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Timers in 2.6.x kernels
2004-03-14 6:01 ` Jarmo
@ 2004-03-15 0:51 ` Ralf Baechle DO1GRB
[not found] ` <200403150806.46071.oh1mrr@nic.fi>
0 siblings, 1 reply; 8+ messages in thread
From: Ralf Baechle DO1GRB @ 2004-03-15 0:51 UTC (permalink / raw)
To: Jarmo; +Cc: linux-hams
On Sun, Mar 14, 2004 at 08:01:27AM +0200, Jarmo wrote:
> But also true,that there is no maintainer for 6pack at the moment..
> So we here,who use it,are in "liquid"...Want to modernize system,
> hardware and software, but seems to take some time...
> In a way this is fun,to try solve problems,but packetradio/cluster
> users does not feel that way,when everything is crushed most
> of the time...
Below is a 6pack patch against 2.6.3. First I thought touching gently was
good enough but I changed my mind to do a full crapectomy as the prefered
method of therapy :-) The code had numerous small problems, is using tons
of outdated constructs etc., multiple 6pack devices were broken, having to
choose the number of 6pack devices at module load / kernel boot time was so
yesterday when having no limit is even easier. Loads of cosmetic cleanups
to get this thing to follow the usual Linux coding conventions.
> > > Hope,that get it running more stable..9 hours max uptime was quite
> > > annoying.
>
> 8 hours 14mins...AAARGGHHHH!
Yuck.
> True,but this case I've started to think,that there sucks my linux
> skills;-)
> No...I'm not giving up...Next..... HW change...again..
Let me know how well this is working. I've tested this as well as possible
without having 6pack hardware myself and that's not too much ... Anyway,
I need testers before I send this patch upstream with good conscious and
that means it at least has to reach stability comparable to what's in stock
2.6.4.
This patch is also available on ftp.linux-mips.net in /pub/ham/6pack/.
73 de DO1GRB op Ralf
--
Loc. JN47BS / CQ 14 / ITU 28 / DOK A21
Index: drivers/net/hamradio/6pack.c
===================================================================
RCS file: /home/cvs/linux/drivers/net/hamradio/6pack.c,v
retrieving revision 1.20
diff -u -r1.20 6pack.c
--- drivers/net/hamradio/6pack.c 11 Mar 2004 16:46:51 -0000 1.20
+++ drivers/net/hamradio/6pack.c 15 Mar 2004 00:39:13 -0000
@@ -3,15 +3,13 @@
* devices like TTY. It interfaces between a raw TTY and the
* kernel's AX.25 protocol layers.
*
- * Version: @(#)6pack.c 0.3.0 04/07/98
- *
* Authors: Andreas Könsgen <ajk@iehk.rwth-aachen.de>
+ * Ralf Baechle DO1GRB <ralf@linux-mips.org>
*
- * Quite a lot of stuff "stolen" by Jörg Reuter from slip.c, written by
+ * Quite a lot of stuff "stolen" by Joerg Reuter from slip.c, written by
*
* Laurence Culhane, <loz@holmes.demon.co.uk>
* Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
- *
*/
#include <linux/config.h>
@@ -31,6 +29,7 @@
#include <linux/etherdevice.h>
#include <linux/skbuff.h>
#include <linux/rtnetlink.h>
+#include <linux/spinlock.h>
#include <linux/if_arp.h>
#include <linux/init.h>
#include <linux/ip.h>
@@ -78,7 +77,6 @@
#define SIXP_MTU 256 /* Default MTU */
enum sixpack_flags {
- SIXPF_INUSE, /* Channel in use */
SIXPF_ERROR, /* Parity, etc. error */
};
@@ -86,15 +84,15 @@
int magic;
/* Various fields. */
- struct tty_struct *tty; /* ptr to TTY structure */
- struct net_device *dev; /* easy for intr handling */
+ struct tty_struct *tty; /* ptr to TTY structure */
+ struct net_device *dev; /* easy for intr handling */
/* These are pointers to the malloc()ed frame buffers. */
- unsigned char *rbuff; /* receiver buffer */
- int rcount; /* received chars counter */
- unsigned char *xbuff; /* transmitter buffer */
- unsigned char *xhead; /* pointer to next byte to XMIT */
- int xleft; /* bytes left in XMIT queue */
+ unsigned char *rbuff; /* receiver buffer */
+ int rcount; /* received chars counter */
+ unsigned char *xbuff; /* transmitter buffer */
+ unsigned char *xhead; /* next byte to XMIT */
+ int xleft; /* bytes left in XMIT queue */
unsigned char raw_buf[4];
unsigned char cooked_buf[400];
@@ -105,11 +103,11 @@
/* 6pack interface statistics. */
struct net_device_stats stats;
- int mtu; /* Our mtu (to spot changes!) */
- int buffsize; /* Max buffers sizes */
+ int mtu; /* Our mtu (to spot changes!) */
+ int buffsize; /* Max buffers sizes */
- unsigned long flags; /* Flag values/ mode etc */
- unsigned char mode; /* 6pack mode */
+ unsigned long flags; /* Flag values/ mode etc */
+ unsigned char mode; /* 6pack mode */
/* 6pack stuff */
unsigned char tx_delay;
@@ -125,112 +123,292 @@
struct timer_list tx_t;
struct timer_list resync_t;
+ spinlock_t lock;
};
#define AX25_6PACK_HEADER_LEN 0
#define SIXPACK_MAGIC 0x5304
-typedef struct sixpack_ctrl {
- struct sixpack ctrl; /* 6pack things */
- struct net_device dev; /* the device */
-} sixpack_ctrl_t;
-static sixpack_ctrl_t **sixpack_ctrls;
-
-int sixpack_maxdev = SIXP_NRUNIT; /* Can be overridden with insmod! */
-MODULE_PARM(sixpack_maxdev, "i");
-MODULE_PARM_DESC(sixpack_maxdev, "number of 6PACK devices");
-
static void sp_start_tx_timer(struct sixpack *);
-static void sp_xmit_on_air(unsigned long);
-static void resync_tnc(unsigned long);
static void sixpack_decode(struct sixpack *, unsigned char[], int);
static int encode_sixpack(unsigned char *, unsigned char *, int, unsigned char);
static int sixpack_init(struct net_device *dev);
-static void decode_prio_command(unsigned char, struct sixpack *);
-static void decode_std_command(unsigned char, struct sixpack *);
-static void decode_data(unsigned char, struct sixpack *);
+/*
+ * perform the persistence/slottime algorithm for CSMA access. If the
+ * persistence check was successful, write the data to the serial driver.
+ * Note that in case of DAMA operation, the data is not sent here.
+ */
+
+static void sp_xmit_on_air(unsigned long channel)
+{
+ struct sixpack *sp = (struct sixpack *) channel;
+ int actual;
+ static unsigned char random;
-static int tnc_init(struct sixpack *);
+ random = random * 17 + 41;
-/* Find a free 6pack channel, and link in this `tty' line. */
-static inline struct sixpack *sp_alloc(void)
+ if (((sp->status1 & SIXP_DCD_MASK) == 0) && (random < sp->persistence)) {
+ sp->led_state = 0x70;
+ sp->tty->driver->write(sp->tty, 0, &sp->led_state, 1);
+ sp->tx_enable = 1;
+ actual = sp->tty->driver->write(sp->tty, 0, sp->xbuff, sp->status2);
+ sp->xleft -= actual;
+ sp->xhead += actual;
+ sp->led_state = 0x60;
+ sp->tty->driver->write(sp->tty, 0, &sp->led_state, 1);
+ sp->status2 = 0;
+ } else
+ sp_start_tx_timer(sp);
+}
+
+/* ----> 6pack timer interrupt handler and friends. <---- */
+static void sp_start_tx_timer(struct sixpack *sp)
+{
+ int when = sp->slottime;
+
+ del_timer(&sp->tx_t);
+ sp->tx_t.data = (unsigned long) sp;
+ sp->tx_t.function = sp_xmit_on_air;
+ sp->tx_t.expires = jiffies + ((when + 1) * HZ) / 100;
+ add_timer(&sp->tx_t);
+}
+
+/* Encapsulate one AX.25 frame and stuff into a TTY queue. */
+static void sp_encaps(struct sixpack *sp, unsigned char *icp, int len)
{
- sixpack_ctrl_t *spp = NULL;
- int i;
+ unsigned char *msg, *p = icp;
+ int actual, count;
+
+ if (len > sp->mtu) { /* sp->mtu = AX25_MTU = max. PACLEN = 256 */
+ msg = "oversized transmit packet!";
+ goto out_drop;
+ }
- for (i = 0; i < sixpack_maxdev; i++) {
- spp = sixpack_ctrls[i];
+ if (p[0] > 5) {
+ msg = "invalid KISS command";
+ goto out_drop;
+ }
- if (spp == NULL)
- break;
+ if ((p[0] != 0) && (len > 2)) {
+ msg = "KISS control packet too long";
+ goto out_drop;
+ }
- if (!test_and_set_bit(SIXPF_INUSE, &spp->ctrl.flags))
- break;
+ if ((p[0] == 0) && (len < 15)) {
+ msg = "bad AX.25 packet to transmit";
+ goto out_drop;
}
- /* Too many devices... */
- if (i >= sixpack_maxdev)
- return NULL;
+ count = encode_sixpack(p, sp->xbuff, len, sp->tx_delay);
+ sp->tty->flags |= (1 << TTY_DO_WRITE_WAKEUP);
- /* If no channels are available, allocate one */
- if (!spp &&
- (sixpack_ctrls[i] = (sixpack_ctrl_t *)kmalloc(sizeof(sixpack_ctrl_t),
- GFP_KERNEL)) != NULL) {
- spp = sixpack_ctrls[i];
+ switch (p[0]) {
+ case 1: sp->tx_delay = p[1];
+ return;
+ case 2: sp->persistence = p[1];
+ return;
+ case 3: sp->slottime = p[1];
+ return;
+ case 4: /* ignored */
+ return;
+ case 5: sp->duplex = p[1];
+ return;
}
- memset(spp, 0, sizeof(sixpack_ctrl_t));
- /* Initialize channel control data */
- set_bit(SIXPF_INUSE, &spp->ctrl.flags);
- spp->ctrl.tty = NULL;
- sprintf(spp->dev.name, "sp%d", i);
- spp->dev.base_addr = i;
- spp->dev.priv = (void *) &spp->ctrl;
- spp->dev.next = NULL;
- spp->dev.init = sixpack_init;
-
- if (spp != NULL) {
- /* register device so that it can be ifconfig'ed */
- /* sixpack_init() will be called as a side-effect */
- /* SIDE-EFFECT WARNING: sixpack_init() CLEARS spp->ctrl ! */
-
- if (register_netdev(&spp->dev) == 0) {
- set_bit(SIXPF_INUSE, &spp->ctrl.flags);
- spp->ctrl.dev = &spp->dev;
- spp->dev.priv = (void *) &spp->ctrl;
- SET_MODULE_OWNER(&spp->dev);
- return &spp->ctrl;
- } else {
- clear_bit(SIXPF_INUSE, &spp->ctrl.flags);
- printk(KERN_WARNING "sp_alloc() - register_netdev() failure.\n");
- }
+ if (p[0] != 0)
+ return;
+
+ /*
+ * In case of fullduplex or DAMA operation, we don't take care about the
+ * state of the DCD or of any timers, as the determination of the
+ * correct time to send is the job of the AX.25 layer. We send
+ * immediately after data has arrived.
+ */
+ if (sp->duplex == 1) {
+ sp->led_state = 0x70;
+ sp->tty->driver->write(sp->tty, 0, &sp->led_state, 1);
+ sp->tx_enable = 1;
+ actual = sp->tty->driver->write(sp->tty, 0, sp->xbuff, count);
+ sp->xleft = count - actual;
+ sp->xhead = sp->xbuff + actual;
+ sp->led_state = 0x60;
+ sp->tty->driver->write(sp->tty, 0, &sp->led_state, 1);
+ } else {
+ sp->xleft = count;
+ sp->xhead = sp->xbuff;
+ sp->status2 = count;
+ if (sp->duplex == 0)
+ sp_start_tx_timer(sp);
}
- return NULL;
+ return;
+
+out_drop:
+ sp->stats.tx_dropped++;
+ netif_start_queue(sp->dev);
+ printk(KERN_DEBUG "%s: %s - dropped.\n", sp->dev->name, msg);
+ return;
}
+/* Encapsulate an IP datagram and kick it into a TTY queue. */
+
+static int sp_xmit(struct sk_buff *skb, struct net_device *dev)
+{
+ struct sixpack *sp = netdev_priv(dev);
+
+ spin_lock_bh(&sp->lock);
+ /* We were not busy, so we are now... :-) */
+ netif_stop_queue(dev);
+ sp->stats.tx_bytes += skb->len;
+ sp_encaps(sp, skb->data, skb->len);
+ spin_unlock_bh(&sp->lock);
+
+ dev_kfree_skb(skb);
+
+ return 0;
+}
+
+static int sp_open_dev(struct net_device *dev)
+{
+ struct sixpack *sp = netdev_priv(dev);
+
+ if (sp->tty == NULL)
+ return -ENODEV;
+ return 0;
+}
+
+/* Close the low-level part of the 6pack channel. */
+static int sp_close(struct net_device *dev)
+{
+ struct sixpack *sp = netdev_priv(dev);
+
+ spin_lock_bh(&sp->lock);
+ if (sp->tty) {
+ /* TTY discipline is running. */
+ sp->tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);
+ }
+ netif_stop_queue(dev);
+ spin_unlock_bh(&sp->lock);
+
+ return 0;
+}
+
+/* Return the frame type ID */
+static int sp_header(struct sk_buff *skb, struct net_device *dev,
+ unsigned short type, void *daddr, void *saddr, unsigned len)
+{
+#ifdef CONFIG_INET
+ if (type != htons(ETH_P_AX25))
+ return ax25_encapsulate(skb, dev, type, daddr, saddr, len);
+#endif
+ return 0;
+}
+
+static struct net_device_stats *sp_get_stats(struct net_device *dev)
+{
+ struct sixpack *sp = netdev_priv(dev);
+ return &sp->stats;
+}
+
+static int sp_set_dev_mac_address(struct net_device *dev, void *addr)
+{
+ struct sockaddr *sa = addr;
+ memcpy(dev->dev_addr, sa->sa_data, AX25_ADDR_LEN);
+ return 0;
+}
+
+static int sp_rebuild_header(struct sk_buff *skb)
+{
+#ifdef CONFIG_INET
+ return ax25_rebuild_header(skb);
+#else
+ return 0;
+#endif
+}
+
+static void sp_setup(struct net_device *dev)
+{
+ static char ax25_bcast[AX25_ADDR_LEN] =
+ {'Q'<<1,'S'<<1,'T'<<1,' '<<1,' '<<1,' '<<1,'0'<<1};
+ static char ax25_test[AX25_ADDR_LEN] =
+ {'L'<<1,'I'<<1,'N'<<1,'U'<<1,'X'<<1,' '<<1,'1'<<1};
+
+ /* Finish setting up the DEVICE info. */
+ dev->init = sixpack_init;
+ dev->mtu = SIXP_MTU;
+ dev->hard_start_xmit = sp_xmit;
+ dev->open = sp_open_dev;
+ dev->destructor = free_netdev;
+ dev->stop = sp_close;
+ dev->hard_header = sp_header;
+ dev->get_stats = sp_get_stats;
+ dev->set_mac_address = sp_set_dev_mac_address;
+ dev->hard_header_len = AX25_MAX_HEADER_LEN;
+ dev->addr_len = AX25_ADDR_LEN;
+ dev->type = ARPHRD_AX25;
+ dev->tx_queue_len = 10;
+ dev->rebuild_header = sp_rebuild_header;
+ dev->tx_timeout = NULL;
+
+ /* Only activated in AX.25 mode */
+ memcpy(dev->broadcast, ax25_bcast, AX25_ADDR_LEN);
+ memcpy(dev->dev_addr, ax25_test, AX25_ADDR_LEN);
+
+ SET_MODULE_OWNER(dev);
+
+ /* New-style flags. */
+ dev->flags = 0;
+}
+
+/* Find a free 6pack channel, and link in this `tty' line. */
+static inline struct sixpack *sp_alloc(void)
+{
+ struct sixpack *sp = NULL;
+ struct net_device *dev = NULL;
+
+ dev = alloc_netdev(sizeof(struct sixpack), "sp%d", sp_setup);
+ if (!dev)
+ return NULL;
+
+ sp = netdev_priv(dev);
+ sp->dev = dev;
+
+ sp->magic = SIXPACK_MAGIC;
+ spin_lock_init(&sp->lock);
+
+ if (register_netdev(dev))
+ goto out_free;
+
+ return sp;
+
+out_free:
+ printk(KERN_WARNING "sp_alloc() - register_netdev() failure.\n");
+
+ free_netdev(dev);
+
+ return NULL;
+}
/* Free a 6pack channel. */
static inline void sp_free(struct sixpack *sp)
{
- /* Free all 6pack frame buffers. */
- if (sp->rbuff)
- kfree(sp->rbuff);
- sp->rbuff = NULL;
- if (sp->xbuff)
- kfree(sp->xbuff);
- sp->xbuff = NULL;
+ void * tmp;
- if (!test_and_clear_bit(SIXPF_INUSE, &sp->flags))
- printk(KERN_WARNING "%s: sp_free for already free unit.\n", sp->dev->name);
+ /* Free all 6pack frame buffers. */
+ if ((tmp = xchg(&sp->rbuff, NULL)) != NULL)
+ kfree(tmp);
+ if ((tmp = xchg(&sp->xbuff, NULL)) != NULL)
+ kfree(tmp);
}
/* Send one completely decapsulated IP datagram to the IP layer. */
-/* This is the routine that sends the received data to the kernel AX.25.
- 'cmd' is the KISS command. For AX.25 data, it is zero. */
+/*
+ * This is the routine that sends the received data to the kernel AX.25.
+ * 'cmd' is the KISS command. For AX.25 data, it is zero.
+ */
static void sp_bump(struct sixpack *sp, char cmd)
{
@@ -238,99 +416,35 @@
int count;
unsigned char *ptr;
- count = sp->rcount+1;
+ count = sp->rcount + 1;
sp->stats.rx_bytes += count;
- if ((skb = dev_alloc_skb(count)) == NULL) {
- printk(KERN_DEBUG "%s: memory squeeze, dropping packet.\n", sp->dev->name);
- sp->stats.rx_dropped++;
- return;
- }
+ if ((skb = dev_alloc_skb(count)) == NULL)
+ goto out_mem;
skb->dev = sp->dev;
ptr = skb_put(skb, count);
*ptr++ = cmd; /* KISS command */
- memcpy(ptr, (sp->cooked_buf)+1, count);
+ memcpy(ptr, sp->cooked_buf + 1, count);
skb->mac.raw = skb->data;
skb->protocol = htons(ETH_P_AX25);
netif_rx(skb);
sp->dev->last_rx = jiffies;
sp->stats.rx_packets++;
-}
-
-
-/* ----------------------------------------------------------------------- */
-
-/* Encapsulate one AX.25 frame and stuff into a TTY queue. */
-static void sp_encaps(struct sixpack *sp, unsigned char *icp, int len)
-{
- unsigned char *p;
- int actual, count;
- if (len > sp->mtu) { /* sp->mtu = AX25_MTU = max. PACLEN = 256 */
- printk(KERN_DEBUG "%s: truncating oversized transmit packet!\n", sp->dev->name);
- sp->stats.tx_dropped++;
- netif_start_queue(sp->dev);
- return;
- }
+ return;
- p = icp;
-
- if (p[0] > 5) {
- printk(KERN_DEBUG "%s: invalid KISS command -- dropped\n", sp->dev->name);
- netif_start_queue(sp->dev);
- return;
- }
-
- if ((p[0] != 0) && (len > 2)) {
- printk(KERN_DEBUG "%s: KISS control packet too long -- dropped\n", sp->dev->name);
- netif_start_queue(sp->dev);
- return;
- }
-
- if ((p[0] == 0) && (len < 15)) {
- printk(KERN_DEBUG "%s: bad AX.25 packet to transmit -- dropped\n", sp->dev->name);
- netif_start_queue(sp->dev);
- sp->stats.tx_dropped++;
- return;
- }
-
- count = encode_sixpack(p, (unsigned char *) sp->xbuff, len, sp->tx_delay);
- sp->tty->flags |= (1 << TTY_DO_WRITE_WAKEUP);
+out_mem:
+ if (net_ratelimit())
+ printk(KERN_ERR "%s: memory squeeze, dropping packet.\n",
+ sp->dev->name);
+ sp->stats.rx_dropped++;
+}
- switch (p[0]) {
- case 1: sp->tx_delay = p[1]; return;
- case 2: sp->persistence = p[1]; return;
- case 3: sp->slottime = p[1]; return;
- case 4: /* ignored */ return;
- case 5: sp->duplex = p[1]; return;
- }
- if (p[0] == 0) {
- /* in case of fullduplex or DAMA operation, we don't take care
- about the state of the DCD or of any timers, as the determination
- of the correct time to send is the job of the AX.25 layer. We send
- immediately after data has arrived. */
- if (sp->duplex == 1) {
- sp->led_state = 0x70;
- sp->tty->driver->write(sp->tty, 0, &sp->led_state, 1);
- sp->tx_enable = 1;
- actual = sp->tty->driver->write(sp->tty, 0, sp->xbuff, count);
- sp->xleft = count - actual;
- sp->xhead = sp->xbuff + actual;
- sp->led_state = 0x60;
- sp->tty->driver->write(sp->tty, 0, &sp->led_state, 1);
- } else {
- sp->xleft = count;
- sp->xhead = sp->xbuff;
- sp->status2 = count;
- if (sp->duplex == 0)
- sp_start_tx_timer(sp);
- }
- }
-}
+/* ----------------------------------------------------------------------- */
/*
* Called by the TTY driver when there's room for more data. If we have
@@ -365,75 +479,31 @@
/* ----------------------------------------------------------------------- */
-/* Encapsulate an IP datagram and kick it into a TTY queue. */
-
-static int sp_xmit(struct sk_buff *skb, struct net_device *dev)
-{
- struct sixpack *sp = (struct sixpack *) dev->priv;
-
- /* We were not busy, so we are now... :-) */
- netif_stop_queue(dev);
- sp->stats.tx_bytes += skb->len;
- sp_encaps(sp, skb->data, skb->len);
- dev_kfree_skb(skb);
- return 0;
-}
-
-/* perform the persistence/slottime algorithm for CSMA access. If the persistence
- check was successful, write the data to the serial driver. Note that in case
- of DAMA operation, the data is not sent here. */
-static void sp_xmit_on_air(unsigned long channel)
-{
- struct sixpack *sp = (struct sixpack *) channel;
- int actual;
- static unsigned char random;
- random = random * 17 + 41;
- if (((sp->status1 & SIXP_DCD_MASK) == 0) && (random < sp->persistence)) {
- sp->led_state = 0x70;
- sp->tty->driver->write(sp->tty, 0, &sp->led_state, 1);
- sp->tx_enable = 1;
- actual = sp->tty->driver->write(sp->tty, 0, sp->xbuff, sp->status2);
- sp->xleft -= actual;
- sp->xhead += actual;
- sp->led_state = 0x60;
- sp->tty->driver->write(sp->tty, 0, &sp->led_state, 1);
- sp->status2 = 0;
- } else
- sp_start_tx_timer(sp);
-}
-
-
-/* Return the frame type ID */
-static int sp_header(struct sk_buff *skb, struct net_device *dev, unsigned short type,
- void *daddr, void *saddr, unsigned len)
+/* Open the low-level part of the 6pack channel. */
+static int sp_open(struct net_device *dev)
{
-#ifdef CONFIG_INET
- if (type != htons(ETH_P_AX25))
- return ax25_encapsulate(skb, dev, type, daddr, saddr, len);
-#endif
- return 0;
-}
+ struct sixpack *sp = netdev_priv(dev);
+ char *rbuff, *xbuff = NULL;
+ int err = -ENOBUFS;
+ unsigned long len;
+ /* !!! length of the buffers. MTU is IP MTU, not PACLEN! */
-static int sp_rebuild_header(struct sk_buff *skb)
-{
-#ifdef CONFIG_INET
- return ax25_rebuild_header(skb);
-#else
- return 0;
-#endif
-}
+ len = dev->mtu * 2;
+ rbuff = kmalloc(len + 4, GFP_KERNEL);
+ if (rbuff == NULL)
+ goto err_exit;
+
+ xbuff = kmalloc(len + 4, GFP_KERNEL);
+ if (xbuff == NULL)
+ goto err_exit;
-/* Open the low-level part of the 6pack channel. */
-static int sp_open(struct net_device *dev)
-{
- struct sixpack *sp = (struct sixpack *) dev->priv;
- unsigned long len;
+ spin_lock_bh(&sp->lock);
if (sp->tty == NULL)
return -ENODEV;
@@ -442,21 +512,11 @@
* Allocate the 6pack frame buffers:
*
* rbuff Receive buffer.
- * xbuff Transmit buffer.
- */
-
- /* !!! length of the buffers. MTU is IP MTU, not PACLEN!
- */
-
- len = dev->mtu * 2;
-
- if ((sp->rbuff = kmalloc(len + 4, GFP_KERNEL)) == NULL)
- return -ENOMEM;
+ * xbuff Transmit buffer.
+ */
- if ((sp->xbuff = kmalloc(len + 4, GFP_KERNEL)) == NULL) {
- kfree(sp->rbuff);
- return -ENOMEM;
- }
+ rbuff = xchg(&sp->rbuff, rbuff);
+ xbuff = xchg(&sp->xbuff, xbuff);
sp->mtu = AX25_MTU + 73;
sp->buffsize = len;
@@ -465,7 +525,7 @@
sp->rx_count_cooked = 0;
sp->xleft = 0;
- sp->flags &= (1 << SIXPF_INUSE); /* Clear ESCAPE & ERROR flags */
+ sp->flags = 0; /* Clear ESCAPE & ERROR flags */
sp->duplex = 0;
sp->tx_delay = SIXP_TXDELAY;
@@ -482,24 +542,21 @@
init_timer(&sp->tx_t);
init_timer(&sp->resync_t);
- return 0;
-}
+ spin_unlock_bh(&sp->lock);
-/* Close the low-level part of the 6pack channel. */
-static int sp_close(struct net_device *dev)
-{
- struct sixpack *sp = (struct sixpack *) dev->priv;
-
- if (sp->tty == NULL)
- return -EBUSY;
+ err = 0;
- sp->tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);
+err_exit:
+ if (xbuff)
+ kfree(xbuff);
+ if (rbuff)
+ kfree(rbuff);
- netif_stop_queue(dev);
- return 0;
+ return err;
}
+
static int sixpack_receive_room(struct tty_struct *tty)
{
return 65536; /* We can handle an infinite amount of data. :-) */
@@ -513,18 +570,18 @@
* a block of 6pack data has been received, which can now be decapsulated
* and sent on to some IP layer for further processing.
*/
-static void sixpack_receive_buf(struct tty_struct *tty, const unsigned char *cp, char *fp, int count)
+static void sixpack_receive_buf(struct tty_struct *tty,
+ const unsigned char *cp, char *fp, int count)
{
+ struct sixpack *sp = (struct sixpack *) tty->disc_data;
unsigned char buf[512];
int count1;
- struct sixpack *sp = (struct sixpack *) tty->disc_data;
-
if (!sp || sp->magic != SIXPACK_MAGIC ||
!netif_running(sp->dev) || !count)
return;
- memcpy(buf, cp, count<sizeof(buf)? count:sizeof(buf));
+ memcpy(buf, cp, count < sizeof(buf) ? count : sizeof(buf));
/* Read the characters out of the buffer */
@@ -541,6 +598,61 @@
}
/*
+ * Try to resync the TNC. Called by the resync timer defined in
+ * decode_prio_command
+ */
+
+static void resync_tnc(unsigned long channel)
+{
+ static char resync_cmd = 0xe8;
+ struct sixpack *sp = (struct sixpack *) channel;
+
+ printk(KERN_INFO "6pack: resyncing TNC\n");
+
+ /* clear any data that might have been received */
+
+ sp->rx_count = 0;
+ sp->rx_count_cooked = 0;
+
+ /* reset state machine */
+
+ sp->status = 1;
+ sp->status1 = 1;
+ sp->status2 = 0;
+ sp->tnc_ok = 0;
+
+ /* resync the TNC */
+
+ sp->led_state = 0x60;
+ sp->tty->driver->write(sp->tty, 0, &sp->led_state, 1);
+ sp->tty->driver->write(sp->tty, 0, &resync_cmd, 1);
+
+
+ /* Start resync timer again -- the TNC might be still absent */
+
+ del_timer(&sp->resync_t);
+ sp->resync_t.data = (unsigned long) sp;
+ sp->resync_t.function = resync_tnc;
+ sp->resync_t.expires = jiffies + SIXP_RESYNC_TIMEOUT;
+ add_timer(&sp->resync_t);
+}
+
+static int tnc_init(struct sixpack *sp)
+{
+ unsigned char inbyte = 0xe8;
+
+ sp->tty->driver->write(sp->tty, 0, &inbyte, 1);
+
+ del_timer(&sp->resync_t);
+ sp->resync_t.data = (unsigned long) sp;
+ sp->resync_t.function = resync_tnc;
+ sp->resync_t.expires = jiffies + SIXP_RESYNC_TIMEOUT;
+ add_timer(&sp->resync_t);
+
+ return 0;
+}
+
+/*
* Open the high-level part of the 6pack channel.
* This function is called by the TTY module when the
* 6pack line discipline is called for. Because we are
@@ -552,25 +664,25 @@
struct sixpack *sp = (struct sixpack *) tty->disc_data;
int err;
- /* First make sure we're not already connected. */
+ if (!tty)
+ return -EINVAL;
- if (sp && sp->magic == SIXPACK_MAGIC)
+ if (sp)
return -EEXIST;
- /* OK. Find a free 6pack channel to use. */
- if ((sp = sp_alloc()) == NULL)
- return -ENFILE;
+ sp = sp_alloc();
+ if (!sp)
+ return -ENOMEM;
+
sp->tty = tty;
tty->disc_data = sp;
+
if (tty->driver->flush_buffer)
tty->driver->flush_buffer(tty);
if (tty->ldisc.flush_buffer)
tty->ldisc.flush_buffer(tty);
- /* Restore default settings */
- sp->dev->type = ARPHRD_AX25;
-
/* Perform the low-level 6pack initialization. */
if ((err = sp_open(sp->dev)))
return err;
@@ -579,7 +691,7 @@
tnc_init(sp);
- return sp->dev->base_addr;
+ return 0;
}
@@ -611,29 +723,14 @@
rtnl_unlock();
}
-
-static struct net_device_stats *sp_get_stats(struct net_device *dev)
-{
- struct sixpack *sp = (struct sixpack *) dev->priv;
- return &sp->stats;
-}
-
-
static int sp_set_mac_address(struct net_device *dev, void *addr)
{
return copy_from_user(dev->dev_addr, addr, AX25_ADDR_LEN) ? -EFAULT : 0;
}
-static int sp_set_dev_mac_address(struct net_device *dev, void *addr)
-{
- struct sockaddr *sa = addr;
- memcpy(dev->dev_addr, sa->sa_data, AX25_ADDR_LEN);
- return 0;
-}
-
-
/* Perform I/O control on an active 6pack channel. */
-static int sixpack_ioctl(struct tty_struct *tty, void *file, int cmd, void *arg)
+static int sixpack_ioctl(struct tty_struct *tty, struct file *file,
+ unsigned int cmd, unsigned long arg)
{
struct sixpack *sp = (struct sixpack *) tty->disc_data;
unsigned int tmp;
@@ -644,7 +741,8 @@
switch(cmd) {
case SIOCGIFNAME:
- return copy_to_user(arg, sp->dev->name, strlen(sp->dev->name) + 1) ? -EFAULT : 0;
+ return copy_to_user((void *) arg, sp->dev->name,
+ strlen(sp->dev->name) + 1) ? -EFAULT : 0;
case SIOCGIFENCAP:
return put_user(0, (int *)arg);
@@ -661,34 +759,26 @@
return 0;
case SIOCSIFHWADDR:
- return sp_set_mac_address(sp->dev, arg);
+ return sp_set_mac_address(sp->dev, (void *) arg);
/* Allow stty to read, but not set, the serial port */
case TCGETS:
case TCGETA:
- return n_tty_ioctl(tty, (struct file *) file, cmd, (unsigned long) arg);
+ return n_tty_ioctl(tty, (struct file *) file, cmd, arg);
default:
return -ENOIOCTLCMD;
}
}
-static int sp_open_dev(struct net_device *dev)
-{
- struct sixpack *sp = (struct sixpack *) dev->priv;
- if (sp->tty == NULL)
- return -ENODEV;
- return 0;
-}
-
/* Fill in our line protocol discipline */
static struct tty_ldisc sp_ldisc = {
- .magic = TTY_LDISC_MAGIC,
+ .owner = THIS_MODULE,
+ .magic = TTY_LDISC_MAGIC,
.name = "6pack",
.open = sixpack_open,
- .close = sixpack_close,
- .ioctl = (int (*)(struct tty_struct *, struct file *,
- unsigned int, unsigned long)) sixpack_ioctl,
+ .close = sixpack_close,
+ .ioctl = sixpack_ioctl,
.receive_buf = sixpack_receive_buf,
.receive_room = sixpack_receive_room,
.write_wakeup = sixpack_write_wakeup,
@@ -696,34 +786,18 @@
/* Initialize 6pack control device -- register 6pack line discipline */
-static char msg_banner[] __initdata = KERN_INFO "AX.25: 6pack driver, " SIXPACK_VERSION " (dynamic channels, max=%d)\n";
-static char msg_nomem[] __initdata = KERN_ERR "6pack: can't allocate sixpack_ctrls[] array! No 6pack available.\n";
+static char msg_banner[] __initdata = KERN_INFO "AX.25: 6pack driver, " SIXPACK_VERSION "\n";
static char msg_regfail[] __initdata = KERN_ERR "6pack: can't register line discipline (err = %d)\n";
static int __init sixpack_init_driver(void)
{
int status;
- /* Do sanity checks on maximum device parameter. */
- if (sixpack_maxdev < 4)
- sixpack_maxdev = 4;
-
- printk(msg_banner, sixpack_maxdev);
-
- sixpack_ctrls = (sixpack_ctrl_t **) kmalloc(sizeof(void*)*sixpack_maxdev, GFP_KERNEL);
- if (sixpack_ctrls == NULL) {
- printk(msg_nomem);
- return -ENOMEM;
- }
-
- /* Clear the pointer array, we allocate devices when we need them */
- memset(sixpack_ctrls, 0, sizeof(void*)*sixpack_maxdev); /* Pointers */
+ printk(msg_banner);
/* Register the provided line protocol discipline */
- if ((status = tty_register_ldisc(N_6PACK, &sp_ldisc)) != 0) {
+ if ((status = tty_register_ldisc(N_6PACK, &sp_ldisc)) != 0)
printk(msg_regfail, status);
- kfree(sixpack_ctrls);
- }
return status;
}
@@ -732,36 +806,16 @@
static void __exit sixpack_exit_driver(void)
{
- int i;
-
- if ((i = tty_register_ldisc(N_6PACK, NULL)))
- printk(msg_unregfail, i);
-
- for (i = 0; i < sixpack_maxdev; i++) {
- if (sixpack_ctrls[i]) {
- /*
- * VSV = if dev->start==0, then device
- * unregistered while close proc.
- */
- if (netif_running(&sixpack_ctrls[i]->dev))
- unregister_netdev(&sixpack_ctrls[i]->dev);
+ int ret;
- kfree(sixpack_ctrls[i]);
- }
- }
- kfree(sixpack_ctrls);
+ if ((ret = tty_register_ldisc(N_6PACK, NULL)))
+ printk(msg_unregfail, ret);
}
-
/* Initialize the 6pack driver. Called by DDI. */
static int sixpack_init(struct net_device *dev)
{
- struct sixpack *sp = (struct sixpack *) dev->priv;
-
- static char ax25_bcast[AX25_ADDR_LEN] =
- {'Q'<<1,'S'<<1,'T'<<1,' '<<1,' '<<1,' '<<1,'0'<<1};
- static char ax25_test[AX25_ADDR_LEN] =
- {'L'<<1,'I'<<1,'N'<<1,'U'<<1,'X'<<1,' '<<1,'1'<<1};
+ struct sixpack *sp = netdev_priv(dev);
if (sp == NULL) /* Allocation failed ?? */
return -ENODEV;
@@ -772,49 +826,13 @@
sp->magic = SIXPACK_MAGIC;
sp->dev = dev;
- /* Finish setting up the DEVICE info. */
- dev->mtu = SIXP_MTU;
- dev->hard_start_xmit = sp_xmit;
- dev->open = sp_open_dev;
- dev->stop = sp_close;
- dev->hard_header = sp_header;
- dev->get_stats = sp_get_stats;
- dev->set_mac_address = sp_set_dev_mac_address;
- dev->hard_header_len = AX25_MAX_HEADER_LEN;
- dev->addr_len = AX25_ADDR_LEN;
- dev->type = ARPHRD_AX25;
- dev->tx_queue_len = 10;
- dev->rebuild_header = sp_rebuild_header;
- dev->tx_timeout = NULL;
-
- memcpy(dev->broadcast, ax25_bcast, AX25_ADDR_LEN); /* Only activated in AX.25 mode */
- memcpy(dev->dev_addr, ax25_test, AX25_ADDR_LEN); /* "" "" "" "" */
-
- /* New-style flags. */
- dev->flags = 0;
-
return 0;
}
-
-
-
-/* ----> 6pack timer interrupt handler and friends. <---- */
-static void sp_start_tx_timer(struct sixpack *sp)
-{
- int when = sp->slottime;
-
- del_timer(&sp->tx_t);
- sp->tx_t.data = (unsigned long) sp;
- sp->tx_t.function = sp_xmit_on_air;
- sp->tx_t.expires = jiffies + ((when+1)*HZ)/100;
- add_timer(&sp->tx_t);
-}
-
-
/* encode an AX.25 packet into 6pack */
-static int encode_sixpack(unsigned char *tx_buf, unsigned char *tx_buf_raw, int length, unsigned char tx_delay)
+static int encode_sixpack(unsigned char *tx_buf, unsigned char *tx_buf_raw,
+ int length, unsigned char tx_delay)
{
int count = 0;
unsigned char checksum = 0, buf[400];
@@ -849,47 +867,28 @@
return raw_count;
}
+/* decode 4 sixpack-encoded bytes into 3 data bytes */
-/* decode a 6pack packet */
-
-static void
-sixpack_decode(struct sixpack *sp, unsigned char pre_rbuff[], int count)
-{
- unsigned char inbyte;
- int count1;
-
- for (count1 = 0; count1 < count; count1++) {
- inbyte = pre_rbuff[count1];
- if (inbyte == SIXP_FOUND_TNC) {
- printk(KERN_INFO "6pack: TNC found.\n");
- sp->tnc_ok = 1;
- del_timer(&sp->resync_t);
- }
- if ((inbyte & SIXP_PRIO_CMD_MASK) != 0)
- decode_prio_command(inbyte, sp);
- else if ((inbyte & SIXP_STD_CMD_MASK) != 0)
- decode_std_command(inbyte, sp);
- else if ((sp->status & SIXP_RX_DCD_MASK) == SIXP_RX_DCD_MASK)
- decode_data(inbyte, sp);
- }
-}
-
-static int tnc_init(struct sixpack *sp)
+static void decode_data(unsigned char inbyte, struct sixpack *sp)
{
- unsigned char inbyte = 0xe8;
+ unsigned char *buf;
- sp->tty->driver->write(sp->tty, 0, &inbyte, 1);
+ if (sp->rx_count != 3) {
+ sp->raw_buf[sp->rx_count++] = inbyte;
- del_timer(&sp->resync_t);
- sp->resync_t.data = (unsigned long) sp;
- sp->resync_t.function = resync_tnc;
- sp->resync_t.expires = jiffies + SIXP_RESYNC_TIMEOUT;
- add_timer(&sp->resync_t);
+ return;
+ }
- return 0;
+ buf = sp->raw_buf;
+ sp->cooked_buf[sp->rx_count_cooked++] =
+ buf[0] | ((buf[1] << 2) & 0xc0);
+ sp->cooked_buf[sp->rx_count_cooked++] =
+ (buf[1] & 0x0f) | ((buf[2] << 2) & 0xf0);
+ sp->cooked_buf[sp->rx_count_cooked++] =
+ (buf[2] & 0x03) | (inbyte << 2);
+ sp->rx_count = 0;
}
-
/* identify and execute a 6pack priority command byte */
static void decode_prio_command(unsigned char cmd, struct sixpack *sp)
@@ -916,8 +915,7 @@
cmd &= !SIXP_RX_DCD_MASK;
}
sp->status = cmd & SIXP_PRIO_DATA_MASK;
- }
- else { /* output watchdog char if idle */
+ } else { /* output watchdog char if idle */
if ((sp->status2 != 0) && (sp->duplex == 1)) {
sp->led_state = 0x70;
sp->tty->driver->write(sp->tty, 0, &sp->led_state, 1);
@@ -948,46 +946,6 @@
sp->status1 = cmd & SIXP_PRIO_DATA_MASK;
}
-/* try to resync the TNC. Called by the resync timer defined in
- decode_prio_command */
-
-static void resync_tnc(unsigned long channel)
-{
- static char resync_cmd = 0xe8;
- struct sixpack *sp = (struct sixpack *) channel;
-
- printk(KERN_INFO "6pack: resyncing TNC\n");
-
- /* clear any data that might have been received */
-
- sp->rx_count = 0;
- sp->rx_count_cooked = 0;
-
- /* reset state machine */
-
- sp->status = 1;
- sp->status1 = 1;
- sp->status2 = 0;
- sp->tnc_ok = 0;
-
- /* resync the TNC */
-
- sp->led_state = 0x60;
- sp->tty->driver->write(sp->tty, 0, &sp->led_state, 1);
- sp->tty->driver->write(sp->tty, 0, &resync_cmd, 1);
-
-
- /* Start resync timer again -- the TNC might be still absent */
-
- del_timer(&sp->resync_t);
- sp->resync_t.data = (unsigned long) sp;
- sp->resync_t.function = resync_tnc;
- sp->resync_t.expires = jiffies + SIXP_RESYNC_TIMEOUT;
- add_timer(&sp->resync_t);
-}
-
-
-
/* identify and execute a standard 6pack command byte */
static void decode_std_command(unsigned char cmd, struct sixpack *sp)
@@ -997,67 +955,70 @@
channel = cmd & SIXP_CHN_MASK;
switch (cmd & SIXP_CMD_MASK) { /* normal command */
- case SIXP_SEOF:
- if ((sp->rx_count == 0) && (sp->rx_count_cooked == 0)) {
- if ((sp->status & SIXP_RX_DCD_MASK) ==
- SIXP_RX_DCD_MASK) {
- sp->led_state = 0x68;
- sp->tty->driver->write(sp->tty, 0, &sp->led_state, 1);
- }
- } else {
- sp->led_state = 0x60;
- /* fill trailing bytes with zeroes */
+ case SIXP_SEOF:
+ if ((sp->rx_count == 0) && (sp->rx_count_cooked == 0)) {
+ if ((sp->status & SIXP_RX_DCD_MASK) ==
+ SIXP_RX_DCD_MASK) {
+ sp->led_state = 0x68;
sp->tty->driver->write(sp->tty, 0, &sp->led_state, 1);
- rest = sp->rx_count;
- if (rest != 0)
- for (i = rest; i <= 3; i++)
- decode_data(0, sp);
- if (rest == 2)
- sp->rx_count_cooked -= 2;
- else if (rest == 3)
- sp->rx_count_cooked -= 1;
- for (i = 0; i < sp->rx_count_cooked; i++)
- checksum += sp->cooked_buf[i];
- if (checksum != SIXP_CHKSUM) {
- printk(KERN_DEBUG "6pack: bad checksum %2.2x\n", checksum);
- } else {
- sp->rcount = sp->rx_count_cooked-2;
- sp_bump(sp, 0);
- }
- sp->rx_count_cooked = 0;
}
- break;
- case SIXP_TX_URUN: printk(KERN_DEBUG "6pack: TX underrun\n");
- break;
- case SIXP_RX_ORUN: printk(KERN_DEBUG "6pack: RX overrun\n");
- break;
- case SIXP_RX_BUF_OVL:
- printk(KERN_DEBUG "6pack: RX buffer overflow\n");
+ } else {
+ sp->led_state = 0x60;
+ /* fill trailing bytes with zeroes */
+ sp->tty->driver->write(sp->tty, 0, &sp->led_state, 1);
+ rest = sp->rx_count;
+ if (rest != 0)
+ for (i = rest; i <= 3; i++)
+ decode_data(0, sp);
+ if (rest == 2)
+ sp->rx_count_cooked -= 2;
+ else if (rest == 3)
+ sp->rx_count_cooked -= 1;
+ for (i = 0; i < sp->rx_count_cooked; i++)
+ checksum += sp->cooked_buf[i];
+ if (checksum != SIXP_CHKSUM) {
+ printk(KERN_DEBUG "6pack: bad checksum %2.2x\n", checksum);
+ } else {
+ sp->rcount = sp->rx_count_cooked-2;
+ sp_bump(sp, 0);
+ }
+ sp->rx_count_cooked = 0;
+ }
+ break;
+ case SIXP_TX_URUN: printk(KERN_DEBUG "6pack: TX underrun\n");
+ break;
+ case SIXP_RX_ORUN: printk(KERN_DEBUG "6pack: RX overrun\n");
+ break;
+ case SIXP_RX_BUF_OVL:
+ printk(KERN_DEBUG "6pack: RX buffer overflow\n");
}
}
-/* decode 4 sixpack-encoded bytes into 3 data bytes */
+/* decode a 6pack packet */
-static void decode_data(unsigned char inbyte, struct sixpack *sp)
+static void
+sixpack_decode(struct sixpack *sp, unsigned char pre_rbuff[], int count)
{
- unsigned char *buf;
+ unsigned char inbyte;
+ int count1;
- if (sp->rx_count != 3)
- sp->raw_buf[sp->rx_count++] = inbyte;
- else {
- buf = sp->raw_buf;
- sp->cooked_buf[sp->rx_count_cooked++] =
- buf[0] | ((buf[1] << 2) & 0xc0);
- sp->cooked_buf[sp->rx_count_cooked++] =
- (buf[1] & 0x0f) | ((buf[2] << 2) & 0xf0);
- sp->cooked_buf[sp->rx_count_cooked++] =
- (buf[2] & 0x03) | (inbyte << 2);
- sp->rx_count = 0;
+ for (count1 = 0; count1 < count; count1++) {
+ inbyte = pre_rbuff[count1];
+ if (inbyte == SIXP_FOUND_TNC) {
+ printk(KERN_INFO "6pack: TNC found.\n");
+ sp->tnc_ok = 1;
+ del_timer(&sp->resync_t);
+ }
+ if ((inbyte & SIXP_PRIO_CMD_MASK) != 0)
+ decode_prio_command(inbyte, sp);
+ else if ((inbyte & SIXP_STD_CMD_MASK) != 0)
+ decode_std_command(inbyte, sp);
+ else if ((sp->status & SIXP_RX_DCD_MASK) == SIXP_RX_DCD_MASK)
+ decode_data(inbyte, sp);
}
}
-
-MODULE_AUTHOR("Andreas Könsgen <ajk@ccac.rwth-aachen.de>");
+MODULE_AUTHOR("Ralf Baechle DO1GRB <ralf@linux-mips.org>");
MODULE_DESCRIPTION("6pack driver for AX.25");
MODULE_LICENSE("GPL");
MODULE_ALIAS_LDISC(N_6PACK);
-
To unsubscribe from this list: send the line "unsubscribe linux-hams" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Timers in 2.6.x kernels
[not found] ` <200403150806.46071.oh1mrr@nic.fi>
@ 2004-03-15 13:38 ` Ralf Baechle
0 siblings, 0 replies; 8+ messages in thread
From: Ralf Baechle @ 2004-03-15 13:38 UTC (permalink / raw)
To: Jarmo; +Cc: linux-hams
On Mon, Mar 15, 2004 at 08:06:45AM +0200, Jarmo wrote:
(Adding mailing list back to Cc list because your mail server doesn't accept
my mails)
> > Let me know how well this is working. I've tested this as well as possible
> > without having 6pack hardware myself and that's not too much ... Anyway,
> > I need testers before I send this patch upstream with good conscious and
> > that means it at least has to reach stability comparable to what's in stock
> > 2.6.4.
> >
> > This patch is also available on ftp.linux-mips.net in /pub/ham/6pack/.
> >
> > 73 de DO1GRB op Ralf
>
> Hi Ralf
>
> FB that someone tries to modernize these things.
Exactly. 6pack.c and mkiss are derived from slip.c which being an uncommon
protocol these days is also suffering from bitrot. Many of the past
updates for 6pack.c and mkiss were following the path set by slip.c ...
Admitedly, there are few good examples for how to write a line discipline
like slip. PPP is reasonably well written but a way too complex protocol
to be a good example, n_tty.c is too simple to be useful and the Linux tty
code is hard to read. So in short, there's a lack of good and simple
examples, maybe one reason of several why this code was suffering from
bitrot so badly ...
> Now,how I patch my 6pack.c...Normally I do it by command..
>
> cat "file-patch.diff" | patch -p0
>
> With this patch that does not work.
Well, you didn't say how it failed so I can only guess ...
Well, the command is right asssuming your working directory was the root
directory of the kernel source tree like in this example:
cd /usr/src/linux-2.6.4
patch -p0 < 2.6.3-6pack-6.diff
Just in case if the patch file got corrupted, ftp it from ftp.linux-mips.net
in /pub/ham/6pack/.
Ralf
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2004-03-15 13:38 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-03-12 11:10 Timers in 2.6.x kernels Jarmo
2004-03-12 19:09 ` Jeroen Vreeken
2004-03-13 14:19 ` Ralf Baechle DO1GRB
2004-03-13 14:59 ` Jarmo
2004-03-13 22:06 ` Ralf Baechle DO1GRB
2004-03-14 6:01 ` Jarmo
2004-03-15 0:51 ` Ralf Baechle DO1GRB
[not found] ` <200403150806.46071.oh1mrr@nic.fi>
2004-03-15 13:38 ` Ralf Baechle
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox