Changeset 1bc35b5 in mainline for uspace/lib/nic/src


Ignore:
Timestamp:
2012-01-19T08:13:45Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d8da56b
Parents:
3ea725e
Message:

Remove most use of packet_t from NIC drivers.

Location:
uspace/lib/nic/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/nic/src/nic_driver.c

    r3ea725e r1bc35b5  
    290290 *
    291291 *  @param nic_data     The NIC driver data
    292  *  @param packet_size  Size of packet
    293  *  @param offload_size Size of packet offload
     292 *  @param size         Frame size in bytes
    294293 *  @return pointer to allocated frame if success, NULL otherwise
    295294 */
    296 nic_frame_t *nic_alloc_frame(nic_t *nic_data, size_t packet_size)
     295nic_frame_t *nic_alloc_frame(nic_t *nic_data, size_t size)
    297296{
    298297        nic_frame_t *frame;
     
    313312        }
    314313
    315         packet_t *packet = nic_alloc_packet(nic_data, packet_size);
    316         if (!packet) {
     314        frame->data = malloc(size);
     315        if (frame->data == NULL) {
    317316                free(frame);
    318317                return NULL;
    319318        }
    320319
    321         frame->packet = packet;
     320        frame->size = size;
    322321        return frame;
    323322}
     
    332331        if (!frame)
    333332                return;
    334         if (frame->packet != NULL) {
    335                 nic_release_packet(nic_data, frame->packet);
    336         }
     333
     334        if (frame->data != NULL) {
     335                free(frame->data);
     336                frame->data = NULL;
     337                frame->size = 0;
     338        }
     339
    337340        fibril_mutex_lock(&nic_globals.lock);
    338341        if (nic_globals.frame_cache_size >= NIC_GLOBALS_MAX_CACHE_SIZE) {
     
    622625
    623626/**
    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
     627 * This is the function that the driver should call when it receives a frame.
     628 * The frame is checked by filters and then sent up to the NIL layer or
     629 * discarded. The frame is released.
     630 *
     631 * @param nic_data
     632 * @param frame         The received frame
    630633 */
    631634void nic_received_frame(nic_t *nic_data, nic_frame_t *frame)
    632 {
    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)
    647635{
    648636        /* Note: this function must not lock main lock, because loopback driver
    649637         *               calls it inside write_packet handler (with locked main lock) */
    650         packet_id_t pid = packet_get_id(packet);
    651        
    652638        fibril_rwlock_read_lock(&nic_data->rxc_lock);
    653639        nic_frame_type_t frame_type;
    654         int check = nic_rxc_check(&nic_data->rx_control, packet, &frame_type);
     640        int check = nic_rxc_check(&nic_data->rx_control, frame->data,
     641            frame->size, &frame_type);
    655642        fibril_rwlock_read_unlock(&nic_data->rxc_lock);
    656643        /* Update statistics */
     
    659646        if (nic_data->state == NIC_STATE_ACTIVE && check) {
    660647                nic_data->stats.receive_packets++;
    661                 nic_data->stats.receive_bytes += packet_get_data_length(packet);
     648                nic_data->stats.receive_bytes += frame->size;
    662649                switch (frame_type) {
    663650                case NIC_FRAME_MULTICAST:
     
    671658                }
    672659                fibril_rwlock_write_unlock(&nic_data->stats_lock);
    673                 nil_received_msg(nic_data->nil_session, nic_data->device_id, pid);
     660                nil_received_msg(nic_data->nil_session, nic_data->device_id,
     661                    frame->data, frame->size);
    674662        } else {
    675663                switch (frame_type) {
     
    685673                }
    686674                fibril_rwlock_write_unlock(&nic_data->stats_lock);
    687                 nic_release_packet(nic_data, packet);
    688         }
     675        }
     676        nic_release_frame(nic_data, frame);
    689677}
    690678
     
    705693       
    706694        nil_received_msg(nic_data->nil_session, nic_data->device_id,
    707             packet_get_id(packet));
     695            packet_get_data(packet), packet_get_data_length(packet));
    708696}
    709697
     
    726714
    727715                list_remove(&frame->link);
    728                 nic_received_packet(nic_data, frame->packet);
    729                 frame->packet = NULL;
    730                 nic_release_frame(nic_data, frame);
     716                nic_received_frame(nic_data, frame);
    731717        }
    732718        nic_driver_release_frame_list(frames);
  • uspace/lib/nic/src/nic_rx_control.c

    r3ea725e r1bc35b5  
    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) {
Note: See TracChangeset for help on using the changeset viewer.