mv_sas.h 11 KB

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