irda_device.h 11.5 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1 2 3 4 5 6 7 8 9 10 11 12 13
/*********************************************************************
 *                
 * Filename:      irda_device.h
 * Version:       0.9
 * Description:   Contains various declarations used by the drivers
 * Status:        Experimental.
 * Author:        Dag Brattli <dagb@cs.uit.no>
 * Created at:    Tue Apr 14 12:41:42 1998
 * Modified at:   Mon Mar 20 09:08:57 2000
 * Modified by:   Dag Brattli <dagb@cs.uit.no>
 * 
 *     Copyright (c) 1999-2000 Dag Brattli, All Rights Reserved.
 *     Copyright (c) 1998 Thomas Davis, <ratbert@radiks.net>,
14
 *     Copyright (c) 2000-2002 Jean Tourrilhes <jt@hpl.hp.com>
Linus Torvalds's avatar
Linus Torvalds committed
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
 *
 *     This program is free software; you can redistribute it and/or 
 *     modify it under the terms of the GNU General Public License as 
 *     published by the Free Software Foundation; either version 2 of 
 *     the License, or (at your option) any later version.
 * 
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *     GNU General Public License for more details.
 * 
 *     You should have received a copy of the GNU General Public License 
 *     along with this program; if not, write to the Free Software 
 *     Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
 *     MA 02111-1307 USA
 *     
 ********************************************************************/

33 34 35 36 37 38
/*
 * This header contains all the IrDA definitions a driver really
 * needs, and therefore the driver should not need to include
 * any other IrDA headers - Jean II
 */

Linus Torvalds's avatar
Linus Torvalds committed
39 40 41 42 43 44
#ifndef IRDA_DEVICE_H
#define IRDA_DEVICE_H

#include <linux/tty.h>
#include <linux/netdevice.h>
#include <linux/spinlock.h>
45
#include <linux/skbuff.h>		/* struct sk_buff */
Linus Torvalds's avatar
Linus Torvalds committed
46 47
#include <linux/irda.h>

48
#include <net/pkt_sched.h>
Linus Torvalds's avatar
Linus Torvalds committed
49
#include <net/irda/irda.h>
50 51 52 53 54
#include <net/irda/qos.h>		/* struct qos_info */
#include <net/irda/irqueue.h>		/* irda_queue_t */

/* A few forward declarations (to make compiler happy) */
struct irlap_cb;
Linus Torvalds's avatar
Linus Torvalds committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131

/* Some non-standard interface flags (should not conflict with any in if.h) */
#define IFF_SIR 	0x0001 /* Supports SIR speeds */
#define IFF_MIR 	0x0002 /* Supports MIR speeds */
#define IFF_FIR 	0x0004 /* Supports FIR speeds */
#define IFF_VFIR        0x0008 /* Supports VFIR speeds */
#define IFF_PIO   	0x0010 /* Supports PIO transfer of data */
#define IFF_DMA		0x0020 /* Supports DMA transfer of data */
#define IFF_SHM         0x0040 /* Supports shared memory data transfers */
#define IFF_DONGLE      0x0080 /* Interface has a dongle attached */
#define IFF_AIR         0x0100 /* Supports Advanced IR (AIR) standards */

#define IO_XMIT 0x01
#define IO_RECV 0x02

typedef enum {
	IRDA_IRLAP, /* IrDA mode, and deliver to IrLAP */
	IRDA_RAW,   /* IrDA mode */
	SHARP_ASK,
	TV_REMOTE,  /* Also known as Consumer Electronics IR */
} INFRARED_MODE;

typedef enum {
	IRDA_TASK_INIT,        /* All tasks are initialized with this state */
	IRDA_TASK_DONE,        /* Signals that the task is finished */
	IRDA_TASK_WAIT,
	IRDA_TASK_WAIT1,
	IRDA_TASK_WAIT2,
	IRDA_TASK_WAIT3,
	IRDA_TASK_CHILD_INIT,  /* Initializing child task */
	IRDA_TASK_CHILD_WAIT,  /* Waiting for child task to finish */
	IRDA_TASK_CHILD_DONE   /* Child task is finished */
} IRDA_TASK_STATE;

struct irda_task;
typedef int (*IRDA_TASK_CALLBACK) (struct irda_task *task);

struct irda_task {
	irda_queue_t q;
	magic_t magic;

	IRDA_TASK_STATE state;
	IRDA_TASK_CALLBACK function;
	IRDA_TASK_CALLBACK finished;

	struct irda_task *parent;
	struct timer_list timer;

	void *instance; /* Instance being called */
	void *param;    /* Parameter to be used by instance */
};

/* Dongle info */
struct dongle_reg;
typedef struct {
	struct dongle_reg *issue;     /* Registration info */
	struct net_device *dev;           /* Device we are attached to */
	struct irda_task *speed_task; /* Task handling speed change */
	struct irda_task *reset_task; /* Task handling reset */
	__u32 speed;                  /* Current speed */

	/* Callbacks to the IrDA device driver */
	int (*set_mode)(struct net_device *, int mode);
	int (*read)(struct net_device *dev, __u8 *buf, int len);
	int (*write)(struct net_device *dev, __u8 *buf, int len);
	int (*set_dtr_rts)(struct net_device *dev, int dtr, int rts);
} dongle_t;

/* Dongle registration info */
struct dongle_reg {
	irda_queue_t q;         /* Must be first */
	IRDA_DONGLE type;

	void (*open)(dongle_t *dongle, struct qos_info *qos);
	void (*close)(dongle_t *dongle);
	int  (*reset)(struct irda_task *task);
	int  (*change_speed)(struct irda_task *task);
132
	struct module *owner;
Linus Torvalds's avatar
Linus Torvalds committed
133 134
};

135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
/* 
 * Per-packet information we need to hide inside sk_buff 
 * (must not exceed 48 bytes, check with struct sk_buff) 
 */
struct irda_skb_cb {
	magic_t magic;       /* Be sure that we can trust the information */
	__u32   next_speed;  /* The Speed to be set *after* this frame */
	__u16   mtt;         /* Minimum turn around time */
	__u16   xbofs;       /* Number of xbofs required, used by SIR mode */
	__u16   next_xbofs;  /* Number of xbofs required *after* this frame */
	void    *context;    /* May be used by drivers */
	void    (*destructor)(struct sk_buff *skb); /* Used for flow control */
	__u16   xbofs_delay; /* Number of xbofs used for generating the mtt */
	__u8    line;        /* Used by IrCOMM in IrLPT mode */
};

Linus Torvalds's avatar
Linus Torvalds committed
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
/* Chip specific info */
typedef struct {
	int cfg_base;         /* Config register IO base */
        int sir_base;         /* SIR IO base */
	int fir_base;         /* FIR IO base */
	int mem_base;         /* Shared memory base */
        int sir_ext;          /* Length of SIR iobase */
	int fir_ext;          /* Length of FIR iobase */
        int irq, irq2;        /* Interrupts used */
        int dma, dma2;        /* DMA channel(s) used */
        int fifo_size;        /* FIFO size */
        int irqflags;         /* interrupt flags (ie, SA_SHIRQ|SA_INTERRUPT) */
	int direction;        /* Link direction, used by some FIR drivers */
	int enabled;          /* Powered on? */
	int suspended;        /* Suspended by APM */
	__u32 speed;          /* Currently used speed */
	__u32 new_speed;      /* Speed we must change to when Tx is finished */
	int dongle_id;        /* Dongle or transceiver currently used */
} chipio_t;

/* IO buffer specific info (inspired by struct sk_buff) */
typedef struct {
	int state;            /* Receiving state (transmit state not used) */
	int in_frame;         /* True if receiving frame */

	__u8 *head;	      /* start of buffer */
	__u8 *data;	      /* start of data in buffer */

179 180
	int len;	      /* current length of data */
	int truesize;	      /* total allocated size of buffer */
Linus Torvalds's avatar
Linus Torvalds committed
181
	__u16 fcs;
182 183

	struct sk_buff *skb;	/* ZeroCopy Rx in async_unwrap_char() */
Linus Torvalds's avatar
Linus Torvalds committed
184 185
} iobuff_t;

186 187 188 189 190 191 192 193 194 195 196 197 198 199
/* Maximum SIR frame (skb) that we expect to receive *unwrapped*.
 * Max LAP MTU (I field) is 2048 bytes max (IrLAP 1.1, chapt 6.6.5, p40).
 * Max LAP header is 2 bytes (for now).
 * Max CRC is 2 bytes at SIR, 4 bytes at FIR. 
 * Need 1 byte for skb_reserve() to align IP header for IrLAN.
 * Add a few extra bytes just to be safe (buffer is power of two anyway)
 * Jean II */
#define IRDA_SKB_MAX_MTU	2064
/* Maximum SIR frame that we expect to send, wrapped (i.e. with XBOFS
 * and escaped characters on top of above). */
#define IRDA_SIR_MAX_FRAME	4269

/* The SIR unwrapper async_unwrap_char() will use a Rx-copy-break mechanism
 * when using the optional ZeroCopy Rx, where only small frames are memcpy
200
 * to a smaller skb to save memory. This is the threshold under which copy
201 202 203 204 205
 * will happen (and over which it won't happen).
 * Some FIR drivers may use this #define as well...
 * This is the same value as various Ethernet drivers. - Jean II */
#define IRDA_RX_COPY_THRESHOLD  256

Linus Torvalds's avatar
Linus Torvalds committed
206 207 208 209
/* Function prototypes */
int  irda_device_init(void);
void irda_device_cleanup(void);

210 211 212 213
/* IrLAP entry points used by the drivers.
 * We declare them here to avoid the driver pulling a whole bunch stack
 * headers they don't really need - Jean II */
struct irlap_cb *irlap_open(struct net_device *dev, struct qos_info *qos,
214
			    const char *hw_name);
215 216
void irlap_close(struct irlap_cb *self);

Linus Torvalds's avatar
Linus Torvalds committed
217 218 219 220 221 222
/* Interface to be uses by IrLAP */
void irda_device_set_media_busy(struct net_device *dev, int status);
int  irda_device_is_media_busy(struct net_device *dev);
int  irda_device_is_receiving(struct net_device *dev);

/* Interface for internal use */
223 224 225 226
static inline int irda_device_txqueue_empty(const struct net_device *dev)
{
	return (skb_queue_len(&dev->qdisc->q) == 0);
}
Linus Torvalds's avatar
Linus Torvalds committed
227 228 229
int  irda_device_set_raw_mode(struct net_device* self, int status);
int  irda_device_set_dtr_rts(struct net_device *dev, int dtr, int rts);
int  irda_device_change_speed(struct net_device *dev, __u32 speed);
230
void irda_device_setup(struct net_device *dev);
231
struct net_device *alloc_irdadev(int sizeof_priv);
Linus Torvalds's avatar
Linus Torvalds committed
232 233 234 235 236 237 238

/* Dongle interface */
void irda_device_unregister_dongle(struct dongle_reg *dongle);
int  irda_device_register_dongle(struct dongle_reg *dongle);
dongle_t *irda_device_dongle_init(struct net_device *dev, int type);
int irda_device_dongle_cleanup(dongle_t *dongle);

Jean Tourrilhes's avatar
Jean Tourrilhes committed
239
#ifdef CONFIG_ISA
240
void irda_setup_dma(int channel, char *buffer, int count, int mode);
Jean Tourrilhes's avatar
Jean Tourrilhes committed
241
#endif
Linus Torvalds's avatar
Linus Torvalds committed
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279

void irda_task_delete(struct irda_task *task);
struct irda_task *irda_task_execute(void *instance, 
				    IRDA_TASK_CALLBACK function, 
				    IRDA_TASK_CALLBACK finished, 
				    struct irda_task *parent, void *param);
void irda_task_next_state(struct irda_task *task, IRDA_TASK_STATE state);

/*
 * Function irda_get_mtt (skb)
 *
 *    Utility function for getting the minimum turnaround time out of 
 *    the skb, where it has been hidden in the cb field.
 */
#define irda_get_mtt(skb) (                                                 \
        IRDA_MIN(10000,                                                     \
                  (((struct irda_skb_cb *) skb->cb)->magic == LAP_MAGIC) ?  \
                          ((struct irda_skb_cb *)(skb->cb))->mtt : 10000    \
                 )							    \
)

#if 0
extern inline __u16 irda_get_mtt(struct sk_buff *skb)
{
	__u16 mtt;

	if (((struct irda_skb_cb *)(skb->cb))->magic != LAP_MAGIC)
		mtt = 10000;
	else
		mtt = ((struct irda_skb_cb *)(skb->cb))->mtt;

	ASSERT(mtt <= 10000, return 10000;);
	
	return mtt;
}
#endif

/*
Linus Torvalds's avatar
Linus Torvalds committed
280
 * Function irda_get_next_speed (skb)
Linus Torvalds's avatar
Linus Torvalds committed
281
 *
Linus Torvalds's avatar
Linus Torvalds committed
282
 *    Extract the speed that should be set *after* this frame from the skb
Linus Torvalds's avatar
Linus Torvalds committed
283
 *
Linus Torvalds's avatar
Linus Torvalds committed
284
 * Note : return -1 for user space frames
Linus Torvalds's avatar
Linus Torvalds committed
285
 */
Linus Torvalds's avatar
Linus Torvalds committed
286
#define irda_get_next_speed(skb) (	                                        \
Linus Torvalds's avatar
Linus Torvalds committed
287
	(((struct irda_skb_cb*) skb->cb)->magic == LAP_MAGIC) ? 	\
Linus Torvalds's avatar
Linus Torvalds committed
288
                  ((struct irda_skb_cb *)(skb->cb))->next_speed : -1 	\
Linus Torvalds's avatar
Linus Torvalds committed
289 290 291
)

#if 0
Linus Torvalds's avatar
Linus Torvalds committed
292
extern inline __u32 irda_get_next_speed(struct sk_buff *skb)
Linus Torvalds's avatar
Linus Torvalds committed
293 294 295 296
{
	__u32 speed;

	if (((struct irda_skb_cb *)(skb->cb))->magic != LAP_MAGIC)
Linus Torvalds's avatar
Linus Torvalds committed
297
		speed = -1;
Linus Torvalds's avatar
Linus Torvalds committed
298
	else
Linus Torvalds's avatar
Linus Torvalds committed
299
		speed = ((struct irda_skb_cb *)(skb->cb))->next_speed;
Linus Torvalds's avatar
Linus Torvalds committed
300 301 302 303 304

	return speed;
}
#endif

Linus Torvalds's avatar
Linus Torvalds committed
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
/*
 * Function irda_get_next_xbofs (skb)
 *
 *    Extract the xbofs that should be set for this frame from the skb
 *
 * Note : default to 10 for user space frames
 */
#define irda_get_xbofs(skb) (	                                        \
	(((struct irda_skb_cb*) skb->cb)->magic == LAP_MAGIC) ? 	\
                  ((struct irda_skb_cb *)(skb->cb))->xbofs : 10 	\
)

/*
 * Function irda_get_next_xbofs (skb)
 *
 *    Extract the xbofs that should be set *after* this frame from the skb
 *
 * Note : return -1 for user space frames
 */
#define irda_get_next_xbofs(skb) (	                                        \
	(((struct irda_skb_cb*) skb->cb)->magic == LAP_MAGIC) ? 	\
                  ((struct irda_skb_cb *)(skb->cb))->next_xbofs : -1 	\
)

Linus Torvalds's avatar
Linus Torvalds committed
329 330 331
#endif /* IRDA_DEVICE_H */