# BCM4322 - WIFI Card - Freebsd 11.2 not working



## joaf (Nov 3, 2018)

Hello FreeBSD Users,

i have a problem to make the Wifi CARD BCM4322  (Rev. 01) running under Freebsd 11.2.

i have searched around the Net, and i found not description, or a howto to setup this Wifi Card.

i have read a lot of post regarding Broadcom Wifi Cards, but i found no solution.


- https://lists.freebsd.org/pipermail/freebsd-wireless/2016-July/006893.html
- i have modificed the GERNERIC Kernel and rebuild it
- https://basicbsd.wordpress.com/2018/01/28/broadcom-bcm4312-wireless-network-card-on-freebsd-11-1/
- i have modified the Makefile from bwn-firmware-kmod 
- in the loader.conf i have acutally the following settings:   
bwn_v4_ucode_load="YES"
bwn_v4_n_ucode_load="YES"
if_bwn_load="YES"

but the card is not listed in the System. 

Please could told me someone if this card could be run under FreeBSD 11.2? 

This would be very helpful for me.

Thank you all for your response.

Best regards

Joachim


----------



## Phishfry (Nov 3, 2018)

Two possible avenues to pursue. There is a LP version of the firmware. You may want to try it.
There is also the bwi(4) driver which covers some older BCM devices with its own firmware.
Have you tried it? I would be tempted to try that first.
I also think adding the firmware settings to loader.conf is jumping the gun. The best way to determine what a module is doing is to load it with kldload from the command prompt. It will output text that could be important to debugging. With it loading via loader.conf you can easily miss these messages. Once you get it working then add your firmware settings to loader.conf.


----------



## joaf (Nov 4, 2018)

Phishfry said:


> Two possible avenues to pursue. There is a LP version of the firmware. You may want to try it.
> There is also the bwi(4) driver which covers some older BCM devices with its own firmware.
> Have you tried it? I would be tempted to try that first.
> I also think adding the firmware settings to loader.conf is jumping the gun. The best way to determine what a module is doing is to load it with kldload from the command prompt. It will output text that could be important to debugging. With it loading via loader.conf you can easily miss these messages. Once you get it working then add your firmware settings to loader.conf.




Hello Phishfrey, thank you for your answer. 
I have no idea what you are meaning with LP Version? I understood that when i use the settings in the loader.conf, then i can't see the full
output messages. So i understand that i should use kldload to load the modules manually to see what happens. 
But i have no idea how to use kldload with the modules ....

First of all i have modified my loader.conf and removed all settings 
bwn_v4_ucode_load="YES"
bwn_v4_n_ucode_load="YES"
if_bwn_load="YES" 

Then i have searched the net how is the correct syntax to load the modules with kldload, but i have now idea. Everything i tried i get the messsage ...."no such file or directory"..... .

I would be very nice if you could help me, to use the correct syntax to load the modules manually.

Thank you very much for your time and help.

Greetings
Joachim


----------



## Phishfry (Nov 4, 2018)

There are two firmwares for bwn(4) driver. The regular one and the LP one.


> Most cases you need to use bwn_v4_ucode module but if you are
> a LP (low power) PHY user please uses bwn_v4_lp_ucode module.



To manually load any FreeBSD module just drop off the '_load' part from the loader.conf line.
Like so: `kldload bwn_v4_lp_ucode`
I don't know if that is the actual name. Just an example.


----------



## joaf (Nov 7, 2018)

Hello Phisfry, sorry for the delay, i was on a business trip.

Now i have tried something

I found out when i load the following:

kldload bwn_v4_ucode
kldload bwn_v4_n_ucode
kldload if_bwn_load

then i can see in demsg the following:
siba_bwn0: <Broadcom BCM4322 802.11a/b/g/n Wireless> mem 0xf2400000-0xf2403fff irq 17 at device 0.0 on pci1
siba_bwn0: warn: multiple PCI(E) cores
siba_bwn0: unsupported coreid (USB 2.0 Device)
siba_bwn0: unsupported coreid (unknown)
siba_bwn0: unsupported coreid (Internal Memory)
bwn0 on siba_bwn0
bwn0: bwn_phy_n_attach: BWN_GPL_PHY not in kernel config; no PHY-N support
bwn0: failed
device_attach: bwn0 attach returned 6

so for me it looks like that the BMC4322 is now detected but can't not loaded? Is my thinking correct? 

Do you know what's going wrong? Do you have an idea how to fix it?

Thank you so much for your support.

greetings
Joachim


----------



## Phishfry (Nov 7, 2018)

joaf said:


> BWN_GPL_PHY not in kernel config


Sounds like you need to build a custom kernel with this option enabled.
https://www.freebsd.org/doc/handbook/kernelconfig-building.html

Here are the details:
https://lists.freebsd.org/pipermail/freebsd-wireless/2016-May/006738.html

I would also try and figure out which firmware it actually needs. Only load one and see which one it is using.


----------



## Phishfry (Nov 8, 2018)

Let me know if you need help. It might seem daunting but it is not that bad.
So you need FreeBSD source. Do you have it installed? Check under /usr/src/. This is the top level source directory.
If you did not install the source on install then download it:
`svnlite checkout https://svn.freebsd.org/base/releng/11.2 /usr/src/`

First you need to add to your kernel configuration by making a custom kernconf.
https://www.freebsd.org/doc/handbook/kernelconfig-config.html
I am assuming here that you are using FreeBSD 11.2 AMD64 build.

`cd /usr/src`
## move to top level directory ##

`cp  /usr/src/sys/amd64/conf/GENERIC WIFI`
## Copy the GENERIC kernconf to a file named WIFI ##

`ee /usr/src/sys/amd64/conf/WIFI`
## This is the easy editor. You are opening your new kernconf to add the options you need ##
Down around line 297 add the following:
option BWN_DEBUG
option BWN_GPL_PHY

Now hit the escape key>> a) leave editor >> a) save changes

This is the KERNCONF now fixed up with your custom kernel options and saved as your WIFI kernconf.

Now you must edit your makefile (shown using easy editor)
`ee /usr/src/sys/modules/bwn/Makefile`

Now notice the code comments:
# Uncomment this for the GPL PHY code; this requires the
# module be built with BWN_GPL_PHY set in the kernel
# configuration.

So all the lines below this comment need to have the pound symbol removed. (pound symbol = #)
You can use backspace or delete key to remove the # symbols.
Lines 21,22,23,24,25,26,27

Now hit the escape key>> a) leave editor >> a) save changes

So now all your editing is done and all you need to do is compile your custom kernel.
`make buildkernel KERNCONF=WIFI`
`make installkernel KERNCONF=WIFI`
This could take many, many hours. If you have multiple CPU cores you can speed it up by using the -j option flag.
For a 2 core Example:
`make -j 2 buildkernel KERNCONF=WIFI`
`make -j 2 installkernel KERNCONF=WIFI`
When complete reboot and see what you have.
if you followed my advice above you know which firmware needs to be kldload 'ed. Load it by hand and see what you get.


----------



## joaf (Nov 8, 2018)

Hello Phishfry,

thank you so mich for your detailed description. I will follow your step by step guide to build my custom kernel. 

But this takes some time because i'm the next days on a business trip. I will inform you if i have tested.

Greetings from germany 

Joachim


----------



## joaf (Nov 11, 2018)

Hello Phishfry,

after compiling and installing custom kernel with your howTo descprition. My Broadcom BMC4322 works now like a charme.

I have now used the following settings

in the loader.conf i use the settings:
bwn_v4_n_ucode_load="YES"
if_bwn_load="YES"

in the /etc/rc.conf i use the follwing settings:
wlans_bwn0="wlan0"
ifconfig_wlan0="WPA SYNCDHCP"

then i have my /etc/wpa_supplicant.conf
network={
ssid="Homezonexxxx-xxxxx"
psk="Komplexxxxx---xxxxx"
}

now my WIFI Device is activated, i can ping all resources. So for me it looks like that the custom kernel works great.

One question to the custom Kernel. What happens when i upgrade to a later Freebsd release? Have i also create the customer kernel new, as you descriped? Or can i use this custom kernel for further releases?

Thank you so much for your great help and your time. I have learned a lot of handling inside freebsd.

It was a pleasure to learn from you.

Greetings

Joachim


Phishfry said:


> Let me know if you need help. It might seem daunting but it is not that bad.
> So you need FreeBSD source. Do you have it installed? Check under /usr/src/. This is the top level source directory.
> If you did not install the source on install then download it:
> `svnlite checkout https://svn.freebsd.org/base/releng/11.2 /usr/src/`
> ...


----------



## Phishfry (Nov 11, 2018)

joaf said:


> What happens when i upgrade to a later Freebsd release?


If you run freebsd-update it will create a GENERIC kernel only. You must re-compile WIFI again for your custom settings.
That is the reason you copy GENERIC to make a custom kernconf.
GENERIC kernconf might get changed during an update. WIFI kernconf will not be touched.
You could just modify GENERIC kernconf instead of making a custom WIFI kernconf, but you lose the settings during an upgrade.
https://www.freebsd.org/doc/handbook/updating-upgrading-freebsdupdate.html


> Only the GENERIC kernel can be    automatically updated by freebsd-update.    If a custom kernel is installed, it will have to be rebuilt    and reinstalled after freebsd-update    finishes installing the updates.  However,    freebsd-update will detect and update the    GENERIC kernel if    /boot/GENERIC exists, even if it is not    the current running kernel of the system.



Thanks for the feedback. I helped one person who had trouble building the bwn firmware from ports.
Unfortunately I did not know of the custom kernel requirement at the time.
I feel like I wasted his time. Now I know what I was missing.


----------



## Phishfry (Nov 11, 2018)

OK how about the super cool refined method.
The problem: Your WIFI kernconf is 'static'. If you upgrade to FreeBSD 12 there maybe different options or devices.
One way to deal with this is to copy GENERIC kernconf to WIFI each upgrade and add your changes. Boring.

Solution is to borrow a method from GENERIC-NODEBUG kernconf that is used on FreeBSD -CURRENT
As seen here:https://github.com/freebsd/freebsd/blob/master/sys/amd64/conf/GENERIC-NODEBUG

So try this for your WIFI kernconf next time you update.
It will bring all the benefits of the upgraded GENERIC kernconf and keep your custom options.

/usr/src/sys/amd64/conf/WIFI

```
include GENERIC
ident   WIFI

option BWN_DEBUG
option BWN_GPL_PHY
```


----------



## joaf (Nov 11, 2018)

Phishfry said:


> OK how about the super cool refined method.
> The problem: Your WIFI kernconf is 'static'. If you upgrade to FreeBSD 12 there maybe different options or devices.
> One way to deal with this is to copy GENERIC kernconf to WIFI each upgrade and add your changes. Boring.
> 
> ...




This sounds very interesting. I will try it for the next update. I will keep it in my description for my setup. 
It's a great experience that you Grant me such detailed informations and instructions. 

Greetings and thanks Form germany


----------



## malnagel (Feb 2, 2021)

HW: late2009 iMac9 Intel Core2duo 8GBRAM nVidia9400GeForce Bcm94322
OS: FreeBSD12.2
Getting this thing up and running has been "a wild ride"!
Thank All of You for making such an effort to build this FreeBSD for us to use!!!
Thanks for posting all this!
I have the same Broadcom94322 chipset in my WiFi router on this iMac9,1... and it's sort of the last thing I'd like to get working on this "good ole" computer; gives me hope there's light at the end of the tunnel!

my dmesg output of interest:
bwn_pci0: <Broadcom BCM4322 802.11n Dual-Band Wireless> mem 0xd3200000-0xd3203fff at device 0.0 on pci4
bhndb0: <PCI-BHND bridge> on bwn_pci0
bhndb0: Using MSI interrupts on bwn_pci0
bhnd_nvram0: <SPROM/OTP> mem 0xd3201000-0xd3201fff on bhndb0
bhnd0: <BCM4322 SIBA bus> on bhndb0
bhnd_chipc0: <Broadcom ChipCommon I/O Controller, rev 23> mem 0x18000000-0x18000dff,0xffff0000-0xffffffff,0x1c000000-0x1dffffff,0x18000f00-0x18000fff,0x1800
0e00-0x18000eff irq 0 at core 0 on bhnd0
bhnd_pmu0: <Broadcom ChipCommon PMU, rev 2> on bhnd_chipc0
gpio0: <Broadcom ChipCommon GPIO> mem 0x18000000-0x18000dff on bhnd_chipc0
bhnd_hostb0: <Broadcom PCIe-G1 Host-PCI bridge, rev 11> mem 0x18002000-0x18002dff,0-0x7fffffff,0x18002f00-0x18002fff,0x18002e00-0x18002eff irq 2 at core 2 o
n bhnd0
bhnd0: <Broadcom Internal Memory, rev 3> mem 0x18006000-0x18006dff,0x1e000000-0x1e01ffff,0x18006f00-0x18006fff,0x18006e00-0x18006eff at core 6 (no driver at
tached)
bhnd0: <Broadcom unknown, rev 0> mem 0x18005000-0x18005dff,0x18005f00-0x18005fff,0x18005e00-0x18005eff irq 5 at core 5 (no driver attached)
bwn0: <Broadcom 802.11 MAC/PHY/Radio, rev 16> mem 0x18001000-0x18001dff,0x18001f00-0x18001fff,0x18001e00-0x18001eff irq 1 at core 1 on bhnd0
bwn0: bwn_phy_n_attach: BWN_GPL_PHY not in kernel config; no PHY-N support
bwn0: failed
device_attach: bwn0 attach returned 6

and so no wlan0 either.

So I made these changes to my CUSTOM kernel config file and un-commented the indicated lines in the bwn/Makefile and get the following:

device          wlan_wep               # 802.11 WEP support
device          wlan_ccmp             # 802.11 CCMP support
device          wlan_tkip               # 802.11 TKIP support
device          wlan_amrr             # AMRR transmit rate control algorithm
device          ath_rate_sample   # SampleRate tx rate control for ath
device          bwi                        # Broadcom BCM430x/BCM431x wireless NICs.
device          bwn                       # Broadcom BCM43xx wireless NICs.
option          BWN_DEBUG
option          BWN_GPL_PHY
device          bhnd               
device          bhndb           
device          bhndb_pci         
device          bcma               
device          siba                 
device          gpio               
# device        firmware             #  apparently already included somewhere else?!
device          ipw                       # Intel 2100 wireless NICs.

.PATH: ${SRCTOP}/sys/gnu/dev/bwn/phy_n
SRCS.BWN_GPL_PHY+=  if_bwn_radio_2055.c
SRCS.BWN_GPL_PHY+=  if_bwn_radio_2056.c
SRCS.BWN_GPL_PHY+=  if_bwn_radio_2057.c
SRCS.BWN_GPL_PHY+=  if_bwn_phy_n_sprom.c
SRCS.BWN_GPL_PHY+=  if_bwn_phy_n_tables.c
SRCS.BWN_GPL_PHY+=  if_bwn_phy_n_ppr.c
SRCS.BWN_GPL_PHY+=  if_bwn_phy_n_core.c

as get the following from the make/compile of the CUSTOM kernel:

....more earlier messages...
-arith -Wcast-qual -Wundef -Wno-pointer-sign -D__printf__=__freebsd_kprintf__ -Wmissing-include-dirs -fdiagnostics-show-option -Wno-unknown-pragmas -Wno-error-tautological-compare -Wno-error-empty-body -Wno-error-parentheses-equality -Wno-error-unused-function -Wno-error-pointer-sign -Wno-error-shift-negative-value -Wno-address-of-packed-member  -mno-aes -mno-avx  -std=iso9899:1999 -Werror  vers.c
ctfconvert -L VERSION -g vers.o
linking kernel.full
ld: error: undefined symbol: bwn_nphy_op_allocate
>>> referenced by if_bwn_phy_n.c:99 (/usr/src/sys/dev/bwn/if_bwn_phy_n.c:99)
>>>               if_bwn_phy_n.obwn_phy_n_attach)

ld: error: undefined symbol: bwn_nphy_op_free
>>> referenced by if_bwn_phy_n.c:113 (/usr/src/sys/dev/bwn/if_bwn_phy_n.c:113)
>>>               if_bwn_phy_n.obwn_phy_n_detach)

ld: error: undefined symbol: bwn_nphy_op_prepare_structs
>>> referenced by if_bwn_phy_n.c:122 (/usr/src/sys/dev/bwn/if_bwn_phy_n.c:122)
>>>               if_bwn_phy_n.obwn_phy_n_prepare_hw)

ld: error: undefined symbol: bwn_nphy_op_init
>>> referenced by if_bwn_phy_n.c:139 (/usr/src/sys/dev/bwn/if_bwn_phy_n.c:139)
>>>               if_bwn_phy_n.obwn_phy_n_init)

ld: error: undefined symbol: bwn_nphy_op_software_rfkill
>>> referenced by if_bwn_phy_n.c:210 (/usr/src/sys/dev/bwn/if_bwn_phy_n.c:210)
>>>               if_bwn_phy_n.obwn_phy_n_rf_onoff)

ld: error: undefined symbol: bwn_nphy_op_switch_analog
>>> referenced by if_bwn_phy_n.c:218 (/usr/src/sys/dev/bwn/if_bwn_phy_n.c:218)
>>>               if_bwn_phy_n.obwn_phy_n_switch_analog)

ld: error: undefined symbol: bwn_nphy_op_switch_channel
>>> referenced by if_bwn_phy_n.c:226 (/usr/src/sys/dev/bwn/if_bwn_phy_n.c:226)
>>>               if_bwn_phy_n.obwn_phy_n_switch_channel)

ld: error: undefined symbol: bwn_nphy_op_recalc_txpower
>>> referenced by if_bwn_phy_n.c:258 (/usr/src/sys/dev/bwn/if_bwn_phy_n.c:258)
>>>               if_bwn_phy_n.obwn_phy_n_recalc_txpwr)
*** Error code 1

Stop.
make[2]: stopped in /usr/obj/usr/src/amd64.amd64/sys/CUSTOM
*** Error code 1
*** Error code 1

This posting editor seems to have replaced a colon and open bracket  in the above messages with a "sad face"?!

OK, so I'm definitely missing something.
Thanks in advance!!!
All the Very Best! m


----------



## Hogo (Nov 5, 2022)

malnagel said:


> HW: late2009 iMac9 Intel Core2duo 8GBRAM nVidia9400GeForce Bcm94322
> OS: FreeBSD12.2
> 
> my dmesg output of interest:
> ...



HW: MacBook Pro 5,4, Intel Core2Duo, RAM 4GB, nVidia GeForce 9400M, BCM4322
OS:
FreeBSD 13.1-RELEASE-p2
indicated lines in /usr/src/sys/modules/bwn/Makefile uncommented by default

I've made an "unstatic" kernel configuration file similar to Phishfry's example and kernel-conf file according to bwn.
This results in same error.

Then I reduced kernelconf file to

```
include GENERIC
ident KERNELBWN
# Additional to generic
device        bwn            # Broadcom BCM43xx wireless NICs.
options       BWN_GPL_PHY
```
because modules bhnd, bhndb, bhndb_pci, bcma, siba, gpio, wlan, wlan_amrr, firmware are already available in kernel GENERIC, see /boot/kernel/.
Then kernel compilation worked without errors.

With /boot/loader.conf

```
#WIFI
siba_bwn_load="YES"
bwn_v4_ucode_load="YES"
bwn_v4_n_ucode_load="YES"
if_bwn_load="YES"
wlan_ccmp_load="YES"
wlan_tkip_load="YES"
```
WIFI works smooth.


----------

