Changeset 6d8455d in mainline for uspace/drv/nic
- Timestamp:
- 2012-01-14T11:07:34Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f302586
- Parents:
- f991b6b
- Location:
- uspace/drv/nic
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/nic/e1k/e1k.c
rf991b6b r6d8455d 67 67 #define E1000_RECEIVE_ADDRESS 16 68 68 69 /** Maximum sending packet size */ 70 #define E1000_MAX_SEND_FRAME_SIZE 2048 69 71 /** Maximum receiving packet size */ 70 72 #define E1000_MAX_RECEIVE_PACKET_SIZE 2048 … … 125 127 void *tx_ring_virt; 126 128 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; 129 133 130 134 /** Physical rx ring address */ … … 223 227 static int e1000_on_activating(nic_t *); 224 228 static int e1000_on_stopping(nic_t *); 225 static void e1000_ write_packet(nic_t *, packet_t *);229 static void e1000_send_frame(nic_t *, void *, size_t); 226 230 227 231 /** Commands to deal with interrupt … … 1126 1130 (e1000->tx_ring_virt + offset * sizeof(e1000_tx_descriptor_t)); 1127 1131 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 1134 1132 tx_descriptor->phys_addr = 0; 1135 1133 tx_descriptor->length = 0; … … 1522 1520 static int e1000_initialize_tx_structure(e1000_t *e1000) 1523 1521 { 1522 size_t i; 1523 1524 1524 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; 1525 1530 1526 1531 int rc = dmamem_map_anonymous( … … 1529 1534 &e1000->tx_ring_virt); 1530 1535 if (rc != EOK) 1531 return rc;1536 goto error; 1532 1537 1533 1538 bzero(e1000->tx_ring_virt, 1534 1539 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 } 1535 1556 1536 1557 E1000_REG_WRITE(e1000, E1000_TDBAH, … … 1539 1560 (uint32_t) PTR_TO_U64(e1000->tx_ring_phys)); 1540 1561 1541 e1000->tx_ring_packets =1542 malloc(E1000_TX_PACKETS_COUNT * sizeof(packet_t *));1543 // FIXME: Check return value1544 1545 1562 e1000_initialize_tx_registers(e1000); 1546 1563 1547 1564 fibril_mutex_unlock(&e1000->tx_lock); 1548 1565 return EOK; 1566 1567 error: 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; 1549 1594 } 1550 1595 … … 1556 1601 static void e1000_uninitialize_tx_structure(e1000_t *e1000) 1557 1602 { 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 } 1559 1620 dmamem_unmap_anonymous(e1000->tx_ring_virt); 1560 1621 } … … 1771 1832 1772 1833 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); 1774 1835 nic_set_state_change_handlers(nic, e1000_on_activating, 1775 1836 e1000_on_down, e1000_on_stopping); … … 2190 2251 } 2191 2252 2192 /** Send packet2253 /** Send frame 2193 2254 * 2194 2255 * @param nic NIC driver data structure 2195 * @param packet Packet to send 2256 * @param data Frame data 2257 * @param size Frame size in bytes 2196 2258 * 2197 2259 * @return EOK if succeed … … 2199 2261 * 2200 2262 */ 2201 static void e1000_ write_packet(nic_t *nic, packet_t *packet)2263 static void e1000_send_frame(nic_t *nic, void *data, size_t size) 2202 2264 { 2203 2265 assert(nic); … … 2217 2279 2218 2280 /* Descriptor done */ 2219 if (tx_descriptor_addr->status & TXDESCRIPTOR_STATUS_DD) {2281 if (tx_descriptor_addr->status & TXDESCRIPTOR_STATUS_DD) 2220 2282 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 }2228 2283 2229 2284 if (!descriptor_available) { … … 2233 2288 } 2234 2289 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; 2249 2294 2250 2295 /* -
uspace/drv/nic/lo/lo.c
rf991b6b r6d8455d 59 59 }; 60 60 61 static void lo_ write_packet(nic_t *nic_data, packet_t *packet)61 static void lo_send_frame(nic_t *nic_data, void *data, size_t size) 62 62 { 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); 64 75 nic_received_noneth_packet(nic_data, packet); 65 76 } … … 88 99 89 100 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); 91 102 92 103 int rc = nic_connect_to_services(nic_data); -
uspace/drv/nic/ne2k/dp8390.c
rf991b6b r6d8455d 404 404 * 405 405 * @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 */ 410 void ne2k_send(nic_t *nic_data, void *data, size_t size) 410 411 { 411 412 ne2k_t *ne2k = (ne2k_t *) nic_get_specific(nic_data); … … 419 420 fibril_condvar_wait(&ne2k->sq_cv, &ne2k->sq_mutex); 420 421 } 421 void *buf = packet_get_data(packet);422 size_t size = packet_get_data_length(packet);423 422 424 423 if ((size < ETH_MIN_PACK_SIZE) || (size > ETH_MAX_PACK_SIZE_TAGGED)) { … … 428 427 429 428 /* 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); 431 430 ne2k->sq.dirty = true; 432 431 ne2k->sq.size = size; … … 438 437 pio_write_8(ne2k->port + DP_CR, CR_TXP | CR_STA); 439 438 fibril_mutex_unlock(&ne2k->sq_mutex); 440 441 /* Relase packet */442 nic_release_packet(nic_data, packet);443 439 } 444 440 -
uspace/drv/nic/ne2k/dp8390.h
rf991b6b r6d8455d 262 262 extern int ne2k_up(ne2k_t *); 263 263 extern void ne2k_down(ne2k_t *); 264 extern void ne2k_send(nic_t *, packet_t *);264 extern void ne2k_send(nic_t *, void *, size_t); 265 265 extern void ne2k_interrupt(nic_t *, uint8_t, uint8_t); 266 266 extern packet_t *ne2k_alloc_packet(nic_t *, size_t); -
uspace/drv/nic/ne2k/ne2k.c
rf991b6b r6d8455d 343 343 return ENOMEM; 344 344 345 nic_set_ write_packet_handler(nic_data, ne2k_send);345 nic_set_send_frame_handler(nic_data, ne2k_send); 346 346 nic_set_state_change_handlers(nic_data, 347 347 ne2k_on_activating, NULL, ne2k_on_stopping); -
uspace/drv/nic/rtl8139/driver.c
rf991b6b r6d8455d 389 389 static int rtl8139_on_activated(nic_t *nic_data); 390 390 static int rtl8139_on_stopped(nic_t *nic_data); 391 static void rtl8139_ write_packet(nic_t *nic_data, packet_t *packet);391 static void rtl8139_send_frame(nic_t *nic_data, void *data, size_t size); 392 392 393 393 /** Check if the transmit buffer is busy */ … … 399 399 * 400 400 * @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 402 403 * 403 404 * @return EOK if succeed, error code in the case of error 404 405 */ 405 static void rtl8139_ write_packet(nic_t *nic_data, packet_t *packet)406 static void rtl8139_send_frame(nic_t *nic_data, void *data, size_t size) 406 407 { 407 408 assert(nic_data); … … 409 410 rtl8139_t *rtl8139 = nic_get_specific(nic_data); 410 411 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); 422 417 nic_report_send_error(rtl8139->nic_data, NIC_SEC_OTHER, 1); 423 418 goto err_size; 424 419 } 425 420 426 assert(( packet_length & TSD_SIZE_MASK) == packet_length);421 assert((size & TSD_SIZE_MASK) == size); 427 422 428 423 /* Lock transmitter structure for obtaining next buffer */ … … 449 444 assert(!rtl8139_tbuf_busy(tsd)); 450 445 451 /* Write packetdata 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); 453 448 454 449 /* Set size of the data to send */ 455 450 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); 457 452 pio_write_32(tsd, tsd_value); 458 453 … … 462 457 tsd_value &= ~(uint32_t)TSD_OWN; 463 458 pio_write_32(tsd, tsd_value); 464 nic_release_packet(nic_data, packet);465 459 return; 466 460 467 461 err_busy_no_inc: 468 462 err_size: 469 nic_release_packet(nic_data, packet);470 463 return; 471 464 }; … … 1022 1015 rtl8139->nic_data = nic_data; 1023 1016 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); 1025 1018 nic_set_state_change_handlers(nic_data, 1026 1019 rtl8139_on_activated, NULL, rtl8139_on_stopped);
Note:
See TracChangeset
for help on using the changeset viewer.