18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright 2014 Cisco Systems, Inc.  All rights reserved.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * This program is free software; you may redistribute it and/or modify
58c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License as published by
68c2ecf20Sopenharmony_ci * the Free Software Foundation; version 2 of the License.
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
98c2ecf20Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
108c2ecf20Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
118c2ecf20Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
128c2ecf20Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
138c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
148c2ecf20Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
158c2ecf20Sopenharmony_ci * SOFTWARE.
168c2ecf20Sopenharmony_ci */
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#ifndef __SNIC_RES_H
198c2ecf20Sopenharmony_ci#define __SNIC_RES_H
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#include "snic_io.h"
228c2ecf20Sopenharmony_ci#include "wq_enet_desc.h"
238c2ecf20Sopenharmony_ci#include "vnic_wq.h"
248c2ecf20Sopenharmony_ci#include "snic_fwint.h"
258c2ecf20Sopenharmony_ci#include "vnic_cq_fw.h"
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_cistatic inline void
288c2ecf20Sopenharmony_cisnic_icmnd_init(struct snic_host_req *req, u32 cmnd_id, u32 host_id, u64 ctx,
298c2ecf20Sopenharmony_ci		u16 flags, u64 tgt_id, u8 *lun, u8 *scsi_cdb, u8 cdb_len,
308c2ecf20Sopenharmony_ci		u32 data_len, u16 sg_cnt, ulong sgl_addr,
318c2ecf20Sopenharmony_ci		dma_addr_t sns_addr_pa, u32 sense_len)
328c2ecf20Sopenharmony_ci{
338c2ecf20Sopenharmony_ci	snic_io_hdr_enc(&req->hdr, SNIC_REQ_ICMND, 0, cmnd_id, host_id, sg_cnt,
348c2ecf20Sopenharmony_ci			ctx);
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci	req->u.icmnd.flags = cpu_to_le16(flags);
378c2ecf20Sopenharmony_ci	req->u.icmnd.tgt_id = cpu_to_le64(tgt_id);
388c2ecf20Sopenharmony_ci	memcpy(&req->u.icmnd.lun_id, lun, LUN_ADDR_LEN);
398c2ecf20Sopenharmony_ci	req->u.icmnd.cdb_len = cdb_len;
408c2ecf20Sopenharmony_ci	memset(req->u.icmnd.cdb, 0, SNIC_CDB_LEN);
418c2ecf20Sopenharmony_ci	memcpy(req->u.icmnd.cdb, scsi_cdb, cdb_len);
428c2ecf20Sopenharmony_ci	req->u.icmnd.data_len = cpu_to_le32(data_len);
438c2ecf20Sopenharmony_ci	req->u.icmnd.sg_addr = cpu_to_le64(sgl_addr);
448c2ecf20Sopenharmony_ci	req->u.icmnd.sense_len = cpu_to_le32(sense_len);
458c2ecf20Sopenharmony_ci	req->u.icmnd.sense_addr = cpu_to_le64(sns_addr_pa);
468c2ecf20Sopenharmony_ci}
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_cistatic inline void
498c2ecf20Sopenharmony_cisnic_itmf_init(struct snic_host_req *req, u32 cmnd_id, u32 host_id, ulong ctx,
508c2ecf20Sopenharmony_ci	       u16 flags, u32 req_id, u64 tgt_id, u8 *lun, u8 tm_type)
518c2ecf20Sopenharmony_ci{
528c2ecf20Sopenharmony_ci	snic_io_hdr_enc(&req->hdr, SNIC_REQ_ITMF, 0, cmnd_id, host_id, 0, ctx);
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci	req->u.itmf.tm_type = tm_type;
558c2ecf20Sopenharmony_ci	req->u.itmf.flags = cpu_to_le16(flags);
568c2ecf20Sopenharmony_ci	/* req_id valid only in abort, clear task */
578c2ecf20Sopenharmony_ci	req->u.itmf.req_id = cpu_to_le32(req_id);
588c2ecf20Sopenharmony_ci	req->u.itmf.tgt_id = cpu_to_le64(tgt_id);
598c2ecf20Sopenharmony_ci	memcpy(&req->u.itmf.lun_id, lun, LUN_ADDR_LEN);
608c2ecf20Sopenharmony_ci}
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_cistatic inline void
638c2ecf20Sopenharmony_cisnic_queue_wq_eth_desc(struct vnic_wq *wq,
648c2ecf20Sopenharmony_ci		       void *os_buf,
658c2ecf20Sopenharmony_ci		       dma_addr_t dma_addr,
668c2ecf20Sopenharmony_ci		       unsigned int len,
678c2ecf20Sopenharmony_ci		       int vlan_tag_insert,
688c2ecf20Sopenharmony_ci		       unsigned int vlan_tag,
698c2ecf20Sopenharmony_ci		       int cq_entry)
708c2ecf20Sopenharmony_ci{
718c2ecf20Sopenharmony_ci	struct wq_enet_desc *desc = svnic_wq_next_desc(wq);
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci	wq_enet_desc_enc(desc,
748c2ecf20Sopenharmony_ci			(u64)dma_addr | VNIC_PADDR_TARGET,
758c2ecf20Sopenharmony_ci			(u16)len,
768c2ecf20Sopenharmony_ci			0, /* mss_or_csum_offset */
778c2ecf20Sopenharmony_ci			0, /* fc_eof */
788c2ecf20Sopenharmony_ci			0, /* offload mode */
798c2ecf20Sopenharmony_ci			1, /* eop */
808c2ecf20Sopenharmony_ci			(u8)cq_entry,
818c2ecf20Sopenharmony_ci			0, /* fcoe_encap */
828c2ecf20Sopenharmony_ci			(u8)vlan_tag_insert,
838c2ecf20Sopenharmony_ci			(u16)vlan_tag,
848c2ecf20Sopenharmony_ci			0 /* loopback */);
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci	svnic_wq_post(wq, os_buf, dma_addr, len, 1, 1);
878c2ecf20Sopenharmony_ci}
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_cistruct snic;
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ciint snic_get_vnic_config(struct snic *);
928c2ecf20Sopenharmony_ciint snic_alloc_vnic_res(struct snic *);
938c2ecf20Sopenharmony_civoid snic_free_vnic_res(struct snic *);
948c2ecf20Sopenharmony_civoid snic_get_res_counts(struct snic *);
958c2ecf20Sopenharmony_civoid snic_log_q_error(struct snic *);
968c2ecf20Sopenharmony_ciint snic_get_vnic_resources_size(struct snic *);
978c2ecf20Sopenharmony_ci#endif /* __SNIC_RES_H */
98