1 // SPDX-License-Identifier: GPL-2.0-only
3 * H/W layer of ISHTP provider device (ISH)
5 * Copyright (c) 2014-2016, Intel Corporation.
8 #include <linux/sched.h>
9 #include <linux/spinlock.h>
10 #include <linux/delay.h>
11 #include <linux/jiffies.h>
16 /* For FW reset flow */
17 static struct work_struct fw_reset_work;
18 static struct ishtp_device *ishtp_dev;
21 * ish_reg_read() - Read register
22 * @dev: ISHTP device pointer
23 * @offset: Register offset
25 * Read 32 bit register at a given offset
27 * Return: Read register value
29 static inline uint32_t ish_reg_read(const struct ishtp_device *dev,
32 struct ish_hw *hw = to_ish_hw(dev);
34 return readl(hw->mem_addr + offset);
38 * ish_reg_write() - Write register
39 * @dev: ISHTP device pointer
40 * @offset: Register offset
41 * @value: Value to write
43 * Writes 32 bit register at a give offset
45 static inline void ish_reg_write(struct ishtp_device *dev,
49 struct ish_hw *hw = to_ish_hw(dev);
51 writel(value, hw->mem_addr + offset);
55 * _ish_read_fw_sts_reg() - Read FW status register
56 * @dev: ISHTP device pointer
58 * Read FW status register
60 * Return: Read register value
62 static inline uint32_t _ish_read_fw_sts_reg(struct ishtp_device *dev)
64 return ish_reg_read(dev, IPC_REG_ISH_HOST_FWSTS);
68 * check_generated_interrupt() - Check if ISH interrupt
69 * @dev: ISHTP device pointer
71 * Check if an interrupt was generated for ISH
73 * Return: Read true or false
75 static bool check_generated_interrupt(struct ishtp_device *dev)
77 bool interrupt_generated = true;
78 uint32_t pisr_val = 0;
80 if (dev->pdev->device == CHV_DEVICE_ID) {
81 pisr_val = ish_reg_read(dev, IPC_REG_PISR_CHV_AB);
83 IPC_INT_FROM_ISH_TO_HOST_CHV_AB(pisr_val);
85 pisr_val = ish_reg_read(dev, IPC_REG_PISR_BXT);
86 interrupt_generated = !!pisr_val;
87 /* only busy-clear bit is RW, others are RO */
89 ish_reg_write(dev, IPC_REG_PISR_BXT, pisr_val);
92 return interrupt_generated;
96 * ish_is_input_ready() - Check if FW ready for RX
97 * @dev: ISHTP device pointer
99 * Check if ISH FW is ready for receiving data
101 * Return: Read true or false
103 static bool ish_is_input_ready(struct ishtp_device *dev)
105 uint32_t doorbell_val;
107 doorbell_val = ish_reg_read(dev, IPC_REG_HOST2ISH_DRBL);
108 return !IPC_IS_BUSY(doorbell_val);
112 * set_host_ready() - Indicate host ready
113 * @dev: ISHTP device pointer
115 * Set host ready indication to FW
117 static void set_host_ready(struct ishtp_device *dev)
119 if (dev->pdev->device == CHV_DEVICE_ID) {
120 if (dev->pdev->revision == REVISION_ID_CHT_A0 ||
121 (dev->pdev->revision & REVISION_ID_SI_MASK) ==
122 REVISION_ID_CHT_Ax_SI)
123 ish_reg_write(dev, IPC_REG_HOST_COMM, 0x81);
124 else if (dev->pdev->revision == REVISION_ID_CHT_B0 ||
125 (dev->pdev->revision & REVISION_ID_SI_MASK) ==
126 REVISION_ID_CHT_Bx_SI ||
127 (dev->pdev->revision & REVISION_ID_SI_MASK) ==
128 REVISION_ID_CHT_Kx_SI ||
129 (dev->pdev->revision & REVISION_ID_SI_MASK) ==
130 REVISION_ID_CHT_Dx_SI) {
131 uint32_t host_comm_val;
133 host_comm_val = ish_reg_read(dev, IPC_REG_HOST_COMM);
134 host_comm_val |= IPC_HOSTCOMM_INT_EN_BIT_CHV_AB | 0x81;
135 ish_reg_write(dev, IPC_REG_HOST_COMM, host_comm_val);
138 uint32_t host_pimr_val;
140 host_pimr_val = ish_reg_read(dev, IPC_REG_PIMR_BXT);
141 host_pimr_val |= IPC_PIMR_INT_EN_BIT_BXT;
143 * disable interrupt generated instead of
146 host_pimr_val &= ~IPC_HOST2ISH_BUSYCLEAR_MASK_BIT;
148 ish_reg_write(dev, IPC_REG_PIMR_BXT, host_pimr_val);
153 * ishtp_fw_is_ready() - Check if FW ready
154 * @dev: ISHTP device pointer
156 * Check if ISH FW is ready
158 * Return: Read true or false
160 static bool ishtp_fw_is_ready(struct ishtp_device *dev)
162 uint32_t ish_status = _ish_read_fw_sts_reg(dev);
164 return IPC_IS_ISH_ILUP(ish_status) &&
165 IPC_IS_ISH_ISHTP_READY(ish_status);
169 * ish_set_host_rdy() - Indicate host ready
170 * @dev: ISHTP device pointer
172 * Set host ready indication to FW
174 static void ish_set_host_rdy(struct ishtp_device *dev)
176 uint32_t host_status = ish_reg_read(dev, IPC_REG_HOST_COMM);
178 IPC_SET_HOST_READY(host_status);
179 ish_reg_write(dev, IPC_REG_HOST_COMM, host_status);
183 * ish_clr_host_rdy() - Indicate host not ready
184 * @dev: ISHTP device pointer
186 * Send host not ready indication to FW
188 static void ish_clr_host_rdy(struct ishtp_device *dev)
190 uint32_t host_status = ish_reg_read(dev, IPC_REG_HOST_COMM);
192 IPC_CLEAR_HOST_READY(host_status);
193 ish_reg_write(dev, IPC_REG_HOST_COMM, host_status);
196 static bool ish_chk_host_rdy(struct ishtp_device *dev)
198 uint32_t host_status = ish_reg_read(dev, IPC_REG_HOST_COMM);
200 return (host_status & IPC_HOSTCOMM_READY_BIT);
204 * ish_set_host_ready() - reconfig ipc host registers
205 * @dev: ishtp device pointer
207 * Set host to ready state
208 * This API is called in some case:
209 * fw is still on, but ipc is powered down.
212 * Return: 0 for success else error fault code
214 void ish_set_host_ready(struct ishtp_device *dev)
216 if (ish_chk_host_rdy(dev))
219 ish_set_host_rdy(dev);
224 * _ishtp_read_hdr() - Read message header
225 * @dev: ISHTP device pointer
227 * Read header of 32bit length
229 * Return: Read register value
231 static uint32_t _ishtp_read_hdr(const struct ishtp_device *dev)
233 return ish_reg_read(dev, IPC_REG_ISH2HOST_MSG);
237 * _ishtp_read - Read message
238 * @dev: ISHTP device pointer
239 * @buffer: message buffer
240 * @buffer_length: length of message buffer
242 * Read message from FW
246 static int _ishtp_read(struct ishtp_device *dev, unsigned char *buffer,
247 unsigned long buffer_length)
250 uint32_t *r_buf = (uint32_t *)buffer;
253 msg_offs = IPC_REG_ISH2HOST_MSG + sizeof(struct ishtp_msg_hdr);
254 for (i = 0; i < buffer_length; i += sizeof(uint32_t))
255 *r_buf++ = ish_reg_read(dev, msg_offs + i);
261 * write_ipc_from_queue() - try to write ipc msg from Tx queue to device
262 * @dev: ishtp device pointer
264 * Check if DRBL is cleared. if it is - write the first IPC msg, then call
265 * the callback function (unless it's NULL)
267 * Return: 0 for success else failure code
269 static int write_ipc_from_queue(struct ishtp_device *dev)
271 struct wr_msg_ctl_info *ipc_link;
272 unsigned long length;
275 uint32_t doorbell_val;
279 void (*ipc_send_compl)(void *);
280 void *ipc_send_compl_prm;
282 if (dev->dev_state == ISHTP_DEV_DISABLED)
285 spin_lock_irqsave(&dev->wr_processing_spinlock, flags);
286 if (!ish_is_input_ready(dev)) {
287 spin_unlock_irqrestore(&dev->wr_processing_spinlock, flags);
292 * if tx send list is empty - return 0;
293 * may happen, as RX_COMPLETE handler doesn't check list emptiness.
295 if (list_empty(&dev->wr_processing_list)) {
296 spin_unlock_irqrestore(&dev->wr_processing_spinlock, flags);
300 ipc_link = list_first_entry(&dev->wr_processing_list,
301 struct wr_msg_ctl_info, link);
302 /* first 4 bytes of the data is the doorbell value (IPC header) */
303 length = ipc_link->length - sizeof(uint32_t);
304 doorbell_val = *(uint32_t *)ipc_link->inline_data;
305 r_buf = (uint32_t *)(ipc_link->inline_data + sizeof(uint32_t));
307 /* If sending MNG_SYNC_FW_CLOCK, update clock again */
308 if (IPC_HEADER_GET_PROTOCOL(doorbell_val) == IPC_PROTOCOL_MNG &&
309 IPC_HEADER_GET_MNG_CMD(doorbell_val) == MNG_SYNC_FW_CLOCK) {
310 uint64_t usec_system, usec_utc;
311 struct ipc_time_update_msg time_update;
312 struct time_sync_format ts_format;
314 usec_system = ktime_to_us(ktime_get_boottime());
315 usec_utc = ktime_to_us(ktime_get_real());
316 ts_format.ts1_source = HOST_SYSTEM_TIME_USEC;
317 ts_format.ts2_source = HOST_UTC_TIME_USEC;
318 ts_format.reserved = 0;
320 time_update.primary_host_time = usec_system;
321 time_update.secondary_host_time = usec_utc;
322 time_update.sync_info = ts_format;
324 memcpy(r_buf, &time_update,
325 sizeof(struct ipc_time_update_msg));
328 for (i = 0, reg_addr = IPC_REG_HOST2ISH_MSG; i < length >> 2; i++,
330 ish_reg_write(dev, reg_addr, r_buf[i]);
336 memcpy(®, &r_buf[length >> 2], rem);
337 ish_reg_write(dev, reg_addr, reg);
339 ish_reg_write(dev, IPC_REG_HOST2ISH_DRBL, doorbell_val);
341 /* Flush writes to msg registers and doorbell */
342 ish_reg_read(dev, IPC_REG_ISH_HOST_FWSTS);
344 /* Update IPC counters */
346 dev->ipc_tx_bytes_cnt += IPC_HEADER_GET_LENGTH(doorbell_val);
348 ipc_send_compl = ipc_link->ipc_send_compl;
349 ipc_send_compl_prm = ipc_link->ipc_send_compl_prm;
350 list_del_init(&ipc_link->link);
351 list_add(&ipc_link->link, &dev->wr_free_list);
352 spin_unlock_irqrestore(&dev->wr_processing_spinlock, flags);
355 * callback will be called out of spinlock,
356 * after ipc_link returned to free list
359 ipc_send_compl(ipc_send_compl_prm);
365 * write_ipc_to_queue() - write ipc msg to Tx queue
366 * @dev: ishtp device instance
367 * @ipc_send_compl: Send complete callback
368 * @ipc_send_compl_prm: Parameter to send in complete callback
369 * @msg: Pointer to message
370 * @length: Length of message
372 * Recived msg with IPC (and upper protocol) header and add it to the device
373 * Tx-to-write list then try to send the first IPC waiting msg
374 * (if DRBL is cleared)
375 * This function returns negative value for failure (means free list
376 * is empty, or msg too long) and 0 for success.
378 * Return: 0 for success else failure code
380 static int write_ipc_to_queue(struct ishtp_device *dev,
381 void (*ipc_send_compl)(void *), void *ipc_send_compl_prm,
382 unsigned char *msg, int length)
384 struct wr_msg_ctl_info *ipc_link;
387 if (length > IPC_FULL_MSG_SIZE)
390 spin_lock_irqsave(&dev->wr_processing_spinlock, flags);
391 if (list_empty(&dev->wr_free_list)) {
392 spin_unlock_irqrestore(&dev->wr_processing_spinlock, flags);
395 ipc_link = list_first_entry(&dev->wr_free_list,
396 struct wr_msg_ctl_info, link);
397 list_del_init(&ipc_link->link);
399 ipc_link->ipc_send_compl = ipc_send_compl;
400 ipc_link->ipc_send_compl_prm = ipc_send_compl_prm;
401 ipc_link->length = length;
402 memcpy(ipc_link->inline_data, msg, length);
404 list_add_tail(&ipc_link->link, &dev->wr_processing_list);
405 spin_unlock_irqrestore(&dev->wr_processing_spinlock, flags);
407 write_ipc_from_queue(dev);
413 * ipc_send_mng_msg() - Send management message
414 * @dev: ishtp device instance
415 * @msg_code: Message code
416 * @msg: Pointer to message
417 * @size: Length of message
419 * Send management message to FW
421 * Return: 0 for success else failure code
423 static int ipc_send_mng_msg(struct ishtp_device *dev, uint32_t msg_code,
424 void *msg, size_t size)
426 unsigned char ipc_msg[IPC_FULL_MSG_SIZE];
427 uint32_t drbl_val = IPC_BUILD_MNG_MSG(msg_code, size);
429 memcpy(ipc_msg, &drbl_val, sizeof(uint32_t));
430 memcpy(ipc_msg + sizeof(uint32_t), msg, size);
431 return write_ipc_to_queue(dev, NULL, NULL, ipc_msg,
432 sizeof(uint32_t) + size);
435 #define WAIT_FOR_FW_RDY 0x1
436 #define WAIT_FOR_INPUT_RDY 0x2
439 * timed_wait_for_timeout() - wait special event with timeout
440 * @dev: ISHTP device pointer
441 * @condition: indicate the condition for waiting
442 * @timeinc: time slice for every wait cycle, in ms
443 * @timeout: time in ms for timeout
445 * This function will check special event to be ready in a loop, the loop
446 * period is specificd in timeinc. Wait timeout will causes failure.
448 * Return: 0 for success else failure code
450 static int timed_wait_for_timeout(struct ishtp_device *dev, int condition,
451 unsigned int timeinc, unsigned int timeout)
453 bool complete = false;
457 if (condition == WAIT_FOR_FW_RDY) {
458 complete = ishtp_fw_is_ready(dev);
459 } else if (condition == WAIT_FOR_INPUT_RDY) {
460 complete = ish_is_input_ready(dev);
467 unsigned long left_time;
469 left_time = msleep_interruptible(timeinc);
470 timeout -= (timeinc - left_time);
472 } while (!complete && timeout > 0);
483 #define TIME_SLICE_FOR_FW_RDY_MS 100
484 #define TIME_SLICE_FOR_INPUT_RDY_MS 100
485 #define TIMEOUT_FOR_FW_RDY_MS 2000
486 #define TIMEOUT_FOR_INPUT_RDY_MS 2000
489 * ish_fw_reset_handler() - FW reset handler
490 * @dev: ishtp device pointer
494 * Return: 0 for success else failure code
496 static int ish_fw_reset_handler(struct ishtp_device *dev)
502 reset_id = ish_reg_read(dev, IPC_REG_ISH2HOST_MSG) & 0xFFFF;
504 /* Clear IPC output queue */
505 spin_lock_irqsave(&dev->wr_processing_spinlock, flags);
506 list_splice_init(&dev->wr_processing_list, &dev->wr_free_list);
507 spin_unlock_irqrestore(&dev->wr_processing_spinlock, flags);
509 /* ISHTP notification in IPC_RESET */
510 ishtp_reset_handler(dev);
512 if (!ish_is_input_ready(dev))
513 timed_wait_for_timeout(dev, WAIT_FOR_INPUT_RDY,
514 TIME_SLICE_FOR_INPUT_RDY_MS, TIMEOUT_FOR_INPUT_RDY_MS);
517 if (!ish_is_input_ready(dev))
520 * Set HOST2ISH.ILUP. Apparently we need this BEFORE sending
521 * RESET_NOTIFY_ACK - FW will be checking for it
523 ish_set_host_rdy(dev);
524 /* Send RESET_NOTIFY_ACK (with reset_id) */
525 ipc_send_mng_msg(dev, MNG_RESET_NOTIFY_ACK, &reset_id,
528 /* Wait for ISH FW'es ILUP and ISHTP_READY */
529 timed_wait_for_timeout(dev, WAIT_FOR_FW_RDY,
530 TIME_SLICE_FOR_FW_RDY_MS, TIMEOUT_FOR_FW_RDY_MS);
531 if (!ishtp_fw_is_ready(dev)) {
535 ish_status = _ish_read_fw_sts_reg(dev);
537 "[ishtp-ish]: completed reset, ISH is dead (FWSTS = %08X)\n",
544 #define TIMEOUT_FOR_HW_RDY_MS 300
547 * fw_reset_work_fn() - FW reset worker function
550 * Call ish_fw_reset_handler to complete FW reset
552 static void fw_reset_work_fn(struct work_struct *unused)
556 rv = ish_fw_reset_handler(ishtp_dev);
558 /* ISH is ILUP & ISHTP-ready. Restart ISHTP */
559 msleep_interruptible(TIMEOUT_FOR_HW_RDY_MS);
560 ishtp_dev->recvd_hw_ready = 1;
561 wake_up_interruptible(&ishtp_dev->wait_hw_ready);
563 /* ISHTP notification in IPC_RESET sequence completion */
564 ishtp_reset_compl_handler(ishtp_dev);
566 dev_err(ishtp_dev->devc, "[ishtp-ish]: FW reset failed (%d)\n",
571 * _ish_sync_fw_clock() -Sync FW clock with the OS clock
572 * @dev: ishtp device pointer
574 * Sync FW and OS time
576 static void _ish_sync_fw_clock(struct ishtp_device *dev)
578 static unsigned long prev_sync;
581 if (prev_sync && time_before(jiffies, prev_sync + 20 * HZ))
585 usec = ktime_to_us(ktime_get_boottime());
586 ipc_send_mng_msg(dev, MNG_SYNC_FW_CLOCK, &usec, sizeof(uint64_t));
590 * recv_ipc() - Receive and process IPC management messages
591 * @dev: ishtp device instance
592 * @doorbell_val: doorbell value
594 * This function runs in ISR context.
595 * NOTE: Any other mng command than reset_notify and reset_notify_ack
596 * won't wake BH handler
598 static void recv_ipc(struct ishtp_device *dev, uint32_t doorbell_val)
602 mng_cmd = IPC_HEADER_GET_MNG_CMD(doorbell_val);
608 case MNG_RX_CMPL_INDICATION:
609 if (dev->suspend_flag) {
610 dev->suspend_flag = 0;
611 wake_up_interruptible(&dev->suspend_wait);
613 if (dev->resume_flag) {
614 dev->resume_flag = 0;
615 wake_up_interruptible(&dev->resume_wait);
618 write_ipc_from_queue(dev);
621 case MNG_RESET_NOTIFY:
624 INIT_WORK(&fw_reset_work, fw_reset_work_fn);
626 schedule_work(&fw_reset_work);
629 case MNG_RESET_NOTIFY_ACK:
630 dev->recvd_hw_ready = 1;
631 wake_up_interruptible(&dev->wait_hw_ready);
637 * ish_irq_handler() - ISH IRQ handler
639 * @dev_id: ishtp device pointer
641 * ISH IRQ handler. If interrupt is generated and is for ISH it will process
644 irqreturn_t ish_irq_handler(int irq, void *dev_id)
646 struct ishtp_device *dev = dev_id;
647 uint32_t doorbell_val;
648 bool interrupt_generated;
650 /* Check that it's interrupt from ISH (may be shared) */
651 interrupt_generated = check_generated_interrupt(dev);
653 if (!interrupt_generated)
656 doorbell_val = ish_reg_read(dev, IPC_REG_ISH2HOST_DRBL);
657 if (!IPC_IS_BUSY(doorbell_val))
660 if (dev->dev_state == ISHTP_DEV_DISABLED)
663 /* Sanity check: IPC dgram length in header */
664 if (IPC_HEADER_GET_LENGTH(doorbell_val) > IPC_PAYLOAD_SIZE) {
666 "IPC hdr - bad length: %u; dropped\n",
667 (unsigned int)IPC_HEADER_GET_LENGTH(doorbell_val));
671 switch (IPC_HEADER_GET_PROTOCOL(doorbell_val)) {
674 case IPC_PROTOCOL_MNG:
675 recv_ipc(dev, doorbell_val);
677 case IPC_PROTOCOL_ISHTP:
683 /* Update IPC counters */
685 dev->ipc_rx_bytes_cnt += IPC_HEADER_GET_LENGTH(doorbell_val);
687 ish_reg_write(dev, IPC_REG_ISH2HOST_DRBL, 0);
688 /* Flush write to doorbell */
689 ish_reg_read(dev, IPC_REG_ISH_HOST_FWSTS);
695 * ish_disable_dma() - disable dma communication between host and ISHFW
696 * @dev: ishtp device pointer
698 * Clear the dma enable bit and wait for dma inactive.
700 * Return: 0 for success else error code.
702 int ish_disable_dma(struct ishtp_device *dev)
704 unsigned int dma_delay;
706 /* Clear the dma enable bit */
707 ish_reg_write(dev, IPC_REG_ISH_RMP2, 0);
709 /* wait for dma inactive */
710 for (dma_delay = 0; dma_delay < MAX_DMA_DELAY &&
711 _ish_read_fw_sts_reg(dev) & (IPC_ISH_IN_DMA);
715 if (dma_delay >= MAX_DMA_DELAY) {
717 "Wait for DMA inactive timeout\n");
725 * ish_wakeup() - wakeup ishfw from waiting-for-host state
726 * @dev: ishtp device pointer
728 * Set the dma enable bit and send a void message to FW,
729 * it wil wakeup FW from waiting-for-host state.
731 static void ish_wakeup(struct ishtp_device *dev)
733 /* Set dma enable bit */
734 ish_reg_write(dev, IPC_REG_ISH_RMP2, IPC_RMP2_DMA_ENABLED);
737 * Send 0 IPC message so that ISH FW wakes up if it was already
740 ish_reg_write(dev, IPC_REG_HOST2ISH_DRBL, IPC_DRBL_BUSY_BIT);
742 /* Flush writes to doorbell and REMAP2 */
743 ish_reg_read(dev, IPC_REG_ISH_HOST_FWSTS);
747 * _ish_hw_reset() - HW reset
748 * @dev: ishtp device pointer
750 * Reset ISH HW to recover if any error
752 * Return: 0 for success else error fault code
754 static int _ish_hw_reset(struct ishtp_device *dev)
756 struct pci_dev *pdev = dev->pdev;
763 rv = pci_reset_function(pdev);
765 dev->dev_state = ISHTP_DEV_RESETTING;
768 dev_err(&pdev->dev, "Can't reset - no PM caps\n");
772 /* Disable dma communication between FW and host */
773 if (ish_disable_dma(dev)) {
775 "Can't reset - stuck with DMA in-progress\n");
779 pci_read_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, &csr);
781 csr &= ~PCI_PM_CTRL_STATE_MASK;
783 pci_write_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, csr);
785 mdelay(pdev->d3hot_delay);
787 csr &= ~PCI_PM_CTRL_STATE_MASK;
789 pci_write_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, csr);
791 /* Now we can enable ISH DMA operation and wakeup ISHFW */
798 * _ish_ipc_reset() - IPC reset
799 * @dev: ishtp device pointer
801 * Resets host and fw IPC and upper layers
803 * Return: 0 for success else error fault code
805 static int _ish_ipc_reset(struct ishtp_device *dev)
807 struct ipc_rst_payload_type ipc_mng_msg;
810 ipc_mng_msg.reset_id = 1;
811 ipc_mng_msg.reserved = 0;
815 /* Clear the incoming doorbell */
816 ish_reg_write(dev, IPC_REG_ISH2HOST_DRBL, 0);
817 /* Flush write to doorbell */
818 ish_reg_read(dev, IPC_REG_ISH_HOST_FWSTS);
820 dev->recvd_hw_ready = 0;
823 rv = ipc_send_mng_msg(dev, MNG_RESET_NOTIFY, &ipc_mng_msg,
824 sizeof(struct ipc_rst_payload_type));
826 dev_err(dev->devc, "Failed to send IPC MNG_RESET_NOTIFY\n");
830 wait_event_interruptible_timeout(dev->wait_hw_ready,
831 dev->recvd_hw_ready, 2 * HZ);
832 if (!dev->recvd_hw_ready) {
833 dev_err(dev->devc, "Timed out waiting for HW ready\n");
841 * ish_hw_start() -Start ISH HW
842 * @dev: ishtp device pointer
844 * Set host to ready state and wait for FW reset
846 * Return: 0 for success else error fault code
848 int ish_hw_start(struct ishtp_device *dev)
850 ish_set_host_rdy(dev);
854 /* After that we can enable ISH DMA operation and wakeup ISHFW */
857 /* wait for FW-initiated reset flow */
858 if (!dev->recvd_hw_ready)
859 wait_event_interruptible_timeout(dev->wait_hw_ready,
863 if (!dev->recvd_hw_ready) {
865 "[ishtp-ish]: Timed out waiting for FW-initiated reset\n");
873 * ish_ipc_get_header() -Get doorbell value
874 * @dev: ishtp device pointer
875 * @length: length of message
878 * Get door bell value from message header
880 * Return: door bell value
882 static uint32_t ish_ipc_get_header(struct ishtp_device *dev, int length,
887 drbl_val = IPC_BUILD_HEADER(length, IPC_PROTOCOL_ISHTP, busy);
893 * _dma_no_cache_snooping()
895 * Check on current platform, DMA supports cache snooping or not.
896 * This callback is used to notify uplayer driver if manully cache
897 * flush is needed when do DMA operation.
899 * Please pay attention to this callback implementation, if declare
900 * having cache snooping on a cache snooping not supported platform
901 * will cause uplayer driver receiving mismatched data; and if
902 * declare no cache snooping on a cache snooping supported platform
903 * will cause cache be flushed twice and performance hit.
905 * @dev: ishtp device pointer
907 * Return: false - has cache snooping capability
908 * true - no cache snooping, need manually cache flush
910 static bool _dma_no_cache_snooping(struct ishtp_device *dev)
912 return (dev->pdev->device == EHL_Ax_DEVICE_ID ||
913 dev->pdev->device == TGL_LP_DEVICE_ID ||
914 dev->pdev->device == TGL_H_DEVICE_ID ||
915 dev->pdev->device == ADL_S_DEVICE_ID ||
916 dev->pdev->device == ADL_P_DEVICE_ID);
919 static const struct ishtp_hw_ops ish_hw_ops = {
920 .hw_reset = _ish_hw_reset,
921 .ipc_reset = _ish_ipc_reset,
922 .ipc_get_header = ish_ipc_get_header,
923 .ishtp_read = _ishtp_read,
924 .write = write_ipc_to_queue,
925 .get_fw_status = _ish_read_fw_sts_reg,
926 .sync_fw_clock = _ish_sync_fw_clock,
927 .ishtp_read_hdr = _ishtp_read_hdr,
928 .dma_no_cache_snooping = _dma_no_cache_snooping
932 * ish_dev_init() -Initialize ISH devoce
935 * Allocate ISHTP device and initialize IPC processing
937 * Return: ISHTP device instance on success else NULL
939 struct ishtp_device *ish_dev_init(struct pci_dev *pdev)
941 struct ishtp_device *dev;
944 dev = devm_kzalloc(&pdev->dev,
945 sizeof(struct ishtp_device) + sizeof(struct ish_hw),
950 ishtp_device_init(dev);
952 init_waitqueue_head(&dev->wait_hw_ready);
954 spin_lock_init(&dev->wr_processing_spinlock);
956 /* Init IPC processing and free lists */
957 INIT_LIST_HEAD(&dev->wr_processing_list);
958 INIT_LIST_HEAD(&dev->wr_free_list);
959 for (i = 0; i < IPC_TX_FIFO_SIZE; i++) {
960 struct wr_msg_ctl_info *tx_buf;
962 tx_buf = devm_kzalloc(&pdev->dev,
963 sizeof(struct wr_msg_ctl_info),
967 * IPC buffers may be limited or not available
968 * at all - although this shouldn't happen
971 "[ishtp-ish]: failure in Tx FIFO allocations (%d)\n",
975 list_add_tail(&tx_buf->link, &dev->wr_free_list);
978 dev->ops = &ish_hw_ops;
979 dev->devc = &pdev->dev;
980 dev->mtu = IPC_PAYLOAD_SIZE - sizeof(struct ishtp_msg_hdr);
985 * ish_device_disable() - Disable ISH device
986 * @dev: ISHTP device pointer
988 * Disable ISH by clearing host ready to inform firmware.
990 void ish_device_disable(struct ishtp_device *dev)
992 struct pci_dev *pdev = dev->pdev;
997 /* Disable dma communication between FW and host */
998 if (ish_disable_dma(dev)) {
1000 "Can't reset - stuck with DMA in-progress\n");
1004 /* Put ISH to D3hot state for power saving */
1005 pci_set_power_state(pdev, PCI_D3hot);
1007 dev->dev_state = ISHTP_DEV_DISABLED;
1008 ish_clr_host_rdy(dev);