diff mbox series

[1/2] libfc: move scsi/fc_encode.h to libfc

Message ID 20201026160705.3706396-1-arnd@kernel.org
State New
Headers show
Series [1/2] libfc: move scsi/fc_encode.h to libfc | expand

Commit Message

Arnd Bergmann Oct. 26, 2020, 4:06 p.m. UTC
From: Arnd Bergmann <arnd@arndb.de>

Most of this file is only used inside of libfc, so move
it to where it is actually used, with only fc_fill_fc_hdr()
left inside of the header.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/scsi/bnx2fc/bnx2fc.h                  |  1 -
 drivers/scsi/libfc/fc_elsct.c                 |  2 +-
 .../scsi => drivers/scsi/libfc}/fc_encode.h   | 30 +------------------
 drivers/scsi/libfc/fc_exch.c                  |  1 -
 drivers/scsi/libfc/fc_fcp.c                   |  2 +-
 drivers/scsi/libfc/fc_libfc.c                 |  2 +-
 drivers/scsi/libfc/fc_lport.c                 |  2 +-
 drivers/scsi/libfc/fc_rport.c                 |  2 +-
 drivers/scsi/qedf/qedf.h                      |  1 -
 drivers/target/tcm_fc/tfc_cmd.c               |  1 -
 drivers/target/tcm_fc/tfc_io.c                |  1 -
 include/scsi/fc_frame.h                       | 30 +++++++++++++++++++
 12 files changed, 36 insertions(+), 39 deletions(-)
 rename {include/scsi => drivers/scsi/libfc}/fc_encode.h (96%)

Comments

kernel test robot Oct. 27, 2020, 2:39 a.m. UTC | #1
Hi Arnd,

I love your patch! Perhaps something to improve:

[auto build test WARNING on mkp-scsi/for-next]
[also build test WARNING on scsi/for-next soc/for-next v5.10-rc1 next-20201026]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Arnd-Bergmann/libfc-move-scsi-fc_encode-h-to-libfc/20201027-000828
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next
config: riscv-randconfig-r033-20201026 (attached as .config)
compiler: riscv32-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/fc5c97b36d0d6d4adba894820c9a412f0467438e
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Arnd-Bergmann/libfc-move-scsi-fc_encode-h-to-libfc/20201027-000828
        git checkout fc5c97b36d0d6d4adba894820c9a412f0467438e
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=riscv 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   In file included from drivers/scsi/libfc/fc_elsct.c:18:
   In function 'fc_ct_ns_fill',
       inlined from 'fc_ct_fill' at drivers/scsi/libfc/fc_encode.h:483:8,
       inlined from 'fc_elsct_send' at drivers/scsi/libfc/fc_elsct.c:47:8:
>> drivers/scsi/libfc/fc_encode.h:153:3: warning: 'strncpy' output may be truncated copying between 0 and 255 bytes from a string of length 255 [-Wstringop-truncation]

     153 |   strncpy(ct->payload.snn.fr_name,
         |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     154 |    fc_host_symbolic_name(lport->host), len);
         |    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/scsi/libfc/fc_encode.h:143:3: warning: 'strncpy' output may be truncated copying between 0 and 255 bytes from a string of length 255 [-Wstringop-truncation]
     143 |   strncpy(ct->payload.spn.fr_name,
         |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     144 |    fc_host_symbolic_name(lport->host), len);
         |    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

vim +/strncpy +153 drivers/scsi/libfc/fc_encode.h

42e9a92fe6a909 include/scsi/fc_encode.h Robert Love   2008-12-09   81  
42e9a92fe6a909 include/scsi/fc_encode.h Robert Love   2008-12-09   82  /**
1ea2c1daf4476a include/scsi/fc_encode.h Neerav Parikh 2012-01-22   83   * fc_ct_ns_fill() - Fill in a name service request frame
2ab7e1ecb81ce3 include/scsi/fc_encode.h Joe Eykholt   2009-08-25   84   * @lport: local port.
2ab7e1ecb81ce3 include/scsi/fc_encode.h Joe Eykholt   2009-08-25   85   * @fc_id: FC_ID of non-destination rport for GPN_ID and similar inquiries.
2ab7e1ecb81ce3 include/scsi/fc_encode.h Joe Eykholt   2009-08-25   86   * @fp: frame to contain payload.
2ab7e1ecb81ce3 include/scsi/fc_encode.h Joe Eykholt   2009-08-25   87   * @op: CT opcode.
2ab7e1ecb81ce3 include/scsi/fc_encode.h Joe Eykholt   2009-08-25   88   * @r_ctl: pointer to FC header R_CTL.
2ab7e1ecb81ce3 include/scsi/fc_encode.h Joe Eykholt   2009-08-25   89   * @fh_type: pointer to FC-4 type.
42e9a92fe6a909 include/scsi/fc_encode.h Robert Love   2008-12-09   90   */
1ea2c1daf4476a include/scsi/fc_encode.h Neerav Parikh 2012-01-22   91  static inline int fc_ct_ns_fill(struct fc_lport *lport,
2ab7e1ecb81ce3 include/scsi/fc_encode.h Joe Eykholt   2009-08-25   92  		      u32 fc_id, struct fc_frame *fp,
a46f327aa5caf2 include/scsi/fc_encode.h Joe Eykholt   2009-08-25   93  		      unsigned int op, enum fc_rctl *r_ctl,
42e9a92fe6a909 include/scsi/fc_encode.h Robert Love   2008-12-09   94  		      enum fc_fh_type *fh_type)
42e9a92fe6a909 include/scsi/fc_encode.h Robert Love   2008-12-09   95  {
42e9a92fe6a909 include/scsi/fc_encode.h Robert Love   2008-12-09   96  	struct fc_ct_req *ct;
5f9a056db9c797 include/scsi/fc_encode.h Joe Eykholt   2009-11-03   97  	size_t len;
42e9a92fe6a909 include/scsi/fc_encode.h Robert Love   2008-12-09   98  
42e9a92fe6a909 include/scsi/fc_encode.h Robert Love   2008-12-09   99  	switch (op) {
42e9a92fe6a909 include/scsi/fc_encode.h Robert Love   2008-12-09  100  	case FC_NS_GPN_FT:
1ea2c1daf4476a include/scsi/fc_encode.h Neerav Parikh 2012-01-22  101  		ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_gid_ft),
1ea2c1daf4476a include/scsi/fc_encode.h Neerav Parikh 2012-01-22  102  				    FC_FST_DIR, FC_NS_SUBTYPE);
42e9a92fe6a909 include/scsi/fc_encode.h Robert Love   2008-12-09  103  		ct->payload.gid.fn_fc4_type = FC_TYPE_FCP;
42e9a92fe6a909 include/scsi/fc_encode.h Robert Love   2008-12-09  104  		break;
42e9a92fe6a909 include/scsi/fc_encode.h Robert Love   2008-12-09  105  
2ab7e1ecb81ce3 include/scsi/fc_encode.h Joe Eykholt   2009-08-25  106  	case FC_NS_GPN_ID:
1ea2c1daf4476a include/scsi/fc_encode.h Neerav Parikh 2012-01-22  107  		ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_fid),
1ea2c1daf4476a include/scsi/fc_encode.h Neerav Parikh 2012-01-22  108  				    FC_FST_DIR, FC_NS_SUBTYPE);
1ea2c1daf4476a include/scsi/fc_encode.h Neerav Parikh 2012-01-22  109  		ct->payload.gid.fn_fc4_type = FC_TYPE_FCP;
2ab7e1ecb81ce3 include/scsi/fc_encode.h Joe Eykholt   2009-08-25  110  		hton24(ct->payload.fid.fp_fid, fc_id);
2ab7e1ecb81ce3 include/scsi/fc_encode.h Joe Eykholt   2009-08-25  111  		break;
2ab7e1ecb81ce3 include/scsi/fc_encode.h Joe Eykholt   2009-08-25  112  
42e9a92fe6a909 include/scsi/fc_encode.h Robert Love   2008-12-09  113  	case FC_NS_RFT_ID:
1ea2c1daf4476a include/scsi/fc_encode.h Neerav Parikh 2012-01-22  114  		ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_rft),
1ea2c1daf4476a include/scsi/fc_encode.h Neerav Parikh 2012-01-22  115  				    FC_FST_DIR, FC_NS_SUBTYPE);
7b2787ec15b9d1 include/scsi/fc_encode.h Robert Love   2010-05-07  116  		hton24(ct->payload.rft.fid.fp_fid, lport->port_id);
42e9a92fe6a909 include/scsi/fc_encode.h Robert Love   2008-12-09  117  		ct->payload.rft.fts = lport->fcts;
42e9a92fe6a909 include/scsi/fc_encode.h Robert Love   2008-12-09  118  		break;
42e9a92fe6a909 include/scsi/fc_encode.h Robert Love   2008-12-09  119  
ab593b187391bd include/scsi/fc_encode.h Joe Eykholt   2009-11-03  120  	case FC_NS_RFF_ID:
1ea2c1daf4476a include/scsi/fc_encode.h Neerav Parikh 2012-01-22  121  		ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_rff_id),
1ea2c1daf4476a include/scsi/fc_encode.h Neerav Parikh 2012-01-22  122  				    FC_FST_DIR, FC_NS_SUBTYPE);
7b2787ec15b9d1 include/scsi/fc_encode.h Robert Love   2010-05-07  123  		hton24(ct->payload.rff.fr_fid.fp_fid, lport->port_id);
ab593b187391bd include/scsi/fc_encode.h Joe Eykholt   2009-11-03  124  		ct->payload.rff.fr_type = FC_TYPE_FCP;
ab593b187391bd include/scsi/fc_encode.h Joe Eykholt   2009-11-03  125  		if (lport->service_params & FCP_SPPF_INIT_FCN)
ab593b187391bd include/scsi/fc_encode.h Joe Eykholt   2009-11-03  126  			ct->payload.rff.fr_feat = FCP_FEAT_INIT;
ab593b187391bd include/scsi/fc_encode.h Joe Eykholt   2009-11-03  127  		if (lport->service_params & FCP_SPPF_TARG_FCN)
ab593b187391bd include/scsi/fc_encode.h Joe Eykholt   2009-11-03  128  			ct->payload.rff.fr_feat |= FCP_FEAT_TARG;
ab593b187391bd include/scsi/fc_encode.h Joe Eykholt   2009-11-03  129  		break;
ab593b187391bd include/scsi/fc_encode.h Joe Eykholt   2009-11-03  130  
c9c7bd7a5e7321 include/scsi/fc_encode.h Chris Leech   2009-11-03  131  	case FC_NS_RNN_ID:
1ea2c1daf4476a include/scsi/fc_encode.h Neerav Parikh 2012-01-22  132  		ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_rn_id),
1ea2c1daf4476a include/scsi/fc_encode.h Neerav Parikh 2012-01-22  133  				    FC_FST_DIR, FC_NS_SUBTYPE);
7b2787ec15b9d1 include/scsi/fc_encode.h Robert Love   2010-05-07  134  		hton24(ct->payload.rn.fr_fid.fp_fid, lport->port_id);
c9c7bd7a5e7321 include/scsi/fc_encode.h Chris Leech   2009-11-03  135  		put_unaligned_be64(lport->wwnn, &ct->payload.rn.fr_wwn);
42e9a92fe6a909 include/scsi/fc_encode.h Robert Love   2008-12-09  136  		break;
42e9a92fe6a909 include/scsi/fc_encode.h Robert Love   2008-12-09  137  
c9866a548024c3 include/scsi/fc_encode.h Chris Leech   2009-11-03  138  	case FC_NS_RSPN_ID:
5f9a056db9c797 include/scsi/fc_encode.h Joe Eykholt   2009-11-03  139  		len = strnlen(fc_host_symbolic_name(lport->host), 255);
1ea2c1daf4476a include/scsi/fc_encode.h Neerav Parikh 2012-01-22  140  		ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_rspn) + len,
1ea2c1daf4476a include/scsi/fc_encode.h Neerav Parikh 2012-01-22  141  				    FC_FST_DIR, FC_NS_SUBTYPE);
7b2787ec15b9d1 include/scsi/fc_encode.h Robert Love   2010-05-07  142  		hton24(ct->payload.spn.fr_fid.fp_fid, lport->port_id);
c9866a548024c3 include/scsi/fc_encode.h Chris Leech   2009-11-03  143  		strncpy(ct->payload.spn.fr_name,
5f9a056db9c797 include/scsi/fc_encode.h Joe Eykholt   2009-11-03  144  			fc_host_symbolic_name(lport->host), len);
5f9a056db9c797 include/scsi/fc_encode.h Joe Eykholt   2009-11-03  145  		ct->payload.spn.fr_name_len = len;
c9866a548024c3 include/scsi/fc_encode.h Chris Leech   2009-11-03  146  		break;
c9866a548024c3 include/scsi/fc_encode.h Chris Leech   2009-11-03  147  
5baa17c3e66fc2 include/scsi/fc_encode.h Chris Leech   2009-11-03  148  	case FC_NS_RSNN_NN:
5f9a056db9c797 include/scsi/fc_encode.h Joe Eykholt   2009-11-03  149  		len = strnlen(fc_host_symbolic_name(lport->host), 255);
1ea2c1daf4476a include/scsi/fc_encode.h Neerav Parikh 2012-01-22  150  		ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_rsnn) + len,
1ea2c1daf4476a include/scsi/fc_encode.h Neerav Parikh 2012-01-22  151  				    FC_FST_DIR, FC_NS_SUBTYPE);
5baa17c3e66fc2 include/scsi/fc_encode.h Chris Leech   2009-11-03  152  		put_unaligned_be64(lport->wwnn, &ct->payload.snn.fr_wwn);
5baa17c3e66fc2 include/scsi/fc_encode.h Chris Leech   2009-11-03 @153  		strncpy(ct->payload.snn.fr_name,
5f9a056db9c797 include/scsi/fc_encode.h Joe Eykholt   2009-11-03  154  			fc_host_symbolic_name(lport->host), len);
5f9a056db9c797 include/scsi/fc_encode.h Joe Eykholt   2009-11-03  155  		ct->payload.snn.fr_name_len = len;
5baa17c3e66fc2 include/scsi/fc_encode.h Chris Leech   2009-11-03  156  		break;
5baa17c3e66fc2 include/scsi/fc_encode.h Chris Leech   2009-11-03  157  
42e9a92fe6a909 include/scsi/fc_encode.h Robert Love   2008-12-09  158  	default:
42e9a92fe6a909 include/scsi/fc_encode.h Robert Love   2008-12-09  159  		return -EINVAL;
42e9a92fe6a909 include/scsi/fc_encode.h Robert Love   2008-12-09  160  	}
42e9a92fe6a909 include/scsi/fc_encode.h Robert Love   2008-12-09  161  	*r_ctl = FC_RCTL_DD_UNSOL_CTL;
42e9a92fe6a909 include/scsi/fc_encode.h Robert Love   2008-12-09  162  	*fh_type = FC_TYPE_CT;
42e9a92fe6a909 include/scsi/fc_encode.h Robert Love   2008-12-09  163  	return 0;
42e9a92fe6a909 include/scsi/fc_encode.h Robert Love   2008-12-09  164  }
42e9a92fe6a909 include/scsi/fc_encode.h Robert Love   2008-12-09  165  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Martin K. Petersen Oct. 30, 2020, 1:52 a.m. UTC | #2
Arnd,

> Most of this file is only used inside of libfc, so move it to where it
> is actually used, with only fc_fill_fc_hdr() left inside of the
> header.

Applied to 5.11/scsi-staging, thanks!
Martin K. Petersen Nov. 5, 2020, 4:21 a.m. UTC | #3
On Mon, 26 Oct 2020 17:06:12 +0100, Arnd Bergmann wrote:

> Most of this file is only used inside of libfc, so move
> it to where it is actually used, with only fc_fill_fc_hdr()
> left inside of the header.

Applied to 5.11/scsi-queue, thanks!

[1/2] scsi: libfc: Move scsi/fc_encode.h to libfc
      https://git.kernel.org/mkp/scsi/c/e31ac898ac29
[2/2] scsi: libfc: Work around -Warray-bounds warning
      https://git.kernel.org/mkp/scsi/c/8fd9efca86d0
diff mbox series

Patch

diff --git a/drivers/scsi/bnx2fc/bnx2fc.h b/drivers/scsi/bnx2fc/bnx2fc.h
index b6e8ed757252..b4cea8b06ea1 100644
--- a/drivers/scsi/bnx2fc/bnx2fc.h
+++ b/drivers/scsi/bnx2fc/bnx2fc.h
@@ -51,7 +51,6 @@ 
 #include <scsi/scsi_tcq.h>
 #include <scsi/libfc.h>
 #include <scsi/libfcoe.h>
-#include <scsi/fc_encode.h>
 #include <scsi/scsi_transport.h>
 #include <scsi/scsi_transport_fc.h>
 #include <scsi/fc/fc_fip.h>
diff --git a/drivers/scsi/libfc/fc_elsct.c b/drivers/scsi/libfc/fc_elsct.c
index 13a2e7c33cb1..8d3006edbe12 100644
--- a/drivers/scsi/libfc/fc_elsct.c
+++ b/drivers/scsi/libfc/fc_elsct.c
@@ -15,7 +15,7 @@ 
 #include <scsi/fc/fc_ns.h>
 #include <scsi/fc/fc_els.h>
 #include <scsi/libfc.h>
-#include <scsi/fc_encode.h>
+#include "fc_encode.h"
 #include "fc_libfc.h"
 
 /**
diff --git a/include/scsi/fc_encode.h b/drivers/scsi/libfc/fc_encode.h
similarity index 96%
rename from include/scsi/fc_encode.h
rename to drivers/scsi/libfc/fc_encode.h
index c6660205d73f..18203cae04b2 100644
--- a/include/scsi/fc_encode.h
+++ b/drivers/scsi/libfc/fc_encode.h
@@ -9,6 +9,7 @@ 
 #define _FC_ENCODE_H_
 #include <asm/unaligned.h>
 #include <linux/utsname.h>
+#include <scsi/fc/fc_ms.h>
 
 /*
  * F_CTL values for simple requests and responses.
@@ -39,35 +40,6 @@  struct fc_ct_req {
 	} payload;
 };
 
-static inline void __fc_fill_fc_hdr(struct fc_frame_header *fh,
-				    enum fc_rctl r_ctl,
-				    u32 did, u32 sid, enum fc_fh_type type,
-				    u32 f_ctl, u32 parm_offset)
-{
-	WARN_ON(r_ctl == 0);
-	fh->fh_r_ctl = r_ctl;
-	hton24(fh->fh_d_id, did);
-	hton24(fh->fh_s_id, sid);
-	fh->fh_type = type;
-	hton24(fh->fh_f_ctl, f_ctl);
-	fh->fh_cs_ctl = 0;
-	fh->fh_df_ctl = 0;
-	fh->fh_parm_offset = htonl(parm_offset);
-}
-
-/**
- * fill FC header fields in specified fc_frame
- */
-static inline void fc_fill_fc_hdr(struct fc_frame *fp, enum fc_rctl r_ctl,
-				  u32 did, u32 sid, enum fc_fh_type type,
-				  u32 f_ctl, u32 parm_offset)
-{
-	struct fc_frame_header *fh;
-
-	fh = fc_frame_header_get(fp);
-	__fc_fill_fc_hdr(fh, r_ctl, did, sid, type, f_ctl, parm_offset);
-}
-
 /**
  * fc_adisc_fill() - Fill in adisc request frame
  * @lport: local port.
diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
index 851335f09221..d71afae6191c 100644
--- a/drivers/scsi/libfc/fc_exch.c
+++ b/drivers/scsi/libfc/fc_exch.c
@@ -20,7 +20,6 @@ 
 #include <scsi/fc/fc_fc2.h>
 
 #include <scsi/libfc.h>
-#include <scsi/fc_encode.h>
 
 #include "fc_libfc.h"
 
diff --git a/drivers/scsi/libfc/fc_fcp.c b/drivers/scsi/libfc/fc_fcp.c
index 7cfeb6886237..b43b5f62ee3e 100644
--- a/drivers/scsi/libfc/fc_fcp.c
+++ b/drivers/scsi/libfc/fc_fcp.c
@@ -26,8 +26,8 @@ 
 #include <scsi/fc/fc_fc2.h>
 
 #include <scsi/libfc.h>
-#include <scsi/fc_encode.h>
 
+#include "fc_encode.h"
 #include "fc_libfc.h"
 
 static struct kmem_cache *scsi_pkt_cachep;
diff --git a/drivers/scsi/libfc/fc_libfc.c b/drivers/scsi/libfc/fc_libfc.c
index 19c4ab4e0f4d..0e6a1355d020 100644
--- a/drivers/scsi/libfc/fc_libfc.c
+++ b/drivers/scsi/libfc/fc_libfc.c
@@ -12,8 +12,8 @@ 
 #include <linux/module.h>
 
 #include <scsi/libfc.h>
-#include <scsi/fc_encode.h>
 
+#include "fc_encode.h"
 #include "fc_libfc.h"
 
 MODULE_AUTHOR("Open-FCoE.org");
diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c
index 6557fda85c5c..22826544da7e 100644
--- a/drivers/scsi/libfc/fc_lport.c
+++ b/drivers/scsi/libfc/fc_lport.c
@@ -84,9 +84,9 @@ 
 #include <scsi/fc/fc_gs.h>
 
 #include <scsi/libfc.h>
-#include <scsi/fc_encode.h>
 #include <linux/scatterlist.h>
 
+#include "fc_encode.h"
 #include "fc_libfc.h"
 
 /* Fabric IDs to use for point-to-point mode, chosen on whims. */
diff --git a/drivers/scsi/libfc/fc_rport.c b/drivers/scsi/libfc/fc_rport.c
index a60b228d13f1..56003208d2e7 100644
--- a/drivers/scsi/libfc/fc_rport.c
+++ b/drivers/scsi/libfc/fc_rport.c
@@ -58,8 +58,8 @@ 
 #include <asm/unaligned.h>
 
 #include <scsi/libfc.h>
-#include <scsi/fc_encode.h>
 
+#include "fc_encode.h"
 #include "fc_libfc.h"
 
 static struct workqueue_struct *rport_event_queue;
diff --git a/drivers/scsi/qedf/qedf.h b/drivers/scsi/qedf/qedf.h
index 0e2cbb164eeb..88a592d09433 100644
--- a/drivers/scsi/qedf/qedf.h
+++ b/drivers/scsi/qedf/qedf.h
@@ -11,7 +11,6 @@ 
 #include <scsi/fc/fc_fip.h>
 #include <scsi/fc/fc_fc2.h>
 #include <scsi/scsi_tcq.h>
-#include <scsi/fc_encode.h>
 #include <linux/version.h>
 
 
diff --git a/drivers/target/tcm_fc/tfc_cmd.c b/drivers/target/tcm_fc/tfc_cmd.c
index a7ed56602c6c..9c8c38a549c6 100644
--- a/drivers/target/tcm_fc/tfc_cmd.c
+++ b/drivers/target/tcm_fc/tfc_cmd.c
@@ -19,7 +19,6 @@ 
 #include <asm/unaligned.h>
 #include <scsi/scsi_tcq.h>
 #include <scsi/libfc.h>
-#include <scsi/fc_encode.h>
 
 #include <target/target_core_base.h>
 #include <target/target_core_fabric.h>
diff --git a/drivers/target/tcm_fc/tfc_io.c b/drivers/target/tcm_fc/tfc_io.c
index 6a38ff936389..bbe2e29612fa 100644
--- a/drivers/target/tcm_fc/tfc_io.c
+++ b/drivers/target/tcm_fc/tfc_io.c
@@ -28,7 +28,6 @@ 
 #include <linux/ratelimit.h>
 #include <asm/unaligned.h>
 #include <scsi/libfc.h>
-#include <scsi/fc_encode.h>
 
 #include <target/target_core_base.h>
 #include <target/target_core_fabric.h>
diff --git a/include/scsi/fc_frame.h b/include/scsi/fc_frame.h
index 41df2ba9dbaa..d544dc5057fc 100644
--- a/include/scsi/fc_frame.h
+++ b/include/scsi/fc_frame.h
@@ -246,4 +246,34 @@  static inline bool fc_frame_is_cmd(const struct fc_frame *fp)
  */
 void fc_frame_leak_check(void);
 
+static inline void __fc_fill_fc_hdr(struct fc_frame_header *fh,
+				    enum fc_rctl r_ctl,
+				    u32 did, u32 sid, enum fc_fh_type type,
+				    u32 f_ctl, u32 parm_offset)
+{
+	WARN_ON(r_ctl == 0);
+	fh->fh_r_ctl = r_ctl;
+	hton24(fh->fh_d_id, did);
+	hton24(fh->fh_s_id, sid);
+	fh->fh_type = type;
+	hton24(fh->fh_f_ctl, f_ctl);
+	fh->fh_cs_ctl = 0;
+	fh->fh_df_ctl = 0;
+	fh->fh_parm_offset = htonl(parm_offset);
+}
+
+/**
+ * fill FC header fields in specified fc_frame
+ */
+static inline void fc_fill_fc_hdr(struct fc_frame *fp, enum fc_rctl r_ctl,
+				  u32 did, u32 sid, enum fc_fh_type type,
+				  u32 f_ctl, u32 parm_offset)
+{
+	struct fc_frame_header *fh;
+
+	fh = fc_frame_header_get(fp);
+	__fc_fill_fc_hdr(fh, r_ctl, did, sid, type, f_ctl, parm_offset);
+}
+
+
 #endif /* _FC_FRAME_H_ */