1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/list.h>
3 #include <linux/errno.h>
6 #include "i40e_prototype.h"
7 #include "i40evf_client.h"
10 const char i40evf_client_interface_version_str
[] = I40EVF_CLIENT_VERSION_STR
;
11 static struct i40e_client
*vf_registered_client
;
12 static LIST_HEAD(i40evf_devices
);
13 static DEFINE_MUTEX(i40evf_device_mutex
);
15 static u32
i40evf_client_virtchnl_send(struct i40e_info
*ldev
,
16 struct i40e_client
*client
,
19 static int i40evf_client_setup_qvlist(struct i40e_info
*ldev
,
20 struct i40e_client
*client
,
21 struct i40e_qvlist_info
*qvlist_info
);
23 static struct i40e_ops i40evf_lan_ops
= {
24 .virtchnl_send
= i40evf_client_virtchnl_send
,
25 .setup_qvlist
= i40evf_client_setup_qvlist
,
29 * i40evf_notify_client_message - call the client message receive callback
30 * @vsi: the VSI associated with this client
31 * @msg: message buffer
32 * @len: length of message
34 * If there is a client to this VSI, call the client
36 void i40evf_notify_client_message(struct i40e_vsi
*vsi
, u8
*msg
, u16 len
)
38 struct i40e_client_instance
*cinst
;
43 cinst
= vsi
->back
->cinst
;
44 if (!cinst
|| !cinst
->client
|| !cinst
->client
->ops
||
45 !cinst
->client
->ops
->virtchnl_receive
) {
46 dev_dbg(&vsi
->back
->pdev
->dev
,
47 "Cannot locate client instance virtchnl_receive function\n");
50 cinst
->client
->ops
->virtchnl_receive(&cinst
->lan_info
, cinst
->client
,
55 * i40evf_notify_client_l2_params - call the client notify callback
56 * @vsi: the VSI with l2 param changes
58 * If there is a client to this VSI, call the client
60 void i40evf_notify_client_l2_params(struct i40e_vsi
*vsi
)
62 struct i40e_client_instance
*cinst
;
63 struct i40e_params params
;
68 cinst
= vsi
->back
->cinst
;
69 memset(¶ms
, 0, sizeof(params
));
70 params
.mtu
= vsi
->netdev
->mtu
;
71 params
.link_up
= vsi
->back
->link_up
;
72 params
.qos
.prio_qos
[0].qs_handle
= vsi
->qs_handle
;
74 if (!cinst
|| !cinst
->client
|| !cinst
->client
->ops
||
75 !cinst
->client
->ops
->l2_param_change
) {
76 dev_dbg(&vsi
->back
->pdev
->dev
,
77 "Cannot locate client instance l2_param_change function\n");
80 cinst
->client
->ops
->l2_param_change(&cinst
->lan_info
, cinst
->client
,
85 * i40evf_notify_client_open - call the client open callback
86 * @vsi: the VSI with netdev opened
88 * If there is a client to this netdev, call the client with open
90 void i40evf_notify_client_open(struct i40e_vsi
*vsi
)
92 struct i40evf_adapter
*adapter
= vsi
->back
;
93 struct i40e_client_instance
*cinst
= adapter
->cinst
;
96 if (!cinst
|| !cinst
->client
|| !cinst
->client
->ops
||
97 !cinst
->client
->ops
->open
) {
98 dev_dbg(&vsi
->back
->pdev
->dev
,
99 "Cannot locate client instance open function\n");
102 if (!(test_bit(__I40E_CLIENT_INSTANCE_OPENED
, &cinst
->state
))) {
103 ret
= cinst
->client
->ops
->open(&cinst
->lan_info
, cinst
->client
);
105 set_bit(__I40E_CLIENT_INSTANCE_OPENED
, &cinst
->state
);
110 * i40evf_client_release_qvlist - send a message to the PF to release iwarp qv map
111 * @ldev: pointer to L2 context.
113 * Return 0 on success or < 0 on error
115 static int i40evf_client_release_qvlist(struct i40e_info
*ldev
)
117 struct i40evf_adapter
*adapter
= ldev
->vf
;
120 if (adapter
->aq_required
)
123 err
= i40e_aq_send_msg_to_pf(&adapter
->hw
,
124 VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP
,
125 I40E_SUCCESS
, NULL
, 0, NULL
);
128 dev_err(&adapter
->pdev
->dev
,
129 "Unable to send iWarp vector release message to PF, error %d, aq status %d\n",
130 err
, adapter
->hw
.aq
.asq_last_status
);
136 * i40evf_notify_client_close - call the client close callback
137 * @vsi: the VSI with netdev closed
138 * @reset: true when close called due to reset pending
140 * If there is a client to this netdev, call the client with close
142 void i40evf_notify_client_close(struct i40e_vsi
*vsi
, bool reset
)
144 struct i40evf_adapter
*adapter
= vsi
->back
;
145 struct i40e_client_instance
*cinst
= adapter
->cinst
;
147 if (!cinst
|| !cinst
->client
|| !cinst
->client
->ops
||
148 !cinst
->client
->ops
->close
) {
149 dev_dbg(&vsi
->back
->pdev
->dev
,
150 "Cannot locate client instance close function\n");
153 cinst
->client
->ops
->close(&cinst
->lan_info
, cinst
->client
, reset
);
154 i40evf_client_release_qvlist(&cinst
->lan_info
);
155 clear_bit(__I40E_CLIENT_INSTANCE_OPENED
, &cinst
->state
);
159 * i40evf_client_add_instance - add a client instance to the instance list
160 * @adapter: pointer to the board struct
161 * @client: pointer to a client struct in the client list.
163 * Returns cinst ptr on success, NULL on failure
165 static struct i40e_client_instance
*
166 i40evf_client_add_instance(struct i40evf_adapter
*adapter
)
168 struct i40e_client_instance
*cinst
= NULL
;
169 struct netdev_hw_addr
*mac
= NULL
;
170 struct i40e_vsi
*vsi
= &adapter
->vsi
;
173 if (!vf_registered_client
)
176 if (adapter
->cinst
) {
177 cinst
= adapter
->cinst
;
181 cinst
= kzalloc(sizeof(*cinst
), GFP_KERNEL
);
185 cinst
->lan_info
.vf
= (void *)adapter
;
186 cinst
->lan_info
.netdev
= vsi
->netdev
;
187 cinst
->lan_info
.pcidev
= adapter
->pdev
;
188 cinst
->lan_info
.fid
= 0;
189 cinst
->lan_info
.ftype
= I40E_CLIENT_FTYPE_VF
;
190 cinst
->lan_info
.hw_addr
= adapter
->hw
.hw_addr
;
191 cinst
->lan_info
.ops
= &i40evf_lan_ops
;
192 cinst
->lan_info
.version
.major
= I40EVF_CLIENT_VERSION_MAJOR
;
193 cinst
->lan_info
.version
.minor
= I40EVF_CLIENT_VERSION_MINOR
;
194 cinst
->lan_info
.version
.build
= I40EVF_CLIENT_VERSION_BUILD
;
195 set_bit(__I40E_CLIENT_INSTANCE_NONE
, &cinst
->state
);
197 cinst
->lan_info
.msix_count
= adapter
->num_iwarp_msix
;
198 cinst
->lan_info
.msix_entries
=
199 &adapter
->msix_entries
[adapter
->iwarp_base_vector
];
201 for (i
= 0; i
< I40E_MAX_USER_PRIORITY
; i
++) {
202 cinst
->lan_info
.params
.qos
.prio_qos
[i
].tc
= 0;
203 cinst
->lan_info
.params
.qos
.prio_qos
[i
].qs_handle
=
207 mac
= list_first_entry(&cinst
->lan_info
.netdev
->dev_addrs
.list
,
208 struct netdev_hw_addr
, list
);
210 ether_addr_copy(cinst
->lan_info
.lanmac
, mac
->addr
);
212 dev_err(&adapter
->pdev
->dev
, "MAC address list is empty!\n");
214 cinst
->client
= vf_registered_client
;
215 adapter
->cinst
= cinst
;
221 * i40evf_client_del_instance - removes a client instance from the list
222 * @adapter: pointer to the board struct
223 * @client: pointer to the client struct
227 void i40evf_client_del_instance(struct i40evf_adapter
*adapter
)
229 kfree(adapter
->cinst
);
230 adapter
->cinst
= NULL
;
234 * i40evf_client_subtask - client maintenance work
235 * @adapter: board private structure
237 void i40evf_client_subtask(struct i40evf_adapter
*adapter
)
239 struct i40e_client
*client
= vf_registered_client
;
240 struct i40e_client_instance
*cinst
;
243 if (adapter
->state
< __I40EVF_DOWN
)
246 /* first check client is registered */
250 /* Add the client instance to the instance list */
251 cinst
= i40evf_client_add_instance(adapter
);
255 dev_info(&adapter
->pdev
->dev
, "Added instance of Client %s\n",
258 if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED
, &cinst
->state
)) {
259 /* Send an Open request to the client */
261 if (client
->ops
&& client
->ops
->open
)
262 ret
= client
->ops
->open(&cinst
->lan_info
, client
);
264 set_bit(__I40E_CLIENT_INSTANCE_OPENED
,
267 /* remove client instance */
268 i40evf_client_del_instance(adapter
);
273 * i40evf_lan_add_device - add a lan device struct to the list of lan devices
274 * @adapter: pointer to the board struct
276 * Returns 0 on success or none 0 on error
278 int i40evf_lan_add_device(struct i40evf_adapter
*adapter
)
280 struct i40e_device
*ldev
;
283 mutex_lock(&i40evf_device_mutex
);
284 list_for_each_entry(ldev
, &i40evf_devices
, list
) {
285 if (ldev
->vf
== adapter
) {
290 ldev
= kzalloc(sizeof(*ldev
), GFP_KERNEL
);
296 INIT_LIST_HEAD(&ldev
->list
);
297 list_add(&ldev
->list
, &i40evf_devices
);
298 dev_info(&adapter
->pdev
->dev
, "Added LAN device bus=0x%02x dev=0x%02x func=0x%02x\n",
299 adapter
->hw
.bus
.bus_id
, adapter
->hw
.bus
.device
,
300 adapter
->hw
.bus
.func
);
302 /* Since in some cases register may have happened before a device gets
303 * added, we can schedule a subtask to go initiate the clients.
305 adapter
->flags
|= I40EVF_FLAG_SERVICE_CLIENT_REQUESTED
;
308 mutex_unlock(&i40evf_device_mutex
);
313 * i40evf_lan_del_device - removes a lan device from the device list
314 * @adapter: pointer to the board struct
316 * Returns 0 on success or non-0 on error
318 int i40evf_lan_del_device(struct i40evf_adapter
*adapter
)
320 struct i40e_device
*ldev
, *tmp
;
323 mutex_lock(&i40evf_device_mutex
);
324 list_for_each_entry_safe(ldev
, tmp
, &i40evf_devices
, list
) {
325 if (ldev
->vf
== adapter
) {
326 dev_info(&adapter
->pdev
->dev
,
327 "Deleted LAN device bus=0x%02x dev=0x%02x func=0x%02x\n",
328 adapter
->hw
.bus
.bus_id
, adapter
->hw
.bus
.device
,
329 adapter
->hw
.bus
.func
);
330 list_del(&ldev
->list
);
337 mutex_unlock(&i40evf_device_mutex
);
342 * i40evf_client_release - release client specific resources
343 * @client: pointer to the registered client
346 static void i40evf_client_release(struct i40e_client
*client
)
348 struct i40e_client_instance
*cinst
;
349 struct i40e_device
*ldev
;
350 struct i40evf_adapter
*adapter
;
352 mutex_lock(&i40evf_device_mutex
);
353 list_for_each_entry(ldev
, &i40evf_devices
, list
) {
355 cinst
= adapter
->cinst
;
358 if (test_bit(__I40E_CLIENT_INSTANCE_OPENED
, &cinst
->state
)) {
359 if (client
->ops
&& client
->ops
->close
)
360 client
->ops
->close(&cinst
->lan_info
, client
,
362 i40evf_client_release_qvlist(&cinst
->lan_info
);
363 clear_bit(__I40E_CLIENT_INSTANCE_OPENED
, &cinst
->state
);
365 dev_warn(&adapter
->pdev
->dev
,
366 "Client %s instance closed\n", client
->name
);
368 /* delete the client instance */
369 i40evf_client_del_instance(adapter
);
370 dev_info(&adapter
->pdev
->dev
, "Deleted client instance of Client %s\n",
373 mutex_unlock(&i40evf_device_mutex
);
377 * i40evf_client_prepare - prepare client specific resources
378 * @client: pointer to the registered client
381 static void i40evf_client_prepare(struct i40e_client
*client
)
383 struct i40e_device
*ldev
;
384 struct i40evf_adapter
*adapter
;
386 mutex_lock(&i40evf_device_mutex
);
387 list_for_each_entry(ldev
, &i40evf_devices
, list
) {
389 /* Signal the watchdog to service the client */
390 adapter
->flags
|= I40EVF_FLAG_SERVICE_CLIENT_REQUESTED
;
392 mutex_unlock(&i40evf_device_mutex
);
396 * i40evf_client_virtchnl_send - send a message to the PF instance
397 * @ldev: pointer to L2 context.
398 * @client: Client pointer.
399 * @msg: pointer to message buffer
400 * @len: message length
402 * Return 0 on success or < 0 on error
404 static u32
i40evf_client_virtchnl_send(struct i40e_info
*ldev
,
405 struct i40e_client
*client
,
408 struct i40evf_adapter
*adapter
= ldev
->vf
;
411 if (adapter
->aq_required
)
414 err
= i40e_aq_send_msg_to_pf(&adapter
->hw
, VIRTCHNL_OP_IWARP
,
415 I40E_SUCCESS
, msg
, len
, NULL
);
417 dev_err(&adapter
->pdev
->dev
, "Unable to send iWarp message to PF, error %d, aq status %d\n",
418 err
, adapter
->hw
.aq
.asq_last_status
);
424 * i40evf_client_setup_qvlist - send a message to the PF to setup iwarp qv map
425 * @ldev: pointer to L2 context.
426 * @client: Client pointer.
427 * @qv_info: queue and vector list
429 * Return 0 on success or < 0 on error
431 static int i40evf_client_setup_qvlist(struct i40e_info
*ldev
,
432 struct i40e_client
*client
,
433 struct i40e_qvlist_info
*qvlist_info
)
435 struct virtchnl_iwarp_qvlist_info
*v_qvlist_info
;
436 struct i40evf_adapter
*adapter
= ldev
->vf
;
437 struct i40e_qv_info
*qv_info
;
442 if (adapter
->aq_required
)
445 /* A quick check on whether the vectors belong to the client */
446 for (i
= 0; i
< qvlist_info
->num_vectors
; i
++) {
447 qv_info
= &qvlist_info
->qv_info
[i
];
450 v_idx
= qv_info
->v_idx
;
452 (adapter
->iwarp_base_vector
+ adapter
->num_iwarp_msix
)) ||
453 (v_idx
< adapter
->iwarp_base_vector
))
457 v_qvlist_info
= (struct virtchnl_iwarp_qvlist_info
*)qvlist_info
;
458 msg_size
= sizeof(struct virtchnl_iwarp_qvlist_info
) +
459 (sizeof(struct virtchnl_iwarp_qv_info
) *
460 (v_qvlist_info
->num_vectors
- 1));
462 adapter
->client_pending
|= BIT(VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP
);
463 err
= i40e_aq_send_msg_to_pf(&adapter
->hw
,
464 VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP
,
465 I40E_SUCCESS
, (u8
*)v_qvlist_info
, msg_size
, NULL
);
468 dev_err(&adapter
->pdev
->dev
,
469 "Unable to send iWarp vector config message to PF, error %d, aq status %d\n",
470 err
, adapter
->hw
.aq
.asq_last_status
);
475 for (i
= 0; i
< 5; i
++) {
477 if (!(adapter
->client_pending
&
478 BIT(VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP
))) {
488 * i40evf_register_client - Register a i40e client driver with the L2 driver
489 * @client: pointer to the i40e_client struct
491 * Returns 0 on success or non-0 on error
493 int i40evf_register_client(struct i40e_client
*client
)
502 if (strlen(client
->name
) == 0) {
503 pr_info("i40evf: Failed to register client with no name\n");
508 if (vf_registered_client
) {
509 pr_info("i40evf: Client %s has already been registered!\n",
515 if ((client
->version
.major
!= I40EVF_CLIENT_VERSION_MAJOR
) ||
516 (client
->version
.minor
!= I40EVF_CLIENT_VERSION_MINOR
)) {
517 pr_info("i40evf: Failed to register client %s due to mismatched client interface version\n",
519 pr_info("Client is using version: %02d.%02d.%02d while LAN driver supports %s\n",
520 client
->version
.major
, client
->version
.minor
,
521 client
->version
.build
,
522 i40evf_client_interface_version_str
);
527 vf_registered_client
= client
;
529 i40evf_client_prepare(client
);
531 pr_info("i40evf: Registered client %s with return code %d\n",
536 EXPORT_SYMBOL(i40evf_register_client
);
539 * i40evf_unregister_client - Unregister a i40e client driver with the L2 driver
540 * @client: pointer to the i40e_client struct
542 * Returns 0 on success or non-0 on error
544 int i40evf_unregister_client(struct i40e_client
*client
)
548 /* When a unregister request comes through we would have to send
549 * a close for each of the client instances that were opened.
550 * client_release function is called to handle this.
552 i40evf_client_release(client
);
554 if (vf_registered_client
!= client
) {
555 pr_info("i40evf: Client %s has not been registered\n",
560 vf_registered_client
= NULL
;
561 pr_info("i40evf: Unregistered client %s\n", client
->name
);
565 EXPORT_SYMBOL(i40evf_unregister_client
);