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