Changeset View
Changeset View
Standalone View
Standalone View
head/sys/cam/nvme/nvme_da.c
Show First 20 Lines • Show All 123 Lines • ▼ Show 20 Lines | #ifdef CAM_IO_STATS | ||||
struct sysctl_oid *sysctl_stats_tree; | struct sysctl_oid *sysctl_stats_tree; | ||||
u_int timeouts; | u_int timeouts; | ||||
u_int errors; | u_int errors; | ||||
u_int invalidations; | u_int invalidations; | ||||
#endif | #endif | ||||
}; | }; | ||||
struct nda_trim_request { | struct nda_trim_request { | ||||
union { | struct nvme_dsm_range dsm[NVME_MAX_DSM_TRIM / sizeof(struct nvme_dsm_range)]; | ||||
struct nvme_dsm_range dsm; | |||||
uint8_t data[NVME_MAX_DSM_TRIM]; | |||||
}; | |||||
TAILQ_HEAD(, bio) bps; | TAILQ_HEAD(, bio) bps; | ||||
}; | }; | ||||
_Static_assert(NVME_MAX_DSM_TRIM % sizeof(struct nvme_dsm_range) == 0, | |||||
"NVME_MAX_DSM_TRIM must be an integral number of ranges"); | |||||
/* Need quirk table */ | /* Need quirk table */ | ||||
static disk_strategy_t ndastrategy; | static disk_strategy_t ndastrategy; | ||||
static dumper_t ndadump; | static dumper_t ndadump; | ||||
static periph_init_t ndainit; | static periph_init_t ndainit; | ||||
static void ndaasync(void *callback_arg, u_int32_t code, | static void ndaasync(void *callback_arg, u_int32_t code, | ||||
struct cam_path *path, void *arg); | struct cam_path *path, void *arg); | ||||
▲ Show 20 Lines • Show All 806 Lines • ▼ Show 20 Lines | case BIO_DELETE: | ||||
if (trim == NULL) { | if (trim == NULL) { | ||||
biofinish(bp, NULL, ENOMEM); | biofinish(bp, NULL, ENOMEM); | ||||
xpt_release_ccb(start_ccb); | xpt_release_ccb(start_ccb); | ||||
ndaschedule(periph); | ndaschedule(periph); | ||||
return; | return; | ||||
} | } | ||||
TAILQ_INIT(&trim->bps); | TAILQ_INIT(&trim->bps); | ||||
bp1 = bp; | bp1 = bp; | ||||
ents = sizeof(trim->data) / sizeof(struct nvme_dsm_range); | ents = min(nitems(trim->dsm), nda_max_trim_entries); | ||||
ents = min(ents, nda_max_trim_entries); | dsm_range = trim->dsm; | ||||
dsm_range = &trim->dsm; | |||||
dsm_end = dsm_range + ents; | dsm_end = dsm_range + ents; | ||||
do { | do { | ||||
TAILQ_INSERT_TAIL(&trim->bps, bp1, bio_queue); | TAILQ_INSERT_TAIL(&trim->bps, bp1, bio_queue); | ||||
dsm_range->length = | dsm_range->length = | ||||
htole32(bp1->bio_bcount / softc->disk->d_sectorsize); | htole32(bp1->bio_bcount / softc->disk->d_sectorsize); | ||||
dsm_range->starting_lba = | dsm_range->starting_lba = | ||||
htole64(bp1->bio_offset / softc->disk->d_sectorsize); | htole64(bp1->bio_offset / softc->disk->d_sectorsize); | ||||
ranges++; | ranges++; | ||||
totalcount += dsm_range->length; | totalcount += dsm_range->length; | ||||
dsm_range++; | dsm_range++; | ||||
if (dsm_range >= dsm_end) | if (dsm_range >= dsm_end) | ||||
break; | break; | ||||
bp1 = cam_iosched_next_trim(softc->cam_iosched); | bp1 = cam_iosched_next_trim(softc->cam_iosched); | ||||
/* XXX -- Could collapse adjacent ranges, but we don't for now */ | /* XXX -- Could collapse adjacent ranges, but we don't for now */ | ||||
/* XXX -- Could limit based on total payload size */ | /* XXX -- Could limit based on total payload size */ | ||||
} while (bp1 != NULL); | } while (bp1 != NULL); | ||||
start_ccb->ccb_trim = trim; | start_ccb->ccb_trim = trim; | ||||
nda_nvme_trim(softc, &start_ccb->nvmeio, &trim->dsm, | nda_nvme_trim(softc, &start_ccb->nvmeio, trim->dsm, | ||||
dsm_range - &trim->dsm); | dsm_range - trim->dsm); | ||||
start_ccb->ccb_state = NDA_CCB_TRIM; | start_ccb->ccb_state = NDA_CCB_TRIM; | ||||
softc->trim_count++; | softc->trim_count++; | ||||
softc->trim_ranges += ranges; | softc->trim_ranges += ranges; | ||||
softc->trim_lbas += totalcount; | softc->trim_lbas += totalcount; | ||||
/* | /* | ||||
* Note: We can have multiple TRIMs in flight, so we don't call | * Note: We can have multiple TRIMs in flight, so we don't call | ||||
* cam_iosched_submit_trim(softc->cam_iosched); | * cam_iosched_submit_trim(softc->cam_iosched); | ||||
* since that forces the I/O scheduler to only schedule one at a time. | * since that forces the I/O scheduler to only schedule one at a time. | ||||
▲ Show 20 Lines • Show All 235 Lines • Show Last 20 Lines |