1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright(c) 2013 - 2018 Intel Corporation. */
3
4 #ifndef _I40E_CLIENT_H_
5 #define _I40E_CLIENT_H_
6
7 #define I40E_CLIENT_STR_LENGTH 10
8
9 /* Client interface version should be updated anytime there is a change in the
10 * existing APIs or data structures.
11 */
12 #define I40E_CLIENT_VERSION_MAJOR 0
13 #define I40E_CLIENT_VERSION_MINOR 01
14 #define I40E_CLIENT_VERSION_BUILD 00
15 #define I40E_CLIENT_VERSION_STR \
16 __stringify(I40E_CLIENT_VERSION_MAJOR) "." \
17 __stringify(I40E_CLIENT_VERSION_MINOR) "." \
18 __stringify(I40E_CLIENT_VERSION_BUILD)
19
20 struct i40e_client_version {
21 u8 major;
22 u8 minor;
23 u8 build;
24 u8 rsvd;
25 };
26
27 enum i40e_client_state {
28 __I40E_CLIENT_NULL,
29 __I40E_CLIENT_REGISTERED
30 };
31
32 enum i40e_client_instance_state {
33 __I40E_CLIENT_INSTANCE_NONE,
34 __I40E_CLIENT_INSTANCE_OPENED,
35 };
36
37 struct i40e_ops;
38 struct i40e_client;
39
40 #define I40E_QUEUE_INVALID_IDX 0xFFFF
41
42 struct i40e_qv_info {
43 u32 v_idx; /* msix_vector */
44 u16 ceq_idx;
45 u16 aeq_idx;
46 u8 itr_idx;
47 };
48
49 struct i40e_qvlist_info {
50 u32 num_vectors;
51 struct i40e_qv_info qv_info[1];
52 };
53
54
55 /* set of LAN parameters useful for clients managed by LAN */
56
57 /* Struct to hold per priority info */
58 struct i40e_prio_qos_params {
59 u16 qs_handle; /* qs handle for prio */
60 u8 tc; /* TC mapped to prio */
61 u8 reserved;
62 };
63
64 #define I40E_CLIENT_MAX_USER_PRIORITY 8
65 /* Struct to hold Client QoS */
66 struct i40e_qos_params {
67 struct i40e_prio_qos_params prio_qos[I40E_CLIENT_MAX_USER_PRIORITY];
68 };
69
70 struct i40e_params {
71 struct i40e_qos_params qos;
72 u16 mtu;
73 };
74
75 /* Structure to hold Lan device info for a client device */
76 struct i40e_info {
77 struct i40e_client_version version;
78 u8 lanmac[6];
79 struct net_device *netdev;
80 struct pci_dev *pcidev;
81 u8 __iomem *hw_addr;
82 u8 fid; /* function id, PF id or VF id */
83 #define I40E_CLIENT_FTYPE_PF 0
84 u8 ftype; /* function type, PF or VF */
85 void *pf;
86
87 /* All L2 params that could change during the life span of the PF
88 * and needs to be communicated to the client when they change
89 */
90 struct i40e_qvlist_info *qvlist_info;
91 struct i40e_params params;
92 struct i40e_ops *ops;
93
94 u16 msix_count; /* number of msix vectors*/
95 /* Array down below will be dynamically allocated based on msix_count */
96 struct msix_entry *msix_entries;
97 u16 itr_index; /* Which ITR index the PE driver is suppose to use */
98 u16 fw_maj_ver; /* firmware major version */
99 u16 fw_min_ver; /* firmware minor version */
100 u32 fw_build; /* firmware build number */
101 };
102
103 #define I40E_CLIENT_RESET_LEVEL_PF 1
104 #define I40E_CLIENT_RESET_LEVEL_CORE 2
105 #define I40E_CLIENT_VSI_FLAG_TCP_ENABLE BIT(1)
106
107 struct i40e_ops {
108 /* setup_q_vector_list enables queues with a particular vector */
109 int (*setup_qvlist)(struct i40e_info *ldev, struct i40e_client *client,
110 struct i40e_qvlist_info *qv_info);
111
112 int (*virtchnl_send)(struct i40e_info *ldev, struct i40e_client *client,
113 u32 vf_id, u8 *msg, u16 len);
114
115 /* If the PE Engine is unresponsive, RDMA driver can request a reset.
116 * The level helps determine the level of reset being requested.
117 */
118 void (*request_reset)(struct i40e_info *ldev,
119 struct i40e_client *client, u32 level);
120
121 /* API for the RDMA driver to set certain VSI flags that control
122 * PE Engine.
123 */
124 int (*update_vsi_ctxt)(struct i40e_info *ldev,
125 struct i40e_client *client,
126 bool is_vf, u32 vf_id,
127 u32 flag, u32 valid_flag);
128 };
129
130 struct i40e_client_ops {
131 /* Should be called from register_client() or whenever PF is ready
132 * to create a specific client instance.
133 */
134 int (*open)(struct i40e_info *ldev, struct i40e_client *client);
135
136 /* Should be called when netdev is unavailable or when unregister
137 * call comes in. If the close is happenening due to a reset being
138 * triggered set the reset bit to true.
139 */
140 void (*close)(struct i40e_info *ldev, struct i40e_client *client,
141 bool reset);
142
143 /* called when some l2 managed parameters changes - mtu */
144 void (*l2_param_change)(struct i40e_info *ldev,
145 struct i40e_client *client,
146 struct i40e_params *params);
147
148 int (*virtchnl_receive)(struct i40e_info *ldev,
149 struct i40e_client *client, u32 vf_id,
150 u8 *msg, u16 len);
151
152 /* called when a VF is reset by the PF */
153 void (*vf_reset)(struct i40e_info *ldev,
154 struct i40e_client *client, u32 vf_id);
155
156 /* called when the number of VFs changes */
157 void (*vf_enable)(struct i40e_info *ldev,
158 struct i40e_client *client, u32 num_vfs);
159
160 /* returns true if VF is capable of specified offload */
161 int (*vf_capable)(struct i40e_info *ldev,
162 struct i40e_client *client, u32 vf_id);
163 };
164
165 /* Client device */
166 struct i40e_client_instance {
167 struct list_head list;
168 struct i40e_info lan_info;
169 struct i40e_client *client;
170 unsigned long state;
171 };
172
173 struct i40e_client {
174 struct list_head list; /* list of registered clients */
175 char name[I40E_CLIENT_STR_LENGTH];
176 struct i40e_client_version version;
177 unsigned long state; /* client state */
178 atomic_t ref_cnt; /* Count of all the client devices of this kind */
179 u32 flags;
180 u8 type;
181 #define I40E_CLIENT_IWARP 0
182 const struct i40e_client_ops *ops; /* client ops provided by the client */
183 };
184
i40e_client_is_registered(struct i40e_client * client)185 static inline bool i40e_client_is_registered(struct i40e_client *client)
186 {
187 return test_bit(__I40E_CLIENT_REGISTERED, &client->state);
188 }
189
190 /* used by clients */
191 int i40e_register_client(struct i40e_client *client);
192 int i40e_unregister_client(struct i40e_client *client);
193
194 #endif /* _I40E_CLIENT_H_ */
195