Lines Matching refs:fw_mgmt

23 struct fw_mgmt {  struct
66 struct fw_mgmt *fw_mgmt = container_of(kref, struct fw_mgmt, kref); in fw_mgmt_kref_release() argument
68 ida_destroy(&fw_mgmt->id_map); in fw_mgmt_kref_release()
69 kfree(fw_mgmt); in fw_mgmt_kref_release()
77 static void put_fw_mgmt(struct fw_mgmt *fw_mgmt) in put_fw_mgmt() argument
79 kref_put(&fw_mgmt->kref, fw_mgmt_kref_release); in put_fw_mgmt()
83 static struct fw_mgmt *get_fw_mgmt(struct cdev *cdev) in get_fw_mgmt()
85 struct fw_mgmt *fw_mgmt; in get_fw_mgmt() local
89 list_for_each_entry(fw_mgmt, &fw_mgmt_list, node) { in get_fw_mgmt()
90 if (&fw_mgmt->cdev == cdev) { in get_fw_mgmt()
91 kref_get(&fw_mgmt->kref); in get_fw_mgmt()
96 fw_mgmt = NULL; in get_fw_mgmt()
101 return fw_mgmt; in get_fw_mgmt()
104 static int fw_mgmt_interface_fw_version_operation(struct fw_mgmt *fw_mgmt, in fw_mgmt_interface_fw_version_operation() argument
107 struct gb_connection *connection = fw_mgmt->connection; in fw_mgmt_interface_fw_version_operation()
115 dev_err(fw_mgmt->parent, in fw_mgmt_interface_fw_version_operation()
131 dev_err(fw_mgmt->parent, in fw_mgmt_interface_fw_version_operation()
139 static int fw_mgmt_load_and_validate_operation(struct fw_mgmt *fw_mgmt, in fw_mgmt_load_and_validate_operation() argument
147 dev_err(fw_mgmt->parent, in fw_mgmt_load_and_validate_operation()
160 dev_err(fw_mgmt->parent, "load-and-validate: firmware-tag is not NULL terminated\n"); in fw_mgmt_load_and_validate_operation()
165 ret = ida_simple_get(&fw_mgmt->id_map, 1, 256, GFP_KERNEL); in fw_mgmt_load_and_validate_operation()
167 dev_err(fw_mgmt->parent, "failed to allocate request id (%d)\n", in fw_mgmt_load_and_validate_operation()
172 fw_mgmt->intf_fw_request_id = ret; in fw_mgmt_load_and_validate_operation()
173 fw_mgmt->intf_fw_loaded = false; in fw_mgmt_load_and_validate_operation()
176 ret = gb_operation_sync(fw_mgmt->connection, in fw_mgmt_load_and_validate_operation()
180 ida_simple_remove(&fw_mgmt->id_map, in fw_mgmt_load_and_validate_operation()
181 fw_mgmt->intf_fw_request_id); in fw_mgmt_load_and_validate_operation()
182 fw_mgmt->intf_fw_request_id = 0; in fw_mgmt_load_and_validate_operation()
183 dev_err(fw_mgmt->parent, in fw_mgmt_load_and_validate_operation()
195 struct fw_mgmt *fw_mgmt = gb_connection_get_data(connection); in fw_mgmt_interface_fw_loaded_operation() local
199 if (!fw_mgmt->intf_fw_request_id) { in fw_mgmt_interface_fw_loaded_operation()
200 dev_err(fw_mgmt->parent, in fw_mgmt_interface_fw_loaded_operation()
206 dev_err(fw_mgmt->parent, "illegal size of firmware loaded request (%zu != %zu)\n", in fw_mgmt_interface_fw_loaded_operation()
214 if (request->request_id != fw_mgmt->intf_fw_request_id) { in fw_mgmt_interface_fw_loaded_operation()
215 dev_err(fw_mgmt->parent, "invalid request id for firmware loaded request (%02u != %02u)\n", in fw_mgmt_interface_fw_loaded_operation()
216 fw_mgmt->intf_fw_request_id, request->request_id); in fw_mgmt_interface_fw_loaded_operation()
220 ida_simple_remove(&fw_mgmt->id_map, fw_mgmt->intf_fw_request_id); in fw_mgmt_interface_fw_loaded_operation()
221 fw_mgmt->intf_fw_request_id = 0; in fw_mgmt_interface_fw_loaded_operation()
222 fw_mgmt->intf_fw_status = request->status; in fw_mgmt_interface_fw_loaded_operation()
223 fw_mgmt->intf_fw_major = le16_to_cpu(request->major); in fw_mgmt_interface_fw_loaded_operation()
224 fw_mgmt->intf_fw_minor = le16_to_cpu(request->minor); in fw_mgmt_interface_fw_loaded_operation()
226 if (fw_mgmt->intf_fw_status == GB_FW_LOAD_STATUS_FAILED) in fw_mgmt_interface_fw_loaded_operation()
227 dev_err(fw_mgmt->parent, in fw_mgmt_interface_fw_loaded_operation()
229 fw_mgmt->intf_fw_status); in fw_mgmt_interface_fw_loaded_operation()
230 else if (fw_mgmt->intf_fw_status == GB_FW_LOAD_STATUS_VALIDATION_FAILED) in fw_mgmt_interface_fw_loaded_operation()
231 dev_err(fw_mgmt->parent, in fw_mgmt_interface_fw_loaded_operation()
233 fw_mgmt->intf_fw_status); in fw_mgmt_interface_fw_loaded_operation()
235 fw_mgmt->intf_fw_loaded = true; in fw_mgmt_interface_fw_loaded_operation()
237 complete(&fw_mgmt->completion); in fw_mgmt_interface_fw_loaded_operation()
242 static int fw_mgmt_backend_fw_version_operation(struct fw_mgmt *fw_mgmt, in fw_mgmt_backend_fw_version_operation() argument
245 struct gb_connection *connection = fw_mgmt->connection; in fw_mgmt_backend_fw_version_operation()
258 dev_err(fw_mgmt->parent, "backend-version: firmware-tag is not NULL terminated\n"); in fw_mgmt_backend_fw_version_operation()
266 dev_err(fw_mgmt->parent, "failed to get version of %s backend firmware (%d)\n", in fw_mgmt_backend_fw_version_operation()
286 dev_err(fw_mgmt->parent, in fw_mgmt_backend_fw_version_operation()
291 dev_err(fw_mgmt->parent, "Invalid status received: %u\n", in fw_mgmt_backend_fw_version_operation()
298 static int fw_mgmt_backend_fw_update_operation(struct fw_mgmt *fw_mgmt, in fw_mgmt_backend_fw_update_operation() argument
311 dev_err(fw_mgmt->parent, "backend-update: firmware-tag is not NULL terminated\n"); in fw_mgmt_backend_fw_update_operation()
316 ret = ida_simple_get(&fw_mgmt->id_map, 1, 256, GFP_KERNEL); in fw_mgmt_backend_fw_update_operation()
318 dev_err(fw_mgmt->parent, "failed to allocate request id (%d)\n", in fw_mgmt_backend_fw_update_operation()
323 fw_mgmt->backend_fw_request_id = ret; in fw_mgmt_backend_fw_update_operation()
326 ret = gb_operation_sync(fw_mgmt->connection, in fw_mgmt_backend_fw_update_operation()
330 ida_simple_remove(&fw_mgmt->id_map, in fw_mgmt_backend_fw_update_operation()
331 fw_mgmt->backend_fw_request_id); in fw_mgmt_backend_fw_update_operation()
332 fw_mgmt->backend_fw_request_id = 0; in fw_mgmt_backend_fw_update_operation()
333 dev_err(fw_mgmt->parent, in fw_mgmt_backend_fw_update_operation()
345 struct fw_mgmt *fw_mgmt = gb_connection_get_data(connection); in fw_mgmt_backend_fw_updated_operation() local
349 if (!fw_mgmt->backend_fw_request_id) { in fw_mgmt_backend_fw_updated_operation()
350 dev_err(fw_mgmt->parent, "unexpected backend firmware updated request received\n"); in fw_mgmt_backend_fw_updated_operation()
355 dev_err(fw_mgmt->parent, "illegal size of backend firmware updated request (%zu != %zu)\n", in fw_mgmt_backend_fw_updated_operation()
363 if (request->request_id != fw_mgmt->backend_fw_request_id) { in fw_mgmt_backend_fw_updated_operation()
364 …dev_err(fw_mgmt->parent, "invalid request id for backend firmware updated request (%02u != %02u)\n… in fw_mgmt_backend_fw_updated_operation()
365 fw_mgmt->backend_fw_request_id, request->request_id); in fw_mgmt_backend_fw_updated_operation()
369 ida_simple_remove(&fw_mgmt->id_map, fw_mgmt->backend_fw_request_id); in fw_mgmt_backend_fw_updated_operation()
370 fw_mgmt->backend_fw_request_id = 0; in fw_mgmt_backend_fw_updated_operation()
371 fw_mgmt->backend_fw_status = request->status; in fw_mgmt_backend_fw_updated_operation()
373 if ((fw_mgmt->backend_fw_status != GB_FW_BACKEND_FW_STATUS_SUCCESS) && in fw_mgmt_backend_fw_updated_operation()
374 (fw_mgmt->backend_fw_status != GB_FW_BACKEND_FW_STATUS_RETRY)) in fw_mgmt_backend_fw_updated_operation()
375 dev_err(fw_mgmt->parent, in fw_mgmt_backend_fw_updated_operation()
377 fw_mgmt->backend_fw_status); in fw_mgmt_backend_fw_updated_operation()
379 complete(&fw_mgmt->completion); in fw_mgmt_backend_fw_updated_operation()
388 struct fw_mgmt *fw_mgmt = get_fw_mgmt(inode->i_cdev); in fw_mgmt_open() local
391 if (fw_mgmt) { in fw_mgmt_open()
392 file->private_data = fw_mgmt; in fw_mgmt_open()
401 struct fw_mgmt *fw_mgmt = file->private_data; in fw_mgmt_release() local
403 put_fw_mgmt(fw_mgmt); in fw_mgmt_release()
407 static int fw_mgmt_ioctl(struct fw_mgmt *fw_mgmt, unsigned int cmd, in fw_mgmt_ioctl() argument
418 if (fw_mgmt->mode_switch_started) in fw_mgmt_ioctl()
423 ret = fw_mgmt_interface_fw_version_operation(fw_mgmt, in fw_mgmt_ioctl()
437 ret = fw_mgmt_backend_fw_version_operation(fw_mgmt, in fw_mgmt_ioctl()
451 ret = fw_mgmt_load_and_validate_operation(fw_mgmt, in fw_mgmt_ioctl()
456 if (!wait_for_completion_timeout(&fw_mgmt->completion, in fw_mgmt_ioctl()
457 fw_mgmt->timeout_jiffies)) { in fw_mgmt_ioctl()
458 dev_err(fw_mgmt->parent, "timed out waiting for firmware load and validation to finish\n"); in fw_mgmt_ioctl()
462 intf_load.status = fw_mgmt->intf_fw_status; in fw_mgmt_ioctl()
463 intf_load.major = fw_mgmt->intf_fw_major; in fw_mgmt_ioctl()
464 intf_load.minor = fw_mgmt->intf_fw_minor; in fw_mgmt_ioctl()
475 ret = fw_mgmt_backend_fw_update_operation(fw_mgmt, in fw_mgmt_ioctl()
480 if (!wait_for_completion_timeout(&fw_mgmt->completion, in fw_mgmt_ioctl()
481 fw_mgmt->timeout_jiffies)) { in fw_mgmt_ioctl()
482 dev_err(fw_mgmt->parent, "timed out waiting for backend firmware update to finish\n"); in fw_mgmt_ioctl()
486 backend_update.status = fw_mgmt->backend_fw_status; in fw_mgmt_ioctl()
497 dev_err(fw_mgmt->parent, "timeout can't be zero\n"); in fw_mgmt_ioctl()
501 fw_mgmt->timeout_jiffies = msecs_to_jiffies(timeout); in fw_mgmt_ioctl()
505 if (!fw_mgmt->intf_fw_loaded) { in fw_mgmt_ioctl()
506 dev_err(fw_mgmt->parent, in fw_mgmt_ioctl()
516 fw_mgmt->mode_switch_started = true; in fw_mgmt_ioctl()
518 ret = gb_interface_request_mode_switch(fw_mgmt->connection->intf); in fw_mgmt_ioctl()
520 dev_err(fw_mgmt->parent, "Mode-switch failed: %d\n", in fw_mgmt_ioctl()
522 fw_mgmt->mode_switch_started = false; in fw_mgmt_ioctl()
535 struct fw_mgmt *fw_mgmt = file->private_data; in fw_mgmt_ioctl_unlocked() local
536 struct gb_bundle *bundle = fw_mgmt->connection->bundle; in fw_mgmt_ioctl_unlocked()
551 mutex_lock(&fw_mgmt->mutex); in fw_mgmt_ioctl_unlocked()
552 if (!fw_mgmt->disabled) { in fw_mgmt_ioctl_unlocked()
555 ret = fw_mgmt_ioctl(fw_mgmt, cmd, (void __user *)arg); in fw_mgmt_ioctl_unlocked()
559 mutex_unlock(&fw_mgmt->mutex); in fw_mgmt_ioctl_unlocked()
589 struct fw_mgmt *fw_mgmt; in gb_fw_mgmt_connection_init() local
595 fw_mgmt = kzalloc(sizeof(*fw_mgmt), GFP_KERNEL); in gb_fw_mgmt_connection_init()
596 if (!fw_mgmt) in gb_fw_mgmt_connection_init()
599 fw_mgmt->parent = &connection->bundle->dev; in gb_fw_mgmt_connection_init()
600 fw_mgmt->timeout_jiffies = msecs_to_jiffies(FW_MGMT_TIMEOUT_MS); in gb_fw_mgmt_connection_init()
601 fw_mgmt->connection = connection; in gb_fw_mgmt_connection_init()
603 gb_connection_set_data(connection, fw_mgmt); in gb_fw_mgmt_connection_init()
604 init_completion(&fw_mgmt->completion); in gb_fw_mgmt_connection_init()
605 ida_init(&fw_mgmt->id_map); in gb_fw_mgmt_connection_init()
606 mutex_init(&fw_mgmt->mutex); in gb_fw_mgmt_connection_init()
607 kref_init(&fw_mgmt->kref); in gb_fw_mgmt_connection_init()
610 list_add(&fw_mgmt->node, &fw_mgmt_list); in gb_fw_mgmt_connection_init()
624 fw_mgmt->dev_num = MKDEV(MAJOR(fw_mgmt_dev_num), minor); in gb_fw_mgmt_connection_init()
625 cdev_init(&fw_mgmt->cdev, &fw_mgmt_fops); in gb_fw_mgmt_connection_init()
627 ret = cdev_add(&fw_mgmt->cdev, fw_mgmt->dev_num, 1); in gb_fw_mgmt_connection_init()
632 fw_mgmt->class_device = device_create(fw_mgmt_class, fw_mgmt->parent, in gb_fw_mgmt_connection_init()
633 fw_mgmt->dev_num, NULL, in gb_fw_mgmt_connection_init()
635 if (IS_ERR(fw_mgmt->class_device)) { in gb_fw_mgmt_connection_init()
636 ret = PTR_ERR(fw_mgmt->class_device); in gb_fw_mgmt_connection_init()
643 cdev_del(&fw_mgmt->cdev); in gb_fw_mgmt_connection_init()
650 list_del(&fw_mgmt->node); in gb_fw_mgmt_connection_init()
653 put_fw_mgmt(fw_mgmt); in gb_fw_mgmt_connection_init()
660 struct fw_mgmt *fw_mgmt; in gb_fw_mgmt_connection_exit() local
665 fw_mgmt = gb_connection_get_data(connection); in gb_fw_mgmt_connection_exit()
667 device_destroy(fw_mgmt_class, fw_mgmt->dev_num); in gb_fw_mgmt_connection_exit()
668 cdev_del(&fw_mgmt->cdev); in gb_fw_mgmt_connection_exit()
669 ida_simple_remove(&fw_mgmt_minors_map, MINOR(fw_mgmt->dev_num)); in gb_fw_mgmt_connection_exit()
675 mutex_lock(&fw_mgmt->mutex); in gb_fw_mgmt_connection_exit()
676 fw_mgmt->disabled = true; in gb_fw_mgmt_connection_exit()
677 mutex_unlock(&fw_mgmt->mutex); in gb_fw_mgmt_connection_exit()
680 gb_connection_disable(fw_mgmt->connection); in gb_fw_mgmt_connection_exit()
684 list_del(&fw_mgmt->node); in gb_fw_mgmt_connection_exit()
692 put_fw_mgmt(fw_mgmt); in gb_fw_mgmt_connection_exit()