xref: /openbmc/linux/drivers/scsi/fnic/fnic_res.h (revision be2b81b5)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright 2008 Cisco Systems, Inc.  All rights reserved.
4  * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
5  */
6 #ifndef _FNIC_RES_H_
7 #define _FNIC_RES_H_
8 
9 #include "wq_enet_desc.h"
10 #include "rq_enet_desc.h"
11 #include "vnic_wq.h"
12 #include "vnic_rq.h"
13 #include "fnic_io.h"
14 #include "fcpio.h"
15 #include "vnic_wq_copy.h"
16 #include "vnic_cq_copy.h"
17 
18 static inline void fnic_queue_wq_desc(struct vnic_wq *wq,
19 				      void *os_buf, dma_addr_t dma_addr,
20 				      unsigned int len, unsigned int fc_eof,
21 				      int vlan_tag_insert,
22 				      unsigned int vlan_tag,
23 				      int cq_entry, int sop, int eop)
24 {
25 	struct wq_enet_desc *desc = vnic_wq_next_desc(wq);
26 
27 	wq_enet_desc_enc(desc,
28 			 (u64)dma_addr | VNIC_PADDR_TARGET,
29 			 (u16)len,
30 			 0, /* mss_or_csum_offset */
31 			 (u16)fc_eof,
32 			 0, /* offload_mode */
33 			 (u8)eop, (u8)cq_entry,
34 			 1, /* fcoe_encap */
35 			 (u8)vlan_tag_insert,
36 			 (u16)vlan_tag,
37 			 0 /* loopback */);
38 
39 	vnic_wq_post(wq, os_buf, dma_addr, len, sop, eop);
40 }
41 
42 static inline void fnic_queue_wq_eth_desc(struct vnic_wq *wq,
43 				      void *os_buf, dma_addr_t dma_addr,
44 				      unsigned int len,
45 				      int vlan_tag_insert,
46 				      unsigned int vlan_tag,
47 				      int cq_entry)
48 {
49 	struct wq_enet_desc *desc = vnic_wq_next_desc(wq);
50 
51 	wq_enet_desc_enc(desc,
52 			 (u64)dma_addr | VNIC_PADDR_TARGET,
53 			 (u16)len,
54 			 0, /* mss_or_csum_offset */
55 			 0, /* fc_eof */
56 			 0, /* offload_mode */
57 			 1, /* eop */
58 			 (u8)cq_entry,
59 			 0, /* fcoe_encap */
60 			 (u8)vlan_tag_insert,
61 			 (u16)vlan_tag,
62 			 0 /* loopback */);
63 
64 	vnic_wq_post(wq, os_buf, dma_addr, len, 1, 1);
65 }
66 
67 static inline void fnic_queue_wq_copy_desc_icmnd_16(struct vnic_wq_copy *wq,
68 						    u32 req_id,
69 						    u32 lunmap_id, u8 spl_flags,
70 						    u32 sgl_cnt, u32 sense_len,
71 						    u64 sgl_addr, u64 sns_addr,
72 						    u8 crn, u8 pri_ta,
73 						    u8 flags, u8 *scsi_cdb,
74 						    u8 cdb_len,
75 						    u32 data_len, u8 *lun,
76 						    u32 d_id, u16 mss,
77 						    u32 ratov, u32 edtov)
78 {
79 	struct fcpio_host_req *desc = vnic_wq_copy_next_desc(wq);
80 
81 	desc->hdr.type = FCPIO_ICMND_16; /* enum fcpio_type */
82 	desc->hdr.status = 0;            /* header status entry */
83 	desc->hdr._resvd = 0;            /* reserved */
84 	desc->hdr.tag.u.req_id = req_id; /* id for this request */
85 
86 	desc->u.icmnd_16.lunmap_id = lunmap_id; /* index into lunmap table */
87 	desc->u.icmnd_16.special_req_flags = spl_flags; /* exch req flags */
88 	desc->u.icmnd_16._resvd0[0] = 0;        /* reserved */
89 	desc->u.icmnd_16._resvd0[1] = 0;        /* reserved */
90 	desc->u.icmnd_16._resvd0[2] = 0;        /* reserved */
91 	desc->u.icmnd_16.sgl_cnt = sgl_cnt;     /* scatter-gather list count */
92 	desc->u.icmnd_16.sense_len = sense_len; /* sense buffer length */
93 	desc->u.icmnd_16.sgl_addr = sgl_addr;   /* scatter-gather list addr */
94 	desc->u.icmnd_16.sense_addr = sns_addr; /* sense buffer address */
95 	desc->u.icmnd_16.crn = crn;             /* SCSI Command Reference No.*/
96 	desc->u.icmnd_16.pri_ta = pri_ta; 	/* SCSI Pri & Task attribute */
97 	desc->u.icmnd_16._resvd1 = 0;           /* reserved: should be 0 */
98 	desc->u.icmnd_16.flags = flags;         /* command flags */
99 	memset(desc->u.icmnd_16.scsi_cdb, 0, CDB_16);
100 	memcpy(desc->u.icmnd_16.scsi_cdb, scsi_cdb, cdb_len);    /* SCSI CDB */
101 	desc->u.icmnd_16.data_len = data_len;   /* length of data expected */
102 	memcpy(desc->u.icmnd_16.lun, lun, LUN_ADDRESS);  /* LUN address */
103 	desc->u.icmnd_16._resvd2 = 0;          	/* reserved */
104 	hton24(desc->u.icmnd_16.d_id, d_id);	/* FC vNIC only: Target D_ID */
105 	desc->u.icmnd_16.mss = mss;            	/* FC vNIC only: max burst */
106 	desc->u.icmnd_16.r_a_tov = ratov; /*FC vNIC only: Res. Alloc Timeout */
107 	desc->u.icmnd_16.e_d_tov = edtov; /*FC vNIC only: Err Detect Timeout */
108 
109 	vnic_wq_copy_post(wq);
110 }
111 
112 static inline void fnic_queue_wq_copy_desc_itmf(struct vnic_wq_copy *wq,
113 						u32 req_id, u32 lunmap_id,
114 						u32 tm_req, u32 tm_id, u8 *lun,
115 						u32 d_id, u32 r_a_tov,
116 						u32 e_d_tov)
117 {
118 	struct fcpio_host_req *desc = vnic_wq_copy_next_desc(wq);
119 
120 	desc->hdr.type = FCPIO_ITMF;     /* enum fcpio_type */
121 	desc->hdr.status = 0;            /* header status entry */
122 	desc->hdr._resvd = 0;            /* reserved */
123 	desc->hdr.tag.u.req_id = req_id; /* id for this request */
124 
125 	desc->u.itmf.lunmap_id = lunmap_id; /* index into lunmap table */
126 	desc->u.itmf.tm_req = tm_req;       /* SCSI Task Management request */
127 	desc->u.itmf.t_tag = tm_id;         /* tag of fcpio to be aborted */
128 	desc->u.itmf._resvd = 0;
129 	memcpy(desc->u.itmf.lun, lun, LUN_ADDRESS);  /* LUN address */
130 	desc->u.itmf._resvd1 = 0;
131 	hton24(desc->u.itmf.d_id, d_id);    /* FC vNIC only: Target D_ID */
132 	desc->u.itmf.r_a_tov = r_a_tov;     /* FC vNIC only: R_A_TOV in msec */
133 	desc->u.itmf.e_d_tov = e_d_tov;     /* FC vNIC only: E_D_TOV in msec */
134 
135 	vnic_wq_copy_post(wq);
136 }
137 
138 static inline void fnic_queue_wq_copy_desc_flogi_reg(struct vnic_wq_copy *wq,
139 						     u32 req_id, u8 format,
140 						     u32 s_id, u8 *gw_mac)
141 {
142 	struct fcpio_host_req *desc = vnic_wq_copy_next_desc(wq);
143 
144 	desc->hdr.type = FCPIO_FLOGI_REG;     /* enum fcpio_type */
145 	desc->hdr.status = 0;                 /* header status entry */
146 	desc->hdr._resvd = 0;                 /* reserved */
147 	desc->hdr.tag.u.req_id = req_id;      /* id for this request */
148 
149 	desc->u.flogi_reg.format = format;
150 	desc->u.flogi_reg._resvd = 0;
151 	hton24(desc->u.flogi_reg.s_id, s_id);
152 	memcpy(desc->u.flogi_reg.gateway_mac, gw_mac, ETH_ALEN);
153 
154 	vnic_wq_copy_post(wq);
155 }
156 
157 static inline void fnic_queue_wq_copy_desc_fip_reg(struct vnic_wq_copy *wq,
158 						   u32 req_id, u32 s_id,
159 						   u8 *fcf_mac, u8 *ha_mac,
160 						   u32 r_a_tov, u32 e_d_tov)
161 {
162 	struct fcpio_host_req *desc = vnic_wq_copy_next_desc(wq);
163 
164 	desc->hdr.type = FCPIO_FLOGI_FIP_REG; /* enum fcpio_type */
165 	desc->hdr.status = 0;                 /* header status entry */
166 	desc->hdr._resvd = 0;                 /* reserved */
167 	desc->hdr.tag.u.req_id = req_id;      /* id for this request */
168 
169 	desc->u.flogi_fip_reg._resvd0 = 0;
170 	hton24(desc->u.flogi_fip_reg.s_id, s_id);
171 	memcpy(desc->u.flogi_fip_reg.fcf_mac, fcf_mac, ETH_ALEN);
172 	desc->u.flogi_fip_reg._resvd1 = 0;
173 	desc->u.flogi_fip_reg.r_a_tov = r_a_tov;
174 	desc->u.flogi_fip_reg.e_d_tov = e_d_tov;
175 	memcpy(desc->u.flogi_fip_reg.ha_mac, ha_mac, ETH_ALEN);
176 	desc->u.flogi_fip_reg._resvd2 = 0;
177 
178 	vnic_wq_copy_post(wq);
179 }
180 
181 static inline void fnic_queue_wq_copy_desc_fw_reset(struct vnic_wq_copy *wq,
182 						    u32 req_id)
183 {
184 	struct fcpio_host_req *desc = vnic_wq_copy_next_desc(wq);
185 
186 	desc->hdr.type = FCPIO_RESET;     /* enum fcpio_type */
187 	desc->hdr.status = 0;             /* header status entry */
188 	desc->hdr._resvd = 0;             /* reserved */
189 	desc->hdr.tag.u.req_id = req_id;  /* id for this request */
190 
191 	vnic_wq_copy_post(wq);
192 }
193 
194 static inline void fnic_queue_wq_copy_desc_lunmap(struct vnic_wq_copy *wq,
195 						  u32 req_id, u64 lunmap_addr,
196 						  u32 lunmap_len)
197 {
198 	struct fcpio_host_req *desc = vnic_wq_copy_next_desc(wq);
199 
200 	desc->hdr.type = FCPIO_LUNMAP_REQ;	/* enum fcpio_type */
201 	desc->hdr.status = 0;			/* header status entry */
202 	desc->hdr._resvd = 0;			/* reserved */
203 	desc->hdr.tag.u.req_id = req_id;	/* id for this request */
204 
205 	desc->u.lunmap_req.addr = lunmap_addr;	/* address of the buffer */
206 	desc->u.lunmap_req.len = lunmap_len;	/* len of the buffer */
207 
208 	vnic_wq_copy_post(wq);
209 }
210 
211 static inline void fnic_queue_rq_desc(struct vnic_rq *rq,
212 				      void *os_buf, dma_addr_t dma_addr,
213 				      u16 len)
214 {
215 	struct rq_enet_desc *desc = vnic_rq_next_desc(rq);
216 
217 	rq_enet_desc_enc(desc,
218 		(u64)dma_addr | VNIC_PADDR_TARGET,
219 		RQ_ENET_TYPE_ONLY_SOP,
220 		(u16)len);
221 
222 	vnic_rq_post(rq, os_buf, 0, dma_addr, len);
223 }
224 
225 
226 struct fnic;
227 
228 int fnic_get_vnic_config(struct fnic *);
229 int fnic_alloc_vnic_resources(struct fnic *);
230 void fnic_free_vnic_resources(struct fnic *);
231 void fnic_get_res_counts(struct fnic *);
232 int fnic_set_nic_config(struct fnic *fnic, u8 rss_default_cpu,
233 			u8 rss_hash_type, u8 rss_hash_bits, u8 rss_base_cpu,
234 			u8 rss_enable, u8 tso_ipid_split_en,
235 			u8 ig_vlan_strip_en);
236 
237 #endif /* _FNIC_RES_H_ */
238