1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0) */
2 /* Copyright (C) 2014-2017 aQuantia Corporation. */
4 /* File hw_atl_utils.h: Declaration of common functions for Atlantic hardware
11 #define HW_ATL_FLUSH() { (void)aq_hw_read_reg(self, 0x10); }
13 /* Hardware tx descriptor */
29 } __attribute__((__packed__));
32 } __attribute__((__packed__));
34 /* Hardware tx context descriptor */
53 } __attribute__((__packed__));
54 } __attribute__((__packed__));
56 enum aq_tx_desc_type {
57 tx_desc_type_desc = 1,
66 tx_desc_cmd_lso = 0x10,
67 tx_desc_cmd_wb = 0x20,
71 /* Hardware rx descriptor */
75 } __attribute__((__packed__));
77 /* Hardware rx descriptor writeback */
78 struct hw_atl_rxd_wb_s {
91 } __attribute__((__packed__));
93 struct hw_atl_stats_s {
109 } __attribute__((__packed__));
119 } __attribute__((__packed__));
121 struct hw_aq_atl_utils_fw_rpc {
148 u32 next_wol_pattern_offset;
152 u8 ipv4_source_address[4];
153 u8 ipv4_dest_address[4];
154 u16 tcp_source_port_number;
155 u16 tcp_dest_port_number;
156 } ipv4_tcp_syn_parameters;
160 u8 ipv6_source_address[16];
161 u8 ipv6_dest_address[16];
162 u16 tcp_source_port_number;
163 u16 tcp_dest_port_number;
164 } ipv6_tcp_syn_parameters;
168 } eapol_request_id_message_parameters;
176 } wol_bit_map_pattern;
179 } wol_magic_packet_pattern;
187 } msg_msm_pfc_quantas;
193 u32 aq_pm_wol_reason_arp_v4_pkt : 1;
194 u32 aq_pm_wol_reason_ipv4_ping_pkt : 1;
195 u32 aq_pm_wol_reason_ipv6_ns_pkt : 1;
196 u32 aq_pm_wol_reason_ipv6_ping_pkt : 1;
197 u32 aq_pm_wol_reason_link_up : 1;
198 u32 aq_pm_wol_reason_link_down : 1;
199 u32 aq_pm_wol_reason_maximum : 1;
209 u32 protocol_offload_type;
210 u32 protocol_offload_id;
211 u32 next_protocol_offload_offset;
216 u8 remote_ipv4_addr[4];
217 u8 host_ipv4_addr[4];
228 } __attribute__((__packed__));
230 struct hw_aq_atl_utils_mbox_header {
234 } __attribute__((__packed__));
242 u32 cable_diag_data[4];
246 } __attribute__((__packed__));
248 struct hw_aq_atl_utils_mbox {
249 struct hw_aq_atl_utils_mbox_header header;
250 struct hw_atl_stats_s stats;
251 struct hw_aq_info info;
252 } __attribute__((__packed__));
255 typedef u16 in_port_t;
256 typedef u32 ip4_addr_t;
258 typedef short int16_t;
259 typedef u32 fw_offset_t;
263 } __attribute__((__packed__));
265 struct offload_ka_v4 {
267 in_port_t local_port;
268 in_port_t remote_port;
269 u8 remote_mac_addr[6];
274 ip4_addr_t remote_ip;
275 } __attribute__((__packed__));
277 struct offload_ka_v6 {
279 in_port_t local_port;
280 in_port_t remote_port;
281 u8 remote_mac_addr[6];
285 struct ip6_addr local_ip;
286 struct ip6_addr remote_ip;
287 } __attribute__((__packed__));
289 struct offload_ip_info {
290 u8 v4_local_addr_count;
292 u8 v6_local_addr_count;
295 fw_offset_t v4_prefix;
297 fw_offset_t v6_prefix;
298 } __attribute__((__packed__));
300 struct offload_port_info {
303 fw_offset_t udp_port;
304 fw_offset_t tcp_port;
305 } __attribute__((__packed__));
307 struct offload_ka_info {
314 } __attribute__((__packed__));
316 struct offload_rr_info {
321 } __attribute__((__packed__));
323 struct offload_info {
324 u32 version; // current version is 0x00000000
325 u32 len; // The whole structure length
326 // including the variable-size buf
327 u8 mac_addr[6]; // 8 bytes to keep alignment. Only
328 // first 6 meaningful.
332 struct offload_ip_info ips;
333 struct offload_port_info ports;
334 struct offload_ka_info kas;
335 struct offload_rr_info rrs;
337 } __attribute__((__packed__));
339 struct smbus_read_request {
340 u32 offset; /* not used */
344 } __attribute__((__packed__));
346 struct smbus_write_request {
347 u32 offset; /* not used */
351 } __attribute__((__packed__));
353 #define HAL_ATLANTIC_UTILS_CHIP_MIPS 0x00000001U
354 #define HAL_ATLANTIC_UTILS_CHIP_TPO2 0x00000002U
355 #define HAL_ATLANTIC_UTILS_CHIP_RPF2 0x00000004U
356 #define HAL_ATLANTIC_UTILS_CHIP_MPI_AQ 0x00000010U
357 #define HAL_ATLANTIC_UTILS_CHIP_REVISION_A0 0x01000000U
358 #define HAL_ATLANTIC_UTILS_CHIP_REVISION_B0 0x02000000U
359 #define HAL_ATLANTIC_UTILS_CHIP_REVISION_B1 0x04000000U
362 #define IS_CHIP_FEATURE(_F_) (HAL_ATLANTIC_UTILS_CHIP_##_F_ & \
365 enum hal_atl_utils_fw_state_e {
372 #define HAL_ATLANTIC_RATE_10G BIT(0)
373 #define HAL_ATLANTIC_RATE_5G BIT(1)
374 #define HAL_ATLANTIC_RATE_5GSR BIT(2)
375 #define HAL_ATLANTIC_RATE_2GS BIT(3)
376 #define HAL_ATLANTIC_RATE_1G BIT(4)
377 #define HAL_ATLANTIC_RATE_100M BIT(5)
378 #define HAL_ATLANTIC_RATE_INVALID BIT(6)
380 #define HAL_ATLANTIC_UTILS_FW_MSG_PING 1U
381 #define HAL_ATLANTIC_UTILS_FW_MSG_ARP 2U
382 #define HAL_ATLANTIC_UTILS_FW_MSG_INJECT 3U
383 #define HAL_ATLANTIC_UTILS_FW_MSG_WOL_ADD 4U
384 #define HAL_ATLANTIC_UTILS_FW_MSG_WOL_DEL 5U
385 #define HAL_ATLANTIC_UTILS_FW_MSG_ENABLE_WAKEUP 6U
386 #define HAL_ATLANTIC_UTILS_FW_MSG_MSM_PFC 7U
387 #define HAL_ATLANTIC_UTILS_FW_MSG_PROVISIONING 8U
388 #define HAL_ATLANTIC_UTILS_FW_MSG_OFFLOAD_ADD 9U
389 #define HAL_ATLANTIC_UTILS_FW_MSG_OFFLOAD_DEL 10U
390 #define HAL_ATLANTIC_UTILS_FW_MSG_CABLE_DIAG 13U // 0xd
392 #define SMBUS_READ_REQUEST BIT(13)
393 #define SMBUS_WRITE_REQUEST BIT(14)
394 #define SMBUS_DEVICE_ID 0x50
396 enum hw_atl_fw2x_rate {
397 FW2X_RATE_100M = 0x20,
398 FW2X_RATE_1G = 0x100,
399 FW2X_RATE_2G5 = 0x200,
400 FW2X_RATE_5G = 0x400,
401 FW2X_RATE_10G = 0x800,
404 enum hw_atl_fw2x_caps_lo {
405 CAPS_LO_10BASET_HD = 0x00,
407 CAPS_LO_100BASETX_HD,
408 CAPS_LO_100BASET4_HD,
409 CAPS_LO_100BASET2_HD,
410 CAPS_LO_100BASETX_FD,
411 CAPS_LO_100BASET2_FD,
412 CAPS_LO_1000BASET_HD,
413 CAPS_LO_1000BASET_FD,
414 CAPS_LO_2P5GBASET_FD,
419 enum hw_atl_fw2x_caps_hi {
420 CAPS_HI_RESERVED1 = 0x00,
424 CAPS_HI_ASYMMETRIC_PAUSE,
425 CAPS_HI_100BASETX_EEE,
428 CAPS_HI_1000BASET_FD_EEE,
429 CAPS_HI_2P5GBASET_FD_EEE,
430 CAPS_HI_5GBASET_FD_EEE,
431 CAPS_HI_10GBASET_FD_EEE,
441 CAPS_HI_MEDIA_DETECT,
446 CAPS_HI_EXT_LOOPBACK,
447 CAPS_HI_INT_LOOPBACK,
451 CAPS_HI_TRANSACTION_ID,
456 struct aq_hw_link_status_s;
458 int hw_atl_utils_initfw(struct aq_hw_s *self, const struct aq_fw_ops **fw_ops);
460 int hw_atl_utils_soft_reset(struct aq_hw_s *self);
462 void hw_atl_utils_hw_chip_features_init(struct aq_hw_s *self, u32 *p);
464 int hw_atl_utils_mpi_read_mbox(struct aq_hw_s *self,
465 struct hw_aq_atl_utils_mbox_header *pmbox);
467 void hw_atl_utils_mpi_read_stats(struct aq_hw_s *self,
468 struct hw_aq_atl_utils_mbox *pmbox);
470 void hw_atl_utils_mpi_set(struct aq_hw_s *self,
471 enum hal_atl_utils_fw_state_e state,
474 int hw_atl_utils_mpi_get_link_status(struct aq_hw_s *self);
476 unsigned int hw_atl_utils_mbps_2_speed_index(unsigned int mbps);
478 unsigned int hw_atl_utils_hw_get_reg_length(void);
480 int hw_atl_utils_hw_get_regs(struct aq_hw_s *self,
483 int hw_atl_utils_hw_set_power(struct aq_hw_s *self,
484 unsigned int power_state);
486 int hw_atl_utils_hw_deinit(struct aq_hw_s *self);
488 int hw_atl_utils_get_fw_version(struct aq_hw_s *self, u32 *fw_version);
490 int hw_atl_utils_update_stats(struct aq_hw_s *self);
492 struct aq_stats_s *hw_atl_utils_get_hw_stats(struct aq_hw_s *self);
494 int hw_atl_utils_fw_downld_dwords(struct aq_hw_s *self, u32 a,
497 int hw_atl_utils_fw_upload_dwords(struct aq_hw_s *self, u32 a, u32 *p,
500 int hw_atl_utils_fw_set_wol(struct aq_hw_s *self, bool wol_enabled, u8 *mac);
502 int hw_atl_utils_fw_rpc_call(struct aq_hw_s *self, unsigned int rpc_size);
504 int hw_atl_utils_fw_rpc_wait(struct aq_hw_s *self,
505 struct hw_aq_atl_utils_fw_rpc **rpc);
507 extern const struct aq_fw_ops aq_fw_1x_ops;
508 extern const struct aq_fw_ops aq_fw_2x_ops;
510 #endif /* HW_ATL_UTILS_H */