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