| 1 |
/* |
| 2 |
* PMC-Sierra PM8001/8081/8088/8089 SAS/SATA based host adapters driver |
| 3 |
* |
| 4 |
* Copyright (c) 2008-2009 USI Co., Ltd. |
| 5 |
* All rights reserved. |
| 6 |
* |
| 7 |
* Redistribution and use in source and binary forms, with or without |
| 8 |
* modification, are permitted provided that the following conditions |
| 9 |
* are met: |
| 10 |
* 1. Redistributions of source code must retain the above copyright |
| 11 |
* notice, this list of conditions, and the following disclaimer, |
| 12 |
* without modification. |
| 13 |
* 2. Redistributions in binary form must reproduce at minimum a disclaimer |
| 14 |
* substantially similar to the "NO WARRANTY" disclaimer below |
| 15 |
* ("Disclaimer") and any redistribution must be conditioned upon |
| 16 |
* including a substantially similar Disclaimer requirement for further |
| 17 |
* binary redistribution. |
| 18 |
* 3. Neither the names of the above-listed copyright holders nor the names |
| 19 |
* of any contributors may be used to endorse or promote products derived |
| 20 |
* from this software without specific prior written permission. |
| 21 |
* |
| 22 |
* Alternatively, this software may be distributed under the terms of the |
| 23 |
* GNU General Public License ("GPL") version 2 as published by the Free |
| 24 |
* Software Foundation. |
| 25 |
* |
| 26 |
* NO WARRANTY |
| 27 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 28 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 29 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR |
| 30 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 31 |
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 32 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 33 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 34 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 35 |
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 36 |
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 37 |
* POSSIBILITY OF SUCH DAMAGES. |
| 38 |
* |
| 39 |
*/ |
| 40 |
|
| 41 |
#ifndef _PM8001_SAS_H_ |
| 42 |
#define _PM8001_SAS_H_ |
| 43 |
|
| 44 |
#include <linux/kernel.h> |
| 45 |
#include <linux/module.h> |
| 46 |
#include <linux/spinlock.h> |
| 47 |
#include <linux/delay.h> |
| 48 |
#include <linux/types.h> |
| 49 |
#include <linux/ctype.h> |
| 50 |
#include <linux/dma-mapping.h> |
| 51 |
#include <linux/pci.h> |
| 52 |
#include <linux/interrupt.h> |
| 53 |
#include <linux/workqueue.h> |
| 54 |
#include <scsi/libsas.h> |
| 55 |
#include <scsi/scsi_tcq.h> |
| 56 |
#include <scsi/sas_ata.h> |
| 57 |
#include <linux/atomic.h> |
| 58 |
#include <linux/blk-mq.h> |
| 59 |
#include "pm8001_defs.h" |
| 60 |
|
| 61 |
#define DRV_NAME "pm80xx" |
| 62 |
#define DRV_VERSION "0.1.40" |
| 63 |
#define PM8001_FAIL_LOGGING 0x01 /* Error message logging */ |
| 64 |
#define PM8001_INIT_LOGGING 0x02 /* driver init logging */ |
| 65 |
#define PM8001_DISC_LOGGING 0x04 /* discovery layer logging */ |
| 66 |
#define PM8001_IO_LOGGING 0x08 /* I/O path logging */ |
| 67 |
#define PM8001_EH_LOGGING 0x10 /* libsas EH function logging*/ |
| 68 |
#define PM8001_IOCTL_LOGGING 0x20 /* IOCTL message logging */ |
| 69 |
#define PM8001_MSG_LOGGING 0x40 /* misc message logging */ |
| 70 |
#define PM8001_DEV_LOGGING 0x80 /* development message logging */ |
| 71 |
#define PM8001_DEVIO_LOGGING 0x100 /* development io message logging */ |
| 72 |
#define PM8001_IOERR_LOGGING 0x200 /* development io err message logging */ |
| 73 |
#define PM8001_EVENT_LOGGING 0x400 /* HW event logging */ |
| 74 |
|
| 75 |
#define pm8001_info(HBA, fmt, ...) \ |
| 76 |
pr_info("%s:: %s %d: " fmt, \ |
| 77 |
(HBA)->name, __func__, __LINE__, ##__VA_ARGS__) |
| 78 |
|
| 79 |
#define pm8001_dbg(HBA, level, fmt, ...) \ |
| 80 |
do { \ |
| 81 |
if (unlikely((HBA)->logging_level & PM8001_##level##_LOGGING)) \ |
| 82 |
pm8001_info(HBA, fmt, ##__VA_ARGS__); \ |
| 83 |
} while (0) |
| 84 |
|
| 85 |
extern bool pm8001_use_msix; |
| 86 |
|
| 87 |
#define IS_SPCV_12G(dev) ((dev->device == 0X8074) \ |
| 88 |
|| (dev->device == 0X8076) \ |
| 89 |
|| (dev->device == 0X8077) \ |
| 90 |
|| (dev->device == 0X8070) \ |
| 91 |
|| (dev->device == 0X8072)) |
| 92 |
|
| 93 |
#define PM8001_NAME_LENGTH 32/* generic length of strings */ |
| 94 |
extern struct list_head hba_list; |
| 95 |
extern const struct pm8001_dispatch pm8001_8001_dispatch; |
| 96 |
extern const struct pm8001_dispatch pm8001_80xx_dispatch; |
| 97 |
|
| 98 |
extern uint pcs_event_log_severity; |
| 99 |
|
| 100 |
struct pm8001_hba_info; |
| 101 |
struct pm8001_ccb_info; |
| 102 |
struct pm8001_device; |
| 103 |
|
| 104 |
struct pm8001_ioctl_payload { |
| 105 |
u32 signature; |
| 106 |
u16 major_function; |
| 107 |
u16 minor_function; |
| 108 |
u16 status; |
| 109 |
u16 offset; |
| 110 |
u16 id; |
| 111 |
u32 wr_length; |
| 112 |
u32 rd_length; |
| 113 |
u8 *func_specific; |
| 114 |
}; |
| 115 |
|
| 116 |
#define MPI_FATAL_ERROR_TABLE_OFFSET_MASK 0xFFFFFF |
| 117 |
#define MPI_FATAL_ERROR_TABLE_SIZE(value) ((0xFF000000 & value) >> SHIFT24) |
| 118 |
#define MPI_FATAL_EDUMP_TABLE_LO_OFFSET 0x00 /* HNFBUFL */ |
| 119 |
#define MPI_FATAL_EDUMP_TABLE_HI_OFFSET 0x04 /* HNFBUFH */ |
| 120 |
#define MPI_FATAL_EDUMP_TABLE_LENGTH 0x08 /* HNFBLEN */ |
| 121 |
#define MPI_FATAL_EDUMP_TABLE_HANDSHAKE 0x0C /* FDDHSHK */ |
| 122 |
#define MPI_FATAL_EDUMP_TABLE_STATUS 0x10 /* FDDTSTAT */ |
| 123 |
#define MPI_FATAL_EDUMP_TABLE_ACCUM_LEN 0x14 /* ACCDDLEN */ |
| 124 |
#define MPI_FATAL_EDUMP_TABLE_TOTAL_LEN 0x18 /* TOTALLEN */ |
| 125 |
#define MPI_FATAL_EDUMP_TABLE_SIGNATURE 0x1C /* SIGNITURE */ |
| 126 |
#define MPI_FATAL_EDUMP_HANDSHAKE_RDY 0x1 |
| 127 |
#define MPI_FATAL_EDUMP_HANDSHAKE_BUSY 0x0 |
| 128 |
#define MPI_FATAL_EDUMP_TABLE_STAT_RSVD 0x0 |
| 129 |
#define MPI_FATAL_EDUMP_TABLE_STAT_DMA_FAILED 0x1 |
| 130 |
#define MPI_FATAL_EDUMP_TABLE_STAT_NF_SUCCESS_MORE_DATA 0x2 |
| 131 |
#define MPI_FATAL_EDUMP_TABLE_STAT_NF_SUCCESS_DONE 0x3 |
| 132 |
#define TYPE_GSM_SPACE 1 |
| 133 |
#define TYPE_QUEUE 2 |
| 134 |
#define TYPE_FATAL 3 |
| 135 |
#define TYPE_NON_FATAL 4 |
| 136 |
#define TYPE_INBOUND 1 |
| 137 |
#define TYPE_OUTBOUND 2 |
| 138 |
struct forensic_data { |
| 139 |
u32 data_type; |
| 140 |
union { |
| 141 |
struct { |
| 142 |
u32 direct_len; |
| 143 |
u32 direct_offset; |
| 144 |
void *direct_data; |
| 145 |
} gsm_buf; |
| 146 |
struct { |
| 147 |
u16 queue_type; |
| 148 |
u16 queue_index; |
| 149 |
u32 direct_len; |
| 150 |
void *direct_data; |
| 151 |
} queue_buf; |
| 152 |
struct { |
| 153 |
u32 direct_len; |
| 154 |
u32 direct_offset; |
| 155 |
u32 read_len; |
| 156 |
void *direct_data; |
| 157 |
} data_buf; |
| 158 |
}; |
| 159 |
}; |
| 160 |
|
| 161 |
/* bit31-26 - mask bar */ |
| 162 |
#define SCRATCH_PAD0_BAR_MASK 0xFC000000 |
| 163 |
/* bit25-0 - offset mask */ |
| 164 |
#define SCRATCH_PAD0_OFFSET_MASK 0x03FFFFFF |
| 165 |
/* if AAP error state */ |
| 166 |
#define SCRATCH_PAD0_AAPERR_MASK 0xFFFFFFFF |
| 167 |
/* Inbound doorbell bit7 */ |
| 168 |
#define SPCv_MSGU_CFG_TABLE_NONFATAL_DUMP 0x80 |
| 169 |
/* Inbound doorbell bit7 SPCV */ |
| 170 |
#define SPCV_MSGU_CFG_TABLE_TRANSFER_DEBUG_INFO 0x80 |
| 171 |
#define MAIN_MERRDCTO_MERRDCES 0xA0/* DWORD 0x28) */ |
| 172 |
|
| 173 |
/** |
| 174 |
* enum fatal_error_reporter: Indicates the originator of the fatal error |
| 175 |
*/ |
| 176 |
enum fatal_error_reporter { |
| 177 |
REPORTER_DRIVER, |
| 178 |
REPORTER_FIRMWARE, |
| 179 |
}; |
| 180 |
|
| 181 |
struct pm8001_dispatch { |
| 182 |
char *name; |
| 183 |
int (*chip_init)(struct pm8001_hba_info *pm8001_ha); |
| 184 |
void (*chip_post_init)(struct pm8001_hba_info *pm8001_ha); |
| 185 |
int (*chip_soft_rst)(struct pm8001_hba_info *pm8001_ha); |
| 186 |
void (*chip_rst)(struct pm8001_hba_info *pm8001_ha); |
| 187 |
int (*chip_ioremap)(struct pm8001_hba_info *pm8001_ha); |
| 188 |
void (*chip_iounmap)(struct pm8001_hba_info *pm8001_ha); |
| 189 |
irqreturn_t (*isr)(struct pm8001_hba_info *pm8001_ha, u8 vec); |
| 190 |
u32 (*is_our_interrupt)(struct pm8001_hba_info *pm8001_ha); |
| 191 |
int (*isr_process_oq)(struct pm8001_hba_info *pm8001_ha, u8 vec); |
| 192 |
void (*interrupt_enable)(struct pm8001_hba_info *pm8001_ha, u8 vec); |
| 193 |
void (*interrupt_disable)(struct pm8001_hba_info *pm8001_ha, u8 vec); |
| 194 |
void (*make_prd)(struct scatterlist *scatter, int nr, void *prd); |
| 195 |
int (*smp_req)(struct pm8001_hba_info *pm8001_ha, |
| 196 |
struct pm8001_ccb_info *ccb); |
| 197 |
int (*ssp_io_req)(struct pm8001_hba_info *pm8001_ha, |
| 198 |
struct pm8001_ccb_info *ccb); |
| 199 |
int (*sata_req)(struct pm8001_hba_info *pm8001_ha, |
| 200 |
struct pm8001_ccb_info *ccb); |
| 201 |
int (*phy_start_req)(struct pm8001_hba_info *pm8001_ha, u8 phy_id); |
| 202 |
int (*phy_stop_req)(struct pm8001_hba_info *pm8001_ha, u8 phy_id); |
| 203 |
int (*reg_dev_req)(struct pm8001_hba_info *pm8001_ha, |
| 204 |
struct pm8001_device *pm8001_dev, u32 flag); |
| 205 |
int (*dereg_dev_req)(struct pm8001_hba_info *pm8001_ha, u32 device_id); |
| 206 |
int (*phy_ctl_req)(struct pm8001_hba_info *pm8001_ha, |
| 207 |
u32 phy_id, u32 phy_op); |
| 208 |
int (*task_abort)(struct pm8001_hba_info *pm8001_ha, |
| 209 |
struct pm8001_ccb_info *ccb); |
| 210 |
int (*ssp_tm_req)(struct pm8001_hba_info *pm8001_ha, |
| 211 |
struct pm8001_ccb_info *ccb, struct sas_tmf_task *tmf); |
| 212 |
int (*get_nvmd_req)(struct pm8001_hba_info *pm8001_ha, void *payload); |
| 213 |
int (*set_nvmd_req)(struct pm8001_hba_info *pm8001_ha, void *payload); |
| 214 |
int (*fw_flash_update_req)(struct pm8001_hba_info *pm8001_ha, |
| 215 |
void *payload); |
| 216 |
int (*set_dev_state_req)(struct pm8001_hba_info *pm8001_ha, |
| 217 |
struct pm8001_device *pm8001_dev, u32 state); |
| 218 |
int (*sas_diag_start_end_req)(struct pm8001_hba_info *pm8001_ha, |
| 219 |
u32 state); |
| 220 |
int (*sas_diag_execute_req)(struct pm8001_hba_info *pm8001_ha, |
| 221 |
u32 state); |
| 222 |
int (*sas_re_init_req)(struct pm8001_hba_info *pm8001_ha); |
| 223 |
int (*fatal_errors)(struct pm8001_hba_info *pm8001_ha); |
| 224 |
void (*hw_event_ack_req)(struct pm8001_hba_info *pm8001_ha, |
| 225 |
u32 Qnum, u32 SEA, u32 port_id, u32 phyId, u32 param0, |
| 226 |
u32 param1); |
| 227 |
}; |
| 228 |
|
| 229 |
struct pm8001_chip_info { |
| 230 |
u32 encrypt; |
| 231 |
u32 n_phy; |
| 232 |
const struct pm8001_dispatch *dispatch; |
| 233 |
}; |
| 234 |
#define PM8001_CHIP_DISP (pm8001_ha->chip->dispatch) |
| 235 |
|
| 236 |
struct pm8001_port { |
| 237 |
struct asd_sas_port sas_port; |
| 238 |
u8 port_attached; |
| 239 |
u16 wide_port_phymap; |
| 240 |
u8 port_state; |
| 241 |
u8 port_id; |
| 242 |
struct list_head list; |
| 243 |
}; |
| 244 |
|
| 245 |
struct pm8001_phy { |
| 246 |
struct pm8001_hba_info *pm8001_ha; |
| 247 |
struct pm8001_port *port; |
| 248 |
struct asd_sas_phy sas_phy; |
| 249 |
struct sas_identify identify; |
| 250 |
struct scsi_device *sdev; |
| 251 |
u64 dev_sas_addr; |
| 252 |
u32 phy_type; |
| 253 |
struct completion *enable_completion; |
| 254 |
u32 frame_rcvd_size; |
| 255 |
u8 frame_rcvd[32]; |
| 256 |
u8 phy_attached; |
| 257 |
u8 phy_state; |
| 258 |
enum sas_linkrate minimum_linkrate; |
| 259 |
enum sas_linkrate maximum_linkrate; |
| 260 |
struct completion *reset_completion; |
| 261 |
bool port_reset_status; |
| 262 |
bool reset_success; |
| 263 |
}; |
| 264 |
|
| 265 |
/* port reset status */ |
| 266 |
#define PORT_RESET_SUCCESS 0x00 |
| 267 |
#define PORT_RESET_TMO 0x01 |
| 268 |
|
| 269 |
struct pm8001_device { |
| 270 |
enum sas_device_type dev_type; |
| 271 |
struct domain_device *sas_device; |
| 272 |
u32 attached_phy; |
| 273 |
u32 id; |
| 274 |
struct completion *dcompletion; |
| 275 |
struct completion *setds_completion; |
| 276 |
u32 device_id; |
| 277 |
atomic_t running_req; |
| 278 |
}; |
| 279 |
|
| 280 |
struct pm8001_prd_imt { |
| 281 |
__le32 len; |
| 282 |
__le32 e; |
| 283 |
}; |
| 284 |
|
| 285 |
struct pm8001_prd { |
| 286 |
__le64 addr; /* 64-bit buffer address */ |
| 287 |
struct pm8001_prd_imt im_len; /* 64-bit length */ |
| 288 |
} __attribute__ ((packed)); |
| 289 |
/* |
| 290 |
* CCB(Command Control Block) |
| 291 |
*/ |
| 292 |
struct pm8001_ccb_info { |
| 293 |
struct sas_task *task; |
| 294 |
u32 n_elem; |
| 295 |
u32 ccb_tag; |
| 296 |
dma_addr_t ccb_dma_handle; |
| 297 |
struct pm8001_device *device; |
| 298 |
struct pm8001_prd *buf_prd; |
| 299 |
struct fw_control_ex *fw_control_context; |
| 300 |
u8 open_retry; |
| 301 |
}; |
| 302 |
|
| 303 |
struct mpi_mem { |
| 304 |
void *virt_ptr; |
| 305 |
dma_addr_t phys_addr; |
| 306 |
u32 phys_addr_hi; |
| 307 |
u32 phys_addr_lo; |
| 308 |
u32 total_len; |
| 309 |
u32 num_elements; |
| 310 |
u32 element_size; |
| 311 |
u32 alignment; |
| 312 |
}; |
| 313 |
|
| 314 |
struct mpi_mem_req { |
| 315 |
/* The number of element in the mpiMemory array */ |
| 316 |
u32 count; |
| 317 |
/* The array of structures that define memroy regions*/ |
| 318 |
struct mpi_mem region[USI_MAX_MEMCNT]; |
| 319 |
}; |
| 320 |
|
| 321 |
struct encrypt { |
| 322 |
u32 cipher_mode; |
| 323 |
u32 sec_mode; |
| 324 |
u32 status; |
| 325 |
u32 flag; |
| 326 |
}; |
| 327 |
|
| 328 |
struct sas_phy_attribute_table { |
| 329 |
u32 phystart1_16[16]; |
| 330 |
u32 outbound_hw_event_pid1_16[16]; |
| 331 |
}; |
| 332 |
|
| 333 |
union main_cfg_table { |
| 334 |
struct { |
| 335 |
u32 signature; |
| 336 |
u32 interface_rev; |
| 337 |
u32 firmware_rev; |
| 338 |
u32 max_out_io; |
| 339 |
u32 max_sgl; |
| 340 |
u32 ctrl_cap_flag; |
| 341 |
u32 gst_offset; |
| 342 |
u32 inbound_queue_offset; |
| 343 |
u32 outbound_queue_offset; |
| 344 |
u32 inbound_q_nppd_hppd; |
| 345 |
u32 outbound_hw_event_pid0_3; |
| 346 |
u32 outbound_hw_event_pid4_7; |
| 347 |
u32 outbound_ncq_event_pid0_3; |
| 348 |
u32 outbound_ncq_event_pid4_7; |
| 349 |
u32 outbound_tgt_ITNexus_event_pid0_3; |
| 350 |
u32 outbound_tgt_ITNexus_event_pid4_7; |
| 351 |
u32 outbound_tgt_ssp_event_pid0_3; |
| 352 |
u32 outbound_tgt_ssp_event_pid4_7; |
| 353 |
u32 outbound_tgt_smp_event_pid0_3; |
| 354 |
u32 outbound_tgt_smp_event_pid4_7; |
| 355 |
u32 upper_event_log_addr; |
| 356 |
u32 lower_event_log_addr; |
| 357 |
u32 event_log_size; |
| 358 |
u32 event_log_option; |
| 359 |
u32 upper_iop_event_log_addr; |
| 360 |
u32 lower_iop_event_log_addr; |
| 361 |
u32 iop_event_log_size; |
| 362 |
u32 iop_event_log_option; |
| 363 |
u32 fatal_err_interrupt; |
| 364 |
u32 fatal_err_dump_offset0; |
| 365 |
u32 fatal_err_dump_length0; |
| 366 |
u32 fatal_err_dump_offset1; |
| 367 |
u32 fatal_err_dump_length1; |
| 368 |
u32 hda_mode_flag; |
| 369 |
u32 anolog_setup_table_offset; |
| 370 |
u32 rsvd[4]; |
| 371 |
} pm8001_tbl; |
| 372 |
|
| 373 |
struct { |
| 374 |
u32 signature; |
| 375 |
u32 interface_rev; |
| 376 |
u32 firmware_rev; |
| 377 |
u32 max_out_io; |
| 378 |
u32 max_sgl; |
| 379 |
u32 ctrl_cap_flag; |
| 380 |
u32 gst_offset; |
| 381 |
u32 inbound_queue_offset; |
| 382 |
u32 outbound_queue_offset; |
| 383 |
u32 inbound_q_nppd_hppd; |
| 384 |
u32 rsvd[8]; |
| 385 |
u32 crc_core_dump; |
| 386 |
u32 rsvd1; |
| 387 |
u32 upper_event_log_addr; |
| 388 |
u32 lower_event_log_addr; |
| 389 |
u32 event_log_size; |
| 390 |
u32 event_log_severity; |
| 391 |
u32 upper_pcs_event_log_addr; |
| 392 |
u32 lower_pcs_event_log_addr; |
| 393 |
u32 pcs_event_log_size; |
| 394 |
u32 pcs_event_log_severity; |
| 395 |
u32 fatal_err_interrupt; |
| 396 |
u32 fatal_err_dump_offset0; |
| 397 |
u32 fatal_err_dump_length0; |
| 398 |
u32 fatal_err_dump_offset1; |
| 399 |
u32 fatal_err_dump_length1; |
| 400 |
u32 gpio_led_mapping; |
| 401 |
u32 analog_setup_table_offset; |
| 402 |
u32 int_vec_table_offset; |
| 403 |
u32 phy_attr_table_offset; |
| 404 |
u32 port_recovery_timer; |
| 405 |
u32 interrupt_reassertion_delay; |
| 406 |
u32 fatal_n_non_fatal_dump; /* 0x28 */ |
| 407 |
u32 ila_version; |
| 408 |
u32 inc_fw_version; |
| 409 |
} pm80xx_tbl; |
| 410 |
}; |
| 411 |
|
| 412 |
union general_status_table { |
| 413 |
struct { |
| 414 |
u32 gst_len_mpistate; |
| 415 |
u32 iq_freeze_state0; |
| 416 |
u32 iq_freeze_state1; |
| 417 |
u32 msgu_tcnt; |
| 418 |
u32 iop_tcnt; |
| 419 |
u32 rsvd; |
| 420 |
u32 phy_state[8]; |
| 421 |
u32 gpio_input_val; |
| 422 |
u32 rsvd1[2]; |
| 423 |
u32 recover_err_info[8]; |
| 424 |
} pm8001_tbl; |
| 425 |
struct { |
| 426 |
u32 gst_len_mpistate; |
| 427 |
u32 iq_freeze_state0; |
| 428 |
u32 iq_freeze_state1; |
| 429 |
u32 msgu_tcnt; |
| 430 |
u32 iop_tcnt; |
| 431 |
u32 rsvd[9]; |
| 432 |
u32 gpio_input_val; |
| 433 |
u32 rsvd1[2]; |
| 434 |
u32 recover_err_info[8]; |
| 435 |
} pm80xx_tbl; |
| 436 |
}; |
| 437 |
struct inbound_queue_table { |
| 438 |
u32 element_pri_size_cnt; |
| 439 |
u32 upper_base_addr; |
| 440 |
u32 lower_base_addr; |
| 441 |
u32 ci_upper_base_addr; |
| 442 |
u32 ci_lower_base_addr; |
| 443 |
u32 pi_pci_bar; |
| 444 |
u32 pi_offset; |
| 445 |
u32 total_length; |
| 446 |
void *base_virt; |
| 447 |
void *ci_virt; |
| 448 |
u32 reserved; |
| 449 |
__le32 consumer_index; |
| 450 |
u32 producer_idx; |
| 451 |
spinlock_t iq_lock; |
| 452 |
}; |
| 453 |
struct outbound_queue_table { |
| 454 |
u32 element_size_cnt; |
| 455 |
u32 upper_base_addr; |
| 456 |
u32 lower_base_addr; |
| 457 |
void *base_virt; |
| 458 |
u32 pi_upper_base_addr; |
| 459 |
u32 pi_lower_base_addr; |
| 460 |
u32 ci_pci_bar; |
| 461 |
u32 ci_offset; |
| 462 |
u32 total_length; |
| 463 |
void *pi_virt; |
| 464 |
u32 interrup_vec_cnt_delay; |
| 465 |
u32 dinterrup_to_pci_offset; |
| 466 |
__le32 producer_index; |
| 467 |
u32 consumer_idx; |
| 468 |
spinlock_t oq_lock; |
| 469 |
unsigned long lock_flags; |
| 470 |
}; |
| 471 |
struct pm8001_hba_memspace { |
| 472 |
void __iomem *memvirtaddr; |
| 473 |
u64 membase; |
| 474 |
u32 memsize; |
| 475 |
}; |
| 476 |
struct isr_param { |
| 477 |
struct pm8001_hba_info *drv_inst; |
| 478 |
u32 irq_id; |
| 479 |
}; |
| 480 |
struct pm8001_hba_info { |
| 481 |
char name[PM8001_NAME_LENGTH]; |
| 482 |
struct list_head list; |
| 483 |
unsigned long flags; |
| 484 |
spinlock_t lock;/* host-wide lock */ |
| 485 |
spinlock_t bitmap_lock; |
| 486 |
struct pci_dev *pdev;/* our device */ |
| 487 |
struct device *dev; |
| 488 |
struct pm8001_hba_memspace io_mem[6]; |
| 489 |
struct mpi_mem_req memoryMap; |
| 490 |
struct encrypt encrypt_info; /* support encryption */ |
| 491 |
struct forensic_data forensic_info; |
| 492 |
u32 fatal_bar_loc; |
| 493 |
u32 forensic_last_offset; |
| 494 |
u32 fatal_forensic_shift_offset; |
| 495 |
u32 forensic_fatal_step; |
| 496 |
u32 forensic_preserved_accumulated_transfer; |
| 497 |
u32 evtlog_ib_offset; |
| 498 |
u32 evtlog_ob_offset; |
| 499 |
void __iomem *msg_unit_tbl_addr;/*Message Unit Table Addr*/ |
| 500 |
void __iomem *main_cfg_tbl_addr;/*Main Config Table Addr*/ |
| 501 |
void __iomem *general_stat_tbl_addr;/*General Status Table Addr*/ |
| 502 |
void __iomem *inbnd_q_tbl_addr;/*Inbound Queue Config Table Addr*/ |
| 503 |
void __iomem *outbnd_q_tbl_addr;/*Outbound Queue Config Table Addr*/ |
| 504 |
void __iomem *pspa_q_tbl_addr; |
| 505 |
/*MPI SAS PHY attributes Queue Config Table Addr*/ |
| 506 |
void __iomem *ivt_tbl_addr; /*MPI IVT Table Addr */ |
| 507 |
void __iomem *fatal_tbl_addr; /*MPI IVT Table Addr */ |
| 508 |
union main_cfg_table main_cfg_tbl; |
| 509 |
union general_status_table gs_tbl; |
| 510 |
struct inbound_queue_table inbnd_q_tbl[PM8001_MAX_INB_NUM]; |
| 511 |
struct outbound_queue_table outbnd_q_tbl[PM8001_MAX_OUTB_NUM]; |
| 512 |
struct sas_phy_attribute_table phy_attr_table; |
| 513 |
/* MPI SAS PHY attributes */ |
| 514 |
u8 sas_addr[SAS_ADDR_SIZE]; |
| 515 |
struct sas_ha_struct *sas;/* SCSI/SAS glue */ |
| 516 |
struct Scsi_Host *shost; |
| 517 |
u32 chip_id; |
| 518 |
const struct pm8001_chip_info *chip; |
| 519 |
struct completion *nvmd_completion; |
| 520 |
unsigned long *rsvd_tags; |
| 521 |
struct pm8001_phy phy[PM8001_MAX_PHYS]; |
| 522 |
struct pm8001_port port[PM8001_MAX_PHYS]; |
| 523 |
u32 id; |
| 524 |
u32 irq; |
| 525 |
u32 iomb_size; /* SPC and SPCV IOMB size */ |
| 526 |
struct pm8001_device *devices; |
| 527 |
struct pm8001_ccb_info *ccb_info; |
| 528 |
u32 ccb_count; |
| 529 |
|
| 530 |
bool use_msix; |
| 531 |
int number_of_intr;/*will be used in remove()*/ |
| 532 |
char intr_drvname[PM8001_MAX_MSIX_VEC] |
| 533 |
[PM8001_NAME_LENGTH+1+3+1]; |
| 534 |
struct tasklet_struct tasklet[PM8001_MAX_MSIX_VEC]; |
| 535 |
u32 logging_level; |
| 536 |
u32 link_rate; |
| 537 |
u32 fw_status; |
| 538 |
u32 smp_exp_mode; |
| 539 |
bool controller_fatal_error; |
| 540 |
const struct firmware *fw_image; |
| 541 |
struct isr_param irq_vector[PM8001_MAX_MSIX_VEC]; |
| 542 |
u32 non_fatal_count; |
| 543 |
u32 non_fatal_read_length; |
| 544 |
u32 max_q_num; |
| 545 |
u32 ib_offset; |
| 546 |
u32 ob_offset; |
| 547 |
u32 ci_offset; |
| 548 |
u32 pi_offset; |
| 549 |
u32 max_memcnt; |
| 550 |
u32 iop_log_start; |
| 551 |
u32 iop_log_end; |
| 552 |
u32 iop_log_count; |
| 553 |
struct mutex iop_log_lock; |
| 554 |
}; |
| 555 |
|
| 556 |
struct pm8001_work { |
| 557 |
struct work_struct work; |
| 558 |
struct pm8001_hba_info *pm8001_ha; |
| 559 |
void *data; |
| 560 |
int handler; |
| 561 |
}; |
| 562 |
|
| 563 |
struct pm8001_fw_image_header { |
| 564 |
u8 vender_id[8]; |
| 565 |
u8 product_id; |
| 566 |
u8 hardware_rev; |
| 567 |
u8 dest_partition; |
| 568 |
u8 reserved; |
| 569 |
u8 fw_rev[4]; |
| 570 |
__be32 image_length; |
| 571 |
__be32 image_crc; |
| 572 |
__be32 startup_entry; |
| 573 |
} __attribute__((packed, aligned(4))); |
| 574 |
|
| 575 |
|
| 576 |
/** |
| 577 |
* FW Flash Update status values |
| 578 |
*/ |
| 579 |
#define FLASH_UPDATE_COMPLETE_PENDING_REBOOT 0x00 |
| 580 |
#define FLASH_UPDATE_IN_PROGRESS 0x01 |
| 581 |
#define FLASH_UPDATE_HDR_ERR 0x02 |
| 582 |
#define FLASH_UPDATE_OFFSET_ERR 0x03 |
| 583 |
#define FLASH_UPDATE_CRC_ERR 0x04 |
| 584 |
#define FLASH_UPDATE_LENGTH_ERR 0x05 |
| 585 |
#define FLASH_UPDATE_HW_ERR 0x06 |
| 586 |
#define FLASH_UPDATE_DNLD_NOT_SUPPORTED 0x10 |
| 587 |
#define FLASH_UPDATE_DISABLED 0x11 |
| 588 |
|
| 589 |
/* Device states */ |
| 590 |
#define DS_OPERATIONAL 0x01 |
| 591 |
#define DS_PORT_IN_RESET 0x02 |
| 592 |
#define DS_IN_RECOVERY 0x03 |
| 593 |
#define DS_IN_ERROR 0x04 |
| 594 |
#define DS_NON_OPERATIONAL 0x07 |
| 595 |
|
| 596 |
/** |
| 597 |
* brief param structure for firmware flash update. |
| 598 |
*/ |
| 599 |
struct fw_flash_updata_info { |
| 600 |
u32 cur_image_offset; |
| 601 |
u32 cur_image_len; |
| 602 |
u32 total_image_len; |
| 603 |
struct pm8001_prd sgl; |
| 604 |
}; |
| 605 |
|
| 606 |
struct fw_control_info { |
| 607 |
u32 retcode;/*ret code (status)*/ |
| 608 |
u32 phase;/*ret code phase*/ |
| 609 |
u32 phaseCmplt;/*percent complete for the current |
| 610 |
update phase */ |
| 611 |
u32 version;/*Hex encoded firmware version number*/ |
| 612 |
u32 offset;/*Used for downloading firmware */ |
| 613 |
u32 len; /*len of buffer*/ |
| 614 |
u32 size;/* Used in OS VPD and Trace get size |
| 615 |
operations.*/ |
| 616 |
u32 reserved;/* padding required for 64 bit |
| 617 |
alignment */ |
| 618 |
u8 buffer[];/* Start of buffer */ |
| 619 |
}; |
| 620 |
struct fw_control_ex { |
| 621 |
struct fw_control_info *fw_control; |
| 622 |
void *buffer;/* keep buffer pointer to be |
| 623 |
freed when the response comes*/ |
| 624 |
void *virtAddr;/* keep virtual address of the data */ |
| 625 |
void *usrAddr;/* keep virtual address of the |
| 626 |
user data */ |
| 627 |
dma_addr_t phys_addr; |
| 628 |
u32 len; /* len of buffer */ |
| 629 |
void *payload; /* pointer to IOCTL Payload */ |
| 630 |
u8 inProgress;/*if 1 - the IOCTL request is in |
| 631 |
progress */ |
| 632 |
void *param1; |
| 633 |
void *param2; |
| 634 |
void *param3; |
| 635 |
}; |
| 636 |
|
| 637 |
/* pm8001 workqueue */ |
| 638 |
extern struct workqueue_struct *pm8001_wq; |
| 639 |
|
| 640 |
/******************** function prototype *********************/ |
| 641 |
int pm8001_tag_alloc(struct pm8001_hba_info *pm8001_ha, u32 *tag_out); |
| 642 |
u32 pm8001_get_ncq_tag(struct sas_task *task, u32 *tag); |
| 643 |
void pm8001_ccb_task_free(struct pm8001_hba_info *pm8001_ha, |
| 644 |
struct pm8001_ccb_info *ccb); |
| 645 |
int pm8001_phy_control(struct asd_sas_phy *sas_phy, enum phy_func func, |
| 646 |
void *funcdata); |
| 647 |
void pm8001_scan_start(struct Scsi_Host *shost); |
| 648 |
int pm8001_scan_finished(struct Scsi_Host *shost, unsigned long time); |
| 649 |
int pm8001_queue_command(struct sas_task *task, gfp_t gfp_flags); |
| 650 |
int pm8001_abort_task(struct sas_task *task); |
| 651 |
int pm8001_clear_task_set(struct domain_device *dev, u8 *lun); |
| 652 |
int pm8001_dev_found(struct domain_device *dev); |
| 653 |
void pm8001_dev_gone(struct domain_device *dev); |
| 654 |
int pm8001_lu_reset(struct domain_device *dev, u8 *lun); |
| 655 |
int pm8001_I_T_nexus_reset(struct domain_device *dev); |
| 656 |
int pm8001_I_T_nexus_event_handler(struct domain_device *dev); |
| 657 |
int pm8001_query_task(struct sas_task *task); |
| 658 |
void pm8001_port_formed(struct asd_sas_phy *sas_phy); |
| 659 |
void pm8001_open_reject_retry( |
| 660 |
struct pm8001_hba_info *pm8001_ha, |
| 661 |
struct sas_task *task_to_close, |
| 662 |
struct pm8001_device *device_to_close); |
| 663 |
int pm8001_mem_alloc(struct pci_dev *pdev, void **virt_addr, |
| 664 |
dma_addr_t *pphys_addr, u32 *pphys_addr_hi, u32 *pphys_addr_lo, |
| 665 |
u32 mem_size, u32 align); |
| 666 |
|
| 667 |
void pm8001_chip_iounmap(struct pm8001_hba_info *pm8001_ha); |
| 668 |
int pm8001_mpi_build_cmd(struct pm8001_hba_info *pm8001_ha, |
| 669 |
u32 q_index, u32 opCode, void *payload, size_t nb, |
| 670 |
u32 responseQueue); |
| 671 |
int pm8001_mpi_msg_free_get(struct inbound_queue_table *circularQ, |
| 672 |
u16 messageSize, void **messagePtr); |
| 673 |
u32 pm8001_mpi_msg_free_set(struct pm8001_hba_info *pm8001_ha, void *pMsg, |
| 674 |
struct outbound_queue_table *circularQ, u8 bc); |
| 675 |
u32 pm8001_mpi_msg_consume(struct pm8001_hba_info *pm8001_ha, |
| 676 |
struct outbound_queue_table *circularQ, |
| 677 |
void **messagePtr1, u8 *pBC); |
| 678 |
int pm8001_chip_set_dev_state_req(struct pm8001_hba_info *pm8001_ha, |
| 679 |
struct pm8001_device *pm8001_dev, u32 state); |
| 680 |
int pm8001_chip_fw_flash_update_req(struct pm8001_hba_info *pm8001_ha, |
| 681 |
void *payload); |
| 682 |
int pm8001_chip_fw_flash_update_build(struct pm8001_hba_info *pm8001_ha, |
| 683 |
void *fw_flash_updata_info, u32 tag); |
| 684 |
int pm8001_chip_set_nvmd_req(struct pm8001_hba_info *pm8001_ha, void *payload); |
| 685 |
int pm8001_chip_get_nvmd_req(struct pm8001_hba_info *pm8001_ha, void *payload); |
| 686 |
int pm8001_chip_ssp_tm_req(struct pm8001_hba_info *pm8001_ha, |
| 687 |
struct pm8001_ccb_info *ccb, |
| 688 |
struct sas_tmf_task *tmf); |
| 689 |
int pm8001_chip_abort_task(struct pm8001_hba_info *pm8001_ha, |
| 690 |
struct pm8001_ccb_info *ccb); |
| 691 |
int pm8001_chip_dereg_dev_req(struct pm8001_hba_info *pm8001_ha, u32 device_id); |
| 692 |
void pm8001_chip_make_sg(struct scatterlist *scatter, int nr, void *prd); |
| 693 |
void pm8001_work_fn(struct work_struct *work); |
| 694 |
int pm8001_handle_event(struct pm8001_hba_info *pm8001_ha, |
| 695 |
void *data, int handler); |
| 696 |
void pm8001_mpi_set_dev_state_resp(struct pm8001_hba_info *pm8001_ha, |
| 697 |
void *piomb); |
| 698 |
void pm8001_mpi_set_nvmd_resp(struct pm8001_hba_info *pm8001_ha, |
| 699 |
void *piomb); |
| 700 |
void pm8001_mpi_get_nvmd_resp(struct pm8001_hba_info *pm8001_ha, |
| 701 |
void *piomb); |
| 702 |
int pm8001_mpi_local_phy_ctl(struct pm8001_hba_info *pm8001_ha, |
| 703 |
void *piomb); |
| 704 |
void pm8001_get_lrate_mode(struct pm8001_phy *phy, u8 link_rate); |
| 705 |
void pm8001_get_attached_sas_addr(struct pm8001_phy *phy, u8 *sas_addr); |
| 706 |
void pm8001_bytes_dmaed(struct pm8001_hba_info *pm8001_ha, int i); |
| 707 |
int pm8001_mpi_reg_resp(struct pm8001_hba_info *pm8001_ha, void *piomb); |
| 708 |
int pm8001_mpi_dereg_resp(struct pm8001_hba_info *pm8001_ha, void *piomb); |
| 709 |
int pm8001_mpi_fw_flash_update_resp(struct pm8001_hba_info *pm8001_ha, |
| 710 |
void *piomb); |
| 711 |
int pm8001_mpi_general_event(struct pm8001_hba_info *pm8001_ha, void *piomb); |
| 712 |
int pm8001_mpi_task_abort_resp(struct pm8001_hba_info *pm8001_ha, void *piomb); |
| 713 |
void pm8001_tag_free(struct pm8001_hba_info *pm8001_ha, u32 tag); |
| 714 |
struct pm8001_device *pm8001_find_dev(struct pm8001_hba_info *pm8001_ha, |
| 715 |
u32 device_id); |
| 716 |
int pm80xx_set_thermal_config(struct pm8001_hba_info *pm8001_ha); |
| 717 |
|
| 718 |
int pm8001_bar4_shift(struct pm8001_hba_info *pm8001_ha, u32 shiftValue); |
| 719 |
void pm8001_set_phy_profile(struct pm8001_hba_info *pm8001_ha, |
| 720 |
u32 length, u8 *buf); |
| 721 |
void pm8001_set_phy_profile_single(struct pm8001_hba_info *pm8001_ha, |
| 722 |
u32 phy, u32 length, u32 *buf); |
| 723 |
int pm80xx_bar4_shift(struct pm8001_hba_info *pm8001_ha, u32 shiftValue); |
| 724 |
ssize_t pm80xx_get_fatal_dump(struct device *cdev, |
| 725 |
struct device_attribute *attr, char *buf); |
| 726 |
ssize_t pm80xx_get_non_fatal_dump(struct device *cdev, |
| 727 |
struct device_attribute *attr, char *buf); |
| 728 |
ssize_t pm8001_get_gsm_dump(struct device *cdev, u32, char *buf); |
| 729 |
int pm80xx_fatal_errors(struct pm8001_hba_info *pm8001_ha); |
| 730 |
void pm80xx_fatal_error_uevent_emit(struct pm8001_hba_info *pm8001_ha, |
| 731 |
enum fatal_error_reporter error_reporter); |
| 732 |
void pm8001_free_dev(struct pm8001_device *pm8001_dev); |
| 733 |
/* ctl shared API */ |
| 734 |
extern const struct attribute_group *pm8001_host_groups[]; |
| 735 |
extern const struct attribute_group *pm8001_sdev_groups[]; |
| 736 |
|
| 737 |
#define PM8001_INVALID_TAG ((u32)-1) |
| 738 |
|
| 739 |
/* |
| 740 |
* Allocate a new tag and return the corresponding ccb after initializing it. |
| 741 |
*/ |
| 742 |
static inline struct pm8001_ccb_info * |
| 743 |
pm8001_ccb_alloc(struct pm8001_hba_info *pm8001_ha, |
| 744 |
struct pm8001_device *dev, struct sas_task *task) |
| 745 |
{ |
| 746 |
struct pm8001_ccb_info *ccb; |
| 747 |
struct request *rq = NULL; |
| 748 |
u32 tag; |
| 749 |
|
| 750 |
if (task) |
| 751 |
rq = sas_task_find_rq(task); |
| 752 |
|
| 753 |
if (rq) { |
| 754 |
tag = rq->tag + PM8001_RESERVE_SLOT; |
| 755 |
} else if (pm8001_tag_alloc(pm8001_ha, &tag)) { |
| 756 |
pm8001_dbg(pm8001_ha, FAIL, "Failed to allocate a tag\n"); |
| 757 |
return NULL; |
| 758 |
} |
| 759 |
|
| 760 |
ccb = &pm8001_ha->ccb_info[tag]; |
| 761 |
ccb->task = task; |
| 762 |
ccb->n_elem = 0; |
| 763 |
ccb->ccb_tag = tag; |
| 764 |
ccb->device = dev; |
| 765 |
ccb->fw_control_context = NULL; |
| 766 |
ccb->open_retry = 0; |
| 767 |
|
| 768 |
return ccb; |
| 769 |
} |
| 770 |
|
| 771 |
/* |
| 772 |
* Free the tag of an initialized ccb. |
| 773 |
*/ |
| 774 |
static inline void pm8001_ccb_free(struct pm8001_hba_info *pm8001_ha, |
| 775 |
struct pm8001_ccb_info *ccb) |
| 776 |
{ |
| 777 |
u32 tag = ccb->ccb_tag; |
| 778 |
|
| 779 |
/* |
| 780 |
* Cleanup the ccb to make sure that a manual scan of the adapter |
| 781 |
* ccb_info array can detect ccb's that are in use. |
| 782 |
* C.f. pm8001_open_reject_retry() |
| 783 |
*/ |
| 784 |
ccb->task = NULL; |
| 785 |
ccb->ccb_tag = PM8001_INVALID_TAG; |
| 786 |
ccb->device = NULL; |
| 787 |
ccb->fw_control_context = NULL; |
| 788 |
|
| 789 |
pm8001_tag_free(pm8001_ha, tag); |
| 790 |
} |
| 791 |
|
| 792 |
static inline void pm8001_ccb_task_free_done(struct pm8001_hba_info *pm8001_ha, |
| 793 |
struct pm8001_ccb_info *ccb) |
| 794 |
{ |
| 795 |
struct sas_task *task = ccb->task; |
| 796 |
|
| 797 |
pm8001_ccb_task_free(pm8001_ha, ccb); |
| 798 |
smp_mb(); /*in order to force CPU ordering*/ |
| 799 |
task->task_done(task); |
| 800 |
} |
| 801 |
void pm8001_setds_completion(struct domain_device *dev); |
| 802 |
void pm8001_tmf_aborted(struct sas_task *task); |
| 803 |
void pm80xx_show_pending_commands(struct pm8001_hba_info *pm8001_ha, |
| 804 |
struct pm8001_device *dev); |
| 805 |
u32 pm80xx_get_local_phy_id(struct domain_device *dev); |
| 806 |
|
| 807 |
#endif |
| 808 |
|