xref: /freebsd/sys/dev/mwl/mwldiag.h (revision 8aac90f18aef7c9eea906c3ff9a001ca7b94f375)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2007-2009 Sam Leffler, Errno Consulting
5  * Copyright (c) 2007-2009 Marvell Semiconductor, Inc.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer,
13  *    without modification.
14  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
15  *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
16  *    redistribution must be conditioned upon including a substantially
17  *    similar Disclaimer requirement for further binary redistribution.
18  *
19  * NO WARRANTY
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
23  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
24  * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
25  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
28  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30  * THE POSSIBILITY OF SUCH DAMAGES.
31  */
32 
33 #ifndef _MWL_DIAG_H_
34 #define	_MWL_DIAG_H_
35 /*
36  * Diagnostic interface.  This is an open-ended interface that
37  * is opaque to applications.  Diagnostic programs use this to
38  * retrieve internal data structures, etc.  There is no guarantee
39  * that calling conventions for calls other than MWL_DIAG_REVS
40  * are stable between HAL releases; a diagnostic application must
41  * use the HAL revision information to deal with ABI/API differences.
42  *
43  * NB: do not renumber these, certain codes are publicly used.
44  */
45 enum {
46 	MWL_DIAG_CMD_REVS	= 0,	/* MAC/PHY/Radio revs */
47 	MWL_DIAG_CMD_REGS	= 1,	/* Registers */
48 	MWL_DIAG_CMD_HOSTCMD	= 2,	/* issue arbitrary cmd */
49 	MWL_DIAG_CMD_FWLOAD	= 3,	/* load firmware */
50 };
51 
52 /*
53  * Device revision information.
54  */
55 typedef struct {
56 	uint16_t	mh_devid;		/* PCI device ID */
57 	uint16_t	mh_subvendorid;		/* PCI subvendor ID */
58 	uint16_t	mh_macRev;		/* MAC revision */
59 	uint16_t	mh_phyRev;		/* PHY revision */
60 } MWL_DIAG_REVS;
61 
62 typedef struct {
63 	uint16_t	start;		/* first register */
64 	uint16_t	end;		/* ending register or zero */
65 } MWL_DIAG_REGRANGE;
66 
67 /*
68  * Registers are mapped into virtual banks; the hal converts
69  * r/w operations through the diag api to host cmds as required.
70  *
71  * NB: register offsets are 16-bits and we need to avoid real
72  *     register mappings in BAR1.
73  */
74 #define	MWL_DIAG_BASE_MAC	0xa000
75 #define	MWL_DIAG_ISMAC(r) \
76 	(MWL_DIAG_BASE_MAC <= (r) && (r) < (MWL_DIAG_BASE_MAC+0x1000))
77 #define	MWL_DIAG_BASE_BB	0xe000
78 #define	MWL_DIAG_ISBB(r) \
79 	(MWL_DIAG_BASE_BB <= (r) && (r) < (MWL_DIAG_BASE_BB+0x1000))
80 #define	MWL_DIAG_BASE_RF	0xf000
81 #define	MWL_DIAG_ISRF(r) \
82 	(MWL_DIAG_BASE_RF <= (r) && (r) < (MWL_DIAG_BASE_RF+0x1000))
83 
84 /*
85  * Firmware download
86  */
87 typedef struct {
88 	uint32_t	opmode;			/* operating mode */
89 	uint32_t	signature;		/* f/w ready signature */
90 	char		name[1];		/* variable length pathname */
91 } MWL_DIAG_FWLOAD;
92 
93 struct mwl_diag {
94 	char	md_name[IFNAMSIZ];	/* if name, e.g. "mv0" */
95 	uint16_t md_id;
96 #define	MWL_DIAG_DYN	0x8000		/* allocate buffer in caller */
97 #define	MWL_DIAG_IN	0x4000		/* copy in parameters */
98 #define	MWL_DIAG_OUT	0x0000		/* copy out results (always) */
99 #define	MWL_DIAG_ID	0x0fff
100 	uint16_t md_in_size;		/* pack to fit, yech */
101 	void *	md_in_data;
102 	void *	md_out_data;
103 	u_int	md_out_size;
104 
105 };
106 #define	SIOCGMVDIAG	_IOWR('i', 138, struct mwl_diag)
107 #define	SIOCGMVRESET	_IOW('i', 139, struct mwl_diag)
108 #endif /* _MWL_DIAG_H_ */
109