1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* Atlantic Network Driver 3 * 4 * Copyright (C) 2014-2019 aQuantia Corporation 5 * Copyright (C) 2019-2020 Marvell International Ltd. 6 */ 7 8 /* File aq_hw.h: Declaration of abstract interface for NIC hardware specific 9 * functions. 10 */ 11 12 #ifndef AQ_HW_H 13 #define AQ_HW_H 14 15 #include "aq_common.h" 16 #include "aq_rss.h" 17 #include "hw_atl/hw_atl_utils.h" 18 19 #define AQ_HW_MAC_COUNTER_HZ 312500000ll 20 #define AQ_HW_PHY_COUNTER_HZ 160000000ll 21 22 enum aq_tc_mode { 23 AQ_TC_MODE_INVALID = -1, 24 AQ_TC_MODE_8TCS, 25 AQ_TC_MODE_4TCS, 26 }; 27 28 #define AQ_RX_FIRST_LOC_FVLANID 0U 29 #define AQ_RX_LAST_LOC_FVLANID 15U 30 #define AQ_RX_FIRST_LOC_FETHERT 16U 31 #define AQ_RX_LAST_LOC_FETHERT 31U 32 #define AQ_RX_FIRST_LOC_FL3L4 32U 33 #define AQ_RX_LAST_LOC_FL3L4 39U 34 #define AQ_RX_MAX_RXNFC_LOC AQ_RX_LAST_LOC_FL3L4 35 #define AQ_VLAN_MAX_FILTERS \ 36 (AQ_RX_LAST_LOC_FVLANID - AQ_RX_FIRST_LOC_FVLANID + 1U) 37 #define AQ_RX_QUEUE_NOT_ASSIGNED 0xFFU 38 39 #define AQ_FRAC_PER_NS 0x100000000LL 40 41 /* Used for rate to Mbps conversion */ 42 #define AQ_MBPS_DIVISOR 125000 /* 1000000 / 8 */ 43 44 /* NIC H/W capabilities */ 45 struct aq_hw_caps_s { 46 u64 hw_features; 47 u64 link_speed_msk; 48 unsigned int hw_priv_flags; 49 u32 media_type; 50 u32 rxds_max; 51 u32 txds_max; 52 u32 rxds_min; 53 u32 txds_min; 54 u32 txhwb_alignment; 55 u32 irq_mask; 56 u32 vecs; 57 u32 mtu; 58 u32 mac_regs_count; 59 u32 hw_alive_check_addr; 60 u8 msix_irqs; 61 u8 tcs_max; 62 u8 rxd_alignment; 63 u8 rxd_size; 64 u8 txd_alignment; 65 u8 txd_size; 66 u8 tx_rings; 67 u8 rx_rings; 68 bool flow_control; 69 bool is_64_dma; 70 bool op64bit; 71 u32 priv_data_len; 72 }; 73 74 struct aq_hw_link_status_s { 75 unsigned int mbps; 76 bool full_duplex; 77 u32 lp_link_speed_msk; 78 u32 lp_flow_control; 79 }; 80 81 struct aq_stats_s { 82 u64 uprc; 83 u64 mprc; 84 u64 bprc; 85 u64 erpt; 86 u64 uptc; 87 u64 mptc; 88 u64 bptc; 89 u64 erpr; 90 u64 mbtc; 91 u64 bbtc; 92 u64 mbrc; 93 u64 bbrc; 94 u64 ubrc; 95 u64 ubtc; 96 u64 dpc; 97 u64 dma_pkt_rc; 98 u64 dma_pkt_tc; 99 u64 dma_oct_rc; 100 u64 dma_oct_tc; 101 }; 102 103 #define AQ_HW_IRQ_INVALID 0U 104 #define AQ_HW_IRQ_LEGACY 1U 105 #define AQ_HW_IRQ_MSI 2U 106 #define AQ_HW_IRQ_MSIX 3U 107 108 #define AQ_HW_SERVICE_IRQS 1U 109 110 #define AQ_HW_POWER_STATE_D0 0U 111 #define AQ_HW_POWER_STATE_D3 3U 112 113 #define AQ_HW_FLAG_STARTED 0x00000004U 114 #define AQ_HW_FLAG_STOPPING 0x00000008U 115 #define AQ_HW_FLAG_RESETTING 0x00000010U 116 #define AQ_HW_FLAG_CLOSING 0x00000020U 117 #define AQ_HW_PTP_AVAILABLE 0x01000000U 118 #define AQ_HW_LINK_DOWN 0x04000000U 119 #define AQ_HW_FLAG_ERR_UNPLUG 0x40000000U 120 #define AQ_HW_FLAG_ERR_HW 0x80000000U 121 122 #define AQ_HW_FLAG_ERRORS (AQ_HW_FLAG_ERR_HW | AQ_HW_FLAG_ERR_UNPLUG) 123 124 #define AQ_NIC_FLAGS_IS_NOT_READY (AQ_NIC_FLAG_STOPPING | \ 125 AQ_NIC_FLAG_RESETTING | AQ_NIC_FLAG_CLOSING | \ 126 AQ_NIC_FLAG_ERR_UNPLUG | AQ_NIC_FLAG_ERR_HW) 127 128 #define AQ_NIC_FLAGS_IS_NOT_TX_READY (AQ_NIC_FLAGS_IS_NOT_READY | \ 129 AQ_NIC_LINK_DOWN) 130 131 #define AQ_HW_MEDIA_TYPE_TP 1U 132 #define AQ_HW_MEDIA_TYPE_FIBRE 2U 133 134 #define AQ_HW_TXD_MULTIPLE 8U 135 #define AQ_HW_RXD_MULTIPLE 8U 136 137 #define AQ_HW_QUEUES_MAX 32U 138 #define AQ_HW_MULTICAST_ADDRESS_MAX 32U 139 140 #define AQ_HW_PTP_TC 2U 141 142 #define AQ_HW_LED_BLINK 0x2U 143 #define AQ_HW_LED_DEFAULT 0x0U 144 145 enum aq_priv_flags { 146 AQ_HW_LOOPBACK_DMA_SYS, 147 AQ_HW_LOOPBACK_PKT_SYS, 148 AQ_HW_LOOPBACK_DMA_NET, 149 AQ_HW_LOOPBACK_PHYINT_SYS, 150 AQ_HW_LOOPBACK_PHYEXT_SYS, 151 }; 152 153 #define AQ_HW_LOOPBACK_MASK (BIT(AQ_HW_LOOPBACK_DMA_SYS) |\ 154 BIT(AQ_HW_LOOPBACK_PKT_SYS) |\ 155 BIT(AQ_HW_LOOPBACK_DMA_NET) |\ 156 BIT(AQ_HW_LOOPBACK_PHYINT_SYS) |\ 157 BIT(AQ_HW_LOOPBACK_PHYEXT_SYS)) 158 159 #define ATL_HW_CHIP_MIPS 0x00000001U 160 #define ATL_HW_CHIP_TPO2 0x00000002U 161 #define ATL_HW_CHIP_RPF2 0x00000004U 162 #define ATL_HW_CHIP_MPI_AQ 0x00000010U 163 #define ATL_HW_CHIP_ATLANTIC 0x00800000U 164 #define ATL_HW_CHIP_REVISION_A0 0x01000000U 165 #define ATL_HW_CHIP_REVISION_B0 0x02000000U 166 #define ATL_HW_CHIP_REVISION_B1 0x04000000U 167 #define ATL_HW_CHIP_ANTIGUA 0x08000000U 168 169 #define ATL_HW_IS_CHIP_FEATURE(_HW_, _F_) (!!(ATL_HW_CHIP_##_F_ & \ 170 (_HW_)->chip_features)) 171 172 struct aq_hw_s { 173 atomic_t flags; 174 u8 rbl_enabled:1; 175 struct aq_nic_cfg_s *aq_nic_cfg; 176 const struct aq_fw_ops *aq_fw_ops; 177 void __iomem *mmio; 178 struct aq_hw_link_status_s aq_link_status; 179 struct hw_atl_utils_mbox mbox; 180 struct hw_atl_stats_s last_stats; 181 struct aq_stats_s curr_stats; 182 u64 speed; 183 u32 itr_tx; 184 u32 itr_rx; 185 unsigned int chip_features; 186 u32 fw_ver_actual; 187 atomic_t dpc; 188 u32 mbox_addr; 189 u32 rpc_addr; 190 u32 settings_addr; 191 u32 rpc_tid; 192 struct hw_atl_utils_fw_rpc rpc; 193 s64 ptp_clk_offset; 194 u16 phy_id; 195 void *priv; 196 }; 197 198 struct aq_ring_s; 199 struct aq_ring_param_s; 200 struct sk_buff; 201 struct aq_rx_filter_l3l4; 202 203 struct aq_hw_ops { 204 205 int (*hw_ring_tx_xmit)(struct aq_hw_s *self, struct aq_ring_s *aq_ring, 206 unsigned int frags); 207 208 int (*hw_ring_rx_receive)(struct aq_hw_s *self, 209 struct aq_ring_s *aq_ring); 210 211 int (*hw_ring_rx_fill)(struct aq_hw_s *self, struct aq_ring_s *aq_ring, 212 unsigned int sw_tail_old); 213 214 int (*hw_ring_tx_head_update)(struct aq_hw_s *self, 215 struct aq_ring_s *aq_ring); 216 217 int (*hw_set_mac_address)(struct aq_hw_s *self, u8 *mac_addr); 218 219 int (*hw_soft_reset)(struct aq_hw_s *self); 220 221 int (*hw_prepare)(struct aq_hw_s *self, 222 const struct aq_fw_ops **fw_ops); 223 224 int (*hw_reset)(struct aq_hw_s *self); 225 226 int (*hw_init)(struct aq_hw_s *self, u8 *mac_addr); 227 228 int (*hw_start)(struct aq_hw_s *self); 229 230 int (*hw_stop)(struct aq_hw_s *self); 231 232 int (*hw_ring_tx_init)(struct aq_hw_s *self, struct aq_ring_s *aq_ring, 233 struct aq_ring_param_s *aq_ring_param); 234 235 int (*hw_ring_tx_start)(struct aq_hw_s *self, 236 struct aq_ring_s *aq_ring); 237 238 int (*hw_ring_tx_stop)(struct aq_hw_s *self, 239 struct aq_ring_s *aq_ring); 240 241 int (*hw_ring_rx_init)(struct aq_hw_s *self, 242 struct aq_ring_s *aq_ring, 243 struct aq_ring_param_s *aq_ring_param); 244 245 int (*hw_ring_rx_start)(struct aq_hw_s *self, 246 struct aq_ring_s *aq_ring); 247 248 int (*hw_ring_rx_stop)(struct aq_hw_s *self, 249 struct aq_ring_s *aq_ring); 250 251 int (*hw_irq_enable)(struct aq_hw_s *self, u64 mask); 252 253 int (*hw_irq_disable)(struct aq_hw_s *self, u64 mask); 254 255 int (*hw_irq_read)(struct aq_hw_s *self, u64 *mask); 256 257 int (*hw_packet_filter_set)(struct aq_hw_s *self, 258 unsigned int packet_filter); 259 260 int (*hw_filter_l3l4_set)(struct aq_hw_s *self, 261 struct aq_rx_filter_l3l4 *data); 262 263 int (*hw_filter_l3l4_clear)(struct aq_hw_s *self, 264 struct aq_rx_filter_l3l4 *data); 265 266 int (*hw_filter_l2_set)(struct aq_hw_s *self, 267 struct aq_rx_filter_l2 *data); 268 269 int (*hw_filter_l2_clear)(struct aq_hw_s *self, 270 struct aq_rx_filter_l2 *data); 271 272 int (*hw_filter_vlan_set)(struct aq_hw_s *self, 273 struct aq_rx_filter_vlan *aq_vlans); 274 275 int (*hw_filter_vlan_ctrl)(struct aq_hw_s *self, bool enable); 276 277 int (*hw_multicast_list_set)(struct aq_hw_s *self, 278 u8 ar_mac[AQ_HW_MULTICAST_ADDRESS_MAX] 279 [ETH_ALEN], 280 u32 count); 281 282 int (*hw_interrupt_moderation_set)(struct aq_hw_s *self); 283 284 int (*hw_rss_set)(struct aq_hw_s *self, 285 struct aq_rss_parameters *rss_params); 286 287 int (*hw_rss_hash_set)(struct aq_hw_s *self, 288 struct aq_rss_parameters *rss_params); 289 290 int (*hw_tc_rate_limit_set)(struct aq_hw_s *self); 291 292 int (*hw_get_regs)(struct aq_hw_s *self, 293 const struct aq_hw_caps_s *aq_hw_caps, 294 u32 *regs_buff); 295 296 struct aq_stats_s *(*hw_get_hw_stats)(struct aq_hw_s *self); 297 298 u32 (*hw_get_fw_version)(struct aq_hw_s *self); 299 300 int (*hw_set_offload)(struct aq_hw_s *self, 301 struct aq_nic_cfg_s *aq_nic_cfg); 302 303 int (*hw_ring_hwts_rx_fill)(struct aq_hw_s *self, 304 struct aq_ring_s *aq_ring); 305 306 int (*hw_ring_hwts_rx_receive)(struct aq_hw_s *self, 307 struct aq_ring_s *ring); 308 309 void (*hw_get_ptp_ts)(struct aq_hw_s *self, u64 *stamp); 310 311 int (*hw_adj_clock_freq)(struct aq_hw_s *self, s32 delta); 312 313 int (*hw_adj_sys_clock)(struct aq_hw_s *self, s64 delta); 314 315 int (*hw_set_sys_clock)(struct aq_hw_s *self, u64 time, u64 ts); 316 317 int (*hw_ts_to_sys_clock)(struct aq_hw_s *self, u64 ts, u64 *time); 318 319 int (*hw_gpio_pulse)(struct aq_hw_s *self, u32 index, u64 start, 320 u32 period); 321 322 int (*hw_extts_gpio_enable)(struct aq_hw_s *self, u32 index, 323 u32 enable); 324 325 int (*hw_get_sync_ts)(struct aq_hw_s *self, u64 *ts); 326 327 u16 (*rx_extract_ts)(struct aq_hw_s *self, u8 *p, unsigned int len, 328 u64 *timestamp); 329 330 int (*extract_hwts)(struct aq_hw_s *self, u8 *p, unsigned int len, 331 u64 *timestamp); 332 333 int (*hw_set_fc)(struct aq_hw_s *self, u32 fc, u32 tc); 334 335 int (*hw_set_loopback)(struct aq_hw_s *self, u32 mode, bool enable); 336 337 int (*hw_get_mac_temp)(struct aq_hw_s *self, u32 *temp); 338 }; 339 340 struct aq_fw_ops { 341 int (*init)(struct aq_hw_s *self); 342 343 int (*deinit)(struct aq_hw_s *self); 344 345 int (*reset)(struct aq_hw_s *self); 346 347 int (*renegotiate)(struct aq_hw_s *self); 348 349 int (*get_mac_permanent)(struct aq_hw_s *self, u8 *mac); 350 351 int (*set_link_speed)(struct aq_hw_s *self, u32 speed); 352 353 int (*set_state)(struct aq_hw_s *self, 354 enum hal_atl_utils_fw_state_e state); 355 356 int (*update_link_status)(struct aq_hw_s *self); 357 358 int (*update_stats)(struct aq_hw_s *self); 359 360 int (*get_mac_temp)(struct aq_hw_s *self, int *temp); 361 362 int (*get_phy_temp)(struct aq_hw_s *self, int *temp); 363 364 u32 (*get_flow_control)(struct aq_hw_s *self, u32 *fcmode); 365 366 int (*set_flow_control)(struct aq_hw_s *self); 367 368 int (*led_control)(struct aq_hw_s *self, u32 mode); 369 370 int (*set_phyloopback)(struct aq_hw_s *self, u32 mode, bool enable); 371 372 int (*set_power)(struct aq_hw_s *self, unsigned int power_state, 373 u8 *mac); 374 375 int (*send_fw_request)(struct aq_hw_s *self, 376 const struct hw_fw_request_iface *fw_req, 377 size_t size); 378 379 void (*enable_ptp)(struct aq_hw_s *self, int enable); 380 381 void (*adjust_ptp)(struct aq_hw_s *self, uint64_t adj); 382 383 int (*set_eee_rate)(struct aq_hw_s *self, u32 speed); 384 385 int (*get_eee_rate)(struct aq_hw_s *self, u32 *rate, 386 u32 *supported_rates); 387 388 u32 (*get_link_capabilities)(struct aq_hw_s *self); 389 390 int (*send_macsec_req)(struct aq_hw_s *self, 391 struct macsec_msg_fw_request *msg, 392 struct macsec_msg_fw_response *resp); 393 }; 394 395 #endif /* AQ_HW_H */ 396