mdio_10g.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /****************************************************************************
  2. * Driver for Solarflare network controllers and boards
  3. * Copyright 2006-2011 Solarflare Communications Inc.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 as published
  7. * by the Free Software Foundation, incorporated herein by reference.
  8. */
  9. #ifndef EFX_MDIO_10G_H
  10. #define EFX_MDIO_10G_H
  11. #include <linux/mdio.h>
  12. /*
  13. * Helper functions for doing 10G MDIO as specified in IEEE 802.3 clause 45.
  14. */
  15. #include "efx.h"
  16. static inline unsigned efx_mdio_id_rev(u32 id) { return id & 0xf; }
  17. static inline unsigned efx_mdio_id_model(u32 id) { return (id >> 4) & 0x3f; }
  18. unsigned efx_mdio_id_oui(u32 id);
  19. static inline int efx_mdio_read(struct efx_nic *efx, int devad, int addr)
  20. {
  21. return efx->mdio.mdio_read(efx->net_dev, efx->mdio.prtad, devad, addr);
  22. }
  23. static inline void
  24. efx_mdio_write(struct efx_nic *efx, int devad, int addr, int value)
  25. {
  26. efx->mdio.mdio_write(efx->net_dev, efx->mdio.prtad, devad, addr, value);
  27. }
  28. static inline u32 efx_mdio_read_id(struct efx_nic *efx, int mmd)
  29. {
  30. u16 id_low = efx_mdio_read(efx, mmd, MDIO_DEVID2);
  31. u16 id_hi = efx_mdio_read(efx, mmd, MDIO_DEVID1);
  32. return (id_hi << 16) | (id_low);
  33. }
  34. static inline bool efx_mdio_phyxgxs_lane_sync(struct efx_nic *efx)
  35. {
  36. int i, lane_status;
  37. bool sync;
  38. for (i = 0; i < 2; ++i)
  39. lane_status = efx_mdio_read(efx, MDIO_MMD_PHYXS,
  40. MDIO_PHYXS_LNSTAT);
  41. sync = !!(lane_status & MDIO_PHYXS_LNSTAT_ALIGN);
  42. if (!sync)
  43. netif_dbg(efx, hw, efx->net_dev, "XGXS lane status: %x\n",
  44. lane_status);
  45. return sync;
  46. }
  47. const char *efx_mdio_mmd_name(int mmd);
  48. /*
  49. * Reset a specific MMD and wait for reset to clear.
  50. * Return number of spins left (>0) on success, -%ETIMEDOUT on failure.
  51. *
  52. * This function will sleep
  53. */
  54. int efx_mdio_reset_mmd(struct efx_nic *efx, int mmd, int spins, int spintime);
  55. /* As efx_mdio_check_mmd but for multiple MMDs */
  56. int efx_mdio_check_mmds(struct efx_nic *efx, unsigned int mmd_mask);
  57. /* Check the link status of specified mmds in bit mask */
  58. bool efx_mdio_links_ok(struct efx_nic *efx, unsigned int mmd_mask);
  59. /* Generic transmit disable support though PMAPMD */
  60. void efx_mdio_transmit_disable(struct efx_nic *efx);
  61. /* Generic part of reconfigure: set/clear loopback bits */
  62. void efx_mdio_phy_reconfigure(struct efx_nic *efx);
  63. /* Set the power state of the specified MMDs */
  64. void efx_mdio_set_mmds_lpower(struct efx_nic *efx, int low_power,
  65. unsigned int mmd_mask);
  66. /* Set (some of) the PHY settings over MDIO */
  67. int efx_mdio_set_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd);
  68. /* Push advertising flags and restart autonegotiation */
  69. void efx_mdio_an_reconfigure(struct efx_nic *efx);
  70. /* Get pause parameters from AN if available (otherwise return
  71. * requested pause parameters)
  72. */
  73. u8 efx_mdio_get_pause(struct efx_nic *efx);
  74. /* Wait for specified MMDs to exit reset within a timeout */
  75. int efx_mdio_wait_reset_mmds(struct efx_nic *efx, unsigned int mmd_mask);
  76. /* Set or clear flag, debouncing */
  77. static inline void
  78. efx_mdio_set_flag(struct efx_nic *efx, int devad, int addr,
  79. int mask, bool state)
  80. {
  81. mdio_set_flag(&efx->mdio, efx->mdio.prtad, devad, addr, mask, state);
  82. }
  83. /* Liveness self-test for MDIO PHYs */
  84. int efx_mdio_test_alive(struct efx_nic *efx);
  85. #endif /* EFX_MDIO_10G_H */