mv_64xx.c 19 KB

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