2 * H/W layer of ISHTP provider device (ISH)
4 * Copyright (c) 2014-2016, Intel Corporation.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 #include <linux/sched.h>
17 #include <linux/spinlock.h>
18 #include <linux/delay.h>
19 #include <linux/jiffies.h>
24 /* For FW reset flow */
25 static struct work_struct fw_reset_work;
26 static struct ishtp_device *ishtp_dev;
29 * ish_reg_read() - Read register
30 * @dev: ISHTP device pointer
31 * @offset: Register offset
33 * Read 32 bit register at a given offset
35 * Return: Read register value
37 static inline uint32_t ish_reg_read(const struct ishtp_device *dev,
40 struct ish_hw *hw = to_ish_hw(dev);
42 return readl(hw->mem_addr + offset);
46 * ish_reg_write() - Write register
47 * @dev: ISHTP device pointer
48 * @offset: Register offset
49 * @value: Value to write
51 * Writes 32 bit register at a give offset
53 static inline void ish_reg_write(struct ishtp_device *dev,
57 struct ish_hw *hw = to_ish_hw(dev);
59 writel(value, hw->mem_addr + offset);
63 * _ish_read_fw_sts_reg() - Read FW status register
64 * @dev: ISHTP device pointer
66 * Read FW status register
68 * Return: Read register value
70 static inline uint32_t _ish_read_fw_sts_reg(struct ishtp_device *dev)
72 return ish_reg_read(dev, IPC_REG_ISH_HOST_FWSTS);
76 * check_generated_interrupt() - Check if ISH interrupt
77 * @dev: ISHTP device pointer
79 * Check if an interrupt was generated for ISH
81 * Return: Read true or false
83 static bool check_generated_interrupt(struct ishtp_device *dev)
85 bool interrupt_generated = true;
86 uint32_t pisr_val = 0;
88 if (dev->pdev->device == CHV_DEVICE_ID) {
89 pisr_val = ish_reg_read(dev, IPC_REG_PISR_CHV_AB);
91 IPC_INT_FROM_ISH_TO_HOST_CHV_AB(pisr_val);
93 pisr_val = ish_reg_read(dev, IPC_REG_PISR_BXT);
94 interrupt_generated = IPC_INT_FROM_ISH_TO_HOST_BXT(pisr_val);
97 return interrupt_generated;
101 * ish_is_input_ready() - Check if FW ready for RX
102 * @dev: ISHTP device pointer
104 * Check if ISH FW is ready for receiving data
106 * Return: Read true or false
108 static bool ish_is_input_ready(struct ishtp_device *dev)
110 uint32_t doorbell_val;
112 doorbell_val = ish_reg_read(dev, IPC_REG_HOST2ISH_DRBL);
113 return !IPC_IS_BUSY(doorbell_val);
117 * set_host_ready() - Indicate host ready
118 * @dev: ISHTP device pointer
120 * Set host ready indication to FW
122 static void set_host_ready(struct ishtp_device *dev)
124 if (dev->pdev->device == CHV_DEVICE_ID) {
125 if (dev->pdev->revision == REVISION_ID_CHT_A0 ||
126 (dev->pdev->revision & REVISION_ID_SI_MASK) ==
127 REVISION_ID_CHT_Ax_SI)
128 ish_reg_write(dev, IPC_REG_HOST_COMM, 0x81);
129 else if (dev->pdev->revision == REVISION_ID_CHT_B0 ||
130 (dev->pdev->revision & REVISION_ID_SI_MASK) ==
131 REVISION_ID_CHT_Bx_SI ||
132 (dev->pdev->revision & REVISION_ID_SI_MASK) ==
133 REVISION_ID_CHT_Kx_SI ||
134 (dev->pdev->revision & REVISION_ID_SI_MASK) ==
135 REVISION_ID_CHT_Dx_SI) {
136 uint32_t host_comm_val;
138 host_comm_val = ish_reg_read(dev, IPC_REG_HOST_COMM);
139 host_comm_val |= IPC_HOSTCOMM_INT_EN_BIT_CHV_AB | 0x81;
140 ish_reg_write(dev, IPC_REG_HOST_COMM, host_comm_val);
143 uint32_t host_pimr_val;
145 host_pimr_val = ish_reg_read(dev, IPC_REG_PIMR_BXT);
146 host_pimr_val |= IPC_PIMR_INT_EN_BIT_BXT;
148 * disable interrupt generated instead of
151 host_pimr_val &= ~IPC_HOST2ISH_BUSYCLEAR_MASK_BIT;
153 ish_reg_write(dev, IPC_REG_PIMR_BXT, host_pimr_val);
158 * ishtp_fw_is_ready() - Check if FW ready
159 * @dev: ISHTP device pointer
161 * Check if ISH FW is ready
163 * Return: Read true or false
165 static bool ishtp_fw_is_ready(struct ishtp_device *dev)
167 uint32_t ish_status = _ish_read_fw_sts_reg(dev);
169 return IPC_IS_ISH_ILUP(ish_status) &&
170 IPC_IS_ISH_ISHTP_READY(ish_status);
174 * ish_set_host_rdy() - Indicate host ready
175 * @dev: ISHTP device pointer
177 * Set host ready indication to FW
179 static void ish_set_host_rdy(struct ishtp_device *dev)
181 uint32_t host_status = ish_reg_read(dev, IPC_REG_HOST_COMM);
183 IPC_SET_HOST_READY(host_status);
184 ish_reg_write(dev, IPC_REG_HOST_COMM, host_status);
188 * ish_clr_host_rdy() - Indicate host not ready
189 * @dev: ISHTP device pointer
191 * Send host not ready indication to FW
193 static void ish_clr_host_rdy(struct ishtp_device *dev)
195 uint32_t host_status = ish_reg_read(dev, IPC_REG_HOST_COMM);
197 IPC_CLEAR_HOST_READY(host_status);
198 ish_reg_write(dev, IPC_REG_HOST_COMM, host_status);
202 * _ishtp_read_hdr() - Read message header
203 * @dev: ISHTP device pointer
205 * Read header of 32bit length
207 * Return: Read register value
209 static uint32_t _ishtp_read_hdr(const struct ishtp_device *dev)
211 return ish_reg_read(dev, IPC_REG_ISH2HOST_MSG);
215 * _ishtp_read - Read message
216 * @dev: ISHTP device pointer
217 * @buffer: message buffer
218 * @buffer_length: length of message buffer
220 * Read message from FW
224 static int _ishtp_read(struct ishtp_device *dev, unsigned char *buffer,
225 unsigned long buffer_length)
228 uint32_t *r_buf = (uint32_t *)buffer;
231 msg_offs = IPC_REG_ISH2HOST_MSG + sizeof(struct ishtp_msg_hdr);
232 for (i = 0; i < buffer_length; i += sizeof(uint32_t))
233 *r_buf++ = ish_reg_read(dev, msg_offs + i);
239 * write_ipc_from_queue() - try to write ipc msg from Tx queue to device
240 * @dev: ishtp device pointer
242 * Check if DRBL is cleared. if it is - write the first IPC msg, then call
243 * the callback function (unless it's NULL)
245 * Return: 0 for success else failure code
247 static int write_ipc_from_queue(struct ishtp_device *dev)
249 struct wr_msg_ctl_info *ipc_link;
250 unsigned long length;
253 uint32_t doorbell_val;
257 void (*ipc_send_compl)(void *);
258 void *ipc_send_compl_prm;
259 static int out_ipc_locked;
260 unsigned long out_ipc_flags;
262 if (dev->dev_state == ISHTP_DEV_DISABLED)
265 spin_lock_irqsave(&dev->out_ipc_spinlock, out_ipc_flags);
266 if (out_ipc_locked) {
267 spin_unlock_irqrestore(&dev->out_ipc_spinlock, out_ipc_flags);
271 if (!ish_is_input_ready(dev)) {
273 spin_unlock_irqrestore(&dev->out_ipc_spinlock, out_ipc_flags);
276 spin_unlock_irqrestore(&dev->out_ipc_spinlock, out_ipc_flags);
278 spin_lock_irqsave(&dev->wr_processing_spinlock, flags);
280 * if tx send list is empty - return 0;
281 * may happen, as RX_COMPLETE handler doesn't check list emptiness.
283 if (list_empty(&dev->wr_processing_list_head.link)) {
284 spin_unlock_irqrestore(&dev->wr_processing_spinlock, flags);
289 ipc_link = list_entry(dev->wr_processing_list_head.link.next,
290 struct wr_msg_ctl_info, link);
291 /* first 4 bytes of the data is the doorbell value (IPC header) */
292 length = ipc_link->length - sizeof(uint32_t);
293 doorbell_val = *(uint32_t *)ipc_link->inline_data;
294 r_buf = (uint32_t *)(ipc_link->inline_data + sizeof(uint32_t));
296 /* If sending MNG_SYNC_FW_CLOCK, update clock again */
297 if (IPC_HEADER_GET_PROTOCOL(doorbell_val) == IPC_PROTOCOL_MNG &&
298 IPC_HEADER_GET_MNG_CMD(doorbell_val) == MNG_SYNC_FW_CLOCK) {
299 uint64_t usec_system, usec_utc;
300 struct ipc_time_update_msg time_update;
301 struct time_sync_format ts_format;
303 usec_system = ktime_to_us(ktime_get_boottime());
304 usec_utc = ktime_to_us(ktime_get_real());
305 ts_format.ts1_source = HOST_SYSTEM_TIME_USEC;
306 ts_format.ts2_source = HOST_UTC_TIME_USEC;
307 ts_format.reserved = 0;
309 time_update.primary_host_time = usec_system;
310 time_update.secondary_host_time = usec_utc;
311 time_update.sync_info = ts_format;
313 memcpy(r_buf, &time_update,
314 sizeof(struct ipc_time_update_msg));
317 for (i = 0, reg_addr = IPC_REG_HOST2ISH_MSG; i < length >> 2; i++,
319 ish_reg_write(dev, reg_addr, r_buf[i]);
325 memcpy(®, &r_buf[length >> 2], rem);
326 ish_reg_write(dev, reg_addr, reg);
328 /* Flush writes to msg registers and doorbell */
329 ish_reg_read(dev, IPC_REG_ISH_HOST_FWSTS);
331 /* Update IPC counters */
333 dev->ipc_tx_bytes_cnt += IPC_HEADER_GET_LENGTH(doorbell_val);
335 ish_reg_write(dev, IPC_REG_HOST2ISH_DRBL, doorbell_val);
338 ipc_send_compl = ipc_link->ipc_send_compl;
339 ipc_send_compl_prm = ipc_link->ipc_send_compl_prm;
340 list_del_init(&ipc_link->link);
341 list_add_tail(&ipc_link->link, &dev->wr_free_list_head.link);
342 spin_unlock_irqrestore(&dev->wr_processing_spinlock, flags);
345 * callback will be called out of spinlock,
346 * after ipc_link returned to free list
349 ipc_send_compl(ipc_send_compl_prm);
355 * write_ipc_to_queue() - write ipc msg to Tx queue
356 * @dev: ishtp device instance
357 * @ipc_send_compl: Send complete callback
358 * @ipc_send_compl_prm: Parameter to send in complete callback
359 * @msg: Pointer to message
360 * @length: Length of message
362 * Recived msg with IPC (and upper protocol) header and add it to the device
363 * Tx-to-write list then try to send the first IPC waiting msg
364 * (if DRBL is cleared)
365 * This function returns negative value for failure (means free list
366 * is empty, or msg too long) and 0 for success.
368 * Return: 0 for success else failure code
370 static int write_ipc_to_queue(struct ishtp_device *dev,
371 void (*ipc_send_compl)(void *), void *ipc_send_compl_prm,
372 unsigned char *msg, int length)
374 struct wr_msg_ctl_info *ipc_link;
377 if (length > IPC_FULL_MSG_SIZE)
380 spin_lock_irqsave(&dev->wr_processing_spinlock, flags);
381 if (list_empty(&dev->wr_free_list_head.link)) {
382 spin_unlock_irqrestore(&dev->wr_processing_spinlock, flags);
385 ipc_link = list_entry(dev->wr_free_list_head.link.next,
386 struct wr_msg_ctl_info, link);
387 list_del_init(&ipc_link->link);
389 ipc_link->ipc_send_compl = ipc_send_compl;
390 ipc_link->ipc_send_compl_prm = ipc_send_compl_prm;
391 ipc_link->length = length;
392 memcpy(ipc_link->inline_data, msg, length);
394 list_add_tail(&ipc_link->link, &dev->wr_processing_list_head.link);
395 spin_unlock_irqrestore(&dev->wr_processing_spinlock, flags);
397 write_ipc_from_queue(dev);
403 * ipc_send_mng_msg() - Send management message
404 * @dev: ishtp device instance
405 * @msg_code: Message code
406 * @msg: Pointer to message
407 * @size: Length of message
409 * Send management message to FW
411 * Return: 0 for success else failure code
413 static int ipc_send_mng_msg(struct ishtp_device *dev, uint32_t msg_code,
414 void *msg, size_t size)
416 unsigned char ipc_msg[IPC_FULL_MSG_SIZE];
417 uint32_t drbl_val = IPC_BUILD_MNG_MSG(msg_code, size);
419 memcpy(ipc_msg, &drbl_val, sizeof(uint32_t));
420 memcpy(ipc_msg + sizeof(uint32_t), msg, size);
421 return write_ipc_to_queue(dev, NULL, NULL, ipc_msg,
422 sizeof(uint32_t) + size);
425 #define WAIT_FOR_FW_RDY 0x1
426 #define WAIT_FOR_INPUT_RDY 0x2
429 * timed_wait_for_timeout() - wait special event with timeout
430 * @dev: ISHTP device pointer
431 * @condition: indicate the condition for waiting
432 * @timeinc: time slice for every wait cycle, in ms
433 * @timeout: time in ms for timeout
435 * This function will check special event to be ready in a loop, the loop
436 * period is specificd in timeinc. Wait timeout will causes failure.
438 * Return: 0 for success else failure code
440 static int timed_wait_for_timeout(struct ishtp_device *dev, int condition,
441 unsigned int timeinc, unsigned int timeout)
443 bool complete = false;
447 if (condition == WAIT_FOR_FW_RDY) {
448 complete = ishtp_fw_is_ready(dev);
449 } else if (condition == WAIT_FOR_INPUT_RDY) {
450 complete = ish_is_input_ready(dev);
457 unsigned long left_time;
459 left_time = msleep_interruptible(timeinc);
460 timeout -= (timeinc - left_time);
462 } while (!complete && timeout > 0);
473 #define TIME_SLICE_FOR_FW_RDY_MS 100
474 #define TIME_SLICE_FOR_INPUT_RDY_MS 100
475 #define TIMEOUT_FOR_FW_RDY_MS 2000
476 #define TIMEOUT_FOR_INPUT_RDY_MS 2000
479 * ish_fw_reset_handler() - FW reset handler
480 * @dev: ishtp device pointer
484 * Return: 0 for success else failure code
486 static int ish_fw_reset_handler(struct ishtp_device *dev)
490 struct wr_msg_ctl_info *processing, *next;
493 reset_id = ish_reg_read(dev, IPC_REG_ISH2HOST_MSG) & 0xFFFF;
495 /* Clear IPC output queue */
496 spin_lock_irqsave(&dev->wr_processing_spinlock, flags);
497 list_for_each_entry_safe(processing, next,
498 &dev->wr_processing_list_head.link, link) {
499 list_move_tail(&processing->link, &dev->wr_free_list_head.link);
501 spin_unlock_irqrestore(&dev->wr_processing_spinlock, flags);
503 /* ISHTP notification in IPC_RESET */
504 ishtp_reset_handler(dev);
506 if (!ish_is_input_ready(dev))
507 timed_wait_for_timeout(dev, WAIT_FOR_INPUT_RDY,
508 TIME_SLICE_FOR_INPUT_RDY_MS, TIMEOUT_FOR_INPUT_RDY_MS);
511 if (!ish_is_input_ready(dev))
514 * Set HOST2ISH.ILUP. Apparently we need this BEFORE sending
515 * RESET_NOTIFY_ACK - FW will be checking for it
517 ish_set_host_rdy(dev);
518 /* Send RESET_NOTIFY_ACK (with reset_id) */
519 ipc_send_mng_msg(dev, MNG_RESET_NOTIFY_ACK, &reset_id,
522 /* Wait for ISH FW'es ILUP and ISHTP_READY */
523 timed_wait_for_timeout(dev, WAIT_FOR_FW_RDY,
524 TIME_SLICE_FOR_FW_RDY_MS, TIMEOUT_FOR_FW_RDY_MS);
525 if (!ishtp_fw_is_ready(dev)) {
529 ish_status = _ish_read_fw_sts_reg(dev);
531 "[ishtp-ish]: completed reset, ISH is dead (FWSTS = %08X)\n",
538 #define TIMEOUT_FOR_HW_RDY_MS 300
541 * ish_fw_reset_work_fn() - FW reset worker function
544 * Call ish_fw_reset_handler to complete FW reset
546 static void fw_reset_work_fn(struct work_struct *unused)
550 rv = ish_fw_reset_handler(ishtp_dev);
552 /* ISH is ILUP & ISHTP-ready. Restart ISHTP */
553 msleep_interruptible(TIMEOUT_FOR_HW_RDY_MS);
554 ishtp_dev->recvd_hw_ready = 1;
555 wake_up_interruptible(&ishtp_dev->wait_hw_ready);
557 /* ISHTP notification in IPC_RESET sequence completion */
558 ishtp_reset_compl_handler(ishtp_dev);
560 dev_err(ishtp_dev->devc, "[ishtp-ish]: FW reset failed (%d)\n",
565 * _ish_sync_fw_clock() -Sync FW clock with the OS clock
566 * @dev: ishtp device pointer
568 * Sync FW and OS time
570 static void _ish_sync_fw_clock(struct ishtp_device *dev)
572 static unsigned long prev_sync;
575 if (prev_sync && jiffies - prev_sync < 20 * HZ)
579 usec = ktime_to_us(ktime_get_boottime());
580 ipc_send_mng_msg(dev, MNG_SYNC_FW_CLOCK, &usec, sizeof(uint64_t));
584 * recv_ipc() - Receive and process IPC management messages
585 * @dev: ishtp device instance
586 * @doorbell_val: doorbell value
588 * This function runs in ISR context.
589 * NOTE: Any other mng command than reset_notify and reset_notify_ack
590 * won't wake BH handler
592 static void recv_ipc(struct ishtp_device *dev, uint32_t doorbell_val)
596 mng_cmd = IPC_HEADER_GET_MNG_CMD(doorbell_val);
602 case MNG_RX_CMPL_INDICATION:
603 if (dev->suspend_flag) {
604 dev->suspend_flag = 0;
605 wake_up_interruptible(&dev->suspend_wait);
607 if (dev->resume_flag) {
608 dev->resume_flag = 0;
609 wake_up_interruptible(&dev->resume_wait);
612 write_ipc_from_queue(dev);
615 case MNG_RESET_NOTIFY:
618 INIT_WORK(&fw_reset_work, fw_reset_work_fn);
620 schedule_work(&fw_reset_work);
623 case MNG_RESET_NOTIFY_ACK:
624 dev->recvd_hw_ready = 1;
625 wake_up_interruptible(&dev->wait_hw_ready);
631 * ish_irq_handler() - ISH IRQ handler
633 * @dev_id: ishtp device pointer
635 * ISH IRQ handler. If interrupt is generated and is for ISH it will process
638 irqreturn_t ish_irq_handler(int irq, void *dev_id)
640 struct ishtp_device *dev = dev_id;
641 uint32_t doorbell_val;
642 bool interrupt_generated;
644 /* Check that it's interrupt from ISH (may be shared) */
645 interrupt_generated = check_generated_interrupt(dev);
647 if (!interrupt_generated)
650 doorbell_val = ish_reg_read(dev, IPC_REG_ISH2HOST_DRBL);
651 if (!IPC_IS_BUSY(doorbell_val))
654 if (dev->dev_state == ISHTP_DEV_DISABLED)
657 /* Sanity check: IPC dgram length in header */
658 if (IPC_HEADER_GET_LENGTH(doorbell_val) > IPC_PAYLOAD_SIZE) {
660 "IPC hdr - bad length: %u; dropped\n",
661 (unsigned int)IPC_HEADER_GET_LENGTH(doorbell_val));
665 switch (IPC_HEADER_GET_PROTOCOL(doorbell_val)) {
668 case IPC_PROTOCOL_MNG:
669 recv_ipc(dev, doorbell_val);
671 case IPC_PROTOCOL_ISHTP:
677 /* Update IPC counters */
679 dev->ipc_rx_bytes_cnt += IPC_HEADER_GET_LENGTH(doorbell_val);
681 ish_reg_write(dev, IPC_REG_ISH2HOST_DRBL, 0);
682 /* Flush write to doorbell */
683 ish_reg_read(dev, IPC_REG_ISH_HOST_FWSTS);
689 * ish_disable_dma() - disable dma communication between host and ISHFW
690 * @dev: ishtp device pointer
692 * Clear the dma enable bit and wait for dma inactive.
694 * Return: 0 for success else error code.
696 static int ish_disable_dma(struct ishtp_device *dev)
698 unsigned int dma_delay;
700 /* Clear the dma enable bit */
701 ish_reg_write(dev, IPC_REG_ISH_RMP2, 0);
703 /* wait for dma inactive */
704 for (dma_delay = 0; dma_delay < MAX_DMA_DELAY &&
705 _ish_read_fw_sts_reg(dev) & (IPC_ISH_IN_DMA);
709 if (dma_delay >= MAX_DMA_DELAY) {
711 "Wait for DMA inactive timeout\n");
719 * ish_wakeup() - wakeup ishfw from waiting-for-host state
720 * @dev: ishtp device pointer
722 * Set the dma enable bit and send a void message to FW,
723 * it wil wakeup FW from waiting-for-host state.
725 static void ish_wakeup(struct ishtp_device *dev)
727 /* Set dma enable bit */
728 ish_reg_write(dev, IPC_REG_ISH_RMP2, IPC_RMP2_DMA_ENABLED);
731 * Send 0 IPC message so that ISH FW wakes up if it was already
734 ish_reg_write(dev, IPC_REG_HOST2ISH_DRBL, IPC_DRBL_BUSY_BIT);
736 /* Flush writes to doorbell and REMAP2 */
737 ish_reg_read(dev, IPC_REG_ISH_HOST_FWSTS);
741 * _ish_hw_reset() - HW reset
742 * @dev: ishtp device pointer
744 * Reset ISH HW to recover if any error
746 * Return: 0 for success else error fault code
748 static int _ish_hw_reset(struct ishtp_device *dev)
750 struct pci_dev *pdev = dev->pdev;
757 rv = pci_reset_function(pdev);
759 dev->dev_state = ISHTP_DEV_RESETTING;
762 dev_err(&pdev->dev, "Can't reset - no PM caps\n");
766 /* Disable dma communication between FW and host */
767 if (ish_disable_dma(dev)) {
769 "Can't reset - stuck with DMA in-progress\n");
773 pci_read_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, &csr);
775 csr &= ~PCI_PM_CTRL_STATE_MASK;
777 pci_write_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, csr);
779 mdelay(pdev->d3_delay);
781 csr &= ~PCI_PM_CTRL_STATE_MASK;
783 pci_write_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, csr);
785 /* Now we can enable ISH DMA operation and wakeup ISHFW */
792 * _ish_ipc_reset() - IPC reset
793 * @dev: ishtp device pointer
795 * Resets host and fw IPC and upper layers
797 * Return: 0 for success else error fault code
799 static int _ish_ipc_reset(struct ishtp_device *dev)
801 struct ipc_rst_payload_type ipc_mng_msg;
804 ipc_mng_msg.reset_id = 1;
805 ipc_mng_msg.reserved = 0;
809 /* Clear the incoming doorbell */
810 ish_reg_write(dev, IPC_REG_ISH2HOST_DRBL, 0);
811 /* Flush write to doorbell */
812 ish_reg_read(dev, IPC_REG_ISH_HOST_FWSTS);
814 dev->recvd_hw_ready = 0;
817 rv = ipc_send_mng_msg(dev, MNG_RESET_NOTIFY, &ipc_mng_msg,
818 sizeof(struct ipc_rst_payload_type));
820 dev_err(dev->devc, "Failed to send IPC MNG_RESET_NOTIFY\n");
824 wait_event_interruptible_timeout(dev->wait_hw_ready,
825 dev->recvd_hw_ready, 2 * HZ);
826 if (!dev->recvd_hw_ready) {
827 dev_err(dev->devc, "Timed out waiting for HW ready\n");
835 * ish_hw_start() -Start ISH HW
836 * @dev: ishtp device pointer
838 * Set host to ready state and wait for FW reset
840 * Return: 0 for success else error fault code
842 int ish_hw_start(struct ishtp_device *dev)
844 ish_set_host_rdy(dev);
846 /* After that we can enable ISH DMA operation and wakeup ISHFW */
851 /* wait for FW-initiated reset flow */
852 if (!dev->recvd_hw_ready)
853 wait_event_interruptible_timeout(dev->wait_hw_ready,
857 if (!dev->recvd_hw_ready) {
859 "[ishtp-ish]: Timed out waiting for FW-initiated reset\n");
867 * ish_ipc_get_header() -Get doorbell value
868 * @dev: ishtp device pointer
869 * @length: length of message
872 * Get door bell value from message header
874 * Return: door bell value
876 static uint32_t ish_ipc_get_header(struct ishtp_device *dev, int length,
881 drbl_val = IPC_BUILD_HEADER(length, IPC_PROTOCOL_ISHTP, busy);
886 static const struct ishtp_hw_ops ish_hw_ops = {
887 .hw_reset = _ish_hw_reset,
888 .ipc_reset = _ish_ipc_reset,
889 .ipc_get_header = ish_ipc_get_header,
890 .ishtp_read = _ishtp_read,
891 .write = write_ipc_to_queue,
892 .get_fw_status = _ish_read_fw_sts_reg,
893 .sync_fw_clock = _ish_sync_fw_clock,
894 .ishtp_read_hdr = _ishtp_read_hdr
898 * ish_dev_init() -Initialize ISH devoce
901 * Allocate ISHTP device and initialize IPC processing
903 * Return: ISHTP device instance on success else NULL
905 struct ishtp_device *ish_dev_init(struct pci_dev *pdev)
907 struct ishtp_device *dev;
910 dev = kzalloc(sizeof(struct ishtp_device) + sizeof(struct ish_hw),
915 ishtp_device_init(dev);
917 init_waitqueue_head(&dev->wait_hw_ready);
919 spin_lock_init(&dev->wr_processing_spinlock);
920 spin_lock_init(&dev->out_ipc_spinlock);
922 /* Init IPC processing and free lists */
923 INIT_LIST_HEAD(&dev->wr_processing_list_head.link);
924 INIT_LIST_HEAD(&dev->wr_free_list_head.link);
925 for (i = 0; i < IPC_TX_FIFO_SIZE; ++i) {
926 struct wr_msg_ctl_info *tx_buf;
928 tx_buf = kzalloc(sizeof(struct wr_msg_ctl_info), GFP_KERNEL);
931 * IPC buffers may be limited or not available
932 * at all - although this shouldn't happen
935 "[ishtp-ish]: failure in Tx FIFO allocations (%d)\n",
939 list_add_tail(&tx_buf->link, &dev->wr_free_list_head.link);
942 dev->ops = &ish_hw_ops;
943 dev->devc = &pdev->dev;
944 dev->mtu = IPC_PAYLOAD_SIZE - sizeof(struct ishtp_msg_hdr);
949 * ish_device_disable() - Disable ISH device
950 * @dev: ISHTP device pointer
952 * Disable ISH by clearing host ready to inform firmware.
954 void ish_device_disable(struct ishtp_device *dev)
956 struct pci_dev *pdev = dev->pdev;
961 /* Disable dma communication between FW and host */
962 if (ish_disable_dma(dev)) {
964 "Can't reset - stuck with DMA in-progress\n");
968 /* Put ISH to D3hot state for power saving */
969 pci_set_power_state(pdev, PCI_D3hot);
971 dev->dev_state = ISHTP_DEV_DISABLED;
972 ish_clr_host_rdy(dev);