port.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  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 scic_sds_port
  74. *
  75. * The core port object provides the the abstraction for an SCU port.
  76. */
  77. struct scic_sds_port {
  78. /**
  79. * This field contains the information for the base port state machine.
  80. */
  81. struct sci_base_state_machine state_machine;
  82. bool ready_exit;
  83. /**
  84. * This field is the port index that is reported to the SCI USER.
  85. * This allows the actual hardware physical port to change without
  86. * the SCI USER getting a different answer for the get port index.
  87. */
  88. u8 logical_port_index;
  89. /**
  90. * This field is the port index used to program the SCU hardware.
  91. */
  92. u8 physical_port_index;
  93. /**
  94. * This field contains the active phy mask for the port.
  95. * This mask is used in conjunction with the phy state to determine
  96. * which phy to select for some port operations.
  97. */
  98. u8 active_phy_mask;
  99. u16 reserved_rni;
  100. u16 reserved_tci;
  101. /**
  102. * This field contains the count of the io requests started on this port
  103. * object. It is used to control controller shutdown.
  104. */
  105. u32 started_request_count;
  106. /**
  107. * This field contains the number of devices assigned to this port.
  108. * It is used to control port start requests.
  109. */
  110. u32 assigned_device_count;
  111. /**
  112. * This field contains the reason for the port not going ready. It is
  113. * assigned in the state handlers and used in the state transition.
  114. */
  115. u32 not_ready_reason;
  116. /**
  117. * This field is the table of phys assigned to the port.
  118. */
  119. struct scic_sds_phy *phy_table[SCI_MAX_PHYS];
  120. /**
  121. * This field is a pointer back to the controller that owns this
  122. * port object.
  123. */
  124. struct scic_sds_controller *owning_controller;
  125. /**
  126. * This field contains the port start/stop timer handle.
  127. */
  128. void *timer_handle;
  129. /**
  130. * This field is the pointer to the port task scheduler registers
  131. * for the SCU hardware.
  132. */
  133. struct scu_port_task_scheduler_registers __iomem
  134. *port_task_scheduler_registers;
  135. /**
  136. * This field is identical for all port objects and points to the port
  137. * task scheduler group PE configuration registers.
  138. * It is used to assign PEs to a port.
  139. */
  140. u32 __iomem *port_pe_configuration_register;
  141. /**
  142. * This field is the VIIT register space for ths port object.
  143. */
  144. struct scu_viit_entry __iomem *viit_registers;
  145. };
  146. /**
  147. * struct isci_port - This class represents the port object used to internally
  148. * represent libsas port objects. It also keeps a list of remote device
  149. * objects.
  150. *
  151. *
  152. */
  153. struct isci_port {
  154. enum isci_status status;
  155. struct isci_host *isci_host;
  156. struct asd_sas_port sas_port;
  157. struct list_head remote_dev_list;
  158. spinlock_t state_lock;
  159. struct list_head domain_dev_list;
  160. struct completion start_complete;
  161. struct completion hard_reset_complete;
  162. enum sci_status hard_reset_status;
  163. struct scic_sds_port sci;
  164. };
  165. static inline struct isci_port *sci_port_to_iport(struct scic_sds_port *sci_port)
  166. {
  167. struct isci_port *iport = container_of(sci_port, typeof(*iport), sci);
  168. return iport;
  169. }
  170. enum scic_port_not_ready_reason_code {
  171. SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS,
  172. SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED,
  173. SCIC_PORT_NOT_READY_INVALID_PORT_CONFIGURATION,
  174. SCIC_PORT_NOT_READY_RECONFIGURING,
  175. SCIC_PORT_NOT_READY_REASON_CODE_MAX
  176. };
  177. struct scic_port_end_point_properties {
  178. struct sci_sas_address sas_address;
  179. struct scic_phy_proto protocols;
  180. };
  181. struct scic_port_properties {
  182. u32 index;
  183. struct scic_port_end_point_properties local;
  184. struct scic_port_end_point_properties remote;
  185. u32 phy_mask;
  186. };
  187. /**
  188. * enum scic_sds_port_states - This enumeration depicts all the states for the
  189. * common port state machine.
  190. *
  191. *
  192. */
  193. enum scic_sds_port_states {
  194. /**
  195. * This state indicates that the port has successfully been stopped.
  196. * In this state no new IO operations are permitted.
  197. * This state is entered from the STOPPING state.
  198. */
  199. SCI_BASE_PORT_STATE_STOPPED,
  200. /**
  201. * This state indicates that the port is in the process of stopping.
  202. * In this state no new IO operations are permitted, but existing IO
  203. * operations are allowed to complete.
  204. * This state is entered from the READY state.
  205. */
  206. SCI_BASE_PORT_STATE_STOPPING,
  207. /**
  208. * This state indicates the port is now ready. Thus, the user is
  209. * able to perform IO operations on this port.
  210. * This state is entered from the STARTING state.
  211. */
  212. SCI_BASE_PORT_STATE_READY,
  213. /**
  214. * The substate where the port is started and ready but has no
  215. * active phys.
  216. */
  217. SCIC_SDS_PORT_READY_SUBSTATE_WAITING,
  218. /**
  219. * The substate where the port is started and ready and there is
  220. * at least one phy operational.
  221. */
  222. SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL,
  223. /**
  224. * The substate where the port is started and there was an
  225. * add/remove phy event. This state is only used in Automatic
  226. * Port Configuration Mode (APC)
  227. */
  228. SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING,
  229. /**
  230. * This state indicates the port is in the process of performing a hard
  231. * reset. Thus, the user is unable to perform IO operations on this
  232. * port.
  233. * This state is entered from the READY state.
  234. */
  235. SCI_BASE_PORT_STATE_RESETTING,
  236. /**
  237. * This state indicates the port has failed a reset request. This state
  238. * is entered when a port reset request times out.
  239. * This state is entered from the RESETTING state.
  240. */
  241. SCI_BASE_PORT_STATE_FAILED,
  242. };
  243. /**
  244. * scic_sds_port_get_controller() -
  245. *
  246. * Helper macro to get the owning controller of this port
  247. */
  248. #define scic_sds_port_get_controller(this_port) \
  249. ((this_port)->owning_controller)
  250. /**
  251. * scic_sds_port_get_index() -
  252. *
  253. * This macro returns the physical port index for this port object
  254. */
  255. #define scic_sds_port_get_index(this_port) \
  256. ((this_port)->physical_port_index)
  257. static inline void scic_sds_port_decrement_request_count(struct scic_sds_port *sci_port)
  258. {
  259. if (WARN_ONCE(sci_port->started_request_count == 0,
  260. "%s: tried to decrement started_request_count past 0!?",
  261. __func__))
  262. /* pass */;
  263. else
  264. sci_port->started_request_count--;
  265. }
  266. #define scic_sds_port_active_phy(port, phy) \
  267. (((port)->active_phy_mask & (1 << (phy)->phy_index)) != 0)
  268. void scic_sds_port_construct(
  269. struct scic_sds_port *sci_port,
  270. u8 port_index,
  271. struct scic_sds_controller *scic);
  272. enum sci_status scic_sds_port_initialize(
  273. struct scic_sds_port *sci_port,
  274. void __iomem *port_task_scheduler_registers,
  275. void __iomem *port_configuration_regsiter,
  276. void __iomem *viit_registers);
  277. enum sci_status scic_sds_port_start(struct scic_sds_port *sci_port);
  278. enum sci_status scic_sds_port_stop(struct scic_sds_port *sci_port);
  279. enum sci_status scic_sds_port_add_phy(
  280. struct scic_sds_port *sci_port,
  281. struct scic_sds_phy *sci_phy);
  282. enum sci_status scic_sds_port_remove_phy(
  283. struct scic_sds_port *sci_port,
  284. struct scic_sds_phy *sci_phy);
  285. void scic_sds_port_setup_transports(
  286. struct scic_sds_port *sci_port,
  287. u32 device_id);
  288. void scic_sds_port_deactivate_phy(
  289. struct scic_sds_port *sci_port,
  290. struct scic_sds_phy *sci_phy,
  291. bool do_notify_user);
  292. bool scic_sds_port_link_detected(
  293. struct scic_sds_port *sci_port,
  294. struct scic_sds_phy *sci_phy);
  295. enum sci_status scic_sds_port_link_up(struct scic_sds_port *sci_port,
  296. struct scic_sds_phy *sci_phy);
  297. enum sci_status scic_sds_port_link_down(struct scic_sds_port *sci_port,
  298. struct scic_sds_phy *sci_phy);
  299. struct scic_sds_request;
  300. struct scic_sds_remote_device;
  301. enum sci_status scic_sds_port_start_io(
  302. struct scic_sds_port *sci_port,
  303. struct scic_sds_remote_device *sci_dev,
  304. struct scic_sds_request *sci_req);
  305. enum sci_status scic_sds_port_complete_io(
  306. struct scic_sds_port *sci_port,
  307. struct scic_sds_remote_device *sci_dev,
  308. struct scic_sds_request *sci_req);
  309. enum sas_linkrate scic_sds_port_get_max_allowed_speed(
  310. struct scic_sds_port *sci_port);
  311. void scic_sds_port_broadcast_change_received(
  312. struct scic_sds_port *sci_port,
  313. struct scic_sds_phy *sci_phy);
  314. bool scic_sds_port_is_valid_phy_assignment(
  315. struct scic_sds_port *sci_port,
  316. u32 phy_index);
  317. void scic_sds_port_get_sas_address(
  318. struct scic_sds_port *sci_port,
  319. struct sci_sas_address *sas_address);
  320. void scic_sds_port_get_attached_sas_address(
  321. struct scic_sds_port *sci_port,
  322. struct sci_sas_address *sas_address);
  323. enum isci_status isci_port_get_state(
  324. struct isci_port *isci_port);
  325. void isci_port_formed(struct asd_sas_phy *);
  326. void isci_port_deformed(struct asd_sas_phy *);
  327. void isci_port_init(
  328. struct isci_port *port,
  329. struct isci_host *host,
  330. int index);
  331. int isci_port_perform_hard_reset(struct isci_host *ihost, struct isci_port *iport,
  332. struct isci_phy *iphy);
  333. #endif /* !defined(_ISCI_PORT_H_) */