sas_phy.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 =
  33. container_of(work, struct asd_sas_event, work);
  34. struct asd_sas_phy *phy = ev->phy;
  35. sas_begin_event(PHYE_LOSS_OF_SIGNAL, &phy->ha->event_lock,
  36. &phy->phy_events_pending);
  37. phy->error = 0;
  38. sas_deform_port(phy, 1);
  39. }
  40. static void sas_phye_oob_done(struct work_struct *work)
  41. {
  42. struct asd_sas_event *ev =
  43. container_of(work, struct asd_sas_event, work);
  44. struct asd_sas_phy *phy = ev->phy;
  45. sas_begin_event(PHYE_OOB_DONE, &phy->ha->event_lock,
  46. &phy->phy_events_pending);
  47. phy->error = 0;
  48. }
  49. static void sas_phye_oob_error(struct work_struct *work)
  50. {
  51. struct asd_sas_event *ev =
  52. container_of(work, struct asd_sas_event, work);
  53. struct asd_sas_phy *phy = ev->phy;
  54. struct sas_ha_struct *sas_ha = phy->ha;
  55. struct asd_sas_port *port = phy->port;
  56. struct sas_internal *i =
  57. to_sas_internal(sas_ha->core.shost->transportt);
  58. sas_begin_event(PHYE_OOB_ERROR, &phy->ha->event_lock,
  59. &phy->phy_events_pending);
  60. sas_deform_port(phy, 1);
  61. if (!port && phy->enabled && i->dft->lldd_control_phy) {
  62. phy->error++;
  63. switch (phy->error) {
  64. case 1:
  65. case 2:
  66. i->dft->lldd_control_phy(phy, PHY_FUNC_HARD_RESET,
  67. NULL);
  68. break;
  69. case 3:
  70. default:
  71. phy->error = 0;
  72. phy->enabled = 0;
  73. i->dft->lldd_control_phy(phy, PHY_FUNC_DISABLE, NULL);
  74. break;
  75. }
  76. }
  77. }
  78. static void sas_phye_spinup_hold(struct work_struct *work)
  79. {
  80. struct asd_sas_event *ev =
  81. container_of(work, struct asd_sas_event, work);
  82. struct asd_sas_phy *phy = ev->phy;
  83. struct sas_ha_struct *sas_ha = phy->ha;
  84. struct sas_internal *i =
  85. to_sas_internal(sas_ha->core.shost->transportt);
  86. sas_begin_event(PHYE_SPINUP_HOLD, &phy->ha->event_lock,
  87. &phy->phy_events_pending);
  88. phy->error = 0;
  89. i->dft->lldd_control_phy(phy, PHY_FUNC_RELEASE_SPINUP_HOLD, NULL);
  90. }
  91. /* ---------- Phy class registration ---------- */
  92. int sas_register_phys(struct sas_ha_struct *sas_ha)
  93. {
  94. int i;
  95. static const work_func_t sas_phy_event_fns[PHY_NUM_EVENTS] = {
  96. [PHYE_LOSS_OF_SIGNAL] = sas_phye_loss_of_signal,
  97. [PHYE_OOB_DONE] = sas_phye_oob_done,
  98. [PHYE_OOB_ERROR] = sas_phye_oob_error,
  99. [PHYE_SPINUP_HOLD] = sas_phye_spinup_hold,
  100. };
  101. static const work_func_t sas_port_event_fns[PORT_NUM_EVENTS] = {
  102. [PORTE_BYTES_DMAED] = sas_porte_bytes_dmaed,
  103. [PORTE_BROADCAST_RCVD] = sas_porte_broadcast_rcvd,
  104. [PORTE_LINK_RESET_ERR] = sas_porte_link_reset_err,
  105. [PORTE_TIMER_EVENT] = sas_porte_timer_event,
  106. [PORTE_HARD_RESET] = sas_porte_hard_reset,
  107. };
  108. /* Now register the phys. */
  109. for (i = 0; i < sas_ha->num_phys; i++) {
  110. int k;
  111. struct asd_sas_phy *phy = sas_ha->sas_phy[i];
  112. phy->error = 0;
  113. INIT_LIST_HEAD(&phy->port_phy_el);
  114. for (k = 0; k < PORT_NUM_EVENTS; k++) {
  115. INIT_WORK(&phy->port_events[k].work,
  116. sas_port_event_fns[k]);
  117. phy->port_events[k].phy = phy;
  118. }
  119. for (k = 0; k < PHY_NUM_EVENTS; k++) {
  120. INIT_WORK(&phy->phy_events[k].work,
  121. sas_phy_event_fns[k]);
  122. phy->phy_events[k].phy = phy;
  123. }
  124. phy->port = NULL;
  125. phy->ha = sas_ha;
  126. spin_lock_init(&phy->frame_rcvd_lock);
  127. spin_lock_init(&phy->sas_prim_lock);
  128. phy->frame_rcvd_size = 0;
  129. phy->phy = sas_phy_alloc(&sas_ha->core.shost->shost_gendev,
  130. i);
  131. if (!phy->phy)
  132. return -ENOMEM;
  133. phy->phy->identify.initiator_port_protocols =
  134. phy->iproto;
  135. phy->phy->identify.target_port_protocols = phy->tproto;
  136. phy->phy->identify.sas_address = SAS_ADDR(sas_ha->sas_addr);
  137. phy->phy->identify.phy_identifier = i;
  138. phy->phy->minimum_linkrate_hw = SAS_LINK_RATE_UNKNOWN;
  139. phy->phy->maximum_linkrate_hw = SAS_LINK_RATE_UNKNOWN;
  140. phy->phy->minimum_linkrate = SAS_LINK_RATE_UNKNOWN;
  141. phy->phy->maximum_linkrate = SAS_LINK_RATE_UNKNOWN;
  142. phy->phy->negotiated_linkrate = SAS_LINK_RATE_UNKNOWN;
  143. sas_phy_add(phy->phy);
  144. }
  145. return 0;
  146. }