Changeset 1bc35b5 in mainline for uspace/drv/nic/rtl8139
- Timestamp:
- 2012-01-19T08:13:45Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d8da56b
- Parents:
- 3ea725e
- Location:
- uspace/drv/nic/rtl8139
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/nic/rtl8139/defs.h
r3ea725e r1bc35b5 42 42 #define RTL8139_IO_SIZE 256 43 43 44 /** The maximal transmitted packetlength in bytes allowed according to RTL813944 /** The maximal transmitted frame length in bytes allowed according to RTL8139 45 45 * documentation (see SIZE part of TSD documentation) 46 46 */ 47 #define RTL8139_ PACKET_MAX_LENGTH 179247 #define RTL8139_FRAME_MAX_LENGTH 1792 48 48 49 49 … … 94 94 95 95 CR = 0x37, /**< Command register, 1b */ 96 CAPR = 0x38, /**< Current address of packetread, 2b */96 CAPR = 0x38, /**< Current address of frame read, 2b */ 97 97 CBA = 0x3a, /**< Current buffer address, 2b */ 98 98 … … 282 282 RCR_MulERINT = 1 << 17, /**< Multiple early interrupt select */ 283 283 284 /** Minimal error packetlength (1 = 8B, 0 = 64B). If AER/AR is set, RER8284 /** Minimal error frame length (1 = 8B, 0 = 64B). If AER/AR is set, RER8 285 285 * is "Don't care" 286 286 */ … … 302 302 303 303 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 */304 RCR_ACCEPT_ERROR = 1 << 5, /**< Accept error frame */ 305 RCR_ACCEPT_RUNT = 1 << 4, /**< Accept Runt (8-64 bytes) frames */ 306 306 RCR_ACCEPT_BROADCAST = 1 << 3, /**< Accept broadcast */ 307 307 RCR_ACCEPT_MULTICAST = 1 << 2, /**< Accept multicast */ 308 308 RCR_ACCEPT_PHYS_MATCH = 1 << 1, /**< Accept device MAC address match */ 309 RCR_ACCEPT_ALL_PHYS = 1 << 0, /**< Accept all packets with309 RCR_ACCEPT_ALL_PHYS = 1 << 0, /**< Accept all frames with 310 310 * phys. desticnation 311 311 */ … … 362 362 ANAR_ACK = (1 << 14), /**< Capability reception acknowledge */ 363 363 ANAR_REMOTE_FAULT = (1 << 13), /**< Remote fault detection capability */ 364 ANAR_PAUSE = (1 << 10), /**< Symetric pause packetcapability */364 ANAR_PAUSE = (1 << 10), /**< Symetric pause frame capability */ 365 365 ANAR_100T4 = (1 << 9), /**< T4, not supported by the device */ 366 366 ANAR_100TX_FD = (1 << 8), /**< 100BASE_TX full duplex */ … … 399 399 CONFIG3_GNT_SELECT = (1 << 7), /**< Gnt select */ 400 400 CONFIG3_PARM_EN = (1 << 6), /**< Parameter enabled (100MBit mode) */ 401 CONFIG3_MAGIC = (1 << 5), /**< WoL Magic packetenable */401 CONFIG3_MAGIC = (1 << 5), /**< WoL Magic frame enable */ 402 402 CONFIG3_LINK_UP = (1 << 4), /**< Wakeup if link is reestablished */ 403 403 CONFIG3_CLKRUN_EN = (1 << 2), /**< CLKRUN enabled */ /* TODO: check what does it mean */ … … 416 416 }; 417 417 418 /** Maximal runt packetsize + 1 */418 /** Maximal runt frame size + 1 */ 419 419 #define RTL8139_RUNT_MAX_SIZE 64 420 420 421 /** Bits in packetheader */422 enum rtl8139_ packet_header {421 /** Bits in frame header */ 422 enum rtl8139_frame_header { 423 423 RSR_MAR = (1 << 15), /**< Multicast received */ 424 424 RSR_PAM = (1 << 14), /**< Physical address match */ … … 426 426 427 427 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) */428 RSR_RUNT = (1 << 4), /**< Runt frame (< RTL8139_RUNT_MAX_SIZE bytes) */ 429 430 RSR_LONG = (1 << 3), /**< Long frmae (size > 4k bytes) */ 431 431 RSR_CRC = (1 << 2), /**< CRC error */ 432 432 RSR_FAE = (1 << 1), /**< Frame alignment error */ 433 RSR_ROK = (1 << 0) /**< Good packetreceived */433 RSR_ROK = (1 << 0) /**< Good frame received */ 434 434 }; 435 435 … … 451 451 */ 452 452 453 APPEND_CRC = 1 << 16, /**< Append CRC at the end of a packet*/453 APPEND_CRC = 1 << 16, /**< Append CRC at the end of a frame */ 454 454 455 455 MXTxDMA_SHIFT = 8, /**< Max. DMA Burst per TxDMA shift, burst = 16^value */ … … 459 459 TX_RETRY_COUNT_SIZE = 4, /**< Retries before aborting size */ 460 460 461 CLEAR_ABORT = 1 << 0 /**< Retransmit aborted packetat the last461 CLEAR_ABORT = 1 << 0 /**< Retransmit aborted frame at the last 462 462 * transmitted descriptor 463 463 */ … … 478 478 extern const struct rtl8139_hwver_map rtl8139_versions[RTL8139_VER_COUNT + 1]; 479 479 480 /** Size in the packetheader while copying from RxFIFO to Rx buffer */480 /** Size in the frame header while copying from RxFIFO to Rx buffer */ 481 481 #define RTL8139_EARLY_SIZE UINT16_C(0xfff0) 482 /** The only supported pause packettime value */482 /** The only supported pause frame time value */ 483 483 #define RTL8139_PAUSE_VAL UINT16_C(0xFFFF) 484 484 485 /** Size of the packetheader in front of the received frame */486 #define RTL_ PACKET_HEADER_SIZE 4485 /** Size of the frame header in front of the received frame */ 486 #define RTL_FRAME_HEADER_SIZE 4 487 487 488 488 /** 8k buffer */ -
uspace/drv/nic/rtl8139/driver.c
r3ea725e r1bc35b5 39 39 #include <io/log.h> 40 40 #include <nic.h> 41 #include <packet_client.h>41 //#include <packet_client.h> 42 42 #include <device/pci.h> 43 43 … … 152 152 } 153 153 154 /** Update the mask of accepted packets in the RCR register according to154 /** Update the mask of accepted frames in the RCR register according to 155 155 * rcr_accept_mode value in rtl8139_t 156 156 * … … 170 170 } 171 171 172 /** Fill the mask of accepted multicast packets in the card registers172 /** Fill the mask of accepted multicast frames in the card registers 173 173 * 174 174 * @param rtl8139 The rtl8139 private data … … 394 394 #define rtl8139_tbuf_busy(tsd) ((pio_read_32(tsd) & TSD_OWN) == 0) 395 395 396 /** Send packetwith the hardware396 /** Send frame with the hardware 397 397 * 398 398 * note: the main_lock is locked when framework calls this function … … 412 412 ddf_msg(LVL_DEBUG, "Sending frame"); 413 413 414 if (size > RTL8139_ PACKET_MAX_LENGTH) {414 if (size > RTL8139_FRAME_MAX_LENGTH) { 415 415 ddf_msg(LVL_ERROR, "Send frame: frame too long, %zu bytes", 416 416 size); … … 437 437 fibril_mutex_unlock(&rtl8139->tx_lock); 438 438 439 /* Get address of the buffer descriptor and packetdata */439 /* Get address of the buffer descriptor and frame data */ 440 440 void *tsd = rtl8139->io_port + TSD0 + tx_curr * 4; 441 441 void *buf_addr = rtl8139->tx_buff[tx_curr]; … … 505 505 } 506 506 507 /** Create packetstructure from the buffer data507 /** Create frame structure from the buffer data 508 508 * 509 509 * @param nic_data NIC driver data 510 510 * @param rx_buffer The receiver buffer 511 511 * @param rx_size The buffer size 512 * @param packet_startThe offset where packet data start513 * @param packet_size The size of the packetdata514 * 515 * @return The packetlist 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);512 * @param frame_start The offset where packet data start 513 * @param frame_size The size of the frame data 514 * 515 * @return The frame list node (not connected) 516 */ 517 static nic_frame_t *rtl8139_read_frame(nic_t *nic_data, 518 void *rx_buffer, size_t rx_size, size_t frame_start, size_t frame_size) 519 { 520 nic_frame_t *frame = nic_alloc_frame(nic_data, frame_size); 521 521 if (! frame) { 522 ddf_msg(LVL_ERROR, "Can not allocate frame for received packet.");522 ddf_msg(LVL_ERROR, "Can not allocate frame for received frame."); 523 523 return NULL; 524 524 } 525 525 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); 526 void *ret = rtl8139_memcpy_wrapped(frame->data, rx_buffer, frame_start, 527 RxBUF_SIZE, frame_size); 535 528 if (ret == NULL) { 536 529 nic_release_frame(nic_data, frame); … … 568 561 } 569 562 570 /** Receive all packets in queue563 /** Receive all frames in queue 571 564 * 572 565 * @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)566 * @return The linked list of nic_frame_list_t nodes, each containing one frame 567 */ 568 static nic_frame_list_t *rtl8139_frame_receive(nic_t *nic_data) 576 569 { 577 570 rtl8139_t *rtl8139 = nic_get_specific(nic_data); … … 581 574 nic_frame_list_t *frames = nic_alloc_frame_list(); 582 575 if (!frames) 583 ddf_msg(LVL_ERROR, "Can not allocate frame list for received packets.");576 ddf_msg(LVL_ERROR, "Can not allocate frame list for received frames."); 584 577 585 578 void *rx_buffer = rtl8139->rx_buff_virt; … … 605 598 while (!rtl8139_hw_buffer_empty(rtl8139)) { 606 599 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;600 uint32_t frame_header = uint32_t_le2host( *((uint32_t*)rx_ptr) ); 601 uint16_t size = frame_header >> 16; 602 uint16_t frame_size = size - RTL8139_CRC_SIZE; 603 /* received frame flags in frame header */ 604 uint16_t rcs = (uint16_t) frame_header; 612 605 613 606 if (size == RTL8139_EARLY_SIZE) { 614 /* The packetcopying is still in progress, break receiving */607 /* The frame copying is still in progress, break receiving */ 615 608 ddf_msg(LVL_DEBUG, "Early threshold reached, not completely coppied"); 616 609 break; … … 618 611 619 612 /* Check if the header is valid, otherwise we are lost in the buffer */ 620 if (size == 0 || size > RTL8139_ PACKET_MAX_LENGTH) {613 if (size == 0 || size > RTL8139_FRAME_MAX_LENGTH) { 621 614 ddf_msg(LVL_ERROR, "Receiver error -> receiver reset (size: %4"PRIu16", " 622 "header 0x%4"PRIx16". Offset: %zu)", size, packet_header,615 "header 0x%4"PRIx16". Offset: %zu)", size, frame_header, 623 616 rx_offset); 624 617 goto rx_err; … … 629 622 } 630 623 631 cur_read += size + RTL_ PACKET_HEADER_SIZE;624 cur_read += size + RTL_FRAME_HEADER_SIZE; 632 625 if (cur_read > max_read) 633 626 break; 634 627 635 628 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);629 nic_frame_t *frame = rtl8139_read_frame(nic_data, rx_buffer, 630 RxBUF_SIZE, rx_offset + RTL_FRAME_HEADER_SIZE, frame_size); 638 631 639 632 if (frame) … … 642 635 643 636 /* 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 packet637 rx_offset = ALIGN_UP(rx_offset + size + RTL_FRAME_HEADER_SIZE, 4); 638 639 /* Write lesser value to prevent overflow into unread frame 647 640 * (the recomendation from the RealTech rtl8139 programming guide) 648 641 */ … … 727 720 tx_used++; 728 721 729 /* If the packetwas sent */722 /* If the frame was sent */ 730 723 if (tsd_value & TSD_TOK) { 731 724 size_t size = REG_GET_VAL(tsd_value, TSD_SIZE); … … 757 750 } 758 751 759 /** Receive all packets from the buffer752 /** Receive all frames from the buffer 760 753 * 761 754 * @param rtl8139 driver private data 762 755 */ 763 static void rtl8139_receive_ packets(nic_t *nic_data)756 static void rtl8139_receive_frames(nic_t *nic_data) 764 757 { 765 758 assert(nic_data); … … 769 762 770 763 fibril_mutex_lock(&rtl8139->rx_lock); 771 nic_frame_list_t *frames = rtl8139_ packet_receive(nic_data);764 nic_frame_list_t *frames = rtl8139_frame_receive(nic_data); 772 765 fibril_mutex_unlock(&rtl8139->rx_lock); 773 766 … … 825 818 } 826 819 827 /* Check transmittion interrupts first to allow transmit next packets820 /* Check transmittion interrupts first to allow transmit next frames 828 821 * sooner 829 822 */ … … 832 825 } 833 826 if (isr & INT_ROK) { 834 rtl8139_receive_ packets(nic_data);827 rtl8139_receive_frames(nic_data); 835 828 } 836 829 if (isr & (INT_RER | INT_RXOVW | INT_FIFOOVW)) { … … 933 926 } 934 927 935 /** Activate the device to receive and transmit packets928 /** Activate the device to receive and transmit frames 936 929 * 937 930 * @param nic_data The nic driver data … … 1213 1206 goto failed; 1214 1207 1215 /* Set default packetacceptance */1208 /* Set default frame acceptance */ 1216 1209 rtl8139->rcr_data.ucast_mask = RTL8139_RCR_UCAST_DEFAULT; 1217 1210 rtl8139->rcr_data.mcast_mask = RTL8139_RCR_MCAST_DEFAULT; 1218 1211 rtl8139->rcr_data.bcast_mask = RTL8139_RCR_BCAST_DEFAULT; 1219 1212 rtl8139->rcr_data.defect_mask = RTL8139_RCR_DEFECT_DEFAULT; 1220 /* Set receiver early treshold to 8/16 of packetlength */1213 /* Set receiver early treshold to 8/16 of frame length */ 1221 1214 rtl8139->rcr_data.rcr_base = (0x8 << RCR_ERTH_SHIFT); 1222 1215 … … 1477 1470 }; 1478 1471 1479 /** Check if pause packetoperations are valid in current situation1472 /** Check if pause frame operations are valid in current situation 1480 1473 * 1481 1474 * @param rtl8139 RTL8139 private structure … … 1502 1495 } 1503 1496 1504 /** Get current pause packetconfiguration1497 /** Get current pause frame configuration 1505 1498 * 1506 1499 * Values are filled with NIC_RESULT_NOT_AVAILABLE if the value has no sense in … … 1508 1501 * 1509 1502 * @param[in] fun The DDF structure of the RTL8139 1510 * @param[out] we_send Sign if local constroller sends pause packets1511 * @param[out] we_receive Sign if local constroller receives pause packets1512 * @param[out] time Time filled in pause packets. 0xFFFF in rtl81391503 * @param[out] we_send Sign if local constroller sends pause frame 1504 * @param[out] we_receive Sign if local constroller receives pause frame 1505 * @param[out] time Time filled in pause frames. 0xFFFF in rtl8139 1513 1506 * 1514 1507 * @return EOK if succeed … … 1540 1533 }; 1541 1534 1542 /** Set current pause packetconfiguration1535 /** Set current pause frame configuration 1543 1536 * 1544 1537 * @param fun The DDF structure of the RTL8139 1545 * @param allow_send Sign if local constroller sends pause packets1546 * @param allow_receive Sign if local constroller receives pause packets1538 * @param allow_send Sign if local constroller sends pause frame 1539 * @param allow_receive Sign if local constroller receives pause frames 1547 1540 * @param time Time to use, ignored (not supported by device) 1548 1541 * 1549 * @return EOK if succeed, INVAL if the pause packethas no sence1542 * @return EOK if succeed, INVAL if the pause frame has no sence 1550 1543 */ 1551 1544 static int rtl8139_pause_set(ddf_fun_t *fun, int allow_send, int allow_receive, … … 1796 1789 } 1797 1790 1798 /** Set unicast packets acceptance mode1791 /** Set unicast frames acceptance mode 1799 1792 * 1800 1793 * @param nic_data The nic device to update … … 1854 1847 } 1855 1848 1856 /** Set multicast packets acceptance mode1849 /** Set multicast frames acceptance mode 1857 1850 * 1858 1851 * @param nic_data The nic device to update … … 1899 1892 } 1900 1893 1901 /** Set broadcast packets acceptance mode1894 /** Set broadcast frames acceptance mode 1902 1895 * 1903 1896 * @param nic_data The nic device to update … … 1929 1922 } 1930 1923 1931 /** Get state of acceptance of weird packets1924 /** Get state of acceptance of weird frames 1932 1925 * 1933 1926 * @param[in] device The device to check … … 1951 1944 }; 1952 1945 1953 /** Set acceptance of weird packets1946 /** Set acceptance of weird frames 1954 1947 * 1955 1948 * @param device The device to update … … 2127 2120 } 2128 2121 2129 /** Force receiving all packets in the receive buffer2122 /** Force receiving all frames in the receive buffer 2130 2123 * 2131 2124 * @param device The device to receive -
uspace/drv/nic/rtl8139/driver.h
r3ea725e r1bc35b5 39 39 /** Transmittion buffers count */ 40 40 #define TX_BUFF_COUNT 4 41 /** Size of buffer for one packet41 /** Size of buffer for one frame 42 42 * - 2kB 43 43 */ … … 49 49 #define RTL8139_CRC_SIZE 4 50 50 51 /** The default mode of accepting unicast packets */51 /** The default mode of accepting unicast frames */ 52 52 #define RTL8139_RCR_UCAST_DEFAULT RCR_ACCEPT_PHYS_MATCH 53 /** The default mode of accepting multicast packets */53 /** The default mode of accepting multicast frames */ 54 54 #define RTL8139_RCR_MCAST_DEFAULT 0 55 /** The default mode of accepting broadcast packets */55 /** The default mode of accepting broadcast frames */ 56 56 #define RTL8139_RCR_BCAST_DEFAULT RCR_ACCEPT_BROADCAST 57 /** The default mode of accepting defect packets */57 /** The default mode of accepting defect frames */ 58 58 #define RTL8139_RCR_DEFECT_DEFAULT 0 59 59 … … 112 112 size_t tx_used; 113 113 114 /** Buffer for receiving packets */114 /** Buffer for receiving frames */ 115 115 void *rx_buff_phys; 116 116 void *rx_buff_virt;
Note:
See TracChangeset
for help on using the changeset viewer.
