Lines Matching full:channel

53  * of data to or from the IPA.  A channel is implemented as a ring buffer,
60 * one or more TREs to a channel, the writer (either the IPA or an EE) writes
64 * Each channel has a GSI "event ring" associated with it. An event ring
65 * is implemented very much like a channel ring, but is always directed from
66 * the IPA to an EE. The IPA notifies an EE (such as the AP) about channel
67 * events by adding an entry to the event ring associated with the channel.
70 * to the channel TRE whose completion the event represents.
72 * Each TRE in a channel ring has a set of flags. One flag indicates whether
74 * an interrupt) in the channel's event ring. Other flags allow transfer
77 * to signal completion of channel transfers.
79 * Elements in channel and event rings are completed (or consumed) strictly
117 * on a channel (in bytes). This determines the amount of prefetch
119 * the TLV FIFO for the channel.
122 * should update the channel doorbell. We configure this to equal
133 /** gsi_channel_scratch - channel scratch configuration area
154 /* Code assumes the size of channel and event ring element are in gsi_validate_build()
166 /* The channel element size must fit in this field */ in gsi_validate_build()
173 /* Return the channel id associated with a given channel */
174 static u32 gsi_channel_id(struct gsi_channel *channel) in gsi_channel_id() argument
176 return channel - &channel->gsi->channel[0]; in gsi_channel_id()
179 /* An initialized channel has a non-null GSI pointer */
180 static bool gsi_channel_initialized(struct gsi_channel *channel) in gsi_channel_initialized() argument
182 return !!channel->gsi; in gsi_channel_initialized()
228 /* Channel commands are performed one at a time. Their completion is
229 * signaled by the channel control GSI interrupt type, which is only
230 * enabled when we issue a channel command. Only the channel being
247 /* Disable channel control interrupts */
263 /* Enable the interrupt type if this is the first channel enabled */ in gsi_irq_ieob_enable_one()
274 /* Disable the interrupt type if this was the last enabled channel */ in gsi_irq_ieob_disable()
464 /* Fetch the current state of a channel from hardware */
465 static enum gsi_channel_state gsi_channel_state(struct gsi_channel *channel) in gsi_channel_state() argument
467 u32 channel_id = gsi_channel_id(channel); in gsi_channel_state()
468 void __iomem *virt = channel->gsi->virt; in gsi_channel_state()
476 /* Issue a channel command and wait for it to complete */
478 gsi_channel_command(struct gsi_channel *channel, enum gsi_ch_cmd_opcode opcode) in gsi_channel_command() argument
480 u32 channel_id = gsi_channel_id(channel); in gsi_channel_command()
481 struct gsi *gsi = channel->gsi; in gsi_channel_command()
498 dev_err(dev, "GSI command %u for channel %u timed out, state %u\n", in gsi_channel_command()
499 opcode, channel_id, gsi_channel_state(channel)); in gsi_channel_command()
502 /* Allocate GSI channel in NOT_ALLOCATED state */
505 struct gsi_channel *channel = &gsi->channel[channel_id]; in gsi_channel_alloc_command() local
509 /* Get initial channel state */ in gsi_channel_alloc_command()
510 state = gsi_channel_state(channel); in gsi_channel_alloc_command()
512 dev_err(dev, "channel %u bad state %u before alloc\n", in gsi_channel_alloc_command()
517 gsi_channel_command(channel, GSI_CH_ALLOCATE); in gsi_channel_alloc_command()
519 /* If successful the channel state will have changed */ in gsi_channel_alloc_command()
520 state = gsi_channel_state(channel); in gsi_channel_alloc_command()
524 dev_err(dev, "channel %u bad state %u after alloc\n", in gsi_channel_alloc_command()
530 /* Start an ALLOCATED channel */
531 static int gsi_channel_start_command(struct gsi_channel *channel) in gsi_channel_start_command() argument
533 struct device *dev = channel->gsi->dev; in gsi_channel_start_command()
536 state = gsi_channel_state(channel); in gsi_channel_start_command()
539 dev_err(dev, "channel %u bad state %u before start\n", in gsi_channel_start_command()
540 gsi_channel_id(channel), state); in gsi_channel_start_command()
544 gsi_channel_command(channel, GSI_CH_START); in gsi_channel_start_command()
546 /* If successful the channel state will have changed */ in gsi_channel_start_command()
547 state = gsi_channel_state(channel); in gsi_channel_start_command()
551 dev_err(dev, "channel %u bad state %u after start\n", in gsi_channel_start_command()
552 gsi_channel_id(channel), state); in gsi_channel_start_command()
557 /* Stop a GSI channel in STARTED state */
558 static int gsi_channel_stop_command(struct gsi_channel *channel) in gsi_channel_stop_command() argument
560 struct device *dev = channel->gsi->dev; in gsi_channel_stop_command()
563 state = gsi_channel_state(channel); in gsi_channel_stop_command()
565 /* Channel could have entered STOPPED state since last call in gsi_channel_stop_command()
573 dev_err(dev, "channel %u bad state %u before stop\n", in gsi_channel_stop_command()
574 gsi_channel_id(channel), state); in gsi_channel_stop_command()
578 gsi_channel_command(channel, GSI_CH_STOP); in gsi_channel_stop_command()
580 /* If successful the channel state will have changed */ in gsi_channel_stop_command()
581 state = gsi_channel_state(channel); in gsi_channel_stop_command()
589 dev_err(dev, "channel %u bad state %u after stop\n", in gsi_channel_stop_command()
590 gsi_channel_id(channel), state); in gsi_channel_stop_command()
595 /* Reset a GSI channel in ALLOCATED or ERROR state. */
596 static void gsi_channel_reset_command(struct gsi_channel *channel) in gsi_channel_reset_command() argument
598 struct device *dev = channel->gsi->dev; in gsi_channel_reset_command()
604 state = gsi_channel_state(channel); in gsi_channel_reset_command()
607 /* No need to reset a channel already in ALLOCATED state */ in gsi_channel_reset_command()
609 dev_err(dev, "channel %u bad state %u before reset\n", in gsi_channel_reset_command()
610 gsi_channel_id(channel), state); in gsi_channel_reset_command()
614 gsi_channel_command(channel, GSI_CH_RESET); in gsi_channel_reset_command()
616 /* If successful the channel state will have changed */ in gsi_channel_reset_command()
617 state = gsi_channel_state(channel); in gsi_channel_reset_command()
619 dev_err(dev, "channel %u bad state %u after reset\n", in gsi_channel_reset_command()
620 gsi_channel_id(channel), state); in gsi_channel_reset_command()
623 /* Deallocate an ALLOCATED GSI channel */
626 struct gsi_channel *channel = &gsi->channel[channel_id]; in gsi_channel_de_alloc_command() local
630 state = gsi_channel_state(channel); in gsi_channel_de_alloc_command()
632 dev_err(dev, "channel %u bad state %u before dealloc\n", in gsi_channel_de_alloc_command()
637 gsi_channel_command(channel, GSI_CH_DE_ALLOC); in gsi_channel_de_alloc_command()
639 /* If successful the channel state will have changed */ in gsi_channel_de_alloc_command()
640 state = gsi_channel_state(channel); in gsi_channel_de_alloc_command()
643 dev_err(dev, "channel %u bad state %u after dealloc\n", in gsi_channel_de_alloc_command()
693 val |= u32_encode_bits(1, MODC_FMASK); /* comes from channel */ in gsi_evt_ring_program()
709 /* Find the transaction whose completion indicates a channel is quiesced */
710 static struct gsi_trans *gsi_channel_trans_last(struct gsi_channel *channel) in gsi_channel_trans_last() argument
712 struct gsi_trans_info *trans_info = &channel->trans_info; in gsi_channel_trans_last()
717 if (channel->toward_ipa && pending_id != trans_info->free_id) { in gsi_channel_trans_last()
737 trans = &trans_info->trans[trans_id % channel->tre_count]; in gsi_channel_trans_last()
743 /* Wait for transaction activity on a channel to complete */
744 static void gsi_channel_trans_quiesce(struct gsi_channel *channel) in gsi_channel_trans_quiesce() argument
749 trans = gsi_channel_trans_last(channel); in gsi_channel_trans_quiesce()
756 /* Program a channel for use; there is no gsi_channel_deprogram() */
757 static void gsi_channel_program(struct gsi_channel *channel, bool doorbell) in gsi_channel_program() argument
759 size_t size = channel->tre_ring.count * GSI_RING_ELEMENT_SIZE; in gsi_channel_program()
760 u32 channel_id = gsi_channel_id(channel); in gsi_channel_program()
763 struct gsi *gsi = channel->gsi; in gsi_channel_program()
769 if (channel->toward_ipa) in gsi_channel_program()
771 val |= u32_encode_bits(channel->evt_ring_id, ERINDEX_FMASK); in gsi_channel_program()
779 * high-order 32 bits of the address of the channel ring, in gsi_channel_program()
782 val = lower_32_bits(channel->tre_ring.addr); in gsi_channel_program()
784 val = upper_32_bits(channel->tre_ring.addr); in gsi_channel_program()
787 /* Command channel gets low weighted round-robin priority */ in gsi_channel_program()
788 if (channel->command) in gsi_channel_program()
799 * on all but the AP command channel. in gsi_channel_program()
801 if (gsi->version >= IPA_VERSION_4_0 && !channel->command) { in gsi_channel_program()
817 gpi->max_outstanding_tre = channel->trans_tre_max * in gsi_channel_program()
841 static int __gsi_channel_start(struct gsi_channel *channel, bool resume) in __gsi_channel_start() argument
843 struct gsi *gsi = channel->gsi; in __gsi_channel_start()
852 ret = gsi_channel_start_command(channel); in __gsi_channel_start()
859 /* Start an allocated GSI channel */
862 struct gsi_channel *channel = &gsi->channel[channel_id]; in gsi_channel_start() local
866 napi_enable(&channel->napi); in gsi_channel_start()
867 gsi_irq_ieob_enable_one(gsi, channel->evt_ring_id); in gsi_channel_start()
869 ret = __gsi_channel_start(channel, false); in gsi_channel_start()
871 gsi_irq_ieob_disable_one(gsi, channel->evt_ring_id); in gsi_channel_start()
872 napi_disable(&channel->napi); in gsi_channel_start()
878 static int gsi_channel_stop_retry(struct gsi_channel *channel) in gsi_channel_stop_retry() argument
884 ret = gsi_channel_stop_command(channel); in gsi_channel_stop_retry()
893 static int __gsi_channel_stop(struct gsi_channel *channel, bool suspend) in __gsi_channel_stop() argument
895 struct gsi *gsi = channel->gsi; in __gsi_channel_stop()
899 gsi_channel_trans_quiesce(channel); in __gsi_channel_stop()
907 ret = gsi_channel_stop_retry(channel); in __gsi_channel_stop()
914 /* Stop a started channel */
917 struct gsi_channel *channel = &gsi->channel[channel_id]; in gsi_channel_stop() local
920 ret = __gsi_channel_stop(channel, false); in gsi_channel_stop()
925 gsi_irq_ieob_disable_one(gsi, channel->evt_ring_id); in gsi_channel_stop()
926 napi_disable(&channel->napi); in gsi_channel_stop()
931 /* Reset and reconfigure a channel, (possibly) enabling the doorbell engine */
934 struct gsi_channel *channel = &gsi->channel[channel_id]; in gsi_channel_reset() local
938 gsi_channel_reset_command(channel); in gsi_channel_reset()
940 if (gsi->version < IPA_VERSION_4_0 && !channel->toward_ipa) in gsi_channel_reset()
941 gsi_channel_reset_command(channel); in gsi_channel_reset()
944 channel->tre_ring.index = 0; in gsi_channel_reset()
945 gsi_channel_program(channel, doorbell); in gsi_channel_reset()
946 gsi_channel_trans_cancel_pending(channel); in gsi_channel_reset()
951 /* Stop a started channel for suspend */
954 struct gsi_channel *channel = &gsi->channel[channel_id]; in gsi_channel_suspend() local
957 ret = __gsi_channel_stop(channel, true); in gsi_channel_suspend()
962 napi_synchronize(&channel->napi); in gsi_channel_suspend()
967 /* Resume a suspended channel (starting if stopped) */
970 struct gsi_channel *channel = &gsi->channel[channel_id]; in gsi_channel_resume() local
972 return __gsi_channel_start(channel, true); in gsi_channel_resume()
989 struct gsi_channel *channel = &trans->gsi->channel[trans->channel_id]; in gsi_trans_tx_committed() local
991 channel->trans_count++; in gsi_trans_tx_committed()
992 channel->byte_count += trans->len; in gsi_trans_tx_committed()
994 trans->trans_count = channel->trans_count; in gsi_trans_tx_committed()
995 trans->byte_count = channel->byte_count; in gsi_trans_tx_committed()
1002 struct gsi_channel *channel; in gsi_trans_tx_queued() local
1006 channel = &gsi->channel[channel_id]; in gsi_trans_tx_queued()
1008 byte_count = channel->byte_count - channel->queued_byte_count; in gsi_trans_tx_queued()
1009 trans_count = channel->trans_count - channel->queued_trans_count; in gsi_trans_tx_queued()
1010 channel->queued_byte_count = channel->byte_count; in gsi_trans_tx_queued()
1011 channel->queued_trans_count = channel->trans_count; in gsi_trans_tx_queued()
1018 * @trans: TX channel transaction that has completed
1020 * Report that a transaction on a TX channel has completed. At the time a
1021 * transaction is committed, we record *in the transaction* its channel's
1023 * order, and the difference between the channel's byte/transaction count
1035 struct gsi_channel *channel; in gsi_trans_tx_completed() local
1039 channel = &gsi->channel[channel_id]; in gsi_trans_tx_completed()
1040 trans_count = trans->trans_count - channel->compl_trans_count; in gsi_trans_tx_completed()
1041 byte_count = trans->byte_count - channel->compl_byte_count; in gsi_trans_tx_completed()
1043 channel->compl_trans_count += trans_count; in gsi_trans_tx_completed()
1044 channel->compl_byte_count += byte_count; in gsi_trans_tx_completed()
1049 /* Channel control interrupt handler */
1083 /* Global channel error interrupt handler */
1088 dev_err(gsi->dev, "channel %u out of resources\n", channel_id); in gsi_isr_glob_chan_err()
1094 dev_err(gsi->dev, "channel %u global error ee 0x%08x code 0x%08x\n", in gsi_isr_glob_chan_err()
1104 u32 channel_id = gsi_channel_id(evt_ring->channel); in gsi_isr_glob_evt_err()
1107 dev_err(gsi->dev, "evt_ring for channel %u out of resources\n", in gsi_isr_glob_evt_err()
1154 * way of knowing whether a modem channel's state has been changed. in gsi_isr_gp_int1()
1156 * We also use GENERIC commands to enable/disable channel flow in gsi_isr_gp_int1()
1160 * when shutting down, but it's possible the channel isn't running in gsi_isr_gp_int1()
1162 * that case, but it's harmless (the channel is already halted). in gsi_isr_gp_int1()
1164 * on a channel because it's not in the proper state. in gsi_isr_gp_int1()
1228 napi_schedule(&gsi->evt_ring[evt_ring_id].channel->napi); in gsi_isr_ieob()
1318 struct gsi_channel *channel; in gsi_event_trans() local
1323 channel = &gsi->channel[channel_id]; in gsi_event_trans()
1324 if (WARN(!channel->gsi, "event has bad channel %u\n", channel_id)) in gsi_event_trans()
1329 tre_index = gsi_ring_index(&channel->tre_ring, tre_offset); in gsi_event_trans()
1331 trans = gsi_channel_trans_mapped(channel, tre_index); in gsi_event_trans()
1333 if (WARN(!trans, "channel %u event with no transaction\n", channel_id)) in gsi_event_trans()
1349 * When an event for a TX channel arrives we use information in the
1373 * transaction (and which channel) is associated with the event. in gsi_evt_ring_update()
1464 /* Ring a channel doorbell, reporting the first un-filled entry */
1465 void gsi_channel_doorbell(struct gsi_channel *channel) in gsi_channel_doorbell() argument
1467 struct gsi_ring *tre_ring = &channel->tre_ring; in gsi_channel_doorbell()
1468 u32 channel_id = gsi_channel_id(channel); in gsi_channel_doorbell()
1469 struct gsi *gsi = channel->gsi; in gsi_channel_doorbell()
1478 void gsi_channel_update(struct gsi_channel *channel) in gsi_channel_update() argument
1480 u32 evt_ring_id = channel->evt_ring_id; in gsi_channel_update()
1481 struct gsi *gsi = channel->gsi; in gsi_channel_update()
1513 * gsi_channel_poll_one() - Return a single completed transaction on a channel
1514 * @channel: Channel to be polled
1518 * This function returns the first of a channel's completed transactions.
1524 static struct gsi_trans *gsi_channel_poll_one(struct gsi_channel *channel) in gsi_channel_poll_one() argument
1529 trans = gsi_channel_trans_complete(channel); in gsi_channel_poll_one()
1537 * gsi_channel_poll() - NAPI poll function for a channel
1538 * @napi: NAPI structure for the channel
1550 struct gsi_channel *channel; in gsi_channel_poll() local
1553 channel = container_of(napi, struct gsi_channel, napi); in gsi_channel_poll()
1557 trans = gsi_channel_poll_one(channel); in gsi_channel_poll()
1564 gsi_irq_ieob_enable_one(channel->gsi, channel->evt_ring_id); in gsi_channel_poll()
1583 /* Setup function for a single channel */
1586 struct gsi_channel *channel = &gsi->channel[channel_id]; in gsi_channel_setup_one() local
1587 u32 evt_ring_id = channel->evt_ring_id; in gsi_channel_setup_one()
1590 if (!gsi_channel_initialized(channel)) in gsi_channel_setup_one()
1603 gsi_channel_program(channel, true); in gsi_channel_setup_one()
1605 if (channel->toward_ipa) in gsi_channel_setup_one()
1606 netif_napi_add_tx(&gsi->dummy_dev, &channel->napi, in gsi_channel_setup_one()
1609 netif_napi_add(&gsi->dummy_dev, &channel->napi, in gsi_channel_setup_one()
1624 struct gsi_channel *channel = &gsi->channel[channel_id]; in gsi_channel_teardown_one() local
1625 u32 evt_ring_id = channel->evt_ring_id; in gsi_channel_teardown_one()
1627 if (!gsi_channel_initialized(channel)) in gsi_channel_teardown_one()
1630 netif_napi_del(&channel->napi); in gsi_channel_teardown_one()
1638 * the ability to determine channel state for a modem channel, so we simply
1654 * channel), and only from this function. So we enable the GP_INT1 in gsi_generic_command()
1679 dev_err(gsi->dev, "GSI generic command %u to channel %u timed out\n", in gsi_generic_command()
1702 dev_err(gsi->dev, "error %d halting modem channel %u\n", in gsi_modem_channel_halt()
1706 /* Enable or disable flow control for a modem GSI TX channel (IPA v4.2+) */
1728 "error %d %sabling mode channel %u flow control\n", in gsi_modem_channel_flow_control()
1751 struct gsi_channel *channel = &gsi->channel[channel_id++]; in gsi_channel_setup() local
1753 if (!gsi_channel_initialized(channel)) in gsi_channel_setup()
1757 dev_err(gsi->dev, "channel %u not supported by hardware\n", in gsi_channel_setup()
1870 /* Get # supported channel and event rings; there is no gsi_ring_teardown() */
1958 /* Initialize a channel's event ring */
1959 static int gsi_channel_evt_ring_init(struct gsi_channel *channel) in gsi_channel_evt_ring_init() argument
1961 struct gsi *gsi = channel->gsi; in gsi_channel_evt_ring_init()
1968 channel->evt_ring_id = ret; in gsi_channel_evt_ring_init()
1970 evt_ring = &gsi->evt_ring[channel->evt_ring_id]; in gsi_channel_evt_ring_init()
1971 evt_ring->channel = channel; in gsi_channel_evt_ring_init()
1973 ret = gsi_ring_alloc(gsi, &evt_ring->ring, channel->event_count); in gsi_channel_evt_ring_init()
1977 dev_err(gsi->dev, "error %d allocating channel %u event ring\n", in gsi_channel_evt_ring_init()
1978 ret, gsi_channel_id(channel)); in gsi_channel_evt_ring_init()
1980 gsi_evt_ring_id_free(gsi, channel->evt_ring_id); in gsi_channel_evt_ring_init()
1986 static void gsi_channel_evt_ring_exit(struct gsi_channel *channel) in gsi_channel_evt_ring_exit() argument
1988 u32 evt_ring_id = channel->evt_ring_id; in gsi_channel_evt_ring_exit()
1989 struct gsi *gsi = channel->gsi; in gsi_channel_evt_ring_exit()
2004 /* Make sure channel ids are in the range driver supports */ in gsi_channel_data_valid()
2006 dev_err(dev, "bad channel id %u; must be less than %u\n", in gsi_channel_data_valid()
2017 dev_err(dev, "command channel %u is not TX\n", channel_id); in gsi_channel_data_valid()
2021 channel_data = &data->channel; in gsi_channel_data_valid()
2025 dev_err(dev, "channel %u bad tlv_count %u; must be 1..%u\n", in gsi_channel_data_valid()
2031 dev_err(dev, "command TRE max too big for channel %u (%u > %u)\n", in gsi_channel_data_valid()
2043 dev_err(dev, "channel %u TLV count %u exceeds TRE count %u\n", in gsi_channel_data_valid()
2050 dev_err(dev, "channel %u bad tre_count %u; not power of 2\n", in gsi_channel_data_valid()
2056 dev_err(dev, "channel %u bad event_count %u; not power of 2\n", in gsi_channel_data_valid()
2064 /* Init function for a single channel */
2069 struct gsi_channel *channel; in gsi_channel_init_one() local
2077 if (data->channel.tre_count > data->channel.event_count) { in gsi_channel_init_one()
2078 tre_count = data->channel.event_count; in gsi_channel_init_one()
2079 dev_warn(gsi->dev, "channel %u limited to %u TREs\n", in gsi_channel_init_one()
2082 tre_count = data->channel.tre_count; in gsi_channel_init_one()
2085 channel = &gsi->channel[data->channel_id]; in gsi_channel_init_one()
2086 memset(channel, 0, sizeof(*channel)); in gsi_channel_init_one()
2088 channel->gsi = gsi; in gsi_channel_init_one()
2089 channel->toward_ipa = data->toward_ipa; in gsi_channel_init_one()
2090 channel->command = command; in gsi_channel_init_one()
2091 channel->trans_tre_max = data->channel.tlv_count; in gsi_channel_init_one()
2092 channel->tre_count = tre_count; in gsi_channel_init_one()
2093 channel->event_count = data->channel.event_count; in gsi_channel_init_one()
2095 ret = gsi_channel_evt_ring_init(channel); in gsi_channel_init_one()
2099 ret = gsi_ring_alloc(gsi, &channel->tre_ring, data->channel.tre_count); in gsi_channel_init_one()
2101 dev_err(gsi->dev, "error %d allocating channel %u ring\n", in gsi_channel_init_one()
2113 ret = ipa_cmd_pool_init(channel, tre_max); in gsi_channel_init_one()
2118 gsi_channel_trans_exit(channel); in gsi_channel_init_one()
2120 gsi_ring_free(gsi, &channel->tre_ring); in gsi_channel_init_one()
2122 gsi_channel_evt_ring_exit(channel); in gsi_channel_init_one()
2124 channel->gsi = NULL; /* Mark it not (fully) initialized */ in gsi_channel_init_one()
2130 static void gsi_channel_exit_one(struct gsi_channel *channel) in gsi_channel_exit_one() argument
2132 if (!gsi_channel_initialized(channel)) in gsi_channel_exit_one()
2135 if (channel->command) in gsi_channel_exit_one()
2136 ipa_cmd_pool_exit(channel); in gsi_channel_exit_one()
2137 gsi_channel_trans_exit(channel); in gsi_channel_exit_one()
2138 gsi_ring_free(channel->gsi, &channel->tre_ring); in gsi_channel_exit_one()
2139 gsi_channel_evt_ring_exit(channel); in gsi_channel_exit_one()
2186 gsi_channel_exit_one(&gsi->channel[data->channel_id]); in gsi_channel_init()
2198 gsi_channel_exit_one(&gsi->channel[channel_id]); in gsi_channel_exit()
2220 * for the channel NAPI contexts to be associated with. in gsi_init()
2281 /* The maximum number of outstanding TREs on a channel. This limits
2282 * a channel's maximum number of transactions outstanding (worst case
2285 * The absolute limit is the number of TREs in the channel's TRE ring,
2303 struct gsi_channel *channel = &gsi->channel[channel_id]; in gsi_channel_tre_max() local
2305 /* Hardware limit is channel->tre_count - 1 */ in gsi_channel_tre_max()
2306 return channel->tre_count - (channel->trans_tre_max - 1); in gsi_channel_tre_max()