blob: 00e4854e20d90490568dd00dfc4f76b81dcdb875 [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 */
55
Dan Williams6f231dd2011-07-02 22:56:22 -070056
57#if !defined(_SCI_HOST_H_)
58#define _SCI_HOST_H_
59
60#include "phy.h"
Artur Wojcikcc3dbd02011-05-04 07:58:16 +000061#include "scic_sds_controller.h"
Dan Williams6f231dd2011-07-02 22:56:22 -070062#include "timers.h"
63#include "remote_device.h"
Dan Williams6f231dd2011-07-02 22:56:22 -070064
65#define DRV_NAME "isci"
66#define SCI_PCI_BAR_COUNT 2
67#define SCI_NUM_MSI_X_INT 2
68#define SCI_SMU_BAR 0
69#define SCI_SMU_BAR_SIZE (16*1024)
70#define SCI_SCU_BAR 1
71#define SCI_SCU_BAR_SIZE (4*1024*1024)
72#define SCI_IO_SPACE_BAR0 2
73#define SCI_IO_SPACE_BAR1 3
Dan Williams6f231dd2011-07-02 22:56:22 -070074#define ISCI_CAN_QUEUE_VAL 250 /* < SCI_MAX_IO_REQUESTS ? */
75#define SCIC_CONTROLLER_STOP_TIMEOUT 5000
76
Dan Williams6f231dd2011-07-02 22:56:22 -070077struct isci_host {
Artur Wojcikcc3dbd02011-05-04 07:58:16 +000078 struct scic_sds_controller sci;
Dan Williams6f231dd2011-07-02 22:56:22 -070079 union scic_oem_parameters oem_parameters;
80
81 int id; /* unique within a given pci device */
Dan Williams7c40a802011-03-02 11:49:26 -080082 struct list_head timers;
Dan Williams6f231dd2011-07-02 22:56:22 -070083 void *core_ctrl_memory;
84 struct dma_pool *dma_pool;
85 unsigned int dma_pool_alloc_size;
86 struct isci_phy phys[SCI_MAX_PHYS];
87
88 /* isci_ports and sas_ports are implicitly parallel to the
89 * ports maintained by the core
90 */
91 struct isci_port isci_ports[SCI_MAX_PORTS];
92 struct asd_sas_port sas_ports[SCI_MAX_PORTS];
93 struct sas_ha_struct sas_ha;
94
95 int can_queue;
96 spinlock_t queue_lock;
97 spinlock_t state_lock;
98
99 struct pci_dev *pdev;
Dan Williams6f231dd2011-07-02 22:56:22 -0700100
101 enum isci_status status;
Dan Williams0cf89d12011-02-18 09:25:07 -0800102 #define IHOST_START_PENDING 0
103 #define IHOST_STOP_PENDING 1
104 unsigned long flags;
105 wait_queue_head_t eventq;
Dan Williams6f231dd2011-07-02 22:56:22 -0700106 struct Scsi_Host *shost;
107 struct tasklet_struct completion_tasklet;
Dan Williams6f231dd2011-07-02 22:56:22 -0700108 struct list_head requests_to_complete;
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800109 struct list_head requests_to_errorback;
Dan Williams6f231dd2011-07-02 22:56:22 -0700110 spinlock_t scic_lock;
Dan Williamsd9c37392011-03-03 17:59:32 -0800111
Dan Williams57f20f42011-04-21 18:14:45 -0700112 struct isci_remote_device devices[SCI_MAX_REMOTE_DEVICES];
Dan Williams6f231dd2011-07-02 22:56:22 -0700113};
114
Dan Williams6f231dd2011-07-02 22:56:22 -0700115/**
116 * struct isci_pci_info - This class represents the pci function containing the
117 * controllers. Depending on PCI SKU, there could be up to 2 controllers in
118 * the PCI function.
119 */
120#define SCI_MAX_MSIX_INT (SCI_NUM_MSI_X_INT*SCI_MAX_CONTROLLERS)
121
122struct isci_pci_info {
123 struct msix_entry msix_entries[SCI_MAX_MSIX_INT];
Dan Williamsb329aff2011-03-07 16:02:25 -0800124 struct isci_host *hosts[SCI_MAX_CONTROLLERS];
Dan Williamsd044af12011-03-08 09:52:49 -0800125 struct isci_orom *orom;
Dan Williams6f231dd2011-07-02 22:56:22 -0700126};
127
128static inline struct isci_pci_info *to_pci_info(struct pci_dev *pdev)
129{
130 return pci_get_drvdata(pdev);
131}
132
Dan Williamsb329aff2011-03-07 16:02:25 -0800133#define for_each_isci_host(id, ihost, pdev) \
134 for (id = 0, ihost = to_pci_info(pdev)->hosts[id]; \
135 id < ARRAY_SIZE(to_pci_info(pdev)->hosts) && ihost; \
136 ihost = to_pci_info(pdev)->hosts[++id])
Dan Williams6f231dd2011-07-02 22:56:22 -0700137
138static inline
139enum isci_status isci_host_get_state(
140 struct isci_host *isci_host)
141{
142 return isci_host->status;
143}
144
145
146static inline void isci_host_change_state(
147 struct isci_host *isci_host,
148 enum isci_status status)
149{
150 unsigned long flags;
151
152 dev_dbg(&isci_host->pdev->dev,
153 "%s: isci_host = %p, state = 0x%x",
154 __func__,
155 isci_host,
156 status);
157 spin_lock_irqsave(&isci_host->state_lock, flags);
158 isci_host->status = status;
159 spin_unlock_irqrestore(&isci_host->state_lock, flags);
160
161}
162
163static inline int isci_host_can_queue(
164 struct isci_host *isci_host,
165 int num)
166{
167 int ret = 0;
168 unsigned long flags;
169
170 spin_lock_irqsave(&isci_host->queue_lock, flags);
171 if ((isci_host->can_queue - num) < 0) {
172 dev_dbg(&isci_host->pdev->dev,
173 "%s: isci_host->can_queue = %d\n",
174 __func__,
175 isci_host->can_queue);
176 ret = -SAS_QUEUE_FULL;
177
178 } else
179 isci_host->can_queue -= num;
180
181 spin_unlock_irqrestore(&isci_host->queue_lock, flags);
182
183 return ret;
184}
185
186static inline void isci_host_can_dequeue(
187 struct isci_host *isci_host,
188 int num)
189{
190 unsigned long flags;
191
192 spin_lock_irqsave(&isci_host->queue_lock, flags);
193 isci_host->can_queue += num;
194 spin_unlock_irqrestore(&isci_host->queue_lock, flags);
195}
196
Dan Williams0cf89d12011-02-18 09:25:07 -0800197static inline void wait_for_start(struct isci_host *ihost)
198{
199 wait_event(ihost->eventq, !test_bit(IHOST_START_PENDING, &ihost->flags));
200}
201
202static inline void wait_for_stop(struct isci_host *ihost)
203{
204 wait_event(ihost->eventq, !test_bit(IHOST_STOP_PENDING, &ihost->flags));
205}
206
Dan Williams6ad31fe2011-03-04 12:10:29 -0800207static inline void wait_for_device_start(struct isci_host *ihost, struct isci_remote_device *idev)
208{
209 wait_event(ihost->eventq, !test_bit(IDEV_START_PENDING, &idev->flags));
210}
211
212static inline void wait_for_device_stop(struct isci_host *ihost, struct isci_remote_device *idev)
213{
Dan Williamsd9c37392011-03-03 17:59:32 -0800214 wait_event(ihost->eventq, !test_bit(IDEV_STOP_PENDING, &idev->flags));
Dan Williams6ad31fe2011-03-04 12:10:29 -0800215}
Dan Williams0cf89d12011-02-18 09:25:07 -0800216
Dan Williams4393aa42011-03-31 13:10:44 -0700217static inline struct isci_host *dev_to_ihost(struct domain_device *dev)
218{
219 return dev->port->ha->lldd_ha;
220}
Dan Williams6f231dd2011-07-02 22:56:22 -0700221
Artur Wojcikcc3dbd02011-05-04 07:58:16 +0000222static inline struct isci_host *scic_to_ihost(struct scic_sds_controller *scic)
223{
224 /* XXX delete after merging scic_sds_contoller and isci_host */
225 struct isci_host *ihost = container_of(scic, typeof(*ihost), sci);
226
227 return ihost;
228}
229
Dan Williams6f231dd2011-07-02 22:56:22 -0700230/**
231 * isci_host_scan_finished() -
232 *
233 * This function is one of the SCSI Host Template functions. The SCSI midlayer
234 * calls this function during a target scan, approx. once every 10 millisecs.
235 */
236int isci_host_scan_finished(
237 struct Scsi_Host *,
238 unsigned long);
239
240
241/**
242 * isci_host_scan_start() -
243 *
244 * This function is one of the SCSI Host Template function, called by the SCSI
245 * mid layer berfore a target scan begins. The core library controller start
246 * routine is called from here.
247 */
248void isci_host_scan_start(
249 struct Scsi_Host *);
250
251/**
252 * isci_host_start_complete() -
253 *
254 * This function is called by the core library, through the ISCI Module, to
255 * indicate controller start status.
256 */
257void isci_host_start_complete(
258 struct isci_host *,
259 enum sci_status);
260
261void isci_host_stop_complete(
262 struct isci_host *isci_host,
263 enum sci_status completion_status);
264
265int isci_host_init(struct isci_host *);
266
267void isci_host_init_controller_names(
268 struct isci_host *isci_host,
269 unsigned int controller_idx);
270
271void isci_host_deinit(
272 struct isci_host *);
273
274void isci_host_port_link_up(
275 struct isci_host *,
276 struct scic_sds_port *,
277 struct scic_sds_phy *);
278int isci_host_dev_found(struct domain_device *);
279
280void isci_host_remote_device_start_complete(
281 struct isci_host *,
282 struct isci_remote_device *,
283 enum sci_status);
284
285#endif /* !defined(_SCI_HOST_H_) */