3 * ===================================
4 * HARP | Host ATM Research Platform
5 * ===================================
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.
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.
21 * Copyright 1994-1998 Network Computing Services, Inc.
23 * Copies of this Software may be made, however, the above copyright
24 * notice must be reproduced on all copies.
31 * FORE Systems 200-Series Adapter Support
32 * ---------------------------------------
34 * Cell Processor (CP) initialization routines
38 #include <sys/param.h>
39 #include <sys/kernel.h>
40 #include <sys/systm.h>
41 #include <sys/socket.h>
42 #include <sys/socketvar.h>
43 #include <sys/syslog.h>
47 #include <netatm/port.h>
48 #include <netatm/queue.h>
49 #include <netatm/atm.h>
50 #include <netatm/atm_sys.h>
51 #include <netatm/atm_sap.h>
52 #include <netatm/atm_cm.h>
53 #include <netatm/atm_if.h>
54 #include <netatm/atm_stack.h>
55 #include <netatm/atm_pcb.h>
56 #include <netatm/atm_var.h>
57 #include <dev/pci/pcivar.h>
58 #include <dev/hfa/fore.h>
59 #include <dev/hfa/fore_aali.h>
60 #include <dev/hfa/fore_slave.h>
61 #include <dev/hfa/fore_stats.h>
62 #include <dev/hfa/fore_var.h>
63 #include <dev/hfa/fore_include.h>
66 __RCSID("@(#) $FreeBSD$");
73 static void fore_get_prom(Fore_unit *);
77 * Begin CP Initialization
79 * This function will poll for the successful downloading and starting of
80 * the CP microcode program. After the microcode is running, we will allocate
81 * any needed kernel memory (must do it in non-interrupt mode), build the CP
82 * queue configurations and issue an Initialize command to the CP.
85 * fup pointer to device unit structure
102 * Must wait until firmware has been downloaded and is running
104 if (CP_READ(fup->fu_mon->mon_bstat) != BOOT_RUNNING) {
110 timeout((KTimeout_ret(*)(void *))fore_initialize,
114 callout_handle_init(&fup->fu_thandle);
117 * Allocate queues and whatever else is needed
119 if (fore_xmit_allocate(fup)) {
120 errmsg = "transmit queue allocation";
123 if (fore_recv_allocate(fup)) {
124 errmsg = "receive queue allocation";
127 if (fore_buf_allocate(fup)) {
128 errmsg = "buffer supply queue allocation";
131 if (fore_cmd_allocate(fup)) {
132 errmsg = "command queue allocation";
137 * CP microcode is downloaded - locate shared memory interface
139 aap = (Aali *)(fup->fu_ram + CP_READ(fup->fu_mon->mon_appl));
143 * Pick out any interesting info from the microcode
145 vers = CP_READ(aap->aali_ucode_ver);
146 if (vers < FORE_MIN_UCODE) {
147 errmsg = "unsupported microcode version";
150 snprintf(fup->fu_config.ac_firm_vers,
151 sizeof(fup->fu_config.ac_firm_vers), "%ld.%ld.%ld",
152 (vers >> 16) & 0xff, (vers >> 8) & 0xff, vers & 0xff);
154 if (((vers >> 16) & 0xff) == 4)
161 * Turn on CP debugging
163 aap->aali_hostlog = 1;
167 * Build the initialization block
169 inp = &aap->aali_init;
170 inp->init_numvcc = CP_WRITE(FORE_MAX_VCC);
171 inp->init_cmd_elem = CP_WRITE(CMD_QUELEN);
172 inp->init_xmit_elem = CP_WRITE(XMIT_QUELEN);
173 inp->init_recv_elem = CP_WRITE(RECV_QUELEN);
174 inp->init_recv_ext = CP_WRITE(RECV_EXTRA_SEGS);
175 inp->init_xmit_ext = CP_WRITE(XMIT_EXTRA_SEGS);
176 inp->init_buf1s.bfs_quelen = CP_WRITE(BUF1_SM_QUELEN);
177 inp->init_buf1s.bfs_bufsize = CP_WRITE(BUF1_SM_SIZE);
178 inp->init_buf1s.bfs_cppool = CP_WRITE(BUF1_SM_CPPOOL);
179 inp->init_buf1s.bfs_entsize = CP_WRITE(BUF1_SM_ENTSIZE);
180 inp->init_buf1l.bfs_quelen = CP_WRITE(BUF1_LG_QUELEN);
181 inp->init_buf1l.bfs_bufsize = CP_WRITE(BUF1_LG_SIZE);
182 inp->init_buf1l.bfs_cppool = CP_WRITE(BUF1_LG_CPPOOL);
183 inp->init_buf1l.bfs_entsize = CP_WRITE(BUF1_LG_ENTSIZE);
184 inp->init_buf2s.bfs_quelen = CP_WRITE(0);
185 inp->init_buf2s.bfs_bufsize = CP_WRITE(0);
186 inp->init_buf2s.bfs_cppool = CP_WRITE(0);
187 inp->init_buf2s.bfs_entsize = CP_WRITE(0);
188 inp->init_buf2l.bfs_quelen = CP_WRITE(0);
189 inp->init_buf2l.bfs_bufsize = CP_WRITE(0);
190 inp->init_buf2l.bfs_cppool = CP_WRITE(0);
191 inp->init_buf2l.bfs_entsize = CP_WRITE(0);
194 * Enable device interrupts
196 aap->aali_intr_ena = CP_WRITE(1);
199 * Issue the Initialize command to the CP and wait for
200 * the CP to interrupt to signal completion
202 inp->init_status = CP_WRITE(QSTAT_PENDING);
205 inp->init_cmd = CP_WRITE(CMD_INIT | CMD_INTR_REQ);
208 inp->init_cmd = CP_WRITE(CMD_INIT);
211 * With the ForeThought 4.X image it appears that we need to
212 * busy wait on the initializisation command to complete.
213 * Otherwise the command queue address (the first word
214 * of the queue structure) will be mangled.
217 for (wait = 0; wait < MAX_WAIT; wait++) {
218 c = CP_READ(inp->init_status);
219 if (c & QSTAT_COMPLETED)
223 if (c & QSTAT_ERROR) {
224 log(LOG_ERR, "fore initialization failed: intf=%s%d, "
225 "hbeat=0x%lx\n", fup->fu_pif.pif_name,
226 fup->fu_pif.pif_unit, (u_long)CP_READ(aap->aali_heartbeat));
227 fore_interface_free(fup);
230 if (!(c & QSTAT_COMPLETED)) {
231 log(LOG_ERR, "fore initialization timed out: intf=%s%d, "
232 "hbeat=0x%lx\n", fup->fu_pif.pif_name, fup->fu_pif.pif_unit,
233 (u_long)CP_READ(aap->aali_heartbeat));
234 fore_interface_free(fup);
237 fore_initialize_complete(fup);
242 * Initialization failure
244 fore_interface_free(fup);
245 log(LOG_ERR, "fore initialization failed: intf=%s%d, err=%s\n",
246 fup->fu_pif.pif_name, fup->fu_pif.pif_unit, errmsg);
252 * Complete CP Initialization
254 * Called after the CP has successfully completed processing of the
255 * Initialize command. We will now finish off our part of the
256 * initialization process by setting up all the host-based queue
257 * management structures.
259 * Called at interrupt level.
262 * fup pointer to device unit structure
268 fore_initialize_complete(fup)
271 Aali *aap = fup->fu_aali;
274 * Log an initialization failure
276 if (CP_READ(aap->aali_init.init_status) & QSTAT_ERROR) {
279 "fore initialization failed: intf=%s%d, hbeat=0x%lx\n",
280 fup->fu_pif.pif_name, fup->fu_pif.pif_unit,
281 (u_long)CP_READ(aap->aali_heartbeat));
285 ATM_DEBUG1("heap=0x%lx\n", aap->aali_heap);
286 ATM_DEBUG1("heaplen=0x%lx\n", aap->aali_heaplen);
287 ATM_DEBUG1("cmd_q=0x%lx\n", aap->aali_cmd_q);
288 ATM_DEBUG1("xmit_q=0x%lx\n", aap->aali_xmit_q);
289 ATM_DEBUG1("recv_q=0x%lx\n", aap->aali_recv_q);
290 ATM_DEBUG1("buf1s_q=0x%lx\n", aap->aali_buf1s_q);
291 ATM_DEBUG1("buf1l_q=0x%lx\n", aap->aali_buf1l_q);
292 ATM_DEBUG1("buf2s_q=0x%lx\n", aap->aali_buf2s_q);
293 ATM_DEBUG1("buf2l_q=0x%lx\n", aap->aali_buf2l_q);
296 * Initialize all of our queues
298 fore_xmit_initialize(fup);
299 fore_recv_initialize(fup);
300 fore_buf_initialize(fup);
301 fore_cmd_initialize(fup);
304 * Mark device initialization completed
306 fup->fu_flags |= CUF_INITED;
314 * Get device PROM values from CP
316 * This function will issue a GET_PROM command to the CP in order to
317 * initiate the DMA transfer of the CP's PROM structure to the host.
318 * This will be called after CP initialization has completed.
319 * There is (currently) no retry if this fails.
321 * It took me some time to find out that FT3 and FT4 use different
322 * operation codes for GET_PROM.
324 * Called at interrupt level.
327 * fup pointer to device unit structure
341 * Queue command at end of command queue
343 hcp = fup->fu_cmd_tail;
344 if ((*hcp->hcq_status) & QSTAT_FREE) {
347 * Queue entry available, so set our view of things up
350 hcp->hcq_code = CMD_GET_PROM4;
352 hcp->hcq_code = CMD_GET_PROM;
354 fup->fu_cmd_tail = hcp->hcq_next;
357 * Now set the CP-resident queue entry - the CP will grab
358 * the command when the op-code is set.
360 cqp = hcp->hcq_cpelem;
361 (*hcp->hcq_status) = QSTAT_PENDING;
363 fup->fu_promd = vtophys(fup->fu_prom);
364 if (fup->fu_promd == 0) {
365 fup->fu_stats->st_drv.drv_cm_nodma++;
368 cqp->cmdq_prom.prom_buffer = (CP_dma) CP_WRITE(fup->fu_promd);
369 cqp->cmdq_prom.prom_cmd = CP_WRITE(hcp->hcq_code | CMD_INTR_REQ);
375 fup->fu_stats->st_drv.drv_cm_full++;