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