[PATCH 2.6.13-rc5] rewrite drivers/scsi/cpqfcTScontrol.c::CpqTsGetSFQEntry

From: Rolf Eike Beer (eike-kernel_at_sf-tec.de)
Date: 08/09/05

  • Next message: Jiri Slaby: "Re: [PATCH -mm] removes pci_find_device from i6300esb.c"
    To: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
    Date:	Tue, 9 Aug 2005 18:06:43 +0200
    
    

    This patch applies on top of my previous one that removed the whitespace
    bloat.

    This patch now fixes the type horror in CpqTsGetSFQEntry():
    -the destination buffer is now void* instead of ULONG*
    -the offset is now done by a int (former ULONG) variable and not
     adding bytes to the pointer address
    -the last argument is not int, not boolean
    -the second argument is compared to ULONG but is USHORT. And one (of two)
     callers passes a ULONG casted to USHORT. Use ULONG instead.
    -remove some of the comments
    -don't use argument names in functions forward declaration: they don't match
     the actual names anyway

    While I'm at it, I fixed the coding style of this function. The rest of the
    file is is still horror, but this no excuse for not fixing this function.

    This shrinks the file by another 500 bytes and should not make any difference
    in function.

    Signed-off-by: Rolf Eike Beer <eike-kernel@sf-tec.de>

    --- 2.6.13-rc6/drivers/scsi/cpqfcTScontrol.c 2005-08-09 17:39:49.000000000 +0200
    +++ b/drivers/scsi/cpqfcTScontrol.c 2005-08-09 17:49:41.000000000 +0200
    @@ -52,8 +52,7 @@
     //#define IMQ_DEBUG 1
     
     static void fcParseLinkStatusCounters(TACHYON * fcChip);
    -static void CpqTsGetSFQEntry(TACHYON * fcChip,
    - USHORT pi, ULONG * buffr, BOOLEAN UpdateChip);
    +static void CpqTsGetSFQEntry(TACHYON *, ULONG, void*, int);
     
     static void
     cpqfc_free_dma_consistent(CPQFCHBA *cpqfcHBAdata)
    @@ -562,12 +561,11 @@ static int PeekIMQEntry( PTACHYON fcChip
               TachFCHDR_GCMND* fchs;
     #error This is too much stack
               ULONG ulFibreFrame[2048/4]; // max DWORDS in incoming FC Frame
    - USHORT SFQpi = (USHORT)(fcChip->IMQ->QEntry[CI].word[0] & 0x0fffL);
    + ULONG SFQpi = (fcChip->IMQ->QEntry[CI].word[0] & 0x0fffL);
     
               CpqTsGetSFQEntry( fcChip,
                 SFQpi, // SFQ producer ndx
    - ulFibreFrame, // contiguous dest. buffer
    - FALSE); // DON'T update chip--this is a "lookahead"
    + ulFibreFrame, 0); // DON'T update chip--this is a "lookahead"
     
               fchs = (TachFCHDR_GCMND*)&ulFibreFrame;
               if( fchs->pl[0] == ELS_LILP_FRAME)
    @@ -875,8 +873,8 @@ int CpqTsProcessIMQEntry(void *host)
               // clears SFQ entry from Tachyon buffer; copies to contiguous ulBuff
           CpqTsGetSFQEntry(
             fcChip, // i.e. this Device Object
    - (USHORT)fcChip->SFQ->producerIndex, // SFQ producer ndx
    - ulFibreFrame, TRUE); // contiguous destination buffer, update chip
    + fcChip->SFQ->producerIndex, // SFQ producer ndx
    + ulFibreFrame, 1); // contiguous destination buffer, update chip
     
             // analyze the incoming frame outside the INT handler...
             // (i.e., Worker)
    @@ -1739,57 +1737,54 @@ int CpqTsDestroyTachLiteQues( void *pHBA
       return iStatus; // non-zero (failed) if any memory not freed
     }
     
    -// The SFQ is an array with SFQ_LEN length, each element (QEntry)
    -// with eight 32-bit words. TachLite places incoming FC frames (i.e.
    -// a valid FC frame with our AL_PA ) in contiguous SFQ entries
    -// and sends a completion message telling the host where the frame is
    -// in the que.
    -// This function copies the current (or oldest not-yet-processed) QEntry to
    -// a caller's contiguous buffer and updates the Tachyon chip's consumer index
    -//
    -// NOTE:
    -// An FC frame may consume one or many SFQ entries. We know the total
    -// length from the completion message. The caller passes a buffer large
    -// enough for the complete message (max 2k).
    -
    -static void CpqTsGetSFQEntry(
    - PTACHYON fcChip,
    - USHORT producerNdx,
    - ULONG *ulDestPtr, // contiguous destination buffer
    - BOOLEAN UpdateChip)
    +/**
    + * CpqTsGetSFQEntry
    + * @dest: contiguous destination buffer
    + *
    + *The SFQ is an array with SFQ_LEN length, each element (QEntry)
    + * with eight 32-bit words. TachLite places incoming FC frames (i.e.
    + * a valid FC frame with our AL_PA ) in contiguous SFQ entries
    + * and sends a completion message telling the host where the frame is
    + * in the queue.
    + * This function copies the current (or oldest not-yet-processed) QEntry to
    + * a caller's contiguous buffer and updates the Tachyon chip's consumer index
    + *
    + * NOTE:
    + * An FC frame may consume one or many SFQ entries. We know the total
    + * length from the completion message. The caller passes a buffer large
    + * enough for the complete message (max 2k).
    + */
    +static void
    +CpqTsGetSFQEntry(PTACHYON fcChip, ULONG producerNdx, void *ulDestPtr,
    + int UpdateChip)
     {
    - ULONG total_bytes=0;
    - ULONG consumerIndex = fcChip->SFQ->consumerIndex;
    -
    - // check passed copy of SFQ producer index -
    - // is a new message waiting for us?
    - // equal indexes means SFS is copied
    + int total_bytes = 0;
    + ULONG consumerIndex = fcChip->SFQ->consumerIndex;
     
    - while( producerNdx != consumerIndex )
    - { // need to process message
    - total_bytes += 64; // maintain count to prevent writing past buffer
    - // don't allow copies over Fibre Channel defined length!
    - if( total_bytes <= 2048 )
    - {
    - memcpy(ulDestPtr,
    - &fcChip->SFQ->QEntry[consumerIndex],
    - 64 ); // each SFQ entry is 64 bytes
    - ulDestPtr += 16; // advance pointer to next 64 byte block
    - }
    - // Tachyon is producing,
    - // and we are consuming
    -
    - if( ++consumerIndex >= SFQ_LEN)// check for rollover
    - consumerIndex = 0L; // reset it
    - }
    + /* check passed copy of SFQ producer index -
    + * is a new message waiting for us?
    + * equal indexes means SFS is copied */
    +
    + while (producerNdx != consumerIndex) {
    + /* need to process message */
    + if(total_bytes < 2048) {
    + memcpy(ulDestPtr + total_bytes,
    + &fcChip->SFQ->QEntry[consumerIndex], 64);
    + }
    + /* each SFQ entry is 64 bytes */
    + total_bytes += 64;
    +
    + /* check for rollover */
    + if(++consumerIndex >= SFQ_LEN)
    + consumerIndex = 0;
    + }
     
    - // if specified, update the Tachlite chip ConsumerIndex...
    - if( UpdateChip )
    - {
    - fcChip->SFQ->consumerIndex = consumerIndex;
    - writel( fcChip->SFQ->consumerIndex,
    - fcChip->Registers.SFQconsumerIndex.address);
    - }
    + /* if specified, update the Tachlite chip ConsumerIndex */
    + if(UpdateChip) {
    + fcChip->SFQ->consumerIndex = consumerIndex;
    + writel(fcChip->SFQ->consumerIndex,
    + fcChip->Registers.SFQconsumerIndex.address);
    + }
     }
     
     // TachLite routinely freezes it's core ques - Outbound FIFO, Inbound FIFO,
    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/


  • Next message: Jiri Slaby: "Re: [PATCH -mm] removes pci_find_device from i6300esb.c"

    Relevant Pages

    • [PATCH] improve OProfile on many-way systems
      ... -static void timer_ping; ... +/* Take ownership of the task struct and place it on the ... Only after two full buffer syncs ... retrieving revision 1.2 ...
      (Linux-Kernel)
    • c6713 audio project
      ... I've decided for a major project to design a digital audio effects ... buffers are used ... PING buffer first, then the PONG buffer. ... void initMcbsp; ...
      (comp.dsp)
    • RFC/Doc/BUGs: CONFIG_PACKET_MMAP
      ... configurable circular buffer mapped in user space. ... circular buffer of unswapable memory mapped in the capture process. ... the name indicates, this function allocates pages of memory, it allocates a power ... There is another vector of pointers, wich hold references to each frame ...
      (Linux-Kernel)
    • Re: Im a C++ programmer, and Relfs X.CPP is good.
      ... void write_path(char* hm_path, char hm_buf); ... void list_contents(int argc, char** argv); ... Makes sure the user has specified an alpha buffer. ...
      (comp.unix.programmer)
    • Re: Streaming video over serial?
      ... In my specific scenario, where I'm not actually streaming video but an interactive application, quality actually trumps frame rate at about the 1Hz rate. ... I agree that for actual *usability* from an Apple client, dropping to lores would be great, but it's not necessary in this case. ... the Apple side it goes straight to frame buffer. ... to switch buffers and screens. ...
      (comp.sys.apple2.programmer)