host.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  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 _SCI_HOST_H_
  56. #define _SCI_HOST_H_
  57. #include "remote_device.h"
  58. #include "phy.h"
  59. #include "isci.h"
  60. #include "remote_node_table.h"
  61. #include "registers.h"
  62. #include "scu_unsolicited_frame.h"
  63. #include "unsolicited_frame_control.h"
  64. #include "probe_roms.h"
  65. struct isci_request;
  66. struct scu_task_context;
  67. /**
  68. * struct scic_power_control -
  69. *
  70. * This structure defines the fields for managing power control for direct
  71. * attached disk devices.
  72. */
  73. struct scic_power_control {
  74. /**
  75. * This field is set when the power control timer is running and cleared when
  76. * it is not.
  77. */
  78. bool timer_started;
  79. /**
  80. * Timer to control when the directed attached disks can consume power.
  81. */
  82. struct sci_timer timer;
  83. /**
  84. * This field is used to keep track of how many phys are put into the
  85. * requesters field.
  86. */
  87. u8 phys_waiting;
  88. /**
  89. * This field is used to keep track of how many phys have been granted to consume power
  90. */
  91. u8 phys_granted_power;
  92. /**
  93. * This field is an array of phys that we are waiting on. The phys are direct
  94. * mapped into requesters via struct scic_sds_phy.phy_index
  95. */
  96. struct isci_phy *requesters[SCI_MAX_PHYS];
  97. };
  98. struct scic_sds_port_configuration_agent;
  99. typedef void (*port_config_fn)(struct isci_host *,
  100. struct scic_sds_port_configuration_agent *,
  101. struct isci_port *, struct isci_phy *);
  102. struct scic_sds_port_configuration_agent {
  103. u16 phy_configured_mask;
  104. u16 phy_ready_mask;
  105. struct {
  106. u8 min_index;
  107. u8 max_index;
  108. } phy_valid_port_range[SCI_MAX_PHYS];
  109. bool timer_pending;
  110. port_config_fn link_up_handler;
  111. port_config_fn link_down_handler;
  112. struct sci_timer timer;
  113. };
  114. /**
  115. * isci_host - primary host/controller object
  116. * @timer: timeout start/stop operations
  117. * @device_table: rni (hw remote node index) to remote device lookup table
  118. * @available_remote_nodes: rni allocator
  119. * @power_control: manage device spin up
  120. * @io_request_sequence: generation number for tci's (task contexts)
  121. * @task_context_table: hw task context table
  122. * @remote_node_context_table: hw remote node context table
  123. * @completion_queue: hw-producer driver-consumer communication ring
  124. * @completion_queue_get: tracks the driver 'head' of the ring to notify hw
  125. * @logical_port_entries: min({driver|silicon}-supported-port-count)
  126. * @remote_node_entries: min({driver|silicon}-supported-node-count)
  127. * @task_context_entries: min({driver|silicon}-supported-task-count)
  128. * @phy_timer: phy startup timer
  129. * @invalid_phy_mask: if an invalid_link_up notification is reported a bit for
  130. * the phy index is set so further notifications are not
  131. * made. Once the phy reports link up and is made part of a
  132. * port then this bit is cleared.
  133. */
  134. struct isci_host {
  135. struct sci_base_state_machine sm;
  136. /* XXX can we time this externally */
  137. struct sci_timer timer;
  138. /* XXX drop reference module params directly */
  139. union scic_user_parameters user_parameters;
  140. /* XXX no need to be a union */
  141. union scic_oem_parameters oem_parameters;
  142. struct scic_sds_port_configuration_agent port_agent;
  143. struct isci_remote_device *device_table[SCI_MAX_REMOTE_DEVICES];
  144. struct scic_remote_node_table available_remote_nodes;
  145. struct scic_power_control power_control;
  146. u8 io_request_sequence[SCI_MAX_IO_REQUESTS];
  147. struct scu_task_context *task_context_table;
  148. dma_addr_t task_context_dma;
  149. union scu_remote_node_context *remote_node_context_table;
  150. u32 *completion_queue;
  151. u32 completion_queue_get;
  152. u32 logical_port_entries;
  153. u32 remote_node_entries;
  154. u32 task_context_entries;
  155. struct scic_sds_unsolicited_frame_control uf_control;
  156. /* phy startup */
  157. struct sci_timer phy_timer;
  158. /* XXX kill */
  159. bool phy_startup_timer_pending;
  160. u32 next_phy_to_start;
  161. u8 invalid_phy_mask;
  162. /* TODO attempt dynamic interrupt coalescing scheme */
  163. u16 interrupt_coalesce_number;
  164. u32 interrupt_coalesce_timeout;
  165. struct smu_registers __iomem *smu_registers;
  166. struct scu_registers __iomem *scu_registers;
  167. u16 tci_head;
  168. u16 tci_tail;
  169. u16 tci_pool[SCI_MAX_IO_REQUESTS];
  170. int id; /* unique within a given pci device */
  171. struct isci_phy phys[SCI_MAX_PHYS];
  172. struct isci_port ports[SCI_MAX_PORTS + 1]; /* includes dummy port */
  173. struct sas_ha_struct sas_ha;
  174. spinlock_t state_lock;
  175. struct pci_dev *pdev;
  176. enum isci_status status;
  177. #define IHOST_START_PENDING 0
  178. #define IHOST_STOP_PENDING 1
  179. unsigned long flags;
  180. wait_queue_head_t eventq;
  181. struct Scsi_Host *shost;
  182. struct tasklet_struct completion_tasklet;
  183. struct list_head requests_to_complete;
  184. struct list_head requests_to_errorback;
  185. spinlock_t scic_lock;
  186. struct isci_request *reqs[SCI_MAX_IO_REQUESTS];
  187. struct isci_remote_device devices[SCI_MAX_REMOTE_DEVICES];
  188. };
  189. /**
  190. * enum scic_sds_controller_states - This enumeration depicts all the states
  191. * for the common controller state machine.
  192. */
  193. enum scic_sds_controller_states {
  194. /**
  195. * Simply the initial state for the base controller state machine.
  196. */
  197. SCIC_INITIAL = 0,
  198. /**
  199. * This state indicates that the controller is reset. The memory for
  200. * the controller is in it's initial state, but the controller requires
  201. * initialization.
  202. * This state is entered from the INITIAL state.
  203. * This state is entered from the RESETTING state.
  204. */
  205. SCIC_RESET,
  206. /**
  207. * This state is typically an action state that indicates the controller
  208. * is in the process of initialization. In this state no new IO operations
  209. * are permitted.
  210. * This state is entered from the RESET state.
  211. */
  212. SCIC_INITIALIZING,
  213. /**
  214. * This state indicates that the controller has been successfully
  215. * initialized. In this state no new IO operations are permitted.
  216. * This state is entered from the INITIALIZING state.
  217. */
  218. SCIC_INITIALIZED,
  219. /**
  220. * This state indicates the the controller is in the process of becoming
  221. * ready (i.e. starting). In this state no new IO operations are permitted.
  222. * This state is entered from the INITIALIZED state.
  223. */
  224. SCIC_STARTING,
  225. /**
  226. * This state indicates the controller is now ready. Thus, the user
  227. * is able to perform IO operations on the controller.
  228. * This state is entered from the STARTING state.
  229. */
  230. SCIC_READY,
  231. /**
  232. * This state is typically an action state that indicates the controller
  233. * is in the process of resetting. Thus, the user is unable to perform
  234. * IO operations on the controller. A reset is considered destructive in
  235. * most cases.
  236. * This state is entered from the READY state.
  237. * This state is entered from the FAILED state.
  238. * This state is entered from the STOPPED state.
  239. */
  240. SCIC_RESETTING,
  241. /**
  242. * This state indicates that the controller is in the process of stopping.
  243. * In this state no new IO operations are permitted, but existing IO
  244. * operations are allowed to complete.
  245. * This state is entered from the READY state.
  246. */
  247. SCIC_STOPPING,
  248. /**
  249. * This state indicates that the controller has successfully been stopped.
  250. * In this state no new IO operations are permitted.
  251. * This state is entered from the STOPPING state.
  252. */
  253. SCIC_STOPPED,
  254. /**
  255. * This state indicates that the controller could not successfully be
  256. * initialized. In this state no new IO operations are permitted.
  257. * This state is entered from the INITIALIZING state.
  258. * This state is entered from the STARTING state.
  259. * This state is entered from the STOPPING state.
  260. * This state is entered from the RESETTING state.
  261. */
  262. SCIC_FAILED,
  263. };
  264. /**
  265. * struct isci_pci_info - This class represents the pci function containing the
  266. * controllers. Depending on PCI SKU, there could be up to 2 controllers in
  267. * the PCI function.
  268. */
  269. #define SCI_MAX_MSIX_INT (SCI_NUM_MSI_X_INT*SCI_MAX_CONTROLLERS)
  270. struct isci_pci_info {
  271. struct msix_entry msix_entries[SCI_MAX_MSIX_INT];
  272. struct isci_host *hosts[SCI_MAX_CONTROLLERS];
  273. struct isci_orom *orom;
  274. };
  275. static inline struct isci_pci_info *to_pci_info(struct pci_dev *pdev)
  276. {
  277. return pci_get_drvdata(pdev);
  278. }
  279. #define for_each_isci_host(id, ihost, pdev) \
  280. for (id = 0, ihost = to_pci_info(pdev)->hosts[id]; \
  281. id < ARRAY_SIZE(to_pci_info(pdev)->hosts) && ihost; \
  282. ihost = to_pci_info(pdev)->hosts[++id])
  283. static inline enum isci_status isci_host_get_state(struct isci_host *isci_host)
  284. {
  285. return isci_host->status;
  286. }
  287. static inline void isci_host_change_state(struct isci_host *isci_host,
  288. enum isci_status status)
  289. {
  290. unsigned long flags;
  291. dev_dbg(&isci_host->pdev->dev,
  292. "%s: isci_host = %p, state = 0x%x",
  293. __func__,
  294. isci_host,
  295. status);
  296. spin_lock_irqsave(&isci_host->state_lock, flags);
  297. isci_host->status = status;
  298. spin_unlock_irqrestore(&isci_host->state_lock, flags);
  299. }
  300. static inline void wait_for_start(struct isci_host *ihost)
  301. {
  302. wait_event(ihost->eventq, !test_bit(IHOST_START_PENDING, &ihost->flags));
  303. }
  304. static inline void wait_for_stop(struct isci_host *ihost)
  305. {
  306. wait_event(ihost->eventq, !test_bit(IHOST_STOP_PENDING, &ihost->flags));
  307. }
  308. static inline void wait_for_device_start(struct isci_host *ihost, struct isci_remote_device *idev)
  309. {
  310. wait_event(ihost->eventq, !test_bit(IDEV_START_PENDING, &idev->flags));
  311. }
  312. static inline void wait_for_device_stop(struct isci_host *ihost, struct isci_remote_device *idev)
  313. {
  314. wait_event(ihost->eventq, !test_bit(IDEV_STOP_PENDING, &idev->flags));
  315. }
  316. static inline struct isci_host *dev_to_ihost(struct domain_device *dev)
  317. {
  318. return dev->port->ha->lldd_ha;
  319. }
  320. /**
  321. * scic_sds_controller_get_protocol_engine_group() -
  322. *
  323. * This macro returns the protocol engine group for this controller object.
  324. * Presently we only support protocol engine group 0 so just return that
  325. */
  326. #define scic_sds_controller_get_protocol_engine_group(controller) 0
  327. /* see scic_controller_io_tag_allocate|free for how seq and tci are built */
  328. #define ISCI_TAG(seq, tci) (((u16) (seq)) << 12 | tci)
  329. /* these are returned by the hardware, so sanitize them */
  330. #define ISCI_TAG_SEQ(tag) (((tag) >> 12) & (SCI_MAX_SEQ-1))
  331. #define ISCI_TAG_TCI(tag) ((tag) & (SCI_MAX_IO_REQUESTS-1))
  332. /* expander attached sata devices require 3 rnc slots */
  333. static inline int scic_sds_remote_device_node_count(struct isci_remote_device *idev)
  334. {
  335. struct domain_device *dev = idev->domain_dev;
  336. if ((dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) &&
  337. !idev->is_direct_attached)
  338. return SCU_STP_REMOTE_NODE_COUNT;
  339. return SCU_SSP_REMOTE_NODE_COUNT;
  340. }
  341. /**
  342. * scic_sds_controller_set_invalid_phy() -
  343. *
  344. * This macro will set the bit in the invalid phy mask for this controller
  345. * object. This is used to control messages reported for invalid link up
  346. * notifications.
  347. */
  348. #define scic_sds_controller_set_invalid_phy(controller, phy) \
  349. ((controller)->invalid_phy_mask |= (1 << (phy)->phy_index))
  350. /**
  351. * scic_sds_controller_clear_invalid_phy() -
  352. *
  353. * This macro will clear the bit in the invalid phy mask for this controller
  354. * object. This is used to control messages reported for invalid link up
  355. * notifications.
  356. */
  357. #define scic_sds_controller_clear_invalid_phy(controller, phy) \
  358. ((controller)->invalid_phy_mask &= ~(1 << (phy)->phy_index))
  359. static inline struct device *sciphy_to_dev(struct isci_phy *iphy)
  360. {
  361. if (!iphy || !iphy->isci_port || !iphy->isci_port->isci_host)
  362. return NULL;
  363. return &iphy->isci_port->isci_host->pdev->dev;
  364. }
  365. static inline struct device *sciport_to_dev(struct isci_port *iport)
  366. {
  367. if (!iport || !iport->isci_host)
  368. return NULL;
  369. return &iport->isci_host->pdev->dev;
  370. }
  371. static inline struct device *scirdev_to_dev(struct isci_remote_device *idev)
  372. {
  373. if (!idev || !idev->isci_port || !idev->isci_port->isci_host)
  374. return NULL;
  375. return &idev->isci_port->isci_host->pdev->dev;
  376. }
  377. enum {
  378. ISCI_SI_REVA0,
  379. ISCI_SI_REVA2,
  380. ISCI_SI_REVB0,
  381. ISCI_SI_REVC0
  382. };
  383. extern int isci_si_rev;
  384. static inline bool is_a0(void)
  385. {
  386. return isci_si_rev == ISCI_SI_REVA0;
  387. }
  388. static inline bool is_a2(void)
  389. {
  390. return isci_si_rev == ISCI_SI_REVA2;
  391. }
  392. static inline bool is_b0(void)
  393. {
  394. return isci_si_rev == ISCI_SI_REVB0;
  395. }
  396. static inline bool is_c0(void)
  397. {
  398. return isci_si_rev > ISCI_SI_REVB0;
  399. }
  400. void scic_sds_controller_post_request(struct isci_host *ihost,
  401. u32 request);
  402. void scic_sds_controller_release_frame(struct isci_host *ihost,
  403. u32 frame_index);
  404. void scic_sds_controller_copy_sata_response(void *response_buffer,
  405. void *frame_header,
  406. void *frame_buffer);
  407. enum sci_status scic_sds_controller_allocate_remote_node_context(struct isci_host *ihost,
  408. struct isci_remote_device *idev,
  409. u16 *node_id);
  410. void scic_sds_controller_free_remote_node_context(
  411. struct isci_host *ihost,
  412. struct isci_remote_device *idev,
  413. u16 node_id);
  414. union scu_remote_node_context *scic_sds_controller_get_remote_node_context_buffer(
  415. struct isci_host *ihost,
  416. u16 node_id);
  417. struct isci_request *scic_request_by_tag(struct isci_host *ihost,
  418. u16 io_tag);
  419. void scic_sds_controller_power_control_queue_insert(
  420. struct isci_host *ihost,
  421. struct isci_phy *iphy);
  422. void scic_sds_controller_power_control_queue_remove(
  423. struct isci_host *ihost,
  424. struct isci_phy *iphy);
  425. void scic_sds_controller_link_up(
  426. struct isci_host *ihost,
  427. struct isci_port *iport,
  428. struct isci_phy *iphy);
  429. void scic_sds_controller_link_down(
  430. struct isci_host *ihost,
  431. struct isci_port *iport,
  432. struct isci_phy *iphy);
  433. void scic_sds_controller_remote_device_stopped(
  434. struct isci_host *ihost,
  435. struct isci_remote_device *idev);
  436. void scic_sds_controller_copy_task_context(
  437. struct isci_host *ihost,
  438. struct isci_request *ireq);
  439. void scic_sds_controller_register_setup(struct isci_host *ihost);
  440. enum sci_status scic_controller_continue_io(struct isci_request *ireq);
  441. int isci_host_scan_finished(struct Scsi_Host *, unsigned long);
  442. void isci_host_scan_start(struct Scsi_Host *);
  443. u16 isci_alloc_tag(struct isci_host *ihost);
  444. enum sci_status isci_free_tag(struct isci_host *ihost, u16 io_tag);
  445. void isci_tci_free(struct isci_host *ihost, u16 tci);
  446. int isci_host_init(struct isci_host *);
  447. void isci_host_init_controller_names(
  448. struct isci_host *isci_host,
  449. unsigned int controller_idx);
  450. void isci_host_deinit(
  451. struct isci_host *);
  452. void isci_host_port_link_up(
  453. struct isci_host *,
  454. struct isci_port *,
  455. struct isci_phy *);
  456. int isci_host_dev_found(struct domain_device *);
  457. void isci_host_remote_device_start_complete(
  458. struct isci_host *,
  459. struct isci_remote_device *,
  460. enum sci_status);
  461. void scic_controller_disable_interrupts(
  462. struct isci_host *ihost);
  463. enum sci_status scic_controller_start_io(
  464. struct isci_host *ihost,
  465. struct isci_remote_device *idev,
  466. struct isci_request *ireq);
  467. enum sci_task_status scic_controller_start_task(
  468. struct isci_host *ihost,
  469. struct isci_remote_device *idev,
  470. struct isci_request *ireq);
  471. enum sci_status scic_controller_terminate_request(
  472. struct isci_host *ihost,
  473. struct isci_remote_device *idev,
  474. struct isci_request *ireq);
  475. enum sci_status scic_controller_complete_io(
  476. struct isci_host *ihost,
  477. struct isci_remote_device *idev,
  478. struct isci_request *ireq);
  479. void scic_sds_port_configuration_agent_construct(
  480. struct scic_sds_port_configuration_agent *port_agent);
  481. enum sci_status scic_sds_port_configuration_agent_initialize(
  482. struct isci_host *ihost,
  483. struct scic_sds_port_configuration_agent *port_agent);
  484. #endif