2 * Copyright(c) 2015 EZchip Technologies.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * The full GNU General Public License is included in this distribution in
14 * the file called "COPYING".
17 #include <linux/smp.h>
19 #include <linux/log2.h>
20 #include <asm/arcregs.h>
24 #define MT_HS_CNT_MIN 0x01
25 #define MT_HS_CNT_MAX 0xFF
26 #define MT_CTRL_ST_CNT 0xF
27 #define NPS_NUM_HW_THREADS 0x10
29 static int mtm_hs_ctr
= MT_HS_CNT_MAX
;
31 #ifdef CONFIG_EZNPS_MEM_ERROR_ALIGN
32 int do_memory_error(unsigned long address
, struct pt_regs
*regs
)
34 die("Invalid Mem Access", regs
, address
);
40 static void mtm_init_nat(int cpu
)
42 struct nps_host_reg_mtm_cfg mtm_cfg
;
43 struct nps_host_reg_aux_udmc udmc
;
44 int log_nat
, nat
= 0, i
, t
;
46 /* Iterate core threads and update nat */
47 for (i
= 0, t
= cpu
; i
< NPS_NUM_HW_THREADS
; i
++, t
++)
48 nat
+= test_bit(t
, cpumask_bits(cpu_possible_mask
));
52 udmc
.value
= read_aux_reg(CTOP_AUX_UDMC
);
54 write_aux_reg(CTOP_AUX_UDMC
, udmc
.value
);
56 mtm_cfg
.value
= ioread32be(MTM_CFG(cpu
));
57 mtm_cfg
.nat
= log_nat
;
58 iowrite32be(mtm_cfg
.value
, MTM_CFG(cpu
));
61 static void mtm_init_thread(int cpu
)
64 struct nps_host_reg_thr_init thr_init
;
65 struct nps_host_reg_thr_init_sts thr_init_sts
;
67 /* Set thread init register */
69 iowrite32be(thr_init
.value
, MTM_THR_INIT(cpu
));
70 thr_init
.thr_id
= NPS_CPU_TO_THREAD_NUM(cpu
);
72 iowrite32be(thr_init
.value
, MTM_THR_INIT(cpu
));
74 /* Poll till thread init is done */
75 for (i
= 0; i
< tries
; i
++) {
76 thr_init_sts
.value
= ioread32be(MTM_THR_INIT_STS(cpu
));
77 if (thr_init_sts
.thr_id
== thr_init
.thr_id
) {
80 else if (thr_init_sts
.err
)
81 pr_warn("Failed to thread init cpu %u\n", cpu
);
85 pr_warn("Wrong thread id in thread init for cpu %u\n", cpu
);
90 pr_warn("Got thread init timeout for cpu %u\n", cpu
);
93 int mtm_enable_thread(int cpu
)
95 struct nps_host_reg_mtm_cfg mtm_cfg
;
97 if (NPS_CPU_TO_THREAD_NUM(cpu
) == 0)
100 /* Enable thread in mtm */
101 mtm_cfg
.value
= ioread32be(MTM_CFG(cpu
));
102 mtm_cfg
.ten
|= (1 << (NPS_CPU_TO_THREAD_NUM(cpu
)));
103 iowrite32be(mtm_cfg
.value
, MTM_CFG(cpu
));
108 void mtm_enable_core(unsigned int cpu
)
111 struct nps_host_reg_aux_mt_ctrl mt_ctrl
;
112 struct nps_host_reg_mtm_cfg mtm_cfg
;
113 struct nps_host_reg_aux_dpc dpc
;
116 * Initializing dpc register in each CPU.
117 * Overwriting the init value of the DPC
118 * register so that CMEM and FMT virtual address
119 * spaces are accessible, and Data Plane HW
120 * facilities are enabled.
124 write_aux_reg(CTOP_AUX_DPC
, dpc
.value
);
126 if (NPS_CPU_TO_THREAD_NUM(cpu
) != 0)
129 /* Initialize Number of Active Threads */
132 /* Initialize mtm_cfg */
133 mtm_cfg
.value
= ioread32be(MTM_CFG(cpu
));
135 iowrite32be(mtm_cfg
.value
, MTM_CFG(cpu
));
137 /* Initialize all other threads in core */
138 for (i
= 1; i
< NPS_NUM_HW_THREADS
; i
++)
139 mtm_init_thread(cpu
+ i
);
142 /* Enable HW schedule, stall counter, mtm */
145 mt_ctrl
.hs_cnt
= mtm_hs_ctr
;
147 write_aux_reg(CTOP_AUX_MT_CTRL
, mt_ctrl
.value
);
150 * HW scheduling mechanism will start working
151 * Only after call to instruction "schd.rw".
152 * cpu_relax() calls "schd.rw" instruction.
157 /* Verify and set the value of the mtm hs counter */
158 static int __init
set_mtm_hs_ctr(char *ctr_str
)
163 ret
= kstrtol(ctr_str
, 0, &hs_ctr
);
165 if (ret
|| hs_ctr
> MT_HS_CNT_MAX
|| hs_ctr
< MT_HS_CNT_MIN
) {
166 pr_err("** Invalid @nps_mtm_hs_ctr [%d] needs to be [%d:%d] (incl)\n",
167 hs_ctr
, MT_HS_CNT_MIN
, MT_HS_CNT_MAX
);
175 early_param("nps_mtm_hs_ctr", set_mtm_hs_ctr
);