kernel: Sync ACPICA with Intel's version 20140424.
[dragonfly.git] / sys / dev / atm / hfa / fore_if.c
1 /*
2  *
3  * ===================================
4  * HARP  |  Host ATM Research Platform
5  * ===================================
6  *
7  *
8  * This Host ATM Research Platform ("HARP") file (the "Software") is
9  * made available by Network Computing Services, Inc. ("NetworkCS")
10  * "AS IS".  NetworkCS does not provide maintenance, improvements or
11  * support of any kind.
12  *
13  * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
14  * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
15  * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
16  * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
17  * In no event shall NetworkCS be responsible for any damages, including
18  * but not limited to consequential damages, arising from or relating to
19  * any use of the Software or related support.
20  *
21  * Copyright 1994-1998 Network Computing Services, Inc.
22  *
23  * Copies of this Software may be made, however, the above copyright
24  * notice must be reproduced on all copies.
25  *
26  *      @(#) $FreeBSD: src/sys/dev/hfa/fore_if.c,v 1.5 1999/08/28 00:41:49 peter Exp $
27  *      @(#) $DragonFly: src/sys/dev/atm/hfa/fore_if.c,v 1.5 2008/03/01 22:03:13 swildner Exp $
28  */
29
30 /*
31  * FORE Systems 200-Series Adapter Support
32  * ---------------------------------------
33  *
34  * Network interface layer support
35  *
36  */
37
38 #include "fore_include.h"
39
40 /*
41  * Handle netatm core service interface ioctl requests 
42  *
43  * Called at splnet.
44  *
45  * Arguments:
46  *      code            ioctl function (sub)code
47  *      data            data to/from ioctl
48  *      arg             optional code-specific argument
49  *
50  * Returns:
51  *      0               request processed successfully
52  *      error           request failed - reason code
53  */
54 int
55 fore_atm_ioctl(int code, caddr_t data, caddr_t arg)
56 {
57         struct atminfreq        *aip = (struct atminfreq *)data;
58         struct atm_pif          *pip;
59         Fore_unit               *fup;
60         caddr_t                 buf = aip->air_buf_addr;
61         struct air_vinfo_rsp    *avr;
62         int                     count, len, buf_len = aip->air_buf_len;
63         int                     err = 0;
64         char                    ifname[2*IFNAMSIZ];
65  
66
67         ATM_DEBUG2("fore_atm_ioctl: code=%d, opcode=%d\n", 
68                 code, aip->air_opcode);
69
70         switch ( aip->air_opcode ) {
71
72         case AIOCS_INF_VST:
73                 /*
74                  * Get vendor statistics
75                  */
76                 pip = (struct atm_pif *)arg;
77                 fup = (Fore_unit *)pip;
78                 if ( pip == NULL )
79                         return ( ENXIO );
80                 ksnprintf ( ifname, sizeof(ifname),
81                     "%s%d", pip->pif_name, pip->pif_unit );
82
83                 /*
84                  * Cast response structure onto user's buffer
85                  */
86                 avr = (struct air_vinfo_rsp *)buf;
87
88                 /*
89                  * How large is the response structure?
90                  */
91                 len = sizeof(struct air_vinfo_rsp);
92
93                 /*
94                  * Sanity check - enough room for response structure?
95                  */
96                 if ( buf_len < len )
97                         return ( ENOSPC );
98
99                 /*
100                  * Copy interface name into response structure
101                  */
102                 if ((err = copyout ( ifname, avr->avsp_intf, IFNAMSIZ)) != 0)
103                         break;
104
105                 /*
106                  * Advance the buffer address and decrement the size
107                  */
108                 buf += len;
109                 buf_len -= len;
110
111                 /*
112                  * Get the vendor stats from the hardware
113                  */
114                 count = 0;
115                 if ( ( err = fore_get_stats ( fup ) ) == 0 )
116                 {
117                         /*
118                          * Stick as much of it as we have room for 
119                          * into the response
120                          */
121                         count = min ( sizeof(Fore_stats), buf_len );
122
123                         /*
124                          * Copy stats into user's buffer. Return value is
125                          * amount of data copied.
126                          */
127                         if ((err = copyout((caddr_t)fup->fu_stats, buf, count)) != 0)
128                                 break;
129                         buf += count;
130                         buf_len -= count;
131                         if ( count < sizeof(Fore_stats) )
132                                 err = ENOSPC;
133                 }
134
135                 /*
136                  * Record amount we're returning as vendor info...
137                  */
138                 if ((err = copyout(&count, &avr->avsp_len, sizeof(int))) != 0)
139                         break;
140
141                 /*
142                  * Update the reply pointers and lengths
143                  */
144                 aip->air_buf_addr = buf;
145                 aip->air_buf_len = buf_len;
146                 break;
147
148         default:
149                 err = ENOSYS;           /* Operation not supported */
150                 break;
151         }
152
153         return (err);
154 }
155
156
157 /*
158  * Free Fore-specific device resources
159  * 
160  * Frees all dynamically acquired resources for a device unit.  Before
161  * this function is called, the CP will have been reset and our interrupt
162  * vectors removed.
163  *
164  * Arguments:
165  *      fup     pointer to device unit structure
166  *
167  * Returns:
168  *      none
169  *
170  */
171 void
172 fore_interface_free(Fore_unit *fup)
173 {
174
175         /*
176          * Free up all of our allocated memory
177          */
178         fore_xmit_free(fup);
179         fore_recv_free(fup);
180         fore_buf_free(fup);
181         fore_cmd_free(fup);
182
183         /*
184          * Clear device initialized
185          */
186         if (fup->fu_flags & CUF_INITED) {
187                 fup->fu_flags &= ~CUF_INITED;
188         }
189
190         if (fup->fu_flags & FUF_STATCMD) {
191                 DMA_FREE_ADDR(fup->fu_stats, fup->fu_statsd,
192                         sizeof(Fore_cp_stats), 0);
193                 fup->fu_flags &= ~FUF_STATCMD;
194         }
195         return;
196 }
197