blob: 2be935fa6af2c0be7a431a48ea8974e0beb7fb6d [file] [log] [blame]
Dan Williams6f231dd2011-07-02 22:56:22 -07001/*
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 */
Dan Williamsce2b3262011-05-08 15:49:15 -070055#ifndef _SCI_HOST_H_
Dan Williams6f231dd2011-07-02 22:56:22 -070056#define _SCI_HOST_H_
57
Dan Williams6f231dd2011-07-02 22:56:22 -070058#include "remote_device.h"
Dan Williamsce2b3262011-05-08 15:49:15 -070059#include "phy.h"
Dan Williamscc9203b2011-05-08 17:34:44 -070060#include "pool.h"
Dan Williams3bff9d52011-05-08 22:15:10 -070061#include "state_machine.h"
Dan Williamscc9203b2011-05-08 17:34:44 -070062#include "remote_node_table.h"
Dan Williams63a3a152011-05-08 21:36:46 -070063#include "registers.h"
Dan Williamscc9203b2011-05-08 17:34:44 -070064#include "scu_unsolicited_frame.h"
Dan Williams63a3a152011-05-08 21:36:46 -070065#include "unsolicited_frame_control.h"
Dan Williamse2f8db52011-05-10 02:28:46 -070066#include "probe_roms.h"
Dan Williamscc9203b2011-05-08 17:34:44 -070067
68struct scic_sds_request;
69struct scu_task_context;
70
Dan Williamse2f8db52011-05-10 02:28:46 -070071
Dan Williamscc9203b2011-05-08 17:34:44 -070072/**
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 /**
Edmund Nadolski04736612011-05-19 20:17:47 -070086 * Timer to control when the directed attached disks can consume power.
Dan Williamscc9203b2011-05-08 17:34:44 -070087 */
Edmund Nadolski04736612011-05-19 20:17:47 -070088 struct sci_timer timer;
Dan Williamscc9203b2011-05-08 17:34:44 -070089
90 /**
91 * This field is used to keep track of how many phys are put into the
92 * requesters field.
93 */
94 u8 phys_waiting;
95
96 /**
97 * This field is used to keep track of how many phys have been granted to consume power
98 */
99 u8 phys_granted_power;
100
101 /**
102 * This field is an array of phys that we are waiting on. The phys are direct
103 * mapped into requesters via struct scic_sds_phy.phy_index
104 */
105 struct scic_sds_phy *requesters[SCI_MAX_PHYS];
106
107};
108
Dan Williamse2f8db52011-05-10 02:28:46 -0700109struct scic_sds_port_configuration_agent;
110typedef void (*port_config_fn)(struct scic_sds_controller *,
111 struct scic_sds_port_configuration_agent *,
112 struct scic_sds_port *, struct scic_sds_phy *);
113
114struct scic_sds_port_configuration_agent {
115 u16 phy_configured_mask;
116 u16 phy_ready_mask;
117 struct {
118 u8 min_index;
119 u8 max_index;
120 } phy_valid_port_range[SCI_MAX_PHYS];
121 bool timer_pending;
122 port_config_fn link_up_handler;
123 port_config_fn link_down_handler;
Edmund Nadolskiac0eeb42011-05-19 20:00:51 -0700124 struct sci_timer timer;
Dan Williamse2f8db52011-05-10 02:28:46 -0700125};
126
Dan Williamscc9203b2011-05-08 17:34:44 -0700127/**
128 * struct scic_sds_controller -
129 *
130 * This structure represents the SCU controller object.
131 */
132struct scic_sds_controller {
133 /**
134 * This field contains the information for the base controller state
135 * machine.
136 */
137 struct sci_base_state_machine state_machine;
138
139 /**
140 * This field is the driver timer object handler used to time the controller
141 * object start and stop requests.
142 */
143 void *timeout_timer;
144
145 /**
146 * This field contains the user parameters to be utilized for this
147 * core controller object.
148 */
149 union scic_user_parameters user_parameters;
150
151 /**
152 * This field contains the OEM parameters to be utilized for this
153 * core controller object.
154 */
155 union scic_oem_parameters oem_parameters;
156
157 /**
158 * This field contains the port configuration agent for this controller.
159 */
160 struct scic_sds_port_configuration_agent port_agent;
161
162 /**
163 * This field is the array of device objects that are currently constructed
164 * for this controller object. This table is used as a fast lookup of device
165 * objects that need to handle device completion notifications from the
166 * hardware. The table is RNi based.
167 */
168 struct scic_sds_remote_device *device_table[SCI_MAX_REMOTE_DEVICES];
169
170 /**
171 * This field is the array of IO request objects that are currently active for
172 * this controller object. This table is used as a fast lookup of the io
173 * request object that need to handle completion queue notifications. The
174 * table is TCi based.
175 */
176 struct scic_sds_request *io_request_table[SCI_MAX_IO_REQUESTS];
177
178 /**
179 * This field is the free RNi data structure
180 */
181 struct scic_remote_node_table available_remote_nodes;
182
183 /**
184 * This field is the TCi pool used to manage the task context index.
185 */
186 SCI_POOL_CREATE(tci_pool, u16, SCI_MAX_IO_REQUESTS);
187
188 /**
189 * This filed is the struct scic_power_control data used to controll when direct
190 * attached devices can consume power.
191 */
192 struct scic_power_control power_control;
193
194 /**
195 * This field is the array of sequence values for the IO Tag fields. Even
196 * though only 4 bits of the field is used for the sequence the sequence is 16
197 * bits in size so the sequence can be bitwise or'd with the TCi to build the
198 * IO Tag value.
199 */
200 u16 io_request_sequence[SCI_MAX_IO_REQUESTS];
201
202 /**
203 * This field in the array of sequence values for the RNi. These are used
204 * to control io request build to io request start operations. The sequence
205 * value is recorded into an io request when it is built and is checked on
206 * the io request start operation to make sure that there was not a device
207 * hot plug between the build and start operation.
208 */
209 u8 remote_device_sequence[SCI_MAX_REMOTE_DEVICES];
210
211 /**
212 * This field is a pointer to the memory allocated by the driver for the task
213 * context table. This data is shared between the hardware and software.
214 */
215 struct scu_task_context *task_context_table;
216
217 /**
218 * This field is a pointer to the memory allocated by the driver for the
219 * remote node context table. This table is shared between the hardware and
220 * software.
221 */
222 union scu_remote_node_context *remote_node_context_table;
223
224 /**
225 * This field is a pointer to the completion queue. This memory is
226 * written to by the hardware and read by the software.
227 */
228 u32 *completion_queue;
229
230 /**
231 * This field is the software copy of the completion queue get pointer. The
232 * controller object writes this value to the hardware after processing the
233 * completion entries.
234 */
235 u32 completion_queue_get;
236
237 /**
238 * This field is the minimum of the number of hardware supported port entries
239 * and the software requested port entries.
240 */
241 u32 logical_port_entries;
242
243 /**
244 * This field is the minimum number of hardware supported completion queue
245 * entries and the software requested completion queue entries.
246 */
247 u32 completion_queue_entries;
248
249 /**
250 * This field is the minimum number of hardware supported event entries and
251 * the software requested event entries.
252 */
253 u32 completion_event_entries;
254
255 /**
256 * This field is the minimum number of devices supported by the hardware and
257 * the number of devices requested by the software.
258 */
259 u32 remote_node_entries;
260
261 /**
262 * This field is the minimum number of IO requests supported by the hardware
263 * and the number of IO requests requested by the software.
264 */
265 u32 task_context_entries;
266
267 /**
268 * This object contains all of the unsolicited frame specific
269 * data utilized by the core controller.
270 */
271 struct scic_sds_unsolicited_frame_control uf_control;
272
273 /* Phy Startup Data */
274 /**
275 * This field is the driver timer handle for controller phy request startup.
276 * On controller start the controller will start each PHY individually in
277 * order of phy index.
278 */
279 void *phy_startup_timer;
280
281 /**
282 * This field is set when the phy_startup_timer is running and is cleared when
283 * the phy_startup_timer is stopped.
284 */
285 bool phy_startup_timer_pending;
286
287 /**
288 * This field is the index of the next phy start. It is initialized to 0 and
289 * increments for each phy index that is started.
290 */
291 u32 next_phy_to_start;
292
293 /**
294 * This field controlls the invalid link up notifications to the SCI_USER. If
295 * an invalid_link_up notification is reported a bit for the PHY index is set
296 * so further notifications are not made. Once the PHY object reports link up
297 * and is made part of a port then this bit for the PHY index is cleared.
298 */
299 u8 invalid_phy_mask;
300
301 /*
302 * This field saves the current interrupt coalescing number of the controller.
303 */
304 u16 interrupt_coalesce_number;
305
306 /*
307 * This field saves the current interrupt coalescing timeout value in microseconds.
308 */
309 u32 interrupt_coalesce_timeout;
310
311 /**
312 * This field is a pointer to the memory mapped register space for the
313 * struct smu_registers.
314 */
315 struct smu_registers __iomem *smu_registers;
316
317 /**
318 * This field is a pointer to the memory mapped register space for the
319 * struct scu_registers.
320 */
321 struct scu_registers __iomem *scu_registers;
322
323};
Dan Williams6f231dd2011-07-02 22:56:22 -0700324
Dan Williams6f231dd2011-07-02 22:56:22 -0700325struct isci_host {
Artur Wojcikcc3dbd02011-05-04 07:58:16 +0000326 struct scic_sds_controller sci;
Dan Williams6f231dd2011-07-02 22:56:22 -0700327 union scic_oem_parameters oem_parameters;
328
329 int id; /* unique within a given pci device */
Dan Williams7c40a802011-03-02 11:49:26 -0800330 struct list_head timers;
Dan Williams6f231dd2011-07-02 22:56:22 -0700331 void *core_ctrl_memory;
332 struct dma_pool *dma_pool;
Dan Williams6f231dd2011-07-02 22:56:22 -0700333 struct isci_phy phys[SCI_MAX_PHYS];
Dan Williamse5313812011-05-07 10:11:43 -0700334 struct isci_port ports[SCI_MAX_PORTS + 1]; /* includes dummy port */
Dan Williams6f231dd2011-07-02 22:56:22 -0700335 struct sas_ha_struct sas_ha;
336
337 int can_queue;
338 spinlock_t queue_lock;
339 spinlock_t state_lock;
340
341 struct pci_dev *pdev;
Dan Williams6f231dd2011-07-02 22:56:22 -0700342
343 enum isci_status status;
Dan Williams0cf89d12011-02-18 09:25:07 -0800344 #define IHOST_START_PENDING 0
345 #define IHOST_STOP_PENDING 1
346 unsigned long flags;
347 wait_queue_head_t eventq;
Dan Williams6f231dd2011-07-02 22:56:22 -0700348 struct Scsi_Host *shost;
349 struct tasklet_struct completion_tasklet;
Dan Williams6f231dd2011-07-02 22:56:22 -0700350 struct list_head requests_to_complete;
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800351 struct list_head requests_to_errorback;
Dan Williams6f231dd2011-07-02 22:56:22 -0700352 spinlock_t scic_lock;
Dan Williamsd9c37392011-03-03 17:59:32 -0800353
Dan Williams57f20f42011-04-21 18:14:45 -0700354 struct isci_remote_device devices[SCI_MAX_REMOTE_DEVICES];
Dan Williams6f231dd2011-07-02 22:56:22 -0700355};
356
Dan Williams6f231dd2011-07-02 22:56:22 -0700357/**
Dan Williamscc9203b2011-05-08 17:34:44 -0700358 * enum scic_sds_controller_states - This enumeration depicts all the states
359 * for the common controller state machine.
360 */
361enum scic_sds_controller_states {
362 /**
363 * Simply the initial state for the base controller state machine.
364 */
365 SCI_BASE_CONTROLLER_STATE_INITIAL = 0,
366
367 /**
368 * This state indicates that the controller is reset. The memory for
369 * the controller is in it's initial state, but the controller requires
370 * initialization.
371 * This state is entered from the INITIAL state.
372 * This state is entered from the RESETTING state.
373 */
374 SCI_BASE_CONTROLLER_STATE_RESET,
375
376 /**
377 * This state is typically an action state that indicates the controller
378 * is in the process of initialization. In this state no new IO operations
379 * are permitted.
380 * This state is entered from the RESET state.
381 */
382 SCI_BASE_CONTROLLER_STATE_INITIALIZING,
383
384 /**
385 * This state indicates that the controller has been successfully
386 * initialized. In this state no new IO operations are permitted.
387 * This state is entered from the INITIALIZING state.
388 */
389 SCI_BASE_CONTROLLER_STATE_INITIALIZED,
390
391 /**
392 * This state indicates the the controller is in the process of becoming
393 * ready (i.e. starting). In this state no new IO operations are permitted.
394 * This state is entered from the INITIALIZED state.
395 */
396 SCI_BASE_CONTROLLER_STATE_STARTING,
397
398 /**
399 * This state indicates the controller is now ready. Thus, the user
400 * is able to perform IO operations on the controller.
401 * This state is entered from the STARTING state.
402 */
403 SCI_BASE_CONTROLLER_STATE_READY,
404
405 /**
406 * This state is typically an action state that indicates the controller
407 * is in the process of resetting. Thus, the user is unable to perform
408 * IO operations on the controller. A reset is considered destructive in
409 * most cases.
410 * This state is entered from the READY state.
411 * This state is entered from the FAILED state.
412 * This state is entered from the STOPPED state.
413 */
414 SCI_BASE_CONTROLLER_STATE_RESETTING,
415
416 /**
417 * This state indicates that the controller is in the process of stopping.
418 * In this state no new IO operations are permitted, but existing IO
419 * operations are allowed to complete.
420 * This state is entered from the READY state.
421 */
422 SCI_BASE_CONTROLLER_STATE_STOPPING,
423
424 /**
425 * This state indicates that the controller has successfully been stopped.
426 * In this state no new IO operations are permitted.
427 * This state is entered from the STOPPING state.
428 */
429 SCI_BASE_CONTROLLER_STATE_STOPPED,
430
431 /**
432 * This state indicates that the controller could not successfully be
433 * initialized. In this state no new IO operations are permitted.
434 * This state is entered from the INITIALIZING state.
435 * This state is entered from the STARTING state.
436 * This state is entered from the STOPPING state.
437 * This state is entered from the RESETTING state.
438 */
439 SCI_BASE_CONTROLLER_STATE_FAILED,
440
441 SCI_BASE_CONTROLLER_MAX_STATES
442
443};
444
445
446
447/**
Dan Williams6f231dd2011-07-02 22:56:22 -0700448 * struct isci_pci_info - This class represents the pci function containing the
449 * controllers. Depending on PCI SKU, there could be up to 2 controllers in
450 * the PCI function.
451 */
452#define SCI_MAX_MSIX_INT (SCI_NUM_MSI_X_INT*SCI_MAX_CONTROLLERS)
453
454struct isci_pci_info {
455 struct msix_entry msix_entries[SCI_MAX_MSIX_INT];
Dan Williamsb329aff2011-03-07 16:02:25 -0800456 struct isci_host *hosts[SCI_MAX_CONTROLLERS];
Dan Williamsd044af12011-03-08 09:52:49 -0800457 struct isci_orom *orom;
Dan Williams6f231dd2011-07-02 22:56:22 -0700458};
459
460static inline struct isci_pci_info *to_pci_info(struct pci_dev *pdev)
461{
462 return pci_get_drvdata(pdev);
463}
464
Dan Williamsb329aff2011-03-07 16:02:25 -0800465#define for_each_isci_host(id, ihost, pdev) \
466 for (id = 0, ihost = to_pci_info(pdev)->hosts[id]; \
467 id < ARRAY_SIZE(to_pci_info(pdev)->hosts) && ihost; \
468 ihost = to_pci_info(pdev)->hosts[++id])
Dan Williams6f231dd2011-07-02 22:56:22 -0700469
Dan Williamscc9203b2011-05-08 17:34:44 -0700470static inline enum isci_status isci_host_get_state(struct isci_host *isci_host)
Dan Williams6f231dd2011-07-02 22:56:22 -0700471{
472 return isci_host->status;
473}
474
Dan Williamscc9203b2011-05-08 17:34:44 -0700475static inline void isci_host_change_state(struct isci_host *isci_host,
476 enum isci_status status)
Dan Williams6f231dd2011-07-02 22:56:22 -0700477{
478 unsigned long flags;
479
480 dev_dbg(&isci_host->pdev->dev,
481 "%s: isci_host = %p, state = 0x%x",
482 __func__,
483 isci_host,
484 status);
485 spin_lock_irqsave(&isci_host->state_lock, flags);
486 isci_host->status = status;
487 spin_unlock_irqrestore(&isci_host->state_lock, flags);
488
489}
490
Dan Williamscc9203b2011-05-08 17:34:44 -0700491static inline int isci_host_can_queue(struct isci_host *isci_host, int num)
Dan Williams6f231dd2011-07-02 22:56:22 -0700492{
493 int ret = 0;
494 unsigned long flags;
495
496 spin_lock_irqsave(&isci_host->queue_lock, flags);
497 if ((isci_host->can_queue - num) < 0) {
498 dev_dbg(&isci_host->pdev->dev,
499 "%s: isci_host->can_queue = %d\n",
500 __func__,
501 isci_host->can_queue);
502 ret = -SAS_QUEUE_FULL;
503
504 } else
505 isci_host->can_queue -= num;
506
507 spin_unlock_irqrestore(&isci_host->queue_lock, flags);
508
509 return ret;
510}
511
Dan Williamscc9203b2011-05-08 17:34:44 -0700512static inline void isci_host_can_dequeue(struct isci_host *isci_host, int num)
Dan Williams6f231dd2011-07-02 22:56:22 -0700513{
514 unsigned long flags;
515
516 spin_lock_irqsave(&isci_host->queue_lock, flags);
517 isci_host->can_queue += num;
518 spin_unlock_irqrestore(&isci_host->queue_lock, flags);
519}
520
Dan Williams0cf89d12011-02-18 09:25:07 -0800521static inline void wait_for_start(struct isci_host *ihost)
522{
523 wait_event(ihost->eventq, !test_bit(IHOST_START_PENDING, &ihost->flags));
524}
525
526static inline void wait_for_stop(struct isci_host *ihost)
527{
528 wait_event(ihost->eventq, !test_bit(IHOST_STOP_PENDING, &ihost->flags));
529}
530
Dan Williams6ad31fe2011-03-04 12:10:29 -0800531static inline void wait_for_device_start(struct isci_host *ihost, struct isci_remote_device *idev)
532{
533 wait_event(ihost->eventq, !test_bit(IDEV_START_PENDING, &idev->flags));
534}
535
536static inline void wait_for_device_stop(struct isci_host *ihost, struct isci_remote_device *idev)
537{
Dan Williamsd9c37392011-03-03 17:59:32 -0800538 wait_event(ihost->eventq, !test_bit(IDEV_STOP_PENDING, &idev->flags));
Dan Williams6ad31fe2011-03-04 12:10:29 -0800539}
Dan Williams0cf89d12011-02-18 09:25:07 -0800540
Dan Williams4393aa42011-03-31 13:10:44 -0700541static inline struct isci_host *dev_to_ihost(struct domain_device *dev)
542{
543 return dev->port->ha->lldd_ha;
544}
Dan Williams6f231dd2011-07-02 22:56:22 -0700545
Artur Wojcikcc3dbd02011-05-04 07:58:16 +0000546static inline struct isci_host *scic_to_ihost(struct scic_sds_controller *scic)
547{
548 /* XXX delete after merging scic_sds_contoller and isci_host */
549 struct isci_host *ihost = container_of(scic, typeof(*ihost), sci);
550
551 return ihost;
552}
553
Dan Williams6f231dd2011-07-02 22:56:22 -0700554/**
Dan Williamscc9203b2011-05-08 17:34:44 -0700555 * INCREMENT_QUEUE_GET() -
Dan Williams6f231dd2011-07-02 22:56:22 -0700556 *
Dan Williamscc9203b2011-05-08 17:34:44 -0700557 * This macro will increment the specified index to and if the index wraps to 0
558 * it will toggel the cycle bit.
Dan Williams6f231dd2011-07-02 22:56:22 -0700559 */
Dan Williamscc9203b2011-05-08 17:34:44 -0700560#define INCREMENT_QUEUE_GET(index, cycle, entry_count, bit_toggle) \
561 { \
562 if ((index) + 1 == entry_count) { \
563 (index) = 0; \
564 (cycle) = (cycle) ^ (bit_toggle); \
565 } else { \
566 index = index + 1; \
567 } \
568 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700569
570/**
Dan Williamscc9203b2011-05-08 17:34:44 -0700571 * scic_sds_controller_get_protocol_engine_group() -
Dan Williams6f231dd2011-07-02 22:56:22 -0700572 *
Dan Williamscc9203b2011-05-08 17:34:44 -0700573 * This macro returns the protocol engine group for this controller object.
574 * Presently we only support protocol engine group 0 so just return that
Dan Williams6f231dd2011-07-02 22:56:22 -0700575 */
Dan Williamscc9203b2011-05-08 17:34:44 -0700576#define scic_sds_controller_get_protocol_engine_group(controller) 0
Dan Williams6f231dd2011-07-02 22:56:22 -0700577
Dan Williamscc9203b2011-05-08 17:34:44 -0700578/**
579 * scic_sds_io_tag_construct() -
580 *
581 * This macro constructs an IO tag from the sequence and index values.
582 */
583#define scic_sds_io_tag_construct(sequence, task_index) \
584 ((sequence) << 12 | (task_index))
585
586/**
587 * scic_sds_io_tag_get_sequence() -
588 *
589 * This macro returns the IO sequence from the IO tag value.
590 */
591#define scic_sds_io_tag_get_sequence(io_tag) \
592 (((io_tag) & 0xF000) >> 12)
593
594/**
595 * scic_sds_io_tag_get_index() -
596 *
597 * This macro returns the TCi from the io tag value
598 */
599#define scic_sds_io_tag_get_index(io_tag) \
600 ((io_tag) & 0x0FFF)
601
602/**
603 * scic_sds_io_sequence_increment() -
604 *
605 * This is a helper macro to increment the io sequence count. We may find in
606 * the future that it will be faster to store the sequence count in such a way
607 * as we dont perform the shift operation to build io tag values so therefore
608 * need a way to incrment them correctly
609 */
610#define scic_sds_io_sequence_increment(value) \
611 ((value) = (((value) + 1) & 0x000F))
612
613/* expander attached sata devices require 3 rnc slots */
614static inline int scic_sds_remote_device_node_count(struct scic_sds_remote_device *sci_dev)
615{
616 struct domain_device *dev = sci_dev_to_domain(sci_dev);
617
618 if ((dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) &&
619 !sci_dev->is_direct_attached)
620 return SCU_STP_REMOTE_NODE_COUNT;
621 return SCU_SSP_REMOTE_NODE_COUNT;
622}
623
624/**
625 * scic_sds_controller_set_invalid_phy() -
626 *
627 * This macro will set the bit in the invalid phy mask for this controller
628 * object. This is used to control messages reported for invalid link up
629 * notifications.
630 */
631#define scic_sds_controller_set_invalid_phy(controller, phy) \
632 ((controller)->invalid_phy_mask |= (1 << (phy)->phy_index))
633
634/**
635 * scic_sds_controller_clear_invalid_phy() -
636 *
637 * This macro will clear the bit in the invalid phy mask for this controller
638 * object. This is used to control messages reported for invalid link up
639 * notifications.
640 */
641#define scic_sds_controller_clear_invalid_phy(controller, phy) \
642 ((controller)->invalid_phy_mask &= ~(1 << (phy)->phy_index))
643
644static inline struct device *scic_to_dev(struct scic_sds_controller *scic)
645{
646 return &scic_to_ihost(scic)->pdev->dev;
647}
648
649static inline struct device *sciphy_to_dev(struct scic_sds_phy *sci_phy)
650{
651 struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
652
653 if (!iphy || !iphy->isci_port || !iphy->isci_port->isci_host)
654 return NULL;
655
656 return &iphy->isci_port->isci_host->pdev->dev;
657}
658
659static inline struct device *sciport_to_dev(struct scic_sds_port *sci_port)
660{
661 struct isci_port *iport = sci_port_to_iport(sci_port);
662
663 if (!iport || !iport->isci_host)
664 return NULL;
665
666 return &iport->isci_host->pdev->dev;
667}
668
669static inline struct device *scirdev_to_dev(struct scic_sds_remote_device *sci_dev)
670{
671 struct isci_remote_device *idev =
672 container_of(sci_dev, typeof(*idev), sci);
673
674 if (!idev || !idev->isci_port || !idev->isci_port->isci_host)
675 return NULL;
676
677 return &idev->isci_port->isci_host->pdev->dev;
678}
679
680enum {
681 ISCI_SI_REVA0,
682 ISCI_SI_REVA2,
683 ISCI_SI_REVB0,
684};
685
686extern int isci_si_rev;
687
688static inline bool is_a0(void)
689{
690 return isci_si_rev == ISCI_SI_REVA0;
691}
692
693static inline bool is_a2(void)
694{
695 return isci_si_rev == ISCI_SI_REVA2;
696}
697
698static inline bool is_b0(void)
699{
700 return isci_si_rev > ISCI_SI_REVA2;
701}
702
703void scic_sds_controller_post_request(struct scic_sds_controller *scic,
704 u32 request);
705void scic_sds_controller_release_frame(struct scic_sds_controller *scic,
706 u32 frame_index);
707void scic_sds_controller_copy_sata_response(void *response_buffer,
708 void *frame_header,
709 void *frame_buffer);
710enum sci_status scic_sds_controller_allocate_remote_node_context(struct scic_sds_controller *scic,
711 struct scic_sds_remote_device *sci_dev,
712 u16 *node_id);
713void scic_sds_controller_free_remote_node_context(
714 struct scic_sds_controller *scic,
715 struct scic_sds_remote_device *sci_dev,
716 u16 node_id);
717union scu_remote_node_context *scic_sds_controller_get_remote_node_context_buffer(
718 struct scic_sds_controller *scic,
719 u16 node_id);
720
721struct scic_sds_request *scic_request_by_tag(struct scic_sds_controller *scic,
722 u16 io_tag);
723
724struct scu_task_context *scic_sds_controller_get_task_context_buffer(
725 struct scic_sds_controller *scic,
726 u16 io_tag);
727
728void scic_sds_controller_power_control_queue_insert(
729 struct scic_sds_controller *scic,
730 struct scic_sds_phy *sci_phy);
731
732void scic_sds_controller_power_control_queue_remove(
733 struct scic_sds_controller *scic,
734 struct scic_sds_phy *sci_phy);
735
736void scic_sds_controller_link_up(
737 struct scic_sds_controller *scic,
738 struct scic_sds_port *sci_port,
739 struct scic_sds_phy *sci_phy);
740
741void scic_sds_controller_link_down(
742 struct scic_sds_controller *scic,
743 struct scic_sds_port *sci_port,
744 struct scic_sds_phy *sci_phy);
745
746void scic_sds_controller_remote_device_stopped(
747 struct scic_sds_controller *scic,
748 struct scic_sds_remote_device *sci_dev);
749
750void scic_sds_controller_copy_task_context(
751 struct scic_sds_controller *scic,
752 struct scic_sds_request *this_request);
753
754void scic_sds_controller_register_setup(struct scic_sds_controller *scic);
755
756enum sci_status scic_controller_continue_io(struct scic_sds_request *sci_req);
757int isci_host_scan_finished(struct Scsi_Host *, unsigned long);
758void isci_host_scan_start(struct Scsi_Host *);
Dan Williams6f231dd2011-07-02 22:56:22 -0700759
760int isci_host_init(struct isci_host *);
761
762void isci_host_init_controller_names(
763 struct isci_host *isci_host,
764 unsigned int controller_idx);
765
766void isci_host_deinit(
767 struct isci_host *);
768
769void isci_host_port_link_up(
770 struct isci_host *,
771 struct scic_sds_port *,
772 struct scic_sds_phy *);
773int isci_host_dev_found(struct domain_device *);
774
775void isci_host_remote_device_start_complete(
776 struct isci_host *,
777 struct isci_remote_device *,
778 enum sci_status);
779
Dan Williamscc9203b2011-05-08 17:34:44 -0700780void scic_controller_disable_interrupts(
781 struct scic_sds_controller *scic);
782
783enum sci_status scic_controller_start_io(
784 struct scic_sds_controller *scic,
785 struct scic_sds_remote_device *remote_device,
786 struct scic_sds_request *io_request,
787 u16 io_tag);
788
789enum sci_task_status scic_controller_start_task(
790 struct scic_sds_controller *scic,
791 struct scic_sds_remote_device *remote_device,
792 struct scic_sds_request *task_request,
793 u16 io_tag);
794
795enum sci_status scic_controller_terminate_request(
796 struct scic_sds_controller *scic,
797 struct scic_sds_remote_device *remote_device,
798 struct scic_sds_request *request);
799
800enum sci_status scic_controller_complete_io(
801 struct scic_sds_controller *scic,
802 struct scic_sds_remote_device *remote_device,
803 struct scic_sds_request *io_request);
804
805u16 scic_controller_allocate_io_tag(
806 struct scic_sds_controller *scic);
807
808enum sci_status scic_controller_free_io_tag(
809 struct scic_sds_controller *scic,
810 u16 io_tag);
Dan Williamse2f8db52011-05-10 02:28:46 -0700811
812void scic_sds_port_configuration_agent_construct(
813 struct scic_sds_port_configuration_agent *port_agent);
814
815enum sci_status scic_sds_port_configuration_agent_initialize(
816 struct scic_sds_controller *controller,
817 struct scic_sds_port_configuration_agent *port_agent);
Dan Williamscc9203b2011-05-08 17:34:44 -0700818#endif