1 /* QLogic FCoE Offload Driver
2  * Copyright (c) 2016-2018 Cavium Inc.
3  *
4  * This software is available under the terms of the GNU General Public License
5  * (GPL) Version 2, available from the file COPYING in the main directory of
6  * this source tree.
7  */
8 #include "drv_scsi_fw_funcs.h"
9 
10 #define SCSI_NUM_SGES_IN_CACHE 0x4
11 
12 bool scsi_is_slow_sgl(u16 num_sges, bool small_mid_sge)
13 {
14 	return (num_sges > SCSI_NUM_SGES_SLOW_SGL_THR && small_mid_sge);
15 }
16 
17 void init_scsi_sgl_context(struct scsi_sgl_params *ctx_sgl_params,
18 			   struct scsi_cached_sges *ctx_data_desc,
19 			   struct scsi_sgl_task_params *sgl_task_params)
20 {
21 	/* no need to check for sgl_task_params->sgl validity */
22 	u8 num_sges_to_init = sgl_task_params->num_sges >
23 			      SCSI_NUM_SGES_IN_CACHE ? SCSI_NUM_SGES_IN_CACHE :
24 			      sgl_task_params->num_sges;
25 	u8 sge_index;
26 	u32 val;
27 
28 	val = cpu_to_le32(sgl_task_params->sgl_phys_addr.lo);
29 	ctx_sgl_params->sgl_addr.lo = val;
30 	val = cpu_to_le32(sgl_task_params->sgl_phys_addr.hi);
31 	ctx_sgl_params->sgl_addr.hi = val;
32 	val = cpu_to_le32(sgl_task_params->total_buffer_size);
33 	ctx_sgl_params->sgl_total_length = val;
34 	ctx_sgl_params->sgl_num_sges = cpu_to_le16(sgl_task_params->num_sges);
35 
36 	for (sge_index = 0; sge_index < num_sges_to_init; sge_index++) {
37 		val = cpu_to_le32(sgl_task_params->sgl[sge_index].sge_addr.lo);
38 		ctx_data_desc->sge[sge_index].sge_addr.lo = val;
39 		val = cpu_to_le32(sgl_task_params->sgl[sge_index].sge_addr.hi);
40 		ctx_data_desc->sge[sge_index].sge_addr.hi = val;
41 		val = cpu_to_le32(sgl_task_params->sgl[sge_index].sge_len);
42 		ctx_data_desc->sge[sge_index].sge_len = val;
43 	}
44 }
45