Lines Matching +full:channel +full:-

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2020-21 Intel Corporation.
15 /* Open a packet data online channel between the network layer and CP. */
18 dev_dbg(ipc_imem->dev, "%s if id: %d", in ipc_imem_sys_wwan_open()
19 ipc_imem_phase_get_string(ipc_imem->phase), if_id); in ipc_imem_sys_wwan_open()
23 dev_err(ipc_imem->dev, "net:%d : refused phase %s", if_id, in ipc_imem_sys_wwan_open()
24 ipc_imem_phase_get_string(ipc_imem->phase)); in ipc_imem_sys_wwan_open()
25 return -EIO; in ipc_imem_sys_wwan_open()
28 return ipc_mux_open_session(ipc_imem->mux, if_id); in ipc_imem_sys_wwan_open()
35 if (ipc_imem->mux && if_id >= IP_MUX_SESSION_START && in ipc_imem_sys_wwan_close()
37 ipc_mux_close_session(ipc_imem->mux, if_id); in ipc_imem_sys_wwan_close()
60 int ret = -EINVAL; in ipc_imem_sys_wwan_transmit()
66 if (ipc_imem->phase != IPC_P_RUN) { in ipc_imem_sys_wwan_transmit()
67 dev_dbg(ipc_imem->dev, "phase %s transmit", in ipc_imem_sys_wwan_transmit()
68 ipc_imem_phase_get_string(ipc_imem->phase)); in ipc_imem_sys_wwan_transmit()
69 ret = -EIO; in ipc_imem_sys_wwan_transmit()
74 ret = ipc_mux_ul_trigger_encode(ipc_imem->mux, if_id, skb); in ipc_imem_sys_wwan_transmit()
79 /* Initialize wwan channel */
85 ipc_imem->cp_version = ipc_mmio_get_cp_version(ipc_imem->mmio); in ipc_imem_wwan_channel_init()
88 if (ipc_imem->cp_version == -1) { in ipc_imem_wwan_channel_init()
89 dev_err(ipc_imem->dev, "invalid CP version"); in ipc_imem_wwan_channel_init()
90 return -EIO; in ipc_imem_wwan_channel_init()
93 ipc_chnl_cfg_get(&chnl_cfg, ipc_imem->nr_of_channels); in ipc_imem_wwan_channel_init()
95 if (ipc_imem->mmio->mux_protocol == MUX_AGGREGATION && in ipc_imem_wwan_channel_init()
96 ipc_imem->nr_of_channels == IPC_MEM_IP_CHL_ID_0) { in ipc_imem_wwan_channel_init()
106 ipc_imem->wwan = ipc_wwan_init(ipc_imem, ipc_imem->dev); in ipc_imem_wwan_channel_init()
107 if (!ipc_imem->wwan) { in ipc_imem_wwan_channel_init()
108 dev_err(ipc_imem->dev, in ipc_imem_wwan_channel_init()
110 return -ENOMEM; in ipc_imem_wwan_channel_init()
120 struct iosm_pcie *ipc_pcie = ipc_imem->pcie; in ipc_imem_map_skb_to_dma()
121 char *buf = skb->data; in ipc_imem_map_skb_to_dma()
122 int len = skb->len; in ipc_imem_map_skb_to_dma()
131 BUILD_BUG_ON(sizeof(*IPC_CB(skb)) > sizeof(skb->cb)); in ipc_imem_map_skb_to_dma()
133 IPC_CB(skb)->mapping = mapping; in ipc_imem_map_skb_to_dma()
134 IPC_CB(skb)->direction = DMA_TO_DEVICE; in ipc_imem_map_skb_to_dma()
135 IPC_CB(skb)->len = len; in ipc_imem_map_skb_to_dma()
136 IPC_CB(skb)->op_type = (u8)UL_DEFAULT; in ipc_imem_map_skb_to_dma()
142 /* return true if channel is ready for use */
144 struct ipc_mem_channel *channel) in ipc_imem_is_channel_active() argument
149 phase = ipc_imem->phase; in ipc_imem_is_channel_active()
162 if (channel->state != IMEM_CHANNEL_RESERVED) { in ipc_imem_is_channel_active()
163 dev_err(ipc_imem->dev, in ipc_imem_is_channel_active()
164 "ch[%d]:invalid channel state %d,expected %d", in ipc_imem_is_channel_active()
165 channel->channel_id, channel->state, in ipc_imem_is_channel_active()
173 dev_err(ipc_imem->dev, "ch[%d]: confused phase %d", in ipc_imem_is_channel_active()
174 channel->channel_id, phase); in ipc_imem_is_channel_active()
177 /* Check the full availability of the channel. */ in ipc_imem_is_channel_active()
178 if (channel->state != IMEM_CHANNEL_ACTIVE) { in ipc_imem_is_channel_active()
179 dev_err(ipc_imem->dev, "ch[%d]: confused channel state %d", in ipc_imem_is_channel_active()
180 channel->channel_id, channel->state); in ipc_imem_is_channel_active()
192 * ipc_imem_sys_port_close - Release a sio link to CP.
194 * @channel: Channel instance.
197 struct ipc_mem_channel *channel) in ipc_imem_sys_port_close() argument
203 curr_phase = ipc_imem->phase; in ipc_imem_sys_port_close()
205 /* If current phase is IPC_P_OFF or SIO ID is -ve then in ipc_imem_sys_port_close()
206 * channel is already freed. Nothing to do. in ipc_imem_sys_port_close()
209 dev_err(ipc_imem->dev, in ipc_imem_sys_port_close()
215 if (channel->state == IMEM_CHANNEL_FREE) { in ipc_imem_sys_port_close()
216 dev_err(ipc_imem->dev, "ch[%d]: invalid channel state %d", in ipc_imem_sys_port_close()
217 channel->channel_id, channel->state); in ipc_imem_sys_port_close()
224 if (channel->ul_pipe.old_tail != channel->ul_pipe.old_head) { in ipc_imem_sys_port_close()
225 ipc_imem->app_notify_ul_pend = 1; in ipc_imem_sys_port_close()
231 (&ipc_imem->ul_pend_sem, in ipc_imem_sys_port_close()
234 dev_dbg(ipc_imem->dev, in ipc_imem_sys_port_close()
235 "Pend data Timeout UL-Pipe:%d Head:%d Tail:%d", in ipc_imem_sys_port_close()
236 channel->ul_pipe.pipe_nr, in ipc_imem_sys_port_close()
237 channel->ul_pipe.old_head, in ipc_imem_sys_port_close()
238 channel->ul_pipe.old_tail); in ipc_imem_sys_port_close()
241 ipc_imem->app_notify_ul_pend = 0; in ipc_imem_sys_port_close()
247 ipc_protocol_get_head_tail_index(ipc_imem->ipc_protocol, in ipc_imem_sys_port_close()
248 &channel->dl_pipe, NULL, &tail); in ipc_imem_sys_port_close()
250 if (tail != channel->dl_pipe.old_tail) { in ipc_imem_sys_port_close()
251 ipc_imem->app_notify_dl_pend = 1; in ipc_imem_sys_port_close()
257 (&ipc_imem->dl_pend_sem, in ipc_imem_sys_port_close()
260 dev_dbg(ipc_imem->dev, in ipc_imem_sys_port_close()
261 "Pend data Timeout DL-Pipe:%d Head:%d Tail:%d", in ipc_imem_sys_port_close()
262 channel->dl_pipe.pipe_nr, in ipc_imem_sys_port_close()
263 channel->dl_pipe.old_head, in ipc_imem_sys_port_close()
264 channel->dl_pipe.old_tail); in ipc_imem_sys_port_close()
267 ipc_imem->app_notify_dl_pend = 0; in ipc_imem_sys_port_close()
271 * between closing the pipe and updating the channel is closed. In this in ipc_imem_sys_port_close()
273 * the channel state as CLOSING to aviod unnecessary interrupt in ipc_imem_sys_port_close()
276 channel->state = IMEM_CHANNEL_CLOSING; in ipc_imem_sys_port_close()
278 ipc_imem_pipe_close(ipc_imem, &channel->ul_pipe); in ipc_imem_sys_port_close()
279 ipc_imem_pipe_close(ipc_imem, &channel->dl_pipe); in ipc_imem_sys_port_close()
281 ipc_imem_channel_free(channel); in ipc_imem_sys_port_close()
284 /* Open a PORT link to CP and return the channel */
288 struct ipc_mem_channel *channel; in ipc_imem_sys_port_open() local
293 dev_err(ipc_imem->dev, "PORT open refused, phase %s", in ipc_imem_sys_port_open()
294 ipc_imem_phase_get_string(ipc_imem->phase)); in ipc_imem_sys_port_open()
301 dev_err(ipc_imem->dev, "reservation of an PORT chnl id failed"); in ipc_imem_sys_port_open()
305 channel = ipc_imem_channel_open(ipc_imem, ch_id, hp_id); in ipc_imem_sys_port_open()
307 if (!channel) { in ipc_imem_sys_port_open()
308 dev_err(ipc_imem->dev, "PORT channel id open failed"); in ipc_imem_sys_port_open()
312 return channel; in ipc_imem_sys_port_open()
318 struct ipc_mem_channel *channel = ipc_cdev->channel; in ipc_imem_sys_cdev_write() local
319 struct iosm_imem *ipc_imem = ipc_cdev->ipc_imem; in ipc_imem_sys_cdev_write()
320 int ret = -EIO; in ipc_imem_sys_cdev_write()
322 if (!ipc_imem_is_channel_active(ipc_imem, channel) || in ipc_imem_sys_cdev_write()
323 ipc_imem->phase == IPC_P_OFF_REQ) in ipc_imem_sys_cdev_write()
332 skb_queue_tail(&channel->ul_list, skb); in ipc_imem_sys_cdev_write()
337 skb_dequeue_tail(&channel->ul_list); in ipc_imem_sys_cdev_write()
338 dev_err(ipc_cdev->dev, "channel id[%d] write failed\n", in ipc_imem_sys_cdev_write()
339 ipc_cdev->channel->channel_id); in ipc_imem_sys_cdev_write()
345 /* Open a SIO link to CP and return the channel instance */
348 struct ipc_mem_channel *channel; in ipc_imem_sys_devlink_open() local
356 /* Get a channel id as flash id and reserve it. */ in ipc_imem_sys_devlink_open()
362 dev_err(ipc_imem->dev, in ipc_imem_sys_devlink_open()
363 "reservation of a flash channel id failed"); in ipc_imem_sys_devlink_open()
367 ipc_imem->ipc_devlink->devlink_sio.channel_id = channel_id; in ipc_imem_sys_devlink_open()
368 channel = &ipc_imem->channels[channel_id]; in ipc_imem_sys_devlink_open()
372 dev_err(ipc_imem->dev, "Enqueue of chip info failed"); in ipc_imem_sys_devlink_open()
373 channel->state = IMEM_CHANNEL_FREE; in ipc_imem_sys_devlink_open()
377 return channel; in ipc_imem_sys_devlink_open()
381 ipc_imem->cp_version = ipc_mmio_get_cp_version(ipc_imem->mmio); in ipc_imem_sys_devlink_open()
382 if (ipc_imem->cp_version == -1) { in ipc_imem_sys_devlink_open()
383 dev_err(ipc_imem->dev, "invalid CP version"); in ipc_imem_sys_devlink_open()
387 channel_id = ipc_imem->ipc_devlink->devlink_sio.channel_id; in ipc_imem_sys_devlink_open()
393 dev_err(ipc_imem->dev, "SIO open refused, phase %d", phase); in ipc_imem_sys_devlink_open()
399 /* Release a SIO channel link to CP. */
402 struct iosm_imem *ipc_imem = ipc_devlink->pcie->imem; in ipc_imem_sys_devlink_close()
405 struct ipc_mem_channel *channel; in ipc_imem_sys_devlink_close() local
409 channel = ipc_imem->ipc_devlink->devlink_sio.channel; in ipc_imem_sys_devlink_close()
412 exec_stage = ipc_mmio_get_exec_stage(ipc_imem->mmio); in ipc_imem_sys_devlink_close()
417 boot_check_timeout -= 20; in ipc_imem_sys_devlink_close()
423 if (channel->ul_pipe.old_tail != channel->ul_pipe.old_head) { in ipc_imem_sys_devlink_close()
425 (&ipc_imem->ul_pend_sem, in ipc_imem_sys_devlink_close()
428 dev_dbg(ipc_imem->dev, in ipc_imem_sys_devlink_close()
429 "Data Timeout on UL-Pipe:%d Head:%d Tail:%d", in ipc_imem_sys_devlink_close()
430 channel->ul_pipe.pipe_nr, in ipc_imem_sys_devlink_close()
431 channel->ul_pipe.old_head, in ipc_imem_sys_devlink_close()
432 channel->ul_pipe.old_tail); in ipc_imem_sys_devlink_close()
436 ipc_protocol_get_head_tail_index(ipc_imem->ipc_protocol, in ipc_imem_sys_devlink_close()
437 &channel->dl_pipe, NULL, &tail); in ipc_imem_sys_devlink_close()
439 if (tail != channel->dl_pipe.old_tail) { in ipc_imem_sys_devlink_close()
441 (&ipc_imem->dl_pend_sem, in ipc_imem_sys_devlink_close()
444 dev_dbg(ipc_imem->dev, in ipc_imem_sys_devlink_close()
445 "Data Timeout on DL-Pipe:%d Head:%d Tail:%d", in ipc_imem_sys_devlink_close()
446 channel->dl_pipe.pipe_nr, in ipc_imem_sys_devlink_close()
447 channel->dl_pipe.old_head, in ipc_imem_sys_devlink_close()
448 channel->dl_pipe.old_tail); in ipc_imem_sys_devlink_close()
453 * between closing the pipe and updating the channel is closed. In this in ipc_imem_sys_devlink_close()
455 * the channel state as CLOSING to aviod unnecessary interrupt in ipc_imem_sys_devlink_close()
458 channel->state = IMEM_CHANNEL_CLOSING; in ipc_imem_sys_devlink_close()
460 ipc_imem_pipe_cleanup(ipc_imem, &channel->ul_pipe); in ipc_imem_sys_devlink_close()
461 ipc_imem_pipe_cleanup(ipc_imem, &channel->dl_pipe); in ipc_imem_sys_devlink_close()
462 ipc_imem->nr_of_channels--; in ipc_imem_sys_devlink_close()
468 skb_queue_tail(&ipc_devlink->devlink_sio.rx_list, skb); in ipc_imem_sys_devlink_notify_rx()
469 complete(&ipc_devlink->devlink_sio.read_sem); in ipc_imem_sys_devlink_notify_rx()
474 struct ipc_mem_channel *channel, in ipc_imem_sys_psi_transfer() argument
483 ret = ipc_pcie_addr_map(ipc_imem->pcie, buf, count, &mapping, in ipc_imem_sys_psi_transfer()
491 ipc_mmio_set_psi_addr_and_size(ipc_imem->mmio, mapping, count); in ipc_imem_sys_psi_transfer()
492 ipc_doorbell_fire(ipc_imem->pcie, 0, IPC_MEM_EXEC_STAGE_BOOT); in ipc_imem_sys_psi_transfer()
495 (&channel->ul_sem, in ipc_imem_sys_psi_transfer()
499 dev_err(ipc_imem->dev, "Failed PSI transfer to CP, Error-%d", in ipc_imem_sys_psi_transfer()
504 if (ipc_imem->rom_exit_code != IMEM_ROM_EXIT_OPEN_EXT && in ipc_imem_sys_psi_transfer()
505 ipc_imem->rom_exit_code != IMEM_ROM_EXIT_CERT_EXT) { in ipc_imem_sys_psi_transfer()
506 ret = (-1) * ((int)ipc_imem->rom_exit_code); in ipc_imem_sys_psi_transfer()
510 dev_dbg(ipc_imem->dev, "PSI image successfully downloaded"); in ipc_imem_sys_psi_transfer()
517 exec_stage = ipc_mmio_get_exec_stage(ipc_imem->mmio); in ipc_imem_sys_psi_transfer()
523 psi_start_timeout -= 20; in ipc_imem_sys_psi_transfer()
529 ipc_imem->phase = IPC_P_PSI; in ipc_imem_sys_psi_transfer()
532 dev_dbg(ipc_imem->dev, "execution_stage[%X] eq. PSI", exec_stage); in ipc_imem_sys_psi_transfer()
540 (&channel->ul_sem, msecs_to_jiffies(IPC_PSI_TRANSFER_TIMEOUT)); in ipc_imem_sys_psi_transfer()
542 dev_err(ipc_imem->dev, in ipc_imem_sys_psi_transfer()
543 "Failed PSI RUNNING state on CP, Error-%d", ret); in ipc_imem_sys_psi_transfer()
547 if (ipc_mmio_get_ipc_state(ipc_imem->mmio) != in ipc_imem_sys_psi_transfer()
549 dev_err(ipc_imem->dev, in ipc_imem_sys_psi_transfer()
551 channel->channel_id, in ipc_imem_sys_psi_transfer()
552 ipc_imem_phase_get_string(ipc_imem->phase), in ipc_imem_sys_psi_transfer()
553 ipc_mmio_get_ipc_state(ipc_imem->mmio)); in ipc_imem_sys_psi_transfer()
558 /* Create the flash channel for the transfer of the images. */ in ipc_imem_sys_psi_transfer()
560 dev_err(ipc_imem->dev, "can't open flash_channel"); in ipc_imem_sys_psi_transfer()
566 ipc_pcie_addr_unmap(ipc_imem->pcie, count, mapping, DMA_TO_DEVICE); in ipc_imem_sys_psi_transfer()
574 struct iosm_imem *ipc_imem = ipc_devlink->pcie->imem; in ipc_imem_sys_devlink_write()
575 struct ipc_mem_channel *channel; in ipc_imem_sys_devlink_write() local
580 channel = ipc_imem->ipc_devlink->devlink_sio.channel; in ipc_imem_sys_devlink_write()
585 if (ipc_imem->phase == IPC_P_ROM) { in ipc_imem_sys_devlink_write()
586 ret = ipc_imem_sys_psi_transfer(ipc_imem, channel, buf, count); in ipc_imem_sys_devlink_write()
598 skb = ipc_pcie_alloc_skb(ipc_devlink->pcie, count, GFP_KERNEL, &mapping, in ipc_imem_sys_devlink_write()
601 ret = -ENOMEM; in ipc_imem_sys_devlink_write()
607 IPC_CB(skb)->op_type = UL_USR_OP_BLOCKED; in ipc_imem_sys_devlink_write()
610 skb_queue_tail(&channel->ul_list, skb); in ipc_imem_sys_devlink_write()
614 ret = wait_for_completion_interruptible(&channel->ul_sem); in ipc_imem_sys_devlink_write()
617 dev_err(ipc_imem->dev, in ipc_imem_sys_devlink_write()
619 channel->channel_id, ret); in ipc_imem_sys_devlink_write()
620 ipc_pcie_kfree_skb(ipc_devlink->pcie, skb); in ipc_imem_sys_devlink_write()
636 devlink->devlink_sio.devlink_read_pend = 1; in ipc_imem_sys_devlink_read()
637 while (!skb && !(skb = skb_dequeue(&devlink->devlink_sio.rx_list))) { in ipc_imem_sys_devlink_read()
639 (&devlink->devlink_sio.read_sem, in ipc_imem_sys_devlink_read()
641 dev_err(devlink->dev, "Read timedout"); in ipc_imem_sys_devlink_read()
642 rc = -ETIMEDOUT; in ipc_imem_sys_devlink_read()
646 devlink->devlink_sio.devlink_read_pend = 0; in ipc_imem_sys_devlink_read()
647 if (bytes_to_read < skb->len) { in ipc_imem_sys_devlink_read()
648 dev_err(devlink->dev, "Invalid size,expected len %d", skb->len); in ipc_imem_sys_devlink_read()
649 rc = -EINVAL; in ipc_imem_sys_devlink_read()
652 *bytes_read = skb->len; in ipc_imem_sys_devlink_read()
653 memcpy(data, skb->data, skb->len); in ipc_imem_sys_devlink_read()