port.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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 sm;
  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. /* timer used for port start/stop operations */
  126. struct sci_timer timer;
  127. /**
  128. * This field is the pointer to the port task scheduler registers
  129. * for the SCU hardware.
  130. */
  131. struct scu_port_task_scheduler_registers __iomem
  132. *port_task_scheduler_registers;
  133. /**
  134. * This field is identical for all port objects and points to the port
  135. * task scheduler group PE configuration registers.
  136. * It is used to assign PEs to a port.
  137. */
  138. u32 __iomem *port_pe_configuration_register;
  139. /**
  140. * This field is the VIIT register space for ths port object.
  141. */
  142. struct scu_viit_entry __iomem *viit_registers;
  143. };
  144. /**
  145. * struct isci_port - This class represents the port object used to internally
  146. * represent libsas port objects. It also keeps a list of remote device
  147. * objects.
  148. *
  149. *
  150. */
  151. struct isci_port {
  152. enum isci_status status;
  153. struct isci_host *isci_host;
  154. struct asd_sas_port sas_port;
  155. struct list_head remote_dev_list;
  156. spinlock_t state_lock;
  157. struct list_head domain_dev_list;
  158. struct completion start_complete;
  159. struct completion hard_reset_complete;
  160. enum sci_status hard_reset_status;
  161. struct scic_sds_port sci;
  162. };
  163. static inline struct isci_port *sci_port_to_iport(struct scic_sds_port *sci_port)
  164. {
  165. struct isci_port *iport = container_of(sci_port, typeof(*iport), sci);
  166. return iport;
  167. }
  168. enum scic_port_not_ready_reason_code {
  169. SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS,
  170. SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED,
  171. SCIC_PORT_NOT_READY_INVALID_PORT_CONFIGURATION,
  172. SCIC_PORT_NOT_READY_RECONFIGURING,
  173. SCIC_PORT_NOT_READY_REASON_CODE_MAX
  174. };
  175. struct scic_port_end_point_properties {
  176. struct sci_sas_address sas_address;
  177. struct scic_phy_proto protocols;
  178. };
  179. struct scic_port_properties {
  180. u32 index;
  181. struct scic_port_end_point_properties local;
  182. struct scic_port_end_point_properties remote;
  183. u32 phy_mask;
  184. };
  185. /**
  186. * enum scic_sds_port_states - This enumeration depicts all the states for the
  187. * common port state machine.
  188. *
  189. *
  190. */
  191. enum scic_sds_port_states {
  192. /**
  193. * This state indicates that the port has successfully been stopped.
  194. * In this state no new IO operations are permitted.
  195. * This state is entered from the STOPPING state.
  196. */
  197. SCI_PORT_STOPPED,
  198. /**
  199. * This state indicates that the port is in the process of stopping.
  200. * In this state no new IO operations are permitted, but existing IO
  201. * operations are allowed to complete.
  202. * This state is entered from the READY state.
  203. */
  204. SCI_PORT_STOPPING,
  205. /**
  206. * This state indicates the port is now ready. Thus, the user is
  207. * able to perform IO operations on this port.
  208. * This state is entered from the STARTING state.
  209. */
  210. SCI_PORT_READY,
  211. /**
  212. * The substate where the port is started and ready but has no
  213. * active phys.
  214. */
  215. SCI_PORT_SUB_WAITING,
  216. /**
  217. * The substate where the port is started and ready and there is
  218. * at least one phy operational.
  219. */
  220. SCI_PORT_SUB_OPERATIONAL,
  221. /**
  222. * The substate where the port is started and there was an
  223. * add/remove phy event. This state is only used in Automatic
  224. * Port Configuration Mode (APC)
  225. */
  226. SCI_PORT_SUB_CONFIGURING,
  227. /**
  228. * This state indicates the port is in the process of performing a hard
  229. * reset. Thus, the user is unable to perform IO operations on this
  230. * port.
  231. * This state is entered from the READY state.
  232. */
  233. SCI_PORT_RESETTING,
  234. /**
  235. * This state indicates the port has failed a reset request. This state
  236. * is entered when a port reset request times out.
  237. * This state is entered from the RESETTING state.
  238. */
  239. SCI_PORT_FAILED,
  240. };
  241. /**
  242. * scic_sds_port_get_controller() -
  243. *
  244. * Helper macro to get the owning controller of this port
  245. */
  246. #define scic_sds_port_get_controller(this_port) \
  247. ((this_port)->owning_controller)
  248. /**
  249. * scic_sds_port_get_index() -
  250. *
  251. * This macro returns the physical port index for this port object
  252. */
  253. #define scic_sds_port_get_index(this_port) \
  254. ((this_port)->physical_port_index)
  255. static inline void scic_sds_port_decrement_request_count(struct scic_sds_port *sci_port)
  256. {
  257. if (WARN_ONCE(sci_port->started_request_count == 0,
  258. "%s: tried to decrement started_request_count past 0!?",
  259. __func__))
  260. /* pass */;
  261. else
  262. sci_port->started_request_count--;
  263. }
  264. #define scic_sds_port_active_phy(port, phy) \
  265. (((port)->active_phy_mask & (1 << (phy)->phy_index)) != 0)
  266. void scic_sds_port_construct(
  267. struct scic_sds_port *sci_port,
  268. u8 port_index,
  269. struct scic_sds_controller *scic);
  270. enum sci_status scic_sds_port_initialize(
  271. struct scic_sds_port *sci_port,
  272. void __iomem *port_task_scheduler_registers,
  273. void __iomem *port_configuration_regsiter,
  274. void __iomem *viit_registers);
  275. enum sci_status scic_sds_port_start(struct scic_sds_port *sci_port);
  276. enum sci_status scic_sds_port_stop(struct scic_sds_port *sci_port);
  277. enum sci_status scic_sds_port_add_phy(
  278. struct scic_sds_port *sci_port,
  279. struct scic_sds_phy *sci_phy);
  280. enum sci_status scic_sds_port_remove_phy(
  281. struct scic_sds_port *sci_port,
  282. struct scic_sds_phy *sci_phy);
  283. void scic_sds_port_setup_transports(
  284. struct scic_sds_port *sci_port,
  285. u32 device_id);
  286. void scic_sds_port_deactivate_phy(
  287. struct scic_sds_port *sci_port,
  288. struct scic_sds_phy *sci_phy,
  289. bool do_notify_user);
  290. bool scic_sds_port_link_detected(
  291. struct scic_sds_port *sci_port,
  292. struct scic_sds_phy *sci_phy);
  293. enum sci_status scic_sds_port_link_up(struct scic_sds_port *sci_port,
  294. struct scic_sds_phy *sci_phy);
  295. enum sci_status scic_sds_port_link_down(struct scic_sds_port *sci_port,
  296. struct scic_sds_phy *sci_phy);
  297. struct scic_sds_request;
  298. struct scic_sds_remote_device;
  299. enum sci_status scic_sds_port_start_io(
  300. struct scic_sds_port *sci_port,
  301. struct scic_sds_remote_device *sci_dev,
  302. struct scic_sds_request *sci_req);
  303. enum sci_status scic_sds_port_complete_io(
  304. struct scic_sds_port *sci_port,
  305. struct scic_sds_remote_device *sci_dev,
  306. struct scic_sds_request *sci_req);
  307. enum sas_linkrate scic_sds_port_get_max_allowed_speed(
  308. struct scic_sds_port *sci_port);
  309. void scic_sds_port_broadcast_change_received(
  310. struct scic_sds_port *sci_port,
  311. struct scic_sds_phy *sci_phy);
  312. bool scic_sds_port_is_valid_phy_assignment(
  313. struct scic_sds_port *sci_port,
  314. u32 phy_index);
  315. void scic_sds_port_get_sas_address(
  316. struct scic_sds_port *sci_port,
  317. struct sci_sas_address *sas_address);
  318. void scic_sds_port_get_attached_sas_address(
  319. struct scic_sds_port *sci_port,
  320. struct sci_sas_address *sas_address);
  321. enum isci_status isci_port_get_state(
  322. struct isci_port *isci_port);
  323. void isci_port_formed(struct asd_sas_phy *);
  324. void isci_port_deformed(struct asd_sas_phy *);
  325. void isci_port_init(
  326. struct isci_port *port,
  327. struct isci_host *host,
  328. int index);
  329. int isci_port_perform_hard_reset(struct isci_host *ihost, struct isci_port *iport,
  330. struct isci_phy *iphy);
  331. #endif /* !defined(_ISCI_PORT_H_) */