Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'nvme-6.5-2023-06-16' of git://git.infradead.org/nvme into for-6.5/block

Pull NVMe updates from Keith:

"nvme updates for Linux 6.5

- Various cleanups all around (Irvin, Chaitanya, Christophe)
- Better struct packing (Christophe JAILLET)
- Reduce controller error logs for optional commands (Keith)
- Support for >=64KiB block sizes (Daniel Gomez)
- Fabrics fixes and code organization (Max, Chaitanya, Daniel Wagner)"

* tag 'nvme-6.5-2023-06-16' of git://git.infradead.org/nvme: (27 commits)
nvme: forward port sysfs delete fix
nvme: skip optional id ctrl csi if it failed
nvme-core: use nvme_ns_head_multipath instead of ns->head->disk
nvmet-fcloop: Do not wait on completion when unregister fails
nvme-fabrics: open code __nvmf_host_find()
nvme-fabrics: error out to unlock the mutex
nvme: Increase block size variable size to 32-bit
nvme-fcloop: no need to return from void function
nvmet-auth: remove unnecessary break after goto
nvmet-auth: remove some dead code
nvme-core: remove redundant check from nvme_init_ns_head
nvme: move sysfs code to a dedicated sysfs.c file
nvme-fabrics: prevent overriding of existing host
nvme-fabrics: check hostid using uuid_equal
nvme-fabrics: unify common code in admin and io queue connect
nvmet: reorder fields in 'struct nvmefc_fcp_req'
nvmet: reorder fields in 'struct nvme_dhchap_queue_context'
nvmet: reorder fields in 'struct nvmf_ctrl_options'
nvme: reorder fields in 'struct nvme_ctrl'
nvmet: reorder fields in 'struct nvmet_sq'
...

+902 -914
+1 -1
drivers/nvme/host/Makefile
··· 10 10 obj-$(CONFIG_NVME_TCP) += nvme-tcp.o 11 11 obj-$(CONFIG_NVME_APPLE) += nvme-apple.o 12 12 13 - nvme-core-y += core.o ioctl.o 13 + nvme-core-y += core.o ioctl.o sysfs.o 14 14 nvme-core-$(CONFIG_NVME_VERBOSE_ERRORS) += constants.o 15 15 nvme-core-$(CONFIG_TRACING) += trace.o 16 16 nvme-core-$(CONFIG_NVME_MULTIPATH) += multipath.o
+3 -3
drivers/nvme/host/auth.c
··· 30 30 u32 s2; 31 31 u16 transaction; 32 32 u8 status; 33 + u8 dhgroup_id; 33 34 u8 hash_id; 34 35 size_t hash_len; 35 - u8 dhgroup_id; 36 36 u8 c1[64]; 37 37 u8 c2[64]; 38 38 u8 response[64]; 39 39 u8 *host_response; 40 40 u8 *ctrl_key; 41 - int ctrl_key_len; 42 41 u8 *host_key; 43 - int host_key_len; 44 42 u8 *sess_key; 43 + int ctrl_key_len; 44 + int host_key_len; 45 45 int sess_key_len; 46 46 }; 47 47
+11 -652
drivers/nvme/host/core.c
··· 237 237 } 238 238 EXPORT_SYMBOL_GPL(nvme_delete_ctrl); 239 239 240 - static void nvme_delete_ctrl_sync(struct nvme_ctrl *ctrl) 240 + void nvme_delete_ctrl_sync(struct nvme_ctrl *ctrl) 241 241 { 242 242 /* 243 243 * Keep a reference until nvme_do_delete_ctrl() complete, ··· 1835 1835 struct nvme_ns *ns, struct nvme_id_ns *id) 1836 1836 { 1837 1837 sector_t capacity = nvme_lba_to_sect(ns, le64_to_cpu(id->nsze)); 1838 - unsigned short bs = 1 << ns->lba_shift; 1838 + u32 bs = 1U << ns->lba_shift; 1839 1839 u32 atomic_bs, phys_bs, io_opt = 0; 1840 1840 1841 1841 /* ··· 2256 2256 #define nvme_report_zones NULL 2257 2257 #endif /* CONFIG_BLK_DEV_ZONED */ 2258 2258 2259 - static const struct block_device_operations nvme_bdev_ops = { 2259 + const struct block_device_operations nvme_bdev_ops = { 2260 2260 .owner = THIS_MODULE, 2261 2261 .ioctl = nvme_ioctl, 2262 2262 .compat_ioctl = blkdev_compat_ptr_ioctl, ··· 2791 2791 return NULL; 2792 2792 } 2793 2793 2794 - #define SUBSYS_ATTR_RO(_name, _mode, _show) \ 2795 - struct device_attribute subsys_attr_##_name = \ 2796 - __ATTR(_name, _mode, _show, NULL) 2797 - 2798 - static ssize_t nvme_subsys_show_nqn(struct device *dev, 2799 - struct device_attribute *attr, 2800 - char *buf) 2801 - { 2802 - struct nvme_subsystem *subsys = 2803 - container_of(dev, struct nvme_subsystem, dev); 2804 - 2805 - return sysfs_emit(buf, "%s\n", subsys->subnqn); 2806 - } 2807 - static SUBSYS_ATTR_RO(subsysnqn, S_IRUGO, nvme_subsys_show_nqn); 2808 - 2809 - static ssize_t nvme_subsys_show_type(struct device *dev, 2810 - struct device_attribute *attr, 2811 - char *buf) 2812 - { 2813 - struct nvme_subsystem *subsys = 2814 - container_of(dev, struct nvme_subsystem, dev); 2815 - 2816 - switch (subsys->subtype) { 2817 - case NVME_NQN_DISC: 2818 - return sysfs_emit(buf, "discovery\n"); 2819 - case NVME_NQN_NVME: 2820 - return sysfs_emit(buf, "nvm\n"); 2821 - default: 2822 - return sysfs_emit(buf, "reserved\n"); 2823 - } 2824 - } 2825 - static SUBSYS_ATTR_RO(subsystype, S_IRUGO, nvme_subsys_show_type); 2826 - 2827 - #define nvme_subsys_show_str_function(field) \ 2828 - static ssize_t subsys_##field##_show(struct device *dev, \ 2829 - struct device_attribute *attr, char *buf) \ 2830 - { \ 2831 - struct nvme_subsystem *subsys = \ 2832 - container_of(dev, struct nvme_subsystem, dev); \ 2833 - return sysfs_emit(buf, "%.*s\n", \ 2834 - (int)sizeof(subsys->field), subsys->field); \ 2835 - } \ 2836 - static SUBSYS_ATTR_RO(field, S_IRUGO, subsys_##field##_show); 2837 - 2838 - nvme_subsys_show_str_function(model); 2839 - nvme_subsys_show_str_function(serial); 2840 - nvme_subsys_show_str_function(firmware_rev); 2841 - 2842 - static struct attribute *nvme_subsys_attrs[] = { 2843 - &subsys_attr_model.attr, 2844 - &subsys_attr_serial.attr, 2845 - &subsys_attr_firmware_rev.attr, 2846 - &subsys_attr_subsysnqn.attr, 2847 - &subsys_attr_subsystype.attr, 2848 - #ifdef CONFIG_NVME_MULTIPATH 2849 - &subsys_attr_iopolicy.attr, 2850 - #endif 2851 - NULL, 2852 - }; 2853 - 2854 - static const struct attribute_group nvme_subsys_attrs_group = { 2855 - .attrs = nvme_subsys_attrs, 2856 - }; 2857 - 2858 - static const struct attribute_group *nvme_subsys_attrs_groups[] = { 2859 - &nvme_subsys_attrs_group, 2860 - NULL, 2861 - }; 2862 - 2863 2794 static inline bool nvme_discovery_ctrl(struct nvme_ctrl *ctrl) 2864 2795 { 2865 2796 return ctrl->opts && ctrl->opts->discovery_nqn; ··· 2995 3064 ctrl->max_zeroes_sectors = 0; 2996 3065 2997 3066 if (ctrl->subsys->subtype != NVME_NQN_NVME || 2998 - nvme_ctrl_limited_cns(ctrl)) 3067 + nvme_ctrl_limited_cns(ctrl) || 3068 + test_bit(NVME_CTRL_SKIP_ID_CNS_CS, &ctrl->flags)) 2999 3069 return 0; 3000 3070 3001 3071 id = kzalloc(sizeof(*id), GFP_KERNEL); ··· 3018 3086 ctrl->max_zeroes_sectors = nvme_mps_to_sectors(ctrl, id->wzsl); 3019 3087 3020 3088 free_data: 3089 + if (ret > 0) 3090 + set_bit(NVME_CTRL_SKIP_ID_CNS_CS, &ctrl->flags); 3021 3091 kfree(id); 3022 3092 return ret; 3023 3093 } ··· 3327 3393 .uring_cmd = nvme_dev_uring_cmd, 3328 3394 }; 3329 3395 3330 - static ssize_t nvme_sysfs_reset(struct device *dev, 3331 - struct device_attribute *attr, const char *buf, 3332 - size_t count) 3333 - { 3334 - struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 3335 - int ret; 3336 - 3337 - ret = nvme_reset_ctrl_sync(ctrl); 3338 - if (ret < 0) 3339 - return ret; 3340 - return count; 3341 - } 3342 - static DEVICE_ATTR(reset_controller, S_IWUSR, NULL, nvme_sysfs_reset); 3343 - 3344 - static ssize_t nvme_sysfs_rescan(struct device *dev, 3345 - struct device_attribute *attr, const char *buf, 3346 - size_t count) 3347 - { 3348 - struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 3349 - 3350 - nvme_queue_scan(ctrl); 3351 - return count; 3352 - } 3353 - static DEVICE_ATTR(rescan_controller, S_IWUSR, NULL, nvme_sysfs_rescan); 3354 - 3355 - static inline struct nvme_ns_head *dev_to_ns_head(struct device *dev) 3356 - { 3357 - struct gendisk *disk = dev_to_disk(dev); 3358 - 3359 - if (disk->fops == &nvme_bdev_ops) 3360 - return nvme_get_ns_from_dev(dev)->head; 3361 - else 3362 - return disk->private_data; 3363 - } 3364 - 3365 - static ssize_t wwid_show(struct device *dev, struct device_attribute *attr, 3366 - char *buf) 3367 - { 3368 - struct nvme_ns_head *head = dev_to_ns_head(dev); 3369 - struct nvme_ns_ids *ids = &head->ids; 3370 - struct nvme_subsystem *subsys = head->subsys; 3371 - int serial_len = sizeof(subsys->serial); 3372 - int model_len = sizeof(subsys->model); 3373 - 3374 - if (!uuid_is_null(&ids->uuid)) 3375 - return sysfs_emit(buf, "uuid.%pU\n", &ids->uuid); 3376 - 3377 - if (memchr_inv(ids->nguid, 0, sizeof(ids->nguid))) 3378 - return sysfs_emit(buf, "eui.%16phN\n", ids->nguid); 3379 - 3380 - if (memchr_inv(ids->eui64, 0, sizeof(ids->eui64))) 3381 - return sysfs_emit(buf, "eui.%8phN\n", ids->eui64); 3382 - 3383 - while (serial_len > 0 && (subsys->serial[serial_len - 1] == ' ' || 3384 - subsys->serial[serial_len - 1] == '\0')) 3385 - serial_len--; 3386 - while (model_len > 0 && (subsys->model[model_len - 1] == ' ' || 3387 - subsys->model[model_len - 1] == '\0')) 3388 - model_len--; 3389 - 3390 - return sysfs_emit(buf, "nvme.%04x-%*phN-%*phN-%08x\n", subsys->vendor_id, 3391 - serial_len, subsys->serial, model_len, subsys->model, 3392 - head->ns_id); 3393 - } 3394 - static DEVICE_ATTR_RO(wwid); 3395 - 3396 - static ssize_t nguid_show(struct device *dev, struct device_attribute *attr, 3397 - char *buf) 3398 - { 3399 - return sysfs_emit(buf, "%pU\n", dev_to_ns_head(dev)->ids.nguid); 3400 - } 3401 - static DEVICE_ATTR_RO(nguid); 3402 - 3403 - static ssize_t uuid_show(struct device *dev, struct device_attribute *attr, 3404 - char *buf) 3405 - { 3406 - struct nvme_ns_ids *ids = &dev_to_ns_head(dev)->ids; 3407 - 3408 - /* For backward compatibility expose the NGUID to userspace if 3409 - * we have no UUID set 3410 - */ 3411 - if (uuid_is_null(&ids->uuid)) { 3412 - dev_warn_ratelimited(dev, 3413 - "No UUID available providing old NGUID\n"); 3414 - return sysfs_emit(buf, "%pU\n", ids->nguid); 3415 - } 3416 - return sysfs_emit(buf, "%pU\n", &ids->uuid); 3417 - } 3418 - static DEVICE_ATTR_RO(uuid); 3419 - 3420 - static ssize_t eui_show(struct device *dev, struct device_attribute *attr, 3421 - char *buf) 3422 - { 3423 - return sysfs_emit(buf, "%8ph\n", dev_to_ns_head(dev)->ids.eui64); 3424 - } 3425 - static DEVICE_ATTR_RO(eui); 3426 - 3427 - static ssize_t nsid_show(struct device *dev, struct device_attribute *attr, 3428 - char *buf) 3429 - { 3430 - return sysfs_emit(buf, "%d\n", dev_to_ns_head(dev)->ns_id); 3431 - } 3432 - static DEVICE_ATTR_RO(nsid); 3433 - 3434 - static struct attribute *nvme_ns_id_attrs[] = { 3435 - &dev_attr_wwid.attr, 3436 - &dev_attr_uuid.attr, 3437 - &dev_attr_nguid.attr, 3438 - &dev_attr_eui.attr, 3439 - &dev_attr_nsid.attr, 3440 - #ifdef CONFIG_NVME_MULTIPATH 3441 - &dev_attr_ana_grpid.attr, 3442 - &dev_attr_ana_state.attr, 3443 - #endif 3444 - NULL, 3445 - }; 3446 - 3447 - static umode_t nvme_ns_id_attrs_are_visible(struct kobject *kobj, 3448 - struct attribute *a, int n) 3449 - { 3450 - struct device *dev = container_of(kobj, struct device, kobj); 3451 - struct nvme_ns_ids *ids = &dev_to_ns_head(dev)->ids; 3452 - 3453 - if (a == &dev_attr_uuid.attr) { 3454 - if (uuid_is_null(&ids->uuid) && 3455 - !memchr_inv(ids->nguid, 0, sizeof(ids->nguid))) 3456 - return 0; 3457 - } 3458 - if (a == &dev_attr_nguid.attr) { 3459 - if (!memchr_inv(ids->nguid, 0, sizeof(ids->nguid))) 3460 - return 0; 3461 - } 3462 - if (a == &dev_attr_eui.attr) { 3463 - if (!memchr_inv(ids->eui64, 0, sizeof(ids->eui64))) 3464 - return 0; 3465 - } 3466 - #ifdef CONFIG_NVME_MULTIPATH 3467 - if (a == &dev_attr_ana_grpid.attr || a == &dev_attr_ana_state.attr) { 3468 - if (dev_to_disk(dev)->fops != &nvme_bdev_ops) /* per-path attr */ 3469 - return 0; 3470 - if (!nvme_ctrl_use_ana(nvme_get_ns_from_dev(dev)->ctrl)) 3471 - return 0; 3472 - } 3473 - #endif 3474 - return a->mode; 3475 - } 3476 - 3477 - static const struct attribute_group nvme_ns_id_attr_group = { 3478 - .attrs = nvme_ns_id_attrs, 3479 - .is_visible = nvme_ns_id_attrs_are_visible, 3480 - }; 3481 - 3482 - const struct attribute_group *nvme_ns_id_attr_groups[] = { 3483 - &nvme_ns_id_attr_group, 3484 - NULL, 3485 - }; 3486 - 3487 - #define nvme_show_str_function(field) \ 3488 - static ssize_t field##_show(struct device *dev, \ 3489 - struct device_attribute *attr, char *buf) \ 3490 - { \ 3491 - struct nvme_ctrl *ctrl = dev_get_drvdata(dev); \ 3492 - return sysfs_emit(buf, "%.*s\n", \ 3493 - (int)sizeof(ctrl->subsys->field), ctrl->subsys->field); \ 3494 - } \ 3495 - static DEVICE_ATTR(field, S_IRUGO, field##_show, NULL); 3496 - 3497 - nvme_show_str_function(model); 3498 - nvme_show_str_function(serial); 3499 - nvme_show_str_function(firmware_rev); 3500 - 3501 - #define nvme_show_int_function(field) \ 3502 - static ssize_t field##_show(struct device *dev, \ 3503 - struct device_attribute *attr, char *buf) \ 3504 - { \ 3505 - struct nvme_ctrl *ctrl = dev_get_drvdata(dev); \ 3506 - return sysfs_emit(buf, "%d\n", ctrl->field); \ 3507 - } \ 3508 - static DEVICE_ATTR(field, S_IRUGO, field##_show, NULL); 3509 - 3510 - nvme_show_int_function(cntlid); 3511 - nvme_show_int_function(numa_node); 3512 - nvme_show_int_function(queue_count); 3513 - nvme_show_int_function(sqsize); 3514 - nvme_show_int_function(kato); 3515 - 3516 - static ssize_t nvme_sysfs_delete(struct device *dev, 3517 - struct device_attribute *attr, const char *buf, 3518 - size_t count) 3519 - { 3520 - struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 3521 - 3522 - if (device_remove_file_self(dev, attr)) 3523 - nvme_delete_ctrl_sync(ctrl); 3524 - return count; 3525 - } 3526 - static DEVICE_ATTR(delete_controller, S_IWUSR, NULL, nvme_sysfs_delete); 3527 - 3528 - static ssize_t nvme_sysfs_show_transport(struct device *dev, 3529 - struct device_attribute *attr, 3530 - char *buf) 3531 - { 3532 - struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 3533 - 3534 - return sysfs_emit(buf, "%s\n", ctrl->ops->name); 3535 - } 3536 - static DEVICE_ATTR(transport, S_IRUGO, nvme_sysfs_show_transport, NULL); 3537 - 3538 - static ssize_t nvme_sysfs_show_state(struct device *dev, 3539 - struct device_attribute *attr, 3540 - char *buf) 3541 - { 3542 - struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 3543 - static const char *const state_name[] = { 3544 - [NVME_CTRL_NEW] = "new", 3545 - [NVME_CTRL_LIVE] = "live", 3546 - [NVME_CTRL_RESETTING] = "resetting", 3547 - [NVME_CTRL_CONNECTING] = "connecting", 3548 - [NVME_CTRL_DELETING] = "deleting", 3549 - [NVME_CTRL_DELETING_NOIO]= "deleting (no IO)", 3550 - [NVME_CTRL_DEAD] = "dead", 3551 - }; 3552 - 3553 - if ((unsigned)ctrl->state < ARRAY_SIZE(state_name) && 3554 - state_name[ctrl->state]) 3555 - return sysfs_emit(buf, "%s\n", state_name[ctrl->state]); 3556 - 3557 - return sysfs_emit(buf, "unknown state\n"); 3558 - } 3559 - 3560 - static DEVICE_ATTR(state, S_IRUGO, nvme_sysfs_show_state, NULL); 3561 - 3562 - static ssize_t nvme_sysfs_show_subsysnqn(struct device *dev, 3563 - struct device_attribute *attr, 3564 - char *buf) 3565 - { 3566 - struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 3567 - 3568 - return sysfs_emit(buf, "%s\n", ctrl->subsys->subnqn); 3569 - } 3570 - static DEVICE_ATTR(subsysnqn, S_IRUGO, nvme_sysfs_show_subsysnqn, NULL); 3571 - 3572 - static ssize_t nvme_sysfs_show_hostnqn(struct device *dev, 3573 - struct device_attribute *attr, 3574 - char *buf) 3575 - { 3576 - struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 3577 - 3578 - return sysfs_emit(buf, "%s\n", ctrl->opts->host->nqn); 3579 - } 3580 - static DEVICE_ATTR(hostnqn, S_IRUGO, nvme_sysfs_show_hostnqn, NULL); 3581 - 3582 - static ssize_t nvme_sysfs_show_hostid(struct device *dev, 3583 - struct device_attribute *attr, 3584 - char *buf) 3585 - { 3586 - struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 3587 - 3588 - return sysfs_emit(buf, "%pU\n", &ctrl->opts->host->id); 3589 - } 3590 - static DEVICE_ATTR(hostid, S_IRUGO, nvme_sysfs_show_hostid, NULL); 3591 - 3592 - static ssize_t nvme_sysfs_show_address(struct device *dev, 3593 - struct device_attribute *attr, 3594 - char *buf) 3595 - { 3596 - struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 3597 - 3598 - return ctrl->ops->get_address(ctrl, buf, PAGE_SIZE); 3599 - } 3600 - static DEVICE_ATTR(address, S_IRUGO, nvme_sysfs_show_address, NULL); 3601 - 3602 - static ssize_t nvme_ctrl_loss_tmo_show(struct device *dev, 3603 - struct device_attribute *attr, char *buf) 3604 - { 3605 - struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 3606 - struct nvmf_ctrl_options *opts = ctrl->opts; 3607 - 3608 - if (ctrl->opts->max_reconnects == -1) 3609 - return sysfs_emit(buf, "off\n"); 3610 - return sysfs_emit(buf, "%d\n", 3611 - opts->max_reconnects * opts->reconnect_delay); 3612 - } 3613 - 3614 - static ssize_t nvme_ctrl_loss_tmo_store(struct device *dev, 3615 - struct device_attribute *attr, const char *buf, size_t count) 3616 - { 3617 - struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 3618 - struct nvmf_ctrl_options *opts = ctrl->opts; 3619 - int ctrl_loss_tmo, err; 3620 - 3621 - err = kstrtoint(buf, 10, &ctrl_loss_tmo); 3622 - if (err) 3623 - return -EINVAL; 3624 - 3625 - if (ctrl_loss_tmo < 0) 3626 - opts->max_reconnects = -1; 3627 - else 3628 - opts->max_reconnects = DIV_ROUND_UP(ctrl_loss_tmo, 3629 - opts->reconnect_delay); 3630 - return count; 3631 - } 3632 - static DEVICE_ATTR(ctrl_loss_tmo, S_IRUGO | S_IWUSR, 3633 - nvme_ctrl_loss_tmo_show, nvme_ctrl_loss_tmo_store); 3634 - 3635 - static ssize_t nvme_ctrl_reconnect_delay_show(struct device *dev, 3636 - struct device_attribute *attr, char *buf) 3637 - { 3638 - struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 3639 - 3640 - if (ctrl->opts->reconnect_delay == -1) 3641 - return sysfs_emit(buf, "off\n"); 3642 - return sysfs_emit(buf, "%d\n", ctrl->opts->reconnect_delay); 3643 - } 3644 - 3645 - static ssize_t nvme_ctrl_reconnect_delay_store(struct device *dev, 3646 - struct device_attribute *attr, const char *buf, size_t count) 3647 - { 3648 - struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 3649 - unsigned int v; 3650 - int err; 3651 - 3652 - err = kstrtou32(buf, 10, &v); 3653 - if (err) 3654 - return err; 3655 - 3656 - ctrl->opts->reconnect_delay = v; 3657 - return count; 3658 - } 3659 - static DEVICE_ATTR(reconnect_delay, S_IRUGO | S_IWUSR, 3660 - nvme_ctrl_reconnect_delay_show, nvme_ctrl_reconnect_delay_store); 3661 - 3662 - static ssize_t nvme_ctrl_fast_io_fail_tmo_show(struct device *dev, 3663 - struct device_attribute *attr, char *buf) 3664 - { 3665 - struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 3666 - 3667 - if (ctrl->opts->fast_io_fail_tmo == -1) 3668 - return sysfs_emit(buf, "off\n"); 3669 - return sysfs_emit(buf, "%d\n", ctrl->opts->fast_io_fail_tmo); 3670 - } 3671 - 3672 - static ssize_t nvme_ctrl_fast_io_fail_tmo_store(struct device *dev, 3673 - struct device_attribute *attr, const char *buf, size_t count) 3674 - { 3675 - struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 3676 - struct nvmf_ctrl_options *opts = ctrl->opts; 3677 - int fast_io_fail_tmo, err; 3678 - 3679 - err = kstrtoint(buf, 10, &fast_io_fail_tmo); 3680 - if (err) 3681 - return -EINVAL; 3682 - 3683 - if (fast_io_fail_tmo < 0) 3684 - opts->fast_io_fail_tmo = -1; 3685 - else 3686 - opts->fast_io_fail_tmo = fast_io_fail_tmo; 3687 - return count; 3688 - } 3689 - static DEVICE_ATTR(fast_io_fail_tmo, S_IRUGO | S_IWUSR, 3690 - nvme_ctrl_fast_io_fail_tmo_show, nvme_ctrl_fast_io_fail_tmo_store); 3691 - 3692 - static ssize_t cntrltype_show(struct device *dev, 3693 - struct device_attribute *attr, char *buf) 3694 - { 3695 - static const char * const type[] = { 3696 - [NVME_CTRL_IO] = "io\n", 3697 - [NVME_CTRL_DISC] = "discovery\n", 3698 - [NVME_CTRL_ADMIN] = "admin\n", 3699 - }; 3700 - struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 3701 - 3702 - if (ctrl->cntrltype > NVME_CTRL_ADMIN || !type[ctrl->cntrltype]) 3703 - return sysfs_emit(buf, "reserved\n"); 3704 - 3705 - return sysfs_emit(buf, type[ctrl->cntrltype]); 3706 - } 3707 - static DEVICE_ATTR_RO(cntrltype); 3708 - 3709 - static ssize_t dctype_show(struct device *dev, 3710 - struct device_attribute *attr, char *buf) 3711 - { 3712 - static const char * const type[] = { 3713 - [NVME_DCTYPE_NOT_REPORTED] = "none\n", 3714 - [NVME_DCTYPE_DDC] = "ddc\n", 3715 - [NVME_DCTYPE_CDC] = "cdc\n", 3716 - }; 3717 - struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 3718 - 3719 - if (ctrl->dctype > NVME_DCTYPE_CDC || !type[ctrl->dctype]) 3720 - return sysfs_emit(buf, "reserved\n"); 3721 - 3722 - return sysfs_emit(buf, type[ctrl->dctype]); 3723 - } 3724 - static DEVICE_ATTR_RO(dctype); 3725 - 3726 - #ifdef CONFIG_NVME_AUTH 3727 - static ssize_t nvme_ctrl_dhchap_secret_show(struct device *dev, 3728 - struct device_attribute *attr, char *buf) 3729 - { 3730 - struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 3731 - struct nvmf_ctrl_options *opts = ctrl->opts; 3732 - 3733 - if (!opts->dhchap_secret) 3734 - return sysfs_emit(buf, "none\n"); 3735 - return sysfs_emit(buf, "%s\n", opts->dhchap_secret); 3736 - } 3737 - 3738 - static ssize_t nvme_ctrl_dhchap_secret_store(struct device *dev, 3739 - struct device_attribute *attr, const char *buf, size_t count) 3740 - { 3741 - struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 3742 - struct nvmf_ctrl_options *opts = ctrl->opts; 3743 - char *dhchap_secret; 3744 - 3745 - if (!ctrl->opts->dhchap_secret) 3746 - return -EINVAL; 3747 - if (count < 7) 3748 - return -EINVAL; 3749 - if (memcmp(buf, "DHHC-1:", 7)) 3750 - return -EINVAL; 3751 - 3752 - dhchap_secret = kzalloc(count + 1, GFP_KERNEL); 3753 - if (!dhchap_secret) 3754 - return -ENOMEM; 3755 - memcpy(dhchap_secret, buf, count); 3756 - nvme_auth_stop(ctrl); 3757 - if (strcmp(dhchap_secret, opts->dhchap_secret)) { 3758 - struct nvme_dhchap_key *key, *host_key; 3759 - int ret; 3760 - 3761 - ret = nvme_auth_generate_key(dhchap_secret, &key); 3762 - if (ret) 3763 - return ret; 3764 - kfree(opts->dhchap_secret); 3765 - opts->dhchap_secret = dhchap_secret; 3766 - host_key = ctrl->host_key; 3767 - mutex_lock(&ctrl->dhchap_auth_mutex); 3768 - ctrl->host_key = key; 3769 - mutex_unlock(&ctrl->dhchap_auth_mutex); 3770 - nvme_auth_free_key(host_key); 3771 - } 3772 - /* Start re-authentication */ 3773 - dev_info(ctrl->device, "re-authenticating controller\n"); 3774 - queue_work(nvme_wq, &ctrl->dhchap_auth_work); 3775 - 3776 - return count; 3777 - } 3778 - static DEVICE_ATTR(dhchap_secret, S_IRUGO | S_IWUSR, 3779 - nvme_ctrl_dhchap_secret_show, nvme_ctrl_dhchap_secret_store); 3780 - 3781 - static ssize_t nvme_ctrl_dhchap_ctrl_secret_show(struct device *dev, 3782 - struct device_attribute *attr, char *buf) 3783 - { 3784 - struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 3785 - struct nvmf_ctrl_options *opts = ctrl->opts; 3786 - 3787 - if (!opts->dhchap_ctrl_secret) 3788 - return sysfs_emit(buf, "none\n"); 3789 - return sysfs_emit(buf, "%s\n", opts->dhchap_ctrl_secret); 3790 - } 3791 - 3792 - static ssize_t nvme_ctrl_dhchap_ctrl_secret_store(struct device *dev, 3793 - struct device_attribute *attr, const char *buf, size_t count) 3794 - { 3795 - struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 3796 - struct nvmf_ctrl_options *opts = ctrl->opts; 3797 - char *dhchap_secret; 3798 - 3799 - if (!ctrl->opts->dhchap_ctrl_secret) 3800 - return -EINVAL; 3801 - if (count < 7) 3802 - return -EINVAL; 3803 - if (memcmp(buf, "DHHC-1:", 7)) 3804 - return -EINVAL; 3805 - 3806 - dhchap_secret = kzalloc(count + 1, GFP_KERNEL); 3807 - if (!dhchap_secret) 3808 - return -ENOMEM; 3809 - memcpy(dhchap_secret, buf, count); 3810 - nvme_auth_stop(ctrl); 3811 - if (strcmp(dhchap_secret, opts->dhchap_ctrl_secret)) { 3812 - struct nvme_dhchap_key *key, *ctrl_key; 3813 - int ret; 3814 - 3815 - ret = nvme_auth_generate_key(dhchap_secret, &key); 3816 - if (ret) 3817 - return ret; 3818 - kfree(opts->dhchap_ctrl_secret); 3819 - opts->dhchap_ctrl_secret = dhchap_secret; 3820 - ctrl_key = ctrl->ctrl_key; 3821 - mutex_lock(&ctrl->dhchap_auth_mutex); 3822 - ctrl->ctrl_key = key; 3823 - mutex_unlock(&ctrl->dhchap_auth_mutex); 3824 - nvme_auth_free_key(ctrl_key); 3825 - } 3826 - /* Start re-authentication */ 3827 - dev_info(ctrl->device, "re-authenticating controller\n"); 3828 - queue_work(nvme_wq, &ctrl->dhchap_auth_work); 3829 - 3830 - return count; 3831 - } 3832 - static DEVICE_ATTR(dhchap_ctrl_secret, S_IRUGO | S_IWUSR, 3833 - nvme_ctrl_dhchap_ctrl_secret_show, nvme_ctrl_dhchap_ctrl_secret_store); 3834 - #endif 3835 - 3836 - static struct attribute *nvme_dev_attrs[] = { 3837 - &dev_attr_reset_controller.attr, 3838 - &dev_attr_rescan_controller.attr, 3839 - &dev_attr_model.attr, 3840 - &dev_attr_serial.attr, 3841 - &dev_attr_firmware_rev.attr, 3842 - &dev_attr_cntlid.attr, 3843 - &dev_attr_delete_controller.attr, 3844 - &dev_attr_transport.attr, 3845 - &dev_attr_subsysnqn.attr, 3846 - &dev_attr_address.attr, 3847 - &dev_attr_state.attr, 3848 - &dev_attr_numa_node.attr, 3849 - &dev_attr_queue_count.attr, 3850 - &dev_attr_sqsize.attr, 3851 - &dev_attr_hostnqn.attr, 3852 - &dev_attr_hostid.attr, 3853 - &dev_attr_ctrl_loss_tmo.attr, 3854 - &dev_attr_reconnect_delay.attr, 3855 - &dev_attr_fast_io_fail_tmo.attr, 3856 - &dev_attr_kato.attr, 3857 - &dev_attr_cntrltype.attr, 3858 - &dev_attr_dctype.attr, 3859 - #ifdef CONFIG_NVME_AUTH 3860 - &dev_attr_dhchap_secret.attr, 3861 - &dev_attr_dhchap_ctrl_secret.attr, 3862 - #endif 3863 - NULL 3864 - }; 3865 - 3866 - static umode_t nvme_dev_attrs_are_visible(struct kobject *kobj, 3867 - struct attribute *a, int n) 3868 - { 3869 - struct device *dev = container_of(kobj, struct device, kobj); 3870 - struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 3871 - 3872 - if (a == &dev_attr_delete_controller.attr && !ctrl->ops->delete_ctrl) 3873 - return 0; 3874 - if (a == &dev_attr_address.attr && !ctrl->ops->get_address) 3875 - return 0; 3876 - if (a == &dev_attr_hostnqn.attr && !ctrl->opts) 3877 - return 0; 3878 - if (a == &dev_attr_hostid.attr && !ctrl->opts) 3879 - return 0; 3880 - if (a == &dev_attr_ctrl_loss_tmo.attr && !ctrl->opts) 3881 - return 0; 3882 - if (a == &dev_attr_reconnect_delay.attr && !ctrl->opts) 3883 - return 0; 3884 - if (a == &dev_attr_fast_io_fail_tmo.attr && !ctrl->opts) 3885 - return 0; 3886 - #ifdef CONFIG_NVME_AUTH 3887 - if (a == &dev_attr_dhchap_secret.attr && !ctrl->opts) 3888 - return 0; 3889 - if (a == &dev_attr_dhchap_ctrl_secret.attr && !ctrl->opts) 3890 - return 0; 3891 - #endif 3892 - 3893 - return a->mode; 3894 - } 3895 - 3896 - const struct attribute_group nvme_dev_attrs_group = { 3897 - .attrs = nvme_dev_attrs, 3898 - .is_visible = nvme_dev_attrs_are_visible, 3899 - }; 3900 - EXPORT_SYMBOL_GPL(nvme_dev_attrs_group); 3901 - 3902 - static const struct attribute_group *nvme_dev_attr_groups[] = { 3903 - &nvme_dev_attrs_group, 3904 - NULL, 3905 - }; 3906 - 3907 3396 static struct nvme_ns_head *nvme_find_ns_head(struct nvme_ctrl *ctrl, 3908 3397 unsigned nsid) 3909 3398 { ··· 3566 4209 goto out_put_ns_head; 3567 4210 } 3568 4211 3569 - if (!multipath && !list_empty(&head->list)) { 4212 + if (!multipath) { 3570 4213 dev_warn(ctrl->device, 3571 4214 "Found shared namespace %d, but multipathing not supported.\n", 3572 4215 info->nsid); ··· 3667 4310 * instance as shared namespaces will show up as multiple block 3668 4311 * devices. 3669 4312 */ 3670 - if (ns->head->disk) { 4313 + if (nvme_ns_head_multipath(ns->head)) { 3671 4314 sprintf(disk->disk_name, "nvme%dc%dn%d", ctrl->subsys->instance, 3672 4315 ctrl->instance, ns->head->instance); 3673 4316 disk->flags |= GENHD_FL_HIDDEN; ··· 4552 5195 4553 5196 return 0; 4554 5197 out_free_cdev: 5198 + nvme_fault_inject_fini(&ctrl->fault_inject); 5199 + dev_pm_qos_hide_latency_tolerance(ctrl->device); 4555 5200 cdev_device_del(&ctrl->cdev, ctrl->device); 4556 5201 out_free_name: 4557 5202 nvme_put_ctrl(ctrl);
+177 -64
drivers/nvme/host/fabrics.c
··· 21 21 22 22 static struct nvmf_host *nvmf_default_host; 23 23 24 - static struct nvmf_host *__nvmf_host_find(const char *hostnqn) 24 + static struct nvmf_host *nvmf_host_alloc(const char *hostnqn, uuid_t *id) 25 25 { 26 26 struct nvmf_host *host; 27 27 28 - list_for_each_entry(host, &nvmf_hosts, list) { 29 - if (!strcmp(host->nqn, hostnqn)) 30 - return host; 31 - } 28 + host = kmalloc(sizeof(*host), GFP_KERNEL); 29 + if (!host) 30 + return NULL; 32 31 33 - return NULL; 32 + kref_init(&host->ref); 33 + uuid_copy(&host->id, id); 34 + strscpy(host->nqn, hostnqn, NVMF_NQN_SIZE); 35 + 36 + return host; 34 37 } 35 38 36 - static struct nvmf_host *nvmf_host_add(const char *hostnqn) 39 + static struct nvmf_host *nvmf_host_add(const char *hostnqn, uuid_t *id) 37 40 { 38 41 struct nvmf_host *host; 39 42 40 43 mutex_lock(&nvmf_hosts_mutex); 41 - host = __nvmf_host_find(hostnqn); 42 - if (host) { 43 - kref_get(&host->ref); 44 - goto out_unlock; 44 + 45 + /* 46 + * We have defined a host as how it is perceived by the target. 47 + * Therefore, we don't allow different Host NQNs with the same Host ID. 48 + * Similarly, we do not allow the usage of the same Host NQN with 49 + * different Host IDs. This'll maintain unambiguous host identification. 50 + */ 51 + list_for_each_entry(host, &nvmf_hosts, list) { 52 + bool same_hostnqn = !strcmp(host->nqn, hostnqn); 53 + bool same_hostid = uuid_equal(&host->id, id); 54 + 55 + if (same_hostnqn && same_hostid) { 56 + kref_get(&host->ref); 57 + goto out_unlock; 58 + } 59 + if (same_hostnqn) { 60 + pr_err("found same hostnqn %s but different hostid %pUb\n", 61 + hostnqn, id); 62 + host = ERR_PTR(-EINVAL); 63 + goto out_unlock; 64 + } 65 + if (same_hostid) { 66 + pr_err("found same hostid %pUb but different hostnqn %s\n", 67 + id, hostnqn); 68 + host = ERR_PTR(-EINVAL); 69 + goto out_unlock; 70 + } 45 71 } 46 72 47 - host = kmalloc(sizeof(*host), GFP_KERNEL); 48 - if (!host) 73 + host = nvmf_host_alloc(hostnqn, id); 74 + if (!host) { 75 + host = ERR_PTR(-ENOMEM); 49 76 goto out_unlock; 50 - 51 - kref_init(&host->ref); 52 - strscpy(host->nqn, hostnqn, NVMF_NQN_SIZE); 77 + } 53 78 54 79 list_add_tail(&host->list, &nvmf_hosts); 55 80 out_unlock: ··· 85 60 static struct nvmf_host *nvmf_host_default(void) 86 61 { 87 62 struct nvmf_host *host; 63 + char nqn[NVMF_NQN_SIZE]; 64 + uuid_t id; 88 65 89 - host = kmalloc(sizeof(*host), GFP_KERNEL); 66 + uuid_gen(&id); 67 + snprintf(nqn, NVMF_NQN_SIZE, 68 + "nqn.2014-08.org.nvmexpress:uuid:%pUb", &id); 69 + 70 + host = nvmf_host_alloc(nqn, &id); 90 71 if (!host) 91 72 return NULL; 92 - 93 - kref_init(&host->ref); 94 - uuid_gen(&host->id); 95 - snprintf(host->nqn, NVMF_NQN_SIZE, 96 - "nqn.2014-08.org.nvmexpress:uuid:%pUb", &host->id); 97 73 98 74 mutex_lock(&nvmf_hosts_mutex); 99 75 list_add_tail(&host->list, &nvmf_hosts); ··· 375 349 } 376 350 } 377 351 352 + static struct nvmf_connect_data *nvmf_connect_data_prep(struct nvme_ctrl *ctrl, 353 + u16 cntlid) 354 + { 355 + struct nvmf_connect_data *data; 356 + 357 + data = kzalloc(sizeof(*data), GFP_KERNEL); 358 + if (!data) 359 + return NULL; 360 + 361 + uuid_copy(&data->hostid, &ctrl->opts->host->id); 362 + data->cntlid = cpu_to_le16(cntlid); 363 + strncpy(data->subsysnqn, ctrl->opts->subsysnqn, NVMF_NQN_SIZE); 364 + strncpy(data->hostnqn, ctrl->opts->host->nqn, NVMF_NQN_SIZE); 365 + 366 + return data; 367 + } 368 + 369 + static void nvmf_connect_cmd_prep(struct nvme_ctrl *ctrl, u16 qid, 370 + struct nvme_command *cmd) 371 + { 372 + cmd->connect.opcode = nvme_fabrics_command; 373 + cmd->connect.fctype = nvme_fabrics_type_connect; 374 + cmd->connect.qid = cpu_to_le16(qid); 375 + 376 + if (qid) { 377 + cmd->connect.sqsize = cpu_to_le16(ctrl->sqsize); 378 + } else { 379 + cmd->connect.sqsize = cpu_to_le16(NVME_AQ_DEPTH - 1); 380 + 381 + /* 382 + * set keep-alive timeout in seconds granularity (ms * 1000) 383 + */ 384 + cmd->connect.kato = cpu_to_le32(ctrl->kato * 1000); 385 + } 386 + 387 + if (ctrl->opts->disable_sqflow) 388 + cmd->connect.cattr |= NVME_CONNECT_DISABLE_SQFLOW; 389 + } 390 + 378 391 /** 379 392 * nvmf_connect_admin_queue() - NVMe Fabrics Admin Queue "Connect" 380 393 * API function. ··· 442 377 int ret; 443 378 u32 result; 444 379 445 - cmd.connect.opcode = nvme_fabrics_command; 446 - cmd.connect.fctype = nvme_fabrics_type_connect; 447 - cmd.connect.qid = 0; 448 - cmd.connect.sqsize = cpu_to_le16(NVME_AQ_DEPTH - 1); 380 + nvmf_connect_cmd_prep(ctrl, 0, &cmd); 449 381 450 - /* 451 - * Set keep-alive timeout in seconds granularity (ms * 1000) 452 - */ 453 - cmd.connect.kato = cpu_to_le32(ctrl->kato * 1000); 454 - 455 - if (ctrl->opts->disable_sqflow) 456 - cmd.connect.cattr |= NVME_CONNECT_DISABLE_SQFLOW; 457 - 458 - data = kzalloc(sizeof(*data), GFP_KERNEL); 382 + data = nvmf_connect_data_prep(ctrl, 0xffff); 459 383 if (!data) 460 384 return -ENOMEM; 461 - 462 - uuid_copy(&data->hostid, &ctrl->opts->host->id); 463 - data->cntlid = cpu_to_le16(0xffff); 464 - strncpy(data->subsysnqn, ctrl->opts->subsysnqn, NVMF_NQN_SIZE); 465 - strncpy(data->hostnqn, ctrl->opts->host->nqn, NVMF_NQN_SIZE); 466 385 467 386 ret = __nvme_submit_sync_cmd(ctrl->fabrics_q, &cmd, &res, 468 387 data, sizeof(*data), NVME_QID_ANY, 1, ··· 517 468 int ret; 518 469 u32 result; 519 470 520 - cmd.connect.opcode = nvme_fabrics_command; 521 - cmd.connect.fctype = nvme_fabrics_type_connect; 522 - cmd.connect.qid = cpu_to_le16(qid); 523 - cmd.connect.sqsize = cpu_to_le16(ctrl->sqsize); 471 + nvmf_connect_cmd_prep(ctrl, qid, &cmd); 524 472 525 - if (ctrl->opts->disable_sqflow) 526 - cmd.connect.cattr |= NVME_CONNECT_DISABLE_SQFLOW; 527 - 528 - data = kzalloc(sizeof(*data), GFP_KERNEL); 473 + data = nvmf_connect_data_prep(ctrl, ctrl->cntlid); 529 474 if (!data) 530 475 return -ENOMEM; 531 - 532 - uuid_copy(&data->hostid, &ctrl->opts->host->id); 533 - data->cntlid = cpu_to_le16(ctrl->cntlid); 534 - strncpy(data->subsysnqn, ctrl->opts->subsysnqn, NVMF_NQN_SIZE); 535 - strncpy(data->hostnqn, ctrl->opts->host->nqn, NVMF_NQN_SIZE); 536 476 537 477 ret = __nvme_submit_sync_cmd(ctrl->connect_q, &cmd, &res, 538 478 data, sizeof(*data), qid, 1, ··· 659 621 size_t nqnlen = 0; 660 622 int ctrl_loss_tmo = NVMF_DEF_CTRL_LOSS_TMO; 661 623 uuid_t hostid; 624 + char hostnqn[NVMF_NQN_SIZE]; 662 625 663 626 /* Set defaults */ 664 627 opts->queue_size = NVMF_DEF_QUEUE_SIZE; ··· 676 637 if (!options) 677 638 return -ENOMEM; 678 639 679 - uuid_gen(&hostid); 640 + /* use default host if not given by user space */ 641 + uuid_copy(&hostid, &nvmf_default_host->id); 642 + strscpy(hostnqn, nvmf_default_host->nqn, NVMF_NQN_SIZE); 680 643 681 644 while ((p = strsep(&o, ",\n")) != NULL) { 682 645 if (!*p) ··· 824 783 ret = -EINVAL; 825 784 goto out; 826 785 } 827 - opts->host = nvmf_host_add(p); 786 + strscpy(hostnqn, p, NVMF_NQN_SIZE); 828 787 kfree(p); 829 - if (!opts->host) { 830 - ret = -ENOMEM; 831 - goto out; 832 - } 833 788 break; 834 789 case NVMF_OPT_RECONNECT_DELAY: 835 790 if (match_int(args, &token)) { ··· 982 945 opts->fast_io_fail_tmo, ctrl_loss_tmo); 983 946 } 984 947 985 - if (!opts->host) { 986 - kref_get(&nvmf_default_host->ref); 987 - opts->host = nvmf_default_host; 948 + opts->host = nvmf_host_add(hostnqn, &hostid); 949 + if (IS_ERR(opts->host)) { 950 + ret = PTR_ERR(opts->host); 951 + opts->host = NULL; 952 + goto out; 988 953 } 989 - 990 - uuid_copy(&opts->host->id, &hostid); 991 954 992 955 out: 993 956 kfree(options); 994 957 return ret; 995 958 } 959 + 960 + void nvmf_set_io_queues(struct nvmf_ctrl_options *opts, u32 nr_io_queues, 961 + u32 io_queues[HCTX_MAX_TYPES]) 962 + { 963 + if (opts->nr_write_queues && opts->nr_io_queues < nr_io_queues) { 964 + /* 965 + * separate read/write queues 966 + * hand out dedicated default queues only after we have 967 + * sufficient read queues. 968 + */ 969 + io_queues[HCTX_TYPE_READ] = opts->nr_io_queues; 970 + nr_io_queues -= io_queues[HCTX_TYPE_READ]; 971 + io_queues[HCTX_TYPE_DEFAULT] = 972 + min(opts->nr_write_queues, nr_io_queues); 973 + nr_io_queues -= io_queues[HCTX_TYPE_DEFAULT]; 974 + } else { 975 + /* 976 + * shared read/write queues 977 + * either no write queues were requested, or we don't have 978 + * sufficient queue count to have dedicated default queues. 979 + */ 980 + io_queues[HCTX_TYPE_DEFAULT] = 981 + min(opts->nr_io_queues, nr_io_queues); 982 + nr_io_queues -= io_queues[HCTX_TYPE_DEFAULT]; 983 + } 984 + 985 + if (opts->nr_poll_queues && nr_io_queues) { 986 + /* map dedicated poll queues only if we have queues left */ 987 + io_queues[HCTX_TYPE_POLL] = 988 + min(opts->nr_poll_queues, nr_io_queues); 989 + } 990 + } 991 + EXPORT_SYMBOL_GPL(nvmf_set_io_queues); 992 + 993 + void nvmf_map_queues(struct blk_mq_tag_set *set, struct nvme_ctrl *ctrl, 994 + u32 io_queues[HCTX_MAX_TYPES]) 995 + { 996 + struct nvmf_ctrl_options *opts = ctrl->opts; 997 + 998 + if (opts->nr_write_queues && io_queues[HCTX_TYPE_READ]) { 999 + /* separate read/write queues */ 1000 + set->map[HCTX_TYPE_DEFAULT].nr_queues = 1001 + io_queues[HCTX_TYPE_DEFAULT]; 1002 + set->map[HCTX_TYPE_DEFAULT].queue_offset = 0; 1003 + set->map[HCTX_TYPE_READ].nr_queues = 1004 + io_queues[HCTX_TYPE_READ]; 1005 + set->map[HCTX_TYPE_READ].queue_offset = 1006 + io_queues[HCTX_TYPE_DEFAULT]; 1007 + } else { 1008 + /* shared read/write queues */ 1009 + set->map[HCTX_TYPE_DEFAULT].nr_queues = 1010 + io_queues[HCTX_TYPE_DEFAULT]; 1011 + set->map[HCTX_TYPE_DEFAULT].queue_offset = 0; 1012 + set->map[HCTX_TYPE_READ].nr_queues = 1013 + io_queues[HCTX_TYPE_DEFAULT]; 1014 + set->map[HCTX_TYPE_READ].queue_offset = 0; 1015 + } 1016 + 1017 + blk_mq_map_queues(&set->map[HCTX_TYPE_DEFAULT]); 1018 + blk_mq_map_queues(&set->map[HCTX_TYPE_READ]); 1019 + if (opts->nr_poll_queues && io_queues[HCTX_TYPE_POLL]) { 1020 + /* map dedicated poll queues only if we have queues left */ 1021 + set->map[HCTX_TYPE_POLL].nr_queues = io_queues[HCTX_TYPE_POLL]; 1022 + set->map[HCTX_TYPE_POLL].queue_offset = 1023 + io_queues[HCTX_TYPE_DEFAULT] + 1024 + io_queues[HCTX_TYPE_READ]; 1025 + blk_mq_map_queues(&set->map[HCTX_TYPE_POLL]); 1026 + } 1027 + 1028 + dev_info(ctrl->device, 1029 + "mapped %d/%d/%d default/read/poll queues.\n", 1030 + io_queues[HCTX_TYPE_DEFAULT], 1031 + io_queues[HCTX_TYPE_READ], 1032 + io_queues[HCTX_TYPE_POLL]); 1033 + } 1034 + EXPORT_SYMBOL_GPL(nvmf_map_queues); 996 1035 997 1036 static int nvmf_check_required_opts(struct nvmf_ctrl_options *opts, 998 1037 unsigned int required_opts)
+16 -5
drivers/nvme/host/fabrics.h
··· 77 77 * with the parsing opts enum. 78 78 * @mask: Used by the fabrics library to parse through sysfs options 79 79 * on adding a NVMe controller. 80 + * @max_reconnects: maximum number of allowed reconnect attempts before removing 81 + * the controller, (-1) means reconnect forever, zero means remove 82 + * immediately; 80 83 * @transport: Holds the fabric transport "technology name" (for a lack of 81 84 * better description) that will be used by an NVMe controller 82 85 * being added. ··· 99 96 * @discovery_nqn: indicates if the subsysnqn is the well-known discovery NQN. 100 97 * @kato: Keep-alive timeout. 101 98 * @host: Virtual NVMe host, contains the NQN and Host ID. 102 - * @max_reconnects: maximum number of allowed reconnect attempts before removing 103 - * the controller, (-1) means reconnect forever, zero means remove 104 - * immediately; 105 99 * @dhchap_secret: DH-HMAC-CHAP secret 106 100 * @dhchap_ctrl_secret: DH-HMAC-CHAP controller secret for bi-directional 107 101 * authentication ··· 112 112 */ 113 113 struct nvmf_ctrl_options { 114 114 unsigned mask; 115 + int max_reconnects; 115 116 char *transport; 116 117 char *subsysnqn; 117 118 char *traddr; ··· 126 125 bool duplicate_connect; 127 126 unsigned int kato; 128 127 struct nvmf_host *host; 129 - int max_reconnects; 130 128 char *dhchap_secret; 131 129 char *dhchap_ctrl_secret; 132 130 bool disable_sqflow; ··· 181 181 ctrl->state == NVME_CTRL_DEAD || 182 182 strcmp(opts->subsysnqn, ctrl->opts->subsysnqn) || 183 183 strcmp(opts->host->nqn, ctrl->opts->host->nqn) || 184 - memcmp(&opts->host->id, &ctrl->opts->host->id, sizeof(uuid_t))) 184 + !uuid_equal(&opts->host->id, &ctrl->opts->host->id)) 185 185 return false; 186 186 187 187 return true; ··· 203 203 } 204 204 } 205 205 206 + static inline unsigned int nvmf_nr_io_queues(struct nvmf_ctrl_options *opts) 207 + { 208 + return min(opts->nr_io_queues, num_online_cpus()) + 209 + min(opts->nr_write_queues, num_online_cpus()) + 210 + min(opts->nr_poll_queues, num_online_cpus()); 211 + } 212 + 206 213 int nvmf_reg_read32(struct nvme_ctrl *ctrl, u32 off, u32 *val); 207 214 int nvmf_reg_read64(struct nvme_ctrl *ctrl, u32 off, u64 *val); 208 215 int nvmf_reg_write32(struct nvme_ctrl *ctrl, u32 off, u32 val); ··· 222 215 bool nvmf_should_reconnect(struct nvme_ctrl *ctrl); 223 216 bool nvmf_ip_options_match(struct nvme_ctrl *ctrl, 224 217 struct nvmf_ctrl_options *opts); 218 + void nvmf_set_io_queues(struct nvmf_ctrl_options *opts, u32 nr_io_queues, 219 + u32 io_queues[HCTX_MAX_TYPES]); 220 + void nvmf_map_queues(struct blk_mq_tag_set *set, struct nvme_ctrl *ctrl, 221 + u32 io_queues[HCTX_MAX_TYPES]); 225 222 226 223 #endif /* _NVME_FABRICS_H */
+8 -3
drivers/nvme/host/nvme.h
··· 242 242 NVME_CTRL_ADMIN_Q_STOPPED = 1, 243 243 NVME_CTRL_STARTED_ONCE = 2, 244 244 NVME_CTRL_STOPPED = 3, 245 + NVME_CTRL_SKIP_ID_CNS_CS = 4, 245 246 }; 246 247 247 248 struct nvme_ctrl { 248 249 bool comp_seen; 249 - enum nvme_ctrl_state state; 250 250 bool identified; 251 + enum nvme_ctrl_state state; 251 252 spinlock_t lock; 252 253 struct mutex scan_lock; 253 254 const struct nvme_ctrl_ops *ops; ··· 280 279 char name[12]; 281 280 u16 cntlid; 282 281 283 - u32 ctrl_config; 284 282 u16 mtfa; 283 + u32 ctrl_config; 285 284 u32 queue_count; 286 285 287 286 u64 cap; ··· 354 353 bool apst_enabled; 355 354 356 355 /* PCIe only: */ 356 + u16 hmmaxd; 357 357 u32 hmpre; 358 358 u32 hmmin; 359 359 u32 hmminds; 360 - u16 hmmaxd; 361 360 362 361 /* Fabrics only */ 363 362 u32 ioccsz; ··· 861 860 extern const struct pr_ops nvme_pr_ops; 862 861 extern const struct block_device_operations nvme_ns_head_ops; 863 862 extern const struct attribute_group nvme_dev_attrs_group; 863 + extern const struct attribute_group *nvme_subsys_attrs_groups[]; 864 + extern const struct attribute_group *nvme_dev_attr_groups[]; 865 + extern const struct block_device_operations nvme_bdev_ops; 864 866 867 + void nvme_delete_ctrl_sync(struct nvme_ctrl *ctrl); 865 868 struct nvme_ns *nvme_find_path(struct nvme_ns_head *head); 866 869 #ifdef CONFIG_NVME_MULTIPATH 867 870 static inline bool nvme_ctrl_use_ana(struct nvme_ctrl *ctrl)
+1 -2
drivers/nvme/host/pci.c
··· 420 420 struct request *req, unsigned int hctx_idx, 421 421 unsigned int numa_node) 422 422 { 423 - struct nvme_dev *dev = to_nvme_dev(set->driver_data); 424 423 struct nvme_iod *iod = blk_mq_rq_to_pdu(req); 425 424 426 - nvme_req(req)->ctrl = &dev->ctrl; 425 + nvme_req(req)->ctrl = set->driver_data; 427 426 nvme_req(req)->cmd = &iod->cmd; 428 427 return 0; 429 428 }
+5 -76
drivers/nvme/host/rdma.c
··· 501 501 } 502 502 ibdev = queue->device->dev; 503 503 504 - /* +1 for ib_stop_cq */ 504 + /* +1 for ib_drain_qp */ 505 505 queue->cq_size = cq_factor * queue->queue_size + 1; 506 506 507 507 ret = nvme_rdma_create_cq(ibdev, queue); ··· 713 713 static int nvme_rdma_alloc_io_queues(struct nvme_rdma_ctrl *ctrl) 714 714 { 715 715 struct nvmf_ctrl_options *opts = ctrl->ctrl.opts; 716 - struct ib_device *ibdev = ctrl->device->dev; 717 - unsigned int nr_io_queues, nr_default_queues; 718 - unsigned int nr_read_queues, nr_poll_queues; 716 + unsigned int nr_io_queues; 719 717 int i, ret; 720 718 721 - nr_read_queues = min_t(unsigned int, ibdev->num_comp_vectors, 722 - min(opts->nr_io_queues, num_online_cpus())); 723 - nr_default_queues = min_t(unsigned int, ibdev->num_comp_vectors, 724 - min(opts->nr_write_queues, num_online_cpus())); 725 - nr_poll_queues = min(opts->nr_poll_queues, num_online_cpus()); 726 - nr_io_queues = nr_read_queues + nr_default_queues + nr_poll_queues; 727 - 719 + nr_io_queues = nvmf_nr_io_queues(opts); 728 720 ret = nvme_set_queue_count(&ctrl->ctrl, &nr_io_queues); 729 721 if (ret) 730 722 return ret; ··· 731 739 dev_info(ctrl->ctrl.device, 732 740 "creating %d I/O queues.\n", nr_io_queues); 733 741 734 - if (opts->nr_write_queues && nr_read_queues < nr_io_queues) { 735 - /* 736 - * separate read/write queues 737 - * hand out dedicated default queues only after we have 738 - * sufficient read queues. 739 - */ 740 - ctrl->io_queues[HCTX_TYPE_READ] = nr_read_queues; 741 - nr_io_queues -= ctrl->io_queues[HCTX_TYPE_READ]; 742 - ctrl->io_queues[HCTX_TYPE_DEFAULT] = 743 - min(nr_default_queues, nr_io_queues); 744 - nr_io_queues -= ctrl->io_queues[HCTX_TYPE_DEFAULT]; 745 - } else { 746 - /* 747 - * shared read/write queues 748 - * either no write queues were requested, or we don't have 749 - * sufficient queue count to have dedicated default queues. 750 - */ 751 - ctrl->io_queues[HCTX_TYPE_DEFAULT] = 752 - min(nr_read_queues, nr_io_queues); 753 - nr_io_queues -= ctrl->io_queues[HCTX_TYPE_DEFAULT]; 754 - } 755 - 756 - if (opts->nr_poll_queues && nr_io_queues) { 757 - /* map dedicated poll queues only if we have queues left */ 758 - ctrl->io_queues[HCTX_TYPE_POLL] = 759 - min(nr_poll_queues, nr_io_queues); 760 - } 761 - 742 + nvmf_set_io_queues(opts, nr_io_queues, ctrl->io_queues); 762 743 for (i = 1; i < ctrl->ctrl.queue_count; i++) { 763 744 ret = nvme_rdma_alloc_queue(ctrl, i, 764 745 ctrl->ctrl.sqsize + 1); ··· 2103 2138 static void nvme_rdma_map_queues(struct blk_mq_tag_set *set) 2104 2139 { 2105 2140 struct nvme_rdma_ctrl *ctrl = to_rdma_ctrl(set->driver_data); 2106 - struct nvmf_ctrl_options *opts = ctrl->ctrl.opts; 2107 2141 2108 - if (opts->nr_write_queues && ctrl->io_queues[HCTX_TYPE_READ]) { 2109 - /* separate read/write queues */ 2110 - set->map[HCTX_TYPE_DEFAULT].nr_queues = 2111 - ctrl->io_queues[HCTX_TYPE_DEFAULT]; 2112 - set->map[HCTX_TYPE_DEFAULT].queue_offset = 0; 2113 - set->map[HCTX_TYPE_READ].nr_queues = 2114 - ctrl->io_queues[HCTX_TYPE_READ]; 2115 - set->map[HCTX_TYPE_READ].queue_offset = 2116 - ctrl->io_queues[HCTX_TYPE_DEFAULT]; 2117 - } else { 2118 - /* shared read/write queues */ 2119 - set->map[HCTX_TYPE_DEFAULT].nr_queues = 2120 - ctrl->io_queues[HCTX_TYPE_DEFAULT]; 2121 - set->map[HCTX_TYPE_DEFAULT].queue_offset = 0; 2122 - set->map[HCTX_TYPE_READ].nr_queues = 2123 - ctrl->io_queues[HCTX_TYPE_DEFAULT]; 2124 - set->map[HCTX_TYPE_READ].queue_offset = 0; 2125 - } 2126 - blk_mq_map_queues(&set->map[HCTX_TYPE_DEFAULT]); 2127 - blk_mq_map_queues(&set->map[HCTX_TYPE_READ]); 2128 - 2129 - if (opts->nr_poll_queues && ctrl->io_queues[HCTX_TYPE_POLL]) { 2130 - /* map dedicated poll queues only if we have queues left */ 2131 - set->map[HCTX_TYPE_POLL].nr_queues = 2132 - ctrl->io_queues[HCTX_TYPE_POLL]; 2133 - set->map[HCTX_TYPE_POLL].queue_offset = 2134 - ctrl->io_queues[HCTX_TYPE_DEFAULT] + 2135 - ctrl->io_queues[HCTX_TYPE_READ]; 2136 - blk_mq_map_queues(&set->map[HCTX_TYPE_POLL]); 2137 - } 2138 - 2139 - dev_info(ctrl->ctrl.device, 2140 - "mapped %d/%d/%d default/read/poll queues.\n", 2141 - ctrl->io_queues[HCTX_TYPE_DEFAULT], 2142 - ctrl->io_queues[HCTX_TYPE_READ], 2143 - ctrl->io_queues[HCTX_TYPE_POLL]); 2142 + nvmf_map_queues(set, &ctrl->ctrl, ctrl->io_queues); 2144 2143 } 2145 2144 2146 2145 static const struct blk_mq_ops nvme_rdma_mq_ops = {
+668
drivers/nvme/host/sysfs.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Sysfs interface for the NVMe core driver. 4 + * 5 + * Copyright (c) 2011-2014, Intel Corporation. 6 + */ 7 + 8 + #include <linux/nvme-auth.h> 9 + 10 + #include "nvme.h" 11 + #include "fabrics.h" 12 + 13 + static ssize_t nvme_sysfs_reset(struct device *dev, 14 + struct device_attribute *attr, const char *buf, 15 + size_t count) 16 + { 17 + struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 18 + int ret; 19 + 20 + ret = nvme_reset_ctrl_sync(ctrl); 21 + if (ret < 0) 22 + return ret; 23 + return count; 24 + } 25 + static DEVICE_ATTR(reset_controller, S_IWUSR, NULL, nvme_sysfs_reset); 26 + 27 + static ssize_t nvme_sysfs_rescan(struct device *dev, 28 + struct device_attribute *attr, const char *buf, 29 + size_t count) 30 + { 31 + struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 32 + 33 + nvme_queue_scan(ctrl); 34 + return count; 35 + } 36 + static DEVICE_ATTR(rescan_controller, S_IWUSR, NULL, nvme_sysfs_rescan); 37 + 38 + static inline struct nvme_ns_head *dev_to_ns_head(struct device *dev) 39 + { 40 + struct gendisk *disk = dev_to_disk(dev); 41 + 42 + if (disk->fops == &nvme_bdev_ops) 43 + return nvme_get_ns_from_dev(dev)->head; 44 + else 45 + return disk->private_data; 46 + } 47 + 48 + static ssize_t wwid_show(struct device *dev, struct device_attribute *attr, 49 + char *buf) 50 + { 51 + struct nvme_ns_head *head = dev_to_ns_head(dev); 52 + struct nvme_ns_ids *ids = &head->ids; 53 + struct nvme_subsystem *subsys = head->subsys; 54 + int serial_len = sizeof(subsys->serial); 55 + int model_len = sizeof(subsys->model); 56 + 57 + if (!uuid_is_null(&ids->uuid)) 58 + return sysfs_emit(buf, "uuid.%pU\n", &ids->uuid); 59 + 60 + if (memchr_inv(ids->nguid, 0, sizeof(ids->nguid))) 61 + return sysfs_emit(buf, "eui.%16phN\n", ids->nguid); 62 + 63 + if (memchr_inv(ids->eui64, 0, sizeof(ids->eui64))) 64 + return sysfs_emit(buf, "eui.%8phN\n", ids->eui64); 65 + 66 + while (serial_len > 0 && (subsys->serial[serial_len - 1] == ' ' || 67 + subsys->serial[serial_len - 1] == '\0')) 68 + serial_len--; 69 + while (model_len > 0 && (subsys->model[model_len - 1] == ' ' || 70 + subsys->model[model_len - 1] == '\0')) 71 + model_len--; 72 + 73 + return sysfs_emit(buf, "nvme.%04x-%*phN-%*phN-%08x\n", subsys->vendor_id, 74 + serial_len, subsys->serial, model_len, subsys->model, 75 + head->ns_id); 76 + } 77 + static DEVICE_ATTR_RO(wwid); 78 + 79 + static ssize_t nguid_show(struct device *dev, struct device_attribute *attr, 80 + char *buf) 81 + { 82 + return sysfs_emit(buf, "%pU\n", dev_to_ns_head(dev)->ids.nguid); 83 + } 84 + static DEVICE_ATTR_RO(nguid); 85 + 86 + static ssize_t uuid_show(struct device *dev, struct device_attribute *attr, 87 + char *buf) 88 + { 89 + struct nvme_ns_ids *ids = &dev_to_ns_head(dev)->ids; 90 + 91 + /* For backward compatibility expose the NGUID to userspace if 92 + * we have no UUID set 93 + */ 94 + if (uuid_is_null(&ids->uuid)) { 95 + dev_warn_ratelimited(dev, 96 + "No UUID available providing old NGUID\n"); 97 + return sysfs_emit(buf, "%pU\n", ids->nguid); 98 + } 99 + return sysfs_emit(buf, "%pU\n", &ids->uuid); 100 + } 101 + static DEVICE_ATTR_RO(uuid); 102 + 103 + static ssize_t eui_show(struct device *dev, struct device_attribute *attr, 104 + char *buf) 105 + { 106 + return sysfs_emit(buf, "%8ph\n", dev_to_ns_head(dev)->ids.eui64); 107 + } 108 + static DEVICE_ATTR_RO(eui); 109 + 110 + static ssize_t nsid_show(struct device *dev, struct device_attribute *attr, 111 + char *buf) 112 + { 113 + return sysfs_emit(buf, "%d\n", dev_to_ns_head(dev)->ns_id); 114 + } 115 + static DEVICE_ATTR_RO(nsid); 116 + 117 + static struct attribute *nvme_ns_id_attrs[] = { 118 + &dev_attr_wwid.attr, 119 + &dev_attr_uuid.attr, 120 + &dev_attr_nguid.attr, 121 + &dev_attr_eui.attr, 122 + &dev_attr_nsid.attr, 123 + #ifdef CONFIG_NVME_MULTIPATH 124 + &dev_attr_ana_grpid.attr, 125 + &dev_attr_ana_state.attr, 126 + #endif 127 + NULL, 128 + }; 129 + 130 + static umode_t nvme_ns_id_attrs_are_visible(struct kobject *kobj, 131 + struct attribute *a, int n) 132 + { 133 + struct device *dev = container_of(kobj, struct device, kobj); 134 + struct nvme_ns_ids *ids = &dev_to_ns_head(dev)->ids; 135 + 136 + if (a == &dev_attr_uuid.attr) { 137 + if (uuid_is_null(&ids->uuid) && 138 + !memchr_inv(ids->nguid, 0, sizeof(ids->nguid))) 139 + return 0; 140 + } 141 + if (a == &dev_attr_nguid.attr) { 142 + if (!memchr_inv(ids->nguid, 0, sizeof(ids->nguid))) 143 + return 0; 144 + } 145 + if (a == &dev_attr_eui.attr) { 146 + if (!memchr_inv(ids->eui64, 0, sizeof(ids->eui64))) 147 + return 0; 148 + } 149 + #ifdef CONFIG_NVME_MULTIPATH 150 + if (a == &dev_attr_ana_grpid.attr || a == &dev_attr_ana_state.attr) { 151 + if (dev_to_disk(dev)->fops != &nvme_bdev_ops) /* per-path attr */ 152 + return 0; 153 + if (!nvme_ctrl_use_ana(nvme_get_ns_from_dev(dev)->ctrl)) 154 + return 0; 155 + } 156 + #endif 157 + return a->mode; 158 + } 159 + 160 + static const struct attribute_group nvme_ns_id_attr_group = { 161 + .attrs = nvme_ns_id_attrs, 162 + .is_visible = nvme_ns_id_attrs_are_visible, 163 + }; 164 + 165 + const struct attribute_group *nvme_ns_id_attr_groups[] = { 166 + &nvme_ns_id_attr_group, 167 + NULL, 168 + }; 169 + 170 + #define nvme_show_str_function(field) \ 171 + static ssize_t field##_show(struct device *dev, \ 172 + struct device_attribute *attr, char *buf) \ 173 + { \ 174 + struct nvme_ctrl *ctrl = dev_get_drvdata(dev); \ 175 + return sysfs_emit(buf, "%.*s\n", \ 176 + (int)sizeof(ctrl->subsys->field), ctrl->subsys->field); \ 177 + } \ 178 + static DEVICE_ATTR(field, S_IRUGO, field##_show, NULL); 179 + 180 + nvme_show_str_function(model); 181 + nvme_show_str_function(serial); 182 + nvme_show_str_function(firmware_rev); 183 + 184 + #define nvme_show_int_function(field) \ 185 + static ssize_t field##_show(struct device *dev, \ 186 + struct device_attribute *attr, char *buf) \ 187 + { \ 188 + struct nvme_ctrl *ctrl = dev_get_drvdata(dev); \ 189 + return sysfs_emit(buf, "%d\n", ctrl->field); \ 190 + } \ 191 + static DEVICE_ATTR(field, S_IRUGO, field##_show, NULL); 192 + 193 + nvme_show_int_function(cntlid); 194 + nvme_show_int_function(numa_node); 195 + nvme_show_int_function(queue_count); 196 + nvme_show_int_function(sqsize); 197 + nvme_show_int_function(kato); 198 + 199 + static ssize_t nvme_sysfs_delete(struct device *dev, 200 + struct device_attribute *attr, const char *buf, 201 + size_t count) 202 + { 203 + struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 204 + 205 + if (!test_bit(NVME_CTRL_STARTED_ONCE, &ctrl->flags)) 206 + return -EBUSY; 207 + 208 + if (device_remove_file_self(dev, attr)) 209 + nvme_delete_ctrl_sync(ctrl); 210 + return count; 211 + } 212 + static DEVICE_ATTR(delete_controller, S_IWUSR, NULL, nvme_sysfs_delete); 213 + 214 + static ssize_t nvme_sysfs_show_transport(struct device *dev, 215 + struct device_attribute *attr, 216 + char *buf) 217 + { 218 + struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 219 + 220 + return sysfs_emit(buf, "%s\n", ctrl->ops->name); 221 + } 222 + static DEVICE_ATTR(transport, S_IRUGO, nvme_sysfs_show_transport, NULL); 223 + 224 + static ssize_t nvme_sysfs_show_state(struct device *dev, 225 + struct device_attribute *attr, 226 + char *buf) 227 + { 228 + struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 229 + static const char *const state_name[] = { 230 + [NVME_CTRL_NEW] = "new", 231 + [NVME_CTRL_LIVE] = "live", 232 + [NVME_CTRL_RESETTING] = "resetting", 233 + [NVME_CTRL_CONNECTING] = "connecting", 234 + [NVME_CTRL_DELETING] = "deleting", 235 + [NVME_CTRL_DELETING_NOIO]= "deleting (no IO)", 236 + [NVME_CTRL_DEAD] = "dead", 237 + }; 238 + 239 + if ((unsigned)ctrl->state < ARRAY_SIZE(state_name) && 240 + state_name[ctrl->state]) 241 + return sysfs_emit(buf, "%s\n", state_name[ctrl->state]); 242 + 243 + return sysfs_emit(buf, "unknown state\n"); 244 + } 245 + 246 + static DEVICE_ATTR(state, S_IRUGO, nvme_sysfs_show_state, NULL); 247 + 248 + static ssize_t nvme_sysfs_show_subsysnqn(struct device *dev, 249 + struct device_attribute *attr, 250 + char *buf) 251 + { 252 + struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 253 + 254 + return sysfs_emit(buf, "%s\n", ctrl->subsys->subnqn); 255 + } 256 + static DEVICE_ATTR(subsysnqn, S_IRUGO, nvme_sysfs_show_subsysnqn, NULL); 257 + 258 + static ssize_t nvme_sysfs_show_hostnqn(struct device *dev, 259 + struct device_attribute *attr, 260 + char *buf) 261 + { 262 + struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 263 + 264 + return sysfs_emit(buf, "%s\n", ctrl->opts->host->nqn); 265 + } 266 + static DEVICE_ATTR(hostnqn, S_IRUGO, nvme_sysfs_show_hostnqn, NULL); 267 + 268 + static ssize_t nvme_sysfs_show_hostid(struct device *dev, 269 + struct device_attribute *attr, 270 + char *buf) 271 + { 272 + struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 273 + 274 + return sysfs_emit(buf, "%pU\n", &ctrl->opts->host->id); 275 + } 276 + static DEVICE_ATTR(hostid, S_IRUGO, nvme_sysfs_show_hostid, NULL); 277 + 278 + static ssize_t nvme_sysfs_show_address(struct device *dev, 279 + struct device_attribute *attr, 280 + char *buf) 281 + { 282 + struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 283 + 284 + return ctrl->ops->get_address(ctrl, buf, PAGE_SIZE); 285 + } 286 + static DEVICE_ATTR(address, S_IRUGO, nvme_sysfs_show_address, NULL); 287 + 288 + static ssize_t nvme_ctrl_loss_tmo_show(struct device *dev, 289 + struct device_attribute *attr, char *buf) 290 + { 291 + struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 292 + struct nvmf_ctrl_options *opts = ctrl->opts; 293 + 294 + if (ctrl->opts->max_reconnects == -1) 295 + return sysfs_emit(buf, "off\n"); 296 + return sysfs_emit(buf, "%d\n", 297 + opts->max_reconnects * opts->reconnect_delay); 298 + } 299 + 300 + static ssize_t nvme_ctrl_loss_tmo_store(struct device *dev, 301 + struct device_attribute *attr, const char *buf, size_t count) 302 + { 303 + struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 304 + struct nvmf_ctrl_options *opts = ctrl->opts; 305 + int ctrl_loss_tmo, err; 306 + 307 + err = kstrtoint(buf, 10, &ctrl_loss_tmo); 308 + if (err) 309 + return -EINVAL; 310 + 311 + if (ctrl_loss_tmo < 0) 312 + opts->max_reconnects = -1; 313 + else 314 + opts->max_reconnects = DIV_ROUND_UP(ctrl_loss_tmo, 315 + opts->reconnect_delay); 316 + return count; 317 + } 318 + static DEVICE_ATTR(ctrl_loss_tmo, S_IRUGO | S_IWUSR, 319 + nvme_ctrl_loss_tmo_show, nvme_ctrl_loss_tmo_store); 320 + 321 + static ssize_t nvme_ctrl_reconnect_delay_show(struct device *dev, 322 + struct device_attribute *attr, char *buf) 323 + { 324 + struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 325 + 326 + if (ctrl->opts->reconnect_delay == -1) 327 + return sysfs_emit(buf, "off\n"); 328 + return sysfs_emit(buf, "%d\n", ctrl->opts->reconnect_delay); 329 + } 330 + 331 + static ssize_t nvme_ctrl_reconnect_delay_store(struct device *dev, 332 + struct device_attribute *attr, const char *buf, size_t count) 333 + { 334 + struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 335 + unsigned int v; 336 + int err; 337 + 338 + err = kstrtou32(buf, 10, &v); 339 + if (err) 340 + return err; 341 + 342 + ctrl->opts->reconnect_delay = v; 343 + return count; 344 + } 345 + static DEVICE_ATTR(reconnect_delay, S_IRUGO | S_IWUSR, 346 + nvme_ctrl_reconnect_delay_show, nvme_ctrl_reconnect_delay_store); 347 + 348 + static ssize_t nvme_ctrl_fast_io_fail_tmo_show(struct device *dev, 349 + struct device_attribute *attr, char *buf) 350 + { 351 + struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 352 + 353 + if (ctrl->opts->fast_io_fail_tmo == -1) 354 + return sysfs_emit(buf, "off\n"); 355 + return sysfs_emit(buf, "%d\n", ctrl->opts->fast_io_fail_tmo); 356 + } 357 + 358 + static ssize_t nvme_ctrl_fast_io_fail_tmo_store(struct device *dev, 359 + struct device_attribute *attr, const char *buf, size_t count) 360 + { 361 + struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 362 + struct nvmf_ctrl_options *opts = ctrl->opts; 363 + int fast_io_fail_tmo, err; 364 + 365 + err = kstrtoint(buf, 10, &fast_io_fail_tmo); 366 + if (err) 367 + return -EINVAL; 368 + 369 + if (fast_io_fail_tmo < 0) 370 + opts->fast_io_fail_tmo = -1; 371 + else 372 + opts->fast_io_fail_tmo = fast_io_fail_tmo; 373 + return count; 374 + } 375 + static DEVICE_ATTR(fast_io_fail_tmo, S_IRUGO | S_IWUSR, 376 + nvme_ctrl_fast_io_fail_tmo_show, nvme_ctrl_fast_io_fail_tmo_store); 377 + 378 + static ssize_t cntrltype_show(struct device *dev, 379 + struct device_attribute *attr, char *buf) 380 + { 381 + static const char * const type[] = { 382 + [NVME_CTRL_IO] = "io\n", 383 + [NVME_CTRL_DISC] = "discovery\n", 384 + [NVME_CTRL_ADMIN] = "admin\n", 385 + }; 386 + struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 387 + 388 + if (ctrl->cntrltype > NVME_CTRL_ADMIN || !type[ctrl->cntrltype]) 389 + return sysfs_emit(buf, "reserved\n"); 390 + 391 + return sysfs_emit(buf, type[ctrl->cntrltype]); 392 + } 393 + static DEVICE_ATTR_RO(cntrltype); 394 + 395 + static ssize_t dctype_show(struct device *dev, 396 + struct device_attribute *attr, char *buf) 397 + { 398 + static const char * const type[] = { 399 + [NVME_DCTYPE_NOT_REPORTED] = "none\n", 400 + [NVME_DCTYPE_DDC] = "ddc\n", 401 + [NVME_DCTYPE_CDC] = "cdc\n", 402 + }; 403 + struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 404 + 405 + if (ctrl->dctype > NVME_DCTYPE_CDC || !type[ctrl->dctype]) 406 + return sysfs_emit(buf, "reserved\n"); 407 + 408 + return sysfs_emit(buf, type[ctrl->dctype]); 409 + } 410 + static DEVICE_ATTR_RO(dctype); 411 + 412 + #ifdef CONFIG_NVME_AUTH 413 + static ssize_t nvme_ctrl_dhchap_secret_show(struct device *dev, 414 + struct device_attribute *attr, char *buf) 415 + { 416 + struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 417 + struct nvmf_ctrl_options *opts = ctrl->opts; 418 + 419 + if (!opts->dhchap_secret) 420 + return sysfs_emit(buf, "none\n"); 421 + return sysfs_emit(buf, "%s\n", opts->dhchap_secret); 422 + } 423 + 424 + static ssize_t nvme_ctrl_dhchap_secret_store(struct device *dev, 425 + struct device_attribute *attr, const char *buf, size_t count) 426 + { 427 + struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 428 + struct nvmf_ctrl_options *opts = ctrl->opts; 429 + char *dhchap_secret; 430 + 431 + if (!ctrl->opts->dhchap_secret) 432 + return -EINVAL; 433 + if (count < 7) 434 + return -EINVAL; 435 + if (memcmp(buf, "DHHC-1:", 7)) 436 + return -EINVAL; 437 + 438 + dhchap_secret = kzalloc(count + 1, GFP_KERNEL); 439 + if (!dhchap_secret) 440 + return -ENOMEM; 441 + memcpy(dhchap_secret, buf, count); 442 + nvme_auth_stop(ctrl); 443 + if (strcmp(dhchap_secret, opts->dhchap_secret)) { 444 + struct nvme_dhchap_key *key, *host_key; 445 + int ret; 446 + 447 + ret = nvme_auth_generate_key(dhchap_secret, &key); 448 + if (ret) { 449 + kfree(dhchap_secret); 450 + return ret; 451 + } 452 + kfree(opts->dhchap_secret); 453 + opts->dhchap_secret = dhchap_secret; 454 + host_key = ctrl->host_key; 455 + mutex_lock(&ctrl->dhchap_auth_mutex); 456 + ctrl->host_key = key; 457 + mutex_unlock(&ctrl->dhchap_auth_mutex); 458 + nvme_auth_free_key(host_key); 459 + } else 460 + kfree(dhchap_secret); 461 + /* Start re-authentication */ 462 + dev_info(ctrl->device, "re-authenticating controller\n"); 463 + queue_work(nvme_wq, &ctrl->dhchap_auth_work); 464 + 465 + return count; 466 + } 467 + 468 + static DEVICE_ATTR(dhchap_secret, S_IRUGO | S_IWUSR, 469 + nvme_ctrl_dhchap_secret_show, nvme_ctrl_dhchap_secret_store); 470 + 471 + static ssize_t nvme_ctrl_dhchap_ctrl_secret_show(struct device *dev, 472 + struct device_attribute *attr, char *buf) 473 + { 474 + struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 475 + struct nvmf_ctrl_options *opts = ctrl->opts; 476 + 477 + if (!opts->dhchap_ctrl_secret) 478 + return sysfs_emit(buf, "none\n"); 479 + return sysfs_emit(buf, "%s\n", opts->dhchap_ctrl_secret); 480 + } 481 + 482 + static ssize_t nvme_ctrl_dhchap_ctrl_secret_store(struct device *dev, 483 + struct device_attribute *attr, const char *buf, size_t count) 484 + { 485 + struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 486 + struct nvmf_ctrl_options *opts = ctrl->opts; 487 + char *dhchap_secret; 488 + 489 + if (!ctrl->opts->dhchap_ctrl_secret) 490 + return -EINVAL; 491 + if (count < 7) 492 + return -EINVAL; 493 + if (memcmp(buf, "DHHC-1:", 7)) 494 + return -EINVAL; 495 + 496 + dhchap_secret = kzalloc(count + 1, GFP_KERNEL); 497 + if (!dhchap_secret) 498 + return -ENOMEM; 499 + memcpy(dhchap_secret, buf, count); 500 + nvme_auth_stop(ctrl); 501 + if (strcmp(dhchap_secret, opts->dhchap_ctrl_secret)) { 502 + struct nvme_dhchap_key *key, *ctrl_key; 503 + int ret; 504 + 505 + ret = nvme_auth_generate_key(dhchap_secret, &key); 506 + if (ret) { 507 + kfree(dhchap_secret); 508 + return ret; 509 + } 510 + kfree(opts->dhchap_ctrl_secret); 511 + opts->dhchap_ctrl_secret = dhchap_secret; 512 + ctrl_key = ctrl->ctrl_key; 513 + mutex_lock(&ctrl->dhchap_auth_mutex); 514 + ctrl->ctrl_key = key; 515 + mutex_unlock(&ctrl->dhchap_auth_mutex); 516 + nvme_auth_free_key(ctrl_key); 517 + } else 518 + kfree(dhchap_secret); 519 + /* Start re-authentication */ 520 + dev_info(ctrl->device, "re-authenticating controller\n"); 521 + queue_work(nvme_wq, &ctrl->dhchap_auth_work); 522 + 523 + return count; 524 + } 525 + 526 + static DEVICE_ATTR(dhchap_ctrl_secret, S_IRUGO | S_IWUSR, 527 + nvme_ctrl_dhchap_ctrl_secret_show, nvme_ctrl_dhchap_ctrl_secret_store); 528 + #endif 529 + 530 + static struct attribute *nvme_dev_attrs[] = { 531 + &dev_attr_reset_controller.attr, 532 + &dev_attr_rescan_controller.attr, 533 + &dev_attr_model.attr, 534 + &dev_attr_serial.attr, 535 + &dev_attr_firmware_rev.attr, 536 + &dev_attr_cntlid.attr, 537 + &dev_attr_delete_controller.attr, 538 + &dev_attr_transport.attr, 539 + &dev_attr_subsysnqn.attr, 540 + &dev_attr_address.attr, 541 + &dev_attr_state.attr, 542 + &dev_attr_numa_node.attr, 543 + &dev_attr_queue_count.attr, 544 + &dev_attr_sqsize.attr, 545 + &dev_attr_hostnqn.attr, 546 + &dev_attr_hostid.attr, 547 + &dev_attr_ctrl_loss_tmo.attr, 548 + &dev_attr_reconnect_delay.attr, 549 + &dev_attr_fast_io_fail_tmo.attr, 550 + &dev_attr_kato.attr, 551 + &dev_attr_cntrltype.attr, 552 + &dev_attr_dctype.attr, 553 + #ifdef CONFIG_NVME_AUTH 554 + &dev_attr_dhchap_secret.attr, 555 + &dev_attr_dhchap_ctrl_secret.attr, 556 + #endif 557 + NULL 558 + }; 559 + 560 + static umode_t nvme_dev_attrs_are_visible(struct kobject *kobj, 561 + struct attribute *a, int n) 562 + { 563 + struct device *dev = container_of(kobj, struct device, kobj); 564 + struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 565 + 566 + if (a == &dev_attr_delete_controller.attr && !ctrl->ops->delete_ctrl) 567 + return 0; 568 + if (a == &dev_attr_address.attr && !ctrl->ops->get_address) 569 + return 0; 570 + if (a == &dev_attr_hostnqn.attr && !ctrl->opts) 571 + return 0; 572 + if (a == &dev_attr_hostid.attr && !ctrl->opts) 573 + return 0; 574 + if (a == &dev_attr_ctrl_loss_tmo.attr && !ctrl->opts) 575 + return 0; 576 + if (a == &dev_attr_reconnect_delay.attr && !ctrl->opts) 577 + return 0; 578 + if (a == &dev_attr_fast_io_fail_tmo.attr && !ctrl->opts) 579 + return 0; 580 + #ifdef CONFIG_NVME_AUTH 581 + if (a == &dev_attr_dhchap_secret.attr && !ctrl->opts) 582 + return 0; 583 + if (a == &dev_attr_dhchap_ctrl_secret.attr && !ctrl->opts) 584 + return 0; 585 + #endif 586 + 587 + return a->mode; 588 + } 589 + 590 + const struct attribute_group nvme_dev_attrs_group = { 591 + .attrs = nvme_dev_attrs, 592 + .is_visible = nvme_dev_attrs_are_visible, 593 + }; 594 + EXPORT_SYMBOL_GPL(nvme_dev_attrs_group); 595 + 596 + const struct attribute_group *nvme_dev_attr_groups[] = { 597 + &nvme_dev_attrs_group, 598 + NULL, 599 + }; 600 + 601 + #define SUBSYS_ATTR_RO(_name, _mode, _show) \ 602 + struct device_attribute subsys_attr_##_name = \ 603 + __ATTR(_name, _mode, _show, NULL) 604 + 605 + static ssize_t nvme_subsys_show_nqn(struct device *dev, 606 + struct device_attribute *attr, 607 + char *buf) 608 + { 609 + struct nvme_subsystem *subsys = 610 + container_of(dev, struct nvme_subsystem, dev); 611 + 612 + return sysfs_emit(buf, "%s\n", subsys->subnqn); 613 + } 614 + static SUBSYS_ATTR_RO(subsysnqn, S_IRUGO, nvme_subsys_show_nqn); 615 + 616 + static ssize_t nvme_subsys_show_type(struct device *dev, 617 + struct device_attribute *attr, 618 + char *buf) 619 + { 620 + struct nvme_subsystem *subsys = 621 + container_of(dev, struct nvme_subsystem, dev); 622 + 623 + switch (subsys->subtype) { 624 + case NVME_NQN_DISC: 625 + return sysfs_emit(buf, "discovery\n"); 626 + case NVME_NQN_NVME: 627 + return sysfs_emit(buf, "nvm\n"); 628 + default: 629 + return sysfs_emit(buf, "reserved\n"); 630 + } 631 + } 632 + static SUBSYS_ATTR_RO(subsystype, S_IRUGO, nvme_subsys_show_type); 633 + 634 + #define nvme_subsys_show_str_function(field) \ 635 + static ssize_t subsys_##field##_show(struct device *dev, \ 636 + struct device_attribute *attr, char *buf) \ 637 + { \ 638 + struct nvme_subsystem *subsys = \ 639 + container_of(dev, struct nvme_subsystem, dev); \ 640 + return sysfs_emit(buf, "%.*s\n", \ 641 + (int)sizeof(subsys->field), subsys->field); \ 642 + } \ 643 + static SUBSYS_ATTR_RO(field, S_IRUGO, subsys_##field##_show); 644 + 645 + nvme_subsys_show_str_function(model); 646 + nvme_subsys_show_str_function(serial); 647 + nvme_subsys_show_str_function(firmware_rev); 648 + 649 + static struct attribute *nvme_subsys_attrs[] = { 650 + &subsys_attr_model.attr, 651 + &subsys_attr_serial.attr, 652 + &subsys_attr_firmware_rev.attr, 653 + &subsys_attr_subsysnqn.attr, 654 + &subsys_attr_subsystype.attr, 655 + #ifdef CONFIG_NVME_MULTIPATH 656 + &subsys_attr_iopolicy.attr, 657 + #endif 658 + NULL, 659 + }; 660 + 661 + static const struct attribute_group nvme_subsys_attrs_group = { 662 + .attrs = nvme_subsys_attrs, 663 + }; 664 + 665 + const struct attribute_group *nvme_subsys_attrs_groups[] = { 666 + &nvme_subsys_attrs_group, 667 + NULL, 668 + };
+4 -86
drivers/nvme/host/tcp.c
··· 1802 1802 return ret; 1803 1803 } 1804 1804 1805 - static unsigned int nvme_tcp_nr_io_queues(struct nvme_ctrl *ctrl) 1806 - { 1807 - unsigned int nr_io_queues; 1808 - 1809 - nr_io_queues = min(ctrl->opts->nr_io_queues, num_online_cpus()); 1810 - nr_io_queues += min(ctrl->opts->nr_write_queues, num_online_cpus()); 1811 - nr_io_queues += min(ctrl->opts->nr_poll_queues, num_online_cpus()); 1812 - 1813 - return nr_io_queues; 1814 - } 1815 - 1816 - static void nvme_tcp_set_io_queues(struct nvme_ctrl *nctrl, 1817 - unsigned int nr_io_queues) 1818 - { 1819 - struct nvme_tcp_ctrl *ctrl = to_tcp_ctrl(nctrl); 1820 - struct nvmf_ctrl_options *opts = nctrl->opts; 1821 - 1822 - if (opts->nr_write_queues && opts->nr_io_queues < nr_io_queues) { 1823 - /* 1824 - * separate read/write queues 1825 - * hand out dedicated default queues only after we have 1826 - * sufficient read queues. 1827 - */ 1828 - ctrl->io_queues[HCTX_TYPE_READ] = opts->nr_io_queues; 1829 - nr_io_queues -= ctrl->io_queues[HCTX_TYPE_READ]; 1830 - ctrl->io_queues[HCTX_TYPE_DEFAULT] = 1831 - min(opts->nr_write_queues, nr_io_queues); 1832 - nr_io_queues -= ctrl->io_queues[HCTX_TYPE_DEFAULT]; 1833 - } else { 1834 - /* 1835 - * shared read/write queues 1836 - * either no write queues were requested, or we don't have 1837 - * sufficient queue count to have dedicated default queues. 1838 - */ 1839 - ctrl->io_queues[HCTX_TYPE_DEFAULT] = 1840 - min(opts->nr_io_queues, nr_io_queues); 1841 - nr_io_queues -= ctrl->io_queues[HCTX_TYPE_DEFAULT]; 1842 - } 1843 - 1844 - if (opts->nr_poll_queues && nr_io_queues) { 1845 - /* map dedicated poll queues only if we have queues left */ 1846 - ctrl->io_queues[HCTX_TYPE_POLL] = 1847 - min(opts->nr_poll_queues, nr_io_queues); 1848 - } 1849 - } 1850 - 1851 1805 static int nvme_tcp_alloc_io_queues(struct nvme_ctrl *ctrl) 1852 1806 { 1853 1807 unsigned int nr_io_queues; 1854 1808 int ret; 1855 1809 1856 - nr_io_queues = nvme_tcp_nr_io_queues(ctrl); 1810 + nr_io_queues = nvmf_nr_io_queues(ctrl->opts); 1857 1811 ret = nvme_set_queue_count(ctrl, &nr_io_queues); 1858 1812 if (ret) 1859 1813 return ret; ··· 1822 1868 dev_info(ctrl->device, 1823 1869 "creating %d I/O queues.\n", nr_io_queues); 1824 1870 1825 - nvme_tcp_set_io_queues(ctrl, nr_io_queues); 1826 - 1871 + nvmf_set_io_queues(ctrl->opts, nr_io_queues, 1872 + to_tcp_ctrl(ctrl)->io_queues); 1827 1873 return __nvme_tcp_alloc_io_queues(ctrl); 1828 1874 } 1829 1875 ··· 2403 2449 static void nvme_tcp_map_queues(struct blk_mq_tag_set *set) 2404 2450 { 2405 2451 struct nvme_tcp_ctrl *ctrl = to_tcp_ctrl(set->driver_data); 2406 - struct nvmf_ctrl_options *opts = ctrl->ctrl.opts; 2407 2452 2408 - if (opts->nr_write_queues && ctrl->io_queues[HCTX_TYPE_READ]) { 2409 - /* separate read/write queues */ 2410 - set->map[HCTX_TYPE_DEFAULT].nr_queues = 2411 - ctrl->io_queues[HCTX_TYPE_DEFAULT]; 2412 - set->map[HCTX_TYPE_DEFAULT].queue_offset = 0; 2413 - set->map[HCTX_TYPE_READ].nr_queues = 2414 - ctrl->io_queues[HCTX_TYPE_READ]; 2415 - set->map[HCTX_TYPE_READ].queue_offset = 2416 - ctrl->io_queues[HCTX_TYPE_DEFAULT]; 2417 - } else { 2418 - /* shared read/write queues */ 2419 - set->map[HCTX_TYPE_DEFAULT].nr_queues = 2420 - ctrl->io_queues[HCTX_TYPE_DEFAULT]; 2421 - set->map[HCTX_TYPE_DEFAULT].queue_offset = 0; 2422 - set->map[HCTX_TYPE_READ].nr_queues = 2423 - ctrl->io_queues[HCTX_TYPE_DEFAULT]; 2424 - set->map[HCTX_TYPE_READ].queue_offset = 0; 2425 - } 2426 - blk_mq_map_queues(&set->map[HCTX_TYPE_DEFAULT]); 2427 - blk_mq_map_queues(&set->map[HCTX_TYPE_READ]); 2428 - 2429 - if (opts->nr_poll_queues && ctrl->io_queues[HCTX_TYPE_POLL]) { 2430 - /* map dedicated poll queues only if we have queues left */ 2431 - set->map[HCTX_TYPE_POLL].nr_queues = 2432 - ctrl->io_queues[HCTX_TYPE_POLL]; 2433 - set->map[HCTX_TYPE_POLL].queue_offset = 2434 - ctrl->io_queues[HCTX_TYPE_DEFAULT] + 2435 - ctrl->io_queues[HCTX_TYPE_READ]; 2436 - blk_mq_map_queues(&set->map[HCTX_TYPE_POLL]); 2437 - } 2438 - 2439 - dev_info(ctrl->ctrl.device, 2440 - "mapped %d/%d/%d default/read/poll queues.\n", 2441 - ctrl->io_queues[HCTX_TYPE_DEFAULT], 2442 - ctrl->io_queues[HCTX_TYPE_READ], 2443 - ctrl->io_queues[HCTX_TYPE_POLL]); 2453 + nvmf_map_queues(set, &ctrl->ctrl, ctrl->io_queues); 2444 2454 } 2445 2455 2446 2456 static int nvme_tcp_poll(struct blk_mq_hw_ctx *hctx, struct io_comp_batch *iob)
-13
drivers/nvme/target/fabrics-cmd-auth.c
··· 295 295 status = 0; 296 296 } 297 297 goto done_kfree; 298 - break; 299 298 case NVME_AUTH_DHCHAP_MESSAGE_SUCCESS2: 300 299 req->sq->authenticated = true; 301 300 pr_debug("%s: ctrl %d qid %d ctrl authenticated\n", 302 301 __func__, ctrl->cntlid, req->sq->qid); 303 302 goto done_kfree; 304 - break; 305 303 case NVME_AUTH_DHCHAP_MESSAGE_FAILURE2: 306 304 status = nvmet_auth_failure2(d); 307 305 if (status) { ··· 310 312 status = 0; 311 313 } 312 314 goto done_kfree; 313 - break; 314 315 default: 315 316 req->sq->dhchap_status = 316 317 NVME_AUTH_DHCHAP_FAILURE_INCORRECT_MESSAGE; ··· 317 320 NVME_AUTH_DHCHAP_MESSAGE_FAILURE2; 318 321 req->sq->authenticated = false; 319 322 goto done_kfree; 320 - break; 321 323 } 322 324 done_failure1: 323 325 req->sq->dhchap_status = NVME_AUTH_DHCHAP_FAILURE_INCORRECT_MESSAGE; ··· 477 481 pr_warn("ctrl %d qid %d: challenge error (%d)\n", 478 482 ctrl->cntlid, req->sq->qid, status); 479 483 status = NVME_SC_INTERNAL; 480 - break; 481 - } 482 - if (status) { 483 - req->sq->dhchap_status = status; 484 - nvmet_auth_failure1(req, d, al); 485 - pr_warn("ctrl %d qid %d: challenge status (%x)\n", 486 - ctrl->cntlid, req->sq->qid, 487 - req->sq->dhchap_status); 488 - status = 0; 489 484 break; 490 485 } 491 486 req->sq->dhchap_step = NVME_AUTH_DHCHAP_MESSAGE_REPLY;
+2 -3
drivers/nvme/target/fcloop.c
··· 645 645 } 646 646 if (ret) 647 647 fcloop_call_host_done(fcpreq, tfcp_req, ret); 648 - 649 - return; 650 648 } 651 649 652 650 static void ··· 1166 1168 1167 1169 ret = nvme_fc_unregister_localport(lport->localport); 1168 1170 1169 - wait_for_completion(&lport->unreg_done); 1171 + if (!ret) 1172 + wait_for_completion(&lport->unreg_done); 1170 1173 1171 1174 kfree(lport); 1172 1175
+1 -1
drivers/nvme/target/nvmet.h
··· 109 109 u32 sqhd; 110 110 bool sqhd_disabled; 111 111 #ifdef CONFIG_NVME_TARGET_AUTH 112 - struct delayed_work auth_expired_work; 113 112 bool authenticated; 113 + struct delayed_work auth_expired_work; 114 114 u16 dhchap_tid; 115 115 u16 dhchap_status; 116 116 int dhchap_step;
+5 -5
include/linux/nvme-fc-driver.h
··· 185 185 * @first_sgl: memory for 1st scatter/gather list segment for payload data 186 186 * @sg_cnt: number of elements in the scatter/gather list 187 187 * @io_dir: direction of the FCP request (see NVMEFC_FCP_xxx) 188 - * @sqid: The nvme SQID the command is being issued on 189 188 * @done: The callback routine the LLDD is to invoke upon completion of 190 189 * the FCP operation. req argument is the pointer to the original 191 190 * FCP IO operation. ··· 193 194 * while processing the operation. The length of the buffer 194 195 * corresponds to the fcprqst_priv_sz value specified in the 195 196 * nvme_fc_port_template supplied by the LLDD. 197 + * @sqid: The nvme SQID the command is being issued on 196 198 * 197 199 * Values set by the LLDD indicating completion status of the FCP operation. 198 200 * Must be set prior to calling the done() callback. 201 + * @rcv_rsplen: length, in bytes, of the FCP RSP IU received. 199 202 * @transferred_length: amount of payload data, in bytes, that were 200 203 * transferred. Should equal payload_length on success. 201 - * @rcv_rsplen: length, in bytes, of the FCP RSP IU received. 202 204 * @status: Completion status of the FCP operation. must be 0 upon success, 203 205 * negative errno value upon failure (ex: -EIO). Note: this is 204 206 * NOT a reflection of the NVME CQE completion status. Only the ··· 219 219 int sg_cnt; 220 220 enum nvmefc_fcp_datadir io_dir; 221 221 222 - __le16 sqid; 223 - 224 222 void (*done)(struct nvmefc_fcp_req *req); 225 223 226 224 void *private; 227 225 228 - u32 transferred_length; 226 + __le16 sqid; 227 + 229 228 u16 rcv_rsplen; 229 + u32 transferred_length; 230 230 u32 status; 231 231 } __aligned(sizeof(u64)); /* alignment for other things alloc'd with */ 232 232