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