]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
b97cc754bfae35bf791fdd13607d3fcc2dc207ec
[mirror_ubuntu-bionic-kernel.git] / drivers / net / ethernet / hisilicon / hns / hns_ae_adapt.c
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
10 #include <linux/etherdevice.h>
11 #include <linux/netdevice.h>
12 #include <linux/spinlock.h>
13
14 #include "hnae.h"
15 #include "hns_dsaf_mac.h"
16 #include "hns_dsaf_main.h"
17 #include "hns_dsaf_ppe.h"
18 #include "hns_dsaf_rcb.h"
19
20 #define AE_NAME_PORT_ID_IDX 6
21 #define ETH_STATIC_REG 1
22 #define ETH_DUMP_REG 5
23 #define ETH_GSTRING_LEN 32
24
25 static struct hns_mac_cb *hns_get_mac_cb(struct hnae_handle *handle)
26 {
27 struct hnae_vf_cb *vf_cb = hns_ae_get_vf_cb(handle);
28
29 return vf_cb->mac_cb;
30 }
31
32 static struct dsaf_device *hns_ae_get_dsaf_dev(struct hnae_ae_dev *dev)
33 {
34 return container_of(dev, struct dsaf_device, ae_dev);
35 }
36
37 static struct hns_ppe_cb *hns_get_ppe_cb(struct hnae_handle *handle)
38 {
39 int ppe_index;
40 struct ppe_common_cb *ppe_comm;
41 struct hnae_vf_cb *vf_cb = hns_ae_get_vf_cb(handle);
42
43 ppe_comm = vf_cb->dsaf_dev->ppe_common[0];
44 ppe_index = vf_cb->port_index;
45
46 return &ppe_comm->ppe_cb[ppe_index];
47 }
48
49 static int hns_ae_get_q_num_per_vf(
50 struct dsaf_device *dsaf_dev, int port)
51 {
52 return dsaf_dev->rcb_common[0]->max_q_per_vf;
53 }
54
55 static int hns_ae_get_vf_num_per_port(
56 struct dsaf_device *dsaf_dev, int port)
57 {
58 return dsaf_dev->rcb_common[0]->max_vfn;
59 }
60
61 static struct ring_pair_cb *hns_ae_get_base_ring_pair(
62 struct dsaf_device *dsaf_dev, int port)
63 {
64 struct rcb_common_cb *rcb_comm = dsaf_dev->rcb_common[0];
65 int q_num = rcb_comm->max_q_per_vf;
66 int vf_num = rcb_comm->max_vfn;
67
68 return &rcb_comm->ring_pair_cb[port * q_num * vf_num];
69 }
70
71 static struct ring_pair_cb *hns_ae_get_ring_pair(struct hnae_queue *q)
72 {
73 return container_of(q, struct ring_pair_cb, q);
74 }
75
76 struct hnae_handle *hns_ae_get_handle(struct hnae_ae_dev *dev,
77 u32 port_id)
78 {
79 int vfnum_per_port;
80 int qnum_per_vf;
81 int i;
82 struct dsaf_device *dsaf_dev;
83 struct hnae_handle *ae_handle;
84 struct ring_pair_cb *ring_pair_cb;
85 struct hnae_vf_cb *vf_cb;
86
87 dsaf_dev = hns_ae_get_dsaf_dev(dev);
88
89 ring_pair_cb = hns_ae_get_base_ring_pair(dsaf_dev, port_id);
90 vfnum_per_port = hns_ae_get_vf_num_per_port(dsaf_dev, port_id);
91 qnum_per_vf = hns_ae_get_q_num_per_vf(dsaf_dev, port_id);
92
93 vf_cb = kzalloc(sizeof(*vf_cb) +
94 qnum_per_vf * sizeof(struct hnae_queue *), GFP_KERNEL);
95 if (unlikely(!vf_cb)) {
96 dev_err(dsaf_dev->dev, "malloc vf_cb fail!\n");
97 ae_handle = ERR_PTR(-ENOMEM);
98 goto handle_err;
99 }
100 ae_handle = &vf_cb->ae_handle;
101 /* ae_handle Init */
102 ae_handle->owner_dev = dsaf_dev->dev;
103 ae_handle->dev = dev;
104 ae_handle->q_num = qnum_per_vf;
105
106 /* find ring pair, and set vf id*/
107 for (ae_handle->vf_id = 0;
108 ae_handle->vf_id < vfnum_per_port; ae_handle->vf_id++) {
109 if (!ring_pair_cb->used_by_vf)
110 break;
111 ring_pair_cb += qnum_per_vf;
112 }
113 if (ae_handle->vf_id >= vfnum_per_port) {
114 dev_err(dsaf_dev->dev, "malloc queue fail!\n");
115 ae_handle = ERR_PTR(-EINVAL);
116 goto vf_id_err;
117 }
118
119 ae_handle->qs = (struct hnae_queue **)(&ae_handle->qs + 1);
120 for (i = 0; i < qnum_per_vf; i++) {
121 ae_handle->qs[i] = &ring_pair_cb->q;
122 ae_handle->qs[i]->rx_ring.q = ae_handle->qs[i];
123 ae_handle->qs[i]->tx_ring.q = ae_handle->qs[i];
124
125 ring_pair_cb->used_by_vf = 1;
126 ring_pair_cb++;
127 }
128
129 vf_cb->dsaf_dev = dsaf_dev;
130 vf_cb->port_index = port_id;
131 vf_cb->mac_cb = dsaf_dev->mac_cb[port_id];
132
133 ae_handle->phy_if = vf_cb->mac_cb->phy_if;
134 ae_handle->phy_dev = vf_cb->mac_cb->phy_dev;
135 ae_handle->if_support = vf_cb->mac_cb->if_support;
136 ae_handle->port_type = vf_cb->mac_cb->mac_type;
137 ae_handle->dport_id = port_id;
138
139 return ae_handle;
140 vf_id_err:
141 kfree(vf_cb);
142 handle_err:
143 return ae_handle;
144 }
145
146 static void hns_ae_put_handle(struct hnae_handle *handle)
147 {
148 struct hnae_vf_cb *vf_cb = hns_ae_get_vf_cb(handle);
149 int i;
150
151 vf_cb->mac_cb = NULL;
152
153 kfree(vf_cb);
154
155 for (i = 0; i < handle->q_num; i++)
156 hns_ae_get_ring_pair(handle->qs[i])->used_by_vf = 0;
157 }
158
159 static void hns_ae_ring_enable_all(struct hnae_handle *handle, int val)
160 {
161 int q_num = handle->q_num;
162 int i;
163
164 for (i = 0; i < q_num; i++)
165 hns_rcb_ring_enable_hw(handle->qs[i], val);
166 }
167
168 static void hns_ae_init_queue(struct hnae_queue *q)
169 {
170 struct ring_pair_cb *ring =
171 container_of(q, struct ring_pair_cb, q);
172
173 hns_rcb_init_hw(ring);
174 }
175
176 static void hns_ae_fini_queue(struct hnae_queue *q)
177 {
178 struct hnae_vf_cb *vf_cb = hns_ae_get_vf_cb(q->handle);
179
180 if (vf_cb->mac_cb->mac_type == HNAE_PORT_SERVICE)
181 hns_rcb_reset_ring_hw(q);
182 }
183
184 static int hns_ae_set_mac_address(struct hnae_handle *handle, void *p)
185 {
186 int ret;
187 struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle);
188
189 if (!p || !is_valid_ether_addr((const u8 *)p)) {
190 dev_err(handle->owner_dev, "is not valid ether addr !\n");
191 return -EADDRNOTAVAIL;
192 }
193
194 ret = hns_mac_change_vf_addr(mac_cb, handle->vf_id, p);
195 if (ret != 0) {
196 dev_err(handle->owner_dev,
197 "set_mac_address fail, ret=%d!\n", ret);
198 return ret;
199 }
200
201 return 0;
202 }
203
204 static int hns_ae_set_multicast_one(struct hnae_handle *handle, void *addr)
205 {
206 int ret;
207 char *mac_addr = (char *)addr;
208 struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle);
209
210 assert(mac_cb);
211
212 if (mac_cb->mac_type != HNAE_PORT_SERVICE)
213 return 0;
214
215 ret = hns_mac_set_multi(mac_cb, mac_cb->mac_id, mac_addr, true);
216 if (ret) {
217 dev_err(handle->owner_dev,
218 "mac add mul_mac:%pM port%d fail, ret = %#x!\n",
219 mac_addr, mac_cb->mac_id, ret);
220 return ret;
221 }
222
223 ret = hns_mac_set_multi(mac_cb, DSAF_BASE_INNER_PORT_NUM,
224 mac_addr, true);
225 if (ret)
226 dev_err(handle->owner_dev,
227 "mac add mul_mac:%pM port%d fail, ret = %#x!\n",
228 mac_addr, DSAF_BASE_INNER_PORT_NUM, ret);
229
230 return ret;
231 }
232
233 static int hns_ae_set_mtu(struct hnae_handle *handle, int new_mtu)
234 {
235 struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle);
236
237 return hns_mac_set_mtu(mac_cb, new_mtu);
238 }
239
240 static void hns_ae_set_tso_stats(struct hnae_handle *handle, int enable)
241 {
242 struct hns_ppe_cb *ppe_cb = hns_get_ppe_cb(handle);
243
244 hns_ppe_set_tso_enable(ppe_cb, enable);
245 }
246
247 static int hns_ae_start(struct hnae_handle *handle)
248 {
249 int ret;
250 struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle);
251
252 ret = hns_mac_vm_config_bc_en(mac_cb, 0, true);
253 if (ret)
254 return ret;
255
256 hns_ae_ring_enable_all(handle, 1);
257 msleep(100);
258
259 hns_mac_start(mac_cb);
260
261 return 0;
262 }
263
264 void hns_ae_stop(struct hnae_handle *handle)
265 {
266 struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle);
267
268 /* just clean tx fbd, neednot rx fbd*/
269 hns_rcb_wait_fbd_clean(handle->qs, handle->q_num, RCB_INT_FLAG_TX);
270
271 msleep(20);
272
273 hns_mac_stop(mac_cb);
274
275 usleep_range(10000, 20000);
276
277 hns_ae_ring_enable_all(handle, 0);
278
279 (void)hns_mac_vm_config_bc_en(mac_cb, 0, false);
280 }
281
282 static void hns_ae_reset(struct hnae_handle *handle)
283 {
284 struct hnae_vf_cb *vf_cb = hns_ae_get_vf_cb(handle);
285
286 if (vf_cb->mac_cb->mac_type == HNAE_PORT_DEBUG) {
287 hns_mac_reset(vf_cb->mac_cb);
288 hns_ppe_reset_common(vf_cb->dsaf_dev, 0);
289 }
290 }
291
292 void hns_ae_toggle_ring_irq(struct hnae_ring *ring, u32 mask)
293 {
294 u32 flag;
295
296 if (is_tx_ring(ring))
297 flag = RCB_INT_FLAG_TX;
298 else
299 flag = RCB_INT_FLAG_RX;
300
301 hns_rcb_int_ctrl_hw(ring->q, flag, mask);
302 }
303
304 static void hns_aev2_toggle_ring_irq(struct hnae_ring *ring, u32 mask)
305 {
306 u32 flag;
307
308 if (is_tx_ring(ring))
309 flag = RCB_INT_FLAG_TX;
310 else
311 flag = RCB_INT_FLAG_RX;
312
313 hns_rcbv2_int_ctrl_hw(ring->q, flag, mask);
314 }
315
316 static void hns_ae_toggle_queue_status(struct hnae_queue *queue, u32 val)
317 {
318 struct dsaf_device *dsaf_dev = hns_ae_get_dsaf_dev(queue->dev);
319
320 if (AE_IS_VER1(dsaf_dev->dsaf_ver))
321 hns_rcb_int_clr_hw(queue, RCB_INT_FLAG_TX | RCB_INT_FLAG_RX);
322 else
323 hns_rcbv2_int_clr_hw(queue, RCB_INT_FLAG_TX | RCB_INT_FLAG_RX);
324
325 hns_rcb_start(queue, val);
326 }
327
328 static int hns_ae_get_link_status(struct hnae_handle *handle)
329 {
330 u32 link_status;
331 struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle);
332
333 hns_mac_get_link_status(mac_cb, &link_status);
334
335 return !!link_status;
336 }
337
338 static int hns_ae_get_mac_info(struct hnae_handle *handle,
339 u8 *auto_neg, u16 *speed, u8 *duplex)
340 {
341 struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle);
342
343 return hns_mac_get_port_info(mac_cb, auto_neg, speed, duplex);
344 }
345
346 static void hns_ae_adjust_link(struct hnae_handle *handle, int speed,
347 int duplex)
348 {
349 struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle);
350
351 hns_mac_adjust_link(mac_cb, speed, duplex);
352 }
353
354 static void hns_ae_get_ring_bdnum_limit(struct hnae_queue *queue,
355 u32 *uplimit)
356 {
357 *uplimit = HNS_RCB_RING_MAX_PENDING_BD;
358 }
359
360 static void hns_ae_get_pauseparam(struct hnae_handle *handle,
361 u32 *auto_neg, u32 *rx_en, u32 *tx_en)
362 {
363 struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle);
364 struct dsaf_device *dsaf_dev = mac_cb->dsaf_dev;
365
366 hns_mac_get_autoneg(mac_cb, auto_neg);
367
368 hns_mac_get_pauseparam(mac_cb, rx_en, tx_en);
369
370 /* Service port's pause feature is provided by DSAF, not mac */
371 if (handle->port_type == HNAE_PORT_SERVICE)
372 hns_dsaf_get_rx_mac_pause_en(dsaf_dev, mac_cb->mac_id, rx_en);
373 }
374
375 static int hns_ae_set_autoneg(struct hnae_handle *handle, u8 enable)
376 {
377 assert(handle);
378
379 return hns_mac_set_autoneg(hns_get_mac_cb(handle), enable);
380 }
381
382 static void hns_ae_set_promisc_mode(struct hnae_handle *handle, u32 en)
383 {
384 struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle);
385
386 hns_dsaf_set_promisc_mode(hns_ae_get_dsaf_dev(handle->dev), en);
387 hns_mac_set_promisc(mac_cb, (u8)!!en);
388 }
389
390 static int hns_ae_get_autoneg(struct hnae_handle *handle)
391 {
392 u32 auto_neg;
393
394 assert(handle);
395
396 hns_mac_get_autoneg(hns_get_mac_cb(handle), &auto_neg);
397
398 return auto_neg;
399 }
400
401 static int hns_ae_set_pauseparam(struct hnae_handle *handle,
402 u32 autoneg, u32 rx_en, u32 tx_en)
403 {
404 struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle);
405 struct dsaf_device *dsaf_dev = mac_cb->dsaf_dev;
406 int ret;
407
408 ret = hns_mac_set_autoneg(mac_cb, autoneg);
409 if (ret)
410 return ret;
411
412 /* Service port's pause feature is provided by DSAF, not mac */
413 if (handle->port_type == HNAE_PORT_SERVICE) {
414 ret = hns_dsaf_set_rx_mac_pause_en(dsaf_dev,
415 mac_cb->mac_id, rx_en);
416 if (ret)
417 return ret;
418 rx_en = 0;
419 }
420 return hns_mac_set_pauseparam(mac_cb, rx_en, tx_en);
421 }
422
423 static void hns_ae_get_coalesce_usecs(struct hnae_handle *handle,
424 u32 *tx_usecs, u32 *rx_usecs)
425 {
426 struct ring_pair_cb *ring_pair =
427 container_of(handle->qs[0], struct ring_pair_cb, q);
428
429 *tx_usecs = hns_rcb_get_coalesce_usecs(ring_pair->rcb_common,
430 ring_pair->port_id_in_comm);
431 *rx_usecs = hns_rcb_get_coalesce_usecs(ring_pair->rcb_common,
432 ring_pair->port_id_in_comm);
433 }
434
435 static void hns_ae_get_rx_max_coalesced_frames(struct hnae_handle *handle,
436 u32 *tx_frames, u32 *rx_frames)
437 {
438 struct ring_pair_cb *ring_pair =
439 container_of(handle->qs[0], struct ring_pair_cb, q);
440
441 *tx_frames = hns_rcb_get_coalesced_frames(ring_pair->rcb_common,
442 ring_pair->port_id_in_comm);
443 *rx_frames = hns_rcb_get_coalesced_frames(ring_pair->rcb_common,
444 ring_pair->port_id_in_comm);
445 }
446
447 static int hns_ae_set_coalesce_usecs(struct hnae_handle *handle,
448 u32 timeout)
449 {
450 struct ring_pair_cb *ring_pair =
451 container_of(handle->qs[0], struct ring_pair_cb, q);
452
453 return hns_rcb_set_coalesce_usecs(
454 ring_pair->rcb_common, ring_pair->port_id_in_comm, timeout);
455 }
456
457 static int hns_ae_set_coalesce_frames(struct hnae_handle *handle,
458 u32 coalesce_frames)
459 {
460 struct ring_pair_cb *ring_pair =
461 container_of(handle->qs[0], struct ring_pair_cb, q);
462
463 return hns_rcb_set_coalesced_frames(
464 ring_pair->rcb_common,
465 ring_pair->port_id_in_comm, coalesce_frames);
466 }
467
468 void hns_ae_update_stats(struct hnae_handle *handle,
469 struct net_device_stats *net_stats)
470 {
471 int port;
472 int idx;
473 struct dsaf_device *dsaf_dev;
474 struct hns_mac_cb *mac_cb;
475 struct hns_ppe_cb *ppe_cb;
476 struct hnae_queue *queue;
477 struct hnae_vf_cb *vf_cb = hns_ae_get_vf_cb(handle);
478 u64 tx_bytes = 0, rx_bytes = 0, tx_packets = 0, rx_packets = 0;
479 u64 rx_errors = 0, tx_errors = 0, tx_dropped = 0;
480 u64 rx_missed_errors = 0;
481
482 dsaf_dev = hns_ae_get_dsaf_dev(handle->dev);
483 if (!dsaf_dev)
484 return;
485 port = vf_cb->port_index;
486 ppe_cb = hns_get_ppe_cb(handle);
487 mac_cb = hns_get_mac_cb(handle);
488
489 for (idx = 0; idx < handle->q_num; idx++) {
490 queue = handle->qs[idx];
491 hns_rcb_update_stats(queue);
492
493 tx_bytes += queue->tx_ring.stats.tx_bytes;
494 tx_packets += queue->tx_ring.stats.tx_pkts;
495 rx_bytes += queue->rx_ring.stats.rx_bytes;
496 rx_packets += queue->rx_ring.stats.rx_pkts;
497
498 rx_errors += queue->rx_ring.stats.err_pkt_len
499 + queue->rx_ring.stats.l2_err
500 + queue->rx_ring.stats.l3l4_csum_err;
501 }
502
503 hns_ppe_update_stats(ppe_cb);
504 rx_missed_errors = ppe_cb->hw_stats.rx_drop_no_buf;
505 tx_errors += ppe_cb->hw_stats.tx_err_checksum
506 + ppe_cb->hw_stats.tx_err_fifo_empty;
507
508 if (mac_cb->mac_type == HNAE_PORT_SERVICE) {
509 hns_dsaf_update_stats(dsaf_dev, port);
510 /* for port upline direction, i.e., rx. */
511 rx_missed_errors += dsaf_dev->hw_stats[port].bp_drop;
512 rx_missed_errors += dsaf_dev->hw_stats[port].pad_drop;
513 rx_missed_errors += dsaf_dev->hw_stats[port].crc_false;
514
515 /* for port downline direction, i.e., tx. */
516 port = port + DSAF_PPE_INODE_BASE;
517 hns_dsaf_update_stats(dsaf_dev, port);
518 tx_dropped += dsaf_dev->hw_stats[port].bp_drop;
519 tx_dropped += dsaf_dev->hw_stats[port].pad_drop;
520 tx_dropped += dsaf_dev->hw_stats[port].crc_false;
521 tx_dropped += dsaf_dev->hw_stats[port].rslt_drop;
522 tx_dropped += dsaf_dev->hw_stats[port].vlan_drop;
523 tx_dropped += dsaf_dev->hw_stats[port].stp_drop;
524 }
525
526 hns_mac_update_stats(mac_cb);
527 rx_errors += mac_cb->hw_stats.rx_fifo_overrun_err;
528
529 tx_errors += mac_cb->hw_stats.tx_bad_pkts
530 + mac_cb->hw_stats.tx_fragment_err
531 + mac_cb->hw_stats.tx_jabber_err
532 + mac_cb->hw_stats.tx_underrun_err
533 + mac_cb->hw_stats.tx_crc_err;
534
535 net_stats->tx_bytes = tx_bytes;
536 net_stats->tx_packets = tx_packets;
537 net_stats->rx_bytes = rx_bytes;
538 net_stats->rx_dropped = 0;
539 net_stats->rx_packets = rx_packets;
540 net_stats->rx_errors = rx_errors;
541 net_stats->tx_errors = tx_errors;
542 net_stats->tx_dropped = tx_dropped;
543 net_stats->rx_missed_errors = rx_missed_errors;
544 net_stats->rx_crc_errors = mac_cb->hw_stats.rx_fcs_err;
545 net_stats->rx_frame_errors = mac_cb->hw_stats.rx_align_err;
546 net_stats->rx_fifo_errors = mac_cb->hw_stats.rx_fifo_overrun_err;
547 net_stats->rx_length_errors = mac_cb->hw_stats.rx_len_err;
548 net_stats->multicast = mac_cb->hw_stats.rx_mc_pkts;
549 }
550
551 void hns_ae_get_stats(struct hnae_handle *handle, u64 *data)
552 {
553 int idx;
554 struct hns_mac_cb *mac_cb;
555 struct hns_ppe_cb *ppe_cb;
556 u64 *p = data;
557 struct hnae_vf_cb *vf_cb;
558
559 if (!handle || !data) {
560 pr_err("hns_ae_get_stats NULL handle or data pointer!\n");
561 return;
562 }
563
564 vf_cb = hns_ae_get_vf_cb(handle);
565 mac_cb = hns_get_mac_cb(handle);
566 ppe_cb = hns_get_ppe_cb(handle);
567
568 for (idx = 0; idx < handle->q_num; idx++) {
569 hns_rcb_get_stats(handle->qs[idx], p);
570 p += hns_rcb_get_ring_sset_count((int)ETH_SS_STATS);
571 }
572
573 hns_ppe_get_stats(ppe_cb, p);
574 p += hns_ppe_get_sset_count((int)ETH_SS_STATS);
575
576 hns_mac_get_stats(mac_cb, p);
577 p += hns_mac_get_sset_count(mac_cb, (int)ETH_SS_STATS);
578
579 if (mac_cb->mac_type == HNAE_PORT_SERVICE)
580 hns_dsaf_get_stats(vf_cb->dsaf_dev, p, vf_cb->port_index);
581 }
582
583 void hns_ae_get_strings(struct hnae_handle *handle,
584 u32 stringset, u8 *data)
585 {
586 int port;
587 int idx;
588 struct hns_mac_cb *mac_cb;
589 struct hns_ppe_cb *ppe_cb;
590 struct dsaf_device *dsaf_dev = hns_ae_get_dsaf_dev(handle->dev);
591 u8 *p = data;
592 struct hnae_vf_cb *vf_cb;
593
594 assert(handle);
595
596 vf_cb = hns_ae_get_vf_cb(handle);
597 port = vf_cb->port_index;
598 mac_cb = hns_get_mac_cb(handle);
599 ppe_cb = hns_get_ppe_cb(handle);
600
601 for (idx = 0; idx < handle->q_num; idx++) {
602 hns_rcb_get_strings(stringset, p, idx);
603 p += ETH_GSTRING_LEN * hns_rcb_get_ring_sset_count(stringset);
604 }
605
606 hns_ppe_get_strings(ppe_cb, stringset, p);
607 p += ETH_GSTRING_LEN * hns_ppe_get_sset_count(stringset);
608
609 hns_mac_get_strings(mac_cb, stringset, p);
610 p += ETH_GSTRING_LEN * hns_mac_get_sset_count(mac_cb, stringset);
611
612 if (mac_cb->mac_type == HNAE_PORT_SERVICE)
613 hns_dsaf_get_strings(stringset, p, port, dsaf_dev);
614 }
615
616 int hns_ae_get_sset_count(struct hnae_handle *handle, int stringset)
617 {
618 u32 sset_count = 0;
619 struct hns_mac_cb *mac_cb;
620 struct dsaf_device *dsaf_dev = hns_ae_get_dsaf_dev(handle->dev);
621
622 assert(handle);
623
624 mac_cb = hns_get_mac_cb(handle);
625
626 sset_count += hns_rcb_get_ring_sset_count(stringset) * handle->q_num;
627 sset_count += hns_ppe_get_sset_count(stringset);
628 sset_count += hns_mac_get_sset_count(mac_cb, stringset);
629
630 if (mac_cb->mac_type == HNAE_PORT_SERVICE)
631 sset_count += hns_dsaf_get_sset_count(dsaf_dev, stringset);
632
633 return sset_count;
634 }
635
636 static int hns_ae_config_loopback(struct hnae_handle *handle,
637 enum hnae_loop loop, int en)
638 {
639 int ret;
640 struct hnae_vf_cb *vf_cb = hns_ae_get_vf_cb(handle);
641 struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle);
642 struct dsaf_device *dsaf_dev = mac_cb->dsaf_dev;
643
644 switch (loop) {
645 case MAC_INTERNALLOOP_PHY:
646 ret = 0;
647 break;
648 case MAC_INTERNALLOOP_SERDES:
649 ret = dsaf_dev->misc_op->cfg_serdes_loopback(vf_cb->mac_cb,
650 !!en);
651 break;
652 case MAC_INTERNALLOOP_MAC:
653 ret = hns_mac_config_mac_loopback(vf_cb->mac_cb, loop, en);
654 break;
655 default:
656 ret = -EINVAL;
657 }
658
659 if (!ret)
660 hns_dsaf_set_inner_lb(mac_cb->dsaf_dev, mac_cb->mac_id, en);
661
662 return ret;
663 }
664
665 void hns_ae_update_led_status(struct hnae_handle *handle)
666 {
667 struct hns_mac_cb *mac_cb;
668
669 assert(handle);
670 mac_cb = hns_get_mac_cb(handle);
671 if (!mac_cb->cpld_ctrl)
672 return;
673 hns_set_led_opt(mac_cb);
674 }
675
676 int hns_ae_cpld_set_led_id(struct hnae_handle *handle,
677 enum hnae_led_state status)
678 {
679 struct hns_mac_cb *mac_cb;
680
681 assert(handle);
682
683 mac_cb = hns_get_mac_cb(handle);
684
685 return hns_cpld_led_set_id(mac_cb, status);
686 }
687
688 void hns_ae_get_regs(struct hnae_handle *handle, void *data)
689 {
690 u32 *p = data;
691 int i;
692 struct hnae_vf_cb *vf_cb = hns_ae_get_vf_cb(handle);
693 struct hns_ppe_cb *ppe_cb = hns_get_ppe_cb(handle);
694
695 hns_ppe_get_regs(ppe_cb, p);
696 p += hns_ppe_get_regs_count();
697
698 hns_rcb_get_common_regs(vf_cb->dsaf_dev->rcb_common[0], p);
699 p += hns_rcb_get_common_regs_count();
700
701 for (i = 0; i < handle->q_num; i++) {
702 hns_rcb_get_ring_regs(handle->qs[i], p);
703 p += hns_rcb_get_ring_regs_count();
704 }
705
706 hns_mac_get_regs(vf_cb->mac_cb, p);
707 p += hns_mac_get_regs_count(vf_cb->mac_cb);
708
709 if (vf_cb->mac_cb->mac_type == HNAE_PORT_SERVICE)
710 hns_dsaf_get_regs(vf_cb->dsaf_dev, vf_cb->port_index, p);
711 }
712
713 int hns_ae_get_regs_len(struct hnae_handle *handle)
714 {
715 u32 total_num;
716 struct hnae_vf_cb *vf_cb = hns_ae_get_vf_cb(handle);
717
718 total_num = hns_ppe_get_regs_count();
719 total_num += hns_rcb_get_common_regs_count();
720 total_num += hns_rcb_get_ring_regs_count() * handle->q_num;
721 total_num += hns_mac_get_regs_count(vf_cb->mac_cb);
722
723 if (vf_cb->mac_cb->mac_type == HNAE_PORT_SERVICE)
724 total_num += hns_dsaf_get_regs_count();
725
726 return total_num;
727 }
728
729 static u32 hns_ae_get_rss_key_size(struct hnae_handle *handle)
730 {
731 return HNS_PPEV2_RSS_KEY_SIZE;
732 }
733
734 static u32 hns_ae_get_rss_indir_size(struct hnae_handle *handle)
735 {
736 return HNS_PPEV2_RSS_IND_TBL_SIZE;
737 }
738
739 static int hns_ae_get_rss(struct hnae_handle *handle, u32 *indir, u8 *key,
740 u8 *hfunc)
741 {
742 struct hns_ppe_cb *ppe_cb = hns_get_ppe_cb(handle);
743
744 /* currently we support only one type of hash function i.e. Toep hash */
745 if (hfunc)
746 *hfunc = ETH_RSS_HASH_TOP;
747
748 /* get the RSS Key required by the user */
749 if (key)
750 memcpy(key, ppe_cb->rss_key, HNS_PPEV2_RSS_KEY_SIZE);
751
752 /* update the current hash->queue mappings from the shadow RSS table */
753 memcpy(indir, ppe_cb->rss_indir_table,
754 HNS_PPEV2_RSS_IND_TBL_SIZE * sizeof(*indir));
755
756 return 0;
757 }
758
759 static int hns_ae_set_rss(struct hnae_handle *handle, const u32 *indir,
760 const u8 *key, const u8 hfunc)
761 {
762 struct hns_ppe_cb *ppe_cb = hns_get_ppe_cb(handle);
763
764 /* set the RSS Hash Key if specififed by the user */
765 if (key)
766 hns_ppe_set_rss_key(ppe_cb, (u32 *)key);
767
768 /* update the shadow RSS table with user specified qids */
769 memcpy(ppe_cb->rss_indir_table, indir,
770 HNS_PPEV2_RSS_IND_TBL_SIZE * sizeof(*indir));
771
772 /* now update the hardware */
773 hns_ppe_set_indir_table(ppe_cb, ppe_cb->rss_indir_table);
774
775 return 0;
776 }
777
778 static struct hnae_ae_ops hns_dsaf_ops = {
779 .get_handle = hns_ae_get_handle,
780 .put_handle = hns_ae_put_handle,
781 .init_queue = hns_ae_init_queue,
782 .fini_queue = hns_ae_fini_queue,
783 .start = hns_ae_start,
784 .stop = hns_ae_stop,
785 .reset = hns_ae_reset,
786 .toggle_ring_irq = hns_ae_toggle_ring_irq,
787 .toggle_queue_status = hns_ae_toggle_queue_status,
788 .get_status = hns_ae_get_link_status,
789 .get_info = hns_ae_get_mac_info,
790 .adjust_link = hns_ae_adjust_link,
791 .set_loopback = hns_ae_config_loopback,
792 .get_ring_bdnum_limit = hns_ae_get_ring_bdnum_limit,
793 .get_pauseparam = hns_ae_get_pauseparam,
794 .set_autoneg = hns_ae_set_autoneg,
795 .get_autoneg = hns_ae_get_autoneg,
796 .set_pauseparam = hns_ae_set_pauseparam,
797 .get_coalesce_usecs = hns_ae_get_coalesce_usecs,
798 .get_rx_max_coalesced_frames = hns_ae_get_rx_max_coalesced_frames,
799 .set_coalesce_usecs = hns_ae_set_coalesce_usecs,
800 .set_coalesce_frames = hns_ae_set_coalesce_frames,
801 .set_promisc_mode = hns_ae_set_promisc_mode,
802 .set_mac_addr = hns_ae_set_mac_address,
803 .set_mc_addr = hns_ae_set_multicast_one,
804 .set_mtu = hns_ae_set_mtu,
805 .update_stats = hns_ae_update_stats,
806 .set_tso_stats = hns_ae_set_tso_stats,
807 .get_stats = hns_ae_get_stats,
808 .get_strings = hns_ae_get_strings,
809 .get_sset_count = hns_ae_get_sset_count,
810 .update_led_status = hns_ae_update_led_status,
811 .set_led_id = hns_ae_cpld_set_led_id,
812 .get_regs = hns_ae_get_regs,
813 .get_regs_len = hns_ae_get_regs_len,
814 .get_rss_key_size = hns_ae_get_rss_key_size,
815 .get_rss_indir_size = hns_ae_get_rss_indir_size,
816 .get_rss = hns_ae_get_rss,
817 .set_rss = hns_ae_set_rss
818 };
819
820 int hns_dsaf_ae_init(struct dsaf_device *dsaf_dev)
821 {
822 struct hnae_ae_dev *ae_dev = &dsaf_dev->ae_dev;
823 static atomic_t id = ATOMIC_INIT(-1);
824
825 switch (dsaf_dev->dsaf_ver) {
826 case AE_VERSION_1:
827 hns_dsaf_ops.toggle_ring_irq = hns_ae_toggle_ring_irq;
828 break;
829 case AE_VERSION_2:
830 hns_dsaf_ops.toggle_ring_irq = hns_aev2_toggle_ring_irq;
831 break;
832 default:
833 break;
834 }
835
836 snprintf(ae_dev->name, AE_NAME_SIZE, "%s%d", DSAF_DEVICE_NAME,
837 (int)atomic_inc_return(&id));
838 ae_dev->ops = &hns_dsaf_ops;
839 ae_dev->dev = dsaf_dev->dev;
840
841 return hnae_ae_register(ae_dev, THIS_MODULE);
842 }
843
844 void hns_dsaf_ae_uninit(struct dsaf_device *dsaf_dev)
845 {
846 hnae_ae_unregister(&dsaf_dev->ae_dev);
847 }