]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/nvme/nvme_sysctl.c
This is the first of several commits which will add NVM Express (NVMe)
[FreeBSD/FreeBSD.git] / sys / dev / nvme / nvme_sysctl.c
1 /*-
2  * Copyright (C) 2012 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
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
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$");
29
30 #include <sys/param.h>
31 #include <sys/bus.h>
32 #include <sys/sysctl.h>
33
34 #include "nvme_private.h"
35
36 static void
37 nvme_dump_queue(struct nvme_qpair *qpair)
38 {
39         struct nvme_completion *cpl;
40         struct nvme_command *cmd;
41         int i;
42
43         printf("id:%04Xh phase:%d\n", qpair->id, qpair->phase);
44
45         printf("Completion queue:\n");
46         for (i = 0; i < qpair->num_entries; i++) {
47                 cpl = &qpair->cpl[i];
48                 printf("%05d: ", i);
49                 nvme_dump_completion(cpl);
50         }
51
52         printf("Submission queue:\n");
53         for (i = 0; i < qpair->num_entries; i++) {
54                 cmd = &qpair->cmd[i];
55                 printf("%05d: ", i);
56                 nvme_dump_command(cmd);
57         }
58 }
59
60
61 static int
62 nvme_sysctl_dump_debug(SYSCTL_HANDLER_ARGS)
63 {
64         struct nvme_qpair       *qpair = arg1;
65         uint32_t                val = 0;
66
67         int error = sysctl_handle_int(oidp, &val, 0, req);
68
69         if (error)
70                 return (error);
71
72         if (val != 0)
73                 nvme_dump_queue(qpair);
74
75         return (0);
76 }
77
78 static int
79 nvme_sysctl_int_coal_time(SYSCTL_HANDLER_ARGS)
80 {
81         struct nvme_controller *ctrlr = arg1;
82         uint32_t oldval = ctrlr->int_coal_time;
83         int error = sysctl_handle_int(oidp, &ctrlr->int_coal_time, 0,
84             req);
85
86         if (error)
87                 return (error);
88
89         if (oldval != ctrlr->int_coal_time)
90                 nvme_ctrlr_cmd_set_interrupt_coalescing(ctrlr,
91                     ctrlr->int_coal_time, ctrlr->int_coal_threshold, NULL,
92                     NULL);
93
94         return (0);
95 }
96
97 static int
98 nvme_sysctl_int_coal_threshold(SYSCTL_HANDLER_ARGS)
99 {
100         struct nvme_controller *ctrlr = arg1;
101         uint32_t oldval = ctrlr->int_coal_threshold;
102         int error = sysctl_handle_int(oidp, &ctrlr->int_coal_threshold, 0,
103             req);
104
105         if (error)
106                 return (error);
107
108         if (oldval != ctrlr->int_coal_threshold)
109                 nvme_ctrlr_cmd_set_interrupt_coalescing(ctrlr,
110                     ctrlr->int_coal_time, ctrlr->int_coal_threshold, NULL,
111                     NULL);
112
113         return (0);
114 }
115
116 static void
117 nvme_sysctl_initialize_queue(struct nvme_qpair *qpair,
118     struct sysctl_ctx_list *ctrlr_ctx, struct sysctl_oid *que_tree)
119 {
120         struct sysctl_oid_list  *que_list = SYSCTL_CHILDREN(que_tree);
121
122         SYSCTL_ADD_UINT(ctrlr_ctx, que_list, OID_AUTO, "num_entries",
123             CTLFLAG_RD, &qpair->num_entries, 0,
124             "Number of entries in hardware queue");
125         SYSCTL_ADD_UINT(ctrlr_ctx, que_list, OID_AUTO, "num_tr",
126             CTLFLAG_RD, &qpair->num_tr, 0,
127             "Number of trackers allocated");
128         SYSCTL_ADD_UINT(ctrlr_ctx, que_list, OID_AUTO, "num_prp_list",
129             CTLFLAG_RD, &qpair->num_prp_list, 0,
130             "Number of PRP lists allocated");
131         SYSCTL_ADD_UINT(ctrlr_ctx, que_list, OID_AUTO, "sq_head",
132             CTLFLAG_RD, &qpair->sq_head, 0,
133             "Current head of submission queue (as observed by driver)");
134         SYSCTL_ADD_UINT(ctrlr_ctx, que_list, OID_AUTO, "sq_tail",
135             CTLFLAG_RD, &qpair->sq_tail, 0,
136             "Current tail of submission queue (as observed by driver)");
137         SYSCTL_ADD_UINT(ctrlr_ctx, que_list, OID_AUTO, "cq_head",
138             CTLFLAG_RD, &qpair->cq_head, 0,
139             "Current head of completion queue (as observed by driver)");
140
141         SYSCTL_ADD_QUAD(ctrlr_ctx, que_list, OID_AUTO, "num_cmds",
142             CTLFLAG_RD, &qpair->num_cmds, "Number of commands submitted");
143
144         SYSCTL_ADD_PROC(ctrlr_ctx, que_list, OID_AUTO,
145             "dump_debug", CTLTYPE_UINT | CTLFLAG_RW, qpair, 0,
146             nvme_sysctl_dump_debug, "IU", "Dump debug data");
147 }
148
149 void
150 nvme_sysctl_initialize_ctrlr(struct nvme_controller *ctrlr)
151 {
152         struct sysctl_ctx_list  *ctrlr_ctx;
153         struct sysctl_oid       *ctrlr_tree, *que_tree;
154         struct sysctl_oid_list  *ctrlr_list;
155 #define QUEUE_NAME_LENGTH       16
156         char                    queue_name[QUEUE_NAME_LENGTH];
157         int                     i;
158
159         ctrlr_ctx = device_get_sysctl_ctx(ctrlr->dev);
160         ctrlr_tree = device_get_sysctl_tree(ctrlr->dev);
161         ctrlr_list = SYSCTL_CHILDREN(ctrlr_tree);
162
163         if (ctrlr->is_started) {
164                 SYSCTL_ADD_PROC(ctrlr_ctx, ctrlr_list, OID_AUTO,
165                     "int_coal_time", CTLTYPE_UINT | CTLFLAG_RW, ctrlr, 0,
166                     nvme_sysctl_int_coal_time, "IU",
167                     "Interrupt coalescing timeout (in microseconds)");
168
169                 SYSCTL_ADD_PROC(ctrlr_ctx, ctrlr_list, OID_AUTO,
170                     "int_coal_threshold", CTLTYPE_UINT | CTLFLAG_RW, ctrlr, 0,
171                     nvme_sysctl_int_coal_threshold, "IU",
172                     "Interrupt coalescing threshold");
173         }
174
175         que_tree = SYSCTL_ADD_NODE(ctrlr_ctx, ctrlr_list, OID_AUTO, "adminq",
176             CTLFLAG_RD, NULL, "Admin Queue");
177
178         nvme_sysctl_initialize_queue(&ctrlr->adminq, ctrlr_ctx, que_tree);
179
180         for (i = 0; i < ctrlr->num_io_queues; i++) {
181                 snprintf(queue_name, QUEUE_NAME_LENGTH, "ioq%d", i);
182                 que_tree = SYSCTL_ADD_NODE(ctrlr_ctx, ctrlr_list, OID_AUTO,
183                     queue_name, CTLFLAG_RD, NULL, "IO Queue");
184                 nvme_sysctl_initialize_queue(&ctrlr->ioq[i], ctrlr_ctx,
185                     que_tree);
186         }
187 }