2020-03-05 22:28:25 -06:00
/* SPDX-License-Identifier: GPL-2.0 */
/* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
2022-09-30 17:45:49 -05:00
* Copyright ( C ) 2019 - 2022 Linaro Ltd .
2020-03-05 22:28:25 -06:00
*/
# ifndef _IPA_TABLE_H_
# define _IPA_TABLE_H_
# include <linux/types.h>
struct ipa ;
/* The maximum number of filter table entries (IPv4, IPv6; hashed or not) */
# define IPA_FILTER_COUNT_MAX 14
net: ipa: properly limit modem routing table use
IPA can route packets between IPA-connected entities. The AP and
modem are currently the only such entities supported, and no routing
is required to transfer packets between them.
The number of entries in each routing table is fixed, and defined at
initialization time. Some of these entries are designated for use
by the modem, and the rest are available for the AP to use. The AP
sends a QMI message to the modem which describes (among other
things) information about routing table memory available for the
modem to use.
Currently the QMI initialization packet gives wrong information in
its description of routing tables. What *should* be supplied is the
maximum index that the modem can use for the routing table memory
located at a given location. The current code instead supplies the
total *number* of routing table entries. Furthermore, the modem is
granted the entire table, not just the subset it's supposed to use.
This patch fixes this. First, the ipa_mem_bounds structure is
generalized so its "end" field can be interpreted either as a final
byte offset, or a final array index. Second, the IPv4 and IPv6
(non-hashed and hashed) table information fields in the QMI
ipa_init_modem_driver_req structure are changed to be ipa_mem_bounds
rather than ipa_mem_array structures. Third, we set the "end" value
for each routing table to be the last index, rather than setting the
"count" to be the number of indices. Finally, instead of allowing
the modem to use all of a routing table's memory, it is limited to
just the portion meant to be used by the modem. In all versions of
IPA currently supported, that is IPA_ROUTE_MODEM_COUNT (8) entries.
Update a few comments for clarity.
Fixes: 530f9216a9537 ("soc: qcom: ipa: AP/modem communications")
Signed-off-by: Alex Elder <elder@linaro.org>
Link: https://lore.kernel.org/r/20220913204602.1803004-1-elder@linaro.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2022-09-13 15:46:02 -05:00
/* The number of route table entries allotted to the modem */
# define IPA_ROUTE_MODEM_COUNT 8
2020-03-05 22:28:25 -06:00
/* The maximum number of route table entries (IPv4, IPv6; hashed or not) */
# define IPA_ROUTE_COUNT_MAX 15
/**
* ipa_table_valid ( ) - Validate route and filter table memory regions
* @ ipa : IPA pointer
2021-03-28 12:31:05 -05:00
*
2020-07-13 07:24:18 -05:00
* Return : true if all regions are valid , false otherwise
2020-03-05 22:28:25 -06:00
*/
bool ipa_table_valid ( struct ipa * ipa ) ;
/**
* ipa_filter_map_valid ( ) - Validate a filter table endpoint bitmap
* @ ipa : IPA pointer
2021-03-28 12:31:05 -05:00
* @ filter_mask : Filter table endpoint bitmap to check
2020-03-05 22:28:25 -06:00
*
2020-07-13 07:24:18 -05:00
* Return : true if all regions are valid , false otherwise
2020-03-05 22:28:25 -06:00
*/
bool ipa_filter_map_valid ( struct ipa * ipa , u32 filter_mask ) ;
2021-02-12 08:34:01 -06:00
/**
* ipa_table_hash_support ( ) - Return true if hashed tables are supported
* @ ipa : IPA pointer
*/
2021-03-15 10:01:18 -05:00
static inline bool ipa_table_hash_support ( struct ipa * ipa )
{
return ipa - > version ! = IPA_VERSION_4_2 ;
}
2021-02-12 08:34:01 -06:00
2020-03-05 22:28:25 -06:00
/**
* ipa_table_reset ( ) - Reset filter and route tables entries to " none "
* @ ipa : IPA pointer
* @ modem : Whether to reset modem or AP entries
*/
void ipa_table_reset ( struct ipa * ipa , bool modem ) ;
/**
* ipa_table_hash_flush ( ) - Synchronize hashed filter and route updates
* @ ipa : IPA pointer
*/
int ipa_table_hash_flush ( struct ipa * ipa ) ;
/**
* ipa_table_setup ( ) - Set up filter and route tables
* @ ipa : IPA pointer
2021-04-09 13:07:20 -05:00
*
* There is no need for a matching ipa_table_teardown ( ) function .
2020-03-05 22:28:25 -06:00
*/
int ipa_table_setup ( struct ipa * ipa ) ;
/**
* ipa_table_config ( ) - Configure filter and route tables
* @ ipa : IPA pointer
2021-04-09 13:07:20 -05:00
*
* There is no need for a matching ipa_table_deconfig ( ) function .
2020-03-05 22:28:25 -06:00
*/
void ipa_table_config ( struct ipa * ipa ) ;
/**
* ipa_table_init ( ) - Do early initialization of filter and route tables
* @ ipa : IPA pointer
*/
int ipa_table_init ( struct ipa * ipa ) ;
/**
* ipa_table_exit ( ) - Inverse of ipa_table_init ( )
* @ ipa : IPA pointer
*/
void ipa_table_exit ( struct ipa * ipa ) ;
# endif /* _IPA_TABLE_H_ */