mv_94xx.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. /*
  2. * Marvell 88SE94xx 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_94xx.h"
  26. #include "mv_chips.h"
  27. static void mvs_94xx_detect_porttype(struct mvs_info *mvi, int i)
  28. {
  29. u32 reg;
  30. struct mvs_phy *phy = &mvi->phy[i];
  31. u32 phy_status;
  32. mvs_write_port_vsr_addr(mvi, i, VSR_PHY_MODE3);
  33. reg = mvs_read_port_vsr_data(mvi, i);
  34. phy_status = ((reg & 0x3f0000) >> 16) & 0xff;
  35. phy->phy_type &= ~(PORT_TYPE_SAS | PORT_TYPE_SATA);
  36. switch (phy_status) {
  37. case 0x10:
  38. phy->phy_type |= PORT_TYPE_SAS;
  39. break;
  40. case 0x1d:
  41. default:
  42. phy->phy_type |= PORT_TYPE_SATA;
  43. break;
  44. }
  45. }
  46. static void __devinit mvs_94xx_enable_xmt(struct mvs_info *mvi, int phy_id)
  47. {
  48. void __iomem *regs = mvi->regs;
  49. u32 tmp;
  50. tmp = mr32(MVS_PCS);
  51. tmp |= 1 << (phy_id + PCS_EN_PORT_XMT_SHIFT2);
  52. mw32(MVS_PCS, tmp);
  53. }
  54. static void mvs_94xx_phy_reset(struct mvs_info *mvi, u32 phy_id, int hard)
  55. {
  56. u32 tmp;
  57. tmp = mvs_read_port_irq_stat(mvi, phy_id);
  58. tmp &= ~PHYEV_RDY_CH;
  59. mvs_write_port_irq_stat(mvi, phy_id, tmp);
  60. if (hard) {
  61. tmp = mvs_read_phy_ctl(mvi, phy_id);
  62. tmp |= PHY_RST_HARD;
  63. mvs_write_phy_ctl(mvi, phy_id, tmp);
  64. do {
  65. tmp = mvs_read_phy_ctl(mvi, phy_id);
  66. } while (tmp & PHY_RST_HARD);
  67. } else {
  68. mvs_write_port_vsr_addr(mvi, phy_id, VSR_PHY_STAT);
  69. tmp = mvs_read_port_vsr_data(mvi, phy_id);
  70. tmp |= PHY_RST;
  71. mvs_write_port_vsr_data(mvi, phy_id, tmp);
  72. }
  73. }
  74. static void mvs_94xx_phy_disable(struct mvs_info *mvi, u32 phy_id)
  75. {
  76. u32 tmp;
  77. mvs_write_port_vsr_addr(mvi, phy_id, VSR_PHY_MODE2);
  78. tmp = mvs_read_port_vsr_data(mvi, phy_id);
  79. mvs_write_port_vsr_data(mvi, phy_id, tmp | 0x00800000);
  80. }
  81. static void mvs_94xx_phy_enable(struct mvs_info *mvi, u32 phy_id)
  82. {
  83. mvs_write_port_vsr_addr(mvi, phy_id, 0x1B4);
  84. mvs_write_port_vsr_data(mvi, phy_id, 0x8300ffc1);
  85. mvs_write_port_vsr_addr(mvi, phy_id, 0x104);
  86. mvs_write_port_vsr_data(mvi, phy_id, 0x00018080);
  87. mvs_write_port_vsr_addr(mvi, phy_id, VSR_PHY_MODE2);
  88. mvs_write_port_vsr_data(mvi, phy_id, 0x00207fff);
  89. }
  90. static int __devinit mvs_94xx_init(struct mvs_info *mvi)
  91. {
  92. void __iomem *regs = mvi->regs;
  93. int i;
  94. u32 tmp, cctl;
  95. mvs_show_pcie_usage(mvi);
  96. if (mvi->flags & MVF_FLAG_SOC) {
  97. tmp = mr32(MVS_PHY_CTL);
  98. tmp &= ~PCTL_PWR_OFF;
  99. tmp |= PCTL_PHY_DSBL;
  100. mw32(MVS_PHY_CTL, tmp);
  101. }
  102. /* Init Chip */
  103. /* make sure RST is set; HBA_RST /should/ have done that for us */
  104. cctl = mr32(MVS_CTL) & 0xFFFF;
  105. if (cctl & CCTL_RST)
  106. cctl &= ~CCTL_RST;
  107. else
  108. mw32_f(MVS_CTL, cctl | CCTL_RST);
  109. if (mvi->flags & MVF_FLAG_SOC) {
  110. tmp = mr32(MVS_PHY_CTL);
  111. tmp &= ~PCTL_PWR_OFF;
  112. tmp |= PCTL_COM_ON;
  113. tmp &= ~PCTL_PHY_DSBL;
  114. tmp |= PCTL_LINK_RST;
  115. mw32(MVS_PHY_CTL, tmp);
  116. msleep(100);
  117. tmp &= ~PCTL_LINK_RST;
  118. mw32(MVS_PHY_CTL, tmp);
  119. msleep(100);
  120. }
  121. /* reset control */
  122. mw32(MVS_PCS, 0); /* MVS_PCS */
  123. mw32(MVS_STP_REG_SET_0, 0);
  124. mw32(MVS_STP_REG_SET_1, 0);
  125. /* init phys */
  126. mvs_phy_hacks(mvi);
  127. /* disable Multiplexing, enable phy implemented */
  128. mw32(MVS_PORTS_IMP, 0xFF);
  129. mw32(MVS_PA_VSR_ADDR, 0x00000104);
  130. mw32(MVS_PA_VSR_PORT, 0x00018080);
  131. mw32(MVS_PA_VSR_ADDR, VSR_PHY_MODE8);
  132. mw32(MVS_PA_VSR_PORT, 0x0084ffff);
  133. /* set LED blink when IO*/
  134. mw32(MVS_PA_VSR_ADDR, 0x00000030);
  135. tmp = mr32(MVS_PA_VSR_PORT);
  136. tmp &= 0xFFFF00FF;
  137. tmp |= 0x00003300;
  138. mw32(MVS_PA_VSR_PORT, tmp);
  139. mw32(MVS_CMD_LIST_LO, mvi->slot_dma);
  140. mw32(MVS_CMD_LIST_HI, (mvi->slot_dma >> 16) >> 16);
  141. mw32(MVS_RX_FIS_LO, mvi->rx_fis_dma);
  142. mw32(MVS_RX_FIS_HI, (mvi->rx_fis_dma >> 16) >> 16);
  143. mw32(MVS_TX_CFG, MVS_CHIP_SLOT_SZ);
  144. mw32(MVS_TX_LO, mvi->tx_dma);
  145. mw32(MVS_TX_HI, (mvi->tx_dma >> 16) >> 16);
  146. mw32(MVS_RX_CFG, MVS_RX_RING_SZ);
  147. mw32(MVS_RX_LO, mvi->rx_dma);
  148. mw32(MVS_RX_HI, (mvi->rx_dma >> 16) >> 16);
  149. for (i = 0; i < mvi->chip->n_phy; i++) {
  150. mvs_94xx_phy_disable(mvi, i);
  151. /* set phy local SAS address */
  152. mvs_set_sas_addr(mvi, i, CONFIG_ID_FRAME3, CONFIG_ID_FRAME4,
  153. (mvi->phy[i].dev_sas_addr));
  154. mvs_94xx_enable_xmt(mvi, i);
  155. mvs_94xx_phy_enable(mvi, i);
  156. mvs_94xx_phy_reset(mvi, i, 1);
  157. msleep(500);
  158. mvs_94xx_detect_porttype(mvi, i);
  159. }
  160. if (mvi->flags & MVF_FLAG_SOC) {
  161. /* set select registers */
  162. writel(0x0E008000, regs + 0x000);
  163. writel(0x59000008, regs + 0x004);
  164. writel(0x20, regs + 0x008);
  165. writel(0x20, regs + 0x00c);
  166. writel(0x20, regs + 0x010);
  167. writel(0x20, regs + 0x014);
  168. writel(0x20, regs + 0x018);
  169. writel(0x20, regs + 0x01c);
  170. }
  171. for (i = 0; i < mvi->chip->n_phy; i++) {
  172. /* clear phy int status */
  173. tmp = mvs_read_port_irq_stat(mvi, i);
  174. tmp &= ~PHYEV_SIG_FIS;
  175. mvs_write_port_irq_stat(mvi, i, tmp);
  176. /* set phy int mask */
  177. tmp = PHYEV_RDY_CH | PHYEV_BROAD_CH |
  178. PHYEV_ID_DONE | PHYEV_DCDR_ERR | PHYEV_CRC_ERR ;
  179. mvs_write_port_irq_mask(mvi, i, tmp);
  180. msleep(100);
  181. mvs_update_phyinfo(mvi, i, 1);
  182. }
  183. /* FIXME: update wide port bitmaps */
  184. /* little endian for open address and command table, etc. */
  185. /*
  186. * it seems that ( from the spec ) turning on big-endian won't
  187. * do us any good on big-endian machines, need further confirmation
  188. */
  189. cctl = mr32(MVS_CTL);
  190. cctl |= CCTL_ENDIAN_CMD;
  191. cctl |= CCTL_ENDIAN_DATA;
  192. cctl &= ~CCTL_ENDIAN_OPEN;
  193. cctl |= CCTL_ENDIAN_RSP;
  194. mw32_f(MVS_CTL, cctl);
  195. /* reset CMD queue */
  196. tmp = mr32(MVS_PCS);
  197. tmp |= PCS_CMD_RST;
  198. mw32(MVS_PCS, tmp);
  199. /* interrupt coalescing may cause missing HW interrput in some case,
  200. * and the max count is 0x1ff, while our max slot is 0x200,
  201. * it will make count 0.
  202. */
  203. tmp = 0;
  204. mw32(MVS_INT_COAL, tmp);
  205. tmp = 0x100;
  206. mw32(MVS_INT_COAL_TMOUT, tmp);
  207. /* ladies and gentlemen, start your engines */
  208. mw32(MVS_TX_CFG, 0);
  209. mw32(MVS_TX_CFG, MVS_CHIP_SLOT_SZ | TX_EN);
  210. mw32(MVS_RX_CFG, MVS_RX_RING_SZ | RX_EN);
  211. /* enable CMD/CMPL_Q/RESP mode */
  212. mw32(MVS_PCS, PCS_SATA_RETRY_2 | PCS_FIS_RX_EN |
  213. PCS_CMD_EN | PCS_CMD_STOP_ERR);
  214. /* enable completion queue interrupt */
  215. tmp = (CINT_PORT_MASK | CINT_DONE | CINT_MEM | CINT_SRS | CINT_CI_STOP |
  216. CINT_DMA_PCIE);
  217. tmp |= CINT_PHY_MASK;
  218. mw32(MVS_INT_MASK, tmp);
  219. /* Enable SRS interrupt */
  220. mw32(MVS_INT_MASK_SRS_0, 0xFFFF);
  221. return 0;
  222. }
  223. static int mvs_94xx_ioremap(struct mvs_info *mvi)
  224. {
  225. if (!mvs_ioremap(mvi, 2, -1)) {
  226. mvi->regs_ex = mvi->regs + 0x10200;
  227. mvi->regs += 0x20000;
  228. if (mvi->id == 1)
  229. mvi->regs += 0x4000;
  230. return 0;
  231. }
  232. return -1;
  233. }
  234. static void mvs_94xx_iounmap(struct mvs_info *mvi)
  235. {
  236. if (mvi->regs) {
  237. mvi->regs -= 0x20000;
  238. if (mvi->id == 1)
  239. mvi->regs -= 0x4000;
  240. mvs_iounmap(mvi->regs);
  241. }
  242. }
  243. static void mvs_94xx_interrupt_enable(struct mvs_info *mvi)
  244. {
  245. void __iomem *regs = mvi->regs_ex;
  246. u32 tmp;
  247. tmp = mr32(MVS_GBL_CTL);
  248. tmp |= (IRQ_SAS_A | IRQ_SAS_B);
  249. mw32(MVS_GBL_INT_STAT, tmp);
  250. writel(tmp, regs + 0x0C);
  251. writel(tmp, regs + 0x10);
  252. writel(tmp, regs + 0x14);
  253. writel(tmp, regs + 0x18);
  254. mw32(MVS_GBL_CTL, tmp);
  255. }
  256. static void mvs_94xx_interrupt_disable(struct mvs_info *mvi)
  257. {
  258. void __iomem *regs = mvi->regs_ex;
  259. u32 tmp;
  260. tmp = mr32(MVS_GBL_CTL);
  261. tmp &= ~(IRQ_SAS_A | IRQ_SAS_B);
  262. mw32(MVS_GBL_INT_STAT, tmp);
  263. writel(tmp, regs + 0x0C);
  264. writel(tmp, regs + 0x10);
  265. writel(tmp, regs + 0x14);
  266. writel(tmp, regs + 0x18);
  267. mw32(MVS_GBL_CTL, tmp);
  268. }
  269. static u32 mvs_94xx_isr_status(struct mvs_info *mvi, int irq)
  270. {
  271. void __iomem *regs = mvi->regs_ex;
  272. u32 stat = 0;
  273. if (!(mvi->flags & MVF_FLAG_SOC)) {
  274. stat = mr32(MVS_GBL_INT_STAT);
  275. if (!(stat & (IRQ_SAS_A | IRQ_SAS_B)))
  276. return 0;
  277. }
  278. return stat;
  279. }
  280. static irqreturn_t mvs_94xx_isr(struct mvs_info *mvi, int irq, u32 stat)
  281. {
  282. void __iomem *regs = mvi->regs;
  283. if (((stat & IRQ_SAS_A) && mvi->id == 0) ||
  284. ((stat & IRQ_SAS_B) && mvi->id == 1)) {
  285. mw32_f(MVS_INT_STAT, CINT_DONE);
  286. #ifndef MVS_USE_TASKLET
  287. spin_lock(&mvi->lock);
  288. #endif
  289. mvs_int_full(mvi);
  290. #ifndef MVS_USE_TASKLET
  291. spin_unlock(&mvi->lock);
  292. #endif
  293. }
  294. return IRQ_HANDLED;
  295. }
  296. static void mvs_94xx_command_active(struct mvs_info *mvi, u32 slot_idx)
  297. {
  298. u32 tmp;
  299. mvs_cw32(mvi, 0x300 + (slot_idx >> 3), 1 << (slot_idx % 32));
  300. do {
  301. tmp = mvs_cr32(mvi, 0x300 + (slot_idx >> 3));
  302. } while (tmp & 1 << (slot_idx % 32));
  303. }
  304. static void mvs_94xx_issue_stop(struct mvs_info *mvi, enum mvs_port_type type,
  305. u32 tfs)
  306. {
  307. void __iomem *regs = mvi->regs;
  308. u32 tmp;
  309. if (type == PORT_TYPE_SATA) {
  310. tmp = mr32(MVS_INT_STAT_SRS_0) | (1U << tfs);
  311. mw32(MVS_INT_STAT_SRS_0, tmp);
  312. }
  313. mw32(MVS_INT_STAT, CINT_CI_STOP);
  314. tmp = mr32(MVS_PCS) | 0xFF00;
  315. mw32(MVS_PCS, tmp);
  316. }
  317. static void mvs_94xx_free_reg_set(struct mvs_info *mvi, u8 *tfs)
  318. {
  319. void __iomem *regs = mvi->regs;
  320. u32 tmp;
  321. u8 reg_set = *tfs;
  322. if (*tfs == MVS_ID_NOT_MAPPED)
  323. return;
  324. mvi->sata_reg_set &= ~bit(reg_set);
  325. if (reg_set < 32) {
  326. w_reg_set_enable(reg_set, (u32)mvi->sata_reg_set);
  327. tmp = mr32(MVS_INT_STAT_SRS_0) & (u32)mvi->sata_reg_set;
  328. if (tmp)
  329. mw32(MVS_INT_STAT_SRS_0, tmp);
  330. } else {
  331. w_reg_set_enable(reg_set, mvi->sata_reg_set);
  332. tmp = mr32(MVS_INT_STAT_SRS_1) & mvi->sata_reg_set;
  333. if (tmp)
  334. mw32(MVS_INT_STAT_SRS_1, tmp);
  335. }
  336. *tfs = MVS_ID_NOT_MAPPED;
  337. return;
  338. }
  339. static u8 mvs_94xx_assign_reg_set(struct mvs_info *mvi, u8 *tfs)
  340. {
  341. int i;
  342. void __iomem *regs = mvi->regs;
  343. if (*tfs != MVS_ID_NOT_MAPPED)
  344. return 0;
  345. i = mv_ffc64(mvi->sata_reg_set);
  346. if (i > 32) {
  347. mvi->sata_reg_set |= bit(i);
  348. w_reg_set_enable(i, (u32)(mvi->sata_reg_set >> 32));
  349. *tfs = i;
  350. return 0;
  351. } else if (i >= 0) {
  352. mvi->sata_reg_set |= bit(i);
  353. w_reg_set_enable(i, (u32)mvi->sata_reg_set);
  354. *tfs = i;
  355. return 0;
  356. }
  357. return MVS_ID_NOT_MAPPED;
  358. }
  359. static void mvs_94xx_make_prd(struct scatterlist *scatter, int nr, void *prd)
  360. {
  361. int i;
  362. struct scatterlist *sg;
  363. struct mvs_prd *buf_prd = prd;
  364. for_each_sg(scatter, sg, nr, i) {
  365. buf_prd->addr = cpu_to_le64(sg_dma_address(sg));
  366. buf_prd->im_len.len = cpu_to_le32(sg_dma_len(sg));
  367. buf_prd++;
  368. }
  369. }
  370. static int mvs_94xx_oob_done(struct mvs_info *mvi, int i)
  371. {
  372. u32 phy_st;
  373. phy_st = mvs_read_phy_ctl(mvi, i);
  374. if (phy_st & PHY_READY_MASK) /* phy ready */
  375. return 1;
  376. return 0;
  377. }
  378. static void mvs_94xx_get_dev_identify_frame(struct mvs_info *mvi, int port_id,
  379. struct sas_identify_frame *id)
  380. {
  381. int i;
  382. u32 id_frame[7];
  383. for (i = 0; i < 7; i++) {
  384. mvs_write_port_cfg_addr(mvi, port_id,
  385. CONFIG_ID_FRAME0 + i * 4);
  386. id_frame[i] = mvs_read_port_cfg_data(mvi, port_id);
  387. }
  388. memcpy(id, id_frame, 28);
  389. }
  390. static void mvs_94xx_get_att_identify_frame(struct mvs_info *mvi, int port_id,
  391. struct sas_identify_frame *id)
  392. {
  393. int i;
  394. u32 id_frame[7];
  395. /* mvs_hexdump(28, (u8 *)id_frame, 0); */
  396. for (i = 0; i < 7; i++) {
  397. mvs_write_port_cfg_addr(mvi, port_id,
  398. CONFIG_ATT_ID_FRAME0 + i * 4);
  399. id_frame[i] = mvs_read_port_cfg_data(mvi, port_id);
  400. mv_dprintk("94xx phy %d atta frame %d %x.\n",
  401. port_id + mvi->id * mvi->chip->n_phy, i, id_frame[i]);
  402. }
  403. /* mvs_hexdump(28, (u8 *)id_frame, 0); */
  404. memcpy(id, id_frame, 28);
  405. }
  406. static u32 mvs_94xx_make_dev_info(struct sas_identify_frame *id)
  407. {
  408. u32 att_dev_info = 0;
  409. att_dev_info |= id->dev_type;
  410. if (id->stp_iport)
  411. att_dev_info |= PORT_DEV_STP_INIT;
  412. if (id->smp_iport)
  413. att_dev_info |= PORT_DEV_SMP_INIT;
  414. if (id->ssp_iport)
  415. att_dev_info |= PORT_DEV_SSP_INIT;
  416. if (id->stp_tport)
  417. att_dev_info |= PORT_DEV_STP_TRGT;
  418. if (id->smp_tport)
  419. att_dev_info |= PORT_DEV_SMP_TRGT;
  420. if (id->ssp_tport)
  421. att_dev_info |= PORT_DEV_SSP_TRGT;
  422. att_dev_info |= (u32)id->phy_id<<24;
  423. return att_dev_info;
  424. }
  425. static u32 mvs_94xx_make_att_info(struct sas_identify_frame *id)
  426. {
  427. return mvs_94xx_make_dev_info(id);
  428. }
  429. static void mvs_94xx_fix_phy_info(struct mvs_info *mvi, int i,
  430. struct sas_identify_frame *id)
  431. {
  432. struct mvs_phy *phy = &mvi->phy[i];
  433. struct asd_sas_phy *sas_phy = &phy->sas_phy;
  434. mv_dprintk("get all reg link rate is 0x%x\n", phy->phy_status);
  435. sas_phy->linkrate =
  436. (phy->phy_status & PHY_NEG_SPP_PHYS_LINK_RATE_MASK) >>
  437. PHY_NEG_SPP_PHYS_LINK_RATE_MASK_OFFSET;
  438. sas_phy->linkrate += 0x8;
  439. mv_dprintk("get link rate is %d\n", sas_phy->linkrate);
  440. phy->minimum_linkrate = SAS_LINK_RATE_1_5_GBPS;
  441. phy->maximum_linkrate = SAS_LINK_RATE_6_0_GBPS;
  442. mvs_94xx_get_dev_identify_frame(mvi, i, id);
  443. phy->dev_info = mvs_94xx_make_dev_info(id);
  444. if (phy->phy_type & PORT_TYPE_SAS) {
  445. mvs_94xx_get_att_identify_frame(mvi, i, id);
  446. phy->att_dev_info = mvs_94xx_make_att_info(id);
  447. phy->att_dev_sas_addr = *(u64 *)id->sas_addr;
  448. } else {
  449. phy->att_dev_info = PORT_DEV_STP_TRGT | 1;
  450. }
  451. }
  452. void mvs_94xx_phy_set_link_rate(struct mvs_info *mvi, u32 phy_id,
  453. struct sas_phy_linkrates *rates)
  454. {
  455. /* TODO */
  456. }
  457. static void mvs_94xx_clear_active_cmds(struct mvs_info *mvi)
  458. {
  459. u32 tmp;
  460. void __iomem *regs = mvi->regs;
  461. tmp = mr32(MVS_STP_REG_SET_0);
  462. mw32(MVS_STP_REG_SET_0, 0);
  463. mw32(MVS_STP_REG_SET_0, tmp);
  464. tmp = mr32(MVS_STP_REG_SET_1);
  465. mw32(MVS_STP_REG_SET_1, 0);
  466. mw32(MVS_STP_REG_SET_1, tmp);
  467. }
  468. u32 mvs_94xx_spi_read_data(struct mvs_info *mvi)
  469. {
  470. void __iomem *regs = mvi->regs_ex - 0x10200;
  471. return mr32(SPI_RD_DATA_REG_94XX);
  472. }
  473. void mvs_94xx_spi_write_data(struct mvs_info *mvi, u32 data)
  474. {
  475. void __iomem *regs = mvi->regs_ex - 0x10200;
  476. mw32(SPI_RD_DATA_REG_94XX, data);
  477. }
  478. int mvs_94xx_spi_buildcmd(struct mvs_info *mvi,
  479. u32 *dwCmd,
  480. u8 cmd,
  481. u8 read,
  482. u8 length,
  483. u32 addr
  484. )
  485. {
  486. void __iomem *regs = mvi->regs_ex - 0x10200;
  487. u32 dwTmp;
  488. dwTmp = ((u32)cmd << 8) | ((u32)length << 4);
  489. if (read)
  490. dwTmp |= SPI_CTRL_READ_94XX;
  491. if (addr != MV_MAX_U32) {
  492. mw32(SPI_ADDR_REG_94XX, (addr & 0x0003FFFFL));
  493. dwTmp |= SPI_ADDR_VLD_94XX;
  494. }
  495. *dwCmd = dwTmp;
  496. return 0;
  497. }
  498. int mvs_94xx_spi_issuecmd(struct mvs_info *mvi, u32 cmd)
  499. {
  500. void __iomem *regs = mvi->regs_ex - 0x10200;
  501. mw32(SPI_CTRL_REG_94XX, cmd | SPI_CTRL_SpiStart_94XX);
  502. return 0;
  503. }
  504. int mvs_94xx_spi_waitdataready(struct mvs_info *mvi, u32 timeout)
  505. {
  506. void __iomem *regs = mvi->regs_ex - 0x10200;
  507. u32 i, dwTmp;
  508. for (i = 0; i < timeout; i++) {
  509. dwTmp = mr32(SPI_CTRL_REG_94XX);
  510. if (!(dwTmp & SPI_CTRL_SpiStart_94XX))
  511. return 0;
  512. msleep(10);
  513. }
  514. return -1;
  515. }
  516. #ifndef DISABLE_HOTPLUG_DMA_FIX
  517. void mvs_94xx_fix_dma(dma_addr_t buf_dma, int buf_len, int from, void *prd)
  518. {
  519. int i;
  520. struct mvs_prd *buf_prd = prd;
  521. buf_prd += from;
  522. for (i = 0; i < MAX_SG_ENTRY - from; i++) {
  523. buf_prd->addr = cpu_to_le64(buf_dma);
  524. buf_prd->im_len.len = cpu_to_le32(buf_len);
  525. ++buf_prd;
  526. }
  527. }
  528. #endif
  529. const struct mvs_dispatch mvs_94xx_dispatch = {
  530. "mv94xx",
  531. mvs_94xx_init,
  532. NULL,
  533. mvs_94xx_ioremap,
  534. mvs_94xx_iounmap,
  535. mvs_94xx_isr,
  536. mvs_94xx_isr_status,
  537. mvs_94xx_interrupt_enable,
  538. mvs_94xx_interrupt_disable,
  539. mvs_read_phy_ctl,
  540. mvs_write_phy_ctl,
  541. mvs_read_port_cfg_data,
  542. mvs_write_port_cfg_data,
  543. mvs_write_port_cfg_addr,
  544. mvs_read_port_vsr_data,
  545. mvs_write_port_vsr_data,
  546. mvs_write_port_vsr_addr,
  547. mvs_read_port_irq_stat,
  548. mvs_write_port_irq_stat,
  549. mvs_read_port_irq_mask,
  550. mvs_write_port_irq_mask,
  551. mvs_get_sas_addr,
  552. mvs_94xx_command_active,
  553. mvs_94xx_issue_stop,
  554. mvs_start_delivery,
  555. mvs_rx_update,
  556. mvs_int_full,
  557. mvs_94xx_assign_reg_set,
  558. mvs_94xx_free_reg_set,
  559. mvs_get_prd_size,
  560. mvs_get_prd_count,
  561. mvs_94xx_make_prd,
  562. mvs_94xx_detect_porttype,
  563. mvs_94xx_oob_done,
  564. mvs_94xx_fix_phy_info,
  565. NULL,
  566. mvs_94xx_phy_set_link_rate,
  567. mvs_hw_max_link_rate,
  568. mvs_94xx_phy_disable,
  569. mvs_94xx_phy_enable,
  570. mvs_94xx_phy_reset,
  571. NULL,
  572. mvs_94xx_clear_active_cmds,
  573. mvs_94xx_spi_read_data,
  574. mvs_94xx_spi_write_data,
  575. mvs_94xx_spi_buildcmd,
  576. mvs_94xx_spi_issuecmd,
  577. mvs_94xx_spi_waitdataready,
  578. #ifndef DISABLE_HOTPLUG_DMA_FIX
  579. mvs_94xx_fix_dma,
  580. #endif
  581. };