xref: /openbmc/linux/drivers/net/ipa/ipa_endpoint.h (revision e7f127b2)
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  * enum ipa_replenish_flag:	RX buffer replenish flags
45  *
46  * @IPA_REPLENISH_ENABLED:	Whether receive buffer replenishing is enabled
47  * @IPA_REPLENISH_ACTIVE:	Whether replenishing is underway
48  * @IPA_REPLENISH_COUNT:	Number of defined replenish flags
49  */
50 enum ipa_replenish_flag {
51 	IPA_REPLENISH_ENABLED,
52 	IPA_REPLENISH_ACTIVE,
53 	IPA_REPLENISH_COUNT,	/* Number of flags (must be last) */
54 };
55 
56 /**
57  * struct ipa_endpoint - IPA endpoint information
58  * @ipa:		IPA pointer
59  * @ee_id:		Execution environmnent endpoint is associated with
60  * @channel_id:		GSI channel used by the endpoint
61  * @endpoint_id:	IPA endpoint number
62  * @toward_ipa:		Endpoint direction (true = TX, false = RX)
63  * @data:		Endpoint configuration data
64  * @trans_tre_max:	Maximum number of TRE descriptors per transaction
65  * @evt_ring_id:	GSI event ring used by the endpoint
66  * @netdev:		Network device pointer, if endpoint uses one
67  * @replenish_flags:	Replenishing state flags
68  * @replenish_ready:	Number of replenish transactions without doorbell
69  * @replenish_saved:	Replenish requests held while disabled
70  * @replenish_backlog:	Number of buffers needed to fill hardware queue
71  * @replenish_work:	Work item used for repeated replenish failures
72  */
73 struct ipa_endpoint {
74 	struct ipa *ipa;
75 	enum gsi_ee_id ee_id;
76 	u32 channel_id;
77 	u32 endpoint_id;
78 	bool toward_ipa;
79 	const struct ipa_endpoint_config_data *data;
80 
81 	u32 trans_tre_max;
82 	u32 evt_ring_id;
83 
84 	/* Net device this endpoint is associated with, if any */
85 	struct net_device *netdev;
86 
87 	/* Receive buffer replenishing for RX endpoints */
88 	DECLARE_BITMAP(replenish_flags, IPA_REPLENISH_COUNT);
89 	u32 replenish_ready;
90 	atomic_t replenish_saved;
91 	atomic_t replenish_backlog;
92 	struct delayed_work replenish_work;		/* global wq */
93 };
94 
95 void ipa_endpoint_modem_hol_block_clear_all(struct ipa *ipa);
96 
97 void ipa_endpoint_modem_pause_all(struct ipa *ipa, bool enable);
98 
99 int ipa_endpoint_modem_exception_reset_all(struct ipa *ipa);
100 
101 int ipa_endpoint_skb_tx(struct ipa_endpoint *endpoint, struct sk_buff *skb);
102 
103 int ipa_endpoint_enable_one(struct ipa_endpoint *endpoint);
104 void ipa_endpoint_disable_one(struct ipa_endpoint *endpoint);
105 
106 void ipa_endpoint_suspend_one(struct ipa_endpoint *endpoint);
107 void ipa_endpoint_resume_one(struct ipa_endpoint *endpoint);
108 
109 void ipa_endpoint_suspend(struct ipa *ipa);
110 void ipa_endpoint_resume(struct ipa *ipa);
111 
112 void ipa_endpoint_setup(struct ipa *ipa);
113 void ipa_endpoint_teardown(struct ipa *ipa);
114 
115 int ipa_endpoint_config(struct ipa *ipa);
116 void ipa_endpoint_deconfig(struct ipa *ipa);
117 
118 void ipa_endpoint_default_route_set(struct ipa *ipa, u32 endpoint_id);
119 void ipa_endpoint_default_route_clear(struct ipa *ipa);
120 
121 u32 ipa_endpoint_init(struct ipa *ipa, u32 count,
122 		      const struct ipa_gsi_endpoint_data *data);
123 void ipa_endpoint_exit(struct ipa *ipa);
124 
125 void ipa_endpoint_trans_complete(struct ipa_endpoint *ipa,
126 				 struct gsi_trans *trans);
127 void ipa_endpoint_trans_release(struct ipa_endpoint *ipa,
128 				struct gsi_trans *trans);
129 
130 #endif /* _IPA_ENDPOINT_H_ */
131