22 #include <linux/slab.h>
23 #include <linux/random.h>
30 #define OFFLOAD_BUF_SIZE 32768
38 pr_debug(
"Dumping Sequence List for ITT: 0x%08x:\n",
43 pr_debug(
"i: %d, pdu_start: %d, pdu_count: %d,"
44 " offset: %d, xfer_len: %d, seq_send_order: %d,"
56 pr_debug(
"Dumping PDU List for ITT: 0x%08x:\n",
61 pr_debug(
"i: %d, offset: %d, length: %d,"
62 " pdu_send_order: %d, seq_no: %d\n", i, pdu->
offset,
67 static void iscsit_dump_seq_list(
struct iscsi_cmd *cmd) {}
68 static void iscsit_dump_pdu_list(
struct iscsi_cmd *cmd) {}
71 static void iscsit_ordered_seq_lists(
80 cmd->
seq_list[
i].seq_send_order = seq_count++;
84 static void iscsit_ordered_pdu_lists(
93 cmd->
pdu_list[
i].pdu_send_order = pdu_send_order++;
106 static void iscsit_create_random_array(
u32 *array,
u32 count)
115 for (i = 0; i <
count; i++) {
118 j = (1 + (
int) (9999 + 1) -
j) % count;
119 for (k = 0; k < i + 1; k++) {
121 if ((array[k] & 0x80000000) && (array[
k] ==
j))
127 for (i = 0; i <
count; i++)
128 array[i] &= ~0x80000000;
131 static int iscsit_randomize_pdu_lists(
138 for (pdu_count = 0; pdu_count < cmd->
pdu_count; pdu_count++) {
146 pr_err(
"Unable to allocate memory"
147 " for random array.\n");
150 iscsit_create_random_array(array, seq_count);
152 for (i = 0; i < seq_count; i++)
166 pr_err(
"Unable to allocate memory for"
170 iscsit_create_random_array(array, seq_count);
172 for (i = 0; i < seq_count; i++)
181 static int iscsit_randomize_seq_lists(
198 pr_err(
"Unable to allocate memory for random array.\n");
201 iscsit_create_random_array(array, seq_count);
206 cmd->
seq_list[
i].seq_send_order = array[j++];
213 static void iscsit_determine_counts_for_list(
219 int check_immediate = 0;
221 u32 unsolicited_data_length = 0;
226 mdsl = cmd->
conn->conn_ops->MaxXmitDataSegmentLength;
228 mdsl = cmd->
conn->conn_ops->MaxRecvDataSegmentLength;
236 unsolicited_data_length =
min(cmd->
se_cmd.data_length,
237 conn->
sess->sess_ops->FirstBurstLength);
242 if (check_immediate) {
246 if (unsolicited_data_length)
247 unsolicited_data_length -=
251 if (unsolicited_data_length > 0) {
253 unsolicited_data_length -=
259 >= conn->
sess->sess_ops->FirstBurstLength) {
260 unsolicited_data_length -=
261 (conn->
sess->sess_ops->FirstBurstLength -
263 offset += (conn->
sess->sess_ops->FirstBurstLength -
271 unsolicited_data_length -= mdsl;
278 if ((burstlength + mdsl) >=
279 conn->
sess->sess_ops->MaxBurstLength) {
280 offset += (conn->
sess->sess_ops->MaxBurstLength -
297 static int iscsit_do_build_pdu_and_seq_lists(
301 int check_immediate = 0, datapduinorder, datasequenceinorder;
302 u32 burstlength = 0,
offset = 0, i = 0, mdsl;
303 u32 pdu_count = 0,
seq_no = 0, unsolicited_data_length = 0;
309 mdsl = cmd->
conn->conn_ops->MaxXmitDataSegmentLength;
311 mdsl = cmd->
conn->conn_ops->MaxRecvDataSegmentLength;
313 datapduinorder = conn->
sess->sess_ops->DataPDUInOrder;
314 datasequenceinorder = conn->
sess->sess_ops->DataSequenceInOrder;
322 unsolicited_data_length =
min(cmd->
se_cmd.data_length,
323 conn->
sess->sess_ops->FirstBurstLength);
327 if (!datapduinorder) {
331 if (!datasequenceinorder && (pdu_count == 1)) {
338 if (check_immediate) {
340 if (!datapduinorder) {
344 if (!datasequenceinorder) {
353 if (unsolicited_data_length)
354 unsolicited_data_length -=
358 if (unsolicited_data_length > 0) {
360 if (!datapduinorder) {
365 if (!datasequenceinorder) {
371 unsolicited_data_length -=
377 conn->
sess->sess_ops->FirstBurstLength) {
378 if (!datapduinorder) {
381 (conn->
sess->sess_ops->FirstBurstLength -
384 if (!datasequenceinorder) {
388 (conn->
sess->sess_ops->FirstBurstLength -
391 unsolicited_data_length -=
392 (conn->
sess->sess_ops->FirstBurstLength -
394 offset += (conn->
sess->sess_ops->FirstBurstLength -
402 if (!datapduinorder) {
408 unsolicited_data_length -= mdsl;
412 if (!datapduinorder) {
416 if (!datasequenceinorder) {
425 if ((burstlength + mdsl) >=
426 conn->
sess->sess_ops->MaxBurstLength) {
427 if (!datapduinorder) {
430 (conn->
sess->sess_ops->MaxBurstLength -
433 if (!datasequenceinorder) {
437 (conn->
sess->sess_ops->MaxBurstLength -
440 offset += (conn->
sess->sess_ops->MaxBurstLength -
448 if (!datapduinorder) {
456 if (!datasequenceinorder) {
459 if (iscsit_randomize_seq_lists(cmd, bl->
type)
463 iscsit_ordered_seq_lists(cmd, bl->
type);
466 if (iscsit_randomize_seq_lists(cmd, bl->
type)
470 iscsit_ordered_seq_lists(cmd, bl->
type);
473 iscsit_dump_seq_list(cmd);
475 if (!datapduinorder) {
478 if (iscsit_randomize_pdu_lists(cmd, bl->
type)
482 iscsit_ordered_pdu_lists(cmd, bl->
type);
485 if (iscsit_randomize_pdu_lists(cmd, bl->
type)
489 iscsit_ordered_pdu_lists(cmd, bl->
type);
492 iscsit_dump_pdu_list(cmd);
500 u32 immediate_data_length)
503 u32 pdu_count = 0, seq_count = 1;
514 if (sess->
sess_ops->DataSequenceInOrder &&
547 iscsit_determine_counts_for_list(cmd, &bl, &seq_count, &pdu_count);
549 if (!conn->
sess->sess_ops->DataSequenceInOrder) {
552 pr_err(
"Unable to allocate struct iscsi_seq list\n");
559 if (!conn->
sess->sess_ops->DataPDUInOrder) {
562 pr_err(
"Unable to allocate struct iscsi_pdu list.\n");
570 return iscsit_do_build_pdu_and_seq_lists(cmd, &bl);
582 pr_err(
"struct iscsi_cmd->pdu_list is NULL!\n");
589 if ((pdu[i].offset == offset) && (pdu[i].length == length))
592 pr_err(
"Unable to locate PDU holder for ITT: 0x%08x, Offset:"
606 pr_err(
"struct iscsi_cmd->pdu_list is NULL!\n");
610 if (conn->
sess->sess_ops->DataSequenceInOrder) {
615 pr_debug(
"pdu[i].seq_no: %d, pdu[i].pdu"
616 "_send_order: %d, pdu[i].offset: %d,"
617 " pdu[i].length: %d\n", pdu[i].
seq_no,
618 pdu[i].pdu_send_order, pdu[i].
offset,
634 pr_err(
"Command ITT: 0x%08x unable to locate"
635 " struct iscsi_pdu for cmd->pdu_send_order: %u.\n",
640 pr_err(
"struct iscsi_seq is NULL!\n");
644 pr_debug(
"seq->pdu_start: %d, seq->pdu_count: %d,"
651 pr_err(
"Command ITT: 0x%08x seq->pdu_send"
652 "_order: %u equals seq->pdu_count: %u\n",
665 pr_err(
"Command ITT: 0x%08x unable to locate iscsi"
666 "_pdu_t for seq->pdu_send_order: %u.\n",
682 pr_err(
"struct iscsi_cmd->seq_list is NULL!\n");
687 pr_debug(
"seq_list[i].orig_offset: %d, seq_list[i]."
688 "xfer_len: %d, seq_list[i].seq_no %u\n",
698 pr_err(
"Unable to locate Sequence holder for ITT: 0x%08x,"