191c6945eSHariprasad Kelam /* SPDX-License-Identifier: GPL-2.0 */ 2c7cd6c5aSSunil Goutham /* Marvell CN10K RPM driver 391c6945eSHariprasad Kelam * 491c6945eSHariprasad Kelam * Copyright (C) 2020 Marvell. 5c7cd6c5aSSunil Goutham * 691c6945eSHariprasad Kelam */ 791c6945eSHariprasad Kelam 891c6945eSHariprasad Kelam #ifndef LMAC_COMMON_H 991c6945eSHariprasad Kelam #define LMAC_COMMON_H 1091c6945eSHariprasad Kelam 1191c6945eSHariprasad Kelam #include "rvu.h" 1291c6945eSHariprasad Kelam #include "cgx.h" 1391c6945eSHariprasad Kelam /** 146f14078eSSunil Kumar Kori * struct lmac - per lmac locks and properties 1591c6945eSHariprasad Kelam * @wq_cmd_cmplt: waitq to keep the process blocked until cmd completion 1691c6945eSHariprasad Kelam * @cmd_lock: Lock to serialize the command interface 1791c6945eSHariprasad Kelam * @resp: command response 1891c6945eSHariprasad Kelam * @link_info: link related information 196f14078eSSunil Kumar Kori * @mac_to_index_bmap: Mac address to CGX table index mapping 20e7400038SHariprasad Kelam * @rx_fc_pfvf_bmap: Receive flow control enabled netdev mapping 21e7400038SHariprasad Kelam * @tx_fc_pfvf_bmap: Transmit flow control enabled netdev mapping 2291c6945eSHariprasad Kelam * @event_cb: callback for linkchange events 2391c6945eSHariprasad Kelam * @event_cb_lock: lock for serializing callback with unregister 246f14078eSSunil Kumar Kori * @cgx: parent cgx port 256f14078eSSunil Kumar Kori * @mcast_filters_count: Number of multicast filters installed 266f14078eSSunil Kumar Kori * @lmac_id: lmac port id 272e3e94c2SHariprasad Kelam * @lmac_type: lmac type like SGMII/XAUI 2891c6945eSHariprasad Kelam * @cmd_pend: flag set before new command is started 2991c6945eSHariprasad Kelam * flag cleared after command response is received 3091c6945eSHariprasad Kelam * @name: lmac port name 3191c6945eSHariprasad Kelam */ 3291c6945eSHariprasad Kelam struct lmac { 3391c6945eSHariprasad Kelam wait_queue_head_t wq_cmd_cmplt; 3491c6945eSHariprasad Kelam /* Lock to serialize the command interface */ 3591c6945eSHariprasad Kelam struct mutex cmd_lock; 3691c6945eSHariprasad Kelam u64 resp; 3791c6945eSHariprasad Kelam struct cgx_link_user_info link_info; 386f14078eSSunil Kumar Kori struct rsrc_bmap mac_to_index_bmap; 39e7400038SHariprasad Kelam struct rsrc_bmap rx_fc_pfvf_bmap; 40e7400038SHariprasad Kelam struct rsrc_bmap tx_fc_pfvf_bmap; 4191c6945eSHariprasad Kelam struct cgx_event_cb event_cb; 4291c6945eSHariprasad Kelam /* lock for serializing callback with unregister */ 4391c6945eSHariprasad Kelam spinlock_t event_cb_lock; 4491c6945eSHariprasad Kelam struct cgx *cgx; 456f14078eSSunil Kumar Kori u8 mcast_filters_count; 4691c6945eSHariprasad Kelam u8 lmac_id; 472e3e94c2SHariprasad Kelam u8 lmac_type; 486f14078eSSunil Kumar Kori bool cmd_pend; 4991c6945eSHariprasad Kelam char *name; 5091c6945eSHariprasad Kelam }; 5191c6945eSHariprasad Kelam 5291c6945eSHariprasad Kelam /* CGX & RPM has different feature set 5391c6945eSHariprasad Kelam * update the structure fields with different one 5491c6945eSHariprasad Kelam */ 5591c6945eSHariprasad Kelam struct mac_ops { 5691c6945eSHariprasad Kelam char *name; 5791c6945eSHariprasad Kelam /* Features like RXSTAT, TXSTAT, DMAC FILTER csrs differs by fixed 5891c6945eSHariprasad Kelam * bar offset for example 5991c6945eSHariprasad Kelam * CGX DMAC_CTL0 0x1f8 6091c6945eSHariprasad Kelam * RPM DMAC_CTL0 0x4ff8 6191c6945eSHariprasad Kelam */ 6291c6945eSHariprasad Kelam u64 csr_offset; 6391c6945eSHariprasad Kelam /* For ATF to send events to kernel, there is no dedicated interrupt 6491c6945eSHariprasad Kelam * defined hence CGX uses OVERFLOW bit in CMR_INT. RPM block supports 6591c6945eSHariprasad Kelam * SW_INT so that ATF triggers this interrupt after processing of 6691c6945eSHariprasad Kelam * requested command 6791c6945eSHariprasad Kelam */ 6891c6945eSHariprasad Kelam u64 int_register; 6991c6945eSHariprasad Kelam u64 int_set_reg; 7091c6945eSHariprasad Kelam /* lmac offset is different is RPM */ 7191c6945eSHariprasad Kelam u8 lmac_offset; 7291c6945eSHariprasad Kelam u8 irq_offset; 7391c6945eSHariprasad Kelam u8 int_ena_bit; 7491c6945eSHariprasad Kelam u8 lmac_fwi; 7591c6945eSHariprasad Kelam bool non_contiguous_serdes_lane; 76ce7a6c31SHariprasad Kelam /* RPM & CGX differs in number of Receive/transmit stats */ 77ce7a6c31SHariprasad Kelam u8 rx_stats_cnt; 78ce7a6c31SHariprasad Kelam u8 tx_stats_cnt; 79b9d0fedcSHariprasad Kelam /* Unlike CN10K which shares same CSR offset with CGX 80b9d0fedcSHariprasad Kelam * CNF10KB has different csr offset 81b9d0fedcSHariprasad Kelam */ 82b9d0fedcSHariprasad Kelam u64 rxid_map_offset; 83b9d0fedcSHariprasad Kelam u8 dmac_filter_count; 8491c6945eSHariprasad Kelam /* Incase of RPM get number of lmacs from RPMX_CMR_RX_LMACS[LMAC_EXIST] 8591c6945eSHariprasad Kelam * number of setbits in lmac_exist tells number of lmacs 8691c6945eSHariprasad Kelam */ 8791c6945eSHariprasad Kelam int (*get_nr_lmacs)(void *cgx); 883ad3f8f9SHariprasad Kelam u8 (*get_lmac_type)(void *cgx, int lmac_id); 89459f326eSSunil Goutham u32 (*lmac_fifo_len)(void *cgx, int lmac_id); 903ad3f8f9SHariprasad Kelam int (*mac_lmac_intl_lbk)(void *cgx, int lmac_id, 913ad3f8f9SHariprasad Kelam bool enable); 92ce7a6c31SHariprasad Kelam /* Register Stats related functions */ 93ce7a6c31SHariprasad Kelam int (*mac_get_rx_stats)(void *cgx, int lmac_id, 94ce7a6c31SHariprasad Kelam int idx, u64 *rx_stat); 95ce7a6c31SHariprasad Kelam int (*mac_get_tx_stats)(void *cgx, int lmac_id, 96ce7a6c31SHariprasad Kelam int idx, u64 *tx_stat); 97ce7a6c31SHariprasad Kelam 981845ada4SRakesh Babu /* Enable LMAC Pause Frame Configuration */ 991845ada4SRakesh Babu void (*mac_enadis_rx_pause_fwding)(void *cgxd, 1001845ada4SRakesh Babu int lmac_id, 1011845ada4SRakesh Babu bool enable); 102ce7a6c31SHariprasad Kelam 1031845ada4SRakesh Babu int (*mac_get_pause_frm_status)(void *cgxd, 1041845ada4SRakesh Babu int lmac_id, 1051845ada4SRakesh Babu u8 *tx_pause, 1061845ada4SRakesh Babu u8 *rx_pause); 1071845ada4SRakesh Babu 1081845ada4SRakesh Babu int (*mac_enadis_pause_frm)(void *cgxd, 1091845ada4SRakesh Babu int lmac_id, 1101845ada4SRakesh Babu u8 tx_pause, 1111845ada4SRakesh Babu u8 rx_pause); 112ce7a6c31SHariprasad Kelam 1131845ada4SRakesh Babu void (*mac_pause_frm_config)(void *cgxd, 1141845ada4SRakesh Babu int lmac_id, 1151845ada4SRakesh Babu bool enable); 116d1489208SHariprasad Kelam 117d1489208SHariprasad Kelam /* Enable/Disable Inbound PTP */ 118d1489208SHariprasad Kelam void (*mac_enadis_ptp_config)(void *cgxd, 119d1489208SHariprasad Kelam int lmac_id, 120d1489208SHariprasad Kelam bool enable); 121fae80edeSGeetha sowjanya 122fae80edeSGeetha sowjanya int (*mac_rx_tx_enable)(void *cgxd, int lmac_id, bool enable); 123fae80edeSGeetha sowjanya int (*mac_tx_enable)(void *cgxd, int lmac_id, bool enable); 1241121f6b0SSunil Kumar Kori int (*pfc_config)(void *cgxd, int lmac_id, 1251121f6b0SSunil Kumar Kori u8 tx_pause, u8 rx_pause, u16 pfc_en); 1261121f6b0SSunil Kumar Kori 127e7400038SHariprasad Kelam int (*mac_get_pfc_frm_cfg)(void *cgxd, int lmac_id, 128e7400038SHariprasad Kelam u8 *tx_pause, u8 *rx_pause); 1292e3e94c2SHariprasad Kelam int (*mac_reset)(void *cgxd, int lmac_id, u8 pf_req_flr); 130e7400038SHariprasad Kelam 13184ad3642SHariprasad Kelam /* FEC stats */ 13284ad3642SHariprasad Kelam int (*get_fec_stats)(void *cgxd, int lmac_id, 13384ad3642SHariprasad Kelam struct cgx_fec_stats_rsp *rsp); 13492ada6dfSSai Krishna int (*mac_stats_reset)(void *cgxd, int lmac_id); 135*fed89cfaSHariprasad Kelam void (*mac_x2p_reset)(void *cgxd, bool enable); 136*fed89cfaSHariprasad Kelam int (*mac_enadis_rx)(void *cgxd, int lmac_id, bool enable); 13791c6945eSHariprasad Kelam }; 13891c6945eSHariprasad Kelam 13991c6945eSHariprasad Kelam struct cgx { 14091c6945eSHariprasad Kelam void __iomem *reg_base; 14191c6945eSHariprasad Kelam struct pci_dev *pdev; 14291c6945eSHariprasad Kelam u8 cgx_id; 14391c6945eSHariprasad Kelam u8 lmac_count; 144f2e664adSRakesh Babu Saladi /* number of LMACs per MAC could be 4 or 8 */ 145f2e664adSRakesh Babu Saladi u8 max_lmac_per_mac; 1463eda3da8SHariprasad Kelam /* length of fifo varies depending on the number 1473eda3da8SHariprasad Kelam * of LMACS 1483eda3da8SHariprasad Kelam */ 1493eda3da8SHariprasad Kelam u32 fifo_len; 150f2e664adSRakesh Babu Saladi #define MAX_LMAC_COUNT 8 151f2e664adSRakesh Babu Saladi struct lmac *lmac_idmap[MAX_LMAC_COUNT]; 15291c6945eSHariprasad Kelam struct work_struct cgx_cmd_work; 15391c6945eSHariprasad Kelam struct workqueue_struct *cgx_cmd_workq; 15491c6945eSHariprasad Kelam struct list_head cgx_list; 15591c6945eSHariprasad Kelam u64 hw_features; 15691c6945eSHariprasad Kelam struct mac_ops *mac_ops; 15791c6945eSHariprasad Kelam unsigned long lmac_bmap; /* bitmap of enabled lmacs */ 158ce7a6c31SHariprasad Kelam /* Lock to serialize read/write of global csrs like 159ce7a6c31SHariprasad Kelam * RPMX_MTI_STAT_DATA_HI_CDC etc 160ce7a6c31SHariprasad Kelam */ 161ce7a6c31SHariprasad Kelam struct mutex lock; 16291c6945eSHariprasad Kelam }; 16391c6945eSHariprasad Kelam 16491c6945eSHariprasad Kelam typedef struct cgx rpm_t; 16591c6945eSHariprasad Kelam 16691c6945eSHariprasad Kelam /* Function Declarations */ 16791c6945eSHariprasad Kelam void cgx_write(struct cgx *cgx, u64 lmac, u64 offset, u64 val); 16891c6945eSHariprasad Kelam u64 cgx_read(struct cgx *cgx, u64 lmac, u64 offset); 16991c6945eSHariprasad Kelam struct lmac *lmac_pdata(u8 lmac_id, struct cgx *cgx); 17091c6945eSHariprasad Kelam int cgx_fwi_cmd_send(u64 req, u64 *resp, struct lmac *lmac); 17191c6945eSHariprasad Kelam int cgx_fwi_cmd_generic(u64 req, u64 *resp, struct cgx *cgx, int lmac_id); 17291c6945eSHariprasad Kelam bool is_lmac_valid(struct cgx *cgx, int lmac_id); 173b9d0fedcSHariprasad Kelam struct mac_ops *rpm_get_mac_ops(struct cgx *cgx); 17491c6945eSHariprasad Kelam 17591c6945eSHariprasad Kelam #endif /* LMAC_COMMON_H */ 176