18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* Atlantic Network Driver 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright (C) 2014-2019 aQuantia Corporation 58c2ecf20Sopenharmony_ci * Copyright (C) 2019-2020 Marvell International Ltd. 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci/* File aq_nic.h: Declaration of common code for NIC. */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#ifndef AQ_NIC_H 118c2ecf20Sopenharmony_ci#define AQ_NIC_H 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include "aq_common.h" 148c2ecf20Sopenharmony_ci#include "aq_rss.h" 158c2ecf20Sopenharmony_ci#include "aq_hw.h" 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_cistruct aq_ring_s; 188c2ecf20Sopenharmony_cistruct aq_hw_ops; 198c2ecf20Sopenharmony_cistruct aq_fw_s; 208c2ecf20Sopenharmony_cistruct aq_vec_s; 218c2ecf20Sopenharmony_cistruct aq_macsec_cfg; 228c2ecf20Sopenharmony_cistruct aq_ptp_s; 238c2ecf20Sopenharmony_cienum aq_rx_filter_type; 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_cienum aq_fc_mode { 268c2ecf20Sopenharmony_ci AQ_NIC_FC_OFF = 0, 278c2ecf20Sopenharmony_ci AQ_NIC_FC_TX, 288c2ecf20Sopenharmony_ci AQ_NIC_FC_RX, 298c2ecf20Sopenharmony_ci AQ_NIC_FC_FULL, 308c2ecf20Sopenharmony_ci}; 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_cistruct aq_fc_info { 338c2ecf20Sopenharmony_ci enum aq_fc_mode req; 348c2ecf20Sopenharmony_ci enum aq_fc_mode cur; 358c2ecf20Sopenharmony_ci}; 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_cistruct aq_nic_cfg_s { 388c2ecf20Sopenharmony_ci const struct aq_hw_caps_s *aq_hw_caps; 398c2ecf20Sopenharmony_ci u64 features; 408c2ecf20Sopenharmony_ci u32 rxds; /* rx ring size, descriptors # */ 418c2ecf20Sopenharmony_ci u32 txds; /* tx ring size, descriptors # */ 428c2ecf20Sopenharmony_ci u32 vecs; /* allocated rx/tx vectors */ 438c2ecf20Sopenharmony_ci u32 link_irq_vec; 448c2ecf20Sopenharmony_ci u32 irq_type; 458c2ecf20Sopenharmony_ci u32 itr; 468c2ecf20Sopenharmony_ci u16 rx_itr; 478c2ecf20Sopenharmony_ci u16 tx_itr; 488c2ecf20Sopenharmony_ci u32 rxpageorder; 498c2ecf20Sopenharmony_ci u32 num_rss_queues; 508c2ecf20Sopenharmony_ci u32 mtu; 518c2ecf20Sopenharmony_ci struct aq_fc_info fc; 528c2ecf20Sopenharmony_ci u32 link_speed_msk; 538c2ecf20Sopenharmony_ci u32 wol; 548c2ecf20Sopenharmony_ci u8 is_vlan_rx_strip; 558c2ecf20Sopenharmony_ci u8 is_vlan_tx_insert; 568c2ecf20Sopenharmony_ci bool is_vlan_force_promisc; 578c2ecf20Sopenharmony_ci u16 is_mc_list_enabled; 588c2ecf20Sopenharmony_ci u16 mc_list_count; 598c2ecf20Sopenharmony_ci bool is_autoneg; 608c2ecf20Sopenharmony_ci bool is_polling; 618c2ecf20Sopenharmony_ci bool is_rss; 628c2ecf20Sopenharmony_ci bool is_lro; 638c2ecf20Sopenharmony_ci bool is_qos; 648c2ecf20Sopenharmony_ci bool is_ptp; 658c2ecf20Sopenharmony_ci bool is_media_detect; 668c2ecf20Sopenharmony_ci int downshift_counter; 678c2ecf20Sopenharmony_ci enum aq_tc_mode tc_mode; 688c2ecf20Sopenharmony_ci u32 priv_flags; 698c2ecf20Sopenharmony_ci u8 tcs; 708c2ecf20Sopenharmony_ci u8 prio_tc_map[8]; 718c2ecf20Sopenharmony_ci u32 tc_max_rate[AQ_CFG_TCS_MAX]; 728c2ecf20Sopenharmony_ci unsigned long tc_min_rate_msk; 738c2ecf20Sopenharmony_ci u32 tc_min_rate[AQ_CFG_TCS_MAX]; 748c2ecf20Sopenharmony_ci struct aq_rss_parameters aq_rss; 758c2ecf20Sopenharmony_ci u32 eee_speeds; 768c2ecf20Sopenharmony_ci}; 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci#define AQ_NIC_FLAG_STARTED 0x00000004U 798c2ecf20Sopenharmony_ci#define AQ_NIC_FLAG_STOPPING 0x00000008U 808c2ecf20Sopenharmony_ci#define AQ_NIC_FLAG_RESETTING 0x00000010U 818c2ecf20Sopenharmony_ci#define AQ_NIC_FLAG_CLOSING 0x00000020U 828c2ecf20Sopenharmony_ci#define AQ_NIC_PTP_DPATH_UP 0x02000000U 838c2ecf20Sopenharmony_ci#define AQ_NIC_LINK_DOWN 0x04000000U 848c2ecf20Sopenharmony_ci#define AQ_NIC_FLAG_ERR_UNPLUG 0x40000000U 858c2ecf20Sopenharmony_ci#define AQ_NIC_FLAG_ERR_HW 0x80000000U 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci#define AQ_NIC_QUIRK_BAD_PTP BIT(0) 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci#define AQ_NIC_WOL_MODES (WAKE_MAGIC |\ 908c2ecf20Sopenharmony_ci WAKE_PHY) 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci#define AQ_NIC_CFG_RING_PER_TC(_NIC_CFG_) \ 938c2ecf20Sopenharmony_ci (((_NIC_CFG_)->tc_mode == AQ_TC_MODE_4TCS) ? 8 : 4) 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci#define AQ_NIC_CFG_TCVEC2RING(_NIC_CFG_, _TC_, _VEC_) \ 968c2ecf20Sopenharmony_ci ((_TC_) * AQ_NIC_CFG_RING_PER_TC(_NIC_CFG_) + (_VEC_)) 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci#define AQ_NIC_RING2QMAP(_NIC_, _ID_) \ 998c2ecf20Sopenharmony_ci ((_ID_) / AQ_NIC_CFG_RING_PER_TC(&(_NIC_)->aq_nic_cfg) * \ 1008c2ecf20Sopenharmony_ci (_NIC_)->aq_vecs + \ 1018c2ecf20Sopenharmony_ci ((_ID_) % AQ_NIC_CFG_RING_PER_TC(&(_NIC_)->aq_nic_cfg))) 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_cistruct aq_hw_rx_fl2 { 1048c2ecf20Sopenharmony_ci struct aq_rx_filter_vlan aq_vlans[AQ_VLAN_MAX_FILTERS]; 1058c2ecf20Sopenharmony_ci}; 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_cistruct aq_hw_rx_fl3l4 { 1088c2ecf20Sopenharmony_ci u8 active_ipv4; 1098c2ecf20Sopenharmony_ci u8 active_ipv6:2; 1108c2ecf20Sopenharmony_ci u8 is_ipv6; 1118c2ecf20Sopenharmony_ci u8 reserved_count; 1128c2ecf20Sopenharmony_ci}; 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_cistruct aq_hw_rx_fltrs_s { 1158c2ecf20Sopenharmony_ci struct hlist_head filter_list; 1168c2ecf20Sopenharmony_ci u16 active_filters; 1178c2ecf20Sopenharmony_ci struct aq_hw_rx_fl2 fl2; 1188c2ecf20Sopenharmony_ci struct aq_hw_rx_fl3l4 fl3l4; 1198c2ecf20Sopenharmony_ci /* filter ether type */ 1208c2ecf20Sopenharmony_ci u8 fet_reserved_count; 1218c2ecf20Sopenharmony_ci}; 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_cistruct aq_nic_s { 1248c2ecf20Sopenharmony_ci atomic_t flags; 1258c2ecf20Sopenharmony_ci u32 msg_enable; 1268c2ecf20Sopenharmony_ci struct aq_vec_s *aq_vec[AQ_CFG_VECS_MAX]; 1278c2ecf20Sopenharmony_ci struct aq_ring_s *aq_ring_tx[AQ_HW_QUEUES_MAX]; 1288c2ecf20Sopenharmony_ci struct aq_hw_s *aq_hw; 1298c2ecf20Sopenharmony_ci struct net_device *ndev; 1308c2ecf20Sopenharmony_ci unsigned int aq_vecs; 1318c2ecf20Sopenharmony_ci unsigned int packet_filter; 1328c2ecf20Sopenharmony_ci unsigned int power_state; 1338c2ecf20Sopenharmony_ci u8 port; 1348c2ecf20Sopenharmony_ci const struct aq_hw_ops *aq_hw_ops; 1358c2ecf20Sopenharmony_ci const struct aq_fw_ops *aq_fw_ops; 1368c2ecf20Sopenharmony_ci struct aq_nic_cfg_s aq_nic_cfg; 1378c2ecf20Sopenharmony_ci struct timer_list service_timer; 1388c2ecf20Sopenharmony_ci struct work_struct service_task; 1398c2ecf20Sopenharmony_ci struct timer_list polling_timer; 1408c2ecf20Sopenharmony_ci struct aq_hw_link_status_s link_status; 1418c2ecf20Sopenharmony_ci struct { 1428c2ecf20Sopenharmony_ci u32 count; 1438c2ecf20Sopenharmony_ci u8 ar[AQ_HW_MULTICAST_ADDRESS_MAX][ETH_ALEN]; 1448c2ecf20Sopenharmony_ci } mc_list; 1458c2ecf20Sopenharmony_ci /* Bitmask of currently assigned vlans from linux */ 1468c2ecf20Sopenharmony_ci unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)]; 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci struct pci_dev *pdev; 1498c2ecf20Sopenharmony_ci unsigned int msix_entry_mask; 1508c2ecf20Sopenharmony_ci u32 irqvecs; 1518c2ecf20Sopenharmony_ci /* mutex to serialize FW interface access operations */ 1528c2ecf20Sopenharmony_ci struct mutex fwreq_mutex; 1538c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_MACSEC) 1548c2ecf20Sopenharmony_ci struct aq_macsec_cfg *macsec_cfg; 1558c2ecf20Sopenharmony_ci /* mutex to protect data in macsec_cfg */ 1568c2ecf20Sopenharmony_ci struct mutex macsec_mutex; 1578c2ecf20Sopenharmony_ci#endif 1588c2ecf20Sopenharmony_ci /* PTP support */ 1598c2ecf20Sopenharmony_ci struct aq_ptp_s *aq_ptp; 1608c2ecf20Sopenharmony_ci struct aq_hw_rx_fltrs_s aq_hw_rx_fltrs; 1618c2ecf20Sopenharmony_ci}; 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_cistatic inline struct device *aq_nic_get_dev(struct aq_nic_s *self) 1648c2ecf20Sopenharmony_ci{ 1658c2ecf20Sopenharmony_ci return self->ndev->dev.parent; 1668c2ecf20Sopenharmony_ci} 1678c2ecf20Sopenharmony_ci 1688c2ecf20Sopenharmony_civoid aq_nic_ndev_init(struct aq_nic_s *self); 1698c2ecf20Sopenharmony_cistruct aq_nic_s *aq_nic_alloc_hot(struct net_device *ndev); 1708c2ecf20Sopenharmony_civoid aq_nic_set_tx_ring(struct aq_nic_s *self, unsigned int idx, 1718c2ecf20Sopenharmony_ci struct aq_ring_s *ring); 1728c2ecf20Sopenharmony_cistruct net_device *aq_nic_get_ndev(struct aq_nic_s *self); 1738c2ecf20Sopenharmony_ciint aq_nic_init(struct aq_nic_s *self); 1748c2ecf20Sopenharmony_civoid aq_nic_cfg_start(struct aq_nic_s *self); 1758c2ecf20Sopenharmony_ciint aq_nic_ndev_register(struct aq_nic_s *self); 1768c2ecf20Sopenharmony_civoid aq_nic_ndev_free(struct aq_nic_s *self); 1778c2ecf20Sopenharmony_ciint aq_nic_start(struct aq_nic_s *self); 1788c2ecf20Sopenharmony_ciunsigned int aq_nic_map_skb(struct aq_nic_s *self, struct sk_buff *skb, 1798c2ecf20Sopenharmony_ci struct aq_ring_s *ring); 1808c2ecf20Sopenharmony_ciint aq_nic_xmit(struct aq_nic_s *self, struct sk_buff *skb); 1818c2ecf20Sopenharmony_ciint aq_nic_get_regs(struct aq_nic_s *self, struct ethtool_regs *regs, void *p); 1828c2ecf20Sopenharmony_ciint aq_nic_get_regs_count(struct aq_nic_s *self); 1838c2ecf20Sopenharmony_ciu64 *aq_nic_get_stats(struct aq_nic_s *self, u64 *data); 1848c2ecf20Sopenharmony_ciint aq_nic_stop(struct aq_nic_s *self); 1858c2ecf20Sopenharmony_civoid aq_nic_deinit(struct aq_nic_s *self, bool link_down); 1868c2ecf20Sopenharmony_civoid aq_nic_set_power(struct aq_nic_s *self); 1878c2ecf20Sopenharmony_civoid aq_nic_free_hot_resources(struct aq_nic_s *self); 1888c2ecf20Sopenharmony_civoid aq_nic_free_vectors(struct aq_nic_s *self); 1898c2ecf20Sopenharmony_ciint aq_nic_realloc_vectors(struct aq_nic_s *self); 1908c2ecf20Sopenharmony_ciint aq_nic_set_mtu(struct aq_nic_s *self, int new_mtu); 1918c2ecf20Sopenharmony_ciint aq_nic_set_mac(struct aq_nic_s *self, struct net_device *ndev); 1928c2ecf20Sopenharmony_ciint aq_nic_set_packet_filter(struct aq_nic_s *self, unsigned int flags); 1938c2ecf20Sopenharmony_ciint aq_nic_set_multicast_list(struct aq_nic_s *self, struct net_device *ndev); 1948c2ecf20Sopenharmony_ciunsigned int aq_nic_get_link_speed(struct aq_nic_s *self); 1958c2ecf20Sopenharmony_civoid aq_nic_get_link_ksettings(struct aq_nic_s *self, 1968c2ecf20Sopenharmony_ci struct ethtool_link_ksettings *cmd); 1978c2ecf20Sopenharmony_ciint aq_nic_set_link_ksettings(struct aq_nic_s *self, 1988c2ecf20Sopenharmony_ci const struct ethtool_link_ksettings *cmd); 1998c2ecf20Sopenharmony_cistruct aq_nic_cfg_s *aq_nic_get_cfg(struct aq_nic_s *self); 2008c2ecf20Sopenharmony_ciu32 aq_nic_get_fw_version(struct aq_nic_s *self); 2018c2ecf20Sopenharmony_ciint aq_nic_set_loopback(struct aq_nic_s *self); 2028c2ecf20Sopenharmony_ciint aq_nic_set_downshift(struct aq_nic_s *self, int val); 2038c2ecf20Sopenharmony_ciint aq_nic_set_media_detect(struct aq_nic_s *self, int val); 2048c2ecf20Sopenharmony_ciint aq_nic_update_interrupt_moderation_settings(struct aq_nic_s *self); 2058c2ecf20Sopenharmony_civoid aq_nic_shutdown(struct aq_nic_s *self); 2068c2ecf20Sopenharmony_ciu8 aq_nic_reserve_filter(struct aq_nic_s *self, enum aq_rx_filter_type type); 2078c2ecf20Sopenharmony_civoid aq_nic_release_filter(struct aq_nic_s *self, enum aq_rx_filter_type type, 2088c2ecf20Sopenharmony_ci u32 location); 2098c2ecf20Sopenharmony_ciint aq_nic_setup_tc_mqprio(struct aq_nic_s *self, u32 tcs, u8 *prio_tc_map); 2108c2ecf20Sopenharmony_ciint aq_nic_setup_tc_max_rate(struct aq_nic_s *self, const unsigned int tc, 2118c2ecf20Sopenharmony_ci const u32 max_rate); 2128c2ecf20Sopenharmony_ciint aq_nic_setup_tc_min_rate(struct aq_nic_s *self, const unsigned int tc, 2138c2ecf20Sopenharmony_ci const u32 min_rate); 2148c2ecf20Sopenharmony_ci#endif /* AQ_NIC_H */ 215