Lines Matching +full:ipa +full:- +full:ap +full:- +full:to +full:- +full:modem
1 // SPDX-License-Identifier: GPL-2.0
3 /* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
4 * Copyright (C) 2019-2023 Linaro Ltd.
11 #include <linux/dma-direction.h>
15 #include "ipa.h"
22 * DOC: IPA Immediate Commands
24 * The AP command TX endpoint is used to issue immediate commands to the IPA.
25 * An immediate command is generally used to request the IPA do something
26 * other than data transfer to another endpoint.
30 * has a well-defined format, having a payload of a known length. This
31 * allows the transfer element's length field to be used to hold an
32 * immediate command's opcode. The payload for a command resides in AP
73 /* For IPA v4.0+, the pipeline clear options are encoded in the opcode */
78 __le16 flags; /* Unused/reserved prior to IPA v4.0 */
82 __le32 clear_options; /* Unused/reserved for IPA v4.0+ */
86 /* The next field is present for IPA v4.0+ */
88 /* The next field is not present for IPA v4.0+ */
91 /* The next field and its values are not present for IPA v4.0+ */
97 u8 dest_endpoint; /* Full 8 bits used for IPA v5.0+ */
106 /* For IPA v4.0+, this opcode gets modified with pipeline clear options */
124 /* The next two fields are not present for IPA v4.0+ */
148 /* The size of a filter table needs to fit into fields in the in ipa_cmd_validate_build()
150 * might not be used, non-hashed and hashed tables have the same in ipa_cmd_validate_build()
154 /* Hashed and non-hashed fields are assumed to be the same size */ in ipa_cmd_validate_build()
160 /* Prior to IPA v5.0, we supported no more than 32 endpoints, in ipa_cmd_validate_build()
161 * and this was reflected in some 5-bit fields that held in ipa_cmd_validate_build()
162 * endpoint numbers. Starting with IPA v5.0, the widths of in ipa_cmd_validate_build()
163 * these fields were extended to 8 bits, meaning up to 256 in ipa_cmd_validate_build()
164 * endpoints. If the driver claims to support more than in ipa_cmd_validate_build()
167 BUILD_BUG_ON(IPA_ENDPOINT_MAX - 1 > U8_MAX); in ipa_cmd_validate_build()
171 bool ipa_cmd_table_init_valid(struct ipa *ipa, const struct ipa_mem *mem, in ipa_cmd_table_init_valid() argument
177 struct device *dev = &ipa->pdev->dev; in ipa_cmd_table_init_valid()
180 size = route ? ipa->route_count : ipa->filter_count + 1; in ipa_cmd_table_init_valid()
192 if (mem->offset > offset_max || in ipa_cmd_table_init_valid()
193 ipa->mem_offset > offset_max - mem->offset) { in ipa_cmd_table_init_valid()
196 ipa->mem_offset, mem->offset, offset_max); in ipa_cmd_table_init_valid()
205 static bool ipa_cmd_header_init_local_valid(struct ipa *ipa) in ipa_cmd_header_init_local_valid() argument
207 struct device *dev = &ipa->pdev->dev; in ipa_cmd_header_init_local_valid()
216 * the offset and size fit in the fields that need to hold them, and in ipa_cmd_header_init_local_valid()
217 * that the entire range is within the overall IPA memory range. in ipa_cmd_header_init_local_valid()
222 /* The header memory area contains both the modem and AP header in ipa_cmd_header_init_local_valid()
223 * regions. The modem portion defines the address of the region. in ipa_cmd_header_init_local_valid()
225 mem = ipa_mem_find(ipa, IPA_MEM_MODEM_HEADER); in ipa_cmd_header_init_local_valid()
226 offset = mem->offset; in ipa_cmd_header_init_local_valid()
227 size = mem->size; in ipa_cmd_header_init_local_valid()
229 /* Make sure the offset fits in the IPA command */ in ipa_cmd_header_init_local_valid()
230 if (offset > offset_max || ipa->mem_offset > offset_max - offset) { in ipa_cmd_header_init_local_valid()
233 ipa->mem_offset, offset, offset_max); in ipa_cmd_header_init_local_valid()
238 /* Add the size of the AP portion (if defined) to the combined size */ in ipa_cmd_header_init_local_valid()
239 mem = ipa_mem_find(ipa, IPA_MEM_AP_HEADER); in ipa_cmd_header_init_local_valid()
241 size += mem->size; in ipa_cmd_header_init_local_valid()
243 /* Make sure the combined size fits in the IPA command */ in ipa_cmd_header_init_local_valid()
255 static bool ipa_cmd_register_write_offset_valid(struct ipa *ipa, in ipa_cmd_register_write_offset_valid() argument
259 struct device *dev = &ipa->pdev->dev; in ipa_cmd_register_write_offset_valid()
264 * on the version of IPA. A 16 bit offset is always supported, in ipa_cmd_register_write_offset_valid()
265 * but starting with IPA v4.0 some additional high-order bits are in ipa_cmd_register_write_offset_valid()
268 bit_count = BITS_PER_BYTE * sizeof(payload->offset); in ipa_cmd_register_write_offset_valid()
269 if (ipa->version >= IPA_VERSION_4_0) in ipa_cmd_register_write_offset_valid()
272 offset_max = ~0U >> (32 - bit_count); in ipa_cmd_register_write_offset_valid()
276 * the overall IPA memory range. in ipa_cmd_register_write_offset_valid()
278 if (offset > offset_max || ipa->mem_offset > offset_max - offset) { in ipa_cmd_register_write_offset_valid()
280 name, ipa->mem_offset, offset, offset_max); in ipa_cmd_register_write_offset_valid()
287 /* Check whether offsets passed to register_write are valid */
288 static bool ipa_cmd_register_write_valid(struct ipa *ipa) in ipa_cmd_register_write_valid() argument
295 * offset will fit in a register write IPA immediate command. in ipa_cmd_register_write_valid()
297 if (ipa_table_hash_support(ipa)) { in ipa_cmd_register_write_valid()
298 if (ipa->version < IPA_VERSION_5_0) in ipa_cmd_register_write_valid()
299 reg = ipa_reg(ipa, FILT_ROUT_HASH_FLUSH); in ipa_cmd_register_write_valid()
301 reg = ipa_reg(ipa, FILT_ROUT_CACHE_FLUSH); in ipa_cmd_register_write_valid()
305 if (!ipa_cmd_register_write_offset_valid(ipa, name, offset)) in ipa_cmd_register_write_valid()
310 * and this is recorded in an endpoint register. If the modem in ipa_cmd_register_write_valid()
311 * crashes, we reset the status endpoint for all modem endpoints in ipa_cmd_register_write_valid()
312 * using a register write IPA immediate command. Make sure the in ipa_cmd_register_write_valid()
316 reg = ipa_reg(ipa, ENDP_STATUS); in ipa_cmd_register_write_valid()
317 offset = reg_n_offset(reg, IPA_ENDPOINT_COUNT - 1); in ipa_cmd_register_write_valid()
319 if (!ipa_cmd_register_write_offset_valid(ipa, name, offset)) in ipa_cmd_register_write_valid()
327 struct gsi_trans_info *trans_info = &channel->trans_info; in ipa_cmd_pool_init()
328 struct device *dev = channel->gsi->dev; in ipa_cmd_pool_init()
331 * transaction can require up to the maximum supported by the in ipa_cmd_pool_init()
334 return gsi_trans_pool_init_dma(dev, &trans_info->cmd_pool, in ipa_cmd_pool_init()
336 tre_max, channel->trans_tre_max); in ipa_cmd_pool_init()
341 struct gsi_trans_info *trans_info = &channel->trans_info; in ipa_cmd_pool_exit()
342 struct device *dev = channel->gsi->dev; in ipa_cmd_pool_exit()
344 gsi_trans_pool_exit_dma(dev, &trans_info->cmd_pool); in ipa_cmd_pool_exit()
348 ipa_cmd_payload_alloc(struct ipa *ipa, dma_addr_t *addr) in ipa_cmd_payload_alloc() argument
353 endpoint = ipa->name_map[IPA_ENDPOINT_AP_COMMAND_TX]; in ipa_cmd_payload_alloc()
354 trans_info = &ipa->gsi.channel[endpoint->channel_id].trans_info; in ipa_cmd_payload_alloc()
356 return gsi_trans_pool_alloc_dma(&trans_info->cmd_pool, addr); in ipa_cmd_payload_alloc()
365 struct ipa *ipa = container_of(trans->gsi, struct ipa, gsi); in ipa_cmd_table_init_add() local
371 /* Record the non-hash table offset and size */ in ipa_cmd_table_init_add()
372 offset += ipa->mem_offset; in ipa_cmd_table_init_add()
379 hash_offset += ipa->mem_offset; in ipa_cmd_table_init_add()
386 cmd_payload = ipa_cmd_payload_alloc(ipa, &payload_addr); in ipa_cmd_table_init_add()
387 payload = &cmd_payload->table_init; in ipa_cmd_table_init_add()
389 /* Fill in all offsets and sizes and the non-hash table address */ in ipa_cmd_table_init_add()
391 payload->hash_rules_addr = cpu_to_le64(hash_addr); in ipa_cmd_table_init_add()
392 payload->flags = cpu_to_le64(val); in ipa_cmd_table_init_add()
393 payload->nhash_rules_addr = cpu_to_le64(addr); in ipa_cmd_table_init_add()
399 /* Initialize header space in IPA-local memory */
403 struct ipa *ipa = container_of(trans->gsi, struct ipa, gsi); in ipa_cmd_hdr_init_local_add() local
410 offset += ipa->mem_offset; in ipa_cmd_hdr_init_local_add()
412 /* With this command we tell the IPA where in its local memory the in ipa_cmd_hdr_init_local_add()
414 * also written via DMA into that space. The IPA hardware owns in ipa_cmd_hdr_init_local_add()
415 * the table, but the AP must initialize it. in ipa_cmd_hdr_init_local_add()
417 cmd_payload = ipa_cmd_payload_alloc(ipa, &payload_addr); in ipa_cmd_hdr_init_local_add()
418 payload = &cmd_payload->hdr_init_local; in ipa_cmd_hdr_init_local_add()
420 payload->hdr_table_addr = cpu_to_le64(addr); in ipa_cmd_hdr_init_local_add()
423 payload->flags = cpu_to_le32(flags); in ipa_cmd_hdr_init_local_add()
432 struct ipa *ipa = container_of(trans->gsi, struct ipa, gsi); in ipa_cmd_register_write_add() local
444 /* IPA v4.0+ represents the pipeline clear options in the opcode. It in ipa_cmd_register_write_add()
445 * also supports a larger offset by encoding additional high-order in ipa_cmd_register_write_add()
448 if (ipa->version >= IPA_VERSION_4_0) { in ipa_cmd_register_write_add()
460 offset &= (1 << 16) - 1; in ipa_cmd_register_write_add()
473 cmd_payload = ipa_cmd_payload_alloc(ipa, &payload_addr); in ipa_cmd_register_write_add()
474 payload = &cmd_payload->register_write; in ipa_cmd_register_write_add()
476 payload->flags = cpu_to_le16(flags); in ipa_cmd_register_write_add()
477 payload->offset = cpu_to_le16((u16)offset); in ipa_cmd_register_write_add()
478 payload->value = cpu_to_le32(value); in ipa_cmd_register_write_add()
479 payload->value_mask = cpu_to_le32(mask); in ipa_cmd_register_write_add()
480 payload->clear_options = cpu_to_le32(options); in ipa_cmd_register_write_add()
489 struct ipa *ipa = container_of(trans->gsi, struct ipa, gsi); in ipa_cmd_ip_packet_init_add() local
495 cmd_payload = ipa_cmd_payload_alloc(ipa, &payload_addr); in ipa_cmd_ip_packet_init_add()
496 payload = &cmd_payload->ip_packet_init; in ipa_cmd_ip_packet_init_add()
498 if (ipa->version < IPA_VERSION_5_0) { in ipa_cmd_ip_packet_init_add()
499 payload->dest_endpoint = in ipa_cmd_ip_packet_init_add()
503 payload->dest_endpoint = endpoint_id; in ipa_cmd_ip_packet_init_add()
510 /* Use a DMA command to read or write a block of IPA-resident memory */
514 struct ipa *ipa = container_of(trans->gsi, struct ipa, gsi); in ipa_cmd_dma_shared_mem_add() local
524 WARN_ON(offset > U16_MAX || ipa->mem_offset > U16_MAX - offset); in ipa_cmd_dma_shared_mem_add()
526 offset += ipa->mem_offset; in ipa_cmd_dma_shared_mem_add()
528 cmd_payload = ipa_cmd_payload_alloc(ipa, &payload_addr); in ipa_cmd_dma_shared_mem_add()
529 payload = &cmd_payload->dma_shared_mem; in ipa_cmd_dma_shared_mem_add()
531 /* payload->clear_after_read was reserved prior to IPA v4.0. It's in ipa_cmd_dma_shared_mem_add()
534 payload->size = cpu_to_le16(size); in ipa_cmd_dma_shared_mem_add()
535 payload->local_addr = cpu_to_le16(offset); in ipa_cmd_dma_shared_mem_add()
536 /* payload->flags: in ipa_cmd_dma_shared_mem_add()
537 * direction: 0 = write to IPA, 1 read from IPA in ipa_cmd_dma_shared_mem_add()
545 payload->flags = cpu_to_le16(flags); in ipa_cmd_dma_shared_mem_add()
546 payload->system_addr = cpu_to_le64(addr); in ipa_cmd_dma_shared_mem_add()
554 struct ipa *ipa = container_of(trans->gsi, struct ipa, gsi); in ipa_cmd_ip_tag_status_add() local
560 cmd_payload = ipa_cmd_payload_alloc(ipa, &payload_addr); in ipa_cmd_ip_tag_status_add()
561 payload = &cmd_payload->ip_packet_tag_status; in ipa_cmd_ip_tag_status_add()
563 payload->tag = le64_encode_bits(0, IP_PACKET_TAG_STATUS_TAG_FMASK); in ipa_cmd_ip_tag_status_add()
572 struct ipa *ipa = container_of(trans->gsi, struct ipa, gsi); in ipa_cmd_transfer_add() local
577 /* Just transfer a zero-filled payload structure */ in ipa_cmd_transfer_add()
578 payload = ipa_cmd_payload_alloc(ipa, &payload_addr); in ipa_cmd_transfer_add()
584 /* Add immediate commands to a transaction to clear the hardware pipeline */
587 struct ipa *ipa = container_of(trans->gsi, struct ipa, gsi); in ipa_cmd_pipeline_clear_add() local
591 reinit_completion(&ipa->completion); in ipa_cmd_pipeline_clear_add()
593 /* Issue a no-op register write command (mask 0 means no write) */ in ipa_cmd_pipeline_clear_add()
596 /* Send a data packet through the IPA pipeline. The packet_init in ipa_cmd_pipeline_clear_add()
597 * command says to send the next packet directly to the exception in ipa_cmd_pipeline_clear_add()
598 * endpoint without any other IPA processing. The tag_status in ipa_cmd_pipeline_clear_add()
604 endpoint = ipa->name_map[IPA_ENDPOINT_AP_LAN_RX]; in ipa_cmd_pipeline_clear_add()
605 ipa_cmd_ip_packet_init_add(trans, endpoint->endpoint_id); in ipa_cmd_pipeline_clear_add()
610 /* Returns the number of commands required to clear the pipeline */
616 void ipa_cmd_pipeline_clear_wait(struct ipa *ipa) in ipa_cmd_pipeline_clear_wait() argument
618 wait_for_completion(&ipa->completion); in ipa_cmd_pipeline_clear_wait()
622 struct gsi_trans *ipa_cmd_trans_alloc(struct ipa *ipa, u32 tre_count) in ipa_cmd_trans_alloc() argument
629 endpoint = ipa->name_map[IPA_ENDPOINT_AP_COMMAND_TX]; in ipa_cmd_trans_alloc()
631 return gsi_channel_trans_alloc(&ipa->gsi, endpoint->channel_id, in ipa_cmd_trans_alloc()
636 int ipa_cmd_init(struct ipa *ipa) in ipa_cmd_init() argument
640 if (!ipa_cmd_header_init_local_valid(ipa)) in ipa_cmd_init()
641 return -EINVAL; in ipa_cmd_init()
643 if (!ipa_cmd_register_write_valid(ipa)) in ipa_cmd_init()
644 return -EINVAL; in ipa_cmd_init()