Merge branch 'timers-for-linus-clocksource' of git://git.kernel.org/pub/scm/linux...
[linux-2.6] / drivers / scsi / fnic / fnic_res.h
1 /*
2  * Copyright 2008 Cisco Systems, Inc.  All rights reserved.
3  * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
4  *
5  * This program is free software; you may redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; version 2 of the License.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
10  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
11  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
12  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
13  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
14  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
15  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
16  * SOFTWARE.
17  */
18 #ifndef _FNIC_RES_H_
19 #define _FNIC_RES_H_
20
21 #include "wq_enet_desc.h"
22 #include "rq_enet_desc.h"
23 #include "vnic_wq.h"
24 #include "vnic_rq.h"
25 #include "fnic_io.h"
26 #include "fcpio.h"
27 #include "vnic_wq_copy.h"
28 #include "vnic_cq_copy.h"
29
30 static inline void fnic_queue_wq_desc(struct vnic_wq *wq,
31                                       void *os_buf, dma_addr_t dma_addr,
32                                       unsigned int len, unsigned int fc_eof,
33                                       int vlan_tag_insert,
34                                       unsigned int vlan_tag,
35                                       int cq_entry, int sop, int eop)
36 {
37         struct wq_enet_desc *desc = vnic_wq_next_desc(wq);
38
39         wq_enet_desc_enc(desc,
40                          (u64)dma_addr | VNIC_PADDR_TARGET,
41                          (u16)len,
42                          0, /* mss_or_csum_offset */
43                          (u16)fc_eof,
44                          0, /* offload_mode */
45                          (u8)eop, (u8)cq_entry,
46                          1, /* fcoe_encap */
47                          (u8)vlan_tag_insert,
48                          (u16)vlan_tag,
49                          0 /* loopback */);
50
51         vnic_wq_post(wq, os_buf, dma_addr, len, sop, eop);
52 }
53
54 static inline void fnic_queue_wq_copy_desc_icmnd_16(struct vnic_wq_copy *wq,
55                                                     u32 req_id,
56                                                     u32 lunmap_id, u8 spl_flags,
57                                                     u32 sgl_cnt, u32 sense_len,
58                                                     u64 sgl_addr, u64 sns_addr,
59                                                     u8 crn, u8 pri_ta,
60                                                     u8 flags, u8 *scsi_cdb,
61                                                     u32 data_len, u8 *lun,
62                                                     u32 d_id, u16 mss,
63                                                     u32 ratov, u32 edtov)
64 {
65         struct fcpio_host_req *desc = vnic_wq_copy_next_desc(wq);
66
67         desc->hdr.type = FCPIO_ICMND_16; /* enum fcpio_type */
68         desc->hdr.status = 0;            /* header status entry */
69         desc->hdr._resvd = 0;            /* reserved */
70         desc->hdr.tag.u.req_id = req_id; /* id for this request */
71
72         desc->u.icmnd_16.lunmap_id = lunmap_id; /* index into lunmap table */
73         desc->u.icmnd_16.special_req_flags = spl_flags; /* exch req flags */
74         desc->u.icmnd_16._resvd0[0] = 0;        /* reserved */
75         desc->u.icmnd_16._resvd0[1] = 0;        /* reserved */
76         desc->u.icmnd_16._resvd0[2] = 0;        /* reserved */
77         desc->u.icmnd_16.sgl_cnt = sgl_cnt;     /* scatter-gather list count */
78         desc->u.icmnd_16.sense_len = sense_len; /* sense buffer length */
79         desc->u.icmnd_16.sgl_addr = sgl_addr;   /* scatter-gather list addr */
80         desc->u.icmnd_16.sense_addr = sns_addr; /* sense buffer address */
81         desc->u.icmnd_16.crn = crn;             /* SCSI Command Reference No.*/
82         desc->u.icmnd_16.pri_ta = pri_ta;       /* SCSI Pri & Task attribute */
83         desc->u.icmnd_16._resvd1 = 0;           /* reserved: should be 0 */
84         desc->u.icmnd_16.flags = flags;         /* command flags */
85         memcpy(desc->u.icmnd_16.scsi_cdb, scsi_cdb, CDB_16);    /* SCSI CDB */
86         desc->u.icmnd_16.data_len = data_len;   /* length of data expected */
87         memcpy(desc->u.icmnd_16.lun, lun, LUN_ADDRESS);  /* LUN address */
88         desc->u.icmnd_16._resvd2 = 0;           /* reserved */
89         hton24(desc->u.icmnd_16.d_id, d_id);    /* FC vNIC only: Target D_ID */
90         desc->u.icmnd_16.mss = mss;             /* FC vNIC only: max burst */
91         desc->u.icmnd_16.r_a_tov = ratov; /*FC vNIC only: Res. Alloc Timeout */
92         desc->u.icmnd_16.e_d_tov = edtov; /*FC vNIC only: Err Detect Timeout */
93
94         vnic_wq_copy_post(wq);
95 }
96
97 static inline void fnic_queue_wq_copy_desc_itmf(struct vnic_wq_copy *wq,
98                                                 u32 req_id, u32 lunmap_id,
99                                                 u32 tm_req, u32 tm_id, u8 *lun,
100                                                 u32 d_id, u32 r_a_tov,
101                                                 u32 e_d_tov)
102 {
103         struct fcpio_host_req *desc = vnic_wq_copy_next_desc(wq);
104
105         desc->hdr.type = FCPIO_ITMF;     /* enum fcpio_type */
106         desc->hdr.status = 0;            /* header status entry */
107         desc->hdr._resvd = 0;            /* reserved */
108         desc->hdr.tag.u.req_id = req_id; /* id for this request */
109
110         desc->u.itmf.lunmap_id = lunmap_id; /* index into lunmap table */
111         desc->u.itmf.tm_req = tm_req;       /* SCSI Task Management request */
112         desc->u.itmf.t_tag = tm_id;         /* tag of fcpio to be aborted */
113         desc->u.itmf._resvd = 0;
114         memcpy(desc->u.itmf.lun, lun, LUN_ADDRESS);  /* LUN address */
115         desc->u.itmf._resvd1 = 0;
116         hton24(desc->u.itmf.d_id, d_id);    /* FC vNIC only: Target D_ID */
117         desc->u.itmf.r_a_tov = r_a_tov;     /* FC vNIC only: R_A_TOV in msec */
118         desc->u.itmf.e_d_tov = e_d_tov;     /* FC vNIC only: E_D_TOV in msec */
119
120         vnic_wq_copy_post(wq);
121 }
122
123 static inline void fnic_queue_wq_copy_desc_flogi_reg(struct vnic_wq_copy *wq,
124                                                      u32 req_id, u8 format,
125                                                      u32 s_id, u8 *gw_mac)
126 {
127         struct fcpio_host_req *desc = vnic_wq_copy_next_desc(wq);
128
129         desc->hdr.type = FCPIO_FLOGI_REG;     /* enum fcpio_type */
130         desc->hdr.status = 0;                 /* header status entry */
131         desc->hdr._resvd = 0;                 /* reserved */
132         desc->hdr.tag.u.req_id = req_id;      /* id for this request */
133
134         desc->u.flogi_reg.format = format;
135         hton24(desc->u.flogi_reg.s_id, s_id);
136         memcpy(desc->u.flogi_reg.gateway_mac, gw_mac, ETH_ALEN);
137
138         vnic_wq_copy_post(wq);
139 }
140
141 static inline void fnic_queue_wq_copy_desc_fw_reset(struct vnic_wq_copy *wq,
142                                                     u32 req_id)
143 {
144         struct fcpio_host_req *desc = vnic_wq_copy_next_desc(wq);
145
146         desc->hdr.type = FCPIO_RESET;     /* enum fcpio_type */
147         desc->hdr.status = 0;             /* header status entry */
148         desc->hdr._resvd = 0;             /* reserved */
149         desc->hdr.tag.u.req_id = req_id;  /* id for this request */
150
151         vnic_wq_copy_post(wq);
152 }
153
154 static inline void fnic_queue_wq_copy_desc_lunmap(struct vnic_wq_copy *wq,
155                                                   u32 req_id, u64 lunmap_addr,
156                                                   u32 lunmap_len)
157 {
158         struct fcpio_host_req *desc = vnic_wq_copy_next_desc(wq);
159
160         desc->hdr.type = FCPIO_LUNMAP_REQ;      /* enum fcpio_type */
161         desc->hdr.status = 0;                   /* header status entry */
162         desc->hdr._resvd = 0;                   /* reserved */
163         desc->hdr.tag.u.req_id = req_id;        /* id for this request */
164
165         desc->u.lunmap_req.addr = lunmap_addr;  /* address of the buffer */
166         desc->u.lunmap_req.len = lunmap_len;    /* len of the buffer */
167
168         vnic_wq_copy_post(wq);
169 }
170
171 static inline void fnic_queue_rq_desc(struct vnic_rq *rq,
172                                       void *os_buf, dma_addr_t dma_addr,
173                                       u16 len)
174 {
175         struct rq_enet_desc *desc = vnic_rq_next_desc(rq);
176
177         rq_enet_desc_enc(desc,
178                 (u64)dma_addr | VNIC_PADDR_TARGET,
179                 RQ_ENET_TYPE_ONLY_SOP,
180                 (u16)len);
181
182         vnic_rq_post(rq, os_buf, 0, dma_addr, len);
183 }
184
185
186 struct fnic;
187
188 int fnic_get_vnic_config(struct fnic *);
189 int fnic_alloc_vnic_resources(struct fnic *);
190 void fnic_free_vnic_resources(struct fnic *);
191 void fnic_get_res_counts(struct fnic *);
192 int fnic_set_nic_config(struct fnic *fnic, u8 rss_default_cpu,
193                         u8 rss_hash_type, u8 rss_hash_bits, u8 rss_base_cpu,
194                         u8 rss_enable, u8 tso_ipid_split_en,
195                         u8 ig_vlan_strip_en);
196
197 #endif /* _FNIC_RES_H_ */