mv_sas.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Marvell 88SE64xx/88SE94xx main function head file
  4. *
  5. * Copyright 2007 Red Hat, Inc.
  6. * Copyright 2008 Marvell. <[email protected]>
  7. * Copyright 2009-2011 Marvell. <[email protected]>
  8. */
  9. #ifndef _MV_SAS_H_
  10. #define _MV_SAS_H_
  11. #include <linux/kernel.h>
  12. #include <linux/module.h>
  13. #include <linux/spinlock.h>
  14. #include <linux/delay.h>
  15. #include <linux/types.h>
  16. #include <linux/ctype.h>
  17. #include <linux/dma-mapping.h>
  18. #include <linux/pci.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/irq.h>
  22. #include <linux/slab.h>
  23. #include <linux/vmalloc.h>
  24. #include <asm/unaligned.h>
  25. #include <scsi/libsas.h>
  26. #include <scsi/scsi.h>
  27. #include <scsi/scsi_tcq.h>
  28. #include <scsi/sas_ata.h>
  29. #include "mv_defs.h"
  30. #define DRV_NAME "mvsas"
  31. #define DRV_VERSION "0.8.16"
  32. #define MVS_ID_NOT_MAPPED 0x7f
  33. #define WIDE_PORT_MAX_PHY 4
  34. #define mv_printk(fmt, arg ...) \
  35. printk(KERN_DEBUG"%s %d:" fmt, __FILE__, __LINE__, ## arg)
  36. #ifdef MV_DEBUG
  37. #define mv_dprintk(format, arg...) \
  38. printk(KERN_DEBUG"%s %d:" format, __FILE__, __LINE__, ## arg)
  39. #else
  40. #define mv_dprintk(format, arg...) no_printk(format, ## arg)
  41. #endif
  42. #define MV_MAX_U32 0xffffffff
  43. extern int interrupt_coalescing;
  44. extern struct mvs_tgt_initiator mvs_tgt;
  45. extern struct mvs_info *tgt_mvi;
  46. extern const struct mvs_dispatch mvs_64xx_dispatch;
  47. extern const struct mvs_dispatch mvs_94xx_dispatch;
  48. #define bit(n) ((u64)1 << n)
  49. #define for_each_phy(__lseq_mask, __mc, __lseq) \
  50. for ((__mc) = (__lseq_mask), (__lseq) = 0; \
  51. (__mc) != 0 ; \
  52. (++__lseq), (__mc) >>= 1)
  53. #define MVS_PHY_ID (1U << sas_phy->id)
  54. #define MV_INIT_DELAYED_WORK(w, f, d) INIT_DELAYED_WORK(w, f)
  55. #define UNASSOC_D2H_FIS(id) \
  56. ((void *) mvi->rx_fis + 0x100 * id)
  57. #define SATA_RECEIVED_FIS_LIST(reg_set) \
  58. ((void *) mvi->rx_fis + mvi->chip->fis_offs + 0x100 * reg_set)
  59. #define SATA_RECEIVED_SDB_FIS(reg_set) \
  60. (SATA_RECEIVED_FIS_LIST(reg_set) + 0x58)
  61. #define SATA_RECEIVED_D2H_FIS(reg_set) \
  62. (SATA_RECEIVED_FIS_LIST(reg_set) + 0x40)
  63. #define SATA_RECEIVED_PIO_FIS(reg_set) \
  64. (SATA_RECEIVED_FIS_LIST(reg_set) + 0x20)
  65. #define SATA_RECEIVED_DMA_FIS(reg_set) \
  66. (SATA_RECEIVED_FIS_LIST(reg_set) + 0x00)
  67. enum dev_status {
  68. MVS_DEV_NORMAL = 0x0,
  69. MVS_DEV_EH = 0x1,
  70. };
  71. enum dev_reset {
  72. MVS_SOFT_RESET = 0,
  73. MVS_HARD_RESET = 1,
  74. MVS_PHY_TUNE = 2,
  75. };
  76. struct mvs_info;
  77. struct mvs_prv_info;
  78. struct mvs_dispatch {
  79. char *name;
  80. int (*chip_init)(struct mvs_info *mvi);
  81. int (*spi_init)(struct mvs_info *mvi);
  82. int (*chip_ioremap)(struct mvs_info *mvi);
  83. void (*chip_iounmap)(struct mvs_info *mvi);
  84. irqreturn_t (*isr)(struct mvs_info *mvi, int irq, u32 stat);
  85. u32 (*isr_status)(struct mvs_info *mvi, int irq);
  86. void (*interrupt_enable)(struct mvs_info *mvi);
  87. void (*interrupt_disable)(struct mvs_info *mvi);
  88. u32 (*read_phy_ctl)(struct mvs_info *mvi, u32 port);
  89. void (*write_phy_ctl)(struct mvs_info *mvi, u32 port, u32 val);
  90. u32 (*read_port_cfg_data)(struct mvs_info *mvi, u32 port);
  91. void (*write_port_cfg_data)(struct mvs_info *mvi, u32 port, u32 val);
  92. void (*write_port_cfg_addr)(struct mvs_info *mvi, u32 port, u32 addr);
  93. u32 (*read_port_vsr_data)(struct mvs_info *mvi, u32 port);
  94. void (*write_port_vsr_data)(struct mvs_info *mvi, u32 port, u32 val);
  95. void (*write_port_vsr_addr)(struct mvs_info *mvi, u32 port, u32 addr);
  96. u32 (*read_port_irq_stat)(struct mvs_info *mvi, u32 port);
  97. void (*write_port_irq_stat)(struct mvs_info *mvi, u32 port, u32 val);
  98. u32 (*read_port_irq_mask)(struct mvs_info *mvi, u32 port);
  99. void (*write_port_irq_mask)(struct mvs_info *mvi, u32 port, u32 val);
  100. void (*command_active)(struct mvs_info *mvi, u32 slot_idx);
  101. void (*clear_srs_irq)(struct mvs_info *mvi, u8 reg_set, u8 clear_all);
  102. void (*issue_stop)(struct mvs_info *mvi, enum mvs_port_type type,
  103. u32 tfs);
  104. void (*start_delivery)(struct mvs_info *mvi, u32 tx);
  105. u32 (*rx_update)(struct mvs_info *mvi);
  106. void (*int_full)(struct mvs_info *mvi);
  107. u8 (*assign_reg_set)(struct mvs_info *mvi, u8 *tfs);
  108. void (*free_reg_set)(struct mvs_info *mvi, u8 *tfs);
  109. u32 (*prd_size)(void);
  110. u32 (*prd_count)(void);
  111. void (*make_prd)(struct scatterlist *scatter, int nr, void *prd);
  112. void (*detect_porttype)(struct mvs_info *mvi, int i);
  113. int (*oob_done)(struct mvs_info *mvi, int i);
  114. void (*fix_phy_info)(struct mvs_info *mvi, int i,
  115. struct sas_identify_frame *id);
  116. void (*phy_work_around)(struct mvs_info *mvi, int i);
  117. void (*phy_set_link_rate)(struct mvs_info *mvi, u32 phy_id,
  118. struct sas_phy_linkrates *rates);
  119. u32 (*phy_max_link_rate)(void);
  120. void (*phy_disable)(struct mvs_info *mvi, u32 phy_id);
  121. void (*phy_enable)(struct mvs_info *mvi, u32 phy_id);
  122. void (*phy_reset)(struct mvs_info *mvi, u32 phy_id, int hard);
  123. void (*stp_reset)(struct mvs_info *mvi, u32 phy_id);
  124. void (*clear_active_cmds)(struct mvs_info *mvi);
  125. u32 (*spi_read_data)(struct mvs_info *mvi);
  126. void (*spi_write_data)(struct mvs_info *mvi, u32 data);
  127. int (*spi_buildcmd)(struct mvs_info *mvi,
  128. u32 *dwCmd,
  129. u8 cmd,
  130. u8 read,
  131. u8 length,
  132. u32 addr
  133. );
  134. int (*spi_issuecmd)(struct mvs_info *mvi, u32 cmd);
  135. int (*spi_waitdataready)(struct mvs_info *mvi, u32 timeout);
  136. void (*dma_fix)(struct mvs_info *mvi, u32 phy_mask,
  137. int buf_len, int from, void *prd);
  138. void (*tune_interrupt)(struct mvs_info *mvi, u32 time);
  139. void (*non_spec_ncq_error)(struct mvs_info *mvi);
  140. int (*gpio_write)(struct mvs_prv_info *mvs_prv, u8 reg_type,
  141. u8 reg_index, u8 reg_count, u8 *write_data);
  142. };
  143. struct mvs_chip_info {
  144. u32 n_host;
  145. u32 n_phy;
  146. u32 fis_offs;
  147. u32 fis_count;
  148. u32 srs_sz;
  149. u32 sg_width;
  150. u32 slot_width;
  151. const struct mvs_dispatch *dispatch;
  152. };
  153. #define MVS_MAX_SG (1U << mvi->chip->sg_width)
  154. #define MVS_CHIP_SLOT_SZ (1U << mvi->chip->slot_width)
  155. #define MVS_RX_FISL_SZ \
  156. (mvi->chip->fis_offs + (mvi->chip->fis_count * 0x100))
  157. #define MVS_CHIP_DISP (mvi->chip->dispatch)
  158. struct mvs_err_info {
  159. __le32 flags;
  160. __le32 flags2;
  161. };
  162. struct mvs_cmd_hdr {
  163. __le32 flags; /* PRD tbl len; SAS, SATA ctl */
  164. __le32 lens; /* cmd, max resp frame len */
  165. __le32 tags; /* targ port xfer tag; tag */
  166. __le32 data_len; /* data xfer len */
  167. __le64 cmd_tbl; /* command table address */
  168. __le64 open_frame; /* open addr frame address */
  169. __le64 status_buf; /* status buffer address */
  170. __le64 prd_tbl; /* PRD tbl address */
  171. __le32 reserved[4];
  172. };
  173. struct mvs_port {
  174. struct asd_sas_port sas_port;
  175. u8 port_attached;
  176. u8 wide_port_phymap;
  177. struct list_head list;
  178. };
  179. struct mvs_phy {
  180. struct mvs_info *mvi;
  181. struct mvs_port *port;
  182. struct asd_sas_phy sas_phy;
  183. struct sas_identify identify;
  184. struct scsi_device *sdev;
  185. struct timer_list timer;
  186. u64 dev_sas_addr;
  187. u64 att_dev_sas_addr;
  188. u32 att_dev_info;
  189. u32 dev_info;
  190. u32 phy_type;
  191. u32 phy_status;
  192. u32 irq_status;
  193. u32 frame_rcvd_size;
  194. u8 frame_rcvd[32];
  195. u8 phy_attached;
  196. u8 phy_mode;
  197. u8 reserved[2];
  198. u32 phy_event;
  199. enum sas_linkrate minimum_linkrate;
  200. enum sas_linkrate maximum_linkrate;
  201. };
  202. struct mvs_device {
  203. struct list_head dev_entry;
  204. enum sas_device_type dev_type;
  205. struct mvs_info *mvi_info;
  206. struct domain_device *sas_device;
  207. u32 attached_phy;
  208. u32 device_id;
  209. u32 running_req;
  210. u8 taskfileset;
  211. u8 dev_status;
  212. u16 reserved;
  213. };
  214. /* Generate PHY tunning parameters */
  215. struct phy_tuning {
  216. /* 1 bit, transmitter emphasis enable */
  217. u8 trans_emp_en:1;
  218. /* 4 bits, transmitter emphasis amplitude */
  219. u8 trans_emp_amp:4;
  220. /* 3 bits, reserved space */
  221. u8 Reserved_2bit_1:3;
  222. /* 5 bits, transmitter amplitude */
  223. u8 trans_amp:5;
  224. /* 2 bits, transmitter amplitude adjust */
  225. u8 trans_amp_adj:2;
  226. /* 1 bit, reserved space */
  227. u8 resv_2bit_2:1;
  228. /* 2 bytes, reserved space */
  229. u8 reserved[2];
  230. };
  231. struct ffe_control {
  232. /* 4 bits, FFE Capacitor Select (value range 0~F) */
  233. u8 ffe_cap_sel:4;
  234. /* 3 bits, FFE Resistor Select (value range 0~7) */
  235. u8 ffe_rss_sel:3;
  236. /* 1 bit reserve*/
  237. u8 reserved:1;
  238. };
  239. /*
  240. * HBA_Info_Page is saved in Flash/NVRAM, total 256 bytes.
  241. * The data area is valid only Signature="MRVL".
  242. * If any member fills with 0xFF, the member is invalid.
  243. */
  244. struct hba_info_page {
  245. /* Dword 0 */
  246. /* 4 bytes, structure signature,should be "MRVL" at first initial */
  247. u8 signature[4];
  248. /* Dword 1-13 */
  249. u32 reserved1[13];
  250. /* Dword 14-29 */
  251. /* 64 bytes, SAS address for each port */
  252. u64 sas_addr[8];
  253. /* Dword 30-31 */
  254. /* 8 bytes for vanir 8 port PHY FFE seeting
  255. * BIT 0~3 : FFE Capacitor select(value range 0~F)
  256. * BIT 4~6 : FFE Resistor select(value range 0~7)
  257. * BIT 7: reserve.
  258. */
  259. struct ffe_control ffe_ctl[8];
  260. /* Dword 32 -43 */
  261. u32 reserved2[12];
  262. /* Dword 44-45 */
  263. /* 8 bytes, 0: 1.5G, 1: 3.0G, should be 0x01 at first initial */
  264. u8 phy_rate[8];
  265. /* Dword 46-53 */
  266. /* 32 bytes, PHY tuning parameters for each PHY*/
  267. struct phy_tuning phy_tuning[8];
  268. /* Dword 54-63 */
  269. u32 reserved3[10];
  270. }; /* total 256 bytes */
  271. struct mvs_slot_info {
  272. struct list_head entry;
  273. union {
  274. struct sas_task *task;
  275. void *tdata;
  276. };
  277. u32 n_elem;
  278. u32 tx;
  279. u32 slot_tag;
  280. /* DMA buffer for storing cmd tbl, open addr frame, status buffer,
  281. * and PRD table
  282. */
  283. void *buf;
  284. dma_addr_t buf_dma;
  285. void *response;
  286. struct mvs_port *port;
  287. struct mvs_device *device;
  288. void *open_frame;
  289. };
  290. struct mvs_info {
  291. unsigned long flags;
  292. /* host-wide lock */
  293. spinlock_t lock;
  294. /* our device */
  295. struct pci_dev *pdev;
  296. struct device *dev;
  297. /* enhanced mode registers */
  298. void __iomem *regs;
  299. /* peripheral or soc registers */
  300. void __iomem *regs_ex;
  301. u8 sas_addr[SAS_ADDR_SIZE];
  302. /* SCSI/SAS glue */
  303. struct sas_ha_struct *sas;
  304. struct Scsi_Host *shost;
  305. /* TX (delivery) DMA ring */
  306. __le32 *tx;
  307. dma_addr_t tx_dma;
  308. /* cached next-producer idx */
  309. u32 tx_prod;
  310. /* RX (completion) DMA ring */
  311. __le32 *rx;
  312. dma_addr_t rx_dma;
  313. /* RX consumer idx */
  314. u32 rx_cons;
  315. /* RX'd FIS area */
  316. __le32 *rx_fis;
  317. dma_addr_t rx_fis_dma;
  318. /* DMA command header slots */
  319. struct mvs_cmd_hdr *slot;
  320. dma_addr_t slot_dma;
  321. u32 chip_id;
  322. const struct mvs_chip_info *chip;
  323. int tags_num;
  324. unsigned long *tags;
  325. /* further per-slot information */
  326. struct mvs_phy phy[MVS_MAX_PHYS];
  327. struct mvs_port port[MVS_MAX_PHYS];
  328. u32 id;
  329. u64 sata_reg_set;
  330. struct list_head *hba_list;
  331. struct list_head soc_entry;
  332. struct list_head wq_list;
  333. unsigned long instance;
  334. u16 flashid;
  335. u32 flashsize;
  336. u32 flashsectSize;
  337. void *addon;
  338. struct hba_info_page hba_info_param;
  339. struct mvs_device devices[MVS_MAX_DEVICES];
  340. void *bulk_buffer;
  341. dma_addr_t bulk_buffer_dma;
  342. void *bulk_buffer1;
  343. dma_addr_t bulk_buffer_dma1;
  344. #define TRASH_BUCKET_SIZE 0x20000
  345. void *dma_pool;
  346. struct mvs_slot_info slot_info[];
  347. };
  348. struct mvs_prv_info{
  349. u8 n_host;
  350. u8 n_phy;
  351. u8 scan_finished;
  352. u8 reserve;
  353. struct mvs_info *mvi[2];
  354. struct tasklet_struct mv_tasklet;
  355. };
  356. struct mvs_wq {
  357. struct delayed_work work_q;
  358. struct mvs_info *mvi;
  359. void *data;
  360. int handler;
  361. struct list_head entry;
  362. };
  363. struct mvs_task_exec_info {
  364. struct sas_task *task;
  365. struct mvs_cmd_hdr *hdr;
  366. struct mvs_port *port;
  367. u32 tag;
  368. int n_elem;
  369. };
  370. /******************** function prototype *********************/
  371. void mvs_get_sas_addr(void *buf, u32 buflen);
  372. void mvs_tag_clear(struct mvs_info *mvi, u32 tag);
  373. void mvs_tag_free(struct mvs_info *mvi, u32 tag);
  374. void mvs_tag_set(struct mvs_info *mvi, unsigned int tag);
  375. int mvs_tag_alloc(struct mvs_info *mvi, u32 *tag_out);
  376. void mvs_tag_init(struct mvs_info *mvi);
  377. void mvs_iounmap(void __iomem *regs);
  378. int mvs_ioremap(struct mvs_info *mvi, int bar, int bar_ex);
  379. void mvs_phys_reset(struct mvs_info *mvi, u32 phy_mask, int hard);
  380. int mvs_phy_control(struct asd_sas_phy *sas_phy, enum phy_func func,
  381. void *funcdata);
  382. void mvs_set_sas_addr(struct mvs_info *mvi, int port_id, u32 off_lo,
  383. u32 off_hi, u64 sas_addr);
  384. void mvs_scan_start(struct Scsi_Host *shost);
  385. int mvs_scan_finished(struct Scsi_Host *shost, unsigned long time);
  386. int mvs_queue_command(struct sas_task *task, gfp_t gfp_flags);
  387. int mvs_abort_task(struct sas_task *task);
  388. void mvs_port_formed(struct asd_sas_phy *sas_phy);
  389. void mvs_port_deformed(struct asd_sas_phy *sas_phy);
  390. int mvs_dev_found(struct domain_device *dev);
  391. void mvs_dev_gone(struct domain_device *dev);
  392. int mvs_lu_reset(struct domain_device *dev, u8 *lun);
  393. int mvs_slot_complete(struct mvs_info *mvi, u32 rx_desc, u32 flags);
  394. int mvs_I_T_nexus_reset(struct domain_device *dev);
  395. int mvs_query_task(struct sas_task *task);
  396. void mvs_release_task(struct mvs_info *mvi,
  397. struct domain_device *dev);
  398. void mvs_do_release_task(struct mvs_info *mvi, int phy_no,
  399. struct domain_device *dev);
  400. void mvs_int_port(struct mvs_info *mvi, int phy_no, u32 events);
  401. void mvs_update_phyinfo(struct mvs_info *mvi, int i, int get_st);
  402. int mvs_int_rx(struct mvs_info *mvi, bool self_clear);
  403. struct mvs_device *mvs_find_dev_by_reg_set(struct mvs_info *mvi, u8 reg_set);
  404. int mvs_gpio_write(struct sas_ha_struct *, u8 reg_type, u8 reg_index,
  405. u8 reg_count, u8 *write_data);
  406. #endif