xref: /linux/drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils.h (revision f6a7a4bcc5d3402a44ef3344157ba4e0420317d1)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Atlantic Network Driver
3  * Copyright (C) 2020 Marvell International Ltd.
4  */
5 
6 #ifndef HW_ATL2_UTILS_H
7 #define HW_ATL2_UTILS_H
8 
9 #include "aq_hw.h"
10 
11 /* Hardware tx launch time descriptor */
12 struct hw_atl2_txts_s {
13 	__le64 ts;
14 	__le32 ctrl;
15 	u32 reserved;
16 };
17 
18 #define HW_ATL2_TXTS_DD	BIT(3)
19 #define HW_ATL2_TXTS_TS_VALID   BIT(20)
20 
21 /* F W    A P I */
22 
23 struct link_options_s {
24 	u8 link_up:1;
25 	u8 link_renegotiate:1;
26 	u8 minimal_link_speed:1;
27 	u8 internal_loopback:1;
28 	u8 external_loopback:1;
29 	u8 rate_10M_hd:1;
30 	u8 rate_100M_hd:1;
31 	u8 rate_1G_hd:1;
32 
33 	u8 rate_10M:1;
34 	u8 rate_100M:1;
35 	u8 rate_1G:1;
36 	u8 rate_2P5G:1;
37 	u8 rate_N2P5G:1;
38 	u8 rate_5G:1;
39 	u8 rate_N5G:1;
40 	u8 rate_10G:1;
41 
42 	u8 eee_100M:1;
43 	u8 eee_1G:1;
44 	u8 eee_2P5G:1;
45 	u8 eee_5G:1;
46 	u8 eee_10G:1;
47 	u8 rsvd3:3;
48 
49 	u8 pause_rx:1;
50 	u8 pause_tx:1;
51 	u8 rsvd4:1;
52 	u8 downshift:1;
53 	u8 downshift_retry:4;
54 };
55 
56 struct link_control_s {
57 	u8 mode:4;
58 	u8 disable_crc_corruption:1;
59 	u8 discard_short_frames:1;
60 	u8 flow_control_mode:1;
61 	u8 disable_length_check:1;
62 
63 	u8 discard_errored_frames:1;
64 	u8 control_frame_enable:1;
65 	u8 enable_tx_padding:1;
66 	u8 enable_crc_forwarding:1;
67 	u8 enable_frame_padding_removal_rx: 1;
68 	u8 promiscuous_mode: 1;
69 	u8 rsvd:2;
70 
71 	u16 rsvd2;
72 };
73 
74 struct thermal_shutdown_s {
75 	u8 enable:1;
76 	u8 warning_enable:1;
77 	u8 rsvd:6;
78 
79 	u8 shutdown_temperature;
80 	u8 cold_temperature;
81 	u8 warning_temperature;
82 };
83 
84 struct mac_address_s {
85 	u8 mac_address[6];
86 };
87 
88 struct mac_address_aligned_s {
89 	struct mac_address_s aligned;
90 	u16 rsvd;
91 };
92 
93 struct sleep_proxy_s {
94 	struct wake_on_lan_s {
95 		u8 wake_on_magic_packet:1;
96 		u8 wake_on_pattern:1;
97 		u8 wake_on_link_up:1;
98 		u8 wake_on_link_down:1;
99 		u8 wake_on_ping:1;
100 		u8 wake_on_timer:1;
101 		u8 rsvd:2;
102 
103 		u8 rsvd2;
104 		u16 rsvd3;
105 
106 		u32 link_up_timeout;
107 		u32 link_down_timeout;
108 		u32 timer;
109 	} wake_on_lan;
110 
111 	struct {
112 		u32 mask[4];
113 		u32 crc32;
114 	} wake_up_pattern[8];
115 
116 	struct __packed {
117 		u8 arp_responder:1;
118 		u8 echo_responder:1;
119 		u8 igmp_client:1;
120 		u8 echo_truncate:1;
121 		u8 address_guard:1;
122 		u8 ignore_fragmented:1;
123 		u8 rsvd:2;
124 
125 		u16 echo_max_len;
126 		u8 rsvd2;
127 	} ipv4_offload;
128 
129 	u32 ipv4_offload_addr[8];
130 	u32 reserved[8];
131 
132 	struct __packed {
133 		u8 ns_responder:1;
134 		u8 echo_responder:1;
135 		u8 mld_client:1;
136 		u8 echo_truncate:1;
137 		u8 address_guard:1;
138 		u8 rsvd:3;
139 
140 		u16 echo_max_len;
141 		u8 rsvd2;
142 	} ipv6_offload;
143 
144 	u32 ipv6_offload_addr[16][4];
145 
146 	struct {
147 		u16 port[16];
148 	} tcp_port_offload;
149 
150 	struct {
151 		u16 port[16];
152 	} udp_port_offload;
153 
154 	struct {
155 		u32 retry_count;
156 		u32 retry_interval;
157 	} ka4_offload;
158 
159 	struct {
160 		u32 timeout;
161 		u16 local_port;
162 		u16 remote_port;
163 		u8 remote_mac_addr[6];
164 		u16 rsvd;
165 		u32 rsvd2;
166 		u32 rsvd3;
167 		u16 rsvd4;
168 		u16 win_size;
169 		u32 seq_num;
170 		u32 ack_num;
171 		u32 local_ip;
172 		u32 remote_ip;
173 	} ka4_connection[16];
174 
175 	struct {
176 		u32 retry_count;
177 		u32 retry_interval;
178 	} ka6_offload;
179 
180 	struct {
181 		u32 timeout;
182 		u16 local_port;
183 		u16 remote_port;
184 		u8 remote_mac_addr[6];
185 		u16 rsvd;
186 		u32 rsvd2;
187 		u32 rsvd3;
188 		u16 rsvd4;
189 		u16 win_size;
190 		u32 seq_num;
191 		u32 ack_num;
192 		u32 local_ip[4];
193 		u32 remote_ip[4];
194 	} ka6_connection[16];
195 
196 	struct {
197 		u32 rr_count;
198 		u32 rr_buf_len;
199 		u32 idx_offset;
200 		u32 rr__offset;
201 	} mdns_offload;
202 };
203 
204 struct pause_quanta_s {
205 	u16 quanta_10M;
206 	u16 threshold_10M;
207 	u16 quanta_100M;
208 	u16 threshold_100M;
209 	u16 quanta_1G;
210 	u16 threshold_1G;
211 	u16 quanta_2P5G;
212 	u16 threshold_2P5G;
213 	u16 quanta_5G;
214 	u16 threshold_5G;
215 	u16 quanta_10G;
216 	u16 threshold_10G;
217 };
218 
219 struct data_buffer_status_s {
220 	u32 data_offset;
221 	u32 data_length;
222 };
223 
224 struct device_caps_s {
225 	u8 finite_flashless:1;
226 	u8 cable_diag:1;
227 	u8 ncsi:1;
228 	u8 avb:1;
229 	u8 rsvd:4;
230 
231 	u8 rsvd2;
232 	u16 rsvd3;
233 	u32 rsvd4;
234 };
235 
236 struct version_s {
237 	struct bundle_version_t {
238 		u8 major;
239 		u8 minor;
240 		u16 build;
241 	} bundle;
242 	struct mac_version_t {
243 		u8 major;
244 		u8 minor;
245 		u16 build;
246 	} mac;
247 	struct phy_version_t {
248 		u8 major;
249 		u8 minor;
250 		u16 build;
251 	} phy;
252 	u32 drv_iface_ver:4;
253 	u32 rsvd:28;
254 };
255 
256 struct link_status_s {
257 	u8 link_state:4;
258 	u8 link_rate:4;
259 
260 	u8 pause_tx:1;
261 	u8 pause_rx:1;
262 	u8 eee:1;
263 	u8 duplex:1;
264 	u8 rsvd:4;
265 
266 	u16 rsvd2;
267 };
268 
269 struct wol_status_s {
270 	u8 wake_count;
271 	u8 wake_reason;
272 
273 	u16 wake_up_packet_length :12;
274 	u16 wake_up_pattern_number :3;
275 	u16 rsvd:1;
276 
277 	u32 wake_up_packet[379];
278 };
279 
280 struct mac_health_monitor_s {
281 	u8 mac_ready:1;
282 	u8 mac_fault:1;
283 	u8 mac_flashless_finished:1;
284 	u8 rsvd:5;
285 
286 	u8 mac_temperature;
287 	u16 mac_heart_beat;
288 	u16 mac_fault_code;
289 	u16 rsvd2;
290 };
291 
292 struct phy_health_monitor_s {
293 	u8 phy_ready:1;
294 	u8 phy_fault:1;
295 	u8 phy_hot_warning:1;
296 	u8 rsvd:5;
297 
298 	u8 phy_temperature;
299 	u16 phy_heart_beat;
300 	u16 phy_fault_code;
301 	u16 rsvd2;
302 };
303 
304 struct device_link_caps_s {
305 	u8 rsvd:3;
306 	u8 internal_loopback:1;
307 	u8 external_loopback:1;
308 	u8 rate_10M_hd:1;
309 	u8 rate_100M_hd:1;
310 	u8 rate_1G_hd:1;
311 
312 	u8 rate_10M:1;
313 	u8 rate_100M:1;
314 	u8 rate_1G:1;
315 	u8 rate_2P5G:1;
316 	u8 rate_N2P5G:1;
317 	u8 rate_5G:1;
318 	u8 rate_N5G:1;
319 	u8 rate_10G:1;
320 
321 	u8 rsvd3:1;
322 	u8 eee_100M:1;
323 	u8 eee_1G:1;
324 	u8 eee_2P5G:1;
325 	u8 rsvd4:1;
326 	u8 eee_5G:1;
327 	u8 rsvd5:1;
328 	u8 eee_10G:1;
329 
330 	u8 pause_rx:1;
331 	u8 pause_tx:1;
332 	u8 pfc:1;
333 	u8 downshift:1;
334 	u8 downshift_retry:4;
335 };
336 
337 struct sleep_proxy_caps_s {
338 	u8 ipv4_offload:1;
339 	u8 ipv6_offload:1;
340 	u8 tcp_port_offload:1;
341 	u8 udp_port_offload:1;
342 	u8 ka4_offload:1;
343 	u8 ka6_offload:1;
344 	u8 mdns_offload:1;
345 	u8 wake_on_ping:1;
346 
347 	u8 wake_on_magic_packet:1;
348 	u8 wake_on_pattern:1;
349 	u8 wake_on_timer:1;
350 	u8 wake_on_link:1;
351 	u8 wake_patterns_count:4;
352 
353 	u8 ipv4_count;
354 	u8 ipv6_count;
355 
356 	u8 tcp_port_offload_count;
357 	u8 udp_port_offload_count;
358 
359 	u8 tcp4_ka_count;
360 	u8 tcp6_ka_count;
361 
362 	u8 igmp_offload:1;
363 	u8 mld_offload:1;
364 	u8 rsvd:6;
365 
366 	u8 rsvd2;
367 	u16 rsvd3;
368 };
369 
370 struct lkp_link_caps_s {
371 	u8 rsvd:5;
372 	u8 rate_10M_hd:1;
373 	u8 rate_100M_hd:1;
374 	u8 rate_1G_hd:1;
375 
376 	u8 rate_10M:1;
377 	u8 rate_100M:1;
378 	u8 rate_1G:1;
379 	u8 rate_2P5G:1;
380 	u8 rate_N2P5G:1;
381 	u8 rate_5G:1;
382 	u8 rate_N5G:1;
383 	u8 rate_10G:1;
384 
385 	u8 rsvd2:1;
386 	u8 eee_100M:1;
387 	u8 eee_1G:1;
388 	u8 eee_2P5G:1;
389 	u8 rsvd3:1;
390 	u8 eee_5G:1;
391 	u8 rsvd4:1;
392 	u8 eee_10G:1;
393 
394 	u8 pause_rx:1;
395 	u8 pause_tx:1;
396 	u8 rsvd5:6;
397 };
398 
399 struct core_dump_s {
400 	u32 reg0;
401 	u32 reg1;
402 	u32 reg2;
403 
404 	u32 hi;
405 	u32 lo;
406 
407 	u32 regs[32];
408 };
409 
410 struct trace_s {
411 	u32 sync_counter;
412 	u32 mem_buffer[0x1ff];
413 };
414 
415 struct cable_diag_control_s {
416 	u8 toggle :1;
417 	u8 rsvd:7;
418 
419 	u8 wait_timeout_sec;
420 	u16 rsvd2;
421 };
422 
423 struct cable_diag_lane_data_s {
424 	u8 result_code;
425 	u8 dist;
426 	u8 far_dist;
427 	u8 rsvd;
428 };
429 
430 struct cable_diag_status_s {
431 	struct cable_diag_lane_data_s lane_data[4];
432 	u8 transact_id;
433 	u8 status:4;
434 	u8 rsvd:4;
435 	u16 rsvd2;
436 };
437 
438 struct statistics_a0_s {
439 	struct {
440 		u32 link_up;
441 		u32 link_down;
442 	} link;
443 
444 	struct {
445 		u64 tx_unicast_octets;
446 		u64 tx_multicast_octets;
447 		u64 tx_broadcast_octets;
448 		u64 rx_unicast_octets;
449 		u64 rx_multicast_octets;
450 		u64 rx_broadcast_octets;
451 
452 		u32 tx_unicast_frames;
453 		u32 tx_multicast_frames;
454 		u32 tx_broadcast_frames;
455 		u32 tx_errors;
456 
457 		u32 rx_unicast_frames;
458 		u32 rx_multicast_frames;
459 		u32 rx_broadcast_frames;
460 		u32 rx_dropped_frames;
461 		u32 rx_error_frames;
462 
463 		u32 tx_good_frames;
464 		u32 rx_good_frames;
465 		u32 reserve_fw_gap;
466 	} msm;
467 	u32 main_loop_cycles;
468 	u32 reserve_fw_gap;
469 };
470 
471 struct __packed statistics_b0_s {
472 	u64 rx_good_octets;
473 	u64 rx_pause_frames;
474 	u64 rx_good_frames;
475 	u64 rx_errors;
476 	u64 rx_unicast_frames;
477 	u64 rx_multicast_frames;
478 	u64 rx_broadcast_frames;
479 
480 	u64 tx_good_octets;
481 	u64 tx_pause_frames;
482 	u64 tx_good_frames;
483 	u64 tx_errors;
484 	u64 tx_unicast_frames;
485 	u64 tx_multicast_frames;
486 	u64 tx_broadcast_frames;
487 
488 	u32 main_loop_cycles;
489 };
490 
491 struct __packed statistics_s {
492 	union __packed {
493 		struct statistics_a0_s a0;
494 		struct statistics_b0_s b0;
495 	};
496 };
497 
498 struct filter_caps_s {
499 	u8 l2_filters_base_index:6;
500 	u8 flexible_filter_mask:2;
501 	u8 l2_filter_count;
502 	u8 ethertype_filter_base_index;
503 	u8 ethertype_filter_count;
504 
505 	u8 vlan_filter_base_index;
506 	u8 vlan_filter_count;
507 	u8 l3_ip4_filter_base_index:4;
508 	u8 l3_ip4_filter_count:4;
509 	u8 l3_ip6_filter_base_index:4;
510 	u8 l3_ip6_filter_count:4;
511 
512 	u8 l4_filter_base_index:4;
513 	u8 l4_filter_count:4;
514 	u8 l4_flex_filter_base_index:4;
515 	u8 l4_flex_filter_count:4;
516 	u8 rslv_tbl_base_index;
517 	u8 rslv_tbl_count;
518 };
519 
520 struct request_policy_s {
521 	struct {
522 		u8 all:1;
523 		u8 mcast:1;
524 		u8 rx_queue_tc_index:5;
525 		u8 queue_or_tc:1;
526 	} promisc;
527 
528 	struct {
529 		u8 accept:1;
530 		u8 rsvd:1;
531 		u8 rx_queue_tc_index:5;
532 		u8 queue_or_tc:1;
533 	} bcast;
534 
535 	struct {
536 		u8 accept:1;
537 		u8 rsvd:1;
538 		u8 rx_queue_tc_index:5;
539 		u8 queue_or_tc:1;
540 	} mcast;
541 
542 	u8 rsvd:8;
543 };
544 
545 struct fw_interface_in {
546 	u32 mtu;
547 	u32 rsvd1;
548 	struct mac_address_aligned_s mac_address;
549 	struct link_control_s link_control;
550 	u32 rsvd2;
551 	struct link_options_s link_options;
552 	u32 rsvd3;
553 	struct thermal_shutdown_s thermal_shutdown;
554 	u32 rsvd4;
555 	struct sleep_proxy_s sleep_proxy;
556 	u32 rsvd5;
557 	struct pause_quanta_s pause_quanta[8];
558 	struct cable_diag_control_s cable_diag_control;
559 	u32 rsvd6;
560 	struct data_buffer_status_s data_buffer_status;
561 	u32 rsvd7;
562 	struct request_policy_s request_policy;
563 };
564 
565 struct transaction_counter_s {
566 	u16 transaction_cnt_a;
567 	u16 transaction_cnt_b;
568 };
569 
570 struct management_status_s {
571 	struct mac_address_s mac_address;
572 	u16 vlan;
573 
574 	struct{
575 		u32 enable : 1;
576 		u32 rsvd:31;
577 	} flags;
578 
579 	u32 rsvd1;
580 	u32 rsvd2;
581 	u32 rsvd3;
582 	u32 rsvd4;
583 	u32 rsvd5;
584 };
585 
586 struct __packed fw_interface_out {
587 	struct transaction_counter_s transaction_id;
588 	struct version_s version;
589 	struct link_status_s link_status;
590 	struct wol_status_s wol_status;
591 	u32 rsvd;
592 	u32 rsvd2;
593 	struct mac_health_monitor_s mac_health_monitor;
594 	u32 rsvd3;
595 	u32 rsvd4;
596 	struct phy_health_monitor_s phy_health_monitor;
597 	u32 rsvd5;
598 	u32 rsvd6;
599 	struct cable_diag_status_s cable_diag_status;
600 	u32 rsvd7;
601 	struct device_link_caps_s device_link_caps;
602 	u32 rsvd8;
603 	struct sleep_proxy_caps_s sleep_proxy_caps;
604 	u32 rsvd9;
605 	struct lkp_link_caps_s lkp_link_caps;
606 	u32 rsvd10;
607 	struct core_dump_s core_dump;
608 	u32 rsvd11;
609 	struct statistics_s stats;
610 	struct filter_caps_s filter_caps;
611 	struct device_caps_s device_caps;
612 	u32 rsvd13;
613 	struct management_status_s management_status;
614 	u32 reserve[21];
615 	struct trace_s trace;
616 };
617 
618 #define  AQ_A2_FW_LINK_RATE_INVALID 0
619 #define  AQ_A2_FW_LINK_RATE_10M     1
620 #define  AQ_A2_FW_LINK_RATE_100M    2
621 #define  AQ_A2_FW_LINK_RATE_1G      3
622 #define  AQ_A2_FW_LINK_RATE_2G5     4
623 #define  AQ_A2_FW_LINK_RATE_5G      5
624 #define  AQ_A2_FW_LINK_RATE_10G     6
625 
626 #define  AQ_HOST_MODE_INVALID      0U
627 #define  AQ_HOST_MODE_ACTIVE       1U
628 #define  AQ_HOST_MODE_SLEEP_PROXY  2U
629 #define  AQ_HOST_MODE_LOW_POWER    3U
630 #define  AQ_HOST_MODE_SHUTDOWN     4U
631 
632 #define  AQ_A2_FW_INTERFACE_A0     0
633 #define  AQ_A2_FW_INTERFACE_B0     1
634 
635 int hw_atl2_utils_initfw(struct aq_hw_s *self, const struct aq_fw_ops **fw_ops);
636 
637 int hw_atl2_utils_soft_reset(struct aq_hw_s *self);
638 
639 int hw_atl2_utils_hw_get_regs(struct aq_hw_s *self,
640 			      const struct aq_hw_caps_s *aq_hw_caps,
641 			      u32 *regs_buff);
642 
643 u32 hw_atl2_utils_get_fw_version(struct aq_hw_s *self);
644 
645 int hw_atl2_utils_get_filter_caps(struct aq_hw_s *self);
646 
647 extern const struct aq_fw_ops aq_a2_fw_ops;
648 
649 #endif /* HW_ATL2_UTILS_H */
650