143844926SMatthew Dillon /*
243844926SMatthew Dillon * Copyright (c) 2016 The DragonFly Project. All rights reserved.
343844926SMatthew Dillon *
443844926SMatthew Dillon * This code is derived from software contributed to The DragonFly Project
543844926SMatthew Dillon * by Matthew Dillon <dillon@backplane.com>
643844926SMatthew Dillon *
743844926SMatthew Dillon * Redistribution and use in source and binary forms, with or without
843844926SMatthew Dillon * modification, are permitted provided that the following conditions
943844926SMatthew Dillon * are met:
1043844926SMatthew Dillon *
1143844926SMatthew Dillon * 1. Redistributions of source code must retain the above copyright
1243844926SMatthew Dillon * notice, this list of conditions and the following disclaimer.
1343844926SMatthew Dillon * 2. Redistributions in binary form must reproduce the above copyright
1443844926SMatthew Dillon * notice, this list of conditions and the following disclaimer in
1543844926SMatthew Dillon * the documentation and/or other materials provided with the
1643844926SMatthew Dillon * distribution.
1743844926SMatthew Dillon * 3. Neither the name of The DragonFly Project nor the names of its
1843844926SMatthew Dillon * contributors may be used to endorse or promote products derived
1943844926SMatthew Dillon * from this software without specific, prior written permission.
2043844926SMatthew Dillon *
2143844926SMatthew Dillon * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2243844926SMatthew Dillon * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2343844926SMatthew Dillon * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
2443844926SMatthew Dillon * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
2543844926SMatthew Dillon * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
2643844926SMatthew Dillon * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
2743844926SMatthew Dillon * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
2843844926SMatthew Dillon * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
2943844926SMatthew Dillon * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
3043844926SMatthew Dillon * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
3143844926SMatthew Dillon * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3243844926SMatthew Dillon * SUCH DAMAGE.
3343844926SMatthew Dillon */
3443844926SMatthew Dillon
3543844926SMatthew Dillon #include "nvme.h"
3643844926SMatthew Dillon
3743844926SMatthew Dillon int
nvme_getlog_ioctl(nvme_softc_t * sc,nvme_getlog_ioctl_t * ioc)3843844926SMatthew Dillon nvme_getlog_ioctl(nvme_softc_t *sc, nvme_getlog_ioctl_t *ioc)
3943844926SMatthew Dillon {
4043844926SMatthew Dillon int error;
4143844926SMatthew Dillon nvme_request_t *req;
4243844926SMatthew Dillon
4343844926SMatthew Dillon if ((ioc->ret_size & 3) || ioc->ret_size > sizeof(ioc->info))
4443844926SMatthew Dillon return EINVAL;
4543844926SMatthew Dillon if (ioc->ret_size < 4)
4643844926SMatthew Dillon return EINVAL;
4743844926SMatthew Dillon
4843844926SMatthew Dillon lockmgr(&sc->ioctl_lk, LK_EXCLUSIVE);
4943844926SMatthew Dillon req = nvme_get_admin_request(sc, NVME_OP_GET_LOG_PAGE);
5043844926SMatthew Dillon req->cmd.head.nsid = -1;
5143844926SMatthew Dillon req->cmd.getlog.lid = ioc->lid;
5243844926SMatthew Dillon req->cmd.getlog.numdl = ioc->ret_size / 4 - 1;
5343844926SMatthew Dillon /* leave numdh 0 (NVMe 1.2.1 allows > 65535 dwords) */
5443844926SMatthew Dillon /* leave lpol and lpou 0 for now */
5543844926SMatthew Dillon bzero(req->info, sizeof(*req->info));
5643844926SMatthew Dillon nvme_submit_request(req);
57*049f03b7SMatthew Dillon ioc->status = nvme_wait_request(req);
5843844926SMatthew Dillon bcopy(req->info, &ioc->info, ioc->ret_size);
5943844926SMatthew Dillon nvme_put_request(req);
6043844926SMatthew Dillon lockmgr(&sc->ioctl_lk, LK_RELEASE);
6143844926SMatthew Dillon
6243844926SMatthew Dillon error = 0;
6343844926SMatthew Dillon
6443844926SMatthew Dillon return error;
6543844926SMatthew Dillon }
66