Changes in uspace/drv/nic/e1k/e1k.c [6d8455d:321052f7] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/nic/e1k/e1k.c
r6d8455d r321052f7 52 52 #include <nil_remote.h> 53 53 #include <ops/nic.h> 54 #include <packet_client.h>55 #include <packet_remote.h>56 #include <net/packet_header.h>57 54 #include "e1k.h" 58 55 … … 62 59 63 60 /* Must be power of 8 */ 64 #define E1000_RX_ PACKETS_COUNT 12865 #define E1000_TX_ PACKETS_COUNT 12861 #define E1000_RX_FRAME_COUNT 128 62 #define E1000_TX_FRAME_COUNT 128 66 63 67 64 #define E1000_RECEIVE_ADDRESS 16 68 65 69 /** Maximum sending packetsize */66 /** Maximum sending frame size */ 70 67 #define E1000_MAX_SEND_FRAME_SIZE 2048 71 /** Maximum receiving packetsize */72 #define E1000_MAX_RECEIVE_ PACKET_SIZE 204868 /** Maximum receiving frame size */ 69 #define E1000_MAX_RECEIVE_FRAME_SIZE 2048 73 70 74 71 /** nic_driver_data_t* -> e1000_t* cast */ … … 137 134 void *rx_ring_virt; 138 135 139 /** Packets in rx ring */ 140 packet_t **rx_ring_packets; 136 /** Ring of RX frames, physical address */ 137 void **rx_frame_phys; 138 /** Ring of RX frames, virtual address */ 139 void **rx_frame_virt; 141 140 142 141 /** VLAN tag */ 143 142 uint16_t vlan_tag; 144 143 145 /** Add VLAN tag to packet*/144 /** Add VLAN tag to frame */ 146 145 bool vlan_tag_add; 147 146 … … 477 476 } 478 477 479 /** Get state of acceptance of weird packets478 /** Get state of acceptance of weird frames 480 479 * 481 480 * @param device Device to check … … 495 494 }; 496 495 497 /** Set acceptance of weird packets496 /** Set acceptance of weird frames 498 497 * 499 498 * @param device Device to update … … 679 678 } 680 679 681 /** Disable receiving packets for default address680 /** Disable receiving frames for default address 682 681 * 683 682 * @param e1000 E1000 data structure … … 691 690 } 692 691 693 /** Enable receiving packets for default address692 /** Enable receiving frames for default address 694 693 * 695 694 * @param e1000 E1000 data structure … … 751 750 } 752 751 753 /** Enable accepting of broadcast packets752 /** Enable accepting of broadcast frames 754 753 * 755 754 * @param e1000 E1000 data structure … … 763 762 } 764 763 765 /** Disable accepting of broadcast packets764 /** Disable accepting of broadcast frames 766 765 * 767 766 * @param e1000 E1000 data structure … … 799 798 } 800 799 801 /** Set multicast packets acceptance mode800 /** Set multicast frames acceptance mode 802 801 * 803 802 * @param nic NIC device to update … … 853 852 } 854 853 855 /** Set unicast packets acceptance mode854 /** Set unicast frames acceptance mode 856 855 * 857 856 * @param nic NIC device to update … … 911 910 } 912 911 913 /** Set broadcast packets acceptance mode912 /** Set broadcast frames acceptance mode 914 913 * 915 914 * @param nic NIC device to update … … 996 995 if (vlan_mask) { 997 996 /* 998 * Disable receiving, so that packetmatching997 * Disable receiving, so that frame matching 999 998 * partially written VLAN is not received. 1000 999 */ … … 1063 1062 } 1064 1063 1065 /** Fill receive descriptor with new empty packet1066 * 1067 * Store packet in e1000->rx_ring_packets1064 /** Fill receive descriptor with new empty buffer 1065 * 1066 * Store frame in e1000->rx_frame_phys 1068 1067 * 1069 1068 * @param nic NIC data stricture … … 1074 1073 { 1075 1074 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 1076 packet_t *packet = 1077 nic_alloc_packet(nic, E1000_MAX_RECEIVE_PACKET_SIZE); 1078 1079 assert(packet); 1080 1081 *(e1000->rx_ring_packets + offset) = packet; 1075 1082 1076 e1000_rx_descriptor_t *rx_descriptor = (e1000_rx_descriptor_t *) 1083 1077 (e1000->rx_ring_virt + offset * sizeof(e1000_rx_descriptor_t)); 1084 1078 1085 void *phys; 1086 int rc = 1087 nic_dma_lock_packet(packet, E1000_MAX_RECEIVE_PACKET_SIZE, &phys); 1088 1089 if (rc == EOK) 1090 rx_descriptor->phys_addr = PTR_TO_U64(phys + packet->data_start); 1091 else 1092 rx_descriptor->phys_addr = 0; 1093 1079 rx_descriptor->phys_addr = PTR_TO_U64(e1000->rx_frame_phys[offset]); 1094 1080 rx_descriptor->length = 0; 1095 1081 rx_descriptor->checksum = 0; … … 1155 1141 } 1156 1142 1157 /** Receive packets1143 /** Receive frames 1158 1144 * 1159 1145 * @param nic NIC data 1160 1146 * 1161 1147 */ 1162 static void e1000_receive_ packets(nic_t *nic)1148 static void e1000_receive_frames(nic_t *nic) 1163 1149 { 1164 1150 e1000_t *e1000 = DRIVER_DATA_NIC(nic); … … 1167 1153 1168 1154 uint32_t *tail_addr = E1000_REG_ADDR(e1000, E1000_RDT); 1169 uint32_t next_tail = e1000_inc_tail(*tail_addr, E1000_RX_ PACKETS_COUNT);1155 uint32_t next_tail = e1000_inc_tail(*tail_addr, E1000_RX_FRAME_COUNT); 1170 1156 1171 1157 e1000_rx_descriptor_t *rx_descriptor = (e1000_rx_descriptor_t *) … … 1173 1159 1174 1160 while (rx_descriptor->status & 0x01) { 1175 uint32_t packet_size = rx_descriptor->length - E1000_CRC_SIZE;1161 uint32_t frame_size = rx_descriptor->length - E1000_CRC_SIZE; 1176 1162 1177 packet_t *packet = *(e1000->rx_ring_packets + next_tail); 1178 packet_suffix(packet, packet_size); 1179 1180 nic_dma_unlock_packet(packet, E1000_MAX_RECEIVE_PACKET_SIZE); 1181 nic_received_packet(nic, packet); 1163 nic_frame_t *frame = nic_alloc_frame(nic, frame_size); 1164 if (frame != NULL) { 1165 memcpy(frame->data, e1000->rx_frame_virt[next_tail], frame_size); 1166 nic_received_frame(nic, frame); 1167 } else { 1168 ddf_msg(LVL_ERROR, "Memory allocation failed. Frame dropped."); 1169 } 1182 1170 1183 1171 e1000_fill_new_rx_descriptor(nic, next_tail); 1184 1172 1185 *tail_addr = e1000_inc_tail(*tail_addr, E1000_RX_ PACKETS_COUNT);1186 next_tail = e1000_inc_tail(*tail_addr, E1000_RX_ PACKETS_COUNT);1173 *tail_addr = e1000_inc_tail(*tail_addr, E1000_RX_FRAME_COUNT); 1174 next_tail = e1000_inc_tail(*tail_addr, E1000_RX_FRAME_COUNT); 1187 1175 1188 1176 rx_descriptor = (e1000_rx_descriptor_t *) … … 1225 1213 { 1226 1214 if (icr & ICR_RXT0) 1227 e1000_receive_ packets(nic);1215 e1000_receive_frames(nic); 1228 1216 } 1229 1217 … … 1274 1262 } 1275 1263 1276 /** Force receiving all packets in the receive buffer1264 /** Force receiving all frames in the receive buffer 1277 1265 * 1278 1266 * @param nic NIC data … … 1347 1335 static void e1000_initialize_rx_registers(e1000_t *e1000) 1348 1336 { 1349 E1000_REG_WRITE(e1000, E1000_RDLEN, E1000_RX_ PACKETS_COUNT * 16);1337 E1000_REG_WRITE(e1000, E1000_RDLEN, E1000_RX_FRAME_COUNT * 16); 1350 1338 E1000_REG_WRITE(e1000, E1000_RDH, 0); 1351 1339 1352 1340 /* It is not posible to let HW use all descriptors */ 1353 E1000_REG_WRITE(e1000, E1000_RDT, E1000_RX_ PACKETS_COUNT - 1);1341 E1000_REG_WRITE(e1000, E1000_RDT, E1000_RX_FRAME_COUNT - 1); 1354 1342 1355 1343 /* Set Broadcast Enable Bit */ … … 1371 1359 1372 1360 int rc = dmamem_map_anonymous( 1373 E1000_RX_ PACKETS_COUNT * sizeof(e1000_rx_descriptor_t),1361 E1000_RX_FRAME_COUNT * sizeof(e1000_rx_descriptor_t), 1374 1362 AS_AREA_READ | AS_AREA_WRITE, 0, &e1000->rx_ring_phys, 1375 1363 &e1000->rx_ring_virt); … … 1382 1370 (uint32_t) PTR_TO_U64(e1000->rx_ring_phys)); 1383 1371 1384 e1000->rx_ring_packets = 1385 malloc(E1000_RX_PACKETS_COUNT * sizeof(packet_t *)); 1386 // FIXME: Check return value 1387 1372 e1000->rx_frame_phys = 1373 calloc(E1000_RX_FRAME_COUNT, sizeof(void *)); 1374 e1000->rx_frame_virt = 1375 calloc(E1000_RX_FRAME_COUNT, sizeof(void *)); 1376 if (e1000->rx_frame_phys == NULL || e1000->rx_frame_virt == NULL) { 1377 rc = ENOMEM; 1378 goto error; 1379 } 1380 1381 size_t i; 1382 void *frame_virt; 1383 void *frame_phys; 1384 1385 for (i = 0; i < E1000_RX_FRAME_COUNT; i++) { 1386 rc = dmamem_map_anonymous( 1387 E1000_MAX_SEND_FRAME_SIZE, AS_AREA_READ | AS_AREA_WRITE, 1388 0, &frame_phys, &frame_virt); 1389 if (rc != EOK) 1390 goto error; 1391 1392 e1000->rx_frame_virt[i] = frame_virt; 1393 e1000->rx_frame_phys[i] = frame_phys; 1394 } 1395 1396 /* Write descriptor */ 1397 for (i = 0; i < E1000_RX_FRAME_COUNT; i++) 1398 e1000_fill_new_rx_descriptor(nic, i); 1399 1400 e1000_initialize_rx_registers(e1000); 1401 1402 fibril_mutex_unlock(&e1000->rx_lock); 1403 return EOK; 1404 error: 1405 for (i = 0; i < E1000_RX_FRAME_COUNT; i++) { 1406 if (e1000->rx_frame_virt[i] != NULL) { 1407 dmamem_unmap_anonymous(e1000->rx_frame_virt[i]); 1408 e1000->rx_frame_virt[i] = NULL; 1409 e1000->rx_frame_phys[i] = NULL; 1410 } 1411 } 1412 if (e1000->rx_frame_phys != NULL) { 1413 free(e1000->rx_frame_phys); 1414 e1000->rx_frame_phys = NULL; 1415 } 1416 if (e1000->rx_frame_virt != NULL) { 1417 free(e1000->rx_frame_virt); 1418 e1000->rx_frame_phys = NULL; 1419 } 1420 return rc; 1421 } 1422 1423 /** Uninitialize receive structure 1424 * 1425 * @param nic NIC data 1426 * 1427 */ 1428 static void e1000_uninitialize_rx_structure(nic_t *nic) 1429 { 1430 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 1431 1432 /* Write descriptor */ 1433 for (unsigned int offset = 0; offset < E1000_RX_FRAME_COUNT; offset++) { 1434 dmamem_unmap_anonymous(e1000->rx_frame_virt[offset]); 1435 e1000->rx_frame_virt[offset] = NULL; 1436 e1000->rx_frame_phys[offset] = NULL; 1437 } 1438 1439 free(e1000->rx_frame_virt); 1440 free(e1000->rx_frame_phys); 1441 e1000->rx_frame_virt = NULL; 1442 e1000->rx_frame_phys = NULL; 1443 dmamem_unmap_anonymous(e1000->rx_ring_virt); 1444 } 1445 1446 /** Clear receive descriptor ring 1447 * 1448 * @param e1000 E1000 data 1449 * 1450 */ 1451 static void e1000_clear_rx_ring(e1000_t *e1000) 1452 { 1388 1453 /* Write descriptor */ 1389 1454 for (unsigned int offset = 0; 1390 offset < E1000_RX_PACKETS_COUNT; 1391 offset++) 1392 e1000_fill_new_rx_descriptor(nic, offset); 1393 1394 e1000_initialize_rx_registers(e1000); 1395 1396 fibril_mutex_unlock(&e1000->rx_lock); 1397 return EOK; 1398 } 1399 1400 /** Uninitialize receive structure 1401 * 1402 * @param nic NIC data 1403 * 1404 */ 1405 static void e1000_uninitialize_rx_structure(nic_t *nic) 1406 { 1407 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 1408 1409 /* Write descriptor */ 1410 for (unsigned int offset = 0; 1411 offset < E1000_RX_PACKETS_COUNT; 1412 offset++) { 1413 packet_t *packet = *(e1000->rx_ring_packets + offset); 1414 nic_dma_unlock_packet(packet, E1000_MAX_RECEIVE_PACKET_SIZE); 1415 nic_release_packet(nic, packet); 1416 } 1417 1418 free(e1000->rx_ring_packets); 1419 dmamem_unmap_anonymous(e1000->rx_ring_virt); 1420 } 1421 1422 /** Clear receive descriptor ring 1423 * 1424 * @param e1000 E1000 data 1425 * 1426 */ 1427 static void e1000_clear_rx_ring(e1000_t *e1000) 1428 { 1429 /* Write descriptor */ 1430 for (unsigned int offset = 0; 1431 offset < E1000_RX_PACKETS_COUNT; 1455 offset < E1000_RX_FRAME_COUNT; 1432 1456 offset++) 1433 1457 e1000_clear_rx_descriptor(e1000, offset); … … 1498 1522 static void e1000_initialize_tx_registers(e1000_t *e1000) 1499 1523 { 1500 E1000_REG_WRITE(e1000, E1000_TDLEN, E1000_TX_ PACKETS_COUNT * 16);1524 E1000_REG_WRITE(e1000, E1000_TDLEN, E1000_TX_FRAME_COUNT * 16); 1501 1525 E1000_REG_WRITE(e1000, E1000_TDH, 0); 1502 1526 E1000_REG_WRITE(e1000, E1000_TDT, 0); … … 1530 1554 1531 1555 int rc = dmamem_map_anonymous( 1532 E1000_TX_ PACKETS_COUNT * sizeof(e1000_tx_descriptor_t),1556 E1000_TX_FRAME_COUNT * sizeof(e1000_tx_descriptor_t), 1533 1557 AS_AREA_READ | AS_AREA_WRITE, 0, &e1000->tx_ring_phys, 1534 1558 &e1000->tx_ring_virt); … … 1537 1561 1538 1562 bzero(e1000->tx_ring_virt, 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 *));1563 E1000_TX_FRAME_COUNT * sizeof(e1000_tx_descriptor_t)); 1564 1565 e1000->tx_frame_phys = calloc(E1000_TX_FRAME_COUNT, sizeof(void *)); 1566 e1000->tx_frame_virt = calloc(E1000_TX_FRAME_COUNT, sizeof(void *)); 1543 1567 1544 1568 if (e1000->tx_frame_phys == NULL || e1000->tx_frame_virt == NULL) { … … 1547 1571 } 1548 1572 1549 for (i = 0; i < E1000_TX_ PACKETS_COUNT; i++) {1573 for (i = 0; i < E1000_TX_FRAME_COUNT; i++) { 1550 1574 rc = dmamem_map_anonymous( 1551 1575 E1000_MAX_SEND_FRAME_SIZE, AS_AREA_READ | AS_AREA_WRITE, … … 1572 1596 1573 1597 if (e1000->tx_frame_phys != NULL && e1000->tx_frame_virt != NULL) { 1574 for (i = 0; i < E1000_TX_ PACKETS_COUNT; i++) {1598 for (i = 0; i < E1000_TX_FRAME_COUNT; i++) { 1575 1599 if (e1000->tx_frame_virt[i] != NULL) { 1576 1600 dmamem_unmap_anonymous(e1000->tx_frame_virt[i]); … … 1603 1627 size_t i; 1604 1628 1605 for (i = 0; i < E1000_TX_ PACKETS_COUNT; i++) {1629 for (i = 0; i < E1000_TX_FRAME_COUNT; i++) { 1606 1630 dmamem_unmap_anonymous(e1000->tx_frame_virt[i]); 1607 1631 e1000->tx_frame_virt[i] = NULL; … … 1630 1654 /* Write descriptor */ 1631 1655 for (unsigned int offset = 0; 1632 offset < E1000_TX_ PACKETS_COUNT;1656 offset < E1000_TX_FRAME_COUNT; 1633 1657 offset++) 1634 1658 e1000_clear_tx_descriptor(nic, offset); … … 1687 1711 } 1688 1712 1689 /** Activate the device to receive and transmit packets1713 /** Activate the device to receive and transmit frames 1690 1714 * 1691 1715 * @param nic NIC driver data … … 2283 2307 2284 2308 if (!descriptor_available) { 2285 /* Packetlost */2309 /* Frame lost */ 2286 2310 fibril_mutex_unlock(&e1000->tx_lock); 2287 2311 return; … … 2312 2336 2313 2337 tdt++; 2314 if (tdt == E1000_TX_ PACKETS_COUNT)2338 if (tdt == E1000_TX_FRAME_COUNT) 2315 2339 tdt = 0; 2316 2340
Note:
See TracChangeset
for help on using the changeset viewer.