xref: /linux/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.h (revision 02680c23d7b3febe45ea3d4f9818c2b2dc89020a)
1 // SPDX-License-Identifier: ISC
2 /*
3  * Copyright (c) 2013 Broadcom Corporation
4  */
5 #ifndef BRCMFMAC_FIRMWARE_H
6 #define BRCMFMAC_FIRMWARE_H
7 
8 #define BRCMF_FW_REQF_OPTIONAL		0x0001
9 
10 #define	BRCMF_FW_NAME_LEN		320
11 
12 #define BRCMF_FW_DEFAULT_PATH		"brcm/"
13 
14 /**
15  * struct brcmf_firmware_mapping - Used to map chipid/revmask to firmware
16  *	filename and nvram filename. Each bus type implementation should create
17  *	a table of firmware mappings (using the macros defined below).
18  *
19  * @chipid: ID of chip.
20  * @revmask: bitmask of revisions, e.g. 0x10 means rev 4 only, 0xf means rev 0-3
21  * @fw: name of the firmware file.
22  * @nvram: name of nvram file.
23  */
24 struct brcmf_firmware_mapping {
25 	u32 chipid;
26 	u32 revmask;
27 	const char *fw_base;
28 };
29 
30 #define BRCMF_FW_DEF(fw_name, fw_base) \
31 static const char BRCM_ ## fw_name ## _FIRMWARE_BASENAME[] = \
32 	BRCMF_FW_DEFAULT_PATH fw_base; \
33 MODULE_FIRMWARE(BRCMF_FW_DEFAULT_PATH fw_base ".bin")
34 
35 #define BRCMF_FW_ENTRY(chipid, mask, name) \
36 	{ chipid, mask, BRCM_ ## name ## _FIRMWARE_BASENAME }
37 
38 void brcmf_fw_nvram_free(void *nvram);
39 
40 enum brcmf_fw_type {
41 	BRCMF_FW_TYPE_BINARY,
42 	BRCMF_FW_TYPE_NVRAM
43 };
44 
45 struct brcmf_fw_item {
46 	const char *path;
47 	enum brcmf_fw_type type;
48 	u16 flags;
49 	union {
50 		const struct firmware *binary;
51 		struct {
52 			void *data;
53 			u32 len;
54 		} nv_data;
55 	};
56 };
57 
58 struct brcmf_fw_request {
59 	u16 domain_nr;
60 	u16 bus_nr;
61 	u32 n_items;
62 	const char *board_type;
63 	struct brcmf_fw_item items[];
64 };
65 
66 struct brcmf_fw_name {
67 	const char *extension;
68 	char *path;
69 };
70 
71 struct brcmf_fw_request *
72 brcmf_fw_alloc_request(u32 chip, u32 chiprev,
73 		       const struct brcmf_firmware_mapping mapping_table[],
74 		       u32 table_size, struct brcmf_fw_name *fwnames,
75 		       u32 n_fwnames);
76 
77 /*
78  * Request firmware(s) asynchronously. When the asynchronous request
79  * fails it will not use the callback, but call device_release_driver()
80  * instead which will call the driver .remove() callback.
81  */
82 int brcmf_fw_get_firmwares(struct device *dev, struct brcmf_fw_request *req,
83 			   void (*fw_cb)(struct device *dev, int err,
84 					 struct brcmf_fw_request *req));
85 
86 #endif /* BRCMFMAC_FIRMWARE_H */
87