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