Lines Matching +full:pcie +full:- +full:mac

1 // SPDX-License-Identifier: ISC
21 #define BRCMF_FW_NVRAM_DEVPATH_LEN 19 /* devpath0=pcie/1/4/ */
22 #define BRCMF_FW_NVRAM_PCIEDEV_LEN 20 /* pcie/1/4/ + \0 */
36 * struct nvram_parser - internal info for parser.
46 * @multi_dev_v1: detect pcie multi device v1 (compressed).
47 * @multi_dev_v2: detect pcie multi device v2.
49 * @strip_mac: strip the MAC address.
67 * is_nvram_char() - check if char is a valid one for NVRAM entry
91 c = nvp->data[nvp->pos]; in brcmf_nvram_handle_idle()
99 nvp->entry = nvp->pos; in brcmf_nvram_handle_idle()
103 nvp->line, nvp->column); in brcmf_nvram_handle_idle()
105 nvp->column++; in brcmf_nvram_handle_idle()
106 nvp->pos++; in brcmf_nvram_handle_idle()
112 enum nvram_parser_state st = nvp->state; in brcmf_nvram_handle_key()
115 c = nvp->data[nvp->pos]; in brcmf_nvram_handle_key()
118 if (strncmp(&nvp->data[nvp->entry], "RAW1", 4) == 0) in brcmf_nvram_handle_key()
122 if (strncmp(&nvp->data[nvp->entry], "devpath", 7) == 0) in brcmf_nvram_handle_key()
123 nvp->multi_dev_v1 = true; in brcmf_nvram_handle_key()
124 if (strncmp(&nvp->data[nvp->entry], "pcie/", 5) == 0) in brcmf_nvram_handle_key()
125 nvp->multi_dev_v2 = true; in brcmf_nvram_handle_key()
126 if (strncmp(&nvp->data[nvp->entry], "boardrev", 8) == 0) in brcmf_nvram_handle_key()
127 nvp->boardrev_found = true; in brcmf_nvram_handle_key()
128 /* strip macaddr if platform MAC overrides */ in brcmf_nvram_handle_key()
129 if (nvp->strip_mac && in brcmf_nvram_handle_key()
130 strncmp(&nvp->data[nvp->entry], "macaddr", 7) == 0) in brcmf_nvram_handle_key()
134 nvp->line, nvp->column); in brcmf_nvram_handle_key()
138 nvp->column++; in brcmf_nvram_handle_key()
139 nvp->pos++; in brcmf_nvram_handle_key()
151 c = nvp->data[nvp->pos]; in brcmf_nvram_handle_value()
154 ekv = (u8 *)&nvp->data[nvp->pos]; in brcmf_nvram_handle_value()
155 skv = (u8 *)&nvp->data[nvp->entry]; in brcmf_nvram_handle_value()
156 cplen = ekv - skv; in brcmf_nvram_handle_value()
157 if (nvp->nvram_len + cplen + 1 >= BRCMF_FW_MAX_NVRAM_SIZE) in brcmf_nvram_handle_value()
160 memcpy(&nvp->nvram[nvp->nvram_len], skv, cplen); in brcmf_nvram_handle_value()
161 nvp->nvram_len += cplen; in brcmf_nvram_handle_value()
162 nvp->nvram[nvp->nvram_len] = '\0'; in brcmf_nvram_handle_value()
163 nvp->nvram_len++; in brcmf_nvram_handle_value()
166 nvp->pos++; in brcmf_nvram_handle_value()
167 nvp->column++; in brcmf_nvram_handle_value()
176 sol = (char *)&nvp->data[nvp->pos]; in brcmf_nvram_handle_comment()
185 nvp->line++; in brcmf_nvram_handle_comment()
186 nvp->column = 1; in brcmf_nvram_handle_comment()
187 nvp->pos += (eoc - sol) + 1; in brcmf_nvram_handle_comment()
212 nvp->data = data; in brcmf_init_nvram_parser()
223 nvp->nvram = kzalloc(size, GFP_KERNEL); in brcmf_init_nvram_parser()
224 if (!nvp->nvram) in brcmf_init_nvram_parser()
225 return -ENOMEM; in brcmf_init_nvram_parser()
227 nvp->line = 1; in brcmf_init_nvram_parser()
228 nvp->column = 1; in brcmf_init_nvram_parser()
240 /* Device path with a leading '=' key-value separator */ in brcmf_fw_strip_multi_v1()
251 nvram = kzalloc(nvp->nvram_len + 1 + 3 + sizeof(u32), GFP_KERNEL); in brcmf_fw_strip_multi_v1()
255 /* min length: devpath0=pcie/1/4/ + 0:x=y */ in brcmf_fw_strip_multi_v1()
256 if (nvp->nvram_len < BRCMF_FW_NVRAM_DEVPATH_LEN + 6) in brcmf_fw_strip_multi_v1()
265 snprintf(pcie_path, sizeof(pcie_path), "=pcie/%d/%d", domain_nr, in brcmf_fw_strip_multi_v1()
270 while (i < nvp->nvram_len - BRCMF_FW_NVRAM_DEVPATH_LEN) { in brcmf_fw_strip_multi_v1()
271 /* Format: devpathX=pcie/Y/Z/ in brcmf_fw_strip_multi_v1()
274 if (strncmp(&nvp->nvram[i], "devpath", 7) == 0 && in brcmf_fw_strip_multi_v1()
275 (!strncmp(&nvp->nvram[i + 8], pci_path, pci_len) || in brcmf_fw_strip_multi_v1()
276 !strncmp(&nvp->nvram[i + 8], pcie_path, pcie_len))) { in brcmf_fw_strip_multi_v1()
277 id = nvp->nvram[i + 7] - '0'; in brcmf_fw_strip_multi_v1()
281 while (nvp->nvram[i] != 0) in brcmf_fw_strip_multi_v1()
291 while (i < nvp->nvram_len) { in brcmf_fw_strip_multi_v1()
292 if ((nvp->nvram[i] - '0' == id) && (nvp->nvram[i + 1] == ':')) { in brcmf_fw_strip_multi_v1()
294 if (strncmp(&nvp->nvram[i], "boardrev", 8) == 0) in brcmf_fw_strip_multi_v1()
295 nvp->boardrev_found = true; in brcmf_fw_strip_multi_v1()
296 while (nvp->nvram[i] != 0) { in brcmf_fw_strip_multi_v1()
297 nvram[j] = nvp->nvram[i]; in brcmf_fw_strip_multi_v1()
304 while (nvp->nvram[i] != 0) in brcmf_fw_strip_multi_v1()
308 kfree(nvp->nvram); in brcmf_fw_strip_multi_v1()
309 nvp->nvram = nvram; in brcmf_fw_strip_multi_v1()
310 nvp->nvram_len = j; in brcmf_fw_strip_multi_v1()
315 nvp->nvram_len = 0; in brcmf_fw_strip_multi_v1()
322 * pcie/domain_nr/bus_nr:
332 nvram = kzalloc(nvp->nvram_len + 1 + 3 + sizeof(u32), GFP_KERNEL); in brcmf_fw_strip_multi_v2()
334 nvp->nvram_len = 0; in brcmf_fw_strip_multi_v2()
339 * Valid entries are of type pcie/X/Y/ where X = domain_nr and in brcmf_fw_strip_multi_v2()
342 snprintf(prefix, sizeof(prefix), "pcie/%d/%d/", domain_nr, bus_nr); in brcmf_fw_strip_multi_v2()
346 while (i < nvp->nvram_len - len) { in brcmf_fw_strip_multi_v2()
347 if (strncmp(&nvp->nvram[i], prefix, len) == 0) { in brcmf_fw_strip_multi_v2()
349 if (strncmp(&nvp->nvram[i], "boardrev", 8) == 0) in brcmf_fw_strip_multi_v2()
350 nvp->boardrev_found = true; in brcmf_fw_strip_multi_v2()
351 while (nvp->nvram[i] != 0) { in brcmf_fw_strip_multi_v2()
352 nvram[j] = nvp->nvram[i]; in brcmf_fw_strip_multi_v2()
359 while (nvp->nvram[i] != 0) in brcmf_fw_strip_multi_v2()
363 kfree(nvp->nvram); in brcmf_fw_strip_multi_v2()
364 nvp->nvram = nvram; in brcmf_fw_strip_multi_v2()
365 nvp->nvram_len = j; in brcmf_fw_strip_multi_v2()
370 if (nvp->boardrev_found) in brcmf_fw_add_defaults()
373 memcpy(&nvp->nvram[nvp->nvram_len], &BRCMF_FW_DEFAULT_BOARDREV, in brcmf_fw_add_defaults()
375 nvp->nvram_len += strlen(BRCMF_FW_DEFAULT_BOARDREV); in brcmf_fw_add_defaults()
376 nvp->nvram[nvp->nvram_len] = '\0'; in brcmf_fw_add_defaults()
377 nvp->nvram_len++; in brcmf_fw_add_defaults()
380 static void brcmf_fw_add_macaddr(struct nvram_parser *nvp, u8 *mac) in brcmf_fw_add_macaddr() argument
384 len = scnprintf(&nvp->nvram[nvp->nvram_len], BRCMF_FW_MACADDR_LEN + 1, in brcmf_fw_add_macaddr()
385 BRCMF_FW_MACADDR_FMT, mac); in brcmf_fw_add_macaddr()
387 nvp->nvram_len += len + 1; in brcmf_fw_add_macaddr()
403 u8 mac[ETH_ALEN]; in brcmf_fw_nvram_strip() local
408 if (eth_platform_get_mac_address(dev, mac) == 0) in brcmf_fw_nvram_strip()
432 brcmf_fw_add_macaddr(&nvp, mac); in brcmf_fw_nvram_strip()
465 /* In some cases the EFI-var stored nvram contains "ccode=ALL" or "ccode=XV"
466 * to specify "worldwide" compatible settings, but these 2 ccode-s do not work
470 * no-Initiate-Radiation mode. This means that we will never send on these
529 for (i = 0, item = &req->items[0]; i < req->n_items; i++, item++) { in brcmf_fw_free_request()
530 if (item->type == BRCMF_FW_TYPE_BINARY) in brcmf_fw_free_request()
531 release_firmware(item->binary); in brcmf_fw_free_request()
532 else if (item->type == BRCMF_FW_TYPE_NVRAM) in brcmf_fw_free_request()
533 brcmf_fw_nvram_free(item->nv_data.data); in brcmf_fw_free_request()
549 brcmf_dbg(TRACE, "enter: dev=%s\n", dev_name(fwctx->dev)); in brcmf_fw_request_nvram_done()
551 cur = &fwctx->req->items[fwctx->curpos]; in brcmf_fw_request_nvram_done()
553 if (fw && fw->data) { in brcmf_fw_request_nvram_done()
554 data = (u8 *)fw->data; in brcmf_fw_request_nvram_done()
555 data_len = fw->size; in brcmf_fw_request_nvram_done()
561 else if (!(cur->flags & BRCMF_FW_REQF_OPTIONAL)) in brcmf_fw_request_nvram_done()
567 fwctx->req->domain_nr, in brcmf_fw_request_nvram_done()
568 fwctx->req->bus_nr, in brcmf_fw_request_nvram_done()
569 fwctx->dev); in brcmf_fw_request_nvram_done()
577 if (!nvram && !(cur->flags & BRCMF_FW_REQF_OPTIONAL)) in brcmf_fw_request_nvram_done()
581 cur->nv_data.data = nvram; in brcmf_fw_request_nvram_done()
582 cur->nv_data.len = nvram_length; in brcmf_fw_request_nvram_done()
586 return -ENOENT; in brcmf_fw_request_nvram_done()
592 struct brcmf_fw_item *cur = &fwctx->req->items[fwctx->curpos]; in brcmf_fw_complete_request()
595 brcmf_dbg(TRACE, "firmware %s %sfound\n", cur->path, fw ? "" : "not "); in brcmf_fw_complete_request()
597 switch (cur->type) { in brcmf_fw_complete_request()
603 cur->binary = fw; in brcmf_fw_complete_request()
605 ret = -ENOENT; in brcmf_fw_complete_request()
609 brcmf_err("unknown fw type: %d\n", cur->type); in brcmf_fw_complete_request()
611 ret = -EINVAL; in brcmf_fw_complete_request()
614 return (cur->flags & BRCMF_FW_REQF_OPTIONAL) ? 0 : ret; in brcmf_fw_complete_request()
632 base[suffix - path] = 0; in brcm_alt_fw_path()
647 struct brcmf_fw_item *cur = &fwctx->req->items[fwctx->curpos]; in brcmf_fw_request_firmware()
651 /* Files can be board-specific, first try board-specific paths */ in brcmf_fw_request_firmware()
652 for (i = 0; i < ARRAY_SIZE(fwctx->req->board_types); i++) { in brcmf_fw_request_firmware()
655 if (!fwctx->req->board_types[i]) in brcmf_fw_request_firmware()
657 alt_path = brcm_alt_fw_path(cur->path, in brcmf_fw_request_firmware()
658 fwctx->req->board_types[i]); in brcmf_fw_request_firmware()
662 ret = firmware_request_nowarn(fw, alt_path, fwctx->dev); in brcmf_fw_request_firmware()
669 return request_firmware(fw, cur->path, fwctx->dev); in brcmf_fw_request_firmware()
679 while (ret == 0 && ++fwctx->curpos < fwctx->req->n_items) { in brcmf_fw_request_done()
685 brcmf_fw_free_request(fwctx->req); in brcmf_fw_request_done()
686 fwctx->req = NULL; in brcmf_fw_request_done()
688 fwctx->done(fwctx->dev, ret, fwctx->req); in brcmf_fw_request_done()
695 struct brcmf_fw_item *first = &fwctx->req->items[0]; in brcmf_fw_request_done_alt_path()
705 if (fwctx->board_index < ARRAY_SIZE(fwctx->req->board_types)) { in brcmf_fw_request_done_alt_path()
706 board_type = fwctx->req->board_types[fwctx->board_index++]; in brcmf_fw_request_done_alt_path()
709 alt_path = brcm_alt_fw_path(first->path, board_type); in brcmf_fw_request_done_alt_path()
714 fwctx->dev, GFP_KERNEL, fwctx, in brcmf_fw_request_done_alt_path()
725 ret = request_firmware_nowait(THIS_MODULE, true, first->path, in brcmf_fw_request_done_alt_path()
726 fwctx->dev, GFP_KERNEL, fwctx, in brcmf_fw_request_done_alt_path()
738 if (!req->n_items) in brcmf_fw_request_is_valid()
741 for (i = 0, item = &req->items[0]; i < req->n_items; i++, item++) { in brcmf_fw_request_is_valid()
742 if (!item->path) in brcmf_fw_request_is_valid()
752 struct brcmf_fw_item *first = &req->items[0]; in brcmf_fw_get_firmwares()
759 return -EINVAL; in brcmf_fw_get_firmwares()
762 return -EINVAL; in brcmf_fw_get_firmwares()
766 return -ENOMEM; in brcmf_fw_get_firmwares()
768 fwctx->dev = dev; in brcmf_fw_get_firmwares()
769 fwctx->req = req; in brcmf_fw_get_firmwares()
770 fwctx->done = fw_cb; in brcmf_fw_get_firmwares()
772 /* First try alternative board-specific path if any */ in brcmf_fw_get_firmwares()
773 if (fwctx->req->board_types[0]) in brcmf_fw_get_firmwares()
774 alt_path = brcm_alt_fw_path(first->path, in brcmf_fw_get_firmwares()
775 fwctx->req->board_types[0]); in brcmf_fw_get_firmwares()
777 fwctx->board_index++; in brcmf_fw_get_firmwares()
779 fwctx->dev, GFP_KERNEL, fwctx, in brcmf_fw_get_firmwares()
783 ret = request_firmware_nowait(THIS_MODULE, true, first->path, in brcmf_fw_get_firmwares()
784 fwctx->dev, GFP_KERNEL, fwctx, in brcmf_fw_get_firmwares()
834 end = mp_path[mp_path_len - 1]; in brcmf_fw_alloc_request()
836 fwreq->n_items = n_fwnames; in brcmf_fw_alloc_request()
839 fwreq->items[j].path = fwnames[j].path; in brcmf_fw_alloc_request()
855 fwreq->items[j].path = fwnames[j].path; in brcmf_fw_alloc_request()