Changes in uspace/drv/nic/rtl8139/driver.c [6d8455d:e86b8f0] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/nic/rtl8139/driver.c
r6d8455d re86b8f0 39 39 #include <io/log.h> 40 40 #include <nic.h> 41 #include <packet_client.h>42 41 #include <device/pci.h> 43 42 … … 152 151 } 153 152 154 /** Update the mask of accepted packets in the RCR register according to153 /** Update the mask of accepted frames in the RCR register according to 155 154 * rcr_accept_mode value in rtl8139_t 156 155 * … … 170 169 } 171 170 172 /** Fill the mask of accepted multicast packets in the card registers171 /** Fill the mask of accepted multicast frames in the card registers 173 172 * 174 173 * @param rtl8139 The rtl8139 private data … … 394 393 #define rtl8139_tbuf_busy(tsd) ((pio_read_32(tsd) & TSD_OWN) == 0) 395 394 396 /** Send packetwith the hardware395 /** Send frame with the hardware 397 396 * 398 397 * note: the main_lock is locked when framework calls this function … … 412 411 ddf_msg(LVL_DEBUG, "Sending frame"); 413 412 414 if (size > RTL8139_ PACKET_MAX_LENGTH) {413 if (size > RTL8139_FRAME_MAX_LENGTH) { 415 414 ddf_msg(LVL_ERROR, "Send frame: frame too long, %zu bytes", 416 415 size); … … 437 436 fibril_mutex_unlock(&rtl8139->tx_lock); 438 437 439 /* Get address of the buffer descriptor and packetdata */438 /* Get address of the buffer descriptor and frame data */ 440 439 void *tsd = rtl8139->io_port + TSD0 + tx_curr * 4; 441 440 void *buf_addr = rtl8139->tx_buff[tx_curr]; … … 505 504 } 506 505 507 /** Create packetstructure from the buffer data506 /** Create frame structure from the buffer data 508 507 * 509 508 * @param nic_data NIC driver data 510 509 * @param rx_buffer The receiver buffer 511 510 * @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);511 * @param frame_start The offset where packet data start 512 * @param frame_size The size of the frame data 513 * 514 * @return The frame list 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); 521 520 if (! frame) { 522 ddf_msg(LVL_ERROR, "Can not allocate frame for received packet.");521 ddf_msg(LVL_ERROR, "Can not allocate frame for received frame."); 523 522 return NULL; 524 523 } 525 524 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); 525 void *ret = rtl8139_memcpy_wrapped(frame->data, rx_buffer, frame_start, 526 RxBUF_SIZE, frame_size); 535 527 if (ret == NULL) { 536 528 nic_release_frame(nic_data, frame); … … 568 560 } 569 561 570 /** Receive all packets in queue562 /** Receive all frames in queue 571 563 * 572 564 * @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)565 * @return The linked list of nic_frame_list_t nodes, each containing one frame 566 */ 567 static nic_frame_list_t *rtl8139_frame_receive(nic_t *nic_data) 576 568 { 577 569 rtl8139_t *rtl8139 = nic_get_specific(nic_data); … … 581 573 nic_frame_list_t *frames = nic_alloc_frame_list(); 582 574 if (!frames) 583 ddf_msg(LVL_ERROR, "Can not allocate frame list for received packets.");575 ddf_msg(LVL_ERROR, "Can not allocate frame list for received frames."); 584 576 585 577 void *rx_buffer = rtl8139->rx_buff_virt; … … 605 597 while (!rtl8139_hw_buffer_empty(rtl8139)) { 606 598 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;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 frame header */ 603 uint16_t rcs = (uint16_t) frame_header; 612 604 613 605 if (size == RTL8139_EARLY_SIZE) { 614 /* The packetcopying is still in progress, break receiving */606 /* The frame copying is still in progress, break receiving */ 615 607 ddf_msg(LVL_DEBUG, "Early threshold reached, not completely coppied"); 616 608 break; … … 618 610 619 611 /* Check if the header is valid, otherwise we are lost in the buffer */ 620 if (size == 0 || size > RTL8139_ PACKET_MAX_LENGTH) {612 if (size == 0 || size > RTL8139_FRAME_MAX_LENGTH) { 621 613 ddf_msg(LVL_ERROR, "Receiver error -> receiver reset (size: %4"PRIu16", " 622 "header 0x%4"PRIx16". Offset: %zu)", size, packet_header,614 "header 0x%4"PRIx16". Offset: %zu)", size, frame_header, 623 615 rx_offset); 624 616 goto rx_err; … … 629 621 } 630 622 631 cur_read += size + RTL_ PACKET_HEADER_SIZE;623 cur_read += size + RTL_FRAME_HEADER_SIZE; 632 624 if (cur_read > max_read) 633 625 break; 634 626 635 627 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);628 nic_frame_t *frame = rtl8139_read_frame(nic_data, rx_buffer, 629 RxBUF_SIZE, rx_offset + RTL_FRAME_HEADER_SIZE, frame_size); 638 630 639 631 if (frame) … … 642 634 643 635 /* 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 packet636 rx_offset = ALIGN_UP(rx_offset + size + RTL_FRAME_HEADER_SIZE, 4); 637 638 /* Write lesser value to prevent overflow into unread frame 647 639 * (the recomendation from the RealTech rtl8139 programming guide) 648 640 */ … … 727 719 tx_used++; 728 720 729 /* If the packetwas sent */721 /* If the frame was sent */ 730 722 if (tsd_value & TSD_TOK) { 731 723 size_t size = REG_GET_VAL(tsd_value, TSD_SIZE); … … 757 749 } 758 750 759 /** Receive all packets from the buffer751 /** Receive all frames from the buffer 760 752 * 761 753 * @param rtl8139 driver private data 762 754 */ 763 static void rtl8139_receive_ packets(nic_t *nic_data)755 static void rtl8139_receive_frames(nic_t *nic_data) 764 756 { 765 757 assert(nic_data); … … 769 761 770 762 fibril_mutex_lock(&rtl8139->rx_lock); 771 nic_frame_list_t *frames = rtl8139_ packet_receive(nic_data);763 nic_frame_list_t *frames = rtl8139_frame_receive(nic_data); 772 764 fibril_mutex_unlock(&rtl8139->rx_lock); 773 765 … … 825 817 } 826 818 827 /* Check transmittion interrupts first to allow transmit next packets819 /* Check transmittion interrupts first to allow transmit next frames 828 820 * sooner 829 821 */ … … 832 824 } 833 825 if (isr & INT_ROK) { 834 rtl8139_receive_ packets(nic_data);826 rtl8139_receive_frames(nic_data); 835 827 } 836 828 if (isr & (INT_RER | INT_RXOVW | INT_FIFOOVW)) { … … 933 925 } 934 926 935 /** Activate the device to receive and transmit packets927 /** Activate the device to receive and transmit frames 936 928 * 937 929 * @param nic_data The nic driver data … … 1213 1205 goto failed; 1214 1206 1215 /* Set default packetacceptance */1207 /* Set default frame acceptance */ 1216 1208 rtl8139->rcr_data.ucast_mask = RTL8139_RCR_UCAST_DEFAULT; 1217 1209 rtl8139->rcr_data.mcast_mask = RTL8139_RCR_MCAST_DEFAULT; 1218 1210 rtl8139->rcr_data.bcast_mask = RTL8139_RCR_BCAST_DEFAULT; 1219 1211 rtl8139->rcr_data.defect_mask = RTL8139_RCR_DEFECT_DEFAULT; 1220 /* Set receiver early treshold to 8/16 of packetlength */1212 /* Set receiver early treshold to 8/16 of frame length */ 1221 1213 rtl8139->rcr_data.rcr_base = (0x8 << RCR_ERTH_SHIFT); 1222 1214 … … 1288 1280 int rtl8139_dev_add(ddf_dev_t *dev) 1289 1281 { 1282 ddf_fun_t *fun; 1283 1290 1284 assert(dev); 1291 1285 ddf_msg(LVL_NOTE, "RTL8139_dev_add %s (handle = %d)", dev->name, dev->handle); … … 1324 1318 } 1325 1319 1326 rc = nic_register_as_ddf_fun(nic_data, &rtl8139_dev_ops); 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); 1327 1330 if (rc != EOK) { 1328 ddf_msg(LVL_ERROR, "Failed to register as DDF function - error %d", rc); 1329 goto err_irq; 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; 1330 1338 } 1331 1339 … … 1335 1343 return EOK; 1336 1344 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 */ 1337 1351 err_irq: 1338 1352 unregister_interrupt_handler(dev, rtl8139->irq); … … 1477 1491 }; 1478 1492 1479 /** Check if pause packetoperations are valid in current situation1493 /** Check if pause frame operations are valid in current situation 1480 1494 * 1481 1495 * @param rtl8139 RTL8139 private structure … … 1502 1516 } 1503 1517 1504 /** Get current pause packetconfiguration1518 /** Get current pause frame configuration 1505 1519 * 1506 1520 * Values are filled with NIC_RESULT_NOT_AVAILABLE if the value has no sense in … … 1508 1522 * 1509 1523 * @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 rtl81391524 * @param[out] we_send Sign if local constroller sends pause frame 1525 * @param[out] we_receive Sign if local constroller receives pause frame 1526 * @param[out] time Time filled in pause frames. 0xFFFF in rtl8139 1513 1527 * 1514 1528 * @return EOK if succeed … … 1540 1554 }; 1541 1555 1542 /** Set current pause packetconfiguration1556 /** Set current pause frame configuration 1543 1557 * 1544 1558 * @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 packets1559 * @param allow_send Sign if local constroller sends pause frame 1560 * @param allow_receive Sign if local constroller receives pause frames 1547 1561 * @param time Time to use, ignored (not supported by device) 1548 1562 * 1549 * @return EOK if succeed, INVAL if the pause packethas no sence1563 * @return EOK if succeed, INVAL if the pause frame has no sence 1550 1564 */ 1551 1565 static int rtl8139_pause_set(ddf_fun_t *fun, int allow_send, int allow_receive, … … 1796 1810 } 1797 1811 1798 /** Set unicast packets acceptance mode1812 /** Set unicast frames acceptance mode 1799 1813 * 1800 1814 * @param nic_data The nic device to update … … 1854 1868 } 1855 1869 1856 /** Set multicast packets acceptance mode1870 /** Set multicast frames acceptance mode 1857 1871 * 1858 1872 * @param nic_data The nic device to update … … 1899 1913 } 1900 1914 1901 /** Set broadcast packets acceptance mode1915 /** Set broadcast frames acceptance mode 1902 1916 * 1903 1917 * @param nic_data The nic device to update … … 1929 1943 } 1930 1944 1931 /** Get state of acceptance of weird packets1945 /** Get state of acceptance of weird frames 1932 1946 * 1933 1947 * @param[in] device The device to check … … 1951 1965 }; 1952 1966 1953 /** Set acceptance of weird packets1967 /** Set acceptance of weird frames 1954 1968 * 1955 1969 * @param device The device to update … … 2127 2141 } 2128 2142 2129 /** Force receiving all packets in the receive buffer2143 /** Force receiving all frames in the receive buffer 2130 2144 * 2131 2145 * @param device The device to receive
Note:
See TracChangeset
for help on using the changeset viewer.