mv_94xx.c 17 KB

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