mdio_10g.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2006-2008 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. #include "boards.h"
  17. static inline unsigned efx_mdio_id_rev(u32 id) { return id & 0xf; }
  18. static inline unsigned efx_mdio_id_model(u32 id) { return (id >> 4) & 0x3f; }
  19. extern unsigned efx_mdio_id_oui(u32 id);
  20. static inline int efx_mdio_read(struct efx_nic *efx, int devad, int addr)
  21. {
  22. return efx->mdio.mdio_read(efx->net_dev, efx->mdio.prtad, devad, addr);
  23. }
  24. static inline void
  25. efx_mdio_write(struct efx_nic *efx, int devad, int addr, int value)
  26. {
  27. efx->mdio.mdio_write(efx->net_dev, efx->mdio.prtad, devad, addr, value);
  28. }
  29. static inline u32 efx_mdio_read_id(struct efx_nic *efx, int mmd)
  30. {
  31. u16 id_low = efx_mdio_read(efx, mmd, MDIO_DEVID2);
  32. u16 id_hi = efx_mdio_read(efx, mmd, MDIO_DEVID1);
  33. return (id_hi << 16) | (id_low);
  34. }
  35. static inline bool efx_mdio_phyxgxs_lane_sync(struct efx_nic *efx)
  36. {
  37. int i, lane_status;
  38. bool sync;
  39. for (i = 0; i < 2; ++i)
  40. lane_status = efx_mdio_read(efx, MDIO_MMD_PHYXS,
  41. MDIO_PHYXS_LNSTAT);
  42. sync = !!(lane_status & MDIO_PHYXS_LNSTAT_ALIGN);
  43. if (!sync)
  44. EFX_LOG(efx, "XGXS lane status: %x\n", lane_status);
  45. return sync;
  46. }
  47. extern 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. extern int efx_mdio_reset_mmd(struct efx_nic *efx, int mmd,
  55. int spins, int spintime);
  56. /* As efx_mdio_check_mmd but for multiple MMDs */
  57. int efx_mdio_check_mmds(struct efx_nic *efx,
  58. unsigned int mmd_mask, unsigned int fatal_mask);
  59. /* Check the link status of specified mmds in bit mask */
  60. extern bool efx_mdio_links_ok(struct efx_nic *efx, unsigned int mmd_mask);
  61. /* Generic transmit disable support though PMAPMD */
  62. extern void efx_mdio_transmit_disable(struct efx_nic *efx);
  63. /* Generic part of reconfigure: set/clear loopback bits */
  64. extern void efx_mdio_phy_reconfigure(struct efx_nic *efx);
  65. /* Set the power state of the specified MMDs */
  66. extern void efx_mdio_set_mmds_lpower(struct efx_nic *efx,
  67. int low_power, unsigned int mmd_mask);
  68. /* Set (some of) the PHY settings over MDIO */
  69. extern int efx_mdio_set_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd);
  70. /* Get pause parameters from AN if available (otherwise return
  71. * requested pause parameters)
  72. */
  73. enum efx_fc_type efx_mdio_get_pause(struct efx_nic *efx);
  74. /* Wait for specified MMDs to exit reset within a timeout */
  75. extern int efx_mdio_wait_reset_mmds(struct efx_nic *efx,
  76. unsigned int mmd_mask);
  77. /* Set or clear flag, debouncing */
  78. static inline void
  79. efx_mdio_set_flag(struct efx_nic *efx, int devad, int addr,
  80. int mask, bool state)
  81. {
  82. mdio_set_flag(&efx->mdio, efx->mdio.prtad, devad, addr, mask, state);
  83. }
  84. #endif /* EFX_MDIO_10G_H */