Linux-libre 4.14.132-gnu
[librecmc/linux-libre.git] / drivers / net / ethernet / intel / i40e / i40e_client.h
1 /*******************************************************************************
2  *
3  * Intel Ethernet Controller XL710 Family Linux Driver
4  * Copyright(c) 2013 - 2015 Intel Corporation.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms and conditions of the GNU General Public License,
8  * version 2, as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program.  If not, see <http://www.gnu.org/licenses/>.
17  *
18  * The full GNU General Public License is included in this distribution in
19  * the file called "COPYING".
20  *
21  * Contact Information:
22  * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23  * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24  *
25  ******************************************************************************/
26
27 #ifndef _I40E_CLIENT_H_
28 #define _I40E_CLIENT_H_
29
30 #define I40E_CLIENT_STR_LENGTH 10
31
32 /* Client interface version should be updated anytime there is a change in the
33  * existing APIs or data structures.
34  */
35 #define I40E_CLIENT_VERSION_MAJOR 0
36 #define I40E_CLIENT_VERSION_MINOR 01
37 #define I40E_CLIENT_VERSION_BUILD 00
38 #define I40E_CLIENT_VERSION_STR     \
39         __stringify(I40E_CLIENT_VERSION_MAJOR) "." \
40         __stringify(I40E_CLIENT_VERSION_MINOR) "." \
41         __stringify(I40E_CLIENT_VERSION_BUILD)
42
43 struct i40e_client_version {
44         u8 major;
45         u8 minor;
46         u8 build;
47         u8 rsvd;
48 };
49
50 enum i40e_client_state {
51         __I40E_CLIENT_NULL,
52         __I40E_CLIENT_REGISTERED
53 };
54
55 enum i40e_client_instance_state {
56         __I40E_CLIENT_INSTANCE_NONE,
57         __I40E_CLIENT_INSTANCE_OPENED,
58 };
59
60 struct i40e_ops;
61 struct i40e_client;
62
63 /* HW does not define a type value for AEQ; only for RX/TX and CEQ.
64  * In order for us to keep the interface simple, SW will define a
65  * unique type value for AEQ.
66  */
67 #define I40E_QUEUE_TYPE_PE_AEQ  0x80
68 #define I40E_QUEUE_INVALID_IDX  0xFFFF
69
70 struct i40e_qv_info {
71         u32 v_idx; /* msix_vector */
72         u16 ceq_idx;
73         u16 aeq_idx;
74         u8 itr_idx;
75 };
76
77 struct i40e_qvlist_info {
78         u32 num_vectors;
79         struct i40e_qv_info qv_info[1];
80 };
81
82 #define I40E_CLIENT_MSIX_ALL 0xFFFFFFFF
83
84 /* set of LAN parameters useful for clients managed by LAN */
85
86 /* Struct to hold per priority info */
87 struct i40e_prio_qos_params {
88         u16 qs_handle; /* qs handle for prio */
89         u8 tc; /* TC mapped to prio */
90         u8 reserved;
91 };
92
93 #define I40E_CLIENT_MAX_USER_PRIORITY        8
94 /* Struct to hold Client QoS */
95 struct i40e_qos_params {
96         struct i40e_prio_qos_params prio_qos[I40E_CLIENT_MAX_USER_PRIORITY];
97 };
98
99 struct i40e_params {
100         struct i40e_qos_params qos;
101         u16 mtu;
102 };
103
104 /* Structure to hold Lan device info for a client device */
105 struct i40e_info {
106         struct i40e_client_version version;
107         u8 lanmac[6];
108         struct net_device *netdev;
109         struct pci_dev *pcidev;
110         u8 __iomem *hw_addr;
111         u8 fid; /* function id, PF id or VF id */
112 #define I40E_CLIENT_FTYPE_PF 0
113 #define I40E_CLIENT_FTYPE_VF 1
114         u8 ftype; /* function type, PF or VF */
115         void *pf;
116
117         /* All L2 params that could change during the life span of the PF
118          * and needs to be communicated to the client when they change
119          */
120         struct i40e_qvlist_info *qvlist_info;
121         struct i40e_params params;
122         struct i40e_ops *ops;
123
124         u16 msix_count;  /* number of msix vectors*/
125         /* Array down below will be dynamically allocated based on msix_count */
126         struct msix_entry *msix_entries;
127         u16 itr_index; /* Which ITR index the PE driver is suppose to use */
128         u16 fw_maj_ver;                 /* firmware major version */
129         u16 fw_min_ver;                 /* firmware minor version */
130         u32 fw_build;                   /* firmware build number */
131 };
132
133 #define I40E_CLIENT_RESET_LEVEL_PF   1
134 #define I40E_CLIENT_RESET_LEVEL_CORE 2
135 #define I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE  BIT(1)
136
137 struct i40e_ops {
138         /* setup_q_vector_list enables queues with a particular vector */
139         int (*setup_qvlist)(struct i40e_info *ldev, struct i40e_client *client,
140                             struct i40e_qvlist_info *qv_info);
141
142         int (*virtchnl_send)(struct i40e_info *ldev, struct i40e_client *client,
143                              u32 vf_id, u8 *msg, u16 len);
144
145         /* If the PE Engine is unresponsive, RDMA driver can request a reset.
146          * The level helps determine the level of reset being requested.
147          */
148         void (*request_reset)(struct i40e_info *ldev,
149                               struct i40e_client *client, u32 level);
150
151         /* API for the RDMA driver to set certain VSI flags that control
152          * PE Engine.
153          */
154         int (*update_vsi_ctxt)(struct i40e_info *ldev,
155                                struct i40e_client *client,
156                                bool is_vf, u32 vf_id,
157                                u32 flag, u32 valid_flag);
158 };
159
160 struct i40e_client_ops {
161         /* Should be called from register_client() or whenever PF is ready
162          * to create a specific client instance.
163          */
164         int (*open)(struct i40e_info *ldev, struct i40e_client *client);
165
166         /* Should be called when netdev is unavailable or when unregister
167          * call comes in. If the close is happenening due to a reset being
168          * triggered set the reset bit to true.
169          */
170         void (*close)(struct i40e_info *ldev, struct i40e_client *client,
171                       bool reset);
172
173         /* called when some l2 managed parameters changes - mtu */
174         void (*l2_param_change)(struct i40e_info *ldev,
175                                 struct i40e_client *client,
176                                 struct i40e_params *params);
177
178         int (*virtchnl_receive)(struct i40e_info *ldev,
179                                 struct i40e_client *client, u32 vf_id,
180                                 u8 *msg, u16 len);
181
182         /* called when a VF is reset by the PF */
183         void (*vf_reset)(struct i40e_info *ldev,
184                          struct i40e_client *client, u32 vf_id);
185
186         /* called when the number of VFs changes */
187         void (*vf_enable)(struct i40e_info *ldev,
188                           struct i40e_client *client, u32 num_vfs);
189
190         /* returns true if VF is capable of specified offload */
191         int (*vf_capable)(struct i40e_info *ldev,
192                           struct i40e_client *client, u32 vf_id);
193 };
194
195 /* Client device */
196 struct i40e_client_instance {
197         struct list_head list;
198         struct i40e_info lan_info;
199         struct i40e_client *client;
200         unsigned long  state;
201 };
202
203 struct i40e_client {
204         struct list_head list;          /* list of registered clients */
205         char name[I40E_CLIENT_STR_LENGTH];
206         struct i40e_client_version version;
207         unsigned long state;            /* client state */
208         atomic_t ref_cnt;  /* Count of all the client devices of this kind */
209         u32 flags;
210 #define I40E_CLIENT_FLAGS_LAUNCH_ON_PROBE       BIT(0)
211 #define I40E_TX_FLAGS_NOTIFY_OTHER_EVENTS       BIT(2)
212         u8 type;
213 #define I40E_CLIENT_IWARP 0
214         const struct i40e_client_ops *ops; /* client ops provided by the client */
215 };
216
217 static inline bool i40e_client_is_registered(struct i40e_client *client)
218 {
219         return test_bit(__I40E_CLIENT_REGISTERED, &client->state);
220 }
221
222 /* used by clients */
223 int i40e_register_client(struct i40e_client *client);
224 int i40e_unregister_client(struct i40e_client *client);
225
226 #endif /* _I40E_CLIENT_H_ */