xref: /linux/drivers/scsi/snic/snic_res.h (revision 249ebf3f65f8530beb2cbfb91bff1d83ba88d23c)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Copyright 2014 Cisco Systems, Inc.  All rights reserved. */
3 
4 #ifndef __SNIC_RES_H
5 #define __SNIC_RES_H
6 
7 #include "snic_io.h"
8 #include "wq_enet_desc.h"
9 #include "vnic_wq.h"
10 #include "snic_fwint.h"
11 #include "vnic_cq_fw.h"
12 
13 static inline void
14 snic_icmnd_init(struct snic_host_req *req, u32 cmnd_id, u32 host_id, u64 ctx,
15 		u16 flags, u64 tgt_id, u8 *lun, u8 *scsi_cdb, u8 cdb_len,
16 		u32 data_len, u16 sg_cnt, ulong sgl_addr,
17 		dma_addr_t sns_addr_pa, u32 sense_len)
18 {
19 	snic_io_hdr_enc(&req->hdr, SNIC_REQ_ICMND, 0, cmnd_id, host_id, sg_cnt,
20 			ctx);
21 
22 	req->u.icmnd.flags = cpu_to_le16(flags);
23 	req->u.icmnd.tgt_id = cpu_to_le64(tgt_id);
24 	memcpy(&req->u.icmnd.lun_id, lun, LUN_ADDR_LEN);
25 	req->u.icmnd.cdb_len = cdb_len;
26 	memset(req->u.icmnd.cdb, 0, SNIC_CDB_LEN);
27 	memcpy(req->u.icmnd.cdb, scsi_cdb, cdb_len);
28 	req->u.icmnd.data_len = cpu_to_le32(data_len);
29 	req->u.icmnd.sg_addr = cpu_to_le64(sgl_addr);
30 	req->u.icmnd.sense_len = cpu_to_le32(sense_len);
31 	req->u.icmnd.sense_addr = cpu_to_le64(sns_addr_pa);
32 }
33 
34 static inline void
35 snic_itmf_init(struct snic_host_req *req, u32 cmnd_id, u32 host_id, ulong ctx,
36 	       u16 flags, u32 req_id, u64 tgt_id, u8 *lun, u8 tm_type)
37 {
38 	snic_io_hdr_enc(&req->hdr, SNIC_REQ_ITMF, 0, cmnd_id, host_id, 0, ctx);
39 
40 	req->u.itmf.tm_type = tm_type;
41 	req->u.itmf.flags = cpu_to_le16(flags);
42 	/* req_id valid only in abort, clear task */
43 	req->u.itmf.req_id = cpu_to_le32(req_id);
44 	req->u.itmf.tgt_id = cpu_to_le64(tgt_id);
45 	memcpy(&req->u.itmf.lun_id, lun, LUN_ADDR_LEN);
46 }
47 
48 static inline void
49 snic_queue_wq_eth_desc(struct vnic_wq *wq,
50 		       void *os_buf,
51 		       dma_addr_t dma_addr,
52 		       unsigned int len,
53 		       int vlan_tag_insert,
54 		       unsigned int vlan_tag,
55 		       int cq_entry)
56 {
57 	struct wq_enet_desc *desc = svnic_wq_next_desc(wq);
58 
59 	wq_enet_desc_enc(desc,
60 			(u64)dma_addr | VNIC_PADDR_TARGET,
61 			(u16)len,
62 			0, /* mss_or_csum_offset */
63 			0, /* fc_eof */
64 			0, /* offload mode */
65 			1, /* eop */
66 			(u8)cq_entry,
67 			0, /* fcoe_encap */
68 			(u8)vlan_tag_insert,
69 			(u16)vlan_tag,
70 			0 /* loopback */);
71 
72 	svnic_wq_post(wq, os_buf, dma_addr, len, 1, 1);
73 }
74 
75 struct snic;
76 
77 int snic_get_vnic_config(struct snic *);
78 int snic_alloc_vnic_res(struct snic *);
79 void snic_free_vnic_res(struct snic *);
80 void snic_get_res_counts(struct snic *);
81 void snic_log_q_error(struct snic *);
82 int snic_get_vnic_resources_size(struct snic *);
83 #endif /* __SNIC_RES_H */
84