2 * Copyright (c) 2016 Chelsio Communications, Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
9 #include <linux/workqueue.h>
10 #include <linux/kthread.h>
11 #include <asm/unaligned.h>
13 #include <target/target_core_base.h>
14 #include <target/target_core_fabric.h>
17 struct sge_opaque_hdr
{
19 dma_addr_t addr
[MAX_SKB_FRAGS
+ 1];
22 static const u8 cxgbit_digest_len
[] = {0, 4, 4, 8};
24 #define TX_HDR_LEN (sizeof(struct sge_opaque_hdr) + \
25 sizeof(struct fw_ofld_tx_data_wr))
27 static struct sk_buff
*
28 __cxgbit_alloc_skb(struct cxgbit_sock
*csk
, u32 len
, bool iso
)
30 struct sk_buff
*skb
= NULL
;
33 static const u32 hdr_len
= TX_HDR_LEN
+ ISCSI_HDR_LEN
;
36 skb
= alloc_skb_with_frags(hdr_len
, len
,
42 skb_reserve(skb
, TX_HDR_LEN
);
43 skb_reset_transport_header(skb
);
44 __skb_put(skb
, ISCSI_HDR_LEN
);
47 submode
|= (csk
->submode
& CXGBIT_SUBMODE_DCRC
);
50 u32 iso_len
= iso
? sizeof(struct cpl_tx_data_iso
) : 0;
52 skb
= alloc_skb(hdr_len
+ iso_len
, GFP_KERNEL
);
56 skb_reserve(skb
, TX_HDR_LEN
+ iso_len
);
57 skb_reset_transport_header(skb
);
58 __skb_put(skb
, ISCSI_HDR_LEN
);
61 submode
|= (csk
->submode
& CXGBIT_SUBMODE_HCRC
);
62 cxgbit_skcb_submode(skb
) = submode
;
63 cxgbit_skcb_tx_extralen(skb
) = cxgbit_digest_len
[submode
];
64 cxgbit_skcb_flags(skb
) |= SKCBF_TX_NEED_HDR
;
68 static struct sk_buff
*cxgbit_alloc_skb(struct cxgbit_sock
*csk
, u32 len
)
70 return __cxgbit_alloc_skb(csk
, len
, false);
74 * cxgbit_is_ofld_imm - check whether a packet can be sent as immediate data
77 * Returns true if a packet can be sent as an offload WR with immediate
78 * data. We currently use the same limit as for Ethernet packets.
80 static int cxgbit_is_ofld_imm(const struct sk_buff
*skb
)
82 int length
= skb
->len
;
84 if (likely(cxgbit_skcb_flags(skb
) & SKCBF_TX_NEED_HDR
))
85 length
+= sizeof(struct fw_ofld_tx_data_wr
);
87 if (likely(cxgbit_skcb_flags(skb
) & SKCBF_TX_ISO
))
88 length
+= sizeof(struct cpl_tx_data_iso
);
90 #define MAX_IMM_TX_PKT_LEN 256
91 return length
<= MAX_IMM_TX_PKT_LEN
;
95 * cxgbit_sgl_len - calculates the size of an SGL of the given capacity
96 * @n: the number of SGL entries
97 * Calculates the number of flits needed for a scatter/gather list that
98 * can hold the given number of entries.
100 static inline unsigned int cxgbit_sgl_len(unsigned int n
)
103 return (3 * n
) / 2 + (n
& 1) + 2;
107 * cxgbit_calc_tx_flits_ofld - calculate # of flits for an offload packet
110 * Returns the number of flits needed for the given offload packet.
111 * These packets are already fully constructed and no additional headers
114 static unsigned int cxgbit_calc_tx_flits_ofld(const struct sk_buff
*skb
)
116 unsigned int flits
, cnt
;
118 if (cxgbit_is_ofld_imm(skb
))
119 return DIV_ROUND_UP(skb
->len
, 8);
120 flits
= skb_transport_offset(skb
) / 8;
121 cnt
= skb_shinfo(skb
)->nr_frags
;
122 if (skb_tail_pointer(skb
) != skb_transport_header(skb
))
124 return flits
+ cxgbit_sgl_len(cnt
);
127 #define CXGBIT_ISO_FSLICE 0x1
128 #define CXGBIT_ISO_LSLICE 0x2
130 cxgbit_cpl_tx_data_iso(struct sk_buff
*skb
, struct cxgbit_iso_info
*iso_info
)
132 struct cpl_tx_data_iso
*cpl
;
133 unsigned int submode
= cxgbit_skcb_submode(skb
);
134 unsigned int fslice
= !!(iso_info
->flags
& CXGBIT_ISO_FSLICE
);
135 unsigned int lslice
= !!(iso_info
->flags
& CXGBIT_ISO_LSLICE
);
137 cpl
= (struct cpl_tx_data_iso
*)__skb_push(skb
, sizeof(*cpl
));
139 cpl
->op_to_scsi
= htonl(CPL_TX_DATA_ISO_OP_V(CPL_TX_DATA_ISO
) |
140 CPL_TX_DATA_ISO_FIRST_V(fslice
) |
141 CPL_TX_DATA_ISO_LAST_V(lslice
) |
142 CPL_TX_DATA_ISO_CPLHDRLEN_V(0) |
143 CPL_TX_DATA_ISO_HDRCRC_V(submode
& 1) |
144 CPL_TX_DATA_ISO_PLDCRC_V(((submode
>> 1) & 1)) |
145 CPL_TX_DATA_ISO_IMMEDIATE_V(0) |
146 CPL_TX_DATA_ISO_SCSI_V(2));
149 cpl
->mpdu
= htons(DIV_ROUND_UP(iso_info
->mpdu
, 4));
150 cpl
->burst_size
= htonl(DIV_ROUND_UP(iso_info
->burst_len
, 4));
151 cpl
->len
= htonl(iso_info
->len
);
152 cpl
->reserved2_seglen_offset
= htonl(0);
153 cpl
->datasn_offset
= htonl(0);
154 cpl
->buffer_offset
= htonl(0);
157 __skb_pull(skb
, sizeof(*cpl
));
161 cxgbit_tx_data_wr(struct cxgbit_sock
*csk
, struct sk_buff
*skb
, u32 dlen
,
162 u32 len
, u32 credits
, u32
compl)
164 struct fw_ofld_tx_data_wr
*req
;
165 u32 submode
= cxgbit_skcb_submode(skb
);
167 u32 hdr_size
= sizeof(*req
);
168 u32 opcode
= FW_OFLD_TX_DATA_WR
;
170 u32 force
= TX_FORCE_V(!submode
);
172 if (cxgbit_skcb_flags(skb
) & SKCBF_TX_ISO
) {
173 opcode
= FW_ISCSI_TX_DATA_WR
;
174 immlen
+= sizeof(struct cpl_tx_data_iso
);
175 hdr_size
+= sizeof(struct cpl_tx_data_iso
);
179 if (cxgbit_is_ofld_imm(skb
))
182 req
= (struct fw_ofld_tx_data_wr
*)__skb_push(skb
,
184 req
->op_to_immdlen
= cpu_to_be32(FW_WR_OP_V(opcode
) |
185 FW_WR_COMPL_V(compl) |
186 FW_WR_IMMDLEN_V(immlen
));
187 req
->flowid_len16
= cpu_to_be32(FW_WR_FLOWID_V(csk
->tid
) |
188 FW_WR_LEN16_V(credits
));
189 req
->plen
= htonl(len
);
190 wr_ulp_mode
= FW_OFLD_TX_DATA_WR_ULPMODE_V(ULP_MODE_ISCSI
) |
191 FW_OFLD_TX_DATA_WR_ULPSUBMODE_V(submode
);
193 req
->tunnel_to_proxy
= htonl((wr_ulp_mode
) | force
|
194 FW_OFLD_TX_DATA_WR_SHOVE_V(skb_peek(&csk
->txq
) ? 0 : 1));
197 static void cxgbit_arp_failure_skb_discard(void *handle
, struct sk_buff
*skb
)
202 void cxgbit_push_tx_frames(struct cxgbit_sock
*csk
)
206 while (csk
->wr_cred
&& ((skb
= skb_peek(&csk
->txq
)) != NULL
)) {
214 if (cxgbit_skcb_flags(skb
) & SKCBF_TX_ISO
)
215 iso_cpl_len
= sizeof(struct cpl_tx_data_iso
);
217 if (cxgbit_is_ofld_imm(skb
))
218 credits_needed
= DIV_ROUND_UP(dlen
+ iso_cpl_len
, 16);
220 credits_needed
= DIV_ROUND_UP((8 *
221 cxgbit_calc_tx_flits_ofld(skb
)) +
224 if (likely(cxgbit_skcb_flags(skb
) & SKCBF_TX_NEED_HDR
))
225 credits_needed
+= DIV_ROUND_UP(
226 sizeof(struct fw_ofld_tx_data_wr
), 16);
228 * Assumes the initial credits is large enough to support
229 * fw_flowc_wr plus largest possible first payload
232 if (!test_and_set_bit(CSK_TX_DATA_SENT
, &csk
->com
.flags
)) {
233 flowclen16
= cxgbit_send_tx_flowc_wr(csk
);
234 csk
->wr_cred
-= flowclen16
;
235 csk
->wr_una_cred
+= flowclen16
;
238 if (csk
->wr_cred
< credits_needed
) {
239 pr_debug("csk 0x%p, skb %u/%u, wr %d < %u.\n",
240 csk
, skb
->len
, skb
->data_len
,
241 credits_needed
, csk
->wr_cred
);
244 __skb_unlink(skb
, &csk
->txq
);
245 set_wr_txq(skb
, CPL_PRIORITY_DATA
, csk
->txq_idx
);
246 skb
->csum
= credits_needed
+ flowclen16
;
247 csk
->wr_cred
-= credits_needed
;
248 csk
->wr_una_cred
+= credits_needed
;
250 pr_debug("csk 0x%p, skb %u/%u, wr %d, left %u, unack %u.\n",
251 csk
, skb
->len
, skb
->data_len
, credits_needed
,
252 csk
->wr_cred
, csk
->wr_una_cred
);
254 if (likely(cxgbit_skcb_flags(skb
) & SKCBF_TX_NEED_HDR
)) {
255 len
+= cxgbit_skcb_tx_extralen(skb
);
257 if ((csk
->wr_una_cred
>= (csk
->wr_max_cred
/ 2)) ||
258 (!before(csk
->write_seq
,
259 csk
->snd_una
+ csk
->snd_win
))) {
261 csk
->wr_una_cred
= 0;
264 cxgbit_tx_data_wr(csk
, skb
, dlen
, len
, credits_needed
,
268 } else if ((cxgbit_skcb_flags(skb
) & SKCBF_TX_FLAG_COMPL
) ||
269 (csk
->wr_una_cred
>= (csk
->wr_max_cred
/ 2))) {
270 struct cpl_close_con_req
*req
=
271 (struct cpl_close_con_req
*)skb
->data
;
272 req
->wr
.wr_hi
|= htonl(FW_WR_COMPL_F
);
273 csk
->wr_una_cred
= 0;
276 cxgbit_sock_enqueue_wr(csk
, skb
);
277 t4_set_arp_err_handler(skb
, csk
,
278 cxgbit_arp_failure_skb_discard
);
280 pr_debug("csk 0x%p,%u, skb 0x%p, %u.\n",
281 csk
, csk
->tid
, skb
, len
);
283 cxgbit_l2t_send(csk
->com
.cdev
, skb
, csk
->l2t
);
287 static bool cxgbit_lock_sock(struct cxgbit_sock
*csk
)
289 spin_lock_bh(&csk
->lock
);
291 if (before(csk
->write_seq
, csk
->snd_una
+ csk
->snd_win
))
292 csk
->lock_owner
= true;
294 spin_unlock_bh(&csk
->lock
);
296 return csk
->lock_owner
;
299 static void cxgbit_unlock_sock(struct cxgbit_sock
*csk
)
301 struct sk_buff_head backlogq
;
303 void (*fn
)(struct cxgbit_sock
*, struct sk_buff
*);
305 skb_queue_head_init(&backlogq
);
307 spin_lock_bh(&csk
->lock
);
308 while (skb_queue_len(&csk
->backlogq
)) {
309 skb_queue_splice_init(&csk
->backlogq
, &backlogq
);
310 spin_unlock_bh(&csk
->lock
);
312 while ((skb
= __skb_dequeue(&backlogq
))) {
313 fn
= cxgbit_skcb_rx_backlog_fn(skb
);
317 spin_lock_bh(&csk
->lock
);
320 csk
->lock_owner
= false;
321 spin_unlock_bh(&csk
->lock
);
324 static int cxgbit_queue_skb(struct cxgbit_sock
*csk
, struct sk_buff
*skb
)
328 wait_event_interruptible(csk
->ack_waitq
, cxgbit_lock_sock(csk
));
330 if (unlikely((csk
->com
.state
!= CSK_STATE_ESTABLISHED
) ||
331 signal_pending(current
))) {
333 __skb_queue_purge(&csk
->ppodq
);
335 spin_lock_bh(&csk
->lock
);
336 if (csk
->lock_owner
) {
337 spin_unlock_bh(&csk
->lock
);
340 spin_unlock_bh(&csk
->lock
);
344 csk
->write_seq
+= skb
->len
+
345 cxgbit_skcb_tx_extralen(skb
);
347 skb_queue_splice_tail_init(&csk
->ppodq
, &csk
->txq
);
348 __skb_queue_tail(&csk
->txq
, skb
);
349 cxgbit_push_tx_frames(csk
);
352 cxgbit_unlock_sock(csk
);
357 cxgbit_map_skb(struct iscsi_cmd
*cmd
, struct sk_buff
*skb
, u32 data_offset
,
360 u32 i
= 0, nr_frags
= MAX_SKB_FRAGS
;
361 u32 padding
= ((-data_length
) & 3);
362 struct scatterlist
*sg
;
364 unsigned int page_off
;
370 * We know each entry in t_data_sg contains a page.
372 sg
= &cmd
->se_cmd
.t_data_sg
[data_offset
/ PAGE_SIZE
];
373 page_off
= (data_offset
% PAGE_SIZE
);
375 while (data_length
&& (i
< nr_frags
)) {
376 u32 cur_len
= min_t(u32
, data_length
, sg
->length
- page_off
);
381 skb_fill_page_desc(skb
, i
, page
, sg
->offset
+ page_off
,
383 skb
->data_len
+= cur_len
;
385 skb
->truesize
+= cur_len
;
387 data_length
-= cur_len
;
397 page
= alloc_page(GFP_KERNEL
| __GFP_ZERO
);
400 skb_fill_page_desc(skb
, i
, page
, 0, padding
);
401 skb
->data_len
+= padding
;
403 skb
->truesize
+= padding
;
410 cxgbit_tx_datain_iso(struct cxgbit_sock
*csk
, struct iscsi_cmd
*cmd
,
411 struct iscsi_datain_req
*dr
)
413 struct iscsi_conn
*conn
= csk
->conn
;
415 struct iscsi_datain datain
;
416 struct cxgbit_iso_info iso_info
;
417 u32 data_length
= cmd
->se_cmd
.data_length
;
418 u32 mrdsl
= conn
->conn_ops
->MaxRecvDataSegmentLength
;
419 u32 num_pdu
, plen
, tx_data
= 0;
420 bool task_sense
= !!(cmd
->se_cmd
.se_cmd_flags
&
421 SCF_TRANSPORT_TASK_SENSE
);
422 bool set_statsn
= false;
425 while (data_length
) {
426 num_pdu
= (data_length
+ mrdsl
- 1) / mrdsl
;
427 if (num_pdu
> csk
->max_iso_npdu
)
428 num_pdu
= csk
->max_iso_npdu
;
430 plen
= num_pdu
* mrdsl
;
431 if (plen
> data_length
)
434 skb
= __cxgbit_alloc_skb(csk
, 0, true);
438 memset(skb
->data
, 0, ISCSI_HDR_LEN
);
439 cxgbit_skcb_flags(skb
) |= SKCBF_TX_ISO
;
440 cxgbit_skcb_submode(skb
) |= (csk
->submode
&
441 CXGBIT_SUBMODE_DCRC
);
442 cxgbit_skcb_tx_extralen(skb
) = (num_pdu
*
443 cxgbit_digest_len
[cxgbit_skcb_submode(skb
)]) +
444 ((num_pdu
- 1) * ISCSI_HDR_LEN
);
446 memset(&datain
, 0, sizeof(struct iscsi_datain
));
447 memset(&iso_info
, 0, sizeof(iso_info
));
450 iso_info
.flags
|= CXGBIT_ISO_FSLICE
;
452 if (!(data_length
- plen
)) {
453 iso_info
.flags
|= CXGBIT_ISO_LSLICE
;
455 datain
.flags
= ISCSI_FLAG_DATA_STATUS
;
456 iscsit_increment_maxcmdsn(cmd
, conn
->sess
);
457 cmd
->stat_sn
= conn
->stat_sn
++;
462 iso_info
.burst_len
= num_pdu
* mrdsl
;
463 iso_info
.mpdu
= mrdsl
;
464 iso_info
.len
= ISCSI_HDR_LEN
+ plen
;
466 cxgbit_cpl_tx_data_iso(skb
, &iso_info
);
468 datain
.offset
= tx_data
;
469 datain
.data_sn
= cmd
->data_sn
- 1;
471 iscsit_build_datain_pdu(cmd
, conn
, &datain
,
472 (struct iscsi_data_rsp
*)skb
->data
,
475 ret
= cxgbit_map_skb(cmd
, skb
, tx_data
, plen
);
481 ret
= cxgbit_queue_skb(csk
, skb
);
488 cmd
->read_data_done
+= plen
;
489 cmd
->data_sn
+= num_pdu
;
492 dr
->dr_complete
= DATAIN_COMPLETE_NORMAL
;
501 cxgbit_tx_datain(struct cxgbit_sock
*csk
, struct iscsi_cmd
*cmd
,
502 const struct iscsi_datain
*datain
)
507 skb
= cxgbit_alloc_skb(csk
, 0);
511 memcpy(skb
->data
, cmd
->pdu
, ISCSI_HDR_LEN
);
513 if (datain
->length
) {
514 cxgbit_skcb_submode(skb
) |= (csk
->submode
&
515 CXGBIT_SUBMODE_DCRC
);
516 cxgbit_skcb_tx_extralen(skb
) =
517 cxgbit_digest_len
[cxgbit_skcb_submode(skb
)];
520 ret
= cxgbit_map_skb(cmd
, skb
, datain
->offset
, datain
->length
);
526 return cxgbit_queue_skb(csk
, skb
);
530 cxgbit_xmit_datain_pdu(struct iscsi_conn
*conn
, struct iscsi_cmd
*cmd
,
531 struct iscsi_datain_req
*dr
,
532 const struct iscsi_datain
*datain
)
534 struct cxgbit_sock
*csk
= conn
->context
;
535 u32 data_length
= cmd
->se_cmd
.data_length
;
536 u32 padding
= ((-data_length
) & 3);
537 u32 mrdsl
= conn
->conn_ops
->MaxRecvDataSegmentLength
;
539 if ((data_length
> mrdsl
) && (!dr
->recovery
) &&
540 (!padding
) && (!datain
->offset
) && csk
->max_iso_npdu
) {
541 atomic_long_add(data_length
- datain
->length
,
542 &conn
->sess
->tx_data_octets
);
543 return cxgbit_tx_datain_iso(csk
, cmd
, dr
);
546 return cxgbit_tx_datain(csk
, cmd
, datain
);
550 cxgbit_xmit_nondatain_pdu(struct iscsi_conn
*conn
, struct iscsi_cmd
*cmd
,
551 const void *data_buf
, u32 data_buf_len
)
553 struct cxgbit_sock
*csk
= conn
->context
;
555 u32 padding
= ((-data_buf_len
) & 3);
557 skb
= cxgbit_alloc_skb(csk
, data_buf_len
+ padding
);
561 memcpy(skb
->data
, cmd
->pdu
, ISCSI_HDR_LEN
);
566 skb_store_bits(skb
, ISCSI_HDR_LEN
, data_buf
, data_buf_len
);
569 skb_store_bits(skb
, ISCSI_HDR_LEN
+ data_buf_len
,
570 &pad_bytes
, padding
);
573 cxgbit_skcb_tx_extralen(skb
) = cxgbit_digest_len
[
574 cxgbit_skcb_submode(skb
)];
576 return cxgbit_queue_skb(csk
, skb
);
580 cxgbit_xmit_pdu(struct iscsi_conn
*conn
, struct iscsi_cmd
*cmd
,
581 struct iscsi_datain_req
*dr
, const void *buf
, u32 buf_len
)
584 return cxgbit_xmit_datain_pdu(conn
, cmd
, dr
, buf
);
586 return cxgbit_xmit_nondatain_pdu(conn
, cmd
, buf
, buf_len
);
589 int cxgbit_validate_params(struct iscsi_conn
*conn
)
591 struct cxgbit_sock
*csk
= conn
->context
;
592 struct cxgbit_device
*cdev
= csk
->com
.cdev
;
593 struct iscsi_param
*param
;
596 param
= iscsi_find_param_from_key(MAXXMITDATASEGMENTLENGTH
,
601 if (kstrtou32(param
->value
, 0, &max_xmitdsl
) < 0)
604 if (max_xmitdsl
> cdev
->mdsl
) {
605 if (iscsi_change_param_sprintf(
606 conn
, "MaxXmitDataSegmentLength=%u", cdev
->mdsl
))
613 static int cxgbit_set_digest(struct cxgbit_sock
*csk
)
615 struct iscsi_conn
*conn
= csk
->conn
;
616 struct iscsi_param
*param
;
618 param
= iscsi_find_param_from_key(HEADERDIGEST
, conn
->param_list
);
620 pr_err("param not found key %s\n", HEADERDIGEST
);
624 if (!strcmp(param
->value
, CRC32C
))
625 csk
->submode
|= CXGBIT_SUBMODE_HCRC
;
627 param
= iscsi_find_param_from_key(DATADIGEST
, conn
->param_list
);
630 pr_err("param not found key %s\n", DATADIGEST
);
634 if (!strcmp(param
->value
, CRC32C
))
635 csk
->submode
|= CXGBIT_SUBMODE_DCRC
;
637 if (cxgbit_setup_conn_digest(csk
)) {
645 static int cxgbit_set_iso_npdu(struct cxgbit_sock
*csk
)
647 struct iscsi_conn
*conn
= csk
->conn
;
648 struct iscsi_conn_ops
*conn_ops
= conn
->conn_ops
;
649 struct iscsi_param
*param
;
651 u32 max_npdu
, max_iso_npdu
;
653 if (conn
->login
->leading_connection
) {
654 param
= iscsi_find_param_from_key(DATASEQUENCEINORDER
,
657 pr_err("param not found key %s\n", DATASEQUENCEINORDER
);
661 if (strcmp(param
->value
, YES
))
664 param
= iscsi_find_param_from_key(DATAPDUINORDER
,
667 pr_err("param not found key %s\n", DATAPDUINORDER
);
671 if (strcmp(param
->value
, YES
))
674 param
= iscsi_find_param_from_key(MAXBURSTLENGTH
,
677 pr_err("param not found key %s\n", MAXBURSTLENGTH
);
681 if (kstrtou32(param
->value
, 0, &mbl
) < 0)
684 if (!conn
->sess
->sess_ops
->DataSequenceInOrder
)
686 if (!conn
->sess
->sess_ops
->DataPDUInOrder
)
689 mbl
= conn
->sess
->sess_ops
->MaxBurstLength
;
692 mrdsl
= conn_ops
->MaxRecvDataSegmentLength
;
693 max_npdu
= mbl
/ mrdsl
;
695 max_iso_npdu
= CXGBIT_MAX_ISO_PAYLOAD
/
696 (ISCSI_HDR_LEN
+ mrdsl
+
697 cxgbit_digest_len
[csk
->submode
]);
699 csk
->max_iso_npdu
= min(max_npdu
, max_iso_npdu
);
701 if (csk
->max_iso_npdu
<= 1)
702 csk
->max_iso_npdu
= 0;
707 static int cxgbit_set_params(struct iscsi_conn
*conn
)
709 struct cxgbit_sock
*csk
= conn
->context
;
710 struct cxgbit_device
*cdev
= csk
->com
.cdev
;
711 struct cxgbi_ppm
*ppm
= *csk
->com
.cdev
->lldi
.iscsi_ppm
;
712 struct iscsi_conn_ops
*conn_ops
= conn
->conn_ops
;
713 struct iscsi_param
*param
;
716 if (conn_ops
->MaxRecvDataSegmentLength
> cdev
->mdsl
)
717 conn_ops
->MaxRecvDataSegmentLength
= cdev
->mdsl
;
719 if (conn
->login
->leading_connection
) {
720 param
= iscsi_find_param_from_key(ERRORRECOVERYLEVEL
,
723 pr_err("param not found key %s\n", ERRORRECOVERYLEVEL
);
726 if (kstrtou8(param
->value
, 0, &erl
) < 0)
729 erl
= conn
->sess
->sess_ops
->ErrorRecoveryLevel
;
733 if (test_bit(CDEV_ISO_ENABLE
, &cdev
->flags
)) {
734 if (cxgbit_set_iso_npdu(csk
))
738 if (test_bit(CDEV_DDP_ENABLE
, &cdev
->flags
)) {
739 if (cxgbit_setup_conn_pgidx(csk
,
740 ppm
->tformat
.pgsz_idx_dflt
))
742 set_bit(CSK_DDP_ENABLE
, &csk
->com
.flags
);
746 if (cxgbit_set_digest(csk
))
753 cxgbit_put_login_tx(struct iscsi_conn
*conn
, struct iscsi_login
*login
,
756 struct cxgbit_sock
*csk
= conn
->context
;
759 u8 padding
= ((-length
) & 3);
761 skb
= cxgbit_alloc_skb(csk
, length
+ padding
);
764 skb_store_bits(skb
, 0, login
->rsp
, ISCSI_HDR_LEN
);
765 skb_store_bits(skb
, ISCSI_HDR_LEN
, login
->rsp_buf
, length
);
768 skb_store_bits(skb
, ISCSI_HDR_LEN
+ length
,
769 &padding_buf
, padding
);
771 if (login
->login_complete
) {
772 if (cxgbit_set_params(conn
)) {
777 set_bit(CSK_LOGIN_DONE
, &csk
->com
.flags
);
780 if (cxgbit_queue_skb(csk
, skb
))
783 if ((!login
->login_complete
) && (!login
->login_failed
))
784 schedule_delayed_work(&conn
->login_work
, 0);
790 cxgbit_skb_copy_to_sg(struct sk_buff
*skb
, struct scatterlist
*sg
,
793 struct skb_seq_state st
;
795 unsigned int consumed
= 0, buf_len
;
796 struct cxgbit_lro_pdu_cb
*pdu_cb
= cxgbit_rx_pdu_cb(skb
);
798 skb_prepare_seq_read(skb
, pdu_cb
->doffset
,
799 pdu_cb
->doffset
+ pdu_cb
->dlen
,
803 buf_len
= skb_seq_read(consumed
, &buf
, &st
);
805 skb_abort_seq_read(&st
);
809 consumed
+= sg_pcopy_from_buffer(sg
, nents
, (void *)buf
,
814 static struct iscsi_cmd
*cxgbit_allocate_cmd(struct cxgbit_sock
*csk
)
816 struct iscsi_conn
*conn
= csk
->conn
;
817 struct cxgbi_ppm
*ppm
= cdev2ppm(csk
->com
.cdev
);
818 struct cxgbit_cmd
*ccmd
;
819 struct iscsi_cmd
*cmd
;
821 cmd
= iscsit_allocate_cmd(conn
, TASK_INTERRUPTIBLE
);
823 pr_err("Unable to allocate iscsi_cmd + cxgbit_cmd\n");
827 ccmd
= iscsit_priv_cmd(cmd
);
828 ccmd
->ttinfo
.tag
= ppm
->tformat
.no_ddp_mask
;
829 ccmd
->setup_ddp
= true;
835 cxgbit_handle_immediate_data(struct iscsi_cmd
*cmd
, struct iscsi_scsi_req
*hdr
,
838 struct iscsi_conn
*conn
= cmd
->conn
;
839 struct cxgbit_sock
*csk
= conn
->context
;
840 struct cxgbit_lro_pdu_cb
*pdu_cb
= cxgbit_rx_pdu_cb(csk
->skb
);
842 if (pdu_cb
->flags
& PDUCBF_RX_DCRC_ERR
) {
843 pr_err("ImmediateData CRC32C DataDigest error\n");
844 if (!conn
->sess
->sess_ops
->ErrorRecoveryLevel
) {
845 pr_err("Unable to recover from"
846 " Immediate Data digest failure while"
848 iscsit_reject_cmd(cmd
, ISCSI_REASON_DATA_DIGEST_ERROR
,
849 (unsigned char *)hdr
);
850 return IMMEDIATE_DATA_CANNOT_RECOVER
;
853 iscsit_reject_cmd(cmd
, ISCSI_REASON_DATA_DIGEST_ERROR
,
854 (unsigned char *)hdr
);
855 return IMMEDIATE_DATA_ERL1_CRC_FAILURE
;
858 if (cmd
->se_cmd
.se_cmd_flags
& SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC
) {
859 struct cxgbit_cmd
*ccmd
= iscsit_priv_cmd(cmd
);
860 struct skb_shared_info
*ssi
= skb_shinfo(csk
->skb
);
861 skb_frag_t
*dfrag
= &ssi
->frags
[pdu_cb
->dfrag_idx
];
863 sg_init_table(&ccmd
->sg
, 1);
864 sg_set_page(&ccmd
->sg
, dfrag
->page
.p
, skb_frag_size(dfrag
),
866 get_page(dfrag
->page
.p
);
868 cmd
->se_cmd
.t_data_sg
= &ccmd
->sg
;
869 cmd
->se_cmd
.t_data_nents
= 1;
871 ccmd
->release
= true;
873 struct scatterlist
*sg
= &cmd
->se_cmd
.t_data_sg
[0];
874 u32 sg_nents
= max(1UL, DIV_ROUND_UP(pdu_cb
->dlen
, PAGE_SIZE
));
876 cxgbit_skb_copy_to_sg(csk
->skb
, sg
, sg_nents
);
879 cmd
->write_data_done
+= pdu_cb
->dlen
;
881 if (cmd
->write_data_done
== cmd
->se_cmd
.data_length
) {
882 spin_lock_bh(&cmd
->istate_lock
);
883 cmd
->cmd_flags
|= ICF_GOT_LAST_DATAOUT
;
884 cmd
->i_state
= ISTATE_RECEIVED_LAST_DATAOUT
;
885 spin_unlock_bh(&cmd
->istate_lock
);
888 return IMMEDIATE_DATA_NORMAL_OPERATION
;
892 cxgbit_get_immediate_data(struct iscsi_cmd
*cmd
, struct iscsi_scsi_req
*hdr
,
895 struct iscsi_conn
*conn
= cmd
->conn
;
896 int cmdsn_ret
= 0, immed_ret
= IMMEDIATE_DATA_NORMAL_OPERATION
;
898 * Special case for Unsupported SAM WRITE Opcodes and ImmediateData=Yes.
901 goto after_immediate_data
;
903 immed_ret
= cxgbit_handle_immediate_data(cmd
, hdr
,
904 cmd
->first_burst_len
);
905 after_immediate_data
:
906 if (immed_ret
== IMMEDIATE_DATA_NORMAL_OPERATION
) {
908 * A PDU/CmdSN carrying Immediate Data passed
909 * DataCRC, check against ExpCmdSN/MaxCmdSN if
910 * Immediate Bit is not set.
912 cmdsn_ret
= iscsit_sequence_cmd(conn
, cmd
,
913 (unsigned char *)hdr
,
915 if (cmdsn_ret
== CMDSN_ERROR_CANNOT_RECOVER
)
918 if (cmd
->sense_reason
|| cmdsn_ret
== CMDSN_LOWER_THAN_EXP
) {
919 target_put_sess_cmd(&cmd
->se_cmd
);
921 } else if (cmd
->unsolicited_data
) {
922 iscsit_set_unsoliticed_dataout(cmd
);
925 } else if (immed_ret
== IMMEDIATE_DATA_ERL1_CRC_FAILURE
) {
927 * Immediate Data failed DataCRC and ERL>=1,
928 * silently drop this PDU and let the initiator
929 * plug the CmdSN gap.
931 * FIXME: Send Unsolicited NOPIN with reserved
932 * TTT here to help the initiator figure out
933 * the missing CmdSN, although they should be
934 * intelligent enough to determine the missing
935 * CmdSN and issue a retry to plug the sequence.
937 cmd
->i_state
= ISTATE_REMOVE
;
938 iscsit_add_cmd_to_immediate_queue(cmd
, conn
, cmd
->i_state
);
939 } else /* immed_ret == IMMEDIATE_DATA_CANNOT_RECOVER */
946 cxgbit_handle_scsi_cmd(struct cxgbit_sock
*csk
, struct iscsi_cmd
*cmd
)
948 struct iscsi_conn
*conn
= csk
->conn
;
949 struct cxgbit_lro_pdu_cb
*pdu_cb
= cxgbit_rx_pdu_cb(csk
->skb
);
950 struct iscsi_scsi_req
*hdr
= (struct iscsi_scsi_req
*)pdu_cb
->hdr
;
952 bool dump_payload
= false;
954 rc
= iscsit_setup_scsi_cmd(conn
, cmd
, (unsigned char *)hdr
);
958 if (pdu_cb
->dlen
&& (pdu_cb
->dlen
== cmd
->se_cmd
.data_length
) &&
959 (pdu_cb
->nr_dfrags
== 1))
960 cmd
->se_cmd
.se_cmd_flags
|= SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC
;
962 rc
= iscsit_process_scsi_cmd(conn
, cmd
, hdr
);
971 return cxgbit_get_immediate_data(cmd
, hdr
, dump_payload
);
974 static int cxgbit_handle_iscsi_dataout(struct cxgbit_sock
*csk
)
976 struct scatterlist
*sg_start
;
977 struct iscsi_conn
*conn
= csk
->conn
;
978 struct iscsi_cmd
*cmd
= NULL
;
979 struct cxgbit_lro_pdu_cb
*pdu_cb
= cxgbit_rx_pdu_cb(csk
->skb
);
980 struct iscsi_data
*hdr
= (struct iscsi_data
*)pdu_cb
->hdr
;
981 u32 data_offset
= be32_to_cpu(hdr
->offset
);
982 u32 data_len
= pdu_cb
->dlen
;
983 int rc
, sg_nents
, sg_off
;
984 bool dcrc_err
= false;
986 rc
= iscsit_check_dataout_hdr(conn
, (unsigned char *)hdr
, &cmd
);
992 if (pdu_cb
->flags
& PDUCBF_RX_DCRC_ERR
) {
993 pr_err("ITT: 0x%08x, Offset: %u, Length: %u,"
995 hdr
->itt
, hdr
->offset
, data_len
,
1002 pr_debug("DataOut data_len: %u, "
1003 "write_data_done: %u, data_length: %u\n",
1004 data_len
, cmd
->write_data_done
,
1005 cmd
->se_cmd
.data_length
);
1007 if (!(pdu_cb
->flags
& PDUCBF_RX_DATA_DDPD
)) {
1008 sg_off
= data_offset
/ PAGE_SIZE
;
1009 sg_start
= &cmd
->se_cmd
.t_data_sg
[sg_off
];
1010 sg_nents
= max(1UL, DIV_ROUND_UP(data_len
, PAGE_SIZE
));
1012 cxgbit_skb_copy_to_sg(csk
->skb
, sg_start
, sg_nents
);
1017 rc
= iscsit_check_dataout_payload(cmd
, hdr
, dcrc_err
);
1024 static int cxgbit_handle_nop_out(struct cxgbit_sock
*csk
, struct iscsi_cmd
*cmd
)
1026 struct iscsi_conn
*conn
= csk
->conn
;
1027 struct cxgbit_lro_pdu_cb
*pdu_cb
= cxgbit_rx_pdu_cb(csk
->skb
);
1028 struct iscsi_nopout
*hdr
= (struct iscsi_nopout
*)pdu_cb
->hdr
;
1029 unsigned char *ping_data
= NULL
;
1030 u32 payload_length
= pdu_cb
->dlen
;
1033 ret
= iscsit_setup_nop_out(conn
, cmd
, hdr
);
1037 if (pdu_cb
->flags
& PDUCBF_RX_DCRC_ERR
) {
1038 if (!conn
->sess
->sess_ops
->ErrorRecoveryLevel
) {
1039 pr_err("Unable to recover from"
1040 " NOPOUT Ping DataCRC failure while in"
1046 * drop this PDU and let the
1047 * initiator plug the CmdSN gap.
1049 pr_info("Dropping NOPOUT"
1050 " Command CmdSN: 0x%08x due to"
1051 " DataCRC error.\n", hdr
->cmdsn
);
1058 * Handle NOP-OUT payload for traditional iSCSI sockets
1060 if (payload_length
&& hdr
->ttt
== cpu_to_be32(0xFFFFFFFF)) {
1061 ping_data
= kzalloc(payload_length
+ 1, GFP_KERNEL
);
1063 pr_err("Unable to allocate memory for"
1064 " NOPOUT ping data.\n");
1069 skb_copy_bits(csk
->skb
, pdu_cb
->doffset
,
1070 ping_data
, payload_length
);
1072 ping_data
[payload_length
] = '\0';
1074 * Attach ping data to struct iscsi_cmd->buf_ptr.
1076 cmd
->buf_ptr
= ping_data
;
1077 cmd
->buf_ptr_size
= payload_length
;
1079 pr_debug("Got %u bytes of NOPOUT ping"
1080 " data.\n", payload_length
);
1081 pr_debug("Ping Data: \"%s\"\n", ping_data
);
1084 return iscsit_process_nop_out(conn
, cmd
, hdr
);
1087 iscsit_free_cmd(cmd
, false);
1092 cxgbit_handle_text_cmd(struct cxgbit_sock
*csk
, struct iscsi_cmd
*cmd
)
1094 struct iscsi_conn
*conn
= csk
->conn
;
1095 struct cxgbit_lro_pdu_cb
*pdu_cb
= cxgbit_rx_pdu_cb(csk
->skb
);
1096 struct iscsi_text
*hdr
= (struct iscsi_text
*)pdu_cb
->hdr
;
1097 u32 payload_length
= pdu_cb
->dlen
;
1099 unsigned char *text_in
= NULL
;
1101 rc
= iscsit_setup_text_cmd(conn
, cmd
, hdr
);
1105 if (pdu_cb
->flags
& PDUCBF_RX_DCRC_ERR
) {
1106 if (!conn
->sess
->sess_ops
->ErrorRecoveryLevel
) {
1107 pr_err("Unable to recover from"
1108 " Text Data digest failure while in"
1113 * drop this PDU and let the
1114 * initiator plug the CmdSN gap.
1116 pr_info("Dropping Text"
1117 " Command CmdSN: 0x%08x due to"
1118 " DataCRC error.\n", hdr
->cmdsn
);
1123 if (payload_length
) {
1124 text_in
= kzalloc(payload_length
, GFP_KERNEL
);
1126 pr_err("Unable to allocate text_in of payload_length: %u\n",
1130 skb_copy_bits(csk
->skb
, pdu_cb
->doffset
,
1131 text_in
, payload_length
);
1133 text_in
[payload_length
- 1] = '\0';
1135 cmd
->text_in_ptr
= text_in
;
1138 return iscsit_process_text_cmd(conn
, cmd
, hdr
);
1141 return iscsit_reject_cmd(cmd
, ISCSI_REASON_PROTOCOL_ERROR
,
1145 static int cxgbit_target_rx_opcode(struct cxgbit_sock
*csk
)
1147 struct cxgbit_lro_pdu_cb
*pdu_cb
= cxgbit_rx_pdu_cb(csk
->skb
);
1148 struct iscsi_hdr
*hdr
= (struct iscsi_hdr
*)pdu_cb
->hdr
;
1149 struct iscsi_conn
*conn
= csk
->conn
;
1150 struct iscsi_cmd
*cmd
= NULL
;
1151 u8 opcode
= (hdr
->opcode
& ISCSI_OPCODE_MASK
);
1155 case ISCSI_OP_SCSI_CMD
:
1156 cmd
= cxgbit_allocate_cmd(csk
);
1160 ret
= cxgbit_handle_scsi_cmd(csk
, cmd
);
1162 case ISCSI_OP_SCSI_DATA_OUT
:
1163 ret
= cxgbit_handle_iscsi_dataout(csk
);
1165 case ISCSI_OP_NOOP_OUT
:
1166 if (hdr
->ttt
== cpu_to_be32(0xFFFFFFFF)) {
1167 cmd
= cxgbit_allocate_cmd(csk
);
1172 ret
= cxgbit_handle_nop_out(csk
, cmd
);
1174 case ISCSI_OP_SCSI_TMFUNC
:
1175 cmd
= cxgbit_allocate_cmd(csk
);
1179 ret
= iscsit_handle_task_mgt_cmd(conn
, cmd
,
1180 (unsigned char *)hdr
);
1183 if (hdr
->ttt
!= cpu_to_be32(0xFFFFFFFF)) {
1184 cmd
= iscsit_find_cmd_from_itt(conn
, hdr
->itt
);
1188 cmd
= cxgbit_allocate_cmd(csk
);
1193 ret
= cxgbit_handle_text_cmd(csk
, cmd
);
1195 case ISCSI_OP_LOGOUT
:
1196 cmd
= cxgbit_allocate_cmd(csk
);
1200 ret
= iscsit_handle_logout_cmd(conn
, cmd
, (unsigned char *)hdr
);
1202 wait_for_completion_timeout(&conn
->conn_logout_comp
,
1203 SECONDS_FOR_LOGOUT_COMP
1206 case ISCSI_OP_SNACK
:
1207 ret
= iscsit_handle_snack(conn
, (unsigned char *)hdr
);
1210 pr_err("Got unknown iSCSI OpCode: 0x%02x\n", opcode
);
1218 return iscsit_add_reject(conn
, ISCSI_REASON_BOOKMARK_NO_RESOURCES
,
1219 (unsigned char *)hdr
);
1223 static int cxgbit_rx_opcode(struct cxgbit_sock
*csk
)
1225 struct cxgbit_lro_pdu_cb
*pdu_cb
= cxgbit_rx_pdu_cb(csk
->skb
);
1226 struct iscsi_conn
*conn
= csk
->conn
;
1227 struct iscsi_hdr
*hdr
= pdu_cb
->hdr
;
1230 if (pdu_cb
->flags
& PDUCBF_RX_HCRC_ERR
) {
1231 atomic_long_inc(&conn
->sess
->conn_digest_errors
);
1235 if (conn
->conn_state
== TARG_CONN_STATE_IN_LOGOUT
)
1238 opcode
= hdr
->opcode
& ISCSI_OPCODE_MASK
;
1240 if (conn
->sess
->sess_ops
->SessionType
&&
1241 ((!(opcode
& ISCSI_OP_TEXT
)) ||
1242 (!(opcode
& ISCSI_OP_LOGOUT
)))) {
1243 pr_err("Received illegal iSCSI Opcode: 0x%02x"
1244 " while in Discovery Session, rejecting.\n", opcode
);
1245 iscsit_add_reject(conn
, ISCSI_REASON_PROTOCOL_ERROR
,
1246 (unsigned char *)hdr
);
1250 if (cxgbit_target_rx_opcode(csk
) < 0)
1259 static int cxgbit_rx_login_pdu(struct cxgbit_sock
*csk
)
1261 struct iscsi_conn
*conn
= csk
->conn
;
1262 struct iscsi_login
*login
= conn
->login
;
1263 struct cxgbit_lro_pdu_cb
*pdu_cb
= cxgbit_rx_pdu_cb(csk
->skb
);
1264 struct iscsi_login_req
*login_req
;
1266 login_req
= (struct iscsi_login_req
*)login
->req
;
1267 memcpy(login_req
, pdu_cb
->hdr
, sizeof(*login_req
));
1269 pr_debug("Got Login Command, Flags 0x%02x, ITT: 0x%08x,"
1270 " CmdSN: 0x%08x, ExpStatSN: 0x%08x, CID: %hu, Length: %u\n",
1271 login_req
->flags
, login_req
->itt
, login_req
->cmdsn
,
1272 login_req
->exp_statsn
, login_req
->cid
, pdu_cb
->dlen
);
1274 * Setup the initial iscsi_login values from the leading
1275 * login request PDU.
1277 if (login
->first_request
) {
1278 login_req
= (struct iscsi_login_req
*)login
->req
;
1279 login
->leading_connection
= (!login_req
->tsih
) ? 1 : 0;
1280 login
->current_stage
= ISCSI_LOGIN_CURRENT_STAGE(
1282 login
->version_min
= login_req
->min_version
;
1283 login
->version_max
= login_req
->max_version
;
1284 memcpy(login
->isid
, login_req
->isid
, 6);
1285 login
->cmd_sn
= be32_to_cpu(login_req
->cmdsn
);
1286 login
->init_task_tag
= login_req
->itt
;
1287 login
->initial_exp_statsn
= be32_to_cpu(login_req
->exp_statsn
);
1288 login
->cid
= be16_to_cpu(login_req
->cid
);
1289 login
->tsih
= be16_to_cpu(login_req
->tsih
);
1292 if (iscsi_target_check_login_request(conn
, login
) < 0)
1295 memset(login
->req_buf
, 0, MAX_KEY_VALUE_PAIRS
);
1296 skb_copy_bits(csk
->skb
, pdu_cb
->doffset
, login
->req_buf
, pdu_cb
->dlen
);
1302 cxgbit_process_iscsi_pdu(struct cxgbit_sock
*csk
, struct sk_buff
*skb
, int idx
)
1304 struct cxgbit_lro_pdu_cb
*pdu_cb
= cxgbit_skb_lro_pdu_cb(skb
, idx
);
1307 cxgbit_rx_pdu_cb(skb
) = pdu_cb
;
1311 if (!test_bit(CSK_LOGIN_DONE
, &csk
->com
.flags
)) {
1312 ret
= cxgbit_rx_login_pdu(csk
);
1313 set_bit(CSK_LOGIN_PDU_DONE
, &csk
->com
.flags
);
1315 ret
= cxgbit_rx_opcode(csk
);
1321 static void cxgbit_lro_skb_dump(struct sk_buff
*skb
)
1323 struct skb_shared_info
*ssi
= skb_shinfo(skb
);
1324 struct cxgbit_lro_cb
*lro_cb
= cxgbit_skb_lro_cb(skb
);
1325 struct cxgbit_lro_pdu_cb
*pdu_cb
= cxgbit_skb_lro_pdu_cb(skb
, 0);
1328 pr_info("skb 0x%p, head 0x%p, 0x%p, len %u,%u, frags %u.\n",
1329 skb
, skb
->head
, skb
->data
, skb
->len
, skb
->data_len
,
1331 pr_info("skb 0x%p, lro_cb, csk 0x%p, pdu %u, %u.\n",
1332 skb
, lro_cb
->csk
, lro_cb
->pdu_idx
, lro_cb
->pdu_totallen
);
1334 for (i
= 0; i
< lro_cb
->pdu_idx
; i
++, pdu_cb
++)
1335 pr_info("skb 0x%p, pdu %d, %u, f 0x%x, seq 0x%x, dcrc 0x%x, "
1337 skb
, i
, pdu_cb
->pdulen
, pdu_cb
->flags
, pdu_cb
->seq
,
1338 pdu_cb
->ddigest
, pdu_cb
->frags
);
1339 for (i
= 0; i
< ssi
->nr_frags
; i
++)
1340 pr_info("skb 0x%p, frag %d, off %u, sz %u.\n",
1341 skb
, i
, ssi
->frags
[i
].page_offset
, ssi
->frags
[i
].size
);
1344 static void cxgbit_lro_hskb_reset(struct cxgbit_sock
*csk
)
1346 struct sk_buff
*skb
= csk
->lro_hskb
;
1347 struct skb_shared_info
*ssi
= skb_shinfo(skb
);
1350 memset(skb
->data
, 0, LRO_SKB_MIN_HEADROOM
);
1351 for (i
= 0; i
< ssi
->nr_frags
; i
++)
1352 put_page(skb_frag_page(&ssi
->frags
[i
]));
1357 cxgbit_lro_skb_merge(struct cxgbit_sock
*csk
, struct sk_buff
*skb
, u8 pdu_idx
)
1359 struct sk_buff
*hskb
= csk
->lro_hskb
;
1360 struct cxgbit_lro_pdu_cb
*hpdu_cb
= cxgbit_skb_lro_pdu_cb(hskb
, 0);
1361 struct cxgbit_lro_pdu_cb
*pdu_cb
= cxgbit_skb_lro_pdu_cb(skb
, pdu_idx
);
1362 struct skb_shared_info
*hssi
= skb_shinfo(hskb
);
1363 struct skb_shared_info
*ssi
= skb_shinfo(skb
);
1364 unsigned int len
= 0;
1366 if (pdu_cb
->flags
& PDUCBF_RX_HDR
) {
1367 hpdu_cb
->flags
= pdu_cb
->flags
;
1368 hpdu_cb
->seq
= pdu_cb
->seq
;
1369 hpdu_cb
->hdr
= pdu_cb
->hdr
;
1370 hpdu_cb
->hlen
= pdu_cb
->hlen
;
1372 memcpy(&hssi
->frags
[0], &ssi
->frags
[pdu_cb
->hfrag_idx
],
1373 sizeof(skb_frag_t
));
1375 get_page(skb_frag_page(&hssi
->frags
[0]));
1378 hpdu_cb
->hfrag_idx
= 0;
1380 len
= hssi
->frags
[0].size
;
1382 hskb
->data_len
= len
;
1383 hskb
->truesize
= len
;
1386 if (pdu_cb
->flags
& PDUCBF_RX_DATA
) {
1387 u8 hfrag_idx
= 1, i
;
1389 hpdu_cb
->flags
|= pdu_cb
->flags
;
1392 for (i
= 0; i
< pdu_cb
->nr_dfrags
; hfrag_idx
++, i
++) {
1393 memcpy(&hssi
->frags
[hfrag_idx
],
1394 &ssi
->frags
[pdu_cb
->dfrag_idx
+ i
],
1395 sizeof(skb_frag_t
));
1397 get_page(skb_frag_page(&hssi
->frags
[hfrag_idx
]));
1399 len
+= hssi
->frags
[hfrag_idx
].size
;
1405 hpdu_cb
->dlen
= pdu_cb
->dlen
;
1406 hpdu_cb
->doffset
= hpdu_cb
->hlen
;
1407 hpdu_cb
->nr_dfrags
= pdu_cb
->nr_dfrags
;
1408 hpdu_cb
->dfrag_idx
= 1;
1410 hskb
->data_len
+= len
;
1411 hskb
->truesize
+= len
;
1414 if (pdu_cb
->flags
& PDUCBF_RX_STATUS
) {
1415 hpdu_cb
->flags
|= pdu_cb
->flags
;
1417 if (hpdu_cb
->flags
& PDUCBF_RX_DATA
)
1418 hpdu_cb
->flags
&= ~PDUCBF_RX_DATA_DDPD
;
1420 hpdu_cb
->ddigest
= pdu_cb
->ddigest
;
1421 hpdu_cb
->pdulen
= pdu_cb
->pdulen
;
1425 static int cxgbit_process_lro_skb(struct cxgbit_sock
*csk
, struct sk_buff
*skb
)
1427 struct cxgbit_lro_cb
*lro_cb
= cxgbit_skb_lro_cb(skb
);
1428 struct cxgbit_lro_pdu_cb
*pdu_cb
= cxgbit_skb_lro_pdu_cb(skb
, 0);
1429 u8 pdu_idx
= 0, last_idx
= 0;
1432 if (!pdu_cb
->complete
) {
1433 cxgbit_lro_skb_merge(csk
, skb
, 0);
1435 if (pdu_cb
->flags
& PDUCBF_RX_STATUS
) {
1436 struct sk_buff
*hskb
= csk
->lro_hskb
;
1438 ret
= cxgbit_process_iscsi_pdu(csk
, hskb
, 0);
1440 cxgbit_lro_hskb_reset(csk
);
1449 if (lro_cb
->pdu_idx
)
1450 last_idx
= lro_cb
->pdu_idx
- 1;
1452 for (; pdu_idx
<= last_idx
; pdu_idx
++) {
1453 ret
= cxgbit_process_iscsi_pdu(csk
, skb
, pdu_idx
);
1458 if ((!lro_cb
->complete
) && lro_cb
->pdu_idx
)
1459 cxgbit_lro_skb_merge(csk
, skb
, lro_cb
->pdu_idx
);
1465 static int cxgbit_rx_lro_skb(struct cxgbit_sock
*csk
, struct sk_buff
*skb
)
1467 struct cxgbit_lro_cb
*lro_cb
= cxgbit_skb_lro_cb(skb
);
1468 struct cxgbit_lro_pdu_cb
*pdu_cb
= cxgbit_skb_lro_pdu_cb(skb
, 0);
1471 if ((pdu_cb
->flags
& PDUCBF_RX_HDR
) &&
1472 (pdu_cb
->seq
!= csk
->rcv_nxt
)) {
1473 pr_info("csk 0x%p, tid 0x%x, seq 0x%x != 0x%x.\n",
1474 csk
, csk
->tid
, pdu_cb
->seq
, csk
->rcv_nxt
);
1475 cxgbit_lro_skb_dump(skb
);
1479 csk
->rcv_nxt
+= lro_cb
->pdu_totallen
;
1481 ret
= cxgbit_process_lro_skb(csk
, skb
);
1483 csk
->rx_credits
+= lro_cb
->pdu_totallen
;
1485 if (csk
->rx_credits
>= (csk
->rcv_win
/ 4))
1486 cxgbit_rx_data_ack(csk
);
1491 static int cxgbit_rx_skb(struct cxgbit_sock
*csk
, struct sk_buff
*skb
)
1495 if (likely(cxgbit_skcb_flags(skb
) & SKCBF_RX_LRO
))
1496 ret
= cxgbit_rx_lro_skb(csk
, skb
);
1502 static bool cxgbit_rxq_len(struct cxgbit_sock
*csk
, struct sk_buff_head
*rxq
)
1504 spin_lock_bh(&csk
->rxq
.lock
);
1505 if (skb_queue_len(&csk
->rxq
)) {
1506 skb_queue_splice_init(&csk
->rxq
, rxq
);
1507 spin_unlock_bh(&csk
->rxq
.lock
);
1510 spin_unlock_bh(&csk
->rxq
.lock
);
1514 static int cxgbit_wait_rxq(struct cxgbit_sock
*csk
)
1516 struct sk_buff
*skb
;
1517 struct sk_buff_head rxq
;
1519 skb_queue_head_init(&rxq
);
1521 wait_event_interruptible(csk
->waitq
, cxgbit_rxq_len(csk
, &rxq
));
1523 if (signal_pending(current
))
1526 while ((skb
= __skb_dequeue(&rxq
))) {
1527 if (cxgbit_rx_skb(csk
, skb
))
1533 __skb_queue_purge(&rxq
);
1537 int cxgbit_get_login_rx(struct iscsi_conn
*conn
, struct iscsi_login
*login
)
1539 struct cxgbit_sock
*csk
= conn
->context
;
1542 while (!test_and_clear_bit(CSK_LOGIN_PDU_DONE
, &csk
->com
.flags
)) {
1543 ret
= cxgbit_wait_rxq(csk
);
1545 clear_bit(CSK_LOGIN_PDU_DONE
, &csk
->com
.flags
);
1553 void cxgbit_get_rx_pdu(struct iscsi_conn
*conn
)
1555 struct cxgbit_sock
*csk
= conn
->context
;
1557 while (!kthread_should_stop()) {
1558 iscsit_thread_check_cpumask(conn
, current
, 0);
1559 if (cxgbit_wait_rxq(csk
))