summaryrefslogtreecommitdiff
path: root/drivers/scsi/fnic/fnic_res.h
blob: 88c4471c18f04087b15c0200c9994ff28ca128c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/*
 * Copyright 2008 Cisco Systems, Inc.  All rights reserved.
 * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
 *
 * This program is free software; you may redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
#ifndef _FNIC_RES_H_
#define _FNIC_RES_H_

#include "wq_enet_desc.h"
#include "rq_enet_desc.h"
#include "vnic_wq.h"
#include "vnic_rq.h"
#include "fnic_io.h"
#include "fcpio.h"
#include "vnic_wq_copy.h"
#include "vnic_cq_copy.h"

static inline void fnic_queue_wq_desc(struct vnic_wq *wq,
				      void *os_buf, dma_addr_t dma_addr,
				      unsigned int len, unsigned int fc_eof,
				      int vlan_tag_insert,
				      unsigned int vlan_tag,
				      int cq_entry, int sop, int eop)
{
	struct wq_enet_desc *desc = vnic_wq_next_desc(wq);

	wq_enet_desc_enc(desc,
			 (u64)dma_addr | VNIC_PADDR_TARGET,
			 (u16)len,
			 0, /* mss_or_csum_offset */
			 (u16)fc_eof,
			 0, /* offload_mode */
			 (u8)eop, (u8)cq_entry,
			 1, /* fcoe_encap */
			 (u8)vlan_tag_insert,
			 (u16)vlan_tag,
			 0 /* loopback */);

	vnic_wq_post(wq, os_buf, dma_addr, len, sop, eop);
}

static inline void fnic_queue_wq_copy_desc_icmnd_16(struct vnic_wq_copy *wq,
						    u32 req_id,
						    u32 lunmap_id, u8 spl_flags,
						    u32 sgl_cnt, u32 sense_len,
						    u64 sgl_addr, u64 sns_addr,
						    u8 crn, u8 pri_ta,
						    u8 flags, u8 *scsi_cdb,
						    u8 cdb_len,
						    u32 data_len, u8 *lun,
						    u32 d_id, u16 mss,
						    u32 ratov, u32 edtov)
{
	struct fcpio_host_req *desc = vnic_wq_copy_next_desc(wq);

	desc->hdr.type = FCPIO_ICMND_16; /* enum fcpio_type */
	desc->hdr.status = 0;            /* header status entry */
	desc->hdr._resvd = 0;            /* reserved */
	desc->hdr.tag.u.req_id = req_id; /* id for this request */

	desc->u.icmnd_16.lunmap_id = lunmap_id; /* index into lunmap table */
	desc->u.icmnd_16.special_req_flags = spl_flags; /* exch req flags */
	desc->u.icmnd_16._resvd0[0] = 0;        /* reserved */
	desc->u.icmnd_16._resvd0[1] = 0;        /* reserved */
	desc->u.icmnd_16._resvd0[2] = 0;        /* reserved */
	desc->u.icmnd_16.sgl_cnt = sgl_cnt;     /* scatter-gather list count */
	desc->u.icmnd_16.sense_len = sense_len; /* sense buffer length */
	desc->u.icmnd_16.sgl_addr = sgl_addr;   /* scatter-gather list addr */
	desc->u.icmnd_16.sense_addr = sns_addr; /* sense buffer address */
	desc->u.icmnd_16.crn = crn;             /* SCSI Command Reference No.*/
	desc->u.icmnd_16.pri_ta = pri_ta; 	/* SCSI Pri & Task attribute */
	desc->u.icmnd_16._resvd1 = 0;           /* reserved: should be 0 */
	desc->u.icmnd_16.flags = flags;         /* command flags */
	memset(desc->u.icmnd_16.scsi_cdb, 0, CDB_16);
	memcpy(desc->u.icmnd_16.scsi_cdb, scsi_cdb, cdb_len);    /* SCSI CDB */
	desc->u.icmnd_16.data_len = data_len;   /* length of data expected */
	memcpy(desc->u.icmnd_16.lun, lun, LUN_ADDRESS);  /* LUN address */
	desc->u.icmnd_16._resvd2 = 0;          	/* reserved */
	hton24(desc->u.icmnd_16.d_id, d_id);	/* FC vNIC only: Target D_ID */
	desc->u.icmnd_16.mss = mss;            	/* FC vNIC only: max burst */
	desc->u.icmnd_16.r_a_tov = ratov; /*FC vNIC only: Res. Alloc Timeout */
	desc->u.icmnd_16.e_d_tov = edtov; /*FC vNIC only: Err Detect Timeout */

	vnic_wq_copy_post(wq);
}

static inline void fnic_queue_wq_copy_desc_itmf(struct vnic_wq_copy *wq,
						u32 req_id, u32 lunmap_id,
						u32 tm_req, u32 tm_id, u8 *lun,
						u32 d_id, u32 r_a_tov,
						u32 e_d_tov)
{
	struct fcpio_host_req *desc = vnic_wq_copy_next_desc(wq);

	desc->hdr.type = FCPIO_ITMF;     /* enum fcpio_type */
	desc->hdr.status = 0;            /* header status entry */
	desc->hdr._resvd = 0;            /* reserved */
	desc->hdr.tag.u.req_id = req_id; /* id for this request */

	desc->u.itmf.lunmap_id = lunmap_id; /* index into lunmap table */
	desc->u.itmf.tm_req = tm_req;       /* SCSI Task Management request */
	desc->u.itmf.t_tag = tm_id;         /* tag of fcpio to be aborted */
	desc->u.itmf._resvd = 0;
	memcpy(desc->u.itmf.lun, lun, LUN_ADDRESS);  /* LUN address */
	desc->u.itmf._resvd1 = 0;
	hton24(desc->u.itmf.d_id, d_id);    /* FC vNIC only: Target D_ID */
	desc->u.itmf.r_a_tov = r_a_tov;     /* FC vNIC only: R_A_TOV in msec */
	desc->u.itmf.e_d_tov = e_d_tov;     /* FC vNIC only: E_D_TOV in msec */

	vnic_wq_copy_post(wq);
}

static inline void fnic_queue_wq_copy_desc_flogi_reg(struct vnic_wq_copy *wq,
						     u32 req_id, u8 format,
						     u32 s_id, u8 *gw_mac)
{
	struct fcpio_host_req *desc = vnic_wq_copy_next_desc(wq);

	desc->hdr.type = FCPIO_FLOGI_REG;     /* enum fcpio_type */
	desc->hdr.status = 0;                 /* header status entry */
	desc->hdr._resvd = 0;                 /* reserved */
	desc->hdr.tag.u.req_id = req_id;      /* id for this request */

	desc->u.flogi_reg.format = format;
	hton24(desc->u.flogi_reg.s_id, s_id);
	memcpy(desc->u.flogi_reg.gateway_mac, gw_mac, ETH_ALEN);

	vnic_wq_copy_post(wq);
}

static inline void fnic_queue_wq_copy_desc_fw_reset(struct vnic_wq_copy *wq,
						    u32 req_id)
{
	struct fcpio_host_req *desc = vnic_wq_copy_next_desc(wq);

	desc->hdr.type = FCPIO_RESET;     /* enum fcpio_type */
	desc->hdr.status = 0;             /* header status entry */
	desc->hdr._resvd = 0;             /* reserved */
	desc->hdr.tag.u.req_id = req_id;  /* id for this request */

	vnic_wq_copy_post(wq);
}

static inline void fnic_queue_wq_copy_desc_lunmap(struct vnic_wq_copy *wq,
						  u32 req_id, u64 lunmap_addr,
						  u32 lunmap_len)
{
	struct fcpio_host_req *desc = vnic_wq_copy_next_desc(wq);

	desc->hdr.type = FCPIO_LUNMAP_REQ;	/* enum fcpio_type */
	desc->hdr.status = 0;			/* header status entry */
	desc->hdr._resvd = 0;			/* reserved */
	desc->hdr.tag.u.req_id = req_id;	/* id for this request */

	desc->u.lunmap_req.addr = lunmap_addr;	/* address of the buffer */
	desc->u.lunmap_req.len = lunmap_len;	/* len of the buffer */

	vnic_wq_copy_post(wq);
}

static inline void fnic_queue_rq_desc(struct vnic_rq *rq,
				      void *os_buf, dma_addr_t dma_addr,
				      u16 len)
{
	struct rq_enet_desc *desc = vnic_rq_next_desc(rq);

	rq_enet_desc_enc(desc,
		(u64)dma_addr | VNIC_PADDR_TARGET,
		RQ_ENET_TYPE_ONLY_SOP,
		(u16)len);

	vnic_rq_post(rq, os_buf, 0, dma_addr, len);
}


struct fnic;

int fnic_get_vnic_config(struct fnic *);
int fnic_alloc_vnic_resources(struct fnic *);
void fnic_free_vnic_resources(struct fnic *);
void fnic_get_res_counts(struct fnic *);
int fnic_set_nic_config(struct fnic *fnic, u8 rss_default_cpu,
			u8 rss_hash_type, u8 rss_hash_bits, u8 rss_base_cpu,
			u8 rss_enable, u8 tso_ipid_split_en,
			u8 ig_vlan_strip_en);

#endif /* _FNIC_RES_H_ */