Gigabit Ethernet driver of Topcliff PCH
Subsystems (2)
PATCH 1/1 Gigabit Ethernet driver of Topcliff PCH
Hi Randy, and Joe
Thank you for your comments and patch.
I have modified.
---
Gigabit Ethernet driver of Topcliff PCH
Patch created against 2.6.35
Topcliff PCH is the platform controller hub that is going to be used in Intel's upcoming general embedded platform. All IO peripherals in Topcliff PCH are actually devices sitting on AMBA bus. Topcliff PCH has Gigabit Ethernet I/F. Using this I/F, it is able to access system devices connected to Gigabit Ethernet.
--- drivers/net/Kconfig | 13 +- drivers/net/Makefile | 1 + drivers/net/pch_gbe/Makefile | 4 + drivers/net/pch_gbe/pch_gbe.h | 683 +++++++++ drivers/net/pch_gbe/pch_gbe_api.c | 246 ++++ drivers/net/pch_gbe/pch_gbe_api.h | 34 + drivers/net/pch_gbe/pch_gbe_ethtool.c | 620 ++++++++ drivers/net/pch_gbe/pch_gbe_main.c | 2547 +++++++++++++++++++++++++++++++++ drivers/net/pch_gbe/pch_gbe_param.c | 507 +++++++ drivers/net/pch_gbe/pch_gbe_phy.c | 276 ++++ drivers/net/pch_gbe/pch_gbe_phy.h | 35 + 11 files changed, 4965 insertions(+), 1 deletions(-) create mode 100644 drivers/net/pch_gbe/Makefile create mode 100644 drivers/net/pch_gbe/pch_gbe.h create mode 100644 drivers/net/pch_gbe/pch_gbe_api.c create mode 100644 drivers/net/pch_gbe/pch_gbe_api.h create mode 100644 drivers/net/pch_gbe/pch_gbe_ethtool.c create mode 100644 drivers/net/pch_gbe/pch_gbe_main.c create mode 100644 drivers/net/pch_gbe/pch_gbe_param.c create mode 100644 drivers/net/pch_gbe/pch_gbe_phy.c create mode 100644 drivers/net/pch_gbe/pch_gbe_phy.h
drivers/net/Kconfig +12 -1
@@ -2004,7 +2004,6 @@ menuconfig NETDEV_1000 If you say N, all options in this submenu will be skipped and disabled. if NETDEV_1000 - config ACENIC tristate "Alteon AceNIC/3Com 3C985/NetGear GA620 Gigabit support" depends on PCI
@@ -2502,6 +2501,18 @@ config S6GMAC source "drivers/net/stmmac/Kconfig" +config PCH_GBE + tristate "PCH Gigabit Ethernet" + depends on PCI + ---help--- + This is a gigabit ethernet driver for Topcliff PCH. + Topcliff PCH is the platform controller hub that is used in Intel's + general embedded platform. + Topcliff PCH has Gigabit Ethernet interface. + Using this interface, it is able to access system devices connected + to Gigabit Ethernet. + This driver enables Gigabit Ethernet function. + endif # NETDEV_1000 #
drivers/net/Makefile +1 -0
@@ -295,3 +295,4 @@ obj-$(CONFIG_WIMAX) += wimax/ obj-$(CONFIG_CAIF) += caif/ obj-$(CONFIG_OCTEON_MGMT_ETHERNET) += octeon/ +obj-$(CONFIG_PCH_GBE) += pch_gbe/
drivers/net/pch_gbe/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +obj-$(CONFIG_PCH_GBE) += pch_gbe.o +//EXTRA_CFLAGS += -DDEBUG +pch_gbe-y := pch_gbe_phy.o pch_gbe_ethtool.o pch_gbe_param.o +pch_gbe-y += pch_gbe_api.o pch_gbe_main.o
drivers/net/pch_gbe/pch_gbe.h new file +683 -0
683 lines not on this page · raw message
drivers/net/pch_gbe/pch_gbe_api.c new file +246 -0
246 lines not on this page · raw message
drivers/net/pch_gbe/pch_gbe_api.h new file +34 -0
@@ -0,0 +1,34 @@ +/* +* Copyright (C) 1999 - 2010 Intel Corporation. +* Copyright (C) 2010 OKI SEMICONDUCTOR Co., LTD. +* +* This code was derived from the Intel e1000e Linux driver. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; version 2 of the License. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. +*/ +#ifndef _PCH_GBE_API_H_ +#define _PCH_GBE_API_H_ + +s32 pch_gbe_hal_setup_init_funcs (struct pch_gbe_hw *hw); +void pch_gbe_hal_get_bus_info (struct pch_gbe_hw *hw); +s32 pch_gbe_hal_init_hw (struct pch_gbe_hw *hw); +s32 pch_gbe_hal_read_phy_reg (struct pch_gbe_hw *hw,u32 offset,u16 *data); +s32 pch_gbe_hal_write_phy_reg (struct pch_gbe_hw *hw,u32 offset,u16 data); +void pch_gbe_hal_phy_hw_reset (struct pch_gbe_hw *hw); +void pch_gbe_hal_phy_sw_reset (struct pch_gbe_hw *hw); +s32 pch_gbe_hal_read_mac_addr (struct pch_gbe_hw *hw); +void pch_gbe_hal_power_up_phy (struct pch_gbe_hw *hw); +void pch_gbe_hal_power_down_phy (struct pch_gbe_hw *hw); + +#endif
drivers/net/pch_gbe/pch_gbe_ethtool.c new file +620 -0
620 lines not on this page · raw message
drivers/net/pch_gbe/pch_gbe_main.c new file +2547 -0
1,384 lines not on this page · raw message
drivers/net/pch_gbe/pch_gbe_param.c new file +507 -0
507 lines not on this page · raw message
drivers/net/pch_gbe/pch_gbe_phy.c new file +276 -0
276 lines not on this page · raw message
drivers/net/pch_gbe/pch_gbe_phy.h new file +35 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.6.2.5
Part of the diff is not shown here. View the raw message.
Hi, I wrote few comments below.
drivers/net/Kconfig menuconfig NETDEV_1000 · line 2009
Quoted 10 lines · Masayuki Ohtake
drivers/net/Kconfig +0
-1@@ -2004,7 +2004,6 @@ menuconfig NETDEV_1000 If you say N, all options in this submenu will be skipped and disabled. if NETDEV_1000 - config ACENIC tristate "Alteon AceNIC/3Com 3C985/NetGear GA620 Gigabit support" depends on PCI
This hunk is unwanted, I think.
Quoted 3 lines
drivers/net/pch_gbe/pch_gbe.h new file +0
-0@@ -0,0 +1,683 @@
...
Quoted 54 lines
drivers/net/pch_gbe/pch_gbe.h new file +54
-0+/** +* pch_gbe_regs_mac_adr - Structure holding values of mac address registers +* @high Denotes the 1st to 4th byte from the initial of MAC address +* @low Denotes the 5th to 6th byte from the initial of MAC address +*/ +struct pch_gbe_regs_mac_adr { +u32 high; +u32 low; +}; +/** +* pch_udc_regs - Structure holding values of MAC registers +*/ +struct pch_gbe_regs { +u32 INT_ST; +u32 INT_EN; +u32 MODE; +u32 RESET; +u32 TCPIP_ACC; +u32 EX_LIST; +u32 INT_ST_HOLD; +u32 PHY_INT_CTRL; +u32 MAC_RX_EN; +u32 RX_FCTRL; +u32 PAUSE_REQ; +u32 RX_MODE; +u32 TX_MODE; +u32 RX_FIFO_ST; +u32 TX_FIFO_ST; +u32 TX_FID; +u32 TX_RESULT; +u32 PAUSE_PKT1; +u32 PAUSE_PKT2; +u32 PAUSE_PKT3; +u32 PAUSE_PKT4; +u32 PAUSE_PKT5; +u32 reserve[2 ]; +struct pch_gbe_regs_mac_adr mac_adr[16 ]; +u32 ADDR_MASK; +u32 MIIM; +u32 reserve2; +u32 RGMII_ST; +u32 RGMII_CTRL; +u32 reserve3[3 ]; +u32 DMA_CTRL; +u32 reserve4[3 ]; +u32 RX_DSC_BASE; +u32 RX_DSC_SIZE; +u32 RX_DSC_HW_P; +u32 RX_DSC_HW_P_HLD; +u32 RX_DSC_SW_P; +u32 reserve5[3 ]; +u32 TX_DSC_BASE; +u32 TX_DSC_SIZE; +u32 TX_DSC_HW_P;
drivers/net/pch_gbe/pch_gbe.h line 90
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe.h new file +10
-0+u32 TX_DSC_HW_P_HLD ; +u32 TX_DSC_SW_P ; +u32 reserve6[3 ]; +u32 RX_DMA_ST ; +u32 TX_DMA_ST ; +u32 reserve7[2 ]; +u32 WOL_ST ; +u32 WOL_CTRL ; +u32 WOL_ADDR_MASK ; +};
Shouldn't that be packed? As it is full of u32, probably not, but consider this comment when thinking about all structures you have here.
drivers/net/pch_gbe/pch_gbe.h line 303
Quoted 7 lines
drivers/net/pch_gbe/pch_gbe.h new file +7
-0+/* Device Driver infomation */ +#define DRV_STRING "PCH Network Driver" +#define DRV_EXT "-NAPI" +#define DRV_VERSION "0.95"DRV_EXT +#define DRV_DESCRIPTION \ + "OKI semiconductor sample Linux driver for PCH Gigabit ethernet" +#define DRV_COPYRIGHT "Copyright(c) 2010 OKI semiconductor"
Why you need these defines?
Quoted 6 lines
drivers/net/pch_gbe/pch_gbe.h new file +6
-0+struct pch_gbe_hw { +void *back; + +struct pch_gbe_regs __iomem *reg; +spinlock_t miim_lock; +
drivers/net/pch_gbe/pch_gbe.h line 426
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe.h new file +10
-0+const struct pch_gbe_functions *func; +struct pch_gbe_mac_info mac; +struct pch_gbe_phy_info phy; +struct pch_gbe_bus_info bus; + +u16 vendor_id; +u16 device_id; +u16 subsystem_vendor_id; +u16 subsystem_device_id; +u8 revision_id;
What you need these IDs for?
Quoted 33 lines
drivers/net/pch_gbe/pch_gbe.h new file +33
-0+}; + +/** +* struct pch_gbe_rx_desc - Receive Descriptor +* @buffer_addr: RX Frame Buffer Address +* @tcp_ip_status: TCP/IP Accelerator Status +* @rx_words_eob: RX word count and Byte position +* @gbec_status: GMAC Status +* @dma_status: DMA Status +* @reserved1: Reserved +* @reserved2: Reserved +*/ +struct pch_gbe_rx_desc { +u32 buffer_addr; +u32 tcp_ip_status; +u16 rx_words_eob; +u16 gbec_status; +u8 dma_status; +u8 reserved1; +u16 reserved2; +}; + +/** +* struct pch_gbe_tx_desc - Transmit Descriptor +* @buffer_addr: TX Frame Buffer Address +* @length: Data buffer length +* @reserved1: Reserved +* @tx_words_eob: TX word count and Byte position +* @tx_frame_ctrl: TX Frame Control +* @dma_status: DMA Status +* @reserved2: Reserved +* @gbec_status: GMAC Status +*/
drivers/net/pch_gbe/pch_gbe.h line 469
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe.h new file +10
-0+struct pch_gbe_tx_desc { +u32 buffer_addr; +u16 length; +u16 reserved1; +u16 tx_words_eob; +u16 tx_frame_ctrl; +u8 dma_status; +u8 reserved2; +u16 gbec_status; +};
packed?
drivers/net/pch_gbe/pch_gbe.h line 619
Quoted 3 lines
drivers/net/pch_gbe/pch_gbe.h new file +3
-0+struct pch_gbe_adapter { +spinlock_t stats_lock; +spinlock_t tx_queue_lock;
unitialized
drivers/net/pch_gbe/pch_gbe.h line 620
Quoted 1 line
drivers/net/pch_gbe/pch_gbe.h new file +1
-0+spinlock_t int_en_lock;
unused
Quoted 5 lines
drivers/net/pch_gbe/pch_gbe.h new file +5
-0+spinlock_t ethtool_lock; +atomic_t irq_sem; +struct net_device *netdev; +struct pci_dev *pdev; +struct net_device_stats net_stats;
drivers/net/pch_gbe/pch_gbe.h line 635
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe.h new file +10
-0+struct net_device *polling_netdev; +struct napi_struct napi; +struct pch_gbe_hw hw; +struct pch_gbe_hw_stats stats; +struct work_struct reset_task; +struct mii_if_info mii; +struct timer_list watchdog_timer; +u32 wake_up_evt; +u32 *config_space; +struct timer_list blink_timer;
unused
Quoted 9 lines
drivers/net/pch_gbe/pch_gbe.h new file +9
-0+unsigned long led_status; +struct pch_gbe_tx_ring *tx_ring; +struct pch_gbe_rx_ring *rx_ring; +unsigned long rx_buffer_len; +unsigned long tx_queue_len; +bool rx_csum; +bool tx_csum; +bool have_msi; +};
drivers/net/pch_gbe/pch_gbe.h line 654
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe.h new file +10
-0+ +/** +* enum pch_gbe_state_t - Driver Status +* @__PCH_GBE_TESTING: Testing +* @__PCH_GBE_RESETTING: Reseting +*/ +enum pch_gbe_state_t { + __PCH_GBE_TESTING, + __PCH_GBE_RESETTING, +};
Why _t? It's not a typedef.
Quoted 3 lines
drivers/net/pch_gbe/pch_gbe_api.c new file +0
-0@@ -0,0 +1,246 @@
...
drivers/net/pch_gbe/pch_gbe_api.c line 119
Quoted 11 lines
drivers/net/pch_gbe/pch_gbe_api.c new file +11
-0+/** +* pch_gbe_hal_setup_init_funcs - Initializes function pointers +* @hw: Pointer to the HW structure +* Returns +* 0: Successfully +* ENOSYS: Function is not registered +*/ +inline s32 pch_gbe_hal_setup_init_funcs (struct pch_gbe_hw *hw) +{ +if (!hw->reg) { +pr_err ("ERROR: Registers not mapped\n" );
No pr_fmt in this file, this line is helpless. Reconsider using dev_* and netdev_* (dev_err, netdev_err and alike) printing wherever possible.
Quoted 4 lines
drivers/net/pch_gbe/pch_gbe_api.c new file +4
-0+return -ENOSYS ; + } +pch_gbe_plat_init_function_pointers (hw); +return 0 ;
drivers/net/pch_gbe/pch_gbe_api.c line 133
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe_api.c new file +10
-0+} + +/** +* pch_gbe_hal_get_bus_info - Obtain bus information for adapter +* @hw: Pointer to the HW structure +*/ +inline void pch_gbe_hal_get_bus_info (struct pch_gbe_hw *hw) +{ +if (!hw->func->get_bus_info) +pr_err ("ERROR: configuration\n" );
Ditto. And on some more places too.
Quoted 3 lines
drivers/net/pch_gbe/pch_gbe_ethtool.c new file +0
-0@@ -0,0 +1,620 @@
...
drivers/net/pch_gbe/pch_gbe_ethtool.c line 28
Quoted 9 lines
drivers/net/pch_gbe/pch_gbe_ethtool.c new file +9
-0+#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#include <linux/pci.h> +#include <linux/ethtool.h> + +#include "pch_gbe.h" +#include "pch_gbe_api.h" + +#define FUNC_ENTER () pr_devel("ethtool: %s enter\n", __func__) +#define FUNC_EXIT () pr_devel("ethtool: %s exit\n", __func__)
Why you need these when you have kprobes (or whatever the name for function entry/exit instrumentation is)?
Quoted 14 lines
drivers/net/pch_gbe/pch_gbe_ethtool.c new file +14
-0+/** +* pch_gbe_get_wol - Report whether Wake-on-Lan is enabled +* @netdev: Network interface device structure +* @wol: Wake-on-Lan information +*/ +static void pch_gbe_get_wol (struct net_device *netdev, +struct ethtool_wolinfo *wol) +{ +struct pch_gbe_adapter *adapter =netdev_priv (netdev); + +FUNC_ENTER (); + + wol->supported =WAKE_UCAST |WAKE_MCAST |WAKE_BCAST |WAKE_MAGIC ; + wol->wolopts =0 ;
drivers/net/pch_gbe/pch_gbe_ethtool.c line 237
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe_ethtool.c new file +10
-0+ +if ((adapter->wake_up_evt &PCH_GBE_WLC_IND )) + wol->wolopts |=WAKE_UCAST ; +if ((adapter->wake_up_evt &PCH_GBE_WLC_MLT )) + wol->wolopts |=WAKE_MCAST ; +if ((adapter->wake_up_evt &PCH_GBE_WLC_BR )) + wol->wolopts |=WAKE_BCAST ; +if ((adapter->wake_up_evt &PCH_GBE_WLC_MP )) + wol->wolopts |=WAKE_MAGIC ; +return ;
no need to return here.
Quoted 1 line
+}
...
Quoted 21 lines
drivers/net/pch_gbe/pch_gbe_ethtool.c new file +21
-0+/** +* pch_gbe_set_ringparam - Set ring sizes +* @netdev: Network interface device structure +* @ring: Ring param structure +* Returns +* 0: Successful. +* Negative value: Failed. +*/ +static int pch_gbe_set_ringparam (struct net_device *netdev, +struct ethtool_ringparam *ring) +{ +struct pch_gbe_adapter *adapter =netdev_priv (netdev); +struct pch_gbe_tx_ring *txdr, *tx_old; +struct pch_gbe_rx_ring *rxdr, *rx_old; +int tx_ring_size, rx_ring_size; +int err =0 ; +unsigned long flags; + +FUNC_ENTER (); +if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending)) +return -EINVAL ;
drivers/net/pch_gbe/pch_gbe_ethtool.c line 339
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe_ethtool.c new file +10
-0+ tx_ring_size = (int )sizeof (struct pch_gbe_tx_ring ); + rx_ring_size = (int )sizeof (struct pch_gbe_rx_ring ); + +spin_lock_irqsave (&adapter->ethtool_lock, flags); +if ((netif_running (adapter->netdev))) +pch_gbe_down (adapter); + tx_old = adapter->tx_ring; + rx_old = adapter->rx_ring; + + txdr =kzalloc (tx_ring_size,GFP_KERNEL );
This is deadlocable. You are calling sleeping allocation inside spinlock.
Quoted 4 lines
drivers/net/pch_gbe/pch_gbe_ethtool.c new file +4
-0+if (!txdr) { + err = -ENOMEM ; + goto err_alloc_tx; + }
drivers/net/pch_gbe/pch_gbe_ethtool.c line 353
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe_ethtool.c new file +10
-0+ rxdr =kzalloc (rx_ring_size,GFP_KERNEL ); +if (!rxdr) { + err = -ENOMEM ; + goto err_alloc_rx; + } + adapter->tx_ring = txdr; + adapter->rx_ring = rxdr; + + rxdr->count =max (ring->rx_pending, (u32 )PCH_GBE_MIN_RXD ); + rxdr->count =min (rxdr->count, (u32 )PCH_GBE_MAX_RXD );
clamp()
And why you need the cast?
drivers/net/pch_gbe/pch_gbe_ethtool.c line 362
Quoted 9 lines
drivers/net/pch_gbe/pch_gbe_ethtool.c new file +9
-0+ rxdr->count =roundup (rxdr->count,PCH_GBE_RX_DESC_MULTIPLE ); + + txdr->count =max (ring->tx_pending, (u32 )PCH_GBE_MIN_TXD ); + txdr->count =min (txdr->count, (u32 )PCH_GBE_MAX_TXD ); + txdr->count =roundup (txdr->count,PCH_GBE_TX_DESC_MULTIPLE ); + +if ((netif_running (adapter->netdev))) { +/* Try to get new resources before deleting old */ + err =pch_gbe_setup_rx_resources (adapter, adapter->rx_ring);
There is vmalloc inside. You really haven't tried sleep-inside-atomic debug option, have you?
In fact you alloc there (at most) PCH_GBE_MAX_TXD*sizeof(struct pch_gbe_rx_desc) = 4096*16=65k=order 16 of continuous (DMAable) space in the atomic context. This is likely to fail early.
Quoted 5 lines
drivers/net/pch_gbe/pch_gbe_ethtool.c new file +5
-0+if (err) + goto err_setup_rx; + err =pch_gbe_setup_tx_resources (adapter, adapter->tx_ring); +if (err) + goto err_setup_tx;
drivers/net/pch_gbe/pch_gbe_ethtool.c line 377
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe_ethtool.c new file +10
-0+/* save the new, restore the old in order to free it, +* then restore the new back again */ + adapter->rx_ring = rx_old; + adapter->tx_ring = tx_old; +pch_gbe_free_rx_resources (adapter, adapter->rx_ring); +pch_gbe_free_tx_resources (adapter, adapter->tx_ring); +kfree (tx_old); +kfree (rx_old); + adapter->rx_ring = rxdr; + adapter->tx_ring = txdr;
Why this shuffling? Isn't enough to free *x_old and set adapter->*x_ring?
drivers/net/pch_gbe/pch_gbe_ethtool.c
Quoted 1 line
drivers/net/pch_gbe/pch_gbe_ethtool.c new file +1
-0+ err =pch_gbe_up (adapter);
Well pch_gbe_up may sleep (via pch_gbe_request_irq via pci_enable_msi and request_irq) and you call it here and on other places from inside an atomic context.
Quoted 18 lines
drivers/net/pch_gbe/pch_gbe_ethtool.c new file +18
-0+ } +spin_unlock_irqrestore (&adapter->ethtool_lock, flags); +return err; + +err_setup_tx: +pch_gbe_free_rx_resources (adapter, adapter->rx_ring); +err_setup_rx: + adapter->rx_ring = rx_old; + adapter->tx_ring = tx_old; +kfree (rxdr); +err_alloc_rx: +kfree (txdr); +err_alloc_tx: +if (netif_running (adapter->netdev)) +pch_gbe_up (adapter); +spin_unlock_irqrestore (&adapter->ethtool_lock, flags); +return err; +}
...
Quoted 3 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +0
-0@@ -0,0 +1,2547 @@
...
Quoted 1 line
+#define
PCI_DEVICE_ID_INTEL_IOH1_GBE(u16)(0x8802) /* Pci device ID */
Why the cast?
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +10
-0+void pch_gbe_mac_mar_set (struct pch_gbe_hw *hw,u8 * addr,u32 index) +{ +u32 mar_low, mar_high, adrmask; + +FUNC_ENTER (); +pr_debug ("index : 0x%x\n" , index); + +/* +* HW expects these in little endian so we reverse the byte order +* from network order (big endian) to little endian
drivers/net/pch_gbe/pch_gbe_main.c line 142
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +10
-0+*/ + mar_high = ((u32 ) addr[0 ] | ((u32 ) addr[1 ] <<8 ) | + ((u32 ) addr[2 ] <<16 ) | ((u32 ) addr[3 ] <<24 )); + mar_low = ((u32 ) addr[4 ] | ((u32 ) addr[5 ] <<8 )); +/* Stop the MAC Address of index. */ + adrmask =ioread32 (&hw->reg->ADDR_MASK); +iowrite32 ((adrmask | (0x0001 << index)), &hw->reg->ADDR_MASK); +/* wait busy */ +while ((ioread32 (&hw->reg->ADDR_MASK) &PCH_GBE_BUSY )) +cpu_relax ();
There should be probably some time limit. Nobody trusts hardware.
drivers/net/pch_gbe/pch_gbe_main.c line 421
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +10
-0+static int pch_gbe_alloc_queues (struct pch_gbe_adapter *adapter) +{ +int size; + +FUNC_ENTER (); + size = (int )sizeof (struct pch_gbe_tx_ring ); + adapter->tx_ring =kmalloc (size,GFP_KERNEL ); +if (!adapter->tx_ring) +return -ENOMEM ; +memset (adapter->tx_ring,0 , size);
kzalloc()
drivers/net/pch_gbe/pch_gbe_main.c line 429
Quoted 8 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +8
-0+ + size = (int )sizeof (struct pch_gbe_rx_ring ); + adapter->rx_ring =kmalloc (size,GFP_KERNEL ); +if (!adapter->rx_ring) { +kfree (adapter->tx_ring); +return -ENOMEM ; + } +memset (adapter->rx_ring,0 , size);
Ditto.
drivers/net/pch_gbe/pch_gbe_main.c line 431
Quoted 1 line
drivers/net/pch_gbe/pch_gbe_main.c new file +1
-0+ size = (int )sizeof (struct net_device );
Unused?
Quoted 2 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +2
-0+return 0 ; +}
...
Quoted 13 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +13
-0+static void pch_gbe_free_irq (struct pch_gbe_adapter *adapter) +{ +struct net_device *netdev = adapter->netdev; + +FUNC_ENTER (); +free_irq (adapter->pdev->irq, netdev); +if (adapter->have_msi) { +pci_disable_msi (adapter->pdev); +pr_debug ("call pci_disable_msi\n" ); + } +} + +/**
drivers/net/pch_gbe/pch_gbe_main.c line 598
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +10
-0+* pch_gbe_irq_disable - Mask off interrupt generation on the NIC +* @adapter: Board private structure +*/ +static void pch_gbe_irq_disable (struct pch_gbe_adapter *adapter) +{ +struct pch_gbe_hw *hw = &adapter->hw; + +FUNC_ENTER (); +atomic_inc (&adapter->irq_sem); +iowrite32 (0 , &hw->reg->INT_EN);
You should flush posted writes here.
Quoted 4 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +4
-0+synchronize_irq (adapter->pdev->irq); + +pr_debug ("INT_EN reg : 0x%08x\n" ,ioread32 (&hw->reg->INT_EN)); +}
...
Quoted 12 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +12
-0+static void +pch_gbe_alloc_rx_buffers (struct pch_gbe_adapter *adapter, +struct pch_gbe_rx_ring *rx_ring,int cleaned_count) +{ +struct net_device *netdev = adapter->netdev; +struct pci_dev *pdev = adapter->pdev; +struct pch_gbe_hw *hw = &adapter->hw; +struct pch_gbe_rx_desc *rx_desc; +struct pch_gbe_buffer *buffer_info; +struct sk_buff *skb; +unsigned int i; +unsigned int bufsz;
...
drivers/net/pch_gbe/pch_gbe_main.c line 1228
Quoted 5 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +5
-0+if (likely (rx_ring->next_to_use != i)) { + rx_ring->next_to_use = i; +if (unlikely (i-- ==0 )) + i = (rx_ring->count -1 ); +wmb ();
Document the barrier.
Quoted 6 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +6
-0+iowrite32 (rx_ring->dma + + (int )sizeof (struct pch_gbe_rx_desc ) * i, + &hw->reg->RX_DSC_SW_P); + } +return ; +}
...
Quoted 4 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +4
-0+static int pch_gbe_sw_init (struct pch_gbe_adapter *adapter) +{ +struct pch_gbe_hw *hw = &adapter->hw; +struct net_device *netdev = adapter->netdev;
drivers/net/pch_gbe/pch_gbe_main.c line 1781
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +10
-0+struct pci_dev *pdev = adapter->pdev; + +FUNC_ENTER (); +/* PCI config space info */ + hw->vendor_id = pdev->vendor; + hw->device_id = pdev->device; + hw->subsystem_vendor_id = pdev->subsystem_vendor; + hw->subsystem_device_id = pdev->subsystem_device; + +pci_read_config_byte (pdev,PCI_REVISION_ID , &hw->revision_id);
pdev->revision?
Quoted 8 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +8
-0+static int pch_gbe_xmit_frame (struct sk_buff *skb,struct net_device *netdev) +{ +struct pch_gbe_adapter *adapter =netdev_priv (netdev); +struct pch_gbe_tx_ring *tx_ring = adapter->tx_ring; +unsigned long flags; + +FUNC_ENTER (); +if (unlikely (skb->len <=0 )) {
drivers/net/pch_gbe/pch_gbe_main.c line 1901
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +10
-0+dev_kfree_skb_any (skb); +pr_debug ("Return : OK skb len : %d\n" , skb->len); +return NETDEV_TX_OK ; + } +if (unlikely (skb->len > (adapter->hw.mac.max_frame_size -4 ))) { +pr_err ("Transfer length Error: skb len: %d > max: %d\n" , + skb->len, adapter->hw.mac.max_frame_size); +dev_kfree_skb_any (skb); + adapter->stats.tx_length_errors++; +return NETDEV_TX_BUSY ;
Not nice. ndev layer will reuse the freed skb now.
Quoted 1 line
drivers/net/pch_gbe/pch_gbe_main.c new file +1
-0+ }
...
Quoted 6 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +6
-0+static int pch_gbe_suspend (struct pci_dev *pdev,pm_message_t state) +{ +struct net_device *netdev =pci_get_drvdata (pdev); +struct pch_gbe_adapter *adapter =netdev_priv (netdev); +struct pch_gbe_hw *hw = &adapter->hw; +u32 wufc = adapter->wake_up_evt;
drivers/net/pch_gbe/pch_gbe_main.c line 2246
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +10
-0+int retval =0 ; + +FUNC_ENTER (); +netif_device_detach (netdev); +if (netif_running (netdev)) +pch_gbe_down (adapter); +#ifdef CONFIG_PM +/* Implement our own version of pci_save_state(pdev) because pci- +* express adapters have 256-byte config spaces. */ + retval =pci_save_state (pdev);
But PCIe saves all caps, why you need this?
Quoted 8 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +8
-0+static int pch_gbe_probe (struct pci_dev *pdev, +const struct pci_device_id *pci_id) +{ +struct net_device *netdev; +struct pch_gbe_adapter *adapter; +unsigned long mmio_start; +unsigned long mmio_len; +int ret;
drivers/net/pch_gbe/pch_gbe_main.c line 2352
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +10
-0+ +FUNC_ENTER (); + ret =pci_enable_device (pdev); +if (ret) +return ret; + +if (!dma_set_mask (&pdev->dev,DMA_BIT_MASK (64 )) + && !dma_set_coherent_mask (&pdev->dev,DMA_BIT_MASK (64 ))) { + ; + }else {
You should invert the logic. And use pci_ variants.
drivers/net/pch_gbe/pch_gbe_main.c line 2365
Quoted 13 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +13
-0+ ret =dma_set_mask (&pdev->dev,DMA_BIT_MASK (32 )); +if (ret) { + ret =dma_set_coherent_mask (&pdev->dev, +DMA_BIT_MASK (32 )); +if (ret) { +pr_err ("ERR: No usable DMA configuration, aborting\n" ); + goto err_disable_device; + } + } + } + ret =pci_request_regions (pdev,KBUILD_MODNAME ); +if (ret) { +pr_err ("ERR: Can't reserve PCI I/O and memory resources\n" );
Here (and below) you should use dev_err instead.
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +10
-0+ goto err_disable_device; + } +pci_set_master (pdev); + + netdev =alloc_etherdev ((int )sizeof (struct pch_gbe_adapter )); +if (!netdev) { + ret = -ENOMEM ; +pr_err ("ERR: Can't allocate and set up an Ethernet device\n" ); + goto err_release_pci; + }
drivers/net/pch_gbe/pch_gbe_main.c line 2385
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +10
-0+SET_NETDEV_DEV (netdev, &pdev->dev); + +pci_set_drvdata (pdev, netdev); + adapter =netdev_priv (netdev); + adapter->netdev = netdev; + adapter->pdev = pdev; + adapter->hw.back = adapter; + mmio_start =pci_resource_start (pdev,PCH_GBE_PCI_BAR ); + mmio_len =pci_resource_len (pdev,PCH_GBE_PCI_BAR ); + adapter->hw.reg =ioremap_nocache (mmio_start, mmio_len);
pci_ioremap_bar()
Anyway you should not use ioread/iowrite* on an ioremapped space. It is intended for iomapped space (pci_iomap) and is slower.
Quoted 37 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +37
-0+if (!adapter->hw.reg) { + ret = -EIO ; +pr_err ("Can't ioremap\n" ); + goto err_free_netdev; + } + + netdev->netdev_ops = &pch_gbe_netdev_ops; + netdev->watchdog_timeo =PCH_GBE_WATCHDOG_PERIOD ; +netif_napi_add (netdev, &adapter->napi, + pch_gbe_napi_poll,PCH_GBE_RX_WEIGHT ); + netdev->mem_start = mmio_start; + netdev->mem_end = mmio_start + mmio_len; + netdev->features =NETIF_F_HW_CSUM ; +pch_gbe_set_ethtool_ops (netdev); + +pch_gbe_mac_reset_hw (&adapter->hw); + +/* setup the private structure */ + ret =pch_gbe_sw_init (adapter); +if (ret) + goto err_iounmap; + +/* Initialize PHY */ + ret =pch_gbe_init_phy (adapter); +if (ret) { +pr_err ("PHY initialize error\n" ); + goto err_free_adapter; + } +pch_gbe_hal_get_bus_info (&adapter->hw); + +/* Read the MAC address. and store to the private data */ + ret =pch_gbe_hal_read_mac_addr (&adapter->hw); +if (ret) { +pr_err ("MAC address Read Error\n" ); + goto err_free_adapter; + } +
drivers/net/pch_gbe/pch_gbe_main.c line 2432
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +10
-0+memcpy (netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len); +if (!is_valid_ether_addr (netdev->dev_addr)) { +pr_err ("Invalid MAC Address\n" ); + ret = -EIO ; + goto err_free_adapter; + } + +init_timer (&adapter->watchdog_timer); + adapter->watchdog_timer.function = &pch_gbe_watchdog; + adapter->watchdog_timer.data = (unsigned long )adapter;
setup_timer()
drivers/net/pch_gbe/pch_gbe_main.c line 2512
Quoted 4 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +4
-0+static int __init pch_gbe_init_module (void ) +{ +int ret; +pr_info ("%s - version %s\n" ,DRV_STRING ,DRV_VERSION );
You don't want to do that. Boot log is polluted enough already.
Quoted 8 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +8
-0+ ret =pci_register_driver (&pch_gbe_pcidev); +if (copybreak !=PCH_GBE_COPYBREAK_DEFAULT ) { +if (copybreak ==0 ) { +pr_info ("copybreak disabled\n" ); + }else { +pr_info ("copybreak enabled for packets <= %u bytes\n" , + copybreak); + }
drivers/net/pch_gbe/pch_gbe_main.c line 2531
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +10
-0+ } +return ret; +} + +static void __exit pch_gbe_exit_module(void) +{ +FUNC_ENTER (); +pci_unregister_driver (&pch_gbe_pcidev); + +pr_info ("%s - unregister\n" ,DRV_STRING );
Get rid of that, please.
Quoted 3 lines
drivers/net/pch_gbe/pch_gbe_param.c new file +0
-0@@ -0,0 +1,507 @@
...
drivers/net/pch_gbe/pch_gbe_param.c line 242
Quoted 11 lines
drivers/net/pch_gbe/pch_gbe_param.c new file +11
-0+static void pch_gbe_check_copper_options (struct pch_gbe_adapter *adapter) +{ +struct pch_gbe_hw *hw = &adapter->hw; +int speed, dplx; + + {/* Speed */ +struct pch_gbe_opt_list speed_list[] = { + {0 ,"" }, + {SPEED_10 ,"" }, + {SPEED_100 ,"" }, + {SPEED_1000 ,"" } };
Is there a reason why these are not static const?
drivers/net/pch_gbe/pch_gbe_param.c line 254
Quoted 12 lines
drivers/net/pch_gbe/pch_gbe_param.c new file +12
-0+ +struct pch_gbe_option opt = { + .type = list_option, + .name ="Speed" , + .err ="parameter ignored" , + .def =0 , + .arg = { .l = { .nr = (int )ARRAY_SIZE (speed_list), + .p = speed_list } } + }; + speed = Speed; +pch_gbe_validate_option (&speed, &opt, adapter); + }
regards,
Signature · 2 lines
js suse labs
Quoted 4 lines · Masayuki Ohtake
Thank you for your comments and patch.
I have modified.
Gigabit Ethernet driver of Topcliff PCH
Patch created against 2.6.35
Hello Ohtake.
It's a bit tedious to track changes in this code when you post the entire patch.
Do you have a git tree for these Topcliff changes?
Hi Jiri
Thank you for your comments.
I confirm them.
And I will modify this patch.
Thanks, Ohtake
----- Original Message -----
From: "Jiri Slaby" <[email protected]>
To: "Masayuki Ohtake" <[email protected]>
Cc: "Randy Dunlap" <[email protected]>; "Ralf Baechle" <[email protected]>; "ML netdev" <[email protected]>; "MeeGo" <[email protected]>; "Maxime Bizon" <[email protected]>; "LKML" <[email protected]>; "Kristoffer Glembo" <[email protected]>; "John Linn" <[email protected]>; "Joe Perches" <[email protected]>; "Greg Rose" <[email protected]>; "David S. Miller" <[email protected]>; "Wang, Yong Y" <[email protected]>; "Wang, Qi" <[email protected]>; "Toshiharu Okada" <[email protected]>; "Tomoya Morinaga" <[email protected]>; "Takahiro Shimizu" <[email protected]>; "Intel OTC" <[email protected]>; "Foster, Margie" <[email protected]>; "Andrew" <[email protected]>
Sent: Saturday, September 04, 2010 1:35 AM
Subject: Re: [PATCH] Gigabit Ethernet driver of Topcliff PCH
Quoted 764 lines
Hi, I wrote few comments below.
drivers/net/Kconfig menuconfig NETDEV_1000 · line 2009
Quoted 10 lines · Masayuki Ohtake
drivers/net/Kconfig +0
-1@@ -2004,7 +2004,6 @@ menuconfig NETDEV_1000 If you say N, all options in this submenu will be skipped and disabled. if NETDEV_1000 - config ACENIC tristate "Alteon AceNIC/3Com 3C985/NetGear GA620 Gigabit support" depends on PCIThis hunk is unwanted, I think.
Quoted 3 lines
drivers/net/pch_gbe/pch_gbe.h new file +0
-0@@ -0,0 +1,683 @@...
Quoted 54 lines
drivers/net/pch_gbe/pch_gbe.h new file +54
-0+/** +* pch_gbe_regs_mac_adr - Structure holding values of mac address registers +* @high Denotes the 1st to 4th byte from the initial of MAC address +* @low Denotes the 5th to 6th byte from the initial of MAC address +*/ +struct pch_gbe_regs_mac_adr { +u32 high; +u32 low; +}; +/** +* pch_udc_regs - Structure holding values of MAC registers +*/ +struct pch_gbe_regs { +u32 INT_ST; +u32 INT_EN; +u32 MODE; +u32 RESET; +u32 TCPIP_ACC; +u32 EX_LIST; +u32 INT_ST_HOLD; +u32 PHY_INT_CTRL; +u32 MAC_RX_EN; +u32 RX_FCTRL; +u32 PAUSE_REQ; +u32 RX_MODE; +u32 TX_MODE; +u32 RX_FIFO_ST; +u32 TX_FIFO_ST; +u32 TX_FID; +u32 TX_RESULT; +u32 PAUSE_PKT1; +u32 PAUSE_PKT2; +u32 PAUSE_PKT3; +u32 PAUSE_PKT4; +u32 PAUSE_PKT5; +u32 reserve[2 ]; +struct pch_gbe_regs_mac_adr mac_adr[16 ]; +u32 ADDR_MASK; +u32 MIIM; +u32 reserve2; +u32 RGMII_ST; +u32 RGMII_CTRL; +u32 reserve3[3 ]; +u32 DMA_CTRL; +u32 reserve4[3 ]; +u32 RX_DSC_BASE; +u32 RX_DSC_SIZE; +u32 RX_DSC_HW_P; +u32 RX_DSC_HW_P_HLD; +u32 RX_DSC_SW_P; +u32 reserve5[3 ]; +u32 TX_DSC_BASE; +u32 TX_DSC_SIZE; +u32 TX_DSC_HW_P;drivers/net/pch_gbe/pch_gbe.h line 90
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe.h new file +10
-0+u32 TX_DSC_HW_P_HLD ; +u32 TX_DSC_SW_P ; +u32 reserve6[3 ]; +u32 RX_DMA_ST ; +u32 TX_DMA_ST ; +u32 reserve7[2 ]; +u32 WOL_ST ; +u32 WOL_CTRL ; +u32 WOL_ADDR_MASK ; +};Shouldn't that be packed? As it is full of u32, probably not, but consider this comment when thinking about all structures you have here.
drivers/net/pch_gbe/pch_gbe.h line 303
Quoted 7 lines
drivers/net/pch_gbe/pch_gbe.h new file +7
-0+/* Device Driver infomation */ +#define DRV_STRING "PCH Network Driver" +#define DRV_EXT "-NAPI" +#define DRV_VERSION "0.95"DRV_EXT +#define DRV_DESCRIPTION \ + "OKI semiconductor sample Linux driver for PCH Gigabit ethernet" +#define DRV_COPYRIGHT "Copyright(c) 2010 OKI semiconductor"Why you need these defines?
Quoted 6 lines
drivers/net/pch_gbe/pch_gbe.h new file +6
-0+struct pch_gbe_hw { +void *back; + +struct pch_gbe_regs __iomem *reg; +spinlock_t miim_lock; +drivers/net/pch_gbe/pch_gbe.h line 426
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe.h new file +10
-0+const struct pch_gbe_functions *func; +struct pch_gbe_mac_info mac; +struct pch_gbe_phy_info phy; +struct pch_gbe_bus_info bus; + +u16 vendor_id; +u16 device_id; +u16 subsystem_vendor_id; +u16 subsystem_device_id; +u8 revision_id;What you need these IDs for?
Quoted 33 lines
drivers/net/pch_gbe/pch_gbe.h new file +33
-0+}; + +/** +* struct pch_gbe_rx_desc - Receive Descriptor +* @buffer_addr: RX Frame Buffer Address +* @tcp_ip_status: TCP/IP Accelerator Status +* @rx_words_eob: RX word count and Byte position +* @gbec_status: GMAC Status +* @dma_status: DMA Status +* @reserved1: Reserved +* @reserved2: Reserved +*/ +struct pch_gbe_rx_desc { +u32 buffer_addr; +u32 tcp_ip_status; +u16 rx_words_eob; +u16 gbec_status; +u8 dma_status; +u8 reserved1; +u16 reserved2; +}; + +/** +* struct pch_gbe_tx_desc - Transmit Descriptor +* @buffer_addr: TX Frame Buffer Address +* @length: Data buffer length +* @reserved1: Reserved +* @tx_words_eob: TX word count and Byte position +* @tx_frame_ctrl: TX Frame Control +* @dma_status: DMA Status +* @reserved2: Reserved +* @gbec_status: GMAC Status +*/ drivers/net/pch_gbe/pch_gbe.h line 469
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe.h new file +10
-0+struct pch_gbe_tx_desc { +u32 buffer_addr; +u16 length; +u16 reserved1; +u16 tx_words_eob; +u16 tx_frame_ctrl; +u8 dma_status; +u8 reserved2; +u16 gbec_status; +};packed?
Quoted 3 lines
+struct
pch_gbe_adapter{
+spinlock_tstats_lock;
+spinlock_ttx_queue_lock;unitialized
Quoted 1 line
+
spinlock_tint_en_lock;unused
Quoted 7 lines
+
spinlock_tethtool_lock;
+atomic_tirq_sem;
+ structnet_device*netdev;
+ structpci_dev*pdev;
+ structnet_device_statsnet_stats;
+ structnet_device*polling_netdev;
+ structnapi_structnapi;Quoted 8 lines
+ struct
pch_gbe_hwhw;
+ structpch_gbe_hw_statsstats;
+ structwork_structreset_task;
+ structmii_if_infomii;
+ structtimer_listwatchdog_timer;
+ u32wake_up_evt;
+ u32*config_space;
+ structtimer_listblink_timer;unused
Quoted 9 lines
+ unsigned long
led_status;
+ structpch_gbe_tx_ring*tx_ring;
+ structpch_gbe_rx_ring*rx_ring;
+ unsigned longrx_buffer_len;
+ unsigned longtx_queue_len;
+ boolrx_csum;
+ booltx_csum;
+ boolhave_msi;drivers/net/pch_gbe/pch_gbe.h new file +1
-0+};drivers/net/pch_gbe/pch_gbe.h line 654
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe.h new file +10
-0+ +/** +* enum pch_gbe_state_t - Driver Status +* @__PCH_GBE_TESTING: Testing +* @__PCH_GBE_RESETTING: Reseting +*/ +enum pch_gbe_state_t { + __PCH_GBE_TESTING, + __PCH_GBE_RESETTING, +};Why _t? It's not a typedef.
Quoted 3 lines
drivers/net/pch_gbe/pch_gbe_api.c new file +0
-0@@ -0,0 +1,246 @@...
drivers/net/pch_gbe/pch_gbe_api.c line 119
Quoted 11 lines
drivers/net/pch_gbe/pch_gbe_api.c new file +11
-0+/** +* pch_gbe_hal_setup_init_funcs - Initializes function pointers +* @hw: Pointer to the HW structure +* Returns +* 0: Successfully +* ENOSYS: Function is not registered +*/ +inline s32 pch_gbe_hal_setup_init_funcs (struct pch_gbe_hw *hw) +{ +if (!hw->reg) { +pr_err ("ERROR: Registers not mapped\n" );No
pr_fmtin this file, this line is helpless. Reconsider using dev_* and netdev_* (dev_err,netdev_errand alike) printing wherever possible.Quoted 4 lines
+ return
-ENOSYS;
+ }
+pch_gbe_plat_init_function_pointers(hw);
+ return 0;drivers/net/pch_gbe/pch_gbe_api.c line 133
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe_api.c new file +10
-0+} + +/** +* pch_gbe_hal_get_bus_info - Obtain bus information for adapter +* @hw: Pointer to the HW structure +*/ +inline void pch_gbe_hal_get_bus_info (struct pch_gbe_hw *hw) +{ +if (!hw->func->get_bus_info) +pr_err ("ERROR: configuration\n" );Ditto. And on some more places too.
Quoted 3 lines
drivers/net/pch_gbe/pch_gbe_ethtool.c new file +0
-0@@ -0,0 +1,620 @@...
drivers/net/pch_gbe/pch_gbe_ethtool.c line 28
Quoted 9 lines
drivers/net/pch_gbe/pch_gbe_ethtool.c new file +9
-0+#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#include <linux/pci.h> +#include <linux/ethtool.h> + +#include "pch_gbe.h" +#include "pch_gbe_api.h" + +#define FUNC_ENTER () pr_devel("ethtool: %s enter\n", __func__) +#define FUNC_EXIT () pr_devel("ethtool: %s exit\n", __func__)Why you need these when you have kprobes (or whatever the name for function entry/exit instrumentation is)?
Quoted 14 lines
drivers/net/pch_gbe/pch_gbe_ethtool.c new file +14
-0+/** +* pch_gbe_get_wol - Report whether Wake-on-Lan is enabled +* @netdev: Network interface device structure +* @wol: Wake-on-Lan information +*/ +static void pch_gbe_get_wol (struct net_device *netdev, +struct ethtool_wolinfo *wol) +{ +struct pch_gbe_adapter *adapter =netdev_priv (netdev); + +FUNC_ENTER (); + + wol->supported =WAKE_UCAST |WAKE_MCAST |WAKE_BCAST |WAKE_MAGIC ; + wol->wolopts =0 ;drivers/net/pch_gbe/pch_gbe_ethtool.c line 237
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe_ethtool.c new file +10
-0+ +if ((adapter->wake_up_evt &PCH_GBE_WLC_IND )) + wol->wolopts |=WAKE_UCAST ; +if ((adapter->wake_up_evt &PCH_GBE_WLC_MLT )) + wol->wolopts |=WAKE_MCAST ; +if ((adapter->wake_up_evt &PCH_GBE_WLC_BR )) + wol->wolopts |=WAKE_BCAST ; +if ((adapter->wake_up_evt &PCH_GBE_WLC_MP )) + wol->wolopts |=WAKE_MAGIC ; +return ;no need to return here.
Quoted 1 line
+}
...
Quoted 21 lines
drivers/net/pch_gbe/pch_gbe_ethtool.c new file +21
-0+/** +* pch_gbe_set_ringparam - Set ring sizes +* @netdev: Network interface device structure +* @ring: Ring param structure +* Returns +* 0: Successful. +* Negative value: Failed. +*/ +static int pch_gbe_set_ringparam (struct net_device *netdev, +struct ethtool_ringparam *ring) +{ +struct pch_gbe_adapter *adapter =netdev_priv (netdev); +struct pch_gbe_tx_ring *txdr, *tx_old; +struct pch_gbe_rx_ring *rxdr, *rx_old; +int tx_ring_size, rx_ring_size; +int err =0 ; +unsigned long flags; + +FUNC_ENTER (); +if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending)) +return -EINVAL ;drivers/net/pch_gbe/pch_gbe_ethtool.c line 339
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe_ethtool.c new file +10
-0+ tx_ring_size = (int )sizeof (struct pch_gbe_tx_ring ); + rx_ring_size = (int )sizeof (struct pch_gbe_rx_ring ); + +spin_lock_irqsave (&adapter->ethtool_lock, flags); +if ((netif_running (adapter->netdev))) +pch_gbe_down (adapter); + tx_old = adapter->tx_ring; + rx_old = adapter->rx_ring; + + txdr =kzalloc (tx_ring_size,GFP_KERNEL );This is deadlocable. You are calling sleeping allocation inside spinlock.
Quoted 6 lines
+ if (!txdr) {
+ err =-ENOMEM;
+ gotoerr_alloc_tx;
+ }
+ rxdr =kzalloc(rx_ring_size, GFP_KERNEL);
+ if (!rxdr) {Quoted 8 lines
+ err =
-ENOMEM;
+ gotoerr_alloc_rx;
+ }
+adapter->tx_ring= txdr;
+adapter->rx_ring= rxdr;
+
+rxdr->count=max(ring->rx_pending, (u32) PCH_GBE_MIN_RXD);
+rxdr->count=min(rxdr->count, (u32) PCH_GBE_MAX_RXD);
clamp()
And why you need the cast?drivers/net/pch_gbe/pch_gbe_ethtool.c line 362
Quoted 9 lines
+
rxdr->count=roundup(rxdr->count, PCH_GBE_RX_DESC_MULTIPLE);drivers/net/pch_gbe/pch_gbe_ethtool.c new file +8
-0+ + txdr->count =max (ring->tx_pending, (u32 )PCH_GBE_MIN_TXD ); + txdr->count =min (txdr->count, (u32 )PCH_GBE_MAX_TXD ); + txdr->count =roundup (txdr->count,PCH_GBE_TX_DESC_MULTIPLE ); + +if ((netif_running (adapter->netdev))) { +/* Try to get new resources before deleting old */ + err =pch_gbe_setup_rx_resources (adapter, adapter->rx_ring);There is vmalloc inside. You really haven't tried sleep-inside-atomic debug option, have you?
In fact you alloc there (at most) PCH_GBE_MAX_TXD*sizeof(struct
pch_gbe_rx_desc) = 4096*16=65k=order 16 of continuous (DMAable) space in the atomic context. This is likely to fail early.Quoted 7 lines
+ if (err)
+ gotoerr_setup_rx;
+ err =pch_gbe_setup_tx_resources(adapter, adapter->tx_ring);
+ if (err)
+ gotoerr_setup_tx;
+ /* save the new, restore the old in order to free it,
+ * then restore the new back again */Quoted 8 lines
+
adapter->rx_ring=rx_old;
+adapter->tx_ring=tx_old;
+pch_gbe_free_rx_resources(adapter, adapter->rx_ring);
+pch_gbe_free_tx_resources(adapter, adapter->tx_ring);
+kfree(tx_old);
+kfree(rx_old);
+adapter->rx_ring= rxdr;
+adapter->tx_ring= txdr;Why this shuffling? Isn't enough to free
*x_oldand set adapter->*x_ring?Quoted 1 line
+ err =
pch_gbe_up(adapter);Well
pch_gbe_upmay sleep (viapch_gbe_request_irqviapci_enable_msiandrequest_irq) and you call it here and on other places from inside an atomic context.Quoted 18 lines
+ }
+spin_unlock_irqrestore(&adapter->ethtool_lock, flags);
+ return err;drivers/net/pch_gbe/pch_gbe_ethtool.c new file +15
-0+ +err_setup_tx: +pch_gbe_free_rx_resources (adapter, adapter->rx_ring); +err_setup_rx: + adapter->rx_ring = rx_old; + adapter->tx_ring = tx_old; +kfree (rxdr); +err_alloc_rx: +kfree (txdr); +err_alloc_tx: +if (netif_running (adapter->netdev)) +pch_gbe_up (adapter); +spin_unlock_irqrestore (&adapter->ethtool_lock, flags); +return err; +}...
Quoted 3 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +0
-0@@ -0,0 +1,2547 @@...
Quoted 1 line
+#define
PCI_DEVICE_ID_INTEL_IOH1_GBE(u16)(0x8802) /* Pci device ID */Why the cast?
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +10
-0+void pch_gbe_mac_mar_set (struct pch_gbe_hw *hw,u8 * addr,u32 index) +{ +u32 mar_low, mar_high, adrmask; + +FUNC_ENTER (); +pr_debug ("index : 0x%x\n" , index); + +/* +* HW expects these in little endian so we reverse the byte order +* from network order (big endian) to little endian drivers/net/pch_gbe/pch_gbe_main.c line 142
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +10
-0+*/ + mar_high = ((u32 ) addr[0 ] | ((u32 ) addr[1 ] <<8 ) | + ((u32 ) addr[2 ] <<16 ) | ((u32 ) addr[3 ] <<24 )); + mar_low = ((u32 ) addr[4 ] | ((u32 ) addr[5 ] <<8 )); +/* Stop the MAC Address of index. */ + adrmask =ioread32 (&hw->reg->ADDR_MASK); +iowrite32 ((adrmask | (0x0001 << index)), &hw->reg->ADDR_MASK); +/* wait busy */ +while ((ioread32 (&hw->reg->ADDR_MASK) &PCH_GBE_BUSY )) +cpu_relax ();There should be probably some time limit. Nobody trusts hardware.
drivers/net/pch_gbe/pch_gbe_main.c line 421
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +10
-0+static int pch_gbe_alloc_queues (struct pch_gbe_adapter *adapter) +{ +int size; + +FUNC_ENTER (); + size = (int )sizeof (struct pch_gbe_tx_ring ); + adapter->tx_ring =kmalloc (size,GFP_KERNEL ); +if (!adapter->tx_ring) +return -ENOMEM ; +memset (adapter->tx_ring,0 , size);
kzalloc()Quoted 8 lines
+
+ size = (int)sizeof(structpch_gbe_rx_ring);
+adapter->rx_ring=kmalloc(size, GFP_KERNEL);
+ if (!adapter->rx_ring) {
+kfree(adapter->tx_ring);
+ return-ENOMEM;
+ }
+memset(adapter->rx_ring, 0, size);Ditto.
Quoted 1 line
+ size = (int)sizeof(struct
net_device);Unused?
Quoted 2 lines
+ return 0;
+}...
Quoted 13 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +13
-0+static void pch_gbe_free_irq (struct pch_gbe_adapter *adapter) +{ +struct net_device *netdev = adapter->netdev; + +FUNC_ENTER (); +free_irq (adapter->pdev->irq, netdev); +if (adapter->have_msi) { +pci_disable_msi (adapter->pdev); +pr_debug ("call pci_disable_msi\n" ); + } +} + +/** drivers/net/pch_gbe/pch_gbe_main.c line 598
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +10
-0+* pch_gbe_irq_disable - Mask off interrupt generation on the NIC +* @adapter: Board private structure +*/ +static void pch_gbe_irq_disable (struct pch_gbe_adapter *adapter) +{ +struct pch_gbe_hw *hw = &adapter->hw; + +FUNC_ENTER (); +atomic_inc (&adapter->irq_sem); +iowrite32 (0 , &hw->reg->INT_EN);You should flush posted writes here.
Quoted 4 lines
+
synchronize_irq(adapter->pdev->irq);drivers/net/pch_gbe/pch_gbe_main.c new file +3
-0+ +pr_debug ("INT_EN reg : 0x%08x\n" ,ioread32 (&hw->reg->INT_EN)); +}...
Quoted 12 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +12
-0+static void +pch_gbe_alloc_rx_buffers (struct pch_gbe_adapter *adapter, +struct pch_gbe_rx_ring *rx_ring,int cleaned_count) +{ +struct net_device *netdev = adapter->netdev; +struct pci_dev *pdev = adapter->pdev; +struct pch_gbe_hw *hw = &adapter->hw; +struct pch_gbe_rx_desc *rx_desc; +struct pch_gbe_buffer *buffer_info; +struct sk_buff *skb; +unsigned int i; +unsigned int bufsz;...
Quoted 5 lines
+ if (
likely(rx_ring->next_to_use != i)) {
+rx_ring->next_to_use= i;
+ if (unlikely(i-- == 0))
+ i = (rx_ring->count- 1);
+wmb();Document the barrier.
Quoted 6 lines
+ iowrite32(rx_ring->dma +
drivers/net/pch_gbe/pch_gbe_main.c new file +5
-0+ (int )sizeof (struct pch_gbe_rx_desc ) * i, + &hw->reg->RX_DSC_SW_P); + } +return ; +}...
Quoted 4 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +4
-0+static int pch_gbe_sw_init (struct pch_gbe_adapter *adapter) +{ +struct pch_gbe_hw *hw = &adapter->hw; +struct net_device *netdev = adapter->netdev;drivers/net/pch_gbe/pch_gbe_main.c line 1781
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +10
-0+struct pci_dev *pdev = adapter->pdev; + +FUNC_ENTER (); +/* PCI config space info */ + hw->vendor_id = pdev->vendor; + hw->device_id = pdev->device; + hw->subsystem_vendor_id = pdev->subsystem_vendor; + hw->subsystem_device_id = pdev->subsystem_device; + +pci_read_config_byte (pdev,PCI_REVISION_ID , &hw->revision_id);
pdev->revision?Quoted 8 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +8
-0+static int pch_gbe_xmit_frame (struct sk_buff *skb,struct net_device *netdev) +{ +struct pch_gbe_adapter *adapter =netdev_priv (netdev); +struct pch_gbe_tx_ring *tx_ring = adapter->tx_ring; +unsigned long flags; + +FUNC_ENTER (); +if (unlikely (skb->len <=0 )) {drivers/net/pch_gbe/pch_gbe_main.c line 1901
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +10
-0+dev_kfree_skb_any (skb); +pr_debug ("Return : OK skb len : %d\n" , skb->len); +return NETDEV_TX_OK ; + } +if (unlikely (skb->len > (adapter->hw.mac.max_frame_size -4 ))) { +pr_err ("Transfer length Error: skb len: %d > max: %d\n" , + skb->len, adapter->hw.mac.max_frame_size); +dev_kfree_skb_any (skb); + adapter->stats.tx_length_errors++; +return NETDEV_TX_BUSY ;Not nice. ndev layer will reuse the freed skb now.
Quoted 1 line
+ }
...
Quoted 6 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +6
-0+static int pch_gbe_suspend (struct pci_dev *pdev,pm_message_t state) +{ +struct net_device *netdev =pci_get_drvdata (pdev); +struct pch_gbe_adapter *adapter =netdev_priv (netdev); +struct pch_gbe_hw *hw = &adapter->hw; +u32 wufc = adapter->wake_up_evt;drivers/net/pch_gbe/pch_gbe_main.c line 2246
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +10
-0+int retval =0 ; + +FUNC_ENTER (); +netif_device_detach (netdev); +if (netif_running (netdev)) +pch_gbe_down (adapter); +#ifdef CONFIG_PM +/* Implement our own version of pci_save_state(pdev) because pci- +* express adapters have 256-byte config spaces. */ + retval =pci_save_state (pdev);But PCIe saves all caps, why you need this?
Quoted 8 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +8
-0+static int pch_gbe_probe (struct pci_dev *pdev, +const struct pci_device_id *pci_id) +{ +struct net_device *netdev; +struct pch_gbe_adapter *adapter; +unsigned long mmio_start; +unsigned long mmio_len; +int ret;drivers/net/pch_gbe/pch_gbe_main.c line 2352
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +10
-0+ +FUNC_ENTER (); + ret =pci_enable_device (pdev); +if (ret) +return ret; + +if (!dma_set_mask (&pdev->dev,DMA_BIT_MASK (64 )) + && !dma_set_coherent_mask (&pdev->dev,DMA_BIT_MASK (64 ))) { + ; + }else {You should invert the logic. And use
pci_variants.Quoted 5 lines
+ ret =
dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
+ if (ret) {
+ ret = dma_set_coherent_mask(&pdev->dev,
+DMA_BIT_MASK(32));
+ if (ret) {Quoted 8 lines
+
pr_err("ERR: No usable DMA configuration, aborting\n");
+ gotoerr_disable_device;
+ }
+ }
+ }
+ ret =pci_request_regions(pdev, KBUILD_MODNAME);
+ if (ret) {
+pr_err("ERR: Can't reserve PCI I/O and memory resources\n");Here (and below) you should use
dev_errinstead.Quoted 10 lines
+ goto
err_disable_device;
+ }
+pci_set_master(pdev);drivers/net/pch_gbe/pch_gbe_main.c new file +7
-0+ + netdev =alloc_etherdev ((int )sizeof (struct pch_gbe_adapter )); +if (!netdev) { + ret = -ENOMEM ; +pr_err ("ERR: Can't allocate and set up an Ethernet device\n" ); + goto err_release_pci; + }drivers/net/pch_gbe/pch_gbe_main.c line 2385
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +10
-0+SET_NETDEV_DEV (netdev, &pdev->dev); + +pci_set_drvdata (pdev, netdev); + adapter =netdev_priv (netdev); + adapter->netdev = netdev; + adapter->pdev = pdev; + adapter->hw.back = adapter; + mmio_start =pci_resource_start (pdev,PCH_GBE_PCI_BAR ); + mmio_len =pci_resource_len (pdev,PCH_GBE_PCI_BAR ); + adapter->hw.reg =ioremap_nocache (mmio_start, mmio_len);
pci_ioremap_bar()Anyway you should not use ioread/iowrite* on an ioremapped space. It is intended for iomapped space (
pci_iomap) and is slower.Quoted 37 lines
+ if (!adapter->hw.reg) {
+ ret =-EIO;
+pr_err("Can't ioremap\n");
+ gotoerr_free_netdev;
+ }drivers/net/pch_gbe/pch_gbe_main.c new file +32
-0+ + netdev->netdev_ops = &pch_gbe_netdev_ops; + netdev->watchdog_timeo =PCH_GBE_WATCHDOG_PERIOD ; +netif_napi_add (netdev, &adapter->napi, + pch_gbe_napi_poll,PCH_GBE_RX_WEIGHT ); + netdev->mem_start = mmio_start; + netdev->mem_end = mmio_start + mmio_len; + netdev->features =NETIF_F_HW_CSUM ; +pch_gbe_set_ethtool_ops (netdev); + +pch_gbe_mac_reset_hw (&adapter->hw); + +/* setup the private structure */ + ret =pch_gbe_sw_init (adapter); +if (ret) + goto err_iounmap; + +/* Initialize PHY */ + ret =pch_gbe_init_phy (adapter); +if (ret) { +pr_err ("PHY initialize error\n" ); + goto err_free_adapter; + } +pch_gbe_hal_get_bus_info (&adapter->hw); + +/* Read the MAC address. and store to the private data */ + ret =pch_gbe_hal_read_mac_addr (&adapter->hw); +if (ret) { +pr_err ("MAC address Read Error\n" ); + goto err_free_adapter; + } +drivers/net/pch_gbe/pch_gbe_main.c line 2432
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +10
-0+memcpy (netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len); +if (!is_valid_ether_addr (netdev->dev_addr)) { +pr_err ("Invalid MAC Address\n" ); + ret = -EIO ; + goto err_free_adapter; + } + +init_timer (&adapter->watchdog_timer); + adapter->watchdog_timer.function = &pch_gbe_watchdog; + adapter->watchdog_timer.data = (unsigned long )adapter;
setup_timer()drivers/net/pch_gbe/pch_gbe_main.c line 2512
Quoted 4 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +4
-0+static int __init pch_gbe_init_module (void ) +{ +int ret; +pr_info ("%s - version %s\n" ,DRV_STRING ,DRV_VERSION );You don't want to do that. Boot log is polluted enough already.
Quoted 10 lines
+ ret =
pci_register_driver(&pch_gbe_pcidev);
+ if (copybreak !=PCH_GBE_COPYBREAK_DEFAULT) {
+ if (copybreak == 0) {
+pr_info("copybreak disabled\n");
+ } else {
+ pr_info("copybreak enabled for packets <= %u bytes\n",
+ copybreak);
+ }
+ }
+ return ret;drivers/net/pch_gbe/pch_gbe_main.c line 2531
Quoted 8 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +8
-0+} + +static void __exit pch_gbe_exit_module(void) +{ +FUNC_ENTER (); +pci_unregister_driver (&pch_gbe_pcidev); + +pr_info ("%s - unregister\n" ,DRV_STRING );Get rid of that, please.
Quoted 3 lines
drivers/net/pch_gbe/pch_gbe_param.c new file +0
-0@@ -0,0 +1,507 @@...
drivers/net/pch_gbe/pch_gbe_param.c line 242
Quoted 11 lines
drivers/net/pch_gbe/pch_gbe_param.c new file +11
-0+static void pch_gbe_check_copper_options (struct pch_gbe_adapter *adapter) +{ +struct pch_gbe_hw *hw = &adapter->hw; +int speed, dplx; + + {/* Speed */ +struct pch_gbe_opt_list speed_list[] = { + {0 ,"" }, + {SPEED_10 ,"" }, + {SPEED_100 ,"" }, + {SPEED_1000 ,"" } };Is there a reason why these are not static const?
Quoted 4 lines
+
+ structpch_gbe_optionopt = {
+ .type =list_option,
+ .name = "Speed",Quoted 8 lines
+ .err = "parameter ignored", + .def = 0, + .arg = { .l = { .nr = (int)ARRAY_SIZE(speed_list),+ .p =
speed_list} }
+ };
+ speed = Speed;
+pch_gbe_validate_option(&speed, &opt, adapter);
+ }regards,
Signature · 2 lines
js suse labs
Hi Eric
Quoted 13 lines
Hmm, maybe you did this at the wrong place ?
Take a look at other drivers how they do this
(network stack default
hard_header_lento 14, innet/ethernet/eth.c, functionether_setup())find
drivers/net| xargs grep -nhard_header_lenExample in
drivers/net/wan/hdlc.cstatic void
hdlc_setup_dev(struct net_device *dev)
Quoted 12 lines
{
/* Re-init all variables changed by HDLC protocol drivers,
* including ether_setup() called from hdlc_raw_eth.c.
*/
dev->flags = IFF_POINTOPOINT | IFF_NOARP;
dev->priv_flags = IFF_WAN_HDLC;
dev->mtu = HDLC_MAX_MTU;
dev->type = ARPHRD_RAWHDLC;
dev->hard_header_len = 16;
dev->addr_len = 0;
dev->header_ops = &hdlc_null_ops;
}I confirm other driver.
As other driver, "hard_header_len" was set up before "register_netdev()"
However, I can not a single memcpy.
When changing "hard_header_len", The format of SKB received is following.
Lemgth=14 [padding:2octet] + [Header:14octet] + [payload] Lemgth=16 [padding:16octet] + [padding:2octet] + [Header:14octet] + [payload]
The format of my hopes is [Header:14octet] + [padding:2octet] + [payload] So, Currentry, this driver needs the following processings.
+ /* [Header:14][payload] ---> [Header:14][paddong:2][payload] */
+ memcpy(tmp_skb->data, skb->data, ETH_HLEN);
+ tmp_skb->data[ETH_HLEN] = 0x00;
+ tmp_skb->data[ETH_HLEN + 1] = 0x00;
+ tmp_skb->len = skb->len;
+ memcpy(&tmp_skb->data[ETH_HLEN + 2], &skb->data[ETH_HLEN],
+ (skb->len - ETH_HLEN));
Thanks Ohtake
---
Topcliff PCH is the platform controller hub that is going to be used in Intel's upcoming general embedded platform. All IO peripherals in Topcliff PCH are actually devices sitting on AMBA bus. Topcliff PCH has Gigabit Ethernet I/F. Using this I/F, it is able to access system devices connected to Gigabit Ethernet.
--- drivers/net/Kconfig | 13 +- drivers/net/Makefile | 1 + drivers/net/pch_gbe/Makefile | 5 + drivers/net/pch_gbe/pch_gbe.h | 683 +++++++++ drivers/net/pch_gbe/pch_gbe_api.c | 246 ++++ drivers/net/pch_gbe/pch_gbe_api.h | 34 + drivers/net/pch_gbe/pch_gbe_ethtool.c | 620 ++++++++ drivers/net/pch_gbe/pch_gbe_main.c | 2550 +++++++++++++++++++++++++++++++++ drivers/net/pch_gbe/pch_gbe_param.c | 507 +++++++ drivers/net/pch_gbe/pch_gbe_phy.c | 276 ++++ drivers/net/pch_gbe/pch_gbe_phy.h | 35 + 11 files changed, 4969 insertions(+), 1 deletions(-) create mode 100644 drivers/net/pch_gbe/Makefile create mode 100644 drivers/net/pch_gbe/pch_gbe.h create mode 100644 drivers/net/pch_gbe/pch_gbe_api.c create mode 100644 drivers/net/pch_gbe/pch_gbe_api.h create mode 100644 drivers/net/pch_gbe/pch_gbe_ethtool.c create mode 100644 drivers/net/pch_gbe/pch_gbe_main.c create mode 100644 drivers/net/pch_gbe/pch_gbe_param.c create mode 100644 drivers/net/pch_gbe/pch_gbe_phy.c create mode 100644 drivers/net/pch_gbe/pch_gbe_phy.h
drivers/net/Kconfig +12 -1
@@ -2004,7 +2004,6 @@ menuconfig NETDEV_1000 If you say N, all options in this submenu will be skipped and disabled. if NETDEV_1000 - config ACENIC tristate "Alteon AceNIC/3Com 3C985/NetGear GA620 Gigabit support" depends on PCI
@@ -2502,6 +2501,18 @@ config S6GMAC source "drivers/net/stmmac/Kconfig" +config PCH_GBE + tristate "PCH Gigabit Ethernet" + depends on PCI + ---help--- + This is a gigabit ethernet driver for Topcliff PCH. + Topcliff PCH is the platform controller hub that is used in Intel's + general embedded platform. + Topcliff PCH has Gigabit Ethernet interface. + Using this interface, it is able to access system devices connected + to Gigabit Ethernet. + This driver enables Gigabit Ethernet function. + endif # NETDEV_1000 #
drivers/net/Makefile +1 -0
@@ -295,3 +295,4 @@ obj-$(CONFIG_WIMAX) += wimax/ obj-$(CONFIG_CAIF) += caif/ obj-$(CONFIG_OCTEON_MGMT_ETHERNET) += octeon/ +obj-$(CONFIG_PCH_GBE) += pch_gbe/
drivers/net/pch_gbe/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +obj-$(CONFIG_PCH_GBE) += pch_gbe.o +EXTRA_CFLAGS += -DHARD_HEADER_LEN_16 + +pch_gbe-y := pch_gbe_phy.o pch_gbe_ethtool.o pch_gbe_param.o +pch_gbe-y += pch_gbe_api.o pch_gbe_main.o
drivers/net/pch_gbe/pch_gbe.h new file +683 -0
683 lines not on this page · raw message
drivers/net/pch_gbe/pch_gbe_api.c new file +246 -0
246 lines not on this page · raw message
drivers/net/pch_gbe/pch_gbe_api.h new file +34 -0
@@ -0,0 +1,34 @@ +/* +* Copyright (C) 1999 - 2010 Intel Corporation. +* Copyright (C) 2010 OKI SEMICONDUCTOR Co., LTD. +* +* This code was derived from the Intel e1000e Linux driver. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; version 2 of the License. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. +*/ +#ifndef _PCH_GBE_API_H_ +#define _PCH_GBE_API_H_ + +s32 pch_gbe_hal_setup_init_funcs (struct pch_gbe_hw *hw); +void pch_gbe_hal_get_bus_info (struct pch_gbe_hw *hw); +s32 pch_gbe_hal_init_hw (struct pch_gbe_hw *hw); +s32 pch_gbe_hal_read_phy_reg (struct pch_gbe_hw *hw,u32 offset,u16 *data); +s32 pch_gbe_hal_write_phy_reg (struct pch_gbe_hw *hw,u32 offset,u16 data); +void pch_gbe_hal_phy_hw_reset (struct pch_gbe_hw *hw); +void pch_gbe_hal_phy_sw_reset (struct pch_gbe_hw *hw); +s32 pch_gbe_hal_read_mac_addr (struct pch_gbe_hw *hw); +void pch_gbe_hal_power_up_phy (struct pch_gbe_hw *hw); +void pch_gbe_hal_power_down_phy (struct pch_gbe_hw *hw); + +#endif
drivers/net/pch_gbe/pch_gbe_ethtool.c new file +620 -0
620 lines not on this page · raw message
drivers/net/pch_gbe/pch_gbe_main.c new file +2550 -0
1,383 lines not on this page · raw message
drivers/net/pch_gbe/pch_gbe_param.c new file +507 -0
507 lines not on this page · raw message
drivers/net/pch_gbe/pch_gbe_phy.c new file +276 -0
276 lines not on this page · raw message
drivers/net/pch_gbe/pch_gbe_phy.h new file +35 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.6.2.5
Part of the diff is not shown here. View the raw message.
Hi Jiri
I have some questions.
Please see out inline comments.
Thanks, Ohtake
----- Original Message -----
From: "Jiri Slaby" <[email protected]>
To: "Masayuki Ohtake" <[email protected]>
Cc: "Randy Dunlap" <[email protected]>; "Ralf Baechle" <[email protected]>; "ML netdev" <[email protected]>; "MeeGo" <[email protected]>; "Maxime Bizon" <[email protected]>; "LKML" <[email protected]>; "Kristoffer Glembo" <[email protected]>; "John Linn" <[email protected]>; "Joe Perches" <[email protected]>; "Greg Rose" <[email protected]>; "David S. Miller" <[email protected]>; "Wang, Yong Y" <[email protected]>; "Wang, Qi" <[email protected]>; "Toshiharu Okada" <[email protected]>; "Tomoya Morinaga" <[email protected]>; "Takahiro Shimizu" <[email protected]>; "Intel OTC" <[email protected]>; "Foster, Margie" <[email protected]>; "Andrew" <[email protected]>
Sent: Saturday, September 04, 2010 1:35 AM
Subject: Re: [PATCH] Gigabit Ethernet driver of Topcliff PCH
Quoted 8 lines
Hi, I wrote few comments below.
Quoted 5 lines · Masayuki Ohtake
drivers/net/Kconfig +0
-0@@ -2004,7 +2004,6 @@ menuconfig NETDEV_1000 If you say N, all options in this submenu will be skipped and disabled.
Quoted 7 lines
drivers/net/Kconfig menuconfig NETDEV_1000 · line 2009
Quoted 5 lines
drivers/net/Kconfig +0
-1if NETDEV_1000 - config ACENIC tristate "Alteon AceNIC/3Com 3C985/NetGear GA620 Gigabit support" depends on PCIThis hunk is unwanted, I think.
[masa]
This will be deleted.
Quoted 64 lines
Quoted 4 lines
drivers/net/pch_gbe/pch_gbe.h new file +0
-0@@ -0,0 +1,683 @@...
Quoted 59 lines
drivers/net/pch_gbe/pch_gbe.h new file +59
-0+/** +* pch_gbe_regs_mac_adr - Structure holding values of mac address registers +* @high Denotes the 1st to 4th byte from the initial of MAC address +* @low Denotes the 5th to 6th byte from the initial of MAC address +*/ +struct pch_gbe_regs_mac_adr { +u32 high; +u32 low; +}; +/** +* pch_udc_regs - Structure holding values of MAC registers +*/ +struct pch_gbe_regs { +u32 INT_ST; +u32 INT_EN; +u32 MODE; +u32 RESET; +u32 TCPIP_ACC; +u32 EX_LIST; +u32 INT_ST_HOLD; +u32 PHY_INT_CTRL; +u32 MAC_RX_EN; +u32 RX_FCTRL; +u32 PAUSE_REQ; +u32 RX_MODE; +u32 TX_MODE; +u32 RX_FIFO_ST; +u32 TX_FIFO_ST; +u32 TX_FID; +u32 TX_RESULT; +u32 PAUSE_PKT1; +u32 PAUSE_PKT2; +u32 PAUSE_PKT3; +u32 PAUSE_PKT4; +u32 PAUSE_PKT5; +u32 reserve[2 ]; +struct pch_gbe_regs_mac_adr mac_adr[16 ]; +u32 ADDR_MASK; +u32 MIIM; +u32 reserve2; +u32 RGMII_ST; +u32 RGMII_CTRL; +u32 reserve3[3 ]; +u32 DMA_CTRL; +u32 reserve4[3 ]; +u32 RX_DSC_BASE; +u32 RX_DSC_SIZE; +u32 RX_DSC_HW_P; +u32 RX_DSC_HW_P_HLD; +u32 RX_DSC_SW_P; +u32 reserve5[3 ]; +u32 TX_DSC_BASE; +u32 TX_DSC_SIZE; +u32 TX_DSC_HW_P; +u32 TX_DSC_HW_P_HLD; +u32 TX_DSC_SW_P; +u32 reserve6[3 ]; +u32 RX_DMA_ST; +u32 TX_DMA_ST;
Quoted 8 lines
Quoted 5 lines
+ u32 reserve7[2];
+ u32WOL_ST;
+ u32WOL_CTRL;
+ u32WOL_ADDR_MASK;
+};Shouldn't that be packed? As it is full of u32, probably not, but consider this comment when thinking about all structures you have here.
[masa]
packed?
I am sorry, I can not understand.
Please let me know details.
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe.h line 303
Quoted 8 lines
drivers/net/pch_gbe/pch_gbe.h new file +7
-0+/* Device Driver infomation */ +#define DRV_STRING "PCH Network Driver" +#define DRV_EXT "-NAPI" +#define DRV_VERSION "0.95"DRV_EXT +#define DRV_DESCRIPTION \ + "OKI semiconductor sample Linux driver for PCH Gigabit ethernet" +#define DRV_COPYRIGHT "Copyright(c) 2010 OKI semiconductor"Why you need these defines?
[masa]
This will be deleted.
Quoted 11 lines
Quoted 11 lines
drivers/net/pch_gbe/pch_gbe.h new file +10
-0+struct pch_gbe_hw { +void *back; + +struct pch_gbe_regs __iomem *reg; +spinlock_t miim_lock; + +const struct pch_gbe_functions *func; +struct pch_gbe_mac_info mac; +struct pch_gbe_phy_info phy; +struct pch_gbe_bus_info bus;
Quoted 8 lines
Quoted 6 lines
+
+ u16vendor_id;
+ u16device_id;
+ u16subsystem_vendor_id;
+ u16subsystem_device_id;
+ u8revision_id;What you need these IDs for?
[masa]
This will be deleted.
Quoted 38 lines
Quoted 38 lines
drivers/net/pch_gbe/pch_gbe.h new file +37
-0+}; + +/** +* struct pch_gbe_rx_desc - Receive Descriptor +* @buffer_addr: RX Frame Buffer Address +* @tcp_ip_status: TCP/IP Accelerator Status +* @rx_words_eob: RX word count and Byte position +* @gbec_status: GMAC Status +* @dma_status: DMA Status +* @reserved1: Reserved +* @reserved2: Reserved +*/ +struct pch_gbe_rx_desc { +u32 buffer_addr; +u32 tcp_ip_status; +u16 rx_words_eob; +u16 gbec_status; +u8 dma_status; +u8 reserved1; +u16 reserved2; +}; + +/** +* struct pch_gbe_tx_desc - Transmit Descriptor +* @buffer_addr: TX Frame Buffer Address +* @length: Data buffer length +* @reserved1: Reserved +* @tx_words_eob: TX word count and Byte position +* @tx_frame_ctrl: TX Frame Control +* @dma_status: DMA Status +* @reserved2: Reserved +* @gbec_status: GMAC Status +*/ +struct pch_gbe_tx_desc { +u32 buffer_addr; +u16 length; +u16 reserved1;
Quoted 8 lines
Quoted 6 lines
+ u16
tx_words_eob;
+ u16tx_frame_ctrl;
+ u8dma_status;
+ u8 reserved2;
+ u16gbec_status;
+};packed?
[masa]
Ditto
Quoted 6 lines
Quoted 4 lines
+struct
pch_gbe_adapter{
+spinlock_tstats_lock;
+spinlock_ttx_queue_lock;unitialized
[masa]
This will be modified.
Quoted 4 lines
Quoted 2 lines
+
spinlock_tint_en_lock;unused
[masa]
This will be deleted.
Quoted 17 lines
Quoted 16 lines
+
spinlock_tethtool_lock;
+atomic_tirq_sem;
+ structnet_device*netdev;
+ structpci_dev*pdev;
+ structnet_device_statsnet_stats;
+ structnet_device*polling_netdev;
+ structnapi_structnapi;
+ structpch_gbe_hwhw;
+ structpch_gbe_hw_statsstats;
+ structwork_structreset_task;
+ structmii_if_infomii;
+ structtimer_listwatchdog_timer;
+ u32wake_up_evt;
+ u32*config_space;
+ structtimer_listblink_timer;
Quoted 1 line
unused
[masa]
This will be deleted.
Quoted 14 lines
Quoted 14 lines
+ unsigned long
led_status;
+ structpch_gbe_tx_ring*tx_ring;
+ structpch_gbe_rx_ring*rx_ring;
+ unsigned longrx_buffer_len;
+ unsigned longtx_queue_len;
+ boolrx_csum;
+ booltx_csum;
+ boolhave_msi;drivers/net/pch_gbe/pch_gbe.h new file +5
-0+}; + +/** +* enum pch_gbe_state_t - Driver Status +* @__PCH_GBE_TESTING: Testing
Quoted 8 lines
drivers/net/pch_gbe/pch_gbe.h line 654
Quoted 6 lines
+ * @__PCH_GBE_RESETTING: Reseting
+ */drivers/net/pch_gbe/pch_gbe.h new file +4
-0+enum pch_gbe_state_t { + __PCH_GBE_TESTING, + __PCH_GBE_RESETTING, +};Why _t? It's not a typedef.
[masa]
This will be deleted.
Quoted 5 lines
Quoted 4 lines
drivers/net/pch_gbe/pch_gbe_api.c new file +0
-0@@ -0,0 +1,246 @@...
Quoted 14 lines
drivers/net/pch_gbe/pch_gbe_api.c line 119
Quoted 11 lines
drivers/net/pch_gbe/pch_gbe_api.c new file +11
-0+/** +* pch_gbe_hal_setup_init_funcs - Initializes function pointers +* @hw: Pointer to the HW structure +* Returns +* 0: Successfully +* ENOSYS: Function is not registered +*/ +inline s32 pch_gbe_hal_setup_init_funcs (struct pch_gbe_hw *hw) +{ +if (!hw->reg) { +pr_err ("ERROR: Registers not mapped\n" );No
pr_fmtin this file, this line is helpless. Reconsider using dev_* and netdev_* (dev_err,netdev_errand alike) printing wherever possible.
[masa]
This will be modified pch_gbe.h.
"#define pr_fmt(fmt) KBUILD_MODNAME ": " tmt" is added
Quoted 22 lines
Quoted 5 lines
+ return
-ENOSYS;
+ }
+pch_gbe_plat_init_function_pointers(hw);
+ return 0;drivers/net/pch_gbe/pch_gbe_api.c line 133
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe_api.c new file +10
-0+} + +/** +* pch_gbe_hal_get_bus_info - Obtain bus information for adapter +* @hw: Pointer to the HW structure +*/ +inline void pch_gbe_hal_get_bus_info (struct pch_gbe_hw *hw) +{ +if (!hw->func->get_bus_info) +pr_err ("ERROR: configuration\n" );Ditto. And on some more places too.
Quoted 3 lines
drivers/net/pch_gbe/pch_gbe_ethtool.c new file +0
-0@@ -0,0 +1,620 @@...
Quoted 12 lines
drivers/net/pch_gbe/pch_gbe_ethtool.c line 28
Quoted 9 lines
drivers/net/pch_gbe/pch_gbe_ethtool.c new file +9
-0+#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#include <linux/pci.h> +#include <linux/ethtool.h> + +#include "pch_gbe.h" +#include "pch_gbe_api.h" + +#define FUNC_ENTER () pr_devel("ethtool: %s enter\n", __func__) +#define FUNC_EXIT () pr_devel("ethtool: %s exit\n", __func__)Why you need these when you have kprobes (or whatever the name for function entry/exit instrumentation is)?
[masa]
This will be deleted.
Quoted 19 lines
Quoted 19 lines
drivers/net/pch_gbe/pch_gbe_ethtool.c new file +18
-0+/** +* pch_gbe_get_wol - Report whether Wake-on-Lan is enabled +* @netdev: Network interface device structure +* @wol: Wake-on-Lan information +*/ +static void pch_gbe_get_wol (struct net_device *netdev, +struct ethtool_wolinfo *wol) +{ +struct pch_gbe_adapter *adapter =netdev_priv (netdev); + +FUNC_ENTER (); + + wol->supported =WAKE_UCAST |WAKE_MCAST |WAKE_BCAST |WAKE_MAGIC ; + wol->wolopts =0 ; + +if ((adapter->wake_up_evt &PCH_GBE_WLC_IND )) + wol->wolopts |=WAKE_UCAST ; +if ((adapter->wake_up_evt &PCH_GBE_WLC_MLT ))
Quoted 8 lines
Quoted 6 lines
+
wol->wolopts|=WAKE_MCAST;
+ if ((adapter->wake_up_evt&PCH_GBE_WLC_BR))
+wol->wolopts|=WAKE_BCAST;
+ if ((adapter->wake_up_evt&PCH_GBE_WLC_MP))
+wol->wolopts|=WAKE_MAGIC;
+ return;no need to return here.
[masa]
This will be deleted
Quoted 28 lines
Quoted 2 lines
+}
...
Quoted 25 lines
drivers/net/pch_gbe/pch_gbe_ethtool.c new file +25
-0+/** +* pch_gbe_set_ringparam - Set ring sizes +* @netdev: Network interface device structure +* @ring: Ring param structure +* Returns +* 0: Successful. +* Negative value: Failed. +*/ +static int pch_gbe_set_ringparam (struct net_device *netdev, +struct ethtool_ringparam *ring) +{ +struct pch_gbe_adapter *adapter =netdev_priv (netdev); +struct pch_gbe_tx_ring *txdr, *tx_old; +struct pch_gbe_rx_ring *rxdr, *rx_old; +int tx_ring_size, rx_ring_size; +int err =0 ; +unsigned long flags; + +FUNC_ENTER (); +if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending)) +return -EINVAL ; + tx_ring_size = (int )sizeof (struct pch_gbe_tx_ring ); + rx_ring_size = (int )sizeof (struct pch_gbe_rx_ring ); + +spin_lock_irqsave (&adapter->ethtool_lock, flags);
Quoted 8 lines
Quoted 6 lines
+ if ((
netif_running(adapter->netdev)))
+pch_gbe_down(adapter);
+tx_old=adapter->tx_ring;
+rx_old=adapter->rx_ring;
+
+ txdr =kzalloc(tx_ring_size, GFP_KERNEL);This is deadlocable. You are calling sleeping allocation inside spinlock.
[masa]
This will be modified
Since spin lock is deleted, this issue is lost.
Quoted 16 lines
Quoted 15 lines
+ if (!txdr) {
+ err =-ENOMEM;
+ gotoerr_alloc_tx;
+ }
+ rxdr =kzalloc(rx_ring_size, GFP_KERNEL);
+ if (!rxdr) {
+ err =-ENOMEM;
+ gotoerr_alloc_rx;
+ }
+adapter->tx_ring= txdr;
+adapter->rx_ring= rxdr;
+
+rxdr->count=max(ring->rx_pending, (u32) PCH_GBE_MIN_RXD);
+rxdr->count=min(rxdr->count, (u32) PCH_GBE_MAX_RXD);
Quoted 2 lines
clamp()
And why you need the cast?
[masa]
Since warning appears at the time of a make.
Quoted 14 lines
drivers/net/pch_gbe/pch_gbe_ethtool.c line 362
Quoted 10 lines
+
rxdr->count=roundup(rxdr->count, PCH_GBE_RX_DESC_MULTIPLE);drivers/net/pch_gbe/pch_gbe_ethtool.c new file +8
-0+ + txdr->count =max (ring->tx_pending, (u32 )PCH_GBE_MIN_TXD ); + txdr->count =min (txdr->count, (u32 )PCH_GBE_MAX_TXD ); + txdr->count =roundup (txdr->count,PCH_GBE_TX_DESC_MULTIPLE ); + +if ((netif_running (adapter->netdev))) { +/* Try to get new resources before deleting old */ + err =pch_gbe_setup_rx_resources (adapter, adapter->rx_ring);There is vmalloc inside. You really haven't tried sleep-inside-atomic debug option, have you?
Quoted 3 lines
In fact you alloc there (at most) PCH_GBE_MAX_TXD*sizeof(struct
pch_gbe_rx_desc) = 4096*16=65k=order 16 of continuous (DMAable) space in the atomic context. This is likely to fail early.
[masa]
Since spin lock is deleted, this issue is lost.
Quoted 17 lines
Quoted 16 lines
+ if (err)
+ gotoerr_setup_rx;
+ err =pch_gbe_setup_tx_resources(adapter, adapter->tx_ring);
+ if (err)
+ gotoerr_setup_tx;
+ /* save the new, restore the old in order to free it,
+ * then restore the new back again */
+adapter->rx_ring=rx_old;
+adapter->tx_ring=tx_old;
+pch_gbe_free_rx_resources(adapter, adapter->rx_ring);
+pch_gbe_free_tx_resources(adapter, adapter->tx_ring);
+kfree(tx_old);
+kfree(rx_old);
+adapter->rx_ring= rxdr;
+adapter->tx_ring= txdr;
Quoted 1 line
Why this shuffling? Isn't enough to free
*x_oldand set adapter->*x_ring?
[masa]
This will be modified
Quoted 6 lines
Quoted 2 lines
+ err =
pch_gbe_up(adapter);Well
pch_gbe_upmay sleep (viapch_gbe_request_irqviapci_enable_msiandrequest_irq) and you call it here and on other places from inside an atomic context.
[masa]
Since spin lock is deleted, this issue is lost.
Quoted 20 lines
Quoted 19 lines
+ }
+spin_unlock_irqrestore(&adapter->ethtool_lock, flags);
+ return err;drivers/net/pch_gbe/pch_gbe_ethtool.c new file +15
-0+ +err_setup_tx: +pch_gbe_free_rx_resources (adapter, adapter->rx_ring); +err_setup_rx: + adapter->rx_ring = rx_old; + adapter->tx_ring = tx_old; +kfree (rxdr); +err_alloc_rx: +kfree (txdr); +err_alloc_tx: +if (netif_running (adapter->netdev)) +pch_gbe_up (adapter); +spin_unlock_irqrestore (&adapter->ethtool_lock, flags); +return err; +}...
Quoted 7 lines
Quoted 3 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +0
-0@@ -0,0 +1,2547 @@...
Quoted 1 line
+#define
PCI_DEVICE_ID_INTEL_IOH1_GBE(u16)(0x8802) /* Pci device ID */Why the cast?
[masa]
This will be deleted.
Quoted 15 lines
Quoted 15 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +14
-0+void pch_gbe_mac_mar_set (struct pch_gbe_hw *hw,u8 * addr,u32 index) +{ +u32 mar_low, mar_high, adrmask; + +FUNC_ENTER (); +pr_debug ("index : 0x%x\n" , index); + +/* +* HW expects these in little endian so we reverse the byte order +* from network order (big endian) to little endian +*/ + mar_high = ((u32 ) addr[0 ] | ((u32 ) addr[1 ] <<8 ) | + ((u32 ) addr[2 ] <<16 ) | ((u32 ) addr[3 ] <<24 )); + mar_low = ((u32 ) addr[4 ] | ((u32 ) addr[5 ] <<8 ));
Quoted 8 lines
Quoted 6 lines
+ /* Stop the MAC Address of index. */
+ adrmask =ioread32(&hw->reg->ADDR_MASK);
+iowrite32((adrmask | (0x0001 << index)), &hw->reg->ADDR_MASK);
+ /* wait busy */
+ while ((ioread32(&hw->reg->ADDR_MASK)&PCH_GBE_BUSY))
+cpu_relax();There should be probably some time limit. Nobody trusts hardware.
[masa]
How should it modify?
Quoted 13 lines
drivers/net/pch_gbe/pch_gbe_main.c line 421
Quoted 11 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +10
-0+static int pch_gbe_alloc_queues (struct pch_gbe_adapter *adapter) +{ +int size; + +FUNC_ENTER (); + size = (int )sizeof (struct pch_gbe_tx_ring ); + adapter->tx_ring =kmalloc (size,GFP_KERNEL ); +if (!adapter->tx_ring) +return -ENOMEM ; +memset (adapter->tx_ring,0 , size);
kzalloc()
[masa]
This will be modified.
Quoted 10 lines
Quoted 9 lines
+
+ size = (int)sizeof(structpch_gbe_rx_ring);
+adapter->rx_ring=kmalloc(size, GFP_KERNEL);
+ if (!adapter->rx_ring) {
+kfree(adapter->tx_ring);
+ return-ENOMEM;
+ }
+memset(adapter->rx_ring, 0, size);
Quoted 5 lines
Ditto.
Quoted 1 line
+ size = (int)sizeof(struct
net_device);Unused?
[masa]
This will be deleted.
Quoted 21 lines
Quoted 3 lines
+ return 0;
+}...
Quoted 17 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +17
-0+static void pch_gbe_free_irq (struct pch_gbe_adapter *adapter) +{ +struct net_device *netdev = adapter->netdev; + +FUNC_ENTER (); +free_irq (adapter->pdev->irq, netdev); +if (adapter->have_msi) { +pci_disable_msi (adapter->pdev); +pr_debug ("call pci_disable_msi\n" ); + } +} + +/** +* pch_gbe_irq_disable - Mask off interrupt generation on the NIC +* @adapter: Board private structure +*/ +static void pch_gbe_irq_disable (struct pch_gbe_adapter *adapter)
Quoted 8 lines
drivers/net/pch_gbe/pch_gbe_main.c line 598
Quoted 6 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +6
-0+{ +struct pch_gbe_hw *hw = &adapter->hw; + +FUNC_ENTER (); +atomic_inc (&adapter->irq_sem); +iowrite32 (0 , &hw->reg->INT_EN);You should flush posted writes here.
[masa]
This will be modified
Reading of a register is added after iowrite.
OK?
Quoted 19 lines
Quoted 5 lines
+
synchronize_irq(adapter->pdev->irq);drivers/net/pch_gbe/pch_gbe_main.c new file +3
-0+ +pr_debug ("INT_EN reg : 0x%08x\n" ,ioread32 (&hw->reg->INT_EN)); +}...
Quoted 12 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +12
-0+static void +pch_gbe_alloc_rx_buffers (struct pch_gbe_adapter *adapter, +struct pch_gbe_rx_ring *rx_ring,int cleaned_count) +{ +struct net_device *netdev = adapter->netdev; +struct pci_dev *pdev = adapter->pdev; +struct pch_gbe_hw *hw = &adapter->hw; +struct pch_gbe_rx_desc *rx_desc; +struct pch_gbe_buffer *buffer_info; +struct sk_buff *skb; +unsigned int i; +unsigned int bufsz;...
Quoted 7 lines
Quoted 5 lines
+ if (
likely(rx_ring->next_to_use != i)) {
+rx_ring->next_to_use= i;
+ if (unlikely(i-- == 0))
+ i = (rx_ring->count- 1);
+wmb();Document the barrier.
[masa]
Document will be added.
Quoted 8 lines
Quoted 7 lines
+ iowrite32(rx_ring->dma +
drivers/net/pch_gbe/pch_gbe_main.c new file +5
-0+ (int )sizeof (struct pch_gbe_rx_desc ) * i, + &hw->reg->RX_DSC_SW_P); + } +return ; +}...
Quoted 16 lines
Quoted 4 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +4
-0+static int pch_gbe_sw_init (struct pch_gbe_adapter *adapter) +{ +struct pch_gbe_hw *hw = &adapter->hw; +struct net_device *netdev = adapter->netdev;drivers/net/pch_gbe/pch_gbe_main.c line 1781
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +10
-0+struct pci_dev *pdev = adapter->pdev; + +FUNC_ENTER (); +/* PCI config space info */ + hw->vendor_id = pdev->vendor; + hw->device_id = pdev->device; + hw->subsystem_vendor_id = pdev->subsystem_vendor; + hw->subsystem_device_id = pdev->subsystem_device; + +pci_read_config_byte (pdev,PCI_REVISION_ID , &hw->revision_id);
pdev->revision?
[masa]
This will be deleted
Quoted 13 lines
Quoted 13 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +12
-0+static int pch_gbe_xmit_frame (struct sk_buff *skb,struct net_device *netdev) +{ +struct pch_gbe_adapter *adapter =netdev_priv (netdev); +struct pch_gbe_tx_ring *tx_ring = adapter->tx_ring; +unsigned long flags; + +FUNC_ENTER (); +if (unlikely (skb->len <=0 )) { +dev_kfree_skb_any (skb); +pr_debug ("Return : OK skb len : %d\n" , skb->len); +return NETDEV_TX_OK ; + }
Quoted 8 lines
Quoted 6 lines
+ if (
unlikely(skb->len > (adapter->hw.mac.max_frame_size - 4))) {
+ pr_err("Transfer length Error: skb len: %d > max: %d\n",
+skb->len,adapter->hw.mac.max_frame_size);
+dev_kfree_skb_any(skb);
+ adapter->stats.tx_length_errors++;
+ returnNETDEV_TX_BUSY;Not nice. ndev layer will reuse the freed skb now.
[masa]
How should it modify?
Quoted 13 lines
Quoted 2 lines
+ }
...
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +10
-0+static int pch_gbe_suspend (struct pci_dev *pdev,pm_message_t state) +{ +struct net_device *netdev =pci_get_drvdata (pdev); +struct pch_gbe_adapter *adapter =netdev_priv (netdev); +struct pch_gbe_hw *hw = &adapter->hw; +u32 wufc = adapter->wake_up_evt; +int retval =0 ; + +FUNC_ENTER (); +netif_device_detach (netdev);
Quoted 8 lines
Quoted 6 lines
+ if (
netif_running(netdev))
+pch_gbe_down(adapter);
+#ifdefCONFIG_PM
+ /* Implement our own version ofpci_save_state(pdev)because pci-
+ * express adapters have 256-byte config spaces. */
+ retval =pci_save_state(pdev);But PCIe saves all caps, why you need this?
[masa]
I can not understand.
Please let me know details.
Quoted 13 lines
Quoted 13 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +12
-0+static int pch_gbe_probe (struct pci_dev *pdev, +const struct pci_device_id *pci_id) +{ +struct net_device *netdev; +struct pch_gbe_adapter *adapter; +unsigned long mmio_start; +unsigned long mmio_len; +int ret; + +FUNC_ENTER (); + ret =pci_enable_device (pdev); +if (ret)
Quoted 8 lines
Quoted 6 lines
+ return ret;
+
+ if (!dma_set_mask(&pdev->dev,DMA_BIT_MASK(64))
+ && !dma_set_coherent_mask(&pdev->dev,DMA_BIT_MASK(64))) {
+ ;
+ } else {You should invert the logic. And use
pci_variants.
[masa]
This will be modified like
if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(64))
|| dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
What is pci_ variants?
Quoted 15 lines
Quoted 14 lines
+ ret =
dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
+ if (ret) {
+ ret = dma_set_coherent_mask(&pdev->dev,
+DMA_BIT_MASK(32));
+ if (ret) {
+pr_err("ERR: No usable DMA configuration, aborting\n");
+ gotoerr_disable_device;
+ }
+ }
+ }
+ ret =pci_request_regions(pdev, KBUILD_MODNAME);
+ if (ret) {
+pr_err("ERR: Can't reserve PCI I/O and memory resources\n");
Quoted 1 line
Here (and below) you should use
dev_errinstead.
[masa]
This will be modified
Quoted 24 lines
Quoted 11 lines
+ goto
err_disable_device;
+ }
+pci_set_master(pdev);drivers/net/pch_gbe/pch_gbe_main.c new file +7
-0+ + netdev =alloc_etherdev ((int )sizeof (struct pch_gbe_adapter )); +if (!netdev) { + ret = -ENOMEM ; +pr_err ("ERR: Can't allocate and set up an Ethernet device\n" ); + goto err_release_pci; + }drivers/net/pch_gbe/pch_gbe_main.c line 2385
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +10
-0+SET_NETDEV_DEV (netdev, &pdev->dev); + +pci_set_drvdata (pdev, netdev); + adapter =netdev_priv (netdev); + adapter->netdev = netdev; + adapter->pdev = pdev; + adapter->hw.back = adapter; + mmio_start =pci_resource_start (pdev,PCH_GBE_PCI_BAR ); + mmio_len =pci_resource_len (pdev,PCH_GBE_PCI_BAR ); + adapter->hw.reg =ioremap_nocache (mmio_start, mmio_len);
pci_ioremap_bar()
Quoted 2 lines
Anyway you should not use ioread/iowrite* on an ioremapped space. It is intended for iomapped space (
pci_iomap) and is slower.
[masa]
This will be modified likepci_iomap(pdev, PCH_GBE_PCI_BAR, 0) is used.
Quoted 42 lines
Quoted 42 lines
+ if (!adapter->hw.reg) {
+ ret =-EIO;
+pr_err("Can't ioremap\n");
+ gotoerr_free_netdev;
+ }drivers/net/pch_gbe/pch_gbe_main.c new file +36
-0+ + netdev->netdev_ops = &pch_gbe_netdev_ops; + netdev->watchdog_timeo =PCH_GBE_WATCHDOG_PERIOD ; +netif_napi_add (netdev, &adapter->napi, + pch_gbe_napi_poll,PCH_GBE_RX_WEIGHT ); + netdev->mem_start = mmio_start; + netdev->mem_end = mmio_start + mmio_len; + netdev->features =NETIF_F_HW_CSUM ; +pch_gbe_set_ethtool_ops (netdev); + +pch_gbe_mac_reset_hw (&adapter->hw); + +/* setup the private structure */ + ret =pch_gbe_sw_init (adapter); +if (ret) + goto err_iounmap; + +/* Initialize PHY */ + ret =pch_gbe_init_phy (adapter); +if (ret) { +pr_err ("PHY initialize error\n" ); + goto err_free_adapter; + } +pch_gbe_hal_get_bus_info (&adapter->hw); + +/* Read the MAC address. and store to the private data */ + ret =pch_gbe_hal_read_mac_addr (&adapter->hw); +if (ret) { +pr_err ("MAC address Read Error\n" ); + goto err_free_adapter; + } + +memcpy (netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len); +if (!is_valid_ether_addr (netdev->dev_addr)) { +pr_err ("Invalid MAC Address\n" ); + ret = -EIO ;
Quoted 8 lines
Quoted 6 lines
+ goto
err_free_adapter;
+ }
+
+init_timer(&adapter->watchdog_timer);
+adapter->watchdog_timer.function=&pch_gbe_watchdog;
+adapter->watchdog_timer.data= (unsigned long)adapter;
setup_timer()
[masa]
This will be modifiedsetup_timer() is used.
Quoted 7 lines
drivers/net/pch_gbe/pch_gbe_main.c line 2512
Quoted 5 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +4
-0+static int __init pch_gbe_init_module (void ) +{ +int ret; +pr_info ("%s - version %s\n" ,DRV_STRING ,DRV_VERSION );You don't want to do that. Boot log is polluted enough already.
[masa]
This will be deleted
Quoted 13 lines
Quoted 13 lines
+ ret =
pci_register_driver(&pch_gbe_pcidev);
+ if (copybreak !=PCH_GBE_COPYBREAK_DEFAULT) {
+ if (copybreak == 0) {
+pr_info("copybreak disabled\n");
+ } else {
+ pr_info("copybreak enabled for packets <= %u bytes\n",
+ copybreak);
+ }
+ }
+ return ret;drivers/net/pch_gbe/pch_gbe_main.c new file +2
-0+} +
Quoted 8 lines
drivers/net/pch_gbe/pch_gbe_main.c line 2531
Quoted 6 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +6
-0+static void __exit pch_gbe_exit_module(void) +{ +FUNC_ENTER (); +pci_unregister_driver (&pch_gbe_pcidev); + +pr_info ("%s - unregister\n" ,DRV_STRING );Get rid of that, please.
[masa]
This will be deleted
Quoted 5 lines
Quoted 4 lines
drivers/net/pch_gbe/pch_gbe_param.c new file +0
-0@@ -0,0 +1,507 @@...
Quoted 13 lines
drivers/net/pch_gbe/pch_gbe_param.c line 242
Quoted 11 lines
drivers/net/pch_gbe/pch_gbe_param.c new file +11
-0+static void pch_gbe_check_copper_options (struct pch_gbe_adapter *adapter) +{ +struct pch_gbe_hw *hw = &adapter->hw; +int speed, dplx; + + {/* Speed */ +struct pch_gbe_opt_list speed_list[] = { + {0 ,"" }, + {SPEED_10 ,"" }, + {SPEED_100 ,"" }, + {SPEED_1000 ,"" } };Is there a reason why these are not static const?
[masa]
This will be modified
Quoted 19 lines
Quoted 5 lines
+
+ structpch_gbe_optionopt = {
+ .type =list_option,
+ .name = "Speed",Quoted 8 lines
+ .err = "parameter ignored", + .def = 0, + .arg = { .l = { .nr = (int)ARRAY_SIZE(speed_list),+ .p =
speed_list} }
+ };
+ speed = Speed;
+pch_gbe_validate_option(&speed, &opt, adapter);
+ }regards,
Signature · 2 lines
js suse labs
Quoted 2 lines · Masayuki Ohtake
I have some questions. Please see out inline comments.
Hi, answered below...
Quoted 72 lines
Quoted 63 lines
Quoted 3 lines
drivers/net/pch_gbe/pch_gbe.h new file +0
-0@@ -0,0 +1,683 @@...
Quoted 59 lines
drivers/net/pch_gbe/pch_gbe.h new file +59
-0+/** +* pch_gbe_regs_mac_adr - Structure holding values of mac address registers +* @high Denotes the 1st to 4th byte from the initial of MAC address +* @low Denotes the 5th to 6th byte from the initial of MAC address +*/ +struct pch_gbe_regs_mac_adr { +u32 high; +u32 low; +}; +/** +* pch_udc_regs - Structure holding values of MAC registers +*/ +struct pch_gbe_regs { +u32 INT_ST; +u32 INT_EN; +u32 MODE; +u32 RESET; +u32 TCPIP_ACC; +u32 EX_LIST; +u32 INT_ST_HOLD; +u32 PHY_INT_CTRL; +u32 MAC_RX_EN; +u32 RX_FCTRL; +u32 PAUSE_REQ; +u32 RX_MODE; +u32 TX_MODE; +u32 RX_FIFO_ST; +u32 TX_FIFO_ST; +u32 TX_FID; +u32 TX_RESULT; +u32 PAUSE_PKT1; +u32 PAUSE_PKT2; +u32 PAUSE_PKT3; +u32 PAUSE_PKT4; +u32 PAUSE_PKT5; +u32 reserve[2 ]; +struct pch_gbe_regs_mac_adr mac_adr[16 ]; +u32 ADDR_MASK; +u32 MIIM; +u32 reserve2; +u32 RGMII_ST; +u32 RGMII_CTRL; +u32 reserve3[3 ]; +u32 DMA_CTRL; +u32 reserve4[3 ]; +u32 RX_DSC_BASE; +u32 RX_DSC_SIZE; +u32 RX_DSC_HW_P; +u32 RX_DSC_HW_P_HLD; +u32 RX_DSC_SW_P; +u32 reserve5[3 ]; +u32 TX_DSC_BASE; +u32 TX_DSC_SIZE; +u32 TX_DSC_HW_P; +u32 TX_DSC_HW_P_HLD; +u32 TX_DSC_SW_P; +u32 reserve6[3 ]; +u32 RX_DMA_ST; +u32 TX_DMA_ST;Quoted 8 lines
Quoted 5 lines
+ u32 reserve7[2];
+ u32WOL_ST;
+ u32WOL_CTRL;
+ u32WOL_ADDR_MASK;
+};Shouldn't that be packed? As it is full of u32, probably not, but consider this comment when thinking about all structures you have here.
Quoted 4 lines
[masa]
packed?
I am sorry, I can not understand. Please let me know details.
attribute((packed)). It ensures that compiler won't add gaps in there for better alignment. As I wrote I'm not sure whether you need them at all, since you use u32 here which are aligned naturally. But bear this in mind while defining the rest of your structures which are transferred from/to the HW.
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
+ if (!txdr) {
+ err =-ENOMEM;
+ gotoerr_alloc_tx;
+ }
+ rxdr =kzalloc(rx_ring_size, GFP_KERNEL);
+ if (!rxdr) {
+ err =-ENOMEM;
+ gotoerr_alloc_rx;
+ }
+adapter->tx_ring= txdr;
+adapter->rx_ring= rxdr;
+
+rxdr->count=max(ring->rx_pending, (u32) PCH_GBE_MIN_RXD);
+rxdr->count=min(rxdr->count, (u32) PCH_GBE_MAX_RXD);
Quoted 5 lines
Quoted 2 lines
clamp()
And why you need the cast?[masa]
Since warning appears at the time of a make.
OK, then you have type error which you should fix instead. Perhaps define the constnts with U suffix?
Quoted 23 lines
Quoted 14 lines
Quoted 14 lines
drivers/net/pch_gbe/pch_gbe.h new file +14
-0+void pch_gbe_mac_mar_set (struct pch_gbe_hw *hw,u8 * addr,u32 index) +{ +u32 mar_low, mar_high, adrmask; + +FUNC_ENTER (); +pr_debug ("index : 0x%x\n" , index); + +/* +* HW expects these in little endian so we reverse the byte order +* from network order (big endian) to little endian +*/ + mar_high = ((u32 ) addr[0 ] | ((u32 ) addr[1 ] <<8 ) | + ((u32 ) addr[2 ] <<16 ) | ((u32 ) addr[3 ] <<24 )); + mar_low = ((u32 ) addr[4 ] | ((u32 ) addr[5 ] <<8 ));Quoted 8 lines
Quoted 6 lines
+ /* Stop the MAC Address of index. */
+ adrmask =ioread32(&hw->reg->ADDR_MASK);
+iowrite32((adrmask | (0x0001 << index)), &hw->reg->ADDR_MASK);
+ /* wait busy */
+ while ((ioread32(&hw->reg->ADDR_MASK)&PCH_GBE_BUSY))
+cpu_relax();There should be probably some time limit. Nobody trusts hardware.
Quoted 2 lines
[masa]
How should it modify?
Similarly to other busy waiting code you have in other places. Some udelay with a loop bound.
Quoted 29 lines
Quoted 20 lines
Quoted 2 lines
+ return 0;
+}...
Quoted 17 lines
drivers/net/pch_gbe/pch_gbe.h new file +17
-0+static void pch_gbe_free_irq (struct pch_gbe_adapter *adapter) +{ +struct net_device *netdev = adapter->netdev; + +FUNC_ENTER (); +free_irq (adapter->pdev->irq, netdev); +if (adapter->have_msi) { +pci_disable_msi (adapter->pdev); +pr_debug ("call pci_disable_msi\n" ); + } +} + +/** +* pch_gbe_irq_disable - Mask off interrupt generation on the NIC +* @adapter: Board private structure +*/ +static void pch_gbe_irq_disable (struct pch_gbe_adapter *adapter)Quoted 8 lines
drivers/net/pch_gbe/pch_gbe.h
Quoted 6 lines
drivers/net/pch_gbe/pch_gbe.h new file +6
-0+{ +struct pch_gbe_hw *hw = &adapter->hw; + +FUNC_ENTER (); +atomic_inc (&adapter->irq_sem); +iowrite32 (0 , &hw->reg->INT_EN);You should flush posted writes here.
Quoted 5 lines
[masa]
This will be modifiedReading of a register is added after iowrite. OK?
Yes, that will do the job.
Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
drivers/net/pch_gbe/pch_gbe.h new file +12
-0+static int pch_gbe_xmit_frame (struct sk_buff *skb,struct net_device *netdev) +{ +struct pch_gbe_adapter *adapter =netdev_priv (netdev); +struct pch_gbe_tx_ring *tx_ring = adapter->tx_ring; +unsigned long flags; + +FUNC_ENTER (); +if (unlikely (skb->len <=0 )) { +dev_kfree_skb_any (skb); +pr_debug ("Return : OK skb len : %d\n" , skb->len); +return NETDEV_TX_OK ; + }Quoted 8 lines
Quoted 6 lines
+ if (
unlikely(skb->len > (adapter->hw.mac.max_frame_size - 4))) {
+ pr_err("Transfer length Error: skb len: %d > max: %d\n",
+skb->len,adapter->hw.mac.max_frame_size);
+dev_kfree_skb_any(skb);
+ adapter->stats.tx_length_errors++;
+ returnNETDEV_TX_BUSY;Not nice. ndev layer will reuse the freed skb now.
Quoted 2 lines
[masa]
How should it modify?
Remove dev_kfree_skb_any(skb) to not free the skb so that ndev layer can requeue the buffer.
Quoted 21 lines
Quoted 12 lines
Quoted 1 line
+ }
...
Quoted 10 lines
drivers/net/pch_gbe/pch_gbe.h new file +10
-0+static int pch_gbe_suspend (struct pci_dev *pdev,pm_message_t state) +{ +struct net_device *netdev =pci_get_drvdata (pdev); +struct pch_gbe_adapter *adapter =netdev_priv (netdev); +struct pch_gbe_hw *hw = &adapter->hw; +u32 wufc = adapter->wake_up_evt; +int retval =0 ; + +FUNC_ENTER (); +netif_device_detach (netdev);Quoted 8 lines
Quoted 6 lines
+ if (
netif_running(netdev))
+pch_gbe_down(adapter);
+#ifdefCONFIG_PM
+ /* Implement our own version ofpci_save_state(pdev)because pci-
+ * express adapters have 256-byte config spaces. */
+ retval =pci_save_state(pdev);But PCIe saves all caps, why you need this?
Quoted 3 lines
[masa]
I can not understand.
Please let me know details.
What exactly do you need the state of pcie for? The core should do it fine on its own...
Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
drivers/net/pch_gbe/pch_gbe.h new file +12
-0+static int pch_gbe_probe (struct pci_dev *pdev, +const struct pci_device_id *pci_id) +{ +struct net_device *netdev; +struct pch_gbe_adapter *adapter; +unsigned long mmio_start; +unsigned long mmio_len; +int ret; + +FUNC_ENTER (); + ret =pci_enable_device (pdev); +if (ret)Quoted 8 lines
Quoted 6 lines
+ return ret;
+
+ if (!dma_set_mask(&pdev->dev,DMA_BIT_MASK(64))
+ && !dma_set_coherent_mask(&pdev->dev,DMA_BIT_MASK(64))) {
+ ;
+ } else {You should invert the logic. And use
pci_variants.
Quoted 6 lines
[masa]
This will be modified like
if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(64))
||dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {What is
pci_variants?
No, don't use them, they used to be pci specific intended for dma setting/mapping but are deprecated now which I didn't realize.
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
+
pci_set_drvdata(pdev, netdev);
+ adapter =netdev_priv(netdev);
+adapter->netdev= netdev;
+adapter->pdev= pdev;
+adapter->hw.back= adapter;
+mmio_start=pci_resource_start(pdev, PCH_GBE_PCI_BAR);
+mmio_len=pci_resource_len(pdev, PCH_GBE_PCI_BAR);
+adapter->hw.reg=ioremap_nocache(mmio_start, mmio_len);
Quoted 8 lines
Quoted 4 lines
pci_ioremap_bar()Anyway you should not use ioread/iowrite* on an ioremapped space. It is intended for iomapped space (
pci_iomap) and is slower.[masa]
This will be modified likepci_iomap(pdev, PCH_GBE_PCI_BAR, 0)is used.
If you don't mind one extra branching in each read/write, then OK :). Here you know it's MMIO space I think, so pci_ioremap_map+readl/writel would be more appropriate and faster. But it's your call.
regards,
Signature · 2 lines
js suse labs
Quoted 9 lines · On Wed, 08 Sep 2010 16:16:11 +0200 Jiri Slaby <[email protected]> wrote:
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
+
+rxdr->count=max(ring->rx_pending, (u32) PCH_GBE_MIN_RXD);
+rxdr->count=min(rxdr->count, (u32) PCH_GBE_MAX_RXD);
clamp()
And why you need the cast?[masa]
Since warning appears at the time of a make.
Better to use the "_t" version which does the necessary cast.
rxdr->count = clamp_t(u32, ring->rx_pending, PCH_GBE_MIN_RXD, PCH_GBE_MAX_RXD)
Quoted 4 lines · On Wed, 08 Sep 2010 16:16:11 +0200 Jiri Slaby <[email protected]> wrote:
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
+
+rxdr->count=max(ring->rx_pending, (u32) PCH_GBE_MIN_RXD);
+rxdr->count=min(rxdr->count, (u32) PCH_GBE_MAX_RXD);
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
clamp()
And why you need the cast?[masa]
Since warning appears at the time of a make.OK, then you have type error which you should fix instead. Perhaps define the constnts with U suffix?
Better yet:
rxdr->count = clamp_val(ring->rx_pending, PCH_GBE_MIN_RXD, PCH_GBE_MAX_RXD);
David Miller
maintainerFrom: Masayuki Ohtake <[email protected]>
Date: Tue, 07 Sep 2010 11:42:53 +0900
Quoted 15 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +15
-0+/** +* pch_gbe_clean_rx - Send received data up the network stack; legacy +* @adapter: Board private structure +* @rx_ring: Rx descriptor ring +* @work_done: Completed count +* @work_to_do: Request count +* Returns +* true: Cleaned the descriptor +* false: Not cleaned the descriptor +*/ +static bool +pch_gbe_clean_rx (struct pch_gbe_adapter *adapter, +struct pch_gbe_rx_ring *rx_ring, +int *work_done,int work_to_do) +{
..
drivers/net/pch_gbe/pch_gbe_main.c line 1500
Quoted 2 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +2
-0+if (netif_receive_skb (skb) ==NET_RX_DROP ) { + adapter->stats.rx_dropped++;
pch_gbe_clean_rx() should be given the "napi_struct" pointer argument from it's caller, and packets should be given to the stack using napi_gro_receive(). Finally, NETIF_F_GRO should be set in netdev->flags at probe time.
Also, you should not use the return value of netif_receive_skb() to bump the standard rx_dropped statistics value, those return code are for other purposes. No other driver does what you are doing with this return value.
If you wish to increment some extended stastic value (like drivers/net/gianfar.c does) with another name, that's fine.
Quoted 5 lines · On Wed, 8 Sep 2010 07:55:45 -0700 Stephen Hemminger <[email protected]>…
Better yet:
rxdr->count= clamp_val(ring->rx_pending,PCH_GBE_MIN_RXD,PCH_GBE_MAX_RXD);
Hi Stephen
Thank you for your suggestion.
I will modify like your suggestion.
.
Thanks, Ohtake
----- Original Message -----
From: "Stephen Hemminger" <[email protected]>
To: "Jiri Slaby" <[email protected]>
Cc: "Masayuki Ohtake" <[email protected]>; "Randy Dunlap" <[email protected]>; "Ralf Baechle" <[email protected]>; "ML netdev" <[email protected]>; "MeeGo" <[email protected]>; "Maxime Bizon" <[email protected]>; "LKML" <[email protected]>; "Kristoffer Glembo" <[email protected]>; "John Linn" <[email protected]>; "Joe Perches" <[email protected]>; "Greg Rose" <[email protected]>; "David S. Miller" <[email protected]>; "Wang, Yong Y" <[email protected]>; "Wang, Qi" <[email protected]>; "Toshiharu Okada" <[email protected]>; "Tomoya Morinaga" <[email protected]>; "Takahiro Shimizu" <[email protected]>; "Intel OTC" <[email protected]>; "Foster, Margie" <[email protected]>; "Andrew" <[email protected]>
Sent: Wednesday, September 08, 2010 11:55 PM
Subject: Re: [PATCH] Gigabit Ethernet driver of Topcliff PCH
Quoted 26 lines
Quoted 4 lines · On Wed, 08 Sep 2010 16:16:11 +0200 Jiri Slaby <[email protected]> wrote:
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
+
+rxdr->count=max(ring->rx_pending, (u32) PCH_GBE_MIN_RXD);
+rxdr->count=min(rxdr->count, (u32) PCH_GBE_MAX_RXD);Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
clamp()
And why you need the cast?[masa]
Since warning appears at the time of a make.OK, then you have type error which you should fix instead. Perhaps define the constnts with U suffix?
Better yet:
rxdr->count= clamp_val(ring->rx_pending,PCH_GBE_MIN_RXD,PCH_GBE_MAX_RXD);--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Jiri
Thank you for your answer
Quoted 15 lines · On: Wed, 08 Sep 2010 16:16:11 +0200,: Jiri Slaby wrote:
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
+ u32
TX_DMA_ST;
+ u32 reserve7[2];
+ u32WOL_ST;
+ u32WOL_CTRL;
+ u32WOL_ADDR_MASK;
+};Quoted 7 lines
Quoted 2 lines
Shouldn't that be packed? As it is full of u32, probably not, but consider this comment when thinking about all structures you have here.
[masa]
packed?
I am sorry, I can not understand. Please let me know details.
Quoted 5 lines
attribute((packed)). It ensures that compiler won't add gaps in there for better alignment. As I wrote I'm not sure whether you need them at all, since you use u32 here which are aligned naturally. But bear this in mind while defining the rest of your structures which are transferred from/to the HW.
[masa]
I understood.
"__attribute ((packed))" is added
u32 WOL_ST;
u32 WOL_CTRL;
u32 WOL_ADDR_MASK;
} __attribute ((packed));Quoted 11 lines
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
+
rxdr->count=max(ring->rx_pending, (u32) PCH_GBE_MIN_RXD);
+rxdr->count=min(rxdr->count, (u32) PCH_GBE_MAX_RXD);
clamp()
And why you need the cast?[masa]
Since warning appears at the time of a make.OK, then you have type error which you should fix instead. Perhaps define the constnts with U suffix?
[masa]
I will modify like Stephen's commentrxdr->count = clamp_val(ring->rx_pending, PCH_GBE_MIN_RXD, PCH_GBE_MAX_RXD);
Quoted 11 lines
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
+ /* wait busy */
+ while ((ioread32(&hw->reg->ADDR_MASK)&PCH_GBE_BUSY))
+cpu_relax();There should be probably some time limit. Nobody trusts hardware.
[masa]
How should it modify?Similarly to other busy waiting code you have in other places. Some udelay with a loop bound.
[masa]
I understood.
This will be modified.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
+ if (
unlikely(skb->len > (adapter->hw.mac.max_frame_size - 4))) {
+ pr_err("Transfer length Error: skb len: %d > max: %d\n",
+skb->len,adapter->hw.mac.max_frame_size);
+dev_kfree_skb_any(skb);
+ adapter->stats.tx_length_errors++;
+ returnNETDEV_TX_BUSY;
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Not nice. ndev layer will reuse the freed skb now.
[masa]
How should it modify?Remove
dev_kfree_skb_any(skb)to not free the skb so that ndev layer can requeue the buffer.
[masa]
"dev_kfree_skb_any(skb)" is removed.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
+#ifdef
CONFIG_PM
+ /* Implement our own version ofpci_save_state(pdev)because pci-
+ * express adapters have 256-byte config spaces. */
+ retval =pci_save_state(pdev);
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
But PCIe saves all caps, why you need this?
[masa]
I can not understand.
Please let me know details.What exactly do you need the state of pcie for? The core should do it fine on its own...
[masa]
Since a config space needs to be stored, pci_save_state() is used.
Quoted 12 lines
Quoted 12 lines
Quoted 6 lines
Quoted 4 lines
+ if (!dma_set_mask(&pdev->dev,
DMA_BIT_MASK(64))
+ && !dma_set_coherent_mask(&pdev->dev,DMA_BIT_MASK(64))) {
+ ;
+ } else {You should invert the logic. And use
pci_variants.[masa]
This will be modified like
if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(64))
||dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
Quoted 4 lines
Quoted 1 line
What is
pci_variants?No, don't use them, they used to be pci specific intended for dma setting/mapping but are deprecated now which I didn't realize.
[masa]
I use "pci_set_dma_mask" and "pci_set_coherent_mask". This will be modified like below
OK?
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 3 lines
+
mmio_start=pci_resource_start(pdev, PCH_GBE_PCI_BAR);
+mmio_len=pci_resource_len(pdev, PCH_GBE_PCI_BAR);
+adapter->hw.reg=ioremap_nocache(mmio_start, mmio_len);
pci_ioremap_bar()Anyway you should not use ioread/iowrite* on an ioremapped space. It is intended for iomapped space (
pci_iomap) and is slower.
Quoted 7 lines
Quoted 3 lines
[masa]
This will be modified likepci_iomap(pdev, PCH_GBE_PCI_BAR, 0)is used.If you don't mind one extra branching in each read/write, then OK :). Here you know it's MMIO space I think, so pci_ioremap_map+readl/writel would be more appropriate and faster. But it's your call.
[masa]
I use "pci_ioremap_bar()"
Thanks Ohtake
Hi David
Thank you for your comments.
I will modify like your comment and resubmit patch.
Thanks Ohtake
-----
Date: Wed, 08 Sep 2010 13:36:27 -0700 (PDT)
From: "David Miller" <[email protected]>
Quoted 32 lines
Quoted 15 lines
drivers/net/pch_gbe/pch_gbe_main.c new file +15
-0+/** +* pch_gbe_clean_rx - Send received data up the network stack; legacy +* @adapter: Board private structure +* @rx_ring: Rx descriptor ring +* @work_done: Completed count +* @work_to_do: Request count +* Returns +* true: Cleaned the descriptor +* false: Not cleaned the descriptor +*/ +static bool +pch_gbe_clean_rx (struct pch_gbe_adapter *adapter, +struct pch_gbe_rx_ring *rx_ring, +int *work_done,int work_to_do) +{..
Quoted 2 lines
+ if (
netif_receive_skb(skb)==NET_RX_DROP) {
+ adapter->stats.rx_dropped++;
pch_gbe_clean_rx()should be given the "napi_struct" pointer argument from it's caller, and packets should be given to the stack usingnapi_gro_receive(). Finally,NETIF_F_GROshould be set innetdev->flagsat probe time.Also, you should not use the return value of
netif_receive_skb()to bump the standardrx_droppedstatistics value, those return code are for other purposes. No other driver does what you are doing with this return value.If you wish to increment some extended stastic value (like
drivers/net/gianfar.cdoes) with another name, that's fine.