Changes in uspace/drv/nic/rtl8139/driver.c [e86b8f0:f0b74b2] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/nic/rtl8139/driver.c
re86b8f0 rf0b74b2 39 39 #include <io/log.h> 40 40 #include <nic.h> 41 #include <packet_client.h> 41 42 #include <device/pci.h> 42 43 … … 151 152 } 152 153 153 /** Update the mask of accepted frames in the RCR register according to154 /** Update the mask of accepted packets in the RCR register according to 154 155 * rcr_accept_mode value in rtl8139_t 155 156 * … … 169 170 } 170 171 171 /** Fill the mask of accepted multicast frames in the card registers172 /** Fill the mask of accepted multicast packets in the card registers 172 173 * 173 174 * @param rtl8139 The rtl8139 private data … … 388 389 static int rtl8139_on_activated(nic_t *nic_data); 389 390 static int rtl8139_on_stopped(nic_t *nic_data); 390 static void rtl8139_ send_frame(nic_t *nic_data, void *data, size_t size);391 static void rtl8139_write_packet(nic_t *nic_data, packet_t *packet); 391 392 392 393 /** Check if the transmit buffer is busy */ 393 394 #define rtl8139_tbuf_busy(tsd) ((pio_read_32(tsd) & TSD_OWN) == 0) 394 395 395 /** Send framewith the hardware396 /** Send packet with the hardware 396 397 * 397 398 * note: the main_lock is locked when framework calls this function 398 399 * 399 400 * @param nic_data The nic driver data structure 400 * @param data Frame data 401 * @param size Frame size in bytes 401 * @param packet The packet to send 402 402 * 403 403 * @return EOK if succeed, error code in the case of error 404 404 */ 405 static void rtl8139_ send_frame(nic_t *nic_data, void *data, size_t size)405 static void rtl8139_write_packet(nic_t *nic_data, packet_t *packet) 406 406 { 407 407 assert(nic_data); … … 409 409 rtl8139_t *rtl8139 = nic_get_specific(nic_data); 410 410 assert(rtl8139); 411 ddf_msg(LVL_DEBUG, "Sending frame"); 412 413 if (size > RTL8139_FRAME_MAX_LENGTH) { 414 ddf_msg(LVL_ERROR, "Send frame: frame too long, %zu bytes", 415 size); 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); 416 422 nic_report_send_error(rtl8139->nic_data, NIC_SEC_OTHER, 1); 417 423 goto err_size; 418 424 } 419 425 420 assert(( size & TSD_SIZE_MASK) == size);426 assert((packet_length & TSD_SIZE_MASK) == packet_length); 421 427 422 428 /* Lock transmitter structure for obtaining next buffer */ … … 436 442 fibril_mutex_unlock(&rtl8139->tx_lock); 437 443 438 /* Get address of the buffer descriptor and framedata */444 /* Get address of the buffer descriptor and packet data */ 439 445 void *tsd = rtl8139->io_port + TSD0 + tx_curr * 4; 440 446 void *buf_addr = rtl8139->tx_buff[tx_curr]; … … 443 449 assert(!rtl8139_tbuf_busy(tsd)); 444 450 445 /* Write framedata to the buffer, set the size to TSD and clear OWN bit */446 memcpy(buf_addr, data, size);451 /* Write packet data to the buffer, set the size to TSD and clear OWN bit */ 452 memcpy(buf_addr, packet_data, packet_length); 447 453 448 454 /* Set size of the data to send */ 449 455 uint32_t tsd_value = pio_read_32(tsd); 450 tsd_value = rtl8139_tsd_set_size(tsd_value, size);456 tsd_value = rtl8139_tsd_set_size(tsd_value, packet_length); 451 457 pio_write_32(tsd, tsd_value); 452 458 … … 456 462 tsd_value &= ~(uint32_t)TSD_OWN; 457 463 pio_write_32(tsd, tsd_value); 464 nic_release_packet(nic_data, packet); 458 465 return; 459 466 460 467 err_busy_no_inc: 461 468 err_size: 469 nic_release_packet(nic_data, packet); 462 470 return; 463 471 }; … … 504 512 } 505 513 506 /** Create framestructure from the buffer data514 /** Create packet structure from the buffer data 507 515 * 508 516 * @param nic_data NIC driver data 509 517 * @param rx_buffer The receiver buffer 510 518 * @param rx_size The buffer size 511 * @param frame_startThe offset where packet data start512 * @param frame_size The size of the framedata513 * 514 * @return The framelist node (not connected)515 */ 516 static nic_frame_t *rtl8139_read_ frame(nic_t *nic_data,517 void *rx_buffer, size_t rx_size, size_t frame_start, size_t frame_size)518 { 519 nic_frame_t *frame = nic_alloc_frame(nic_data, frame_size);519 * @param packet_start The offset where packet data start 520 * @param packet_size The size of the packet data 521 * 522 * @return The packet list node (not connected) 523 */ 524 static nic_frame_t *rtl8139_read_packet(nic_t *nic_data, 525 void *rx_buffer, size_t rx_size, size_t packet_start, size_t packet_size) 526 { 527 nic_frame_t *frame = nic_alloc_frame(nic_data, packet_size); 520 528 if (! frame) { 521 ddf_msg(LVL_ERROR, "Can not allocate frame for received frame.");529 ddf_msg(LVL_ERROR, "Can not allocate frame for received packet."); 522 530 return NULL; 523 531 } 524 532 525 void *ret = rtl8139_memcpy_wrapped(frame->data, rx_buffer, frame_start, 526 RxBUF_SIZE, frame_size); 533 void *packet_data = packet_suffix(frame->packet, packet_size); 534 if (!packet_data) { 535 ddf_msg(LVL_ERROR, "Can not get the packet suffix."); 536 nic_release_frame(nic_data, frame); 537 return NULL; 538 } 539 540 void *ret = rtl8139_memcpy_wrapped(packet_data, rx_buffer, packet_start, 541 RxBUF_SIZE, packet_size); 527 542 if (ret == NULL) { 528 543 nic_release_frame(nic_data, frame); … … 560 575 } 561 576 562 /** Receive all frames in queue577 /** Receive all packets in queue 563 578 * 564 579 * @param nic_data The controller data 565 * @return The linked list of nic_frame_list_t nodes, each containing one frame566 */ 567 static nic_frame_list_t *rtl8139_ frame_receive(nic_t *nic_data)580 * @return The linked list of packet_list_t nodes, each containing one packet 581 */ 582 static nic_frame_list_t *rtl8139_packet_receive(nic_t *nic_data) 568 583 { 569 584 rtl8139_t *rtl8139 = nic_get_specific(nic_data); … … 573 588 nic_frame_list_t *frames = nic_alloc_frame_list(); 574 589 if (!frames) 575 ddf_msg(LVL_ERROR, "Can not allocate frame list for received frames.");590 ddf_msg(LVL_ERROR, "Can not allocate frame list for received packets."); 576 591 577 592 void *rx_buffer = rtl8139->rx_buff_virt; … … 597 612 while (!rtl8139_hw_buffer_empty(rtl8139)) { 598 613 void *rx_ptr = rx_buffer + rx_offset % RxBUF_SIZE; 599 uint32_t frame_header = uint32_t_le2host( *((uint32_t*)rx_ptr) );600 uint16_t size = frame_header >> 16;601 uint16_t frame_size = size - RTL8139_CRC_SIZE;602 /* received frame flags in frameheader */603 uint16_t rcs = (uint16_t) frame_header;614 uint32_t packet_header = uint32_t_le2host( *((uint32_t*)rx_ptr) ); 615 uint16_t size = packet_header >> 16; 616 uint16_t packet_size = size - RTL8139_CRC_SIZE; 617 /* received packet flags in packet header */ 618 uint16_t rcs = (uint16_t) packet_header; 604 619 605 620 if (size == RTL8139_EARLY_SIZE) { 606 /* The framecopying is still in progress, break receiving */621 /* The packet copying is still in progress, break receiving */ 607 622 ddf_msg(LVL_DEBUG, "Early threshold reached, not completely coppied"); 608 623 break; … … 610 625 611 626 /* Check if the header is valid, otherwise we are lost in the buffer */ 612 if (size == 0 || size > RTL8139_ FRAME_MAX_LENGTH) {627 if (size == 0 || size > RTL8139_PACKET_MAX_LENGTH) { 613 628 ddf_msg(LVL_ERROR, "Receiver error -> receiver reset (size: %4"PRIu16", " 614 "header 0x%4"PRIx16". Offset: %zu)", size, frame_header,629 "header 0x%4"PRIx16". Offset: %zu)", size, packet_header, 615 630 rx_offset); 616 631 goto rx_err; … … 621 636 } 622 637 623 cur_read += size + RTL_ FRAME_HEADER_SIZE;638 cur_read += size + RTL_PACKET_HEADER_SIZE; 624 639 if (cur_read > max_read) 625 640 break; 626 641 627 642 if (frames) { 628 nic_frame_t *frame = rtl8139_read_ frame(nic_data, rx_buffer,629 RxBUF_SIZE, rx_offset + RTL_ FRAME_HEADER_SIZE, frame_size);643 nic_frame_t *frame = rtl8139_read_packet(nic_data, rx_buffer, 644 RxBUF_SIZE, rx_offset + RTL_PACKET_HEADER_SIZE, packet_size); 630 645 631 646 if (frame) … … 634 649 635 650 /* Update offset */ 636 rx_offset = ALIGN_UP(rx_offset + size + RTL_ FRAME_HEADER_SIZE, 4);637 638 /* Write lesser value to prevent overflow into unread frame651 rx_offset = ALIGN_UP(rx_offset + size + RTL_PACKET_HEADER_SIZE, 4); 652 653 /* Write lesser value to prevent overflow into unread packet 639 654 * (the recomendation from the RealTech rtl8139 programming guide) 640 655 */ … … 719 734 tx_used++; 720 735 721 /* If the framewas sent */736 /* If the packet was sent */ 722 737 if (tsd_value & TSD_TOK) { 723 738 size_t size = REG_GET_VAL(tsd_value, TSD_SIZE); … … 749 764 } 750 765 751 /** Receive all frames from the buffer766 /** Receive all packets from the buffer 752 767 * 753 768 * @param rtl8139 driver private data 754 769 */ 755 static void rtl8139_receive_ frames(nic_t *nic_data)770 static void rtl8139_receive_packets(nic_t *nic_data) 756 771 { 757 772 assert(nic_data); … … 761 776 762 777 fibril_mutex_lock(&rtl8139->rx_lock); 763 nic_frame_list_t *frames = rtl8139_ frame_receive(nic_data);778 nic_frame_list_t *frames = rtl8139_packet_receive(nic_data); 764 779 fibril_mutex_unlock(&rtl8139->rx_lock); 765 780 … … 817 832 } 818 833 819 /* Check transmittion interrupts first to allow transmit next frames834 /* Check transmittion interrupts first to allow transmit next packets 820 835 * sooner 821 836 */ … … 824 839 } 825 840 if (isr & INT_ROK) { 826 rtl8139_receive_ frames(nic_data);841 rtl8139_receive_packets(nic_data); 827 842 } 828 843 if (isr & (INT_RER | INT_RXOVW | INT_FIFOOVW)) { … … 925 940 } 926 941 927 /** Activate the device to receive and transmit frames942 /** Activate the device to receive and transmit packets 928 943 * 929 944 * @param nic_data The nic driver data … … 1007 1022 rtl8139->nic_data = nic_data; 1008 1023 nic_set_specific(nic_data, rtl8139); 1009 nic_set_ send_frame_handler(nic_data, rtl8139_send_frame);1024 nic_set_write_packet_handler(nic_data, rtl8139_write_packet); 1010 1025 nic_set_state_change_handlers(nic_data, 1011 1026 rtl8139_on_activated, NULL, rtl8139_on_stopped); … … 1205 1220 goto failed; 1206 1221 1207 /* Set default frameacceptance */1222 /* Set default packet acceptance */ 1208 1223 rtl8139->rcr_data.ucast_mask = RTL8139_RCR_UCAST_DEFAULT; 1209 1224 rtl8139->rcr_data.mcast_mask = RTL8139_RCR_MCAST_DEFAULT; 1210 1225 rtl8139->rcr_data.bcast_mask = RTL8139_RCR_BCAST_DEFAULT; 1211 1226 rtl8139->rcr_data.defect_mask = RTL8139_RCR_DEFECT_DEFAULT; 1212 /* Set receiver early treshold to 8/16 of framelength */1227 /* Set receiver early treshold to 8/16 of packet length */ 1213 1228 rtl8139->rcr_data.rcr_base = (0x8 << RCR_ERTH_SHIFT); 1214 1229 … … 1280 1295 int rtl8139_dev_add(ddf_dev_t *dev) 1281 1296 { 1282 ddf_fun_t *fun;1283 1284 1297 assert(dev); 1285 1298 ddf_msg(LVL_NOTE, "RTL8139_dev_add %s (handle = %d)", dev->name, dev->handle); … … 1318 1331 } 1319 1332 1320 fun = ddf_fun_create(nic_get_ddf_dev(nic_data), fun_exposed, "port0"); 1321 if (fun == NULL) { 1322 ddf_msg(LVL_ERROR, "Failed creating device function"); 1323 goto err_srv; 1324 } 1325 nic_set_ddf_fun(nic_data, fun); 1326 fun->ops = &rtl8139_dev_ops; 1327 fun->driver_data = nic_data; 1328 1329 rc = ddf_fun_bind(fun); 1333 rc = nic_register_as_ddf_fun(nic_data, &rtl8139_dev_ops); 1330 1334 if (rc != EOK) { 1331 ddf_msg(LVL_ERROR, "Failed binding device function"); 1332 goto err_fun_create; 1333 } 1334 rc = ddf_fun_add_to_category(fun, DEVICE_CATEGORY_NIC); 1335 if (rc != EOK) { 1336 ddf_msg(LVL_ERROR, "Failed adding function to category"); 1337 goto err_fun_bind; 1335 ddf_msg(LVL_ERROR, "Failed to register as DDF function - error %d", rc); 1336 goto err_irq; 1338 1337 } 1339 1338 … … 1343 1342 return EOK; 1344 1343 1345 err_fun_bind:1346 ddf_fun_unbind(fun);1347 err_fun_create:1348 ddf_fun_destroy(fun);1349 err_srv:1350 /* XXX Disconnect from services */1351 1344 err_irq: 1352 1345 unregister_interrupt_handler(dev, rtl8139->irq); … … 1491 1484 }; 1492 1485 1493 /** Check if pause frameoperations are valid in current situation1486 /** Check if pause packet operations are valid in current situation 1494 1487 * 1495 1488 * @param rtl8139 RTL8139 private structure … … 1516 1509 } 1517 1510 1518 /** Get current pause frameconfiguration1511 /** Get current pause packet configuration 1519 1512 * 1520 1513 * Values are filled with NIC_RESULT_NOT_AVAILABLE if the value has no sense in … … 1522 1515 * 1523 1516 * @param[in] fun The DDF structure of the RTL8139 1524 * @param[out] we_send Sign if local constroller sends pause frame1525 * @param[out] we_receive Sign if local constroller receives pause frame1526 * @param[out] time Time filled in pause frames. 0xFFFF in rtl81391517 * @param[out] we_send Sign if local constroller sends pause packets 1518 * @param[out] we_receive Sign if local constroller receives pause packets 1519 * @param[out] time Time filled in pause packets. 0xFFFF in rtl8139 1527 1520 * 1528 1521 * @return EOK if succeed … … 1554 1547 }; 1555 1548 1556 /** Set current pause frameconfiguration1549 /** Set current pause packet configuration 1557 1550 * 1558 1551 * @param fun The DDF structure of the RTL8139 1559 * @param allow_send Sign if local constroller sends pause frame1560 * @param allow_receive Sign if local constroller receives pause frames1552 * @param allow_send Sign if local constroller sends pause packets 1553 * @param allow_receive Sign if local constroller receives pause packets 1561 1554 * @param time Time to use, ignored (not supported by device) 1562 1555 * 1563 * @return EOK if succeed, INVAL if the pause framehas no sence1556 * @return EOK if succeed, INVAL if the pause packet has no sence 1564 1557 */ 1565 1558 static int rtl8139_pause_set(ddf_fun_t *fun, int allow_send, int allow_receive, … … 1810 1803 } 1811 1804 1812 /** Set unicast frames acceptance mode1805 /** Set unicast packets acceptance mode 1813 1806 * 1814 1807 * @param nic_data The nic device to update … … 1868 1861 } 1869 1862 1870 /** Set multicast frames acceptance mode1863 /** Set multicast packets acceptance mode 1871 1864 * 1872 1865 * @param nic_data The nic device to update … … 1913 1906 } 1914 1907 1915 /** Set broadcast frames acceptance mode1908 /** Set broadcast packets acceptance mode 1916 1909 * 1917 1910 * @param nic_data The nic device to update … … 1943 1936 } 1944 1937 1945 /** Get state of acceptance of weird frames1938 /** Get state of acceptance of weird packets 1946 1939 * 1947 1940 * @param[in] device The device to check … … 1965 1958 }; 1966 1959 1967 /** Set acceptance of weird frames1960 /** Set acceptance of weird packets 1968 1961 * 1969 1962 * @param device The device to update … … 2141 2134 } 2142 2135 2143 /** Force receiving all frames in the receive buffer2136 /** Force receiving all packets in the receive buffer 2144 2137 * 2145 2138 * @param device The device to receive
Note:
See TracChangeset
for help on using the changeset viewer.