port.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. #ifndef _ISCI_PORT_H_
  56. #define _ISCI_PORT_H_
  57. #include <scsi/libsas.h>
  58. #include "isci.h"
  59. #include "sas.h"
  60. #include "phy.h"
  61. #define SCIC_SDS_DUMMY_PORT 0xFF
  62. #define PF_NOTIFY (1 << 0)
  63. #define PF_RESUME (1 << 1)
  64. struct isci_phy;
  65. struct isci_host;
  66. enum isci_status {
  67. isci_freed = 0x00,
  68. isci_starting = 0x01,
  69. isci_ready = 0x02,
  70. isci_ready_for_io = 0x03,
  71. isci_stopping = 0x04,
  72. isci_stopped = 0x05,
  73. };
  74. /**
  75. * struct isci_port - isci direct attached sas port object
  76. * @ready_exit: several states constitute 'ready'. When exiting ready we
  77. * need to take extra port-teardown actions that are
  78. * skipped when exiting to another 'ready' state.
  79. * @logical_port_index: software port index
  80. * @physical_port_index: hardware port index
  81. * @active_phy_mask: identifies phy members
  82. * @enabled_phy_mask: phy mask for the port
  83. * that are already part of the port
  84. * @reserved_tag:
  85. * @reserved_rni: reserver for port task scheduler workaround
  86. * @started_request_count: reference count for outstanding commands
  87. * @not_ready_reason: set during state transitions and notified
  88. * @timer: timeout start/stop operations
  89. */
  90. struct isci_port {
  91. struct isci_host *isci_host;
  92. struct list_head remote_dev_list;
  93. struct list_head domain_dev_list;
  94. #define IPORT_RESET_PENDING 0
  95. unsigned long state;
  96. enum sci_status hard_reset_status;
  97. struct sci_base_state_machine sm;
  98. bool ready_exit;
  99. u8 logical_port_index;
  100. u8 physical_port_index;
  101. u8 active_phy_mask;
  102. u8 enabled_phy_mask;
  103. u8 last_active_phy;
  104. u16 reserved_rni;
  105. u16 reserved_tag;
  106. u32 started_request_count;
  107. u32 assigned_device_count;
  108. u32 not_ready_reason;
  109. struct isci_phy *phy_table[SCI_MAX_PHYS];
  110. struct isci_host *owning_controller;
  111. struct sci_timer timer;
  112. struct scu_port_task_scheduler_registers __iomem *port_task_scheduler_registers;
  113. /* XXX rework: only one register, no need to replicate per-port */
  114. u32 __iomem *port_pe_configuration_register;
  115. struct scu_viit_entry __iomem *viit_registers;
  116. };
  117. enum sci_port_not_ready_reason_code {
  118. SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS,
  119. SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED,
  120. SCIC_PORT_NOT_READY_INVALID_PORT_CONFIGURATION,
  121. SCIC_PORT_NOT_READY_RECONFIGURING,
  122. SCIC_PORT_NOT_READY_REASON_CODE_MAX
  123. };
  124. struct sci_port_end_point_properties {
  125. struct sci_sas_address sas_address;
  126. struct sci_phy_proto protocols;
  127. };
  128. struct sci_port_properties {
  129. u32 index;
  130. struct sci_port_end_point_properties local;
  131. struct sci_port_end_point_properties remote;
  132. u32 phy_mask;
  133. };
  134. /**
  135. * enum sci_port_states - This enumeration depicts all the states for the
  136. * common port state machine.
  137. *
  138. *
  139. */
  140. enum sci_port_states {
  141. /**
  142. * This state indicates that the port has successfully been stopped.
  143. * In this state no new IO operations are permitted.
  144. * This state is entered from the STOPPING state.
  145. */
  146. SCI_PORT_STOPPED,
  147. /**
  148. * This state indicates that the port is in the process of stopping.
  149. * In this state no new IO operations are permitted, but existing IO
  150. * operations are allowed to complete.
  151. * This state is entered from the READY state.
  152. */
  153. SCI_PORT_STOPPING,
  154. /**
  155. * This state indicates the port is now ready. Thus, the user is
  156. * able to perform IO operations on this port.
  157. * This state is entered from the STARTING state.
  158. */
  159. SCI_PORT_READY,
  160. /**
  161. * The substate where the port is started and ready but has no
  162. * active phys.
  163. */
  164. SCI_PORT_SUB_WAITING,
  165. /**
  166. * The substate where the port is started and ready and there is
  167. * at least one phy operational.
  168. */
  169. SCI_PORT_SUB_OPERATIONAL,
  170. /**
  171. * The substate where the port is started and there was an
  172. * add/remove phy event. This state is only used in Automatic
  173. * Port Configuration Mode (APC)
  174. */
  175. SCI_PORT_SUB_CONFIGURING,
  176. /**
  177. * This state indicates the port is in the process of performing a hard
  178. * reset. Thus, the user is unable to perform IO operations on this
  179. * port.
  180. * This state is entered from the READY state.
  181. */
  182. SCI_PORT_RESETTING,
  183. /**
  184. * This state indicates the port has failed a reset request. This state
  185. * is entered when a port reset request times out.
  186. * This state is entered from the RESETTING state.
  187. */
  188. SCI_PORT_FAILED,
  189. };
  190. static inline void sci_port_decrement_request_count(struct isci_port *iport)
  191. {
  192. if (WARN_ONCE(iport->started_request_count == 0,
  193. "%s: tried to decrement started_request_count past 0!?",
  194. __func__))
  195. /* pass */;
  196. else
  197. iport->started_request_count--;
  198. }
  199. #define sci_port_active_phy(port, phy) \
  200. (((port)->active_phy_mask & (1 << (phy)->phy_index)) != 0)
  201. void sci_port_construct(
  202. struct isci_port *iport,
  203. u8 port_index,
  204. struct isci_host *ihost);
  205. enum sci_status sci_port_start(struct isci_port *iport);
  206. enum sci_status sci_port_stop(struct isci_port *iport);
  207. enum sci_status sci_port_add_phy(
  208. struct isci_port *iport,
  209. struct isci_phy *iphy);
  210. enum sci_status sci_port_remove_phy(
  211. struct isci_port *iport,
  212. struct isci_phy *iphy);
  213. void sci_port_setup_transports(
  214. struct isci_port *iport,
  215. u32 device_id);
  216. void isci_port_bcn_enable(struct isci_host *, struct isci_port *);
  217. void sci_port_deactivate_phy(
  218. struct isci_port *iport,
  219. struct isci_phy *iphy,
  220. bool do_notify_user);
  221. bool sci_port_link_detected(
  222. struct isci_port *iport,
  223. struct isci_phy *iphy);
  224. enum sci_status sci_port_get_properties(
  225. struct isci_port *iport,
  226. struct sci_port_properties *prop);
  227. enum sci_status sci_port_link_up(struct isci_port *iport,
  228. struct isci_phy *iphy);
  229. enum sci_status sci_port_link_down(struct isci_port *iport,
  230. struct isci_phy *iphy);
  231. struct isci_request;
  232. struct isci_remote_device;
  233. enum sci_status sci_port_start_io(
  234. struct isci_port *iport,
  235. struct isci_remote_device *idev,
  236. struct isci_request *ireq);
  237. enum sci_status sci_port_complete_io(
  238. struct isci_port *iport,
  239. struct isci_remote_device *idev,
  240. struct isci_request *ireq);
  241. enum sas_linkrate sci_port_get_max_allowed_speed(
  242. struct isci_port *iport);
  243. void sci_port_broadcast_change_received(
  244. struct isci_port *iport,
  245. struct isci_phy *iphy);
  246. bool sci_port_is_valid_phy_assignment(
  247. struct isci_port *iport,
  248. u32 phy_index);
  249. void sci_port_get_sas_address(
  250. struct isci_port *iport,
  251. struct sci_sas_address *sas_address);
  252. void sci_port_get_attached_sas_address(
  253. struct isci_port *iport,
  254. struct sci_sas_address *sas_address);
  255. void isci_port_formed(struct asd_sas_phy *);
  256. void isci_port_deformed(struct asd_sas_phy *);
  257. void isci_port_init(
  258. struct isci_port *port,
  259. struct isci_host *host,
  260. int index);
  261. int isci_port_perform_hard_reset(struct isci_host *ihost, struct isci_port *iport,
  262. struct isci_phy *iphy);
  263. int isci_ata_check_ready(struct domain_device *dev);
  264. #endif /* !defined(_ISCI_PORT_H_) */