Commit | Line | Data |
---|---|---|
6f231dda DW |
1 | /* |
2 | * This file is provided under a dual BSD/GPLv2 license. When using or | |
3 | * redistributing this file, you may do so under either license. | |
4 | * | |
5 | * GPL LICENSE SUMMARY | |
6 | * | |
7 | * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of version 2 of the GNU General Public License as | |
11 | * published by the Free Software Foundation. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, but | |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | * General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program; if not, write to the Free Software | |
20 | * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | |
21 | * The full GNU General Public License is included in this distribution | |
22 | * in the file called LICENSE.GPL. | |
23 | * | |
24 | * BSD LICENSE | |
25 | * | |
26 | * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. | |
27 | * All rights reserved. | |
28 | * | |
29 | * Redistribution and use in source and binary forms, with or without | |
30 | * modification, are permitted provided that the following conditions | |
31 | * are met: | |
32 | * | |
33 | * * Redistributions of source code must retain the above copyright | |
34 | * notice, this list of conditions and the following disclaimer. | |
35 | * * Redistributions in binary form must reproduce the above copyright | |
36 | * notice, this list of conditions and the following disclaimer in | |
37 | * the documentation and/or other materials provided with the | |
38 | * distribution. | |
39 | * * Neither the name of Intel Corporation nor the names of its | |
40 | * contributors may be used to endorse or promote products derived | |
41 | * from this software without specific prior written permission. | |
42 | * | |
43 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
44 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
45 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
46 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
47 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
48 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
49 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
50 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
51 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
52 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
53 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
54 | */ | |
55 | ||
6f231dda DW |
56 | |
57 | #if !defined(_SCI_HOST_H_) | |
58 | #define _SCI_HOST_H_ | |
59 | ||
60 | #include "phy.h" | |
61 | /*#include "task.h"*/ | |
62 | #include "timers.h" | |
63 | #include "remote_device.h" | |
d9c37390 | 64 | #include "scic_remote_device.h" |
6f231dda DW |
65 | |
66 | #define DRV_NAME "isci" | |
67 | #define SCI_PCI_BAR_COUNT 2 | |
68 | #define SCI_NUM_MSI_X_INT 2 | |
69 | #define SCI_SMU_BAR 0 | |
70 | #define SCI_SMU_BAR_SIZE (16*1024) | |
71 | #define SCI_SCU_BAR 1 | |
72 | #define SCI_SCU_BAR_SIZE (4*1024*1024) | |
73 | #define SCI_IO_SPACE_BAR0 2 | |
74 | #define SCI_IO_SPACE_BAR1 3 | |
6f231dda DW |
75 | #define ISCI_CAN_QUEUE_VAL 250 /* < SCI_MAX_IO_REQUESTS ? */ |
76 | #define SCIC_CONTROLLER_STOP_TIMEOUT 5000 | |
77 | ||
78 | struct coherent_memory_info { | |
79 | struct list_head node; | |
80 | dma_addr_t dma_handle; | |
81 | void *vaddr; | |
82 | size_t size; | |
83 | struct sci_physical_memory_descriptor *mde; | |
84 | }; | |
85 | ||
86 | struct isci_host { | |
87 | struct scic_sds_controller *core_controller; | |
6f231dda DW |
88 | union scic_oem_parameters oem_parameters; |
89 | ||
90 | int id; /* unique within a given pci device */ | |
7c40a803 | 91 | struct list_head timers; |
6f231dda DW |
92 | void *core_ctrl_memory; |
93 | struct dma_pool *dma_pool; | |
94 | unsigned int dma_pool_alloc_size; | |
95 | struct isci_phy phys[SCI_MAX_PHYS]; | |
96 | ||
97 | /* isci_ports and sas_ports are implicitly parallel to the | |
98 | * ports maintained by the core | |
99 | */ | |
100 | struct isci_port isci_ports[SCI_MAX_PORTS]; | |
101 | struct asd_sas_port sas_ports[SCI_MAX_PORTS]; | |
102 | struct sas_ha_struct sas_ha; | |
103 | ||
104 | int can_queue; | |
105 | spinlock_t queue_lock; | |
106 | spinlock_t state_lock; | |
107 | ||
108 | struct pci_dev *pdev; | |
6f231dda DW |
109 | |
110 | enum isci_status status; | |
0cf89d1d DW |
111 | #define IHOST_START_PENDING 0 |
112 | #define IHOST_STOP_PENDING 1 | |
113 | unsigned long flags; | |
114 | wait_queue_head_t eventq; | |
6f231dda DW |
115 | struct Scsi_Host *shost; |
116 | struct tasklet_struct completion_tasklet; | |
117 | struct list_head mdl_struct_list; | |
118 | struct list_head requests_to_complete; | |
11b00c19 | 119 | struct list_head requests_to_errorback; |
6f231dda | 120 | spinlock_t scic_lock; |
d9c37390 DW |
121 | |
122 | /* careful only access this via idev_by_id */ | |
123 | struct isci_remote_device devices[0]; | |
6f231dda DW |
124 | }; |
125 | ||
d9c37390 DW |
126 | static inline struct isci_remote_device *idev_by_id(struct isci_host *ihost, int i) |
127 | { | |
128 | void *p = ihost->devices; | |
129 | ||
130 | return p + i * (sizeof(struct isci_remote_device) + | |
131 | scic_remote_device_get_object_size()); | |
132 | } | |
6f231dda DW |
133 | |
134 | /** | |
135 | * struct isci_pci_info - This class represents the pci function containing the | |
136 | * controllers. Depending on PCI SKU, there could be up to 2 controllers in | |
137 | * the PCI function. | |
138 | */ | |
139 | #define SCI_MAX_MSIX_INT (SCI_NUM_MSI_X_INT*SCI_MAX_CONTROLLERS) | |
140 | ||
141 | struct isci_pci_info { | |
142 | struct msix_entry msix_entries[SCI_MAX_MSIX_INT]; | |
b329aff1 | 143 | struct isci_host *hosts[SCI_MAX_CONTROLLERS]; |
d044af17 | 144 | struct isci_orom *orom; |
6f231dda DW |
145 | }; |
146 | ||
147 | static inline struct isci_pci_info *to_pci_info(struct pci_dev *pdev) | |
148 | { | |
149 | return pci_get_drvdata(pdev); | |
150 | } | |
151 | ||
b329aff1 DW |
152 | #define for_each_isci_host(id, ihost, pdev) \ |
153 | for (id = 0, ihost = to_pci_info(pdev)->hosts[id]; \ | |
154 | id < ARRAY_SIZE(to_pci_info(pdev)->hosts) && ihost; \ | |
155 | ihost = to_pci_info(pdev)->hosts[++id]) | |
6f231dda DW |
156 | |
157 | static inline | |
158 | enum isci_status isci_host_get_state( | |
159 | struct isci_host *isci_host) | |
160 | { | |
161 | return isci_host->status; | |
162 | } | |
163 | ||
164 | ||
165 | static inline void isci_host_change_state( | |
166 | struct isci_host *isci_host, | |
167 | enum isci_status status) | |
168 | { | |
169 | unsigned long flags; | |
170 | ||
171 | dev_dbg(&isci_host->pdev->dev, | |
172 | "%s: isci_host = %p, state = 0x%x", | |
173 | __func__, | |
174 | isci_host, | |
175 | status); | |
176 | spin_lock_irqsave(&isci_host->state_lock, flags); | |
177 | isci_host->status = status; | |
178 | spin_unlock_irqrestore(&isci_host->state_lock, flags); | |
179 | ||
180 | } | |
181 | ||
182 | static inline int isci_host_can_queue( | |
183 | struct isci_host *isci_host, | |
184 | int num) | |
185 | { | |
186 | int ret = 0; | |
187 | unsigned long flags; | |
188 | ||
189 | spin_lock_irqsave(&isci_host->queue_lock, flags); | |
190 | if ((isci_host->can_queue - num) < 0) { | |
191 | dev_dbg(&isci_host->pdev->dev, | |
192 | "%s: isci_host->can_queue = %d\n", | |
193 | __func__, | |
194 | isci_host->can_queue); | |
195 | ret = -SAS_QUEUE_FULL; | |
196 | ||
197 | } else | |
198 | isci_host->can_queue -= num; | |
199 | ||
200 | spin_unlock_irqrestore(&isci_host->queue_lock, flags); | |
201 | ||
202 | return ret; | |
203 | } | |
204 | ||
205 | static inline void isci_host_can_dequeue( | |
206 | struct isci_host *isci_host, | |
207 | int num) | |
208 | { | |
209 | unsigned long flags; | |
210 | ||
211 | spin_lock_irqsave(&isci_host->queue_lock, flags); | |
212 | isci_host->can_queue += num; | |
213 | spin_unlock_irqrestore(&isci_host->queue_lock, flags); | |
214 | } | |
215 | ||
0cf89d1d DW |
216 | static inline void wait_for_start(struct isci_host *ihost) |
217 | { | |
218 | wait_event(ihost->eventq, !test_bit(IHOST_START_PENDING, &ihost->flags)); | |
219 | } | |
220 | ||
221 | static inline void wait_for_stop(struct isci_host *ihost) | |
222 | { | |
223 | wait_event(ihost->eventq, !test_bit(IHOST_STOP_PENDING, &ihost->flags)); | |
224 | } | |
225 | ||
6ad31fec DW |
226 | static inline void wait_for_device_start(struct isci_host *ihost, struct isci_remote_device *idev) |
227 | { | |
228 | wait_event(ihost->eventq, !test_bit(IDEV_START_PENDING, &idev->flags)); | |
229 | } | |
230 | ||
231 | static inline void wait_for_device_stop(struct isci_host *ihost, struct isci_remote_device *idev) | |
232 | { | |
d9c37390 | 233 | wait_event(ihost->eventq, !test_bit(IDEV_STOP_PENDING, &idev->flags)); |
6ad31fec | 234 | } |
0cf89d1d | 235 | |
6f231dda DW |
236 | /** |
237 | * isci_host_from_sas_ha() - This accessor retrieves the isci_host object | |
238 | * reference from the Linux sas_ha_struct reference. | |
239 | * @ha_struct,: This parameter points to the Linux sas_ha_struct object | |
240 | * | |
241 | * A reference to the associated isci_host structure. | |
242 | */ | |
243 | #define isci_host_from_sas_ha(ha_struct) \ | |
244 | ((struct isci_host *)(ha_struct)->lldd_ha) | |
245 | ||
246 | /** | |
247 | * isci_host_scan_finished() - | |
248 | * | |
249 | * This function is one of the SCSI Host Template functions. The SCSI midlayer | |
250 | * calls this function during a target scan, approx. once every 10 millisecs. | |
251 | */ | |
252 | int isci_host_scan_finished( | |
253 | struct Scsi_Host *, | |
254 | unsigned long); | |
255 | ||
256 | ||
257 | /** | |
258 | * isci_host_scan_start() - | |
259 | * | |
260 | * This function is one of the SCSI Host Template function, called by the SCSI | |
261 | * mid layer berfore a target scan begins. The core library controller start | |
262 | * routine is called from here. | |
263 | */ | |
264 | void isci_host_scan_start( | |
265 | struct Scsi_Host *); | |
266 | ||
267 | /** | |
268 | * isci_host_start_complete() - | |
269 | * | |
270 | * This function is called by the core library, through the ISCI Module, to | |
271 | * indicate controller start status. | |
272 | */ | |
273 | void isci_host_start_complete( | |
274 | struct isci_host *, | |
275 | enum sci_status); | |
276 | ||
277 | void isci_host_stop_complete( | |
278 | struct isci_host *isci_host, | |
279 | enum sci_status completion_status); | |
280 | ||
281 | int isci_host_init(struct isci_host *); | |
282 | ||
283 | void isci_host_init_controller_names( | |
284 | struct isci_host *isci_host, | |
285 | unsigned int controller_idx); | |
286 | ||
287 | void isci_host_deinit( | |
288 | struct isci_host *); | |
289 | ||
290 | void isci_host_port_link_up( | |
291 | struct isci_host *, | |
292 | struct scic_sds_port *, | |
293 | struct scic_sds_phy *); | |
294 | int isci_host_dev_found(struct domain_device *); | |
295 | ||
296 | void isci_host_remote_device_start_complete( | |
297 | struct isci_host *, | |
298 | struct isci_remote_device *, | |
299 | enum sci_status); | |
300 | ||
301 | #endif /* !defined(_SCI_HOST_H_) */ |