Lines Matching refs:ns
59 static int nvme_ns_split_bio(struct nvme_namespace *ns,
67 struct nvme_namespace *ns; in nvme_ns_ioctl() local
71 ns = cdev->si_drv1; in nvme_ns_ioctl()
72 ctrlr = ns->ctrlr; in nvme_ns_ioctl()
77 nvme_ns_test(ns, cmd, arg); in nvme_ns_ioctl()
81 return (nvme_ctrlr_passthrough_cmd(ctrlr, pt, ns->id, in nvme_ns_ioctl()
88 gnsid->nsid = ns->id; in nvme_ns_ioctl()
92 *(off_t *)arg = (off_t)nvme_ns_get_size(ns); in nvme_ns_ioctl()
95 *(u_int *)arg = nvme_ns_get_sector_size(ns); in nvme_ns_ioctl()
99 td->td_retval[0] = ns->id; in nvme_ns_ioctl()
106 return (nvme_ctrlr_linux_passthru_cmd(ctrlr, npc, ns->id, true, in nvme_ns_ioctl()
158 struct nvme_namespace *ns; in nvme_ns_strategy() local
161 ns = bp->bio_dev->si_drv1; in nvme_ns_strategy()
162 err = nvme_ns_bio_process(ns, bp, nvme_ns_strategy_done); in nvme_ns_strategy()
185 nvme_ns_get_max_io_xfer_size(struct nvme_namespace *ns) in nvme_ns_get_max_io_xfer_size() argument
187 return ns->ctrlr->max_xfer_size; in nvme_ns_get_max_io_xfer_size()
191 nvme_ns_get_sector_size(struct nvme_namespace *ns) in nvme_ns_get_sector_size() argument
195 flbas_fmt = NVMEV(NVME_NS_DATA_FLBAS_FORMAT, ns->data.flbas); in nvme_ns_get_sector_size()
196 lbads = NVMEV(NVME_NS_DATA_LBAF_LBADS, ns->data.lbaf[flbas_fmt]); in nvme_ns_get_sector_size()
202 nvme_ns_get_num_sectors(struct nvme_namespace *ns) in nvme_ns_get_num_sectors() argument
204 return (ns->data.nsze); in nvme_ns_get_num_sectors()
208 nvme_ns_get_size(struct nvme_namespace *ns) in nvme_ns_get_size() argument
210 return (nvme_ns_get_num_sectors(ns) * nvme_ns_get_sector_size(ns)); in nvme_ns_get_size()
214 nvme_ns_get_flags(struct nvme_namespace *ns) in nvme_ns_get_flags() argument
216 return (ns->flags); in nvme_ns_get_flags()
220 nvme_ns_get_serial_number(struct nvme_namespace *ns) in nvme_ns_get_serial_number() argument
222 return ((const char *)ns->ctrlr->cdata.sn); in nvme_ns_get_serial_number()
226 nvme_ns_get_model_number(struct nvme_namespace *ns) in nvme_ns_get_model_number() argument
228 return ((const char *)ns->ctrlr->cdata.mn); in nvme_ns_get_model_number()
232 nvme_ns_get_data(struct nvme_namespace *ns) in nvme_ns_get_data() argument
235 return (&ns->data); in nvme_ns_get_data()
239 nvme_ns_get_stripesize(struct nvme_namespace *ns) in nvme_ns_get_stripesize() argument
243 if (NVMEV(NVME_NS_DATA_NSFEAT_NPVALID, ns->data.nsfeat) != 0) { in nvme_ns_get_stripesize()
244 ss = nvme_ns_get_sector_size(ns); in nvme_ns_get_stripesize()
245 if (ns->data.npwa != 0) in nvme_ns_get_stripesize()
246 return ((ns->data.npwa + 1) * ss); in nvme_ns_get_stripesize()
247 else if (ns->data.npwg != 0) in nvme_ns_get_stripesize()
248 return ((ns->data.npwg + 1) * ss); in nvme_ns_get_stripesize()
250 return (ns->boundary); in nvme_ns_get_stripesize()
433 nvme_ns_split_bio(struct nvme_namespace *ns, struct bio *bp, in nvme_ns_split_bio() argument
444 counter_u64_add(ns->ctrlr->alignment_splits, 1); in nvme_ns_split_bio()
447 err = nvme_ns_bio_process(ns, child, nvme_bio_child_done); in nvme_ns_split_bio()
459 nvme_ns_bio_process(struct nvme_namespace *ns, struct bio *bp, in nvme_ns_bio_process() argument
468 if (ns->boundary > 0 && in nvme_ns_bio_process()
471 bp->bio_bcount, ns->boundary); in nvme_ns_bio_process()
473 return (nvme_ns_split_bio(ns, bp, ns->boundary)); in nvme_ns_bio_process()
478 err = nvme_ns_cmd_read_bio(ns, bp, nvme_ns_bio_done, bp); in nvme_ns_bio_process()
481 err = nvme_ns_cmd_write_bio(ns, bp, nvme_ns_bio_done, bp); in nvme_ns_bio_process()
484 err = nvme_ns_cmd_flush(ns, nvme_ns_bio_done, bp); in nvme_ns_bio_process()
495 htole32(bp->bio_bcount/nvme_ns_get_sector_size(ns)); in nvme_ns_bio_process()
497 htole64(bp->bio_offset/nvme_ns_get_sector_size(ns)); in nvme_ns_bio_process()
499 err = nvme_ns_cmd_deallocate(ns, dsm_range, 1, in nvme_ns_bio_process()
513 nvme_ns_ioctl_process(struct nvme_namespace *ns, u_long cmd, caddr_t arg, in nvme_ns_ioctl_process() argument
516 return (nvme_ns_ioctl(ns->cdev, cmd, arg, flag, td)); in nvme_ns_ioctl_process()
520 nvme_ns_construct(struct nvme_namespace *ns, uint32_t id, in nvme_ns_construct() argument
530 ns->ctrlr = ctrlr; in nvme_ns_construct()
531 ns->id = id; in nvme_ns_construct()
541 if (!mtx_initialized(&ns->lock)) in nvme_ns_construct()
542 mtx_init(&ns->lock, "nvme ns lock", NULL, MTX_DEF); in nvme_ns_construct()
545 nvme_ctrlr_cmd_identify_namespace(ctrlr, id, &ns->data, in nvme_ns_construct()
554 nvme_namespace_data_swapbytes(&ns->data); in nvme_ns_construct()
562 if (ns->data.nsze == 0) in nvme_ns_construct()
565 flbas_fmt = NVMEV(NVME_NS_DATA_FLBAS_FORMAT, ns->data.flbas); in nvme_ns_construct()
571 if (flbas_fmt > ns->data.nlbaf) { in nvme_ns_construct()
574 flbas_fmt, ns->data.nlbaf + 1); in nvme_ns_construct()
586 ns->boundary = in nvme_ns_construct()
590 ns->boundary = 0; in nvme_ns_construct()
592 ns->boundary = ns->data.noiob * nvme_ns_get_sector_size(ns); in nvme_ns_construct()
596 ns->flags |= NVME_NS_DEALLOCATE_SUPPORTED; in nvme_ns_construct()
600 ns->flags |= NVME_NS_FLUSH_SUPPORTED; in nvme_ns_construct()
606 if (ns->cdev != NULL) in nvme_ns_construct()
613 unit = device_get_unit(ctrlr->dev) * NVME_MAX_NAMESPACES + ns->id - 1; in nvme_ns_construct()
619 md_args.mda_si_drv1 = ns; in nvme_ns_construct()
620 res = make_dev_s(&md_args, &ns->cdev, "%sn%d", in nvme_ns_construct()
621 device_get_nameunit(ctrlr->dev), ns->id); in nvme_ns_construct()
624 ns->cdev->si_drv2 = make_dev_alias(ns->cdev, "%sns%d", in nvme_ns_construct()
625 device_get_nameunit(ctrlr->dev), ns->id); in nvme_ns_construct()
626 ns->cdev->si_flags |= SI_UNMAPPED; in nvme_ns_construct()
632 nvme_ns_destruct(struct nvme_namespace *ns) in nvme_ns_destruct() argument
635 if (ns->cdev != NULL) { in nvme_ns_destruct()
636 if (ns->cdev->si_drv2 != NULL) in nvme_ns_destruct()
637 destroy_dev(ns->cdev->si_drv2); in nvme_ns_destruct()
638 destroy_dev(ns->cdev); in nvme_ns_destruct()