irda_device.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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>
  11. *
  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>
  15. *
  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.
  20. *
  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.
  25. *
  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
  30. *
  31. ********************************************************************/
  32. /*
  33. * This header contains all the IrDA definitions a driver really
  34. * needs, and therefore the driver should not need to include
  35. * any other IrDA headers - Jean II
  36. */
  37. #ifndef IRDA_DEVICE_H
  38. #define IRDA_DEVICE_H
  39. #include <linux/tty.h>
  40. #include <linux/netdevice.h>
  41. #include <linux/spinlock.h>
  42. #include <linux/skbuff.h> /* struct sk_buff */
  43. #include <linux/irda.h>
  44. #include <linux/types.h>
  45. #include <net/pkt_sched.h>
  46. #include <net/irda/irda.h>
  47. #include <net/irda/qos.h> /* struct qos_info */
  48. #include <net/irda/irqueue.h> /* irda_queue_t */
  49. /* A few forward declarations (to make compiler happy) */
  50. struct irlap_cb;
  51. /* Some non-standard interface flags (should not conflict with any in if.h) */
  52. #define IFF_SIR 0x0001 /* Supports SIR speeds */
  53. #define IFF_MIR 0x0002 /* Supports MIR speeds */
  54. #define IFF_FIR 0x0004 /* Supports FIR speeds */
  55. #define IFF_VFIR 0x0008 /* Supports VFIR speeds */
  56. #define IFF_PIO 0x0010 /* Supports PIO transfer of data */
  57. #define IFF_DMA 0x0020 /* Supports DMA transfer of data */
  58. #define IFF_SHM 0x0040 /* Supports shared memory data transfers */
  59. #define IFF_DONGLE 0x0080 /* Interface has a dongle attached */
  60. #define IFF_AIR 0x0100 /* Supports Advanced IR (AIR) standards */
  61. #define IO_XMIT 0x01
  62. #define IO_RECV 0x02
  63. typedef enum {
  64. IRDA_IRLAP, /* IrDA mode, and deliver to IrLAP */
  65. IRDA_RAW, /* IrDA mode */
  66. SHARP_ASK,
  67. TV_REMOTE, /* Also known as Consumer Electronics IR */
  68. } INFRARED_MODE;
  69. typedef enum {
  70. IRDA_TASK_INIT, /* All tasks are initialized with this state */
  71. IRDA_TASK_DONE, /* Signals that the task is finished */
  72. IRDA_TASK_WAIT,
  73. IRDA_TASK_WAIT1,
  74. IRDA_TASK_WAIT2,
  75. IRDA_TASK_WAIT3,
  76. IRDA_TASK_CHILD_INIT, /* Initializing child task */
  77. IRDA_TASK_CHILD_WAIT, /* Waiting for child task to finish */
  78. IRDA_TASK_CHILD_DONE /* Child task is finished */
  79. } IRDA_TASK_STATE;
  80. struct irda_task;
  81. typedef int (*IRDA_TASK_CALLBACK) (struct irda_task *task);
  82. struct irda_task {
  83. irda_queue_t q;
  84. magic_t magic;
  85. IRDA_TASK_STATE state;
  86. IRDA_TASK_CALLBACK function;
  87. IRDA_TASK_CALLBACK finished;
  88. struct irda_task *parent;
  89. struct timer_list timer;
  90. void *instance; /* Instance being called */
  91. void *param; /* Parameter to be used by instance */
  92. };
  93. /* Dongle info */
  94. struct dongle_reg;
  95. typedef struct {
  96. struct dongle_reg *issue; /* Registration info */
  97. struct net_device *dev; /* Device we are attached to */
  98. struct irda_task *speed_task; /* Task handling speed change */
  99. struct irda_task *reset_task; /* Task handling reset */
  100. __u32 speed; /* Current speed */
  101. /* Callbacks to the IrDA device driver */
  102. int (*set_mode)(struct net_device *, int mode);
  103. int (*read)(struct net_device *dev, __u8 *buf, int len);
  104. int (*write)(struct net_device *dev, __u8 *buf, int len);
  105. int (*set_dtr_rts)(struct net_device *dev, int dtr, int rts);
  106. } dongle_t;
  107. /* Dongle registration info */
  108. struct dongle_reg {
  109. irda_queue_t q; /* Must be first */
  110. IRDA_DONGLE type;
  111. void (*open)(dongle_t *dongle, struct qos_info *qos);
  112. void (*close)(dongle_t *dongle);
  113. int (*reset)(struct irda_task *task);
  114. int (*change_speed)(struct irda_task *task);
  115. struct module *owner;
  116. };
  117. /*
  118. * Per-packet information we need to hide inside sk_buff
  119. * (must not exceed 48 bytes, check with struct sk_buff)
  120. */
  121. struct irda_skb_cb {
  122. magic_t magic; /* Be sure that we can trust the information */
  123. __u32 next_speed; /* The Speed to be set *after* this frame */
  124. __u16 mtt; /* Minimum turn around time */
  125. __u16 xbofs; /* Number of xbofs required, used by SIR mode */
  126. __u16 next_xbofs; /* Number of xbofs required *after* this frame */
  127. void *context; /* May be used by drivers */
  128. void (*destructor)(struct sk_buff *skb); /* Used for flow control */
  129. __u16 xbofs_delay; /* Number of xbofs used for generating the mtt */
  130. __u8 line; /* Used by IrCOMM in IrLPT mode */
  131. };
  132. /* Chip specific info */
  133. typedef struct {
  134. int cfg_base; /* Config register IO base */
  135. int sir_base; /* SIR IO base */
  136. int fir_base; /* FIR IO base */
  137. int mem_base; /* Shared memory base */
  138. int sir_ext; /* Length of SIR iobase */
  139. int fir_ext; /* Length of FIR iobase */
  140. int irq, irq2; /* Interrupts used */
  141. int dma, dma2; /* DMA channel(s) used */
  142. int fifo_size; /* FIFO size */
  143. int irqflags; /* interrupt flags (ie, IRQF_SHARED|IRQF_DISABLED) */
  144. int direction; /* Link direction, used by some FIR drivers */
  145. int enabled; /* Powered on? */
  146. int suspended; /* Suspended by APM */
  147. __u32 speed; /* Currently used speed */
  148. __u32 new_speed; /* Speed we must change to when Tx is finished */
  149. int dongle_id; /* Dongle or transceiver currently used */
  150. } chipio_t;
  151. /* IO buffer specific info (inspired by struct sk_buff) */
  152. typedef struct {
  153. int state; /* Receiving state (transmit state not used) */
  154. int in_frame; /* True if receiving frame */
  155. __u8 *head; /* start of buffer */
  156. __u8 *data; /* start of data in buffer */
  157. int len; /* current length of data */
  158. int truesize; /* total allocated size of buffer */
  159. __u16 fcs;
  160. struct sk_buff *skb; /* ZeroCopy Rx in async_unwrap_char() */
  161. } iobuff_t;
  162. /* Maximum SIR frame (skb) that we expect to receive *unwrapped*.
  163. * Max LAP MTU (I field) is 2048 bytes max (IrLAP 1.1, chapt 6.6.5, p40).
  164. * Max LAP header is 2 bytes (for now).
  165. * Max CRC is 2 bytes at SIR, 4 bytes at FIR.
  166. * Need 1 byte for skb_reserve() to align IP header for IrLAN.
  167. * Add a few extra bytes just to be safe (buffer is power of two anyway)
  168. * Jean II */
  169. #define IRDA_SKB_MAX_MTU 2064
  170. /* Maximum SIR frame that we expect to send, wrapped (i.e. with XBOFS
  171. * and escaped characters on top of above). */
  172. #define IRDA_SIR_MAX_FRAME 4269
  173. /* The SIR unwrapper async_unwrap_char() will use a Rx-copy-break mechanism
  174. * when using the optional ZeroCopy Rx, where only small frames are memcpy
  175. * to a smaller skb to save memory. This is the threshold under which copy
  176. * will happen (and over which it won't happen).
  177. * Some FIR drivers may use this #define as well...
  178. * This is the same value as various Ethernet drivers. - Jean II */
  179. #define IRDA_RX_COPY_THRESHOLD 256
  180. /* Function prototypes */
  181. int irda_device_init(void);
  182. void irda_device_cleanup(void);
  183. /* IrLAP entry points used by the drivers.
  184. * We declare them here to avoid the driver pulling a whole bunch stack
  185. * headers they don't really need - Jean II */
  186. struct irlap_cb *irlap_open(struct net_device *dev, struct qos_info *qos,
  187. const char *hw_name);
  188. void irlap_close(struct irlap_cb *self);
  189. /* Interface to be uses by IrLAP */
  190. void irda_device_set_media_busy(struct net_device *dev, int status);
  191. int irda_device_is_media_busy(struct net_device *dev);
  192. int irda_device_is_receiving(struct net_device *dev);
  193. /* Interface for internal use */
  194. static inline int irda_device_txqueue_empty(const struct net_device *dev)
  195. {
  196. return skb_queue_empty(&dev->qdisc->q);
  197. }
  198. int irda_device_set_raw_mode(struct net_device* self, int status);
  199. struct net_device *alloc_irdadev(int sizeof_priv);
  200. /* Dongle interface */
  201. void irda_device_unregister_dongle(struct dongle_reg *dongle);
  202. int irda_device_register_dongle(struct dongle_reg *dongle);
  203. dongle_t *irda_device_dongle_init(struct net_device *dev, int type);
  204. int irda_device_dongle_cleanup(dongle_t *dongle);
  205. void irda_setup_dma(int channel, dma_addr_t buffer, int count, int mode);
  206. void irda_task_delete(struct irda_task *task);
  207. struct irda_task *irda_task_execute(void *instance,
  208. IRDA_TASK_CALLBACK function,
  209. IRDA_TASK_CALLBACK finished,
  210. struct irda_task *parent, void *param);
  211. void irda_task_next_state(struct irda_task *task, IRDA_TASK_STATE state);
  212. /*
  213. * Function irda_get_mtt (skb)
  214. *
  215. * Utility function for getting the minimum turnaround time out of
  216. * the skb, where it has been hidden in the cb field.
  217. */
  218. static inline __u16 irda_get_mtt(const struct sk_buff *skb)
  219. {
  220. const struct irda_skb_cb *cb = (const struct irda_skb_cb *) skb->cb;
  221. return (cb->magic == LAP_MAGIC) ? cb->mtt : 10000;
  222. }
  223. /*
  224. * Function irda_get_next_speed (skb)
  225. *
  226. * Extract the speed that should be set *after* this frame from the skb
  227. *
  228. * Note : return -1 for user space frames
  229. */
  230. static inline __u32 irda_get_next_speed(const struct sk_buff *skb)
  231. {
  232. const struct irda_skb_cb *cb = (const struct irda_skb_cb *) skb->cb;
  233. return (cb->magic == LAP_MAGIC) ? cb->next_speed : -1;
  234. }
  235. /*
  236. * Function irda_get_next_xbofs (skb)
  237. *
  238. * Extract the xbofs that should be set for this frame from the skb
  239. *
  240. * Note : default to 10 for user space frames
  241. */
  242. static inline __u16 irda_get_xbofs(const struct sk_buff *skb)
  243. {
  244. const struct irda_skb_cb *cb = (const struct irda_skb_cb *) skb->cb;
  245. return (cb->magic == LAP_MAGIC) ? cb->xbofs : 10;
  246. }
  247. /*
  248. * Function irda_get_next_xbofs (skb)
  249. *
  250. * Extract the xbofs that should be set *after* this frame from the skb
  251. *
  252. * Note : return -1 for user space frames
  253. */
  254. static inline __u16 irda_get_next_xbofs(const struct sk_buff *skb)
  255. {
  256. const struct irda_skb_cb *cb = (const struct irda_skb_cb *) skb->cb;
  257. return (cb->magic == LAP_MAGIC) ? cb->next_xbofs : -1;
  258. }
  259. #endif /* IRDA_DEVICE_H */