net: hns: delete redundancy ring enable operations
[deliverable/linux.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 int k;
251 struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle);
252
253 ret = hns_mac_vm_config_bc_en(mac_cb, 0, true);
254 if (ret)
255 return ret;
256
257 for (k = 0; k < handle->q_num; k++) {
258 if (AE_IS_VER1(mac_cb->dsaf_dev->dsaf_ver))
259 hns_rcb_int_clr_hw(handle->qs[k],
260 RCB_INT_FLAG_TX | RCB_INT_FLAG_RX);
261 else
262 hns_rcbv2_int_clr_hw(handle->qs[k],
263 RCB_INT_FLAG_TX | RCB_INT_FLAG_RX);
264 }
265 hns_ae_ring_enable_all(handle, 1);
266 msleep(100);
267
268 hns_mac_start(mac_cb);
269
270 return 0;
271 }
272
273 void hns_ae_stop(struct hnae_handle *handle)
274 {
275 struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle);
276
277 /* just clean tx fbd, neednot rx fbd*/
278 hns_rcb_wait_fbd_clean(handle->qs, handle->q_num, RCB_INT_FLAG_TX);
279
280 msleep(20);
281
282 hns_mac_stop(mac_cb);
283
284 usleep_range(10000, 20000);
285
286 hns_ae_ring_enable_all(handle, 0);
287
288 (void)hns_mac_vm_config_bc_en(mac_cb, 0, false);
289 }
290
291 static void hns_ae_reset(struct hnae_handle *handle)
292 {
293 struct hnae_vf_cb *vf_cb = hns_ae_get_vf_cb(handle);
294
295 if (vf_cb->mac_cb->mac_type == HNAE_PORT_DEBUG) {
296 hns_mac_reset(vf_cb->mac_cb);
297 hns_ppe_reset_common(vf_cb->dsaf_dev, 0);
298 }
299 }
300
301 void hns_ae_toggle_ring_irq(struct hnae_ring *ring, u32 mask)
302 {
303 u32 flag;
304
305 if (is_tx_ring(ring))
306 flag = RCB_INT_FLAG_TX;
307 else
308 flag = RCB_INT_FLAG_RX;
309
310 hns_rcb_int_ctrl_hw(ring->q, flag, mask);
311 }
312
313 static void hns_aev2_toggle_ring_irq(struct hnae_ring *ring, u32 mask)
314 {
315 u32 flag;
316
317 if (is_tx_ring(ring))
318 flag = RCB_INT_FLAG_TX;
319 else
320 flag = RCB_INT_FLAG_RX;
321
322 hns_rcbv2_int_ctrl_hw(ring->q, flag, mask);
323 }
324
325 static int hns_ae_get_link_status(struct hnae_handle *handle)
326 {
327 u32 link_status;
328 struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle);
329
330 hns_mac_get_link_status(mac_cb, &link_status);
331
332 return !!link_status;
333 }
334
335 static int hns_ae_get_mac_info(struct hnae_handle *handle,
336 u8 *auto_neg, u16 *speed, u8 *duplex)
337 {
338 struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle);
339
340 return hns_mac_get_port_info(mac_cb, auto_neg, speed, duplex);
341 }
342
343 static void hns_ae_adjust_link(struct hnae_handle *handle, int speed,
344 int duplex)
345 {
346 struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle);
347
348 hns_mac_adjust_link(mac_cb, speed, duplex);
349 }
350
351 static void hns_ae_get_ring_bdnum_limit(struct hnae_queue *queue,
352 u32 *uplimit)
353 {
354 *uplimit = HNS_RCB_RING_MAX_PENDING_BD;
355 }
356
357 static void hns_ae_get_pauseparam(struct hnae_handle *handle,
358 u32 *auto_neg, u32 *rx_en, u32 *tx_en)
359 {
360 struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle);
361 struct dsaf_device *dsaf_dev = mac_cb->dsaf_dev;
362
363 hns_mac_get_autoneg(mac_cb, auto_neg);
364
365 hns_mac_get_pauseparam(mac_cb, rx_en, tx_en);
366
367 /* Service port's pause feature is provided by DSAF, not mac */
368 if (handle->port_type == HNAE_PORT_SERVICE)
369 hns_dsaf_get_rx_mac_pause_en(dsaf_dev, mac_cb->mac_id, rx_en);
370 }
371
372 static int hns_ae_set_autoneg(struct hnae_handle *handle, u8 enable)
373 {
374 assert(handle);
375
376 return hns_mac_set_autoneg(hns_get_mac_cb(handle), enable);
377 }
378
379 static void hns_ae_set_promisc_mode(struct hnae_handle *handle, u32 en)
380 {
381 struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle);
382
383 hns_dsaf_set_promisc_mode(hns_ae_get_dsaf_dev(handle->dev), en);
384 hns_mac_set_promisc(mac_cb, (u8)!!en);
385 }
386
387 static int hns_ae_get_autoneg(struct hnae_handle *handle)
388 {
389 u32 auto_neg;
390
391 assert(handle);
392
393 hns_mac_get_autoneg(hns_get_mac_cb(handle), &auto_neg);
394
395 return auto_neg;
396 }
397
398 static int hns_ae_set_pauseparam(struct hnae_handle *handle,
399 u32 autoneg, u32 rx_en, u32 tx_en)
400 {
401 struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle);
402 struct dsaf_device *dsaf_dev = mac_cb->dsaf_dev;
403 int ret;
404
405 ret = hns_mac_set_autoneg(mac_cb, autoneg);
406 if (ret)
407 return ret;
408
409 /* Service port's pause feature is provided by DSAF, not mac */
410 if (handle->port_type == HNAE_PORT_SERVICE) {
411 ret = hns_dsaf_set_rx_mac_pause_en(dsaf_dev,
412 mac_cb->mac_id, rx_en);
413 if (ret)
414 return ret;
415 rx_en = 0;
416 }
417 return hns_mac_set_pauseparam(mac_cb, rx_en, tx_en);
418 }
419
420 static void hns_ae_get_coalesce_usecs(struct hnae_handle *handle,
421 u32 *tx_usecs, u32 *rx_usecs)
422 {
423 struct ring_pair_cb *ring_pair =
424 container_of(handle->qs[0], struct ring_pair_cb, q);
425
426 *tx_usecs = hns_rcb_get_coalesce_usecs(ring_pair->rcb_common,
427 ring_pair->port_id_in_comm);
428 *rx_usecs = hns_rcb_get_coalesce_usecs(ring_pair->rcb_common,
429 ring_pair->port_id_in_comm);
430 }
431
432 static void hns_ae_get_rx_max_coalesced_frames(struct hnae_handle *handle,
433 u32 *tx_frames, u32 *rx_frames)
434 {
435 struct ring_pair_cb *ring_pair =
436 container_of(handle->qs[0], struct ring_pair_cb, q);
437
438 *tx_frames = hns_rcb_get_coalesced_frames(ring_pair->rcb_common,
439 ring_pair->port_id_in_comm);
440 *rx_frames = hns_rcb_get_coalesced_frames(ring_pair->rcb_common,
441 ring_pair->port_id_in_comm);
442 }
443
444 static int hns_ae_set_coalesce_usecs(struct hnae_handle *handle,
445 u32 timeout)
446 {
447 struct ring_pair_cb *ring_pair =
448 container_of(handle->qs[0], struct ring_pair_cb, q);
449
450 return hns_rcb_set_coalesce_usecs(
451 ring_pair->rcb_common, ring_pair->port_id_in_comm, timeout);
452 }
453
454 static int hns_ae_set_coalesce_frames(struct hnae_handle *handle,
455 u32 coalesce_frames)
456 {
457 struct ring_pair_cb *ring_pair =
458 container_of(handle->qs[0], struct ring_pair_cb, q);
459
460 return hns_rcb_set_coalesced_frames(
461 ring_pair->rcb_common,
462 ring_pair->port_id_in_comm, coalesce_frames);
463 }
464
465 static void hns_ae_get_coalesce_range(struct hnae_handle *handle,
466 u32 *tx_frames_low, u32 *rx_frames_low,
467 u32 *tx_frames_high, u32 *rx_frames_high,
468 u32 *tx_usecs_low, u32 *rx_usecs_low,
469 u32 *tx_usecs_high, u32 *rx_usecs_high)
470 {
471 struct dsaf_device *dsaf_dev;
472
473 dsaf_dev = hns_ae_get_dsaf_dev(handle->dev);
474
475 *tx_frames_low = HNS_RCB_MIN_COALESCED_FRAMES;
476 *rx_frames_low = HNS_RCB_MIN_COALESCED_FRAMES;
477 *tx_frames_high =
478 (dsaf_dev->desc_num - 1 > HNS_RCB_MAX_COALESCED_FRAMES) ?
479 HNS_RCB_MAX_COALESCED_FRAMES : dsaf_dev->desc_num - 1;
480 *rx_frames_high =
481 (dsaf_dev->desc_num - 1 > HNS_RCB_MAX_COALESCED_FRAMES) ?
482 HNS_RCB_MAX_COALESCED_FRAMES : dsaf_dev->desc_num - 1;
483 *tx_usecs_low = 0;
484 *rx_usecs_low = 0;
485 *tx_usecs_high = HNS_RCB_MAX_COALESCED_USECS;
486 *rx_usecs_high = HNS_RCB_MAX_COALESCED_USECS;
487 }
488
489 void hns_ae_update_stats(struct hnae_handle *handle,
490 struct net_device_stats *net_stats)
491 {
492 int port;
493 int idx;
494 struct dsaf_device *dsaf_dev;
495 struct hns_mac_cb *mac_cb;
496 struct hns_ppe_cb *ppe_cb;
497 struct hnae_queue *queue;
498 struct hnae_vf_cb *vf_cb = hns_ae_get_vf_cb(handle);
499 u64 tx_bytes = 0, rx_bytes = 0, tx_packets = 0, rx_packets = 0;
500 u64 rx_errors = 0, tx_errors = 0, tx_dropped = 0;
501 u64 rx_missed_errors = 0;
502
503 dsaf_dev = hns_ae_get_dsaf_dev(handle->dev);
504 if (!dsaf_dev)
505 return;
506 port = vf_cb->port_index;
507 ppe_cb = hns_get_ppe_cb(handle);
508 mac_cb = hns_get_mac_cb(handle);
509
510 for (idx = 0; idx < handle->q_num; idx++) {
511 queue = handle->qs[idx];
512 hns_rcb_update_stats(queue);
513
514 tx_bytes += queue->tx_ring.stats.tx_bytes;
515 tx_packets += queue->tx_ring.stats.tx_pkts;
516 rx_bytes += queue->rx_ring.stats.rx_bytes;
517 rx_packets += queue->rx_ring.stats.rx_pkts;
518
519 rx_errors += queue->rx_ring.stats.err_pkt_len
520 + queue->rx_ring.stats.l2_err
521 + queue->rx_ring.stats.l3l4_csum_err;
522 }
523
524 hns_ppe_update_stats(ppe_cb);
525 rx_missed_errors = ppe_cb->hw_stats.rx_drop_no_buf;
526 tx_errors += ppe_cb->hw_stats.tx_err_checksum
527 + ppe_cb->hw_stats.tx_err_fifo_empty;
528
529 if (mac_cb->mac_type == HNAE_PORT_SERVICE) {
530 hns_dsaf_update_stats(dsaf_dev, port);
531 /* for port upline direction, i.e., rx. */
532 rx_missed_errors += dsaf_dev->hw_stats[port].bp_drop;
533 rx_missed_errors += dsaf_dev->hw_stats[port].pad_drop;
534 rx_missed_errors += dsaf_dev->hw_stats[port].crc_false;
535
536 /* for port downline direction, i.e., tx. */
537 port = port + DSAF_PPE_INODE_BASE;
538 hns_dsaf_update_stats(dsaf_dev, port);
539 tx_dropped += dsaf_dev->hw_stats[port].bp_drop;
540 tx_dropped += dsaf_dev->hw_stats[port].pad_drop;
541 tx_dropped += dsaf_dev->hw_stats[port].crc_false;
542 tx_dropped += dsaf_dev->hw_stats[port].rslt_drop;
543 tx_dropped += dsaf_dev->hw_stats[port].vlan_drop;
544 tx_dropped += dsaf_dev->hw_stats[port].stp_drop;
545 }
546
547 hns_mac_update_stats(mac_cb);
548 rx_errors += mac_cb->hw_stats.rx_fifo_overrun_err;
549
550 tx_errors += mac_cb->hw_stats.tx_bad_pkts
551 + mac_cb->hw_stats.tx_fragment_err
552 + mac_cb->hw_stats.tx_jabber_err
553 + mac_cb->hw_stats.tx_underrun_err
554 + mac_cb->hw_stats.tx_crc_err;
555
556 net_stats->tx_bytes = tx_bytes;
557 net_stats->tx_packets = tx_packets;
558 net_stats->rx_bytes = rx_bytes;
559 net_stats->rx_dropped = 0;
560 net_stats->rx_packets = rx_packets;
561 net_stats->rx_errors = rx_errors;
562 net_stats->tx_errors = tx_errors;
563 net_stats->tx_dropped = tx_dropped;
564 net_stats->rx_missed_errors = rx_missed_errors;
565 net_stats->rx_crc_errors = mac_cb->hw_stats.rx_fcs_err;
566 net_stats->rx_frame_errors = mac_cb->hw_stats.rx_align_err;
567 net_stats->rx_fifo_errors = mac_cb->hw_stats.rx_fifo_overrun_err;
568 net_stats->rx_length_errors = mac_cb->hw_stats.rx_len_err;
569 net_stats->multicast = mac_cb->hw_stats.rx_mc_pkts;
570 }
571
572 void hns_ae_get_stats(struct hnae_handle *handle, u64 *data)
573 {
574 int idx;
575 struct hns_mac_cb *mac_cb;
576 struct hns_ppe_cb *ppe_cb;
577 u64 *p = data;
578 struct hnae_vf_cb *vf_cb;
579
580 if (!handle || !data) {
581 pr_err("hns_ae_get_stats NULL handle or data pointer!\n");
582 return;
583 }
584
585 vf_cb = hns_ae_get_vf_cb(handle);
586 mac_cb = hns_get_mac_cb(handle);
587 ppe_cb = hns_get_ppe_cb(handle);
588
589 for (idx = 0; idx < handle->q_num; idx++) {
590 hns_rcb_get_stats(handle->qs[idx], p);
591 p += hns_rcb_get_ring_sset_count((int)ETH_SS_STATS);
592 }
593
594 hns_ppe_get_stats(ppe_cb, p);
595 p += hns_ppe_get_sset_count((int)ETH_SS_STATS);
596
597 hns_mac_get_stats(mac_cb, p);
598 p += hns_mac_get_sset_count(mac_cb, (int)ETH_SS_STATS);
599
600 if (mac_cb->mac_type == HNAE_PORT_SERVICE)
601 hns_dsaf_get_stats(vf_cb->dsaf_dev, p, vf_cb->port_index);
602 }
603
604 void hns_ae_get_strings(struct hnae_handle *handle,
605 u32 stringset, u8 *data)
606 {
607 int port;
608 int idx;
609 struct hns_mac_cb *mac_cb;
610 struct hns_ppe_cb *ppe_cb;
611 struct dsaf_device *dsaf_dev = hns_ae_get_dsaf_dev(handle->dev);
612 u8 *p = data;
613 struct hnae_vf_cb *vf_cb;
614
615 assert(handle);
616
617 vf_cb = hns_ae_get_vf_cb(handle);
618 port = vf_cb->port_index;
619 mac_cb = hns_get_mac_cb(handle);
620 ppe_cb = hns_get_ppe_cb(handle);
621
622 for (idx = 0; idx < handle->q_num; idx++) {
623 hns_rcb_get_strings(stringset, p, idx);
624 p += ETH_GSTRING_LEN * hns_rcb_get_ring_sset_count(stringset);
625 }
626
627 hns_ppe_get_strings(ppe_cb, stringset, p);
628 p += ETH_GSTRING_LEN * hns_ppe_get_sset_count(stringset);
629
630 hns_mac_get_strings(mac_cb, stringset, p);
631 p += ETH_GSTRING_LEN * hns_mac_get_sset_count(mac_cb, stringset);
632
633 if (mac_cb->mac_type == HNAE_PORT_SERVICE)
634 hns_dsaf_get_strings(stringset, p, port, dsaf_dev);
635 }
636
637 int hns_ae_get_sset_count(struct hnae_handle *handle, int stringset)
638 {
639 u32 sset_count = 0;
640 struct hns_mac_cb *mac_cb;
641 struct dsaf_device *dsaf_dev = hns_ae_get_dsaf_dev(handle->dev);
642
643 assert(handle);
644
645 mac_cb = hns_get_mac_cb(handle);
646
647 sset_count += hns_rcb_get_ring_sset_count(stringset) * handle->q_num;
648 sset_count += hns_ppe_get_sset_count(stringset);
649 sset_count += hns_mac_get_sset_count(mac_cb, stringset);
650
651 if (mac_cb->mac_type == HNAE_PORT_SERVICE)
652 sset_count += hns_dsaf_get_sset_count(dsaf_dev, stringset);
653
654 return sset_count;
655 }
656
657 static int hns_ae_config_loopback(struct hnae_handle *handle,
658 enum hnae_loop loop, int en)
659 {
660 int ret;
661 struct hnae_vf_cb *vf_cb = hns_ae_get_vf_cb(handle);
662 struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle);
663 struct dsaf_device *dsaf_dev = mac_cb->dsaf_dev;
664
665 switch (loop) {
666 case MAC_INTERNALLOOP_PHY:
667 ret = 0;
668 break;
669 case MAC_INTERNALLOOP_SERDES:
670 ret = dsaf_dev->misc_op->cfg_serdes_loopback(vf_cb->mac_cb,
671 !!en);
672 break;
673 case MAC_INTERNALLOOP_MAC:
674 ret = hns_mac_config_mac_loopback(vf_cb->mac_cb, loop, en);
675 break;
676 default:
677 ret = -EINVAL;
678 }
679
680 if (!ret)
681 hns_dsaf_set_inner_lb(mac_cb->dsaf_dev, mac_cb->mac_id, en);
682
683 return ret;
684 }
685
686 void hns_ae_update_led_status(struct hnae_handle *handle)
687 {
688 struct hns_mac_cb *mac_cb;
689
690 assert(handle);
691 mac_cb = hns_get_mac_cb(handle);
692 if (!mac_cb->cpld_ctrl)
693 return;
694 hns_set_led_opt(mac_cb);
695 }
696
697 int hns_ae_cpld_set_led_id(struct hnae_handle *handle,
698 enum hnae_led_state status)
699 {
700 struct hns_mac_cb *mac_cb;
701
702 assert(handle);
703
704 mac_cb = hns_get_mac_cb(handle);
705
706 return hns_cpld_led_set_id(mac_cb, status);
707 }
708
709 void hns_ae_get_regs(struct hnae_handle *handle, void *data)
710 {
711 u32 *p = data;
712 int i;
713 struct hnae_vf_cb *vf_cb = hns_ae_get_vf_cb(handle);
714 struct hns_ppe_cb *ppe_cb = hns_get_ppe_cb(handle);
715
716 hns_ppe_get_regs(ppe_cb, p);
717 p += hns_ppe_get_regs_count();
718
719 hns_rcb_get_common_regs(vf_cb->dsaf_dev->rcb_common[0], p);
720 p += hns_rcb_get_common_regs_count();
721
722 for (i = 0; i < handle->q_num; i++) {
723 hns_rcb_get_ring_regs(handle->qs[i], p);
724 p += hns_rcb_get_ring_regs_count();
725 }
726
727 hns_mac_get_regs(vf_cb->mac_cb, p);
728 p += hns_mac_get_regs_count(vf_cb->mac_cb);
729
730 if (vf_cb->mac_cb->mac_type == HNAE_PORT_SERVICE)
731 hns_dsaf_get_regs(vf_cb->dsaf_dev, vf_cb->port_index, p);
732 }
733
734 int hns_ae_get_regs_len(struct hnae_handle *handle)
735 {
736 u32 total_num;
737 struct hnae_vf_cb *vf_cb = hns_ae_get_vf_cb(handle);
738
739 total_num = hns_ppe_get_regs_count();
740 total_num += hns_rcb_get_common_regs_count();
741 total_num += hns_rcb_get_ring_regs_count() * handle->q_num;
742 total_num += hns_mac_get_regs_count(vf_cb->mac_cb);
743
744 if (vf_cb->mac_cb->mac_type == HNAE_PORT_SERVICE)
745 total_num += hns_dsaf_get_regs_count();
746
747 return total_num;
748 }
749
750 static u32 hns_ae_get_rss_key_size(struct hnae_handle *handle)
751 {
752 return HNS_PPEV2_RSS_KEY_SIZE;
753 }
754
755 static u32 hns_ae_get_rss_indir_size(struct hnae_handle *handle)
756 {
757 return HNS_PPEV2_RSS_IND_TBL_SIZE;
758 }
759
760 static int hns_ae_get_rss(struct hnae_handle *handle, u32 *indir, u8 *key,
761 u8 *hfunc)
762 {
763 struct hns_ppe_cb *ppe_cb = hns_get_ppe_cb(handle);
764
765 /* currently we support only one type of hash function i.e. Toep hash */
766 if (hfunc)
767 *hfunc = ETH_RSS_HASH_TOP;
768
769 /* get the RSS Key required by the user */
770 if (key)
771 memcpy(key, ppe_cb->rss_key, HNS_PPEV2_RSS_KEY_SIZE);
772
773 /* update the current hash->queue mappings from the shadow RSS table */
774 memcpy(indir, ppe_cb->rss_indir_table,
775 HNS_PPEV2_RSS_IND_TBL_SIZE * sizeof(*indir));
776
777 return 0;
778 }
779
780 static int hns_ae_set_rss(struct hnae_handle *handle, const u32 *indir,
781 const u8 *key, const u8 hfunc)
782 {
783 struct hns_ppe_cb *ppe_cb = hns_get_ppe_cb(handle);
784
785 /* set the RSS Hash Key if specififed by the user */
786 if (key)
787 hns_ppe_set_rss_key(ppe_cb, (u32 *)key);
788
789 /* update the shadow RSS table with user specified qids */
790 memcpy(ppe_cb->rss_indir_table, indir,
791 HNS_PPEV2_RSS_IND_TBL_SIZE * sizeof(*indir));
792
793 /* now update the hardware */
794 hns_ppe_set_indir_table(ppe_cb, ppe_cb->rss_indir_table);
795
796 return 0;
797 }
798
799 static struct hnae_ae_ops hns_dsaf_ops = {
800 .get_handle = hns_ae_get_handle,
801 .put_handle = hns_ae_put_handle,
802 .init_queue = hns_ae_init_queue,
803 .fini_queue = hns_ae_fini_queue,
804 .start = hns_ae_start,
805 .stop = hns_ae_stop,
806 .reset = hns_ae_reset,
807 .toggle_ring_irq = hns_ae_toggle_ring_irq,
808 .get_status = hns_ae_get_link_status,
809 .get_info = hns_ae_get_mac_info,
810 .adjust_link = hns_ae_adjust_link,
811 .set_loopback = hns_ae_config_loopback,
812 .get_ring_bdnum_limit = hns_ae_get_ring_bdnum_limit,
813 .get_pauseparam = hns_ae_get_pauseparam,
814 .set_autoneg = hns_ae_set_autoneg,
815 .get_autoneg = hns_ae_get_autoneg,
816 .set_pauseparam = hns_ae_set_pauseparam,
817 .get_coalesce_usecs = hns_ae_get_coalesce_usecs,
818 .get_rx_max_coalesced_frames = hns_ae_get_rx_max_coalesced_frames,
819 .set_coalesce_usecs = hns_ae_set_coalesce_usecs,
820 .set_coalesce_frames = hns_ae_set_coalesce_frames,
821 .get_coalesce_range = hns_ae_get_coalesce_range,
822 .set_promisc_mode = hns_ae_set_promisc_mode,
823 .set_mac_addr = hns_ae_set_mac_address,
824 .set_mc_addr = hns_ae_set_multicast_one,
825 .set_mtu = hns_ae_set_mtu,
826 .update_stats = hns_ae_update_stats,
827 .set_tso_stats = hns_ae_set_tso_stats,
828 .get_stats = hns_ae_get_stats,
829 .get_strings = hns_ae_get_strings,
830 .get_sset_count = hns_ae_get_sset_count,
831 .update_led_status = hns_ae_update_led_status,
832 .set_led_id = hns_ae_cpld_set_led_id,
833 .get_regs = hns_ae_get_regs,
834 .get_regs_len = hns_ae_get_regs_len,
835 .get_rss_key_size = hns_ae_get_rss_key_size,
836 .get_rss_indir_size = hns_ae_get_rss_indir_size,
837 .get_rss = hns_ae_get_rss,
838 .set_rss = hns_ae_set_rss
839 };
840
841 int hns_dsaf_ae_init(struct dsaf_device *dsaf_dev)
842 {
843 struct hnae_ae_dev *ae_dev = &dsaf_dev->ae_dev;
844 static atomic_t id = ATOMIC_INIT(-1);
845
846 switch (dsaf_dev->dsaf_ver) {
847 case AE_VERSION_1:
848 hns_dsaf_ops.toggle_ring_irq = hns_ae_toggle_ring_irq;
849 break;
850 case AE_VERSION_2:
851 hns_dsaf_ops.toggle_ring_irq = hns_aev2_toggle_ring_irq;
852 break;
853 default:
854 break;
855 }
856
857 snprintf(ae_dev->name, AE_NAME_SIZE, "%s%d", DSAF_DEVICE_NAME,
858 (int)atomic_inc_return(&id));
859 ae_dev->ops = &hns_dsaf_ops;
860 ae_dev->dev = dsaf_dev->dev;
861
862 return hnae_ae_register(ae_dev, THIS_MODULE);
863 }
864
865 void hns_dsaf_ae_uninit(struct dsaf_device *dsaf_dev)
866 {
867 hnae_ae_unregister(&dsaf_dev->ae_dev);
868 }
This page took 0.047871 seconds and 5 git commands to generate.