1 /* SPDX-License-Identifier: GPL-2.0 */ 2 3 /* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved. 4 * Copyright (C) 2019-2020 Linaro Ltd. 5 */ 6 #ifndef _IPA_ENDPOINT_H_ 7 #define _IPA_ENDPOINT_H_ 8 9 #include <linux/types.h> 10 #include <linux/workqueue.h> 11 #include <linux/if_ether.h> 12 13 #include "gsi.h" 14 #include "ipa_reg.h" 15 16 struct net_device; 17 struct sk_buff; 18 19 struct ipa; 20 struct ipa_gsi_endpoint_data; 21 22 /* Non-zero granularity of counter used to implement aggregation timeout */ 23 #define IPA_AGGR_GRANULARITY 500 /* microseconds */ 24 25 #define IPA_MTU ETH_DATA_LEN 26 27 enum ipa_endpoint_name { 28 IPA_ENDPOINT_AP_COMMAND_TX, 29 IPA_ENDPOINT_AP_LAN_RX, 30 IPA_ENDPOINT_AP_MODEM_TX, 31 IPA_ENDPOINT_AP_MODEM_RX, 32 IPA_ENDPOINT_MODEM_COMMAND_TX, 33 IPA_ENDPOINT_MODEM_LAN_TX, 34 IPA_ENDPOINT_MODEM_LAN_RX, 35 IPA_ENDPOINT_MODEM_AP_TX, 36 IPA_ENDPOINT_MODEM_AP_RX, 37 IPA_ENDPOINT_MODEM_DL_NLO_TX, 38 IPA_ENDPOINT_COUNT, /* Number of names (not an index) */ 39 }; 40 41 #define IPA_ENDPOINT_MAX 32 /* Max supported by driver */ 42 43 /** 44 * struct ipa_endpoint_tx - Endpoint configuration for TX endpoints 45 * @seq_type: primary packet processing sequencer type 46 * @seq_rep_type: sequencer type for replication processing 47 * @status_endpoint: endpoint to which status elements are sent 48 * 49 * The @status_endpoint is only valid if the endpoint's @status_enable 50 * flag is set. 51 */ 52 struct ipa_endpoint_tx { 53 enum ipa_seq_type seq_type; 54 enum ipa_seq_rep_type seq_rep_type; 55 enum ipa_endpoint_name status_endpoint; 56 }; 57 58 /** 59 * struct ipa_endpoint_rx - Endpoint configuration for RX endpoints 60 * @buffer_size: requested receive buffer size (bytes) 61 * @pad_align: power-of-2 boundary to which packet payload is aligned 62 * @aggr_close_eof: whether aggregation closes on end-of-frame 63 * @holb_drop: whether to drop packets to avoid head-of-line blocking 64 * 65 * With each packet it transfers, the IPA hardware can perform certain 66 * transformations of its packet data. One of these is adding pad bytes 67 * to the end of the packet data so the result ends on a power-of-2 boundary. 68 * 69 * It is also able to aggregate multiple packets into a single receive buffer. 70 * Aggregation is "open" while a buffer is being filled, and "closes" when 71 * certain criteria are met. One of those criteria is the sender indicating 72 * a "frame" consisting of several transfers has ended. 73 */ 74 struct ipa_endpoint_rx { 75 u32 buffer_size; 76 u32 pad_align; 77 bool aggr_close_eof; 78 bool holb_drop; 79 }; 80 81 /** 82 * struct ipa_endpoint_config - IPA endpoint hardware configuration 83 * @resource_group: resource group to assign endpoint to 84 * @checksum: whether checksum offload is enabled 85 * @qmap: whether endpoint uses QMAP protocol 86 * @aggregation: whether endpoint supports aggregation 87 * @status_enable: whether endpoint uses status elements 88 * @dma_mode: whether endpoint operates in DMA mode 89 * @dma_endpoint: peer endpoint, if operating in DMA mode 90 * @tx: TX-specific endpoint information (see above) 91 * @rx: RX-specific endpoint information (see above) 92 */ 93 struct ipa_endpoint_config { 94 u32 resource_group; 95 bool checksum; 96 bool qmap; 97 bool aggregation; 98 bool status_enable; 99 bool dma_mode; 100 enum ipa_endpoint_name dma_endpoint; 101 union { 102 struct ipa_endpoint_tx tx; 103 struct ipa_endpoint_rx rx; 104 }; 105 }; 106 107 /** 108 * enum ipa_replenish_flag: RX buffer replenish flags 109 * 110 * @IPA_REPLENISH_ENABLED: Whether receive buffer replenishing is enabled 111 * @IPA_REPLENISH_ACTIVE: Whether replenishing is underway 112 * @IPA_REPLENISH_COUNT: Number of defined replenish flags 113 */ 114 enum ipa_replenish_flag { 115 IPA_REPLENISH_ENABLED, 116 IPA_REPLENISH_ACTIVE, 117 IPA_REPLENISH_COUNT, /* Number of flags (must be last) */ 118 }; 119 120 /** 121 * struct ipa_endpoint - IPA endpoint information 122 * @ipa: IPA pointer 123 * @ee_id: Execution environmnent endpoint is associated with 124 * @channel_id: GSI channel used by the endpoint 125 * @endpoint_id: IPA endpoint number 126 * @toward_ipa: Endpoint direction (true = TX, false = RX) 127 * @config: Default endpoint configuration 128 * @trans_tre_max: Maximum number of TRE descriptors per transaction 129 * @evt_ring_id: GSI event ring used by the endpoint 130 * @netdev: Network device pointer, if endpoint uses one 131 * @replenish_flags: Replenishing state flags 132 * @replenish_count: Total number of replenish transactions committed 133 * @replenish_work: Work item used for repeated replenish failures 134 */ 135 struct ipa_endpoint { 136 struct ipa *ipa; 137 enum gsi_ee_id ee_id; 138 u32 channel_id; 139 u32 endpoint_id; 140 bool toward_ipa; 141 struct ipa_endpoint_config config; 142 143 u32 trans_tre_max; 144 u32 evt_ring_id; 145 146 /* Net device this endpoint is associated with, if any */ 147 struct net_device *netdev; 148 149 /* Receive buffer replenishing for RX endpoints */ 150 DECLARE_BITMAP(replenish_flags, IPA_REPLENISH_COUNT); 151 u64 replenish_count; 152 struct delayed_work replenish_work; /* global wq */ 153 }; 154 155 void ipa_endpoint_modem_hol_block_clear_all(struct ipa *ipa); 156 157 void ipa_endpoint_modem_pause_all(struct ipa *ipa, bool enable); 158 159 int ipa_endpoint_modem_exception_reset_all(struct ipa *ipa); 160 161 int ipa_endpoint_skb_tx(struct ipa_endpoint *endpoint, struct sk_buff *skb); 162 163 int ipa_endpoint_enable_one(struct ipa_endpoint *endpoint); 164 void ipa_endpoint_disable_one(struct ipa_endpoint *endpoint); 165 166 void ipa_endpoint_suspend_one(struct ipa_endpoint *endpoint); 167 void ipa_endpoint_resume_one(struct ipa_endpoint *endpoint); 168 169 void ipa_endpoint_suspend(struct ipa *ipa); 170 void ipa_endpoint_resume(struct ipa *ipa); 171 172 void ipa_endpoint_setup(struct ipa *ipa); 173 void ipa_endpoint_teardown(struct ipa *ipa); 174 175 int ipa_endpoint_config(struct ipa *ipa); 176 void ipa_endpoint_deconfig(struct ipa *ipa); 177 178 void ipa_endpoint_default_route_set(struct ipa *ipa, u32 endpoint_id); 179 void ipa_endpoint_default_route_clear(struct ipa *ipa); 180 181 u32 ipa_endpoint_init(struct ipa *ipa, u32 count, 182 const struct ipa_gsi_endpoint_data *data); 183 void ipa_endpoint_exit(struct ipa *ipa); 184 185 void ipa_endpoint_trans_complete(struct ipa_endpoint *ipa, 186 struct gsi_trans *trans); 187 void ipa_endpoint_trans_release(struct ipa_endpoint *ipa, 188 struct gsi_trans *trans); 189 190 #endif /* _IPA_ENDPOINT_H_ */ 191