Re: Help me grok the ath(4) device attach code

From: John Nielsen <lists_at_jnielsen.net>
Date: Wed, 31 May 2023 00:23:34 UTC
> On May 30, 2023, at 5:40 PM, Bjoern A. Zeeb <bzeeb-lists@lists.zabbadoz.net> wrote:
> 
> On Tue, 30 May 2023, John Nielsen wrote:
> 
>> I’m trying to wrap my head around the code in sys/dev/ath/ath_hal , partly for my own edification but mostly due to wanting to fix this bug:
>> https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=255337
>> 
>> The card in question is an AR9462, branded (I think) as a Dell Wireless 1901 with this ID:
>> vendor=0x168c device=0x0034 subvendor=0x1028 subdevice=0x020d
>> 
>> The card is identified and appears to initialize correctly but it has a default/bogus MAC address of 00:02:03:04:05:06 and is never able to scan any networks. It does work fine under Linux, so I’m attempting to compare the two codebases. But since I’m not a device developer and haven’t done much C since my undergraduate work, I’m having a bit of trouble.
>> 
>> I’m open to any pointers but I’d specifically like to work out the following (unless I’m way off base, in which case I’d like to know that too):
>> 
>> 1) Where does the default MAC address come from? In the Linux driver it looks like it’s here:
>> https://git.kernel.org/pub/scm/linux/kernel/git/kvalo/ath.git/tree/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c#n49
>> I don’t see any such definition in the FreeBSD code.
> 
> No idea, but you should end up in a call to ar9300_get_mac_address()
> from sys/contrib/dev/ath/ath_hal/ar9300/ar9300_misc.c if my guess is right.
> 
> The call comes from sys/dev/ath/if_ath.c ath_hal_getmac().
> 
> Hope that helps you to trace this.

Thanks! I had no idea that directory was even there. More source to dive through...

>> 2) When ath_hal_attach() calls chip->attach(), which code is actually called (and how/where is that determined)?
>> 
>> 3) Is there any equivalent in the FreeBSD code for this Linux process of trying to read the EEPROM from multiple different addresses? (Is it necessary?)
>> https://git.kernel.org/pub/scm/linux/kernel/git/kvalo/ath.git/tree/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c#n3299
>> See also:
>> https://git.kernel.org/pub/scm/linux/kernel/git/kvalo/ath.git/commit/drivers/net/wireless/ath/ath9k?id=528782ecf59f7bab2f1368628a479f49be59b512
>> and the definitions here:
>> https://git.kernel.org/pub/scm/linux/kernel/git/kvalo/ath.git/tree/drivers/net/wireless/ath/ath9k/ar9003_eeprom.h#n78
>> 
>> (I don’t see any of those BASE_ADDR values referenced or defined anywhere in FreeBSD)
>> 
>> 4) In general, what code should I be looking at to see how the EEPROM is read and interpreted for a specific card?
>> 
>> Any help appreciated!