mv_94xx.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198
  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 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. static 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. static 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 void mvs_94xx_sgpio_init(struct mvs_info *mvi)
  302. {
  303. void __iomem *regs = mvi->regs_ex - 0x10200;
  304. u32 tmp;
  305. tmp = mr32(MVS_HST_CHIP_CONFIG);
  306. tmp |= 0x100;
  307. mw32(MVS_HST_CHIP_CONFIG, tmp);
  308. mw32(MVS_SGPIO_CTRL + MVS_SGPIO_HOST_OFFSET * mvi->id,
  309. MVS_SGPIO_CTRL_SDOUT_AUTO << MVS_SGPIO_CTRL_SDOUT_SHIFT);
  310. mw32(MVS_SGPIO_CFG1 + MVS_SGPIO_HOST_OFFSET * mvi->id,
  311. 8 << MVS_SGPIO_CFG1_LOWA_SHIFT |
  312. 8 << MVS_SGPIO_CFG1_HIA_SHIFT |
  313. 4 << MVS_SGPIO_CFG1_LOWB_SHIFT |
  314. 4 << MVS_SGPIO_CFG1_HIB_SHIFT |
  315. 2 << MVS_SGPIO_CFG1_MAXACTON_SHIFT |
  316. 1 << MVS_SGPIO_CFG1_FORCEACTOFF_SHIFT
  317. );
  318. mw32(MVS_SGPIO_CFG2 + MVS_SGPIO_HOST_OFFSET * mvi->id,
  319. (300000 / 100) << MVS_SGPIO_CFG2_CLK_SHIFT | /* 100kHz clock */
  320. 66 << MVS_SGPIO_CFG2_BLINK_SHIFT /* (66 * 0,121 Hz?)*/
  321. );
  322. mw32(MVS_SGPIO_CFG0 + MVS_SGPIO_HOST_OFFSET * mvi->id,
  323. MVS_SGPIO_CFG0_ENABLE |
  324. MVS_SGPIO_CFG0_BLINKA |
  325. MVS_SGPIO_CFG0_BLINKB |
  326. /* 3*4 data bits / PDU */
  327. (12 - 1) << MVS_SGPIO_CFG0_AUT_BITLEN_SHIFT
  328. );
  329. mw32(MVS_SGPIO_DCTRL + MVS_SGPIO_HOST_OFFSET * mvi->id,
  330. DEFAULT_SGPIO_BITS);
  331. mw32(MVS_SGPIO_DSRC + MVS_SGPIO_HOST_OFFSET * mvi->id,
  332. ((mvi->id * 4) + 3) << (8 * 3) |
  333. ((mvi->id * 4) + 2) << (8 * 2) |
  334. ((mvi->id * 4) + 1) << (8 * 1) |
  335. ((mvi->id * 4) + 0) << (8 * 0));
  336. }
  337. static int mvs_94xx_init(struct mvs_info *mvi)
  338. {
  339. void __iomem *regs = mvi->regs;
  340. int i;
  341. u32 tmp, cctl;
  342. u8 revision;
  343. revision = mvi->pdev->revision;
  344. mvs_show_pcie_usage(mvi);
  345. if (mvi->flags & MVF_FLAG_SOC) {
  346. tmp = mr32(MVS_PHY_CTL);
  347. tmp &= ~PCTL_PWR_OFF;
  348. tmp |= PCTL_PHY_DSBL;
  349. mw32(MVS_PHY_CTL, tmp);
  350. }
  351. /* Init Chip */
  352. /* make sure RST is set; HBA_RST /should/ have done that for us */
  353. cctl = mr32(MVS_CTL) & 0xFFFF;
  354. if (cctl & CCTL_RST)
  355. cctl &= ~CCTL_RST;
  356. else
  357. mw32_f(MVS_CTL, cctl | CCTL_RST);
  358. if (mvi->flags & MVF_FLAG_SOC) {
  359. tmp = mr32(MVS_PHY_CTL);
  360. tmp &= ~PCTL_PWR_OFF;
  361. tmp |= PCTL_COM_ON;
  362. tmp &= ~PCTL_PHY_DSBL;
  363. tmp |= PCTL_LINK_RST;
  364. mw32(MVS_PHY_CTL, tmp);
  365. msleep(100);
  366. tmp &= ~PCTL_LINK_RST;
  367. mw32(MVS_PHY_CTL, tmp);
  368. msleep(100);
  369. }
  370. /* disable Multiplexing, enable phy implemented */
  371. mw32(MVS_PORTS_IMP, 0xFF);
  372. if (revision == VANIR_A0_REV) {
  373. mw32(MVS_PA_VSR_ADDR, CMD_CMWK_OOB_DET);
  374. mw32(MVS_PA_VSR_PORT, 0x00018080);
  375. }
  376. mw32(MVS_PA_VSR_ADDR, VSR_PHY_MODE2);
  377. if (revision == VANIR_A0_REV || revision == VANIR_B0_REV)
  378. /* set 6G/3G/1.5G, multiplexing, without SSC */
  379. mw32(MVS_PA_VSR_PORT, 0x0084d4fe);
  380. else
  381. /* set 6G/3G/1.5G, multiplexing, with and without SSC */
  382. mw32(MVS_PA_VSR_PORT, 0x0084fffe);
  383. if (revision == VANIR_B0_REV) {
  384. mw32(MVS_PA_VSR_ADDR, CMD_APP_MEM_CTL);
  385. mw32(MVS_PA_VSR_PORT, 0x08001006);
  386. mw32(MVS_PA_VSR_ADDR, CMD_HOST_RD_DATA);
  387. mw32(MVS_PA_VSR_PORT, 0x0000705f);
  388. }
  389. /* reset control */
  390. mw32(MVS_PCS, 0); /* MVS_PCS */
  391. mw32(MVS_STP_REG_SET_0, 0);
  392. mw32(MVS_STP_REG_SET_1, 0);
  393. /* init phys */
  394. mvs_phy_hacks(mvi);
  395. /* disable non data frame retry */
  396. tmp = mvs_cr32(mvi, CMD_SAS_CTL1);
  397. if ((revision == VANIR_A0_REV) ||
  398. (revision == VANIR_B0_REV) ||
  399. (revision == VANIR_C0_REV)) {
  400. tmp &= ~0xffff;
  401. tmp |= 0x007f;
  402. mvs_cw32(mvi, CMD_SAS_CTL1, tmp);
  403. }
  404. /* set LED blink when IO*/
  405. mw32(MVS_PA_VSR_ADDR, VSR_PHY_ACT_LED);
  406. tmp = mr32(MVS_PA_VSR_PORT);
  407. tmp &= 0xFFFF00FF;
  408. tmp |= 0x00003300;
  409. mw32(MVS_PA_VSR_PORT, tmp);
  410. mw32(MVS_CMD_LIST_LO, mvi->slot_dma);
  411. mw32(MVS_CMD_LIST_HI, (mvi->slot_dma >> 16) >> 16);
  412. mw32(MVS_RX_FIS_LO, mvi->rx_fis_dma);
  413. mw32(MVS_RX_FIS_HI, (mvi->rx_fis_dma >> 16) >> 16);
  414. mw32(MVS_TX_CFG, MVS_CHIP_SLOT_SZ);
  415. mw32(MVS_TX_LO, mvi->tx_dma);
  416. mw32(MVS_TX_HI, (mvi->tx_dma >> 16) >> 16);
  417. mw32(MVS_RX_CFG, MVS_RX_RING_SZ);
  418. mw32(MVS_RX_LO, mvi->rx_dma);
  419. mw32(MVS_RX_HI, (mvi->rx_dma >> 16) >> 16);
  420. for (i = 0; i < mvi->chip->n_phy; i++) {
  421. mvs_94xx_phy_disable(mvi, i);
  422. /* set phy local SAS address */
  423. mvs_set_sas_addr(mvi, i, CONFIG_ID_FRAME3, CONFIG_ID_FRAME4,
  424. cpu_to_le64(mvi->phy[i].dev_sas_addr));
  425. mvs_94xx_enable_xmt(mvi, i);
  426. mvs_94xx_config_reg_from_hba(mvi, i);
  427. mvs_94xx_phy_enable(mvi, i);
  428. mvs_94xx_phy_reset(mvi, i, PHY_RST_HARD);
  429. msleep(500);
  430. mvs_94xx_detect_porttype(mvi, i);
  431. }
  432. if (mvi->flags & MVF_FLAG_SOC) {
  433. /* set select registers */
  434. writel(0x0E008000, regs + 0x000);
  435. writel(0x59000008, regs + 0x004);
  436. writel(0x20, regs + 0x008);
  437. writel(0x20, regs + 0x00c);
  438. writel(0x20, regs + 0x010);
  439. writel(0x20, regs + 0x014);
  440. writel(0x20, regs + 0x018);
  441. writel(0x20, regs + 0x01c);
  442. }
  443. for (i = 0; i < mvi->chip->n_phy; i++) {
  444. /* clear phy int status */
  445. tmp = mvs_read_port_irq_stat(mvi, i);
  446. tmp &= ~PHYEV_SIG_FIS;
  447. mvs_write_port_irq_stat(mvi, i, tmp);
  448. /* set phy int mask */
  449. tmp = PHYEV_RDY_CH | PHYEV_BROAD_CH |
  450. PHYEV_ID_DONE | PHYEV_DCDR_ERR | PHYEV_CRC_ERR ;
  451. mvs_write_port_irq_mask(mvi, i, tmp);
  452. msleep(100);
  453. mvs_update_phyinfo(mvi, i, 1);
  454. }
  455. /* little endian for open address and command table, etc. */
  456. cctl = mr32(MVS_CTL);
  457. cctl |= CCTL_ENDIAN_CMD;
  458. cctl &= ~CCTL_ENDIAN_OPEN;
  459. cctl |= CCTL_ENDIAN_RSP;
  460. mw32_f(MVS_CTL, cctl);
  461. /* reset CMD queue */
  462. tmp = mr32(MVS_PCS);
  463. tmp |= PCS_CMD_RST;
  464. tmp &= ~PCS_SELF_CLEAR;
  465. mw32(MVS_PCS, tmp);
  466. /*
  467. * the max count is 0x1ff, while our max slot is 0x200,
  468. * it will make count 0.
  469. */
  470. tmp = 0;
  471. if (MVS_CHIP_SLOT_SZ > 0x1ff)
  472. mw32(MVS_INT_COAL, 0x1ff | COAL_EN);
  473. else
  474. mw32(MVS_INT_COAL, MVS_CHIP_SLOT_SZ | COAL_EN);
  475. /* default interrupt coalescing time is 128us */
  476. tmp = 0x10000 | interrupt_coalescing;
  477. mw32(MVS_INT_COAL_TMOUT, tmp);
  478. /* ladies and gentlemen, start your engines */
  479. mw32(MVS_TX_CFG, 0);
  480. mw32(MVS_TX_CFG, MVS_CHIP_SLOT_SZ | TX_EN);
  481. mw32(MVS_RX_CFG, MVS_RX_RING_SZ | RX_EN);
  482. /* enable CMD/CMPL_Q/RESP mode */
  483. mw32(MVS_PCS, PCS_SATA_RETRY_2 | PCS_FIS_RX_EN |
  484. PCS_CMD_EN | PCS_CMD_STOP_ERR);
  485. /* enable completion queue interrupt */
  486. tmp = (CINT_PORT_MASK | CINT_DONE | CINT_MEM | CINT_SRS | CINT_CI_STOP |
  487. CINT_DMA_PCIE | CINT_NON_SPEC_NCQ_ERROR);
  488. tmp |= CINT_PHY_MASK;
  489. mw32(MVS_INT_MASK, tmp);
  490. tmp = mvs_cr32(mvi, CMD_LINK_TIMER);
  491. tmp |= 0xFFFF0000;
  492. mvs_cw32(mvi, CMD_LINK_TIMER, tmp);
  493. /* tune STP performance */
  494. tmp = 0x003F003F;
  495. mvs_cw32(mvi, CMD_PL_TIMER, tmp);
  496. /* This can improve expander large block size seq write performance */
  497. tmp = mvs_cr32(mvi, CMD_PORT_LAYER_TIMER1);
  498. tmp |= 0xFFFF007F;
  499. mvs_cw32(mvi, CMD_PORT_LAYER_TIMER1, tmp);
  500. /* change the connection open-close behavior (bit 9)
  501. * set bit8 to 1 for performance tuning */
  502. tmp = mvs_cr32(mvi, CMD_SL_MODE0);
  503. tmp |= 0x00000300;
  504. /* set bit0 to 0 to enable retry for no_dest reject case */
  505. tmp &= 0xFFFFFFFE;
  506. mvs_cw32(mvi, CMD_SL_MODE0, tmp);
  507. /* Enable SRS interrupt */
  508. mw32(MVS_INT_MASK_SRS_0, 0xFFFF);
  509. mvs_94xx_sgpio_init(mvi);
  510. return 0;
  511. }
  512. static int mvs_94xx_ioremap(struct mvs_info *mvi)
  513. {
  514. if (!mvs_ioremap(mvi, 2, -1)) {
  515. mvi->regs_ex = mvi->regs + 0x10200;
  516. mvi->regs += 0x20000;
  517. if (mvi->id == 1)
  518. mvi->regs += 0x4000;
  519. return 0;
  520. }
  521. return -1;
  522. }
  523. static void mvs_94xx_iounmap(struct mvs_info *mvi)
  524. {
  525. if (mvi->regs) {
  526. mvi->regs -= 0x20000;
  527. if (mvi->id == 1)
  528. mvi->regs -= 0x4000;
  529. mvs_iounmap(mvi->regs);
  530. }
  531. }
  532. static void mvs_94xx_interrupt_enable(struct mvs_info *mvi)
  533. {
  534. void __iomem *regs = mvi->regs_ex;
  535. u32 tmp;
  536. tmp = mr32(MVS_GBL_CTL);
  537. tmp |= (MVS_IRQ_SAS_A | MVS_IRQ_SAS_B);
  538. mw32(MVS_GBL_INT_STAT, tmp);
  539. writel(tmp, regs + 0x0C);
  540. writel(tmp, regs + 0x10);
  541. writel(tmp, regs + 0x14);
  542. writel(tmp, regs + 0x18);
  543. mw32(MVS_GBL_CTL, tmp);
  544. }
  545. static void mvs_94xx_interrupt_disable(struct mvs_info *mvi)
  546. {
  547. void __iomem *regs = mvi->regs_ex;
  548. u32 tmp;
  549. tmp = mr32(MVS_GBL_CTL);
  550. tmp &= ~(MVS_IRQ_SAS_A | MVS_IRQ_SAS_B);
  551. mw32(MVS_GBL_INT_STAT, tmp);
  552. writel(tmp, regs + 0x0C);
  553. writel(tmp, regs + 0x10);
  554. writel(tmp, regs + 0x14);
  555. writel(tmp, regs + 0x18);
  556. mw32(MVS_GBL_CTL, tmp);
  557. }
  558. static u32 mvs_94xx_isr_status(struct mvs_info *mvi, int irq)
  559. {
  560. void __iomem *regs = mvi->regs_ex;
  561. u32 stat = 0;
  562. if (!(mvi->flags & MVF_FLAG_SOC)) {
  563. stat = mr32(MVS_GBL_INT_STAT);
  564. if (!(stat & (MVS_IRQ_SAS_A | MVS_IRQ_SAS_B)))
  565. return 0;
  566. }
  567. return stat;
  568. }
  569. static irqreturn_t mvs_94xx_isr(struct mvs_info *mvi, int irq, u32 stat)
  570. {
  571. void __iomem *regs = mvi->regs;
  572. if (((stat & MVS_IRQ_SAS_A) && mvi->id == 0) ||
  573. ((stat & MVS_IRQ_SAS_B) && mvi->id == 1)) {
  574. mw32_f(MVS_INT_STAT, CINT_DONE);
  575. spin_lock(&mvi->lock);
  576. mvs_int_full(mvi);
  577. spin_unlock(&mvi->lock);
  578. }
  579. return IRQ_HANDLED;
  580. }
  581. static void mvs_94xx_command_active(struct mvs_info *mvi, u32 slot_idx)
  582. {
  583. u32 tmp;
  584. tmp = mvs_cr32(mvi, MVS_COMMAND_ACTIVE+(slot_idx >> 3));
  585. if (tmp & 1 << (slot_idx % 32)) {
  586. mv_printk("command active %08X, slot [%x].\n", tmp, slot_idx);
  587. mvs_cw32(mvi, MVS_COMMAND_ACTIVE + (slot_idx >> 3),
  588. 1 << (slot_idx % 32));
  589. do {
  590. tmp = mvs_cr32(mvi,
  591. MVS_COMMAND_ACTIVE + (slot_idx >> 3));
  592. } while (tmp & 1 << (slot_idx % 32));
  593. }
  594. }
  595. static void
  596. mvs_94xx_clear_srs_irq(struct mvs_info *mvi, u8 reg_set, u8 clear_all)
  597. {
  598. void __iomem *regs = mvi->regs;
  599. u32 tmp;
  600. if (clear_all) {
  601. tmp = mr32(MVS_INT_STAT_SRS_0);
  602. if (tmp) {
  603. mv_dprintk("check SRS 0 %08X.\n", tmp);
  604. mw32(MVS_INT_STAT_SRS_0, tmp);
  605. }
  606. tmp = mr32(MVS_INT_STAT_SRS_1);
  607. if (tmp) {
  608. mv_dprintk("check SRS 1 %08X.\n", tmp);
  609. mw32(MVS_INT_STAT_SRS_1, tmp);
  610. }
  611. } else {
  612. if (reg_set > 31)
  613. tmp = mr32(MVS_INT_STAT_SRS_1);
  614. else
  615. tmp = mr32(MVS_INT_STAT_SRS_0);
  616. if (tmp & (1 << (reg_set % 32))) {
  617. mv_dprintk("register set 0x%x was stopped.\n", reg_set);
  618. if (reg_set > 31)
  619. mw32(MVS_INT_STAT_SRS_1, 1 << (reg_set % 32));
  620. else
  621. mw32(MVS_INT_STAT_SRS_0, 1 << (reg_set % 32));
  622. }
  623. }
  624. }
  625. static void mvs_94xx_issue_stop(struct mvs_info *mvi, enum mvs_port_type type,
  626. u32 tfs)
  627. {
  628. void __iomem *regs = mvi->regs;
  629. u32 tmp;
  630. mvs_94xx_clear_srs_irq(mvi, 0, 1);
  631. tmp = mr32(MVS_INT_STAT);
  632. mw32(MVS_INT_STAT, tmp | CINT_CI_STOP);
  633. tmp = mr32(MVS_PCS) | 0xFF00;
  634. mw32(MVS_PCS, tmp);
  635. }
  636. static void mvs_94xx_non_spec_ncq_error(struct mvs_info *mvi)
  637. {
  638. void __iomem *regs = mvi->regs;
  639. u32 err_0, err_1;
  640. u8 i;
  641. struct mvs_device *device;
  642. err_0 = mr32(MVS_NON_NCQ_ERR_0);
  643. err_1 = mr32(MVS_NON_NCQ_ERR_1);
  644. mv_dprintk("non specific ncq error err_0:%x,err_1:%x.\n",
  645. err_0, err_1);
  646. for (i = 0; i < 32; i++) {
  647. if (err_0 & bit(i)) {
  648. device = mvs_find_dev_by_reg_set(mvi, i);
  649. if (device)
  650. mvs_release_task(mvi, device->sas_device);
  651. }
  652. if (err_1 & bit(i)) {
  653. device = mvs_find_dev_by_reg_set(mvi, i+32);
  654. if (device)
  655. mvs_release_task(mvi, device->sas_device);
  656. }
  657. }
  658. mw32(MVS_NON_NCQ_ERR_0, err_0);
  659. mw32(MVS_NON_NCQ_ERR_1, err_1);
  660. }
  661. static void mvs_94xx_free_reg_set(struct mvs_info *mvi, u8 *tfs)
  662. {
  663. void __iomem *regs = mvi->regs;
  664. u8 reg_set = *tfs;
  665. if (*tfs == MVS_ID_NOT_MAPPED)
  666. return;
  667. mvi->sata_reg_set &= ~bit(reg_set);
  668. if (reg_set < 32)
  669. w_reg_set_enable(reg_set, (u32)mvi->sata_reg_set);
  670. else
  671. w_reg_set_enable(reg_set, (u32)(mvi->sata_reg_set >> 32));
  672. *tfs = MVS_ID_NOT_MAPPED;
  673. return;
  674. }
  675. static u8 mvs_94xx_assign_reg_set(struct mvs_info *mvi, u8 *tfs)
  676. {
  677. int i;
  678. void __iomem *regs = mvi->regs;
  679. if (*tfs != MVS_ID_NOT_MAPPED)
  680. return 0;
  681. i = mv_ffc64(mvi->sata_reg_set);
  682. if (i >= 32) {
  683. mvi->sata_reg_set |= bit(i);
  684. w_reg_set_enable(i, (u32)(mvi->sata_reg_set >> 32));
  685. *tfs = i;
  686. return 0;
  687. } else if (i >= 0) {
  688. mvi->sata_reg_set |= bit(i);
  689. w_reg_set_enable(i, (u32)mvi->sata_reg_set);
  690. *tfs = i;
  691. return 0;
  692. }
  693. return MVS_ID_NOT_MAPPED;
  694. }
  695. static void mvs_94xx_make_prd(struct scatterlist *scatter, int nr, void *prd)
  696. {
  697. int i;
  698. struct scatterlist *sg;
  699. struct mvs_prd *buf_prd = prd;
  700. struct mvs_prd_imt im_len;
  701. *(u32 *)&im_len = 0;
  702. for_each_sg(scatter, sg, nr, i) {
  703. buf_prd->addr = cpu_to_le64(sg_dma_address(sg));
  704. im_len.len = sg_dma_len(sg);
  705. buf_prd->im_len = cpu_to_le32(*(u32 *)&im_len);
  706. buf_prd++;
  707. }
  708. }
  709. static int mvs_94xx_oob_done(struct mvs_info *mvi, int i)
  710. {
  711. u32 phy_st;
  712. phy_st = mvs_read_phy_ctl(mvi, i);
  713. if (phy_st & PHY_READY_MASK)
  714. return 1;
  715. return 0;
  716. }
  717. static void mvs_94xx_get_dev_identify_frame(struct mvs_info *mvi, int port_id,
  718. struct sas_identify_frame *id)
  719. {
  720. int i;
  721. u32 id_frame[7];
  722. for (i = 0; i < 7; i++) {
  723. mvs_write_port_cfg_addr(mvi, port_id,
  724. CONFIG_ID_FRAME0 + i * 4);
  725. id_frame[i] = cpu_to_le32(mvs_read_port_cfg_data(mvi, port_id));
  726. }
  727. memcpy(id, id_frame, 28);
  728. }
  729. static void mvs_94xx_get_att_identify_frame(struct mvs_info *mvi, int port_id,
  730. struct sas_identify_frame *id)
  731. {
  732. int i;
  733. u32 id_frame[7];
  734. for (i = 0; i < 7; i++) {
  735. mvs_write_port_cfg_addr(mvi, port_id,
  736. CONFIG_ATT_ID_FRAME0 + i * 4);
  737. id_frame[i] = cpu_to_le32(mvs_read_port_cfg_data(mvi, port_id));
  738. mv_dprintk("94xx phy %d atta frame %d %x.\n",
  739. port_id + mvi->id * mvi->chip->n_phy, i, id_frame[i]);
  740. }
  741. memcpy(id, id_frame, 28);
  742. }
  743. static u32 mvs_94xx_make_dev_info(struct sas_identify_frame *id)
  744. {
  745. u32 att_dev_info = 0;
  746. att_dev_info |= id->dev_type;
  747. if (id->stp_iport)
  748. att_dev_info |= PORT_DEV_STP_INIT;
  749. if (id->smp_iport)
  750. att_dev_info |= PORT_DEV_SMP_INIT;
  751. if (id->ssp_iport)
  752. att_dev_info |= PORT_DEV_SSP_INIT;
  753. if (id->stp_tport)
  754. att_dev_info |= PORT_DEV_STP_TRGT;
  755. if (id->smp_tport)
  756. att_dev_info |= PORT_DEV_SMP_TRGT;
  757. if (id->ssp_tport)
  758. att_dev_info |= PORT_DEV_SSP_TRGT;
  759. att_dev_info |= (u32)id->phy_id<<24;
  760. return att_dev_info;
  761. }
  762. static u32 mvs_94xx_make_att_info(struct sas_identify_frame *id)
  763. {
  764. return mvs_94xx_make_dev_info(id);
  765. }
  766. static void mvs_94xx_fix_phy_info(struct mvs_info *mvi, int i,
  767. struct sas_identify_frame *id)
  768. {
  769. struct mvs_phy *phy = &mvi->phy[i];
  770. struct asd_sas_phy *sas_phy = &phy->sas_phy;
  771. mv_dprintk("get all reg link rate is 0x%x\n", phy->phy_status);
  772. sas_phy->linkrate =
  773. (phy->phy_status & PHY_NEG_SPP_PHYS_LINK_RATE_MASK) >>
  774. PHY_NEG_SPP_PHYS_LINK_RATE_MASK_OFFSET;
  775. sas_phy->linkrate += 0x8;
  776. mv_dprintk("get link rate is %d\n", sas_phy->linkrate);
  777. phy->minimum_linkrate = SAS_LINK_RATE_1_5_GBPS;
  778. phy->maximum_linkrate = SAS_LINK_RATE_6_0_GBPS;
  779. mvs_94xx_get_dev_identify_frame(mvi, i, id);
  780. phy->dev_info = mvs_94xx_make_dev_info(id);
  781. if (phy->phy_type & PORT_TYPE_SAS) {
  782. mvs_94xx_get_att_identify_frame(mvi, i, id);
  783. phy->att_dev_info = mvs_94xx_make_att_info(id);
  784. phy->att_dev_sas_addr = *(u64 *)id->sas_addr;
  785. } else {
  786. phy->att_dev_info = PORT_DEV_STP_TRGT | 1;
  787. }
  788. /* enable spin up bit */
  789. mvs_write_port_cfg_addr(mvi, i, PHYR_PHY_STAT);
  790. mvs_write_port_cfg_data(mvi, i, 0x04);
  791. }
  792. static void mvs_94xx_phy_set_link_rate(struct mvs_info *mvi, u32 phy_id,
  793. struct sas_phy_linkrates *rates)
  794. {
  795. u32 lrmax = 0;
  796. u32 tmp;
  797. tmp = mvs_read_phy_ctl(mvi, phy_id);
  798. lrmax = (rates->maximum_linkrate - SAS_LINK_RATE_1_5_GBPS) << 12;
  799. if (lrmax) {
  800. tmp &= ~(0x3 << 12);
  801. tmp |= lrmax;
  802. }
  803. mvs_write_phy_ctl(mvi, phy_id, tmp);
  804. mvs_94xx_phy_reset(mvi, phy_id, PHY_RST_HARD);
  805. }
  806. static void mvs_94xx_clear_active_cmds(struct mvs_info *mvi)
  807. {
  808. u32 tmp;
  809. void __iomem *regs = mvi->regs;
  810. tmp = mr32(MVS_STP_REG_SET_0);
  811. mw32(MVS_STP_REG_SET_0, 0);
  812. mw32(MVS_STP_REG_SET_0, tmp);
  813. tmp = mr32(MVS_STP_REG_SET_1);
  814. mw32(MVS_STP_REG_SET_1, 0);
  815. mw32(MVS_STP_REG_SET_1, tmp);
  816. }
  817. static u32 mvs_94xx_spi_read_data(struct mvs_info *mvi)
  818. {
  819. void __iomem *regs = mvi->regs_ex - 0x10200;
  820. return mr32(SPI_RD_DATA_REG_94XX);
  821. }
  822. static void mvs_94xx_spi_write_data(struct mvs_info *mvi, u32 data)
  823. {
  824. void __iomem *regs = mvi->regs_ex - 0x10200;
  825. mw32(SPI_RD_DATA_REG_94XX, data);
  826. }
  827. static int mvs_94xx_spi_buildcmd(struct mvs_info *mvi,
  828. u32 *dwCmd,
  829. u8 cmd,
  830. u8 read,
  831. u8 length,
  832. u32 addr
  833. )
  834. {
  835. void __iomem *regs = mvi->regs_ex - 0x10200;
  836. u32 dwTmp;
  837. dwTmp = ((u32)cmd << 8) | ((u32)length << 4);
  838. if (read)
  839. dwTmp |= SPI_CTRL_READ_94XX;
  840. if (addr != MV_MAX_U32) {
  841. mw32(SPI_ADDR_REG_94XX, (addr & 0x0003FFFFL));
  842. dwTmp |= SPI_ADDR_VLD_94XX;
  843. }
  844. *dwCmd = dwTmp;
  845. return 0;
  846. }
  847. static int mvs_94xx_spi_issuecmd(struct mvs_info *mvi, u32 cmd)
  848. {
  849. void __iomem *regs = mvi->regs_ex - 0x10200;
  850. mw32(SPI_CTRL_REG_94XX, cmd | SPI_CTRL_SpiStart_94XX);
  851. return 0;
  852. }
  853. static int mvs_94xx_spi_waitdataready(struct mvs_info *mvi, u32 timeout)
  854. {
  855. void __iomem *regs = mvi->regs_ex - 0x10200;
  856. u32 i, dwTmp;
  857. for (i = 0; i < timeout; i++) {
  858. dwTmp = mr32(SPI_CTRL_REG_94XX);
  859. if (!(dwTmp & SPI_CTRL_SpiStart_94XX))
  860. return 0;
  861. msleep(10);
  862. }
  863. return -1;
  864. }
  865. static void mvs_94xx_fix_dma(struct mvs_info *mvi, u32 phy_mask,
  866. int buf_len, int from, void *prd)
  867. {
  868. int i;
  869. struct mvs_prd *buf_prd = prd;
  870. dma_addr_t buf_dma;
  871. struct mvs_prd_imt im_len;
  872. *(u32 *)&im_len = 0;
  873. buf_prd += from;
  874. #define PRD_CHAINED_ENTRY 0x01
  875. if ((mvi->pdev->revision == VANIR_A0_REV) ||
  876. (mvi->pdev->revision == VANIR_B0_REV))
  877. buf_dma = (phy_mask <= 0x08) ?
  878. mvi->bulk_buffer_dma : mvi->bulk_buffer_dma1;
  879. else
  880. return;
  881. for (i = from; i < MAX_SG_ENTRY; i++, ++buf_prd) {
  882. if (i == MAX_SG_ENTRY - 1) {
  883. buf_prd->addr = cpu_to_le64(virt_to_phys(buf_prd - 1));
  884. im_len.len = 2;
  885. im_len.misc_ctl = PRD_CHAINED_ENTRY;
  886. } else {
  887. buf_prd->addr = cpu_to_le64(buf_dma);
  888. im_len.len = buf_len;
  889. }
  890. buf_prd->im_len = cpu_to_le32(*(u32 *)&im_len);
  891. }
  892. }
  893. static void mvs_94xx_tune_interrupt(struct mvs_info *mvi, u32 time)
  894. {
  895. void __iomem *regs = mvi->regs;
  896. u32 tmp = 0;
  897. /*
  898. * the max count is 0x1ff, while our max slot is 0x200,
  899. * it will make count 0.
  900. */
  901. if (time == 0) {
  902. mw32(MVS_INT_COAL, 0);
  903. mw32(MVS_INT_COAL_TMOUT, 0x10000);
  904. } else {
  905. if (MVS_CHIP_SLOT_SZ > 0x1ff)
  906. mw32(MVS_INT_COAL, 0x1ff|COAL_EN);
  907. else
  908. mw32(MVS_INT_COAL, MVS_CHIP_SLOT_SZ|COAL_EN);
  909. tmp = 0x10000 | time;
  910. mw32(MVS_INT_COAL_TMOUT, tmp);
  911. }
  912. }
  913. static int mvs_94xx_gpio_write(struct mvs_prv_info *mvs_prv,
  914. u8 reg_type, u8 reg_index,
  915. u8 reg_count, u8 *write_data)
  916. {
  917. int i;
  918. switch (reg_type) {
  919. case SAS_GPIO_REG_TX_GP:
  920. if (reg_index == 0)
  921. return -EINVAL;
  922. if (reg_count > 1)
  923. return -EINVAL;
  924. if (reg_count == 0)
  925. return 0;
  926. /* maximum supported bits = hosts * 4 drives * 3 bits */
  927. for (i = 0; i < mvs_prv->n_host * 4 * 3; i++) {
  928. /* select host */
  929. struct mvs_info *mvi = mvs_prv->mvi[i/(4*3)];
  930. void __iomem *regs = mvi->regs_ex - 0x10200;
  931. int drive = (i/3) & (4-1); /* drive number on host */
  932. int driveshift = drive * 8; /* bit offset of drive */
  933. u32 block = ioread32be(regs + MVS_SGPIO_DCTRL +
  934. MVS_SGPIO_HOST_OFFSET * mvi->id);
  935. /*
  936. * if bit is set then create a mask with the first
  937. * bit of the drive set in the mask ...
  938. */
  939. u32 bit = get_unaligned_be32(write_data) & (1 << i) ?
  940. 1 << driveshift : 0;
  941. /*
  942. * ... and then shift it to the right position based
  943. * on the led type (activity/id/fail)
  944. */
  945. switch (i%3) {
  946. case 0: /* activity */
  947. block &= ~((0x7 << MVS_SGPIO_DCTRL_ACT_SHIFT)
  948. << driveshift);
  949. /* hardwire activity bit to SOF */
  950. block |= LED_BLINKA_SOF << (
  951. MVS_SGPIO_DCTRL_ACT_SHIFT +
  952. driveshift);
  953. break;
  954. case 1: /* id */
  955. block &= ~((0x3 << MVS_SGPIO_DCTRL_LOC_SHIFT)
  956. << driveshift);
  957. block |= bit << MVS_SGPIO_DCTRL_LOC_SHIFT;
  958. break;
  959. case 2: /* fail */
  960. block &= ~((0x7 << MVS_SGPIO_DCTRL_ERR_SHIFT)
  961. << driveshift);
  962. block |= bit << MVS_SGPIO_DCTRL_ERR_SHIFT;
  963. break;
  964. }
  965. iowrite32be(block,
  966. regs + MVS_SGPIO_DCTRL +
  967. MVS_SGPIO_HOST_OFFSET * mvi->id);
  968. }
  969. return reg_count;
  970. case SAS_GPIO_REG_TX:
  971. if (reg_index + reg_count > mvs_prv->n_host)
  972. return -EINVAL;
  973. for (i = 0; i < reg_count; i++) {
  974. struct mvs_info *mvi = mvs_prv->mvi[i+reg_index];
  975. void __iomem *regs = mvi->regs_ex - 0x10200;
  976. mw32(MVS_SGPIO_DCTRL + MVS_SGPIO_HOST_OFFSET * mvi->id,
  977. ((u32 *) write_data)[i]);
  978. }
  979. return reg_count;
  980. }
  981. return -ENOSYS;
  982. }
  983. const struct mvs_dispatch mvs_94xx_dispatch = {
  984. "mv94xx",
  985. mvs_94xx_init,
  986. NULL,
  987. mvs_94xx_ioremap,
  988. mvs_94xx_iounmap,
  989. mvs_94xx_isr,
  990. mvs_94xx_isr_status,
  991. mvs_94xx_interrupt_enable,
  992. mvs_94xx_interrupt_disable,
  993. mvs_read_phy_ctl,
  994. mvs_write_phy_ctl,
  995. mvs_read_port_cfg_data,
  996. mvs_write_port_cfg_data,
  997. mvs_write_port_cfg_addr,
  998. mvs_read_port_vsr_data,
  999. mvs_write_port_vsr_data,
  1000. mvs_write_port_vsr_addr,
  1001. mvs_read_port_irq_stat,
  1002. mvs_write_port_irq_stat,
  1003. mvs_read_port_irq_mask,
  1004. mvs_write_port_irq_mask,
  1005. mvs_94xx_command_active,
  1006. mvs_94xx_clear_srs_irq,
  1007. mvs_94xx_issue_stop,
  1008. mvs_start_delivery,
  1009. mvs_rx_update,
  1010. mvs_int_full,
  1011. mvs_94xx_assign_reg_set,
  1012. mvs_94xx_free_reg_set,
  1013. mvs_get_prd_size,
  1014. mvs_get_prd_count,
  1015. mvs_94xx_make_prd,
  1016. mvs_94xx_detect_porttype,
  1017. mvs_94xx_oob_done,
  1018. mvs_94xx_fix_phy_info,
  1019. NULL,
  1020. mvs_94xx_phy_set_link_rate,
  1021. mvs_hw_max_link_rate,
  1022. mvs_94xx_phy_disable,
  1023. mvs_94xx_phy_enable,
  1024. mvs_94xx_phy_reset,
  1025. NULL,
  1026. mvs_94xx_clear_active_cmds,
  1027. mvs_94xx_spi_read_data,
  1028. mvs_94xx_spi_write_data,
  1029. mvs_94xx_spi_buildcmd,
  1030. mvs_94xx_spi_issuecmd,
  1031. mvs_94xx_spi_waitdataready,
  1032. mvs_94xx_fix_dma,
  1033. mvs_94xx_tune_interrupt,
  1034. mvs_94xx_non_spec_ncq_error,
  1035. mvs_94xx_gpio_write,
  1036. };