xref: /linux/drivers/net/ethernet/meta/fbnic/fbnic_mac.h (revision 8be4d31cb8aaeea27bde4b7ddb26e28a89062ebf) !
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 #define FBNIC_MAX_JUMBO_FRAME_SIZE	9742
12 
13 enum {
14 	FBNIC_LINK_EVENT_NONE	= 0,
15 	FBNIC_LINK_EVENT_UP	= 1,
16 	FBNIC_LINK_EVENT_DOWN	= 2,
17 };
18 
19 /* Treat the FEC bits as a bitmask laid out as follows:
20  * Bit 0: RS Enabled
21  * Bit 1: BASER(Firecode) Enabled
22  * Bit 2: Retrieve FEC from FW
23  */
24 enum {
25 	FBNIC_FEC_OFF		= 0,
26 	FBNIC_FEC_RS		= 1,
27 	FBNIC_FEC_BASER		= 2,
28 };
29 
30 /* Treat the AUI modes as a modulation/lanes bitmask:
31  * Bit 0: Lane Count, 0 = R1, 1 = R2
32  * Bit 1: Modulation, 0 = NRZ, 1 = PAM4
33  * Bit 2: Unknown Modulation/Lane Configuration
34  */
35 enum {
36 	FBNIC_AUI_25GAUI	= 0,	/* 25.7812GBd	25.78125 * 1 */
37 	FBNIC_AUI_LAUI2		= 1,	/* 51.5625GBd	25.78128 * 2 */
38 	FBNIC_AUI_50GAUI1	= 2,	/* 53.125GBd	53.125   * 1 */
39 	FBNIC_AUI_100GAUI2	= 3,	/* 106.25GBd	53.125   * 2 */
40 	FBNIC_AUI_UNKNOWN	= 4,
41 };
42 
43 #define FBNIC_AUI_MODE_R2	(FBNIC_AUI_LAUI2)
44 #define FBNIC_AUI_MODE_PAM4	(FBNIC_AUI_50GAUI1)
45 
46 enum fbnic_sensor_id {
47 	FBNIC_SENSOR_TEMP,		/* Temp in millidegrees Centigrade */
48 	FBNIC_SENSOR_VOLTAGE,		/* Voltage in millivolts */
49 };
50 
51 /* This structure defines the interface hooks for the MAC. The MAC hooks
52  * will be configured as a const struct provided with a set of function
53  * pointers.
54  *
55  * void (*init_regs)(struct fbnic_dev *fbd);
56  *	Initialize MAC registers to enable Tx/Rx paths and FIFOs.
57  *
58  * void (*pcs_enable)(struct fbnic_dev *fbd);
59  *	Configure and enable PCS to enable link if not already enabled
60  * void (*pcs_disable)(struct fbnic_dev *fbd);
61  *	Shutdown the link if we are the only consumer of it.
62  * bool (*pcs_get_link)(struct fbnic_dev *fbd);
63  *	Check PCS link status
64  * int (*pcs_get_link_event)(struct fbnic_dev *fbd)
65  *	Get the current link event status, reports true if link has
66  *	changed to either FBNIC_LINK_EVENT_DOWN or FBNIC_LINK_EVENT_UP
67  *
68  * void (*link_down)(struct fbnic_dev *fbd);
69  *	Configure MAC for link down event
70  * void (*link_up)(struct fbnic_dev *fbd, bool tx_pause, bool rx_pause);
71  *	Configure MAC for link up event;
72  *
73  */
74 struct fbnic_mac {
75 	void (*init_regs)(struct fbnic_dev *fbd);
76 
77 	int (*pcs_enable)(struct fbnic_dev *fbd);
78 	void (*pcs_disable)(struct fbnic_dev *fbd);
79 	bool (*pcs_get_link)(struct fbnic_dev *fbd);
80 	int (*pcs_get_link_event)(struct fbnic_dev *fbd);
81 
82 	void (*get_eth_mac_stats)(struct fbnic_dev *fbd, bool reset,
83 				  struct fbnic_eth_mac_stats *mac_stats);
84 	void (*get_eth_ctrl_stats)(struct fbnic_dev *fbd, bool reset,
85 				   struct fbnic_eth_ctrl_stats *ctrl_stats);
86 	void (*get_rmon_stats)(struct fbnic_dev *fbd, bool reset,
87 			       struct fbnic_rmon_stats *rmon_stats);
88 
89 	void (*link_down)(struct fbnic_dev *fbd);
90 	void (*link_up)(struct fbnic_dev *fbd, bool tx_pause, bool rx_pause);
91 
92 	int (*get_sensor)(struct fbnic_dev *fbd, int id, long *val);
93 };
94 
95 int fbnic_mac_init(struct fbnic_dev *fbd);
96 void fbnic_mac_get_fw_settings(struct fbnic_dev *fbd, u8 *aui, u8 *fec);
97 #endif /* _FBNIC_MAC_H_ */
98