49
49
#include <linux/log2.h>
50
50
#include <linux/aer.h>
51
51
#include <linux/bitmap.h>
52
+ #include <linux/ptp_clock_kernel.h>
53
+ #include <linux/timecounter.h>
52
54
#include <linux/cpu_rmap.h>
53
55
#include <linux/cpumask.h>
54
56
#include <net/pkt_cls.h>
63
65
#include "bnxt_ethtool.h"
64
66
#include "bnxt_dcb.h"
65
67
#include "bnxt_xdp.h"
68
+ #include "bnxt_ptp.h"
66
69
#include "bnxt_vfr.h"
67
70
#include "bnxt_tc.h"
68
71
#include "bnxt_devlink.h"
@@ -418,12 +421,25 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev)
418
421
vlan_tag_flags |= 1 << TX_BD_CFA_META_TPID_SHIFT ;
419
422
}
420
423
421
- if (unlikely (skb -> no_fcs )) {
422
- lflags |= cpu_to_le32 (TX_BD_FLAGS_NO_CRC );
423
- goto normal_tx ;
424
+ if (unlikely (skb_shinfo (skb )-> tx_flags & SKBTX_HW_TSTAMP )) {
425
+ struct bnxt_ptp_cfg * ptp = bp -> ptp_cfg ;
426
+
427
+ if (ptp && ptp -> tx_tstamp_en && !skb_is_gso (skb ) &&
428
+ atomic_dec_if_positive (& ptp -> tx_avail ) >= 0 ) {
429
+ if (!bnxt_ptp_parse (skb , & ptp -> tx_seqid )) {
430
+ lflags |= cpu_to_le32 (TX_BD_FLAGS_STAMP );
431
+ skb_shinfo (skb )-> tx_flags |= SKBTX_IN_PROGRESS ;
432
+ } else {
433
+ atomic_inc (& bp -> ptp_cfg -> tx_avail );
434
+ }
435
+ }
424
436
}
425
437
426
- if (free_size == bp -> tx_ring_size && length <= bp -> tx_push_thresh ) {
438
+ if (unlikely (skb -> no_fcs ))
439
+ lflags |= cpu_to_le32 (TX_BD_FLAGS_NO_CRC );
440
+
441
+ if (free_size == bp -> tx_ring_size && length <= bp -> tx_push_thresh &&
442
+ !lflags ) {
427
443
struct tx_push_buffer * tx_push_buf = txr -> tx_push ;
428
444
struct tx_push_bd * tx_push = & tx_push_buf -> push_bd ;
429
445
struct tx_bd_ext * tx_push1 = & tx_push -> txbd2 ;
@@ -590,6 +606,8 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev)
590
606
591
607
netdev_tx_sent_queue (txq , skb -> len );
592
608
609
+ skb_tx_timestamp (skb );
610
+
593
611
/* Sync BD data before updating doorbell */
594
612
wmb ();
595
613
@@ -619,6 +637,9 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev)
619
637
return NETDEV_TX_OK ;
620
638
621
639
tx_dma_error :
640
+ if (BNXT_TX_PTP_IS_SET (lflags ))
641
+ atomic_inc (& bp -> ptp_cfg -> tx_avail );
642
+
622
643
last_frag = i ;
623
644
624
645
/* start back at beginning and unmap skb */
@@ -653,6 +674,7 @@ static void bnxt_tx_int(struct bnxt *bp, struct bnxt_napi *bnapi, int nr_pkts)
653
674
654
675
for (i = 0 ; i < nr_pkts ; i ++ ) {
655
676
struct bnxt_sw_tx_bd * tx_buf ;
677
+ bool compl_deferred = false;
656
678
struct sk_buff * skb ;
657
679
int j , last ;
658
680
@@ -679,12 +701,21 @@ static void bnxt_tx_int(struct bnxt *bp, struct bnxt_napi *bnapi, int nr_pkts)
679
701
skb_frag_size (& skb_shinfo (skb )-> frags [j ]),
680
702
PCI_DMA_TODEVICE );
681
703
}
704
+ if (unlikely (skb_shinfo (skb )-> tx_flags & SKBTX_IN_PROGRESS )) {
705
+ if (bp -> flags & BNXT_FLAG_CHIP_P5 ) {
706
+ if (!bnxt_get_tx_ts_p5 (bp , skb ))
707
+ compl_deferred = true;
708
+ else
709
+ atomic_inc (& bp -> ptp_cfg -> tx_avail );
710
+ }
711
+ }
682
712
683
713
next_tx_int :
684
714
cons = NEXT_TX (cons );
685
715
686
716
tx_bytes += skb -> len ;
687
- dev_kfree_skb_any (skb );
717
+ if (!compl_deferred )
718
+ dev_kfree_skb_any (skb );
688
719
}
689
720
690
721
netdev_tx_completed_queue (txq , nr_pkts , tx_bytes );
@@ -1706,9 +1737,9 @@ static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
1706
1737
u8 * data_ptr , agg_bufs , cmp_type ;
1707
1738
dma_addr_t dma_addr ;
1708
1739
struct sk_buff * skb ;
1740
+ u32 flags , misc ;
1709
1741
void * data ;
1710
1742
int rc = 0 ;
1711
- u32 misc ;
1712
1743
1713
1744
rxcmp = (struct rx_cmp * )
1714
1745
& cpr -> cp_desc_ring [CP_RING (cp_cons )][CP_IDX (cp_cons )];
@@ -1806,7 +1837,8 @@ static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
1806
1837
goto next_rx_no_len ;
1807
1838
}
1808
1839
1809
- len = le32_to_cpu (rxcmp -> rx_cmp_len_flags_type ) >> RX_CMP_LEN_SHIFT ;
1840
+ flags = le32_to_cpu (rxcmp -> rx_cmp_len_flags_type );
1841
+ len = flags >> RX_CMP_LEN_SHIFT ;
1810
1842
dma_addr = rx_buf -> mapping ;
1811
1843
1812
1844
if (bnxt_rx_xdp (bp , rxr , cons , data , & data_ptr , & len , event )) {
@@ -1883,6 +1915,24 @@ static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
1883
1915
}
1884
1916
}
1885
1917
1918
+ if (unlikely ((flags & RX_CMP_FLAGS_ITYPES_MASK ) ==
1919
+ RX_CMP_FLAGS_ITYPE_PTP_W_TS )) {
1920
+ if (bp -> flags & BNXT_FLAG_CHIP_P5 ) {
1921
+ u32 cmpl_ts = le32_to_cpu (rxcmp1 -> rx_cmp_timestamp );
1922
+ u64 ns , ts ;
1923
+
1924
+ if (!bnxt_get_rx_ts_p5 (bp , & ts , cmpl_ts )) {
1925
+ struct bnxt_ptp_cfg * ptp = bp -> ptp_cfg ;
1926
+
1927
+ spin_lock_bh (& ptp -> ptp_lock );
1928
+ ns = timecounter_cyc2time (& ptp -> tc , ts );
1929
+ spin_unlock_bh (& ptp -> ptp_lock );
1930
+ memset (skb_hwtstamps (skb ), 0 ,
1931
+ sizeof (* skb_hwtstamps (skb )));
1932
+ skb_hwtstamps (skb )-> hwtstamp = ns_to_ktime (ns );
1933
+ }
1934
+ }
1935
+ }
1886
1936
bnxt_deliver_skb (bp , bnapi , skb );
1887
1937
rc = 1 ;
1888
1938
@@ -7391,6 +7441,56 @@ int bnxt_hwrm_func_resc_qcaps(struct bnxt *bp, bool all)
7391
7441
return rc ;
7392
7442
}
7393
7443
7444
+ /* bp->hwrm_cmd_lock already held. */
7445
+ static int __bnxt_hwrm_ptp_qcfg (struct bnxt * bp )
7446
+ {
7447
+ struct hwrm_port_mac_ptp_qcfg_output * resp = bp -> hwrm_cmd_resp_addr ;
7448
+ struct hwrm_port_mac_ptp_qcfg_input req = {0 };
7449
+ struct bnxt_ptp_cfg * ptp = bp -> ptp_cfg ;
7450
+ u8 flags ;
7451
+ int rc ;
7452
+
7453
+ if (bp -> hwrm_spec_code < 0x10801 ) {
7454
+ rc = - ENODEV ;
7455
+ goto no_ptp ;
7456
+ }
7457
+
7458
+ req .port_id = cpu_to_le16 (bp -> pf .port_id );
7459
+ bnxt_hwrm_cmd_hdr_init (bp , & req , HWRM_PORT_MAC_PTP_QCFG , -1 , -1 );
7460
+ rc = _hwrm_send_message (bp , & req , sizeof (req ), HWRM_CMD_TIMEOUT );
7461
+ if (rc )
7462
+ goto no_ptp ;
7463
+
7464
+ flags = resp -> flags ;
7465
+ if (!(flags & PORT_MAC_PTP_QCFG_RESP_FLAGS_HWRM_ACCESS )) {
7466
+ rc = - ENODEV ;
7467
+ goto no_ptp ;
7468
+ }
7469
+ if (!ptp ) {
7470
+ ptp = kzalloc (sizeof (* ptp ), GFP_KERNEL );
7471
+ if (!ptp )
7472
+ return - ENOMEM ;
7473
+ ptp -> bp = bp ;
7474
+ bp -> ptp_cfg = ptp ;
7475
+ }
7476
+ if (flags & PORT_MAC_PTP_QCFG_RESP_FLAGS_PARTIAL_DIRECT_ACCESS_REF_CLOCK ) {
7477
+ ptp -> refclk_regs [0 ] = le32_to_cpu (resp -> ts_ref_clock_reg_lower );
7478
+ ptp -> refclk_regs [1 ] = le32_to_cpu (resp -> ts_ref_clock_reg_upper );
7479
+ } else if (bp -> flags & BNXT_FLAG_CHIP_P5 ) {
7480
+ ptp -> refclk_regs [0 ] = BNXT_TS_REG_TIMESYNC_TS0_LOWER ;
7481
+ ptp -> refclk_regs [1 ] = BNXT_TS_REG_TIMESYNC_TS0_UPPER ;
7482
+ } else {
7483
+ rc = - ENODEV ;
7484
+ goto no_ptp ;
7485
+ }
7486
+ return 0 ;
7487
+
7488
+ no_ptp :
7489
+ kfree (ptp );
7490
+ bp -> ptp_cfg = NULL ;
7491
+ return rc ;
7492
+ }
7493
+
7394
7494
static int __bnxt_hwrm_func_qcaps (struct bnxt * bp )
7395
7495
{
7396
7496
int rc = 0 ;
@@ -7462,6 +7562,8 @@ static int __bnxt_hwrm_func_qcaps(struct bnxt *bp)
7462
7562
bp -> flags &= ~BNXT_FLAG_WOL_CAP ;
7463
7563
if (flags & FUNC_QCAPS_RESP_FLAGS_WOL_MAGICPKT_SUPPORTED )
7464
7564
bp -> flags |= BNXT_FLAG_WOL_CAP ;
7565
+ if (flags & FUNC_QCAPS_RESP_FLAGS_PTP_SUPPORTED )
7566
+ __bnxt_hwrm_ptp_qcfg (bp );
7465
7567
} else {
7466
7568
#ifdef CONFIG_BNXT_SRIOV
7467
7569
struct bnxt_vf_info * vf = & bp -> vf ;
@@ -10020,6 +10122,7 @@ static int __bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
10020
10122
}
10021
10123
}
10022
10124
10125
+ bnxt_ptp_start (bp );
10023
10126
rc = bnxt_init_nic (bp , irq_re_init );
10024
10127
if (rc ) {
10025
10128
netdev_err (bp -> dev , "bnxt_init_nic err: %x\n" , rc );
@@ -10335,6 +10438,12 @@ static int bnxt_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
10335
10438
return bnxt_hwrm_port_phy_write (bp , mdio -> phy_id , mdio -> reg_num ,
10336
10439
mdio -> val_in );
10337
10440
10441
+ case SIOCSHWTSTAMP :
10442
+ return bnxt_hwtstamp_set (dev , ifr );
10443
+
10444
+ case SIOCGHWTSTAMP :
10445
+ return bnxt_hwtstamp_get (dev , ifr );
10446
+
10338
10447
default :
10339
10448
/* do nothing */
10340
10449
break ;
@@ -12551,6 +12660,8 @@ static void bnxt_remove_one(struct pci_dev *pdev)
12551
12660
12552
12661
if (BNXT_PF (bp ))
12553
12662
devlink_port_type_clear (& bp -> dl_port );
12663
+
12664
+ bnxt_ptp_clear (bp );
12554
12665
pci_disable_pcie_error_reporting (pdev );
12555
12666
unregister_netdev (dev );
12556
12667
clear_bit (BNXT_STATE_IN_FW_RESET , & bp -> state );
@@ -12571,6 +12682,8 @@ static void bnxt_remove_one(struct pci_dev *pdev)
12571
12682
bnxt_dcb_free (bp );
12572
12683
kfree (bp -> edev );
12573
12684
bp -> edev = NULL ;
12685
+ kfree (bp -> ptp_cfg );
12686
+ bp -> ptp_cfg = NULL ;
12574
12687
kfree (bp -> fw_health );
12575
12688
bp -> fw_health = NULL ;
12576
12689
bnxt_cleanup_pci (bp );
@@ -13132,6 +13245,11 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
13132
13245
rc );
13133
13246
}
13134
13247
13248
+ if (bnxt_ptp_init (bp )) {
13249
+ netdev_warn (dev , "PTP initialization failed.\n" );
13250
+ kfree (bp -> ptp_cfg );
13251
+ bp -> ptp_cfg = NULL ;
13252
+ }
13135
13253
bnxt_inv_fw_health_reg (bp );
13136
13254
bnxt_dl_register (bp );
13137
13255
@@ -13161,6 +13279,8 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
13161
13279
bnxt_free_hwrm_short_cmd_req (bp );
13162
13280
bnxt_free_hwrm_resources (bp );
13163
13281
bnxt_ethtool_free (bp );
13282
+ kfree (bp -> ptp_cfg );
13283
+ bp -> ptp_cfg = NULL ;
13164
13284
kfree (bp -> fw_health );
13165
13285
bp -> fw_health = NULL ;
13166
13286
bnxt_cleanup_pci (bp );
0 commit comments