Lines Matching +full:ipa +full:- +full:ap +full:- +full:to +full:- +full:modem
1 // SPDX-License-Identifier: GPL-2.0
3 /* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
4 * Copyright (C) 2018-2023 Linaro Ltd.
28 * DOC: The IPA Generic Software Interface
30 * The generic software interface (GSI) is an integral component of the IPA,
31 * providing a well-defined communication layer between the AP subsystem
32 * and the IPA core. The modem uses the GSI layer as well.
34 * -------- ---------
36 * | AP +<---. .----+ Modem |
37 * | +--. | | .->+ |
39 * -------- | | | | ---------
41 * --+-+---+-+--
43 * |-----------|
45 * | IPA |
47 * -------------
49 * In the above diagram, the AP and Modem represent "execution environments"
50 * (EEs), which are independent operating environments that use the IPA for
54 * of data to or from the IPA. A channel is implemented as a ring buffer,
55 * with a DRAM-resident array of "transfer elements" (TREs) available to
56 * describe transfers to or from other EEs through the IPA. A transfer
57 * element can also contain an immediate command, requesting the IPA perform
60 * Each TRE refers to a block of data--also located in DRAM. After writing
61 * one or more TREs to a channel, the writer (either the IPA or an EE) writes
62 * a doorbell register to inform the receiving side how many elements have
67 * the IPA to an EE. The IPA notifies an EE (such as the AP) about channel
68 * events by adding an entry to the event ring associated with the channel.
70 * EE to be interrupted. Each entry in an event ring contains a pointer
71 * to the channel TRE whose completion the event represents.
76 * elements to be chained together, forming a single logical transaction.
77 * TRE flags are used to control whether and when interrupts are generated
78 * to signal completion of channel transfers.
85 * Note that all GSI registers are little-endian, which is the assumed
90 /* Delay period for interrupt moderation (in 32KHz IPA internal timer ticks) */
115 /** gsi_channel_scratch_gpi - GPI protocol scratch register
119 * performed by the hardware. We configure this to equal the size of
123 * should update the channel doorbell. We configure this to equal
134 /** gsi_channel_scratch - channel scratch configuration area
136 * The exact interpretation of this register is protocol-specific.
171 return channel - &channel->gsi->channel[0]; in gsi_channel_id()
174 /* An initialized channel has a non-null GSI pointer */
177 return !!channel->gsi; in gsi_channel_initialized()
201 gsi->type_enabled_bitmap = val; in gsi_irq_type_update()
202 iowrite32(val, gsi->virt + reg_offset(reg)); in gsi_irq_type_update()
207 gsi_irq_type_update(gsi, gsi->type_enabled_bitmap | type_id); in gsi_irq_type_enable()
212 gsi_irq_type_update(gsi, gsi->type_enabled_bitmap & ~type_id); in gsi_irq_type_disable()
230 iowrite32(~0, gsi->virt + reg_offset(reg)); in gsi_irq_ev_ctrl_enable()
233 iowrite32(val, gsi->virt + reg_offset(reg)); in gsi_irq_ev_ctrl_enable()
245 iowrite32(0, gsi->virt + reg_offset(reg)); in gsi_irq_ev_ctrl_disable()
263 iowrite32(~0, gsi->virt + reg_offset(reg)); in gsi_irq_ch_ctrl_enable()
266 iowrite32(val, gsi->virt + reg_offset(reg)); in gsi_irq_ch_ctrl_enable()
279 iowrite32(0, gsi->virt + reg_offset(reg)); in gsi_irq_ch_ctrl_disable()
284 bool enable_ieob = !gsi->ieob_enabled_bitmap; in gsi_irq_ieob_enable_one()
288 gsi->ieob_enabled_bitmap |= BIT(evt_ring_id); in gsi_irq_ieob_enable_one()
291 val = gsi->ieob_enabled_bitmap; in gsi_irq_ieob_enable_one()
292 iowrite32(val, gsi->virt + reg_offset(reg)); in gsi_irq_ieob_enable_one()
304 gsi->ieob_enabled_bitmap &= ~event_mask; in gsi_irq_ieob_disable()
307 if (!gsi->ieob_enabled_bitmap) in gsi_irq_ieob_disable()
311 val = gsi->ieob_enabled_bitmap; in gsi_irq_ieob_disable()
312 iowrite32(val, gsi->virt + reg_offset(reg)); in gsi_irq_ieob_disable()
330 iowrite32(ERROR_INT, gsi->virt + reg_offset(reg)); in gsi_irq_enable()
332 gsi_irq_type_update(gsi, gsi->type_enabled_bitmap | GSI_GLOB_EE); in gsi_irq_enable()
334 /* General GSI interrupts are reported to all EEs; if they occur in gsi_irq_enable()
336 * also exists, but we don't support that. We want to be notified in gsi_irq_enable()
343 iowrite32(val, gsi->virt + reg_offset(reg)); in gsi_irq_enable()
345 gsi_irq_type_update(gsi, gsi->type_enabled_bitmap | GSI_GENERAL); in gsi_irq_enable()
355 /* Clear the type-specific interrupt masks set by gsi_irq_enable() */ in gsi_irq_disable()
357 iowrite32(0, gsi->virt + reg_offset(reg)); in gsi_irq_disable()
360 iowrite32(0, gsi->virt + reg_offset(reg)); in gsi_irq_disable()
367 return ring->virt + (index % ring->count) * GSI_RING_ELEMENT_SIZE; in gsi_ring_virt()
370 /* Return the 32-bit DMA address associated with a ring index */
373 return lower_32_bits(ring->addr) + index * GSI_RING_ELEMENT_SIZE; in gsi_ring_addr()
376 /* Return the ring index of a 32-bit ring offset */
379 return (offset - gsi_ring_addr(ring, 0)) / GSI_RING_ELEMENT_SIZE; in gsi_ring_index()
382 /* Issue a GSI command by writing a value to a register, then wait for
383 * completion to be signaled. Returns true if the command completes
389 struct completion *completion = &gsi->completion; in gsi_command()
393 iowrite32(val, gsi->virt + reg); in gsi_command()
405 val = ioread32(gsi->virt + reg_n_offset(reg, evt_ring_id)); in gsi_evt_ring_state()
410 /* Issue an event ring command and wait for it to complete */
414 struct device *dev = gsi->dev; in gsi_evt_ring_command()
445 dev_err(gsi->dev, "event ring %u bad state %u before alloc\n", in gsi_evt_ring_alloc_command()
447 return -EINVAL; in gsi_evt_ring_alloc_command()
457 dev_err(gsi->dev, "event ring %u bad state %u after alloc\n", in gsi_evt_ring_alloc_command()
460 return -EIO; in gsi_evt_ring_alloc_command()
471 dev_err(gsi->dev, "event ring %u bad state %u before reset\n", in gsi_evt_ring_reset_command()
483 dev_err(gsi->dev, "event ring %u bad state %u after reset\n", in gsi_evt_ring_reset_command()
487 /* Issue a hardware de-allocation request for an allocated event ring */
494 dev_err(gsi->dev, "event ring %u state %u before dealloc\n", in gsi_evt_ring_de_alloc_command()
506 dev_err(gsi->dev, "event ring %u bad state %u after dealloc\n", in gsi_evt_ring_de_alloc_command()
513 const struct reg *reg = gsi_reg(channel->gsi, CH_C_CNTXT_0); in gsi_channel_state()
515 struct gsi *gsi = channel->gsi; in gsi_channel_state()
516 void __iomem *virt = gsi->virt; in gsi_channel_state()
525 /* Issue a channel command and wait for it to complete */
530 struct gsi *gsi = channel->gsi; in gsi_channel_command()
531 struct device *dev = gsi->dev; in gsi_channel_command()
557 struct gsi_channel *channel = &gsi->channel[channel_id]; in gsi_channel_alloc_command()
558 struct device *dev = gsi->dev; in gsi_channel_alloc_command()
566 return -EINVAL; in gsi_channel_alloc_command()
579 return -EIO; in gsi_channel_alloc_command()
585 struct device *dev = channel->gsi->dev; in gsi_channel_start_command()
593 return -EINVAL; in gsi_channel_start_command()
606 return -EIO; in gsi_channel_start_command()
612 struct device *dev = channel->gsi->dev; in gsi_channel_stop_command()
627 return -EINVAL; in gsi_channel_stop_command()
637 /* We may have to try again if stop is in progress */ in gsi_channel_stop_command()
639 return -EAGAIN; in gsi_channel_stop_command()
644 return -EIO; in gsi_channel_stop_command()
650 struct device *dev = channel->gsi->dev; in gsi_channel_reset_command()
659 /* No need to reset a channel already in ALLOCATED state */ in gsi_channel_reset_command()
678 struct gsi_channel *channel = &gsi->channel[channel_id]; in gsi_channel_de_alloc_command()
679 struct device *dev = gsi->dev; in gsi_channel_de_alloc_command()
699 /* Ring an event ring doorbell, reporting the last entry processed by the AP.
707 struct gsi_ring *ring = &gsi->evt_ring[evt_ring_id].ring; in gsi_evt_ring_doorbell()
710 ring->index = index; /* Next unused entry */ in gsi_evt_ring_doorbell()
713 val = gsi_ring_addr(ring, (index - 1) % ring->count); in gsi_evt_ring_doorbell()
714 iowrite32(val, gsi->virt + reg_n_offset(reg, evt_ring_id)); in gsi_evt_ring_doorbell()
720 struct gsi_evt_ring *evt_ring = &gsi->evt_ring[evt_ring_id]; in gsi_evt_ring_program()
721 struct gsi_ring *ring = &evt_ring->ring; in gsi_evt_ring_program()
731 iowrite32(val, gsi->virt + reg_n_offset(reg, evt_ring_id)); in gsi_evt_ring_program()
734 val = reg_encode(reg, R_LENGTH, ring->count * GSI_RING_ELEMENT_SIZE); in gsi_evt_ring_program()
735 iowrite32(val, gsi->virt + reg_n_offset(reg, evt_ring_id)); in gsi_evt_ring_program()
737 /* The context 2 and 3 registers store the low-order and in gsi_evt_ring_program()
738 * high-order 32 bits of the address of the event ring, in gsi_evt_ring_program()
742 val = lower_32_bits(ring->addr); in gsi_evt_ring_program()
743 iowrite32(val, gsi->virt + reg_n_offset(reg, evt_ring_id)); in gsi_evt_ring_program()
746 val = upper_32_bits(ring->addr); in gsi_evt_ring_program()
747 iowrite32(val, gsi->virt + reg_n_offset(reg, evt_ring_id)); in gsi_evt_ring_program()
753 /* EV_MOD_CNT is 0 (no counter-based interrupt coalescing) */ in gsi_evt_ring_program()
754 iowrite32(val, gsi->virt + reg_n_offset(reg, evt_ring_id)); in gsi_evt_ring_program()
758 iowrite32(0, gsi->virt + reg_n_offset(reg, evt_ring_id)); in gsi_evt_ring_program()
761 iowrite32(0, gsi->virt + reg_n_offset(reg, evt_ring_id)); in gsi_evt_ring_program()
764 iowrite32(0, gsi->virt + reg_n_offset(reg, evt_ring_id)); in gsi_evt_ring_program()
766 /* We don't need to get event read pointer updates */ in gsi_evt_ring_program()
768 iowrite32(0, gsi->virt + reg_n_offset(reg, evt_ring_id)); in gsi_evt_ring_program()
771 iowrite32(0, gsi->virt + reg_n_offset(reg, evt_ring_id)); in gsi_evt_ring_program()
774 gsi_evt_ring_doorbell(gsi, evt_ring_id, ring->index); in gsi_evt_ring_program()
780 struct gsi_trans_info *trans_info = &channel->trans_info; in gsi_channel_trans_last()
781 u32 pending_id = trans_info->pending_id; in gsi_channel_trans_last()
785 if (channel->toward_ipa && pending_id != trans_info->free_id) { in gsi_channel_trans_last()
791 trans_id = trans_info->free_id - 1; in gsi_channel_trans_last()
792 } else if (trans_info->polled_id != pending_id) { in gsi_channel_trans_last()
793 /* Otherwise (TX or RX) we want to wait for anything that in gsi_channel_trans_last()
799 trans_id = pending_id - 1; in gsi_channel_trans_last()
805 trans = &trans_info->trans[trans_id % channel->tre_count]; in gsi_channel_trans_last()
806 refcount_inc(&trans->refcount); in gsi_channel_trans_last()
811 /* Wait for transaction activity on a channel to complete */
816 /* Get the last transaction, and wait for it to complete */ in gsi_channel_trans_quiesce()
819 wait_for_completion(&trans->completion); in gsi_channel_trans_quiesce()
827 size_t size = channel->tre_ring.count * GSI_RING_ELEMENT_SIZE; in gsi_channel_program()
831 struct gsi *gsi = channel->gsi; in gsi_channel_program()
840 val = ch_c_cntxt_0_type_encode(gsi->version, reg, GSI_CHANNEL_TYPE_GPI); in gsi_channel_program()
841 if (channel->toward_ipa) in gsi_channel_program()
843 if (gsi->version < IPA_VERSION_5_0) in gsi_channel_program()
844 val |= reg_encode(reg, ERINDEX, channel->evt_ring_id); in gsi_channel_program()
846 iowrite32(val, gsi->virt + reg_n_offset(reg, channel_id)); in gsi_channel_program()
850 if (gsi->version >= IPA_VERSION_5_0) in gsi_channel_program()
851 val |= reg_encode(reg, CH_ERINDEX, channel->evt_ring_id); in gsi_channel_program()
852 iowrite32(val, gsi->virt + reg_n_offset(reg, channel_id)); in gsi_channel_program()
854 /* The context 2 and 3 registers store the low-order and in gsi_channel_program()
855 * high-order 32 bits of the address of the channel ring, in gsi_channel_program()
859 val = lower_32_bits(channel->tre_ring.addr); in gsi_channel_program()
860 iowrite32(val, gsi->virt + reg_n_offset(reg, channel_id)); in gsi_channel_program()
863 val = upper_32_bits(channel->tre_ring.addr); in gsi_channel_program()
864 iowrite32(val, gsi->virt + reg_n_offset(reg, channel_id)); in gsi_channel_program()
868 /* Command channel gets low weighted round-robin priority */ in gsi_channel_program()
869 if (channel->command) in gsi_channel_program()
875 /* No need to use the doorbell engine starting at IPA v4.0 */ in gsi_channel_program()
876 if (gsi->version < IPA_VERSION_4_0 && doorbell) in gsi_channel_program()
880 * on all but the AP command channel. in gsi_channel_program()
882 if (gsi->version >= IPA_VERSION_4_0 && !channel->command) { in gsi_channel_program()
884 if (gsi->version < IPA_VERSION_4_5) in gsi_channel_program()
890 if (gsi->version >= IPA_VERSION_4_9) in gsi_channel_program()
893 iowrite32(val, gsi->virt + reg_n_offset(reg, channel_id)); in gsi_channel_program()
897 gpi->max_outstanding_tre = channel->trans_tre_max * in gsi_channel_program()
899 gpi->outstanding_threshold = 2 * GSI_RING_ELEMENT_SIZE; in gsi_channel_program()
903 iowrite32(val, gsi->virt + reg_n_offset(reg, channel_id)); in gsi_channel_program()
907 iowrite32(val, gsi->virt + reg_n_offset(reg, channel_id)); in gsi_channel_program()
911 iowrite32(val, gsi->virt + reg_n_offset(reg, channel_id)); in gsi_channel_program()
919 val = ioread32(gsi->virt + offset); in gsi_channel_program()
921 iowrite32(val, gsi->virt + offset); in gsi_channel_program()
928 struct gsi *gsi = channel->gsi; in __gsi_channel_start()
931 /* Prior to IPA v4.0 suspend/resume is not implemented by GSI */ in __gsi_channel_start()
932 if (resume && gsi->version < IPA_VERSION_4_0) in __gsi_channel_start()
935 mutex_lock(&gsi->mutex); in __gsi_channel_start()
939 mutex_unlock(&gsi->mutex); in __gsi_channel_start()
947 struct gsi_channel *channel = &gsi->channel[channel_id]; in gsi_channel_start()
951 napi_enable(&channel->napi); in gsi_channel_start()
952 gsi_irq_ieob_enable_one(gsi, channel->evt_ring_id); in gsi_channel_start()
956 gsi_irq_ieob_disable_one(gsi, channel->evt_ring_id); in gsi_channel_start()
957 napi_disable(&channel->napi); in gsi_channel_start()
970 if (ret != -EAGAIN) in gsi_channel_stop_retry()
973 } while (retries--); in gsi_channel_stop_retry()
980 struct gsi *gsi = channel->gsi; in __gsi_channel_stop()
983 /* Wait for any underway transactions to complete before stopping. */ in __gsi_channel_stop()
986 /* Prior to IPA v4.0 suspend/resume is not implemented by GSI */ in __gsi_channel_stop()
987 if (suspend && gsi->version < IPA_VERSION_4_0) in __gsi_channel_stop()
990 mutex_lock(&gsi->mutex); in __gsi_channel_stop()
994 mutex_unlock(&gsi->mutex); in __gsi_channel_stop()
1002 struct gsi_channel *channel = &gsi->channel[channel_id]; in gsi_channel_stop()
1010 gsi_irq_ieob_disable_one(gsi, channel->evt_ring_id); in gsi_channel_stop()
1011 napi_disable(&channel->napi); in gsi_channel_stop()
1019 struct gsi_channel *channel = &gsi->channel[channel_id]; in gsi_channel_reset()
1021 mutex_lock(&gsi->mutex); in gsi_channel_reset()
1024 /* Due to a hardware quirk we may need to reset RX channels twice. */ in gsi_channel_reset()
1025 if (gsi->version < IPA_VERSION_4_0 && !channel->toward_ipa) in gsi_channel_reset()
1029 channel->tre_ring.index = 0; in gsi_channel_reset()
1033 mutex_unlock(&gsi->mutex); in gsi_channel_reset()
1039 struct gsi_channel *channel = &gsi->channel[channel_id]; in gsi_channel_suspend()
1047 napi_synchronize(&channel->napi); in gsi_channel_suspend()
1055 struct gsi_channel *channel = &gsi->channel[channel_id]; in gsi_channel_resume()
1063 disable_irq(gsi->irq); in gsi_suspend()
1069 enable_irq(gsi->irq); in gsi_resume()
1074 struct gsi_channel *channel = &trans->gsi->channel[trans->channel_id]; in gsi_trans_tx_committed()
1076 channel->trans_count++; in gsi_trans_tx_committed()
1077 channel->byte_count += trans->len; in gsi_trans_tx_committed()
1079 trans->trans_count = channel->trans_count; in gsi_trans_tx_committed()
1080 trans->byte_count = channel->byte_count; in gsi_trans_tx_committed()
1085 u32 channel_id = trans->channel_id; in gsi_trans_tx_queued()
1086 struct gsi *gsi = trans->gsi; in gsi_trans_tx_queued()
1091 channel = &gsi->channel[channel_id]; in gsi_trans_tx_queued()
1093 byte_count = channel->byte_count - channel->queued_byte_count; in gsi_trans_tx_queued()
1094 trans_count = channel->trans_count - channel->queued_trans_count; in gsi_trans_tx_queued()
1095 channel->queued_byte_count = channel->byte_count; in gsi_trans_tx_queued()
1096 channel->queued_trans_count = channel->trans_count; in gsi_trans_tx_queued()
1102 * gsi_trans_tx_completed() - Report completed TX transactions
1113 * We report this information to the network stack, which uses it to manage
1114 * the rate at which data is sent to hardware.
1118 u32 channel_id = trans->channel_id; in gsi_trans_tx_completed()
1119 struct gsi *gsi = trans->gsi; in gsi_trans_tx_completed()
1124 channel = &gsi->channel[channel_id]; in gsi_trans_tx_completed()
1125 trans_count = trans->trans_count - channel->compl_trans_count; in gsi_trans_tx_completed()
1126 byte_count = trans->byte_count - channel->compl_byte_count; in gsi_trans_tx_completed()
1128 channel->compl_trans_count += trans_count; in gsi_trans_tx_completed()
1129 channel->compl_byte_count += byte_count; in gsi_trans_tx_completed()
1141 channel_mask = ioread32(gsi->virt + reg_offset(reg)); in gsi_isr_chan_ctrl()
1144 iowrite32(channel_mask, gsi->virt + reg_offset(reg)); in gsi_isr_chan_ctrl()
1151 complete(&gsi->completion); in gsi_isr_chan_ctrl()
1162 event_mask = ioread32(gsi->virt + reg_offset(reg)); in gsi_isr_evt_ctrl()
1165 iowrite32(event_mask, gsi->virt + reg_offset(reg)); in gsi_isr_evt_ctrl()
1172 complete(&gsi->completion); in gsi_isr_evt_ctrl()
1181 dev_err(gsi->dev, "channel %u out of resources\n", channel_id); in gsi_isr_glob_chan_err()
1182 complete(&gsi->completion); in gsi_isr_glob_chan_err()
1187 dev_err(gsi->dev, "channel %u global error ee 0x%08x code 0x%08x\n", in gsi_isr_glob_chan_err()
1196 struct gsi_evt_ring *evt_ring = &gsi->evt_ring[evt_ring_id]; in gsi_isr_glob_evt_err()
1197 u32 channel_id = gsi_channel_id(evt_ring->channel); in gsi_isr_glob_evt_err()
1199 complete(&gsi->completion); in gsi_isr_glob_evt_err()
1200 dev_err(gsi->dev, "evt_ring for channel %u out of resources\n", in gsi_isr_glob_evt_err()
1206 dev_err(gsi->dev, "event ring %u global error ee %u code 0x%08x\n", in gsi_isr_glob_evt_err()
1225 val = ioread32(gsi->virt + offset); in gsi_isr_glob_err()
1226 iowrite32(0, gsi->virt + offset); in gsi_isr_glob_err()
1229 iowrite32(~0, gsi->virt + reg_offset(clr_reg)); in gsi_isr_glob_err()
1242 dev_err(gsi->dev, "unexpected global error 0x%08x\n", type); in gsi_isr_glob_err()
1252 /* This interrupt is used to handle completions of GENERIC GSI in gsi_isr_gp_int1()
1253 * commands. We use these to allocate and halt channels on the in gsi_isr_gp_int1()
1254 * modem's behalf due to a hardware quirk on IPA v4.2. The modem in gsi_isr_gp_int1()
1255 * "owns" channels even when the AP allocates them, and have no in gsi_isr_gp_int1()
1256 * way of knowing whether a modem channel's state has been changed. in gsi_isr_gp_int1()
1258 * We also use GENERIC commands to enable/disable channel flow in gsi_isr_gp_int1()
1259 * control for IPA v4.2+. in gsi_isr_gp_int1()
1261 * It is recommended that we halt the modem channels we allocated in gsi_isr_gp_int1()
1272 val = ioread32(gsi->virt + reg_offset(reg)); in gsi_isr_gp_int1()
1278 gsi->result = 0; in gsi_isr_gp_int1()
1282 gsi->result = -EAGAIN; in gsi_isr_gp_int1()
1286 dev_err(gsi->dev, "global INT1 generic result %u\n", result); in gsi_isr_gp_int1()
1287 gsi->result = -EIO; in gsi_isr_gp_int1()
1291 complete(&gsi->completion); in gsi_isr_gp_int1()
1294 /* Inter-EE interrupt handler */
1301 val = ioread32(gsi->virt + reg_offset(reg)); in gsi_isr_glob_ee()
1307 iowrite32(val, gsi->virt + reg_offset(reg)); in gsi_isr_glob_ee()
1317 dev_err(gsi->dev, "unexpected global interrupt 0x%08x\n", val); in gsi_isr_glob_ee()
1327 event_mask = ioread32(gsi->virt + reg_offset(reg)); in gsi_isr_ieob()
1332 iowrite32(event_mask, gsi->virt + reg_offset(reg)); in gsi_isr_ieob()
1339 napi_schedule(&gsi->evt_ring[evt_ring_id].channel->napi); in gsi_isr_ieob()
1346 struct device *dev = gsi->dev; in gsi_isr_general()
1351 val = ioread32(gsi->virt + reg_offset(reg)); in gsi_isr_general()
1354 iowrite32(val, gsi->virt + reg_offset(reg)); in gsi_isr_general()
1360 * gsi_isr() - Top level GSI interrupt service routine
1362 * @dev_id: GSI pointer supplied to request_irq()
1379 while ((intr_mask = ioread32(gsi->virt + offset))) { in gsi_isr()
1387 * when the type-specific register is updated. in gsi_isr()
1406 dev_err(gsi->dev, in gsi_isr()
1414 dev_err(gsi->dev, "interrupt flood\n"); in gsi_isr()
1429 return ret ? : -EINVAL; in gsi_irq_init()
1431 gsi->irq = ret; in gsi_irq_init()
1440 u32 channel_id = event->chid; in gsi_event_trans()
1446 channel = &gsi->channel[channel_id]; in gsi_event_trans()
1447 if (WARN(!channel->gsi, "event has bad channel %u\n", channel_id)) in gsi_event_trans()
1451 tre_offset = lower_32_bits(le64_to_cpu(event->xfer_ptr)); in gsi_event_trans()
1452 tre_index = gsi_ring_index(&channel->tre_ring, tre_offset); in gsi_event_trans()
1463 * gsi_evt_ring_update() - Update transaction state from hardware
1470 * we update transactions to record their actual received lengths.
1473 * transaction to report the number of requests and bytes that have
1484 * Note that @index always refers to an element *within* the event ring.
1488 struct gsi_evt_ring *evt_ring = &gsi->evt_ring[evt_ring_id]; in gsi_evt_ring_update()
1489 struct gsi_ring *ring = &evt_ring->ring; in gsi_evt_ring_update()
1495 /* Starting with the oldest un-processed event, determine which in gsi_evt_ring_update()
1499 * associated with a network device, report to the network stack in gsi_evt_ring_update()
1502 old_index = ring->index; in gsi_evt_ring_update()
1505 /* Compute the number of events to process before we wrap, in gsi_evt_ring_update()
1508 event_avail = ring->count - old_index % ring->count; in gsi_evt_ring_update()
1517 if (trans->direction == DMA_FROM_DEVICE) in gsi_evt_ring_update()
1518 trans->len = __le16_to_cpu(event->len); in gsi_evt_ring_update()
1524 /* Move on to the next event and transaction */ in gsi_evt_ring_update()
1525 if (--event_avail) in gsi_evt_ring_update()
1539 struct device *dev = gsi->dev; in gsi_ring_alloc()
1542 /* Hardware requires a 2^n ring size, with alignment equal to size. in gsi_ring_alloc()
1543 * The DMA address returned by dma_alloc_coherent() is guaranteed to in gsi_ring_alloc()
1544 * be a power-of-2 number of pages, which satisfies the requirement. in gsi_ring_alloc()
1546 ring->virt = dma_alloc_coherent(dev, size, &addr, GFP_KERNEL); in gsi_ring_alloc()
1547 if (!ring->virt) in gsi_ring_alloc()
1548 return -ENOMEM; in gsi_ring_alloc()
1550 ring->addr = addr; in gsi_ring_alloc()
1551 ring->count = count; in gsi_ring_alloc()
1552 ring->index = 0; in gsi_ring_alloc()
1557 /* Free a previously-allocated ring */
1560 size_t size = ring->count * GSI_RING_ELEMENT_SIZE; in gsi_ring_free()
1562 dma_free_coherent(gsi->dev, size, ring->virt, ring->addr); in gsi_ring_free()
1570 if (gsi->event_bitmap == ~0U) { in gsi_evt_ring_id_alloc()
1571 dev_err(gsi->dev, "event rings exhausted\n"); in gsi_evt_ring_id_alloc()
1572 return -ENOSPC; in gsi_evt_ring_id_alloc()
1575 evt_ring_id = ffz(gsi->event_bitmap); in gsi_evt_ring_id_alloc()
1576 gsi->event_bitmap |= BIT(evt_ring_id); in gsi_evt_ring_id_alloc()
1581 /* Free a previously-allocated event ring id */
1584 gsi->event_bitmap &= ~BIT(evt_ring_id); in gsi_evt_ring_id_free()
1587 /* Ring a channel doorbell, reporting the first un-filled entry */
1590 struct gsi_ring *tre_ring = &channel->tre_ring; in gsi_channel_doorbell()
1592 struct gsi *gsi = channel->gsi; in gsi_channel_doorbell()
1598 val = gsi_ring_addr(tre_ring, tre_ring->index % tre_ring->count); in gsi_channel_doorbell()
1599 iowrite32(val, gsi->virt + reg_n_offset(reg, channel_id)); in gsi_channel_doorbell()
1602 /* Consult hardware, move newly completed transactions to completed state */
1605 u32 evt_ring_id = channel->evt_ring_id; in gsi_channel_update()
1606 struct gsi *gsi = channel->gsi; in gsi_channel_update()
1614 evt_ring = &gsi->evt_ring[evt_ring_id]; in gsi_channel_update()
1615 ring = &evt_ring->ring; in gsi_channel_update()
1617 /* See if there's anything new to process; if not, we're done. Note in gsi_channel_update()
1618 * that index always refers to an entry *within* the event ring. in gsi_channel_update()
1622 index = gsi_ring_index(ring, ioread32(gsi->virt + offset)); in gsi_channel_update()
1623 if (index == ring->index % ring->count) in gsi_channel_update()
1627 trans = gsi_event_trans(gsi, gsi_ring_virt(ring, index - 1)); in gsi_channel_update()
1640 * gsi_channel_poll_one() - Return a single completed transaction on a channel
1641 * @channel: Channel to be polled
1646 * If no transactions are in completed state, the hardware is consulted to
1648 * moved to completed state and the first such transaction is returned.
1664 * gsi_channel_poll() - NAPI poll function for a channel
1672 * polled is passed to gsi_trans_complete(), to perform remaining
1691 gsi_irq_ieob_enable_one(channel->gsi, channel->evt_ring_id); in gsi_channel_poll()
1703 u32 event_bitmap = GENMASK(BITS_PER_LONG - 1, evt_ring_max); in gsi_event_bitmap_init()
1713 struct gsi_channel *channel = &gsi->channel[channel_id]; in gsi_channel_setup_one()
1714 u32 evt_ring_id = channel->evt_ring_id; in gsi_channel_setup_one()
1732 if (channel->toward_ipa) in gsi_channel_setup_one()
1733 netif_napi_add_tx(&gsi->dummy_dev, &channel->napi, in gsi_channel_setup_one()
1736 netif_napi_add(&gsi->dummy_dev, &channel->napi, in gsi_channel_setup_one()
1751 struct gsi_channel *channel = &gsi->channel[channel_id]; in gsi_channel_teardown_one()
1752 u32 evt_ring_id = channel->evt_ring_id; in gsi_channel_teardown_one()
1757 netif_napi_del(&channel->napi); in gsi_channel_teardown_one()
1764 /* We use generic commands only to operate on modem channels. We don't have
1765 * the ability to determine channel state for a modem channel, so we simply
1766 * issue the command and wait for it to complete.
1782 * (to allocate, halt, or enable/disable flow control on a modem in gsi_generic_command()
1788 iowrite32(val, gsi->virt + reg_offset(reg)); in gsi_generic_command()
1793 val = ioread32(gsi->virt + offset); in gsi_generic_command()
1796 iowrite32(val, gsi->virt + offset); in gsi_generic_command()
1803 if (gsi->version >= IPA_VERSION_4_11) in gsi_generic_command()
1810 iowrite32(ERROR_INT, gsi->virt + reg_offset(reg)); in gsi_generic_command()
1813 return gsi->result; in gsi_generic_command()
1815 dev_err(gsi->dev, "GSI generic command %u to channel %u timed out\n", in gsi_generic_command()
1818 return -ETIMEDOUT; in gsi_generic_command()
1835 while (ret == -EAGAIN && retries--); in gsi_modem_channel_halt()
1838 dev_err(gsi->dev, "error %d halting modem channel %u\n", in gsi_modem_channel_halt()
1842 /* Enable or disable flow control for a modem GSI TX channel (IPA v4.2+) */
1852 /* Disabling flow control on IPA v4.11+ can return -EAGAIN if enable in gsi_modem_channel_flow_control()
1853 * is underway. In this case we need to retry the command. in gsi_modem_channel_flow_control()
1855 if (!enable && gsi->version >= IPA_VERSION_4_11) in gsi_modem_channel_flow_control()
1860 while (ret == -EAGAIN && retries--); in gsi_modem_channel_flow_control()
1863 dev_err(gsi->dev, in gsi_modem_channel_flow_control()
1877 mutex_lock(&gsi->mutex); in gsi_channel_setup()
1883 } while (++channel_id < gsi->channel_count); in gsi_channel_setup()
1887 struct gsi_channel *channel = &gsi->channel[channel_id++]; in gsi_channel_setup()
1892 ret = -EINVAL; in gsi_channel_setup()
1893 dev_err(gsi->dev, "channel %u not supported by hardware\n", in gsi_channel_setup()
1894 channel_id - 1); in gsi_channel_setup()
1895 channel_id = gsi->channel_count; in gsi_channel_setup()
1899 /* Allocate modem channels if necessary */ in gsi_channel_setup()
1900 mask = gsi->modem_channel_bitmap; in gsi_channel_setup()
1912 mutex_unlock(&gsi->mutex); in gsi_channel_setup()
1917 /* Compute which modem channels need to be deallocated */ in gsi_channel_setup()
1918 mask ^= gsi->modem_channel_bitmap; in gsi_channel_setup()
1928 while (channel_id--) in gsi_channel_setup()
1931 mutex_unlock(&gsi->mutex); in gsi_channel_setup()
1941 u32 mask = gsi->modem_channel_bitmap; in gsi_channel_teardown()
1944 mutex_lock(&gsi->mutex); in gsi_channel_teardown()
1954 channel_id = gsi->channel_count - 1; in gsi_channel_teardown()
1957 while (channel_id--); in gsi_channel_teardown()
1959 mutex_unlock(&gsi->mutex); in gsi_channel_teardown()
1972 iowrite32(reg_bit(reg, INTYPE), gsi->virt + reg_offset(reg)); in gsi_irq_setup()
1977 /* Clear all type-specific interrupt masks */ in gsi_irq_setup()
1979 iowrite32(0, gsi->virt + reg_offset(reg)); in gsi_irq_setup()
1982 iowrite32(0, gsi->virt + reg_offset(reg)); in gsi_irq_setup()
1985 iowrite32(0, gsi->virt + reg_offset(reg)); in gsi_irq_setup()
1988 iowrite32(0, gsi->virt + reg_offset(reg)); in gsi_irq_setup()
1990 /* The inter-EE interrupts are not supported for IPA v3.0-v3.1 */ in gsi_irq_setup()
1991 if (gsi->version > IPA_VERSION_3_1) { in gsi_irq_setup()
1993 iowrite32(0, gsi->virt + reg_offset(reg)); in gsi_irq_setup()
1996 iowrite32(0, gsi->virt + reg_offset(reg)); in gsi_irq_setup()
2000 iowrite32(0, gsi->virt + reg_offset(reg)); in gsi_irq_setup()
2002 ret = request_irq(gsi->irq, gsi_isr, 0, "gsi", gsi); in gsi_irq_setup()
2004 dev_err(gsi->dev, "error %d requesting \"gsi\" IRQ\n", ret); in gsi_irq_setup()
2011 free_irq(gsi->irq, gsi); in gsi_irq_teardown()
2017 struct device *dev = gsi->dev; in gsi_ring_setup()
2022 if (gsi->version < IPA_VERSION_3_5_1) { in gsi_ring_setup()
2023 /* No HW_PARAM_2 register prior to IPA v3.5.1, assume the max */ in gsi_ring_setup()
2024 gsi->channel_count = GSI_CHANNEL_COUNT_MAX; in gsi_ring_setup()
2025 gsi->evt_ring_count = GSI_EVT_RING_COUNT_MAX; in gsi_ring_setup()
2031 val = ioread32(gsi->virt + reg_offset(reg)); in gsi_ring_setup()
2036 return -EINVAL; in gsi_ring_setup()
2039 dev_warn(dev, "limiting to %u channels; hardware supports %u\n", in gsi_ring_setup()
2043 gsi->channel_count = count; in gsi_ring_setup()
2045 if (gsi->version < IPA_VERSION_5_0) { in gsi_ring_setup()
2053 return -EINVAL; in gsi_ring_setup()
2057 "limiting to %u event rings; hardware supports %u\n", in gsi_ring_setup()
2061 gsi->evt_ring_count = count; in gsi_ring_setup()
2075 val = ioread32(gsi->virt + reg_offset(reg)); in gsi_setup()
2077 dev_err(gsi->dev, "GSI has not been enabled\n"); in gsi_setup()
2078 return -EIO; in gsi_setup()
2091 iowrite32(0, gsi->virt + reg_offset(reg)); in gsi_setup()
2115 struct gsi *gsi = channel->gsi; in gsi_channel_evt_ring_init()
2122 channel->evt_ring_id = ret; in gsi_channel_evt_ring_init()
2124 evt_ring = &gsi->evt_ring[channel->evt_ring_id]; in gsi_channel_evt_ring_init()
2125 evt_ring->channel = channel; in gsi_channel_evt_ring_init()
2127 ret = gsi_ring_alloc(gsi, &evt_ring->ring, channel->event_count); in gsi_channel_evt_ring_init()
2131 dev_err(gsi->dev, "error %d allocating channel %u event ring\n", in gsi_channel_evt_ring_init()
2134 gsi_evt_ring_id_free(gsi, channel->evt_ring_id); in gsi_channel_evt_ring_init()
2142 u32 evt_ring_id = channel->evt_ring_id; in gsi_channel_evt_ring_exit()
2143 struct gsi *gsi = channel->gsi; in gsi_channel_evt_ring_exit()
2146 evt_ring = &gsi->evt_ring[evt_ring_id]; in gsi_channel_evt_ring_exit()
2147 gsi_ring_free(gsi, &evt_ring->ring); in gsi_channel_evt_ring_exit()
2155 u32 channel_id = data->channel_id; in gsi_channel_data_valid()
2156 struct device *dev = gsi->dev; in gsi_channel_data_valid()
2165 if (data->ee_id != GSI_EE_AP && data->ee_id != GSI_EE_MODEM) { in gsi_channel_data_valid()
2166 dev_err(dev, "bad EE id %u; not AP or modem\n", data->ee_id); in gsi_channel_data_valid()
2170 if (command && !data->toward_ipa) { in gsi_channel_data_valid()
2175 channel_data = &data->channel; in gsi_channel_data_valid()
2177 if (!channel_data->tlv_count || in gsi_channel_data_valid()
2178 channel_data->tlv_count > GSI_TLV_MAX) { in gsi_channel_data_valid()
2180 channel_id, channel_data->tlv_count, GSI_TLV_MAX); in gsi_channel_data_valid()
2184 if (command && IPA_COMMAND_TRANS_TRE_MAX > channel_data->tlv_count) { in gsi_channel_data_valid()
2187 channel_data->tlv_count); in gsi_channel_data_valid()
2191 /* We have to allow at least one maximally-sized transaction to in gsi_channel_data_valid()
2193 * gsi_channel_tre_max() is computed, tre_count has to be almost in gsi_channel_data_valid()
2194 * twice the TLV FIFO size to satisfy this requirement. in gsi_channel_data_valid()
2196 if (channel_data->tre_count < 2 * channel_data->tlv_count - 1) { in gsi_channel_data_valid()
2198 channel_id, channel_data->tlv_count, in gsi_channel_data_valid()
2199 channel_data->tre_count); in gsi_channel_data_valid()
2203 if (!is_power_of_2(channel_data->tre_count)) { in gsi_channel_data_valid()
2205 channel_id, channel_data->tre_count); in gsi_channel_data_valid()
2209 if (!is_power_of_2(channel_data->event_count)) { in gsi_channel_data_valid()
2211 channel_id, channel_data->event_count); in gsi_channel_data_valid()
2228 return -EINVAL; in gsi_channel_init_one()
2231 if (data->channel.tre_count > data->channel.event_count) { in gsi_channel_init_one()
2232 tre_count = data->channel.event_count; in gsi_channel_init_one()
2233 dev_warn(gsi->dev, "channel %u limited to %u TREs\n", in gsi_channel_init_one()
2234 data->channel_id, tre_count); in gsi_channel_init_one()
2236 tre_count = data->channel.tre_count; in gsi_channel_init_one()
2239 channel = &gsi->channel[data->channel_id]; in gsi_channel_init_one()
2242 channel->gsi = gsi; in gsi_channel_init_one()
2243 channel->toward_ipa = data->toward_ipa; in gsi_channel_init_one()
2244 channel->command = command; in gsi_channel_init_one()
2245 channel->trans_tre_max = data->channel.tlv_count; in gsi_channel_init_one()
2246 channel->tre_count = tre_count; in gsi_channel_init_one()
2247 channel->event_count = data->channel.event_count; in gsi_channel_init_one()
2253 ret = gsi_ring_alloc(gsi, &channel->tre_ring, data->channel.tre_count); in gsi_channel_init_one()
2255 dev_err(gsi->dev, "error %d allocating channel %u ring\n", in gsi_channel_init_one()
2256 ret, data->channel_id); in gsi_channel_init_one()
2260 ret = gsi_channel_trans_init(gsi, data->channel_id); in gsi_channel_init_one()
2265 u32 tre_max = gsi_channel_tre_max(gsi, data->channel_id); in gsi_channel_init_one()
2274 gsi_ring_free(gsi, &channel->tre_ring); in gsi_channel_init_one()
2278 channel->gsi = NULL; /* Mark it not (fully) initialized */ in gsi_channel_init_one()
2289 if (channel->command) in gsi_channel_exit_one()
2292 gsi_ring_free(channel->gsi, &channel->tre_ring); in gsi_channel_exit_one()
2304 /* IPA v4.2 requires the AP to allocate channels for the modem */ in gsi_channel_init()
2305 modem_alloc = gsi->version == IPA_VERSION_4_2; in gsi_channel_init()
2307 gsi->event_bitmap = gsi_event_bitmap_init(GSI_EVT_RING_COUNT_MAX); in gsi_channel_init()
2308 gsi->ieob_enabled_bitmap = 0; in gsi_channel_init()
2317 /* Mark modem channels to be allocated (hardware workaround) */ in gsi_channel_init()
2320 gsi->modem_channel_bitmap |= in gsi_channel_init()
2333 while (i--) { in gsi_channel_init()
2337 gsi->modem_channel_bitmap &= ~BIT(data[i].channel_id); in gsi_channel_init()
2340 gsi_channel_exit_one(&gsi->channel[data->channel_id]); in gsi_channel_init()
2349 u32 channel_id = GSI_CHANNEL_COUNT_MAX - 1; in gsi_channel_exit()
2352 gsi_channel_exit_one(&gsi->channel[channel_id]); in gsi_channel_exit()
2353 while (channel_id--); in gsi_channel_exit()
2354 gsi->modem_channel_bitmap = 0; in gsi_channel_exit()
2357 /* Init function for GSI. GSI hardware does not need to be "ready" */
2366 gsi->dev = &pdev->dev; in gsi_init()
2367 gsi->version = version; in gsi_init()
2370 * for the channel NAPI contexts to be associated with. in gsi_init()
2372 init_dummy_netdev(&gsi->dummy_dev); in gsi_init()
2373 init_completion(&gsi->completion); in gsi_init()
2387 mutex_init(&gsi->mutex); in gsi_init()
2400 mutex_destroy(&gsi->mutex); in gsi_exit()
2411 * doing that led to the hardware reporting exhaustion of event ring
2413 * would be (tre_count - 1).
2416 * sized to be a little larger than this maximum, to allow resource
2417 * allocations to always be contiguous. The number of entries in a
2419 * tends to nearly double the memory allocated for it. Reducing the
2421 * a pool to avoid crossing that power-of-2 boundary, and this can
2427 struct gsi_channel *channel = &gsi->channel[channel_id]; in gsi_channel_tre_max()
2429 /* Hardware limit is channel->tre_count - 1 */ in gsi_channel_tre_max()
2430 return channel->tre_count - (channel->trans_tre_max - 1); in gsi_channel_tre_max()