[Linux1394-cvslog] rev 553 - trunk
Brought to you by:
aeb,
bencollins
From: SVN U. <hog...@li...> - 2002-08-25 17:50:59
|
Author: hogsberg Date: 2002-08-25 22:43:53 -0400 (Sun, 25 Aug 2002) New Revision: 553 Modified: trunk/ohci1394.c trunk/ohci1394.h Log: Minor cleanup: embed dma_rcv_ctx and dma_trm_ctx structs in struct ti_ohci - fewer kmallocs, fewer null-checks, less fragmentation. Modified: trunk/ohci1394.c ============================================================================== --- trunk/ohci1394.c (original) +++ trunk/ohci1394.c 2002-08-25 22:43:54.000000000 -0400 @@ -569,18 +569,18 @@ reg_write(ohci, OHCI1394_IRMultiChanMaskLoClear, 0xffffffff); /* Initialize AR dma */ - initialize_dma_rcv_ctx(ohci->ar_req_context, 0); - initialize_dma_rcv_ctx(ohci->ar_resp_context, 0); + initialize_dma_rcv_ctx(&ohci->ar_req_context, 0); + initialize_dma_rcv_ctx(&ohci->ar_resp_context, 0); /* Initialize AT dma */ - initialize_dma_trm_ctx(ohci->at_req_context); - initialize_dma_trm_ctx(ohci->at_resp_context); + initialize_dma_trm_ctx(&ohci->at_req_context); + initialize_dma_trm_ctx(&ohci->at_resp_context); /* Initialize IR dma */ - initialize_dma_rcv_ctx(ohci->ir_context, 1); + initialize_dma_rcv_ctx(&ohci->ir_context, 1); /* Initialize IT dma */ - initialize_dma_trm_ctx(ohci->it_context); + initialize_dma_trm_ctx(&ohci->it_context); /* Set up isoRecvIntMask to generate interrupts for context 0 (thanks to Michael Greger for seeing that I forgot this) */ @@ -854,9 +854,9 @@ /* Decide wether we have an iso, a request, or a response packet */ tcode = (packet->header[0]>>4)&0xf; - if (tcode == TCODE_ISO_DATA) d = ohci->it_context; - else if (tcode & 0x02) d = ohci->at_resp_context; - else d = ohci->at_req_context; + if (tcode == TCODE_ISO_DATA) d = &ohci->it_context; + else if (tcode & 0x02) d = &ohci->at_resp_context; + else d = &ohci->at_req_context; spin_lock_irqsave(&d->lock,flags); @@ -914,8 +914,8 @@ case CANCEL_REQUESTS: DBGMSG(ohci->id, "Cancel request received"); - dma_trm_reset(ohci->at_req_context); - dma_trm_reset(ohci->at_resp_context); + dma_trm_reset(&ohci->at_req_context); + dma_trm_reset(&ohci->at_resp_context); break; case MODIFY_USAGE: @@ -1120,7 +1120,7 @@ * we get sent acks before response packets. This sucks mainly * because it halts the interrupt handler. */ if (event & OHCI1394_reqTxComplete) { - struct dma_trm_ctx *d = ohci->at_req_context; + struct dma_trm_ctx *d = &ohci->at_req_context; DBGMSG(ohci->id, "Got reqTxComplete interrupt " "status=0x%08X", reg_read(ohci, d->ctrlSet)); if (reg_read(ohci, d->ctrlSet) & 0x800) @@ -1131,7 +1131,7 @@ event &= ~OHCI1394_reqTxComplete; } if (event & OHCI1394_respTxComplete) { - struct dma_trm_ctx *d = ohci->at_resp_context; + struct dma_trm_ctx *d = &ohci->at_resp_context; DBGMSG(ohci->id, "Got respTxComplete interrupt " "status=0x%08X", reg_read(ohci, d->ctrlSet)); if (reg_read(ohci, d->ctrlSet) & 0x800) @@ -1142,7 +1142,7 @@ event &= ~OHCI1394_respTxComplete; } if (event & OHCI1394_RQPkt) { - struct dma_rcv_ctx *d = ohci->ar_req_context; + struct dma_rcv_ctx *d = &ohci->ar_req_context; DBGMSG(ohci->id, "Got RQPkt interrupt status=0x%08X", reg_read(ohci, d->ctrlSet)); if (reg_read(ohci, d->ctrlSet) & 0x800) @@ -1152,7 +1152,7 @@ event &= ~OHCI1394_RQPkt; } if (event & OHCI1394_RSPkt) { - struct dma_rcv_ctx *d = ohci->ar_resp_context; + struct dma_rcv_ctx *d = &ohci->ar_resp_context; DBGMSG(ohci->id, "Got RSPkt interrupt status=0x%08X", reg_read(ohci, d->ctrlSet)); if (reg_read(ohci, d->ctrlSet) & 0x800) @@ -1163,7 +1163,7 @@ } if (event & OHCI1394_isochRx) { quadlet_t isoRecvIntEvent; - struct dma_rcv_ctx *d = ohci->ir_context; + struct dma_rcv_ctx *d = &ohci->ir_context; isoRecvIntEvent = reg_read(ohci, OHCI1394_IsoRecvIntEventSet); reg_write(ohci, OHCI1394_IsoRecvIntEventClear, @@ -1185,7 +1185,7 @@ } if (event & OHCI1394_isochTx) { quadlet_t isoXmitIntEvent; - struct dma_trm_ctx *d = ohci->it_context; + struct dma_trm_ctx *d = &ohci->it_context; isoXmitIntEvent = reg_read(ohci, OHCI1394_IsoXmitIntEventSet); reg_write(ohci, OHCI1394_IsoXmitIntEventClear, @@ -1563,80 +1563,63 @@ spin_unlock_irqrestore(&d->lock, flags); } -static int free_dma_rcv_ctx(struct dma_rcv_ctx **d) +static void free_dma_rcv_ctx(struct dma_rcv_ctx *d) { int i; struct ti_ohci *ohci; - if (*d==NULL) return -1; + ohci = d->ohci; - ohci = (struct ti_ohci *)(*d)->ohci; - - DBGMSG(ohci->id, "Freeing dma_rcv_ctx %d",(*d)->ctx); + DBGMSG(ohci->id, "Freeing dma_rcv_ctx %d", d->ctx); - ohci1394_stop_context(ohci, (*d)->ctrlClear, NULL); + ohci1394_stop_context(ohci, d->ctrlClear, NULL); - tasklet_kill(&(*d)->task); + tasklet_kill(&d->task); - if ((*d)->buf_cpu) { - for (i=0; i<(*d)->num_desc; i++) - if ((*d)->buf_cpu[i] && (*d)->buf_bus[i]) { + if (d->buf_cpu) { + for (i=0; i<d->num_desc; i++) + if (d->buf_cpu[i] && d->buf_bus[i]) { pci_free_consistent( - ohci->dev, (*d)->buf_size, - (*d)->buf_cpu[i], (*d)->buf_bus[i]); + ohci->dev, d->buf_size, + d->buf_cpu[i], d->buf_bus[i]); OHCI_DMA_FREE("consistent dma_rcv buf[%d]", i); } - kfree((*d)->buf_cpu); - kfree((*d)->buf_bus); + kfree(d->buf_cpu); + kfree(d->buf_bus); } - if ((*d)->prg_cpu) { - for (i=0; i<(*d)->num_desc; i++) - if ((*d)->prg_cpu[i] && (*d)->prg_bus[i]) { + if (d->prg_cpu) { + for (i=0; i<d->num_desc; i++) + if (d->prg_cpu[i] && d->prg_bus[i]) { pci_free_consistent( ohci->dev, sizeof(struct dma_cmd), - (*d)->prg_cpu[i], (*d)->prg_bus[i]); + d->prg_cpu[i], d->prg_bus[i]); OHCI_DMA_FREE("consistent dma_rcv prg[%d]", i); } - kfree((*d)->prg_cpu); - kfree((*d)->prg_bus); + kfree(d->prg_cpu); + kfree(d->prg_bus); } - if ((*d)->spb) kfree((*d)->spb); + if (d->spb) kfree(d->spb); /* clear ISO context usage bit */ - if ((*d)->type == DMA_CTX_ISO) { - clear_bit((*d)->ctx, &ohci->ir_ctx_usage); - } - - kfree(*d); - *d = NULL; - - return 0; + if (d->type == DMA_CTX_ISO) + clear_bit(d->ctx, &ohci->ir_ctx_usage); } -static struct dma_rcv_ctx * -alloc_dma_rcv_ctx(struct ti_ohci *ohci, enum context_type type, int ctx, int num_desc, +static int +alloc_dma_rcv_ctx(struct ti_ohci *ohci, struct dma_rcv_ctx *d, + enum context_type type, int ctx, int num_desc, int buf_size, int split_buf_size, int context_base) { - struct dma_rcv_ctx *d; int i; if (type == DMA_CTX_ISO) { /* try to claim the ISO context usage bit */ if (test_and_set_bit(ctx, &ohci->ir_ctx_usage)) { PRINT(KERN_ERR, ohci->id, "IR DMA context %d is not available", ctx); - return NULL; + return -EBUSY; } } - d = kmalloc(sizeof(struct dma_rcv_ctx), GFP_KERNEL); - - if (d == NULL) { - PRINT(KERN_ERR, ohci->id, "Failed to allocate dma_rcv_ctx"); - return NULL; - } - - memset (d, 0, sizeof (struct dma_rcv_ctx)); - d->ohci = ohci; d->type = type; d->ctx = ctx; @@ -1654,8 +1637,8 @@ if (d->buf_cpu == NULL || d->buf_bus == NULL) { PRINT(KERN_ERR, ohci->id, "Failed to allocate dma buffer"); - free_dma_rcv_ctx(&d); - return NULL; + free_dma_rcv_ctx(d); + return -ENOMEM; } memset(d->buf_cpu, 0, d->num_desc * sizeof(quadlet_t*)); memset(d->buf_bus, 0, d->num_desc * sizeof(dma_addr_t)); @@ -1666,8 +1649,8 @@ if (d->prg_cpu == NULL || d->prg_bus == NULL) { PRINT(KERN_ERR, ohci->id, "Failed to allocate dma prg"); - free_dma_rcv_ctx(&d); - return NULL; + free_dma_rcv_ctx(d); + return -ENOMEM; } memset(d->prg_cpu, 0, d->num_desc * sizeof(struct dma_cmd*)); memset(d->prg_bus, 0, d->num_desc * sizeof(dma_addr_t)); @@ -1676,8 +1659,8 @@ if (d->spb == NULL) { PRINT(KERN_ERR, ohci->id, "Failed to allocate split buffer"); - free_dma_rcv_ctx(&d); - return NULL; + free_dma_rcv_ctx(d); + return -ENOMEM; } for (i=0; i<d->num_desc; i++) { @@ -1691,8 +1674,8 @@ } else { PRINT(KERN_ERR, ohci->id, "Failed to allocate dma buffer"); - free_dma_rcv_ctx(&d); - return NULL; + free_dma_rcv_ctx(d); + return -ENOMEM; } @@ -1706,8 +1689,8 @@ } else { PRINT(KERN_ERR, ohci->id, "Failed to allocate dma prg"); - free_dma_rcv_ctx(&d); - return NULL; + free_dma_rcv_ctx(d); + return -ENOMEM; } } @@ -1716,70 +1699,54 @@ /* initialize tasklet */ tasklet_init (&d->task, dma_rcv_tasklet, (unsigned long)d); - return d; + return 0; } -static int free_dma_trm_ctx(struct dma_trm_ctx **d) +static void free_dma_trm_ctx(struct dma_trm_ctx *d) { struct ti_ohci *ohci; int i; - if (*d==NULL) return -1; - - ohci = (struct ti_ohci *)(*d)->ohci; + ohci = d->ohci; - DBGMSG(ohci->id, "Freeing dma_trm_ctx %d",(*d)->ctx); + DBGMSG(ohci->id, "Freeing dma_trm_ctx %d", d->ctx); - ohci1394_stop_context(ohci, (*d)->ctrlClear, NULL); + ohci1394_stop_context(ohci, d->ctrlClear, NULL); - tasklet_kill(&(*d)->task); + tasklet_kill(&d->task); - if ((*d)->prg_cpu) { - for (i=0; i<(*d)->num_desc; i++) - if ((*d)->prg_cpu[i] && (*d)->prg_bus[i]) { + if (d->prg_cpu) { + for (i=0; i<d->num_desc; i++) + if (d->prg_cpu[i] && d->prg_bus[i]) { pci_free_consistent( ohci->dev, sizeof(struct at_dma_prg), - (*d)->prg_cpu[i], (*d)->prg_bus[i]); + d->prg_cpu[i], d->prg_bus[i]); OHCI_DMA_FREE("consistent dma_trm prg[%d]", i); } - kfree((*d)->prg_cpu); - kfree((*d)->prg_bus); + kfree(d->prg_cpu); + kfree(d->prg_bus); } /* clear the ISO context usage bit */ - if ((*d)->type == DMA_CTX_ISO) { - clear_bit((*d)->ctx, &ohci->it_ctx_usage); - } - - kfree(*d); - *d = NULL; - return 0; + if (d->type == DMA_CTX_ISO) + clear_bit(d->ctx, &ohci->it_ctx_usage); } -static struct dma_trm_ctx * -alloc_dma_trm_ctx(struct ti_ohci *ohci, enum context_type type, int ctx, int num_desc, +static int +alloc_dma_trm_ctx(struct ti_ohci *ohci, struct dma_trm_ctx *d, + enum context_type type, int ctx, int num_desc, int context_base) { - struct dma_trm_ctx *d; int i; if (type == DMA_CTX_ISO) { /* try to claim the ISO context usage bit */ if (test_and_set_bit(ctx, &ohci->it_ctx_usage)) { PRINT(KERN_ERR, ohci->id, "IT DMA context %d is not available", ctx); - return NULL; + return -EBUSY; } } - d = kmalloc(sizeof(struct dma_trm_ctx), GFP_KERNEL); - - if (d == NULL) { - PRINT(KERN_ERR, ohci->id, "Failed to allocate dma_trm_ctx"); - return NULL; - } - - memset (d, 0, sizeof (struct dma_trm_ctx)); - d->ohci = ohci; d->type = type; d->ctx = ctx; @@ -1794,8 +1761,8 @@ if (d->prg_cpu == NULL || d->prg_bus == NULL) { PRINT(KERN_ERR, ohci->id, "Failed to allocate at dma prg"); - free_dma_trm_ctx(&d); - return NULL; + free_dma_trm_ctx(d); + return -ENOMEM; } memset(d->prg_cpu, 0, d->num_desc * sizeof(struct at_dma_prg*)); memset(d->prg_bus, 0, d->num_desc * sizeof(dma_addr_t)); @@ -1811,8 +1778,8 @@ } else { PRINT(KERN_ERR, ohci->id, "Failed to allocate at dma prg"); - free_dma_trm_ctx(&d); - return NULL; + free_dma_trm_ctx(d); + return -ENOMEM; } } @@ -1821,7 +1788,7 @@ /* initialize bottom handler */ tasklet_init (&d->task, dma_trm_tasklet, (unsigned long)d); - return d; + return 0; } static u16 ohci_crc16 (u32 *ptr, int length) @@ -2115,58 +2082,46 @@ ohci->init_state = OHCI_INIT_HAVE_TXRX_BUFFERS__MAYBE; /* AR DMA request context allocation */ - ohci->ar_req_context = - alloc_dma_rcv_ctx(ohci, DMA_CTX_ASYNC_REQ, 0, AR_REQ_NUM_DESC, - AR_REQ_BUF_SIZE, AR_REQ_SPLIT_BUF_SIZE, - OHCI1394_AsReqRcvContextBase); - - if (ohci->ar_req_context == NULL) + if (alloc_dma_rcv_ctx(ohci, &ohci->ar_req_context, + DMA_CTX_ASYNC_REQ, 0, AR_REQ_NUM_DESC, + AR_REQ_BUF_SIZE, AR_REQ_SPLIT_BUF_SIZE, + OHCI1394_AsReqRcvContextBase) < 0) FAIL(-ENOMEM, "Failed to allocate AR Req context"); /* AR DMA response context allocation */ - ohci->ar_resp_context = - alloc_dma_rcv_ctx(ohci, DMA_CTX_ASYNC_RESP, 0, AR_RESP_NUM_DESC, - AR_RESP_BUF_SIZE, AR_RESP_SPLIT_BUF_SIZE, - OHCI1394_AsRspRcvContextBase); - - if (ohci->ar_resp_context == NULL) + if (alloc_dma_rcv_ctx(ohci, &ohci->ar_resp_context, + DMA_CTX_ASYNC_RESP, 0, AR_RESP_NUM_DESC, + AR_RESP_BUF_SIZE, AR_RESP_SPLIT_BUF_SIZE, + OHCI1394_AsRspRcvContextBase) < 0) FAIL(-ENOMEM, "Failed to allocate AR Resp context"); /* AT DMA request context */ - ohci->at_req_context = - alloc_dma_trm_ctx(ohci, DMA_CTX_ASYNC_REQ, 0, AT_REQ_NUM_DESC, - OHCI1394_AsReqTrContextBase); - - if (ohci->at_req_context == NULL) + if (alloc_dma_trm_ctx(ohci, &ohci->at_req_context, + DMA_CTX_ASYNC_REQ, 0, AT_REQ_NUM_DESC, + OHCI1394_AsReqTrContextBase) < 0) FAIL(-ENOMEM, "Failed to allocate AT Req context"); /* AT DMA response context */ - ohci->at_resp_context = - alloc_dma_trm_ctx(ohci, DMA_CTX_ASYNC_RESP, 1, AT_RESP_NUM_DESC, - OHCI1394_AsRspTrContextBase); - - if (ohci->at_resp_context == NULL) + if (alloc_dma_trm_ctx(ohci, &ohci->at_resp_context, + DMA_CTX_ASYNC_RESP, 1, AT_RESP_NUM_DESC, + OHCI1394_AsRspTrContextBase) < 0) FAIL(-ENOMEM, "Failed to allocate AT Resp context"); ohci->ir_ctx_usage = 0; ohci->it_ctx_usage = 0; /* IR DMA context */ - ohci->ir_context = - alloc_dma_rcv_ctx(ohci, DMA_CTX_ISO, 0, IR_NUM_DESC, - IR_BUF_SIZE, IR_SPLIT_BUF_SIZE, - OHCI1394_IsoRcvContextBase); - - if (ohci->ir_context == NULL) + if (alloc_dma_rcv_ctx(ohci, &ohci->ir_context, + DMA_CTX_ISO, 0, IR_NUM_DESC, + IR_BUF_SIZE, IR_SPLIT_BUF_SIZE, + OHCI1394_IsoRcvContextBase) < 0) FAIL(-ENOMEM, "Failed to allocate IR context"); /* IT DMA context allocation */ - ohci->it_context = - alloc_dma_trm_ctx(ohci, DMA_CTX_ISO, 0, IT_NUM_DESC, - OHCI1394_IsoXmitContextBase); - - if (ohci->it_context == NULL) + if (alloc_dma_trm_ctx(ohci, &ohci->it_context, + DMA_CTX_ISO, 0, IT_NUM_DESC, + OHCI1394_IsoXmitContextBase) < 0) FAIL(-ENOMEM, "Failed to allocate IT context"); ohci->ISO_channel_usage = 0; Modified: trunk/ohci1394.h ============================================================================== --- trunk/ohci1394.h (original) +++ trunk/ohci1394.h 2002-08-25 22:43:54.000000000 -0400 @@ -170,21 +170,21 @@ unsigned int max_packet_size; /* async receive */ - struct dma_rcv_ctx *ar_resp_context; - struct dma_rcv_ctx *ar_req_context; + struct dma_rcv_ctx ar_resp_context; + struct dma_rcv_ctx ar_req_context; /* async transmit */ - struct dma_trm_ctx *at_resp_context; - struct dma_trm_ctx *at_req_context; + struct dma_trm_ctx at_resp_context; + struct dma_trm_ctx at_req_context; /* iso receive */ - struct dma_rcv_ctx *ir_context; + struct dma_rcv_ctx ir_context; spinlock_t IR_channel_lock; int nb_iso_rcv_ctx; unsigned long ir_ctx_usage; /* use test_and_set_bit() for atomicity */ /* iso transmit */ - struct dma_trm_ctx *it_context; + struct dma_trm_ctx it_context; int nb_iso_xmit_ctx; unsigned long it_ctx_usage; /* use test_and_set_bit() for atomicity */ |