Lines Matching refs:dev

23 static void ishtp_hbm_fw_cl_allocate(struct ishtp_device *dev)  in ishtp_hbm_fw_cl_allocate()  argument
29 for_each_set_bit(b, dev->fw_clients_map, ISHTP_CLIENTS_MAX) in ishtp_hbm_fw_cl_allocate()
30 dev->fw_clients_num++; in ishtp_hbm_fw_cl_allocate()
32 if (dev->fw_clients_num <= 0) in ishtp_hbm_fw_cl_allocate()
36 clients = kcalloc(dev->fw_clients_num, sizeof(struct ishtp_fw_client), in ishtp_hbm_fw_cl_allocate()
39 dev->dev_state = ISHTP_DEV_RESETTING; in ishtp_hbm_fw_cl_allocate()
40 ish_hw_reset(dev); in ishtp_hbm_fw_cl_allocate()
43 dev->fw_clients = clients; in ishtp_hbm_fw_cl_allocate()
92 int ishtp_hbm_start_wait(struct ishtp_device *dev) in ishtp_hbm_start_wait() argument
96 if (dev->hbm_state > ISHTP_HBM_START) in ishtp_hbm_start_wait()
99 dev_dbg(dev->devc, "Going to wait for ishtp start. hbm_state=%08X\n", in ishtp_hbm_start_wait()
100 dev->hbm_state); in ishtp_hbm_start_wait()
101 ret = wait_event_interruptible_timeout(dev->wait_hbm_recvd_msg, in ishtp_hbm_start_wait()
102 dev->hbm_state >= ISHTP_HBM_STARTED, in ishtp_hbm_start_wait()
105 dev_dbg(dev->devc, in ishtp_hbm_start_wait()
107 dev->hbm_state); in ishtp_hbm_start_wait()
109 if (ret <= 0 && (dev->hbm_state <= ISHTP_HBM_START)) { in ishtp_hbm_start_wait()
110 dev->hbm_state = ISHTP_HBM_IDLE; in ishtp_hbm_start_wait()
111 dev_err(dev->devc, in ishtp_hbm_start_wait()
113 ret, dev->hbm_state); in ishtp_hbm_start_wait()
127 int ishtp_hbm_start_req(struct ishtp_device *dev) in ishtp_hbm_start_req() argument
144 dev->hbm_state = ISHTP_HBM_START; in ishtp_hbm_start_req()
145 if (ishtp_write_message(dev, &hdr, &start_req)) { in ishtp_hbm_start_req()
146 dev_err(dev->devc, "version message send failed\n"); in ishtp_hbm_start_req()
147 dev->dev_state = ISHTP_DEV_RESETTING; in ishtp_hbm_start_req()
148 dev->hbm_state = ISHTP_HBM_IDLE; in ishtp_hbm_start_req()
149 ish_hw_reset(dev); in ishtp_hbm_start_req()
164 void ishtp_hbm_enum_clients_req(struct ishtp_device *dev) in ishtp_hbm_enum_clients_req() argument
173 if (ishtp_write_message(dev, &hdr, &enum_req)) { in ishtp_hbm_enum_clients_req()
174 dev->dev_state = ISHTP_DEV_RESETTING; in ishtp_hbm_enum_clients_req()
175 dev_err(dev->devc, "enumeration request send failed\n"); in ishtp_hbm_enum_clients_req()
176 ish_hw_reset(dev); in ishtp_hbm_enum_clients_req()
178 dev->hbm_state = ISHTP_HBM_ENUM_CLIENTS; in ishtp_hbm_enum_clients_req()
189 static int ishtp_hbm_prop_req(struct ishtp_device *dev) in ishtp_hbm_prop_req() argument
196 client_num = dev->fw_client_presentation_num; in ishtp_hbm_prop_req()
198 next_client_index = find_next_bit(dev->fw_clients_map, in ishtp_hbm_prop_req()
199 ISHTP_CLIENTS_MAX, dev->fw_client_index); in ishtp_hbm_prop_req()
203 dev->hbm_state = ISHTP_HBM_WORKING; in ishtp_hbm_prop_req()
204 dev->dev_state = ISHTP_DEV_ENABLED; in ishtp_hbm_prop_req()
206 for (dev->fw_client_presentation_num = 1; in ishtp_hbm_prop_req()
207 dev->fw_client_presentation_num < client_num + 1; in ishtp_hbm_prop_req()
208 ++dev->fw_client_presentation_num) in ishtp_hbm_prop_req()
210 ishtp_bus_new_client(dev); in ishtp_hbm_prop_req()
214 dev->fw_clients[client_num].client_id = next_client_index; in ishtp_hbm_prop_req()
221 if (ishtp_write_message(dev, &hdr, &prop_req)) { in ishtp_hbm_prop_req()
222 dev->dev_state = ISHTP_DEV_RESETTING; in ishtp_hbm_prop_req()
223 dev_err(dev->devc, "properties request send failed\n"); in ishtp_hbm_prop_req()
224 ish_hw_reset(dev); in ishtp_hbm_prop_req()
228 dev->fw_client_index = next_client_index; in ishtp_hbm_prop_req()
239 static void ishtp_hbm_stop_req(struct ishtp_device *dev) in ishtp_hbm_stop_req() argument
249 ishtp_write_message(dev, &hdr, &stop_req); in ishtp_hbm_stop_req()
261 int ishtp_hbm_cl_flow_control_req(struct ishtp_device *dev, in ishtp_hbm_cl_flow_control_req() argument
286 rv = ishtp_write_message(dev, &hdr, &flow_ctrl); in ishtp_hbm_cl_flow_control_req()
313 int ishtp_hbm_cl_disconnect_req(struct ishtp_device *dev, struct ishtp_cl *cl) in ishtp_hbm_cl_disconnect_req() argument
322 return ishtp_write_message(dev, &hdr, &disconn_req); in ishtp_hbm_cl_disconnect_req()
332 static void ishtp_hbm_cl_disconnect_res(struct ishtp_device *dev, in ishtp_hbm_cl_disconnect_res() argument
338 spin_lock_irqsave(&dev->cl_list_lock, flags); in ishtp_hbm_cl_disconnect_res()
339 list_for_each_entry(cl, &dev->cl_list, link) { in ishtp_hbm_cl_disconnect_res()
346 spin_unlock_irqrestore(&dev->cl_list_lock, flags); in ishtp_hbm_cl_disconnect_res()
358 int ishtp_hbm_cl_connect_req(struct ishtp_device *dev, struct ishtp_cl *cl) in ishtp_hbm_cl_connect_req() argument
367 return ishtp_write_message(dev, &hdr, &conn_req); in ishtp_hbm_cl_connect_req()
377 static void ishtp_hbm_cl_connect_res(struct ishtp_device *dev, in ishtp_hbm_cl_connect_res() argument
383 spin_lock_irqsave(&dev->cl_list_lock, flags); in ishtp_hbm_cl_connect_res()
384 list_for_each_entry(cl, &dev->cl_list, link) { in ishtp_hbm_cl_connect_res()
397 spin_unlock_irqrestore(&dev->cl_list_lock, flags); in ishtp_hbm_cl_connect_res()
407 static void ishtp_hbm_fw_disconnect_req(struct ishtp_device *dev, in ishtp_hbm_fw_disconnect_req() argument
416 spin_lock_irqsave(&dev->cl_list_lock, flags); in ishtp_hbm_fw_disconnect_req()
417 list_for_each_entry(cl, &dev->cl_list, link) { in ishtp_hbm_fw_disconnect_req()
425 ishtp_write_message(dev, &hdr, data); in ishtp_hbm_fw_disconnect_req()
429 spin_unlock_irqrestore(&dev->cl_list_lock, flags); in ishtp_hbm_fw_disconnect_req()
439 static void ishtp_hbm_dma_xfer_ack(struct ishtp_device *dev, in ishtp_hbm_dma_xfer_ack() argument
445 (struct ishtp_msg_hdr *)&dev->ishtp_msg_hdr; in ishtp_hbm_dma_xfer_ack()
451 offs = dma_xfer->msg_addr - dev->ishtp_host_dma_tx_buf_phys; in ishtp_hbm_dma_xfer_ack()
452 if (offs > dev->ishtp_host_dma_tx_buf_size) { in ishtp_hbm_dma_xfer_ack()
453 dev_err(dev->devc, "Bad DMA Tx ack message address\n"); in ishtp_hbm_dma_xfer_ack()
457 dev->ishtp_host_dma_tx_buf_size - offs) { in ishtp_hbm_dma_xfer_ack()
458 dev_err(dev->devc, "Bad DMA Tx ack message size\n"); in ishtp_hbm_dma_xfer_ack()
463 msg = (unsigned char *)dev->ishtp_host_dma_tx_buf + offs; in ishtp_hbm_dma_xfer_ack()
464 ishtp_cl_release_dma_acked_mem(dev, msg, dma_xfer->msg_length); in ishtp_hbm_dma_xfer_ack()
466 list_for_each_entry(cl, &dev->cl_list, link) { in ishtp_hbm_dma_xfer_ack()
487 ishtp_cl_send_msg(dev, cl); in ishtp_hbm_dma_xfer_ack()
502 static void ishtp_hbm_dma_xfer(struct ishtp_device *dev, in ishtp_hbm_dma_xfer() argument
509 (struct ishtp_msg_hdr *) &dev->ishtp_msg_hdr; in ishtp_hbm_dma_xfer()
516 offs = dma_xfer->msg_addr - dev->ishtp_host_dma_rx_buf_phys; in ishtp_hbm_dma_xfer()
517 if (offs > dev->ishtp_host_dma_rx_buf_size) { in ishtp_hbm_dma_xfer()
518 dev_err(dev->devc, "Bad DMA Rx message address\n"); in ishtp_hbm_dma_xfer()
522 dev->ishtp_host_dma_rx_buf_size - offs) { in ishtp_hbm_dma_xfer()
523 dev_err(dev->devc, "Bad DMA Rx message size\n"); in ishtp_hbm_dma_xfer()
526 msg = dev->ishtp_host_dma_rx_buf + offs; in ishtp_hbm_dma_xfer()
527 recv_ishtp_cl_msg_dma(dev, msg, dma_xfer); in ishtp_hbm_dma_xfer()
534 ishtp_write_message(dev, &hdr, (unsigned char *)prm); in ishtp_hbm_dma_xfer()
545 void ishtp_hbm_dispatch(struct ishtp_device *dev, in ishtp_hbm_dispatch() argument
566 dev->version = version_res->fw_max_version; in ishtp_hbm_dispatch()
568 dev->hbm_state = ISHTP_HBM_STOPPED; in ishtp_hbm_dispatch()
569 ishtp_hbm_stop_req(dev); in ishtp_hbm_dispatch()
573 dev->version.major_version = HBM_MAJOR_VERSION; in ishtp_hbm_dispatch()
574 dev->version.minor_version = HBM_MINOR_VERSION; in ishtp_hbm_dispatch()
575 if (dev->dev_state == ISHTP_DEV_INIT_CLIENTS && in ishtp_hbm_dispatch()
576 dev->hbm_state == ISHTP_HBM_START) { in ishtp_hbm_dispatch()
577 dev->hbm_state = ISHTP_HBM_STARTED; in ishtp_hbm_dispatch()
578 ishtp_hbm_enum_clients_req(dev); in ishtp_hbm_dispatch()
580 dev_err(dev->devc, in ishtp_hbm_dispatch()
583 ish_hw_reset(dev); in ishtp_hbm_dispatch()
587 wake_up_interruptible(&dev->wait_hbm_recvd_msg); in ishtp_hbm_dispatch()
592 ishtp_hbm_cl_connect_res(dev, connect_res); in ishtp_hbm_dispatch()
598 ishtp_hbm_cl_disconnect_res(dev, disconnect_res); in ishtp_hbm_dispatch()
603 fw_client = &dev->fw_clients[dev->fw_client_presentation_num]; in ishtp_hbm_dispatch()
605 if (props_res->status || !dev->fw_clients) { in ishtp_hbm_dispatch()
606 dev_err(dev->devc, in ishtp_hbm_dispatch()
608 ish_hw_reset(dev); in ishtp_hbm_dispatch()
613 dev_err(dev->devc, in ishtp_hbm_dispatch()
616 ish_hw_reset(dev); in ishtp_hbm_dispatch()
620 if (dev->dev_state != ISHTP_DEV_INIT_CLIENTS || in ishtp_hbm_dispatch()
621 dev->hbm_state != ISHTP_HBM_CLIENT_PROPERTIES) { in ishtp_hbm_dispatch()
622 dev_err(dev->devc, in ishtp_hbm_dispatch()
624 ish_hw_reset(dev); in ishtp_hbm_dispatch()
629 dev->fw_client_index++; in ishtp_hbm_dispatch()
630 dev->fw_client_presentation_num++; in ishtp_hbm_dispatch()
633 ishtp_hbm_prop_req(dev); in ishtp_hbm_dispatch()
635 if (dev->dev_state != ISHTP_DEV_ENABLED) in ishtp_hbm_dispatch()
641 dev_dbg(dev->devc, "Requesting to use DMA\n"); in ishtp_hbm_dispatch()
642 ishtp_cl_alloc_dma_buf(dev); in ishtp_hbm_dispatch()
643 if (dev->ishtp_host_dma_rx_buf) { in ishtp_hbm_dispatch()
649 dev->ishtp_host_dma_rx_buf_size; in ishtp_hbm_dispatch()
651 dev->ishtp_host_dma_rx_buf_phys; in ishtp_hbm_dispatch()
653 ishtp_write_message(dev, &ishtp_hdr, in ishtp_hbm_dispatch()
661 memcpy(dev->fw_clients_map, enum_res->valid_addresses, 32); in ishtp_hbm_dispatch()
662 if (dev->dev_state == ISHTP_DEV_INIT_CLIENTS && in ishtp_hbm_dispatch()
663 dev->hbm_state == ISHTP_HBM_ENUM_CLIENTS) { in ishtp_hbm_dispatch()
664 dev->fw_client_presentation_num = 0; in ishtp_hbm_dispatch()
665 dev->fw_client_index = 0; in ishtp_hbm_dispatch()
667 ishtp_hbm_fw_cl_allocate(dev); in ishtp_hbm_dispatch()
668 dev->hbm_state = ISHTP_HBM_CLIENT_PROPERTIES; in ishtp_hbm_dispatch()
671 ishtp_hbm_prop_req(dev); in ishtp_hbm_dispatch()
673 dev_err(dev->devc, in ishtp_hbm_dispatch()
675 ish_hw_reset(dev); in ishtp_hbm_dispatch()
681 if (dev->hbm_state != ISHTP_HBM_STOPPED) in ishtp_hbm_dispatch()
682 dev_err(dev->devc, "unexpected stop response\n"); in ishtp_hbm_dispatch()
684 dev->dev_state = ISHTP_DEV_DISABLED; in ishtp_hbm_dispatch()
685 dev_info(dev->devc, "reset: FW stop response\n"); in ishtp_hbm_dispatch()
686 ish_hw_reset(dev); in ishtp_hbm_dispatch()
693 ishtp_hbm_fw_disconnect_req(dev, disconnect_req); in ishtp_hbm_dispatch()
697 dev->hbm_state = ISHTP_HBM_STOPPED; in ishtp_hbm_dispatch()
701 dev->ishtp_host_dma_enabled = 1; in ishtp_hbm_dispatch()
706 if (!dev->ishtp_host_dma_enabled) { in ishtp_hbm_dispatch()
707 dev_err(dev->devc, in ishtp_hbm_dispatch()
711 ishtp_hbm_dma_xfer(dev, dma_xfer); in ishtp_hbm_dispatch()
716 if (!dev->ishtp_host_dma_enabled || in ishtp_hbm_dispatch()
717 !dev->ishtp_host_dma_tx_buf) { in ishtp_hbm_dispatch()
718 dev_err(dev->devc, in ishtp_hbm_dispatch()
722 ishtp_hbm_dma_xfer_ack(dev, dma_xfer); in ishtp_hbm_dispatch()
726 dev_err(dev->devc, "unknown HBM: %u\n", in ishtp_hbm_dispatch()
743 struct ishtp_device *dev; in bh_hbm_work_fn() local
746 dev = container_of(work, struct ishtp_device, bh_hbm_work); in bh_hbm_work_fn()
747 spin_lock_irqsave(&dev->rd_msg_spinlock, flags); in bh_hbm_work_fn()
748 if (dev->rd_msg_fifo_head != dev->rd_msg_fifo_tail) { in bh_hbm_work_fn()
749 memcpy(hbm, dev->rd_msg_fifo + dev->rd_msg_fifo_head, in bh_hbm_work_fn()
751 dev->rd_msg_fifo_head = in bh_hbm_work_fn()
752 (dev->rd_msg_fifo_head + IPC_PAYLOAD_SIZE) % in bh_hbm_work_fn()
754 spin_unlock_irqrestore(&dev->rd_msg_spinlock, flags); in bh_hbm_work_fn()
755 ishtp_hbm_dispatch(dev, (struct ishtp_bus_message *)hbm); in bh_hbm_work_fn()
757 spin_unlock_irqrestore(&dev->rd_msg_spinlock, flags); in bh_hbm_work_fn()
769 void recv_hbm(struct ishtp_device *dev, struct ishtp_msg_hdr *ishtp_hdr) in recv_hbm() argument
776 dev->ops->ishtp_read(dev, rd_msg_buf, ishtp_hdr->length); in recv_hbm()
785 spin_lock_irqsave(&dev->cl_list_lock, flags); in recv_hbm()
786 list_for_each_entry(cl, &dev->cl_list, link) { in recv_hbm()
797 dev_err(dev->devc, in recv_hbm()
817 ishtp_cl_send_msg(dev, cl); in recv_hbm()
827 spin_unlock_irqrestore(&dev->cl_list_lock, flags); in recv_hbm()
839 ishtp_hbm_dispatch(dev, ishtp_msg); in recv_hbm()
848 spin_lock_irqsave(&dev->rd_msg_spinlock, flags); in recv_hbm()
849 if ((dev->rd_msg_fifo_tail + IPC_PAYLOAD_SIZE) % in recv_hbm()
851 dev->rd_msg_fifo_head) { in recv_hbm()
852 spin_unlock_irqrestore(&dev->rd_msg_spinlock, flags); in recv_hbm()
853 dev_err(dev->devc, "BH buffer overflow, dropping HBM %u\n", in recv_hbm()
857 memcpy(dev->rd_msg_fifo + dev->rd_msg_fifo_tail, ishtp_msg, in recv_hbm()
859 dev->rd_msg_fifo_tail = (dev->rd_msg_fifo_tail + IPC_PAYLOAD_SIZE) % in recv_hbm()
861 spin_unlock_irqrestore(&dev->rd_msg_spinlock, flags); in recv_hbm()
862 schedule_work(&dev->bh_hbm_work); in recv_hbm()
875 void recv_fixed_cl_msg(struct ishtp_device *dev, in recv_fixed_cl_msg() argument
880 dev->print_log(dev, in recv_fixed_cl_msg()
883 dev->ops->ishtp_read(dev, rd_msg_buf, ishtp_hdr->length); in recv_fixed_cl_msg()
888 ishtp_send_resume(dev); in recv_fixed_cl_msg()
891 dev_err(dev->devc, "unknown fixed client msg [%02X]\n", in recv_fixed_cl_msg()
925 void ishtp_send_suspend(struct ishtp_device *dev) in ishtp_send_suspend() argument
937 dev->print_log(dev, "%s() sends SUSPEND notification\n", __func__); in ishtp_send_suspend()
940 ishtp_write_message(dev, &ishtp_hdr, in ishtp_send_suspend()
951 void ishtp_send_resume(struct ishtp_device *dev) in ishtp_send_resume() argument
963 dev->print_log(dev, "%s() sends RESUME notification\n", __func__); in ishtp_send_resume()
966 ishtp_write_message(dev, &ishtp_hdr, in ishtp_send_resume()
977 void ishtp_query_subscribers(struct ishtp_device *dev) in ishtp_query_subscribers() argument
988 ishtp_write_message(dev, &ishtp_hdr, in ishtp_query_subscribers()