1/* SPDX-License-Identifier: GPL-2.0+ */ 2 3#ifndef __LAN966X_MAIN_H__ 4#define __LAN966X_MAIN_H__ 5 6#include <linux/debugfs.h> 7#include <linux/etherdevice.h> 8#include <linux/if_vlan.h> 9#include <linux/jiffies.h> 10#include <linux/phy.h> 11#include <linux/phylink.h> 12#include <linux/ptp_clock_kernel.h> 13#include <net/page_pool/types.h> 14#include <net/pkt_cls.h> 15#include <net/pkt_sched.h> 16#include <net/switchdev.h> 17#include <net/xdp.h> 18 19#include <vcap_api.h> 20#include <vcap_api_client.h> 21 22#include "lan966x_regs.h" 23#include "lan966x_ifh.h" 24 25#define TABLE_UPDATE_SLEEP_US 10 26#define TABLE_UPDATE_TIMEOUT_US 100000 27 28#define READL_SLEEP_US 10 29#define READL_TIMEOUT_US 100000000 30 31#define LAN966X_BUFFER_CELL_SZ 64 32#define LAN966X_BUFFER_MEMORY (160 * 1024) 33#define LAN966X_BUFFER_MIN_SZ 60 34 35#define LAN966X_HW_MTU(mtu) ((mtu) + ETH_HLEN + ETH_FCS_LEN) 36 37#define PGID_AGGR 64 38#define PGID_SRC 80 39#define PGID_ENTRIES 89 40 41#define UNAWARE_PVID 0 42#define HOST_PVID 4095 43 44/* Reserved amount for (SRC, PRIO) at index 8*SRC + PRIO */ 45#define QSYS_Q_RSRV 95 46 47#define NUM_PHYS_PORTS 8 48#define CPU_PORT 8 49#define NUM_PRIO_QUEUES 8 50 51/* Reserved PGIDs */ 52#define PGID_CPU (PGID_AGGR - 6) 53#define PGID_UC (PGID_AGGR - 5) 54#define PGID_BC (PGID_AGGR - 4) 55#define PGID_MC (PGID_AGGR - 3) 56#define PGID_MCIPV4 (PGID_AGGR - 2) 57#define PGID_MCIPV6 (PGID_AGGR - 1) 58 59/* Non-reserved PGIDs, used for general purpose */ 60#define PGID_GP_START (CPU_PORT + 1) 61#define PGID_GP_END PGID_CPU 62 63#define LAN966X_SPEED_NONE 0 64#define LAN966X_SPEED_2500 1 65#define LAN966X_SPEED_1000 1 66#define LAN966X_SPEED_100 2 67#define LAN966X_SPEED_10 3 68 69#define LAN966X_PHC_COUNT 3 70#define LAN966X_PHC_PORT 0 71#define LAN966X_PHC_PINS_NUM 7 72 73#define IFH_REW_OP_NOOP 0x0 74#define IFH_REW_OP_ONE_STEP_PTP 0x3 75#define IFH_REW_OP_TWO_STEP_PTP 0x4 76 77#define FDMA_RX_DCB_MAX_DBS 1 78#define FDMA_TX_DCB_MAX_DBS 1 79#define FDMA_DCB_INFO_DATAL(x) ((x) & GENMASK(15, 0)) 80 81#define FDMA_DCB_STATUS_BLOCKL(x) ((x) & GENMASK(15, 0)) 82#define FDMA_DCB_STATUS_SOF BIT(16) 83#define FDMA_DCB_STATUS_EOF BIT(17) 84#define FDMA_DCB_STATUS_INTR BIT(18) 85#define FDMA_DCB_STATUS_DONE BIT(19) 86#define FDMA_DCB_STATUS_BLOCKO(x) (((x) << 20) & GENMASK(31, 20)) 87#define FDMA_DCB_INVALID_DATA 0x1 88 89#define FDMA_XTR_CHANNEL 6 90#define FDMA_INJ_CHANNEL 0 91#define FDMA_DCB_MAX 512 92 93#define SE_IDX_QUEUE 0 /* 0-79 : Queue scheduler elements */ 94#define SE_IDX_PORT 80 /* 80-89 : Port schedular elements */ 95 96#define LAN966X_VCAP_CID_IS1_L0 VCAP_CID_INGRESS_L0 /* IS1 lookup 0 */ 97#define LAN966X_VCAP_CID_IS1_L1 VCAP_CID_INGRESS_L1 /* IS1 lookup 1 */ 98#define LAN966X_VCAP_CID_IS1_L2 VCAP_CID_INGRESS_L2 /* IS1 lookup 2 */ 99#define LAN966X_VCAP_CID_IS1_MAX (VCAP_CID_INGRESS_L3 - 1) /* IS1 Max */ 100 101#define LAN966X_VCAP_CID_IS2_L0 VCAP_CID_INGRESS_STAGE2_L0 /* IS2 lookup 0 */ 102#define LAN966X_VCAP_CID_IS2_L1 VCAP_CID_INGRESS_STAGE2_L1 /* IS2 lookup 1 */ 103#define LAN966X_VCAP_CID_IS2_MAX (VCAP_CID_INGRESS_STAGE2_L2 - 1) /* IS2 Max */ 104 105#define LAN966X_VCAP_CID_ES0_L0 VCAP_CID_EGRESS_L0 /* ES0 lookup 0 */ 106#define LAN966X_VCAP_CID_ES0_MAX (VCAP_CID_EGRESS_L1 - 1) /* ES0 Max */ 107 108#define LAN966X_PORT_QOS_PCP_COUNT 8 109#define LAN966X_PORT_QOS_DEI_COUNT 8 110#define LAN966X_PORT_QOS_PCP_DEI_COUNT \ 111 (LAN966X_PORT_QOS_PCP_COUNT + LAN966X_PORT_QOS_DEI_COUNT) 112 113#define LAN966X_PORT_QOS_DSCP_COUNT 64 114 115/* Port PCP rewrite mode */ 116#define LAN966X_PORT_REW_TAG_CTRL_CLASSIFIED 0 117#define LAN966X_PORT_REW_TAG_CTRL_MAPPED 2 118 119/* Port DSCP rewrite mode */ 120#define LAN966X_PORT_REW_DSCP_FRAME 0 121#define LAN966X_PORT_REW_DSCP_ANALIZER 1 122#define LAN966X_PORT_QOS_REWR_DSCP_ALL 3 123 124/* MAC table entry types. 125 * ENTRYTYPE_NORMAL is subject to aging. 126 * ENTRYTYPE_LOCKED is not subject to aging. 127 * ENTRYTYPE_MACv4 is not subject to aging. For IPv4 multicast. 128 * ENTRYTYPE_MACv6 is not subject to aging. For IPv6 multicast. 129 */ 130enum macaccess_entry_type { 131 ENTRYTYPE_NORMAL = 0, 132 ENTRYTYPE_LOCKED, 133 ENTRYTYPE_MACV4, 134 ENTRYTYPE_MACV6, 135}; 136 137/* FDMA return action codes for checking if the frame is valid 138 * FDMA_PASS, frame is valid and can be used 139 * FDMA_ERROR, something went wrong, stop getting more frames 140 * FDMA_DROP, frame is dropped, but continue to get more frames 141 * FDMA_TX, frame is given to TX, but continue to get more frames 142 * FDMA_REDIRECT, frame is given to TX, but continue to get more frames 143 */ 144enum lan966x_fdma_action { 145 FDMA_PASS = 0, 146 FDMA_ERROR, 147 FDMA_DROP, 148 FDMA_TX, 149 FDMA_REDIRECT, 150}; 151 152/* Controls how PORT_MASK is applied */ 153enum LAN966X_PORT_MASK_MODE { 154 LAN966X_PMM_NO_ACTION, 155 LAN966X_PMM_REPLACE, 156 LAN966X_PMM_FORWARDING, 157 LAN966X_PMM_REDIRECT, 158}; 159 160enum vcap_is2_port_sel_ipv6 { 161 VCAP_IS2_PS_IPV6_TCPUDP_OTHER, 162 VCAP_IS2_PS_IPV6_STD, 163 VCAP_IS2_PS_IPV6_IP4_TCPUDP_IP4_OTHER, 164 VCAP_IS2_PS_IPV6_MAC_ETYPE, 165}; 166 167enum vcap_is1_port_sel_other { 168 VCAP_IS1_PS_OTHER_NORMAL, 169 VCAP_IS1_PS_OTHER_7TUPLE, 170 VCAP_IS1_PS_OTHER_DBL_VID, 171 VCAP_IS1_PS_OTHER_DMAC_VID, 172}; 173 174enum vcap_is1_port_sel_ipv4 { 175 VCAP_IS1_PS_IPV4_NORMAL, 176 VCAP_IS1_PS_IPV4_7TUPLE, 177 VCAP_IS1_PS_IPV4_5TUPLE_IP4, 178 VCAP_IS1_PS_IPV4_DBL_VID, 179 VCAP_IS1_PS_IPV4_DMAC_VID, 180}; 181 182enum vcap_is1_port_sel_ipv6 { 183 VCAP_IS1_PS_IPV6_NORMAL, 184 VCAP_IS1_PS_IPV6_7TUPLE, 185 VCAP_IS1_PS_IPV6_5TUPLE_IP4, 186 VCAP_IS1_PS_IPV6_NORMAL_IP6, 187 VCAP_IS1_PS_IPV6_5TUPLE_IP6, 188 VCAP_IS1_PS_IPV6_DBL_VID, 189 VCAP_IS1_PS_IPV6_DMAC_VID, 190}; 191 192enum vcap_is1_port_sel_rt { 193 VCAP_IS1_PS_RT_NORMAL, 194 VCAP_IS1_PS_RT_7TUPLE, 195 VCAP_IS1_PS_RT_DBL_VID, 196 VCAP_IS1_PS_RT_DMAC_VID, 197 VCAP_IS1_PS_RT_FOLLOW_OTHER = 7, 198}; 199 200struct lan966x_port; 201 202struct lan966x_db { 203 u64 dataptr; 204 u64 status; 205}; 206 207struct lan966x_rx_dcb { 208 u64 nextptr; 209 u64 info; 210 struct lan966x_db db[FDMA_RX_DCB_MAX_DBS]; 211}; 212 213struct lan966x_tx_dcb { 214 u64 nextptr; 215 u64 info; 216 struct lan966x_db db[FDMA_TX_DCB_MAX_DBS]; 217}; 218 219struct lan966x_rx { 220 struct lan966x *lan966x; 221 222 /* Pointer to the array of hardware dcbs. */ 223 struct lan966x_rx_dcb *dcbs; 224 225 /* Pointer to the last address in the dcbs. */ 226 struct lan966x_rx_dcb *last_entry; 227 228 /* For each DB, there is a page */ 229 struct page *page[FDMA_DCB_MAX][FDMA_RX_DCB_MAX_DBS]; 230 231 /* Represents the db_index, it can have a value between 0 and 232 * FDMA_RX_DCB_MAX_DBS, once it reaches the value of FDMA_RX_DCB_MAX_DBS 233 * it means that the DCB can be reused. 234 */ 235 int db_index; 236 237 /* Represents the index in the dcbs. It has a value between 0 and 238 * FDMA_DCB_MAX 239 */ 240 int dcb_index; 241 242 /* Represents the dma address to the dcbs array */ 243 dma_addr_t dma; 244 245 /* Represents the page order that is used to allocate the pages for the 246 * RX buffers. This value is calculated based on max MTU of the devices. 247 */ 248 u8 page_order; 249 250 /* Represents the max size frame that it can receive to the CPU. This 251 * includes the IFH + VLAN tags + frame + skb_shared_info 252 */ 253 u32 max_mtu; 254 255 u8 channel_id; 256 257 struct page_pool *page_pool; 258}; 259 260struct lan966x_tx_dcb_buf { 261 dma_addr_t dma_addr; 262 struct net_device *dev; 263 union { 264 struct sk_buff *skb; 265 struct xdp_frame *xdpf; 266 struct page *page; 267 } data; 268 u32 len; 269 u32 used : 1; 270 u32 ptp : 1; 271 u32 use_skb : 1; 272 u32 xdp_ndo : 1; 273}; 274 275struct lan966x_tx { 276 struct lan966x *lan966x; 277 278 /* Pointer to the dcb list */ 279 struct lan966x_tx_dcb *dcbs; 280 u16 last_in_use; 281 282 /* Represents the DMA address to the first entry of the dcb entries. */ 283 dma_addr_t dma; 284 285 /* Array of dcbs that are given to the HW */ 286 struct lan966x_tx_dcb_buf *dcbs_buf; 287 288 u8 channel_id; 289 290 bool activated; 291}; 292 293struct lan966x_stat_layout { 294 u32 offset; 295 char name[ETH_GSTRING_LEN]; 296}; 297 298struct lan966x_phc { 299 struct ptp_clock *clock; 300 struct ptp_clock_info info; 301 struct ptp_pin_desc pins[LAN966X_PHC_PINS_NUM]; 302 struct kernel_hwtstamp_config hwtstamp_config; 303 struct lan966x *lan966x; 304 u8 index; 305}; 306 307struct lan966x_skb_cb { 308 u8 rew_op; 309 u16 ts_id; 310 unsigned long jiffies; 311}; 312 313#define LAN966X_PTP_TIMEOUT msecs_to_jiffies(10) 314#define LAN966X_SKB_CB(skb) \ 315 ((struct lan966x_skb_cb *)((skb)->cb)) 316 317struct lan966x { 318 struct device *dev; 319 320 u8 num_phys_ports; 321 struct lan966x_port **ports; 322 323 void __iomem *regs[NUM_TARGETS]; 324 325 int shared_queue_sz; 326 327 u8 base_mac[ETH_ALEN]; 328 329 spinlock_t tx_lock; /* lock for frame transmition */ 330 331 struct net_device *bridge; 332 u16 bridge_mask; 333 u16 bridge_fwd_mask; 334 335 struct list_head mac_entries; 336 spinlock_t mac_lock; /* lock for mac_entries list */ 337 338 u16 vlan_mask[VLAN_N_VID]; 339 DECLARE_BITMAP(cpu_vlan_mask, VLAN_N_VID); 340 341 /* stats */ 342 const struct lan966x_stat_layout *stats_layout; 343 u32 num_stats; 344 345 /* workqueue for reading stats */ 346 struct mutex stats_lock; 347 u64 *stats; 348 struct delayed_work stats_work; 349 struct workqueue_struct *stats_queue; 350 351 /* interrupts */ 352 int xtr_irq; 353 int ana_irq; 354 int ptp_irq; 355 int fdma_irq; 356 int ptp_ext_irq; 357 358 /* worqueue for fdb */ 359 struct workqueue_struct *fdb_work; 360 struct list_head fdb_entries; 361 362 /* mdb */ 363 struct list_head mdb_entries; 364 struct list_head pgid_entries; 365 366 /* ptp */ 367 bool ptp; 368 struct lan966x_phc phc[LAN966X_PHC_COUNT]; 369 spinlock_t ptp_clock_lock; /* lock for phc */ 370 spinlock_t ptp_ts_id_lock; /* lock for ts_id */ 371 struct mutex ptp_lock; /* lock for ptp interface state */ 372 u16 ptp_skbs; 373 374 /* fdma */ 375 bool fdma; 376 struct net_device *fdma_ndev; 377 struct lan966x_rx rx; 378 struct lan966x_tx tx; 379 struct napi_struct napi; 380 381 /* Mirror */ 382 struct lan966x_port *mirror_monitor; 383 u32 mirror_mask[2]; 384 u32 mirror_count; 385 386 /* vcap */ 387 struct vcap_control *vcap_ctrl; 388 389 /* debugfs */ 390 struct dentry *debugfs_root; 391}; 392 393struct lan966x_port_config { 394 phy_interface_t portmode; 395 const unsigned long *advertising; 396 int speed; 397 int duplex; 398 u32 pause; 399 bool inband; 400 bool autoneg; 401}; 402 403struct lan966x_port_tc { 404 bool ingress_shared_block; 405 unsigned long police_id; 406 unsigned long ingress_mirror_id; 407 unsigned long egress_mirror_id; 408 struct flow_stats police_stat; 409 struct flow_stats mirror_stat; 410}; 411 412struct lan966x_port_qos_pcp { 413 u8 map[LAN966X_PORT_QOS_PCP_DEI_COUNT]; 414 bool enable; 415}; 416 417struct lan966x_port_qos_dscp { 418 u8 map[LAN966X_PORT_QOS_DSCP_COUNT]; 419 bool enable; 420}; 421 422struct lan966x_port_qos_pcp_rewr { 423 u16 map[NUM_PRIO_QUEUES]; 424 bool enable; 425}; 426 427struct lan966x_port_qos_dscp_rewr { 428 u16 map[LAN966X_PORT_QOS_DSCP_COUNT]; 429 bool enable; 430}; 431 432struct lan966x_port_qos { 433 struct lan966x_port_qos_pcp pcp; 434 struct lan966x_port_qos_dscp dscp; 435 struct lan966x_port_qos_pcp_rewr pcp_rewr; 436 struct lan966x_port_qos_dscp_rewr dscp_rewr; 437 u8 default_prio; 438}; 439 440struct lan966x_port { 441 struct net_device *dev; 442 struct lan966x *lan966x; 443 444 u8 chip_port; 445 u16 pvid; 446 u16 vid; 447 bool vlan_aware; 448 449 bool learn_ena; 450 bool mcast_ena; 451 452 struct phylink_config phylink_config; 453 struct phylink_pcs phylink_pcs; 454 struct lan966x_port_config config; 455 struct phylink *phylink; 456 struct phy *serdes; 457 struct fwnode_handle *fwnode; 458 459 u8 ptp_tx_cmd; 460 bool ptp_rx_cmd; 461 u16 ts_id; 462 struct sk_buff_head tx_skbs; 463 464 struct net_device *bond; 465 bool lag_tx_active; 466 enum netdev_lag_hash hash_type; 467 468 struct lan966x_port_tc tc; 469 470 struct bpf_prog *xdp_prog; 471 struct xdp_rxq_info xdp_rxq; 472}; 473 474extern const struct phylink_mac_ops lan966x_phylink_mac_ops; 475extern const struct phylink_pcs_ops lan966x_phylink_pcs_ops; 476extern const struct ethtool_ops lan966x_ethtool_ops; 477extern struct notifier_block lan966x_switchdev_nb __read_mostly; 478extern struct notifier_block lan966x_switchdev_blocking_nb __read_mostly; 479 480bool lan966x_netdevice_check(const struct net_device *dev); 481 482void lan966x_register_notifier_blocks(void); 483void lan966x_unregister_notifier_blocks(void); 484 485bool lan966x_hw_offload(struct lan966x *lan966x, u32 port, struct sk_buff *skb); 486 487void lan966x_ifh_get_src_port(void *ifh, u64 *src_port); 488void lan966x_ifh_get_timestamp(void *ifh, u64 *timestamp); 489void lan966x_ifh_set_bypass(void *ifh, u64 bypass); 490void lan966x_ifh_set_port(void *ifh, u64 bypass); 491 492void lan966x_stats_get(struct net_device *dev, 493 struct rtnl_link_stats64 *stats); 494int lan966x_stats_init(struct lan966x *lan966x); 495 496void lan966x_port_config_down(struct lan966x_port *port); 497void lan966x_port_config_up(struct lan966x_port *port); 498void lan966x_port_status_get(struct lan966x_port *port, 499 struct phylink_link_state *state); 500int lan966x_port_pcs_set(struct lan966x_port *port, 501 struct lan966x_port_config *config); 502void lan966x_port_init(struct lan966x_port *port); 503 504void lan966x_port_qos_set(struct lan966x_port *port, 505 struct lan966x_port_qos *qos); 506void lan966x_port_qos_dscp_rewr_mode_set(struct lan966x_port *port, 507 int mode); 508 509int lan966x_mac_ip_learn(struct lan966x *lan966x, 510 bool cpu_copy, 511 const unsigned char mac[ETH_ALEN], 512 unsigned int vid, 513 enum macaccess_entry_type type); 514int lan966x_mac_learn(struct lan966x *lan966x, int port, 515 const unsigned char mac[ETH_ALEN], 516 unsigned int vid, 517 enum macaccess_entry_type type); 518int lan966x_mac_forget(struct lan966x *lan966x, 519 const unsigned char mac[ETH_ALEN], 520 unsigned int vid, 521 enum macaccess_entry_type type); 522int lan966x_mac_cpu_learn(struct lan966x *lan966x, const char *addr, u16 vid); 523int lan966x_mac_cpu_forget(struct lan966x *lan966x, const char *addr, u16 vid); 524void lan966x_mac_init(struct lan966x *lan966x); 525void lan966x_mac_set_ageing(struct lan966x *lan966x, 526 u32 ageing); 527int lan966x_mac_del_entry(struct lan966x *lan966x, 528 const unsigned char *addr, 529 u16 vid); 530int lan966x_mac_add_entry(struct lan966x *lan966x, 531 struct lan966x_port *port, 532 const unsigned char *addr, 533 u16 vid); 534void lan966x_mac_lag_replace_port_entry(struct lan966x *lan966x, 535 struct lan966x_port *src, 536 struct lan966x_port *dst); 537void lan966x_mac_lag_remove_port_entry(struct lan966x *lan966x, 538 struct lan966x_port *src); 539void lan966x_mac_purge_entries(struct lan966x *lan966x); 540irqreturn_t lan966x_mac_irq_handler(struct lan966x *lan966x); 541 542void lan966x_vlan_init(struct lan966x *lan966x); 543void lan966x_vlan_port_apply(struct lan966x_port *port); 544bool lan966x_vlan_cpu_member_cpu_vlan_mask(struct lan966x *lan966x, u16 vid); 545void lan966x_vlan_port_set_vlan_aware(struct lan966x_port *port, 546 bool vlan_aware); 547int lan966x_vlan_port_set_vid(struct lan966x_port *port, 548 u16 vid, 549 bool pvid, 550 bool untagged); 551void lan966x_vlan_port_add_vlan(struct lan966x_port *port, 552 u16 vid, 553 bool pvid, 554 bool untagged); 555void lan966x_vlan_port_del_vlan(struct lan966x_port *port, u16 vid); 556void lan966x_vlan_cpu_add_vlan(struct lan966x *lan966x, u16 vid); 557void lan966x_vlan_cpu_del_vlan(struct lan966x *lan966x, u16 vid); 558 559void lan966x_fdb_write_entries(struct lan966x *lan966x, u16 vid); 560void lan966x_fdb_erase_entries(struct lan966x *lan966x, u16 vid); 561int lan966x_fdb_init(struct lan966x *lan966x); 562void lan966x_fdb_deinit(struct lan966x *lan966x); 563void lan966x_fdb_flush_workqueue(struct lan966x *lan966x); 564int lan966x_handle_fdb(struct net_device *dev, 565 struct net_device *orig_dev, 566 unsigned long event, const void *ctx, 567 const struct switchdev_notifier_fdb_info *fdb_info); 568 569void lan966x_mdb_init(struct lan966x *lan966x); 570void lan966x_mdb_deinit(struct lan966x *lan966x); 571int lan966x_handle_port_mdb_add(struct lan966x_port *port, 572 const struct switchdev_obj *obj); 573int lan966x_handle_port_mdb_del(struct lan966x_port *port, 574 const struct switchdev_obj *obj); 575void lan966x_mdb_erase_entries(struct lan966x *lan966x, u16 vid); 576void lan966x_mdb_write_entries(struct lan966x *lan966x, u16 vid); 577void lan966x_mdb_clear_entries(struct lan966x *lan966x); 578void lan966x_mdb_restore_entries(struct lan966x *lan966x); 579 580int lan966x_ptp_init(struct lan966x *lan966x); 581void lan966x_ptp_deinit(struct lan966x *lan966x); 582int lan966x_ptp_hwtstamp_set(struct lan966x_port *port, 583 struct kernel_hwtstamp_config *cfg, 584 struct netlink_ext_ack *extack); 585void lan966x_ptp_hwtstamp_get(struct lan966x_port *port, 586 struct kernel_hwtstamp_config *cfg); 587void lan966x_ptp_rxtstamp(struct lan966x *lan966x, struct sk_buff *skb, 588 u64 src_port, u64 timestamp); 589int lan966x_ptp_txtstamp_request(struct lan966x_port *port, 590 struct sk_buff *skb); 591void lan966x_ptp_txtstamp_release(struct lan966x_port *port, 592 struct sk_buff *skb); 593irqreturn_t lan966x_ptp_irq_handler(int irq, void *args); 594irqreturn_t lan966x_ptp_ext_irq_handler(int irq, void *args); 595u32 lan966x_ptp_get_period_ps(void); 596int lan966x_ptp_gettime64(struct ptp_clock_info *ptp, struct timespec64 *ts); 597int lan966x_ptp_setup_traps(struct lan966x_port *port, 598 struct kernel_hwtstamp_config *cfg); 599int lan966x_ptp_del_traps(struct lan966x_port *port); 600 601int lan966x_fdma_xmit(struct sk_buff *skb, __be32 *ifh, struct net_device *dev); 602int lan966x_fdma_xmit_xdpf(struct lan966x_port *port, void *ptr, u32 len); 603int lan966x_fdma_change_mtu(struct lan966x *lan966x); 604void lan966x_fdma_netdev_init(struct lan966x *lan966x, struct net_device *dev); 605void lan966x_fdma_netdev_deinit(struct lan966x *lan966x, struct net_device *dev); 606int lan966x_fdma_init(struct lan966x *lan966x); 607void lan966x_fdma_deinit(struct lan966x *lan966x); 608irqreturn_t lan966x_fdma_irq_handler(int irq, void *args); 609int lan966x_fdma_reload_page_pool(struct lan966x *lan966x); 610 611int lan966x_lag_port_join(struct lan966x_port *port, 612 struct net_device *brport_dev, 613 struct net_device *bond, 614 struct netlink_ext_ack *extack); 615void lan966x_lag_port_leave(struct lan966x_port *port, struct net_device *bond); 616int lan966x_lag_port_prechangeupper(struct net_device *dev, 617 struct netdev_notifier_changeupper_info *info); 618int lan966x_lag_port_changelowerstate(struct net_device *dev, 619 struct netdev_notifier_changelowerstate_info *info); 620int lan966x_lag_netdev_prechangeupper(struct net_device *dev, 621 struct netdev_notifier_changeupper_info *info); 622int lan966x_lag_netdev_changeupper(struct net_device *dev, 623 struct netdev_notifier_changeupper_info *info); 624bool lan966x_lag_first_port(struct net_device *lag, struct net_device *dev); 625u32 lan966x_lag_get_mask(struct lan966x *lan966x, struct net_device *bond); 626 627int lan966x_port_changeupper(struct net_device *dev, 628 struct net_device *brport_dev, 629 struct netdev_notifier_changeupper_info *info); 630int lan966x_port_prechangeupper(struct net_device *dev, 631 struct net_device *brport_dev, 632 struct netdev_notifier_changeupper_info *info); 633void lan966x_port_stp_state_set(struct lan966x_port *port, u8 state); 634void lan966x_port_ageing_set(struct lan966x_port *port, 635 unsigned long ageing_clock_t); 636void lan966x_update_fwd_mask(struct lan966x *lan966x); 637 638int lan966x_tc_setup(struct net_device *dev, enum tc_setup_type type, 639 void *type_data); 640 641int lan966x_mqprio_add(struct lan966x_port *port, u8 num_tc); 642int lan966x_mqprio_del(struct lan966x_port *port); 643 644void lan966x_taprio_init(struct lan966x *lan966x); 645void lan966x_taprio_deinit(struct lan966x *lan966x); 646int lan966x_taprio_add(struct lan966x_port *port, 647 struct tc_taprio_qopt_offload *qopt); 648int lan966x_taprio_del(struct lan966x_port *port); 649int lan966x_taprio_speed_set(struct lan966x_port *port, int speed); 650 651int lan966x_tbf_add(struct lan966x_port *port, 652 struct tc_tbf_qopt_offload *qopt); 653int lan966x_tbf_del(struct lan966x_port *port, 654 struct tc_tbf_qopt_offload *qopt); 655 656int lan966x_cbs_add(struct lan966x_port *port, 657 struct tc_cbs_qopt_offload *qopt); 658int lan966x_cbs_del(struct lan966x_port *port, 659 struct tc_cbs_qopt_offload *qopt); 660 661int lan966x_ets_add(struct lan966x_port *port, 662 struct tc_ets_qopt_offload *qopt); 663int lan966x_ets_del(struct lan966x_port *port, 664 struct tc_ets_qopt_offload *qopt); 665 666int lan966x_tc_matchall(struct lan966x_port *port, 667 struct tc_cls_matchall_offload *f, 668 bool ingress); 669 670int lan966x_police_port_add(struct lan966x_port *port, 671 struct flow_action *action, 672 struct flow_action_entry *act, 673 unsigned long police_id, 674 bool ingress, 675 struct netlink_ext_ack *extack); 676int lan966x_police_port_del(struct lan966x_port *port, 677 unsigned long police_id, 678 struct netlink_ext_ack *extack); 679void lan966x_police_port_stats(struct lan966x_port *port, 680 struct flow_stats *stats); 681 682int lan966x_mirror_port_add(struct lan966x_port *port, 683 struct flow_action_entry *action, 684 unsigned long mirror_id, 685 bool ingress, 686 struct netlink_ext_ack *extack); 687int lan966x_mirror_port_del(struct lan966x_port *port, 688 bool ingress, 689 struct netlink_ext_ack *extack); 690void lan966x_mirror_port_stats(struct lan966x_port *port, 691 struct flow_stats *stats, 692 bool ingress); 693 694int lan966x_xdp_port_init(struct lan966x_port *port); 695void lan966x_xdp_port_deinit(struct lan966x_port *port); 696int lan966x_xdp(struct net_device *dev, struct netdev_bpf *xdp); 697int lan966x_xdp_run(struct lan966x_port *port, 698 struct page *page, 699 u32 data_len); 700int lan966x_xdp_xmit(struct net_device *dev, 701 int n, 702 struct xdp_frame **frames, 703 u32 flags); 704bool lan966x_xdp_present(struct lan966x *lan966x); 705static inline bool lan966x_xdp_port_present(struct lan966x_port *port) 706{ 707 return !!port->xdp_prog; 708} 709 710int lan966x_vcap_init(struct lan966x *lan966x); 711void lan966x_vcap_deinit(struct lan966x *lan966x); 712#if defined(CONFIG_DEBUG_FS) 713int lan966x_vcap_port_info(struct net_device *dev, 714 struct vcap_admin *admin, 715 struct vcap_output_print *out); 716#else 717static inline int lan966x_vcap_port_info(struct net_device *dev, 718 struct vcap_admin *admin, 719 struct vcap_output_print *out) 720{ 721 return 0; 722} 723#endif 724 725int lan966x_tc_flower(struct lan966x_port *port, 726 struct flow_cls_offload *f, 727 bool ingress); 728 729int lan966x_goto_port_add(struct lan966x_port *port, 730 int from_cid, int to_cid, 731 unsigned long goto_id, 732 struct netlink_ext_ack *extack); 733int lan966x_goto_port_del(struct lan966x_port *port, 734 unsigned long goto_id, 735 struct netlink_ext_ack *extack); 736 737#ifdef CONFIG_LAN966X_DCB 738void lan966x_dcb_init(struct lan966x *lan966x); 739#else 740static inline void lan966x_dcb_init(struct lan966x *lan966x) 741{ 742} 743#endif 744 745static inline void __iomem *lan_addr(void __iomem *base[], 746 int id, int tinst, int tcnt, 747 int gbase, int ginst, 748 int gcnt, int gwidth, 749 int raddr, int rinst, 750 int rcnt, int rwidth) 751{ 752 WARN_ON((tinst) >= tcnt); 753 WARN_ON((ginst) >= gcnt); 754 WARN_ON((rinst) >= rcnt); 755 return base[id + (tinst)] + 756 gbase + ((ginst) * gwidth) + 757 raddr + ((rinst) * rwidth); 758} 759 760static inline u32 lan_rd(struct lan966x *lan966x, int id, int tinst, int tcnt, 761 int gbase, int ginst, int gcnt, int gwidth, 762 int raddr, int rinst, int rcnt, int rwidth) 763{ 764 return readl(lan_addr(lan966x->regs, id, tinst, tcnt, gbase, ginst, 765 gcnt, gwidth, raddr, rinst, rcnt, rwidth)); 766} 767 768static inline void lan_wr(u32 val, struct lan966x *lan966x, 769 int id, int tinst, int tcnt, 770 int gbase, int ginst, int gcnt, int gwidth, 771 int raddr, int rinst, int rcnt, int rwidth) 772{ 773 writel(val, lan_addr(lan966x->regs, id, tinst, tcnt, 774 gbase, ginst, gcnt, gwidth, 775 raddr, rinst, rcnt, rwidth)); 776} 777 778static inline void lan_rmw(u32 val, u32 mask, struct lan966x *lan966x, 779 int id, int tinst, int tcnt, 780 int gbase, int ginst, int gcnt, int gwidth, 781 int raddr, int rinst, int rcnt, int rwidth) 782{ 783 u32 nval; 784 785 nval = readl(lan_addr(lan966x->regs, id, tinst, tcnt, gbase, ginst, 786 gcnt, gwidth, raddr, rinst, rcnt, rwidth)); 787 nval = (nval & ~mask) | (val & mask); 788 writel(nval, lan_addr(lan966x->regs, id, tinst, tcnt, gbase, ginst, 789 gcnt, gwidth, raddr, rinst, rcnt, rwidth)); 790} 791 792#endif /* __LAN966X_MAIN_H__ */ 793