Deleted Added
full compact
nvd.c (253473) nvd.c (253476)
1/*-
2 * Copyright (C) 2012-2013 Intel Corporation
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
1/*-
2 * Copyright (C) 2012-2013 Intel Corporation
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/dev/nvd/nvd.c 253473 2013-07-19 21:30:53Z jimharris $");
28__FBSDID("$FreeBSD: head/sys/dev/nvd/nvd.c 253476 2013-07-19 21:40:57Z jimharris $");
29
30#include <sys/param.h>
31#include <sys/bio.h>
32#include <sys/kernel.h>
33#include <sys/malloc.h>
34#include <sys/module.h>
35#include <sys/systm.h>
36#include <sys/taskqueue.h>
37
38#include <geom/geom.h>
39#include <geom/geom_disk.h>
40
41#include <dev/nvme/nvme.h>
42
29
30#include <sys/param.h>
31#include <sys/bio.h>
32#include <sys/kernel.h>
33#include <sys/malloc.h>
34#include <sys/module.h>
35#include <sys/systm.h>
36#include <sys/taskqueue.h>
37
38#include <geom/geom.h>
39#include <geom/geom_disk.h>
40
41#include <dev/nvme/nvme.h>
42
43#define NVD_STR "nvd"
44
43struct nvd_disk;
44
45static disk_ioctl_t nvd_ioctl;
46static disk_strategy_t nvd_strategy;
47
48static void *nvd_new_disk(struct nvme_namespace *ns, void *ctrlr);
49static void destroy_geom_disk(struct nvd_disk *ndisk);
50

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

97 default:
98 break;
99 }
100
101 return (error);
102}
103
104moduledata_t nvd_mod = {
45struct nvd_disk;
46
47static disk_ioctl_t nvd_ioctl;
48static disk_strategy_t nvd_strategy;
49
50static void *nvd_new_disk(struct nvme_namespace *ns, void *ctrlr);
51static void destroy_geom_disk(struct nvd_disk *ndisk);
52

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

99 default:
100 break;
101 }
102
103 return (error);
104}
105
106moduledata_t nvd_mod = {
105 "nvd",
107 NVD_STR,
106 (modeventhand_t)nvd_modevent,
107 0
108};
109
110DECLARE_MODULE(nvd, nvd_mod, SI_SUB_DRIVERS, SI_ORDER_ANY);
111MODULE_VERSION(nvd, 1);
112MODULE_DEPEND(nvd, nvme, 1, 1, 1);
113

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

266 TAILQ_INSERT_TAIL(&ctrlr_head, nvd_ctrlr, tailq);
267
268 return (nvd_ctrlr);
269}
270
271static void *
272nvd_new_disk(struct nvme_namespace *ns, void *ctrlr_arg)
273{
108 (modeventhand_t)nvd_modevent,
109 0
110};
111
112DECLARE_MODULE(nvd, nvd_mod, SI_SUB_DRIVERS, SI_ORDER_ANY);
113MODULE_VERSION(nvd, 1);
114MODULE_DEPEND(nvd, nvme, 1, 1, 1);
115

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

268 TAILQ_INSERT_TAIL(&ctrlr_head, nvd_ctrlr, tailq);
269
270 return (nvd_ctrlr);
271}
272
273static void *
274nvd_new_disk(struct nvme_namespace *ns, void *ctrlr_arg)
275{
276 uint8_t descr[NVME_MODEL_NUMBER_LENGTH+1];
274 struct nvd_disk *ndisk;
275 struct disk *disk;
276 struct nvd_controller *ctrlr = ctrlr_arg;
277
278 ndisk = malloc(sizeof(struct nvd_disk), M_NVD, M_ZERO | M_WAITOK);
279
280 disk = disk_alloc();
281 disk->d_strategy = nvd_strategy;
282 disk->d_ioctl = nvd_ioctl;
277 struct nvd_disk *ndisk;
278 struct disk *disk;
279 struct nvd_controller *ctrlr = ctrlr_arg;
280
281 ndisk = malloc(sizeof(struct nvd_disk), M_NVD, M_ZERO | M_WAITOK);
282
283 disk = disk_alloc();
284 disk->d_strategy = nvd_strategy;
285 disk->d_ioctl = nvd_ioctl;
283 disk->d_name = "nvd";
286 disk->d_name = NVD_STR;
284 disk->d_drv1 = ndisk;
285
286 disk->d_maxsize = nvme_ns_get_max_io_xfer_size(ns);
287 disk->d_sectorsize = nvme_ns_get_sector_size(ns);
288 disk->d_mediasize = (off_t)nvme_ns_get_size(ns);
289
290 if (TAILQ_EMPTY(&disk_head))
291 disk->d_unit = 0;

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

305#ifdef DISKFLAG_UNMAPPED_BIO
306 disk->d_flags |= DISKFLAG_UNMAPPED_BIO;
307#endif
308
309 /*
310 * d_ident and d_descr are both far bigger than the length of either
311 * the serial or model number strings.
312 */
287 disk->d_drv1 = ndisk;
288
289 disk->d_maxsize = nvme_ns_get_max_io_xfer_size(ns);
290 disk->d_sectorsize = nvme_ns_get_sector_size(ns);
291 disk->d_mediasize = (off_t)nvme_ns_get_size(ns);
292
293 if (TAILQ_EMPTY(&disk_head))
294 disk->d_unit = 0;

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

308#ifdef DISKFLAG_UNMAPPED_BIO
309 disk->d_flags |= DISKFLAG_UNMAPPED_BIO;
310#endif
311
312 /*
313 * d_ident and d_descr are both far bigger than the length of either
314 * the serial or model number strings.
315 */
313 strlcpy(disk->d_ident, nvme_ns_get_serial_number(ns),
314 min(sizeof(disk->d_ident), NVME_SERIAL_NUMBER_LENGTH));
316 nvme_strvis(disk->d_ident, nvme_ns_get_serial_number(ns),
317 sizeof(disk->d_ident), NVME_SERIAL_NUMBER_LENGTH);
315
318
319 nvme_strvis(descr, nvme_ns_get_model_number(ns), sizeof(descr),
320 NVME_MODEL_NUMBER_LENGTH);
321
316#if __FreeBSD_version >= 900034
322#if __FreeBSD_version >= 900034
317 strlcpy(disk->d_descr, nvme_ns_get_model_number(ns),
318 min(sizeof(disk->d_descr), NVME_MODEL_NUMBER_LENGTH));
323 strlcpy(disk->d_descr, descr, sizeof(descr));
319#endif
320
321 ndisk->ns = ns;
322 ndisk->disk = disk;
323 ndisk->cur_depth = 0;
324
325 mtx_init(&ndisk->bioqlock, "NVD bioq lock", NULL, MTX_DEF);
326 bioq_init(&ndisk->bioq);
327
328 TASK_INIT(&ndisk->bioqtask, 0, nvd_bioq_process, ndisk);
329 ndisk->tq = taskqueue_create("nvd_taskq", M_WAITOK,
330 taskqueue_thread_enqueue, &ndisk->tq);
331 taskqueue_start_threads(&ndisk->tq, 1, PI_DISK, "nvd taskq");
332
333 TAILQ_INSERT_TAIL(&disk_head, ndisk, global_tailq);
334 TAILQ_INSERT_TAIL(&ctrlr->disk_head, ndisk, ctrlr_tailq);
335
336 disk_create(disk, DISK_VERSION);
337
324#endif
325
326 ndisk->ns = ns;
327 ndisk->disk = disk;
328 ndisk->cur_depth = 0;
329
330 mtx_init(&ndisk->bioqlock, "NVD bioq lock", NULL, MTX_DEF);
331 bioq_init(&ndisk->bioq);
332
333 TASK_INIT(&ndisk->bioqtask, 0, nvd_bioq_process, ndisk);
334 ndisk->tq = taskqueue_create("nvd_taskq", M_WAITOK,
335 taskqueue_thread_enqueue, &ndisk->tq);
336 taskqueue_start_threads(&ndisk->tq, 1, PI_DISK, "nvd taskq");
337
338 TAILQ_INSERT_TAIL(&disk_head, ndisk, global_tailq);
339 TAILQ_INSERT_TAIL(&ctrlr->disk_head, ndisk, ctrlr_tailq);
340
341 disk_create(disk, DISK_VERSION);
342
343 printf(NVD_STR"%u: <%s> NVMe namespace\n", disk->d_unit, descr);
344 printf(NVD_STR"%u: %juMB (%ju %u byte sectors)\n", disk->d_unit,
345 (uintmax_t)disk->d_mediasize / (1024*1024),
346 (uintmax_t)disk->d_mediasize / disk->d_sectorsize,
347 disk->d_sectorsize);
348
338 return (NULL);
339}
340
341static void
342destroy_geom_disk(struct nvd_disk *ndisk)
343{
349 return (NULL);
350}
351
352static void
353destroy_geom_disk(struct nvd_disk *ndisk)
354{
344 struct bio *bp;
355 struct bio *bp;
356 struct disk *disk;
357 uint32_t unit;
358 int cnt = 0;
345
359
360 disk = ndisk->disk;
361 unit = disk->d_unit;
346 taskqueue_free(ndisk->tq);
362 taskqueue_free(ndisk->tq);
363
347 disk_destroy(ndisk->disk);
348
349 mtx_lock(&ndisk->bioqlock);
350 for (;;) {
351 bp = bioq_takefirst(&ndisk->bioq);
352 if (bp == NULL)
353 break;
354 bp->bio_error = EIO;
355 bp->bio_flags |= BIO_ERROR;
356 bp->bio_resid = bp->bio_bcount;
364 disk_destroy(ndisk->disk);
365
366 mtx_lock(&ndisk->bioqlock);
367 for (;;) {
368 bp = bioq_takefirst(&ndisk->bioq);
369 if (bp == NULL)
370 break;
371 bp->bio_error = EIO;
372 bp->bio_flags |= BIO_ERROR;
373 bp->bio_resid = bp->bio_bcount;
357
374 cnt++;
358 biodone(bp);
359 }
375 biodone(bp);
376 }
377
378 printf(NVD_STR"%u: lost device - %d outstanding\n", unit, cnt);
379 printf(NVD_STR"%u: removing device entry\n", unit);
380
360 mtx_unlock(&ndisk->bioqlock);
361
362 mtx_destroy(&ndisk->bioqlock);
363}
364
365static void
366nvd_controller_fail(void *ctrlr_arg)
367{

--- 15 unchanged lines hidden ---
381 mtx_unlock(&ndisk->bioqlock);
382
383 mtx_destroy(&ndisk->bioqlock);
384}
385
386static void
387nvd_controller_fail(void *ctrlr_arg)
388{

--- 15 unchanged lines hidden ---