1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2008 NetXen, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _UNM_NIC_HW_
28 #define	_UNM_NIC_HW_
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #include "unm_inc.h"
35 
36 /* Hardware memory size of 128 meg */
37 #define	BAR0_SIZE (128 * 1024 * 1024)
38 /*
39  * It can be calculated by looking at the first 1 bit of the BAR0 addr after
40  * bit 4 For us lets assume that BAR0 is D8000008, then the size is 0x8000000,
41  * 8 represents first bit containing 1.   FSL temp notes....pg 162 of PCI
42  * systems arch...
43  */
44 
45 #define	UNM_NIC_HW_BLOCK_WRITE_64(DATA_PTR, ADDR, NUM_WORDS)        \
46 {                                                           \
47 	int i;                                              \
48 	u64 *a = (u64 *) (DATA_PTR);                        \
49 	u64 *b = (u64 *) (ADDR);                            \
50 	u64 tmp;					    \
51 	for (i = 0; i < (NUM_WORDS); i++, a++, b++) {       \
52 		tmp = UNM_NIC_PCI_READ_64(a);		    \
53 		UNM_NIC_PCI_WRITE_64(tmp, b);		    \
54 	}						    \
55 }
56 
57 #define	UNM_NIC_HW_BLOCK_READ_64(DATA_PTR, ADDR, NUM_WORDS)           \
58 {                                                             \
59 	int i;                                                \
60 	u64 *a = (u64 *) (DATA_PTR);                          \
61 	u64 *b = (u64 *) (ADDR);                              \
62 	u64 tmp;					      \
63 	for (i = 0; i < (NUM_WORDS); i++, a++, b++) {            \
64 		tmp = UNM_NIC_PCI_READ_64(b);		      \
65 		UNM_NIC_PCI_WRITE_64(tmp, a);		      \
66 	}                                                     \
67 }
68 
69 #define	UNM_PCI_MAPSIZE_BYTES  (UNM_PCI_MAPSIZE << 20)
70 
71 #define	UNM_NIC_LOCKED_READ_REG(X, Y)   \
72 	addr = (void *)(pci_base_offset(adapter, (X)));     \
73 	*(uint32_t *)(Y) = UNM_NIC_PCI_READ_32(addr);
74 
75 #define	UNM_NIC_LOCKED_WRITE_REG(X, Y)   \
76 	addr = (void *)(pci_base_offset(adapter, (X))); \
77 	UNM_NIC_PCI_WRITE_32(*(uint32_t *)(Y), addr);
78 
79 /* For Multicard support */
80 #define	UNM_CRB_READ_VAL_ADAPTER(ADDR, ADAPTER) \
81 	unm_crb_read_val_adapter((ADDR), (struct unm_adapter_s *)ADAPTER)
82 
83 #define	UNM_CRB_READ_CHECK_ADAPTER(ADDR, VALUE, ADAPTER)		\
84 	{								\
85 		if (unm_crb_read_adapter(ADDR, VALUE,			\
86 		    (struct unm_adapter_s *)ADAPTER)) return -1;	\
87 	}
88 
89 #define	UNM_CRB_WRITELIT_ADAPTER(ADDR, VALUE, ADAPTER)			\
90 	{								\
91 		adapter->unm_crb_writelit_adapter(			\
92 		    (struct unm_adapter_s *)ADAPTER,			\
93 		    (unsigned long)ADDR, (int)VALUE);			\
94 	}
95 
96 struct unm_adapter_s;
97 void unm_nic_set_link_parameters(struct unm_adapter_s *adapter);
98 long xge_mdio_init(struct unm_adapter_s *adapter);
99 void unm_nic_flash_print(struct unm_adapter_s *adapter);
100 void unm_nic_get_serial_num(struct unm_adapter_s *adapter);
101 
102 typedef struct {
103 	unsigned valid;
104 	unsigned start_128M;
105 	unsigned end_128M;
106 	unsigned start_2M;
107 } crb_128M_2M_sub_block_map_t;
108 
109 typedef struct {
110 	crb_128M_2M_sub_block_map_t sub_block[16];
111 } crb_128M_2M_block_map_t;
112 
113 #ifdef __cplusplus
114 }
115 #endif
116 
117 #endif /* _UNM_NIC_HW_ */
118