vmod/vmodttl: fixed bug related to luns not ordered and/or not starting from zero.
[ht-drivers.git] / vmebridge / driver / vmebus.h
blobde13a37a64f25075ebdc8d482d75c7a35f927889
1 /**
2 * \file vmebus.h
3 * \brief PCI-VME public API
4 * \author Sebastien Dugue
5 * \date 04/02/2009
7 * This API presents in fact 2 APIs with some common definitions. One for
8 * drivers and one for user applications. User applications cannot use the
9 * driver specific parts enclosed in \#ifdef __KERNEL__ sections.
11 * Copyright (c) 2009 \em Sebastien \em Dugue
13 * \par License:
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
21 #ifndef _VME_H
22 #define _VME_H
24 #ifdef __KERNEL__
25 #include <linux/device.h>
26 #include <linux/kernel.h>
27 #endif /* __KERNEL__ */
29 #include <linux/types.h>
32 * VME window attributes
35 /**
36 * \brief Read prefetch size
38 enum vme_read_prefetch_size {
39 VME_PREFETCH_2 = 0,
40 VME_PREFETCH_4,
41 VME_PREFETCH_8,
42 VME_PREFETCH_16
45 /**
46 * \brief Data width
48 enum vme_data_width {
49 VME_D8 = 8,
50 VME_D16 = 16,
51 VME_D32 = 32,
52 VME_D64 = 64
55 /**
56 * \brief 2eSST data transfer speed
58 enum vme_2esst_mode {
59 VME_SST160 = 0,
60 VME_SST267,
61 VME_SST320
64 /**
65 * \brief Address modifiers
67 enum vme_address_modifier {
68 VME_A64_MBLT = 0, /* 0x00 */
69 VME_A64_SCT, /* 0x01 */
70 VME_A64_BLT = 3, /* 0x03 */
71 VME_A64_LCK, /* 0x04 */
72 VME_A32_LCK, /* 0x05 */
73 VME_A32_USER_MBLT = 8, /* 0x08 */
74 VME_A32_USER_DATA_SCT, /* 0x09 */
75 VME_A32_USER_PRG_SCT, /* 0x0a */
76 VME_A32_USER_BLT, /* 0x0b */
77 VME_A32_SUP_MBLT, /* 0x0c */
78 VME_A32_SUP_DATA_SCT, /* 0x0d */
79 VME_A32_SUP_PRG_SCT, /* 0x0e */
80 VME_A32_SUP_BLT, /* 0x0f */
81 VME_2e6U = 0x20, /* 0x20 */
82 VME_2e3U, /* 0x21 */
83 VME_A16_USER = 0x29, /* 0x29 */
84 VME_A16_LCK = 0x2c, /* 0x2c */
85 VME_A16_SUP = 0x2d, /* 0x2d */
86 VME_CR_CSR = 0x2f, /* 0x2f */
87 VME_A40_SCT = 0x34, /* 0x34 */
88 VME_A40_LCK, /* 0x35 */
89 VME_A40_BLT = 0x37, /* 0x37 */
90 VME_A24_USER_MBLT, /* 0x38 */
91 VME_A24_USER_DATA_SCT, /* 0x39 */
92 VME_A24_USER_PRG_SCT, /* 0x3a */
93 VME_A24_USER_BLT, /* 0x3b */
94 VME_A24_SUP_MBLT, /* 0x3c */
95 VME_A24_SUP_DATA_SCT, /* 0x3d */
96 VME_A24_SUP_PRG_SCT, /* 0x3e */
97 VME_A24_SUP_BLT, /* 0x3f */
103 * \brief PCI-VME mapping descriptor
104 * \param window_num Hardware window number
105 * \param kernel_va Kernel virtual address of the mapping for use by drivers
106 * \param user_va User virtual address of the mapping for use by applications
107 * \param fd User file descriptor for this mapping
108 * \param window_enabled State of the hardware window
109 * \param data_width VME data width
110 * \param am VME address modifier
111 * \param read_prefetch_enabled PCI read prefetch enabled state
112 * \param read_prefetch_size PCI read prefetch size (in cache lines)
113 * \param v2esst_mode VME 2eSST transfer speed
114 * \param bcast_select VME 2eSST broadcast select
115 * \param pci_addru PCI bus start address upper 32 bits
116 * \param pci_addrl PCI bus start address lower 32 bits
117 * \param sizeu Window size upper 32 bits
118 * \param sizel Window size lower 32 bits
119 * \param vme_addru VME bus start address upper 32 bits
120 * \param vme_addrl VME bus start address lower 32 bits
122 * This data structure is used for describing both a hardware window
123 * and a logical mapping on top of a hardware window. Therefore some of
124 * the fields are only relevant to one of those two entities.
126 struct vme_mapping {
127 int window_num;
129 /* Reserved for kernel use */
130 void *kernel_va;
132 /* Reserved for userspace */
133 void *user_va;
134 int fd;
136 /* Window settings */
137 int window_enabled;
138 enum vme_data_width data_width;
139 enum vme_address_modifier am;
140 int read_prefetch_enabled;
141 enum vme_read_prefetch_size read_prefetch_size;
142 enum vme_2esst_mode v2esst_mode;
143 int bcast_select;
144 unsigned int pci_addru;
145 unsigned int pci_addrl;
146 unsigned int sizeu;
147 unsigned int sizel;
148 unsigned int vme_addru;
149 unsigned int vme_addrl;
153 * \brief VME RMW descriptor
154 * \param vme_addru VME address for the RMW cycle upper 32 bits
155 * \param vme_addrl VME address for the RMW cycle lower 32 bits
156 * \param am VME address modifier
157 * \param enable_mask Bitmask of the bit
158 * \param compare_data
159 * \param swap_data
162 struct vme_rmw {
163 unsigned int vme_addru;
164 unsigned int vme_addrl;
165 enum vme_address_modifier am;
166 unsigned int enable_mask;
167 unsigned int compare_data;
168 unsigned int swap_data;
172 * \brief DMA endpoint attributes
173 * \param data_width VME data width (only used if endpoint is on the VME bus)
174 * \param am VME address modifier (ditto)
175 * \param v2esst_mode VME 2eSST transfer speed (ditto)
176 * \param bcast_select VME 2eSST broadcast select (ditto)
177 * \param addru Address upper 32 bits
178 * \param addrl Address lower 32 bits
180 * This data structure is used for describing the attributes of a DMA endpoint.
181 * All the field excepted for the address are only relevant for an endpoint
182 * on the VME bus.
184 struct vme_dma_attr {
185 enum vme_data_width data_width;
186 enum vme_address_modifier am;
187 enum vme_2esst_mode v2esst_mode;
188 unsigned int bcast_select;
189 unsigned int addru;
190 unsigned int addrl;
193 /** \brief DMA block size on the PCI or VME bus */
194 enum vme_dma_block_size {
195 VME_DMA_BSIZE_32 = 0,
196 VME_DMA_BSIZE_64,
197 VME_DMA_BSIZE_128,
198 VME_DMA_BSIZE_256,
199 VME_DMA_BSIZE_512,
200 VME_DMA_BSIZE_1024,
201 VME_DMA_BSIZE_2048,
202 VME_DMA_BSIZE_4096
205 /** \brief DMA backoff time (us) on the PCI or VME bus */
206 enum vme_dma_backoff {
207 VME_DMA_BACKOFF_0 = 0,
208 VME_DMA_BACKOFF_1,
209 VME_DMA_BACKOFF_2,
210 VME_DMA_BACKOFF_4,
211 VME_DMA_BACKOFF_8,
212 VME_DMA_BACKOFF_16,
213 VME_DMA_BACKOFF_32,
214 VME_DMA_BACKOFF_64
218 * \brief DMA control
219 * \param vme_block_size VME bus block size when the source is VME
220 * \param vme_backoff_time VME bus backoff time when the source is VME
221 * \param pci_block_size PCI/X bus block size when the source is PCI
222 * \param pci_backoff_time PCI bus backoff time when the source is PCI
225 struct vme_dma_ctrl {
226 enum vme_dma_block_size vme_block_size;
227 enum vme_dma_backoff vme_backoff_time;
228 enum vme_dma_block_size pci_block_size;
229 enum vme_dma_backoff pci_backoff_time;
232 /** \brief DMA transfer direction */
233 enum vme_dma_dir {
234 VME_DMA_TO_DEVICE = 1,
235 VME_DMA_FROM_DEVICE
239 * \brief VME DMA transfer descriptor
240 * \param status Transfer status
241 * \param length Transfer size in bytes
242 * \param novmeinc Must be set to 1 when accessing a FIFO like device on the VME
243 * \param dir Transfer direction
244 * \param src Transfer source attributes
245 * \param dst Transfer destination attributes
246 * \param opt Transfer control
249 struct vme_dma {
250 unsigned int status;
251 unsigned int length;
252 unsigned int novmeinc;
253 enum vme_dma_dir dir;
255 struct vme_dma_attr src;
256 struct vme_dma_attr dst;
258 struct vme_dma_ctrl ctrl;
262 * \brief VME Bus Error
263 * \param address Address of the bus error
264 * \param am Address Modifier of the bus error
266 struct vme_bus_error {
267 __u64 address;
268 enum vme_address_modifier am;
272 * \brief VME Bus Error descriptor
273 * \param error Address/AM of the bus error
274 * \param valid Valid Flag: 0 -> no error, 1 -> error
276 struct vme_bus_error_desc {
277 struct vme_bus_error error;
278 int valid;
282 /*! @name VME single access swapping policy
285 #define SINGLE_NO_SWAP 0
286 #define SINGLE_AUTO_SWAP 1
287 #define SINGLE_WORD_SWAP 2
288 #define SINGLE_BYTEWORD_SWAP 3
289 /*@}*/
292 /*! @name page qualifier
296 #define VME_PG_SHARED 0x00
297 #define VME_PG_PRIVATE 0x02
298 /*@}*/
302 * \brief VME mapping attributes
303 * \param iack VME IACK 0 -> IACK pages
304 * \param rdpref VME read prefetch option 0 -> Disable
305 * \param wrpost VME write posting option
306 * \param swap VME swap options
307 * \param sgmin page descriptor number returned by find_controller
308 * \param dum -- dum[0] page qualifier (shared/private), dum[1] XPC ADP-type
309 * dum[2] - reserved, _must_ be 0.
311 * This structure is used for the find_controller() and return_controller()
312 * LynxOS CES driver emulation.
314 struct pdparam_master
316 unsigned long iack;
317 unsigned long rdpref;
318 unsigned long wrpost;
319 unsigned long swap;
320 unsigned long sgmin;
321 unsigned long dum[3];
327 * \name Window management ioctl numbers
328 * \{
330 /** Get a physical window attributes */
331 #define VME_IOCTL_GET_WINDOW_ATTR _IOWR('V', 0, struct vme_mapping)
332 /** Create a physical window */
333 #define VME_IOCTL_CREATE_WINDOW _IOW( 'V', 1, struct vme_mapping)
334 /** Destroy a physical window */
335 #define VME_IOCTL_DESTROY_WINDOW _IOW( 'V', 2, int)
336 /** Create a mapping over a physical window */
337 #define VME_IOCTL_FIND_MAPPING _IOWR('V', 3, struct vme_mapping)
338 /** Remove a mapping */
339 #define VME_IOCTL_RELEASE_MAPPING _IOW( 'V', 4, struct vme_mapping)
340 /** Get the create on find failed flag */
341 #define VME_IOCTL_GET_CREATE_ON_FIND_FAIL _IOR( 'V', 5, unsigned int)
342 /** Set the create on find failed flag */
343 #define VME_IOCTL_SET_CREATE_ON_FIND_FAIL _IOW( 'V', 6, unsigned int)
344 /** Get the destroy on remove flag */
345 #define VME_IOCTL_GET_DESTROY_ON_REMOVE _IOR( 'V', 7, unsigned int)
346 /** Set the destroy on remove flag */
347 #define VME_IOCTL_SET_DESTROY_ON_REMOVE _IOW( 'V', 8, unsigned int)
348 /** Get bus error status -- DEPRECATED */
349 #define VME_IOCTL_GET_BUS_ERROR _IOR( 'V', 9, unsigned int)
350 /** Check (and possibly clear) the bus error status */
351 #define VME_IOCTL_CHECK_CLEAR_BUS_ERROR _IOWR('V',10, struct vme_bus_error_desc)
352 /* \}*/
355 * DMA ioctls
356 * \{
358 /** Start a DMA transfer */
359 #define VME_IOCTL_START_DMA _IOWR('V', 10, struct vme_dma)
360 /* \}*/
363 #ifdef __KERNEL__
366 * Those definitions are for drivers only and are not visible to userspace.
369 struct vme_driver {
370 int (*match)(struct device *, unsigned int);
371 int (*probe)(struct device *, unsigned int);
372 int (*remove)(struct device *, unsigned int);
373 void (*shutdown)(struct device *, unsigned int);
374 int (*suspend)(struct device *, unsigned int, pm_message_t);
375 int (*resume)(struct device *, unsigned int);
376 struct device_driver driver;
377 struct device *devices;
380 #define to_vme_driver(x) container_of((x), struct vme_driver, driver)
382 typedef void (*vme_berr_handler_t)(struct vme_bus_error *);
384 /* API for new drivers */
385 extern int vme_register_driver(struct vme_driver *vme_driver, unsigned int ndev);
386 extern void vme_unregister_driver(struct vme_driver *vme_driver);
387 extern int vme_request_irq(unsigned int, int (*)(void *),
388 void *, const char *);
389 extern int vme_free_irq(unsigned int );
390 extern int vme_generate_interrupt(int, int, signed long);
392 extern struct vme_mapping* find_vme_mapping_from_addr(unsigned);
393 extern int vme_get_window_attr(struct vme_mapping *);
394 extern int vme_create_window(struct vme_mapping *);
395 extern int vme_destroy_window(int);
396 extern int vme_find_mapping(struct vme_mapping *, int);
397 extern int vme_release_mapping(struct vme_mapping *, int);
399 extern int vme_do_dma(struct vme_dma *);
400 extern int vme_do_dma_kernel(struct vme_dma *);
403 extern int vme_bus_error_check(int);
404 extern struct vme_berr_handler *
405 vme_register_berr_handler(struct vme_bus_error *, size_t, vme_berr_handler_t);
406 extern void vme_unregister_berr_handler(struct vme_berr_handler *);
408 /* API providing an emulation of the CES VME driver for legacy drivers */
409 extern unsigned long find_controller(unsigned long, unsigned long,
410 unsigned long, unsigned long,
411 unsigned long, struct pdparam_master *);
412 extern unsigned long return_controller(unsigned, unsigned);
413 extern int vme_intset(int, int (*)(void *), void *, void *);
414 extern int vme_intclr(int, void *);
416 #endif /* __KERNEL__ */
419 #endif /* _VME_H */