pm8001_sas.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. /*
  2. * PMC-Sierra SPC 8001 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 <asm/atomic.h>
  56. #include "pm8001_defs.h"
  57. #define DRV_NAME "pm8001"
  58. #define DRV_VERSION "0.1.36"
  59. #define PM8001_FAIL_LOGGING 0x01 /* Error message logging */
  60. #define PM8001_INIT_LOGGING 0x02 /* driver init logging */
  61. #define PM8001_DISC_LOGGING 0x04 /* discovery layer logging */
  62. #define PM8001_IO_LOGGING 0x08 /* I/O path logging */
  63. #define PM8001_EH_LOGGING 0x10 /* libsas EH function logging*/
  64. #define PM8001_IOCTL_LOGGING 0x20 /* IOCTL message logging */
  65. #define PM8001_MSG_LOGGING 0x40 /* misc message logging */
  66. #define pm8001_printk(format, arg...) printk(KERN_INFO "%s %d:" format,\
  67. __func__, __LINE__, ## arg)
  68. #define PM8001_CHECK_LOGGING(HBA, LEVEL, CMD) \
  69. do { \
  70. if (unlikely(HBA->logging_level & LEVEL)) \
  71. do { \
  72. CMD; \
  73. } while (0); \
  74. } while (0);
  75. #define PM8001_EH_DBG(HBA, CMD) \
  76. PM8001_CHECK_LOGGING(HBA, PM8001_EH_LOGGING, CMD)
  77. #define PM8001_INIT_DBG(HBA, CMD) \
  78. PM8001_CHECK_LOGGING(HBA, PM8001_INIT_LOGGING, CMD)
  79. #define PM8001_DISC_DBG(HBA, CMD) \
  80. PM8001_CHECK_LOGGING(HBA, PM8001_DISC_LOGGING, CMD)
  81. #define PM8001_IO_DBG(HBA, CMD) \
  82. PM8001_CHECK_LOGGING(HBA, PM8001_IO_LOGGING, CMD)
  83. #define PM8001_FAIL_DBG(HBA, CMD) \
  84. PM8001_CHECK_LOGGING(HBA, PM8001_FAIL_LOGGING, CMD)
  85. #define PM8001_IOCTL_DBG(HBA, CMD) \
  86. PM8001_CHECK_LOGGING(HBA, PM8001_IOCTL_LOGGING, CMD)
  87. #define PM8001_MSG_DBG(HBA, CMD) \
  88. PM8001_CHECK_LOGGING(HBA, PM8001_MSG_LOGGING, CMD)
  89. #define PM8001_USE_TASKLET
  90. #define PM8001_USE_MSIX
  91. #define PM8001_READ_VPD
  92. #define DEV_IS_EXPANDER(type) ((type == EDGE_DEV) || (type == FANOUT_DEV))
  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. struct pm8001_hba_info;
  97. struct pm8001_ccb_info;
  98. struct pm8001_device;
  99. /* define task management IU */
  100. struct pm8001_tmf_task {
  101. u8 tmf;
  102. u32 tag_of_task_to_be_managed;
  103. };
  104. struct pm8001_ioctl_payload {
  105. u32 signature;
  106. u16 major_function;
  107. u16 minor_function;
  108. u16 length;
  109. u16 status;
  110. u16 offset;
  111. u16 id;
  112. u8 *func_specific;
  113. };
  114. struct pm8001_dispatch {
  115. char *name;
  116. int (*chip_init)(struct pm8001_hba_info *pm8001_ha);
  117. int (*chip_soft_rst)(struct pm8001_hba_info *pm8001_ha, u32 signature);
  118. void (*chip_rst)(struct pm8001_hba_info *pm8001_ha);
  119. int (*chip_ioremap)(struct pm8001_hba_info *pm8001_ha);
  120. void (*chip_iounmap)(struct pm8001_hba_info *pm8001_ha);
  121. irqreturn_t (*isr)(struct pm8001_hba_info *pm8001_ha);
  122. u32 (*is_our_interupt)(struct pm8001_hba_info *pm8001_ha);
  123. int (*isr_process_oq)(struct pm8001_hba_info *pm8001_ha);
  124. void (*interrupt_enable)(struct pm8001_hba_info *pm8001_ha);
  125. void (*interrupt_disable)(struct pm8001_hba_info *pm8001_ha);
  126. void (*make_prd)(struct scatterlist *scatter, int nr, void *prd);
  127. int (*smp_req)(struct pm8001_hba_info *pm8001_ha,
  128. struct pm8001_ccb_info *ccb);
  129. int (*ssp_io_req)(struct pm8001_hba_info *pm8001_ha,
  130. struct pm8001_ccb_info *ccb);
  131. int (*sata_req)(struct pm8001_hba_info *pm8001_ha,
  132. struct pm8001_ccb_info *ccb);
  133. int (*phy_start_req)(struct pm8001_hba_info *pm8001_ha, u8 phy_id);
  134. int (*phy_stop_req)(struct pm8001_hba_info *pm8001_ha, u8 phy_id);
  135. int (*reg_dev_req)(struct pm8001_hba_info *pm8001_ha,
  136. struct pm8001_device *pm8001_dev, u32 flag);
  137. int (*dereg_dev_req)(struct pm8001_hba_info *pm8001_ha, u32 device_id);
  138. int (*phy_ctl_req)(struct pm8001_hba_info *pm8001_ha,
  139. u32 phy_id, u32 phy_op);
  140. int (*task_abort)(struct pm8001_hba_info *pm8001_ha,
  141. struct pm8001_device *pm8001_dev, u8 flag, u32 task_tag,
  142. u32 cmd_tag);
  143. int (*ssp_tm_req)(struct pm8001_hba_info *pm8001_ha,
  144. struct pm8001_ccb_info *ccb, struct pm8001_tmf_task *tmf);
  145. int (*get_nvmd_req)(struct pm8001_hba_info *pm8001_ha, void *payload);
  146. int (*set_nvmd_req)(struct pm8001_hba_info *pm8001_ha, void *payload);
  147. int (*fw_flash_update_req)(struct pm8001_hba_info *pm8001_ha,
  148. void *payload);
  149. int (*set_dev_state_req)(struct pm8001_hba_info *pm8001_ha,
  150. struct pm8001_device *pm8001_dev, u32 state);
  151. int (*sas_diag_start_end_req)(struct pm8001_hba_info *pm8001_ha,
  152. u32 state);
  153. int (*sas_diag_execute_req)(struct pm8001_hba_info *pm8001_ha,
  154. u32 state);
  155. int (*sas_re_init_req)(struct pm8001_hba_info *pm8001_ha);
  156. };
  157. struct pm8001_chip_info {
  158. u32 n_phy;
  159. const struct pm8001_dispatch *dispatch;
  160. };
  161. #define PM8001_CHIP_DISP (pm8001_ha->chip->dispatch)
  162. struct pm8001_port {
  163. struct asd_sas_port sas_port;
  164. u8 port_attached;
  165. u8 wide_port_phymap;
  166. u8 port_state;
  167. struct list_head list;
  168. };
  169. struct pm8001_phy {
  170. struct pm8001_hba_info *pm8001_ha;
  171. struct pm8001_port *port;
  172. struct asd_sas_phy sas_phy;
  173. struct sas_identify identify;
  174. struct scsi_device *sdev;
  175. u64 dev_sas_addr;
  176. u32 phy_type;
  177. struct completion *enable_completion;
  178. u32 frame_rcvd_size;
  179. u8 frame_rcvd[32];
  180. u8 phy_attached;
  181. u8 phy_state;
  182. enum sas_linkrate minimum_linkrate;
  183. enum sas_linkrate maximum_linkrate;
  184. };
  185. struct pm8001_device {
  186. enum sas_dev_type dev_type;
  187. struct domain_device *sas_device;
  188. u32 attached_phy;
  189. u32 id;
  190. struct completion *dcompletion;
  191. struct completion *setds_completion;
  192. u32 device_id;
  193. u32 running_req;
  194. };
  195. struct pm8001_prd_imt {
  196. __le32 len;
  197. __le32 e;
  198. };
  199. struct pm8001_prd {
  200. __le64 addr; /* 64-bit buffer address */
  201. struct pm8001_prd_imt im_len; /* 64-bit length */
  202. } __attribute__ ((packed));
  203. /*
  204. * CCB(Command Control Block)
  205. */
  206. struct pm8001_ccb_info {
  207. struct list_head entry;
  208. struct sas_task *task;
  209. u32 n_elem;
  210. u32 ccb_tag;
  211. dma_addr_t ccb_dma_handle;
  212. struct pm8001_device *device;
  213. struct pm8001_prd buf_prd[PM8001_MAX_DMA_SG];
  214. struct fw_control_ex *fw_control_context;
  215. };
  216. struct mpi_mem {
  217. void *virt_ptr;
  218. dma_addr_t phys_addr;
  219. u32 phys_addr_hi;
  220. u32 phys_addr_lo;
  221. u32 total_len;
  222. u32 num_elements;
  223. u32 element_size;
  224. u32 alignment;
  225. };
  226. struct mpi_mem_req {
  227. /* The number of element in the mpiMemory array */
  228. u32 count;
  229. /* The array of structures that define memroy regions*/
  230. struct mpi_mem region[USI_MAX_MEMCNT];
  231. };
  232. struct main_cfg_table {
  233. u32 signature;
  234. u32 interface_rev;
  235. u32 firmware_rev;
  236. u32 max_out_io;
  237. u32 max_sgl;
  238. u32 ctrl_cap_flag;
  239. u32 gst_offset;
  240. u32 inbound_queue_offset;
  241. u32 outbound_queue_offset;
  242. u32 inbound_q_nppd_hppd;
  243. u32 outbound_hw_event_pid0_3;
  244. u32 outbound_hw_event_pid4_7;
  245. u32 outbound_ncq_event_pid0_3;
  246. u32 outbound_ncq_event_pid4_7;
  247. u32 outbound_tgt_ITNexus_event_pid0_3;
  248. u32 outbound_tgt_ITNexus_event_pid4_7;
  249. u32 outbound_tgt_ssp_event_pid0_3;
  250. u32 outbound_tgt_ssp_event_pid4_7;
  251. u32 outbound_tgt_smp_event_pid0_3;
  252. u32 outbound_tgt_smp_event_pid4_7;
  253. u32 upper_event_log_addr;
  254. u32 lower_event_log_addr;
  255. u32 event_log_size;
  256. u32 event_log_option;
  257. u32 upper_iop_event_log_addr;
  258. u32 lower_iop_event_log_addr;
  259. u32 iop_event_log_size;
  260. u32 iop_event_log_option;
  261. u32 fatal_err_interrupt;
  262. u32 fatal_err_dump_offset0;
  263. u32 fatal_err_dump_length0;
  264. u32 fatal_err_dump_offset1;
  265. u32 fatal_err_dump_length1;
  266. u32 hda_mode_flag;
  267. u32 anolog_setup_table_offset;
  268. };
  269. struct general_status_table {
  270. u32 gst_len_mpistate;
  271. u32 iq_freeze_state0;
  272. u32 iq_freeze_state1;
  273. u32 msgu_tcnt;
  274. u32 iop_tcnt;
  275. u32 reserved;
  276. u32 phy_state[8];
  277. u32 reserved1;
  278. u32 reserved2;
  279. u32 reserved3;
  280. u32 recover_err_info[8];
  281. };
  282. struct inbound_queue_table {
  283. u32 element_pri_size_cnt;
  284. u32 upper_base_addr;
  285. u32 lower_base_addr;
  286. u32 ci_upper_base_addr;
  287. u32 ci_lower_base_addr;
  288. u32 pi_pci_bar;
  289. u32 pi_offset;
  290. u32 total_length;
  291. void *base_virt;
  292. void *ci_virt;
  293. u32 reserved;
  294. __le32 consumer_index;
  295. u32 producer_idx;
  296. };
  297. struct outbound_queue_table {
  298. u32 element_size_cnt;
  299. u32 upper_base_addr;
  300. u32 lower_base_addr;
  301. void *base_virt;
  302. u32 pi_upper_base_addr;
  303. u32 pi_lower_base_addr;
  304. u32 ci_pci_bar;
  305. u32 ci_offset;
  306. u32 total_length;
  307. void *pi_virt;
  308. u32 interrup_vec_cnt_delay;
  309. u32 dinterrup_to_pci_offset;
  310. __le32 producer_index;
  311. u32 consumer_idx;
  312. };
  313. struct pm8001_hba_memspace {
  314. void __iomem *memvirtaddr;
  315. u64 membase;
  316. u32 memsize;
  317. };
  318. struct pm8001_hba_info {
  319. char name[PM8001_NAME_LENGTH];
  320. struct list_head list;
  321. unsigned long flags;
  322. spinlock_t lock;/* host-wide lock */
  323. struct pci_dev *pdev;/* our device */
  324. struct device *dev;
  325. struct pm8001_hba_memspace io_mem[6];
  326. struct mpi_mem_req memoryMap;
  327. void __iomem *msg_unit_tbl_addr;/*Message Unit Table Addr*/
  328. void __iomem *main_cfg_tbl_addr;/*Main Config Table Addr*/
  329. void __iomem *general_stat_tbl_addr;/*General Status Table Addr*/
  330. void __iomem *inbnd_q_tbl_addr;/*Inbound Queue Config Table Addr*/
  331. void __iomem *outbnd_q_tbl_addr;/*Outbound Queue Config Table Addr*/
  332. struct main_cfg_table main_cfg_tbl;
  333. struct general_status_table gs_tbl;
  334. struct inbound_queue_table inbnd_q_tbl[PM8001_MAX_INB_NUM];
  335. struct outbound_queue_table outbnd_q_tbl[PM8001_MAX_OUTB_NUM];
  336. u8 sas_addr[SAS_ADDR_SIZE];
  337. struct sas_ha_struct *sas;/* SCSI/SAS glue */
  338. struct Scsi_Host *shost;
  339. u32 chip_id;
  340. const struct pm8001_chip_info *chip;
  341. struct completion *nvmd_completion;
  342. int tags_num;
  343. unsigned long *tags;
  344. struct pm8001_phy phy[PM8001_MAX_PHYS];
  345. struct pm8001_port port[PM8001_MAX_PHYS];
  346. u32 id;
  347. u32 irq;
  348. struct pm8001_device *devices;
  349. struct pm8001_ccb_info *ccb_info;
  350. #ifdef PM8001_USE_MSIX
  351. struct msix_entry msix_entries[16];/*for msi-x interrupt*/
  352. int number_of_intr;/*will be used in remove()*/
  353. #endif
  354. #ifdef PM8001_USE_TASKLET
  355. struct tasklet_struct tasklet;
  356. #endif
  357. u32 logging_level;
  358. u32 fw_status;
  359. const struct firmware *fw_image;
  360. };
  361. struct pm8001_work {
  362. struct work_struct work;
  363. struct pm8001_hba_info *pm8001_ha;
  364. void *data;
  365. int handler;
  366. };
  367. struct pm8001_fw_image_header {
  368. u8 vender_id[8];
  369. u8 product_id;
  370. u8 hardware_rev;
  371. u8 dest_partition;
  372. u8 reserved;
  373. u8 fw_rev[4];
  374. __be32 image_length;
  375. __be32 image_crc;
  376. __be32 startup_entry;
  377. } __attribute__((packed, aligned(4)));
  378. /**
  379. * FW Flash Update status values
  380. */
  381. #define FLASH_UPDATE_COMPLETE_PENDING_REBOOT 0x00
  382. #define FLASH_UPDATE_IN_PROGRESS 0x01
  383. #define FLASH_UPDATE_HDR_ERR 0x02
  384. #define FLASH_UPDATE_OFFSET_ERR 0x03
  385. #define FLASH_UPDATE_CRC_ERR 0x04
  386. #define FLASH_UPDATE_LENGTH_ERR 0x05
  387. #define FLASH_UPDATE_HW_ERR 0x06
  388. #define FLASH_UPDATE_DNLD_NOT_SUPPORTED 0x10
  389. #define FLASH_UPDATE_DISABLED 0x11
  390. /**
  391. * brief param structure for firmware flash update.
  392. */
  393. struct fw_flash_updata_info {
  394. u32 cur_image_offset;
  395. u32 cur_image_len;
  396. u32 total_image_len;
  397. struct pm8001_prd sgl;
  398. };
  399. struct fw_control_info {
  400. u32 retcode;/*ret code (status)*/
  401. u32 phase;/*ret code phase*/
  402. u32 phaseCmplt;/*percent complete for the current
  403. update phase */
  404. u32 version;/*Hex encoded firmware version number*/
  405. u32 offset;/*Used for downloading firmware */
  406. u32 len; /*len of buffer*/
  407. u32 size;/* Used in OS VPD and Trace get size
  408. operations.*/
  409. u32 reserved;/* padding required for 64 bit
  410. alignment */
  411. u8 buffer[1];/* Start of buffer */
  412. };
  413. struct fw_control_ex {
  414. struct fw_control_info *fw_control;
  415. void *buffer;/* keep buffer pointer to be
  416. freed when the response comes*/
  417. void *virtAddr;/* keep virtual address of the data */
  418. void *usrAddr;/* keep virtual address of the
  419. user data */
  420. dma_addr_t phys_addr;
  421. u32 len; /* len of buffer */
  422. void *payload; /* pointer to IOCTL Payload */
  423. u8 inProgress;/*if 1 - the IOCTL request is in
  424. progress */
  425. void *param1;
  426. void *param2;
  427. void *param3;
  428. };
  429. /* pm8001 workqueue */
  430. extern struct workqueue_struct *pm8001_wq;
  431. /******************** function prototype *********************/
  432. int pm8001_tag_alloc(struct pm8001_hba_info *pm8001_ha, u32 *tag_out);
  433. void pm8001_tag_init(struct pm8001_hba_info *pm8001_ha);
  434. u32 pm8001_get_ncq_tag(struct sas_task *task, u32 *tag);
  435. void pm8001_ccb_free(struct pm8001_hba_info *pm8001_ha, u32 ccb_idx);
  436. void pm8001_ccb_task_free(struct pm8001_hba_info *pm8001_ha,
  437. struct sas_task *task, struct pm8001_ccb_info *ccb, u32 ccb_idx);
  438. int pm8001_phy_control(struct asd_sas_phy *sas_phy, enum phy_func func,
  439. void *funcdata);
  440. int pm8001_slave_alloc(struct scsi_device *scsi_dev);
  441. int pm8001_slave_configure(struct scsi_device *sdev);
  442. void pm8001_scan_start(struct Scsi_Host *shost);
  443. int pm8001_scan_finished(struct Scsi_Host *shost, unsigned long time);
  444. int pm8001_queue_command(struct sas_task *task, const int num,
  445. gfp_t gfp_flags);
  446. int pm8001_abort_task(struct sas_task *task);
  447. int pm8001_abort_task_set(struct domain_device *dev, u8 *lun);
  448. int pm8001_clear_aca(struct domain_device *dev, u8 *lun);
  449. int pm8001_clear_task_set(struct domain_device *dev, u8 *lun);
  450. int pm8001_dev_found(struct domain_device *dev);
  451. void pm8001_dev_gone(struct domain_device *dev);
  452. int pm8001_lu_reset(struct domain_device *dev, u8 *lun);
  453. int pm8001_I_T_nexus_reset(struct domain_device *dev);
  454. int pm8001_query_task(struct sas_task *task);
  455. int pm8001_mem_alloc(struct pci_dev *pdev, void **virt_addr,
  456. dma_addr_t *pphys_addr, u32 *pphys_addr_hi, u32 *pphys_addr_lo,
  457. u32 mem_size, u32 align);
  458. /* ctl shared API */
  459. extern struct device_attribute *pm8001_host_attrs[];
  460. #endif