bnxt_en: Configure ptp filters during bnxt open
authorPavan Chebbi <pavan.chebbi@broadcom.com>
Fri, 13 May 2022 02:40:22 +0000 (22:40 -0400)
committerDavid S. Miller <davem@davemloft.net>
Fri, 13 May 2022 11:47:40 +0000 (12:47 +0100)
For correctness, we need to configure the packet filters for timestamping
during bnxt_open.  This way they are always configured after firmware
reset or chip reset.  We should not assume that the filters will always
be retained across resets.

This patch modifies the ioctl handler and always configures the PTP
filters in the bnxt_open() path.

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_ptp.c
drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.h

index 082518e68579bc317fd5ff8f2f91eb2a5eee6110..bcb3c16bf915eecf5d32b8436926dbf23d23030d 100644 (file)
@@ -10508,6 +10508,7 @@ static int __bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
        if (BNXT_PF(bp))
                bnxt_vf_reps_open(bp);
        bnxt_ptp_init_rtc(bp, true);
+       bnxt_ptp_cfg_tstamp_filters(bp);
        return 0;
 
 open_err_irq:
index 00f2f80c007332911cec143635c7589f474dcfc8..f9c94e5fe7187744a547ca999778a6bd1c3c5819 100644 (file)
@@ -295,6 +295,27 @@ static int bnxt_ptp_cfg_event(struct bnxt *bp, u8 event)
        return hwrm_req_send(bp, req);
 }
 
+void bnxt_ptp_cfg_tstamp_filters(struct bnxt *bp)
+{
+       struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
+       struct hwrm_port_mac_cfg_input *req;
+
+       if (!ptp || !ptp->tstamp_filters)
+               return;
+
+       if (hwrm_req_init(bp, req, HWRM_PORT_MAC_CFG))
+               goto out;
+       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))
+               return;
+       ptp->tstamp_filters = 0;
+out:
+       netdev_warn(bp->dev, "Failed to configure HW packet timestamp filters\n");
+}
+
 void bnxt_ptp_reapply_pps(struct bnxt *bp)
 {
        struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
@@ -435,27 +456,36 @@ static int bnxt_ptp_enable(struct ptp_clock_info *ptp_info,
 static int bnxt_hwrm_ptp_cfg(struct bnxt *bp)
 {
        struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
-       struct hwrm_port_mac_cfg_input *req;
        u32 flags = 0;
-       int rc;
+       int rc = 0;
 
-       rc = hwrm_req_init(bp, req, HWRM_PORT_MAC_CFG);
-       if (rc)
-               return rc;
+       switch (ptp->rx_filter) {
+       case HWTSTAMP_FILTER_NONE:
+               flags = PORT_MAC_CFG_REQ_FLAGS_PTP_RX_TS_CAPTURE_DISABLE;
+               break;
+       case HWTSTAMP_FILTER_PTP_V2_EVENT:
+       case HWTSTAMP_FILTER_PTP_V2_SYNC:
+       case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
+               flags = PORT_MAC_CFG_REQ_FLAGS_PTP_RX_TS_CAPTURE_ENABLE;
+               break;
+       }
 
-       if (ptp->rx_filter)
-               flags |= PORT_MAC_CFG_REQ_FLAGS_PTP_RX_TS_CAPTURE_ENABLE;
-       else
-               flags |= PORT_MAC_CFG_REQ_FLAGS_PTP_RX_TS_CAPTURE_DISABLE;
        if (ptp->tx_tstamp_en)
                flags |= PORT_MAC_CFG_REQ_FLAGS_PTP_TX_TS_CAPTURE_ENABLE;
        else
                flags |= PORT_MAC_CFG_REQ_FLAGS_PTP_TX_TS_CAPTURE_DISABLE;
-       req->flags = cpu_to_le32(flags);
-       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);
 
-       return hwrm_req_send(bp, req);
+       ptp->tstamp_filters = flags;
+
+       if (netif_running(bp->dev)) {
+               rc = bnxt_close_nic(bp, false, false);
+               if (!rc)
+                       rc = bnxt_open_nic(bp, false, false);
+               if (!rc && !ptp->tstamp_filters)
+                       rc = -EIO;
+       }
+
+       return rc;
 }
 
 int bnxt_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
index 530b9922608c8bc007a75512c3f1b37cec0dee7f..4ce0a14c1e2326840a7c198be56baef3ae8a26d7 100644 (file)
@@ -113,6 +113,7 @@ struct bnxt_ptp_cfg {
                                         BNXT_PTP_MSG_PDELAY_RESP)
        u8                      tx_tstamp_en:1;
        int                     rx_filter;
+       u32                     tstamp_filters;
 
        u32                     refclk_regs[2];
        u32                     refclk_mapped_regs[2];
@@ -133,6 +134,7 @@ do {                                                \
 int bnxt_ptp_parse(struct sk_buff *skb, u16 *seq_id, u16 *hdr_off);
 void bnxt_ptp_update_current_time(struct bnxt *bp);
 void bnxt_ptp_pps_event(struct bnxt *bp, u32 data1, u32 data2);
+void bnxt_ptp_cfg_tstamp_filters(struct bnxt *bp);
 void bnxt_ptp_reapply_pps(struct bnxt *bp);
 int bnxt_hwtstamp_set(struct net_device *dev, struct ifreq *ifr);
 int bnxt_hwtstamp_get(struct net_device *dev, struct ifreq *ifr);