Skip to content

Commit

Permalink
Merge branch 'mlxsw-Spectrum-2-PTP-preparations'
Browse files Browse the repository at this point in the history
Ido Schimmel says:

====================
mlxsw: Spectrum-2 PTP preparations

This patchset includes various preparations required for Spectrum-2 PTP
support.

Most of the changes are non-functional (e.g., renaming, adding
registers). The only intentional user visible change is in patch #10
where the PHC time is initialized to zero in accordance with the
recommendation of the PTP maintainer.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Jul 25, 2022
2 parents e222dc8 + a168e13 commit 360f9f3
Show file tree
Hide file tree
Showing 8 changed files with 344 additions and 77 deletions.
52 changes: 52 additions & 0 deletions drivers/net/ethernet/mellanox/mlxsw/cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,32 @@ MLXSW_ITEM64(cmd_mbox, query_fw, free_running_clock_offset, 0x50, 0, 64);
*/
MLXSW_ITEM32(cmd_mbox, query_fw, fr_rn_clk_bar, 0x58, 30, 2);

/* cmd_mbox_query_fw_utc_sec_offset
* The offset of the UTC_Sec page
*/
MLXSW_ITEM64(cmd_mbox, query_fw, utc_sec_offset, 0x70, 0, 64);

/* cmd_mbox_query_fw_utc_sec_bar
* PCI base address register (BAR) of the UTC_Sec page
* 0: BAR 0
* 1: 64 bit BAR
* Reserved on SwitchX/-2, Switch-IB/2, Spectrum-1
*/
MLXSW_ITEM32(cmd_mbox, query_fw, utc_sec_bar, 0x78, 30, 2);

/* cmd_mbox_query_fw_utc_nsec_offset
* The offset of the UTC_nSec page
*/
MLXSW_ITEM64(cmd_mbox, query_fw, utc_nsec_offset, 0x80, 0, 64);

/* cmd_mbox_query_fw_utc_nsec_bar
* PCI base address register (BAR) of the UTC_nSec page
* 0: BAR 0
* 1: 64 bit BAR
* Reserved on SwitchX/-2, Switch-IB/2, Spectrum-1
*/
MLXSW_ITEM32(cmd_mbox, query_fw, utc_nsec_bar, 0x88, 30, 2);

/* QUERY_BOARDINFO - Query Board Information
* -----------------------------------------
* OpMod == 0 (N/A), INMmod == 0 (N/A)
Expand Down Expand Up @@ -663,6 +689,12 @@ MLXSW_ITEM32(cmd_mbox, config_profile, set_kvd_hash_double_size, 0x0C, 26, 1);
*/
MLXSW_ITEM32(cmd_mbox, config_profile, set_cqe_version, 0x08, 0, 1);

/* cmd_mbox_config_set_cqe_time_stamp_type
* Capability bit. Setting a bit to 1 configures the profile
* according to the mailbox contents.
*/
MLXSW_ITEM32(cmd_mbox, config_profile, set_cqe_time_stamp_type, 0x08, 2, 1);

/* cmd_mbox_config_profile_max_vepa_channels
* Maximum number of VEPA channels per port (0 through 16)
* 0 - multi-channel VEPA is disabled
Expand Down Expand Up @@ -858,6 +890,26 @@ MLXSW_ITEM32_INDEXED(cmd_mbox, config_profile, swid_config_type,
MLXSW_ITEM32_INDEXED(cmd_mbox, config_profile, swid_config_properties,
0x60, 0, 8, 0x08, 0x00, false);

enum mlxsw_cmd_mbox_config_profile_cqe_time_stamp_type {
/* uSec - 1.024uSec (default). Only bits 15:0 are valid. */
MLXSW_CMD_MBOX_CONFIG_PROFILE_CQE_TIME_STAMP_TYPE_USEC,
/* FRC - Free Running Clock, units of 1nSec.
* Reserved when SwitchX/-2, Switch-IB/2 and Spectrum-1.
*/
MLXSW_CMD_MBOX_CONFIG_PROFILE_CQE_TIME_STAMP_TYPE_FRC,
/* UTC. time_stamp[37:30] = Sec, time_stamp[29:0] = nSec.
* Reserved when SwitchX/2, Switch-IB/2 and Spectrum-1.
*/
MLXSW_CMD_MBOX_CONFIG_PROFILE_CQE_TIME_STAMP_TYPE_UTC,
};

/* cmd_mbox_config_profile_cqe_time_stamp_type
* CQE time_stamp_type for non-mirror-packets.
* Configured if set_cqe_time_stamp_type is set.
* Reserved when SwitchX/-2, Switch-IB/2 and Spectrum-1.
*/
MLXSW_ITEM32(cmd_mbox, config_profile, cqe_time_stamp_type, 0xB0, 8, 2);

/* cmd_mbox_config_profile_cqe_version
* CQE version:
* 0: CQE version is 0
Expand Down
6 changes: 4 additions & 2 deletions drivers/net/ethernet/mellanox/mlxsw/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ struct mlxsw_config_profile {
used_ar_sec:1,
used_adaptive_routing_group_cap:1,
used_ubridge:1,
used_kvd_sizes:1;
used_kvd_sizes:1,
used_cqe_time_stamp_type:1;
u8 max_vepa_channels;
u16 max_mid;
u16 max_pgt;
Expand All @@ -319,6 +320,7 @@ struct mlxsw_config_profile {
u32 kvd_linear_size;
u8 kvd_hash_single_parts;
u8 kvd_hash_double_parts;
u8 cqe_time_stamp_type;
struct mlxsw_swid_config swid_config[MLXSW_CONFIG_PROFILE_SWID_COUNT];
};

Expand Down Expand Up @@ -485,7 +487,7 @@ struct mlxsw_bus_info {
u8 vsd[MLXSW_CMD_BOARDINFO_VSD_LEN];
u8 psid[MLXSW_CMD_BOARDINFO_PSID_LEN];
u8 low_frequency:1,
read_frc_capable:1;
read_clock_capable:1;
};

struct mlxsw_hwmon;
Expand Down
27 changes: 20 additions & 7 deletions drivers/net/ethernet/mellanox/mlxsw/pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,12 @@ static void mlxsw_pci_cq_fini(struct mlxsw_pci *mlxsw_pci,
mlxsw_cmd_hw2sw_cq(mlxsw_pci->core, q->num);
}

static unsigned int mlxsw_pci_read32_off(struct mlxsw_pci *mlxsw_pci,
ptrdiff_t off)
{
return ioread32be(mlxsw_pci->hw_addr + off);
}

static void mlxsw_pci_cqe_sdq_handle(struct mlxsw_pci *mlxsw_pci,
struct mlxsw_pci_queue *q,
u16 consumer_counter_limit,
Expand Down Expand Up @@ -1267,6 +1273,13 @@ static int mlxsw_pci_config_profile(struct mlxsw_pci *mlxsw_pci, char *mbox,
mlxsw_cmd_mbox_config_profile_cqe_version_set(mbox, 1);
}

if (profile->used_cqe_time_stamp_type) {
mlxsw_cmd_mbox_config_profile_set_cqe_time_stamp_type_set(mbox,
1);
mlxsw_cmd_mbox_config_profile_cqe_time_stamp_type_set(mbox,
profile->cqe_time_stamp_type);
}

return mlxsw_cmd_config_profile_set(mlxsw_pci->core, mbox);
}

Expand Down Expand Up @@ -1802,19 +1815,19 @@ static int mlxsw_pci_cmd_exec(void *bus_priv, u16 opcode, u8 opcode_mod,
static u32 mlxsw_pci_read_frc_h(void *bus_priv)
{
struct mlxsw_pci *mlxsw_pci = bus_priv;
u64 frc_offset;
u64 frc_offset_h;

frc_offset = mlxsw_pci->free_running_clock_offset;
return mlxsw_pci_read32(mlxsw_pci, FREE_RUNNING_CLOCK_H(frc_offset));
frc_offset_h = mlxsw_pci->free_running_clock_offset;
return mlxsw_pci_read32_off(mlxsw_pci, frc_offset_h);
}

static u32 mlxsw_pci_read_frc_l(void *bus_priv)
{
struct mlxsw_pci *mlxsw_pci = bus_priv;
u64 frc_offset;
u64 frc_offset_l;

frc_offset = mlxsw_pci->free_running_clock_offset;
return mlxsw_pci_read32(mlxsw_pci, FREE_RUNNING_CLOCK_L(frc_offset));
frc_offset_l = mlxsw_pci->free_running_clock_offset + 4;
return mlxsw_pci_read32_off(mlxsw_pci, frc_offset_l);
}

static const struct mlxsw_bus mlxsw_pci_bus = {
Expand Down Expand Up @@ -1916,7 +1929,7 @@ static int mlxsw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
mlxsw_pci->bus_info.device_kind = driver_name;
mlxsw_pci->bus_info.device_name = pci_name(mlxsw_pci->pdev);
mlxsw_pci->bus_info.dev = &pdev->dev;
mlxsw_pci->bus_info.read_frc_capable = true;
mlxsw_pci->bus_info.read_clock_capable = true;
mlxsw_pci->id = id;

err = mlxsw_core_bus_device_register(&mlxsw_pci->bus_info,
Expand Down
81 changes: 78 additions & 3 deletions drivers/net/ethernet/mellanox/mlxsw/pci_hw.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@
#define MLXSW_PCI_DOORBELL(offset, type_offset, num) \
((offset) + (type_offset) + (num) * 4)

#define MLXSW_PCI_FREE_RUNNING_CLOCK_H(offset) (offset)
#define MLXSW_PCI_FREE_RUNNING_CLOCK_L(offset) ((offset) + 4)

#define MLXSW_PCI_CQS_MAX 96
#define MLXSW_PCI_EQS_COUNT 2
#define MLXSW_PCI_EQ_ASYNC_NUM 0
Expand Down Expand Up @@ -217,6 +214,25 @@ MLXSW_ITEM32(pci, cqe0, dqn, 0x0C, 1, 5);
MLXSW_ITEM32(pci, cqe12, dqn, 0x0C, 1, 6);
mlxsw_pci_cqe_item_helpers(dqn, 0, 12, 12);

/* pci_cqe_time_stamp_low
* Time stamp of the CQE
* Format according to time_stamp_type:
* 0: uSec - 1.024uSec (default for devices which do not support
* time_stamp_type). Only bits 15:0 are valid
* 1: FRC - Free Running Clock - units of 1nSec
* 2: UTC - time_stamp[37:30] = Sec
* - time_stamp[29:0] = nSec
* 3: Mirror_UTC. UTC time stamp of the original packet that has
* MIRROR_SESSION traps
* - time_stamp[37:30] = Sec
* - time_stamp[29:0] = nSec
* Formats 0..2 are configured by
* CONFIG_PROFILE.cqe_time_stamp_type for PTP traps
* Format 3 is used for MIRROR_SESSION traps
* Note that Spectrum does not reveal FRC, UTC and Mirror_UTC
*/
MLXSW_ITEM32(pci, cqe2, time_stamp_low, 0x0C, 16, 16);

#define MLXSW_PCI_CQE2_MIRROR_TCLASS_INVALID 0x1F

/* pci_cqe_mirror_tclass
Expand Down Expand Up @@ -280,8 +296,67 @@ MLXSW_ITEM32(pci, cqe2, user_def_val_orig_pkt_len, 0x14, 0, 20);
*/
MLXSW_ITEM32(pci, cqe2, mirror_reason, 0x18, 24, 8);

enum mlxsw_pci_cqe_time_stamp_type {
MLXSW_PCI_CQE_TIME_STAMP_TYPE_USEC,
MLXSW_PCI_CQE_TIME_STAMP_TYPE_FRC,
MLXSW_PCI_CQE_TIME_STAMP_TYPE_UTC,
MLXSW_PCI_CQE_TIME_STAMP_TYPE_MIRROR_UTC,
};

/* pci_cqe_time_stamp_type
* Time stamp type:
* 0: uSec - 1.024uSec (default for devices which do not support
* time_stamp_type)
* 1: FRC - Free Running Clock - units of 1nSec
* 2: UTC
* 3: Mirror_UTC. UTC time stamp of the original packet that has
* MIRROR_SESSION traps
*/
MLXSW_ITEM32(pci, cqe2, time_stamp_type, 0x18, 22, 2);

#define MLXSW_PCI_CQE2_MIRROR_LATENCY_INVALID 0xFFFFFF

/* pci_cqe_time_stamp_high
* Time stamp of the CQE
* Format according to time_stamp_type:
* 0: uSec - 1.024uSec (default for devices which do not support
* time_stamp_type). Only bits 15:0 are valid
* 1: FRC - Free Running Clock - units of 1nSec
* 2: UTC - time_stamp[37:30] = Sec
* - time_stamp[29:0] = nSec
* 3: Mirror_UTC. UTC time stamp of the original packet that has
* MIRROR_SESSION traps
* - time_stamp[37:30] = Sec
* - time_stamp[29:0] = nSec
* Formats 0..2 are configured by
* CONFIG_PROFILE.cqe_time_stamp_type for PTP traps
* Format 3 is used for MIRROR_SESSION traps
* Note that Spectrum does not reveal FRC, UTC and Mirror_UTC
*/
MLXSW_ITEM32(pci, cqe2, time_stamp_high, 0x18, 0, 22);

static inline u64 mlxsw_pci_cqe2_time_stamp_get(const char *cqe)
{
u64 ts_high = mlxsw_pci_cqe2_time_stamp_high_get(cqe);
u64 ts_low = mlxsw_pci_cqe2_time_stamp_low_get(cqe);

return ts_high << 16 | ts_low;
}

static inline u8 mlxsw_pci_cqe2_time_stamp_sec_get(const char *cqe)
{
u64 full_ts = mlxsw_pci_cqe2_time_stamp_get(cqe);

return full_ts >> 30 & 0xFF;
}

static inline u32 mlxsw_pci_cqe2_time_stamp_nsec_get(const char *cqe)
{
u64 full_ts = mlxsw_pci_cqe2_time_stamp_get(cqe);

return full_ts & 0x3FFFFFFF;
}

/* pci_cqe_mirror_latency
* End-to-end latency of the original packet that does mirroring to the CPU.
* Value of 0xFFFFFF means that the latency is invalid. Units are according to
Expand Down
Loading

0 comments on commit 360f9f3

Please sign in to comment.