octeon_eth.h 4.3 KB

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