13859Sml29623 /* 23859Sml29623 * CDDL HEADER START 33859Sml29623 * 43859Sml29623 * The contents of this file are subject to the terms of the 53859Sml29623 * Common Development and Distribution License (the "License"). 63859Sml29623 * You may not use this file except in compliance with the License. 73859Sml29623 * 83859Sml29623 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 93859Sml29623 * or http://www.opensolaris.org/os/licensing. 103859Sml29623 * See the License for the specific language governing permissions 113859Sml29623 * and limitations under the License. 123859Sml29623 * 133859Sml29623 * When distributing Covered Code, include this CDDL HEADER in each 143859Sml29623 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 153859Sml29623 * If applicable, add the following below this CDDL HEADER, with the 163859Sml29623 * fields enclosed by brackets "[]" replaced with your own identifying 173859Sml29623 * information: Portions Copyright [yyyy] [name of copyright owner] 183859Sml29623 * 193859Sml29623 * CDDL HEADER END 203859Sml29623 */ 213859Sml29623 /* 226495Sspeer * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 233859Sml29623 * Use is subject to license terms. 243859Sml29623 */ 253859Sml29623 263859Sml29623 #ifndef _SYS_NXGE_NXGE_TXDMA_H 273859Sml29623 #define _SYS_NXGE_NXGE_TXDMA_H 283859Sml29623 293859Sml29623 #ifdef __cplusplus 303859Sml29623 extern "C" { 313859Sml29623 #endif 323859Sml29623 33*8275SEric Cheng #include <sys/taskq.h> 343859Sml29623 #include <sys/nxge/nxge_txdma_hw.h> 353859Sml29623 #include <npi_txdma.h> 363859Sml29623 373859Sml29623 #define TXDMA_PORT_BITMAP(nxgep) (nxgep->pt_config.tx_dma_map) 383859Sml29623 393859Sml29623 #define TXDMA_RECLAIM_PENDING_DEFAULT 64 403859Sml29623 #define TX_FULL_MARK 3 413859Sml29623 423859Sml29623 /* 433859Sml29623 * Transmit load balancing definitions. 443859Sml29623 */ 453859Sml29623 #define NXGE_TX_LB_TCPUDP 0 /* default policy */ 463859Sml29623 #define NXGE_TX_LB_HASH 1 /* from the hint data */ 473859Sml29623 #define NXGE_TX_LB_DEST_MAC 2 /* Dest. MAC */ 483859Sml29623 493859Sml29623 /* 503859Sml29623 * Descriptor ring empty: 513859Sml29623 * (1) head index is equal to tail index. 523859Sml29623 * (2) wrapped around bits are the same. 533859Sml29623 * Descriptor ring full: 543859Sml29623 * (1) head index is equal to tail index. 553859Sml29623 * (2) wrapped around bits are different. 563859Sml29623 * 573859Sml29623 */ 583859Sml29623 #define TXDMA_RING_EMPTY(head, head_wrap, tail, tail_wrap) \ 593859Sml29623 ((head == tail && head_wrap == tail_wrap) ? B_TRUE : B_FALSE) 603859Sml29623 613859Sml29623 #define TXDMA_RING_FULL(head, head_wrap, tail, tail_wrap) \ 623859Sml29623 ((head == tail && head_wrap != tail_wrap) ? B_TRUE : B_FALSE) 633859Sml29623 643859Sml29623 #define TXDMA_DESC_NEXT_INDEX(index, entries, wrap_mask) \ 653859Sml29623 ((index + entries) & wrap_mask) 663859Sml29623 673859Sml29623 #define TXDMA_DRR_WEIGHT_DEFAULT 0x001f 683859Sml29623 693952Sml29623 typedef enum { 703952Sml29623 NXGE_USE_SERIAL = 0, 713952Sml29623 NXGE_USE_START, 723952Sml29623 } nxge_tx_mode_t; 733952Sml29623 743859Sml29623 typedef struct _tx_msg_t { 753859Sml29623 nxge_os_block_mv_t flags; /* DMA, BCOPY, DVMA (?) */ 763859Sml29623 nxge_os_dma_common_t buf_dma; /* premapped buffer blocks */ 773859Sml29623 nxge_os_dma_handle_t buf_dma_handle; /* premapped buffer handle */ 783859Sml29623 nxge_os_dma_handle_t dma_handle; /* DMA handle for normal send */ 793859Sml29623 nxge_os_dma_handle_t dvma_handle; /* Fast DVMA handle */ 807906SMichael.Speer@Sun.COM struct _tx_msg_t *nextp; 813859Sml29623 823859Sml29623 p_mblk_t tx_message; 833859Sml29623 uint32_t tx_msg_size; 843859Sml29623 size_t bytes_used; 853859Sml29623 int head; 863859Sml29623 int tail; 873859Sml29623 } tx_msg_t, *p_tx_msg_t; 883859Sml29623 893859Sml29623 /* 903859Sml29623 * TX Statistics. 913859Sml29623 */ 923859Sml29623 typedef struct _nxge_tx_ring_stats_t { 933859Sml29623 uint64_t opackets; 943859Sml29623 uint64_t obytes; 953859Sml29623 uint64_t oerrors; 963859Sml29623 973859Sml29623 uint32_t tx_inits; 983859Sml29623 uint32_t tx_no_buf; 993859Sml29623 1003859Sml29623 uint32_t mbox_err; 1013859Sml29623 uint32_t pkt_size_err; 1023859Sml29623 uint32_t tx_ring_oflow; 1033859Sml29623 uint32_t pre_buf_par_err; 1043859Sml29623 uint32_t nack_pref; 1053859Sml29623 uint32_t nack_pkt_rd; 1063859Sml29623 uint32_t conf_part_err; 1073859Sml29623 uint32_t pkt_part_err; 1083859Sml29623 uint32_t tx_starts; 1093859Sml29623 uint32_t tx_nocanput; 1103859Sml29623 uint32_t tx_msgdup_fail; 1113859Sml29623 uint32_t tx_allocb_fail; 1123859Sml29623 uint32_t tx_no_desc; 1133859Sml29623 uint32_t tx_dma_bind_fail; 1143859Sml29623 uint32_t tx_uflo; 1153859Sml29623 1163859Sml29623 uint32_t tx_hdr_pkts; 1173859Sml29623 uint32_t tx_ddi_pkts; 1183859Sml29623 uint32_t tx_dvma_pkts; 1193859Sml29623 1203859Sml29623 uint32_t tx_max_pend; 1213859Sml29623 uint32_t tx_jumbo_pkts; 1223859Sml29623 1233859Sml29623 txdma_ring_errlog_t errlog; 1243859Sml29623 } nxge_tx_ring_stats_t, *p_nxge_tx_ring_stats_t; 1253859Sml29623 1263859Sml29623 typedef struct _tx_ring_t { 1273859Sml29623 nxge_os_dma_common_t tdc_desc; 1283859Sml29623 struct _nxge_t *nxgep; 1293859Sml29623 p_tx_msg_t tx_msg_ring; 1303859Sml29623 uint32_t tnblocks; 1313859Sml29623 tx_rng_cfig_t tx_ring_cfig; 1323859Sml29623 tx_ring_hdl_t tx_ring_hdl; 1333859Sml29623 tx_ring_kick_t tx_ring_kick; 1343859Sml29623 tx_cs_t tx_cs; 1353859Sml29623 tx_dma_ent_msk_t tx_evmask; 1363859Sml29623 txdma_mbh_t tx_mbox_mbh; 1373859Sml29623 txdma_mbl_t tx_mbox_mbl; 1383859Sml29623 log_page_vld_t page_valid; 1393859Sml29623 log_page_mask_t page_mask_1; 1403859Sml29623 log_page_mask_t page_mask_2; 1413859Sml29623 log_page_value_t page_value_1; 1423859Sml29623 log_page_value_t page_value_2; 1433859Sml29623 log_page_relo_t page_reloc_1; 1443859Sml29623 log_page_relo_t page_reloc_2; 1453859Sml29623 log_page_hdl_t page_hdl; 1463859Sml29623 txc_dma_max_burst_t max_burst; 1473859Sml29623 boolean_t cfg_set; 1486713Sspeer #define NXGE_TX_RING_ONLINE 0x00 1496713Sspeer #define NXGE_TX_RING_OFFLINING 0x01 1506713Sspeer #define NXGE_TX_RING_OFFLINED 0x02 1516713Sspeer uint32_t tx_ring_offline; 1526886Sspeer boolean_t tx_ring_busy; 1533859Sml29623 1543859Sml29623 nxge_os_mutex_t lock; 155*8275SEric Cheng mac_ring_handle_t tx_ring_handle; 156*8275SEric Cheng ddi_taskq_t *taskq; 1573859Sml29623 uint16_t index; 1583859Sml29623 uint16_t tdc; 1593859Sml29623 struct nxge_tdc_cfg *tdc_p; 160*8275SEric Cheng int tx_ring_size; 1613859Sml29623 uint32_t num_chunks; 1623859Sml29623 1633859Sml29623 uint_t tx_wrap_mask; 1643859Sml29623 uint_t rd_index; 1653859Sml29623 uint_t wr_index; 1663859Sml29623 boolean_t wr_index_wrap; 1673859Sml29623 tx_ring_hdl_t ring_head; 1683859Sml29623 tx_ring_kick_t ring_kick_tail; 1693859Sml29623 txdma_mailbox_t tx_mbox; 1703859Sml29623 171*8275SEric Cheng int descs_pending; 1723859Sml29623 boolean_t queueing; 1733859Sml29623 1743859Sml29623 nxge_os_mutex_t sq_lock; 1753859Sml29623 p_mblk_t head; 1763859Sml29623 p_mblk_t tail; 1773859Sml29623 1783859Sml29623 uint16_t ldg_group_id; 1793859Sml29623 p_nxge_tx_ring_stats_t tdc_stats; 1803859Sml29623 1813859Sml29623 nxge_os_mutex_t dvma_lock; 1823859Sml29623 uint_t dvma_wr_index; 1833859Sml29623 uint_t dvma_rd_index; 1843859Sml29623 uint_t dvma_pending; 1853859Sml29623 uint_t dvma_available; 1863859Sml29623 uint_t dvma_wrap_mask; 1873859Sml29623 1883859Sml29623 nxge_os_dma_handle_t *dvma_ring; 1893859Sml29623 1903859Sml29623 #if defined(sun4v) && defined(NIU_LP_WORKAROUND) 1913859Sml29623 uint64_t hv_tx_buf_base_ioaddr_pp; 1923859Sml29623 uint64_t hv_tx_buf_ioaddr_size; 1933859Sml29623 uint64_t hv_tx_cntl_base_ioaddr_pp; 1943859Sml29623 uint64_t hv_tx_cntl_ioaddr_size; 1953859Sml29623 boolean_t hv_set; 1963859Sml29623 #endif 1973859Sml29623 } tx_ring_t, *p_tx_ring_t; 1983859Sml29623 1993859Sml29623 2003859Sml29623 /* Transmit Mailbox */ 2013859Sml29623 typedef struct _tx_mbox_t { 2023859Sml29623 nxge_os_mutex_t lock; 2033859Sml29623 uint16_t index; 2043859Sml29623 struct _nxge_t *nxgep; 2053859Sml29623 uint16_t tdc; 2063859Sml29623 nxge_os_dma_common_t tx_mbox; 2073859Sml29623 txdma_mbl_t tx_mbox_l; 2083859Sml29623 txdma_mbh_t tx_mbox_h; 2093859Sml29623 } tx_mbox_t, *p_tx_mbox_t; 2103859Sml29623 2113859Sml29623 typedef struct _tx_rings_t { 2123859Sml29623 p_tx_ring_t *rings; 2133859Sml29623 boolean_t txdesc_allocated; 2143859Sml29623 uint32_t ndmas; 2153859Sml29623 nxge_os_dma_common_t tdc_dma; 2163859Sml29623 nxge_os_dma_common_t tdc_mbox; 2173859Sml29623 } tx_rings_t, *p_tx_rings_t; 2183859Sml29623 2193859Sml29623 2203859Sml29623 typedef struct _tx_mbox_areas_t { 2213859Sml29623 p_tx_mbox_t *txmbox_areas_p; 2223859Sml29623 boolean_t txmbox_allocated; 2233859Sml29623 } tx_mbox_areas_t, *p_tx_mbox_areas_t; 2243859Sml29623 2253859Sml29623 /* 2263859Sml29623 * Transmit prototypes. 2273859Sml29623 */ 2283859Sml29623 nxge_status_t nxge_init_txdma_channels(p_nxge_t); 2293859Sml29623 void nxge_uninit_txdma_channels(p_nxge_t); 2306495Sspeer 2316495Sspeer nxge_status_t nxge_init_txdma_channel(p_nxge_t, int); 2326495Sspeer void nxge_uninit_txdma_channel(p_nxge_t, int); 2336495Sspeer 2343859Sml29623 void nxge_setup_dma_common(p_nxge_dma_common_t, p_nxge_dma_common_t, 2353859Sml29623 uint32_t, uint32_t); 2363859Sml29623 nxge_status_t nxge_reset_txdma_channel(p_nxge_t, uint16_t, 2373859Sml29623 uint64_t); 2383859Sml29623 nxge_status_t nxge_init_txdma_channel_event_mask(p_nxge_t, 2393859Sml29623 uint16_t, p_tx_dma_ent_msk_t); 2403859Sml29623 nxge_status_t nxge_init_txdma_channel_cntl_stat(p_nxge_t, 2413859Sml29623 uint16_t, uint64_t); 2423859Sml29623 nxge_status_t nxge_enable_txdma_channel(p_nxge_t, uint16_t, 2433859Sml29623 p_tx_ring_t, p_tx_mbox_t); 2443859Sml29623 2453859Sml29623 p_mblk_t nxge_tx_pkt_header_reserve(p_mblk_t, uint8_t *); 2463859Sml29623 int nxge_tx_pkt_nmblocks(p_mblk_t, int *); 2473859Sml29623 boolean_t nxge_txdma_reclaim(p_nxge_t, p_tx_ring_t, int); 2483859Sml29623 2493859Sml29623 void nxge_fill_tx_hdr(p_mblk_t, boolean_t, boolean_t, 2506611Sml29623 int, uint8_t, p_tx_pkt_hdr_all_t, t_uscalar_t, t_uscalar_t); 2513859Sml29623 2523859Sml29623 nxge_status_t nxge_txdma_hw_mode(p_nxge_t, boolean_t); 2533859Sml29623 void nxge_hw_start_tx(p_nxge_t); 2543859Sml29623 void nxge_txdma_stop(p_nxge_t); 2553859Sml29623 void nxge_txdma_stop_start(p_nxge_t); 2563859Sml29623 void nxge_fixup_txdma_rings(p_nxge_t); 2573859Sml29623 void nxge_txdma_hw_kick(p_nxge_t); 2583859Sml29623 void nxge_txdma_fix_channel(p_nxge_t, uint16_t); 2593859Sml29623 void nxge_txdma_fixup_channel(p_nxge_t, p_tx_ring_t, 2603859Sml29623 uint16_t); 2613859Sml29623 void nxge_txdma_hw_kick_channel(p_nxge_t, p_tx_ring_t, 2623859Sml29623 uint16_t); 2633859Sml29623 2643859Sml29623 void nxge_txdma_regs_dump(p_nxge_t, int); 2653859Sml29623 void nxge_txdma_regs_dump_channels(p_nxge_t); 2663859Sml29623 2673859Sml29623 void nxge_check_tx_hang(p_nxge_t); 2683859Sml29623 void nxge_fixup_hung_txdma_rings(p_nxge_t); 2693859Sml29623 2703859Sml29623 void nxge_reclaim_rings(p_nxge_t); 2713859Sml29623 int nxge_txdma_channel_hung(p_nxge_t, 2723859Sml29623 p_tx_ring_t tx_ring_p, uint16_t); 2733859Sml29623 int nxge_txdma_hung(p_nxge_t); 2743859Sml29623 int nxge_txdma_stop_inj_err(p_nxge_t, int); 2753859Sml29623 void nxge_txdma_inject_err(p_nxge_t, uint32_t, uint8_t); 2763859Sml29623 2776495Sspeer extern nxge_status_t nxge_alloc_tx_mem_pool(p_nxge_t); 2786495Sspeer extern nxge_status_t nxge_alloc_txb(p_nxge_t nxgep, int channel); 2796495Sspeer extern void nxge_free_txb(p_nxge_t nxgep, int channel); 2806495Sspeer 2813859Sml29623 #ifdef __cplusplus 2823859Sml29623 } 2833859Sml29623 #endif 2843859Sml29623 2853859Sml29623 #endif /* _SYS_NXGE_NXGE_TXDMA_H */ 286