4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #include <sys/mac_provider.h>
27 #include <sys/nxge/nxge_impl.h>
28 #include <sys/nxge/nxge_hio.h>
29 #include <npi_tx_wr64.h>
31 /* Software LSO required header files */
32 #include <netinet/tcp.h>
33 #include <inet/ip_impl.h>
36 extern uint64_t mac_pkt_hash(uint_t
, mblk_t
*mp
, uint8_t policy
,
37 boolean_t is_outbound
);
39 static mblk_t
*nxge_lso_eliminate(mblk_t
*);
40 static mblk_t
*nxge_do_softlso(mblk_t
*mp
, uint32_t mss
);
41 static void nxge_lso_info_get(mblk_t
*, uint32_t *, uint32_t *);
42 static void nxge_hcksum_retrieve(mblk_t
*,
43 uint32_t *, uint32_t *, uint32_t *,
44 uint32_t *, uint32_t *);
45 static uint32_t nxge_csgen(uint16_t *, int);
47 extern uint32_t nxge_reclaim_pending
;
48 extern uint32_t nxge_bcopy_thresh
;
49 extern uint32_t nxge_dvma_thresh
;
50 extern uint32_t nxge_dma_stream_thresh
;
51 extern uint32_t nxge_tx_minfree
;
52 extern uint32_t nxge_tx_intr_thres
;
53 extern uint32_t nxge_tx_max_gathers
;
54 extern uint32_t nxge_tx_tiny_pack
;
55 extern uint32_t nxge_tx_use_bcopy
;
56 extern nxge_tx_mode_t nxge_tx_scheme
;
57 uint32_t nxge_lso_kick_cnt
= 2;
61 nxge_tx_ring_task(void *arg
)
63 p_tx_ring_t ring
= (p_tx_ring_t
)arg
;
65 ASSERT(ring
->tx_ring_handle
!= NULL
);
67 MUTEX_ENTER(&ring
->lock
);
68 (void) nxge_txdma_reclaim(ring
->nxgep
, ring
, 0);
69 MUTEX_EXIT(&ring
->lock
);
71 if (!ring
->tx_ring_offline
) {
72 mac_tx_ring_update(ring
->nxgep
->mach
, ring
->tx_ring_handle
);
77 nxge_tx_ring_dispatch(p_tx_ring_t ring
)
80 * Kick the ring task to reclaim some buffers.
82 (void) ddi_taskq_dispatch(ring
->taskq
,
83 nxge_tx_ring_task
, (void *)ring
, DDI_SLEEP
);
87 nxge_tx_ring_send(void *arg
, mblk_t
*mp
)
89 p_nxge_ring_handle_t nrhp
= (p_nxge_ring_handle_t
)arg
;
91 p_tx_ring_t tx_ring_p
;
96 channel
= nxgep
->pt_config
.hw_config
.tdc
.start
+ nrhp
->index
;
97 tx_ring_p
= nxgep
->tx_rings
->rings
[channel
];
100 * We may be in a transition from offlined DMA to onlined
103 if (tx_ring_p
== NULL
) {
104 ASSERT(tx_ring_p
!= NULL
);
112 ASSERT(nxgep
== tx_ring_p
->nxgep
);
115 * Make sure DMA is not offlined.
117 if (isLDOMservice(nxgep
) && tx_ring_p
->tx_ring_offline
) {
118 ASSERT(!tx_ring_p
->tx_ring_offline
);
124 * Transmit the packet.
126 status
= nxge_start(nxgep
, tx_ring_p
, mp
);
128 nxge_tx_ring_dispatch(tx_ring_p
);
136 nxge_start(p_nxge_t nxgep
, p_tx_ring_t tx_ring_p
, p_mblk_t mp
)
138 int dma_status
, status
= 0;
139 p_tx_desc_t tx_desc_ring_vp
;
140 npi_handle_t npi_desc_handle
;
141 nxge_os_dma_handle_t tx_desc_dma_handle
;
142 p_tx_desc_t tx_desc_p
;
143 p_tx_msg_t tx_msg_ring
;
145 tx_desc_t tx_desc
, *tmp_desc_p
;
146 tx_desc_t sop_tx_desc
, *sop_tx_desc_p
;
147 p_tx_pkt_header_t hdrp
;
148 tx_pkt_hdr_all_t tmp_hdrp
;
149 p_tx_pkt_hdr_all_t pkthdrp
;
160 uint32_t pkt_len
, pack_len
, min_len
;
161 uint32_t bcopy_thresh
;
162 int i
, cur_index
, sop_index
;
164 boolean_t tail_wrap
= B_FALSE
;
165 nxge_dma_common_t desc_area
;
166 nxge_os_dma_handle_t dma_handle
;
167 ddi_dma_cookie_t dma_cookie
;
168 npi_handle_t npi_handle
;
172 boolean_t good_packet
;
173 boolean_t mark_mode
= B_FALSE
;
174 p_nxge_stats_t statsp
;
175 p_nxge_tx_ring_stats_t tdc_stats
;
176 t_uscalar_t start_offset
= 0;
177 t_uscalar_t stuff_offset
= 0;
178 t_uscalar_t end_offset
= 0;
179 t_uscalar_t value
= 0;
180 t_uscalar_t cksum_flags
= 0;
181 boolean_t cksum_on
= B_FALSE
;
183 uint64_t tot_xfer_len
= 0;
184 boolean_t header_set
= B_FALSE
;
186 p_tx_desc_t tx_desc_ring_pp
;
187 p_tx_desc_t tx_desc_pp
;
188 tx_desc_t
*save_desc_p
;
195 p_mblk_t mp_chain
= NULL
;
196 boolean_t is_lso
= B_FALSE
;
199 p_mblk_t nmp_lso_save
;
200 uint32_t lso_ngathers
;
201 boolean_t lso_tail_wrap
= B_FALSE
;
203 NXGE_DEBUG_MSG((nxgep
, TX_CTL
,
204 "==> nxge_start: tx dma channel %d", tx_ring_p
->tdc
));
205 NXGE_DEBUG_MSG((nxgep
, TX_CTL
,
206 "==> nxge_start: Starting tdc %d desc pending %d",
207 tx_ring_p
->tdc
, tx_ring_p
->descs_pending
));
209 statsp
= nxgep
->statsp
;
211 if (!isLDOMguest(nxgep
)) {
212 switch (nxgep
->mac
.portmode
) {
214 if (nxgep
->statsp
->port_stats
.lb_mode
==
216 if (!statsp
->mac_stats
.link_up
) {
218 NXGE_DEBUG_MSG((nxgep
, TX_CTL
,
221 goto nxge_start_fail1
;
227 * For the following modes, check the link status
228 * before sending the packet out:
235 if (nxgep
->statsp
->port_stats
.lb_mode
<
237 if (!statsp
->mac_stats
.link_up
) {
239 NXGE_DEBUG_MSG((nxgep
, TX_CTL
,
242 goto nxge_start_fail1
;
249 if ((!(nxgep
->drv_state
& STATE_HW_INITIALIZED
)) ||
250 (nxgep
->nxge_mac_state
!= NXGE_MAC_STARTED
)) {
251 NXGE_DEBUG_MSG((nxgep
, TX_CTL
,
252 "==> nxge_start: hardware not initialized or stopped"));
254 goto nxge_start_fail1
;
257 if (nxgep
->soft_lso_enable
) {
258 mp_chain
= nxge_lso_eliminate(mp
);
259 NXGE_DEBUG_MSG((nxgep
, TX_CTL
,
260 "==> nxge_start(0): LSO mp $%p mp_chain $%p",
262 if (mp_chain
== NULL
) {
263 NXGE_ERROR_MSG((nxgep
, TX_CTL
,
264 "==> nxge_send(0): NULL mp_chain $%p != mp $%p",
266 goto nxge_start_fail1
;
268 if (mp_chain
!= mp
) {
269 NXGE_DEBUG_MSG((nxgep
, TX_CTL
,
270 "==> nxge_send(1): IS LSO mp_chain $%p != mp $%p",
274 mp_chain
= mp_chain
->b_next
;
279 mac_hcksum_get(mp
, &start_offset
, &stuff_offset
, &end_offset
,
280 &value
, &cksum_flags
);
281 if (!NXGE_IS_VLAN_PACKET(mp
->b_rptr
)) {
282 start_offset
+= sizeof (ether_header_t
);
283 stuff_offset
+= sizeof (ether_header_t
);
285 start_offset
+= sizeof (struct ether_vlan_header
);
286 stuff_offset
+= sizeof (struct ether_vlan_header
);
289 if (cksum_flags
& HCK_PARTIALCKSUM
) {
290 NXGE_DEBUG_MSG((nxgep
, TX_CTL
,
291 "==> nxge_start: mp $%p len %d "
292 "cksum_flags 0x%x (partial checksum) ",
293 mp
, MBLKL(mp
), cksum_flags
));
297 pkthdrp
= (p_tx_pkt_hdr_all_t
)&tmp_hdrp
;
298 pkthdrp
->reserved
= 0;
299 tmp_hdrp
.pkthdr
.value
= 0;
300 nxge_fill_tx_hdr(mp
, B_FALSE
, cksum_on
,
302 start_offset
, stuff_offset
);
307 MUTEX_ENTER(&tx_ring_p
->lock
);
309 if (isLDOMservice(nxgep
)) {
310 tx_ring_p
->tx_ring_busy
= B_TRUE
;
311 if (tx_ring_p
->tx_ring_offline
) {
313 tx_ring_p
->tx_ring_busy
= B_FALSE
;
314 (void) atomic_swap_32(&tx_ring_p
->tx_ring_offline
,
315 NXGE_TX_RING_OFFLINED
);
316 MUTEX_EXIT(&tx_ring_p
->lock
);
321 cur_index_lso
= tx_ring_p
->wr_index
;
322 lso_tail_wrap
= tx_ring_p
->wr_index_wrap
;
325 sop_index
= tx_ring_p
->wr_index
;
327 if (tx_ring_p
->descs_pending
) {
328 NXGE_DEBUG_MSG((nxgep
, TX_CTL
, "==> nxge_start: "
329 "desc pending %d ", tx_ring_p
->descs_pending
));
332 dump_len
= (int)(MBLKL(mp
));
333 dump_len
= (dump_len
> 128) ? 128: dump_len
;
335 NXGE_DEBUG_MSG((nxgep
, TX_CTL
,
336 "==> nxge_start: tdc %d: dumping ...: b_rptr $%p "
337 "(Before header reserve: ORIGINAL LEN %d)",
342 NXGE_DEBUG_MSG((nxgep
, TX_CTL
, "==> nxge_start: dump packets "
343 "(IP ORIGINAL b_rptr $%p): %s", mp
->b_rptr
,
344 nxge_dump_packet((char *)mp
->b_rptr
, dump_len
)));
347 tdc_stats
= tx_ring_p
->tdc_stats
;
348 mark_mode
= (tx_ring_p
->descs_pending
&&
349 (((int)tx_ring_p
->tx_ring_size
- (int)tx_ring_p
->descs_pending
) <
350 (int)nxge_tx_minfree
));
352 NXGE_DEBUG_MSG((nxgep
, TX_CTL
,
353 "TX Descriptor ring is channel %d mark mode %d",
354 tx_ring_p
->tdc
, mark_mode
));
356 if ((tx_ring_p
->descs_pending
+ lso_ngathers
) >= nxge_reclaim_pending
) {
357 if (!nxge_txdma_reclaim(nxgep
, tx_ring_p
,
358 (nxge_tx_minfree
+ lso_ngathers
))) {
359 NXGE_DEBUG_MSG((nxgep
, TX_CTL
,
360 "TX Descriptor ring is full: channel %d",
362 NXGE_DEBUG_MSG((nxgep
, TX_CTL
,
363 "TX Descriptor ring is full: channel %d",
367 * free the current mp and mp_chain if not FULL.
369 tdc_stats
->tx_no_desc
++;
370 NXGE_DEBUG_MSG((nxgep
, TX_CTL
,
371 "LSO packet: TX Descriptor ring is full: "
374 goto nxge_start_fail_lso
;
376 (void) atomic_cas_32(
377 (uint32_t *)&tx_ring_p
->queueing
, 0, 1);
378 tdc_stats
->tx_no_desc
++;
380 if (isLDOMservice(nxgep
)) {
381 tx_ring_p
->tx_ring_busy
= B_FALSE
;
382 if (tx_ring_p
->tx_ring_offline
) {
383 (void) atomic_swap_32(
384 &tx_ring_p
->tx_ring_offline
,
385 NXGE_TX_RING_OFFLINED
);
389 MUTEX_EXIT(&tx_ring_p
->lock
);
391 goto nxge_start_fail1
;
397 i
= sop_index
= tx_ring_p
->wr_index
;
404 good_packet
= B_TRUE
;
406 desc_area
= tx_ring_p
->tdc_desc
;
407 npi_handle
= desc_area
.npi_handle
;
408 npi_desc_handle
.regh
= (nxge_os_acc_handle_t
)
409 DMA_COMMON_ACC_HANDLE(desc_area
);
410 tx_desc_ring_vp
= (p_tx_desc_t
)DMA_COMMON_VPTR(desc_area
);
411 tx_desc_dma_handle
= (nxge_os_dma_handle_t
)
412 DMA_COMMON_HANDLE(desc_area
);
413 tx_msg_ring
= tx_ring_p
->tx_msg_ring
;
415 NXGE_DEBUG_MSG((nxgep
, TX_CTL
, "==> nxge_start: wr_index %d i %d",
419 msgsize
= msgdsize(nmp
);
420 NXGE_DEBUG_MSG((nxgep
, TX_CTL
,
421 "==> nxge_start(1): wr_index %d i %d msgdsize %d",
422 sop_index
, i
, msgsize
));
425 * The first 16 bytes of the premapped buffer are reserved
426 * for header. No padding will be used.
428 pkt_len
= pack_len
= boff
= TX_PKT_HEADER_SIZE
;
429 if (nxge_tx_use_bcopy
&& (nxgep
->niu_type
!= N2_NIU
)) {
430 bcopy_thresh
= (nxge_bcopy_thresh
- TX_PKT_HEADER_SIZE
);
432 bcopy_thresh
= (TX_BCOPY_SIZE
- TX_PKT_HEADER_SIZE
);
435 good_packet
= B_TRUE
;
436 b_rptr
= nmp
->b_rptr
;
444 NXGE_DEBUG_MSG((nxgep
, TX_CTL
, "==> nxge_start(1): nmblks %d "
445 "len %d pkt_len %d pack_len %d",
446 nmblks
, len
, pkt_len
, pack_len
));
448 * Hardware limits the transfer length to 4K for NIU and
449 * 4076 (TX_MAX_TRANSFER_LENGTH) for Neptune. But we just
450 * use TX_MAX_TRANSFER_LENGTH as the limit for both.
451 * If len is longer than the limit, then we break nmp into
452 * two chunks: Make the first chunk equal to the limit and
453 * the second chunk for the remaining data. If the second
454 * chunk is still larger than the limit, then it will be
455 * broken into two in the next pass.
457 if (len
> TX_MAX_TRANSFER_LENGTH
- TX_PKT_HEADER_SIZE
) {
458 if ((t_mp
= dupb(nmp
)) != NULL
) {
459 nmp
->b_wptr
= nmp
->b_rptr
+
460 (TX_MAX_TRANSFER_LENGTH
461 - TX_PKT_HEADER_SIZE
);
462 t_mp
->b_rptr
= nmp
->b_wptr
;
463 t_mp
->b_cont
= nmp
->b_cont
;
468 NXGE_DEBUG_MSG((nxgep
, TX_CTL
,
469 "LSO packet: dupb failed: "
473 goto nxge_start_fail_lso
;
475 good_packet
= B_FALSE
;
476 goto nxge_start_fail2
;
481 tx_desc_p
= &tx_desc_ring_vp
[i
];
483 tx_desc_pp
= &tx_desc_ring_pp
[i
];
485 tx_msg_p
= &tx_msg_ring
[i
];
487 npi_desc_handle
.regp
= (uint32_t)tx_desc_p
;
489 npi_desc_handle
.regp
= (uint64_t)tx_desc_p
;
492 ((!nxge_tx_use_bcopy
&& (len
> TX_BCOPY_SIZE
)) ||
493 (len
>= bcopy_thresh
))) {
495 bcopy_thresh
+= TX_PKT_HEADER_SIZE
;
498 kaddr
= (caddr_t
)DMA_COMMON_VPTR(tx_msg_p
->buf_dma
);
499 hdrp
= (p_tx_pkt_header_t
)kaddr
;
501 dma_handle
= tx_msg_p
->buf_dma_handle
;
502 dma_ioaddr
= DMA_COMMON_IOADDR(tx_msg_p
->buf_dma
);
503 (void) ddi_dma_sync(dma_handle
,
504 i
* nxge_bcopy_thresh
, nxge_bcopy_thresh
,
505 DDI_DMA_SYNC_FORDEV
);
507 tx_msg_p
->flags
.dma_type
= USE_BCOPY
;
508 goto nxge_start_control_header_only
;
514 NXGE_DEBUG_MSG((nxgep
, TX_CTL
, "==> nxge_start(3): "
517 "desc_vp $%p tx_desc_p $%p "
518 "desc_pp $%p tx_desc_pp $%p "
519 "len %d pkt_len %d pack_len %d",
521 DMA_COMMON_IOADDR(desc_area
),
522 tx_desc_ring_vp
, tx_desc_p
,
523 tx_desc_ring_pp
, tx_desc_pp
,
524 len
, pkt_len
, pack_len
));
526 if (len
< bcopy_thresh
) {
527 NXGE_DEBUG_MSG((nxgep
, TX_CTL
, "==> nxge_start(4): "
529 if (nxge_tx_tiny_pack
) {
531 TXDMA_DESC_NEXT_INDEX(i
, -1,
532 tx_ring_p
->tx_wrap_mask
);
533 NXGE_DEBUG_MSG((nxgep
, TX_CTL
,
534 "==> nxge_start(5): pack"));
535 if ((pack_len
<= bcopy_thresh
) &&
536 (last_bidx
== blst
)) {
537 NXGE_DEBUG_MSG((nxgep
, TX_CTL
,
538 "==> nxge_start: pack(6) "
539 "(pkt_len %d pack_len %d)",
542 tx_desc_p
= &tx_desc_ring_vp
[i
];
544 tx_desc_pp
= &tx_desc_ring_pp
[i
];
546 tx_msg_p
= &tx_msg_ring
[i
];
547 boff
= pack_len
- len
;
549 } else if (pack_len
> bcopy_thresh
&&
553 bcopy_thresh
= nxge_bcopy_thresh
;
554 NXGE_DEBUG_MSG((nxgep
, TX_CTL
,
555 "==> nxge_start(7): > max NEW "
557 "pkt_len %d pack_len %d(next)",
563 kaddr
= (caddr_t
)DMA_COMMON_VPTR(tx_msg_p
->buf_dma
);
564 if ((boff
== TX_PKT_HEADER_SIZE
) && (nmblks
== 1)) {
565 hdrp
= (p_tx_pkt_header_t
)kaddr
;
567 NXGE_DEBUG_MSG((nxgep
, TX_CTL
,
568 "==> nxge_start(7_x2): "
569 "pkt_len %d pack_len %d (new hdrp $%p)",
570 pkt_len
, pack_len
, hdrp
));
572 tx_msg_p
->flags
.dma_type
= USE_BCOPY
;
574 NXGE_DEBUG_MSG((nxgep
, TX_CTL
, "==> nxge_start(8): "
575 "USE BCOPY: before bcopy "
576 "DESC IOADDR $%p entry %d "
579 "bcopy ioaddr (SAD) $%p "
582 DMA_COMMON_IOADDR(desc_area
), i
,
583 tdc_stats
->tx_hdr_pkts
,
588 NXGE_DEBUG_MSG((nxgep
, TX_CTL
, "==> nxge_start: "
590 NXGE_DEBUG_MSG((nxgep
, TX_CTL
, "==> nxge_start: "
592 NXGE_DEBUG_MSG((nxgep
, TX_CTL
, "==> nxge_start: "
593 "last USE BCOPY: copy from b_rptr $%p "
594 "to KADDR $%p (len %d offset %d",
595 b_rptr
, kaddr
, len
, boff
));
597 bcopy(b_rptr
, kaddr
, len
);
600 dump_len
= (len
> 128) ? 128: len
;
601 NXGE_DEBUG_MSG((nxgep
, TX_CTL
,
602 "==> nxge_start: dump packets "
603 "(After BCOPY len %d)"
604 "(b_rptr $%p): %s", len
, nmp
->b_rptr
,
605 nxge_dump_packet((char *)nmp
->b_rptr
,
609 dma_handle
= tx_msg_p
->buf_dma_handle
;
610 dma_ioaddr
= DMA_COMMON_IOADDR(tx_msg_p
->buf_dma
);
611 (void) ddi_dma_sync(dma_handle
,
612 i
* nxge_bcopy_thresh
, nxge_bcopy_thresh
,
613 DDI_DMA_SYNC_FORDEV
);
615 tdc_stats
->tx_hdr_pkts
++;
616 NXGE_DEBUG_MSG((nxgep
, TX_CTL
, "==> nxge_start(9): "
618 "DESC IOADDR $%p entry %d "
621 "bcopy ioaddr (SAD) $%p "
624 DMA_COMMON_IOADDR(desc_area
),
626 tdc_stats
->tx_hdr_pkts
,
632 NXGE_DEBUG_MSG((nxgep
, TX_CTL
, "==> nxge_start(12): "
633 "USE DVMA: len %d", len
));
634 tx_msg_p
->flags
.dma_type
= USE_DMA
;
635 dma_flags
= DDI_DMA_WRITE
;
636 if (len
< nxge_dma_stream_thresh
) {
637 dma_flags
|= DDI_DMA_CONSISTENT
;
639 dma_flags
|= DDI_DMA_STREAMING
;
642 dma_handle
= tx_msg_p
->dma_handle
;
643 dma_status
= ddi_dma_addr_bind_handle(dma_handle
, NULL
,
644 (caddr_t
)b_rptr
, len
, dma_flags
,
645 DDI_DMA_DONTWAIT
, NULL
,
646 &dma_cookie
, &ncookies
);
647 if (dma_status
== DDI_DMA_MAPPED
) {
648 dma_ioaddr
= dma_cookie
.dmac_laddress
;
649 len
= (int)dma_cookie
.dmac_size
;
650 clen
= (uint32_t)dma_cookie
.dmac_size
;
651 NXGE_DEBUG_MSG((nxgep
, TX_CTL
,
652 "==> nxge_start(12_1): "
653 "USE DVMA: len %d clen %d "
658 npi_desc_handle
.regp
= (uint32_t)tx_desc_p
;
660 npi_desc_handle
.regp
= (uint64_t)tx_desc_p
;
662 while (ncookies
> 1) {
665 * this is the fix for multiple
666 * cookies, which are basically
667 * a descriptor entry, we don't set
668 * SOP bit as well as related fields
671 (void) npi_txdma_desc_gather_set(
680 tx_msg_p
->tx_msg_size
= clen
;
681 NXGE_DEBUG_MSG((nxgep
, TX_CTL
,
682 "==> nxge_start: DMA "
685 "dma_ioaddr $%p len %d"
686 "desc $%p descp $%p (%d)",
690 *tx_desc_p
, tx_desc_p
, i
));
692 ddi_dma_nextcookie(dma_handle
,
695 dma_cookie
.dmac_laddress
;
697 len
= (int)dma_cookie
.dmac_size
;
698 clen
= (uint32_t)dma_cookie
.dmac_size
;
699 NXGE_DEBUG_MSG((nxgep
, TX_CTL
,
700 "==> nxge_start(12_2): "
701 "USE DVMA: len %d clen %d ",
704 i
= TXDMA_DESC_NEXT_INDEX(i
, 1,
705 tx_ring_p
->tx_wrap_mask
);
706 tx_desc_p
= &tx_desc_ring_vp
[i
];
709 npi_desc_handle
.regp
=
712 npi_desc_handle
.regp
=
715 tx_msg_p
= &tx_msg_ring
[i
];
716 tx_msg_p
->flags
.dma_type
= USE_NONE
;
721 tdc_stats
->tx_ddi_pkts
++;
722 NXGE_DEBUG_MSG((nxgep
, TX_CTL
, "==> nxge_start:"
723 "DMA: ddi packets %d",
724 tdc_stats
->tx_ddi_pkts
));
726 NXGE_ERROR_MSG((nxgep
, NXGE_ERR_CTL
,
727 "dma mapping failed for %d "
728 "bytes addr $%p flags %x (%d)",
729 len
, b_rptr
, status
, status
));
730 good_packet
= B_FALSE
;
731 tdc_stats
->tx_dma_bind_fail
++;
732 tx_msg_p
->flags
.dma_type
= USE_NONE
;
735 goto nxge_start_fail_lso
;
738 goto nxge_start_fail2
;
747 nxge_start_control_header_only
:
749 npi_desc_handle
.regp
= (uint32_t)tx_desc_p
;
751 npi_desc_handle
.regp
= (uint64_t)tx_desc_p
;
757 save_desc_p
= &sop_tx_desc
;
759 sop_tx_desc_p
= &sop_tx_desc
;
760 sop_tx_desc_p
->value
= 0;
761 sop_tx_desc_p
->bits
.hdw
.tr_len
= clen
;
762 sop_tx_desc_p
->bits
.hdw
.sad
= dma_ioaddr
>> 32;
763 sop_tx_desc_p
->bits
.ldw
.sad
= dma_ioaddr
& 0xffffffff;
766 save_desc_p
= &tx_desc
;
768 tmp_desc_p
= &tx_desc
;
769 tmp_desc_p
->value
= 0;
770 tmp_desc_p
->bits
.hdw
.tr_len
= clen
;
771 tmp_desc_p
->bits
.hdw
.sad
= dma_ioaddr
>> 32;
772 tmp_desc_p
->bits
.ldw
.sad
= dma_ioaddr
& 0xffffffff;
774 tx_desc_p
->value
= tmp_desc_p
->value
;
777 NXGE_DEBUG_MSG((nxgep
, TX_CTL
, "==> nxge_start(13): "
778 "Desc_entry %d ngathers %d "
779 "desc_vp $%p tx_desc_p $%p "
780 "len %d clen %d pkt_len %d pack_len %d nmblks %d "
781 "dma_ioaddr (SAD) $%p mark %d",
783 tx_desc_ring_vp
, tx_desc_p
,
784 len
, clen
, pkt_len
, pack_len
, nmblks
,
785 dma_ioaddr
, mark_mode
));
788 npi_desc_handle
.nxgep
= nxgep
;
789 npi_desc_handle
.function
.function
= nxgep
->function_num
;
790 npi_desc_handle
.function
.instance
= nxgep
->instance
;
791 sad
= (save_desc_p
->value
& TX_PKT_DESC_SAD_MASK
);
792 xfer_len
= ((save_desc_p
->value
& TX_PKT_DESC_TR_LEN_MASK
) >>
793 TX_PKT_DESC_TR_LEN_SHIFT
);
796 NXGE_DEBUG_MSG((nxgep
, TX_CTL
, "\n\t: value 0x%llx\n"
797 "\t\tsad $%p\ttr_len %d len %d\tnptrs %d\t"
801 save_desc_p
->bits
.hdw
.tr_len
,
803 save_desc_p
->bits
.hdw
.num_ptr
,
804 save_desc_p
->bits
.hdw
.mark
,
805 save_desc_p
->bits
.hdw
.sop
));
807 npi_txdma_dump_desc_one(npi_desc_handle
, NULL
, i
);
810 tx_msg_p
->tx_msg_size
= clen
;
811 i
= TXDMA_DESC_NEXT_INDEX(i
, 1, tx_ring_p
->tx_wrap_mask
);
812 if (ngathers
> nxge_tx_max_gathers
) {
813 good_packet
= B_FALSE
;
814 mac_hcksum_get(mp
, &start_offset
,
815 &stuff_offset
, &end_offset
, &value
,
818 NXGE_DEBUG_MSG((NULL
, TX_CTL
,
819 "==> nxge_start(14): pull msg - "
820 "len %d pkt_len %d ngathers %d",
821 len
, pkt_len
, ngathers
));
824 * Just give up on this packet.
828 goto nxge_start_fail_lso
;
831 goto nxge_start_fail2
;
835 tx_msg_p
->tx_message
= mp
;
836 tx_desc_p
= &tx_desc_ring_vp
[sop_index
];
838 npi_desc_handle
.regp
= (uint32_t)tx_desc_p
;
840 npi_desc_handle
.regp
= (uint64_t)tx_desc_p
;
843 pkthdrp
= (p_tx_pkt_hdr_all_t
)hdrp
;
844 pkthdrp
->reserved
= 0;
846 bcopy(&tmp_hdrp
, hdrp
, sizeof (tx_pkt_header_t
));
848 if (pkt_len
> NXGE_MTU_DEFAULT_MAX
) {
849 tdc_stats
->tx_jumbo_pkts
++;
852 min_len
= (ETHERMIN
+ TX_PKT_HEADER_SIZE
+ (npads
* 2));
853 if (pkt_len
< min_len
) {
854 /* Assume we use bcopy to premapped buffers */
855 kaddr
= (caddr_t
)DMA_COMMON_VPTR(tx_msg_p
->buf_dma
);
856 NXGE_DEBUG_MSG((NULL
, TX_CTL
,
857 "==> nxge_start(14-1): < (msg_min + 16)"
858 "len %d pkt_len %d min_len %d bzero %d ngathers %d",
859 len
, pkt_len
, min_len
, (min_len
- pkt_len
), ngathers
));
860 bzero((kaddr
+ pkt_len
), (min_len
- pkt_len
));
861 pkt_len
= tx_msg_p
->tx_msg_size
= min_len
;
863 sop_tx_desc_p
->bits
.hdw
.tr_len
= min_len
;
865 NXGE_MEM_PIO_WRITE64(npi_desc_handle
, sop_tx_desc_p
->value
);
866 tx_desc_p
->value
= sop_tx_desc_p
->value
;
868 NXGE_DEBUG_MSG((NULL
, TX_CTL
,
869 "==> nxge_start(14-2): < msg_min - "
870 "len %d pkt_len %d min_len %d ngathers %d",
871 len
, pkt_len
, min_len
, ngathers
));
874 NXGE_DEBUG_MSG((nxgep
, TX_CTL
, "==> nxge_start: cksum_flags 0x%x ",
879 /* pkt_len already includes 16 + paddings!! */
880 /* Update the control header length */
881 tot_xfer_len
= (pkt_len
- TX_PKT_HEADER_SIZE
);
882 tmp_len
= hdrp
->value
|
883 (tot_xfer_len
<< TX_PKT_HEADER_TOT_XFER_LEN_SHIFT
);
885 NXGE_DEBUG_MSG((nxgep
, TX_CTL
,
886 "==> nxge_start(15_x1): setting SOP "
887 "tot_xfer_len 0x%llx (%d) pkt_len %d tmp_len "
888 "0x%llx hdrp->value 0x%llx",
889 tot_xfer_len
, tot_xfer_len
, pkt_len
,
890 tmp_len
, hdrp
->value
));
891 #if defined(_BIG_ENDIAN)
892 hdrp
->value
= ddi_swap64(tmp_len
);
894 hdrp
->value
= tmp_len
;
896 NXGE_DEBUG_MSG((nxgep
,
897 TX_CTL
, "==> nxge_start(15_x2): setting SOP "
898 "after SWAP: tot_xfer_len 0x%llx pkt_len %d "
899 "tmp_len 0x%llx hdrp->value 0x%llx",
900 tot_xfer_len
, pkt_len
,
901 tmp_len
, hdrp
->value
));
904 NXGE_DEBUG_MSG((nxgep
, TX_CTL
, "==> nxge_start(15): setting SOP "
906 "tot_xfer_len (%d) pkt_len %d npads %d",
908 tot_xfer_len
, pkt_len
,
911 sop_tx_desc_p
->bits
.hdw
.sop
= 1;
912 sop_tx_desc_p
->bits
.hdw
.mark
= mark_mode
;
913 sop_tx_desc_p
->bits
.hdw
.num_ptr
= ngathers
;
915 NXGE_MEM_PIO_WRITE64(npi_desc_handle
, sop_tx_desc_p
->value
);
917 NXGE_DEBUG_MSG((nxgep
, TX_CTL
, "==> nxge_start(16): set SOP done"));
920 npi_desc_handle
.nxgep
= nxgep
;
921 npi_desc_handle
.function
.function
= nxgep
->function_num
;
922 npi_desc_handle
.function
.instance
= nxgep
->instance
;
924 NXGE_DEBUG_MSG((nxgep
, TX_CTL
, "\n\t: value 0x%llx\n"
925 "\t\tsad $%p\ttr_len %d len %d\tnptrs %d\tmark %d sop %d\n",
928 save_desc_p
->bits
.hdw
.tr_len
,
930 save_desc_p
->bits
.hdw
.num_ptr
,
931 save_desc_p
->bits
.hdw
.mark
,
932 save_desc_p
->bits
.hdw
.sop
));
933 (void) npi_txdma_dump_desc_one(npi_desc_handle
, NULL
, sop_index
);
935 dump_len
= (pkt_len
> 128) ? 128: pkt_len
;
936 NXGE_DEBUG_MSG((nxgep
, TX_CTL
,
937 "==> nxge_start: dump packets(17) (after sop set, len "
938 " (len/dump_len/pkt_len/tot_xfer_len) %d/%d/%d/%d):\n"
939 "ptr $%p: %s", len
, dump_len
, pkt_len
, tot_xfer_len
,
941 nxge_dump_packet((char *)hdrp
, dump_len
)));
942 NXGE_DEBUG_MSG((nxgep
, TX_CTL
,
943 "==> nxge_start(18): TX desc sync: sop_index %d",
947 if ((ngathers
== 1) || tx_ring_p
->wr_index
< i
) {
948 (void) ddi_dma_sync(tx_desc_dma_handle
,
949 sop_index
* sizeof (tx_desc_t
),
950 ngathers
* sizeof (tx_desc_t
),
951 DDI_DMA_SYNC_FORDEV
);
953 NXGE_DEBUG_MSG((nxgep
, TX_CTL
, "nxge_start(19): sync 1 "
954 "cs_off = 0x%02X cs_s_off = 0x%02X "
955 "pkt_len %d ngathers %d sop_index %d\n",
956 stuff_offset
, start_offset
,
957 pkt_len
, ngathers
, sop_index
));
958 } else { /* more than one descriptor and wrap around */
959 uint32_t nsdescs
= tx_ring_p
->tx_ring_size
- sop_index
;
960 (void) ddi_dma_sync(tx_desc_dma_handle
,
961 sop_index
* sizeof (tx_desc_t
),
962 nsdescs
* sizeof (tx_desc_t
),
963 DDI_DMA_SYNC_FORDEV
);
964 NXGE_DEBUG_MSG((nxgep
, TX_CTL
, "nxge_start(20): sync 1 "
965 "cs_off = 0x%02X cs_s_off = 0x%02X "
966 "pkt_len %d ngathers %d sop_index %d\n",
967 stuff_offset
, start_offset
,
968 pkt_len
, ngathers
, sop_index
));
970 (void) ddi_dma_sync(tx_desc_dma_handle
,
972 (ngathers
- nsdescs
) * sizeof (tx_desc_t
),
973 DDI_DMA_SYNC_FORDEV
);
974 NXGE_DEBUG_MSG((nxgep
, TX_CTL
, "nxge_start(21): sync 2 "
975 "cs_off = 0x%02X cs_s_off = 0x%02X "
976 "pkt_len %d ngathers %d sop_index %d\n",
977 stuff_offset
, start_offset
,
978 pkt_len
, ngathers
, sop_index
));
981 tail_index
= tx_ring_p
->wr_index
;
982 tail_wrap
= tx_ring_p
->wr_index_wrap
;
984 tx_ring_p
->wr_index
= i
;
985 if (tx_ring_p
->wr_index
<= tail_index
) {
986 tx_ring_p
->wr_index_wrap
= ((tail_wrap
== B_TRUE
) ?
990 NXGE_DEBUG_MSG((nxgep
, TX_CTL
, "==> nxge_start: TX kick: "
991 "channel %d wr_index %d wrap %d ngathers %d desc_pend %d",
994 tx_ring_p
->wr_index_wrap
,
996 tx_ring_p
->descs_pending
));
999 lso_ngathers
+= ngathers
;
1000 if (mp_chain
!= NULL
) {
1002 mp_chain
= mp_chain
->b_next
;
1004 if (nxge_lso_kick_cnt
== lso_ngathers
) {
1005 tx_ring_p
->descs_pending
+= lso_ngathers
;
1007 tx_ring_kick_t kick
;
1010 kick
.bits
.ldw
.wrap
=
1011 tx_ring_p
->wr_index_wrap
;
1012 kick
.bits
.ldw
.tail
=
1013 (uint16_t)tx_ring_p
->wr_index
;
1015 /* Kick the Transmit kick register */
1017 NXGE_DEV_NPI_HANDLE(nxgep
),
1019 (uint8_t)tx_ring_p
->tdc
,
1021 tdc_stats
->tx_starts
++;
1023 NXGE_DEBUG_MSG((nxgep
, TX_CTL
,
1024 "==> nxge_start: more LSO: "
1030 cur_index_lso
= sop_index
= tx_ring_p
->wr_index
;
1031 lso_tail_wrap
= tx_ring_p
->wr_index_wrap
;
1033 NXGE_DEBUG_MSG((nxgep
, TX_CTL
,
1034 "==> nxge_start: lso again: "
1035 "lso_gathers %d ngathers %d cur_index_lso %d "
1036 "wr_index %d sop_index %d",
1037 lso_ngathers
, ngathers
, cur_index_lso
,
1038 tx_ring_p
->wr_index
, sop_index
));
1040 NXGE_DEBUG_MSG((nxgep
, TX_CTL
,
1041 "==> nxge_start: next : count %d",
1046 ngathers
= lso_ngathers
;
1049 NXGE_DEBUG_MSG((nxgep
, TX_CTL
, "==> nxge_start: TX KICKING: "));
1052 tx_ring_kick_t kick
;
1055 kick
.bits
.ldw
.wrap
= tx_ring_p
->wr_index_wrap
;
1056 kick
.bits
.ldw
.tail
= (uint16_t)tx_ring_p
->wr_index
;
1058 /* Kick start the Transmit kick register */
1059 TXDMA_REG_WRITE64(NXGE_DEV_NPI_HANDLE(nxgep
),
1061 (uint8_t)tx_ring_p
->tdc
,
1065 tx_ring_p
->descs_pending
+= ngathers
;
1066 tdc_stats
->tx_starts
++;
1068 if (isLDOMservice(nxgep
)) {
1069 tx_ring_p
->tx_ring_busy
= B_FALSE
;
1070 if (tx_ring_p
->tx_ring_offline
) {
1071 (void) atomic_swap_32(&tx_ring_p
->tx_ring_offline
,
1072 NXGE_TX_RING_OFFLINED
);
1076 MUTEX_EXIT(&tx_ring_p
->lock
);
1078 NXGE_DEBUG_MSG((nxgep
, TX_CTL
, "<== nxge_start"));
1081 nxge_start_fail_lso
:
1083 good_packet
= B_FALSE
;
1086 if (mp_chain
!= NULL
)
1087 freemsgchain(mp_chain
);
1089 if (!lso_again
&& !ngathers
) {
1090 if (isLDOMservice(nxgep
)) {
1091 tx_ring_p
->tx_ring_busy
= B_FALSE
;
1092 if (tx_ring_p
->tx_ring_offline
) {
1093 (void) atomic_swap_32(
1094 &tx_ring_p
->tx_ring_offline
,
1095 NXGE_TX_RING_OFFLINED
);
1099 MUTEX_EXIT(&tx_ring_p
->lock
);
1100 NXGE_DEBUG_MSG((nxgep
, TX_CTL
,
1101 "==> nxge_start: lso exit (nothing changed)"));
1102 goto nxge_start_fail1
;
1105 NXGE_DEBUG_MSG((nxgep
, TX_CTL
,
1106 "==> nxge_start (channel %d): before lso "
1107 "lso_gathers %d ngathers %d cur_index_lso %d "
1108 "wr_index %d sop_index %d lso_again %d",
1110 lso_ngathers
, ngathers
, cur_index_lso
,
1111 tx_ring_p
->wr_index
, sop_index
, lso_again
));
1114 lso_ngathers
+= ngathers
;
1115 ngathers
= lso_ngathers
;
1116 sop_index
= cur_index_lso
;
1117 tx_ring_p
->wr_index
= sop_index
;
1118 tx_ring_p
->wr_index_wrap
= lso_tail_wrap
;
1121 NXGE_DEBUG_MSG((nxgep
, TX_CTL
,
1122 "==> nxge_start (channel %d): after lso "
1123 "lso_gathers %d ngathers %d cur_index_lso %d "
1124 "wr_index %d sop_index %d lso_again %d",
1126 lso_ngathers
, ngathers
, cur_index_lso
,
1127 tx_ring_p
->wr_index
, sop_index
, lso_again
));
1130 if (good_packet
== B_FALSE
) {
1131 cur_index
= sop_index
;
1132 NXGE_DEBUG_MSG((nxgep
, TX_CTL
, "==> nxge_start: clean up"));
1133 for (i
= 0; i
< ngathers
; i
++) {
1134 tx_desc_p
= &tx_desc_ring_vp
[cur_index
];
1136 npi_handle
.regp
= (uint32_t)tx_desc_p
;
1138 npi_handle
.regp
= (uint64_t)tx_desc_p
;
1140 tx_msg_p
= &tx_msg_ring
[cur_index
];
1141 (void) npi_txdma_desc_set_zero(npi_handle
, 1);
1142 if (tx_msg_p
->flags
.dma_type
== USE_DVMA
) {
1143 NXGE_DEBUG_MSG((nxgep
, TX_CTL
,
1144 "tx_desc_p = %X index = %d",
1145 tx_desc_p
, tx_ring_p
->rd_index
));
1146 (void) dvma_unload(tx_msg_p
->dvma_handle
,
1148 tx_msg_p
->dvma_handle
= NULL
;
1149 if (tx_ring_p
->dvma_wr_index
==
1150 tx_ring_p
->dvma_wrap_mask
)
1151 tx_ring_p
->dvma_wr_index
= 0;
1153 tx_ring_p
->dvma_wr_index
++;
1154 tx_ring_p
->dvma_pending
--;
1155 } else if (tx_msg_p
->flags
.dma_type
== USE_DMA
) {
1156 if (ddi_dma_unbind_handle(
1157 tx_msg_p
->dma_handle
)) {
1158 cmn_err(CE_WARN
, "!nxge_start: "
1159 "ddi_dma_unbind_handle failed");
1162 tx_msg_p
->flags
.dma_type
= USE_NONE
;
1163 cur_index
= TXDMA_DESC_NEXT_INDEX(cur_index
, 1,
1164 tx_ring_p
->tx_wrap_mask
);
1169 if (isLDOMservice(nxgep
)) {
1170 tx_ring_p
->tx_ring_busy
= B_FALSE
;
1171 if (tx_ring_p
->tx_ring_offline
) {
1172 (void) atomic_swap_32(&tx_ring_p
->tx_ring_offline
,
1173 NXGE_TX_RING_OFFLINED
);
1177 MUTEX_EXIT(&tx_ring_p
->lock
);
1180 /* Add FMA to check the access handle nxge_hregh */
1182 NXGE_DEBUG_MSG((nxgep
, TX_CTL
, "<== nxge_start"));
1186 /* Software LSO starts here */
1188 nxge_hcksum_retrieve(mblk_t
*mp
,
1189 uint32_t *start
, uint32_t *stuff
, uint32_t *end
,
1190 uint32_t *value
, uint32_t *flags
)
1192 if (mp
->b_datap
->db_type
== M_DATA
) {
1193 if (flags
!= NULL
) {
1194 *flags
= DB_CKSUMFLAGS(mp
) & (HCK_IPV4_HDRCKSUM
|
1195 HCK_PARTIALCKSUM
| HCK_FULLCKSUM
|
1197 if ((*flags
& (HCK_PARTIALCKSUM
|
1198 HCK_FULLCKSUM
)) != 0) {
1200 *value
= (uint32_t)DB_CKSUM16(mp
);
1201 if ((*flags
& HCK_PARTIALCKSUM
) != 0) {
1204 (uint32_t)DB_CKSUMSTART(mp
);
1207 (uint32_t)DB_CKSUMSTUFF(mp
);
1210 (uint32_t)DB_CKSUMEND(mp
);
1218 nxge_lso_info_get(mblk_t
*mp
, uint32_t *mss
, uint32_t *flags
)
1220 ASSERT(DB_TYPE(mp
) == M_DATA
);
1223 if (flags
!= NULL
) {
1224 *flags
= DB_CKSUMFLAGS(mp
) & HW_LSO
;
1225 if ((*flags
!= 0) && (mss
!= NULL
)) {
1226 *mss
= (uint32_t)DB_LSOMSS(mp
);
1228 NXGE_DEBUG_MSG((NULL
, TX_CTL
,
1229 "==> nxge_lso_info_get(flag !=NULL): mss %d *flags 0x%x",
1233 NXGE_DEBUG_MSG((NULL
, TX_CTL
,
1234 "<== nxge_lso_info_get: mss %d", *mss
));
1238 * Do Soft LSO on the oversized packet.
1240 * 1. Create a chain of message for headers.
1241 * 2. Fill up header messages with proper information.
1242 * 3. Copy Eithernet, IP, and TCP headers from the original message to
1243 * each new message with necessary adjustments.
1244 * * Unchange the ethernet header for DIX frames. (by default)
1245 * * IP Total Length field is updated to MSS or less(only for the last one).
1246 * * IP Identification value is incremented by one for each packet.
1247 * * TCP sequence Number is recalculated according to the payload length.
1248 * * Set FIN and/or PSH flags for the *last* packet if applied.
1249 * * TCP partial Checksum
1250 * 4. Update LSO information in the first message header.
1251 * 5. Release the original message header.
1254 nxge_do_softlso(mblk_t
*mp
, uint32_t mss
)
1261 struct ether_vlan_header
*evh
;
1262 int ehlen
, iphlen
, tcphlen
;
1263 struct ip
*oiph
, *niph
;
1264 struct tcphdr
*otcph
, *ntcph
;
1265 int available
, len
, left
;
1273 boolean_t do_cleanup
= B_FALSE
;
1274 t_uscalar_t start_offset
= 0;
1275 t_uscalar_t stuff_offset
= 0;
1276 t_uscalar_t value
= 0;
1279 uint32_t cksum
, sum
, l4cksum
;
1281 NXGE_DEBUG_MSG((NULL
, TX_CTL
,
1282 "==> nxge_do_softlso"));
1284 * check the length of LSO packet payload and calculate the number of
1285 * segments to be generated.
1287 pktlen
= msgsize(mp
);
1288 evh
= (struct ether_vlan_header
*)mp
->b_rptr
;
1291 if (evh
->ether_tpid
== htons(ETHERTYPE_VLAN
))
1292 ehlen
= sizeof (struct ether_vlan_header
);
1294 ehlen
= sizeof (struct ether_header
);
1295 oiph
= (struct ip
*)(mp
->b_rptr
+ ehlen
);
1296 iphlen
= oiph
->ip_hl
* 4;
1297 otcph
= (struct tcphdr
*)(mp
->b_rptr
+ ehlen
+ iphlen
);
1298 tcphlen
= otcph
->th_off
* 4;
1300 l4_len
= pktlen
- ehlen
- iphlen
;
1302 NXGE_DEBUG_MSG((NULL
, TX_CTL
,
1303 "==> nxge_do_softlso: mss %d oiph $%p "
1304 "original ip_sum oiph->ip_sum 0x%x "
1305 "original tcp_sum otcph->th_sum 0x%x "
1306 "oiph->ip_len %d pktlen %d ehlen %d "
1307 "l4_len %d (0x%x) ip_len - iphlen %d ",
1312 ntohs(oiph
->ip_len
), pktlen
,
1316 ntohs(oiph
->ip_len
) - iphlen
));
1319 if (!(oiph
->ip_v
== IPV4_VERSION
)) {
1320 NXGE_ERROR_MSG((NULL
, NXGE_ERR_CTL
,
1321 "<== nxge_do_softlso: not IPV4 "
1322 "oiph->ip_len %d pktlen %d ehlen %d tcphlen %d",
1323 ntohs(oiph
->ip_len
), pktlen
, ehlen
,
1329 if (!(oiph
->ip_p
== IPPROTO_TCP
)) {
1330 NXGE_ERROR_MSG((NULL
, NXGE_ERR_CTL
,
1331 "<== nxge_do_softlso: not TCP "
1332 "oiph->ip_len %d pktlen %d ehlen %d tcphlen %d",
1333 ntohs(oiph
->ip_len
), pktlen
, ehlen
,
1339 if (!(ntohs(oiph
->ip_len
) == pktlen
- ehlen
)) {
1340 NXGE_ERROR_MSG((NULL
, NXGE_ERR_CTL
,
1341 "<== nxge_do_softlso: len not matched "
1342 "oiph->ip_len %d pktlen %d ehlen %d tcphlen %d",
1343 ntohs(oiph
->ip_len
), pktlen
, ehlen
,
1349 otcph
= (struct tcphdr
*)(mp
->b_rptr
+ ehlen
+ iphlen
);
1350 tcphlen
= otcph
->th_off
* 4;
1352 /* TCP flags can not include URG, RST, or SYN */
1353 VERIFY((otcph
->th_flags
& (TH_SYN
| TH_RST
| TH_URG
)) == 0);
1355 hdrlen
= ehlen
+ iphlen
+ tcphlen
;
1357 VERIFY(MBLKL(mp
) >= hdrlen
);
1359 if (MBLKL(mp
) > hdrlen
) {
1361 rptr
= mp
->b_rptr
+ hdrlen
;
1363 datamp
= mp
->b_cont
;
1364 rptr
= datamp
->b_rptr
;
1367 NXGE_DEBUG_MSG((NULL
, TX_CTL
,
1368 "nxge_do_softlso: otcph $%p pktlen: %d, "
1369 "hdrlen %d ehlen %d iphlen %d tcphlen %d "
1370 "mblkl(mp): %d, mblkl(datamp): %d",
1372 pktlen
, hdrlen
, ehlen
, iphlen
, tcphlen
,
1373 (int)MBLKL(mp
), (int)MBLKL(datamp
)));
1376 nxge_hcksum_retrieve(mp
,
1377 &start_offset
, &stuff_offset
, &value
, NULL
, &hckflags
);
1379 dst
= oiph
->ip_dst
.s_addr
;
1380 src
= oiph
->ip_src
.s_addr
;
1382 cksum
= (dst
>> 16) + (dst
& 0xFFFF) +
1383 (src
>> 16) + (src
& 0xFFFF);
1384 l4cksum
= cksum
+ IP_TCP_CSUM_COMP
;
1386 sum
= l4_len
+ l4cksum
;
1387 sum
= (sum
& 0xFFFF) + (sum
>> 16);
1389 NXGE_DEBUG_MSG((NULL
, TX_CTL
,
1390 "==> nxge_do_softlso: dst 0x%x src 0x%x sum 0x%x ~new 0x%x "
1391 "hckflags 0x%x start_offset %d stuff_offset %d "
1392 "value (original) 0x%x th_sum 0x%x "
1393 "pktlen %d l4_len %d (0x%x) "
1394 "MBLKL(mp): %d, MBLKL(datamp): %d dump header %s",
1396 (sum
& 0xffff), (~sum
& 0xffff),
1397 hckflags
, start_offset
, stuff_offset
,
1398 value
, otcph
->th_sum
,
1402 ntohs(oiph
->ip_len
) - (int)MBLKL(mp
),
1404 nxge_dump_packet((char *)evh
, 12)));
1409 available
= pktlen
- hdrlen
;
1410 segnum
= (available
- 1) / mss
+ 1;
1412 NXGE_DEBUG_MSG((NULL
, TX_CTL
,
1413 "==> nxge_do_softlso: pktlen %d "
1414 "MBLKL(mp): %d, MBLKL(datamp): %d "
1415 "available %d mss %d segnum %d",
1416 pktlen
, (int)MBLKL(mp
), (int)MBLKL(datamp
),
1421 VERIFY(segnum
>= 2);
1424 * Try to pre-allocate all header messages
1427 for (i
= 0; i
< segnum
; i
++) {
1428 if ((nmp
= allocb(hdrlen
, 0)) == NULL
) {
1429 /* Clean up the mp_chain */
1430 while (mp_chain
!= NULL
) {
1432 mp_chain
= mp_chain
->b_next
;
1435 NXGE_DEBUG_MSG((NULL
, TX_CTL
,
1436 "<== nxge_do_softlso: "
1437 "Could not allocate enough messages for headers!"));
1441 nmp
->b_next
= mp_chain
;
1444 NXGE_DEBUG_MSG((NULL
, TX_CTL
,
1445 "==> nxge_do_softlso: "
1446 "mp $%p nmp $%p mp_chain $%p mp_chain->b_next $%p",
1447 mp
, nmp
, mp_chain
, mp_chain
->b_next
));
1450 NXGE_DEBUG_MSG((NULL
, TX_CTL
,
1451 "==> nxge_do_softlso: mp $%p nmp $%p mp_chain $%p",
1452 mp
, nmp
, mp_chain
));
1455 * Associate payload with new packets
1459 while (cmp
!= NULL
) {
1462 do_cleanup
= B_TRUE
;
1463 NXGE_DEBUG_MSG((NULL
, TX_CTL
,
1464 "==>nxge_do_softlso: "
1465 "Can not dupb(datamp), have to do clean up"));
1466 goto cleanup_allocated_msgs
;
1469 NXGE_DEBUG_MSG((NULL
, TX_CTL
,
1470 "==> nxge_do_softlso: (loop) before mp $%p cmp $%p "
1471 "dupb nmp $%p len %d left %d msd %d ",
1472 mp
, cmp
, nmp
, len
, left
, mss
));
1476 len
= (left
< mss
) ? left
: mss
;
1479 NXGE_DEBUG_MSG((NULL
, TX_CTL
,
1480 "==> nxge_do_softlso: (loop) after mp $%p cmp $%p "
1481 "dupb nmp $%p len %d left %d mss %d ",
1482 mp
, cmp
, nmp
, len
, left
, mss
));
1483 NXGE_DEBUG_MSG((NULL
, TX_CTL
,
1484 "nxge_do_softlso: before available: %d, "
1485 "left: %d, len: %d, segnum: %d MBLK(nmp): %d",
1486 available
, left
, len
, segnum
, (int)MBLKL(nmp
)));
1489 NXGE_DEBUG_MSG((NULL
, TX_CTL
,
1490 "nxge_do_softlso: after available: %d, "
1491 "left: %d, len: %d, segnum: %d MBLK(nmp): %d",
1492 available
, left
, len
, segnum
, (int)MBLKL(nmp
)));
1497 NXGE_DEBUG_MSG((NULL
, TX_CTL
,
1498 "nxge_do_softlso: (4) len > 0 available: %d, "
1499 "left: %d, len: %d, segnum: %d MBLK(nmp): %d",
1500 available
, left
, len
, segnum
, (int)MBLKL(nmp
)));
1502 if (datamp
->b_cont
!= NULL
) {
1503 datamp
= datamp
->b_cont
;
1504 rptr
= datamp
->b_rptr
;
1507 do_cleanup
= B_TRUE
;
1508 NXGE_DEBUG_MSG((NULL
, TX_CTL
,
1509 "==> nxge_do_softlso: "
1510 "Can not dupb(datamp) (1), :"
1511 "have to do clean up"));
1512 NXGE_DEBUG_MSG((NULL
, TX_CTL
,
1513 "==> nxge_do_softlso: "
1514 "available: %d, left: %d, "
1515 "len: %d, MBLKL(nmp): %d",
1516 available
, left
, len
,
1518 goto cleanup_allocated_msgs
;
1521 NXGE_ERROR_MSG((NULL
, NXGE_ERR_CTL
,
1522 "==> nxge_do_softlso: "
1523 "(1)available: %d, left: %d, "
1524 "len: %d, MBLKL(nmp): %d",
1525 available
, left
, len
,
1528 "==> nxge_do_softlso: "
1529 "Pointers must have been corrupted!\n"
1530 "datamp: $%p, nmp: $%p, rptr: $%p",
1542 NXGE_DEBUG_MSG((NULL
, TX_CTL
,
1543 "(5) len < 0 (less than 0)"
1544 "available: %d, left: %d, len: %d, MBLKL(nmp): %d",
1545 available
, left
, len
, (int)MBLKL(nmp
)));
1547 } else if (len
== 0) {
1548 if (datamp
->b_cont
!= NULL
) {
1549 NXGE_DEBUG_MSG((NULL
, TX_CTL
,
1551 "available: %d, left: %d, len: %d, "
1553 available
, left
, len
, (int)MBLKL(nmp
)));
1554 datamp
= datamp
->b_cont
;
1555 rptr
= datamp
->b_rptr
;
1557 NXGE_DEBUG_MSG((NULL
, TX_CTL
,
1558 "(6)available b_cont == NULL : %d, "
1559 "left: %d, len: %d, MBLKL(nmp): %d",
1560 available
, left
, len
, (int)MBLKL(nmp
)));
1562 VERIFY(cmp
->b_next
== NULL
);
1569 NXGE_DEBUG_MSG((NULL
, TX_CTL
,
1571 "next mp in mp_chain available len != 0 : %d, "
1572 "left: %d, len: %d, MBLKL(nmp): %d",
1573 available
, left
, len
, (int)MBLKL(nmp
)));
1577 * From now, start to fill up all headers for the first message
1578 * Hardware checksum flags need to be updated separately for FULLCKSUM
1579 * and PARTIALCKSUM cases. For full checksum, copy the original flags
1580 * into every new packet is enough. But for HCK_PARTIALCKSUM, all
1581 * required fields need to be updated properly.
1584 bcopy(mp
->b_rptr
, nmp
->b_rptr
, hdrlen
);
1585 nmp
->b_wptr
= nmp
->b_rptr
+ hdrlen
;
1586 niph
= (struct ip
*)(nmp
->b_rptr
+ ehlen
);
1587 niph
->ip_len
= htons(mss
+ iphlen
+ tcphlen
);
1588 ip_id
= ntohs(niph
->ip_id
);
1589 ntcph
= (struct tcphdr
*)(nmp
->b_rptr
+ ehlen
+ iphlen
);
1590 tcp_seq
= ntohl(ntcph
->th_seq
);
1592 ntcph
->th_flags
&= ~(TH_FIN
| TH_PUSH
| TH_RST
);
1594 DB_CKSUMFLAGS(nmp
) = (uint16_t)hckflags
;
1595 DB_CKSUMSTART(nmp
) = start_offset
;
1596 DB_CKSUMSTUFF(nmp
) = stuff_offset
;
1598 /* calculate IP checksum and TCP pseudo header checksum */
1600 niph
->ip_sum
= (uint16_t)nxge_csgen((uint16_t *)niph
, iphlen
);
1602 l4_len
= mss
+ tcphlen
;
1603 sum
= htons(l4_len
) + l4cksum
;
1604 sum
= (sum
& 0xFFFF) + (sum
>> 16);
1605 ntcph
->th_sum
= (sum
& 0xffff);
1607 NXGE_DEBUG_MSG((NULL
, TX_CTL
,
1608 "==> nxge_do_softlso: first mp $%p (mp_chain $%p) "
1609 "mss %d pktlen %d l4_len %d (0x%x) "
1610 "MBLKL(mp): %d, MBLKL(datamp): %d "
1612 "th_sum 0x%x sum 0x%x ) "
1613 "dump first ip->tcp %s",
1619 (int)MBLKL(mp
), (int)MBLKL(datamp
),
1623 nxge_dump_packet((char *)niph
, 52)));
1626 while ((nmp
= nmp
->b_next
)->b_next
!= NULL
) {
1627 NXGE_DEBUG_MSG((NULL
, TX_CTL
,
1628 "==>nxge_do_softlso: middle l4_len %d ", l4_len
));
1629 bcopy(cmp
->b_rptr
, nmp
->b_rptr
, hdrlen
);
1630 nmp
->b_wptr
= nmp
->b_rptr
+ hdrlen
;
1631 niph
= (struct ip
*)(nmp
->b_rptr
+ ehlen
);
1632 niph
->ip_id
= htons(++ip_id
);
1633 niph
->ip_len
= htons(mss
+ iphlen
+ tcphlen
);
1634 ntcph
= (struct tcphdr
*)(nmp
->b_rptr
+ ehlen
+ iphlen
);
1637 ntcph
->th_flags
&= ~(TH_FIN
| TH_PUSH
| TH_RST
| TH_URG
);
1639 ntcph
->th_seq
= htonl(tcp_seq
);
1640 DB_CKSUMFLAGS(nmp
) = (uint16_t)hckflags
;
1641 DB_CKSUMSTART(nmp
) = start_offset
;
1642 DB_CKSUMSTUFF(nmp
) = stuff_offset
;
1644 /* calculate IP checksum and TCP pseudo header checksum */
1646 niph
->ip_sum
= (uint16_t)nxge_csgen((uint16_t *)niph
, iphlen
);
1647 ntcph
->th_sum
= (sum
& 0xffff);
1649 NXGE_DEBUG_MSG((NULL
, TX_CTL
,
1650 "==> nxge_do_softlso: middle ip_sum 0x%x "
1652 " mp $%p (mp_chain $%p) pktlen %d "
1653 "MBLKL(mp): %d, MBLKL(datamp): %d ",
1657 pktlen
, (int)MBLKL(mp
), (int)MBLKL(datamp
)));
1662 * Set FIN and/or PSH flags if present only in the last packet.
1663 * The ip_len could be different from prior packets.
1665 bcopy(cmp
->b_rptr
, nmp
->b_rptr
, hdrlen
);
1666 nmp
->b_wptr
= nmp
->b_rptr
+ hdrlen
;
1667 niph
= (struct ip
*)(nmp
->b_rptr
+ ehlen
);
1668 niph
->ip_id
= htons(++ip_id
);
1669 niph
->ip_len
= htons(msgsize(nmp
->b_cont
) + iphlen
+ tcphlen
);
1670 ntcph
= (struct tcphdr
*)(nmp
->b_rptr
+ ehlen
+ iphlen
);
1672 ntcph
->th_seq
= htonl(tcp_seq
);
1673 ntcph
->th_flags
= (otcph
->th_flags
& ~TH_URG
);
1675 DB_CKSUMFLAGS(nmp
) = (uint16_t)hckflags
;
1676 DB_CKSUMSTART(nmp
) = start_offset
;
1677 DB_CKSUMSTUFF(nmp
) = stuff_offset
;
1679 /* calculate IP checksum and TCP pseudo header checksum */
1681 niph
->ip_sum
= (uint16_t)nxge_csgen((uint16_t *)niph
, iphlen
);
1683 l4_len
= ntohs(niph
->ip_len
) - iphlen
;
1684 sum
= htons(l4_len
) + l4cksum
;
1685 sum
= (sum
& 0xFFFF) + (sum
>> 16);
1686 ntcph
->th_sum
= (sum
& 0xffff);
1688 NXGE_DEBUG_MSG((NULL
, TX_CTL
,
1689 "==> nxge_do_softlso: last next "
1690 "niph->ip_sum 0x%x "
1691 "ntcph->th_sum 0x%x sum 0x%x "
1692 "dump last ip->tcp %s "
1693 "cmp $%p mp $%p (mp_chain $%p) pktlen %d (0x%x) "
1695 "MBLKL(mp): %d, MBLKL(datamp): %d ",
1698 nxge_dump_packet((char *)niph
, 52),
1703 (int)MBLKL(mp
), (int)MBLKL(datamp
)));
1705 cleanup_allocated_msgs
:
1707 NXGE_DEBUG_MSG((NULL
, TX_CTL
,
1708 "==> nxge_do_softlso: "
1709 "Failed allocating messages, "
1710 "have to clean up and fail!"));
1711 while (mp_chain
!= NULL
) {
1713 mp_chain
= mp_chain
->b_next
;
1718 * We're done here, so just free the original message and return the
1719 * new message chain, that could be NULL if failed, back to the caller.
1723 NXGE_DEBUG_MSG((NULL
, TX_CTL
,
1724 "<== nxge_do_softlso:mp_chain $%p", mp_chain
));
1729 * Will be called before NIC driver do further operation on the message.
1730 * The input message may include LSO information, if so, go to softlso logic
1731 * to eliminate the oversized LSO packet for the incapable underlying h/w.
1732 * The return could be the same non-LSO message or a message chain for LSO case.
1734 * The driver needs to call this function per packet and process the whole chain
1738 nxge_lso_eliminate(mblk_t
*mp
)
1743 NXGE_DEBUG_MSG((NULL
, TX_CTL
,
1744 "==>nxge_lso_eliminate:"));
1745 nxge_lso_info_get(mp
, &mss
, &lsoflags
);
1747 if (lsoflags
& HW_LSO
) {
1750 NXGE_DEBUG_MSG((NULL
, TX_CTL
,
1751 "==>nxge_lso_eliminate:"
1752 "HW_LSO:mss %d mp $%p",
1754 if ((nmp
= nxge_do_softlso(mp
, mss
)) != NULL
) {
1755 NXGE_DEBUG_MSG((NULL
, TX_CTL
,
1756 "<== nxge_lso_eliminate: "
1757 "LSO: nmp not NULL nmp $%p mss %d mp $%p",
1761 NXGE_DEBUG_MSG((NULL
, TX_CTL
,
1762 "<== nxge_lso_eliminate_ "
1763 "LSO: failed nmp NULL nmp $%p mss %d mp $%p",
1769 NXGE_DEBUG_MSG((NULL
, TX_CTL
,
1770 "<== nxge_lso_eliminate"));
1775 nxge_csgen(uint16_t *adr
, int len
)
1782 for (i
= 0; i
< (len
/ 2); i
++) {
1783 sum
+= (adr
[i
] & 0xffff);
1786 sum
+= adr
[len
/ 2] & 0xff00;
1788 while ((c
= ((sum
& 0xffff0000) >> 16)) != 0) {
1792 return (~sum
& 0xffff);