Lines Matching +full:os +full:- +full:initiated

1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (c) 2012-2016, Intel Corporation.
15 #include "ishtp-dev.h"
28 * ishtp_recv() - process ishtp message
42 msg_hdr = dev->ops->ishtp_read_hdr(dev); in ishtp_recv()
46 dev->ops->sync_fw_clock(dev); in ishtp_recv()
49 dev->ishtp_msg_hdr = msg_hdr; in ishtp_recv()
52 if (ishtp_hdr->length > dev->mtu) { in ishtp_recv()
53 dev_err(dev->devc, in ishtp_recv()
54 "ISHTP hdr - bad length: %u; dropped [%08X]\n", in ishtp_recv()
55 (unsigned int)ishtp_hdr->length, msg_hdr); in ishtp_recv()
60 if (!ishtp_hdr->host_addr && !ishtp_hdr->fw_addr) in ishtp_recv()
62 /* ISHTP fixed-client message */ in ishtp_recv()
63 else if (!ishtp_hdr->host_addr) in ishtp_recv()
72 * ishtp_send_msg() - Send ishtp message
91 drbl_val = dev->ops->ipc_get_header(dev, hdr->length + in ishtp_send_msg()
97 memcpy(ipc_msg + 2 * sizeof(uint32_t), msg, hdr->length); in ishtp_send_msg()
98 return dev->ops->write(dev, ipc_send_compl, ipc_send_compl_prm, in ishtp_send_msg()
99 ipc_msg, 2 * sizeof(uint32_t) + hdr->length); in ishtp_send_msg()
103 * ishtp_write_message() - Send ishtp single fragment message
120 * ishtp_fw_cl_by_uuid() - locate index of fw client
126 * Return: fw client index or -ENOENT if not found
132 for (i = 0; i < dev->fw_clients_num; ++i) { in ishtp_fw_cl_by_uuid()
133 if (guid_equal(uuid, &dev->fw_clients[i].props.protocol_name)) in ishtp_fw_cl_by_uuid()
136 return -ENOENT; in ishtp_fw_cl_by_uuid()
141 * ishtp_fw_cl_get_client() - return client information to client
155 spin_lock_irqsave(&dev->fw_clients_lock, flags); in ishtp_fw_cl_get_client()
157 spin_unlock_irqrestore(&dev->fw_clients_lock, flags); in ishtp_fw_cl_get_client()
158 if (i < 0 || dev->fw_clients[i].props.fixed_address) in ishtp_fw_cl_get_client()
161 return &dev->fw_clients[i]; in ishtp_fw_cl_get_client()
166 * ishtp_get_fw_client_id() - Get fw client id
174 return fw_client->client_id; in ishtp_get_fw_client_id()
179 * ishtp_fw_cl_by_id() - return index to fw_clients for client_id
185 * Return: index on success, -ENOENT on failure.
189 int i, res = -ENOENT; in ishtp_fw_cl_by_id()
192 spin_lock_irqsave(&dev->fw_clients_lock, flags); in ishtp_fw_cl_by_id()
193 for (i = 0; i < dev->fw_clients_num; i++) { in ishtp_fw_cl_by_id()
194 if (dev->fw_clients[i].client_id == client_id) { in ishtp_fw_cl_by_id()
199 spin_unlock_irqrestore(&dev->fw_clients_lock, flags); in ishtp_fw_cl_by_id()
205 * ishtp_cl_device_probe() - Bus probe() callback
220 driver = to_ishtp_cl_driver(dev->driver); in ishtp_cl_device_probe()
221 if (!driver || !driver->probe) in ishtp_cl_device_probe()
222 return -ENODEV; in ishtp_cl_device_probe()
224 return driver->probe(device); in ishtp_cl_device_probe()
228 * ishtp_cl_bus_match() - Bus match() callback
243 return guid_equal(driver->guid, in ishtp_cl_bus_match()
244 &device->fw_client->props.protocol_name); in ishtp_cl_bus_match()
248 * ishtp_cl_device_remove() - Bus remove() callback
262 if (!device || !dev->driver) in ishtp_cl_device_remove()
265 if (device->event_cb) { in ishtp_cl_device_remove()
266 device->event_cb = NULL; in ishtp_cl_device_remove()
267 cancel_work_sync(&device->event_work); in ishtp_cl_device_remove()
270 driver = to_ishtp_cl_driver(dev->driver); in ishtp_cl_device_remove()
271 if (!driver->remove) { in ishtp_cl_device_remove()
272 dev->driver = NULL; in ishtp_cl_device_remove()
277 return driver->remove(device); in ishtp_cl_device_remove()
281 * ishtp_cl_device_suspend() - Bus suspend callback
297 driver = to_ishtp_cl_driver(dev->driver); in ishtp_cl_device_suspend()
298 if (driver && driver->driver.pm) { in ishtp_cl_device_suspend()
299 if (driver->driver.pm->suspend) in ishtp_cl_device_suspend()
300 ret = driver->driver.pm->suspend(dev); in ishtp_cl_device_suspend()
307 * ishtp_cl_device_resume() - Bus resume callback
327 if (device->ishtp_dev->resume_flag) in ishtp_cl_device_resume()
330 driver = to_ishtp_cl_driver(dev->driver); in ishtp_cl_device_resume()
331 if (driver && driver->driver.pm) { in ishtp_cl_device_resume()
332 if (driver->driver.pm->resume) in ishtp_cl_device_resume()
333 ret = driver->driver.pm->resume(dev); in ishtp_cl_device_resume()
340 * ishtp_cl_device_reset() - Reset callback
353 device->event_cb = NULL; in ishtp_cl_device_reset()
354 cancel_work_sync(&device->event_work); in ishtp_cl_device_reset()
356 driver = to_ishtp_cl_driver(device->dev.driver); in ishtp_cl_device_reset()
357 if (driver && driver->reset) in ishtp_cl_device_reset()
358 ret = driver->reset(device); in ishtp_cl_device_reset()
369 return (len >= PAGE_SIZE) ? (PAGE_SIZE - 1) : len; in modalias_show()
382 return -ENOMEM; in ishtp_cl_uevent()
416 * ishtp_bus_add_device() - Function to create device on bus
433 spin_lock_irqsave(&dev->device_list_lock, flags); in ishtp_bus_add_device()
434 list_for_each_entry(device, &dev->device_list, device_link) { in ishtp_bus_add_device()
435 if (!strcmp(name, dev_name(&device->dev))) { in ishtp_bus_add_device()
436 device->fw_client = &dev->fw_clients[ in ishtp_bus_add_device()
437 dev->fw_client_presentation_num - 1]; in ishtp_bus_add_device()
438 spin_unlock_irqrestore(&dev->device_list_lock, flags); in ishtp_bus_add_device()
443 spin_unlock_irqrestore(&dev->device_list_lock, flags); in ishtp_bus_add_device()
449 device->dev.parent = dev->devc; in ishtp_bus_add_device()
450 device->dev.bus = &ishtp_cl_bus_type; in ishtp_bus_add_device()
451 device->dev.type = &ishtp_cl_device_type; in ishtp_bus_add_device()
452 device->ishtp_dev = dev; in ishtp_bus_add_device()
454 device->fw_client = in ishtp_bus_add_device()
455 &dev->fw_clients[dev->fw_client_presentation_num - 1]; in ishtp_bus_add_device()
457 dev_set_name(&device->dev, "%s", name); in ishtp_bus_add_device()
459 spin_lock_irqsave(&dev->device_list_lock, flags); in ishtp_bus_add_device()
460 list_add_tail(&device->device_link, &dev->device_list); in ishtp_bus_add_device()
461 spin_unlock_irqrestore(&dev->device_list_lock, flags); in ishtp_bus_add_device()
463 status = device_register(&device->dev); in ishtp_bus_add_device()
465 spin_lock_irqsave(&dev->device_list_lock, flags); in ishtp_bus_add_device()
466 list_del(&device->device_link); in ishtp_bus_add_device()
467 spin_unlock_irqrestore(&dev->device_list_lock, flags); in ishtp_bus_add_device()
468 dev_err(dev->devc, "Failed to register ISHTP client device\n"); in ishtp_bus_add_device()
469 put_device(&device->dev); in ishtp_bus_add_device()
479 * ishtp_bus_remove_device() - Function to relase device on bus
489 device_unregister(&device->dev); in ishtp_bus_remove_device()
493 * ishtp_cl_driver_register() - Client driver register
500 * Return: Return value of driver_register or -ENODEV if not ready
506 return -ENODEV; in ishtp_cl_driver_register()
508 driver->driver.name = driver->name; in ishtp_cl_driver_register()
509 driver->driver.owner = owner; in ishtp_cl_driver_register()
510 driver->driver.bus = &ishtp_cl_bus_type; in ishtp_cl_driver_register()
512 return driver_register(&driver->driver); in ishtp_cl_driver_register()
517 * ishtp_cl_driver_unregister() - Client driver unregister
524 driver_unregister(&driver->driver); in ishtp_cl_driver_unregister()
529 * ishtp_bus_event_work() - event work function
542 if (device->event_cb) in ishtp_bus_event_work()
543 device->event_cb(device); in ishtp_bus_event_work()
547 * ishtp_cl_bus_rx_event() - schedule event work
555 if (!device || !device->event_cb) in ishtp_cl_bus_rx_event()
558 if (device->event_cb) in ishtp_cl_bus_rx_event()
559 schedule_work(&device->event_work); in ishtp_cl_bus_rx_event()
563 * ishtp_register_event_cb() - Register callback
569 * Return: Return 0 or -EALREADY if already registered
574 if (device->event_cb) in ishtp_register_event_cb()
575 return -EALREADY; in ishtp_register_event_cb()
577 device->event_cb = event_cb; in ishtp_register_event_cb()
578 INIT_WORK(&device->event_work, ishtp_bus_event_work); in ishtp_register_event_cb()
585 * ishtp_get_device() - update usage count for the device
592 cl_device->reference_count++; in ishtp_get_device()
597 * ishtp_put_device() - decrement usage count for the device
604 cl_device->reference_count--; in ishtp_put_device()
609 * ishtp_set_drvdata() - set client driver data
613 * Set client driver data to cl_device->driver_data.
617 cl_device->driver_data = data; in ishtp_set_drvdata()
622 * ishtp_get_drvdata() - get client driver data
625 * Get client driver data from cl_device->driver_data.
631 return cl_device->driver_data; in ishtp_get_drvdata()
636 * ishtp_dev_to_cl_device() - get ishtp_cl_device instance from device instance
650 * ishtp_bus_new_client() - Create a new client
671 i = dev->fw_client_presentation_num - 1; in ishtp_bus_new_client()
672 device_uuid = dev->fw_clients[i].props.protocol_name; in ishtp_bus_new_client()
675 return -ENOMEM; in ishtp_bus_new_client()
680 return -ENOENT; in ishtp_bus_new_client()
689 * ishtp_cl_device_bind() - bind a device
702 if (!cl->fw_client_id || cl->state != ISHTP_CL_CONNECTED) in ishtp_cl_device_bind()
703 return -EFAULT; in ishtp_cl_device_bind()
705 rv = -ENOENT; in ishtp_cl_device_bind()
706 spin_lock_irqsave(&cl->dev->device_list_lock, flags); in ishtp_cl_device_bind()
707 list_for_each_entry(cl_device, &cl->dev->device_list, in ishtp_cl_device_bind()
709 if (cl_device->fw_client && in ishtp_cl_device_bind()
710 cl_device->fw_client->client_id == cl->fw_client_id) { in ishtp_cl_device_bind()
711 cl->device = cl_device; in ishtp_cl_device_bind()
716 spin_unlock_irqrestore(&cl->dev->device_list_lock, flags); in ishtp_cl_device_bind()
721 * ishtp_bus_remove_all_clients() - Remove all clients
737 spin_lock_irqsave(&ishtp_dev->cl_list_lock, flags); in ishtp_bus_remove_all_clients()
738 list_for_each_entry(cl, &ishtp_dev->cl_list, link) { in ishtp_bus_remove_all_clients()
739 cl->state = ISHTP_CL_DISCONNECTED; in ishtp_bus_remove_all_clients()
742 * Wake any pending process. The waiter would check dev->state in ishtp_bus_remove_all_clients()
746 wake_up_interruptible(&cl->wait_ctrl_res); in ishtp_bus_remove_all_clients()
757 * don't free host client because it is part of the OS fd in ishtp_bus_remove_all_clients()
761 spin_unlock_irqrestore(&ishtp_dev->cl_list_lock, flags); in ishtp_bus_remove_all_clients()
767 spin_lock_irqsave(&ishtp_dev->device_list_lock, flags); in ishtp_bus_remove_all_clients()
768 list_for_each_entry_safe(cl_device, n, &ishtp_dev->device_list, in ishtp_bus_remove_all_clients()
770 cl_device->fw_client = NULL; in ishtp_bus_remove_all_clients()
771 if (warm_reset && cl_device->reference_count) in ishtp_bus_remove_all_clients()
774 list_del(&cl_device->device_link); in ishtp_bus_remove_all_clients()
775 spin_unlock_irqrestore(&ishtp_dev->device_list_lock, flags); in ishtp_bus_remove_all_clients()
777 spin_lock_irqsave(&ishtp_dev->device_list_lock, flags); in ishtp_bus_remove_all_clients()
779 spin_unlock_irqrestore(&ishtp_dev->device_list_lock, flags); in ishtp_bus_remove_all_clients()
782 spin_lock_irqsave(&ishtp_dev->fw_clients_lock, flags); in ishtp_bus_remove_all_clients()
783 kfree(ishtp_dev->fw_clients); in ishtp_bus_remove_all_clients()
784 ishtp_dev->fw_clients = NULL; in ishtp_bus_remove_all_clients()
785 ishtp_dev->fw_clients_num = 0; in ishtp_bus_remove_all_clients()
786 ishtp_dev->fw_client_presentation_num = 0; in ishtp_bus_remove_all_clients()
787 ishtp_dev->fw_client_index = 0; in ishtp_bus_remove_all_clients()
788 bitmap_zero(ishtp_dev->fw_clients_map, ISHTP_CLIENTS_MAX); in ishtp_bus_remove_all_clients()
789 spin_unlock_irqrestore(&ishtp_dev->fw_clients_lock, flags); in ishtp_bus_remove_all_clients()
794 * ishtp_reset_handler() - IPC reset handler
803 /* Handle FW-initiated reset */ in ishtp_reset_handler()
804 dev->dev_state = ISHTP_DEV_RESETTING; in ishtp_reset_handler()
806 /* Clear BH processing queue - no further HBMs */ in ishtp_reset_handler()
807 spin_lock_irqsave(&dev->rd_msg_spinlock, flags); in ishtp_reset_handler()
808 dev->rd_msg_fifo_head = dev->rd_msg_fifo_tail = 0; in ishtp_reset_handler()
809 spin_unlock_irqrestore(&dev->rd_msg_spinlock, flags); in ishtp_reset_handler()
817 * ishtp_reset_compl_handler() - Reset completion handler
825 dev->dev_state = ISHTP_DEV_INIT_CLIENTS; in ishtp_reset_compl_handler()
826 dev->hbm_state = ISHTP_HBM_START; in ishtp_reset_compl_handler()
832 * ishtp_use_dma_transfer() - Function to use DMA
844 * ishtp_device() - Return device pointer
853 return &device->dev; in ishtp_device()
858 * ishtp_get_pci_device() - Return PCI device dev pointer
866 return device->ishtp_dev->devc; in ishtp_get_pci_device()
871 * ishtp_trace_callback() - Return trace callback
879 return cl_device->ishtp_dev->print_log; in ishtp_trace_callback()
884 * ish_hw_reset() - Call HW reset IPC callback
892 return dev->ops->hw_reset(dev); in ish_hw_reset()
897 * ishtp_bus_register() - Function to register bus
909 * ishtp_bus_unregister() - Function to unregister bus