| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright(c) 2013-2015 Intel Corporation. All rights reserved. |
|---|
| 3 | | - * |
|---|
| 4 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 5 | | - * it under the terms of version 2 of the GNU General Public License as |
|---|
| 6 | | - * published by the Free Software Foundation. |
|---|
| 7 | | - * |
|---|
| 8 | | - * This program is distributed in the hope that it will be useful, but |
|---|
| 9 | | - * WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 10 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 11 | | - * General Public License for more details. |
|---|
| 12 | 4 | */ |
|---|
| 13 | 5 | #include <linux/vmalloc.h> |
|---|
| 14 | 6 | #include <linux/module.h> |
|---|
| .. | .. |
|---|
| 26 | 18 | struct nvdimm_drvdata *ndd; |
|---|
| 27 | 19 | int rc; |
|---|
| 28 | 20 | |
|---|
| 21 | + rc = nvdimm_security_setup_events(dev); |
|---|
| 22 | + if (rc < 0) { |
|---|
| 23 | + dev_err(dev, "security event setup failed: %d\n", rc); |
|---|
| 24 | + return rc; |
|---|
| 25 | + } |
|---|
| 26 | + |
|---|
| 29 | 27 | rc = nvdimm_check_config_data(dev); |
|---|
| 30 | 28 | if (rc) { |
|---|
| 31 | 29 | /* not required for non-aliased nvdimm, ex. NVDIMM-N */ |
|---|
| .. | .. |
|---|
| 34 | 32 | return rc; |
|---|
| 35 | 33 | } |
|---|
| 36 | 34 | |
|---|
| 37 | | - /* reset locked, to be validated below... */ |
|---|
| 35 | + /* |
|---|
| 36 | + * The locked status bit reflects explicit status codes from the |
|---|
| 37 | + * label reading commands, revalidate it each time the driver is |
|---|
| 38 | + * activated and re-reads the label area. |
|---|
| 39 | + */ |
|---|
| 38 | 40 | nvdimm_clear_locked(dev); |
|---|
| 39 | 41 | |
|---|
| 40 | 42 | ndd = kzalloc(sizeof(*ndd), GFP_KERNEL); |
|---|
| .. | .. |
|---|
| 50 | 52 | ndd->dev = dev; |
|---|
| 51 | 53 | get_device(dev); |
|---|
| 52 | 54 | kref_init(&ndd->kref); |
|---|
| 55 | + |
|---|
| 56 | + /* |
|---|
| 57 | + * Attempt to unlock, if the DIMM supports security commands, |
|---|
| 58 | + * otherwise the locked indication is determined by explicit |
|---|
| 59 | + * status codes from the label reading commands. |
|---|
| 60 | + */ |
|---|
| 61 | + rc = nvdimm_security_unlock(dev); |
|---|
| 62 | + if (rc < 0) |
|---|
| 63 | + dev_dbg(dev, "failed to unlock dimm: %d\n", rc); |
|---|
| 64 | + |
|---|
| 53 | 65 | |
|---|
| 54 | 66 | /* |
|---|
| 55 | 67 | * EACCES failures reading the namespace label-area-properties |
|---|
| .. | .. |
|---|
| 75 | 87 | * DIMM capacity. We fail the dimm probe to prevent regions from |
|---|
| 76 | 88 | * attempting to parse the label area. |
|---|
| 77 | 89 | */ |
|---|
| 78 | | - rc = nvdimm_init_config_data(ndd); |
|---|
| 90 | + rc = nd_label_data_init(ndd); |
|---|
| 79 | 91 | if (rc == -EACCES) |
|---|
| 80 | 92 | nvdimm_set_locked(dev); |
|---|
| 81 | 93 | if (rc) |
|---|
| .. | .. |
|---|
| 84 | 96 | dev_dbg(dev, "config data size: %d\n", ndd->nsarea.config_size); |
|---|
| 85 | 97 | |
|---|
| 86 | 98 | nvdimm_bus_lock(dev); |
|---|
| 87 | | - ndd->ns_current = nd_label_validate(ndd); |
|---|
| 88 | | - ndd->ns_next = nd_label_next_nsindex(ndd->ns_current); |
|---|
| 89 | | - nd_label_copy(ndd, to_next_namespace_index(ndd), |
|---|
| 90 | | - to_current_namespace_index(ndd)); |
|---|
| 91 | 99 | if (ndd->ns_current >= 0) { |
|---|
| 92 | 100 | rc = nd_label_reserve_dpa(ndd); |
|---|
| 93 | 101 | if (rc == 0) |
|---|
| 94 | | - nvdimm_set_aliasing(dev); |
|---|
| 102 | + nvdimm_set_labeling(dev); |
|---|
| 95 | 103 | } |
|---|
| 96 | 104 | nvdimm_bus_unlock(dev); |
|---|
| 97 | 105 | |
|---|