phy.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 "host.h"
  57. #include "phy.h"
  58. #include "scic_port.h"
  59. #include "scic_config_parameters.h"
  60. struct scic_sds_phy;
  61. extern enum sci_status scic_sds_phy_start(struct scic_sds_phy *sci_phy);
  62. extern enum sci_status scic_sds_phy_stop(struct scic_sds_phy *sci_phy);
  63. void isci_phy_init(struct isci_phy *iphy, struct isci_host *ihost, int index)
  64. {
  65. union scic_oem_parameters oem;
  66. u64 sci_sas_addr;
  67. __be64 sas_addr;
  68. scic_oem_parameters_get(&ihost->sci, &oem);
  69. sci_sas_addr = oem.sds1.phys[index].sas_address.high;
  70. sci_sas_addr <<= 32;
  71. sci_sas_addr |= oem.sds1.phys[index].sas_address.low;
  72. sas_addr = cpu_to_be64(sci_sas_addr);
  73. memcpy(iphy->sas_addr, &sas_addr, sizeof(sas_addr));
  74. iphy->isci_port = NULL;
  75. iphy->sas_phy.enabled = 0;
  76. iphy->sas_phy.id = index;
  77. iphy->sas_phy.sas_addr = &iphy->sas_addr[0];
  78. iphy->sas_phy.frame_rcvd = (u8 *)&iphy->frame_rcvd;
  79. iphy->sas_phy.ha = &ihost->sas_ha;
  80. iphy->sas_phy.lldd_phy = iphy;
  81. iphy->sas_phy.enabled = 1;
  82. iphy->sas_phy.class = SAS;
  83. iphy->sas_phy.iproto = SAS_PROTOCOL_ALL;
  84. iphy->sas_phy.tproto = 0;
  85. iphy->sas_phy.type = PHY_TYPE_PHYSICAL;
  86. iphy->sas_phy.role = PHY_ROLE_INITIATOR;
  87. iphy->sas_phy.oob_mode = OOB_NOT_CONNECTED;
  88. iphy->sas_phy.linkrate = SAS_LINK_RATE_UNKNOWN;
  89. memset(&iphy->frame_rcvd, 0, sizeof(iphy->frame_rcvd));
  90. }
  91. /**
  92. * isci_phy_control() - This function is one of the SAS Domain Template
  93. * functions. This is a phy management function.
  94. * @phy: This parameter specifies the sphy being controlled.
  95. * @func: This parameter specifies the phy control function being invoked.
  96. * @buf: This parameter is specific to the phy function being invoked.
  97. *
  98. * status, zero indicates success.
  99. */
  100. int isci_phy_control(struct asd_sas_phy *sas_phy,
  101. enum phy_func func,
  102. void *buf)
  103. {
  104. int ret = 0;
  105. struct isci_phy *iphy = sas_phy->lldd_phy;
  106. struct isci_port *iport = iphy->isci_port;
  107. struct isci_host *ihost = sas_phy->ha->lldd_ha;
  108. unsigned long flags;
  109. dev_dbg(&ihost->pdev->dev,
  110. "%s: phy %p; func %d; buf %p; isci phy %p, port %p\n",
  111. __func__, sas_phy, func, buf, iphy, iport);
  112. switch (func) {
  113. case PHY_FUNC_DISABLE:
  114. spin_lock_irqsave(&ihost->scic_lock, flags);
  115. scic_sds_phy_stop(&iphy->sci);
  116. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  117. break;
  118. case PHY_FUNC_LINK_RESET:
  119. spin_lock_irqsave(&ihost->scic_lock, flags);
  120. scic_sds_phy_stop(&iphy->sci);
  121. scic_sds_phy_start(&iphy->sci);
  122. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  123. break;
  124. case PHY_FUNC_HARD_RESET:
  125. if (!iport)
  126. return -ENODEV;
  127. /* Perform the port reset. */
  128. ret = isci_port_perform_hard_reset(ihost, iport, iphy);
  129. break;
  130. default:
  131. dev_dbg(&ihost->pdev->dev,
  132. "%s: phy %p; func %d NOT IMPLEMENTED!\n",
  133. __func__, sas_phy, func);
  134. ret = -ENOSYS;
  135. break;
  136. }
  137. return ret;
  138. }