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-2022 Linaro Ltd.
11 #include <linux/dma-direction.h>
30 * has a well-defined format, having a payload of a known length. This
79 __le16 offset; member
150 * might not be used, non-hashed and hashed tables have the same in ipa_cmd_validate_build()
162 /* Hashed and non-hashed fields are assumed to be the same size */ in ipa_cmd_validate_build()
170 IPA_ENDPOINT_MAX - 1); in ipa_cmd_validate_build()
179 struct device *dev = &ipa->pdev->dev; in ipa_cmd_table_valid()
182 if (mem->size > size_max) { in ipa_cmd_table_valid()
184 dev_err(dev, " (0x%04x > 0x%04x)\n", in ipa_cmd_table_valid()
185 mem->size, size_max); in ipa_cmd_table_valid()
190 /* Offset must fit in the immediate command field that holds it */ in ipa_cmd_table_valid()
191 if (mem->offset > offset_max || in ipa_cmd_table_valid()
192 ipa->mem_offset > offset_max - mem->offset) { in ipa_cmd_table_valid()
193 dev_err(dev, "%s table region offset too large\n", table); in ipa_cmd_table_valid()
194 dev_err(dev, " (0x%04x + 0x%04x > 0x%04x)\n", in ipa_cmd_table_valid()
195 ipa->mem_offset, mem->offset, offset_max); in ipa_cmd_table_valid()
200 /* Entire memory range must fit within IPA-local memory */ in ipa_cmd_table_valid()
201 if (mem->offset > ipa->mem_size || in ipa_cmd_table_valid()
202 mem->size > ipa->mem_size - mem->offset) { in ipa_cmd_table_valid()
204 dev_err(dev, " (0x%04x + 0x%04x > 0x%04x)\n", in ipa_cmd_table_valid()
205 mem->offset, mem->size, ipa->mem_size); in ipa_cmd_table_valid()
216 struct device *dev = &ipa->pdev->dev; in ipa_cmd_header_valid()
220 u32 offset; in ipa_cmd_header_valid() local
223 /* In ipa_cmd_hdr_init_local_add() we record the offset and size of in ipa_cmd_header_valid()
225 * the offset and size fit in the fields that need to hold them, and in ipa_cmd_header_valid()
235 offset = mem->offset; in ipa_cmd_header_valid()
236 size = mem->size; in ipa_cmd_header_valid()
238 /* Make sure the offset fits in the IPA command */ in ipa_cmd_header_valid()
239 if (offset > offset_max || ipa->mem_offset > offset_max - offset) { in ipa_cmd_header_valid()
240 dev_err(dev, "header table region offset too large\n"); in ipa_cmd_header_valid()
241 dev_err(dev, " (0x%04x + 0x%04x > 0x%04x)\n", in ipa_cmd_header_valid()
242 ipa->mem_offset, offset, offset_max); in ipa_cmd_header_valid()
250 size += mem->size; in ipa_cmd_header_valid()
255 dev_err(dev, " (0x%04x > 0x%08x)\n", size, size_max); in ipa_cmd_header_valid()
261 if (size > ipa->mem_size || offset > ipa->mem_size - size) { in ipa_cmd_header_valid()
263 dev_err(dev, " (0x%04x + 0x%04x > 0x%04x)\n", in ipa_cmd_header_valid()
264 offset, size, ipa->mem_size); in ipa_cmd_header_valid()
272 /* Indicate whether an offset can be used with a register_write command */
274 const char *name, u32 offset) in ipa_cmd_register_write_offset_valid() argument
277 struct device *dev = &ipa->pdev->dev; in ipa_cmd_register_write_offset_valid()
281 /* The maximum offset in a register_write immediate command depends in ipa_cmd_register_write_offset_valid()
282 * on the version of IPA. A 16 bit offset is always supported, in ipa_cmd_register_write_offset_valid()
283 * but starting with IPA v4.0 some additional high-order bits are in ipa_cmd_register_write_offset_valid()
286 bit_count = BITS_PER_BYTE * sizeof(payload->offset); in ipa_cmd_register_write_offset_valid()
287 if (ipa->version >= IPA_VERSION_4_0) in ipa_cmd_register_write_offset_valid()
290 offset_max = ~0U >> (32 - bit_count); in ipa_cmd_register_write_offset_valid()
292 /* Make sure the offset can be represented by the field(s) in ipa_cmd_register_write_offset_valid()
293 * that holds it. Also make sure the offset is not outside in ipa_cmd_register_write_offset_valid()
296 if (offset > offset_max || ipa->mem_offset > offset_max - offset) { in ipa_cmd_register_write_offset_valid()
297 dev_err(dev, "%s offset too large 0x%04x + 0x%04x > 0x%04x)\n", in ipa_cmd_register_write_offset_valid()
298 name, ipa->mem_offset, offset, offset_max); in ipa_cmd_register_write_offset_valid()
310 u32 offset; in ipa_cmd_register_write_valid() local
313 * offset will fit in a register write IPA immediate command. in ipa_cmd_register_write_valid()
317 offset = ipa_reg_offset(reg); in ipa_cmd_register_write_valid()
319 if (!ipa_cmd_register_write_offset_valid(ipa, name, offset)) in ipa_cmd_register_write_valid()
327 * worst case (highest endpoint number) offset of that endpoint in ipa_cmd_register_write_valid()
331 offset = ipa_reg_n_offset(reg, IPA_ENDPOINT_COUNT - 1); in ipa_cmd_register_write_valid()
333 if (!ipa_cmd_register_write_offset_valid(ipa, name, offset)) in ipa_cmd_register_write_valid()
353 struct gsi_trans_info *trans_info = &channel->trans_info; in ipa_cmd_pool_init()
354 struct device *dev = channel->gsi->dev; in ipa_cmd_pool_init()
363 return gsi_trans_pool_init_dma(dev, &trans_info->cmd_pool, in ipa_cmd_pool_init()
365 tre_max, channel->trans_tre_max); in ipa_cmd_pool_init()
370 struct gsi_trans_info *trans_info = &channel->trans_info; in ipa_cmd_pool_exit()
371 struct device *dev = channel->gsi->dev; in ipa_cmd_pool_exit()
373 gsi_trans_pool_exit_dma(dev, &trans_info->cmd_pool); in ipa_cmd_pool_exit()
382 endpoint = ipa->name_map[IPA_ENDPOINT_AP_COMMAND_TX]; in ipa_cmd_payload_alloc()
383 trans_info = &ipa->gsi.channel[endpoint->channel_id].trans_info; in ipa_cmd_payload_alloc()
385 return gsi_trans_pool_alloc_dma(&trans_info->cmd_pool, addr); in ipa_cmd_payload_alloc()
390 enum ipa_cmd_opcode opcode, u16 size, u32 offset, in ipa_cmd_table_init_add() argument
394 struct ipa *ipa = container_of(trans->gsi, struct ipa, gsi); in ipa_cmd_table_init_add()
400 /* Record the non-hash table offset and size */ in ipa_cmd_table_init_add()
401 offset += ipa->mem_offset; in ipa_cmd_table_init_add()
402 val = u64_encode_bits(offset, IP_FLTRT_FLAGS_NHASH_ADDR_FMASK); in ipa_cmd_table_init_add()
405 /* The hash table offset and address are zero if its size is 0 */ in ipa_cmd_table_init_add()
407 /* Record the hash table offset and size */ in ipa_cmd_table_init_add()
408 hash_offset += ipa->mem_offset; in ipa_cmd_table_init_add()
416 payload = &cmd_payload->table_init; in ipa_cmd_table_init_add()
418 /* Fill in all offsets and sizes and the non-hash table address */ in ipa_cmd_table_init_add()
420 payload->hash_rules_addr = cpu_to_le64(hash_addr); in ipa_cmd_table_init_add()
421 payload->flags = cpu_to_le64(val); in ipa_cmd_table_init_add()
422 payload->nhash_rules_addr = cpu_to_le64(addr); in ipa_cmd_table_init_add()
428 /* Initialize header space in IPA-local memory */
429 void ipa_cmd_hdr_init_local_add(struct gsi_trans *trans, u32 offset, u16 size, in ipa_cmd_hdr_init_local_add() argument
432 struct ipa *ipa = container_of(trans->gsi, struct ipa, gsi); in ipa_cmd_hdr_init_local_add()
439 offset += ipa->mem_offset; in ipa_cmd_hdr_init_local_add()
447 payload = &cmd_payload->hdr_init_local; in ipa_cmd_hdr_init_local_add()
449 payload->hdr_table_addr = cpu_to_le64(addr); in ipa_cmd_hdr_init_local_add()
451 flags |= u32_encode_bits(offset, HDR_INIT_LOCAL_FLAGS_HDR_ADDR_FMASK); in ipa_cmd_hdr_init_local_add()
452 payload->flags = cpu_to_le32(flags); in ipa_cmd_hdr_init_local_add()
458 void ipa_cmd_register_write_add(struct gsi_trans *trans, u32 offset, u32 value, in ipa_cmd_register_write_add() argument
461 struct ipa *ipa = container_of(trans->gsi, struct ipa, gsi); in ipa_cmd_register_write_add()
474 * also supports a larger offset by encoding additional high-order in ipa_cmd_register_write_add()
477 if (ipa->version >= IPA_VERSION_4_0) { in ipa_cmd_register_write_add()
487 /* Extract the high 4 bits from the offset */ in ipa_cmd_register_write_add()
488 offset_high = (u16)u32_get_bits(offset, GENMASK(19, 16)); in ipa_cmd_register_write_add()
489 offset &= (1 << 16) - 1; in ipa_cmd_register_write_add()
503 payload = &cmd_payload->register_write; in ipa_cmd_register_write_add()
505 payload->flags = cpu_to_le16(flags); in ipa_cmd_register_write_add()
506 payload->offset = cpu_to_le16((u16)offset); in ipa_cmd_register_write_add()
507 payload->value = cpu_to_le32(value); in ipa_cmd_register_write_add()
508 payload->value_mask = cpu_to_le32(mask); in ipa_cmd_register_write_add()
509 payload->clear_options = cpu_to_le32(options); in ipa_cmd_register_write_add()
518 struct ipa *ipa = container_of(trans->gsi, struct ipa, gsi); in ipa_cmd_ip_packet_init_add()
525 payload = &cmd_payload->ip_packet_init; in ipa_cmd_ip_packet_init_add()
527 payload->dest_endpoint = u8_encode_bits(endpoint_id, in ipa_cmd_ip_packet_init_add()
534 /* Use a DMA command to read or write a block of IPA-resident memory */
535 void ipa_cmd_dma_shared_mem_add(struct gsi_trans *trans, u32 offset, u16 size, in ipa_cmd_dma_shared_mem_add() argument
538 struct ipa *ipa = container_of(trans->gsi, struct ipa, gsi); in ipa_cmd_dma_shared_mem_add()
545 /* size and offset must fit in 16 bit fields */ in ipa_cmd_dma_shared_mem_add()
548 WARN_ON(offset > U16_MAX || ipa->mem_offset > U16_MAX - offset); in ipa_cmd_dma_shared_mem_add()
550 offset += ipa->mem_offset; in ipa_cmd_dma_shared_mem_add()
553 payload = &cmd_payload->dma_shared_mem; in ipa_cmd_dma_shared_mem_add()
555 /* payload->clear_after_read was reserved prior to IPA v4.0. It's in ipa_cmd_dma_shared_mem_add()
558 payload->size = cpu_to_le16(size); in ipa_cmd_dma_shared_mem_add()
559 payload->local_addr = cpu_to_le16(offset); in ipa_cmd_dma_shared_mem_add()
560 /* payload->flags: in ipa_cmd_dma_shared_mem_add()
569 payload->flags = cpu_to_le16(flags); in ipa_cmd_dma_shared_mem_add()
570 payload->system_addr = cpu_to_le64(addr); in ipa_cmd_dma_shared_mem_add()
578 struct ipa *ipa = container_of(trans->gsi, struct ipa, gsi); in ipa_cmd_ip_tag_status_add()
585 payload = &cmd_payload->ip_packet_tag_status; in ipa_cmd_ip_tag_status_add()
587 payload->tag = le64_encode_bits(0, IP_PACKET_TAG_STATUS_TAG_FMASK); in ipa_cmd_ip_tag_status_add()
596 struct ipa *ipa = container_of(trans->gsi, struct ipa, gsi); in ipa_cmd_transfer_add()
601 /* Just transfer a zero-filled payload structure */ in ipa_cmd_transfer_add()
611 struct ipa *ipa = container_of(trans->gsi, struct ipa, gsi); in ipa_cmd_pipeline_clear_add()
615 reinit_completion(&ipa->completion); in ipa_cmd_pipeline_clear_add()
617 /* Issue a no-op register write command (mask 0 means no write) */ in ipa_cmd_pipeline_clear_add()
628 endpoint = ipa->name_map[IPA_ENDPOINT_AP_LAN_RX]; in ipa_cmd_pipeline_clear_add()
629 ipa_cmd_ip_packet_init_add(trans, endpoint->endpoint_id); in ipa_cmd_pipeline_clear_add()
642 wait_for_completion(&ipa->completion); in ipa_cmd_pipeline_clear_wait()
653 endpoint = ipa->name_map[IPA_ENDPOINT_AP_COMMAND_TX]; in ipa_cmd_trans_alloc()
655 return gsi_channel_trans_alloc(&ipa->gsi, endpoint->channel_id, in ipa_cmd_trans_alloc()