1 /* SPDX-License-Identifier: GPL-2.0+ */ 2 /* Microchip Sparx5 Switch driver 3 * 4 * Copyright (c) 2021 Microchip Technology Inc. and its subsidiaries. 5 */ 6 7 #ifndef __SPARX5_MAIN_H__ 8 #define __SPARX5_MAIN_H__ 9 10 #include <linux/types.h> 11 #include <linux/phy/phy.h> 12 #include <linux/netdevice.h> 13 #include <linux/phy.h> 14 #include <linux/if_vlan.h> 15 #include <linux/bitmap.h> 16 #include <linux/phylink.h> 17 #include <linux/net_tstamp.h> 18 #include <linux/ptp_clock_kernel.h> 19 #include <linux/hrtimer.h> 20 #include <linux/debugfs.h> 21 #include <net/flow_offload.h> 22 23 #include <fdma_api.h> 24 25 #include "sparx5_main_regs.h" 26 27 /* Target chip type */ 28 enum spx5_target_chiptype { 29 SPX5_TARGET_CT_7546 = 0x7546, /* SparX-5-64 Enterprise */ 30 SPX5_TARGET_CT_7549 = 0x7549, /* SparX-5-90 Enterprise */ 31 SPX5_TARGET_CT_7552 = 0x7552, /* SparX-5-128 Enterprise */ 32 SPX5_TARGET_CT_7556 = 0x7556, /* SparX-5-160 Enterprise */ 33 SPX5_TARGET_CT_7558 = 0x7558, /* SparX-5-200 Enterprise */ 34 SPX5_TARGET_CT_7546TSN = 0x47546, /* SparX-5-64i Industrial */ 35 SPX5_TARGET_CT_7549TSN = 0x47549, /* SparX-5-90i Industrial */ 36 SPX5_TARGET_CT_7552TSN = 0x47552, /* SparX-5-128i Industrial */ 37 SPX5_TARGET_CT_7556TSN = 0x47556, /* SparX-5-160i Industrial */ 38 SPX5_TARGET_CT_7558TSN = 0x47558, /* SparX-5-200i Industrial */ 39 SPX5_TARGET_CT_LAN9694 = 0x9694, /* lan969x-40 */ 40 SPX5_TARGET_CT_LAN9691VAO = 0x9691, /* lan969x-40-VAO */ 41 SPX5_TARGET_CT_LAN9694TSN = 0x9695, /* lan969x-40-TSN */ 42 SPX5_TARGET_CT_LAN9694RED = 0x969A, /* lan969x-40-RED */ 43 SPX5_TARGET_CT_LAN9696 = 0x9696, /* lan969x-60 */ 44 SPX5_TARGET_CT_LAN9692VAO = 0x9692, /* lan969x-65-VAO */ 45 SPX5_TARGET_CT_LAN9696TSN = 0x9697, /* lan969x-60-TSN */ 46 SPX5_TARGET_CT_LAN9696RED = 0x969B, /* lan969x-60-RED */ 47 SPX5_TARGET_CT_LAN9698 = 0x9698, /* lan969x-100 */ 48 SPX5_TARGET_CT_LAN9693VAO = 0x9693, /* lan969x-100-VAO */ 49 SPX5_TARGET_CT_LAN9698TSN = 0x9699, /* lan969x-100-TSN */ 50 SPX5_TARGET_CT_LAN9698RED = 0x969C, /* lan969x-100-RED */ 51 }; 52 53 enum sparx5_port_max_tags { 54 SPX5_PORT_MAX_TAGS_NONE, /* No extra tags allowed */ 55 SPX5_PORT_MAX_TAGS_ONE, /* Single tag allowed */ 56 SPX5_PORT_MAX_TAGS_TWO /* Single and double tag allowed */ 57 }; 58 59 enum sparx5_vlan_port_type { 60 SPX5_VLAN_PORT_TYPE_UNAWARE, /* VLAN unaware port */ 61 SPX5_VLAN_PORT_TYPE_C, /* C-port */ 62 SPX5_VLAN_PORT_TYPE_S, /* S-port */ 63 SPX5_VLAN_PORT_TYPE_S_CUSTOM /* S-port using custom type */ 64 }; 65 66 /* This is used in calendar configuration */ 67 enum sparx5_cal_bw { 68 SPX5_CAL_SPEED_NONE = 0, 69 SPX5_CAL_SPEED_1G = 1, 70 SPX5_CAL_SPEED_2G5 = 2, 71 SPX5_CAL_SPEED_5G = 3, 72 SPX5_CAL_SPEED_10G = 4, 73 SPX5_CAL_SPEED_25G = 5, 74 SPX5_CAL_SPEED_0G5 = 6, 75 SPX5_CAL_SPEED_12G5 = 7 76 }; 77 78 enum sparx5_feature { 79 SPX5_FEATURE_PSFP = BIT(0), 80 SPX5_FEATURE_PTP = BIT(1), 81 }; 82 83 #define SPX5_PORTS 65 84 #define SPX5_PORTS_ALL 70 /* Total number of ports */ 85 86 #define SPX5_PORT_CPU_0 0 /* CPU Port 0 */ 87 #define SPX5_PORT_CPU_1 1 /* CPU Port 1 */ 88 #define SPX5_PORT_VD0 2 /* VD0/Port used for IPMC */ 89 #define SPX5_PORT_VD1 3 /* VD1/Port used for AFI/OAM */ 90 #define SPX5_PORT_VD2 4 /* VD2/Port used for IPinIP*/ 91 92 #define PGID_UC_FLOOD 0 93 #define PGID_MC_FLOOD 1 94 #define PGID_IPV4_MC_DATA 2 95 #define PGID_IPV4_MC_CTRL 3 96 #define PGID_IPV6_MC_DATA 4 97 #define PGID_IPV6_MC_CTRL 5 98 #define PGID_BCAST 6 99 #define PGID_CPU 7 100 #define PGID_MCAST_START 8 101 102 #define PGID_TABLE_SIZE 3290 103 104 #define IFH_LEN 9 /* 36 bytes */ 105 #define NULL_VID 0 106 #define SPX5_MACT_PULL_DELAY (2 * HZ) 107 #define SPX5_STATS_CHECK_DELAY (1 * HZ) 108 #define SPX5_PRIOS 8 /* Number of priority queues */ 109 #define SPX5_BUFFER_CELL_SZ 184 /* Cell size */ 110 #define SPX5_BUFFER_MEMORY 4194280 /* 22795 words * 184 bytes */ 111 112 #define XTR_QUEUE 0 113 #define INJ_QUEUE 0 114 115 #define FDMA_DCB_MAX 64 116 #define FDMA_RX_DCB_MAX_DBS 15 117 #define FDMA_TX_DCB_MAX_DBS 1 118 119 #define SPARX5_PHC_COUNT 3 120 #define SPARX5_PHC_PORT 0 121 122 #define IFH_REW_OP_NOOP 0x0 123 #define IFH_REW_OP_ONE_STEP_PTP 0x3 124 #define IFH_REW_OP_TWO_STEP_PTP 0x4 125 126 #define IFH_PDU_TYPE_NONE 0x0 127 #define IFH_PDU_TYPE_PTP 0x5 128 #define IFH_PDU_TYPE_IPV4_UDP_PTP 0x6 129 #define IFH_PDU_TYPE_IPV6_UDP_PTP 0x7 130 131 #define SPX5_DSM_CAL_LEN 64 132 #define SPX5_DSM_CAL_MAX_DEVS_PER_TAXI 13 133 #define SPX5_DSM_CAL_EMPTY 0xFFFF 134 135 #define SPARX5_MAX_PTP_ID 512 136 137 struct sparx5; 138 139 struct sparx5_calendar_data { 140 u32 schedule[SPX5_DSM_CAL_LEN]; 141 u32 avg_dist[SPX5_DSM_CAL_MAX_DEVS_PER_TAXI]; 142 u32 taxi_ports[SPX5_DSM_CAL_MAX_DEVS_PER_TAXI]; 143 u32 taxi_speeds[SPX5_DSM_CAL_MAX_DEVS_PER_TAXI]; 144 u32 dev_slots[SPX5_DSM_CAL_MAX_DEVS_PER_TAXI]; 145 u32 new_slots[SPX5_DSM_CAL_LEN]; 146 u32 temp_sched[SPX5_DSM_CAL_LEN]; 147 u32 indices[SPX5_DSM_CAL_LEN]; 148 u32 short_list[SPX5_DSM_CAL_LEN]; 149 u32 long_list[SPX5_DSM_CAL_LEN]; 150 }; 151 152 /* Frame DMA receive state: 153 * For each DB, there is a SKB, and the skb data pointer is mapped in 154 * the DB. Once a frame is received the skb is given to the upper layers 155 * and a new skb is added to the dcb. 156 * When the db_index reached FDMA_RX_DCB_MAX_DBS the DB is reused. 157 */ 158 struct sparx5_rx { 159 struct fdma fdma; 160 struct sk_buff *skb[FDMA_DCB_MAX][FDMA_RX_DCB_MAX_DBS]; 161 dma_addr_t dma; 162 struct napi_struct napi; 163 struct net_device *ndev; 164 u64 packets; 165 }; 166 167 /* Frame DMA transmit state: 168 * DCBs are chained using the DCBs nextptr field. 169 */ 170 struct sparx5_tx { 171 struct fdma fdma; 172 u64 packets; 173 u64 dropped; 174 }; 175 176 struct sparx5_port_config { 177 phy_interface_t portmode; 178 u32 bandwidth; 179 int speed; 180 int duplex; 181 enum phy_media media; 182 bool inband; 183 bool power_down; 184 bool autoneg; 185 bool serdes_reset; 186 u32 pause; 187 u32 pause_adv; 188 phy_interface_t phy_mode; 189 u32 sd_sgpio; 190 }; 191 192 struct sparx5_port { 193 struct net_device *ndev; 194 struct sparx5 *sparx5; 195 struct device_node *of_node; 196 struct phy *serdes; 197 struct sparx5_port_config conf; 198 struct phylink_config phylink_config; 199 struct phylink *phylink; 200 struct phylink_pcs phylink_pcs; 201 struct flow_stats mirror_stats; 202 u16 portno; 203 /* Ingress default VLAN (pvid) */ 204 u16 pvid; 205 /* Egress default VLAN (vid) */ 206 u16 vid; 207 bool signd_internal; 208 bool signd_active_high; 209 bool signd_enable; 210 bool flow_control; 211 enum sparx5_port_max_tags max_vlan_tags; 212 enum sparx5_vlan_port_type vlan_type; 213 u32 custom_etype; 214 bool vlan_aware; 215 struct hrtimer inj_timer; 216 /* ptp */ 217 u8 ptp_cmd; 218 u16 ts_id; 219 struct sk_buff_head tx_skbs; 220 bool is_mrouter; 221 struct list_head tc_templates; /* list of TC templates on this port */ 222 }; 223 224 enum sparx5_core_clockfreq { 225 SPX5_CORE_CLOCK_DEFAULT, /* Defaults to the highest supported frequency */ 226 SPX5_CORE_CLOCK_250MHZ, /* 250MHZ core clock frequency */ 227 SPX5_CORE_CLOCK_328MHZ, /* 328MHZ core clock frequency */ 228 SPX5_CORE_CLOCK_500MHZ, /* 500MHZ core clock frequency */ 229 SPX5_CORE_CLOCK_625MHZ, /* 625MHZ core clock frequency */ 230 }; 231 232 struct sparx5_phc { 233 struct ptp_clock *clock; 234 struct ptp_clock_info info; 235 struct kernel_hwtstamp_config hwtstamp_config; 236 struct sparx5 *sparx5; 237 u8 index; 238 }; 239 240 struct sparx5_skb_cb { 241 u8 rew_op; 242 u8 pdu_type; 243 u8 pdu_w16_offset; 244 u16 ts_id; 245 unsigned long jiffies; 246 }; 247 248 struct sparx5_mdb_entry { 249 struct list_head list; 250 DECLARE_BITMAP(port_mask, SPX5_PORTS); 251 unsigned char addr[ETH_ALEN]; 252 bool cpu_copy; 253 u16 vid; 254 u16 pgid_idx; 255 }; 256 257 struct sparx5_mall_mirror_entry { 258 u32 idx; 259 struct sparx5_port *port; 260 }; 261 262 struct sparx5_mall_entry { 263 struct list_head list; 264 struct sparx5_port *port; 265 unsigned long cookie; 266 enum flow_action_id type; 267 bool ingress; 268 union { 269 struct sparx5_mall_mirror_entry mirror; 270 }; 271 }; 272 273 #define SPARX5_PTP_TIMEOUT msecs_to_jiffies(10) 274 #define SPARX5_SKB_CB(skb) \ 275 ((struct sparx5_skb_cb *)((skb)->cb)) 276 277 struct sparx5_regs { 278 const unsigned int *tsize; 279 const unsigned int *gaddr; 280 const unsigned int *gcnt; 281 const unsigned int *gsize; 282 const unsigned int *raddr; 283 const unsigned int *rcnt; 284 const unsigned int *fpos; 285 const unsigned int *fsize; 286 }; 287 288 struct sparx5_consts { 289 u32 n_ports; /* Number of front ports */ 290 u32 n_ports_all; /* Number of front ports + internal ports */ 291 u32 n_hsch_l1_elems; /* Number of HSCH layer 1 elements */ 292 u32 n_hsch_queues; /* Number of HSCH queues */ 293 u32 n_lb_groups; /* Number of leacky bucket groupd */ 294 u32 n_pgids; /* Number of PGID's */ 295 u32 n_sio_clks; /* Number of serial IO clocks */ 296 u32 n_own_upsids; /* Number of own UPSID's */ 297 u32 n_auto_cals; /* Number of auto calendars */ 298 u32 n_filters; /* Number of PSFP filters */ 299 u32 n_gates; /* Number of PSFP gates */ 300 u32 n_sdlbs; /* Number of service dual leaky buckets */ 301 u32 n_dsm_cal_taxis; /* Number of DSM calendar taxis */ 302 u32 buf_size; /* Amount of QLIM watermark memory */ 303 u32 qres_max_prio_idx; /* Maximum QRES prio index */ 304 u32 qres_max_colour_idx; /* Maximum QRES colour index */ 305 u32 tod_pin; /* PTP TOD pin */ 306 const struct sparx5_vcap_inst *vcaps_cfg; 307 const struct vcap_info *vcaps; 308 const struct vcap_statistics *vcap_stats; 309 }; 310 311 struct sparx5_ops { 312 bool (*is_port_2g5)(int portno); 313 bool (*is_port_5g)(int portno); 314 bool (*is_port_10g)(int portno); 315 bool (*is_port_25g)(int portno); 316 bool (*is_port_rgmii)(int portno); 317 u32 (*get_port_dev_index)(struct sparx5 *sparx5, int port); 318 u32 (*get_port_dev_bit)(struct sparx5 *sparx5, int port); 319 u32 (*get_hsch_max_group_rate)(int grp); 320 struct sparx5_sdlb_group *(*get_sdlb_group)(int idx); 321 int (*set_port_mux)(struct sparx5 *sparx5, struct sparx5_port *port, 322 struct sparx5_port_config *conf); 323 324 irqreturn_t (*ptp_irq_handler)(int irq, void *args); 325 int (*dsm_calendar_calc)(struct sparx5 *sparx5, u32 taxi, 326 struct sparx5_calendar_data *data); 327 int (*port_config_rgmii)(struct sparx5_port *port, 328 struct sparx5_port_config *conf); 329 }; 330 331 struct sparx5_main_io_resource { 332 enum sparx5_target id; 333 phys_addr_t offset; 334 int range; 335 }; 336 337 struct sparx5_match_data { 338 const struct sparx5_regs *regs; 339 const struct sparx5_consts *consts; 340 const struct sparx5_ops *ops; 341 const struct sparx5_main_io_resource *iomap; 342 int ioranges; 343 int iomap_size; 344 }; 345 346 struct sparx5 { 347 struct platform_device *pdev; 348 struct device *dev; 349 u32 chip_id; 350 enum spx5_target_chiptype target_ct; 351 u32 features; 352 void __iomem *regs[NUM_TARGETS]; 353 int port_count; 354 struct mutex lock; /* MAC reg lock */ 355 /* port structures are in net device */ 356 struct sparx5_port *ports[SPX5_PORTS]; 357 enum sparx5_core_clockfreq coreclock; 358 /* Statistics */ 359 u32 num_stats; 360 u32 num_ethtool_stats; 361 const char * const *stats_layout; 362 u64 *stats; 363 /* Workqueue for reading stats */ 364 struct mutex queue_stats_lock; 365 struct delayed_work stats_work; 366 struct workqueue_struct *stats_queue; 367 /* Notifiers */ 368 struct notifier_block netdevice_nb; 369 struct notifier_block switchdev_nb; 370 struct notifier_block switchdev_blocking_nb; 371 /* Switch state */ 372 u8 base_mac[ETH_ALEN]; 373 /* Associated bridge device (when bridged) */ 374 struct net_device *hw_bridge_dev; 375 /* Bridged interfaces */ 376 DECLARE_BITMAP(bridge_mask, SPX5_PORTS); 377 DECLARE_BITMAP(bridge_fwd_mask, SPX5_PORTS); 378 DECLARE_BITMAP(bridge_lrn_mask, SPX5_PORTS); 379 DECLARE_BITMAP(vlan_mask[VLAN_N_VID], SPX5_PORTS); 380 /* SW MAC table */ 381 struct list_head mact_entries; 382 /* mac table list (mact_entries) mutex */ 383 struct mutex mact_lock; 384 /* SW MDB table */ 385 struct list_head mdb_entries; 386 /* mdb list mutex */ 387 struct mutex mdb_lock; 388 struct delayed_work mact_work; 389 struct workqueue_struct *mact_queue; 390 /* Board specifics */ 391 bool sd_sgpio_remapping; 392 /* Register based inj/xtr */ 393 int xtr_irq; 394 /* Frame DMA */ 395 int fdma_irq; 396 spinlock_t tx_lock; /* lock for frame transmission */ 397 struct sparx5_rx rx; 398 struct sparx5_tx tx; 399 /* PTP */ 400 bool ptp; 401 struct sparx5_phc phc[SPARX5_PHC_COUNT]; 402 spinlock_t ptp_clock_lock; /* lock for phc */ 403 spinlock_t ptp_ts_id_lock; /* lock for ts_id */ 404 struct mutex ptp_lock; /* lock for ptp interface state */ 405 u16 ptp_skbs; 406 int ptp_irq; 407 /* VCAP */ 408 struct vcap_control *vcap_ctrl; 409 /* PGID allocation map */ 410 u8 pgid_map[PGID_TABLE_SIZE]; 411 struct list_head mall_entries; 412 /* Common root for debugfs */ 413 struct dentry *debugfs_root; 414 const struct sparx5_match_data *data; 415 }; 416 417 /* sparx5_main.c */ 418 bool is_sparx5(struct sparx5 *sparx5); 419 bool sparx5_has_feature(struct sparx5 *sparx5, enum sparx5_feature feature); 420 421 /* sparx5_switchdev.c */ 422 int sparx5_register_notifier_blocks(struct sparx5 *sparx5); 423 void sparx5_unregister_notifier_blocks(struct sparx5 *sparx5); 424 425 /* sparx5_packet.c */ 426 struct frame_info { 427 int src_port; 428 u32 timestamp; 429 }; 430 431 void sparx5_xtr_flush(struct sparx5 *sparx5, u8 grp); 432 void sparx5_ifh_parse(struct sparx5 *sparx5, u32 *ifh, struct frame_info *info); 433 irqreturn_t sparx5_xtr_handler(int irq, void *_priv); 434 netdev_tx_t sparx5_port_xmit_impl(struct sk_buff *skb, struct net_device *dev); 435 int sparx5_manual_injection_mode(struct sparx5 *sparx5); 436 void sparx5_port_inj_timer_setup(struct sparx5_port *port); 437 438 /* sparx5_fdma.c */ 439 int sparx5_fdma_start(struct sparx5 *sparx5); 440 int sparx5_fdma_stop(struct sparx5 *sparx5); 441 int sparx5_fdma_xmit(struct sparx5 *sparx5, u32 *ifh, struct sk_buff *skb); 442 irqreturn_t sparx5_fdma_handler(int irq, void *args); 443 444 /* sparx5_mactable.c */ 445 void sparx5_mact_pull_work(struct work_struct *work); 446 int sparx5_mact_learn(struct sparx5 *sparx5, int port, 447 const unsigned char mac[ETH_ALEN], u16 vid); 448 bool sparx5_mact_getnext(struct sparx5 *sparx5, 449 unsigned char mac[ETH_ALEN], u16 *vid, u32 *pcfg2); 450 int sparx5_mact_find(struct sparx5 *sparx5, 451 const unsigned char mac[ETH_ALEN], u16 vid, u32 *pcfg2); 452 int sparx5_mact_forget(struct sparx5 *sparx5, 453 const unsigned char mac[ETH_ALEN], u16 vid); 454 int sparx5_add_mact_entry(struct sparx5 *sparx5, 455 struct net_device *dev, 456 u16 portno, 457 const unsigned char *addr, u16 vid); 458 int sparx5_del_mact_entry(struct sparx5 *sparx5, 459 const unsigned char *addr, 460 u16 vid); 461 int sparx5_mc_sync(struct net_device *dev, const unsigned char *addr); 462 int sparx5_mc_unsync(struct net_device *dev, const unsigned char *addr); 463 void sparx5_set_ageing(struct sparx5 *sparx5, int msecs); 464 void sparx5_mact_init(struct sparx5 *sparx5); 465 466 /* sparx5_vlan.c */ 467 void sparx5_pgid_update_mask(struct sparx5_port *port, int pgid, bool enable); 468 void sparx5_pgid_clear(struct sparx5 *spx5, int pgid); 469 void sparx5_pgid_read_mask(struct sparx5 *sparx5, int pgid, u32 portmask[3]); 470 void sparx5_update_fwd(struct sparx5 *sparx5); 471 void sparx5_vlan_init(struct sparx5 *sparx5); 472 void sparx5_vlan_port_setup(struct sparx5 *sparx5, int portno); 473 int sparx5_vlan_vid_add(struct sparx5_port *port, u16 vid, bool pvid, 474 bool untagged); 475 int sparx5_vlan_vid_del(struct sparx5_port *port, u16 vid); 476 void sparx5_vlan_port_apply(struct sparx5 *sparx5, struct sparx5_port *port); 477 478 /* sparx5_calendar.c */ 479 int sparx5_config_auto_calendar(struct sparx5 *sparx5); 480 int sparx5_config_dsm_calendar(struct sparx5 *sparx5); 481 int sparx5_dsm_calendar_calc(struct sparx5 *sparx5, u32 taxi, 482 struct sparx5_calendar_data *data); 483 u32 sparx5_cal_speed_to_value(enum sparx5_cal_bw speed); 484 enum sparx5_cal_bw sparx5_get_port_cal_speed(struct sparx5 *sparx5, u32 portno); 485 486 487 /* sparx5_ethtool.c */ 488 void sparx5_get_stats64(struct net_device *ndev, struct rtnl_link_stats64 *stats); 489 int sparx_stats_init(struct sparx5 *sparx5); 490 491 /* sparx5_dcb.c */ 492 #ifdef CONFIG_SPARX5_DCB 493 int sparx5_dcb_init(struct sparx5 *sparx5); 494 #else 495 static inline int sparx5_dcb_init(struct sparx5 *sparx5) 496 { 497 return 0; 498 } 499 #endif 500 501 /* sparx5_netdev.c */ 502 void sparx5_set_port_ifh_timestamp(struct sparx5 *sparx5, void *ifh_hdr, 503 u64 timestamp); 504 void sparx5_set_port_ifh_rew_op(void *ifh_hdr, u32 rew_op); 505 void sparx5_set_port_ifh_pdu_type(struct sparx5 *sparx5, void *ifh_hdr, 506 u32 pdu_type); 507 void sparx5_set_port_ifh_pdu_w16_offset(struct sparx5 *sparx5, void *ifh_hdr, 508 u32 pdu_w16_offset); 509 void sparx5_set_port_ifh(struct sparx5 *sparx5, void *ifh_hdr, u16 portno); 510 bool sparx5_netdevice_check(const struct net_device *dev); 511 struct net_device *sparx5_create_netdev(struct sparx5 *sparx5, u32 portno); 512 int sparx5_register_netdevs(struct sparx5 *sparx5); 513 void sparx5_destroy_netdevs(struct sparx5 *sparx5); 514 void sparx5_unregister_netdevs(struct sparx5 *sparx5); 515 516 /* sparx5_ptp.c */ 517 int sparx5_ptp_init(struct sparx5 *sparx5); 518 void sparx5_ptp_deinit(struct sparx5 *sparx5); 519 int sparx5_ptp_hwtstamp_set(struct sparx5_port *port, 520 struct kernel_hwtstamp_config *cfg, 521 struct netlink_ext_ack *extack); 522 void sparx5_ptp_hwtstamp_get(struct sparx5_port *port, 523 struct kernel_hwtstamp_config *cfg); 524 void sparx5_ptp_rxtstamp(struct sparx5 *sparx5, struct sk_buff *skb, 525 u64 timestamp); 526 int sparx5_ptp_txtstamp_request(struct sparx5_port *port, 527 struct sk_buff *skb); 528 void sparx5_ptp_txtstamp_release(struct sparx5_port *port, 529 struct sk_buff *skb); 530 irqreturn_t sparx5_ptp_irq_handler(int irq, void *args); 531 int sparx5_ptp_gettime64(struct ptp_clock_info *ptp, struct timespec64 *ts); 532 void sparx5_get_hwtimestamp(struct sparx5 *sparx5, 533 struct timespec64 *ts, 534 u32 nsec); 535 536 /* sparx5_vcap_impl.c */ 537 int sparx5_vcap_init(struct sparx5 *sparx5); 538 void sparx5_vcap_destroy(struct sparx5 *sparx5); 539 540 /* sparx5_pgid.c */ 541 enum sparx5_pgid_type { 542 SPX5_PGID_FREE, 543 SPX5_PGID_RESERVED, 544 SPX5_PGID_MULTICAST, 545 }; 546 547 void sparx5_pgid_init(struct sparx5 *spx5); 548 int sparx5_pgid_alloc_mcast(struct sparx5 *spx5, u16 *idx); 549 int sparx5_pgid_free(struct sparx5 *spx5, u16 idx); 550 int sparx5_get_pgid(struct sparx5 *sparx5, int pgid); 551 552 /* sparx5_pool.c */ 553 struct sparx5_pool_entry { 554 u16 ref_cnt; 555 u32 idx; /* tc index */ 556 }; 557 558 u32 sparx5_pool_idx_to_id(u32 idx); 559 int sparx5_pool_put(struct sparx5_pool_entry *pool, int size, u32 id); 560 int sparx5_pool_get(struct sparx5_pool_entry *pool, int size, u32 *id); 561 int sparx5_pool_get_with_idx(struct sparx5_pool_entry *pool, int size, u32 idx, 562 u32 *id); 563 564 /* sparx5_port.c */ 565 int sparx5_port_mux_set(struct sparx5 *sparx5, struct sparx5_port *port, 566 struct sparx5_port_config *conf); 567 int sparx5_get_internal_port(struct sparx5 *sparx5, int port); 568 569 /* sparx5_sdlb.c */ 570 #define SPX5_SDLB_PUP_TOKEN_DISABLE 0x1FFF 571 #define SPX5_SDLB_PUP_TOKEN_MAX (SPX5_SDLB_PUP_TOKEN_DISABLE - 1) 572 #define SPX5_SDLB_GROUP_RATE_MAX 25000000000ULL 573 #define SPX5_SDLB_2CYCLES_TYPE2_THRES_OFFSET 13 574 #define SPX5_SDLB_CNT 4096 575 #define SPX5_SDLB_GROUP_CNT 10 576 #define SPX5_CLK_PER_100PS_DEFAULT 16 577 578 struct sparx5_sdlb_group { 579 u64 max_rate; 580 u32 min_burst; 581 u32 frame_size; 582 u32 pup_interval; 583 u32 nsets; 584 }; 585 586 extern struct sparx5_sdlb_group sdlb_groups[SPX5_SDLB_GROUP_CNT]; 587 struct sparx5_sdlb_group *sparx5_get_sdlb_group(int idx); 588 int sparx5_sdlb_pup_token_get(struct sparx5 *sparx5, u32 pup_interval, 589 u64 rate); 590 591 u64 sparx5_sdlb_clk_hz_get(struct sparx5 *sparx5); 592 int sparx5_sdlb_group_get_by_rate(struct sparx5 *sparx5, u32 rate, u32 burst); 593 int sparx5_sdlb_group_get_by_index(struct sparx5 *sparx5, u32 idx, u32 *group); 594 595 int sparx5_sdlb_group_add(struct sparx5 *sparx5, u32 group, u32 idx); 596 int sparx5_sdlb_group_del(struct sparx5 *sparx5, u32 group, u32 idx); 597 598 void sparx5_sdlb_group_init(struct sparx5 *sparx5, u64 max_rate, u32 min_burst, 599 u32 frame_size, u32 idx); 600 601 /* sparx5_police.c */ 602 enum { 603 /* More policer types will be added later */ 604 SPX5_POL_SERVICE 605 }; 606 607 struct sparx5_policer { 608 u32 type; 609 u32 idx; 610 u64 rate; 611 u32 burst; 612 u32 group; 613 u8 event_mask; 614 }; 615 616 int sparx5_policer_conf_set(struct sparx5 *sparx5, struct sparx5_policer *pol); 617 618 /* sparx5_psfp.c */ 619 #define SPX5_PSFP_GCE_CNT 4 620 #define SPX5_PSFP_SG_CNT 1024 621 #define SPX5_PSFP_SG_MIN_CYCLE_TIME_NS (1 * NSEC_PER_USEC) 622 #define SPX5_PSFP_SG_MAX_CYCLE_TIME_NS ((1 * NSEC_PER_SEC) - 1) 623 #define SPX5_PSFP_SG_MAX_IPV (SPX5_PRIOS - 1) 624 #define SPX5_PSFP_SG_OPEN (SPX5_PSFP_SG_CNT - 1) 625 #define SPX5_PSFP_SG_CYCLE_TIME_DEFAULT 1000000 626 #define SPX5_PSFP_SF_MAX_SDU 16383 627 628 struct sparx5_psfp_fm { 629 struct sparx5_policer pol; 630 }; 631 632 struct sparx5_psfp_gce { 633 bool gate_state; /* StreamGateState */ 634 u32 interval; /* TimeInterval */ 635 u32 ipv; /* InternalPriorityValue */ 636 u32 maxoctets; /* IntervalOctetMax */ 637 }; 638 639 struct sparx5_psfp_sg { 640 bool gate_state; /* PSFPAdminGateStates */ 641 bool gate_enabled; /* PSFPGateEnabled */ 642 u32 ipv; /* PSFPAdminIPV */ 643 struct timespec64 basetime; /* PSFPAdminBaseTime */ 644 u32 cycletime; /* PSFPAdminCycleTime */ 645 u32 cycletimeext; /* PSFPAdminCycleTimeExtension */ 646 u32 num_entries; /* PSFPAdminControlListLength */ 647 struct sparx5_psfp_gce gce[SPX5_PSFP_GCE_CNT]; 648 }; 649 650 struct sparx5_psfp_sf { 651 bool sblock_osize_ena; 652 bool sblock_osize; 653 u32 max_sdu; 654 u32 sgid; /* Gate id */ 655 u32 fmid; /* Flow meter id */ 656 }; 657 658 int sparx5_psfp_fm_add(struct sparx5 *sparx5, u32 uidx, 659 struct sparx5_psfp_fm *fm, u32 *id); 660 int sparx5_psfp_fm_del(struct sparx5 *sparx5, u32 id); 661 662 int sparx5_psfp_sg_add(struct sparx5 *sparx5, u32 uidx, 663 struct sparx5_psfp_sg *sg, u32 *id); 664 int sparx5_psfp_sg_del(struct sparx5 *sparx5, u32 id); 665 666 int sparx5_psfp_sf_add(struct sparx5 *sparx5, const struct sparx5_psfp_sf *sf, 667 u32 *id); 668 int sparx5_psfp_sf_del(struct sparx5 *sparx5, u32 id); 669 670 u32 sparx5_psfp_isdx_get_sf(struct sparx5 *sparx5, u32 isdx); 671 u32 sparx5_psfp_isdx_get_fm(struct sparx5 *sparx5, u32 isdx); 672 u32 sparx5_psfp_sf_get_sg(struct sparx5 *sparx5, u32 sfid); 673 void sparx5_isdx_conf_set(struct sparx5 *sparx5, u32 isdx, u32 sfid, u32 fmid); 674 675 void sparx5_psfp_init(struct sparx5 *sparx5); 676 677 /* sparx5_qos.c */ 678 void sparx5_new_base_time(struct sparx5 *sparx5, const u32 cycle_time, 679 const ktime_t org_base_time, ktime_t *new_base_time); 680 681 /* sparx5_mirror.c */ 682 int sparx5_mirror_add(struct sparx5_mall_entry *entry); 683 void sparx5_mirror_del(struct sparx5_mall_entry *entry); 684 void sparx5_mirror_stats(struct sparx5_mall_entry *entry, 685 struct flow_stats *fstats); 686 687 /* Clock period in picoseconds */ 688 static inline u32 sparx5_clk_period(enum sparx5_core_clockfreq cclock) 689 { 690 switch (cclock) { 691 case SPX5_CORE_CLOCK_250MHZ: 692 return 4000; 693 case SPX5_CORE_CLOCK_328MHZ: 694 return 3048; 695 case SPX5_CORE_CLOCK_500MHZ: 696 return 2000; 697 case SPX5_CORE_CLOCK_625MHZ: 698 default: 699 return 1600; 700 } 701 } 702 703 static inline bool sparx5_is_baser(phy_interface_t interface) 704 { 705 return interface == PHY_INTERFACE_MODE_5GBASER || 706 interface == PHY_INTERFACE_MODE_10GBASER || 707 interface == PHY_INTERFACE_MODE_25GBASER; 708 } 709 710 extern const struct phylink_mac_ops sparx5_phylink_mac_ops; 711 extern const struct phylink_pcs_ops sparx5_phylink_pcs_ops; 712 extern const struct ethtool_ops sparx5_ethtool_ops; 713 extern const struct dcbnl_rtnl_ops sparx5_dcbnl_ops; 714 715 /* Calculate raw offset */ 716 static inline __pure int spx5_offset(int id, int tinst, int tcnt, 717 int gbase, int ginst, 718 int gcnt, int gwidth, 719 int raddr, int rinst, 720 int rcnt, int rwidth) 721 { 722 WARN_ON((tinst) >= tcnt); 723 WARN_ON((ginst) >= gcnt); 724 WARN_ON((rinst) >= rcnt); 725 return gbase + ((ginst) * gwidth) + 726 raddr + ((rinst) * rwidth); 727 } 728 729 /* Read, Write and modify registers content. 730 * The register definition macros start at the id 731 */ 732 static inline void __iomem *spx5_addr(void __iomem *base[], 733 int id, int tinst, int tcnt, 734 int gbase, int ginst, 735 int gcnt, int gwidth, 736 int raddr, int rinst, 737 int rcnt, int rwidth) 738 { 739 WARN_ON((tinst) >= tcnt); 740 WARN_ON((ginst) >= gcnt); 741 WARN_ON((rinst) >= rcnt); 742 return base[id + (tinst)] + 743 gbase + ((ginst) * gwidth) + 744 raddr + ((rinst) * rwidth); 745 } 746 747 static inline void __iomem *spx5_inst_addr(void __iomem *base, 748 int gbase, int ginst, 749 int gcnt, int gwidth, 750 int raddr, int rinst, 751 int rcnt, int rwidth) 752 { 753 WARN_ON((ginst) >= gcnt); 754 WARN_ON((rinst) >= rcnt); 755 return base + 756 gbase + ((ginst) * gwidth) + 757 raddr + ((rinst) * rwidth); 758 } 759 760 static inline u32 spx5_rd(struct sparx5 *sparx5, 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(spx5_addr(sparx5->regs, id, tinst, tcnt, gbase, ginst, 765 gcnt, gwidth, raddr, rinst, rcnt, rwidth)); 766 } 767 768 static inline u32 spx5_inst_rd(void __iomem *iomem, int id, int tinst, int tcnt, 769 int gbase, int ginst, int gcnt, int gwidth, 770 int raddr, int rinst, int rcnt, int rwidth) 771 { 772 return readl(spx5_inst_addr(iomem, gbase, ginst, 773 gcnt, gwidth, raddr, rinst, rcnt, rwidth)); 774 } 775 776 static inline void spx5_wr(u32 val, struct sparx5 *sparx5, 777 int id, int tinst, int tcnt, 778 int gbase, int ginst, int gcnt, int gwidth, 779 int raddr, int rinst, int rcnt, int rwidth) 780 { 781 writel(val, spx5_addr(sparx5->regs, id, tinst, tcnt, 782 gbase, ginst, gcnt, gwidth, 783 raddr, rinst, rcnt, rwidth)); 784 } 785 786 static inline void spx5_inst_wr(u32 val, void __iomem *iomem, 787 int id, int tinst, int tcnt, 788 int gbase, int ginst, int gcnt, int gwidth, 789 int raddr, int rinst, int rcnt, int rwidth) 790 { 791 writel(val, spx5_inst_addr(iomem, 792 gbase, ginst, gcnt, gwidth, 793 raddr, rinst, rcnt, rwidth)); 794 } 795 796 static inline void spx5_rmw(u32 val, u32 mask, struct sparx5 *sparx5, 797 int id, int tinst, int tcnt, 798 int gbase, int ginst, int gcnt, int gwidth, 799 int raddr, int rinst, int rcnt, int rwidth) 800 { 801 u32 nval; 802 803 nval = readl(spx5_addr(sparx5->regs, id, tinst, tcnt, gbase, ginst, 804 gcnt, gwidth, raddr, rinst, rcnt, rwidth)); 805 nval = (nval & ~mask) | (val & mask); 806 writel(nval, spx5_addr(sparx5->regs, id, tinst, tcnt, gbase, ginst, 807 gcnt, gwidth, raddr, rinst, rcnt, rwidth)); 808 } 809 810 static inline void spx5_inst_rmw(u32 val, u32 mask, void __iomem *iomem, 811 int id, int tinst, int tcnt, 812 int gbase, int ginst, int gcnt, int gwidth, 813 int raddr, int rinst, int rcnt, int rwidth) 814 { 815 u32 nval; 816 817 nval = readl(spx5_inst_addr(iomem, gbase, ginst, gcnt, gwidth, raddr, 818 rinst, rcnt, rwidth)); 819 nval = (nval & ~mask) | (val & mask); 820 writel(nval, spx5_inst_addr(iomem, gbase, ginst, gcnt, gwidth, raddr, 821 rinst, rcnt, rwidth)); 822 } 823 824 static inline void __iomem *spx5_inst_get(struct sparx5 *sparx5, int id, int tinst) 825 { 826 return sparx5->regs[id + tinst]; 827 } 828 829 static inline void __iomem *spx5_reg_get(struct sparx5 *sparx5, 830 int id, int tinst, int tcnt, 831 int gbase, int ginst, int gcnt, int gwidth, 832 int raddr, int rinst, int rcnt, int rwidth) 833 { 834 return spx5_addr(sparx5->regs, id, tinst, tcnt, 835 gbase, ginst, gcnt, gwidth, 836 raddr, rinst, rcnt, rwidth); 837 } 838 839 #endif /* __SPARX5_MAIN_H__ */ 840