Changes in uspace/drv/nic/rtl8139/driver.c [d8da56b:6d8455d] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/nic/rtl8139/driver.c
rd8da56b r6d8455d 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 … … 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 … … 411 412 ddf_msg(LVL_DEBUG, "Sending frame"); 412 413 413 if (size > RTL8139_ FRAME_MAX_LENGTH) {414 if (size > RTL8139_PACKET_MAX_LENGTH) { 414 415 ddf_msg(LVL_ERROR, "Send frame: frame too long, %zu bytes", 415 416 size); … … 436 437 fibril_mutex_unlock(&rtl8139->tx_lock); 437 438 438 /* Get address of the buffer descriptor and framedata */439 /* Get address of the buffer descriptor and packet data */ 439 440 void *tsd = rtl8139->io_port + TSD0 + tx_curr * 4; 440 441 void *buf_addr = rtl8139->tx_buff[tx_curr]; … … 504 505 } 505 506 506 /** Create framestructure from the buffer data507 /** Create packet structure from the buffer data 507 508 * 508 509 * @param nic_data NIC driver data 509 510 * @param rx_buffer The receiver buffer 510 511 * @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);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); 520 521 if (! frame) { 521 ddf_msg(LVL_ERROR, "Can not allocate frame for received frame.");522 ddf_msg(LVL_ERROR, "Can not allocate frame for received packet."); 522 523 return NULL; 523 524 } 524 525 525 void *ret = rtl8139_memcpy_wrapped(frame->data, rx_buffer, frame_start, 526 RxBUF_SIZE, frame_size); 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); 527 535 if (ret == NULL) { 528 536 nic_release_frame(nic_data, frame); … … 560 568 } 561 569 562 /** Receive all frames in queue570 /** Receive all packets in queue 563 571 * 564 572 * @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)573 * @return The linked list of packet_list_t nodes, each containing one packet 574 */ 575 static nic_frame_list_t *rtl8139_packet_receive(nic_t *nic_data) 568 576 { 569 577 rtl8139_t *rtl8139 = nic_get_specific(nic_data); … … 573 581 nic_frame_list_t *frames = nic_alloc_frame_list(); 574 582 if (!frames) 575 ddf_msg(LVL_ERROR, "Can not allocate frame list for received frames.");583 ddf_msg(LVL_ERROR, "Can not allocate frame list for received packets."); 576 584 577 585 void *rx_buffer = rtl8139->rx_buff_virt; … … 597 605 while (!rtl8139_hw_buffer_empty(rtl8139)) { 598 606 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;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 packet header */ 611 uint16_t rcs = (uint16_t) packet_header; 604 612 605 613 if (size == RTL8139_EARLY_SIZE) { 606 /* The framecopying is still in progress, break receiving */614 /* The packet copying is still in progress, break receiving */ 607 615 ddf_msg(LVL_DEBUG, "Early threshold reached, not completely coppied"); 608 616 break; … … 610 618 611 619 /* Check if the header is valid, otherwise we are lost in the buffer */ 612 if (size == 0 || size > RTL8139_ FRAME_MAX_LENGTH) {620 if (size == 0 || size > RTL8139_PACKET_MAX_LENGTH) { 613 621 ddf_msg(LVL_ERROR, "Receiver error -> receiver reset (size: %4"PRIu16", " 614 "header 0x%4"PRIx16". Offset: %zu)", size, frame_header,622 "header 0x%4"PRIx16". Offset: %zu)", size, packet_header, 615 623 rx_offset); 616 624 goto rx_err; … … 621 629 } 622 630 623 cur_read += size + RTL_ FRAME_HEADER_SIZE;631 cur_read += size + RTL_PACKET_HEADER_SIZE; 624 632 if (cur_read > max_read) 625 633 break; 626 634 627 635 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);636 nic_frame_t *frame = rtl8139_read_packet(nic_data, rx_buffer, 637 RxBUF_SIZE, rx_offset + RTL_PACKET_HEADER_SIZE, packet_size); 630 638 631 639 if (frame) … … 634 642 635 643 /* 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 frame644 rx_offset = ALIGN_UP(rx_offset + size + RTL_PACKET_HEADER_SIZE, 4); 645 646 /* Write lesser value to prevent overflow into unread packet 639 647 * (the recomendation from the RealTech rtl8139 programming guide) 640 648 */ … … 719 727 tx_used++; 720 728 721 /* If the framewas sent */729 /* If the packet was sent */ 722 730 if (tsd_value & TSD_TOK) { 723 731 size_t size = REG_GET_VAL(tsd_value, TSD_SIZE); … … 749 757 } 750 758 751 /** Receive all frames from the buffer759 /** Receive all packets from the buffer 752 760 * 753 761 * @param rtl8139 driver private data 754 762 */ 755 static void rtl8139_receive_ frames(nic_t *nic_data)763 static void rtl8139_receive_packets(nic_t *nic_data) 756 764 { 757 765 assert(nic_data); … … 761 769 762 770 fibril_mutex_lock(&rtl8139->rx_lock); 763 nic_frame_list_t *frames = rtl8139_ frame_receive(nic_data);771 nic_frame_list_t *frames = rtl8139_packet_receive(nic_data); 764 772 fibril_mutex_unlock(&rtl8139->rx_lock); 765 773 … … 817 825 } 818 826 819 /* Check transmittion interrupts first to allow transmit next frames827 /* Check transmittion interrupts first to allow transmit next packets 820 828 * sooner 821 829 */ … … 824 832 } 825 833 if (isr & INT_ROK) { 826 rtl8139_receive_ frames(nic_data);834 rtl8139_receive_packets(nic_data); 827 835 } 828 836 if (isr & (INT_RER | INT_RXOVW | INT_FIFOOVW)) { … … 925 933 } 926 934 927 /** Activate the device to receive and transmit frames935 /** Activate the device to receive and transmit packets 928 936 * 929 937 * @param nic_data The nic driver data … … 1205 1213 goto failed; 1206 1214 1207 /* Set default frameacceptance */1215 /* Set default packet acceptance */ 1208 1216 rtl8139->rcr_data.ucast_mask = RTL8139_RCR_UCAST_DEFAULT; 1209 1217 rtl8139->rcr_data.mcast_mask = RTL8139_RCR_MCAST_DEFAULT; 1210 1218 rtl8139->rcr_data.bcast_mask = RTL8139_RCR_BCAST_DEFAULT; 1211 1219 rtl8139->rcr_data.defect_mask = RTL8139_RCR_DEFECT_DEFAULT; 1212 /* Set receiver early treshold to 8/16 of framelength */1220 /* Set receiver early treshold to 8/16 of packet length */ 1213 1221 rtl8139->rcr_data.rcr_base = (0x8 << RCR_ERTH_SHIFT); 1214 1222 … … 1469 1477 }; 1470 1478 1471 /** Check if pause frameoperations are valid in current situation1479 /** Check if pause packet operations are valid in current situation 1472 1480 * 1473 1481 * @param rtl8139 RTL8139 private structure … … 1494 1502 } 1495 1503 1496 /** Get current pause frameconfiguration1504 /** Get current pause packet configuration 1497 1505 * 1498 1506 * Values are filled with NIC_RESULT_NOT_AVAILABLE if the value has no sense in … … 1500 1508 * 1501 1509 * @param[in] fun The DDF structure of the RTL8139 1502 * @param[out] we_send Sign if local constroller sends pause frame1503 * @param[out] we_receive Sign if local constroller receives pause frame1504 * @param[out] time Time filled in pause frames. 0xFFFF in rtl81391510 * @param[out] we_send Sign if local constroller sends pause packets 1511 * @param[out] we_receive Sign if local constroller receives pause packets 1512 * @param[out] time Time filled in pause packets. 0xFFFF in rtl8139 1505 1513 * 1506 1514 * @return EOK if succeed … … 1532 1540 }; 1533 1541 1534 /** Set current pause frameconfiguration1542 /** Set current pause packet configuration 1535 1543 * 1536 1544 * @param fun The DDF structure of the RTL8139 1537 * @param allow_send Sign if local constroller sends pause frame1538 * @param allow_receive Sign if local constroller receives pause frames1545 * @param allow_send Sign if local constroller sends pause packets 1546 * @param allow_receive Sign if local constroller receives pause packets 1539 1547 * @param time Time to use, ignored (not supported by device) 1540 1548 * 1541 * @return EOK if succeed, INVAL if the pause framehas no sence1549 * @return EOK if succeed, INVAL if the pause packet has no sence 1542 1550 */ 1543 1551 static int rtl8139_pause_set(ddf_fun_t *fun, int allow_send, int allow_receive, … … 1788 1796 } 1789 1797 1790 /** Set unicast frames acceptance mode1798 /** Set unicast packets acceptance mode 1791 1799 * 1792 1800 * @param nic_data The nic device to update … … 1846 1854 } 1847 1855 1848 /** Set multicast frames acceptance mode1856 /** Set multicast packets acceptance mode 1849 1857 * 1850 1858 * @param nic_data The nic device to update … … 1891 1899 } 1892 1900 1893 /** Set broadcast frames acceptance mode1901 /** Set broadcast packets acceptance mode 1894 1902 * 1895 1903 * @param nic_data The nic device to update … … 1921 1929 } 1922 1930 1923 /** Get state of acceptance of weird frames1931 /** Get state of acceptance of weird packets 1924 1932 * 1925 1933 * @param[in] device The device to check … … 1943 1951 }; 1944 1952 1945 /** Set acceptance of weird frames1953 /** Set acceptance of weird packets 1946 1954 * 1947 1955 * @param device The device to update … … 2119 2127 } 2120 2128 2121 /** Force receiving all frames in the receive buffer2129 /** Force receiving all packets in the receive buffer 2122 2130 * 2123 2131 * @param device The device to receive
Note:
See TracChangeset
for help on using the changeset viewer.