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