blob: d8164f5d7988aaf5de96d154c83bbb7db29cac55 [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"
Edmund Nadolski12ef6542011-06-02 00:10:50 +000060#include "isci.h"
Dan Williamscc9203b2011-05-08 17:34:44 -070061#include "remote_node_table.h"
Dan Williams63a3a152011-05-08 21:36:46 -070062#include "registers.h"
Dan Williamscc9203b2011-05-08 17:34:44 -070063#include "scu_unsolicited_frame.h"
Dan Williams63a3a152011-05-08 21:36:46 -070064#include "unsolicited_frame_control.h"
Dan Williamse2f8db52011-05-10 02:28:46 -070065#include "probe_roms.h"
Dan Williamscc9203b2011-05-08 17:34:44 -070066
67struct scic_sds_request;
68struct scu_task_context;
69
Dan Williamse2f8db52011-05-10 02:28:46 -070070
Dan Williamscc9203b2011-05-08 17:34:44 -070071/**
72 * struct scic_power_control -
73 *
74 * This structure defines the fields for managing power control for direct
75 * attached disk devices.
76 */
77struct scic_power_control {
78 /**
79 * This field is set when the power control timer is running and cleared when
80 * it is not.
81 */
82 bool timer_started;
83
84 /**
Edmund Nadolski04736612011-05-19 20:17:47 -070085 * Timer to control when the directed attached disks can consume power.
Dan Williamscc9203b2011-05-08 17:34:44 -070086 */
Edmund Nadolski04736612011-05-19 20:17:47 -070087 struct sci_timer timer;
Dan Williamscc9203b2011-05-08 17:34:44 -070088
89 /**
90 * This field is used to keep track of how many phys are put into the
91 * requesters field.
92 */
93 u8 phys_waiting;
94
95 /**
96 * This field is used to keep track of how many phys have been granted to consume power
97 */
98 u8 phys_granted_power;
99
100 /**
101 * This field is an array of phys that we are waiting on. The phys are direct
102 * mapped into requesters via struct scic_sds_phy.phy_index
103 */
104 struct scic_sds_phy *requesters[SCI_MAX_PHYS];
105
106};
107
Dan Williamse2f8db52011-05-10 02:28:46 -0700108struct scic_sds_port_configuration_agent;
109typedef void (*port_config_fn)(struct scic_sds_controller *,
110 struct scic_sds_port_configuration_agent *,
111 struct scic_sds_port *, struct scic_sds_phy *);
112
113struct scic_sds_port_configuration_agent {
114 u16 phy_configured_mask;
115 u16 phy_ready_mask;
116 struct {
117 u8 min_index;
118 u8 max_index;
119 } phy_valid_port_range[SCI_MAX_PHYS];
120 bool timer_pending;
121 port_config_fn link_up_handler;
122 port_config_fn link_down_handler;
Edmund Nadolskiac0eeb42011-05-19 20:00:51 -0700123 struct sci_timer timer;
Dan Williamse2f8db52011-05-10 02:28:46 -0700124};
125
Dan Williamscc9203b2011-05-08 17:34:44 -0700126/**
127 * struct scic_sds_controller -
128 *
129 * This structure represents the SCU controller object.
130 */
131struct scic_sds_controller {
132 /**
133 * This field contains the information for the base controller state
134 * machine.
135 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000136 struct sci_base_state_machine sm;
Dan Williamscc9203b2011-05-08 17:34:44 -0700137
138 /**
Edmund Nadolski6cb58532011-05-19 11:59:56 +0000139 * Timer for controller start/stop operations.
Dan Williamscc9203b2011-05-08 17:34:44 -0700140 */
Edmund Nadolski6cb58532011-05-19 11:59:56 +0000141 struct sci_timer timer;
Dan Williamscc9203b2011-05-08 17:34:44 -0700142
143 /**
144 * This field contains the user parameters to be utilized for this
145 * core controller object.
146 */
147 union scic_user_parameters user_parameters;
148
149 /**
150 * This field contains the OEM parameters to be utilized for this
151 * core controller object.
152 */
153 union scic_oem_parameters oem_parameters;
154
155 /**
156 * This field contains the port configuration agent for this controller.
157 */
158 struct scic_sds_port_configuration_agent port_agent;
159
160 /**
161 * This field is the array of device objects that are currently constructed
162 * for this controller object. This table is used as a fast lookup of device
163 * objects that need to handle device completion notifications from the
164 * hardware. The table is RNi based.
165 */
166 struct scic_sds_remote_device *device_table[SCI_MAX_REMOTE_DEVICES];
167
168 /**
169 * This field is the array of IO request objects that are currently active for
170 * this controller object. This table is used as a fast lookup of the io
171 * request object that need to handle completion queue notifications. The
172 * table is TCi based.
173 */
174 struct scic_sds_request *io_request_table[SCI_MAX_IO_REQUESTS];
175
176 /**
177 * This field is the free RNi data structure
178 */
179 struct scic_remote_node_table available_remote_nodes;
180
181 /**
Dan Williamscc9203b2011-05-08 17:34:44 -0700182 * This filed is the struct scic_power_control data used to controll when direct
183 * attached devices can consume power.
184 */
185 struct scic_power_control power_control;
186
Dan Williamsdd047c82011-06-09 11:06:58 -0700187 /* sequence number per tci */
188 u8 io_request_sequence[SCI_MAX_IO_REQUESTS];
Dan Williamscc9203b2011-05-08 17:34:44 -0700189
190 /**
Dan Williamscc9203b2011-05-08 17:34:44 -0700191 * This field is a pointer to the memory allocated by the driver for the task
192 * context table. This data is shared between the hardware and software.
193 */
194 struct scu_task_context *task_context_table;
Dan Williams312e0c22011-06-28 13:47:09 -0700195 dma_addr_t task_context_dma;
Dan Williamscc9203b2011-05-08 17:34:44 -0700196
197 /**
198 * This field is a pointer to the memory allocated by the driver for the
199 * remote node context table. This table is shared between the hardware and
200 * software.
201 */
202 union scu_remote_node_context *remote_node_context_table;
203
204 /**
205 * This field is a pointer to the completion queue. This memory is
206 * written to by the hardware and read by the software.
207 */
208 u32 *completion_queue;
209
210 /**
211 * This field is the software copy of the completion queue get pointer. The
212 * controller object writes this value to the hardware after processing the
213 * completion entries.
214 */
215 u32 completion_queue_get;
216
217 /**
218 * This field is the minimum of the number of hardware supported port entries
219 * and the software requested port entries.
220 */
221 u32 logical_port_entries;
222
223 /**
Dan Williamscc9203b2011-05-08 17:34:44 -0700224 * This field is the minimum number of devices supported by the hardware and
225 * the number of devices requested by the software.
226 */
227 u32 remote_node_entries;
228
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 /**
236 * This object contains all of the unsolicited frame specific
237 * data utilized by the core controller.
238 */
239 struct scic_sds_unsolicited_frame_control uf_control;
240
241 /* Phy Startup Data */
242 /**
Edmund Nadolskibb3dbdf2011-05-19 20:26:02 -0700243 * Timer for controller phy request startup. On controller start the
244 * controller will start each PHY individually in order of phy index.
Dan Williamscc9203b2011-05-08 17:34:44 -0700245 */
Edmund Nadolskibb3dbdf2011-05-19 20:26:02 -0700246 struct sci_timer phy_timer;
Dan Williamscc9203b2011-05-08 17:34:44 -0700247
248 /**
Edmund Nadolskibb3dbdf2011-05-19 20:26:02 -0700249 * This field is set when the phy_timer is running and is cleared when
250 * the phy_timer is stopped.
Dan Williamscc9203b2011-05-08 17:34:44 -0700251 */
252 bool phy_startup_timer_pending;
253
254 /**
255 * This field is the index of the next phy start. It is initialized to 0 and
256 * increments for each phy index that is started.
257 */
258 u32 next_phy_to_start;
259
260 /**
261 * This field controlls the invalid link up notifications to the SCI_USER. If
262 * an invalid_link_up notification is reported a bit for the PHY index is set
263 * so further notifications are not made. Once the PHY object reports link up
264 * and is made part of a port then this bit for the PHY index is cleared.
265 */
266 u8 invalid_phy_mask;
267
268 /*
269 * This field saves the current interrupt coalescing number of the controller.
270 */
271 u16 interrupt_coalesce_number;
272
273 /*
274 * This field saves the current interrupt coalescing timeout value in microseconds.
275 */
276 u32 interrupt_coalesce_timeout;
277
278 /**
279 * This field is a pointer to the memory mapped register space for the
280 * struct smu_registers.
281 */
282 struct smu_registers __iomem *smu_registers;
283
284 /**
285 * This field is a pointer to the memory mapped register space for the
286 * struct scu_registers.
287 */
288 struct scu_registers __iomem *scu_registers;
289
290};
Dan Williams6f231dd2011-07-02 22:56:22 -0700291
Dan Williams6f231dd2011-07-02 22:56:22 -0700292struct isci_host {
Artur Wojcikcc3dbd02011-05-04 07:58:16 +0000293 struct scic_sds_controller sci;
Dan Williamsac668c62011-06-07 18:50:55 -0700294 u16 tci_head;
295 u16 tci_tail;
296 u16 tci_pool[SCI_MAX_IO_REQUESTS];
297
Dan Williams6f231dd2011-07-02 22:56:22 -0700298 union scic_oem_parameters oem_parameters;
299
300 int id; /* unique within a given pci device */
Dan Williams6f231dd2011-07-02 22:56:22 -0700301 struct dma_pool *dma_pool;
Dan Williams6f231dd2011-07-02 22:56:22 -0700302 struct isci_phy phys[SCI_MAX_PHYS];
Dan Williamse5313812011-05-07 10:11:43 -0700303 struct isci_port ports[SCI_MAX_PORTS + 1]; /* includes dummy port */
Dan Williams6f231dd2011-07-02 22:56:22 -0700304 struct sas_ha_struct sas_ha;
305
Dan Williams6f231dd2011-07-02 22:56:22 -0700306 spinlock_t state_lock;
Dan Williams6f231dd2011-07-02 22:56:22 -0700307 struct pci_dev *pdev;
Dan Williams6f231dd2011-07-02 22:56:22 -0700308 enum isci_status status;
Dan Williams0cf89d12011-02-18 09:25:07 -0800309 #define IHOST_START_PENDING 0
310 #define IHOST_STOP_PENDING 1
311 unsigned long flags;
312 wait_queue_head_t eventq;
Dan Williams6f231dd2011-07-02 22:56:22 -0700313 struct Scsi_Host *shost;
314 struct tasklet_struct completion_tasklet;
Dan Williams6f231dd2011-07-02 22:56:22 -0700315 struct list_head requests_to_complete;
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800316 struct list_head requests_to_errorback;
Dan Williams6f231dd2011-07-02 22:56:22 -0700317 spinlock_t scic_lock;
Dan Williamsd9c37392011-03-03 17:59:32 -0800318
Dan Williams57f20f42011-04-21 18:14:45 -0700319 struct isci_remote_device devices[SCI_MAX_REMOTE_DEVICES];
Dan Williams6f231dd2011-07-02 22:56:22 -0700320};
321
Dan Williams6f231dd2011-07-02 22:56:22 -0700322/**
Dan Williamscc9203b2011-05-08 17:34:44 -0700323 * enum scic_sds_controller_states - This enumeration depicts all the states
324 * for the common controller state machine.
325 */
326enum scic_sds_controller_states {
327 /**
328 * Simply the initial state for the base controller state machine.
329 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000330 SCIC_INITIAL = 0,
Dan Williamscc9203b2011-05-08 17:34:44 -0700331
332 /**
333 * This state indicates that the controller is reset. The memory for
334 * the controller is in it's initial state, but the controller requires
335 * initialization.
336 * This state is entered from the INITIAL state.
337 * This state is entered from the RESETTING state.
338 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000339 SCIC_RESET,
Dan Williamscc9203b2011-05-08 17:34:44 -0700340
341 /**
342 * This state is typically an action state that indicates the controller
343 * is in the process of initialization. In this state no new IO operations
344 * are permitted.
345 * This state is entered from the RESET state.
346 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000347 SCIC_INITIALIZING,
Dan Williamscc9203b2011-05-08 17:34:44 -0700348
349 /**
350 * This state indicates that the controller has been successfully
351 * initialized. In this state no new IO operations are permitted.
352 * This state is entered from the INITIALIZING state.
353 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000354 SCIC_INITIALIZED,
Dan Williamscc9203b2011-05-08 17:34:44 -0700355
356 /**
357 * This state indicates the the controller is in the process of becoming
358 * ready (i.e. starting). In this state no new IO operations are permitted.
359 * This state is entered from the INITIALIZED state.
360 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000361 SCIC_STARTING,
Dan Williamscc9203b2011-05-08 17:34:44 -0700362
363 /**
364 * This state indicates the controller is now ready. Thus, the user
365 * is able to perform IO operations on the controller.
366 * This state is entered from the STARTING state.
367 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000368 SCIC_READY,
Dan Williamscc9203b2011-05-08 17:34:44 -0700369
370 /**
371 * This state is typically an action state that indicates the controller
372 * is in the process of resetting. Thus, the user is unable to perform
373 * IO operations on the controller. A reset is considered destructive in
374 * most cases.
375 * This state is entered from the READY state.
376 * This state is entered from the FAILED state.
377 * This state is entered from the STOPPED state.
378 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000379 SCIC_RESETTING,
Dan Williamscc9203b2011-05-08 17:34:44 -0700380
381 /**
382 * This state indicates that the controller is in the process of stopping.
383 * In this state no new IO operations are permitted, but existing IO
384 * operations are allowed to complete.
385 * This state is entered from the READY state.
386 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000387 SCIC_STOPPING,
Dan Williamscc9203b2011-05-08 17:34:44 -0700388
389 /**
390 * This state indicates that the controller has successfully been stopped.
391 * In this state no new IO operations are permitted.
392 * This state is entered from the STOPPING state.
393 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000394 SCIC_STOPPED,
Dan Williamscc9203b2011-05-08 17:34:44 -0700395
396 /**
397 * This state indicates that the controller could not successfully be
398 * initialized. In this state no new IO operations are permitted.
399 * This state is entered from the INITIALIZING state.
400 * This state is entered from the STARTING state.
401 * This state is entered from the STOPPING state.
402 * This state is entered from the RESETTING state.
403 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000404 SCIC_FAILED,
Dan Williamscc9203b2011-05-08 17:34:44 -0700405};
406
Dan Williamscc9203b2011-05-08 17:34:44 -0700407/**
Dan Williams6f231dd2011-07-02 22:56:22 -0700408 * struct isci_pci_info - This class represents the pci function containing the
409 * controllers. Depending on PCI SKU, there could be up to 2 controllers in
410 * the PCI function.
411 */
412#define SCI_MAX_MSIX_INT (SCI_NUM_MSI_X_INT*SCI_MAX_CONTROLLERS)
413
414struct isci_pci_info {
415 struct msix_entry msix_entries[SCI_MAX_MSIX_INT];
Dan Williamsb329aff2011-03-07 16:02:25 -0800416 struct isci_host *hosts[SCI_MAX_CONTROLLERS];
Dan Williamsd044af12011-03-08 09:52:49 -0800417 struct isci_orom *orom;
Dan Williams6f231dd2011-07-02 22:56:22 -0700418};
419
420static inline struct isci_pci_info *to_pci_info(struct pci_dev *pdev)
421{
422 return pci_get_drvdata(pdev);
423}
424
Dan Williamsb329aff2011-03-07 16:02:25 -0800425#define for_each_isci_host(id, ihost, pdev) \
426 for (id = 0, ihost = to_pci_info(pdev)->hosts[id]; \
427 id < ARRAY_SIZE(to_pci_info(pdev)->hosts) && ihost; \
428 ihost = to_pci_info(pdev)->hosts[++id])
Dan Williams6f231dd2011-07-02 22:56:22 -0700429
Dan Williamscc9203b2011-05-08 17:34:44 -0700430static inline enum isci_status isci_host_get_state(struct isci_host *isci_host)
Dan Williams6f231dd2011-07-02 22:56:22 -0700431{
432 return isci_host->status;
433}
434
Dan Williamscc9203b2011-05-08 17:34:44 -0700435static inline void isci_host_change_state(struct isci_host *isci_host,
436 enum isci_status status)
Dan Williams6f231dd2011-07-02 22:56:22 -0700437{
438 unsigned long flags;
439
440 dev_dbg(&isci_host->pdev->dev,
441 "%s: isci_host = %p, state = 0x%x",
442 __func__,
443 isci_host,
444 status);
445 spin_lock_irqsave(&isci_host->state_lock, flags);
446 isci_host->status = status;
447 spin_unlock_irqrestore(&isci_host->state_lock, flags);
448
449}
450
Dan Williams0cf89d12011-02-18 09:25:07 -0800451static inline void wait_for_start(struct isci_host *ihost)
452{
453 wait_event(ihost->eventq, !test_bit(IHOST_START_PENDING, &ihost->flags));
454}
455
456static inline void wait_for_stop(struct isci_host *ihost)
457{
458 wait_event(ihost->eventq, !test_bit(IHOST_STOP_PENDING, &ihost->flags));
459}
460
Dan Williams6ad31fe2011-03-04 12:10:29 -0800461static inline void wait_for_device_start(struct isci_host *ihost, struct isci_remote_device *idev)
462{
463 wait_event(ihost->eventq, !test_bit(IDEV_START_PENDING, &idev->flags));
464}
465
466static inline void wait_for_device_stop(struct isci_host *ihost, struct isci_remote_device *idev)
467{
Dan Williamsd9c37392011-03-03 17:59:32 -0800468 wait_event(ihost->eventq, !test_bit(IDEV_STOP_PENDING, &idev->flags));
Dan Williams6ad31fe2011-03-04 12:10:29 -0800469}
Dan Williams0cf89d12011-02-18 09:25:07 -0800470
Dan Williams4393aa42011-03-31 13:10:44 -0700471static inline struct isci_host *dev_to_ihost(struct domain_device *dev)
472{
473 return dev->port->ha->lldd_ha;
474}
Dan Williams6f231dd2011-07-02 22:56:22 -0700475
Artur Wojcikcc3dbd02011-05-04 07:58:16 +0000476static inline struct isci_host *scic_to_ihost(struct scic_sds_controller *scic)
477{
478 /* XXX delete after merging scic_sds_contoller and isci_host */
479 struct isci_host *ihost = container_of(scic, typeof(*ihost), sci);
480
481 return ihost;
482}
483
Dan Williams6f231dd2011-07-02 22:56:22 -0700484/**
Dan Williamscc9203b2011-05-08 17:34:44 -0700485 * scic_sds_controller_get_protocol_engine_group() -
Dan Williams6f231dd2011-07-02 22:56:22 -0700486 *
Dan Williamscc9203b2011-05-08 17:34:44 -0700487 * This macro returns the protocol engine group for this controller object.
488 * Presently we only support protocol engine group 0 so just return that
Dan Williams6f231dd2011-07-02 22:56:22 -0700489 */
Dan Williamscc9203b2011-05-08 17:34:44 -0700490#define scic_sds_controller_get_protocol_engine_group(controller) 0
Dan Williams6f231dd2011-07-02 22:56:22 -0700491
Dan Williamsdd047c82011-06-09 11:06:58 -0700492/* see scic_controller_io_tag_allocate|free for how seq and tci are built */
493#define ISCI_TAG(seq, tci) (((u16) (seq)) << 12 | tci)
Dan Williamscc9203b2011-05-08 17:34:44 -0700494
Dan Williamsdd047c82011-06-09 11:06:58 -0700495/* these are returned by the hardware, so sanitize them */
496#define ISCI_TAG_SEQ(tag) (((tag) >> 12) & (SCI_MAX_SEQ-1))
497#define ISCI_TAG_TCI(tag) ((tag) & (SCI_MAX_IO_REQUESTS-1))
Dan Williamscc9203b2011-05-08 17:34:44 -0700498
499/* expander attached sata devices require 3 rnc slots */
500static inline int scic_sds_remote_device_node_count(struct scic_sds_remote_device *sci_dev)
501{
502 struct domain_device *dev = sci_dev_to_domain(sci_dev);
503
504 if ((dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) &&
505 !sci_dev->is_direct_attached)
506 return SCU_STP_REMOTE_NODE_COUNT;
507 return SCU_SSP_REMOTE_NODE_COUNT;
508}
509
510/**
511 * scic_sds_controller_set_invalid_phy() -
512 *
513 * This macro will set the bit in the invalid phy mask for this controller
514 * object. This is used to control messages reported for invalid link up
515 * notifications.
516 */
517#define scic_sds_controller_set_invalid_phy(controller, phy) \
518 ((controller)->invalid_phy_mask |= (1 << (phy)->phy_index))
519
520/**
521 * scic_sds_controller_clear_invalid_phy() -
522 *
523 * This macro will clear the bit in the invalid phy mask for this controller
524 * object. This is used to control messages reported for invalid link up
525 * notifications.
526 */
527#define scic_sds_controller_clear_invalid_phy(controller, phy) \
528 ((controller)->invalid_phy_mask &= ~(1 << (phy)->phy_index))
529
530static inline struct device *scic_to_dev(struct scic_sds_controller *scic)
531{
532 return &scic_to_ihost(scic)->pdev->dev;
533}
534
535static inline struct device *sciphy_to_dev(struct scic_sds_phy *sci_phy)
536{
537 struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
538
539 if (!iphy || !iphy->isci_port || !iphy->isci_port->isci_host)
540 return NULL;
541
542 return &iphy->isci_port->isci_host->pdev->dev;
543}
544
545static inline struct device *sciport_to_dev(struct scic_sds_port *sci_port)
546{
547 struct isci_port *iport = sci_port_to_iport(sci_port);
548
549 if (!iport || !iport->isci_host)
550 return NULL;
551
552 return &iport->isci_host->pdev->dev;
553}
554
555static inline struct device *scirdev_to_dev(struct scic_sds_remote_device *sci_dev)
556{
557 struct isci_remote_device *idev =
558 container_of(sci_dev, typeof(*idev), sci);
559
560 if (!idev || !idev->isci_port || !idev->isci_port->isci_host)
561 return NULL;
562
563 return &idev->isci_port->isci_host->pdev->dev;
564}
565
566enum {
567 ISCI_SI_REVA0,
568 ISCI_SI_REVA2,
569 ISCI_SI_REVB0,
Adam Gruchaladbb07432011-06-01 22:31:03 +0000570 ISCI_SI_REVC0
Dan Williamscc9203b2011-05-08 17:34:44 -0700571};
572
573extern int isci_si_rev;
574
575static inline bool is_a0(void)
576{
577 return isci_si_rev == ISCI_SI_REVA0;
578}
579
580static inline bool is_a2(void)
581{
582 return isci_si_rev == ISCI_SI_REVA2;
583}
584
585static inline bool is_b0(void)
586{
Adam Gruchaladbb07432011-06-01 22:31:03 +0000587 return isci_si_rev == ISCI_SI_REVB0;
588}
589
590static inline bool is_c0(void)
591{
592 return isci_si_rev > ISCI_SI_REVB0;
Dan Williamscc9203b2011-05-08 17:34:44 -0700593}
594
595void scic_sds_controller_post_request(struct scic_sds_controller *scic,
596 u32 request);
597void scic_sds_controller_release_frame(struct scic_sds_controller *scic,
598 u32 frame_index);
599void scic_sds_controller_copy_sata_response(void *response_buffer,
600 void *frame_header,
601 void *frame_buffer);
602enum sci_status scic_sds_controller_allocate_remote_node_context(struct scic_sds_controller *scic,
603 struct scic_sds_remote_device *sci_dev,
604 u16 *node_id);
605void scic_sds_controller_free_remote_node_context(
606 struct scic_sds_controller *scic,
607 struct scic_sds_remote_device *sci_dev,
608 u16 node_id);
609union scu_remote_node_context *scic_sds_controller_get_remote_node_context_buffer(
610 struct scic_sds_controller *scic,
611 u16 node_id);
612
613struct scic_sds_request *scic_request_by_tag(struct scic_sds_controller *scic,
614 u16 io_tag);
615
Dan Williamscc9203b2011-05-08 17:34:44 -0700616void scic_sds_controller_power_control_queue_insert(
617 struct scic_sds_controller *scic,
618 struct scic_sds_phy *sci_phy);
619
620void scic_sds_controller_power_control_queue_remove(
621 struct scic_sds_controller *scic,
622 struct scic_sds_phy *sci_phy);
623
624void scic_sds_controller_link_up(
625 struct scic_sds_controller *scic,
626 struct scic_sds_port *sci_port,
627 struct scic_sds_phy *sci_phy);
628
629void scic_sds_controller_link_down(
630 struct scic_sds_controller *scic,
631 struct scic_sds_port *sci_port,
632 struct scic_sds_phy *sci_phy);
633
634void scic_sds_controller_remote_device_stopped(
635 struct scic_sds_controller *scic,
636 struct scic_sds_remote_device *sci_dev);
637
638void scic_sds_controller_copy_task_context(
639 struct scic_sds_controller *scic,
640 struct scic_sds_request *this_request);
641
642void scic_sds_controller_register_setup(struct scic_sds_controller *scic);
643
644enum sci_status scic_controller_continue_io(struct scic_sds_request *sci_req);
645int isci_host_scan_finished(struct Scsi_Host *, unsigned long);
646void isci_host_scan_start(struct Scsi_Host *);
Dan Williams312e0c22011-06-28 13:47:09 -0700647u16 isci_alloc_tag(struct isci_host *ihost);
648enum sci_status isci_free_tag(struct isci_host *ihost, u16 io_tag);
649void isci_tci_free(struct isci_host *ihost, u16 tci);
Dan Williams6f231dd2011-07-02 22:56:22 -0700650
651int isci_host_init(struct isci_host *);
652
653void isci_host_init_controller_names(
654 struct isci_host *isci_host,
655 unsigned int controller_idx);
656
657void isci_host_deinit(
658 struct isci_host *);
659
660void isci_host_port_link_up(
661 struct isci_host *,
662 struct scic_sds_port *,
663 struct scic_sds_phy *);
664int isci_host_dev_found(struct domain_device *);
665
666void isci_host_remote_device_start_complete(
667 struct isci_host *,
668 struct isci_remote_device *,
669 enum sci_status);
670
Dan Williamscc9203b2011-05-08 17:34:44 -0700671void scic_controller_disable_interrupts(
672 struct scic_sds_controller *scic);
673
674enum sci_status scic_controller_start_io(
675 struct scic_sds_controller *scic,
676 struct scic_sds_remote_device *remote_device,
Dan Williams312e0c22011-06-28 13:47:09 -0700677 struct scic_sds_request *io_request);
Dan Williamscc9203b2011-05-08 17:34:44 -0700678
679enum sci_task_status scic_controller_start_task(
680 struct scic_sds_controller *scic,
681 struct scic_sds_remote_device *remote_device,
Dan Williams312e0c22011-06-28 13:47:09 -0700682 struct scic_sds_request *task_request);
Dan Williamscc9203b2011-05-08 17:34:44 -0700683
684enum sci_status scic_controller_terminate_request(
685 struct scic_sds_controller *scic,
686 struct scic_sds_remote_device *remote_device,
687 struct scic_sds_request *request);
688
689enum sci_status scic_controller_complete_io(
690 struct scic_sds_controller *scic,
691 struct scic_sds_remote_device *remote_device,
692 struct scic_sds_request *io_request);
693
Dan Williamse2f8db52011-05-10 02:28:46 -0700694void scic_sds_port_configuration_agent_construct(
695 struct scic_sds_port_configuration_agent *port_agent);
696
697enum sci_status scic_sds_port_configuration_agent_initialize(
698 struct scic_sds_controller *controller,
699 struct scic_sds_port_configuration_agent *port_agent);
Dan Williamscc9203b2011-05-08 17:34:44 -0700700#endif