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