blob: a9f0d22a7cf46c8fa916ee4b450312951b8e00e9 [file] [log] [blame]
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06001/*******************************************************************************
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#include <linux/list.h>
28#include <linux/errno.h>
29
30#include "i40e.h"
31#include "i40e_prototype.h"
32#include "i40e_client.h"
33
34static const char i40e_client_interface_version_str[] = I40E_CLIENT_VERSION_STR;
Mitch Williams0ef2d5a2017-01-24 10:24:00 -080035static struct i40e_client *registered_client;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -060036static LIST_HEAD(i40e_devices);
37static DEFINE_MUTEX(i40e_device_mutex);
38
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -060039static int i40e_client_virtchnl_send(struct i40e_info *ldev,
40 struct i40e_client *client,
41 u32 vf_id, u8 *msg, u16 len);
42
43static int i40e_client_setup_qvlist(struct i40e_info *ldev,
44 struct i40e_client *client,
45 struct i40e_qvlist_info *qvlist_info);
46
47static void i40e_client_request_reset(struct i40e_info *ldev,
48 struct i40e_client *client,
49 u32 reset_level);
50
51static int i40e_client_update_vsi_ctxt(struct i40e_info *ldev,
52 struct i40e_client *client,
53 bool is_vf, u32 vf_id,
54 u32 flag, u32 valid_flag);
55
56static struct i40e_ops i40e_lan_ops = {
57 .virtchnl_send = i40e_client_virtchnl_send,
58 .setup_qvlist = i40e_client_setup_qvlist,
59 .request_reset = i40e_client_request_reset,
60 .update_vsi_ctxt = i40e_client_update_vsi_ctxt,
61};
62
63/**
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -060064 * i40e_client_get_params - Get the params that can change at runtime
65 * @vsi: the VSI with the message
66 * @param: clinet param struct
67 *
68 **/
69static
70int i40e_client_get_params(struct i40e_vsi *vsi, struct i40e_params *params)
71{
72 struct i40e_dcbx_config *dcb_cfg = &vsi->back->hw.local_dcbx_config;
73 int i = 0;
74
75 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
76 u8 tc = dcb_cfg->etscfg.prioritytable[i];
77 u16 qs_handle;
78
79 /* If TC is not enabled for VSI use TC0 for UP */
80 if (!(vsi->tc_config.enabled_tc & BIT(tc)))
81 tc = 0;
82
83 qs_handle = le16_to_cpu(vsi->info.qs_handle[tc]);
84 params->qos.prio_qos[i].tc = tc;
85 params->qos.prio_qos[i].qs_handle = qs_handle;
86 if (qs_handle == I40E_AQ_VSI_QS_HANDLE_INVALID) {
87 dev_err(&vsi->back->pdev->dev, "Invalid queue set handle for TC = %d, vsi id = %d\n",
88 tc, vsi->id);
89 return -EINVAL;
90 }
91 }
92
93 params->mtu = vsi->netdev->mtu;
94 return 0;
95}
96
97/**
98 * i40e_notify_client_of_vf_msg - call the client vf message callback
99 * @vsi: the VSI with the message
100 * @vf_id: the absolute VF id that sent the message
101 * @msg: message buffer
102 * @len: length of the message
103 *
104 * If there is a client to this VSI, call the client
105 **/
106void
107i40e_notify_client_of_vf_msg(struct i40e_vsi *vsi, u32 vf_id, u8 *msg, u16 len)
108{
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800109 struct i40e_pf *pf = vsi->back;
110 struct i40e_client_instance *cdev = pf->cinst;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600111
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800112 if (!cdev || !cdev->client)
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600113 return;
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800114 if (!cdev->client->ops || !cdev->client->ops->virtchnl_receive) {
115 dev_dbg(&pf->pdev->dev,
116 "Cannot locate client instance virtual channel receive routine\n");
117 return;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600118 }
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800119 if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state)) {
120 dev_dbg(&pf->pdev->dev, "Client is not open, abort virtchnl_receive\n");
121 return;
122 }
123 cdev->client->ops->virtchnl_receive(&cdev->lan_info, cdev->client,
124 vf_id, msg, len);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600125}
126
127/**
128 * i40e_notify_client_of_l2_param_changes - call the client notify callback
129 * @vsi: the VSI with l2 param changes
130 *
131 * If there is a client to this VSI, call the client
132 **/
133void i40e_notify_client_of_l2_param_changes(struct i40e_vsi *vsi)
134{
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800135 struct i40e_pf *pf = vsi->back;
136 struct i40e_client_instance *cdev = pf->cinst;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600137 struct i40e_params params;
138
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800139 if (!cdev || !cdev->client)
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600140 return;
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800141 if (!cdev->client->ops || !cdev->client->ops->l2_param_change) {
142 dev_dbg(&vsi->back->pdev->dev,
143 "Cannot locate client instance l2_param_change routine\n");
144 return;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600145 }
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800146 if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state)) {
147 dev_dbg(&vsi->back->pdev->dev, "Client is not open, abort l2 param change\n");
148 return;
149 }
150 memcpy(&cdev->lan_info.params, &params, sizeof(struct i40e_params));
151 cdev->client->ops->l2_param_change(&cdev->lan_info, cdev->client,
152 &params);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600153}
154
155/**
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800156 * i40e_client_release_qvlist - release MSI-X vector mapping for client
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600157 * @ldev: pointer to L2 context.
158 *
159 **/
160static void i40e_client_release_qvlist(struct i40e_info *ldev)
161{
162 struct i40e_qvlist_info *qvlist_info = ldev->qvlist_info;
163 u32 i;
164
165 if (!ldev->qvlist_info)
166 return;
167
168 for (i = 0; i < qvlist_info->num_vectors; i++) {
169 struct i40e_pf *pf = ldev->pf;
170 struct i40e_qv_info *qv_info;
171 u32 reg_idx;
172
173 qv_info = &qvlist_info->qv_info[i];
174 if (!qv_info)
175 continue;
176 reg_idx = I40E_PFINT_LNKLSTN(qv_info->v_idx - 1);
177 wr32(&pf->hw, reg_idx, I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK);
178 }
179 kfree(ldev->qvlist_info);
180 ldev->qvlist_info = NULL;
181}
182
183/**
184 * i40e_notify_client_of_netdev_close - call the client close callback
185 * @vsi: the VSI with netdev closed
186 * @reset: true when close called due to a reset pending
187 *
188 * If there is a client to this netdev, call the client with close
189 **/
190void i40e_notify_client_of_netdev_close(struct i40e_vsi *vsi, bool reset)
191{
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800192 struct i40e_pf *pf = vsi->back;
193 struct i40e_client_instance *cdev = pf->cinst;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600194
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800195 if (!cdev || !cdev->client)
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600196 return;
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800197 if (!cdev->client->ops || !cdev->client->ops->close) {
198 dev_dbg(&vsi->back->pdev->dev,
199 "Cannot locate client instance close routine\n");
200 return;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600201 }
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800202 cdev->client->ops->close(&cdev->lan_info, cdev->client, reset);
203 clear_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state);
204 i40e_client_release_qvlist(&cdev->lan_info);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600205}
206
207/**
208 * i40e_notify_client_of_vf_reset - call the client vf reset callback
209 * @pf: PF device pointer
210 * @vf_id: asolute id of VF being reset
211 *
212 * If there is a client attached to this PF, notify when a VF is reset
213 **/
214void i40e_notify_client_of_vf_reset(struct i40e_pf *pf, u32 vf_id)
215{
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800216 struct i40e_client_instance *cdev = pf->cinst;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600217
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800218 if (!cdev || !cdev->client)
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600219 return;
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800220 if (!cdev->client->ops || !cdev->client->ops->vf_reset) {
221 dev_dbg(&pf->pdev->dev,
222 "Cannot locate client instance VF reset routine\n");
223 return;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600224 }
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800225 if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state)) {
226 dev_dbg(&pf->pdev->dev, "Client is not open, abort vf-reset\n");
227 return;
228 }
229 cdev->client->ops->vf_reset(&cdev->lan_info, cdev->client, vf_id);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600230}
231
232/**
233 * i40e_notify_client_of_vf_enable - call the client vf notification callback
234 * @pf: PF device pointer
235 * @num_vfs: the number of VFs currently enabled, 0 for disable
236 *
237 * If there is a client attached to this PF, call its VF notification routine
238 **/
239void i40e_notify_client_of_vf_enable(struct i40e_pf *pf, u32 num_vfs)
240{
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800241 struct i40e_client_instance *cdev = pf->cinst;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600242
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800243 if (!cdev || !cdev->client)
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600244 return;
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800245 if (!cdev->client->ops || !cdev->client->ops->vf_enable) {
246 dev_dbg(&pf->pdev->dev,
247 "Cannot locate client instance VF enable routine\n");
248 return;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600249 }
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800250 if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED,
251 &cdev->state)) {
252 dev_dbg(&pf->pdev->dev, "Client is not open, abort vf-enable\n");
253 return;
254 }
255 cdev->client->ops->vf_enable(&cdev->lan_info, cdev->client, num_vfs);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600256}
257
258/**
259 * i40e_vf_client_capable - ask the client if it likes the specified VF
260 * @pf: PF device pointer
261 * @vf_id: the VF in question
262 *
263 * If there is a client of the specified type attached to this PF, call
264 * its vf_capable routine
265 **/
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800266int i40e_vf_client_capable(struct i40e_pf *pf, u32 vf_id)
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600267{
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800268 struct i40e_client_instance *cdev = pf->cinst;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600269 int capable = false;
270
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800271 if (!cdev || !cdev->client)
272 goto out;
273 if (!cdev->client->ops || !cdev->client->ops->vf_capable) {
274 dev_info(&pf->pdev->dev,
275 "Cannot locate client instance VF capability routine\n");
276 goto out;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600277 }
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800278 if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state))
279 goto out;
280
281 capable = cdev->client->ops->vf_capable(&cdev->lan_info,
282 cdev->client,
283 vf_id);
284out:
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600285 return capable;
286}
287
288/**
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600289 * i40e_client_add_instance - add a client instance struct to the instance list
290 * @pf: pointer to the board struct
291 * @client: pointer to a client struct in the client list.
Anjali Singhai Jainf38ff2e2016-08-24 17:51:53 -0700292 * @existing: if there was already an existing instance
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600293 *
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600294 **/
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800295static void i40e_client_add_instance(struct i40e_pf *pf)
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600296{
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800297 struct i40e_client_instance *cdev = NULL;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600298 struct netdev_hw_addr *mac = NULL;
299 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
300
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800301 if (!registered_client || pf->cinst)
302 return;
303
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600304 cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
305 if (!cdev)
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800306 return;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600307
308 cdev->lan_info.pf = (void *)pf;
309 cdev->lan_info.netdev = vsi->netdev;
310 cdev->lan_info.pcidev = pf->pdev;
311 cdev->lan_info.fid = pf->hw.pf_id;
312 cdev->lan_info.ftype = I40E_CLIENT_FTYPE_PF;
313 cdev->lan_info.hw_addr = pf->hw.hw_addr;
314 cdev->lan_info.ops = &i40e_lan_ops;
315 cdev->lan_info.version.major = I40E_CLIENT_VERSION_MAJOR;
316 cdev->lan_info.version.minor = I40E_CLIENT_VERSION_MINOR;
317 cdev->lan_info.version.build = I40E_CLIENT_VERSION_BUILD;
318 cdev->lan_info.fw_maj_ver = pf->hw.aq.fw_maj_ver;
319 cdev->lan_info.fw_min_ver = pf->hw.aq.fw_min_ver;
320 cdev->lan_info.fw_build = pf->hw.aq.fw_build;
321 set_bit(__I40E_CLIENT_INSTANCE_NONE, &cdev->state);
322
323 if (i40e_client_get_params(vsi, &cdev->lan_info.params)) {
324 kfree(cdev);
325 cdev = NULL;
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800326 return;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600327 }
328
329 cdev->lan_info.msix_count = pf->num_iwarp_msix;
330 cdev->lan_info.msix_entries = &pf->msix_entries[pf->iwarp_base_vector];
331
332 mac = list_first_entry(&cdev->lan_info.netdev->dev_addrs.list,
333 struct netdev_hw_addr, list);
334 if (mac)
335 ether_addr_copy(cdev->lan_info.lanmac, mac->addr);
336 else
337 dev_err(&pf->pdev->dev, "MAC address list is empty!\n");
338
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800339 cdev->client = registered_client;
340 pf->cinst = cdev;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600341}
342
343/**
344 * i40e_client_del_instance - removes a client instance from the list
345 * @pf: pointer to the board struct
346 *
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600347 **/
348static
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800349void i40e_client_del_instance(struct i40e_pf *pf)
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600350{
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800351 kfree(pf->cinst);
352 pf->cinst = NULL;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600353}
354
355/**
356 * i40e_client_subtask - client maintenance work
357 * @pf: board private structure
358 **/
359void i40e_client_subtask(struct i40e_pf *pf)
360{
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800361 struct i40e_client *client = registered_client;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600362 struct i40e_client_instance *cdev;
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800363 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600364 int ret = 0;
365
366 if (!(pf->flags & I40E_FLAG_SERVICE_CLIENT_REQUESTED))
367 return;
368 pf->flags &= ~I40E_FLAG_SERVICE_CLIENT_REQUESTED;
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800369 cdev = pf->cinst;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600370
371 /* If we're down or resetting, just bail */
372 if (test_bit(__I40E_DOWN, &pf->state) ||
373 test_bit(__I40E_CONFIG_BUSY, &pf->state))
374 return;
375
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800376 if (!client || !cdev)
377 return;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600378
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800379 /* Here we handle client opens. If the client is down, but
380 * the netdev is up, then open the client.
381 */
382 if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state)) {
383 if (!test_bit(__I40E_DOWN, &vsi->state) &&
384 client->ops && client->ops->open) {
385 set_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state);
386 ret = client->ops->open(&cdev->lan_info, client);
387 if (ret) {
388 /* Remove failed client instance */
389 clear_bit(__I40E_CLIENT_INSTANCE_OPENED,
390 &cdev->state);
391 i40e_client_del_instance(pf);
Carolyn Wybornyc73d2e82016-09-14 16:24:31 -0700392 }
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600393 }
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800394 } else {
395 /* Likewise for client close. If the client is up, but the netdev
396 * is down, then close the client.
397 */
398 if (test_bit(__I40E_DOWN, &vsi->state) &&
399 client->ops && client->ops->close) {
400 clear_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state);
401 client->ops->close(&cdev->lan_info, client, false);
402 i40e_client_release_qvlist(&cdev->lan_info);
403 }
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600404 }
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600405}
406
407/**
408 * i40e_lan_add_device - add a lan device struct to the list of lan devices
409 * @pf: pointer to the board struct
410 *
411 * Returns 0 on success or none 0 on error
412 **/
413int i40e_lan_add_device(struct i40e_pf *pf)
414{
415 struct i40e_device *ldev;
416 int ret = 0;
417
418 mutex_lock(&i40e_device_mutex);
419 list_for_each_entry(ldev, &i40e_devices, list) {
420 if (ldev->pf == pf) {
421 ret = -EEXIST;
422 goto out;
423 }
424 }
425 ldev = kzalloc(sizeof(*ldev), GFP_KERNEL);
426 if (!ldev) {
427 ret = -ENOMEM;
428 goto out;
429 }
430 ldev->pf = pf;
431 INIT_LIST_HEAD(&ldev->list);
432 list_add(&ldev->list, &i40e_devices);
Sudheer Mogilappagarib3f028f2017-02-09 23:58:22 -0800433 dev_info(&pf->pdev->dev, "Added LAN device PF%d bus=0x%02x dev=0x%02x func=0x%02x\n",
434 pf->hw.pf_id, pf->hw.bus.bus_id,
435 pf->hw.bus.device, pf->hw.bus.func);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600436
437 /* Since in some cases register may have happened before a device gets
Anjali Singhai Jainf38ff2e2016-08-24 17:51:53 -0700438 * added, we can schedule a subtask to go initiate the clients if
439 * they can be launched at probe time.
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600440 */
441 pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED;
442 i40e_service_event_schedule(pf);
443
444out:
445 mutex_unlock(&i40e_device_mutex);
446 return ret;
447}
448
449/**
450 * i40e_lan_del_device - removes a lan device from the device list
451 * @pf: pointer to the board struct
452 *
453 * Returns 0 on success or non-0 on error
454 **/
455int i40e_lan_del_device(struct i40e_pf *pf)
456{
457 struct i40e_device *ldev, *tmp;
458 int ret = -ENODEV;
459
460 mutex_lock(&i40e_device_mutex);
461 list_for_each_entry_safe(ldev, tmp, &i40e_devices, list) {
462 if (ldev->pf == pf) {
Sudheer Mogilappagarib3f028f2017-02-09 23:58:22 -0800463 dev_info(&pf->pdev->dev, "Deleted LAN device PF%d bus=0x%02x dev=0x%02x func=0x%02x\n",
464 pf->hw.pf_id, pf->hw.bus.bus_id,
465 pf->hw.bus.device, pf->hw.bus.func);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600466 list_del(&ldev->list);
467 kfree(ldev);
468 ret = 0;
469 break;
470 }
471 }
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600472 mutex_unlock(&i40e_device_mutex);
473 return ret;
474}
475
476/**
477 * i40e_client_release - release client specific resources
478 * @client: pointer to the registered client
479 *
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600480 **/
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800481static void i40e_client_release(struct i40e_client *client)
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600482{
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800483 struct i40e_client_instance *cdev;
484 struct i40e_device *ldev;
Harshitha Ramamurthy682d11d2016-08-15 14:17:19 -0700485 struct i40e_pf *pf;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600486
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800487 mutex_lock(&i40e_device_mutex);
488 list_for_each_entry(ldev, &i40e_devices, list) {
489 pf = ldev->pf;
490 cdev = pf->cinst;
491 if (!cdev)
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600492 continue;
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800493
494 while (test_and_set_bit(__I40E_SERVICE_SCHED,
495 &pf->state))
496 usleep_range(500, 1000);
497
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600498 if (test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state)) {
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600499 if (client->ops && client->ops->close)
500 client->ops->close(&cdev->lan_info, client,
501 false);
502 i40e_client_release_qvlist(&cdev->lan_info);
503 clear_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state);
504
505 dev_warn(&pf->pdev->dev,
506 "Client %s instance for PF id %d closed\n",
507 client->name, pf->hw.pf_id);
508 }
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800509 /* delete the client instance */
510 i40e_client_del_instance(pf);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600511 dev_info(&pf->pdev->dev, "Deleted client instance of Client %s\n",
512 client->name);
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800513 clear_bit(__I40E_SERVICE_SCHED, &pf->state);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600514 }
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800515 mutex_unlock(&i40e_device_mutex);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600516}
517
518/**
519 * i40e_client_prepare - prepare client specific resources
520 * @client: pointer to the registered client
521 *
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600522 **/
Mitch Williams3bb83ba2017-02-09 23:46:50 -0800523static void i40e_client_prepare(struct i40e_client *client)
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600524{
525 struct i40e_device *ldev;
526 struct i40e_pf *pf;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600527
528 mutex_lock(&i40e_device_mutex);
529 list_for_each_entry(ldev, &i40e_devices, list) {
530 pf = ldev->pf;
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800531 i40e_client_add_instance(pf);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600532 /* Start the client subtask */
533 pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED;
534 i40e_service_event_schedule(pf);
535 }
536 mutex_unlock(&i40e_device_mutex);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600537}
538
539/**
540 * i40e_client_virtchnl_send - TBD
541 * @ldev: pointer to L2 context
542 * @client: Client pointer
543 * @vf_id: absolute VF identifier
544 * @msg: message buffer
545 * @len: length of message buffer
546 *
547 * Return 0 on success or < 0 on error
548 **/
549static int i40e_client_virtchnl_send(struct i40e_info *ldev,
550 struct i40e_client *client,
551 u32 vf_id, u8 *msg, u16 len)
552{
553 struct i40e_pf *pf = ldev->pf;
554 struct i40e_hw *hw = &pf->hw;
555 i40e_status err;
556
557 err = i40e_aq_send_msg_to_vf(hw, vf_id, I40E_VIRTCHNL_OP_IWARP,
558 0, msg, len, NULL);
559 if (err)
560 dev_err(&pf->pdev->dev, "Unable to send iWarp message to VF, error %d, aq status %d\n",
561 err, hw->aq.asq_last_status);
562
563 return err;
564}
565
566/**
567 * i40e_client_setup_qvlist
568 * @ldev: pointer to L2 context.
569 * @client: Client pointer.
570 * @qv_info: queue and vector list
571 *
572 * Return 0 on success or < 0 on error
573 **/
574static int i40e_client_setup_qvlist(struct i40e_info *ldev,
575 struct i40e_client *client,
576 struct i40e_qvlist_info *qvlist_info)
577{
578 struct i40e_pf *pf = ldev->pf;
579 struct i40e_hw *hw = &pf->hw;
580 struct i40e_qv_info *qv_info;
581 u32 v_idx, i, reg_idx, reg;
582 u32 size;
583
584 size = sizeof(struct i40e_qvlist_info) +
585 (sizeof(struct i40e_qv_info) * (qvlist_info->num_vectors - 1));
586 ldev->qvlist_info = kzalloc(size, GFP_KERNEL);
587 ldev->qvlist_info->num_vectors = qvlist_info->num_vectors;
588
589 for (i = 0; i < qvlist_info->num_vectors; i++) {
590 qv_info = &qvlist_info->qv_info[i];
591 if (!qv_info)
592 continue;
593 v_idx = qv_info->v_idx;
594
595 /* Validate vector id belongs to this client */
596 if ((v_idx >= (pf->iwarp_base_vector + pf->num_iwarp_msix)) ||
597 (v_idx < pf->iwarp_base_vector))
598 goto err;
599
600 ldev->qvlist_info->qv_info[i] = *qv_info;
601 reg_idx = I40E_PFINT_LNKLSTN(v_idx - 1);
602
603 if (qv_info->ceq_idx == I40E_QUEUE_INVALID_IDX) {
604 /* Special case - No CEQ mapped on this vector */
605 wr32(hw, reg_idx, I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK);
606 } else {
607 reg = (qv_info->ceq_idx &
608 I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
609 (I40E_QUEUE_TYPE_PE_CEQ <<
610 I40E_PFINT_LNKLSTN_FIRSTQ_TYPE_SHIFT);
611 wr32(hw, reg_idx, reg);
612
613 reg = (I40E_PFINT_CEQCTL_CAUSE_ENA_MASK |
614 (v_idx << I40E_PFINT_CEQCTL_MSIX_INDX_SHIFT) |
615 (qv_info->itr_idx <<
616 I40E_PFINT_CEQCTL_ITR_INDX_SHIFT) |
617 (I40E_QUEUE_END_OF_LIST <<
618 I40E_PFINT_CEQCTL_NEXTQ_INDX_SHIFT));
619 wr32(hw, I40E_PFINT_CEQCTL(qv_info->ceq_idx), reg);
620 }
621 if (qv_info->aeq_idx != I40E_QUEUE_INVALID_IDX) {
622 reg = (I40E_PFINT_AEQCTL_CAUSE_ENA_MASK |
623 (v_idx << I40E_PFINT_AEQCTL_MSIX_INDX_SHIFT) |
624 (qv_info->itr_idx <<
625 I40E_PFINT_AEQCTL_ITR_INDX_SHIFT));
626
627 wr32(hw, I40E_PFINT_AEQCTL, reg);
628 }
629 }
Avinash Dayanand70df9732016-07-27 12:02:36 -0700630 /* Mitigate sync problems with iwarp VF driver */
631 i40e_flush(hw);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600632 return 0;
633err:
634 kfree(ldev->qvlist_info);
635 ldev->qvlist_info = NULL;
636 return -EINVAL;
637}
638
639/**
640 * i40e_client_request_reset
641 * @ldev: pointer to L2 context.
642 * @client: Client pointer.
643 * @level: reset level
644 **/
645static void i40e_client_request_reset(struct i40e_info *ldev,
646 struct i40e_client *client,
647 u32 reset_level)
648{
649 struct i40e_pf *pf = ldev->pf;
650
651 switch (reset_level) {
652 case I40E_CLIENT_RESET_LEVEL_PF:
653 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
654 break;
655 case I40E_CLIENT_RESET_LEVEL_CORE:
656 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
657 break;
658 default:
659 dev_warn(&pf->pdev->dev,
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800660 "Client for PF id %d requested an unsupported reset: %d.\n",
661 pf->hw.pf_id, reset_level);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600662 break;
663 }
664
665 i40e_service_event_schedule(pf);
666}
667
668/**
669 * i40e_client_update_vsi_ctxt
670 * @ldev: pointer to L2 context.
671 * @client: Client pointer.
672 * @is_vf: if this for the VF
673 * @vf_id: if is_vf true this carries the vf_id
674 * @flag: Any device level setting that needs to be done for PE
675 * @valid_flag: Bits in this match up and enable changing of flag bits
676 *
677 * Return 0 on success or < 0 on error
678 **/
679static int i40e_client_update_vsi_ctxt(struct i40e_info *ldev,
680 struct i40e_client *client,
681 bool is_vf, u32 vf_id,
682 u32 flag, u32 valid_flag)
683{
684 struct i40e_pf *pf = ldev->pf;
685 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
686 struct i40e_vsi_context ctxt;
687 bool update = true;
688 i40e_status err;
689
690 /* TODO: for now do not allow setting VF's VSI setting */
691 if (is_vf)
692 return -EINVAL;
693
694 ctxt.seid = pf->main_vsi_seid;
695 ctxt.pf_num = pf->hw.pf_id;
696 err = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
697 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
698 if (err) {
699 dev_info(&pf->pdev->dev,
700 "couldn't get PF vsi config, err %s aq_err %s\n",
701 i40e_stat_str(&pf->hw, err),
702 i40e_aq_str(&pf->hw,
703 pf->hw.aq.asq_last_status));
704 return -ENOENT;
705 }
706
707 if ((valid_flag & I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE) &&
708 (flag & I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE)) {
709 ctxt.info.valid_sections =
710 cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
711 ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA;
712 } else if ((valid_flag & I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE) &&
713 !(flag & I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE)) {
714 ctxt.info.valid_sections =
715 cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
716 ctxt.info.queueing_opt_flags &= ~I40E_AQ_VSI_QUE_OPT_TCP_ENA;
717 } else {
718 update = false;
719 dev_warn(&pf->pdev->dev,
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800720 "Client for PF id %d request an unsupported Config: %x.\n",
721 pf->hw.pf_id, flag);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600722 }
723
724 if (update) {
725 err = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
726 if (err) {
727 dev_info(&pf->pdev->dev,
728 "update VSI ctxt for PE failed, err %s aq_err %s\n",
729 i40e_stat_str(&pf->hw, err),
730 i40e_aq_str(&pf->hw,
731 pf->hw.aq.asq_last_status));
732 }
733 }
734 return err;
735}
736
737/**
738 * i40e_register_client - Register a i40e client driver with the L2 driver
739 * @client: pointer to the i40e_client struct
740 *
741 * Returns 0 on success or non-0 on error
742 **/
743int i40e_register_client(struct i40e_client *client)
744{
745 int ret = 0;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600746
747 if (!client) {
748 ret = -EIO;
749 goto out;
750 }
751
752 if (strlen(client->name) == 0) {
753 pr_info("i40e: Failed to register client with no name\n");
754 ret = -EIO;
755 goto out;
756 }
757
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800758 if (registered_client) {
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600759 pr_info("i40e: Client %s has already been registered!\n",
760 client->name);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600761 ret = -EEXIST;
762 goto out;
763 }
764
765 if ((client->version.major != I40E_CLIENT_VERSION_MAJOR) ||
766 (client->version.minor != I40E_CLIENT_VERSION_MINOR)) {
767 pr_info("i40e: Failed to register client %s due to mismatched client interface version\n",
768 client->name);
769 pr_info("Client is using version: %02d.%02d.%02d while LAN driver supports %s\n",
770 client->version.major, client->version.minor,
771 client->version.build,
772 i40e_client_interface_version_str);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600773 ret = -EIO;
774 goto out;
775 }
776
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800777 registered_client = client;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600778
Mitch Williams3bb83ba2017-02-09 23:46:50 -0800779 i40e_client_prepare(client);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600780
Mitch Williams3bb83ba2017-02-09 23:46:50 -0800781 pr_info("i40e: Registered client %s\n", client->name);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600782out:
783 return ret;
784}
785EXPORT_SYMBOL(i40e_register_client);
786
787/**
788 * i40e_unregister_client - Unregister a i40e client driver with the L2 driver
789 * @client: pointer to the i40e_client struct
790 *
791 * Returns 0 on success or non-0 on error
792 **/
793int i40e_unregister_client(struct i40e_client *client)
794{
795 int ret = 0;
796
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800797 if (registered_client != client) {
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600798 pr_info("i40e: Client %s has not been registered\n",
799 client->name);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600800 ret = -ENODEV;
801 goto out;
802 }
Mitch Williams0ef2d5a2017-01-24 10:24:00 -0800803 registered_client = NULL;
804 /* When a unregister request comes through we would have to send
805 * a close for each of the client instances that were opened.
806 * client_release function is called to handle this.
807 */
808 i40e_client_release(client);
809
810 pr_info("i40e: Unregistered client %s\n", client->name);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600811out:
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600812 return ret;
813}
814EXPORT_SYMBOL(i40e_unregister_client);