Lines Matching +full:dev +full:- +full:ctrl
1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (c) 2011-2014, Intel Corporation.
8 #include <linux/nvme-auth.h>
13 static ssize_t nvme_sysfs_reset(struct device *dev, in nvme_sysfs_reset() argument
17 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_sysfs_reset() local
20 ret = nvme_reset_ctrl_sync(ctrl); in nvme_sysfs_reset()
27 static ssize_t nvme_sysfs_rescan(struct device *dev, in nvme_sysfs_rescan() argument
31 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_sysfs_rescan() local
33 nvme_queue_scan(ctrl); in nvme_sysfs_rescan()
38 static inline struct nvme_ns_head *dev_to_ns_head(struct device *dev) in dev_to_ns_head() argument
40 struct gendisk *disk = dev_to_disk(dev); in dev_to_ns_head()
42 if (disk->fops == &nvme_bdev_ops) in dev_to_ns_head()
43 return nvme_get_ns_from_dev(dev)->head; in dev_to_ns_head()
45 return disk->private_data; in dev_to_ns_head()
48 static ssize_t wwid_show(struct device *dev, struct device_attribute *attr, in wwid_show() argument
51 struct nvme_ns_head *head = dev_to_ns_head(dev); in wwid_show()
52 struct nvme_ns_ids *ids = &head->ids; in wwid_show()
53 struct nvme_subsystem *subsys = head->subsys; in wwid_show()
54 int serial_len = sizeof(subsys->serial); in wwid_show()
55 int model_len = sizeof(subsys->model); in wwid_show()
57 if (!uuid_is_null(&ids->uuid)) in wwid_show()
58 return sysfs_emit(buf, "uuid.%pU\n", &ids->uuid); in wwid_show()
60 if (memchr_inv(ids->nguid, 0, sizeof(ids->nguid))) in wwid_show()
61 return sysfs_emit(buf, "eui.%16phN\n", ids->nguid); in wwid_show()
63 if (memchr_inv(ids->eui64, 0, sizeof(ids->eui64))) in wwid_show()
64 return sysfs_emit(buf, "eui.%8phN\n", ids->eui64); in wwid_show()
66 while (serial_len > 0 && (subsys->serial[serial_len - 1] == ' ' || in wwid_show()
67 subsys->serial[serial_len - 1] == '\0')) in wwid_show()
68 serial_len--; in wwid_show()
69 while (model_len > 0 && (subsys->model[model_len - 1] == ' ' || in wwid_show()
70 subsys->model[model_len - 1] == '\0')) in wwid_show()
71 model_len--; in wwid_show()
73 return sysfs_emit(buf, "nvme.%04x-%*phN-%*phN-%08x\n", subsys->vendor_id, in wwid_show()
74 serial_len, subsys->serial, model_len, subsys->model, in wwid_show()
75 head->ns_id); in wwid_show()
79 static ssize_t nguid_show(struct device *dev, struct device_attribute *attr, in nguid_show() argument
82 return sysfs_emit(buf, "%pU\n", dev_to_ns_head(dev)->ids.nguid); in nguid_show()
86 static ssize_t uuid_show(struct device *dev, struct device_attribute *attr, in uuid_show() argument
89 struct nvme_ns_ids *ids = &dev_to_ns_head(dev)->ids; in uuid_show()
94 if (uuid_is_null(&ids->uuid)) { in uuid_show()
95 dev_warn_once(dev, in uuid_show()
97 return sysfs_emit(buf, "%pU\n", ids->nguid); in uuid_show()
99 return sysfs_emit(buf, "%pU\n", &ids->uuid); in uuid_show()
103 static ssize_t eui_show(struct device *dev, struct device_attribute *attr, in eui_show() argument
106 return sysfs_emit(buf, "%8ph\n", dev_to_ns_head(dev)->ids.eui64); in eui_show()
110 static ssize_t nsid_show(struct device *dev, struct device_attribute *attr, in nsid_show() argument
113 return sysfs_emit(buf, "%d\n", dev_to_ns_head(dev)->ns_id); in nsid_show()
133 struct device *dev = container_of(kobj, struct device, kobj); in nvme_ns_id_attrs_are_visible() local
134 struct nvme_ns_ids *ids = &dev_to_ns_head(dev)->ids; in nvme_ns_id_attrs_are_visible()
137 if (uuid_is_null(&ids->uuid) && in nvme_ns_id_attrs_are_visible()
138 !memchr_inv(ids->nguid, 0, sizeof(ids->nguid))) in nvme_ns_id_attrs_are_visible()
142 if (!memchr_inv(ids->nguid, 0, sizeof(ids->nguid))) in nvme_ns_id_attrs_are_visible()
146 if (!memchr_inv(ids->eui64, 0, sizeof(ids->eui64))) in nvme_ns_id_attrs_are_visible()
151 if (dev_to_disk(dev)->fops != &nvme_bdev_ops) /* per-path attr */ in nvme_ns_id_attrs_are_visible()
153 if (!nvme_ctrl_use_ana(nvme_get_ns_from_dev(dev)->ctrl)) in nvme_ns_id_attrs_are_visible()
157 return a->mode; in nvme_ns_id_attrs_are_visible()
171 static ssize_t field##_show(struct device *dev, \
174 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); \
176 (int)sizeof(ctrl->subsys->field), ctrl->subsys->field); \
185 static ssize_t field##_show(struct device *dev, \
188 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); \
189 return sysfs_emit(buf, "%d\n", ctrl->field); \
199 static ssize_t nvme_sysfs_delete(struct device *dev, in nvme_sysfs_delete() argument
203 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_sysfs_delete() local
205 if (!test_bit(NVME_CTRL_STARTED_ONCE, &ctrl->flags)) in nvme_sysfs_delete()
206 return -EBUSY; in nvme_sysfs_delete()
208 if (device_remove_file_self(dev, attr)) in nvme_sysfs_delete()
209 nvme_delete_ctrl_sync(ctrl); in nvme_sysfs_delete()
214 static ssize_t nvme_sysfs_show_transport(struct device *dev, in nvme_sysfs_show_transport() argument
218 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_sysfs_show_transport() local
220 return sysfs_emit(buf, "%s\n", ctrl->ops->name); in nvme_sysfs_show_transport()
224 static ssize_t nvme_sysfs_show_state(struct device *dev, in nvme_sysfs_show_state() argument
228 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_sysfs_show_state() local
239 if ((unsigned)ctrl->state < ARRAY_SIZE(state_name) && in nvme_sysfs_show_state()
240 state_name[ctrl->state]) in nvme_sysfs_show_state()
241 return sysfs_emit(buf, "%s\n", state_name[ctrl->state]); in nvme_sysfs_show_state()
248 static ssize_t nvme_sysfs_show_subsysnqn(struct device *dev, in nvme_sysfs_show_subsysnqn() argument
252 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_sysfs_show_subsysnqn() local
254 return sysfs_emit(buf, "%s\n", ctrl->subsys->subnqn); in nvme_sysfs_show_subsysnqn()
258 static ssize_t nvme_sysfs_show_hostnqn(struct device *dev, in nvme_sysfs_show_hostnqn() argument
262 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_sysfs_show_hostnqn() local
264 return sysfs_emit(buf, "%s\n", ctrl->opts->host->nqn); in nvme_sysfs_show_hostnqn()
268 static ssize_t nvme_sysfs_show_hostid(struct device *dev, in nvme_sysfs_show_hostid() argument
272 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_sysfs_show_hostid() local
274 return sysfs_emit(buf, "%pU\n", &ctrl->opts->host->id); in nvme_sysfs_show_hostid()
278 static ssize_t nvme_sysfs_show_address(struct device *dev, in nvme_sysfs_show_address() argument
282 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_sysfs_show_address() local
284 return ctrl->ops->get_address(ctrl, buf, PAGE_SIZE); in nvme_sysfs_show_address()
288 static ssize_t nvme_ctrl_loss_tmo_show(struct device *dev, in nvme_ctrl_loss_tmo_show() argument
291 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_ctrl_loss_tmo_show() local
292 struct nvmf_ctrl_options *opts = ctrl->opts; in nvme_ctrl_loss_tmo_show()
294 if (ctrl->opts->max_reconnects == -1) in nvme_ctrl_loss_tmo_show()
297 opts->max_reconnects * opts->reconnect_delay); in nvme_ctrl_loss_tmo_show()
300 static ssize_t nvme_ctrl_loss_tmo_store(struct device *dev, in nvme_ctrl_loss_tmo_store() argument
303 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_ctrl_loss_tmo_store() local
304 struct nvmf_ctrl_options *opts = ctrl->opts; in nvme_ctrl_loss_tmo_store()
309 return -EINVAL; in nvme_ctrl_loss_tmo_store()
312 opts->max_reconnects = -1; in nvme_ctrl_loss_tmo_store()
314 opts->max_reconnects = DIV_ROUND_UP(ctrl_loss_tmo, in nvme_ctrl_loss_tmo_store()
315 opts->reconnect_delay); in nvme_ctrl_loss_tmo_store()
321 static ssize_t nvme_ctrl_reconnect_delay_show(struct device *dev, in nvme_ctrl_reconnect_delay_show() argument
324 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_ctrl_reconnect_delay_show() local
326 if (ctrl->opts->reconnect_delay == -1) in nvme_ctrl_reconnect_delay_show()
328 return sysfs_emit(buf, "%d\n", ctrl->opts->reconnect_delay); in nvme_ctrl_reconnect_delay_show()
331 static ssize_t nvme_ctrl_reconnect_delay_store(struct device *dev, in nvme_ctrl_reconnect_delay_store() argument
334 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_ctrl_reconnect_delay_store() local
342 ctrl->opts->reconnect_delay = v; in nvme_ctrl_reconnect_delay_store()
348 static ssize_t nvme_ctrl_fast_io_fail_tmo_show(struct device *dev, in nvme_ctrl_fast_io_fail_tmo_show() argument
351 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_ctrl_fast_io_fail_tmo_show() local
353 if (ctrl->opts->fast_io_fail_tmo == -1) in nvme_ctrl_fast_io_fail_tmo_show()
355 return sysfs_emit(buf, "%d\n", ctrl->opts->fast_io_fail_tmo); in nvme_ctrl_fast_io_fail_tmo_show()
358 static ssize_t nvme_ctrl_fast_io_fail_tmo_store(struct device *dev, in nvme_ctrl_fast_io_fail_tmo_store() argument
361 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_ctrl_fast_io_fail_tmo_store() local
362 struct nvmf_ctrl_options *opts = ctrl->opts; in nvme_ctrl_fast_io_fail_tmo_store()
367 return -EINVAL; in nvme_ctrl_fast_io_fail_tmo_store()
370 opts->fast_io_fail_tmo = -1; in nvme_ctrl_fast_io_fail_tmo_store()
372 opts->fast_io_fail_tmo = fast_io_fail_tmo; in nvme_ctrl_fast_io_fail_tmo_store()
378 static ssize_t cntrltype_show(struct device *dev, in cntrltype_show() argument
386 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in cntrltype_show() local
388 if (ctrl->cntrltype > NVME_CTRL_ADMIN || !type[ctrl->cntrltype]) in cntrltype_show()
391 return sysfs_emit(buf, type[ctrl->cntrltype]); in cntrltype_show()
395 static ssize_t dctype_show(struct device *dev, in dctype_show() argument
403 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in dctype_show() local
405 if (ctrl->dctype > NVME_DCTYPE_CDC || !type[ctrl->dctype]) in dctype_show()
408 return sysfs_emit(buf, type[ctrl->dctype]); in dctype_show()
413 static ssize_t nvme_ctrl_dhchap_secret_show(struct device *dev, in nvme_ctrl_dhchap_secret_show() argument
416 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_ctrl_dhchap_secret_show() local
417 struct nvmf_ctrl_options *opts = ctrl->opts; in nvme_ctrl_dhchap_secret_show()
419 if (!opts->dhchap_secret) in nvme_ctrl_dhchap_secret_show()
421 return sysfs_emit(buf, "%s\n", opts->dhchap_secret); in nvme_ctrl_dhchap_secret_show()
424 static ssize_t nvme_ctrl_dhchap_secret_store(struct device *dev, in nvme_ctrl_dhchap_secret_store() argument
427 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_ctrl_dhchap_secret_store() local
428 struct nvmf_ctrl_options *opts = ctrl->opts; in nvme_ctrl_dhchap_secret_store()
431 if (!ctrl->opts->dhchap_secret) in nvme_ctrl_dhchap_secret_store()
432 return -EINVAL; in nvme_ctrl_dhchap_secret_store()
434 return -EINVAL; in nvme_ctrl_dhchap_secret_store()
435 if (memcmp(buf, "DHHC-1:", 7)) in nvme_ctrl_dhchap_secret_store()
436 return -EINVAL; in nvme_ctrl_dhchap_secret_store()
440 return -ENOMEM; in nvme_ctrl_dhchap_secret_store()
442 nvme_auth_stop(ctrl); in nvme_ctrl_dhchap_secret_store()
443 if (strcmp(dhchap_secret, opts->dhchap_secret)) { in nvme_ctrl_dhchap_secret_store()
452 kfree(opts->dhchap_secret); in nvme_ctrl_dhchap_secret_store()
453 opts->dhchap_secret = dhchap_secret; in nvme_ctrl_dhchap_secret_store()
454 host_key = ctrl->host_key; in nvme_ctrl_dhchap_secret_store()
455 mutex_lock(&ctrl->dhchap_auth_mutex); in nvme_ctrl_dhchap_secret_store()
456 ctrl->host_key = key; in nvme_ctrl_dhchap_secret_store()
457 mutex_unlock(&ctrl->dhchap_auth_mutex); in nvme_ctrl_dhchap_secret_store()
461 /* Start re-authentication */ in nvme_ctrl_dhchap_secret_store()
462 dev_info(ctrl->device, "re-authenticating controller\n"); in nvme_ctrl_dhchap_secret_store()
463 queue_work(nvme_wq, &ctrl->dhchap_auth_work); in nvme_ctrl_dhchap_secret_store()
471 static ssize_t nvme_ctrl_dhchap_ctrl_secret_show(struct device *dev, in nvme_ctrl_dhchap_ctrl_secret_show() argument
474 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_ctrl_dhchap_ctrl_secret_show() local
475 struct nvmf_ctrl_options *opts = ctrl->opts; in nvme_ctrl_dhchap_ctrl_secret_show()
477 if (!opts->dhchap_ctrl_secret) in nvme_ctrl_dhchap_ctrl_secret_show()
479 return sysfs_emit(buf, "%s\n", opts->dhchap_ctrl_secret); in nvme_ctrl_dhchap_ctrl_secret_show()
482 static ssize_t nvme_ctrl_dhchap_ctrl_secret_store(struct device *dev, in nvme_ctrl_dhchap_ctrl_secret_store() argument
485 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_ctrl_dhchap_ctrl_secret_store() local
486 struct nvmf_ctrl_options *opts = ctrl->opts; in nvme_ctrl_dhchap_ctrl_secret_store()
489 if (!ctrl->opts->dhchap_ctrl_secret) in nvme_ctrl_dhchap_ctrl_secret_store()
490 return -EINVAL; in nvme_ctrl_dhchap_ctrl_secret_store()
492 return -EINVAL; in nvme_ctrl_dhchap_ctrl_secret_store()
493 if (memcmp(buf, "DHHC-1:", 7)) in nvme_ctrl_dhchap_ctrl_secret_store()
494 return -EINVAL; in nvme_ctrl_dhchap_ctrl_secret_store()
498 return -ENOMEM; in nvme_ctrl_dhchap_ctrl_secret_store()
500 nvme_auth_stop(ctrl); in nvme_ctrl_dhchap_ctrl_secret_store()
501 if (strcmp(dhchap_secret, opts->dhchap_ctrl_secret)) { in nvme_ctrl_dhchap_ctrl_secret_store()
510 kfree(opts->dhchap_ctrl_secret); in nvme_ctrl_dhchap_ctrl_secret_store()
511 opts->dhchap_ctrl_secret = dhchap_secret; in nvme_ctrl_dhchap_ctrl_secret_store()
512 ctrl_key = ctrl->ctrl_key; in nvme_ctrl_dhchap_ctrl_secret_store()
513 mutex_lock(&ctrl->dhchap_auth_mutex); in nvme_ctrl_dhchap_ctrl_secret_store()
514 ctrl->ctrl_key = key; in nvme_ctrl_dhchap_ctrl_secret_store()
515 mutex_unlock(&ctrl->dhchap_auth_mutex); in nvme_ctrl_dhchap_ctrl_secret_store()
519 /* Start re-authentication */ in nvme_ctrl_dhchap_ctrl_secret_store()
520 dev_info(ctrl->device, "re-authenticating controller\n"); in nvme_ctrl_dhchap_ctrl_secret_store()
521 queue_work(nvme_wq, &ctrl->dhchap_auth_work); in nvme_ctrl_dhchap_ctrl_secret_store()
563 struct device *dev = container_of(kobj, struct device, kobj); in nvme_dev_attrs_are_visible() local
564 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_dev_attrs_are_visible() local
566 if (a == &dev_attr_delete_controller.attr && !ctrl->ops->delete_ctrl) in nvme_dev_attrs_are_visible()
568 if (a == &dev_attr_address.attr && !ctrl->ops->get_address) in nvme_dev_attrs_are_visible()
570 if (a == &dev_attr_hostnqn.attr && !ctrl->opts) in nvme_dev_attrs_are_visible()
572 if (a == &dev_attr_hostid.attr && !ctrl->opts) in nvme_dev_attrs_are_visible()
574 if (a == &dev_attr_ctrl_loss_tmo.attr && !ctrl->opts) in nvme_dev_attrs_are_visible()
576 if (a == &dev_attr_reconnect_delay.attr && !ctrl->opts) in nvme_dev_attrs_are_visible()
578 if (a == &dev_attr_fast_io_fail_tmo.attr && !ctrl->opts) in nvme_dev_attrs_are_visible()
581 if (a == &dev_attr_dhchap_secret.attr && !ctrl->opts) in nvme_dev_attrs_are_visible()
583 if (a == &dev_attr_dhchap_ctrl_secret.attr && !ctrl->opts) in nvme_dev_attrs_are_visible()
587 return a->mode; in nvme_dev_attrs_are_visible()
605 static ssize_t nvme_subsys_show_nqn(struct device *dev, in nvme_subsys_show_nqn() argument
610 container_of(dev, struct nvme_subsystem, dev); in nvme_subsys_show_nqn()
612 return sysfs_emit(buf, "%s\n", subsys->subnqn); in nvme_subsys_show_nqn()
616 static ssize_t nvme_subsys_show_type(struct device *dev, in nvme_subsys_show_type() argument
621 container_of(dev, struct nvme_subsystem, dev); in nvme_subsys_show_type()
623 switch (subsys->subtype) { in nvme_subsys_show_type()
635 static ssize_t subsys_##field##_show(struct device *dev, \
639 container_of(dev, struct nvme_subsystem, dev); \
641 (int)sizeof(subsys->field), subsys->field); \