Lines Matching defs:channel
52 * of data to or from the IPA. A channel is implemented as a ring buffer,
59 * or more TREs to a channel, the writer (either the IPA or an EE) writes a
63 * Each channel has a GSI "event ring" associated with it. An event ring
64 * is implemented very much like a channel ring, but is always directed from
65 * the IPA to an EE. The IPA notifies an EE (such as the AP) about channel
66 * events by adding an entry to the event ring associated with the channel.
69 * to the channel TRE whose completion the event represents.
71 * Each TRE in a channel ring has a set of flags. One flag indicates whether
73 * an interrupt) in the channel's event ring. Other flags allow transfer
76 * to signal completion of channel transfers.
78 * Elements in channel and event rings are completed (or consumed) strictly
137 /* Hardware values used when programming a channel */
158 /* Hardware values representing a channel immediate command opcode */
170 * on a channel (in bytes). This determines the amount of prefetch
172 * the TLV FIFO for the channel.
175 * should update the channel doorbell. We configure this to equal
186 /** gsi_channel_scratch - channel scratch configuration area
207 /* Code assumes the size of channel and event ring element are
219 /* The channel element size must fit in this field */
226 /* Return the channel id associated with a given channel */
227 static u32 gsi_channel_id(struct gsi_channel *channel)
229 return channel - &channel->gsi->channel[0];
255 /* We don't use inter-EE channel or event interrupts */
416 /* Fetch the current state of a channel from hardware */
417 static enum gsi_channel_state gsi_channel_state(struct gsi_channel *channel)
419 u32 channel_id = gsi_channel_id(channel);
420 void *virt = channel->gsi->virt;
428 /* Issue a channel command and wait for it to complete */
430 gsi_channel_command(struct gsi_channel *channel, enum gsi_ch_cmd_opcode opcode)
432 struct completion *completion = &channel->completion;
433 u32 channel_id = gsi_channel_id(channel);
434 struct gsi *gsi = channel->gsi;
444 dev_err(dev, "GSI command %u for channel %u timed out, state %u\n",
445 opcode, channel_id, gsi_channel_state(channel));
450 /* Allocate GSI channel in NOT_ALLOCATED state */
453 struct gsi_channel *channel = &gsi->channel[channel_id];
458 /* Get initial channel state */
459 state = gsi_channel_state(channel);
461 dev_err(dev, "bad channel state %u before alloc\n", state);
465 ret = gsi_channel_command(channel, GSI_CH_ALLOCATE);
468 state = gsi_channel_state(channel);
470 dev_err(dev, "bad channel state %u after alloc\n", state);
477 /* Start an ALLOCATED channel */
478 static int gsi_channel_start_command(struct gsi_channel *channel)
480 struct device *dev = channel->gsi->dev;
484 state = gsi_channel_state(channel);
487 dev_err(dev, "bad channel state %u before start\n", state);
491 ret = gsi_channel_command(channel, GSI_CH_START);
494 state = gsi_channel_state(channel);
496 dev_err(dev, "bad channel state %u after start\n", state);
503 /* Stop a GSI channel in STARTED state */
504 static int gsi_channel_stop_command(struct gsi_channel *channel)
506 struct device *dev = channel->gsi->dev;
510 state = gsi_channel_state(channel);
520 dev_err(dev, "bad channel state %u before stop\n", state);
524 ret = gsi_channel_command(channel, GSI_CH_STOP);
527 state = gsi_channel_state(channel);
535 dev_err(dev, "bad channel state %u after stop\n", state);
540 /* Reset a GSI channel in ALLOCATED or ERROR state. */
541 static void gsi_channel_reset_command(struct gsi_channel *channel)
543 struct device *dev = channel->gsi->dev;
549 state = gsi_channel_state(channel);
552 dev_err(dev, "bad channel state %u before reset\n", state);
556 ret = gsi_channel_command(channel, GSI_CH_RESET);
559 state = gsi_channel_state(channel);
561 dev_err(dev, "bad channel state %u after reset\n", state);
564 /* Deallocate an ALLOCATED GSI channel */
567 struct gsi_channel *channel = &gsi->channel[channel_id];
572 state = gsi_channel_state(channel);
574 dev_err(dev, "bad channel state %u before dealloc\n", state);
578 ret = gsi_channel_command(channel, GSI_CH_DE_ALLOC);
581 state = gsi_channel_state(channel);
583 dev_err(dev, "bad channel state %u after dealloc\n", state);
630 val |= u32_encode_bits(1, MODC_FMASK); /* comes from channel */
646 /* Return the last (most recent) transaction completed on a channel. */
647 static struct gsi_trans *gsi_channel_trans_last(struct gsi_channel *channel)
649 struct gsi_trans_info *trans_info = &channel->trans_info;
672 /* Wait for transaction activity on a channel to complete */
673 static void gsi_channel_trans_quiesce(struct gsi_channel *channel)
678 trans = gsi_channel_trans_last(channel);
685 /* Stop channel activity. Transactions may not be allocated until thawed. */
686 static void gsi_channel_freeze(struct gsi_channel *channel)
688 gsi_channel_trans_quiesce(channel);
690 napi_disable(&channel->napi);
692 gsi_irq_ieob_disable(channel->gsi, channel->evt_ring_id);
695 /* Allow transactions to be used on the channel again. */
696 static void gsi_channel_thaw(struct gsi_channel *channel)
698 gsi_irq_ieob_enable(channel->gsi, channel->evt_ring_id);
700 napi_enable(&channel->napi);
703 /* Program a channel for use */
704 static void gsi_channel_program(struct gsi_channel *channel, bool doorbell)
706 size_t size = channel->tre_ring.count * GSI_RING_ELEMENT_SIZE;
707 u32 channel_id = gsi_channel_id(channel);
710 struct gsi *gsi = channel->gsi;
714 /* Arbitrarily pick TRE 0 as the first channel element to use */
715 channel->tre_ring.index = 0;
719 if (channel->toward_ipa)
721 val |= u32_encode_bits(channel->evt_ring_id, ERINDEX_FMASK);
729 * high-order 32 bits of the address of the channel ring,
732 val = channel->tre_ring.addr & GENMASK(31, 0);
735 val = channel->tre_ring.addr >> 32;
738 /* Command channel gets low weighted round-robin priority */
739 if (channel->command)
749 if (!channel->use_prefetch)
780 static void gsi_channel_deprogram(struct gsi_channel *channel)
785 /* Start an allocated GSI channel */
788 struct gsi_channel *channel = &gsi->channel[channel_id];
793 ret = gsi_channel_start_command(channel);
797 gsi_channel_thaw(channel);
802 /* Stop a started channel */
805 struct gsi_channel *channel = &gsi->channel[channel_id];
809 gsi_channel_freeze(channel);
812 retries = channel->toward_ipa ? 0 : GSI_CHANNEL_STOP_RX_RETRIES;
817 ret = gsi_channel_stop_command(channel);
825 /* Thaw the channel if we need to retry (or on error) */
827 gsi_channel_thaw(channel);
832 /* Reset and reconfigure a channel (possibly leaving doorbell disabled) */
835 struct gsi_channel *channel = &gsi->channel[channel_id];
839 gsi_channel_reset_command(channel);
841 if (legacy && !channel->toward_ipa)
842 gsi_channel_reset_command(channel);
844 gsi_channel_program(channel, legacy);
845 gsi_channel_trans_cancel_pending(channel);
850 /* Stop a STARTED channel for suspend (using stop if requested) */
853 struct gsi_channel *channel = &gsi->channel[channel_id];
858 gsi_channel_freeze(channel);
863 /* Resume a suspended channel (starting will be requested if STOPPED) */
866 struct gsi_channel *channel = &gsi->channel[channel_id];
871 gsi_channel_thaw(channel);
877 * gsi_channel_tx_queued() - Report queued TX transfers for a channel
878 * @channel: Channel for which to report
884 * For each channel we track the number of transactions used and bytes of
890 * Calling this each time we ring the channel doorbell allows us to
894 void gsi_channel_tx_queued(struct gsi_channel *channel)
899 byte_count = channel->byte_count - channel->queued_byte_count;
900 trans_count = channel->trans_count - channel->queued_trans_count;
901 channel->queued_byte_count = channel->byte_count;
902 channel->queued_trans_count = channel->trans_count;
904 ipa_gsi_channel_tx_queued(channel->gsi, gsi_channel_id(channel),
910 * @channel: Channel that has completed transmitting packets
914 * over a TX channel since the given transaction was committed. Report this
917 * At the time a transaction is committed, we record its channel's
933 gsi_channel_tx_update(struct gsi_channel *channel, struct gsi_trans *trans)
938 byte_count -= channel->compl_byte_count;
939 channel->compl_byte_count += byte_count;
940 trans_count -= channel->compl_trans_count;
941 channel->compl_trans_count += trans_count;
943 ipa_gsi_channel_tx_completed(channel->gsi, gsi_channel_id(channel),
957 struct gsi_channel *channel;
961 channel = &gsi->channel[channel_id];
963 complete(&channel->completion);
988 /* Global channel error interrupt handler */
993 dev_err(gsi->dev, "channel %u out of resources\n", channel_id);
994 complete(&gsi->channel[channel_id].completion);
999 dev_err(gsi->dev, "channel %u global error ee 0x%08x code 0x%08x\n",
1009 u32 channel_id = gsi_channel_id(evt_ring->channel);
1012 dev_err(gsi->dev, "evt_ring for channel %u out of resources\n",
1100 napi_schedule(&gsi->evt_ring[evt_ring_id].channel->napi);
1172 static struct gsi_trans *gsi_event_trans(struct gsi_channel *channel,
1180 tre_index = gsi_ring_index(&channel->tre_ring, tre_offset);
1182 return gsi_channel_trans_mapped(channel, tre_index);
1187 * @evt_ring: Event ring associated with channel that received packets
1206 struct gsi_channel *channel = evt_ring->channel;
1217 trans_info = &channel->trans_info;
1226 trans = gsi_event_trans(channel, event);
1247 channel->byte_count += byte_count;
1248 channel->trans_count += trans_count;
1302 /* Ring a channel doorbell, reporting the first un-filled entry */
1303 void gsi_channel_doorbell(struct gsi_channel *channel)
1305 struct gsi_ring *tre_ring = &channel->tre_ring;
1306 u32 channel_id = gsi_channel_id(channel);
1307 struct gsi *gsi = channel->gsi;
1316 static void gsi_channel_update(struct gsi_channel *channel)
1318 u32 evt_ring_id = channel->evt_ring_id;
1319 struct gsi *gsi = channel->gsi;
1341 trans = gsi_event_trans(channel, gsi_ring_virt(ring, index - 1));
1349 if (channel->toward_ipa)
1350 gsi_channel_tx_update(channel, trans);
1357 gsi_evt_ring_doorbell(channel->gsi, channel->evt_ring_id, index);
1363 * gsi_channel_poll_one() - Return a single completed transaction on a channel
1364 * @channel: Channel to be polled
1368 * This function returns the first entry on a channel's completed transaction
1374 static struct gsi_trans *gsi_channel_poll_one(struct gsi_channel *channel)
1379 trans = gsi_channel_trans_complete(channel);
1382 gsi_channel_update(channel);
1383 trans = gsi_channel_trans_complete(channel);
1393 * gsi_channel_poll() - NAPI poll function for a channel
1394 * @napi: NAPI structure for the channel
1406 struct gsi_channel *channel;
1409 channel = container_of(napi, struct gsi_channel, napi);
1414 trans = gsi_channel_poll_one(channel);
1421 napi_complete(&channel->napi);
1422 gsi_irq_ieob_enable(channel->gsi, channel->evt_ring_id);
1454 /* Setup function for a single channel */
1458 struct gsi_channel *channel = &gsi->channel[channel_id];
1459 u32 evt_ring_id = channel->evt_ring_id;
1462 if (!channel->gsi)
1475 gsi_channel_program(channel, legacy);
1477 if (channel->toward_ipa)
1478 netif_tx_napi_add(&gsi->dummy_dev, &channel->napi,
1481 netif_napi_add(&gsi->dummy_dev, &channel->napi,
1496 struct gsi_channel *channel = &gsi->channel[channel_id];
1497 u32 evt_ring_id = channel->evt_ring_id;
1499 if (!channel->gsi)
1502 netif_napi_del(&channel->napi);
1504 gsi_channel_deprogram(channel);
1529 dev_err(gsi->dev, "GSI generic command %u to channel %u timed out\n",
1547 dev_err(gsi->dev, "error %d halting modem channel %u\n",
1571 struct gsi_channel *channel = &gsi->channel[channel_id++];
1573 if (!channel->gsi)
1577 dev_err(gsi->dev, "channel %u not supported by hardware\n",
1704 /* Initialize a channel's event ring */
1705 static int gsi_channel_evt_ring_init(struct gsi_channel *channel)
1707 struct gsi *gsi = channel->gsi;
1714 channel->evt_ring_id = ret;
1716 evt_ring = &gsi->evt_ring[channel->evt_ring_id];
1717 evt_ring->channel = channel;
1719 ret = gsi_ring_alloc(gsi, &evt_ring->ring, channel->event_count);
1723 dev_err(gsi->dev, "error %d allocating channel %u event ring\n",
1724 ret, gsi_channel_id(channel));
1726 gsi_evt_ring_id_free(gsi, channel->evt_ring_id);
1732 static void gsi_channel_evt_ring_exit(struct gsi_channel *channel)
1734 u32 evt_ring_id = channel->evt_ring_id;
1735 struct gsi *gsi = channel->gsi;
1768 /* Make sure channel ids are in the range driver supports */
1770 dev_err(dev, "bad channel id %u; must be less than %u\n",
1780 if (!data->channel.tlv_count ||
1781 data->channel.tlv_count > GSI_TLV_MAX) {
1782 dev_err(dev, "channel %u bad tlv_count %u; must be 1..%u\n",
1783 channel_id, data->channel.tlv_count, GSI_TLV_MAX);
1792 if (data->channel.tre_count < 2 * data->channel.tlv_count - 1) {
1793 dev_err(dev, "channel %u TLV count %u exceeds TRE count %u\n",
1794 channel_id, data->channel.tlv_count,
1795 data->channel.tre_count);
1799 if (!is_power_of_2(data->channel.tre_count)) {
1800 dev_err(dev, "channel %u bad tre_count %u; not power of 2\n",
1801 channel_id, data->channel.tre_count);
1805 if (!is_power_of_2(data->channel.event_count)) {
1806 dev_err(dev, "channel %u bad event_count %u; not power of 2\n",
1807 channel_id, data->channel.event_count);
1815 /* Init function for a single channel */
1820 struct gsi_channel *channel;
1828 if (data->channel.tre_count > data->channel.event_count) {
1829 tre_count = data->channel.event_count;
1830 dev_warn(gsi->dev, "channel %u limited to %u TREs\n",
1833 tre_count = data->channel.tre_count;
1836 channel = &gsi->channel[data->channel_id];
1837 memset(channel, 0, sizeof(*channel));
1839 channel->gsi = gsi;
1840 channel->toward_ipa = data->toward_ipa;
1841 channel->command = command;
1842 channel->use_prefetch = command && prefetch;
1843 channel->tlv_count = data->channel.tlv_count;
1844 channel->tre_count = tre_count;
1845 channel->event_count = data->channel.event_count;
1846 init_completion(&channel->completion);
1848 ret = gsi_channel_evt_ring_init(channel);
1852 ret = gsi_ring_alloc(gsi, &channel->tre_ring, data->channel.tre_count);
1854 dev_err(gsi->dev, "error %d allocating channel %u ring\n",
1866 ret = ipa_cmd_pool_init(channel, tre_max);
1871 gsi_channel_trans_exit(channel);
1873 gsi_ring_free(gsi, &channel->tre_ring);
1875 gsi_channel_evt_ring_exit(channel);
1877 channel->gsi = NULL; /* Mark it not (fully) initialized */
1883 static void gsi_channel_exit_one(struct gsi_channel *channel)
1885 if (!channel->gsi)
1888 if (channel->command)
1889 ipa_cmd_pool_exit(channel);
1890 gsi_channel_trans_exit(channel);
1891 gsi_ring_free(channel->gsi, &channel->tre_ring);
1892 gsi_channel_evt_ring_exit(channel);
1935 gsi_channel_exit_one(&gsi->channel[data->channel_id]);
1948 gsi_channel_exit_one(&gsi->channel[channel_id]);
2038 /* The maximum number of outstanding TREs on a channel. This limits
2039 * a channel's maximum number of transactions outstanding (worst case
2042 * The absolute limit is the number of TREs in the channel's TRE ring,
2060 struct gsi_channel *channel = &gsi->channel[channel_id];
2062 /* Hardware limit is channel->tre_count - 1 */
2063 return channel->tre_count - (channel->tlv_count - 1);
2066 /* Returns the maximum number of TREs in a single transaction for a channel */
2069 struct gsi_channel *channel = &gsi->channel[channel_id];
2071 return channel->tlv_count;