host.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818
  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 "pool.h"
  60. #include "state_machine.h"
  61. #include "remote_node_table.h"
  62. #include "registers.h"
  63. #include "scu_unsolicited_frame.h"
  64. #include "unsolicited_frame_control.h"
  65. #include "probe_roms.h"
  66. struct scic_sds_request;
  67. struct scu_task_context;
  68. /**
  69. * struct scic_power_control -
  70. *
  71. * This structure defines the fields for managing power control for direct
  72. * attached disk devices.
  73. */
  74. struct scic_power_control {
  75. /**
  76. * This field is set when the power control timer is running and cleared when
  77. * it is not.
  78. */
  79. bool timer_started;
  80. /**
  81. * Timer to control when the directed attached disks can consume power.
  82. */
  83. struct sci_timer timer;
  84. /**
  85. * This field is used to keep track of how many phys are put into the
  86. * requesters field.
  87. */
  88. u8 phys_waiting;
  89. /**
  90. * This field is used to keep track of how many phys have been granted to consume power
  91. */
  92. u8 phys_granted_power;
  93. /**
  94. * This field is an array of phys that we are waiting on. The phys are direct
  95. * mapped into requesters via struct scic_sds_phy.phy_index
  96. */
  97. struct scic_sds_phy *requesters[SCI_MAX_PHYS];
  98. };
  99. struct scic_sds_port_configuration_agent;
  100. typedef void (*port_config_fn)(struct scic_sds_controller *,
  101. struct scic_sds_port_configuration_agent *,
  102. struct scic_sds_port *, struct scic_sds_phy *);
  103. struct scic_sds_port_configuration_agent {
  104. u16 phy_configured_mask;
  105. u16 phy_ready_mask;
  106. struct {
  107. u8 min_index;
  108. u8 max_index;
  109. } phy_valid_port_range[SCI_MAX_PHYS];
  110. bool timer_pending;
  111. port_config_fn link_up_handler;
  112. port_config_fn link_down_handler;
  113. struct sci_timer timer;
  114. };
  115. /**
  116. * struct scic_sds_controller -
  117. *
  118. * This structure represents the SCU controller object.
  119. */
  120. struct scic_sds_controller {
  121. /**
  122. * This field contains the information for the base controller state
  123. * machine.
  124. */
  125. struct sci_base_state_machine state_machine;
  126. /**
  127. * This field is the driver timer object handler used to time the controller
  128. * object start and stop requests.
  129. */
  130. void *timeout_timer;
  131. /**
  132. * This field contains the user parameters to be utilized for this
  133. * core controller object.
  134. */
  135. union scic_user_parameters user_parameters;
  136. /**
  137. * This field contains the OEM parameters to be utilized for this
  138. * core controller object.
  139. */
  140. union scic_oem_parameters oem_parameters;
  141. /**
  142. * This field contains the port configuration agent for this controller.
  143. */
  144. struct scic_sds_port_configuration_agent port_agent;
  145. /**
  146. * This field is the array of device objects that are currently constructed
  147. * for this controller object. This table is used as a fast lookup of device
  148. * objects that need to handle device completion notifications from the
  149. * hardware. The table is RNi based.
  150. */
  151. struct scic_sds_remote_device *device_table[SCI_MAX_REMOTE_DEVICES];
  152. /**
  153. * This field is the array of IO request objects that are currently active for
  154. * this controller object. This table is used as a fast lookup of the io
  155. * request object that need to handle completion queue notifications. The
  156. * table is TCi based.
  157. */
  158. struct scic_sds_request *io_request_table[SCI_MAX_IO_REQUESTS];
  159. /**
  160. * This field is the free RNi data structure
  161. */
  162. struct scic_remote_node_table available_remote_nodes;
  163. /**
  164. * This field is the TCi pool used to manage the task context index.
  165. */
  166. SCI_POOL_CREATE(tci_pool, u16, SCI_MAX_IO_REQUESTS);
  167. /**
  168. * This filed is the struct scic_power_control data used to controll when direct
  169. * attached devices can consume power.
  170. */
  171. struct scic_power_control power_control;
  172. /**
  173. * This field is the array of sequence values for the IO Tag fields. Even
  174. * though only 4 bits of the field is used for the sequence the sequence is 16
  175. * bits in size so the sequence can be bitwise or'd with the TCi to build the
  176. * IO Tag value.
  177. */
  178. u16 io_request_sequence[SCI_MAX_IO_REQUESTS];
  179. /**
  180. * This field in the array of sequence values for the RNi. These are used
  181. * to control io request build to io request start operations. The sequence
  182. * value is recorded into an io request when it is built and is checked on
  183. * the io request start operation to make sure that there was not a device
  184. * hot plug between the build and start operation.
  185. */
  186. u8 remote_device_sequence[SCI_MAX_REMOTE_DEVICES];
  187. /**
  188. * This field is a pointer to the memory allocated by the driver for the task
  189. * context table. This data is shared between the hardware and software.
  190. */
  191. struct scu_task_context *task_context_table;
  192. /**
  193. * This field is a pointer to the memory allocated by the driver for the
  194. * remote node context table. This table is shared between the hardware and
  195. * software.
  196. */
  197. union scu_remote_node_context *remote_node_context_table;
  198. /**
  199. * This field is a pointer to the completion queue. This memory is
  200. * written to by the hardware and read by the software.
  201. */
  202. u32 *completion_queue;
  203. /**
  204. * This field is the software copy of the completion queue get pointer. The
  205. * controller object writes this value to the hardware after processing the
  206. * completion entries.
  207. */
  208. u32 completion_queue_get;
  209. /**
  210. * This field is the minimum of the number of hardware supported port entries
  211. * and the software requested port entries.
  212. */
  213. u32 logical_port_entries;
  214. /**
  215. * This field is the minimum number of hardware supported completion queue
  216. * entries and the software requested completion queue entries.
  217. */
  218. u32 completion_queue_entries;
  219. /**
  220. * This field is the minimum number of hardware supported event entries and
  221. * the software requested event entries.
  222. */
  223. u32 completion_event_entries;
  224. /**
  225. * This field is the minimum number of devices supported by the hardware and
  226. * the number of devices requested by the software.
  227. */
  228. u32 remote_node_entries;
  229. /**
  230. * This field is the minimum number of IO requests supported by the hardware
  231. * and the number of IO requests requested by the software.
  232. */
  233. u32 task_context_entries;
  234. /**
  235. * This object contains all of the unsolicited frame specific
  236. * data utilized by the core controller.
  237. */
  238. struct scic_sds_unsolicited_frame_control uf_control;
  239. /* Phy Startup Data */
  240. /**
  241. * This field is the driver timer handle for controller phy request startup.
  242. * On controller start the controller will start each PHY individually in
  243. * order of phy index.
  244. */
  245. void *phy_startup_timer;
  246. /**
  247. * This field is set when the phy_startup_timer is running and is cleared when
  248. * the phy_startup_timer is stopped.
  249. */
  250. bool phy_startup_timer_pending;
  251. /**
  252. * This field is the index of the next phy start. It is initialized to 0 and
  253. * increments for each phy index that is started.
  254. */
  255. u32 next_phy_to_start;
  256. /**
  257. * This field controlls the invalid link up notifications to the SCI_USER. If
  258. * an invalid_link_up notification is reported a bit for the PHY index is set
  259. * so further notifications are not made. Once the PHY object reports link up
  260. * and is made part of a port then this bit for the PHY index is cleared.
  261. */
  262. u8 invalid_phy_mask;
  263. /*
  264. * This field saves the current interrupt coalescing number of the controller.
  265. */
  266. u16 interrupt_coalesce_number;
  267. /*
  268. * This field saves the current interrupt coalescing timeout value in microseconds.
  269. */
  270. u32 interrupt_coalesce_timeout;
  271. /**
  272. * This field is a pointer to the memory mapped register space for the
  273. * struct smu_registers.
  274. */
  275. struct smu_registers __iomem *smu_registers;
  276. /**
  277. * This field is a pointer to the memory mapped register space for the
  278. * struct scu_registers.
  279. */
  280. struct scu_registers __iomem *scu_registers;
  281. };
  282. struct isci_host {
  283. struct scic_sds_controller sci;
  284. union scic_oem_parameters oem_parameters;
  285. int id; /* unique within a given pci device */
  286. struct list_head timers;
  287. void *core_ctrl_memory;
  288. struct dma_pool *dma_pool;
  289. struct isci_phy phys[SCI_MAX_PHYS];
  290. struct isci_port ports[SCI_MAX_PORTS + 1]; /* includes dummy port */
  291. struct sas_ha_struct sas_ha;
  292. int can_queue;
  293. spinlock_t queue_lock;
  294. spinlock_t state_lock;
  295. struct pci_dev *pdev;
  296. enum isci_status status;
  297. #define IHOST_START_PENDING 0
  298. #define IHOST_STOP_PENDING 1
  299. unsigned long flags;
  300. wait_queue_head_t eventq;
  301. struct Scsi_Host *shost;
  302. struct tasklet_struct completion_tasklet;
  303. struct list_head requests_to_complete;
  304. struct list_head requests_to_errorback;
  305. spinlock_t scic_lock;
  306. struct isci_remote_device devices[SCI_MAX_REMOTE_DEVICES];
  307. };
  308. /**
  309. * enum scic_sds_controller_states - This enumeration depicts all the states
  310. * for the common controller state machine.
  311. */
  312. enum scic_sds_controller_states {
  313. /**
  314. * Simply the initial state for the base controller state machine.
  315. */
  316. SCI_BASE_CONTROLLER_STATE_INITIAL = 0,
  317. /**
  318. * This state indicates that the controller is reset. The memory for
  319. * the controller is in it's initial state, but the controller requires
  320. * initialization.
  321. * This state is entered from the INITIAL state.
  322. * This state is entered from the RESETTING state.
  323. */
  324. SCI_BASE_CONTROLLER_STATE_RESET,
  325. /**
  326. * This state is typically an action state that indicates the controller
  327. * is in the process of initialization. In this state no new IO operations
  328. * are permitted.
  329. * This state is entered from the RESET state.
  330. */
  331. SCI_BASE_CONTROLLER_STATE_INITIALIZING,
  332. /**
  333. * This state indicates that the controller has been successfully
  334. * initialized. In this state no new IO operations are permitted.
  335. * This state is entered from the INITIALIZING state.
  336. */
  337. SCI_BASE_CONTROLLER_STATE_INITIALIZED,
  338. /**
  339. * This state indicates the the controller is in the process of becoming
  340. * ready (i.e. starting). In this state no new IO operations are permitted.
  341. * This state is entered from the INITIALIZED state.
  342. */
  343. SCI_BASE_CONTROLLER_STATE_STARTING,
  344. /**
  345. * This state indicates the controller is now ready. Thus, the user
  346. * is able to perform IO operations on the controller.
  347. * This state is entered from the STARTING state.
  348. */
  349. SCI_BASE_CONTROLLER_STATE_READY,
  350. /**
  351. * This state is typically an action state that indicates the controller
  352. * is in the process of resetting. Thus, the user is unable to perform
  353. * IO operations on the controller. A reset is considered destructive in
  354. * most cases.
  355. * This state is entered from the READY state.
  356. * This state is entered from the FAILED state.
  357. * This state is entered from the STOPPED state.
  358. */
  359. SCI_BASE_CONTROLLER_STATE_RESETTING,
  360. /**
  361. * This state indicates that the controller is in the process of stopping.
  362. * In this state no new IO operations are permitted, but existing IO
  363. * operations are allowed to complete.
  364. * This state is entered from the READY state.
  365. */
  366. SCI_BASE_CONTROLLER_STATE_STOPPING,
  367. /**
  368. * This state indicates that the controller has successfully been stopped.
  369. * In this state no new IO operations are permitted.
  370. * This state is entered from the STOPPING state.
  371. */
  372. SCI_BASE_CONTROLLER_STATE_STOPPED,
  373. /**
  374. * This state indicates that the controller could not successfully be
  375. * initialized. In this state no new IO operations are permitted.
  376. * This state is entered from the INITIALIZING state.
  377. * This state is entered from the STARTING state.
  378. * This state is entered from the STOPPING state.
  379. * This state is entered from the RESETTING state.
  380. */
  381. SCI_BASE_CONTROLLER_STATE_FAILED,
  382. SCI_BASE_CONTROLLER_MAX_STATES
  383. };
  384. /**
  385. * struct isci_pci_info - This class represents the pci function containing the
  386. * controllers. Depending on PCI SKU, there could be up to 2 controllers in
  387. * the PCI function.
  388. */
  389. #define SCI_MAX_MSIX_INT (SCI_NUM_MSI_X_INT*SCI_MAX_CONTROLLERS)
  390. struct isci_pci_info {
  391. struct msix_entry msix_entries[SCI_MAX_MSIX_INT];
  392. struct isci_host *hosts[SCI_MAX_CONTROLLERS];
  393. struct isci_orom *orom;
  394. };
  395. static inline struct isci_pci_info *to_pci_info(struct pci_dev *pdev)
  396. {
  397. return pci_get_drvdata(pdev);
  398. }
  399. #define for_each_isci_host(id, ihost, pdev) \
  400. for (id = 0, ihost = to_pci_info(pdev)->hosts[id]; \
  401. id < ARRAY_SIZE(to_pci_info(pdev)->hosts) && ihost; \
  402. ihost = to_pci_info(pdev)->hosts[++id])
  403. static inline enum isci_status isci_host_get_state(struct isci_host *isci_host)
  404. {
  405. return isci_host->status;
  406. }
  407. static inline void isci_host_change_state(struct isci_host *isci_host,
  408. enum isci_status status)
  409. {
  410. unsigned long flags;
  411. dev_dbg(&isci_host->pdev->dev,
  412. "%s: isci_host = %p, state = 0x%x",
  413. __func__,
  414. isci_host,
  415. status);
  416. spin_lock_irqsave(&isci_host->state_lock, flags);
  417. isci_host->status = status;
  418. spin_unlock_irqrestore(&isci_host->state_lock, flags);
  419. }
  420. static inline int isci_host_can_queue(struct isci_host *isci_host, int num)
  421. {
  422. int ret = 0;
  423. unsigned long flags;
  424. spin_lock_irqsave(&isci_host->queue_lock, flags);
  425. if ((isci_host->can_queue - num) < 0) {
  426. dev_dbg(&isci_host->pdev->dev,
  427. "%s: isci_host->can_queue = %d\n",
  428. __func__,
  429. isci_host->can_queue);
  430. ret = -SAS_QUEUE_FULL;
  431. } else
  432. isci_host->can_queue -= num;
  433. spin_unlock_irqrestore(&isci_host->queue_lock, flags);
  434. return ret;
  435. }
  436. static inline void isci_host_can_dequeue(struct isci_host *isci_host, int num)
  437. {
  438. unsigned long flags;
  439. spin_lock_irqsave(&isci_host->queue_lock, flags);
  440. isci_host->can_queue += num;
  441. spin_unlock_irqrestore(&isci_host->queue_lock, flags);
  442. }
  443. static inline void wait_for_start(struct isci_host *ihost)
  444. {
  445. wait_event(ihost->eventq, !test_bit(IHOST_START_PENDING, &ihost->flags));
  446. }
  447. static inline void wait_for_stop(struct isci_host *ihost)
  448. {
  449. wait_event(ihost->eventq, !test_bit(IHOST_STOP_PENDING, &ihost->flags));
  450. }
  451. static inline void wait_for_device_start(struct isci_host *ihost, struct isci_remote_device *idev)
  452. {
  453. wait_event(ihost->eventq, !test_bit(IDEV_START_PENDING, &idev->flags));
  454. }
  455. static inline void wait_for_device_stop(struct isci_host *ihost, struct isci_remote_device *idev)
  456. {
  457. wait_event(ihost->eventq, !test_bit(IDEV_STOP_PENDING, &idev->flags));
  458. }
  459. static inline struct isci_host *dev_to_ihost(struct domain_device *dev)
  460. {
  461. return dev->port->ha->lldd_ha;
  462. }
  463. static inline struct isci_host *scic_to_ihost(struct scic_sds_controller *scic)
  464. {
  465. /* XXX delete after merging scic_sds_contoller and isci_host */
  466. struct isci_host *ihost = container_of(scic, typeof(*ihost), sci);
  467. return ihost;
  468. }
  469. /**
  470. * INCREMENT_QUEUE_GET() -
  471. *
  472. * This macro will increment the specified index to and if the index wraps to 0
  473. * it will toggel the cycle bit.
  474. */
  475. #define INCREMENT_QUEUE_GET(index, cycle, entry_count, bit_toggle) \
  476. { \
  477. if ((index) + 1 == entry_count) { \
  478. (index) = 0; \
  479. (cycle) = (cycle) ^ (bit_toggle); \
  480. } else { \
  481. index = index + 1; \
  482. } \
  483. }
  484. /**
  485. * scic_sds_controller_get_protocol_engine_group() -
  486. *
  487. * This macro returns the protocol engine group for this controller object.
  488. * Presently we only support protocol engine group 0 so just return that
  489. */
  490. #define scic_sds_controller_get_protocol_engine_group(controller) 0
  491. /**
  492. * scic_sds_io_tag_construct() -
  493. *
  494. * This macro constructs an IO tag from the sequence and index values.
  495. */
  496. #define scic_sds_io_tag_construct(sequence, task_index) \
  497. ((sequence) << 12 | (task_index))
  498. /**
  499. * scic_sds_io_tag_get_sequence() -
  500. *
  501. * This macro returns the IO sequence from the IO tag value.
  502. */
  503. #define scic_sds_io_tag_get_sequence(io_tag) \
  504. (((io_tag) & 0xF000) >> 12)
  505. /**
  506. * scic_sds_io_tag_get_index() -
  507. *
  508. * This macro returns the TCi from the io tag value
  509. */
  510. #define scic_sds_io_tag_get_index(io_tag) \
  511. ((io_tag) & 0x0FFF)
  512. /**
  513. * scic_sds_io_sequence_increment() -
  514. *
  515. * This is a helper macro to increment the io sequence count. We may find in
  516. * the future that it will be faster to store the sequence count in such a way
  517. * as we dont perform the shift operation to build io tag values so therefore
  518. * need a way to incrment them correctly
  519. */
  520. #define scic_sds_io_sequence_increment(value) \
  521. ((value) = (((value) + 1) & 0x000F))
  522. /* expander attached sata devices require 3 rnc slots */
  523. static inline int scic_sds_remote_device_node_count(struct scic_sds_remote_device *sci_dev)
  524. {
  525. struct domain_device *dev = sci_dev_to_domain(sci_dev);
  526. if ((dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) &&
  527. !sci_dev->is_direct_attached)
  528. return SCU_STP_REMOTE_NODE_COUNT;
  529. return SCU_SSP_REMOTE_NODE_COUNT;
  530. }
  531. /**
  532. * scic_sds_controller_set_invalid_phy() -
  533. *
  534. * This macro will set the bit in the invalid phy mask for this controller
  535. * object. This is used to control messages reported for invalid link up
  536. * notifications.
  537. */
  538. #define scic_sds_controller_set_invalid_phy(controller, phy) \
  539. ((controller)->invalid_phy_mask |= (1 << (phy)->phy_index))
  540. /**
  541. * scic_sds_controller_clear_invalid_phy() -
  542. *
  543. * This macro will clear the bit in the invalid phy mask for this controller
  544. * object. This is used to control messages reported for invalid link up
  545. * notifications.
  546. */
  547. #define scic_sds_controller_clear_invalid_phy(controller, phy) \
  548. ((controller)->invalid_phy_mask &= ~(1 << (phy)->phy_index))
  549. static inline struct device *scic_to_dev(struct scic_sds_controller *scic)
  550. {
  551. return &scic_to_ihost(scic)->pdev->dev;
  552. }
  553. static inline struct device *sciphy_to_dev(struct scic_sds_phy *sci_phy)
  554. {
  555. struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
  556. if (!iphy || !iphy->isci_port || !iphy->isci_port->isci_host)
  557. return NULL;
  558. return &iphy->isci_port->isci_host->pdev->dev;
  559. }
  560. static inline struct device *sciport_to_dev(struct scic_sds_port *sci_port)
  561. {
  562. struct isci_port *iport = sci_port_to_iport(sci_port);
  563. if (!iport || !iport->isci_host)
  564. return NULL;
  565. return &iport->isci_host->pdev->dev;
  566. }
  567. static inline struct device *scirdev_to_dev(struct scic_sds_remote_device *sci_dev)
  568. {
  569. struct isci_remote_device *idev =
  570. container_of(sci_dev, typeof(*idev), sci);
  571. if (!idev || !idev->isci_port || !idev->isci_port->isci_host)
  572. return NULL;
  573. return &idev->isci_port->isci_host->pdev->dev;
  574. }
  575. enum {
  576. ISCI_SI_REVA0,
  577. ISCI_SI_REVA2,
  578. ISCI_SI_REVB0,
  579. };
  580. extern int isci_si_rev;
  581. static inline bool is_a0(void)
  582. {
  583. return isci_si_rev == ISCI_SI_REVA0;
  584. }
  585. static inline bool is_a2(void)
  586. {
  587. return isci_si_rev == ISCI_SI_REVA2;
  588. }
  589. static inline bool is_b0(void)
  590. {
  591. return isci_si_rev > ISCI_SI_REVA2;
  592. }
  593. void scic_sds_controller_post_request(struct scic_sds_controller *scic,
  594. u32 request);
  595. void scic_sds_controller_release_frame(struct scic_sds_controller *scic,
  596. u32 frame_index);
  597. void scic_sds_controller_copy_sata_response(void *response_buffer,
  598. void *frame_header,
  599. void *frame_buffer);
  600. enum sci_status scic_sds_controller_allocate_remote_node_context(struct scic_sds_controller *scic,
  601. struct scic_sds_remote_device *sci_dev,
  602. u16 *node_id);
  603. void scic_sds_controller_free_remote_node_context(
  604. struct scic_sds_controller *scic,
  605. struct scic_sds_remote_device *sci_dev,
  606. u16 node_id);
  607. union scu_remote_node_context *scic_sds_controller_get_remote_node_context_buffer(
  608. struct scic_sds_controller *scic,
  609. u16 node_id);
  610. struct scic_sds_request *scic_request_by_tag(struct scic_sds_controller *scic,
  611. u16 io_tag);
  612. struct scu_task_context *scic_sds_controller_get_task_context_buffer(
  613. struct scic_sds_controller *scic,
  614. u16 io_tag);
  615. void scic_sds_controller_power_control_queue_insert(
  616. struct scic_sds_controller *scic,
  617. struct scic_sds_phy *sci_phy);
  618. void scic_sds_controller_power_control_queue_remove(
  619. struct scic_sds_controller *scic,
  620. struct scic_sds_phy *sci_phy);
  621. void scic_sds_controller_link_up(
  622. struct scic_sds_controller *scic,
  623. struct scic_sds_port *sci_port,
  624. struct scic_sds_phy *sci_phy);
  625. void scic_sds_controller_link_down(
  626. struct scic_sds_controller *scic,
  627. struct scic_sds_port *sci_port,
  628. struct scic_sds_phy *sci_phy);
  629. void scic_sds_controller_remote_device_stopped(
  630. struct scic_sds_controller *scic,
  631. struct scic_sds_remote_device *sci_dev);
  632. void scic_sds_controller_copy_task_context(
  633. struct scic_sds_controller *scic,
  634. struct scic_sds_request *this_request);
  635. void scic_sds_controller_register_setup(struct scic_sds_controller *scic);
  636. enum sci_status scic_controller_continue_io(struct scic_sds_request *sci_req);
  637. int isci_host_scan_finished(struct Scsi_Host *, unsigned long);
  638. void isci_host_scan_start(struct Scsi_Host *);
  639. int isci_host_init(struct isci_host *);
  640. void isci_host_init_controller_names(
  641. struct isci_host *isci_host,
  642. unsigned int controller_idx);
  643. void isci_host_deinit(
  644. struct isci_host *);
  645. void isci_host_port_link_up(
  646. struct isci_host *,
  647. struct scic_sds_port *,
  648. struct scic_sds_phy *);
  649. int isci_host_dev_found(struct domain_device *);
  650. void isci_host_remote_device_start_complete(
  651. struct isci_host *,
  652. struct isci_remote_device *,
  653. enum sci_status);
  654. void scic_controller_disable_interrupts(
  655. struct scic_sds_controller *scic);
  656. enum sci_status scic_controller_start_io(
  657. struct scic_sds_controller *scic,
  658. struct scic_sds_remote_device *remote_device,
  659. struct scic_sds_request *io_request,
  660. u16 io_tag);
  661. enum sci_task_status scic_controller_start_task(
  662. struct scic_sds_controller *scic,
  663. struct scic_sds_remote_device *remote_device,
  664. struct scic_sds_request *task_request,
  665. u16 io_tag);
  666. enum sci_status scic_controller_terminate_request(
  667. struct scic_sds_controller *scic,
  668. struct scic_sds_remote_device *remote_device,
  669. struct scic_sds_request *request);
  670. enum sci_status scic_controller_complete_io(
  671. struct scic_sds_controller *scic,
  672. struct scic_sds_remote_device *remote_device,
  673. struct scic_sds_request *io_request);
  674. u16 scic_controller_allocate_io_tag(
  675. struct scic_sds_controller *scic);
  676. enum sci_status scic_controller_free_io_tag(
  677. struct scic_sds_controller *scic,
  678. u16 io_tag);
  679. void scic_sds_port_configuration_agent_construct(
  680. struct scic_sds_port_configuration_agent *port_agent);
  681. enum sci_status scic_sds_port_configuration_agent_initialize(
  682. struct scic_sds_controller *controller,
  683. struct scic_sds_port_configuration_agent *port_agent);
  684. #endif