Changes in uspace/drv/nic/rtl8139/driver.c [f0b74b2:e86b8f0] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/nic/rtl8139/driver.c
rf0b74b2 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 … … 389 388 static int rtl8139_on_activated(nic_t *nic_data); 390 389 static int rtl8139_on_stopped(nic_t *nic_data); 391 static void rtl8139_ write_packet(nic_t *nic_data, packet_t *packet);390 static void rtl8139_send_frame(nic_t *nic_data, void *data, size_t size); 392 391 393 392 /** Check if the transmit buffer is busy */ 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 399 398 * 400 399 * @param nic_data The nic driver data structure 401 * @param packet The packet to send 400 * @param data Frame data 401 * @param size Frame size in bytes 402 402 * 403 403 * @return EOK if succeed, error code in the case of error 404 404 */ 405 static void rtl8139_ write_packet(nic_t *nic_data, packet_t *packet)405 static void rtl8139_send_frame(nic_t *nic_data, void *data, size_t size) 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 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); 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); 422 416 nic_report_send_error(rtl8139->nic_data, NIC_SEC_OTHER, 1); 423 417 goto err_size; 424 418 } 425 419 426 assert(( packet_length & TSD_SIZE_MASK) == packet_length);420 assert((size & TSD_SIZE_MASK) == size); 427 421 428 422 /* Lock transmitter structure for obtaining next buffer */ … … 442 436 fibril_mutex_unlock(&rtl8139->tx_lock); 443 437 444 /* Get address of the buffer descriptor and packetdata */438 /* Get address of the buffer descriptor and frame data */ 445 439 void *tsd = rtl8139->io_port + TSD0 + tx_curr * 4; 446 440 void *buf_addr = rtl8139->tx_buff[tx_curr]; … … 449 443 assert(!rtl8139_tbuf_busy(tsd)); 450 444 451 /* Write packetdata to the buffer, set the size to TSD and clear OWN bit */452 memcpy(buf_addr, packet_data, packet_length);445 /* Write frame data to the buffer, set the size to TSD and clear OWN bit */ 446 memcpy(buf_addr, data, size); 453 447 454 448 /* Set size of the data to send */ 455 449 uint32_t tsd_value = pio_read_32(tsd); 456 tsd_value = rtl8139_tsd_set_size(tsd_value, packet_length);450 tsd_value = rtl8139_tsd_set_size(tsd_value, size); 457 451 pio_write_32(tsd, tsd_value); 458 452 … … 462 456 tsd_value &= ~(uint32_t)TSD_OWN; 463 457 pio_write_32(tsd, tsd_value); 464 nic_release_packet(nic_data, packet);465 458 return; 466 459 467 460 err_busy_no_inc: 468 461 err_size: 469 nic_release_packet(nic_data, packet);470 462 return; 471 463 }; … … 512 504 } 513 505 514 /** Create packetstructure from the buffer data506 /** Create frame structure from the buffer data 515 507 * 516 508 * @param nic_data NIC driver data 517 509 * @param rx_buffer The receiver buffer 518 510 * @param rx_size The buffer size 519 * @param packet_startThe offset where packet data start520 * @param packet_size The size of the packetdata521 * 522 * @return The packetlist 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);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); 528 520 if (! frame) { 529 ddf_msg(LVL_ERROR, "Can not allocate frame for received packet.");521 ddf_msg(LVL_ERROR, "Can not allocate frame for received frame."); 530 522 return NULL; 531 523 } 532 524 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); 525 void *ret = rtl8139_memcpy_wrapped(frame->data, rx_buffer, frame_start, 526 RxBUF_SIZE, frame_size); 542 527 if (ret == NULL) { 543 528 nic_release_frame(nic_data, frame); … … 575 560 } 576 561 577 /** Receive all packets in queue562 /** Receive all frames in queue 578 563 * 579 564 * @param nic_data The controller data 580 * @return The linked list of packet_list_t nodes, each containing one packet581 */ 582 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) 583 568 { 584 569 rtl8139_t *rtl8139 = nic_get_specific(nic_data); … … 588 573 nic_frame_list_t *frames = nic_alloc_frame_list(); 589 574 if (!frames) 590 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."); 591 576 592 577 void *rx_buffer = rtl8139->rx_buff_virt; … … 612 597 while (!rtl8139_hw_buffer_empty(rtl8139)) { 613 598 void *rx_ptr = rx_buffer + rx_offset % RxBUF_SIZE; 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 packetheader */618 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; 619 604 620 605 if (size == RTL8139_EARLY_SIZE) { 621 /* The packetcopying is still in progress, break receiving */606 /* The frame copying is still in progress, break receiving */ 622 607 ddf_msg(LVL_DEBUG, "Early threshold reached, not completely coppied"); 623 608 break; … … 625 610 626 611 /* Check if the header is valid, otherwise we are lost in the buffer */ 627 if (size == 0 || size > RTL8139_ PACKET_MAX_LENGTH) {612 if (size == 0 || size > RTL8139_FRAME_MAX_LENGTH) { 628 613 ddf_msg(LVL_ERROR, "Receiver error -> receiver reset (size: %4"PRIu16", " 629 "header 0x%4"PRIx16". Offset: %zu)", size, packet_header,614 "header 0x%4"PRIx16". Offset: %zu)", size, frame_header, 630 615 rx_offset); 631 616 goto rx_err; … … 636 621 } 637 622 638 cur_read += size + RTL_ PACKET_HEADER_SIZE;623 cur_read += size + RTL_FRAME_HEADER_SIZE; 639 624 if (cur_read > max_read) 640 625 break; 641 626 642 627 if (frames) { 643 nic_frame_t *frame = rtl8139_read_ packet(nic_data, rx_buffer,644 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); 645 630 646 631 if (frame) … … 649 634 650 635 /* Update offset */ 651 rx_offset = ALIGN_UP(rx_offset + size + RTL_ PACKET_HEADER_SIZE, 4);652 653 /* 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 654 639 * (the recomendation from the RealTech rtl8139 programming guide) 655 640 */ … … 734 719 tx_used++; 735 720 736 /* If the packetwas sent */721 /* If the frame was sent */ 737 722 if (tsd_value & TSD_TOK) { 738 723 size_t size = REG_GET_VAL(tsd_value, TSD_SIZE); … … 764 749 } 765 750 766 /** Receive all packets from the buffer751 /** Receive all frames from the buffer 767 752 * 768 753 * @param rtl8139 driver private data 769 754 */ 770 static void rtl8139_receive_ packets(nic_t *nic_data)755 static void rtl8139_receive_frames(nic_t *nic_data) 771 756 { 772 757 assert(nic_data); … … 776 761 777 762 fibril_mutex_lock(&rtl8139->rx_lock); 778 nic_frame_list_t *frames = rtl8139_ packet_receive(nic_data);763 nic_frame_list_t *frames = rtl8139_frame_receive(nic_data); 779 764 fibril_mutex_unlock(&rtl8139->rx_lock); 780 765 … … 832 817 } 833 818 834 /* Check transmittion interrupts first to allow transmit next packets819 /* Check transmittion interrupts first to allow transmit next frames 835 820 * sooner 836 821 */ … … 839 824 } 840 825 if (isr & INT_ROK) { 841 rtl8139_receive_ packets(nic_data);826 rtl8139_receive_frames(nic_data); 842 827 } 843 828 if (isr & (INT_RER | INT_RXOVW | INT_FIFOOVW)) { … … 940 925 } 941 926 942 /** Activate the device to receive and transmit packets927 /** Activate the device to receive and transmit frames 943 928 * 944 929 * @param nic_data The nic driver data … … 1022 1007 rtl8139->nic_data = nic_data; 1023 1008 nic_set_specific(nic_data, rtl8139); 1024 nic_set_ write_packet_handler(nic_data, rtl8139_write_packet);1009 nic_set_send_frame_handler(nic_data, rtl8139_send_frame); 1025 1010 nic_set_state_change_handlers(nic_data, 1026 1011 rtl8139_on_activated, NULL, rtl8139_on_stopped); … … 1220 1205 goto failed; 1221 1206 1222 /* Set default packetacceptance */1207 /* Set default frame acceptance */ 1223 1208 rtl8139->rcr_data.ucast_mask = RTL8139_RCR_UCAST_DEFAULT; 1224 1209 rtl8139->rcr_data.mcast_mask = RTL8139_RCR_MCAST_DEFAULT; 1225 1210 rtl8139->rcr_data.bcast_mask = RTL8139_RCR_BCAST_DEFAULT; 1226 1211 rtl8139->rcr_data.defect_mask = RTL8139_RCR_DEFECT_DEFAULT; 1227 /* Set receiver early treshold to 8/16 of packetlength */1212 /* Set receiver early treshold to 8/16 of frame length */ 1228 1213 rtl8139->rcr_data.rcr_base = (0x8 << RCR_ERTH_SHIFT); 1229 1214 … … 1295 1280 int rtl8139_dev_add(ddf_dev_t *dev) 1296 1281 { 1282 ddf_fun_t *fun; 1283 1297 1284 assert(dev); 1298 1285 ddf_msg(LVL_NOTE, "RTL8139_dev_add %s (handle = %d)", dev->name, dev->handle); … … 1331 1318 } 1332 1319 1333 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); 1334 1330 if (rc != EOK) { 1335 ddf_msg(LVL_ERROR, "Failed to register as DDF function - error %d", rc); 1336 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; 1337 1338 } 1338 1339 … … 1342 1343 return EOK; 1343 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 */ 1344 1351 err_irq: 1345 1352 unregister_interrupt_handler(dev, rtl8139->irq); … … 1484 1491 }; 1485 1492 1486 /** Check if pause packetoperations are valid in current situation1493 /** Check if pause frame operations are valid in current situation 1487 1494 * 1488 1495 * @param rtl8139 RTL8139 private structure … … 1509 1516 } 1510 1517 1511 /** Get current pause packetconfiguration1518 /** Get current pause frame configuration 1512 1519 * 1513 1520 * Values are filled with NIC_RESULT_NOT_AVAILABLE if the value has no sense in … … 1515 1522 * 1516 1523 * @param[in] fun The DDF structure of the RTL8139 1517 * @param[out] we_send Sign if local constroller sends pause packets1518 * @param[out] we_receive Sign if local constroller receives pause packets1519 * @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 1520 1527 * 1521 1528 * @return EOK if succeed … … 1547 1554 }; 1548 1555 1549 /** Set current pause packetconfiguration1556 /** Set current pause frame configuration 1550 1557 * 1551 1558 * @param fun The DDF structure of the RTL8139 1552 * @param allow_send Sign if local constroller sends pause packets1553 * @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 1554 1561 * @param time Time to use, ignored (not supported by device) 1555 1562 * 1556 * @return EOK if succeed, INVAL if the pause packethas no sence1563 * @return EOK if succeed, INVAL if the pause frame has no sence 1557 1564 */ 1558 1565 static int rtl8139_pause_set(ddf_fun_t *fun, int allow_send, int allow_receive, … … 1803 1810 } 1804 1811 1805 /** Set unicast packets acceptance mode1812 /** Set unicast frames acceptance mode 1806 1813 * 1807 1814 * @param nic_data The nic device to update … … 1861 1868 } 1862 1869 1863 /** Set multicast packets acceptance mode1870 /** Set multicast frames acceptance mode 1864 1871 * 1865 1872 * @param nic_data The nic device to update … … 1906 1913 } 1907 1914 1908 /** Set broadcast packets acceptance mode1915 /** Set broadcast frames acceptance mode 1909 1916 * 1910 1917 * @param nic_data The nic device to update … … 1936 1943 } 1937 1944 1938 /** Get state of acceptance of weird packets1945 /** Get state of acceptance of weird frames 1939 1946 * 1940 1947 * @param[in] device The device to check … … 1958 1965 }; 1959 1966 1960 /** Set acceptance of weird packets1967 /** Set acceptance of weird frames 1961 1968 * 1962 1969 * @param device The device to update … … 2134 2141 } 2135 2142 2136 /** Force receiving all packets in the receive buffer2143 /** Force receiving all frames in the receive buffer 2137 2144 * 2138 2145 * @param device The device to receive
Note:
See TracChangeset
for help on using the changeset viewer.