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