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
;
216 mutex_lock(&i40e_client_instance_mutex
);
217 list_for_each_entry(cdev
, &i40e_client_instances
, list
) {
218 if (cdev
->lan_info
.netdev
== vsi
->netdev
) {
220 !cdev
->client
->ops
|| !cdev
->client
->ops
->open
) {
221 dev_dbg(&vsi
->back
->pdev
->dev
,
222 "Cannot locate client instance open routine\n");
225 if (!(test_bit(__I40E_CLIENT_INSTANCE_OPENED
,
227 ret
= cdev
->client
->ops
->open(&cdev
->lan_info
,
230 set_bit(__I40E_CLIENT_INSTANCE_OPENED
,
235 mutex_unlock(&i40e_client_instance_mutex
);
239 * i40e_client_release_qvlist
240 * @ldev: pointer to L2 context.
243 static void i40e_client_release_qvlist(struct i40e_info
*ldev
)
245 struct i40e_qvlist_info
*qvlist_info
= ldev
->qvlist_info
;
248 if (!ldev
->qvlist_info
)
251 for (i
= 0; i
< qvlist_info
->num_vectors
; i
++) {
252 struct i40e_pf
*pf
= ldev
->pf
;
253 struct i40e_qv_info
*qv_info
;
256 qv_info
= &qvlist_info
->qv_info
[i
];
259 reg_idx
= I40E_PFINT_LNKLSTN(qv_info
->v_idx
- 1);
260 wr32(&pf
->hw
, reg_idx
, I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK
);
262 kfree(ldev
->qvlist_info
);
263 ldev
->qvlist_info
= NULL
;
267 * i40e_notify_client_of_netdev_close - call the client close callback
268 * @vsi: the VSI with netdev closed
269 * @reset: true when close called due to a reset pending
271 * If there is a client to this netdev, call the client with close
273 void i40e_notify_client_of_netdev_close(struct i40e_vsi
*vsi
, bool reset
)
275 struct i40e_client_instance
*cdev
;
279 mutex_lock(&i40e_client_instance_mutex
);
280 list_for_each_entry(cdev
, &i40e_client_instances
, list
) {
281 if (cdev
->lan_info
.netdev
== vsi
->netdev
) {
283 !cdev
->client
->ops
|| !cdev
->client
->ops
->close
) {
284 dev_dbg(&vsi
->back
->pdev
->dev
,
285 "Cannot locate client instance close routine\n");
288 cdev
->client
->ops
->close(&cdev
->lan_info
, cdev
->client
,
290 i40e_client_release_qvlist(&cdev
->lan_info
);
293 mutex_unlock(&i40e_client_instance_mutex
);
297 * i40e_notify_client_of_vf_reset - call the client vf reset callback
298 * @pf: PF device pointer
299 * @vf_id: asolute id of VF being reset
301 * If there is a client attached to this PF, notify when a VF is reset
303 void i40e_notify_client_of_vf_reset(struct i40e_pf
*pf
, u32 vf_id
)
305 struct i40e_client_instance
*cdev
;
309 mutex_lock(&i40e_client_instance_mutex
);
310 list_for_each_entry(cdev
, &i40e_client_instances
, list
) {
311 if (cdev
->lan_info
.pf
== pf
) {
313 !cdev
->client
->ops
||
314 !cdev
->client
->ops
->vf_reset
) {
315 dev_dbg(&pf
->pdev
->dev
,
316 "Cannot locate client instance VF reset routine\n");
319 if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED
,
321 dev_dbg(&pf
->pdev
->dev
, "Client is not open, abort vf-reset\n");
324 cdev
->client
->ops
->vf_reset(&cdev
->lan_info
,
325 cdev
->client
, vf_id
);
328 mutex_unlock(&i40e_client_instance_mutex
);
332 * i40e_notify_client_of_vf_enable - call the client vf notification callback
333 * @pf: PF device pointer
334 * @num_vfs: the number of VFs currently enabled, 0 for disable
336 * If there is a client attached to this PF, call its VF notification routine
338 void i40e_notify_client_of_vf_enable(struct i40e_pf
*pf
, u32 num_vfs
)
340 struct i40e_client_instance
*cdev
;
344 mutex_lock(&i40e_client_instance_mutex
);
345 list_for_each_entry(cdev
, &i40e_client_instances
, list
) {
346 if (cdev
->lan_info
.pf
== pf
) {
348 !cdev
->client
->ops
||
349 !cdev
->client
->ops
->vf_enable
) {
350 dev_dbg(&pf
->pdev
->dev
,
351 "Cannot locate client instance VF enable routine\n");
354 if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED
,
356 dev_dbg(&pf
->pdev
->dev
, "Client is not open, abort vf-enable\n");
359 cdev
->client
->ops
->vf_enable(&cdev
->lan_info
,
360 cdev
->client
, num_vfs
);
363 mutex_unlock(&i40e_client_instance_mutex
);
367 * i40e_vf_client_capable - ask the client if it likes the specified VF
368 * @pf: PF device pointer
369 * @vf_id: the VF in question
371 * If there is a client of the specified type attached to this PF, call
372 * its vf_capable routine
374 int i40e_vf_client_capable(struct i40e_pf
*pf
, u32 vf_id
,
375 enum i40e_client_type type
)
377 struct i40e_client_instance
*cdev
;
382 mutex_lock(&i40e_client_instance_mutex
);
383 list_for_each_entry(cdev
, &i40e_client_instances
, list
) {
384 if (cdev
->lan_info
.pf
== pf
) {
386 !cdev
->client
->ops
||
387 !cdev
->client
->ops
->vf_capable
||
388 !(cdev
->client
->type
== type
)) {
389 dev_dbg(&pf
->pdev
->dev
,
390 "Cannot locate client instance VF capability routine\n");
393 if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED
,
395 dev_dbg(&pf
->pdev
->dev
, "Client is not open, abort vf-capable\n");
398 capable
= cdev
->client
->ops
->vf_capable(&cdev
->lan_info
,
404 mutex_unlock(&i40e_client_instance_mutex
);
409 * i40e_vsi_lookup - finds a matching VSI from the PF list starting at start_vsi
410 * @pf: board private structure
412 * @start_vsi: a VSI pointer from where to start the search
414 * Returns non NULL on success or NULL for failure
416 struct i40e_vsi
*i40e_vsi_lookup(struct i40e_pf
*pf
,
417 enum i40e_vsi_type type
,
418 struct i40e_vsi
*start_vsi
)
420 struct i40e_vsi
*vsi
;
424 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
426 if (vsi
== start_vsi
)
430 for (; i
< pf
->num_alloc_vsi
; i
++) {
432 if (vsi
&& vsi
->type
== type
)
440 * i40e_client_add_instance - add a client instance struct to the instance list
441 * @pf: pointer to the board struct
442 * @client: pointer to a client struct in the client list.
443 * @existing: if there was already an existing instance
445 * Returns cdev ptr on success or if already exists, NULL on failure
448 struct i40e_client_instance
*i40e_client_add_instance(struct i40e_pf
*pf
,
449 struct i40e_client
*client
,
452 struct i40e_client_instance
*cdev
;
453 struct netdev_hw_addr
*mac
= NULL
;
454 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
456 mutex_lock(&i40e_client_instance_mutex
);
457 list_for_each_entry(cdev
, &i40e_client_instances
, list
) {
458 if ((cdev
->lan_info
.pf
== pf
) && (cdev
->client
== client
)) {
463 cdev
= kzalloc(sizeof(*cdev
), GFP_KERNEL
);
467 cdev
->lan_info
.pf
= (void *)pf
;
468 cdev
->lan_info
.netdev
= vsi
->netdev
;
469 cdev
->lan_info
.pcidev
= pf
->pdev
;
470 cdev
->lan_info
.fid
= pf
->hw
.pf_id
;
471 cdev
->lan_info
.ftype
= I40E_CLIENT_FTYPE_PF
;
472 cdev
->lan_info
.hw_addr
= pf
->hw
.hw_addr
;
473 cdev
->lan_info
.ops
= &i40e_lan_ops
;
474 cdev
->lan_info
.version
.major
= I40E_CLIENT_VERSION_MAJOR
;
475 cdev
->lan_info
.version
.minor
= I40E_CLIENT_VERSION_MINOR
;
476 cdev
->lan_info
.version
.build
= I40E_CLIENT_VERSION_BUILD
;
477 cdev
->lan_info
.fw_maj_ver
= pf
->hw
.aq
.fw_maj_ver
;
478 cdev
->lan_info
.fw_min_ver
= pf
->hw
.aq
.fw_min_ver
;
479 cdev
->lan_info
.fw_build
= pf
->hw
.aq
.fw_build
;
480 set_bit(__I40E_CLIENT_INSTANCE_NONE
, &cdev
->state
);
482 if (i40e_client_get_params(vsi
, &cdev
->lan_info
.params
)) {
488 cdev
->lan_info
.msix_count
= pf
->num_iwarp_msix
;
489 cdev
->lan_info
.msix_entries
= &pf
->msix_entries
[pf
->iwarp_base_vector
];
491 mac
= list_first_entry(&cdev
->lan_info
.netdev
->dev_addrs
.list
,
492 struct netdev_hw_addr
, list
);
494 ether_addr_copy(cdev
->lan_info
.lanmac
, mac
->addr
);
496 dev_err(&pf
->pdev
->dev
, "MAC address list is empty!\n");
498 cdev
->client
= client
;
499 INIT_LIST_HEAD(&cdev
->list
);
500 list_add(&cdev
->list
, &i40e_client_instances
);
502 mutex_unlock(&i40e_client_instance_mutex
);
507 * i40e_client_del_instance - removes a client instance from the list
508 * @pf: pointer to the board struct
510 * Returns 0 on success or non-0 on error
513 int i40e_client_del_instance(struct i40e_pf
*pf
, struct i40e_client
*client
)
515 struct i40e_client_instance
*cdev
, *tmp
;
518 mutex_lock(&i40e_client_instance_mutex
);
519 list_for_each_entry_safe(cdev
, tmp
, &i40e_client_instances
, list
) {
520 if ((cdev
->lan_info
.pf
!= pf
) || (cdev
->client
!= client
))
523 dev_info(&pf
->pdev
->dev
, "Deleted instance of Client %s, of dev %d bus=0x%02x func=0x%02x)\n",
524 client
->name
, pf
->hw
.pf_id
,
525 pf
->hw
.bus
.device
, pf
->hw
.bus
.func
);
526 list_del(&cdev
->list
);
531 mutex_unlock(&i40e_client_instance_mutex
);
536 * i40e_client_subtask - client maintenance work
537 * @pf: board private structure
539 void i40e_client_subtask(struct i40e_pf
*pf
)
541 struct i40e_client_instance
*cdev
;
542 struct i40e_client
*client
;
543 bool existing
= false;
546 if (!(pf
->flags
& I40E_FLAG_SERVICE_CLIENT_REQUESTED
))
548 pf
->flags
&= ~I40E_FLAG_SERVICE_CLIENT_REQUESTED
;
550 /* If we're down or resetting, just bail */
551 if (test_bit(__I40E_DOWN
, &pf
->state
) ||
552 test_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
555 /* Check client state and instantiate client if client registered */
556 mutex_lock(&i40e_client_mutex
);
557 list_for_each_entry(client
, &i40e_clients
, list
) {
558 /* first check client is registered */
559 if (!test_bit(__I40E_CLIENT_REGISTERED
, &client
->state
))
562 /* Do we also need the LAN VSI to be up, to create instance */
563 if (!(client
->flags
& I40E_CLIENT_FLAGS_LAUNCH_ON_PROBE
)) {
564 /* check if L2 VSI is up, if not we are not ready */
565 if (test_bit(__I40E_DOWN
, &pf
->vsi
[pf
->lan_vsi
]->state
))
568 dev_warn(&pf
->pdev
->dev
, "This client %s is being instanciated at probe\n",
572 /* Add the client instance to the instance list */
573 cdev
= i40e_client_add_instance(pf
, client
, &existing
);
578 /* Also up the ref_cnt for no. of instances of this
581 atomic_inc(&client
->ref_cnt
);
582 dev_info(&pf
->pdev
->dev
, "Added instance of Client %s to PF%d bus=0x%02x func=0x%02x\n",
583 client
->name
, pf
->hw
.pf_id
,
584 pf
->hw
.bus
.device
, pf
->hw
.bus
.func
);
587 mutex_lock(&i40e_client_instance_mutex
);
588 /* Send an Open request to the client */
589 atomic_inc(&cdev
->ref_cnt
);
590 if (client
->ops
&& client
->ops
->open
)
591 ret
= client
->ops
->open(&cdev
->lan_info
, client
);
592 atomic_dec(&cdev
->ref_cnt
);
594 set_bit(__I40E_CLIENT_INSTANCE_OPENED
, &cdev
->state
);
596 /* remove client instance */
597 mutex_unlock(&i40e_client_instance_mutex
);
598 i40e_client_del_instance(pf
, client
);
599 atomic_dec(&client
->ref_cnt
);
602 mutex_unlock(&i40e_client_instance_mutex
);
604 mutex_unlock(&i40e_client_mutex
);
608 * i40e_lan_add_device - add a lan device struct to the list of lan devices
609 * @pf: pointer to the board struct
611 * Returns 0 on success or none 0 on error
613 int i40e_lan_add_device(struct i40e_pf
*pf
)
615 struct i40e_device
*ldev
;
618 mutex_lock(&i40e_device_mutex
);
619 list_for_each_entry(ldev
, &i40e_devices
, list
) {
620 if (ldev
->pf
== pf
) {
625 ldev
= kzalloc(sizeof(*ldev
), GFP_KERNEL
);
631 INIT_LIST_HEAD(&ldev
->list
);
632 list_add(&ldev
->list
, &i40e_devices
);
633 dev_info(&pf
->pdev
->dev
, "Added LAN device PF%d bus=0x%02x func=0x%02x\n",
634 pf
->hw
.pf_id
, pf
->hw
.bus
.device
, pf
->hw
.bus
.func
);
636 /* Since in some cases register may have happened before a device gets
637 * added, we can schedule a subtask to go initiate the clients if
638 * they can be launched at probe time.
640 pf
->flags
|= I40E_FLAG_SERVICE_CLIENT_REQUESTED
;
641 i40e_service_event_schedule(pf
);
644 mutex_unlock(&i40e_device_mutex
);
649 * i40e_lan_del_device - removes a lan device from the device list
650 * @pf: pointer to the board struct
652 * Returns 0 on success or non-0 on error
654 int i40e_lan_del_device(struct i40e_pf
*pf
)
656 struct i40e_device
*ldev
, *tmp
;
659 mutex_lock(&i40e_device_mutex
);
660 list_for_each_entry_safe(ldev
, tmp
, &i40e_devices
, list
) {
661 if (ldev
->pf
== pf
) {
662 dev_info(&pf
->pdev
->dev
, "Deleted LAN device PF%d bus=0x%02x func=0x%02x\n",
663 pf
->hw
.pf_id
, pf
->hw
.bus
.device
,
665 list_del(&ldev
->list
);
672 mutex_unlock(&i40e_device_mutex
);
677 * i40e_client_release - release client specific resources
678 * @client: pointer to the registered client
680 * Return 0 on success or < 0 on error
682 static int i40e_client_release(struct i40e_client
*client
)
684 struct i40e_client_instance
*cdev
, *tmp
;
688 LIST_HEAD(cdevs_tmp
);
690 mutex_lock(&i40e_client_instance_mutex
);
691 list_for_each_entry_safe(cdev
, tmp
, &i40e_client_instances
, list
) {
692 if (strncmp(cdev
->client
->name
, client
->name
,
693 I40E_CLIENT_STR_LENGTH
))
695 pf
= (struct i40e_pf
*)cdev
->lan_info
.pf
;
696 if (test_bit(__I40E_CLIENT_INSTANCE_OPENED
, &cdev
->state
)) {
697 if (atomic_read(&cdev
->ref_cnt
) > 0) {
698 ret
= I40E_ERR_NOT_READY
;
701 if (client
->ops
&& client
->ops
->close
)
702 client
->ops
->close(&cdev
->lan_info
, client
,
704 i40e_client_release_qvlist(&cdev
->lan_info
);
705 clear_bit(__I40E_CLIENT_INSTANCE_OPENED
, &cdev
->state
);
707 dev_warn(&pf
->pdev
->dev
,
708 "Client %s instance for PF id %d closed\n",
709 client
->name
, pf
->hw
.pf_id
);
711 /* delete the client instance from the list */
712 list_move(&cdev
->list
, &cdevs_tmp
);
713 atomic_dec(&client
->ref_cnt
);
714 dev_info(&pf
->pdev
->dev
, "Deleted client instance of Client %s\n",
718 mutex_unlock(&i40e_client_instance_mutex
);
720 /* free the client device and release its vsi */
721 list_for_each_entry_safe(cdev
, tmp
, &cdevs_tmp
, list
) {
728 * i40e_client_prepare - prepare client specific resources
729 * @client: pointer to the registered client
731 * Return 0 on success or < 0 on error
733 static int i40e_client_prepare(struct i40e_client
*client
)
735 struct i40e_device
*ldev
;
739 mutex_lock(&i40e_device_mutex
);
740 list_for_each_entry(ldev
, &i40e_devices
, list
) {
742 /* Start the client subtask */
743 pf
->flags
|= I40E_FLAG_SERVICE_CLIENT_REQUESTED
;
744 i40e_service_event_schedule(pf
);
746 mutex_unlock(&i40e_device_mutex
);
751 * i40e_client_virtchnl_send - TBD
752 * @ldev: pointer to L2 context
753 * @client: Client pointer
754 * @vf_id: absolute VF identifier
755 * @msg: message buffer
756 * @len: length of message buffer
758 * Return 0 on success or < 0 on error
760 static int i40e_client_virtchnl_send(struct i40e_info
*ldev
,
761 struct i40e_client
*client
,
762 u32 vf_id
, u8
*msg
, u16 len
)
764 struct i40e_pf
*pf
= ldev
->pf
;
765 struct i40e_hw
*hw
= &pf
->hw
;
768 err
= i40e_aq_send_msg_to_vf(hw
, vf_id
, I40E_VIRTCHNL_OP_IWARP
,
771 dev_err(&pf
->pdev
->dev
, "Unable to send iWarp message to VF, error %d, aq status %d\n",
772 err
, hw
->aq
.asq_last_status
);
778 * i40e_client_setup_qvlist
779 * @ldev: pointer to L2 context.
780 * @client: Client pointer.
781 * @qv_info: queue and vector list
783 * Return 0 on success or < 0 on error
785 static int i40e_client_setup_qvlist(struct i40e_info
*ldev
,
786 struct i40e_client
*client
,
787 struct i40e_qvlist_info
*qvlist_info
)
789 struct i40e_pf
*pf
= ldev
->pf
;
790 struct i40e_hw
*hw
= &pf
->hw
;
791 struct i40e_qv_info
*qv_info
;
792 u32 v_idx
, i
, reg_idx
, reg
;
795 size
= sizeof(struct i40e_qvlist_info
) +
796 (sizeof(struct i40e_qv_info
) * (qvlist_info
->num_vectors
- 1));
797 ldev
->qvlist_info
= kzalloc(size
, GFP_KERNEL
);
798 ldev
->qvlist_info
->num_vectors
= qvlist_info
->num_vectors
;
800 for (i
= 0; i
< qvlist_info
->num_vectors
; i
++) {
801 qv_info
= &qvlist_info
->qv_info
[i
];
804 v_idx
= qv_info
->v_idx
;
806 /* Validate vector id belongs to this client */
807 if ((v_idx
>= (pf
->iwarp_base_vector
+ pf
->num_iwarp_msix
)) ||
808 (v_idx
< pf
->iwarp_base_vector
))
811 ldev
->qvlist_info
->qv_info
[i
] = *qv_info
;
812 reg_idx
= I40E_PFINT_LNKLSTN(v_idx
- 1);
814 if (qv_info
->ceq_idx
== I40E_QUEUE_INVALID_IDX
) {
815 /* Special case - No CEQ mapped on this vector */
816 wr32(hw
, reg_idx
, I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK
);
818 reg
= (qv_info
->ceq_idx
&
819 I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK
) |
820 (I40E_QUEUE_TYPE_PE_CEQ
<<
821 I40E_PFINT_LNKLSTN_FIRSTQ_TYPE_SHIFT
);
822 wr32(hw
, reg_idx
, reg
);
824 reg
= (I40E_PFINT_CEQCTL_CAUSE_ENA_MASK
|
825 (v_idx
<< I40E_PFINT_CEQCTL_MSIX_INDX_SHIFT
) |
827 I40E_PFINT_CEQCTL_ITR_INDX_SHIFT
) |
828 (I40E_QUEUE_END_OF_LIST
<<
829 I40E_PFINT_CEQCTL_NEXTQ_INDX_SHIFT
));
830 wr32(hw
, I40E_PFINT_CEQCTL(qv_info
->ceq_idx
), reg
);
832 if (qv_info
->aeq_idx
!= I40E_QUEUE_INVALID_IDX
) {
833 reg
= (I40E_PFINT_AEQCTL_CAUSE_ENA_MASK
|
834 (v_idx
<< I40E_PFINT_AEQCTL_MSIX_INDX_SHIFT
) |
836 I40E_PFINT_AEQCTL_ITR_INDX_SHIFT
));
838 wr32(hw
, I40E_PFINT_AEQCTL
, reg
);
841 /* Mitigate sync problems with iwarp VF driver */
845 kfree(ldev
->qvlist_info
);
846 ldev
->qvlist_info
= NULL
;
851 * i40e_client_request_reset
852 * @ldev: pointer to L2 context.
853 * @client: Client pointer.
854 * @level: reset level
856 static void i40e_client_request_reset(struct i40e_info
*ldev
,
857 struct i40e_client
*client
,
860 struct i40e_pf
*pf
= ldev
->pf
;
862 switch (reset_level
) {
863 case I40E_CLIENT_RESET_LEVEL_PF
:
864 set_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
866 case I40E_CLIENT_RESET_LEVEL_CORE
:
867 set_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
870 dev_warn(&pf
->pdev
->dev
,
871 "Client %s instance for PF id %d request an unsupported reset: %d.\n",
872 client
->name
, pf
->hw
.pf_id
, reset_level
);
876 i40e_service_event_schedule(pf
);
880 * i40e_client_update_vsi_ctxt
881 * @ldev: pointer to L2 context.
882 * @client: Client pointer.
883 * @is_vf: if this for the VF
884 * @vf_id: if is_vf true this carries the vf_id
885 * @flag: Any device level setting that needs to be done for PE
886 * @valid_flag: Bits in this match up and enable changing of flag bits
888 * Return 0 on success or < 0 on error
890 static int i40e_client_update_vsi_ctxt(struct i40e_info
*ldev
,
891 struct i40e_client
*client
,
892 bool is_vf
, u32 vf_id
,
893 u32 flag
, u32 valid_flag
)
895 struct i40e_pf
*pf
= ldev
->pf
;
896 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
897 struct i40e_vsi_context ctxt
;
901 /* TODO: for now do not allow setting VF's VSI setting */
905 ctxt
.seid
= pf
->main_vsi_seid
;
906 ctxt
.pf_num
= pf
->hw
.pf_id
;
907 err
= i40e_aq_get_vsi_params(&pf
->hw
, &ctxt
, NULL
);
908 ctxt
.flags
= I40E_AQ_VSI_TYPE_PF
;
910 dev_info(&pf
->pdev
->dev
,
911 "couldn't get PF vsi config, err %s aq_err %s\n",
912 i40e_stat_str(&pf
->hw
, err
),
914 pf
->hw
.aq
.asq_last_status
));
918 if ((valid_flag
& I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE
) &&
919 (flag
& I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE
)) {
920 ctxt
.info
.valid_sections
=
921 cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID
);
922 ctxt
.info
.queueing_opt_flags
|= I40E_AQ_VSI_QUE_OPT_TCP_ENA
;
923 } else if ((valid_flag
& I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE
) &&
924 !(flag
& I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE
)) {
925 ctxt
.info
.valid_sections
=
926 cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID
);
927 ctxt
.info
.queueing_opt_flags
&= ~I40E_AQ_VSI_QUE_OPT_TCP_ENA
;
930 dev_warn(&pf
->pdev
->dev
,
931 "Client %s instance for PF id %d request an unsupported Config: %x.\n",
932 client
->name
, pf
->hw
.pf_id
, flag
);
936 err
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
938 dev_info(&pf
->pdev
->dev
,
939 "update VSI ctxt for PE failed, err %s aq_err %s\n",
940 i40e_stat_str(&pf
->hw
, err
),
942 pf
->hw
.aq
.asq_last_status
));
949 * i40e_register_client - Register a i40e client driver with the L2 driver
950 * @client: pointer to the i40e_client struct
952 * Returns 0 on success or non-0 on error
954 int i40e_register_client(struct i40e_client
*client
)
957 enum i40e_vsi_type vsi_type
;
964 if (strlen(client
->name
) == 0) {
965 pr_info("i40e: Failed to register client with no name\n");
970 mutex_lock(&i40e_client_mutex
);
971 if (i40e_client_is_registered(client
)) {
972 pr_info("i40e: Client %s has already been registered!\n",
974 mutex_unlock(&i40e_client_mutex
);
979 if ((client
->version
.major
!= I40E_CLIENT_VERSION_MAJOR
) ||
980 (client
->version
.minor
!= I40E_CLIENT_VERSION_MINOR
)) {
981 pr_info("i40e: Failed to register client %s due to mismatched client interface version\n",
983 pr_info("Client is using version: %02d.%02d.%02d while LAN driver supports %s\n",
984 client
->version
.major
, client
->version
.minor
,
985 client
->version
.build
,
986 i40e_client_interface_version_str
);
987 mutex_unlock(&i40e_client_mutex
);
992 vsi_type
= i40e_client_type_to_vsi_type(client
->type
);
993 if (vsi_type
== I40E_VSI_TYPE_UNKNOWN
) {
994 pr_info("i40e: Failed to register client %s due to unknown client type %d\n",
995 client
->name
, client
->type
);
996 mutex_unlock(&i40e_client_mutex
);
1000 list_add(&client
->list
, &i40e_clients
);
1001 set_bit(__I40E_CLIENT_REGISTERED
, &client
->state
);
1002 mutex_unlock(&i40e_client_mutex
);
1004 if (i40e_client_prepare(client
)) {
1009 pr_info("i40e: Registered client %s with return code %d\n",
1014 EXPORT_SYMBOL(i40e_register_client
);
1017 * i40e_unregister_client - Unregister a i40e client driver with the L2 driver
1018 * @client: pointer to the i40e_client struct
1020 * Returns 0 on success or non-0 on error
1022 int i40e_unregister_client(struct i40e_client
*client
)
1026 /* When a unregister request comes through we would have to send
1027 * a close for each of the client instances that were opened.
1028 * client_release function is called to handle this.
1030 mutex_lock(&i40e_client_mutex
);
1031 if (!client
|| i40e_client_release(client
)) {
1036 /* TODO: check if device is in reset, or if that matters? */
1037 if (!i40e_client_is_registered(client
)) {
1038 pr_info("i40e: Client %s has not been registered\n",
1043 if (atomic_read(&client
->ref_cnt
) == 0) {
1044 clear_bit(__I40E_CLIENT_REGISTERED
, &client
->state
);
1045 list_del(&client
->list
);
1046 pr_info("i40e: Unregistered client %s with return code %d\n",
1049 ret
= I40E_ERR_NOT_READY
;
1050 pr_err("i40e: Client %s failed unregister - client has open instances\n",
1055 mutex_unlock(&i40e_client_mutex
);
1058 EXPORT_SYMBOL(i40e_unregister_client
);