nxge_send.c revision 3d16f8e771544ca454864650bbe6fa545a2d7dd2
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/* Software LSO required header files */
static void nxge_hcksum_retrieve(mblk_t *,
extern uint32_t nxge_reclaim_pending;
extern uint32_t nxge_bcopy_thresh;
extern uint32_t nxge_dvma_thresh;
extern uint32_t nxge_dma_stream_thresh;
extern uint32_t nxge_tx_minfree;
extern uint32_t nxge_tx_intr_thres;
extern uint32_t nxge_tx_max_gathers;
extern uint32_t nxge_tx_tiny_pack;
extern uint32_t nxge_tx_use_bcopy;
extern uint32_t nxge_tx_lb_policy;
extern uint32_t nxge_no_tx_lb;
extern nxge_tx_mode_t nxge_tx_scheme;
typedef struct _mac_tx_hint {
void *hash;
int
{
int status = 0;
int last_bidx;
int len;
t_uscalar_t start_offset = 0;
t_uscalar_t stuff_offset = 0;
t_uscalar_t end_offset = 0;
t_uscalar_t value = 0;
t_uscalar_t cksum_flags = 0;
#ifdef NXGE_DEBUG
int dump_len;
int sad_len;
int xfer_len;
#endif
int cur_index_lso;
"==> nxge_start: Starting tdc %d desc pending %d",
"link not up or LB mode"));
goto nxge_start_fail1;
}
}
if (nxgep->soft_lso_enable) {
"==> nxge_start(0): LSO mp $%p mp_chain $%p",
"==> nxge_send(0): NULL mp_chain $%p != mp $%p",
goto nxge_start_fail1;
}
"==> nxge_send(1): IS LSO mp_chain $%p != mp $%p",
}
}
start_offset += sizeof (ether_header_t);
stuff_offset += sizeof (ether_header_t);
} else {
start_offset += sizeof (struct ether_vlan_header);
stuff_offset += sizeof (struct ether_vlan_header);
}
if (cksum_flags & HCK_PARTIALCKSUM) {
"==> nxge_start: mp $%p len %d "
"cksum_flags 0x%x (partial checksum) ",
}
lso_ngathers = 0;
ngathers = 0;
#ifdef NXGE_DEBUG
if (tx_ring_p->descs_pending) {
}
"==> nxge_start: tdc %d: dumping ...: b_rptr $%p "
"(Before header reserve: ORIGINAL LEN %d)",
dump_len));
#endif
< nxge_tx_minfree));
"TX Descriptor ring is channel %d mark mode %d",
"TX Descriptor ring is full: channel %d",
"TX Descriptor ring is full: channel %d",
if (is_lso) {
/* free the current mp and mp_chain if not FULL */
tdc_stats->tx_no_desc++;
"LSO packet: TX Descriptor ring is full: "
"channel %d",
goto nxge_start_fail_lso;
} else {
tdc_stats->tx_no_desc++;
}
status = 1;
goto nxge_start_fail1;
}
}
nmblks = 0;
ngathers = 0;
pkt_len = 0;
pack_len = 0;
clen = 0;
last_bidx = -1;
#ifdef NXGE_DEBUG
#endif
sop_index, i));
#ifdef NXGE_DEBUG
"==> nxge_start(1): wr_index %d i %d msgdsize %d",
#endif
/*
* The first 16 bytes of the premapped buffer are reserved
* for header. No padding will be used.
*/
} else {
}
while (nmp) {
if (len <= 0) {
continue;
}
nmblks++;
"len %d pkt_len %d pack_len %d",
/*
* Hardware limits the transfer length to 4K for NIU and
* 4076 (TX_MAX_TRANSFER_LENGTH) for Neptune. But we just
* use TX_MAX_TRANSFER_LENGTH as the limit for both.
* If len is longer than the limit, then we break nmp into
* two chunks: Make the first chunk equal to the limit and
* the second chunk for the remaining data. If the second
* chunk is still larger than the limit, then it will be
* broken into two in the next pass.
*/
} else {
if (is_lso) {
"LSO packet: dupb failed: "
"channel %d",
goto nxge_start_fail_lso;
} else {
goto nxge_start_fail2;
}
}
}
tx_desc_p = &tx_desc_ring_vp[i];
#ifdef NXGE_DEBUG
tx_desc_pp = &tx_desc_ring_pp[i];
#endif
tx_msg_p = &tx_msg_ring[i];
#if defined(__i386)
#else
#endif
if (!header_set &&
(len >= bcopy_thresh))) {
header_set = B_TRUE;
boff = 0;
pack_len = 0;
(void) ddi_dma_sync(dma_handle,
}
"desc entry %d "
"DESC IOADDR $%p "
"desc_vp $%p tx_desc_p $%p "
"desc_pp $%p tx_desc_pp $%p "
"len %d pkt_len %d pack_len %d",
i,
if (len < bcopy_thresh) {
"USE BCOPY: "));
if (nxge_tx_tiny_pack) {
TXDMA_DESC_NEXT_INDEX(i, -1,
"==> nxge_start(5): pack"));
if ((pack_len <= bcopy_thresh) &&
"==> nxge_start: pack(6) "
"(pkt_len %d pack_len %d)",
i = blst;
tx_desc_p = &tx_desc_ring_vp[i];
#ifdef NXGE_DEBUG
tx_desc_pp = &tx_desc_ring_pp[i];
#endif
tx_msg_p = &tx_msg_ring[i];
ngathers--;
} else if (pack_len > bcopy_thresh &&
header_set) {
boff = 0;
"==> nxge_start(7): > max NEW "
"bcopy thresh %d "
"pkt_len %d pack_len %d(next)",
}
last_bidx = i;
}
header_set = B_TRUE;
"==> nxge_start(7_x2): "
"pkt_len %d pack_len %d (new hdrp $%p)",
}
"USE BCOPY: before bcopy "
"DESC IOADDR $%p entry %d "
"bcopy packets %d "
"bcopy kaddr $%p "
"bcopy ioaddr (SAD) $%p "
"bcopy clen %d "
"bcopy boff %d",
clen,
boff));
"1USE BCOPY: "));
"2USE BCOPY: "));
"last USE BCOPY: copy from b_rptr $%p "
"to KADDR $%p (len %d offset %d",
#ifdef NXGE_DEBUG
"==> nxge_start: dump packets "
"(After BCOPY len %d)"
dump_len)));
#endif
(void) ddi_dma_sync(dma_handle,
tdc_stats->tx_hdr_pkts++;
"USE BCOPY: "
"DESC IOADDR $%p entry %d "
"bcopy packets %d "
"bcopy kaddr $%p "
"bcopy ioaddr (SAD) $%p "
"bcopy clen %d "
"bcopy boff %d",
i,
clen,
boff));
} else {
"USE DVMA: len %d", len));
if (len < nxge_dma_stream_thresh) {
} else {
}
&dma_cookie, &ncookies);
if (status == DDI_DMA_MAPPED) {
"==> nxge_start(12_1): "
"USE DVMA: len %d clen %d "
"ngathers %d",
ngathers));
#if defined(__i386)
#else
#endif
while (ncookies > 1) {
ngathers++;
/*
* this is the fix for multiple
* cookies, which are basically
* a descriptor entry, we don't set
* SOP bit as well as related fields
*/
(void) npi_txdma_desc_gather_set(
&tx_desc,
(ngathers -1),
clen);
"==> nxge_start: DMA "
"ncookie %d "
"ngathers %d "
"dma_ioaddr $%p len %d"
"desc $%p descp $%p (%d)",
&dma_cookie);
"==> nxge_start(12_2): "
"USE DVMA: len %d clen %d ",
i = TXDMA_DESC_NEXT_INDEX(i, 1,
tx_desc_p = &tx_desc_ring_vp[i];
#if defined(__i386)
#else
#endif
tx_msg_p = &tx_msg_ring[i];
ncookies--;
}
tdc_stats->tx_ddi_pkts++;
"DMA: ddi packets %d",
tdc_stats->tx_ddi_pkts));
} else {
"dma mapping failed for %d "
"bytes addr $%p flags %x (%d)",
if (is_lso) {
goto nxge_start_fail_lso;
} else {
goto nxge_start_fail2;
}
}
} /* ddi dvma */
if (is_lso) {
nmp_lso_save = nmp;
}
#if defined(__i386)
#else
#endif
ngathers++;
if (ngathers == 1) {
#ifdef NXGE_DEBUG
#endif
sop_tx_desc_p->value = 0;
} else {
#ifdef NXGE_DEBUG
save_desc_p = &tx_desc;
#endif
tmp_desc_p = &tx_desc;
tmp_desc_p->value = 0;
}
"Desc_entry %d ngathers %d "
"desc_vp $%p tx_desc_p $%p "
"len %d clen %d pkt_len %d pack_len %d nmblks %d "
"dma_ioaddr (SAD) $%p mark %d",
i, ngathers,
dma_ioaddr, mark_mode));
#ifdef NXGE_DEBUG
"\t\tsad $%p\ttr_len %d len %d\tnptrs %d\t"
"mark %d sop %d\n",
sad,
#endif
if (ngathers > nxge_tx_max_gathers) {
&cksum_flags);
"==> nxge_start(14): pull msg - "
"len %d pkt_len %d ngathers %d",
/* Pull all message blocks from b_cont */
if (is_lso) {
mp = nmp_lso_save;
goto nxge_start_fail_lso;
}
goto nxge_start_fail2;
}
goto nxge_start_fail2;
}
} /* while (nmp) */
#if defined(__i386)
#else
#endif
if (pkt_len > NXGE_MTU_DEFAULT_MAX) {
}
/* Assume we use bcopy to premapped buffers */
"==> nxge_start(14-1): < (msg_min + 16)"
"len %d pkt_len %d min_len %d bzero %d ngathers %d",
"==> nxge_start(14-2): < msg_min - "
"len %d pkt_len %d min_len %d ngathers %d",
}
cksum_flags));
if (cksum_flags & HCK_PARTIALCKSUM) {
"==> nxge_start: cksum_flags 0x%x (partial checksum) ",
cksum_flags));
"==> nxge_start: from IP cksum_flags 0x%x "
"(partial checksum) "
"start_offset %d stuff_offset %d",
"==> nxge_start: from IP cksum_flags 0x%x "
"(partial checksum) "
"after SHIFT start_offset %d stuff_offset %d",
}
{
/* pkt_len already includes 16 + paddings!! */
/* Update the control header length */
"==> nxge_start(15_x1): setting SOP "
"tot_xfer_len 0x%llx (%d) pkt_len %d tmp_len "
"0x%llx hdrp->value 0x%llx",
#if defined(_BIG_ENDIAN)
#else
#endif
TX_CTL, "==> nxge_start(15_x2): setting SOP "
"after SWAP: tot_xfer_len 0x%llx pkt_len %d "
"tmp_len 0x%llx hdrp->value 0x%llx",
}
"wr_index %d "
"tot_xfer_len (%d) pkt_len %d npads %d",
npads));
#ifdef NXGE_DEBUG
"\t\tsad $%p\ttr_len %d len %d\tnptrs %d\tmark %d sop %d\n",
sad,
"==> nxge_start: dump packets(17) (after sop set, len "
" (len/dump_len/pkt_len/tot_xfer_len) %d/%d/%d/%d):\n"
(char *)hdrp,
"==> nxge_start(18): TX desc sync: sop_index %d",
sop_index));
#endif
(void) ddi_dma_sync(tx_desc_dma_handle,
"cs_off = 0x%02X cs_s_off = 0x%02X "
"pkt_len %d ngathers %d sop_index %d\n",
} else { /* more than one descriptor and wrap around */
(void) ddi_dma_sync(tx_desc_dma_handle,
"cs_off = 0x%02X cs_s_off = 0x%02X "
"pkt_len %d ngathers %d sop_index %d\n",
(void) ddi_dma_sync(tx_desc_dma_handle,
0,
"cs_off = 0x%02X cs_s_off = 0x%02X "
"pkt_len %d ngathers %d sop_index %d\n",
}
}
"channel %d wr_index %d wrap %d ngathers %d desc_pend %d",
if (is_lso) {
lso_ngathers += ngathers;
if (nxge_lso_kick_cnt == lso_ngathers) {
{
/* Kick the Transmit kick register */
"==> nxge_start: more LSO: "
"LSO_CNT %d",
lso_gathers));
}
lso_ngathers = 0;
ngathers = 0;
}
"==> nxge_start: lso again: "
"lso_gathers %d ngathers %d cur_index_lso %d "
"wr_index %d sop_index %d",
"==> nxge_start: next : count %d",
lso_gathers));
goto start_again;
}
}
{
/* Kick start the Transmit kick register */
}
return (status);
status = 0;
}
}
"==> nxge_start: lso exit (nothing changed)"));
goto nxge_start_fail1;
}
"==> nxge_start (channel %d): before lso "
"lso_gathers %d ngathers %d cur_index_lso %d "
"wr_index %d sop_index %d lso_again %d",
if (lso_again) {
lso_ngathers += ngathers;
}
"==> nxge_start (channel %d): after lso "
"lso_gathers %d ngathers %d cur_index_lso %d "
"wr_index %d sop_index %d lso_again %d",
if (good_packet == B_FALSE) {
for (i = 0; i < ngathers; i++) {
#if defined(__i386)
#else
#endif
"tx_desc_p = %X index = %d",
0, -1);
if (tx_ring_p->dvma_wr_index ==
tx_ring_p->dvma_wr_index = 0;
else
tx_msg_p->dma_handle)) {
"ddi_dma_unbind_handle failed");
}
}
}
}
/* Add FMA to check the access handle nxge_hregh */
return (status);
}
int
{
}
{
tx_rings));
switch (nxge_tx_scheme) {
case NXGE_USE_START:
"ring index %d", ring_index));
return (B_FALSE);
}
break;
case NXGE_USE_SERIAL:
default:
break;
}
ring_index));
return (B_TRUE);
}
/*
* nxge_m_tx() - send a chain of packets
*/
mblk_t *
{
"==> nxge_m_tx: hardware not initialized"));
"<== nxge_m_tx"));
return (mp);
}
/*
* Until Nemo tx resource works, the mac driver
* does the load balancing based on TCP port,
* or CPU. For debugging, we use a system
* configurable parameter.
*/
break;
}
"==> nxge_m_tx: (go back to loop) mp $%p next $%p",
}
return (mp);
}
int
{
uint8_t ring_index = 0;
IP_MAX_HDR_LENGTH + sizeof (uint32_t)];
/*
* allocate space big enough to cover
* the max ip header length and the first
*/
}
switch (nxge_tx_lb_policy) {
case NXGE_TX_LB_TCPUDP: /* default IPv4 TCP/UDP */
default:
if (!nxge_no_tx_lb && !qos &&
== ETHERTYPE_IP)) {
if (mblk_len > sizeof (struct ether_header) +
sizeof (uint8_t)) {
sizeof (struct ether_header);
mblk_len -= sizeof (struct ether_header);
} else {
}
}
hdrs_size = 0;
sizeof (hdrs_buf))) {
if (mblk_len >=
}
}
tcp_port += sizeof (ether_header_t);
switch (tcp_port[9]) {
case IPPROTO_TCP:
case IPPROTO_UDP:
case IPPROTO_ESP:
((tcp_port[0] ^
tcp_port[1] ^
tcp_port[2] ^
break;
case IPPROTO_AH:
/* SPI starts at the 4th byte */
((tcp_port[4] ^
tcp_port[5] ^
tcp_port[6] ^
break;
default:
break;
}
} else { /* fragmented packet */
}
} else {
}
break;
case NXGE_TX_LB_HASH:
#if defined(__i386)
#else
#endif
} else {
}
break;
case NXGE_TX_LB_DEST_MAC: /* Use destination MAC address */
break;
}
return (ring_index);
}
{
nxgep->resched_needed) {
}
return (DDI_INTR_CLAIMED);
}
/* Software LSO starts here */
static void
{
if ((*flags & (HCK_PARTIALCKSUM |
HCK_FULLCKSUM)) != 0) {
if ((*flags & HCK_PARTIALCKSUM) != 0) {
*start =
*stuff =
*end =
}
}
}
}
}
static void
{
*mss = 0;
}
"==> nxge_lso_info_get(flag !=NULL): mss %d *flags 0x%x",
}
"<== nxge_lso_info_get: mss %d", *mss));
}
/*
* Do Soft LSO on the oversized packet.
*
* 1. Create a chain of message for headers.
* 2. Fill up header messages with proper information.
* 3. Copy Eithernet, IP, and TCP headers from the original message to
* each new message with necessary adjustments.
* * Unchange the ethernet header for DIX frames. (by default)
* * IP Total Length field is updated to MSS or less(only for the last one).
* * IP Identification value is incremented by one for each packet.
* * TCP sequence Number is recalculated according to the payload length.
* * TCP partial Checksum
* 4. Update LSO information in the first message header.
* 5. Release the original message header.
*/
static mblk_t *
{
int pktlen;
int hdrlen;
int segnum;
int i;
struct ether_vlan_header *evh;
#ifdef __sparc
#endif
t_uscalar_t start_offset = 0;
t_uscalar_t stuff_offset = 0;
t_uscalar_t value = 0;
"==> nxge_do_softlso"));
/*
* check the length of LSO packet payload and calculate the number of
* segments to be generated.
*/
/* VLAN? */
ehlen = sizeof (struct ether_vlan_header);
else
ehlen = sizeof (struct ether_header);
"==> nxge_do_softlso: mss %d oiph $%p "
"original ip_sum oiph->ip_sum 0x%x "
"original tcp_sum otcph->th_sum 0x%x "
"oiph->ip_len %d pktlen %d ehlen %d "
"l4_len %d (0x%x) ip_len - iphlen %d ",
mss,
oiph,
/* IPv4 + TCP */
"<== nxge_do_softlso: not IPV4 "
"oiph->ip_len %d pktlen %d ehlen %d tcphlen %d",
tcphlen));
return (NULL);
}
"<== nxge_do_softlso: not TCP "
"oiph->ip_len %d pktlen %d ehlen %d tcphlen %d",
tcphlen));
return (NULL);
}
"<== nxge_do_softlso: len not matched "
"oiph->ip_len %d pktlen %d ehlen %d tcphlen %d",
tcphlen));
return (NULL);
}
/* TCP flags can not include URG, RST, or SYN */
} else { /* = */
}
"nxge_do_softlso: otcph $%p pktlen: %d, "
"hdrlen %d ehlen %d iphlen %d tcphlen %d "
"mblkl(mp): %d, mblkl(datamp): %d",
hckflags = 0;
"==> nxge_do_softlso: dst 0x%x src 0x%x sum 0x%x ~new 0x%x "
"hckflags 0x%x start_offset %d stuff_offset %d "
"value (original) 0x%x th_sum 0x%x "
"pktlen %d l4_len %d (0x%x) "
"MBLKL(mp): %d, MBLKL(datamp): %d dump header %s",
/*
* Start to process.
*/
"==> nxge_do_softlso: pktlen %d "
"MBLKL(mp): %d, MBLKL(datamp): %d "
"available %d mss %d segnum %d",
mss,
segnum));
/*
* Try to pre-allocate all header messages
*/
for (i = 0; i < segnum; i++) {
/* Clean up the mp_chain */
}
"<== nxge_do_softlso: "
"Could not allocate enough messages for headers!"));
return (NULL);
}
"==> nxge_do_softlso: "
"mp $%p nmp $%p mp_chain $%p mp_chain->b_next $%p",
}
"==> nxge_do_softlso: mp $%p nmp $%p mp_chain $%p",
/*
* Associate payload with new packets
*/
do_cleanup = B_TRUE;
"==>nxge_do_softlso: "
"Can not dupb(datamp), have to do clean up"));
goto cleanup_allocated_msgs;
}
"==> nxge_do_softlso: (loop) before mp $%p cmp $%p "
"dupb nmp $%p len %d left %d msd %d ",
"==> nxge_do_softlso: (loop) after mp $%p cmp $%p "
"dupb nmp $%p len %d left %d mss %d ",
"nxge_do_softlso: before available: %d, "
"left: %d, len: %d, segnum: %d MBLK(nmp): %d",
"nxge_do_softlso: after available: %d, "
"left: %d, len: %d, segnum: %d MBLK(nmp): %d",
while (len > 0) {
"nxge_do_softlso: (4) len > 0 available: %d, "
"left: %d, len: %d, segnum: %d MBLK(nmp): %d",
do_cleanup = B_TRUE;
"==> nxge_do_softlso: "
"Can not dupb(datamp) (1), :
NXGE_DEBUG_MSG((NULL, TX_CTL,
available, left, len,
(int)MBLKL(nmp)));
goto cleanup_allocated_msgs;
}
} else {
NXGE_ERROR_MSG((NULL, NXGE_ERR_CTL,
available, left, len,
(int)MBLKL(nmp)));
cmn_err(CE_PANIC,
(void *)datamp,
(void *)nmp,
(void *)rptr);
}
nmp->b_cont = mmp;
nmp = mmp;
len -= MBLKL(nmp);
}
if (len < 0) {
nmp->b_wptr += len;
rptr = nmp->b_wptr;
NXGE_DEBUG_MSG((NULL, TX_CTL,
available, left, len, (int)MBLKL(nmp)));
} else if (len == 0) {
if (datamp->b_cont != NULL) {
NXGE_DEBUG_MSG((NULL, TX_CTL,
available, left, len, (int)MBLKL(nmp)));
datamp = datamp->b_cont;
rptr = datamp->b_rptr;
} else {
NXGE_DEBUG_MSG((NULL, TX_CTL,
available, left, len, (int)MBLKL(nmp)));
VERIFY(cmp->b_next == NULL);
VERIFY(left == 0);
break; /* Done! */
}
}
cmp = cmp->b_next;
NXGE_DEBUG_MSG((NULL, TX_CTL,
available, left, len, (int)MBLKL(nmp)));
}
/*
* From now, start to fill up all headers for the first message
* Hardware checksum flags need to be updated separately for FULLCKSUM
* and PARTIALCKSUM cases. For full checksum, copy the original flags
* into every new packet is enough. But for HCK_PARTIALCKSUM, all
* required fields need to be updated properly.
*/
nmp = mp_chain;
bcopy(mp->b_rptr, nmp->b_rptr, hdrlen);
nmp->b_wptr = nmp->b_rptr + hdrlen;
niph = (struct ip *)(nmp->b_rptr + ehlen);
niph->ip_len = htons(mss + iphlen + tcphlen);
ip_id = ntohs(niph->ip_id);
ntcph = (struct tcphdr *)(nmp->b_rptr + ehlen + iphlen);
#ifdef __sparc
bcopy((char *)&ntcph->th_seq, &tcp_seq_tmp, 4);
tcp_seq = ntohl(tcp_seq_tmp);
#else
tcp_seq = ntohl(ntcph->th_seq);
#endif
ntcph->th_flags &= ~(TH_FIN | TH_PUSH | TH_RST);
DB_CKSUMFLAGS(nmp) = (uint16_t)hckflags;
DB_CKSUMSTART(nmp) = start_offset;
DB_CKSUMSTUFF(nmp) = stuff_offset;
/* calculate IP checksum and TCP pseudo header checksum */
niph->ip_sum = 0;
niph->ip_sum = (uint16_t)nxge_csgen((uint16_t *)niph, iphlen);
l4_len = mss + tcphlen;
sum = htons(l4_len) + l4cksum;
sum = (sum & 0xFFFF) + (sum >> 16);
ntcph->th_sum = (sum & 0xffff);
NXGE_DEBUG_MSG((NULL, TX_CTL,
nmp, mp_chain,
mss,
pktlen,
l4_len,
l4_len,
(int)MBLKL(mp), (int)MBLKL(datamp),
niph->ip_sum,
ntcph->th_sum,
sum,
nxge_dump_packet((char *)niph, 52)));
cmp = nmp;
while ((nmp = nmp->b_next)->b_next != NULL) {
NXGE_DEBUG_MSG((NULL, TX_CTL,
bcopy(cmp->b_rptr, nmp->b_rptr, hdrlen);
nmp->b_wptr = nmp->b_rptr + hdrlen;
niph = (struct ip *)(nmp->b_rptr + ehlen);
niph->ip_id = htons(++ip_id);
niph->ip_len = htons(mss + iphlen + tcphlen);
ntcph = (struct tcphdr *)(nmp->b_rptr + ehlen + iphlen);
tcp_seq += mss;
ntcph->th_flags &= ~(TH_FIN | TH_PUSH | TH_RST | TH_URG);
#ifdef __sparc
tcp_seq_tmp = htonl(tcp_seq);
bcopy(&tcp_seq_tmp, (char *)&ntcph->th_seq, 4);
#else
ntcph->th_seq = htonl(tcp_seq);
#endif
DB_CKSUMFLAGS(nmp) = (uint16_t)hckflags;
DB_CKSUMSTART(nmp) = start_offset;
DB_CKSUMSTUFF(nmp) = stuff_offset;
/* calculate IP checksum and TCP pseudo header checksum */
niph->ip_sum = 0;
niph->ip_sum = (uint16_t)nxge_csgen((uint16_t *)niph, iphlen);
ntcph->th_sum = (sum & 0xffff);
NXGE_DEBUG_MSG((NULL, TX_CTL,
niph->ip_sum,
ntcph->th_sum,
nmp, mp_chain,
pktlen, (int)MBLKL(mp), (int)MBLKL(datamp)));
}
/* Last segment */
/*
* The ip_len could be different from prior packets.
*/
bcopy(cmp->b_rptr, nmp->b_rptr, hdrlen);
nmp->b_wptr = nmp->b_rptr + hdrlen;
niph = (struct ip *)(nmp->b_rptr + ehlen);
niph->ip_id = htons(++ip_id);
niph->ip_len = htons(msgsize(nmp->b_cont) + iphlen + tcphlen);
ntcph = (struct tcphdr *)(nmp->b_rptr + ehlen + iphlen);
tcp_seq += mss;
#ifdef __sparc
tcp_seq_tmp = htonl(tcp_seq);
bcopy(&tcp_seq_tmp, (char *)&ntcph->th_seq, 4);
#else
ntcph->th_seq = htonl(tcp_seq);
#endif
ntcph->th_flags = (otcph->th_flags & ~TH_URG);
DB_CKSUMFLAGS(nmp) = (uint16_t)hckflags;
DB_CKSUMSTART(nmp) = start_offset;
DB_CKSUMSTUFF(nmp) = stuff_offset;
/* calculate IP checksum and TCP pseudo header checksum */
niph->ip_sum = 0;
niph->ip_sum = (uint16_t)nxge_csgen((uint16_t *)niph, iphlen);
l4_len = ntohs(niph->ip_len) - iphlen;
sum = htons(l4_len) + l4cksum;
sum = (sum & 0xFFFF) + (sum >> 16);
ntcph->th_sum = (sum & 0xffff);
NXGE_DEBUG_MSG((NULL, TX_CTL,
niph->ip_sum,
ntcph->th_sum, sum,
nxge_dump_packet((char *)niph, 52),
cmp, nmp, mp_chain,
pktlen, pktlen,
l4_len,
l4_len,
(int)MBLKL(mp), (int)MBLKL(datamp)));
cleanup_allocated_msgs:
if (do_cleanup) {
NXGE_DEBUG_MSG((NULL, TX_CTL,
while (mp_chain != NULL) {
nmp = mp_chain;
mp_chain = mp_chain->b_next;
freemsg(nmp);
}
}
/*
* We're done here, so just free the original message and return the
* new message chain, that could be NULL if failed, back to the caller.
*/
freemsg(mp);
NXGE_DEBUG_MSG((NULL, TX_CTL,
return (mp_chain);
}
/*
* Will be called before NIC driver do further operation on the message.
* The input message may include LSO information, if so, go to softlso logic
* to eliminate the oversized LSO packet for the incapable underlying h/w.
* The return could be the same non-LSO message or a message chain for LSO case.
*
* The driver needs to call this function per packet and process the whole chain
* if applied.
*/
static mblk_t *
nxge_lso_eliminate(mblk_t *mp)
{
uint32_t lsoflags;
uint32_t mss;
NXGE_DEBUG_MSG((NULL, TX_CTL,
nxge_lso_info_get(mp, &mss, &lsoflags);
if (lsoflags & HW_LSO) {
mblk_t *nmp;
NXGE_DEBUG_MSG((NULL, TX_CTL,
mss, mp));
if ((nmp = nxge_do_softlso(mp, mss)) != NULL) {
NXGE_DEBUG_MSG((NULL, TX_CTL,
nmp, mss, mp));
return (nmp);
} else {
NXGE_DEBUG_MSG((NULL, TX_CTL,
nmp, mss, mp));
return (NULL);
}
}
NXGE_DEBUG_MSG((NULL, TX_CTL,
return (mp);
}
static uint32_t
nxge_csgen(uint16_t *adr, int len)
{
int i, odd;
uint32_t sum = 0;
uint32_t c = 0;
odd = len % 2;
for (i = 0; i < (len / 2); i++) {
sum += (adr[i] & 0xffff);
}
if (odd) {
sum += adr[len / 2] & 0xff00;
}
while ((c = ((sum & 0xffff0000) >> 16)) != 0) {
sum &= 0xffff;
sum += c;
}
return (~sum & 0xffff);
}