Lines Matching +full:x +full:- +full:rc

1 // SPDX-License-Identifier: GPL-2.0-or-later
8 #define pr_fmt(fmt) "pseries-hotplug-mem: " fmt
26 kfree(prop->name); in dlpar_free_property()
27 kfree(prop->value); in dlpar_free_property()
40 new_prop->name = kstrdup(prop->name, GFP_KERNEL); in dlpar_clone_property()
41 new_prop->value = kzalloc(prop_size, GFP_KERNEL); in dlpar_clone_property()
42 if (!new_prop->name || !new_prop->value) { in dlpar_clone_property()
47 memcpy(new_prop->value, prop->value, prop->length); in dlpar_clone_property()
48 new_prop->length = prop_size; in dlpar_clone_property()
65 * The ibm,associativity-lookup-arrays property is defined to be in find_aa_index()
66 * a 32-bit value specifying the number of associativity arrays in find_aa_index()
67 * followed by a 32-bitvalue specifying the number of entries per in find_aa_index()
70 assoc_arrays = ala_prop->value; in find_aa_index()
86 new_prop_size = ala_prop->length + aa_array_sz; in find_aa_index()
91 assoc_arrays = new_prop->value; in find_aa_index()
104 * number of entries - 1 since we added its associativity in find_aa_index()
107 *aa_index = be32_to_cpu(assoc_arrays[0]) - 1; in find_aa_index()
121 return -ENODEV; in update_lmb_associativity_index()
123 lmb_node = dlpar_configure_connector(cpu_to_be32(lmb->drc_index), in update_lmb_associativity_index()
127 return -EINVAL; in update_lmb_associativity_index()
132 return -ENODEV; in update_lmb_associativity_index()
137 dr_node = of_find_node_by_path("/ibm,dynamic-reconfiguration-memory"); in update_lmb_associativity_index()
140 return -ENODEV; in update_lmb_associativity_index()
143 ala_prop = of_find_property(dr_node, "ibm,associativity-lookup-arrays", in update_lmb_associativity_index()
148 return -ENODEV; in update_lmb_associativity_index()
158 return -1; in update_lmb_associativity_index()
161 lmb->aa_index = aa_index; in update_lmb_associativity_index()
170 section_nr = pfn_to_section_nr(PFN_DOWN(lmb->base_addr)); in lmb_to_memblock()
185 if (lmb->drc_index == drc_index) { in get_lmb_range()
192 return -EINVAL; in get_lmb_range()
196 limit = &drmem_info->lmbs[drmem_info->n_lmbs]; in get_lmb_range()
198 return -EINVAL; in get_lmb_range()
208 int rc; in dlpar_change_lmb_state() local
212 pr_err("Failed memory block lookup for LMB 0x%x\n", lmb->drc_index); in dlpar_change_lmb_state()
213 return -EINVAL; in dlpar_change_lmb_state()
216 if (online && mem_block->dev.offline) in dlpar_change_lmb_state()
217 rc = device_online(&mem_block->dev); in dlpar_change_lmb_state()
218 else if (!online && !mem_block->dev.offline) in dlpar_change_lmb_state()
219 rc = device_offline(&mem_block->dev); in dlpar_change_lmb_state()
221 rc = 0; in dlpar_change_lmb_state()
223 put_device(&mem_block->dev); in dlpar_change_lmb_state()
225 return rc; in dlpar_change_lmb_state()
290 if ((lmb->flags & DRCONF_MEM_RESERVED) || in lmb_is_removable()
291 !(lmb->flags & DRCONF_MEM_ASSIGNED)) in lmb_is_removable()
296 * Don't hot-remove memory that falls in fadump boot memory area in lmb_is_removable()
299 if (is_fadump_memory_area(lmb->base_addr, memory_block_size_bytes())) in lmb_is_removable()
311 int rc; in dlpar_remove_lmb() local
314 return -EINVAL; in dlpar_remove_lmb()
318 return -EINVAL; in dlpar_remove_lmb()
320 rc = dlpar_offline_lmb(lmb); in dlpar_remove_lmb()
321 if (rc) { in dlpar_remove_lmb()
322 put_device(&mem_block->dev); in dlpar_remove_lmb()
323 return rc; in dlpar_remove_lmb()
326 __remove_memory(lmb->base_addr, memory_block_size); in dlpar_remove_lmb()
327 put_device(&mem_block->dev); in dlpar_remove_lmb()
330 memblock_remove(lmb->base_addr, memory_block_size); in dlpar_remove_lmb()
333 lmb->flags &= ~DRCONF_MEM_ASSIGNED; in dlpar_remove_lmb()
343 int rc; in dlpar_memory_remove_by_count() local
345 pr_info("Attempting to hot-remove %d LMB(s)\n", lmbs_to_remove); in dlpar_memory_remove_by_count()
348 return -EINVAL; in dlpar_memory_remove_by_count()
362 return -EINVAL; in dlpar_memory_remove_by_count()
366 rc = dlpar_remove_lmb(lmb); in dlpar_memory_remove_by_count()
367 if (rc) in dlpar_memory_remove_by_count()
381 pr_err("Memory hot-remove failed, adding LMB's back\n"); in dlpar_memory_remove_by_count()
387 rc = dlpar_add_lmb(lmb); in dlpar_memory_remove_by_count()
388 if (rc) in dlpar_memory_remove_by_count()
389 pr_err("Failed to add LMB back, drc index %x\n", in dlpar_memory_remove_by_count()
390 lmb->drc_index); in dlpar_memory_remove_by_count()
394 lmbs_reserved--; in dlpar_memory_remove_by_count()
399 rc = -EINVAL; in dlpar_memory_remove_by_count()
405 dlpar_release_drc(lmb->drc_index); in dlpar_memory_remove_by_count()
406 pr_info("Memory at %llx was hot-removed\n", in dlpar_memory_remove_by_count()
407 lmb->base_addr); in dlpar_memory_remove_by_count()
411 lmbs_reserved--; in dlpar_memory_remove_by_count()
415 rc = 0; in dlpar_memory_remove_by_count()
418 return rc; in dlpar_memory_remove_by_count()
425 int rc; in dlpar_memory_remove_by_index() local
427 pr_debug("Attempting to hot-remove LMB, drc index %x\n", drc_index); in dlpar_memory_remove_by_index()
431 if (lmb->drc_index == drc_index) { in dlpar_memory_remove_by_index()
433 rc = dlpar_remove_lmb(lmb); in dlpar_memory_remove_by_index()
434 if (!rc) in dlpar_memory_remove_by_index()
435 dlpar_release_drc(lmb->drc_index); in dlpar_memory_remove_by_index()
442 pr_debug("Failed to look up LMB for drc index %x\n", drc_index); in dlpar_memory_remove_by_index()
443 rc = -EINVAL; in dlpar_memory_remove_by_index()
444 } else if (rc) { in dlpar_memory_remove_by_index()
445 pr_debug("Failed to hot-remove memory at %llx\n", in dlpar_memory_remove_by_index()
446 lmb->base_addr); in dlpar_memory_remove_by_index()
448 pr_debug("Memory at %llx was hot-removed\n", lmb->base_addr); in dlpar_memory_remove_by_index()
451 return rc; in dlpar_memory_remove_by_index()
457 int rc; in dlpar_memory_remove_by_ic() local
459 pr_info("Attempting to hot-remove %u LMB(s) at %x\n", in dlpar_memory_remove_by_ic()
463 return -EINVAL; in dlpar_memory_remove_by_ic()
465 rc = get_lmb_range(drc_index, lmbs_to_remove, &start_lmb, &end_lmb); in dlpar_memory_remove_by_ic()
466 if (rc) in dlpar_memory_remove_by_ic()
467 return -EINVAL; in dlpar_memory_remove_by_ic()
480 if (lmb->flags & DRCONF_MEM_RESERVED) { in dlpar_memory_remove_by_ic()
481 pr_err("Memory at %llx (drc index %x) is reserved\n", in dlpar_memory_remove_by_ic()
482 lmb->base_addr, lmb->drc_index); in dlpar_memory_remove_by_ic()
483 return -EINVAL; in dlpar_memory_remove_by_ic()
490 * !ASSIGNED, but this case is a no-op for us. in dlpar_memory_remove_by_ic()
492 if (!(lmb->flags & DRCONF_MEM_ASSIGNED)) in dlpar_memory_remove_by_ic()
495 rc = dlpar_remove_lmb(lmb); in dlpar_memory_remove_by_ic()
496 if (rc) in dlpar_memory_remove_by_ic()
502 if (rc) { in dlpar_memory_remove_by_ic()
503 pr_err("Memory indexed-count-remove failed, adding any removed LMBs\n"); in dlpar_memory_remove_by_ic()
512 * device to UNISOLATE is a no-op, but the hypervisor can in dlpar_memory_remove_by_ic()
515 dlpar_unisolate_drc(lmb->drc_index); in dlpar_memory_remove_by_ic()
517 rc = dlpar_add_lmb(lmb); in dlpar_memory_remove_by_ic()
518 if (rc) in dlpar_memory_remove_by_ic()
519 pr_err("Failed to add LMB, drc index %x\n", in dlpar_memory_remove_by_ic()
520 lmb->drc_index); in dlpar_memory_remove_by_ic()
524 rc = -EINVAL; in dlpar_memory_remove_by_ic()
530 dlpar_release_drc(lmb->drc_index); in dlpar_memory_remove_by_ic()
531 pr_info("Memory at %llx (drc index %x) was hot-removed\n", in dlpar_memory_remove_by_ic()
532 lmb->base_addr, lmb->drc_index); in dlpar_memory_remove_by_ic()
538 return rc; in dlpar_memory_remove_by_ic()
545 return -EOPNOTSUPP; in pseries_remove_memblock()
553 return -EOPNOTSUPP; in dlpar_remove_lmb()
557 return -EOPNOTSUPP; in dlpar_memory_remove_by_count()
561 return -EOPNOTSUPP; in dlpar_memory_remove_by_index()
566 return -EOPNOTSUPP; in dlpar_memory_remove_by_ic()
573 int nid, rc; in dlpar_add_lmb() local
575 if (lmb->flags & DRCONF_MEM_ASSIGNED) in dlpar_add_lmb()
576 return -EINVAL; in dlpar_add_lmb()
578 rc = update_lmb_associativity_index(lmb); in dlpar_add_lmb()
579 if (rc) { in dlpar_add_lmb()
580 dlpar_release_drc(lmb->drc_index); in dlpar_add_lmb()
581 pr_err("Failed to configure LMB 0x%x\n", lmb->drc_index); in dlpar_add_lmb()
582 return rc; in dlpar_add_lmb()
593 rc = __add_memory(nid, lmb->base_addr, block_sz, MHP_MEMMAP_ON_MEMORY); in dlpar_add_lmb()
594 if (rc) { in dlpar_add_lmb()
595 pr_err("Failed to add LMB 0x%x to node %u", lmb->drc_index, nid); in dlpar_add_lmb()
597 return rc; in dlpar_add_lmb()
600 rc = dlpar_online_lmb(lmb); in dlpar_add_lmb()
601 if (rc) { in dlpar_add_lmb()
602 pr_err("Failed to online LMB 0x%x on node %u\n", lmb->drc_index, nid); in dlpar_add_lmb()
603 __remove_memory(lmb->base_addr, block_sz); in dlpar_add_lmb()
606 lmb->flags |= DRCONF_MEM_ASSIGNED; in dlpar_add_lmb()
609 return rc; in dlpar_add_lmb()
617 int rc; in dlpar_memory_add_by_count() local
619 pr_info("Attempting to hot-add %d LMB(s)\n", lmbs_to_add); in dlpar_memory_add_by_count()
622 return -EINVAL; in dlpar_memory_add_by_count()
626 if (lmb->flags & DRCONF_MEM_RESERVED) in dlpar_memory_add_by_count()
629 if (!(lmb->flags & DRCONF_MEM_ASSIGNED)) in dlpar_memory_add_by_count()
637 return -EINVAL; in dlpar_memory_add_by_count()
640 if (lmb->flags & DRCONF_MEM_ASSIGNED) in dlpar_memory_add_by_count()
643 rc = dlpar_acquire_drc(lmb->drc_index); in dlpar_memory_add_by_count()
644 if (rc) in dlpar_memory_add_by_count()
647 rc = dlpar_add_lmb(lmb); in dlpar_memory_add_by_count()
648 if (rc) { in dlpar_memory_add_by_count()
649 dlpar_release_drc(lmb->drc_index); in dlpar_memory_add_by_count()
663 pr_err("Memory hot-add failed, removing any added LMBs\n"); in dlpar_memory_add_by_count()
669 rc = dlpar_remove_lmb(lmb); in dlpar_memory_add_by_count()
670 if (rc) in dlpar_memory_add_by_count()
671 pr_err("Failed to remove LMB, drc index %x\n", in dlpar_memory_add_by_count()
672 lmb->drc_index); in dlpar_memory_add_by_count()
674 dlpar_release_drc(lmb->drc_index); in dlpar_memory_add_by_count()
677 lmbs_reserved--; in dlpar_memory_add_by_count()
682 rc = -EINVAL; in dlpar_memory_add_by_count()
688 pr_debug("Memory at %llx (drc index %x) was hot-added\n", in dlpar_memory_add_by_count()
689 lmb->base_addr, lmb->drc_index); in dlpar_memory_add_by_count()
691 lmbs_reserved--; in dlpar_memory_add_by_count()
696 rc = 0; in dlpar_memory_add_by_count()
699 return rc; in dlpar_memory_add_by_count()
705 int rc, lmb_found; in dlpar_memory_add_by_index() local
707 pr_info("Attempting to hot-add LMB, drc index %x\n", drc_index); in dlpar_memory_add_by_index()
711 if (lmb->drc_index == drc_index) { in dlpar_memory_add_by_index()
713 rc = dlpar_acquire_drc(lmb->drc_index); in dlpar_memory_add_by_index()
714 if (!rc) { in dlpar_memory_add_by_index()
715 rc = dlpar_add_lmb(lmb); in dlpar_memory_add_by_index()
716 if (rc) in dlpar_memory_add_by_index()
717 dlpar_release_drc(lmb->drc_index); in dlpar_memory_add_by_index()
725 rc = -EINVAL; in dlpar_memory_add_by_index()
727 if (rc) in dlpar_memory_add_by_index()
728 pr_info("Failed to hot-add memory, drc index %x\n", drc_index); in dlpar_memory_add_by_index()
730 pr_info("Memory at %llx (drc index %x) was hot-added\n", in dlpar_memory_add_by_index()
731 lmb->base_addr, drc_index); in dlpar_memory_add_by_index()
733 return rc; in dlpar_memory_add_by_index()
739 int rc; in dlpar_memory_add_by_ic() local
741 pr_info("Attempting to hot-add %u LMB(s) at index %x\n", in dlpar_memory_add_by_ic()
745 return -EINVAL; in dlpar_memory_add_by_ic()
747 rc = get_lmb_range(drc_index, lmbs_to_add, &start_lmb, &end_lmb); in dlpar_memory_add_by_ic()
748 if (rc) in dlpar_memory_add_by_ic()
749 return -EINVAL; in dlpar_memory_add_by_ic()
753 /* Fail immediately if the whole range can't be hot-added */ in dlpar_memory_add_by_ic()
754 if (lmb->flags & DRCONF_MEM_RESERVED) { in dlpar_memory_add_by_ic()
755 pr_err("Memory at %llx (drc index %x) is reserved\n", in dlpar_memory_add_by_ic()
756 lmb->base_addr, lmb->drc_index); in dlpar_memory_add_by_ic()
757 return -EINVAL; in dlpar_memory_add_by_ic()
762 if (lmb->flags & DRCONF_MEM_ASSIGNED) in dlpar_memory_add_by_ic()
765 rc = dlpar_acquire_drc(lmb->drc_index); in dlpar_memory_add_by_ic()
766 if (rc) in dlpar_memory_add_by_ic()
769 rc = dlpar_add_lmb(lmb); in dlpar_memory_add_by_ic()
770 if (rc) { in dlpar_memory_add_by_ic()
771 dlpar_release_drc(lmb->drc_index); in dlpar_memory_add_by_ic()
778 if (rc) { in dlpar_memory_add_by_ic()
779 pr_err("Memory indexed-count-add failed, removing any added LMBs\n"); in dlpar_memory_add_by_ic()
785 rc = dlpar_remove_lmb(lmb); in dlpar_memory_add_by_ic()
786 if (rc) in dlpar_memory_add_by_ic()
787 pr_err("Failed to remove LMB, drc index %x\n", in dlpar_memory_add_by_ic()
788 lmb->drc_index); in dlpar_memory_add_by_ic()
790 dlpar_release_drc(lmb->drc_index); in dlpar_memory_add_by_ic()
794 rc = -EINVAL; in dlpar_memory_add_by_ic()
800 pr_info("Memory at %llx (drc index %x) was hot-added\n", in dlpar_memory_add_by_ic()
801 lmb->base_addr, lmb->drc_index); in dlpar_memory_add_by_ic()
806 return rc; in dlpar_memory_add_by_ic()
812 int rc; in dlpar_memory() local
816 switch (hp_elog->action) { in dlpar_memory()
818 switch (hp_elog->id_type) { in dlpar_memory()
820 count = be32_to_cpu(hp_elog->_drc_u.drc_count); in dlpar_memory()
821 rc = dlpar_memory_add_by_count(count); in dlpar_memory()
824 drc_index = be32_to_cpu(hp_elog->_drc_u.drc_index); in dlpar_memory()
825 rc = dlpar_memory_add_by_index(drc_index); in dlpar_memory()
828 count = be32_to_cpu(hp_elog->_drc_u.ic.count); in dlpar_memory()
829 drc_index = be32_to_cpu(hp_elog->_drc_u.ic.index); in dlpar_memory()
830 rc = dlpar_memory_add_by_ic(count, drc_index); in dlpar_memory()
833 rc = -EINVAL; in dlpar_memory()
839 switch (hp_elog->id_type) { in dlpar_memory()
841 count = be32_to_cpu(hp_elog->_drc_u.drc_count); in dlpar_memory()
842 rc = dlpar_memory_remove_by_count(count); in dlpar_memory()
845 drc_index = be32_to_cpu(hp_elog->_drc_u.drc_index); in dlpar_memory()
846 rc = dlpar_memory_remove_by_index(drc_index); in dlpar_memory()
849 count = be32_to_cpu(hp_elog->_drc_u.ic.count); in dlpar_memory()
850 drc_index = be32_to_cpu(hp_elog->_drc_u.ic.index); in dlpar_memory()
851 rc = dlpar_memory_remove_by_ic(count, drc_index); in dlpar_memory()
854 rc = -EINVAL; in dlpar_memory()
860 pr_err("Invalid action (%d) specified\n", hp_elog->action); in dlpar_memory()
861 rc = -EINVAL; in dlpar_memory()
865 if (!rc) in dlpar_memory()
866 rc = drmem_update_dt(); in dlpar_memory()
869 return rc; in dlpar_memory()
894 return (ret < 0) ? -EINVAL : 0; in pseries_add_mem_node()
905 err = pseries_add_mem_node(rd->dn); in pseries_memory_notifier()
908 err = pseries_remove_mem_node(rd->dn); in pseries_memory_notifier()
911 if (!strcmp(rd->dn->name, in pseries_memory_notifier()
912 "ibm,dynamic-reconfiguration-memory")) in pseries_memory_notifier()
913 drmem_update_lmbs(rd->prop); in pseries_memory_notifier()