mv_94xx.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062
  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. void set_phy_tuning(struct mvs_info *mvi, int phy_id,
  48. struct phy_tuning phy_tuning)
  49. {
  50. u32 tmp, setting_0 = 0, setting_1 = 0;
  51. u8 i;
  52. /* Remap information for B0 chip:
  53. *
  54. * R0Ch -> R118h[15:0] (Adapted DFE F3 - F5 coefficient)
  55. * R0Dh -> R118h[31:16] (Generation 1 Setting 0)
  56. * R0Eh -> R11Ch[15:0] (Generation 1 Setting 1)
  57. * R0Fh -> R11Ch[31:16] (Generation 2 Setting 0)
  58. * R10h -> R120h[15:0] (Generation 2 Setting 1)
  59. * R11h -> R120h[31:16] (Generation 3 Setting 0)
  60. * R12h -> R124h[15:0] (Generation 3 Setting 1)
  61. * R13h -> R124h[31:16] (Generation 4 Setting 0 (Reserved))
  62. */
  63. /* A0 has a different set of registers */
  64. if (mvi->pdev->revision == VANIR_A0_REV)
  65. return;
  66. for (i = 0; i < 3; i++) {
  67. /* loop 3 times, set Gen 1, Gen 2, Gen 3 */
  68. switch (i) {
  69. case 0:
  70. setting_0 = GENERATION_1_SETTING;
  71. setting_1 = GENERATION_1_2_SETTING;
  72. break;
  73. case 1:
  74. setting_0 = GENERATION_1_2_SETTING;
  75. setting_1 = GENERATION_2_3_SETTING;
  76. break;
  77. case 2:
  78. setting_0 = GENERATION_2_3_SETTING;
  79. setting_1 = GENERATION_3_4_SETTING;
  80. break;
  81. }
  82. /* Set:
  83. *
  84. * Transmitter Emphasis Enable
  85. * Transmitter Emphasis Amplitude
  86. * Transmitter Amplitude
  87. */
  88. mvs_write_port_vsr_addr(mvi, phy_id, setting_0);
  89. tmp = mvs_read_port_vsr_data(mvi, phy_id);
  90. tmp &= ~(0xFBE << 16);
  91. tmp |= (((phy_tuning.trans_emp_en << 11) |
  92. (phy_tuning.trans_emp_amp << 7) |
  93. (phy_tuning.trans_amp << 1)) << 16);
  94. mvs_write_port_vsr_data(mvi, phy_id, tmp);
  95. /* Set Transmitter Amplitude Adjust */
  96. mvs_write_port_vsr_addr(mvi, phy_id, setting_1);
  97. tmp = mvs_read_port_vsr_data(mvi, phy_id);
  98. tmp &= ~(0xC000);
  99. tmp |= (phy_tuning.trans_amp_adj << 14);
  100. mvs_write_port_vsr_data(mvi, phy_id, tmp);
  101. }
  102. }
  103. void set_phy_ffe_tuning(struct mvs_info *mvi, int phy_id,
  104. struct ffe_control ffe)
  105. {
  106. u32 tmp;
  107. /* Don't run this if A0/B0 */
  108. if ((mvi->pdev->revision == VANIR_A0_REV)
  109. || (mvi->pdev->revision == VANIR_B0_REV))
  110. return;
  111. /* FFE Resistor and Capacitor */
  112. /* R10Ch DFE Resolution Control/Squelch and FFE Setting
  113. *
  114. * FFE_FORCE [7]
  115. * FFE_RES_SEL [6:4]
  116. * FFE_CAP_SEL [3:0]
  117. */
  118. mvs_write_port_vsr_addr(mvi, phy_id, VSR_PHY_FFE_CONTROL);
  119. tmp = mvs_read_port_vsr_data(mvi, phy_id);
  120. tmp &= ~0xFF;
  121. /* Read from HBA_Info_Page */
  122. tmp |= ((0x1 << 7) |
  123. (ffe.ffe_rss_sel << 4) |
  124. (ffe.ffe_cap_sel << 0));
  125. mvs_write_port_vsr_data(mvi, phy_id, tmp);
  126. /* R064h PHY Mode Register 1
  127. *
  128. * DFE_DIS 18
  129. */
  130. mvs_write_port_vsr_addr(mvi, phy_id, VSR_REF_CLOCK_CRTL);
  131. tmp = mvs_read_port_vsr_data(mvi, phy_id);
  132. tmp &= ~0x40001;
  133. /* Hard coding */
  134. /* No defines in HBA_Info_Page */
  135. tmp |= (0 << 18);
  136. mvs_write_port_vsr_data(mvi, phy_id, tmp);
  137. /* R110h DFE F0-F1 Coefficient Control/DFE Update Control
  138. *
  139. * DFE_UPDATE_EN [11:6]
  140. * DFE_FX_FORCE [5:0]
  141. */
  142. mvs_write_port_vsr_addr(mvi, phy_id, VSR_PHY_DFE_UPDATE_CRTL);
  143. tmp = mvs_read_port_vsr_data(mvi, phy_id);
  144. tmp &= ~0xFFF;
  145. /* Hard coding */
  146. /* No defines in HBA_Info_Page */
  147. tmp |= ((0x3F << 6) | (0x0 << 0));
  148. mvs_write_port_vsr_data(mvi, phy_id, tmp);
  149. /* R1A0h Interface and Digital Reference Clock Control/Reserved_50h
  150. *
  151. * FFE_TRAIN_EN 3
  152. */
  153. mvs_write_port_vsr_addr(mvi, phy_id, VSR_REF_CLOCK_CRTL);
  154. tmp = mvs_read_port_vsr_data(mvi, phy_id);
  155. tmp &= ~0x8;
  156. /* Hard coding */
  157. /* No defines in HBA_Info_Page */
  158. tmp |= (0 << 3);
  159. mvs_write_port_vsr_data(mvi, phy_id, tmp);
  160. }
  161. /*Notice: this function must be called when phy is disabled*/
  162. void set_phy_rate(struct mvs_info *mvi, int phy_id, u8 rate)
  163. {
  164. union reg_phy_cfg phy_cfg, phy_cfg_tmp;
  165. mvs_write_port_vsr_addr(mvi, phy_id, VSR_PHY_MODE2);
  166. phy_cfg_tmp.v = mvs_read_port_vsr_data(mvi, phy_id);
  167. phy_cfg.v = 0;
  168. phy_cfg.u.disable_phy = phy_cfg_tmp.u.disable_phy;
  169. phy_cfg.u.sas_support = 1;
  170. phy_cfg.u.sata_support = 1;
  171. phy_cfg.u.sata_host_mode = 1;
  172. switch (rate) {
  173. case 0x0:
  174. /* support 1.5 Gbps */
  175. phy_cfg.u.speed_support = 1;
  176. phy_cfg.u.snw_3_support = 0;
  177. phy_cfg.u.tx_lnk_parity = 1;
  178. phy_cfg.u.tx_spt_phs_lnk_rate = 0x30;
  179. break;
  180. case 0x1:
  181. /* support 1.5, 3.0 Gbps */
  182. phy_cfg.u.speed_support = 3;
  183. phy_cfg.u.tx_spt_phs_lnk_rate = 0x3c;
  184. phy_cfg.u.tx_lgcl_lnk_rate = 0x08;
  185. break;
  186. case 0x2:
  187. default:
  188. /* support 1.5, 3.0, 6.0 Gbps */
  189. phy_cfg.u.speed_support = 7;
  190. phy_cfg.u.snw_3_support = 1;
  191. phy_cfg.u.tx_lnk_parity = 1;
  192. phy_cfg.u.tx_spt_phs_lnk_rate = 0x3f;
  193. phy_cfg.u.tx_lgcl_lnk_rate = 0x09;
  194. break;
  195. }
  196. mvs_write_port_vsr_data(mvi, phy_id, phy_cfg.v);
  197. }
  198. static void mvs_94xx_config_reg_from_hba(struct mvs_info *mvi, int phy_id)
  199. {
  200. u32 temp;
  201. temp = (u32)(*(u32 *)&mvi->hba_info_param.phy_tuning[phy_id]);
  202. if (temp == 0xFFFFFFFFL) {
  203. mvi->hba_info_param.phy_tuning[phy_id].trans_emp_amp = 0x6;
  204. mvi->hba_info_param.phy_tuning[phy_id].trans_amp = 0x1A;
  205. mvi->hba_info_param.phy_tuning[phy_id].trans_amp_adj = 0x3;
  206. }
  207. temp = (u8)(*(u8 *)&mvi->hba_info_param.ffe_ctl[phy_id]);
  208. if (temp == 0xFFL) {
  209. switch (mvi->pdev->revision) {
  210. case VANIR_A0_REV:
  211. case VANIR_B0_REV:
  212. mvi->hba_info_param.ffe_ctl[phy_id].ffe_rss_sel = 0x7;
  213. mvi->hba_info_param.ffe_ctl[phy_id].ffe_cap_sel = 0x7;
  214. break;
  215. case VANIR_C0_REV:
  216. case VANIR_C1_REV:
  217. case VANIR_C2_REV:
  218. default:
  219. mvi->hba_info_param.ffe_ctl[phy_id].ffe_rss_sel = 0x7;
  220. mvi->hba_info_param.ffe_ctl[phy_id].ffe_cap_sel = 0xC;
  221. break;
  222. }
  223. }
  224. temp = (u8)(*(u8 *)&mvi->hba_info_param.phy_rate[phy_id]);
  225. if (temp == 0xFFL)
  226. /*set default phy_rate = 6Gbps*/
  227. mvi->hba_info_param.phy_rate[phy_id] = 0x2;
  228. set_phy_tuning(mvi, phy_id,
  229. mvi->hba_info_param.phy_tuning[phy_id]);
  230. set_phy_ffe_tuning(mvi, phy_id,
  231. mvi->hba_info_param.ffe_ctl[phy_id]);
  232. set_phy_rate(mvi, phy_id,
  233. mvi->hba_info_param.phy_rate[phy_id]);
  234. }
  235. static void mvs_94xx_enable_xmt(struct mvs_info *mvi, int phy_id)
  236. {
  237. void __iomem *regs = mvi->regs;
  238. u32 tmp;
  239. tmp = mr32(MVS_PCS);
  240. tmp |= 1 << (phy_id + PCS_EN_PORT_XMT_SHIFT2);
  241. mw32(MVS_PCS, tmp);
  242. }
  243. static void mvs_94xx_phy_reset(struct mvs_info *mvi, u32 phy_id, int hard)
  244. {
  245. u32 tmp;
  246. u32 delay = 5000;
  247. if (hard == MVS_PHY_TUNE) {
  248. mvs_write_port_cfg_addr(mvi, phy_id, PHYR_SATA_CTL);
  249. tmp = mvs_read_port_cfg_data(mvi, phy_id);
  250. mvs_write_port_cfg_data(mvi, phy_id, tmp|0x20000000);
  251. mvs_write_port_cfg_data(mvi, phy_id, tmp|0x100000);
  252. return;
  253. }
  254. tmp = mvs_read_port_irq_stat(mvi, phy_id);
  255. tmp &= ~PHYEV_RDY_CH;
  256. mvs_write_port_irq_stat(mvi, phy_id, tmp);
  257. if (hard) {
  258. tmp = mvs_read_phy_ctl(mvi, phy_id);
  259. tmp |= PHY_RST_HARD;
  260. mvs_write_phy_ctl(mvi, phy_id, tmp);
  261. do {
  262. tmp = mvs_read_phy_ctl(mvi, phy_id);
  263. udelay(10);
  264. delay--;
  265. } while ((tmp & PHY_RST_HARD) && delay);
  266. if (!delay)
  267. mv_dprintk("phy hard reset failed.\n");
  268. } else {
  269. tmp = mvs_read_phy_ctl(mvi, phy_id);
  270. tmp |= PHY_RST;
  271. mvs_write_phy_ctl(mvi, phy_id, tmp);
  272. }
  273. }
  274. static void mvs_94xx_phy_disable(struct mvs_info *mvi, u32 phy_id)
  275. {
  276. u32 tmp;
  277. mvs_write_port_vsr_addr(mvi, phy_id, VSR_PHY_MODE2);
  278. tmp = mvs_read_port_vsr_data(mvi, phy_id);
  279. mvs_write_port_vsr_data(mvi, phy_id, tmp | 0x00800000);
  280. }
  281. static void mvs_94xx_phy_enable(struct mvs_info *mvi, u32 phy_id)
  282. {
  283. u32 tmp;
  284. u8 revision = 0;
  285. revision = mvi->pdev->revision;
  286. if (revision == VANIR_A0_REV) {
  287. mvs_write_port_vsr_addr(mvi, phy_id, CMD_HOST_RD_DATA);
  288. mvs_write_port_vsr_data(mvi, phy_id, 0x8300ffc1);
  289. }
  290. if (revision == VANIR_B0_REV) {
  291. mvs_write_port_vsr_addr(mvi, phy_id, CMD_APP_MEM_CTL);
  292. mvs_write_port_vsr_data(mvi, phy_id, 0x08001006);
  293. mvs_write_port_vsr_addr(mvi, phy_id, CMD_HOST_RD_DATA);
  294. mvs_write_port_vsr_data(mvi, phy_id, 0x0000705f);
  295. }
  296. mvs_write_port_vsr_addr(mvi, phy_id, VSR_PHY_MODE2);
  297. tmp = mvs_read_port_vsr_data(mvi, phy_id);
  298. tmp |= bit(0);
  299. mvs_write_port_vsr_data(mvi, phy_id, tmp & 0xfd7fffff);
  300. }
  301. static int mvs_94xx_init(struct mvs_info *mvi)
  302. {
  303. void __iomem *regs = mvi->regs;
  304. int i;
  305. u32 tmp, cctl;
  306. u8 revision;
  307. revision = mvi->pdev->revision;
  308. mvs_show_pcie_usage(mvi);
  309. if (mvi->flags & MVF_FLAG_SOC) {
  310. tmp = mr32(MVS_PHY_CTL);
  311. tmp &= ~PCTL_PWR_OFF;
  312. tmp |= PCTL_PHY_DSBL;
  313. mw32(MVS_PHY_CTL, tmp);
  314. }
  315. /* Init Chip */
  316. /* make sure RST is set; HBA_RST /should/ have done that for us */
  317. cctl = mr32(MVS_CTL) & 0xFFFF;
  318. if (cctl & CCTL_RST)
  319. cctl &= ~CCTL_RST;
  320. else
  321. mw32_f(MVS_CTL, cctl | CCTL_RST);
  322. if (mvi->flags & MVF_FLAG_SOC) {
  323. tmp = mr32(MVS_PHY_CTL);
  324. tmp &= ~PCTL_PWR_OFF;
  325. tmp |= PCTL_COM_ON;
  326. tmp &= ~PCTL_PHY_DSBL;
  327. tmp |= PCTL_LINK_RST;
  328. mw32(MVS_PHY_CTL, tmp);
  329. msleep(100);
  330. tmp &= ~PCTL_LINK_RST;
  331. mw32(MVS_PHY_CTL, tmp);
  332. msleep(100);
  333. }
  334. /* disable Multiplexing, enable phy implemented */
  335. mw32(MVS_PORTS_IMP, 0xFF);
  336. if (revision == VANIR_A0_REV) {
  337. mw32(MVS_PA_VSR_ADDR, CMD_CMWK_OOB_DET);
  338. mw32(MVS_PA_VSR_PORT, 0x00018080);
  339. }
  340. mw32(MVS_PA_VSR_ADDR, VSR_PHY_MODE2);
  341. if (revision == VANIR_A0_REV || revision == VANIR_B0_REV)
  342. /* set 6G/3G/1.5G, multiplexing, without SSC */
  343. mw32(MVS_PA_VSR_PORT, 0x0084d4fe);
  344. else
  345. /* set 6G/3G/1.5G, multiplexing, with and without SSC */
  346. mw32(MVS_PA_VSR_PORT, 0x0084fffe);
  347. if (revision == VANIR_B0_REV) {
  348. mw32(MVS_PA_VSR_ADDR, CMD_APP_MEM_CTL);
  349. mw32(MVS_PA_VSR_PORT, 0x08001006);
  350. mw32(MVS_PA_VSR_ADDR, CMD_HOST_RD_DATA);
  351. mw32(MVS_PA_VSR_PORT, 0x0000705f);
  352. }
  353. /* reset control */
  354. mw32(MVS_PCS, 0); /* MVS_PCS */
  355. mw32(MVS_STP_REG_SET_0, 0);
  356. mw32(MVS_STP_REG_SET_1, 0);
  357. /* init phys */
  358. mvs_phy_hacks(mvi);
  359. /* disable non data frame retry */
  360. tmp = mvs_cr32(mvi, CMD_SAS_CTL1);
  361. if ((revision == VANIR_A0_REV) ||
  362. (revision == VANIR_B0_REV) ||
  363. (revision == VANIR_C0_REV)) {
  364. tmp &= ~0xffff;
  365. tmp |= 0x007f;
  366. mvs_cw32(mvi, CMD_SAS_CTL1, tmp);
  367. }
  368. /* set LED blink when IO*/
  369. mw32(MVS_PA_VSR_ADDR, VSR_PHY_ACT_LED);
  370. tmp = mr32(MVS_PA_VSR_PORT);
  371. tmp &= 0xFFFF00FF;
  372. tmp |= 0x00003300;
  373. mw32(MVS_PA_VSR_PORT, tmp);
  374. mw32(MVS_CMD_LIST_LO, mvi->slot_dma);
  375. mw32(MVS_CMD_LIST_HI, (mvi->slot_dma >> 16) >> 16);
  376. mw32(MVS_RX_FIS_LO, mvi->rx_fis_dma);
  377. mw32(MVS_RX_FIS_HI, (mvi->rx_fis_dma >> 16) >> 16);
  378. mw32(MVS_TX_CFG, MVS_CHIP_SLOT_SZ);
  379. mw32(MVS_TX_LO, mvi->tx_dma);
  380. mw32(MVS_TX_HI, (mvi->tx_dma >> 16) >> 16);
  381. mw32(MVS_RX_CFG, MVS_RX_RING_SZ);
  382. mw32(MVS_RX_LO, mvi->rx_dma);
  383. mw32(MVS_RX_HI, (mvi->rx_dma >> 16) >> 16);
  384. for (i = 0; i < mvi->chip->n_phy; i++) {
  385. mvs_94xx_phy_disable(mvi, i);
  386. /* set phy local SAS address */
  387. mvs_set_sas_addr(mvi, i, CONFIG_ID_FRAME3, CONFIG_ID_FRAME4,
  388. cpu_to_le64(mvi->phy[i].dev_sas_addr));
  389. mvs_94xx_enable_xmt(mvi, i);
  390. mvs_94xx_config_reg_from_hba(mvi, i);
  391. mvs_94xx_phy_enable(mvi, i);
  392. mvs_94xx_phy_reset(mvi, i, PHY_RST_HARD);
  393. msleep(500);
  394. mvs_94xx_detect_porttype(mvi, i);
  395. }
  396. if (mvi->flags & MVF_FLAG_SOC) {
  397. /* set select registers */
  398. writel(0x0E008000, regs + 0x000);
  399. writel(0x59000008, regs + 0x004);
  400. writel(0x20, regs + 0x008);
  401. writel(0x20, regs + 0x00c);
  402. writel(0x20, regs + 0x010);
  403. writel(0x20, regs + 0x014);
  404. writel(0x20, regs + 0x018);
  405. writel(0x20, regs + 0x01c);
  406. }
  407. for (i = 0; i < mvi->chip->n_phy; i++) {
  408. /* clear phy int status */
  409. tmp = mvs_read_port_irq_stat(mvi, i);
  410. tmp &= ~PHYEV_SIG_FIS;
  411. mvs_write_port_irq_stat(mvi, i, tmp);
  412. /* set phy int mask */
  413. tmp = PHYEV_RDY_CH | PHYEV_BROAD_CH |
  414. PHYEV_ID_DONE | PHYEV_DCDR_ERR | PHYEV_CRC_ERR ;
  415. mvs_write_port_irq_mask(mvi, i, tmp);
  416. msleep(100);
  417. mvs_update_phyinfo(mvi, i, 1);
  418. }
  419. /* little endian for open address and command table, etc. */
  420. cctl = mr32(MVS_CTL);
  421. cctl |= CCTL_ENDIAN_CMD;
  422. cctl &= ~CCTL_ENDIAN_OPEN;
  423. cctl |= CCTL_ENDIAN_RSP;
  424. mw32_f(MVS_CTL, cctl);
  425. /* reset CMD queue */
  426. tmp = mr32(MVS_PCS);
  427. tmp |= PCS_CMD_RST;
  428. tmp &= ~PCS_SELF_CLEAR;
  429. mw32(MVS_PCS, tmp);
  430. /*
  431. * the max count is 0x1ff, while our max slot is 0x200,
  432. * it will make count 0.
  433. */
  434. tmp = 0;
  435. if (MVS_CHIP_SLOT_SZ > 0x1ff)
  436. mw32(MVS_INT_COAL, 0x1ff | COAL_EN);
  437. else
  438. mw32(MVS_INT_COAL, MVS_CHIP_SLOT_SZ | COAL_EN);
  439. /* default interrupt coalescing time is 128us */
  440. tmp = 0x10000 | interrupt_coalescing;
  441. mw32(MVS_INT_COAL_TMOUT, tmp);
  442. /* ladies and gentlemen, start your engines */
  443. mw32(MVS_TX_CFG, 0);
  444. mw32(MVS_TX_CFG, MVS_CHIP_SLOT_SZ | TX_EN);
  445. mw32(MVS_RX_CFG, MVS_RX_RING_SZ | RX_EN);
  446. /* enable CMD/CMPL_Q/RESP mode */
  447. mw32(MVS_PCS, PCS_SATA_RETRY_2 | PCS_FIS_RX_EN |
  448. PCS_CMD_EN | PCS_CMD_STOP_ERR);
  449. /* enable completion queue interrupt */
  450. tmp = (CINT_PORT_MASK | CINT_DONE | CINT_MEM | CINT_SRS | CINT_CI_STOP |
  451. CINT_DMA_PCIE | CINT_NON_SPEC_NCQ_ERROR);
  452. tmp |= CINT_PHY_MASK;
  453. mw32(MVS_INT_MASK, tmp);
  454. tmp = mvs_cr32(mvi, CMD_LINK_TIMER);
  455. tmp |= 0xFFFF0000;
  456. mvs_cw32(mvi, CMD_LINK_TIMER, tmp);
  457. /* tune STP performance */
  458. tmp = 0x003F003F;
  459. mvs_cw32(mvi, CMD_PL_TIMER, tmp);
  460. /* This can improve expander large block size seq write performance */
  461. tmp = mvs_cr32(mvi, CMD_PORT_LAYER_TIMER1);
  462. tmp |= 0xFFFF007F;
  463. mvs_cw32(mvi, CMD_PORT_LAYER_TIMER1, tmp);
  464. /* change the connection open-close behavior (bit 9)
  465. * set bit8 to 1 for performance tuning */
  466. tmp = mvs_cr32(mvi, CMD_SL_MODE0);
  467. tmp |= 0x00000300;
  468. /* set bit0 to 0 to enable retry for no_dest reject case */
  469. tmp &= 0xFFFFFFFE;
  470. mvs_cw32(mvi, CMD_SL_MODE0, tmp);
  471. /* Enable SRS interrupt */
  472. mw32(MVS_INT_MASK_SRS_0, 0xFFFF);
  473. return 0;
  474. }
  475. static int mvs_94xx_ioremap(struct mvs_info *mvi)
  476. {
  477. if (!mvs_ioremap(mvi, 2, -1)) {
  478. mvi->regs_ex = mvi->regs + 0x10200;
  479. mvi->regs += 0x20000;
  480. if (mvi->id == 1)
  481. mvi->regs += 0x4000;
  482. return 0;
  483. }
  484. return -1;
  485. }
  486. static void mvs_94xx_iounmap(struct mvs_info *mvi)
  487. {
  488. if (mvi->regs) {
  489. mvi->regs -= 0x20000;
  490. if (mvi->id == 1)
  491. mvi->regs -= 0x4000;
  492. mvs_iounmap(mvi->regs);
  493. }
  494. }
  495. static void mvs_94xx_interrupt_enable(struct mvs_info *mvi)
  496. {
  497. void __iomem *regs = mvi->regs_ex;
  498. u32 tmp;
  499. tmp = mr32(MVS_GBL_CTL);
  500. tmp |= (MVS_IRQ_SAS_A | MVS_IRQ_SAS_B);
  501. mw32(MVS_GBL_INT_STAT, tmp);
  502. writel(tmp, regs + 0x0C);
  503. writel(tmp, regs + 0x10);
  504. writel(tmp, regs + 0x14);
  505. writel(tmp, regs + 0x18);
  506. mw32(MVS_GBL_CTL, tmp);
  507. }
  508. static void mvs_94xx_interrupt_disable(struct mvs_info *mvi)
  509. {
  510. void __iomem *regs = mvi->regs_ex;
  511. u32 tmp;
  512. tmp = mr32(MVS_GBL_CTL);
  513. tmp &= ~(MVS_IRQ_SAS_A | MVS_IRQ_SAS_B);
  514. mw32(MVS_GBL_INT_STAT, tmp);
  515. writel(tmp, regs + 0x0C);
  516. writel(tmp, regs + 0x10);
  517. writel(tmp, regs + 0x14);
  518. writel(tmp, regs + 0x18);
  519. mw32(MVS_GBL_CTL, tmp);
  520. }
  521. static u32 mvs_94xx_isr_status(struct mvs_info *mvi, int irq)
  522. {
  523. void __iomem *regs = mvi->regs_ex;
  524. u32 stat = 0;
  525. if (!(mvi->flags & MVF_FLAG_SOC)) {
  526. stat = mr32(MVS_GBL_INT_STAT);
  527. if (!(stat & (MVS_IRQ_SAS_A | MVS_IRQ_SAS_B)))
  528. return 0;
  529. }
  530. return stat;
  531. }
  532. static irqreturn_t mvs_94xx_isr(struct mvs_info *mvi, int irq, u32 stat)
  533. {
  534. void __iomem *regs = mvi->regs;
  535. if (((stat & MVS_IRQ_SAS_A) && mvi->id == 0) ||
  536. ((stat & MVS_IRQ_SAS_B) && mvi->id == 1)) {
  537. mw32_f(MVS_INT_STAT, CINT_DONE);
  538. spin_lock(&mvi->lock);
  539. mvs_int_full(mvi);
  540. spin_unlock(&mvi->lock);
  541. }
  542. return IRQ_HANDLED;
  543. }
  544. static void mvs_94xx_command_active(struct mvs_info *mvi, u32 slot_idx)
  545. {
  546. u32 tmp;
  547. tmp = mvs_cr32(mvi, MVS_COMMAND_ACTIVE+(slot_idx >> 3));
  548. if (tmp && 1 << (slot_idx % 32)) {
  549. mv_printk("command active %08X, slot [%x].\n", tmp, slot_idx);
  550. mvs_cw32(mvi, MVS_COMMAND_ACTIVE + (slot_idx >> 3),
  551. 1 << (slot_idx % 32));
  552. do {
  553. tmp = mvs_cr32(mvi,
  554. MVS_COMMAND_ACTIVE + (slot_idx >> 3));
  555. } while (tmp & 1 << (slot_idx % 32));
  556. }
  557. }
  558. void mvs_94xx_clear_srs_irq(struct mvs_info *mvi, u8 reg_set, u8 clear_all)
  559. {
  560. void __iomem *regs = mvi->regs;
  561. u32 tmp;
  562. if (clear_all) {
  563. tmp = mr32(MVS_INT_STAT_SRS_0);
  564. if (tmp) {
  565. mv_dprintk("check SRS 0 %08X.\n", tmp);
  566. mw32(MVS_INT_STAT_SRS_0, tmp);
  567. }
  568. tmp = mr32(MVS_INT_STAT_SRS_1);
  569. if (tmp) {
  570. mv_dprintk("check SRS 1 %08X.\n", tmp);
  571. mw32(MVS_INT_STAT_SRS_1, tmp);
  572. }
  573. } else {
  574. if (reg_set > 31)
  575. tmp = mr32(MVS_INT_STAT_SRS_1);
  576. else
  577. tmp = mr32(MVS_INT_STAT_SRS_0);
  578. if (tmp & (1 << (reg_set % 32))) {
  579. mv_dprintk("register set 0x%x was stopped.\n", reg_set);
  580. if (reg_set > 31)
  581. mw32(MVS_INT_STAT_SRS_1, 1 << (reg_set % 32));
  582. else
  583. mw32(MVS_INT_STAT_SRS_0, 1 << (reg_set % 32));
  584. }
  585. }
  586. }
  587. static void mvs_94xx_issue_stop(struct mvs_info *mvi, enum mvs_port_type type,
  588. u32 tfs)
  589. {
  590. void __iomem *regs = mvi->regs;
  591. u32 tmp;
  592. mvs_94xx_clear_srs_irq(mvi, 0, 1);
  593. tmp = mr32(MVS_INT_STAT);
  594. mw32(MVS_INT_STAT, tmp | CINT_CI_STOP);
  595. tmp = mr32(MVS_PCS) | 0xFF00;
  596. mw32(MVS_PCS, tmp);
  597. }
  598. static void mvs_94xx_non_spec_ncq_error(struct mvs_info *mvi)
  599. {
  600. void __iomem *regs = mvi->regs;
  601. u32 err_0, err_1;
  602. u8 i;
  603. struct mvs_device *device;
  604. err_0 = mr32(MVS_NON_NCQ_ERR_0);
  605. err_1 = mr32(MVS_NON_NCQ_ERR_1);
  606. mv_dprintk("non specific ncq error err_0:%x,err_1:%x.\n",
  607. err_0, err_1);
  608. for (i = 0; i < 32; i++) {
  609. if (err_0 & bit(i)) {
  610. device = mvs_find_dev_by_reg_set(mvi, i);
  611. if (device)
  612. mvs_release_task(mvi, device->sas_device);
  613. }
  614. if (err_1 & bit(i)) {
  615. device = mvs_find_dev_by_reg_set(mvi, i+32);
  616. if (device)
  617. mvs_release_task(mvi, device->sas_device);
  618. }
  619. }
  620. mw32(MVS_NON_NCQ_ERR_0, err_0);
  621. mw32(MVS_NON_NCQ_ERR_1, err_1);
  622. }
  623. static void mvs_94xx_free_reg_set(struct mvs_info *mvi, u8 *tfs)
  624. {
  625. void __iomem *regs = mvi->regs;
  626. u8 reg_set = *tfs;
  627. if (*tfs == MVS_ID_NOT_MAPPED)
  628. return;
  629. mvi->sata_reg_set &= ~bit(reg_set);
  630. if (reg_set < 32)
  631. w_reg_set_enable(reg_set, (u32)mvi->sata_reg_set);
  632. else
  633. w_reg_set_enable(reg_set, (u32)(mvi->sata_reg_set >> 32));
  634. *tfs = MVS_ID_NOT_MAPPED;
  635. return;
  636. }
  637. static u8 mvs_94xx_assign_reg_set(struct mvs_info *mvi, u8 *tfs)
  638. {
  639. int i;
  640. void __iomem *regs = mvi->regs;
  641. if (*tfs != MVS_ID_NOT_MAPPED)
  642. return 0;
  643. i = mv_ffc64(mvi->sata_reg_set);
  644. if (i >= 32) {
  645. mvi->sata_reg_set |= bit(i);
  646. w_reg_set_enable(i, (u32)(mvi->sata_reg_set >> 32));
  647. *tfs = i;
  648. return 0;
  649. } else if (i >= 0) {
  650. mvi->sata_reg_set |= bit(i);
  651. w_reg_set_enable(i, (u32)mvi->sata_reg_set);
  652. *tfs = i;
  653. return 0;
  654. }
  655. return MVS_ID_NOT_MAPPED;
  656. }
  657. static void mvs_94xx_make_prd(struct scatterlist *scatter, int nr, void *prd)
  658. {
  659. int i;
  660. struct scatterlist *sg;
  661. struct mvs_prd *buf_prd = prd;
  662. struct mvs_prd_imt im_len;
  663. *(u32 *)&im_len = 0;
  664. for_each_sg(scatter, sg, nr, i) {
  665. buf_prd->addr = cpu_to_le64(sg_dma_address(sg));
  666. im_len.len = sg_dma_len(sg);
  667. buf_prd->im_len = cpu_to_le32(*(u32 *)&im_len);
  668. buf_prd++;
  669. }
  670. }
  671. static int mvs_94xx_oob_done(struct mvs_info *mvi, int i)
  672. {
  673. u32 phy_st;
  674. phy_st = mvs_read_phy_ctl(mvi, i);
  675. if (phy_st & PHY_READY_MASK)
  676. return 1;
  677. return 0;
  678. }
  679. static void mvs_94xx_get_dev_identify_frame(struct mvs_info *mvi, int port_id,
  680. struct sas_identify_frame *id)
  681. {
  682. int i;
  683. u32 id_frame[7];
  684. for (i = 0; i < 7; i++) {
  685. mvs_write_port_cfg_addr(mvi, port_id,
  686. CONFIG_ID_FRAME0 + i * 4);
  687. id_frame[i] = cpu_to_le32(mvs_read_port_cfg_data(mvi, port_id));
  688. }
  689. memcpy(id, id_frame, 28);
  690. }
  691. static void mvs_94xx_get_att_identify_frame(struct mvs_info *mvi, int port_id,
  692. struct sas_identify_frame *id)
  693. {
  694. int i;
  695. u32 id_frame[7];
  696. for (i = 0; i < 7; i++) {
  697. mvs_write_port_cfg_addr(mvi, port_id,
  698. CONFIG_ATT_ID_FRAME0 + i * 4);
  699. id_frame[i] = cpu_to_le32(mvs_read_port_cfg_data(mvi, port_id));
  700. mv_dprintk("94xx phy %d atta frame %d %x.\n",
  701. port_id + mvi->id * mvi->chip->n_phy, i, id_frame[i]);
  702. }
  703. memcpy(id, id_frame, 28);
  704. }
  705. static u32 mvs_94xx_make_dev_info(struct sas_identify_frame *id)
  706. {
  707. u32 att_dev_info = 0;
  708. att_dev_info |= id->dev_type;
  709. if (id->stp_iport)
  710. att_dev_info |= PORT_DEV_STP_INIT;
  711. if (id->smp_iport)
  712. att_dev_info |= PORT_DEV_SMP_INIT;
  713. if (id->ssp_iport)
  714. att_dev_info |= PORT_DEV_SSP_INIT;
  715. if (id->stp_tport)
  716. att_dev_info |= PORT_DEV_STP_TRGT;
  717. if (id->smp_tport)
  718. att_dev_info |= PORT_DEV_SMP_TRGT;
  719. if (id->ssp_tport)
  720. att_dev_info |= PORT_DEV_SSP_TRGT;
  721. att_dev_info |= (u32)id->phy_id<<24;
  722. return att_dev_info;
  723. }
  724. static u32 mvs_94xx_make_att_info(struct sas_identify_frame *id)
  725. {
  726. return mvs_94xx_make_dev_info(id);
  727. }
  728. static void mvs_94xx_fix_phy_info(struct mvs_info *mvi, int i,
  729. struct sas_identify_frame *id)
  730. {
  731. struct mvs_phy *phy = &mvi->phy[i];
  732. struct asd_sas_phy *sas_phy = &phy->sas_phy;
  733. mv_dprintk("get all reg link rate is 0x%x\n", phy->phy_status);
  734. sas_phy->linkrate =
  735. (phy->phy_status & PHY_NEG_SPP_PHYS_LINK_RATE_MASK) >>
  736. PHY_NEG_SPP_PHYS_LINK_RATE_MASK_OFFSET;
  737. sas_phy->linkrate += 0x8;
  738. mv_dprintk("get link rate is %d\n", sas_phy->linkrate);
  739. phy->minimum_linkrate = SAS_LINK_RATE_1_5_GBPS;
  740. phy->maximum_linkrate = SAS_LINK_RATE_6_0_GBPS;
  741. mvs_94xx_get_dev_identify_frame(mvi, i, id);
  742. phy->dev_info = mvs_94xx_make_dev_info(id);
  743. if (phy->phy_type & PORT_TYPE_SAS) {
  744. mvs_94xx_get_att_identify_frame(mvi, i, id);
  745. phy->att_dev_info = mvs_94xx_make_att_info(id);
  746. phy->att_dev_sas_addr = *(u64 *)id->sas_addr;
  747. } else {
  748. phy->att_dev_info = PORT_DEV_STP_TRGT | 1;
  749. }
  750. /* enable spin up bit */
  751. mvs_write_port_cfg_addr(mvi, i, PHYR_PHY_STAT);
  752. mvs_write_port_cfg_data(mvi, i, 0x04);
  753. }
  754. void mvs_94xx_phy_set_link_rate(struct mvs_info *mvi, u32 phy_id,
  755. struct sas_phy_linkrates *rates)
  756. {
  757. u32 lrmax = 0;
  758. u32 tmp;
  759. tmp = mvs_read_phy_ctl(mvi, phy_id);
  760. lrmax = (rates->maximum_linkrate - SAS_LINK_RATE_1_5_GBPS) << 12;
  761. if (lrmax) {
  762. tmp &= ~(0x3 << 12);
  763. tmp |= lrmax;
  764. }
  765. mvs_write_phy_ctl(mvi, phy_id, tmp);
  766. mvs_94xx_phy_reset(mvi, phy_id, PHY_RST_HARD);
  767. }
  768. static void mvs_94xx_clear_active_cmds(struct mvs_info *mvi)
  769. {
  770. u32 tmp;
  771. void __iomem *regs = mvi->regs;
  772. tmp = mr32(MVS_STP_REG_SET_0);
  773. mw32(MVS_STP_REG_SET_0, 0);
  774. mw32(MVS_STP_REG_SET_0, tmp);
  775. tmp = mr32(MVS_STP_REG_SET_1);
  776. mw32(MVS_STP_REG_SET_1, 0);
  777. mw32(MVS_STP_REG_SET_1, tmp);
  778. }
  779. u32 mvs_94xx_spi_read_data(struct mvs_info *mvi)
  780. {
  781. void __iomem *regs = mvi->regs_ex - 0x10200;
  782. return mr32(SPI_RD_DATA_REG_94XX);
  783. }
  784. void mvs_94xx_spi_write_data(struct mvs_info *mvi, u32 data)
  785. {
  786. void __iomem *regs = mvi->regs_ex - 0x10200;
  787. mw32(SPI_RD_DATA_REG_94XX, data);
  788. }
  789. int mvs_94xx_spi_buildcmd(struct mvs_info *mvi,
  790. u32 *dwCmd,
  791. u8 cmd,
  792. u8 read,
  793. u8 length,
  794. u32 addr
  795. )
  796. {
  797. void __iomem *regs = mvi->regs_ex - 0x10200;
  798. u32 dwTmp;
  799. dwTmp = ((u32)cmd << 8) | ((u32)length << 4);
  800. if (read)
  801. dwTmp |= SPI_CTRL_READ_94XX;
  802. if (addr != MV_MAX_U32) {
  803. mw32(SPI_ADDR_REG_94XX, (addr & 0x0003FFFFL));
  804. dwTmp |= SPI_ADDR_VLD_94XX;
  805. }
  806. *dwCmd = dwTmp;
  807. return 0;
  808. }
  809. int mvs_94xx_spi_issuecmd(struct mvs_info *mvi, u32 cmd)
  810. {
  811. void __iomem *regs = mvi->regs_ex - 0x10200;
  812. mw32(SPI_CTRL_REG_94XX, cmd | SPI_CTRL_SpiStart_94XX);
  813. return 0;
  814. }
  815. int mvs_94xx_spi_waitdataready(struct mvs_info *mvi, u32 timeout)
  816. {
  817. void __iomem *regs = mvi->regs_ex - 0x10200;
  818. u32 i, dwTmp;
  819. for (i = 0; i < timeout; i++) {
  820. dwTmp = mr32(SPI_CTRL_REG_94XX);
  821. if (!(dwTmp & SPI_CTRL_SpiStart_94XX))
  822. return 0;
  823. msleep(10);
  824. }
  825. return -1;
  826. }
  827. void mvs_94xx_fix_dma(struct mvs_info *mvi, u32 phy_mask,
  828. int buf_len, int from, void *prd)
  829. {
  830. int i;
  831. struct mvs_prd *buf_prd = prd;
  832. dma_addr_t buf_dma;
  833. struct mvs_prd_imt im_len;
  834. *(u32 *)&im_len = 0;
  835. buf_prd += from;
  836. #define PRD_CHAINED_ENTRY 0x01
  837. if ((mvi->pdev->revision == VANIR_A0_REV) ||
  838. (mvi->pdev->revision == VANIR_B0_REV))
  839. buf_dma = (phy_mask <= 0x08) ?
  840. mvi->bulk_buffer_dma : mvi->bulk_buffer_dma1;
  841. else
  842. return;
  843. for (i = from; i < MAX_SG_ENTRY; i++, ++buf_prd) {
  844. if (i == MAX_SG_ENTRY - 1) {
  845. buf_prd->addr = cpu_to_le64(virt_to_phys(buf_prd - 1));
  846. im_len.len = 2;
  847. im_len.misc_ctl = PRD_CHAINED_ENTRY;
  848. } else {
  849. buf_prd->addr = cpu_to_le64(buf_dma);
  850. im_len.len = buf_len;
  851. }
  852. buf_prd->im_len = cpu_to_le32(*(u32 *)&im_len);
  853. }
  854. }
  855. static void mvs_94xx_tune_interrupt(struct mvs_info *mvi, u32 time)
  856. {
  857. void __iomem *regs = mvi->regs;
  858. u32 tmp = 0;
  859. /*
  860. * the max count is 0x1ff, while our max slot is 0x200,
  861. * it will make count 0.
  862. */
  863. if (time == 0) {
  864. mw32(MVS_INT_COAL, 0);
  865. mw32(MVS_INT_COAL_TMOUT, 0x10000);
  866. } else {
  867. if (MVS_CHIP_SLOT_SZ > 0x1ff)
  868. mw32(MVS_INT_COAL, 0x1ff|COAL_EN);
  869. else
  870. mw32(MVS_INT_COAL, MVS_CHIP_SLOT_SZ|COAL_EN);
  871. tmp = 0x10000 | time;
  872. mw32(MVS_INT_COAL_TMOUT, tmp);
  873. }
  874. }
  875. const struct mvs_dispatch mvs_94xx_dispatch = {
  876. "mv94xx",
  877. mvs_94xx_init,
  878. NULL,
  879. mvs_94xx_ioremap,
  880. mvs_94xx_iounmap,
  881. mvs_94xx_isr,
  882. mvs_94xx_isr_status,
  883. mvs_94xx_interrupt_enable,
  884. mvs_94xx_interrupt_disable,
  885. mvs_read_phy_ctl,
  886. mvs_write_phy_ctl,
  887. mvs_read_port_cfg_data,
  888. mvs_write_port_cfg_data,
  889. mvs_write_port_cfg_addr,
  890. mvs_read_port_vsr_data,
  891. mvs_write_port_vsr_data,
  892. mvs_write_port_vsr_addr,
  893. mvs_read_port_irq_stat,
  894. mvs_write_port_irq_stat,
  895. mvs_read_port_irq_mask,
  896. mvs_write_port_irq_mask,
  897. mvs_94xx_command_active,
  898. mvs_94xx_clear_srs_irq,
  899. mvs_94xx_issue_stop,
  900. mvs_start_delivery,
  901. mvs_rx_update,
  902. mvs_int_full,
  903. mvs_94xx_assign_reg_set,
  904. mvs_94xx_free_reg_set,
  905. mvs_get_prd_size,
  906. mvs_get_prd_count,
  907. mvs_94xx_make_prd,
  908. mvs_94xx_detect_porttype,
  909. mvs_94xx_oob_done,
  910. mvs_94xx_fix_phy_info,
  911. NULL,
  912. mvs_94xx_phy_set_link_rate,
  913. mvs_hw_max_link_rate,
  914. mvs_94xx_phy_disable,
  915. mvs_94xx_phy_enable,
  916. mvs_94xx_phy_reset,
  917. NULL,
  918. mvs_94xx_clear_active_cmds,
  919. mvs_94xx_spi_read_data,
  920. mvs_94xx_spi_write_data,
  921. mvs_94xx_spi_buildcmd,
  922. mvs_94xx_spi_issuecmd,
  923. mvs_94xx_spi_waitdataready,
  924. mvs_94xx_fix_dma,
  925. mvs_94xx_tune_interrupt,
  926. mvs_94xx_non_spec_ncq_error,
  927. };