Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /* Marvell CN10K RPM driver
0003  *
0004  * Copyright (C) 2020 Marvell.
0005  *
0006  */
0007 
0008 #ifndef LMAC_COMMON_H
0009 #define LMAC_COMMON_H
0010 
0011 #include "rvu.h"
0012 #include "cgx.h"
0013 /**
0014  * struct lmac - per lmac locks and properties
0015  * @wq_cmd_cmplt:   waitq to keep the process blocked until cmd completion
0016  * @cmd_lock:       Lock to serialize the command interface
0017  * @resp:       command response
0018  * @link_info:      link related information
0019  * @mac_to_index_bmap:  Mac address to CGX table index mapping
0020  * @rx_fc_pfvf_bmap:    Receive flow control enabled netdev mapping
0021  * @tx_fc_pfvf_bmap:    Transmit flow control enabled netdev mapping
0022  * @event_cb:       callback for linkchange events
0023  * @event_cb_lock:  lock for serializing callback with unregister
0024  * @cgx:        parent cgx port
0025  * @mcast_filters_count:  Number of multicast filters installed
0026  * @lmac_id:        lmac port id
0027  * @cmd_pend:       flag set before new command is started
0028  *          flag cleared after command response is received
0029  * @name:       lmac port name
0030  */
0031 struct lmac {
0032     wait_queue_head_t wq_cmd_cmplt;
0033     /* Lock to serialize the command interface */
0034     struct mutex cmd_lock;
0035     u64 resp;
0036     struct cgx_link_user_info link_info;
0037     struct rsrc_bmap mac_to_index_bmap;
0038     struct rsrc_bmap rx_fc_pfvf_bmap;
0039     struct rsrc_bmap tx_fc_pfvf_bmap;
0040     struct cgx_event_cb event_cb;
0041     /* lock for serializing callback with unregister */
0042     spinlock_t event_cb_lock;
0043     struct cgx *cgx;
0044     u8 mcast_filters_count;
0045     u8 lmac_id;
0046     bool cmd_pend;
0047     char *name;
0048 };
0049 
0050 /* CGX & RPM has different feature set
0051  * update the structure fields with different one
0052  */
0053 struct mac_ops {
0054     char               *name;
0055     /* Features like RXSTAT, TXSTAT, DMAC FILTER csrs differs by fixed
0056      * bar offset for example
0057      * CGX DMAC_CTL0  0x1f8
0058      * RPM DMAC_CTL0  0x4ff8
0059      */
0060     u64         csr_offset;
0061     /* For ATF to send events to kernel, there is no dedicated interrupt
0062      * defined hence CGX uses OVERFLOW bit in CMR_INT. RPM block supports
0063      * SW_INT so that ATF triggers this interrupt after processing of
0064      * requested command
0065      */
0066     u64         int_register;
0067     u64         int_set_reg;
0068     /* lmac offset is different is RPM */
0069     u8          lmac_offset;
0070     u8          irq_offset;
0071     u8          int_ena_bit;
0072     u8          lmac_fwi;
0073     u32         fifo_len;
0074     bool            non_contiguous_serdes_lane;
0075     /* RPM & CGX differs in number of Receive/transmit stats */
0076     u8          rx_stats_cnt;
0077     u8          tx_stats_cnt;
0078     /* Incase of RPM get number of lmacs from RPMX_CMR_RX_LMACS[LMAC_EXIST]
0079      * number of setbits in lmac_exist tells number of lmacs
0080      */
0081     int         (*get_nr_lmacs)(void *cgx);
0082     u8                      (*get_lmac_type)(void *cgx, int lmac_id);
0083     u32                     (*lmac_fifo_len)(void *cgx, int lmac_id);
0084     int                     (*mac_lmac_intl_lbk)(void *cgx, int lmac_id,
0085                              bool enable);
0086     /* Register Stats related functions */
0087     int         (*mac_get_rx_stats)(void *cgx, int lmac_id,
0088                             int idx, u64 *rx_stat);
0089     int         (*mac_get_tx_stats)(void *cgx, int lmac_id,
0090                             int idx, u64 *tx_stat);
0091 
0092     /* Enable LMAC Pause Frame Configuration */
0093     void            (*mac_enadis_rx_pause_fwding)(void *cgxd,
0094                                   int lmac_id,
0095                                   bool enable);
0096 
0097     int         (*mac_get_pause_frm_status)(void *cgxd,
0098                                 int lmac_id,
0099                                 u8 *tx_pause,
0100                                 u8 *rx_pause);
0101 
0102     int         (*mac_enadis_pause_frm)(void *cgxd,
0103                             int lmac_id,
0104                             u8 tx_pause,
0105                             u8 rx_pause);
0106 
0107     void            (*mac_pause_frm_config)(void  *cgxd,
0108                             int lmac_id,
0109                             bool enable);
0110 
0111     /* Enable/Disable Inbound PTP */
0112     void            (*mac_enadis_ptp_config)(void  *cgxd,
0113                              int lmac_id,
0114                              bool enable);
0115 
0116     int         (*mac_rx_tx_enable)(void *cgxd, int lmac_id, bool enable);
0117     int         (*mac_tx_enable)(void *cgxd, int lmac_id, bool enable);
0118     int                     (*pfc_config)(void *cgxd, int lmac_id,
0119                           u8 tx_pause, u8 rx_pause, u16 pfc_en);
0120 
0121     int                     (*mac_get_pfc_frm_cfg)(void *cgxd, int lmac_id,
0122                                u8 *tx_pause, u8 *rx_pause);
0123 
0124 };
0125 
0126 struct cgx {
0127     void __iomem        *reg_base;
0128     struct pci_dev      *pdev;
0129     u8          cgx_id;
0130     u8          lmac_count;
0131     struct lmac     *lmac_idmap[MAX_LMAC_PER_CGX];
0132     struct          work_struct cgx_cmd_work;
0133     struct          workqueue_struct *cgx_cmd_workq;
0134     struct list_head    cgx_list;
0135     u64         hw_features;
0136     struct mac_ops      *mac_ops;
0137     unsigned long       lmac_bmap; /* bitmap of enabled lmacs */
0138     /* Lock to serialize read/write of global csrs like
0139      * RPMX_MTI_STAT_DATA_HI_CDC etc
0140      */
0141     struct mutex        lock;
0142 };
0143 
0144 typedef struct cgx rpm_t;
0145 
0146 /* Function Declarations */
0147 void cgx_write(struct cgx *cgx, u64 lmac, u64 offset, u64 val);
0148 u64 cgx_read(struct cgx *cgx, u64 lmac, u64 offset);
0149 struct lmac *lmac_pdata(u8 lmac_id, struct cgx *cgx);
0150 int cgx_fwi_cmd_send(u64 req, u64 *resp, struct lmac *lmac);
0151 int cgx_fwi_cmd_generic(u64 req, u64 *resp, struct cgx *cgx, int lmac_id);
0152 bool is_lmac_valid(struct cgx *cgx, int lmac_id);
0153 struct mac_ops *rpm_get_mac_ops(void);
0154 
0155 #endif /* LMAC_COMMON_H */