162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/* 10G controller driver for Samsung SoCs
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Copyright (C) 2013 Samsung Electronics Co., Ltd.
562306a36Sopenharmony_ci *		http://www.samsung.com
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * Author: Siva Reddy Kallam <siva.kallam@samsung.com>
862306a36Sopenharmony_ci */
962306a36Sopenharmony_ci#ifndef __SXGBE_DESC_H__
1062306a36Sopenharmony_ci#define __SXGBE_DESC_H__
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci#define SXGBE_DESC_SIZE_BYTES	16
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci/* forward declaration */
1562306a36Sopenharmony_cistruct sxgbe_extra_stats;
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci/* Transmit checksum insertion control */
1862306a36Sopenharmony_cienum tdes_csum_insertion {
1962306a36Sopenharmony_ci	cic_disabled		= 0,	/* Checksum Insertion Control */
2062306a36Sopenharmony_ci	cic_only_ip		= 1,	/* Only IP header */
2162306a36Sopenharmony_ci	/* IP header but pseudoheader is not calculated */
2262306a36Sopenharmony_ci	cic_no_pseudoheader	= 2,
2362306a36Sopenharmony_ci	cic_full		= 3,	/* IP header and pseudoheader */
2462306a36Sopenharmony_ci};
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_cistruct sxgbe_tx_norm_desc {
2762306a36Sopenharmony_ci	u64 tdes01; /* buf1 address */
2862306a36Sopenharmony_ci	union {
2962306a36Sopenharmony_ci		/* TX Read-Format Desc 2,3 */
3062306a36Sopenharmony_ci		struct {
3162306a36Sopenharmony_ci			/* TDES2 */
3262306a36Sopenharmony_ci			u32 buf1_size:14;
3362306a36Sopenharmony_ci			u32 vlan_tag_ctl:2;
3462306a36Sopenharmony_ci			u32 buf2_size:14;
3562306a36Sopenharmony_ci			u32 timestmp_enable:1;
3662306a36Sopenharmony_ci			u32 int_on_com:1;
3762306a36Sopenharmony_ci			/* TDES3 */
3862306a36Sopenharmony_ci			union {
3962306a36Sopenharmony_ci				u16 tcp_payload_len;
4062306a36Sopenharmony_ci				struct {
4162306a36Sopenharmony_ci					u32 total_pkt_len:15;
4262306a36Sopenharmony_ci					u32 reserved1:1;
4362306a36Sopenharmony_ci				} pkt_len;
4462306a36Sopenharmony_ci			} tx_pkt_len;
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_ci			u16 cksum_ctl:2;
4762306a36Sopenharmony_ci			u16 tse_bit:1;
4862306a36Sopenharmony_ci			u16 tcp_hdr_len:4;
4962306a36Sopenharmony_ci			u16 sa_insert_ctl:3;
5062306a36Sopenharmony_ci			u16 crc_pad_ctl:2;
5162306a36Sopenharmony_ci			u16 last_desc:1;
5262306a36Sopenharmony_ci			u16 first_desc:1;
5362306a36Sopenharmony_ci			u16 ctxt_bit:1;
5462306a36Sopenharmony_ci			u16 own_bit:1;
5562306a36Sopenharmony_ci		} tx_rd_des23;
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ci		/* tx write back Desc 2,3 */
5862306a36Sopenharmony_ci		struct {
5962306a36Sopenharmony_ci			/* WB TES2 */
6062306a36Sopenharmony_ci			u32 reserved1;
6162306a36Sopenharmony_ci			/* WB TES3 */
6262306a36Sopenharmony_ci			u32 reserved2:31;
6362306a36Sopenharmony_ci			u32 own_bit:1;
6462306a36Sopenharmony_ci		} tx_wb_des23;
6562306a36Sopenharmony_ci	} tdes23;
6662306a36Sopenharmony_ci};
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_cistruct sxgbe_rx_norm_desc {
6962306a36Sopenharmony_ci	union {
7062306a36Sopenharmony_ci		u64 rdes01; /* buf1 address */
7162306a36Sopenharmony_ci		union {
7262306a36Sopenharmony_ci			u32 out_vlan_tag:16;
7362306a36Sopenharmony_ci			u32 in_vlan_tag:16;
7462306a36Sopenharmony_ci			u32 rss_hash;
7562306a36Sopenharmony_ci		} rx_wb_des01;
7662306a36Sopenharmony_ci	} rdes01;
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_ci	union {
7962306a36Sopenharmony_ci		/* RX Read format Desc 2,3 */
8062306a36Sopenharmony_ci		struct{
8162306a36Sopenharmony_ci			/* RDES2 */
8262306a36Sopenharmony_ci			u64 buf2_addr:62;
8362306a36Sopenharmony_ci			/* RDES3 */
8462306a36Sopenharmony_ci			u32 int_on_com:1;
8562306a36Sopenharmony_ci			u32 own_bit:1;
8662306a36Sopenharmony_ci		} rx_rd_des23;
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ci		/* RX write back */
8962306a36Sopenharmony_ci		struct{
9062306a36Sopenharmony_ci			/* WB RDES2 */
9162306a36Sopenharmony_ci			u32 hdr_len:10;
9262306a36Sopenharmony_ci			u32 rdes2_reserved:2;
9362306a36Sopenharmony_ci			u32 elrd_val:1;
9462306a36Sopenharmony_ci			u32 iovt_sel:1;
9562306a36Sopenharmony_ci			u32 res_pkt:1;
9662306a36Sopenharmony_ci			u32 vlan_filter_match:1;
9762306a36Sopenharmony_ci			u32 sa_filter_fail:1;
9862306a36Sopenharmony_ci			u32 da_filter_fail:1;
9962306a36Sopenharmony_ci			u32 hash_filter_pass:1;
10062306a36Sopenharmony_ci			u32 macaddr_filter_match:8;
10162306a36Sopenharmony_ci			u32 l3_filter_match:1;
10262306a36Sopenharmony_ci			u32 l4_filter_match:1;
10362306a36Sopenharmony_ci			u32 l34_filter_num:3;
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_ci			/* WB RDES3 */
10662306a36Sopenharmony_ci			u32 pkt_len:14;
10762306a36Sopenharmony_ci			u32 rdes3_reserved:1;
10862306a36Sopenharmony_ci			u32 err_summary:1;
10962306a36Sopenharmony_ci			u32 err_l2_type:4;
11062306a36Sopenharmony_ci			u32 layer34_pkt_type:4;
11162306a36Sopenharmony_ci			u32 no_coagulation_pkt:1;
11262306a36Sopenharmony_ci			u32 in_seq_pkt:1;
11362306a36Sopenharmony_ci			u32 rss_valid:1;
11462306a36Sopenharmony_ci			u32 context_des_avail:1;
11562306a36Sopenharmony_ci			u32 last_desc:1;
11662306a36Sopenharmony_ci			u32 first_desc:1;
11762306a36Sopenharmony_ci			u32 recv_context_desc:1;
11862306a36Sopenharmony_ci			u32 own_bit:1;
11962306a36Sopenharmony_ci		} rx_wb_des23;
12062306a36Sopenharmony_ci	} rdes23;
12162306a36Sopenharmony_ci};
12262306a36Sopenharmony_ci
12362306a36Sopenharmony_ci/* Context descriptor structure */
12462306a36Sopenharmony_cistruct sxgbe_tx_ctxt_desc {
12562306a36Sopenharmony_ci	u32 tstamp_lo;
12662306a36Sopenharmony_ci	u32 tstamp_hi;
12762306a36Sopenharmony_ci	u32 maxseg_size:15;
12862306a36Sopenharmony_ci	u32 reserved1:1;
12962306a36Sopenharmony_ci	u32 ivlan_tag:16;
13062306a36Sopenharmony_ci	u32 vlan_tag:16;
13162306a36Sopenharmony_ci	u32 vltag_valid:1;
13262306a36Sopenharmony_ci	u32 ivlan_tag_valid:1;
13362306a36Sopenharmony_ci	u32 ivlan_tag_ctl:2;
13462306a36Sopenharmony_ci	u32 reserved2:3;
13562306a36Sopenharmony_ci	u32 ctxt_desc_err:1;
13662306a36Sopenharmony_ci	u32 reserved3:2;
13762306a36Sopenharmony_ci	u32 ostc:1;
13862306a36Sopenharmony_ci	u32 tcmssv:1;
13962306a36Sopenharmony_ci	u32 reserved4:2;
14062306a36Sopenharmony_ci	u32 ctxt_bit:1;
14162306a36Sopenharmony_ci	u32 own_bit:1;
14262306a36Sopenharmony_ci};
14362306a36Sopenharmony_ci
14462306a36Sopenharmony_cistruct sxgbe_rx_ctxt_desc {
14562306a36Sopenharmony_ci	u32 tstamp_lo;
14662306a36Sopenharmony_ci	u32 tstamp_hi;
14762306a36Sopenharmony_ci	u32 reserved1;
14862306a36Sopenharmony_ci	u32 ptp_msgtype:4;
14962306a36Sopenharmony_ci	u32 tstamp_available:1;
15062306a36Sopenharmony_ci	u32 ptp_rsp_err:1;
15162306a36Sopenharmony_ci	u32 tstamp_dropped:1;
15262306a36Sopenharmony_ci	u32 reserved2:23;
15362306a36Sopenharmony_ci	u32 rx_ctxt_desc:1;
15462306a36Sopenharmony_ci	u32 own_bit:1;
15562306a36Sopenharmony_ci};
15662306a36Sopenharmony_ci
15762306a36Sopenharmony_cistruct sxgbe_desc_ops {
15862306a36Sopenharmony_ci	/* DMA TX descriptor ring initialization */
15962306a36Sopenharmony_ci	void (*init_tx_desc)(struct sxgbe_tx_norm_desc *p);
16062306a36Sopenharmony_ci
16162306a36Sopenharmony_ci	/* Invoked by the xmit function to prepare the tx descriptor */
16262306a36Sopenharmony_ci	void (*tx_desc_enable_tse)(struct sxgbe_tx_norm_desc *p, u8 is_tse,
16362306a36Sopenharmony_ci				   u32 total_hdr_len, u32 tcp_hdr_len,
16462306a36Sopenharmony_ci				   u32 tcp_payload_len);
16562306a36Sopenharmony_ci
16662306a36Sopenharmony_ci	/* Assign buffer lengths for descriptor */
16762306a36Sopenharmony_ci	void (*prepare_tx_desc)(struct sxgbe_tx_norm_desc *p, u8 is_fd,
16862306a36Sopenharmony_ci				int buf1_len, int pkt_len, int cksum);
16962306a36Sopenharmony_ci
17062306a36Sopenharmony_ci	/* Set VLAN control information */
17162306a36Sopenharmony_ci	void (*tx_vlanctl_desc)(struct sxgbe_tx_norm_desc *p, int vlan_ctl);
17262306a36Sopenharmony_ci
17362306a36Sopenharmony_ci	/* Set the owner of the descriptor */
17462306a36Sopenharmony_ci	void (*set_tx_owner)(struct sxgbe_tx_norm_desc *p);
17562306a36Sopenharmony_ci
17662306a36Sopenharmony_ci	/* Get the owner of the descriptor */
17762306a36Sopenharmony_ci	int (*get_tx_owner)(struct sxgbe_tx_norm_desc *p);
17862306a36Sopenharmony_ci
17962306a36Sopenharmony_ci	/* Invoked by the xmit function to close the tx descriptor */
18062306a36Sopenharmony_ci	void (*close_tx_desc)(struct sxgbe_tx_norm_desc *p);
18162306a36Sopenharmony_ci
18262306a36Sopenharmony_ci	/* Clean the tx descriptor as soon as the tx irq is received */
18362306a36Sopenharmony_ci	void (*release_tx_desc)(struct sxgbe_tx_norm_desc *p);
18462306a36Sopenharmony_ci
18562306a36Sopenharmony_ci	/* Clear interrupt on tx frame completion. When this bit is
18662306a36Sopenharmony_ci	 * set an interrupt happens as soon as the frame is transmitted
18762306a36Sopenharmony_ci	 */
18862306a36Sopenharmony_ci	void (*clear_tx_ic)(struct sxgbe_tx_norm_desc *p);
18962306a36Sopenharmony_ci
19062306a36Sopenharmony_ci	/* Last tx segment reports the transmit status */
19162306a36Sopenharmony_ci	int (*get_tx_ls)(struct sxgbe_tx_norm_desc *p);
19262306a36Sopenharmony_ci
19362306a36Sopenharmony_ci	/* Get the buffer size from the descriptor */
19462306a36Sopenharmony_ci	int (*get_tx_len)(struct sxgbe_tx_norm_desc *p);
19562306a36Sopenharmony_ci
19662306a36Sopenharmony_ci	/* Set tx timestamp enable bit */
19762306a36Sopenharmony_ci	void (*tx_enable_tstamp)(struct sxgbe_tx_norm_desc *p);
19862306a36Sopenharmony_ci
19962306a36Sopenharmony_ci	/* get tx timestamp status */
20062306a36Sopenharmony_ci	int (*get_tx_timestamp_status)(struct sxgbe_tx_norm_desc *p);
20162306a36Sopenharmony_ci
20262306a36Sopenharmony_ci	/* TX Context Descripto Specific */
20362306a36Sopenharmony_ci	void (*tx_ctxt_desc_set_ctxt)(struct sxgbe_tx_ctxt_desc *p);
20462306a36Sopenharmony_ci
20562306a36Sopenharmony_ci	/* Set the owner of the TX context descriptor */
20662306a36Sopenharmony_ci	void (*tx_ctxt_desc_set_owner)(struct sxgbe_tx_ctxt_desc *p);
20762306a36Sopenharmony_ci
20862306a36Sopenharmony_ci	/* Get the owner of the TX context descriptor */
20962306a36Sopenharmony_ci	int (*get_tx_ctxt_owner)(struct sxgbe_tx_ctxt_desc *p);
21062306a36Sopenharmony_ci
21162306a36Sopenharmony_ci	/* Set TX mss */
21262306a36Sopenharmony_ci	void (*tx_ctxt_desc_set_mss)(struct sxgbe_tx_ctxt_desc *p, u16 mss);
21362306a36Sopenharmony_ci
21462306a36Sopenharmony_ci	/* Set TX mss */
21562306a36Sopenharmony_ci	int (*tx_ctxt_desc_get_mss)(struct sxgbe_tx_ctxt_desc *p);
21662306a36Sopenharmony_ci
21762306a36Sopenharmony_ci	/* Set TX tcmssv */
21862306a36Sopenharmony_ci	void (*tx_ctxt_desc_set_tcmssv)(struct sxgbe_tx_ctxt_desc *p);
21962306a36Sopenharmony_ci
22062306a36Sopenharmony_ci	/* Reset TX ostc */
22162306a36Sopenharmony_ci	void (*tx_ctxt_desc_reset_ostc)(struct sxgbe_tx_ctxt_desc *p);
22262306a36Sopenharmony_ci
22362306a36Sopenharmony_ci	/* Set IVLAN information */
22462306a36Sopenharmony_ci	void (*tx_ctxt_desc_set_ivlantag)(struct sxgbe_tx_ctxt_desc *p,
22562306a36Sopenharmony_ci					  int is_ivlanvalid, int ivlan_tag,
22662306a36Sopenharmony_ci					  int ivlan_ctl);
22762306a36Sopenharmony_ci
22862306a36Sopenharmony_ci	/* Return IVLAN Tag */
22962306a36Sopenharmony_ci	int (*tx_ctxt_desc_get_ivlantag)(struct sxgbe_tx_ctxt_desc *p);
23062306a36Sopenharmony_ci
23162306a36Sopenharmony_ci	/* Set VLAN Tag */
23262306a36Sopenharmony_ci	void (*tx_ctxt_desc_set_vlantag)(struct sxgbe_tx_ctxt_desc *p,
23362306a36Sopenharmony_ci					 int is_vlanvalid, int vlan_tag);
23462306a36Sopenharmony_ci
23562306a36Sopenharmony_ci	/* Return VLAN Tag */
23662306a36Sopenharmony_ci	int (*tx_ctxt_desc_get_vlantag)(struct sxgbe_tx_ctxt_desc *p);
23762306a36Sopenharmony_ci
23862306a36Sopenharmony_ci	/* Set Time stamp */
23962306a36Sopenharmony_ci	void (*tx_ctxt_set_tstamp)(struct sxgbe_tx_ctxt_desc *p,
24062306a36Sopenharmony_ci				   u8 ostc_enable, u64 tstamp);
24162306a36Sopenharmony_ci
24262306a36Sopenharmony_ci	/* Close TX context descriptor */
24362306a36Sopenharmony_ci	void (*close_tx_ctxt_desc)(struct sxgbe_tx_ctxt_desc *p);
24462306a36Sopenharmony_ci
24562306a36Sopenharmony_ci	/* WB status of context descriptor */
24662306a36Sopenharmony_ci	int (*get_tx_ctxt_cde)(struct sxgbe_tx_ctxt_desc *p);
24762306a36Sopenharmony_ci
24862306a36Sopenharmony_ci	/* DMA RX descriptor ring initialization */
24962306a36Sopenharmony_ci	void (*init_rx_desc)(struct sxgbe_rx_norm_desc *p, int disable_rx_ic,
25062306a36Sopenharmony_ci			     int mode, int end);
25162306a36Sopenharmony_ci
25262306a36Sopenharmony_ci	/* Get own bit */
25362306a36Sopenharmony_ci	int (*get_rx_owner)(struct sxgbe_rx_norm_desc *p);
25462306a36Sopenharmony_ci
25562306a36Sopenharmony_ci	/* Set own bit */
25662306a36Sopenharmony_ci	void (*set_rx_owner)(struct sxgbe_rx_norm_desc *p);
25762306a36Sopenharmony_ci
25862306a36Sopenharmony_ci	/* Set Interrupt on completion bit */
25962306a36Sopenharmony_ci	void (*set_rx_int_on_com)(struct sxgbe_rx_norm_desc *p);
26062306a36Sopenharmony_ci
26162306a36Sopenharmony_ci	/* Get the receive frame size */
26262306a36Sopenharmony_ci	int (*get_rx_frame_len)(struct sxgbe_rx_norm_desc *p);
26362306a36Sopenharmony_ci
26462306a36Sopenharmony_ci	/* Return first Descriptor status */
26562306a36Sopenharmony_ci	int (*get_rx_fd_status)(struct sxgbe_rx_norm_desc *p);
26662306a36Sopenharmony_ci
26762306a36Sopenharmony_ci	/* Return first Descriptor status */
26862306a36Sopenharmony_ci	int (*get_rx_ld_status)(struct sxgbe_rx_norm_desc *p);
26962306a36Sopenharmony_ci
27062306a36Sopenharmony_ci	/* Return the reception status looking at the RDES1 */
27162306a36Sopenharmony_ci	int (*rx_wbstatus)(struct sxgbe_rx_norm_desc *p,
27262306a36Sopenharmony_ci			   struct sxgbe_extra_stats *x, int *checksum);
27362306a36Sopenharmony_ci
27462306a36Sopenharmony_ci	/* Get own bit */
27562306a36Sopenharmony_ci	int (*get_rx_ctxt_owner)(struct sxgbe_rx_ctxt_desc *p);
27662306a36Sopenharmony_ci
27762306a36Sopenharmony_ci	/* Set own bit */
27862306a36Sopenharmony_ci	void (*set_rx_ctxt_owner)(struct sxgbe_rx_ctxt_desc *p);
27962306a36Sopenharmony_ci
28062306a36Sopenharmony_ci	/* Return the reception status looking at Context control information */
28162306a36Sopenharmony_ci	void (*rx_ctxt_wbstatus)(struct sxgbe_rx_ctxt_desc *p,
28262306a36Sopenharmony_ci				 struct sxgbe_extra_stats *x);
28362306a36Sopenharmony_ci
28462306a36Sopenharmony_ci	/* Get rx timestamp status */
28562306a36Sopenharmony_ci	int (*get_rx_ctxt_tstamp_status)(struct sxgbe_rx_ctxt_desc *p);
28662306a36Sopenharmony_ci
28762306a36Sopenharmony_ci	/* Get timestamp value for rx, need to check this */
28862306a36Sopenharmony_ci	u64 (*get_timestamp)(struct sxgbe_rx_ctxt_desc *p);
28962306a36Sopenharmony_ci};
29062306a36Sopenharmony_ci
29162306a36Sopenharmony_ciconst struct sxgbe_desc_ops *sxgbe_get_desc_ops(void);
29262306a36Sopenharmony_ci
29362306a36Sopenharmony_ci#endif /* __SXGBE_DESC_H__ */
294