Rename printf -> kprintf in sys/ and add some defines where necessary
[dragonfly.git] / sys / dev / netif / nv / if_nvreg.h
1 /*
2  * Copyright (c) 2003 by Quinton Dolan <q@onthenet.com.au>.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS `AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
24  * SUCH DAMAGE.
25  *
26  * $Id: if_nvreg.h,v 1.6 2004/08/12 14:00:05 q Exp $
27  * $FreeBSD: src/sys/dev/nve/if_nvereg.h,v 1.7 2005/12/07 17:38:03 obrien Exp $
28  * $DragonFly: src/sys/dev/netif/nv/Attic/if_nvreg.h,v 1.13 2006/12/22 23:26:21 swildner Exp $
29  */
30  
31 #ifndef _IF_NVREG_H_
32 #define _IF_NVREG_H_
33
34 /* Include NVIDIA Linux driver header files */
35
36 #define linux
37
38 #include "nvenet_version.h"
39 #include "basetype.h"
40 #include "os.h"
41 #include "drvinfo.h"
42 #include "adapter.h"
43
44 #undef linux
45
46 #ifndef NVIDIA_VENDORID
47 #define NVIDIA_VENDORID 0x10DE
48 #endif
49
50 #define NFORCE_MCPNET1_DEVICEID 0x01C3
51 #define NFORCE_MCPNET2_DEVICEID 0x0066
52 #define NFORCE_MCPNET3_DEVICEID 0x00D6
53 #define NFORCE_MCPNET4_DEVICEID 0x0086
54 #define NFORCE_MCPNET5_DEVICEID 0x008C
55 #define NFORCE_MCPNET6_DEVICEID 0x00E6
56 #define NFORCE_MCPNET7_DEVICEID 0x00DF
57 #define NFORCE_MCPNET8_DEVICEID 0x0056
58 #define NFORCE_MCPNET9_DEVICEID 0x0057
59 #define NFORCE_MCPNET10_DEVICEID 0x0037
60 #define NFORCE_MCPNET11_DEVICEID 0x0038
61 #define NFORCE_MCPNET12_DEVICEID 0x0268
62 #define NFORCE_MCPNET13_DEVICEID 0x0269
63
64 #define NV_RID          0x10
65
66 #define TX_RING_SIZE 64
67 #define RX_RING_SIZE 64
68 #define NV_MAX_FRAGS 32         /* match adapter.h:ADAPTER_WRITE_DATA.sElement[] */
69
70 #define FCS_LEN 4
71
72 #define NV_DEBUG                0x0000
73 #define NV_DEBUG_INIT           0x0001
74 #define NV_DEBUG_RUNNING        0x0002
75 #define NV_DEBUG_DEINIT         0x0004
76 #define NV_DEBUG_IOCTL          0x0008
77 #define NV_DEBUG_INTERRUPT      0x0010
78 #define NV_DEBUG_API            0x0020
79 #define NV_DEBUG_LOCK           0x0040
80 #define NV_DEBUG_BROKEN         0x0080
81 #define NV_DEBUG_MII            0x0100
82 #define NV_DEBUG_ALL            0xFFFF
83
84 #if NV_DEBUG
85 #define DEBUGOUT(level, fmt, args...) if (NV_DEBUG & level) \
86     kprintf(fmt, ## args)
87 #else
88 #define DEBUGOUT(level, fmt, args...)
89 #endif
90
91 typedef unsigned long   ulong;
92
93 struct nv_map_buffer {
94         struct mbuf *mbuf;              /* mbuf receiving packet */
95         bus_dmamap_t map;               /* DMA map */   
96 };
97
98 struct nv_dma_info {
99         bus_dma_tag_t tag;
100         struct nv_map_buffer buf;
101         u_int16_t buflength;
102         caddr_t vaddr;                  /* Virtual memory address */
103         bus_addr_t paddr;               /* DMA physical address */
104 };
105
106 struct nv_rx_desc {
107         struct nv_rx_desc *next;
108         struct nv_map_buffer buf;
109         u_int16_t buflength;
110         caddr_t vaddr;
111         bus_addr_t paddr;
112 };
113
114 struct nv_tx_desc {
115         /* Don't add anything above this structure */
116         TX_INFO_ADAP TxInfoAdap;
117         struct nv_tx_desc *next;
118         struct nv_map_buffer buf;
119         u_int16_t buflength;
120         u_int32_t numfrags;
121         bus_dma_segment_t frags[NV_MAX_FRAGS + 1];
122 };
123
124 struct nv_softc {
125         struct arpcom arpcom;         /* interface info */
126         struct resource *res;
127         struct resource *irq;
128
129         ADAPTER_API *hwapi;
130         OS_API osapi;
131                 
132         device_t miibus;
133         device_t dev;
134         u_int32_t unit;
135         struct callout  nv_stat_timer;
136
137         void *sc_ih;
138         bus_space_tag_t sc_st;
139         bus_space_handle_t sc_sh;
140         bus_dma_tag_t mtag;
141         bus_dma_tag_t rtag;
142         bus_dmamap_t rmap;
143         bus_dma_tag_t ttag;
144         bus_dmamap_t tmap;
145         
146         struct nv_rx_desc *rx_desc;
147         struct nv_tx_desc *tx_desc;
148         bus_addr_t rx_addr;
149         bus_addr_t tx_addr;
150         u_int16_t rx_ring_full;
151         u_int16_t tx_ring_full;
152         u_int32_t cur_rx;
153         u_int32_t cur_tx;
154         u_int32_t pending_rxs;
155         u_int32_t pending_txs;
156         
157         u_int32_t flags;
158         u_int32_t miicfg;
159         int spl;
160                 
161         /* Stuff for dealing with the NVIDIA OS API */
162         struct callout ostimer;
163         PTIMER_FUNC ostimer_func;
164         void *ostimer_params;
165         int linkup;
166         ulong tx_errors;
167         NV_UINT32 hwmode;
168         NV_UINT32 max_frame_size;
169         NV_UINT32 phyaddr;
170         NV_UINT32 media;
171         CMNDATA_OS_ADAPTER adapterdata;
172         unsigned char original_mac_addr[6];
173 };
174
175 struct nv_type {
176         u_int16_t               vid_id;
177         u_int16_t               dev_id;
178         char                    *name;
179 };
180
181 #define sc_if arpcom.ac_if
182 #define sc_macaddr arpcom.ac_enaddr
183
184 #define IF_Kbps(x)      ((x) * 1000)            /* kilobits/sec. */
185 #define IF_Mbps(x)      (IF_Kbps((x) * 1000))   /* megabits/sec. */
186 #define ETHER_ALIGN     2
187
188 extern int ADAPTER_ReadPhy (PVOID pContext, ULONG ulPhyAddr, ULONG ulReg, ULONG *pulVal);
189 extern int ADAPTER_WritePhy (PVOID pContext, ULONG ulPhyAddr, ULONG ulReg, ULONG ulVal);
190 extern int ADAPTER_Init (PVOID pContext, USHORT usForcedSpeed, UCHAR ucForceDpx, UCHAR ucForceMode, UINT *puiLinkState);
191 #endif