mv_64xx.c 19 KB

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