66 static ec_master_t *masters; /**< Array of masters. */ |
67 static ec_master_t *masters; /**< Array of masters. */ |
67 static struct semaphore master_sem; /**< Master semaphore. */ |
68 static struct semaphore master_sem; /**< Master semaphore. */ |
68 static unsigned int master_count; /**< Number of masters. */ |
69 static unsigned int master_count; /**< Number of masters. */ |
69 static unsigned int backup_count; /**< Number of backup devices. */ |
70 static unsigned int backup_count; /**< Number of backup devices. */ |
70 |
71 |
|
72 static dev_t device_number; /**< Device number for cdevs. */ |
|
73 |
71 static uint8_t macs[MAX_MASTERS][2][ETH_ALEN]; /**< MAC addresses. */ |
74 static uint8_t macs[MAX_MASTERS][2][ETH_ALEN]; /**< MAC addresses. */ |
72 |
75 |
73 char *ec_master_version_str = EC_MASTER_VERSION; /**< Version string. */ |
76 char *ec_master_version_str = EC_MASTER_VERSION; /**< Version string. */ |
74 |
77 |
75 /*****************************************************************************/ |
78 /*****************************************************************************/ |
90 |
93 |
91 /*****************************************************************************/ |
94 /*****************************************************************************/ |
92 |
95 |
93 /** Module initialization. |
96 /** Module initialization. |
94 * |
97 * |
95 * Initializes \a ec_master_count masters. |
98 * Initializes \a master_count masters. |
96 * \return 0 on success, else < 0 |
99 * \return 0 on success, else < 0 |
97 */ |
100 */ |
98 int __init ec_init_module(void) |
101 int __init ec_init_module(void) |
99 { |
102 { |
100 int i, ret = 0; |
103 int i, ret = 0; |
117 EC_ERR("Failed to add module kobject.\n"); |
120 EC_ERR("Failed to add module kobject.\n"); |
118 ret = -EEXIST; |
121 ret = -EEXIST; |
119 goto out_put; |
122 goto out_put; |
120 } |
123 } |
121 |
124 |
|
125 if (alloc_chrdev_region(&device_number, 0, master_count, "EtherCAT")) { |
|
126 EC_ERR("Failed to obtain device number(s)!\n"); |
|
127 ret = -EBUSY; |
|
128 goto out_del; |
|
129 } |
|
130 |
122 // zero MAC addresses |
131 // zero MAC addresses |
123 memset(macs, 0x00, sizeof(uint8_t) * MAX_MASTERS * 2 * ETH_ALEN); |
132 memset(macs, 0x00, sizeof(uint8_t) * MAX_MASTERS * 2 * ETH_ALEN); |
124 |
133 |
125 // process MAC parameters |
134 // process MAC parameters |
126 for (i = 0; i < master_count; i++) { |
135 for (i = 0; i < master_count; i++) { |
127 if (ec_mac_parse(macs[i][0], main_devices[i], 0)) { |
136 if (ec_mac_parse(macs[i][0], main_devices[i], 0)) { |
128 ret = -EINVAL; |
137 ret = -EINVAL; |
129 goto out_del; |
138 goto out_cdev; |
130 } |
139 } |
131 |
140 |
132 if (i < backup_count && ec_mac_parse(macs[i][1], backup_devices[i], 1)) { |
141 if (i < backup_count && ec_mac_parse(macs[i][1], backup_devices[i], 1)) { |
133 ret = -EINVAL; |
142 ret = -EINVAL; |
134 goto out_del; |
143 goto out_cdev; |
135 } |
144 } |
136 } |
145 } |
137 |
146 |
138 if (master_count) { |
147 if (master_count) { |
139 if (!(masters = kmalloc(sizeof(ec_master_t) * master_count, |
148 if (!(masters = kmalloc(sizeof(ec_master_t) * master_count, |
140 GFP_KERNEL))) { |
149 GFP_KERNEL))) { |
141 EC_ERR("Failed to allocate memory for EtherCAT masters.\n"); |
150 EC_ERR("Failed to allocate memory for EtherCAT masters.\n"); |
142 ret = -ENOMEM; |
151 ret = -ENOMEM; |
143 goto out_del; |
152 goto out_cdev; |
144 } |
153 } |
145 } |
154 } |
146 |
155 |
147 for (i = 0; i < master_count; i++) { |
156 for (i = 0; i < master_count; i++) { |
148 if (ec_master_init(&masters[i], &kobj, i, macs[i][0], macs[i][1])) { |
157 if (ec_master_init(&masters[i], &kobj, i, macs[i][0], macs[i][1], |
|
158 device_number)) { |
149 ret = -EIO; |
159 ret = -EIO; |
150 goto out_free_masters; |
160 goto out_free_masters; |
151 } |
161 } |
152 } |
162 } |
153 |
163 |