1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* Copyright (c) Meta Platforms, Inc. and affiliates. */ 3 4 #ifndef _FBNIC_MAC_H_ 5 #define _FBNIC_MAC_H_ 6 7 #include <linux/types.h> 8 9 struct fbnic_dev; 10 11 /* The RXB clock runs at 600 MHZ in the ASIC and the PAUSE_STORM_UNIT_WR 12 * is 10us granularity, so set the clock to 6000 (0x1770) 13 */ 14 #define FBNIC_RXB_PS_CLK_DIV 0x1770 15 16 /* Convert milliseconds to pause storm timeout units (10us granularity) */ 17 #define FBNIC_MAC_RXB_PS_TO(ms) ((ms) * 100) 18 19 /* Convert pause storm timeout units (10us granularity) to milliseconds */ 20 #define FBNIC_MAC_RXB_PS_TO_MS(ps) ((ps) / 100) 21 22 /* Set the default timer to 500ms, which should be longer than any 23 * reasonable period of continuous pausing. The service task, which runs 24 * once per second, periodically resets the pause storm trigger. 25 * 26 * As a result, on a functioning system, if pause continues, we enforce 27 * a duty cycle determined by the configured pause storm timeout (50% 28 * default). A crashed system will not have the service task and therefore 29 * pause will remain disabled until reboot recovery. 30 */ 31 #define FBNIC_MAC_PS_TO_DEFAULT_MS 500 32 #define FBNIC_MAC_PS_TO_MAX_MS \ 33 FBNIC_MAC_RXB_PS_TO_MS(FIELD_MAX(FBNIC_RXB_PAUSE_STORM_THLD_TIME)) 34 35 #define FBNIC_MAX_JUMBO_FRAME_SIZE 9742 36 37 /* States loosely based on section 136.8.11.7.5 of IEEE 802.3-2022 Ethernet 38 * Standard. These are needed to track the state of the PHY as it has a delay 39 * of several seconds from the time link comes up until it has completed 40 * training that we need to wait to report the link. 41 * 42 * Currently we treat training as a single block as this is managed by the 43 * firmware. 44 * 45 * We have FBNIC_PMD_SEND_DATA set to 0 as the expected default at driver load 46 * and we initialize the structure containing it to zero at allocation. 47 */ 48 enum { 49 FBNIC_PMD_SEND_DATA = 0x0, 50 FBNIC_PMD_INITIALIZE = 0x1, 51 FBNIC_PMD_TRAINING = 0x2, 52 FBNIC_PMD_LINK_READY = 0x3, 53 }; 54 55 enum { 56 FBNIC_LINK_EVENT_NONE = 0, 57 FBNIC_LINK_EVENT_UP = 1, 58 FBNIC_LINK_EVENT_DOWN = 2, 59 }; 60 61 /* Treat the FEC bits as a bitmask laid out as follows: 62 * Bit 0: RS Enabled 63 * Bit 1: BASER(Firecode) Enabled 64 * Bit 2: Retrieve FEC from FW 65 */ 66 enum { 67 FBNIC_FEC_OFF = 0, 68 FBNIC_FEC_RS = 1, 69 FBNIC_FEC_BASER = 2, 70 }; 71 72 /* Treat the AUI modes as a modulation/lanes bitmask: 73 * Bit 0: Lane Count, 0 = R1, 1 = R2 74 * Bit 1: Modulation, 0 = NRZ, 1 = PAM4 75 * Bit 2: Unknown Modulation/Lane Configuration 76 */ 77 enum { 78 FBNIC_AUI_25GAUI = 0, /* 25.7812GBd 25.78125 * 1 */ 79 FBNIC_AUI_LAUI2 = 1, /* 51.5625GBd 25.78128 * 2 */ 80 FBNIC_AUI_50GAUI1 = 2, /* 53.125GBd 53.125 * 1 */ 81 FBNIC_AUI_100GAUI2 = 3, /* 106.25GBd 53.125 * 2 */ 82 FBNIC_AUI_UNKNOWN = 4, 83 __FBNIC_AUI_MAX__ 84 }; 85 86 #define FBNIC_AUI_MODE_R2 (FBNIC_AUI_LAUI2) 87 #define FBNIC_AUI_MODE_PAM4 (FBNIC_AUI_50GAUI1) 88 89 enum fbnic_sensor_id { 90 FBNIC_SENSOR_TEMP, /* Temp in millidegrees Centigrade */ 91 FBNIC_SENSOR_VOLTAGE, /* Voltage in millivolts */ 92 }; 93 94 /* This structure defines the interface hooks for the MAC. The MAC hooks 95 * will be configured as a const struct provided with a set of function 96 * pointers. 97 * 98 * void (*init_regs)(struct fbnic_dev *fbd); 99 * Initialize MAC registers to enable Tx/Rx paths and FIFOs. 100 * 101 * int (*get_link_event)(struct fbnic_dev *fbd) 102 * Get the current link event status, reports true if link has 103 * changed to either FBNIC_LINK_EVENT_DOWN or FBNIC_LINK_EVENT_UP 104 * bool (*get_link)(struct fbnic_dev *fbd, u8 aui, u8 fec); 105 * Check link status 106 * 107 * void (*prepare)(struct fbnic_dev *fbd, u8 aui, u8 fec); 108 * Prepare PHY for init by fetching settings, disabling interrupts, 109 * and sending an updated PHY config to FW if needed. 110 * 111 * void (*link_down)(struct fbnic_dev *fbd); 112 * Configure MAC for link down event 113 * void (*link_up)(struct fbnic_dev *fbd, bool tx_pause, bool rx_pause); 114 * Configure MAC for link up event; 115 * 116 */ 117 struct fbnic_mac { 118 void (*init_regs)(struct fbnic_dev *fbd); 119 120 int (*get_link_event)(struct fbnic_dev *fbd); 121 bool (*get_link)(struct fbnic_dev *fbd, u8 aui, u8 fec); 122 123 void (*prepare)(struct fbnic_dev *fbd, u8 aui, u8 fec); 124 125 void (*get_fec_stats)(struct fbnic_dev *fbd, bool reset, 126 struct fbnic_fec_stats *fec_stats); 127 void (*get_pcs_stats)(struct fbnic_dev *fbd, bool reset, 128 struct fbnic_pcs_stats *pcs_stats); 129 void (*get_eth_mac_stats)(struct fbnic_dev *fbd, bool reset, 130 struct fbnic_eth_mac_stats *mac_stats); 131 void (*get_pause_stats)(struct fbnic_dev *fbd, bool reset, 132 struct fbnic_pause_stats *pause_stats); 133 void (*get_eth_ctrl_stats)(struct fbnic_dev *fbd, bool reset, 134 struct fbnic_eth_ctrl_stats *ctrl_stats); 135 void (*get_rmon_stats)(struct fbnic_dev *fbd, bool reset, 136 struct fbnic_rmon_stats *rmon_stats); 137 138 void (*link_down)(struct fbnic_dev *fbd); 139 void (*link_up)(struct fbnic_dev *fbd, bool tx_pause, bool rx_pause); 140 141 int (*get_sensor)(struct fbnic_dev *fbd, int id, long *val); 142 }; 143 144 int fbnic_mac_init(struct fbnic_dev *fbd); 145 void fbnic_mac_get_fw_settings(struct fbnic_dev *fbd, u8 *aui, u8 *fec); 146 int fbnic_mac_ps_protect_to_config(struct fbnic_dev *fbd, u16 timeout); 147 void fbnic_mac_ps_protect_handler(struct fbnic_dev *fbd); 148 bool fbnic_mac_check_tx_pause(struct fbnic_dev *fbd); 149 #endif /* _FBNIC_MAC_H_ */ 150