mm-only debug patch...
[mmotm.git] / include / net / irda / irda_device.h
blob94c852d47d0f8d5c7d033279bf2f67ca3fd861dd
1 /*********************************************************************
2 *
3 * Filename: irda_device.h
4 * Version: 0.9
5 * Description: Contains various declarations used by the drivers
6 * Status: Experimental.
7 * Author: Dag Brattli <dagb@cs.uit.no>
8 * Created at: Tue Apr 14 12:41:42 1998
9 * Modified at: Mon Mar 20 09:08:57 2000
10 * Modified by: Dag Brattli <dagb@cs.uit.no>
12 * Copyright (c) 1999-2000 Dag Brattli, All Rights Reserved.
13 * Copyright (c) 1998 Thomas Davis, <ratbert@radiks.net>,
14 * Copyright (c) 2000-2002 Jean Tourrilhes <jt@hpl.hp.com>
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License as
18 * published by the Free Software Foundation; either version 2 of
19 * the License, or (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 * MA 02111-1307 USA
31 ********************************************************************/
34 * This header contains all the IrDA definitions a driver really
35 * needs, and therefore the driver should not need to include
36 * any other IrDA headers - Jean II
39 #ifndef IRDA_DEVICE_H
40 #define IRDA_DEVICE_H
42 #include <linux/tty.h>
43 #include <linux/netdevice.h>
44 #include <linux/spinlock.h>
45 #include <linux/skbuff.h> /* struct sk_buff */
46 #include <linux/irda.h>
47 #include <linux/types.h>
49 #include <net/pkt_sched.h>
50 #include <net/irda/irda.h>
51 #include <net/irda/qos.h> /* struct qos_info */
52 #include <net/irda/irqueue.h> /* irda_queue_t */
54 /* A few forward declarations (to make compiler happy) */
55 struct irlap_cb;
57 /* Some non-standard interface flags (should not conflict with any in if.h) */
58 #define IFF_SIR 0x0001 /* Supports SIR speeds */
59 #define IFF_MIR 0x0002 /* Supports MIR speeds */
60 #define IFF_FIR 0x0004 /* Supports FIR speeds */
61 #define IFF_VFIR 0x0008 /* Supports VFIR speeds */
62 #define IFF_PIO 0x0010 /* Supports PIO transfer of data */
63 #define IFF_DMA 0x0020 /* Supports DMA transfer of data */
64 #define IFF_SHM 0x0040 /* Supports shared memory data transfers */
65 #define IFF_DONGLE 0x0080 /* Interface has a dongle attached */
66 #define IFF_AIR 0x0100 /* Supports Advanced IR (AIR) standards */
68 #define IO_XMIT 0x01
69 #define IO_RECV 0x02
71 typedef enum {
72 IRDA_IRLAP, /* IrDA mode, and deliver to IrLAP */
73 IRDA_RAW, /* IrDA mode */
74 SHARP_ASK,
75 TV_REMOTE, /* Also known as Consumer Electronics IR */
76 } INFRARED_MODE;
78 typedef enum {
79 IRDA_TASK_INIT, /* All tasks are initialized with this state */
80 IRDA_TASK_DONE, /* Signals that the task is finished */
81 IRDA_TASK_WAIT,
82 IRDA_TASK_WAIT1,
83 IRDA_TASK_WAIT2,
84 IRDA_TASK_WAIT3,
85 IRDA_TASK_CHILD_INIT, /* Initializing child task */
86 IRDA_TASK_CHILD_WAIT, /* Waiting for child task to finish */
87 IRDA_TASK_CHILD_DONE /* Child task is finished */
88 } IRDA_TASK_STATE;
90 struct irda_task;
91 typedef int (*IRDA_TASK_CALLBACK) (struct irda_task *task);
93 struct irda_task {
94 irda_queue_t q;
95 magic_t magic;
97 IRDA_TASK_STATE state;
98 IRDA_TASK_CALLBACK function;
99 IRDA_TASK_CALLBACK finished;
101 struct irda_task *parent;
102 struct timer_list timer;
104 void *instance; /* Instance being called */
105 void *param; /* Parameter to be used by instance */
108 /* Dongle info */
109 struct dongle_reg;
110 typedef struct {
111 struct dongle_reg *issue; /* Registration info */
112 struct net_device *dev; /* Device we are attached to */
113 struct irda_task *speed_task; /* Task handling speed change */
114 struct irda_task *reset_task; /* Task handling reset */
115 __u32 speed; /* Current speed */
117 /* Callbacks to the IrDA device driver */
118 int (*set_mode)(struct net_device *, int mode);
119 int (*read)(struct net_device *dev, __u8 *buf, int len);
120 int (*write)(struct net_device *dev, __u8 *buf, int len);
121 int (*set_dtr_rts)(struct net_device *dev, int dtr, int rts);
122 } dongle_t;
124 /* Dongle registration info */
125 struct dongle_reg {
126 irda_queue_t q; /* Must be first */
127 IRDA_DONGLE type;
129 void (*open)(dongle_t *dongle, struct qos_info *qos);
130 void (*close)(dongle_t *dongle);
131 int (*reset)(struct irda_task *task);
132 int (*change_speed)(struct irda_task *task);
133 struct module *owner;
137 * Per-packet information we need to hide inside sk_buff
138 * (must not exceed 48 bytes, check with struct sk_buff)
139 * The default_qdisc_pad field is a temporary hack.
141 struct irda_skb_cb {
142 unsigned int default_qdisc_pad;
143 magic_t magic; /* Be sure that we can trust the information */
144 __u32 next_speed; /* The Speed to be set *after* this frame */
145 __u16 mtt; /* Minimum turn around time */
146 __u16 xbofs; /* Number of xbofs required, used by SIR mode */
147 __u16 next_xbofs; /* Number of xbofs required *after* this frame */
148 void *context; /* May be used by drivers */
149 void (*destructor)(struct sk_buff *skb); /* Used for flow control */
150 __u16 xbofs_delay; /* Number of xbofs used for generating the mtt */
151 __u8 line; /* Used by IrCOMM in IrLPT mode */
154 /* Chip specific info */
155 typedef struct {
156 int cfg_base; /* Config register IO base */
157 int sir_base; /* SIR IO base */
158 int fir_base; /* FIR IO base */
159 int mem_base; /* Shared memory base */
160 int sir_ext; /* Length of SIR iobase */
161 int fir_ext; /* Length of FIR iobase */
162 int irq, irq2; /* Interrupts used */
163 int dma, dma2; /* DMA channel(s) used */
164 int fifo_size; /* FIFO size */
165 int irqflags; /* interrupt flags (ie, IRQF_SHARED|IRQF_DISABLED) */
166 int direction; /* Link direction, used by some FIR drivers */
167 int enabled; /* Powered on? */
168 int suspended; /* Suspended by APM */
169 __u32 speed; /* Currently used speed */
170 __u32 new_speed; /* Speed we must change to when Tx is finished */
171 int dongle_id; /* Dongle or transceiver currently used */
172 } chipio_t;
174 /* IO buffer specific info (inspired by struct sk_buff) */
175 typedef struct {
176 int state; /* Receiving state (transmit state not used) */
177 int in_frame; /* True if receiving frame */
179 __u8 *head; /* start of buffer */
180 __u8 *data; /* start of data in buffer */
182 int len; /* current length of data */
183 int truesize; /* total allocated size of buffer */
184 __u16 fcs;
186 struct sk_buff *skb; /* ZeroCopy Rx in async_unwrap_char() */
187 } iobuff_t;
189 /* Maximum SIR frame (skb) that we expect to receive *unwrapped*.
190 * Max LAP MTU (I field) is 2048 bytes max (IrLAP 1.1, chapt 6.6.5, p40).
191 * Max LAP header is 2 bytes (for now).
192 * Max CRC is 2 bytes at SIR, 4 bytes at FIR.
193 * Need 1 byte for skb_reserve() to align IP header for IrLAN.
194 * Add a few extra bytes just to be safe (buffer is power of two anyway)
195 * Jean II */
196 #define IRDA_SKB_MAX_MTU 2064
197 /* Maximum SIR frame that we expect to send, wrapped (i.e. with XBOFS
198 * and escaped characters on top of above). */
199 #define IRDA_SIR_MAX_FRAME 4269
201 /* The SIR unwrapper async_unwrap_char() will use a Rx-copy-break mechanism
202 * when using the optional ZeroCopy Rx, where only small frames are memcpy
203 * to a smaller skb to save memory. This is the threshold under which copy
204 * will happen (and over which it won't happen).
205 * Some FIR drivers may use this #define as well...
206 * This is the same value as various Ethernet drivers. - Jean II */
207 #define IRDA_RX_COPY_THRESHOLD 256
209 /* Function prototypes */
210 int irda_device_init(void);
211 void irda_device_cleanup(void);
213 /* IrLAP entry points used by the drivers.
214 * We declare them here to avoid the driver pulling a whole bunch stack
215 * headers they don't really need - Jean II */
216 struct irlap_cb *irlap_open(struct net_device *dev, struct qos_info *qos,
217 const char *hw_name);
218 void irlap_close(struct irlap_cb *self);
220 /* Interface to be uses by IrLAP */
221 void irda_device_set_media_busy(struct net_device *dev, int status);
222 int irda_device_is_media_busy(struct net_device *dev);
223 int irda_device_is_receiving(struct net_device *dev);
225 /* Interface for internal use */
226 static inline int irda_device_txqueue_empty(const struct net_device *dev)
228 return qdisc_all_tx_empty(dev);
230 int irda_device_set_raw_mode(struct net_device* self, int status);
231 struct net_device *alloc_irdadev(int sizeof_priv);
233 void irda_setup_dma(int channel, dma_addr_t buffer, int count, int mode);
236 * Function irda_get_mtt (skb)
238 * Utility function for getting the minimum turnaround time out of
239 * the skb, where it has been hidden in the cb field.
241 static inline __u16 irda_get_mtt(const struct sk_buff *skb)
243 const struct irda_skb_cb *cb = (const struct irda_skb_cb *) skb->cb;
244 return (cb->magic == LAP_MAGIC) ? cb->mtt : 10000;
248 * Function irda_get_next_speed (skb)
250 * Extract the speed that should be set *after* this frame from the skb
252 * Note : return -1 for user space frames
254 static inline __u32 irda_get_next_speed(const struct sk_buff *skb)
256 const struct irda_skb_cb *cb = (const struct irda_skb_cb *) skb->cb;
257 return (cb->magic == LAP_MAGIC) ? cb->next_speed : -1;
261 * Function irda_get_next_xbofs (skb)
263 * Extract the xbofs that should be set for this frame from the skb
265 * Note : default to 10 for user space frames
267 static inline __u16 irda_get_xbofs(const struct sk_buff *skb)
269 const struct irda_skb_cb *cb = (const struct irda_skb_cb *) skb->cb;
270 return (cb->magic == LAP_MAGIC) ? cb->xbofs : 10;
274 * Function irda_get_next_xbofs (skb)
276 * Extract the xbofs that should be set *after* this frame from the skb
278 * Note : return -1 for user space frames
280 static inline __u16 irda_get_next_xbofs(const struct sk_buff *skb)
282 const struct irda_skb_cb *cb = (const struct irda_skb_cb *) skb->cb;
283 return (cb->magic == LAP_MAGIC) ? cb->next_xbofs : -1;
285 #endif /* IRDA_DEVICE_H */