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.
26 * @(#) $FreeBSD: src/sys/dev/hfa/fore_init.c,v 1.6 1999/08/29 10:28:09 bde Exp $
27 * @(#) $DragonFly: src/sys/dev/atm/hfa/fore_init.c,v 1.4 2003/08/27 10:35:16 rob Exp $
31 * FORE Systems 200-Series Adapter Support
32 * ---------------------------------------
34 * Cell Processor (CP) initialization routines
38 #include "fore_include.h"
44 static void fore_get_prom (Fore_unit *);
49 * Begin CP Initialization
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.
57 * fup pointer to device unit structure
72 * Must wait until firmware has been downloaded and is running
74 if (CP_READ(fup->fu_mon->mon_bstat) != BOOT_RUNNING) {
80 timeout((KTimeout_ret(*) (void *))fore_initialize,
84 callout_handle_init(&fup->fu_thandle);
87 * Allocate queues and whatever else is needed
89 if (fore_xmit_allocate(fup)) {
90 errmsg = "transmit queue allocation";
93 if (fore_recv_allocate(fup)) {
94 errmsg = "receive queue allocation";
97 if (fore_buf_allocate(fup)) {
98 errmsg = "buffer supply queue allocation";
101 if (fore_cmd_allocate(fup)) {
102 errmsg = "command queue allocation";
107 * CP microcode is downloaded - locate shared memory interface
109 aap = (Aali *)(fup->fu_ram + CP_READ(fup->fu_mon->mon_appl));
113 * Pick out any interesting info from the microcode
115 vers = CP_READ(aap->aali_ucode_ver);
116 if (vers < FORE_MIN_UCODE) {
117 errmsg = "unsupported microcode version";
120 snprintf(fup->fu_config.ac_firm_vers,
121 sizeof(fup->fu_config.ac_firm_vers), "%ld.%ld.%ld",
122 (vers >> 16) & 0xff, (vers >> 8) & 0xff, vers & 0xff);
126 * Turn on CP debugging
128 aap->aali_hostlog = 1;
132 * Build the initialization block
134 inp = &aap->aali_init;
135 inp->init_numvcc = CP_WRITE(FORE_MAX_VCC);
136 inp->init_cmd_elem = CP_WRITE(CMD_QUELEN);
137 inp->init_xmit_elem = CP_WRITE(XMIT_QUELEN);
138 inp->init_recv_elem = CP_WRITE(RECV_QUELEN);
139 inp->init_recv_ext = CP_WRITE(RECV_EXTRA_SEGS);
140 inp->init_xmit_ext = CP_WRITE(XMIT_EXTRA_SEGS);
141 inp->init_buf1s.bfs_quelen = CP_WRITE(BUF1_SM_QUELEN);
142 inp->init_buf1s.bfs_bufsize = CP_WRITE(BUF1_SM_SIZE);
143 inp->init_buf1s.bfs_cppool = CP_WRITE(BUF1_SM_CPPOOL);
144 inp->init_buf1s.bfs_entsize = CP_WRITE(BUF1_SM_ENTSIZE);
145 inp->init_buf1l.bfs_quelen = CP_WRITE(BUF1_LG_QUELEN);
146 inp->init_buf1l.bfs_bufsize = CP_WRITE(BUF1_LG_SIZE);
147 inp->init_buf1l.bfs_cppool = CP_WRITE(BUF1_LG_CPPOOL);
148 inp->init_buf1l.bfs_entsize = CP_WRITE(BUF1_LG_ENTSIZE);
149 inp->init_buf2s.bfs_quelen = CP_WRITE(0);
150 inp->init_buf2s.bfs_bufsize = CP_WRITE(0);
151 inp->init_buf2s.bfs_cppool = CP_WRITE(0);
152 inp->init_buf2s.bfs_entsize = CP_WRITE(0);
153 inp->init_buf2l.bfs_quelen = CP_WRITE(0);
154 inp->init_buf2l.bfs_bufsize = CP_WRITE(0);
155 inp->init_buf2l.bfs_cppool = CP_WRITE(0);
156 inp->init_buf2l.bfs_entsize = CP_WRITE(0);
159 * Enable device interrupts
161 aap->aali_intr_ena = CP_WRITE(1);
164 * Issue the Initialize command to the CP and wait for
165 * the CP to interrupt to signal completion
167 inp->init_status = CP_WRITE(QSTAT_PENDING);
168 inp->init_cmd = CP_WRITE(CMD_INIT | CMD_INTR_REQ);
173 * Initialization failure
175 fore_interface_free(fup);
176 log(LOG_ERR, "fore initialization failed: intf=%s%d, err=%s\n",
177 fup->fu_pif.pif_name, fup->fu_pif.pif_unit, errmsg);
183 * Complete CP Initialization
185 * Called after the CP has successfully completed processing of the
186 * Initialize command. We will now finish off our part of the
187 * initialization process by setting up all the host-based queue
188 * management structures.
190 * Called at interrupt level.
193 * fup pointer to device unit structure
199 fore_initialize_complete(fup)
202 Aali *aap = fup->fu_aali;
205 * Log an initialization failure
207 if (CP_READ(aap->aali_init.init_status) & QSTAT_ERROR) {
210 "fore initialization failed: intf=%s%d, hbeat=0x%lx\n",
211 fup->fu_pif.pif_name, fup->fu_pif.pif_unit,
212 (u_long)CP_READ(aap->aali_heartbeat));
216 ATM_DEBUG1("heap=0x%lx\n", aap->aali_heap);
217 ATM_DEBUG1("heaplen=0x%lx\n", aap->aali_heaplen);
218 ATM_DEBUG1("cmd_q=0x%lx\n", aap->aali_cmd_q);
219 ATM_DEBUG1("xmit_q=0x%lx\n", aap->aali_xmit_q);
220 ATM_DEBUG1("recv_q=0x%lx\n", aap->aali_recv_q);
221 ATM_DEBUG1("buf1s_q=0x%lx\n", aap->aali_buf1s_q);
222 ATM_DEBUG1("buf1l_q=0x%lx\n", aap->aali_buf1l_q);
223 ATM_DEBUG1("buf2s_q=0x%lx\n", aap->aali_buf2s_q);
224 ATM_DEBUG1("buf2l_q=0x%lx\n", aap->aali_buf2l_q);
227 * Initialize all of our queues
229 fore_xmit_initialize(fup);
230 fore_recv_initialize(fup);
231 fore_buf_initialize(fup);
232 fore_cmd_initialize(fup);
235 * Mark device initialization completed
237 fup->fu_flags |= CUF_INITED;
248 * Get device PROM values from CP
250 * This function will issue a GET_PROM command to the CP in order to
251 * initiate the DMA transfer of the CP's PROM structure to the host.
252 * This will be called after CP initialization has completed.
253 * There is (currently) no retry if this fails.
255 * Called at interrupt level.
258 * fup pointer to device unit structure
272 * Queue command at end of command queue
274 hcp = fup->fu_cmd_tail;
275 if ((*hcp->hcq_status) & QSTAT_FREE) {
278 * Queue entry available, so set our view of things up
280 hcp->hcq_code = CMD_GET_PROM;
282 fup->fu_cmd_tail = hcp->hcq_next;
285 * Now set the CP-resident queue entry - the CP will grab
286 * the command when the op-code is set.
288 cqp = hcp->hcq_cpelem;
289 (*hcp->hcq_status) = QSTAT_PENDING;
291 fup->fu_promd = DMA_GET_ADDR(fup->fu_prom, sizeof(Fore_prom),
293 if (fup->fu_promd == NULL) {
294 fup->fu_stats->st_drv.drv_cm_nodma++;
297 cqp->cmdq_prom.prom_buffer = (CP_dma) CP_WRITE(fup->fu_promd);
298 cqp->cmdq_prom.prom_cmd = CP_WRITE(CMD_GET_PROM | CMD_INTR_REQ);
304 fup->fu_stats->st_drv.drv_cm_full++;
309 #endif /* FORE_PCI */