timeout/untimeout ==> callout_*
[dragonfly.git] / sys / dev / atm / hfa / fore_init.c
CommitLineData
984263bc
MD
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_init.c,v 1.6 1999/08/29 10:28:09 bde Exp $
7a651277 27 * @(#) $DragonFly: src/sys/dev/atm/hfa/fore_init.c,v 1.5 2004/09/15 01:51:55 joerg Exp $
984263bc
MD
28 */
29
30/*
31 * FORE Systems 200-Series Adapter Support
32 * ---------------------------------------
33 *
34 * Cell Processor (CP) initialization routines
35 *
36 */
37
1f2de5d4 38#include "fore_include.h"
984263bc 39
984263bc
MD
40/*
41 * Local functions
42 */
43#ifdef FORE_PCI
38e94a25 44static void fore_get_prom (Fore_unit *);
984263bc
MD
45#endif
46
47
48/*
49 * Begin CP Initialization
50 *
51 * This function will poll for the successful downloading and starting of
52 * the CP microcode program. After the microcode is running, we will allocate
53 * any needed kernel memory (must do it in non-interrupt mode), build the CP
54 * queue configurations and issue an Initialize command to the CP.
55 *
56 * Arguments:
57 * fup pointer to device unit structure
58 *
59 * Returns:
60 * none
61 */
62void
7a651277 63fore_initialize(void *xfup)
984263bc 64{
7a651277 65 Fore_unit *fup = xfup;
984263bc
MD
66 Aali *aap;
67 Init_parms *inp;
68 caddr_t errmsg;
69 u_long vers;
70
71 /*
72 * Must wait until firmware has been downloaded and is running
73 */
74 if (CP_READ(fup->fu_mon->mon_bstat) != BOOT_RUNNING) {
75
76 /*
77 * Try again later
78 */
7a651277 79 callout_reset(&fup->fu_init_timer, hz, fore_initialize, fup);
984263bc 80 return;
7a651277 81 }
984263bc
MD
82
83 /*
84 * Allocate queues and whatever else is needed
85 */
86 if (fore_xmit_allocate(fup)) {
87 errmsg = "transmit queue allocation";
88 goto failed;
89 }
90 if (fore_recv_allocate(fup)) {
91 errmsg = "receive queue allocation";
92 goto failed;
93 }
94 if (fore_buf_allocate(fup)) {
95 errmsg = "buffer supply queue allocation";
96 goto failed;
97 }
98 if (fore_cmd_allocate(fup)) {
99 errmsg = "command queue allocation";
100 goto failed;
101 }
102
103 /*
104 * CP microcode is downloaded - locate shared memory interface
105 */
106 aap = (Aali *)(fup->fu_ram + CP_READ(fup->fu_mon->mon_appl));
107 fup->fu_aali = aap;
108
109 /*
110 * Pick out any interesting info from the microcode
111 */
112 vers = CP_READ(aap->aali_ucode_ver);
113 if (vers < FORE_MIN_UCODE) {
114 errmsg = "unsupported microcode version";
115 goto failed;
116 }
117 snprintf(fup->fu_config.ac_firm_vers,
118 sizeof(fup->fu_config.ac_firm_vers), "%ld.%ld.%ld",
119 (vers >> 16) & 0xff, (vers >> 8) & 0xff, vers & 0xff);
120
121#ifdef notdef
122 /*
123 * Turn on CP debugging
124 */
125 aap->aali_hostlog = 1;
126#endif
127
128 /*
129 * Build the initialization block
130 */
131 inp = &aap->aali_init;
132 inp->init_numvcc = CP_WRITE(FORE_MAX_VCC);
133 inp->init_cmd_elem = CP_WRITE(CMD_QUELEN);
134 inp->init_xmit_elem = CP_WRITE(XMIT_QUELEN);
135 inp->init_recv_elem = CP_WRITE(RECV_QUELEN);
136 inp->init_recv_ext = CP_WRITE(RECV_EXTRA_SEGS);
137 inp->init_xmit_ext = CP_WRITE(XMIT_EXTRA_SEGS);
138 inp->init_buf1s.bfs_quelen = CP_WRITE(BUF1_SM_QUELEN);
139 inp->init_buf1s.bfs_bufsize = CP_WRITE(BUF1_SM_SIZE);
140 inp->init_buf1s.bfs_cppool = CP_WRITE(BUF1_SM_CPPOOL);
141 inp->init_buf1s.bfs_entsize = CP_WRITE(BUF1_SM_ENTSIZE);
142 inp->init_buf1l.bfs_quelen = CP_WRITE(BUF1_LG_QUELEN);
143 inp->init_buf1l.bfs_bufsize = CP_WRITE(BUF1_LG_SIZE);
144 inp->init_buf1l.bfs_cppool = CP_WRITE(BUF1_LG_CPPOOL);
145 inp->init_buf1l.bfs_entsize = CP_WRITE(BUF1_LG_ENTSIZE);
146 inp->init_buf2s.bfs_quelen = CP_WRITE(0);
147 inp->init_buf2s.bfs_bufsize = CP_WRITE(0);
148 inp->init_buf2s.bfs_cppool = CP_WRITE(0);
149 inp->init_buf2s.bfs_entsize = CP_WRITE(0);
150 inp->init_buf2l.bfs_quelen = CP_WRITE(0);
151 inp->init_buf2l.bfs_bufsize = CP_WRITE(0);
152 inp->init_buf2l.bfs_cppool = CP_WRITE(0);
153 inp->init_buf2l.bfs_entsize = CP_WRITE(0);
154
155 /*
156 * Enable device interrupts
157 */
158 aap->aali_intr_ena = CP_WRITE(1);
159
160 /*
161 * Issue the Initialize command to the CP and wait for
162 * the CP to interrupt to signal completion
163 */
164 inp->init_status = CP_WRITE(QSTAT_PENDING);
165 inp->init_cmd = CP_WRITE(CMD_INIT | CMD_INTR_REQ);
166 return;
167
168failed:
169 /*
170 * Initialization failure
171 */
172 fore_interface_free(fup);
173 log(LOG_ERR, "fore initialization failed: intf=%s%d, err=%s\n",
174 fup->fu_pif.pif_name, fup->fu_pif.pif_unit, errmsg);
175 return;
176}
177
178
179/*
180 * Complete CP Initialization
181 *
182 * Called after the CP has successfully completed processing of the
183 * Initialize command. We will now finish off our part of the
184 * initialization process by setting up all the host-based queue
185 * management structures.
186 *
187 * Called at interrupt level.
188 *
189 * Arguments:
190 * fup pointer to device unit structure
191 *
192 * Returns:
193 * none
194 */
195void
196fore_initialize_complete(fup)
197 Fore_unit *fup;
198{
199 Aali *aap = fup->fu_aali;
200
201 /*
202 * Log an initialization failure
203 */
204 if (CP_READ(aap->aali_init.init_status) & QSTAT_ERROR) {
205
206 log(LOG_ERR,
207 "fore initialization failed: intf=%s%d, hbeat=0x%lx\n",
208 fup->fu_pif.pif_name, fup->fu_pif.pif_unit,
209 (u_long)CP_READ(aap->aali_heartbeat));
210 return;
211 }
212
213 ATM_DEBUG1("heap=0x%lx\n", aap->aali_heap);
214 ATM_DEBUG1("heaplen=0x%lx\n", aap->aali_heaplen);
215 ATM_DEBUG1("cmd_q=0x%lx\n", aap->aali_cmd_q);
216 ATM_DEBUG1("xmit_q=0x%lx\n", aap->aali_xmit_q);
217 ATM_DEBUG1("recv_q=0x%lx\n", aap->aali_recv_q);
218 ATM_DEBUG1("buf1s_q=0x%lx\n", aap->aali_buf1s_q);
219 ATM_DEBUG1("buf1l_q=0x%lx\n", aap->aali_buf1l_q);
220 ATM_DEBUG1("buf2s_q=0x%lx\n", aap->aali_buf2s_q);
221 ATM_DEBUG1("buf2l_q=0x%lx\n", aap->aali_buf2l_q);
222
223 /*
224 * Initialize all of our queues
225 */
226 fore_xmit_initialize(fup);
227 fore_recv_initialize(fup);
228 fore_buf_initialize(fup);
229 fore_cmd_initialize(fup);
230
231 /*
232 * Mark device initialization completed
233 */
234 fup->fu_flags |= CUF_INITED;
235
236#ifdef FORE_PCI
237 fore_get_prom(fup);
238#endif
239 return;
240}
241
242
243#ifdef FORE_PCI
244/*
245 * Get device PROM values from CP
246 *
247 * This function will issue a GET_PROM command to the CP in order to
248 * initiate the DMA transfer of the CP's PROM structure to the host.
249 * This will be called after CP initialization has completed.
250 * There is (currently) no retry if this fails.
251 *
252 * Called at interrupt level.
253 *
254 * Arguments:
255 * fup pointer to device unit structure
256 *
257 * Returns:
258 * none
259 *
260 */
261static void
262fore_get_prom(fup)
263 Fore_unit *fup;
264{
265 H_cmd_queue *hcp;
266 Cmd_queue *cqp;
267
268 /*
269 * Queue command at end of command queue
270 */
271 hcp = fup->fu_cmd_tail;
272 if ((*hcp->hcq_status) & QSTAT_FREE) {
273
274 /*
275 * Queue entry available, so set our view of things up
276 */
277 hcp->hcq_code = CMD_GET_PROM;
278 hcp->hcq_arg = NULL;
279 fup->fu_cmd_tail = hcp->hcq_next;
280
281 /*
282 * Now set the CP-resident queue entry - the CP will grab
283 * the command when the op-code is set.
284 */
285 cqp = hcp->hcq_cpelem;
286 (*hcp->hcq_status) = QSTAT_PENDING;
287
288 fup->fu_promd = DMA_GET_ADDR(fup->fu_prom, sizeof(Fore_prom),
289 FORE_PROM_ALIGN, 0);
290 if (fup->fu_promd == NULL) {
291 fup->fu_stats->st_drv.drv_cm_nodma++;
292 return;
293 }
294 cqp->cmdq_prom.prom_buffer = (CP_dma) CP_WRITE(fup->fu_promd);
295 cqp->cmdq_prom.prom_cmd = CP_WRITE(CMD_GET_PROM | CMD_INTR_REQ);
296
297 } else {
298 /*
299 * Command queue full
300 */
301 fup->fu_stats->st_drv.drv_cm_full++;
302 }
303
304 return;
305}
306#endif /* FORE_PCI */
307