aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/isci/host.h
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/isci/host.h')
-rw-r--r--drivers/scsi/isci/host.h612
1 files changed, 575 insertions, 37 deletions
diff --git a/drivers/scsi/isci/host.h b/drivers/scsi/isci/host.h
index 13c1c99ef29..1f542c47fb3 100644
--- a/drivers/scsi/isci/host.h
+++ b/drivers/scsi/isci/host.h
@@ -52,13 +52,258 @@
52 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 53 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54 */ 54 */
55
56#ifndef _SCI_HOST_H_ 55#ifndef _SCI_HOST_H_
57#define _SCI_HOST_H_ 56#define _SCI_HOST_H_
58 57
59#include "scic_sds_controller.h" 58#include "scic_config_parameters.h"
60#include "remote_device.h" 59#include "remote_device.h"
61#include "phy.h" 60#include "phy.h"
61#include "pool.h"
62#include "sci_base_state_machine.h"
63#include "remote_node_table.h"
64#include "scu_registers.h"
65#include "scu_unsolicited_frame.h"
66#include "scic_sds_unsolicited_frame_control.h"
67#include "scic_sds_port_configuration_agent.h"
68
69struct scic_sds_request;
70struct scu_task_context;
71
72/**
73 * struct scic_power_control -
74 *
75 * This structure defines the fields for managing power control for direct
76 * attached disk devices.
77 */
78struct scic_power_control {
79 /**
80 * This field is set when the power control timer is running and cleared when
81 * it is not.
82 */
83 bool timer_started;
84
85 /**
86 * This field is the handle to the driver timer object. This timer is used to
87 * control when the directed attached disks can consume power.
88 */
89 void *timer;
90
91 /**
92 * This field is used to keep track of how many phys are put into the
93 * requesters field.
94 */
95 u8 phys_waiting;
96
97 /**
98 * This field is used to keep track of how many phys have been granted to consume power
99 */
100 u8 phys_granted_power;
101
102 /**
103 * This field is an array of phys that we are waiting on. The phys are direct
104 * mapped into requesters via struct scic_sds_phy.phy_index
105 */
106 struct scic_sds_phy *requesters[SCI_MAX_PHYS];
107
108};
109
110/**
111 * struct scic_sds_controller -
112 *
113 * This structure represents the SCU controller object.
114 */
115struct scic_sds_controller {
116 /**
117 * This field contains the information for the base controller state
118 * machine.
119 */
120 struct sci_base_state_machine state_machine;
121
122 /**
123 * This field is the driver timer object handler used to time the controller
124 * object start and stop requests.
125 */
126 void *timeout_timer;
127
128 /**
129 * This field contains the user parameters to be utilized for this
130 * core controller object.
131 */
132 union scic_user_parameters user_parameters;
133
134 /**
135 * This field contains the OEM parameters to be utilized for this
136 * core controller object.
137 */
138 union scic_oem_parameters oem_parameters;
139
140 /**
141 * This field contains the port configuration agent for this controller.
142 */
143 struct scic_sds_port_configuration_agent port_agent;
144
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 /**
154 * This field is the array of IO request objects that are currently active for
155 * this controller object. This table is used as a fast lookup of the io
156 * request object that need to handle completion queue notifications. The
157 * table is TCi based.
158 */
159 struct scic_sds_request *io_request_table[SCI_MAX_IO_REQUESTS];
160
161 /**
162 * This field is the free RNi data structure
163 */
164 struct scic_remote_node_table available_remote_nodes;
165
166 /**
167 * This field is the TCi pool used to manage the task context index.
168 */
169 SCI_POOL_CREATE(tci_pool, u16, SCI_MAX_IO_REQUESTS);
170
171 /**
172 * This filed is the struct scic_power_control data used to controll when direct
173 * attached devices can consume power.
174 */
175 struct scic_power_control power_control;
176
177 /**
178 * This field is the array of sequence values for the IO Tag fields. Even
179 * though only 4 bits of the field is used for the sequence the sequence is 16
180 * bits in size so the sequence can be bitwise or'd with the TCi to build the
181 * IO Tag value.
182 */
183 u16 io_request_sequence[SCI_MAX_IO_REQUESTS];
184
185 /**
186 * This field in the array of sequence values for the RNi. These are used
187 * to control io request build to io request start operations. The sequence
188 * value is recorded into an io request when it is built and is checked on
189 * the io request start operation to make sure that there was not a device
190 * hot plug between the build and start operation.
191 */
192 u8 remote_device_sequence[SCI_MAX_REMOTE_DEVICES];
193
194 /**
195 * This field is a pointer to the memory allocated by the driver for the task
196 * context table. This data is shared between the hardware and software.
197 */
198 struct scu_task_context *task_context_table;
199
200 /**
201 * This field is a pointer to the memory allocated by the driver for the
202 * remote node context table. This table is shared between the hardware and
203 * software.
204 */
205 union scu_remote_node_context *remote_node_context_table;
206
207 /**
208 * This field is a pointer to the completion queue. This memory is
209 * written to by the hardware and read by the software.
210 */
211 u32 *completion_queue;
212
213 /**
214 * This field is the software copy of the completion queue get pointer. The
215 * controller object writes this value to the hardware after processing the
216 * completion entries.
217 */
218 u32 completion_queue_get;
219
220 /**
221 * This field is the minimum of the number of hardware supported port entries
222 * and the software requested port entries.
223 */
224 u32 logical_port_entries;
225
226 /**
227 * This field is the minimum number of hardware supported completion queue
228 * entries and the software requested completion queue entries.
229 */
230 u32 completion_queue_entries;
231
232 /**
233 * This field is the minimum number of hardware supported event entries and
234 * the software requested event entries.
235 */
236 u32 completion_event_entries;
237
238 /**
239 * This field is the minimum number of devices supported by the hardware and
240 * the number of devices requested by the software.
241 */
242 u32 remote_node_entries;
243
244 /**
245 * This field is the minimum number of IO requests supported by the hardware
246 * and the number of IO requests requested by the software.
247 */
248 u32 task_context_entries;
249
250 /**
251 * This object contains all of the unsolicited frame specific
252 * data utilized by the core controller.
253 */
254 struct scic_sds_unsolicited_frame_control uf_control;
255
256 /* Phy Startup Data */
257 /**
258 * This field is the driver timer handle for controller phy request startup.
259 * On controller start the controller will start each PHY individually in
260 * order of phy index.
261 */
262 void *phy_startup_timer;
263
264 /**
265 * This field is set when the phy_startup_timer is running and is cleared when
266 * the phy_startup_timer is stopped.
267 */
268 bool phy_startup_timer_pending;
269
270 /**
271 * This field is the index of the next phy start. It is initialized to 0 and
272 * increments for each phy index that is started.
273 */
274 u32 next_phy_to_start;
275
276 /**
277 * This field controlls the invalid link up notifications to the SCI_USER. If
278 * an invalid_link_up notification is reported a bit for the PHY index is set
279 * so further notifications are not made. Once the PHY object reports link up
280 * and is made part of a port then this bit for the PHY index is cleared.
281 */
282 u8 invalid_phy_mask;
283
284 /*
285 * This field saves the current interrupt coalescing number of the controller.
286 */
287 u16 interrupt_coalesce_number;
288
289 /*
290 * This field saves the current interrupt coalescing timeout value in microseconds.
291 */
292 u32 interrupt_coalesce_timeout;
293
294 /**
295 * This field is a pointer to the memory mapped register space for the
296 * struct smu_registers.
297 */
298 struct smu_registers __iomem *smu_registers;
299
300 /**
301 * This field is a pointer to the memory mapped register space for the
302 * struct scu_registers.
303 */
304 struct scu_registers __iomem *scu_registers;
305
306};
62 307
63struct isci_host { 308struct isci_host {
64 struct scic_sds_controller sci; 309 struct scic_sds_controller sci;
@@ -93,6 +338,96 @@ struct isci_host {
93}; 338};
94 339
95/** 340/**
341 * enum scic_sds_controller_states - This enumeration depicts all the states
342 * for the common controller state machine.
343 */
344enum scic_sds_controller_states {
345 /**
346 * Simply the initial state for the base controller state machine.
347 */
348 SCI_BASE_CONTROLLER_STATE_INITIAL = 0,
349
350 /**
351 * This state indicates that the controller is reset. The memory for
352 * the controller is in it's initial state, but the controller requires
353 * initialization.
354 * This state is entered from the INITIAL state.
355 * This state is entered from the RESETTING state.
356 */
357 SCI_BASE_CONTROLLER_STATE_RESET,
358
359 /**
360 * This state is typically an action state that indicates the controller
361 * is in the process of initialization. In this state no new IO operations
362 * are permitted.
363 * This state is entered from the RESET state.
364 */
365 SCI_BASE_CONTROLLER_STATE_INITIALIZING,
366
367 /**
368 * This state indicates that the controller has been successfully
369 * initialized. In this state no new IO operations are permitted.
370 * This state is entered from the INITIALIZING state.
371 */
372 SCI_BASE_CONTROLLER_STATE_INITIALIZED,
373
374 /**
375 * This state indicates the the controller is in the process of becoming
376 * ready (i.e. starting). In this state no new IO operations are permitted.
377 * This state is entered from the INITIALIZED state.
378 */
379 SCI_BASE_CONTROLLER_STATE_STARTING,
380
381 /**
382 * This state indicates the controller is now ready. Thus, the user
383 * is able to perform IO operations on the controller.
384 * This state is entered from the STARTING state.
385 */
386 SCI_BASE_CONTROLLER_STATE_READY,
387
388 /**
389 * This state is typically an action state that indicates the controller
390 * is in the process of resetting. Thus, the user is unable to perform
391 * IO operations on the controller. A reset is considered destructive in
392 * most cases.
393 * This state is entered from the READY state.
394 * This state is entered from the FAILED state.
395 * This state is entered from the STOPPED state.
396 */
397 SCI_BASE_CONTROLLER_STATE_RESETTING,
398
399 /**
400 * This state indicates that the controller is in the process of stopping.
401 * In this state no new IO operations are permitted, but existing IO
402 * operations are allowed to complete.
403 * This state is entered from the READY state.
404 */
405 SCI_BASE_CONTROLLER_STATE_STOPPING,
406
407 /**
408 * This state indicates that the controller has successfully been stopped.
409 * In this state no new IO operations are permitted.
410 * This state is entered from the STOPPING state.
411 */
412 SCI_BASE_CONTROLLER_STATE_STOPPED,
413
414 /**
415 * This state indicates that the controller could not successfully be
416 * initialized. In this state no new IO operations are permitted.
417 * This state is entered from the INITIALIZING state.
418 * This state is entered from the STARTING state.
419 * This state is entered from the STOPPING state.
420 * This state is entered from the RESETTING state.
421 */
422 SCI_BASE_CONTROLLER_STATE_FAILED,
423
424 SCI_BASE_CONTROLLER_MAX_STATES
425
426};
427
428
429
430/**
96 * struct isci_pci_info - This class represents the pci function containing the 431 * struct isci_pci_info - This class represents the pci function containing the
97 * controllers. Depending on PCI SKU, there could be up to 2 controllers in 432 * controllers. Depending on PCI SKU, there could be up to 2 controllers in
98 * the PCI function. 433 * the PCI function.
@@ -115,17 +450,13 @@ static inline struct isci_pci_info *to_pci_info(struct pci_dev *pdev)
115 id < ARRAY_SIZE(to_pci_info(pdev)->hosts) && ihost; \ 450 id < ARRAY_SIZE(to_pci_info(pdev)->hosts) && ihost; \
116 ihost = to_pci_info(pdev)->hosts[++id]) 451 ihost = to_pci_info(pdev)->hosts[++id])
117 452
118static inline 453static inline enum isci_status isci_host_get_state(struct isci_host *isci_host)
119enum isci_status isci_host_get_state(
120 struct isci_host *isci_host)
121{ 454{
122 return isci_host->status; 455 return isci_host->status;
123} 456}
124 457
125 458static inline void isci_host_change_state(struct isci_host *isci_host,
126static inline void isci_host_change_state( 459 enum isci_status status)
127 struct isci_host *isci_host,
128 enum isci_status status)
129{ 460{
130 unsigned long flags; 461 unsigned long flags;
131 462
@@ -140,9 +471,7 @@ static inline void isci_host_change_state(
140 471
141} 472}
142 473
143static inline int isci_host_can_queue( 474static inline int isci_host_can_queue(struct isci_host *isci_host, int num)
144 struct isci_host *isci_host,
145 int num)
146{ 475{
147 int ret = 0; 476 int ret = 0;
148 unsigned long flags; 477 unsigned long flags;
@@ -163,9 +492,7 @@ static inline int isci_host_can_queue(
163 return ret; 492 return ret;
164} 493}
165 494
166static inline void isci_host_can_dequeue( 495static inline void isci_host_can_dequeue(struct isci_host *isci_host, int num)
167 struct isci_host *isci_host,
168 int num)
169{ 496{
170 unsigned long flags; 497 unsigned long flags;
171 498
@@ -208,39 +535,219 @@ static inline struct isci_host *scic_to_ihost(struct scic_sds_controller *scic)
208} 535}
209 536
210/** 537/**
211 * isci_host_scan_finished() - 538 * INCREMENT_QUEUE_GET() -
212 * 539 *
213 * This function is one of the SCSI Host Template functions. The SCSI midlayer 540 * This macro will increment the specified index to and if the index wraps to 0
214 * calls this function during a target scan, approx. once every 10 millisecs. 541 * it will toggel the cycle bit.
215 */ 542 */
216int isci_host_scan_finished( 543#define INCREMENT_QUEUE_GET(index, cycle, entry_count, bit_toggle) \
217 struct Scsi_Host *, 544 { \
218 unsigned long); 545 if ((index) + 1 == entry_count) { \
546 (index) = 0; \
547 (cycle) = (cycle) ^ (bit_toggle); \
548 } else { \
549 index = index + 1; \
550 } \
551 }
219 552
553/**
554 * scic_sds_controller_get_port_configuration_agent() -
555 *
556 * This is a helper macro to get the port configuration agent from the
557 * controller object.
558 */
559#define scic_sds_controller_get_port_configuration_agent(controller) \
560 (&(controller)->port_agent)
220 561
221/** 562/**
222 * isci_host_scan_start() - 563 * scic_sds_controller_get_protocol_engine_group() -
223 * 564 *
224 * This function is one of the SCSI Host Template function, called by the SCSI 565 * This macro returns the protocol engine group for this controller object.
225 * mid layer berfore a target scan begins. The core library controller start 566 * Presently we only support protocol engine group 0 so just return that
226 * routine is called from here.
227 */ 567 */
228void isci_host_scan_start( 568#define scic_sds_controller_get_protocol_engine_group(controller) 0
229 struct Scsi_Host *);
230 569
231/** 570/**
232 * isci_host_start_complete() - 571 * scic_sds_io_tag_construct() -
233 * 572 *
234 * This function is called by the core library, through the ISCI Module, to 573 * This macro constructs an IO tag from the sequence and index values.
235 * indicate controller start status.
236 */ 574 */
237void isci_host_start_complete( 575#define scic_sds_io_tag_construct(sequence, task_index) \
238 struct isci_host *, 576 ((sequence) << 12 | (task_index))
239 enum sci_status);
240 577
241void isci_host_stop_complete( 578/**
242 struct isci_host *isci_host, 579 * scic_sds_io_tag_get_sequence() -
243 enum sci_status completion_status); 580 *
581 * This macro returns the IO sequence from the IO tag value.
582 */
583#define scic_sds_io_tag_get_sequence(io_tag) \
584 (((io_tag) & 0xF000) >> 12)
585
586/**
587 * scic_sds_io_tag_get_index() -
588 *
589 * This macro returns the TCi from the io tag value
590 */
591#define scic_sds_io_tag_get_index(io_tag) \
592 ((io_tag) & 0x0FFF)
593
594/**
595 * scic_sds_io_sequence_increment() -
596 *
597 * This is a helper macro to increment the io sequence count. We may find in
598 * the future that it will be faster to store the sequence count in such a way
599 * as we dont perform the shift operation to build io tag values so therefore
600 * need a way to incrment them correctly
601 */
602#define scic_sds_io_sequence_increment(value) \
603 ((value) = (((value) + 1) & 0x000F))
604
605/* expander attached sata devices require 3 rnc slots */
606static inline int scic_sds_remote_device_node_count(struct scic_sds_remote_device *sci_dev)
607{
608 struct domain_device *dev = sci_dev_to_domain(sci_dev);
609
610 if ((dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) &&
611 !sci_dev->is_direct_attached)
612 return SCU_STP_REMOTE_NODE_COUNT;
613 return SCU_SSP_REMOTE_NODE_COUNT;
614}
615
616/**
617 * scic_sds_controller_set_invalid_phy() -
618 *
619 * This macro will set the bit in the invalid phy mask for this controller
620 * object. This is used to control messages reported for invalid link up
621 * notifications.
622 */
623#define scic_sds_controller_set_invalid_phy(controller, phy) \
624 ((controller)->invalid_phy_mask |= (1 << (phy)->phy_index))
625
626/**
627 * scic_sds_controller_clear_invalid_phy() -
628 *
629 * This macro will clear the bit in the invalid phy mask for this controller
630 * object. This is used to control messages reported for invalid link up
631 * notifications.
632 */
633#define scic_sds_controller_clear_invalid_phy(controller, phy) \
634 ((controller)->invalid_phy_mask &= ~(1 << (phy)->phy_index))
635
636static inline struct device *scic_to_dev(struct scic_sds_controller *scic)
637{
638 return &scic_to_ihost(scic)->pdev->dev;
639}
640
641static inline struct device *sciphy_to_dev(struct scic_sds_phy *sci_phy)
642{
643 struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
644
645 if (!iphy || !iphy->isci_port || !iphy->isci_port->isci_host)
646 return NULL;
647
648 return &iphy->isci_port->isci_host->pdev->dev;
649}
650
651static inline struct device *sciport_to_dev(struct scic_sds_port *sci_port)
652{
653 struct isci_port *iport = sci_port_to_iport(sci_port);
654
655 if (!iport || !iport->isci_host)
656 return NULL;
657
658 return &iport->isci_host->pdev->dev;
659}
660
661static inline struct device *scirdev_to_dev(struct scic_sds_remote_device *sci_dev)
662{
663 struct isci_remote_device *idev =
664 container_of(sci_dev, typeof(*idev), sci);
665
666 if (!idev || !idev->isci_port || !idev->isci_port->isci_host)
667 return NULL;
668
669 return &idev->isci_port->isci_host->pdev->dev;
670}
671
672enum {
673 ISCI_SI_REVA0,
674 ISCI_SI_REVA2,
675 ISCI_SI_REVB0,
676};
677
678extern int isci_si_rev;
679
680static inline bool is_a0(void)
681{
682 return isci_si_rev == ISCI_SI_REVA0;
683}
684
685static inline bool is_a2(void)
686{
687 return isci_si_rev == ISCI_SI_REVA2;
688}
689
690static inline bool is_b0(void)
691{
692 return isci_si_rev > ISCI_SI_REVA2;
693}
694
695void scic_sds_controller_post_request(struct scic_sds_controller *scic,
696 u32 request);
697void scic_sds_controller_release_frame(struct scic_sds_controller *scic,
698 u32 frame_index);
699void scic_sds_controller_copy_sata_response(void *response_buffer,
700 void *frame_header,
701 void *frame_buffer);
702enum sci_status scic_sds_controller_allocate_remote_node_context(struct scic_sds_controller *scic,
703 struct scic_sds_remote_device *sci_dev,
704 u16 *node_id);
705void scic_sds_controller_free_remote_node_context(
706 struct scic_sds_controller *scic,
707 struct scic_sds_remote_device *sci_dev,
708 u16 node_id);
709union scu_remote_node_context *scic_sds_controller_get_remote_node_context_buffer(
710 struct scic_sds_controller *scic,
711 u16 node_id);
712
713struct scic_sds_request *scic_request_by_tag(struct scic_sds_controller *scic,
714 u16 io_tag);
715
716struct scu_task_context *scic_sds_controller_get_task_context_buffer(
717 struct scic_sds_controller *scic,
718 u16 io_tag);
719
720void scic_sds_controller_power_control_queue_insert(
721 struct scic_sds_controller *scic,
722 struct scic_sds_phy *sci_phy);
723
724void scic_sds_controller_power_control_queue_remove(
725 struct scic_sds_controller *scic,
726 struct scic_sds_phy *sci_phy);
727
728void scic_sds_controller_link_up(
729 struct scic_sds_controller *scic,
730 struct scic_sds_port *sci_port,
731 struct scic_sds_phy *sci_phy);
732
733void scic_sds_controller_link_down(
734 struct scic_sds_controller *scic,
735 struct scic_sds_port *sci_port,
736 struct scic_sds_phy *sci_phy);
737
738void scic_sds_controller_remote_device_stopped(
739 struct scic_sds_controller *scic,
740 struct scic_sds_remote_device *sci_dev);
741
742void scic_sds_controller_copy_task_context(
743 struct scic_sds_controller *scic,
744 struct scic_sds_request *this_request);
745
746void scic_sds_controller_register_setup(struct scic_sds_controller *scic);
747
748enum sci_status scic_controller_continue_io(struct scic_sds_request *sci_req);
749int isci_host_scan_finished(struct Scsi_Host *, unsigned long);
750void isci_host_scan_start(struct Scsi_Host *);
244 751
245int isci_host_init(struct isci_host *); 752int isci_host_init(struct isci_host *);
246 753
@@ -262,4 +769,35 @@ void isci_host_remote_device_start_complete(
262 struct isci_remote_device *, 769 struct isci_remote_device *,
263 enum sci_status); 770 enum sci_status);
264 771
265#endif /* !defined(_SCI_HOST_H_) */ 772void scic_controller_disable_interrupts(
773 struct scic_sds_controller *scic);
774
775enum sci_status scic_controller_start_io(
776 struct scic_sds_controller *scic,
777 struct scic_sds_remote_device *remote_device,
778 struct scic_sds_request *io_request,
779 u16 io_tag);
780
781enum sci_task_status scic_controller_start_task(
782 struct scic_sds_controller *scic,
783 struct scic_sds_remote_device *remote_device,
784 struct scic_sds_request *task_request,
785 u16 io_tag);
786
787enum sci_status scic_controller_terminate_request(
788 struct scic_sds_controller *scic,
789 struct scic_sds_remote_device *remote_device,
790 struct scic_sds_request *request);
791
792enum sci_status scic_controller_complete_io(
793 struct scic_sds_controller *scic,
794 struct scic_sds_remote_device *remote_device,
795 struct scic_sds_request *io_request);
796
797u16 scic_controller_allocate_io_tag(
798 struct scic_sds_controller *scic);
799
800enum sci_status scic_controller_free_io_tag(
801 struct scic_sds_controller *scic,
802 u16 io_tag);
803#endif