Skip to content

Commit caf3eed

Browse files
pavanchebbidavem330
authored andcommitted
bnxt_en: 1PPS support for 5750X family chips
1PPS (One Pulse Per Second) is a signal generated either by the NIC PHC or an external timing source. Integrating the support to configure and use 1PPS using the TSIO pins along with PTP timestamps will add Grand Master capability to the 5750X family chipsets. This patch initializes the driver data structures and registers the 1PPS with kernel, based on the TSIO pins' capability in the hardware. This will create a /dev/ppsX device which applications can use to receive PPS events. Later patches will define functions to configure and use the pins. 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 30e96f4 commit caf3eed

File tree

4 files changed

+113
-1
lines changed

4 files changed

+113
-1
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7545,6 +7545,8 @@ static int __bnxt_hwrm_func_qcaps(struct bnxt *bp)
75457545
flags_ext = le32_to_cpu(resp->flags_ext);
75467546
if (flags_ext & FUNC_QCAPS_RESP_FLAGS_EXT_EXT_HW_STATS_SUPPORTED)
75477547
bp->fw_cap |= BNXT_FW_CAP_EXT_HW_STATS_SUPPORTED;
7548+
if (BNXT_PF(bp) && (flags_ext & FUNC_QCAPS_RESP_FLAGS_EXT_PTP_PPS_SUPPORTED))
7549+
bp->fw_cap |= BNXT_FW_CAP_PTP_PPS;
75487550

75497551
bp->tx_push_thresh = 0;
75507552
if ((flags & FUNC_QCAPS_RESP_FLAGS_PUSH_MODE_SUPPORTED) &&

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,6 +1887,7 @@ struct bnxt {
18871887
#define BNXT_FW_CAP_VLAN_RX_STRIP 0x01000000
18881888
#define BNXT_FW_CAP_VLAN_TX_INSERT 0x02000000
18891889
#define BNXT_FW_CAP_EXT_HW_STATS_SUPPORTED 0x04000000
1890+
#define BNXT_FW_CAP_PTP_PPS 0x10000000
18901891
#define BNXT_FW_CAP_RING_MONITOR 0x40000000
18911892

18921893
#define BNXT_NEW_RM(bp) ((bp)->fw_cap & BNXT_FW_CAP_NEW_RM)

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

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,80 @@ static const struct ptp_clock_info bnxt_ptp_caps = {
412412
.enable = bnxt_ptp_enable,
413413
};
414414

415+
static int bnxt_ptp_verify(struct ptp_clock_info *ptp_info, unsigned int pin,
416+
enum ptp_pin_function func, unsigned int chan)
417+
{
418+
struct bnxt_ptp_cfg *ptp = container_of(ptp_info, struct bnxt_ptp_cfg,
419+
ptp_info);
420+
/* Allow only PPS pin function configuration */
421+
if (ptp->pps_info.pins[pin].usage <= BNXT_PPS_PIN_PPS_OUT &&
422+
func != PTP_PF_PHYSYNC)
423+
return 0;
424+
else
425+
return -EOPNOTSUPP;
426+
}
427+
428+
/* bp->hwrm_cmd_lock held by the caller */
429+
static int bnxt_ptp_pps_init(struct bnxt *bp)
430+
{
431+
struct hwrm_func_ptp_pin_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
432+
struct hwrm_func_ptp_pin_qcfg_input req = {0};
433+
struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
434+
struct ptp_clock_info *ptp_info;
435+
struct bnxt_pps *pps_info;
436+
u8 *pin_usg;
437+
u32 i, rc;
438+
439+
/* Query current/default PIN CFG */
440+
bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_PTP_PIN_QCFG, -1, -1);
441+
442+
rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
443+
if (rc || !resp->num_pins)
444+
return -EOPNOTSUPP;
445+
446+
ptp_info = &ptp->ptp_info;
447+
pps_info = &ptp->pps_info;
448+
pps_info->num_pins = resp->num_pins;
449+
ptp_info->n_pins = pps_info->num_pins;
450+
ptp_info->pin_config = kcalloc(ptp_info->n_pins,
451+
sizeof(*ptp_info->pin_config),
452+
GFP_KERNEL);
453+
if (!ptp_info->pin_config)
454+
return -ENOMEM;
455+
456+
/* Report the TSIO capability to kernel */
457+
pin_usg = &resp->pin0_usage;
458+
for (i = 0; i < pps_info->num_pins; i++, pin_usg++) {
459+
snprintf(ptp_info->pin_config[i].name,
460+
sizeof(ptp_info->pin_config[i].name), "bnxt_pps%d", i);
461+
ptp_info->pin_config[i].index = i;
462+
ptp_info->pin_config[i].chan = i;
463+
if (*pin_usg == BNXT_PPS_PIN_PPS_IN)
464+
ptp_info->pin_config[i].func = PTP_PF_EXTTS;
465+
else if (*pin_usg == BNXT_PPS_PIN_PPS_OUT)
466+
ptp_info->pin_config[i].func = PTP_PF_PEROUT;
467+
else
468+
ptp_info->pin_config[i].func = PTP_PF_NONE;
469+
470+
pps_info->pins[i].usage = *pin_usg;
471+
}
472+
473+
/* Only 1 each of ext_ts and per_out pins is available in HW */
474+
ptp_info->n_ext_ts = 1;
475+
ptp_info->n_per_out = 1;
476+
ptp_info->pps = 1;
477+
ptp_info->verify = bnxt_ptp_verify;
478+
479+
return 0;
480+
}
481+
482+
static bool bnxt_pps_config_ok(struct bnxt *bp)
483+
{
484+
struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
485+
486+
return !(bp->fw_cap & BNXT_FW_CAP_PTP_PPS) == !ptp->ptp_info.pin_config;
487+
}
488+
415489
int bnxt_ptp_init(struct bnxt *bp)
416490
{
417491
struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
@@ -424,9 +498,15 @@ int bnxt_ptp_init(struct bnxt *bp)
424498
if (rc)
425499
return rc;
426500

427-
if (ptp->ptp_clock)
501+
if (ptp->ptp_clock && bnxt_pps_config_ok(bp))
428502
return 0;
429503

504+
if (ptp->ptp_clock) {
505+
ptp_clock_unregister(ptp->ptp_clock);
506+
ptp->ptp_clock = NULL;
507+
kfree(ptp->ptp_info.pin_config);
508+
ptp->ptp_info.pin_config = NULL;
509+
}
430510
atomic_set(&ptp->tx_avail, BNXT_MAX_TX_TS);
431511
spin_lock_init(&ptp->ptp_lock);
432512

@@ -439,6 +519,10 @@ int bnxt_ptp_init(struct bnxt *bp)
439519
timecounter_init(&ptp->tc, &ptp->cc, ktime_to_ns(ktime_get_real()));
440520

441521
ptp->ptp_info = bnxt_ptp_caps;
522+
if ((bp->fw_cap & BNXT_FW_CAP_PTP_PPS)) {
523+
if (bnxt_ptp_pps_init(bp))
524+
netdev_err(bp->dev, "1pps not initialized, continuing without 1pps support\n");
525+
}
442526
ptp->ptp_clock = ptp_clock_register(&ptp->ptp_info, &bp->pdev->dev);
443527
if (IS_ERR(ptp->ptp_clock)) {
444528
int err = PTR_ERR(ptp->ptp_clock);
@@ -468,6 +552,9 @@ void bnxt_ptp_clear(struct bnxt *bp)
468552
ptp_clock_unregister(ptp->ptp_clock);
469553

470554
ptp->ptp_clock = NULL;
555+
kfree(ptp->ptp_info.pin_config);
556+
ptp->ptp_info.pin_config = NULL;
557+
471558
if (ptp->tx_skb) {
472559
dev_kfree_skb_any(ptp->tx_skb);
473560
ptp->tx_skb = NULL;

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,33 @@
2121
#define BNXT_PTP_QTS_TX_ENABLES (PORT_TS_QUERY_REQ_ENABLES_PTP_SEQ_ID | \
2222
PORT_TS_QUERY_REQ_ENABLES_TS_REQ_TIMEOUT)
2323

24+
struct pps_pin {
25+
u8 usage;
26+
};
27+
28+
#define BNXT_PPS_PIN_DISABLE 0
29+
#define BNXT_PPS_PIN_ENABLE 1
30+
#define BNXT_PPS_PIN_NONE 0
31+
#define BNXT_PPS_PIN_PPS_IN 1
32+
#define BNXT_PPS_PIN_PPS_OUT 2
33+
#define BNXT_PPS_PIN_SYNC_IN 3
34+
#define BNXT_PPS_PIN_SYNC_OUT 4
35+
36+
#define BNXT_PPS_EVENT_INTERNAL 1
37+
#define BNXT_PPS_EVENT_EXTERNAL 2
38+
39+
struct bnxt_pps {
40+
u8 num_pins;
41+
#define BNXT_MAX_TSIO_PINS 4
42+
struct pps_pin pins[BNXT_MAX_TSIO_PINS];
43+
};
44+
2445
struct bnxt_ptp_cfg {
2546
struct ptp_clock_info ptp_info;
2647
struct ptp_clock *ptp_clock;
2748
struct cyclecounter cc;
2849
struct timecounter tc;
50+
struct bnxt_pps pps_info;
2951
/* serialize timecounter access */
3052
spinlock_t ptp_lock;
3153
struct sk_buff *tx_skb;

0 commit comments

Comments
 (0)