Changeset cfb79747 in mainline for uspace/drv/nic
- Timestamp:
- 2012-02-14T22:06:15Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a31aad1
- Parents:
- 199112e4 (diff), e10d41a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- uspace/drv/nic
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/nic/e1k/e1k.c
r199112e4 rcfb79747 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 … … 488 487 } 489 488 490 /** Get state of acceptance of weird packets489 /** Get state of acceptance of weird frames 491 490 * 492 491 * @param device Device to check … … 506 505 }; 507 506 508 /** Set acceptance of weird packets507 /** Set acceptance of weird frames 509 508 * 510 509 * @param device Device to update … … 690 689 } 691 690 692 /** Disable receiving packets for default address691 /** Disable receiving frames for default address 693 692 * 694 693 * @param e1000 E1000 data structure … … 702 701 } 703 702 704 /** Enable receiving packets for default address703 /** Enable receiving frames for default address 705 704 * 706 705 * @param e1000 E1000 data structure … … 762 761 } 763 762 764 /** Enable accepting of broadcast packets763 /** Enable accepting of broadcast frames 765 764 * 766 765 * @param e1000 E1000 data structure … … 774 773 } 775 774 776 /** Disable accepting of broadcast packets775 /** Disable accepting of broadcast frames 777 776 * 778 777 * @param e1000 E1000 data structure … … 810 809 } 811 810 812 /** Set multicast packets acceptance mode811 /** Set multicast frames acceptance mode 813 812 * 814 813 * @param nic NIC device to update … … 864 863 } 865 864 866 /** Set unicast packets acceptance mode865 /** Set unicast frames acceptance mode 867 866 * 868 867 * @param nic NIC device to update … … 922 921 } 923 922 924 /** Set broadcast packets acceptance mode923 /** Set broadcast frames acceptance mode 925 924 * 926 925 * @param nic NIC device to update … … 1007 1006 if (vlan_mask) { 1008 1007 /* 1009 * Disable receiving, so that packetmatching1008 * Disable receiving, so that frame matching 1010 1009 * partially written VLAN is not received. 1011 1010 */ … … 1074 1073 } 1075 1074 1076 /** Fill receive descriptor with new empty packet1077 * 1078 * Store packet in e1000->rx_ring_packets1075 /** Fill receive descriptor with new empty buffer 1076 * 1077 * Store frame in e1000->rx_frame_phys 1079 1078 * 1080 1079 * @param nic NIC data stricture … … 1085 1084 { 1086 1085 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 1087 packet_t *packet = 1088 nic_alloc_packet(nic, E1000_MAX_RECEIVE_PACKET_SIZE); 1089 1090 assert(packet); 1091 1092 *(e1000->rx_ring_packets + offset) = packet; 1086 1093 1087 e1000_rx_descriptor_t *rx_descriptor = (e1000_rx_descriptor_t *) 1094 1088 (e1000->rx_ring_virt + offset * sizeof(e1000_rx_descriptor_t)); 1095 1089 1096 void *phys; 1097 int rc = 1098 nic_dma_lock_packet(packet, E1000_MAX_RECEIVE_PACKET_SIZE, &phys); 1099 1100 if (rc == EOK) 1101 rx_descriptor->phys_addr = PTR_TO_U64(phys + packet->data_start); 1102 else 1103 rx_descriptor->phys_addr = 0; 1104 1090 rx_descriptor->phys_addr = PTR_TO_U64(e1000->rx_frame_phys[offset]); 1105 1091 rx_descriptor->length = 0; 1106 1092 rx_descriptor->checksum = 0; … … 1166 1152 } 1167 1153 1168 /** Receive packets1154 /** Receive frames 1169 1155 * 1170 1156 * @param nic NIC data 1171 1157 * 1172 1158 */ 1173 static void e1000_receive_ packets(nic_t *nic)1159 static void e1000_receive_frames(nic_t *nic) 1174 1160 { 1175 1161 e1000_t *e1000 = DRIVER_DATA_NIC(nic); … … 1178 1164 1179 1165 uint32_t *tail_addr = E1000_REG_ADDR(e1000, E1000_RDT); 1180 uint32_t next_tail = e1000_inc_tail(*tail_addr, E1000_RX_ PACKETS_COUNT);1166 uint32_t next_tail = e1000_inc_tail(*tail_addr, E1000_RX_FRAME_COUNT); 1181 1167 1182 1168 e1000_rx_descriptor_t *rx_descriptor = (e1000_rx_descriptor_t *) … … 1184 1170 1185 1171 while (rx_descriptor->status & 0x01) { 1186 uint32_t packet_size = rx_descriptor->length - E1000_CRC_SIZE;1172 uint32_t frame_size = rx_descriptor->length - E1000_CRC_SIZE; 1187 1173 1188 packet_t *packet = *(e1000->rx_ring_packets + next_tail); 1189 packet_suffix(packet, packet_size); 1190 1191 nic_dma_unlock_packet(packet, E1000_MAX_RECEIVE_PACKET_SIZE); 1192 nic_received_packet(nic, packet); 1174 nic_frame_t *frame = nic_alloc_frame(nic, frame_size); 1175 if (frame != NULL) { 1176 memcpy(frame->data, e1000->rx_frame_virt[next_tail], frame_size); 1177 nic_received_frame(nic, frame); 1178 } else { 1179 ddf_msg(LVL_ERROR, "Memory allocation failed. Frame dropped."); 1180 } 1193 1181 1194 1182 e1000_fill_new_rx_descriptor(nic, next_tail); 1195 1183 1196 *tail_addr = e1000_inc_tail(*tail_addr, E1000_RX_ PACKETS_COUNT);1197 next_tail = e1000_inc_tail(*tail_addr, E1000_RX_ PACKETS_COUNT);1184 *tail_addr = e1000_inc_tail(*tail_addr, E1000_RX_FRAME_COUNT); 1185 next_tail = e1000_inc_tail(*tail_addr, E1000_RX_FRAME_COUNT); 1198 1186 1199 1187 rx_descriptor = (e1000_rx_descriptor_t *) … … 1236 1224 { 1237 1225 if (icr & ICR_RXT0) 1238 e1000_receive_ packets(nic);1226 e1000_receive_frames(nic); 1239 1227 } 1240 1228 … … 1286 1274 } 1287 1275 1288 /** Force receiving all packets in the receive buffer1276 /** Force receiving all frames in the receive buffer 1289 1277 * 1290 1278 * @param nic NIC data … … 1359 1347 static void e1000_initialize_rx_registers(e1000_t *e1000) 1360 1348 { 1361 E1000_REG_WRITE(e1000, E1000_RDLEN, E1000_RX_ PACKETS_COUNT * 16);1349 E1000_REG_WRITE(e1000, E1000_RDLEN, E1000_RX_FRAME_COUNT * 16); 1362 1350 E1000_REG_WRITE(e1000, E1000_RDH, 0); 1363 1351 1364 1352 /* It is not posible to let HW use all descriptors */ 1365 E1000_REG_WRITE(e1000, E1000_RDT, E1000_RX_ PACKETS_COUNT - 1);1353 E1000_REG_WRITE(e1000, E1000_RDT, E1000_RX_FRAME_COUNT - 1); 1366 1354 1367 1355 /* Set Broadcast Enable Bit */ … … 1383 1371 1384 1372 int rc = dmamem_map_anonymous( 1385 E1000_RX_ PACKETS_COUNT * sizeof(e1000_rx_descriptor_t),1373 E1000_RX_FRAME_COUNT * sizeof(e1000_rx_descriptor_t), 1386 1374 AS_AREA_READ | AS_AREA_WRITE, 0, &e1000->rx_ring_phys, 1387 1375 &e1000->rx_ring_virt); … … 1394 1382 (uint32_t) PTR_TO_U64(e1000->rx_ring_phys)); 1395 1383 1396 e1000->rx_ring_packets = 1397 malloc(E1000_RX_PACKETS_COUNT * sizeof(packet_t *)); 1398 // FIXME: Check return value 1399 1384 e1000->rx_frame_phys = 1385 calloc(E1000_RX_FRAME_COUNT, sizeof(void *)); 1386 e1000->rx_frame_virt = 1387 calloc(E1000_RX_FRAME_COUNT, sizeof(void *)); 1388 if (e1000->rx_frame_phys == NULL || e1000->rx_frame_virt == NULL) { 1389 rc = ENOMEM; 1390 goto error; 1391 } 1392 1393 size_t i; 1394 void *frame_virt; 1395 void *frame_phys; 1396 1397 for (i = 0; i < E1000_RX_FRAME_COUNT; i++) { 1398 rc = dmamem_map_anonymous( 1399 E1000_MAX_SEND_FRAME_SIZE, AS_AREA_READ | AS_AREA_WRITE, 1400 0, &frame_phys, &frame_virt); 1401 if (rc != EOK) 1402 goto error; 1403 1404 e1000->rx_frame_virt[i] = frame_virt; 1405 e1000->rx_frame_phys[i] = frame_phys; 1406 } 1407 1408 /* Write descriptor */ 1409 for (i = 0; i < E1000_RX_FRAME_COUNT; i++) 1410 e1000_fill_new_rx_descriptor(nic, i); 1411 1412 e1000_initialize_rx_registers(e1000); 1413 1414 fibril_mutex_unlock(&e1000->rx_lock); 1415 return EOK; 1416 1417 error: 1418 for (i = 0; i < E1000_RX_FRAME_COUNT; i++) { 1419 if (e1000->rx_frame_virt[i] != NULL) { 1420 dmamem_unmap_anonymous(e1000->rx_frame_virt[i]); 1421 e1000->rx_frame_virt[i] = NULL; 1422 e1000->rx_frame_phys[i] = NULL; 1423 } 1424 } 1425 1426 if (e1000->rx_frame_phys != NULL) { 1427 free(e1000->rx_frame_phys); 1428 e1000->rx_frame_phys = NULL; 1429 } 1430 1431 if (e1000->rx_frame_virt != NULL) { 1432 free(e1000->rx_frame_virt); 1433 e1000->rx_frame_phys = NULL; 1434 } 1435 1436 return rc; 1437 } 1438 1439 /** Uninitialize receive structure 1440 * 1441 * @param nic NIC data 1442 * 1443 */ 1444 static void e1000_uninitialize_rx_structure(nic_t *nic) 1445 { 1446 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 1447 1448 /* Write descriptor */ 1449 for (unsigned int offset = 0; offset < E1000_RX_FRAME_COUNT; offset++) { 1450 dmamem_unmap_anonymous(e1000->rx_frame_virt[offset]); 1451 e1000->rx_frame_virt[offset] = NULL; 1452 e1000->rx_frame_phys[offset] = NULL; 1453 } 1454 1455 free(e1000->rx_frame_virt); 1456 free(e1000->rx_frame_phys); 1457 e1000->rx_frame_virt = NULL; 1458 e1000->rx_frame_phys = NULL; 1459 dmamem_unmap_anonymous(e1000->rx_ring_virt); 1460 } 1461 1462 /** Clear receive descriptor ring 1463 * 1464 * @param e1000 E1000 data 1465 * 1466 */ 1467 static void e1000_clear_rx_ring(e1000_t *e1000) 1468 { 1400 1469 /* Write descriptor */ 1401 1470 for (unsigned int offset = 0; 1402 offset < E1000_RX_PACKETS_COUNT; 1403 offset++) 1404 e1000_fill_new_rx_descriptor(nic, offset); 1405 1406 e1000_initialize_rx_registers(e1000); 1407 1408 fibril_mutex_unlock(&e1000->rx_lock); 1409 return EOK; 1410 } 1411 1412 /** Uninitialize receive structure 1413 * 1414 * @param nic NIC data 1415 * 1416 */ 1417 static void e1000_uninitialize_rx_structure(nic_t *nic) 1418 { 1419 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 1420 1421 /* Write descriptor */ 1422 for (unsigned int offset = 0; 1423 offset < E1000_RX_PACKETS_COUNT; 1424 offset++) { 1425 packet_t *packet = *(e1000->rx_ring_packets + offset); 1426 nic_dma_unlock_packet(packet, E1000_MAX_RECEIVE_PACKET_SIZE); 1427 nic_release_packet(nic, packet); 1428 } 1429 1430 free(e1000->rx_ring_packets); 1431 dmamem_unmap_anonymous(e1000->rx_ring_virt); 1432 } 1433 1434 /** Clear receive descriptor ring 1435 * 1436 * @param e1000 E1000 data 1437 * 1438 */ 1439 static void e1000_clear_rx_ring(e1000_t *e1000) 1440 { 1441 /* Write descriptor */ 1442 for (unsigned int offset = 0; 1443 offset < E1000_RX_PACKETS_COUNT; 1471 offset < E1000_RX_FRAME_COUNT; 1444 1472 offset++) 1445 1473 e1000_clear_rx_descriptor(e1000, offset); … … 1510 1538 static void e1000_initialize_tx_registers(e1000_t *e1000) 1511 1539 { 1512 E1000_REG_WRITE(e1000, E1000_TDLEN, E1000_TX_ PACKETS_COUNT * 16);1540 E1000_REG_WRITE(e1000, E1000_TDLEN, E1000_TX_FRAME_COUNT * 16); 1513 1541 E1000_REG_WRITE(e1000, E1000_TDH, 0); 1514 1542 E1000_REG_WRITE(e1000, E1000_TDT, 0); … … 1542 1570 1543 1571 int rc = dmamem_map_anonymous( 1544 E1000_TX_ PACKETS_COUNT * sizeof(e1000_tx_descriptor_t),1572 E1000_TX_FRAME_COUNT * sizeof(e1000_tx_descriptor_t), 1545 1573 AS_AREA_READ | AS_AREA_WRITE, 0, &e1000->tx_ring_phys, 1546 1574 &e1000->tx_ring_virt); … … 1549 1577 1550 1578 bzero(e1000->tx_ring_virt, 1551 E1000_TX_ PACKETS_COUNT * sizeof(e1000_tx_descriptor_t));1552 1553 e1000->tx_frame_phys = calloc(E1000_TX_ PACKETS_COUNT, sizeof(void *));1554 e1000->tx_frame_virt = calloc(E1000_TX_ PACKETS_COUNT, sizeof(void *));1579 E1000_TX_FRAME_COUNT * sizeof(e1000_tx_descriptor_t)); 1580 1581 e1000->tx_frame_phys = calloc(E1000_TX_FRAME_COUNT, sizeof(void *)); 1582 e1000->tx_frame_virt = calloc(E1000_TX_FRAME_COUNT, sizeof(void *)); 1555 1583 1556 1584 if (e1000->tx_frame_phys == NULL || e1000->tx_frame_virt == NULL) { … … 1559 1587 } 1560 1588 1561 for (i = 0; i < E1000_TX_ PACKETS_COUNT; i++) {1589 for (i = 0; i < E1000_TX_FRAME_COUNT; i++) { 1562 1590 rc = dmamem_map_anonymous( 1563 1591 E1000_MAX_SEND_FRAME_SIZE, AS_AREA_READ | AS_AREA_WRITE, … … 1584 1612 1585 1613 if (e1000->tx_frame_phys != NULL && e1000->tx_frame_virt != NULL) { 1586 for (i = 0; i < E1000_TX_ PACKETS_COUNT; i++) {1614 for (i = 0; i < E1000_TX_FRAME_COUNT; i++) { 1587 1615 if (e1000->tx_frame_virt[i] != NULL) { 1588 1616 dmamem_unmap_anonymous(e1000->tx_frame_virt[i]); … … 1615 1643 size_t i; 1616 1644 1617 for (i = 0; i < E1000_TX_ PACKETS_COUNT; i++) {1645 for (i = 0; i < E1000_TX_FRAME_COUNT; i++) { 1618 1646 dmamem_unmap_anonymous(e1000->tx_frame_virt[i]); 1619 1647 e1000->tx_frame_virt[i] = NULL; … … 1630 1658 e1000->tx_frame_phys = NULL; 1631 1659 } 1660 1632 1661 dmamem_unmap_anonymous(e1000->tx_ring_virt); 1633 1662 } … … 1642 1671 /* Write descriptor */ 1643 1672 for (unsigned int offset = 0; 1644 offset < E1000_TX_ PACKETS_COUNT;1673 offset < E1000_TX_FRAME_COUNT; 1645 1674 offset++) 1646 1675 e1000_clear_tx_descriptor(nic, offset); … … 1699 1728 } 1700 1729 1701 /** Activate the device to receive and transmit packets1730 /** Activate the device to receive and transmit frames 1702 1731 * 1703 1732 * @param nic NIC driver data … … 2040 2069 case E1000_82545: 2041 2070 case E1000_82546: 2042 case E1000_82572:2043 2071 e1000->info.eerd_start = 0x01; 2044 2072 e1000->info.eerd_done = 0x10; … … 2047 2075 break; 2048 2076 case E1000_82547: 2077 case E1000_82572: 2049 2078 case E1000_80003ES2: 2050 2079 e1000->info.eerd_start = 0x01; … … 2085 2114 int e1000_dev_add(ddf_dev_t *dev) 2086 2115 { 2116 ddf_fun_t *fun; 2087 2117 assert(dev); 2088 2118 … … 2115 2145 e1000_initialize_vlan(e1000); 2116 2146 2117 rc = nic_register_as_ddf_fun(nic, &e1000_dev_ops);2118 if ( rc != EOK)2147 fun = ddf_fun_create(nic_get_ddf_dev(nic), fun_exposed, "port0"); 2148 if (fun == NULL) 2119 2149 goto err_tx_structure; 2150 nic_set_ddf_fun(nic, fun); 2151 fun->ops = &e1000_dev_ops; 2152 fun->driver_data = nic; 2120 2153 2121 2154 rc = e1000_register_int_handler(nic); 2122 2155 if (rc != EOK) 2123 goto err_ tx_structure;2156 goto err_fun_create; 2124 2157 2125 2158 rc = nic_connect_to_services(nic); … … 2144 2177 goto err_rx_structure; 2145 2178 2179 rc = ddf_fun_bind(fun); 2180 if (rc != EOK) 2181 goto err_fun_bind; 2182 2183 rc = ddf_fun_add_to_category(fun, DEVICE_CATEGORY_NIC); 2184 if (rc != EOK) 2185 goto err_add_to_cat; 2186 2146 2187 return EOK; 2147 2188 2189 err_add_to_cat: 2190 ddf_fun_unbind(fun); 2191 err_fun_bind: 2148 2192 err_rx_structure: 2149 2193 e1000_uninitialize_rx_structure(nic); 2150 2194 err_irq: 2151 2195 unregister_interrupt_handler(dev, DRIVER_DATA_DEV(dev)->irq); 2196 err_fun_create: 2197 ddf_fun_destroy(fun); 2198 nic_set_ddf_fun(nic, NULL); 2152 2199 err_tx_structure: 2153 2200 e1000_uninitialize_tx_structure(e1000); … … 2295 2342 2296 2343 if (!descriptor_available) { 2297 /* Packetlost */2344 /* Frame lost */ 2298 2345 fibril_mutex_unlock(&e1000->tx_lock); 2299 2346 return; … … 2324 2371 2325 2372 tdt++; 2326 if (tdt == E1000_TX_ PACKETS_COUNT)2373 if (tdt == E1000_TX_FRAME_COUNT) 2327 2374 tdt = 0; 2328 2375 -
uspace/drv/nic/e1k/e1k.h
r199112e4 rcfb79747 39 39 #include <stdint.h> 40 40 41 /** Ethernet CRC size after packetreceived in rx_descriptor */41 /** Ethernet CRC size after frame received in rx_descriptor */ 42 42 #define E1000_CRC_SIZE 4 43 43 … … 109 109 /** Transmit descriptor COMMAND field bits */ 110 110 typedef enum { 111 TXDESCRIPTOR_COMMAND_VLE = (1 << 6), /**< VLAN PacketEnable */111 TXDESCRIPTOR_COMMAND_VLE = (1 << 6), /**< VLAN frame Enable */ 112 112 TXDESCRIPTOR_COMMAND_RS = (1 << 3), /**< Report Status */ 113 113 TXDESCRIPTOR_COMMAND_IFCS = (1 << 1), /**< Insert FCS */ -
uspace/drv/nic/lo/lo.c
r199112e4 rcfb79747 42 42 #include <async.h> 43 43 #include <nic.h> 44 #include <packet_client.h>45 44 46 45 #define NAME "lo" … … 61 60 static void lo_send_frame(nic_t *nic_data, void *data, size_t size) 62 61 { 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 62 nic_report_send_ok(nic_data, 1, size); 75 nic_received_noneth_ packet(nic_data, packet);63 nic_received_noneth_frame(nic_data, data, size); 76 64 } 77 65 … … 92 80 static int lo_dev_add(ddf_dev_t *dev) 93 81 { 94 nic_t *nic_data = nic_create_and_bind(dev); 95 if (nic_data == NULL) { 82 ddf_fun_t *fun = NULL; 83 bool bound = false; 84 85 nic_t *nic = nic_create_and_bind(dev); 86 if (nic == NULL) { 96 87 printf("%s: Failed to initialize\n", NAME); 97 88 return ENOMEM; 98 89 } 99 90 100 dev->driver_data = nic _data;101 nic_set_send_frame_handler(nic _data, lo_send_frame);91 dev->driver_data = nic; 92 nic_set_send_frame_handler(nic, lo_send_frame); 102 93 103 int rc = nic_connect_to_services(nic _data);94 int rc = nic_connect_to_services(nic); 104 95 if (rc != EOK) { 105 96 printf("%s: Failed to connect to services\n", NAME); 106 nic_unbind_and_destroy(dev); 107 return rc; 97 goto error; 108 98 } 109 99 110 rc = nic_register_as_ddf_fun(nic_data, &lo_dev_ops); 100 fun = ddf_fun_create(nic_get_ddf_dev(nic), fun_exposed, "port0"); 101 if (fun == NULL) { 102 printf("%s: Failed creating function\n", NAME); 103 rc = ENOMEM; 104 goto error; 105 } 106 nic_set_ddf_fun(nic, fun); 107 fun->ops = &lo_dev_ops; 108 fun->driver_data = nic; 109 110 rc = nic_report_address(nic, &lo_addr); 111 111 if (rc != EOK) { 112 printf("%s: Failed to register as DDF function\n", NAME); 113 nic_unbind_and_destroy(dev); 114 return rc; 112 printf("%s: Failed to setup loopback address\n", NAME); 113 goto error; 115 114 } 116 115 117 rc = nic_report_address(nic_data, &lo_addr);116 rc = ddf_fun_bind(fun); 118 117 if (rc != EOK) { 119 printf("%s: Failed to setup loopback address\n", NAME); 120 nic_unbind_and_destroy(dev); 121 return rc; 118 printf("%s: Failed binding function\n", NAME); 119 goto error; 122 120 } 121 bound = true; 122 123 rc = ddf_fun_add_to_category(fun, DEVICE_CATEGORY_NIC); 124 if (rc != EOK) 125 goto error; 123 126 124 127 printf("%s: Adding loopback device '%s'\n", NAME, dev->name); 125 128 return EOK; 129 130 error: 131 if (bound) 132 ddf_fun_unbind(fun); 133 134 if (fun != NULL) 135 ddf_fun_destroy(fun); 136 137 nic_unbind_and_destroy(dev); 138 return rc; 126 139 } 127 140 -
uspace/drv/nic/ne2k/dp8390.c
r199112e4 rcfb79747 59 59 #include <stdio.h> 60 60 #include <libarch/ddi.h> 61 #include <net/packet.h>62 #include <packet_client.h>63 61 #include "dp8390.h" 64 62 … … 76 74 uint8_t status; 77 75 78 /** Pointer to next packet*/76 /** Pointer to next frame */ 79 77 uint8_t next; 80 78 … … 393 391 /* 394 392 * Reset the transmit ring. If we were transmitting a frame, 395 * we pretend that the packetis processed. Higher layers will396 * retransmit if the packetwasn't actually sent.393 * we pretend that the frame is processed. Higher layers will 394 * retransmit if the frame wasn't actually sent. 397 395 */ 398 396 ne2k->sq.dirty = false; … … 448 446 return NULL; 449 447 450 void *buf = packet_suffix(frame->packet, length); 451 bzero(buf, length); 448 bzero(frame->data, length); 452 449 uint8_t last = page + length / DP_PAGE; 453 450 … … 455 452 size_t left = (ne2k->stop_page - page) * DP_PAGE 456 453 - sizeof(recv_header_t); 457 ne2k_download(ne2k, buf, page * DP_PAGE + sizeof(recv_header_t),454 ne2k_download(ne2k, frame->data, page * DP_PAGE + sizeof(recv_header_t), 458 455 left); 459 ne2k_download(ne2k, buf+ left, ne2k->start_page * DP_PAGE,456 ne2k_download(ne2k, frame->data + left, ne2k->start_page * DP_PAGE, 460 457 length - left); 461 458 } else { 462 ne2k_download(ne2k, buf, page * DP_PAGE + sizeof(recv_header_t),459 ne2k_download(ne2k, frame->data, page * DP_PAGE + sizeof(recv_header_t), 463 460 length); 464 461 } … … 541 538 * Update the boundary pointer 542 539 * to the value of the page 543 * prior to the next packetto540 * prior to the next frame to 544 541 * be processed. 545 542 */ … … 584 581 fibril_mutex_lock(&ne2k->sq_mutex); 585 582 if (ne2k->sq.dirty) { 586 /* Prepare the buffer for next packet*/583 /* Prepare the buffer for next frame */ 587 584 ne2k->sq.dirty = false; 588 585 ne2k->sq.size = 0; -
uspace/drv/nic/ne2k/dp8390.h
r199112e4 rcfb79747 264 264 extern void ne2k_send(nic_t *, void *, size_t); 265 265 extern void ne2k_interrupt(nic_t *, uint8_t, uint8_t); 266 extern packet_t *ne2k_alloc_packet(nic_t *, size_t);267 266 268 267 extern void ne2k_set_accept_mcast(ne2k_t *, int); -
uspace/drv/nic/ne2k/ne2k.c
r199112e4 rcfb79747 286 286 /* Note: some frame with previous physical address may slip to NIL here 287 287 * (for a moment the filtering is not exact), but ethernet should be OK with 288 * that. Some packetmay also be lost, but this is not a problem.288 * that. Some frames may also be lost, but this is not a problem. 289 289 */ 290 290 ne2k_set_physical_address((ne2k_t *) nic_get_specific(nic_data), address); … … 363 363 static int ne2k_dev_add(ddf_dev_t *dev) 364 364 { 365 ddf_fun_t *fun; 366 365 367 /* Allocate driver data for the device. */ 366 368 nic_t *nic_data = nic_create_and_bind(dev); … … 396 398 } 397 399 398 rc = nic_ register_as_ddf_fun(nic_data, &ne2k_dev_ops);400 rc = nic_connect_to_services(nic_data); 399 401 if (rc != EOK) { 400 402 ne2k_dev_cleanup(dev); … … 402 404 } 403 405 404 rc = nic_connect_to_services(nic_data);405 if ( rc != EOK) {406 fun = ddf_fun_create(nic_get_ddf_dev(nic_data), fun_exposed, "port0"); 407 if (fun == NULL) { 406 408 ne2k_dev_cleanup(dev); 409 return ENOMEM; 410 } 411 nic_set_ddf_fun(nic_data, fun); 412 fun->ops = &ne2k_dev_ops; 413 fun->driver_data = nic_data; 414 415 rc = ddf_fun_bind(fun); 416 if (rc != EOK) { 417 ddf_fun_destroy(fun); 418 ne2k_dev_cleanup(dev); 419 return rc; 420 } 421 422 rc = ddf_fun_add_to_category(fun, DEVICE_CATEGORY_NIC); 423 if (rc != EOK) { 424 ddf_fun_unbind(fun); 425 ddf_fun_destroy(fun); 407 426 return rc; 408 427 } -
uspace/drv/nic/rtl8139/defs.h
r199112e4 rcfb79747 29 29 /** @file rtl8139_defs.h 30 30 * 31 * Registers, bit positions and masks definition of the RTL8139 network family 32 * cards 33 */ 34 35 #ifndef RTL8139_DEFS_H_INCLUDED_ 36 #define RTL8139_DEFS_H_INCLUDED_ 31 * Registers, bit positions and masks definition 32 * of the RTL8139 network family cards 33 */ 34 35 #ifndef RTL8139_DEFS_H_ 36 #define RTL8139_DEFS_H_ 37 37 38 #include <sys/types.h> 38 39 #include <libarch/ddi.h> 39 40 40 41 /** The size of RTL8139 registers address space */ 42 #define RTL8139_IO_SIZE 256 43 44 /** The maximal transmitted packet length in bytes allowed according to RTL8139 45 * documentation (see SIZE part of TSD documentation) 46 */ 47 #define RTL8139_PACKET_MAX_LENGTH 1792 48 41 /** Size of RTL8139 registers address space */ 42 #define RTL8139_IO_SIZE 256 43 44 /** Maximal transmitted frame length 45 * 46 * Maximal transmitted frame length in bytes 47 * allowed according to the RTL8139 documentation 48 * (see SIZE part of TSD documentation). 49 * 50 */ 51 #define RTL8139_FRAME_MAX_LENGTH 1792 49 52 50 53 /** HW version 51 54 * 52 * as can be detected from HWVERID part of TCR 53 * (Transmit Configuration Register) 54 */ 55 enum rtl8139_version_id { 55 * As can be detected from HWVERID part of TCR 56 * (Transmit Configuration Register). 57 * 58 */ 59 typedef enum { 56 60 RTL8139 = 0, /**< RTL8139 */ 57 61 RTL8139A, /**< RTL8139A */ … … 66 70 RTL8101, /**< RTL8101 */ 67 71 RTL8139_VER_COUNT /**< Count of known RTL versions, the last value */ 68 }; 69 70 extern const char* model_names[RTL8139_VER_COUNT]; 72 } rtl8139_version_id_t; 71 73 72 74 /** Registers of RTL8139 family card offsets from the memory address base */ … … 75 77 MAC0 = IDR0, /**< Alias for IDR0 */ 76 78 77 // 0x 6 - 0x7 reserved79 // 0x06 - 0x07 reserved 78 80 79 81 MAR0 = 0x08, /**< Multicast mask registers 8 1b registers sequence */ … … 94 96 95 97 CR = 0x37, /**< Command register, 1b */ 96 CAPR = 0x38, /**< Current address of packetread, 2b */98 CAPR = 0x38, /**< Current address of frame read, 2b */ 97 99 CBA = 0x3a, /**< Current buffer address, 2b */ 98 100 … … 213 215 pio_write_8(io_base + CR9346, RTL8139_REGS_LOCKED); 214 216 } 217 215 218 /** Allow to change Config0-4 and BMCR register */ 216 219 static inline void rtl8139_regs_unlock(void *io_base) … … 282 285 RCR_MulERINT = 1 << 17, /**< Multiple early interrupt select */ 283 286 284 /** Minimal error packetlength (1 = 8B, 0 = 64B). If AER/AR is set, RER8287 /** Minimal error frame length (1 = 8B, 0 = 64B). If AER/AR is set, RER8 285 288 * is "Don't care" 286 289 */ … … 302 305 303 306 RCR_WRAP = 1 << 7, /**< Rx buffer wrapped */ 304 RCR_ACCEPT_ERROR = 1 << 5, /**< Accept error packet*/305 RCR_ACCEPT_RUNT = 1 << 4, /**< Accept Runt (8-64 bytes) packets */307 RCR_ACCEPT_ERROR = 1 << 5, /**< Accept error frame */ 308 RCR_ACCEPT_RUNT = 1 << 4, /**< Accept Runt (8-64 bytes) frames */ 306 309 RCR_ACCEPT_BROADCAST = 1 << 3, /**< Accept broadcast */ 307 310 RCR_ACCEPT_MULTICAST = 1 << 2, /**< Accept multicast */ 308 311 RCR_ACCEPT_PHYS_MATCH = 1 << 1, /**< Accept device MAC address match */ 309 RCR_ACCEPT_ALL_PHYS = 1 << 0, /**< Accept all packets with312 RCR_ACCEPT_ALL_PHYS = 1 << 0, /**< Accept all frames with 310 313 * phys. desticnation 311 314 */ … … 362 365 ANAR_ACK = (1 << 14), /**< Capability reception acknowledge */ 363 366 ANAR_REMOTE_FAULT = (1 << 13), /**< Remote fault detection capability */ 364 ANAR_PAUSE = (1 << 10), /**< Symetric pause packetcapability */367 ANAR_PAUSE = (1 << 10), /**< Symetric pause frame capability */ 365 368 ANAR_100T4 = (1 << 9), /**< T4, not supported by the device */ 366 369 ANAR_100TX_FD = (1 << 8), /**< 100BASE_TX full duplex */ … … 399 402 CONFIG3_GNT_SELECT = (1 << 7), /**< Gnt select */ 400 403 CONFIG3_PARM_EN = (1 << 6), /**< Parameter enabled (100MBit mode) */ 401 CONFIG3_MAGIC = (1 << 5), /**< WoL Magic packetenable */404 CONFIG3_MAGIC = (1 << 5), /**< WoL Magic frame enable */ 402 405 CONFIG3_LINK_UP = (1 << 4), /**< Wakeup if link is reestablished */ 403 406 CONFIG3_CLKRUN_EN = (1 << 2), /**< CLKRUN enabled */ /* TODO: check what does it mean */ … … 416 419 }; 417 420 418 /** Maximal runt packetsize + 1 */419 #define RTL8139_RUNT_MAX_SIZE 64420 421 /** Bits in packetheader */422 enum rtl8139_ packet_header {421 /** Maximal runt frame size + 1 */ 422 #define RTL8139_RUNT_MAX_SIZE 64 423 424 /** Bits in frame header */ 425 enum rtl8139_frame_header { 423 426 RSR_MAR = (1 << 15), /**< Multicast received */ 424 427 RSR_PAM = (1 << 14), /**< Physical address match */ … … 426 429 427 430 RSR_ISE = (1 << 5), /**< Invalid symbol error, 100BASE-TX only */ 428 RSR_RUNT = (1 << 4), /**< Runt packet(< RTL8139_RUNT_MAX_SIZE bytes) */429 430 RSR_LONG = (1 << 3), /**< Long packet(size > 4k bytes) */431 RSR_RUNT = (1 << 4), /**< Runt frame (< RTL8139_RUNT_MAX_SIZE bytes) */ 432 433 RSR_LONG = (1 << 3), /**< Long frame (size > 4k bytes) */ 431 434 RSR_CRC = (1 << 2), /**< CRC error */ 432 435 RSR_FAE = (1 << 1), /**< Frame alignment error */ 433 RSR_ROK = (1 << 0) /**< Good packetreceived */436 RSR_ROK = (1 << 0) /**< Good frame received */ 434 437 }; 435 438 … … 451 454 */ 452 455 453 APPEND_CRC = 1 << 16, /**< Append CRC at the end of a packet*/456 APPEND_CRC = 1 << 16, /**< Append CRC at the end of a frame */ 454 457 455 458 MXTxDMA_SHIFT = 8, /**< Max. DMA Burst per TxDMA shift, burst = 16^value */ … … 459 462 TX_RETRY_COUNT_SIZE = 4, /**< Retries before aborting size */ 460 463 461 CLEAR_ABORT = 1 << 0 /**< Retransmit aborted packetat the last464 CLEAR_ABORT = 1 << 0 /**< Retransmit aborted frame at the last 462 465 * transmitted descriptor 463 466 */ … … 470 473 471 474 /** Mapping of HW version -> version ID */ 472 struct rtl8139_hwver_map { 473 uint32_t hwverid; 474 enum rtl8139_version_idver_id; /**< appropriate version id */475 struct rtl8139_hwver_map { 476 uint32_t hwverid; /**< HW version value in the register */ 477 rtl8139_version_id_t ver_id; /**< appropriate version id */ 475 478 }; 476 479 477 480 /** Mapping of HW version -> version ID */ 478 481 extern const struct rtl8139_hwver_map rtl8139_versions[RTL8139_VER_COUNT + 1]; 479 480 /** Size in the packet header while copying from RxFIFO to Rx buffer */ 481 #define RTL8139_EARLY_SIZE UINT16_C(0xfff0) 482 /** The only supported pause packet time value */ 483 #define RTL8139_PAUSE_VAL UINT16_C(0xFFFF) 484 485 /** Size of the packet header in front of the received frame */ 486 #define RTL_PACKET_HEADER_SIZE 4 482 extern const char* model_names[RTL8139_VER_COUNT]; 483 484 /** Size in the frame header while copying from RxFIFO to Rx buffer */ 485 #define RTL8139_EARLY_SIZE UINT16_C(0xfff0) 486 487 /** The only supported pause frame time value */ 488 #define RTL8139_PAUSE_VAL UINT16_C(0xFFFF) 489 490 /** Size of the frame header in front of the received frame */ 491 #define RTL_FRAME_HEADER_SIZE 4 487 492 488 493 /** 8k buffer */ -
uspace/drv/nic/rtl8139/driver.c
r199112e4 rcfb79747 39 39 #include <io/log.h> 40 40 #include <nic.h> 41 #include <packet_client.h>42 41 #include <device/pci.h> 43 42 … … 56 55 /** Global mutex for work with shared irq structure */ 57 56 FIBRIL_MUTEX_INITIALIZE(irq_reg_lock); 57 58 58 /** Lock interrupt structure mutex */ 59 #define RTL8139_IRQ_STRUCT_LOCK() fibril_mutex_lock(&irq_reg_lock) 59 #define RTL8139_IRQ_STRUCT_LOCK() \ 60 fibril_mutex_lock(&irq_reg_lock) 61 60 62 /** Unlock interrupt structure mutex */ 61 #define RTL8139_IRQ_STRUCT_UNLOCK() fibril_mutex_unlock(&irq_reg_lock) 63 #define RTL8139_IRQ_STRUCT_UNLOCK() \ 64 fibril_mutex_unlock(&irq_reg_lock) 62 65 63 66 /** PCI clock frequency in kHz */ 64 #define RTL8139_PCI_FREQ_KHZ 3300065 66 #define RTL8139_AUTONEG_CAPS (ETH_AUTONEG_10BASE_T_HALF \67 | ETH_AUTONEG_10BASE_T_FULL | ETH_AUTONEG_100BASE_TX_HALF\68 |ETH_AUTONEG_100BASE_TX_FULL | ETH_AUTONEG_PAUSE_SYMETRIC)67 #define RTL8139_PCI_FREQ_KHZ 33000 68 69 #define RTL8139_AUTONEG_CAPS (ETH_AUTONEG_10BASE_T_HALF | \ 70 ETH_AUTONEG_10BASE_T_FULL | ETH_AUTONEG_100BASE_TX_HALF | \ 71 ETH_AUTONEG_100BASE_TX_FULL | ETH_AUTONEG_PAUSE_SYMETRIC) 69 72 70 73 /** Lock transmitter and receiver data 71 * This function shall be called whenever both transmitter and receiver locking 72 * to force safe lock ordering (deadlock prevention) 73 * 74 * @param rtl8139 RTL8139 private data 74 * 75 * This function shall be called whenever 76 * both transmitter and receiver locking 77 * to force safe lock ordering (deadlock prevention) 78 * 79 * @param rtl8139 RTL8139 private data 80 * 75 81 */ 76 82 inline static void rtl8139_lock_all(rtl8139_t *rtl8139) … … 83 89 /** Unlock transmitter and receiver data 84 90 * 85 * @param rtl8139 RTL8139 private data 91 * @param rtl8139 RTL8139 private data 92 * 86 93 */ 87 94 inline static void rtl8139_unlock_all(rtl8139_t *rtl8139) … … 152 159 } 153 160 154 /** Update the mask of accepted packets in the RCR register according to161 /** Update the mask of accepted frames in the RCR register according to 155 162 * rcr_accept_mode value in rtl8139_t 156 163 * … … 170 177 } 171 178 172 /** Fill the mask of accepted multicast packets in the card registers179 /** Fill the mask of accepted multicast frames in the card registers 173 180 * 174 181 * @param rtl8139 The rtl8139 private data … … 394 401 #define rtl8139_tbuf_busy(tsd) ((pio_read_32(tsd) & TSD_OWN) == 0) 395 402 396 /** Send packetwith the hardware403 /** Send frame with the hardware 397 404 * 398 405 * note: the main_lock is locked when framework calls this function … … 412 419 ddf_msg(LVL_DEBUG, "Sending frame"); 413 420 414 if (size > RTL8139_ PACKET_MAX_LENGTH) {421 if (size > RTL8139_FRAME_MAX_LENGTH) { 415 422 ddf_msg(LVL_ERROR, "Send frame: frame too long, %zu bytes", 416 423 size); … … 437 444 fibril_mutex_unlock(&rtl8139->tx_lock); 438 445 439 /* Get address of the buffer descriptor and packetdata */446 /* Get address of the buffer descriptor and frame data */ 440 447 void *tsd = rtl8139->io_port + TSD0 + tx_curr * 4; 441 448 void *buf_addr = rtl8139->tx_buff[tx_curr]; … … 458 465 pio_write_32(tsd, tsd_value); 459 466 return; 460 467 461 468 err_busy_no_inc: 462 469 err_size: … … 505 512 } 506 513 507 /** Create packetstructure from the buffer data514 /** Create frame structure from the buffer data 508 515 * 509 516 * @param nic_data NIC driver data 510 517 * @param rx_buffer The receiver buffer 511 518 * @param rx_size The buffer size 512 * @param packet_start The offset where packet data start 513 * @param packet_size The size of the packet data 514 * 515 * @return The packet list node (not connected) 516 */ 517 static nic_frame_t *rtl8139_read_packet(nic_t *nic_data, 518 void *rx_buffer, size_t rx_size, size_t packet_start, size_t packet_size) 519 { 520 nic_frame_t *frame = nic_alloc_frame(nic_data, packet_size); 519 * @param frame_start The offset where packet data start 520 * @param frame_size The size of the frame data 521 * 522 * @return The frame list node (not connected) 523 * 524 */ 525 static nic_frame_t *rtl8139_read_frame(nic_t *nic_data, 526 void *rx_buffer, size_t rx_size, size_t frame_start, size_t frame_size) 527 { 528 nic_frame_t *frame = nic_alloc_frame(nic_data, frame_size); 521 529 if (! frame) { 522 ddf_msg(LVL_ERROR, "Can not allocate frame for received packet.");530 ddf_msg(LVL_ERROR, "Can not allocate frame for received frame."); 523 531 return NULL; 524 532 } 525 533 526 void *packet_data = packet_suffix(frame->packet, packet_size); 527 if (!packet_data) { 528 ddf_msg(LVL_ERROR, "Can not get the packet suffix."); 529 nic_release_frame(nic_data, frame); 530 return NULL; 531 } 532 533 void *ret = rtl8139_memcpy_wrapped(packet_data, rx_buffer, packet_start, 534 RxBUF_SIZE, packet_size); 534 void *ret = rtl8139_memcpy_wrapped(frame->data, rx_buffer, frame_start, 535 RxBUF_SIZE, frame_size); 535 536 if (ret == NULL) { 536 537 nic_release_frame(nic_data, frame); … … 568 569 } 569 570 570 /** Receive all packets in queue571 /** Receive all frames in queue 571 572 * 572 573 * @param nic_data The controller data 573 * @return The linked list of packet_list_t nodes, each containing one packet574 */ 575 static nic_frame_list_t *rtl8139_ packet_receive(nic_t *nic_data)574 * @return The linked list of nic_frame_list_t nodes, each containing one frame 575 */ 576 static nic_frame_list_t *rtl8139_frame_receive(nic_t *nic_data) 576 577 { 577 578 rtl8139_t *rtl8139 = nic_get_specific(nic_data); … … 581 582 nic_frame_list_t *frames = nic_alloc_frame_list(); 582 583 if (!frames) 583 ddf_msg(LVL_ERROR, "Can not allocate frame list for received packets.");584 ddf_msg(LVL_ERROR, "Can not allocate frame list for received frames."); 584 585 585 586 void *rx_buffer = rtl8139->rx_buff_virt; … … 605 606 while (!rtl8139_hw_buffer_empty(rtl8139)) { 606 607 void *rx_ptr = rx_buffer + rx_offset % RxBUF_SIZE; 607 uint32_t packet_header = uint32_t_le2host( *((uint32_t*)rx_ptr) );608 uint16_t size = packet_header >> 16;609 uint16_t packet_size = size - RTL8139_CRC_SIZE;610 /* received packet flags in packetheader */611 uint16_t rcs = (uint16_t) packet_header;608 uint32_t frame_header = uint32_t_le2host( *((uint32_t*)rx_ptr) ); 609 uint16_t size = frame_header >> 16; 610 uint16_t frame_size = size - RTL8139_CRC_SIZE; 611 /* received frame flags in frame header */ 612 uint16_t rcs = (uint16_t) frame_header; 612 613 613 614 if (size == RTL8139_EARLY_SIZE) { 614 /* The packetcopying is still in progress, break receiving */615 /* The frame copying is still in progress, break receiving */ 615 616 ddf_msg(LVL_DEBUG, "Early threshold reached, not completely coppied"); 616 617 break; … … 618 619 619 620 /* Check if the header is valid, otherwise we are lost in the buffer */ 620 if (size == 0 || size > RTL8139_ PACKET_MAX_LENGTH) {621 if (size == 0 || size > RTL8139_FRAME_MAX_LENGTH) { 621 622 ddf_msg(LVL_ERROR, "Receiver error -> receiver reset (size: %4"PRIu16", " 622 "header 0x%4"PRIx16". Offset: %zu)", size, packet_header,623 "header 0x%4"PRIx16". Offset: %zu)", size, frame_header, 623 624 rx_offset); 624 625 goto rx_err; … … 629 630 } 630 631 631 cur_read += size + RTL_ PACKET_HEADER_SIZE;632 cur_read += size + RTL_FRAME_HEADER_SIZE; 632 633 if (cur_read > max_read) 633 634 break; 634 635 635 636 if (frames) { 636 nic_frame_t *frame = rtl8139_read_ packet(nic_data, rx_buffer,637 RxBUF_SIZE, rx_offset + RTL_ PACKET_HEADER_SIZE, packet_size);637 nic_frame_t *frame = rtl8139_read_frame(nic_data, rx_buffer, 638 RxBUF_SIZE, rx_offset + RTL_FRAME_HEADER_SIZE, frame_size); 638 639 639 640 if (frame) … … 642 643 643 644 /* Update offset */ 644 rx_offset = ALIGN_UP(rx_offset + size + RTL_ PACKET_HEADER_SIZE, 4);645 646 /* Write lesser value to prevent overflow into unread packet645 rx_offset = ALIGN_UP(rx_offset + size + RTL_FRAME_HEADER_SIZE, 4); 646 647 /* Write lesser value to prevent overflow into unread frame 647 648 * (the recomendation from the RealTech rtl8139 programming guide) 648 649 */ … … 735 736 tx_used++; 736 737 737 /* If the packetwas sent */738 /* If the frame was sent */ 738 739 if (tsd_value & TSD_TOK) { 739 740 size_t size = REG_GET_VAL(tsd_value, TSD_SIZE); … … 765 766 } 766 767 767 /** Receive all packets from the buffer768 /** Receive all frames from the buffer 768 769 * 769 770 * @param rtl8139 driver private data 770 771 */ 771 static void rtl8139_receive_ packets(nic_t *nic_data)772 static void rtl8139_receive_frames(nic_t *nic_data) 772 773 { 773 774 assert(nic_data); … … 777 778 778 779 fibril_mutex_lock(&rtl8139->rx_lock); 779 nic_frame_list_t *frames = rtl8139_ packet_receive(nic_data);780 nic_frame_list_t *frames = rtl8139_frame_receive(nic_data); 780 781 fibril_mutex_unlock(&rtl8139->rx_lock); 781 782 … … 833 834 } 834 835 835 /* Check transmittion interrupts first to allow transmit next packets836 /* Check transmittion interrupts first to allow transmit next frames 836 837 * sooner 837 838 */ … … 840 841 } 841 842 if (isr & INT_ROK) { 842 rtl8139_receive_ packets(nic_data);843 rtl8139_receive_frames(nic_data); 843 844 } 844 845 if (isr & (INT_RER | INT_RXOVW | INT_FIFOOVW)) { … … 942 943 } 943 944 944 /** Activate the device to receive and transmit packets945 /** Activate the device to receive and transmit frames 945 946 * 946 947 * @param nic_data The nic driver data … … 1222 1223 goto failed; 1223 1224 1224 /* Set default packetacceptance */1225 /* Set default frame acceptance */ 1225 1226 rtl8139->rcr_data.ucast_mask = RTL8139_RCR_UCAST_DEFAULT; 1226 1227 rtl8139->rcr_data.mcast_mask = RTL8139_RCR_MCAST_DEFAULT; 1227 1228 rtl8139->rcr_data.bcast_mask = RTL8139_RCR_BCAST_DEFAULT; 1228 1229 rtl8139->rcr_data.defect_mask = RTL8139_RCR_DEFECT_DEFAULT; 1229 /* Set receiver early treshold to 8/16 of packetlength */1230 /* Set receiver early treshold to 8/16 of frame length */ 1230 1231 rtl8139->rcr_data.rcr_base = (0x8 << RCR_ERTH_SHIFT); 1231 1232 1232 1233 ddf_msg(LVL_DEBUG, "The device is initialized"); 1233 1234 return ret; 1234 1235 1235 1236 failed: 1236 1237 ddf_msg(LVL_ERROR, "The device initialization failed"); … … 1297 1298 int rtl8139_dev_add(ddf_dev_t *dev) 1298 1299 { 1300 ddf_fun_t *fun; 1301 1299 1302 assert(dev); 1300 1303 ddf_msg(LVL_NOTE, "RTL8139_dev_add %s (handle = %d)", dev->name, dev->handle); … … 1333 1336 } 1334 1337 1335 rc = nic_register_as_ddf_fun(nic_data, &rtl8139_dev_ops); 1338 fun = ddf_fun_create(nic_get_ddf_dev(nic_data), fun_exposed, "port0"); 1339 if (fun == NULL) { 1340 ddf_msg(LVL_ERROR, "Failed creating device function"); 1341 goto err_srv; 1342 } 1343 nic_set_ddf_fun(nic_data, fun); 1344 fun->ops = &rtl8139_dev_ops; 1345 fun->driver_data = nic_data; 1346 1347 rc = ddf_fun_bind(fun); 1336 1348 if (rc != EOK) { 1337 ddf_msg(LVL_ERROR, "Failed to register as DDF function - error %d", rc); 1338 goto err_irq; 1349 ddf_msg(LVL_ERROR, "Failed binding device function"); 1350 goto err_fun_create; 1351 } 1352 rc = ddf_fun_add_to_category(fun, DEVICE_CATEGORY_NIC); 1353 if (rc != EOK) { 1354 ddf_msg(LVL_ERROR, "Failed adding function to category"); 1355 goto err_fun_bind; 1339 1356 } 1340 1357 … … 1343 1360 1344 1361 return EOK; 1345 1362 1363 err_fun_bind: 1364 ddf_fun_unbind(fun); 1365 err_fun_create: 1366 ddf_fun_destroy(fun); 1367 err_srv: 1368 /* XXX Disconnect from services */ 1346 1369 err_irq: 1347 1370 unregister_interrupt_handler(dev, rtl8139->irq); … … 1486 1509 }; 1487 1510 1488 /** Check if pause packetoperations are valid in current situation1511 /** Check if pause frame operations are valid in current situation 1489 1512 * 1490 1513 * @param rtl8139 RTL8139 private structure … … 1511 1534 } 1512 1535 1513 /** Get current pause packetconfiguration1536 /** Get current pause frame configuration 1514 1537 * 1515 1538 * Values are filled with NIC_RESULT_NOT_AVAILABLE if the value has no sense in … … 1517 1540 * 1518 1541 * @param[in] fun The DDF structure of the RTL8139 1519 * @param[out] we_send Sign if local constroller sends pause packets1520 * @param[out] we_receive Sign if local constroller receives pause packets1521 * @param[out] time Time filled in pause packets. 0xFFFF in rtl81391542 * @param[out] we_send Sign if local constroller sends pause frame 1543 * @param[out] we_receive Sign if local constroller receives pause frame 1544 * @param[out] time Time filled in pause frames. 0xFFFF in rtl8139 1522 1545 * 1523 1546 * @return EOK if succeed … … 1549 1572 }; 1550 1573 1551 /** Set current pause packetconfiguration1574 /** Set current pause frame configuration 1552 1575 * 1553 1576 * @param fun The DDF structure of the RTL8139 1554 * @param allow_send Sign if local constroller sends pause packets1555 * @param allow_receive Sign if local constroller receives pause packets1577 * @param allow_send Sign if local constroller sends pause frame 1578 * @param allow_receive Sign if local constroller receives pause frames 1556 1579 * @param time Time to use, ignored (not supported by device) 1557 1580 * 1558 * @return EOK if succeed, INVAL if the pause packethas no sence1581 * @return EOK if succeed, INVAL if the pause frame has no sence 1559 1582 */ 1560 1583 static int rtl8139_pause_set(ddf_fun_t *fun, int allow_send, int allow_receive, … … 1805 1828 } 1806 1829 1807 /** Set unicast packets acceptance mode1830 /** Set unicast frames acceptance mode 1808 1831 * 1809 1832 * @param nic_data The nic device to update … … 1863 1886 } 1864 1887 1865 /** Set multicast packets acceptance mode1888 /** Set multicast frames acceptance mode 1866 1889 * 1867 1890 * @param nic_data The nic device to update … … 1908 1931 } 1909 1932 1910 /** Set broadcast packets acceptance mode1933 /** Set broadcast frames acceptance mode 1911 1934 * 1912 1935 * @param nic_data The nic device to update … … 1938 1961 } 1939 1962 1940 /** Get state of acceptance of weird packets1963 /** Get state of acceptance of weird frames 1941 1964 * 1942 1965 * @param[in] device The device to check … … 1960 1983 }; 1961 1984 1962 /** Set acceptance of weird packets1985 /** Set acceptance of weird frames 1963 1986 * 1964 1987 * @param device The device to update … … 2136 2159 } 2137 2160 2138 /** Force receiving all packets in the receive buffer2161 /** Force receiving all frames in the receive buffer 2139 2162 * 2140 2163 * @param device The device to receive -
uspace/drv/nic/rtl8139/driver.h
r199112e4 rcfb79747 30 30 #define RTL8139_DRIVER_H_ 31 31 32 #include <sys/types.h> 33 #include <stdint.h> 32 34 #include "defs.h" 33 35 #include "general.h" 34 #include <sys/types.h>35 #include <stdint.h>36 36 37 37 /** The driver name */ 38 #define NAME "rtl8139" 38 #define NAME "rtl8139" 39 39 40 /** Transmittion buffers count */ 40 #define TX_BUFF_COUNT 441 /** Size of buffer for one packet 42 * - 2kB 43 */ 44 #define TX_BUFF_SIZE (2 * 1024) 45 /** Countof pages to allocate for TxBuffers */46 #define TX_PAGES 241 #define TX_BUFF_COUNT 4 42 43 /** Size of buffer for one frame (2kB) */ 44 #define TX_BUFF_SIZE (2 * 1024) 45 46 /** Number of pages to allocate for TxBuffers */ 47 #define TX_PAGES 2 47 48 48 49 /** Size of the CRC after the received frame in the receiver buffer */ 49 #define RTL8139_CRC_SIZE 4 50 51 /** The default mode of accepting unicast packets */ 52 #define RTL8139_RCR_UCAST_DEFAULT RCR_ACCEPT_PHYS_MATCH 53 /** The default mode of accepting multicast packets */ 54 #define RTL8139_RCR_MCAST_DEFAULT 0 55 /** The default mode of accepting broadcast packets */ 56 #define RTL8139_RCR_BCAST_DEFAULT RCR_ACCEPT_BROADCAST 57 /** The default mode of accepting defect packets */ 58 #define RTL8139_RCR_DEFECT_DEFAULT 0 50 #define RTL8139_CRC_SIZE 4 51 52 /** The default mode of accepting unicast frames */ 53 #define RTL8139_RCR_UCAST_DEFAULT RCR_ACCEPT_PHYS_MATCH 54 55 /** The default mode of accepting multicast frames */ 56 #define RTL8139_RCR_MCAST_DEFAULT 0 57 58 /** The default mode of accepting broadcast frames */ 59 #define RTL8139_RCR_BCAST_DEFAULT RCR_ACCEPT_BROADCAST 60 61 /** The default mode of accepting defect frames */ 62 #define RTL8139_RCR_DEFECT_DEFAULT 0 59 63 60 64 /** Mask for accepting all multicast */ 61 #define RTL8139_MCAST_MASK_PROMISC UINT64_MAX62 63 /** Data 65 #define RTL8139_MCAST_MASK_PROMISC UINT64_MAX 66 67 /** Data */ 64 68 struct rtl8139_rcr_data { 65 69 /** Configuration part of RCR */ … … 112 116 size_t tx_used; 113 117 114 /** Buffer for receiving packets */118 /** Buffer for receiving frames */ 115 119 void *rx_buff_phys; 116 120 void *rx_buff_virt; … … 134 138 135 139 /** Version of RT8139 controller */ 136 enum rtl8139_version_idhw_version;140 rtl8139_version_id_t hw_version; 137 141 } rtl8139_t; 138 139 142 140 143 /* ***** Pointers casting - for both amd64 and ia32 ***** */ … … 160 163 */ 161 164 #define IOADDR_TO_PTR(ioaddr) ((void*)((size_t)(ioaddr))) 162 163 164 165 165 166 /* ***** Bit operation macros ***** */ … … 177 178 * @return New value 178 179 */ 179 #define bit_set_part_g( src, value, mask, type) \180 #define bit_set_part_g(src, value, mask, type) \ 180 181 ((type)(((src) & ~((type)(mask))) | ((value) & (type)(mask)))) 181 182 … … 237 238 bit_set_part_32(tsd_value, (size) << TSD_SIZE_SHIFT, TSD_SIZE_MASK << TSD_SIZE_SHIFT) 238 239 239 240 240 #endif -
uspace/drv/nic/rtl8139/general.h
r199112e4 rcfb79747 29 29 /** @file 30 30 * 31 * 31 * General functions and structures used in rtl8139 driver 32 32 */ 33 33 … … 37 37 #include <unistd.h> 38 38 39 extern void* rtl8139_memcpy_wrapped(void *dest, const void *src_buf, 40 size_t src_offset, size_t src_size, size_t data_size); 41 39 /** Number of microseconds in second */ 40 #define RTL8139_USEC_IN_SEC 1000000 42 41 43 42 /** Structure for HW timer control */ 44 typedef struct rtl8139_timer_act{43 typedef struct { 45 44 /** Register value set in the last timer period */ 46 45 uint32_t last_val; 46 47 47 /** Register value set in the common timer period */ 48 48 uint32_t full_val; 49 49 50 50 /** Amount of full register periods in timer period */ 51 51 size_t full_skips; 52 52 53 /** Remaining full register periods to the next period end */ 53 54 size_t full_skips_remains; 55 54 56 /** Mark if there is a last run */ 55 57 int last_run; 56 58 } rtl8139_timer_act_t; 57 59 58 /** Count of microseconds in second */ 59 #define RTL8139_USEC_IN_SEC 1000000 60 61 extern int rtl8139_timer_act_init(rtl8139_timer_act_t *ta, uint32_t timer_freq, 62 const struct timeval *time); 63 extern int rtl8139_timer_act_step(rtl8139_timer_act_t *ta, uint32_t *new_reg); 64 60 extern void *rtl8139_memcpy_wrapped(void *, const void *, size_t, size_t, 61 size_t); 62 extern int rtl8139_timer_act_init(rtl8139_timer_act_t *, uint32_t, 63 const struct timeval *); 64 extern int rtl8139_timer_act_step(rtl8139_timer_act_t *, uint32_t *); 65 65 66 66 #endif
Note:
See TracChangeset
for help on using the changeset viewer.