1 /*
2  * Copyright (c) 2013 Broadcom Corporation
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 #ifndef BRCMFMAC_FIRMWARE_H
17 #define BRCMFMAC_FIRMWARE_H
18 
19 #define BRCMF_FW_REQUEST		0x000F
20 #define  BRCMF_FW_REQUEST_NVRAM		0x0001
21 #define BRCMF_FW_REQ_FLAGS		0x00F0
22 #define  BRCMF_FW_REQ_NV_OPTIONAL	0x0010
23 
24 #define	BRCMF_FW_NAME_LEN		320
25 
26 #define BRCMF_FW_DEFAULT_PATH		"brcm/"
27 
28 /**
29  * struct brcmf_firmware_mapping - Used to map chipid/revmask to firmware
30  *	filename and nvram filename. Each bus type implementation should create
31  *	a table of firmware mappings (using the macros defined below).
32  *
33  * @chipid: ID of chip.
34  * @revmask: bitmask of revisions, e.g. 0x10 means rev 4 only, 0xf means rev 0-3
35  * @fw: name of the firmware file.
36  * @nvram: name of nvram file.
37  */
38 struct brcmf_firmware_mapping {
39 	u32 chipid;
40 	u32 revmask;
41 	const char *fw;
42 	const char *nvram;
43 };
44 
45 #define BRCMF_FW_NVRAM_DEF(fw_nvram_name, fw, nvram) \
46 static const char BRCM_ ## fw_nvram_name ## _FIRMWARE_NAME[] = \
47 	BRCMF_FW_DEFAULT_PATH fw; \
48 static const char BRCM_ ## fw_nvram_name ## _NVRAM_NAME[] = \
49 	BRCMF_FW_DEFAULT_PATH nvram; \
50 MODULE_FIRMWARE(BRCMF_FW_DEFAULT_PATH fw);
51 
52 #define BRCMF_FW_DEF(fw_name, fw) \
53 static const char BRCM_ ## fw_name ## _FIRMWARE_NAME[] = \
54 	BRCMF_FW_DEFAULT_PATH fw; \
55 MODULE_FIRMWARE(BRCMF_FW_DEFAULT_PATH fw) \
56 
57 #define BRCMF_FW_NVRAM_ENTRY(chipid, mask, name) \
58 	{ chipid, mask, \
59 	  BRCM_ ## name ## _FIRMWARE_NAME, BRCM_ ## name ## _NVRAM_NAME }
60 
61 #define BRCMF_FW_ENTRY(chipid, mask, name) \
62 	{ chipid, mask, BRCM_ ## name ## _FIRMWARE_NAME, NULL }
63 
64 int brcmf_fw_map_chip_to_name(u32 chip, u32 chiprev,
65 			      struct brcmf_firmware_mapping mapping_table[],
66 			      u32 table_size, char fw_name[BRCMF_FW_NAME_LEN],
67 			      char nvram_name[BRCMF_FW_NAME_LEN]);
68 void brcmf_fw_nvram_free(void *nvram);
69 /*
70  * Request firmware(s) asynchronously. When the asynchronous request
71  * fails it will not use the callback, but call device_release_driver()
72  * instead which will call the driver .remove() callback.
73  */
74 int brcmf_fw_get_firmwares_pcie(struct device *dev, u16 flags,
75 				const char *code, const char *nvram,
76 				void (*fw_cb)(struct device *dev,
77 					      const struct firmware *fw,
78 					      void *nvram_image, u32 nvram_len),
79 				u16 domain_nr, u16 bus_nr);
80 int brcmf_fw_get_firmwares(struct device *dev, u16 flags,
81 			   const char *code, const char *nvram,
82 			   void (*fw_cb)(struct device *dev,
83 					 const struct firmware *fw,
84 					 void *nvram_image, u32 nvram_len));
85 
86 #endif /* BRCMFMAC_FIRMWARE_H */
87