Lines Matching +full:offset +full:- +full:x

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>
31 * has a well-defined format, having a payload of a known length. This
80 __le16 offset; member
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()
162 * and this was reflected in some 5-bit fields that held in ipa_cmd_validate_build()
168 BUILD_BUG_ON(IPA_ENDPOINT_MAX - 1 > U8_MAX); in ipa_cmd_validate_build()
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()
187 dev_err(dev, " (0x%04x > 0x%04x)\n", size, size_max); in ipa_cmd_table_init_valid()
192 /* Offset must fit in the immediate command field that holds it */ 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()
195 dev_err(dev, "%s table region offset too large\n", table); in ipa_cmd_table_init_valid()
196 dev_err(dev, " (0x%04x + 0x%04x > 0x%04x)\n", in ipa_cmd_table_init_valid()
197 ipa->mem_offset, mem->offset, offset_max); in ipa_cmd_table_init_valid()
208 struct device *dev = ipa->dev; in ipa_cmd_header_init_local_valid()
212 u32 offset; in ipa_cmd_header_init_local_valid() local
215 /* In ipa_cmd_hdr_init_local_add() we record the offset and size of 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()
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()
232 dev_err(dev, "header table region offset too large\n"); in ipa_cmd_header_init_local_valid()
233 dev_err(dev, " (0x%04x + 0x%04x > 0x%04x)\n", in ipa_cmd_header_init_local_valid()
234 ipa->mem_offset, offset, offset_max); in ipa_cmd_header_init_local_valid()
242 size += mem->size; in ipa_cmd_header_init_local_valid()
247 dev_err(dev, " (0x%04x > 0x%08x)\n", size, size_max); in ipa_cmd_header_init_local_valid()
255 /* Indicate whether an offset can be used with a register_write command */
257 const char *name, u32 offset) in ipa_cmd_register_write_offset_valid() argument
260 struct device *dev = ipa->dev; in ipa_cmd_register_write_offset_valid()
264 /* The maximum offset in a register_write immediate command depends 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()
275 /* Make sure the offset can be represented by the field(s) in ipa_cmd_register_write_offset_valid()
276 * that holds it. Also make sure the offset is not outside 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()
280 dev_err(dev, "%s offset too large 0x%04x + 0x%04x > 0x%04x)\n", in ipa_cmd_register_write_offset_valid()
281 name, ipa->mem_offset, offset, offset_max); in ipa_cmd_register_write_offset_valid()
293 u32 offset; in ipa_cmd_register_write_valid() local
296 * offset will fit in a register write IPA immediate command. in ipa_cmd_register_write_valid()
299 if (ipa->version < IPA_VERSION_5_0) in ipa_cmd_register_write_valid()
304 offset = reg_offset(reg); in ipa_cmd_register_write_valid()
306 if (!ipa_cmd_register_write_offset_valid(ipa, name, offset)) in ipa_cmd_register_write_valid()
314 * worst case (highest endpoint number) offset of that endpoint 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()
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()
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()
362 enum ipa_cmd_opcode opcode, u16 size, u32 offset, in ipa_cmd_table_init_add() argument
366 struct ipa *ipa = container_of(trans->gsi, struct ipa, gsi); in ipa_cmd_table_init_add()
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()
374 val = u64_encode_bits(offset, IP_FLTRT_FLAGS_NHASH_ADDR_FMASK); in ipa_cmd_table_init_add()
377 /* The hash table offset and address are zero if its size is 0 */ in ipa_cmd_table_init_add()
379 /* Record the hash table offset and size */ in ipa_cmd_table_init_add()
380 hash_offset += ipa->mem_offset; 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 */
401 void ipa_cmd_hdr_init_local_add(struct gsi_trans *trans, u32 offset, u16 size, in ipa_cmd_hdr_init_local_add() argument
404 struct ipa *ipa = container_of(trans->gsi, struct ipa, gsi); in ipa_cmd_hdr_init_local_add()
411 offset += ipa->mem_offset; 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()
423 flags |= u32_encode_bits(offset, HDR_INIT_LOCAL_FLAGS_HDR_ADDR_FMASK); in ipa_cmd_hdr_init_local_add()
424 payload->flags = cpu_to_le32(flags); in ipa_cmd_hdr_init_local_add()
430 void ipa_cmd_register_write_add(struct gsi_trans *trans, u32 offset, u32 value, in ipa_cmd_register_write_add() argument
433 struct ipa *ipa = container_of(trans->gsi, struct ipa, gsi); 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()
459 /* Extract the high 4 bits from the offset */ in ipa_cmd_register_write_add()
460 offset_high = (u16)u32_get_bits(offset, GENMASK(19, 16)); in ipa_cmd_register_write_add()
461 offset &= (1 << 16) - 1; 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()
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 */
512 void ipa_cmd_dma_shared_mem_add(struct gsi_trans *trans, u32 offset, u16 size, in ipa_cmd_dma_shared_mem_add() argument
515 struct ipa *ipa = container_of(trans->gsi, struct ipa, gsi); in ipa_cmd_dma_shared_mem_add()
522 /* size and offset must fit in 16 bit fields */ in ipa_cmd_dma_shared_mem_add()
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()
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()
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()
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()
578 /* Just transfer a zero-filled payload structure */ in ipa_cmd_transfer_add()
588 struct ipa *ipa = container_of(trans->gsi, struct ipa, gsi); in ipa_cmd_pipeline_clear_add()
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()
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()
619 wait_for_completion(&ipa->completion); in ipa_cmd_pipeline_clear_wait()
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()
642 return -EINVAL; in ipa_cmd_init()
645 return -EINVAL; in ipa_cmd_init()