hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/soc/fsl/qbman/bman_portal.c
....@@ -32,6 +32,7 @@
3232
3333 static struct bman_portal *affine_bportals[NR_CPUS];
3434 static struct cpumask portal_cpus;
35
+static int __bman_portals_probed;
3536 /* protect bman global registers and global data shared among portals */
3637 static DEFINE_SPINLOCK(bman_lock);
3738
....@@ -65,7 +66,9 @@
6566 if (!pcfg)
6667 return 0;
6768
68
- irq_set_affinity(pcfg->irq, cpumask_of(0));
69
+ /* use any other online CPU */
70
+ cpu = cpumask_any_but(cpu_online_mask, cpu);
71
+ irq_set_affinity(pcfg->irq, cpumask_of(cpu));
6972 return 0;
7073 }
7174
....@@ -85,13 +88,19 @@
8588 return 0;
8689 }
8790
91
+int bman_portals_probed(void)
92
+{
93
+ return __bman_portals_probed;
94
+}
95
+EXPORT_SYMBOL_GPL(bman_portals_probed);
96
+
8897 static int bman_portal_probe(struct platform_device *pdev)
8998 {
9099 struct device *dev = &pdev->dev;
91100 struct device_node *node = dev->of_node;
92101 struct bm_portal_config *pcfg;
93102 struct resource *addr_phys[2];
94
- int irq, cpu, err;
103
+ int irq, cpu, err, i;
95104
96105 err = bman_is_probed();
97106 if (!err)
....@@ -102,8 +111,10 @@
102111 }
103112
104113 pcfg = devm_kmalloc(dev, sizeof(*pcfg), GFP_KERNEL);
105
- if (!pcfg)
114
+ if (!pcfg) {
115
+ __bman_portals_probed = -1;
106116 return -ENOMEM;
117
+ }
107118
108119 pcfg->dev = dev;
109120
....@@ -111,23 +122,21 @@
111122 DPAA_PORTAL_CE);
112123 if (!addr_phys[0]) {
113124 dev_err(dev, "Can't get %pOF property 'reg::CE'\n", node);
114
- return -ENXIO;
125
+ goto err_ioremap1;
115126 }
116127
117128 addr_phys[1] = platform_get_resource(pdev, IORESOURCE_MEM,
118129 DPAA_PORTAL_CI);
119130 if (!addr_phys[1]) {
120131 dev_err(dev, "Can't get %pOF property 'reg::CI'\n", node);
121
- return -ENXIO;
132
+ goto err_ioremap1;
122133 }
123134
124135 pcfg->cpu = -1;
125136
126137 irq = platform_get_irq(pdev, 0);
127
- if (irq <= 0) {
128
- dev_err(dev, "Can't get %pOF IRQ'\n", node);
129
- return -ENXIO;
130
- }
138
+ if (irq <= 0)
139
+ goto err_ioremap1;
131140 pcfg->irq = irq;
132141
133142 pcfg->addr_virt_ce = memremap(addr_phys[0]->start,
....@@ -148,6 +157,7 @@
148157 spin_lock(&bman_lock);
149158 cpu = cpumask_next_zero(-1, &portal_cpus);
150159 if (cpu >= nr_cpu_ids) {
160
+ __bman_portals_probed = 1;
151161 /* unassigned portal, skip init */
152162 spin_unlock(&bman_lock);
153163 return 0;
....@@ -166,6 +176,22 @@
166176 if (!cpu_online(cpu))
167177 bman_offline_cpu(cpu);
168178
179
+ if (__bman_portals_probed == 1 && bman_requires_cleanup()) {
180
+ /*
181
+ * BMan wasn't reset prior to boot (Kexec for example)
182
+ * Empty all the buffer pools so they are in reset state
183
+ */
184
+ for (i = 0; i < BM_POOL_MAX; i++) {
185
+ err = bm_shutdown_pool(i);
186
+ if (err) {
187
+ dev_err(dev, "Failed to shutdown bpool %d\n",
188
+ i);
189
+ goto err_portal_init;
190
+ }
191
+ }
192
+ bman_done_cleanup();
193
+ }
194
+
169195 return 0;
170196
171197 err_portal_init:
....@@ -173,6 +199,8 @@
173199 err_ioremap2:
174200 memunmap(pcfg->addr_virt_ce);
175201 err_ioremap1:
202
+ __bman_portals_probed = -1;
203
+
176204 return -ENXIO;
177205 }
178206