Skip to content

Commit ae5c42f

Browse files
Michael Chandavem330
authored andcommitted
bnxt_en: Get PTP hardware capability from firmware
Store PTP hardware info in a structure if hardware and firmware support PTP. Reviewed-by: Edwin Peer <edwin.peer@broadcom.com> Reviewed-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 78eeadb commit ae5c42f

File tree

3 files changed

+113
-0
lines changed

3 files changed

+113
-0
lines changed

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

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
#include <linux/log2.h>
5050
#include <linux/aer.h>
5151
#include <linux/bitmap.h>
52+
#include <linux/ptp_clock_kernel.h>
53+
#include <linux/timecounter.h>
5254
#include <linux/cpu_rmap.h>
5355
#include <linux/cpumask.h>
5456
#include <net/pkt_cls.h>
@@ -63,6 +65,7 @@
6365
#include "bnxt_ethtool.h"
6466
#include "bnxt_dcb.h"
6567
#include "bnxt_xdp.h"
68+
#include "bnxt_ptp.h"
6669
#include "bnxt_vfr.h"
6770
#include "bnxt_tc.h"
6871
#include "bnxt_devlink.h"
@@ -7391,6 +7394,56 @@ int bnxt_hwrm_func_resc_qcaps(struct bnxt *bp, bool all)
73917394
return rc;
73927395
}
73937396

7397+
/* bp->hwrm_cmd_lock already held. */
7398+
static int __bnxt_hwrm_ptp_qcfg(struct bnxt *bp)
7399+
{
7400+
struct hwrm_port_mac_ptp_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
7401+
struct hwrm_port_mac_ptp_qcfg_input req = {0};
7402+
struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
7403+
u8 flags;
7404+
int rc;
7405+
7406+
if (bp->hwrm_spec_code < 0x10801) {
7407+
rc = -ENODEV;
7408+
goto no_ptp;
7409+
}
7410+
7411+
req.port_id = cpu_to_le16(bp->pf.port_id);
7412+
bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_MAC_PTP_QCFG, -1, -1);
7413+
rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
7414+
if (rc)
7415+
goto no_ptp;
7416+
7417+
flags = resp->flags;
7418+
if (!(flags & PORT_MAC_PTP_QCFG_RESP_FLAGS_HWRM_ACCESS)) {
7419+
rc = -ENODEV;
7420+
goto no_ptp;
7421+
}
7422+
if (!ptp) {
7423+
ptp = kzalloc(sizeof(*ptp), GFP_KERNEL);
7424+
if (!ptp)
7425+
return -ENOMEM;
7426+
ptp->bp = bp;
7427+
bp->ptp_cfg = ptp;
7428+
}
7429+
if (flags & PORT_MAC_PTP_QCFG_RESP_FLAGS_PARTIAL_DIRECT_ACCESS_REF_CLOCK) {
7430+
ptp->refclk_regs[0] = le32_to_cpu(resp->ts_ref_clock_reg_lower);
7431+
ptp->refclk_regs[1] = le32_to_cpu(resp->ts_ref_clock_reg_upper);
7432+
} else if (bp->flags & BNXT_FLAG_CHIP_P5) {
7433+
ptp->refclk_regs[0] = BNXT_TS_REG_TIMESYNC_TS0_LOWER;
7434+
ptp->refclk_regs[1] = BNXT_TS_REG_TIMESYNC_TS0_UPPER;
7435+
} else {
7436+
rc = -ENODEV;
7437+
goto no_ptp;
7438+
}
7439+
return 0;
7440+
7441+
no_ptp:
7442+
kfree(ptp);
7443+
bp->ptp_cfg = NULL;
7444+
return rc;
7445+
}
7446+
73947447
static int __bnxt_hwrm_func_qcaps(struct bnxt *bp)
73957448
{
73967449
int rc = 0;
@@ -7462,6 +7515,8 @@ static int __bnxt_hwrm_func_qcaps(struct bnxt *bp)
74627515
bp->flags &= ~BNXT_FLAG_WOL_CAP;
74637516
if (flags & FUNC_QCAPS_RESP_FLAGS_WOL_MAGICPKT_SUPPORTED)
74647517
bp->flags |= BNXT_FLAG_WOL_CAP;
7518+
if (flags & FUNC_QCAPS_RESP_FLAGS_PTP_SUPPORTED)
7519+
__bnxt_hwrm_ptp_qcfg(bp);
74657520
} else {
74667521
#ifdef CONFIG_BNXT_SRIOV
74677522
struct bnxt_vf_info *vf = &bp->vf;
@@ -12571,6 +12626,8 @@ static void bnxt_remove_one(struct pci_dev *pdev)
1257112626
bnxt_dcb_free(bp);
1257212627
kfree(bp->edev);
1257312628
bp->edev = NULL;
12629+
kfree(bp->ptp_cfg);
12630+
bp->ptp_cfg = NULL;
1257412631
kfree(bp->fw_health);
1257512632
bp->fw_health = NULL;
1257612633
bnxt_cleanup_pci(bp);
@@ -13161,6 +13218,8 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1316113218
bnxt_free_hwrm_short_cmd_req(bp);
1316213219
bnxt_free_hwrm_resources(bp);
1316313220
bnxt_ethtool_free(bp);
13221+
kfree(bp->ptp_cfg);
13222+
bp->ptp_cfg = NULL;
1316413223
kfree(bp->fw_health);
1316513224
bp->fw_health = NULL;
1316613225
bnxt_cleanup_pci(bp);

drivers/net/ethernet/broadcom/bnxt/bnxt.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,6 +1362,9 @@ struct bnxt_test_info {
13621362
#define BNXT_GRC_REG_CHIP_NUM 0x48
13631363
#define BNXT_GRC_REG_BASE 0x260000
13641364

1365+
#define BNXT_TS_REG_TIMESYNC_TS0_LOWER 0x640180c
1366+
#define BNXT_TS_REG_TIMESYNC_TS0_UPPER 0x6401810
1367+
13651368
#define BNXT_GRC_BASE_MASK 0xfffff000
13661369
#define BNXT_GRC_OFFSET_MASK 0x00000ffc
13671370

@@ -2042,6 +2045,8 @@ struct bnxt {
20422045

20432046
struct bpf_prog *xdp_prog;
20442047

2048+
struct bnxt_ptp_cfg *ptp_cfg;
2049+
20452050
/* devlink interface and vf-rep structs */
20462051
struct devlink *dl;
20472052
struct devlink_port dl_port;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* Broadcom NetXtreme-C/E network driver.
2+
*
3+
* Copyright (c) 2021 Broadcom Inc.
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation.
8+
*/
9+
10+
#ifndef BNXT_PTP_H
11+
#define BNXT_PTP_H
12+
13+
struct bnxt_ptp_cfg {
14+
struct ptp_clock_info ptp_info;
15+
struct ptp_clock *ptp_clock;
16+
struct cyclecounter cc;
17+
struct timecounter tc;
18+
/* serialize timecounter access */
19+
spinlock_t ptp_lock;
20+
struct sk_buff *tx_skb;
21+
u64 current_time;
22+
u64 old_time;
23+
unsigned long next_period;
24+
u16 tx_seqid;
25+
struct bnxt *bp;
26+
atomic_t tx_avail;
27+
#define BNXT_MAX_TX_TS 1
28+
u16 rxctl;
29+
#define BNXT_PTP_MSG_SYNC (1 << 0)
30+
#define BNXT_PTP_MSG_DELAY_REQ (1 << 1)
31+
#define BNXT_PTP_MSG_PDELAY_REQ (1 << 2)
32+
#define BNXT_PTP_MSG_PDELAY_RESP (1 << 3)
33+
#define BNXT_PTP_MSG_FOLLOW_UP (1 << 8)
34+
#define BNXT_PTP_MSG_DELAY_RESP (1 << 9)
35+
#define BNXT_PTP_MSG_PDELAY_RESP_FOLLOW_UP (1 << 10)
36+
#define BNXT_PTP_MSG_ANNOUNCE (1 << 11)
37+
#define BNXT_PTP_MSG_SIGNALING (1 << 12)
38+
#define BNXT_PTP_MSG_MANAGEMENT (1 << 13)
39+
#define BNXT_PTP_MSG_EVENTS (BNXT_PTP_MSG_SYNC | \
40+
BNXT_PTP_MSG_DELAY_REQ | \
41+
BNXT_PTP_MSG_PDELAY_REQ | \
42+
BNXT_PTP_MSG_PDELAY_RESP)
43+
u8 tx_tstamp_en:1;
44+
int rx_filter;
45+
46+
u32 refclk_regs[2];
47+
u32 refclk_mapped_regs[2];
48+
};
49+
#endif

0 commit comments

Comments
 (0)