162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci/* Marvell CN10K MCS driver 362306a36Sopenharmony_ci * 462306a36Sopenharmony_ci * Copyright (C) 2022 Marvell. 562306a36Sopenharmony_ci */ 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci#ifndef MCS_H 862306a36Sopenharmony_ci#define MCS_H 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci#include <linux/bits.h> 1162306a36Sopenharmony_ci#include "rvu.h" 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ci#define PCI_DEVID_CN10K_MCS 0xA096 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci#define MCSX_LINK_LMAC_RANGE_MASK GENMASK_ULL(19, 16) 1662306a36Sopenharmony_ci#define MCSX_LINK_LMAC_BASE_MASK GENMASK_ULL(11, 0) 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ci#define MCS_ID_MASK 0x7 1962306a36Sopenharmony_ci#define MCS_MAX_PFS 128 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci#define MCS_PORT_MODE_MASK 0x3 2262306a36Sopenharmony_ci#define MCS_PORT_FIFO_SKID_MASK 0x3F 2362306a36Sopenharmony_ci#define MCS_MAX_CUSTOM_TAGS 0x8 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ci#define MCS_CTRLPKT_ETYPE_RULE_MAX 8 2662306a36Sopenharmony_ci#define MCS_CTRLPKT_DA_RULE_MAX 8 2762306a36Sopenharmony_ci#define MCS_CTRLPKT_DA_RANGE_RULE_MAX 4 2862306a36Sopenharmony_ci#define MCS_CTRLPKT_COMBO_RULE_MAX 4 2962306a36Sopenharmony_ci#define MCS_CTRLPKT_MAC_RULE_MAX 1 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ci#define MCS_MAX_CTRLPKT_RULES (MCS_CTRLPKT_ETYPE_RULE_MAX + \ 3262306a36Sopenharmony_ci MCS_CTRLPKT_DA_RULE_MAX + \ 3362306a36Sopenharmony_ci MCS_CTRLPKT_DA_RANGE_RULE_MAX + \ 3462306a36Sopenharmony_ci MCS_CTRLPKT_COMBO_RULE_MAX + \ 3562306a36Sopenharmony_ci MCS_CTRLPKT_MAC_RULE_MAX) 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_ci#define MCS_CTRLPKT_ETYPE_RULE_OFFSET 0 3862306a36Sopenharmony_ci#define MCS_CTRLPKT_DA_RULE_OFFSET 8 3962306a36Sopenharmony_ci#define MCS_CTRLPKT_DA_RANGE_RULE_OFFSET 16 4062306a36Sopenharmony_ci#define MCS_CTRLPKT_COMBO_RULE_OFFSET 20 4162306a36Sopenharmony_ci#define MCS_CTRLPKT_MAC_EN_RULE_OFFSET 24 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci/* Reserved resources for default bypass entry */ 4462306a36Sopenharmony_ci#define MCS_RSRC_RSVD_CNT 1 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_ci/* MCS Interrupt Vector */ 4762306a36Sopenharmony_ci#define MCS_CNF10KB_INT_VEC_IP 0x13 4862306a36Sopenharmony_ci#define MCS_CN10KB_INT_VEC_IP 0x53 4962306a36Sopenharmony_ci 5062306a36Sopenharmony_ci#define MCS_MAX_BBE_INT 8ULL 5162306a36Sopenharmony_ci#define MCS_BBE_INT_MASK 0xFFULL 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ci#define MCS_MAX_PAB_INT 8ULL 5462306a36Sopenharmony_ci#define MCS_PAB_INT_MASK 0xFULL 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ci#define MCS_BBE_RX_INT_ENA BIT_ULL(0) 5762306a36Sopenharmony_ci#define MCS_BBE_TX_INT_ENA BIT_ULL(1) 5862306a36Sopenharmony_ci#define MCS_CPM_RX_INT_ENA BIT_ULL(2) 5962306a36Sopenharmony_ci#define MCS_CPM_TX_INT_ENA BIT_ULL(3) 6062306a36Sopenharmony_ci#define MCS_PAB_RX_INT_ENA BIT_ULL(4) 6162306a36Sopenharmony_ci#define MCS_PAB_TX_INT_ENA BIT_ULL(5) 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci#define MCS_CPM_TX_INT_PACKET_XPN_EQ0 BIT_ULL(0) 6462306a36Sopenharmony_ci#define MCS_CPM_TX_INT_PN_THRESH_REACHED BIT_ULL(1) 6562306a36Sopenharmony_ci#define MCS_CPM_TX_INT_SA_NOT_VALID BIT_ULL(2) 6662306a36Sopenharmony_ci 6762306a36Sopenharmony_ci#define MCS_CPM_RX_INT_SECTAG_V_EQ1 BIT_ULL(0) 6862306a36Sopenharmony_ci#define MCS_CPM_RX_INT_SECTAG_E_EQ0_C_EQ1 BIT_ULL(1) 6962306a36Sopenharmony_ci#define MCS_CPM_RX_INT_SL_GTE48 BIT_ULL(2) 7062306a36Sopenharmony_ci#define MCS_CPM_RX_INT_ES_EQ1_SC_EQ1 BIT_ULL(3) 7162306a36Sopenharmony_ci#define MCS_CPM_RX_INT_SC_EQ1_SCB_EQ1 BIT_ULL(4) 7262306a36Sopenharmony_ci#define MCS_CPM_RX_INT_PACKET_XPN_EQ0 BIT_ULL(5) 7362306a36Sopenharmony_ci#define MCS_CPM_RX_INT_PN_THRESH_REACHED BIT_ULL(6) 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ci#define MCS_CPM_RX_INT_ALL (MCS_CPM_RX_INT_SECTAG_V_EQ1 | \ 7662306a36Sopenharmony_ci MCS_CPM_RX_INT_SECTAG_E_EQ0_C_EQ1 | \ 7762306a36Sopenharmony_ci MCS_CPM_RX_INT_SL_GTE48 | \ 7862306a36Sopenharmony_ci MCS_CPM_RX_INT_ES_EQ1_SC_EQ1 | \ 7962306a36Sopenharmony_ci MCS_CPM_RX_INT_SC_EQ1_SCB_EQ1 | \ 8062306a36Sopenharmony_ci MCS_CPM_RX_INT_PACKET_XPN_EQ0 | \ 8162306a36Sopenharmony_ci MCS_CPM_RX_INT_PN_THRESH_REACHED) 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_cistruct mcs_pfvf { 8462306a36Sopenharmony_ci u64 intr_mask; /* Enabled Interrupt mask */ 8562306a36Sopenharmony_ci}; 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_cistruct mcs_intr_event { 8862306a36Sopenharmony_ci u16 pcifunc; 8962306a36Sopenharmony_ci u64 intr_mask; 9062306a36Sopenharmony_ci u64 sa_id; 9162306a36Sopenharmony_ci u8 mcs_id; 9262306a36Sopenharmony_ci u8 lmac_id; 9362306a36Sopenharmony_ci}; 9462306a36Sopenharmony_ci 9562306a36Sopenharmony_cistruct mcs_intrq_entry { 9662306a36Sopenharmony_ci struct list_head node; 9762306a36Sopenharmony_ci struct mcs_intr_event intr_event; 9862306a36Sopenharmony_ci}; 9962306a36Sopenharmony_ci 10062306a36Sopenharmony_cistruct secy_mem_map { 10162306a36Sopenharmony_ci u8 flow_id; 10262306a36Sopenharmony_ci u8 secy; 10362306a36Sopenharmony_ci u8 ctrl_pkt; 10462306a36Sopenharmony_ci u8 sc; 10562306a36Sopenharmony_ci u64 sci; 10662306a36Sopenharmony_ci}; 10762306a36Sopenharmony_ci 10862306a36Sopenharmony_cistruct mcs_rsrc_map { 10962306a36Sopenharmony_ci u16 *flowid2pf_map; 11062306a36Sopenharmony_ci u16 *secy2pf_map; 11162306a36Sopenharmony_ci u16 *sc2pf_map; 11262306a36Sopenharmony_ci u16 *sa2pf_map; 11362306a36Sopenharmony_ci u16 *flowid2secy_map; /* bitmap flowid mapped to secy*/ 11462306a36Sopenharmony_ci u16 *ctrlpktrule2pf_map; 11562306a36Sopenharmony_ci struct rsrc_bmap flow_ids; 11662306a36Sopenharmony_ci struct rsrc_bmap secy; 11762306a36Sopenharmony_ci struct rsrc_bmap sc; 11862306a36Sopenharmony_ci struct rsrc_bmap sa; 11962306a36Sopenharmony_ci struct rsrc_bmap ctrlpktrule; 12062306a36Sopenharmony_ci}; 12162306a36Sopenharmony_ci 12262306a36Sopenharmony_cistruct hwinfo { 12362306a36Sopenharmony_ci u8 tcam_entries; 12462306a36Sopenharmony_ci u8 secy_entries; 12562306a36Sopenharmony_ci u8 sc_entries; 12662306a36Sopenharmony_ci u16 sa_entries; 12762306a36Sopenharmony_ci u8 mcs_x2p_intf; 12862306a36Sopenharmony_ci u8 lmac_cnt; 12962306a36Sopenharmony_ci u8 mcs_blks; 13062306a36Sopenharmony_ci unsigned long lmac_bmap; /* bitmap of enabled mcs lmac */ 13162306a36Sopenharmony_ci u16 ip_vec; 13262306a36Sopenharmony_ci}; 13362306a36Sopenharmony_ci 13462306a36Sopenharmony_cistruct mcs { 13562306a36Sopenharmony_ci void __iomem *reg_base; 13662306a36Sopenharmony_ci struct pci_dev *pdev; 13762306a36Sopenharmony_ci struct device *dev; 13862306a36Sopenharmony_ci struct hwinfo *hw; 13962306a36Sopenharmony_ci struct mcs_rsrc_map tx; 14062306a36Sopenharmony_ci struct mcs_rsrc_map rx; 14162306a36Sopenharmony_ci u16 pf_map[MCS_MAX_PFS]; /* List of PCIFUNC mapped to MCS */ 14262306a36Sopenharmony_ci u8 mcs_id; 14362306a36Sopenharmony_ci struct mcs_ops *mcs_ops; 14462306a36Sopenharmony_ci struct list_head mcs_list; 14562306a36Sopenharmony_ci /* Lock for mcs stats */ 14662306a36Sopenharmony_ci struct mutex stats_lock; 14762306a36Sopenharmony_ci struct mcs_pfvf *pf; 14862306a36Sopenharmony_ci struct mcs_pfvf *vf; 14962306a36Sopenharmony_ci u16 num_vec; 15062306a36Sopenharmony_ci void *rvu; 15162306a36Sopenharmony_ci u16 *tx_sa_active; 15262306a36Sopenharmony_ci bool bypass; 15362306a36Sopenharmony_ci}; 15462306a36Sopenharmony_ci 15562306a36Sopenharmony_cistruct mcs_ops { 15662306a36Sopenharmony_ci void (*mcs_set_hw_capabilities)(struct mcs *mcs); 15762306a36Sopenharmony_ci void (*mcs_parser_cfg)(struct mcs *mcs); 15862306a36Sopenharmony_ci void (*mcs_tx_sa_mem_map_write)(struct mcs *mcs, struct mcs_tx_sc_sa_map *map); 15962306a36Sopenharmony_ci void (*mcs_rx_sa_mem_map_write)(struct mcs *mcs, struct mcs_rx_sc_sa_map *map); 16062306a36Sopenharmony_ci void (*mcs_flowid_secy_map)(struct mcs *mcs, struct secy_mem_map *map, int dir); 16162306a36Sopenharmony_ci void (*mcs_bbe_intr_handler)(struct mcs *mcs, u64 intr, enum mcs_direction dir); 16262306a36Sopenharmony_ci void (*mcs_pab_intr_handler)(struct mcs *mcs, u64 intr, enum mcs_direction dir); 16362306a36Sopenharmony_ci}; 16462306a36Sopenharmony_ci 16562306a36Sopenharmony_ciextern struct pci_driver mcs_driver; 16662306a36Sopenharmony_ci 16762306a36Sopenharmony_cistatic inline void mcs_reg_write(struct mcs *mcs, u64 offset, u64 val) 16862306a36Sopenharmony_ci{ 16962306a36Sopenharmony_ci writeq(val, mcs->reg_base + offset); 17062306a36Sopenharmony_ci} 17162306a36Sopenharmony_ci 17262306a36Sopenharmony_cistatic inline u64 mcs_reg_read(struct mcs *mcs, u64 offset) 17362306a36Sopenharmony_ci{ 17462306a36Sopenharmony_ci return readq(mcs->reg_base + offset); 17562306a36Sopenharmony_ci} 17662306a36Sopenharmony_ci 17762306a36Sopenharmony_ci/* MCS APIs */ 17862306a36Sopenharmony_cistruct mcs *mcs_get_pdata(int mcs_id); 17962306a36Sopenharmony_ciint mcs_get_blkcnt(void); 18062306a36Sopenharmony_ciint mcs_set_lmac_channels(int mcs_id, u16 base); 18162306a36Sopenharmony_ciint mcs_alloc_rsrc(struct rsrc_bmap *rsrc, u16 *pf_map, u16 pcifunc); 18262306a36Sopenharmony_ciint mcs_free_rsrc(struct rsrc_bmap *rsrc, u16 *pf_map, int rsrc_id, u16 pcifunc); 18362306a36Sopenharmony_ciint mcs_alloc_all_rsrc(struct mcs *mcs, u8 *flowid, u8 *secy_id, 18462306a36Sopenharmony_ci u8 *sc_id, u8 *sa1_id, u8 *sa2_id, u16 pcifunc, int dir); 18562306a36Sopenharmony_ciint mcs_free_all_rsrc(struct mcs *mcs, int dir, u16 pcifunc); 18662306a36Sopenharmony_civoid mcs_clear_secy_plcy(struct mcs *mcs, int secy_id, int dir); 18762306a36Sopenharmony_civoid mcs_ena_dis_flowid_entry(struct mcs *mcs, int id, int dir, int ena); 18862306a36Sopenharmony_civoid mcs_ena_dis_sc_cam_entry(struct mcs *mcs, int id, int ena); 18962306a36Sopenharmony_civoid mcs_flowid_entry_write(struct mcs *mcs, u64 *data, u64 *mask, int id, int dir); 19062306a36Sopenharmony_civoid mcs_secy_plcy_write(struct mcs *mcs, u64 plcy, int id, int dir); 19162306a36Sopenharmony_civoid mcs_rx_sc_cam_write(struct mcs *mcs, u64 sci, u64 secy, int sc_id); 19262306a36Sopenharmony_civoid mcs_sa_plcy_write(struct mcs *mcs, u64 *plcy, int sa, int dir); 19362306a36Sopenharmony_civoid mcs_map_sc_to_sa(struct mcs *mcs, u64 *sa_map, int sc, int dir); 19462306a36Sopenharmony_civoid mcs_pn_table_write(struct mcs *mcs, u8 pn_id, u64 next_pn, u8 dir); 19562306a36Sopenharmony_civoid mcs_tx_sa_mem_map_write(struct mcs *mcs, struct mcs_tx_sc_sa_map *map); 19662306a36Sopenharmony_civoid mcs_flowid_secy_map(struct mcs *mcs, struct secy_mem_map *map, int dir); 19762306a36Sopenharmony_civoid mcs_rx_sa_mem_map_write(struct mcs *mcs, struct mcs_rx_sc_sa_map *map); 19862306a36Sopenharmony_civoid mcs_pn_threshold_set(struct mcs *mcs, struct mcs_set_pn_threshold *pn); 19962306a36Sopenharmony_ciint mcs_install_flowid_bypass_entry(struct mcs *mcs); 20062306a36Sopenharmony_civoid mcs_set_lmac_mode(struct mcs *mcs, int lmac_id, u8 mode); 20162306a36Sopenharmony_civoid mcs_reset_port(struct mcs *mcs, u8 port_id, u8 reset); 20262306a36Sopenharmony_civoid mcs_set_port_cfg(struct mcs *mcs, struct mcs_port_cfg_set_req *req); 20362306a36Sopenharmony_civoid mcs_get_port_cfg(struct mcs *mcs, struct mcs_port_cfg_get_req *req, 20462306a36Sopenharmony_ci struct mcs_port_cfg_get_rsp *rsp); 20562306a36Sopenharmony_civoid mcs_get_custom_tag_cfg(struct mcs *mcs, struct mcs_custom_tag_cfg_get_req *req, 20662306a36Sopenharmony_ci struct mcs_custom_tag_cfg_get_rsp *rsp); 20762306a36Sopenharmony_ciint mcs_alloc_ctrlpktrule(struct rsrc_bmap *rsrc, u16 *pf_map, u16 offset, u16 pcifunc); 20862306a36Sopenharmony_ciint mcs_free_ctrlpktrule(struct mcs *mcs, struct mcs_free_ctrl_pkt_rule_req *req); 20962306a36Sopenharmony_ciint mcs_ctrlpktrule_write(struct mcs *mcs, struct mcs_ctrl_pkt_rule_write_req *req); 21062306a36Sopenharmony_cibool is_mcs_bypass(int mcs_id); 21162306a36Sopenharmony_ci 21262306a36Sopenharmony_ci/* CN10K-B APIs */ 21362306a36Sopenharmony_civoid cn10kb_mcs_set_hw_capabilities(struct mcs *mcs); 21462306a36Sopenharmony_civoid cn10kb_mcs_tx_sa_mem_map_write(struct mcs *mcs, struct mcs_tx_sc_sa_map *map); 21562306a36Sopenharmony_civoid cn10kb_mcs_flowid_secy_map(struct mcs *mcs, struct secy_mem_map *map, int dir); 21662306a36Sopenharmony_civoid cn10kb_mcs_rx_sa_mem_map_write(struct mcs *mcs, struct mcs_rx_sc_sa_map *map); 21762306a36Sopenharmony_civoid cn10kb_mcs_parser_cfg(struct mcs *mcs); 21862306a36Sopenharmony_civoid cn10kb_mcs_pab_intr_handler(struct mcs *mcs, u64 intr, enum mcs_direction dir); 21962306a36Sopenharmony_civoid cn10kb_mcs_bbe_intr_handler(struct mcs *mcs, u64 intr, enum mcs_direction dir); 22062306a36Sopenharmony_ci 22162306a36Sopenharmony_ci/* CNF10K-B APIs */ 22262306a36Sopenharmony_cistruct mcs_ops *cnf10kb_get_mac_ops(void); 22362306a36Sopenharmony_civoid cnf10kb_mcs_set_hw_capabilities(struct mcs *mcs); 22462306a36Sopenharmony_civoid cnf10kb_mcs_tx_sa_mem_map_write(struct mcs *mcs, struct mcs_tx_sc_sa_map *map); 22562306a36Sopenharmony_civoid cnf10kb_mcs_flowid_secy_map(struct mcs *mcs, struct secy_mem_map *map, int dir); 22662306a36Sopenharmony_civoid cnf10kb_mcs_rx_sa_mem_map_write(struct mcs *mcs, struct mcs_rx_sc_sa_map *map); 22762306a36Sopenharmony_civoid cnf10kb_mcs_parser_cfg(struct mcs *mcs); 22862306a36Sopenharmony_civoid cnf10kb_mcs_tx_pn_thresh_reached_handler(struct mcs *mcs); 22962306a36Sopenharmony_civoid cnf10kb_mcs_tx_pn_wrapped_handler(struct mcs *mcs); 23062306a36Sopenharmony_civoid cnf10kb_mcs_bbe_intr_handler(struct mcs *mcs, u64 intr, enum mcs_direction dir); 23162306a36Sopenharmony_civoid cnf10kb_mcs_pab_intr_handler(struct mcs *mcs, u64 intr, enum mcs_direction dir); 23262306a36Sopenharmony_ci 23362306a36Sopenharmony_ci/* Stats APIs */ 23462306a36Sopenharmony_civoid mcs_get_sc_stats(struct mcs *mcs, struct mcs_sc_stats *stats, int id, int dir); 23562306a36Sopenharmony_civoid mcs_get_sa_stats(struct mcs *mcs, struct mcs_sa_stats *stats, int id, int dir); 23662306a36Sopenharmony_civoid mcs_get_port_stats(struct mcs *mcs, struct mcs_port_stats *stats, int id, int dir); 23762306a36Sopenharmony_civoid mcs_get_flowid_stats(struct mcs *mcs, struct mcs_flowid_stats *stats, int id, int dir); 23862306a36Sopenharmony_civoid mcs_get_rx_secy_stats(struct mcs *mcs, struct mcs_secy_stats *stats, int id); 23962306a36Sopenharmony_civoid mcs_get_tx_secy_stats(struct mcs *mcs, struct mcs_secy_stats *stats, int id); 24062306a36Sopenharmony_civoid mcs_clear_stats(struct mcs *mcs, u8 type, u8 id, int dir); 24162306a36Sopenharmony_ciint mcs_clear_all_stats(struct mcs *mcs, u16 pcifunc, int dir); 24262306a36Sopenharmony_ciint mcs_set_force_clk_en(struct mcs *mcs, bool set); 24362306a36Sopenharmony_ci 24462306a36Sopenharmony_ciint mcs_add_intr_wq_entry(struct mcs *mcs, struct mcs_intr_event *event); 24562306a36Sopenharmony_ci 24662306a36Sopenharmony_ci#endif /* MCS_H */ 247