mv_chips.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /*
  2. * Marvell 88SE64xx/88SE94xx register IO interface
  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_CHIPS_H_
  26. #define _MV_CHIPS_H_
  27. #define mr32(reg) readl(regs + reg)
  28. #define mw32(reg, val) writel((val), regs + reg)
  29. #define mw32_f(reg, val) do { \
  30. mw32(reg, val); \
  31. mr32(reg); \
  32. } while (0)
  33. #define iow32(reg, val) outl(val, (unsigned long)(regs + reg))
  34. #define ior32(reg) inl((unsigned long)(regs + reg))
  35. #define iow16(reg, val) outw((unsigned long)(val, regs + reg))
  36. #define ior16(reg) inw((unsigned long)(regs + reg))
  37. #define iow8(reg, val) outb((unsigned long)(val, regs + reg))
  38. #define ior8(reg) inb((unsigned long)(regs + reg))
  39. static inline u32 mvs_cr32(struct mvs_info *mvi, u32 addr)
  40. {
  41. void __iomem *regs = mvi->regs;
  42. mw32(MVS_CMD_ADDR, addr);
  43. return mr32(MVS_CMD_DATA);
  44. }
  45. static inline void mvs_cw32(struct mvs_info *mvi, u32 addr, u32 val)
  46. {
  47. void __iomem *regs = mvi->regs;
  48. mw32(MVS_CMD_ADDR, addr);
  49. mw32(MVS_CMD_DATA, val);
  50. }
  51. static inline u32 mvs_read_phy_ctl(struct mvs_info *mvi, u32 port)
  52. {
  53. void __iomem *regs = mvi->regs;
  54. return (port < 4) ? mr32(MVS_P0_SER_CTLSTAT + port * 4) :
  55. mr32(MVS_P4_SER_CTLSTAT + (port - 4) * 4);
  56. }
  57. static inline void mvs_write_phy_ctl(struct mvs_info *mvi, u32 port, u32 val)
  58. {
  59. void __iomem *regs = mvi->regs;
  60. if (port < 4)
  61. mw32(MVS_P0_SER_CTLSTAT + port * 4, val);
  62. else
  63. mw32(MVS_P4_SER_CTLSTAT + (port - 4) * 4, val);
  64. }
  65. static inline u32 mvs_read_port(struct mvs_info *mvi, u32 off,
  66. u32 off2, u32 port)
  67. {
  68. void __iomem *regs = mvi->regs + off;
  69. void __iomem *regs2 = mvi->regs + off2;
  70. return (port < 4) ? readl(regs + port * 8) :
  71. readl(regs2 + (port - 4) * 8);
  72. }
  73. static inline void mvs_write_port(struct mvs_info *mvi, u32 off, u32 off2,
  74. u32 port, u32 val)
  75. {
  76. void __iomem *regs = mvi->regs + off;
  77. void __iomem *regs2 = mvi->regs + off2;
  78. if (port < 4)
  79. writel(val, regs + port * 8);
  80. else
  81. writel(val, regs2 + (port - 4) * 8);
  82. }
  83. static inline u32 mvs_read_port_cfg_data(struct mvs_info *mvi, u32 port)
  84. {
  85. return mvs_read_port(mvi, MVS_P0_CFG_DATA,
  86. MVS_P4_CFG_DATA, port);
  87. }
  88. static inline void mvs_write_port_cfg_data(struct mvs_info *mvi,
  89. u32 port, u32 val)
  90. {
  91. mvs_write_port(mvi, MVS_P0_CFG_DATA,
  92. MVS_P4_CFG_DATA, port, val);
  93. }
  94. static inline void mvs_write_port_cfg_addr(struct mvs_info *mvi,
  95. u32 port, u32 addr)
  96. {
  97. mvs_write_port(mvi, MVS_P0_CFG_ADDR,
  98. MVS_P4_CFG_ADDR, port, addr);
  99. mdelay(10);
  100. }
  101. static inline u32 mvs_read_port_vsr_data(struct mvs_info *mvi, u32 port)
  102. {
  103. return mvs_read_port(mvi, MVS_P0_VSR_DATA,
  104. MVS_P4_VSR_DATA, port);
  105. }
  106. static inline void mvs_write_port_vsr_data(struct mvs_info *mvi,
  107. u32 port, u32 val)
  108. {
  109. mvs_write_port(mvi, MVS_P0_VSR_DATA,
  110. MVS_P4_VSR_DATA, port, val);
  111. }
  112. static inline void mvs_write_port_vsr_addr(struct mvs_info *mvi,
  113. u32 port, u32 addr)
  114. {
  115. mvs_write_port(mvi, MVS_P0_VSR_ADDR,
  116. MVS_P4_VSR_ADDR, port, addr);
  117. mdelay(10);
  118. }
  119. static inline u32 mvs_read_port_irq_stat(struct mvs_info *mvi, u32 port)
  120. {
  121. return mvs_read_port(mvi, MVS_P0_INT_STAT,
  122. MVS_P4_INT_STAT, port);
  123. }
  124. static inline void mvs_write_port_irq_stat(struct mvs_info *mvi,
  125. u32 port, u32 val)
  126. {
  127. mvs_write_port(mvi, MVS_P0_INT_STAT,
  128. MVS_P4_INT_STAT, port, val);
  129. }
  130. static inline u32 mvs_read_port_irq_mask(struct mvs_info *mvi, u32 port)
  131. {
  132. return mvs_read_port(mvi, MVS_P0_INT_MASK,
  133. MVS_P4_INT_MASK, port);
  134. }
  135. static inline void mvs_write_port_irq_mask(struct mvs_info *mvi,
  136. u32 port, u32 val)
  137. {
  138. mvs_write_port(mvi, MVS_P0_INT_MASK,
  139. MVS_P4_INT_MASK, port, val);
  140. }
  141. static inline void mvs_phy_hacks(struct mvs_info *mvi)
  142. {
  143. u32 tmp;
  144. tmp = mvs_cr32(mvi, CMD_PHY_TIMER);
  145. tmp &= ~(1 << 9);
  146. tmp |= (1 << 10);
  147. mvs_cw32(mvi, CMD_PHY_TIMER, tmp);
  148. /* enable retry 127 times */
  149. mvs_cw32(mvi, CMD_SAS_CTL1, 0x7f7f);
  150. /* extend open frame timeout to max */
  151. tmp = mvs_cr32(mvi, CMD_SAS_CTL0);
  152. tmp &= ~0xffff;
  153. tmp |= 0x3fff;
  154. mvs_cw32(mvi, CMD_SAS_CTL0, tmp);
  155. mvs_cw32(mvi, CMD_WD_TIMER, 0x7a0000);
  156. /* not to halt for different port op during wideport link change */
  157. mvs_cw32(mvi, CMD_APP_ERR_CONFIG, 0xffefbf7d);
  158. }
  159. static inline void mvs_int_sata(struct mvs_info *mvi)
  160. {
  161. u32 tmp;
  162. void __iomem *regs = mvi->regs;
  163. tmp = mr32(MVS_INT_STAT_SRS_0);
  164. if (tmp)
  165. mw32(MVS_INT_STAT_SRS_0, tmp);
  166. MVS_CHIP_DISP->clear_active_cmds(mvi);
  167. }
  168. static inline void mvs_int_full(struct mvs_info *mvi)
  169. {
  170. void __iomem *regs = mvi->regs;
  171. u32 tmp, stat;
  172. int i;
  173. stat = mr32(MVS_INT_STAT);
  174. mvs_int_rx(mvi, false);
  175. for (i = 0; i < mvi->chip->n_phy; i++) {
  176. tmp = (stat >> i) & (CINT_PORT | CINT_PORT_STOPPED);
  177. if (tmp)
  178. mvs_int_port(mvi, i, tmp);
  179. }
  180. if (stat & CINT_NON_SPEC_NCQ_ERROR)
  181. MVS_CHIP_DISP->non_spec_ncq_error(mvi);
  182. if (stat & CINT_SRS)
  183. mvs_int_sata(mvi);
  184. mw32(MVS_INT_STAT, stat);
  185. }
  186. static inline void mvs_start_delivery(struct mvs_info *mvi, u32 tx)
  187. {
  188. void __iomem *regs = mvi->regs;
  189. mw32(MVS_TX_PROD_IDX, tx);
  190. }
  191. static inline u32 mvs_rx_update(struct mvs_info *mvi)
  192. {
  193. void __iomem *regs = mvi->regs;
  194. return mr32(MVS_RX_CONS_IDX);
  195. }
  196. static inline u32 mvs_get_prd_size(void)
  197. {
  198. return sizeof(struct mvs_prd);
  199. }
  200. static inline u32 mvs_get_prd_count(void)
  201. {
  202. return MAX_SG_ENTRY;
  203. }
  204. static inline void mvs_show_pcie_usage(struct mvs_info *mvi)
  205. {
  206. u16 link_stat, link_spd;
  207. const char *spd[] = {
  208. "UnKnown",
  209. "2.5",
  210. "5.0",
  211. };
  212. if (mvi->flags & MVF_FLAG_SOC || mvi->id > 0)
  213. return;
  214. pci_read_config_word(mvi->pdev, PCR_LINK_STAT, &link_stat);
  215. link_spd = (link_stat & PLS_LINK_SPD) >> PLS_LINK_SPD_OFFS;
  216. if (link_spd >= 3)
  217. link_spd = 0;
  218. dev_printk(KERN_INFO, mvi->dev,
  219. "mvsas: PCI-E x%u, Bandwidth Usage: %s Gbps\n",
  220. (link_stat & PLS_NEG_LINK_WD) >> PLS_NEG_LINK_WD_OFFS,
  221. spd[link_spd]);
  222. }
  223. static inline u32 mvs_hw_max_link_rate(void)
  224. {
  225. return MAX_LINK_RATE;
  226. }
  227. #endif /* _MV_CHIPS_H_ */