Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/nil/eth/eth.c

    r9cd8165 r6d8455d  
    4848#include <ipc/net.h>
    4949#include <ipc/services.h>
    50 #include <loc.h>
    5150#include <net/modules.h>
    5251#include <net_checksum.h>
     
    170169INT_MAP_IMPLEMENT(eth_protos, eth_proto_t);
    171170
    172 static void eth_nic_cb_connection(ipc_callid_t iid, ipc_call_t *icall,
    173     void *arg);
    174 
    175 static int eth_device_state(eth_device_t *device, sysarg_t state)
     171int nil_device_state_msg_local(nic_device_id_t device_id, sysarg_t state)
    176172{
    177173        int index;
     
    183179                proto = eth_protos_get_index(&eth_globals.protos, index);
    184180                if ((proto) && (proto->sess)) {
    185                         il_device_state_msg(proto->sess, device->device_id,
    186                             state, proto->service);
     181                        il_device_state_msg(proto->sess, device_id, state,
     182                            proto->service);
    187183                }
    188184        }
     
    230226 *
    231227 * @param[in] device_id New device identifier.
    232  * @param[in] sid       NIC service ID.
     228 * @param[in] handle    Device driver handle.
    233229 * @param[in] mtu       Device maximum transmission unit.
    234230 *
     
    238234 *
    239235 */
    240 static int eth_device_message(nic_device_id_t device_id, service_id_t sid,
     236static int eth_device_message(nic_device_id_t device_id, devman_handle_t handle,
    241237    size_t mtu)
    242238{
     
    263259        device = eth_devices_find(&eth_globals.devices, device_id);
    264260        if (device) {
    265                 if (device->sid != sid) {
     261                if (device->handle != handle) {
    266262                        printf("Device %d already exists\n", device->device_id);
    267263                        fibril_rwlock_write_unlock(&eth_globals.devices_lock);
     
    302298
    303299        device->device_id = device_id;
    304         device->sid = sid;
     300        device->handle = handle;
    305301        device->flags = 0;
    306302        if ((mtu > 0) && (mtu <= ETH_MAX_TAGGED_CONTENT(device->flags)))
     
    339335       
    340336        /* Bind the device driver */
    341         device->sess = loc_service_connect(EXCHANGE_SERIALIZE, sid,
     337        device->sess = devman_device_connect(EXCHANGE_SERIALIZE, handle,
    342338            IPC_FLAG_BLOCKING);
    343339        if (device->sess == NULL) {
     
    347343        }
    348344       
    349         rc = nic_callback_create(device->sess, eth_nic_cb_connection, device);
    350         if (rc != EOK) {
    351                 fibril_rwlock_write_unlock(&eth_globals.devices_lock);
    352                 async_hangup(device->sess);
    353                 free(device);
    354                 return EIO;
    355         }
     345        nic_connect_to_nil(device->sess, SERVICE_ETHERNET, device_id);
    356346       
    357347        /* Get hardware address */
     
    372362        }
    373363       
    374         printf("%s: Device registered (id: %d, sid: %zu: mtu: %zu, "
     364        printf("%s: Device registered (id: %d, handle: %zu: mtu: %zu, "
    375365            "mac: " PRIMAC ", flags: 0x%x)\n", NAME,
    376             device->device_id, device->sid, device->mtu,
     366            device->device_id, device->handle, device->mtu,
    377367            ARGSMAC(device->addr.address), device->flags);
    378368
     
    824814}
    825815
    826 static int eth_received(eth_device_t *device)
    827 {
    828         void *data;
    829         size_t size;
    830         int rc;
    831        
    832         rc = async_data_write_accept(&data, false, 0, 0, 0, &size);
    833         if (rc != EOK) {
    834                 printf("%s: data_write_accept() failed\n", NAME);
    835                 return rc;
    836         }
    837        
    838         packet_t *packet = packet_get_1_remote(eth_globals.net_sess, size);
    839         if (packet == NULL)
    840                 return ENOMEM;
    841        
    842         void *pdata = packet_suffix(packet, size);
    843         memcpy(pdata, data, size);
    844         free(data);
    845        
    846         return nil_received_msg_local(device->device_id, packet);
    847 }
    848 
    849 static int eth_addr_changed(eth_device_t *device)
     816static int eth_addr_changed(nic_device_id_t device_id)
    850817{
    851818        nic_address_t address;
     
    865832
    866833        fibril_rwlock_write_lock(&eth_globals.devices_lock);
    867 
    868         printf("Device %d changing address from " PRIMAC " to " PRIMAC "\n",
    869                 device->device_id, ARGSMAC(device->addr.address),
    870                 ARGSMAC(address.address));
    871         memcpy(&device->addr, &address, sizeof (nic_address_t));
    872         fibril_rwlock_write_unlock(&eth_globals.devices_lock);
    873 
    874         /* Notify all upper layer modules */
    875         fibril_rwlock_read_lock(&eth_globals.protos_lock);
    876         int index;
    877         for (index = 0; index < eth_protos_count(&eth_globals.protos); index++) {
    878                 eth_proto_t *proto = eth_protos_get_index(&eth_globals.protos, index);
    879                 if (proto->sess != NULL) {
    880                         il_addr_changed_msg(proto->sess, device->device_id,
    881                                         ETH_ADDR, address.address);
    882                 }
    883         }
    884 
    885         fibril_rwlock_read_unlock(&eth_globals.protos_lock);
    886         return EOK;
     834        /* An existing device? */
     835        eth_device_t *device = eth_devices_find(&eth_globals.devices, device_id);
     836        if (device) {
     837                printf("Device %d changing address from " PRIMAC " to " PRIMAC "\n",
     838                        device_id, ARGSMAC(device->addr.address), ARGSMAC(address.address));
     839                memcpy(&device->addr, &address, sizeof (nic_address_t));
     840                fibril_rwlock_write_unlock(&eth_globals.devices_lock);
     841
     842                /* Notify all upper layer modules */
     843                fibril_rwlock_read_lock(&eth_globals.protos_lock);
     844                int index;
     845                for (index = 0; index < eth_protos_count(&eth_globals.protos); index++) {
     846                        eth_proto_t *proto = eth_protos_get_index(&eth_globals.protos, index);
     847                        if (proto->sess != NULL) {
     848                                il_addr_changed_msg(proto->sess, device->device_id,
     849                                                ETH_ADDR, address.address);
     850                        }
     851                }
     852
     853                fibril_rwlock_read_unlock(&eth_globals.protos_lock);
     854                return EOK;
     855        } else {
     856                return ENOENT;
     857        }
    887858}
    888859
     
    950921               
    951922                return EOK;
     923        case NET_NIL_DEVICE_STATE:
     924                nil_device_state_msg_local(IPC_GET_DEVICE(*call), IPC_GET_STATE(*call));
     925                async_answer_0(callid, EOK);
     926                return EOK;
     927        case NET_NIL_RECEIVED:
     928                rc = packet_translate_remote(eth_globals.net_sess, &packet,
     929                    IPC_GET_ARG2(*call));
     930                if (rc == EOK)
     931                        rc = nil_received_msg_local(IPC_GET_ARG1(*call), packet);
     932               
     933                async_answer_0(callid, (sysarg_t) rc);
     934                return rc;
     935        case NET_NIL_ADDR_CHANGED:
     936                rc = eth_addr_changed(IPC_GET_DEVICE(*call));
     937                async_answer_0(callid, (sysarg_t) rc);
     938                return rc;
    952939        }
    953940       
    954941        return ENOTSUP;
    955 }
    956 
    957 static void eth_nic_cb_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    958 {
    959         eth_device_t *device = (eth_device_t *)arg;
    960         int rc;
    961        
    962         async_answer_0(iid, EOK);
    963        
    964         while (true) {
    965                 ipc_call_t call;
    966                 ipc_callid_t callid = async_get_call(&call);
    967                
    968                 if (!IPC_GET_IMETHOD(call))
    969                         break;
    970                
    971                 switch (IPC_GET_IMETHOD(call)) {
    972                 case NIC_EV_DEVICE_STATE:
    973                         rc = eth_device_state(device, IPC_GET_ARG1(call));
    974                         async_answer_0(callid, (sysarg_t) rc);
    975                         break;
    976                 case NIC_EV_RECEIVED:
    977                         rc = eth_received(device);
    978                         async_answer_0(callid, (sysarg_t) rc);
    979                         break;
    980                 case NIC_EV_ADDR_CHANGED:
    981                         rc = eth_addr_changed(device);
    982                         async_answer_0(callid, (sysarg_t) rc);
    983                         break;
    984                 default:
    985                         async_answer_0(callid, ENOTSUP);
    986                 }
    987         }
    988942}
    989943
Note: See TracChangeset for help on using the changeset viewer.