sas_phy.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * Serial Attached SCSI (SAS) Phy class
  3. *
  4. * Copyright (C) 2005 Adaptec, Inc. All rights reserved.
  5. * Copyright (C) 2005 Luben Tuikov <luben_tuikov@adaptec.com>
  6. *
  7. * This file is licensed under GPLv2.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. */
  24. #include "sas_internal.h"
  25. #include <scsi/scsi_host.h>
  26. #include <scsi/scsi_transport.h>
  27. #include <scsi/scsi_transport_sas.h>
  28. #include "../scsi_sas_internal.h"
  29. /* ---------- Phy events ---------- */
  30. static void sas_phye_loss_of_signal(struct work_struct *work)
  31. {
  32. struct asd_sas_event *ev = to_asd_sas_event(work);
  33. struct asd_sas_phy *phy = ev->phy;
  34. phy->in_shutdown = 0;
  35. phy->error = 0;
  36. sas_deform_port(phy, 1);
  37. }
  38. static void sas_phye_oob_done(struct work_struct *work)
  39. {
  40. struct asd_sas_event *ev = to_asd_sas_event(work);
  41. struct asd_sas_phy *phy = ev->phy;
  42. phy->in_shutdown = 0;
  43. phy->error = 0;
  44. }
  45. static void sas_phye_oob_error(struct work_struct *work)
  46. {
  47. struct asd_sas_event *ev = to_asd_sas_event(work);
  48. struct asd_sas_phy *phy = ev->phy;
  49. struct sas_ha_struct *sas_ha = phy->ha;
  50. struct asd_sas_port *port = phy->port;
  51. struct sas_internal *i =
  52. to_sas_internal(sas_ha->core.shost->transportt);
  53. sas_deform_port(phy, 1);
  54. if (!port && phy->enabled && i->dft->lldd_control_phy) {
  55. phy->error++;
  56. switch (phy->error) {
  57. case 1:
  58. case 2:
  59. i->dft->lldd_control_phy(phy, PHY_FUNC_HARD_RESET,
  60. NULL);
  61. break;
  62. case 3:
  63. default:
  64. phy->error = 0;
  65. phy->enabled = 0;
  66. i->dft->lldd_control_phy(phy, PHY_FUNC_DISABLE, NULL);
  67. break;
  68. }
  69. }
  70. }
  71. static void sas_phye_spinup_hold(struct work_struct *work)
  72. {
  73. struct asd_sas_event *ev = to_asd_sas_event(work);
  74. struct asd_sas_phy *phy = ev->phy;
  75. struct sas_ha_struct *sas_ha = phy->ha;
  76. struct sas_internal *i =
  77. to_sas_internal(sas_ha->core.shost->transportt);
  78. phy->error = 0;
  79. i->dft->lldd_control_phy(phy, PHY_FUNC_RELEASE_SPINUP_HOLD, NULL);
  80. }
  81. static void sas_phye_resume_timeout(struct work_struct *work)
  82. {
  83. struct asd_sas_event *ev = to_asd_sas_event(work);
  84. struct asd_sas_phy *phy = ev->phy;
  85. /* phew, lldd got the phy back in the nick of time */
  86. if (!phy->suspended) {
  87. dev_info(&phy->phy->dev, "resume timeout cancelled\n");
  88. return;
  89. }
  90. phy->error = 0;
  91. phy->suspended = 0;
  92. sas_deform_port(phy, 1);
  93. }
  94. static void sas_phye_shutdown(struct work_struct *work)
  95. {
  96. struct asd_sas_event *ev = to_asd_sas_event(work);
  97. struct asd_sas_phy *phy = ev->phy;
  98. struct sas_ha_struct *sas_ha = phy->ha;
  99. struct sas_internal *i =
  100. to_sas_internal(sas_ha->core.shost->transportt);
  101. if (phy->enabled) {
  102. int ret;
  103. phy->error = 0;
  104. phy->enabled = 0;
  105. ret = i->dft->lldd_control_phy(phy, PHY_FUNC_DISABLE, NULL);
  106. if (ret)
  107. sas_printk("lldd disable phy%02d returned %d\n",
  108. phy->id, ret);
  109. } else
  110. sas_printk("phy%02d is not enabled, cannot shutdown\n",
  111. phy->id);
  112. }
  113. /* ---------- Phy class registration ---------- */
  114. int sas_register_phys(struct sas_ha_struct *sas_ha)
  115. {
  116. int i;
  117. /* Now register the phys. */
  118. for (i = 0; i < sas_ha->num_phys; i++) {
  119. struct asd_sas_phy *phy = sas_ha->sas_phy[i];
  120. phy->error = 0;
  121. atomic_set(&phy->event_nr, 0);
  122. INIT_LIST_HEAD(&phy->port_phy_el);
  123. phy->port = NULL;
  124. phy->ha = sas_ha;
  125. spin_lock_init(&phy->frame_rcvd_lock);
  126. spin_lock_init(&phy->sas_prim_lock);
  127. phy->frame_rcvd_size = 0;
  128. phy->phy = sas_phy_alloc(&sas_ha->core.shost->shost_gendev, i);
  129. if (!phy->phy)
  130. return -ENOMEM;
  131. phy->phy->identify.initiator_port_protocols =
  132. phy->iproto;
  133. phy->phy->identify.target_port_protocols = phy->tproto;
  134. phy->phy->identify.sas_address = SAS_ADDR(sas_ha->sas_addr);
  135. phy->phy->identify.phy_identifier = i;
  136. phy->phy->minimum_linkrate_hw = SAS_LINK_RATE_UNKNOWN;
  137. phy->phy->maximum_linkrate_hw = SAS_LINK_RATE_UNKNOWN;
  138. phy->phy->minimum_linkrate = SAS_LINK_RATE_UNKNOWN;
  139. phy->phy->maximum_linkrate = SAS_LINK_RATE_UNKNOWN;
  140. phy->phy->negotiated_linkrate = SAS_LINK_RATE_UNKNOWN;
  141. sas_phy_add(phy->phy);
  142. }
  143. return 0;
  144. }
  145. const work_func_t sas_phy_event_fns[PHY_NUM_EVENTS] = {
  146. [PHYE_LOSS_OF_SIGNAL] = sas_phye_loss_of_signal,
  147. [PHYE_OOB_DONE] = sas_phye_oob_done,
  148. [PHYE_OOB_ERROR] = sas_phye_oob_error,
  149. [PHYE_SPINUP_HOLD] = sas_phye_spinup_hold,
  150. [PHYE_RESUME_TIMEOUT] = sas_phye_resume_timeout,
  151. [PHYE_SHUTDOWN] = sas_phye_shutdown,
  152. };