mv_64xx.c 19 KB

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