xref: /openbmc/linux/drivers/scsi/snic/snic_res.h (revision 0bf49ffb)
1 /*
2  * Copyright 2014 Cisco Systems, Inc.  All rights reserved.
3  *
4  * This program is free software; you may redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 2 of the License.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
9  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
10  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
11  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
12  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
13  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
14  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
15  * SOFTWARE.
16  */
17 
18 #ifndef __SNIC_RES_H
19 #define __SNIC_RES_H
20 
21 #include "snic_io.h"
22 #include "wq_enet_desc.h"
23 #include "vnic_wq.h"
24 #include "snic_fwint.h"
25 #include "vnic_cq_fw.h"
26 
27 static inline void
28 snic_icmnd_init(struct snic_host_req *req, u32 cmnd_id, u32 host_id, u64 ctx,
29 		u16 flags, u64 tgt_id, u8 *lun, u8 *scsi_cdb, u8 cdb_len,
30 		u32 data_len, u16 sg_cnt, ulong sgl_addr,
31 		dma_addr_t sns_addr_pa, u32 sense_len)
32 {
33 	snic_io_hdr_enc(&req->hdr, SNIC_REQ_ICMND, 0, cmnd_id, host_id, sg_cnt,
34 			ctx);
35 
36 	req->u.icmnd.flags = cpu_to_le16(flags);
37 	req->u.icmnd.tgt_id = cpu_to_le64(tgt_id);
38 	memcpy(&req->u.icmnd.lun_id, lun, LUN_ADDR_LEN);
39 	req->u.icmnd.cdb_len = cdb_len;
40 	memset(req->u.icmnd.cdb, 0, SNIC_CDB_LEN);
41 	memcpy(req->u.icmnd.cdb, scsi_cdb, cdb_len);
42 	req->u.icmnd.data_len = cpu_to_le32(data_len);
43 	req->u.icmnd.sg_addr = cpu_to_le64(sgl_addr);
44 	req->u.icmnd.sense_len = cpu_to_le32(sense_len);
45 	req->u.icmnd.sense_addr = cpu_to_le64(sns_addr_pa);
46 }
47 
48 static inline void
49 snic_itmf_init(struct snic_host_req *req, u32 cmnd_id, u32 host_id, ulong ctx,
50 	       u16 flags, u32 req_id, u64 tgt_id, u8 *lun, u8 tm_type)
51 {
52 	snic_io_hdr_enc(&req->hdr, SNIC_REQ_ITMF, 0, cmnd_id, host_id, 0, ctx);
53 
54 	req->u.itmf.tm_type = tm_type;
55 	req->u.itmf.flags = cpu_to_le16(flags);
56 	/* req_id valid only in abort, clear task */
57 	req->u.itmf.req_id = cpu_to_le32(req_id);
58 	req->u.itmf.tgt_id = cpu_to_le64(tgt_id);
59 	memcpy(&req->u.itmf.lun_id, lun, LUN_ADDR_LEN);
60 }
61 
62 static inline void
63 snic_queue_wq_eth_desc(struct vnic_wq *wq,
64 		       void *os_buf,
65 		       dma_addr_t dma_addr,
66 		       unsigned int len,
67 		       int vlan_tag_insert,
68 		       unsigned int vlan_tag,
69 		       int cq_entry)
70 {
71 	struct wq_enet_desc *desc = svnic_wq_next_desc(wq);
72 
73 	wq_enet_desc_enc(desc,
74 			(u64)dma_addr | VNIC_PADDR_TARGET,
75 			(u16)len,
76 			0, /* mss_or_csum_offset */
77 			0, /* fc_eof */
78 			0, /* offload mode */
79 			1, /* eop */
80 			(u8)cq_entry,
81 			0, /* fcoe_encap */
82 			(u8)vlan_tag_insert,
83 			(u16)vlan_tag,
84 			0 /* loopback */);
85 
86 	svnic_wq_post(wq, os_buf, dma_addr, len, 1, 1);
87 }
88 
89 struct snic;
90 
91 int snic_get_vnic_config(struct snic *);
92 int snic_alloc_vnic_res(struct snic *);
93 void snic_free_vnic_res(struct snic *);
94 void snic_get_res_counts(struct snic *);
95 void snic_log_q_error(struct snic *);
96 int snic_get_vnic_resources_size(struct snic *);
97 #endif /* __SNIC_RES_H */
98