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