dimm_devs.c (1b40e09a1232de537b193fa1b6b3ef16d3a1e397) dimm_devs.c (f524bf271a5cf12a44253194abcf8b6688ff5b9d)
1/*
2 * 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

--- 118 unchanged lines hidden (view full) ---

127 memcpy(ndd->data + offset, cmd->out_buf, cmd->in_length);
128 }
129 dev_dbg(ndd->dev, "%s: len: %zu rc: %d\n", __func__, offset, rc);
130 kfree(cmd);
131
132 return rc;
133}
134
1/*
2 * 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

--- 118 unchanged lines hidden (view full) ---

127 memcpy(ndd->data + offset, cmd->out_buf, cmd->in_length);
128 }
129 dev_dbg(ndd->dev, "%s: len: %zu rc: %d\n", __func__, offset, rc);
130 kfree(cmd);
131
132 return rc;
133}
134
135int nvdimm_set_config_data(struct nvdimm_drvdata *ndd, size_t offset,
136 void *buf, size_t len)
137{
138 int rc = validate_dimm(ndd);
139 size_t max_cmd_size, buf_offset;
140 struct nd_cmd_set_config_hdr *cmd;
141 struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(ndd->dev);
142 struct nvdimm_bus_descriptor *nd_desc = nvdimm_bus->nd_desc;
143
144 if (rc)
145 return rc;
146
147 if (!ndd->data)
148 return -ENXIO;
149
150 if (offset + len > ndd->nsarea.config_size)
151 return -ENXIO;
152
153 max_cmd_size = min_t(u32, PAGE_SIZE, len);
154 max_cmd_size = min_t(u32, max_cmd_size, ndd->nsarea.max_xfer);
155 cmd = kzalloc(max_cmd_size + sizeof(*cmd) + sizeof(u32), GFP_KERNEL);
156 if (!cmd)
157 return -ENOMEM;
158
159 for (buf_offset = 0; len; len -= cmd->in_length,
160 buf_offset += cmd->in_length) {
161 size_t cmd_size;
162 u32 *status;
163
164 cmd->in_offset = offset + buf_offset;
165 cmd->in_length = min(max_cmd_size, len);
166 memcpy(cmd->in_buf, buf + buf_offset, cmd->in_length);
167
168 /* status is output in the last 4-bytes of the command buffer */
169 cmd_size = sizeof(*cmd) + cmd->in_length + sizeof(u32);
170 status = ((void *) cmd) + cmd_size - sizeof(u32);
171
172 rc = nd_desc->ndctl(nd_desc, to_nvdimm(ndd->dev),
173 ND_CMD_SET_CONFIG_DATA, cmd, cmd_size);
174 if (rc || *status) {
175 rc = rc ? rc : -ENXIO;
176 break;
177 }
178 }
179 kfree(cmd);
180
181 return rc;
182}
183
135static void nvdimm_release(struct device *dev)
136{
137 struct nvdimm *nvdimm = to_nvdimm(dev);
138
139 ida_simple_remove(&dimm_ida, nvdimm->id);
140 kfree(nvdimm);
141}
142

--- 326 unchanged lines hidden ---
184static void nvdimm_release(struct device *dev)
185{
186 struct nvdimm *nvdimm = to_nvdimm(dev);
187
188 ida_simple_remove(&dimm_ida, nvdimm->id);
189 kfree(nvdimm);
190}
191

--- 326 unchanged lines hidden ---