1 // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
2 /*
3  * Greybus Firmware Management User Header
4  *
5  * This file is provided under a dual BSD/GPLv2 license.  When using or
6  * redistributing this file, you may do so under either license.
7  *
8  * GPL LICENSE SUMMARY
9  *
10  * Copyright(c) 2016 Google Inc. All rights reserved.
11  * Copyright(c) 2016 Linaro Ltd. All rights reserved.
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of version 2 of the GNU General Public License as
15  * published by the Free Software Foundation.
16  *
17  * This program is distributed in the hope that it will be useful, but
18  * WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  * General Public License version 2 for more details.
21  *
22  * BSD LICENSE
23  *
24  * Copyright(c) 2016 Google Inc. All rights reserved.
25  * Copyright(c) 2016 Linaro Ltd. All rights reserved.
26  *
27  * Redistribution and use in source and binary forms, with or without
28  * modification, are permitted provided that the following conditions
29  * are met:
30  *
31  *  * Redistributions of source code must retain the above copyright
32  *    notice, this list of conditions and the following disclaimer.
33  *  * Redistributions in binary form must reproduce the above copyright
34  *    notice, this list of conditions and the following disclaimer in
35  *    the documentation and/or other materials provided with the
36  *    distribution.
37  *  * Neither the name of Google Inc. or Linaro Ltd. nor the names of
38  *    its contributors may be used to endorse or promote products
39  *    derived from this software without specific prior written
40  *    permission.
41  *
42  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
43  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
44  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
45  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC. OR
46  * LINARO LTD. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
47  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
48  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
49  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
50  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
51  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
52  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53  */
54 
55 #ifndef __GREYBUS_FIRMWARE_USER_H
56 #define __GREYBUS_FIRMWARE_USER_H
57 
58 #include <linux/ioctl.h>
59 #include <linux/types.h>
60 
61 #define GB_FIRMWARE_U_TAG_MAX_SIZE		10
62 
63 #define GB_FW_U_LOAD_METHOD_UNIPRO		0x01
64 #define GB_FW_U_LOAD_METHOD_INTERNAL		0x02
65 
66 #define GB_FW_U_LOAD_STATUS_FAILED		0x00
67 #define GB_FW_U_LOAD_STATUS_UNVALIDATED		0x01
68 #define GB_FW_U_LOAD_STATUS_VALIDATED		0x02
69 #define GB_FW_U_LOAD_STATUS_VALIDATION_FAILED	0x03
70 
71 #define GB_FW_U_BACKEND_FW_STATUS_SUCCESS	0x01
72 #define GB_FW_U_BACKEND_FW_STATUS_FAIL_FIND	0x02
73 #define GB_FW_U_BACKEND_FW_STATUS_FAIL_FETCH	0x03
74 #define GB_FW_U_BACKEND_FW_STATUS_FAIL_WRITE	0x04
75 #define GB_FW_U_BACKEND_FW_STATUS_INT		0x05
76 #define GB_FW_U_BACKEND_FW_STATUS_RETRY		0x06
77 #define GB_FW_U_BACKEND_FW_STATUS_NOT_SUPPORTED	0x07
78 
79 #define GB_FW_U_BACKEND_VERSION_STATUS_SUCCESS		0x01
80 #define GB_FW_U_BACKEND_VERSION_STATUS_NOT_AVAILABLE	0x02
81 #define GB_FW_U_BACKEND_VERSION_STATUS_NOT_SUPPORTED	0x03
82 #define GB_FW_U_BACKEND_VERSION_STATUS_RETRY		0x04
83 #define GB_FW_U_BACKEND_VERSION_STATUS_FAIL_INT		0x05
84 
85 /* IOCTL support */
86 struct fw_mgmt_ioc_get_intf_version {
87 	__u8 firmware_tag[GB_FIRMWARE_U_TAG_MAX_SIZE];
88 	__u16 major;
89 	__u16 minor;
90 } __attribute__ ((__packed__));
91 
92 struct fw_mgmt_ioc_get_backend_version {
93 	__u8 firmware_tag[GB_FIRMWARE_U_TAG_MAX_SIZE];
94 	__u16 major;
95 	__u16 minor;
96 	__u8 status;
97 } __attribute__ ((__packed__));
98 
99 struct fw_mgmt_ioc_intf_load_and_validate {
100 	__u8 firmware_tag[GB_FIRMWARE_U_TAG_MAX_SIZE];
101 	__u8 load_method;
102 	__u8 status;
103 	__u16 major;
104 	__u16 minor;
105 } __attribute__ ((__packed__));
106 
107 struct fw_mgmt_ioc_backend_fw_update {
108 	__u8 firmware_tag[GB_FIRMWARE_U_TAG_MAX_SIZE];
109 	__u8 status;
110 } __attribute__ ((__packed__));
111 
112 #define FW_MGMT_IOCTL_BASE			'F'
113 #define FW_MGMT_IOC_GET_INTF_FW			_IOR(FW_MGMT_IOCTL_BASE, 0, struct fw_mgmt_ioc_get_intf_version)
114 #define FW_MGMT_IOC_GET_BACKEND_FW		_IOWR(FW_MGMT_IOCTL_BASE, 1, struct fw_mgmt_ioc_get_backend_version)
115 #define FW_MGMT_IOC_INTF_LOAD_AND_VALIDATE	_IOWR(FW_MGMT_IOCTL_BASE, 2, struct fw_mgmt_ioc_intf_load_and_validate)
116 #define FW_MGMT_IOC_INTF_BACKEND_FW_UPDATE	_IOWR(FW_MGMT_IOCTL_BASE, 3, struct fw_mgmt_ioc_backend_fw_update)
117 #define FW_MGMT_IOC_SET_TIMEOUT_MS		_IOW(FW_MGMT_IOCTL_BASE, 4, unsigned int)
118 #define FW_MGMT_IOC_MODE_SWITCH			_IO(FW_MGMT_IOCTL_BASE, 5)
119 
120 #endif /* __GREYBUS_FIRMWARE_USER_H */
121 
122