Skip to content

Commit c565b6e

Browse files
committed
iavf: negotiate PTP capabilities
JIRA: https://issues.redhat.com/browse/RHEL-83568 commit 3247d65 Author: Jacob Keller <jacob.e.keller@intel.com> Date: Wed Nov 6 12:37:22 2024 -0500 iavf: negotiate PTP capabilities Add a new extended capabilities negotiation to exchange information from the PF about what PTP capabilities are supported by this VF. This requires sending a VIRTCHNL_OP_1588_PTP_GET_CAPS message, and waiting for the response from the PF. Handle this early on during the VF initialization. Signed-off-by: Jacob Keller <jacob.e.keller@intel.com> Reviewed-by: Simon Horman <horms@kernel.org> Tested-by: Rafal Romanowski <rafal.romanowski@intel.com> Co-developed-by: Mateusz Polchlopek <mateusz.polchlopek@intel.com> Signed-off-by: Mateusz Polchlopek <mateusz.polchlopek@intel.com> Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com> Signed-off-by: Michal Schmidt <mschmidt@redhat.com>
1 parent bfec27f commit c565b6e

File tree

5 files changed

+178
-2
lines changed

5 files changed

+178
-2
lines changed

drivers/net/ethernet/intel/iavf/iavf.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "iavf_txrx.h"
4242
#include "iavf_fdir.h"
4343
#include "iavf_adv_rss.h"
44+
#include "iavf_types.h"
4445
#include <linux/bitmap.h>
4546

4647
#define DEFAULT_DEBUG_LEVEL_SHIFT 3
@@ -345,13 +346,16 @@ struct iavf_adapter {
345346
#define IAVF_FLAG_AQ_CFG_QUEUES_QUANTA_SIZE BIT_ULL(40)
346347
#define IAVF_FLAG_AQ_GET_QOS_CAPS BIT_ULL(41)
347348
#define IAVF_FLAG_AQ_GET_SUPPORTED_RXDIDS BIT_ULL(42)
349+
#define IAVF_FLAG_AQ_GET_PTP_CAPS BIT_ULL(43)
350+
#define IAVF_FLAG_AQ_SEND_PTP_CMD BIT_ULL(44)
348351

349352
/* AQ messages that must be sent after IAVF_FLAG_AQ_GET_CONFIG, in
350353
* order to negotiated extended capabilities.
351354
*/
352355
#define IAVF_FLAG_AQ_EXTENDED_CAPS \
353356
(IAVF_FLAG_AQ_GET_OFFLOAD_VLAN_V2_CAPS | \
354-
IAVF_FLAG_AQ_GET_SUPPORTED_RXDIDS)
357+
IAVF_FLAG_AQ_GET_SUPPORTED_RXDIDS | \
358+
IAVF_FLAG_AQ_GET_PTP_CAPS)
355359

356360
/* flags for processing extended capability messages during
357361
* __IAVF_INIT_EXTENDED_CAPS. Each capability exchange requires
@@ -365,12 +369,16 @@ struct iavf_adapter {
365369
#define IAVF_EXTENDED_CAP_RECV_VLAN_V2 BIT_ULL(1)
366370
#define IAVF_EXTENDED_CAP_SEND_RXDID BIT_ULL(2)
367371
#define IAVF_EXTENDED_CAP_RECV_RXDID BIT_ULL(3)
372+
#define IAVF_EXTENDED_CAP_SEND_PTP BIT_ULL(4)
373+
#define IAVF_EXTENDED_CAP_RECV_PTP BIT_ULL(5)
368374

369375
#define IAVF_EXTENDED_CAPS \
370376
(IAVF_EXTENDED_CAP_SEND_VLAN_V2 | \
371377
IAVF_EXTENDED_CAP_RECV_VLAN_V2 | \
372378
IAVF_EXTENDED_CAP_SEND_RXDID | \
373-
IAVF_EXTENDED_CAP_RECV_RXDID)
379+
IAVF_EXTENDED_CAP_RECV_RXDID | \
380+
IAVF_EXTENDED_CAP_SEND_PTP | \
381+
IAVF_EXTENDED_CAP_RECV_PTP)
374382

375383
/* Lock to prevent possible clobbering of
376384
* current_netdev_promisc_flags
@@ -432,13 +440,16 @@ struct iavf_adapter {
432440
VIRTCHNL_VF_OFFLOAD_QOS)
433441
#define IAVF_RXDID_ALLOWED(a) \
434442
((a)->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC)
443+
#define IAVF_PTP_ALLOWED(a) \
444+
((a)->vf_res->vf_cap_flags & VIRTCHNL_VF_CAP_PTP)
435445
struct virtchnl_vf_resource *vf_res; /* incl. all VSIs */
436446
struct virtchnl_vsi_resource *vsi_res; /* our LAN VSI */
437447
struct virtchnl_version_info pf_version;
438448
#define PF_IS_V11(_a) (((_a)->pf_version.major == 1) && \
439449
((_a)->pf_version.minor == 1))
440450
struct virtchnl_vlan_caps vlan_v2_caps;
441451
u64 supp_rxdids;
452+
struct iavf_ptp ptp;
442453
u16 msg_enable;
443454
struct iavf_eth_stats current_stats;
444455
struct virtchnl_qos_cap_list *qos_caps;
@@ -573,6 +584,8 @@ int iavf_get_vf_vlan_v2_caps(struct iavf_adapter *adapter);
573584
int iavf_send_vf_offload_vlan_v2_msg(struct iavf_adapter *adapter);
574585
int iavf_send_vf_supported_rxdids_msg(struct iavf_adapter *adapter);
575586
int iavf_get_vf_supported_rxdids(struct iavf_adapter *adapter);
587+
int iavf_send_vf_ptp_caps_msg(struct iavf_adapter *adapter);
588+
int iavf_get_vf_ptp_caps(struct iavf_adapter *adapter);
576589
void iavf_set_queue_vlan_tag_loc(struct iavf_adapter *adapter);
577590
u16 iavf_get_num_vlans_added(struct iavf_adapter *adapter);
578591
void iavf_irq_enable(struct iavf_adapter *adapter, bool flush);

drivers/net/ethernet/intel/iavf/iavf_main.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2102,6 +2102,8 @@ static int iavf_process_aq_command(struct iavf_adapter *adapter)
21022102
return iavf_send_vf_offload_vlan_v2_msg(adapter);
21032103
if (adapter->aq_required & IAVF_FLAG_AQ_GET_SUPPORTED_RXDIDS)
21042104
return iavf_send_vf_supported_rxdids_msg(adapter);
2105+
if (adapter->aq_required & IAVF_FLAG_AQ_GET_PTP_CAPS)
2106+
return iavf_send_vf_ptp_caps_msg(adapter);
21052107
if (adapter->aq_required & IAVF_FLAG_AQ_DISABLE_QUEUES) {
21062108
iavf_disable_queues(adapter);
21072109
return 0;
@@ -2687,6 +2689,55 @@ static void iavf_init_recv_supported_rxdids(struct iavf_adapter *adapter)
26872689
iavf_change_state(adapter, __IAVF_INIT_FAILED);
26882690
}
26892691

2692+
/**
2693+
* iavf_init_send_ptp_caps - part of querying for extended PTP capabilities
2694+
* @adapter: board private structure
2695+
*
2696+
* Function processes send of the request for 1588 PTP capabilities to the PF.
2697+
* Must clear IAVF_EXTENDED_CAP_SEND_PTP if the message is not sent, e.g.
2698+
* due to the PF not negotiating VIRTCHNL_VF_PTP_CAP
2699+
*/
2700+
static void iavf_init_send_ptp_caps(struct iavf_adapter *adapter)
2701+
{
2702+
if (iavf_send_vf_ptp_caps_msg(adapter) == -EOPNOTSUPP) {
2703+
/* PF does not support VIRTCHNL_VF_PTP_CAP. In this case, we
2704+
* did not send the capability exchange message and do not
2705+
* expect a response.
2706+
*/
2707+
adapter->extended_caps &= ~IAVF_EXTENDED_CAP_RECV_PTP;
2708+
}
2709+
2710+
/* We sent the message, so move on to the next step */
2711+
adapter->extended_caps &= ~IAVF_EXTENDED_CAP_SEND_PTP;
2712+
}
2713+
2714+
/**
2715+
* iavf_init_recv_ptp_caps - part of querying for supported PTP capabilities
2716+
* @adapter: board private structure
2717+
*
2718+
* Function processes receipt of the PTP capabilities supported on this VF.
2719+
**/
2720+
static void iavf_init_recv_ptp_caps(struct iavf_adapter *adapter)
2721+
{
2722+
memset(&adapter->ptp.hw_caps, 0, sizeof(adapter->ptp.hw_caps));
2723+
2724+
if (iavf_get_vf_ptp_caps(adapter))
2725+
goto err;
2726+
2727+
/* We've processed the PF response to the VIRTCHNL_OP_1588_PTP_GET_CAPS
2728+
* message we sent previously.
2729+
*/
2730+
adapter->extended_caps &= ~IAVF_EXTENDED_CAP_RECV_PTP;
2731+
return;
2732+
2733+
err:
2734+
/* We didn't receive a reply. Make sure we try sending again when
2735+
* __IAVF_INIT_FAILED attempts to recover.
2736+
*/
2737+
adapter->extended_caps |= IAVF_EXTENDED_CAP_SEND_PTP;
2738+
iavf_change_state(adapter, __IAVF_INIT_FAILED);
2739+
}
2740+
26902741
/**
26912742
* iavf_init_process_extended_caps - Part of driver startup
26922743
* @adapter: board private structure
@@ -2720,6 +2771,15 @@ static void iavf_init_process_extended_caps(struct iavf_adapter *adapter)
27202771
return;
27212772
}
27222773

2774+
/* Process capability exchange for PTP features */
2775+
if (adapter->extended_caps & IAVF_EXTENDED_CAP_SEND_PTP) {
2776+
iavf_init_send_ptp_caps(adapter);
2777+
return;
2778+
} else if (adapter->extended_caps & IAVF_EXTENDED_CAP_RECV_PTP) {
2779+
iavf_init_recv_ptp_caps(adapter);
2780+
return;
2781+
}
2782+
27232783
/* When we reach here, no further extended capabilities exchanges are
27242784
* necessary, so we finally transition into __IAVF_INIT_CONFIG_ADAPTER
27252785
*/
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/* Copyright(c) 2024 Intel Corporation. */
3+
4+
#ifndef _IAVF_PTP_H_
5+
#define _IAVF_PTP_H_
6+
7+
#include "iavf_types.h"
8+
9+
#endif /* _IAVF_PTP_H_ */
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/* Copyright(c) 2024 Intel Corporation. */
3+
4+
#ifndef _IAVF_TYPES_H_
5+
#define _IAVF_TYPES_H_
6+
7+
#include "iavf_types.h"
8+
9+
#include <linux/avf/virtchnl.h>
10+
#include <linux/ptp_clock_kernel.h>
11+
12+
/* structure used to queue PTP commands for processing */
13+
struct iavf_ptp_aq_cmd {
14+
struct list_head list;
15+
enum virtchnl_ops v_opcode:16;
16+
u16 msglen;
17+
u8 msg[] __counted_by(msglen);
18+
};
19+
20+
struct iavf_ptp {
21+
wait_queue_head_t phc_time_waitqueue;
22+
struct virtchnl_ptp_caps hw_caps;
23+
struct ptp_clock_info info;
24+
struct ptp_clock *clock;
25+
struct list_head aq_cmds;
26+
u64 cached_phc_time;
27+
unsigned long cached_phc_updated;
28+
/* Lock protecting access to the AQ command list */
29+
struct mutex aq_cmd_lock;
30+
struct kernel_hwtstamp_config hwtstamp_config;
31+
bool phc_time_ready:1;
32+
};
33+
34+
#endif /* _IAVF_TYPES_H_ */

drivers/net/ethernet/intel/iavf/iavf_virtchnl.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ int iavf_send_vf_config_msg(struct iavf_adapter *adapter)
148148
VIRTCHNL_VF_OFFLOAD_CRC |
149149
VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM |
150150
VIRTCHNL_VF_OFFLOAD_REQ_QUEUES |
151+
VIRTCHNL_VF_CAP_PTP |
151152
VIRTCHNL_VF_OFFLOAD_ADQ |
152153
VIRTCHNL_VF_OFFLOAD_USO |
153154
VIRTCHNL_VF_OFFLOAD_FDIR_PF |
@@ -191,6 +192,41 @@ int iavf_send_vf_supported_rxdids_msg(struct iavf_adapter *adapter)
191192
NULL, 0);
192193
}
193194

195+
/**
196+
* iavf_send_vf_ptp_caps_msg - Send request for PTP capabilities
197+
* @adapter: private adapter structure
198+
*
199+
* Send the VIRTCHNL_OP_1588_PTP_GET_CAPS command to the PF to request the PTP
200+
* capabilities available to this device. This includes the following
201+
* potential access:
202+
*
203+
* * READ_PHC - access to read the PTP hardware clock time
204+
* * RX_TSTAMP - access to request Rx timestamps on all received packets
205+
*
206+
* The PF will reply with the same opcode a filled out copy of the
207+
* virtchnl_ptp_caps structure which defines the specifics of which features
208+
* are accessible to this device.
209+
*
210+
* Return: 0 if success, error code otherwise.
211+
*/
212+
int iavf_send_vf_ptp_caps_msg(struct iavf_adapter *adapter)
213+
{
214+
struct virtchnl_ptp_caps hw_caps = {
215+
.caps = VIRTCHNL_1588_PTP_CAP_READ_PHC |
216+
VIRTCHNL_1588_PTP_CAP_RX_TSTAMP
217+
};
218+
219+
adapter->aq_required &= ~IAVF_FLAG_AQ_GET_PTP_CAPS;
220+
221+
if (!IAVF_PTP_ALLOWED(adapter))
222+
return -EOPNOTSUPP;
223+
224+
adapter->current_op = VIRTCHNL_OP_1588_PTP_GET_CAPS;
225+
226+
return iavf_send_pf_msg(adapter, VIRTCHNL_OP_1588_PTP_GET_CAPS,
227+
(u8 *)&hw_caps, sizeof(hw_caps));
228+
}
229+
194230
/**
195231
* iavf_validate_num_queues
196232
* @adapter: adapter structure
@@ -294,6 +330,23 @@ int iavf_get_vf_supported_rxdids(struct iavf_adapter *adapter)
294330
return err;
295331
}
296332

333+
int iavf_get_vf_ptp_caps(struct iavf_adapter *adapter)
334+
{
335+
struct virtchnl_ptp_caps caps = {};
336+
struct iavf_arq_event_info event;
337+
int err;
338+
339+
event.msg_buf = (u8 *)&caps;
340+
event.buf_len = sizeof(caps);
341+
342+
err = iavf_poll_virtchnl_msg(&adapter->hw, &event,
343+
VIRTCHNL_OP_1588_PTP_GET_CAPS);
344+
if (!err)
345+
adapter->ptp.hw_caps = caps;
346+
347+
return err;
348+
}
349+
297350
/**
298351
* iavf_configure_queues
299352
* @adapter: adapter structure
@@ -2548,6 +2601,13 @@ void iavf_virtchnl_completion(struct iavf_adapter *adapter,
25482601

25492602
adapter->supp_rxdids = *(u64 *)msg;
25502603

2604+
break;
2605+
case VIRTCHNL_OP_1588_PTP_GET_CAPS:
2606+
if (msglen != sizeof(adapter->ptp.hw_caps))
2607+
return;
2608+
2609+
adapter->ptp.hw_caps = *(struct virtchnl_ptp_caps *)msg;
2610+
25512611
break;
25522612
case VIRTCHNL_OP_ENABLE_QUEUES:
25532613
/* enable transmits */

0 commit comments

Comments
 (0)