xref: /openbmc/linux/drivers/crypto/cavium/nitrox/nitrox_hal.c (revision bee7bdf11f0129f460e83a2f5f50bba8434a6929)
1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
214fa93cdSSrikanth Jampala #include <linux/delay.h>
314fa93cdSSrikanth Jampala 
414fa93cdSSrikanth Jampala #include "nitrox_dev.h"
514fa93cdSSrikanth Jampala #include "nitrox_csr.h"
614fa93cdSSrikanth Jampala 
748e10548SSrikanth Jampala #define PLL_REF_CLK 50
8cf718eaaSSrikanth, Jampala #define MAX_CSR_RETRIES 10
948e10548SSrikanth Jampala 
1014fa93cdSSrikanth Jampala /**
1114fa93cdSSrikanth Jampala  * emu_enable_cores - Enable EMU cluster cores.
12cf718eaaSSrikanth, Jampala  * @ndev: NITROX device
1314fa93cdSSrikanth Jampala  */
1414fa93cdSSrikanth Jampala static void emu_enable_cores(struct nitrox_device *ndev)
1514fa93cdSSrikanth Jampala {
1614fa93cdSSrikanth Jampala 	union emu_se_enable emu_se;
1714fa93cdSSrikanth Jampala 	union emu_ae_enable emu_ae;
1814fa93cdSSrikanth Jampala 	int i;
1914fa93cdSSrikanth Jampala 
2014fa93cdSSrikanth Jampala 	/* AE cores 20 per cluster */
2114fa93cdSSrikanth Jampala 	emu_ae.value = 0;
2214fa93cdSSrikanth Jampala 	emu_ae.s.enable = 0xfffff;
2314fa93cdSSrikanth Jampala 
2414fa93cdSSrikanth Jampala 	/* SE cores 16 per cluster */
2514fa93cdSSrikanth Jampala 	emu_se.value = 0;
2614fa93cdSSrikanth Jampala 	emu_se.s.enable = 0xffff;
2714fa93cdSSrikanth Jampala 
2814fa93cdSSrikanth Jampala 	/* enable per cluster cores */
2914fa93cdSSrikanth Jampala 	for (i = 0; i < NR_CLUSTERS; i++) {
3014fa93cdSSrikanth Jampala 		nitrox_write_csr(ndev, EMU_AE_ENABLEX(i), emu_ae.value);
3114fa93cdSSrikanth Jampala 		nitrox_write_csr(ndev, EMU_SE_ENABLEX(i), emu_se.value);
3214fa93cdSSrikanth Jampala 	}
3314fa93cdSSrikanth Jampala }
3414fa93cdSSrikanth Jampala 
3514fa93cdSSrikanth Jampala /**
3614fa93cdSSrikanth Jampala  * nitrox_config_emu_unit - configure EMU unit.
37cf718eaaSSrikanth, Jampala  * @ndev: NITROX device
3814fa93cdSSrikanth Jampala  */
3914fa93cdSSrikanth Jampala void nitrox_config_emu_unit(struct nitrox_device *ndev)
4014fa93cdSSrikanth Jampala {
4114fa93cdSSrikanth Jampala 	union emu_wd_int_ena_w1s emu_wd_int;
4214fa93cdSSrikanth Jampala 	union emu_ge_int_ena_w1s emu_ge_int;
4314fa93cdSSrikanth Jampala 	u64 offset;
4414fa93cdSSrikanth Jampala 	int i;
4514fa93cdSSrikanth Jampala 
4614fa93cdSSrikanth Jampala 	/* enable cores */
4714fa93cdSSrikanth Jampala 	emu_enable_cores(ndev);
4814fa93cdSSrikanth Jampala 
4914fa93cdSSrikanth Jampala 	/* enable general error and watch dog interrupts */
5014fa93cdSSrikanth Jampala 	emu_ge_int.value = 0;
5114fa93cdSSrikanth Jampala 	emu_ge_int.s.se_ge = 0xffff;
5214fa93cdSSrikanth Jampala 	emu_ge_int.s.ae_ge = 0xfffff;
5314fa93cdSSrikanth Jampala 	emu_wd_int.value = 0;
5414fa93cdSSrikanth Jampala 	emu_wd_int.s.se_wd = 1;
5514fa93cdSSrikanth Jampala 
5614fa93cdSSrikanth Jampala 	for (i = 0; i < NR_CLUSTERS; i++) {
5714fa93cdSSrikanth Jampala 		offset = EMU_WD_INT_ENA_W1SX(i);
5814fa93cdSSrikanth Jampala 		nitrox_write_csr(ndev, offset, emu_wd_int.value);
5914fa93cdSSrikanth Jampala 		offset = EMU_GE_INT_ENA_W1SX(i);
6014fa93cdSSrikanth Jampala 		nitrox_write_csr(ndev, offset, emu_ge_int.value);
6114fa93cdSSrikanth Jampala 	}
6214fa93cdSSrikanth Jampala }
6314fa93cdSSrikanth Jampala 
6414fa93cdSSrikanth Jampala static void reset_pkt_input_ring(struct nitrox_device *ndev, int ring)
6514fa93cdSSrikanth Jampala {
6614fa93cdSSrikanth Jampala 	union nps_pkt_in_instr_ctl pkt_in_ctl;
6714fa93cdSSrikanth Jampala 	union nps_pkt_in_done_cnts pkt_in_cnts;
68cf718eaaSSrikanth, Jampala 	int max_retries = MAX_CSR_RETRIES;
6914fa93cdSSrikanth Jampala 	u64 offset;
7014fa93cdSSrikanth Jampala 
71cf718eaaSSrikanth, Jampala 	/* step 1: disable the ring, clear enable bit */
7214fa93cdSSrikanth Jampala 	offset = NPS_PKT_IN_INSTR_CTLX(ring);
7314fa93cdSSrikanth Jampala 	pkt_in_ctl.value = nitrox_read_csr(ndev, offset);
7414fa93cdSSrikanth Jampala 	pkt_in_ctl.s.enb = 0;
7514fa93cdSSrikanth Jampala 	nitrox_write_csr(ndev, offset, pkt_in_ctl.value);
7614fa93cdSSrikanth Jampala 
77cf718eaaSSrikanth, Jampala 	/* step 2: wait to clear [ENB] */
78cf718eaaSSrikanth, Jampala 	usleep_range(100, 150);
7914fa93cdSSrikanth Jampala 	do {
8014fa93cdSSrikanth Jampala 		pkt_in_ctl.value = nitrox_read_csr(ndev, offset);
81cf718eaaSSrikanth, Jampala 		if (!pkt_in_ctl.s.enb)
82cf718eaaSSrikanth, Jampala 			break;
83cf718eaaSSrikanth, Jampala 		udelay(50);
84cf718eaaSSrikanth, Jampala 	} while (max_retries--);
8514fa93cdSSrikanth Jampala 
86cf718eaaSSrikanth, Jampala 	/* step 3: clear done counts */
8714fa93cdSSrikanth Jampala 	offset = NPS_PKT_IN_DONE_CNTSX(ring);
8814fa93cdSSrikanth Jampala 	pkt_in_cnts.value = nitrox_read_csr(ndev, offset);
8914fa93cdSSrikanth Jampala 	nitrox_write_csr(ndev, offset, pkt_in_cnts.value);
9014fa93cdSSrikanth Jampala 	usleep_range(50, 100);
9114fa93cdSSrikanth Jampala }
9214fa93cdSSrikanth Jampala 
9314fa93cdSSrikanth Jampala void enable_pkt_input_ring(struct nitrox_device *ndev, int ring)
9414fa93cdSSrikanth Jampala {
9514fa93cdSSrikanth Jampala 	union nps_pkt_in_instr_ctl pkt_in_ctl;
96cf718eaaSSrikanth, Jampala 	int max_retries = MAX_CSR_RETRIES;
9714fa93cdSSrikanth Jampala 	u64 offset;
9814fa93cdSSrikanth Jampala 
9914fa93cdSSrikanth Jampala 	/* 64-byte instruction size */
10014fa93cdSSrikanth Jampala 	offset = NPS_PKT_IN_INSTR_CTLX(ring);
10114fa93cdSSrikanth Jampala 	pkt_in_ctl.value = nitrox_read_csr(ndev, offset);
10214fa93cdSSrikanth Jampala 	pkt_in_ctl.s.is64b = 1;
10314fa93cdSSrikanth Jampala 	pkt_in_ctl.s.enb = 1;
10414fa93cdSSrikanth Jampala 	nitrox_write_csr(ndev, offset, pkt_in_ctl.value);
10514fa93cdSSrikanth Jampala 
10614fa93cdSSrikanth Jampala 	/* wait for set [ENB] */
10714fa93cdSSrikanth Jampala 	do {
10814fa93cdSSrikanth Jampala 		pkt_in_ctl.value = nitrox_read_csr(ndev, offset);
109cf718eaaSSrikanth, Jampala 		if (pkt_in_ctl.s.enb)
110cf718eaaSSrikanth, Jampala 			break;
111cf718eaaSSrikanth, Jampala 		udelay(50);
112cf718eaaSSrikanth, Jampala 	} while (max_retries--);
11314fa93cdSSrikanth Jampala }
11414fa93cdSSrikanth Jampala 
11514fa93cdSSrikanth Jampala /**
11614fa93cdSSrikanth Jampala  * nitrox_config_pkt_input_rings - configure Packet Input Rings
117cf718eaaSSrikanth, Jampala  * @ndev: NITROX device
11814fa93cdSSrikanth Jampala  */
11914fa93cdSSrikanth Jampala void nitrox_config_pkt_input_rings(struct nitrox_device *ndev)
12014fa93cdSSrikanth Jampala {
12114fa93cdSSrikanth Jampala 	int i;
12214fa93cdSSrikanth Jampala 
12314fa93cdSSrikanth Jampala 	for (i = 0; i < ndev->nr_queues; i++) {
124e7892dd6SSrikanth Jampala 		struct nitrox_cmdq *cmdq = &ndev->pkt_inq[i];
12514fa93cdSSrikanth Jampala 		union nps_pkt_in_instr_rsize pkt_in_rsize;
126cf718eaaSSrikanth, Jampala 		union nps_pkt_in_instr_baoff_dbell pkt_in_dbell;
12714fa93cdSSrikanth Jampala 		u64 offset;
12814fa93cdSSrikanth Jampala 
12914fa93cdSSrikanth Jampala 		reset_pkt_input_ring(ndev, i);
13014fa93cdSSrikanth Jampala 
131cf718eaaSSrikanth, Jampala 		/**
132cf718eaaSSrikanth, Jampala 		 * step 4:
133cf718eaaSSrikanth, Jampala 		 * configure ring base address 16-byte aligned,
13414fa93cdSSrikanth Jampala 		 * size and interrupt threshold.
13514fa93cdSSrikanth Jampala 		 */
13614fa93cdSSrikanth Jampala 		offset = NPS_PKT_IN_INSTR_BADDRX(i);
1372f1fedcaSColin Ian King 		nitrox_write_csr(ndev, offset, cmdq->dma);
13814fa93cdSSrikanth Jampala 
13914fa93cdSSrikanth Jampala 		/* configure ring size */
14014fa93cdSSrikanth Jampala 		offset = NPS_PKT_IN_INSTR_RSIZEX(i);
14114fa93cdSSrikanth Jampala 		pkt_in_rsize.value = 0;
14214fa93cdSSrikanth Jampala 		pkt_in_rsize.s.rsize = ndev->qlen;
14314fa93cdSSrikanth Jampala 		nitrox_write_csr(ndev, offset, pkt_in_rsize.value);
14414fa93cdSSrikanth Jampala 
14514fa93cdSSrikanth Jampala 		/* set high threshold for pkt input ring interrupts */
14614fa93cdSSrikanth Jampala 		offset = NPS_PKT_IN_INT_LEVELSX(i);
14714fa93cdSSrikanth Jampala 		nitrox_write_csr(ndev, offset, 0xffffffff);
14814fa93cdSSrikanth Jampala 
149cf718eaaSSrikanth, Jampala 		/* step 5: clear off door bell counts */
150cf718eaaSSrikanth, Jampala 		offset = NPS_PKT_IN_INSTR_BAOFF_DBELLX(i);
151cf718eaaSSrikanth, Jampala 		pkt_in_dbell.value = 0;
152cf718eaaSSrikanth, Jampala 		pkt_in_dbell.s.dbell = 0xffffffff;
153cf718eaaSSrikanth, Jampala 		nitrox_write_csr(ndev, offset, pkt_in_dbell.value);
154cf718eaaSSrikanth, Jampala 
155cf718eaaSSrikanth, Jampala 		/* enable the ring */
15614fa93cdSSrikanth Jampala 		enable_pkt_input_ring(ndev, i);
15714fa93cdSSrikanth Jampala 	}
15814fa93cdSSrikanth Jampala }
15914fa93cdSSrikanth Jampala 
16014fa93cdSSrikanth Jampala static void reset_pkt_solicit_port(struct nitrox_device *ndev, int port)
16114fa93cdSSrikanth Jampala {
16214fa93cdSSrikanth Jampala 	union nps_pkt_slc_ctl pkt_slc_ctl;
16314fa93cdSSrikanth Jampala 	union nps_pkt_slc_cnts pkt_slc_cnts;
164cf718eaaSSrikanth, Jampala 	int max_retries = MAX_CSR_RETRIES;
16514fa93cdSSrikanth Jampala 	u64 offset;
16614fa93cdSSrikanth Jampala 
167cf718eaaSSrikanth, Jampala 	/* step 1: disable slc port */
16814fa93cdSSrikanth Jampala 	offset = NPS_PKT_SLC_CTLX(port);
16914fa93cdSSrikanth Jampala 	pkt_slc_ctl.value = nitrox_read_csr(ndev, offset);
17014fa93cdSSrikanth Jampala 	pkt_slc_ctl.s.enb = 0;
17114fa93cdSSrikanth Jampala 	nitrox_write_csr(ndev, offset, pkt_slc_ctl.value);
17214fa93cdSSrikanth Jampala 
173cf718eaaSSrikanth, Jampala 	/* step 2 */
174cf718eaaSSrikanth, Jampala 	usleep_range(100, 150);
17514fa93cdSSrikanth Jampala 	/* wait to clear [ENB] */
17614fa93cdSSrikanth Jampala 	do {
17714fa93cdSSrikanth Jampala 		pkt_slc_ctl.value = nitrox_read_csr(ndev, offset);
178cf718eaaSSrikanth, Jampala 		if (!pkt_slc_ctl.s.enb)
179cf718eaaSSrikanth, Jampala 			break;
180cf718eaaSSrikanth, Jampala 		udelay(50);
181cf718eaaSSrikanth, Jampala 	} while (max_retries--);
18214fa93cdSSrikanth Jampala 
183cf718eaaSSrikanth, Jampala 	/* step 3: clear slc counters */
18414fa93cdSSrikanth Jampala 	offset = NPS_PKT_SLC_CNTSX(port);
18514fa93cdSSrikanth Jampala 	pkt_slc_cnts.value = nitrox_read_csr(ndev, offset);
18614fa93cdSSrikanth Jampala 	nitrox_write_csr(ndev, offset, pkt_slc_cnts.value);
18714fa93cdSSrikanth Jampala 	usleep_range(50, 100);
18814fa93cdSSrikanth Jampala }
18914fa93cdSSrikanth Jampala 
19014fa93cdSSrikanth Jampala void enable_pkt_solicit_port(struct nitrox_device *ndev, int port)
19114fa93cdSSrikanth Jampala {
19214fa93cdSSrikanth Jampala 	union nps_pkt_slc_ctl pkt_slc_ctl;
193cf718eaaSSrikanth, Jampala 	int max_retries = MAX_CSR_RETRIES;
19414fa93cdSSrikanth Jampala 	u64 offset;
19514fa93cdSSrikanth Jampala 
19614fa93cdSSrikanth Jampala 	offset = NPS_PKT_SLC_CTLX(port);
19714fa93cdSSrikanth Jampala 	pkt_slc_ctl.value = 0;
19814fa93cdSSrikanth Jampala 	pkt_slc_ctl.s.enb = 1;
19914fa93cdSSrikanth Jampala 	/*
20014fa93cdSSrikanth Jampala 	 * 8 trailing 0x00 bytes will be added
20114fa93cdSSrikanth Jampala 	 * to the end of the outgoing packet.
20214fa93cdSSrikanth Jampala 	 */
20314fa93cdSSrikanth Jampala 	pkt_slc_ctl.s.z = 1;
20414fa93cdSSrikanth Jampala 	/* enable response header */
20514fa93cdSSrikanth Jampala 	pkt_slc_ctl.s.rh = 1;
20614fa93cdSSrikanth Jampala 	nitrox_write_csr(ndev, offset, pkt_slc_ctl.value);
20714fa93cdSSrikanth Jampala 
20814fa93cdSSrikanth Jampala 	/* wait to set [ENB] */
20914fa93cdSSrikanth Jampala 	do {
21014fa93cdSSrikanth Jampala 		pkt_slc_ctl.value = nitrox_read_csr(ndev, offset);
211cf718eaaSSrikanth, Jampala 		if (pkt_slc_ctl.s.enb)
212cf718eaaSSrikanth, Jampala 			break;
213cf718eaaSSrikanth, Jampala 		udelay(50);
214cf718eaaSSrikanth, Jampala 	} while (max_retries--);
21514fa93cdSSrikanth Jampala }
21614fa93cdSSrikanth Jampala 
217cf718eaaSSrikanth, Jampala static void config_pkt_solicit_port(struct nitrox_device *ndev, int port)
21814fa93cdSSrikanth Jampala {
21914fa93cdSSrikanth Jampala 	union nps_pkt_slc_int_levels pkt_slc_int;
22014fa93cdSSrikanth Jampala 	u64 offset;
22114fa93cdSSrikanth Jampala 
22214fa93cdSSrikanth Jampala 	reset_pkt_solicit_port(ndev, port);
22314fa93cdSSrikanth Jampala 
224cf718eaaSSrikanth, Jampala 	/* step 4: configure interrupt levels */
22514fa93cdSSrikanth Jampala 	offset = NPS_PKT_SLC_INT_LEVELSX(port);
22614fa93cdSSrikanth Jampala 	pkt_slc_int.value = 0;
22714fa93cdSSrikanth Jampala 	/* time interrupt threshold */
22814fa93cdSSrikanth Jampala 	pkt_slc_int.s.timet = 0x3fffff;
22914fa93cdSSrikanth Jampala 	nitrox_write_csr(ndev, offset, pkt_slc_int.value);
23014fa93cdSSrikanth Jampala 
231cf718eaaSSrikanth, Jampala 	/* enable the solicit port */
23214fa93cdSSrikanth Jampala 	enable_pkt_solicit_port(ndev, port);
23314fa93cdSSrikanth Jampala }
23414fa93cdSSrikanth Jampala 
23514fa93cdSSrikanth Jampala void nitrox_config_pkt_solicit_ports(struct nitrox_device *ndev)
23614fa93cdSSrikanth Jampala {
23714fa93cdSSrikanth Jampala 	int i;
23814fa93cdSSrikanth Jampala 
23914fa93cdSSrikanth Jampala 	for (i = 0; i < ndev->nr_queues; i++)
240cf718eaaSSrikanth, Jampala 		config_pkt_solicit_port(ndev, i);
24114fa93cdSSrikanth Jampala }
24214fa93cdSSrikanth Jampala 
24314fa93cdSSrikanth Jampala /**
24414fa93cdSSrikanth Jampala  * enable_nps_interrupts - enable NPS interrutps
245cf718eaaSSrikanth, Jampala  * @ndev: NITROX device.
24614fa93cdSSrikanth Jampala  *
24714fa93cdSSrikanth Jampala  * This includes NPS core, packet in and slc interrupts.
24814fa93cdSSrikanth Jampala  */
24914fa93cdSSrikanth Jampala static void enable_nps_interrupts(struct nitrox_device *ndev)
25014fa93cdSSrikanth Jampala {
25114fa93cdSSrikanth Jampala 	union nps_core_int_ena_w1s core_int;
25214fa93cdSSrikanth Jampala 
25314fa93cdSSrikanth Jampala 	/* NPS core interrutps */
25414fa93cdSSrikanth Jampala 	core_int.value = 0;
25514fa93cdSSrikanth Jampala 	core_int.s.host_wr_err = 1;
25614fa93cdSSrikanth Jampala 	core_int.s.host_wr_timeout = 1;
25714fa93cdSSrikanth Jampala 	core_int.s.exec_wr_timeout = 1;
25814fa93cdSSrikanth Jampala 	core_int.s.npco_dma_malform = 1;
25914fa93cdSSrikanth Jampala 	core_int.s.host_nps_wr_err = 1;
26014fa93cdSSrikanth Jampala 	nitrox_write_csr(ndev, NPS_CORE_INT_ENA_W1S, core_int.value);
26114fa93cdSSrikanth Jampala 
26214fa93cdSSrikanth Jampala 	/* NPS packet in ring interrupts */
26314fa93cdSSrikanth Jampala 	nitrox_write_csr(ndev, NPS_PKT_IN_RERR_LO_ENA_W1S, (~0ULL));
26414fa93cdSSrikanth Jampala 	nitrox_write_csr(ndev, NPS_PKT_IN_RERR_HI_ENA_W1S, (~0ULL));
26514fa93cdSSrikanth Jampala 	nitrox_write_csr(ndev, NPS_PKT_IN_ERR_TYPE_ENA_W1S, (~0ULL));
26614fa93cdSSrikanth Jampala 	/* NPS packet slc port interrupts */
26714fa93cdSSrikanth Jampala 	nitrox_write_csr(ndev, NPS_PKT_SLC_RERR_HI_ENA_W1S, (~0ULL));
26814fa93cdSSrikanth Jampala 	nitrox_write_csr(ndev, NPS_PKT_SLC_RERR_LO_ENA_W1S, (~0ULL));
26914fa93cdSSrikanth Jampala 	nitrox_write_csr(ndev, NPS_PKT_SLC_ERR_TYPE_ENA_W1S, (~0uLL));
27014fa93cdSSrikanth Jampala }
27114fa93cdSSrikanth Jampala 
27214fa93cdSSrikanth Jampala void nitrox_config_nps_unit(struct nitrox_device *ndev)
27314fa93cdSSrikanth Jampala {
27414fa93cdSSrikanth Jampala 	union nps_core_gbl_vfcfg core_gbl_vfcfg;
27514fa93cdSSrikanth Jampala 
27614fa93cdSSrikanth Jampala 	/* endian control information */
27714fa93cdSSrikanth Jampala 	nitrox_write_csr(ndev, NPS_CORE_CONTROL, 1ULL);
27814fa93cdSSrikanth Jampala 
27914fa93cdSSrikanth Jampala 	/* disable ILK interface */
28014fa93cdSSrikanth Jampala 	core_gbl_vfcfg.value = 0;
28114fa93cdSSrikanth Jampala 	core_gbl_vfcfg.s.ilk_disable = 1;
28241a9aca6SSrikanth Jampala 	core_gbl_vfcfg.s.cfg = __NDEV_MODE_PF;
28314fa93cdSSrikanth Jampala 	nitrox_write_csr(ndev, NPS_CORE_GBL_VFCFG, core_gbl_vfcfg.value);
28414fa93cdSSrikanth Jampala 	/* config input and solicit ports */
28514fa93cdSSrikanth Jampala 	nitrox_config_pkt_input_rings(ndev);
28614fa93cdSSrikanth Jampala 	nitrox_config_pkt_solicit_ports(ndev);
28714fa93cdSSrikanth Jampala 
28814fa93cdSSrikanth Jampala 	/* enable interrupts */
28914fa93cdSSrikanth Jampala 	enable_nps_interrupts(ndev);
29014fa93cdSSrikanth Jampala }
29114fa93cdSSrikanth Jampala 
29214fa93cdSSrikanth Jampala void nitrox_config_pom_unit(struct nitrox_device *ndev)
29314fa93cdSSrikanth Jampala {
29414fa93cdSSrikanth Jampala 	union pom_int_ena_w1s pom_int;
29514fa93cdSSrikanth Jampala 	int i;
29614fa93cdSSrikanth Jampala 
29714fa93cdSSrikanth Jampala 	/* enable pom interrupts */
29814fa93cdSSrikanth Jampala 	pom_int.value = 0;
29914fa93cdSSrikanth Jampala 	pom_int.s.illegal_dport = 1;
30014fa93cdSSrikanth Jampala 	nitrox_write_csr(ndev, POM_INT_ENA_W1S, pom_int.value);
30114fa93cdSSrikanth Jampala 
30214fa93cdSSrikanth Jampala 	/* enable perf counters */
30314fa93cdSSrikanth Jampala 	for (i = 0; i < ndev->hw.se_cores; i++)
30414fa93cdSSrikanth Jampala 		nitrox_write_csr(ndev, POM_PERF_CTL, BIT_ULL(i));
30514fa93cdSSrikanth Jampala }
30614fa93cdSSrikanth Jampala 
30714fa93cdSSrikanth Jampala /**
308cf718eaaSSrikanth, Jampala  * nitrox_config_rand_unit - enable NITROX random number unit
309cf718eaaSSrikanth, Jampala  * @ndev: NITROX device
31014fa93cdSSrikanth Jampala  */
31114fa93cdSSrikanth Jampala void nitrox_config_rand_unit(struct nitrox_device *ndev)
31214fa93cdSSrikanth Jampala {
31314fa93cdSSrikanth Jampala 	union efl_rnm_ctl_status efl_rnm_ctl;
31414fa93cdSSrikanth Jampala 	u64 offset;
31514fa93cdSSrikanth Jampala 
31614fa93cdSSrikanth Jampala 	offset = EFL_RNM_CTL_STATUS;
31714fa93cdSSrikanth Jampala 	efl_rnm_ctl.value = nitrox_read_csr(ndev, offset);
31814fa93cdSSrikanth Jampala 	efl_rnm_ctl.s.ent_en = 1;
31914fa93cdSSrikanth Jampala 	efl_rnm_ctl.s.rng_en = 1;
32014fa93cdSSrikanth Jampala 	nitrox_write_csr(ndev, offset, efl_rnm_ctl.value);
32114fa93cdSSrikanth Jampala }
32214fa93cdSSrikanth Jampala 
32314fa93cdSSrikanth Jampala void nitrox_config_efl_unit(struct nitrox_device *ndev)
32414fa93cdSSrikanth Jampala {
32514fa93cdSSrikanth Jampala 	int i;
32614fa93cdSSrikanth Jampala 
32714fa93cdSSrikanth Jampala 	for (i = 0; i < NR_CLUSTERS; i++) {
32814fa93cdSSrikanth Jampala 		union efl_core_int_ena_w1s efl_core_int;
32914fa93cdSSrikanth Jampala 		u64 offset;
33014fa93cdSSrikanth Jampala 
33114fa93cdSSrikanth Jampala 		/* EFL core interrupts */
33214fa93cdSSrikanth Jampala 		offset = EFL_CORE_INT_ENA_W1SX(i);
33314fa93cdSSrikanth Jampala 		efl_core_int.value = 0;
33414fa93cdSSrikanth Jampala 		efl_core_int.s.len_ovr = 1;
33514fa93cdSSrikanth Jampala 		efl_core_int.s.d_left = 1;
33614fa93cdSSrikanth Jampala 		efl_core_int.s.epci_decode_err = 1;
33714fa93cdSSrikanth Jampala 		nitrox_write_csr(ndev, offset, efl_core_int.value);
33814fa93cdSSrikanth Jampala 
33914fa93cdSSrikanth Jampala 		offset = EFL_CORE_VF_ERR_INT0_ENA_W1SX(i);
34014fa93cdSSrikanth Jampala 		nitrox_write_csr(ndev, offset, (~0ULL));
34114fa93cdSSrikanth Jampala 		offset = EFL_CORE_VF_ERR_INT1_ENA_W1SX(i);
34214fa93cdSSrikanth Jampala 		nitrox_write_csr(ndev, offset, (~0ULL));
34314fa93cdSSrikanth Jampala 	}
34414fa93cdSSrikanth Jampala }
34514fa93cdSSrikanth Jampala 
34614fa93cdSSrikanth Jampala void nitrox_config_bmi_unit(struct nitrox_device *ndev)
34714fa93cdSSrikanth Jampala {
34814fa93cdSSrikanth Jampala 	union bmi_ctl bmi_ctl;
34914fa93cdSSrikanth Jampala 	union bmi_int_ena_w1s bmi_int_ena;
35014fa93cdSSrikanth Jampala 	u64 offset;
35114fa93cdSSrikanth Jampala 
35214fa93cdSSrikanth Jampala 	/* no threshold limits for PCIe */
35314fa93cdSSrikanth Jampala 	offset = BMI_CTL;
35414fa93cdSSrikanth Jampala 	bmi_ctl.value = nitrox_read_csr(ndev, offset);
35514fa93cdSSrikanth Jampala 	bmi_ctl.s.max_pkt_len = 0xff;
35614fa93cdSSrikanth Jampala 	bmi_ctl.s.nps_free_thrsh = 0xff;
35714fa93cdSSrikanth Jampala 	bmi_ctl.s.nps_hdrq_thrsh = 0x7a;
35814fa93cdSSrikanth Jampala 	nitrox_write_csr(ndev, offset, bmi_ctl.value);
35914fa93cdSSrikanth Jampala 
36014fa93cdSSrikanth Jampala 	/* enable interrupts */
36114fa93cdSSrikanth Jampala 	offset = BMI_INT_ENA_W1S;
36214fa93cdSSrikanth Jampala 	bmi_int_ena.value = 0;
36314fa93cdSSrikanth Jampala 	bmi_int_ena.s.max_len_err_nps = 1;
36414fa93cdSSrikanth Jampala 	bmi_int_ena.s.pkt_rcv_err_nps = 1;
36514fa93cdSSrikanth Jampala 	bmi_int_ena.s.fpf_undrrn = 1;
36614fa93cdSSrikanth Jampala 	nitrox_write_csr(ndev, offset, bmi_int_ena.value);
36714fa93cdSSrikanth Jampala }
36814fa93cdSSrikanth Jampala 
36914fa93cdSSrikanth Jampala void nitrox_config_bmo_unit(struct nitrox_device *ndev)
37014fa93cdSSrikanth Jampala {
37114fa93cdSSrikanth Jampala 	union bmo_ctl2 bmo_ctl2;
37214fa93cdSSrikanth Jampala 	u64 offset;
37314fa93cdSSrikanth Jampala 
37414fa93cdSSrikanth Jampala 	/* no threshold limits for PCIe */
37514fa93cdSSrikanth Jampala 	offset = BMO_CTL2;
37614fa93cdSSrikanth Jampala 	bmo_ctl2.value = nitrox_read_csr(ndev, offset);
37714fa93cdSSrikanth Jampala 	bmo_ctl2.s.nps_slc_buf_thrsh = 0xff;
37814fa93cdSSrikanth Jampala 	nitrox_write_csr(ndev, offset, bmo_ctl2.value);
37914fa93cdSSrikanth Jampala }
38014fa93cdSSrikanth Jampala 
38114fa93cdSSrikanth Jampala void invalidate_lbc(struct nitrox_device *ndev)
38214fa93cdSSrikanth Jampala {
38314fa93cdSSrikanth Jampala 	union lbc_inval_ctl lbc_ctl;
38414fa93cdSSrikanth Jampala 	union lbc_inval_status lbc_stat;
385cf718eaaSSrikanth, Jampala 	int max_retries = MAX_CSR_RETRIES;
38614fa93cdSSrikanth Jampala 	u64 offset;
38714fa93cdSSrikanth Jampala 
38814fa93cdSSrikanth Jampala 	/* invalidate LBC */
38914fa93cdSSrikanth Jampala 	offset = LBC_INVAL_CTL;
39014fa93cdSSrikanth Jampala 	lbc_ctl.value = nitrox_read_csr(ndev, offset);
39114fa93cdSSrikanth Jampala 	lbc_ctl.s.cam_inval_start = 1;
39214fa93cdSSrikanth Jampala 	nitrox_write_csr(ndev, offset, lbc_ctl.value);
39314fa93cdSSrikanth Jampala 
39414fa93cdSSrikanth Jampala 	offset = LBC_INVAL_STATUS;
39514fa93cdSSrikanth Jampala 	do {
39614fa93cdSSrikanth Jampala 		lbc_stat.value = nitrox_read_csr(ndev, offset);
397cf718eaaSSrikanth, Jampala 		if (lbc_stat.s.done)
398cf718eaaSSrikanth, Jampala 			break;
399cf718eaaSSrikanth, Jampala 		udelay(50);
400cf718eaaSSrikanth, Jampala 	} while (max_retries--);
40114fa93cdSSrikanth Jampala }
40214fa93cdSSrikanth Jampala 
40314fa93cdSSrikanth Jampala void nitrox_config_lbc_unit(struct nitrox_device *ndev)
40414fa93cdSSrikanth Jampala {
40514fa93cdSSrikanth Jampala 	union lbc_int_ena_w1s lbc_int_ena;
40614fa93cdSSrikanth Jampala 	u64 offset;
40714fa93cdSSrikanth Jampala 
40814fa93cdSSrikanth Jampala 	invalidate_lbc(ndev);
40914fa93cdSSrikanth Jampala 
41014fa93cdSSrikanth Jampala 	/* enable interrupts */
41114fa93cdSSrikanth Jampala 	offset = LBC_INT_ENA_W1S;
41214fa93cdSSrikanth Jampala 	lbc_int_ena.value = 0;
41314fa93cdSSrikanth Jampala 	lbc_int_ena.s.dma_rd_err = 1;
41414fa93cdSSrikanth Jampala 	lbc_int_ena.s.over_fetch_err = 1;
41514fa93cdSSrikanth Jampala 	lbc_int_ena.s.cam_inval_abort = 1;
41614fa93cdSSrikanth Jampala 	lbc_int_ena.s.cam_hard_err = 1;
41714fa93cdSSrikanth Jampala 	nitrox_write_csr(ndev, offset, lbc_int_ena.value);
41814fa93cdSSrikanth Jampala 
41914fa93cdSSrikanth Jampala 	offset = LBC_PLM_VF1_64_INT_ENA_W1S;
42014fa93cdSSrikanth Jampala 	nitrox_write_csr(ndev, offset, (~0ULL));
42114fa93cdSSrikanth Jampala 	offset = LBC_PLM_VF65_128_INT_ENA_W1S;
42214fa93cdSSrikanth Jampala 	nitrox_write_csr(ndev, offset, (~0ULL));
42314fa93cdSSrikanth Jampala 
42414fa93cdSSrikanth Jampala 	offset = LBC_ELM_VF1_64_INT_ENA_W1S;
42514fa93cdSSrikanth Jampala 	nitrox_write_csr(ndev, offset, (~0ULL));
42614fa93cdSSrikanth Jampala 	offset = LBC_ELM_VF65_128_INT_ENA_W1S;
42714fa93cdSSrikanth Jampala 	nitrox_write_csr(ndev, offset, (~0ULL));
42814fa93cdSSrikanth Jampala }
42941a9aca6SSrikanth Jampala 
43041a9aca6SSrikanth Jampala void config_nps_core_vfcfg_mode(struct nitrox_device *ndev, enum vf_mode mode)
43141a9aca6SSrikanth Jampala {
43241a9aca6SSrikanth Jampala 	union nps_core_gbl_vfcfg vfcfg;
43341a9aca6SSrikanth Jampala 
43441a9aca6SSrikanth Jampala 	vfcfg.value = nitrox_read_csr(ndev, NPS_CORE_GBL_VFCFG);
43541a9aca6SSrikanth Jampala 	vfcfg.s.cfg = mode & 0x7;
43641a9aca6SSrikanth Jampala 
43741a9aca6SSrikanth Jampala 	nitrox_write_csr(ndev, NPS_CORE_GBL_VFCFG, vfcfg.value);
43841a9aca6SSrikanth Jampala }
43948e10548SSrikanth Jampala 
440*bee7bdf1SNagadheeraj Rottela static const char *get_core_option(u8 se_cores, u8 ae_cores)
441*bee7bdf1SNagadheeraj Rottela {
442*bee7bdf1SNagadheeraj Rottela 	const char *option = "";
443*bee7bdf1SNagadheeraj Rottela 
444*bee7bdf1SNagadheeraj Rottela 	if (ae_cores == AE_MAX_CORES) {
445*bee7bdf1SNagadheeraj Rottela 		switch (se_cores) {
446*bee7bdf1SNagadheeraj Rottela 		case SE_MAX_CORES:
447*bee7bdf1SNagadheeraj Rottela 			option = "60";
448*bee7bdf1SNagadheeraj Rottela 			break;
449*bee7bdf1SNagadheeraj Rottela 		case 40:
450*bee7bdf1SNagadheeraj Rottela 			option = "60s";
451*bee7bdf1SNagadheeraj Rottela 			break;
452*bee7bdf1SNagadheeraj Rottela 		}
453*bee7bdf1SNagadheeraj Rottela 	} else if (ae_cores == (AE_MAX_CORES / 2)) {
454*bee7bdf1SNagadheeraj Rottela 		option = "30";
455*bee7bdf1SNagadheeraj Rottela 	} else {
456*bee7bdf1SNagadheeraj Rottela 		option = "60i";
457*bee7bdf1SNagadheeraj Rottela 	}
458*bee7bdf1SNagadheeraj Rottela 
459*bee7bdf1SNagadheeraj Rottela 	return option;
460*bee7bdf1SNagadheeraj Rottela }
461*bee7bdf1SNagadheeraj Rottela 
462*bee7bdf1SNagadheeraj Rottela static const char *get_feature_option(u8 zip_cores, int core_freq)
463*bee7bdf1SNagadheeraj Rottela {
464*bee7bdf1SNagadheeraj Rottela 	if (zip_cores == 0)
465*bee7bdf1SNagadheeraj Rottela 		return "";
466*bee7bdf1SNagadheeraj Rottela 	else if (zip_cores < ZIP_MAX_CORES)
467*bee7bdf1SNagadheeraj Rottela 		return "-C15";
468*bee7bdf1SNagadheeraj Rottela 
469*bee7bdf1SNagadheeraj Rottela 	if (core_freq >= 850)
470*bee7bdf1SNagadheeraj Rottela 		return "-C45";
471*bee7bdf1SNagadheeraj Rottela 	else if (core_freq >= 750)
472*bee7bdf1SNagadheeraj Rottela 		return "-C35";
473*bee7bdf1SNagadheeraj Rottela 	else if (core_freq >= 550)
474*bee7bdf1SNagadheeraj Rottela 		return "-C25";
475*bee7bdf1SNagadheeraj Rottela 
476*bee7bdf1SNagadheeraj Rottela 	return "";
477*bee7bdf1SNagadheeraj Rottela }
478*bee7bdf1SNagadheeraj Rottela 
47948e10548SSrikanth Jampala void nitrox_get_hwinfo(struct nitrox_device *ndev)
48048e10548SSrikanth Jampala {
48148e10548SSrikanth Jampala 	union emu_fuse_map emu_fuse;
48248e10548SSrikanth Jampala 	union rst_boot rst_boot;
48348e10548SSrikanth Jampala 	union fus_dat1 fus_dat1;
48448e10548SSrikanth Jampala 	unsigned char name[IFNAMSIZ * 2] = {};
48548e10548SSrikanth Jampala 	int i, dead_cores;
48648e10548SSrikanth Jampala 	u64 offset;
48748e10548SSrikanth Jampala 
48848e10548SSrikanth Jampala 	/* get core frequency */
48948e10548SSrikanth Jampala 	offset = RST_BOOT;
49048e10548SSrikanth Jampala 	rst_boot.value = nitrox_read_csr(ndev, offset);
49148e10548SSrikanth Jampala 	ndev->hw.freq = (rst_boot.pnr_mul + 3) * PLL_REF_CLK;
49248e10548SSrikanth Jampala 
49348e10548SSrikanth Jampala 	for (i = 0; i < NR_CLUSTERS; i++) {
49448e10548SSrikanth Jampala 		offset = EMU_FUSE_MAPX(i);
49548e10548SSrikanth Jampala 		emu_fuse.value = nitrox_read_csr(ndev, offset);
49648e10548SSrikanth Jampala 		if (emu_fuse.s.valid) {
49748e10548SSrikanth Jampala 			dead_cores = hweight32(emu_fuse.s.ae_fuse);
49848e10548SSrikanth Jampala 			ndev->hw.ae_cores += AE_CORES_PER_CLUSTER - dead_cores;
49948e10548SSrikanth Jampala 			dead_cores = hweight16(emu_fuse.s.se_fuse);
50048e10548SSrikanth Jampala 			ndev->hw.se_cores += SE_CORES_PER_CLUSTER - dead_cores;
50148e10548SSrikanth Jampala 		}
50248e10548SSrikanth Jampala 	}
50348e10548SSrikanth Jampala 	/* find zip hardware availability */
50448e10548SSrikanth Jampala 	offset = FUS_DAT1;
50548e10548SSrikanth Jampala 	fus_dat1.value = nitrox_read_csr(ndev, offset);
50648e10548SSrikanth Jampala 	if (!fus_dat1.nozip) {
50748e10548SSrikanth Jampala 		dead_cores = hweight8(fus_dat1.zip_info);
50848e10548SSrikanth Jampala 		ndev->hw.zip_cores = ZIP_MAX_CORES - dead_cores;
50948e10548SSrikanth Jampala 	}
51048e10548SSrikanth Jampala 
511*bee7bdf1SNagadheeraj Rottela 	/* determine the partname
512*bee7bdf1SNagadheeraj Rottela 	 * CNN55<core option>-<freq><pincount>-<feature option>-<rev>
513*bee7bdf1SNagadheeraj Rottela 	 */
514*bee7bdf1SNagadheeraj Rottela 	snprintf(name, sizeof(name), "CNN55%s-%3dBG676%s-1.%u",
515*bee7bdf1SNagadheeraj Rottela 		 get_core_option(ndev->hw.se_cores, ndev->hw.ae_cores),
516*bee7bdf1SNagadheeraj Rottela 		 ndev->hw.freq,
517*bee7bdf1SNagadheeraj Rottela 		 get_feature_option(ndev->hw.zip_cores, ndev->hw.freq),
518*bee7bdf1SNagadheeraj Rottela 		 ndev->hw.revision_id);
51948e10548SSrikanth Jampala 
52048e10548SSrikanth Jampala 	/* copy partname */
52148e10548SSrikanth Jampala 	strncpy(ndev->hw.partname, name, sizeof(ndev->hw.partname));
52248e10548SSrikanth Jampala }
523cf718eaaSSrikanth, Jampala 
524cf718eaaSSrikanth, Jampala void enable_pf2vf_mbox_interrupts(struct nitrox_device *ndev)
525cf718eaaSSrikanth, Jampala {
526cf718eaaSSrikanth, Jampala 	u64 value = ~0ULL;
527cf718eaaSSrikanth, Jampala 	u64 reg_addr;
528cf718eaaSSrikanth, Jampala 
529cf718eaaSSrikanth, Jampala 	/* Mailbox interrupt low enable set register */
530cf718eaaSSrikanth, Jampala 	reg_addr = NPS_PKT_MBOX_INT_LO_ENA_W1S;
531cf718eaaSSrikanth, Jampala 	nitrox_write_csr(ndev, reg_addr, value);
532cf718eaaSSrikanth, Jampala 
533cf718eaaSSrikanth, Jampala 	/* Mailbox interrupt high enable set register */
534cf718eaaSSrikanth, Jampala 	reg_addr = NPS_PKT_MBOX_INT_HI_ENA_W1S;
535cf718eaaSSrikanth, Jampala 	nitrox_write_csr(ndev, reg_addr, value);
536cf718eaaSSrikanth, Jampala }
537cf718eaaSSrikanth, Jampala 
538cf718eaaSSrikanth, Jampala void disable_pf2vf_mbox_interrupts(struct nitrox_device *ndev)
539cf718eaaSSrikanth, Jampala {
540cf718eaaSSrikanth, Jampala 	u64 value = ~0ULL;
541cf718eaaSSrikanth, Jampala 	u64 reg_addr;
542cf718eaaSSrikanth, Jampala 
543cf718eaaSSrikanth, Jampala 	/* Mailbox interrupt low enable clear register */
544cf718eaaSSrikanth, Jampala 	reg_addr = NPS_PKT_MBOX_INT_LO_ENA_W1C;
545cf718eaaSSrikanth, Jampala 	nitrox_write_csr(ndev, reg_addr, value);
546cf718eaaSSrikanth, Jampala 
547cf718eaaSSrikanth, Jampala 	/* Mailbox interrupt high enable clear register */
548cf718eaaSSrikanth, Jampala 	reg_addr = NPS_PKT_MBOX_INT_HI_ENA_W1C;
549cf718eaaSSrikanth, Jampala 	nitrox_write_csr(ndev, reg_addr, value);
550cf718eaaSSrikanth, Jampala }
551