Changes in / [f4d5f90:9fe4db3] in mainline


Ignore:
Files:
1 added
31 edited

Legend:

Unmodified
Added
Removed
  • abi/include/ddi/arg.h

    rf4d5f90 r9fe4db3  
    3636#define ABI_DDI_ARG_H_
    3737
     38#define DMAMEM_FLAGS_ANONYMOUS  0x01
     39
    3840/** Structure encapsulating arguments for SYS_PHYSMEM_MAP syscall. */
    3941typedef struct {
  • abi/include/syscall.h

    rf4d5f90 r9fe4db3  
    8585        SYS_DEVICE_ASSIGN_DEVNO,
    8686        SYS_PHYSMEM_MAP,
     87        SYS_DMAMEM_MAP,
     88        SYS_DMAMEM_UNMAP,
    8789        SYS_IOSPACE_ENABLE,
    8890        SYS_REGISTER_IRQ,
  • boot/Makefile.common

    rf4d5f90 r9fe4db3  
    127127        test/test3 \
    128128        nic/lo \
    129         nic/ne2k
     129        nic/ne2k \
     130        nic/e1k
    130131
    131132RD_DRV_CFG =
     
    208209        $(USPACE_PATH)/srv/net/cfg/general \
    209210        $(USPACE_PATH)/srv/net/cfg/lo.nic \
    210         $(USPACE_PATH)/srv/net/cfg/ne2k.nic
     211        $(USPACE_PATH)/srv/net/cfg/ne2k.nic \
     212        $(USPACE_PATH)/srv/net/cfg/e1k.nic
    211213endif
    212214
  • contrib/conf/net-qe.sh

    rf4d5f90 r9fe4db3  
    11#!/bin/sh
    22
    3 # Obsolete versions of QEMU
    4 #
    5 #   QEMU 0.10.2 and later 0.10.*
    6 #    qemu $@ -no-kqemu -vga std -M isapc -net nic,model=ne2k_isa -net user -boot d -redir udp:8080::8080 -redir udp:8081::8081 -redir tcp:8080::8080 -redir tcp:8081::8081 -cdrom image.iso
    7 #
    8 #   QEMU 0.11.* and 0.12.*
    9 #    qemu $@ -vga std -M isapc -net nic,model=ne2k_isa -net user -boot d -redir udp:8080::8080 -redir udp:8081::8081 -redir tcp:8080::8080 -redir tcp:8081::8081 -cdrom image.iso
    10 
    11 # QEMU 0.13 and later
    12 qemu $@ -device ne2k_isa,irq=5,vlan=0 -net user -boot d -redir udp:8080::8080 -redir udp:8081::8081 -redir tcp:8080::8080 -redir tcp:8081::8081 -cdrom image.iso
     3case "$1" in
     4        ne2k)
     5                shift
     6                qemu $@ -device ne2k_isa,irq=5,vlan=0 -net user -boot d -redir udp:8080::8080 -redir udp:8081::8081 -redir tcp:8080::8080 -redir tcp:8081::8081 -cdrom image.iso
     7                ;;
     8        e1k)
     9                shift
     10                qemu $@ -device e1000,vlan=0 -net user -boot d -redir udp:8080::8080 -redir udp:8081::8081 -redir tcp:8080::8080 -redir tcp:8081::8081 -cdrom image.iso
     11                ;;
     12        *)
     13                echo "Usage: $0 {ne2k|e1k}"
     14esac
  • kernel/arch/abs32le/src/abs32le.c

    rf4d5f90 r9fe4db3  
    8686}
    8787
    88 sysarg_t sys_tls_set(sysarg_t addr)
     88sysarg_t sys_tls_set(uintptr_t addr)
    8989{
    9090        return EOK;
  • kernel/arch/amd64/src/amd64.c

    rf4d5f90 r9fe4db3  
    3434
    3535#include <arch.h>
    36 
    3736#include <typedefs.h>
    38 
    39 #include <config.h>
    40 
    41 #include <proc/thread.h>
     37#include <errno.h>
     38#include <memstr.h>
     39#include <interrupt.h>
     40#include <console/console.h>
     41#include <syscall/syscall.h>
     42#include <sysinfo/sysinfo.h>
     43#include <arch/bios/bios.h>
     44#include <arch/boot/boot.h>
     45#include <arch/debugger.h>
     46#include <arch/drivers/i8254.h>
     47#include <arch/drivers/i8259.h>
     48#include <arch/syscall.h>
     49#include <genarch/acpi/acpi.h>
     50#include <genarch/drivers/ega/ega.h>
     51#include <genarch/drivers/i8042/i8042.h>
     52#include <genarch/drivers/legacy/ia32/io.h>
     53#include <genarch/fb/bfb.h>
     54#include <genarch/kbrd/kbrd.h>
    4255#include <genarch/multiboot/multiboot.h>
    4356#include <genarch/multiboot/multiboot2.h>
    44 #include <genarch/drivers/legacy/ia32/io.h>
    45 #include <genarch/drivers/ega/ega.h>
    46 #include <genarch/fb/bfb.h>
    47 #include <genarch/drivers/i8042/i8042.h>
    48 #include <genarch/kbrd/kbrd.h>
    49 #include <arch/drivers/i8254.h>
    50 #include <arch/drivers/i8259.h>
    51 #include <arch/boot/boot.h>
    5257
    5358#ifdef CONFIG_SMP
    5459#include <arch/smp/apic.h>
    5560#endif
    56 
    57 #include <arch/bios/bios.h>
    58 #include <arch/cpu.h>
    59 #include <print.h>
    60 #include <arch/cpuid.h>
    61 #include <genarch/acpi/acpi.h>
    62 #include <panic.h>
    63 #include <interrupt.h>
    64 #include <arch/syscall.h>
    65 #include <arch/debugger.h>
    66 #include <syscall/syscall.h>
    67 #include <console/console.h>
    68 #include <ddi/irq.h>
    69 #include <sysinfo/sysinfo.h>
    70 #include <memstr.h>
    7161
    7262/** Disable I/O on non-privileged levels
     
    264254 * we need not to go to CPL0 to read it.
    265255 */
    266 sysarg_t sys_tls_set(sysarg_t addr)
     256sysarg_t sys_tls_set(uintptr_t addr)
    267257{
    268258        THREAD->arch.tls = addr;
    269259        write_msr(AMD_MSR_FS, addr);
    270260       
    271         return 0;
     261        return EOK;
    272262}
    273263
  • kernel/arch/ia32/src/ia32.c

    rf4d5f90 r9fe4db3  
    3636
    3737#include <arch.h>
    38 
    3938#include <typedefs.h>
    40 
    41 #include <arch/pm.h>
    42 
     39#include <errno.h>
     40#include <memstr.h>
     41#include <interrupt.h>
     42#include <console/console.h>
     43#include <syscall/syscall.h>
     44#include <sysinfo/sysinfo.h>
     45#include <arch/bios/bios.h>
     46#include <arch/boot/boot.h>
     47#include <arch/debugger.h>
     48#include <arch/drivers/i8254.h>
     49#include <arch/drivers/i8259.h>
     50#include <genarch/acpi/acpi.h>
     51#include <genarch/drivers/ega/ega.h>
     52#include <genarch/drivers/i8042/i8042.h>
     53#include <genarch/drivers/legacy/ia32/io.h>
     54#include <genarch/fb/bfb.h>
     55#include <genarch/kbrd/kbrd.h>
    4356#include <genarch/multiboot/multiboot.h>
    4457#include <genarch/multiboot/multiboot2.h>
    45 #include <genarch/drivers/legacy/ia32/io.h>
    46 #include <genarch/drivers/ega/ega.h>
    47 #include <genarch/fb/bfb.h>
    48 #include <genarch/drivers/i8042/i8042.h>
    49 #include <genarch/kbrd/kbrd.h>
    50 #include <arch/drivers/i8254.h>
    51 #include <arch/drivers/i8259.h>
    52 
    53 #include <arch/context.h>
    54 
    55 #include <config.h>
    56 
    57 #include <arch/interrupt.h>
    58 #include <arch/asm.h>
    59 #include <genarch/acpi/acpi.h>
    60 
    61 #include <arch/bios/bios.h>
    62 
    63 #include <interrupt.h>
    64 #include <ddi/irq.h>
    65 #include <arch/debugger.h>
    66 #include <proc/thread.h>
    67 #include <syscall/syscall.h>
    68 #include <console/console.h>
    69 #include <sysinfo/sysinfo.h>
    70 #include <arch/boot/boot.h>
    71 #include <memstr.h>
    7258
    7359#ifdef CONFIG_SMP
     
    219205 * selector, and the descriptor->base is the correct address.
    220206 */
    221 sysarg_t sys_tls_set(sysarg_t addr)
     207sysarg_t sys_tls_set(uintptr_t addr)
    222208{
    223209        THREAD->arch.tls = addr;
    224210        set_tls_desc(addr);
    225211       
    226         return 0;
     212        return EOK;
    227213}
    228214
  • kernel/arch/ia64/include/asm.h

    rf4d5f90 r9fe4db3  
    3838#include <config.h>
    3939#include <typedefs.h>
    40 #include <typedefs.h>
    4140#include <arch/register.h>
    4241#include <trace.h>
  • kernel/arch/ia64/src/ia64.c

    rf4d5f90 r9fe4db3  
    3434
    3535#include <arch.h>
    36 #include <arch/drivers/ski.h>
    37 #include <arch/drivers/it.h>
    38 #include <arch/interrupt.h>
    39 #include <arch/barrier.h>
    40 #include <arch/asm.h>
    41 #include <arch/register.h>
    4236#include <typedefs.h>
    43 #include <arch/context.h>
    44 #include <arch/stack.h>
    45 #include <arch/mm/page.h>
     37#include <errno.h>
    4638#include <interrupt.h>
    47 #include <mm/as.h>
    48 #include <config.h>
    4939#include <macros.h>
     40#include <str.h>
    5041#include <userspace.h>
    5142#include <console/console.h>
    52 #include <abi/proc/uarg.h>
    5343#include <syscall/syscall.h>
    54 #include <ddi/irq.h>
    55 #include <arch/bootinfo.h>
     44#include <sysinfo/sysinfo.h>
     45#include <arch/drivers/it.h>
     46#include <arch/drivers/kbd.h>
     47#include <genarch/drivers/ega/ega.h>
     48#include <genarch/drivers/i8042/i8042.h>
     49#include <genarch/drivers/ns16550/ns16550.h>
    5650#include <genarch/drivers/legacy/ia32/io.h>
    57 #include <genarch/drivers/ega/ega.h>
    5851#include <genarch/kbrd/kbrd.h>
    5952#include <genarch/srln/srln.h>
    60 #include <genarch/drivers/i8042/i8042.h>
    61 #include <genarch/drivers/ns16550/ns16550.h>
    62 #include <arch/drivers/kbd.h>
    63 #include <smp/smp.h>
    64 #include <smp/ipi.h>
    65 #include <arch/atomic.h>
    66 #include <panic.h>
    67 #include <print.h>
    68 #include <sysinfo/sysinfo.h>
    69 #include <str.h>
    7053
    7154/* NS16550 as a COM 1 */
     
    262245 * We use r13 (a.k.a. tp) for this purpose.
    263246 */
    264 sysarg_t sys_tls_set(sysarg_t addr)
    265 {
    266         return 0;
     247sysarg_t sys_tls_set(uintptr_t addr)
     248{
     249        return EOK;
    267250}
    268251
     
    270253{
    271254        pio_write_8((ioport8_t *)0x64, 0xfe);
    272         while (1)
    273                 ;
     255        while (1);
    274256}
    275257
  • kernel/arch/mips32/src/mips32.c

    rf4d5f90 r9fe4db3  
    3434
    3535#include <arch.h>
    36 #include <arch/cp0.h>
    37 #include <arch/exception.h>
    38 #include <arch/debug.h>
    39 #include <mm/as.h>
     36#include <typedefs.h>
     37#include <errno.h>
     38#include <interrupt.h>
     39#include <macros.h>
     40#include <str.h>
     41#include <memstr.h>
    4042#include <userspace.h>
    41 #include <memstr.h>
    42 #include <proc/thread.h>
    43 #include <abi/proc/uarg.h>
    44 #include <print.h>
    4543#include <console/console.h>
    4644#include <syscall/syscall.h>
    4745#include <sysinfo/sysinfo.h>
    48 #include <arch/interrupt.h>
    49 #include <interrupt.h>
    50 #include <console/chardev.h>
    51 #include <arch/barrier.h>
     46#include <arch/debug.h>
    5247#include <arch/debugger.h>
     48#include <arch/drivers/msim.h>
    5349#include <genarch/fb/fb.h>
    54 #include <abi/fb/visuals.h>
    5550#include <genarch/drivers/dsrln/dsrlnin.h>
    5651#include <genarch/drivers/dsrln/dsrlnout.h>
    5752#include <genarch/srln/srln.h>
    58 #include <macros.h>
    59 #include <config.h>
    60 #include <str.h>
    61 #include <arch/drivers/msim.h>
    62 #include <arch/asm/regname.h>
    6353
    6454/* Size of the code jumping to the exception handler code
     
    248238 * possible to have it separately in the future.
    249239 */
    250 sysarg_t sys_tls_set(sysarg_t addr)
    251 {
    252         return 0;
     240sysarg_t sys_tls_set(uintptr_t addr)
     241{
     242        return EOK;
    253243}
    254244
  • kernel/arch/mips64/src/mips64.c

    rf4d5f90 r9fe4db3  
    3434
    3535#include <arch.h>
    36 #include <arch/cp0.h>
    37 #include <arch/exception.h>
    38 #include <arch/debug.h>
    39 #include <mm/as.h>
     36#include <typedefs.h>
     37#include <errno.h>
     38#include <interrupt.h>
     39#include <macros.h>
     40#include <str.h>
     41#include <memstr.h>
    4042#include <userspace.h>
    41 #include <memstr.h>
    42 #include <proc/thread.h>
    43 #include <abi/proc/uarg.h>
    44 #include <print.h>
    4543#include <console/console.h>
    4644#include <syscall/syscall.h>
    4745#include <sysinfo/sysinfo.h>
    48 #include <arch/interrupt.h>
    49 #include <interrupt.h>
    50 #include <console/chardev.h>
    51 #include <arch/barrier.h>
     46#include <arch/debug.h>
    5247#include <arch/debugger.h>
     48#include <arch/drivers/msim.h>
    5349#include <genarch/fb/fb.h>
    54 #include <abi/fb/visuals.h>
    5550#include <genarch/drivers/dsrln/dsrlnin.h>
    5651#include <genarch/drivers/dsrln/dsrlnout.h>
    5752#include <genarch/srln/srln.h>
    58 #include <macros.h>
    59 #include <config.h>
    60 #include <str.h>
    61 #include <arch/drivers/msim.h>
    62 #include <arch/asm/regname.h>
    6353
    6454/* Size of the code jumping to the exception handler code
     
    226216 * possible to have it separately in the future.
    227217 */
    228 sysarg_t sys_tls_set(sysarg_t addr)
    229 {
    230         return 0;
     218sysarg_t sys_tls_set(uintptr_t addr)
     219{
     220        return EOK;
    231221}
    232222
  • kernel/generic/include/ddi/ddi.h

    rf4d5f90 r9fe4db3  
    5555extern void ddi_parea_register(parea_t *);
    5656
    57 extern sysarg_t sys_physmem_map(sysarg_t, sysarg_t, sysarg_t, sysarg_t);
     57extern sysarg_t sys_physmem_map(uintptr_t, uintptr_t, size_t, unsigned int);
     58
     59extern sysarg_t sys_dmamem_map(uintptr_t, size_t, unsigned int, unsigned int,
     60    void *);
     61extern sysarg_t sys_dmamem_unmap(uintptr_t, size_t, unsigned int);
     62
    5863extern sysarg_t sys_iospace_enable(ddi_ioarg_t *);
    5964
  • kernel/generic/include/mm/page.h

    rf4d5f90 r9fe4db3  
    6666extern uintptr_t hw_map(uintptr_t, size_t);
    6767
    68 extern sysarg_t sys_page_find_mapping(uintptr_t, uintptr_t *);
     68extern int page_find_mapping(uintptr_t, void **);
     69extern sysarg_t sys_page_find_mapping(uintptr_t, void *);
    6970
    7071#endif
  • kernel/generic/include/synch/smc.h

    rf4d5f90 r9fe4db3  
    3636#define KERN_SMC_H_
    3737
    38 extern sysarg_t sys_smc_coherence(uintptr_t va, size_t size);
     38extern sysarg_t sys_smc_coherence(uintptr_t, size_t);
    3939
    4040#endif
  • kernel/generic/include/syscall/syscall.h

    rf4d5f90 r9fe4db3  
    4545extern sysarg_t syscall_handler(sysarg_t, sysarg_t, sysarg_t, sysarg_t,
    4646    sysarg_t, sysarg_t, sysarg_t);
    47 extern sysarg_t sys_tls_set(sysarg_t);
     47extern sysarg_t sys_tls_set(uintptr_t);
    4848
    4949#endif
  • kernel/generic/src/ddi/ddi.c

    rf4d5f90 r9fe4db3  
    4545#include <mm/frame.h>
    4646#include <mm/as.h>
     47#include <mm/page.h>
    4748#include <synch/mutex.h>
    4849#include <syscall/copy.h>
     
    5253#include <errno.h>
    5354#include <trace.h>
     55#include <bitops.h>
    5456
    5557/** This lock protects the parea_btree. */
     
    8789/** Map piece of physical memory into virtual address space of current task.
    8890 *
    89  * @param p  Physical address of the starting frame.
    90  * @param v  Virtual address of the starting page.
     91 * @param phys  Physical address of the starting frame.
     92 * @param virt  Virtual address of the starting page.
    9193 * @param pages Number of pages to map.
    9294 * @param flags Address space area flags for the mapping.
    9395 *
    94  * @return 0 on success, EPERM if the caller lacks capabilities to use this
    95  *         syscall, EBADMEM if pf or vf is not page aligned, ENOENT if there
    96  *         is no task matching the specified ID or the physical address space
    97  *         is not enabled for mapping and ENOMEM if there was a problem in
    98  *         creating address space area.
    99  *
    100  */
    101 NO_TRACE static int ddi_physmem_map(uintptr_t pf, uintptr_t vp, size_t pages,
     96 * @return EOK on success.
     97 * @return EPERM if the caller lacks capabilities to use this syscall.
     98 * @return EBADMEM if phys or virt is not page aligned.
     99 * @return ENOENT if there is no task matching the specified ID or
     100 *         the physical address space is not enabled for mapping.
     101 * @return ENOMEM if there was a problem in creating address space area.
     102 *
     103 */
     104NO_TRACE static int ddi_physmem_map(uintptr_t phys, uintptr_t virt, size_t pages,
    102105    unsigned int flags)
    103106{
    104107        ASSERT(TASK);
    105108       
    106         if ((pf % FRAME_SIZE) != 0)
     109        if ((phys % FRAME_SIZE) != 0)
    107110                return EBADMEM;
    108111       
    109         if ((vp % PAGE_SIZE) != 0)
     112        if ((virt % PAGE_SIZE) != 0)
    110113                return EBADMEM;
    111114       
     
    118121       
    119122        mem_backend_data_t backend_data;
    120         backend_data.base = pf;
     123        backend_data.base = phys;
    121124        backend_data.frames = pages;
    122125       
     
    129132        btree_node_t *nodep;
    130133        parea_t *parea = (parea_t *) btree_search(&parea_btree,
    131             (btree_key_t) pf, &nodep);
     134            (btree_key_t) phys, &nodep);
    132135       
    133136        if ((parea != NULL) && (parea->frames >= pages)) {
     
    149152       
    150153        irq_spinlock_lock(&zones.lock, true);
    151         size_t znum = find_zone(ADDR2PFN(pf), pages, 0);
     154        size_t znum = find_zone(ADDR2PFN(phys), pages, 0);
    152155       
    153156        if (znum == (size_t) -1) {
     
    182185       
    183186map:
    184         if (!as_area_create(TASK->as, flags, pages * PAGE_SIZE, vp,
     187        if (!as_area_create(TASK->as, flags, FRAMES2SIZE(pages), virt,
    185188            AS_AREA_ATTR_NONE, &phys_backend, &backend_data)) {
    186189                /*
     
    253256/** Wrapper for SYS_PHYSMEM_MAP syscall.
    254257 *
    255  * @param phys_base Physical base address to map
    256  * @param virt_base Destination virtual address
     258 * @param phys  Physical base address to map
     259 * @param virt  Destination virtual address
    257260 * @param pages Number of pages
    258261 * @param flags Flags of newly mapped pages
     
    261264 *
    262265 */
    263 sysarg_t sys_physmem_map(sysarg_t phys_base, sysarg_t virt_base,
    264     sysarg_t pages, sysarg_t flags)
    265 {
    266         return (sysarg_t) ddi_physmem_map(ALIGN_DOWN((uintptr_t) phys_base,
    267             FRAME_SIZE), ALIGN_DOWN((uintptr_t) virt_base, PAGE_SIZE),
    268             (size_t) pages, (int) flags);
     266sysarg_t sys_physmem_map(uintptr_t phys, uintptr_t virt,
     267    size_t pages, unsigned int flags)
     268{
     269        return (sysarg_t)
     270            ddi_physmem_map(ALIGN_DOWN(phys, FRAME_SIZE),
     271            ALIGN_DOWN(virt, PAGE_SIZE), pages, flags);
    269272}
    270273
     
    287290}
    288291
     292NO_TRACE static int dmamem_map(uintptr_t virt, size_t size,
     293    unsigned int map_flags, unsigned int flags, void **phys)
     294{
     295        ASSERT(TASK);
     296       
     297        if ((flags & DMAMEM_FLAGS_ANONYMOUS) == 0) {
     298                // TODO: implement locking of non-anonymous mapping
     299                return page_find_mapping(virt, phys);
     300        } else {
     301                // TODO: implement locking
     302               
     303                if ((virt % PAGE_SIZE) != 0)
     304                        return EBADMEM;
     305               
     306                size_t pages = SIZE2FRAMES(size);
     307                uint8_t order;
     308               
     309                /* We need the 2^order >= pages */
     310                if (pages == 1)
     311                        order = 0;
     312                else
     313                        order = fnzb(pages - 1) + 1;
     314               
     315                *phys = frame_alloc_noreserve(order, 0);
     316                if (*phys == NULL)
     317                        return ENOMEM;
     318               
     319                mem_backend_data_t backend_data;
     320                backend_data.base = (uintptr_t) *phys;
     321                backend_data.frames = pages;
     322               
     323                if (!as_area_create(TASK->as, map_flags, size, virt,
     324                    AS_AREA_ATTR_NONE, &phys_backend, &backend_data)) {
     325                        frame_free_noreserve((uintptr_t) *phys);
     326                        return ENOMEM;
     327                }
     328               
     329                return EOK;
     330        }
     331}
     332
     333NO_TRACE static int dmamem_unmap(uintptr_t virt, size_t size,
     334    unsigned int flags)
     335{
     336        // TODO: implement unlocking & unmap
     337        return EOK;
     338}
     339
     340sysarg_t sys_dmamem_map(uintptr_t virt, size_t size, unsigned int map_flags,
     341    unsigned int flags, void *phys_ptr)
     342{
     343        void *phys;
     344        int rc = dmamem_map(virt, size, map_flags, flags, &phys);
     345        if (rc != EOK)
     346                return rc;
     347       
     348        rc = copy_to_uspace(phys_ptr, &phys, sizeof(phys));
     349        if (rc != EOK) {
     350                dmamem_unmap(virt, size, flags);
     351                return rc;
     352        }
     353       
     354        return EOK;
     355}
     356
     357sysarg_t sys_dmamem_unmap(uintptr_t virt, size_t size, unsigned int flags)
     358{
     359        return dmamem_unmap(virt, size, flags);
     360}
     361
    289362/** @}
    290363 */
  • kernel/generic/src/ipc/irq.c

    rf4d5f90 r9fe4db3  
    365365                return IRQ_DECLINE;
    366366       
    367 #define CMD_MEM_READ(target) \
    368 do { \
    369         void *va = code->cmds[i].addr; \
    370         if (AS != irq->driver_as) \
    371                 as_switch(AS, irq->driver_as); \
    372         memcpy_from_uspace(&target, va, (sizeof(target))); \
    373         if (dstarg) \
    374                 scratch[dstarg] = target; \
    375 } while(0)
    376 
    377 #define CMD_MEM_WRITE(val) \
    378 do { \
    379         void *va = code->cmds[i].addr; \
    380         if (AS != irq->driver_as) \
    381                 as_switch(AS, irq->driver_as); \
    382         memcpy_to_uspace(va, &val, sizeof(val)); \
    383 } while (0)
    384 
    385367        as_t *current_as = AS;
    386         size_t i;
    387         for (i = 0; i < code->cmdcount; i++) {
     368        if (current_as != irq->driver_as)
     369                as_switch(AS, irq->driver_as);
     370       
     371        for (size_t i = 0; i < code->cmdcount; i++) {
    388372                uint32_t dstval;
     373                void *va;
     374                uint8_t val8;
     375                uint16_t val16;
     376                uint32_t val32;
     377               
    389378                uintptr_t srcarg = code->cmds[i].srcarg;
    390379                uintptr_t dstarg = code->cmds[i].dstarg;
     
    442431                        }
    443432                        break;
    444                 case CMD_MEM_READ_8: {
    445                         uint8_t val;
    446                         CMD_MEM_READ(val);
    447                         break;
    448                         }
    449                 case CMD_MEM_READ_16: {
    450                         uint16_t val;
    451                         CMD_MEM_READ(val);
    452                         break;
    453                         }
    454                 case CMD_MEM_READ_32: {
    455                         uint32_t val;
    456                         CMD_MEM_READ(val);
    457                         break;
    458                         }
    459                 case CMD_MEM_WRITE_8: {
    460                         uint8_t val = code->cmds[i].value;
    461                         CMD_MEM_WRITE(val);
    462                         break;
    463                         }
    464                 case CMD_MEM_WRITE_16: {
    465                         uint16_t val = code->cmds[i].value;
    466                         CMD_MEM_WRITE(val);
    467                         break;
    468                         }
    469                 case CMD_MEM_WRITE_32: {
    470                         uint32_t val = code->cmds[i].value;
    471                         CMD_MEM_WRITE(val);
    472                         break;
    473                         }
     433                case CMD_MEM_READ_8:
     434                        va = code->cmds[i].addr;
     435                        memcpy_from_uspace(&val8, va, sizeof(val8));
     436                        if (dstarg)
     437                                scratch[dstarg] = val8;
     438                        break;
     439                case CMD_MEM_READ_16:
     440                        va = code->cmds[i].addr;
     441                        memcpy_from_uspace(&val16, va, sizeof(val16));
     442                        if (dstarg)
     443                                scratch[dstarg] = val16;
     444                        break;
     445                case CMD_MEM_READ_32:
     446                        va = code->cmds[i].addr;
     447                        memcpy_from_uspace(&val32, va, sizeof(val32));
     448                        if (dstarg)
     449                                scratch[dstarg] = val32;
     450                        break;
     451                case CMD_MEM_WRITE_8:
     452                        val8 = code->cmds[i].value;
     453                        va = code->cmds[i].addr;
     454                        memcpy_to_uspace(va, &val8, sizeof(val8));
     455                        break;
     456                case CMD_MEM_WRITE_16:
     457                        val16 = code->cmds[i].value;
     458                        va = code->cmds[i].addr;
     459                        memcpy_to_uspace(va, &val16, sizeof(val16));
     460                        break;
     461                case CMD_MEM_WRITE_32:
     462                        val32 = code->cmds[i].value;
     463                        va = code->cmds[i].addr;
     464                        memcpy_to_uspace(va, &val32, sizeof(val32));
     465                        break;
    474466                case CMD_MEM_WRITE_A_8:
    475467                        if (srcarg) {
    476                                 uint8_t val = scratch[srcarg];
    477                                 CMD_MEM_WRITE(val);
     468                                val8 = scratch[srcarg];
     469                                va = code->cmds[i].addr;
     470                                memcpy_to_uspace(va, &val8, sizeof(val8));
    478471                        }
    479472                        break;
    480473                case CMD_MEM_WRITE_A_16:
    481474                        if (srcarg) {
    482                                 uint16_t val = scratch[srcarg];
    483                                 CMD_MEM_WRITE(val);
     475                                val16 = scratch[srcarg];
     476                                va = code->cmds[i].addr;
     477                                memcpy_to_uspace(va, &val16, sizeof(val16));
    484478                        }
    485479                        break;
    486480                case CMD_MEM_WRITE_A_32:
    487481                        if (srcarg) {
    488                                 uint32_t val = scratch[srcarg];
    489                                 CMD_MEM_WRITE(val);
     482                                val32 = scratch[srcarg];
     483                                va = code->cmds[i].addr;
     484                                memcpy_to_uspace(va, &val32, sizeof(val32));
    490485                        }
    491486                        break;
     
    513508                }
    514509        }
     510       
    515511        if (AS != current_as)
    516512                as_switch(AS, current_as);
  • kernel/generic/src/mm/page.c

    rf4d5f90 r9fe4db3  
    5353 * We assume that the other processors are either not using the mapping yet
    5454 * (i.e. during the bootstrap) or are executing the TLB shootdown code.  While
    55  * we don't care much about the former case, the processors in the latter case 
     55 * we don't care much about the former case, the processors in the latter case
    5656 * will do an implicit serialization by virtue of running the TLB shootdown
    5757 * interrupt handler.
     
    7474#include <syscall/copy.h>
    7575#include <errno.h>
     76#include <align.h>
    7677
    7778/** Virtual operations for page subsystem. */
     
    176177}
    177178
     179int page_find_mapping(uintptr_t virt, void **phys)
     180{
     181        mutex_lock(&AS->lock);
     182       
     183        pte_t *pte = page_mapping_find(AS, virt, false);
     184        if ((!PTE_VALID(pte)) || (!PTE_PRESENT(pte))) {
     185                mutex_unlock(&AS->lock);
     186                return ENOENT;
     187        }
     188       
     189        *phys = (void *) PTE_GET_FRAME(pte) +
     190            (virt - ALIGN_DOWN(virt, PAGE_SIZE));
     191       
     192        mutex_unlock(&AS->lock);
     193       
     194        return EOK;
     195}
     196
    178197/** Syscall wrapper for getting mapping of a virtual page.
    179  *
    180  * @retval EOK Everything went find, @p uspace_frame and @p uspace_node
    181  *             contains correct values.
    182  * @retval ENOENT Virtual address has no mapping.
    183  */
    184 sysarg_t sys_page_find_mapping(uintptr_t virt_address,
    185     uintptr_t *uspace_frame)
    186 {
    187         mutex_lock(&AS->lock);
    188        
    189         pte_t *pte = page_mapping_find(AS, virt_address, false);
    190         if (!PTE_VALID(pte) || !PTE_PRESENT(pte)) {
    191                 mutex_unlock(&AS->lock);
    192                
    193                 return (sysarg_t) ENOENT;
    194         }
    195        
    196         uintptr_t phys_address = PTE_GET_FRAME(pte);
    197        
    198         mutex_unlock(&AS->lock);
    199        
    200         int rc = copy_to_uspace(uspace_frame,
    201             &phys_address, sizeof(phys_address));
    202         if (rc != EOK) {
    203                 return (sysarg_t) rc;
    204         }
    205        
    206         return EOK;
     198 *
     199 * @return EOK on success.
     200 * @return ENOENT if no virtual address mapping found.
     201 *
     202 */
     203sysarg_t sys_page_find_mapping(uintptr_t virt, void *phys_ptr)
     204{
     205        void *phys;
     206        int rc = page_find_mapping(virt, &phys);
     207        if (rc != EOK)
     208                return rc;
     209       
     210        rc = copy_to_uspace(phys_ptr, &phys, sizeof(phys));
     211        return (sysarg_t) rc;
    207212}
    208213
  • kernel/generic/src/syscall/syscall.c

    rf4d5f90 r9fe4db3  
    176176        (syshandler_t) sys_device_assign_devno,
    177177        (syshandler_t) sys_physmem_map,
     178        (syshandler_t) sys_dmamem_map,
     179        (syshandler_t) sys_dmamem_unmap,
    178180        (syshandler_t) sys_iospace_enable,
    179181        (syshandler_t) sys_register_irq,
  • uspace/app/tester/mm/mapping1.c

    rf4d5f90 r9fe4db3  
    7171        int i;
    7272        for (i = 0; i < page_count; i++) {
    73                 void *page_start = ((char *)area) + PAGE_SIZE * i;
     73                void *page_start = ((char *) area) + PAGE_SIZE * i;
    7474                int rc = as_get_physical_mapping(page_start, NULL);
    7575                if (rc != expected_rc) {
  • uspace/drv/bus/usb/ohci/utils/malloc32.h

    rf4d5f90 r9fe4db3  
    5656        uintptr_t result;
    5757        int ret = as_get_physical_mapping(addr, &result);
    58 
     58       
    5959        if (ret != EOK)
    6060                return 0;
    61         return (result | ((uintptr_t)addr & 0xfff));
     61       
     62        return result;
    6263}
    6364/*----------------------------------------------------------------------------*/
  • uspace/drv/bus/usb/uhci/utils/malloc32.h

    rf4d5f90 r9fe4db3  
    5454        if (addr == NULL)
    5555                return 0;
    56 
     56       
    5757        uintptr_t result;
    5858        const int ret = as_get_physical_mapping(addr, &result);
    5959        if (ret != EOK)
    6060                return 0;
    61         return (result | ((uintptr_t)addr & 0xfff));
     61       
     62        return result;
    6263}
    6364/*----------------------------------------------------------------------------*/
  • uspace/drv/nic/e1k/e1k.c

    rf4d5f90 r9fe4db3  
    7070
    7171/** nic_driver_data_t* -> e1000_t* cast */
    72 #define DRIVER_DATA_NIC(nic_data) \
    73         ((e1000_t *) nic_get_specific(nic_data))
     72#define DRIVER_DATA_NIC(nic) \
     73        ((e1000_t *) nic_get_specific(nic))
    7474
    7575/** device_t* -> nic_driver_data_t* cast */
     
    9797#define MEMADDR_TO_PTR(memaddr)  ((void *) ((size_t) (memaddr)))
    9898
    99 #define E1000_REG_BASE(e1000_data) \
    100         ((e1000_data)->virt_reg_base)
    101 
    102 #define E1000_REG_ADDR(e1000_data, reg) \
    103         ((uint32_t *) (E1000_REG_BASE(e1000_data) + reg))
    104 
    105 #define E1000_REG_READ(e1000_data, reg) \
    106         (pio_read_32(E1000_REG_ADDR(e1000_data, reg)))
    107 
    108 #define E1000_REG_WRITE(e1000_data, reg, value) \
    109         (pio_write_32(E1000_REG_ADDR(e1000_data, reg), value))
     99#define E1000_REG_BASE(e1000) \
     100        ((e1000)->reg_base_virt)
     101
     102#define E1000_REG_ADDR(e1000, reg) \
     103        ((uint32_t *) (E1000_REG_BASE(e1000) + reg))
     104
     105#define E1000_REG_READ(e1000, reg) \
     106        (pio_read_32(E1000_REG_ADDR(e1000, reg)))
     107
     108#define E1000_REG_WRITE(e1000, reg, value) \
     109        (pio_write_32(E1000_REG_ADDR(e1000, reg), value))
    110110
    111111/** E1000 device data */
    112 typedef struct e1000_data {
     112typedef struct {
    113113        /** Physical registers base address */
    114         void *phys_reg_base;
     114        void *reg_base_phys;
    115115        /** Virtual registers base address */
    116         void *virt_reg_base;
    117         /** Tx ring */
    118         dmamem_t tx_ring;
     116        void *reg_base_virt;
     117       
     118        /** Physical tx ring address */
     119        void *tx_ring_phys;
     120        /** Virtual tx ring address */
     121        void *tx_ring_virt;
     122       
    119123        /** Packets in tx ring  */
    120124        packet_t **tx_ring_packets;
    121         /** Rx ring */
    122         dmamem_t rx_ring;
     125       
     126        /** Physical rx ring address */
     127        void *rx_ring_phys;
     128        /** Virtual rx ring address */
     129        void *rx_ring_virt;
     130       
    123131        /** Packets in rx ring  */
    124132        packet_t **rx_ring_packets;
     133       
    125134        /** VLAN tag */
    126135        uint16_t vlan_tag;
     136       
    127137        /** Add VLAN tag to packet */
    128138        bool vlan_tag_add;
     139       
    129140        /** Used unicast Receive Address count */
    130141        unsigned int unicast_ra_count;
     142       
    131143        /** Used milticast Receive addrress count */
    132144        unsigned int multicast_ra_count;
     145       
    133146        /** PCI device ID */
    134147        uint16_t device_id;
     148       
    135149        /** The irq assigned */
    136150        int irq;
     151       
    137152        /** Lock for CTRL register */
    138153        fibril_mutex_t ctrl_lock;
     154       
    139155        /** Lock for receiver */
    140156        fibril_mutex_t rx_lock;
     157       
    141158        /** Lock for transmitter */
    142159        fibril_mutex_t tx_lock;
     160       
    143161        /** Lock for EEPROM access */
    144162        fibril_mutex_t eeprom_lock;
     
    225243                .cmd = CMD_PIO_WRITE_32,
    226244                .addr = NULL,
    227                 .value = 0xFFFFFFFF
     245                .value = 0xffffffff
    228246        },
    229247        {
     
    280298        assert(state);
    281299       
    282         e1000_t *e1000_data = DRIVER_DATA_DEV(dev);
    283         if (E1000_REG_READ(e1000_data, E1000_STATUS) & (STATUS_LU))
     300        e1000_t *e1000 = DRIVER_DATA_DEV(dev);
     301        if (E1000_REG_READ(e1000, E1000_STATUS) & (STATUS_LU))
    284302                *state = NIC_CS_PLUGGED;
    285303        else
     
    300318    nic_channel_mode_t *duplex, nic_role_t *role)
    301319{
    302         e1000_t *e1000_data = DRIVER_DATA_DEV(dev);
    303         uint32_t status = E1000_REG_READ(e1000_data, E1000_STATUS);
     320        e1000_t *e1000 = DRIVER_DATA_DEV(dev);
     321        uint32_t status = E1000_REG_READ(e1000, E1000_STATUS);
    304322       
    305323        if (status & STATUS_FD)
     
    323341}
    324342
    325 static void e1000_link_restart(e1000_t * e1000_data)
    326 {
    327         fibril_mutex_lock(&e1000_data->ctrl_lock);
    328        
    329         uint32_t ctrl = E1000_REG_READ(e1000_data, E1000_CTRL);
     343static void e1000_link_restart(e1000_t *e1000)
     344{
     345        fibril_mutex_lock(&e1000->ctrl_lock);
     346       
     347        uint32_t ctrl = E1000_REG_READ(e1000, E1000_CTRL);
    330348       
    331349        if (ctrl & CTRL_SLU) {
    332350                ctrl &= ~(CTRL_SLU);
    333                 fibril_mutex_unlock(&e1000_data->ctrl_lock);
     351                fibril_mutex_unlock(&e1000->ctrl_lock);
    334352                usleep(10);
    335                 fibril_mutex_lock(&e1000_data->ctrl_lock);
     353                fibril_mutex_lock(&e1000->ctrl_lock);
    336354                ctrl |= CTRL_SLU;
    337355        }
    338356       
    339         fibril_mutex_unlock(&e1000_data->ctrl_lock);
    340        
    341         e1000_link_restart(e1000_data);
     357        fibril_mutex_unlock(&e1000->ctrl_lock);
     358       
     359        e1000_link_restart(e1000);
    342360}
    343361
     
    354372                return EINVAL;
    355373       
    356         e1000_t *e1000_data = DRIVER_DATA_DEV(dev);
    357        
    358         fibril_mutex_lock(&e1000_data->ctrl_lock);
    359         uint32_t ctrl = E1000_REG_READ(e1000_data, E1000_CTRL);
     374        e1000_t *e1000 = DRIVER_DATA_DEV(dev);
     375       
     376        fibril_mutex_lock(&e1000->ctrl_lock);
     377        uint32_t ctrl = E1000_REG_READ(e1000, E1000_CTRL);
    360378       
    361379        ctrl |= CTRL_FRCSPD;
     
    376394                ctrl |= CTRL_SPEED_10 << CTRL_SPEED_SHIFT;
    377395       
    378         E1000_REG_WRITE(e1000_data, E1000_CTRL, ctrl);
    379        
    380         fibril_mutex_unlock(&e1000_data->ctrl_lock);
    381        
    382         e1000_link_restart(e1000_data);
     396        E1000_REG_WRITE(e1000, E1000_CTRL, ctrl);
     397       
     398        fibril_mutex_unlock(&e1000->ctrl_lock);
     399       
     400        e1000_link_restart(e1000);
    383401       
    384402        return EOK;
     
    395413static int e1000_autoneg_enable(ddf_fun_t *dev, uint32_t advertisement)
    396414{
    397         e1000_t *e1000_data = DRIVER_DATA_DEV(dev);
    398        
    399         fibril_mutex_lock(&e1000_data->ctrl_lock);
    400        
    401         uint32_t ctrl = E1000_REG_READ(e1000_data, E1000_CTRL);
     415        e1000_t *e1000 = DRIVER_DATA_DEV(dev);
     416       
     417        fibril_mutex_lock(&e1000->ctrl_lock);
     418       
     419        uint32_t ctrl = E1000_REG_READ(e1000, E1000_CTRL);
    402420       
    403421        ctrl &= ~(CTRL_FRCSPD);
     
    405423        ctrl |= CTRL_ASDE;
    406424       
    407         E1000_REG_WRITE(e1000_data, E1000_CTRL, ctrl);
    408        
    409         fibril_mutex_unlock(&e1000_data->ctrl_lock);
    410        
    411         e1000_link_restart(e1000_data);
     425        E1000_REG_WRITE(e1000, E1000_CTRL, ctrl);
     426       
     427        fibril_mutex_unlock(&e1000->ctrl_lock);
     428       
     429        e1000_link_restart(e1000);
    412430       
    413431        return EOK;
     
    423441static int e1000_autoneg_disable(ddf_fun_t *dev)
    424442{
    425         e1000_t *e1000_data = DRIVER_DATA_DEV(dev);
    426        
    427         fibril_mutex_lock(&e1000_data->ctrl_lock);
    428        
    429         uint32_t ctrl = E1000_REG_READ(e1000_data, E1000_CTRL);
     443        e1000_t *e1000 = DRIVER_DATA_DEV(dev);
     444       
     445        fibril_mutex_lock(&e1000->ctrl_lock);
     446       
     447        uint32_t ctrl = E1000_REG_READ(e1000, E1000_CTRL);
    430448       
    431449        ctrl |= CTRL_FRCSPD;
     
    433451        ctrl &= ~(CTRL_ASDE);
    434452       
    435         E1000_REG_WRITE(e1000_data, E1000_CTRL, ctrl);
    436        
    437         fibril_mutex_unlock(&e1000_data->ctrl_lock);
    438        
    439         e1000_link_restart(e1000_data);
     453        E1000_REG_WRITE(e1000, E1000_CTRL, ctrl);
     454       
     455        fibril_mutex_unlock(&e1000->ctrl_lock);
     456       
     457        e1000_link_restart(e1000);
    440458       
    441459        return EOK;
     
    462480static int e1000_defective_get_mode(ddf_fun_t *device, uint32_t *mode)
    463481{
    464         e1000_t *e1000_data = DRIVER_DATA_DEV(device);
     482        e1000_t *e1000 = DRIVER_DATA_DEV(device);
    465483       
    466484        *mode = 0;
    467         uint32_t rctl = E1000_REG_READ(e1000_data, E1000_RCTL);
     485        uint32_t rctl = E1000_REG_READ(e1000, E1000_RCTL);
    468486        if (rctl & RCTL_SBP)
    469487                *mode = NIC_DEFECTIVE_BAD_CRC | NIC_DEFECTIVE_SHORT;
     
    483501static int e1000_defective_set_mode(ddf_fun_t *device, uint32_t mode)
    484502{
    485         e1000_t *e1000_data = DRIVER_DATA_DEV(device);
     503        e1000_t *e1000 = DRIVER_DATA_DEV(device);
    486504        int rc = EOK;
    487505       
    488         fibril_mutex_lock(&e1000_data->rx_lock);
    489        
    490         uint32_t rctl = E1000_REG_READ(e1000_data, E1000_RCTL);
     506        fibril_mutex_lock(&e1000->rx_lock);
     507       
     508        uint32_t rctl = E1000_REG_READ(e1000, E1000_RCTL);
    491509        bool short_mode = (mode & NIC_DEFECTIVE_SHORT ? true : false);
    492510        bool bad_mode = (mode & NIC_DEFECTIVE_BAD_CRC ? true : false);
     
    499517                rc = ENOTSUP;
    500518       
    501         E1000_REG_WRITE(e1000_data, E1000_RCTL, rctl);
    502        
    503         fibril_mutex_unlock(&e1000_data->rx_lock);
     519        E1000_REG_WRITE(e1000, E1000_RCTL, rctl);
     520       
     521        fibril_mutex_unlock(&e1000->rx_lock);
    504522        return rc;
    505523};
     
    507525/** Write receive address to RA registr
    508526 *
    509  * @param e1000_data E1000 data structure
     527 * @param e1000      E1000 data structure
    510528 * @param position   RA register position
    511529 * @param address    Ethernet address
     
    513531 *
    514532 */
    515 static void e1000_write_receive_address(e1000_t *e1000_data,
    516     unsigned int position, const nic_address_t * address,
    517     bool set_av_bit)
     533static void e1000_write_receive_address(e1000_t *e1000, unsigned int position,
     534    const nic_address_t * address, bool set_av_bit)
    518535{
    519536        uint8_t *mac0 = (uint8_t *) address->address;
     
    533550                rah |= RAH_AV;
    534551        else
    535                 rah |= E1000_REG_READ(e1000_data, E1000_RAH_ARRAY(position)) &
    536                     RAH_AV;
    537        
    538         E1000_REG_WRITE(e1000_data, E1000_RAH_ARRAY(position), rah);
    539         E1000_REG_WRITE(e1000_data, E1000_RAL_ARRAY(position), ral);
     552                rah |= E1000_REG_READ(e1000, E1000_RAH_ARRAY(position)) & RAH_AV;
     553       
     554        E1000_REG_WRITE(e1000, E1000_RAH_ARRAY(position), rah);
     555        E1000_REG_WRITE(e1000, E1000_RAL_ARRAY(position), ral);
    540556}
    541557
     
    544560 *  Clear Address Valid bit
    545561 *
    546  * @param e1000_data E1000 data structure
    547  * @param position   RA register position
    548  *
    549  */
    550 static void e1000_disable_receive_address(e1000_t *e1000_data,
    551     unsigned int position)
    552 {
    553         uint32_t rah =
    554             E1000_REG_READ(e1000_data, E1000_RAH_ARRAY(position));
     562 * @param e1000    E1000 data structure
     563 * @param position RA register position
     564 *
     565 */
     566static void e1000_disable_receive_address(e1000_t *e1000, unsigned int position)
     567{
     568        uint32_t rah = E1000_REG_READ(e1000, E1000_RAH_ARRAY(position));
    555569        rah = rah & ~RAH_AV;
    556         E1000_REG_WRITE(e1000_data, E1000_RAH_ARRAY(position), rah);
     570        E1000_REG_WRITE(e1000, E1000_RAH_ARRAY(position), rah);
    557571}
    558572
    559573/** Clear all unicast addresses from RA registers
    560574 *
    561  * @param e1000_data E1000 data structure
    562  *
    563  */
    564 static void e1000_clear_unicast_receive_addresses(e1000_t *e1000_data)
     575 * @param e1000 E1000 data structure
     576 *
     577 */
     578static void e1000_clear_unicast_receive_addresses(e1000_t *e1000)
    565579{
    566580        for (unsigned int ra_num = 1;
    567             ra_num <= e1000_data->unicast_ra_count;
     581            ra_num <= e1000->unicast_ra_count;
    568582            ra_num++)
    569                 e1000_disable_receive_address(e1000_data, ra_num);
    570        
    571         e1000_data->unicast_ra_count = 0;
     583                e1000_disable_receive_address(e1000, ra_num);
     584       
     585        e1000->unicast_ra_count = 0;
    572586}
    573587
    574588/** Clear all multicast addresses from RA registers
    575589 *
    576  * @param e1000_data E1000 data structure
    577  *
    578  */
    579 static void e1000_clear_multicast_receive_addresses(e1000_t *e1000_data)
     590 * @param e1000 E1000 data structure
     591 *
     592 */
     593static void e1000_clear_multicast_receive_addresses(e1000_t *e1000)
    580594{
    581595        unsigned int first_multicast_ra_num =
    582             E1000_RECEIVE_ADDRESS - e1000_data->multicast_ra_count;
     596            E1000_RECEIVE_ADDRESS - e1000->multicast_ra_count;
    583597       
    584598        for (unsigned int ra_num = E1000_RECEIVE_ADDRESS - 1;
    585599            ra_num >= first_multicast_ra_num;
    586600            ra_num--)
    587                 e1000_disable_receive_address(e1000_data, ra_num);
    588        
    589         e1000_data->multicast_ra_count = 0;
     601                e1000_disable_receive_address(e1000, ra_num);
     602       
     603        e1000->multicast_ra_count = 0;
    590604}
    591605
    592606/** Return receive address filter positions count usable for unicast
    593607 *
    594  * @param e1000_data E1000 data structure
     608 * @param e1000 E1000 data structure
    595609 *
    596610 * @return receive address filter positions count usable for unicast
    597611 *
    598612 */
    599 static unsigned int get_free_unicast_address_count(e1000_t *e1000_data)
    600 {
    601         return E1000_RECEIVE_ADDRESS - 1 - e1000_data->multicast_ra_count;
     613static unsigned int get_free_unicast_address_count(e1000_t *e1000)
     614{
     615        return E1000_RECEIVE_ADDRESS - 1 - e1000->multicast_ra_count;
    602616}
    603617
    604618/** Return receive address filter positions count usable for multicast
    605619 *
    606  * @param e1000_data E1000 data structure
     620 * @param e1000 E1000 data structure
    607621 *
    608622 * @return receive address filter positions count usable for multicast
    609623 *
    610624 */
    611 static unsigned int get_free_multicast_address_count(e1000_t *e1000_data)
    612 {
    613         return E1000_RECEIVE_ADDRESS - 1 - e1000_data->unicast_ra_count;
     625static unsigned int get_free_multicast_address_count(e1000_t *e1000)
     626{
     627        return E1000_RECEIVE_ADDRESS - 1 - e1000->unicast_ra_count;
    614628}
    615629
    616630/** Write unicast receive addresses to receive address filter registers
    617631 *
    618  * @param e1000_data E1000 data structure
    619  * @param addr       Pointer to address array
    620  * @param addr_cnt   Address array count
    621  *
    622  */
    623 static void e1000_add_unicast_receive_addresses(e1000_t *e1000_data,
     632 * @param e1000    E1000 data structure
     633 * @param addr     Pointer to address array
     634 * @param addr_cnt Address array count
     635 *
     636 */
     637static void e1000_add_unicast_receive_addresses(e1000_t *e1000,
    624638    const nic_address_t *addr, size_t addr_cnt)
    625639{
    626         assert(addr_cnt <= get_free_unicast_address_count(e1000_data));
     640        assert(addr_cnt <= get_free_unicast_address_count(e1000));
    627641       
    628642        nic_address_t *addr_iterator = (nic_address_t *) addr;
     
    632646            ra_num <= addr_cnt;
    633647            ra_num++) {
    634                 e1000_write_receive_address(e1000_data, ra_num, addr_iterator, true);
     648                e1000_write_receive_address(e1000, ra_num, addr_iterator, true);
    635649                addr_iterator++;
    636650        }
     
    639653/** Write multicast receive addresses to receive address filter registers
    640654 *
    641  * @param e1000_data E1000 data structure
    642  * @param addr       Pointer to address array
    643  * @param addr_cnt   Address array count
    644  *
    645  */
    646 static void e1000_add_multicast_receive_addresses(e1000_t *e1000_data,
     655 * @param e1000    E1000 data structure
     656 * @param addr     Pointer to address array
     657 * @param addr_cnt Address array count
     658 *
     659 */
     660static void e1000_add_multicast_receive_addresses(e1000_t *e1000,
    647661    const nic_address_t *addr, size_t addr_cnt)
    648662{
    649         assert(addr_cnt <= get_free_multicast_address_count(e1000_data));
     663        assert(addr_cnt <= get_free_multicast_address_count(e1000));
    650664       
    651665        nic_address_t *addr_iterator = (nic_address_t *) addr;
     
    655669            ra_num >= first_multicast_ra_num;
    656670            ra_num--) {
    657                 e1000_write_receive_address(e1000_data, ra_num, addr_iterator, true);
     671                e1000_write_receive_address(e1000, ra_num, addr_iterator, true);
    658672                addr_iterator++;
    659673        }
     
    662676/** Disable receiving packets for default address
    663677 *
    664  * @param e1000_data E1000 data structure
    665  *
    666  */
    667 static void disable_ra0_address_filter(e1000_t *e1000_data)
    668 {
    669         uint32_t rah0 = E1000_REG_READ(e1000_data, E1000_RAH_ARRAY(0));
     678 * @param e1000 E1000 data structure
     679 *
     680 */
     681static void disable_ra0_address_filter(e1000_t *e1000)
     682{
     683        uint32_t rah0 = E1000_REG_READ(e1000, E1000_RAH_ARRAY(0));
    670684        rah0 = rah0 & ~RAH_AV;
    671         E1000_REG_WRITE(e1000_data, E1000_RAH_ARRAY(0), rah0);
     685        E1000_REG_WRITE(e1000, E1000_RAH_ARRAY(0), rah0);
    672686}
    673687
    674688/** Enable receiving packets for default address
    675689 *
    676  * @param e1000_data E1000 data structure
    677  *
    678  */
    679 static void enable_ra0_address_filter(e1000_t *e1000_data)
    680 {
    681         uint32_t rah0 = E1000_REG_READ(e1000_data, E1000_RAH_ARRAY(0));
     690 * @param e1000 E1000 data structure
     691 *
     692 */
     693static void enable_ra0_address_filter(e1000_t *e1000)
     694{
     695        uint32_t rah0 = E1000_REG_READ(e1000, E1000_RAH_ARRAY(0));
    682696        rah0 = rah0 | RAH_AV;
    683         E1000_REG_WRITE(e1000_data, E1000_RAH_ARRAY(0), rah0);
     697        E1000_REG_WRITE(e1000, E1000_RAH_ARRAY(0), rah0);
    684698}
    685699
    686700/** Disable unicast promiscuous mode
    687701 *
    688  * @param e1000_data E1000 data structure
    689  *
    690  */
    691 static void e1000_disable_unicast_promisc(e1000_t *e1000_data)
    692 {
    693         uint32_t rctl = E1000_REG_READ(e1000_data, E1000_RCTL);
     702 * @param e1000 E1000 data structure
     703 *
     704 */
     705static void e1000_disable_unicast_promisc(e1000_t *e1000)
     706{
     707        uint32_t rctl = E1000_REG_READ(e1000, E1000_RCTL);
    694708        rctl = rctl & ~RCTL_UPE;
    695         E1000_REG_WRITE(e1000_data, E1000_RCTL, rctl);
     709        E1000_REG_WRITE(e1000, E1000_RCTL, rctl);
    696710}
    697711
    698712/** Enable unicast promiscuous mode
    699713 *
    700  * @param e1000_data E1000 data structure
    701  *
    702  */
    703 static void e1000_enable_unicast_promisc(e1000_t *e1000_data)
    704 {
    705         uint32_t rctl = E1000_REG_READ(e1000_data, E1000_RCTL);
     714 * @param e1000 E1000 data structure
     715 *
     716 */
     717static void e1000_enable_unicast_promisc(e1000_t *e1000)
     718{
     719        uint32_t rctl = E1000_REG_READ(e1000, E1000_RCTL);
    706720        rctl = rctl | RCTL_UPE;
    707         E1000_REG_WRITE(e1000_data, E1000_RCTL, rctl);
     721        E1000_REG_WRITE(e1000, E1000_RCTL, rctl);
    708722}
    709723
    710724/** Disable multicast promiscuous mode
    711725 *
    712  * @param e1000_data E1000 data structure
    713  *
    714  */
    715 static void e1000_disable_multicast_promisc(e1000_t *e1000_data)
    716 {
    717         uint32_t rctl = E1000_REG_READ(e1000_data, E1000_RCTL);
     726 * @param e1000 E1000 data structure
     727 *
     728 */
     729static void e1000_disable_multicast_promisc(e1000_t *e1000)
     730{
     731        uint32_t rctl = E1000_REG_READ(e1000, E1000_RCTL);
    718732        rctl = rctl & ~RCTL_MPE;
    719         E1000_REG_WRITE(e1000_data, E1000_RCTL, rctl);
     733        E1000_REG_WRITE(e1000, E1000_RCTL, rctl);
    720734}
    721735
    722736/** Enable multicast promiscuous mode
    723737 *
    724  * @param e1000_data E1000 data structure
    725  *
    726  */
    727 static void e1000_enable_multicast_promisc(e1000_t *e1000_data)
    728 {
    729         uint32_t rctl = E1000_REG_READ(e1000_data, E1000_RCTL);
     738 * @param e1000 E1000 data structure
     739 *
     740 */
     741static void e1000_enable_multicast_promisc(e1000_t *e1000)
     742{
     743        uint32_t rctl = E1000_REG_READ(e1000, E1000_RCTL);
    730744        rctl = rctl | RCTL_MPE;
    731         E1000_REG_WRITE(e1000_data, E1000_RCTL, rctl);
     745        E1000_REG_WRITE(e1000, E1000_RCTL, rctl);
    732746}
    733747
    734748/** Enable accepting of broadcast packets
    735749 *
    736  * @param e1000_data E1000 data structure
    737  *
    738  */
    739 static void e1000_enable_broadcast_accept(e1000_t *e1000_data)
    740 {
    741         uint32_t rctl = E1000_REG_READ(e1000_data, E1000_RCTL);
     750 * @param e1000 E1000 data structure
     751 *
     752 */
     753static void e1000_enable_broadcast_accept(e1000_t *e1000)
     754{
     755        uint32_t rctl = E1000_REG_READ(e1000, E1000_RCTL);
    742756        rctl = rctl | RCTL_BAM;
    743         E1000_REG_WRITE(e1000_data, E1000_RCTL, rctl);
     757        E1000_REG_WRITE(e1000, E1000_RCTL, rctl);
    744758}
    745759
    746760/** Disable accepting of broadcast packets
    747761 *
    748  * @param e1000_data E1000 data structure
    749  *
    750  */
    751 static void e1000_disable_broadcast_accept(e1000_t *e1000_data)
    752 {
    753         uint32_t rctl = E1000_REG_READ(e1000_data, E1000_RCTL);
     762 * @param e1000 E1000 data structure
     763 *
     764 */
     765static void e1000_disable_broadcast_accept(e1000_t *e1000)
     766{
     767        uint32_t rctl = E1000_REG_READ(e1000, E1000_RCTL);
    754768        rctl = rctl & ~RCTL_BAM;
    755         E1000_REG_WRITE(e1000_data, E1000_RCTL, rctl);
     769        E1000_REG_WRITE(e1000, E1000_RCTL, rctl);
    756770}
    757771
    758772/** Enable VLAN filtering according to VFTA registers
    759773 *
    760  * @param e1000_data E1000 data structure
    761  *
    762  */
    763 static void e1000_enable_vlan_filter(e1000_t *e1000_data)
    764 {
    765         uint32_t rctl = E1000_REG_READ(e1000_data, E1000_RCTL);
     774 * @param e1000 E1000 data structure
     775 *
     776 */
     777static void e1000_enable_vlan_filter(e1000_t *e1000)
     778{
     779        uint32_t rctl = E1000_REG_READ(e1000, E1000_RCTL);
    766780        rctl = rctl | RCTL_VFE;
    767         E1000_REG_WRITE(e1000_data, E1000_RCTL, rctl);
     781        E1000_REG_WRITE(e1000, E1000_RCTL, rctl);
    768782}
    769783
    770784/** Disable VLAN filtering
    771785 *
    772  * @param e1000_data E1000 data structure
    773  *
    774  */
    775 static void e1000_disable_vlan_filter(e1000_t *e1000_data)
    776 {
    777         uint32_t rctl = E1000_REG_READ(e1000_data, E1000_RCTL);
     786 * @param e1000 E1000 data structure
     787 *
     788 */
     789static void e1000_disable_vlan_filter(e1000_t *e1000)
     790{
     791        uint32_t rctl = E1000_REG_READ(e1000, E1000_RCTL);
    778792        rctl = rctl & ~RCTL_VFE;
    779         E1000_REG_WRITE(e1000_data, E1000_RCTL, rctl);
     793        E1000_REG_WRITE(e1000, E1000_RCTL, rctl);
    780794}
    781795
    782796/** Set multicast packets acceptance mode
    783797 *
    784  * @param nic_data NIC device to update
     798 * @param nic      NIC device to update
    785799 * @param mode     Mode to set
    786800 * @param addr     Address list (used in mode = NIC_MULTICAST_LIST)
     
    790804 *
    791805 */
    792 static int e1000_on_multicast_mode_change(nic_t *nic_data,
    793     nic_multicast_mode_t mode, const nic_address_t *addr, size_t addr_cnt)
    794 {
    795         e1000_t *e1000_data = DRIVER_DATA_NIC(nic_data);
     806static int e1000_on_multicast_mode_change(nic_t *nic, nic_multicast_mode_t mode,
     807    const nic_address_t *addr, size_t addr_cnt)
     808{
     809        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
    796810        int rc = EOK;
    797811       
    798         fibril_mutex_lock(&e1000_data->rx_lock);
     812        fibril_mutex_lock(&e1000->rx_lock);
    799813       
    800814        switch (mode) {
    801815        case NIC_MULTICAST_BLOCKED:
    802                 e1000_clear_multicast_receive_addresses(e1000_data);
    803                 e1000_disable_multicast_promisc(e1000_data);
    804                 nic_report_hw_filtering(nic_data, -1, 1, -1);
     816                e1000_clear_multicast_receive_addresses(e1000);
     817                e1000_disable_multicast_promisc(e1000);
     818                nic_report_hw_filtering(nic, -1, 1, -1);
    805819                break;
    806820        case NIC_MULTICAST_LIST:
    807                 e1000_clear_multicast_receive_addresses(e1000_data);
    808                 if (addr_cnt > get_free_multicast_address_count(e1000_data)) {
     821                e1000_clear_multicast_receive_addresses(e1000);
     822                if (addr_cnt > get_free_multicast_address_count(e1000)) {
    809823                        /*
    810824                         * Future work: fill MTA table
     
    812826                         * in the NIC library.
    813827                         */
    814                         e1000_enable_multicast_promisc(e1000_data);
    815                         nic_report_hw_filtering(nic_data, -1, 0, -1);
     828                        e1000_enable_multicast_promisc(e1000);
     829                        nic_report_hw_filtering(nic, -1, 0, -1);
    816830                } else {
    817                         e1000_disable_multicast_promisc(e1000_data);
    818                         e1000_add_multicast_receive_addresses(e1000_data, addr, addr_cnt);
    819                         nic_report_hw_filtering(nic_data, -1, 1, -1);
     831                        e1000_disable_multicast_promisc(e1000);
     832                        e1000_add_multicast_receive_addresses(e1000, addr, addr_cnt);
     833                        nic_report_hw_filtering(nic, -1, 1, -1);
    820834                }
    821835                break;
    822836        case NIC_MULTICAST_PROMISC:
    823                 e1000_enable_multicast_promisc(e1000_data);
    824                 e1000_clear_multicast_receive_addresses(e1000_data);
    825                 nic_report_hw_filtering(nic_data, -1, 1, -1);
     837                e1000_enable_multicast_promisc(e1000);
     838                e1000_clear_multicast_receive_addresses(e1000);
     839                nic_report_hw_filtering(nic, -1, 1, -1);
    826840                break;
    827841        default:
     
    830844        }
    831845       
    832         fibril_mutex_unlock(&e1000_data->rx_lock);
     846        fibril_mutex_unlock(&e1000->rx_lock);
    833847        return rc;
    834848}
     
    836850/** Set unicast packets acceptance mode
    837851 *
    838  * @param nic_data NIC device to update
     852 * @param nic      NIC device to update
    839853 * @param mode     Mode to set
    840854 * @param addr     Address list (used in mode = NIC_MULTICAST_LIST)
     
    844858 *
    845859 */
    846 static int e1000_on_unicast_mode_change(nic_t *nic_data,
    847     nic_unicast_mode_t mode, const nic_address_t *addr, size_t addr_cnt)
    848 {
    849         e1000_t *e1000_data = DRIVER_DATA_NIC(nic_data);
     860static int e1000_on_unicast_mode_change(nic_t *nic, nic_unicast_mode_t mode,
     861    const nic_address_t *addr, size_t addr_cnt)
     862{
     863        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
    850864        int rc = EOK;
    851865       
    852         fibril_mutex_lock(&e1000_data->rx_lock);
     866        fibril_mutex_lock(&e1000->rx_lock);
    853867       
    854868        switch (mode) {
    855869        case NIC_UNICAST_BLOCKED:
    856                 disable_ra0_address_filter(e1000_data);
    857                 e1000_clear_unicast_receive_addresses(e1000_data);
    858                 e1000_disable_unicast_promisc(e1000_data);
    859                 nic_report_hw_filtering(nic_data, 1, -1, -1);
     870                disable_ra0_address_filter(e1000);
     871                e1000_clear_unicast_receive_addresses(e1000);
     872                e1000_disable_unicast_promisc(e1000);
     873                nic_report_hw_filtering(nic, 1, -1, -1);
    860874                break;
    861875        case NIC_UNICAST_DEFAULT:
    862                 enable_ra0_address_filter(e1000_data);
    863                 e1000_clear_unicast_receive_addresses(e1000_data);
    864                 e1000_disable_unicast_promisc(e1000_data);
    865                 nic_report_hw_filtering(nic_data, 1, -1, -1);
     876                enable_ra0_address_filter(e1000);
     877                e1000_clear_unicast_receive_addresses(e1000);
     878                e1000_disable_unicast_promisc(e1000);
     879                nic_report_hw_filtering(nic, 1, -1, -1);
    866880                break;
    867881        case NIC_UNICAST_LIST:
    868                 enable_ra0_address_filter(e1000_data);
    869                 e1000_clear_unicast_receive_addresses(e1000_data);
    870                 if (addr_cnt > get_free_unicast_address_count(e1000_data)) {
    871                         e1000_enable_unicast_promisc(e1000_data);
    872                         nic_report_hw_filtering(nic_data, 0, -1, -1);
     882                enable_ra0_address_filter(e1000);
     883                e1000_clear_unicast_receive_addresses(e1000);
     884                if (addr_cnt > get_free_unicast_address_count(e1000)) {
     885                        e1000_enable_unicast_promisc(e1000);
     886                        nic_report_hw_filtering(nic, 0, -1, -1);
    873887                } else {
    874                         e1000_disable_unicast_promisc(e1000_data);
    875                         e1000_add_unicast_receive_addresses(e1000_data, addr, addr_cnt);
    876                         nic_report_hw_filtering(nic_data, 1, -1, -1);
     888                        e1000_disable_unicast_promisc(e1000);
     889                        e1000_add_unicast_receive_addresses(e1000, addr, addr_cnt);
     890                        nic_report_hw_filtering(nic, 1, -1, -1);
    877891                }
    878892                break;
    879893        case NIC_UNICAST_PROMISC:
    880                 e1000_enable_unicast_promisc(e1000_data);
    881                 enable_ra0_address_filter(e1000_data);
    882                 e1000_clear_unicast_receive_addresses(e1000_data);
    883                 nic_report_hw_filtering(nic_data, 1, -1, -1);
     894                e1000_enable_unicast_promisc(e1000);
     895                enable_ra0_address_filter(e1000);
     896                e1000_clear_unicast_receive_addresses(e1000);
     897                nic_report_hw_filtering(nic, 1, -1, -1);
    884898                break;
    885899        default:
     
    888902        }
    889903       
    890         fibril_mutex_unlock(&e1000_data->rx_lock);
     904        fibril_mutex_unlock(&e1000->rx_lock);
    891905        return rc;
    892906}
     
    894908/** Set broadcast packets acceptance mode
    895909 *
    896  * @param nic_data NIC device to update
    897  * @param mode     Mode to set
     910 * @param nic  NIC device to update
     911 * @param mode Mode to set
    898912 *
    899913 * @return EOK
    900914 *
    901915 */
    902 static int e1000_on_broadcast_mode_change(nic_t *nic_data,
    903     nic_broadcast_mode_t mode)
    904 {
    905         e1000_t *e1000_data = DRIVER_DATA_NIC(nic_data);
     916static int e1000_on_broadcast_mode_change(nic_t *nic, nic_broadcast_mode_t mode)
     917{
     918        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
    906919        int rc = EOK;
    907920       
    908         fibril_mutex_lock(&e1000_data->rx_lock);
     921        fibril_mutex_lock(&e1000->rx_lock);
    909922       
    910923        switch (mode) {
    911924        case NIC_BROADCAST_BLOCKED:
    912                 e1000_disable_broadcast_accept(e1000_data);
     925                e1000_disable_broadcast_accept(e1000);
    913926                break;
    914927        case NIC_BROADCAST_ACCEPTED:
    915                 e1000_enable_broadcast_accept(e1000_data);
     928                e1000_enable_broadcast_accept(e1000);
    916929                break;
    917930        default:
     
    920933        }
    921934       
    922         fibril_mutex_unlock(&e1000_data->rx_lock);
     935        fibril_mutex_unlock(&e1000->rx_lock);
    923936        return rc;
    924937}
     
    926939/** Check if receiving is enabled
    927940 *
    928  * @param e1000_data E1000 data structure
     941 * @param e1000 E1000 data structure
    929942 *
    930943 * @return true if receiving is enabled
    931944 *
    932945 */
    933 static bool e1000_is_rx_enabled(e1000_t *e1000_data)
    934 {
    935         if (E1000_REG_READ(e1000_data, E1000_RCTL) & (RCTL_EN))
     946static bool e1000_is_rx_enabled(e1000_t *e1000)
     947{
     948        if (E1000_REG_READ(e1000, E1000_RCTL) & (RCTL_EN))
    936949                return true;
    937950       
     
    941954/** Enable receiving
    942955 *
    943  * @param e1000_data E1000 data structure
    944  *
    945  */
    946 static void e1000_enable_rx(e1000_t *e1000_data)
     956 * @param e1000 E1000 data structure
     957 *
     958 */
     959static void e1000_enable_rx(e1000_t *e1000)
    947960{
    948961        /* Set Receive Enable Bit */
    949         E1000_REG_WRITE(e1000_data, E1000_RCTL,
    950             E1000_REG_READ(e1000_data, E1000_RCTL) | (RCTL_EN));
     962        E1000_REG_WRITE(e1000, E1000_RCTL,
     963            E1000_REG_READ(e1000, E1000_RCTL) | (RCTL_EN));
    951964}
    952965
    953966/** Disable receiving
    954967 *
    955  * @param e1000_data E1000 data structure
    956  *
    957  */
    958 static void e1000_disable_rx(e1000_t *e1000_data)
     968 * @param e1000 E1000 data structure
     969 *
     970 */
     971static void e1000_disable_rx(e1000_t *e1000)
    959972{
    960973        /* Clear Receive Enable Bit */
    961         E1000_REG_WRITE(e1000_data, E1000_RCTL,
    962             E1000_REG_READ(e1000_data, E1000_RCTL) & ~(RCTL_EN));
     974        E1000_REG_WRITE(e1000, E1000_RCTL,
     975            E1000_REG_READ(e1000, E1000_RCTL) & ~(RCTL_EN));
    963976}
    964977
    965978/** Set VLAN mask
    966979 *
    967  * @param nic_data  NIC device to update
     980 * @param nic       NIC device to update
    968981 * @param vlan_mask VLAN mask
    969982 *
    970983 */
    971 static void e1000_on_vlan_mask_change(nic_t *nic_data,
    972    const nic_vlan_mask_t *vlan_mask)
    973 {
    974         e1000_t *e1000_data = DRIVER_DATA_NIC(nic_data);
    975        
    976         fibril_mutex_lock(&e1000_data->rx_lock);
     984static void e1000_on_vlan_mask_change(nic_t *nic,
     985    const nic_vlan_mask_t *vlan_mask)
     986{
     987        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
     988       
     989        fibril_mutex_lock(&e1000->rx_lock);
    977990       
    978991        if (vlan_mask) {
     
    981994                 * partially written VLAN is not received.
    982995                 */
    983                 bool rx_enabled = e1000_is_rx_enabled(e1000_data);
     996                bool rx_enabled = e1000_is_rx_enabled(e1000);
    984997                if (rx_enabled)
    985                         e1000_disable_rx(e1000_data);
     998                        e1000_disable_rx(e1000);
    986999               
    9871000                for (unsigned int i = 0; i < NIC_VLAN_BITMAP_SIZE; i += 4) {
     
    9911004                            (((uint32_t) vlan_mask->bitmap[i + 2]) << 16) |
    9921005                            (((uint32_t) vlan_mask->bitmap[i + 3]) << 24);
    993                         E1000_REG_WRITE(e1000_data, E1000_VFTA_ARRAY(i / 4), bitmap_part);
     1006                        E1000_REG_WRITE(e1000, E1000_VFTA_ARRAY(i / 4), bitmap_part);
    9941007                }
    9951008               
    996                 e1000_enable_vlan_filter(e1000_data);
     1009                e1000_enable_vlan_filter(e1000);
    9971010                if (rx_enabled)
    998                         e1000_enable_rx(e1000_data);
     1011                        e1000_enable_rx(e1000);
    9991012        } else
    1000                 e1000_disable_vlan_filter(e1000_data);
    1001        
    1002         fibril_mutex_unlock(&e1000_data->rx_lock);
     1013                e1000_disable_vlan_filter(e1000);
     1014       
     1015        fibril_mutex_unlock(&e1000->rx_lock);
    10031016}
    10041017
     
    10261039                return ENOTSUP;
    10271040       
    1028         e1000_t *e1000_data = DRIVER_DATA_DEV(device);
    1029        
    1030         e1000_data->vlan_tag = tag;
    1031         e1000_data->vlan_tag_add = add;
    1032        
    1033         fibril_mutex_lock(&e1000_data->ctrl_lock);
    1034        
    1035         uint32_t ctrl = E1000_REG_READ(e1000_data, E1000_CTRL);
     1041        e1000_t *e1000 = DRIVER_DATA_DEV(device);
     1042       
     1043        e1000->vlan_tag = tag;
     1044        e1000->vlan_tag_add = add;
     1045       
     1046        fibril_mutex_lock(&e1000->ctrl_lock);
     1047       
     1048        uint32_t ctrl = E1000_REG_READ(e1000, E1000_CTRL);
    10361049        if (strip)
    10371050                ctrl |= CTRL_VME;
     
    10391052                ctrl &= ~CTRL_VME;
    10401053       
    1041         E1000_REG_WRITE(e1000_data, E1000_CTRL, ctrl);
    1042        
    1043         fibril_mutex_unlock(&e1000_data->ctrl_lock);
     1054        E1000_REG_WRITE(e1000, E1000_CTRL, ctrl);
     1055       
     1056        fibril_mutex_unlock(&e1000->ctrl_lock);
    10441057        return EOK;
    10451058}
     
    10471060/** Fill receive descriptor with new empty packet
    10481061 *
    1049  * Store packet in e1000_data->rx_ring_packets
    1050  *
    1051  * @param nic_data NIC data stricture
    1052  * @param offset   Receive descriptor offset
    1053  *
    1054  */
    1055 static void e1000_fill_new_rx_descriptor(nic_t *nic_data, unsigned int offset)
    1056 {
    1057         e1000_t *e1000_data = DRIVER_DATA_NIC(nic_data);
    1058         packet_t *packet = nic_alloc_packet(nic_data, E1000_MAX_RECEIVE_PACKET_SIZE);
     1062 * Store packet in e1000->rx_ring_packets
     1063 *
     1064 * @param nic    NIC data stricture
     1065 * @param offset Receive descriptor offset
     1066 *
     1067 */
     1068static void e1000_fill_new_rx_descriptor(nic_t *nic, size_t offset)
     1069{
     1070        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
     1071        packet_t *packet =
     1072            nic_alloc_packet(nic, E1000_MAX_RECEIVE_PACKET_SIZE);
    10591073       
    10601074        assert(packet);
    10611075       
    1062         *(e1000_data->rx_ring_packets + offset) = packet;
    1063         e1000_rx_descriptor_t * rx_descriptor = (e1000_rx_descriptor_t *)
    1064             (e1000_data->rx_ring.virt +
    1065             offset * sizeof(e1000_rx_descriptor_t));
    1066        
    1067         void *phys_addr = nic_dma_lock_packet(packet);
    1068        
    1069         if (phys_addr) {
    1070                 rx_descriptor->phys_addr =
    1071                     PTR_TO_U64(phys_addr + packet->data_start);
    1072         } else
     1076        *(e1000->rx_ring_packets + offset) = packet;
     1077        e1000_rx_descriptor_t *rx_descriptor = (e1000_rx_descriptor_t *)
     1078            (e1000->rx_ring_virt + offset * sizeof(e1000_rx_descriptor_t));
     1079       
     1080        void *phys;
     1081        int rc =
     1082            nic_dma_lock_packet(packet, E1000_MAX_RECEIVE_PACKET_SIZE, &phys);
     1083       
     1084        if (rc == EOK)
     1085                rx_descriptor->phys_addr = PTR_TO_U64(phys + packet->data_start);
     1086        else
    10731087                rx_descriptor->phys_addr = 0;
    10741088       
     
    10821096/** Clear receive descriptor
    10831097 *
    1084  * @param e1000_data E1000 data
    1085  * @param offset     Receive descriptor offset
    1086  *
    1087  */
    1088 static void e1000_clear_rx_descriptor(e1000_t *e1000_data, unsigned int offset)
     1098 * @param e1000  E1000 data
     1099 * @param offset Receive descriptor offset
     1100 *
     1101 */
     1102static void e1000_clear_rx_descriptor(e1000_t *e1000, unsigned int offset)
    10891103{
    10901104        e1000_rx_descriptor_t *rx_descriptor = (e1000_rx_descriptor_t *)
    1091             (e1000_data->rx_ring.virt +
    1092             offset * sizeof(e1000_rx_descriptor_t));
     1105            (e1000->rx_ring_virt + offset * sizeof(e1000_rx_descriptor_t));
    10931106       
    10941107        rx_descriptor->length = 0;
     
    11011114/** Clear receive descriptor
    11021115 *
    1103  * @param nic_data NIC data
    1104  * @param offset   Receive descriptor offset
    1105  *
    1106  */
    1107 static void e1000_clear_tx_descriptor(nic_t *nic_data, unsigned int offset)
    1108 {
    1109         e1000_t *e1000_data = DRIVER_DATA_NIC(nic_data);
    1110        
    1111         e1000_tx_descriptor_t * tx_descriptor = (e1000_tx_descriptor_t *)
    1112             (e1000_data->tx_ring.virt +
    1113             offset * sizeof(e1000_tx_descriptor_t));
     1116 * @param nic    NIC data
     1117 * @param offset Receive descriptor offset
     1118 *
     1119 */
     1120static void e1000_clear_tx_descriptor(nic_t *nic, unsigned int offset)
     1121{
     1122        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
     1123       
     1124        e1000_tx_descriptor_t *tx_descriptor = (e1000_tx_descriptor_t *)
     1125            (e1000->tx_ring_virt + offset * sizeof(e1000_tx_descriptor_t));
    11141126       
    11151127        if (tx_descriptor->length) {
    1116                 packet_t * old_packet = *(e1000_data->tx_ring_packets + offset);
     1128                packet_t *old_packet = *(e1000->tx_ring_packets + offset);
    11171129                if (old_packet)
    1118                         nic_release_packet(nic_data, old_packet);
     1130                        nic_release_packet(nic, old_packet);
    11191131        }
    11201132       
     
    11461158/** Receive packets
    11471159 *
    1148  * @param nic_data NIC data
    1149  *
    1150  */
    1151 static void e1000_receive_packets(nic_t *nic_data)
    1152 {
    1153         e1000_t *e1000_data = DRIVER_DATA_NIC(nic_data);
    1154        
    1155         fibril_mutex_lock(&e1000_data->rx_lock);
    1156        
    1157         uint32_t *tail_addr = E1000_REG_ADDR(e1000_data, E1000_RDT);
     1160 * @param nic NIC data
     1161 *
     1162 */
     1163static void e1000_receive_packets(nic_t *nic)
     1164{
     1165        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
     1166       
     1167        fibril_mutex_lock(&e1000->rx_lock);
     1168       
     1169        uint32_t *tail_addr = E1000_REG_ADDR(e1000, E1000_RDT);
    11581170        uint32_t next_tail = e1000_inc_tail(*tail_addr, E1000_RX_PACKETS_COUNT);
    11591171       
    11601172        e1000_rx_descriptor_t *rx_descriptor = (e1000_rx_descriptor_t *)
    1161             (e1000_data->rx_ring.virt +
    1162             next_tail * sizeof(e1000_rx_descriptor_t));
     1173            (e1000->rx_ring_virt + next_tail * sizeof(e1000_rx_descriptor_t));
    11631174       
    11641175        while (rx_descriptor->status & 0x01) {
    11651176                uint32_t packet_size = rx_descriptor->length - E1000_CRC_SIZE;
    11661177               
    1167                 packet_t *packet = *(e1000_data->rx_ring_packets + next_tail);
     1178                packet_t *packet = *(e1000->rx_ring_packets + next_tail);
    11681179                packet_suffix(packet, packet_size);
    11691180               
    1170                 nic_dma_unlock_packet(packet);
    1171                 nic_received_packet(nic_data, packet);
     1181                nic_dma_unlock_packet(packet, E1000_MAX_RECEIVE_PACKET_SIZE);
     1182                nic_received_packet(nic, packet);
    11721183               
    1173                 e1000_fill_new_rx_descriptor(nic_data, next_tail);
     1184                e1000_fill_new_rx_descriptor(nic, next_tail);
    11741185               
    11751186                *tail_addr = e1000_inc_tail(*tail_addr, E1000_RX_PACKETS_COUNT);
     
    11771188               
    11781189                rx_descriptor = (e1000_rx_descriptor_t *)
    1179                     (e1000_data->rx_ring.virt +
    1180                     next_tail * sizeof(e1000_rx_descriptor_t));
     1190                    (e1000->rx_ring_virt + next_tail * sizeof(e1000_rx_descriptor_t));
    11811191        }
    11821192       
    1183         fibril_mutex_unlock(&e1000_data->rx_lock);
     1193        fibril_mutex_unlock(&e1000->rx_lock);
    11841194}
    11851195
    11861196/** Enable E1000 interupts
    11871197 *
    1188  * @param e1000_data E1000 data structure
    1189  *
    1190  */
    1191 static void e1000_enable_interrupts(e1000_t *e1000_data)
    1192 {
    1193         E1000_REG_WRITE(e1000_data, E1000_IMS, ICR_RXT0);
     1198 * @param e1000 E1000 data structure
     1199 *
     1200 */
     1201static void e1000_enable_interrupts(e1000_t *e1000)
     1202{
     1203        E1000_REG_WRITE(e1000, E1000_IMS, ICR_RXT0);
    11941204}
    11951205
    11961206/** Disable E1000 interupts
    11971207 *
    1198  * @param e1000_data E1000 data structure
    1199  *
    1200  */
    1201 static void e1000_disable_interrupts(e1000_t *e1000_data)
    1202 {
    1203         E1000_REG_WRITE(e1000_data, E1000_IMS, 0);
     1208 * @param e1000 E1000 data structure
     1209 *
     1210 */
     1211static void e1000_disable_interrupts(e1000_t *e1000)
     1212{
     1213        E1000_REG_WRITE(e1000, E1000_IMS, 0);
    12041214}
    12051215
     
    12091219 * and e1000_poll()
    12101220 *
    1211  * @param nic_data NIC data
    1212  * @param icr      ICR register value
    1213  *
    1214  */
    1215 static void e1000_interrupt_handler_impl(nic_t *nic_data, uint32_t icr)
     1221 * @param nic NIC data
     1222 * @param icr ICR register value
     1223 *
     1224 */
     1225static void e1000_interrupt_handler_impl(nic_t *nic, uint32_t icr)
    12161226{
    12171227        if (icr & ICR_RXT0)
    1218                 e1000_receive_packets(nic_data);
     1228                e1000_receive_packets(nic);
    12191229}
    12201230
     
    12301240{
    12311241        uint32_t icr = (uint32_t) IPC_GET_ARG2(*icall);
    1232         nic_t *nic_data = NIC_DATA_DEV(dev);
    1233         e1000_t *e1000_data = DRIVER_DATA_NIC(nic_data);
    1234        
    1235         e1000_interrupt_handler_impl(nic_data, icr);
    1236         e1000_enable_interrupts(e1000_data);
     1242        nic_t *nic = NIC_DATA_DEV(dev);
     1243        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
     1244       
     1245        e1000_interrupt_handler_impl(nic, icr);
     1246        e1000_enable_interrupts(e1000);
    12371247}
    12381248
     
    12421252 * structure.
    12431253 *
    1244  * @param nic_data Driver data
     1254 * @param nic Driver data
    12451255 *
    12461256 * @return EOK if the handler was registered
     
    12481258 *
    12491259 */
    1250 inline static int e1000_register_int_handler(nic_t *nic_data)
    1251 {
    1252         e1000_t *e1000_data = DRIVER_DATA_NIC(nic_data);
     1260inline static int e1000_register_int_handler(nic_t *nic)
     1261{
     1262        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
    12531263       
    12541264        /* Lock the mutex in whole driver while working with global structure */
    12551265        fibril_mutex_lock(&irq_reg_mutex);
    12561266       
    1257         // FIXME: This is not supported in mainline
    1258         e1000_irq_code.cmds[0].addr =
    1259             0xffff800000000000 + e1000_data->phys_reg_base + E1000_ICR;
    1260         e1000_irq_code.cmds[2].addr =
    1261             0xffff800000000000 + e1000_data->phys_reg_base + E1000_IMC;
    1262        
    1263         int rc = register_interrupt_handler(nic_get_ddf_dev(nic_data),
    1264             e1000_data->irq, e1000_interrupt_handler, &e1000_irq_code);
     1267        e1000_irq_code.cmds[0].addr = e1000->reg_base_virt + E1000_ICR;
     1268        e1000_irq_code.cmds[2].addr = e1000->reg_base_virt + E1000_IMC;
     1269       
     1270        int rc = register_interrupt_handler(nic_get_ddf_dev(nic),
     1271            e1000->irq, e1000_interrupt_handler, &e1000_irq_code);
    12651272       
    12661273        fibril_mutex_unlock(&irq_reg_mutex);
     
    12701277/** Force receiving all packets in the receive buffer
    12711278 *
    1272  * @param nic_data NIC data
    1273  *
    1274  */
    1275 static void e1000_poll(nic_t *nic_data)
    1276 {
    1277         assert(nic_data);
    1278        
    1279         e1000_t *e1000_data = nic_get_specific(nic_data);
    1280         assert(e1000_data);
    1281        
    1282         uint32_t icr = E1000_REG_READ(e1000_data, E1000_ICR);
    1283         e1000_interrupt_handler_impl(nic_data, icr);
     1279 * @param nic NIC data
     1280 *
     1281 */
     1282static void e1000_poll(nic_t *nic)
     1283{
     1284        assert(nic);
     1285       
     1286        e1000_t *e1000 = nic_get_specific(nic);
     1287        assert(e1000);
     1288       
     1289        uint32_t icr = E1000_REG_READ(e1000, E1000_ICR);
     1290        e1000_interrupt_handler_impl(nic, icr);
    12841291}
    12851292
     
    13051312 *
    13061313 */
    1307 static int e1000_poll_mode_change(nic_t *nic_data, nic_poll_mode_t mode,
     1314static int e1000_poll_mode_change(nic_t *nic, nic_poll_mode_t mode,
    13081315    const struct timeval *period)
    13091316{
    1310         assert(nic_data);
    1311        
    1312         e1000_t *e1000_data = nic_get_specific(nic_data);
    1313         assert(e1000_data);
     1317        assert(nic);
     1318       
     1319        e1000_t *e1000 = nic_get_specific(nic);
     1320        assert(e1000);
    13141321       
    13151322        switch (mode) {
    13161323        case NIC_POLL_IMMEDIATE:
    1317                 E1000_REG_WRITE(e1000_data, E1000_ITR, 0);
    1318                 e1000_enable_interrupts(e1000_data);
     1324                E1000_REG_WRITE(e1000, E1000_ITR, 0);
     1325                e1000_enable_interrupts(e1000);
    13191326                break;
    13201327        case NIC_POLL_ON_DEMAND:
    1321                 e1000_disable_interrupts(e1000_data);
     1328                e1000_disable_interrupts(e1000);
    13221329                break;
    13231330        case NIC_POLL_PERIODIC:
    13241331                assert(period);
    13251332                uint16_t itr_interval = e1000_calculate_itr_interval(period);
    1326                 E1000_REG_WRITE(e1000_data, E1000_ITR, (uint32_t) itr_interval);
    1327                 e1000_enable_interrupts(e1000_data);
     1333                E1000_REG_WRITE(e1000, E1000_ITR, (uint32_t) itr_interval);
     1334                e1000_enable_interrupts(e1000);
    13281335                break;
    13291336        default:
     
    13361343/** Initialize receive registers
    13371344 *
    1338  * @param e1000_data E1000 data structure
    1339  *
    1340  */
    1341 static void e1000_initialize_rx_registers(e1000_t * e1000_data)
    1342 {
    1343         E1000_REG_WRITE(e1000_data, E1000_RDLEN, E1000_RX_PACKETS_COUNT * 16);
    1344         E1000_REG_WRITE(e1000_data, E1000_RDH, 0);
     1345 * @param e1000 E1000 data structure
     1346 *
     1347 */
     1348static void e1000_initialize_rx_registers(e1000_t *e1000)
     1349{
     1350        E1000_REG_WRITE(e1000, E1000_RDLEN, E1000_RX_PACKETS_COUNT * 16);
     1351        E1000_REG_WRITE(e1000, E1000_RDH, 0);
    13451352       
    13461353        /* It is not posible to let HW use all descriptors */
    1347         E1000_REG_WRITE(e1000_data, E1000_RDT, E1000_RX_PACKETS_COUNT - 1);
     1354        E1000_REG_WRITE(e1000, E1000_RDT, E1000_RX_PACKETS_COUNT - 1);
    13481355       
    13491356        /* Set Broadcast Enable Bit */
    1350         E1000_REG_WRITE(e1000_data, E1000_RCTL, RCTL_BAM);
     1357        E1000_REG_WRITE(e1000, E1000_RCTL, RCTL_BAM);
    13511358}
    13521359
    13531360/** Initialize receive structure
    13541361 *
    1355  * @param nic_data NIC data
     1362 * @param nic NIC data
    13561363 *
    13571364 * @return EOK if succeed
     
    13591366 *
    13601367 */
    1361 static int e1000_initialize_rx_structure(nic_t *nic_data)
    1362 {
    1363         e1000_t *e1000_data = DRIVER_DATA_NIC(nic_data);
    1364         fibril_mutex_lock(&e1000_data->rx_lock);
    1365        
    1366         int rc = dmamem_map(&e1000_data->rx_ring,
    1367             SIZE2PAGES(E1000_RX_PACKETS_COUNT * sizeof(e1000_rx_descriptor_t)),
    1368             AS_AREA_READ | AS_AREA_WRITE, 0);
     1368static int e1000_initialize_rx_structure(nic_t *nic)
     1369{
     1370        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
     1371        fibril_mutex_lock(&e1000->rx_lock);
     1372       
     1373        int rc = dmamem_map_anonymous(
     1374            E1000_RX_PACKETS_COUNT * sizeof(e1000_rx_descriptor_t),
     1375            AS_AREA_READ | AS_AREA_WRITE, 0, &e1000->rx_ring_phys,
     1376            &e1000->rx_ring_virt);
    13691377        if (rc != EOK)
    13701378                return rc;
    13711379       
    1372         E1000_REG_WRITE(e1000_data, E1000_RDBAH,
    1373             (uint32_t) (PTR_TO_U64(e1000_data->rx_ring.phys) >> 32));
    1374         E1000_REG_WRITE(e1000_data, E1000_RDBAL,
    1375             (uint32_t) PTR_TO_U64(e1000_data->rx_ring.phys));
    1376        
    1377         e1000_data->rx_ring_packets =
     1380        E1000_REG_WRITE(e1000, E1000_RDBAH,
     1381            (uint32_t) (PTR_TO_U64(e1000->rx_ring_phys) >> 32));
     1382        E1000_REG_WRITE(e1000, E1000_RDBAL,
     1383            (uint32_t) PTR_TO_U64(e1000->rx_ring_phys));
     1384       
     1385        e1000->rx_ring_packets =
    13781386            malloc(E1000_RX_PACKETS_COUNT * sizeof(packet_t *));
    13791387        // FIXME: Check return value
     
    13831391            offset < E1000_RX_PACKETS_COUNT;
    13841392            offset++)
    1385                 e1000_fill_new_rx_descriptor(nic_data, offset);
    1386        
    1387         e1000_initialize_rx_registers(e1000_data);
    1388        
    1389         fibril_mutex_unlock(&e1000_data->rx_lock);
     1393                e1000_fill_new_rx_descriptor(nic, offset);
     1394       
     1395        e1000_initialize_rx_registers(e1000);
     1396       
     1397        fibril_mutex_unlock(&e1000->rx_lock);
    13901398        return EOK;
    13911399}
     
    13931401/** Uninitialize receive structure
    13941402 *
    1395  * @param nic_data NIC data
    1396  *
    1397  */
    1398 static void e1000_uninitialize_rx_structure(nic_t *nic_data)
    1399 {
    1400         e1000_t *e1000_data = DRIVER_DATA_NIC(nic_data);
     1403 * @param nic NIC data
     1404 *
     1405 */
     1406static void e1000_uninitialize_rx_structure(nic_t *nic)
     1407{
     1408        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
    14011409       
    14021410        /* Write descriptor */
     
    14041412            offset < E1000_RX_PACKETS_COUNT;
    14051413            offset++) {
    1406                 packet_t *packet = *(e1000_data->rx_ring_packets + offset);
    1407                 nic_dma_unlock_packet(packet);
    1408                 nic_release_packet(nic_data, packet);
     1414                packet_t *packet = *(e1000->rx_ring_packets + offset);
     1415                nic_dma_unlock_packet(packet, E1000_MAX_RECEIVE_PACKET_SIZE);
     1416                nic_release_packet(nic, packet);
    14091417        }
    14101418       
    1411         free(e1000_data->rx_ring_packets);
    1412         dmamem_unmap(&e1000_data->rx_ring);
     1419        free(e1000->rx_ring_packets);
     1420        dmamem_unmap_anonymous(e1000->rx_ring_virt);
    14131421}
    14141422
    14151423/** Clear receive descriptor ring
    14161424 *
    1417  * @param e1000_data E1000 data
    1418  *
    1419  */
    1420 static void e1000_clear_rx_ring(e1000_t * e1000_data)
     1425 * @param e1000 E1000 data
     1426 *
     1427 */
     1428static void e1000_clear_rx_ring(e1000_t *e1000)
    14211429{
    14221430        /* Write descriptor */
     
    14241432            offset < E1000_RX_PACKETS_COUNT;
    14251433            offset++)
    1426                 e1000_clear_rx_descriptor(e1000_data, offset);
     1434                e1000_clear_rx_descriptor(e1000, offset);
    14271435}
    14281436
    14291437/** Initialize filters
    14301438 *
    1431  * @param e1000_data E1000 data
    1432  *
    1433  */
    1434 static void e1000_initialize_filters(e1000_t *e1000_data)
     1439 * @param e1000 E1000 data
     1440 *
     1441 */
     1442static void e1000_initialize_filters(e1000_t *e1000)
    14351443{
    14361444        /* Initialize address filter */
    1437         e1000_data->unicast_ra_count = 0;
    1438         e1000_data->multicast_ra_count = 0;
    1439         e1000_clear_unicast_receive_addresses(e1000_data);
     1445        e1000->unicast_ra_count = 0;
     1446        e1000->multicast_ra_count = 0;
     1447        e1000_clear_unicast_receive_addresses(e1000);
    14401448}
    14411449
    14421450/** Initialize VLAN
    14431451 *
    1444  * @param e1000_data E1000 data
    1445  *
    1446  */
    1447 static void e1000_initialize_vlan(e1000_t *e1000_data)
    1448 {
    1449         e1000_data->vlan_tag_add = false;
     1452 * @param e1000 E1000 data
     1453 *
     1454 */
     1455static void e1000_initialize_vlan(e1000_t *e1000)
     1456{
     1457        e1000->vlan_tag_add = false;
    14501458}
    14511459
    14521460/** Fill MAC address from EEPROM to RA[0] register
    14531461 *
    1454  * @param e1000_data E1000 data
    1455  *
    1456  */
    1457 static void e1000_fill_mac_from_eeprom(e1000_t *e1000_data)
     1462 * @param e1000 E1000 data
     1463 *
     1464 */
     1465static void e1000_fill_mac_from_eeprom(e1000_t *e1000)
    14581466{
    14591467        /* MAC address from eeprom to RA[0] */
    14601468        nic_address_t address;
    1461         e1000_eeprom_get_address(e1000_data, &address);
    1462         e1000_write_receive_address(e1000_data, 0, &address, true);
     1469        e1000_eeprom_get_address(e1000, &address);
     1470        e1000_write_receive_address(e1000, 0, &address, true);
    14631471}
    14641472
     
    14711479 *
    14721480 */
    1473 static void e1000_initialize_registers(e1000_t *e1000_data)
    1474 {
    1475         E1000_REG_WRITE(e1000_data, E1000_ITR,
     1481static void e1000_initialize_registers(e1000_t *e1000)
     1482{
     1483        E1000_REG_WRITE(e1000, E1000_ITR,
    14761484            e1000_calculate_itr_interval_from_usecs(
    14771485            E1000_DEFAULT_INTERRUPT_INTERVAL_USEC));
    1478         E1000_REG_WRITE(e1000_data, E1000_FCAH, 0);
    1479         E1000_REG_WRITE(e1000_data, E1000_FCAL, 0);
    1480         E1000_REG_WRITE(e1000_data, E1000_FCT, 0);
    1481         E1000_REG_WRITE(e1000_data, E1000_FCTTV, 0);
    1482         E1000_REG_WRITE(e1000_data, E1000_VET, VET_VALUE);
    1483         E1000_REG_WRITE(e1000_data, E1000_CTRL, CTRL_ASDE);
     1486        E1000_REG_WRITE(e1000, E1000_FCAH, 0);
     1487        E1000_REG_WRITE(e1000, E1000_FCAL, 0);
     1488        E1000_REG_WRITE(e1000, E1000_FCT, 0);
     1489        E1000_REG_WRITE(e1000, E1000_FCTTV, 0);
     1490        E1000_REG_WRITE(e1000, E1000_VET, VET_VALUE);
     1491        E1000_REG_WRITE(e1000, E1000_CTRL, CTRL_ASDE);
    14841492}
    14851493
    14861494/** Initialize transmit registers
    14871495 *
    1488  * @param e1000_data E1000 data.
    1489  *
    1490  */
    1491 static void e1000_initialize_tx_registers(e1000_t *e1000_data)
    1492 {
    1493         E1000_REG_WRITE(e1000_data, E1000_TDLEN, E1000_TX_PACKETS_COUNT * 16);
    1494         E1000_REG_WRITE(e1000_data, E1000_TDH, 0);
    1495         E1000_REG_WRITE(e1000_data, E1000_TDT, 0);
    1496        
    1497         E1000_REG_WRITE(e1000_data, E1000_TIPG,
     1496 * @param e1000 E1000 data.
     1497 *
     1498 */
     1499static void e1000_initialize_tx_registers(e1000_t *e1000)
     1500{
     1501        E1000_REG_WRITE(e1000, E1000_TDLEN, E1000_TX_PACKETS_COUNT * 16);
     1502        E1000_REG_WRITE(e1000, E1000_TDH, 0);
     1503        E1000_REG_WRITE(e1000, E1000_TDT, 0);
     1504       
     1505        E1000_REG_WRITE(e1000, E1000_TIPG,
    14981506            10 << TIPG_IPGT_SHIFT |
    14991507            8 << TIPG_IPGR1_SHIFT |
    15001508            6 << TIPG_IPGR2_SHIFT);
    15011509       
    1502         E1000_REG_WRITE(e1000_data, E1000_TCTL,
     1510        E1000_REG_WRITE(e1000, E1000_TCTL,
    15031511            0x0F << TCTL_CT_SHIFT /* Collision Threshold */ |
    15041512            0x40 << TCTL_COLD_SHIFT /* Collision Distance */ |
     
    15081516/** Initialize transmit structure
    15091517 *
    1510  * @param e1000_data E1000 data.
    1511  *
    1512  */
    1513 static int e1000_initialize_tx_structure(e1000_t *e1000_data)
    1514 {
    1515         fibril_mutex_lock(&e1000_data->tx_lock);
    1516        
    1517         int rc = dmamem_map(&e1000_data->tx_ring,
    1518             SIZE2PAGES(E1000_TX_PACKETS_COUNT * sizeof(e1000_tx_descriptor_t)),
    1519             AS_AREA_READ | AS_AREA_WRITE, 0);
     1518 * @param e1000 E1000 data.
     1519 *
     1520 */
     1521static int e1000_initialize_tx_structure(e1000_t *e1000)
     1522{
     1523        fibril_mutex_lock(&e1000->tx_lock);
     1524       
     1525        int rc = dmamem_map_anonymous(
     1526            E1000_TX_PACKETS_COUNT * sizeof(e1000_tx_descriptor_t),
     1527            AS_AREA_READ | AS_AREA_WRITE, 0, &e1000->tx_ring_phys,
     1528            &e1000->tx_ring_virt);
    15201529        if (rc != EOK)
    15211530                return rc;
    15221531       
    1523         bzero(e1000_data->tx_ring.virt,
     1532        bzero(e1000->tx_ring_virt,
    15241533            E1000_TX_PACKETS_COUNT * sizeof(e1000_tx_descriptor_t));
    15251534       
    1526         E1000_REG_WRITE(e1000_data, E1000_TDBAH,
    1527             (uint32_t) (PTR_TO_U64(e1000_data->tx_ring.phys) >> 32));
    1528         E1000_REG_WRITE(e1000_data, E1000_TDBAL,
    1529             (uint32_t) PTR_TO_U64(e1000_data->tx_ring.phys));
    1530        
    1531         e1000_data->tx_ring_packets =
     1535        E1000_REG_WRITE(e1000, E1000_TDBAH,
     1536            (uint32_t) (PTR_TO_U64(e1000->tx_ring_phys) >> 32));
     1537        E1000_REG_WRITE(e1000, E1000_TDBAL,
     1538            (uint32_t) PTR_TO_U64(e1000->tx_ring_phys));
     1539       
     1540        e1000->tx_ring_packets =
    15321541            malloc(E1000_TX_PACKETS_COUNT * sizeof(packet_t *));
    15331542        // FIXME: Check return value
    15341543       
    1535         e1000_initialize_tx_registers(e1000_data);
    1536        
    1537         fibril_mutex_unlock(&e1000_data->tx_lock);
     1544        e1000_initialize_tx_registers(e1000);
     1545       
     1546        fibril_mutex_unlock(&e1000->tx_lock);
    15381547        return EOK;
    15391548}
     
    15411550/** Uninitialize transmit structure
    15421551 *
    1543  * @param nic_data NIC data
    1544  *
    1545  */
    1546 static void e1000_uninitialize_tx_structure(e1000_t *e1000_data)
    1547 {
    1548         free(e1000_data->tx_ring_packets);
    1549         dmamem_unmap(&e1000_data->tx_ring);
     1552 * @param nic NIC data
     1553 *
     1554 */
     1555static void e1000_uninitialize_tx_structure(e1000_t *e1000)
     1556{
     1557        free(e1000->tx_ring_packets);
     1558        dmamem_unmap_anonymous(e1000->tx_ring_virt);
    15501559}
    15511560
    15521561/** Clear transmit descriptor ring
    15531562 *
    1554  * @param nic_data NIC data
    1555  *
    1556  */
    1557 static void e1000_clear_tx_ring(nic_t *nic_data)
     1563 * @param nic NIC data
     1564 *
     1565 */
     1566static void e1000_clear_tx_ring(nic_t *nic)
    15581567{
    15591568        /* Write descriptor */
     
    15611570            offset < E1000_TX_PACKETS_COUNT;
    15621571            offset++)
    1563                 e1000_clear_tx_descriptor(nic_data, offset);
     1572                e1000_clear_tx_descriptor(nic, offset);
    15641573}
    15651574
    15661575/** Enable transmit
    15671576 *
    1568  * @param e1000_data E1000 data
    1569  *
    1570  */
    1571 static void e1000_enable_tx(e1000_t *e1000_data)
     1577 * @param e1000 E1000 data
     1578 *
     1579 */
     1580static void e1000_enable_tx(e1000_t *e1000)
    15721581{
    15731582        /* Set Transmit Enable Bit */
    1574         E1000_REG_WRITE(e1000_data, E1000_TCTL,
    1575             E1000_REG_READ(e1000_data, E1000_TCTL) | (TCTL_EN));
     1583        E1000_REG_WRITE(e1000, E1000_TCTL,
     1584            E1000_REG_READ(e1000, E1000_TCTL) | (TCTL_EN));
    15761585}
    15771586
    15781587/** Disable transmit
    15791588 *
    1580  * @param e1000_data E1000 data
    1581  *
    1582  */
    1583 static void e1000_disable_tx(e1000_t *e1000_data)
     1589 * @param e1000 E1000 data
     1590 *
     1591 */
     1592static void e1000_disable_tx(e1000_t *e1000)
    15841593{
    15851594        /* Clear Transmit Enable Bit */
    1586         E1000_REG_WRITE(e1000_data, E1000_TCTL,
    1587             E1000_REG_READ(e1000_data, E1000_TCTL) & ~(TCTL_EN));
     1595        E1000_REG_WRITE(e1000, E1000_TCTL,
     1596            E1000_REG_READ(e1000, E1000_TCTL) & ~(TCTL_EN));
    15881597}
    15891598
    15901599/** Reset E1000 device
    15911600 *
    1592  * @param e1000_data The E1000 data
    1593  *
    1594  */
    1595 static int e1000_reset(nic_t *nic_data)
    1596 {
    1597         e1000_t *e1000_data = DRIVER_DATA_NIC(nic_data);
    1598        
    1599         E1000_REG_WRITE(e1000_data, E1000_CTRL, CTRL_RST);
     1601 * @param e1000 The E1000 data
     1602 *
     1603 */
     1604static int e1000_reset(nic_t *nic)
     1605{
     1606        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
     1607       
     1608        E1000_REG_WRITE(e1000, E1000_CTRL, CTRL_RST);
    16001609       
    16011610        /* Wait for the reset */
     
    16031612       
    16041613        /* check if RST_BIT cleared */
    1605         if (E1000_REG_READ(e1000_data, E1000_CTRL) & (CTRL_RST))
     1614        if (E1000_REG_READ(e1000, E1000_CTRL) & (CTRL_RST))
    16061615                return EINVAL;
    16071616       
    1608         e1000_initialize_registers(e1000_data);
    1609         e1000_initialize_rx_registers(e1000_data);
    1610         e1000_initialize_tx_registers(e1000_data);
    1611         e1000_fill_mac_from_eeprom(e1000_data);
    1612         e1000_initialize_filters(e1000_data);
    1613         e1000_initialize_vlan(e1000_data);
     1617        e1000_initialize_registers(e1000);
     1618        e1000_initialize_rx_registers(e1000);
     1619        e1000_initialize_tx_registers(e1000);
     1620        e1000_fill_mac_from_eeprom(e1000);
     1621        e1000_initialize_filters(e1000);
     1622        e1000_initialize_vlan(e1000);
    16141623       
    16151624        return EOK;
     
    16181627/** Activate the device to receive and transmit packets
    16191628 *
    1620  * @param nic_data NIC driver data
     1629 * @param nic NIC driver data
    16211630 *
    16221631 * @return EOK if activated successfully
     
    16241633 *
    16251634 */
    1626 static int e1000_on_activating(nic_t *nic_data)
    1627 {
    1628         assert(nic_data);
    1629        
    1630         e1000_t *e1000_data = DRIVER_DATA_NIC(nic_data);
    1631        
    1632         fibril_mutex_lock(&e1000_data->rx_lock);
    1633         fibril_mutex_lock(&e1000_data->tx_lock);
    1634         fibril_mutex_lock(&e1000_data->ctrl_lock);
    1635        
    1636         e1000_enable_interrupts(e1000_data);
    1637        
    1638         nic_enable_interrupt(nic_data, e1000_data->irq);
    1639        
    1640         e1000_clear_rx_ring(e1000_data);
    1641         e1000_enable_rx(e1000_data);
    1642        
    1643         e1000_clear_tx_ring(nic_data);
    1644         e1000_enable_tx(e1000_data);
    1645        
    1646         uint32_t ctrl = E1000_REG_READ(e1000_data, E1000_CTRL);
     1635static int e1000_on_activating(nic_t *nic)
     1636{
     1637        assert(nic);
     1638       
     1639        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
     1640       
     1641        fibril_mutex_lock(&e1000->rx_lock);
     1642        fibril_mutex_lock(&e1000->tx_lock);
     1643        fibril_mutex_lock(&e1000->ctrl_lock);
     1644       
     1645        e1000_enable_interrupts(e1000);
     1646       
     1647        nic_enable_interrupt(nic, e1000->irq);
     1648       
     1649        e1000_clear_rx_ring(e1000);
     1650        e1000_enable_rx(e1000);
     1651       
     1652        e1000_clear_tx_ring(nic);
     1653        e1000_enable_tx(e1000);
     1654       
     1655        uint32_t ctrl = E1000_REG_READ(e1000, E1000_CTRL);
    16471656        ctrl |= CTRL_SLU;
    1648         E1000_REG_WRITE(e1000_data, E1000_CTRL, ctrl);
    1649        
    1650         fibril_mutex_unlock(&e1000_data->ctrl_lock);
    1651         fibril_mutex_unlock(&e1000_data->tx_lock);
    1652         fibril_mutex_unlock(&e1000_data->rx_lock);
     1657        E1000_REG_WRITE(e1000, E1000_CTRL, ctrl);
     1658       
     1659        fibril_mutex_unlock(&e1000->ctrl_lock);
     1660        fibril_mutex_unlock(&e1000->tx_lock);
     1661        fibril_mutex_unlock(&e1000->rx_lock);
    16531662       
    16541663        return EOK;
     
    16571666/** Callback for NIC_STATE_DOWN change
    16581667 *
    1659  * @param nic_data NIC driver data
     1668 * @param nic NIC driver data
    16601669 *
    16611670 * @return EOK if succeed
     
    16631672 *
    16641673 */
    1665 static int e1000_on_down_unlocked(nic_t *nic_data)
    1666 {
    1667         e1000_t *e1000_data = DRIVER_DATA_NIC(nic_data);
    1668        
    1669         uint32_t ctrl = E1000_REG_READ(e1000_data, E1000_CTRL);
     1674static int e1000_on_down_unlocked(nic_t *nic)
     1675{
     1676        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
     1677       
     1678        uint32_t ctrl = E1000_REG_READ(e1000, E1000_CTRL);
    16701679        ctrl &= ~CTRL_SLU;
    1671         E1000_REG_WRITE(e1000_data, E1000_CTRL, ctrl);
    1672        
    1673         e1000_disable_tx(e1000_data);
    1674         e1000_disable_rx(e1000_data);
    1675        
    1676         nic_disable_interrupt(nic_data, e1000_data->irq);
    1677         e1000_disable_interrupts(e1000_data);
     1680        E1000_REG_WRITE(e1000, E1000_CTRL, ctrl);
     1681       
     1682        e1000_disable_tx(e1000);
     1683        e1000_disable_rx(e1000);
     1684       
     1685        nic_disable_interrupt(nic, e1000->irq);
     1686        e1000_disable_interrupts(e1000);
    16781687       
    16791688        /*
     
    16881697/** Callback for NIC_STATE_DOWN change
    16891698 *
    1690  * @param nic_data NIC driver data
     1699 * @param nic NIC driver data
    16911700 *
    16921701 * @return EOK if succeed
     
    16941703 *
    16951704 */
    1696 static int e1000_on_down(nic_t *nic_data)
    1697 {
    1698         e1000_t *e1000_data = DRIVER_DATA_NIC(nic_data);
    1699        
    1700         fibril_mutex_lock(&e1000_data->rx_lock);
    1701         fibril_mutex_lock(&e1000_data->tx_lock);
    1702         fibril_mutex_lock(&e1000_data->ctrl_lock);
    1703        
    1704         int rc = e1000_on_down_unlocked(nic_data);
    1705        
    1706         fibril_mutex_unlock(&e1000_data->ctrl_lock);
    1707         fibril_mutex_unlock(&e1000_data->tx_lock);
    1708         fibril_mutex_unlock(&e1000_data->rx_lock);
     1705static int e1000_on_down(nic_t *nic)
     1706{
     1707        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
     1708       
     1709        fibril_mutex_lock(&e1000->rx_lock);
     1710        fibril_mutex_lock(&e1000->tx_lock);
     1711        fibril_mutex_lock(&e1000->ctrl_lock);
     1712       
     1713        int rc = e1000_on_down_unlocked(nic);
     1714       
     1715        fibril_mutex_unlock(&e1000->ctrl_lock);
     1716        fibril_mutex_unlock(&e1000->tx_lock);
     1717        fibril_mutex_unlock(&e1000->rx_lock);
    17091718       
    17101719        return rc;
     
    17131722/** Callback for NIC_STATE_STOPPED change
    17141723 *
    1715  * @param nic_data NIC driver data
     1724 * @param nic NIC driver data
    17161725 *
    17171726 * @return EOK if succeed
     
    17191728 *
    17201729 */
    1721 static int e1000_on_stopping(nic_t *nic_data)
    1722 {
    1723         e1000_t *e1000_data = DRIVER_DATA_NIC(nic_data);
    1724        
    1725         fibril_mutex_lock(&e1000_data->rx_lock);
    1726         fibril_mutex_lock(&e1000_data->tx_lock);
    1727         fibril_mutex_lock(&e1000_data->ctrl_lock);
    1728        
    1729         int rc = e1000_on_down_unlocked(nic_data);
     1730static int e1000_on_stopping(nic_t *nic)
     1731{
     1732        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
     1733       
     1734        fibril_mutex_lock(&e1000->rx_lock);
     1735        fibril_mutex_lock(&e1000->tx_lock);
     1736        fibril_mutex_lock(&e1000->ctrl_lock);
     1737       
     1738        int rc = e1000_on_down_unlocked(nic);
    17301739        if (rc == EOK)
    1731                 rc = e1000_reset(nic_data);
    1732        
    1733         fibril_mutex_unlock(&e1000_data->ctrl_lock);
    1734         fibril_mutex_unlock(&e1000_data->tx_lock);
    1735         fibril_mutex_unlock(&e1000_data->rx_lock);
     1740                rc = e1000_reset(nic);
     1741       
     1742        fibril_mutex_unlock(&e1000->ctrl_lock);
     1743        fibril_mutex_unlock(&e1000->tx_lock);
     1744        fibril_mutex_unlock(&e1000->rx_lock);
    17361745       
    17371746        return rc;
     
    17481757        assert(!dev->driver_data);
    17491758       
    1750         nic_t *nic_data = nic_create_and_bind(dev);
    1751         if (!nic_data)
     1759        nic_t *nic = nic_create_and_bind(dev);
     1760        if (!nic)
    17521761                return NULL;
    17531762       
    1754         e1000_t *e1000_data = malloc(sizeof(e1000_t));
    1755         if (!e1000_data) {
     1763        e1000_t *e1000 = malloc(sizeof(e1000_t));
     1764        if (!e1000) {
    17561765                nic_unbind_and_destroy(dev);
    17571766                return NULL;
    17581767        }
    17591768       
    1760         bzero(e1000_data, sizeof(e1000_t));
    1761        
    1762         nic_set_specific(nic_data, e1000_data);
    1763         nic_set_write_packet_handler(nic_data, e1000_write_packet);
    1764         nic_set_state_change_handlers(nic_data, e1000_on_activating,
     1769        bzero(e1000, sizeof(e1000_t));
     1770       
     1771        nic_set_specific(nic, e1000);
     1772        nic_set_write_packet_handler(nic, e1000_write_packet);
     1773        nic_set_state_change_handlers(nic, e1000_on_activating,
    17651774            e1000_on_down, e1000_on_stopping);
    1766         nic_set_filtering_change_handlers(nic_data,
     1775        nic_set_filtering_change_handlers(nic,
    17671776            e1000_on_unicast_mode_change, e1000_on_multicast_mode_change,
    17681777            e1000_on_broadcast_mode_change, NULL, e1000_on_vlan_mask_change);
    1769         nic_set_poll_handlers(nic_data, e1000_poll_mode_change, e1000_poll);
    1770        
    1771         fibril_mutex_initialize(&e1000_data->ctrl_lock);
    1772         fibril_mutex_initialize(&e1000_data->rx_lock);
    1773         fibril_mutex_initialize(&e1000_data->tx_lock);
    1774         fibril_mutex_initialize(&e1000_data->eeprom_lock);
    1775        
    1776         return e1000_data;
     1778        nic_set_poll_handlers(nic, e1000_poll_mode_change, e1000_poll);
     1779       
     1780        fibril_mutex_initialize(&e1000->ctrl_lock);
     1781        fibril_mutex_initialize(&e1000->rx_lock);
     1782        fibril_mutex_initialize(&e1000->tx_lock);
     1783        fibril_mutex_initialize(&e1000->eeprom_lock);
     1784       
     1785        return e1000;
    17771786}
    17781787
     
    18251834        assert(dev->driver_data != NULL);
    18261835       
    1827         e1000_t *e1000_data = DRIVER_DATA_DEV(dev);
     1836        e1000_t *e1000 = DRIVER_DATA_DEV(dev);
    18281837       
    18291838        if (hw_resources->irqs.count != 1)
    18301839                return EINVAL;
    18311840       
    1832         e1000_data->irq = hw_resources->irqs.irqs[0];
    1833         e1000_data->phys_reg_base =
     1841        e1000->irq = hw_resources->irqs.irqs[0];
     1842        e1000->reg_base_phys =
    18341843            MEMADDR_TO_PTR(hw_resources->mem_ranges.ranges[0].address);
    18351844       
     
    18781887{
    18791888        /* Allocate driver data for the device. */
    1880         e1000_t *e1000_data = e1000_create_dev_data(dev);
    1881         if (e1000_data == NULL)
     1889        e1000_t *e1000 = e1000_create_dev_data(dev);
     1890        if (e1000 == NULL)
    18821891                return ENOMEM;
    18831892       
     
    18901899       
    18911900        rc = pci_config_space_read_16(dev->parent_sess, PCI_DEVICE_ID,
    1892             &e1000_data->device_id);
     1901            &e1000->device_id);
    18931902        if (rc != EOK) {
    18941903                e1000_dev_cleanup(dev);
     
    19091918static int e1000_pio_enable(ddf_dev_t *dev)
    19101919{
    1911         e1000_t *e1000_data = DRIVER_DATA_DEV(dev);
    1912        
    1913         int rc = pio_enable(e1000_data->phys_reg_base, 8 * PAGE_SIZE,
    1914             &e1000_data->virt_reg_base);
     1920        e1000_t *e1000 = DRIVER_DATA_DEV(dev);
     1921       
     1922        int rc = pio_enable(e1000->reg_base_phys, 8 * PAGE_SIZE,
     1923            &e1000->reg_base_virt);
    19151924        if (rc != EOK)
    19161925                return EADDRNOTAVAIL;
     
    19341943       
    19351944        /* Device initialization */
    1936         nic_t *nic_data = dev->driver_data;
    1937         e1000_t *e1000_data = DRIVER_DATA_NIC(nic_data);
     1945        nic_t *nic = dev->driver_data;
     1946        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
    19381947       
    19391948        /* Map registers */
     
    19421951                goto err_destroy;
    19431952       
    1944         e1000_initialize_registers(e1000_data);
    1945         rc = e1000_initialize_tx_structure(e1000_data);
     1953        e1000_initialize_registers(e1000);
     1954        rc = e1000_initialize_tx_structure(e1000);
    19461955        if (rc != EOK)
    19471956                goto err_pio;
    19481957       
    1949         fibril_mutex_lock(&e1000_data->rx_lock);
    1950        
    1951         e1000_fill_mac_from_eeprom(e1000_data);
    1952         e1000_initialize_filters(e1000_data);
    1953        
    1954         fibril_mutex_unlock(&e1000_data->rx_lock);
    1955        
    1956         e1000_initialize_vlan(e1000_data);
    1957        
    1958         rc = nic_register_as_ddf_fun(nic_data, &e1000_dev_ops);
     1958        fibril_mutex_lock(&e1000->rx_lock);
     1959       
     1960        e1000_fill_mac_from_eeprom(e1000);
     1961        e1000_initialize_filters(e1000);
     1962       
     1963        fibril_mutex_unlock(&e1000->rx_lock);
     1964       
     1965        e1000_initialize_vlan(e1000);
     1966       
     1967        rc = nic_register_as_ddf_fun(nic, &e1000_dev_ops);
    19591968        if (rc != EOK)
    19601969                goto err_tx_structure;
    19611970       
    1962         rc = e1000_register_int_handler(nic_data);
     1971        rc = e1000_register_int_handler(nic);
    19631972        if (rc != EOK)
    19641973                goto err_tx_structure;
    19651974       
    1966         rc = nic_connect_to_services(nic_data);
     1975        rc = nic_connect_to_services(nic);
    19671976        if (rc != EOK)
    19681977                goto err_irq;
    19691978       
    1970         rc = e1000_initialize_rx_structure(nic_data);
     1979        rc = e1000_initialize_rx_structure(nic);
    19711980        if (rc != EOK)
    19721981                goto err_irq;
    19731982       
    19741983        nic_address_t e1000_address;
    1975         e1000_get_address(e1000_data, &e1000_address);
    1976         rc = nic_report_address(nic_data, &e1000_address);
     1984        e1000_get_address(e1000, &e1000_address);
     1985        rc = nic_report_address(nic, &e1000_address);
    19771986        if (rc != EOK)
    19781987                goto err_rx_structure;
     
    19811990        period.tv_sec = 0;
    19821991        period.tv_usec = E1000_DEFAULT_INTERRUPT_INTERVAL_USEC;
    1983         rc = nic_report_poll_mode(nic_data, NIC_POLL_PERIODIC, &period);
     1992        rc = nic_report_poll_mode(nic, NIC_POLL_PERIODIC, &period);
    19841993        if (rc != EOK)
    19851994                goto err_rx_structure;
     
    19881997       
    19891998err_rx_structure:
    1990         e1000_uninitialize_rx_structure(nic_data);
     1999        e1000_uninitialize_rx_structure(nic);
    19912000err_irq:
    19922001        unregister_interrupt_handler(dev, DRIVER_DATA_DEV(dev)->irq);
    19932002err_tx_structure:
    1994         e1000_uninitialize_tx_structure(e1000_data);
     2003        e1000_uninitialize_tx_structure(e1000);
    19952004err_pio:
    19962005        // TODO: e1000_pio_disable(dev);
     
    20102019 *
    20112020 */
    2012 static uint16_t e1000_eeprom_read(e1000_t *e1000_data, uint8_t eeprom_address)
    2013 {
    2014         fibril_mutex_lock(&e1000_data->eeprom_lock);
     2021static uint16_t e1000_eeprom_read(e1000_t *e1000, uint8_t eeprom_address)
     2022{
     2023        fibril_mutex_lock(&e1000->eeprom_lock);
    20152024       
    20162025        uint32_t eerd_done;
    20172026        uint32_t eerd_address_offset;
    20182027       
    2019         switch (e1000_data->device_id) {
     2028        switch (e1000->device_id) {
    20202029        case 0x107c:
    20212030        case 0x1013:
     
    20402049        uint32_t write_data = EERD_START |
    20412050            (((uint32_t) eeprom_address) << eerd_address_offset);
    2042         E1000_REG_WRITE(e1000_data, E1000_EERD, write_data);
    2043        
    2044         uint32_t eerd = E1000_REG_READ(e1000_data, E1000_EERD);
     2051        E1000_REG_WRITE(e1000, E1000_EERD, write_data);
     2052       
     2053        uint32_t eerd = E1000_REG_READ(e1000, E1000_EERD);
    20452054        while ((eerd & eerd_done) == 0) {
    20462055                usleep(1);
    2047                 eerd = E1000_REG_READ(e1000_data, E1000_EERD);
     2056                eerd = E1000_REG_READ(e1000, E1000_EERD);
    20482057        }
    20492058       
    2050         fibril_mutex_unlock(&e1000_data->eeprom_lock);
     2059        fibril_mutex_unlock(&e1000->eeprom_lock);
    20512060       
    20522061        return (uint16_t) (eerd >> EERD_DATA_OFFSET);
     
    20632072 *
    20642073 */
    2065 static int e1000_get_address(e1000_t *e1000_data, nic_address_t *address)
    2066 {
    2067         fibril_mutex_lock(&e1000_data->rx_lock);
     2074static int e1000_get_address(e1000_t *e1000, nic_address_t *address)
     2075{
     2076        fibril_mutex_lock(&e1000->rx_lock);
    20682077       
    20692078        uint8_t *mac0_dest = (uint8_t *) address->address;
     
    20742083        uint8_t *mac5_dest = (uint8_t *) address->address + 5;
    20752084       
    2076         uint32_t rah = E1000_REG_READ(e1000_data, E1000_RAH_ARRAY(0));
    2077         uint32_t ral = E1000_REG_READ(e1000_data, E1000_RAL_ARRAY(0));
     2085        uint32_t rah = E1000_REG_READ(e1000, E1000_RAH_ARRAY(0));
     2086        uint32_t ral = E1000_REG_READ(e1000, E1000_RAL_ARRAY(0));
    20782087       
    20792088        *mac0_dest = (uint8_t) ral;
     
    20842093        *mac5_dest = (uint8_t) (rah >> 8);
    20852094       
    2086         fibril_mutex_unlock(&e1000_data->rx_lock);
     2095        fibril_mutex_unlock(&e1000->rx_lock);
    20872096        return EOK;
    20882097};
     
    20982107static int e1000_set_addr(ddf_fun_t *dev, const nic_address_t *addr)
    20992108{
    2100         nic_t *nic_data = NIC_DATA_DEV(dev);
    2101         e1000_t *e1000_data = DRIVER_DATA_NIC(nic_data);
    2102        
    2103         fibril_mutex_lock(&e1000_data->rx_lock);
    2104         fibril_mutex_lock(&e1000_data->tx_lock);
    2105        
    2106         int rc = nic_report_address(nic_data, addr);
     2109        nic_t *nic = NIC_DATA_DEV(dev);
     2110        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
     2111       
     2112        fibril_mutex_lock(&e1000->rx_lock);
     2113        fibril_mutex_lock(&e1000->tx_lock);
     2114       
     2115        int rc = nic_report_address(nic, addr);
    21072116        if (rc == EOK)
    2108                 e1000_write_receive_address(e1000_data, 0, addr, false);
    2109        
    2110         fibril_mutex_unlock(&e1000_data->tx_lock);
    2111         fibril_mutex_unlock(&e1000_data->rx_lock);
     2117                e1000_write_receive_address(e1000, 0, addr, false);
     2118       
     2119        fibril_mutex_unlock(&e1000->tx_lock);
     2120        fibril_mutex_unlock(&e1000->rx_lock);
    21122121       
    21132122        return rc;
    21142123}
    21152124
    2116 static void e1000_eeprom_get_address(e1000_t *e1000_data,
     2125static void e1000_eeprom_get_address(e1000_t *e1000,
    21172126    nic_address_t *address)
    21182127{
     
    21212130        uint16_t *mac4_dest = (uint16_t *) (address->address + 4);
    21222131       
    2123         *mac0_dest = e1000_eeprom_read(e1000_data, 0);
    2124         *mac2_dest = e1000_eeprom_read(e1000_data, 1);
    2125         *mac4_dest = e1000_eeprom_read(e1000_data, 2);
     2132        *mac0_dest = e1000_eeprom_read(e1000, 0);
     2133        *mac2_dest = e1000_eeprom_read(e1000, 1);
     2134        *mac4_dest = e1000_eeprom_read(e1000, 2);
    21262135}
    21272136
    21282137/** Send packet
    21292138 *
    2130  * @param nic_data NIC driver data structure
    2131  * @param packet   Packet to send
     2139 * @param nic    NIC driver data structure
     2140 * @param packet Packet to send
    21322141 *
    21332142 * @return EOK if succeed
     
    21352144 *
    21362145 */
    2137 static void e1000_write_packet(nic_t *nic_data, packet_t *packet)
    2138 {
    2139         assert(nic_data);
    2140        
    2141         e1000_t *e1000_data = DRIVER_DATA_NIC(nic_data);
    2142         fibril_mutex_lock(&e1000_data->tx_lock);
    2143        
    2144         uint32_t tdt = E1000_REG_READ(e1000_data, E1000_TDT);
     2146static void e1000_write_packet(nic_t *nic, packet_t *packet)
     2147{
     2148        assert(nic);
     2149       
     2150        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
     2151        fibril_mutex_lock(&e1000->tx_lock);
     2152       
     2153        uint32_t tdt = E1000_REG_READ(e1000, E1000_TDT);
    21452154        e1000_tx_descriptor_t *tx_descriptor_addr = (e1000_tx_descriptor_t *)
    2146             (e1000_data->tx_ring.virt + tdt * sizeof(e1000_tx_descriptor_t));
     2155            (e1000->tx_ring_virt + tdt * sizeof(e1000_tx_descriptor_t));
    21472156       
    21482157        bool descriptor_available = false;
     
    21552164        if (tx_descriptor_addr->status & TXDESCRIPTOR_STATUS_DD) {
    21562165                descriptor_available = true;
    2157                 packet_t *old_packet = *(e1000_data->tx_ring_packets + tdt);
     2166                packet_t *old_packet = *(e1000->tx_ring_packets + tdt);
    21582167                if (old_packet) {
    2159                         nic_dma_unlock_packet(old_packet);
    2160                         nic_release_packet(nic_data, old_packet);
     2168                        size_t old_packet_size = packet_get_data_length(old_packet);
     2169                        nic_dma_unlock_packet(old_packet, old_packet_size);
     2170                        nic_release_packet(nic, old_packet);
    21612171                }
    21622172        }
     
    21642174        if (!descriptor_available) {
    21652175                /* Packet lost */
    2166                 fibril_mutex_unlock(&e1000_data->tx_lock);
     2176                fibril_mutex_unlock(&e1000->tx_lock);
    21672177                return;
    21682178        }
     
    21702180        size_t packet_size = packet_get_data_length(packet);
    21712181       
    2172         void *phys_addr = nic_dma_lock_packet(packet);
    2173         if (!phys_addr) {
    2174                 fibril_mutex_unlock(&e1000_data->tx_lock);
     2182        void *phys;
     2183        int rc = nic_dma_lock_packet(packet, packet_size, &phys);
     2184        if (rc != EOK) {
     2185                fibril_mutex_unlock(&e1000->tx_lock);
    21752186                return;
    21762187        }
    21772188       
    2178         *(e1000_data->tx_ring_packets + tdt) = packet;
     2189        *(e1000->tx_ring_packets + tdt) = packet;
    21792190       
    21802191        tx_descriptor_addr->phys_addr =
    2181             PTR_TO_U64(phys_addr + packet->data_start);
     2192            PTR_TO_U64(phys + packet->data_start);
    21822193        tx_descriptor_addr->length = packet_size;
    21832194       
     
    21922203        tx_descriptor_addr->checksum_offset = 0;
    21932204        tx_descriptor_addr->status = 0;
    2194         if (e1000_data->vlan_tag_add) {
    2195                 tx_descriptor_addr->special = e1000_data->vlan_tag;
     2205        if (e1000->vlan_tag_add) {
     2206                tx_descriptor_addr->special = e1000->vlan_tag;
    21962207                tx_descriptor_addr->command |= TXDESCRIPTOR_COMMAND_VLE;
    21972208        } else
     
    22042215                tdt = 0;
    22052216       
    2206         E1000_REG_WRITE(e1000_data, E1000_TDT, tdt);
    2207        
    2208         fibril_mutex_unlock(&e1000_data->tx_lock);
     2217        E1000_REG_WRITE(e1000, E1000_TDT, tdt);
     2218       
     2219        fibril_mutex_unlock(&e1000->tx_lock);
    22092220}
    22102221
     
    22152226                return rc;
    22162227       
    2217         nic_driver_implement(&e1000_driver_ops, &e1000_dev_ops, &e1000_nic_iface);
     2228        nic_driver_implement(&e1000_driver_ops, &e1000_dev_ops,
     2229            &e1000_nic_iface);
    22182230        return ddf_driver_main(&e1000_driver);
    22192231}
  • uspace/drv/nic/e1k/e1k.h

    rf4d5f90 r9fe4db3  
    4949
    5050/** Receive descriptior */
    51 typedef struct e1000_rx_descriptor {
     51typedef struct {
    5252        /** Buffer Address - physical */
    5353        uint64_t phys_addr;
     
    5757        uint16_t checksum;
    5858        /** Status field */
    59          uint8_t status;
     59        uint8_t status;
    6060        /** Errors field */
    6161        uint8_t errors;
     
    6565
    6666/** Legacy transmit descriptior */
    67 typedef struct e1000_tx_descriptor {
     67typedef struct {
    6868        /** Buffer Address - physical */
    6969        uint64_t phys_addr;
     
    7575        uint8_t command;
    7676        /** Status field, upper bits are reserved */
    77          uint8_t status;
     77        uint8_t status;
    7878        /** Checksum Start Field */
    7979        uint8_t checksum_start_field;
  • uspace/lib/c/generic/as.c

    rf4d5f90 r9fe4db3  
    117117/** Find mapping to physical address.
    118118 *
    119  * @param address Virtual address in question (virtual).
    120  * @param[out] frame Frame address (physical).
    121  * @return Error code.
    122  * @retval EOK No error, @p frame holds the translation.
    123  * @retval ENOENT Mapping not found.
     119 * @param      virt Virtual address to find mapping for.
     120 * @param[out] phys Physical adress.
     121 *
     122 * @return EOK on no error.
     123 * @retval ENOENT if no mapping was found.
     124 *
    124125 */
    125 int as_get_physical_mapping(const void *address, uintptr_t *frame)
     126int as_get_physical_mapping(const void *virt, uintptr_t *phys)
    126127{
    127         uintptr_t tmp_frame;
    128         uintptr_t virt = (uintptr_t) address;
    129        
    130         int rc = (int) __SYSCALL2(SYS_PAGE_FIND_MAPPING,
    131             (sysarg_t) virt, (sysarg_t) &tmp_frame);
    132         if (rc != EOK) {
    133                 return rc;
    134         }
    135        
    136         if (frame != NULL) {
    137                 *frame = tmp_frame;
    138         }
    139        
    140         return EOK;
     128        return (int) __SYSCALL2(SYS_PAGE_FIND_MAPPING, (sysarg_t) virt,
     129            (sysarg_t) phys);
    141130}
    142131
  • uspace/lib/c/generic/ddi.c

    rf4d5f90 r9fe4db3  
    3333 */
    3434
     35#include <assert.h>
     36#include <unistd.h>
     37#include <errno.h>
    3538#include <sys/types.h>
    3639#include <abi/ddi/arg.h>
     
    5760 * Caller of this function must have the CAP_MEM_MANAGER capability.
    5861 *
    59  * @param p  Physical address of the starting frame.
    60  * @param v  Virtual address of the starting page.
     62 * @param phys  Physical address of the starting frame.
     63 * @param virt  Virtual address of the starting page.
    6164 * @param pages Number of pages to map.
    6265 * @param flags Flags for the new address space area.
     
    6972 *
    7073 */
    71 int physmem_map(void *pf, void *vp, size_t pages, unsigned int flags)
     74int physmem_map(void *phys, void *virt, size_t pages, unsigned int flags)
    7275{
    73         return __SYSCALL4(SYS_PHYSMEM_MAP, (sysarg_t) pf, (sysarg_t) vp,
    74             pages, flags);
     76        return __SYSCALL4(SYS_PHYSMEM_MAP, (sysarg_t) phys,
     77            (sysarg_t) virt, pages, flags);
    7578}
    7679
    77 int dmamem_map(dmamem_t *dmamem, size_t pages, unsigned int map_flags,
    78     unsigned int dma_flags)
     80int dmamem_map(void *virt, size_t size, unsigned int map_flags,
     81    unsigned int flags, void **phys)
    7982{
    80         // FIXME TODO
    81         return -1;
     83        return (int) __SYSCALL5(SYS_DMAMEM_MAP, (sysarg_t) virt,
     84            (sysarg_t) size, (sysarg_t) map_flags, (sysarg_t) flags,
     85            (sysarg_t) phys);
    8286}
    8387
    84 int dmamem_unmap(dmamem_t *dmamem)
     88int dmamem_map_anonymous(size_t size, unsigned int map_flags,
     89    unsigned int flags, void **phys, void **virt)
    8590{
    86         // FIXME TODO
    87         return -1;
     91        *virt = as_get_mappable_page(size);
     92        if (*virt == NULL)
     93                return ENOMEM;
     94       
     95        return dmamem_map(*virt, size, map_flags,
     96            flags | DMAMEM_FLAGS_ANONYMOUS, phys);
    8897}
    8998
    90 int dmamem_lock(void *virt, void **phys, size_t pages)
     99int dmamem_unmap(void *virt, size_t size, unsigned int flags)
    91100{
    92         // FIXME TODO
    93         return -1;
     101        return __SYSCALL3(SYS_DMAMEM_UNMAP, (sysarg_t) virt, (sysarg_t) size,
     102            (sysarg_t) flags);
    94103}
    95104
    96 int dmamem_unlock(void *virt, size_t pages)
     105int dmamem_unmap_anonymous(void *virt)
    97106{
    98         // FIXME TODO
    99         return -1;
     107        return __SYSCALL3(SYS_DMAMEM_UNMAP, (sysarg_t) virt, 0,
     108            DMAMEM_FLAGS_ANONYMOUS);
    100109}
    101110
  • uspace/lib/c/include/ddi.h

    rf4d5f90 r9fe4db3  
    4040#include <task.h>
    4141
    42 typedef struct {
    43         /** Physical memory */
    44         void *phys;
    45        
    46         /** Virtual memory */
    47         void *virt;
    48        
    49         /** Size in pages */
    50         size_t size;
    51        
    52         /** Mapping flags */
    53         unsigned int flags;
    54 } dmamem_t;
     42extern int device_assign_devno(void);
    5543
    56 extern int device_assign_devno(void);
    5744extern int physmem_map(void *, void *, size_t, unsigned int);
    58 extern int dmamem_map(dmamem_t *, size_t, unsigned int, unsigned int);
    59 extern int dmamem_unmap(dmamem_t *);
    60 extern int dmamem_lock(void *, void **, size_t);
    61 extern int dmamem_unlock(void *, size_t);
     45
     46extern int dmamem_map(void *, size_t, unsigned int, unsigned int, void **);
     47extern int dmamem_map_anonymous(size_t, unsigned int, unsigned int, void **,
     48    void **);
     49extern int dmamem_unmap(void *, size_t, unsigned int);
     50extern int dmamem_unmap_anonymous(void *);
     51
    6252extern int iospace_enable(task_id_t, void *, unsigned long);
    6353extern int pio_enable(void *, size_t, void **);
     54
    6455extern int register_irq(int, int, int, irq_code_t *);
    6556extern int unregister_irq(int, int);
  • uspace/lib/net/generic/packet_client.c

    rf4d5f90 r9fe4db3  
    3939#include <unistd.h>
    4040#include <sys/mman.h>
    41 
    4241#include <packet_client.h>
    4342#include <packet_remote.h>
  • uspace/lib/nic/include/nic.h

    rf4d5f90 r9fe4db3  
    275275
    276276/* Packet DMA lock */
    277 extern void *nic_dma_lock_packet(packet_t *);
    278 extern int nic_dma_unlock_packet(packet_t *);
     277extern int nic_dma_lock_packet(packet_t *, size_t, void **);
     278extern int nic_dma_unlock_packet(packet_t *, size_t);
    279279
    280280#endif // __NIC_H__
  • uspace/lib/nic/src/nic_driver.c

    rf4d5f90 r9fe4db3  
    4646#include <ipc/irc.h>
    4747#include <sysinfo.h>
    48 
     48#include <as.h>
    4949#include <devman.h>
    5050#include <ddf/interrupt.h>
     
    13341334 * @return physical address of packet
    13351335 */
    1336 void *nic_dma_lock_packet(packet_t *packet)
    1337 {
    1338         void *phys_addr;
    1339         int rc = dmamem_lock(packet, &phys_addr, 1);
    1340         if (rc != EOK)
    1341                 return NULL;
    1342        
    1343         return phys_addr;
     1336int nic_dma_lock_packet(packet_t *packet, size_t size, void **phys)
     1337{
     1338        return dmamem_map(packet, SIZE2PAGES(size), 0, 0, phys);
    13441339}
    13451340
     
    13481343 * @param packet
    13491344 */
    1350 int nic_dma_unlock_packet(packet_t *packet)
    1351 {
    1352         return dmamem_unlock(packet, 1);
     1345int nic_dma_unlock_packet(packet_t *packet, size_t size)
     1346{
     1347        return dmamem_unmap(packet, size, 0);
    13531348}
    13541349
  • uspace/lib/nic/src/nic_rx_control.c

    rf4d5f90 r9fe4db3  
    438438                }
    439439        }
     440       
    440441        /* Blocked source addresses */
    441442        if (rxc->block_sources) {
     
    443444                        return false;
    444445        }
     446       
    445447        /* VLAN filtering */
    446448        if (!rxc->vlan_exact && rxc->vlan_mask != NULL) {
Note: See TracChangeset for help on using the changeset viewer.