Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/bhyve/pci_virtio_block.c
/*- | /*- | ||||
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD | * SPDX-License-Identifier: BSD-2-Clause-FreeBSD | ||||
* | * | ||||
* Copyright (c) 2011 NetApp, Inc. | * Copyright (c) 2011 NetApp, Inc. | ||||
* All rights reserved. | * All rights reserved. | ||||
* Copyright (c) 2019 Joyent, Inc. | |||||
* | * | ||||
* Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
* modification, are permitted provided that the following conditions | * modification, are permitted provided that the following conditions | ||||
* are met: | * are met: | ||||
* 1. Redistributions of source code must retain the above copyright | * 1. Redistributions of source code must retain the above copyright | ||||
* notice, this list of conditions and the following disclaimer. | * notice, this list of conditions and the following disclaimer. | ||||
* 2. Redistributions in binary form must reproduce the above copyright | * 2. Redistributions in binary form must reproduce the above copyright | ||||
* notice, this list of conditions and the following disclaimer in the | * notice, this list of conditions and the following disclaimer in the | ||||
Show All 36 Lines | |||||
#include <pthread.h> | #include <pthread.h> | ||||
#include <md5.h> | #include <md5.h> | ||||
#include "bhyverun.h" | #include "bhyverun.h" | ||||
#include "pci_emul.h" | #include "pci_emul.h" | ||||
#include "virtio.h" | #include "virtio.h" | ||||
#include "block_if.h" | #include "block_if.h" | ||||
#define VTBLK_RINGSZ 64 | #define VTBLK_RINGSZ 128 | ||||
_Static_assert(VTBLK_RINGSZ <= BLOCKIF_RING_MAX, "Each ring entry must be able to queue a request"); | |||||
#define VTBLK_S_OK 0 | #define VTBLK_S_OK 0 | ||||
#define VTBLK_S_IOERR 1 | #define VTBLK_S_IOERR 1 | ||||
#define VTBLK_S_UNSUPP 2 | #define VTBLK_S_UNSUPP 2 | ||||
#define VTBLK_BLK_ID_BYTES 20 + 1 | #define VTBLK_BLK_ID_BYTES 20 + 1 | ||||
/* Capability bits */ | /* Capability bits */ | ||||
#define VTBLK_F_SEG_MAX (1 << 2) /* Maximum request segments */ | #define VTBLK_F_SEG_MAX (1 << 2) /* Maximum request segments */ | ||||
▲ Show 20 Lines • Show All 278 Lines • ▼ Show 20 Lines | pci_vtblk_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts) | ||||
MD5Final(digest, &mdctx); | MD5Final(digest, &mdctx); | ||||
snprintf(sc->vbsc_ident, VTBLK_BLK_ID_BYTES, | snprintf(sc->vbsc_ident, VTBLK_BLK_ID_BYTES, | ||||
"BHYVE-%02X%02X-%02X%02X-%02X%02X", | "BHYVE-%02X%02X-%02X%02X-%02X%02X", | ||||
digest[0], digest[1], digest[2], digest[3], digest[4], digest[5]); | digest[0], digest[1], digest[2], digest[3], digest[4], digest[5]); | ||||
/* setup virtio block config space */ | /* setup virtio block config space */ | ||||
sc->vbsc_cfg.vbc_capacity = size / DEV_BSIZE; /* 512-byte units */ | sc->vbsc_cfg.vbc_capacity = size / DEV_BSIZE; /* 512-byte units */ | ||||
sc->vbsc_cfg.vbc_size_max = 0; /* not negotiated */ | sc->vbsc_cfg.vbc_size_max = 0; /* not negotiated */ | ||||
sc->vbsc_cfg.vbc_seg_max = BLOCKIF_IOV_MAX; | |||||
/* | |||||
* If Linux is presented with a seg_max greater than the virtio queue | |||||
* size, it can stumble into situations where it violates its own | |||||
* invariants and panics. For safety, we keep seg_max clamped, paying | |||||
* heed to the two extra descriptors needed for the header and status | |||||
* of a request. | |||||
*/ | |||||
sc->vbsc_cfg.vbc_seg_max = MIN(VTBLK_RINGSZ - 2, BLOCKIF_IOV_MAX); | |||||
sc->vbsc_cfg.vbc_geometry.cylinders = 0; /* no geometry */ | sc->vbsc_cfg.vbc_geometry.cylinders = 0; /* no geometry */ | ||||
sc->vbsc_cfg.vbc_geometry.heads = 0; | sc->vbsc_cfg.vbc_geometry.heads = 0; | ||||
sc->vbsc_cfg.vbc_geometry.sectors = 0; | sc->vbsc_cfg.vbc_geometry.sectors = 0; | ||||
sc->vbsc_cfg.vbc_blk_size = sectsz; | sc->vbsc_cfg.vbc_blk_size = sectsz; | ||||
sc->vbsc_cfg.vbc_topology.physical_block_exp = | sc->vbsc_cfg.vbc_topology.physical_block_exp = | ||||
(sts > sectsz) ? (ffsll(sts / sectsz) - 1) : 0; | (sts > sectsz) ? (ffsll(sts / sectsz) - 1) : 0; | ||||
sc->vbsc_cfg.vbc_topology.alignment_offset = | sc->vbsc_cfg.vbc_topology.alignment_offset = | ||||
(sto != 0) ? ((sts - sto) / sectsz) : 0; | (sto != 0) ? ((sts - sto) / sectsz) : 0; | ||||
▲ Show 20 Lines • Show All 51 Lines • Show Last 20 Lines |