Ignore:
File:
1 edited

Legend:

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

    r9cd8165 r00d7e1b  
    3636 */
    3737
    38 #include <errno.h>
    3938#include <str_error.h>
    4039#include <ipc/services.h>
    4140#include <ns.h>
     41#include <packet_client.h>
     42#include <packet_remote.h>
    4243#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->client_session == NULL) {
     89                if (nic_data->nil_session == NULL || nic_data->net_session == NULL
     90                    || nic_data->device_id < 0) {
    9091                        fibril_rwlock_write_unlock(&nic_data->main_lock);
    9192                        return EINVAL;
     
    117118        if (state == NIC_STATE_STOPPED) {
    118119                /* Notify upper layers that we are reseting the MAC */
    119                 int rc = nic_ev_addr_changed(nic_data->client_session,
    120                         &nic_data->default_mac);
     120                int rc = nil_addr_changed_msg(nic_data->nil_session,
     121                        nic_data->device_id, &nic_data->default_mac);
    121122                nic_data->poll_mode = nic_data->default_poll_mode;
    122123                memcpy(&nic_data->poll_period, &nic_data->default_poll_period,
     
    150151        nic_data->state = state;
    151152
    152         nic_ev_device_state(nic_data->client_session, state);
     153        nil_device_state_msg(nic_data->nil_session, nic_data->device_id, state);
    153154
    154155        fibril_rwlock_write_unlock(&nic_data->main_lock);
     
    158159
    159160/**
    160  * Default implementation of the send_frame method.
     161 * Default implementation of the send_message method.
    161162 * Send messages to the network.
    162163 *
    163164 * @param       fun
    164  * @param       data    Frame data
    165  * @param       size    Frame size in bytes
     165 * @param       packet_id       ID of the first packet in a queue of sent packets
    166166 *
    167167 * @return EOK          If the message was sent
    168  * @return EBUSY        If the device is not in state when the frame can be sent.
    169  */
    170 int nic_send_frame_impl(ddf_fun_t *fun, void *data, size_t size)
    171 {
    172         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;
    173175
    174176        fibril_rwlock_read_lock(&nic_data->main_lock);
    175177        if (nic_data->state != NIC_STATE_ACTIVE || nic_data->tx_busy) {
    176178                fibril_rwlock_read_unlock(&nic_data->main_lock);
     179                pq_release_remote(nic_data->net_session, packet_id);
    177180                return EBUSY;
    178181        }
    179182
    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.
     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.
    187209 *
    188210 * @param       fun
    189  *
    190  * @return EOK          On success, or negative error code.
    191  */
    192 int 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);
     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 */
     217int 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);
    196222       
    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         }
     223        nic_data->device_id = device_id;
    202224       
    203         fibril_rwlock_write_unlock(&nic->main_lock);
    204         return EOK;
     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;
    205234}
    206235
     
    799828}
    800829
     830/** Default implementation of the device_added method
     831 *
     832 * Just calls nic_ready.
     833 *
     834 * @param dev
     835 *
     836 */
     837void nic_device_added_impl(ddf_dev_t *dev)
     838{
     839        nic_ready((nic_t *) dev->driver_data);
     840}
     841
    801842/**
    802843 * Default handler for unknown methods (outside of the NIC interface).
Note: See TracChangeset for help on using the changeset viewer.