1 /***************************************************************************
2 * Copyright (c) 2005-2009, Broadcom Corporation.
4 * Name: crystalhd_misc . h
7 * BCM70012 Linux driver general purpose routines.
8 * Includes reg/mem read and write routines.
12 **********************************************************************
13 * This file is part of the crystalhd device driver.
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.
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.
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 **********************************************************************/
28 #ifndef _CRYSTALHD_MISC_H_
29 #define _CRYSTALHD_MISC_H_
31 #include <linux/module.h>
32 #include <linux/kernel.h>
33 #include <linux/errno.h>
34 #include <linux/string.h>
35 #include <linux/ioctl.h>
36 #include <linux/dma-mapping.h>
37 #include <linux/sched.h>
38 #include <asm/system.h>
39 #include "bc_dts_glob_lnx.h"
41 /* Global log level variable defined in crystal_misc.c file */
42 extern uint32_t g_linklog_level
;
44 /* Global element pool for all Queue management.
45 * TX: Active = BC_TX_LIST_CNT, Free = BC_TX_LIST_CNT.
46 * RX: Free = BC_RX_LIST_CNT, Active = 2
49 #define BC_LINK_ELEM_POOL_SZ ((BC_TX_LIST_CNT * 2) + BC_RX_LIST_CNT + 2 + 4)
51 /* Driver's IODATA pool count */
52 #define CHD_IODATA_POOL_SZ (BC_IOCTL_DATA_POOL_SIZE * BC_LINK_MAX_OPENS)
54 /* Scatter Gather memory pool size for Tx and Rx */
55 #define BC_LINK_SG_POOL_SZ (BC_TX_LIST_CNT + BC_RX_LIST_CNT)
57 enum crystalhd_dio_sig
{
58 crystalhd_dio_inv
= 0,
60 crystalhd_dio_sg_mapped
,
63 struct crystalhd_dio_user_info
{
79 struct crystalhd_dio_req
{
83 struct scatterlist
*sg
;
87 struct crystalhd_dio_user_info uinfo
;
91 struct crystalhd_dio_req
*next
;
94 #define BC_LINK_DIOQ_SIG (0x09223280)
96 struct crystalhd_elem
{
97 struct crystalhd_elem
*flink
;
98 struct crystalhd_elem
*blink
;
103 typedef void (*crystalhd_data_free_cb
)(void *context
, void *data
);
105 struct crystalhd_dioq
{
107 struct crystalhd_adp
*adp
;
108 struct crystalhd_elem
*head
;
109 struct crystalhd_elem
*tail
;
112 wait_queue_head_t event
;
113 crystalhd_data_free_cb data_rel_cb
;
117 typedef void (*hw_comp_callback
)(struct crystalhd_dio_req
*,
118 wait_queue_head_t
*event
, enum BC_STATUS sts
);
120 /*========= Decoder (7412) register access routines.================= */
121 uint32_t bc_dec_reg_rd(struct crystalhd_adp
*, uint32_t);
122 void bc_dec_reg_wr(struct crystalhd_adp
*, uint32_t, uint32_t);
124 /*========= Link (70012) register access routines.. =================*/
125 uint32_t crystalhd_reg_rd(struct crystalhd_adp
*, uint32_t);
126 void crystalhd_reg_wr(struct crystalhd_adp
*, uint32_t, uint32_t);
128 /*========= Decoder (7412) memory access routines..=================*/
129 enum BC_STATUS
crystalhd_mem_rd(struct crystalhd_adp
*, uint32_t, uint32_t, uint32_t *);
130 enum BC_STATUS
crystalhd_mem_wr(struct crystalhd_adp
*, uint32_t, uint32_t, uint32_t *);
132 /*==========Link (70012) PCIe Config access routines.================*/
133 enum BC_STATUS
crystalhd_pci_cfg_rd(struct crystalhd_adp
*, uint32_t, uint32_t, uint32_t *);
134 enum BC_STATUS
crystalhd_pci_cfg_wr(struct crystalhd_adp
*, uint32_t, uint32_t, uint32_t);
136 /*========= Linux Kernel Interface routines. ======================= */
137 void *bc_kern_dma_alloc(struct crystalhd_adp
*, uint32_t, dma_addr_t
*);
138 void bc_kern_dma_free(struct crystalhd_adp
*, uint32_t,
140 #define crystalhd_create_event(_ev) init_waitqueue_head(_ev)
141 #define crystalhd_set_event(_ev) wake_up_interruptible(_ev)
142 #define crystalhd_wait_on_event(ev, condition, timeout, ret, nosig) \
144 DECLARE_WAITQUEUE(entry, current); \
145 unsigned long end = jiffies + ((timeout * HZ) / 1000); \
147 add_wait_queue(ev, &entry); \
149 __set_current_state(TASK_INTERRUPTIBLE); \
153 if (time_after_eq(jiffies, end)) { \
157 schedule_timeout((HZ / 100 > 1) ? HZ / 100 : 1); \
158 if (!nosig && signal_pending(current)) { \
163 __set_current_state(TASK_RUNNING); \
164 remove_wait_queue(ev, &entry); \
167 /*================ Direct IO mapping routines ==================*/
168 extern int crystalhd_create_dio_pool(struct crystalhd_adp
*, uint32_t);
169 extern void crystalhd_destroy_dio_pool(struct crystalhd_adp
*);
170 extern enum BC_STATUS
crystalhd_map_dio(struct crystalhd_adp
*, void *, uint32_t,
171 uint32_t, bool, bool, struct crystalhd_dio_req
**);
173 extern enum BC_STATUS
crystalhd_unmap_dio(struct crystalhd_adp
*, struct crystalhd_dio_req
*);
174 #define crystalhd_get_sgle_paddr(_dio, _ix) (cpu_to_le64(sg_dma_address(&_dio->sg[_ix])))
175 #define crystalhd_get_sgle_len(_dio, _ix) (cpu_to_le32(sg_dma_len(&_dio->sg[_ix])))
177 /*================ General Purpose Queues ==================*/
178 extern enum BC_STATUS
crystalhd_create_dioq(struct crystalhd_adp
*, struct crystalhd_dioq
**, crystalhd_data_free_cb
, void *);
179 extern void crystalhd_delete_dioq(struct crystalhd_adp
*, struct crystalhd_dioq
*);
180 extern enum BC_STATUS
crystalhd_dioq_add(struct crystalhd_dioq
*ioq
, void *data
, bool wake
, uint32_t tag
);
181 extern void *crystalhd_dioq_fetch(struct crystalhd_dioq
*ioq
);
182 extern void *crystalhd_dioq_find_and_fetch(struct crystalhd_dioq
*ioq
, uint32_t tag
);
183 extern void *crystalhd_dioq_fetch_wait(struct crystalhd_dioq
*ioq
, uint32_t to_secs
, uint32_t *sig_pend
);
185 #define crystalhd_dioq_count(_ioq) ((_ioq) ? _ioq->count : 0)
187 extern int crystalhd_create_elem_pool(struct crystalhd_adp
*, uint32_t);
188 extern void crystalhd_delete_elem_pool(struct crystalhd_adp
*);
191 /*================ Debug routines/macros .. ================================*/
192 extern void crystalhd_show_buffer(uint32_t off
, uint8_t *buff
, uint32_t dwcount
);
194 enum _chd_log_levels
{
195 BCMLOG_ERROR
= 0x80000000, /* Don't disable this option */
196 BCMLOG_DATA
= 0x40000000, /* Data, enable by default */
197 BCMLOG_SPINLOCK
= 0x20000000, /* Spcial case for Spin locks*/
199 /* Following are allowed only in debug mode */
200 BCMLOG_INFO
= 0x00000001, /* Generic informational */
201 BCMLOG_DBG
= 0x00000002, /* First level Debug info */
202 BCMLOG_SSTEP
= 0x00000004, /* Stepping information */
203 BCMLOG_ENTER_LEAVE
= 0x00000008, /* stack tracking */
206 #define BCMLOG_ENTER \
207 if (g_linklog_level & BCMLOG_ENTER_LEAVE) { \
208 printk("Entered %s\n", __func__); \
211 #define BCMLOG_LEAVE \
212 if (g_linklog_level & BCMLOG_ENTER_LEAVE) { \
213 printk("Leaving %s\n", __func__); \
216 #define BCMLOG(trace, fmt, args...) \
217 if (g_linklog_level & trace) { \
218 printk(fmt, ##args); \
221 #define BCMLOG_ERR(fmt, args...) \
223 if (g_linklog_level & BCMLOG_ERROR) { \
224 printk("*ERR*:%s:%d: "fmt, __FILE__, __LINE__, ##args); \