Changeset 6d8455d in mainline for uspace/drv/nic


Ignore:
Timestamp:
2012-01-14T11:07:34Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f302586
Parents:
f991b6b
Message:

Eliminate packet_t from sending direction of NIC interface.

Location:
uspace/drv/nic
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/nic/e1k/e1k.c

    rf991b6b r6d8455d  
    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

    rf991b6b r6d8455d  
    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

    rf991b6b r6d8455d  
    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

    rf991b6b r6d8455d  
    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

    rf991b6b r6d8455d  
    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

    rf991b6b r6d8455d  
    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.