pm8001_sas.h 25 KB

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