fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
a2255df3e7bbadf7b06c76c8226a1f6f5bbc9e07Daniel Beauregard
a2255df3e7bbadf7b06c76c8226a1f6f5bbc9e07Daniel Beauregard/*
a2255df3e7bbadf7b06c76c8226a1f6f5bbc9e07Daniel Beauregard * Copyright 2009 QLogic Corporation. All rights reserved.
a2255df3e7bbadf7b06c76c8226a1f6f5bbc9e07Daniel Beauregard * Use is subject to license terms.
a2255df3e7bbadf7b06c76c8226a1f6f5bbc9e07Daniel Beauregard */
a2255df3e7bbadf7b06c76c8226a1f6f5bbc9e07Daniel Beauregard
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
a2255df3e7bbadf7b06c76c8226a1f6f5bbc9e07Daniel Beauregard
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifndef _QLT_DMA_H
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _QLT_DMA_H
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
4558d122136f151d62acbbc02ddb42df89a5ef66Viswanathan Kannappan#include <sys/stmf.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef __cplusplus
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern "C" {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore/*
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore * DMA memory object.
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore */
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore#define QLT_DMA_SG_LIST_LENGTH 1270
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore#define CMD7_2400_DATA_SEGMENTS 1
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore#define CONT_A64_DATA_SEGMENTS 5
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore/*
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore * Container for ddi_dma_handle
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore *
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore * These elements are either linked to an active dbuf or in the free list.
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore */
3fb517f786391b507780c78aabb8d98bfea9efe9James Moorestruct qlt_dma_handle {
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore struct qlt_dma_handle *next;
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore ddi_dma_handle_t dma_handle;
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore ddi_dma_cookie_t first_cookie;
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore uint_t num_cookies;
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore uint_t num_cookies_fetched;
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore};
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore
3fb517f786391b507780c78aabb8d98bfea9efe9James Mooretypedef struct qlt_dma_handle qlt_dma_handle_t;
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore/*
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore * The dbuf private data when using a scatter/gather list.
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore */
3fb517f786391b507780c78aabb8d98bfea9efe9James Moorestruct qlt_dma_sgl {
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore uint16_t handle_count;
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore uint16_t cookie_count;
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore uint16_t cookie_next_fetch;
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore uint16_t cookie_prefetched;
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore qlt_dma_handle_t *handle_list;
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore qlt_dma_handle_t *handle_next_fetch;
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore size_t qsize;
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore ddi_dma_cookie_t cookie[1];
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore};
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore
3fb517f786391b507780c78aabb8d98bfea9efe9James Mooretypedef struct qlt_dma_sgl qlt_dma_sgl_t;
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore/*
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore * Structure to maintain ddi_dma_handle free pool.
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore */
3fb517f786391b507780c78aabb8d98bfea9efe9James Moorestruct qlt_dma_handle_pool {
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore kmutex_t pool_lock; /* protects all fields */
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore qlt_dma_handle_t *free_list;
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore int num_free;
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore int num_total;
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore};
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore
3fb517f786391b507780c78aabb8d98bfea9efe9James Mooretypedef struct qlt_dma_handle_pool qlt_dma_handle_pool_t;
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestruct qlt_dmem_bucket;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct qlt_dmem_bctl {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct qlt_dmem_bucket *bctl_bucket;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct qlt_dmem_bctl *bctl_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t bctl_dev_addr;
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore uint8_t bctl_task_ndx; /* notused */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_data_buf_t *bctl_buf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} qlt_dmem_bctl_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct qlt_dmem_bucket {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t dmem_buf_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t dmem_nbufs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t dmem_nbufs_free;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *dmem_host_addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t dmem_dev_addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ddi_dma_handle_t dmem_dma_handle;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ddi_acc_handle_t dmem_acc_handle;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmutex_t dmem_lock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qlt_dmem_bctl_t *dmem_bctl_free_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void *dmem_bctls_mem;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} qlt_dmem_bucket_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefct_status_t qlt_dmem_init(qlt_state_t *qlt);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid qlt_dmem_fini(qlt_state_t *qlt);
3fb517f786391b507780c78aabb8d98bfea9efe9James Moorevoid qlt_dma_handle_pool_init(qlt_state_t *qlt);
3fb517f786391b507780c78aabb8d98bfea9efe9James Moorevoid qlt_dma_handle_pool_fini(qlt_state_t *qlt);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_data_buf_t *qlt_dmem_alloc(fct_local_port_t *port, uint32_t size,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t *pminsize, uint32_t flags);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_data_buf_t *qlt_i_dmem_alloc(qlt_state_t *qlt, uint32_t size,
a2255df3e7bbadf7b06c76c8226a1f6f5bbc9e07Daniel Beauregard uint32_t *pminsize, uint32_t flags);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid qlt_dmem_free(fct_dbuf_store_t *fds, stmf_data_buf_t *dbuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid qlt_i_dmem_free(qlt_state_t *qlt, stmf_data_buf_t *dbuf);
3fb517f786391b507780c78aabb8d98bfea9efe9James Moorestmf_status_t qlt_dma_setup_dbuf(fct_local_port_t *port,
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore stmf_data_buf_t *dbuf, uint32_t flags);
3fb517f786391b507780c78aabb8d98bfea9efe9James Moorevoid qlt_dma_teardown_dbuf(fct_dbuf_store_t *fds, stmf_data_buf_t *dbuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid qlt_dmem_dma_sync(stmf_data_buf_t *dbuf, uint_t sync_type);
3fb517f786391b507780c78aabb8d98bfea9efe9James Mooreuint8_t qlt_get_iocb_count(uint32_t cookie_cnt);
3fb517f786391b507780c78aabb8d98bfea9efe9James Mooreuint64_t qlt_ddi_vtop(caddr_t vaddr);
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore/*
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore * XXX move the following into the fct layer
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore */
3fb517f786391b507780c78aabb8d98bfea9efe9James Mooreuint16_t qlt_get_cookie_count(stmf_data_buf_t *dbuf);
3fb517f786391b507780c78aabb8d98bfea9efe9James Moorevoid qlt_ddi_dma_nextcookie(stmf_data_buf_t *dbuf, ddi_dma_cookie_t *cookie_p);
3fb517f786391b507780c78aabb8d98bfea9efe9James Mooreddi_dma_cookie_t *qlt_get_cookie_array(stmf_data_buf_t *dbuf);
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef __cplusplus
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _QLT_DMA_H */