Changeset 1bc35b5 in mainline for uspace/drv/nic/rtl8139


Ignore:
Timestamp:
2012-01-19T08:13:45Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d8da56b
Parents:
3ea725e
Message:

Remove most use of packet_t from NIC drivers.

Location:
uspace/drv/nic/rtl8139
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/nic/rtl8139/defs.h

    r3ea725e r1bc35b5  
    4242#define RTL8139_IO_SIZE 256
    4343
    44 /** The maximal transmitted packet length in bytes allowed according to RTL8139
     44/** The maximal transmitted frame length in bytes allowed according to RTL8139
    4545 *  documentation (see SIZE part of TSD documentation)
    4646 */
    47 #define RTL8139_PACKET_MAX_LENGTH 1792
     47#define RTL8139_FRAME_MAX_LENGTH 1792
    4848
    4949
     
    9494
    9595        CR      = 0x37,  /**< Command register, 1b */
    96         CAPR    = 0x38,  /**< Current address of packet read, 2b */
     96        CAPR    = 0x38,  /**< Current address of frame read, 2b */
    9797        CBA     = 0x3a,  /**< Current buffer address, 2b */
    9898
     
    282282        RCR_MulERINT = 1 << 17,    /**< Multiple early interrupt select */
    283283
    284         /** Minimal error packet length (1 = 8B, 0 = 64B). If AER/AR is set, RER8
     284        /** Minimal error frame length (1 = 8B, 0 = 64B). If AER/AR is set, RER8
    285285         * is "Don't care"
    286286         */
     
    302302
    303303        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 */
    306306        RCR_ACCEPT_BROADCAST  = 1 << 3,  /**< Accept broadcast */
    307307        RCR_ACCEPT_MULTICAST  = 1 << 2,  /**< Accept multicast */
    308308        RCR_ACCEPT_PHYS_MATCH = 1 << 1,  /**< Accept device MAC address match */
    309         RCR_ACCEPT_ALL_PHYS   = 1 << 0,  /**< Accept all packets with
     309        RCR_ACCEPT_ALL_PHYS   = 1 << 0,  /**< Accept all frames with
    310310                                          * phys. desticnation
    311311                                                                          */
     
    362362        ANAR_ACK          = (1 << 14),  /**< Capability reception acknowledge */
    363363        ANAR_REMOTE_FAULT = (1 << 13),  /**< Remote fault detection capability */
    364         ANAR_PAUSE        = (1 << 10),  /**< Symetric pause packet capability */
     364        ANAR_PAUSE        = (1 << 10),  /**< Symetric pause frame capability */
    365365        ANAR_100T4        = (1 << 9),   /**< T4, not supported by the device */
    366366        ANAR_100TX_FD     = (1 << 8),   /**< 100BASE_TX full duplex */
     
    399399        CONFIG3_GNT_SELECT = (1 << 7),  /**< Gnt select */
    400400        CONFIG3_PARM_EN    = (1 << 6),  /**< Parameter enabled (100MBit mode) */
    401         CONFIG3_MAGIC      = (1 << 5),  /**< WoL Magic packet enable */
     401        CONFIG3_MAGIC      = (1 << 5),  /**< WoL Magic frame enable */
    402402        CONFIG3_LINK_UP    = (1 << 4),  /**< Wakeup if link is reestablished */
    403403        CONFIG3_CLKRUN_EN  = (1 << 2),  /**< CLKRUN enabled */ /* TODO: check what does it mean */
     
    416416};
    417417
    418 /** Maximal runt packet size + 1 */
     418/** Maximal runt frame size + 1 */
    419419#define RTL8139_RUNT_MAX_SIZE 64
    420420
    421 /** Bits in packet header */
    422 enum rtl8139_packet_header {
     421/** Bits in frame header */
     422enum rtl8139_frame_header {
    423423        RSR_MAR  = (1 << 15),  /**< Multicast received */
    424424        RSR_PAM  = (1 << 14),  /**< Physical address match */
     
    426426
    427427        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) */
    431431        RSR_CRC  = (1 << 2),   /**< CRC error */
    432432        RSR_FAE  = (1 << 1),   /**< Frame alignment error */
    433         RSR_ROK  = (1 << 0)    /**< Good packet received */
     433        RSR_ROK  = (1 << 0)    /**< Good frame received */
    434434};
    435435
     
    451451                                                                          */
    452452
    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 */
    454454
    455455        MXTxDMA_SHIFT = 8,  /**< Max. DMA Burst per TxDMA shift, burst = 16^value */
     
    459459        TX_RETRY_COUNT_SIZE  = 4,            /**< Retries before aborting size */
    460460
    461         CLEAR_ABORT = 1 << 0    /**< Retransmit aborted packet at the last
     461        CLEAR_ABORT = 1 << 0    /**< Retransmit aborted frame at the last
    462462                                  *  transmitted descriptor
    463463                                                          */
     
    478478extern const struct rtl8139_hwver_map rtl8139_versions[RTL8139_VER_COUNT + 1];
    479479
    480 /** Size in the packet header while copying from RxFIFO to Rx buffer */
     480/** Size in the frame header while copying from RxFIFO to Rx buffer */
    481481#define RTL8139_EARLY_SIZE UINT16_C(0xfff0)
    482 /** The only supported pause packet time value */
     482/** The only supported pause frame time value */
    483483#define RTL8139_PAUSE_VAL UINT16_C(0xFFFF)
    484484
    485 /** Size of the packet header in front of the received frame */
    486 #define RTL_PACKET_HEADER_SIZE 4
     485/** Size of the frame header in front of the received frame */
     486#define RTL_FRAME_HEADER_SIZE 4
    487487
    488488/** 8k buffer */
  • uspace/drv/nic/rtl8139/driver.c

    r3ea725e r1bc35b5  
    3939#include <io/log.h>
    4040#include <nic.h>
    41 #include <packet_client.h>
     41//#include <packet_client.h>
    4242#include <device/pci.h>
    4343
     
    152152}
    153153
    154 /** Update the mask of accepted packets in the RCR register according to
     154/** Update the mask of accepted frames in the RCR register according to
    155155 * rcr_accept_mode value in rtl8139_t
    156156 *
     
    170170}
    171171
    172 /** Fill the mask of accepted multicast packets in the card registers
     172/** Fill the mask of accepted multicast frames in the card registers
    173173 *
    174174 *  @param rtl8139  The rtl8139 private data
     
    394394#define rtl8139_tbuf_busy(tsd) ((pio_read_32(tsd) & TSD_OWN) == 0)
    395395
    396 /** Send packet with the hardware
     396/** Send frame with the hardware
    397397 *
    398398 * note: the main_lock is locked when framework calls this function
     
    412412        ddf_msg(LVL_DEBUG, "Sending frame");
    413413
    414         if (size > RTL8139_PACKET_MAX_LENGTH) {
     414        if (size > RTL8139_FRAME_MAX_LENGTH) {
    415415                ddf_msg(LVL_ERROR, "Send frame: frame too long, %zu bytes",
    416416                    size);
     
    437437        fibril_mutex_unlock(&rtl8139->tx_lock);
    438438
    439         /* Get address of the buffer descriptor and packet data */
     439        /* Get address of the buffer descriptor and frame data */
    440440        void *tsd = rtl8139->io_port + TSD0 + tx_curr * 4;
    441441        void *buf_addr = rtl8139->tx_buff[tx_curr];
     
    505505}
    506506
    507 /** Create packet structure from the buffer data
     507/** Create frame structure from the buffer data
    508508 *
    509509 * @param nic_data      NIC driver data
    510510 * @param rx_buffer     The receiver buffer
    511511 * @param rx_size       The buffer 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);
     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 */
     517static 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);
    521521        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.");
    523523                return NULL;
    524524        }
    525525
    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);
    535528        if (ret == NULL) {
    536529                nic_release_frame(nic_data, frame);
     
    568561}
    569562
    570 /** Receive all packets in queue
     563/** Receive all frames in queue
    571564 *
    572565 *  @param nic_data  The controller 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)
     566 *  @return The linked list of nic_frame_list_t nodes, each containing one frame
     567 */
     568static nic_frame_list_t *rtl8139_frame_receive(nic_t *nic_data)
    576569{
    577570        rtl8139_t *rtl8139 = nic_get_specific(nic_data);
     
    581574        nic_frame_list_t *frames = nic_alloc_frame_list();
    582575        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.");
    584577
    585578        void *rx_buffer = rtl8139->rx_buff_virt;
     
    605598        while (!rtl8139_hw_buffer_empty(rtl8139)) {
    606599                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 packet header */
    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;
    612605
    613606                if (size == RTL8139_EARLY_SIZE) {
    614                         /* The packet copying is still in progress, break receiving */
     607                        /* The frame copying is still in progress, break receiving */
    615608                        ddf_msg(LVL_DEBUG, "Early threshold reached, not completely coppied");
    616609                        break;
     
    618611
    619612                /* 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) {
    621614                        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,
    623616                            rx_offset);
    624617                        goto rx_err;
     
    629622                }
    630623
    631                 cur_read += size + RTL_PACKET_HEADER_SIZE;
     624                cur_read += size + RTL_FRAME_HEADER_SIZE;
    632625                if (cur_read > max_read)
    633626                        break;
    634627
    635628                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);
    638631
    639632                        if (frame)
     
    642635
    643636                /* 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 packet
     637                rx_offset = ALIGN_UP(rx_offset + size + RTL_FRAME_HEADER_SIZE, 4);
     638
     639                /* Write lesser value to prevent overflow into unread frame
    647640                 * (the recomendation from the RealTech rtl8139 programming guide)
    648641                 */
     
    727720                tx_used++;
    728721
    729                 /* If the packet was sent */
     722                /* If the frame was sent */
    730723                if (tsd_value & TSD_TOK) {
    731724                        size_t size = REG_GET_VAL(tsd_value, TSD_SIZE);
     
    757750}
    758751
    759 /** Receive all packets from the buffer
     752/** Receive all frames from the buffer
    760753 *
    761754 *  @param rtl8139  driver private data
    762755 */
    763 static void rtl8139_receive_packets(nic_t *nic_data)
     756static void rtl8139_receive_frames(nic_t *nic_data)
    764757{
    765758        assert(nic_data);
     
    769762
    770763        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);
    772765        fibril_mutex_unlock(&rtl8139->rx_lock);
    773766
     
    825818        }
    826819
    827         /* Check transmittion interrupts first to allow transmit next packets
     820        /* Check transmittion interrupts first to allow transmit next frames
    828821         * sooner
    829822         */
     
    832825        }
    833826        if (isr & INT_ROK) {
    834                 rtl8139_receive_packets(nic_data);
     827                rtl8139_receive_frames(nic_data);
    835828        }
    836829        if (isr & (INT_RER | INT_RXOVW | INT_FIFOOVW)) {
     
    933926}
    934927
    935 /** Activate the device to receive and transmit packets
     928/** Activate the device to receive and transmit frames
    936929 *
    937930 *  @param nic_data  The nic driver data
     
    12131206                goto failed;
    12141207
    1215         /* Set default packet acceptance */
     1208        /* Set default frame acceptance */
    12161209        rtl8139->rcr_data.ucast_mask = RTL8139_RCR_UCAST_DEFAULT;
    12171210        rtl8139->rcr_data.mcast_mask = RTL8139_RCR_MCAST_DEFAULT;
    12181211        rtl8139->rcr_data.bcast_mask = RTL8139_RCR_BCAST_DEFAULT;
    12191212        rtl8139->rcr_data.defect_mask = RTL8139_RCR_DEFECT_DEFAULT;
    1220         /* Set receiver early treshold to 8/16 of packet length */
     1213        /* Set receiver early treshold to 8/16 of frame length */
    12211214        rtl8139->rcr_data.rcr_base = (0x8 << RCR_ERTH_SHIFT);
    12221215
     
    14771470};
    14781471
    1479 /** Check if pause packet operations are valid in current situation
     1472/** Check if pause frame operations are valid in current situation
    14801473 *
    14811474 *  @param rtl8139  RTL8139 private structure
     
    15021495}
    15031496
    1504 /** Get current pause packet configuration
     1497/** Get current pause frame configuration
    15051498 *
    15061499 *  Values are filled with NIC_RESULT_NOT_AVAILABLE if the value has no sense in
     
    15081501 *
    15091502 *  @param[in]  fun         The DDF structure of the RTL8139
    1510  *  @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
     1503 *  @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
    15131506 *
    15141507 *  @return EOK if succeed
     
    15401533};
    15411534
    1542 /** Set current pause packet configuration
     1535/** Set current pause frame configuration
    15431536 *
    15441537 *  @param fun            The DDF structure of the RTL8139
    1545  *  @param allow_send     Sign if local constroller sends pause packets
    1546  *  @param allow_receive  Sign if local constroller receives pause packets
     1538 *  @param allow_send     Sign if local constroller sends pause frame
     1539 *  @param allow_receive  Sign if local constroller receives pause frames
    15471540 *  @param time           Time to use, ignored (not supported by device)
    15481541 *
    1549  *  @return EOK if succeed, INVAL if the pause packet has no sence
     1542 *  @return EOK if succeed, INVAL if the pause frame has no sence
    15501543 */
    15511544static int rtl8139_pause_set(ddf_fun_t *fun, int allow_send, int allow_receive,
     
    17961789}
    17971790
    1798 /** Set unicast packets acceptance mode
     1791/** Set unicast frames acceptance mode
    17991792 *
    18001793 *  @param nic_data  The nic device to update
     
    18541847}
    18551848
    1856 /** Set multicast packets acceptance mode
     1849/** Set multicast frames acceptance mode
    18571850 *
    18581851 *  @param nic_data  The nic device to update
     
    18991892}
    19001893
    1901 /** Set broadcast packets acceptance mode
     1894/** Set broadcast frames acceptance mode
    19021895 *
    19031896 *  @param nic_data  The nic device to update
     
    19291922}
    19301923
    1931 /** Get state of acceptance of weird packets
     1924/** Get state of acceptance of weird frames
    19321925 *
    19331926 *  @param[in]  device  The device to check
     
    19511944};
    19521945
    1953 /** Set acceptance of weird packets
     1946/** Set acceptance of weird frames
    19541947 *
    19551948 *  @param device  The device to update
     
    21272120}
    21282121
    2129 /** Force receiving all packets in the receive buffer
     2122/** Force receiving all frames in the receive buffer
    21302123 *
    21312124 *  @param device  The device to receive
  • uspace/drv/nic/rtl8139/driver.h

    r3ea725e r1bc35b5  
    3939/** Transmittion buffers count */
    4040#define TX_BUFF_COUNT 4
    41 /** Size of buffer for one packet
     41/** Size of buffer for one frame
    4242 *  - 2kB
    4343 */
     
    4949#define RTL8139_CRC_SIZE 4
    5050
    51 /** The default mode of accepting unicast packets */
     51/** The default mode of accepting unicast frames */
    5252#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 */
    5454#define RTL8139_RCR_MCAST_DEFAULT 0
    55 /** The default mode of accepting broadcast packets */
     55/** The default mode of accepting broadcast frames */
    5656#define RTL8139_RCR_BCAST_DEFAULT RCR_ACCEPT_BROADCAST
    57 /** The default mode of accepting defect packets */
     57/** The default mode of accepting defect frames */
    5858#define RTL8139_RCR_DEFECT_DEFAULT 0
    5959
     
    112112        size_t tx_used;
    113113
    114         /** Buffer for receiving packets */
     114        /** Buffer for receiving frames */
    115115        void *rx_buff_phys;
    116116        void *rx_buff_virt;
Note: See TracChangeset for help on using the changeset viewer.