Plan 9: Intel Wireless 3165

Intel Wireless 3165 internal PCI card works with Plan 9. You'll need firmware blob /lib/firmware/iwlwifi-7265D-29.ucode from Linux as /lib/firmware/iwlwifi-7265D-29 in Plan 9.

Detect hardware on Linux 

lspci -nn
02:00.0
Network controller [0280]: Intel Corporation Wireless 3165 [8086:3165] (rev 81)
  
 
# slot_info=0000:02:00.0
# vendor_id=8086
# device_code=3165
 

Detect firmware on Linux 

sudo dmesg | grep -i iwlwifi | grep -i firmware
[    6.062085] iwlwifi 0000:02:00.0: loaded firmware version 29.f2390aa8.0 7265D-29.ucode op_mode iwlmvm

Apply the following patch to etheriwl.c and rebuild kernel (cd  /sys/src/9/pc64 && mk install). The kernel should be copied to /n/9fat (9fat partition - use 9fs 9fat).

@@ -4509,6 +4512,10 @@ iwlpci(void)
             family = 9000;
             fwname = "iwm-9260-34";
             break;
+        case 0x3165:    /* Wireless AC 3165 */
+            family = 7000;
+            fwname = "iwlwifi-7265D-29";
+            break;
         }
 
         ctlr = malloc(sizeof(Ctlr));
 

If wifi is the only network interface, rio startup will take time since the system is trying to get a network connection and it can't connect without a password. You might want to add a key for the AP in the factotum after the boot process.

 

List Access Points (AP)

term% cat /net/ether0/ifstats
essid: 
bssid: 
status: associated
channel: 01
rxkey2: ccmp:[16]
rxkey4: ccmp:[16]
txkey0: ccmp:[16]
brsne: 30140100000FAC040100000FAC040100000FAC020C00
node: 80ae3c0f1ff9 1c11 191050      01 Aarna_2G
node: b4861863011a 1411 191960      07 - Shiva Shakti Niwas -
node: b486187867ca 1411 191950      07 Tataplay
   

 

Connect to AP Tataplay prompting for a password

term% aux/wpa -dps Tataplay /net/ether0
status: need authentication
rsne: 30140100000FAC040100000FAC040100000FAC020000

!Adding key: essid=Tataplay proto=wpapsk
password: 
   


Obtain an IP address

ip/ipconfig
 
# Full syntax - helpful when multiple network interfaces are present
ip/ipconfig ether /net/ether0 

Now you should be able to access the internet.

ip/ping 8.8.8.8 

 

Multiple Network Interfaces

If you have multiple network interfaces, only the first available is initialized. To configure others on boot, add all the needed interfaces in plan9.ini.

ether1=type=iwl  station=Tataplay

For configuring after the boot process, use bind command to create the /net/ether1 directory. #l<n> will create /net/ether<n> when available.

bind -a '#l1' /net 

 

Explanation

Ethernet driver files are named as ether<manufacturer identifier>.c . During build, all the <filename>link() methods are collected in links() method in pc64.c [generated from pc64] for initialization. devether.c contains generic methods for ethernet drivers. dev.c defines a generic device. 

Plan 9 supports MaxEther (64) number of network cards in a system.

main() [/sys/src/9/pc64/main.c] > links() [pc64.c generated file] > etheriwllink() [etheriwl.c] > addethercard() [devether.c]
   

 

Device Driver Development Setup

If you are developing or debugging drivers for an OS different from your current one, QEMU provides direct access to the host hardware via PCI Passthrough [1].

Verify if PCI passthrough is supported by the kernel.

slot_info=0000:02:00.0
vendor_id=8086
device_code=3165
export slot_info vendor_id device_code
 
modprobe vfio-pci
echo $vendor_id $device_code > /sys/bus/pci/drivers/vfio-pci/new_id

echo $
slot_info > /sys/bus/pci/devices/$slot_info/driver/unbind
echo $
slot_info > /sys/bus/pci/drivers/vfio-pci/bind

Unbind device from guest.

echo 1 > /sys/bus/pci/devices/$slot_info/remove    
echo 1 > /sys/bus/pci/rescan  

 

libvirt provides a convenient frontend virt-manager (and API if you are so inclined) to QEMU. Since device access requires root privilege, add the following to /etc/libvirt/qemu.conf.

user = "root"
group = "root"
   

PCI passthrough can be configured via UI or by adding following to <devices> section in domain XML.

    <!-- Intel 3165 passthrough -->
    <hostdev mode='subsystem' type='pci' managed='yes'>
      <source>
        <address domain='0x0000' bus='0x02' slot='0x00' function='0x0'/>
      </source>
    </hostdev>

Some useful commands for libvirt. 

# Create a new domain 
sudo virsh define vm.xml
 
# Start network and domain 
sudo virsh net-start default
sudo virsh start plan9
 
# Connect to a running domain 
virt-viewer -c qemu:///system plan9
 
# Stop a domain 
sudo virsh destroy plan9

 

References

  1. QEMU PCI Passtrhough 
  2. Linux iwlwifi debugging 

 

Comments

Popular posts from this blog

Plan 9 : The Infinity Notebook

Emacs: Binary File Viewer

Plan 9 Remote File Access from Emacs