mv_sas.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  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 <scsi/libsas.h>
  41. #include <scsi/scsi.h>
  42. #include <scsi/scsi_tcq.h>
  43. #include <scsi/sas_ata.h>
  44. #include <linux/version.h>
  45. #include "mv_defs.h"
  46. #define DRV_NAME "mvsas"
  47. #define DRV_VERSION "0.8.2"
  48. #define _MV_DUMP 0
  49. #define MVS_ID_NOT_MAPPED 0x7f
  50. /* #define DISABLE_HOTPLUG_DMA_FIX */
  51. // #define MAX_EXP_RUNNING_REQ 2
  52. #define WIDE_PORT_MAX_PHY 4
  53. #define MV_DISABLE_NCQ 0
  54. #define mv_printk(fmt, arg ...) \
  55. printk(KERN_DEBUG"%s %d:" fmt, __FILE__, __LINE__, ## arg)
  56. #ifdef MV_DEBUG
  57. #define mv_dprintk(format, arg...) \
  58. printk(KERN_DEBUG"%s %d:" format, __FILE__, __LINE__, ## arg)
  59. #else
  60. #define mv_dprintk(format, arg...)
  61. #endif
  62. #define MV_MAX_U32 0xffffffff
  63. extern struct mvs_tgt_initiator mvs_tgt;
  64. extern struct mvs_info *tgt_mvi;
  65. extern const struct mvs_dispatch mvs_64xx_dispatch;
  66. extern const struct mvs_dispatch mvs_94xx_dispatch;
  67. extern struct kmem_cache *mvs_task_list_cache;
  68. #define DEV_IS_EXPANDER(type) \
  69. ((type == EDGE_DEV) || (type == FANOUT_DEV))
  70. #define bit(n) ((u32)1 << n)
  71. #define for_each_phy(__lseq_mask, __mc, __lseq) \
  72. for ((__mc) = (__lseq_mask), (__lseq) = 0; \
  73. (__mc) != 0 ; \
  74. (++__lseq), (__mc) >>= 1)
  75. #define MV_INIT_DELAYED_WORK(w, f, d) INIT_DELAYED_WORK(w, f)
  76. #define UNASSOC_D2H_FIS(id) \
  77. ((void *) mvi->rx_fis + 0x100 * id)
  78. #define SATA_RECEIVED_FIS_LIST(reg_set) \
  79. ((void *) mvi->rx_fis + mvi->chip->fis_offs + 0x100 * reg_set)
  80. #define SATA_RECEIVED_SDB_FIS(reg_set) \
  81. (SATA_RECEIVED_FIS_LIST(reg_set) + 0x58)
  82. #define SATA_RECEIVED_D2H_FIS(reg_set) \
  83. (SATA_RECEIVED_FIS_LIST(reg_set) + 0x40)
  84. #define SATA_RECEIVED_PIO_FIS(reg_set) \
  85. (SATA_RECEIVED_FIS_LIST(reg_set) + 0x20)
  86. #define SATA_RECEIVED_DMA_FIS(reg_set) \
  87. (SATA_RECEIVED_FIS_LIST(reg_set) + 0x00)
  88. enum dev_status {
  89. MVS_DEV_NORMAL = 0x0,
  90. MVS_DEV_EH = 0x1,
  91. };
  92. struct mvs_info;
  93. struct mvs_dispatch {
  94. char *name;
  95. int (*chip_init)(struct mvs_info *mvi);
  96. int (*spi_init)(struct mvs_info *mvi);
  97. int (*chip_ioremap)(struct mvs_info *mvi);
  98. void (*chip_iounmap)(struct mvs_info *mvi);
  99. irqreturn_t (*isr)(struct mvs_info *mvi, int irq, u32 stat);
  100. u32 (*isr_status)(struct mvs_info *mvi, int irq);
  101. void (*interrupt_enable)(struct mvs_info *mvi);
  102. void (*interrupt_disable)(struct mvs_info *mvi);
  103. u32 (*read_phy_ctl)(struct mvs_info *mvi, u32 port);
  104. void (*write_phy_ctl)(struct mvs_info *mvi, u32 port, u32 val);
  105. u32 (*read_port_cfg_data)(struct mvs_info *mvi, u32 port);
  106. void (*write_port_cfg_data)(struct mvs_info *mvi, u32 port, u32 val);
  107. void (*write_port_cfg_addr)(struct mvs_info *mvi, u32 port, u32 addr);
  108. u32 (*read_port_vsr_data)(struct mvs_info *mvi, u32 port);
  109. void (*write_port_vsr_data)(struct mvs_info *mvi, u32 port, u32 val);
  110. void (*write_port_vsr_addr)(struct mvs_info *mvi, u32 port, u32 addr);
  111. u32 (*read_port_irq_stat)(struct mvs_info *mvi, u32 port);
  112. void (*write_port_irq_stat)(struct mvs_info *mvi, u32 port, u32 val);
  113. u32 (*read_port_irq_mask)(struct mvs_info *mvi, u32 port);
  114. void (*write_port_irq_mask)(struct mvs_info *mvi, u32 port, u32 val);
  115. void (*get_sas_addr)(void *buf, u32 buflen);
  116. void (*command_active)(struct mvs_info *mvi, u32 slot_idx);
  117. void (*clear_srs_irq)(struct mvs_info *mvi, u8 reg_set, u8 clear_all);
  118. void (*issue_stop)(struct mvs_info *mvi, enum mvs_port_type type,
  119. u32 tfs);
  120. void (*start_delivery)(struct mvs_info *mvi, u32 tx);
  121. u32 (*rx_update)(struct mvs_info *mvi);
  122. void (*int_full)(struct mvs_info *mvi);
  123. u8 (*assign_reg_set)(struct mvs_info *mvi, u8 *tfs);
  124. void (*free_reg_set)(struct mvs_info *mvi, u8 *tfs);
  125. u32 (*prd_size)(void);
  126. u32 (*prd_count)(void);
  127. void (*make_prd)(struct scatterlist *scatter, int nr, void *prd);
  128. void (*detect_porttype)(struct mvs_info *mvi, int i);
  129. int (*oob_done)(struct mvs_info *mvi, int i);
  130. void (*fix_phy_info)(struct mvs_info *mvi, int i,
  131. struct sas_identify_frame *id);
  132. void (*phy_work_around)(struct mvs_info *mvi, int i);
  133. void (*phy_set_link_rate)(struct mvs_info *mvi, u32 phy_id,
  134. struct sas_phy_linkrates *rates);
  135. u32 (*phy_max_link_rate)(void);
  136. void (*phy_disable)(struct mvs_info *mvi, u32 phy_id);
  137. void (*phy_enable)(struct mvs_info *mvi, u32 phy_id);
  138. void (*phy_reset)(struct mvs_info *mvi, u32 phy_id, int hard);
  139. void (*stp_reset)(struct mvs_info *mvi, u32 phy_id);
  140. void (*clear_active_cmds)(struct mvs_info *mvi);
  141. u32 (*spi_read_data)(struct mvs_info *mvi);
  142. void (*spi_write_data)(struct mvs_info *mvi, u32 data);
  143. int (*spi_buildcmd)(struct mvs_info *mvi,
  144. u32 *dwCmd,
  145. u8 cmd,
  146. u8 read,
  147. u8 length,
  148. u32 addr
  149. );
  150. int (*spi_issuecmd)(struct mvs_info *mvi, u32 cmd);
  151. int (*spi_waitdataready)(struct mvs_info *mvi, u32 timeout);
  152. #ifndef DISABLE_HOTPLUG_DMA_FIX
  153. void (*dma_fix)(dma_addr_t buf_dma, int buf_len, int from, void *prd);
  154. #endif
  155. };
  156. struct mvs_chip_info {
  157. u32 n_host;
  158. u32 n_phy;
  159. u32 fis_offs;
  160. u32 fis_count;
  161. u32 srs_sz;
  162. u32 slot_width;
  163. const struct mvs_dispatch *dispatch;
  164. };
  165. #define MVS_CHIP_SLOT_SZ (1U << mvi->chip->slot_width)
  166. #define MVS_RX_FISL_SZ \
  167. (mvi->chip->fis_offs + (mvi->chip->fis_count * 0x100))
  168. #define MVS_CHIP_DISP (mvi->chip->dispatch)
  169. struct mvs_err_info {
  170. __le32 flags;
  171. __le32 flags2;
  172. };
  173. struct mvs_cmd_hdr {
  174. __le32 flags; /* PRD tbl len; SAS, SATA ctl */
  175. __le32 lens; /* cmd, max resp frame len */
  176. __le32 tags; /* targ port xfer tag; tag */
  177. __le32 data_len; /* data xfer len */
  178. __le64 cmd_tbl; /* command table address */
  179. __le64 open_frame; /* open addr frame address */
  180. __le64 status_buf; /* status buffer address */
  181. __le64 prd_tbl; /* PRD tbl address */
  182. __le32 reserved[4];
  183. };
  184. struct mvs_port {
  185. struct asd_sas_port sas_port;
  186. u8 port_attached;
  187. u8 wide_port_phymap;
  188. struct list_head list;
  189. };
  190. struct mvs_phy {
  191. struct mvs_info *mvi;
  192. struct mvs_port *port;
  193. struct asd_sas_phy sas_phy;
  194. struct sas_identify identify;
  195. struct scsi_device *sdev;
  196. struct timer_list timer;
  197. u64 dev_sas_addr;
  198. u64 att_dev_sas_addr;
  199. u32 att_dev_info;
  200. u32 dev_info;
  201. u32 phy_type;
  202. u32 phy_status;
  203. u32 irq_status;
  204. u32 frame_rcvd_size;
  205. u8 frame_rcvd[32];
  206. u8 phy_attached;
  207. u8 phy_mode;
  208. u8 reserved[2];
  209. u32 phy_event;
  210. enum sas_linkrate minimum_linkrate;
  211. enum sas_linkrate maximum_linkrate;
  212. };
  213. struct mvs_device {
  214. struct list_head dev_entry;
  215. enum sas_dev_type dev_type;
  216. struct mvs_info *mvi_info;
  217. struct domain_device *sas_device;
  218. struct timer_list timer;
  219. u32 attached_phy;
  220. u32 device_id;
  221. u32 running_req;
  222. u8 taskfileset;
  223. u8 dev_status;
  224. u16 reserved;
  225. };
  226. struct mvs_slot_info {
  227. struct list_head entry;
  228. union {
  229. struct sas_task *task;
  230. void *tdata;
  231. };
  232. u32 n_elem;
  233. u32 tx;
  234. u32 slot_tag;
  235. /* DMA buffer for storing cmd tbl, open addr frame, status buffer,
  236. * and PRD table
  237. */
  238. void *buf;
  239. dma_addr_t buf_dma;
  240. #if _MV_DUMP
  241. u32 cmd_size;
  242. #endif
  243. void *response;
  244. struct mvs_port *port;
  245. struct mvs_device *device;
  246. void *open_frame;
  247. };
  248. struct mvs_info {
  249. unsigned long flags;
  250. /* host-wide lock */
  251. spinlock_t lock;
  252. /* our device */
  253. struct pci_dev *pdev;
  254. struct device *dev;
  255. /* enhanced mode registers */
  256. void __iomem *regs;
  257. /* peripheral or soc registers */
  258. void __iomem *regs_ex;
  259. u8 sas_addr[SAS_ADDR_SIZE];
  260. /* SCSI/SAS glue */
  261. struct sas_ha_struct *sas;
  262. struct Scsi_Host *shost;
  263. /* TX (delivery) DMA ring */
  264. __le32 *tx;
  265. dma_addr_t tx_dma;
  266. /* cached next-producer idx */
  267. u32 tx_prod;
  268. /* RX (completion) DMA ring */
  269. __le32 *rx;
  270. dma_addr_t rx_dma;
  271. /* RX consumer idx */
  272. u32 rx_cons;
  273. /* RX'd FIS area */
  274. __le32 *rx_fis;
  275. dma_addr_t rx_fis_dma;
  276. /* DMA command header slots */
  277. struct mvs_cmd_hdr *slot;
  278. dma_addr_t slot_dma;
  279. u32 chip_id;
  280. const struct mvs_chip_info *chip;
  281. int tags_num;
  282. DECLARE_BITMAP(tags, MVS_SLOTS);
  283. /* further per-slot information */
  284. struct mvs_phy phy[MVS_MAX_PHYS];
  285. struct mvs_port port[MVS_MAX_PHYS];
  286. u32 irq;
  287. u32 exp_req;
  288. u32 id;
  289. u64 sata_reg_set;
  290. struct list_head *hba_list;
  291. struct list_head soc_entry;
  292. struct list_head wq_list;
  293. unsigned long instance;
  294. u16 flashid;
  295. u32 flashsize;
  296. u32 flashsectSize;
  297. void *addon;
  298. struct mvs_device devices[MVS_MAX_DEVICES];
  299. #ifndef DISABLE_HOTPLUG_DMA_FIX
  300. void *bulk_buffer;
  301. dma_addr_t bulk_buffer_dma;
  302. #define TRASH_BUCKET_SIZE 0x20000
  303. #endif
  304. void *dma_pool;
  305. struct mvs_slot_info slot_info[0];
  306. };
  307. struct mvs_prv_info{
  308. u8 n_host;
  309. u8 n_phy;
  310. u16 reserve;
  311. struct mvs_info *mvi[2];
  312. };
  313. struct mvs_wq {
  314. struct delayed_work work_q;
  315. struct mvs_info *mvi;
  316. void *data;
  317. int handler;
  318. struct list_head entry;
  319. };
  320. struct mvs_task_exec_info {
  321. struct sas_task *task;
  322. struct mvs_cmd_hdr *hdr;
  323. struct mvs_port *port;
  324. u32 tag;
  325. int n_elem;
  326. };
  327. struct mvs_task_list {
  328. struct sas_task *task;
  329. struct list_head list;
  330. };
  331. /******************** function prototype *********************/
  332. void mvs_get_sas_addr(void *buf, u32 buflen);
  333. void mvs_tag_clear(struct mvs_info *mvi, u32 tag);
  334. void mvs_tag_free(struct mvs_info *mvi, u32 tag);
  335. void mvs_tag_set(struct mvs_info *mvi, unsigned int tag);
  336. int mvs_tag_alloc(struct mvs_info *mvi, u32 *tag_out);
  337. void mvs_tag_init(struct mvs_info *mvi);
  338. void mvs_iounmap(void __iomem *regs);
  339. int mvs_ioremap(struct mvs_info *mvi, int bar, int bar_ex);
  340. void mvs_phys_reset(struct mvs_info *mvi, u32 phy_mask, int hard);
  341. int mvs_phy_control(struct asd_sas_phy *sas_phy, enum phy_func func,
  342. void *funcdata);
  343. void __devinit mvs_set_sas_addr(struct mvs_info *mvi, int port_id,
  344. u32 off_lo, u32 off_hi, u64 sas_addr);
  345. int mvs_slave_alloc(struct scsi_device *scsi_dev);
  346. int mvs_slave_configure(struct scsi_device *sdev);
  347. void mvs_scan_start(struct Scsi_Host *shost);
  348. int mvs_scan_finished(struct Scsi_Host *shost, unsigned long time);
  349. int mvs_queue_command(struct sas_task *task, const int num,
  350. gfp_t gfp_flags);
  351. int mvs_abort_task(struct sas_task *task);
  352. int mvs_abort_task_set(struct domain_device *dev, u8 *lun);
  353. int mvs_clear_aca(struct domain_device *dev, u8 *lun);
  354. int mvs_clear_task_set(struct domain_device *dev, u8 * lun);
  355. void mvs_port_formed(struct asd_sas_phy *sas_phy);
  356. void mvs_port_deformed(struct asd_sas_phy *sas_phy);
  357. int mvs_dev_found(struct domain_device *dev);
  358. void mvs_dev_gone(struct domain_device *dev);
  359. int mvs_lu_reset(struct domain_device *dev, u8 *lun);
  360. int mvs_slot_complete(struct mvs_info *mvi, u32 rx_desc, u32 flags);
  361. int mvs_I_T_nexus_reset(struct domain_device *dev);
  362. int mvs_query_task(struct sas_task *task);
  363. void mvs_release_task(struct mvs_info *mvi,
  364. struct domain_device *dev);
  365. void mvs_do_release_task(struct mvs_info *mvi, int phy_no,
  366. struct domain_device *dev);
  367. void mvs_int_port(struct mvs_info *mvi, int phy_no, u32 events);
  368. void mvs_update_phyinfo(struct mvs_info *mvi, int i, int get_st);
  369. int mvs_int_rx(struct mvs_info *mvi, bool self_clear);
  370. void mvs_hexdump(u32 size, u8 *data, u32 baseaddr);
  371. #endif