equal
deleted
inserted
replaced
102 EC_INFO("Master driver %s\n", EC_MASTER_VERSION); |
102 EC_INFO("Master driver %s\n", EC_MASTER_VERSION); |
103 |
103 |
104 sema_init(&master_sem, 1); |
104 sema_init(&master_sem, 1); |
105 |
105 |
106 if (master_count) { |
106 if (master_count) { |
107 if (alloc_chrdev_region(&device_number, 0, master_count, "EtherCAT")) { |
107 if (alloc_chrdev_region(&device_number, |
|
108 0, master_count, "EtherCAT")) { |
108 EC_ERR("Failed to obtain device number(s)!\n"); |
109 EC_ERR("Failed to obtain device number(s)!\n"); |
109 ret = -EBUSY; |
110 ret = -EBUSY; |
110 goto out_return; |
111 goto out_return; |
111 } |
112 } |
112 } |
113 } |
138 ec_master_init_static(); |
139 ec_master_init_static(); |
139 |
140 |
140 if (master_count) { |
141 if (master_count) { |
141 if (!(masters = kmalloc(sizeof(ec_master_t) * master_count, |
142 if (!(masters = kmalloc(sizeof(ec_master_t) * master_count, |
142 GFP_KERNEL))) { |
143 GFP_KERNEL))) { |
143 EC_ERR("Failed to allocate memory for EtherCAT masters.\n"); |
144 EC_ERR("Failed to allocate memory" |
|
145 " for EtherCAT masters.\n"); |
144 ret = -ENOMEM; |
146 ret = -ENOMEM; |
145 goto out_class; |
147 goto out_class; |
146 } |
148 } |
147 } |
149 } |
148 |
150 |
487 else { |
489 else { |
488 up(&master->device_sem); |
490 up(&master->device_sem); |
489 |
491 |
490 if (master->debug_level) { |
492 if (master->debug_level) { |
491 ec_mac_print(net_dev->dev_addr, str); |
493 ec_mac_print(net_dev->dev_addr, str); |
492 EC_DBG("Master %u declined device %s.\n", master->index, str); |
494 EC_MASTER_DBG(master, 0, "Master declined device %s.\n", |
|
495 str); |
493 } |
496 } |
494 } |
497 } |
495 } |
498 } |
496 |
499 |
497 return NULL; // offer declined |
500 return NULL; // offer declined |
525 goto out_return; |
528 goto out_return; |
526 } |
529 } |
527 |
530 |
528 if (master->reserved) { |
531 if (master->reserved) { |
529 up(&master_sem); |
532 up(&master_sem); |
530 EC_ERR("Master %u is already in use!\n", master_index); |
533 EC_MASTER_ERR(master, "Master already in use!\n"); |
531 errptr = ERR_PTR(-EBUSY); |
534 errptr = ERR_PTR(-EBUSY); |
532 goto out_return; |
535 goto out_return; |
533 } |
536 } |
534 master->reserved = 1; |
537 master->reserved = 1; |
535 up(&master_sem); |
538 up(&master_sem); |
539 goto out_release; |
542 goto out_release; |
540 } |
543 } |
541 |
544 |
542 if (master->phase != EC_IDLE) { |
545 if (master->phase != EC_IDLE) { |
543 up(&master->device_sem); |
546 up(&master->device_sem); |
544 EC_ERR("Master %u still waiting for devices!\n", master_index); |
547 EC_MASTER_ERR(master, "Master still waiting for devices!\n"); |
545 errptr = ERR_PTR(-ENODEV); |
548 errptr = ERR_PTR(-ENODEV); |
546 goto out_release; |
549 goto out_release; |
547 } |
550 } |
548 |
551 |
549 if (!try_module_get(master->main_device.module)) { |
552 if (!try_module_get(master->main_device.module)) { |
554 } |
557 } |
555 |
558 |
556 up(&master->device_sem); |
559 up(&master->device_sem); |
557 |
560 |
558 if (ec_master_enter_operation_phase(master)) { |
561 if (ec_master_enter_operation_phase(master)) { |
559 EC_ERR("Failed to enter OPERATION phase!\n"); |
562 EC_MASTER_ERR(master, "Failed to enter OPERATION phase!\n"); |
560 errptr = ERR_PTR(-EIO); |
563 errptr = ERR_PTR(-EIO); |
561 goto out_module_put; |
564 goto out_module_put; |
562 } |
565 } |
563 |
566 |
564 EC_INFO("Successfully requested master %u.\n", master_index); |
567 EC_INFO("Successfully requested master %u.\n", master_index); |
582 |
585 |
583 /*****************************************************************************/ |
586 /*****************************************************************************/ |
584 |
587 |
585 void ecrt_release_master(ec_master_t *master) |
588 void ecrt_release_master(ec_master_t *master) |
586 { |
589 { |
587 EC_INFO("Releasing master %u...\n", master->index); |
590 EC_MASTER_INFO(master, "Releasing master...\n"); |
588 |
591 |
589 if (!master->reserved) { |
592 if (!master->reserved) { |
590 EC_WARN("Master %u was was not requested!\n", master->index); |
593 EC_MASTER_WARN(master, "%s(): Master was was not requested!\n", |
|
594 __func__); |
591 return; |
595 return; |
592 } |
596 } |
593 |
597 |
594 ec_master_leave_operation_phase(master); |
598 ec_master_leave_operation_phase(master); |
595 |
599 |
596 module_put(master->main_device.module); |
600 module_put(master->main_device.module); |
597 master->reserved = 0; |
601 master->reserved = 0; |
598 |
602 |
599 EC_INFO("Released master %u.\n", master->index); |
603 EC_MASTER_INFO(master, "Released.\n"); |
600 } |
604 } |
601 |
605 |
602 /*****************************************************************************/ |
606 /*****************************************************************************/ |
603 |
607 |
604 unsigned int ecrt_version_magic(void) |
608 unsigned int ecrt_version_magic(void) |