xref: /linux/drivers/net/ethernet/meta/fbnic/fbnic_mac.h (revision 3fd6c59042dbba50391e30862beac979491145fe)
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 	FBNIC_FEC_AUTO		= 4,
29 };
30 
31 #define FBNIC_FEC_MODE_MASK	(FBNIC_FEC_AUTO - 1)
32 
33 /* Treat the link modes as a set of modulation/lanes bitmask:
34  * Bit 0: Lane Count, 0 = R1, 1 = R2
35  * Bit 1: Modulation, 0 = NRZ, 1 = PAM4
36  * Bit 2: Retrieve link mode from FW
37  */
38 enum {
39 	FBNIC_LINK_25R1		= 0,
40 	FBNIC_LINK_50R2		= 1,
41 	FBNIC_LINK_50R1		= 2,
42 	FBNIC_LINK_100R2	= 3,
43 	FBNIC_LINK_AUTO		= 4,
44 };
45 
46 #define FBNIC_LINK_MODE_R2	(FBNIC_LINK_50R2)
47 #define FBNIC_LINK_MODE_PAM4	(FBNIC_LINK_50R1)
48 #define FBNIC_LINK_MODE_MASK	(FBNIC_LINK_AUTO - 1)
49 
50 enum fbnic_sensor_id {
51 	FBNIC_SENSOR_TEMP,		/* Temp in millidegrees Centigrade */
52 	FBNIC_SENSOR_VOLTAGE,		/* Voltage in millivolts */
53 };
54 
55 /* This structure defines the interface hooks for the MAC. The MAC hooks
56  * will be configured as a const struct provided with a set of function
57  * pointers.
58  *
59  * void (*init_regs)(struct fbnic_dev *fbd);
60  *	Initialize MAC registers to enable Tx/Rx paths and FIFOs.
61  *
62  * void (*pcs_enable)(struct fbnic_dev *fbd);
63  *	Configure and enable PCS to enable link if not already enabled
64  * void (*pcs_disable)(struct fbnic_dev *fbd);
65  *	Shutdown the link if we are the only consumer of it.
66  * bool (*pcs_get_link)(struct fbnic_dev *fbd);
67  *	Check PCS link status
68  * int (*pcs_get_link_event)(struct fbnic_dev *fbd)
69  *	Get the current link event status, reports true if link has
70  *	changed to either FBNIC_LINK_EVENT_DOWN or FBNIC_LINK_EVENT_UP
71  *
72  * void (*link_down)(struct fbnic_dev *fbd);
73  *	Configure MAC for link down event
74  * void (*link_up)(struct fbnic_dev *fbd, bool tx_pause, bool rx_pause);
75  *	Configure MAC for link up event;
76  *
77  */
78 struct fbnic_mac {
79 	void (*init_regs)(struct fbnic_dev *fbd);
80 
81 	int (*pcs_enable)(struct fbnic_dev *fbd);
82 	void (*pcs_disable)(struct fbnic_dev *fbd);
83 	bool (*pcs_get_link)(struct fbnic_dev *fbd);
84 	int (*pcs_get_link_event)(struct fbnic_dev *fbd);
85 
86 	void (*get_eth_mac_stats)(struct fbnic_dev *fbd, bool reset,
87 				  struct fbnic_eth_mac_stats *mac_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 #endif /* _FBNIC_MAC_H_ */
97