port.h 9.0 KB

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