blob: d570219efd9f33b8934fdfe8ad3e256fb78a2e97 [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) {
Sudheer Mogilappagarib3f028f2017-02-09 23:58:22 -0800513 dev_info(&pf->pdev->dev, "Added instance of Client %s to PF%d bus=0x%02x dev=0x%02x func=0x%02x\n",
Anjali Singhai Jainf38ff2e2016-08-24 17:51:53 -0700514 client->name, pf->hw.pf_id,
Sudheer Mogilappagarib3f028f2017-02-09 23:58:22 -0800515 pf->hw.bus.bus_id, pf->hw.bus.device,
516 pf->hw.bus.func);
Mitch Williams7be963222016-09-14 16:24:36 -0700517 }
518
519 mutex_lock(&i40e_client_instance_mutex);
520 if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED,
521 &cdev->state)) {
522 /* Send an Open request to the client */
Carolyn Wybornyc73d2e82016-09-14 16:24:31 -0700523 if (client->ops && client->ops->open)
524 ret = client->ops->open(&cdev->lan_info,
525 client);
Mitch Williams7be963222016-09-14 16:24:36 -0700526 if (!ret) {
527 set_bit(__I40E_CLIENT_INSTANCE_OPENED,
528 &cdev->state);
529 } else {
530 /* remove client instance */
Carolyn Wybornyc73d2e82016-09-14 16:24:31 -0700531 i40e_client_del_instance(pf, client);
Carolyn Wybornyc73d2e82016-09-14 16:24:31 -0700532 }
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600533 }
Mitch Williams7be963222016-09-14 16:24:36 -0700534 mutex_unlock(&i40e_client_instance_mutex);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600535 }
536 mutex_unlock(&i40e_client_mutex);
537}
538
539/**
540 * i40e_lan_add_device - add a lan device struct to the list of lan devices
541 * @pf: pointer to the board struct
542 *
543 * Returns 0 on success or none 0 on error
544 **/
545int i40e_lan_add_device(struct i40e_pf *pf)
546{
547 struct i40e_device *ldev;
548 int ret = 0;
549
550 mutex_lock(&i40e_device_mutex);
551 list_for_each_entry(ldev, &i40e_devices, list) {
552 if (ldev->pf == pf) {
553 ret = -EEXIST;
554 goto out;
555 }
556 }
557 ldev = kzalloc(sizeof(*ldev), GFP_KERNEL);
558 if (!ldev) {
559 ret = -ENOMEM;
560 goto out;
561 }
562 ldev->pf = pf;
563 INIT_LIST_HEAD(&ldev->list);
564 list_add(&ldev->list, &i40e_devices);
Sudheer Mogilappagarib3f028f2017-02-09 23:58:22 -0800565 dev_info(&pf->pdev->dev, "Added LAN device PF%d bus=0x%02x dev=0x%02x func=0x%02x\n",
566 pf->hw.pf_id, pf->hw.bus.bus_id,
567 pf->hw.bus.device, pf->hw.bus.func);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600568
569 /* Since in some cases register may have happened before a device gets
Anjali Singhai Jainf38ff2e2016-08-24 17:51:53 -0700570 * added, we can schedule a subtask to go initiate the clients if
571 * they can be launched at probe time.
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600572 */
573 pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED;
574 i40e_service_event_schedule(pf);
575
576out:
577 mutex_unlock(&i40e_device_mutex);
578 return ret;
579}
580
581/**
582 * i40e_lan_del_device - removes a lan device from the device list
583 * @pf: pointer to the board struct
584 *
585 * Returns 0 on success or non-0 on error
586 **/
587int i40e_lan_del_device(struct i40e_pf *pf)
588{
589 struct i40e_device *ldev, *tmp;
590 int ret = -ENODEV;
591
592 mutex_lock(&i40e_device_mutex);
593 list_for_each_entry_safe(ldev, tmp, &i40e_devices, list) {
594 if (ldev->pf == pf) {
Sudheer Mogilappagarib3f028f2017-02-09 23:58:22 -0800595 dev_info(&pf->pdev->dev, "Deleted LAN device PF%d bus=0x%02x dev=0x%02x func=0x%02x\n",
596 pf->hw.pf_id, pf->hw.bus.bus_id,
597 pf->hw.bus.device, pf->hw.bus.func);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600598 list_del(&ldev->list);
599 kfree(ldev);
600 ret = 0;
601 break;
602 }
603 }
604
605 mutex_unlock(&i40e_device_mutex);
606 return ret;
607}
608
609/**
610 * i40e_client_release - release client specific resources
611 * @client: pointer to the registered client
612 *
613 * Return 0 on success or < 0 on error
614 **/
615static int i40e_client_release(struct i40e_client *client)
616{
617 struct i40e_client_instance *cdev, *tmp;
Harshitha Ramamurthy682d11d2016-08-15 14:17:19 -0700618 struct i40e_pf *pf;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600619 int ret = 0;
620
621 LIST_HEAD(cdevs_tmp);
622
623 mutex_lock(&i40e_client_instance_mutex);
624 list_for_each_entry_safe(cdev, tmp, &i40e_client_instances, list) {
625 if (strncmp(cdev->client->name, client->name,
626 I40E_CLIENT_STR_LENGTH))
627 continue;
Harshitha Ramamurthy682d11d2016-08-15 14:17:19 -0700628 pf = (struct i40e_pf *)cdev->lan_info.pf;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600629 if (test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state)) {
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600630 if (client->ops && client->ops->close)
631 client->ops->close(&cdev->lan_info, client,
632 false);
633 i40e_client_release_qvlist(&cdev->lan_info);
634 clear_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state);
635
636 dev_warn(&pf->pdev->dev,
637 "Client %s instance for PF id %d closed\n",
638 client->name, pf->hw.pf_id);
639 }
640 /* delete the client instance from the list */
Wei Yongjuneb271632016-07-26 14:58:30 +0000641 list_move(&cdev->list, &cdevs_tmp);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600642 dev_info(&pf->pdev->dev, "Deleted client instance of Client %s\n",
643 client->name);
644 }
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600645 mutex_unlock(&i40e_client_instance_mutex);
646
647 /* free the client device and release its vsi */
648 list_for_each_entry_safe(cdev, tmp, &cdevs_tmp, list) {
649 kfree(cdev);
650 }
651 return ret;
652}
653
654/**
655 * i40e_client_prepare - prepare client specific resources
656 * @client: pointer to the registered client
657 *
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600658 **/
Mitch Williams3bb83ba2017-02-09 23:46:50 -0800659static void i40e_client_prepare(struct i40e_client *client)
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600660{
661 struct i40e_device *ldev;
662 struct i40e_pf *pf;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600663
664 mutex_lock(&i40e_device_mutex);
665 list_for_each_entry(ldev, &i40e_devices, list) {
666 pf = ldev->pf;
667 /* Start the client subtask */
668 pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED;
669 i40e_service_event_schedule(pf);
670 }
671 mutex_unlock(&i40e_device_mutex);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600672}
673
674/**
675 * i40e_client_virtchnl_send - TBD
676 * @ldev: pointer to L2 context
677 * @client: Client pointer
678 * @vf_id: absolute VF identifier
679 * @msg: message buffer
680 * @len: length of message buffer
681 *
682 * Return 0 on success or < 0 on error
683 **/
684static int i40e_client_virtchnl_send(struct i40e_info *ldev,
685 struct i40e_client *client,
686 u32 vf_id, u8 *msg, u16 len)
687{
688 struct i40e_pf *pf = ldev->pf;
689 struct i40e_hw *hw = &pf->hw;
690 i40e_status err;
691
692 err = i40e_aq_send_msg_to_vf(hw, vf_id, I40E_VIRTCHNL_OP_IWARP,
693 0, msg, len, NULL);
694 if (err)
695 dev_err(&pf->pdev->dev, "Unable to send iWarp message to VF, error %d, aq status %d\n",
696 err, hw->aq.asq_last_status);
697
698 return err;
699}
700
701/**
702 * i40e_client_setup_qvlist
703 * @ldev: pointer to L2 context.
704 * @client: Client pointer.
705 * @qv_info: queue and vector list
706 *
707 * Return 0 on success or < 0 on error
708 **/
709static int i40e_client_setup_qvlist(struct i40e_info *ldev,
710 struct i40e_client *client,
711 struct i40e_qvlist_info *qvlist_info)
712{
713 struct i40e_pf *pf = ldev->pf;
714 struct i40e_hw *hw = &pf->hw;
715 struct i40e_qv_info *qv_info;
716 u32 v_idx, i, reg_idx, reg;
717 u32 size;
718
719 size = sizeof(struct i40e_qvlist_info) +
720 (sizeof(struct i40e_qv_info) * (qvlist_info->num_vectors - 1));
721 ldev->qvlist_info = kzalloc(size, GFP_KERNEL);
722 ldev->qvlist_info->num_vectors = qvlist_info->num_vectors;
723
724 for (i = 0; i < qvlist_info->num_vectors; i++) {
725 qv_info = &qvlist_info->qv_info[i];
726 if (!qv_info)
727 continue;
728 v_idx = qv_info->v_idx;
729
730 /* Validate vector id belongs to this client */
731 if ((v_idx >= (pf->iwarp_base_vector + pf->num_iwarp_msix)) ||
732 (v_idx < pf->iwarp_base_vector))
733 goto err;
734
735 ldev->qvlist_info->qv_info[i] = *qv_info;
736 reg_idx = I40E_PFINT_LNKLSTN(v_idx - 1);
737
738 if (qv_info->ceq_idx == I40E_QUEUE_INVALID_IDX) {
739 /* Special case - No CEQ mapped on this vector */
740 wr32(hw, reg_idx, I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK);
741 } else {
742 reg = (qv_info->ceq_idx &
743 I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
744 (I40E_QUEUE_TYPE_PE_CEQ <<
745 I40E_PFINT_LNKLSTN_FIRSTQ_TYPE_SHIFT);
746 wr32(hw, reg_idx, reg);
747
748 reg = (I40E_PFINT_CEQCTL_CAUSE_ENA_MASK |
749 (v_idx << I40E_PFINT_CEQCTL_MSIX_INDX_SHIFT) |
750 (qv_info->itr_idx <<
751 I40E_PFINT_CEQCTL_ITR_INDX_SHIFT) |
752 (I40E_QUEUE_END_OF_LIST <<
753 I40E_PFINT_CEQCTL_NEXTQ_INDX_SHIFT));
754 wr32(hw, I40E_PFINT_CEQCTL(qv_info->ceq_idx), reg);
755 }
756 if (qv_info->aeq_idx != I40E_QUEUE_INVALID_IDX) {
757 reg = (I40E_PFINT_AEQCTL_CAUSE_ENA_MASK |
758 (v_idx << I40E_PFINT_AEQCTL_MSIX_INDX_SHIFT) |
759 (qv_info->itr_idx <<
760 I40E_PFINT_AEQCTL_ITR_INDX_SHIFT));
761
762 wr32(hw, I40E_PFINT_AEQCTL, reg);
763 }
764 }
Avinash Dayanand70df9732016-07-27 12:02:36 -0700765 /* Mitigate sync problems with iwarp VF driver */
766 i40e_flush(hw);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600767 return 0;
768err:
769 kfree(ldev->qvlist_info);
770 ldev->qvlist_info = NULL;
771 return -EINVAL;
772}
773
774/**
775 * i40e_client_request_reset
776 * @ldev: pointer to L2 context.
777 * @client: Client pointer.
778 * @level: reset level
779 **/
780static void i40e_client_request_reset(struct i40e_info *ldev,
781 struct i40e_client *client,
782 u32 reset_level)
783{
784 struct i40e_pf *pf = ldev->pf;
785
786 switch (reset_level) {
787 case I40E_CLIENT_RESET_LEVEL_PF:
788 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
789 break;
790 case I40E_CLIENT_RESET_LEVEL_CORE:
791 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
792 break;
793 default:
794 dev_warn(&pf->pdev->dev,
795 "Client %s instance for PF id %d request an unsupported reset: %d.\n",
796 client->name, pf->hw.pf_id, reset_level);
797 break;
798 }
799
800 i40e_service_event_schedule(pf);
801}
802
803/**
804 * i40e_client_update_vsi_ctxt
805 * @ldev: pointer to L2 context.
806 * @client: Client pointer.
807 * @is_vf: if this for the VF
808 * @vf_id: if is_vf true this carries the vf_id
809 * @flag: Any device level setting that needs to be done for PE
810 * @valid_flag: Bits in this match up and enable changing of flag bits
811 *
812 * Return 0 on success or < 0 on error
813 **/
814static int i40e_client_update_vsi_ctxt(struct i40e_info *ldev,
815 struct i40e_client *client,
816 bool is_vf, u32 vf_id,
817 u32 flag, u32 valid_flag)
818{
819 struct i40e_pf *pf = ldev->pf;
820 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
821 struct i40e_vsi_context ctxt;
822 bool update = true;
823 i40e_status err;
824
825 /* TODO: for now do not allow setting VF's VSI setting */
826 if (is_vf)
827 return -EINVAL;
828
829 ctxt.seid = pf->main_vsi_seid;
830 ctxt.pf_num = pf->hw.pf_id;
831 err = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
832 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
833 if (err) {
834 dev_info(&pf->pdev->dev,
835 "couldn't get PF vsi config, err %s aq_err %s\n",
836 i40e_stat_str(&pf->hw, err),
837 i40e_aq_str(&pf->hw,
838 pf->hw.aq.asq_last_status));
839 return -ENOENT;
840 }
841
842 if ((valid_flag & I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE) &&
843 (flag & I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE)) {
844 ctxt.info.valid_sections =
845 cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
846 ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA;
847 } else if ((valid_flag & I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE) &&
848 !(flag & I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE)) {
849 ctxt.info.valid_sections =
850 cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
851 ctxt.info.queueing_opt_flags &= ~I40E_AQ_VSI_QUE_OPT_TCP_ENA;
852 } else {
853 update = false;
854 dev_warn(&pf->pdev->dev,
855 "Client %s instance for PF id %d request an unsupported Config: %x.\n",
856 client->name, pf->hw.pf_id, flag);
857 }
858
859 if (update) {
860 err = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
861 if (err) {
862 dev_info(&pf->pdev->dev,
863 "update VSI ctxt for PE failed, err %s aq_err %s\n",
864 i40e_stat_str(&pf->hw, err),
865 i40e_aq_str(&pf->hw,
866 pf->hw.aq.asq_last_status));
867 }
868 }
869 return err;
870}
871
872/**
873 * i40e_register_client - Register a i40e client driver with the L2 driver
874 * @client: pointer to the i40e_client struct
875 *
876 * Returns 0 on success or non-0 on error
877 **/
878int i40e_register_client(struct i40e_client *client)
879{
880 int ret = 0;
881 enum i40e_vsi_type vsi_type;
882
883 if (!client) {
884 ret = -EIO;
885 goto out;
886 }
887
888 if (strlen(client->name) == 0) {
889 pr_info("i40e: Failed to register client with no name\n");
890 ret = -EIO;
891 goto out;
892 }
893
894 mutex_lock(&i40e_client_mutex);
895 if (i40e_client_is_registered(client)) {
896 pr_info("i40e: Client %s has already been registered!\n",
897 client->name);
898 mutex_unlock(&i40e_client_mutex);
899 ret = -EEXIST;
900 goto out;
901 }
902
903 if ((client->version.major != I40E_CLIENT_VERSION_MAJOR) ||
904 (client->version.minor != I40E_CLIENT_VERSION_MINOR)) {
905 pr_info("i40e: Failed to register client %s due to mismatched client interface version\n",
906 client->name);
907 pr_info("Client is using version: %02d.%02d.%02d while LAN driver supports %s\n",
908 client->version.major, client->version.minor,
909 client->version.build,
910 i40e_client_interface_version_str);
911 mutex_unlock(&i40e_client_mutex);
912 ret = -EIO;
913 goto out;
914 }
915
916 vsi_type = i40e_client_type_to_vsi_type(client->type);
917 if (vsi_type == I40E_VSI_TYPE_UNKNOWN) {
918 pr_info("i40e: Failed to register client %s due to unknown client type %d\n",
919 client->name, client->type);
920 mutex_unlock(&i40e_client_mutex);
921 ret = -EIO;
922 goto out;
923 }
924 list_add(&client->list, &i40e_clients);
925 set_bit(__I40E_CLIENT_REGISTERED, &client->state);
926 mutex_unlock(&i40e_client_mutex);
927
Mitch Williams3bb83ba2017-02-09 23:46:50 -0800928 i40e_client_prepare(client);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600929
Mitch Williams3bb83ba2017-02-09 23:46:50 -0800930 pr_info("i40e: Registered client %s\n", client->name);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600931out:
932 return ret;
933}
934EXPORT_SYMBOL(i40e_register_client);
935
936/**
937 * i40e_unregister_client - Unregister a i40e client driver with the L2 driver
938 * @client: pointer to the i40e_client struct
939 *
940 * Returns 0 on success or non-0 on error
941 **/
942int i40e_unregister_client(struct i40e_client *client)
943{
944 int ret = 0;
945
946 /* When a unregister request comes through we would have to send
947 * a close for each of the client instances that were opened.
948 * client_release function is called to handle this.
949 */
Catherine Sullivancd3be162016-06-23 14:08:46 -0700950 mutex_lock(&i40e_client_mutex);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600951 if (!client || i40e_client_release(client)) {
952 ret = -EIO;
953 goto out;
954 }
955
956 /* TODO: check if device is in reset, or if that matters? */
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600957 if (!i40e_client_is_registered(client)) {
958 pr_info("i40e: Client %s has not been registered\n",
959 client->name);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600960 ret = -ENODEV;
961 goto out;
962 }
Mitch Williams7be963222016-09-14 16:24:36 -0700963 clear_bit(__I40E_CLIENT_REGISTERED, &client->state);
964 list_del(&client->list);
965 pr_info("i40e: Unregistered client %s with return code %d\n",
966 client->name, ret);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600967out:
Catherine Sullivancd3be162016-06-23 14:08:46 -0700968 mutex_unlock(&i40e_client_mutex);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600969 return ret;
970}
971EXPORT_SYMBOL(i40e_unregister_client);