blob: 0f63827acfb4924fece149986c7ad023ddce7b91 [file] [log] [blame]
Jarod Wilson7963eb42010-01-04 18:02:27 -05001/***************************************************************************
2 * Copyright (c) 2005-2009, Broadcom Corporation.
3 *
4 * Name: crystalhd_misc . h
5 *
6 * Description:
7 * BCM70012 Linux driver general purpose routines.
8 * Includes reg/mem read and write routines.
9 *
10 * HISTORY:
11 *
12 **********************************************************************
13 * This file is part of the crystalhd device driver.
14 *
15 * This driver is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation, version 2 of the License.
18 *
19 * This driver is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this driver. If not, see <http://www.gnu.org/licenses/>.
26 **********************************************************************/
27
28#ifndef _CRYSTALHD_MISC_H_
29#define _CRYSTALHD_MISC_H_
30
Jorgyano Vieira01c32072012-02-25 21:58:21 -020031#include "crystalhd.h"
32
Jarod Wilson7963eb42010-01-04 18:02:27 -050033#include <linux/module.h>
34#include <linux/kernel.h>
35#include <linux/errno.h>
36#include <linux/string.h>
37#include <linux/ioctl.h>
38#include <linux/dma-mapping.h>
Jarod Wilson7963eb42010-01-04 18:02:27 -050039#include <linux/sched.h>
David Howells9ffc93f2012-03-28 18:30:03 +010040#include "bc_dts_glob_lnx.h"
Jarod Wilson7963eb42010-01-04 18:02:27 -050041
42/* Global log level variable defined in crystal_misc.c file */
43extern uint32_t g_linklog_level;
44
45/* Global element pool for all Queue management.
46 * TX: Active = BC_TX_LIST_CNT, Free = BC_TX_LIST_CNT.
47 * RX: Free = BC_RX_LIST_CNT, Active = 2
48 * FW-CMD: 4
49 */
50#define BC_LINK_ELEM_POOL_SZ ((BC_TX_LIST_CNT * 2) + BC_RX_LIST_CNT + 2 + 4)
51
52/* Driver's IODATA pool count */
53#define CHD_IODATA_POOL_SZ (BC_IOCTL_DATA_POOL_SIZE * BC_LINK_MAX_OPENS)
54
55/* Scatter Gather memory pool size for Tx and Rx */
56#define BC_LINK_SG_POOL_SZ (BC_TX_LIST_CNT + BC_RX_LIST_CNT)
57
Lior Dotanabfc7682010-05-18 12:46:42 +030058enum crystalhd_dio_sig {
Jarod Wilson7963eb42010-01-04 18:02:27 -050059 crystalhd_dio_inv = 0,
60 crystalhd_dio_locked,
61 crystalhd_dio_sg_mapped,
62};
63
64struct crystalhd_dio_user_info {
65 void *xfr_buff;
66 uint32_t xfr_len;
67 uint32_t uv_offset;
68 bool dir_tx;
69
70 uint32_t uv_sg_ix;
71 uint32_t uv_sg_off;
72 int comp_sts;
73 int ev_sts;
74 uint32_t y_done_sz;
75 uint32_t uv_done_sz;
76 uint32_t comp_flags;
77 bool b422mode;
78};
79
Lior Dotanabfc7682010-05-18 12:46:42 +030080struct crystalhd_dio_req {
Jarod Wilson7963eb42010-01-04 18:02:27 -050081 uint32_t sig;
82 uint32_t max_pages;
83 struct page **pages;
84 struct scatterlist *sg;
85 int sg_cnt;
86 int page_cnt;
87 int direction;
88 struct crystalhd_dio_user_info uinfo;
89 void *fb_va;
90 uint32_t fb_size;
91 dma_addr_t fb_pa;
Lior Dotanabfc7682010-05-18 12:46:42 +030092 struct crystalhd_dio_req *next;
93};
Jarod Wilson7963eb42010-01-04 18:02:27 -050094
95#define BC_LINK_DIOQ_SIG (0x09223280)
96
Lior Dotanabfc7682010-05-18 12:46:42 +030097struct crystalhd_elem {
98 struct crystalhd_elem *flink;
99 struct crystalhd_elem *blink;
Jarod Wilson7963eb42010-01-04 18:02:27 -0500100 void *data;
101 uint32_t tag;
Lior Dotanabfc7682010-05-18 12:46:42 +0300102};
Jarod Wilson7963eb42010-01-04 18:02:27 -0500103
104typedef void (*crystalhd_data_free_cb)(void *context, void *data);
105
Lior Dotanabfc7682010-05-18 12:46:42 +0300106struct crystalhd_dioq {
Jarod Wilson7963eb42010-01-04 18:02:27 -0500107 uint32_t sig;
108 struct crystalhd_adp *adp;
Lior Dotanabfc7682010-05-18 12:46:42 +0300109 struct crystalhd_elem *head;
110 struct crystalhd_elem *tail;
Jarod Wilson7963eb42010-01-04 18:02:27 -0500111 uint32_t count;
112 spinlock_t lock;
113 wait_queue_head_t event;
114 crystalhd_data_free_cb data_rel_cb;
115 void *cb_context;
Lior Dotanabfc7682010-05-18 12:46:42 +0300116};
Jarod Wilson7963eb42010-01-04 18:02:27 -0500117
Lior Dotanabfc7682010-05-18 12:46:42 +0300118typedef void (*hw_comp_callback)(struct crystalhd_dio_req *,
119 wait_queue_head_t *event, enum BC_STATUS sts);
Jarod Wilson7963eb42010-01-04 18:02:27 -0500120
121/*========= Decoder (7412) register access routines.================= */
122uint32_t bc_dec_reg_rd(struct crystalhd_adp *, uint32_t);
123void bc_dec_reg_wr(struct crystalhd_adp *, uint32_t, uint32_t);
124
125/*========= Link (70012) register access routines.. =================*/
126uint32_t crystalhd_reg_rd(struct crystalhd_adp *, uint32_t);
127void crystalhd_reg_wr(struct crystalhd_adp *, uint32_t, uint32_t);
128
129/*========= Decoder (7412) memory access routines..=================*/
Amarjargal Gundjalamd7c94552013-05-13 03:18:07 -0700130enum BC_STATUS crystalhd_mem_rd(struct crystalhd_adp *,
131 uint32_t, uint32_t, uint32_t *);
132enum BC_STATUS crystalhd_mem_wr(struct crystalhd_adp *,
133 uint32_t, uint32_t, uint32_t *);
Jarod Wilson7963eb42010-01-04 18:02:27 -0500134
135/*==========Link (70012) PCIe Config access routines.================*/
Amarjargal Gundjalamd7c94552013-05-13 03:18:07 -0700136enum BC_STATUS crystalhd_pci_cfg_rd(struct crystalhd_adp *,
137 uint32_t, uint32_t, uint32_t *);
138enum BC_STATUS crystalhd_pci_cfg_wr(struct crystalhd_adp *,
139 uint32_t, uint32_t, uint32_t);
Jarod Wilson7963eb42010-01-04 18:02:27 -0500140
141/*========= Linux Kernel Interface routines. ======================= */
142void *bc_kern_dma_alloc(struct crystalhd_adp *, uint32_t, dma_addr_t *);
143void bc_kern_dma_free(struct crystalhd_adp *, uint32_t,
144 void *, dma_addr_t);
145#define crystalhd_create_event(_ev) init_waitqueue_head(_ev)
146#define crystalhd_set_event(_ev) wake_up_interruptible(_ev)
147#define crystalhd_wait_on_event(ev, condition, timeout, ret, nosig) \
148do { \
149 DECLARE_WAITQUEUE(entry, current); \
150 unsigned long end = jiffies + ((timeout * HZ) / 1000); \
151 ret = 0; \
152 add_wait_queue(ev, &entry); \
153 for (;;) { \
154 __set_current_state(TASK_INTERRUPTIBLE); \
155 if (condition) { \
156 break; \
157 } \
158 if (time_after_eq(jiffies, end)) { \
159 ret = -EBUSY; \
160 break; \
161 } \
162 schedule_timeout((HZ / 100 > 1) ? HZ / 100 : 1); \
163 if (!nosig && signal_pending(current)) { \
164 ret = -EINTR; \
165 break; \
166 } \
167 } \
168 __set_current_state(TASK_RUNNING); \
169 remove_wait_queue(ev, &entry); \
170} while (0)
171
172/*================ Direct IO mapping routines ==================*/
173extern int crystalhd_create_dio_pool(struct crystalhd_adp *, uint32_t);
174extern void crystalhd_destroy_dio_pool(struct crystalhd_adp *);
Amarjargal Gundjalamd7c94552013-05-13 03:18:07 -0700175extern enum BC_STATUS crystalhd_map_dio(struct crystalhd_adp *, void *,
176 uint32_t, uint32_t, bool, bool, struct crystalhd_dio_req**);
Jarod Wilson7963eb42010-01-04 18:02:27 -0500177
Amarjargal Gundjalamd7c94552013-05-13 03:18:07 -0700178extern enum BC_STATUS crystalhd_unmap_dio(struct crystalhd_adp *,
179 struct crystalhd_dio_req*);
Shaun Laingdf239832013-08-29 08:27:22 -0600180#define crystalhd_get_sgle_paddr(_dio, _ix) (sg_dma_address(&_dio->sg[_ix]))
181#define crystalhd_get_sgle_len(_dio, _ix) (sg_dma_len(&_dio->sg[_ix]))
Jarod Wilson7963eb42010-01-04 18:02:27 -0500182
183/*================ General Purpose Queues ==================*/
Amarjargal Gundjalamd7c94552013-05-13 03:18:07 -0700184extern enum BC_STATUS crystalhd_create_dioq(struct crystalhd_adp *,
185 struct crystalhd_dioq **, crystalhd_data_free_cb , void *);
186extern void crystalhd_delete_dioq(struct crystalhd_adp *,
187 struct crystalhd_dioq *);
188extern enum BC_STATUS crystalhd_dioq_add(struct crystalhd_dioq *ioq,
189 void *data, bool wake, uint32_t tag);
Lior Dotanabfc7682010-05-18 12:46:42 +0300190extern void *crystalhd_dioq_fetch(struct crystalhd_dioq *ioq);
Amarjargal Gundjalamd7c94552013-05-13 03:18:07 -0700191extern void *crystalhd_dioq_find_and_fetch(struct crystalhd_dioq *ioq,
192 uint32_t tag);
193extern void *crystalhd_dioq_fetch_wait(struct crystalhd_dioq *ioq,
194 uint32_t to_secs, uint32_t *sig_pend);
Jarod Wilson7963eb42010-01-04 18:02:27 -0500195
196#define crystalhd_dioq_count(_ioq) ((_ioq) ? _ioq->count : 0)
197
198extern int crystalhd_create_elem_pool(struct crystalhd_adp *, uint32_t);
199extern void crystalhd_delete_elem_pool(struct crystalhd_adp *);
200
201
202/*================ Debug routines/macros .. ================================*/
Amarjargal Gundjalamd7c94552013-05-13 03:18:07 -0700203extern void crystalhd_show_buffer(uint32_t off, uint8_t *buff,
204 uint32_t dwcount);
Jarod Wilson7963eb42010-01-04 18:02:27 -0500205
206enum _chd_log_levels {
207 BCMLOG_ERROR = 0x80000000, /* Don't disable this option */
208 BCMLOG_DATA = 0x40000000, /* Data, enable by default */
Masanari Iidacc922722013-12-06 23:27:55 +0900209 BCMLOG_SPINLOCK = 0x20000000, /* Special case for Spin locks*/
Jarod Wilson7963eb42010-01-04 18:02:27 -0500210
211 /* Following are allowed only in debug mode */
212 BCMLOG_INFO = 0x00000001, /* Generic informational */
213 BCMLOG_DBG = 0x00000002, /* First level Debug info */
214 BCMLOG_SSTEP = 0x00000004, /* Stepping information */
Jarod Wilson7963eb42010-01-04 18:02:27 -0500215};
216
Jarod Wilson7963eb42010-01-04 18:02:27 -0500217
Jorgyano Vieira413db8c2012-02-15 00:20:06 -0200218#define BCMLOG(trace, fmt, args...) \
219do { \
220 if (g_linklog_level & trace) \
221 printk(fmt, ##args); \
222} while (0)
Jarod Wilson7963eb42010-01-04 18:02:27 -0500223
Jorgyano Vieira413db8c2012-02-15 00:20:06 -0200224
225#define BCMLOG_ERR(fmt, args...) \
226do { \
227 if (g_linklog_level & BCMLOG_ERROR) \
Gulsah Kose4353ea82014-03-15 03:06:06 +0200228 pr_err("*ERR*:%s:%d: "fmt, \
Jorgyano Vieira413db8c2012-02-15 00:20:06 -0200229 __FILE__, __LINE__, ##args); \
230} while (0)
Jarod Wilson7963eb42010-01-04 18:02:27 -0500231
232#endif