@@ -47,6 +47,7 @@ MODULE_LICENSE("GPL v2");
struct hfidd_global hfidd_global;
EXPORT_SYMBOL_GPL(hfidd_global);
+struct device *hfidd_class_dev[MAX_HFIS + 1];
static dev_t hfidd_dev;
#define MAX_HFI_DEVS (MAX_HFIS + 1)
@@ -71,6 +72,38 @@ static const struct file_operations hfidd_fops = {
.write = hfidd_cmd_write,
};
+/* Create the hfi device */
+static int hfidd_mkdev(int ai, struct hfidd_acs *p_acs)
+{
+ char dname[128];
+ int rc = 0;
+
+ sprintf(dname, "%s%d", HFIDD_DEV_NAME, ai);
+
+ hfidd_class_dev[ai] = device_create(hfidd_global.class,
+ NULL, MKDEV(MAJOR(hfidd_dev), ai),
+ (void *)p_acs, (char *)dname);
+
+ if (IS_ERR(hfidd_class_dev[ai])) {
+ rc = PTR_ERR(hfidd_class_dev[ai]);
+ printk(KERN_ERR "%s: hfidd_mkdev: device_create for ai=%d fail"
+ " rc = %d\n", dname, ai, rc);
+ return rc;
+ }
+
+ if (ai == MAX_HFIS)
+ return 0;
+
+ p_acs->hfidd_dev = hfidd_class_dev[ai];
+ return rc;
+}
+
+/* delete the hfi device, /dev/hfi* files and sysclass files */
+static void hfidd_rmdev(int ai)
+{
+ device_destroy(hfidd_global.class, MKDEV(MAJOR(hfidd_dev), ai));
+}
+
/* Destroy the HFI class */
static inline void hfidd_destroy_class(void)
{
@@ -129,6 +162,8 @@ static void hfidd_destroy_devices(void)
hfidd_global.p_acs[i] = NULL;
hfidd_global.acs_cnt--;
}
+ for (i = 0; i <= MAX_HFIS; i++)
+ hfidd_rmdev(i);
}
/*
@@ -156,6 +191,23 @@ static int hfidd_create_devices(void)
}
hfidd_global.acs_cnt++;
}
+
+ for (i = 0; i <= MAX_HFIS; i++) {
+ rc = hfidd_mkdev(i, hfidd_global.p_acs[i]);
+ if (rc) {
+ for (j = 0; j < i; j++)
+ hfidd_rmdev(j);
+ goto hfidd_create_devices_error0;
+ }
+ }
+ return 0;
+
+hfidd_create_devices_error0:
+ for (i = 0; i < MAX_HFIS; i++) {
+ hfidd_free_adapter(hfidd_global.p_acs[i]);
+ hfidd_global.p_acs[i] = NULL;
+ hfidd_global.acs_cnt--;
+ }
return rc;
}
@@ -54,6 +54,7 @@ struct hfidd_acs {
unsigned int index;
unsigned int acs_cnt;
unsigned int state;
+ struct device *hfidd_dev;
};
/* DD global */