blob: 74032d0881efab82d80b93193a2ebfc372e9bd58 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* $Id: isdn_net.h,v 1.1.2.2 2004/01/12 22:37:19 keil Exp $
2 *
3 * header for Linux ISDN subsystem, network related functions (linklevel).
4 *
5 * Copyright 1994-1999 by Fritz Elfert (fritz@isdn4linux.de)
6 * Copyright 1995,96 by Thinking Objects Software GmbH Wuerzburg
7 * Copyright 1995,96 by Michael Hipp (Michael.Hipp@student.uni-tuebingen.de)
8 *
9 * This software may be used and distributed according to the terms
10 * of the GNU General Public License, incorporated herein by reference.
11 *
12 */
13
14 /* Definitions for hupflags: */
15#define ISDN_WAITCHARGE 1 /* did not get a charge info yet */
16#define ISDN_HAVECHARGE 2 /* We know a charge info */
17#define ISDN_CHARGEHUP 4 /* We want to use the charge mechanism */
18#define ISDN_INHUP 8 /* Even if incoming, close after huptimeout */
19#define ISDN_MANCHARGE 16 /* Charge Interval manually set */
20
21/*
22 * Definitions for Cisco-HDLC header.
23 */
24
25#define CISCO_ADDR_UNICAST 0x0f
26#define CISCO_ADDR_BROADCAST 0x8f
27#define CISCO_CTRL 0x00
28#define CISCO_TYPE_CDP 0x2000
29#define CISCO_TYPE_SLARP 0x8035
30#define CISCO_SLARP_REQUEST 0
31#define CISCO_SLARP_REPLY 1
32#define CISCO_SLARP_KEEPALIVE 2
33
34extern char *isdn_net_new(char *, struct net_device *);
35extern char *isdn_net_newslave(char *);
36extern int isdn_net_rm(char *);
37extern int isdn_net_rmall(void);
38extern int isdn_net_stat_callback(int, isdn_ctrl *);
39extern int isdn_net_setcfg(isdn_net_ioctl_cfg *);
40extern int isdn_net_getcfg(isdn_net_ioctl_cfg *);
41extern int isdn_net_addphone(isdn_net_ioctl_phone *);
42extern int isdn_net_getphones(isdn_net_ioctl_phone *, char __user *);
43extern int isdn_net_getpeer(isdn_net_ioctl_phone *, isdn_net_ioctl_phone __user *);
44extern int isdn_net_delphone(isdn_net_ioctl_phone *);
45extern int isdn_net_find_icall(int, int, int, setup_parm *);
46extern void isdn_net_hangup(struct net_device *);
47extern void isdn_net_dial(void);
48extern void isdn_net_autohup(void);
49extern int isdn_net_force_hangup(char *);
50extern int isdn_net_force_dial(char *);
51extern isdn_net_dev *isdn_net_findif(char *);
52extern int isdn_net_rcv_skb(int, struct sk_buff *);
53extern int isdn_net_dial_req(isdn_net_local *);
54extern void isdn_net_writebuf_skb(isdn_net_local *lp, struct sk_buff *skb);
55extern void isdn_net_write_super(isdn_net_local *lp, struct sk_buff *skb);
56
57#define ISDN_NET_MAX_QUEUE_LENGTH 2
58
Wang Chen838361f2008-12-03 15:49:46 -080059#define ISDN_MASTER_PRIV(lp) ((isdn_net_local *) netdev_priv(lp->master))
60#define ISDN_SLAVE_PRIV(lp) ((isdn_net_local *) netdev_priv(lp->slave))
61#define MASTER_TO_SLAVE(master) \
62 (((isdn_net_local *) netdev_priv(master))->slave)
63
Linus Torvalds1da177e2005-04-16 15:20:36 -070064/*
65 * is this particular channel busy?
66 */
67static __inline__ int isdn_net_lp_busy(isdn_net_local *lp)
68{
69 if (atomic_read(&lp->frame_cnt) < ISDN_NET_MAX_QUEUE_LENGTH)
70 return 0;
71 else
72 return 1;
73}
74
75/*
76 * For the given net device, this will get a non-busy channel out of the
77 * corresponding bundle. The returned channel is locked.
78 */
79static __inline__ isdn_net_local * isdn_net_get_locked_lp(isdn_net_dev *nd)
80{
81 unsigned long flags;
82 isdn_net_local *lp;
83
84 spin_lock_irqsave(&nd->queue_lock, flags);
85 lp = nd->queue; /* get lp on top of queue */
86 spin_lock(&nd->queue->xmit_lock);
87 while (isdn_net_lp_busy(nd->queue)) {
88 spin_unlock(&nd->queue->xmit_lock);
89 nd->queue = nd->queue->next;
90 if (nd->queue == lp) { /* not found -- should never happen */
91 lp = NULL;
92 goto errout;
93 }
94 spin_lock(&nd->queue->xmit_lock);
95 }
96 lp = nd->queue;
97 nd->queue = nd->queue->next;
98 local_bh_disable();
99errout:
100 spin_unlock_irqrestore(&nd->queue_lock, flags);
101 return lp;
102}
103
104/*
105 * add a channel to a bundle
106 */
107static __inline__ void isdn_net_add_to_bundle(isdn_net_dev *nd, isdn_net_local *nlp)
108{
109 isdn_net_local *lp;
110 unsigned long flags;
111
112 spin_lock_irqsave(&nd->queue_lock, flags);
113
114 lp = nd->queue;
115// printk(KERN_DEBUG "%s: lp:%s(%p) nlp:%s(%p) last(%p)\n",
Harvey Harrison156f1ed2008-04-28 02:14:40 -0700116// __func__, lp->name, lp, nlp->name, nlp, lp->last);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 nlp->last = lp->last;
118 lp->last->next = nlp;
119 lp->last = nlp;
120 nlp->next = lp;
121 nd->queue = nlp;
122
123 spin_unlock_irqrestore(&nd->queue_lock, flags);
124}
125/*
126 * remove a channel from the bundle it belongs to
127 */
128static __inline__ void isdn_net_rm_from_bundle(isdn_net_local *lp)
129{
130 isdn_net_local *master_lp = lp;
131 unsigned long flags;
132
133 if (lp->master)
Wang Chen838361f2008-12-03 15:49:46 -0800134 master_lp = ISDN_MASTER_PRIV(lp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
136// printk(KERN_DEBUG "%s: lp:%s(%p) mlp:%s(%p) last(%p) next(%p) mndq(%p)\n",
Harvey Harrison156f1ed2008-04-28 02:14:40 -0700137// __func__, lp->name, lp, master_lp->name, master_lp, lp->last, lp->next, master_lp->netdev->queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 spin_lock_irqsave(&master_lp->netdev->queue_lock, flags);
139 lp->last->next = lp->next;
140 lp->next->last = lp->last;
141 if (master_lp->netdev->queue == lp) {
142 master_lp->netdev->queue = lp->next;
143 if (lp->next == lp) { /* last in queue */
144 master_lp->netdev->queue = master_lp->netdev->local;
145 }
146 }
147 lp->next = lp->last = lp; /* (re)set own pointers */
148// printk(KERN_DEBUG "%s: mndq(%p)\n",
Harvey Harrison156f1ed2008-04-28 02:14:40 -0700149// __func__, master_lp->netdev->queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 spin_unlock_irqrestore(&master_lp->netdev->queue_lock, flags);
151}
152