sas_phy.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Serial Attached SCSI (SAS) Phy class
  4. *
  5. * Copyright (C) 2005 Adaptec, Inc. All rights reserved.
  6. * Copyright (C) 2005 Luben Tuikov <[email protected]>
  7. */
  8. #include "sas_internal.h"
  9. #include <scsi/scsi_host.h>
  10. #include <scsi/scsi_transport.h>
  11. #include <scsi/scsi_transport_sas.h>
  12. #include "scsi_sas_internal.h"
  13. /* ---------- Phy events ---------- */
  14. static void sas_phye_loss_of_signal(struct work_struct *work)
  15. {
  16. struct asd_sas_event *ev = to_asd_sas_event(work);
  17. struct asd_sas_phy *phy = ev->phy;
  18. phy->error = 0;
  19. sas_deform_port(phy, 1);
  20. }
  21. static void sas_phye_oob_done(struct work_struct *work)
  22. {
  23. struct asd_sas_event *ev = to_asd_sas_event(work);
  24. struct asd_sas_phy *phy = ev->phy;
  25. phy->error = 0;
  26. }
  27. static void sas_phye_oob_error(struct work_struct *work)
  28. {
  29. struct asd_sas_event *ev = to_asd_sas_event(work);
  30. struct asd_sas_phy *phy = ev->phy;
  31. struct sas_ha_struct *sas_ha = phy->ha;
  32. struct asd_sas_port *port = phy->port;
  33. struct sas_internal *i =
  34. to_sas_internal(sas_ha->core.shost->transportt);
  35. sas_deform_port(phy, 1);
  36. if (!port && phy->enabled && i->dft->lldd_control_phy) {
  37. phy->error++;
  38. switch (phy->error) {
  39. case 1:
  40. case 2:
  41. i->dft->lldd_control_phy(phy, PHY_FUNC_HARD_RESET,
  42. NULL);
  43. break;
  44. case 3:
  45. default:
  46. phy->error = 0;
  47. phy->enabled = 0;
  48. i->dft->lldd_control_phy(phy, PHY_FUNC_DISABLE, NULL);
  49. break;
  50. }
  51. }
  52. }
  53. static void sas_phye_spinup_hold(struct work_struct *work)
  54. {
  55. struct asd_sas_event *ev = to_asd_sas_event(work);
  56. struct asd_sas_phy *phy = ev->phy;
  57. struct sas_ha_struct *sas_ha = phy->ha;
  58. struct sas_internal *i =
  59. to_sas_internal(sas_ha->core.shost->transportt);
  60. phy->error = 0;
  61. i->dft->lldd_control_phy(phy, PHY_FUNC_RELEASE_SPINUP_HOLD, NULL);
  62. }
  63. static void sas_phye_resume_timeout(struct work_struct *work)
  64. {
  65. struct asd_sas_event *ev = to_asd_sas_event(work);
  66. struct asd_sas_phy *phy = ev->phy;
  67. /* phew, lldd got the phy back in the nick of time */
  68. if (!phy->suspended) {
  69. dev_info(&phy->phy->dev, "resume timeout cancelled\n");
  70. return;
  71. }
  72. phy->error = 0;
  73. phy->suspended = 0;
  74. sas_deform_port(phy, 1);
  75. }
  76. static void sas_phye_shutdown(struct work_struct *work)
  77. {
  78. struct asd_sas_event *ev = to_asd_sas_event(work);
  79. struct asd_sas_phy *phy = ev->phy;
  80. struct sas_ha_struct *sas_ha = phy->ha;
  81. struct sas_internal *i =
  82. to_sas_internal(sas_ha->core.shost->transportt);
  83. if (phy->enabled) {
  84. int ret;
  85. phy->error = 0;
  86. phy->enabled = 0;
  87. ret = i->dft->lldd_control_phy(phy, PHY_FUNC_DISABLE, NULL);
  88. if (ret)
  89. pr_notice("lldd disable phy%d returned %d\n", phy->id,
  90. ret);
  91. } else
  92. pr_notice("phy%d is not enabled, cannot shutdown\n", phy->id);
  93. phy->in_shutdown = 0;
  94. }
  95. /* ---------- Phy class registration ---------- */
  96. int sas_register_phys(struct sas_ha_struct *sas_ha)
  97. {
  98. int i;
  99. /* Now register the phys. */
  100. for (i = 0; i < sas_ha->num_phys; i++) {
  101. struct asd_sas_phy *phy = sas_ha->sas_phy[i];
  102. phy->error = 0;
  103. atomic_set(&phy->event_nr, 0);
  104. INIT_LIST_HEAD(&phy->port_phy_el);
  105. phy->port = NULL;
  106. phy->ha = sas_ha;
  107. spin_lock_init(&phy->frame_rcvd_lock);
  108. spin_lock_init(&phy->sas_prim_lock);
  109. phy->frame_rcvd_size = 0;
  110. phy->phy = sas_phy_alloc(&sas_ha->core.shost->shost_gendev, i);
  111. if (!phy->phy)
  112. return -ENOMEM;
  113. phy->phy->identify.initiator_port_protocols =
  114. phy->iproto;
  115. phy->phy->identify.target_port_protocols = phy->tproto;
  116. phy->phy->identify.sas_address = SAS_ADDR(sas_ha->sas_addr);
  117. phy->phy->identify.phy_identifier = i;
  118. phy->phy->minimum_linkrate_hw = SAS_LINK_RATE_UNKNOWN;
  119. phy->phy->maximum_linkrate_hw = SAS_LINK_RATE_UNKNOWN;
  120. phy->phy->minimum_linkrate = SAS_LINK_RATE_UNKNOWN;
  121. phy->phy->maximum_linkrate = SAS_LINK_RATE_UNKNOWN;
  122. phy->phy->negotiated_linkrate = SAS_LINK_RATE_UNKNOWN;
  123. sas_phy_add(phy->phy);
  124. }
  125. return 0;
  126. }
  127. const work_func_t sas_phy_event_fns[PHY_NUM_EVENTS] = {
  128. [PHYE_LOSS_OF_SIGNAL] = sas_phye_loss_of_signal,
  129. [PHYE_OOB_DONE] = sas_phye_oob_done,
  130. [PHYE_OOB_ERROR] = sas_phye_oob_error,
  131. [PHYE_SPINUP_HOLD] = sas_phye_spinup_hold,
  132. [PHYE_RESUME_TIMEOUT] = sas_phye_resume_timeout,
  133. [PHYE_SHUTDOWN] = sas_phye_shutdown,
  134. };