vmod/vmodttl: fixed bug related to luns not ordered and/or not starting from zero.
[ht-drivers.git] / vmod / lib / libvmod12e162dioaio.c
blobdbdcf331d58441ebc320072a836b21bf34dae845
1 /**
2 @file libvmod12e162dioaio.c
3 @brief Library file for the vmod12e16 driver
4 @author Samuel Iglesias Gonsalvez
5 @date July 6 2010
6 */
8 #include <sys/ioctl.h>
9 #include <fcntl.h>
10 #include <unistd.h>
11 #include <stdio.h>
12 #include "libvmod12e162dioaio.h"
13 #include <gm/moduletypes.h>
14 #include <ioconfiglib.h>
15 #include <dioaiolib.h>
17 #define VMOD12E16_MAX_MODULES 64
18 #define PURGE_CPUPIPELINE asm("eieio")
20 struct vmod12e16_registers {
21 unsigned short control; /**< control register (wo) */
22 unsigned short unused;
23 unsigned short ready; /**< ready status register (ro)
24 (bit 15 == 0 if ready, and then bits 11-0
25 in data register are valid) */
26 unsigned short interrupt; /**< interrupt mode get/set (rw)
27 (bit 15 == 0 iff interrupt
28 mode is in force/desired) */
31 int vmod12e16_get_handle(unsigned int carrier_lun)
33 if(carrier_lun < 0 || carrier_lun >= VMOD12E16_MAX_MODULES){
34 fprintf(stderr, "libvmod12e162dioaio : Invalid lun %d\n", carrier_lun);
35 return -1;
37 return carrier_lun;
40 int vmod12e16_convert(int fd, int channel, enum vmod12e16_amplification factor, int *datum)
42 int ret;
43 void *address;
44 struct vmod12e16_registers *reg;
46 ret = IocModulPointer(IocVMOD12E16, fd, IOC_DEFAULTP, &address);
47 if (ret < 0){
48 fprintf(stderr,"libvmod12e162dioaio: error getting the address: %d\n", ret);
49 return -1;
51 reg = (struct vmod12e16_registers *)address;
53 reg->interrupt = 0x8000; /* No interrupts*/
54 PURGE_CPUPIPELINE;
56 reg->control = channel;
57 PURGE_CPUPIPELINE;
59 while ((reg->ready & 0x8000) != 0) {};
61 *datum = reg->control & 0x0fff;
62 PURGE_CPUPIPELINE;
64 return 0;
67 int vmod12e16_close(int fd)
69 return 0;