hns_dsaf_misc.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. /*
  2. * Copyright (c) 2014-2015 Hisilicon Limited.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. */
  9. #include "hns_dsaf_mac.h"
  10. #include "hns_dsaf_misc.h"
  11. #include "hns_dsaf_ppe.h"
  12. #include "hns_dsaf_reg.h"
  13. enum _dsm_op_index {
  14. HNS_OP_RESET_FUNC = 0x1,
  15. HNS_OP_SERDES_LP_FUNC = 0x2,
  16. HNS_OP_LED_SET_FUNC = 0x3,
  17. HNS_OP_GET_PORT_TYPE_FUNC = 0x4,
  18. HNS_OP_GET_SFP_STAT_FUNC = 0x5,
  19. };
  20. enum _dsm_rst_type {
  21. HNS_DSAF_RESET_FUNC = 0x1,
  22. HNS_PPE_RESET_FUNC = 0x2,
  23. HNS_XGE_CORE_RESET_FUNC = 0x3,
  24. HNS_XGE_RESET_FUNC = 0x4,
  25. HNS_GE_RESET_FUNC = 0x5,
  26. HNS_DSAF_CHN_RESET_FUNC = 0x6,
  27. HNS_ROCE_RESET_FUNC = 0x7,
  28. };
  29. const u8 hns_dsaf_acpi_dsm_uuid[] = {
  30. 0x1A, 0xAA, 0x85, 0x1A, 0x93, 0xE2, 0x5E, 0x41,
  31. 0x8E, 0x28, 0x8D, 0x69, 0x0A, 0x0F, 0x82, 0x0A
  32. };
  33. static void dsaf_write_sub(struct dsaf_device *dsaf_dev, u32 reg, u32 val)
  34. {
  35. if (dsaf_dev->sub_ctrl)
  36. dsaf_write_syscon(dsaf_dev->sub_ctrl, reg, val);
  37. else
  38. dsaf_write_reg(dsaf_dev->sc_base, reg, val);
  39. }
  40. static u32 dsaf_read_sub(struct dsaf_device *dsaf_dev, u32 reg)
  41. {
  42. u32 ret;
  43. if (dsaf_dev->sub_ctrl)
  44. ret = dsaf_read_syscon(dsaf_dev->sub_ctrl, reg);
  45. else
  46. ret = dsaf_read_reg(dsaf_dev->sc_base, reg);
  47. return ret;
  48. }
  49. static void hns_cpld_set_led(struct hns_mac_cb *mac_cb, int link_status,
  50. u16 speed, int data)
  51. {
  52. int speed_reg = 0;
  53. u8 value;
  54. if (!mac_cb) {
  55. pr_err("sfp_led_opt mac_dev is null!\n");
  56. return;
  57. }
  58. if (!mac_cb->cpld_ctrl) {
  59. dev_err(mac_cb->dev, "mac_id=%d, cpld syscon is null !\n",
  60. mac_cb->mac_id);
  61. return;
  62. }
  63. if (speed == MAC_SPEED_10000)
  64. speed_reg = 1;
  65. value = mac_cb->cpld_led_value;
  66. if (link_status) {
  67. dsaf_set_bit(value, DSAF_LED_LINK_B, link_status);
  68. dsaf_set_field(value, DSAF_LED_SPEED_M,
  69. DSAF_LED_SPEED_S, speed_reg);
  70. dsaf_set_bit(value, DSAF_LED_DATA_B, data);
  71. if (value != mac_cb->cpld_led_value) {
  72. dsaf_write_syscon(mac_cb->cpld_ctrl,
  73. mac_cb->cpld_ctrl_reg, value);
  74. mac_cb->cpld_led_value = value;
  75. }
  76. } else {
  77. value = (mac_cb->cpld_led_value) & (0x1 << DSAF_LED_ANCHOR_B);
  78. dsaf_write_syscon(mac_cb->cpld_ctrl,
  79. mac_cb->cpld_ctrl_reg, value);
  80. mac_cb->cpld_led_value = value;
  81. }
  82. }
  83. static void cpld_led_reset(struct hns_mac_cb *mac_cb)
  84. {
  85. if (!mac_cb || !mac_cb->cpld_ctrl)
  86. return;
  87. dsaf_write_syscon(mac_cb->cpld_ctrl, mac_cb->cpld_ctrl_reg,
  88. CPLD_LED_DEFAULT_VALUE);
  89. mac_cb->cpld_led_value = CPLD_LED_DEFAULT_VALUE;
  90. }
  91. static int cpld_set_led_id(struct hns_mac_cb *mac_cb,
  92. enum hnae_led_state status)
  93. {
  94. switch (status) {
  95. case HNAE_LED_ACTIVE:
  96. mac_cb->cpld_led_value =
  97. dsaf_read_syscon(mac_cb->cpld_ctrl,
  98. mac_cb->cpld_ctrl_reg);
  99. dsaf_set_bit(mac_cb->cpld_led_value, DSAF_LED_ANCHOR_B,
  100. CPLD_LED_ON_VALUE);
  101. dsaf_write_syscon(mac_cb->cpld_ctrl, mac_cb->cpld_ctrl_reg,
  102. mac_cb->cpld_led_value);
  103. break;
  104. case HNAE_LED_INACTIVE:
  105. dsaf_set_bit(mac_cb->cpld_led_value, DSAF_LED_ANCHOR_B,
  106. CPLD_LED_DEFAULT_VALUE);
  107. dsaf_write_syscon(mac_cb->cpld_ctrl, mac_cb->cpld_ctrl_reg,
  108. mac_cb->cpld_led_value);
  109. break;
  110. default:
  111. dev_err(mac_cb->dev, "invalid led state: %d!", status);
  112. return -EINVAL;
  113. }
  114. return 0;
  115. }
  116. #define RESET_REQ_OR_DREQ 1
  117. static void hns_dsaf_acpi_srst_by_port(struct dsaf_device *dsaf_dev, u8 op_type,
  118. u32 port_type, u32 port, u32 val)
  119. {
  120. union acpi_object *obj;
  121. union acpi_object obj_args[3], argv4;
  122. obj_args[0].integer.type = ACPI_TYPE_INTEGER;
  123. obj_args[0].integer.value = port_type;
  124. obj_args[1].integer.type = ACPI_TYPE_INTEGER;
  125. obj_args[1].integer.value = port;
  126. obj_args[2].integer.type = ACPI_TYPE_INTEGER;
  127. obj_args[2].integer.value = val;
  128. argv4.type = ACPI_TYPE_PACKAGE;
  129. argv4.package.count = 3;
  130. argv4.package.elements = obj_args;
  131. obj = acpi_evaluate_dsm(ACPI_HANDLE(dsaf_dev->dev),
  132. hns_dsaf_acpi_dsm_uuid, 0, op_type, &argv4);
  133. if (!obj) {
  134. dev_warn(dsaf_dev->dev, "reset port_type%d port%d fail!",
  135. port_type, port);
  136. return;
  137. }
  138. ACPI_FREE(obj);
  139. }
  140. static void hns_dsaf_rst(struct dsaf_device *dsaf_dev, bool dereset)
  141. {
  142. u32 xbar_reg_addr;
  143. u32 nt_reg_addr;
  144. if (!dereset) {
  145. xbar_reg_addr = DSAF_SUB_SC_XBAR_RESET_REQ_REG;
  146. nt_reg_addr = DSAF_SUB_SC_NT_RESET_REQ_REG;
  147. } else {
  148. xbar_reg_addr = DSAF_SUB_SC_XBAR_RESET_DREQ_REG;
  149. nt_reg_addr = DSAF_SUB_SC_NT_RESET_DREQ_REG;
  150. }
  151. dsaf_write_sub(dsaf_dev, xbar_reg_addr, RESET_REQ_OR_DREQ);
  152. dsaf_write_sub(dsaf_dev, nt_reg_addr, RESET_REQ_OR_DREQ);
  153. }
  154. static void hns_dsaf_rst_acpi(struct dsaf_device *dsaf_dev, bool dereset)
  155. {
  156. hns_dsaf_acpi_srst_by_port(dsaf_dev, HNS_OP_RESET_FUNC,
  157. HNS_DSAF_RESET_FUNC,
  158. 0, dereset);
  159. }
  160. static void hns_dsaf_xge_srst_by_port(struct dsaf_device *dsaf_dev, u32 port,
  161. bool dereset)
  162. {
  163. u32 reg_val = 0;
  164. u32 reg_addr;
  165. if (port >= DSAF_XGE_NUM)
  166. return;
  167. reg_val |= RESET_REQ_OR_DREQ;
  168. reg_val |= 0x2082082 << dsaf_dev->mac_cb[port]->port_rst_off;
  169. if (!dereset)
  170. reg_addr = DSAF_SUB_SC_XGE_RESET_REQ_REG;
  171. else
  172. reg_addr = DSAF_SUB_SC_XGE_RESET_DREQ_REG;
  173. dsaf_write_sub(dsaf_dev, reg_addr, reg_val);
  174. }
  175. static void hns_dsaf_xge_srst_by_port_acpi(struct dsaf_device *dsaf_dev,
  176. u32 port, bool dereset)
  177. {
  178. hns_dsaf_acpi_srst_by_port(dsaf_dev, HNS_OP_RESET_FUNC,
  179. HNS_XGE_RESET_FUNC, port, dereset);
  180. }
  181. static void hns_dsaf_xge_core_srst_by_port(struct dsaf_device *dsaf_dev,
  182. u32 port, bool dereset)
  183. {
  184. u32 reg_val = 0;
  185. u32 reg_addr;
  186. if (port >= DSAF_XGE_NUM)
  187. return;
  188. reg_val |= XGMAC_TRX_CORE_SRST_M
  189. << dsaf_dev->mac_cb[port]->port_rst_off;
  190. if (!dereset)
  191. reg_addr = DSAF_SUB_SC_XGE_RESET_REQ_REG;
  192. else
  193. reg_addr = DSAF_SUB_SC_XGE_RESET_DREQ_REG;
  194. dsaf_write_sub(dsaf_dev, reg_addr, reg_val);
  195. }
  196. /**
  197. * hns_dsaf_srst_chns - reset dsaf channels
  198. * @dsaf_dev: dsaf device struct pointer
  199. * @msk: xbar channels mask value:
  200. * bit0-5 for xge0-5
  201. * bit6-11 for ppe0-5
  202. * bit12-17 for roce0-5
  203. * bit18-19 for com/dfx
  204. * @enable: false - request reset , true - drop reset
  205. */
  206. void hns_dsaf_srst_chns(struct dsaf_device *dsaf_dev, u32 msk, bool dereset)
  207. {
  208. u32 reg_addr;
  209. if (!dereset)
  210. reg_addr = DSAF_SUB_SC_DSAF_RESET_REQ_REG;
  211. else
  212. reg_addr = DSAF_SUB_SC_DSAF_RESET_DREQ_REG;
  213. dsaf_write_sub(dsaf_dev, reg_addr, msk);
  214. }
  215. /**
  216. * hns_dsaf_srst_chns - reset dsaf channels
  217. * @dsaf_dev: dsaf device struct pointer
  218. * @msk: xbar channels mask value:
  219. * bit0-5 for xge0-5
  220. * bit6-11 for ppe0-5
  221. * bit12-17 for roce0-5
  222. * bit18-19 for com/dfx
  223. * @enable: false - request reset , true - drop reset
  224. */
  225. void
  226. hns_dsaf_srst_chns_acpi(struct dsaf_device *dsaf_dev, u32 msk, bool dereset)
  227. {
  228. hns_dsaf_acpi_srst_by_port(dsaf_dev, HNS_OP_RESET_FUNC,
  229. HNS_DSAF_CHN_RESET_FUNC,
  230. msk, dereset);
  231. }
  232. void hns_dsaf_roce_srst(struct dsaf_device *dsaf_dev, bool dereset)
  233. {
  234. if (!dereset) {
  235. dsaf_write_sub(dsaf_dev, DSAF_SUB_SC_ROCEE_RESET_REQ_REG, 1);
  236. } else {
  237. dsaf_write_sub(dsaf_dev,
  238. DSAF_SUB_SC_ROCEE_CLK_DIS_REG, 1);
  239. dsaf_write_sub(dsaf_dev,
  240. DSAF_SUB_SC_ROCEE_RESET_DREQ_REG, 1);
  241. msleep(20);
  242. dsaf_write_sub(dsaf_dev, DSAF_SUB_SC_ROCEE_CLK_EN_REG, 1);
  243. }
  244. }
  245. void hns_dsaf_roce_srst_acpi(struct dsaf_device *dsaf_dev, bool dereset)
  246. {
  247. hns_dsaf_acpi_srst_by_port(dsaf_dev, HNS_OP_RESET_FUNC,
  248. HNS_ROCE_RESET_FUNC, 0, dereset);
  249. }
  250. static void
  251. hns_dsaf_xge_core_srst_by_port_acpi(struct dsaf_device *dsaf_dev,
  252. u32 port, bool dereset)
  253. {
  254. hns_dsaf_acpi_srst_by_port(dsaf_dev, HNS_OP_RESET_FUNC,
  255. HNS_XGE_CORE_RESET_FUNC, port, dereset);
  256. }
  257. static void hns_dsaf_ge_srst_by_port(struct dsaf_device *dsaf_dev, u32 port,
  258. bool dereset)
  259. {
  260. u32 reg_val_1;
  261. u32 reg_val_2;
  262. u32 port_rst_off;
  263. if (port >= DSAF_GE_NUM)
  264. return;
  265. if (!HNS_DSAF_IS_DEBUG(dsaf_dev)) {
  266. reg_val_1 = 0x1 << port;
  267. port_rst_off = dsaf_dev->mac_cb[port]->port_rst_off;
  268. /* there is difference between V1 and V2 in register.*/
  269. reg_val_2 = AE_IS_VER1(dsaf_dev->dsaf_ver) ?
  270. 0x1041041 : 0x2082082;
  271. reg_val_2 <<= port_rst_off;
  272. if (!dereset) {
  273. dsaf_write_sub(dsaf_dev, DSAF_SUB_SC_GE_RESET_REQ1_REG,
  274. reg_val_1);
  275. dsaf_write_sub(dsaf_dev, DSAF_SUB_SC_GE_RESET_REQ0_REG,
  276. reg_val_2);
  277. } else {
  278. dsaf_write_sub(dsaf_dev, DSAF_SUB_SC_GE_RESET_DREQ0_REG,
  279. reg_val_2);
  280. dsaf_write_sub(dsaf_dev, DSAF_SUB_SC_GE_RESET_DREQ1_REG,
  281. reg_val_1);
  282. }
  283. } else {
  284. reg_val_1 = 0x15540;
  285. reg_val_2 = AE_IS_VER1(dsaf_dev->dsaf_ver) ? 0x100 : 0x40;
  286. reg_val_1 <<= dsaf_dev->reset_offset;
  287. reg_val_2 <<= dsaf_dev->reset_offset;
  288. if (!dereset) {
  289. dsaf_write_sub(dsaf_dev, DSAF_SUB_SC_GE_RESET_REQ1_REG,
  290. reg_val_1);
  291. dsaf_write_sub(dsaf_dev, DSAF_SUB_SC_PPE_RESET_REQ_REG,
  292. reg_val_2);
  293. } else {
  294. dsaf_write_sub(dsaf_dev, DSAF_SUB_SC_GE_RESET_DREQ1_REG,
  295. reg_val_1);
  296. dsaf_write_sub(dsaf_dev, DSAF_SUB_SC_PPE_RESET_DREQ_REG,
  297. reg_val_2);
  298. }
  299. }
  300. }
  301. static void hns_dsaf_ge_srst_by_port_acpi(struct dsaf_device *dsaf_dev,
  302. u32 port, bool dereset)
  303. {
  304. hns_dsaf_acpi_srst_by_port(dsaf_dev, HNS_OP_RESET_FUNC,
  305. HNS_GE_RESET_FUNC, port, dereset);
  306. }
  307. static void hns_ppe_srst_by_port(struct dsaf_device *dsaf_dev, u32 port,
  308. bool dereset)
  309. {
  310. u32 reg_val = 0;
  311. u32 reg_addr;
  312. reg_val |= RESET_REQ_OR_DREQ << dsaf_dev->mac_cb[port]->port_rst_off;
  313. if (!dereset)
  314. reg_addr = DSAF_SUB_SC_PPE_RESET_REQ_REG;
  315. else
  316. reg_addr = DSAF_SUB_SC_PPE_RESET_DREQ_REG;
  317. dsaf_write_sub(dsaf_dev, reg_addr, reg_val);
  318. }
  319. static void
  320. hns_ppe_srst_by_port_acpi(struct dsaf_device *dsaf_dev, u32 port, bool dereset)
  321. {
  322. hns_dsaf_acpi_srst_by_port(dsaf_dev, HNS_OP_RESET_FUNC,
  323. HNS_PPE_RESET_FUNC, port, dereset);
  324. }
  325. static void hns_ppe_com_srst(struct dsaf_device *dsaf_dev, bool dereset)
  326. {
  327. u32 reg_val;
  328. u32 reg_addr;
  329. if (!(dev_of_node(dsaf_dev->dev)))
  330. return;
  331. if (!HNS_DSAF_IS_DEBUG(dsaf_dev)) {
  332. reg_val = RESET_REQ_OR_DREQ;
  333. if (!dereset)
  334. reg_addr = DSAF_SUB_SC_RCB_PPE_COM_RESET_REQ_REG;
  335. else
  336. reg_addr = DSAF_SUB_SC_RCB_PPE_COM_RESET_DREQ_REG;
  337. } else {
  338. reg_val = 0x100 << dsaf_dev->reset_offset;
  339. if (!dereset)
  340. reg_addr = DSAF_SUB_SC_PPE_RESET_REQ_REG;
  341. else
  342. reg_addr = DSAF_SUB_SC_PPE_RESET_DREQ_REG;
  343. }
  344. dsaf_write_sub(dsaf_dev, reg_addr, reg_val);
  345. }
  346. /**
  347. * hns_mac_get_sds_mode - get phy ifterface form serdes mode
  348. * @mac_cb: mac control block
  349. * retuen phy interface
  350. */
  351. static phy_interface_t hns_mac_get_phy_if(struct hns_mac_cb *mac_cb)
  352. {
  353. u32 mode;
  354. u32 reg;
  355. bool is_ver1 = AE_IS_VER1(mac_cb->dsaf_dev->dsaf_ver);
  356. int mac_id = mac_cb->mac_id;
  357. phy_interface_t phy_if;
  358. if (is_ver1) {
  359. if (HNS_DSAF_IS_DEBUG(mac_cb->dsaf_dev))
  360. return PHY_INTERFACE_MODE_SGMII;
  361. if (mac_id >= 0 && mac_id <= 3)
  362. reg = HNS_MAC_HILINK4_REG;
  363. else
  364. reg = HNS_MAC_HILINK3_REG;
  365. } else{
  366. if (!HNS_DSAF_IS_DEBUG(mac_cb->dsaf_dev) && mac_id <= 3)
  367. reg = HNS_MAC_HILINK4V2_REG;
  368. else
  369. reg = HNS_MAC_HILINK3V2_REG;
  370. }
  371. mode = dsaf_read_sub(mac_cb->dsaf_dev, reg);
  372. if (dsaf_get_bit(mode, mac_cb->port_mode_off))
  373. phy_if = PHY_INTERFACE_MODE_XGMII;
  374. else
  375. phy_if = PHY_INTERFACE_MODE_SGMII;
  376. return phy_if;
  377. }
  378. static phy_interface_t hns_mac_get_phy_if_acpi(struct hns_mac_cb *mac_cb)
  379. {
  380. phy_interface_t phy_if = PHY_INTERFACE_MODE_NA;
  381. union acpi_object *obj;
  382. union acpi_object obj_args, argv4;
  383. obj_args.integer.type = ACPI_TYPE_INTEGER;
  384. obj_args.integer.value = mac_cb->mac_id;
  385. argv4.type = ACPI_TYPE_PACKAGE,
  386. argv4.package.count = 1,
  387. argv4.package.elements = &obj_args,
  388. obj = acpi_evaluate_dsm(ACPI_HANDLE(mac_cb->dev),
  389. hns_dsaf_acpi_dsm_uuid, 0,
  390. HNS_OP_GET_PORT_TYPE_FUNC, &argv4);
  391. if (!obj || obj->type != ACPI_TYPE_INTEGER)
  392. return phy_if;
  393. phy_if = obj->integer.value ?
  394. PHY_INTERFACE_MODE_XGMII : PHY_INTERFACE_MODE_SGMII;
  395. dev_dbg(mac_cb->dev, "mac_id=%d, phy_if=%d\n", mac_cb->mac_id, phy_if);
  396. ACPI_FREE(obj);
  397. return phy_if;
  398. }
  399. int hns_mac_get_sfp_prsnt(struct hns_mac_cb *mac_cb, int *sfp_prsnt)
  400. {
  401. if (!mac_cb->cpld_ctrl)
  402. return -ENODEV;
  403. *sfp_prsnt = !dsaf_read_syscon(mac_cb->cpld_ctrl, mac_cb->cpld_ctrl_reg
  404. + MAC_SFP_PORT_OFFSET);
  405. return 0;
  406. }
  407. /**
  408. * hns_mac_config_sds_loopback - set loop back for serdes
  409. * @mac_cb: mac control block
  410. * retuen 0 == success
  411. */
  412. static int hns_mac_config_sds_loopback(struct hns_mac_cb *mac_cb, bool en)
  413. {
  414. const u8 lane_id[] = {
  415. 0, /* mac 0 -> lane 0 */
  416. 1, /* mac 1 -> lane 1 */
  417. 2, /* mac 2 -> lane 2 */
  418. 3, /* mac 3 -> lane 3 */
  419. 2, /* mac 4 -> lane 2 */
  420. 3, /* mac 5 -> lane 3 */
  421. 0, /* mac 6 -> lane 0 */
  422. 1 /* mac 7 -> lane 1 */
  423. };
  424. #define RX_CSR(lane, reg) ((0x4080 + (reg) * 0x0002 + (lane) * 0x0200) * 2)
  425. u64 reg_offset = RX_CSR(lane_id[mac_cb->mac_id], 0);
  426. int sfp_prsnt;
  427. int ret = hns_mac_get_sfp_prsnt(mac_cb, &sfp_prsnt);
  428. if (!mac_cb->phy_dev) {
  429. if (ret)
  430. pr_info("please confirm sfp is present or not\n");
  431. else
  432. if (!sfp_prsnt)
  433. pr_info("no sfp in this eth\n");
  434. }
  435. if (mac_cb->serdes_ctrl) {
  436. u32 origin;
  437. if (!AE_IS_VER1(mac_cb->dsaf_dev->dsaf_ver)) {
  438. #define HILINK_ACCESS_SEL_CFG 0x40008
  439. /* hilink4 & hilink3 use the same xge training and
  440. * xge u adaptor. There is a hilink access sel cfg
  441. * register to select which one to be configed
  442. */
  443. if ((!HNS_DSAF_IS_DEBUG(mac_cb->dsaf_dev)) &&
  444. (mac_cb->mac_id <= 3))
  445. dsaf_write_syscon(mac_cb->serdes_ctrl,
  446. HILINK_ACCESS_SEL_CFG, 0);
  447. else
  448. dsaf_write_syscon(mac_cb->serdes_ctrl,
  449. HILINK_ACCESS_SEL_CFG, 3);
  450. }
  451. origin = dsaf_read_syscon(mac_cb->serdes_ctrl, reg_offset);
  452. dsaf_set_field(origin, 1ull << 10, 10, en);
  453. dsaf_write_syscon(mac_cb->serdes_ctrl, reg_offset, origin);
  454. } else {
  455. u8 *base_addr = (u8 *)mac_cb->serdes_vaddr +
  456. (mac_cb->mac_id <= 3 ? 0x00280000 : 0x00200000);
  457. dsaf_set_reg_field(base_addr, reg_offset, 1ull << 10, 10, en);
  458. }
  459. return 0;
  460. }
  461. static int
  462. hns_mac_config_sds_loopback_acpi(struct hns_mac_cb *mac_cb, bool en)
  463. {
  464. union acpi_object *obj;
  465. union acpi_object obj_args[3], argv4;
  466. obj_args[0].integer.type = ACPI_TYPE_INTEGER;
  467. obj_args[0].integer.value = mac_cb->mac_id;
  468. obj_args[1].integer.type = ACPI_TYPE_INTEGER;
  469. obj_args[1].integer.value = !!en;
  470. argv4.type = ACPI_TYPE_PACKAGE;
  471. argv4.package.count = 2;
  472. argv4.package.elements = obj_args;
  473. obj = acpi_evaluate_dsm(ACPI_HANDLE(mac_cb->dsaf_dev->dev),
  474. hns_dsaf_acpi_dsm_uuid, 0,
  475. HNS_OP_SERDES_LP_FUNC, &argv4);
  476. if (!obj) {
  477. dev_warn(mac_cb->dsaf_dev->dev, "set port%d serdes lp fail!",
  478. mac_cb->mac_id);
  479. return -ENOTSUPP;
  480. }
  481. ACPI_FREE(obj);
  482. return 0;
  483. }
  484. struct dsaf_misc_op *hns_misc_op_get(struct dsaf_device *dsaf_dev)
  485. {
  486. struct dsaf_misc_op *misc_op;
  487. misc_op = devm_kzalloc(dsaf_dev->dev, sizeof(*misc_op), GFP_KERNEL);
  488. if (!misc_op)
  489. return NULL;
  490. if (dev_of_node(dsaf_dev->dev)) {
  491. misc_op->cpld_set_led = hns_cpld_set_led;
  492. misc_op->cpld_reset_led = cpld_led_reset;
  493. misc_op->cpld_set_led_id = cpld_set_led_id;
  494. misc_op->dsaf_reset = hns_dsaf_rst;
  495. misc_op->xge_srst = hns_dsaf_xge_srst_by_port;
  496. misc_op->xge_core_srst = hns_dsaf_xge_core_srst_by_port;
  497. misc_op->ge_srst = hns_dsaf_ge_srst_by_port;
  498. misc_op->ppe_srst = hns_ppe_srst_by_port;
  499. misc_op->ppe_comm_srst = hns_ppe_com_srst;
  500. misc_op->hns_dsaf_srst_chns = hns_dsaf_srst_chns;
  501. misc_op->hns_dsaf_roce_srst = hns_dsaf_roce_srst;
  502. misc_op->get_phy_if = hns_mac_get_phy_if;
  503. misc_op->get_sfp_prsnt = hns_mac_get_sfp_prsnt;
  504. misc_op->cfg_serdes_loopback = hns_mac_config_sds_loopback;
  505. } else if (is_acpi_node(dsaf_dev->dev->fwnode)) {
  506. misc_op->cpld_set_led = hns_cpld_set_led;
  507. misc_op->cpld_reset_led = cpld_led_reset;
  508. misc_op->cpld_set_led_id = cpld_set_led_id;
  509. misc_op->dsaf_reset = hns_dsaf_rst_acpi;
  510. misc_op->xge_srst = hns_dsaf_xge_srst_by_port_acpi;
  511. misc_op->xge_core_srst = hns_dsaf_xge_core_srst_by_port_acpi;
  512. misc_op->ge_srst = hns_dsaf_ge_srst_by_port_acpi;
  513. misc_op->ppe_srst = hns_ppe_srst_by_port_acpi;
  514. misc_op->ppe_comm_srst = hns_ppe_com_srst;
  515. misc_op->hns_dsaf_srst_chns = hns_dsaf_srst_chns_acpi;
  516. misc_op->hns_dsaf_roce_srst = hns_dsaf_roce_srst_acpi;
  517. misc_op->get_phy_if = hns_mac_get_phy_if_acpi;
  518. misc_op->get_sfp_prsnt = hns_mac_get_sfp_prsnt;
  519. misc_op->cfg_serdes_loopback = hns_mac_config_sds_loopback_acpi;
  520. } else {
  521. devm_kfree(dsaf_dev->dev, (void *)misc_op);
  522. misc_op = NULL;
  523. }
  524. return (void *)misc_op;
  525. }
  526. static int hns_dsaf_dev_match(struct device *dev, void *fwnode)
  527. {
  528. return dev->fwnode == fwnode;
  529. }
  530. struct
  531. platform_device *hns_dsaf_find_platform_device(struct fwnode_handle *fwnode)
  532. {
  533. struct device *dev;
  534. dev = bus_find_device(&platform_bus_type, NULL,
  535. fwnode, hns_dsaf_dev_match);
  536. return dev ? to_platform_device(dev) : NULL;
  537. }