hns_dsaf_mac.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175
  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 <linux/acpi.h>
  10. #include <linux/init.h>
  11. #include <linux/interrupt.h>
  12. #include <linux/kernel.h>
  13. #include <linux/mfd/syscon.h>
  14. #include <linux/module.h>
  15. #include <linux/netdevice.h>
  16. #include <linux/of.h>
  17. #include <linux/of_address.h>
  18. #include <linux/of_mdio.h>
  19. #include <linux/phy.h>
  20. #include <linux/platform_device.h>
  21. #include "hns_dsaf_main.h"
  22. #include "hns_dsaf_misc.h"
  23. #include "hns_dsaf_rcb.h"
  24. #define MAC_EN_FLAG_V 0xada0328
  25. static const u16 mac_phy_to_speed[] = {
  26. [PHY_INTERFACE_MODE_MII] = MAC_SPEED_100,
  27. [PHY_INTERFACE_MODE_GMII] = MAC_SPEED_1000,
  28. [PHY_INTERFACE_MODE_SGMII] = MAC_SPEED_1000,
  29. [PHY_INTERFACE_MODE_TBI] = MAC_SPEED_1000,
  30. [PHY_INTERFACE_MODE_RMII] = MAC_SPEED_100,
  31. [PHY_INTERFACE_MODE_RGMII] = MAC_SPEED_1000,
  32. [PHY_INTERFACE_MODE_RGMII_ID] = MAC_SPEED_1000,
  33. [PHY_INTERFACE_MODE_RGMII_RXID] = MAC_SPEED_1000,
  34. [PHY_INTERFACE_MODE_RGMII_TXID] = MAC_SPEED_1000,
  35. [PHY_INTERFACE_MODE_RTBI] = MAC_SPEED_1000,
  36. [PHY_INTERFACE_MODE_XGMII] = MAC_SPEED_10000
  37. };
  38. static const enum mac_mode g_mac_mode_100[] = {
  39. [PHY_INTERFACE_MODE_MII] = MAC_MODE_MII_100,
  40. [PHY_INTERFACE_MODE_RMII] = MAC_MODE_RMII_100
  41. };
  42. static const enum mac_mode g_mac_mode_1000[] = {
  43. [PHY_INTERFACE_MODE_GMII] = MAC_MODE_GMII_1000,
  44. [PHY_INTERFACE_MODE_SGMII] = MAC_MODE_SGMII_1000,
  45. [PHY_INTERFACE_MODE_TBI] = MAC_MODE_TBI_1000,
  46. [PHY_INTERFACE_MODE_RGMII] = MAC_MODE_RGMII_1000,
  47. [PHY_INTERFACE_MODE_RGMII_ID] = MAC_MODE_RGMII_1000,
  48. [PHY_INTERFACE_MODE_RGMII_RXID] = MAC_MODE_RGMII_1000,
  49. [PHY_INTERFACE_MODE_RGMII_TXID] = MAC_MODE_RGMII_1000,
  50. [PHY_INTERFACE_MODE_RTBI] = MAC_MODE_RTBI_1000
  51. };
  52. static enum mac_mode hns_get_enet_interface(const struct hns_mac_cb *mac_cb)
  53. {
  54. switch (mac_cb->max_speed) {
  55. case MAC_SPEED_100:
  56. return g_mac_mode_100[mac_cb->phy_if];
  57. case MAC_SPEED_1000:
  58. return g_mac_mode_1000[mac_cb->phy_if];
  59. case MAC_SPEED_10000:
  60. return MAC_MODE_XGMII_10000;
  61. default:
  62. return MAC_MODE_MII_100;
  63. }
  64. }
  65. void hns_mac_get_link_status(struct hns_mac_cb *mac_cb, u32 *link_status)
  66. {
  67. struct mac_driver *mac_ctrl_drv;
  68. int ret, sfp_prsnt;
  69. mac_ctrl_drv = hns_mac_get_drv(mac_cb);
  70. if (mac_ctrl_drv->get_link_status)
  71. mac_ctrl_drv->get_link_status(mac_ctrl_drv, link_status);
  72. else
  73. *link_status = 0;
  74. if (mac_cb->media_type == HNAE_MEDIA_TYPE_FIBER) {
  75. ret = mac_cb->dsaf_dev->misc_op->get_sfp_prsnt(mac_cb,
  76. &sfp_prsnt);
  77. if (!ret)
  78. *link_status = *link_status && sfp_prsnt;
  79. }
  80. mac_cb->link = *link_status;
  81. }
  82. int hns_mac_get_port_info(struct hns_mac_cb *mac_cb,
  83. u8 *auto_neg, u16 *speed, u8 *duplex)
  84. {
  85. struct mac_driver *mac_ctrl_drv;
  86. struct mac_info info;
  87. mac_ctrl_drv = hns_mac_get_drv(mac_cb);
  88. if (!mac_ctrl_drv->get_info)
  89. return -ENODEV;
  90. mac_ctrl_drv->get_info(mac_ctrl_drv, &info);
  91. if (auto_neg)
  92. *auto_neg = info.auto_neg;
  93. if (speed)
  94. *speed = info.speed;
  95. if (duplex)
  96. *duplex = info.duplex;
  97. return 0;
  98. }
  99. void hns_mac_adjust_link(struct hns_mac_cb *mac_cb, int speed, int duplex)
  100. {
  101. int ret;
  102. struct mac_driver *mac_ctrl_drv;
  103. mac_ctrl_drv = (struct mac_driver *)(mac_cb->priv.mac);
  104. mac_cb->speed = speed;
  105. mac_cb->half_duplex = !duplex;
  106. if (mac_ctrl_drv->adjust_link) {
  107. ret = mac_ctrl_drv->adjust_link(mac_ctrl_drv,
  108. (enum mac_speed)speed, duplex);
  109. if (ret) {
  110. dev_err(mac_cb->dev,
  111. "adjust_link failed, %s mac%d ret = %#x!\n",
  112. mac_cb->dsaf_dev->ae_dev.name,
  113. mac_cb->mac_id, ret);
  114. return;
  115. }
  116. }
  117. }
  118. /**
  119. *hns_mac_get_inner_port_num - get mac table inner port number
  120. *@mac_cb: mac device
  121. *@vmid: vm id
  122. *@port_num:port number
  123. *
  124. */
  125. int hns_mac_get_inner_port_num(struct hns_mac_cb *mac_cb, u8 vmid, u8 *port_num)
  126. {
  127. int q_num_per_vf, vf_num_per_port;
  128. int vm_queue_id;
  129. u8 tmp_port;
  130. if (mac_cb->dsaf_dev->dsaf_mode <= DSAF_MODE_ENABLE) {
  131. if (mac_cb->mac_id != DSAF_MAX_PORT_NUM) {
  132. dev_err(mac_cb->dev,
  133. "input invalid, %s mac%d vmid%d !\n",
  134. mac_cb->dsaf_dev->ae_dev.name,
  135. mac_cb->mac_id, vmid);
  136. return -EINVAL;
  137. }
  138. } else if (mac_cb->dsaf_dev->dsaf_mode < DSAF_MODE_MAX) {
  139. if (mac_cb->mac_id >= DSAF_MAX_PORT_NUM) {
  140. dev_err(mac_cb->dev,
  141. "input invalid, %s mac%d vmid%d!\n",
  142. mac_cb->dsaf_dev->ae_dev.name,
  143. mac_cb->mac_id, vmid);
  144. return -EINVAL;
  145. }
  146. } else {
  147. dev_err(mac_cb->dev, "dsaf mode invalid, %s mac%d!\n",
  148. mac_cb->dsaf_dev->ae_dev.name, mac_cb->mac_id);
  149. return -EINVAL;
  150. }
  151. if (vmid >= mac_cb->dsaf_dev->rcb_common[0]->max_vfn) {
  152. dev_err(mac_cb->dev, "input invalid, %s mac%d vmid%d !\n",
  153. mac_cb->dsaf_dev->ae_dev.name, mac_cb->mac_id, vmid);
  154. return -EINVAL;
  155. }
  156. q_num_per_vf = mac_cb->dsaf_dev->rcb_common[0]->max_q_per_vf;
  157. vf_num_per_port = mac_cb->dsaf_dev->rcb_common[0]->max_vfn;
  158. vm_queue_id = vmid * q_num_per_vf +
  159. vf_num_per_port * q_num_per_vf * mac_cb->mac_id;
  160. switch (mac_cb->dsaf_dev->dsaf_mode) {
  161. case DSAF_MODE_ENABLE_FIX:
  162. tmp_port = 0;
  163. break;
  164. case DSAF_MODE_DISABLE_FIX:
  165. tmp_port = 0;
  166. break;
  167. case DSAF_MODE_ENABLE_0VM:
  168. case DSAF_MODE_ENABLE_8VM:
  169. case DSAF_MODE_ENABLE_16VM:
  170. case DSAF_MODE_ENABLE_32VM:
  171. case DSAF_MODE_ENABLE_128VM:
  172. case DSAF_MODE_DISABLE_2PORT_8VM:
  173. case DSAF_MODE_DISABLE_2PORT_16VM:
  174. case DSAF_MODE_DISABLE_2PORT_64VM:
  175. case DSAF_MODE_DISABLE_6PORT_0VM:
  176. case DSAF_MODE_DISABLE_6PORT_2VM:
  177. case DSAF_MODE_DISABLE_6PORT_4VM:
  178. case DSAF_MODE_DISABLE_6PORT_16VM:
  179. tmp_port = vm_queue_id;
  180. break;
  181. default:
  182. dev_err(mac_cb->dev, "dsaf mode invalid, %s mac%d!\n",
  183. mac_cb->dsaf_dev->ae_dev.name, mac_cb->mac_id);
  184. return -EINVAL;
  185. }
  186. tmp_port += DSAF_BASE_INNER_PORT_NUM;
  187. *port_num = tmp_port;
  188. return 0;
  189. }
  190. /**
  191. *hns_mac_change_vf_addr - change vf mac address
  192. *@mac_cb: mac device
  193. *@vmid: vmid
  194. *@addr:mac address
  195. */
  196. int hns_mac_change_vf_addr(struct hns_mac_cb *mac_cb,
  197. u32 vmid, char *addr)
  198. {
  199. int ret;
  200. struct mac_driver *mac_ctrl_drv = hns_mac_get_drv(mac_cb);
  201. struct dsaf_device *dsaf_dev = mac_cb->dsaf_dev;
  202. struct dsaf_drv_mac_single_dest_entry mac_entry;
  203. struct mac_entry_idx *old_entry;
  204. old_entry = &mac_cb->addr_entry_idx[vmid];
  205. if (!HNS_DSAF_IS_DEBUG(dsaf_dev)) {
  206. memcpy(mac_entry.addr, addr, sizeof(mac_entry.addr));
  207. mac_entry.in_vlan_id = old_entry->vlan_id;
  208. mac_entry.in_port_num = mac_cb->mac_id;
  209. ret = hns_mac_get_inner_port_num(mac_cb, (u8)vmid,
  210. &mac_entry.port_num);
  211. if (ret)
  212. return ret;
  213. if ((old_entry->valid != 0) &&
  214. (memcmp(old_entry->addr,
  215. addr, sizeof(mac_entry.addr)) != 0)) {
  216. ret = hns_dsaf_del_mac_entry(dsaf_dev,
  217. old_entry->vlan_id,
  218. mac_cb->mac_id,
  219. old_entry->addr);
  220. if (ret)
  221. return ret;
  222. }
  223. ret = hns_dsaf_set_mac_uc_entry(dsaf_dev, &mac_entry);
  224. if (ret)
  225. return ret;
  226. }
  227. if ((mac_ctrl_drv->set_mac_addr) && (vmid == 0))
  228. mac_ctrl_drv->set_mac_addr(mac_cb->priv.mac, addr);
  229. memcpy(old_entry->addr, addr, sizeof(old_entry->addr));
  230. old_entry->valid = 1;
  231. return 0;
  232. }
  233. int hns_mac_add_uc_addr(struct hns_mac_cb *mac_cb, u8 vf_id,
  234. const unsigned char *addr)
  235. {
  236. struct dsaf_device *dsaf_dev = mac_cb->dsaf_dev;
  237. struct dsaf_drv_mac_single_dest_entry mac_entry;
  238. int ret;
  239. if (HNS_DSAF_IS_DEBUG(dsaf_dev))
  240. return -ENOSPC;
  241. memset(&mac_entry, 0, sizeof(mac_entry));
  242. memcpy(mac_entry.addr, addr, sizeof(mac_entry.addr));
  243. mac_entry.in_port_num = mac_cb->mac_id;
  244. ret = hns_mac_get_inner_port_num(mac_cb, vf_id, &mac_entry.port_num);
  245. if (ret)
  246. return ret;
  247. return hns_dsaf_set_mac_uc_entry(dsaf_dev, &mac_entry);
  248. }
  249. int hns_mac_rm_uc_addr(struct hns_mac_cb *mac_cb, u8 vf_id,
  250. const unsigned char *addr)
  251. {
  252. struct dsaf_device *dsaf_dev = mac_cb->dsaf_dev;
  253. struct dsaf_drv_mac_single_dest_entry mac_entry;
  254. int ret;
  255. if (HNS_DSAF_IS_DEBUG(dsaf_dev))
  256. return -ENOSPC;
  257. memset(&mac_entry, 0, sizeof(mac_entry));
  258. memcpy(mac_entry.addr, addr, sizeof(mac_entry.addr));
  259. mac_entry.in_port_num = mac_cb->mac_id;
  260. ret = hns_mac_get_inner_port_num(mac_cb, vf_id, &mac_entry.port_num);
  261. if (ret)
  262. return ret;
  263. return hns_dsaf_rm_mac_addr(dsaf_dev, &mac_entry);
  264. }
  265. int hns_mac_set_multi(struct hns_mac_cb *mac_cb,
  266. u32 port_num, char *addr, bool enable)
  267. {
  268. int ret;
  269. struct dsaf_device *dsaf_dev = mac_cb->dsaf_dev;
  270. struct dsaf_drv_mac_single_dest_entry mac_entry;
  271. if (!HNS_DSAF_IS_DEBUG(dsaf_dev) && addr) {
  272. memcpy(mac_entry.addr, addr, sizeof(mac_entry.addr));
  273. mac_entry.in_vlan_id = 0;/*vlan_id;*/
  274. mac_entry.in_port_num = mac_cb->mac_id;
  275. mac_entry.port_num = port_num;
  276. if (!enable)
  277. ret = hns_dsaf_del_mac_mc_port(dsaf_dev, &mac_entry);
  278. else
  279. ret = hns_dsaf_add_mac_mc_port(dsaf_dev, &mac_entry);
  280. if (ret) {
  281. dev_err(dsaf_dev->dev,
  282. "set mac mc port failed, %s mac%d ret = %#x!\n",
  283. mac_cb->dsaf_dev->ae_dev.name,
  284. mac_cb->mac_id, ret);
  285. return ret;
  286. }
  287. }
  288. return 0;
  289. }
  290. int hns_mac_clr_multicast(struct hns_mac_cb *mac_cb, int vfn)
  291. {
  292. struct dsaf_device *dsaf_dev = mac_cb->dsaf_dev;
  293. u8 port_num;
  294. int ret = hns_mac_get_inner_port_num(mac_cb, vfn, &port_num);
  295. if (ret)
  296. return ret;
  297. return hns_dsaf_clr_mac_mc_port(dsaf_dev, mac_cb->mac_id, port_num);
  298. }
  299. static void hns_mac_param_get(struct mac_params *param,
  300. struct hns_mac_cb *mac_cb)
  301. {
  302. param->vaddr = (void *)mac_cb->vaddr;
  303. param->mac_mode = hns_get_enet_interface(mac_cb);
  304. ether_addr_copy(param->addr, mac_cb->addr_entry_idx[0].addr);
  305. param->mac_id = mac_cb->mac_id;
  306. param->dev = mac_cb->dev;
  307. }
  308. /**
  309. *hns_mac_queue_config_bc_en - set broadcast rx&tx enable
  310. *@mac_cb: mac device
  311. *@queue: queue number
  312. *@en:enable
  313. *retuen 0 - success , negative --fail
  314. */
  315. static int hns_mac_port_config_bc_en(struct hns_mac_cb *mac_cb,
  316. u32 port_num, u16 vlan_id, bool enable)
  317. {
  318. int ret;
  319. struct dsaf_device *dsaf_dev = mac_cb->dsaf_dev;
  320. u8 addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  321. struct dsaf_drv_mac_single_dest_entry mac_entry;
  322. /* directy return ok in debug network mode */
  323. if (mac_cb->mac_type == HNAE_PORT_DEBUG)
  324. return 0;
  325. if (!HNS_DSAF_IS_DEBUG(dsaf_dev)) {
  326. memcpy(mac_entry.addr, addr, sizeof(mac_entry.addr));
  327. mac_entry.in_vlan_id = vlan_id;
  328. mac_entry.in_port_num = mac_cb->mac_id;
  329. mac_entry.port_num = port_num;
  330. if (!enable)
  331. ret = hns_dsaf_del_mac_mc_port(dsaf_dev, &mac_entry);
  332. else
  333. ret = hns_dsaf_add_mac_mc_port(dsaf_dev, &mac_entry);
  334. return ret;
  335. }
  336. return 0;
  337. }
  338. /**
  339. *hns_mac_vm_config_bc_en - set broadcast rx&tx enable
  340. *@mac_cb: mac device
  341. *@vmid: vm id
  342. *@en:enable
  343. *retuen 0 - success , negative --fail
  344. */
  345. int hns_mac_vm_config_bc_en(struct hns_mac_cb *mac_cb, u32 vmid, bool enable)
  346. {
  347. int ret;
  348. struct dsaf_device *dsaf_dev = mac_cb->dsaf_dev;
  349. u8 port_num;
  350. u8 addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  351. struct mac_entry_idx *uc_mac_entry;
  352. struct dsaf_drv_mac_single_dest_entry mac_entry;
  353. if (mac_cb->mac_type == HNAE_PORT_DEBUG)
  354. return 0;
  355. uc_mac_entry = &mac_cb->addr_entry_idx[vmid];
  356. if (!HNS_DSAF_IS_DEBUG(dsaf_dev)) {
  357. memcpy(mac_entry.addr, addr, sizeof(mac_entry.addr));
  358. mac_entry.in_vlan_id = uc_mac_entry->vlan_id;
  359. mac_entry.in_port_num = mac_cb->mac_id;
  360. ret = hns_mac_get_inner_port_num(mac_cb, vmid, &port_num);
  361. if (ret)
  362. return ret;
  363. mac_entry.port_num = port_num;
  364. if (!enable)
  365. ret = hns_dsaf_del_mac_mc_port(dsaf_dev, &mac_entry);
  366. else
  367. ret = hns_dsaf_add_mac_mc_port(dsaf_dev, &mac_entry);
  368. return ret;
  369. }
  370. return 0;
  371. }
  372. void hns_mac_reset(struct hns_mac_cb *mac_cb)
  373. {
  374. struct mac_driver *drv = hns_mac_get_drv(mac_cb);
  375. bool is_ver1 = AE_IS_VER1(mac_cb->dsaf_dev->dsaf_ver);
  376. drv->mac_init(drv);
  377. if (drv->config_max_frame_length)
  378. drv->config_max_frame_length(drv, mac_cb->max_frm);
  379. if (drv->set_tx_auto_pause_frames)
  380. drv->set_tx_auto_pause_frames(drv, mac_cb->tx_pause_frm_time);
  381. if (drv->set_an_mode)
  382. drv->set_an_mode(drv, 1);
  383. if (drv->mac_pausefrm_cfg) {
  384. if (mac_cb->mac_type == HNAE_PORT_DEBUG)
  385. drv->mac_pausefrm_cfg(drv, !is_ver1, !is_ver1);
  386. else /* mac rx must disable, dsaf pfc close instead of it*/
  387. drv->mac_pausefrm_cfg(drv, 0, 1);
  388. }
  389. }
  390. int hns_mac_set_mtu(struct hns_mac_cb *mac_cb, u32 new_mtu, u32 buf_size)
  391. {
  392. struct mac_driver *drv = hns_mac_get_drv(mac_cb);
  393. u32 new_frm = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
  394. u32 max_frm = AE_IS_VER1(mac_cb->dsaf_dev->dsaf_ver) ?
  395. MAC_MAX_MTU : MAC_MAX_MTU_V2;
  396. if (mac_cb->mac_type == HNAE_PORT_DEBUG)
  397. max_frm = MAC_MAX_MTU_DBG;
  398. if (new_frm > HNS_RCB_RING_MAX_BD_PER_PKT * buf_size)
  399. return -EINVAL;
  400. if (!drv->config_max_frame_length)
  401. return -ECHILD;
  402. /* adjust max frame to be at least the size of a standard frame */
  403. if (new_frm < (ETH_FRAME_LEN + ETH_FCS_LEN + VLAN_HLEN))
  404. new_frm = (ETH_FRAME_LEN + ETH_FCS_LEN + VLAN_HLEN);
  405. drv->config_max_frame_length(drv, new_frm);
  406. mac_cb->max_frm = new_frm;
  407. return 0;
  408. }
  409. void hns_mac_start(struct hns_mac_cb *mac_cb)
  410. {
  411. struct mac_driver *mac_drv = hns_mac_get_drv(mac_cb);
  412. /* for virt */
  413. if (mac_drv->mac_en_flg == MAC_EN_FLAG_V) {
  414. /*plus 1 when the virtual mac has been enabled */
  415. mac_drv->virt_dev_num += 1;
  416. return;
  417. }
  418. if (mac_drv->mac_enable) {
  419. mac_drv->mac_enable(mac_cb->priv.mac, MAC_COMM_MODE_RX_AND_TX);
  420. mac_drv->mac_en_flg = MAC_EN_FLAG_V;
  421. }
  422. }
  423. void hns_mac_stop(struct hns_mac_cb *mac_cb)
  424. {
  425. struct mac_driver *mac_ctrl_drv = hns_mac_get_drv(mac_cb);
  426. /*modified for virtualization */
  427. if (mac_ctrl_drv->virt_dev_num > 0) {
  428. mac_ctrl_drv->virt_dev_num -= 1;
  429. if (mac_ctrl_drv->virt_dev_num > 0)
  430. return;
  431. }
  432. if (mac_ctrl_drv->mac_disable)
  433. mac_ctrl_drv->mac_disable(mac_cb->priv.mac,
  434. MAC_COMM_MODE_RX_AND_TX);
  435. mac_ctrl_drv->mac_en_flg = 0;
  436. mac_cb->link = 0;
  437. mac_cb->dsaf_dev->misc_op->cpld_reset_led(mac_cb);
  438. }
  439. /**
  440. * hns_mac_get_autoneg - get auto autonegotiation
  441. * @mac_cb: mac control block
  442. * @enable: enable or not
  443. * retuen 0 - success , negative --fail
  444. */
  445. void hns_mac_get_autoneg(struct hns_mac_cb *mac_cb, u32 *auto_neg)
  446. {
  447. struct mac_driver *mac_ctrl_drv = hns_mac_get_drv(mac_cb);
  448. if (mac_ctrl_drv->autoneg_stat)
  449. mac_ctrl_drv->autoneg_stat(mac_ctrl_drv, auto_neg);
  450. else
  451. *auto_neg = 0;
  452. }
  453. /**
  454. * hns_mac_get_pauseparam - set rx & tx pause parameter
  455. * @mac_cb: mac control block
  456. * @rx_en: rx enable status
  457. * @tx_en: tx enable status
  458. * retuen 0 - success , negative --fail
  459. */
  460. void hns_mac_get_pauseparam(struct hns_mac_cb *mac_cb, u32 *rx_en, u32 *tx_en)
  461. {
  462. struct mac_driver *mac_ctrl_drv = hns_mac_get_drv(mac_cb);
  463. if (mac_ctrl_drv->get_pause_enable) {
  464. mac_ctrl_drv->get_pause_enable(mac_ctrl_drv, rx_en, tx_en);
  465. } else {
  466. *rx_en = 0;
  467. *tx_en = 0;
  468. }
  469. }
  470. /**
  471. * hns_mac_set_autoneg - set auto autonegotiation
  472. * @mac_cb: mac control block
  473. * @enable: enable or not
  474. * retuen 0 - success , negative --fail
  475. */
  476. int hns_mac_set_autoneg(struct hns_mac_cb *mac_cb, u8 enable)
  477. {
  478. struct mac_driver *mac_ctrl_drv = hns_mac_get_drv(mac_cb);
  479. if (mac_cb->phy_if == PHY_INTERFACE_MODE_XGMII && enable) {
  480. dev_err(mac_cb->dev, "enabling autoneg is not allowed!\n");
  481. return -ENOTSUPP;
  482. }
  483. if (mac_ctrl_drv->set_an_mode)
  484. mac_ctrl_drv->set_an_mode(mac_ctrl_drv, enable);
  485. return 0;
  486. }
  487. /**
  488. * hns_mac_set_autoneg - set rx & tx pause parameter
  489. * @mac_cb: mac control block
  490. * @rx_en: rx enable or not
  491. * @tx_en: tx enable or not
  492. * return 0 - success , negative --fail
  493. */
  494. int hns_mac_set_pauseparam(struct hns_mac_cb *mac_cb, u32 rx_en, u32 tx_en)
  495. {
  496. struct mac_driver *mac_ctrl_drv = hns_mac_get_drv(mac_cb);
  497. bool is_ver1 = AE_IS_VER1(mac_cb->dsaf_dev->dsaf_ver);
  498. if (mac_cb->mac_type == HNAE_PORT_DEBUG) {
  499. if (is_ver1 && (tx_en || rx_en)) {
  500. dev_err(mac_cb->dev, "macv1 can't enable tx/rx_pause!\n");
  501. return -EINVAL;
  502. }
  503. }
  504. if (mac_ctrl_drv->mac_pausefrm_cfg)
  505. mac_ctrl_drv->mac_pausefrm_cfg(mac_ctrl_drv, rx_en, tx_en);
  506. return 0;
  507. }
  508. /**
  509. * hns_mac_init_ex - mac init
  510. * @mac_cb: mac control block
  511. * retuen 0 - success , negative --fail
  512. */
  513. static int hns_mac_init_ex(struct hns_mac_cb *mac_cb)
  514. {
  515. int ret;
  516. struct mac_params param;
  517. struct mac_driver *drv;
  518. hns_dsaf_fix_mac_mode(mac_cb);
  519. memset(&param, 0, sizeof(struct mac_params));
  520. hns_mac_param_get(&param, mac_cb);
  521. if (MAC_SPEED_FROM_MODE(param.mac_mode) < MAC_SPEED_10000)
  522. drv = (struct mac_driver *)hns_gmac_config(mac_cb, &param);
  523. else
  524. drv = (struct mac_driver *)hns_xgmac_config(mac_cb, &param);
  525. if (!drv)
  526. return -ENOMEM;
  527. mac_cb->priv.mac = (void *)drv;
  528. hns_mac_reset(mac_cb);
  529. hns_mac_adjust_link(mac_cb, mac_cb->speed, !mac_cb->half_duplex);
  530. ret = hns_mac_port_config_bc_en(mac_cb, mac_cb->mac_id, 0, true);
  531. if (ret)
  532. goto free_mac_drv;
  533. return 0;
  534. free_mac_drv:
  535. drv->mac_free(mac_cb->priv.mac);
  536. mac_cb->priv.mac = NULL;
  537. return ret;
  538. }
  539. static int
  540. hns_mac_phy_parse_addr(struct device *dev, struct fwnode_handle *fwnode)
  541. {
  542. u32 addr;
  543. int ret;
  544. ret = fwnode_property_read_u32(fwnode, "phy-addr", &addr);
  545. if (ret) {
  546. dev_err(dev, "has invalid PHY address ret:%d\n", ret);
  547. return ret;
  548. }
  549. if (addr >= PHY_MAX_ADDR) {
  550. dev_err(dev, "PHY address %i is too large\n", addr);
  551. return -EINVAL;
  552. }
  553. return addr;
  554. }
  555. static int
  556. hns_mac_register_phydev(struct mii_bus *mdio, struct hns_mac_cb *mac_cb,
  557. u32 addr)
  558. {
  559. struct phy_device *phy;
  560. const char *phy_type;
  561. bool is_c45;
  562. int rc;
  563. rc = fwnode_property_read_string(mac_cb->fw_port,
  564. "phy-mode", &phy_type);
  565. if (rc < 0)
  566. return rc;
  567. if (!strcmp(phy_type, phy_modes(PHY_INTERFACE_MODE_XGMII)))
  568. is_c45 = 1;
  569. else if (!strcmp(phy_type, phy_modes(PHY_INTERFACE_MODE_SGMII)))
  570. is_c45 = 0;
  571. else
  572. return -ENODATA;
  573. phy = get_phy_device(mdio, addr, is_c45);
  574. if (!phy || IS_ERR(phy))
  575. return -EIO;
  576. phy->irq = mdio->irq[addr];
  577. /* All data is now stored in the phy struct;
  578. * register it
  579. */
  580. rc = phy_device_register(phy);
  581. if (rc) {
  582. phy_device_free(phy);
  583. dev_err(&mdio->dev, "registered phy fail at address %i\n",
  584. addr);
  585. return -ENODEV;
  586. }
  587. mac_cb->phy_dev = phy;
  588. dev_dbg(&mdio->dev, "registered phy at address %i\n", addr);
  589. return 0;
  590. }
  591. static int hns_mac_register_phy(struct hns_mac_cb *mac_cb)
  592. {
  593. struct acpi_reference_args args;
  594. struct platform_device *pdev;
  595. struct mii_bus *mii_bus;
  596. int rc;
  597. int addr;
  598. /* Loop over the child nodes and register a phy_device for each one */
  599. if (!to_acpi_device_node(mac_cb->fw_port))
  600. return -ENODEV;
  601. rc = acpi_node_get_property_reference(
  602. mac_cb->fw_port, "mdio-node", 0, &args);
  603. if (rc)
  604. return rc;
  605. addr = hns_mac_phy_parse_addr(mac_cb->dev, mac_cb->fw_port);
  606. if (addr < 0)
  607. return addr;
  608. /* dev address in adev */
  609. pdev = hns_dsaf_find_platform_device(acpi_fwnode_handle(args.adev));
  610. if (!pdev) {
  611. dev_err(mac_cb->dev, "mac%d mdio pdev is NULL\n",
  612. mac_cb->mac_id);
  613. return -EINVAL;
  614. }
  615. mii_bus = platform_get_drvdata(pdev);
  616. if (!mii_bus) {
  617. dev_err(mac_cb->dev,
  618. "mac%d mdio is NULL, dsaf will probe again later\n",
  619. mac_cb->mac_id);
  620. return -EPROBE_DEFER;
  621. }
  622. rc = hns_mac_register_phydev(mii_bus, mac_cb, addr);
  623. if (!rc)
  624. dev_dbg(mac_cb->dev, "mac%d register phy addr:%d\n",
  625. mac_cb->mac_id, addr);
  626. return rc;
  627. }
  628. #define MAC_MEDIA_TYPE_MAX_LEN 16
  629. static const struct {
  630. enum hnae_media_type value;
  631. const char *name;
  632. } media_type_defs[] = {
  633. {HNAE_MEDIA_TYPE_UNKNOWN, "unknown" },
  634. {HNAE_MEDIA_TYPE_FIBER, "fiber" },
  635. {HNAE_MEDIA_TYPE_COPPER, "copper" },
  636. {HNAE_MEDIA_TYPE_BACKPLANE, "backplane" },
  637. };
  638. /**
  639. *hns_mac_get_info - get mac information from device node
  640. *@mac_cb: mac device
  641. *@np:device node
  642. * return: 0 --success, negative --fail
  643. */
  644. static int hns_mac_get_info(struct hns_mac_cb *mac_cb)
  645. {
  646. struct device_node *np;
  647. struct regmap *syscon;
  648. struct of_phandle_args cpld_args;
  649. const char *media_type;
  650. u32 i;
  651. u32 ret;
  652. mac_cb->link = false;
  653. mac_cb->half_duplex = false;
  654. mac_cb->media_type = HNAE_MEDIA_TYPE_UNKNOWN;
  655. mac_cb->speed = mac_phy_to_speed[mac_cb->phy_if];
  656. mac_cb->max_speed = mac_cb->speed;
  657. if (mac_cb->phy_if == PHY_INTERFACE_MODE_SGMII) {
  658. mac_cb->if_support = MAC_GMAC_SUPPORTED;
  659. mac_cb->if_support |= SUPPORTED_1000baseT_Full;
  660. } else if (mac_cb->phy_if == PHY_INTERFACE_MODE_XGMII) {
  661. mac_cb->if_support = SUPPORTED_10000baseR_FEC;
  662. mac_cb->if_support |= SUPPORTED_10000baseKR_Full;
  663. }
  664. mac_cb->max_frm = MAC_DEFAULT_MTU;
  665. mac_cb->tx_pause_frm_time = MAC_DEFAULT_PAUSE_TIME;
  666. mac_cb->port_rst_off = mac_cb->mac_id;
  667. mac_cb->port_mode_off = 0;
  668. /* if the dsaf node doesn't contain a port subnode, get phy-handle
  669. * from dsaf node
  670. */
  671. if (!mac_cb->fw_port) {
  672. np = of_parse_phandle(mac_cb->dev->of_node, "phy-handle",
  673. mac_cb->mac_id);
  674. mac_cb->phy_dev = of_phy_find_device(np);
  675. if (mac_cb->phy_dev) {
  676. /* refcount is held by of_phy_find_device()
  677. * if the phy_dev is found
  678. */
  679. put_device(&mac_cb->phy_dev->mdio.dev);
  680. dev_dbg(mac_cb->dev, "mac%d phy_node: %s\n",
  681. mac_cb->mac_id, np->name);
  682. }
  683. of_node_put(np);
  684. return 0;
  685. }
  686. if (is_of_node(mac_cb->fw_port)) {
  687. /* parse property from port subnode in dsaf */
  688. np = of_parse_phandle(to_of_node(mac_cb->fw_port),
  689. "phy-handle", 0);
  690. mac_cb->phy_dev = of_phy_find_device(np);
  691. if (mac_cb->phy_dev) {
  692. /* refcount is held by of_phy_find_device()
  693. * if the phy_dev is found
  694. */
  695. put_device(&mac_cb->phy_dev->mdio.dev);
  696. dev_dbg(mac_cb->dev, "mac%d phy_node: %s\n",
  697. mac_cb->mac_id, np->name);
  698. }
  699. of_node_put(np);
  700. np = of_parse_phandle(to_of_node(mac_cb->fw_port),
  701. "serdes-syscon", 0);
  702. syscon = syscon_node_to_regmap(np);
  703. of_node_put(np);
  704. if (IS_ERR_OR_NULL(syscon)) {
  705. dev_err(mac_cb->dev, "serdes-syscon is needed!\n");
  706. return -EINVAL;
  707. }
  708. mac_cb->serdes_ctrl = syscon;
  709. ret = fwnode_property_read_u32(mac_cb->fw_port,
  710. "port-rst-offset",
  711. &mac_cb->port_rst_off);
  712. if (ret) {
  713. dev_dbg(mac_cb->dev,
  714. "mac%d port-rst-offset not found, use default value.\n",
  715. mac_cb->mac_id);
  716. }
  717. ret = fwnode_property_read_u32(mac_cb->fw_port,
  718. "port-mode-offset",
  719. &mac_cb->port_mode_off);
  720. if (ret) {
  721. dev_dbg(mac_cb->dev,
  722. "mac%d port-mode-offset not found, use default value.\n",
  723. mac_cb->mac_id);
  724. }
  725. ret = of_parse_phandle_with_fixed_args(
  726. to_of_node(mac_cb->fw_port), "cpld-syscon", 1, 0,
  727. &cpld_args);
  728. if (ret) {
  729. dev_dbg(mac_cb->dev, "mac%d no cpld-syscon found.\n",
  730. mac_cb->mac_id);
  731. mac_cb->cpld_ctrl = NULL;
  732. } else {
  733. syscon = syscon_node_to_regmap(cpld_args.np);
  734. if (IS_ERR_OR_NULL(syscon)) {
  735. dev_dbg(mac_cb->dev, "no cpld-syscon found!\n");
  736. mac_cb->cpld_ctrl = NULL;
  737. } else {
  738. mac_cb->cpld_ctrl = syscon;
  739. mac_cb->cpld_ctrl_reg = cpld_args.args[0];
  740. }
  741. }
  742. } else if (is_acpi_node(mac_cb->fw_port)) {
  743. ret = hns_mac_register_phy(mac_cb);
  744. /*
  745. * Mac can work well if there is phy or not.If the port don't
  746. * connect with phy, the return value will be ignored. Only
  747. * when there is phy but can't find mdio bus, the return value
  748. * will be handled.
  749. */
  750. if (ret == -EPROBE_DEFER)
  751. return ret;
  752. } else {
  753. dev_err(mac_cb->dev, "mac%d cannot find phy node\n",
  754. mac_cb->mac_id);
  755. }
  756. if (!fwnode_property_read_string(mac_cb->fw_port, "media-type",
  757. &media_type)) {
  758. for (i = 0; i < ARRAY_SIZE(media_type_defs); i++) {
  759. if (!strncmp(media_type_defs[i].name, media_type,
  760. MAC_MEDIA_TYPE_MAX_LEN)) {
  761. mac_cb->media_type = media_type_defs[i].value;
  762. break;
  763. }
  764. }
  765. }
  766. if (fwnode_property_read_u8_array(mac_cb->fw_port, "mc-mac-mask",
  767. mac_cb->mc_mask, ETH_ALEN)) {
  768. dev_warn(mac_cb->dev,
  769. "no mc-mac-mask property, set to default value.\n");
  770. eth_broadcast_addr(mac_cb->mc_mask);
  771. }
  772. return 0;
  773. }
  774. /**
  775. * hns_mac_get_mode - get mac mode
  776. * @phy_if: phy interface
  777. * retuen 0 - gmac, 1 - xgmac , negative --fail
  778. */
  779. static int hns_mac_get_mode(phy_interface_t phy_if)
  780. {
  781. switch (phy_if) {
  782. case PHY_INTERFACE_MODE_SGMII:
  783. return MAC_GMAC_IDX;
  784. case PHY_INTERFACE_MODE_XGMII:
  785. return MAC_XGMAC_IDX;
  786. default:
  787. return -EINVAL;
  788. }
  789. }
  790. u8 __iomem *hns_mac_get_vaddr(struct dsaf_device *dsaf_dev,
  791. struct hns_mac_cb *mac_cb, u32 mac_mode_idx)
  792. {
  793. u8 __iomem *base = dsaf_dev->io_base;
  794. int mac_id = mac_cb->mac_id;
  795. if (mac_cb->mac_type == HNAE_PORT_SERVICE)
  796. return base + 0x40000 + mac_id * 0x4000 -
  797. mac_mode_idx * 0x20000;
  798. else
  799. return dsaf_dev->ppe_base + 0x1000;
  800. }
  801. /**
  802. * hns_mac_get_cfg - get mac cfg from dtb or acpi table
  803. * @dsaf_dev: dsa fabric device struct pointer
  804. * @mac_cb: mac control block
  805. * return 0 - success , negative --fail
  806. */
  807. int hns_mac_get_cfg(struct dsaf_device *dsaf_dev, struct hns_mac_cb *mac_cb)
  808. {
  809. int ret;
  810. u32 mac_mode_idx;
  811. mac_cb->dsaf_dev = dsaf_dev;
  812. mac_cb->dev = dsaf_dev->dev;
  813. mac_cb->sys_ctl_vaddr = dsaf_dev->sc_base;
  814. mac_cb->serdes_vaddr = dsaf_dev->sds_base;
  815. mac_cb->sfp_prsnt = 0;
  816. mac_cb->txpkt_for_led = 0;
  817. mac_cb->rxpkt_for_led = 0;
  818. if (!HNS_DSAF_IS_DEBUG(dsaf_dev))
  819. mac_cb->mac_type = HNAE_PORT_SERVICE;
  820. else
  821. mac_cb->mac_type = HNAE_PORT_DEBUG;
  822. mac_cb->phy_if = dsaf_dev->misc_op->get_phy_if(mac_cb);
  823. ret = hns_mac_get_mode(mac_cb->phy_if);
  824. if (ret < 0) {
  825. dev_err(dsaf_dev->dev,
  826. "hns_mac_get_mode failed, mac%d ret = %#x!\n",
  827. mac_cb->mac_id, ret);
  828. return ret;
  829. }
  830. mac_mode_idx = (u32)ret;
  831. ret = hns_mac_get_info(mac_cb);
  832. if (ret)
  833. return ret;
  834. mac_cb->dsaf_dev->misc_op->cpld_reset_led(mac_cb);
  835. mac_cb->vaddr = hns_mac_get_vaddr(dsaf_dev, mac_cb, mac_mode_idx);
  836. return 0;
  837. }
  838. static int hns_mac_get_max_port_num(struct dsaf_device *dsaf_dev)
  839. {
  840. if (HNS_DSAF_IS_DEBUG(dsaf_dev))
  841. return 1;
  842. else
  843. return DSAF_MAX_PORT_NUM;
  844. }
  845. /**
  846. * hns_mac_init - init mac
  847. * @dsaf_dev: dsa fabric device struct pointer
  848. * return 0 - success , negative --fail
  849. */
  850. int hns_mac_init(struct dsaf_device *dsaf_dev)
  851. {
  852. bool found = false;
  853. int ret;
  854. u32 port_id;
  855. int max_port_num = hns_mac_get_max_port_num(dsaf_dev);
  856. struct hns_mac_cb *mac_cb;
  857. struct fwnode_handle *child;
  858. device_for_each_child_node(dsaf_dev->dev, child) {
  859. ret = fwnode_property_read_u32(child, "reg", &port_id);
  860. if (ret) {
  861. dev_err(dsaf_dev->dev,
  862. "get reg fail, ret=%d!\n", ret);
  863. return ret;
  864. }
  865. if (port_id >= max_port_num) {
  866. dev_err(dsaf_dev->dev,
  867. "reg(%u) out of range!\n", port_id);
  868. return -EINVAL;
  869. }
  870. mac_cb = devm_kzalloc(dsaf_dev->dev, sizeof(*mac_cb),
  871. GFP_KERNEL);
  872. if (!mac_cb)
  873. return -ENOMEM;
  874. mac_cb->fw_port = child;
  875. mac_cb->mac_id = (u8)port_id;
  876. dsaf_dev->mac_cb[port_id] = mac_cb;
  877. found = true;
  878. }
  879. /* if don't get any port subnode from dsaf node
  880. * will init all port then, this is compatible with the old dts
  881. */
  882. if (!found) {
  883. for (port_id = 0; port_id < max_port_num; port_id++) {
  884. mac_cb = devm_kzalloc(dsaf_dev->dev, sizeof(*mac_cb),
  885. GFP_KERNEL);
  886. if (!mac_cb)
  887. return -ENOMEM;
  888. mac_cb->mac_id = port_id;
  889. dsaf_dev->mac_cb[port_id] = mac_cb;
  890. }
  891. }
  892. /* init mac_cb for all port */
  893. for (port_id = 0; port_id < max_port_num; port_id++) {
  894. mac_cb = dsaf_dev->mac_cb[port_id];
  895. if (!mac_cb)
  896. continue;
  897. ret = hns_mac_get_cfg(dsaf_dev, mac_cb);
  898. if (ret)
  899. return ret;
  900. ret = hns_mac_init_ex(mac_cb);
  901. if (ret)
  902. return ret;
  903. }
  904. return 0;
  905. }
  906. void hns_mac_uninit(struct dsaf_device *dsaf_dev)
  907. {
  908. int i;
  909. int max_port_num = hns_mac_get_max_port_num(dsaf_dev);
  910. for (i = 0; i < max_port_num; i++) {
  911. dsaf_dev->misc_op->cpld_reset_led(dsaf_dev->mac_cb[i]);
  912. dsaf_dev->mac_cb[i] = NULL;
  913. }
  914. }
  915. int hns_mac_config_mac_loopback(struct hns_mac_cb *mac_cb,
  916. enum hnae_loop loop, int en)
  917. {
  918. int ret;
  919. struct mac_driver *drv = hns_mac_get_drv(mac_cb);
  920. if (drv->config_loopback)
  921. ret = drv->config_loopback(drv, loop, en);
  922. else
  923. ret = -ENOTSUPP;
  924. return ret;
  925. }
  926. void hns_mac_update_stats(struct hns_mac_cb *mac_cb)
  927. {
  928. struct mac_driver *mac_ctrl_drv = hns_mac_get_drv(mac_cb);
  929. mac_ctrl_drv->update_stats(mac_ctrl_drv);
  930. }
  931. void hns_mac_get_stats(struct hns_mac_cb *mac_cb, u64 *data)
  932. {
  933. struct mac_driver *mac_ctrl_drv = hns_mac_get_drv(mac_cb);
  934. mac_ctrl_drv->get_ethtool_stats(mac_ctrl_drv, data);
  935. }
  936. void hns_mac_get_strings(struct hns_mac_cb *mac_cb,
  937. int stringset, u8 *data)
  938. {
  939. struct mac_driver *mac_ctrl_drv = hns_mac_get_drv(mac_cb);
  940. mac_ctrl_drv->get_strings(stringset, data);
  941. }
  942. int hns_mac_get_sset_count(struct hns_mac_cb *mac_cb, int stringset)
  943. {
  944. struct mac_driver *mac_ctrl_drv = hns_mac_get_drv(mac_cb);
  945. return mac_ctrl_drv->get_sset_count(stringset);
  946. }
  947. void hns_mac_set_promisc(struct hns_mac_cb *mac_cb, u8 en)
  948. {
  949. struct mac_driver *mac_ctrl_drv = hns_mac_get_drv(mac_cb);
  950. hns_dsaf_set_promisc_tcam(mac_cb->dsaf_dev, mac_cb->mac_id, !!en);
  951. if (mac_ctrl_drv->set_promiscuous)
  952. mac_ctrl_drv->set_promiscuous(mac_ctrl_drv, en);
  953. }
  954. int hns_mac_get_regs_count(struct hns_mac_cb *mac_cb)
  955. {
  956. struct mac_driver *mac_ctrl_drv = hns_mac_get_drv(mac_cb);
  957. return mac_ctrl_drv->get_regs_count();
  958. }
  959. void hns_mac_get_regs(struct hns_mac_cb *mac_cb, void *data)
  960. {
  961. struct mac_driver *mac_ctrl_drv = hns_mac_get_drv(mac_cb);
  962. mac_ctrl_drv->get_regs(mac_ctrl_drv, data);
  963. }
  964. void hns_set_led_opt(struct hns_mac_cb *mac_cb)
  965. {
  966. int nic_data = 0;
  967. int txpkts, rxpkts;
  968. txpkts = mac_cb->txpkt_for_led - mac_cb->hw_stats.tx_good_pkts;
  969. rxpkts = mac_cb->rxpkt_for_led - mac_cb->hw_stats.rx_good_pkts;
  970. if (txpkts || rxpkts)
  971. nic_data = 1;
  972. else
  973. nic_data = 0;
  974. mac_cb->txpkt_for_led = mac_cb->hw_stats.tx_good_pkts;
  975. mac_cb->rxpkt_for_led = mac_cb->hw_stats.rx_good_pkts;
  976. mac_cb->dsaf_dev->misc_op->cpld_set_led(mac_cb, (int)mac_cb->link,
  977. mac_cb->speed, nic_data);
  978. }
  979. int hns_cpld_led_set_id(struct hns_mac_cb *mac_cb,
  980. enum hnae_led_state status)
  981. {
  982. if (!mac_cb || !mac_cb->cpld_ctrl)
  983. return 0;
  984. return mac_cb->dsaf_dev->misc_op->cpld_set_led_id(mac_cb, status);
  985. }