port.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  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 points to the current set of state handlers for this port
  131. * object. These state handlers are assigned at each enter state of
  132. * the state machine.
  133. */
  134. struct scic_sds_port_state_handler *state_handlers;
  135. /* / Memory mapped hardware register space */
  136. /**
  137. * This field is the pointer to the port task scheduler registers
  138. * for the SCU hardware.
  139. */
  140. struct scu_port_task_scheduler_registers __iomem
  141. *port_task_scheduler_registers;
  142. /**
  143. * This field is identical for all port objects and points to the port
  144. * task scheduler group PE configuration registers.
  145. * It is used to assign PEs to a port.
  146. */
  147. u32 __iomem *port_pe_configuration_register;
  148. /**
  149. * This field is the VIIT register space for ths port object.
  150. */
  151. struct scu_viit_entry __iomem *viit_registers;
  152. };
  153. /**
  154. * struct isci_port - This class represents the port object used to internally
  155. * represent libsas port objects. It also keeps a list of remote device
  156. * objects.
  157. *
  158. *
  159. */
  160. struct isci_port {
  161. enum isci_status status;
  162. struct isci_host *isci_host;
  163. struct asd_sas_port sas_port;
  164. struct list_head remote_dev_list;
  165. spinlock_t state_lock;
  166. struct list_head domain_dev_list;
  167. struct completion start_complete;
  168. struct completion hard_reset_complete;
  169. enum sci_status hard_reset_status;
  170. struct scic_sds_port sci;
  171. };
  172. static inline struct isci_port *sci_port_to_iport(struct scic_sds_port *sci_port)
  173. {
  174. struct isci_port *iport = container_of(sci_port, typeof(*iport), sci);
  175. return iport;
  176. }
  177. enum scic_port_not_ready_reason_code {
  178. SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS,
  179. SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED,
  180. SCIC_PORT_NOT_READY_INVALID_PORT_CONFIGURATION,
  181. SCIC_PORT_NOT_READY_RECONFIGURING,
  182. SCIC_PORT_NOT_READY_REASON_CODE_MAX
  183. };
  184. struct scic_port_end_point_properties {
  185. struct sci_sas_address sas_address;
  186. struct scic_phy_proto protocols;
  187. };
  188. struct scic_port_properties {
  189. u32 index;
  190. struct scic_port_end_point_properties local;
  191. struct scic_port_end_point_properties remote;
  192. u32 phy_mask;
  193. };
  194. /**
  195. * enum scic_sds_port_states - This enumeration depicts all the states for the
  196. * common port state machine.
  197. *
  198. *
  199. */
  200. enum scic_sds_port_states {
  201. /**
  202. * This state indicates that the port has successfully been stopped.
  203. * In this state no new IO operations are permitted.
  204. * This state is entered from the STOPPING state.
  205. */
  206. SCI_BASE_PORT_STATE_STOPPED,
  207. /**
  208. * This state indicates that the port is in the process of stopping.
  209. * In this state no new IO operations are permitted, but existing IO
  210. * operations are allowed to complete.
  211. * This state is entered from the READY state.
  212. */
  213. SCI_BASE_PORT_STATE_STOPPING,
  214. /**
  215. * This state indicates the port is now ready. Thus, the user is
  216. * able to perform IO operations on this port.
  217. * This state is entered from the STARTING state.
  218. */
  219. SCI_BASE_PORT_STATE_READY,
  220. /**
  221. * The substate where the port is started and ready but has no
  222. * active phys.
  223. */
  224. SCIC_SDS_PORT_READY_SUBSTATE_WAITING,
  225. /**
  226. * The substate where the port is started and ready and there is
  227. * at least one phy operational.
  228. */
  229. SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL,
  230. /**
  231. * The substate where the port is started and there was an
  232. * add/remove phy event. This state is only used in Automatic
  233. * Port Configuration Mode (APC)
  234. */
  235. SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING,
  236. /**
  237. * This state indicates the port is in the process of performing a hard
  238. * reset. Thus, the user is unable to perform IO operations on this
  239. * port.
  240. * This state is entered from the READY state.
  241. */
  242. SCI_BASE_PORT_STATE_RESETTING,
  243. /**
  244. * This state indicates the port has failed a reset request. This state
  245. * is entered when a port reset request times out.
  246. * This state is entered from the RESETTING state.
  247. */
  248. SCI_BASE_PORT_STATE_FAILED,
  249. SCI_BASE_PORT_MAX_STATES
  250. };
  251. struct scic_sds_remote_device;
  252. struct scic_sds_request;
  253. typedef enum sci_status (*scic_sds_port_handler_t)(struct scic_sds_port *);
  254. typedef enum sci_status (*scic_sds_port_phy_handler_t)(struct scic_sds_port *,
  255. struct scic_sds_phy *);
  256. typedef enum sci_status (*scic_sds_port_reset_handler_t)(struct scic_sds_port *,
  257. u32 timeout);
  258. typedef enum sci_status (*scic_sds_port_event_handler_t)(struct scic_sds_port *, u32);
  259. typedef enum sci_status (*scic_sds_port_frame_handler_t)(struct scic_sds_port *, u32);
  260. typedef void (*scic_sds_port_link_handler_t)(struct scic_sds_port *, struct scic_sds_phy *);
  261. typedef enum sci_status (*scic_sds_port_io_request_handler_t)(struct scic_sds_port *,
  262. struct scic_sds_remote_device *,
  263. struct scic_sds_request *);
  264. struct scic_sds_port_state_handler {
  265. /**
  266. * The destruct_handler specifies the method invoked when attempting to
  267. * destruct a port.
  268. */
  269. scic_sds_port_handler_t destruct_handler;
  270. /**
  271. * The reset_handler specifies the method invoked when a user
  272. * attempts to hard reset a port.
  273. */
  274. scic_sds_port_reset_handler_t reset_handler;
  275. /**
  276. * The add_phy_handler specifies the method invoked when a user
  277. * attempts to add another phy into the port.
  278. */
  279. scic_sds_port_phy_handler_t add_phy_handler;
  280. /**
  281. * The remove_phy_handler specifies the method invoked when a user
  282. * attempts to remove a phy from the port.
  283. */
  284. scic_sds_port_phy_handler_t remove_phy_handler;
  285. scic_sds_port_frame_handler_t frame_handler;
  286. scic_sds_port_event_handler_t event_handler;
  287. scic_sds_port_link_handler_t link_up_handler;
  288. scic_sds_port_link_handler_t link_down_handler;
  289. scic_sds_port_io_request_handler_t start_io_handler;
  290. scic_sds_port_io_request_handler_t complete_io_handler;
  291. };
  292. /**
  293. * scic_sds_port_get_controller() -
  294. *
  295. * Helper macro to get the owning controller of this port
  296. */
  297. #define scic_sds_port_get_controller(this_port) \
  298. ((this_port)->owning_controller)
  299. /**
  300. * scic_sds_port_set_base_state_handlers() -
  301. *
  302. * This macro will change the state handlers to those of the specified state id
  303. */
  304. #define scic_sds_port_set_base_state_handlers(this_port, state_id) \
  305. scic_sds_port_set_state_handlers(\
  306. (this_port), &scic_sds_port_state_handler_table[(state_id)])
  307. /**
  308. * scic_sds_port_set_state_handlers() -
  309. *
  310. * Helper macro to set the port object state handlers
  311. */
  312. #define scic_sds_port_set_state_handlers(this_port, handlers) \
  313. ((this_port)->state_handlers = (handlers))
  314. /**
  315. * scic_sds_port_get_index() -
  316. *
  317. * This macro returns the physical port index for this port object
  318. */
  319. #define scic_sds_port_get_index(this_port) \
  320. ((this_port)->physical_port_index)
  321. static inline void scic_sds_port_decrement_request_count(struct scic_sds_port *sci_port)
  322. {
  323. if (WARN_ONCE(sci_port->started_request_count == 0,
  324. "%s: tried to decrement started_request_count past 0!?",
  325. __func__))
  326. /* pass */;
  327. else
  328. sci_port->started_request_count--;
  329. }
  330. #define scic_sds_port_active_phy(port, phy) \
  331. (((port)->active_phy_mask & (1 << (phy)->phy_index)) != 0)
  332. void scic_sds_port_construct(
  333. struct scic_sds_port *sci_port,
  334. u8 port_index,
  335. struct scic_sds_controller *scic);
  336. enum sci_status scic_sds_port_initialize(
  337. struct scic_sds_port *sci_port,
  338. void __iomem *port_task_scheduler_registers,
  339. void __iomem *port_configuration_regsiter,
  340. void __iomem *viit_registers);
  341. enum sci_status scic_sds_port_start(struct scic_sds_port *sci_port);
  342. enum sci_status scic_sds_port_stop(struct scic_sds_port *sci_port);
  343. enum sci_status scic_sds_port_add_phy(
  344. struct scic_sds_port *sci_port,
  345. struct scic_sds_phy *sci_phy);
  346. enum sci_status scic_sds_port_remove_phy(
  347. struct scic_sds_port *sci_port,
  348. struct scic_sds_phy *sci_phy);
  349. void scic_sds_port_setup_transports(
  350. struct scic_sds_port *sci_port,
  351. u32 device_id);
  352. void scic_sds_port_deactivate_phy(
  353. struct scic_sds_port *sci_port,
  354. struct scic_sds_phy *sci_phy,
  355. bool do_notify_user);
  356. bool scic_sds_port_link_detected(
  357. struct scic_sds_port *sci_port,
  358. struct scic_sds_phy *sci_phy);
  359. void scic_sds_port_link_up(
  360. struct scic_sds_port *sci_port,
  361. struct scic_sds_phy *sci_phy);
  362. void scic_sds_port_link_down(
  363. struct scic_sds_port *sci_port,
  364. struct scic_sds_phy *sci_phy);
  365. enum sci_status scic_sds_port_start_io(
  366. struct scic_sds_port *sci_port,
  367. struct scic_sds_remote_device *sci_dev,
  368. struct scic_sds_request *sci_req);
  369. enum sci_status scic_sds_port_complete_io(
  370. struct scic_sds_port *sci_port,
  371. struct scic_sds_remote_device *sci_dev,
  372. struct scic_sds_request *sci_req);
  373. enum sas_linkrate scic_sds_port_get_max_allowed_speed(
  374. struct scic_sds_port *sci_port);
  375. void scic_sds_port_broadcast_change_received(
  376. struct scic_sds_port *sci_port,
  377. struct scic_sds_phy *sci_phy);
  378. bool scic_sds_port_is_valid_phy_assignment(
  379. struct scic_sds_port *sci_port,
  380. u32 phy_index);
  381. void scic_sds_port_get_sas_address(
  382. struct scic_sds_port *sci_port,
  383. struct sci_sas_address *sas_address);
  384. void scic_sds_port_get_attached_sas_address(
  385. struct scic_sds_port *sci_port,
  386. struct sci_sas_address *sas_address);
  387. enum isci_status isci_port_get_state(
  388. struct isci_port *isci_port);
  389. void isci_port_formed(struct asd_sas_phy *);
  390. void isci_port_deformed(struct asd_sas_phy *);
  391. void isci_port_init(
  392. struct isci_port *port,
  393. struct isci_host *host,
  394. int index);
  395. int isci_port_perform_hard_reset(struct isci_host *ihost, struct isci_port *iport,
  396. struct isci_phy *iphy);
  397. #endif /* !defined(_ISCI_PORT_H_) */