FILE
enetc.h
File preview with syntax highlighting.
linux-6.19.14/drivers/net/ethernet/freescale/enetc/enetc.h
1/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */ 2/* Copyright 2017-2019 NXP */ 3 4#include <linux/timer.h> 5#include <linux/pci.h> 6#include <linux/netdevice.h> 7#include <linux/etherdevice.h> 8#include <linux/dma-mapping.h> 9#include <linux/skbuff.h> 10#include <linux/ethtool.h> 11#include <linux/fsl/ntmp.h> 12#include <linux/if_vlan.h> 13#include <linux/phylink.h> 14#include <linux/dim.h> 15#include <net/xdp.h> 16 17#include "enetc_hw.h" 18#include "enetc4_hw.h" 19 20#define ENETC_MAC_MAXFRM_SIZE 9600 21#define ENETC_MAX_MTU (ENETC_MAC_MAXFRM_SIZE - \ 22 (ETH_FCS_LEN + ETH_HLEN + VLAN_HLEN)) 23 24#define ENETC_CBD_DATA_MEM_ALIGN 64 25 26#define ENETC_MADDR_HASH_TBL_SZ 64 27 28enum enetc_mac_addr_type {UC, MC, MADDR_TYPE}; 29 30struct enetc_mac_filter { 31 union { 32 char mac_addr[ETH_ALEN]; 33 DECLARE_BITMAP(mac_hash_table, ENETC_MADDR_HASH_TBL_SZ); 34 }; 35 int mac_addr_cnt; 36}; 37 38struct enetc_tx_swbd { 39 union { 40 struct sk_buff *skb; 41 struct xdp_frame *xdp_frame; 42 }; 43 dma_addr_t dma; 44 struct page *page; /* valid only if is_xdp_tx */ 45 u16 page_offset; /* valid only if is_xdp_tx */ 46 u16 len; 47 enum dma_data_direction dir; 48 u8 is_dma_page:1; 49 u8 check_wb:1; 50 u8 do_twostep_tstamp:1; 51 u8 is_eof:1; 52 u8 is_xdp_tx:1; 53 u8 is_xdp_redirect:1; 54 u8 qbv_en:1; 55}; 56 57struct enetc_skb_cb { 58 u8 flag; 59 bool udp; 60 u16 correction_off; 61 u16 origin_tstamp_off; 62}; 63 64#define ENETC_SKB_CB(skb) ((struct enetc_skb_cb *)((skb)->cb)) 65 66struct enetc_lso_t { 67 bool ipv6; 68 bool tcp; 69 u8 l3_hdr_len; 70 u8 hdr_len; /* LSO header length */ 71 u8 l3_start; 72 u16 lso_seg_size; 73 int total_len; /* total data length, not include LSO header */ 74}; 75 76#define ENETC_LSO_MAX_DATA_LEN SZ_256K 77 78#define ENETC_RX_MAXFRM_SIZE ENETC_MAC_MAXFRM_SIZE 79#define ENETC_RXB_TRUESIZE (PAGE_SIZE >> 1) 80#define ENETC_RXB_PAD NET_SKB_PAD /* add extra space if needed */ 81#define ENETC_RXB_DMA_SIZE \ 82 min(SKB_WITH_OVERHEAD(ENETC_RXB_TRUESIZE) - ENETC_RXB_PAD, 0xffff) 83#define ENETC_RXB_DMA_SIZE_XDP \ 84 min(SKB_WITH_OVERHEAD(ENETC_RXB_TRUESIZE) - XDP_PACKET_HEADROOM, 0xffff) 85 86struct enetc_rx_swbd { 87 dma_addr_t dma; 88 struct page *page; 89 u16 page_offset; 90 enum dma_data_direction dir; 91 u16 len; 92}; 93 94/* ENETC overhead: optional extension BD + 1 BD gap */ 95#define ENETC_TXBDS_NEEDED(val) ((val) + 2) 96/* For LS1028A, max # of chained Tx BDs is 15, including head and 97 * extension BD. 98 */ 99#define ENETC_MAX_SKB_FRAGS 13 100/* For ENETC v4 and later versions, max # of chained Tx BDs is 63, 101 * including head and extension BD, but the range of MAX_SKB_FRAGS 102 * is 17 ~ 45, so set ENETC4_MAX_SKB_FRAGS to MAX_SKB_FRAGS. 103 */ 104#define ENETC4_MAX_SKB_FRAGS MAX_SKB_FRAGS 105#define ENETC_TXBDS_MAX_NEEDED(x) ENETC_TXBDS_NEEDED((x) + 1) 106 107struct enetc_ring_stats { 108 unsigned long packets; 109 unsigned long bytes; 110 unsigned long rx_alloc_errs; 111 unsigned long xdp_drops; 112 unsigned long xdp_tx; 113 unsigned long xdp_tx_drops; 114 unsigned long xdp_redirect; 115 unsigned long xdp_redirect_failures; 116 unsigned long recycles; 117 unsigned long recycle_failures; 118 unsigned long win_drop; 119}; 120 121struct enetc_xdp_data { 122 struct xdp_rxq_info rxq; 123 struct bpf_prog *prog; 124 int xdp_tx_in_flight; 125}; 126 127#define ENETC_RX_RING_DEFAULT_SIZE 2048 128#define ENETC_TX_RING_DEFAULT_SIZE 2048 129#define ENETC_DEFAULT_TX_WORK (ENETC_TX_RING_DEFAULT_SIZE / 2) 130 131struct enetc_bdr_resource { 132 /* Input arguments saved for teardown */ 133 struct device *dev; /* for DMA mapping */ 134 size_t bd_count; 135 size_t bd_size; 136 137 /* Resource proper */ 138 void *bd_base; /* points to Rx or Tx BD ring */ 139 dma_addr_t bd_dma_base; 140 union { 141 struct enetc_tx_swbd *tx_swbd; 142 struct enetc_rx_swbd *rx_swbd; 143 }; 144 char *tso_headers; 145 dma_addr_t tso_headers_dma; 146}; 147 148struct enetc_bdr { 149 struct device *dev; /* for DMA mapping */ 150 struct net_device *ndev; 151 void *bd_base; /* points to Rx or Tx BD ring */ 152 union { 153 void __iomem *tpir; 154 void __iomem *rcir; 155 }; 156 u16 index; 157 u16 prio; 158 int bd_count; /* # of BDs */ 159 int next_to_use; 160 int next_to_clean; 161 union { 162 struct enetc_tx_swbd *tx_swbd; 163 struct enetc_rx_swbd *rx_swbd; 164 }; 165 union { 166 void __iomem *tcir; /* Tx */ 167 int next_to_alloc; /* Rx */ 168 }; 169 void __iomem *idr; /* Interrupt Detect Register pointer */ 170 171 int buffer_offset; 172 struct enetc_xdp_data xdp; 173 174 struct enetc_ring_stats stats; 175 176 dma_addr_t bd_dma_base; 177 u8 tsd_enable; /* Time specific departure */ 178 bool ext_en; /* enable h/w descriptor extensions */ 179 180 /* DMA buffer for TSO headers */ 181 char *tso_headers; 182 dma_addr_t tso_headers_dma; 183} ____cacheline_aligned_in_smp; 184 185static inline void enetc_bdr_idx_inc(struct enetc_bdr *bdr, int *i) 186{ 187 if (unlikely(++*i == bdr->bd_count)) 188 *i = 0; 189} 190 191static inline int enetc_bd_unused(struct enetc_bdr *bdr) 192{ 193 if (bdr->next_to_clean > bdr->next_to_use) 194 return bdr->next_to_clean - bdr->next_to_use - 1; 195 196 return bdr->bd_count + bdr->next_to_clean - bdr->next_to_use - 1; 197} 198 199static inline int enetc_swbd_unused(struct enetc_bdr *bdr) 200{ 201 if (bdr->next_to_clean > bdr->next_to_alloc) 202 return bdr->next_to_clean - bdr->next_to_alloc - 1; 203 204 return bdr->bd_count + bdr->next_to_clean - bdr->next_to_alloc - 1; 205} 206 207/* Control BD ring */ 208#define ENETC_CBDR_DEFAULT_SIZE 64 209struct enetc_cbdr { 210 void *bd_base; /* points to Rx or Tx BD ring */ 211 void __iomem *pir; 212 void __iomem *cir; 213 void __iomem *mr; /* mode register */ 214 215 int bd_count; /* # of BDs */ 216 int next_to_use; 217 int next_to_clean; 218 219 dma_addr_t bd_dma_base; 220 struct device *dma_dev; 221}; 222 223#define ENETC_TXBD(BDR, i) (&(((union enetc_tx_bd *)((BDR).bd_base))[i])) 224 225static inline union enetc_rx_bd *enetc_rxbd(struct enetc_bdr *rx_ring, int i) 226{ 227 int hw_idx = i; 228 229 if (rx_ring->ext_en) 230 hw_idx = 2 * i; 231 232 return &(((union enetc_rx_bd *)rx_ring->bd_base)[hw_idx]); 233} 234 235static inline void enetc_rxbd_next(struct enetc_bdr *rx_ring, 236 union enetc_rx_bd **old_rxbd, int *old_index) 237{ 238 union enetc_rx_bd *new_rxbd = *old_rxbd; 239 int new_index = *old_index; 240 241 new_rxbd++; 242 243 if (rx_ring->ext_en) 244 new_rxbd++; 245 246 if (unlikely(++new_index == rx_ring->bd_count)) { 247 new_rxbd = rx_ring->bd_base; 248 new_index = 0; 249 } 250 251 *old_rxbd = new_rxbd; 252 *old_index = new_index; 253} 254 255static inline union enetc_rx_bd *enetc_rxbd_ext(union enetc_rx_bd *rxbd) 256{ 257 return ++rxbd; 258} 259 260struct enetc_msg_swbd { 261 void *vaddr; 262 dma_addr_t dma; 263 int size; 264}; 265 266#define ENETC_REV1 0x1 267enum enetc_errata { 268 ENETC_ERR_VLAN_ISOL = BIT(0), 269 ENETC_ERR_UCMCSWP = BIT(1), 270}; 271 272#define ENETC_SI_F_PSFP BIT(0) 273#define ENETC_SI_F_QBV BIT(1) 274#define ENETC_SI_F_QBU BIT(2) 275#define ENETC_SI_F_LSO BIT(3) 276#define ENETC_SI_F_PPM BIT(4) /* pseudo MAC */ 277 278struct enetc_drvdata { 279 u32 pmac_offset; /* Only valid for PSI which supports 802.1Qbu */ 280 u8 tx_csum:1; 281 u8 max_frags; 282 u64 sysclk_freq; 283 const struct ethtool_ops *eth_ops; 284}; 285 286struct enetc_platform_info { 287 u16 revision; 288 u16 dev_id; 289 const struct enetc_drvdata *data; 290}; 291 292struct enetc_si; 293 294/* 295 * This structure defines the some common hooks for ENETC PSI and VSI. 296 * In addition, since VSI only uses the struct enetc_si as its private 297 * driver data, so this structure also define some hooks specifically 298 * for VSI. For VSI-specific hooks, the format is ‘vf_*()’. 299 */ 300struct enetc_si_ops { 301 int (*get_rss_table)(struct enetc_si *si, u32 *table, int count); 302 int (*set_rss_table)(struct enetc_si *si, const u32 *table, int count); 303}; 304 305/* PCI IEP device data */ 306struct enetc_si { 307 struct pci_dev *pdev; 308 struct enetc_hw hw; 309 enum enetc_errata errata; 310 311 struct net_device *ndev; /* back ref. */ 312 313 union { 314 struct enetc_cbdr cbd_ring; /* Only ENETC 1.0 */ 315 struct ntmp_user ntmp_user; /* ENETC 4.1 and later */ 316 }; 317 318 int num_rx_rings; /* how many rings are available in the SI */ 319 int num_tx_rings; 320 int num_fs_entries; 321 int num_rss; /* number of RSS buckets */ 322 unsigned short pad; 323 u16 revision; 324 int hw_features; 325 const struct enetc_drvdata *drvdata; 326 const struct enetc_si_ops *ops; 327 328 struct workqueue_struct *workqueue; 329 struct work_struct rx_mode_task; 330 struct dentry *debugfs_root; 331}; 332 333#define ENETC_SI_ALIGN 32 334 335static inline bool is_enetc_rev1(struct enetc_si *si) 336{ 337 return si->pdev->revision == ENETC_REV1; 338} 339 340static inline void *enetc_si_priv(const struct enetc_si *si) 341{ 342 return (char *)si + ALIGN(sizeof(struct enetc_si), ENETC_SI_ALIGN); 343} 344 345static inline bool enetc_si_is_pf(struct enetc_si *si) 346{ 347 return !!(si->hw.port); 348} 349 350static inline int enetc_pf_to_port(struct pci_dev *pf_pdev) 351{ 352 switch (pf_pdev->devfn) { 353 case 0: 354 return 0; 355 case 1: 356 return 1; 357 case 2: 358 return 2; 359 case 6: 360 return 3; 361 default: 362 return -1; 363 } 364} 365 366static inline bool enetc_is_pseudo_mac(struct enetc_si *si) 367{ 368 return si->hw_features & ENETC_SI_F_PPM; 369} 370 371#define ENETC_MAX_NUM_TXQS 8 372#define ENETC_INT_NAME_MAX (IFNAMSIZ + 8) 373 374struct enetc_int_vector { 375 void __iomem *rbier; 376 void __iomem *tbier_base; 377 void __iomem *ricr1; 378 unsigned long tx_rings_map; 379 int count_tx_rings; 380 u32 rx_ictt; 381 u16 comp_cnt; 382 bool rx_dim_en, rx_napi_work; 383 struct napi_struct napi ____cacheline_aligned_in_smp; 384 struct dim rx_dim ____cacheline_aligned_in_smp; 385 char name[ENETC_INT_NAME_MAX]; 386 387 struct enetc_bdr rx_ring; 388 struct enetc_bdr tx_ring[] __counted_by(count_tx_rings); 389} ____cacheline_aligned_in_smp; 390 391struct enetc_cls_rule { 392 struct ethtool_rx_flow_spec fs; 393 int used; 394}; 395 396#define ENETC_MAX_BDR_INT 6 /* fixed to max # of available cpus */ 397struct psfp_cap { 398 u32 max_streamid; 399 u32 max_psfp_filter; 400 u32 max_psfp_gate; 401 u32 max_psfp_gatelist; 402 u32 max_psfp_meter; 403}; 404 405#define ENETC_F_TX_TSTAMP_MASK 0xff 406enum enetc_active_offloads { 407 /* 8 bits reserved for TX timestamp types (hwtstamp_tx_types) */ 408 ENETC_F_TX_TSTAMP = BIT(0), 409 ENETC_F_TX_ONESTEP_SYNC_TSTAMP = BIT(1), 410 411 ENETC_F_RX_TSTAMP = BIT(8), 412 ENETC_F_QBV = BIT(9), 413 ENETC_F_QCI = BIT(10), 414 ENETC_F_QBU = BIT(11), 415 ENETC_F_TXCSUM = BIT(12), 416 ENETC_F_LSO = BIT(13), 417}; 418 419enum enetc_flags_bit { 420 ENETC_TX_ONESTEP_TSTAMP_IN_PROGRESS = 0, 421 ENETC_TX_DOWN, 422}; 423 424/* interrupt coalescing modes */ 425enum enetc_ic_mode { 426 /* one interrupt per frame */ 427 ENETC_IC_NONE = 0, 428 /* activated when int coalescing time is set to a non-0 value */ 429 ENETC_IC_RX_MANUAL = BIT(0), 430 ENETC_IC_TX_MANUAL = BIT(1), 431 /* use dynamic interrupt moderation */ 432 ENETC_IC_RX_ADAPTIVE = BIT(2), 433}; 434 435#define ENETC_RXIC_PKTTHR min_t(u32, 256, ENETC_RX_RING_DEFAULT_SIZE / 2) 436#define ENETC_TXIC_PKTTHR min_t(u32, 128, ENETC_TX_RING_DEFAULT_SIZE / 2) 437 438struct enetc_ndev_priv { 439 struct net_device *ndev; 440 struct device *dev; /* dma-mapping device */ 441 struct enetc_si *si; 442 443 int bdr_int_num; /* number of Rx/Tx ring interrupts */ 444 struct enetc_int_vector *int_vector[ENETC_MAX_BDR_INT]; 445 u16 num_rx_rings, num_tx_rings; 446 u16 rx_bd_count, tx_bd_count; 447 448 u16 msg_enable; 449 450 u8 preemptible_tcs; 451 u8 max_frags; /* The maximum number of BDs for fragments */ 452 453 enum enetc_active_offloads active_offloads; 454 455 u32 speed; /* store speed for compare update pspeed */ 456 457 struct enetc_bdr **xdp_tx_ring; 458 struct enetc_bdr *tx_ring[16]; 459 struct enetc_bdr *rx_ring[16]; 460 const struct enetc_bdr_resource *tx_res; 461 const struct enetc_bdr_resource *rx_res; 462 463 struct enetc_cls_rule *cls_rules; 464 465 struct psfp_cap psfp_cap; 466 467 /* Minimum number of TX queues required by the network stack */ 468 unsigned int min_num_stack_tx_queues; 469 470 struct phylink *phylink; 471 int ic_mode; 472 u32 tx_ictt; 473 474 struct bpf_prog *xdp_prog; 475 476 unsigned long flags; 477 478 struct work_struct tx_onestep_tstamp; 479 struct sk_buff_head tx_skbs; 480 481 /* Serialize access to MAC Merge state between ethtool requests 482 * and link state updates 483 */ 484 struct mutex mm_lock; 485 486 struct clk *ref_clk; /* RGMII/RMII reference clock */ 487 u64 sysclk_freq; /* NETC system clock frequency */ 488}; 489 490/* Messaging */ 491 492/* VF-PF set primary MAC address message format */ 493struct enetc_msg_cmd_set_primary_mac { 494 struct enetc_msg_cmd_header header; 495 struct sockaddr mac; 496}; 497 498#define ENETC_CBD(R, i) (&(((struct enetc_cbd *)((R).bd_base))[i])) 499 500#define ENETC_CBDR_TIMEOUT 1000 /* usecs */ 501 502/* SI common */ 503u32 enetc_port_mac_rd(struct enetc_si *si, u32 reg); 504void enetc_port_mac_wr(struct enetc_si *si, u32 reg, u32 val); 505int enetc_pci_probe(struct pci_dev *pdev, const char *name, int sizeof_priv); 506void enetc_pci_remove(struct pci_dev *pdev); 507int enetc_alloc_msix(struct enetc_ndev_priv *priv); 508void enetc_free_msix(struct enetc_ndev_priv *priv); 509void enetc_get_si_caps(struct enetc_si *si); 510void enetc_init_si_rings_params(struct enetc_ndev_priv *priv); 511int enetc_alloc_si_resources(struct enetc_ndev_priv *priv); 512void enetc_free_si_resources(struct enetc_ndev_priv *priv); 513int enetc_configure_si(struct enetc_ndev_priv *priv); 514int enetc_get_driver_data(struct enetc_si *si); 515void enetc_add_mac_addr_ht_filter(struct enetc_mac_filter *filter, 516 const unsigned char *addr); 517void enetc_reset_mac_addr_filter(struct enetc_mac_filter *filter); 518 519int enetc_open(struct net_device *ndev); 520int enetc_close(struct net_device *ndev); 521void enetc_start(struct net_device *ndev); 522void enetc_stop(struct net_device *ndev); 523netdev_tx_t enetc_xmit(struct sk_buff *skb, struct net_device *ndev); 524struct net_device_stats *enetc_get_stats(struct net_device *ndev); 525void enetc_set_features(struct net_device *ndev, netdev_features_t features); 526int enetc_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd); 527int enetc_setup_tc_mqprio(struct net_device *ndev, void *type_data); 528void enetc_reset_tc_mqprio(struct net_device *ndev); 529int enetc_setup_bpf(struct net_device *ndev, struct netdev_bpf *bpf); 530int enetc_xdp_xmit(struct net_device *ndev, int num_frames, 531 struct xdp_frame **frames, u32 flags); 532 533int enetc_hwtstamp_get(struct net_device *ndev, 534 struct kernel_hwtstamp_config *config); 535int enetc_hwtstamp_set(struct net_device *ndev, 536 struct kernel_hwtstamp_config *config, 537 struct netlink_ext_ack *extack); 538 539/* ethtool */ 540extern const struct ethtool_ops enetc_pf_ethtool_ops; 541extern const struct ethtool_ops enetc4_pf_ethtool_ops; 542extern const struct ethtool_ops enetc_vf_ethtool_ops; 543extern const struct ethtool_ops enetc4_ppm_ethtool_ops; 544 545void enetc_set_ethtool_ops(struct net_device *ndev); 546void enetc_mm_link_state_update(struct enetc_ndev_priv *priv, bool link); 547void enetc_mm_commit_preemptible_tcs(struct enetc_ndev_priv *priv); 548 549/* control buffer descriptor ring (CBDR) */ 550int enetc_setup_cbdr(struct device *dev, struct enetc_hw *hw, int bd_count, 551 struct enetc_cbdr *cbdr); 552void enetc_teardown_cbdr(struct enetc_cbdr *cbdr); 553int enetc4_setup_cbdr(struct enetc_si *si); 554void enetc4_teardown_cbdr(struct enetc_si *si); 555int enetc_set_mac_flt_entry(struct enetc_si *si, int index, 556 char *mac_addr, int si_map); 557int enetc_clear_mac_flt_entry(struct enetc_si *si, int index); 558int enetc_set_fs_entry(struct enetc_si *si, struct enetc_cmd_rfse *rfse, 559 int index); 560void enetc_set_rss_key(struct enetc_si *si, const u8 *bytes); 561int enetc_get_rss_table(struct enetc_si *si, u32 *table, int count); 562int enetc_set_rss_table(struct enetc_si *si, const u32 *table, int count); 563int enetc_send_cmd(struct enetc_si *si, struct enetc_cbd *cbd); 564int enetc4_get_rss_table(struct enetc_si *si, u32 *table, int count); 565int enetc4_set_rss_table(struct enetc_si *si, const u32 *table, int count); 566 567static inline void *enetc_cbd_alloc_data_mem(struct enetc_si *si, 568 struct enetc_cbd *cbd, 569 int size, dma_addr_t *dma, 570 void **data_align) 571{ 572 struct enetc_cbdr *ring = &si->cbd_ring; 573 dma_addr_t dma_align; 574 void *data; 575 576 data = dma_alloc_coherent(ring->dma_dev, 577 size + ENETC_CBD_DATA_MEM_ALIGN, 578 dma, GFP_KERNEL); 579 if (!data) { 580 dev_err(ring->dma_dev, "CBD alloc data memory failed!\n"); 581 return NULL; 582 } 583 584 dma_align = ALIGN(*dma, ENETC_CBD_DATA_MEM_ALIGN); 585 *data_align = PTR_ALIGN(data, ENETC_CBD_DATA_MEM_ALIGN); 586 587 cbd->addr[0] = cpu_to_le32(lower_32_bits(dma_align)); 588 cbd->addr[1] = cpu_to_le32(upper_32_bits(dma_align)); 589 cbd->length = cpu_to_le16(size); 590 591 return data; 592} 593 594static inline void enetc_cbd_free_data_mem(struct enetc_si *si, int size, 595 void *data, dma_addr_t *dma) 596{ 597 struct enetc_cbdr *ring = &si->cbd_ring; 598 599 dma_free_coherent(ring->dma_dev, size + ENETC_CBD_DATA_MEM_ALIGN, 600 data, *dma); 601} 602 603void enetc_reset_ptcmsdur(struct enetc_hw *hw); 604void enetc_set_ptcmsdur(struct enetc_hw *hw, u32 *queue_max_sdu); 605 606static inline bool enetc_ptp_clock_is_enabled(struct enetc_si *si) 607{ 608 if (is_enetc_rev1(si)) 609 return IS_ENABLED(CONFIG_FSL_ENETC_PTP_CLOCK); 610 611 return IS_ENABLED(CONFIG_PTP_NETC_V4_TIMER); 612} 613 614#ifdef CONFIG_FSL_ENETC_QOS 615int enetc_qos_query_caps(struct net_device *ndev, void *type_data); 616int enetc_setup_tc_taprio(struct net_device *ndev, void *type_data); 617void enetc_sched_speed_set(struct enetc_ndev_priv *priv, int speed); 618int enetc_setup_tc_cbs(struct net_device *ndev, void *type_data); 619int enetc_setup_tc_txtime(struct net_device *ndev, void *type_data); 620int enetc_setup_tc_block_cb(enum tc_setup_type type, void *type_data, 621 void *cb_priv); 622int enetc_setup_tc_psfp(struct net_device *ndev, void *type_data); 623int enetc_psfp_init(struct enetc_ndev_priv *priv); 624int enetc_psfp_clean(struct enetc_ndev_priv *priv); 625int enetc_set_psfp(struct net_device *ndev, bool en); 626 627static inline void enetc_get_max_cap(struct enetc_ndev_priv *priv) 628{ 629 struct enetc_hw *hw = &priv->si->hw; 630 u32 reg; 631 632 reg = enetc_port_rd(hw, ENETC_PSIDCAPR); 633 priv->psfp_cap.max_streamid = reg & ENETC_PSIDCAPR_MSK; 634 /* Port stream filter capability */ 635 reg = enetc_port_rd(hw, ENETC_PSFCAPR); 636 priv->psfp_cap.max_psfp_filter = reg & ENETC_PSFCAPR_MSK; 637 /* Port stream gate capability */ 638 reg = enetc_port_rd(hw, ENETC_PSGCAPR); 639 priv->psfp_cap.max_psfp_gate = (reg & ENETC_PSGCAPR_SGIT_MSK); 640 priv->psfp_cap.max_psfp_gatelist = (reg & ENETC_PSGCAPR_GCL_MSK) >> 16; 641 /* Port flow meter capability */ 642 reg = enetc_port_rd(hw, ENETC_PFMCAPR); 643 priv->psfp_cap.max_psfp_meter = reg & ENETC_PFMCAPR_MSK; 644} 645 646static inline int enetc_psfp_enable(struct enetc_ndev_priv *priv) 647{ 648 struct enetc_hw *hw = &priv->si->hw; 649 int err; 650 651 enetc_get_max_cap(priv); 652 653 err = enetc_psfp_init(priv); 654 if (err) 655 return err; 656 657 enetc_wr(hw, ENETC_PPSFPMR, enetc_rd(hw, ENETC_PPSFPMR) | 658 ENETC_PPSFPMR_PSFPEN | ENETC_PPSFPMR_VS | 659 ENETC_PPSFPMR_PVC | ENETC_PPSFPMR_PVZC); 660 661 return 0; 662} 663 664static inline int enetc_psfp_disable(struct enetc_ndev_priv *priv) 665{ 666 struct enetc_hw *hw = &priv->si->hw; 667 int err; 668 669 err = enetc_psfp_clean(priv); 670 if (err) 671 return err; 672 673 enetc_wr(hw, ENETC_PPSFPMR, enetc_rd(hw, ENETC_PPSFPMR) & 674 ~ENETC_PPSFPMR_PSFPEN & ~ENETC_PPSFPMR_VS & 675 ~ENETC_PPSFPMR_PVC & ~ENETC_PPSFPMR_PVZC); 676 677 memset(&priv->psfp_cap, 0, sizeof(struct psfp_cap)); 678 679 return 0; 680} 681 682#else 683#define enetc_qos_query_caps(ndev, type_data) -EOPNOTSUPP 684#define enetc_setup_tc_taprio(ndev, type_data) -EOPNOTSUPP 685#define enetc_sched_speed_set(priv, speed) (void)0 686#define enetc_setup_tc_cbs(ndev, type_data) -EOPNOTSUPP 687#define enetc_setup_tc_txtime(ndev, type_data) -EOPNOTSUPP 688#define enetc_setup_tc_psfp(ndev, type_data) -EOPNOTSUPP 689#define enetc_setup_tc_block_cb NULL 690 691#define enetc_get_max_cap(p) \ 692 memset(&((p)->psfp_cap), 0, sizeof(struct psfp_cap)) 693 694static inline int enetc_psfp_enable(struct enetc_ndev_priv *priv) 695{ 696 return 0; 697} 698 699static inline int enetc_psfp_disable(struct enetc_ndev_priv *priv) 700{ 701 return 0; 702} 703 704static inline int enetc_set_psfp(struct net_device *ndev, bool en) 705{ 706 return 0; 707} 708#endif
~/
Read-only file preview.