Skip to content

Commit 118612d

Browse files
Michael Chandavem330
authored andcommitted
bnxt_en: Add PTP clock APIs, ioctls, and ethtool methods
Add the clock APIs to set/get/adjust the hw clock, and the related ioctls and ethtool methods. v2: Propagate error code from ptp_clock_register(). Add spinlock to serialize access to the timecounter. The timecounter is accessed in process context and the RX datapath. Read the PHC using direct registers. Reviewed-by: Edwin Peer <edwin.peer@broadcom.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>
1 parent ae5c42f commit 118612d

File tree

6 files changed

+382
-1
lines changed

6 files changed

+382
-1
lines changed

drivers/net/ethernet/broadcom/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ config SYSTEMPORT
206206
config BNXT
207207
tristate "Broadcom NetXtreme-C/E support"
208208
depends on PCI
209+
imply PTP_1588_CLOCK
209210
select FW_LOADER
210211
select LIBCRC32C
211212
select NET_DEVLINK
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SPDX-License-Identifier: GPL-2.0-only
22
obj-$(CONFIG_BNXT) += bnxt_en.o
33

4-
bnxt_en-y := bnxt.o bnxt_sriov.o bnxt_ethtool.o bnxt_dcb.o bnxt_ulp.o bnxt_xdp.o bnxt_vfr.o bnxt_devlink.o bnxt_dim.o
4+
bnxt_en-y := bnxt.o bnxt_sriov.o bnxt_ethtool.o bnxt_dcb.o bnxt_ulp.o bnxt_xdp.o bnxt_ptp.o bnxt_vfr.o bnxt_devlink.o bnxt_dim.o
55
bnxt_en-$(CONFIG_BNXT_FLOWER_OFFLOAD) += bnxt_tc.o
66
bnxt_en-$(CONFIG_DEBUG_FS) += bnxt_debugfs.o

drivers/net/ethernet/broadcom/bnxt/bnxt.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10390,6 +10390,12 @@ static int bnxt_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
1039010390
return bnxt_hwrm_port_phy_write(bp, mdio->phy_id, mdio->reg_num,
1039110391
mdio->val_in);
1039210392

10393+
case SIOCSHWTSTAMP:
10394+
return bnxt_hwtstamp_set(dev, ifr);
10395+
10396+
case SIOCGHWTSTAMP:
10397+
return bnxt_hwtstamp_get(dev, ifr);
10398+
1039310399
default:
1039410400
/* do nothing */
1039510401
break;

drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@
1919
#include <linux/firmware.h>
2020
#include <linux/utsname.h>
2121
#include <linux/time.h>
22+
#include <linux/ptp_clock_kernel.h>
23+
#include <linux/net_tstamp.h>
24+
#include <linux/timecounter.h>
2225
#include "bnxt_hsi.h"
2326
#include "bnxt.h"
2427
#include "bnxt_xdp.h"
28+
#include "bnxt_ptp.h"
2529
#include "bnxt_ethtool.h"
2630
#include "bnxt_nvm_defs.h" /* NVRAM content constant and structure defs */
2731
#include "bnxt_fw_hdr.h" /* Firmware hdr constant and structure defs */
@@ -3926,6 +3930,35 @@ static int bnxt_get_dump_data(struct net_device *dev, struct ethtool_dump *dump,
39263930
return 0;
39273931
}
39283932

3933+
static int bnxt_get_ts_info(struct net_device *dev,
3934+
struct ethtool_ts_info *info)
3935+
{
3936+
struct bnxt *bp = netdev_priv(dev);
3937+
struct bnxt_ptp_cfg *ptp;
3938+
3939+
ptp = bp->ptp_cfg;
3940+
info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
3941+
SOF_TIMESTAMPING_RX_SOFTWARE |
3942+
SOF_TIMESTAMPING_SOFTWARE;
3943+
3944+
info->phc_index = -1;
3945+
if (!ptp)
3946+
return 0;
3947+
3948+
info->so_timestamping |= SOF_TIMESTAMPING_TX_HARDWARE |
3949+
SOF_TIMESTAMPING_RX_HARDWARE |
3950+
SOF_TIMESTAMPING_RAW_HARDWARE;
3951+
if (ptp->ptp_clock)
3952+
info->phc_index = ptp_clock_index(ptp->ptp_clock);
3953+
3954+
info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
3955+
3956+
info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
3957+
(1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
3958+
(1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT);
3959+
return 0;
3960+
}
3961+
39293962
void bnxt_ethtool_init(struct bnxt *bp)
39303963
{
39313964
struct hwrm_selftest_qlist_output *resp = bp->hwrm_cmd_resp_addr;
@@ -4172,6 +4205,7 @@ const struct ethtool_ops bnxt_ethtool_ops = {
41724205
.nway_reset = bnxt_nway_reset,
41734206
.set_phys_id = bnxt_set_phys_id,
41744207
.self_test = bnxt_self_test,
4208+
.get_ts_info = bnxt_get_ts_info,
41754209
.reset = bnxt_reset,
41764210
.set_dump = bnxt_set_dump,
41774211
.get_dump_flag = bnxt_get_dump_flag,

0 commit comments

Comments
 (0)