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