734-v5.5-net-sfp-move-module-insert-reporting-out-of-probe.patch 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. From 57cbf7453551db1df619b79410d79fc418d862d5 Mon Sep 17 00:00:00 2001
  2. From: Russell King <[email protected]>
  3. Date: Tue, 5 Nov 2019 13:00:45 +0000
  4. Subject: [PATCH 632/660] net: sfp: move module insert reporting out of probe
  5. Move the module insertion reporting out of the probe handling, but
  6. after we have detected that the upstream has attached (since that is
  7. whom we are reporting insertion to.)
  8. Only report module removal if we had previously reported a module
  9. insertion.
  10. This gives cleaner semantics, and means we can probe the module before
  11. we have an upstream attached.
  12. Signed-off-by: Russell King <[email protected]>
  13. ---
  14. drivers/net/phy/sfp.c | 58 +++++++++++++++++++++++++++++--------------
  15. 1 file changed, 40 insertions(+), 18 deletions(-)
  16. --- a/drivers/net/phy/sfp.c
  17. +++ b/drivers/net/phy/sfp.c
  18. @@ -45,11 +45,12 @@ enum {
  19. SFP_E_TIMEOUT,
  20. SFP_MOD_EMPTY = 0,
  21. + SFP_MOD_ERROR,
  22. SFP_MOD_PROBE,
  23. + SFP_MOD_WAITDEV,
  24. SFP_MOD_HPOWER,
  25. SFP_MOD_WAITPWR,
  26. SFP_MOD_PRESENT,
  27. - SFP_MOD_ERROR,
  28. SFP_DEV_DETACHED = 0,
  29. SFP_DEV_DOWN,
  30. @@ -68,11 +69,12 @@ enum {
  31. static const char * const mod_state_strings[] = {
  32. [SFP_MOD_EMPTY] = "empty",
  33. + [SFP_MOD_ERROR] = "error",
  34. [SFP_MOD_PROBE] = "probe",
  35. + [SFP_MOD_WAITDEV] = "waitdev",
  36. [SFP_MOD_HPOWER] = "hpower",
  37. [SFP_MOD_WAITPWR] = "waitpwr",
  38. [SFP_MOD_PRESENT] = "present",
  39. - [SFP_MOD_ERROR] = "error",
  40. };
  41. static const char *mod_state_to_str(unsigned short mod_state)
  42. @@ -1479,16 +1481,13 @@ static int sfp_sm_mod_probe(struct sfp *
  43. if (ret < 0)
  44. return ret;
  45. - ret = sfp_module_insert(sfp->sfp_bus, &sfp->id);
  46. - if (ret < 0)
  47. - return ret;
  48. -
  49. return 0;
  50. }
  51. static void sfp_sm_mod_remove(struct sfp *sfp)
  52. {
  53. - sfp_module_remove(sfp->sfp_bus);
  54. + if (sfp->sm_mod_state > SFP_MOD_WAITDEV)
  55. + sfp_module_remove(sfp->sfp_bus);
  56. sfp_hwmon_remove(sfp);
  57. @@ -1539,12 +1538,12 @@ static void sfp_sm_module(struct sfp *sf
  58. }
  59. /* Handle device detach globally */
  60. - if (sfp->sm_dev_state < SFP_DEV_DOWN) {
  61. + if (sfp->sm_dev_state < SFP_DEV_DOWN &&
  62. + sfp->sm_mod_state > SFP_MOD_WAITDEV) {
  63. if (sfp->module_power_mW > 1000 &&
  64. sfp->sm_mod_state > SFP_MOD_HPOWER)
  65. sfp_sm_mod_hpower(sfp, false);
  66. - if (sfp->sm_mod_state > SFP_MOD_EMPTY)
  67. - sfp_sm_mod_next(sfp, SFP_MOD_EMPTY, 0);
  68. + sfp_sm_mod_next(sfp, SFP_MOD_WAITDEV, 0);
  69. return;
  70. }
  71. @@ -1555,6 +1554,7 @@ static void sfp_sm_module(struct sfp *sf
  72. break;
  73. case SFP_MOD_PROBE:
  74. + /* Wait for T_PROBE_INIT to time out */
  75. if (event != SFP_E_TIMEOUT)
  76. break;
  77. @@ -1568,6 +1568,20 @@ static void sfp_sm_module(struct sfp *sf
  78. break;
  79. }
  80. + sfp_sm_mod_next(sfp, SFP_MOD_WAITDEV, 0);
  81. + /* fall through */
  82. + case SFP_MOD_WAITDEV:
  83. + /* Ensure that the device is attached before proceeding */
  84. + if (sfp->sm_dev_state < SFP_DEV_DOWN)
  85. + break;
  86. +
  87. + /* Report the module insertion to the upstream device */
  88. + err = sfp_module_insert(sfp->sfp_bus, &sfp->id);
  89. + if (err < 0) {
  90. + sfp_sm_mod_next(sfp, SFP_MOD_ERROR, 0);
  91. + break;
  92. + }
  93. +
  94. /* If this is a power level 1 module, we are done */
  95. if (sfp->module_power_mW <= 1000)
  96. goto insert;
  97. @@ -1577,12 +1591,17 @@ static void sfp_sm_module(struct sfp *sf
  98. case SFP_MOD_HPOWER:
  99. /* Enable high power mode */
  100. err = sfp_sm_mod_hpower(sfp, true);
  101. - if (err == 0)
  102. - sfp_sm_mod_next(sfp, SFP_MOD_WAITPWR, T_HPOWER_LEVEL);
  103. - else if (err != -EAGAIN)
  104. - sfp_sm_mod_next(sfp, SFP_MOD_ERROR, 0);
  105. - else
  106. - sfp_sm_set_timer(sfp, T_PROBE_RETRY);
  107. + if (err < 0) {
  108. + if (err != -EAGAIN) {
  109. + sfp_module_remove(sfp->sfp_bus);
  110. + sfp_sm_mod_next(sfp, SFP_MOD_ERROR, 0);
  111. + } else {
  112. + sfp_sm_set_timer(sfp, T_PROBE_RETRY);
  113. + }
  114. + break;
  115. + }
  116. +
  117. + sfp_sm_mod_next(sfp, SFP_MOD_WAITPWR, T_HPOWER_LEVEL);
  118. break;
  119. case SFP_MOD_WAITPWR:
  120. @@ -1750,8 +1769,6 @@ static void sfp_sm_event(struct sfp *sfp
  121. static void sfp_attach(struct sfp *sfp)
  122. {
  123. sfp_sm_event(sfp, SFP_E_DEV_ATTACH);
  124. - if (sfp->state & SFP_F_PRESENT)
  125. - sfp_sm_event(sfp, SFP_E_INSERT);
  126. }
  127. static void sfp_detach(struct sfp *sfp)
  128. @@ -2001,6 +2018,11 @@ static int sfp_probe(struct platform_dev
  129. sfp->state |= SFP_F_RATE_SELECT;
  130. sfp_set_state(sfp, sfp->state);
  131. sfp_module_tx_disable(sfp);
  132. + if (sfp->state & SFP_F_PRESENT) {
  133. + rtnl_lock();
  134. + sfp_sm_event(sfp, SFP_E_INSERT);
  135. + rtnl_unlock();
  136. + }
  137. for (i = 0; i < GPIO_MAX; i++) {
  138. if (gpio_flags[i] != GPIOD_IN || !sfp->gpio[i])