port.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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 <linux/workqueue.h>
  56. #include "isci.h"
  57. #include "scic_phy.h"
  58. #include "scic_sds_phy.h"
  59. #include "scic_port.h"
  60. #include "port.h"
  61. #include "request.h"
  62. static void isci_port_change_state(struct isci_port *iport, enum isci_status status)
  63. {
  64. unsigned long flags;
  65. dev_dbg(&iport->isci_host->pdev->dev,
  66. "%s: iport = %p, state = 0x%x\n",
  67. __func__, iport, status);
  68. /* XXX pointless lock */
  69. spin_lock_irqsave(&iport->state_lock, flags);
  70. iport->status = status;
  71. spin_unlock_irqrestore(&iport->state_lock, flags);
  72. }
  73. void isci_port_init(struct isci_port *iport, struct isci_host *ihost, int index)
  74. {
  75. INIT_LIST_HEAD(&iport->remote_dev_list);
  76. INIT_LIST_HEAD(&iport->domain_dev_list);
  77. spin_lock_init(&iport->state_lock);
  78. init_completion(&iport->start_complete);
  79. iport->isci_host = ihost;
  80. isci_port_change_state(iport, isci_freed);
  81. }
  82. /**
  83. * isci_port_get_state() - This function gets the status of the port object.
  84. * @isci_port: This parameter points to the isci_port object
  85. *
  86. * status of the object as a isci_status enum.
  87. */
  88. enum isci_status isci_port_get_state(
  89. struct isci_port *isci_port)
  90. {
  91. return isci_port->status;
  92. }
  93. void isci_port_bc_change_received(struct isci_host *ihost,
  94. struct scic_sds_port *sci_port,
  95. struct scic_sds_phy *sci_phy)
  96. {
  97. struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
  98. dev_dbg(&ihost->pdev->dev, "%s: iphy = %p, sas_phy = %p\n",
  99. __func__, iphy, &iphy->sas_phy);
  100. ihost->sas_ha.notify_port_event(&iphy->sas_phy, PORTE_BROADCAST_RCVD);
  101. scic_port_enable_broadcast_change_notification(sci_port);
  102. }
  103. void isci_port_link_up(struct isci_host *isci_host,
  104. struct scic_sds_port *port,
  105. struct scic_sds_phy *phy)
  106. {
  107. unsigned long flags;
  108. struct scic_port_properties properties;
  109. struct isci_phy *isci_phy = sci_phy_to_iphy(phy);
  110. struct isci_port *isci_port = sci_port_to_iport(port);
  111. unsigned long success = true;
  112. BUG_ON(isci_phy->isci_port != NULL);
  113. isci_phy->isci_port = isci_port;
  114. dev_dbg(&isci_host->pdev->dev,
  115. "%s: isci_port = %p\n",
  116. __func__, isci_port);
  117. spin_lock_irqsave(&isci_phy->sas_phy.frame_rcvd_lock, flags);
  118. isci_port_change_state(isci_phy->isci_port, isci_starting);
  119. scic_port_get_properties(port, &properties);
  120. if (phy->protocol == SCIC_SDS_PHY_PROTOCOL_SATA) {
  121. u64 attached_sas_address;
  122. isci_phy->sas_phy.oob_mode = SATA_OOB_MODE;
  123. isci_phy->sas_phy.frame_rcvd_size = sizeof(struct dev_to_host_fis);
  124. /*
  125. * For direct-attached SATA devices, the SCI core will
  126. * automagically assign a SAS address to the end device
  127. * for the purpose of creating a port. This SAS address
  128. * will not be the same as assigned to the PHY and needs
  129. * to be obtained from struct scic_port_properties properties.
  130. */
  131. attached_sas_address = properties.remote.sas_address.high;
  132. attached_sas_address <<= 32;
  133. attached_sas_address |= properties.remote.sas_address.low;
  134. swab64s(&attached_sas_address);
  135. memcpy(&isci_phy->sas_phy.attached_sas_addr,
  136. &attached_sas_address, sizeof(attached_sas_address));
  137. } else if (phy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) {
  138. isci_phy->sas_phy.oob_mode = SAS_OOB_MODE;
  139. isci_phy->sas_phy.frame_rcvd_size = sizeof(struct sas_identify_frame);
  140. /* Copy the attached SAS address from the IAF */
  141. memcpy(isci_phy->sas_phy.attached_sas_addr,
  142. isci_phy->frame_rcvd.iaf.sas_addr, SAS_ADDR_SIZE);
  143. } else {
  144. dev_err(&isci_host->pdev->dev, "%s: unkown target\n", __func__);
  145. success = false;
  146. }
  147. isci_phy->sas_phy.phy->negotiated_linkrate = sci_phy_linkrate(phy);
  148. spin_unlock_irqrestore(&isci_phy->sas_phy.frame_rcvd_lock, flags);
  149. /* Notify libsas that we have an address frame, if indeed
  150. * we've found an SSP, SMP, or STP target */
  151. if (success)
  152. isci_host->sas_ha.notify_port_event(&isci_phy->sas_phy,
  153. PORTE_BYTES_DMAED);
  154. }
  155. /**
  156. * isci_port_link_down() - This function is called by the sci core when a link
  157. * becomes inactive.
  158. * @isci_host: This parameter specifies the isci host object.
  159. * @phy: This parameter specifies the isci phy with the active link.
  160. * @port: This parameter specifies the isci port with the active link.
  161. *
  162. */
  163. void isci_port_link_down(struct isci_host *isci_host, struct isci_phy *isci_phy,
  164. struct isci_port *isci_port)
  165. {
  166. struct isci_remote_device *isci_device;
  167. dev_dbg(&isci_host->pdev->dev,
  168. "%s: isci_port = %p\n", __func__, isci_port);
  169. if (isci_port) {
  170. /* check to see if this is the last phy on this port. */
  171. if (isci_phy->sas_phy.port
  172. && isci_phy->sas_phy.port->num_phys == 1) {
  173. /* change the state for all devices on this port.
  174. * The next task sent to this device will be returned
  175. * as SAS_TASK_UNDELIVERED, and the scsi mid layer
  176. * will remove the target
  177. */
  178. list_for_each_entry(isci_device,
  179. &isci_port->remote_dev_list,
  180. node) {
  181. dev_dbg(&isci_host->pdev->dev,
  182. "%s: isci_device = %p\n",
  183. __func__, isci_device);
  184. isci_remote_device_change_state(isci_device,
  185. isci_stopping);
  186. }
  187. }
  188. isci_port_change_state(isci_port, isci_stopping);
  189. }
  190. /* Notify libsas of the borken link, this will trigger calls to our
  191. * isci_port_deformed and isci_dev_gone functions.
  192. */
  193. sas_phy_disconnected(&isci_phy->sas_phy);
  194. isci_host->sas_ha.notify_phy_event(&isci_phy->sas_phy,
  195. PHYE_LOSS_OF_SIGNAL);
  196. isci_phy->isci_port = NULL;
  197. dev_dbg(&isci_host->pdev->dev,
  198. "%s: isci_port = %p - Done\n", __func__, isci_port);
  199. }
  200. /**
  201. * isci_port_deformed() - This function is called by libsas when a port becomes
  202. * inactive.
  203. * @phy: This parameter specifies the libsas phy with the inactive port.
  204. *
  205. */
  206. void isci_port_deformed(
  207. struct asd_sas_phy *phy)
  208. {
  209. pr_debug("%s: sas_phy = %p\n", __func__, phy);
  210. }
  211. /**
  212. * isci_port_formed() - This function is called by libsas when a port becomes
  213. * active.
  214. * @phy: This parameter specifies the libsas phy with the active port.
  215. *
  216. */
  217. void isci_port_formed(
  218. struct asd_sas_phy *phy)
  219. {
  220. pr_debug("%s: sas_phy = %p, sas_port = %p\n", __func__, phy, phy->port);
  221. }
  222. /**
  223. * isci_port_ready() - This function is called by the sci core when a link
  224. * becomes ready.
  225. * @isci_host: This parameter specifies the isci host object.
  226. * @port: This parameter specifies the sci port with the active link.
  227. *
  228. */
  229. void isci_port_ready(struct isci_host *isci_host, struct isci_port *isci_port)
  230. {
  231. dev_dbg(&isci_host->pdev->dev,
  232. "%s: isci_port = %p\n", __func__, isci_port);
  233. complete_all(&isci_port->start_complete);
  234. isci_port_change_state(isci_port, isci_ready);
  235. return;
  236. }
  237. /**
  238. * isci_port_not_ready() - This function is called by the sci core when a link
  239. * is not ready. All remote devices on this link will be removed if they are
  240. * in the stopping state.
  241. * @isci_host: This parameter specifies the isci host object.
  242. * @port: This parameter specifies the sci port with the active link.
  243. *
  244. */
  245. void isci_port_not_ready(struct isci_host *isci_host, struct isci_port *isci_port)
  246. {
  247. dev_dbg(&isci_host->pdev->dev,
  248. "%s: isci_port = %p\n", __func__, isci_port);
  249. }
  250. /**
  251. * isci_port_hard_reset_complete() - This function is called by the sci core
  252. * when the hard reset complete notification has been received.
  253. * @port: This parameter specifies the sci port with the active link.
  254. * @completion_status: This parameter specifies the core status for the reset
  255. * process.
  256. *
  257. */
  258. void isci_port_hard_reset_complete(struct isci_port *isci_port,
  259. enum sci_status completion_status)
  260. {
  261. dev_dbg(&isci_port->isci_host->pdev->dev,
  262. "%s: isci_port = %p, completion_status=%x\n",
  263. __func__, isci_port, completion_status);
  264. /* Save the status of the hard reset from the port. */
  265. isci_port->hard_reset_status = completion_status;
  266. complete_all(&isci_port->hard_reset_complete);
  267. }
  268. int isci_port_perform_hard_reset(struct isci_host *ihost, struct isci_port *iport,
  269. struct isci_phy *iphy)
  270. {
  271. unsigned long flags;
  272. enum sci_status status;
  273. int ret = TMF_RESP_FUNC_COMPLETE;
  274. dev_dbg(&ihost->pdev->dev, "%s: iport = %p\n",
  275. __func__, iport);
  276. init_completion(&iport->hard_reset_complete);
  277. spin_lock_irqsave(&ihost->scic_lock, flags);
  278. #define ISCI_PORT_RESET_TIMEOUT SCIC_SDS_SIGNATURE_FIS_TIMEOUT
  279. status = scic_port_hard_reset(&iport->sci, ISCI_PORT_RESET_TIMEOUT);
  280. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  281. if (status == SCI_SUCCESS) {
  282. wait_for_completion(&iport->hard_reset_complete);
  283. dev_dbg(&ihost->pdev->dev,
  284. "%s: iport = %p; hard reset completion\n",
  285. __func__, iport);
  286. if (iport->hard_reset_status != SCI_SUCCESS)
  287. ret = TMF_RESP_FUNC_FAILED;
  288. } else {
  289. ret = TMF_RESP_FUNC_FAILED;
  290. dev_err(&ihost->pdev->dev,
  291. "%s: iport = %p; scic_port_hard_reset call"
  292. " failed 0x%x\n",
  293. __func__, iport, status);
  294. }
  295. /* If the hard reset for the port has failed, consider this
  296. * the same as link failures on all phys in the port.
  297. */
  298. if (ret != TMF_RESP_FUNC_COMPLETE) {
  299. dev_err(&ihost->pdev->dev,
  300. "%s: iport = %p; hard reset failed "
  301. "(0x%x) - sending link down to libsas for phy %p\n",
  302. __func__, iport, iport->hard_reset_status, iphy);
  303. isci_port_link_down(ihost, iphy, iport);
  304. }
  305. return ret;
  306. }
  307. void isci_port_stop_complete(struct scic_sds_controller *scic,
  308. struct scic_sds_port *sci_port,
  309. enum sci_status completion_status)
  310. {
  311. dev_dbg(&scic_to_ihost(scic)->pdev->dev, "Port stop complete\n");
  312. }