Print this page
NEX-5733 cleanup qlt/qlc
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Reviewed by: Alek Pinchuk <alek.pinchuk@nexenta.com>
NEX-5717 import QLogic 16G FC drivers
Reviewed by: Steve Peng <steve.peng@nexenta.com>
Reviewed by: Josef 'Jeff' Sipek <josef.sipek@nexenta.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>


   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2009 QLogic Corporation.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 /*
  28  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  29  */
  30 
  31 #include <sys/conf.h>
  32 #include <sys/ddi.h>
  33 #include <sys/sunddi.h>
  34 #include <sys/modctl.h>
  35 
  36 #include <sys/stmf_defines.h>
  37 #include <sys/fct_defines.h>
  38 #include <sys/stmf.h>
  39 #include <sys/portif.h>
  40 #include <sys/fct.h>
  41 
  42 #include "qlt.h"
  43 #include "qlt_dma.h"
  44 
  45 /*
  46  *  Local Function Prototypes.
  47  */
  48 static void


 197         while (bc) {
 198                 stmf_free(bc->bctl_buf);
 199                 bc = bc->bctl_next;
 200         }
 201 dmem_init_failed:;
 202         (void) ddi_dma_unbind_handle(p->dmem_dma_handle);
 203 addr_bind_handle_failed:;
 204         ddi_dma_mem_free(&p->dmem_acc_handle);
 205 mem_alloc_failed:;
 206         ddi_dma_free_handle(&p->dmem_dma_handle);
 207 alloc_handle_failed:;
 208         kmem_free(p->dmem_bctls_mem, p->dmem_nbufs * sizeof (qlt_dmem_bctl_t));
 209         mutex_destroy(&p->dmem_lock);
 210 alloc_bctl_failed:;
 211         if (--ndx >= 0) {
 212                 p = qlt->dmem_buckets[ndx];
 213                 bctl = p->dmem_bctl_free_list;
 214                 goto dmem_failure_loop;
 215         }
 216         kmem_free(qlt->dmem_buckets, sizeof (dmem_buckets) +
 217             ((sizeof (dmem_buckets)/sizeof (void *))
 218             *sizeof (qlt_dmem_bucket_t)));
 219         qlt->dmem_buckets = NULL;
 220 
 221         return (QLT_FAILURE);
 222 }
 223 
 224 void
 225 qlt_dma_handle_pool_init(qlt_state_t *qlt)
 226 {
 227         qlt_dma_handle_pool_t *pool;
 228 
 229         pool = kmem_zalloc(sizeof (*pool), KM_SLEEP);
 230         mutex_init(&pool->pool_lock, NULL, MUTEX_DRIVER, NULL);
 231         qlt->qlt_dma_handle_pool = pool;
 232 }
 233 
 234 void
 235 qlt_dma_handle_pool_fini(qlt_state_t *qlt)
 236 {
 237         qlt_dma_handle_pool_t   *pool;
 238         qlt_dma_handle_t        *handle, *next_handle;


 546 {
 547         qlt_dma_handle_pool_t *pool;
 548         qlt_dma_handle_t *tmp_handle, *last_handle;
 549         int rv, handle_count;
 550 
 551         /*
 552          * Traverse the list and unbind the handles
 553          */
 554         ASSERT(first_handle);
 555         tmp_handle = first_handle;
 556         handle_count = 0;
 557         while (tmp_handle != NULL) {
 558                 last_handle = tmp_handle;
 559                 /*
 560                  * If the handle is bound, unbind the handle so it can be
 561                  * reused. It may not be bound if there was a bind failure.
 562                  */
 563                 if (tmp_handle->num_cookies != 0) {
 564                         rv = ddi_dma_unbind_handle(tmp_handle->dma_handle);
 565                         ASSERT(rv == DDI_SUCCESS);

 566                         tmp_handle->num_cookies = 0;
 567                         tmp_handle->num_cookies_fetched = 0;
 568                 }

 569                 tmp_handle = tmp_handle->next;
 570                 handle_count++;
 571         }
 572         /*
 573          * Insert this list into the free list
 574          */
 575         pool = qlt->qlt_dma_handle_pool;
 576         mutex_enter(&pool->pool_lock);
 577         last_handle->next = pool->free_list;
 578         pool->free_list = first_handle;
 579         pool->num_free += handle_count;
 580         mutex_exit(&pool->pool_lock);
 581 }
 582 
 583 /*
 584  * cookies produced by mapping this dbuf
 585  */
 586 uint16_t
 587 qlt_get_cookie_count(stmf_data_buf_t *dbuf)
 588 {


 629                 if (fetch->num_cookies_fetched == 0) {
 630                         *cookiep = fetch->first_cookie;
 631                 } else {
 632                         ddi_dma_nextcookie(fetch->dma_handle, cookiep);
 633                 }
 634                 if (++fetch->num_cookies_fetched == fetch->num_cookies) {
 635                         if (fetch->next == NULL)
 636                                 qsgl->handle_next_fetch = FETCH_DONE;
 637                         else
 638                                 qsgl->handle_next_fetch = fetch->next;
 639                 }
 640         }
 641 }
 642 
 643 /*
 644  * Set this flag to fetch the DDI dma cookies from the handles here and
 645  * store them in the port private area of the dbuf. This will allow
 646  * faster access to the cookies in qlt_xfer_scsi_data() at the expense of
 647  * an extra copy. If the qlt->req_lock is hot, this may help.
 648  */
 649 int qlt_sgl_prefetch = 0;
 650 
 651 /*ARGSUSED*/
 652 stmf_status_t
 653 qlt_dma_setup_dbuf(fct_local_port_t *port, stmf_data_buf_t *dbuf,
 654     uint32_t flags)
 655 {
 656         qlt_state_t             *qlt = port->port_fca_private;
 657         qlt_dma_sgl_t           *qsgl;
 658         struct stmf_sglist_ent  *sglp;
 659         qlt_dma_handle_t        *handle_list, *th;
 660         int                     i, rv;
 661         ddi_dma_cookie_t        *cookie_p;
 662         int                     cookie_count, numbufs;
 663         int                     prefetch;

 664         size_t                  qsize;
 665 
 666         /*
 667          * psuedo code:
 668          * get dma handle list from cache - one per sglist entry
 669          * foreach sglist entry
 670          *      bind dma handle to sglist vaddr
 671          * allocate space for DMA state to store in db_port_private
 672          * fill in port private object
 673          * if prefetching
 674          *      move all dma cookies into db_port_private
 675          */
 676         dbuf->db_port_private = NULL;
 677         numbufs = dbuf->db_sglist_length;
 678         handle_list = qlt_dma_alloc_handle_list(qlt, numbufs);
 679         if (handle_list == NULL) {
 680                 EL(qlt, "handle_list==NULL\n");
 681                 return (STMF_FAILURE);
 682         }
 683         /*




   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2009-2015 QLogic Corporation.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 /*
  28  * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
  29  */
  30 
  31 #include <sys/conf.h>
  32 #include <sys/ddi.h>
  33 #include <sys/sunddi.h>
  34 #include <sys/modctl.h>
  35 
  36 #include <sys/stmf_defines.h>
  37 #include <sys/fct_defines.h>
  38 #include <sys/stmf.h>
  39 #include <sys/portif.h>
  40 #include <sys/fct.h>
  41 
  42 #include "qlt.h"
  43 #include "qlt_dma.h"
  44 
  45 /*
  46  *  Local Function Prototypes.
  47  */
  48 static void


 197         while (bc) {
 198                 stmf_free(bc->bctl_buf);
 199                 bc = bc->bctl_next;
 200         }
 201 dmem_init_failed:;
 202         (void) ddi_dma_unbind_handle(p->dmem_dma_handle);
 203 addr_bind_handle_failed:;
 204         ddi_dma_mem_free(&p->dmem_acc_handle);
 205 mem_alloc_failed:;
 206         ddi_dma_free_handle(&p->dmem_dma_handle);
 207 alloc_handle_failed:;
 208         kmem_free(p->dmem_bctls_mem, p->dmem_nbufs * sizeof (qlt_dmem_bctl_t));
 209         mutex_destroy(&p->dmem_lock);
 210 alloc_bctl_failed:;
 211         if (--ndx >= 0) {
 212                 p = qlt->dmem_buckets[ndx];
 213                 bctl = p->dmem_bctl_free_list;
 214                 goto dmem_failure_loop;
 215         }
 216         kmem_free(qlt->dmem_buckets, sizeof (dmem_buckets) +
 217             (((sizeof (dmem_buckets)/sizeof (void *))-1)*
 218             sizeof (qlt_dmem_bucket_t)));
 219         qlt->dmem_buckets = NULL;
 220 
 221         return (QLT_FAILURE);
 222 }
 223 
 224 void
 225 qlt_dma_handle_pool_init(qlt_state_t *qlt)
 226 {
 227         qlt_dma_handle_pool_t *pool;
 228 
 229         pool = kmem_zalloc(sizeof (*pool), KM_SLEEP);
 230         mutex_init(&pool->pool_lock, NULL, MUTEX_DRIVER, NULL);
 231         qlt->qlt_dma_handle_pool = pool;
 232 }
 233 
 234 void
 235 qlt_dma_handle_pool_fini(qlt_state_t *qlt)
 236 {
 237         qlt_dma_handle_pool_t   *pool;
 238         qlt_dma_handle_t        *handle, *next_handle;


 546 {
 547         qlt_dma_handle_pool_t *pool;
 548         qlt_dma_handle_t *tmp_handle, *last_handle;
 549         int rv, handle_count;
 550 
 551         /*
 552          * Traverse the list and unbind the handles
 553          */
 554         ASSERT(first_handle);
 555         tmp_handle = first_handle;
 556         handle_count = 0;
 557         while (tmp_handle != NULL) {
 558                 last_handle = tmp_handle;
 559                 /*
 560                  * If the handle is bound, unbind the handle so it can be
 561                  * reused. It may not be bound if there was a bind failure.
 562                  */
 563                 if (tmp_handle->num_cookies != 0) {
 564                         rv = ddi_dma_unbind_handle(tmp_handle->dma_handle);
 565                         ASSERT(rv == DDI_SUCCESS);
 566                         if (rv == DDI_SUCCESS) {
 567                                 tmp_handle->num_cookies = 0;
 568                                 tmp_handle->num_cookies_fetched = 0;
 569                         }
 570                 }
 571                 tmp_handle = tmp_handle->next;
 572                 handle_count++;
 573         }
 574         /*
 575          * Insert this list into the free list
 576          */
 577         pool = qlt->qlt_dma_handle_pool;
 578         mutex_enter(&pool->pool_lock);
 579         last_handle->next = pool->free_list;
 580         pool->free_list = first_handle;
 581         pool->num_free += handle_count;
 582         mutex_exit(&pool->pool_lock);
 583 }
 584 
 585 /*
 586  * cookies produced by mapping this dbuf
 587  */
 588 uint16_t
 589 qlt_get_cookie_count(stmf_data_buf_t *dbuf)
 590 {


 631                 if (fetch->num_cookies_fetched == 0) {
 632                         *cookiep = fetch->first_cookie;
 633                 } else {
 634                         ddi_dma_nextcookie(fetch->dma_handle, cookiep);
 635                 }
 636                 if (++fetch->num_cookies_fetched == fetch->num_cookies) {
 637                         if (fetch->next == NULL)
 638                                 qsgl->handle_next_fetch = FETCH_DONE;
 639                         else
 640                                 qsgl->handle_next_fetch = fetch->next;
 641                 }
 642         }
 643 }
 644 
 645 /*
 646  * Set this flag to fetch the DDI dma cookies from the handles here and
 647  * store them in the port private area of the dbuf. This will allow
 648  * faster access to the cookies in qlt_xfer_scsi_data() at the expense of
 649  * an extra copy. If the qlt->req_lock is hot, this may help.
 650  */
 651 uint16_t qlt_sgl_prefetch = 0;
 652 
 653 /*ARGSUSED*/
 654 stmf_status_t
 655 qlt_dma_setup_dbuf(fct_local_port_t *port, stmf_data_buf_t *dbuf,
 656     uint32_t flags)
 657 {
 658         qlt_state_t             *qlt = port->port_fca_private;
 659         qlt_dma_sgl_t           *qsgl;
 660         struct stmf_sglist_ent  *sglp;
 661         qlt_dma_handle_t        *handle_list, *th;
 662         int                     i, rv;
 663         ddi_dma_cookie_t        *cookie_p;
 664         int                     numbufs;
 665         uint16_t                cookie_count;
 666         uint16_t                prefetch;
 667         size_t                  qsize;
 668 
 669         /*
 670          * psuedo code:
 671          * get dma handle list from cache - one per sglist entry
 672          * foreach sglist entry
 673          *      bind dma handle to sglist vaddr
 674          * allocate space for DMA state to store in db_port_private
 675          * fill in port private object
 676          * if prefetching
 677          *      move all dma cookies into db_port_private
 678          */
 679         dbuf->db_port_private = NULL;
 680         numbufs = dbuf->db_sglist_length;
 681         handle_list = qlt_dma_alloc_handle_list(qlt, numbufs);
 682         if (handle_list == NULL) {
 683                 EL(qlt, "handle_list==NULL\n");
 684                 return (STMF_FAILURE);
 685         }
 686         /*