From patchwork Thu Apr 12 18:27:27 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: sjur.brandeland@stericsson.com X-Patchwork-Id: 152161 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id A8CD0B7006 for ; Fri, 13 Apr 2012 04:27:55 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757847Ab2DLS1r (ORCPT ); Thu, 12 Apr 2012 14:27:47 -0400 Received: from mail-lpp01m010-f46.google.com ([209.85.215.46]:59270 "EHLO mail-lpp01m010-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932281Ab2DLS1n (ORCPT ); Thu, 12 Apr 2012 14:27:43 -0400 Received: by lahj13 with SMTP id j13so1796059lah.19 for ; Thu, 12 Apr 2012 11:27:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:mime-version:content-type:content-transfer-encoding; bh=kq5dnYWCpHz6rbUtW6n0PwnXJP+oy3i5ygO0cD001H8=; b=HXzZninvJ7/vX6K0QchDBRC/QzntpDHhk0bKexv/Kw8/9+230c/adPKn9IB0bws9/y nXkdDVLmZ6o1aS72x8nwAc0vcC1928985SYC8KMD6xz2kKsz6ji49NcxK+/SSkaLvF6M uesKuE/OzPXvhec83FvnnG9WU4F9sndAhI4jJwBMvm4p0bhtCFglIuxw0bRvMX3H90ua UnwOIiP0Bl7j5sRPZONjF8+UKyDViFpOBs0mDYPIfQ2VNPP66YqkrRiHea7Nuoq/wPds kGt0r5f+rGB2omZsHJ0JVW8d9aeXZNLK2nupWG8lboGsO78BN/NYrp9WeD5X/FVHGuLd 2Rjw== Received: by 10.112.83.105 with SMTP id p9mr1563948lby.43.1334255261552; Thu, 12 Apr 2012 11:27:41 -0700 (PDT) Received: from localhost.localdomain ([212.4.57.94]) by mx.google.com with ESMTPS id c3sm8661103lbg.6.2012.04.12.11.27.40 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 12 Apr 2012 11:27:40 -0700 (PDT) From: =?UTF-8?q?Sjur=20Br=C3=A6ndeland?= To: netdev@vger.kernel.org, davem@davemloft.net Cc: sjurbren@gmail.com, =?UTF-8?q?Sjur=20Br=C3=A6ndeland?= Subject: [PATCH net-next 4/4] caif-hsi: Postpone init of HSI until open() Date: Thu, 12 Apr 2012 20:27:27 +0200 Message-Id: <1334255247-3372-5-git-send-email-sjur.brandeland@stericsson.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1334255247-3372-1-git-send-email-sjur.brandeland@stericsson.com> References: <1334255247-3372-1-git-send-email-sjur.brandeland@stericsson.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Do the initialization of the HSI interface when the interface is opened, instead of upon registration. When the interface is closed the HSI interface is de-initialized, allowing other modules to use the HSI interface. Signed-off-by: Sjur Brændeland --- Hi Dave, This patch does not apply cleanly on net-next, but depends on the bug-fix patch intended for 3.4: caif-hsi: Free flip_buffer at shutdown I hope this don't cause trouble for you. Thanks, Sjur drivers/net/caif/caif_hsi.c | 97 ++++++++++++++++++++----------------------- 1 files changed, 45 insertions(+), 52 deletions(-) diff --git a/drivers/net/caif/caif_hsi.c b/drivers/net/caif/caif_hsi.c index 4253991..1520814 100644 --- a/drivers/net/caif/caif_hsi.c +++ b/drivers/net/caif/caif_hsi.c @@ -6,6 +6,8 @@ * License terms: GNU General Public License (GPL) version 2. */ +#define pr_fmt(fmt) KBUILD_MODNAME fmt + #include #include #include @@ -1127,21 +1129,7 @@ static int cfhsi_xmit(struct sk_buff *skb, struct net_device *dev) return 0; } -static int cfhsi_open(struct net_device *dev) -{ - return 0; -} - -static int cfhsi_close(struct net_device *dev) -{ - return 0; -} - -static const struct net_device_ops cfhsi_ops = { - .ndo_open = cfhsi_open, - .ndo_stop = cfhsi_close, - .ndo_start_xmit = cfhsi_xmit -}; +static const struct net_device_ops cfhsi_ops; static void cfhsi_setup(struct net_device *dev) { @@ -1167,7 +1155,7 @@ int cfhsi_probe(struct platform_device *pdev) { struct cfhsi *cfhsi = NULL; struct net_device *ndev; - struct cfhsi_dev *dev; + int res; ndev = alloc_netdev(sizeof(struct cfhsi), "cfhsi%d", cfhsi_setup); @@ -1178,6 +1166,34 @@ int cfhsi_probe(struct platform_device *pdev) cfhsi->ndev = ndev; cfhsi->pdev = pdev; + /* Assign the HSI device. */ + cfhsi->dev = pdev->dev.platform_data; + + /* Assign the driver to this HSI device. */ + cfhsi->dev->drv = &cfhsi->drv; + + /* Register network device. */ + res = register_netdev(ndev); + if (res) { + dev_err(&ndev->dev, "%s: Registration error: %d.\n", + __func__, res); + free_netdev(ndev); + } + /* Add CAIF HSI device to list. */ + spin_lock(&cfhsi_list_lock); + list_add_tail(&cfhsi->list, &cfhsi_list); + spin_unlock(&cfhsi_list_lock); + + return res; +} + +static int cfhsi_open(struct net_device *ndev) +{ + struct cfhsi *cfhsi = netdev_priv(ndev); + int res; + + clear_bit(CFHSI_SHUTDOWN, &cfhsi->bits); + /* Initialize state vaiables. */ cfhsi->tx_state = CFHSI_TX_STATE_IDLE; cfhsi->rx_state.state = CFHSI_RX_STATE_DESC; @@ -1187,12 +1203,6 @@ int cfhsi_probe(struct platform_device *pdev) cfhsi->q_low_mark = LOW_WATER_MARK; cfhsi->q_high_mark = HIGH_WATER_MARK; - /* Assign the HSI device. */ - dev = (struct cfhsi_dev *)pdev->dev.platform_data; - cfhsi->dev = dev; - - /* Assign the driver to this HSI device. */ - dev->drv = &cfhsi->drv; /* * Allocate a TX buffer with the size of a HSI packet descriptors @@ -1260,9 +1270,9 @@ int cfhsi_probe(struct platform_device *pdev) clear_bit(CFHSI_AWAKE, &cfhsi->bits); /* Create work thread. */ - cfhsi->wq = create_singlethread_workqueue(pdev->name); + cfhsi->wq = create_singlethread_workqueue(cfhsi->pdev->name); if (!cfhsi->wq) { - dev_err(&ndev->dev, "%s: Failed to create work queue.\n", + dev_err(&cfhsi->ndev->dev, "%s: Failed to create work queue.\n", __func__); res = -ENODEV; goto err_create_wq; @@ -1286,11 +1296,6 @@ int cfhsi_probe(struct platform_device *pdev) cfhsi->aggregation_timer.data = (unsigned long)cfhsi; cfhsi->aggregation_timer.function = cfhsi_aggregation_tout; - /* Add CAIF HSI device to list. */ - spin_lock(&cfhsi_list_lock); - list_add_tail(&cfhsi->list, &cfhsi_list); - spin_unlock(&cfhsi_list_lock); - /* Activate HSI interface. */ res = cfhsi->dev->cfhsi_up(cfhsi->dev); if (res) { @@ -1303,15 +1308,7 @@ int cfhsi_probe(struct platform_device *pdev) /* Flush FIFO */ res = cfhsi_flush_fifo(cfhsi); if (res) { - dev_err(&ndev->dev, "%s: Can't flush FIFO: %d.\n", - __func__, res); - goto err_net_reg; - } - - /* Register network device. */ - res = register_netdev(ndev); - if (res) { - dev_err(&ndev->dev, "%s: Registration error: %d.\n", + dev_err(&cfhsi->ndev->dev, "%s: Can't flush FIFO: %d.\n", __func__, res); goto err_net_reg; } @@ -1328,13 +1325,12 @@ int cfhsi_probe(struct platform_device *pdev) err_alloc_rx: kfree(cfhsi->tx_buf); err_alloc_tx: - free_netdev(ndev); - return res; } -static void cfhsi_shutdown(struct cfhsi *cfhsi) +static int cfhsi_close(struct net_device *ndev) { + struct cfhsi *cfhsi = netdev_priv(ndev); u8 *tx_buf, *rx_buf, *flip_buf; /* going to shutdown driver */ @@ -1364,15 +1360,19 @@ static void cfhsi_shutdown(struct cfhsi *cfhsi) /* Deactivate interface */ cfhsi->dev->cfhsi_down(cfhsi->dev); - /* Finally unregister the network device. */ - unregister_netdev(cfhsi->ndev); - /* Free buffers. */ kfree(tx_buf); kfree(rx_buf); kfree(flip_buf); + return 0; } +static const struct net_device_ops cfhsi_ops = { + .ndo_open = cfhsi_open, + .ndo_stop = cfhsi_close, + .ndo_start_xmit = cfhsi_xmit +}; + int cfhsi_remove(struct platform_device *pdev) { struct list_head *list_node; @@ -1389,10 +1389,6 @@ int cfhsi_remove(struct platform_device *pdev) /* Remove from list. */ list_del(list_node); spin_unlock(&cfhsi_list_lock); - - /* Shutdown driver. */ - cfhsi_shutdown(cfhsi); - return 0; } } @@ -1423,8 +1419,7 @@ static void __exit cfhsi_exit_module(void) list_del(list_node); spin_unlock(&cfhsi_list_lock); - /* Shutdown driver. */ - cfhsi_shutdown(cfhsi); + unregister_netdevice(cfhsi->ndev); spin_lock(&cfhsi_list_lock); } @@ -1449,8 +1444,6 @@ static int __init cfhsi_init_module(void) goto err_dev_register; } - return result; - err_dev_register: return result; }