mv_64xx.c 19 KB

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