Changeset 6d8455d in mainline for uspace/drv/nic/e1k/e1k.c
- Timestamp:
- 2012-01-14T11:07:34Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f302586
- Parents:
- f991b6b
- File:
-
- 1 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 /*
Note:
See TracChangeset
for help on using the changeset viewer.