| .. | .. |
|---|
| 32 | 32 | |
|---|
| 33 | 33 | static struct bman_portal *affine_bportals[NR_CPUS]; |
|---|
| 34 | 34 | static struct cpumask portal_cpus; |
|---|
| 35 | +static int __bman_portals_probed; |
|---|
| 35 | 36 | /* protect bman global registers and global data shared among portals */ |
|---|
| 36 | 37 | static DEFINE_SPINLOCK(bman_lock); |
|---|
| 37 | 38 | |
|---|
| .. | .. |
|---|
| 65 | 66 | if (!pcfg) |
|---|
| 66 | 67 | return 0; |
|---|
| 67 | 68 | |
|---|
| 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)); |
|---|
| 69 | 72 | return 0; |
|---|
| 70 | 73 | } |
|---|
| 71 | 74 | |
|---|
| .. | .. |
|---|
| 85 | 88 | return 0; |
|---|
| 86 | 89 | } |
|---|
| 87 | 90 | |
|---|
| 91 | +int bman_portals_probed(void) |
|---|
| 92 | +{ |
|---|
| 93 | + return __bman_portals_probed; |
|---|
| 94 | +} |
|---|
| 95 | +EXPORT_SYMBOL_GPL(bman_portals_probed); |
|---|
| 96 | + |
|---|
| 88 | 97 | static int bman_portal_probe(struct platform_device *pdev) |
|---|
| 89 | 98 | { |
|---|
| 90 | 99 | struct device *dev = &pdev->dev; |
|---|
| 91 | 100 | struct device_node *node = dev->of_node; |
|---|
| 92 | 101 | struct bm_portal_config *pcfg; |
|---|
| 93 | 102 | struct resource *addr_phys[2]; |
|---|
| 94 | | - int irq, cpu, err; |
|---|
| 103 | + int irq, cpu, err, i; |
|---|
| 95 | 104 | |
|---|
| 96 | 105 | err = bman_is_probed(); |
|---|
| 97 | 106 | if (!err) |
|---|
| .. | .. |
|---|
| 102 | 111 | } |
|---|
| 103 | 112 | |
|---|
| 104 | 113 | pcfg = devm_kmalloc(dev, sizeof(*pcfg), GFP_KERNEL); |
|---|
| 105 | | - if (!pcfg) |
|---|
| 114 | + if (!pcfg) { |
|---|
| 115 | + __bman_portals_probed = -1; |
|---|
| 106 | 116 | return -ENOMEM; |
|---|
| 117 | + } |
|---|
| 107 | 118 | |
|---|
| 108 | 119 | pcfg->dev = dev; |
|---|
| 109 | 120 | |
|---|
| .. | .. |
|---|
| 111 | 122 | DPAA_PORTAL_CE); |
|---|
| 112 | 123 | if (!addr_phys[0]) { |
|---|
| 113 | 124 | dev_err(dev, "Can't get %pOF property 'reg::CE'\n", node); |
|---|
| 114 | | - return -ENXIO; |
|---|
| 125 | + goto err_ioremap1; |
|---|
| 115 | 126 | } |
|---|
| 116 | 127 | |
|---|
| 117 | 128 | addr_phys[1] = platform_get_resource(pdev, IORESOURCE_MEM, |
|---|
| 118 | 129 | DPAA_PORTAL_CI); |
|---|
| 119 | 130 | if (!addr_phys[1]) { |
|---|
| 120 | 131 | dev_err(dev, "Can't get %pOF property 'reg::CI'\n", node); |
|---|
| 121 | | - return -ENXIO; |
|---|
| 132 | + goto err_ioremap1; |
|---|
| 122 | 133 | } |
|---|
| 123 | 134 | |
|---|
| 124 | 135 | pcfg->cpu = -1; |
|---|
| 125 | 136 | |
|---|
| 126 | 137 | 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; |
|---|
| 131 | 140 | pcfg->irq = irq; |
|---|
| 132 | 141 | |
|---|
| 133 | 142 | pcfg->addr_virt_ce = memremap(addr_phys[0]->start, |
|---|
| .. | .. |
|---|
| 148 | 157 | spin_lock(&bman_lock); |
|---|
| 149 | 158 | cpu = cpumask_next_zero(-1, &portal_cpus); |
|---|
| 150 | 159 | if (cpu >= nr_cpu_ids) { |
|---|
| 160 | + __bman_portals_probed = 1; |
|---|
| 151 | 161 | /* unassigned portal, skip init */ |
|---|
| 152 | 162 | spin_unlock(&bman_lock); |
|---|
| 153 | 163 | return 0; |
|---|
| .. | .. |
|---|
| 166 | 176 | if (!cpu_online(cpu)) |
|---|
| 167 | 177 | bman_offline_cpu(cpu); |
|---|
| 168 | 178 | |
|---|
| 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 | + |
|---|
| 169 | 195 | return 0; |
|---|
| 170 | 196 | |
|---|
| 171 | 197 | err_portal_init: |
|---|
| .. | .. |
|---|
| 173 | 199 | err_ioremap2: |
|---|
| 174 | 200 | memunmap(pcfg->addr_virt_ce); |
|---|
| 175 | 201 | err_ioremap1: |
|---|
| 202 | + __bman_portals_probed = -1; |
|---|
| 203 | + |
|---|
| 176 | 204 | return -ENXIO; |
|---|
| 177 | 205 | } |
|---|
| 178 | 206 | |
|---|