From patchwork Fri Sep 4 03:02:45 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Scott Feldman X-Patchwork-Id: 32969 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@bilbo.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from ozlabs.org (ozlabs.org [203.10.76.45]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "mx.ozlabs.org", Issuer "CA Cert Signing Authority" (verified OK)) by bilbo.ozlabs.org (Postfix) with ESMTPS id E0AC8B70B0 for ; Fri, 4 Sep 2009 13:02:57 +1000 (EST) Received: by ozlabs.org (Postfix) id D5C42DDD1B; Fri, 4 Sep 2009 13:02:57 +1000 (EST) Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by ozlabs.org (Postfix) with ESMTP id 343B6DDD0B for ; Fri, 4 Sep 2009 13:02:57 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932812AbZIDDCo (ORCPT ); Thu, 3 Sep 2009 23:02:44 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S932795AbZIDDCn (ORCPT ); Thu, 3 Sep 2009 23:02:43 -0400 Received: from sj-iport-1.cisco.com ([171.71.176.70]:59828 "EHLO sj-iport-1.cisco.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932802AbZIDDCm (ORCPT ); Thu, 3 Sep 2009 23:02:42 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhgFALsgoEqrR7PE/2dsb2JhbACBU8BLiEEBkCsFhBuBXQ X-IronPort-AV: E=Sophos;i="4.44,329,1249257600"; d="scan'208";a="237329356" Received: from sj-dkim-4.cisco.com ([171.71.179.196]) by sj-iport-1.cisco.com with ESMTP; 04 Sep 2009 03:02:45 +0000 Received: from sj-core-1.cisco.com (sj-core-1.cisco.com [171.71.177.237]) by sj-dkim-4.cisco.com (8.12.11/8.12.11) with ESMTP id n8432j0S001385; Thu, 3 Sep 2009 20:02:45 -0700 Received: from palito_client100.nuovasystems.com (savbu-palito-client100.cisco.com [10.193.70.13]) by sj-core-1.cisco.com (8.13.8/8.14.3) with ESMTP id n8432j2N009175; Fri, 4 Sep 2009 03:02:45 GMT From: Scott Feldman Subject: [net-next PATCH 11/11] enic: organize device initialization/deinit into separate functions To: davem@davemloft.net Cc: netdev@vger.kernel.org Date: Thu, 03 Sep 2009 20:02:45 -0700 Message-ID: <20090904030245.5047.80150.stgit@palito_client100.nuovasystems.com> In-Reply-To: <20090904030046.5047.46509.stgit@palito_client100.nuovasystems.com> References: <20090904030046.5047.46509.stgit@palito_client100.nuovasystems.com> User-Agent: StGIT/0.12.1 MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; l=11876; t=1252033365; x=1252897365; c=relaxed/simple; s=sjdkim4002; h=Content-Type:From:Subject:Content-Transfer-Encoding:MIME-Version; d=cisco.com; i=scofeldm@cisco.com; z=From:=20Scott=20Feldman=20 |Subject:=20[net-next=20PATCH=2011/11]=20enic=3A=20organize =20device=20initialization/deinit=0A=09into=20separate=20fun ctions |Sender:=20; bh=7pcW9uTirjzG7Qnd6NfRqVhbIcvk9EelHRm1TMPM4wE=; b=ReHZhl/+XoUtGcg5nO7ovA7gPwGC9dwW42yiEww3oC53Qyl9zmZU5PPJWY xrICCTo524ZdtNbuMKsfX6WnjqB48Ufe8bbFbStakIlsq0nYishJ6Pcc7hu+ pBuCWylGA9; Authentication-Results: sj-dkim-4; header.From=scofeldm@cisco.com; dkim=pass ( sig from cisco.com/sjdkim4002 verified; ); Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org enic: organize device initialization/deinit into separate functions To unclutter probe() a little bit, put all device initialization code in one spot and device deinit code in another spot. Also remove unused rq->buf_index variable/func. Signed-off-by: Scott Feldman --- drivers/net/enic/enic_main.c | 145 ++++++++++++++++++++++++++---------------- drivers/net/enic/vnic_rq.c | 27 +++++--- drivers/net/enic/vnic_rq.h | 12 +-- drivers/net/enic/vnic_wq.c | 20 +++++- drivers/net/enic/vnic_wq.h | 4 + 5 files changed, 133 insertions(+), 75 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/net/enic/enic_main.c b/drivers/net/enic/enic_main.c index 9368dae..2737c0d 100644 --- a/drivers/net/enic/enic_main.c +++ b/drivers/net/enic/enic_main.c @@ -1740,6 +1740,88 @@ static const struct net_device_ops enic_netdev_ops = { #endif }; +void enic_dev_deinit(struct enic *enic) +{ + netif_napi_del(&enic->napi); + enic_free_vnic_resources(enic); + enic_clear_intr_mode(enic); +} + +int enic_dev_init(struct enic *enic) +{ + struct net_device *netdev = enic->netdev; + int err; + + /* Get vNIC configuration + */ + + err = enic_get_vnic_config(enic); + if (err) { + printk(KERN_ERR PFX + "Get vNIC configuration failed, aborting.\n"); + return err; + } + + /* Get available resource counts + */ + + enic_get_res_counts(enic); + + /* Set interrupt mode based on resource counts and system + * capabilities + */ + + err = enic_set_intr_mode(enic); + if (err) { + printk(KERN_ERR PFX + "Failed to set intr mode, aborting.\n"); + return err; + } + + /* Allocate and configure vNIC resources + */ + + err = enic_alloc_vnic_resources(enic); + if (err) { + printk(KERN_ERR PFX + "Failed to alloc vNIC resources, aborting.\n"); + goto err_out_free_vnic_resources; + } + + enic_init_vnic_resources(enic); + + err = enic_set_rq_alloc_buf(enic); + if (err) { + printk(KERN_ERR PFX + "Failed to set RQ buffer allocator, aborting.\n"); + goto err_out_free_vnic_resources; + } + + err = enic_set_niccfg(enic); + if (err) { + printk(KERN_ERR PFX + "Failed to config nic, aborting.\n"); + goto err_out_free_vnic_resources; + } + + switch (vnic_dev_get_intr_mode(enic->vdev)) { + default: + netif_napi_add(netdev, &enic->napi, enic_poll, 64); + break; + case VNIC_DEV_INTR_MODE_MSIX: + netif_napi_add(netdev, &enic->napi, enic_poll_msix, 64); + break; + } + + return 0; + +err_out_free_vnic_resources: + enic_clear_intr_mode(enic); + enic_free_vnic_resources(enic); + + return err; +} + static void enic_iounmap(struct enic *enic) { unsigned int i; @@ -1882,51 +1964,13 @@ static int __devinit enic_probe(struct pci_dev *pdev, goto err_out_dev_close; } - /* Get vNIC configuration - */ - - err = enic_get_vnic_config(enic); + err = enic_dev_init(enic); if (err) { printk(KERN_ERR PFX - "Get vNIC configuration failed, aborting.\n"); + "Device initialization failed, aborting.\n"); goto err_out_dev_close; } - /* Get available resource counts - */ - - enic_get_res_counts(enic); - - /* Set interrupt mode based on resource counts and system - * capabilities - */ - - err = enic_set_intr_mode(enic); - if (err) { - printk(KERN_ERR PFX - "Failed to set intr mode, aborting.\n"); - goto err_out_dev_close; - } - - /* Allocate and configure vNIC resources - */ - - err = enic_alloc_vnic_resources(enic); - if (err) { - printk(KERN_ERR PFX - "Failed to alloc vNIC resources, aborting.\n"); - goto err_out_free_vnic_resources; - } - - enic_init_vnic_resources(enic); - - err = enic_set_niccfg(enic); - if (err) { - printk(KERN_ERR PFX - "Failed to config nic, aborting.\n"); - goto err_out_free_vnic_resources; - } - /* Setup notification timer, HW reset task, and locks */ @@ -1951,22 +1995,13 @@ static int __devinit enic_probe(struct pci_dev *pdev, if (err) { printk(KERN_ERR PFX "Invalid MAC address, aborting.\n"); - goto err_out_free_vnic_resources; + goto err_out_dev_deinit; } netdev->netdev_ops = &enic_netdev_ops; netdev->watchdog_timeo = 2 * HZ; netdev->ethtool_ops = &enic_ethtool_ops; - switch (vnic_dev_get_intr_mode(enic->vdev)) { - default: - netif_napi_add(netdev, &enic->napi, enic_poll, 64); - break; - case VNIC_DEV_INTR_MODE_MSIX: - netif_napi_add(netdev, &enic->napi, enic_poll_msix, 64); - break; - } - netdev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER; if (ENIC_SETTING(enic, TXCSUM)) @@ -1994,17 +2029,16 @@ static int __devinit enic_probe(struct pci_dev *pdev, if (err) { printk(KERN_ERR PFX "Cannot register net device, aborting.\n"); - goto err_out_free_vnic_resources; + goto err_out_dev_deinit; } return 0; -err_out_free_vnic_resources: - enic_free_vnic_resources(enic); +err_out_dev_deinit: + enic_dev_deinit(enic); err_out_dev_close: vnic_dev_close(enic->vdev); err_out_vnic_unregister: - enic_clear_intr_mode(enic); vnic_dev_unregister(enic->vdev); err_out_iounmap: enic_iounmap(enic); @@ -2028,9 +2062,8 @@ static void __devexit enic_remove(struct pci_dev *pdev) flush_scheduled_work(); unregister_netdev(netdev); - enic_free_vnic_resources(enic); + enic_dev_deinit(enic); vnic_dev_close(enic->vdev); - enic_clear_intr_mode(enic); vnic_dev_unregister(enic->vdev); enic_iounmap(enic); pci_release_regions(pdev); diff --git a/drivers/net/enic/vnic_rq.c b/drivers/net/enic/vnic_rq.c index 9365e63..7558397 100644 --- a/drivers/net/enic/vnic_rq.c +++ b/drivers/net/enic/vnic_rq.c @@ -62,7 +62,6 @@ static int vnic_rq_alloc_bufs(struct vnic_rq *rq) } rq->to_use = rq->to_clean = rq->bufs[0]; - rq->buf_index = 0; return 0; } @@ -113,12 +112,12 @@ int vnic_rq_alloc(struct vnic_dev *vdev, struct vnic_rq *rq, unsigned int index, return 0; } -void vnic_rq_init(struct vnic_rq *rq, unsigned int cq_index, +void vnic_rq_init_start(struct vnic_rq *rq, unsigned int cq_index, + unsigned int fetch_index, unsigned int posted_index, unsigned int error_interrupt_enable, unsigned int error_interrupt_offset) { u64 paddr; - u32 fetch_index; paddr = (u64)rq->ring.base_addr | VNIC_PADDR_TARGET; writeq(paddr, &rq->ctrl->ring_base); @@ -128,15 +127,27 @@ void vnic_rq_init(struct vnic_rq *rq, unsigned int cq_index, iowrite32(error_interrupt_offset, &rq->ctrl->error_interrupt_offset); iowrite32(0, &rq->ctrl->dropped_packet_count); iowrite32(0, &rq->ctrl->error_status); + iowrite32(fetch_index, &rq->ctrl->fetch_index); + iowrite32(posted_index, &rq->ctrl->posted_index); - /* Use current fetch_index as the ring starting point */ - fetch_index = ioread32(&rq->ctrl->fetch_index); rq->to_use = rq->to_clean = &rq->bufs[fetch_index / VNIC_RQ_BUF_BLK_ENTRIES] [fetch_index % VNIC_RQ_BUF_BLK_ENTRIES]; - iowrite32(fetch_index, &rq->ctrl->posted_index); +} + +void vnic_rq_init(struct vnic_rq *rq, unsigned int cq_index, + unsigned int error_interrupt_enable, + unsigned int error_interrupt_offset) +{ + u32 fetch_index; - rq->buf_index = 0; + /* Use current fetch_index as the ring starting point */ + fetch_index = ioread32(&rq->ctrl->fetch_index); + + vnic_rq_init_start(rq, cq_index, + fetch_index, fetch_index, + error_interrupt_enable, + error_interrupt_offset); } unsigned int vnic_rq_error_status(struct vnic_rq *rq) @@ -192,8 +203,6 @@ void vnic_rq_clean(struct vnic_rq *rq, [fetch_index % VNIC_RQ_BUF_BLK_ENTRIES]; iowrite32(fetch_index, &rq->ctrl->posted_index); - rq->buf_index = 0; - vnic_dev_clear_desc_ring(&rq->ring); } diff --git a/drivers/net/enic/vnic_rq.h b/drivers/net/enic/vnic_rq.h index f7b5730..35e736c 100644 --- a/drivers/net/enic/vnic_rq.h +++ b/drivers/net/enic/vnic_rq.h @@ -1,5 +1,5 @@ /* - * Copyright 2008 Cisco Systems, Inc. All rights reserved. + * Copyright 2008, 2009 Cisco Systems, Inc. All rights reserved. * Copyright 2007 Nuova Systems, Inc. All rights reserved. * * This program is free software; you may redistribute it and/or modify @@ -79,7 +79,6 @@ struct vnic_rq { struct vnic_rq_buf *to_use; struct vnic_rq_buf *to_clean; void *os_buf_head; - unsigned int buf_index; unsigned int pkts_outstanding; }; @@ -105,11 +104,6 @@ static inline unsigned int vnic_rq_next_index(struct vnic_rq *rq) return rq->to_use->index; } -static inline unsigned int vnic_rq_next_buf_index(struct vnic_rq *rq) -{ - return rq->buf_index++; -} - static inline void vnic_rq_post(struct vnic_rq *rq, void *os_buf, unsigned int os_buf_index, dma_addr_t dma_addr, unsigned int len) @@ -204,6 +198,10 @@ static inline int vnic_rq_fill(struct vnic_rq *rq, void vnic_rq_free(struct vnic_rq *rq); int vnic_rq_alloc(struct vnic_dev *vdev, struct vnic_rq *rq, unsigned int index, unsigned int desc_count, unsigned int desc_size); +void vnic_rq_init_start(struct vnic_rq *rq, unsigned int cq_index, + unsigned int fetch_index, unsigned int posted_index, + unsigned int error_interrupt_enable, + unsigned int error_interrupt_offset); void vnic_rq_init(struct vnic_rq *rq, unsigned int cq_index, unsigned int error_interrupt_enable, unsigned int error_interrupt_offset); diff --git a/drivers/net/enic/vnic_wq.c b/drivers/net/enic/vnic_wq.c index a576d04..d2e00e5 100644 --- a/drivers/net/enic/vnic_wq.c +++ b/drivers/net/enic/vnic_wq.c @@ -112,7 +112,8 @@ int vnic_wq_alloc(struct vnic_dev *vdev, struct vnic_wq *wq, unsigned int index, return 0; } -void vnic_wq_init(struct vnic_wq *wq, unsigned int cq_index, +void vnic_wq_init_start(struct vnic_wq *wq, unsigned int cq_index, + unsigned int fetch_index, unsigned int posted_index, unsigned int error_interrupt_enable, unsigned int error_interrupt_offset) { @@ -121,12 +122,25 @@ void vnic_wq_init(struct vnic_wq *wq, unsigned int cq_index, paddr = (u64)wq->ring.base_addr | VNIC_PADDR_TARGET; writeq(paddr, &wq->ctrl->ring_base); iowrite32(wq->ring.desc_count, &wq->ctrl->ring_size); - iowrite32(0, &wq->ctrl->fetch_index); - iowrite32(0, &wq->ctrl->posted_index); + iowrite32(fetch_index, &wq->ctrl->fetch_index); + iowrite32(posted_index, &wq->ctrl->posted_index); iowrite32(cq_index, &wq->ctrl->cq_index); iowrite32(error_interrupt_enable, &wq->ctrl->error_interrupt_enable); iowrite32(error_interrupt_offset, &wq->ctrl->error_interrupt_offset); iowrite32(0, &wq->ctrl->error_status); + + wq->to_use = wq->to_clean = + &wq->bufs[fetch_index / VNIC_WQ_BUF_BLK_ENTRIES] + [fetch_index % VNIC_WQ_BUF_BLK_ENTRIES]; +} + +void vnic_wq_init(struct vnic_wq *wq, unsigned int cq_index, + unsigned int error_interrupt_enable, + unsigned int error_interrupt_offset) +{ + vnic_wq_init_start(wq, cq_index, 0, 0, + error_interrupt_enable, + error_interrupt_offset); } unsigned int vnic_wq_error_status(struct vnic_wq *wq) diff --git a/drivers/net/enic/vnic_wq.h b/drivers/net/enic/vnic_wq.h index c826137..9c34d41 100644 --- a/drivers/net/enic/vnic_wq.h +++ b/drivers/net/enic/vnic_wq.h @@ -149,6 +149,10 @@ static inline void vnic_wq_service(struct vnic_wq *wq, void vnic_wq_free(struct vnic_wq *wq); int vnic_wq_alloc(struct vnic_dev *vdev, struct vnic_wq *wq, unsigned int index, unsigned int desc_count, unsigned int desc_size); +void vnic_wq_init_start(struct vnic_wq *wq, unsigned int cq_index, + unsigned int fetch_index, unsigned int posted_index, + unsigned int error_interrupt_enable, + unsigned int error_interrupt_offset); void vnic_wq_init(struct vnic_wq *wq, unsigned int cq_index, unsigned int error_interrupt_enable, unsigned int error_interrupt_offset);