69 static unsigned int master_count; /**< Number of masters. */ |
68 static unsigned int master_count; /**< Number of masters. */ |
70 static unsigned int backup_count; /**< Number of backup devices. */ |
69 static unsigned int backup_count; /**< Number of backup devices. */ |
71 |
70 |
72 static uint8_t macs[MAX_MASTERS][2][ETH_ALEN]; /**< MAC addresses. */ |
71 static uint8_t macs[MAX_MASTERS][2][ETH_ALEN]; /**< MAC addresses. */ |
73 |
72 |
74 static dev_t device_number; /**< XML character device number. */ |
|
75 ec_xmldev_t xmldev; /**< XML character device. */ |
|
76 |
|
77 char *ec_master_version_str = EC_MASTER_VERSION; /**< Version string. */ |
73 char *ec_master_version_str = EC_MASTER_VERSION; /**< Version string. */ |
78 |
74 |
79 /*****************************************************************************/ |
75 /*****************************************************************************/ |
80 |
76 |
81 /** \cond */ |
77 /** \cond */ |
121 EC_ERR("Failed to add module kobject.\n"); |
117 EC_ERR("Failed to add module kobject.\n"); |
122 ret = -EEXIST; |
118 ret = -EEXIST; |
123 goto out_put; |
119 goto out_put; |
124 } |
120 } |
125 |
121 |
126 if (alloc_chrdev_region(&device_number, 0, 1, "EtherCAT")) { |
|
127 EC_ERR("Failed to obtain device number!\n"); |
|
128 ret = -EBUSY; |
|
129 goto out_del; |
|
130 } |
|
131 |
|
132 // zero MAC addresses |
122 // zero MAC addresses |
133 memset(macs, 0x00, sizeof(uint8_t) * MAX_MASTERS * 2 * ETH_ALEN); |
123 memset(macs, 0x00, sizeof(uint8_t) * MAX_MASTERS * 2 * ETH_ALEN); |
134 |
124 |
135 // process MAC parameters |
125 // process MAC parameters |
136 for (i = 0; i < master_count; i++) { |
126 for (i = 0; i < master_count; i++) { |
137 if (ec_mac_parse(macs[i][0], main_devices[i], 0)) { |
127 if (ec_mac_parse(macs[i][0], main_devices[i], 0)) { |
138 ret = -EINVAL; |
128 ret = -EINVAL; |
139 goto out_cdev; |
129 goto out_del; |
140 } |
130 } |
141 |
131 |
142 if (i < backup_count && ec_mac_parse(macs[i][1], backup_devices[i], 1)) { |
132 if (i < backup_count && ec_mac_parse(macs[i][1], backup_devices[i], 1)) { |
143 ret = -EINVAL; |
133 ret = -EINVAL; |
144 goto out_cdev; |
134 goto out_del; |
145 } |
135 } |
146 } |
136 } |
147 |
137 |
148 if (master_count) { |
138 if (master_count) { |
149 if (!(masters = kmalloc(sizeof(ec_master_t) * master_count, |
139 if (!(masters = kmalloc(sizeof(ec_master_t) * master_count, |
150 GFP_KERNEL))) { |
140 GFP_KERNEL))) { |
151 EC_ERR("Failed to allocate memory for EtherCAT masters.\n"); |
141 EC_ERR("Failed to allocate memory for EtherCAT masters.\n"); |
152 ret = -ENOMEM; |
142 ret = -ENOMEM; |
153 goto out_cdev; |
143 goto out_del; |
154 } |
144 } |
155 } |
145 } |
156 |
146 |
157 for (i = 0; i < master_count; i++) { |
147 for (i = 0; i < master_count; i++) { |
158 if (ec_master_init(&masters[i], &kobj, i, macs[i][0], macs[i][1])) { |
148 if (ec_master_init(&masters[i], &kobj, i, macs[i][0], macs[i][1])) { |