port.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. #define IPORT_RESET_PENDING 0
  94. unsigned long state;
  95. enum sci_status hard_reset_status;
  96. struct sci_base_state_machine sm;
  97. bool ready_exit;
  98. u8 logical_port_index;
  99. u8 physical_port_index;
  100. u8 active_phy_mask;
  101. u8 enabled_phy_mask;
  102. u8 last_active_phy;
  103. u16 reserved_rni;
  104. u16 reserved_tag;
  105. u32 started_request_count;
  106. u32 assigned_device_count;
  107. u32 hang_detect_users;
  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 - port state machine states
  136. * @SCI_PORT_STOPPED: port has successfully been stopped. In this state
  137. * no new IO operations are permitted. This state is
  138. * entered from the STOPPING state.
  139. * @SCI_PORT_STOPPING: port is in the process of stopping. In this
  140. * state no new IO operations are permitted, but
  141. * existing IO operations are allowed to complete.
  142. * This state is entered from the READY state.
  143. * @SCI_PORT_READY: port is now ready. Thus, the user is able to
  144. * perform IO operations on this port. This state is
  145. * entered from the STARTING state.
  146. * @SCI_PORT_SUB_WAITING: port is started and ready but has no active
  147. * phys.
  148. * @SCI_PORT_SUB_OPERATIONAL: port is started and ready and there is at
  149. * least one phy operational.
  150. * @SCI_PORT_SUB_CONFIGURING: port is started and there was an
  151. * add/remove phy event. This state is only
  152. * used in Automatic Port Configuration Mode
  153. * (APC)
  154. * @SCI_PORT_RESETTING: port is in the process of performing a hard
  155. * reset. Thus, the user is unable to perform IO
  156. * operations on this port. This state is entered
  157. * from the READY state.
  158. * @SCI_PORT_FAILED: port has failed a reset request. This state is
  159. * entered when a port reset request times out. This
  160. * state is entered from the RESETTING state.
  161. */
  162. #define PORT_STATES {\
  163. C(PORT_STOPPED),\
  164. C(PORT_STOPPING),\
  165. C(PORT_READY),\
  166. C(PORT_SUB_WAITING),\
  167. C(PORT_SUB_OPERATIONAL),\
  168. C(PORT_SUB_CONFIGURING),\
  169. C(PORT_RESETTING),\
  170. C(PORT_FAILED),\
  171. }
  172. #undef C
  173. #define C(a) SCI_##a
  174. enum sci_port_states PORT_STATES;
  175. #undef C
  176. static inline void sci_port_decrement_request_count(struct isci_port *iport)
  177. {
  178. if (WARN_ONCE(iport->started_request_count == 0,
  179. "%s: tried to decrement started_request_count past 0!?",
  180. __func__))
  181. /* pass */;
  182. else
  183. iport->started_request_count--;
  184. }
  185. #define sci_port_active_phy(port, phy) \
  186. (((port)->active_phy_mask & (1 << (phy)->phy_index)) != 0)
  187. void sci_port_construct(
  188. struct isci_port *iport,
  189. u8 port_index,
  190. struct isci_host *ihost);
  191. enum sci_status sci_port_start(struct isci_port *iport);
  192. enum sci_status sci_port_stop(struct isci_port *iport);
  193. enum sci_status sci_port_add_phy(
  194. struct isci_port *iport,
  195. struct isci_phy *iphy);
  196. enum sci_status sci_port_remove_phy(
  197. struct isci_port *iport,
  198. struct isci_phy *iphy);
  199. void sci_port_setup_transports(
  200. struct isci_port *iport,
  201. u32 device_id);
  202. void isci_port_bcn_enable(struct isci_host *, struct isci_port *);
  203. void sci_port_deactivate_phy(
  204. struct isci_port *iport,
  205. struct isci_phy *iphy,
  206. bool do_notify_user);
  207. bool sci_port_link_detected(
  208. struct isci_port *iport,
  209. struct isci_phy *iphy);
  210. enum sci_status sci_port_get_properties(
  211. struct isci_port *iport,
  212. struct sci_port_properties *prop);
  213. enum sci_status sci_port_link_up(struct isci_port *iport,
  214. struct isci_phy *iphy);
  215. enum sci_status sci_port_link_down(struct isci_port *iport,
  216. struct isci_phy *iphy);
  217. struct isci_request;
  218. struct isci_remote_device;
  219. enum sci_status sci_port_start_io(
  220. struct isci_port *iport,
  221. struct isci_remote_device *idev,
  222. struct isci_request *ireq);
  223. enum sci_status sci_port_complete_io(
  224. struct isci_port *iport,
  225. struct isci_remote_device *idev,
  226. struct isci_request *ireq);
  227. enum sas_linkrate sci_port_get_max_allowed_speed(
  228. struct isci_port *iport);
  229. void sci_port_broadcast_change_received(
  230. struct isci_port *iport,
  231. struct isci_phy *iphy);
  232. bool sci_port_is_valid_phy_assignment(
  233. struct isci_port *iport,
  234. u32 phy_index);
  235. void sci_port_get_sas_address(
  236. struct isci_port *iport,
  237. struct sci_sas_address *sas_address);
  238. void sci_port_get_attached_sas_address(
  239. struct isci_port *iport,
  240. struct sci_sas_address *sas_address);
  241. void sci_port_set_hang_detection_timeout(
  242. struct isci_port *isci_port,
  243. u32 timeout);
  244. void isci_port_formed(struct asd_sas_phy *);
  245. void isci_port_deformed(struct asd_sas_phy *);
  246. int isci_port_perform_hard_reset(struct isci_host *ihost, struct isci_port *iport,
  247. struct isci_phy *iphy);
  248. int isci_ata_check_ready(struct domain_device *dev);
  249. #endif /* !defined(_ISCI_PORT_H_) */