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_command.c,v 1.6 1999/08/28 00:41:49 peter Exp $
27 * @(#) $DragonFly: src/sys/dev/atm/hfa/fore_command.c,v 1.6 2008/03/01 22:03:13 swildner Exp $
31 * FORE Systems 200-Series Adapter Support
32 * ---------------------------------------
34 * Command queue management
38 #include "fore_include.h"
43 static struct t_atm_cause fore_cause = {
46 T_ATM_CAUSE_TEMPORARY_FAILURE,
52 * Allocate Command Queue Data Structures
55 * fup pointer to device unit structure
58 * 0 allocations successful
59 * else allocation failed
62 fore_cmd_allocate(Fore_unit *fup)
67 * Allocate non-cacheable memory for command status words
69 memp = atm_dev_alloc(sizeof(Q_status) * CMD_QUELEN,
70 QSTAT_ALIGN, ATM_DEV_NONCACHE);
74 fup->fu_cmd_stat = (Q_status *) memp;
76 memp = DMA_GET_ADDR(fup->fu_cmd_stat, sizeof(Q_status) * CMD_QUELEN,
77 QSTAT_ALIGN, ATM_DEV_NONCACHE);
81 fup->fu_cmd_statd = (Q_status *) memp;
84 * Allocate memory for statistics buffer
86 memp = atm_dev_alloc(sizeof(Fore_stats), FORE_STATS_ALIGN, 0);
90 fup->fu_stats = (Fore_stats *) memp;
93 * Allocate memory for PROM buffer
95 memp = atm_dev_alloc(sizeof(Fore_prom), FORE_PROM_ALIGN, 0);
99 fup->fu_prom = (Fore_prom *) memp;
106 * Command Queue Initialization
108 * Allocate and initialize the host-resident command queue structures
109 * and then initialize the CP-resident queue structures.
111 * Called at interrupt level.
114 * fup pointer to device unit structure
120 fore_cmd_initialize(Fore_unit *fup)
122 Aali *aap = fup->fu_aali;
130 * Point to CP-resident command queue
132 cqp = (Cmd_queue *)(fup->fu_ram + CP_READ(aap->aali_cmd_q));
135 * Point to host-resident command queue structures
138 qsp = fup->fu_cmd_stat;
139 qsp_dma = fup->fu_cmd_statd;
142 * Loop thru all queue entries and do whatever needs doing
144 for (i = 0; i < CMD_QUELEN; i++) {
147 * Set queue status word to free
152 * Set up host queue entry and link into ring
154 hcp->hcq_cpelem = cqp;
155 hcp->hcq_status = qsp;
156 if (i == (CMD_QUELEN - 1))
157 hcp->hcq_next = fup->fu_cmd_q;
159 hcp->hcq_next = hcp + 1;
162 * Now let the CP into the game
164 cqp->cmdq_status = (CP_dma) CP_WRITE(qsp_dma);
167 * Bump all queue pointers
176 * Initialize queue pointers
178 fup->fu_cmd_head = fup->fu_cmd_tail = fup->fu_cmd_q;
185 * Drain Command Queue
187 * This function will process and free all completed entries at the head
188 * of the command queue.
190 * May be called in interrupt state.
191 * Must be called with interrupts locked out.
194 * fup pointer to device unit structure
200 fore_cmd_drain(Fore_unit *fup)
206 * Process each completed entry
208 while (*fup->fu_cmd_head->hcq_status & QSTAT_COMPLETED) {
210 hcp = fup->fu_cmd_head;
213 * Process command completion
215 switch (hcp->hcq_code) {
220 if (*hcp->hcq_status & QSTAT_ERROR) {
222 * VCC activation failed - just abort vcc
225 atm_cm_abort(fvp->fv_connvc,
227 fup->fu_pif.pif_cmderrors++;
230 * Successful VCC activation
233 fvp->fv_state = CVS_ACTIVE;
240 case CMD_DACT_VCCOUT:
242 if (*hcp->hcq_status & QSTAT_ERROR) {
244 * VCC dactivation failed - whine
247 "fore_cmd_drain: DACT failed, vcc=(%d,%d)\n",
248 fvp->fv_connvc->cvc_vcc->vc_vpi,
249 fvp->fv_connvc->cvc_vcc->vc_vci);
250 fup->fu_pif.pif_cmderrors++;
253 * Successful VCC dactivation - so what?
259 if (*hcp->hcq_status & QSTAT_ERROR) {
263 fup->fu_pif.pif_cmderrors++;
264 fup->fu_stats_ret = EIO;
267 * Stats are now in unit buffer
269 fup->fu_stats_ret = 0;
271 DMA_FREE_ADDR(fup->fu_stats, fup->fu_statsd,
272 sizeof(Fore_cp_stats), 0);
273 fup->fu_flags &= ~FUF_STATCMD;
276 * Flush received stats data
280 vac_pageflush((addr_t)fup->fu_stats);
283 #if BYTE_ORDER == LITTLE_ENDIAN
285 * Little endian machines receives the stats in
286 * wrong byte order. Instead of swapping in user
287 * land, swap here so that everything going out
288 * of the kernel is in correct host order.
291 u_long *bp = (u_long *)fup->fu_stats;
294 for ( loop = 0; loop < sizeof(Fore_cp_stats)/
295 sizeof(long); loop++, bp++ )
298 #endif /* BYTE_ORDER == LITTLE_ENDIAN */
301 * Poke whoever is waiting on the stats
303 wakeup((caddr_t)&fup->fu_stats);
307 if (*hcp->hcq_status & QSTAT_ERROR) {
309 * Couldn't get PROM data
311 fup->fu_pif.pif_cmderrors++;
313 "fore_cmd_drain: %s%d: GET_PROM failed\n",
314 fup->fu_pif.pif_name,
315 fup->fu_pif.pif_unit);
317 Fore_prom *fp = fup->fu_prom;
320 * Flush received PROM data
324 vac_pageflush((addr_t)fp);
327 * Copy PROM info into config areas
329 KM_COPY(&fp->pr_mac[2],
330 &fup->fu_pif.pif_macaddr,
331 sizeof(struct mac_addr));
332 fup->fu_config.ac_macaddr =
333 fup->fu_pif.pif_macaddr;
334 ksnprintf(fup->fu_config.ac_hard_vers,
335 sizeof(fup->fu_config.ac_hard_vers),
337 (fp->pr_hwver >> 16) & 0xff,
338 (fp->pr_hwver >> 8) & 0xff,
339 fp->pr_hwver & 0xff);
340 fup->fu_config.ac_serial = fp->pr_serno;
343 DMA_FREE_ADDR(fup->fu_prom, fup->fu_promd,
344 sizeof(Fore_prom), 0);
348 log(LOG_ERR, "fore_cmd_drain: unknown command %ld\n",
353 * Mark this entry free for use and bump head pointer
354 * to the next entry in the queue
356 *hcp->hcq_status = QSTAT_FREE;
357 fup->fu_cmd_head = hcp->hcq_next;
365 * Free Command Queue Data Structures
368 * fup pointer to device unit structure
374 fore_cmd_free(Fore_unit *fup)
379 * Deal with any commands left on the queue
381 if (fup->fu_flags & CUF_INITED) {
382 while (*fup->fu_cmd_head->hcq_status != QSTAT_FREE) {
383 hcp = fup->fu_cmd_head;
385 switch (hcp->hcq_code) {
389 * Just in case someone is sleeping on this
391 fup->fu_stats_ret = EIO;
392 wakeup((caddr_t)&fup->fu_stats);
396 *hcp->hcq_status = QSTAT_FREE;
397 fup->fu_cmd_head = hcp->hcq_next;
402 * Free the statistics buffer
405 atm_dev_free(fup->fu_stats);
406 fup->fu_stats = NULL;
410 * Free the PROM buffer
413 atm_dev_free(fup->fu_prom);
418 * Free the status words
420 if (fup->fu_cmd_stat) {
421 if (fup->fu_cmd_statd) {
422 DMA_FREE_ADDR(fup->fu_cmd_stat, fup->fu_cmd_statd,
423 sizeof(Q_status) * CMD_QUELEN,
426 atm_dev_free((volatile void *)fup->fu_cmd_stat);
427 fup->fu_cmd_stat = NULL;
428 fup->fu_cmd_statd = NULL;