• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
21 #include "sparx5_main_regs.h"
22 
23 /* Target chip type */
24 enum spx5_target_chiptype {
25 	SPX5_TARGET_CT_7546    = 0x7546,  /* SparX-5-64  Enterprise */
26 	SPX5_TARGET_CT_7549    = 0x7549,  /* SparX-5-90  Enterprise */
27 	SPX5_TARGET_CT_7552    = 0x7552,  /* SparX-5-128 Enterprise */
28 	SPX5_TARGET_CT_7556    = 0x7556,  /* SparX-5-160 Enterprise */
29 	SPX5_TARGET_CT_7558    = 0x7558,  /* SparX-5-200 Enterprise */
30 	SPX5_TARGET_CT_7546TSN = 0x47546, /* SparX-5-64i Industrial */
31 	SPX5_TARGET_CT_7549TSN = 0x47549, /* SparX-5-90i Industrial */
32 	SPX5_TARGET_CT_7552TSN = 0x47552, /* SparX-5-128i Industrial */
33 	SPX5_TARGET_CT_7556TSN = 0x47556, /* SparX-5-160i Industrial */
34 	SPX5_TARGET_CT_7558TSN = 0x47558, /* SparX-5-200i Industrial */
35 };
36 
37 enum sparx5_port_max_tags {
38 	SPX5_PORT_MAX_TAGS_NONE,  /* No extra tags allowed */
39 	SPX5_PORT_MAX_TAGS_ONE,   /* Single tag allowed */
40 	SPX5_PORT_MAX_TAGS_TWO    /* Single and double tag allowed */
41 };
42 
43 enum sparx5_vlan_port_type {
44 	SPX5_VLAN_PORT_TYPE_UNAWARE, /* VLAN unaware port */
45 	SPX5_VLAN_PORT_TYPE_C,       /* C-port */
46 	SPX5_VLAN_PORT_TYPE_S,       /* S-port */
47 	SPX5_VLAN_PORT_TYPE_S_CUSTOM /* S-port using custom type */
48 };
49 
50 #define SPX5_PORTS             65
51 #define SPX5_PORT_CPU          (SPX5_PORTS)  /* Next port is CPU port */
52 #define SPX5_PORT_CPU_0        (SPX5_PORT_CPU + 0) /* CPU Port 65 */
53 #define SPX5_PORT_CPU_1        (SPX5_PORT_CPU + 1) /* CPU Port 66 */
54 #define SPX5_PORT_VD0          (SPX5_PORT_CPU + 2) /* VD0/Port 67 used for IPMC */
55 #define SPX5_PORT_VD1          (SPX5_PORT_CPU + 3) /* VD1/Port 68 used for AFI/OAM */
56 #define SPX5_PORT_VD2          (SPX5_PORT_CPU + 4) /* VD2/Port 69 used for IPinIP*/
57 #define SPX5_PORTS_ALL         (SPX5_PORT_CPU + 5) /* Total number of ports */
58 
59 #define PGID_BASE              SPX5_PORTS /* Starts after port PGIDs */
60 #define PGID_UC_FLOOD          (PGID_BASE + 0)
61 #define PGID_MC_FLOOD          (PGID_BASE + 1)
62 #define PGID_IPV4_MC_DATA      (PGID_BASE + 2)
63 #define PGID_IPV4_MC_CTRL      (PGID_BASE + 3)
64 #define PGID_IPV6_MC_DATA      (PGID_BASE + 4)
65 #define PGID_IPV6_MC_CTRL      (PGID_BASE + 5)
66 #define PGID_BCAST	       (PGID_BASE + 6)
67 #define PGID_CPU	       (PGID_BASE + 7)
68 #define PGID_MCAST_START       (PGID_BASE + 8)
69 
70 #define PGID_TABLE_SIZE	       3290
71 
72 #define IFH_LEN                9 /* 36 bytes */
73 #define NULL_VID               0
74 #define SPX5_MACT_PULL_DELAY   (2 * HZ)
75 #define SPX5_STATS_CHECK_DELAY (1 * HZ)
76 #define SPX5_PRIOS             8     /* Number of priority queues */
77 #define SPX5_BUFFER_CELL_SZ    184   /* Cell size  */
78 #define SPX5_BUFFER_MEMORY     4194280 /* 22795 words * 184 bytes */
79 
80 #define XTR_QUEUE     0
81 #define INJ_QUEUE     0
82 
83 #define FDMA_DCB_MAX			64
84 #define FDMA_RX_DCB_MAX_DBS		15
85 #define FDMA_TX_DCB_MAX_DBS		1
86 
87 #define SPARX5_PHC_COUNT		3
88 #define SPARX5_PHC_PORT			0
89 
90 #define IFH_REW_OP_NOOP			0x0
91 #define IFH_REW_OP_ONE_STEP_PTP		0x3
92 #define IFH_REW_OP_TWO_STEP_PTP		0x4
93 
94 #define IFH_PDU_TYPE_NONE		0x0
95 #define IFH_PDU_TYPE_PTP		0x5
96 #define IFH_PDU_TYPE_IPV4_UDP_PTP	0x6
97 #define IFH_PDU_TYPE_IPV6_UDP_PTP	0x7
98 
99 struct sparx5;
100 
101 struct sparx5_db_hw {
102 	u64 dataptr;
103 	u64 status;
104 };
105 
106 struct sparx5_rx_dcb_hw {
107 	u64 nextptr;
108 	u64 info;
109 	struct sparx5_db_hw db[FDMA_RX_DCB_MAX_DBS];
110 };
111 
112 struct sparx5_tx_dcb_hw {
113 	u64 nextptr;
114 	u64 info;
115 	struct sparx5_db_hw db[FDMA_TX_DCB_MAX_DBS];
116 };
117 
118 /* Frame DMA receive state:
119  * For each DB, there is a SKB, and the skb data pointer is mapped in
120  * the DB. Once a frame is received the skb is given to the upper layers
121  * and a new skb is added to the dcb.
122  * When the db_index reached FDMA_RX_DCB_MAX_DBS the DB is reused.
123  */
124 struct sparx5_rx {
125 	struct sparx5_rx_dcb_hw *dcb_entries;
126 	struct sparx5_rx_dcb_hw *last_entry;
127 	struct sk_buff *skb[FDMA_DCB_MAX][FDMA_RX_DCB_MAX_DBS];
128 	int db_index;
129 	int dcb_index;
130 	dma_addr_t dma;
131 	struct napi_struct napi;
132 	u32 channel_id;
133 	struct net_device *ndev;
134 	u64 packets;
135 };
136 
137 /* Frame DMA transmit state:
138  * DCBs are chained using the DCBs nextptr field.
139  */
140 struct sparx5_tx {
141 	struct sparx5_tx_dcb_hw *curr_entry;
142 	struct sparx5_tx_dcb_hw *first_entry;
143 	struct list_head db_list;
144 	dma_addr_t dma;
145 	u32 channel_id;
146 	u64 packets;
147 	u64 dropped;
148 };
149 
150 struct sparx5_port_config {
151 	phy_interface_t portmode;
152 	u32 bandwidth;
153 	int speed;
154 	int duplex;
155 	enum phy_media media;
156 	bool inband;
157 	bool power_down;
158 	bool autoneg;
159 	bool serdes_reset;
160 	u32 pause;
161 	u32 pause_adv;
162 	phy_interface_t phy_mode;
163 	u32 sd_sgpio;
164 };
165 
166 struct sparx5_port {
167 	struct net_device *ndev;
168 	struct sparx5 *sparx5;
169 	struct device_node *of_node;
170 	struct phy *serdes;
171 	struct sparx5_port_config conf;
172 	struct phylink_config phylink_config;
173 	struct phylink *phylink;
174 	struct phylink_pcs phylink_pcs;
175 	u16 portno;
176 	/* Ingress default VLAN (pvid) */
177 	u16 pvid;
178 	/* Egress default VLAN (vid) */
179 	u16 vid;
180 	bool signd_internal;
181 	bool signd_active_high;
182 	bool signd_enable;
183 	bool flow_control;
184 	enum sparx5_port_max_tags max_vlan_tags;
185 	enum sparx5_vlan_port_type vlan_type;
186 	u32 custom_etype;
187 	bool vlan_aware;
188 	struct hrtimer inj_timer;
189 	/* ptp */
190 	u8 ptp_cmd;
191 	u16 ts_id;
192 	struct sk_buff_head tx_skbs;
193 	bool is_mrouter;
194 };
195 
196 enum sparx5_core_clockfreq {
197 	SPX5_CORE_CLOCK_DEFAULT,  /* Defaults to the highest supported frequency */
198 	SPX5_CORE_CLOCK_250MHZ,   /* 250MHZ core clock frequency */
199 	SPX5_CORE_CLOCK_500MHZ,   /* 500MHZ core clock frequency */
200 	SPX5_CORE_CLOCK_625MHZ,   /* 625MHZ core clock frequency */
201 };
202 
203 struct sparx5_phc {
204 	struct ptp_clock *clock;
205 	struct ptp_clock_info info;
206 	struct hwtstamp_config hwtstamp_config;
207 	struct sparx5 *sparx5;
208 	u8 index;
209 };
210 
211 struct sparx5_skb_cb {
212 	u8 rew_op;
213 	u8 pdu_type;
214 	u8 pdu_w16_offset;
215 	u16 ts_id;
216 	unsigned long jiffies;
217 };
218 
219 struct sparx5_mdb_entry {
220 	struct list_head list;
221 	DECLARE_BITMAP(port_mask, SPX5_PORTS);
222 	unsigned char addr[ETH_ALEN];
223 	bool cpu_copy;
224 	u16 vid;
225 	u16 pgid_idx;
226 };
227 
228 #define SPARX5_PTP_TIMEOUT		msecs_to_jiffies(10)
229 #define SPARX5_SKB_CB(skb) \
230 	((struct sparx5_skb_cb *)((skb)->cb))
231 
232 struct sparx5 {
233 	struct platform_device *pdev;
234 	struct device *dev;
235 	u32 chip_id;
236 	enum spx5_target_chiptype target_ct;
237 	void __iomem *regs[NUM_TARGETS];
238 	int port_count;
239 	struct mutex lock; /* MAC reg lock */
240 	/* port structures are in net device */
241 	struct sparx5_port *ports[SPX5_PORTS];
242 	enum sparx5_core_clockfreq coreclock;
243 	/* Statistics */
244 	u32 num_stats;
245 	u32 num_ethtool_stats;
246 	const char * const *stats_layout;
247 	u64 *stats;
248 	/* Workqueue for reading stats */
249 	struct mutex queue_stats_lock;
250 	struct delayed_work stats_work;
251 	struct workqueue_struct *stats_queue;
252 	/* Notifiers */
253 	struct notifier_block netdevice_nb;
254 	struct notifier_block switchdev_nb;
255 	struct notifier_block switchdev_blocking_nb;
256 	/* Switch state */
257 	u8 base_mac[ETH_ALEN];
258 	/* Associated bridge device (when bridged) */
259 	struct net_device *hw_bridge_dev;
260 	/* Bridged interfaces */
261 	DECLARE_BITMAP(bridge_mask, SPX5_PORTS);
262 	DECLARE_BITMAP(bridge_fwd_mask, SPX5_PORTS);
263 	DECLARE_BITMAP(bridge_lrn_mask, SPX5_PORTS);
264 	DECLARE_BITMAP(vlan_mask[VLAN_N_VID], SPX5_PORTS);
265 	/* SW MAC table */
266 	struct list_head mact_entries;
267 	/* mac table list (mact_entries) mutex */
268 	struct mutex mact_lock;
269 	/* SW MDB table */
270 	struct list_head mdb_entries;
271 	/* mdb list mutex */
272 	struct mutex mdb_lock;
273 	struct delayed_work mact_work;
274 	struct workqueue_struct *mact_queue;
275 	/* Board specifics */
276 	bool sd_sgpio_remapping;
277 	/* Register based inj/xtr */
278 	int xtr_irq;
279 	/* Frame DMA */
280 	int fdma_irq;
281 	spinlock_t tx_lock; /* lock for frame transmission */
282 	struct sparx5_rx rx;
283 	struct sparx5_tx tx;
284 	/* PTP */
285 	bool ptp;
286 	struct sparx5_phc phc[SPARX5_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 	int ptp_irq;
292 	/* PGID allocation map */
293 	u8 pgid_map[PGID_TABLE_SIZE];
294 };
295 
296 /* sparx5_switchdev.c */
297 int sparx5_register_notifier_blocks(struct sparx5 *sparx5);
298 void sparx5_unregister_notifier_blocks(struct sparx5 *sparx5);
299 
300 /* sparx5_packet.c */
301 struct frame_info {
302 	int src_port;
303 	u32 timestamp;
304 };
305 
306 void sparx5_xtr_flush(struct sparx5 *sparx5, u8 grp);
307 void sparx5_ifh_parse(u32 *ifh, struct frame_info *info);
308 irqreturn_t sparx5_xtr_handler(int irq, void *_priv);
309 netdev_tx_t sparx5_port_xmit_impl(struct sk_buff *skb, struct net_device *dev);
310 int sparx5_manual_injection_mode(struct sparx5 *sparx5);
311 void sparx5_port_inj_timer_setup(struct sparx5_port *port);
312 
313 /* sparx5_fdma.c */
314 int sparx5_fdma_start(struct sparx5 *sparx5);
315 int sparx5_fdma_stop(struct sparx5 *sparx5);
316 int sparx5_fdma_xmit(struct sparx5 *sparx5, u32 *ifh, struct sk_buff *skb);
317 irqreturn_t sparx5_fdma_handler(int irq, void *args);
318 
319 /* sparx5_mactable.c */
320 void sparx5_mact_pull_work(struct work_struct *work);
321 int sparx5_mact_learn(struct sparx5 *sparx5, int port,
322 		      const unsigned char mac[ETH_ALEN], u16 vid);
323 bool sparx5_mact_getnext(struct sparx5 *sparx5,
324 			 unsigned char mac[ETH_ALEN], u16 *vid, u32 *pcfg2);
325 int sparx5_mact_find(struct sparx5 *sparx5,
326 		     const unsigned char mac[ETH_ALEN], u16 vid, u32 *pcfg2);
327 int sparx5_mact_forget(struct sparx5 *sparx5,
328 		       const unsigned char mac[ETH_ALEN], u16 vid);
329 int sparx5_add_mact_entry(struct sparx5 *sparx5,
330 			  struct net_device *dev,
331 			  u16 portno,
332 			  const unsigned char *addr, u16 vid);
333 int sparx5_del_mact_entry(struct sparx5 *sparx5,
334 			  const unsigned char *addr,
335 			  u16 vid);
336 int sparx5_mc_sync(struct net_device *dev, const unsigned char *addr);
337 int sparx5_mc_unsync(struct net_device *dev, const unsigned char *addr);
338 void sparx5_set_ageing(struct sparx5 *sparx5, int msecs);
339 void sparx5_mact_init(struct sparx5 *sparx5);
340 
341 /* sparx5_vlan.c */
342 void sparx5_pgid_update_mask(struct sparx5_port *port, int pgid, bool enable);
343 void sparx5_pgid_clear(struct sparx5 *spx5, int pgid);
344 void sparx5_pgid_read_mask(struct sparx5 *sparx5, int pgid, u32 portmask[3]);
345 void sparx5_update_fwd(struct sparx5 *sparx5);
346 void sparx5_vlan_init(struct sparx5 *sparx5);
347 void sparx5_vlan_port_setup(struct sparx5 *sparx5, int portno);
348 int sparx5_vlan_vid_add(struct sparx5_port *port, u16 vid, bool pvid,
349 			bool untagged);
350 int sparx5_vlan_vid_del(struct sparx5_port *port, u16 vid);
351 void sparx5_vlan_port_apply(struct sparx5 *sparx5, struct sparx5_port *port);
352 
353 /* sparx5_calendar.c */
354 int sparx5_config_auto_calendar(struct sparx5 *sparx5);
355 int sparx5_config_dsm_calendar(struct sparx5 *sparx5);
356 
357 /* sparx5_ethtool.c */
358 void sparx5_get_stats64(struct net_device *ndev, struct rtnl_link_stats64 *stats);
359 int sparx_stats_init(struct sparx5 *sparx5);
360 
361 /* sparx5_netdev.c */
362 void sparx5_set_port_ifh_timestamp(void *ifh_hdr, u64 timestamp);
363 void sparx5_set_port_ifh_rew_op(void *ifh_hdr, u32 rew_op);
364 void sparx5_set_port_ifh_pdu_type(void *ifh_hdr, u32 pdu_type);
365 void sparx5_set_port_ifh_pdu_w16_offset(void *ifh_hdr, u32 pdu_w16_offset);
366 void sparx5_set_port_ifh(void *ifh_hdr, u16 portno);
367 bool sparx5_netdevice_check(const struct net_device *dev);
368 struct net_device *sparx5_create_netdev(struct sparx5 *sparx5, u32 portno);
369 int sparx5_register_netdevs(struct sparx5 *sparx5);
370 void sparx5_destroy_netdevs(struct sparx5 *sparx5);
371 void sparx5_unregister_netdevs(struct sparx5 *sparx5);
372 
373 /* sparx5_ptp.c */
374 int sparx5_ptp_init(struct sparx5 *sparx5);
375 void sparx5_ptp_deinit(struct sparx5 *sparx5);
376 int sparx5_ptp_hwtstamp_set(struct sparx5_port *port, struct ifreq *ifr);
377 int sparx5_ptp_hwtstamp_get(struct sparx5_port *port, struct ifreq *ifr);
378 void sparx5_ptp_rxtstamp(struct sparx5 *sparx5, struct sk_buff *skb,
379 			 u64 timestamp);
380 int sparx5_ptp_txtstamp_request(struct sparx5_port *port,
381 				struct sk_buff *skb);
382 void sparx5_ptp_txtstamp_release(struct sparx5_port *port,
383 				 struct sk_buff *skb);
384 irqreturn_t sparx5_ptp_irq_handler(int irq, void *args);
385 
386 /* sparx5_pgid.c */
387 enum sparx5_pgid_type {
388 	SPX5_PGID_FREE,
389 	SPX5_PGID_RESERVED,
390 	SPX5_PGID_MULTICAST,
391 };
392 
393 void sparx5_pgid_init(struct sparx5 *spx5);
394 int sparx5_pgid_alloc_glag(struct sparx5 *spx5, u16 *idx);
395 int sparx5_pgid_alloc_mcast(struct sparx5 *spx5, u16 *idx);
396 int sparx5_pgid_free(struct sparx5 *spx5, u16 idx);
397 
398 /* Clock period in picoseconds */
sparx5_clk_period(enum sparx5_core_clockfreq cclock)399 static inline u32 sparx5_clk_period(enum sparx5_core_clockfreq cclock)
400 {
401 	switch (cclock) {
402 	case SPX5_CORE_CLOCK_250MHZ:
403 		return 4000;
404 	case SPX5_CORE_CLOCK_500MHZ:
405 		return 2000;
406 	case SPX5_CORE_CLOCK_625MHZ:
407 	default:
408 		return 1600;
409 	}
410 }
411 
sparx5_is_baser(phy_interface_t interface)412 static inline bool sparx5_is_baser(phy_interface_t interface)
413 {
414 	return interface == PHY_INTERFACE_MODE_5GBASER ||
415 		   interface == PHY_INTERFACE_MODE_10GBASER ||
416 		   interface == PHY_INTERFACE_MODE_25GBASER;
417 }
418 
419 extern const struct phylink_mac_ops sparx5_phylink_mac_ops;
420 extern const struct phylink_pcs_ops sparx5_phylink_pcs_ops;
421 extern const struct ethtool_ops sparx5_ethtool_ops;
422 
423 /* Calculate raw offset */
spx5_offset(int id,int tinst,int tcnt,int gbase,int ginst,int gcnt,int gwidth,int raddr,int rinst,int rcnt,int rwidth)424 static inline __pure int spx5_offset(int id, int tinst, int tcnt,
425 				     int gbase, int ginst,
426 				     int gcnt, int gwidth,
427 				     int raddr, int rinst,
428 				     int rcnt, int rwidth)
429 {
430 	WARN_ON((tinst) >= tcnt);
431 	WARN_ON((ginst) >= gcnt);
432 	WARN_ON((rinst) >= rcnt);
433 	return gbase + ((ginst) * gwidth) +
434 		raddr + ((rinst) * rwidth);
435 }
436 
437 /* Read, Write and modify registers content.
438  * The register definition macros start at the id
439  */
spx5_addr(void __iomem * base[],int id,int tinst,int tcnt,int gbase,int ginst,int gcnt,int gwidth,int raddr,int rinst,int rcnt,int rwidth)440 static inline void __iomem *spx5_addr(void __iomem *base[],
441 				      int id, int tinst, int tcnt,
442 				      int gbase, int ginst,
443 				      int gcnt, int gwidth,
444 				      int raddr, int rinst,
445 				      int rcnt, int rwidth)
446 {
447 	WARN_ON((tinst) >= tcnt);
448 	WARN_ON((ginst) >= gcnt);
449 	WARN_ON((rinst) >= rcnt);
450 	return base[id + (tinst)] +
451 		gbase + ((ginst) * gwidth) +
452 		raddr + ((rinst) * rwidth);
453 }
454 
spx5_inst_addr(void __iomem * base,int gbase,int ginst,int gcnt,int gwidth,int raddr,int rinst,int rcnt,int rwidth)455 static inline void __iomem *spx5_inst_addr(void __iomem *base,
456 					   int gbase, int ginst,
457 					   int gcnt, int gwidth,
458 					   int raddr, int rinst,
459 					   int rcnt, int rwidth)
460 {
461 	WARN_ON((ginst) >= gcnt);
462 	WARN_ON((rinst) >= rcnt);
463 	return base +
464 		gbase + ((ginst) * gwidth) +
465 		raddr + ((rinst) * rwidth);
466 }
467 
spx5_rd(struct sparx5 * sparx5,int id,int tinst,int tcnt,int gbase,int ginst,int gcnt,int gwidth,int raddr,int rinst,int rcnt,int rwidth)468 static inline u32 spx5_rd(struct sparx5 *sparx5, int id, int tinst, int tcnt,
469 			  int gbase, int ginst, int gcnt, int gwidth,
470 			  int raddr, int rinst, int rcnt, int rwidth)
471 {
472 	return readl(spx5_addr(sparx5->regs, id, tinst, tcnt, gbase, ginst,
473 			       gcnt, gwidth, raddr, rinst, rcnt, rwidth));
474 }
475 
spx5_inst_rd(void __iomem * iomem,int id,int tinst,int tcnt,int gbase,int ginst,int gcnt,int gwidth,int raddr,int rinst,int rcnt,int rwidth)476 static inline u32 spx5_inst_rd(void __iomem *iomem, int id, int tinst, int tcnt,
477 			       int gbase, int ginst, int gcnt, int gwidth,
478 			       int raddr, int rinst, int rcnt, int rwidth)
479 {
480 	return readl(spx5_inst_addr(iomem, gbase, ginst,
481 				     gcnt, gwidth, raddr, rinst, rcnt, rwidth));
482 }
483 
spx5_wr(u32 val,struct sparx5 * sparx5,int id,int tinst,int tcnt,int gbase,int ginst,int gcnt,int gwidth,int raddr,int rinst,int rcnt,int rwidth)484 static inline void spx5_wr(u32 val, struct sparx5 *sparx5,
485 			   int id, int tinst, int tcnt,
486 			   int gbase, int ginst, int gcnt, int gwidth,
487 			   int raddr, int rinst, int rcnt, int rwidth)
488 {
489 	writel(val, spx5_addr(sparx5->regs, id, tinst, tcnt,
490 			      gbase, ginst, gcnt, gwidth,
491 			      raddr, rinst, rcnt, rwidth));
492 }
493 
spx5_inst_wr(u32 val,void __iomem * iomem,int id,int tinst,int tcnt,int gbase,int ginst,int gcnt,int gwidth,int raddr,int rinst,int rcnt,int rwidth)494 static inline void spx5_inst_wr(u32 val, void __iomem *iomem,
495 				int id, int tinst, int tcnt,
496 				int gbase, int ginst, int gcnt, int gwidth,
497 				int raddr, int rinst, int rcnt, int rwidth)
498 {
499 	writel(val, spx5_inst_addr(iomem,
500 				   gbase, ginst, gcnt, gwidth,
501 				   raddr, rinst, rcnt, rwidth));
502 }
503 
spx5_rmw(u32 val,u32 mask,struct sparx5 * sparx5,int id,int tinst,int tcnt,int gbase,int ginst,int gcnt,int gwidth,int raddr,int rinst,int rcnt,int rwidth)504 static inline void spx5_rmw(u32 val, u32 mask, struct sparx5 *sparx5,
505 			    int id, int tinst, int tcnt,
506 			    int gbase, int ginst, int gcnt, int gwidth,
507 			    int raddr, int rinst, int rcnt, int rwidth)
508 {
509 	u32 nval;
510 
511 	nval = readl(spx5_addr(sparx5->regs, id, tinst, tcnt, gbase, ginst,
512 			       gcnt, gwidth, raddr, rinst, rcnt, rwidth));
513 	nval = (nval & ~mask) | (val & mask);
514 	writel(nval, spx5_addr(sparx5->regs, id, tinst, tcnt, gbase, ginst,
515 			       gcnt, gwidth, raddr, rinst, rcnt, rwidth));
516 }
517 
spx5_inst_rmw(u32 val,u32 mask,void __iomem * iomem,int id,int tinst,int tcnt,int gbase,int ginst,int gcnt,int gwidth,int raddr,int rinst,int rcnt,int rwidth)518 static inline void spx5_inst_rmw(u32 val, u32 mask, void __iomem *iomem,
519 				 int id, int tinst, int tcnt,
520 				 int gbase, int ginst, int gcnt, int gwidth,
521 				 int raddr, int rinst, int rcnt, int rwidth)
522 {
523 	u32 nval;
524 
525 	nval = readl(spx5_inst_addr(iomem, gbase, ginst, gcnt, gwidth, raddr,
526 				    rinst, rcnt, rwidth));
527 	nval = (nval & ~mask) | (val & mask);
528 	writel(nval, spx5_inst_addr(iomem, gbase, ginst, gcnt, gwidth, raddr,
529 				    rinst, rcnt, rwidth));
530 }
531 
spx5_inst_get(struct sparx5 * sparx5,int id,int tinst)532 static inline void __iomem *spx5_inst_get(struct sparx5 *sparx5, int id, int tinst)
533 {
534 	return sparx5->regs[id + tinst];
535 }
536 
spx5_reg_get(struct sparx5 * sparx5,int id,int tinst,int tcnt,int gbase,int ginst,int gcnt,int gwidth,int raddr,int rinst,int rcnt,int rwidth)537 static inline void __iomem *spx5_reg_get(struct sparx5 *sparx5,
538 					 int id, int tinst, int tcnt,
539 					 int gbase, int ginst, int gcnt, int gwidth,
540 					 int raddr, int rinst, int rcnt, int rwidth)
541 {
542 	return spx5_addr(sparx5->regs, id, tinst, tcnt,
543 			 gbase, ginst, gcnt, gwidth,
544 			 raddr, rinst, rcnt, rwidth);
545 }
546 
547 #endif	/* __SPARX5_MAIN_H__ */
548