Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 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 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 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" |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 64 | |
| 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 Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 74 | #define ISCI_CAN_QUEUE_VAL 250 /* < SCI_MAX_IO_REQUESTS ? */ |
| 75 | #define SCIC_CONTROLLER_STOP_TIMEOUT 5000 |
| 76 | |
| 77 | struct coherent_memory_info { |
| 78 | struct list_head node; |
| 79 | dma_addr_t dma_handle; |
| 80 | void *vaddr; |
| 81 | size_t size; |
| 82 | struct sci_physical_memory_descriptor *mde; |
| 83 | }; |
| 84 | |
| 85 | struct isci_host { |
| 86 | struct scic_sds_controller *core_controller; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 87 | union scic_oem_parameters oem_parameters; |
| 88 | |
| 89 | int id; /* unique within a given pci device */ |
Dan Williams | 7c40a80 | 2011-03-02 11:49:26 -0800 | [diff] [blame] | 90 | struct list_head timers; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 91 | void *core_ctrl_memory; |
| 92 | struct dma_pool *dma_pool; |
| 93 | unsigned int dma_pool_alloc_size; |
| 94 | struct isci_phy phys[SCI_MAX_PHYS]; |
| 95 | |
| 96 | /* isci_ports and sas_ports are implicitly parallel to the |
| 97 | * ports maintained by the core |
| 98 | */ |
| 99 | struct isci_port isci_ports[SCI_MAX_PORTS]; |
| 100 | struct asd_sas_port sas_ports[SCI_MAX_PORTS]; |
| 101 | struct sas_ha_struct sas_ha; |
| 102 | |
| 103 | int can_queue; |
| 104 | spinlock_t queue_lock; |
| 105 | spinlock_t state_lock; |
| 106 | |
| 107 | struct pci_dev *pdev; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 108 | |
| 109 | enum isci_status status; |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 110 | #define IHOST_START_PENDING 0 |
| 111 | #define IHOST_STOP_PENDING 1 |
| 112 | unsigned long flags; |
| 113 | wait_queue_head_t eventq; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 114 | struct Scsi_Host *shost; |
| 115 | struct tasklet_struct completion_tasklet; |
| 116 | struct list_head mdl_struct_list; |
| 117 | struct list_head requests_to_complete; |
| 118 | struct list_head requests_to_abort; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 119 | spinlock_t scic_lock; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 120 | }; |
| 121 | |
| 122 | |
| 123 | /** |
| 124 | * struct isci_pci_info - This class represents the pci function containing the |
| 125 | * controllers. Depending on PCI SKU, there could be up to 2 controllers in |
| 126 | * the PCI function. |
| 127 | */ |
| 128 | #define SCI_MAX_MSIX_INT (SCI_NUM_MSI_X_INT*SCI_MAX_CONTROLLERS) |
| 129 | |
| 130 | struct isci_pci_info { |
| 131 | struct msix_entry msix_entries[SCI_MAX_MSIX_INT]; |
| 132 | int core_lib_array_index; |
Dan Williams | b329aff | 2011-03-07 16:02:25 -0800 | [diff] [blame^] | 133 | struct isci_host *hosts[SCI_MAX_CONTROLLERS]; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 134 | }; |
| 135 | |
| 136 | static inline struct isci_pci_info *to_pci_info(struct pci_dev *pdev) |
| 137 | { |
| 138 | return pci_get_drvdata(pdev); |
| 139 | } |
| 140 | |
Dan Williams | b329aff | 2011-03-07 16:02:25 -0800 | [diff] [blame^] | 141 | #define for_each_isci_host(id, ihost, pdev) \ |
| 142 | for (id = 0, ihost = to_pci_info(pdev)->hosts[id]; \ |
| 143 | id < ARRAY_SIZE(to_pci_info(pdev)->hosts) && ihost; \ |
| 144 | ihost = to_pci_info(pdev)->hosts[++id]) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 145 | |
| 146 | static inline |
| 147 | enum isci_status isci_host_get_state( |
| 148 | struct isci_host *isci_host) |
| 149 | { |
| 150 | return isci_host->status; |
| 151 | } |
| 152 | |
| 153 | |
| 154 | static inline void isci_host_change_state( |
| 155 | struct isci_host *isci_host, |
| 156 | enum isci_status status) |
| 157 | { |
| 158 | unsigned long flags; |
| 159 | |
| 160 | dev_dbg(&isci_host->pdev->dev, |
| 161 | "%s: isci_host = %p, state = 0x%x", |
| 162 | __func__, |
| 163 | isci_host, |
| 164 | status); |
| 165 | spin_lock_irqsave(&isci_host->state_lock, flags); |
| 166 | isci_host->status = status; |
| 167 | spin_unlock_irqrestore(&isci_host->state_lock, flags); |
| 168 | |
| 169 | } |
| 170 | |
| 171 | static inline int isci_host_can_queue( |
| 172 | struct isci_host *isci_host, |
| 173 | int num) |
| 174 | { |
| 175 | int ret = 0; |
| 176 | unsigned long flags; |
| 177 | |
| 178 | spin_lock_irqsave(&isci_host->queue_lock, flags); |
| 179 | if ((isci_host->can_queue - num) < 0) { |
| 180 | dev_dbg(&isci_host->pdev->dev, |
| 181 | "%s: isci_host->can_queue = %d\n", |
| 182 | __func__, |
| 183 | isci_host->can_queue); |
| 184 | ret = -SAS_QUEUE_FULL; |
| 185 | |
| 186 | } else |
| 187 | isci_host->can_queue -= num; |
| 188 | |
| 189 | spin_unlock_irqrestore(&isci_host->queue_lock, flags); |
| 190 | |
| 191 | return ret; |
| 192 | } |
| 193 | |
| 194 | static inline void isci_host_can_dequeue( |
| 195 | struct isci_host *isci_host, |
| 196 | int num) |
| 197 | { |
| 198 | unsigned long flags; |
| 199 | |
| 200 | spin_lock_irqsave(&isci_host->queue_lock, flags); |
| 201 | isci_host->can_queue += num; |
| 202 | spin_unlock_irqrestore(&isci_host->queue_lock, flags); |
| 203 | } |
| 204 | |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 205 | static inline void wait_for_start(struct isci_host *ihost) |
| 206 | { |
| 207 | wait_event(ihost->eventq, !test_bit(IHOST_START_PENDING, &ihost->flags)); |
| 208 | } |
| 209 | |
| 210 | static inline void wait_for_stop(struct isci_host *ihost) |
| 211 | { |
| 212 | wait_event(ihost->eventq, !test_bit(IHOST_STOP_PENDING, &ihost->flags)); |
| 213 | } |
| 214 | |
| 215 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 216 | /** |
| 217 | * isci_host_from_sas_ha() - This accessor retrieves the isci_host object |
| 218 | * reference from the Linux sas_ha_struct reference. |
| 219 | * @ha_struct,: This parameter points to the Linux sas_ha_struct object |
| 220 | * |
| 221 | * A reference to the associated isci_host structure. |
| 222 | */ |
| 223 | #define isci_host_from_sas_ha(ha_struct) \ |
| 224 | ((struct isci_host *)(ha_struct)->lldd_ha) |
| 225 | |
| 226 | /** |
| 227 | * isci_host_scan_finished() - |
| 228 | * |
| 229 | * This function is one of the SCSI Host Template functions. The SCSI midlayer |
| 230 | * calls this function during a target scan, approx. once every 10 millisecs. |
| 231 | */ |
| 232 | int isci_host_scan_finished( |
| 233 | struct Scsi_Host *, |
| 234 | unsigned long); |
| 235 | |
| 236 | |
| 237 | /** |
| 238 | * isci_host_scan_start() - |
| 239 | * |
| 240 | * This function is one of the SCSI Host Template function, called by the SCSI |
| 241 | * mid layer berfore a target scan begins. The core library controller start |
| 242 | * routine is called from here. |
| 243 | */ |
| 244 | void isci_host_scan_start( |
| 245 | struct Scsi_Host *); |
| 246 | |
| 247 | /** |
| 248 | * isci_host_start_complete() - |
| 249 | * |
| 250 | * This function is called by the core library, through the ISCI Module, to |
| 251 | * indicate controller start status. |
| 252 | */ |
| 253 | void isci_host_start_complete( |
| 254 | struct isci_host *, |
| 255 | enum sci_status); |
| 256 | |
| 257 | void isci_host_stop_complete( |
| 258 | struct isci_host *isci_host, |
| 259 | enum sci_status completion_status); |
| 260 | |
| 261 | int isci_host_init(struct isci_host *); |
| 262 | |
| 263 | void isci_host_init_controller_names( |
| 264 | struct isci_host *isci_host, |
| 265 | unsigned int controller_idx); |
| 266 | |
| 267 | void isci_host_deinit( |
| 268 | struct isci_host *); |
| 269 | |
| 270 | void isci_host_port_link_up( |
| 271 | struct isci_host *, |
| 272 | struct scic_sds_port *, |
| 273 | struct scic_sds_phy *); |
| 274 | int isci_host_dev_found(struct domain_device *); |
| 275 | |
| 276 | void isci_host_remote_device_start_complete( |
| 277 | struct isci_host *, |
| 278 | struct isci_remote_device *, |
| 279 | enum sci_status); |
| 280 | |
| 281 | #endif /* !defined(_SCI_HOST_H_) */ |