Ignore:
File:
1 edited

Legend:

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

    r6d8455d r00d7e1b  
    3939#include <ipc/services.h>
    4040#include <ns.h>
     41#include <packet_client.h>
     42#include <packet_remote.h>
    4143#include "nic_driver.h"
    4244#include "nic_impl.h"
     
    157159
    158160/**
    159  * Default implementation of the send_frame method.
     161 * Default implementation of the send_message method.
    160162 * Send messages to the network.
    161163 *
    162164 * @param       fun
    163  * @param       data    Frame data
    164  * @param       size    Frame size in bytes
     165 * @param       packet_id       ID of the first packet in a queue of sent packets
    165166 *
    166167 * @return EOK          If the message was sent
    167  * @return EBUSY        If the device is not in state when the frame can be sent.
    168  */
    169 int nic_send_frame_impl(ddf_fun_t *fun, void *data, size_t size)
    170 {
    171         nic_t *nic_data = (nic_t *) fun->driver_data;
     168 * @return EBUSY        If the device is not in state when the packet can be set.
     169 * @return EINVAL       If the packet ID is invalid
     170 */
     171int nic_send_message_impl(ddf_fun_t *fun, packet_id_t packet_id)
     172{
     173        nic_t *nic_data = (nic_t *) fun->driver_data;
     174        packet_t *packet, *next;
    172175
    173176        fibril_rwlock_read_lock(&nic_data->main_lock);
    174177        if (nic_data->state != NIC_STATE_ACTIVE || nic_data->tx_busy) {
    175178                fibril_rwlock_read_unlock(&nic_data->main_lock);
     179                pq_release_remote(nic_data->net_session, packet_id);
    176180                return EBUSY;
    177181        }
    178182
    179         nic_data->send_frame(nic_data, data, size);
     183        int rc = packet_translate_remote(nic_data->net_session, &packet, packet_id);
     184
     185        if (rc != EOK) {
     186                fibril_rwlock_read_unlock(&nic_data->main_lock);
     187                return EINVAL;
     188        }
     189
     190        /*
     191         * Process the packet queue. Each sent packet must be detached from the
     192         * queue and destroyed. This is why the cycle differs from loopback's
     193         * cycle, where the packets are immediately used in upper layers and
     194         * therefore they must not be destroyed (released).
     195         */
     196        assert(nic_data->write_packet != NULL);
     197        do {
     198                next = pq_detach(packet);
     199                nic_data->write_packet(nic_data, packet);
     200                packet = next;
     201        } while (packet);
     202        fibril_rwlock_read_unlock(&nic_data->main_lock);
    180203        return EOK;
    181204}
Note: See TracChangeset for help on using the changeset viewer.