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-2024 Linaro Ltd.
10 #include <linux/dma-direction.h>
15 #include "ipa.h"
23 * DOC: IPA Immediate Commands
25 * The AP command TX endpoint is used to issue immediate commands to the IPA.
26 * An immediate command is generally used to request the IPA do something
27 * other than data transfer to another endpoint.
31 * has a well-defined format, having a payload of a known length. This
32 * allows the transfer element's length field to be used to hold an
33 * immediate command's opcode. The payload for a command resides in AP
74 /* For IPA v4.0+, the pipeline clear options are encoded in the opcode */
79 __le16 flags; /* Unused/reserved prior to IPA v4.0 */
83 __le32 clear_options; /* Unused/reserved for IPA v4.0+ */
87 /* The next field is present for IPA v4.0+ */
89 /* The next field is not present for IPA v4.0+ */
92 /* The next field and its values are not present for IPA v4.0+ */
98 u8 dest_endpoint; /* Full 8 bits used for IPA v5.0+ */
107 /* For IPA v4.0+, this opcode gets modified with pipeline clear options */
125 /* The next two fields are not present for IPA v4.0+ */
149 /* The size of a filter table needs to fit into fields in the in ipa_cmd_validate_build()
151 * might not be used, non-hashed and hashed tables have the same in ipa_cmd_validate_build()
155 /* Hashed and non-hashed fields are assumed to be the same size */ in ipa_cmd_validate_build()
161 /* Prior to IPA v5.0, we supported no more than 32 endpoints, in ipa_cmd_validate_build()
162 * and this was reflected in some 5-bit fields that held in ipa_cmd_validate_build()
163 * endpoint numbers. Starting with IPA v5.0, the widths of in ipa_cmd_validate_build()
164 * these fields were extended to 8 bits, meaning up to 256 in ipa_cmd_validate_build()
165 * endpoints. If the driver claims to support more than in ipa_cmd_validate_build()
168 BUILD_BUG_ON(IPA_ENDPOINT_MAX - 1 > U8_MAX); in ipa_cmd_validate_build()
172 bool ipa_cmd_table_init_valid(struct ipa *ipa, const struct ipa_mem *mem, in ipa_cmd_table_init_valid() argument
178 struct device *dev = ipa->dev; in ipa_cmd_table_init_valid()
181 size = route ? ipa->route_count : ipa->filter_count + 1; in ipa_cmd_table_init_valid()
193 if (mem->offset > offset_max || in ipa_cmd_table_init_valid()
194 ipa->mem_offset > offset_max - mem->offset) { in ipa_cmd_table_init_valid()
197 ipa->mem_offset, mem->offset, offset_max); in ipa_cmd_table_init_valid()
206 static bool ipa_cmd_header_init_local_valid(struct ipa *ipa) in ipa_cmd_header_init_local_valid() argument
208 struct device *dev = ipa->dev; in ipa_cmd_header_init_local_valid()
217 * the offset and size fit in the fields that need to hold them, and in ipa_cmd_header_init_local_valid()
218 * that the entire range is within the overall IPA memory range. in ipa_cmd_header_init_local_valid()
223 /* The header memory area contains both the modem and AP header in ipa_cmd_header_init_local_valid()
224 * regions. The modem portion defines the address of the region. in ipa_cmd_header_init_local_valid()
226 mem = ipa_mem_find(ipa, IPA_MEM_MODEM_HEADER); in ipa_cmd_header_init_local_valid()
227 offset = mem->offset; in ipa_cmd_header_init_local_valid()
228 size = mem->size; in ipa_cmd_header_init_local_valid()
230 /* Make sure the offset fits in the IPA command */ in ipa_cmd_header_init_local_valid()
231 if (offset > offset_max || ipa->mem_offset > offset_max - offset) { in ipa_cmd_header_init_local_valid()
234 ipa->mem_offset, offset, offset_max); in ipa_cmd_header_init_local_valid()
239 /* Add the size of the AP portion (if defined) to the combined size */ in ipa_cmd_header_init_local_valid()
240 mem = ipa_mem_find(ipa, IPA_MEM_AP_HEADER); in ipa_cmd_header_init_local_valid()
242 size += mem->size; in ipa_cmd_header_init_local_valid()
244 /* Make sure the combined size fits in the IPA command */ in ipa_cmd_header_init_local_valid()
256 static bool ipa_cmd_register_write_offset_valid(struct ipa *ipa, in ipa_cmd_register_write_offset_valid() argument
260 struct device *dev = ipa->dev; in ipa_cmd_register_write_offset_valid()
265 * on the version of IPA. A 16 bit offset is always supported, in ipa_cmd_register_write_offset_valid()
266 * but starting with IPA v4.0 some additional high-order bits are in ipa_cmd_register_write_offset_valid()
269 bit_count = BITS_PER_BYTE * sizeof(payload->offset); in ipa_cmd_register_write_offset_valid()
270 if (ipa->version >= IPA_VERSION_4_0) in ipa_cmd_register_write_offset_valid()
273 offset_max = ~0U >> (32 - bit_count); in ipa_cmd_register_write_offset_valid()
277 * the overall IPA memory range. in ipa_cmd_register_write_offset_valid()
279 if (offset > offset_max || ipa->mem_offset > offset_max - offset) { in ipa_cmd_register_write_offset_valid()
281 name, ipa->mem_offset, offset, offset_max); in ipa_cmd_register_write_offset_valid()
288 /* Check whether offsets passed to register_write are valid */
289 static bool ipa_cmd_register_write_valid(struct ipa *ipa) in ipa_cmd_register_write_valid() argument
296 * offset will fit in a register write IPA immediate command. in ipa_cmd_register_write_valid()
298 if (ipa_table_hash_support(ipa)) { in ipa_cmd_register_write_valid()
299 if (ipa->version < IPA_VERSION_5_0) in ipa_cmd_register_write_valid()
300 reg = ipa_reg(ipa, FILT_ROUT_HASH_FLUSH); in ipa_cmd_register_write_valid()
302 reg = ipa_reg(ipa, FILT_ROUT_CACHE_FLUSH); in ipa_cmd_register_write_valid()
306 if (!ipa_cmd_register_write_offset_valid(ipa, name, offset)) in ipa_cmd_register_write_valid()
311 * and this is recorded in an endpoint register. If the modem in ipa_cmd_register_write_valid()
312 * crashes, we reset the status endpoint for all modem endpoints in ipa_cmd_register_write_valid()
313 * using a register write IPA immediate command. Make sure the in ipa_cmd_register_write_valid()
317 reg = ipa_reg(ipa, ENDP_STATUS); in ipa_cmd_register_write_valid()
318 offset = reg_n_offset(reg, IPA_ENDPOINT_COUNT - 1); in ipa_cmd_register_write_valid()
320 if (!ipa_cmd_register_write_offset_valid(ipa, name, offset)) in ipa_cmd_register_write_valid()
328 struct gsi_trans_info *trans_info = &channel->trans_info; in ipa_cmd_pool_init()
329 struct device *dev = channel->gsi->dev; in ipa_cmd_pool_init()
332 * transaction can require up to the maximum supported by the in ipa_cmd_pool_init()
335 return gsi_trans_pool_init_dma(dev, &trans_info->cmd_pool, in ipa_cmd_pool_init()
337 tre_max, channel->trans_tre_max); in ipa_cmd_pool_init()
342 struct gsi_trans_info *trans_info = &channel->trans_info; in ipa_cmd_pool_exit()
343 struct device *dev = channel->gsi->dev; in ipa_cmd_pool_exit()
345 gsi_trans_pool_exit_dma(dev, &trans_info->cmd_pool); in ipa_cmd_pool_exit()
349 ipa_cmd_payload_alloc(struct ipa *ipa, dma_addr_t *addr) in ipa_cmd_payload_alloc() argument
354 endpoint = ipa->name_map[IPA_ENDPOINT_AP_COMMAND_TX]; in ipa_cmd_payload_alloc()
355 trans_info = &ipa->gsi.channel[endpoint->channel_id].trans_info; in ipa_cmd_payload_alloc()
357 return gsi_trans_pool_alloc_dma(&trans_info->cmd_pool, addr); in ipa_cmd_payload_alloc()
366 struct ipa *ipa = container_of(trans->gsi, struct ipa, gsi); in ipa_cmd_table_init_add() local
372 /* Record the non-hash table offset and size */ in ipa_cmd_table_init_add()
373 offset += ipa->mem_offset; in ipa_cmd_table_init_add()
380 hash_offset += ipa->mem_offset; in ipa_cmd_table_init_add()
387 cmd_payload = ipa_cmd_payload_alloc(ipa, &payload_addr); in ipa_cmd_table_init_add()
388 payload = &cmd_payload->table_init; in ipa_cmd_table_init_add()
390 /* Fill in all offsets and sizes and the non-hash table address */ in ipa_cmd_table_init_add()
392 payload->hash_rules_addr = cpu_to_le64(hash_addr); in ipa_cmd_table_init_add()
393 payload->flags = cpu_to_le64(val); in ipa_cmd_table_init_add()
394 payload->nhash_rules_addr = cpu_to_le64(addr); in ipa_cmd_table_init_add()
400 /* Initialize header space in IPA-local memory */
404 struct ipa *ipa = container_of(trans->gsi, struct ipa, gsi); in ipa_cmd_hdr_init_local_add() local
411 offset += ipa->mem_offset; in ipa_cmd_hdr_init_local_add()
413 /* With this command we tell the IPA where in its local memory the in ipa_cmd_hdr_init_local_add()
415 * also written via DMA into that space. The IPA hardware owns in ipa_cmd_hdr_init_local_add()
416 * the table, but the AP must initialize it. in ipa_cmd_hdr_init_local_add()
418 cmd_payload = ipa_cmd_payload_alloc(ipa, &payload_addr); in ipa_cmd_hdr_init_local_add()
419 payload = &cmd_payload->hdr_init_local; in ipa_cmd_hdr_init_local_add()
421 payload->hdr_table_addr = cpu_to_le64(addr); in ipa_cmd_hdr_init_local_add()
424 payload->flags = cpu_to_le32(flags); in ipa_cmd_hdr_init_local_add()
433 struct ipa *ipa = container_of(trans->gsi, struct ipa, gsi); in ipa_cmd_register_write_add() local
445 /* IPA v4.0+ represents the pipeline clear options in the opcode. It in ipa_cmd_register_write_add()
446 * also supports a larger offset by encoding additional high-order in ipa_cmd_register_write_add()
449 if (ipa->version >= IPA_VERSION_4_0) { in ipa_cmd_register_write_add()
461 offset &= (1 << 16) - 1; in ipa_cmd_register_write_add()
474 cmd_payload = ipa_cmd_payload_alloc(ipa, &payload_addr); in ipa_cmd_register_write_add()
475 payload = &cmd_payload->register_write; in ipa_cmd_register_write_add()
477 payload->flags = cpu_to_le16(flags); in ipa_cmd_register_write_add()
478 payload->offset = cpu_to_le16((u16)offset); in ipa_cmd_register_write_add()
479 payload->value = cpu_to_le32(value); in ipa_cmd_register_write_add()
480 payload->value_mask = cpu_to_le32(mask); in ipa_cmd_register_write_add()
481 payload->clear_options = cpu_to_le32(options); in ipa_cmd_register_write_add()
490 struct ipa *ipa = container_of(trans->gsi, struct ipa, gsi); in ipa_cmd_ip_packet_init_add() local
496 cmd_payload = ipa_cmd_payload_alloc(ipa, &payload_addr); in ipa_cmd_ip_packet_init_add()
497 payload = &cmd_payload->ip_packet_init; in ipa_cmd_ip_packet_init_add()
499 if (ipa->version < IPA_VERSION_5_0) { in ipa_cmd_ip_packet_init_add()
500 payload->dest_endpoint = in ipa_cmd_ip_packet_init_add()
504 payload->dest_endpoint = endpoint_id; in ipa_cmd_ip_packet_init_add()
511 /* Use a DMA command to read or write a block of IPA-resident memory */
515 struct ipa *ipa = container_of(trans->gsi, struct ipa, gsi); in ipa_cmd_dma_shared_mem_add() local
525 WARN_ON(offset > U16_MAX || ipa->mem_offset > U16_MAX - offset); in ipa_cmd_dma_shared_mem_add()
527 offset += ipa->mem_offset; in ipa_cmd_dma_shared_mem_add()
529 cmd_payload = ipa_cmd_payload_alloc(ipa, &payload_addr); in ipa_cmd_dma_shared_mem_add()
530 payload = &cmd_payload->dma_shared_mem; in ipa_cmd_dma_shared_mem_add()
532 /* payload->clear_after_read was reserved prior to IPA v4.0. It's in ipa_cmd_dma_shared_mem_add()
535 payload->size = cpu_to_le16(size); in ipa_cmd_dma_shared_mem_add()
536 payload->local_addr = cpu_to_le16(offset); in ipa_cmd_dma_shared_mem_add()
537 /* payload->flags: in ipa_cmd_dma_shared_mem_add()
538 * direction: 0 = write to IPA, 1 read from IPA in ipa_cmd_dma_shared_mem_add()
546 payload->flags = cpu_to_le16(flags); in ipa_cmd_dma_shared_mem_add()
547 payload->system_addr = cpu_to_le64(addr); in ipa_cmd_dma_shared_mem_add()
555 struct ipa *ipa = container_of(trans->gsi, struct ipa, gsi); in ipa_cmd_ip_tag_status_add() local
561 cmd_payload = ipa_cmd_payload_alloc(ipa, &payload_addr); in ipa_cmd_ip_tag_status_add()
562 payload = &cmd_payload->ip_packet_tag_status; in ipa_cmd_ip_tag_status_add()
564 payload->tag = le64_encode_bits(0, IP_PACKET_TAG_STATUS_TAG_FMASK); in ipa_cmd_ip_tag_status_add()
573 struct ipa *ipa = container_of(trans->gsi, struct ipa, gsi); in ipa_cmd_transfer_add() local
578 /* Just transfer a zero-filled payload structure */ in ipa_cmd_transfer_add()
579 payload = ipa_cmd_payload_alloc(ipa, &payload_addr); in ipa_cmd_transfer_add()
585 /* Add immediate commands to a transaction to clear the hardware pipeline */
588 struct ipa *ipa = container_of(trans->gsi, struct ipa, gsi); in ipa_cmd_pipeline_clear_add() local
592 reinit_completion(&ipa->completion); in ipa_cmd_pipeline_clear_add()
594 /* Issue a no-op register write command (mask 0 means no write) */ in ipa_cmd_pipeline_clear_add()
597 /* Send a data packet through the IPA pipeline. The packet_init in ipa_cmd_pipeline_clear_add()
598 * command says to send the next packet directly to the exception in ipa_cmd_pipeline_clear_add()
599 * endpoint without any other IPA processing. The tag_status in ipa_cmd_pipeline_clear_add()
605 endpoint = ipa->name_map[IPA_ENDPOINT_AP_LAN_RX]; in ipa_cmd_pipeline_clear_add()
606 ipa_cmd_ip_packet_init_add(trans, endpoint->endpoint_id); in ipa_cmd_pipeline_clear_add()
611 /* Returns the number of commands required to clear the pipeline */
617 void ipa_cmd_pipeline_clear_wait(struct ipa *ipa) in ipa_cmd_pipeline_clear_wait() argument
619 wait_for_completion(&ipa->completion); in ipa_cmd_pipeline_clear_wait()
623 struct gsi_trans *ipa_cmd_trans_alloc(struct ipa *ipa, u32 tre_count) in ipa_cmd_trans_alloc() argument
630 endpoint = ipa->name_map[IPA_ENDPOINT_AP_COMMAND_TX]; in ipa_cmd_trans_alloc()
632 return gsi_channel_trans_alloc(&ipa->gsi, endpoint->channel_id, in ipa_cmd_trans_alloc()
637 int ipa_cmd_init(struct ipa *ipa) in ipa_cmd_init() argument
641 if (!ipa_cmd_header_init_local_valid(ipa)) in ipa_cmd_init()
642 return -EINVAL; in ipa_cmd_init()
644 if (!ipa_cmd_register_write_valid(ipa)) in ipa_cmd_init()
645 return -EINVAL; in ipa_cmd_init()