pm8001_sas.h 25 KB

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