phy.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * This file is provided under a dual BSD/GPLv2 license. When using or
  3. * redistributing this file, you may do so under either license.
  4. *
  5. * GPL LICENSE SUMMARY
  6. *
  7. * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of version 2 of the GNU General Public License as
  11. * published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  21. * The full GNU General Public License is included in this distribution
  22. * in the file called LICENSE.GPL.
  23. *
  24. * BSD LICENSE
  25. *
  26. * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
  27. * All rights reserved.
  28. *
  29. * Redistribution and use in source and binary forms, with or without
  30. * modification, are permitted provided that the following conditions
  31. * are met:
  32. *
  33. * * Redistributions of source code must retain the above copyright
  34. * notice, this list of conditions and the following disclaimer.
  35. * * Redistributions in binary form must reproduce the above copyright
  36. * notice, this list of conditions and the following disclaimer in
  37. * the documentation and/or other materials provided with the
  38. * distribution.
  39. * * Neither the name of Intel Corporation nor the names of its
  40. * contributors may be used to endorse or promote products derived
  41. * from this software without specific prior written permission.
  42. *
  43. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  44. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  45. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  46. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  47. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  48. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  49. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  50. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  51. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  52. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  53. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  54. */
  55. #include "isci.h"
  56. #include "phy.h"
  57. #include "scic_port.h"
  58. #include "scic_config_parameters.h"
  59. struct scic_sds_phy;
  60. extern enum sci_status scic_sds_phy_start(struct scic_sds_phy *sci_phy);
  61. extern enum sci_status scic_sds_phy_stop(struct scic_sds_phy *sci_phy);
  62. /**
  63. * isci_phy_init() - This function is called by the probe function to
  64. * initialize the phy objects. This func assumes that the isci_port objects
  65. * associated with the SCU have been initialized.
  66. * @isci_phy: This parameter specifies the isci_phy object to initialize
  67. * @isci_host: This parameter specifies the parent SCU host object for this
  68. * isci_phy
  69. * @index: This parameter specifies which SCU phy associates with this
  70. * isci_phy. Generally, SCU phy 0 relates isci_phy 0, etc.
  71. *
  72. */
  73. void isci_phy_init(
  74. struct isci_phy *phy,
  75. struct isci_host *isci_host,
  76. int index)
  77. {
  78. struct scic_sds_controller *scic = isci_host->core_controller;
  79. struct scic_sds_phy *scic_phy;
  80. union scic_oem_parameters oem;
  81. enum sci_status status = SCI_SUCCESS;
  82. u64 sas_addr;
  83. /*--------------- SCU_Phy Initialization Stuff -----------------------*/
  84. status = scic_controller_get_phy_handle(scic, index, &scic_phy);
  85. if (status == SCI_SUCCESS) {
  86. sci_object_set_association(scic_phy, (void *)phy);
  87. phy->sci_phy_handle = scic_phy;
  88. } else
  89. dev_err(&isci_host->pdev->dev,
  90. "failed scic_controller_get_phy_handle\n");
  91. scic_oem_parameters_get(scic, &oem);
  92. sas_addr = oem.sds1.phys[index].sas_address.high;
  93. sas_addr <<= 32;
  94. sas_addr |= oem.sds1.phys[index].sas_address.low;
  95. swab64s(&sas_addr);
  96. memcpy(phy->sas_addr, &sas_addr, sizeof(sas_addr));
  97. phy->isci_port = NULL;
  98. phy->sas_phy.enabled = 0;
  99. phy->sas_phy.id = index;
  100. phy->sas_phy.sas_addr = &phy->sas_addr[0];
  101. phy->sas_phy.frame_rcvd = (u8 *)&phy->frame_rcvd;
  102. phy->sas_phy.ha = &isci_host->sas_ha;
  103. phy->sas_phy.lldd_phy = phy;
  104. phy->sas_phy.enabled = 1;
  105. phy->sas_phy.class = SAS;
  106. phy->sas_phy.iproto = SAS_PROTOCOL_ALL;
  107. phy->sas_phy.tproto = 0;
  108. phy->sas_phy.type = PHY_TYPE_PHYSICAL;
  109. phy->sas_phy.role = PHY_ROLE_INITIATOR;
  110. phy->sas_phy.oob_mode = OOB_NOT_CONNECTED;
  111. phy->sas_phy.linkrate = SAS_LINK_RATE_UNKNOWN;
  112. memset((u8 *)&phy->frame_rcvd, 0, sizeof(phy->frame_rcvd));
  113. }
  114. /**
  115. * isci_phy_control() - This function is one of the SAS Domain Template
  116. * functions. This is a phy management function.
  117. * @phy: This parameter specifies the sphy being controlled.
  118. * @func: This parameter specifies the phy control function being invoked.
  119. * @buf: This parameter is specific to the phy function being invoked.
  120. *
  121. * status, zero indicates success.
  122. */
  123. int isci_phy_control(struct asd_sas_phy *sas_phy,
  124. enum phy_func func,
  125. void *buf)
  126. {
  127. int ret = 0;
  128. struct isci_phy *iphy = sas_phy->lldd_phy;
  129. struct isci_port *iport = iphy->isci_port;
  130. struct isci_host *ihost = sas_phy->ha->lldd_ha;
  131. unsigned long flags;
  132. dev_dbg(&ihost->pdev->dev,
  133. "%s: phy %p; func %d; buf %p; isci phy %p, port %p\n",
  134. __func__, sas_phy, func, buf, iphy, iport);
  135. switch (func) {
  136. case PHY_FUNC_DISABLE:
  137. spin_lock_irqsave(&ihost->scic_lock, flags);
  138. scic_sds_phy_stop(iphy->sci_phy_handle);
  139. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  140. break;
  141. case PHY_FUNC_LINK_RESET:
  142. spin_lock_irqsave(&ihost->scic_lock, flags);
  143. scic_sds_phy_stop(iphy->sci_phy_handle);
  144. scic_sds_phy_start(iphy->sci_phy_handle);
  145. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  146. break;
  147. case PHY_FUNC_HARD_RESET:
  148. if (!iport)
  149. return -ENODEV;
  150. /* Perform the port reset. */
  151. ret = isci_port_perform_hard_reset(iport, iphy);
  152. break;
  153. default:
  154. dev_dbg(&ihost->pdev->dev,
  155. "%s: phy %p; func %d NOT IMPLEMENTED!\n",
  156. __func__, sas_phy, func);
  157. ret = -ENOSYS;
  158. break;
  159. }
  160. return ret;
  161. }