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 cdev
->client
->ops
->virtchnl_receive(&cdev
->lan_info
,
156 mutex_unlock(&i40e_client_instance_mutex
);
160 * i40e_notify_client_of_l2_param_changes - call the client notify callback
161 * @vsi: the VSI with l2 param changes
163 * If there is a client to this VSI, call the client
165 void i40e_notify_client_of_l2_param_changes(struct i40e_vsi
*vsi
)
167 struct i40e_client_instance
*cdev
;
168 struct i40e_params params
;
172 memset(¶ms
, 0, sizeof(params
));
173 i40e_client_get_params(vsi
, ¶ms
);
174 mutex_lock(&i40e_client_instance_mutex
);
175 list_for_each_entry(cdev
, &i40e_client_instances
, list
) {
176 if (cdev
->lan_info
.pf
== vsi
->back
) {
178 !cdev
->client
->ops
||
179 !cdev
->client
->ops
->l2_param_change
) {
180 dev_dbg(&vsi
->back
->pdev
->dev
,
181 "Cannot locate client instance l2_param_change routine\n");
184 cdev
->lan_info
.params
= params
;
185 cdev
->client
->ops
->l2_param_change(&cdev
->lan_info
,
190 mutex_unlock(&i40e_client_instance_mutex
);
194 * i40e_notify_client_of_netdev_open - call the client open callback
195 * @vsi: the VSI with netdev opened
197 * If there is a client to this netdev, call the client with open
199 void i40e_notify_client_of_netdev_open(struct i40e_vsi
*vsi
)
201 struct i40e_client_instance
*cdev
;
206 mutex_lock(&i40e_client_instance_mutex
);
207 list_for_each_entry(cdev
, &i40e_client_instances
, list
) {
208 if (cdev
->lan_info
.netdev
== vsi
->netdev
) {
210 !cdev
->client
->ops
|| !cdev
->client
->ops
->open
) {
211 dev_dbg(&vsi
->back
->pdev
->dev
,
212 "Cannot locate client instance open routine\n");
215 if (!(test_bit(__I40E_CLIENT_INSTANCE_OPENED
,
217 ret
= cdev
->client
->ops
->open(&cdev
->lan_info
,
220 set_bit(__I40E_CLIENT_INSTANCE_OPENED
,
225 mutex_unlock(&i40e_client_instance_mutex
);
229 * i40e_client_release_qvlist
230 * @ldev: pointer to L2 context.
233 static void i40e_client_release_qvlist(struct i40e_info
*ldev
)
235 struct i40e_qvlist_info
*qvlist_info
= ldev
->qvlist_info
;
238 if (!ldev
->qvlist_info
)
241 for (i
= 0; i
< qvlist_info
->num_vectors
; i
++) {
242 struct i40e_pf
*pf
= ldev
->pf
;
243 struct i40e_qv_info
*qv_info
;
246 qv_info
= &qvlist_info
->qv_info
[i
];
249 reg_idx
= I40E_PFINT_LNKLSTN(qv_info
->v_idx
- 1);
250 wr32(&pf
->hw
, reg_idx
, I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK
);
252 kfree(ldev
->qvlist_info
);
253 ldev
->qvlist_info
= NULL
;
257 * i40e_notify_client_of_netdev_close - call the client close callback
258 * @vsi: the VSI with netdev closed
259 * @reset: true when close called due to a reset pending
261 * If there is a client to this netdev, call the client with close
263 void i40e_notify_client_of_netdev_close(struct i40e_vsi
*vsi
, bool reset
)
265 struct i40e_client_instance
*cdev
;
269 mutex_lock(&i40e_client_instance_mutex
);
270 list_for_each_entry(cdev
, &i40e_client_instances
, list
) {
271 if (cdev
->lan_info
.netdev
== vsi
->netdev
) {
273 !cdev
->client
->ops
|| !cdev
->client
->ops
->close
) {
274 dev_dbg(&vsi
->back
->pdev
->dev
,
275 "Cannot locate client instance close routine\n");
278 cdev
->client
->ops
->close(&cdev
->lan_info
, cdev
->client
,
280 i40e_client_release_qvlist(&cdev
->lan_info
);
283 mutex_unlock(&i40e_client_instance_mutex
);
287 * i40e_notify_client_of_vf_reset - call the client vf reset callback
288 * @pf: PF device pointer
289 * @vf_id: asolute id of VF being reset
291 * If there is a client attached to this PF, notify when a VF is reset
293 void i40e_notify_client_of_vf_reset(struct i40e_pf
*pf
, u32 vf_id
)
295 struct i40e_client_instance
*cdev
;
299 mutex_lock(&i40e_client_instance_mutex
);
300 list_for_each_entry(cdev
, &i40e_client_instances
, list
) {
301 if (cdev
->lan_info
.pf
== pf
) {
303 !cdev
->client
->ops
||
304 !cdev
->client
->ops
->vf_reset
) {
305 dev_dbg(&pf
->pdev
->dev
,
306 "Cannot locate client instance VF reset routine\n");
309 cdev
->client
->ops
->vf_reset(&cdev
->lan_info
,
310 cdev
->client
, vf_id
);
313 mutex_unlock(&i40e_client_instance_mutex
);
317 * i40e_notify_client_of_vf_enable - call the client vf notification callback
318 * @pf: PF device pointer
319 * @num_vfs: the number of VFs currently enabled, 0 for disable
321 * If there is a client attached to this PF, call its VF notification routine
323 void i40e_notify_client_of_vf_enable(struct i40e_pf
*pf
, u32 num_vfs
)
325 struct i40e_client_instance
*cdev
;
329 mutex_lock(&i40e_client_instance_mutex
);
330 list_for_each_entry(cdev
, &i40e_client_instances
, list
) {
331 if (cdev
->lan_info
.pf
== pf
) {
333 !cdev
->client
->ops
||
334 !cdev
->client
->ops
->vf_enable
) {
335 dev_dbg(&pf
->pdev
->dev
,
336 "Cannot locate client instance VF enable routine\n");
339 cdev
->client
->ops
->vf_enable(&cdev
->lan_info
,
340 cdev
->client
, num_vfs
);
343 mutex_unlock(&i40e_client_instance_mutex
);
347 * i40e_vf_client_capable - ask the client if it likes the specified VF
348 * @pf: PF device pointer
349 * @vf_id: the VF in question
351 * If there is a client of the specified type attached to this PF, call
352 * its vf_capable routine
354 int i40e_vf_client_capable(struct i40e_pf
*pf
, u32 vf_id
,
355 enum i40e_client_type type
)
357 struct i40e_client_instance
*cdev
;
362 mutex_lock(&i40e_client_instance_mutex
);
363 list_for_each_entry(cdev
, &i40e_client_instances
, list
) {
364 if (cdev
->lan_info
.pf
== pf
) {
366 !cdev
->client
->ops
||
367 !cdev
->client
->ops
->vf_capable
||
368 !(cdev
->client
->type
== type
)) {
369 dev_dbg(&pf
->pdev
->dev
,
370 "Cannot locate client instance VF capability routine\n");
373 capable
= cdev
->client
->ops
->vf_capable(&cdev
->lan_info
,
379 mutex_unlock(&i40e_client_instance_mutex
);
384 * i40e_vsi_lookup - finds a matching VSI from the PF list starting at start_vsi
385 * @pf: board private structure
387 * @start_vsi: a VSI pointer from where to start the search
389 * Returns non NULL on success or NULL for failure
391 struct i40e_vsi
*i40e_vsi_lookup(struct i40e_pf
*pf
,
392 enum i40e_vsi_type type
,
393 struct i40e_vsi
*start_vsi
)
395 struct i40e_vsi
*vsi
;
399 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
401 if (vsi
== start_vsi
)
405 for (; i
< pf
->num_alloc_vsi
; i
++) {
407 if (vsi
&& vsi
->type
== type
)
415 * i40e_client_add_instance - add a client instance struct to the instance list
416 * @pf: pointer to the board struct
417 * @client: pointer to a client struct in the client list.
418 * @existing: if there was already an existing instance
420 * Returns cdev ptr on success or if already exists, NULL on failure
423 struct i40e_client_instance
*i40e_client_add_instance(struct i40e_pf
*pf
,
424 struct i40e_client
*client
,
427 struct i40e_client_instance
*cdev
;
428 struct netdev_hw_addr
*mac
= NULL
;
429 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
431 mutex_lock(&i40e_client_instance_mutex
);
432 list_for_each_entry(cdev
, &i40e_client_instances
, list
) {
433 if ((cdev
->lan_info
.pf
== pf
) && (cdev
->client
== client
)) {
438 cdev
= kzalloc(sizeof(*cdev
), GFP_KERNEL
);
442 cdev
->lan_info
.pf
= (void *)pf
;
443 cdev
->lan_info
.netdev
= vsi
->netdev
;
444 cdev
->lan_info
.pcidev
= pf
->pdev
;
445 cdev
->lan_info
.fid
= pf
->hw
.pf_id
;
446 cdev
->lan_info
.ftype
= I40E_CLIENT_FTYPE_PF
;
447 cdev
->lan_info
.hw_addr
= pf
->hw
.hw_addr
;
448 cdev
->lan_info
.ops
= &i40e_lan_ops
;
449 cdev
->lan_info
.version
.major
= I40E_CLIENT_VERSION_MAJOR
;
450 cdev
->lan_info
.version
.minor
= I40E_CLIENT_VERSION_MINOR
;
451 cdev
->lan_info
.version
.build
= I40E_CLIENT_VERSION_BUILD
;
452 cdev
->lan_info
.fw_maj_ver
= pf
->hw
.aq
.fw_maj_ver
;
453 cdev
->lan_info
.fw_min_ver
= pf
->hw
.aq
.fw_min_ver
;
454 cdev
->lan_info
.fw_build
= pf
->hw
.aq
.fw_build
;
455 set_bit(__I40E_CLIENT_INSTANCE_NONE
, &cdev
->state
);
457 if (i40e_client_get_params(vsi
, &cdev
->lan_info
.params
)) {
463 cdev
->lan_info
.msix_count
= pf
->num_iwarp_msix
;
464 cdev
->lan_info
.msix_entries
= &pf
->msix_entries
[pf
->iwarp_base_vector
];
466 mac
= list_first_entry(&cdev
->lan_info
.netdev
->dev_addrs
.list
,
467 struct netdev_hw_addr
, list
);
469 ether_addr_copy(cdev
->lan_info
.lanmac
, mac
->addr
);
471 dev_err(&pf
->pdev
->dev
, "MAC address list is empty!\n");
473 cdev
->client
= client
;
474 INIT_LIST_HEAD(&cdev
->list
);
475 list_add(&cdev
->list
, &i40e_client_instances
);
477 mutex_unlock(&i40e_client_instance_mutex
);
482 * i40e_client_del_instance - removes a client instance from the list
483 * @pf: pointer to the board struct
485 * Returns 0 on success or non-0 on error
488 int i40e_client_del_instance(struct i40e_pf
*pf
, struct i40e_client
*client
)
490 struct i40e_client_instance
*cdev
, *tmp
;
493 mutex_lock(&i40e_client_instance_mutex
);
494 list_for_each_entry_safe(cdev
, tmp
, &i40e_client_instances
, list
) {
495 if ((cdev
->lan_info
.pf
!= pf
) || (cdev
->client
!= client
))
498 dev_info(&pf
->pdev
->dev
, "Deleted instance of Client %s, of dev %d bus=0x%02x func=0x%02x)\n",
499 client
->name
, pf
->hw
.pf_id
,
500 pf
->hw
.bus
.device
, pf
->hw
.bus
.func
);
501 list_del(&cdev
->list
);
506 mutex_unlock(&i40e_client_instance_mutex
);
511 * i40e_client_subtask - client maintenance work
512 * @pf: board private structure
514 void i40e_client_subtask(struct i40e_pf
*pf
)
516 struct i40e_client_instance
*cdev
;
517 struct i40e_client
*client
;
518 bool existing
= false;
521 if (!(pf
->flags
& I40E_FLAG_SERVICE_CLIENT_REQUESTED
))
523 pf
->flags
&= ~I40E_FLAG_SERVICE_CLIENT_REQUESTED
;
525 /* If we're down or resetting, just bail */
526 if (test_bit(__I40E_DOWN
, &pf
->state
) ||
527 test_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
530 /* Check client state and instantiate client if client registered */
531 mutex_lock(&i40e_client_mutex
);
532 list_for_each_entry(client
, &i40e_clients
, list
) {
533 /* first check client is registered */
534 if (!test_bit(__I40E_CLIENT_REGISTERED
, &client
->state
))
537 /* Do we also need the LAN VSI to be up, to create instance */
538 if (!(client
->flags
& I40E_CLIENT_FLAGS_LAUNCH_ON_PROBE
)) {
539 /* check if L2 VSI is up, if not we are not ready */
540 if (test_bit(__I40E_DOWN
, &pf
->vsi
[pf
->lan_vsi
]->state
))
543 dev_warn(&pf
->pdev
->dev
, "This client %s is being instanciated at probe\n",
547 /* Add the client instance to the instance list */
548 cdev
= i40e_client_add_instance(pf
, client
, &existing
);
553 /* Also up the ref_cnt for no. of instances of this
556 atomic_inc(&client
->ref_cnt
);
557 dev_info(&pf
->pdev
->dev
, "Added instance of Client %s to PF%d bus=0x%02x func=0x%02x\n",
558 client
->name
, pf
->hw
.pf_id
,
559 pf
->hw
.bus
.device
, pf
->hw
.bus
.func
);
562 /* Send an Open request to the client */
563 atomic_inc(&cdev
->ref_cnt
);
564 if (client
->ops
&& client
->ops
->open
)
565 ret
= client
->ops
->open(&cdev
->lan_info
, client
);
566 atomic_dec(&cdev
->ref_cnt
);
568 set_bit(__I40E_CLIENT_INSTANCE_OPENED
, &cdev
->state
);
570 /* remove client instance */
571 i40e_client_del_instance(pf
, client
);
572 atomic_dec(&client
->ref_cnt
);
576 mutex_unlock(&i40e_client_mutex
);
580 * i40e_lan_add_device - add a lan device struct to the list of lan devices
581 * @pf: pointer to the board struct
583 * Returns 0 on success or none 0 on error
585 int i40e_lan_add_device(struct i40e_pf
*pf
)
587 struct i40e_device
*ldev
;
590 mutex_lock(&i40e_device_mutex
);
591 list_for_each_entry(ldev
, &i40e_devices
, list
) {
592 if (ldev
->pf
== pf
) {
597 ldev
= kzalloc(sizeof(*ldev
), GFP_KERNEL
);
603 INIT_LIST_HEAD(&ldev
->list
);
604 list_add(&ldev
->list
, &i40e_devices
);
605 dev_info(&pf
->pdev
->dev
, "Added LAN device PF%d bus=0x%02x func=0x%02x\n",
606 pf
->hw
.pf_id
, pf
->hw
.bus
.device
, pf
->hw
.bus
.func
);
608 /* Since in some cases register may have happened before a device gets
609 * added, we can schedule a subtask to go initiate the clients if
610 * they can be launched at probe time.
612 pf
->flags
|= I40E_FLAG_SERVICE_CLIENT_REQUESTED
;
613 i40e_service_event_schedule(pf
);
616 mutex_unlock(&i40e_device_mutex
);
621 * i40e_lan_del_device - removes a lan device from the device list
622 * @pf: pointer to the board struct
624 * Returns 0 on success or non-0 on error
626 int i40e_lan_del_device(struct i40e_pf
*pf
)
628 struct i40e_device
*ldev
, *tmp
;
631 mutex_lock(&i40e_device_mutex
);
632 list_for_each_entry_safe(ldev
, tmp
, &i40e_devices
, list
) {
633 if (ldev
->pf
== pf
) {
634 dev_info(&pf
->pdev
->dev
, "Deleted LAN device PF%d bus=0x%02x func=0x%02x\n",
635 pf
->hw
.pf_id
, pf
->hw
.bus
.device
,
637 list_del(&ldev
->list
);
644 mutex_unlock(&i40e_device_mutex
);
649 * i40e_client_release - release client specific resources
650 * @client: pointer to the registered client
652 * Return 0 on success or < 0 on error
654 static int i40e_client_release(struct i40e_client
*client
)
656 struct i40e_client_instance
*cdev
, *tmp
;
657 struct i40e_pf
*pf
= NULL
;
660 LIST_HEAD(cdevs_tmp
);
662 mutex_lock(&i40e_client_instance_mutex
);
663 list_for_each_entry_safe(cdev
, tmp
, &i40e_client_instances
, list
) {
664 if (strncmp(cdev
->client
->name
, client
->name
,
665 I40E_CLIENT_STR_LENGTH
))
667 if (test_bit(__I40E_CLIENT_INSTANCE_OPENED
, &cdev
->state
)) {
668 if (atomic_read(&cdev
->ref_cnt
) > 0) {
669 ret
= I40E_ERR_NOT_READY
;
672 pf
= (struct i40e_pf
*)cdev
->lan_info
.pf
;
673 if (client
->ops
&& client
->ops
->close
)
674 client
->ops
->close(&cdev
->lan_info
, client
,
676 i40e_client_release_qvlist(&cdev
->lan_info
);
677 clear_bit(__I40E_CLIENT_INSTANCE_OPENED
, &cdev
->state
);
679 dev_warn(&pf
->pdev
->dev
,
680 "Client %s instance for PF id %d closed\n",
681 client
->name
, pf
->hw
.pf_id
);
683 /* delete the client instance from the list */
684 list_del(&cdev
->list
);
685 list_add(&cdev
->list
, &cdevs_tmp
);
686 atomic_dec(&client
->ref_cnt
);
687 dev_info(&pf
->pdev
->dev
, "Deleted client instance of Client %s\n",
691 mutex_unlock(&i40e_client_instance_mutex
);
693 /* free the client device and release its vsi */
694 list_for_each_entry_safe(cdev
, tmp
, &cdevs_tmp
, list
) {
701 * i40e_client_prepare - prepare client specific resources
702 * @client: pointer to the registered client
704 * Return 0 on success or < 0 on error
706 static int i40e_client_prepare(struct i40e_client
*client
)
708 struct i40e_device
*ldev
;
712 mutex_lock(&i40e_device_mutex
);
713 list_for_each_entry(ldev
, &i40e_devices
, list
) {
715 /* Start the client subtask */
716 pf
->flags
|= I40E_FLAG_SERVICE_CLIENT_REQUESTED
;
717 i40e_service_event_schedule(pf
);
719 mutex_unlock(&i40e_device_mutex
);
724 * i40e_client_virtchnl_send - TBD
725 * @ldev: pointer to L2 context
726 * @client: Client pointer
727 * @vf_id: absolute VF identifier
728 * @msg: message buffer
729 * @len: length of message buffer
731 * Return 0 on success or < 0 on error
733 static int i40e_client_virtchnl_send(struct i40e_info
*ldev
,
734 struct i40e_client
*client
,
735 u32 vf_id
, u8
*msg
, u16 len
)
737 struct i40e_pf
*pf
= ldev
->pf
;
738 struct i40e_hw
*hw
= &pf
->hw
;
741 err
= i40e_aq_send_msg_to_vf(hw
, vf_id
, I40E_VIRTCHNL_OP_IWARP
,
744 dev_err(&pf
->pdev
->dev
, "Unable to send iWarp message to VF, error %d, aq status %d\n",
745 err
, hw
->aq
.asq_last_status
);
751 * i40e_client_setup_qvlist
752 * @ldev: pointer to L2 context.
753 * @client: Client pointer.
754 * @qv_info: queue and vector list
756 * Return 0 on success or < 0 on error
758 static int i40e_client_setup_qvlist(struct i40e_info
*ldev
,
759 struct i40e_client
*client
,
760 struct i40e_qvlist_info
*qvlist_info
)
762 struct i40e_pf
*pf
= ldev
->pf
;
763 struct i40e_hw
*hw
= &pf
->hw
;
764 struct i40e_qv_info
*qv_info
;
765 u32 v_idx
, i
, reg_idx
, reg
;
768 size
= sizeof(struct i40e_qvlist_info
) +
769 (sizeof(struct i40e_qv_info
) * (qvlist_info
->num_vectors
- 1));
770 ldev
->qvlist_info
= kzalloc(size
, GFP_KERNEL
);
771 ldev
->qvlist_info
->num_vectors
= qvlist_info
->num_vectors
;
773 for (i
= 0; i
< qvlist_info
->num_vectors
; i
++) {
774 qv_info
= &qvlist_info
->qv_info
[i
];
777 v_idx
= qv_info
->v_idx
;
779 /* Validate vector id belongs to this client */
780 if ((v_idx
>= (pf
->iwarp_base_vector
+ pf
->num_iwarp_msix
)) ||
781 (v_idx
< pf
->iwarp_base_vector
))
784 ldev
->qvlist_info
->qv_info
[i
] = *qv_info
;
785 reg_idx
= I40E_PFINT_LNKLSTN(v_idx
- 1);
787 if (qv_info
->ceq_idx
== I40E_QUEUE_INVALID_IDX
) {
788 /* Special case - No CEQ mapped on this vector */
789 wr32(hw
, reg_idx
, I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK
);
791 reg
= (qv_info
->ceq_idx
&
792 I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK
) |
793 (I40E_QUEUE_TYPE_PE_CEQ
<<
794 I40E_PFINT_LNKLSTN_FIRSTQ_TYPE_SHIFT
);
795 wr32(hw
, reg_idx
, reg
);
797 reg
= (I40E_PFINT_CEQCTL_CAUSE_ENA_MASK
|
798 (v_idx
<< I40E_PFINT_CEQCTL_MSIX_INDX_SHIFT
) |
800 I40E_PFINT_CEQCTL_ITR_INDX_SHIFT
) |
801 (I40E_QUEUE_END_OF_LIST
<<
802 I40E_PFINT_CEQCTL_NEXTQ_INDX_SHIFT
));
803 wr32(hw
, I40E_PFINT_CEQCTL(qv_info
->ceq_idx
), reg
);
805 if (qv_info
->aeq_idx
!= I40E_QUEUE_INVALID_IDX
) {
806 reg
= (I40E_PFINT_AEQCTL_CAUSE_ENA_MASK
|
807 (v_idx
<< I40E_PFINT_AEQCTL_MSIX_INDX_SHIFT
) |
809 I40E_PFINT_AEQCTL_ITR_INDX_SHIFT
));
811 wr32(hw
, I40E_PFINT_AEQCTL
, reg
);
817 kfree(ldev
->qvlist_info
);
818 ldev
->qvlist_info
= NULL
;
823 * i40e_client_request_reset
824 * @ldev: pointer to L2 context.
825 * @client: Client pointer.
826 * @level: reset level
828 static void i40e_client_request_reset(struct i40e_info
*ldev
,
829 struct i40e_client
*client
,
832 struct i40e_pf
*pf
= ldev
->pf
;
834 switch (reset_level
) {
835 case I40E_CLIENT_RESET_LEVEL_PF
:
836 set_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
838 case I40E_CLIENT_RESET_LEVEL_CORE
:
839 set_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
842 dev_warn(&pf
->pdev
->dev
,
843 "Client %s instance for PF id %d request an unsupported reset: %d.\n",
844 client
->name
, pf
->hw
.pf_id
, reset_level
);
848 i40e_service_event_schedule(pf
);
852 * i40e_client_update_vsi_ctxt
853 * @ldev: pointer to L2 context.
854 * @client: Client pointer.
855 * @is_vf: if this for the VF
856 * @vf_id: if is_vf true this carries the vf_id
857 * @flag: Any device level setting that needs to be done for PE
858 * @valid_flag: Bits in this match up and enable changing of flag bits
860 * Return 0 on success or < 0 on error
862 static int i40e_client_update_vsi_ctxt(struct i40e_info
*ldev
,
863 struct i40e_client
*client
,
864 bool is_vf
, u32 vf_id
,
865 u32 flag
, u32 valid_flag
)
867 struct i40e_pf
*pf
= ldev
->pf
;
868 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
869 struct i40e_vsi_context ctxt
;
873 /* TODO: for now do not allow setting VF's VSI setting */
877 ctxt
.seid
= pf
->main_vsi_seid
;
878 ctxt
.pf_num
= pf
->hw
.pf_id
;
879 err
= i40e_aq_get_vsi_params(&pf
->hw
, &ctxt
, NULL
);
880 ctxt
.flags
= I40E_AQ_VSI_TYPE_PF
;
882 dev_info(&pf
->pdev
->dev
,
883 "couldn't get PF vsi config, err %s aq_err %s\n",
884 i40e_stat_str(&pf
->hw
, err
),
886 pf
->hw
.aq
.asq_last_status
));
890 if ((valid_flag
& I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE
) &&
891 (flag
& I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE
)) {
892 ctxt
.info
.valid_sections
=
893 cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID
);
894 ctxt
.info
.queueing_opt_flags
|= I40E_AQ_VSI_QUE_OPT_TCP_ENA
;
895 } else if ((valid_flag
& I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE
) &&
896 !(flag
& I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE
)) {
897 ctxt
.info
.valid_sections
=
898 cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID
);
899 ctxt
.info
.queueing_opt_flags
&= ~I40E_AQ_VSI_QUE_OPT_TCP_ENA
;
902 dev_warn(&pf
->pdev
->dev
,
903 "Client %s instance for PF id %d request an unsupported Config: %x.\n",
904 client
->name
, pf
->hw
.pf_id
, flag
);
908 err
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
910 dev_info(&pf
->pdev
->dev
,
911 "update VSI ctxt for PE failed, err %s aq_err %s\n",
912 i40e_stat_str(&pf
->hw
, err
),
914 pf
->hw
.aq
.asq_last_status
));
921 * i40e_register_client - Register a i40e client driver with the L2 driver
922 * @client: pointer to the i40e_client struct
924 * Returns 0 on success or non-0 on error
926 int i40e_register_client(struct i40e_client
*client
)
929 enum i40e_vsi_type vsi_type
;
936 if (strlen(client
->name
) == 0) {
937 pr_info("i40e: Failed to register client with no name\n");
942 mutex_lock(&i40e_client_mutex
);
943 if (i40e_client_is_registered(client
)) {
944 pr_info("i40e: Client %s has already been registered!\n",
946 mutex_unlock(&i40e_client_mutex
);
951 if ((client
->version
.major
!= I40E_CLIENT_VERSION_MAJOR
) ||
952 (client
->version
.minor
!= I40E_CLIENT_VERSION_MINOR
)) {
953 pr_info("i40e: Failed to register client %s due to mismatched client interface version\n",
955 pr_info("Client is using version: %02d.%02d.%02d while LAN driver supports %s\n",
956 client
->version
.major
, client
->version
.minor
,
957 client
->version
.build
,
958 i40e_client_interface_version_str
);
959 mutex_unlock(&i40e_client_mutex
);
964 vsi_type
= i40e_client_type_to_vsi_type(client
->type
);
965 if (vsi_type
== I40E_VSI_TYPE_UNKNOWN
) {
966 pr_info("i40e: Failed to register client %s due to unknown client type %d\n",
967 client
->name
, client
->type
);
968 mutex_unlock(&i40e_client_mutex
);
972 list_add(&client
->list
, &i40e_clients
);
973 set_bit(__I40E_CLIENT_REGISTERED
, &client
->state
);
974 mutex_unlock(&i40e_client_mutex
);
976 if (i40e_client_prepare(client
)) {
981 pr_info("i40e: Registered client %s with return code %d\n",
986 EXPORT_SYMBOL(i40e_register_client
);
989 * i40e_unregister_client - Unregister a i40e client driver with the L2 driver
990 * @client: pointer to the i40e_client struct
992 * Returns 0 on success or non-0 on error
994 int i40e_unregister_client(struct i40e_client
*client
)
998 /* When a unregister request comes through we would have to send
999 * a close for each of the client instances that were opened.
1000 * client_release function is called to handle this.
1002 mutex_lock(&i40e_client_mutex
);
1003 if (!client
|| i40e_client_release(client
)) {
1008 /* TODO: check if device is in reset, or if that matters? */
1009 if (!i40e_client_is_registered(client
)) {
1010 pr_info("i40e: Client %s has not been registered\n",
1012 mutex_unlock(&i40e_client_mutex
);
1016 if (atomic_read(&client
->ref_cnt
) == 0) {
1017 clear_bit(__I40E_CLIENT_REGISTERED
, &client
->state
);
1018 list_del(&client
->list
);
1019 pr_info("i40e: Unregistered client %s with return code %d\n",
1022 ret
= I40E_ERR_NOT_READY
;
1023 pr_err("i40e: Client %s failed unregister - client has open instances\n",
1028 mutex_unlock(&i40e_client_mutex
);
1031 EXPORT_SYMBOL(i40e_unregister_client
);