2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2013 Adrian Chadd <adrian@freebsd.org>
5 * Copyright (c) 2019 Vladimir Kondratyev <wulf@FreeBSD.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #include <sys/types.h>
32 #include <sys/endian.h>
44 #include "iwmbt_dbg.h"
47 iwmbt_fw_read(struct iwmbt_firmware *fw, const char *fwname)
55 fd = open(fwname, O_RDONLY);
57 warn("%s: open: %s", __func__, fwname);
61 if (fstat(fd, &sb) != 0) {
62 warn("%s: stat: %s", __func__, fwname);
67 buf = calloc(1, sb.st_size);
69 warn("%s: calloc", __func__);
75 /* XXX handle partial reads */
76 r = read(fd, buf, sb.st_size);
78 warn("%s: read", __func__);
84 if (r != sb.st_size) {
85 iwmbt_err("read len %d != file size %d",
93 /* We have everything, so! */
95 memset(fw, 0, sizeof(*fw));
97 fw->fwname = strdup(fwname);
106 iwmbt_fw_free(struct iwmbt_firmware *fw)
112 memset(fw, 0, sizeof(*fw));
116 iwmbt_get_fwname(struct iwmbt_version *ver, struct iwmbt_boot_params *params,
117 const char *prefix, const char *suffix)
121 switch (ver->hw_variant) {
122 case 0x0b: /* 8260 */
123 case 0x0c: /* 8265 */
124 asprintf(&fwname, "%s/ibt-%u-%u.%s",
126 le16toh(ver->hw_variant),
127 le16toh(params->dev_revid),
131 case 0x11: /* 9560 */
132 case 0x12: /* 9260 */
134 case 0x14: /* 22161 */
135 asprintf(&fwname, "%s/ibt-%u-%u-%u.%s",
137 le16toh(ver->hw_variant),
138 le16toh(ver->hw_revision),
139 le16toh(ver->fw_revision),