mv_64xx.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839
  1. /*
  2. * Marvell 88SE64xx hardware specific
  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. #include "mv_sas.h"
  26. #include "mv_64xx.h"
  27. #include "mv_chips.h"
  28. static void mvs_64xx_detect_porttype(struct mvs_info *mvi, int i)
  29. {
  30. void __iomem *regs = mvi->regs;
  31. u32 reg;
  32. struct mvs_phy *phy = &mvi->phy[i];
  33. /* TODO check & save device type */
  34. reg = mr32(MVS_GBL_PORT_TYPE);
  35. phy->phy_type &= ~(PORT_TYPE_SAS | PORT_TYPE_SATA);
  36. if (reg & MODE_SAS_SATA & (1 << i))
  37. phy->phy_type |= PORT_TYPE_SAS;
  38. else
  39. phy->phy_type |= PORT_TYPE_SATA;
  40. }
  41. static void __devinit mvs_64xx_enable_xmt(struct mvs_info *mvi, int phy_id)
  42. {
  43. void __iomem *regs = mvi->regs;
  44. u32 tmp;
  45. tmp = mr32(MVS_PCS);
  46. if (mvi->chip->n_phy <= MVS_SOC_PORTS)
  47. tmp |= 1 << (phy_id + PCS_EN_PORT_XMT_SHIFT);
  48. else
  49. tmp |= 1 << (phy_id + PCS_EN_PORT_XMT_SHIFT2);
  50. mw32(MVS_PCS, tmp);
  51. }
  52. static void __devinit mvs_64xx_phy_hacks(struct mvs_info *mvi)
  53. {
  54. void __iomem *regs = mvi->regs;
  55. int i;
  56. mvs_phy_hacks(mvi);
  57. if (!(mvi->flags & MVF_FLAG_SOC)) {
  58. /* TEST - for phy decoding error, adjust voltage levels */
  59. for (i = 0; i < MVS_SOC_PORTS; i++) {
  60. mvs_write_port_vsr_addr(mvi, i, VSR_PHY_MODE8);
  61. mvs_write_port_vsr_data(mvi, i, 0x2F0);
  62. }
  63. } else {
  64. /* disable auto port detection */
  65. mw32(MVS_GBL_PORT_TYPE, 0);
  66. for (i = 0; i < mvi->chip->n_phy; i++) {
  67. mvs_write_port_vsr_addr(mvi, i, VSR_PHY_MODE7);
  68. mvs_write_port_vsr_data(mvi, i, 0x90000000);
  69. mvs_write_port_vsr_addr(mvi, i, VSR_PHY_MODE9);
  70. mvs_write_port_vsr_data(mvi, i, 0x50f2);
  71. mvs_write_port_vsr_addr(mvi, i, VSR_PHY_MODE11);
  72. mvs_write_port_vsr_data(mvi, i, 0x0e);
  73. }
  74. }
  75. }
  76. static void mvs_64xx_stp_reset(struct mvs_info *mvi, u32 phy_id)
  77. {
  78. void __iomem *regs = mvi->regs;
  79. u32 reg, tmp;
  80. if (!(mvi->flags & MVF_FLAG_SOC)) {
  81. if (phy_id < MVS_SOC_PORTS)
  82. pci_read_config_dword(mvi->pdev, PCR_PHY_CTL, &reg);
  83. else
  84. pci_read_config_dword(mvi->pdev, PCR_PHY_CTL2, &reg);
  85. } else
  86. reg = mr32(MVS_PHY_CTL);
  87. tmp = reg;
  88. if (phy_id < MVS_SOC_PORTS)
  89. tmp |= (1U << phy_id) << PCTL_LINK_OFFS;
  90. else
  91. tmp |= (1U << (phy_id - MVS_SOC_PORTS)) << PCTL_LINK_OFFS;
  92. if (!(mvi->flags & MVF_FLAG_SOC)) {
  93. if (phy_id < MVS_SOC_PORTS) {
  94. pci_write_config_dword(mvi->pdev, PCR_PHY_CTL, tmp);
  95. mdelay(10);
  96. pci_write_config_dword(mvi->pdev, PCR_PHY_CTL, reg);
  97. } else {
  98. pci_write_config_dword(mvi->pdev, PCR_PHY_CTL2, tmp);
  99. mdelay(10);
  100. pci_write_config_dword(mvi->pdev, PCR_PHY_CTL2, reg);
  101. }
  102. } else {
  103. mw32(MVS_PHY_CTL, tmp);
  104. mdelay(10);
  105. mw32(MVS_PHY_CTL, reg);
  106. }
  107. }
  108. static void mvs_64xx_phy_reset(struct mvs_info *mvi, u32 phy_id, int hard)
  109. {
  110. u32 tmp;
  111. tmp = mvs_read_port_irq_stat(mvi, phy_id);
  112. tmp &= ~PHYEV_RDY_CH;
  113. mvs_write_port_irq_stat(mvi, phy_id, tmp);
  114. tmp = mvs_read_phy_ctl(mvi, phy_id);
  115. if (hard == MVS_HARD_RESET)
  116. tmp |= PHY_RST_HARD;
  117. else if (hard == MVS_SOFT_RESET)
  118. tmp |= PHY_RST;
  119. mvs_write_phy_ctl(mvi, phy_id, tmp);
  120. if (hard) {
  121. do {
  122. tmp = mvs_read_phy_ctl(mvi, phy_id);
  123. } while (tmp & PHY_RST_HARD);
  124. }
  125. }
  126. void mvs_64xx_clear_srs_irq(struct mvs_info *mvi, u8 reg_set, u8 clear_all)
  127. {
  128. void __iomem *regs = mvi->regs;
  129. u32 tmp;
  130. if (clear_all) {
  131. tmp = mr32(MVS_INT_STAT_SRS_0);
  132. if (tmp) {
  133. printk(KERN_DEBUG "check SRS 0 %08X.\n", tmp);
  134. mw32(MVS_INT_STAT_SRS_0, tmp);
  135. }
  136. } else {
  137. tmp = mr32(MVS_INT_STAT_SRS_0);
  138. if (tmp & (1 << (reg_set % 32))) {
  139. printk(KERN_DEBUG "register set 0x%x was stopped.\n",
  140. reg_set);
  141. mw32(MVS_INT_STAT_SRS_0, 1 << (reg_set % 32));
  142. }
  143. }
  144. }
  145. static int __devinit mvs_64xx_chip_reset(struct mvs_info *mvi)
  146. {
  147. void __iomem *regs = mvi->regs;
  148. u32 tmp;
  149. int i;
  150. /* make sure interrupts are masked immediately (paranoia) */
  151. mw32(MVS_GBL_CTL, 0);
  152. tmp = mr32(MVS_GBL_CTL);
  153. /* Reset Controller */
  154. if (!(tmp & HBA_RST)) {
  155. if (mvi->flags & MVF_PHY_PWR_FIX) {
  156. pci_read_config_dword(mvi->pdev, PCR_PHY_CTL, &tmp);
  157. tmp &= ~PCTL_PWR_OFF;
  158. tmp |= PCTL_PHY_DSBL;
  159. pci_write_config_dword(mvi->pdev, PCR_PHY_CTL, tmp);
  160. pci_read_config_dword(mvi->pdev, PCR_PHY_CTL2, &tmp);
  161. tmp &= ~PCTL_PWR_OFF;
  162. tmp |= PCTL_PHY_DSBL;
  163. pci_write_config_dword(mvi->pdev, PCR_PHY_CTL2, tmp);
  164. }
  165. }
  166. /* make sure interrupts are masked immediately (paranoia) */
  167. mw32(MVS_GBL_CTL, 0);
  168. tmp = mr32(MVS_GBL_CTL);
  169. /* Reset Controller */
  170. if (!(tmp & HBA_RST)) {
  171. /* global reset, incl. COMRESET/H_RESET_N (self-clearing) */
  172. mw32_f(MVS_GBL_CTL, HBA_RST);
  173. }
  174. /* wait for reset to finish; timeout is just a guess */
  175. i = 1000;
  176. while (i-- > 0) {
  177. msleep(10);
  178. if (!(mr32(MVS_GBL_CTL) & HBA_RST))
  179. break;
  180. }
  181. if (mr32(MVS_GBL_CTL) & HBA_RST) {
  182. dev_printk(KERN_ERR, mvi->dev, "HBA reset failed\n");
  183. return -EBUSY;
  184. }
  185. return 0;
  186. }
  187. static void mvs_64xx_phy_disable(struct mvs_info *mvi, u32 phy_id)
  188. {
  189. void __iomem *regs = mvi->regs;
  190. u32 tmp;
  191. if (!(mvi->flags & MVF_FLAG_SOC)) {
  192. u32 offs;
  193. if (phy_id < 4)
  194. offs = PCR_PHY_CTL;
  195. else {
  196. offs = PCR_PHY_CTL2;
  197. phy_id -= 4;
  198. }
  199. pci_read_config_dword(mvi->pdev, offs, &tmp);
  200. tmp |= 1U << (PCTL_PHY_DSBL_OFFS + phy_id);
  201. pci_write_config_dword(mvi->pdev, offs, tmp);
  202. } else {
  203. tmp = mr32(MVS_PHY_CTL);
  204. tmp |= 1U << (PCTL_PHY_DSBL_OFFS + phy_id);
  205. mw32(MVS_PHY_CTL, tmp);
  206. }
  207. }
  208. static void mvs_64xx_phy_enable(struct mvs_info *mvi, u32 phy_id)
  209. {
  210. void __iomem *regs = mvi->regs;
  211. u32 tmp;
  212. if (!(mvi->flags & MVF_FLAG_SOC)) {
  213. u32 offs;
  214. if (phy_id < 4)
  215. offs = PCR_PHY_CTL;
  216. else {
  217. offs = PCR_PHY_CTL2;
  218. phy_id -= 4;
  219. }
  220. pci_read_config_dword(mvi->pdev, offs, &tmp);
  221. tmp &= ~(1U << (PCTL_PHY_DSBL_OFFS + phy_id));
  222. pci_write_config_dword(mvi->pdev, offs, tmp);
  223. } else {
  224. tmp = mr32(MVS_PHY_CTL);
  225. tmp &= ~(1U << (PCTL_PHY_DSBL_OFFS + phy_id));
  226. mw32(MVS_PHY_CTL, tmp);
  227. }
  228. }
  229. static int __devinit mvs_64xx_init(struct mvs_info *mvi)
  230. {
  231. void __iomem *regs = mvi->regs;
  232. int i;
  233. u32 tmp, cctl;
  234. if (mvi->pdev && mvi->pdev->revision == 0)
  235. mvi->flags |= MVF_PHY_PWR_FIX;
  236. if (!(mvi->flags & MVF_FLAG_SOC)) {
  237. mvs_show_pcie_usage(mvi);
  238. tmp = mvs_64xx_chip_reset(mvi);
  239. if (tmp)
  240. return tmp;
  241. } else {
  242. tmp = mr32(MVS_PHY_CTL);
  243. tmp &= ~PCTL_PWR_OFF;
  244. tmp |= PCTL_PHY_DSBL;
  245. mw32(MVS_PHY_CTL, tmp);
  246. }
  247. /* Init Chip */
  248. /* make sure RST is set; HBA_RST /should/ have done that for us */
  249. cctl = mr32(MVS_CTL) & 0xFFFF;
  250. if (cctl & CCTL_RST)
  251. cctl &= ~CCTL_RST;
  252. else
  253. mw32_f(MVS_CTL, cctl | CCTL_RST);
  254. if (!(mvi->flags & MVF_FLAG_SOC)) {
  255. /* write to device control _AND_ device status register */
  256. pci_read_config_dword(mvi->pdev, PCR_DEV_CTRL, &tmp);
  257. tmp &= ~PRD_REQ_MASK;
  258. tmp |= PRD_REQ_SIZE;
  259. pci_write_config_dword(mvi->pdev, PCR_DEV_CTRL, tmp);
  260. pci_read_config_dword(mvi->pdev, PCR_PHY_CTL, &tmp);
  261. tmp &= ~PCTL_PWR_OFF;
  262. tmp &= ~PCTL_PHY_DSBL;
  263. pci_write_config_dword(mvi->pdev, PCR_PHY_CTL, tmp);
  264. pci_read_config_dword(mvi->pdev, PCR_PHY_CTL2, &tmp);
  265. tmp &= PCTL_PWR_OFF;
  266. tmp &= ~PCTL_PHY_DSBL;
  267. pci_write_config_dword(mvi->pdev, PCR_PHY_CTL2, tmp);
  268. } else {
  269. tmp = mr32(MVS_PHY_CTL);
  270. tmp &= ~PCTL_PWR_OFF;
  271. tmp |= PCTL_COM_ON;
  272. tmp &= ~PCTL_PHY_DSBL;
  273. tmp |= PCTL_LINK_RST;
  274. mw32(MVS_PHY_CTL, tmp);
  275. msleep(100);
  276. tmp &= ~PCTL_LINK_RST;
  277. mw32(MVS_PHY_CTL, tmp);
  278. msleep(100);
  279. }
  280. /* reset control */
  281. mw32(MVS_PCS, 0); /* MVS_PCS */
  282. /* init phys */
  283. mvs_64xx_phy_hacks(mvi);
  284. tmp = mvs_cr32(mvi, CMD_PHY_MODE_21);
  285. tmp &= 0x0000ffff;
  286. tmp |= 0x00fa0000;
  287. mvs_cw32(mvi, CMD_PHY_MODE_21, tmp);
  288. /* enable auto port detection */
  289. mw32(MVS_GBL_PORT_TYPE, MODE_AUTO_DET_EN);
  290. mw32(MVS_CMD_LIST_LO, mvi->slot_dma);
  291. mw32(MVS_CMD_LIST_HI, (mvi->slot_dma >> 16) >> 16);
  292. mw32(MVS_RX_FIS_LO, mvi->rx_fis_dma);
  293. mw32(MVS_RX_FIS_HI, (mvi->rx_fis_dma >> 16) >> 16);
  294. mw32(MVS_TX_CFG, MVS_CHIP_SLOT_SZ);
  295. mw32(MVS_TX_LO, mvi->tx_dma);
  296. mw32(MVS_TX_HI, (mvi->tx_dma >> 16) >> 16);
  297. mw32(MVS_RX_CFG, MVS_RX_RING_SZ);
  298. mw32(MVS_RX_LO, mvi->rx_dma);
  299. mw32(MVS_RX_HI, (mvi->rx_dma >> 16) >> 16);
  300. for (i = 0; i < mvi->chip->n_phy; i++) {
  301. /* set phy local SAS address */
  302. /* should set little endian SAS address to 64xx chip */
  303. mvs_set_sas_addr(mvi, i, PHYR_ADDR_LO, PHYR_ADDR_HI,
  304. cpu_to_be64(mvi->phy[i].dev_sas_addr));
  305. mvs_64xx_enable_xmt(mvi, i);
  306. mvs_64xx_phy_reset(mvi, i, MVS_HARD_RESET);
  307. msleep(500);
  308. mvs_64xx_detect_porttype(mvi, i);
  309. }
  310. if (mvi->flags & MVF_FLAG_SOC) {
  311. /* set select registers */
  312. writel(0x0E008000, regs + 0x000);
  313. writel(0x59000008, regs + 0x004);
  314. writel(0x20, regs + 0x008);
  315. writel(0x20, regs + 0x00c);
  316. writel(0x20, regs + 0x010);
  317. writel(0x20, regs + 0x014);
  318. writel(0x20, regs + 0x018);
  319. writel(0x20, regs + 0x01c);
  320. }
  321. for (i = 0; i < mvi->chip->n_phy; i++) {
  322. /* clear phy int status */
  323. tmp = mvs_read_port_irq_stat(mvi, i);
  324. tmp &= ~PHYEV_SIG_FIS;
  325. mvs_write_port_irq_stat(mvi, i, tmp);
  326. /* set phy int mask */
  327. tmp = PHYEV_RDY_CH | PHYEV_BROAD_CH | PHYEV_UNASSOC_FIS |
  328. PHYEV_ID_DONE | PHYEV_DCDR_ERR | PHYEV_CRC_ERR |
  329. PHYEV_DEC_ERR;
  330. mvs_write_port_irq_mask(mvi, i, tmp);
  331. msleep(100);
  332. mvs_update_phyinfo(mvi, i, 1);
  333. }
  334. /* FIXME: update wide port bitmaps */
  335. /* little endian for open address and command table, etc. */
  336. /*
  337. * it seems that ( from the spec ) turning on big-endian won't
  338. * do us any good on big-endian machines, need further confirmation
  339. */
  340. cctl = mr32(MVS_CTL);
  341. cctl |= CCTL_ENDIAN_CMD;
  342. cctl |= CCTL_ENDIAN_DATA;
  343. cctl &= ~CCTL_ENDIAN_OPEN;
  344. cctl |= CCTL_ENDIAN_RSP;
  345. mw32_f(MVS_CTL, cctl);
  346. /* reset CMD queue */
  347. tmp = mr32(MVS_PCS);
  348. tmp |= PCS_CMD_RST;
  349. tmp &= ~PCS_SELF_CLEAR;
  350. mw32(MVS_PCS, tmp);
  351. /* interrupt coalescing may cause missing HW interrput in some case,
  352. * and the max count is 0x1ff, while our max slot is 0x200,
  353. * it will make count 0.
  354. */
  355. tmp = 0;
  356. if (MVS_CHIP_SLOT_SZ > 0x1ff)
  357. mw32(MVS_INT_COAL, 0x1ff | COAL_EN);
  358. else
  359. mw32(MVS_INT_COAL, MVS_CHIP_SLOT_SZ | COAL_EN);
  360. tmp = 0x10000 | interrupt_coalescing;
  361. mw32(MVS_INT_COAL_TMOUT, tmp);
  362. /* ladies and gentlemen, start your engines */
  363. mw32(MVS_TX_CFG, 0);
  364. mw32(MVS_TX_CFG, MVS_CHIP_SLOT_SZ | TX_EN);
  365. mw32(MVS_RX_CFG, MVS_RX_RING_SZ | RX_EN);
  366. /* enable CMD/CMPL_Q/RESP mode */
  367. mw32(MVS_PCS, PCS_SATA_RETRY | PCS_FIS_RX_EN |
  368. PCS_CMD_EN | PCS_CMD_STOP_ERR);
  369. /* enable completion queue interrupt */
  370. tmp = (CINT_PORT_MASK | CINT_DONE | CINT_MEM | CINT_SRS | CINT_CI_STOP |
  371. CINT_DMA_PCIE);
  372. mw32(MVS_INT_MASK, tmp);
  373. /* Enable SRS interrupt */
  374. mw32(MVS_INT_MASK_SRS_0, 0xFFFF);
  375. return 0;
  376. }
  377. static int mvs_64xx_ioremap(struct mvs_info *mvi)
  378. {
  379. if (!mvs_ioremap(mvi, 4, 2))
  380. return 0;
  381. return -1;
  382. }
  383. static void mvs_64xx_iounmap(struct mvs_info *mvi)
  384. {
  385. mvs_iounmap(mvi->regs);
  386. mvs_iounmap(mvi->regs_ex);
  387. }
  388. static void mvs_64xx_interrupt_enable(struct mvs_info *mvi)
  389. {
  390. void __iomem *regs = mvi->regs;
  391. u32 tmp;
  392. tmp = mr32(MVS_GBL_CTL);
  393. mw32(MVS_GBL_CTL, tmp | INT_EN);
  394. }
  395. static void mvs_64xx_interrupt_disable(struct mvs_info *mvi)
  396. {
  397. void __iomem *regs = mvi->regs;
  398. u32 tmp;
  399. tmp = mr32(MVS_GBL_CTL);
  400. mw32(MVS_GBL_CTL, tmp & ~INT_EN);
  401. }
  402. static u32 mvs_64xx_isr_status(struct mvs_info *mvi, int irq)
  403. {
  404. void __iomem *regs = mvi->regs;
  405. u32 stat;
  406. if (!(mvi->flags & MVF_FLAG_SOC)) {
  407. stat = mr32(MVS_GBL_INT_STAT);
  408. if (stat == 0 || stat == 0xffffffff)
  409. return 0;
  410. } else
  411. stat = 1;
  412. return stat;
  413. }
  414. static irqreturn_t mvs_64xx_isr(struct mvs_info *mvi, int irq, u32 stat)
  415. {
  416. void __iomem *regs = mvi->regs;
  417. /* clear CMD_CMPLT ASAP */
  418. mw32_f(MVS_INT_STAT, CINT_DONE);
  419. #ifndef MVS_USE_TASKLET
  420. spin_lock(&mvi->lock);
  421. #endif
  422. mvs_int_full(mvi);
  423. #ifndef MVS_USE_TASKLET
  424. spin_unlock(&mvi->lock);
  425. #endif
  426. return IRQ_HANDLED;
  427. }
  428. static void mvs_64xx_command_active(struct mvs_info *mvi, u32 slot_idx)
  429. {
  430. u32 tmp;
  431. mvs_cw32(mvi, 0x40 + (slot_idx >> 3), 1 << (slot_idx % 32));
  432. mvs_cw32(mvi, 0x00 + (slot_idx >> 3), 1 << (slot_idx % 32));
  433. do {
  434. tmp = mvs_cr32(mvi, 0x00 + (slot_idx >> 3));
  435. } while (tmp & 1 << (slot_idx % 32));
  436. do {
  437. tmp = mvs_cr32(mvi, 0x40 + (slot_idx >> 3));
  438. } while (tmp & 1 << (slot_idx % 32));
  439. }
  440. static void mvs_64xx_issue_stop(struct mvs_info *mvi, enum mvs_port_type type,
  441. u32 tfs)
  442. {
  443. void __iomem *regs = mvi->regs;
  444. u32 tmp;
  445. if (type == PORT_TYPE_SATA) {
  446. tmp = mr32(MVS_INT_STAT_SRS_0) | (1U << tfs);
  447. mw32(MVS_INT_STAT_SRS_0, tmp);
  448. }
  449. mw32(MVS_INT_STAT, CINT_CI_STOP);
  450. tmp = mr32(MVS_PCS) | 0xFF00;
  451. mw32(MVS_PCS, tmp);
  452. }
  453. static void mvs_64xx_free_reg_set(struct mvs_info *mvi, u8 *tfs)
  454. {
  455. void __iomem *regs = mvi->regs;
  456. u32 tmp, offs;
  457. if (*tfs == MVS_ID_NOT_MAPPED)
  458. return;
  459. offs = 1U << ((*tfs & 0x0f) + PCS_EN_SATA_REG_SHIFT);
  460. if (*tfs < 16) {
  461. tmp = mr32(MVS_PCS);
  462. mw32(MVS_PCS, tmp & ~offs);
  463. } else {
  464. tmp = mr32(MVS_CTL);
  465. mw32(MVS_CTL, tmp & ~offs);
  466. }
  467. tmp = mr32(MVS_INT_STAT_SRS_0) & (1U << *tfs);
  468. if (tmp)
  469. mw32(MVS_INT_STAT_SRS_0, tmp);
  470. *tfs = MVS_ID_NOT_MAPPED;
  471. return;
  472. }
  473. static u8 mvs_64xx_assign_reg_set(struct mvs_info *mvi, u8 *tfs)
  474. {
  475. int i;
  476. u32 tmp, offs;
  477. void __iomem *regs = mvi->regs;
  478. if (*tfs != MVS_ID_NOT_MAPPED)
  479. return 0;
  480. tmp = mr32(MVS_PCS);
  481. for (i = 0; i < mvi->chip->srs_sz; i++) {
  482. if (i == 16)
  483. tmp = mr32(MVS_CTL);
  484. offs = 1U << ((i & 0x0f) + PCS_EN_SATA_REG_SHIFT);
  485. if (!(tmp & offs)) {
  486. *tfs = i;
  487. if (i < 16)
  488. mw32(MVS_PCS, tmp | offs);
  489. else
  490. mw32(MVS_CTL, tmp | offs);
  491. tmp = mr32(MVS_INT_STAT_SRS_0) & (1U << i);
  492. if (tmp)
  493. mw32(MVS_INT_STAT_SRS_0, tmp);
  494. return 0;
  495. }
  496. }
  497. return MVS_ID_NOT_MAPPED;
  498. }
  499. void mvs_64xx_make_prd(struct scatterlist *scatter, int nr, void *prd)
  500. {
  501. int i;
  502. struct scatterlist *sg;
  503. struct mvs_prd *buf_prd = prd;
  504. for_each_sg(scatter, sg, nr, i) {
  505. buf_prd->addr = cpu_to_le64(sg_dma_address(sg));
  506. buf_prd->len = cpu_to_le32(sg_dma_len(sg));
  507. buf_prd++;
  508. }
  509. }
  510. static int mvs_64xx_oob_done(struct mvs_info *mvi, int i)
  511. {
  512. u32 phy_st;
  513. mvs_write_port_cfg_addr(mvi, i,
  514. PHYR_PHY_STAT);
  515. phy_st = mvs_read_port_cfg_data(mvi, i);
  516. if (phy_st & PHY_OOB_DTCTD)
  517. return 1;
  518. return 0;
  519. }
  520. static void mvs_64xx_fix_phy_info(struct mvs_info *mvi, int i,
  521. struct sas_identify_frame *id)
  522. {
  523. struct mvs_phy *phy = &mvi->phy[i];
  524. struct asd_sas_phy *sas_phy = &phy->sas_phy;
  525. sas_phy->linkrate =
  526. (phy->phy_status & PHY_NEG_SPP_PHYS_LINK_RATE_MASK) >>
  527. PHY_NEG_SPP_PHYS_LINK_RATE_MASK_OFFSET;
  528. phy->minimum_linkrate =
  529. (phy->phy_status &
  530. PHY_MIN_SPP_PHYS_LINK_RATE_MASK) >> 8;
  531. phy->maximum_linkrate =
  532. (phy->phy_status &
  533. PHY_MAX_SPP_PHYS_LINK_RATE_MASK) >> 12;
  534. mvs_write_port_cfg_addr(mvi, i, PHYR_IDENTIFY);
  535. phy->dev_info = mvs_read_port_cfg_data(mvi, i);
  536. mvs_write_port_cfg_addr(mvi, i, PHYR_ATT_DEV_INFO);
  537. phy->att_dev_info = mvs_read_port_cfg_data(mvi, i);
  538. mvs_write_port_cfg_addr(mvi, i, PHYR_ATT_ADDR_HI);
  539. phy->att_dev_sas_addr =
  540. (u64) mvs_read_port_cfg_data(mvi, i) << 32;
  541. mvs_write_port_cfg_addr(mvi, i, PHYR_ATT_ADDR_LO);
  542. phy->att_dev_sas_addr |= mvs_read_port_cfg_data(mvi, i);
  543. phy->att_dev_sas_addr = SAS_ADDR(&phy->att_dev_sas_addr);
  544. }
  545. static void mvs_64xx_phy_work_around(struct mvs_info *mvi, int i)
  546. {
  547. u32 tmp;
  548. struct mvs_phy *phy = &mvi->phy[i];
  549. /* workaround for HW phy decoding error on 1.5g disk drive */
  550. mvs_write_port_vsr_addr(mvi, i, VSR_PHY_MODE6);
  551. tmp = mvs_read_port_vsr_data(mvi, i);
  552. if (((phy->phy_status & PHY_NEG_SPP_PHYS_LINK_RATE_MASK) >>
  553. PHY_NEG_SPP_PHYS_LINK_RATE_MASK_OFFSET) ==
  554. SAS_LINK_RATE_1_5_GBPS)
  555. tmp &= ~PHY_MODE6_LATECLK;
  556. else
  557. tmp |= PHY_MODE6_LATECLK;
  558. mvs_write_port_vsr_data(mvi, i, tmp);
  559. }
  560. void mvs_64xx_phy_set_link_rate(struct mvs_info *mvi, u32 phy_id,
  561. struct sas_phy_linkrates *rates)
  562. {
  563. u32 lrmin = 0, lrmax = 0;
  564. u32 tmp;
  565. tmp = mvs_read_phy_ctl(mvi, phy_id);
  566. lrmin = (rates->minimum_linkrate << 8);
  567. lrmax = (rates->maximum_linkrate << 12);
  568. if (lrmin) {
  569. tmp &= ~(0xf << 8);
  570. tmp |= lrmin;
  571. }
  572. if (lrmax) {
  573. tmp &= ~(0xf << 12);
  574. tmp |= lrmax;
  575. }
  576. mvs_write_phy_ctl(mvi, phy_id, tmp);
  577. mvs_64xx_phy_reset(mvi, phy_id, MVS_HARD_RESET);
  578. }
  579. static void mvs_64xx_clear_active_cmds(struct mvs_info *mvi)
  580. {
  581. u32 tmp;
  582. void __iomem *regs = mvi->regs;
  583. tmp = mr32(MVS_PCS);
  584. mw32(MVS_PCS, tmp & 0xFFFF);
  585. mw32(MVS_PCS, tmp);
  586. tmp = mr32(MVS_CTL);
  587. mw32(MVS_CTL, tmp & 0xFFFF);
  588. mw32(MVS_CTL, tmp);
  589. }
  590. u32 mvs_64xx_spi_read_data(struct mvs_info *mvi)
  591. {
  592. void __iomem *regs = mvi->regs_ex;
  593. return ior32(SPI_DATA_REG_64XX);
  594. }
  595. void mvs_64xx_spi_write_data(struct mvs_info *mvi, u32 data)
  596. {
  597. void __iomem *regs = mvi->regs_ex;
  598. iow32(SPI_DATA_REG_64XX, data);
  599. }
  600. int mvs_64xx_spi_buildcmd(struct mvs_info *mvi,
  601. u32 *dwCmd,
  602. u8 cmd,
  603. u8 read,
  604. u8 length,
  605. u32 addr
  606. )
  607. {
  608. u32 dwTmp;
  609. dwTmp = ((u32)cmd << 24) | ((u32)length << 19);
  610. if (read)
  611. dwTmp |= 1U<<23;
  612. if (addr != MV_MAX_U32) {
  613. dwTmp |= 1U<<22;
  614. dwTmp |= (addr & 0x0003FFFF);
  615. }
  616. *dwCmd = dwTmp;
  617. return 0;
  618. }
  619. int mvs_64xx_spi_issuecmd(struct mvs_info *mvi, u32 cmd)
  620. {
  621. void __iomem *regs = mvi->regs_ex;
  622. int retry;
  623. for (retry = 0; retry < 1; retry++) {
  624. iow32(SPI_CTRL_REG_64XX, SPI_CTRL_VENDOR_ENABLE);
  625. iow32(SPI_CMD_REG_64XX, cmd);
  626. iow32(SPI_CTRL_REG_64XX,
  627. SPI_CTRL_VENDOR_ENABLE | SPI_CTRL_SPISTART);
  628. }
  629. return 0;
  630. }
  631. int mvs_64xx_spi_waitdataready(struct mvs_info *mvi, u32 timeout)
  632. {
  633. void __iomem *regs = mvi->regs_ex;
  634. u32 i, dwTmp;
  635. for (i = 0; i < timeout; i++) {
  636. dwTmp = ior32(SPI_CTRL_REG_64XX);
  637. if (!(dwTmp & SPI_CTRL_SPISTART))
  638. return 0;
  639. msleep(10);
  640. }
  641. return -1;
  642. }
  643. void mvs_64xx_fix_dma(struct mvs_info *mvi, u32 phy_mask,
  644. int buf_len, int from, void *prd)
  645. {
  646. int i;
  647. struct mvs_prd *buf_prd = prd;
  648. dma_addr_t buf_dma = mvi->bulk_buffer_dma;
  649. buf_prd += from;
  650. for (i = 0; i < MAX_SG_ENTRY - from; i++) {
  651. buf_prd->addr = cpu_to_le64(buf_dma);
  652. buf_prd->len = cpu_to_le32(buf_len);
  653. ++buf_prd;
  654. }
  655. }
  656. static void mvs_64xx_tune_interrupt(struct mvs_info *mvi, u32 time)
  657. {
  658. void __iomem *regs = mvi->regs;
  659. u32 tmp = 0;
  660. /* interrupt coalescing may cause missing HW interrput in some case,
  661. * and the max count is 0x1ff, while our max slot is 0x200,
  662. * it will make count 0.
  663. */
  664. if (time == 0) {
  665. mw32(MVS_INT_COAL, 0);
  666. mw32(MVS_INT_COAL_TMOUT, 0x10000);
  667. } else {
  668. if (MVS_CHIP_SLOT_SZ > 0x1ff)
  669. mw32(MVS_INT_COAL, 0x1ff|COAL_EN);
  670. else
  671. mw32(MVS_INT_COAL, MVS_CHIP_SLOT_SZ|COAL_EN);
  672. tmp = 0x10000 | time;
  673. mw32(MVS_INT_COAL_TMOUT, tmp);
  674. }
  675. }
  676. const struct mvs_dispatch mvs_64xx_dispatch = {
  677. "mv64xx",
  678. mvs_64xx_init,
  679. NULL,
  680. mvs_64xx_ioremap,
  681. mvs_64xx_iounmap,
  682. mvs_64xx_isr,
  683. mvs_64xx_isr_status,
  684. mvs_64xx_interrupt_enable,
  685. mvs_64xx_interrupt_disable,
  686. mvs_read_phy_ctl,
  687. mvs_write_phy_ctl,
  688. mvs_read_port_cfg_data,
  689. mvs_write_port_cfg_data,
  690. mvs_write_port_cfg_addr,
  691. mvs_read_port_vsr_data,
  692. mvs_write_port_vsr_data,
  693. mvs_write_port_vsr_addr,
  694. mvs_read_port_irq_stat,
  695. mvs_write_port_irq_stat,
  696. mvs_read_port_irq_mask,
  697. mvs_write_port_irq_mask,
  698. mvs_64xx_command_active,
  699. mvs_64xx_clear_srs_irq,
  700. mvs_64xx_issue_stop,
  701. mvs_start_delivery,
  702. mvs_rx_update,
  703. mvs_int_full,
  704. mvs_64xx_assign_reg_set,
  705. mvs_64xx_free_reg_set,
  706. mvs_get_prd_size,
  707. mvs_get_prd_count,
  708. mvs_64xx_make_prd,
  709. mvs_64xx_detect_porttype,
  710. mvs_64xx_oob_done,
  711. mvs_64xx_fix_phy_info,
  712. mvs_64xx_phy_work_around,
  713. mvs_64xx_phy_set_link_rate,
  714. mvs_hw_max_link_rate,
  715. mvs_64xx_phy_disable,
  716. mvs_64xx_phy_enable,
  717. mvs_64xx_phy_reset,
  718. mvs_64xx_stp_reset,
  719. mvs_64xx_clear_active_cmds,
  720. mvs_64xx_spi_read_data,
  721. mvs_64xx_spi_write_data,
  722. mvs_64xx_spi_buildcmd,
  723. mvs_64xx_spi_issuecmd,
  724. mvs_64xx_spi_waitdataready,
  725. mvs_64xx_fix_dma,
  726. mvs_64xx_tune_interrupt,
  727. NULL,
  728. };