Changeset a1347a7 in mainline for uspace/drv


Ignore:
Timestamp:
2012-01-15T13:51:09Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
bd79281
Parents:
03e0a244 (diff), f302586 (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

Location:
uspace/drv
Files:
18 added
10 edited
2 moved

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/isa/isa.c

    r03e0a244 ra1347a7  
    5252#include <dirent.h>
    5353#include <fcntl.h>
     54#include <ipc/irc.h>
     55#include <ipc/services.h>
     56#include <sysinfo.h>
     57#include <ns.h>
    5458#include <sys/stat.h>
    5559#include <ipc/irc.h>
     
    109113        sysarg_t apic;
    110114        sysarg_t i8259;
    111        
     115
    112116        async_sess_t *irc_sess = NULL;
    113        
     117
    114118        if (((sysinfo_get_value("apic", &apic) == EOK) && (apic))
    115119            || ((sysinfo_get_value("i8259", &i8259) == EOK) && (i8259))) {
     
    117121                    SERVICE_IRC, 0, 0);
    118122        }
    119        
     123
    120124        if (!irc_sess)
    121125                return false;
    122        
     126
    123127        assert(isa_fun);
    124128        const hw_resource_list_t *res = &isa_fun->hw_resources;
     
    127131                if (res->resources[i].type == INTERRUPT) {
    128132                        const int irq = res->resources[i].res.interrupt.irq;
    129                        
     133
    130134                        async_exch_t *exch = async_exchange_begin(irc_sess);
    131135                        const int rc =
    132136                            async_req_1_0(exch, IRC_ENABLE_INTERRUPT, irq);
    133137                        async_exchange_end(exch);
    134                        
     138
    135139                        if (rc != EOK) {
    136140                                async_hangup(irc_sess);
     
    139143                }
    140144        }
    141        
     145
    142146        async_hangup(irc_sess);
    143147        return true;
     
    397401
    398402        val = skip_spaces(val);
    399         irq = (int)strtol(val, &end, 0x10);
     403        irq = (int)strtol(val, &end, 10);
    400404
    401405        if (val != end)
  • uspace/drv/bus/isa/isa.dev

    r03e0a244 ra1347a7  
    99        io_range 2f8 8
    1010
    11 keyboard:
    12         match 100 isa/keyboard
     11i8042:
     12        match 100 isa/i8042
    1313        irq 1
    14         io_range 060 10
     14        irq 12
     15        io_range 060 5
     16       
    1517
    1618ne2k:
  • uspace/drv/bus/usb/usbhid/mouse/mousedev.c

    r03e0a244 ra1347a7  
    5252#include "../usbhid.h"
    5353
    54 /** Number of simulated arrow-key presses for singel wheel step. */
    55 #define ARROWS_PER_SINGLE_WHEEL 3
    56 
    5754#define NAME "mouse"
    5855
     
    6966
    7067const char *HID_MOUSE_FUN_NAME = "mouse";
    71 const char *HID_MOUSE_WHEEL_FUN_NAME = "mouse-wheel";
    7268const char *HID_MOUSE_CATEGORY = "mouse";
    73 const char *HID_MOUSE_WHEEL_CATEGORY = "keyboard";
    7469
    7570/** Default idle rate for mouses. */
     
    126121
    127122        usb_log_debug("%s: fun->name: %s\n", __FUNCTION__, fun->name);
    128         usb_log_debug("%s: mouse_sess: %p, wheel_sess: %p\n",
    129             __FUNCTION__, mouse_dev->mouse_sess, mouse_dev->wheel_sess);
    130 
    131         async_sess_t **sess_ptr = (fun == mouse_dev->mouse_fun) ?
    132             &mouse_dev->mouse_sess : &mouse_dev->wheel_sess;
     123        usb_log_debug("%s: mouse_sess: %p\n",
     124            __FUNCTION__, mouse_dev->mouse_sess);
    133125
    134126        async_sess_t *sess =
    135127            async_callback_receive_start(EXCHANGE_SERIALIZE, icall);
    136128        if (sess != NULL) {
    137                 if (*sess_ptr == NULL) {
    138                         *sess_ptr = sess;
     129                if (mouse_dev->mouse_sess == NULL) {
     130                        mouse_dev->mouse_sess = sess;
    139131                        usb_log_debug("Console session to %s set ok (%p).\n",
    140132                            fun->name, sess);
     
    144136                            fun->name);
    145137                        async_answer_0(icallid, ELIMIT);
     138                        async_hangup(sess);
    146139                }
    147140        } else {
     
    150143        }
    151144}
    152 
    153 /*----------------------------------------------------------------------------*/
    154 
    155 static void usb_mouse_send_wheel(const usb_mouse_t *mouse_dev, int wheel)
    156 {
    157         unsigned int key = (wheel > 0) ? KC_UP : KC_DOWN;
    158 
    159         if (mouse_dev->wheel_sess == NULL) {
    160                 usb_log_warning(
    161                     "Connection to console not ready, wheel roll discarded.\n");
    162                 return;
    163         }
    164 
    165         const unsigned count =
    166             ((wheel < 0) ? -wheel : wheel) * ARROWS_PER_SINGLE_WHEEL;
    167         for (unsigned i = 0; i < count; i++) {
    168                 /* Send arrow press and release. */
    169                 usb_log_debug2("Sending key %d to the console\n", key);
    170                
    171                 async_exch_t *exch = async_exchange_begin(mouse_dev->wheel_sess);
    172                
    173                 async_msg_4(exch, KBDEV_EVENT, KEY_PRESS, key, 0, 0);
    174                 async_msg_4(exch, KBDEV_EVENT, KEY_RELEASE, key, 0, 0);
    175                
    176                 async_exchange_end(exch);
    177         }
    178 }
    179 
    180 /*----------------------------------------------------------------------------*/
    181 
     145/*----------------------------------------------------------------------------*/
    182146static int get_mouse_axis_move_value(uint8_t rid, usb_hid_report_t *report,
    183147    int32_t usage)
     
    203167        return result;
    204168}
    205 
     169/*----------------------------------------------------------------------------*/
    206170static bool usb_mouse_process_report(usb_hid_dev_t *hid_dev,
    207171    usb_mouse_t *mouse_dev)
     
    221185            &hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_WHEEL);
    222186
    223         if ((shift_x != 0) || (shift_y != 0)) {
     187        if (shift_x || shift_y || wheel) {
    224188                async_exch_t *exch =
    225189                    async_exchange_begin(mouse_dev->mouse_sess);
    226190                if (exch != NULL) {
    227                         async_req_2_0(exch, MOUSEEV_MOVE_EVENT, shift_x, shift_y);
     191                        async_msg_3(exch, MOUSEEV_MOVE_EVENT,
     192                            shift_x, shift_y, wheel);
    228193                        async_exchange_end(exch);
    229194                }
    230195        }
    231 
    232         if (wheel != 0)
    233                 usb_mouse_send_wheel(mouse_dev, wheel);
    234196
    235197        /* Buttons */
     
    341303        mouse->mouse_fun = fun;
    342304
    343         /*
    344          * Special function for acting as keyboard (wheel)
    345          */
    346         usb_log_debug("Creating DDF function %s...\n",
    347                       HID_MOUSE_WHEEL_FUN_NAME);
    348         fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed,
    349             HID_MOUSE_WHEEL_FUN_NAME);
    350         if (fun == NULL) {
    351                 usb_log_error("Could not create DDF function node `%s'.\n",
    352                     HID_MOUSE_WHEEL_FUN_NAME);
    353                 FUN_UNBIND_DESTROY(mouse->mouse_fun);
    354                 mouse->mouse_fun = NULL;
    355                 return ENOMEM;
    356         }
    357 
    358         /*
    359          * Store the initialized HID device and HID ops
    360          * to the DDF function.
    361          */
    362         fun->ops = &mouse->ops;
    363         fun->driver_data = mouse;
    364 
    365         rc = ddf_fun_bind(fun);
    366         if (rc != EOK) {
    367                 usb_log_error("Could not bind DDF function `%s': %s.\n",
    368                     fun->name, str_error(rc));
    369                 FUN_UNBIND_DESTROY(mouse->mouse_fun);
    370                 mouse->mouse_fun = NULL;
    371 
    372                 fun->driver_data = NULL;
    373                 ddf_fun_destroy(fun);
    374                 return rc;
    375         }
    376 
    377         usb_log_debug("Adding DDF function to category %s...\n",
    378             HID_MOUSE_WHEEL_CATEGORY);
    379         rc = ddf_fun_add_to_category(fun, HID_MOUSE_WHEEL_CATEGORY);
    380         if (rc != EOK) {
    381                 usb_log_error(
    382                     "Could not add DDF function to category %s: %s.\n",
    383                     HID_MOUSE_WHEEL_CATEGORY, str_error(rc));
    384 
    385                 FUN_UNBIND_DESTROY(mouse->mouse_fun);
    386                 mouse->mouse_fun = NULL;
    387                 FUN_UNBIND_DESTROY(fun);
    388                 return rc;
    389         }
    390         mouse->wheel_fun = fun;
    391 
    392305        return EOK;
    393306}
    394 
    395 /*----------------------------------------------------------------------------*/
    396 
     307/*----------------------------------------------------------------------------*/
    397308/** Get highest index of a button mentioned in given report.
    398309 *
     
    516427        }
    517428
    518         if (mouse_dev->wheel_sess != NULL) {
    519                 const int ret = async_hangup(mouse_dev->wheel_sess);
    520                 if (ret != EOK)
    521                         usb_log_warning("Failed to hang up wheel session: "
    522                             "%p, %s.\n", mouse_dev->wheel_sess, str_error(ret));
    523         }
    524 
    525429        FUN_UNBIND_DESTROY(mouse_dev->mouse_fun);
    526         FUN_UNBIND_DESTROY(mouse_dev->wheel_fun);
    527430
    528431        free(mouse_dev->buttons);
  • uspace/drv/bus/usb/usbhid/mouse/mousedev.h

    r03e0a244 ra1347a7  
    4848        /** IPC session to console (consumer). */
    4949        async_sess_t *mouse_sess;
    50         async_sess_t *wheel_sess;
    5150
    5251        /* Mouse buttons statuses. */
     
    5756        /* DDF mouse function */
    5857        ddf_fun_t *mouse_fun;
    59         /* DDF mouse function */
    60         ddf_fun_t *wheel_fun;
    6158} usb_mouse_t;
    6259
  • uspace/drv/char/i8042/Makefile

    r03e0a244 ra1347a7  
    2828#
    2929
    30 USPACE_PREFIX = ../../../..
     30USPACE_PREFIX = ../../..
     31LIBS = $(LIBDRV_PREFIX)/libdrv.a
     32EXTRA_CFLAGS += -I$(LIBDRV_PREFIX)/include
    3133BINARY = i8042
    3234
    3335SOURCES = \
    34         i8042.c
     36        i8042.c \
     37        main.c
    3538
    3639include $(USPACE_PREFIX)/Makefile.common
  • uspace/drv/char/ps2mouse/chardev.h

    r03e0a244 ra1347a7  
    11/*
    2  * Copyright (c) 2006 Josef Cejka
     2 * Copyright (c) 2011 Jan Vesely
    33 * All rights reserved.
    44 *
     
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 
    29 /** @addtogroup kbd_port
    30  * @ingroup  kbd
     28/** @addtogroup drvmouse
    3129 * @{
    3230 */
    33 
    3431/** @file
    35  * @brief i8042 port driver.
     32 * @brief ps/2 mouse driver.
    3633 */
    3734
    38 #ifndef i8042_H_
    39 #define i8042_H_
     35#ifndef _CHARDEV_H_
     36#define _CHARDEV_H_
    4037
    41 #include <sys/types.h>
    42 #include <libarch/ddi.h>
     38#include <libarch/types.h>
    4339#include <async.h>
    4440
    45 /** i8042 HW I/O interface */
    46 struct i8042 {
    47         ioport8_t data;
    48         uint8_t pad[3];
    49         ioport8_t status;
    50 } __attribute__ ((packed));
    51 typedef struct i8042 i8042_t;
    52 
    53 /** Softstate structure, one for each serial port (primary and aux). */
    54 typedef struct {
    55         service_id_t service_id;
    56         async_sess_t *client_sess;
    57 } i8042_port_t;
     41ssize_t chardev_read(async_exch_t *, void *, size_t);
     42ssize_t chardev_write(async_exch_t *, const void *, size_t);
    5843
    5944#endif
    60 
    6145/**
    6246 * @}
  • uspace/drv/nic/e1k/e1k.c

    r03e0a244 ra1347a7  
    6767#define E1000_RECEIVE_ADDRESS  16
    6868
     69/** Maximum sending packet size */
     70#define E1000_MAX_SEND_FRAME_SIZE  2048
    6971/** Maximum receiving packet size */
    7072#define E1000_MAX_RECEIVE_PACKET_SIZE  2048
     
    125127        void *tx_ring_virt;
    126128       
    127         /** Packets in tx ring  */
    128         packet_t **tx_ring_packets;
     129        /** Ring of TX frames, physical address */
     130        void **tx_frame_phys;
     131        /** Ring of TX frames, virtual address */
     132        void **tx_frame_virt;
    129133       
    130134        /** Physical rx ring address */
     
    223227static int e1000_on_activating(nic_t *);
    224228static int e1000_on_stopping(nic_t *);
    225 static void e1000_write_packet(nic_t *, packet_t *);
     229static void e1000_send_frame(nic_t *, void *, size_t);
    226230
    227231/** Commands to deal with interrupt
     
    11261130            (e1000->tx_ring_virt + offset * sizeof(e1000_tx_descriptor_t));
    11271131       
    1128         if (tx_descriptor->length) {
    1129                 packet_t *old_packet = *(e1000->tx_ring_packets + offset);
    1130                 if (old_packet)
    1131                         nic_release_packet(nic, old_packet);
    1132         }
    1133        
    11341132        tx_descriptor->phys_addr = 0;
    11351133        tx_descriptor->length = 0;
     
    15221520static int e1000_initialize_tx_structure(e1000_t *e1000)
    15231521{
     1522        size_t i;
     1523       
    15241524        fibril_mutex_lock(&e1000->tx_lock);
     1525       
     1526        e1000->tx_ring_phys = NULL;
     1527        e1000->tx_ring_virt = NULL;
     1528        e1000->tx_frame_phys = NULL;
     1529        e1000->tx_frame_virt = NULL;
    15251530       
    15261531        int rc = dmamem_map_anonymous(
     
    15291534            &e1000->tx_ring_virt);
    15301535        if (rc != EOK)
    1531                 return rc;
     1536                goto error;
    15321537       
    15331538        bzero(e1000->tx_ring_virt,
    15341539            E1000_TX_PACKETS_COUNT * sizeof(e1000_tx_descriptor_t));
     1540       
     1541        e1000->tx_frame_phys = calloc(E1000_TX_PACKETS_COUNT, sizeof(void *));
     1542        e1000->tx_frame_virt = calloc(E1000_TX_PACKETS_COUNT, sizeof(void *));
     1543
     1544        if (e1000->tx_frame_phys == NULL || e1000->tx_frame_virt == NULL) {
     1545                rc = ENOMEM;
     1546                goto error;
     1547        }
     1548       
     1549        for (i = 0; i < E1000_TX_PACKETS_COUNT; i++) {
     1550                rc = dmamem_map_anonymous(
     1551                    E1000_MAX_SEND_FRAME_SIZE, AS_AREA_READ | AS_AREA_WRITE,
     1552                    0, &e1000->tx_frame_phys[i], &e1000->tx_frame_virt[i]);
     1553                if (rc != EOK)
     1554                        goto error;
     1555        }
    15351556       
    15361557        E1000_REG_WRITE(e1000, E1000_TDBAH,
     
    15391560            (uint32_t) PTR_TO_U64(e1000->tx_ring_phys));
    15401561       
    1541         e1000->tx_ring_packets =
    1542             malloc(E1000_TX_PACKETS_COUNT * sizeof(packet_t *));
    1543         // FIXME: Check return value
    1544        
    15451562        e1000_initialize_tx_registers(e1000);
    15461563       
    15471564        fibril_mutex_unlock(&e1000->tx_lock);
    15481565        return EOK;
     1566       
     1567error:
     1568        if (e1000->tx_ring_virt != NULL) {
     1569                dmamem_unmap_anonymous(e1000->tx_ring_virt);
     1570                e1000->tx_ring_virt = NULL;
     1571        }
     1572       
     1573        if (e1000->tx_frame_phys != NULL && e1000->tx_frame_virt != NULL) {
     1574                for (i = 0; i < E1000_TX_PACKETS_COUNT; i++) {
     1575                        if (e1000->tx_frame_virt[i] != NULL) {
     1576                                dmamem_unmap_anonymous(e1000->tx_frame_virt[i]);
     1577                                e1000->tx_frame_virt[i] = NULL;
     1578                                e1000->tx_frame_phys[i] = NULL;
     1579                        }
     1580                }
     1581        }
     1582       
     1583        if (e1000->tx_frame_phys != NULL) {
     1584                free(e1000->tx_frame_phys);
     1585                e1000->tx_frame_phys = NULL;
     1586        }
     1587       
     1588        if (e1000->tx_frame_virt != NULL) {
     1589                free(e1000->tx_frame_virt);
     1590                e1000->tx_frame_phys = NULL;
     1591        }
     1592       
     1593        return rc;
    15491594}
    15501595
     
    15561601static void e1000_uninitialize_tx_structure(e1000_t *e1000)
    15571602{
    1558         free(e1000->tx_ring_packets);
     1603        size_t i;
     1604       
     1605        for (i = 0; i < E1000_TX_PACKETS_COUNT; i++) {
     1606                dmamem_unmap_anonymous(e1000->tx_frame_virt[i]);
     1607                e1000->tx_frame_virt[i] = NULL;
     1608                e1000->tx_frame_phys[i] = NULL;
     1609        }
     1610       
     1611        if (e1000->tx_frame_phys != NULL) {
     1612                free(e1000->tx_frame_phys);
     1613                e1000->tx_frame_phys = NULL;
     1614        }
     1615       
     1616        if (e1000->tx_frame_virt != NULL) {
     1617                free(e1000->tx_frame_virt);
     1618                e1000->tx_frame_phys = NULL;
     1619        }
    15591620        dmamem_unmap_anonymous(e1000->tx_ring_virt);
    15601621}
     
    17711832       
    17721833        nic_set_specific(nic, e1000);
    1773         nic_set_write_packet_handler(nic, e1000_write_packet);
     1834        nic_set_send_frame_handler(nic, e1000_send_frame);
    17741835        nic_set_state_change_handlers(nic, e1000_on_activating,
    17751836            e1000_on_down, e1000_on_stopping);
     
    21902251}
    21912252
    2192 /** Send packet
     2253/** Send frame
    21932254 *
    21942255 * @param nic    NIC driver data structure
    2195  * @param packet Packet to send
     2256 * @param data   Frame data
     2257 * @param size   Frame size in bytes
    21962258 *
    21972259 * @return EOK if succeed
     
    21992261 *
    22002262 */
    2201 static void e1000_write_packet(nic_t *nic, packet_t *packet)
     2263static void e1000_send_frame(nic_t *nic, void *data, size_t size)
    22022264{
    22032265        assert(nic);
     
    22172279       
    22182280        /* Descriptor done */
    2219         if (tx_descriptor_addr->status & TXDESCRIPTOR_STATUS_DD) {
     2281        if (tx_descriptor_addr->status & TXDESCRIPTOR_STATUS_DD)
    22202282                descriptor_available = true;
    2221                 packet_t *old_packet = *(e1000->tx_ring_packets + tdt);
    2222                 if (old_packet) {
    2223                         size_t old_packet_size = packet_get_data_length(old_packet);
    2224                         nic_dma_unlock_packet(old_packet, old_packet_size);
    2225                         nic_release_packet(nic, old_packet);
    2226                 }
    2227         }
    22282283       
    22292284        if (!descriptor_available) {
     
    22332288        }
    22342289       
    2235         size_t packet_size = packet_get_data_length(packet);
    2236        
    2237         void *phys;
    2238         int rc = nic_dma_lock_packet(packet, packet_size, &phys);
    2239         if (rc != EOK) {
    2240                 fibril_mutex_unlock(&e1000->tx_lock);
    2241                 return;
    2242         }
    2243        
    2244         *(e1000->tx_ring_packets + tdt) = packet;
    2245        
    2246         tx_descriptor_addr->phys_addr =
    2247             PTR_TO_U64(phys + packet->data_start);
    2248         tx_descriptor_addr->length = packet_size;
     2290        memcpy(e1000->tx_frame_virt[tdt], data, size);
     2291       
     2292        tx_descriptor_addr->phys_addr = PTR_TO_U64(e1000->tx_frame_phys[tdt]);
     2293        tx_descriptor_addr->length = size;
    22492294       
    22502295        /*
  • uspace/drv/nic/lo/lo.c

    r03e0a244 ra1347a7  
    5959};
    6060
    61 static void lo_write_packet(nic_t *nic_data, packet_t *packet)
     61static void lo_send_frame(nic_t *nic_data, void *data, size_t size)
    6262{
    63         nic_report_send_ok(nic_data, 1, packet_get_data_length(packet));
     63        packet_t *packet;
     64        int rc;
     65
     66        packet = nic_alloc_packet(nic_data, size);
     67        if (packet == NULL)
     68                return;
     69
     70        rc = packet_copy_data(packet, data, size);
     71        if (rc != EOK)
     72                return;
     73
     74        nic_report_send_ok(nic_data, 1, size);
    6475        nic_received_noneth_packet(nic_data, packet);
    6576}
     
    8899       
    89100        dev->driver_data = nic_data;
    90         nic_set_write_packet_handler(nic_data, lo_write_packet);
     101        nic_set_send_frame_handler(nic_data, lo_send_frame);
    91102       
    92103        int rc = nic_connect_to_services(nic_data);
  • uspace/drv/nic/ne2k/dp8390.c

    r03e0a244 ra1347a7  
    404404 *
    405405 * @param[in,out] ne2k   Network interface structure.
    406  * @param[in]     packet Frame to be sent.
    407  *
    408  */
    409 void ne2k_send(nic_t *nic_data, packet_t *packet)
     406 * @param[in]     data   Pointer to frame data
     407 * @param[in]     size   Frame size in bytes
     408 *
     409 */
     410void ne2k_send(nic_t *nic_data, void *data, size_t size)
    410411{
    411412        ne2k_t *ne2k = (ne2k_t *) nic_get_specific(nic_data);
     
    419420                fibril_condvar_wait(&ne2k->sq_cv, &ne2k->sq_mutex);
    420421        }
    421         void *buf = packet_get_data(packet);
    422         size_t size = packet_get_data_length(packet);
    423422       
    424423        if ((size < ETH_MIN_PACK_SIZE) || (size > ETH_MAX_PACK_SIZE_TAGGED)) {
     
    428427
    429428        /* Upload the frame to the ethernet card */
    430         ne2k_upload(ne2k, buf, ne2k->sq.page * DP_PAGE, size);
     429        ne2k_upload(ne2k, data, ne2k->sq.page * DP_PAGE, size);
    431430        ne2k->sq.dirty = true;
    432431        ne2k->sq.size = size;
     
    438437        pio_write_8(ne2k->port + DP_CR, CR_TXP | CR_STA);
    439438        fibril_mutex_unlock(&ne2k->sq_mutex);
    440 
    441         /* Relase packet */
    442         nic_release_packet(nic_data, packet);
    443439}
    444440
  • uspace/drv/nic/ne2k/dp8390.h

    r03e0a244 ra1347a7  
    262262extern int ne2k_up(ne2k_t *);
    263263extern void ne2k_down(ne2k_t *);
    264 extern void ne2k_send(nic_t *, packet_t *);
     264extern void ne2k_send(nic_t *, void *, size_t);
    265265extern void ne2k_interrupt(nic_t *, uint8_t, uint8_t);
    266266extern packet_t *ne2k_alloc_packet(nic_t *, size_t);
  • uspace/drv/nic/ne2k/ne2k.c

    r03e0a244 ra1347a7  
    343343                return ENOMEM;
    344344       
    345         nic_set_write_packet_handler(nic_data, ne2k_send);
     345        nic_set_send_frame_handler(nic_data, ne2k_send);
    346346        nic_set_state_change_handlers(nic_data,
    347347                ne2k_on_activating, NULL, ne2k_on_stopping);
  • uspace/drv/nic/rtl8139/driver.c

    r03e0a244 ra1347a7  
    389389static int rtl8139_on_activated(nic_t *nic_data);
    390390static int rtl8139_on_stopped(nic_t *nic_data);
    391 static void rtl8139_write_packet(nic_t *nic_data, packet_t *packet);
     391static void rtl8139_send_frame(nic_t *nic_data, void *data, size_t size);
    392392
    393393/** Check if the transmit buffer is busy */
     
    399399 *
    400400 * @param nic_data  The nic driver data structure
    401  * @param packet    The packet to send
     401 * @param data      Frame data
     402 * @param size      Frame size in bytes
    402403 *
    403404 * @return EOK if succeed, error code in the case of error
    404405 */
    405 static void rtl8139_write_packet(nic_t *nic_data, packet_t *packet)
     406static void rtl8139_send_frame(nic_t *nic_data, void *data, size_t size)
    406407{
    407408        assert(nic_data);
     
    409410        rtl8139_t *rtl8139 = nic_get_specific(nic_data);
    410411        assert(rtl8139);
    411         ddf_msg(LVL_DEBUG, "Sending packet");
    412 
    413         /* Get the packet data and check if it can be send */
    414         size_t packet_length = packet_get_data_length(packet);
    415         void *packet_data = packet_get_data(packet);
    416 
    417         assert(packet_data);
    418 
    419         if ((packet_length > RTL8139_PACKET_MAX_LENGTH) || !packet_data) {
    420                 ddf_msg(LVL_ERROR, "Write packet length error: data %p, length %z",
    421                     packet_data, packet_length);
     412        ddf_msg(LVL_DEBUG, "Sending frame");
     413
     414        if (size > RTL8139_PACKET_MAX_LENGTH) {
     415                ddf_msg(LVL_ERROR, "Send frame: frame too long, %zu bytes",
     416                    size);
    422417                nic_report_send_error(rtl8139->nic_data, NIC_SEC_OTHER, 1);
    423418                goto err_size;
    424419        }
    425420
    426         assert((packet_length & TSD_SIZE_MASK) == packet_length);
     421        assert((size & TSD_SIZE_MASK) == size);
    427422
    428423        /* Lock transmitter structure for obtaining next buffer */
     
    449444        assert(!rtl8139_tbuf_busy(tsd));
    450445
    451         /* Write packet data to the buffer, set the size to TSD and clear OWN bit */
    452         memcpy(buf_addr, packet_data, packet_length);
     446        /* Write frame data to the buffer, set the size to TSD and clear OWN bit */
     447        memcpy(buf_addr, data, size);
    453448
    454449        /* Set size of the data to send */
    455450        uint32_t tsd_value = pio_read_32(tsd);
    456         tsd_value = rtl8139_tsd_set_size(tsd_value, packet_length);
     451        tsd_value = rtl8139_tsd_set_size(tsd_value, size);
    457452        pio_write_32(tsd, tsd_value);
    458453
     
    462457        tsd_value &= ~(uint32_t)TSD_OWN;
    463458        pio_write_32(tsd, tsd_value);
    464         nic_release_packet(nic_data, packet);
    465459        return;
    466460
    467461err_busy_no_inc:
    468462err_size:
    469         nic_release_packet(nic_data, packet);
    470463        return;
    471464};
     
    10221015        rtl8139->nic_data = nic_data;
    10231016        nic_set_specific(nic_data, rtl8139);
    1024         nic_set_write_packet_handler(nic_data, rtl8139_write_packet);
     1017        nic_set_send_frame_handler(nic_data, rtl8139_send_frame);
    10251018        nic_set_state_change_handlers(nic_data,
    10261019                rtl8139_on_activated, NULL, rtl8139_on_stopped);
Note: See TracChangeset for help on using the changeset viewer.