From patchwork Wed Feb 10 14:11:55 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike McCormack X-Patchwork-Id: 45034 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 13C82B7D41 for ; Thu, 11 Feb 2010 01:17:14 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753699Ab0BJORI (ORCPT ); Wed, 10 Feb 2010 09:17:08 -0500 Received: from mail-pz0-f187.google.com ([209.85.222.187]:55858 "EHLO mail-pz0-f187.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752738Ab0BJORG (ORCPT ); Wed, 10 Feb 2010 09:17:06 -0500 Received: by mail-pz0-f187.google.com with SMTP id 17so24824pzk.4 for ; Wed, 10 Feb 2010 06:17:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:message-id:date:from :user-agent:mime-version:to:cc:subject:content-type :content-transfer-encoding; bh=mGgc7KfydQq+DeEBVfzpDRJTUjzgZZ07ITgxksOe+zs=; b=BddZsOOetnPRS0LH5ora2YYIwsubhnyT/crMfyzLCqoL8y1VTnKBopfu5m3L1G4o5L 4vH8LmMFFpZnwlmarEHKo+4h08wcT0utiwoq9t7IbFkAQCXTnmS+14qSjur0rIGYF9Sh TJ1H1AGWEm6u/9mnQ3L3DsTqqdWxC0EIC5+48= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:message-id:date:from:user-agent:mime-version:to:cc:subject :content-type:content-transfer-encoding; b=xZYbpKVb63SpeEFwjyYTgh0y6LhMvxxvVRrSAU377zu8FIEKOWKkh01jEzwFxbC/Dq glI703MubgcxJEdcvi3nvp6gEVuiGZ3NZPfWb+c1f4mRyWiLOeunafyvVWL88hmLpc4F pTARTes8deo1MHz/KyIp5QxUr8S4CIa2ZFGX0= Received: by 10.114.237.5 with SMTP id k5mr180515wah.61.1265811425711; Wed, 10 Feb 2010 06:17:05 -0800 (PST) Received: from ?192.168.0.103? ([121.168.21.96]) by mx.google.com with ESMTPS id 21sm497467pzk.3.2010.02.10.06.17.03 (version=SSLv3 cipher=RC4-MD5); Wed, 10 Feb 2010 06:17:04 -0800 (PST) Message-ID: <4B72BEAB.7020805@ring3k.org> Date: Wed, 10 Feb 2010 23:11:55 +0900 From: Mike McCormack User-Agent: Mozilla-Thunderbird 2.0.0.22 (X11/20090706) MIME-Version: 1.0 To: Stephen Hemminger CC: netdev@vger.kernel.org Subject: [PATCH 1/5] sky2: Factor out code to calculate packet sizes Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Move code to calculate receive threshold and packet size out of sky2_rx_start() so that is can be called from elsewhere easily. Signed-off-by: Mike McCormack --- drivers/net/sky2.c | 57 +++++++++++++++++++++++++++++++++------------------ 1 files changed, 37 insertions(+), 20 deletions(-) diff --git a/drivers/net/sky2.c b/drivers/net/sky2.c index 7443622..40c661b 100644 --- a/drivers/net/sky2.c +++ b/drivers/net/sky2.c @@ -1065,6 +1065,40 @@ static inline struct sky2_rx_le *sky2_next_rx(struct sky2_port *sky2) return le; } +static unsigned sky2_get_rx_threshold(struct sky2_port* sky2) +{ + unsigned size; + + /* Space needed for frame data + headers rounded up */ + size = roundup(sky2->netdev->mtu + ETH_HLEN + VLAN_HLEN, 8); + + /* Stopping point for hardware truncation */ + return (size - 8) / sizeof(u32); +} + +static unsigned sky2_get_rx_data_size(struct sky2_port* sky2) +{ + struct rx_ring_info *re; + unsigned size; + + /* Space needed for frame data + headers rounded up */ + size = roundup(sky2->netdev->mtu + ETH_HLEN + VLAN_HLEN, 8); + + sky2->rx_nfrags = size >> PAGE_SHIFT; + BUG_ON(sky2->rx_nfrags > ARRAY_SIZE(re->frag_addr)); + + /* Compute residue after pages */ + size -= sky2->rx_nfrags << PAGE_SHIFT; + + /* Optimize to handle small packets and headers */ + if (size < copybreak) + size = copybreak; + if (size < ETH_HLEN) + size = ETH_HLEN; + + return size; +} + /* Build description to hardware for one receive segment */ static void sky2_rx_add(struct sky2_port *sky2, u8 op, dma_addr_t map, unsigned len) @@ -1359,7 +1393,7 @@ static int sky2_rx_start(struct sky2_port *sky2) struct sky2_hw *hw = sky2->hw; struct rx_ring_info *re; unsigned rxq = rxqaddr[sky2->port]; - unsigned i, size, thresh; + unsigned i, thresh; sky2->rx_put = sky2->rx_next = 0; sky2_qset(hw, rxq); @@ -1380,25 +1414,7 @@ static int sky2_rx_start(struct sky2_port *sky2) if (!(hw->flags & SKY2_HW_NEW_LE)) rx_set_checksum(sky2); - /* Space needed for frame data + headers rounded up */ - size = roundup(sky2->netdev->mtu + ETH_HLEN + VLAN_HLEN, 8); - - /* Stopping point for hardware truncation */ - thresh = (size - 8) / sizeof(u32); - - sky2->rx_nfrags = size >> PAGE_SHIFT; - BUG_ON(sky2->rx_nfrags > ARRAY_SIZE(re->frag_addr)); - - /* Compute residue after pages */ - size -= sky2->rx_nfrags << PAGE_SHIFT; - - /* Optimize to handle small packets and headers */ - if (size < copybreak) - size = copybreak; - if (size < ETH_HLEN) - size = ETH_HLEN; - - sky2->rx_data_size = size; + sky2->rx_data_size = sky2_get_rx_data_size(sky2); /* Fill Rx ring */ for (i = 0; i < sky2->rx_pending; i++) { @@ -1423,6 +1439,7 @@ static int sky2_rx_start(struct sky2_port *sky2) * the register is limited to 9 bits, so if you do frames > 2052 * you better get the MTU right! */ + thresh = sky2_get_rx_threshold(sky2); if (thresh > 0x1ff) sky2_write32(hw, SK_REG(sky2->port, RX_GMF_CTRL_T), RX_TRUNC_OFF); else {