1 /*******************************************************************************
3 * Intel Ethernet Controller XL710 Family Linux Driver
4 * Copyright(c) 2013 - 2015 Intel Corporation.
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.
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
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/>.
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
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
25 ******************************************************************************/
27 #include <linux/list.h>
28 #include <linux/errno.h>
31 #include "i40e_prototype.h"
32 #include "i40e_client.h"
34 static const char i40e_client_interface_version_str[] = I40E_CLIENT_VERSION_STR;
36 static LIST_HEAD(i40e_devices);
37 static DEFINE_MUTEX(i40e_device_mutex);
39 static LIST_HEAD(i40e_clients);
40 static DEFINE_MUTEX(i40e_client_mutex);
42 static LIST_HEAD(i40e_client_instances);
43 static DEFINE_MUTEX(i40e_client_instance_mutex);
45 static int i40e_client_virtchnl_send(struct i40e_info *ldev,
46 struct i40e_client *client,
47 u32 vf_id, u8 *msg, u16 len);
49 static int i40e_client_setup_qvlist(struct i40e_info *ldev,
50 struct i40e_client *client,
51 struct i40e_qvlist_info *qvlist_info);
53 static void i40e_client_request_reset(struct i40e_info *ldev,
54 struct i40e_client *client,
57 static 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);
62 static 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,
70 * i40e_client_type_to_vsi_type - convert client type to vsi type
71 * @client_type: the i40e_client type
73 * returns the related vsi type value
76 enum i40e_vsi_type i40e_client_type_to_vsi_type(enum i40e_client_type type)
79 case I40E_CLIENT_IWARP:
80 return I40E_VSI_IWARP;
82 case I40E_CLIENT_VMDQ2:
83 return I40E_VSI_VMDQ2;
86 pr_err("i40e: Client type unknown\n");
87 return I40E_VSI_TYPE_UNKNOWN;
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
98 int i40e_client_get_params(struct i40e_vsi *vsi, struct i40e_params *params)
100 struct i40e_dcbx_config *dcb_cfg = &vsi->back->hw.local_dcbx_config;
103 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
104 u8 tc = dcb_cfg->etscfg.prioritytable[i];
107 /* If TC is not enabled for VSI use TC0 for UP */
108 if (!(vsi->tc_config.enabled_tc & BIT(tc)))
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",
121 params->mtu = vsi->netdev->mtu;
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
132 * If there is a client to this VSI, call the client
135 i40e_notify_client_of_vf_msg(struct i40e_vsi *vsi, u32 vf_id, u8 *msg, u16 len)
137 struct i40e_client_instance *cdev;
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) {
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");
151 if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED,
153 dev_dbg(&vsi->back->pdev->dev, "Client is not open, abort virtchnl_receive\n");
156 cdev->client->ops->virtchnl_receive(&cdev->lan_info,
161 mutex_unlock(&i40e_client_instance_mutex);
165 * i40e_notify_client_of_l2_param_changes - call the client notify callback
166 * @vsi: the VSI with l2 param changes
168 * If there is a client to this VSI, call the client
170 void i40e_notify_client_of_l2_param_changes(struct i40e_vsi *vsi)
172 struct i40e_client_instance *cdev;
173 struct i40e_params params;
177 memset(¶ms, 0, sizeof(params));
178 i40e_client_get_params(vsi, ¶ms);
179 mutex_lock(&i40e_client_instance_mutex);
180 list_for_each_entry(cdev, &i40e_client_instances, list) {
181 if (cdev->lan_info.pf == vsi->back) {
183 !cdev->client->ops ||
184 !cdev->client->ops->l2_param_change) {
185 dev_dbg(&vsi->back->pdev->dev,
186 "Cannot locate client instance l2_param_change routine\n");
189 if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED,
191 dev_dbg(&vsi->back->pdev->dev, "Client is not open, abort l2 param change\n");
194 cdev->lan_info.params = params;
195 cdev->client->ops->l2_param_change(&cdev->lan_info,
200 mutex_unlock(&i40e_client_instance_mutex);
204 * i40e_notify_client_of_netdev_open - call the client open callback
205 * @vsi: the VSI with netdev opened
207 * If there is a client to this netdev, call the client with open
209 void i40e_notify_client_of_netdev_open(struct i40e_vsi *vsi)
211 struct i40e_client_instance *cdev;
215 mutex_lock(&i40e_client_instance_mutex);
216 list_for_each_entry(cdev, &i40e_client_instances, list) {
217 if (cdev->lan_info.netdev == vsi->netdev) {
219 !cdev->client->ops || !cdev->client->ops->open) {
220 dev_dbg(&vsi->back->pdev->dev,
221 "Cannot locate client instance open routine\n");
224 cdev->client->ops->open(&cdev->lan_info, cdev->client);
227 mutex_unlock(&i40e_client_instance_mutex);
231 * i40e_client_release_qvlist
232 * @ldev: pointer to L2 context.
235 static void i40e_client_release_qvlist(struct i40e_info *ldev)
237 struct i40e_qvlist_info *qvlist_info = ldev->qvlist_info;
240 if (!ldev->qvlist_info)
243 for (i = 0; i < qvlist_info->num_vectors; i++) {
244 struct i40e_pf *pf = ldev->pf;
245 struct i40e_qv_info *qv_info;
248 qv_info = &qvlist_info->qv_info[i];
251 reg_idx = I40E_PFINT_LNKLSTN(qv_info->v_idx - 1);
252 wr32(&pf->hw, reg_idx, I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK);
254 kfree(ldev->qvlist_info);
255 ldev->qvlist_info = NULL;
259 * i40e_notify_client_of_netdev_close - call the client close callback
260 * @vsi: the VSI with netdev closed
261 * @reset: true when close called due to a reset pending
263 * If there is a client to this netdev, call the client with close
265 void i40e_notify_client_of_netdev_close(struct i40e_vsi *vsi, bool reset)
267 struct i40e_client_instance *cdev;
271 mutex_lock(&i40e_client_instance_mutex);
272 list_for_each_entry(cdev, &i40e_client_instances, list) {
273 if (cdev->lan_info.netdev == vsi->netdev) {
275 !cdev->client->ops || !cdev->client->ops->close) {
276 dev_dbg(&vsi->back->pdev->dev,
277 "Cannot locate client instance close routine\n");
280 cdev->client->ops->close(&cdev->lan_info, cdev->client,
282 i40e_client_release_qvlist(&cdev->lan_info);
285 mutex_unlock(&i40e_client_instance_mutex);
289 * i40e_notify_client_of_vf_reset - call the client vf reset callback
290 * @pf: PF device pointer
291 * @vf_id: asolute id of VF being reset
293 * If there is a client attached to this PF, notify when a VF is reset
295 void i40e_notify_client_of_vf_reset(struct i40e_pf *pf, u32 vf_id)
297 struct i40e_client_instance *cdev;
301 mutex_lock(&i40e_client_instance_mutex);
302 list_for_each_entry(cdev, &i40e_client_instances, list) {
303 if (cdev->lan_info.pf == pf) {
305 !cdev->client->ops ||
306 !cdev->client->ops->vf_reset) {
307 dev_dbg(&pf->pdev->dev,
308 "Cannot locate client instance VF reset routine\n");
311 if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED,
313 dev_dbg(&pf->pdev->dev, "Client is not open, abort vf-reset\n");
316 cdev->client->ops->vf_reset(&cdev->lan_info,
317 cdev->client, vf_id);
320 mutex_unlock(&i40e_client_instance_mutex);
324 * i40e_notify_client_of_vf_enable - call the client vf notification callback
325 * @pf: PF device pointer
326 * @num_vfs: the number of VFs currently enabled, 0 for disable
328 * If there is a client attached to this PF, call its VF notification routine
330 void i40e_notify_client_of_vf_enable(struct i40e_pf *pf, u32 num_vfs)
332 struct i40e_client_instance *cdev;
336 mutex_lock(&i40e_client_instance_mutex);
337 list_for_each_entry(cdev, &i40e_client_instances, list) {
338 if (cdev->lan_info.pf == pf) {
340 !cdev->client->ops ||
341 !cdev->client->ops->vf_enable) {
342 dev_dbg(&pf->pdev->dev,
343 "Cannot locate client instance VF enable routine\n");
346 if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED,
348 dev_dbg(&pf->pdev->dev, "Client is not open, abort vf-enable\n");
351 cdev->client->ops->vf_enable(&cdev->lan_info,
352 cdev->client, num_vfs);
355 mutex_unlock(&i40e_client_instance_mutex);
359 * i40e_vf_client_capable - ask the client if it likes the specified VF
360 * @pf: PF device pointer
361 * @vf_id: the VF in question
363 * If there is a client of the specified type attached to this PF, call
364 * its vf_capable routine
366 int i40e_vf_client_capable(struct i40e_pf *pf, u32 vf_id,
367 enum i40e_client_type type)
369 struct i40e_client_instance *cdev;
374 mutex_lock(&i40e_client_instance_mutex);
375 list_for_each_entry(cdev, &i40e_client_instances, list) {
376 if (cdev->lan_info.pf == pf) {
378 !cdev->client->ops ||
379 !cdev->client->ops->vf_capable ||
380 !(cdev->client->type == type)) {
381 dev_dbg(&pf->pdev->dev,
382 "Cannot locate client instance VF capability routine\n");
385 if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED,
387 dev_dbg(&pf->pdev->dev, "Client is not open, abort vf-capable\n");
390 capable = cdev->client->ops->vf_capable(&cdev->lan_info,
396 mutex_unlock(&i40e_client_instance_mutex);
401 * i40e_vsi_lookup - finds a matching VSI from the PF list starting at start_vsi
402 * @pf: board private structure
404 * @start_vsi: a VSI pointer from where to start the search
406 * Returns non NULL on success or NULL for failure
408 struct i40e_vsi *i40e_vsi_lookup(struct i40e_pf *pf,
409 enum i40e_vsi_type type,
410 struct i40e_vsi *start_vsi)
412 struct i40e_vsi *vsi;
416 for (i = 0; i < pf->num_alloc_vsi; i++) {
418 if (vsi == start_vsi)
422 for (; i < pf->num_alloc_vsi; i++) {
424 if (vsi && vsi->type == type)
432 * i40e_client_add_instance - add a client instance struct to the instance list
433 * @pf: pointer to the board struct
434 * @client: pointer to a client struct in the client list.
436 * Returns cdev ptr on success, NULL on failure
439 struct i40e_client_instance *i40e_client_add_instance(struct i40e_pf *pf,
440 struct i40e_client *client)
442 struct i40e_client_instance *cdev;
443 struct netdev_hw_addr *mac = NULL;
444 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
446 mutex_lock(&i40e_client_instance_mutex);
447 list_for_each_entry(cdev, &i40e_client_instances, list) {
448 if ((cdev->lan_info.pf == pf) && (cdev->client == client)) {
453 cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
457 cdev->lan_info.pf = (void *)pf;
458 cdev->lan_info.netdev = vsi->netdev;
459 cdev->lan_info.pcidev = pf->pdev;
460 cdev->lan_info.fid = pf->hw.pf_id;
461 cdev->lan_info.ftype = I40E_CLIENT_FTYPE_PF;
462 cdev->lan_info.hw_addr = pf->hw.hw_addr;
463 cdev->lan_info.ops = &i40e_lan_ops;
464 cdev->lan_info.version.major = I40E_CLIENT_VERSION_MAJOR;
465 cdev->lan_info.version.minor = I40E_CLIENT_VERSION_MINOR;
466 cdev->lan_info.version.build = I40E_CLIENT_VERSION_BUILD;
467 cdev->lan_info.fw_maj_ver = pf->hw.aq.fw_maj_ver;
468 cdev->lan_info.fw_min_ver = pf->hw.aq.fw_min_ver;
469 cdev->lan_info.fw_build = pf->hw.aq.fw_build;
470 set_bit(__I40E_CLIENT_INSTANCE_NONE, &cdev->state);
472 if (i40e_client_get_params(vsi, &cdev->lan_info.params)) {
478 cdev->lan_info.msix_count = pf->num_iwarp_msix;
479 cdev->lan_info.msix_entries = &pf->msix_entries[pf->iwarp_base_vector];
481 mac = list_first_entry(&cdev->lan_info.netdev->dev_addrs.list,
482 struct netdev_hw_addr, list);
484 ether_addr_copy(cdev->lan_info.lanmac, mac->addr);
486 dev_err(&pf->pdev->dev, "MAC address list is empty!\n");
488 cdev->client = client;
489 INIT_LIST_HEAD(&cdev->list);
490 list_add(&cdev->list, &i40e_client_instances);
492 mutex_unlock(&i40e_client_instance_mutex);
497 * i40e_client_del_instance - removes a client instance from the list
498 * @pf: pointer to the board struct
500 * Returns 0 on success or non-0 on error
503 int i40e_client_del_instance(struct i40e_pf *pf, struct i40e_client *client)
505 struct i40e_client_instance *cdev, *tmp;
508 mutex_lock(&i40e_client_instance_mutex);
509 list_for_each_entry_safe(cdev, tmp, &i40e_client_instances, list) {
510 if ((cdev->lan_info.pf != pf) || (cdev->client != client))
513 dev_info(&pf->pdev->dev, "Deleted instance of Client %s, of dev %d bus=0x%02x func=0x%02x)\n",
514 client->name, pf->hw.pf_id,
515 pf->hw.bus.device, pf->hw.bus.func);
516 list_del(&cdev->list);
521 mutex_unlock(&i40e_client_instance_mutex);
526 * i40e_client_subtask - client maintenance work
527 * @pf: board private structure
529 void i40e_client_subtask(struct i40e_pf *pf)
531 struct i40e_client_instance *cdev;
532 struct i40e_client *client;
535 if (!(pf->flags & I40E_FLAG_SERVICE_CLIENT_REQUESTED))
537 pf->flags &= ~I40E_FLAG_SERVICE_CLIENT_REQUESTED;
539 /* If we're down or resetting, just bail */
540 if (test_bit(__I40E_DOWN, &pf->state) ||
541 test_bit(__I40E_CONFIG_BUSY, &pf->state))
544 /* Check client state and instantiate client if client registered */
545 mutex_lock(&i40e_client_mutex);
546 list_for_each_entry(client, &i40e_clients, list) {
547 /* first check client is registered */
548 if (!test_bit(__I40E_CLIENT_REGISTERED, &client->state))
551 /* Do we also need the LAN VSI to be up, to create instance */
552 if (!(client->flags & I40E_CLIENT_FLAGS_LAUNCH_ON_PROBE)) {
553 /* check if L2 VSI is up, if not we are not ready */
554 if (test_bit(__I40E_DOWN, &pf->vsi[pf->lan_vsi]->state))
558 /* Add the client instance to the instance list */
559 cdev = i40e_client_add_instance(pf, client);
563 /* Also up the ref_cnt of no. of instances of this client */
564 atomic_inc(&client->ref_cnt);
565 dev_info(&pf->pdev->dev, "Added instance of Client %s to PF%d bus=0x%02x func=0x%02x\n",
566 client->name, pf->hw.pf_id,
567 pf->hw.bus.device, pf->hw.bus.func);
569 mutex_lock(&i40e_client_instance_mutex);
570 /* Send an Open request to the client */
571 atomic_inc(&cdev->ref_cnt);
572 if (client->ops && client->ops->open)
573 ret = client->ops->open(&cdev->lan_info, client);
574 atomic_dec(&cdev->ref_cnt);
576 set_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state);
578 /* remove client instance */
579 mutex_unlock(&i40e_client_instance_mutex);
580 i40e_client_del_instance(pf, client);
581 atomic_dec(&client->ref_cnt);
584 mutex_unlock(&i40e_client_instance_mutex);
586 mutex_unlock(&i40e_client_mutex);
590 * i40e_lan_add_device - add a lan device struct to the list of lan devices
591 * @pf: pointer to the board struct
593 * Returns 0 on success or none 0 on error
595 int i40e_lan_add_device(struct i40e_pf *pf)
597 struct i40e_device *ldev;
600 mutex_lock(&i40e_device_mutex);
601 list_for_each_entry(ldev, &i40e_devices, list) {
602 if (ldev->pf == pf) {
607 ldev = kzalloc(sizeof(*ldev), GFP_KERNEL);
613 INIT_LIST_HEAD(&ldev->list);
614 list_add(&ldev->list, &i40e_devices);
615 dev_info(&pf->pdev->dev, "Added LAN device PF%d bus=0x%02x func=0x%02x\n",
616 pf->hw.pf_id, pf->hw.bus.device, pf->hw.bus.func);
618 /* Since in some cases register may have happened before a device gets
619 * added, we can schedule a subtask to go initiate the clients.
621 pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED;
622 i40e_service_event_schedule(pf);
625 mutex_unlock(&i40e_device_mutex);
630 * i40e_lan_del_device - removes a lan device from the device list
631 * @pf: pointer to the board struct
633 * Returns 0 on success or non-0 on error
635 int i40e_lan_del_device(struct i40e_pf *pf)
637 struct i40e_device *ldev, *tmp;
640 mutex_lock(&i40e_device_mutex);
641 list_for_each_entry_safe(ldev, tmp, &i40e_devices, list) {
642 if (ldev->pf == pf) {
643 dev_info(&pf->pdev->dev, "Deleted LAN device PF%d bus=0x%02x func=0x%02x\n",
644 pf->hw.pf_id, pf->hw.bus.device,
646 list_del(&ldev->list);
653 mutex_unlock(&i40e_device_mutex);
658 * i40e_client_release - release client specific resources
659 * @client: pointer to the registered client
661 * Return 0 on success or < 0 on error
663 static int i40e_client_release(struct i40e_client *client)
665 struct i40e_client_instance *cdev, *tmp;
669 LIST_HEAD(cdevs_tmp);
671 mutex_lock(&i40e_client_instance_mutex);
672 list_for_each_entry_safe(cdev, tmp, &i40e_client_instances, list) {
673 if (strncmp(cdev->client->name, client->name,
674 I40E_CLIENT_STR_LENGTH))
676 pf = (struct i40e_pf *)cdev->lan_info.pf;
677 if (test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state)) {
678 if (atomic_read(&cdev->ref_cnt) > 0) {
679 ret = I40E_ERR_NOT_READY;
682 if (client->ops && client->ops->close)
683 client->ops->close(&cdev->lan_info, client,
685 i40e_client_release_qvlist(&cdev->lan_info);
686 clear_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state);
688 dev_warn(&pf->pdev->dev,
689 "Client %s instance for PF id %d closed\n",
690 client->name, pf->hw.pf_id);
692 /* delete the client instance from the list */
693 list_move(&cdev->list, &cdevs_tmp);
694 atomic_dec(&client->ref_cnt);
695 dev_info(&pf->pdev->dev, "Deleted client instance of Client %s\n",
699 mutex_unlock(&i40e_client_instance_mutex);
701 /* free the client device and release its vsi */
702 list_for_each_entry_safe(cdev, tmp, &cdevs_tmp, list) {
709 * i40e_client_prepare - prepare client specific resources
710 * @client: pointer to the registered client
712 * Return 0 on success or < 0 on error
714 static int i40e_client_prepare(struct i40e_client *client)
716 struct i40e_device *ldev;
720 mutex_lock(&i40e_device_mutex);
721 list_for_each_entry(ldev, &i40e_devices, list) {
723 /* Start the client subtask */
724 pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED;
725 i40e_service_event_schedule(pf);
727 mutex_unlock(&i40e_device_mutex);
732 * i40e_client_virtchnl_send - TBD
733 * @ldev: pointer to L2 context
734 * @client: Client pointer
735 * @vf_id: absolute VF identifier
736 * @msg: message buffer
737 * @len: length of message buffer
739 * Return 0 on success or < 0 on error
741 static int i40e_client_virtchnl_send(struct i40e_info *ldev,
742 struct i40e_client *client,
743 u32 vf_id, u8 *msg, u16 len)
745 struct i40e_pf *pf = ldev->pf;
746 struct i40e_hw *hw = &pf->hw;
749 err = i40e_aq_send_msg_to_vf(hw, vf_id, I40E_VIRTCHNL_OP_IWARP,
752 dev_err(&pf->pdev->dev, "Unable to send iWarp message to VF, error %d, aq status %d\n",
753 err, hw->aq.asq_last_status);
759 * i40e_client_setup_qvlist
760 * @ldev: pointer to L2 context.
761 * @client: Client pointer.
762 * @qv_info: queue and vector list
764 * Return 0 on success or < 0 on error
766 static int i40e_client_setup_qvlist(struct i40e_info *ldev,
767 struct i40e_client *client,
768 struct i40e_qvlist_info *qvlist_info)
770 struct i40e_pf *pf = ldev->pf;
771 struct i40e_hw *hw = &pf->hw;
772 struct i40e_qv_info *qv_info;
773 u32 v_idx, i, reg_idx, reg;
776 size = sizeof(struct i40e_qvlist_info) +
777 (sizeof(struct i40e_qv_info) * (qvlist_info->num_vectors - 1));
778 ldev->qvlist_info = kzalloc(size, GFP_KERNEL);
779 ldev->qvlist_info->num_vectors = qvlist_info->num_vectors;
781 for (i = 0; i < qvlist_info->num_vectors; i++) {
782 qv_info = &qvlist_info->qv_info[i];
785 v_idx = qv_info->v_idx;
787 /* Validate vector id belongs to this client */
788 if ((v_idx >= (pf->iwarp_base_vector + pf->num_iwarp_msix)) ||
789 (v_idx < pf->iwarp_base_vector))
792 ldev->qvlist_info->qv_info[i] = *qv_info;
793 reg_idx = I40E_PFINT_LNKLSTN(v_idx - 1);
795 if (qv_info->ceq_idx == I40E_QUEUE_INVALID_IDX) {
796 /* Special case - No CEQ mapped on this vector */
797 wr32(hw, reg_idx, I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK);
799 reg = (qv_info->ceq_idx &
800 I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
801 (I40E_QUEUE_TYPE_PE_CEQ <<
802 I40E_PFINT_LNKLSTN_FIRSTQ_TYPE_SHIFT);
803 wr32(hw, reg_idx, reg);
805 reg = (I40E_PFINT_CEQCTL_CAUSE_ENA_MASK |
806 (v_idx << I40E_PFINT_CEQCTL_MSIX_INDX_SHIFT) |
808 I40E_PFINT_CEQCTL_ITR_INDX_SHIFT) |
809 (I40E_QUEUE_END_OF_LIST <<
810 I40E_PFINT_CEQCTL_NEXTQ_INDX_SHIFT));
811 wr32(hw, I40E_PFINT_CEQCTL(qv_info->ceq_idx), reg);
813 if (qv_info->aeq_idx != I40E_QUEUE_INVALID_IDX) {
814 reg = (I40E_PFINT_AEQCTL_CAUSE_ENA_MASK |
815 (v_idx << I40E_PFINT_AEQCTL_MSIX_INDX_SHIFT) |
817 I40E_PFINT_AEQCTL_ITR_INDX_SHIFT));
819 wr32(hw, I40E_PFINT_AEQCTL, reg);
822 /* Mitigate sync problems with iwarp VF driver */
826 kfree(ldev->qvlist_info);
827 ldev->qvlist_info = NULL;
832 * i40e_client_request_reset
833 * @ldev: pointer to L2 context.
834 * @client: Client pointer.
835 * @level: reset level
837 static void i40e_client_request_reset(struct i40e_info *ldev,
838 struct i40e_client *client,
841 struct i40e_pf *pf = ldev->pf;
843 switch (reset_level) {
844 case I40E_CLIENT_RESET_LEVEL_PF:
845 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
847 case I40E_CLIENT_RESET_LEVEL_CORE:
848 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
851 dev_warn(&pf->pdev->dev,
852 "Client %s instance for PF id %d request an unsupported reset: %d.\n",
853 client->name, pf->hw.pf_id, reset_level);
857 i40e_service_event_schedule(pf);
861 * i40e_client_update_vsi_ctxt
862 * @ldev: pointer to L2 context.
863 * @client: Client pointer.
864 * @is_vf: if this for the VF
865 * @vf_id: if is_vf true this carries the vf_id
866 * @flag: Any device level setting that needs to be done for PE
867 * @valid_flag: Bits in this match up and enable changing of flag bits
869 * Return 0 on success or < 0 on error
871 static int i40e_client_update_vsi_ctxt(struct i40e_info *ldev,
872 struct i40e_client *client,
873 bool is_vf, u32 vf_id,
874 u32 flag, u32 valid_flag)
876 struct i40e_pf *pf = ldev->pf;
877 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
878 struct i40e_vsi_context ctxt;
882 /* TODO: for now do not allow setting VF's VSI setting */
886 ctxt.seid = pf->main_vsi_seid;
887 ctxt.pf_num = pf->hw.pf_id;
888 err = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
889 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
891 dev_info(&pf->pdev->dev,
892 "couldn't get PF vsi config, err %s aq_err %s\n",
893 i40e_stat_str(&pf->hw, err),
895 pf->hw.aq.asq_last_status));
899 if ((valid_flag & I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE) &&
900 (flag & I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE)) {
901 ctxt.info.valid_sections =
902 cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
903 ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA;
904 } else if ((valid_flag & I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE) &&
905 !(flag & I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE)) {
906 ctxt.info.valid_sections =
907 cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
908 ctxt.info.queueing_opt_flags &= ~I40E_AQ_VSI_QUE_OPT_TCP_ENA;
911 dev_warn(&pf->pdev->dev,
912 "Client %s instance for PF id %d request an unsupported Config: %x.\n",
913 client->name, pf->hw.pf_id, flag);
917 err = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
919 dev_info(&pf->pdev->dev,
920 "update VSI ctxt for PE failed, err %s aq_err %s\n",
921 i40e_stat_str(&pf->hw, err),
923 pf->hw.aq.asq_last_status));
930 * i40e_register_client - Register a i40e client driver with the L2 driver
931 * @client: pointer to the i40e_client struct
933 * Returns 0 on success or non-0 on error
935 int i40e_register_client(struct i40e_client *client)
938 enum i40e_vsi_type vsi_type;
945 if (strlen(client->name) == 0) {
946 pr_info("i40e: Failed to register client with no name\n");
951 mutex_lock(&i40e_client_mutex);
952 if (i40e_client_is_registered(client)) {
953 pr_info("i40e: Client %s has already been registered!\n",
955 mutex_unlock(&i40e_client_mutex);
960 if ((client->version.major != I40E_CLIENT_VERSION_MAJOR) ||
961 (client->version.minor != I40E_CLIENT_VERSION_MINOR)) {
962 pr_info("i40e: Failed to register client %s due to mismatched client interface version\n",
964 pr_info("Client is using version: %02d.%02d.%02d while LAN driver supports %s\n",
965 client->version.major, client->version.minor,
966 client->version.build,
967 i40e_client_interface_version_str);
968 mutex_unlock(&i40e_client_mutex);
973 vsi_type = i40e_client_type_to_vsi_type(client->type);
974 if (vsi_type == I40E_VSI_TYPE_UNKNOWN) {
975 pr_info("i40e: Failed to register client %s due to unknown client type %d\n",
976 client->name, client->type);
977 mutex_unlock(&i40e_client_mutex);
981 list_add(&client->list, &i40e_clients);
982 set_bit(__I40E_CLIENT_REGISTERED, &client->state);
983 mutex_unlock(&i40e_client_mutex);
985 if (i40e_client_prepare(client)) {
990 pr_info("i40e: Registered client %s with return code %d\n",
995 EXPORT_SYMBOL(i40e_register_client);
998 * i40e_unregister_client - Unregister a i40e client driver with the L2 driver
999 * @client: pointer to the i40e_client struct
1001 * Returns 0 on success or non-0 on error
1003 int i40e_unregister_client(struct i40e_client *client)
1007 /* When a unregister request comes through we would have to send
1008 * a close for each of the client instances that were opened.
1009 * client_release function is called to handle this.
1011 mutex_lock(&i40e_client_mutex);
1012 if (!client || i40e_client_release(client)) {
1017 /* TODO: check if device is in reset, or if that matters? */
1018 if (!i40e_client_is_registered(client)) {
1019 pr_info("i40e: Client %s has not been registered\n",
1024 if (atomic_read(&client->ref_cnt) == 0) {
1025 clear_bit(__I40E_CLIENT_REGISTERED, &client->state);
1026 list_del(&client->list);
1027 pr_info("i40e: Unregistered client %s with return code %d\n",
1030 ret = I40E_ERR_NOT_READY;
1031 pr_err("i40e: Client %s failed unregister - client has open instances\n",
1036 mutex_unlock(&i40e_client_mutex);
1039 EXPORT_SYMBOL(i40e_unregister_client);