xref: /freebsd-13-stable/sys/dev/qlxge/qls_ioctl.c (revision 3bc80996974a61a4223eae4c1ccd47b6ee32a48a)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2013-2014 Qlogic Corporation
5  * All rights reserved.
6  *
7  *  Redistribution and use in source and binary forms, with or without
8  *  modification, are permitted provided that the following conditions
9  *  are met:
10  *
11  *  1. Redistributions of source code must retain the above copyright
12  *     notice, this list of conditions and the following disclaimer.
13  *  2. Redistributions in binary form must reproduce the above copyright
14  *     notice, this list of conditions and the following disclaimer in the
15  *     documentation and/or other materials provided with the distribution.
16  *
17  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  *  POSSIBILITY OF SUCH DAMAGE.
28  */
29 /*
30  * File: qls_ioctl.c
31  * Author : David C Somayajulu, Qlogic Corporation, Aliso Viejo, CA 92656.
32  */
33 #include <sys/cdefs.h>
34 #include "qls_os.h"
35 #include "qls_hw.h"
36 #include "qls_def.h"
37 #include "qls_inline.h"
38 #include "qls_glbl.h"
39 #include "qls_ioctl.h"
40 #include "qls_dump.h"
41 extern qls_mpi_coredump_t ql_mpi_coredump;
42 
43 static int qls_eioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag,
44 		struct thread *td);
45 
46 static struct cdevsw qla_cdevsw = {
47 	.d_version = D_VERSION,
48 	.d_ioctl = qls_eioctl,
49 	.d_name = "qlxge",
50 };
51 
52 int
qls_make_cdev(qla_host_t * ha)53 qls_make_cdev(qla_host_t *ha)
54 {
55         ha->ioctl_dev = make_dev(&qla_cdevsw,
56 				ha->ifp->if_dunit,
57                                 UID_ROOT,
58                                 GID_WHEEL,
59                                 0600,
60                                 "%s",
61                                 if_name(ha->ifp));
62 
63 	if (ha->ioctl_dev == NULL)
64 		return (-1);
65 
66         ha->ioctl_dev->si_drv1 = ha;
67 
68 	return (0);
69 }
70 
71 void
qls_del_cdev(qla_host_t * ha)72 qls_del_cdev(qla_host_t *ha)
73 {
74 	if (ha->ioctl_dev != NULL)
75 		destroy_dev(ha->ioctl_dev);
76 	return;
77 }
78 
79 static int
qls_eioctl(struct cdev * dev,u_long cmd,caddr_t data,int fflag,struct thread * td)80 qls_eioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag,
81         struct thread *td)
82 {
83         qla_host_t *ha;
84         int rval = 0;
85 	device_t pci_dev;
86 
87 	qls_mpi_dump_t *mpi_dump;
88 
89         if ((ha = (qla_host_t *)dev->si_drv1) == NULL)
90                 return ENXIO;
91 
92 	pci_dev= ha->pci_dev;
93 
94         switch(cmd) {
95 	case QLA_MPI_DUMP:
96 		mpi_dump = (qls_mpi_dump_t *)data;
97 
98 		if (mpi_dump->size == 0) {
99 			mpi_dump->size = sizeof (qls_mpi_coredump_t);
100 		} else {
101 			if ((mpi_dump->size != sizeof (qls_mpi_coredump_t)) ||
102 				(mpi_dump->dbuf == NULL))
103 				rval = EINVAL;
104 			else {
105 				if (qls_mpi_core_dump(ha) == 0) {
106 					rval = copyout(&ql_mpi_coredump,
107 							mpi_dump->dbuf,
108 							mpi_dump->size);
109 				} else
110 					rval = ENXIO;
111 
112 				if (rval) {
113 					device_printf(ha->pci_dev,
114 						"%s: mpidump failed[%d]\n",
115 						__func__, rval);
116 				}
117 			}
118 		}
119 
120 		break;
121         default:
122                 break;
123         }
124 
125         return rval;
126 }
127