port.h 9.3 KB

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