vmod/vmodttl: fixed bug related to luns not ordered and/or not starting from zero.
[ht-drivers.git] / vmod / driver / lunargs.c
blobb7966dcc6f72c1ad9645c7067fa9c1bb34664cee
1 #include <linux/kernel.h>
2 #include <linux/module.h>
3 #include "modulbus_register.h"
4 #include "lunargs.h"
6 #define PFX "VMOD args: "
8 /* module parameters */
9 static int lun[VMOD_MAX_BOARDS];
10 static unsigned int num_lun;
11 module_param_array(lun, int, &num_lun, S_IRUGO);
12 MODULE_PARM_DESC(lun, "Logical Unit Number of the VMOD-XXX board");
14 static char *carrier[VMOD_MAX_BOARDS];
15 static unsigned int num_carrier;
16 module_param_array(carrier, charp, &num_carrier, S_IRUGO);
17 MODULE_PARM_DESC(carrier, "Name of the carrier in which the VMOD-XXX is plugged in.");
19 static int carrier_number[VMOD_MAX_BOARDS];
20 static unsigned int num_carrier_number;
21 module_param_array(carrier_number, int, &num_carrier_number, S_IRUGO);
22 MODULE_PARM_DESC(carrier_number, "Logical Unit Number of the carrier");
24 static int slot[VMOD_MAX_BOARDS];
25 static unsigned int num_slot;
26 module_param_array(slot, int, &num_slot, S_IRUGO);
27 MODULE_PARM_DESC(slot, "Slot of the carrier in which the VMOD-XXX board is placed.");
29 static int set_module_params(struct vmod_dev *module,
30 int lun, char *cname, int carrier_lun, int slot)
32 gas_t get_address_space;
33 struct carrier_as as, *asp = &as;
35 /* Sanity check parameters */
36 if (lun < 0) {
37 printk(KERN_ERR PFX "invalid lun: %d\n", lun);
38 return -1;
40 get_address_space = modulbus_carrier_as_entry(cname);
41 if (get_address_space == NULL) {
42 printk(KERN_ERR PFX "No carrier %s\n", cname);
43 return -1;
44 } else
45 printk(KERN_INFO PFX
46 "Carrier %s get_address_space entry point at %p\n",
47 cname, get_address_space);
48 if (get_address_space(asp, carrier_lun, slot, 1) < 0){
49 printk(KERN_ERR PFX
50 "Invalid carrier number: %d or slot: %d\n",
51 carrier_lun, slot);
52 return -1;
55 /* Parameters OK, go ahead */
56 module->lun = lun;
57 module->carrier_name = cname;
58 module->carrier_lun = carrier_lun;
59 module->slot = slot;
60 module->address = asp->address;
61 module->is_big_endian = asp->is_big_endian;
62 return 0;
65 int read_params(char *driver_name, struct vmod_devices *devs)
67 int i, device;
69 /* check that all insmod argument vectors are the same length */
70 if (num_lun != num_carrier || num_lun != num_carrier_number ||
71 num_lun != num_slot || num_lun >= VMOD_MAX_BOARDS) {
72 printk(KERN_ERR PFX "the number of parameters doesn't match or is invalid\n");
73 return -1;
76 device = 0;
77 for (i=0; i < num_lun ; i++) {
78 int ret;
79 struct vmod_dev *module = &devs->module[i];
81 printk(KERN_INFO PFX
82 "configuring %s lun %d\n", driver_name, lun[i]);
83 ret = set_module_params(module,
84 lun[i], carrier[i], carrier_number[i], slot[i]);
85 if (ret != 0)
86 return -1;
88 device++;
89 printk(KERN_INFO PFX
90 "module<%02d>: lun %d"
91 " carrier %s carrier_number = %d slot = %d"
92 " address 0x%08lx endian = %d\n",
93 i, module->lun, module->carrier_name,
94 module->carrier_lun, module->slot,
95 module->address, module->is_big_endian);
97 devs->num_modules = device;
99 return 0;
102 int lun_to_index(struct vmod_devices *devs, int lun)
104 int i;
106 for (i = 0; i < devs->num_modules; i++)
107 if (lun == devs->module[i].lun)
108 return i;
109 return -1;