Changeset 6d8455d in mainline for uspace/lib


Ignore:
Timestamp:
2012-01-14T11:07:34Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f302586
Parents:
f991b6b
Message:

Eliminate packet_t from sending direction of NIC interface.

Location:
uspace/lib
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/device/nic.c

    rf991b6b r6d8455d  
    4444#include <ipc/services.h>
    4545
    46 /** Send a packet through the device
    47  *
    48  * @param[in] dev_sess
    49  * @param[in] packet_id Id of the sent packet
    50  *
    51  * @return EOK If the operation was successfully completed
    52  *
    53  */
    54 int nic_send_message(async_sess_t *dev_sess, packet_id_t packet_id)
    55 {
    56         async_exch_t *exch = async_exchange_begin(dev_sess);
    57         int rc = async_req_2_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
    58             NIC_SEND_MESSAGE, packet_id);
    59         async_exchange_end(exch);
    60        
    61         return rc;
     46/** Send frame from NIC
     47 *
     48 * @param[in] dev_sess
     49 * @param[in] data     Frame data
     50 * @param[in] size     Frame size in bytes
     51 *
     52 * @return EOK If the operation was successfully completed
     53 *
     54 */
     55int nic_send_frame(async_sess_t *dev_sess, void *data, size_t size)
     56{
     57        async_exch_t *exch = async_exchange_begin(dev_sess);
     58       
     59        ipc_call_t answer;
     60        aid_t req = async_send_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     61            NIC_SEND_MESSAGE, &answer);
     62        sysarg_t retval = async_data_write_start(exch, data, size);
     63       
     64        async_exchange_end(exch);
     65       
     66        if (retval != EOK) {
     67                async_wait_for(req, NULL);
     68                return retval;
     69        }
     70
     71        async_wait_for(req, &retval);
     72        return retval;
    6273}
    6374
  • uspace/lib/c/include/device/nic.h

    rf991b6b r6d8455d  
    8585} nic_funcs_t;
    8686
    87 extern int nic_send_message(async_sess_t *, packet_id_t);
     87extern int nic_send_frame(async_sess_t *, void *, size_t);
    8888extern int nic_connect_to_nil(async_sess_t *, services_t, nic_device_id_t);
    8989extern int nic_get_state(async_sess_t *, nic_device_state_t *);
  • uspace/lib/drv/generic/remote_nic.c

    rf991b6b r6d8455d  
    3939#include <errno.h>
    4040#include <ipc/services.h>
    41 #include <adt/measured_strings.h>
    4241#include <sys/time.h>
    4342#include "ops/nic.h"
    4443
    45 static void remote_nic_send_message(ddf_fun_t *dev, void *iface,
    46     ipc_callid_t callid, ipc_call_t *call)
    47 {
    48         nic_iface_t *nic_iface = (nic_iface_t *) iface;
    49         assert(nic_iface->send_message);
    50        
    51         packet_id_t packet_id = (packet_id_t) IPC_GET_ARG2(*call);
    52        
    53         int rc = nic_iface->send_message(dev, packet_id);
    54         async_answer_0(callid, rc);
     44static void remote_nic_send_frame(ddf_fun_t *dev, void *iface,
     45    ipc_callid_t callid, ipc_call_t *call)
     46{
     47        nic_iface_t *nic_iface = (nic_iface_t *) iface;
     48        assert(nic_iface->send_frame);
     49       
     50        void *data;
     51        size_t size;
     52        int rc;
     53       
     54        rc = async_data_write_accept(&data, false, 0, 0, 0, &size);
     55        if (rc != EOK) {
     56                async_answer_0(callid, EINVAL);
     57                return;
     58        }
     59       
     60        rc = nic_iface->send_frame(dev, data, size);
     61        async_answer_0(callid, rc);
     62        free(data);
    5563}
    5664
     
    11941202 */
    11951203static remote_iface_func_ptr_t remote_nic_iface_ops[] = {
    1196         &remote_nic_send_message,
     1204        &remote_nic_send_frame,
    11971205        &remote_nic_connect_to_nil,
    11981206        &remote_nic_get_state,
  • uspace/lib/drv/include/ops/nic.h

    rf991b6b r6d8455d  
    3737#define LIBDRV_OPS_NIC_H_
    3838
    39 #include <net/packet.h>
    4039#include <ipc/services.h>
    4140#include <net/device.h>
     
    4645typedef struct nic_iface {
    4746        /** Mandatory methods */
    48         int (*send_message)(ddf_fun_t *, packet_id_t);
     47        int (*send_frame)(ddf_fun_t *, void *, size_t);
    4948        int (*connect_to_nil)(ddf_fun_t *, services_t, nic_device_id_t);
    5049        int (*get_state)(ddf_fun_t *, nic_device_state_t *);
  • uspace/lib/nic/include/nic.h

    rf991b6b r6d8455d  
    7777 *
    7878 * @param nic_data
    79  * @param packet        Pointer to the packet to be sent
    80  */
    81 typedef void (*write_packet_handler)(nic_t *, packet_t *);
     79 * @param data          Pointer to frame data
     80 * @param size          Size of frame data in bytes
     81 */
     82typedef void (*send_frame_handler)(nic_t *, void *, size_t);
    8283/**
    8384 * The handler for transitions between driver states.
     
    206207extern int nic_get_resources(nic_t *, hw_res_list_parsed_t *);
    207208extern void nic_set_specific(nic_t *, void *);
    208 extern void nic_set_write_packet_handler(nic_t *, write_packet_handler);
     209extern void nic_set_send_frame_handler(nic_t *, send_frame_handler);
    209210extern void nic_set_state_change_handlers(nic_t *,
    210211        state_change_handler, state_change_handler, state_change_handler);
  • uspace/lib/nic/include/nic_driver.h

    rf991b6b r6d8455d  
    134134         * Called with the main_lock locked for reading.
    135135         */
    136         write_packet_handler write_packet;
     136        send_frame_handler send_frame;
    137137        /**
    138138         * Event handler called when device goes to the ACTIVE state.
  • uspace/lib/nic/include/nic_impl.h

    rf991b6b r6d8455d  
    4848
    4949extern int nic_get_address_impl(ddf_fun_t *dev_fun, nic_address_t *address);
    50 extern int nic_send_message_impl(ddf_fun_t *dev_fun, packet_id_t packet_id);
     50extern int nic_send_frame_impl(ddf_fun_t *dev_fun, void *data, size_t size);
    5151extern int nic_connect_to_nil_impl(ddf_fun_t *dev_fun, services_t nil_service,
    5252        int device_id);
  • uspace/lib/nic/src/nic_driver.c

    rf991b6b r6d8455d  
    114114                if (!iface->set_state)
    115115                        iface->set_state = nic_set_state_impl;
    116                 if (!iface->send_message)
    117                         iface->send_message = nic_send_message_impl;
     116                if (!iface->send_frame)
     117                        iface->send_frame = nic_send_frame_impl;
    118118                if (!iface->connect_to_nil)
    119119                        iface->connect_to_nil = nic_connect_to_nil_impl;
     
    168168 *
    169169 * @param nic_data
    170  * @param wpfunc                Function handling the write_packet request
    171  */
    172 void nic_set_write_packet_handler(nic_t *nic_data, write_packet_handler wpfunc)
    173 {
    174         nic_data->write_packet = wpfunc;
     170 * @param sffunc        Function handling the send_frame request
     171 */
     172void nic_set_send_frame_handler(nic_t *nic_data, send_frame_handler sffunc)
     173{
     174        nic_data->send_frame = sffunc;
    175175}
    176176
     
    765765        nic_data->poll_mode = NIC_POLL_IMMEDIATE;
    766766        nic_data->default_poll_mode = NIC_POLL_IMMEDIATE;
    767         nic_data->write_packet = NULL;
     767        nic_data->send_frame = NULL;
    768768        nic_data->on_activating = NULL;
    769769        nic_data->on_going_down = NULL;
  • uspace/lib/nic/src/nic_impl.c

    rf991b6b r6d8455d  
    3939#include <ipc/services.h>
    4040#include <ns.h>
    41 #include <packet_client.h>
    42 #include <packet_remote.h>
    4341#include "nic_driver.h"
    4442#include "nic_impl.h"
     
    159157
    160158/**
    161  * Default implementation of the send_message method.
     159 * Default implementation of the send_frame method.
    162160 * Send messages to the network.
    163161 *
    164162 * @param       fun
    165  * @param       packet_id       ID of the first packet in a queue of sent packets
     163 * @param       data    Frame data
     164 * @param       size    Frame size in bytes
    166165 *
    167166 * @return EOK          If the message was sent
    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  */
    171 int 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;
     167 * @return EBUSY        If the device is not in state when the frame can be sent.
     168 */
     169int nic_send_frame_impl(ddf_fun_t *fun, void *data, size_t size)
     170{
     171        nic_t *nic_data = (nic_t *) fun->driver_data;
    175172
    176173        fibril_rwlock_read_lock(&nic_data->main_lock);
    177174        if (nic_data->state != NIC_STATE_ACTIVE || nic_data->tx_busy) {
    178175                fibril_rwlock_read_unlock(&nic_data->main_lock);
    179                 pq_release_remote(nic_data->net_session, packet_id);
    180176                return EBUSY;
    181177        }
    182178
    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);
     179        nic_data->send_frame(nic_data, data, size);
    203180        return EOK;
    204181}
Note: See TracChangeset for help on using the changeset viewer.