Changeset b7068da in mainline for uspace/lib/nic/src/nic_impl.c


Ignore:
Timestamp:
2012-02-09T20:35:12Z (12 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
591762c6
Parents:
7cede12c (diff), 3d4750f (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 mainline changes

File:
1 edited

Legend:

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

    r7cede12c rb7068da  
    3636 */
    3737
     38#include <errno.h>
    3839#include <str_error.h>
    3940#include <ipc/services.h>
    4041#include <ns.h>
    41 #include <packet_client.h>
    42 #include <packet_remote.h>
    4342#include "nic_driver.h"
     43#include "nic_ev.h"
    4444#include "nic_impl.h"
    4545
     
    8787        }
    8888        if (state == NIC_STATE_ACTIVE) {
    89                 if (nic_data->nil_session == NULL || nic_data->net_session == NULL
    90                     || nic_data->device_id < 0) {
     89                if (nic_data->client_session == NULL) {
    9190                        fibril_rwlock_write_unlock(&nic_data->main_lock);
    9291                        return EINVAL;
     
    118117        if (state == NIC_STATE_STOPPED) {
    119118                /* Notify upper layers that we are reseting the MAC */
    120                 int rc = nil_addr_changed_msg(nic_data->nil_session,
    121                         nic_data->device_id, &nic_data->default_mac);
     119                int rc = nic_ev_addr_changed(nic_data->client_session,
     120                        &nic_data->default_mac);
    122121                nic_data->poll_mode = nic_data->default_poll_mode;
    123122                memcpy(&nic_data->poll_period, &nic_data->default_poll_period,
     
    151150        nic_data->state = state;
    152151
    153         nil_device_state_msg(nic_data->nil_session, nic_data->device_id, state);
     152        nic_ev_device_state(nic_data->client_session, state);
    154153
    155154        fibril_rwlock_write_unlock(&nic_data->main_lock);
     
    159158
    160159/**
    161  * Default implementation of the send_message method.
     160 * Default implementation of the send_frame method.
    162161 * Send messages to the network.
    163162 *
    164163 * @param       fun
    165  * @param       packet_id       ID of the first packet in a queue of sent packets
     164 * @param       data    Frame data
     165 * @param       size    Frame size in bytes
    166166 *
    167167 * @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;
     168 * @return EBUSY        If the device is not in state when the frame can be sent.
     169 */
     170int nic_send_frame_impl(ddf_fun_t *fun, void *data, size_t size)
     171{
     172        nic_t *nic_data = (nic_t *) fun->driver_data;
    175173
    176174        fibril_rwlock_read_lock(&nic_data->main_lock);
    177175        if (nic_data->state != NIC_STATE_ACTIVE || nic_data->tx_busy) {
    178176                fibril_rwlock_read_unlock(&nic_data->main_lock);
    179                 pq_release_remote(nic_data->net_session, packet_id);
    180177                return EBUSY;
    181178        }
    182179
    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);
    203         return EOK;
    204 }
    205 
    206 /**
    207  * Default implementation of the connect_to_nil method.
    208  * Connects the driver to the NIL service.
     180        nic_data->send_frame(nic_data, data, size);
     181        return EOK;
     182}
     183
     184/**
     185 * Default implementation of the connect_client method.
     186 * Creates callback connection to the client.
    209187 *
    210188 * @param       fun
    211  * @param       nil_service     ID of the server implementing the NIL service
    212  * @param       device_id       ID of the device as used in higher layers
    213  *
    214  * @return EOK          If the services were bound
    215  * @return                      Negative error code from service_connect_blocking
    216  */
    217 int nic_connect_to_nil_impl(ddf_fun_t *fun, services_t nil_service,
    218     nic_device_id_t device_id)
    219 {
    220         nic_t *nic_data = (nic_t *) fun->driver_data;
    221         fibril_rwlock_write_lock(&nic_data->main_lock);
     189 *
     190 * @return EOK          On success, or negative error code.
     191 */
     192int nic_callback_create_impl(ddf_fun_t *fun)
     193{
     194        nic_t *nic = (nic_t *) fun->driver_data;
     195        fibril_rwlock_write_lock(&nic->main_lock);
    222196       
    223         nic_data->device_id = device_id;
     197        nic->client_session = async_callback_receive(EXCHANGE_SERIALIZE);
     198        if (nic->client_session == NULL) {
     199                fibril_rwlock_write_unlock(&nic->main_lock);
     200                return ENOMEM;
     201        }
    224202       
    225         nic_data->nil_session = service_connect_blocking(EXCHANGE_SERIALIZE,
    226             nil_service, 0, 0);
    227         if (nic_data->nil_session != NULL) {
    228                 fibril_rwlock_write_unlock(&nic_data->main_lock);
    229                 return EOK;
    230         }
    231        
    232         fibril_rwlock_write_unlock(&nic_data->main_lock);
    233         return EHANGUP;
     203        fibril_rwlock_write_unlock(&nic->main_lock);
     204        return EOK;
    234205}
    235206
     
    828799}
    829800
    830 /** Default implementation of the device_added method
    831  *
    832  * Just calls nic_ready.
    833  *
    834  * @param dev
    835  *
    836  */
    837 void nic_device_added_impl(ddf_dev_t *dev)
    838 {
    839         nic_ready((nic_t *) dev->driver_data);
    840 }
    841 
    842801/**
    843802 * Default handler for unknown methods (outside of the NIC interface).
Note: See TracChangeset for help on using the changeset viewer.