vmod/vmodttl: fixed bug related to luns not ordered and/or not starting from zero.
[ht-drivers.git] / vmod / lib / libvmoddor2dioaio.c
blob6a944ac7ac7ad8db5974292b5d73b78a99acbc57
1 #include <stdio.h>
2 #include <gm/moduletypes.h>
3 #include <dioaiolib.h>
4 #include "libvmoddor2dioaio.h"
6 #define VMODDOR_MAX_BOARDS 64
7 #define MAX_SIZE 5
8 #define MAX_OFFSET 6
9 static short int offset_to_group [MAX_OFFSET][MAX_SIZE] = /* Translate from offset to groups */
10 {{-1, -1, 2, -1, 0}, /* that are used in dioaiolib */
11 {-1, -1, 0, -1, -1},
12 {-1, 2, -1, -1, -1},
13 {-1, 0, -1, -1, -1},
14 {-1, 3, -1, -1, -1},
15 {-1, 1, -1, -1, -1}};
17 static void print_error(int error);
19 int vmoddor_open(int lun)
21 if(lun < 0 || lun >= VMODDOR_MAX_BOARDS){
22 fprintf(stderr, "libvmoddor2dioaio : Invalid lun %d\n", lun);
23 return -1;
26 return lun;
29 int vmoddor_close(int lun)
31 return 0;
34 int vmoddor_write(int lun , struct vmoddor_warg val)
36 int ret;
37 int group_no;
38 int size = val.size / 4;
40 group_no = offset_to_group[val.offset][size];
42 /* The size in dioaiolib means 4 bits in VMODDOR case. */
43 ret = DioStrobeWrite(IocVMODDOR, group_no, size, 0, 20, 80, val.data);
45 if (ret < 0)
46 print_error(ret);
48 return ret;
51 static void print_error(int error)
53 switch(error){
54 case -dio_system_errno:
55 fprintf(stderr, dio_err1msg);
56 break;
57 case -dio_bad_key:
58 fprintf(stderr, dio_err8msg);
59 break;
60 case -dio_cannot_find_shared_table:
61 fprintf(stderr, dio_err7msg);
62 break;
63 case -dio_cannot_map_shared_table:
64 fprintf(stderr, dio_err6msg);
65 break;
66 case -dio_odd_group_no_and_even_size:
67 fprintf(stderr, dio_err5msg);
68 break;
69 case -dio_bad_size:
70 fprintf(stderr, dio_err4msg);
71 break;
72 case -dio_bad_group:
73 fprintf(stderr, dio_err3msg);
74 break;
75 case -dio_no_direct_access_allowed:
76 fprintf(stderr, dio_err2msg);
77 break;
78 case -dio_lun_out_of_range:
79 fprintf(stderr, dio_err9msg);
80 break;
81 case -dio_no_module_of_this_type:
82 fprintf(stderr, dio_err10msg);
83 break;
84 default:
85 break;