47693af92e50a1ad81825eb01b7157a211269613mx * CDDL HEADER START
47693af92e50a1ad81825eb01b7157a211269613mx * The contents of this file are subject to the terms of the
47693af92e50a1ad81825eb01b7157a211269613mx * Common Development and Distribution License (the "License").
47693af92e50a1ad81825eb01b7157a211269613mx * You may not use this file except in compliance with the License.
47693af92e50a1ad81825eb01b7157a211269613mx * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
47693af92e50a1ad81825eb01b7157a211269613mx * See the License for the specific language governing permissions
47693af92e50a1ad81825eb01b7157a211269613mx * and limitations under the License.
47693af92e50a1ad81825eb01b7157a211269613mx * When distributing Covered Code, include this CDDL HEADER in each
47693af92e50a1ad81825eb01b7157a211269613mx * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
47693af92e50a1ad81825eb01b7157a211269613mx * If applicable, add the following below this CDDL HEADER, with the
47693af92e50a1ad81825eb01b7157a211269613mx * fields enclosed by brackets "[]" replaced with your own identifying
47693af92e50a1ad81825eb01b7157a211269613mx * information: Portions Copyright [yyyy] [name of copyright owner]
47693af92e50a1ad81825eb01b7157a211269613mx * CDDL HEADER END
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
47693af92e50a1ad81825eb01b7157a211269613mx * Use is subject to license terms.
75675fb724f5909db6f601f4c342437208ca4178vb * Callback code invoked from STREAMs when the recv data buffer is free for
75675fb724f5909db6f601f4c342437208ca4178vb * recycling.
75675fb724f5909db6f601f4c342437208ca4178vb * The following table describes function behaviour:
75675fb724f5909db6f601f4c342437208ca4178vb * | mac stopped | mac running
75675fb724f5909db6f601f4c342437208ca4178vb * ---------------------------------------------------
75675fb724f5909db6f601f4c342437208ca4178vb * buffer delivered | free buffer | recycle buffer
75675fb724f5909db6f601f4c342437208ca4178vb * buffer not delivered | do nothing | recycle buffer (*)
75675fb724f5909db6f601f4c342437208ca4178vb * Note (*):
75675fb724f5909db6f601f4c342437208ca4178vb * Recycle buffer only if mac state did not change during execution of
75675fb724f5909db6f601f4c342437208ca4178vb * function. Otherwise if mac state changed, set buffer delivered & re-enter
75675fb724f5909db6f601f4c342437208ca4178vb * function by calling freemsg().
6f3e57ac9d0b054c3169579f3422080b8ba10105mx * Free the buffer directly if the buffer was allocated
6f3e57ac9d0b054c3169579f3422080b8ba10105mx * previously or mac was stopped.
6f3e57ac9d0b054c3169579f3422080b8ba10105mx * recycle the data buffer again and fill them in free ring
6f3e57ac9d0b054c3169579f3422080b8ba10105mx /* call nge_rx_recycle again to free it */
6f3e57ac9d0b054c3169579f3422080b8ba10105mx * Checking the rx's BDs (one or more) to receive
6f3e57ac9d0b054c3169579f3422080b8ba10105mx * one complete packet.
6f3e57ac9d0b054c3169579f3422080b8ba10105mx * start_index: the start indexer of BDs for one packet.
6f3e57ac9d0b054c3169579f3422080b8ba10105mx * end_index: the end indexer of BDs for one packet.
6f3e57ac9d0b054c3169579f3422080b8ba10105mxstatic mblk_t *nge_recv_packet(nge_t *ngep, uint32_t start_index, size_t len);
6f3e57ac9d0b054c3169579f3422080b8ba10105mx#pragma inline(nge_recv_packet)
6f3e57ac9d0b054c3169579f3422080b8ba10105mxnge_recv_packet(nge_t *ngep, uint32_t start_index, size_t len)
6f3e57ac9d0b054c3169579f3422080b8ba10105mx * First check the free_list, if it is NULL,
6f3e57ac9d0b054c3169579f3422080b8ba10105mx * make the recycle_list be free_list.
6f3e57ac9d0b054c3169579f3422080b8ba10105mx /* If it's not a qualified packet, delete it */
6f3e57ac9d0b054c3169579f3422080b8ba10105mx * If receive packet size is smaller than RX bcopy threshold,
6f3e57ac9d0b054c3169579f3422080b8ba10105mx * or there is no available buffer in free_list or recycle list,
6f3e57ac9d0b054c3169579f3422080b8ba10105mx * we use bcopy directly.
6f3e57ac9d0b054c3169579f3422080b8ba10105mx if (len <= ngep->param_rxbcopy_threshold || bufp == NULL)
6f3e57ac9d0b054c3169579f3422080b8ba10105mx * Make sure the packet *contents* 4-byte aligned
6f3e57ac9d0b054c3169579f3422080b8ba10105mx /* Fill the buffer from free_list */
6f3e57ac9d0b054c3169579f3422080b8ba10105mx /* replenish the buffer for hardware descriptor */
6f3e57ac9d0b054c3169579f3422080b8ba10105mx return (mp);
6f3e57ac9d0b054c3169579f3422080b8ba10105mx * Statistic the rx's error
6f3e57ac9d0b054c3169579f3422080b8ba10105mx * and generate a log msg for these.
6f3e57ac9d0b054c3169579f3422080b8ba10105mx * RXE, Parity Error, Symbo error, CRC error
6f3e57ac9d0b054c3169579f3422080b8ba10105mx * have been recored by nvidia's hardware
6f3e57ac9d0b054c3169579f3422080b8ba10105mx * statistics part (nge_statistics). So it is uncessary to record them by
6f3e57ac9d0b054c3169579f3422080b8ba10105mx * driver in this place.
6f3e57ac9d0b054c3169579f3422080b8ba10105mxnge_rxsta_handle(nge_t *ngep, uint32_t stflag, uint32_t *pflags);
6f3e57ac9d0b054c3169579f3422080b8ba10105mx#pragma inline(nge_rxsta_handle)
6f3e57ac9d0b054c3169579f3422080b8ba10105mxnge_rxsta_handle(nge_t *ngep, uint32_t stflag, uint32_t *pflags)
6f3e57ac9d0b054c3169579f3422080b8ba10105mx switch (errors) {
6f3e57ac9d0b054c3169579f3422080b8ba10105mx /* Sync the descriptor for kernel */
6f3e57ac9d0b054c3169579f3422080b8ba10105mx if (sync_start + ngep->param_recv_max_packet <= ngep->rx_desc) {
6f3e57ac9d0b054c3169579f3422080b8ba10105mx (ngep->param_recv_max_packet + sync_start - ngep->rx_desc) *
6f3e57ac9d0b054c3169579f3422080b8ba10105mx * Looking through the rx's ring to find the good packets
6f3e57ac9d0b054c3169579f3422080b8ba10105mx * and try to receive more and more packets in rx's ring
6f3e57ac9d0b054c3169579f3422080b8ba10105mx for (;;) {
6f3e57ac9d0b054c3169579f3422080b8ba10105mx * If there is no packet in receving ring
6f3e57ac9d0b054c3169579f3422080b8ba10105mx * break the loop
6f3e57ac9d0b054c3169579f3422080b8ba10105mx /* Hardware error, re-use the buffer */
6ad2424573dc54dfdafb513b5b710b59337b0869Winson Wang - Sun Microsystems - Beijing China if (ngep->recv_count >= ngep->param_recv_max_packet)
6f3e57ac9d0b054c3169579f3422080b8ba10105mx /* Sync the descriptors for device */
6f3e57ac9d0b054c3169579f3422080b8ba10105mxnge_hot_rxd_fill(void *hwd, const ddi_dma_cookie_t *cookie, size_t len)
a55f711916b9f7718fabc2d1822bf5719aa6140fMiles Xu, Sun Microsystems hw_bd_p->host_buf_addr_lo = (uint32_t)dmac_addr;
6f3e57ac9d0b054c3169579f3422080b8ba10105mxnge_sum_rxd_fill(void *hwd, const ddi_dma_cookie_t *cookie, size_t len)
a55f711916b9f7718fabc2d1822bf5719aa6140fMiles Xu, Sun Microsystems (uint32_t)(cookie->dmac_address + NGE_HEADROOM);
9fa05d92f6b225eb418fb782225c991b887ea8b7Winson Wang - Sun Microsystems - Beijing China err_flag = hrbdp->cntl_status.cntl_val;
9fa05d92f6b225eb418fb782225c991b887ea8b7Winson Wang - Sun Microsystems - Beijing China *len = err_flag & RXD_BCNT_MSK;
9fa05d92f6b225eb418fb782225c991b887ea8b7Winson Wang - Sun Microsystems - Beijing China err_flag = hrbdp->cntl_status.cntl_val;