mv_sas.h 13 KB

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