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
;
205 mutex_lock(&i40e_client_instance_mutex
);
206 list_for_each_entry(cdev
, &i40e_client_instances
, list
) {
207 if (cdev
->lan_info
.netdev
== vsi
->netdev
) {
209 !cdev
->client
->ops
|| !cdev
->client
->ops
->open
) {
210 dev_dbg(&vsi
->back
->pdev
->dev
,
211 "Cannot locate client instance open routine\n");
214 cdev
->client
->ops
->open(&cdev
->lan_info
, cdev
->client
);
217 mutex_unlock(&i40e_client_instance_mutex
);
221 * i40e_client_release_qvlist
222 * @ldev: pointer to L2 context.
225 static void i40e_client_release_qvlist(struct i40e_info
*ldev
)
227 struct i40e_qvlist_info
*qvlist_info
= ldev
->qvlist_info
;
230 if (!ldev
->qvlist_info
)
233 for (i
= 0; i
< qvlist_info
->num_vectors
; i
++) {
234 struct i40e_pf
*pf
= ldev
->pf
;
235 struct i40e_qv_info
*qv_info
;
238 qv_info
= &qvlist_info
->qv_info
[i
];
241 reg_idx
= I40E_PFINT_LNKLSTN(qv_info
->v_idx
- 1);
242 wr32(&pf
->hw
, reg_idx
, I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK
);
244 kfree(ldev
->qvlist_info
);
245 ldev
->qvlist_info
= NULL
;
249 * i40e_notify_client_of_netdev_close - call the client close callback
250 * @vsi: the VSI with netdev closed
251 * @reset: true when close called due to a reset pending
253 * If there is a client to this netdev, call the client with close
255 void i40e_notify_client_of_netdev_close(struct i40e_vsi
*vsi
, bool reset
)
257 struct i40e_client_instance
*cdev
;
261 mutex_lock(&i40e_client_instance_mutex
);
262 list_for_each_entry(cdev
, &i40e_client_instances
, list
) {
263 if (cdev
->lan_info
.netdev
== vsi
->netdev
) {
265 !cdev
->client
->ops
|| !cdev
->client
->ops
->close
) {
266 dev_dbg(&vsi
->back
->pdev
->dev
,
267 "Cannot locate client instance close routine\n");
270 cdev
->client
->ops
->close(&cdev
->lan_info
, cdev
->client
,
272 i40e_client_release_qvlist(&cdev
->lan_info
);
275 mutex_unlock(&i40e_client_instance_mutex
);
279 * i40e_notify_client_of_vf_reset - call the client vf reset callback
280 * @pf: PF device pointer
281 * @vf_id: asolute id of VF being reset
283 * If there is a client attached to this PF, notify when a VF is reset
285 void i40e_notify_client_of_vf_reset(struct i40e_pf
*pf
, u32 vf_id
)
287 struct i40e_client_instance
*cdev
;
291 mutex_lock(&i40e_client_instance_mutex
);
292 list_for_each_entry(cdev
, &i40e_client_instances
, list
) {
293 if (cdev
->lan_info
.pf
== pf
) {
295 !cdev
->client
->ops
||
296 !cdev
->client
->ops
->vf_reset
) {
297 dev_dbg(&pf
->pdev
->dev
,
298 "Cannot locate client instance VF reset routine\n");
301 cdev
->client
->ops
->vf_reset(&cdev
->lan_info
,
302 cdev
->client
, vf_id
);
305 mutex_unlock(&i40e_client_instance_mutex
);
309 * i40e_notify_client_of_vf_enable - call the client vf notification callback
310 * @pf: PF device pointer
311 * @num_vfs: the number of VFs currently enabled, 0 for disable
313 * If there is a client attached to this PF, call its VF notification routine
315 void i40e_notify_client_of_vf_enable(struct i40e_pf
*pf
, u32 num_vfs
)
317 struct i40e_client_instance
*cdev
;
321 mutex_lock(&i40e_client_instance_mutex
);
322 list_for_each_entry(cdev
, &i40e_client_instances
, list
) {
323 if (cdev
->lan_info
.pf
== pf
) {
325 !cdev
->client
->ops
||
326 !cdev
->client
->ops
->vf_enable
) {
327 dev_dbg(&pf
->pdev
->dev
,
328 "Cannot locate client instance VF enable routine\n");
331 cdev
->client
->ops
->vf_enable(&cdev
->lan_info
,
332 cdev
->client
, num_vfs
);
335 mutex_unlock(&i40e_client_instance_mutex
);
339 * i40e_vf_client_capable - ask the client if it likes the specified VF
340 * @pf: PF device pointer
341 * @vf_id: the VF in question
343 * If there is a client of the specified type attached to this PF, call
344 * its vf_capable routine
346 int i40e_vf_client_capable(struct i40e_pf
*pf
, u32 vf_id
,
347 enum i40e_client_type type
)
349 struct i40e_client_instance
*cdev
;
354 mutex_lock(&i40e_client_instance_mutex
);
355 list_for_each_entry(cdev
, &i40e_client_instances
, list
) {
356 if (cdev
->lan_info
.pf
== pf
) {
358 !cdev
->client
->ops
||
359 !cdev
->client
->ops
->vf_capable
||
360 !(cdev
->client
->type
== type
)) {
361 dev_dbg(&pf
->pdev
->dev
,
362 "Cannot locate client instance VF capability routine\n");
365 capable
= cdev
->client
->ops
->vf_capable(&cdev
->lan_info
,
371 mutex_unlock(&i40e_client_instance_mutex
);
376 * i40e_vsi_lookup - finds a matching VSI from the PF list starting at start_vsi
377 * @pf: board private structure
379 * @start_vsi: a VSI pointer from where to start the search
381 * Returns non NULL on success or NULL for failure
383 struct i40e_vsi
*i40e_vsi_lookup(struct i40e_pf
*pf
,
384 enum i40e_vsi_type type
,
385 struct i40e_vsi
*start_vsi
)
387 struct i40e_vsi
*vsi
;
391 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
393 if (vsi
== start_vsi
)
397 for (; i
< pf
->num_alloc_vsi
; i
++) {
399 if (vsi
&& vsi
->type
== type
)
407 * i40e_client_add_instance - add a client instance struct to the instance list
408 * @pf: pointer to the board struct
409 * @client: pointer to a client struct in the client list.
411 * Returns cdev ptr on success, NULL on failure
414 struct i40e_client_instance
*i40e_client_add_instance(struct i40e_pf
*pf
,
415 struct i40e_client
*client
)
417 struct i40e_client_instance
*cdev
;
418 struct netdev_hw_addr
*mac
= NULL
;
419 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
421 mutex_lock(&i40e_client_instance_mutex
);
422 list_for_each_entry(cdev
, &i40e_client_instances
, list
) {
423 if ((cdev
->lan_info
.pf
== pf
) && (cdev
->client
== client
)) {
428 cdev
= kzalloc(sizeof(*cdev
), GFP_KERNEL
);
432 cdev
->lan_info
.pf
= (void *)pf
;
433 cdev
->lan_info
.netdev
= vsi
->netdev
;
434 cdev
->lan_info
.pcidev
= pf
->pdev
;
435 cdev
->lan_info
.fid
= pf
->hw
.pf_id
;
436 cdev
->lan_info
.ftype
= I40E_CLIENT_FTYPE_PF
;
437 cdev
->lan_info
.hw_addr
= pf
->hw
.hw_addr
;
438 cdev
->lan_info
.ops
= &i40e_lan_ops
;
439 cdev
->lan_info
.version
.major
= I40E_CLIENT_VERSION_MAJOR
;
440 cdev
->lan_info
.version
.minor
= I40E_CLIENT_VERSION_MINOR
;
441 cdev
->lan_info
.version
.build
= I40E_CLIENT_VERSION_BUILD
;
442 cdev
->lan_info
.fw_maj_ver
= pf
->hw
.aq
.fw_maj_ver
;
443 cdev
->lan_info
.fw_min_ver
= pf
->hw
.aq
.fw_min_ver
;
444 cdev
->lan_info
.fw_build
= pf
->hw
.aq
.fw_build
;
445 set_bit(__I40E_CLIENT_INSTANCE_NONE
, &cdev
->state
);
447 if (i40e_client_get_params(vsi
, &cdev
->lan_info
.params
)) {
453 cdev
->lan_info
.msix_count
= pf
->num_iwarp_msix
;
454 cdev
->lan_info
.msix_entries
= &pf
->msix_entries
[pf
->iwarp_base_vector
];
456 mac
= list_first_entry(&cdev
->lan_info
.netdev
->dev_addrs
.list
,
457 struct netdev_hw_addr
, list
);
459 ether_addr_copy(cdev
->lan_info
.lanmac
, mac
->addr
);
461 dev_err(&pf
->pdev
->dev
, "MAC address list is empty!\n");
463 cdev
->client
= client
;
464 INIT_LIST_HEAD(&cdev
->list
);
465 list_add(&cdev
->list
, &i40e_client_instances
);
467 mutex_unlock(&i40e_client_instance_mutex
);
472 * i40e_client_del_instance - removes a client instance from the list
473 * @pf: pointer to the board struct
475 * Returns 0 on success or non-0 on error
478 int i40e_client_del_instance(struct i40e_pf
*pf
, struct i40e_client
*client
)
480 struct i40e_client_instance
*cdev
, *tmp
;
483 mutex_lock(&i40e_client_instance_mutex
);
484 list_for_each_entry_safe(cdev
, tmp
, &i40e_client_instances
, list
) {
485 if ((cdev
->lan_info
.pf
!= pf
) || (cdev
->client
!= client
))
488 dev_info(&pf
->pdev
->dev
, "Deleted instance of Client %s, of dev %d bus=0x%02x func=0x%02x)\n",
489 client
->name
, pf
->hw
.pf_id
,
490 pf
->hw
.bus
.device
, pf
->hw
.bus
.func
);
491 list_del(&cdev
->list
);
496 mutex_unlock(&i40e_client_instance_mutex
);
501 * i40e_client_subtask - client maintenance work
502 * @pf: board private structure
504 void i40e_client_subtask(struct i40e_pf
*pf
)
506 struct i40e_client_instance
*cdev
;
507 struct i40e_client
*client
;
510 if (!(pf
->flags
& I40E_FLAG_SERVICE_CLIENT_REQUESTED
))
512 pf
->flags
&= ~I40E_FLAG_SERVICE_CLIENT_REQUESTED
;
514 /* If we're down or resetting, just bail */
515 if (test_bit(__I40E_DOWN
, &pf
->state
) ||
516 test_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
519 /* Check client state and instantiate client if client registered */
520 mutex_lock(&i40e_client_mutex
);
521 list_for_each_entry(client
, &i40e_clients
, list
) {
522 /* first check client is registered */
523 if (!test_bit(__I40E_CLIENT_REGISTERED
, &client
->state
))
526 /* Do we also need the LAN VSI to be up, to create instance */
527 if (!(client
->flags
& I40E_CLIENT_FLAGS_LAUNCH_ON_PROBE
)) {
528 /* check if L2 VSI is up, if not we are not ready */
529 if (test_bit(__I40E_DOWN
, &pf
->vsi
[pf
->lan_vsi
]->state
))
533 /* Add the client instance to the instance list */
534 cdev
= i40e_client_add_instance(pf
, client
);
538 /* Also up the ref_cnt of no. of instances of this client */
539 atomic_inc(&client
->ref_cnt
);
540 dev_info(&pf
->pdev
->dev
, "Added instance of Client %s to PF%d bus=0x%02x func=0x%02x\n",
541 client
->name
, pf
->hw
.pf_id
,
542 pf
->hw
.bus
.device
, pf
->hw
.bus
.func
);
544 /* Send an Open request to the client */
545 atomic_inc(&cdev
->ref_cnt
);
546 if (client
->ops
&& client
->ops
->open
)
547 ret
= client
->ops
->open(&cdev
->lan_info
, client
);
548 atomic_dec(&cdev
->ref_cnt
);
550 set_bit(__I40E_CLIENT_INSTANCE_OPENED
, &cdev
->state
);
552 /* remove client instance */
553 i40e_client_del_instance(pf
, client
);
554 atomic_dec(&client
->ref_cnt
);
558 mutex_unlock(&i40e_client_mutex
);
562 * i40e_lan_add_device - add a lan device struct to the list of lan devices
563 * @pf: pointer to the board struct
565 * Returns 0 on success or none 0 on error
567 int i40e_lan_add_device(struct i40e_pf
*pf
)
569 struct i40e_device
*ldev
;
572 mutex_lock(&i40e_device_mutex
);
573 list_for_each_entry(ldev
, &i40e_devices
, list
) {
574 if (ldev
->pf
== pf
) {
579 ldev
= kzalloc(sizeof(*ldev
), GFP_KERNEL
);
585 INIT_LIST_HEAD(&ldev
->list
);
586 list_add(&ldev
->list
, &i40e_devices
);
587 dev_info(&pf
->pdev
->dev
, "Added LAN device PF%d bus=0x%02x func=0x%02x\n",
588 pf
->hw
.pf_id
, pf
->hw
.bus
.device
, pf
->hw
.bus
.func
);
590 /* Since in some cases register may have happened before a device gets
591 * added, we can schedule a subtask to go initiate the clients.
593 pf
->flags
|= I40E_FLAG_SERVICE_CLIENT_REQUESTED
;
594 i40e_service_event_schedule(pf
);
597 mutex_unlock(&i40e_device_mutex
);
602 * i40e_lan_del_device - removes a lan device from the device list
603 * @pf: pointer to the board struct
605 * Returns 0 on success or non-0 on error
607 int i40e_lan_del_device(struct i40e_pf
*pf
)
609 struct i40e_device
*ldev
, *tmp
;
612 mutex_lock(&i40e_device_mutex
);
613 list_for_each_entry_safe(ldev
, tmp
, &i40e_devices
, list
) {
614 if (ldev
->pf
== pf
) {
615 dev_info(&pf
->pdev
->dev
, "Deleted LAN device PF%d bus=0x%02x func=0x%02x\n",
616 pf
->hw
.pf_id
, pf
->hw
.bus
.device
,
618 list_del(&ldev
->list
);
625 mutex_unlock(&i40e_device_mutex
);
630 * i40e_client_release - release client specific resources
631 * @client: pointer to the registered client
633 * Return 0 on success or < 0 on error
635 static int i40e_client_release(struct i40e_client
*client
)
637 struct i40e_client_instance
*cdev
, *tmp
;
638 struct i40e_pf
*pf
= NULL
;
641 LIST_HEAD(cdevs_tmp
);
643 mutex_lock(&i40e_client_instance_mutex
);
644 list_for_each_entry_safe(cdev
, tmp
, &i40e_client_instances
, list
) {
645 if (strncmp(cdev
->client
->name
, client
->name
,
646 I40E_CLIENT_STR_LENGTH
))
648 if (test_bit(__I40E_CLIENT_INSTANCE_OPENED
, &cdev
->state
)) {
649 if (atomic_read(&cdev
->ref_cnt
) > 0) {
650 ret
= I40E_ERR_NOT_READY
;
653 pf
= (struct i40e_pf
*)cdev
->lan_info
.pf
;
654 if (client
->ops
&& client
->ops
->close
)
655 client
->ops
->close(&cdev
->lan_info
, client
,
657 i40e_client_release_qvlist(&cdev
->lan_info
);
658 clear_bit(__I40E_CLIENT_INSTANCE_OPENED
, &cdev
->state
);
660 dev_warn(&pf
->pdev
->dev
,
661 "Client %s instance for PF id %d closed\n",
662 client
->name
, pf
->hw
.pf_id
);
664 /* delete the client instance from the list */
665 list_del(&cdev
->list
);
666 list_add(&cdev
->list
, &cdevs_tmp
);
667 atomic_dec(&client
->ref_cnt
);
668 dev_info(&pf
->pdev
->dev
, "Deleted client instance of Client %s\n",
672 mutex_unlock(&i40e_client_instance_mutex
);
674 /* free the client device and release its vsi */
675 list_for_each_entry_safe(cdev
, tmp
, &cdevs_tmp
, list
) {
682 * i40e_client_prepare - prepare client specific resources
683 * @client: pointer to the registered client
685 * Return 0 on success or < 0 on error
687 static int i40e_client_prepare(struct i40e_client
*client
)
689 struct i40e_device
*ldev
;
693 mutex_lock(&i40e_device_mutex
);
694 list_for_each_entry(ldev
, &i40e_devices
, list
) {
696 /* Start the client subtask */
697 pf
->flags
|= I40E_FLAG_SERVICE_CLIENT_REQUESTED
;
698 i40e_service_event_schedule(pf
);
700 mutex_unlock(&i40e_device_mutex
);
705 * i40e_client_virtchnl_send - TBD
706 * @ldev: pointer to L2 context
707 * @client: Client pointer
708 * @vf_id: absolute VF identifier
709 * @msg: message buffer
710 * @len: length of message buffer
712 * Return 0 on success or < 0 on error
714 static int i40e_client_virtchnl_send(struct i40e_info
*ldev
,
715 struct i40e_client
*client
,
716 u32 vf_id
, u8
*msg
, u16 len
)
718 struct i40e_pf
*pf
= ldev
->pf
;
719 struct i40e_hw
*hw
= &pf
->hw
;
722 err
= i40e_aq_send_msg_to_vf(hw
, vf_id
, I40E_VIRTCHNL_OP_IWARP
,
725 dev_err(&pf
->pdev
->dev
, "Unable to send iWarp message to VF, error %d, aq status %d\n",
726 err
, hw
->aq
.asq_last_status
);
732 * i40e_client_setup_qvlist
733 * @ldev: pointer to L2 context.
734 * @client: Client pointer.
735 * @qv_info: queue and vector list
737 * Return 0 on success or < 0 on error
739 static int i40e_client_setup_qvlist(struct i40e_info
*ldev
,
740 struct i40e_client
*client
,
741 struct i40e_qvlist_info
*qvlist_info
)
743 struct i40e_pf
*pf
= ldev
->pf
;
744 struct i40e_hw
*hw
= &pf
->hw
;
745 struct i40e_qv_info
*qv_info
;
746 u32 v_idx
, i
, reg_idx
, reg
;
749 size
= sizeof(struct i40e_qvlist_info
) +
750 (sizeof(struct i40e_qv_info
) * (qvlist_info
->num_vectors
- 1));
751 ldev
->qvlist_info
= kzalloc(size
, GFP_KERNEL
);
752 ldev
->qvlist_info
->num_vectors
= qvlist_info
->num_vectors
;
754 for (i
= 0; i
< qvlist_info
->num_vectors
; i
++) {
755 qv_info
= &qvlist_info
->qv_info
[i
];
758 v_idx
= qv_info
->v_idx
;
760 /* Validate vector id belongs to this client */
761 if ((v_idx
>= (pf
->iwarp_base_vector
+ pf
->num_iwarp_msix
)) ||
762 (v_idx
< pf
->iwarp_base_vector
))
765 ldev
->qvlist_info
->qv_info
[i
] = *qv_info
;
766 reg_idx
= I40E_PFINT_LNKLSTN(v_idx
- 1);
768 if (qv_info
->ceq_idx
== I40E_QUEUE_INVALID_IDX
) {
769 /* Special case - No CEQ mapped on this vector */
770 wr32(hw
, reg_idx
, I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK
);
772 reg
= (qv_info
->ceq_idx
&
773 I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK
) |
774 (I40E_QUEUE_TYPE_PE_CEQ
<<
775 I40E_PFINT_LNKLSTN_FIRSTQ_TYPE_SHIFT
);
776 wr32(hw
, reg_idx
, reg
);
778 reg
= (I40E_PFINT_CEQCTL_CAUSE_ENA_MASK
|
779 (v_idx
<< I40E_PFINT_CEQCTL_MSIX_INDX_SHIFT
) |
781 I40E_PFINT_CEQCTL_ITR_INDX_SHIFT
) |
782 (I40E_QUEUE_END_OF_LIST
<<
783 I40E_PFINT_CEQCTL_NEXTQ_INDX_SHIFT
));
784 wr32(hw
, I40E_PFINT_CEQCTL(qv_info
->ceq_idx
), reg
);
786 if (qv_info
->aeq_idx
!= I40E_QUEUE_INVALID_IDX
) {
787 reg
= (I40E_PFINT_AEQCTL_CAUSE_ENA_MASK
|
788 (v_idx
<< I40E_PFINT_AEQCTL_MSIX_INDX_SHIFT
) |
790 I40E_PFINT_AEQCTL_ITR_INDX_SHIFT
));
792 wr32(hw
, I40E_PFINT_AEQCTL
, reg
);
798 kfree(ldev
->qvlist_info
);
799 ldev
->qvlist_info
= NULL
;
804 * i40e_client_request_reset
805 * @ldev: pointer to L2 context.
806 * @client: Client pointer.
807 * @level: reset level
809 static void i40e_client_request_reset(struct i40e_info
*ldev
,
810 struct i40e_client
*client
,
813 struct i40e_pf
*pf
= ldev
->pf
;
815 switch (reset_level
) {
816 case I40E_CLIENT_RESET_LEVEL_PF
:
817 set_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
819 case I40E_CLIENT_RESET_LEVEL_CORE
:
820 set_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
823 dev_warn(&pf
->pdev
->dev
,
824 "Client %s instance for PF id %d request an unsupported reset: %d.\n",
825 client
->name
, pf
->hw
.pf_id
, reset_level
);
829 i40e_service_event_schedule(pf
);
833 * i40e_client_update_vsi_ctxt
834 * @ldev: pointer to L2 context.
835 * @client: Client pointer.
836 * @is_vf: if this for the VF
837 * @vf_id: if is_vf true this carries the vf_id
838 * @flag: Any device level setting that needs to be done for PE
839 * @valid_flag: Bits in this match up and enable changing of flag bits
841 * Return 0 on success or < 0 on error
843 static int i40e_client_update_vsi_ctxt(struct i40e_info
*ldev
,
844 struct i40e_client
*client
,
845 bool is_vf
, u32 vf_id
,
846 u32 flag
, u32 valid_flag
)
848 struct i40e_pf
*pf
= ldev
->pf
;
849 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
850 struct i40e_vsi_context ctxt
;
854 /* TODO: for now do not allow setting VF's VSI setting */
858 ctxt
.seid
= pf
->main_vsi_seid
;
859 ctxt
.pf_num
= pf
->hw
.pf_id
;
860 err
= i40e_aq_get_vsi_params(&pf
->hw
, &ctxt
, NULL
);
861 ctxt
.flags
= I40E_AQ_VSI_TYPE_PF
;
863 dev_info(&pf
->pdev
->dev
,
864 "couldn't get PF vsi config, err %s aq_err %s\n",
865 i40e_stat_str(&pf
->hw
, err
),
867 pf
->hw
.aq
.asq_last_status
));
871 if ((valid_flag
& I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE
) &&
872 (flag
& I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE
)) {
873 ctxt
.info
.valid_sections
=
874 cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID
);
875 ctxt
.info
.queueing_opt_flags
|= I40E_AQ_VSI_QUE_OPT_TCP_ENA
;
876 } else if ((valid_flag
& I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE
) &&
877 !(flag
& I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE
)) {
878 ctxt
.info
.valid_sections
=
879 cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID
);
880 ctxt
.info
.queueing_opt_flags
&= ~I40E_AQ_VSI_QUE_OPT_TCP_ENA
;
883 dev_warn(&pf
->pdev
->dev
,
884 "Client %s instance for PF id %d request an unsupported Config: %x.\n",
885 client
->name
, pf
->hw
.pf_id
, flag
);
889 err
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
891 dev_info(&pf
->pdev
->dev
,
892 "update VSI ctxt for PE failed, err %s aq_err %s\n",
893 i40e_stat_str(&pf
->hw
, err
),
895 pf
->hw
.aq
.asq_last_status
));
902 * i40e_register_client - Register a i40e client driver with the L2 driver
903 * @client: pointer to the i40e_client struct
905 * Returns 0 on success or non-0 on error
907 int i40e_register_client(struct i40e_client
*client
)
910 enum i40e_vsi_type vsi_type
;
917 if (strlen(client
->name
) == 0) {
918 pr_info("i40e: Failed to register client with no name\n");
923 mutex_lock(&i40e_client_mutex
);
924 if (i40e_client_is_registered(client
)) {
925 pr_info("i40e: Client %s has already been registered!\n",
927 mutex_unlock(&i40e_client_mutex
);
932 if ((client
->version
.major
!= I40E_CLIENT_VERSION_MAJOR
) ||
933 (client
->version
.minor
!= I40E_CLIENT_VERSION_MINOR
)) {
934 pr_info("i40e: Failed to register client %s due to mismatched client interface version\n",
936 pr_info("Client is using version: %02d.%02d.%02d while LAN driver supports %s\n",
937 client
->version
.major
, client
->version
.minor
,
938 client
->version
.build
,
939 i40e_client_interface_version_str
);
940 mutex_unlock(&i40e_client_mutex
);
945 vsi_type
= i40e_client_type_to_vsi_type(client
->type
);
946 if (vsi_type
== I40E_VSI_TYPE_UNKNOWN
) {
947 pr_info("i40e: Failed to register client %s due to unknown client type %d\n",
948 client
->name
, client
->type
);
949 mutex_unlock(&i40e_client_mutex
);
953 list_add(&client
->list
, &i40e_clients
);
954 set_bit(__I40E_CLIENT_REGISTERED
, &client
->state
);
955 mutex_unlock(&i40e_client_mutex
);
957 if (i40e_client_prepare(client
)) {
962 pr_info("i40e: Registered client %s with return code %d\n",
967 EXPORT_SYMBOL(i40e_register_client
);
970 * i40e_unregister_client - Unregister a i40e client driver with the L2 driver
971 * @client: pointer to the i40e_client struct
973 * Returns 0 on success or non-0 on error
975 int i40e_unregister_client(struct i40e_client
*client
)
979 /* When a unregister request comes through we would have to send
980 * a close for each of the client instances that were opened.
981 * client_release function is called to handle this.
983 if (!client
|| i40e_client_release(client
)) {
988 /* TODO: check if device is in reset, or if that matters? */
989 mutex_lock(&i40e_client_mutex
);
990 if (!i40e_client_is_registered(client
)) {
991 pr_info("i40e: Client %s has not been registered\n",
993 mutex_unlock(&i40e_client_mutex
);
997 if (atomic_read(&client
->ref_cnt
) == 0) {
998 clear_bit(__I40E_CLIENT_REGISTERED
, &client
->state
);
999 list_del(&client
->list
);
1000 pr_info("i40e: Unregistered client %s with return code %d\n",
1003 ret
= I40E_ERR_NOT_READY
;
1004 pr_err("i40e: Client %s failed unregister - client has open instances\n",
1008 mutex_unlock(&i40e_client_mutex
);
1012 EXPORT_SYMBOL(i40e_unregister_client
);