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