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