port.h 11 KB

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