bnxt_en: Enable packet timestamping for all RX packets
authorPavan Chebbi <pavan.chebbi@broadcom.com>
Fri, 13 May 2022 02:40:23 +0000 (22:40 -0400)
committerDavid S. Miller <davem@davemloft.net>
Fri, 13 May 2022 11:47:40 +0000 (12:47 +0100)
Add driver support to enable timestamping on all RX packets
that are received by the NIC. This capability can be requested
by the applications using SIOCSHWTSTAMP ioctl with filter type
HWTSTAMP_FILTER_ALL.

Cc: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: Pavan Chebbi <pavan.chebbi@broadcom.com>
Signed-off-by: Michael Chan <michael.chan@broadcom.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/broadcom/bnxt/bnxt.c
drivers/net/ethernet/broadcom/bnxt/bnxt.h
drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c
drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c

index bcb3c16..56b46b8 100644 (file)
@@ -2040,7 +2040,7 @@ static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
        }
 
        if (unlikely((flags & RX_CMP_FLAGS_ITYPES_MASK) ==
-                    RX_CMP_FLAGS_ITYPE_PTP_W_TS)) {
+                    RX_CMP_FLAGS_ITYPE_PTP_W_TS) || bp->ptp_all_rx_tstamp) {
                if (bp->flags & BNXT_FLAG_CHIP_P5) {
                        u32 cmpl_ts = le32_to_cpu(rxcmp1->rx_cmp_timestamp);
                        u64 ns, ts;
@@ -7659,7 +7659,7 @@ static int __bnxt_hwrm_func_qcaps(struct bnxt *bp)
        struct hwrm_func_qcaps_output *resp;
        struct hwrm_func_qcaps_input *req;
        struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
-       u32 flags, flags_ext;
+       u32 flags, flags_ext, flags_ext2;
        int rc;
 
        rc = hwrm_req_init(bp, req, HWRM_FUNC_QCAPS);
@@ -7704,6 +7704,10 @@ static int __bnxt_hwrm_func_qcaps(struct bnxt *bp)
        if (BNXT_PF(bp) && (flags_ext & FUNC_QCAPS_RESP_FLAGS_EXT_FW_LIVEPATCH_SUPPORTED))
                bp->fw_cap |= BNXT_FW_CAP_LIVEPATCH;
 
+       flags_ext2 = le32_to_cpu(resp->flags_ext2);
+       if (flags_ext2 & FUNC_QCAPS_RESP_FLAGS_EXT2_RX_ALL_PKTS_TIMESTAMPS_SUPPORTED)
+               bp->fw_cap |= BNXT_FW_CAP_RX_ALL_PKT_TS;
+
        bp->tx_push_thresh = 0;
        if ((flags & FUNC_QCAPS_RESP_FLAGS_PUSH_MODE_SUPPORTED) &&
            BNXT_FW_MAJ(bp) > 217)
index a498ee2..a1dca8c 100644 (file)
@@ -1968,6 +1968,7 @@ struct bnxt {
        #define BNXT_FW_CAP_ERR_RECOVER_RELOAD          0x00100000
        #define BNXT_FW_CAP_HOT_RESET                   0x00200000
        #define BNXT_FW_CAP_PTP_RTC                     0x00400000
+       #define BNXT_FW_CAP_RX_ALL_PKT_TS               0x00800000
        #define BNXT_FW_CAP_VLAN_RX_STRIP               0x01000000
        #define BNXT_FW_CAP_VLAN_TX_INSERT              0x02000000
        #define BNXT_FW_CAP_EXT_HW_STATS_SUPPORTED      0x04000000
@@ -2131,6 +2132,7 @@ struct bnxt {
        struct bpf_prog         *xdp_prog;
 
        struct bnxt_ptp_cfg     *ptp_cfg;
+       u8                      ptp_all_rx_tstamp;
 
        /* devlink interface and vf-rep structs */
        struct devlink          *dl;
index b3a48d6..8a7f3f0 100644 (file)
@@ -3759,6 +3759,9 @@ static int bnxt_get_ts_info(struct net_device *dev,
        info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
                           (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
                           (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT);
+
+       if (bp->fw_cap & BNXT_FW_CAP_RX_ALL_PKT_TS)
+               info->rx_filters |= (1 << HWTSTAMP_FILTER_ALL);
        return 0;
 }
 
index f9c94e5..562f8f6 100644 (file)
@@ -305,14 +305,27 @@ void bnxt_ptp_cfg_tstamp_filters(struct bnxt *bp)
 
        if (hwrm_req_init(bp, req, HWRM_PORT_MAC_CFG))
                goto out;
+
+       if (!(bp->fw_cap & BNXT_FW_CAP_RX_ALL_PKT_TS) && (ptp->tstamp_filters &
+           (PORT_MAC_CFG_REQ_FLAGS_ALL_RX_TS_CAPTURE_ENABLE |
+            PORT_MAC_CFG_REQ_FLAGS_PTP_RX_TS_CAPTURE_DISABLE))) {
+               ptp->tstamp_filters &= ~(PORT_MAC_CFG_REQ_FLAGS_ALL_RX_TS_CAPTURE_ENABLE |
+                                        PORT_MAC_CFG_REQ_FLAGS_PTP_RX_TS_CAPTURE_DISABLE);
+               netdev_warn(bp->dev, "Unsupported FW for all RX pkts timestamp filter\n");
+       }
+
        req->flags = cpu_to_le32(ptp->tstamp_filters);
        req->enables = cpu_to_le32(PORT_MAC_CFG_REQ_ENABLES_RX_TS_CAPTURE_PTP_MSG_TYPE);
        req->rx_ts_capture_ptp_msg_type = cpu_to_le16(ptp->rxctl);
 
-       if (!hwrm_req_send(bp, req))
+       if (!hwrm_req_send(bp, req)) {
+               bp->ptp_all_rx_tstamp = !!(ptp->tstamp_filters &
+                                          PORT_MAC_CFG_REQ_FLAGS_ALL_RX_TS_CAPTURE_ENABLE);
                return;
+       }
        ptp->tstamp_filters = 0;
 out:
+       bp->ptp_all_rx_tstamp = 0;
        netdev_warn(bp->dev, "Failed to configure HW packet timestamp filters\n");
 }
 
@@ -460,8 +473,13 @@ static int bnxt_hwrm_ptp_cfg(struct bnxt *bp)
        int rc = 0;
 
        switch (ptp->rx_filter) {
+       case HWTSTAMP_FILTER_ALL:
+               flags = PORT_MAC_CFG_REQ_FLAGS_ALL_RX_TS_CAPTURE_ENABLE;
+               break;
        case HWTSTAMP_FILTER_NONE:
                flags = PORT_MAC_CFG_REQ_FLAGS_PTP_RX_TS_CAPTURE_DISABLE;
+               if (bp->fw_cap & BNXT_FW_CAP_RX_ALL_PKT_TS)
+                       flags |= PORT_MAC_CFG_REQ_FLAGS_ALL_RX_TS_CAPTURE_DISABLE;
                break;
        case HWTSTAMP_FILTER_PTP_V2_EVENT:
        case HWTSTAMP_FILTER_PTP_V2_SYNC:
@@ -516,6 +534,12 @@ int bnxt_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
                ptp->rxctl = 0;
                ptp->rx_filter = HWTSTAMP_FILTER_NONE;
                break;
+       case HWTSTAMP_FILTER_ALL:
+               if (bp->fw_cap & BNXT_FW_CAP_RX_ALL_PKT_TS) {
+                       ptp->rx_filter = HWTSTAMP_FILTER_ALL;
+                       break;
+               }
+               return -EOPNOTSUPP;
        case HWTSTAMP_FILTER_PTP_V2_EVENT:
        case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
        case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: