Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FS#1734 - pci-ath9k-fixup is never called on ath79 #6707

Closed
openwrt-bot opened this issue Aug 4, 2018 · 11 comments
Closed

FS#1734 - pci-ath9k-fixup is never called on ath79 #6707

openwrt-bot opened this issue Aug 4, 2018 · 11 comments
Labels

Comments

@openwrt-bot
Copy link

Pilot6:

I am building an ath79 image for DIR825b1.
It has 2 PCIE wireless AR922x adapters.

When QCA firmware is not loaded they have ff1d device PCI IDs.
On ar71xx there was pci-ath9k-fixup that loaded the firmware and the ID changed to 0029.

On ath79 it is never called and firmware doesn't load.
hotplug "firmware" event isn't called either.

So there is no way to enable the device.

@openwrt-bot
Copy link
Author

mkresin:

Please try to add the kmod-owl-loader (target/linux/generic/files/drivers/misc/owl-loader.c) to your image. the owl-loader is supposed to do the fixup.

@openwrt-bot
Copy link
Author

Pilot6:

Yes, it moves forward the issue.
I have the firmware files already extracted to /lib/firmware.

owl-loader loads from them successfully and the id changes to 0x0029.

owl-loader als checks the magic 0xa55a and is satisfied with it.

But ath complains

Sat Aug 4 19:06:37 2018 kern.warn kernel: [ 40.321785] PCI: Enabling device 0000:00:11.0 (0000 -> 0002)
Sat Aug 4 19:06:37 2018 kern.warn kernel: [ 40.327630] PCI: Enabling device 0000:00:12.0 (0000 -> 0002)
Sat Aug 4 19:06:37 2018 kern.info kernel: [ 40.334441] owl-loader 0000:00:11.0: fixup device configuration
Sat Aug 4 19:06:37 2018 kern.debug kernel: [ 40.341886] pci 0000:00:11.0: [168c:0029] type 00 class 0x028000
Sat Aug 4 19:06:37 2018 kern.debug kernel: [ 40.341921] pci 0000:00:11.0: reg 0x10: [mem 0x10000000-0x1000ffff]
Sat Aug 4 19:06:37 2018 kern.debug kernel: [ 40.341987] pci 0000:00:11.0: PME# supported from D0 D3hot
Sat Aug 4 19:06:37 2018 kern.info kernel: [ 40.342187] pci 0000:00:11.0: BAR 0: assigned [mem 0x10000000-0x1000ffff]
Sat Aug 4 19:06:37 2018 kern.info kernel: [ 40.352139] owl-loader 0000:00:12.0: fixup device configuration
Sat Aug 4 19:06:37 2018 kern.debug kernel: [ 40.359643] pci 0000:00:12.0: [168c:0029] type 00 class 0x028000
Sat Aug 4 19:06:37 2018 kern.debug kernel: [ 40.359678] pci 0000:00:12.0: reg 0x10: [mem 0x10010000-0x1001ffff]
Sat Aug 4 19:06:37 2018 kern.debug kernel: [ 40.359744] pci 0000:00:12.0: PME# supported from D0 D3hot
Sat Aug 4 19:06:37 2018 kern.info kernel: [ 40.359949] pci 0000:00:12.0: BAR 0: assigned [mem 0x10010000-0x1001ffff]
Sat Aug 4 19:06:37 2018 kern.info kernel: [ 40.383225] xt_time: kernel timezone is -0000
Sat Aug 4 19:06:37 2018 kern.info kernel: [ 40.432460] PPP generic driver version 2.4.2
Sat Aug 4 19:06:37 2018 kern.info kernel: [ 40.438975] NET: Registered protocol family 24
Sat Aug 4 19:06:37 2018 kern.warn kernel: [ 40.472882] PCI: Enabling device 0000:00:11.0 (0000 -> 0002)
Sat Aug 4 19:06:37 2018 kern.err kernel: [ 42.035042] ath: phy0: Invalid EEPROM magic (0x0000).
Sat Aug 4 19:06:37 2018 kern.err kernel: [ 42.040085] ath: phy0: Unable to initialize hardware; initialization status: -22
Sat Aug 4 19:06:37 2018 kern.err kernel: [ 42.047475] ath9k 0000:00:11.0: Failed to initialize device
Sat Aug 4 19:06:37 2018 kern.warn kernel: [ 42.053098] ath9k: probe of 0000:00:11.0 failed with error -22
Sat Aug 4 19:06:37 2018 kern.warn kernel: [ 42.058984] PCI: Enabling device 0000:00:12.0 (0000 -> 0002)
Sat Aug 4 19:06:37 2018 kern.err kernel: [ 43.621111] ath: phy1: Invalid EEPROM magic (0x0000).
Sat Aug 4 19:06:37 2018 kern.err kernel: [ 43.626164] ath: phy1: Unable to initialize hardware; initialization status: -22
Sat Aug 4 19:06:37 2018 kern.err kernel: [ 43.633551] ath9k 0000:00:12.0: Failed to initialize device
Sat Aug 4 19:06:37 2018 kern.warn kernel: [ 43.639158] ath9k: probe of 0000:00:12.0 failed with error -22

@openwrt-bot
Copy link
Author

Pilot6:

I see that owl-loader sets

pdata->eeprom_name = NULL;

it is supposed that in ath9k/init.c firmare won't try to load again, but it does for some reason.

And also what is wierd that it gets 0x0000 fro the beginning of the same file.

And I removed "qca,no-eeprom" from the dts file.

@openwrt-bot
Copy link
Author

mkresin:

You mix things up here. First of all your wireless doesn't seem to have an eeprom and hence reports the bogus pci id. Therefore the "qca,no-eeprom" should be required.

The second part of the story are the calibration data. These are required in all cases. owl-loader only injects the eeprom into the pci config space to fixup the pci id and so on. To my knowledge the calibration data still need to be applied/considered by the driver.

Would you please provide a full dump of the partition containing the eeprom/caldata (should caldata and maybe unknown) plus your changes to target/linux/ath79/base-files/etc/hotplug.d/firmware/.

@openwrt-bot
Copy link
Author

Pilot6:

OK. I'll try to explain my findings better.

  1. I didn't change the hotplug script yet and did the job manually. I extracted firmware from caldata and placed it to /lib/firmware/ath9k-eeprom-pci-0000:00:11.0.bin and ath9k-eeprom-pci-0000:00:12.0.bin

The dump of the first one is

A5 5A 00 00 00 03 60 00 16 8C 00 29 60 08 00 01 02 80 60 2C 16 8C A0 95 50 00 16 8C 00 2A 50 08 00 01 02 80 50 2C 16 8C A0 95 50 64 0C C0 05 04 50 6C 38 11 00 03 40 04 07 3B 00 40 40 74 00 03 00 00 40 00 00 00 01 C2 60 34 00 44 00 00 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 0C B8 31 FD E0 12 02 01 00 00 00 1F 09 20 10 32 39 23 03 03 00 00 00 00 00 00 00 07 13 00 04 01 00 FF 02 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2D 0B 0B 0B 0B 0B 0B E0 00 0E 0E 0E 00 02 0E 00 CA CA CA 09 01 00 00 00 00 00 00 06 02 02 00 00 00 0E 0E 02 00 00 00 00 00 00 2C 00 00 00 00 00 00 02 02 0D 01 00 00 00 00 00 00 00 00 00 00 00 00 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 10 00 00 00 10 00 00 00 00 00 00 01 20 00 00 00 2D 20 20 0B 00 00 10 E2 00 0D 0D 0D 00 02 0E 1C FF FF FF 06 01 00 00 00 00 00 00 06 03 03 02 00 00 0E 0E 02 00 00 00 00 00 00 2D 00 00 00 00 00 00 03 03 0D 01 00 00 00 00 00 00 92 00 00 92 00 00 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 70 8E AC FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 17 2B 3F 52 47 50 5F 6B 70 00 00 00 00 00 00 00 00 00 00 02 05 0D 1D 3B 14 1B 30 49 54 00 00 00 00 00 00 00 00 00 00 05 18 2D 3F 51 48 56 5D 6A 72 00 00 00 00 00 00 00 00 00 00 01 07 0F 1E 39 15 24 2C 49 5B 00 00 00 00 00 00 00 00 00 00 06 1A 2D 3F 51 48 55 5C 68 6D 00 00 00 00 00 00 00 00 00 00 04 08 11 22 43 17 26 2F 4A 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 18 2C 40 52 47 57 5F 6E 76 00 00 00 00 00 00 00 00 00 00 02 06 0D 1E 36 13 22 2B 4A 61 00 00 00 00 00 00 00 00 00 00 02 16 2A 41 50 46 53 5F 6B 76 00 00 00 00 00 00 00 00 00 00 02 04 0B 1C 33 13 1F 2F

  1. Owl-loader successfully loads from this file and changes the PCI id to 0x0029.
    After that it tries to prevent ath9k from loading it again by setting

pdata->eeprom_name = NULL;

See:
static void owl_fw_cb(const struct firmware *fw, void *context)
{
struct pci_dev *pdev = (struct pci_dev *) context;
struct owl_ctx *ctx = (struct owl_ctx *) pci_get_drvdata(pdev);
struct ath9k_platform_data *pdata = dev_get_platdata(&pdev->dev);
struct pci_bus *bus;

complete(&ctx->eeprom_load);

if (!fw) {
	dev_err(&pdev->dev, "no eeprom data received.\n");
	goto release;
}

/* also note that we are doing *u16 operations on the file */
if (fw->size > sizeof(pdata->eeprom_data) || fw->size < 0x200 ||
    (fw->size & 1) == 1) {
	dev_err(&pdev->dev, "eeprom file has an invalid size.\n");
	goto release;
}

if (pdata) {
	memcpy(pdata->eeprom_data, fw->data, fw->size);

	/*
	 * eeprom has been successfully loaded - pass the data to ath9k
	 * but remove the eeprom_name, so it doesn't try to load it too.
	 */
	pdata->eeprom_name = NULL;
}

if (ath9k_pci_fixup(pdev, (const u16 *) fw->data, fw->size))
	goto release;

pci_lock_rescan_remove();
bus = pdev->bus;
pci_stop_and_remove_bus_device(pdev);

/*
 * the device should come back with the proper
 * ProductId. But we have to initiate a rescan.
 */
pci_rescan_bus(bus);
pci_unlock_rescan_remove();

release:
release_firmware(fw);
}

  1. This used to work on ar71xx because (ath9k/init.c)

static int ath9k_init_platform(struct ath_softc *sc)
{
struct ath9k_platform_data *pdata = sc->dev->platform_data;
struct ath_hw *ah = sc->sc_ah;
struct ath_common *common = ath9k_hw_common(ah);
int ret;

if (!pdata)
	return 0;

if (!pdata->use_eeprom) {
	ah->ah_flags &= ~AH_USE_EEPROM;
	ah->gpio_mask = pdata->gpio_mask;
	ah->gpio_val = pdata->gpio_val;
	ah->led_pin = pdata->led_pin;
	ah->is_clk_25mhz = pdata->is_clk_25mhz;
	ah->get_mac_revision = pdata->get_mac_revision;
	ah->external_reset = pdata->external_reset;
	ah->disable_2ghz = pdata->disable_2ghz;
	ah->disable_5ghz = pdata->disable_5ghz;

	if (!pdata->endian_check)
		ah->ah_flags |= AH_NO_EEP_SWAP;
}

if (pdata->eeprom_name) {
	ret = ath9k_eeprom_request(sc, pdata->eeprom_name);
	if (ret)
		return ret;
}

if (pdata->led_active_high)
	ah->config.led_active_high = true;

if (pdata->tx_gain_buffalo)
	ah->config.tx_gain_buffalo = true;

if (pdata->macaddr)
	ether_addr_copy(common->macaddr, pdata->macaddr);

return 0;

}

But it doesn't on ath79, becuase loading eeprom is triggered differntly by "qca, noeeprom"

static int ath9k_of_init(struct ath_softc *sc)
{
struct device_node *np = sc->dev->of_node;
struct ath_hw *ah = sc->sc_ah;
struct ath_common *common = ath9k_hw_common(ah);
enum ath_bus_type bus_type = common->bus_ops->ath_bus_type;
const char *mac;
char eeprom_name[100];
int ret;

if (!of_device_is_available(np))
	return 0;

ath_dbg(common, CONFIG, "parsing configuration from OF node\n");

if (of_property_read_bool(np, "qca,no-eeprom")) {
	/* ath9k-eeprom-<bus>-<id>.bin */
	scnprintf(eeprom_name, sizeof(eeprom_name),
		  "ath9k-eeprom-%s-%s.bin",
		  ath_bus_type_to_string(bus_type), dev_name(ah->dev));

	ret = ath9k_eeprom_request(sc, eeprom_name);
	if (ret)
		return ret;
}

mac = of_get_mac_address(np);
if (mac)
	ether_addr_copy(common->macaddr, mac);

ah->ah_flags &= ~AH_USE_EEPROM;
ah->ah_flags |= AH_NO_EEP_SWAP;

return 0;

}

So it looks like removing "qca, noeeprom" is a good idea. But nothing really bad will happen if it loads the firmware one more time.

So the questions are:

  1. Why ath9k attempts to load the firmware without "qca,noeeprom"?
  2. Whhy does it see the magic number as "0x0000"

I think removing the eeprom load from the kernel code will get it working, but how to fix it properly?

The wierd part is that ath9k doesn't complain on the absence of firmware, but on the magic number, that is actually correct.

Anyway adding "qca,noeeprom" doesn't change anything.

@openwrt-bot
Copy link
Author

Pilot6:

It seems that instead of loading firmware from a file, it checks the magic number in the device and founds 0 there.

The hotplug firmware is never triggered.

@openwrt-bot
Copy link
Author

mkresin:

Took me some time and a poke from someone else, but it rather looks like the reg of the wireless nodes in your dts are wrong.

If the reg is wrong, the qca,no-eeprom property isn't passed to the driver. The owl-loader works without the devicetree and might explain why 50% of what you are trying to do now works.

According to your log the pci wireless are at pci 0000:00:11.0 and pci 0000:00:12.0. It translates to the following dts:

&pcie0 { status = "okay";
ath9k0: wifi@0,12 {
	compatible = "pci168c,0029";
	reg = <0x9000 0 0 0 0>;
	qca,no-eeprom;
	#gpio-cells = <2>;
	gpio-controller;
};
ath9k1: wifi@0,13 {
	compatible = "pci168c,0029";
	reg = <0x9800 0 0 0 0>;
	qca,no-eeprom;
	#gpio-cells = <2>;
	gpio-controller;
};

};

I would prefer to move the discussion to the PR instead. It looks like even the last piece is a config error.

@openwrt-bot
Copy link
Author

Pilot6:

You mean my pull request adding this device?

I will test this, but now I am checking another idea.

owl-loader cuts of the magic number and passes firmware to pdata->eeprom_data

I fixed this in the code and now compiling.

I will move to the PR with results.

@openwrt-bot
Copy link
Author

mkresin:

You mean my pull request adding this device?

Yes. Seeing the code we are talking about, makes spotting issues way easier.

I will test this, but now I am checking another idea.

Please fix the reg value first. I'm quite sure it will solve your issues. The very same code is already used for the lantiq target and works fine. It is used without devicetree for ar71xx/nand as well (in fact, it was written for the ar71xx/nand Cisco Meraki Z1 board).

@openwrt-bot
Copy link
Author

Pilot6:

And what are 0,12 and 0,13 numbers? Or is it a typo?

@openwrt-bot
Copy link
Author

Pilot6:

No dice with your solution, still, sry.

I commited to the PR with the log.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant