1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2020 Marvell International Ltd.
4  */
5 
6 #ifndef __OCTEON_ETH_H__
7 #define __OCTEON_ETH_H__
8 
9 #include <phy.h>
10 #include <miiphy.h>
11 
12 #include <mach/cvmx-helper.h>
13 #include <mach/cvmx-helper-board.h>
14 #include <mach/octeon_fdt.h>
15 
16 struct eth_device;
17 
18 /** Ethernet device private data structure for octeon ethernet */
19 struct octeon_eth_info {
20 	u64 link_state;
21 	u32 port;		   /** ipd port */
22 	u32 interface;		   /** Port interface */
23 	u32 index;		   /** port index on interface */
24 	int node;		   /** OCX node number */
25 	u32 initted_flag;	   /** 0 if port not initialized */
26 	struct mii_dev *mii_bus;   /** MII bus for PHY */
27 	struct phy_device *phydev; /** PHY device */
28 	struct eth_device *ethdev; /** Eth device this priv is part of */
29 	int mii_addr;
30 	int phy_fdt_offset;		    /** Offset of PHY info in device tree */
31 	int fdt_offset;			    /** Offset of Eth interface in DT */
32 	int phy_offset;			    /** Offset of PHY dev in device tree */
33 	enum cvmx_phy_type phy_device_type; /** Type of PHY */
34 	/* current link status, use to reconfigure on status changes */
35 	u64 packets_sent;
36 	u64 packets_received;
37 	u32 link_speed : 2;
38 	u32 link_duplex : 1;
39 	u32 link_status : 1;
40 	u32 loopback : 1;
41 	u32 enabled : 1;
42 	u32 is_c45 : 1;		    /** Set if we need to use clause 45 */
43 	u32 vitesse_sfp_config : 1; /** Need Vitesse SFP config */
44 	u32 ti_gpio_config : 1;	    /** Need TI GPIO config */
45 	u32 bgx_mac_set : 1;	    /** Has the BGX MAC been set already */
46 	u64 last_bgx_mac;	    /** Last BGX MAC address set */
47 	u64 gmx_base;		    /** Base address to access GMX CSRs */
48 	bool mod_abs;		    /** True if module is absent */
49 
50 	/**
51 	 * User defined function to check if a SFP+ module is absent or not.
52 	 *
53 	 * @param	dev	Ethernet device
54 	 * @param	data	User supplied data
55 	 */
56 	int (*check_mod_abs)(struct eth_device *dev, void *data);
57 
58 	/** User supplied data for check_mod_abs */
59 	void *mod_abs_data;
60 	/**
61 	 * Called to check the status of a port.  This is used for some
62 	 * Vitesse and Inphi phys to probe the sFP adapter.
63 	 */
64 	int (*phy_port_check)(struct phy_device *dev);
65 	/**
66 	 * Called whenever mod_abs changes state
67 	 *
68 	 * @param	dev	Ethernet device
69 	 * @param	mod_abs	True if module is absent
70 	 *
71 	 * @return	0 for success, otherwise error
72 	 */
73 	int (*mod_abs_changed)(struct eth_device *dev, bool mod_abs);
74 	/** SDK phy information data structure */
75 	cvmx_phy_info_t phy_info;
76 #ifdef CONFIG_OCTEON_SFP
77 	/** Information about connected SFP/SFP+/SFP28/QSFP+/QSFP28 module */
78 	struct octeon_sfp_info sfp;
79 #endif
80 };
81 
82 /**
83  * Searches for an ethernet device based on interface and index.
84  *
85  * @param interface - interface number to search for
86  * @param index - index to search for
87  *
88  * @returns pointer to ethernet device or NULL if not found.
89  */
90 struct eth_device *octeon_find_eth_by_interface_index(int interface, int index);
91 
92 /**
93  * User-defined function called when the link state changes
94  *
95  * @param[in]	dev		Ethernet device
96  * @param	link_state	new link state
97  *
98  * NOTE: This is defined as a weak function.
99  */
100 void board_net_set_link(struct eth_device *dev, cvmx_helper_link_info_t link_state);
101 
102 /**
103  * Registers a function to be called when the link goes down.  The function is
104  * often used for things like reading the SFP+ EEPROM.
105  *
106  * @param	dev		Ethernet device
107  * @param	phy_port_check	Function to call
108  */
109 void octeon_eth_register_phy_port_check(struct eth_device *dev,
110 					int (*phy_port_check)(struct phy_device *dev));
111 
112 /**
113  * This weak function is called after the phy driver is connected but before
114  * it is initialized.
115  *
116  * @param	dev	Ethernet device for phy
117  *
118  * @return	0 to continue, or -1 for error to stop setting up the phy
119  */
120 int octeon_eth_board_post_setup_phy(struct eth_device *dev);
121 
122 /**
123  * Registers a function to be called whenever a mod_abs change is detected.
124  *
125  * @param	dev		Ethernet device
126  * @param	mod_abs_changed	Function to be called
127  */
128 void octeon_eth_register_mod_abs_changed(struct eth_device *dev,
129 					 int (*mod_abs_changed)(struct eth_device *dev,
130 								bool mod_abs));
131 
132 /**
133  * Checks for state changes with the link state or module state
134  *
135  * @param	dev	Ethernet device to check
136  *
137  * NOTE: If the module state is changed then the module callback is called.
138  */
139 void octeon_phy_port_check(struct eth_device *dev);
140 
141 #endif /* __OCTEON_ETH_H__ */
142