mv_64xx.c 18 KB

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