staging: octeon: ethernet: logging and struct cleanups
v4 cover staging: octeon: ethernet: logging and struct cleanups
This series replaces pr_*() logging calls with dev_warn() and netdev_err()/dev_err() in the octeon ethernet staging driver to include device context in log messages.
Changes since v3:
- Broke the series into much smaller, focused patches to ease review.
- Removed the global cvm_oct_rx_refill_work by introducing a per-device struct octeon_ethernet_platform, allocated during probe.
- Retrieved the device pointer via platform_get_drvdata() and passed it down the call chain (NAPI poll -> rx refill -> mem free/fill) as the first argument to avoid global state.
- Note: Dropped the ethernet-spi.c IRQ handler conversions from this series for now, as those errors are SPI4 bus-level.
Ayush Mukkanwar (3):
staging: octeon: ethernet-mem: replace pr_warn with dev_warn in free
functions
staging: octeon: replace pr_warn with dev_warn in fill path
staging: octeon: ethernet: replace pr_err and pr_info with dev_err and
netdev_err
drivers/staging/octeon/ethernet-mem.c | 42 +++++++++-------- drivers/staging/octeon/ethernet-mem.h | 4 +- drivers/staging/octeon/ethernet-rx.c | 6 ++- drivers/staging/octeon/ethernet-rx.h | 6 +-- drivers/staging/octeon/ethernet.c | 65 ++++++++++++++++----------- 5 files changed, 73 insertions(+), 50 deletions(-)
Signature · 1 line
2.53.0
PATCH v4 1/3 staging: octeon: ethernet-mem: replace pr_warn with dev_warn in free functions
Replace pr_warn() calls with dev_warn() in the hardware pool free functions (cvm_oct_free_hw_skbuff and cvm_oct_free_hw_memory) to include device information in log messages. The struct device pointer is passed from cvm_oct_remove() through cvm_oct_mem_empty_fpa() to the internal free functions.
--- drivers/staging/octeon/ethernet-mem.c | 30 +++++++++++++++------------ drivers/staging/octeon/ethernet-mem.h | 2 +- drivers/staging/octeon/ethernet.c | 6 +++--- 3 files changed, 21 insertions(+), 17 deletions(-)
drivers/staging/octeon/ethernet-mem.c +17 -13
@@ -40,11 +40,13 @@ static int cvm_oct_fill_hw_skbuff(int pool, int size, int elements)/** * cvm_oct_free_hw_skbuff- free hardware pool skbuffs +* @dev: Device for logging * @pool: Pool to allocate an skbuff for * @size: Size of the buffer needed for the pool * @elements: Number of buffers to allocate */ -static void cvm_oct_free_hw_skbuff (int pool,int size,int elements) +static void cvm_oct_free_hw_skbuff (struct device *dev, +int pool,int size,int elements) {char *memory;
@@ -59,11 +61,11 @@ static void cvm_oct_free_hw_skbuff(int pool, int size, int elements) }while (memory);if (elements <0 ) -pr_warn ("Freeing of pool %u had too many skbuffs (%d)\n" , - pool, elements); +dev_warn (dev,"Freeing of pool %u had too many skbuffs (%d)\n" , + pool, elements);else if (elements >0 ) -pr_warn ("Freeing of pool %u is missing %d skbuffs\n" , - pool, elements); +dev_warn (dev,"Freeing of pool %u is missing %d skbuffs\n" , + pool, elements); }/**
@@ -107,11 +109,13 @@ static int cvm_oct_fill_hw_memory(int pool, int size, int elements)/** * cvm_oct_free_hw_memory - Free memory allocated by cvm_oct_fill_hw_memory +* @dev: Device for logging * @pool: FPA pool to free * @size: Size of each buffer in the pool * @elements: Number of buffers that should be in the pool */ -static void cvm_oct_free_hw_memory (int pool,int size,int elements) +static void cvm_oct_free_hw_memory (struct device *dev, +int pool,int size,int elements) {char *memory;char *fpa;
@@ -127,11 +131,11 @@ static void cvm_oct_free_hw_memory(int pool, int size, int elements) }while (fpa);if (elements <0 ) -pr_warn ("Freeing of pool %u had too many buffers (%d)\n" , - pool, elements); +dev_warn (dev,"Freeing of pool %u had too many buffers (%d)\n" , + pool, elements);else if (elements >0 ) -pr_warn ("Warning: Freeing of pool %u is missing %d buffers\n" , - pool, elements); +dev_warn (dev,"Freeing of pool %u is missing %d buffers\n" , + pool, elements); }int cvm_oct_mem_fill_fpa (int pool,int size,int elements)
@@ -145,10 +149,10 @@ int cvm_oct_mem_fill_fpa(int pool, int size, int elements)return freed; } -void cvm_oct_mem_empty_fpa (int pool,int size,int elements) +void cvm_oct_mem_empty_fpa (struct device *dev,int pool,int size,int elements) {if (pool ==CVMX_FPA_PACKET_POOL ) -cvm_oct_free_hw_skbuff (pool, size, elements); +cvm_oct_free_hw_skbuff (dev, pool, size, elements);else -cvm_oct_free_hw_memory (pool, size, elements); +cvm_oct_free_hw_memory (dev, pool, size, elements); }
drivers/staging/octeon/ethernet-mem.h +1 -1
@@ -6,4 +6,4 @@*/ int cvm_oct_mem_fill_fpa (int pool,int size,int elements); -void cvm_oct_mem_empty_fpa (int pool,int size,int elements); +void cvm_oct_mem_empty_fpa (struct device *dev,int pool,int size,int elements);
drivers/staging/octeon/ethernet.c +3 -3
@@ -958,12 +958,12 @@ static void cvm_oct_remove(struct platform_device *pdev)cvmx_ipd_free_ptr ();/* Free the HW pools */ -cvm_oct_mem_empty_fpa (CVMX_FPA_PACKET_POOL ,CVMX_FPA_PACKET_POOL_SIZE , +cvm_oct_mem_empty_fpa (&pdev->dev,CVMX_FPA_PACKET_POOL ,CVMX_FPA_PACKET_POOL_SIZE , num_packet_buffers); -cvm_oct_mem_empty_fpa (CVMX_FPA_WQE_POOL ,CVMX_FPA_WQE_POOL_SIZE , +cvm_oct_mem_empty_fpa (&pdev->dev,CVMX_FPA_WQE_POOL ,CVMX_FPA_WQE_POOL_SIZE , num_packet_buffers);if (CVMX_FPA_OUTPUT_BUFFER_POOL !=CVMX_FPA_PACKET_POOL ) -cvm_oct_mem_empty_fpa (CVMX_FPA_OUTPUT_BUFFER_POOL , +cvm_oct_mem_empty_fpa (&pdev->dev,CVMX_FPA_OUTPUT_BUFFER_POOL ,CVMX_FPA_OUTPUT_BUFFER_POOL_SIZE ,128 ); }
Signature · 1 line
2.53.0
Greg KH
maintainerRe: [PATCH v4 1/3] staging: octeon: ethernet-mem: replace pr_warn with dev_warn in free functions
Quoted 5 lines · Ayush Mukkanwar
Replace
pr_warn()calls withdev_warn()in the hardware pool free functions (cvm_oct_free_hw_skbuffandcvm_oct_free_hw_memory) to include device information in log messages. The struct device pointer is passed fromcvm_oct_remove()throughcvm_oct_mem_empty_fpa()to the internal free functions.
This should be passing the platform device around, not the struct device child, right? You should keep it as close to the original device pointer as possible.
thanks,
greg k-h
PATCH v4 2/3 staging: octeon: replace pr_warn with dev_warn in fill path
In reply to Ayush MukkanwarReplace pr_warn() with dev_warn() in cvm_oct_fill_hw_memory() to include device information in log messages.
To make the device pointer accessible from the workqueue callback, introduce struct octeon_ethernet_platform to hold both a struct device pointer and the delayed_work. This replaces the static global cvm_oct_rx_refill_work. The struct is allocated with devm_kzalloc() in probe() and stored via platform_set_drvdata(). The worker retrieves it using container_of().
Add a struct device pointer to oct_rx_group and thread it through cvm_oct_rx_initialize() to support the NAPI poll refill path.
--- drivers/staging/octeon/ethernet-mem.c | 12 +++++---- drivers/staging/octeon/ethernet-mem.h | 2 +- drivers/staging/octeon/ethernet-rx.c | 6 +++-- drivers/staging/octeon/ethernet-rx.h | 6 ++--- drivers/staging/octeon/ethernet.c | 39 ++++++++++++++++++--------- 5 files changed, 42 insertions(+), 23 deletions(-)
drivers/staging/octeon/ethernet-mem.c +7 -5
@@ -70,13 +70,15 @@ static void cvm_oct_free_hw_skbuff(struct device *dev,/** * cvm_oct_fill_hw_memory - fill a hardware pool with memory. +* @dev: Device for logging * @pool: Pool to populate * @size: Size of each buffer in the pool * @elements: Number of buffers to allocate * * Returns the actual number of buffers allocated. */ -static int cvm_oct_fill_hw_memory (int pool,int size,int elements) +static int cvm_oct_fill_hw_memory (struct device *dev,int pool,int size, +int elements) {char *memory;char *fpa;
@@ -95,8 +97,8 @@ static int cvm_oct_fill_hw_memory(int pool, int size, int elements)*/ memory =kmalloc (size +256 ,GFP_ATOMIC );if (unlikely (!memory)) { -pr_warn ("Unable to allocate %u bytes for FPA pool %d\n" , - elements * size, pool); +dev_warn (dev,"Unable to allocate %u bytes for FPA pool %d\n" , + elements * size, pool);break ; } fpa = (char *)(((unsigned long )memory +256 ) & ~0x7fUL );
@@ -138,14 +140,14 @@ static void cvm_oct_free_hw_memory(struct device *dev, pool, elements); } -int cvm_oct_mem_fill_fpa (int pool,int size,int elements) +int cvm_oct_mem_fill_fpa (struct device *dev,int pool,int size,int elements) {int freed;if (pool ==CVMX_FPA_PACKET_POOL ) freed =cvm_oct_fill_hw_skbuff (pool, size, elements);else - freed =cvm_oct_fill_hw_memory (pool, size, elements); + freed =cvm_oct_fill_hw_memory (dev, pool, size, elements);return freed; }
drivers/staging/octeon/ethernet-mem.h +1 -1
@@ -5,5 +5,5 @@* Copyright (c) 2003-2007 Cavium Networks */ -int cvm_oct_mem_fill_fpa (int pool,int size,int elements); +int cvm_oct_mem_fill_fpa (struct device *dev,int pool,int size,int elements);void cvm_oct_mem_empty_fpa (struct device *dev,int pool,int size,int elements);
drivers/staging/octeon/ethernet-rx.c +4 -2
@@ -35,6 +35,7 @@ static struct oct_rx_group {int irq;int group;struct napi_struct napi; +struct device *dev; } oct_rx_group[16 ];/**
@@ -397,7 +398,7 @@ static int cvm_oct_poll(struct oct_rx_group *rx_group, int budget)/* Restore the scratch area */ cvmx_scratch_write64 (CVMX_SCR_SCRATCH , old_scratch); } -cvm_oct_rx_refill_pool (0 ); +cvm_oct_rx_refill_pool (rx_group->dev,0 );return rx_count; }
@@ -448,7 +449,7 @@ void cvm_oct_poll_controller(struct net_device *dev) }#endif -void cvm_oct_rx_initialize (void ) +void cvm_oct_rx_initialize (struct device *dev) {int i;struct net_device *dev_for_napi =NULL ;
@@ -475,6 +476,7 @@ void cvm_oct_rx_initialize(void) oct_rx_group[i].irq =OCTEON_IRQ_WORKQ0 + i; oct_rx_group[i].group = i; + oct_rx_group[i].dev = dev;/* Register an IRQ handler to receive POW interrupts */ ret = request_irq(oct_rx_group[i].irq, cvm_oct_do_interrupt, 0,
drivers/staging/octeon/ethernet-rx.h +3 -3
@@ -6,10 +6,10 @@*/ void cvm_oct_poll_controller (struct net_device *dev); -void cvm_oct_rx_initialize (void ); +void cvm_oct_rx_initialize (struct device *dev);void cvm_oct_rx_shutdown (void ); -static inline void cvm_oct_rx_refill_pool (int fill_threshold) +static inline void cvm_oct_rx_refill_pool (struct device *dev,int fill_threshold) {int number_to_free;int num_freed;
@@ -20,7 +20,7 @@ static inline void cvm_oct_rx_refill_pool(int fill_threshold)if (number_to_free > fill_threshold) {cvmx_fau_atomic_add32 (FAU_NUM_PACKET_BUFFERS_TO_FREE , -number_to_free); - num_freed =cvm_oct_mem_fill_fpa (CVMX_FPA_PACKET_POOL , + num_freed =cvm_oct_mem_fill_fpa (dev,CVMX_FPA_PACKET_POOL ,CVMX_FPA_PACKET_POOL_SIZE , number_to_free);if (num_freed != number_to_free) {
drivers/staging/octeon/ethernet.c +27 -12
@@ -104,11 +104,15 @@ struct net_device *cvm_oct_device[TOTAL_NUMBER_OF_PORTS];u64 cvm_oct_tx_poll_interval; -static void cvm_oct_rx_refill_worker (struct work_struct *work); -static DECLARE_DELAYED_WORK(cvm_oct_rx_refill_work, cvm_oct_rx_refill_worker); +struct octeon_ethernet_platform { +struct device *dev; +struct delayed_work rx_refill_work; +};static void cvm_oct_rx_refill_worker (struct work_struct *work) { +struct octeon_ethernet_platform *plt =container_of (work, + struct octeon_ethernet_platform, rx_refill_work.work);/* * FPA 0 may have been drained, try to refill it if we need * more than num_packet_buffers / 2, otherwise normal receive
@@ -116,10 +120,10 @@ static void cvm_oct_rx_refill_worker(struct work_struct *work)* could be received so cvm_oct_napi_poll would never be * invoked to do the refill. */ -cvm_oct_rx_refill_pool (num_packet_buffers /2 ); +cvm_oct_rx_refill_pool (plt->dev, num_packet_buffers /2 );if (!atomic_read (&cvm_oct_poll_queue_stopping)) -schedule_delayed_work (&cvm_oct_rx_refill_work,HZ ); +schedule_delayed_work (&plt->rx_refill_work,HZ ); }static void cvm_oct_periodic_worker (struct work_struct *work)
@@ -138,16 +142,16 @@ static void cvm_oct_periodic_worker(struct work_struct *work)schedule_delayed_work (&priv->port_periodic_work,HZ ); } -static void cvm_oct_configure_common_hw (void ) +static void cvm_oct_configure_common_hw (struct device *dev) {/* Setup the FPA */ cvmx_fpa_enable (); -cvm_oct_mem_fill_fpa (CVMX_FPA_PACKET_POOL ,CVMX_FPA_PACKET_POOL_SIZE , +cvm_oct_mem_fill_fpa (dev,CVMX_FPA_PACKET_POOL ,CVMX_FPA_PACKET_POOL_SIZE , num_packet_buffers); -cvm_oct_mem_fill_fpa (CVMX_FPA_WQE_POOL ,CVMX_FPA_WQE_POOL_SIZE , +cvm_oct_mem_fill_fpa (dev,CVMX_FPA_WQE_POOL ,CVMX_FPA_WQE_POOL_SIZE , num_packet_buffers);if (CVMX_FPA_OUTPUT_BUFFER_POOL !=CVMX_FPA_PACKET_POOL ) -cvm_oct_mem_fill_fpa (CVMX_FPA_OUTPUT_BUFFER_POOL , +cvm_oct_mem_fill_fpa (dev,CVMX_FPA_OUTPUT_BUFFER_POOL ,CVMX_FPA_OUTPUT_BUFFER_POOL_SIZE ,1024 );#ifdef __LITTLE_ENDIAN
@@ -678,6 +682,15 @@ static int cvm_oct_probe(struct platform_device *pdev)int qos;struct device_node *pip;int mtu_overhead =ETH_HLEN +ETH_FCS_LEN ; +struct octeon_ethernet_platform *plt; + + plt =devm_kzalloc (&pdev->dev,sizeof (*plt),GFP_KERNEL ); +if (!plt) +return -ENOMEM ; + + plt->dev = &pdev->dev; +INIT_DELAYED_WORK (&plt->rx_refill_work, cvm_oct_rx_refill_worker); +platform_set_drvdata (pdev, plt);#if IS_ENABLED (CONFIG_VLAN_8021Q ) mtu_overhead +=VLAN_HLEN ;
@@ -689,7 +702,7 @@ static int cvm_oct_probe(struct platform_device *pdev)return -EINVAL ; } -cvm_oct_configure_common_hw (); +cvm_oct_configure_common_hw (&pdev->dev);cvmx_helper_initialize_packet_io_global ();
@@ -912,26 +925,28 @@ static int cvm_oct_probe(struct platform_device *pdev) }cvm_oct_tx_initialize (); -cvm_oct_rx_initialize (); +cvm_oct_rx_initialize (&pdev->dev);/* * 150 uS: about 10 1500-byte packets at 1GE. */ cvm_oct_tx_poll_interval =150 * (octeon_get_clock_rate () /1000000 ); -schedule_delayed_work (&cvm_oct_rx_refill_work,HZ ); +schedule_delayed_work (&plt->rx_refill_work,HZ );return 0 ; }static void cvm_oct_remove (struct platform_device *pdev) { +struct octeon_ethernet_platform *plt =platform_get_drvdata (pdev);int port;cvmx_ipd_disable ();atomic_inc_return (&cvm_oct_poll_queue_stopping); -cancel_delayed_work_sync (&cvm_oct_rx_refill_work); + +cancel_delayed_work_sync (&plt->rx_refill_work);cvm_oct_rx_shutdown ();cvm_oct_tx_shutdown ();
Signature · 1 line
2.53.0
Greg KH
maintainerRe: [PATCH v4 2/3] staging: octeon: replace pr_warn with dev_warn in fill path
Quoted 10 lines · Ayush Mukkanwar
Replace
pr_warn()withdev_warn()incvm_oct_fill_hw_memory()to include device information in log messages.To make the device pointer accessible from the workqueue callback, introduce struct
octeon_ethernet_platformto hold both a struct device pointer and thedelayed_work. This replaces the static globalcvm_oct_rx_refill_work. The struct is allocated withdevm_kzalloc()inprobe()and stored viaplatform_set_drvdata(). The worker retrieves it usingcontainer_of().
Quoted 2 lines
Add a struct device pointer to
oct_rx_groupand thread it throughcvm_oct_rx_initialize()to support the NAPI poll refill path.
This is getting better, but you still have a static array here, now with a random struct device pointer in it. That array should just go away entirely, and the info in that structure should be what is part of the platform device local structure. Or am I missing some reason that would not work?
You are close, just take it to the next step and make everything per-device, removing the array entirely.
thanks,
greg k-h
PATCH v4 3/3 staging: octeon: ethernet: replace pr_err and pr_info with dev_err and netdev_err
In reply to Ayush MukkanwarReplace pr_err() and pr_info() calls in cvm_oct_probe() with dev_err(), netdev_err(), and netdev_info() to include device information in log messages. Use dev_err() where no net_device is available (allocation failures), and netdev_err()/netdev_info() where a net_device exists.
--- drivers/staging/octeon/ethernet.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/staging/octeon/ethernet.c +10 -10
@@ -698,7 +698,7 @@ static int cvm_oct_probe(struct platform_device *pdev) pip = pdev->dev.of_node;if (!pip) { -pr_err ("Error: No 'pip' in /aliases\n" ); +dev_err (&pdev->dev,"No 'pip' in /aliases\n" );return -EINVAL ; }
@@ -796,16 +796,16 @@ static int cvm_oct_probe(struct platform_device *pdev) dev->max_mtu =OCTEON_MAX_MTU - mtu_overhead;if (register_netdev (dev) <0 ) { -pr_err ("Failed to register ethernet device for POW\n" ); +netdev_err (dev,"Failed to register ethernet device for POW\n" );free_netdev (dev); }else { cvm_oct_device[CVMX_PIP_NUM_INPUT_PORTS ] = dev; -pr_info ("%s: POW send group %d, receive group %d\n" , - dev->name, pow_send_group, - pow_receive_group); +netdev_info (dev,"POW send group %d, receive group %d\n" , + pow_send_group, + pow_receive_group); } }else { -pr_err ("Failed to allocate ethernet device for POW\n" ); +dev_err (&pdev->dev,"Failed to allocate ethernet device for POW\n" ); } }
@@ -825,8 +825,8 @@ static int cvm_oct_probe(struct platform_device *pdev)struct net_device *dev =alloc_etherdev (sizeof (struct octeon_ethernet ));if (!dev) { -pr_err ("Failed to allocate ethernet device for port %d\n" , - port); +dev_err (&pdev->dev,"Failed to allocate ethernet device for port %d\n" , + port);continue ; }
@@ -910,8 +910,8 @@ static int cvm_oct_probe(struct platform_device *pdev)if (!dev->netdev_ops) {free_netdev (dev); }else if (register_netdev (dev) <0 ) { -pr_err ("Failed to register ethernet device for interface %d, port %d\n" , - interface, priv->port); +netdev_err (dev,"Failed to register ethernet device for interface %d, port %d\n" , + interface, priv->port);free_netdev (dev); }else { cvm_oct_device[priv->port] = dev;
Signature · 1 line
2.53.0