Changeset 86c71de in mainline


Ignore:
Timestamp:
2012-01-21T12:57:55Z (13 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
eaa0c3f
Parents:
47a89fe (diff), e86b8f0 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge with mainline

Files:
28 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/arm32/include/mm/km.h

    r47a89fe r86c71de  
    3939
    4040#define KM_ARM32_IDENTITY_START         UINT32_C(0x80000000)
    41 #define KM_ARM32_IDENTITY_SIZE          UINT32_C(0x40000000)
     41#define KM_ARM32_IDENTITY_SIZE          UINT32_C(0x70000000)
    4242
    43 #define KM_ARM32_NON_IDENTITY_START     UINT32_C(0xc0000000)
    44 #define KM_ARM32_NON_IDENTITY_SIZE      UINT32_C(0x40000000)
     43#define KM_ARM32_NON_IDENTITY_START     UINT32_C(0xf0000000)
     44/*
     45 * The last virtual megabyte contains the high exception vectors (0xFFFF0000).
     46 * Do not include this range into kernel non-identity.
     47 */
     48#define KM_ARM32_NON_IDENTITY_SIZE      UINT32_C(0x0ff00000)
    4549
    4650extern void km_identity_arch_init(void);
  • kernel/arch/arm32/src/mm/page.c

    r47a89fe r86c71de  
    6565                page_mapping_insert(AS_KERNEL, PA2KA(cur), cur, flags);
    6666       
     67#ifdef HIGH_EXCEPTION_VECTORS
    6768        /* Create mapping for exception table at high offset */
    68 #ifdef HIGH_EXCEPTION_VECTORS
    69         // XXX: fixme to use proper non-identity page
    70         void *virtaddr = frame_alloc(ONE_FRAME, FRAME_KA);
    71         page_mapping_insert(AS_KERNEL, EXC_BASE_ADDRESS, KA2PA(virtaddr),
    72             flags);
     69        uintptr_t ev_frame = (uintptr_t) frame_alloc(ONE_FRAME, FRAME_NONE);
     70        page_mapping_insert(AS_KERNEL, EXC_BASE_ADDRESS, ev_frame, flags);
    7371#else
    7472#error "Only high exception vector supported now"
    7573#endif
    76         cur = ALIGN_DOWN(0x50008010, FRAME_SIZE);
    77         page_mapping_insert(AS_KERNEL, PA2KA(cur), cur, flags);
    7874
    7975        page_table_unlock(AS_KERNEL, true);
  • kernel/arch/ia32/src/mm/frame.c

    r47a89fe r86c71de  
    5454       
    5555        for (i = 0; i < e820counter; i++) {
    56                 uintptr_t base = (uintptr_t) e820table[i].base_address;
    57                 size_t size = (size_t) e820table[i].size;
     56                uint64_t base64 = e820table[i].base_address;
     57                uint64_t size64 = e820table[i].size;
     58
     59#ifdef KARCH_ia32
     60                /*
     61                 * Restrict the e820 table entries to 32-bits.
     62                 */
     63                if (base64 >= 0x100000000ULL)
     64                        continue;
     65                if (base64 + size64 > 0x100000000ULL)
     66                        size64 -= base64 + size64 - 0x100000000ULL;
     67#endif
     68
     69                uintptr_t base = (uintptr_t) base64;
     70                size_t size = (size_t) size64;
    5871               
    5972                if (!frame_adjust_zone_bounds(low, &base, &size))
  • kernel/genarch/src/mm/page_pt.c

    r47a89fe r86c71de  
    322322
    323323        ASSERT(ispwr2(ptl0step));
    324 
    325         for (addr = ALIGN_DOWN(base, ptl0step); addr < base + size;
     324        ASSERT(size > 0);
     325
     326        for (addr = ALIGN_DOWN(base, ptl0step); addr - 1 < base + size - 1;
    326327            addr += ptl0step) {
    327328                uintptr_t l1;
  • kernel/generic/include/mm/frame.h

    r47a89fe r86c71de  
    8383#define FRAME_TO_ZONE_FLAGS(ff) \
    8484        ((((ff) & FRAME_LOWMEM) ? ZONE_LOWMEM : \
    85             (((ff) & FRAME_HIGHMEM) ? ZONE_HIGHMEM : ZONE_NONE)) | \
    86             (ZONE_AVAILABLE | ZONE_LOWMEM /* | ZONE_HIGHMEM */))
     85            (((ff) & FRAME_HIGHMEM) ? ZONE_HIGHMEM : \
     86            ZONE_LOWMEM /* | ZONE_HIGHMEM */)) | \
     87            ZONE_AVAILABLE)
    8788
    8889#define ZONE_FLAGS_MATCH(zf, f) \
  • kernel/generic/include/mm/km.h

    r47a89fe r86c71de  
    3737
    3838#include <typedefs.h>
     39#include <mm/frame.h>
    3940
    4041extern void km_identity_init(void);
     
    4849extern bool km_is_non_identity(uintptr_t);
    4950
     51extern uintptr_t km_temporary_page_get(uintptr_t *, frame_flags_t);
     52extern void km_temporary_page_put(uintptr_t);
     53
    5054#endif
    5155
  • kernel/generic/src/mm/backend_anon.c

    r47a89fe r86c71de  
    4444#include <mm/frame.h>
    4545#include <mm/slab.h>
     46#include <mm/km.h>
    4647#include <synch/mutex.h>
    4748#include <adt/list.h>
     
    155156int anon_page_fault(as_area_t *area, uintptr_t addr, pf_access_t access)
    156157{
     158        uintptr_t upage = ALIGN_DOWN(addr, PAGE_SIZE);
     159        uintptr_t kpage;
    157160        uintptr_t frame;
    158161
     
    175178                mutex_lock(&area->sh_info->lock);
    176179                frame = (uintptr_t) btree_search(&area->sh_info->pagemap,
    177                     ALIGN_DOWN(addr, PAGE_SIZE) - area->base, &leaf);
     180                    upage - area->base, &leaf);
    178181                if (!frame) {
    179182                        bool allocate = true;
     
    185188                         */
    186189                        for (i = 0; i < leaf->keys; i++) {
    187                                 if (leaf->key[i] ==
    188                                     ALIGN_DOWN(addr, PAGE_SIZE) - area->base) {
     190                                if (leaf->key[i] == upage - area->base) {
    189191                                        allocate = false;
    190192                                        break;
     
    192194                        }
    193195                        if (allocate) {
    194                                 frame = (uintptr_t) frame_alloc_noreserve(
    195                                     ONE_FRAME, 0);
    196                                 memsetb((void *) PA2KA(frame), FRAME_SIZE, 0);
     196                                kpage = km_temporary_page_get(&frame,
     197                                    FRAME_NO_RESERVE);
     198                                memsetb((void *) kpage, PAGE_SIZE, 0);
     199                                km_temporary_page_put(kpage);
    197200                               
    198201                                /*
     
    201204                                 */
    202205                                btree_insert(&area->sh_info->pagemap,
    203                                     ALIGN_DOWN(addr, PAGE_SIZE) - area->base,
    204                                     (void *) frame, leaf);
     206                                    upage - area->base, (void *) frame, leaf);
    205207                        }
    206208                }
     
    223225                 *   the different causes
    224226                 */
    225                 frame = (uintptr_t) frame_alloc_noreserve(ONE_FRAME, 0);
    226                 memsetb((void *) PA2KA(frame), FRAME_SIZE, 0);
     227                kpage = km_temporary_page_get(&frame, FRAME_NO_RESERVE);
     228                memsetb((void *) kpage, PAGE_SIZE, 0);
     229                km_temporary_page_put(kpage);
    227230        }
    228231       
    229232        /*
    230          * Map 'page' to 'frame'.
     233         * Map 'upage' to 'frame'.
    231234         * Note that TLB shootdown is not attempted as only new information is
    232235         * being inserted into page tables.
    233236         */
    234         page_mapping_insert(AS, addr, frame, as_area_get_flags(area));
    235         if (!used_space_insert(area, ALIGN_DOWN(addr, PAGE_SIZE), 1))
     237        page_mapping_insert(AS, upage, frame, as_area_get_flags(area));
     238        if (!used_space_insert(area, upage, 1))
    236239                panic("Cannot insert used space.");
    237240               
  • kernel/generic/src/mm/backend_elf.c

    r47a89fe r86c71de  
    4444#include <mm/page.h>
    4545#include <mm/reserve.h>
     46#include <mm/km.h>
    4647#include <genarch/mm/page_pt.h>
    4748#include <genarch/mm/page_ht.h>
     
    229230        elf_segment_header_t *entry = area->backend_data.segment;
    230231        btree_node_t *leaf;
    231         uintptr_t base, frame, page, start_anon;
     232        uintptr_t base;
     233        uintptr_t frame;
     234        uintptr_t kpage;
     235        uintptr_t upage;
     236        uintptr_t start_anon;
    232237        size_t i;
    233238        bool dirty = false;
     
    249254            (((void *) elf) + ALIGN_DOWN(entry->p_offset, PAGE_SIZE));
    250255
    251         /* Virtual address of faulting page*/
    252         page = ALIGN_DOWN(addr, PAGE_SIZE);
     256        /* Virtual address of faulting page */
     257        upage = ALIGN_DOWN(addr, PAGE_SIZE);
    253258
    254259        /* Virtual address of the end of initialized part of segment */
     
    264269                mutex_lock(&area->sh_info->lock);
    265270                frame = (uintptr_t) btree_search(&area->sh_info->pagemap,
    266                     page - area->base, &leaf);
     271                    upage - area->base, &leaf);
    267272                if (!frame) {
    268273                        unsigned int i;
     
    273278
    274279                        for (i = 0; i < leaf->keys; i++) {
    275                                 if (leaf->key[i] == page - area->base) {
     280                                if (leaf->key[i] == upage - area->base) {
    276281                                        found = true;
    277282                                        break;
     
    281286                if (frame || found) {
    282287                        frame_reference_add(ADDR2PFN(frame));
    283                         page_mapping_insert(AS, addr, frame,
     288                        page_mapping_insert(AS, upage, frame,
    284289                            as_area_get_flags(area));
    285                         if (!used_space_insert(area, page, 1))
     290                        if (!used_space_insert(area, upage, 1))
    286291                                panic("Cannot insert used space.");
    287292                        mutex_unlock(&area->sh_info->lock);
     
    294299         * mapping.
    295300         */
    296         if (page >= entry->p_vaddr && page + PAGE_SIZE <= start_anon) {
     301        if (upage >= entry->p_vaddr && upage + PAGE_SIZE <= start_anon) {
    297302                /*
    298303                 * Initialized portion of the segment. The memory is backed
     
    304309                 */
    305310                if (entry->p_flags & PF_W) {
    306                         frame = (uintptr_t)frame_alloc_noreserve(ONE_FRAME, 0);
    307                         memcpy((void *) PA2KA(frame),
    308                             (void *) (base + i * FRAME_SIZE), FRAME_SIZE);
     311                        kpage = km_temporary_page_get(&frame, FRAME_NO_RESERVE);
     312                        memcpy((void *) kpage, (void *) (base + i * PAGE_SIZE),
     313                            PAGE_SIZE);
    309314                        if (entry->p_flags & PF_X) {
    310                                 smc_coherence_block((void *) PA2KA(frame),
    311                                     FRAME_SIZE);
     315                                smc_coherence_block((void *) kpage, PAGE_SIZE);
    312316                        }
     317                        km_temporary_page_put(kpage);
    313318                        dirty = true;
    314319                } else {
    315320                        frame = KA2PA(base + i * FRAME_SIZE);
    316321                }       
    317         } else if (page >= start_anon) {
     322        } else if (upage >= start_anon) {
    318323                /*
    319324                 * This is the uninitialized portion of the segment.
     
    322327                 * and cleared.
    323328                 */
    324                 frame = (uintptr_t) frame_alloc_noreserve(ONE_FRAME, 0);
    325                 memsetb((void *) PA2KA(frame), FRAME_SIZE, 0);
     329                kpage = km_temporary_page_get(&frame, FRAME_NO_RESERVE);
     330                memsetb((void *) kpage, PAGE_SIZE, 0);
     331                km_temporary_page_put(kpage);
    326332                dirty = true;
    327333        } else {
     
    334340                 * (The segment can be and often is shorter than 1 page).
    335341                 */
    336                 if (page < entry->p_vaddr)
    337                         pad_lo = entry->p_vaddr - page;
     342                if (upage < entry->p_vaddr)
     343                        pad_lo = entry->p_vaddr - upage;
    338344                else
    339345                        pad_lo = 0;
    340346
    341                 if (start_anon < page + PAGE_SIZE)
    342                         pad_hi = page + PAGE_SIZE - start_anon;
     347                if (start_anon < upage + PAGE_SIZE)
     348                        pad_hi = upage + PAGE_SIZE - start_anon;
    343349                else
    344350                        pad_hi = 0;
    345351
    346                 frame = (uintptr_t) frame_alloc_noreserve(ONE_FRAME, 0);
    347                 memcpy((void *) (PA2KA(frame) + pad_lo),
    348                     (void *) (base + i * FRAME_SIZE + pad_lo),
    349                     FRAME_SIZE - pad_lo - pad_hi);
     352                kpage = km_temporary_page_get(&frame, FRAME_NO_RESERVE);
     353                memcpy((void *) (kpage + pad_lo),
     354                    (void *) (base + i * PAGE_SIZE + pad_lo),
     355                    PAGE_SIZE - pad_lo - pad_hi);
    350356                if (entry->p_flags & PF_X) {
    351                         smc_coherence_block((void *) (PA2KA(frame) + pad_lo),
    352                             FRAME_SIZE - pad_lo - pad_hi);
     357                        smc_coherence_block((void *) (kpage + pad_lo),
     358                            PAGE_SIZE - pad_lo - pad_hi);
    353359                }
    354                 memsetb((void *) PA2KA(frame), pad_lo, 0);
    355                 memsetb((void *) (PA2KA(frame) + FRAME_SIZE - pad_hi), pad_hi,
    356                     0);
     360                memsetb((void *) kpage, pad_lo, 0);
     361                memsetb((void *) (kpage + PAGE_SIZE - pad_hi), pad_hi, 0);
     362                km_temporary_page_put(kpage);
    357363                dirty = true;
    358364        }
     
    360366        if (dirty && area->sh_info) {
    361367                frame_reference_add(ADDR2PFN(frame));
    362                 btree_insert(&area->sh_info->pagemap, page - area->base,
     368                btree_insert(&area->sh_info->pagemap, upage - area->base,
    363369                    (void *) frame, leaf);
    364370        }
     
    367373                mutex_unlock(&area->sh_info->lock);
    368374
    369         page_mapping_insert(AS, addr, frame, as_area_get_flags(area));
    370         if (!used_space_insert(area, page, 1))
     375        page_mapping_insert(AS, upage, frame, as_area_get_flags(area));
     376        if (!used_space_insert(area, upage, 1))
    371377                panic("Cannot insert used space.");
    372378
  • kernel/generic/src/mm/km.c

    r47a89fe r86c71de  
    3939#include <arch/mm/km.h>
    4040#include <mm/page.h>
     41#include <mm/frame.h>
     42#include <mm/asid.h>
    4143#include <config.h>
    4244#include <typedefs.h>
    4345#include <lib/ra.h>
    4446#include <debug.h>
     47#include <arch.h>
    4548
    4649static ra_arena_t *km_ni_arena;
     50
     51#define DEFERRED_PAGES_MAX      (PAGE_SIZE / sizeof(uintptr_t))
     52
     53/** Number of freed pages in the deferred buffer. */
     54static volatile unsigned deferred_pages;
     55/** Buffer of deferred freed pages. */
     56static uintptr_t deferred_page[DEFERRED_PAGES_MAX];
     57
     58/** Flush the buffer of deferred freed pages.
     59 *
     60 * @return              Number of freed pages.
     61 */
     62static unsigned km_flush_deferred(void)
     63{
     64        unsigned i = 0;
     65        ipl_t ipl;
     66
     67        ipl = tlb_shootdown_start(TLB_INVL_ASID, ASID_KERNEL, 0, 0);
     68
     69        for (i = 0; i < deferred_pages; i++) {
     70                page_mapping_remove(AS_KERNEL, deferred_page[i]);
     71                km_page_free(deferred_page[i], PAGE_SIZE);
     72        }
     73
     74        tlb_invalidate_asid(ASID_KERNEL);
     75
     76        as_invalidate_translation_cache(AS_KERNEL, 0, -1);
     77        tlb_shootdown_finalize(ipl);
     78
     79        return i;
     80}
    4781
    4882/** Architecture dependent setup of identity-mapped kernel memory. */
     
    87121}
    88122
     123/** Unmap kernen non-identity page.
     124 *
     125 * @param[in] page      Non-identity page to be unmapped.
     126 */
     127static void km_unmap_deferred(uintptr_t page)
     128{
     129        page_table_lock(AS_KERNEL, true);
     130
     131        if (deferred_pages == DEFERRED_PAGES_MAX) {
     132                (void) km_flush_deferred();
     133                deferred_pages = 0;
     134        }
     135
     136        deferred_page[deferred_pages++] = page;
     137
     138        page_table_unlock(AS_KERNEL, true);
     139}
     140
     141/** Create a temporary page.
     142 *
     143 * The page is mapped read/write to a newly allocated frame of physical memory.
     144 * The page must be returned back to the system by a call to
     145 * km_temporary_page_put().
     146 *
     147 * @param[inout] framep Pointer to a variable which will receive the physical
     148 *                      address of the allocated frame.
     149 * @param[in] flags     Frame allocation flags. FRAME_NONE or FRAME_NO_RESERVE.
     150 * @return              Virtual address of the allocated frame.
     151 */
     152uintptr_t km_temporary_page_get(uintptr_t *framep, frame_flags_t flags)
     153{
     154        uintptr_t frame;
     155        uintptr_t page;
     156
     157        ASSERT(THREAD);
     158        ASSERT(framep);
     159        ASSERT(!(flags & ~FRAME_NO_RESERVE));
     160
     161        /*
     162         * Allocate a frame, preferably from high memory.
     163         */
     164        frame = (uintptr_t) frame_alloc(ONE_FRAME,
     165            FRAME_HIGHMEM | FRAME_ATOMIC | flags);
     166        if (frame) {
     167                page = km_page_alloc(PAGE_SIZE, PAGE_SIZE);
     168                ASSERT(page);   // FIXME
     169                page_table_lock(AS_KERNEL, true);
     170                page_mapping_insert(AS_KERNEL, page, frame,
     171                    PAGE_CACHEABLE | PAGE_READ | PAGE_WRITE);
     172                page_table_unlock(AS_KERNEL, true);
     173        } else {
     174                frame = (uintptr_t) frame_alloc_noreserve(ONE_FRAME,
     175                    FRAME_LOWMEM);
     176                page = PA2KA(frame);
     177        }
     178
     179        *framep = frame;
     180        return page;   
     181}
     182
     183/** Destroy a temporary page.
     184 *
     185 * This function destroys a temporary page previously created by
     186 * km_temporary_page_get(). The page destruction may be immediate or deferred.
     187 * The frame mapped by the destroyed page is not freed.
     188 *
     189 * @param[in] page      Temporary page to be destroyed.
     190 */
     191void km_temporary_page_put(uintptr_t page)
     192{
     193        ASSERT(THREAD);
     194
     195        if (km_is_non_identity(page))
     196                km_unmap_deferred(page);
     197}
    89198
    90199/** @}
  • kernel/generic/src/mm/page.c

    r47a89fe r86c71de  
    202202        asize = ALIGN_UP(size, PAGE_SIZE);
    203203        align = ispwr2(size) ? size : (1U << (fnzb(size) + 1));
    204         virtaddr = km_page_alloc(asize, align);
     204        virtaddr = km_page_alloc(asize, max(PAGE_SIZE, align));
    205205
    206206        page_table_lock(AS_KERNEL, true);
  • uspace/drv/nic/e1k/e1k.c

    r47a89fe r86c71de  
    5252#include <nil_remote.h>
    5353#include <ops/nic.h>
    54 #include <packet_client.h>
    55 #include <packet_remote.h>
    56 #include <net/packet_header.h>
    5754#include "e1k.h"
    5855
     
    6259
    6360/* Must be power of 8 */
    64 #define E1000_RX_PACKETS_COUNT  128
    65 #define E1000_TX_PACKETS_COUNT  128
     61#define E1000_RX_FRAME_COUNT  128
     62#define E1000_TX_FRAME_COUNT  128
    6663
    6764#define E1000_RECEIVE_ADDRESS  16
    6865
    69 /** Maximum sending packet size */
     66/** Maximum sending frame size */
    7067#define E1000_MAX_SEND_FRAME_SIZE  2048
    71 /** Maximum receiving packet size */
    72 #define E1000_MAX_RECEIVE_PACKET_SIZE  2048
     68/** Maximum receiving frame size */
     69#define E1000_MAX_RECEIVE_FRAME_SIZE  2048
    7370
    7471/** nic_driver_data_t* -> e1000_t* cast */
     
    137134        void *rx_ring_virt;
    138135       
    139         /** Packets in rx ring  */
    140         packet_t **rx_ring_packets;
     136        /** Ring of RX frames, physical address */
     137        void **rx_frame_phys;
     138        /** Ring of RX frames, virtual address */
     139        void **rx_frame_virt;
    141140       
    142141        /** VLAN tag */
    143142        uint16_t vlan_tag;
    144143       
    145         /** Add VLAN tag to packet */
     144        /** Add VLAN tag to frame */
    146145        bool vlan_tag_add;
    147146       
     
    477476}
    478477
    479 /** Get state of acceptance of weird packets
     478/** Get state of acceptance of weird frames
    480479 *
    481480 * @param      device Device to check
     
    495494};
    496495
    497 /** Set acceptance of weird packets
     496/** Set acceptance of weird frames
    498497 *
    499498 * @param device Device to update
     
    679678}
    680679
    681 /** Disable receiving packets for default address
     680/** Disable receiving frames for default address
    682681 *
    683682 * @param e1000 E1000 data structure
     
    691690}
    692691
    693 /** Enable receiving packets for default address
     692/** Enable receiving frames for default address
    694693 *
    695694 * @param e1000 E1000 data structure
     
    751750}
    752751
    753 /** Enable accepting of broadcast packets
     752/** Enable accepting of broadcast frames
    754753 *
    755754 * @param e1000 E1000 data structure
     
    763762}
    764763
    765 /** Disable accepting of broadcast packets
     764/** Disable accepting of broadcast frames
    766765 *
    767766 * @param e1000 E1000 data structure
     
    799798}
    800799
    801 /** Set multicast packets acceptance mode
     800/** Set multicast frames acceptance mode
    802801 *
    803802 * @param nic      NIC device to update
     
    853852}
    854853
    855 /** Set unicast packets acceptance mode
     854/** Set unicast frames acceptance mode
    856855 *
    857856 * @param nic      NIC device to update
     
    911910}
    912911
    913 /** Set broadcast packets acceptance mode
     912/** Set broadcast frames acceptance mode
    914913 *
    915914 * @param nic  NIC device to update
     
    996995        if (vlan_mask) {
    997996                /*
    998                  * Disable receiving, so that packet matching
     997                 * Disable receiving, so that frame matching
    999998                 * partially written VLAN is not received.
    1000999                 */
     
    10631062}
    10641063
    1065 /** Fill receive descriptor with new empty packet
    1066  *
    1067  * Store packet in e1000->rx_ring_packets
     1064/** Fill receive descriptor with new empty buffer
     1065 *
     1066 * Store frame in e1000->rx_frame_phys
    10681067 *
    10691068 * @param nic    NIC data stricture
     
    10741073{
    10751074        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
    1076         packet_t *packet =
    1077             nic_alloc_packet(nic, E1000_MAX_RECEIVE_PACKET_SIZE);
    1078        
    1079         assert(packet);
    1080        
    1081         *(e1000->rx_ring_packets + offset) = packet;
     1075       
    10821076        e1000_rx_descriptor_t *rx_descriptor = (e1000_rx_descriptor_t *)
    10831077            (e1000->rx_ring_virt + offset * sizeof(e1000_rx_descriptor_t));
    10841078       
    1085         void *phys;
    1086         int rc =
    1087             nic_dma_lock_packet(packet, E1000_MAX_RECEIVE_PACKET_SIZE, &phys);
    1088        
    1089         if (rc == EOK)
    1090                 rx_descriptor->phys_addr = PTR_TO_U64(phys + packet->data_start);
    1091         else
    1092                 rx_descriptor->phys_addr = 0;
    1093        
     1079        rx_descriptor->phys_addr = PTR_TO_U64(e1000->rx_frame_phys[offset]);
    10941080        rx_descriptor->length = 0;
    10951081        rx_descriptor->checksum = 0;
     
    11551141}
    11561142
    1157 /** Receive packets
     1143/** Receive frames
    11581144 *
    11591145 * @param nic NIC data
    11601146 *
    11611147 */
    1162 static void e1000_receive_packets(nic_t *nic)
     1148static void e1000_receive_frames(nic_t *nic)
    11631149{
    11641150        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
     
    11671153       
    11681154        uint32_t *tail_addr = E1000_REG_ADDR(e1000, E1000_RDT);
    1169         uint32_t next_tail = e1000_inc_tail(*tail_addr, E1000_RX_PACKETS_COUNT);
     1155        uint32_t next_tail = e1000_inc_tail(*tail_addr, E1000_RX_FRAME_COUNT);
    11701156       
    11711157        e1000_rx_descriptor_t *rx_descriptor = (e1000_rx_descriptor_t *)
     
    11731159       
    11741160        while (rx_descriptor->status & 0x01) {
    1175                 uint32_t packet_size = rx_descriptor->length - E1000_CRC_SIZE;
     1161                uint32_t frame_size = rx_descriptor->length - E1000_CRC_SIZE;
    11761162               
    1177                 packet_t *packet = *(e1000->rx_ring_packets + next_tail);
    1178                 packet_suffix(packet, packet_size);
    1179                
    1180                 nic_dma_unlock_packet(packet, E1000_MAX_RECEIVE_PACKET_SIZE);
    1181                 nic_received_packet(nic, packet);
     1163                nic_frame_t *frame = nic_alloc_frame(nic, frame_size);
     1164                if (frame != NULL) {
     1165                        memcpy(frame->data, e1000->rx_frame_virt[next_tail], frame_size);
     1166                        nic_received_frame(nic, frame);
     1167                } else {
     1168                        ddf_msg(LVL_ERROR, "Memory allocation failed. Frame dropped.");
     1169                }
    11821170               
    11831171                e1000_fill_new_rx_descriptor(nic, next_tail);
    11841172               
    1185                 *tail_addr = e1000_inc_tail(*tail_addr, E1000_RX_PACKETS_COUNT);
    1186                 next_tail = e1000_inc_tail(*tail_addr, E1000_RX_PACKETS_COUNT);
     1173                *tail_addr = e1000_inc_tail(*tail_addr, E1000_RX_FRAME_COUNT);
     1174                next_tail = e1000_inc_tail(*tail_addr, E1000_RX_FRAME_COUNT);
    11871175               
    11881176                rx_descriptor = (e1000_rx_descriptor_t *)
     
    12251213{
    12261214        if (icr & ICR_RXT0)
    1227                 e1000_receive_packets(nic);
     1215                e1000_receive_frames(nic);
    12281216}
    12291217
     
    12741262}
    12751263
    1276 /** Force receiving all packets in the receive buffer
     1264/** Force receiving all frames in the receive buffer
    12771265 *
    12781266 * @param nic NIC data
     
    13471335static void e1000_initialize_rx_registers(e1000_t *e1000)
    13481336{
    1349         E1000_REG_WRITE(e1000, E1000_RDLEN, E1000_RX_PACKETS_COUNT * 16);
     1337        E1000_REG_WRITE(e1000, E1000_RDLEN, E1000_RX_FRAME_COUNT * 16);
    13501338        E1000_REG_WRITE(e1000, E1000_RDH, 0);
    13511339       
    13521340        /* It is not posible to let HW use all descriptors */
    1353         E1000_REG_WRITE(e1000, E1000_RDT, E1000_RX_PACKETS_COUNT - 1);
     1341        E1000_REG_WRITE(e1000, E1000_RDT, E1000_RX_FRAME_COUNT - 1);
    13541342       
    13551343        /* Set Broadcast Enable Bit */
     
    13711359       
    13721360        int rc = dmamem_map_anonymous(
    1373             E1000_RX_PACKETS_COUNT * sizeof(e1000_rx_descriptor_t),
     1361            E1000_RX_FRAME_COUNT * sizeof(e1000_rx_descriptor_t),
    13741362            AS_AREA_READ | AS_AREA_WRITE, 0, &e1000->rx_ring_phys,
    13751363            &e1000->rx_ring_virt);
     
    13821370            (uint32_t) PTR_TO_U64(e1000->rx_ring_phys));
    13831371       
    1384         e1000->rx_ring_packets =
    1385             malloc(E1000_RX_PACKETS_COUNT * sizeof(packet_t *));
    1386         // FIXME: Check return value
    1387        
     1372        e1000->rx_frame_phys =
     1373            calloc(E1000_RX_FRAME_COUNT, sizeof(void *));
     1374        e1000->rx_frame_virt =
     1375            calloc(E1000_RX_FRAME_COUNT, sizeof(void *));
     1376        if (e1000->rx_frame_phys == NULL || e1000->rx_frame_virt == NULL) {
     1377                rc = ENOMEM;
     1378                goto error;
     1379        }
     1380       
     1381        size_t i;
     1382        void *frame_virt;
     1383        void *frame_phys;
     1384       
     1385        for (i = 0; i < E1000_RX_FRAME_COUNT; i++) {
     1386                rc = dmamem_map_anonymous(
     1387                    E1000_MAX_SEND_FRAME_SIZE, AS_AREA_READ | AS_AREA_WRITE,
     1388                    0, &frame_phys, &frame_virt);
     1389                if (rc != EOK)
     1390                        goto error;
     1391               
     1392                e1000->rx_frame_virt[i] = frame_virt;
     1393                e1000->rx_frame_phys[i] = frame_phys;
     1394        }
     1395       
     1396        /* Write descriptor */
     1397        for (i = 0; i < E1000_RX_FRAME_COUNT; i++)
     1398                e1000_fill_new_rx_descriptor(nic, i);
     1399       
     1400        e1000_initialize_rx_registers(e1000);
     1401       
     1402        fibril_mutex_unlock(&e1000->rx_lock);
     1403        return EOK;
     1404error:
     1405        for (i = 0; i < E1000_RX_FRAME_COUNT; i++) {
     1406                if (e1000->rx_frame_virt[i] != NULL) {
     1407                        dmamem_unmap_anonymous(e1000->rx_frame_virt[i]);
     1408                        e1000->rx_frame_virt[i] = NULL;
     1409                        e1000->rx_frame_phys[i] = NULL;
     1410                }
     1411        }
     1412        if (e1000->rx_frame_phys != NULL) {
     1413                free(e1000->rx_frame_phys);
     1414                e1000->rx_frame_phys = NULL;
     1415        }
     1416        if (e1000->rx_frame_virt != NULL) {
     1417                free(e1000->rx_frame_virt);
     1418                e1000->rx_frame_phys = NULL;
     1419        }
     1420        return rc;
     1421}
     1422
     1423/** Uninitialize receive structure
     1424 *
     1425 * @param nic NIC data
     1426 *
     1427 */
     1428static void e1000_uninitialize_rx_structure(nic_t *nic)
     1429{
     1430        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
     1431       
     1432        /* Write descriptor */
     1433        for (unsigned int offset = 0; offset < E1000_RX_FRAME_COUNT; offset++) {
     1434                dmamem_unmap_anonymous(e1000->rx_frame_virt[offset]);
     1435                e1000->rx_frame_virt[offset] = NULL;
     1436                e1000->rx_frame_phys[offset] = NULL;
     1437        }
     1438       
     1439        free(e1000->rx_frame_virt);
     1440        free(e1000->rx_frame_phys);
     1441        e1000->rx_frame_virt = NULL;
     1442        e1000->rx_frame_phys = NULL;
     1443        dmamem_unmap_anonymous(e1000->rx_ring_virt);
     1444}
     1445
     1446/** Clear receive descriptor ring
     1447 *
     1448 * @param e1000 E1000 data
     1449 *
     1450 */
     1451static void e1000_clear_rx_ring(e1000_t *e1000)
     1452{
    13881453        /* Write descriptor */
    13891454        for (unsigned int offset = 0;
    1390             offset < E1000_RX_PACKETS_COUNT;
    1391             offset++)
    1392                 e1000_fill_new_rx_descriptor(nic, offset);
    1393        
    1394         e1000_initialize_rx_registers(e1000);
    1395        
    1396         fibril_mutex_unlock(&e1000->rx_lock);
    1397         return EOK;
    1398 }
    1399 
    1400 /** Uninitialize receive structure
    1401  *
    1402  * @param nic NIC data
    1403  *
    1404  */
    1405 static void e1000_uninitialize_rx_structure(nic_t *nic)
    1406 {
    1407         e1000_t *e1000 = DRIVER_DATA_NIC(nic);
    1408        
    1409         /* Write descriptor */
    1410         for (unsigned int offset = 0;
    1411             offset < E1000_RX_PACKETS_COUNT;
    1412             offset++) {
    1413                 packet_t *packet = *(e1000->rx_ring_packets + offset);
    1414                 nic_dma_unlock_packet(packet, E1000_MAX_RECEIVE_PACKET_SIZE);
    1415                 nic_release_packet(nic, packet);
    1416         }
    1417        
    1418         free(e1000->rx_ring_packets);
    1419         dmamem_unmap_anonymous(e1000->rx_ring_virt);
    1420 }
    1421 
    1422 /** Clear receive descriptor ring
    1423  *
    1424  * @param e1000 E1000 data
    1425  *
    1426  */
    1427 static void e1000_clear_rx_ring(e1000_t *e1000)
    1428 {
    1429         /* Write descriptor */
    1430         for (unsigned int offset = 0;
    1431             offset < E1000_RX_PACKETS_COUNT;
     1455            offset < E1000_RX_FRAME_COUNT;
    14321456            offset++)
    14331457                e1000_clear_rx_descriptor(e1000, offset);
     
    14981522static void e1000_initialize_tx_registers(e1000_t *e1000)
    14991523{
    1500         E1000_REG_WRITE(e1000, E1000_TDLEN, E1000_TX_PACKETS_COUNT * 16);
     1524        E1000_REG_WRITE(e1000, E1000_TDLEN, E1000_TX_FRAME_COUNT * 16);
    15011525        E1000_REG_WRITE(e1000, E1000_TDH, 0);
    15021526        E1000_REG_WRITE(e1000, E1000_TDT, 0);
     
    15301554       
    15311555        int rc = dmamem_map_anonymous(
    1532             E1000_TX_PACKETS_COUNT * sizeof(e1000_tx_descriptor_t),
     1556            E1000_TX_FRAME_COUNT * sizeof(e1000_tx_descriptor_t),
    15331557            AS_AREA_READ | AS_AREA_WRITE, 0, &e1000->tx_ring_phys,
    15341558            &e1000->tx_ring_virt);
     
    15371561       
    15381562        bzero(e1000->tx_ring_virt,
    1539             E1000_TX_PACKETS_COUNT * sizeof(e1000_tx_descriptor_t));
    1540        
    1541         e1000->tx_frame_phys = calloc(E1000_TX_PACKETS_COUNT, sizeof(void *));
    1542         e1000->tx_frame_virt = calloc(E1000_TX_PACKETS_COUNT, sizeof(void *));
     1563            E1000_TX_FRAME_COUNT * sizeof(e1000_tx_descriptor_t));
     1564       
     1565        e1000->tx_frame_phys = calloc(E1000_TX_FRAME_COUNT, sizeof(void *));
     1566        e1000->tx_frame_virt = calloc(E1000_TX_FRAME_COUNT, sizeof(void *));
    15431567
    15441568        if (e1000->tx_frame_phys == NULL || e1000->tx_frame_virt == NULL) {
     
    15471571        }
    15481572       
    1549         for (i = 0; i < E1000_TX_PACKETS_COUNT; i++) {
     1573        for (i = 0; i < E1000_TX_FRAME_COUNT; i++) {
    15501574                rc = dmamem_map_anonymous(
    15511575                    E1000_MAX_SEND_FRAME_SIZE, AS_AREA_READ | AS_AREA_WRITE,
     
    15721596       
    15731597        if (e1000->tx_frame_phys != NULL && e1000->tx_frame_virt != NULL) {
    1574                 for (i = 0; i < E1000_TX_PACKETS_COUNT; i++) {
     1598                for (i = 0; i < E1000_TX_FRAME_COUNT; i++) {
    15751599                        if (e1000->tx_frame_virt[i] != NULL) {
    15761600                                dmamem_unmap_anonymous(e1000->tx_frame_virt[i]);
     
    16031627        size_t i;
    16041628       
    1605         for (i = 0; i < E1000_TX_PACKETS_COUNT; i++) {
     1629        for (i = 0; i < E1000_TX_FRAME_COUNT; i++) {
    16061630                dmamem_unmap_anonymous(e1000->tx_frame_virt[i]);
    16071631                e1000->tx_frame_virt[i] = NULL;
     
    16301654        /* Write descriptor */
    16311655        for (unsigned int offset = 0;
    1632             offset < E1000_TX_PACKETS_COUNT;
     1656            offset < E1000_TX_FRAME_COUNT;
    16331657            offset++)
    16341658                e1000_clear_tx_descriptor(nic, offset);
     
    16871711}
    16881712
    1689 /** Activate the device to receive and transmit packets
     1713/** Activate the device to receive and transmit frames
    16901714 *
    16911715 * @param nic NIC driver data
     
    20732097int e1000_dev_add(ddf_dev_t *dev)
    20742098{
     2099        ddf_fun_t *fun;
    20752100        assert(dev);
    20762101       
     
    21032128        e1000_initialize_vlan(e1000);
    21042129       
    2105         rc = nic_register_as_ddf_fun(nic, &e1000_dev_ops);
    2106         if (rc != EOK)
     2130        fun = ddf_fun_create(nic_get_ddf_dev(nic), fun_exposed, "port0");
     2131        if (fun == NULL)
    21072132                goto err_tx_structure;
     2133        nic_set_ddf_fun(nic, fun);
     2134        fun->ops = &e1000_dev_ops;
     2135        fun->driver_data = nic;
    21082136       
    21092137        rc = e1000_register_int_handler(nic);
    21102138        if (rc != EOK)
    2111                 goto err_tx_structure;
     2139                goto err_fun_create;
    21122140       
    21132141        rc = nic_connect_to_services(nic);
     
    21322160                goto err_rx_structure;
    21332161       
     2162        rc = ddf_fun_bind(fun);
     2163        if (rc != EOK)
     2164                goto err_fun_bind;
     2165       
     2166        rc = ddf_fun_add_to_category(fun, DEVICE_CATEGORY_NIC);
     2167        if (rc != EOK)
     2168                goto err_add_to_cat;
     2169       
    21342170        return EOK;
    21352171       
     2172err_add_to_cat:
     2173        ddf_fun_unbind(fun);
     2174err_fun_bind:
    21362175err_rx_structure:
    21372176        e1000_uninitialize_rx_structure(nic);
    21382177err_irq:
    21392178        unregister_interrupt_handler(dev, DRIVER_DATA_DEV(dev)->irq);
     2179err_fun_create:
     2180        ddf_fun_destroy(fun);
     2181        nic_set_ddf_fun(nic, NULL);
    21402182err_tx_structure:
    21412183        e1000_uninitialize_tx_structure(e1000);
     
    22832325       
    22842326        if (!descriptor_available) {
    2285                 /* Packet lost */
     2327                /* Frame lost */
    22862328                fibril_mutex_unlock(&e1000->tx_lock);
    22872329                return;
     
    23122354       
    23132355        tdt++;
    2314         if (tdt == E1000_TX_PACKETS_COUNT)
     2356        if (tdt == E1000_TX_FRAME_COUNT)
    23152357                tdt = 0;
    23162358       
  • uspace/drv/nic/e1k/e1k.h

    r47a89fe r86c71de  
    3939#include <stdint.h>
    4040
    41 /** Ethernet CRC size after packet received in rx_descriptor */
     41/** Ethernet CRC size after frame received in rx_descriptor */
    4242#define E1000_CRC_SIZE  4
    4343
     
    109109/** Transmit descriptor COMMAND field bits */
    110110typedef enum {
    111         TXDESCRIPTOR_COMMAND_VLE = (1 << 6),   /**< VLAN Packet Enable */
     111        TXDESCRIPTOR_COMMAND_VLE = (1 << 6),   /**< VLAN frame Enable */
    112112        TXDESCRIPTOR_COMMAND_RS = (1 << 3),    /**< Report Status */
    113113        TXDESCRIPTOR_COMMAND_IFCS = (1 << 1),  /**< Insert FCS */
  • uspace/drv/nic/lo/lo.c

    r47a89fe r86c71de  
    4242#include <async.h>
    4343#include <nic.h>
    44 #include <packet_client.h>
    4544
    4645#define NAME  "lo"
     
    6160static void lo_send_frame(nic_t *nic_data, void *data, size_t size)
    6261{
    63         packet_t *packet;
    64         int rc;
    65 
    66         packet = nic_alloc_packet(nic_data, size);
    67         if (packet == NULL)
    68                 return;
    69 
    70         rc = packet_copy_data(packet, data, size);
    71         if (rc != EOK)
    72                 return;
    73 
    7462        nic_report_send_ok(nic_data, 1, size);
    75         nic_received_noneth_packet(nic_data, packet);
     63        nic_received_noneth_frame(nic_data, data, size);
    7664}
    7765
     
    9280static int lo_dev_add(ddf_dev_t *dev)
    9381{
    94         nic_t *nic_data = nic_create_and_bind(dev);
    95         if (nic_data == NULL) {
     82        ddf_fun_t *fun = NULL;
     83        bool bound = false;
     84       
     85        nic_t *nic = nic_create_and_bind(dev);
     86        if (nic == NULL) {
    9687                printf("%s: Failed to initialize\n", NAME);
    9788                return ENOMEM;
    9889        }
    9990       
    100         dev->driver_data = nic_data;
    101         nic_set_send_frame_handler(nic_data, lo_send_frame);
     91        dev->driver_data = nic;
     92        nic_set_send_frame_handler(nic, lo_send_frame);
    10293       
    103         int rc = nic_connect_to_services(nic_data);
     94        int rc = nic_connect_to_services(nic);
    10495        if (rc != EOK) {
    10596                printf("%s: Failed to connect to services\n", NAME);
    106                 nic_unbind_and_destroy(dev);
    107                 return rc;
     97                goto error;
    10898        }
    10999       
    110         rc = nic_register_as_ddf_fun(nic_data, &lo_dev_ops);
     100        fun = ddf_fun_create(nic_get_ddf_dev(nic), fun_exposed, "port0");
     101        if (fun == NULL) {
     102                printf("%s: Failed creating function\n", NAME);
     103                rc = ENOMEM;
     104                goto error;
     105        }
     106        nic_set_ddf_fun(nic, fun);
     107        fun->ops = &lo_dev_ops;
     108        fun->driver_data = nic;
     109       
     110        rc = nic_report_address(nic, &lo_addr);
    111111        if (rc != EOK) {
    112                 printf("%s: Failed to register as DDF function\n", NAME);
    113                 nic_unbind_and_destroy(dev);
    114                 return rc;
     112                printf("%s: Failed to setup loopback address\n", NAME);
     113                goto error;
    115114        }
    116115       
    117         rc = nic_report_address(nic_data, &lo_addr);
     116        rc = ddf_fun_bind(fun);
    118117        if (rc != EOK) {
    119                 printf("%s: Failed to setup loopback address\n", NAME);
    120                 nic_unbind_and_destroy(dev);
    121                 return rc;
     118                printf("%s: Failed binding function\n", NAME);
     119                goto error;
    122120        }
     121        bound = true;
     122       
     123        rc = ddf_fun_add_to_category(fun, DEVICE_CATEGORY_NIC);
     124        if (rc != EOK)
     125                goto error;
    123126       
    124127        printf("%s: Adding loopback device '%s'\n", NAME, dev->name);
    125128        return EOK;
     129error:
     130        if (bound)
     131                ddf_fun_unbind(fun);
     132        if (fun != NULL)
     133                ddf_fun_destroy(fun);
     134       
     135        nic_unbind_and_destroy(dev);
     136        return rc;
    126137}
    127138
  • uspace/drv/nic/ne2k/dp8390.c

    r47a89fe r86c71de  
    5959#include <stdio.h>
    6060#include <libarch/ddi.h>
    61 #include <net/packet.h>
    62 #include <packet_client.h>
    6361#include "dp8390.h"
    6462
     
    7674        uint8_t status;
    7775       
    78         /** Pointer to next packet */
     76        /** Pointer to next frame */
    7977        uint8_t next;
    8078       
     
    393391        /*
    394392         * Reset the transmit ring. If we were transmitting a frame,
    395          * we pretend that the packet is processed. Higher layers will
    396          * retransmit if the packet wasn't actually sent.
     393         * we pretend that the frame is processed. Higher layers will
     394         * retransmit if the frame wasn't actually sent.
    397395         */
    398396        ne2k->sq.dirty = false;
     
    448446                return NULL;
    449447       
    450         void *buf = packet_suffix(frame->packet, length);
    451         bzero(buf, length);
     448        bzero(frame->data, length);
    452449        uint8_t last = page + length / DP_PAGE;
    453450       
     
    455452                size_t left = (ne2k->stop_page - page) * DP_PAGE
    456453                    - sizeof(recv_header_t);
    457                 ne2k_download(ne2k, buf, page * DP_PAGE + sizeof(recv_header_t),
     454                ne2k_download(ne2k, frame->data, page * DP_PAGE + sizeof(recv_header_t),
    458455                    left);
    459                 ne2k_download(ne2k, buf + left, ne2k->start_page * DP_PAGE,
     456                ne2k_download(ne2k, frame->data + left, ne2k->start_page * DP_PAGE,
    460457                    length - left);
    461458        } else {
    462                 ne2k_download(ne2k, buf, page * DP_PAGE + sizeof(recv_header_t),
     459                ne2k_download(ne2k, frame->data, page * DP_PAGE + sizeof(recv_header_t),
    463460                    length);
    464461        }
     
    541538                 * Update the boundary pointer
    542539                 * to the value of the page
    543                  * prior to the next packet to
     540                 * prior to the next frame to
    544541                 * be processed.
    545542                 */
     
    584581                fibril_mutex_lock(&ne2k->sq_mutex);
    585582                if (ne2k->sq.dirty) {
    586                         /* Prepare the buffer for next packet */
     583                        /* Prepare the buffer for next frame */
    587584                        ne2k->sq.dirty = false;
    588585                        ne2k->sq.size = 0;
  • uspace/drv/nic/ne2k/dp8390.h

    r47a89fe r86c71de  
    264264extern void ne2k_send(nic_t *, void *, size_t);
    265265extern void ne2k_interrupt(nic_t *, uint8_t, uint8_t);
    266 extern packet_t *ne2k_alloc_packet(nic_t *, size_t);
    267266
    268267extern void ne2k_set_accept_mcast(ne2k_t *, int);
  • uspace/drv/nic/ne2k/ne2k.c

    r47a89fe r86c71de  
    261261        /* Note: some frame with previous physical address may slip to NIL here
    262262         * (for a moment the filtering is not exact), but ethernet should be OK with
    263          * that. Some packet may also be lost, but this is not a problem.
     263         * that. Some frames may also be lost, but this is not a problem.
    264264         */
    265265        ne2k_set_physical_address((ne2k_t *) nic_get_specific(nic_data), address);
     
    338338static int ne2k_dev_add(ddf_dev_t *dev)
    339339{
     340        ddf_fun_t *fun;
     341       
    340342        /* Allocate driver data for the device. */
    341343        nic_t *nic_data = nic_create_and_bind(dev);
     
    371373        }
    372374       
    373         rc = nic_register_as_ddf_fun(nic_data, &ne2k_dev_ops);
     375        rc = nic_connect_to_services(nic_data);
    374376        if (rc != EOK) {
    375377                ne2k_dev_cleanup(dev);
     
    377379        }
    378380       
    379         rc = nic_connect_to_services(nic_data);
    380         if (rc != EOK) {
     381        fun = ddf_fun_create(nic_get_ddf_dev(nic_data), fun_exposed, "port0");
     382        if (fun == NULL) {
    381383                ne2k_dev_cleanup(dev);
     384                return ENOMEM;
     385        }
     386        nic_set_ddf_fun(nic_data, fun);
     387        fun->ops = &ne2k_dev_ops;
     388        fun->driver_data = nic_data;
     389       
     390        rc = ddf_fun_bind(fun);
     391        if (rc != EOK) {
     392                ddf_fun_destroy(fun);
     393                ne2k_dev_cleanup(dev);
     394                return rc;
     395        }
     396       
     397        rc = ddf_fun_add_to_category(fun, DEVICE_CATEGORY_NIC);
     398        if (rc != EOK) {
     399                ddf_fun_unbind(fun);
     400                ddf_fun_destroy(fun);
    382401                return rc;
    383402        }
  • uspace/drv/nic/rtl8139/defs.h

    r47a89fe r86c71de  
    4242#define RTL8139_IO_SIZE 256
    4343
    44 /** The maximal transmitted packet length in bytes allowed according to RTL8139
     44/** The maximal transmitted frame length in bytes allowed according to RTL8139
    4545 *  documentation (see SIZE part of TSD documentation)
    4646 */
    47 #define RTL8139_PACKET_MAX_LENGTH 1792
     47#define RTL8139_FRAME_MAX_LENGTH 1792
    4848
    4949
     
    9494
    9595        CR      = 0x37,  /**< Command register, 1b */
    96         CAPR    = 0x38,  /**< Current address of packet read, 2b */
     96        CAPR    = 0x38,  /**< Current address of frame read, 2b */
    9797        CBA     = 0x3a,  /**< Current buffer address, 2b */
    9898
     
    282282        RCR_MulERINT = 1 << 17,    /**< Multiple early interrupt select */
    283283
    284         /** Minimal error packet length (1 = 8B, 0 = 64B). If AER/AR is set, RER8
     284        /** Minimal error frame length (1 = 8B, 0 = 64B). If AER/AR is set, RER8
    285285         * is "Don't care"
    286286         */
     
    302302
    303303        RCR_WRAP              = 1 << 7,  /**< Rx buffer wrapped */
    304         RCR_ACCEPT_ERROR      = 1 << 5,  /**< Accept error packet */
    305         RCR_ACCEPT_RUNT       = 1 << 4,  /**< Accept Runt (8-64 bytes) packets */
     304        RCR_ACCEPT_ERROR      = 1 << 5,  /**< Accept error frame */
     305        RCR_ACCEPT_RUNT       = 1 << 4,  /**< Accept Runt (8-64 bytes) frames */
    306306        RCR_ACCEPT_BROADCAST  = 1 << 3,  /**< Accept broadcast */
    307307        RCR_ACCEPT_MULTICAST  = 1 << 2,  /**< Accept multicast */
    308308        RCR_ACCEPT_PHYS_MATCH = 1 << 1,  /**< Accept device MAC address match */
    309         RCR_ACCEPT_ALL_PHYS   = 1 << 0,  /**< Accept all packets with
     309        RCR_ACCEPT_ALL_PHYS   = 1 << 0,  /**< Accept all frames with
    310310                                          * phys. desticnation
    311311                                                                          */
     
    362362        ANAR_ACK          = (1 << 14),  /**< Capability reception acknowledge */
    363363        ANAR_REMOTE_FAULT = (1 << 13),  /**< Remote fault detection capability */
    364         ANAR_PAUSE        = (1 << 10),  /**< Symetric pause packet capability */
     364        ANAR_PAUSE        = (1 << 10),  /**< Symetric pause frame capability */
    365365        ANAR_100T4        = (1 << 9),   /**< T4, not supported by the device */
    366366        ANAR_100TX_FD     = (1 << 8),   /**< 100BASE_TX full duplex */
     
    399399        CONFIG3_GNT_SELECT = (1 << 7),  /**< Gnt select */
    400400        CONFIG3_PARM_EN    = (1 << 6),  /**< Parameter enabled (100MBit mode) */
    401         CONFIG3_MAGIC      = (1 << 5),  /**< WoL Magic packet enable */
     401        CONFIG3_MAGIC      = (1 << 5),  /**< WoL Magic frame enable */
    402402        CONFIG3_LINK_UP    = (1 << 4),  /**< Wakeup if link is reestablished */
    403403        CONFIG3_CLKRUN_EN  = (1 << 2),  /**< CLKRUN enabled */ /* TODO: check what does it mean */
     
    416416};
    417417
    418 /** Maximal runt packet size + 1 */
     418/** Maximal runt frame size + 1 */
    419419#define RTL8139_RUNT_MAX_SIZE 64
    420420
    421 /** Bits in packet header */
    422 enum rtl8139_packet_header {
     421/** Bits in frame header */
     422enum rtl8139_frame_header {
    423423        RSR_MAR  = (1 << 15),  /**< Multicast received */
    424424        RSR_PAM  = (1 << 14),  /**< Physical address match */
     
    426426
    427427        RSR_ISE  = (1 << 5),   /**< Invalid symbol error, 100BASE-TX only */
    428         RSR_RUNT = (1 << 4),   /**< Runt packet (< RTL8139_RUNT_MAX_SIZE bytes) */
    429 
    430         RSR_LONG = (1 << 3),   /**< Long packet (size > 4k bytes) */
     428        RSR_RUNT = (1 << 4),   /**< Runt frame (< RTL8139_RUNT_MAX_SIZE bytes) */
     429
     430        RSR_LONG = (1 << 3),   /**< Long frame (size > 4k bytes) */
    431431        RSR_CRC  = (1 << 2),   /**< CRC error */
    432432        RSR_FAE  = (1 << 1),   /**< Frame alignment error */
    433         RSR_ROK  = (1 << 0)    /**< Good packet received */
     433        RSR_ROK  = (1 << 0)    /**< Good frame received */
    434434};
    435435
     
    451451                                                                          */
    452452
    453         APPEND_CRC = 1 << 16,        /**< Append CRC at the end of a packet */
     453        APPEND_CRC = 1 << 16,        /**< Append CRC at the end of a frame */
    454454
    455455        MXTxDMA_SHIFT = 8,  /**< Max. DMA Burst per TxDMA shift, burst = 16^value */
     
    459459        TX_RETRY_COUNT_SIZE  = 4,            /**< Retries before aborting size */
    460460
    461         CLEAR_ABORT = 1 << 0    /**< Retransmit aborted packet at the last
     461        CLEAR_ABORT = 1 << 0    /**< Retransmit aborted frame at the last
    462462                                  *  transmitted descriptor
    463463                                                          */
     
    478478extern const struct rtl8139_hwver_map rtl8139_versions[RTL8139_VER_COUNT + 1];
    479479
    480 /** Size in the packet header while copying from RxFIFO to Rx buffer */
     480/** Size in the frame header while copying from RxFIFO to Rx buffer */
    481481#define RTL8139_EARLY_SIZE UINT16_C(0xfff0)
    482 /** The only supported pause packet time value */
     482/** The only supported pause frame time value */
    483483#define RTL8139_PAUSE_VAL UINT16_C(0xFFFF)
    484484
    485 /** Size of the packet header in front of the received frame */
    486 #define RTL_PACKET_HEADER_SIZE 4
     485/** Size of the frame header in front of the received frame */
     486#define RTL_FRAME_HEADER_SIZE 4
    487487
    488488/** 8k buffer */
  • uspace/drv/nic/rtl8139/driver.c

    r47a89fe r86c71de  
    3939#include <io/log.h>
    4040#include <nic.h>
    41 #include <packet_client.h>
    4241#include <device/pci.h>
    4342
     
    152151}
    153152
    154 /** Update the mask of accepted packets in the RCR register according to
     153/** Update the mask of accepted frames in the RCR register according to
    155154 * rcr_accept_mode value in rtl8139_t
    156155 *
     
    170169}
    171170
    172 /** Fill the mask of accepted multicast packets in the card registers
     171/** Fill the mask of accepted multicast frames in the card registers
    173172 *
    174173 *  @param rtl8139  The rtl8139 private data
     
    394393#define rtl8139_tbuf_busy(tsd) ((pio_read_32(tsd) & TSD_OWN) == 0)
    395394
    396 /** Send packet with the hardware
     395/** Send frame with the hardware
    397396 *
    398397 * note: the main_lock is locked when framework calls this function
     
    412411        ddf_msg(LVL_DEBUG, "Sending frame");
    413412
    414         if (size > RTL8139_PACKET_MAX_LENGTH) {
     413        if (size > RTL8139_FRAME_MAX_LENGTH) {
    415414                ddf_msg(LVL_ERROR, "Send frame: frame too long, %zu bytes",
    416415                    size);
     
    437436        fibril_mutex_unlock(&rtl8139->tx_lock);
    438437
    439         /* Get address of the buffer descriptor and packet data */
     438        /* Get address of the buffer descriptor and frame data */
    440439        void *tsd = rtl8139->io_port + TSD0 + tx_curr * 4;
    441440        void *buf_addr = rtl8139->tx_buff[tx_curr];
     
    505504}
    506505
    507 /** Create packet structure from the buffer data
     506/** Create frame structure from the buffer data
    508507 *
    509508 * @param nic_data      NIC driver data
    510509 * @param rx_buffer     The receiver buffer
    511510 * @param rx_size       The buffer size
    512  * @param packet_start  The offset where packet data start
    513  * @param packet_size   The size of the packet data
    514  *
    515  * @return The packet  list node (not connected)
    516  */
    517 static nic_frame_t *rtl8139_read_packet(nic_t *nic_data,
    518     void *rx_buffer, size_t rx_size, size_t packet_start, size_t packet_size)
    519 {
    520         nic_frame_t *frame = nic_alloc_frame(nic_data, packet_size);
     511 * @param frame_start   The offset where packet data start
     512 * @param frame_size    The size of the frame data
     513 *
     514 * @return The frame list node (not connected)
     515 */
     516static nic_frame_t *rtl8139_read_frame(nic_t *nic_data,
     517    void *rx_buffer, size_t rx_size, size_t frame_start, size_t frame_size)
     518{
     519        nic_frame_t *frame = nic_alloc_frame(nic_data, frame_size);
    521520        if (! frame) {
    522                 ddf_msg(LVL_ERROR, "Can not allocate frame for received packet.");
     521                ddf_msg(LVL_ERROR, "Can not allocate frame for received frame.");
    523522                return NULL;
    524523        }
    525524
    526         void *packet_data = packet_suffix(frame->packet, packet_size);
    527         if (!packet_data) {
    528                 ddf_msg(LVL_ERROR, "Can not get the packet suffix.");
    529                 nic_release_frame(nic_data, frame);
    530                 return NULL;
    531         }
    532 
    533         void *ret = rtl8139_memcpy_wrapped(packet_data, rx_buffer, packet_start,
    534             RxBUF_SIZE, packet_size);
     525        void *ret = rtl8139_memcpy_wrapped(frame->data, rx_buffer, frame_start,
     526            RxBUF_SIZE, frame_size);
    535527        if (ret == NULL) {
    536528                nic_release_frame(nic_data, frame);
     
    568560}
    569561
    570 /** Receive all packets in queue
     562/** Receive all frames in queue
    571563 *
    572564 *  @param nic_data  The controller data
    573  *  @return The linked list of packet_list_t nodes, each containing one packet
    574  */
    575 static nic_frame_list_t *rtl8139_packet_receive(nic_t *nic_data)
     565 *  @return The linked list of nic_frame_list_t nodes, each containing one frame
     566 */
     567static nic_frame_list_t *rtl8139_frame_receive(nic_t *nic_data)
    576568{
    577569        rtl8139_t *rtl8139 = nic_get_specific(nic_data);
     
    581573        nic_frame_list_t *frames = nic_alloc_frame_list();
    582574        if (!frames)
    583                 ddf_msg(LVL_ERROR, "Can not allocate frame list for received packets.");
     575                ddf_msg(LVL_ERROR, "Can not allocate frame list for received frames.");
    584576
    585577        void *rx_buffer = rtl8139->rx_buff_virt;
     
    605597        while (!rtl8139_hw_buffer_empty(rtl8139)) {
    606598                void *rx_ptr = rx_buffer + rx_offset % RxBUF_SIZE;
    607                 uint32_t packet_header = uint32_t_le2host( *((uint32_t*)rx_ptr) );
    608                 uint16_t size = packet_header >> 16;
    609                 uint16_t packet_size = size - RTL8139_CRC_SIZE;
    610                 /* received packet flags in packet header */
    611                 uint16_t rcs = (uint16_t) packet_header;
     599                uint32_t frame_header = uint32_t_le2host( *((uint32_t*)rx_ptr) );
     600                uint16_t size = frame_header >> 16;
     601                uint16_t frame_size = size - RTL8139_CRC_SIZE;
     602                /* received frame flags in frame header */
     603                uint16_t rcs = (uint16_t) frame_header;
    612604
    613605                if (size == RTL8139_EARLY_SIZE) {
    614                         /* The packet copying is still in progress, break receiving */
     606                        /* The frame copying is still in progress, break receiving */
    615607                        ddf_msg(LVL_DEBUG, "Early threshold reached, not completely coppied");
    616608                        break;
     
    618610
    619611                /* Check if the header is valid, otherwise we are lost in the buffer */
    620                 if (size == 0 || size > RTL8139_PACKET_MAX_LENGTH) {
     612                if (size == 0 || size > RTL8139_FRAME_MAX_LENGTH) {
    621613                        ddf_msg(LVL_ERROR, "Receiver error -> receiver reset (size: %4"PRIu16", "
    622                             "header 0x%4"PRIx16". Offset: %zu)", size, packet_header,
     614                            "header 0x%4"PRIx16". Offset: %zu)", size, frame_header,
    623615                            rx_offset);
    624616                        goto rx_err;
     
    629621                }
    630622
    631                 cur_read += size + RTL_PACKET_HEADER_SIZE;
     623                cur_read += size + RTL_FRAME_HEADER_SIZE;
    632624                if (cur_read > max_read)
    633625                        break;
    634626
    635627                if (frames) {
    636                         nic_frame_t *frame = rtl8139_read_packet(nic_data, rx_buffer,
    637                             RxBUF_SIZE, rx_offset + RTL_PACKET_HEADER_SIZE, packet_size);
     628                        nic_frame_t *frame = rtl8139_read_frame(nic_data, rx_buffer,
     629                            RxBUF_SIZE, rx_offset + RTL_FRAME_HEADER_SIZE, frame_size);
    638630
    639631                        if (frame)
     
    642634
    643635                /* Update offset */
    644                 rx_offset = ALIGN_UP(rx_offset + size + RTL_PACKET_HEADER_SIZE, 4);
    645 
    646                 /* Write lesser value to prevent overflow into unread packet
     636                rx_offset = ALIGN_UP(rx_offset + size + RTL_FRAME_HEADER_SIZE, 4);
     637
     638                /* Write lesser value to prevent overflow into unread frame
    647639                 * (the recomendation from the RealTech rtl8139 programming guide)
    648640                 */
     
    727719                tx_used++;
    728720
    729                 /* If the packet was sent */
     721                /* If the frame was sent */
    730722                if (tsd_value & TSD_TOK) {
    731723                        size_t size = REG_GET_VAL(tsd_value, TSD_SIZE);
     
    757749}
    758750
    759 /** Receive all packets from the buffer
     751/** Receive all frames from the buffer
    760752 *
    761753 *  @param rtl8139  driver private data
    762754 */
    763 static void rtl8139_receive_packets(nic_t *nic_data)
     755static void rtl8139_receive_frames(nic_t *nic_data)
    764756{
    765757        assert(nic_data);
     
    769761
    770762        fibril_mutex_lock(&rtl8139->rx_lock);
    771         nic_frame_list_t *frames = rtl8139_packet_receive(nic_data);
     763        nic_frame_list_t *frames = rtl8139_frame_receive(nic_data);
    772764        fibril_mutex_unlock(&rtl8139->rx_lock);
    773765
     
    825817        }
    826818
    827         /* Check transmittion interrupts first to allow transmit next packets
     819        /* Check transmittion interrupts first to allow transmit next frames
    828820         * sooner
    829821         */
     
    832824        }
    833825        if (isr & INT_ROK) {
    834                 rtl8139_receive_packets(nic_data);
     826                rtl8139_receive_frames(nic_data);
    835827        }
    836828        if (isr & (INT_RER | INT_RXOVW | INT_FIFOOVW)) {
     
    933925}
    934926
    935 /** Activate the device to receive and transmit packets
     927/** Activate the device to receive and transmit frames
    936928 *
    937929 *  @param nic_data  The nic driver data
     
    12131205                goto failed;
    12141206
    1215         /* Set default packet acceptance */
     1207        /* Set default frame acceptance */
    12161208        rtl8139->rcr_data.ucast_mask = RTL8139_RCR_UCAST_DEFAULT;
    12171209        rtl8139->rcr_data.mcast_mask = RTL8139_RCR_MCAST_DEFAULT;
    12181210        rtl8139->rcr_data.bcast_mask = RTL8139_RCR_BCAST_DEFAULT;
    12191211        rtl8139->rcr_data.defect_mask = RTL8139_RCR_DEFECT_DEFAULT;
    1220         /* Set receiver early treshold to 8/16 of packet length */
     1212        /* Set receiver early treshold to 8/16 of frame length */
    12211213        rtl8139->rcr_data.rcr_base = (0x8 << RCR_ERTH_SHIFT);
    12221214
     
    12881280int rtl8139_dev_add(ddf_dev_t *dev)
    12891281{
     1282        ddf_fun_t *fun;
     1283
    12901284        assert(dev);
    12911285        ddf_msg(LVL_NOTE, "RTL8139_dev_add %s (handle = %d)", dev->name, dev->handle);
     
    13241318        }
    13251319
    1326         rc = nic_register_as_ddf_fun(nic_data, &rtl8139_dev_ops);
     1320        fun = ddf_fun_create(nic_get_ddf_dev(nic_data), fun_exposed, "port0");
     1321        if (fun == NULL) {
     1322                ddf_msg(LVL_ERROR, "Failed creating device function");
     1323                goto err_srv;
     1324        }
     1325        nic_set_ddf_fun(nic_data, fun);
     1326        fun->ops = &rtl8139_dev_ops;
     1327        fun->driver_data = nic_data;
     1328
     1329        rc = ddf_fun_bind(fun);
    13271330        if (rc != EOK) {
    1328                 ddf_msg(LVL_ERROR, "Failed to register as DDF function - error %d", rc);
    1329                 goto err_irq;
     1331                ddf_msg(LVL_ERROR, "Failed binding device function");
     1332                goto err_fun_create;
     1333        }
     1334        rc = ddf_fun_add_to_category(fun, DEVICE_CATEGORY_NIC);
     1335        if (rc != EOK) {
     1336                ddf_msg(LVL_ERROR, "Failed adding function to category");
     1337                goto err_fun_bind;
    13301338        }
    13311339
     
    13351343        return EOK;
    13361344
     1345err_fun_bind:
     1346        ddf_fun_unbind(fun);
     1347err_fun_create:
     1348        ddf_fun_destroy(fun);
     1349err_srv:
     1350        /* XXX Disconnect from services */
    13371351err_irq:
    13381352        unregister_interrupt_handler(dev, rtl8139->irq);
     
    14771491};
    14781492
    1479 /** Check if pause packet operations are valid in current situation
     1493/** Check if pause frame operations are valid in current situation
    14801494 *
    14811495 *  @param rtl8139  RTL8139 private structure
     
    15021516}
    15031517
    1504 /** Get current pause packet configuration
     1518/** Get current pause frame configuration
    15051519 *
    15061520 *  Values are filled with NIC_RESULT_NOT_AVAILABLE if the value has no sense in
     
    15081522 *
    15091523 *  @param[in]  fun         The DDF structure of the RTL8139
    1510  *  @param[out] we_send     Sign if local constroller sends pause packets
    1511  *  @param[out] we_receive  Sign if local constroller receives pause packets
    1512  *  @param[out] time        Time filled in pause packets. 0xFFFF in rtl8139
     1524 *  @param[out] we_send     Sign if local constroller sends pause frame
     1525 *  @param[out] we_receive  Sign if local constroller receives pause frame
     1526 *  @param[out] time        Time filled in pause frames. 0xFFFF in rtl8139
    15131527 *
    15141528 *  @return EOK if succeed
     
    15401554};
    15411555
    1542 /** Set current pause packet configuration
     1556/** Set current pause frame configuration
    15431557 *
    15441558 *  @param fun            The DDF structure of the RTL8139
    1545  *  @param allow_send     Sign if local constroller sends pause packets
    1546  *  @param allow_receive  Sign if local constroller receives pause packets
     1559 *  @param allow_send     Sign if local constroller sends pause frame
     1560 *  @param allow_receive  Sign if local constroller receives pause frames
    15471561 *  @param time           Time to use, ignored (not supported by device)
    15481562 *
    1549  *  @return EOK if succeed, INVAL if the pause packet has no sence
     1563 *  @return EOK if succeed, INVAL if the pause frame has no sence
    15501564 */
    15511565static int rtl8139_pause_set(ddf_fun_t *fun, int allow_send, int allow_receive,
     
    17961810}
    17971811
    1798 /** Set unicast packets acceptance mode
     1812/** Set unicast frames acceptance mode
    17991813 *
    18001814 *  @param nic_data  The nic device to update
     
    18541868}
    18551869
    1856 /** Set multicast packets acceptance mode
     1870/** Set multicast frames acceptance mode
    18571871 *
    18581872 *  @param nic_data  The nic device to update
     
    18991913}
    19001914
    1901 /** Set broadcast packets acceptance mode
     1915/** Set broadcast frames acceptance mode
    19021916 *
    19031917 *  @param nic_data  The nic device to update
     
    19291943}
    19301944
    1931 /** Get state of acceptance of weird packets
     1945/** Get state of acceptance of weird frames
    19321946 *
    19331947 *  @param[in]  device  The device to check
     
    19511965};
    19521966
    1953 /** Set acceptance of weird packets
     1967/** Set acceptance of weird frames
    19541968 *
    19551969 *  @param device  The device to update
     
    21272141}
    21282142
    2129 /** Force receiving all packets in the receive buffer
     2143/** Force receiving all frames in the receive buffer
    21302144 *
    21312145 *  @param device  The device to receive
  • uspace/drv/nic/rtl8139/driver.h

    r47a89fe r86c71de  
    3939/** Transmittion buffers count */
    4040#define TX_BUFF_COUNT 4
    41 /** Size of buffer for one packet
     41/** Size of buffer for one frame
    4242 *  - 2kB
    4343 */
     
    4949#define RTL8139_CRC_SIZE 4
    5050
    51 /** The default mode of accepting unicast packets */
     51/** The default mode of accepting unicast frames */
    5252#define RTL8139_RCR_UCAST_DEFAULT RCR_ACCEPT_PHYS_MATCH
    53 /** The default mode of accepting multicast packets */
     53/** The default mode of accepting multicast frames */
    5454#define RTL8139_RCR_MCAST_DEFAULT 0
    55 /** The default mode of accepting broadcast packets */
     55/** The default mode of accepting broadcast frames */
    5656#define RTL8139_RCR_BCAST_DEFAULT RCR_ACCEPT_BROADCAST
    57 /** The default mode of accepting defect packets */
     57/** The default mode of accepting defect frames */
    5858#define RTL8139_RCR_DEFECT_DEFAULT 0
    5959
     
    112112        size_t tx_used;
    113113
    114         /** Buffer for receiving packets */
     114        /** Buffer for receiving frames */
    115115        void *rx_buff_phys;
    116116        void *rx_buff_virt;
  • uspace/lib/net/include/nil_remote.h

    r47a89fe r86c71de  
    3939#include <generic.h>
    4040#include <async.h>
     41#include <sys/types.h>
    4142
    4243#define nil_bind_service(service, device_id, me, receiver) \
     
    6162    size_t);
    6263extern int nil_device_state_msg(async_sess_t *, nic_device_id_t, sysarg_t);
    63 extern int nil_received_msg(async_sess_t *, nic_device_id_t, packet_id_t);
     64extern int nil_received_msg(async_sess_t *, nic_device_id_t, void *, size_t);
    6465extern int nil_addr_changed_msg(async_sess_t *, nic_device_id_t,
    6566    const nic_address_t *);
  • uspace/lib/net/nil/nil_remote.c

    r47a89fe r86c71de  
    7777 */
    7878int nil_received_msg(async_sess_t *sess, nic_device_id_t device_id,
    79     packet_id_t packet_id)
     79    void *data, size_t size)
    8080{
    81         return generic_received_msg_remote(sess, NET_NIL_RECEIVED,
    82             device_id, packet_id, 0, 0);
     81        async_exch_t *exch = async_exchange_begin(sess);
     82
     83        ipc_call_t answer;
     84        aid_t req = async_send_1(exch, NET_NIL_RECEIVED, (sysarg_t) device_id,
     85            &answer);
     86        sysarg_t retval = async_data_write_start(exch, data, size);
     87
     88        async_exchange_end(exch);
     89
     90        if (retval != EOK) {
     91                async_wait_for(req, NULL);
     92                return retval;
     93        }
     94
     95        async_wait_for(req, &retval);
     96        return retval;
    8397}
    8498
  • uspace/lib/nic/include/nic.h

    r47a89fe r86c71de  
    4242#include <ddf/driver.h>
    4343#include <device/hw_res_parsed.h>
    44 #include <net/packet.h>
    4544#include <ops/nic.h>
     45
     46#define DEVICE_CATEGORY_NIC "nic"
    4647
    4748struct nic;
     
    6162
    6263/**
    63  * Simple structure for sending the allocated frames (packets) in a list.
     64 * Simple structure for sending lists of frames.
    6465 */
    6566typedef struct {
    6667        link_t link;
    67         packet_t *packet;
     68        void *data;
     69        size_t size;
    6870} nic_frame_t;
    6971
     
    7173
    7274/**
    73  * Handler for writing packet data to the NIC device.
    74  * The function is responsible for releasing the packet.
     75 * Handler for writing frame data to the NIC device.
     76 * The function is responsible for releasing the frame.
    7577 * It does not return anything, if some error is detected the function just
    7678 * silently fails (logging on debug level is suggested).
     
    158160 * @return ENOTSUP      If this filter cannot work on this NIC (e.g. the NIC
    159161 *                                      cannot run in promiscuous node or the limit of WOL
    160  *                                      packets' specifications was reached).
     162 *                                      frames' specifications was reached).
    161163 * @return ELIMIT       If this filter must implemented in HW but currently the
    162164 *                                      limit of these HW filters was reached.
     
    204206/* Functions called in add_device */
    205207extern int nic_connect_to_services(nic_t *);
    206 extern int nic_register_as_ddf_fun(nic_t *, ddf_dev_ops_t *);
    207208extern int nic_get_resources(nic_t *, hw_res_list_parsed_t *);
    208209extern void nic_set_specific(nic_t *, void *);
     
    225226extern ddf_dev_t *nic_get_ddf_dev(nic_t *);
    226227extern ddf_fun_t *nic_get_ddf_fun(nic_t *);
     228extern void nic_set_ddf_fun(nic_t *, ddf_fun_t *);
    227229extern nic_t *nic_get_from_ddf_dev(ddf_dev_t *);
    228230extern nic_t *nic_get_from_ddf_fun(ddf_fun_t *);
     
    233235extern int nic_report_poll_mode(nic_t *, nic_poll_mode_t, struct timeval *);
    234236extern void nic_query_address(nic_t *, nic_address_t *);
    235 extern void nic_received_packet(nic_t *, packet_t *);
    236 extern void nic_received_noneth_packet(nic_t *, packet_t *);
     237extern void nic_received_noneth_frame(nic_t *, void *, size_t);
    237238extern void nic_received_frame(nic_t *, nic_frame_t *);
    238239extern void nic_received_frame_list(nic_t *, nic_frame_list_t *);
     
    248249extern void nic_report_collisions(nic_t *, unsigned);
    249250
    250 /* Packet / frame / frame list allocation and deallocation */
    251 extern packet_t *nic_alloc_packet(nic_t *, size_t);
    252 extern void nic_release_packet(nic_t *, packet_t *);
     251/* Frame / frame list allocation and deallocation */
    253252extern nic_frame_t *nic_alloc_frame(nic_t *, size_t);
    254253extern nic_frame_list_t *nic_alloc_frame_list(void);
     
    275274extern void nic_sw_period_stop(nic_t *);
    276275
    277 /* Packet DMA lock */
    278 extern int nic_dma_lock_packet(packet_t *, size_t, void **);
    279 extern int nic_dma_unlock_packet(packet_t *, size_t);
    280 
    281276#endif // __NIC_H__
    282277
  • uspace/lib/nic/include/nic_driver.h

    r47a89fe r86c71de  
    5050#include "nic_rx_control.h"
    5151#include "nic_wol_virtues.h"
    52 
    53 #define DEVICE_CATEGORY_NIC "nic"
    5452
    5553struct sw_poll_info {
  • uspace/lib/nic/include/nic_rx_control.h

    r47a89fe r86c71de  
    4646#include <fibril_synch.h>
    4747#include <net/device.h>
    48 #include <net/packet_header.h>
    4948
    5049#include "nic_addr_db.h"
     
    120119        const nic_address_t *prev_addr, const nic_address_t *curr_addr);
    121120extern int nic_rxc_check(const nic_rxc_t *rxc,
    122         const packet_t *packet, nic_frame_type_t *frame_type);
     121        const void *data, size_t size, nic_frame_type_t *frame_type);
    123122extern void nic_rxc_hw_filtering(nic_rxc_t *rxc,
    124123        int unicast_exact, int multicast_exact, int vlan_exact);
  • uspace/lib/nic/src/nic_driver.c

    r47a89fe r86c71de  
    5151#include <net_interface.h>
    5252#include <ops/nic.h>
    53 #include <packet_client.h>
    54 #include <packet_remote.h>
    55 #include <net/packet_header.h>
    5653#include <errno.h>
    5754
     
    6461
    6562/**
    66  * Initializes libraries required for NIC framework - logger, packet manager
     63 * Initializes libraries required for NIC framework - logger
    6764 *
    6865 * @param name  Name of the device/driver (used in logging)
     
    7976        snprintf(buffer, 256, "drv/" DEVICE_CATEGORY_NIC "/%s", name);
    8077       
    81         /* Initialize packet manager */
    82         return pm_init();
     78        return EOK;
    8379}
    8480
     
    162158
    163159/**
    164  * Setup write packet handler. This MUST be called in the add_device handler
     160 * Setup send frame handler. This MUST be called in the add_device handler
    165161 * if the nic_send_message_impl function is used for sending messages (filled
    166162 * as send_message member of the nic_iface_t structure). The function must not
     
    270266}
    271267
    272 /**
    273  * Just a wrapper over the packet_get_1_remote function
    274  */
    275 packet_t *nic_alloc_packet(nic_t *nic_data, size_t data_size)
    276 {
    277         return packet_get_1_remote(nic_data->net_session, data_size);
    278 }
    279 
    280 
    281 /**
    282  * Just a wrapper over the pq_release_remote function
    283  */
    284 void nic_release_packet(nic_t *nic_data, packet_t *packet)
    285 {
    286         pq_release_remote(nic_data->net_session, packet_get_id(packet));
    287 }
    288 
    289 /** Allocate frame and packet
     268/** Allocate frame
    290269 *
    291270 *  @param nic_data     The NIC driver data
    292  *  @param packet_size  Size of packet
    293  *  @param offload_size Size of packet offload
     271 *  @param size         Frame size in bytes
    294272 *  @return pointer to allocated frame if success, NULL otherwise
    295273 */
    296 nic_frame_t *nic_alloc_frame(nic_t *nic_data, size_t packet_size)
     274nic_frame_t *nic_alloc_frame(nic_t *nic_data, size_t size)
    297275{
    298276        nic_frame_t *frame;
     
    313291        }
    314292
    315         packet_t *packet = nic_alloc_packet(nic_data, packet_size);
    316         if (!packet) {
     293        frame->data = malloc(size);
     294        if (frame->data == NULL) {
    317295                free(frame);
    318296                return NULL;
    319297        }
    320298
    321         frame->packet = packet;
     299        frame->size = size;
    322300        return frame;
    323301}
     
    332310        if (!frame)
    333311                return;
    334         if (frame->packet != NULL) {
    335                 nic_release_packet(nic_data, frame->packet);
    336         }
     312
     313        if (frame->data != NULL) {
     314                free(frame->data);
     315                frame->data = NULL;
     316                frame->size = 0;
     317        }
     318
    337319        fibril_mutex_lock(&nic_globals.lock);
    338320        if (nic_globals.frame_cache_size >= NIC_GLOBALS_MAX_CACHE_SIZE) {
     
    604586
    605587/**
    606  * The busy flag can be set to 1 only in the write_packet handler, to 0 it can
     588 * The busy flag can be set to 1 only in the send_frame handler, to 0 it can
    607589 * be set anywhere.
    608590 *
     
    613595{
    614596        /*
    615          * When the function is called in write_packet handler the main lock is
     597         * When the function is called in send_frame handler the main lock is
    616598         * locked so no race can happen.
    617599         * Otherwise, when it is unexpectedly set to 0 (even with main lock held
     
    622604
    623605/**
    624  * Provided for correct naming conventions.
    625  * The packet is checked by filters and then sent up to the NIL layer or
    626  * discarded, the frame is released.
    627  *
    628  * @param nic_data
    629  * @param frame         The frame containing received packet
     606 * This is the function that the driver should call when it receives a frame.
     607 * The frame is checked by filters and then sent up to the NIL layer or
     608 * discarded. The frame is released.
     609 *
     610 * @param nic_data
     611 * @param frame         The received frame
    630612 */
    631613void nic_received_frame(nic_t *nic_data, nic_frame_t *frame)
    632614{
    633         nic_received_packet(nic_data, frame->packet);
    634         frame->packet = NULL;
    635         nic_release_frame(nic_data, frame);
    636 }
    637 
    638 /**
    639  * This is the function that the driver should call when it receives a packet.
    640  * The packet is checked by filters and then sent up to the NIL layer or
    641  * discarded.
    642  *
    643  * @param nic_data
    644  * @param packet                The received packet
    645  */
    646 void nic_received_packet(nic_t *nic_data, packet_t *packet)
    647 {
    648615        /* Note: this function must not lock main lock, because loopback driver
    649          *               calls it inside write_packet handler (with locked main lock) */
    650         packet_id_t pid = packet_get_id(packet);
    651        
     616         *               calls it inside send_frame handler (with locked main lock) */
    652617        fibril_rwlock_read_lock(&nic_data->rxc_lock);
    653618        nic_frame_type_t frame_type;
    654         int check = nic_rxc_check(&nic_data->rx_control, packet, &frame_type);
     619        int check = nic_rxc_check(&nic_data->rx_control, frame->data,
     620            frame->size, &frame_type);
    655621        fibril_rwlock_read_unlock(&nic_data->rxc_lock);
    656622        /* Update statistics */
    657623        fibril_rwlock_write_lock(&nic_data->stats_lock);
    658         /* Both sending message up and releasing packet are atomic IPC calls */
     624
    659625        if (nic_data->state == NIC_STATE_ACTIVE && check) {
    660626                nic_data->stats.receive_packets++;
    661                 nic_data->stats.receive_bytes += packet_get_data_length(packet);
     627                nic_data->stats.receive_bytes += frame->size;
    662628                switch (frame_type) {
    663629                case NIC_FRAME_MULTICAST:
     
    671637                }
    672638                fibril_rwlock_write_unlock(&nic_data->stats_lock);
    673                 nil_received_msg(nic_data->nil_session, nic_data->device_id, pid);
     639                nil_received_msg(nic_data->nil_session, nic_data->device_id,
     640                    frame->data, frame->size);
    674641        } else {
    675642                switch (frame_type) {
     
    685652                }
    686653                fibril_rwlock_write_unlock(&nic_data->stats_lock);
    687                 nic_release_packet(nic_data, packet);
    688         }
     654        }
     655        nic_release_frame(nic_data, frame);
    689656}
    690657
    691658/**
    692659 * This function is to be used only in the loopback driver. It's workaround
    693  * for the situation when the packet does not contain ethernet address.
     660 * for the situation when the frame does not contain ethernet address.
    694661 * The filtering is therefore not applied here.
    695662 *
    696663 * @param nic_data
    697  * @param packet
    698  */
    699 void nic_received_noneth_packet(nic_t *nic_data, packet_t *packet)
     664 * @param data          Frame data
     665 * @param size          Frame size in bytes
     666 */
     667void nic_received_noneth_frame(nic_t *nic_data, void *data, size_t size)
    700668{
    701669        fibril_rwlock_write_lock(&nic_data->stats_lock);
    702670        nic_data->stats.receive_packets++;
    703         nic_data->stats.receive_bytes += packet_get_data_length(packet);
     671        nic_data->stats.receive_bytes += size;
    704672        fibril_rwlock_write_unlock(&nic_data->stats_lock);
    705673       
    706674        nil_received_msg(nic_data->nil_session, nic_data->device_id,
    707             packet_get_id(packet));
    708 }
    709 
    710 /**
    711  * Some NICs can receive multiple packets during single interrupt. These can
     675            data, size);
     676}
     677
     678/**
     679 * Some NICs can receive multiple frames during single interrupt. These can
    712680 * send them in whole list of frames (actually nic_frame_t structures), then
    713  * the list is deallocated and each packet is passed to the
     681 * the list is deallocated and each frame is passed to the
    714682 * nic_received_packet function.
    715683 *
     
    726694
    727695                list_remove(&frame->link);
    728                 nic_received_packet(nic_data, frame->packet);
    729                 frame->packet = NULL;
    730                 nic_release_frame(nic_data, frame);
     696                nic_received_frame(nic_data, frame);
    731697        }
    732698        nic_driver_release_frame_list(frames);
     
    846812
    847813/**
    848  * Creates an exposed DDF function for the device, named "port0".
    849  * Device options are set as this function's options. The function is bound
    850  * (see ddf_fun_bind) and then registered to the DEVICE_CATEGORY_NIC class.
    851  * Note: this function should be called only from add_device handler, therefore
    852  * we don't need to use locks.
    853  *
    854  * @param nic_data      The NIC structure
    855  * @param ops           Device options for the DDF function.
    856  */
    857 int nic_register_as_ddf_fun(nic_t *nic_data, ddf_dev_ops_t *ops)
    858 {
    859         int rc;
    860         assert(nic_data);
    861 
    862         nic_data->fun = ddf_fun_create(nic_data->dev, fun_exposed, "port0");
    863         if (nic_data->fun == NULL)
    864                 return ENOMEM;
    865        
    866         nic_data->fun->ops = ops;
    867         nic_data->fun->driver_data = nic_data;
    868 
    869         rc = ddf_fun_bind(nic_data->fun);
    870         if (rc != EOK) {
    871                 ddf_fun_destroy(nic_data->fun);
    872                 return rc;
    873         }
    874 
    875         rc = ddf_fun_add_to_category(nic_data->fun, DEVICE_CATEGORY_NIC);
    876         if (rc != EOK) {
    877                 ddf_fun_destroy(nic_data->fun);
    878                 return rc;
    879         }
    880        
    881         return EOK;
    882 }
    883 
    884 /**
    885814 * Set information about current HW filtering.
    886815 *  1 ...       Only those frames we want to receive are passed through HW
     
    10971026{
    10981027        return nic_data->fun;
     1028}
     1029
     1030/**
     1031 * @param nic_data
     1032 * @param fun
     1033 */
     1034void nic_set_ddf_fun(nic_t *nic_data, ddf_fun_t *fun)
     1035{
     1036        nic_data->fun = fun;
    10991037}
    11001038
     
    13291267}
    13301268
    1331 /** Lock packet for DMA usage
    1332  *
    1333  * @param packet
    1334  * @return physical address of packet
    1335  */
    1336 int nic_dma_lock_packet(packet_t *packet, size_t size, void **phys)
    1337 {
    1338         return dmamem_map(packet, SIZE2PAGES(size), 0, 0, phys);
    1339 }
    1340 
    1341 /** Unlock packet after DMA usage
    1342  *
    1343  * @param packet
    1344  */
    1345 int nic_dma_unlock_packet(packet_t *packet, size_t size)
    1346 {
    1347         return dmamem_unmap(packet, size);
    1348 }
    1349 
    13501269/** @}
    13511270 */
  • uspace/lib/nic/src/nic_rx_control.c

    r47a89fe r86c71de  
    392392 *
    393393 * @param rxc
    394  * @param packet        The probed frame
     394 * @param frame     The probed frame
    395395 *
    396396 * @return True if the frame passes, false if it does not
    397397 */
    398 int nic_rxc_check(const nic_rxc_t *rxc, const packet_t *packet,
     398int nic_rxc_check(const nic_rxc_t *rxc, const void *data, size_t size,
    399399        nic_frame_type_t *frame_type)
    400400{
    401401        assert(frame_type != NULL);
    402         uint8_t *dest_addr = (uint8_t *) packet + packet->data_start;
     402        uint8_t *dest_addr = (uint8_t *) data;
    403403        uint8_t *src_addr = dest_addr + ETH_ADDR;
     404
     405        if (size < 2 * ETH_ADDR)
     406                return false;
    404407
    405408        if (dest_addr[0] & 1) {
     
    448451        if (!rxc->vlan_exact && rxc->vlan_mask != NULL) {
    449452                vlan_header_t *vlan_header = (vlan_header_t *)
    450                         ((uint8_t *) packet + packet->data_start + 2 * ETH_ADDR);
     453                        ((uint8_t *) data + 2 * ETH_ADDR);
    451454                if (vlan_header->tpid_upper == VLAN_TPID_UPPER &&
    452455                        vlan_header->tpid_lower == VLAN_TPID_LOWER) {
  • uspace/srv/net/nil/eth/eth.c

    r47a89fe r86c71de  
    814814}
    815815
     816static int eth_received(nic_device_id_t device_id)
     817{
     818        void *data;
     819        size_t size;
     820        int rc;
     821       
     822        rc = async_data_write_accept(&data, false, 0, 0, 0, &size);
     823        if (rc != EOK)
     824                return rc;
     825       
     826        packet_t *packet = packet_get_1_remote(eth_globals.net_sess, size);
     827        if (packet == NULL)
     828                return ENOMEM;
     829       
     830        void *pdata = packet_suffix(packet, size);
     831        memcpy(pdata, data, size);
     832        free(data);
     833       
     834        return nil_received_msg_local(device_id, packet);
     835}
     836
    816837static int eth_addr_changed(nic_device_id_t device_id)
    817838{
     
    926947                return EOK;
    927948        case NET_NIL_RECEIVED:
    928                 rc = packet_translate_remote(eth_globals.net_sess, &packet,
    929                     IPC_GET_ARG2(*call));
    930                 if (rc == EOK)
    931                         rc = nil_received_msg_local(IPC_GET_ARG1(*call), packet);
    932                
     949                rc = eth_received(IPC_GET_ARG1(*call));
    933950                async_answer_0(callid, (sysarg_t) rc);
    934951                return rc;
  • uspace/srv/net/nil/nildummy/nildummy.c

    r47a89fe r86c71de  
    370370}
    371371
     372static int nildummy_received(nic_device_id_t device_id)
     373{
     374        void *data;
     375        size_t size;
     376        int rc;
     377
     378        rc = async_data_write_accept(&data, false, 0, 0, 0, &size);
     379        if (rc != EOK)
     380                return rc;
     381
     382        packet_t *packet = packet_get_1_remote(nildummy_globals.net_sess, size);
     383        if (packet == NULL)
     384                return ENOMEM;
     385
     386        void *pdata = packet_suffix(packet, size);
     387        memcpy(pdata, data, size);
     388        free(pdata);
     389
     390        return nil_received_msg_local(device_id, packet);
     391}
     392
    372393int nil_module_message(ipc_callid_t callid, ipc_call_t *call,
    373394    ipc_call_t *answer, size_t *answer_count)
     
    431452       
    432453        case NET_NIL_RECEIVED:
    433                 rc = packet_translate_remote(nildummy_globals.net_sess, &packet,
    434                     IPC_GET_ARG2(*call));
    435                 if (rc == EOK)
    436                         rc = nil_received_msg_local(IPC_GET_ARG1(*call), packet);
    437                
     454                rc = nildummy_received(IPC_GET_ARG1(*call));
    438455                async_answer_0(callid, (sysarg_t) rc);
    439456                return rc;
Note: See TracChangeset for help on using the changeset viewer.