blob: 233627e84751f1ac0d1a60f86b60b52f08eee0c6 [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;
35
36static LIST_HEAD(i40e_devices);
37static DEFINE_MUTEX(i40e_device_mutex);
38
39static LIST_HEAD(i40e_clients);
40static DEFINE_MUTEX(i40e_client_mutex);
41
42static LIST_HEAD(i40e_client_instances);
43static DEFINE_MUTEX(i40e_client_instance_mutex);
44
45static int i40e_client_virtchnl_send(struct i40e_info *ldev,
46 struct i40e_client *client,
47 u32 vf_id, u8 *msg, u16 len);
48
49static int i40e_client_setup_qvlist(struct i40e_info *ldev,
50 struct i40e_client *client,
51 struct i40e_qvlist_info *qvlist_info);
52
53static void i40e_client_request_reset(struct i40e_info *ldev,
54 struct i40e_client *client,
55 u32 reset_level);
56
57static int i40e_client_update_vsi_ctxt(struct i40e_info *ldev,
58 struct i40e_client *client,
59 bool is_vf, u32 vf_id,
60 u32 flag, u32 valid_flag);
61
62static struct i40e_ops i40e_lan_ops = {
63 .virtchnl_send = i40e_client_virtchnl_send,
64 .setup_qvlist = i40e_client_setup_qvlist,
65 .request_reset = i40e_client_request_reset,
66 .update_vsi_ctxt = i40e_client_update_vsi_ctxt,
67};
68
69/**
70 * i40e_client_type_to_vsi_type - convert client type to vsi type
71 * @client_type: the i40e_client type
72 *
73 * returns the related vsi type value
74 **/
75static
76enum i40e_vsi_type i40e_client_type_to_vsi_type(enum i40e_client_type type)
77{
78 switch (type) {
79 case I40E_CLIENT_IWARP:
80 return I40E_VSI_IWARP;
81
82 case I40E_CLIENT_VMDQ2:
83 return I40E_VSI_VMDQ2;
84
85 default:
86 pr_err("i40e: Client type unknown\n");
87 return I40E_VSI_TYPE_UNKNOWN;
88 }
89}
90
91/**
92 * i40e_client_get_params - Get the params that can change at runtime
93 * @vsi: the VSI with the message
94 * @param: clinet param struct
95 *
96 **/
97static
98int i40e_client_get_params(struct i40e_vsi *vsi, struct i40e_params *params)
99{
100 struct i40e_dcbx_config *dcb_cfg = &vsi->back->hw.local_dcbx_config;
101 int i = 0;
102
103 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
104 u8 tc = dcb_cfg->etscfg.prioritytable[i];
105 u16 qs_handle;
106
107 /* If TC is not enabled for VSI use TC0 for UP */
108 if (!(vsi->tc_config.enabled_tc & BIT(tc)))
109 tc = 0;
110
111 qs_handle = le16_to_cpu(vsi->info.qs_handle[tc]);
112 params->qos.prio_qos[i].tc = tc;
113 params->qos.prio_qos[i].qs_handle = qs_handle;
114 if (qs_handle == I40E_AQ_VSI_QS_HANDLE_INVALID) {
115 dev_err(&vsi->back->pdev->dev, "Invalid queue set handle for TC = %d, vsi id = %d\n",
116 tc, vsi->id);
117 return -EINVAL;
118 }
119 }
120
121 params->mtu = vsi->netdev->mtu;
122 return 0;
123}
124
125/**
126 * i40e_notify_client_of_vf_msg - call the client vf message callback
127 * @vsi: the VSI with the message
128 * @vf_id: the absolute VF id that sent the message
129 * @msg: message buffer
130 * @len: length of the message
131 *
132 * If there is a client to this VSI, call the client
133 **/
134void
135i40e_notify_client_of_vf_msg(struct i40e_vsi *vsi, u32 vf_id, u8 *msg, u16 len)
136{
137 struct i40e_client_instance *cdev;
138
139 if (!vsi)
140 return;
141 mutex_lock(&i40e_client_instance_mutex);
142 list_for_each_entry(cdev, &i40e_client_instances, list) {
143 if (cdev->lan_info.pf == vsi->back) {
144 if (!cdev->client ||
145 !cdev->client->ops ||
146 !cdev->client->ops->virtchnl_receive) {
147 dev_dbg(&vsi->back->pdev->dev,
148 "Cannot locate client instance virtual channel receive routine\n");
149 continue;
150 }
Catherine Sullivan91cdca42016-08-15 14:17:18 -0700151 if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED,
152 &cdev->state)) {
153 dev_dbg(&vsi->back->pdev->dev, "Client is not open, abort virtchnl_receive\n");
154 continue;
155 }
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600156 cdev->client->ops->virtchnl_receive(&cdev->lan_info,
157 cdev->client,
158 vf_id, msg, len);
159 }
160 }
161 mutex_unlock(&i40e_client_instance_mutex);
162}
163
164/**
165 * i40e_notify_client_of_l2_param_changes - call the client notify callback
166 * @vsi: the VSI with l2 param changes
167 *
168 * If there is a client to this VSI, call the client
169 **/
170void i40e_notify_client_of_l2_param_changes(struct i40e_vsi *vsi)
171{
172 struct i40e_client_instance *cdev;
173 struct i40e_params params;
174
175 if (!vsi)
176 return;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600177 mutex_lock(&i40e_client_instance_mutex);
178 list_for_each_entry(cdev, &i40e_client_instances, list) {
179 if (cdev->lan_info.pf == vsi->back) {
180 if (!cdev->client ||
181 !cdev->client->ops ||
182 !cdev->client->ops->l2_param_change) {
183 dev_dbg(&vsi->back->pdev->dev,
184 "Cannot locate client instance l2_param_change routine\n");
185 continue;
186 }
Jacob Kellerd7ce6422017-02-09 23:29:13 -0800187 memset(&params, 0, sizeof(params));
188 i40e_client_get_params(vsi, &params);
Catherine Sullivan91cdca42016-08-15 14:17:18 -0700189 if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED,
190 &cdev->state)) {
191 dev_dbg(&vsi->back->pdev->dev, "Client is not open, abort l2 param change\n");
192 continue;
193 }
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600194 cdev->lan_info.params = params;
195 cdev->client->ops->l2_param_change(&cdev->lan_info,
196 cdev->client,
197 &params);
198 }
199 }
200 mutex_unlock(&i40e_client_instance_mutex);
201}
202
203/**
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600204 * i40e_client_release_qvlist
205 * @ldev: pointer to L2 context.
206 *
207 **/
208static void i40e_client_release_qvlist(struct i40e_info *ldev)
209{
210 struct i40e_qvlist_info *qvlist_info = ldev->qvlist_info;
211 u32 i;
212
213 if (!ldev->qvlist_info)
214 return;
215
216 for (i = 0; i < qvlist_info->num_vectors; i++) {
217 struct i40e_pf *pf = ldev->pf;
218 struct i40e_qv_info *qv_info;
219 u32 reg_idx;
220
221 qv_info = &qvlist_info->qv_info[i];
222 if (!qv_info)
223 continue;
224 reg_idx = I40E_PFINT_LNKLSTN(qv_info->v_idx - 1);
225 wr32(&pf->hw, reg_idx, I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK);
226 }
227 kfree(ldev->qvlist_info);
228 ldev->qvlist_info = NULL;
229}
230
231/**
232 * i40e_notify_client_of_netdev_close - call the client close callback
233 * @vsi: the VSI with netdev closed
234 * @reset: true when close called due to a reset pending
235 *
236 * If there is a client to this netdev, call the client with close
237 **/
238void i40e_notify_client_of_netdev_close(struct i40e_vsi *vsi, bool reset)
239{
240 struct i40e_client_instance *cdev;
241
242 if (!vsi)
243 return;
244 mutex_lock(&i40e_client_instance_mutex);
245 list_for_each_entry(cdev, &i40e_client_instances, list) {
246 if (cdev->lan_info.netdev == vsi->netdev) {
247 if (!cdev->client ||
248 !cdev->client->ops || !cdev->client->ops->close) {
249 dev_dbg(&vsi->back->pdev->dev,
250 "Cannot locate client instance close routine\n");
251 continue;
252 }
253 cdev->client->ops->close(&cdev->lan_info, cdev->client,
254 reset);
Mitch Williams7be963222016-09-14 16:24:36 -0700255 clear_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600256 i40e_client_release_qvlist(&cdev->lan_info);
257 }
258 }
259 mutex_unlock(&i40e_client_instance_mutex);
260}
261
262/**
263 * i40e_notify_client_of_vf_reset - call the client vf reset callback
264 * @pf: PF device pointer
265 * @vf_id: asolute id of VF being reset
266 *
267 * If there is a client attached to this PF, notify when a VF is reset
268 **/
269void i40e_notify_client_of_vf_reset(struct i40e_pf *pf, u32 vf_id)
270{
271 struct i40e_client_instance *cdev;
272
273 if (!pf)
274 return;
275 mutex_lock(&i40e_client_instance_mutex);
276 list_for_each_entry(cdev, &i40e_client_instances, list) {
277 if (cdev->lan_info.pf == pf) {
278 if (!cdev->client ||
279 !cdev->client->ops ||
280 !cdev->client->ops->vf_reset) {
281 dev_dbg(&pf->pdev->dev,
282 "Cannot locate client instance VF reset routine\n");
283 continue;
284 }
Catherine Sullivan91cdca42016-08-15 14:17:18 -0700285 if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED,
286 &cdev->state)) {
287 dev_dbg(&pf->pdev->dev, "Client is not open, abort vf-reset\n");
288 continue;
289 }
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600290 cdev->client->ops->vf_reset(&cdev->lan_info,
291 cdev->client, vf_id);
292 }
293 }
294 mutex_unlock(&i40e_client_instance_mutex);
295}
296
297/**
298 * i40e_notify_client_of_vf_enable - call the client vf notification callback
299 * @pf: PF device pointer
300 * @num_vfs: the number of VFs currently enabled, 0 for disable
301 *
302 * If there is a client attached to this PF, call its VF notification routine
303 **/
304void i40e_notify_client_of_vf_enable(struct i40e_pf *pf, u32 num_vfs)
305{
306 struct i40e_client_instance *cdev;
307
308 if (!pf)
309 return;
310 mutex_lock(&i40e_client_instance_mutex);
311 list_for_each_entry(cdev, &i40e_client_instances, list) {
312 if (cdev->lan_info.pf == pf) {
313 if (!cdev->client ||
314 !cdev->client->ops ||
315 !cdev->client->ops->vf_enable) {
316 dev_dbg(&pf->pdev->dev,
317 "Cannot locate client instance VF enable routine\n");
318 continue;
319 }
Catherine Sullivan91cdca42016-08-15 14:17:18 -0700320 if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED,
321 &cdev->state)) {
322 dev_dbg(&pf->pdev->dev, "Client is not open, abort vf-enable\n");
323 continue;
324 }
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600325 cdev->client->ops->vf_enable(&cdev->lan_info,
326 cdev->client, num_vfs);
327 }
328 }
329 mutex_unlock(&i40e_client_instance_mutex);
330}
331
332/**
333 * i40e_vf_client_capable - ask the client if it likes the specified VF
334 * @pf: PF device pointer
335 * @vf_id: the VF in question
336 *
337 * If there is a client of the specified type attached to this PF, call
338 * its vf_capable routine
339 **/
340int i40e_vf_client_capable(struct i40e_pf *pf, u32 vf_id,
341 enum i40e_client_type type)
342{
343 struct i40e_client_instance *cdev;
344 int capable = false;
345
346 if (!pf)
347 return false;
348 mutex_lock(&i40e_client_instance_mutex);
349 list_for_each_entry(cdev, &i40e_client_instances, list) {
350 if (cdev->lan_info.pf == pf) {
351 if (!cdev->client ||
352 !cdev->client->ops ||
353 !cdev->client->ops->vf_capable ||
354 !(cdev->client->type == type)) {
355 dev_dbg(&pf->pdev->dev,
356 "Cannot locate client instance VF capability routine\n");
357 continue;
358 }
Catherine Sullivan91cdca42016-08-15 14:17:18 -0700359 if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED,
360 &cdev->state)) {
361 dev_dbg(&pf->pdev->dev, "Client is not open, abort vf-capable\n");
362 continue;
363 }
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600364 capable = cdev->client->ops->vf_capable(&cdev->lan_info,
365 cdev->client,
366 vf_id);
367 break;
368 }
369 }
370 mutex_unlock(&i40e_client_instance_mutex);
371 return capable;
372}
373
374/**
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600375 * i40e_client_add_instance - add a client instance struct to the instance list
376 * @pf: pointer to the board struct
377 * @client: pointer to a client struct in the client list.
Anjali Singhai Jainf38ff2e2016-08-24 17:51:53 -0700378 * @existing: if there was already an existing instance
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600379 *
Anjali Singhai Jainf38ff2e2016-08-24 17:51:53 -0700380 * Returns cdev ptr on success or if already exists, NULL on failure
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600381 **/
382static
383struct i40e_client_instance *i40e_client_add_instance(struct i40e_pf *pf,
Anjali Singhai Jainf38ff2e2016-08-24 17:51:53 -0700384 struct i40e_client *client,
385 bool *existing)
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600386{
387 struct i40e_client_instance *cdev;
388 struct netdev_hw_addr *mac = NULL;
389 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
390
391 mutex_lock(&i40e_client_instance_mutex);
392 list_for_each_entry(cdev, &i40e_client_instances, list) {
393 if ((cdev->lan_info.pf == pf) && (cdev->client == client)) {
Anjali Singhai Jainf38ff2e2016-08-24 17:51:53 -0700394 *existing = true;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600395 goto out;
396 }
397 }
398 cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
399 if (!cdev)
400 goto out;
401
402 cdev->lan_info.pf = (void *)pf;
403 cdev->lan_info.netdev = vsi->netdev;
404 cdev->lan_info.pcidev = pf->pdev;
405 cdev->lan_info.fid = pf->hw.pf_id;
406 cdev->lan_info.ftype = I40E_CLIENT_FTYPE_PF;
407 cdev->lan_info.hw_addr = pf->hw.hw_addr;
408 cdev->lan_info.ops = &i40e_lan_ops;
409 cdev->lan_info.version.major = I40E_CLIENT_VERSION_MAJOR;
410 cdev->lan_info.version.minor = I40E_CLIENT_VERSION_MINOR;
411 cdev->lan_info.version.build = I40E_CLIENT_VERSION_BUILD;
412 cdev->lan_info.fw_maj_ver = pf->hw.aq.fw_maj_ver;
413 cdev->lan_info.fw_min_ver = pf->hw.aq.fw_min_ver;
414 cdev->lan_info.fw_build = pf->hw.aq.fw_build;
415 set_bit(__I40E_CLIENT_INSTANCE_NONE, &cdev->state);
416
417 if (i40e_client_get_params(vsi, &cdev->lan_info.params)) {
418 kfree(cdev);
419 cdev = NULL;
420 goto out;
421 }
422
423 cdev->lan_info.msix_count = pf->num_iwarp_msix;
424 cdev->lan_info.msix_entries = &pf->msix_entries[pf->iwarp_base_vector];
425
426 mac = list_first_entry(&cdev->lan_info.netdev->dev_addrs.list,
427 struct netdev_hw_addr, list);
428 if (mac)
429 ether_addr_copy(cdev->lan_info.lanmac, mac->addr);
430 else
431 dev_err(&pf->pdev->dev, "MAC address list is empty!\n");
432
433 cdev->client = client;
434 INIT_LIST_HEAD(&cdev->list);
435 list_add(&cdev->list, &i40e_client_instances);
436out:
437 mutex_unlock(&i40e_client_instance_mutex);
438 return cdev;
439}
440
441/**
442 * i40e_client_del_instance - removes a client instance from the list
443 * @pf: pointer to the board struct
444 *
445 * Returns 0 on success or non-0 on error
446 **/
447static
448int i40e_client_del_instance(struct i40e_pf *pf, struct i40e_client *client)
449{
450 struct i40e_client_instance *cdev, *tmp;
451 int ret = -ENODEV;
452
453 mutex_lock(&i40e_client_instance_mutex);
454 list_for_each_entry_safe(cdev, tmp, &i40e_client_instances, list) {
455 if ((cdev->lan_info.pf != pf) || (cdev->client != client))
456 continue;
457
458 dev_info(&pf->pdev->dev, "Deleted instance of Client %s, of dev %d bus=0x%02x func=0x%02x)\n",
459 client->name, pf->hw.pf_id,
460 pf->hw.bus.device, pf->hw.bus.func);
461 list_del(&cdev->list);
462 kfree(cdev);
463 ret = 0;
464 break;
465 }
466 mutex_unlock(&i40e_client_instance_mutex);
467 return ret;
468}
469
470/**
471 * i40e_client_subtask - client maintenance work
472 * @pf: board private structure
473 **/
474void i40e_client_subtask(struct i40e_pf *pf)
475{
476 struct i40e_client_instance *cdev;
477 struct i40e_client *client;
Anjali Singhai Jainf38ff2e2016-08-24 17:51:53 -0700478 bool existing = false;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600479 int ret = 0;
480
481 if (!(pf->flags & I40E_FLAG_SERVICE_CLIENT_REQUESTED))
482 return;
483 pf->flags &= ~I40E_FLAG_SERVICE_CLIENT_REQUESTED;
484
485 /* If we're down or resetting, just bail */
486 if (test_bit(__I40E_DOWN, &pf->state) ||
487 test_bit(__I40E_CONFIG_BUSY, &pf->state))
488 return;
489
490 /* Check client state and instantiate client if client registered */
491 mutex_lock(&i40e_client_mutex);
492 list_for_each_entry(client, &i40e_clients, list) {
493 /* first check client is registered */
494 if (!test_bit(__I40E_CLIENT_REGISTERED, &client->state))
495 continue;
496
497 /* Do we also need the LAN VSI to be up, to create instance */
498 if (!(client->flags & I40E_CLIENT_FLAGS_LAUNCH_ON_PROBE)) {
499 /* check if L2 VSI is up, if not we are not ready */
500 if (test_bit(__I40E_DOWN, &pf->vsi[pf->lan_vsi]->state))
501 continue;
Anjali Singhai Jainf38ff2e2016-08-24 17:51:53 -0700502 } else {
Carolyn Wybornyc73d2e82016-09-14 16:24:31 -0700503 dev_warn(&pf->pdev->dev, "This client %s is being instantiated at probe\n",
Anjali Singhai Jainf38ff2e2016-08-24 17:51:53 -0700504 client->name);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600505 }
506
507 /* Add the client instance to the instance list */
Anjali Singhai Jainf38ff2e2016-08-24 17:51:53 -0700508 cdev = i40e_client_add_instance(pf, client, &existing);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600509 if (!cdev)
510 continue;
511
Anjali Singhai Jainf38ff2e2016-08-24 17:51:53 -0700512 if (!existing) {
Anjali Singhai Jainf38ff2e2016-08-24 17:51:53 -0700513 dev_info(&pf->pdev->dev, "Added instance of Client %s to PF%d bus=0x%02x func=0x%02x\n",
514 client->name, pf->hw.pf_id,
515 pf->hw.bus.device, pf->hw.bus.func);
Mitch Williams7be963222016-09-14 16:24:36 -0700516 }
517
518 mutex_lock(&i40e_client_instance_mutex);
519 if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED,
520 &cdev->state)) {
521 /* Send an Open request to the client */
Carolyn Wybornyc73d2e82016-09-14 16:24:31 -0700522 if (client->ops && client->ops->open)
523 ret = client->ops->open(&cdev->lan_info,
524 client);
Mitch Williams7be963222016-09-14 16:24:36 -0700525 if (!ret) {
526 set_bit(__I40E_CLIENT_INSTANCE_OPENED,
527 &cdev->state);
528 } else {
529 /* remove client instance */
Carolyn Wybornyc73d2e82016-09-14 16:24:31 -0700530 i40e_client_del_instance(pf, client);
Carolyn Wybornyc73d2e82016-09-14 16:24:31 -0700531 }
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600532 }
Mitch Williams7be963222016-09-14 16:24:36 -0700533 mutex_unlock(&i40e_client_instance_mutex);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600534 }
535 mutex_unlock(&i40e_client_mutex);
536}
537
538/**
539 * i40e_lan_add_device - add a lan device struct to the list of lan devices
540 * @pf: pointer to the board struct
541 *
542 * Returns 0 on success or none 0 on error
543 **/
544int i40e_lan_add_device(struct i40e_pf *pf)
545{
546 struct i40e_device *ldev;
547 int ret = 0;
548
549 mutex_lock(&i40e_device_mutex);
550 list_for_each_entry(ldev, &i40e_devices, list) {
551 if (ldev->pf == pf) {
552 ret = -EEXIST;
553 goto out;
554 }
555 }
556 ldev = kzalloc(sizeof(*ldev), GFP_KERNEL);
557 if (!ldev) {
558 ret = -ENOMEM;
559 goto out;
560 }
561 ldev->pf = pf;
562 INIT_LIST_HEAD(&ldev->list);
563 list_add(&ldev->list, &i40e_devices);
564 dev_info(&pf->pdev->dev, "Added LAN device PF%d bus=0x%02x func=0x%02x\n",
565 pf->hw.pf_id, pf->hw.bus.device, pf->hw.bus.func);
566
567 /* Since in some cases register may have happened before a device gets
Anjali Singhai Jainf38ff2e2016-08-24 17:51:53 -0700568 * added, we can schedule a subtask to go initiate the clients if
569 * they can be launched at probe time.
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600570 */
571 pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED;
572 i40e_service_event_schedule(pf);
573
574out:
575 mutex_unlock(&i40e_device_mutex);
576 return ret;
577}
578
579/**
580 * i40e_lan_del_device - removes a lan device from the device list
581 * @pf: pointer to the board struct
582 *
583 * Returns 0 on success or non-0 on error
584 **/
585int i40e_lan_del_device(struct i40e_pf *pf)
586{
587 struct i40e_device *ldev, *tmp;
588 int ret = -ENODEV;
589
590 mutex_lock(&i40e_device_mutex);
591 list_for_each_entry_safe(ldev, tmp, &i40e_devices, list) {
592 if (ldev->pf == pf) {
593 dev_info(&pf->pdev->dev, "Deleted LAN device PF%d bus=0x%02x func=0x%02x\n",
594 pf->hw.pf_id, pf->hw.bus.device,
595 pf->hw.bus.func);
596 list_del(&ldev->list);
597 kfree(ldev);
598 ret = 0;
599 break;
600 }
601 }
602
603 mutex_unlock(&i40e_device_mutex);
604 return ret;
605}
606
607/**
608 * i40e_client_release - release client specific resources
609 * @client: pointer to the registered client
610 *
611 * Return 0 on success or < 0 on error
612 **/
613static int i40e_client_release(struct i40e_client *client)
614{
615 struct i40e_client_instance *cdev, *tmp;
Harshitha Ramamurthy682d11d2016-08-15 14:17:19 -0700616 struct i40e_pf *pf;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600617 int ret = 0;
618
619 LIST_HEAD(cdevs_tmp);
620
621 mutex_lock(&i40e_client_instance_mutex);
622 list_for_each_entry_safe(cdev, tmp, &i40e_client_instances, list) {
623 if (strncmp(cdev->client->name, client->name,
624 I40E_CLIENT_STR_LENGTH))
625 continue;
Harshitha Ramamurthy682d11d2016-08-15 14:17:19 -0700626 pf = (struct i40e_pf *)cdev->lan_info.pf;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600627 if (test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state)) {
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600628 if (client->ops && client->ops->close)
629 client->ops->close(&cdev->lan_info, client,
630 false);
631 i40e_client_release_qvlist(&cdev->lan_info);
632 clear_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state);
633
634 dev_warn(&pf->pdev->dev,
635 "Client %s instance for PF id %d closed\n",
636 client->name, pf->hw.pf_id);
637 }
638 /* delete the client instance from the list */
Wei Yongjuneb271632016-07-26 14:58:30 +0000639 list_move(&cdev->list, &cdevs_tmp);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600640 dev_info(&pf->pdev->dev, "Deleted client instance of Client %s\n",
641 client->name);
642 }
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600643 mutex_unlock(&i40e_client_instance_mutex);
644
645 /* free the client device and release its vsi */
646 list_for_each_entry_safe(cdev, tmp, &cdevs_tmp, list) {
647 kfree(cdev);
648 }
649 return ret;
650}
651
652/**
653 * i40e_client_prepare - prepare client specific resources
654 * @client: pointer to the registered client
655 *
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600656 **/
Mitch Williams3bb83ba2017-02-09 23:46:50 -0800657static void i40e_client_prepare(struct i40e_client *client)
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600658{
659 struct i40e_device *ldev;
660 struct i40e_pf *pf;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600661
662 mutex_lock(&i40e_device_mutex);
663 list_for_each_entry(ldev, &i40e_devices, list) {
664 pf = ldev->pf;
665 /* Start the client subtask */
666 pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED;
667 i40e_service_event_schedule(pf);
668 }
669 mutex_unlock(&i40e_device_mutex);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600670}
671
672/**
673 * i40e_client_virtchnl_send - TBD
674 * @ldev: pointer to L2 context
675 * @client: Client pointer
676 * @vf_id: absolute VF identifier
677 * @msg: message buffer
678 * @len: length of message buffer
679 *
680 * Return 0 on success or < 0 on error
681 **/
682static int i40e_client_virtchnl_send(struct i40e_info *ldev,
683 struct i40e_client *client,
684 u32 vf_id, u8 *msg, u16 len)
685{
686 struct i40e_pf *pf = ldev->pf;
687 struct i40e_hw *hw = &pf->hw;
688 i40e_status err;
689
690 err = i40e_aq_send_msg_to_vf(hw, vf_id, I40E_VIRTCHNL_OP_IWARP,
691 0, msg, len, NULL);
692 if (err)
693 dev_err(&pf->pdev->dev, "Unable to send iWarp message to VF, error %d, aq status %d\n",
694 err, hw->aq.asq_last_status);
695
696 return err;
697}
698
699/**
700 * i40e_client_setup_qvlist
701 * @ldev: pointer to L2 context.
702 * @client: Client pointer.
703 * @qv_info: queue and vector list
704 *
705 * Return 0 on success or < 0 on error
706 **/
707static int i40e_client_setup_qvlist(struct i40e_info *ldev,
708 struct i40e_client *client,
709 struct i40e_qvlist_info *qvlist_info)
710{
711 struct i40e_pf *pf = ldev->pf;
712 struct i40e_hw *hw = &pf->hw;
713 struct i40e_qv_info *qv_info;
714 u32 v_idx, i, reg_idx, reg;
715 u32 size;
716
717 size = sizeof(struct i40e_qvlist_info) +
718 (sizeof(struct i40e_qv_info) * (qvlist_info->num_vectors - 1));
719 ldev->qvlist_info = kzalloc(size, GFP_KERNEL);
720 ldev->qvlist_info->num_vectors = qvlist_info->num_vectors;
721
722 for (i = 0; i < qvlist_info->num_vectors; i++) {
723 qv_info = &qvlist_info->qv_info[i];
724 if (!qv_info)
725 continue;
726 v_idx = qv_info->v_idx;
727
728 /* Validate vector id belongs to this client */
729 if ((v_idx >= (pf->iwarp_base_vector + pf->num_iwarp_msix)) ||
730 (v_idx < pf->iwarp_base_vector))
731 goto err;
732
733 ldev->qvlist_info->qv_info[i] = *qv_info;
734 reg_idx = I40E_PFINT_LNKLSTN(v_idx - 1);
735
736 if (qv_info->ceq_idx == I40E_QUEUE_INVALID_IDX) {
737 /* Special case - No CEQ mapped on this vector */
738 wr32(hw, reg_idx, I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK);
739 } else {
740 reg = (qv_info->ceq_idx &
741 I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
742 (I40E_QUEUE_TYPE_PE_CEQ <<
743 I40E_PFINT_LNKLSTN_FIRSTQ_TYPE_SHIFT);
744 wr32(hw, reg_idx, reg);
745
746 reg = (I40E_PFINT_CEQCTL_CAUSE_ENA_MASK |
747 (v_idx << I40E_PFINT_CEQCTL_MSIX_INDX_SHIFT) |
748 (qv_info->itr_idx <<
749 I40E_PFINT_CEQCTL_ITR_INDX_SHIFT) |
750 (I40E_QUEUE_END_OF_LIST <<
751 I40E_PFINT_CEQCTL_NEXTQ_INDX_SHIFT));
752 wr32(hw, I40E_PFINT_CEQCTL(qv_info->ceq_idx), reg);
753 }
754 if (qv_info->aeq_idx != I40E_QUEUE_INVALID_IDX) {
755 reg = (I40E_PFINT_AEQCTL_CAUSE_ENA_MASK |
756 (v_idx << I40E_PFINT_AEQCTL_MSIX_INDX_SHIFT) |
757 (qv_info->itr_idx <<
758 I40E_PFINT_AEQCTL_ITR_INDX_SHIFT));
759
760 wr32(hw, I40E_PFINT_AEQCTL, reg);
761 }
762 }
Avinash Dayanand70df9732016-07-27 12:02:36 -0700763 /* Mitigate sync problems with iwarp VF driver */
764 i40e_flush(hw);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600765 return 0;
766err:
767 kfree(ldev->qvlist_info);
768 ldev->qvlist_info = NULL;
769 return -EINVAL;
770}
771
772/**
773 * i40e_client_request_reset
774 * @ldev: pointer to L2 context.
775 * @client: Client pointer.
776 * @level: reset level
777 **/
778static void i40e_client_request_reset(struct i40e_info *ldev,
779 struct i40e_client *client,
780 u32 reset_level)
781{
782 struct i40e_pf *pf = ldev->pf;
783
784 switch (reset_level) {
785 case I40E_CLIENT_RESET_LEVEL_PF:
786 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
787 break;
788 case I40E_CLIENT_RESET_LEVEL_CORE:
789 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
790 break;
791 default:
792 dev_warn(&pf->pdev->dev,
793 "Client %s instance for PF id %d request an unsupported reset: %d.\n",
794 client->name, pf->hw.pf_id, reset_level);
795 break;
796 }
797
798 i40e_service_event_schedule(pf);
799}
800
801/**
802 * i40e_client_update_vsi_ctxt
803 * @ldev: pointer to L2 context.
804 * @client: Client pointer.
805 * @is_vf: if this for the VF
806 * @vf_id: if is_vf true this carries the vf_id
807 * @flag: Any device level setting that needs to be done for PE
808 * @valid_flag: Bits in this match up and enable changing of flag bits
809 *
810 * Return 0 on success or < 0 on error
811 **/
812static int i40e_client_update_vsi_ctxt(struct i40e_info *ldev,
813 struct i40e_client *client,
814 bool is_vf, u32 vf_id,
815 u32 flag, u32 valid_flag)
816{
817 struct i40e_pf *pf = ldev->pf;
818 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
819 struct i40e_vsi_context ctxt;
820 bool update = true;
821 i40e_status err;
822
823 /* TODO: for now do not allow setting VF's VSI setting */
824 if (is_vf)
825 return -EINVAL;
826
827 ctxt.seid = pf->main_vsi_seid;
828 ctxt.pf_num = pf->hw.pf_id;
829 err = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
830 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
831 if (err) {
832 dev_info(&pf->pdev->dev,
833 "couldn't get PF vsi config, err %s aq_err %s\n",
834 i40e_stat_str(&pf->hw, err),
835 i40e_aq_str(&pf->hw,
836 pf->hw.aq.asq_last_status));
837 return -ENOENT;
838 }
839
840 if ((valid_flag & I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE) &&
841 (flag & I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE)) {
842 ctxt.info.valid_sections =
843 cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
844 ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA;
845 } else if ((valid_flag & I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE) &&
846 !(flag & I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE)) {
847 ctxt.info.valid_sections =
848 cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
849 ctxt.info.queueing_opt_flags &= ~I40E_AQ_VSI_QUE_OPT_TCP_ENA;
850 } else {
851 update = false;
852 dev_warn(&pf->pdev->dev,
853 "Client %s instance for PF id %d request an unsupported Config: %x.\n",
854 client->name, pf->hw.pf_id, flag);
855 }
856
857 if (update) {
858 err = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
859 if (err) {
860 dev_info(&pf->pdev->dev,
861 "update VSI ctxt for PE failed, err %s aq_err %s\n",
862 i40e_stat_str(&pf->hw, err),
863 i40e_aq_str(&pf->hw,
864 pf->hw.aq.asq_last_status));
865 }
866 }
867 return err;
868}
869
870/**
871 * i40e_register_client - Register a i40e client driver with the L2 driver
872 * @client: pointer to the i40e_client struct
873 *
874 * Returns 0 on success or non-0 on error
875 **/
876int i40e_register_client(struct i40e_client *client)
877{
878 int ret = 0;
879 enum i40e_vsi_type vsi_type;
880
881 if (!client) {
882 ret = -EIO;
883 goto out;
884 }
885
886 if (strlen(client->name) == 0) {
887 pr_info("i40e: Failed to register client with no name\n");
888 ret = -EIO;
889 goto out;
890 }
891
892 mutex_lock(&i40e_client_mutex);
893 if (i40e_client_is_registered(client)) {
894 pr_info("i40e: Client %s has already been registered!\n",
895 client->name);
896 mutex_unlock(&i40e_client_mutex);
897 ret = -EEXIST;
898 goto out;
899 }
900
901 if ((client->version.major != I40E_CLIENT_VERSION_MAJOR) ||
902 (client->version.minor != I40E_CLIENT_VERSION_MINOR)) {
903 pr_info("i40e: Failed to register client %s due to mismatched client interface version\n",
904 client->name);
905 pr_info("Client is using version: %02d.%02d.%02d while LAN driver supports %s\n",
906 client->version.major, client->version.minor,
907 client->version.build,
908 i40e_client_interface_version_str);
909 mutex_unlock(&i40e_client_mutex);
910 ret = -EIO;
911 goto out;
912 }
913
914 vsi_type = i40e_client_type_to_vsi_type(client->type);
915 if (vsi_type == I40E_VSI_TYPE_UNKNOWN) {
916 pr_info("i40e: Failed to register client %s due to unknown client type %d\n",
917 client->name, client->type);
918 mutex_unlock(&i40e_client_mutex);
919 ret = -EIO;
920 goto out;
921 }
922 list_add(&client->list, &i40e_clients);
923 set_bit(__I40E_CLIENT_REGISTERED, &client->state);
924 mutex_unlock(&i40e_client_mutex);
925
Mitch Williams3bb83ba2017-02-09 23:46:50 -0800926 i40e_client_prepare(client);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600927
Mitch Williams3bb83ba2017-02-09 23:46:50 -0800928 pr_info("i40e: Registered client %s\n", client->name);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600929out:
930 return ret;
931}
932EXPORT_SYMBOL(i40e_register_client);
933
934/**
935 * i40e_unregister_client - Unregister a i40e client driver with the L2 driver
936 * @client: pointer to the i40e_client struct
937 *
938 * Returns 0 on success or non-0 on error
939 **/
940int i40e_unregister_client(struct i40e_client *client)
941{
942 int ret = 0;
943
944 /* When a unregister request comes through we would have to send
945 * a close for each of the client instances that were opened.
946 * client_release function is called to handle this.
947 */
Catherine Sullivancd3be162016-06-23 14:08:46 -0700948 mutex_lock(&i40e_client_mutex);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600949 if (!client || i40e_client_release(client)) {
950 ret = -EIO;
951 goto out;
952 }
953
954 /* TODO: check if device is in reset, or if that matters? */
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600955 if (!i40e_client_is_registered(client)) {
956 pr_info("i40e: Client %s has not been registered\n",
957 client->name);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600958 ret = -ENODEV;
959 goto out;
960 }
Mitch Williams7be963222016-09-14 16:24:36 -0700961 clear_bit(__I40E_CLIENT_REGISTERED, &client->state);
962 list_del(&client->list);
963 pr_info("i40e: Unregistered client %s with return code %d\n",
964 client->name, ret);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600965out:
Catherine Sullivancd3be162016-06-23 14:08:46 -0700966 mutex_unlock(&i40e_client_mutex);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600967 return ret;
968}
969EXPORT_SYMBOL(i40e_unregister_client);