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