Extend the dpmac_counter_id enum with the newly added counters which can be interrogated through the MC firmware. Also add the dpmac_get_statistics() API which can be used to retrieve multiple MAC counters through a single firmware command.
Signed-off-by: Ioana Ciornei <[email protected]> --- .../net/ethernet/freescale/dpaa2/dpmac-cmd.h | 11 ++- drivers/net/ethernet/freescale/dpaa2/dpmac.c | 30 ++++++- drivers/net/ethernet/freescale/dpaa2/dpmac.h | 86 ++++++++++++++++++- 3 files changed, 123 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/freescale/dpaa2/dpmac-cmd.h b/drivers/net/ethernet/freescale/dpaa2/dpmac-cmd.h index e9ac2ecef3be..a864a99a0f75 100644 --- a/drivers/net/ethernet/freescale/dpaa2/dpmac-cmd.h +++ b/drivers/net/ethernet/freescale/dpaa2/dpmac-cmd.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */ /* Copyright 2013-2016 Freescale Semiconductor Inc. - * Copyright 2019 NXP + * Copyright 2019, 2024-2026 NXP */ #ifndef _FSL_DPMAC_CMD_H #define _FSL_DPMAC_CMD_H @@ -28,6 +28,8 @@ #define DPMAC_CMDID_SET_PROTOCOL DPMAC_CMD(0x0c7) +#define DPMAC_CMDID_GET_STATISTICS DPMAC_CMD(0x0c8) + /* Macros for accessing command fields smaller than 1byte */ #define DPMAC_MASK(field) \ GENMASK(DPMAC_##field##_SHIFT + DPMAC_##field##_SIZE - 1, \ @@ -82,4 +84,11 @@ struct dpmac_rsp_get_api_version { struct dpmac_cmd_set_protocol { u8 eth_if; }; + +struct dpmac_cmd_get_statistics { + __le64 iova_cnt; + __le64 iova_values; + __le32 num_cnt; +}; + #endif /* _FSL_DPMAC_CMD_H */ diff --git a/drivers/net/ethernet/freescale/dpaa2/dpmac.c b/drivers/net/ethernet/freescale/dpaa2/dpmac.c index f440a4c3b70c..8957665c05fc 100644 --- a/drivers/net/ethernet/freescale/dpaa2/dpmac.c +++ b/drivers/net/ethernet/freescale/dpaa2/dpmac.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) /* Copyright 2013-2016 Freescale Semiconductor Inc. - * Copyright 2019 NXP + * Copyright 2019, 2024-2026 NXP */ #include <linux/fsl/mc.h> #include "dpmac.h" @@ -235,3 +235,31 @@ int dpmac_set_protocol(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, return mc_send_command(mc_io, &cmd); } + +/** + * dpmac_get_statistics() - Get MAC statistics + * @mc_io: Pointer to opaque I/O object + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' + * @token: Token of DPMAC object + * @iova_cnt: IOVA containing the requested MAC counters formatted as an + * array of __le32 representing the dpmac_counter_id. + * @iova_values: IOVA containing the values for all the requested counters + * formatted as an array of __le64. + * @num_cnt: Number of counters requested + * + * Return: '0' on Success; Error code otherwise. + */ +int dpmac_get_statistics(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, + u64 iova_cnt, u64 iova_values, u32 num_cnt) +{ + struct dpmac_cmd_get_statistics *cmd_params; + struct fsl_mc_command cmd = { 0 }; + + cmd.header = mc_encode_cmd_header(DPMAC_CMDID_GET_STATISTICS, cmd_flags, token); + cmd_params = (struct dpmac_cmd_get_statistics *)cmd.params; + cmd_params->iova_cnt = cpu_to_le64(iova_cnt); + cmd_params->iova_values = cpu_to_le64(iova_values); + cmd_params->num_cnt = cpu_to_le32(num_cnt); + + return mc_send_command(mc_io, &cmd); +} diff --git a/drivers/net/ethernet/freescale/dpaa2/dpmac.h b/drivers/net/ethernet/freescale/dpaa2/dpmac.h index 17488819ef68..857b40a5b339 100644 --- a/drivers/net/ethernet/freescale/dpaa2/dpmac.h +++ b/drivers/net/ethernet/freescale/dpaa2/dpmac.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */ /* Copyright 2013-2016 Freescale Semiconductor Inc. - * Copyright 2019 NXP + * Copyright 2019, 2024-2026 NXP */ #ifndef __FSL_DPMAC_H #define __FSL_DPMAC_H @@ -170,6 +170,50 @@ int dpmac_set_link_state(struct fsl_mc_io *mc_io, * pause frames. * @DPMAC_CNT_EGR_GOOD_FRAME: counts frames transmitted without error, including * pause frames. + * @DPMAC_CNT_EGR_FRAME_64: counts transmitted 64-bytes frames, good or bad. + * @DPMAC_CNT_EGR_FRAME_127: counts transmitted 65 to 127-bytes frames, good or bad. + * @DPMAC_CNT_EGR_FRAME_255: counts transmitted 128 to 255-bytes frames, good or bad. + * @DPMAC_CNT_EGR_FRAME_511: counts transmitted 256 to 511-bytes frames, good or bad. + * @DPMAC_CNT_EGR_FRAME_1023: counts transmitted 512 to 1023-bytes frames, good or bad. + * @DPMAC_CNT_EGR_FRAME_1518: counts transmitted 1024 to 1518-bytes frames, good or bad. + * @DPMAC_CNT_EGR_FRAME_1519_MAX: counts transmitted 1519-bytes frames and + * larger (up to max frame length specified), good or bad. + * @DPMAC_CNT_ING_ALL_BYTE: counts bytes received in both good and bad packets + * @DPMAC_CNT_ING_FCS_ERR: counts frames received with a CRC-32 error but the + * frame is otherwise of correct length + * @DPMAC_CNT_ING_VLAN_FRAME: counts the received VLAN tagged frames which are valid. + * @DPMAC_CNT_ING_UNDERSIZED: counts received frames which were less than 64 + * bytes long and with a good CRC. + * @DPMAC_CNT_ING_CONTROL_FRAME: counts received control frames (type 0x8808) + * but not pause frames. + * @DPMAC_CNT_ING_FRAME_DISCARD_NOT_TRUNC: counts the fully dropped frames (not + * truncated) due to internal errors of the MAC client. Occurs when a received + * FIFO overflows. + * @DPMAC_CNT_EGR_ALL_BYTE: counts transmitted bytes in both good and bad + * packets. + * @DPMAC_CNT_EGR_FCS_ERR: counts trasmitted frames with a CRC-32 error except + * for underflows. + * @DPMAC_CNT_EGR_VLAN_FRAME: counts the transmitted VLAN tagged frames which + * are valid. + * @DPMAC_CNT_EGR_ALL_FRAME: counts all trasmitted frames, good or bad. + * @DPMAC_CNT_EGR_CONTROL_FRAME: counts transmitted control frames (type + * 0x8808) but not pause frames. + * @DPMAC_CNT_ING_PFC0: number of PFC frames received for class 0. + * @DPMAC_CNT_ING_PFC1: number of PFC frames received for class 1. + * @DPMAC_CNT_ING_PFC2: number of PFC frames received for class 2. + * @DPMAC_CNT_ING_PFC3: number of PFC frames received for class 3. + * @DPMAC_CNT_ING_PFC4: number of PFC frames received for class 4. + * @DPMAC_CNT_ING_PFC5: number of PFC frames received for class 5. + * @DPMAC_CNT_ING_PFC6: number of PFC frames received for class 6. + * @DPMAC_CNT_ING_PFC7: number of PFC frames received for class 7. + * @DPMAC_CNT_EGR_PFC0: number of PFC frames transmitted for class 0. + * @DPMAC_CNT_EGR_PFC1: number of PFC frames transmitted for class 1. + * @DPMAC_CNT_EGR_PFC2: number of PFC frames transmitted for class 2. + * @DPMAC_CNT_EGR_PFC3: number of PFC frames transmitted for class 3. + * @DPMAC_CNT_EGR_PFC4: number of PFC frames transmitted for class 4. + * @DPMAC_CNT_EGR_PFC5: number of PFC frames transmitted for class 5. + * @DPMAC_CNT_EGR_PFC6: number of PFC frames transmitted for class 6. + * @DPMAC_CNT_EGR_PFC7: number of PFC frames transmitted for class 7. */ enum dpmac_counter_id { DPMAC_CNT_ING_FRAME_64, @@ -199,7 +243,41 @@ enum dpmac_counter_id { DPMAC_CNT_EGR_UCAST_FRAME, DPMAC_CNT_EGR_ERR_FRAME, DPMAC_CNT_ING_GOOD_FRAME, - DPMAC_CNT_EGR_GOOD_FRAME + DPMAC_CNT_EGR_GOOD_FRAME, + DPMAC_CNT_EGR_FRAME_64, + DPMAC_CNT_EGR_FRAME_127, + DPMAC_CNT_EGR_FRAME_255, + DPMAC_CNT_EGR_FRAME_511, + DPMAC_CNT_EGR_FRAME_1023, + DPMAC_CNT_EGR_FRAME_1518, + DPMAC_CNT_EGR_FRAME_1519_MAX, + DPMAC_CNT_ING_ALL_BYTE, + DPMAC_CNT_ING_FCS_ERR, + DPMAC_CNT_ING_VLAN_FRAME, + DPMAC_CNT_ING_UNDERSIZED, + DPMAC_CNT_ING_CONTROL_FRAME, + DPMAC_CNT_ING_FRAME_DISCARD_NOT_TRUNC, + DPMAC_CNT_EGR_ALL_BYTE, + DPMAC_CNT_EGR_FCS_ERR, + DPMAC_CNT_EGR_VLAN_FRAME, + DPMAC_CNT_EGR_ALL_FRAME, + DPMAC_CNT_EGR_CONTROL_FRAME, + DPMAC_CNT_ING_PFC0, + DPMAC_CNT_ING_PFC1, + DPMAC_CNT_ING_PFC2, + DPMAC_CNT_ING_PFC3, + DPMAC_CNT_ING_PFC4, + DPMAC_CNT_ING_PFC5, + DPMAC_CNT_ING_PFC6, + DPMAC_CNT_ING_PFC7, + DPMAC_CNT_EGR_PFC0, + DPMAC_CNT_EGR_PFC1, + DPMAC_CNT_EGR_PFC2, + DPMAC_CNT_EGR_PFC3, + DPMAC_CNT_EGR_PFC4, + DPMAC_CNT_EGR_PFC5, + DPMAC_CNT_EGR_PFC6, + DPMAC_CNT_EGR_PFC7, }; int dpmac_get_counter(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, @@ -210,4 +288,8 @@ int dpmac_get_api_version(struct fsl_mc_io *mc_io, u32 cmd_flags, int dpmac_set_protocol(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, enum dpmac_eth_if protocol); + +int dpmac_get_statistics(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, + u64 iova_cnt, u64 iova_values, u32 num_cnt); + #endif /* __FSL_DPMAC_H */ -- 2.25.1

