Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/nic/rtl8139/driver.c

    r6d8455d rf0b74b2  
    389389static int rtl8139_on_activated(nic_t *nic_data);
    390390static int rtl8139_on_stopped(nic_t *nic_data);
    391 static void rtl8139_send_frame(nic_t *nic_data, void *data, size_t size);
     391static void rtl8139_write_packet(nic_t *nic_data, packet_t *packet);
    392392
    393393/** Check if the transmit buffer is busy */
     
    399399 *
    400400 * @param nic_data  The nic driver data structure
    401  * @param data      Frame data
    402  * @param size      Frame size in bytes
     401 * @param packet    The packet to send
    403402 *
    404403 * @return EOK if succeed, error code in the case of error
    405404 */
    406 static void rtl8139_send_frame(nic_t *nic_data, void *data, size_t size)
     405static void rtl8139_write_packet(nic_t *nic_data, packet_t *packet)
    407406{
    408407        assert(nic_data);
     
    410409        rtl8139_t *rtl8139 = nic_get_specific(nic_data);
    411410        assert(rtl8139);
    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);
     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);
    417422                nic_report_send_error(rtl8139->nic_data, NIC_SEC_OTHER, 1);
    418423                goto err_size;
    419424        }
    420425
    421         assert((size & TSD_SIZE_MASK) == size);
     426        assert((packet_length & TSD_SIZE_MASK) == packet_length);
    422427
    423428        /* Lock transmitter structure for obtaining next buffer */
     
    444449        assert(!rtl8139_tbuf_busy(tsd));
    445450
    446         /* Write frame data to the buffer, set the size to TSD and clear OWN bit */
    447         memcpy(buf_addr, data, size);
     451        /* Write packet data to the buffer, set the size to TSD and clear OWN bit */
     452        memcpy(buf_addr, packet_data, packet_length);
    448453
    449454        /* Set size of the data to send */
    450455        uint32_t tsd_value = pio_read_32(tsd);
    451         tsd_value = rtl8139_tsd_set_size(tsd_value, size);
     456        tsd_value = rtl8139_tsd_set_size(tsd_value, packet_length);
    452457        pio_write_32(tsd, tsd_value);
    453458
     
    457462        tsd_value &= ~(uint32_t)TSD_OWN;
    458463        pio_write_32(tsd, tsd_value);
     464        nic_release_packet(nic_data, packet);
    459465        return;
    460466
    461467err_busy_no_inc:
    462468err_size:
     469        nic_release_packet(nic_data, packet);
    463470        return;
    464471};
     
    10151022        rtl8139->nic_data = nic_data;
    10161023        nic_set_specific(nic_data, rtl8139);
    1017         nic_set_send_frame_handler(nic_data, rtl8139_send_frame);
     1024        nic_set_write_packet_handler(nic_data, rtl8139_write_packet);
    10181025        nic_set_state_change_handlers(nic_data,
    10191026                rtl8139_on_activated, NULL, rtl8139_on_stopped);
Note: See TracChangeset for help on using the changeset viewer.