Lines Matching +full:inactive +full:- +full:delay +full:- +full:ms

1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (c) 2014-2016, Intel Corporation.
10 #include <linux/delay.h>
13 #include "hw-ish.h"
21 * ish_reg_read() - Read register
34 return readl(hw->mem_addr + offset); in ish_reg_read()
38 * ish_reg_write() - Write register
51 writel(value, hw->mem_addr + offset); in ish_reg_write()
55 * _ish_read_fw_sts_reg() - Read FW status register
68 * check_generated_interrupt() - Check if ISH interrupt
80 if (dev->pdev->device == CHV_DEVICE_ID) { in check_generated_interrupt()
87 /* only busy-clear bit is RW, others are RO */ in check_generated_interrupt()
96 * ish_is_input_ready() - Check if FW ready for RX
112 * set_host_ready() - Indicate host ready
119 if (dev->pdev->device == CHV_DEVICE_ID) { in set_host_ready()
120 if (dev->pdev->revision == REVISION_ID_CHT_A0 || in set_host_ready()
121 (dev->pdev->revision & REVISION_ID_SI_MASK) == in set_host_ready()
124 else if (dev->pdev->revision == REVISION_ID_CHT_B0 || in set_host_ready()
125 (dev->pdev->revision & REVISION_ID_SI_MASK) == in set_host_ready()
127 (dev->pdev->revision & REVISION_ID_SI_MASK) == in set_host_ready()
129 (dev->pdev->revision & REVISION_ID_SI_MASK) == in set_host_ready()
153 * ishtp_fw_is_ready() - Check if FW ready
169 * ish_set_host_rdy() - Indicate host ready
183 * ish_clr_host_rdy() - Indicate host not ready
204 * ish_set_host_ready() - reconfig ipc host registers
224 * _ishtp_read_hdr() - Read message header
237 * _ishtp_read - Read message
261 * write_ipc_from_queue() - try to write ipc msg from Tx queue to device
264 * Check if DRBL is cleared. if it is - write the first IPC msg, then call
282 if (dev->dev_state == ISHTP_DEV_DISABLED) in write_ipc_from_queue()
283 return -EINVAL; in write_ipc_from_queue()
285 spin_lock_irqsave(&dev->wr_processing_spinlock, flags); in write_ipc_from_queue()
287 spin_unlock_irqrestore(&dev->wr_processing_spinlock, flags); in write_ipc_from_queue()
288 return -EBUSY; in write_ipc_from_queue()
292 * if tx send list is empty - return 0; in write_ipc_from_queue()
295 if (list_empty(&dev->wr_processing_list)) { in write_ipc_from_queue()
296 spin_unlock_irqrestore(&dev->wr_processing_spinlock, flags); in write_ipc_from_queue()
300 ipc_link = list_first_entry(&dev->wr_processing_list, in write_ipc_from_queue()
303 length = ipc_link->length - sizeof(uint32_t); in write_ipc_from_queue()
304 doorbell_val = *(uint32_t *)ipc_link->inline_data; in write_ipc_from_queue()
305 r_buf = (uint32_t *)(ipc_link->inline_data + sizeof(uint32_t)); in write_ipc_from_queue()
345 ++dev->ipc_tx_cnt; in write_ipc_from_queue()
346 dev->ipc_tx_bytes_cnt += IPC_HEADER_GET_LENGTH(doorbell_val); in write_ipc_from_queue()
348 ipc_send_compl = ipc_link->ipc_send_compl; in write_ipc_from_queue()
349 ipc_send_compl_prm = ipc_link->ipc_send_compl_prm; in write_ipc_from_queue()
350 list_del_init(&ipc_link->link); in write_ipc_from_queue()
351 list_add(&ipc_link->link, &dev->wr_free_list); in write_ipc_from_queue()
352 spin_unlock_irqrestore(&dev->wr_processing_spinlock, flags); in write_ipc_from_queue()
365 * write_ipc_to_queue() - write ipc msg to Tx queue
373 * Tx-to-write list then try to send the first IPC waiting msg
388 return -EMSGSIZE; in write_ipc_to_queue()
390 spin_lock_irqsave(&dev->wr_processing_spinlock, flags); in write_ipc_to_queue()
391 if (list_empty(&dev->wr_free_list)) { in write_ipc_to_queue()
392 spin_unlock_irqrestore(&dev->wr_processing_spinlock, flags); in write_ipc_to_queue()
393 return -ENOMEM; in write_ipc_to_queue()
395 ipc_link = list_first_entry(&dev->wr_free_list, in write_ipc_to_queue()
397 list_del_init(&ipc_link->link); in write_ipc_to_queue()
399 ipc_link->ipc_send_compl = ipc_send_compl; in write_ipc_to_queue()
400 ipc_link->ipc_send_compl_prm = ipc_send_compl_prm; in write_ipc_to_queue()
401 ipc_link->length = length; in write_ipc_to_queue()
402 memcpy(ipc_link->inline_data, msg, length); in write_ipc_to_queue()
404 list_add_tail(&ipc_link->link, &dev->wr_processing_list); in write_ipc_to_queue()
405 spin_unlock_irqrestore(&dev->wr_processing_spinlock, flags); in write_ipc_to_queue()
413 * ipc_send_mng_msg() - Send management message
439 * timed_wait_for_timeout() - wait special event with timeout
442 * @timeinc: time slice for every wait cycle, in ms
443 * @timeout: time in ms for timeout
462 ret = -EINVAL; in timed_wait_for_timeout()
470 timeout -= (timeinc - left_time); in timed_wait_for_timeout()
477 ret = -EBUSY; in timed_wait_for_timeout()
489 * ish_fw_reset_handler() - FW reset handler
505 spin_lock_irqsave(&dev->wr_processing_spinlock, flags); in ish_fw_reset_handler()
506 list_splice_init(&dev->wr_processing_list, &dev->wr_free_list); in ish_fw_reset_handler()
507 spin_unlock_irqrestore(&dev->wr_processing_spinlock, flags); in ish_fw_reset_handler()
518 return -EPIPE; in ish_fw_reset_handler()
521 * RESET_NOTIFY_ACK - FW will be checking for it in ish_fw_reset_handler()
536 dev_err(dev->devc, in ish_fw_reset_handler()
537 "[ishtp-ish]: completed reset, ISH is dead (FWSTS = %08X)\n", in ish_fw_reset_handler()
539 return -ENODEV; in ish_fw_reset_handler()
547 * fw_reset_work_fn() - FW reset worker function
558 /* ISH is ILUP & ISHTP-ready. Restart ISHTP */ in fw_reset_work_fn()
560 ishtp_dev->recvd_hw_ready = 1; in fw_reset_work_fn()
561 wake_up_interruptible(&ishtp_dev->wait_hw_ready); in fw_reset_work_fn()
566 dev_err(ishtp_dev->devc, "[ishtp-ish]: FW reset failed (%d)\n", in fw_reset_work_fn()
571 * _ish_sync_fw_clock() -Sync FW clock with the OS clock
590 * recv_ipc() - Receive and process IPC management messages
609 if (dev->suspend_flag) { in recv_ipc()
610 dev->suspend_flag = 0; in recv_ipc()
611 wake_up_interruptible(&dev->suspend_wait); in recv_ipc()
613 if (dev->resume_flag) { in recv_ipc()
614 dev->resume_flag = 0; in recv_ipc()
615 wake_up_interruptible(&dev->resume_wait); in recv_ipc()
630 dev->recvd_hw_ready = 1; in recv_ipc()
631 wake_up_interruptible(&dev->wait_hw_ready); in recv_ipc()
637 * ish_irq_handler() - ISH IRQ handler
660 if (dev->dev_state == ISHTP_DEV_DISABLED) in ish_irq_handler()
665 dev_err(dev->devc, in ish_irq_handler()
666 "IPC hdr - bad length: %u; dropped\n", in ish_irq_handler()
684 ++dev->ipc_rx_cnt; in ish_irq_handler()
685 dev->ipc_rx_bytes_cnt += IPC_HEADER_GET_LENGTH(doorbell_val); in ish_irq_handler()
695 * ish_disable_dma() - disable dma communication between host and ISHFW
698 * Clear the dma enable bit and wait for dma inactive.
709 /* wait for dma inactive */ in ish_disable_dma()
716 dev_err(dev->devc, in ish_disable_dma()
717 "Wait for DMA inactive timeout\n"); in ish_disable_dma()
718 return -EBUSY; in ish_disable_dma()
725 * ish_wakeup() - wakeup ishfw from waiting-for-host state
729 * it wil wakeup FW from waiting-for-host state.
747 * _ish_hw_reset() - HW reset
756 struct pci_dev *pdev = dev->pdev; in _ish_hw_reset()
761 return -ENODEV; in _ish_hw_reset()
765 dev->dev_state = ISHTP_DEV_RESETTING; in _ish_hw_reset()
767 if (!pdev->pm_cap) { in _ish_hw_reset()
768 dev_err(&pdev->dev, "Can't reset - no PM caps\n"); in _ish_hw_reset()
769 return -EINVAL; in _ish_hw_reset()
774 dev_err(&pdev->dev, in _ish_hw_reset()
775 "Can't reset - stuck with DMA in-progress\n"); in _ish_hw_reset()
776 return -EBUSY; in _ish_hw_reset()
779 pci_read_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, &csr); in _ish_hw_reset()
783 pci_write_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, csr); in _ish_hw_reset()
785 mdelay(pdev->d3hot_delay); in _ish_hw_reset()
789 pci_write_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, csr); in _ish_hw_reset()
798 * _ish_ipc_reset() - IPC reset
820 dev->recvd_hw_ready = 0; in _ish_ipc_reset()
826 dev_err(dev->devc, "Failed to send IPC MNG_RESET_NOTIFY\n"); in _ish_ipc_reset()
830 wait_event_interruptible_timeout(dev->wait_hw_ready, in _ish_ipc_reset()
831 dev->recvd_hw_ready, 2 * HZ); in _ish_ipc_reset()
832 if (!dev->recvd_hw_ready) { in _ish_ipc_reset()
833 dev_err(dev->devc, "Timed out waiting for HW ready\n"); in _ish_ipc_reset()
834 rv = -ENODEV; in _ish_ipc_reset()
841 * ish_hw_start() -Start ISH HW
857 /* wait for FW-initiated reset flow */ in ish_hw_start()
858 if (!dev->recvd_hw_ready) in ish_hw_start()
859 wait_event_interruptible_timeout(dev->wait_hw_ready, in ish_hw_start()
860 dev->recvd_hw_ready, in ish_hw_start()
863 if (!dev->recvd_hw_ready) { in ish_hw_start()
864 dev_err(dev->devc, in ish_hw_start()
865 "[ishtp-ish]: Timed out waiting for FW-initiated reset\n"); in ish_hw_start()
866 return -ENODEV; in ish_hw_start()
873 * ish_ipc_get_header() -Get doorbell value
907 * Return: false - has cache snooping capability
908 * true - no cache snooping, need manually cache flush
912 return (dev->pdev->device == EHL_Ax_DEVICE_ID || in _dma_no_cache_snooping()
913 dev->pdev->device == TGL_LP_DEVICE_ID || in _dma_no_cache_snooping()
914 dev->pdev->device == TGL_H_DEVICE_ID || in _dma_no_cache_snooping()
915 dev->pdev->device == ADL_S_DEVICE_ID || in _dma_no_cache_snooping()
916 dev->pdev->device == ADL_P_DEVICE_ID); in _dma_no_cache_snooping()
932 * ish_dev_init() -Initialize ISH devoce
944 dev = devm_kzalloc(&pdev->dev, in ish_dev_init()
952 init_waitqueue_head(&dev->wait_hw_ready); in ish_dev_init()
954 spin_lock_init(&dev->wr_processing_spinlock); in ish_dev_init()
957 INIT_LIST_HEAD(&dev->wr_processing_list); in ish_dev_init()
958 INIT_LIST_HEAD(&dev->wr_free_list); in ish_dev_init()
962 tx_buf = devm_kzalloc(&pdev->dev, in ish_dev_init()
968 * at all - although this shouldn't happen in ish_dev_init()
970 dev_err(dev->devc, in ish_dev_init()
971 "[ishtp-ish]: failure in Tx FIFO allocations (%d)\n", in ish_dev_init()
975 list_add_tail(&tx_buf->link, &dev->wr_free_list); in ish_dev_init()
978 dev->ops = &ish_hw_ops; in ish_dev_init()
979 dev->devc = &pdev->dev; in ish_dev_init()
980 dev->mtu = IPC_PAYLOAD_SIZE - sizeof(struct ishtp_msg_hdr); in ish_dev_init()
985 * ish_device_disable() - Disable ISH device
992 struct pci_dev *pdev = dev->pdev; in ish_device_disable()
999 dev_err(&pdev->dev, in ish_device_disable()
1000 "Can't reset - stuck with DMA in-progress\n"); in ish_device_disable()
1007 dev->dev_state = ISHTP_DEV_DISABLED; in ish_device_disable()