[PATCH 10/10] staging: gasket: don't print device addresses as kernel pointers

2018-07-26 Thread Todd Poynor
From: Todd Poynor 

Print device addresses as unsigned long, not as kernel pointers.

Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_page_table.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/gasket/gasket_page_table.c 
b/drivers/staging/gasket/gasket_page_table.c
index 8ea8ea1c5174c..32f1c1e10c7e2 100644
--- a/drivers/staging/gasket/gasket_page_table.c
+++ b/drivers/staging/gasket/gasket_page_table.c
@@ -1333,8 +1333,8 @@ static bool gasket_is_extended_dev_addr_bad(
/* check if the device address is out of bound */
addr = dev_addr & ~((pg_tbl)->extended_flag);
if (addr >> (GASKET_EXTENDED_LVL0_WIDTH + GASKET_EXTENDED_LVL0_SHIFT)) {
-   dev_err(pg_tbl->device, "device address out of bound, 0x%p\n",
-   (void *)dev_addr);
+   dev_err(pg_tbl->device, "device address out of bounds: 0x%lx\n",
+   dev_addr);
return true;
}
 
@@ -1351,8 +1351,8 @@ static bool gasket_is_extended_dev_addr_bad(
 
if (gasket_components_to_dev_address(
pg_tbl, 0, page_global_idx, page_offset) != dev_addr) {
-   dev_err(pg_tbl->device, "address is invalid, 0x%p\n",
-   (void *)dev_addr);
+   dev_err(pg_tbl->device, "address is invalid: 0x%lx\n",
+   dev_addr);
return true;
}
 
-- 
2.18.0.345.g5c9ce644c3-goog

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 06/10] staging: gasket: sysfs: convert to standard logging

2018-07-26 Thread Todd Poynor
From: Todd Poynor 

Drop gasket logging calls in favor of standard logging.

Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_sysfs.c | 73 +--
 1 file changed, 35 insertions(+), 38 deletions(-)

diff --git a/drivers/staging/gasket/gasket_sysfs.c 
b/drivers/staging/gasket/gasket_sysfs.c
index 1c5f7502e0d5e..418b81797e638 100644
--- a/drivers/staging/gasket/gasket_sysfs.c
+++ b/drivers/staging/gasket/gasket_sysfs.c
@@ -3,7 +3,9 @@
 #include "gasket_sysfs.h"
 
 #include "gasket_core.h"
-#include "gasket_logging.h"
+
+#include 
+#include 
 
 /*
  * Pair of kernel device and user-specified pointer. Used in lookups in sysfs
@@ -66,7 +68,7 @@ static struct gasket_sysfs_mapping *get_mapping(struct device 
*device)
int i;
 
if (!device) {
-   gasket_nodev_error("Received NULL device!");
+   pr_debug("%s: Received NULL device\n", __func__);
return NULL;
}
 
@@ -80,7 +82,8 @@ static struct gasket_sysfs_mapping *get_mapping(struct device 
*device)
mutex_unlock(_mappings[i].mutex);
}
 
-   gasket_nodev_info("Mapping to device %s not found.", device->kobj.name);
+   dev_dbg(device, "%s: Mapping to device %s not found\n",
+   __func__, device->kobj.name);
return NULL;
 }
 
@@ -103,16 +106,15 @@ static void put_mapping(struct gasket_sysfs_mapping 
*mapping)
struct device *device;
 
if (!mapping) {
-   gasket_nodev_info("Mapping should not be NULL.");
+   pr_debug("%s: Mapping should not be NULL\n", __func__);
return;
}
 
mutex_lock(>mutex);
if (refcount_read(>refcount.refcount) == 0)
-   gasket_nodev_error("Refcount is already 0!");
+   dev_err(mapping->device, "Refcount is already 0\n");
if (kref_put(>refcount, release_entry)) {
-   gasket_nodev_info("Removing Gasket sysfs mapping, device %s",
- mapping->device->kobj.name);
+   dev_dbg(mapping->device, "Removing Gasket sysfs mapping\n");
/*
 * We can't remove the sysfs nodes in the kref callback, since
 * device_remove_file() blocks until the node is free.
@@ -182,16 +184,13 @@ int gasket_sysfs_create_mapping(
static DEFINE_MUTEX(function_mutex);
 
mutex_lock(_mutex);
-
-   gasket_nodev_info(
-   "Creating sysfs entries for device pointer 0x%p.", device);
+   dev_dbg(device, "Creating sysfs entries for device\n");
 
/* Check that the device we're adding hasn't already been added. */
mapping = get_mapping(device);
if (mapping) {
-   gasket_nodev_error(
-   "Attempting to re-initialize sysfs mapping for device "
-   "0x%p.", device);
+   dev_err(device,
+   "Attempting to re-initialize sysfs mapping for 
device\n");
put_mapping(mapping);
mutex_unlock(_mutex);
return -EBUSY;
@@ -207,13 +206,13 @@ int gasket_sysfs_create_mapping(
}
 
if (map_idx == GASKET_SYSFS_NUM_MAPPINGS) {
-   gasket_nodev_error("All mappings have been exhausted!");
+   dev_err(device, "All mappings have been exhausted\n");
mutex_unlock(_mutex);
return -ENOMEM;
}
 
-   gasket_nodev_info(
-   "Creating sysfs mapping for device %s.", device->kobj.name);
+   dev_dbg(device, "Creating sysfs mapping for device %s\n",
+   device->kobj.name);
 
mapping = _mappings[map_idx];
kref_init(>refcount);
@@ -224,7 +223,7 @@ int gasket_sysfs_create_mapping(
  GFP_KERNEL);
mapping->attribute_count = 0;
if (!mapping->attributes) {
-   gasket_nodev_error("Unable to allocate sysfs attribute array.");
+   dev_dbg(device, "Unable to allocate sysfs attribute array\n");
mapping->device = NULL;
mapping->gasket_dev = NULL;
mutex_unlock(>mutex);
@@ -247,10 +246,9 @@ int gasket_sysfs_create_entries(
struct gasket_sysfs_mapping *mapping = get_mapping(device);
 
if (!mapping) {
-   gasket_nodev_error(
-   "Creating entries for device 0x%p without first "
-   "initializing mapping.",
-   device);
+   dev_dbg(device,
+   "Creating entries for device without first "
+   "initializing mapping\n");
return -EINVAL;
}
 
@@ -258,9 +256,9 @@ int gasket_sysfs_create_entries(
for (i = 0; strcmp(attrs[i].attr.attr.name, GASKET_ARRAY_END_MARKER);
i++) {
if (mapping->attribute_count == GASKET_SYSFS_MAX_NODES) {
-   

[PATCH 05/10] staging: gasket: page table: convert to standard logging

2018-07-26 Thread Todd Poynor
From: Todd Poynor 

Replace gasket logging calls with standard logging calls.

Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_page_table.c | 131 +
 1 file changed, 54 insertions(+), 77 deletions(-)

diff --git a/drivers/staging/gasket/gasket_page_table.c 
b/drivers/staging/gasket/gasket_page_table.c
index 55ab59303247a..8ea8ea1c5174c 100644
--- a/drivers/staging/gasket/gasket_page_table.c
+++ b/drivers/staging/gasket/gasket_page_table.c
@@ -33,6 +33,7 @@
  */
 #include "gasket_page_table.h"
 
+#include 
 #include 
 #include 
 #include 
@@ -43,7 +44,6 @@
 
 #include "gasket_constants.h"
 #include "gasket_core.h"
-#include "gasket_logging.h"
 
 /* Constants & utility macros */
 /* The number of pages that can be mapped into each second-level page table. */
@@ -79,11 +79,6 @@
  */
 #define GASKET_EXTENDED_LVL1_SHIFT 12
 
-/* Page-table specific error logging. */
-#define gasket_pg_tbl_error(pg_tbl, format, arg...)
\
-   gasket_dev_log(err, (pg_tbl)->device, (struct pci_dev *)NULL, format,  \
-   ##arg)
-
 /* Type declarations */
 /* Valid states for a struct gasket_page_table_entry. */
 enum pte_status {
@@ -306,24 +301,23 @@ int gasket_page_table_init(
 * hardware register that contains the page table size.
 */
if (total_entries == ULONG_MAX) {
-   gasket_nodev_debug(
-   "Error reading page table size. "
-   "Initializing page table with size 0.");
+   dev_dbg(device, "Error reading page table size. "
+   "Initializing page table with size 0\n");
total_entries = 0;
}
 
-   gasket_nodev_debug(
-   "Attempting to initialize page table of size 0x%lx.",
+   dev_dbg(device,
+   "Attempting to initialize page table of size 0x%lx\n",
total_entries);
 
-   gasket_nodev_debug(
-   "Table has base reg 0x%x, extended offset reg 0x%x.",
+   dev_dbg(device,
+   "Table has base reg 0x%x, extended offset reg 0x%x\n",
page_table_config->base_reg,
page_table_config->extended_reg);
 
*ppg_tbl = kzalloc(sizeof(**ppg_tbl), GFP_KERNEL);
if (!*ppg_tbl) {
-   gasket_nodev_debug("No memory for page table.");
+   dev_dbg(device, "No memory for page table\n");
return -ENOMEM;
}
 
@@ -332,8 +326,8 @@ int gasket_page_table_init(
if (bytes != 0) {
pg_tbl->entries = vzalloc(bytes);
if (!pg_tbl->entries) {
-   gasket_nodev_debug(
-   "No memory for address translation metadata.");
+   dev_dbg(device,
+   "No memory for address translation metadata\n");
kfree(pg_tbl);
*ppg_tbl = NULL;
return -ENOMEM;
@@ -361,7 +355,7 @@ int gasket_page_table_init(
pg_tbl->pci_dev = pci_dev;
pg_tbl->dma_ops = has_dma_ops;
 
-   gasket_nodev_debug("Page table initialized successfully.");
+   dev_dbg(device, "Page table initialized successfully\n");
 
return 0;
 }
@@ -398,7 +392,7 @@ int gasket_page_table_partition(
 
for (i = start; i < pg_tbl->config.total_entries; i++) {
if (pg_tbl->entries[i].status != PTE_FREE) {
-   gasket_pg_tbl_error(pg_tbl, "entry %d is not free", i);
+   dev_err(pg_tbl->device, "entry %d is not free\n", i);
mutex_unlock(_tbl->mutex);
return -EBUSY;
}
@@ -443,11 +437,9 @@ int gasket_page_table_map(
 
mutex_unlock(_tbl->mutex);
 
-   gasket_nodev_debug(
-   "%s done: ha %llx daddr %llx num %d, "
-   "ret %d\n",
-   __func__,
-   (unsigned long long)host_addr,
+   dev_dbg(pg_tbl->device,
+   "%s done: ha %llx daddr %llx num %d, ret %d\n",
+   __func__, (unsigned long long)host_addr,
(unsigned long long)dev_addr, num_pages, ret);
return ret;
 }
@@ -562,9 +554,8 @@ bool gasket_page_table_are_addrs_bad(
ulong bytes)
 {
if (host_addr & (PAGE_SIZE - 1)) {
-   gasket_pg_tbl_error(
-   pg_tbl,
-   "host mapping address 0x%lx must be page aligned",
+   dev_err(pg_tbl->device,
+   "host mapping address 0x%lx must be page aligned\n",
host_addr);
return true;
}
@@ -580,16 +571,14 @@ bool gasket_page_table_is_dev_addr_bad(
uint num_pages = bytes / PAGE_SIZE;
 
if (bytes & (PAGE_SIZE - 1)) {
-   gasket_pg_tbl_error(
-   pg_tbl,
-   "mapping size 0x%lX must be page aligned", bytes);
+ 

[PATCH 09/10] staging: gasket: TODO: remove entry for convert to standard logging

2018-07-26 Thread Todd Poynor
From: Todd Poynor 

Gasket/apex drivers now use standard logging, remove TODO entry for
this.

Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/TODO | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/staging/gasket/TODO b/drivers/staging/gasket/TODO
index d3c44ca4fda25..fb71997fb5612 100644
--- a/drivers/staging/gasket/TODO
+++ b/drivers/staging/gasket/TODO
@@ -4,7 +4,6 @@ staging directory.
 - Document sysfs files with Documentation/ABI/ entries.
 - Use misc interface instead of major number for driver version description.
 - Add descriptions of module_param's
-- Remove gasket-specific logging functions.
 - apex_get_status() should actually check status.
 - Static functions don't need kernel doc formatting, can be simplified.
 - Fix multi-line alignment formatting to look like:
-- 
2.18.0.345.g5c9ce644c3-goog

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 01/10] staging: gasket: save struct device for a gasket device

2018-07-26 Thread Todd Poynor
From: Todd Poynor 

Save the struct device pointer to a gasket device in gasket's metadata,
to facilitate use of standard logging calls and in anticipation of
non-PCI gasket devices in the future.

Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_core.c | 5 +++--
 drivers/staging/gasket/gasket_core.h | 3 +++
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/gasket/gasket_core.c 
b/drivers/staging/gasket/gasket_core.c
index 732218773c3c6..e8f3b021c20d1 100644
--- a/drivers/staging/gasket/gasket_core.c
+++ b/drivers/staging/gasket/gasket_core.c
@@ -450,6 +450,7 @@ static int gasket_alloc_dev(
gasket_dev->internal_desc = internal_desc;
gasket_dev->dev_idx = dev_idx;
snprintf(gasket_dev->kobj_name, GASKET_NAME_MAX, "%s", kobj_name);
+   gasket_dev->dev = parent;
/* gasket_bar_data is uninitialized. */
gasket_dev->num_page_tables = driver_desc->num_page_tables;
/* max_page_table_size and *page table are uninit'ed */
@@ -925,7 +926,7 @@ static int gasket_enable_dev(
_dev->bar_data[
driver_desc->page_table_bar_index],
_desc->page_table_configs[tbl_idx],
-   _dev->pci_dev->dev, gasket_dev->pci_dev, true);
+   gasket_dev->dev, gasket_dev->pci_dev, true);
if (ret) {
gasket_log_error(
gasket_dev,
@@ -2028,7 +2029,7 @@ const struct gasket_driver_desc 
*gasket_get_driver_desc(struct gasket_dev *dev)
  */
 struct device *gasket_get_device(struct gasket_dev *dev)
 {
-   return >pci_dev->dev;
+   return dev->dev;
 }
 
 /**
diff --git a/drivers/staging/gasket/gasket_core.h 
b/drivers/staging/gasket/gasket_core.h
index bf4ed3769efb2..8bd431ad3b58b 100644
--- a/drivers/staging/gasket/gasket_core.h
+++ b/drivers/staging/gasket/gasket_core.h
@@ -263,6 +263,9 @@ struct gasket_dev {
/* Pointer to the internal driver description for this device. */
struct gasket_internal_desc *internal_desc;
 
+   /* Device info */
+   struct device *dev;
+
/* PCI subsystem metadata. */
struct pci_dev *pci_dev;
 
-- 
2.18.0.345.g5c9ce644c3-goog

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 04/10] staging: gasket: ioctl: convert to standard logging

2018-07-26 Thread Todd Poynor
From: Todd Poynor 

Replace gasket logging calls with standard logging calls.

Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_ioctl.c | 23 +--
 1 file changed, 9 insertions(+), 14 deletions(-)

diff --git a/drivers/staging/gasket/gasket_ioctl.c 
b/drivers/staging/gasket/gasket_ioctl.c
index 63e139ab7ff89..78a132a60cc4f 100644
--- a/drivers/staging/gasket/gasket_ioctl.c
+++ b/drivers/staging/gasket/gasket_ioctl.c
@@ -5,9 +5,9 @@
 #include "gasket_constants.h"
 #include "gasket_core.h"
 #include "gasket_interrupt.h"
-#include "gasket_logging.h"
 #include "gasket_page_table.h"
 #include 
+#include 
 #include 
 #include 
 
@@ -73,7 +73,7 @@ long gasket_handle_ioctl(struct file *filp, uint cmd, void 
__user *argp)
}
} else if (!gasket_ioctl_check_permissions(filp, cmd)) {
trace_gasket_ioctl_exit(-EPERM);
-   gasket_log_debug(gasket_dev, "ioctl cmd=%x noperm.", cmd);
+   dev_dbg(gasket_dev->dev, "ioctl cmd=%x noperm\n", cmd);
return -EPERM;
}
 
@@ -132,10 +132,9 @@ long gasket_handle_ioctl(struct file *filp, uint cmd, void 
__user *argp)
 * the arg.
 */
trace_gasket_ioctl_integer_data(arg);
-   gasket_log_debug(
-   gasket_dev,
+   dev_dbg(gasket_dev->dev,
"Unknown ioctl cmd=0x%x not caught by "
-   "gasket_is_supported_ioctl",
+   "gasket_is_supported_ioctl\n",
cmd);
retval = -EINVAL;
break;
@@ -186,12 +185,9 @@ static bool gasket_ioctl_check_permissions(struct file 
*filp, uint cmd)
struct gasket_dev *gasket_dev = (struct gasket_dev *)filp->private_data;
 
alive = (gasket_dev->status == GASKET_STATUS_ALIVE);
-   if (!alive) {
-   gasket_nodev_error(
-   "%s alive %d status %d.",
-   __func__,
-   alive, gasket_dev->status);
-   }
+   if (!alive)
+   dev_dbg(gasket_dev->dev, "%s alive %d status %d\n",
+   __func__, alive, gasket_dev->status);
 
read = !!(filp->f_mode & FMODE_READ);
write = !!(filp->f_mode & FMODE_WRITE);
@@ -329,9 +325,8 @@ static int gasket_partition_page_table(
gasket_dev->page_table[ibuf.page_table_index]);
 
if (ibuf.size > max_page_table_size) {
-   gasket_log_debug(
-   gasket_dev,
-   "Partition request 0x%llx too large, max is 0x%x.",
+   dev_dbg(gasket_dev->dev,
+   "Partition request 0x%llx too large, max is 0x%x\n",
ibuf.size, max_page_table_size);
return -EINVAL;
}
-- 
2.18.0.345.g5c9ce644c3-goog

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 08/10] staging: gasket: remove gasket logging header

2018-07-26 Thread Todd Poynor
From: Todd Poynor 

Gasket logging functions no longer used.

Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_logging.h | 64 -
 1 file changed, 64 deletions(-)
 delete mode 100644 drivers/staging/gasket/gasket_logging.h

diff --git a/drivers/staging/gasket/gasket_logging.h 
b/drivers/staging/gasket/gasket_logging.h
deleted file mode 100644
index 54bbe516b0716..0
--- a/drivers/staging/gasket/gasket_logging.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/*
- * Common logging utilities for the Gasket driver framework.
- *
- * Copyright (C) 2018 Google, Inc.
- */
-
-#include 
-#include 
-
-#ifndef _GASKET_LOGGING_H_
-#define _GASKET_LOGGING_H_
-
-/* Base macro; other logging can/should be built on top of this. */
-#define gasket_dev_log(level, device, pci_dev, format, arg...) 
\
-   if (false) {   \
-   if (pci_dev) { \
-   dev_##level(&(pci_dev)->dev, "%s: " format "\n",   \
-   __func__, ##arg);  \
-   } else {   \
-   gasket_nodev_log(level, format, ##arg);\
-   }  \
-   }
-
-/* "No-device" logging macros. */
-#define gasket_nodev_log(level, format, arg...)
\
-   if (false) pr_##level("gasket: %s: " format "\n", __func__, ##arg)
-
-#define gasket_nodev_debug(format, arg...) 
\
-   if (false) gasket_nodev_log(debug, format, ##arg)
-
-#define gasket_nodev_info(format, arg...)  
\
-   if (false) gasket_nodev_log(info, format, ##arg)
-
-#define gasket_nodev_warn(format, arg...)  
\
-   if (false) gasket_nodev_log(warn, format, ##arg)
-
-#define gasket_nodev_error(format, arg...) 
\
-   if (false) gasket_nodev_log(err, format, ##arg)
-
-/* gasket_dev logging macros */
-#define gasket_log_info(gasket_dev, format, arg...)
\
-   if (false) gasket_dev_log(info, (gasket_dev)->dev_info.device, \
-   (gasket_dev)->pci_dev, format, ##arg)
-
-#define gasket_log_warn(gasket_dev, format, arg...)
\
-   if (false) gasket_dev_log(warn, (gasket_dev)->dev_info.device, \
-   (gasket_dev)->pci_dev, format, ##arg)
-
-#define gasket_log_error(gasket_dev, format, arg...)   
\
-   if (false) gasket_dev_log(err, (gasket_dev)->dev_info.device,  \
-   (gasket_dev)->pci_dev, format, ##arg)
-
-#define gasket_log_debug(gasket_dev, format, arg...)   
\
-   if (false){\
-   if ((gasket_dev)->pci_dev) {   \
-   dev_dbg(&((gasket_dev)->pci_dev)->dev, "%s: " format   \
-   "\n", __func__, ##arg);\
-   } else {   \
-   gasket_nodev_log(debug, format, ##arg);\
-   }  \
-   }
-
-#endif
-- 
2.18.0.345.g5c9ce644c3-goog

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 03/10] staging: gasket: interrupt: convert to standard logging

2018-07-26 Thread Todd Poynor
From: Todd Poynor 

Convert gasket logging calls to standard functions.

Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_interrupt.c | 67 +++
 1 file changed, 32 insertions(+), 35 deletions(-)

diff --git a/drivers/staging/gasket/gasket_interrupt.c 
b/drivers/staging/gasket/gasket_interrupt.c
index 2b8c26d065336..3be8e24c126d0 100644
--- a/drivers/staging/gasket/gasket_interrupt.c
+++ b/drivers/staging/gasket/gasket_interrupt.c
@@ -5,9 +5,10 @@
 
 #include "gasket_constants.h"
 #include "gasket_core.h"
-#include "gasket_logging.h"
 #include "gasket_sysfs.h"
+#include 
 #include 
+#include 
 #include 
 #ifdef GASKET_KERNEL_TRACE_SUPPORT
 #define CREATE_TRACE_POINTS
@@ -165,8 +166,8 @@ int gasket_interrupt_init(
case PCI_MSI:
case PLATFORM_WIRE:
default:
-   gasket_nodev_error(
-   "Cannot handle unsupported interrupt type %d.",
+   dev_err(gasket_dev->dev,
+   "Cannot handle unsupported interrupt type %d\n",
interrupt_data->type);
ret = -EINVAL;
};
@@ -175,8 +176,8 @@ int gasket_interrupt_init(
/* Failing to setup interrupts will cause the device to report
 * GASKET_STATUS_LAMED. But it is not fatal.
 */
-   gasket_log_warn(
-   gasket_dev, "Couldn't initialize interrupts: %d", ret);
+   dev_warn(gasket_dev->dev,
+"Couldn't initialize interrupts: %d\n", ret);
return 0;
}
 
@@ -216,7 +217,7 @@ static int gasket_interrupt_msix_init(
interrupt_data);
 
if (ret) {
-   gasket_nodev_error(
+   dev_err(_data->pci_dev->dev,
"Cannot get IRQ for interrupt %d, vector %d; "
"%d\n",
i, interrupt_data->msix_entries[i].vector, ret);
@@ -287,9 +288,8 @@ int gasket_interrupt_reinit(struct gasket_dev *gasket_dev)
int ret;
 
if (!gasket_dev->interrupt_data) {
-   gasket_log_debug(
-   gasket_dev,
-   "Attempted to reinit uninitialized interrupt data.");
+   dev_dbg(gasket_dev->dev,
+   "Attempted to reinit uninitialized interrupt data\n");
return -EINVAL;
}
 
@@ -305,8 +305,8 @@ int gasket_interrupt_reinit(struct gasket_dev *gasket_dev)
case PCI_MSI:
case PLATFORM_WIRE:
default:
-   gasket_nodev_debug(
-   "Cannot handle unsupported interrupt type %d.",
+   dev_dbg(gasket_dev->dev,
+   "Cannot handle unsupported interrupt type %d\n",
gasket_dev->interrupt_data->type);
ret = -EINVAL;
};
@@ -315,7 +315,7 @@ int gasket_interrupt_reinit(struct gasket_dev *gasket_dev)
/* Failing to setup MSIx will cause the device
 * to report GASKET_STATUS_LAMED, but is not fatal.
 */
-   gasket_log_warn(gasket_dev, "Couldn't init msix: %d", ret);
+   dev_warn(gasket_dev->dev, "Couldn't init msix: %d\n", ret);
return 0;
}
 
@@ -327,7 +327,7 @@ int gasket_interrupt_reinit(struct gasket_dev *gasket_dev)
 /* See gasket_interrupt.h for description. */
 int gasket_interrupt_reset_counts(struct gasket_dev *gasket_dev)
 {
-   gasket_log_debug(gasket_dev, "Clearing interrupt counts.");
+   dev_dbg(gasket_dev->dev, "Clearing interrupt counts\n");
memset(gasket_dev->interrupt_data->interrupt_counts, 0,
   gasket_dev->interrupt_data->num_interrupts *
sizeof(*gasket_dev->interrupt_data->interrupt_counts));
@@ -351,12 +351,11 @@ static void gasket_interrupt_setup(struct gasket_dev 
*gasket_dev)
gasket_dev->interrupt_data;
 
if (!interrupt_data) {
-   gasket_log_debug(
-   gasket_dev, "Interrupt data is not initialized.");
+   dev_dbg(gasket_dev->dev, "Interrupt data is not initialized\n");
return;
}
 
-   gasket_log_debug(gasket_dev, "Running interrupt setup.");
+   dev_dbg(gasket_dev->dev, "Running interrupt setup\n");
 
if (interrupt_data->type == PLATFORM_WIRE ||
interrupt_data->type == PCI_MSI) {
@@ -365,8 +364,8 @@ static void gasket_interrupt_setup(struct gasket_dev 
*gasket_dev)
}
 
if (interrupt_data->type != PCI_MSIX) {
-   gasket_nodev_debug(
-   "Cannot handle unsupported interrupt type %d.",
+   dev_dbg(gasket_dev->dev,
+   "Cannot handle unsupported interrupt type %d\n",
interrupt_data->type);
return;
}
@@ -379,10 +378,9 @@ 

[PATCH 02/10] staging: gasket: core: convert to standard logging

2018-07-26 Thread Todd Poynor
From: Todd Poynor 

Use standard logging functions, drop use of gasket log functions.

Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_core.c | 295 ---
 1 file changed, 134 insertions(+), 161 deletions(-)

diff --git a/drivers/staging/gasket/gasket_core.c 
b/drivers/staging/gasket/gasket_core.c
index e8f3b021c20d1..f44805c38159b 100644
--- a/drivers/staging/gasket/gasket_core.c
+++ b/drivers/staging/gasket/gasket_core.c
@@ -10,15 +10,16 @@
 
 #include "gasket_interrupt.h"
 #include "gasket_ioctl.h"
-#include "gasket_logging.h"
 #include "gasket_page_table.h"
 #include "gasket_sysfs.h"
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
+#include 
 
 #ifdef GASKET_KERNEL_TRACE_SUPPORT
 #define CREATE_TRACE_POINTS
@@ -205,8 +206,8 @@ static inline int check_and_invoke_callback(
 {
int ret = 0;
 
-   gasket_log_debug(gasket_dev, "check_and_invoke_callback %p",
-cb_function);
+   dev_dbg(gasket_dev->dev, "check_and_invoke_callback %p\n",
+   cb_function);
if (cb_function) {
mutex_lock(_dev->mutex);
ret = cb_function(gasket_dev);
@@ -228,8 +229,8 @@ static inline int gasket_check_and_invoke_callback_nolock(
int ret = 0;
 
if (cb_function) {
-   gasket_log_debug(
-   gasket_dev, "Invoking device-specific callback.");
+   dev_dbg(gasket_dev->dev,
+   "Invoking device-specific callback.\n");
ret = cb_function(gasket_dev);
}
return ret;
@@ -250,7 +251,7 @@ static int __init gasket_init(void)
 {
int i;
 
-   gasket_nodev_info("Performing one-time init of the Gasket framework.");
+   pr_info("Performing one-time init of the Gasket framework.\n");
/* Check for duplicates and find a free slot. */
mutex_lock(_mutex);
for (i = 0; i < GASKET_FRAMEWORK_DESC_MAX; i++) {
@@ -267,7 +268,7 @@ static int __init gasket_init(void)
 static void __exit gasket_exit(void)
 {
/* No deinit/dealloc needed at present. */
-   gasket_nodev_info("Removing Gasket framework module.");
+   pr_info("Removing Gasket framework module.\n");
 }
 
 /* See gasket_core.h for description. */
@@ -277,15 +278,14 @@ int gasket_register_device(const struct 
gasket_driver_desc *driver_desc)
int desc_idx = -1;
struct gasket_internal_desc *internal;
 
-   gasket_nodev_info("Initializing Gasket framework device");
+   pr_info("Initializing Gasket framework device\n");
/* Check for duplicates and find a free slot. */
mutex_lock(_mutex);
 
for (i = 0; i < GASKET_FRAMEWORK_DESC_MAX; i++) {
if (g_descs[i].driver_desc == driver_desc) {
-   gasket_nodev_error(
-   "%s driver already loaded/registered",
-   driver_desc->name);
+   pr_err("%s driver already loaded/registered\n",
+  driver_desc->name);
mutex_unlock(_mutex);
return -EBUSY;
}
@@ -301,17 +301,17 @@ int gasket_register_device(const struct 
gasket_driver_desc *driver_desc)
}
mutex_unlock(_mutex);
 
-   gasket_nodev_info("Loaded %s driver, framework version %s",
- driver_desc->name, GASKET_FRAMEWORK_VERSION);
+   pr_info("Loaded %s driver, framework version %s\n",
+   driver_desc->name, GASKET_FRAMEWORK_VERSION);
 
if (desc_idx == -1) {
-   gasket_nodev_error("Too many Gasket drivers loaded: %d\n",
-  GASKET_FRAMEWORK_DESC_MAX);
+   pr_err("Too many Gasket drivers loaded: %d\n",
+  GASKET_FRAMEWORK_DESC_MAX);
return -EBUSY;
}
 
/* Internal structure setup. */
-   gasket_nodev_info("Performing initial internal structure setup.");
+   pr_debug("Performing initial internal structure setup.\n");
internal = _descs[desc_idx];
mutex_init(>mutex);
memset(internal->devs, 0, sizeof(struct gasket_dev *) * GASKET_DEV_MAX);
@@ -324,8 +324,8 @@ int gasket_register_device(const struct gasket_driver_desc 
*driver_desc)
class_create(driver_desc->module, driver_desc->name);
 
if (IS_ERR(internal->class)) {
-   gasket_nodev_error("Cannot register %s class [ret=%ld]",
-  driver_desc->name, PTR_ERR(internal->class));
+   pr_err("Cannot register %s class [ret=%ld]\n",
+  driver_desc->name, PTR_ERR(internal->class));
ret = PTR_ERR(internal->class);
goto unregister_gasket_driver;
}
@@ -334,25 +334,24 @@ int gasket_register_device(const struct 
gasket_driver_desc *driver_desc)
 * Not using pci_register_driver() (without 

[PATCH 07/10] staging: gasket: apex: convert to standard logging

2018-07-26 Thread Todd Poynor
From: Todd Poynor 

Drop gasket logging calls in favor of standard logging.

Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/apex_driver.c | 61 
 1 file changed, 26 insertions(+), 35 deletions(-)

diff --git a/drivers/staging/gasket/apex_driver.c 
b/drivers/staging/gasket/apex_driver.c
index 6396b18b246a5..73fc2683a834d 100644
--- a/drivers/staging/gasket/apex_driver.c
+++ b/drivers/staging/gasket/apex_driver.c
@@ -7,11 +7,13 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -19,7 +21,6 @@
 
 #include "gasket_core.h"
 #include "gasket_interrupt.h"
-#include "gasket_logging.h"
 #include "gasket_page_table.h"
 #include "gasket_sysfs.h"
 
@@ -362,11 +363,9 @@ static int apex_add_dev_cb(struct gasket_dev *gasket_dev)
 
if (retries == APEX_RESET_RETRY) {
if (!page_table_ready)
-   gasket_log_error(
-   gasket_dev, "Page table init timed out.");
+   dev_err(gasket_dev->dev, "Page table init timed out\n");
if (!msix_table_ready)
-   gasket_log_error(
-   gasket_dev, "MSI-X table init timed out.");
+   dev_err(gasket_dev->dev, "MSI-X table init timed 
out\n");
return -ETIMEDOUT;
}
 
@@ -420,12 +419,9 @@ static int apex_device_cleanup(struct gasket_dev 
*gasket_dev)
gasket_dev, APEX_BAR_INDEX,
APEX_BAR2_REG_SCALAR_CORE_ERROR_STATUS);
 
-   gasket_log_debug(
-   gasket_dev,
-   "%s 0x%p hib_error 0x%llx scalar_error "
-   "0x%llx.",
-   __func__,
-   gasket_dev, hib_error, scalar_error);
+   dev_dbg(gasket_dev->dev,
+   "%s 0x%p hib_error 0x%llx scalar_error 0x%llx\n",
+   __func__, gasket_dev, hib_error, scalar_error);
 
if (allow_power_save)
ret = apex_enter_reset(gasket_dev, APEX_CHIP_REINIT_RESET);
@@ -452,7 +448,7 @@ static int apex_reset(struct gasket_dev *gasket_dev, uint 
type)
/* We are not in reset - toggle the reset bit so as to force
 * re-init of custom block
 */
-   gasket_log_debug(gasket_dev, "%s: toggle reset.", __func__);
+   dev_dbg(gasket_dev->dev, "%s: toggle reset\n", __func__);
 
ret = apex_enter_reset(gasket_dev, type);
if (ret)
@@ -489,9 +485,9 @@ static int apex_enter_reset(struct gasket_dev *gasket_dev, 
uint type)
if (gasket_wait_with_reschedule(gasket_dev, APEX_BAR_INDEX,
APEX_BAR2_REG_USER_HIB_DMA_PAUSED, 1, 1,
APEX_RESET_DELAY, APEX_RESET_RETRY)) {
-   gasket_log_error(gasket_dev,
-"DMAs did not quiesce within timeout (%d ms)",
-APEX_RESET_RETRY * APEX_RESET_DELAY);
+   dev_err(gasket_dev->dev,
+   "DMAs did not quiesce within timeout (%d ms)\n",
+   APEX_RESET_RETRY * APEX_RESET_DELAY);
return -ETIMEDOUT;
}
 
@@ -511,9 +507,8 @@ static int apex_enter_reset(struct gasket_dev *gasket_dev, 
uint type)
if (gasket_wait_with_reschedule(gasket_dev, APEX_BAR_INDEX,
APEX_BAR2_REG_SCU_3, 1 << 6, 1 << 6,
APEX_RESET_DELAY, APEX_RESET_RETRY)) {
-   gasket_log_error(
-   gasket_dev,
-   "RAM did not shut down within timeout (%d ms)",
+   dev_err(gasket_dev->dev,
+   "RAM did not shut down within timeout (%d ms)\n",
APEX_RESET_RETRY * APEX_RESET_DELAY);
return -ETIMEDOUT;
}
@@ -560,9 +555,8 @@ static int apex_quit_reset(struct gasket_dev *gasket_dev, 
uint type)
if (gasket_wait_with_reschedule(gasket_dev, APEX_BAR_INDEX,
APEX_BAR2_REG_SCU_3, 1 << 6, 0,
APEX_RESET_DELAY, APEX_RESET_RETRY)) {
-   gasket_log_error(
-   gasket_dev,
-   "RAM did not enable within timeout (%d ms)",
+   dev_err(gasket_dev->dev,
+   "RAM did not enable within timeout (%d ms)\n",
APEX_RESET_RETRY * APEX_RESET_DELAY);
return -ETIMEDOUT;
}
@@ -572,9 +566,8 @@ static int apex_quit_reset(struct gasket_dev *gasket_dev, 
uint type)
APEX_BAR2_REG_SCU_3,
SCU3_CUR_RST_GCB_BIT_MASK, 0,
APEX_RESET_DELAY, APEX_RESET_RETRY)) {
-   gasket_log_error(
-   

[PATCH 00/10] staging: gasket: logging cleanups

2018-07-26 Thread Todd Poynor
From: Todd Poynor 

Kill off gasket logging functions, convert to standard.

Fixup a few formatting/style problems in the process.

Todd Poynor (10):
  staging: gasket: save struct device for a gasket device
  staging: gasket: core: convert to standard logging
  staging: gasket: interrupt: convert to standard logging
  staging: gasket: ioctl: convert to standard logging
  staging: gasket: page table: convert to standard logging
  staging: gasket: sysfs: convert to standard logging
  staging: gasket: apex: convert to standard logging
  staging: gasket: remove gasket logging header
  staging: gasket: TODO: remove entry for convert to standard logging
  staging: gasket: don't print device addresses as kernel pointers

 drivers/staging/gasket/TODO|   1 -
 drivers/staging/gasket/apex_driver.c   |  61 ++---
 drivers/staging/gasket/gasket_core.c   | 300 ++---
 drivers/staging/gasket/gasket_core.h   |   3 +
 drivers/staging/gasket/gasket_interrupt.c  |  67 +++--
 drivers/staging/gasket/gasket_ioctl.c  |  23 +-
 drivers/staging/gasket/gasket_logging.h|  64 -
 drivers/staging/gasket/gasket_page_table.c | 131 -
 drivers/staging/gasket/gasket_sysfs.c  |  73 +++--
 9 files changed, 296 insertions(+), 427 deletions(-)
 delete mode 100644 drivers/staging/gasket/gasket_logging.h

-- 
2.18.0.345.g5c9ce644c3-goog

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 00/25] staging: erofs: introduce erofs file system

2018-07-26 Thread Gao Xiang



On 2018/7/27 9:39, Gao Xiang wrote:
> Every file system has its typical usage case.
> 
> I don't think there exists a silver bullet solving all usage cases optimally.
> JFFS2, YAFFS and UBIFS are designed for raw flash, we use UFS or eMMC solution
> rather than raw nand flash.
> 
> Cramfs and ROMFS are too simple for us, and it is actually useless because no
> similar & duplicate code with EROFS.
> 
> We can save about 200MB+ metadata space than EXT4 by just using EROFS
> _without_ compression support in our products, which could be more compared
> with F2FS(F2FS has more useless metadata for read-only use such as SIT, and 
> SSA).
> Since we are a read-only file system, we could use aggressive inline(compact) 
> and data
> deduplication approach. It is not a small number storage space because we
> leave some compression ratio for better performance in low memory scenario.
> 
> and I don't think SquashFS is optimal for us, 1) it doesn't have the inline
> consideration by design (inline could save storage space also reduce extra 
> data IOs),
> 2) it is designed for saving more storage space rather than keeping high 
> performance
> for limited physical memory scenario; 3) it has many compatible code for its 
> historial
> design, actually its on-disk layout design is hard to be extended considering 
> its
> historial images 4) It is not designed for VLE, we need to rewrite more than 
> half of
> its current code 5) EROFS has no similar code with the current SquashFS.
> > In the end, I don't think F2FS could be an expansion of NILFS2, BTRFS
> is an b-tree expansion of some read-write file system. You could call EROFS
> as ROMFS2 or Squashfs+ but EROFS is a completely different solution.
> We need to evaluate the optimal file system for each specific usage case 
> (actually
> we think erofs almost reaches our requirements for our Android products rather
> than SquashFS) and KISS for each solution.

One more to say, if we could make a rather complicated final file system,
and you can imagine it has average or even worse performance, lots of 
limitation and
historial issues(just complicated as the C++ language), and hard to maintain
by some individuals and debug.

Thanks,
Gao Xiang
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] Drivers: HV: Fix the check for return value from kmsg get dump buffer

2018-07-26 Thread Sunil Muthuswamy
The code to support panic control message was checking the return was
checking the return value from kmsg_dump_get_buffer as error value, which
is not what the routine returns. This fixes it.

Fixes: 81b18bce48af ("Drivers: HV: Send one page worth of kmsg dump over 
Hyper-V during panic")

Signed-off-by: Sunil Muthuswamy 
---
 drivers/hv/vmbus_drv.c | 11 ---
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 05e37283d7c3..a7f33c1f42c5 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -1047,13 +1047,10 @@ static void hv_kmsg_dump(struct kmsg_dumper *dumper,
 * Write dump contents to the page. No need to synchronize; panic should
 * be single-threaded.
 */
-   if (!kmsg_dump_get_buffer(dumper, true, hv_panic_page,
- PAGE_SIZE, _written)) {
-   pr_err("Hyper-V: Unable to get kmsg data for panic\n");
-   return;
-   }
-
-   hyperv_report_panic_msg(panic_pa, bytes_written);
+   kmsg_dump_get_buffer(dumper, true, hv_panic_page, PAGE_SIZE,
+_written);
+   if (bytes_written)
+   hyperv_report_panic_msg(panic_pa, bytes_written);
 }
 
 static struct kmsg_dumper hv_kmsg_dumper = {
-- 
2.17.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


RE: [PATCH] Drivers: HV: panic kmsg dump, move MSR access to arch specific

2018-07-26 Thread Sunil Muthuswamy
I just sent three individual patches to address the below.

Thanks,
Sunil

> -Original Message-
> From: KY Srinivasan
> Sent: Thursday, July 26, 2018 11:53 AM
> To: Sunil Muthuswamy ; Michael Kelley (EOSG)
> 
> Cc: Stephen Hemminger ; Haiyang Zhang
> ; de...@linuxdriverproject.org
> Subject: RE: [PATCH] Drivers: HV: panic kmsg dump, move MSR access to arch
> specific
> 
> 
> 
> > -Original Message-
> > From: Sunil Muthuswamy
> > Sent: Monday, July 23, 2018 11:31 AM
> > To: Michael Kelley (EOSG) ; Sunil
> > Muthuswamy 
> > Cc: KY Srinivasan ; Stephen Hemminger
> > ; Haiyang Zhang ;
> > de...@linuxdriverproject.org
> > Subject: [PATCH] Drivers: HV: panic kmsg dump, move MSR access to arch
> > specific
> >
> > Moves the MSR access from arch independent code to arch
> > dependent code. Also includes minor bug fixes.
> 
> Please breakup this patch into 3 patches:
> 
> 1) Making the code ISA independent - moving the MSR accesses out of the
> common code.
> 2) Fixing the issue with checking the return value from
> kmsg_dump_get_buffer()
> 3) Fix the issue with freeing up hv_ctl_table_hdr
> 
> Thank you,
> 
> K. Y
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] Drivers: HV: Fix the issue with freeing up hv_ctl_table_hdr

2018-07-26 Thread Sunil Muthuswamy
The check to free the Hyper-V control table header was reversed. This
fixes it.

Fixes: 81b18bce48af ("Drivers: HV: Send one page worth of kmsg dump over 
Hyper-V during panic")

Signed-off-by: Sunil Muthuswamy 
---
 drivers/hv/vmbus_drv.c | 14 --
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 05e37283d7c3..9380f115095b 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -1179,11 +1179,8 @@ static int vmbus_bus_init(void)
 
bus_unregister(_bus);
free_page((unsigned long)hv_panic_page);
-   if (!hv_ctl_table_hdr) {
-   unregister_sysctl_table(hv_ctl_table_hdr);
-   hv_ctl_table_hdr = NULL;
-   }
-
+   unregister_sysctl_table(hv_ctl_table_hdr);
+   hv_ctl_table_hdr = NULL;
return ret;
 }
 
@@ -1894,11 +1891,8 @@ static void __exit vmbus_exit(void)
}
 
free_page((unsigned long)hv_panic_page);
-   if (!hv_ctl_table_hdr) {
-   unregister_sysctl_table(hv_ctl_table_hdr);
-   hv_ctl_table_hdr = NULL;
-   }
-
+   unregister_sysctl_table(hv_ctl_table_hdr);
+   hv_ctl_table_hdr = NULL;
bus_unregister(_bus);
 
cpuhp_remove_state(hyperv_cpuhp_online);
-- 
2.17.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] Drivers: HV: move the crash control MSR access out of common code

2018-07-26 Thread Sunil Muthuswamy
Fixes: 81b18bce48af ("Drivers: HV: Send one page worth of kmsg dump over 
Hyper-V during panic")

Signed-off-by: Sunil Muthuswamy 
---
 arch/x86/include/asm/mshyperv.h | 3 +++
 drivers/hv/vmbus_drv.c  | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
index 406da8d159e3..4d82ad347b75 100644
--- a/arch/x86/include/asm/mshyperv.h
+++ b/arch/x86/include/asm/mshyperv.h
@@ -97,6 +97,9 @@ static inline void vmbus_signal_eom(struct hv_message *msg, 
u32 old_msg_type)
 #define hv_set_synint_state(int_num, val) \
wrmsrl(HV_X64_MSR_SINT0 + int_num, val)
 
+#define hv_get_crash_ctl(val) \
+   rdmsrl(HV_X64_MSR_CRASH_CTL, val)
+
 void hyperv_callback_vector(void);
 void hyperv_reenlightenment_vector(void);
 #ifdef CONFIG_TRACING
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 05e37283d7c3..6f7686f75f86 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -1149,7 +1149,7 @@ static int vmbus_bus_init(void)
 * Register for panic kmsg callback only if the right
 * capability is supported by the hypervisor.
 */
-   rdmsrl(HV_X64_MSR_CRASH_CTL, hyperv_crash_ctl);
+   hv_get_crash_ctl(hyperv_crash_ctl);
if (hyperv_crash_ctl & HV_CRASH_CTL_CRASH_NOTIFY_MSG) {
hv_panic_page = (void *)get_zeroed_page(GFP_KERNEL);
if (hv_panic_page) {
-- 
2.17.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 1/2] android: binder: Show extra_buffers_size in trace

2018-07-26 Thread Sherry Yang
Add extra_buffers_size to the binder_transaction_alloc_buf tracepoint.

Acked-by: Arve Hjønnevåg 
Signed-off-by: Sherry Yang 
---
 drivers/android/binder_trace.h | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/android/binder_trace.h b/drivers/android/binder_trace.h
index 76e3b9c8a8a2..588eb3ec3507 100644
--- a/drivers/android/binder_trace.h
+++ b/drivers/android/binder_trace.h
@@ -248,14 +248,17 @@ DECLARE_EVENT_CLASS(binder_buffer_class,
__field(int, debug_id)
__field(size_t, data_size)
__field(size_t, offsets_size)
+   __field(size_t, extra_buffers_size)
),
TP_fast_assign(
__entry->debug_id = buf->debug_id;
__entry->data_size = buf->data_size;
__entry->offsets_size = buf->offsets_size;
+   __entry->extra_buffers_size = buf->extra_buffers_size;
),
-   TP_printk("transaction=%d data_size=%zd offsets_size=%zd",
- __entry->debug_id, __entry->data_size, __entry->offsets_size)
+   TP_printk("transaction=%d data_size=%zd offsets_size=%zd 
extra_buffers_size=%zd",
+ __entry->debug_id, __entry->data_size, __entry->offsets_size,
+ __entry->extra_buffers_size)
 );
 
 DEFINE_EVENT(binder_buffer_class, binder_transaction_alloc_buf,
-- 
2.18.0.345.g5c9ce644c3-goog

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 2/2] android: binder: Rate-limit debug and userspace triggered err msgs

2018-07-26 Thread Sherry Yang
Use rate-limited debug messages where userspace can trigger
excessive log spams.

Acked-by: Arve Hjønnevåg 
Signed-off-by: Sherry Yang 
---
 drivers/android/binder.c   |  5 +++--
 drivers/android/binder_alloc.c | 41 +-
 2 files changed, 29 insertions(+), 17 deletions(-)

diff --git a/drivers/android/binder.c b/drivers/android/binder.c
index 95283f3bb51c..78cc1190282c 100644
--- a/drivers/android/binder.c
+++ b/drivers/android/binder.c
@@ -71,6 +71,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include "binder_alloc.h"
@@ -161,13 +162,13 @@ module_param_call(stop_on_user_error, 
binder_set_stop_on_user_error,
 #define binder_debug(mask, x...) \
do { \
if (binder_debug_mask & mask) \
-   pr_info(x); \
+   pr_info_ratelimited(x); \
} while (0)
 
 #define binder_user_error(x...) \
do { \
if (binder_debug_mask & BINDER_DEBUG_USER_ERROR) \
-   pr_info(x); \
+   pr_info_ratelimited(x); \
if (binder_stop_on_user_error) \
binder_stop_on_user_error = 2; \
} while (0)
diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c
index 2628806c64a2..e16116e9ad1f 100644
--- a/drivers/android/binder_alloc.c
+++ b/drivers/android/binder_alloc.c
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "binder_alloc.h"
 #include "binder_trace.h"
 
@@ -36,11 +37,12 @@ struct list_lru binder_alloc_lru;
 static DEFINE_MUTEX(binder_alloc_mmap_lock);
 
 enum {
+   BINDER_DEBUG_USER_ERROR = 1U << 0,
BINDER_DEBUG_OPEN_CLOSE = 1U << 1,
BINDER_DEBUG_BUFFER_ALLOC   = 1U << 2,
BINDER_DEBUG_BUFFER_ALLOC_ASYNC = 1U << 3,
 };
-static uint32_t binder_alloc_debug_mask;
+static uint32_t binder_alloc_debug_mask = BINDER_DEBUG_USER_ERROR;
 
 module_param_named(debug_mask, binder_alloc_debug_mask,
   uint, 0644);
@@ -48,7 +50,7 @@ module_param_named(debug_mask, binder_alloc_debug_mask,
 #define binder_alloc_debug(mask, x...) \
do { \
if (binder_alloc_debug_mask & mask) \
-   pr_info(x); \
+   pr_info_ratelimited(x); \
} while (0)
 
 static struct binder_buffer *binder_buffer_next(struct binder_buffer *buffer)
@@ -152,8 +154,10 @@ static struct binder_buffer 
*binder_alloc_prepare_to_free_locked(
 * free the buffer twice
 */
if (buffer->free_in_progress) {
-   pr_err("%d:%d FREE_BUFFER u%016llx user freed 
buffer twice\n",
-  alloc->pid, current->pid, (u64)user_ptr);
+   binder_alloc_debug(BINDER_DEBUG_USER_ERROR,
+  "%d:%d FREE_BUFFER u%016llx 
user freed buffer twice\n",
+  alloc->pid, current->pid,
+  (u64)user_ptr);
return NULL;
}
buffer->free_in_progress = 1;
@@ -224,8 +228,9 @@ static int binder_update_page_range(struct binder_alloc 
*alloc, int allocate,
}
 
if (!vma && need_mm) {
-   pr_err("%d: binder_alloc_buf failed to map pages in userspace, 
no vma\n",
-   alloc->pid);
+   binder_alloc_debug(BINDER_DEBUG_USER_ERROR,
+  "%d: binder_alloc_buf failed to map pages in 
userspace, no vma\n",
+  alloc->pid);
goto err_no_vma;
}
 
@@ -344,8 +349,9 @@ static struct binder_buffer *binder_alloc_new_buf_locked(
int ret;
 
if (alloc->vma == NULL) {
-   pr_err("%d: binder_alloc_buf, no vma\n",
-  alloc->pid);
+   binder_alloc_debug(BINDER_DEBUG_USER_ERROR,
+  "%d: binder_alloc_buf, no vma\n",
+  alloc->pid);
return ERR_PTR(-ESRCH);
}
 
@@ -417,11 +423,14 @@ static struct binder_buffer *binder_alloc_new_buf_locked(
if (buffer_size > largest_free_size)
largest_free_size = buffer_size;
}
-   pr_err("%d: binder_alloc_buf size %zd failed, no address 
space\n",
-   alloc->pid, size);
-   pr_err("allocated: %zd (num: %zd largest: %zd), free: %zd (num: 
%zd largest: %zd)\n",
-  total_alloc_size, allocated_buffers, largest_alloc_size,
-  total_free_size, free_buffers, largest_free_size);
+   binder_alloc_debug(BINDER_DEBUG_USER_ERROR,
+  "%d: binder_alloc_buf size %zd failed, 

Re: [PATCH v2 3/3] Staging: octeon-usb: Breaks down cvmx_usb_poll_channel().

2018-07-26 Thread Georgios Tsotsos
Indeed i should probably either use pointer
or pass the values, i will do some more testing
and update this.
Thanks

On Thu, 26 Jul 2018 at 19:31, Joe Perches  wrote:
>
> On Thu, 2018-07-26 at 18:41 +0300, Georgios Tsotsos wrote:
> > In order to make this function more clear a new function created that 
> > controls
> > channels halt on no DMA mode.
> []
> > diff --git a/drivers/staging/octeon-usb/octeon-hcd.c 
> > b/drivers/staging/octeon-usb/octeon-hcd.c
> []
> > @@ -2585,6 +2585,52 @@ static void cvmx_usb_transfer_isoc(struct octeon_hcd 
> > *usb,
> >   }
> >  }
> >
> > +/**
> > + * Handles channels halt in non DMA mode
> > + * @usbc_hcchar: Host Channel-n Characteristics Register (HCCHAR)
> > + * @usbc_hcint:  Host Channel-n Interrupt Register
> > + * @usb: USB device
> > + * @channel: Channel to poll
> > + *
> > + * In non DMA mode the channels don't halt themselves. We need
> > + * to manually disable channels that are left running
> > + *
> > + * Returns: -1 on halt
> > + */
> > +static int cvmx_usb_dma_halt(union cvmx_usbcx_hccharx usbc_hcchar,
> > +  union cvmx_usbcx_hcintx usbc_hcint,
>
> It looks very suspect to pass unions on the stack.
>
> Are you sure these aren't used after this function
> is called?
>
> Likely these should be pointers to unions.
>


-- 
Best regards!
Georgios Tsotsos
Greece-Evia-Chalkida
tsot...@linux.com
skype: tsotsos

Georgios Tsotsos
*Greece - Evia - Chalkida*
tsotsos[at]linux.com
skype: tsotsos
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging: rtl8188eu: remove unused sreset_get_wifi_status()

2018-07-26 Thread Michael Straube
The function sreset_get_wifi_status() is never used, so remove it.
Discovered by cppcheck.

Signed-off-by: Michael Straube 
---
 drivers/staging/rtl8188eu/core/rtw_sreset.c   | 27 ---
 .../staging/rtl8188eu/include/rtw_sreset.h|  1 -
 2 files changed, 28 deletions(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_sreset.c 
b/drivers/staging/rtl8188eu/core/rtw_sreset.c
index 4097380b0bc9..fb5adaf4a42c 100644
--- a/drivers/staging/rtl8188eu/core/rtw_sreset.c
+++ b/drivers/staging/rtl8188eu/core/rtw_sreset.c
@@ -15,33 +15,6 @@ void rtw_hal_sreset_init(struct adapter *padapter)
psrtpriv->Wifi_Error_Status = WIFI_STATUS_SUCCESS;
 }
 
-u8 sreset_get_wifi_status(struct adapter *padapter)
-{
-   struct sreset_priv *psrtpriv = >HalData->srestpriv;
-
-   u8 status = WIFI_STATUS_SUCCESS;
-   u32 val32 = 0;
-
-   val32 = usb_read32(padapter, REG_TXDMA_STATUS);
-   if (val32 == 0xeaeaeaea) {
-   psrtpriv->Wifi_Error_Status = WIFI_IF_NOT_EXIST;
-   } else if (val32 != 0) {
-   DBG_88E("txdmastatu(%x)\n", val32);
-   psrtpriv->Wifi_Error_Status = WIFI_MAC_TXDMA_ERROR;
-   }
-
-   if (WIFI_STATUS_SUCCESS != psrtpriv->Wifi_Error_Status) {
-   DBG_88E("==>%s error_status(0x%x)\n", __func__, 
psrtpriv->Wifi_Error_Status);
-   status = psrtpriv->Wifi_Error_Status & 
(~(USB_READ_PORT_FAIL|USB_WRITE_PORT_FAIL));
-   }
-   DBG_88E("==> %s wifi_status(0x%x)\n", __func__, status);
-
-   /* status restore */
-   psrtpriv->Wifi_Error_Status = WIFI_STATUS_SUCCESS;
-
-   return status;
-}
-
 void sreset_set_wifi_error_status(struct adapter *padapter, u32 status)
 {
padapter->HalData->srestpriv.Wifi_Error_Status = status;
diff --git a/drivers/staging/rtl8188eu/include/rtw_sreset.h 
b/drivers/staging/rtl8188eu/include/rtw_sreset.h
index a03989461985..3ee6a4a7847d 100644
--- a/drivers/staging/rtl8188eu/include/rtw_sreset.h
+++ b/drivers/staging/rtl8188eu/include/rtw_sreset.h
@@ -25,7 +25,6 @@ struct sreset_priv {
 #defineWIFI_RX_HANGBIT(5)
 #defineWIFI_IF_NOT_EXIST   BIT(6)
 
-u8 sreset_get_wifi_status(struct adapter *padapter);
 void sreset_set_wifi_error_status(struct adapter *padapter, u32 status);
 
 #endif
-- 
2.18.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


RE: [PATCH] Drivers: HV: panic kmsg dump, move MSR access to arch specific

2018-07-26 Thread KY Srinivasan



> -Original Message-
> From: Sunil Muthuswamy
> Sent: Monday, July 23, 2018 11:31 AM
> To: Michael Kelley (EOSG) ; Sunil
> Muthuswamy 
> Cc: KY Srinivasan ; Stephen Hemminger
> ; Haiyang Zhang ;
> de...@linuxdriverproject.org
> Subject: [PATCH] Drivers: HV: panic kmsg dump, move MSR access to arch
> specific
> 
> Moves the MSR access from arch independent code to arch
> dependent code. Also includes minor bug fixes.

Please breakup this patch into 3 patches:

1) Making the code ISA independent - moving the MSR accesses out of the common 
code.
2) Fixing the issue with checking the return value from kmsg_dump_get_buffer()
3) Fix the issue with freeing up hv_ctl_table_hdr

Thank you,

K. Y
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 13/16] staging:rtl8192u: Rename HW90_BLOCK_E - Style

2018-07-26 Thread John Whitmore
Rename the enumerated type HW90_BLOCK_E to hw90_block_e. Whilst this is
not flagged by checkpatch types are meant to be in lowercase.

This is a coding style change which should have no impact on runtime
code execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/r819xU_phy.c | 8 
 drivers/staging/rtl8192u/r819xU_phy.h | 4 ++--
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/rtl8192u/r819xU_phy.c 
b/drivers/staging/rtl8192u/r819xU_phy.c
index 983520b3aa25..c8c54484eab5 100644
--- a/drivers/staging/rtl8192u/r819xU_phy.c
+++ b/drivers/staging/rtl8192u/r819xU_phy.c
@@ -687,14 +687,14 @@ static void rtl8192_InitBBRFRegDef(struct net_device *dev)
  * function:  This function is to write register and then readback to make
  *sure whether BB and RF is OK
  * input: net_device*dev
- *HW90_BLOCK_E  CheckBlock
+ *hw90_block_e  CheckBlock
  *RF90_RADIO_PATH_E eRFPath  //only used when checkblock is
  *   //HW90_BLOCK_RF
  * output:none
  * return:return whether BB and RF is ok (0:OK, 1:Fail)
  * notice:This function may be removed in the ASIC
  
**/
-u8 rtl8192_phy_checkBBAndRF(struct net_device *dev, enum HW90_BLOCK_E 
CheckBlock,
+u8 rtl8192_phy_checkBBAndRF(struct net_device *dev, enum hw90_block_e 
CheckBlock,
enum RF90_RADIO_PATH_E eRFPath)
 {
u8 ret = 0;
@@ -786,10 +786,10 @@ static void rtl8192_BB_Config_ParaFile(struct net_device 
*dev)
 
/* Ckeck FPGAPHY0 and PHY1 board is OK */
/* TODO: this function should be removed on ASIC */
-   for (eCheckItem = (enum HW90_BLOCK_E)HW90_BLOCK_PHY0;
+   for (eCheckItem = (enum hw90_block_e)HW90_BLOCK_PHY0;
 eCheckItem <= HW90_BLOCK_PHY1; eCheckItem++) {
/* don't care RF path */
-   status = rtl8192_phy_checkBBAndRF(dev, (enum 
HW90_BLOCK_E)eCheckItem,
+   status = rtl8192_phy_checkBBAndRF(dev, (enum 
hw90_block_e)eCheckItem,
  (enum RF90_RADIO_PATH_E)0);
if (status != 0) {
RT_TRACE((COMP_ERR | COMP_PHY),
diff --git a/drivers/staging/rtl8192u/r819xU_phy.h 
b/drivers/staging/rtl8192u/r819xU_phy.h
index 2cd1c25164a2..d9503996457d 100644
--- a/drivers/staging/rtl8192u/r819xU_phy.h
+++ b/drivers/staging/rtl8192u/r819xU_phy.h
@@ -25,7 +25,7 @@ struct sw_chnl_cmd {
u32 ms_delay;
 } __packed;
 
-enum HW90_BLOCK_E {
+enum hw90_block_e {
HW90_BLOCK_MAC = 0,
HW90_BLOCK_PHY0 = 1,
HW90_BLOCK_PHY1 = 2,
@@ -62,7 +62,7 @@ u32 rtl8192_phy_QueryRFReg(struct net_device *dev,
 void rtl8192_phy_configmac(struct net_device *dev);
 void rtl8192_phyConfigBB(struct net_device *dev, u8 ConfigType);
 u8 rtl8192_phy_checkBBAndRF(struct net_device *dev,
-   enum HW90_BLOCK_E CheckBlock,
+   enum hw90_block_e CheckBlock,
enum RF90_RADIO_PATH_E eRFPath);
 void rtl8192_BBConfig(struct net_device *dev);
 void rtl8192_phy_getTxPower(struct net_device *dev);
-- 
2.18.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 15/16] staging:rtl8192u: Remove repeated definitions - Style

2018-07-26 Thread John Whitmore
Remove bit field masks which are defined in two files: r819xU_phy.h
and r819xU_phyreg.h. Or in the case of bMaskByte3 defined but never used.

The definitions have been removed from the file r819xU_phy.h.

This is a coding style change, which should have no impact on runtime
code execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/r819xU_phy.h | 8 
 1 file changed, 8 deletions(-)

diff --git a/drivers/staging/rtl8192u/r819xU_phy.h 
b/drivers/staging/rtl8192u/r819xU_phy.h
index 1ad459cf05ae..8ca869e8ee2f 100644
--- a/drivers/staging/rtl8192u/r819xU_phy.h
+++ b/drivers/staging/rtl8192u/r819xU_phy.h
@@ -41,14 +41,6 @@ enum rf90_radio_path_e {
RF90_PATH_MAX   /* Max RF number 92 support */
 };
 
-#define bMaskByte00xff
-#define bMaskByte10xff00
-#define bMaskByte20xff
-#define bMaskByte30xff00
-#define bMaskHWord0x
-#define bMaskLWord0x
-#define bMaskDWord0x
-
 u8 rtl8192_phy_CheckIsLegalRFPath(struct net_device *dev, u32 eRFPath);
 void rtl8192_setBBreg(struct net_device *dev, u32 reg_addr,
  u32 bitmask, u32 data);
-- 
2.18.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 14/16] staging:rtl8192u: Rename RF90_RADIO_PATH_E - Style

2018-07-26 Thread John Whitmore
Rename the enumerated type RF90_RADIO_PATH_E to rf90_radio_path_e.
Whilst it is not flagged as an issue by checkpatch, types are meant
to be named in lowercase.

This change is purely a coding style change which should have no
impact on runtime code execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/r8190_rtl8256.c | 42 
 drivers/staging/rtl8192u/r8192U_core.c   |  4 +--
 drivers/staging/rtl8192u/r819xU_phy.c| 38 ++---
 drivers/staging/rtl8192u/r819xU_phy.h| 10 +++---
 4 files changed, 47 insertions(+), 47 deletions(-)

diff --git a/drivers/staging/rtl8192u/r8190_rtl8256.c 
b/drivers/staging/rtl8192u/r8190_rtl8256.c
index 9f35dcb9e13e..9b7f822e9762 100644
--- a/drivers/staging/rtl8192u/r8190_rtl8256.c
+++ b/drivers/staging/rtl8192u/r8190_rtl8256.c
@@ -41,16 +41,16 @@ void PHY_SetRF8256Bandwidth(struct net_device *dev, enum 
ht_channel_width Bandwi
|| priv->card_8192_version
== VERSION_819xU_B) { /* 8256 D-cut, 
E-cut, xiong: consider it later! */
rtl8192_phy_SetRFReg(dev,
-   (enum RF90_RADIO_PATH_E)eRFPath,
+   (enum rf90_radio_path_e)eRFPath,
0x0b, bMask12Bits, 0x100); /* 
phy para:1ba */
rtl8192_phy_SetRFReg(dev,
-   (enum RF90_RADIO_PATH_E)eRFPath,
+   (enum rf90_radio_path_e)eRFPath,
0x2c, bMask12Bits, 0x3d7);
rtl8192_phy_SetRFReg(dev,
-   (enum RF90_RADIO_PATH_E)eRFPath,
+   (enum rf90_radio_path_e)eRFPath,
0x0e, bMask12Bits, 0x021);
rtl8192_phy_SetRFReg(dev,
-   (enum RF90_RADIO_PATH_E)eRFPath,
+   (enum rf90_radio_path_e)eRFPath,
0x14, bMask12Bits, 0x5ab);
} else {
RT_TRACE(COMP_ERR, 
"PHY_SetRF8256Bandwidth(): unknown hardware version\n");
@@ -58,15 +58,15 @@ void PHY_SetRF8256Bandwidth(struct net_device *dev, enum 
ht_channel_width Bandwi
break;
case HT_CHANNEL_WIDTH_20_40:
if (priv->card_8192_version == VERSION_819xU_A 
|| priv->card_8192_version == VERSION_819xU_B) { /* 8256 D-cut, E-cut, xiong: 
consider it later! */
-   rtl8192_phy_SetRFReg(dev, (enum 
RF90_RADIO_PATH_E)eRFPath, 0x0b, bMask12Bits, 0x300); /* phy para:3ba */
-   rtl8192_phy_SetRFReg(dev, (enum 
RF90_RADIO_PATH_E)eRFPath, 0x2c, bMask12Bits, 0x3df);
-   rtl8192_phy_SetRFReg(dev, (enum 
RF90_RADIO_PATH_E)eRFPath, 0x0e, bMask12Bits, 0x0a1);
+   rtl8192_phy_SetRFReg(dev, (enum 
rf90_radio_path_e)eRFPath, 0x0b, bMask12Bits, 0x300); /* phy para:3ba */
+   rtl8192_phy_SetRFReg(dev, (enum 
rf90_radio_path_e)eRFPath, 0x2c, bMask12Bits, 0x3df);
+   rtl8192_phy_SetRFReg(dev, (enum 
rf90_radio_path_e)eRFPath, 0x0e, bMask12Bits, 0x0a1);
 
if (priv->chan == 3 || priv->chan == 9)
/* I need to set priv->chan 
whenever current channel changes */
-   rtl8192_phy_SetRFReg(dev, (enum 
RF90_RADIO_PATH_E)eRFPath, 0x14, bMask12Bits, 0x59b);
+   rtl8192_phy_SetRFReg(dev, (enum 
rf90_radio_path_e)eRFPath, 0x14, bMask12Bits, 0x59b);
else
-   rtl8192_phy_SetRFReg(dev, (enum 
RF90_RADIO_PATH_E)eRFPath, 0x14, bMask12Bits, 0x5ab);
+   rtl8192_phy_SetRFReg(dev, (enum 
rf90_radio_path_e)eRFPath, 0x14, bMask12Bits, 0x5ab);
} else {
RT_TRACE(COMP_ERR, 
"PHY_SetRF8256Bandwidth(): unknown hardware version\n");
}
@@ -115,14 +115,14 @@ void phy_RF8256_Config_ParaFile(struct net_device *dev)
u8  ConstRetryTimes = 5, RetryTimes = 5;
u8 ret = 0;
/* Initialize RF */
-   for (eRFPath = (enum RF90_RADIO_PATH_E)RF90_PATH_A; eRFPath < 
priv->NumTotalRFPath; eRFPath++) {
+   for (eRFPath = (enum rf90_radio_path_e)RF90_PATH_A; 

[PATCH 11/16] staging:rtl8192u: Remove proxy rtl819XRadioC_Array - Style

2018-07-26 Thread John Whitmore
Remove the array rtl819XRadioC_Array which is only serving as a proxy for
the real array Rtl8192UsbRadioC_Array. This is a coding style change and
should have no impact on runtime code execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/r819xU_phy.c | 7 +++
 drivers/staging/rtl8192u/r819xU_phy.h | 1 -
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/rtl8192u/r819xU_phy.c 
b/drivers/staging/rtl8192u/r819xU_phy.c
index 1cbb48c5c110..3ed48d6095d7 100644
--- a/drivers/staging/rtl8192u/r819xU_phy.c
+++ b/drivers/staging/rtl8192u/r819xU_phy.c
@@ -29,7 +29,6 @@ static u32 RF_CHANNEL_TABLE_ZEBRA[] = {
 };
 
 #define rtl819XMACPHY_Array Rtl8192UsbMACPHY_Array
-#define rtl819XRadioC_Array Rtl8192UsbRadioC_Array
 #define rtl819XRadioD_Array Rtl8192UsbRadioD_Array
 
 /**
@@ -1009,14 +1008,14 @@ u8 rtl8192_phy_ConfigRFWithHeaderFile(struct net_device 
*dev,
case RF90_PATH_C:
for (i = 0; i < RadioC_ArrayLength; i = i+2) {
 
-   if (rtl819XRadioC_Array[i] == 0xfe) {
+   if (Rtl8192UsbRadioC_Array[i] == 0xfe) {
mdelay(100);
continue;
}
rtl8192_phy_SetRFReg(dev, eRFPath,
-rtl819XRadioC_Array[i],
+Rtl8192UsbRadioC_Array[i],
 bMask12Bits,
-rtl819XRadioC_Array[i+1]);
+Rtl8192UsbRadioC_Array[i+1]);
mdelay(1);
 
}
diff --git a/drivers/staging/rtl8192u/r819xU_phy.h 
b/drivers/staging/rtl8192u/r819xU_phy.h
index d708796d7cec..44af37f19f45 100644
--- a/drivers/staging/rtl8192u/r819xU_phy.h
+++ b/drivers/staging/rtl8192u/r819xU_phy.h
@@ -25,7 +25,6 @@ struct sw_chnl_cmd {
u32 ms_delay;
 } __packed;
 
-extern u32 rtl819XRadioC_Array[];
 extern u32 rtl819XRadioD_Array[];
 
 enum HW90_BLOCK_E {
-- 
2.18.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 08/16] staging:rtl8192u: Remove proxy array rtl819XAGCTAB_Array - Style

2018-07-26 Thread John Whitmore
Remove the array rtl819XAGCTAB_Array which is only a proxy to the
array Rtl8192UsbAGCTAB_Array. There appears to be no purpose
served by this implementation, other then to obscure the
Rtl8192UsbAGCTAB_Array structure, which is actually written to and
read from.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/r819xU_phy.c | 11 +--
 drivers/staging/rtl8192u/r819xU_phy.h |  1 -
 2 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/rtl8192u/r819xU_phy.c 
b/drivers/staging/rtl8192u/r819xU_phy.c
index 8d44bbe90221..cf7b09f9818a 100644
--- a/drivers/staging/rtl8192u/r819xU_phy.c
+++ b/drivers/staging/rtl8192u/r819xU_phy.c
@@ -33,7 +33,6 @@ static u32 RF_CHANNEL_TABLE_ZEBRA[] = {
 #define rtl819XRadioB_Array Rtl8192UsbRadioB_Array
 #define rtl819XRadioC_Array Rtl8192UsbRadioC_Array
 #define rtl819XRadioD_Array Rtl8192UsbRadioD_Array
-#define rtl819XAGCTAB_Array Rtl8192UsbAGCTAB_Array
 
 /**
  * function:  This function checks different RF type to execute legal 
judgement.
@@ -542,12 +541,12 @@ void rtl8192_phyConfigBB(struct net_device *dev, u8 
ConfigType)
}
} else if (ConfigType == BaseBand_Config_AGC_TAB) {
for (i = 0; i < AGCTAB_ArrayLength; i += 2) {
-   rtl8192_setBBreg(dev, rtl819XAGCTAB_Array[i],
-bMaskDWord, rtl819XAGCTAB_Array[i+1]);
+   rtl8192_setBBreg(dev, Rtl8192UsbAGCTAB_Array[i],
+bMaskDWord, 
Rtl8192UsbAGCTAB_Array[i+1]);
RT_TRACE(COMP_DBG,
-"i: %x, rtl819XAGCTAB_Array[0]=%x 
rtl819XAGCTAB_Array[1]=%x\n",
-i, rtl819XAGCTAB_Array[i],
-rtl819XAGCTAB_Array[i+1]);
+"i: %x, Rtl8192UsbAGCTAB_Array[0]=%x 
Rtl8192UsbAGCTAB_Array[1]=%x\n",
+i, Rtl8192UsbAGCTAB_Array[i],
+Rtl8192UsbAGCTAB_Array[i+1]);
}
}
 }
diff --git a/drivers/staging/rtl8192u/r819xU_phy.h 
b/drivers/staging/rtl8192u/r819xU_phy.h
index 842837bd6631..808a11c475a4 100644
--- a/drivers/staging/rtl8192u/r819xU_phy.h
+++ b/drivers/staging/rtl8192u/r819xU_phy.h
@@ -25,7 +25,6 @@ struct sw_chnl_cmd {
u32 ms_delay;
 } __packed;
 
-extern u32 rtl819XAGCTAB_Array[];
 extern u32 rtl819XRadioA_Array[];
 extern u32 rtl819XRadioB_Array[];
 extern u32 rtl819XRadioC_Array[];
-- 
2.18.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 12/16] staging:rtl8192u: Remove proxy rtl819XRadioD_Array - Style

2018-07-26 Thread John Whitmore
Remove the array rtl819XRadioD_Array which is only acting as a proxy to
the real array Rtl8192UsbRadioD_Array.

This is a coding style change which should have no impact on runtime
code execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/r819xU_phy.c | 7 +++
 drivers/staging/rtl8192u/r819xU_phy.h | 2 --
 2 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/rtl8192u/r819xU_phy.c 
b/drivers/staging/rtl8192u/r819xU_phy.c
index 3ed48d6095d7..983520b3aa25 100644
--- a/drivers/staging/rtl8192u/r819xU_phy.c
+++ b/drivers/staging/rtl8192u/r819xU_phy.c
@@ -29,7 +29,6 @@ static u32 RF_CHANNEL_TABLE_ZEBRA[] = {
 };
 
 #define rtl819XMACPHY_Array Rtl8192UsbMACPHY_Array
-#define rtl819XRadioD_Array Rtl8192UsbRadioD_Array
 
 /**
  * function:  This function checks different RF type to execute legal 
judgement.
@@ -1023,14 +1022,14 @@ u8 rtl8192_phy_ConfigRFWithHeaderFile(struct net_device 
*dev,
case RF90_PATH_D:
for (i = 0; i < RadioD_ArrayLength; i = i+2) {
 
-   if (rtl819XRadioD_Array[i] == 0xfe) {
+   if (Rtl8192UsbRadioD_Array[i] == 0xfe) {
mdelay(100);
continue;
}
rtl8192_phy_SetRFReg(dev, eRFPath,
-rtl819XRadioD_Array[i],
+Rtl8192UsbRadioD_Array[i],
 bMask12Bits,
-rtl819XRadioD_Array[i+1]);
+Rtl8192UsbRadioD_Array[i+1]);
mdelay(1);
 
}
diff --git a/drivers/staging/rtl8192u/r819xU_phy.h 
b/drivers/staging/rtl8192u/r819xU_phy.h
index 44af37f19f45..2cd1c25164a2 100644
--- a/drivers/staging/rtl8192u/r819xU_phy.h
+++ b/drivers/staging/rtl8192u/r819xU_phy.h
@@ -25,8 +25,6 @@ struct sw_chnl_cmd {
u32 ms_delay;
 } __packed;
 
-extern u32 rtl819XRadioD_Array[];
-
 enum HW90_BLOCK_E {
HW90_BLOCK_MAC = 0,
HW90_BLOCK_PHY0 = 1,
-- 
2.18.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 09/16] staging:rtl8192u: Remove proxy rtl819XRadioA_Array - Style

2018-07-26 Thread John Whitmore
The array rtl819XRadioA_Array serves as a proxy array for the actual
array Rtl8192UsbRadioA_Array. This implementation seems to serve no
other purpose then to obscure the actually array Rtl8192UsbRadioA_Array.

This is a coding style change which should have no impact on runtime
code execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/r819xU_phy.c | 7 +++
 drivers/staging/rtl8192u/r819xU_phy.h | 1 -
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/rtl8192u/r819xU_phy.c 
b/drivers/staging/rtl8192u/r819xU_phy.c
index cf7b09f9818a..775dfa847b93 100644
--- a/drivers/staging/rtl8192u/r819xU_phy.c
+++ b/drivers/staging/rtl8192u/r819xU_phy.c
@@ -29,7 +29,6 @@ static u32 RF_CHANNEL_TABLE_ZEBRA[] = {
 };
 
 #define rtl819XMACPHY_Array Rtl8192UsbMACPHY_Array
-#define rtl819XRadioA_Array  Rtl8192UsbRadioA_Array
 #define rtl819XRadioB_Array Rtl8192UsbRadioB_Array
 #define rtl819XRadioC_Array Rtl8192UsbRadioC_Array
 #define rtl819XRadioD_Array Rtl8192UsbRadioD_Array
@@ -981,14 +980,14 @@ u8 rtl8192_phy_ConfigRFWithHeaderFile(struct net_device 
*dev,
case RF90_PATH_A:
for (i = 0; i < RadioA_ArrayLength; i = i+2) {
 
-   if (rtl819XRadioA_Array[i] == 0xfe) {
+   if (Rtl8192UsbRadioA_Array[i] == 0xfe) {
mdelay(100);
continue;
}
rtl8192_phy_SetRFReg(dev, eRFPath,
-rtl819XRadioA_Array[i],
+Rtl8192UsbRadioA_Array[i],
 bMask12Bits,
-rtl819XRadioA_Array[i+1]);
+Rtl8192UsbRadioA_Array[i+1]);
mdelay(1);
 
}
diff --git a/drivers/staging/rtl8192u/r819xU_phy.h 
b/drivers/staging/rtl8192u/r819xU_phy.h
index 808a11c475a4..7c4b89a5c592 100644
--- a/drivers/staging/rtl8192u/r819xU_phy.h
+++ b/drivers/staging/rtl8192u/r819xU_phy.h
@@ -25,7 +25,6 @@ struct sw_chnl_cmd {
u32 ms_delay;
 } __packed;
 
-extern u32 rtl819XRadioA_Array[];
 extern u32 rtl819XRadioB_Array[];
 extern u32 rtl819XRadioC_Array[];
 extern u32 rtl819XRadioD_Array[];
-- 
2.18.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 16/16] staging:rtl8192u: Rename eRFPath - Style

2018-07-26 Thread John Whitmore
Rename the variable eRFPath to e_rfpath. This change resolves a
checkpatch issue with CamelCase naming. The variable name is used both
as a parameter name in function definitions, function prototypes and as
a local variable.

This change is purely a coding style change which should have no impact
on runtime code execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/r819xU_phy.c | 120 +-
 drivers/staging/rtl8192u/r819xU_phy.h |  10 +--
 2 files changed, 65 insertions(+), 65 deletions(-)

diff --git a/drivers/staging/rtl8192u/r819xU_phy.c 
b/drivers/staging/rtl8192u/r819xU_phy.c
index fb74b749fbcf..7ee10d49894b 100644
--- a/drivers/staging/rtl8192u/r819xU_phy.c
+++ b/drivers/staging/rtl8192u/r819xU_phy.c
@@ -34,11 +34,11 @@ static u32 RF_CHANNEL_TABLE_ZEBRA[] = {
  * function:  This function checks different RF type to execute legal 
judgement.
  *If RF Path is illegal, we will return false.
  * input: net_device*dev
- *u32   eRFPath
+ *u32   e_rfpath
  * output:none
  * return:0(illegal, false), 1(legal, true)
  */
-u8 rtl8192_phy_CheckIsLegalRFPath(struct net_device *dev, u32 eRFPath)
+u8 rtl8192_phy_CheckIsLegalRFPath(struct net_device *dev, u32 e_rfpath)
 {
u8 ret = 1;
struct r8192_priv *priv = ieee80211_priv(dev);
@@ -46,9 +46,9 @@ u8 rtl8192_phy_CheckIsLegalRFPath(struct net_device *dev, u32 
eRFPath)
if (priv->rf_type == RF_2T4R) {
ret = 0;
} else if (priv->rf_type == RF_1T2R) {
-   if (eRFPath == RF90_PATH_A || eRFPath == RF90_PATH_B)
+   if (e_rfpath == RF90_PATH_A || e_rfpath == RF90_PATH_B)
ret = 1;
-   else if (eRFPath == RF90_PATH_C || eRFPath == RF90_PATH_D)
+   else if (e_rfpath == RF90_PATH_C || e_rfpath == RF90_PATH_D)
ret = 0;
}
return ret;
@@ -101,18 +101,18 @@ u32 rtl8192_QueryBBReg(struct net_device *dev, u32 
reg_addr, u32 bitmask)
 }
 
 static u32 phy_FwRFSerialRead(struct net_device *dev,
- enum rf90_radio_path_e eRFPath,
+ enum rf90_radio_path_e e_rfpath,
  u32 offset);
 
 static void phy_FwRFSerialWrite(struct net_device *dev,
-   enum rf90_radio_path_e eRFPath,
+   enum rf90_radio_path_e e_rfpath,
u32  offset,
u32  data);
 
 /**
  * function:  This function reads register from RF chip
  * input: net_device*dev
- *rf90_radio_path_e eRFPath//radio path of A/B/C/D
+ *rf90_radio_path_e e_rfpath//radio path of A/B/C/D
  *u32   offset //target address to be read
  * output:none
  * return:u32   readback value
@@ -124,12 +124,12 @@ static void phy_FwRFSerialWrite(struct net_device *dev,
  *---need more spec for this information.
  
**/
 static u32 rtl8192_phy_RFSerialRead(struct net_device *dev,
-   enum rf90_radio_path_e eRFPath, u32 offset)
+   enum rf90_radio_path_e e_rfpath, u32 offset)
 {
struct r8192_priv *priv = ieee80211_priv(dev);
u32 ret = 0;
u32 new_offset = 0;
-   BB_REGISTER_DEFINITION_T *pPhyReg = >PHYRegDef[eRFPath];
+   BB_REGISTER_DEFINITION_T *pPhyReg = >PHYRegDef[e_rfpath];
 
rtl8192_setBBreg(dev, pPhyReg->rfLSSIReadBack, bLSSIReadBackData, 0);
/* Make sure RF register offset is correct */
@@ -138,20 +138,20 @@ static u32 rtl8192_phy_RFSerialRead(struct net_device 
*dev,
/* Switch page for 8256 RF IC */
if (priv->rf_chip == RF_8256) {
if (offset >= 31) {
-   priv->RfReg0Value[eRFPath] |= 0x140;
+   priv->RfReg0Value[e_rfpath] |= 0x140;
/* Switch to Reg_Mode2 for Reg 31-45 */
rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset,
 bMaskDWord,
-priv->RfReg0Value[eRFPath]<<16);
+priv->RfReg0Value[e_rfpath]<<16);
/* Modify offset */
new_offset = offset - 30;
} else if (offset >= 16) {
-   priv->RfReg0Value[eRFPath] |= 0x100;
-   priv->RfReg0Value[eRFPath] &= (~0x40);
+   priv->RfReg0Value[e_rfpath] |= 0x100;
+   priv->RfReg0Value[e_rfpath] &= (~0x40);
/* Switch to 

[PATCH 06/16] staging:rtl8192u: Remove proxy struct rtl819XMACPHY_Array_PG - Style

2018-07-26 Thread John Whitmore
Remove the struct rtl819XMACPHY_Array_PG which is simply a proxy for
the struct Rtl8192UsbMACPHY_Array_PG. There appears to be no purpose
served by this implementation, other then to obscure the
Rtl8192UsbMACPHY_Array_PG structure.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/r819xU_phy.c | 3 +--
 drivers/staging/rtl8192u/r819xU_phy.h | 1 -
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/staging/rtl8192u/r819xU_phy.c 
b/drivers/staging/rtl8192u/r819xU_phy.c
index 496f42b8f425..cc35ca7b9140 100644
--- a/drivers/staging/rtl8192u/r819xU_phy.c
+++ b/drivers/staging/rtl8192u/r819xU_phy.c
@@ -30,7 +30,6 @@ static u32 RF_CHANNEL_TABLE_ZEBRA[] = {
 
 
 #define rtl819XPHY_REG_1T2RArray Rtl8192UsbPHY_REG_1T2RArray
-#define rtl819XMACPHY_Array_PG Rtl8192UsbMACPHY_Array_PG
 #define rtl819XMACPHY_Array Rtl8192UsbMACPHY_Array
 #define rtl819XRadioA_Array  Rtl8192UsbRadioA_Array
 #define rtl819XRadioB_Array Rtl8192UsbRadioB_Array
@@ -491,7 +490,7 @@ void rtl8192_phy_configmac(struct net_device *dev)
if (priv->btxpowerdata_readfromEEPORM) {
RT_TRACE(COMP_PHY, "Rtl819XMACPHY_Array_PG\n");
dwArrayLen = MACPHY_Array_PGLength;
-   pdwArray = rtl819XMACPHY_Array_PG;
+   pdwArray = Rtl8192UsbMACPHY_Array_PG;
 
} else {
RT_TRACE(COMP_PHY, "Rtl819XMACPHY_Array\n");
diff --git a/drivers/staging/rtl8192u/r819xU_phy.h 
b/drivers/staging/rtl8192u/r819xU_phy.h
index d783e9c0dfd1..3c069b89bcdb 100644
--- a/drivers/staging/rtl8192u/r819xU_phy.h
+++ b/drivers/staging/rtl8192u/r819xU_phy.h
@@ -25,7 +25,6 @@ struct sw_chnl_cmd {
u32 ms_delay;
 } __packed;
 
-extern u32 rtl819XMACPHY_Array_PG[];
 extern u32 rtl819XPHY_REG_1T2RArray[];
 extern u32 rtl819XAGCTAB_Array[];
 extern u32 rtl819XRadioA_Array[];
-- 
2.18.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 05/16] staging:rtl8192u: Rename msDelay to ms_delay - Style

2018-07-26 Thread John Whitmore
Rename the member variable msDelay to ms_delay. This change clears the
checkpatch issue with CamelCase naming. The change is purely a coding
style change which should not impact runtime code execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/r819xU_phy.c | 6 +++---
 drivers/staging/rtl8192u/r819xU_phy.h | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/rtl8192u/r819xU_phy.c 
b/drivers/staging/rtl8192u/r819xU_phy.c
index 904cc8c1a83b..496f42b8f425 100644
--- a/drivers/staging/rtl8192u/r819xU_phy.c
+++ b/drivers/staging/rtl8192u/r819xU_phy.c
@@ -1247,7 +1247,7 @@ static u8 rtl8192_phy_SetSwChnlCmdArray(struct 
sw_chnl_cmd *CmdTable, u32 CmdTab
pCmd->cmd_id = CmdID;
pCmd->para_1 = Para1;
pCmd->para_2 = Para2;
-   pCmd->msDelay = msDelay;
+   pCmd->ms_delay = msDelay;
 
return true;
 }
@@ -1365,7 +1365,7 @@ static u8 rtl8192_phy_SwChnlStepByStep(struct net_device 
*dev, u8 channel,
 
if (CurrentCmd->cmd_id == CMD_ID_END) {
if ((*stage) == 2) {
-   (*delay) = CurrentCmd->msDelay;
+   (*delay) = CurrentCmd->ms_delay;
return true;
}
(*stage)++;
@@ -1407,7 +1407,7 @@ static u8 rtl8192_phy_SwChnlStepByStep(struct net_device 
*dev, u8 channel,
break;
} while (true);
 
-   (*delay) = CurrentCmd->msDelay;
+   (*delay) = CurrentCmd->ms_delay;
(*step)++;
return false;
 }
diff --git a/drivers/staging/rtl8192u/r819xU_phy.h 
b/drivers/staging/rtl8192u/r819xU_phy.h
index 0d4c083ea718..d783e9c0dfd1 100644
--- a/drivers/staging/rtl8192u/r819xU_phy.h
+++ b/drivers/staging/rtl8192u/r819xU_phy.h
@@ -22,7 +22,7 @@ struct sw_chnl_cmd {
enum switch_chan_cmd_id cmd_id;
u32 para_1;
u32 para_2;
-   u32 msDelay;
+   u32 ms_delay;
 } __packed;
 
 extern u32 rtl819XMACPHY_Array_PG[];
-- 
2.18.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 02/16] staging:rtl8192u: Rename CmdID - Style

2018-07-26 Thread John Whitmore
Rename the member variable CmdId to cmd_id. This change clears the
checkpatch issue with CamelCase naming. The change is purely a coding
style change which should have no impact on runtime code execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/r819xU_phy.c | 6 +++---
 drivers/staging/rtl8192u/r819xU_phy.h | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/rtl8192u/r819xU_phy.c 
b/drivers/staging/rtl8192u/r819xU_phy.c
index 4a49bc1f139c..17cc47e20145 100644
--- a/drivers/staging/rtl8192u/r819xU_phy.c
+++ b/drivers/staging/rtl8192u/r819xU_phy.c
@@ -1244,7 +1244,7 @@ static u8 rtl8192_phy_SetSwChnlCmdArray(struct 
sw_chnl_cmd *CmdTable, u32 CmdTab
}
 
pCmd = CmdTable + CmdTableIdx;
-   pCmd->CmdID = CmdID;
+   pCmd->cmd_id = CmdID;
pCmd->Para1 = Para1;
pCmd->Para2 = Para2;
pCmd->msDelay = msDelay;
@@ -1363,7 +1363,7 @@ static u8 rtl8192_phy_SwChnlStepByStep(struct net_device 
*dev, u8 channel,
break;
}
 
-   if (CurrentCmd->CmdID == CMD_ID_END) {
+   if (CurrentCmd->cmd_id == CMD_ID_END) {
if ((*stage) == 2) {
(*delay) = CurrentCmd->msDelay;
return true;
@@ -1373,7 +1373,7 @@ static u8 rtl8192_phy_SwChnlStepByStep(struct net_device 
*dev, u8 channel,
continue;
}
 
-   switch (CurrentCmd->CmdID) {
+   switch (CurrentCmd->cmd_id) {
case CMD_ID_SET_TX_PWR_LEVEL:
if (priv->card_8192_version == (u8)VERSION_819xU_A)
/* consider it later! */
diff --git a/drivers/staging/rtl8192u/r819xU_phy.h 
b/drivers/staging/rtl8192u/r819xU_phy.h
index 509b18415127..75970febaac5 100644
--- a/drivers/staging/rtl8192u/r819xU_phy.h
+++ b/drivers/staging/rtl8192u/r819xU_phy.h
@@ -19,7 +19,7 @@ enum switch_chan_cmd_id {
 /* ---Define structure-- */
 /* 1. Switch channel related */
 struct sw_chnl_cmd {
-   enum switch_chan_cmd_id CmdID;
+   enum switch_chan_cmd_id cmd_id;
u32 Para1;
u32 Para2;
u32 msDelay;
-- 
2.18.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 01/16] staging:rtl8192u: Rename SwChnlCmd - Style

2018-07-26 Thread John Whitmore
Rename the structure SwChnlCmd to sw_chnl_cmd. This change clears the
checkpatch issue with CamelCase naming. The change is purely a coding
style change and should have no impact on runtime code execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/r819xU_phy.c | 16 
 drivers/staging/rtl8192u/r819xU_phy.h |  2 +-
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/rtl8192u/r819xU_phy.c 
b/drivers/staging/rtl8192u/r819xU_phy.c
index 75fcd3134b6d..4a49bc1f139c 100644
--- a/drivers/staging/rtl8192u/r819xU_phy.c
+++ b/drivers/staging/rtl8192u/r819xU_phy.c
@@ -1215,8 +1215,8 @@ bool rtl8192_SetRFPowerState(struct net_device *dev,
 }
 
 /**
- * function:  This function sets command table variable (struct SwChnlCmd).
- * input: SwChnlCmd  *CmdTable//table to be set
+ * function:  This function sets command table variable (struct sw_chnl_cmd).
+ * input: sw_chnl_cmd  *CmdTable//table to be set
  *u32CmdTableIdx  //variable index in table to be set
  *u32CmdTableSz   //table size
  *switch_chan_cmd_idCmdID//command ID to set
@@ -1227,11 +1227,11 @@ bool rtl8192_SetRFPowerState(struct net_device *dev,
  * return:true if finished, false otherwise
  * notice:
  
**/
-static u8 rtl8192_phy_SetSwChnlCmdArray(struct SwChnlCmd *CmdTable, u32 
CmdTableIdx,
+static u8 rtl8192_phy_SetSwChnlCmdArray(struct sw_chnl_cmd *CmdTable, u32 
CmdTableIdx,
u32 CmdTableSz, enum switch_chan_cmd_id 
CmdID,
u32 Para1, u32 Para2, u32 msDelay)
 {
-   struct SwChnlCmd *pCmd;
+   struct sw_chnl_cmd *pCmd;
 
if (CmdTable == NULL) {
RT_TRACE(COMP_ERR, "%s(): CmdTable cannot be NULL\n", __func__);
@@ -1268,13 +1268,13 @@ static u8 rtl8192_phy_SwChnlStepByStep(struct 
net_device *dev, u8 channel,
   u8 *stage, u8 *step, u32 *delay)
 {
struct r8192_priv *priv = ieee80211_priv(dev);
-   struct SwChnlCmd   PreCommonCmd[MAX_PRECMD_CNT];
+   struct sw_chnl_cmd   PreCommonCmd[MAX_PRECMD_CNT];
u32PreCommonCmdCnt;
-   struct SwChnlCmd   PostCommonCmd[MAX_POSTCMD_CNT];
+   struct sw_chnl_cmd   PostCommonCmd[MAX_POSTCMD_CNT];
u32PostCommonCmdCnt;
-   struct SwChnlCmd   RfDependCmd[MAX_RFDEPENDCMD_CNT];
+   struct sw_chnl_cmd   RfDependCmd[MAX_RFDEPENDCMD_CNT];
u32RfDependCmdCnt;
-   struct SwChnlCmd  *CurrentCmd = NULL;
+   struct sw_chnl_cmd  *CurrentCmd = NULL;
u8 eRFPath;
 
RT_TRACE(COMP_CH, "%s() stage: %d, step: %d, channel: %d\n",
diff --git a/drivers/staging/rtl8192u/r819xU_phy.h 
b/drivers/staging/rtl8192u/r819xU_phy.h
index 75aa56ddd22f..509b18415127 100644
--- a/drivers/staging/rtl8192u/r819xU_phy.h
+++ b/drivers/staging/rtl8192u/r819xU_phy.h
@@ -18,7 +18,7 @@ enum switch_chan_cmd_id {
 
 /* ---Define structure-- */
 /* 1. Switch channel related */
-struct SwChnlCmd {
+struct sw_chnl_cmd {
enum switch_chan_cmd_id CmdID;
u32 Para1;
u32 Para2;
-- 
2.18.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 07/16] staging:rtl8192u: Remove proxy struct rtl819XPHY_REG_1T2RArray - Style

2018-07-26 Thread John Whitmore
Remove the struct rtl819XPHY_REG_1T2RArray which is simply a proxy for
the struct Rtl8192UsbPHY_REG_1T2RArray. There appears to be no purpose
served by this implementation, other then to obscure the
Rtl8192UsbPHY_REG_1T2RArray structure.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/r819xU_phy.c | 10 --
 drivers/staging/rtl8192u/r819xU_phy.h |  1 -
 2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/rtl8192u/r819xU_phy.c 
b/drivers/staging/rtl8192u/r819xU_phy.c
index cc35ca7b9140..8d44bbe90221 100644
--- a/drivers/staging/rtl8192u/r819xU_phy.c
+++ b/drivers/staging/rtl8192u/r819xU_phy.c
@@ -28,8 +28,6 @@ static u32 RF_CHANNEL_TABLE_ZEBRA[] = {
0x0f72, /* 2484*/
 };
 
-
-#define rtl819XPHY_REG_1T2RArray Rtl8192UsbPHY_REG_1T2RArray
 #define rtl819XMACPHY_Array Rtl8192UsbMACPHY_Array
 #define rtl819XRadioA_Array  Rtl8192UsbRadioA_Array
 #define rtl819XRadioB_Array Rtl8192UsbRadioB_Array
@@ -534,13 +532,13 @@ void rtl8192_phyConfigBB(struct net_device *dev, u8 
ConfigType)
 #endif
if (ConfigType == BaseBand_Config_PHY_REG) {
for (i = 0; i < PHY_REG_1T2RArrayLength; i += 2) {
-   rtl8192_setBBreg(dev, rtl819XPHY_REG_1T2RArray[i],
+   rtl8192_setBBreg(dev, Rtl8192UsbPHY_REG_1T2RArray[i],
 bMaskDWord,
-rtl819XPHY_REG_1T2RArray[i+1]);
+Rtl8192UsbPHY_REG_1T2RArray[i+1]);
RT_TRACE(COMP_DBG,
 "i: %x, Rtl819xUsbPHY_REGArray[0]=%x 
Rtl819xUsbPHY_REGArray[1]=%x\n",
-i, rtl819XPHY_REG_1T2RArray[i],
-rtl819XPHY_REG_1T2RArray[i+1]);
+i, Rtl8192UsbPHY_REG_1T2RArray[i],
+Rtl8192UsbPHY_REG_1T2RArray[i+1]);
}
} else if (ConfigType == BaseBand_Config_AGC_TAB) {
for (i = 0; i < AGCTAB_ArrayLength; i += 2) {
diff --git a/drivers/staging/rtl8192u/r819xU_phy.h 
b/drivers/staging/rtl8192u/r819xU_phy.h
index 3c069b89bcdb..842837bd6631 100644
--- a/drivers/staging/rtl8192u/r819xU_phy.h
+++ b/drivers/staging/rtl8192u/r819xU_phy.h
@@ -25,7 +25,6 @@ struct sw_chnl_cmd {
u32 ms_delay;
 } __packed;
 
-extern u32 rtl819XPHY_REG_1T2RArray[];
 extern u32 rtl819XAGCTAB_Array[];
 extern u32 rtl819XRadioA_Array[];
 extern u32 rtl819XRadioB_Array[];
-- 
2.18.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 04/16] staging:rtl8192u: Rename Para2 to para_2 - style

2018-07-26 Thread John Whitmore
Rename member variable Para2 to para_2. This change clears the checkpatch
issue with CamelCase naming. The change is purely a coding style change
and should have no impact on runtime code execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/r819xU_phy.c | 10 +-
 drivers/staging/rtl8192u/r819xU_phy.h |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/rtl8192u/r819xU_phy.c 
b/drivers/staging/rtl8192u/r819xU_phy.c
index c2a73ec90f70..904cc8c1a83b 100644
--- a/drivers/staging/rtl8192u/r819xU_phy.c
+++ b/drivers/staging/rtl8192u/r819xU_phy.c
@@ -1246,7 +1246,7 @@ static u8 rtl8192_phy_SetSwChnlCmdArray(struct 
sw_chnl_cmd *CmdTable, u32 CmdTab
pCmd = CmdTable + CmdTableIdx;
pCmd->cmd_id = CmdID;
pCmd->para_1 = Para1;
-   pCmd->Para2 = Para2;
+   pCmd->para_2 = Para2;
pCmd->msDelay = msDelay;
 
return true;
@@ -1381,15 +1381,15 @@ static u8 rtl8192_phy_SwChnlStepByStep(struct 
net_device *dev, u8 channel,
break;
case CMD_ID_WRITE_PORT_ULONG:
write_nic_dword(dev, CurrentCmd->para_1,
-   CurrentCmd->Para2);
+   CurrentCmd->para_2);
break;
case CMD_ID_WRITE_PORT_USHORT:
write_nic_word(dev, CurrentCmd->para_1,
-  (u16)CurrentCmd->Para2);
+  (u16)CurrentCmd->para_2);
break;
case CMD_ID_WRITE_PORT_UCHAR:
write_nic_byte(dev, CurrentCmd->para_1,
-  (u8)CurrentCmd->Para2);
+  (u8)CurrentCmd->para_2);
break;
case CMD_ID_RF_WRITE_REG:
for (eRFPath = 0; eRFPath < RF90_PATH_MAX; eRFPath++) {
@@ -1397,7 +1397,7 @@ static u8 rtl8192_phy_SwChnlStepByStep(struct net_device 
*dev, u8 channel,
 (enum 
RF90_RADIO_PATH_E)eRFPath,
 CurrentCmd->para_1,
 bZebra1_ChannelNum,
-CurrentCmd->Para2);
+CurrentCmd->para_2);
}
break;
default:
diff --git a/drivers/staging/rtl8192u/r819xU_phy.h 
b/drivers/staging/rtl8192u/r819xU_phy.h
index 77ae606c77ce..0d4c083ea718 100644
--- a/drivers/staging/rtl8192u/r819xU_phy.h
+++ b/drivers/staging/rtl8192u/r819xU_phy.h
@@ -21,7 +21,7 @@ enum switch_chan_cmd_id {
 struct sw_chnl_cmd {
enum switch_chan_cmd_id cmd_id;
u32 para_1;
-   u32 Para2;
+   u32 para_2;
u32 msDelay;
 } __packed;
 
-- 
2.18.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 03/16] staging:rtl8192u: Rename Para1 > para_1 - Style

2018-07-26 Thread John Whitmore
Rename the member variable Para1 to para_1. This change clears the
checkpatch issue with CamelCase naming. The change is purely a coding
style change and should have no impact on runtime code execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/r819xU_phy.c | 10 +-
 drivers/staging/rtl8192u/r819xU_phy.h |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/rtl8192u/r819xU_phy.c 
b/drivers/staging/rtl8192u/r819xU_phy.c
index 17cc47e20145..c2a73ec90f70 100644
--- a/drivers/staging/rtl8192u/r819xU_phy.c
+++ b/drivers/staging/rtl8192u/r819xU_phy.c
@@ -1245,7 +1245,7 @@ static u8 rtl8192_phy_SetSwChnlCmdArray(struct 
sw_chnl_cmd *CmdTable, u32 CmdTab
 
pCmd = CmdTable + CmdTableIdx;
pCmd->cmd_id = CmdID;
-   pCmd->Para1 = Para1;
+   pCmd->para_1 = Para1;
pCmd->Para2 = Para2;
pCmd->msDelay = msDelay;
 
@@ -1380,22 +1380,22 @@ static u8 rtl8192_phy_SwChnlStepByStep(struct 
net_device *dev, u8 channel,
rtl8192_SetTxPowerLevel(dev, channel);
break;
case CMD_ID_WRITE_PORT_ULONG:
-   write_nic_dword(dev, CurrentCmd->Para1,
+   write_nic_dword(dev, CurrentCmd->para_1,
CurrentCmd->Para2);
break;
case CMD_ID_WRITE_PORT_USHORT:
-   write_nic_word(dev, CurrentCmd->Para1,
+   write_nic_word(dev, CurrentCmd->para_1,
   (u16)CurrentCmd->Para2);
break;
case CMD_ID_WRITE_PORT_UCHAR:
-   write_nic_byte(dev, CurrentCmd->Para1,
+   write_nic_byte(dev, CurrentCmd->para_1,
   (u8)CurrentCmd->Para2);
break;
case CMD_ID_RF_WRITE_REG:
for (eRFPath = 0; eRFPath < RF90_PATH_MAX; eRFPath++) {
rtl8192_phy_SetRFReg(dev,
 (enum 
RF90_RADIO_PATH_E)eRFPath,
-CurrentCmd->Para1,
+CurrentCmd->para_1,
 bZebra1_ChannelNum,
 CurrentCmd->Para2);
}
diff --git a/drivers/staging/rtl8192u/r819xU_phy.h 
b/drivers/staging/rtl8192u/r819xU_phy.h
index 75970febaac5..77ae606c77ce 100644
--- a/drivers/staging/rtl8192u/r819xU_phy.h
+++ b/drivers/staging/rtl8192u/r819xU_phy.h
@@ -20,7 +20,7 @@ enum switch_chan_cmd_id {
 /* 1. Switch channel related */
 struct sw_chnl_cmd {
enum switch_chan_cmd_id cmd_id;
-   u32 Para1;
+   u32 para_1;
u32 Para2;
u32 msDelay;
 } __packed;
-- 
2.18.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 00/16] staging:rtl8192u: Proxy Structures?

2018-07-26 Thread John Whitmore
This series of patches contains coding style changes.

There is one type of change, proxy structures, which whilst not flagged
by checkpatch, as an issue, I have changed. I can't see the purpose of
defining a structure, in this case arrays, and then using a #define to
name the structure something else.

This may well be a pattern which I'm not familiar with, in which case
the patches can be rejected, and I'll have learned something, but I thought
I'd better explicitly mention it, as I'm assuming that there is not actual
point to the practice.

Apart from that all the rest are simple coding style changes.

John Whitmore (16):
  staging:rtl8192u: Rename SwChnlCmd - Style
  staging:rtl8192u: Rename CmdID - Style
  staging:rtl8192u: Rename Para1 > para_1 - Style
  staging:rtl8192u: Rename Para2 to para_2 - style
  staging:rtl8192u: Rename msDelay to ms_delay - Style
  staging:rtl8192u: Remove proxy struct rtl819XMACPHY_Array_PG - Style
  staging:rtl8192u: Remove proxy struct rtl819XPHY_REG_1T2RArray - Style
  staging:rtl8192u: Remove proxy array rtl819XAGCTAB_Array - Style
  staging:rtl8192u: Remove proxy rtl819XRadioA_Array - Style
  staging:rtl8192u: Remove proxy rtl819XRadioB_Array - Style
  staging:rtl8192u: Remove proxy rtl819XRadioC_Array - Style
  staging:rtl8192u: Remove proxy rtl819XRadioD_Array - Style
  staging:rtl8192u: Rename HW90_BLOCK_E - Style
  staging:rtl8192u: Rename RF90_RADIO_PATH_E - Style
  staging:rtl8192u: Remove repeated definitions - Style
  staging:rtl8192u: Rename eRFPath - Style

 drivers/staging/rtl8192u/r8190_rtl8256.c |  42 ++---
 drivers/staging/rtl8192u/r8192U_core.c   |   4 +-
 drivers/staging/rtl8192u/r819xU_phy.c| 230 +++
 drivers/staging/rtl8192u/r819xU_phy.h|  42 ++---
 4 files changed, 147 insertions(+), 171 deletions(-)

-- 
2.18.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v2 3/3] Staging: octeon-usb: Breaks down cvmx_usb_poll_channel().

2018-07-26 Thread Joe Perches
On Thu, 2018-07-26 at 18:41 +0300, Georgios Tsotsos wrote:
> In order to make this function more clear a new function created that controls
> channels halt on no DMA mode.
[]
> diff --git a/drivers/staging/octeon-usb/octeon-hcd.c 
> b/drivers/staging/octeon-usb/octeon-hcd.c
[]
> @@ -2585,6 +2585,52 @@ static void cvmx_usb_transfer_isoc(struct octeon_hcd 
> *usb,
>   }
>  }
>  
> +/**
> + * Handles channels halt in non DMA mode
> + * @usbc_hcchar: Host Channel-n Characteristics Register (HCCHAR)
> + * @usbc_hcint:  Host Channel-n Interrupt Register
> + * @usb: USB device
> + * @channel: Channel to poll
> + *
> + * In non DMA mode the channels don't halt themselves. We need
> + * to manually disable channels that are left running
> + *
> + * Returns: -1 on halt
> + */
> +static int cvmx_usb_dma_halt(union cvmx_usbcx_hccharx usbc_hcchar,
> +  union cvmx_usbcx_hcintx usbc_hcint,

It looks very suspect to pass unions on the stack.

Are you sure these aren't used after this function
is called?

Likely these should be pointers to unions.

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 3/3] Staging: octeon-usb: Breaks down cvmx_usb_poll_channel().

2018-07-26 Thread Georgios Tsotsos
In order to make this function more clear a new function created that controls
channels halt on no DMA mode.

Signed-off-by: Georgios Tsotsos 
---
 drivers/staging/octeon-usb/octeon-hcd.c | 83 +
 1 file changed, 54 insertions(+), 29 deletions(-)

diff --git a/drivers/staging/octeon-usb/octeon-hcd.c 
b/drivers/staging/octeon-usb/octeon-hcd.c
index c8e0ebf1434f..f9f429d385ce 100644
--- a/drivers/staging/octeon-usb/octeon-hcd.c
+++ b/drivers/staging/octeon-usb/octeon-hcd.c
@@ -2585,6 +2585,52 @@ static void cvmx_usb_transfer_isoc(struct octeon_hcd 
*usb,
}
 }
 
+/**
+ * Handles channels halt in non DMA mode
+ * @usbc_hcchar: Host Channel-n Characteristics Register (HCCHAR)
+ * @usbc_hcint:  Host Channel-n Interrupt Register
+ * @usb: USB device
+ * @channel: Channel to poll
+ *
+ * In non DMA mode the channels don't halt themselves. We need
+ * to manually disable channels that are left running
+ *
+ * Returns: -1 on halt
+ */
+static int cvmx_usb_dma_halt(union cvmx_usbcx_hccharx usbc_hcchar,
+union cvmx_usbcx_hcintx usbc_hcint,
+struct octeon_hcd *usb,
+int channel)
+{
+   struct usb_hcd *hcd = octeon_to_hcd(usb);
+   struct device *dev = hcd->self.controller;
+
+   if (usbc_hcchar.s.chena) {
+   union cvmx_usbcx_hcintmskx hcintmsk;
+   /* Disable all interrupts except CHHLTD */
+   hcintmsk.u32 = 0;
+   hcintmsk.s.chhltdmsk = 1;
+   cvmx_usb_write_csr32(usb,
+CVMX_USBCX_HCINTMSKX(channel, usb->index),
+hcintmsk.u32);
+   usbc_hcchar.s.chdis = 1;
+   cvmx_usb_write_csr32(usb,
+CVMX_USBCX_HCCHARX(channel, usb->index),
+usbc_hcchar.u32);
+   return -1;
+   } else if (usbc_hcint.s.xfercompl) {
+   /*
+* Successful IN/OUT with transfer complete.
+* Channel halt isn't needed.
+*/
+   } else {
+   dev_err(dev, "USB%d: Channel %d interrupt without halt\n",
+   usb->index, channel);
+   return -1;
+   }
+
+   return 0;
+}
 /**
  * Poll a channel for status
  *
@@ -2595,8 +2641,6 @@ static void cvmx_usb_transfer_isoc(struct octeon_hcd *usb,
  */
 static int cvmx_usb_poll_channel(struct octeon_hcd *usb, int channel)
 {
-   struct usb_hcd *hcd = octeon_to_hcd(usb);
-   struct device *dev = hcd->self.controller;
union cvmx_usbcx_hcintx usbc_hcint;
union cvmx_usbcx_hctsizx usbc_hctsiz;
union cvmx_usbcx_hccharx usbc_hcchar;
@@ -2627,35 +2671,16 @@ static int cvmx_usb_poll_channel(struct octeon_hcd 
*usb, int channel)
 usbc_hcchar.u32);
return 0;
}
-
-   /*
-* In non DMA mode the channels don't halt themselves. We need
-* to manually disable channels that are left running
-*/
+   /* In case of non DMA mode handle halt */
if (!usbc_hcint.s.chhltd) {
-   if (usbc_hcchar.s.chena) {
-   union cvmx_usbcx_hcintmskx hcintmsk;
-   /* Disable all interrupts except CHHLTD */
-   hcintmsk.u32 = 0;
-   hcintmsk.s.chhltdmsk = 1;
-   cvmx_usb_write_csr32(usb,
-
CVMX_USBCX_HCINTMSKX(channel, usb->index),
-hcintmsk.u32);
-   usbc_hcchar.s.chdis = 1;
-   cvmx_usb_write_csr32(usb,
-
CVMX_USBCX_HCCHARX(channel, usb->index),
-usbc_hcchar.u32);
-   return 0;
-   } else if (usbc_hcint.s.xfercompl) {
-   /*
-* Successful IN/OUT with transfer complete.
-* Channel halt isn't needed.
-*/
-   } else {
-   dev_err(dev, "USB%d: Channel %d interrupt 
without halt\n",
-   usb->index, channel);
+   int dma_halt_status = 0;
+
+   dma_halt_status = cvmx_usb_dma_halt(usbc_hcchar,
+   usbc_hcint,
+   usb, channel);
+
+   if (dma_halt_status < 0)
return 0;
-   }
   

[PATCH v2 1/3] Staging: octeon-usb: Adding SPDX license identifier

2018-07-26 Thread Georgios Tsotsos
Adding appropriate SPDX-License-Identifier (GPL-2) that were missing
from code, header and make files.

Signed-off-by: Georgios Tsotsos 
---
 drivers/staging/octeon-usb/Makefile | 1 +
 drivers/staging/octeon-usb/octeon-hcd.c | 1 +
 drivers/staging/octeon-usb/octeon-hcd.h | 1 +
 3 files changed, 3 insertions(+)

diff --git a/drivers/staging/octeon-usb/Makefile 
b/drivers/staging/octeon-usb/Makefile
index 5588be395f2a..9873a0130ad5 100644
--- a/drivers/staging/octeon-usb/Makefile
+++ b/drivers/staging/octeon-usb/Makefile
@@ -1 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0
 obj-${CONFIG_OCTEON_USB} := octeon-hcd.o
diff --git a/drivers/staging/octeon-usb/octeon-hcd.c 
b/drivers/staging/octeon-usb/octeon-hcd.c
index cded30f145aa..cff5e790b196 100644
--- a/drivers/staging/octeon-usb/octeon-hcd.c
+++ b/drivers/staging/octeon-usb/octeon-hcd.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * This file is subject to the terms and conditions of the GNU General Public
  * License.  See the file "COPYING" in the main directory of this archive
diff --git a/drivers/staging/octeon-usb/octeon-hcd.h 
b/drivers/staging/octeon-usb/octeon-hcd.h
index 3353aefe662e..769c36cf6614 100644
--- a/drivers/staging/octeon-usb/octeon-hcd.h
+++ b/drivers/staging/octeon-usb/octeon-hcd.h
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: GPL-2.0 */
 /*
  * Octeon HCD hardware register definitions.
  *
-- 
2.16.4
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 2/3] Staging: octeon-usb: Change coding style of CVMX_WAIT_FOR_FIELD32 marco.

2018-07-26 Thread Georgios Tsotsos
Fixing coding style for CVMX_WAIT_FOR_FIELD32 was confusing. Also
encapsulates into parentheses timeout_usec.

Signed-off-by: Georgios Tsotsos 
---
 drivers/staging/octeon-usb/octeon-hcd.c | 44 +
 1 file changed, 23 insertions(+), 21 deletions(-)

diff --git a/drivers/staging/octeon-usb/octeon-hcd.c 
b/drivers/staging/octeon-usb/octeon-hcd.c
index cff5e790b196..c8e0ebf1434f 100644
--- a/drivers/staging/octeon-usb/octeon-hcd.c
+++ b/drivers/staging/octeon-usb/octeon-hcd.c
@@ -378,27 +378,29 @@ struct octeon_hcd {
 };
 
 /* This macro spins on a register waiting for it to reach a condition. */
-#define CVMX_WAIT_FOR_FIELD32(address, _union, cond, timeout_usec) \
-   ({int result;   \
-   do {\
-   u64 done = cvmx_get_cycle() + (u64)timeout_usec *   \
-  octeon_get_clock_rate() / 100;   \
-   union _union c; \
-   \
-   while (1) { \
-   c.u32 = cvmx_usb_read_csr32(usb, address);  \
-   \
-   if (cond) { \
-   result = 0; \
-   break;  \
-   } else if (cvmx_get_cycle() > done) {   \
-   result = -1;\
-   break;  \
-   } else  \
-   __delay(100);   \
-   }   \
-   } while (0);\
-   result; })
+#define CVMX_WAIT_FOR_FIELD32(address, _union, cond, timeout_usec) \
+({ \
+   int result; \
+   do {\
+   u64 done = cvmx_get_cycle() + (u64)(timeout_usec) * \
+  octeon_get_clock_rate() / 100;   \
+   union _union c; \
+   \
+   while (1) { \
+   c.u32 = cvmx_usb_read_csr32(usb, address);  \
+   \
+   if (cond) { \
+   result = 0; \
+   break;  \
+   } else if (cvmx_get_cycle() > done) {   \
+   result = -1;\
+   break;  \
+   } else  \
+   __delay(100);   \
+   }   \
+   } while (0);\
+   result; \
+})
 
 /*
  * This macro logically sets a single field in a CSR. It does the sequence
-- 
2.16.4
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 0/3] Staging: octeon-usb fixes for coding style, SPDX and readability.

2018-07-26 Thread Georgios Tsotsos
Hello, 
Ok, this have gone too far, i sent these series so many times wrong...
I am sorry its my first patch (and series) and i keep mix-up patch generation
an sending to my self. Last time not everybody was cc.

Here are three patches which trying to resolve TODO's list requirements 
number 45 about octeon-usb. 
There are SPDX licence additions on code, makefile and header files.
Checkpatch warnings are resolved,also a notice about CVMX_WAIT_FOR_FIELD32 
macro.
After Joe Perches's (j...@perches.com) suggestion i broke down the 
cvmx_usb_poll_channel function in order to improve readability and keeping it
under 80 columns.

Georgios Tsotsos (3):
  Staging: octeon-usb: Adding SPDX license identifier
  Staging: octeon-usb: Change coding style of CVMX_WAIT_FOR_FIELD32 marco.
  Staging: octeon-usb: Breaks down cvmx_usb_poll_channel().

 drivers/staging/octeon-usb/Makefile |   1 +
 drivers/staging/octeon-usb/octeon-hcd.c | 128 +++-
 drivers/staging/octeon-usb/octeon-hcd.h |   1 +
 3 files changed, 80 insertions(+), 50 deletions(-)

-- 
2.16.4
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v7 4/4] kexec_file: Load kernel at top of system RAM if required

2018-07-26 Thread Baoquan He
On 07/26/18 at 04:01pm, Michal Hocko wrote:
> On Thu 26-07-18 21:37:05, Baoquan He wrote:
> > On 07/26/18 at 03:14pm, Michal Hocko wrote:
> > > On Thu 26-07-18 15:12:42, Michal Hocko wrote:
> > > > On Thu 26-07-18 21:09:04, Baoquan He wrote:
> > > > > On 07/26/18 at 02:59pm, Michal Hocko wrote:
> > > > > > On Wed 25-07-18 14:48:13, Baoquan He wrote:
> > > > > > > On 07/23/18 at 04:34pm, Michal Hocko wrote:
> > > > > > > > On Thu 19-07-18 23:17:53, Baoquan He wrote:
> > > > > > > > > Kexec has been a formal feature in our distro, and customers 
> > > > > > > > > owning
> > > > > > > > > those kind of very large machine can make use of this feature 
> > > > > > > > > to speed
> > > > > > > > > up the reboot process. On uefi machine, the kexec_file 
> > > > > > > > > loading will
> > > > > > > > > search place to put kernel under 4G from top to down. As we 
> > > > > > > > > know, the
> > > > > > > > > 1st 4G space is DMA32 ZONE, dma, pci mmcfg, bios etc all try 
> > > > > > > > > to consume
> > > > > > > > > it. It may have possibility to not be able to find a usable 
> > > > > > > > > space for
> > > > > > > > > kernel/initrd. From the top down of the whole memory space, 
> > > > > > > > > we don't
> > > > > > > > > have this worry. 
> > > > > > > > 
> > > > > > > > I do not have the full context here but let me note that you 
> > > > > > > > should be
> > > > > > > > careful when doing top-down reservation because you can easily 
> > > > > > > > get into
> > > > > > > > hotplugable memory and break the hotremove usecase. We even 
> > > > > > > > warn when
> > > > > > > > this is done. See memblock_find_in_range_node
> > > > > > > 
> > > > > > > Kexec read kernel/initrd file into buffer, just search usable 
> > > > > > > positions
> > > > > > > for them to do the later copying. You can see below struct 
> > > > > > > kexec_segment, 
> > > > > > > for the old kexec_load, kernel/initrd are read into user space 
> > > > > > > buffer,
> > > > > > > the @buf stores the user space buffer address, @mem stores the 
> > > > > > > position
> > > > > > > where kernel/initrd will be put. In kernel, it calls
> > > > > > > kimage_load_normal_segment() to copy user space buffer to 
> > > > > > > intermediate
> > > > > > > pages which are allocated with flag GFP_KERNEL. These 
> > > > > > > intermediate pages
> > > > > > > are recorded as entries, later when user execute "kexec -e" to 
> > > > > > > trigger
> > > > > > > kexec jumping, it will do the final copying from the intermediate 
> > > > > > > pages
> > > > > > > to the real destination pages which @mem pointed. Because we 
> > > > > > > can't touch
> > > > > > > the existed data in 1st kernel when do kexec kernel loading. With 
> > > > > > > my
> > > > > > > understanding, GFP_KERNEL will make those intermediate pages be
> > > > > > > allocated inside immovable area, it won't impact hotplugging. But 
> > > > > > > the
> > > > > > > @mem we searched in the whole system RAM might be lost along with
> > > > > > > hotplug. Hence we need do kexec kernel again when hotplug event is
> > > > > > > detected.
> > > > > > 
> > > > > > I am not sure I am following. If @mem is placed at movable node 
> > > > > > then the
> > > > > > memory hotremove simply won't work, because we are seeing reserved 
> > > > > > pages
> > > > > > and do not know what to do about them. They are not migrateable.
> > > > > > Allocating intermediate pages from other nodes doesn't really help.
> > > > > 
> > > > > OK, I forgot the 2nd kernel which kexec jump into. It won't impact 
> > > > > hotremove
> > > > > in 1st kernel, it does impact the kernel which kexec jump into if 
> > > > > kernel
> > > > > is at top of system RAM and the top RAM is in movable node.
> > > > 
> > > > It will affect the 1st kernel (which does the memblock allocation
> > > > top-down) as well. For reasons mentioned above.
> > > 
> > > And btw. in the ideal world, we would restrict the memblock allocation
> > > top-down from the non-movable nodes. But I do not think we have that
> > > information ready at the time when the reservation is done.
> > 
> > Oh, you could mix kexec loading up with kdump kernel loading. For kdump
> > kernel, we need reserve memory region during bootup with memblock
> > allocator. For kexec loading, we just operate after system up, and do
> > not need to reserve any memmory region. About memory used to load them,
> > it's quite different way.
> 
> I didn't know about that. I thought both use the same underlying
> reservation mechanism. My bad and sorry for the noise.

Not at all. It's truly confusing. I often need take time to recall those
details. 
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [BUG] staging: lustre: Possible null function pointer in ctx_refresh_timeout()

2018-07-26 Thread Greg KH
On Thu, Jul 26, 2018 at 10:02:22PM +0800, Jia-Ju Bai wrote:
> In Linux-4.16, drivers/staging/lustre/lustre/ptlrp/sec.c,

Please look at the 4.18-rc6 release for this file.

In short, nothing to worry about anymore :)

thanks,

greg k-h
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[GIT PULL] Staging driver fixes for 4.18-rc7

2018-07-26 Thread Greg KH
The following changes since commit 9d3cce1e8b8561fed5f383d22a4d6949db4eadbe:

  Linux 4.18-rc5 (2018-07-15 12:49:31 -0700)

are available in the Git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git 
tags/staging-4.18-rc7

for you to fetch changes up to b96fba8d5855c3617adbfb43ca4723a808cac954:

  staging: speakup: fix wraparound in uaccess length check (2018-07-16 10:04:11 
+0200)


staging driver fixes for 4.18-rc7

Here are 3 small staging driver fixes for 4.18-rc7.  One is a revert of
an earlier patch that turned out to be incorrect, one is a fix for the
speakup drivers, and the last a fix for the ks7010 driver to resolve a
regression.

All of these have been in linux-next for a while with no reported
issues.

Signed-off-by: Greg Kroah-Hartman 


Hans de Goede (1):
  Revert "staging:r8188eu: Use lib80211 to support TKIP"

Samuel Thibault (1):
  staging: speakup: fix wraparound in uaccess length check

Sergio Paracuellos (1):
  staging: ks7010: call 'hostif_mib_set_request_int' instead of 
'hostif_mib_set_request_bool'

 drivers/staging/ks7010/ks_hostif.c|  12 +-
 drivers/staging/rtl8188eu/Kconfig |   1 -
 drivers/staging/rtl8188eu/core/rtw_recv.c | 161 ++
 drivers/staging/rtl8188eu/core/rtw_security.c |  92 +++
 drivers/staging/speakup/speakup_soft.c|   6 +-
 5 files changed, 171 insertions(+), 101 deletions(-)
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [BUG] staging: lustre: Possible null function pointer in ctx_refresh_timeout()

2018-07-26 Thread Jia-Ju Bai




On 2018/7/26 22:12, Greg KH wrote:

On Thu, Jul 26, 2018 at 10:02:22PM +0800, Jia-Ju Bai wrote:

In Linux-4.16, drivers/staging/lustre/lustre/ptlrp/sec.c,

Please look at the 4.18-rc6 release for this file.

In short, nothing to worry about anymore :)


Looks good now :)


Best wishes,
Jia-Ju Bai
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[BUG] staging: lustre: Possible null function pointer in ctx_refresh_timeout()

2018-07-26 Thread Jia-Ju Bai

In Linux-4.16, drivers/staging/lustre/lustre/ptlrp/sec.c,

557. int ctx_refresh_timeout(...) {
    ...
573. req->rq_cli_ctx->cc_ops->force_die(req->rq_cli_ctx, 0);
    ..
575. }

For x86 kernel configuration, there is no assignment of the function 
pointer ".force_die" in the kernel code.
So calling the function pointer in line 573 may cause a null pointer 
dereference.



Best wishes,
Jia-Ju Bai
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v7 4/4] kexec_file: Load kernel at top of system RAM if required

2018-07-26 Thread Michal Hocko
On Thu 26-07-18 21:37:05, Baoquan He wrote:
> On 07/26/18 at 03:14pm, Michal Hocko wrote:
> > On Thu 26-07-18 15:12:42, Michal Hocko wrote:
> > > On Thu 26-07-18 21:09:04, Baoquan He wrote:
> > > > On 07/26/18 at 02:59pm, Michal Hocko wrote:
> > > > > On Wed 25-07-18 14:48:13, Baoquan He wrote:
> > > > > > On 07/23/18 at 04:34pm, Michal Hocko wrote:
> > > > > > > On Thu 19-07-18 23:17:53, Baoquan He wrote:
> > > > > > > > Kexec has been a formal feature in our distro, and customers 
> > > > > > > > owning
> > > > > > > > those kind of very large machine can make use of this feature 
> > > > > > > > to speed
> > > > > > > > up the reboot process. On uefi machine, the kexec_file loading 
> > > > > > > > will
> > > > > > > > search place to put kernel under 4G from top to down. As we 
> > > > > > > > know, the
> > > > > > > > 1st 4G space is DMA32 ZONE, dma, pci mmcfg, bios etc all try to 
> > > > > > > > consume
> > > > > > > > it. It may have possibility to not be able to find a usable 
> > > > > > > > space for
> > > > > > > > kernel/initrd. From the top down of the whole memory space, we 
> > > > > > > > don't
> > > > > > > > have this worry. 
> > > > > > > 
> > > > > > > I do not have the full context here but let me note that you 
> > > > > > > should be
> > > > > > > careful when doing top-down reservation because you can easily 
> > > > > > > get into
> > > > > > > hotplugable memory and break the hotremove usecase. We even warn 
> > > > > > > when
> > > > > > > this is done. See memblock_find_in_range_node
> > > > > > 
> > > > > > Kexec read kernel/initrd file into buffer, just search usable 
> > > > > > positions
> > > > > > for them to do the later copying. You can see below struct 
> > > > > > kexec_segment, 
> > > > > > for the old kexec_load, kernel/initrd are read into user space 
> > > > > > buffer,
> > > > > > the @buf stores the user space buffer address, @mem stores the 
> > > > > > position
> > > > > > where kernel/initrd will be put. In kernel, it calls
> > > > > > kimage_load_normal_segment() to copy user space buffer to 
> > > > > > intermediate
> > > > > > pages which are allocated with flag GFP_KERNEL. These intermediate 
> > > > > > pages
> > > > > > are recorded as entries, later when user execute "kexec -e" to 
> > > > > > trigger
> > > > > > kexec jumping, it will do the final copying from the intermediate 
> > > > > > pages
> > > > > > to the real destination pages which @mem pointed. Because we can't 
> > > > > > touch
> > > > > > the existed data in 1st kernel when do kexec kernel loading. With my
> > > > > > understanding, GFP_KERNEL will make those intermediate pages be
> > > > > > allocated inside immovable area, it won't impact hotplugging. But 
> > > > > > the
> > > > > > @mem we searched in the whole system RAM might be lost along with
> > > > > > hotplug. Hence we need do kexec kernel again when hotplug event is
> > > > > > detected.
> > > > > 
> > > > > I am not sure I am following. If @mem is placed at movable node then 
> > > > > the
> > > > > memory hotremove simply won't work, because we are seeing reserved 
> > > > > pages
> > > > > and do not know what to do about them. They are not migrateable.
> > > > > Allocating intermediate pages from other nodes doesn't really help.
> > > > 
> > > > OK, I forgot the 2nd kernel which kexec jump into. It won't impact 
> > > > hotremove
> > > > in 1st kernel, it does impact the kernel which kexec jump into if kernel
> > > > is at top of system RAM and the top RAM is in movable node.
> > > 
> > > It will affect the 1st kernel (which does the memblock allocation
> > > top-down) as well. For reasons mentioned above.
> > 
> > And btw. in the ideal world, we would restrict the memblock allocation
> > top-down from the non-movable nodes. But I do not think we have that
> > information ready at the time when the reservation is done.
> 
> Oh, you could mix kexec loading up with kdump kernel loading. For kdump
> kernel, we need reserve memory region during bootup with memblock
> allocator. For kexec loading, we just operate after system up, and do
> not need to reserve any memmory region. About memory used to load them,
> it's quite different way.

I didn't know about that. I thought both use the same underlying
reservation mechanism. My bad and sorry for the noise.
-- 
Michal Hocko
SUSE Labs
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v7 4/4] kexec_file: Load kernel at top of system RAM if required

2018-07-26 Thread Baoquan He
On 07/26/18 at 03:14pm, Michal Hocko wrote:
> On Thu 26-07-18 15:12:42, Michal Hocko wrote:
> > On Thu 26-07-18 21:09:04, Baoquan He wrote:
> > > On 07/26/18 at 02:59pm, Michal Hocko wrote:
> > > > On Wed 25-07-18 14:48:13, Baoquan He wrote:
> > > > > On 07/23/18 at 04:34pm, Michal Hocko wrote:
> > > > > > On Thu 19-07-18 23:17:53, Baoquan He wrote:
> > > > > > > Kexec has been a formal feature in our distro, and customers 
> > > > > > > owning
> > > > > > > those kind of very large machine can make use of this feature to 
> > > > > > > speed
> > > > > > > up the reboot process. On uefi machine, the kexec_file loading 
> > > > > > > will
> > > > > > > search place to put kernel under 4G from top to down. As we know, 
> > > > > > > the
> > > > > > > 1st 4G space is DMA32 ZONE, dma, pci mmcfg, bios etc all try to 
> > > > > > > consume
> > > > > > > it. It may have possibility to not be able to find a usable space 
> > > > > > > for
> > > > > > > kernel/initrd. From the top down of the whole memory space, we 
> > > > > > > don't
> > > > > > > have this worry. 
> > > > > > 
> > > > > > I do not have the full context here but let me note that you should 
> > > > > > be
> > > > > > careful when doing top-down reservation because you can easily get 
> > > > > > into
> > > > > > hotplugable memory and break the hotremove usecase. We even warn 
> > > > > > when
> > > > > > this is done. See memblock_find_in_range_node
> > > > > 
> > > > > Kexec read kernel/initrd file into buffer, just search usable 
> > > > > positions
> > > > > for them to do the later copying. You can see below struct 
> > > > > kexec_segment, 
> > > > > for the old kexec_load, kernel/initrd are read into user space buffer,
> > > > > the @buf stores the user space buffer address, @mem stores the 
> > > > > position
> > > > > where kernel/initrd will be put. In kernel, it calls
> > > > > kimage_load_normal_segment() to copy user space buffer to intermediate
> > > > > pages which are allocated with flag GFP_KERNEL. These intermediate 
> > > > > pages
> > > > > are recorded as entries, later when user execute "kexec -e" to trigger
> > > > > kexec jumping, it will do the final copying from the intermediate 
> > > > > pages
> > > > > to the real destination pages which @mem pointed. Because we can't 
> > > > > touch
> > > > > the existed data in 1st kernel when do kexec kernel loading. With my
> > > > > understanding, GFP_KERNEL will make those intermediate pages be
> > > > > allocated inside immovable area, it won't impact hotplugging. But the
> > > > > @mem we searched in the whole system RAM might be lost along with
> > > > > hotplug. Hence we need do kexec kernel again when hotplug event is
> > > > > detected.
> > > > 
> > > > I am not sure I am following. If @mem is placed at movable node then the
> > > > memory hotremove simply won't work, because we are seeing reserved pages
> > > > and do not know what to do about them. They are not migrateable.
> > > > Allocating intermediate pages from other nodes doesn't really help.
> > > 
> > > OK, I forgot the 2nd kernel which kexec jump into. It won't impact 
> > > hotremove
> > > in 1st kernel, it does impact the kernel which kexec jump into if kernel
> > > is at top of system RAM and the top RAM is in movable node.
> > 
> > It will affect the 1st kernel (which does the memblock allocation
> > top-down) as well. For reasons mentioned above.
> 
> And btw. in the ideal world, we would restrict the memblock allocation
> top-down from the non-movable nodes. But I do not think we have that
> information ready at the time when the reservation is done.

Oh, you could mix kexec loading up with kdump kernel loading. For kdump
kernel, we need reserve memory region during bootup with memblock
allocator. For kexec loading, we just operate after system up, and do
not need to reserve any memmory region. About memory used to load them,
it's quite different way.

Thanks
Baoquan
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v7 4/4] kexec_file: Load kernel at top of system RAM if required

2018-07-26 Thread Michal Hocko
On Thu 26-07-18 15:12:42, Michal Hocko wrote:
> On Thu 26-07-18 21:09:04, Baoquan He wrote:
> > On 07/26/18 at 02:59pm, Michal Hocko wrote:
> > > On Wed 25-07-18 14:48:13, Baoquan He wrote:
> > > > On 07/23/18 at 04:34pm, Michal Hocko wrote:
> > > > > On Thu 19-07-18 23:17:53, Baoquan He wrote:
> > > > > > Kexec has been a formal feature in our distro, and customers owning
> > > > > > those kind of very large machine can make use of this feature to 
> > > > > > speed
> > > > > > up the reboot process. On uefi machine, the kexec_file loading will
> > > > > > search place to put kernel under 4G from top to down. As we know, 
> > > > > > the
> > > > > > 1st 4G space is DMA32 ZONE, dma, pci mmcfg, bios etc all try to 
> > > > > > consume
> > > > > > it. It may have possibility to not be able to find a usable space 
> > > > > > for
> > > > > > kernel/initrd. From the top down of the whole memory space, we don't
> > > > > > have this worry. 
> > > > > 
> > > > > I do not have the full context here but let me note that you should be
> > > > > careful when doing top-down reservation because you can easily get 
> > > > > into
> > > > > hotplugable memory and break the hotremove usecase. We even warn when
> > > > > this is done. See memblock_find_in_range_node
> > > > 
> > > > Kexec read kernel/initrd file into buffer, just search usable positions
> > > > for them to do the later copying. You can see below struct 
> > > > kexec_segment, 
> > > > for the old kexec_load, kernel/initrd are read into user space buffer,
> > > > the @buf stores the user space buffer address, @mem stores the position
> > > > where kernel/initrd will be put. In kernel, it calls
> > > > kimage_load_normal_segment() to copy user space buffer to intermediate
> > > > pages which are allocated with flag GFP_KERNEL. These intermediate pages
> > > > are recorded as entries, later when user execute "kexec -e" to trigger
> > > > kexec jumping, it will do the final copying from the intermediate pages
> > > > to the real destination pages which @mem pointed. Because we can't touch
> > > > the existed data in 1st kernel when do kexec kernel loading. With my
> > > > understanding, GFP_KERNEL will make those intermediate pages be
> > > > allocated inside immovable area, it won't impact hotplugging. But the
> > > > @mem we searched in the whole system RAM might be lost along with
> > > > hotplug. Hence we need do kexec kernel again when hotplug event is
> > > > detected.
> > > 
> > > I am not sure I am following. If @mem is placed at movable node then the
> > > memory hotremove simply won't work, because we are seeing reserved pages
> > > and do not know what to do about them. They are not migrateable.
> > > Allocating intermediate pages from other nodes doesn't really help.
> > 
> > OK, I forgot the 2nd kernel which kexec jump into. It won't impact hotremove
> > in 1st kernel, it does impact the kernel which kexec jump into if kernel
> > is at top of system RAM and the top RAM is in movable node.
> 
> It will affect the 1st kernel (which does the memblock allocation
> top-down) as well. For reasons mentioned above.

And btw. in the ideal world, we would restrict the memblock allocation
top-down from the non-movable nodes. But I do not think we have that
information ready at the time when the reservation is done.
-- 
Michal Hocko
SUSE Labs
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v7 4/4] kexec_file: Load kernel at top of system RAM if required

2018-07-26 Thread Michal Hocko
On Thu 26-07-18 21:09:04, Baoquan He wrote:
> On 07/26/18 at 02:59pm, Michal Hocko wrote:
> > On Wed 25-07-18 14:48:13, Baoquan He wrote:
> > > On 07/23/18 at 04:34pm, Michal Hocko wrote:
> > > > On Thu 19-07-18 23:17:53, Baoquan He wrote:
> > > > > Kexec has been a formal feature in our distro, and customers owning
> > > > > those kind of very large machine can make use of this feature to speed
> > > > > up the reboot process. On uefi machine, the kexec_file loading will
> > > > > search place to put kernel under 4G from top to down. As we know, the
> > > > > 1st 4G space is DMA32 ZONE, dma, pci mmcfg, bios etc all try to 
> > > > > consume
> > > > > it. It may have possibility to not be able to find a usable space for
> > > > > kernel/initrd. From the top down of the whole memory space, we don't
> > > > > have this worry. 
> > > > 
> > > > I do not have the full context here but let me note that you should be
> > > > careful when doing top-down reservation because you can easily get into
> > > > hotplugable memory and break the hotremove usecase. We even warn when
> > > > this is done. See memblock_find_in_range_node
> > > 
> > > Kexec read kernel/initrd file into buffer, just search usable positions
> > > for them to do the later copying. You can see below struct kexec_segment, 
> > > for the old kexec_load, kernel/initrd are read into user space buffer,
> > > the @buf stores the user space buffer address, @mem stores the position
> > > where kernel/initrd will be put. In kernel, it calls
> > > kimage_load_normal_segment() to copy user space buffer to intermediate
> > > pages which are allocated with flag GFP_KERNEL. These intermediate pages
> > > are recorded as entries, later when user execute "kexec -e" to trigger
> > > kexec jumping, it will do the final copying from the intermediate pages
> > > to the real destination pages which @mem pointed. Because we can't touch
> > > the existed data in 1st kernel when do kexec kernel loading. With my
> > > understanding, GFP_KERNEL will make those intermediate pages be
> > > allocated inside immovable area, it won't impact hotplugging. But the
> > > @mem we searched in the whole system RAM might be lost along with
> > > hotplug. Hence we need do kexec kernel again when hotplug event is
> > > detected.
> > 
> > I am not sure I am following. If @mem is placed at movable node then the
> > memory hotremove simply won't work, because we are seeing reserved pages
> > and do not know what to do about them. They are not migrateable.
> > Allocating intermediate pages from other nodes doesn't really help.
> 
> OK, I forgot the 2nd kernel which kexec jump into. It won't impact hotremove
> in 1st kernel, it does impact the kernel which kexec jump into if kernel
> is at top of system RAM and the top RAM is in movable node.

It will affect the 1st kernel (which does the memblock allocation
top-down) as well. For reasons mentioned above.
-- 
Michal Hocko
SUSE Labs
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v4 00/15] staging: mt7621-pci: avoid custom pci config read and writes

2018-07-26 Thread Sergio Paracuellos
On Thu, Jul 26, 2018 at 1:24 PM, Sergio Paracuellos
 wrote:
> On Thu, Jul 26, 2018 at 08:02:17PM +1000, NeilBrown wrote:
>> On Thu, Jul 26 2018, Sergio Paracuellos wrote:
>>
>> >
>> > Ok, I think the problem is we are not setting the bridge->windows retrieved
>> > with devm_request_pci_bus_resources in "res". So we have to set those 
>> > properly
>> > to the bridge to get all correctly assigned. So I think adding this should 
>> > make
>> > the system to work:
>> >
>> > + list_splice_init(, >windows);
>> > bridge->busnr = 0;
>> > bridge->dev.parent = dev;
>> > bridge->sysdata = pcie;
>> >
>> >
>> > (Sorry don't access to code now and cannot diff).
>> >
>> > Let me know if this works. Is this the hopefully good one?
>>
>> This one, at least, makes a difference.
>>
>> I now see
>> [2.42] pci :01:00.0: BAR 5: assigned [mem 0x6000-0x61ff]
>>
>> which is promising.
>
> Yes, this and also the dmesg are promising and seems resources are correctly
> assigned now.
>
>>
>> However it gets to:
>>
>> [8.62] pci :00:00.0: enabling device (0004 -> 0006)
>> [8.64] ahci :01:00.0: enabling device ( -> 0002)
>>
>
> So after setup the PCI system topology is the driver responsability to enable
> the device. It means only make the hardware memory space accesible and
> this is the (-> 0002) of the log message (set the memory space bit of PCI 
> COMMAND
> register to 1 to make it accesible to allow the device to respond to memory 
> space acceses).
> So it is correct the behaviour of trying to enable this but it should not 
> hang. This trace is in
> drivers/pci/setup-res.c +495 (function pci_enable_resources). It would be 
> helpful
> a more deeper debug to know exactly where it really hangs.

I was thinking a reason for this to hang could be the access bridge
has not set the "bus master" bit enabled in its
PCI_COMMAND register but it should be set because this is done inside
"pci_assign_unassigned_bridge_resources"
concretely when "pci_enable_bridges(parent);" is called. This function
internally call pci_set_master(dev); that should set the bit active
for each bridge.

Best regards,
Sergio Paracuellos

>
> Thanks in advance.
>
>> and hangs.
>>
>> Full dmesg pasted below.
>>
>> Thanks,
>> NeilBrown
>
> Best regards,
> Sergio Paracuellos
>>
>>
>> [0.00] Linux version 4.18.0-rc5+ (neilb@noble) (gcc version 7.2.0 
>> (GCC)) #231 SMP Thu Jul 26 19:57:52 AEST 2018
>> [0.00] SoC Type: MediaTek MT7621 ver:1 eco:3
>> [0.00] bootconsole [early0] enabled
>> [0.00] CPU0 revision is: 0001992f (MIPS 1004Kc)
>> [0.00] MIPS: machine is GB-PC1
>> [0.00] Determined physical RAM map:
>> [0.00]  memory: 1c00 @  (usable)
>> [0.00]  memory: 0400 @ 2000 (usable)
>> [0.00] Initrd not found or empty - disabling initrd
>> [0.00] VPE topology {2,2} total 4
>> [0.00] Primary instruction cache 32kB, VIPT, 4-way, linesize 32 
>> bytes.
>> [0.00] Primary data cache 32kB, 4-way, PIPT, no aliases, linesize 32 
>> bytes
>> [0.00] MIPS secondary cache 256kB, 8-way, linesize 32 bytes.
>> [0.00] Zone ranges:
>> [0.00]   Normal   [mem 0x-0x1fff]
>> [0.00]   HighMem  [mem 0x2000-0x23ff]
>> [0.00] Movable zone start for each node
>> [0.00] Early memory node ranges
>> [0.00]   node   0: [mem 0x-0x1bff]
>> [0.00]   node   0: [mem 0x2000-0x23ff]
>> [0.00] Initmem setup node 0 [mem 
>> 0x-0x23ff]
>> [0.00] random: get_random_bytes called from start_kernel+0xb4/0x4ec 
>> with crng_init=0
>> [0.00] percpu: Embedded 15 pages/cpu @(ptrval) s30480 r8192 d22768 
>> u61440
>> [0.00] Built 1 zonelists, mobility grouping on.  Total pages: 130048
>> [0.00] Kernel command line: console=ttyS0,57600
>> [0.00] Dentry cache hash table entries: 65536 (order: 6, 262144 
>> bytes)
>> [0.00] Inode-cache hash table entries: 32768 (order: 5, 131072 bytes)
>> [0.00] Writing ErrCtl register=00010882
>> [0.00] Readback ErrCtl register=00010882
>> [0.00] Memory: 504788K/524288K available (6131K kernel code, 232K 
>> rwdata, 1052K rodata, 6524K init, 241K bss, 19500K reserved, 0K 
>> cma-reserved, 65536K highmem)
>> [0.00] SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=4, Nodes=1
>> [0.00] Hierarchical RCU implementation.
>> [0.00] NR_IRQS: 256
>> [0.00] clocksource: GIC: mask: 0x max_cycles: 
>> 0xcf914c9718, max_idle_ns: 440795231327 ns
>> [0.00] sched_clock: 32 bits at 100 Hz, resolution 1000ns, wraps 
>> every 2147483647500ns
>> [0.01] Calibrating delay loop... 597.60 BogoMIPS (lpj=2988032)
>> [0.07] pid_max: default: 32768 minimum: 301
>> [0.08] Mount-cache 

Re: [PATCH v7 4/4] kexec_file: Load kernel at top of system RAM if required

2018-07-26 Thread Baoquan He
On 07/26/18 at 02:59pm, Michal Hocko wrote:
> On Wed 25-07-18 14:48:13, Baoquan He wrote:
> > On 07/23/18 at 04:34pm, Michal Hocko wrote:
> > > On Thu 19-07-18 23:17:53, Baoquan He wrote:
> > > > Kexec has been a formal feature in our distro, and customers owning
> > > > those kind of very large machine can make use of this feature to speed
> > > > up the reboot process. On uefi machine, the kexec_file loading will
> > > > search place to put kernel under 4G from top to down. As we know, the
> > > > 1st 4G space is DMA32 ZONE, dma, pci mmcfg, bios etc all try to consume
> > > > it. It may have possibility to not be able to find a usable space for
> > > > kernel/initrd. From the top down of the whole memory space, we don't
> > > > have this worry. 
> > > 
> > > I do not have the full context here but let me note that you should be
> > > careful when doing top-down reservation because you can easily get into
> > > hotplugable memory and break the hotremove usecase. We even warn when
> > > this is done. See memblock_find_in_range_node
> > 
> > Kexec read kernel/initrd file into buffer, just search usable positions
> > for them to do the later copying. You can see below struct kexec_segment, 
> > for the old kexec_load, kernel/initrd are read into user space buffer,
> > the @buf stores the user space buffer address, @mem stores the position
> > where kernel/initrd will be put. In kernel, it calls
> > kimage_load_normal_segment() to copy user space buffer to intermediate
> > pages which are allocated with flag GFP_KERNEL. These intermediate pages
> > are recorded as entries, later when user execute "kexec -e" to trigger
> > kexec jumping, it will do the final copying from the intermediate pages
> > to the real destination pages which @mem pointed. Because we can't touch
> > the existed data in 1st kernel when do kexec kernel loading. With my
> > understanding, GFP_KERNEL will make those intermediate pages be
> > allocated inside immovable area, it won't impact hotplugging. But the
> > @mem we searched in the whole system RAM might be lost along with
> > hotplug. Hence we need do kexec kernel again when hotplug event is
> > detected.
> 
> I am not sure I am following. If @mem is placed at movable node then the
> memory hotremove simply won't work, because we are seeing reserved pages
> and do not know what to do about them. They are not migrateable.
> Allocating intermediate pages from other nodes doesn't really help.

OK, I forgot the 2nd kernel which kexec jump into. It won't impact hotremove
in 1st kernel, it does impact the kernel which kexec jump into if kernel
is at top of system RAM and the top RAM is in movable node.

> 
> The memblock code warns exactly for that reason.
> -- 
> Michal Hocko
> SUSE Labs
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v7 4/4] kexec_file: Load kernel at top of system RAM if required

2018-07-26 Thread Michal Hocko
On Wed 25-07-18 14:48:13, Baoquan He wrote:
> On 07/23/18 at 04:34pm, Michal Hocko wrote:
> > On Thu 19-07-18 23:17:53, Baoquan He wrote:
> > > Kexec has been a formal feature in our distro, and customers owning
> > > those kind of very large machine can make use of this feature to speed
> > > up the reboot process. On uefi machine, the kexec_file loading will
> > > search place to put kernel under 4G from top to down. As we know, the
> > > 1st 4G space is DMA32 ZONE, dma, pci mmcfg, bios etc all try to consume
> > > it. It may have possibility to not be able to find a usable space for
> > > kernel/initrd. From the top down of the whole memory space, we don't
> > > have this worry. 
> > 
> > I do not have the full context here but let me note that you should be
> > careful when doing top-down reservation because you can easily get into
> > hotplugable memory and break the hotremove usecase. We even warn when
> > this is done. See memblock_find_in_range_node
> 
> Kexec read kernel/initrd file into buffer, just search usable positions
> for them to do the later copying. You can see below struct kexec_segment, 
> for the old kexec_load, kernel/initrd are read into user space buffer,
> the @buf stores the user space buffer address, @mem stores the position
> where kernel/initrd will be put. In kernel, it calls
> kimage_load_normal_segment() to copy user space buffer to intermediate
> pages which are allocated with flag GFP_KERNEL. These intermediate pages
> are recorded as entries, later when user execute "kexec -e" to trigger
> kexec jumping, it will do the final copying from the intermediate pages
> to the real destination pages which @mem pointed. Because we can't touch
> the existed data in 1st kernel when do kexec kernel loading. With my
> understanding, GFP_KERNEL will make those intermediate pages be
> allocated inside immovable area, it won't impact hotplugging. But the
> @mem we searched in the whole system RAM might be lost along with
> hotplug. Hence we need do kexec kernel again when hotplug event is
> detected.

I am not sure I am following. If @mem is placed at movable node then the
memory hotremove simply won't work, because we are seeing reserved pages
and do not know what to do about them. They are not migrateable.
Allocating intermediate pages from other nodes doesn't really help.

The memblock code warns exactly for that reason.
-- 
Michal Hocko
SUSE Labs
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 25/25] staging: erofs: add a TODO and update MAINTAINERS for staging

2018-07-26 Thread Gao Xiang
This patch adds a TODO to list the things to be done, and
the relevant info to MAINTAINERS so we can take all the blame :)

Signed-off-by: Gao Xiang 
---
 MAINTAINERS|  7 +++
 drivers/staging/erofs/TODO | 45 +
 2 files changed, 52 insertions(+)
 create mode 100644 drivers/staging/erofs/TODO

diff --git a/MAINTAINERS b/MAINTAINERS
index 0fe4228..8d470b0 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -13487,6 +13487,13 @@ M: H Hartley Sweeten 
 S: Odd Fixes
 F: drivers/staging/comedi/
 
+STAGING - EROFS FILE SYSTEM
+M: Gao Xiang 
+M: Chao Yu 
+L: linux-er...@lists.ozlabs.org
+S: Maintained
+F: drivers/staging/erofs/
+
 STAGING - FLARION FT1000 DRIVERS
 M: Marek Belisko 
 S: Odd Fixes
diff --git a/drivers/staging/erofs/TODO b/drivers/staging/erofs/TODO
new file mode 100644
index 000..f99ddb8
--- /dev/null
+++ b/drivers/staging/erofs/TODO
@@ -0,0 +1,45 @@
+
+EROFS is still working in progress, thus it is not suitable
+for all productive uses. play at your own risk :)
+
+TODO List:
+ - add the missing error handling code
+   (mainly existed in xattr and decompression submodules);
+
+ - finalize erofs ondisk format design  (which means that
+   minor on-disk revisions could happen later);
+
+ - documentation and detailed technical analysis;
+
+ - general code review and clean up
+   (including confusing variable names and code snippets);
+
+ - support larger compressed clustersizes for selection
+   (currently erofs only works as expected with the page-sized
+compressed cluster configuration, usually 4KB);
+
+ - support more lossless data compression algorithms
+   in addition to LZ4 algorithms in VLE approach;
+
+ - data deduplication and other useful features.
+
+erofs-mkfs (preview version) binaries for i386 / x86_64 are available at:
+
+   https://github.com/hsiangkao/erofs_mkfs_binary
+
+It is still in progress opening mkfs source code to public,
+in any case an open-source mkfs will be released in the near future.
+
+
+Code, suggestions, etc, are welcome. Please feel free to
+ask and send patches,
+
+To:
+  linux-erofs mailing list   
+  Gao Xiang  
+  Chao Yu
+
+Cc: (for linux-kernel upstream patches)
+  Greg Kroah-Hartman 
+  linux-staging mailing list 
+
-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 24/25] staging: erofs: introduce cached decompression

2018-07-26 Thread Gao Xiang
This patch adds an optional choice which can be
enabled by users in order to cache both incomplete
ends of compressed clusters as a complement to
the in-place decompression in order to boost random
read, but it costs more memory than the in-place
decompression only.

Signed-off-by: Gao Xiang 
---
 drivers/staging/erofs/Kconfig |  38 ++
 drivers/staging/erofs/internal.h  |  26 
 drivers/staging/erofs/super.c |  73 ++
 drivers/staging/erofs/unzip_vle.c | 274 ++
 drivers/staging/erofs/utils.c |  17 ++-
 5 files changed, 427 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/erofs/Kconfig b/drivers/staging/erofs/Kconfig
index b55ce1c..663b755 100644
--- a/drivers/staging/erofs/Kconfig
+++ b/drivers/staging/erofs/Kconfig
@@ -101,3 +101,41 @@ config EROFS_FS_CLUSTER_PAGE_LIMIT
  than 2. Otherwise, the image cannot be mounted
  correctly on this kernel.
 
+choice
+   prompt "EROFS VLE Data Decompression mode"
+   depends on EROFS_FS_ZIP
+   default EROFS_FS_ZIP_CACHE_BIPOLAR
+   help
+ EROFS supports three options for VLE decompression.
+ "In-place Decompression Only" consumes the minimum memory
+ with lowest random read.
+
+ "Bipolar Cached Decompression" consumes the maximum memory
+ with highest random read.
+
+ If unsure, select "Bipolar Cached Decompression"
+
+config EROFS_FS_ZIP_NO_CACHE
+   bool "In-place Decompression Only"
+   help
+ Read compressed data into page cache and do in-place
+ decompression directly.
+
+config EROFS_FS_ZIP_CACHE_UNIPOLAR
+   bool "Unipolar Cached Decompression"
+   help
+ For each request, it caches the last compressed page
+ for further reading.
+ It still decompresses in place for the rest compressed pages.
+
+config EROFS_FS_ZIP_CACHE_BIPOLAR
+   bool "Bipolar Cached Decompression"
+   help
+ For each request, it caches the both end compressed pages
+ for further reading.
+ It still decompresses in place for the rest compressed pages.
+
+ Recommended for performance priority.
+
+endchoice
+
diff --git a/drivers/staging/erofs/internal.h b/drivers/staging/erofs/internal.h
index 3adec7d..669f93a 100644
--- a/drivers/staging/erofs/internal.h
+++ b/drivers/staging/erofs/internal.h
@@ -58,6 +58,18 @@ struct erofs_fault_info {
 };
 #endif
 
+#ifdef CONFIG_EROFS_FS_ZIP_CACHE_BIPOLAR
+#define EROFS_FS_ZIP_CACHE_LVL (2)
+#elif defined(EROFS_FS_ZIP_CACHE_UNIPOLAR)
+#define EROFS_FS_ZIP_CACHE_LVL (1)
+#else
+#define EROFS_FS_ZIP_CACHE_LVL (0)
+#endif
+
+#if (!defined(EROFS_FS_HAS_MANAGED_CACHE) && (EROFS_FS_ZIP_CACHE_LVL > 0))
+#define EROFS_FS_HAS_MANAGED_CACHE
+#endif
+
 /* EROFS_SUPER_MAGIC_V1 to represent the whole file system */
 #define EROFS_SUPER_MAGIC   EROFS_SUPER_MAGIC_V1
 
@@ -82,6 +94,11 @@ struct erofs_sb_info {
 
/* the dedicated workstation for compression */
struct radix_tree_root workstn_tree;
+
+#ifdef EROFS_FS_HAS_MANAGED_CACHE
+   struct inode *managed_cache;
+#endif
+
 #endif
 
u32 build_time_nsec;
@@ -240,6 +257,15 @@ static inline void erofs_workstation_cleanup_all(struct 
super_block *sb)
erofs_shrink_workstation(EROFS_SB(sb), ~0UL, true);
 }
 
+#ifdef EROFS_FS_HAS_MANAGED_CACHE
+#define EROFS_UNALLOCATED_CACHED_PAGE  ((void *)0x5F0EF00D)
+
+extern int try_to_free_all_cached_pages(struct erofs_sb_info *sbi,
+   struct erofs_workgroup *egrp);
+extern int try_to_free_cached_page(struct address_space *mapping,
+   struct page *page);
+#endif
+
 #endif
 
 /* we strictly follow PAGE_SIZE and no buffer head yet */
diff --git a/drivers/staging/erofs/super.c b/drivers/staging/erofs/super.c
index 2bd433a..97da5c8 100644
--- a/drivers/staging/erofs/super.c
+++ b/drivers/staging/erofs/super.c
@@ -256,6 +256,63 @@ static int parse_options(struct super_block *sb, char 
*options)
return 0;
 }
 
+#ifdef EROFS_FS_HAS_MANAGED_CACHE
+
+static const struct address_space_operations managed_cache_aops;
+
+static int managed_cache_releasepage(struct page *page, gfp_t gfp_mask)
+{
+   int ret = 1;/* 0 - busy */
+   struct address_space *const mapping = page->mapping;
+
+   BUG_ON(!PageLocked(page));
+   BUG_ON(mapping->a_ops != _cache_aops);
+
+   if (PagePrivate(page))
+   ret = try_to_free_cached_page(mapping, page);
+
+   return ret;
+}
+
+static void managed_cache_invalidatepage(struct page *page,
+   unsigned int offset, unsigned int length)
+{
+   const unsigned int stop = length + offset;
+
+   BUG_ON(!PageLocked(page));
+
+   /* Check for overflow */
+   BUG_ON(stop > PAGE_SIZE || stop < length);
+
+   if (offset == 0 && stop == PAGE_SIZE)
+   while (!managed_cache_releasepage(page, GFP_NOFS))
+   cond_resched();
+}
+
+static const struct address_space_operations managed_cache_aops = {

[PATCH 23/25] staging: erofs: introduce VLE decompression support

2018-07-26 Thread Gao Xiang
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.

Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:

|---  variable-length extent ---|-- VLE --|---  VLE ---|
 /> clusterofs  /> clusterofs /> clusterofs /> 
clusterofs
   ++---|---++---++-|-++---++-|-++-|
...||   |   ||   || | ||   || | || | ... 
original data
   ++---|---++---++-|-++---++-|-++-|
   ++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
 \ / //
  \  /  //
   \   ///
++---++---++---++
... ||   ||   ||   || ... compressed clusters
++---++---++---++
++->cluster<-++->cluster<-++->cluster<-++
 size size size

The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.

In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.

Signed-off-by: Gao Xiang 
---
 drivers/staging/erofs/inode.c |5 +
 drivers/staging/erofs/internal.h  |6 +
 drivers/staging/erofs/super.c |   25 +
 drivers/staging/erofs/unzip_vle.c | 1119 -
 drivers/staging/erofs/unzip_vle.h |  204 +++
 drivers/staging/erofs/utils.c |   61 +-
 6 files changed, 1418 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/erofs/inode.c b/drivers/staging/erofs/inode.c
index 613c977..fbf6ff2 100644
--- a/drivers/staging/erofs/inode.c
+++ b/drivers/staging/erofs/inode.c
@@ -210,7 +210,12 @@ static int fill_inode(struct inode *inode, int isdir)
}
 
if (is_inode_layout_compression(inode)) {
+#ifdef CONFIG_EROFS_FS_ZIP
+   inode->i_mapping->a_ops =
+   _erofs_vle_normalaccess_aops;
+#else
err = -ENOTSUPP;
+#endif
goto out_unlock;
}
 
diff --git a/drivers/staging/erofs/internal.h b/drivers/staging/erofs/internal.h
index b07cd7a..3adec7d 100644
--- a/drivers/staging/erofs/internal.h
+++ b/drivers/staging/erofs/internal.h
@@ -262,6 +262,9 @@ static inline void erofs_workstation_cleanup_all(struct 
super_block *sb)
 #ifdef CONFIG_EROFS_FS_ZIP
 /* hard limit of pages per compressed cluster */
 #define Z_EROFS_CLUSTER_MAX_PAGES   (CONFIG_EROFS_FS_CLUSTER_PAGE_LIMIT)
+
+/* page count of a compressed cluster */
+#define erofs_clusterpages(sbi) ((1 << (sbi)->clusterbits) / PAGE_SIZE)
 #endif
 
 typedef u64 erofs_off_t;
@@ -340,6 +343,9 @@ static inline bool is_inode_layout_inline(struct inode 
*inode)
 extern const struct file_operations erofs_dir_fops;
 
 extern const struct address_space_operations erofs_raw_access_aops;
+#ifdef CONFIG_EROFS_FS_ZIP
+extern const struct address_space_operations z_erofs_vle_normalaccess_aops;
+#endif
 
 /*
  * Logical to physical block mapping, used by erofs_map_blocks()
diff --git a/drivers/staging/erofs/super.c b/drivers/staging/erofs/super.c
index e155a2b..2bd433a 100644
--- a/drivers/staging/erofs/super.c
+++ b/drivers/staging/erofs/super.c
@@ -115,6 +115,13 @@ static int superblock_read(struct super_block *sb)
sbi->xattr_blkaddr = le32_to_cpu(layout->xattr_blkaddr);
 #endif
  

[PATCH 22/25] staging: erofs: introduce workstation for decompression

2018-07-26 Thread Gao Xiang
This patch introduces another concept used by the unzip
subsystem called 'workstation'. It can be seen as a sparse
array that stores pointers pointed to data structures
related to the corresponding physical blocks.

All lookup cases are protected by RCU read lock. Besides,
reference count and spin_lock are also introduced to
manage its lifetime and serialize all update operations.

'workstation' is currently implemented on the in-kernel
radix tree approach for backward compatibility.
With the evolution of linux kernel, it could be migrated
into XArray implementation in the future.

Signed-off-by: Gao Xiang 
---
 drivers/staging/erofs/internal.h | 93 
 drivers/staging/erofs/super.c|  9 
 drivers/staging/erofs/utils.c| 81 --
 3 files changed, 180 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/erofs/internal.h b/drivers/staging/erofs/internal.h
index 42455f0..b07cd7a 100644
--- a/drivers/staging/erofs/internal.h
+++ b/drivers/staging/erofs/internal.h
@@ -79,6 +79,9 @@ struct erofs_sb_info {
 #ifdef CONFIG_EROFS_FS_ZIP
/* cluster size in bit shift */
unsigned char clusterbits;
+
+   /* the dedicated workstation for compression */
+   struct radix_tree_root workstn_tree;
 #endif
 
u32 build_time_nsec;
@@ -149,6 +152,96 @@ static inline void *erofs_kmalloc(struct erofs_sb_info 
*sbi,
 #define set_opt(sbi, option)   ((sbi)->mount_opt |= EROFS_MOUNT_##option)
 #define test_opt(sbi, option)  ((sbi)->mount_opt & EROFS_MOUNT_##option)
 
+#ifdef CONFIG_EROFS_FS_ZIP
+#define erofs_workstn_lock(sbi) xa_lock(&(sbi)->workstn_tree)
+#define erofs_workstn_unlock(sbi)   xa_unlock(&(sbi)->workstn_tree)
+
+/* basic unit of the workstation of a super_block */
+struct erofs_workgroup {
+   /* the workgroup index in the workstation */
+   pgoff_t index;
+
+   /* overall workgroup reference count */
+   atomic_t refcount;
+};
+
+#define EROFS_LOCKED_MAGIC (INT_MIN | 0xE0F510CCL)
+
+static inline bool erofs_workgroup_try_to_freeze(
+   struct erofs_workgroup *grp, int v)
+{
+#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
+   if (v != atomic_cmpxchg(>refcount,
+   v, EROFS_LOCKED_MAGIC))
+   return false;
+   preempt_disable();
+#else
+   preempt_disable();
+   if (atomic_read(>refcount) != v) {
+   preempt_enable();
+   return false;
+   }
+#endif
+   return true;
+}
+
+static inline void erofs_workgroup_unfreeze(
+   struct erofs_workgroup *grp, int v)
+{
+#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
+   atomic_set(>refcount, v);
+#endif
+   preempt_enable();
+}
+
+static inline bool erofs_workgroup_get(struct erofs_workgroup *grp, int *ocnt)
+{
+   const int locked = (int)EROFS_LOCKED_MAGIC;
+   int o;
+
+repeat:
+   o = atomic_read(>refcount);
+
+   /* spin if it is temporarily locked at the reclaim path */
+   if (unlikely(o == locked)) {
+#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
+   do
+   cpu_relax();
+   while (atomic_read(>refcount) == locked);
+#endif
+   goto repeat;
+   }
+
+   if (unlikely(o <= 0))
+   return -1;
+
+   if (unlikely(atomic_cmpxchg(>refcount, o, o + 1) != o))
+   goto repeat;
+
+   *ocnt = o;
+   return 0;
+}
+
+#define __erofs_workgroup_get(grp) atomic_inc(&(grp)->refcount)
+
+extern int erofs_workgroup_put(struct erofs_workgroup *grp);
+
+extern struct erofs_workgroup *erofs_find_workgroup(
+   struct super_block *sb, pgoff_t index, bool *tag);
+
+extern int erofs_register_workgroup(struct super_block *sb,
+   struct erofs_workgroup *grp, bool tag);
+
+extern unsigned long erofs_shrink_workstation(struct erofs_sb_info *sbi,
+   unsigned long nr_shrink, bool cleanup);
+
+static inline void erofs_workstation_cleanup_all(struct super_block *sb)
+{
+   erofs_shrink_workstation(EROFS_SB(sb), ~0UL, true);
+}
+
+#endif
+
 /* we strictly follow PAGE_SIZE and no buffer head yet */
 #define LOG_BLOCK_SIZE PAGE_SHIFT
 
diff --git a/drivers/staging/erofs/super.c b/drivers/staging/erofs/super.c
index ef85884..e155a2b 100644
--- a/drivers/staging/erofs/super.c
+++ b/drivers/staging/erofs/super.c
@@ -296,6 +296,10 @@ static int erofs_read_super(struct super_block *sb,
if (!silent)
infoln("root inode @ nid %llu", ROOT_NID(sbi));
 
+#ifdef CONFIG_EROFS_FS_ZIP
+   INIT_RADIX_TREE(>workstn_tree, GFP_ATOMIC);
+#endif
+
/* get the root inode */
inode = erofs_iget(sb, ROOT_NID(sbi), true);
if (IS_ERR(inode)) {
@@ -376,6 +380,11 @@ static void erofs_put_super(struct super_block *sb)
__putname(sbi->dev_name);
 
mutex_lock(>umount_mutex);
+
+#ifdef CONFIG_EROFS_FS_ZIP
+   erofs_workstation_cleanup_all(sb);
+#endif
+

[PATCH 21/25] staging: erofs: introduce erofs shrinker

2018-07-26 Thread Gao Xiang
This patch adds a dedicated shrinker targeting to free unneeded
memory consumed by a number of erofs in-memory data structures.

Like F2FS and UBIFS, it also adds:
  - sbi->umount_mutex to avoid races on shrinker and put_super
  - sbi->shrinker_run_no to not revisit recently scaned objects

Signed-off-by: Gao Xiang 
---
 drivers/staging/erofs/internal.h |  7 
 drivers/staging/erofs/super.c| 15 +++
 drivers/staging/erofs/utils.c| 85 +---
 3 files changed, 101 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/erofs/internal.h b/drivers/staging/erofs/internal.h
index 18e7b9c..42455f0 100644
--- a/drivers/staging/erofs/internal.h
+++ b/drivers/staging/erofs/internal.h
@@ -66,6 +66,7 @@ struct erofs_fault_info {
 struct erofs_sb_info {
/* list for all registered superblocks, mainly for shrinker */
struct list_head list;
+   struct mutex umount_mutex;
 
u32 blocks;
u32 meta_blkaddr;
@@ -93,6 +94,7 @@ struct erofs_sb_info {
char *dev_name;
 
unsigned int mount_opt;
+   unsigned int shrinker_run_no;
 
 #ifdef CONFIG_EROFS_FAULT_INJECTION
struct erofs_fault_info fault_info; /* For fault injection */
@@ -416,6 +418,11 @@ static inline void erofs_vunmap(const void *mem, unsigned 
int count)
 extern void erofs_register_super(struct super_block *sb);
 extern void erofs_unregister_super(struct super_block *sb);
 
+extern unsigned long erofs_shrink_count(struct shrinker *shrink,
+   struct shrink_control *sc);
+extern unsigned long erofs_shrink_scan(struct shrinker *shrink,
+   struct shrink_control *sc);
+
 #ifndef lru_to_page
 #define lru_to_page(head) (list_entry((head)->prev, struct page, lru))
 #endif
diff --git a/drivers/staging/erofs/super.c b/drivers/staging/erofs/super.c
index f455d71..ef85884 100644
--- a/drivers/staging/erofs/super.c
+++ b/drivers/staging/erofs/super.c
@@ -375,7 +375,9 @@ static void erofs_put_super(struct super_block *sb)
infoln("unmounted for %s", sbi->dev_name);
__putname(sbi->dev_name);
 
+   mutex_lock(>umount_mutex);
erofs_unregister_super(sb);
+   mutex_unlock(>umount_mutex);
 
kfree(sbi);
sb->s_fs_info = NULL;
@@ -415,6 +417,12 @@ static void erofs_kill_sb(struct super_block *sb)
kill_block_super(sb);
 }
 
+static struct shrinker erofs_shrinker_info = {
+   .scan_objects = erofs_shrink_scan,
+   .count_objects = erofs_shrink_count,
+   .seeks = DEFAULT_SEEKS,
+};
+
 static struct file_system_type erofs_fs_type = {
.owner  = THIS_MODULE,
.name   = "erofs",
@@ -435,6 +443,10 @@ static int __init erofs_module_init(void)
if (err)
goto icache_err;
 
+   err = register_shrinker(_shrinker_info);
+   if (err)
+   goto shrinker_err;
+
err = register_filesystem(_fs_type);
if (err)
goto fs_err;
@@ -443,6 +455,8 @@ static int __init erofs_module_init(void)
return 0;
 
 fs_err:
+   unregister_shrinker(_shrinker_info);
+shrinker_err:
erofs_exit_inode_cache();
 icache_err:
return err;
@@ -451,6 +465,7 @@ static int __init erofs_module_init(void)
 static void __exit erofs_module_exit(void)
 {
unregister_filesystem(_fs_type);
+   unregister_shrinker(_shrinker_info);
erofs_exit_inode_cache();
infoln("successfully finalize erofs");
 }
diff --git a/drivers/staging/erofs/utils.c b/drivers/staging/erofs/utils.c
index 6748def..c1d83ce 100644
--- a/drivers/staging/erofs/utils.c
+++ b/drivers/staging/erofs/utils.c
@@ -29,20 +29,93 @@ struct page *erofs_allocpage(struct list_head *pool, gfp_t 
gfp)
return page;
 }
 
-static DEFINE_MUTEX(erofs_sb_list_lock);
+
+/* protected by 'erofs_sb_list_lock' */
+static unsigned int shrinker_run_no;
+
+/* protects the mounted 'erofs_sb_list' */
+static DEFINE_SPINLOCK(erofs_sb_list_lock);
 static LIST_HEAD(erofs_sb_list);
 
+/* global shrink count (for all mounted EROFS instances) */
+static atomic_long_t erofs_global_shrink_cnt;
+
 void erofs_register_super(struct super_block *sb)
 {
-   mutex_lock(_sb_list_lock);
-   list_add(_SB(sb)->list, _sb_list);
-   mutex_unlock(_sb_list_lock);
+   struct erofs_sb_info *sbi = EROFS_SB(sb);
+
+   mutex_init(>umount_mutex);
+
+   spin_lock(_sb_list_lock);
+   list_add(>list, _sb_list);
+   spin_unlock(_sb_list_lock);
 }
 
 void erofs_unregister_super(struct super_block *sb)
 {
-   mutex_lock(_sb_list_lock);
+   spin_lock(_sb_list_lock);
list_del(_SB(sb)->list);
-   mutex_unlock(_sb_list_lock);
+   spin_unlock(_sb_list_lock);
+}
+
+unsigned long erofs_shrink_count(struct shrinker *shrink,
+struct shrink_control *sc)
+{
+   return atomic_long_read(_global_shrink_cnt);
+}
+
+unsigned long erofs_shrink_scan(struct shrinker *shrink,
+   struct 

[PATCH 20/25] staging: erofs: introduce superblock registration

2018-07-26 Thread Gao Xiang
In order to introducing shrinker solution for erofs,
let's manage all mounted erofs instances at first.

Signed-off-by: Gao Xiang 
---
 drivers/staging/erofs/internal.h |  6 ++
 drivers/staging/erofs/super.c|  4 
 drivers/staging/erofs/utils.c| 17 +
 3 files changed, 27 insertions(+)

diff --git a/drivers/staging/erofs/internal.h b/drivers/staging/erofs/internal.h
index e61d417..18e7b9c 100644
--- a/drivers/staging/erofs/internal.h
+++ b/drivers/staging/erofs/internal.h
@@ -64,6 +64,9 @@ struct erofs_fault_info {
 typedef u64 erofs_nid_t;
 
 struct erofs_sb_info {
+   /* list for all registered superblocks, mainly for shrinker */
+   struct list_head list;
+
u32 blocks;
u32 meta_blkaddr;
 #ifdef CONFIG_EROFS_FS_XATTR
@@ -410,6 +413,9 @@ static inline void erofs_vunmap(const void *mem, unsigned 
int count)
 /* utils.c */
 extern struct page *erofs_allocpage(struct list_head *pool, gfp_t gfp);
 
+extern void erofs_register_super(struct super_block *sb);
+extern void erofs_unregister_super(struct super_block *sb);
+
 #ifndef lru_to_page
 #define lru_to_page(head) (list_entry((head)->prev, struct page, lru))
 #endif
diff --git a/drivers/staging/erofs/super.c b/drivers/staging/erofs/super.c
index 054375d..f455d71 100644
--- a/drivers/staging/erofs/super.c
+++ b/drivers/staging/erofs/super.c
@@ -326,6 +326,8 @@ static int erofs_read_super(struct super_block *sb,
snprintf(sbi->dev_name, PATH_MAX, "%s", dev_name);
sbi->dev_name[PATH_MAX - 1] = '\0';
 
+   erofs_register_super(sb);
+
/*
 * We already have a positive dentry, which was instantiated
 * by d_make_root. Just need to d_rehash it.
@@ -373,6 +375,8 @@ static void erofs_put_super(struct super_block *sb)
infoln("unmounted for %s", sbi->dev_name);
__putname(sbi->dev_name);
 
+   erofs_unregister_super(sb);
+
kfree(sbi);
sb->s_fs_info = NULL;
 }
diff --git a/drivers/staging/erofs/utils.c b/drivers/staging/erofs/utils.c
index 3dec4f8..6748def 100644
--- a/drivers/staging/erofs/utils.c
+++ b/drivers/staging/erofs/utils.c
@@ -29,3 +29,20 @@ struct page *erofs_allocpage(struct list_head *pool, gfp_t 
gfp)
return page;
 }
 
+static DEFINE_MUTEX(erofs_sb_list_lock);
+static LIST_HEAD(erofs_sb_list);
+
+void erofs_register_super(struct super_block *sb)
+{
+   mutex_lock(_sb_list_lock);
+   list_add(_SB(sb)->list, _sb_list);
+   mutex_unlock(_sb_list_lock);
+}
+
+void erofs_unregister_super(struct super_block *sb)
+{
+   mutex_lock(_sb_list_lock);
+   list_del(_SB(sb)->list);
+   mutex_unlock(_sb_list_lock);
+}
+
-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 19/25] staging: erofs: add a generic z_erofs VLE decompressor

2018-07-26 Thread Gao Xiang
Currently, this patch only simply implements LZ4
decompressor due to its development priority.

In the future, erofs will support more compression
algorithm and format other than LZ4, thus a generic
decompressor interface will be needed.

Signed-off-by: Gao Xiang 
---
 drivers/staging/erofs/Kconfig |  14 +++
 drivers/staging/erofs/Makefile|   2 +-
 drivers/staging/erofs/internal.h  |   5 +
 drivers/staging/erofs/unzip_vle.h |  35 ++
 drivers/staging/erofs/unzip_vle_lz4.c | 209 ++
 5 files changed, 264 insertions(+), 1 deletion(-)
 create mode 100644 drivers/staging/erofs/unzip_vle.h
 create mode 100644 drivers/staging/erofs/unzip_vle_lz4.c

diff --git a/drivers/staging/erofs/Kconfig b/drivers/staging/erofs/Kconfig
index 63bec70..b55ce1c 100644
--- a/drivers/staging/erofs/Kconfig
+++ b/drivers/staging/erofs/Kconfig
@@ -87,3 +87,17 @@ config EROFS_FS_ZIP
 
  If you don't want to use compression feature, say N.
 
+config EROFS_FS_CLUSTER_PAGE_LIMIT
+   int "EROFS Cluster Pages Hard Limit"
+   depends on EROFS_FS_ZIP
+   range 1 256
+   default "1"
+   help
+ Indicates VLE compressed pages hard limit of a
+ compressed cluster.
+
+ For example, if files of a image are compressed
+ into 8k-unit, the hard limit should not be less
+ than 2. Otherwise, the image cannot be mounted
+ correctly on this kernel.
+
diff --git a/drivers/staging/erofs/Makefile b/drivers/staging/erofs/Makefile
index e409637..9a766eb 100644
--- a/drivers/staging/erofs/Makefile
+++ b/drivers/staging/erofs/Makefile
@@ -9,5 +9,5 @@ obj-$(CONFIG_EROFS_FS) += erofs.o
 ccflags-y += -I$(src)/include
 erofs-objs := super.o inode.o data.o namei.o dir.o utils.o
 erofs-$(CONFIG_EROFS_FS_XATTR) += xattr.o
-erofs-$(CONFIG_EROFS_FS_ZIP) += unzip_vle.o unzip_lz4.o
+erofs-$(CONFIG_EROFS_FS_ZIP) += unzip_vle.o unzip_lz4.o unzip_vle_lz4.o
 
diff --git a/drivers/staging/erofs/internal.h b/drivers/staging/erofs/internal.h
index 6a0f045..e61d417 100644
--- a/drivers/staging/erofs/internal.h
+++ b/drivers/staging/erofs/internal.h
@@ -161,6 +161,11 @@ static inline void *erofs_kmalloc(struct erofs_sb_info 
*sbi,
 
 #define ROOT_NID(sb)   ((sb)->root_nid)
 
+#ifdef CONFIG_EROFS_FS_ZIP
+/* hard limit of pages per compressed cluster */
+#define Z_EROFS_CLUSTER_MAX_PAGES   (CONFIG_EROFS_FS_CLUSTER_PAGE_LIMIT)
+#endif
+
 typedef u64 erofs_off_t;
 
 /* data type for filesystem-wide blocks number */
diff --git a/drivers/staging/erofs/unzip_vle.h 
b/drivers/staging/erofs/unzip_vle.h
new file mode 100644
index 000..b34f5bc
--- /dev/null
+++ b/drivers/staging/erofs/unzip_vle.h
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: GPL-2.0
+ *
+ * linux/drivers/staging/erofs/unzip_vle.h
+ *
+ * Copyright (C) 2018 HUAWEI, Inc.
+ * http://www.huawei.com/
+ * Created by Gao Xiang 
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file COPYING in the main directory of the Linux
+ * distribution for more details.
+ */
+#ifndef __EROFS_FS_UNZIP_VLE_H
+#define __EROFS_FS_UNZIP_VLE_H
+
+#include "internal.h"
+
+#define Z_EROFS_VLE_INLINE_PAGEVECS 3
+
+/* unzip_vle_lz4.c */
+extern int z_erofs_vle_plain_copy(struct page **compressed_pages,
+   unsigned clusterpages, struct page **pages,
+   unsigned nr_pages, unsigned short pageofs);
+
+extern int z_erofs_vle_unzip_fast_percpu(struct page **compressed_pages,
+   unsigned clusterpages, struct page **pages,
+   unsigned outlen, unsigned short pageofs,
+   void (*endio)(struct page *));
+
+extern int z_erofs_vle_unzip_vmap(struct page **compressed_pages,
+   unsigned clusterpages, void *vaddr, unsigned llen,
+   unsigned short pageofs, bool overlapped);
+
+#endif
+
diff --git a/drivers/staging/erofs/unzip_vle_lz4.c 
b/drivers/staging/erofs/unzip_vle_lz4.c
new file mode 100644
index 000..f5b665f
--- /dev/null
+++ b/drivers/staging/erofs/unzip_vle_lz4.c
@@ -0,0 +1,209 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * linux/drivers/staging/erofs/unzip_vle_lz4.c
+ *
+ * Copyright (C) 2018 HUAWEI, Inc.
+ * http://www.huawei.com/
+ * Created by Gao Xiang 
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file COPYING in the main directory of the Linux
+ * distribution for more details.
+ */
+#include "unzip_vle.h"
+
+#if Z_EROFS_CLUSTER_MAX_PAGES > Z_EROFS_VLE_INLINE_PAGEVECS
+#define EROFS_PERCPU_NR_PAGES   Z_EROFS_CLUSTER_MAX_PAGES
+#else
+#define EROFS_PERCPU_NR_PAGES   Z_EROFS_VLE_INLINE_PAGEVECS
+#endif
+
+static struct {
+   char data[PAGE_SIZE * EROFS_PERCPU_NR_PAGES];
+} erofs_pcpubuf[NR_CPUS];
+
+int z_erofs_vle_plain_copy(struct page **compressed_pages,
+  unsigned clusterpages,
+  struct page **pages,
+  unsigned nr_pages,
+  

[PATCH 17/25] staging: erofs: globalize prepare_bio and __submit_bio

2018-07-26 Thread Gao Xiang
The unzip subsystem also uses these functions,
let's export them to internal.h.

Signed-off-by: Gao Xiang 
---
 drivers/staging/erofs/data.c | 34 +-
 drivers/staging/erofs/internal.h | 33 +
 2 files changed, 42 insertions(+), 25 deletions(-)

diff --git a/drivers/staging/erofs/data.c b/drivers/staging/erofs/data.c
index 163bfe6..ac263a1 100644
--- a/drivers/staging/erofs/data.c
+++ b/drivers/staging/erofs/data.c
@@ -38,26 +38,6 @@ static inline void read_endio(struct bio *bio)
bio_put(bio);
 }
 
-static void __submit_bio(struct bio *bio, unsigned op, unsigned op_flags)
-{
-   bio_set_op_attrs(bio, op, op_flags);
-   submit_bio(bio);
-}
-
-static struct bio *prepare_bio(struct super_block *sb,
-   erofs_blk_t blkaddr, unsigned nr_pages)
-{
-   struct bio *bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, nr_pages);
-
-   BUG_ON(bio == NULL);
-
-   bio->bi_end_io = read_endio;
-   bio_set_dev(bio, sb->s_bdev);
-   bio->bi_iter.bi_sector = blkaddr << LOG_SECTORS_PER_BLOCK;
-
-   return bio;
-}
-
 /* prio -- true is used for dir */
 struct page *erofs_get_meta_page(struct super_block *sb,
erofs_blk_t blkaddr, bool prio)
@@ -80,7 +60,7 @@ struct page *erofs_get_meta_page(struct super_block *sb,
struct bio *bio;
int err;
 
-   bio = prepare_bio(sb, blkaddr, 1);
+   bio = prepare_bio(sb, blkaddr, 1, read_endio);
err = bio_add_page(bio, page, PAGE_SIZE, 0);
BUG_ON(err != PAGE_SIZE);
 
@@ -236,6 +216,8 @@ static inline struct bio *erofs_read_raw_page(
struct erofs_map_blocks map = {
.m_la = blknr_to_addr(current_block),
};
+   erofs_blk_t blknr;
+   unsigned blkoff;
 
err = erofs_map_blocks(inode, , EROFS_GET_BLOCKS_RAW);
if (unlikely(err))
@@ -253,6 +235,9 @@ static inline struct bio *erofs_read_raw_page(
/* for RAW access mode, m_plen must be equal to m_llen */
BUG_ON(map.m_plen != map.m_llen);
 
+   blknr = erofs_blknr(map.m_pa);
+   blkoff = erofs_blkoff(map.m_pa);
+
/* deal with inline page */
if (map.m_flags & EROFS_MAP_META) {
void *vsrc, *vto;
@@ -260,8 +245,7 @@ static inline struct bio *erofs_read_raw_page(
 
BUG_ON(map.m_plen > PAGE_SIZE);
 
-   ipage = erofs_get_meta_page(inode->i_sb,
-   erofs_blknr(map.m_pa), 0);
+   ipage = erofs_get_meta_page(inode->i_sb, blknr, 0);
 
if (IS_ERR(ipage)) {
err = PTR_ERR(ipage);
@@ -270,7 +254,7 @@ static inline struct bio *erofs_read_raw_page(
 
vsrc = kmap_atomic(ipage);
vto = kmap_atomic(page);
-   memcpy(vto, vsrc + erofs_blkoff(map.m_pa), map.m_plen);
+   memcpy(vto, vsrc + blkoff, map.m_plen);
memset(vto + map.m_plen, 0, PAGE_SIZE - map.m_plen);
kunmap_atomic(vto);
kunmap_atomic(vsrc);
@@ -294,7 +278,7 @@ static inline struct bio *erofs_read_raw_page(
if (nblocks > BIO_MAX_PAGES)
nblocks = BIO_MAX_PAGES;
 
-   bio = prepare_bio(inode->i_sb, erofs_blknr(map.m_pa), nblocks);
+   bio = prepare_bio(inode->i_sb, blknr, nblocks, read_endio);
}
 
err = bio_add_page(bio, page, PAGE_SIZE, 0);
diff --git a/drivers/staging/erofs/internal.h b/drivers/staging/erofs/internal.h
index 210ab6c..6a0f045 100644
--- a/drivers/staging/erofs/internal.h
+++ b/drivers/staging/erofs/internal.h
@@ -285,6 +285,39 @@ struct erofs_map_blocks {
 #define EROFS_GET_BLOCKS_RAW0x0001
 
 /* data.c */
+static inline struct bio *prepare_bio(
+   struct super_block *sb,
+   erofs_blk_t blkaddr, unsigned nr_pages,
+   bio_end_io_t endio)
+{
+   gfp_t gfp = GFP_NOIO;
+   struct bio *bio = bio_alloc(gfp, nr_pages);
+
+   if (unlikely(bio == NULL) &&
+   (current->flags & PF_MEMALLOC)) {
+   do {
+   nr_pages /= 2;
+   if (unlikely(!nr_pages)) {
+   bio = bio_alloc(gfp | __GFP_NOFAIL, 1);
+   BUG_ON(bio == NULL);
+   break;
+   }
+   bio = bio_alloc(gfp, nr_pages);
+   } while (bio == NULL);
+   }
+
+   bio->bi_end_io = endio;
+   bio_set_dev(bio, sb->s_bdev);
+   bio->bi_iter.bi_sector = blkaddr << LOG_SECTORS_PER_BLOCK;
+   return bio;
+}
+
+static inline void __submit_bio(struct bio *bio, unsigned op, unsigned 
op_flags)
+{
+   bio_set_op_attrs(bio, op, 

[PATCH 18/25] staging: erofs: introduce a customized LZ4 decompression

2018-07-26 Thread Gao Xiang
We have to reduce the memory cost as much as possible,
so we don't want to decompress more data beyond
the output buffer size, however "LZ4_decompress_safe_partial"
doesn't guarantee to stop at the arbitary end position,
but stop just after its current LZ4 "sequence" is completed.

Link: https://groups.google.com/forum/#!topic/lz4c/_3kkz5N6n00

Therefore, I hacked the LZ4 decompression logic by hand,
probably NOT the fastest approach, and hope for better
implementation.

Signed-off-by: Miao Xie 
Signed-off-by: Chao Yu 
Signed-off-by: Gao Xiang 
---
 drivers/staging/erofs/Makefile|   2 +-
 drivers/staging/erofs/lz4defs.h   | 227 ++
 drivers/staging/erofs/unzip_lz4.c | 251 ++
 3 files changed, 479 insertions(+), 1 deletion(-)
 create mode 100644 drivers/staging/erofs/lz4defs.h
 create mode 100644 drivers/staging/erofs/unzip_lz4.c

diff --git a/drivers/staging/erofs/Makefile b/drivers/staging/erofs/Makefile
index 490fa6c..e409637 100644
--- a/drivers/staging/erofs/Makefile
+++ b/drivers/staging/erofs/Makefile
@@ -9,5 +9,5 @@ obj-$(CONFIG_EROFS_FS) += erofs.o
 ccflags-y += -I$(src)/include
 erofs-objs := super.o inode.o data.o namei.o dir.o utils.o
 erofs-$(CONFIG_EROFS_FS_XATTR) += xattr.o
-erofs-$(CONFIG_EROFS_FS_ZIP) += unzip_vle.o
+erofs-$(CONFIG_EROFS_FS_ZIP) += unzip_vle.o unzip_lz4.o
 
diff --git a/drivers/staging/erofs/lz4defs.h b/drivers/staging/erofs/lz4defs.h
new file mode 100644
index 000..00a0b58
--- /dev/null
+++ b/drivers/staging/erofs/lz4defs.h
@@ -0,0 +1,227 @@
+#ifndef __LZ4DEFS_H__
+#define __LZ4DEFS_H__
+
+/*
+ * lz4defs.h -- common and architecture specific defines for the kernel usage
+
+ * LZ4 - Fast LZ compression algorithm
+ * Copyright (C) 2011-2016, Yann Collet.
+ * BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * You can contact the author at :
+ * - LZ4 homepage : http://www.lz4.org
+ * - LZ4 source repository : https://github.com/lz4/lz4
+ *
+ * Changed for kernel usage by:
+ * Sven Schmidt <4ssch...@informatik.uni-hamburg.de>
+ */
+
+#include 
+#include/* memset, memcpy */
+
+#define FORCE_INLINE __always_inline
+
+/*-
+ * Basic Types
+ **/
+#include 
+
+typedefuint8_t BYTE;
+typedef uint16_t U16;
+typedef uint32_t U32;
+typedefint32_t S32;
+typedef uint64_t U64;
+typedef uintptr_t uptrval;
+
+/*-
+ * Architecture specifics
+ **/
+#if defined(CONFIG_64BIT)
+#define LZ4_ARCH64 1
+#else
+#define LZ4_ARCH64 0
+#endif
+
+#if defined(__LITTLE_ENDIAN)
+#define LZ4_LITTLE_ENDIAN 1
+#else
+#define LZ4_LITTLE_ENDIAN 0
+#endif
+
+/*-
+ * Constants
+ **/
+#define MINMATCH 4
+
+#define WILDCOPYLENGTH 8
+#define LASTLITERALS 5
+#define MFLIMIT (WILDCOPYLENGTH + MINMATCH)
+
+/* Increase this value ==> compression run slower on incompressible data */
+#define LZ4_SKIPTRIGGER 6
+
+#define HASH_UNIT sizeof(size_t)
+
+#define KB (1 << 10)
+#define MB (1 << 20)
+#define GB (1U << 30)
+
+#define MAXD_LOG 16
+#define MAX_DISTANCE ((1 << MAXD_LOG) - 1)
+#define STEPSIZE sizeof(size_t)
+
+#define ML_BITS4
+#define ML_MASK((1U << ML_BITS) - 1)
+#define RUN_BITS (8 - ML_BITS)
+#define RUN_MASK ((1U << RUN_BITS) - 1)
+
+/*-
+ * Reading and writing into memory
+ **/
+static FORCE_INLINE U16 LZ4_read16(const void *ptr)
+{
+   return 

[PATCH 16/25] staging: erofs: add erofs_allocpage

2018-07-26 Thread Gao Xiang
This patch introduces an temporary _on-stack_ page
pool to reuse the freed page directly as much as
it can for better performance and release all pages
at a time, it also slightly reduces the possibility of
the potential memory allocation failure.

Signed-off-by: Gao Xiang 
---
 drivers/staging/erofs/Makefile   |  2 +-
 drivers/staging/erofs/internal.h |  7 +++
 drivers/staging/erofs/utils.c| 31 +++
 3 files changed, 39 insertions(+), 1 deletion(-)
 create mode 100644 drivers/staging/erofs/utils.c

diff --git a/drivers/staging/erofs/Makefile b/drivers/staging/erofs/Makefile
index 8558c76..490fa6c 100644
--- a/drivers/staging/erofs/Makefile
+++ b/drivers/staging/erofs/Makefile
@@ -7,7 +7,7 @@ ccflags-y += -Wall -DEROFS_VERSION=\"$(EROFS_VERSION)\"
 obj-$(CONFIG_EROFS_FS) += erofs.o
 # staging requirement: to be self-contained in its own directory
 ccflags-y += -I$(src)/include
-erofs-objs := super.o inode.o data.o namei.o dir.o
+erofs-objs := super.o inode.o data.o namei.o dir.o utils.o
 erofs-$(CONFIG_EROFS_FS_XATTR) += xattr.o
 erofs-$(CONFIG_EROFS_FS_ZIP) += unzip_vle.o
 
diff --git a/drivers/staging/erofs/internal.h b/drivers/staging/erofs/internal.h
index bea5ec4..210ab6c 100644
--- a/drivers/staging/erofs/internal.h
+++ b/drivers/staging/erofs/internal.h
@@ -369,5 +369,12 @@ static inline void erofs_vunmap(const void *mem, unsigned 
int count)
 #endif
 }
 
+/* utils.c */
+extern struct page *erofs_allocpage(struct list_head *pool, gfp_t gfp);
+
+#ifndef lru_to_page
+#define lru_to_page(head) (list_entry((head)->prev, struct page, lru))
+#endif
+
 #endif
 
diff --git a/drivers/staging/erofs/utils.c b/drivers/staging/erofs/utils.c
new file mode 100644
index 000..3dec4f8
--- /dev/null
+++ b/drivers/staging/erofs/utils.c
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * linux/drivers/staging/erofs/utils.c
+ *
+ * Copyright (C) 2018 HUAWEI, Inc.
+ * http://www.huawei.com/
+ * Created by Gao Xiang 
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file COPYING in the main directory of the Linux
+ * distribution for more details.
+ */
+
+#include "internal.h"
+
+struct page *erofs_allocpage(struct list_head *pool, gfp_t gfp)
+{
+   struct page *page;
+
+   if (!list_empty(pool)) {
+   page = lru_to_page(pool);
+   list_del(>lru);
+   } else {
+   page = alloc_pages(gfp | __GFP_NOFAIL, 0);
+
+   BUG_ON(page == NULL);
+   BUG_ON(page->mapping != NULL);
+   }
+   return page;
+}
+
-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 15/25] staging: erofs: add erofs_map_blocks_iter

2018-07-26 Thread Gao Xiang
This patch introduces an iterable L2P mapping
operation 'erofs_map_blocks_iter'.
Compared with 'erofs_map_blocks', it avoids
a number of redundant 'release and regrab'
processes if they request the same meta page.

Signed-off-by: Gao Xiang 
---
 drivers/staging/erofs/Kconfig |  10 ++
 drivers/staging/erofs/Makefile|   1 +
 drivers/staging/erofs/data.c  |  36 +-
 drivers/staging/erofs/internal.h  |  12 ++
 drivers/staging/erofs/unzip_vle.c | 243 ++
 5 files changed, 300 insertions(+), 2 deletions(-)
 create mode 100644 drivers/staging/erofs/unzip_vle.c

diff --git a/drivers/staging/erofs/Kconfig b/drivers/staging/erofs/Kconfig
index edda055..63bec70 100644
--- a/drivers/staging/erofs/Kconfig
+++ b/drivers/staging/erofs/Kconfig
@@ -77,3 +77,13 @@ config EROFS_FAULT_INJECTION
help
  Test EROFS to inject faults such as ENOMEM, EIO, and so on.
  If unsure, say N.
+
+config EROFS_FS_ZIP
+   bool "EROFS Data Compresssion Support"
+   depends on EROFS_FS
+   help
+ Currently we support VLE Compression only.
+ Play at your own risk.
+
+ If you don't want to use compression feature, say N.
+
diff --git a/drivers/staging/erofs/Makefile b/drivers/staging/erofs/Makefile
index 977b7e0..8558c76 100644
--- a/drivers/staging/erofs/Makefile
+++ b/drivers/staging/erofs/Makefile
@@ -9,4 +9,5 @@ obj-$(CONFIG_EROFS_FS) += erofs.o
 ccflags-y += -I$(src)/include
 erofs-objs := super.o inode.o data.o namei.o dir.o
 erofs-$(CONFIG_EROFS_FS_XATTR) += xattr.o
+erofs-$(CONFIG_EROFS_FS_ZIP) += unzip_vle.o
 
diff --git a/drivers/staging/erofs/data.c b/drivers/staging/erofs/data.c
index 47d1787..163bfe6 100644
--- a/drivers/staging/erofs/data.c
+++ b/drivers/staging/erofs/data.c
@@ -157,12 +157,44 @@ static int erofs_map_blocks_flatmode(struct inode *inode,
return 0;
 }
 
+#ifdef CONFIG_EROFS_FS_ZIP
+extern int z_erofs_map_blocks_iter(struct inode *,
+   struct erofs_map_blocks *, struct page **, int);
+#endif
+
+int erofs_map_blocks_iter(struct inode *inode,
+   struct erofs_map_blocks *map,
+   struct page **mpage_ret, int flags)
+{
+   /* by default, reading raw data never use erofs_map_blocks_iter */
+   if (unlikely(!is_inode_layout_compression(inode))) {
+   if (*mpage_ret != NULL)
+   put_page(*mpage_ret);
+   *mpage_ret = NULL;
+
+   return erofs_map_blocks(inode, map, flags);
+   }
+
+#ifdef CONFIG_EROFS_FS_ZIP
+   return z_erofs_map_blocks_iter(inode, map, mpage_ret, flags);
+#else
+   /* data compression is not available */
+   return -ENOTSUPP;
+#endif
+}
+
 int erofs_map_blocks(struct inode *inode,
struct erofs_map_blocks *map, int flags)
 {
-   if (unlikely(is_inode_layout_compression(inode)))
-   return -ENOTSUPP;
+   if (unlikely(is_inode_layout_compression(inode))) {
+   struct page *mpage = NULL;
+   int err;
 
+   err = erofs_map_blocks_iter(inode, map, , flags);
+   if (mpage != NULL)
+   put_page(mpage);
+   return err;
+   }
return erofs_map_blocks_flatmode(inode, map, flags);
 }
 
diff --git a/drivers/staging/erofs/internal.h b/drivers/staging/erofs/internal.h
index ca22486..bea5ec4 100644
--- a/drivers/staging/erofs/internal.h
+++ b/drivers/staging/erofs/internal.h
@@ -72,6 +72,10 @@ struct erofs_sb_info {
 
/* inode slot unit size in bit shift */
unsigned char islotbits;
+#ifdef CONFIG_EROFS_FS_ZIP
+   /* cluster size in bit shift */
+   unsigned char clusterbits;
+#endif
 
u32 build_time_nsec;
u64 build_time;
@@ -284,6 +288,14 @@ struct erofs_map_blocks {
 extern struct page *erofs_get_meta_page(struct super_block *sb,
erofs_blk_t blkaddr, bool prio);
 extern int erofs_map_blocks(struct inode *, struct erofs_map_blocks *, int);
+extern int erofs_map_blocks_iter(struct inode *, struct erofs_map_blocks *,
+   struct page **, int);
+
+struct erofs_map_blocks_iter {
+   struct erofs_map_blocks map;
+   struct page *mpage;
+};
+
 
 static inline struct page *erofs_get_inline_page(struct inode *inode,
erofs_blk_t blkaddr)
diff --git a/drivers/staging/erofs/unzip_vle.c 
b/drivers/staging/erofs/unzip_vle.c
new file mode 100644
index 000..329cbe4
--- /dev/null
+++ b/drivers/staging/erofs/unzip_vle.c
@@ -0,0 +1,243 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * linux/drivers/staging/erofs/unzip_vle.c
+ *
+ * Copyright (C) 2018 HUAWEI, Inc.
+ * http://www.huawei.com/
+ * Created by Gao Xiang 
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file COPYING in the main directory of the Linux
+ * distribution for more details.
+ */
+#include "internal.h"
+
+#define __vle_cluster_advise(x, bit, bits) \
+   ((le16_to_cpu(x) >> (bit)) & ((1 << (bits)) - 1))
+

[PATCH 13/25] staging: erofs: : introduce tagged pointer

2018-07-26 Thread Gao Xiang
Currently kernel has scattered tagged pointer usages hacked
by hand in plain code, without a unique and portable functionset
to highlight the tagged pointer itself and wrap these hacked code
in order to clean up all over meaningless magic masks.

Therefore, this patch introduces simple generic methods to fold
tags into a pointer integer. It currently supports the last n bits
of the pointer for tags, which can be selected by users.

In addition, it will also be used for the upcoming EROFS filesystem,
which heavily uses tagged pointer approach for high performance
and reducing extra memory allocation.

Link: https://en.wikipedia.org/wiki/Tagged_pointer

Signed-off-by: Gao Xiang 
---
 drivers/staging/erofs/include/linux/tagptr.h | 110 +++
 1 file changed, 110 insertions(+)
 create mode 100644 drivers/staging/erofs/include/linux/tagptr.h

diff --git a/drivers/staging/erofs/include/linux/tagptr.h 
b/drivers/staging/erofs/include/linux/tagptr.h
new file mode 100644
index 000..ccd106d
--- /dev/null
+++ b/drivers/staging/erofs/include/linux/tagptr.h
@@ -0,0 +1,110 @@
+/* SPDX-License-Identifier: GPL-2.0
+ *
+ * Tagged pointer implementation
+ *
+ * Copyright (C) 2018 Gao Xiang 
+ */
+#ifndef _LINUX_TAGPTR_H
+#define _LINUX_TAGPTR_H
+
+#include 
+#include 
+
+/*
+ * the name of tagged pointer types are tagptr{1, 2, 3...}_t
+ * avoid directly using the internal structs __tagptr{1, 2, 3...}
+ */
+#define __MAKE_TAGPTR(n) \
+typedef struct __tagptr##n {   \
+   uintptr_t v;\
+} tagptr##n##_t;
+
+__MAKE_TAGPTR(1)
+__MAKE_TAGPTR(2)
+__MAKE_TAGPTR(3)
+__MAKE_TAGPTR(4)
+
+#undef __MAKE_TAGPTR
+
+extern void __compiletime_error("bad tagptr tags")
+   __bad_tagptr_tags(void);
+
+extern void __compiletime_error("bad tagptr type")
+   __bad_tagptr_type(void);
+
+/* fix the broken usage of "#define tagptr2_t tagptr3_t" by users */
+#define __tagptr_mask_1(ptr, n)\
+   __builtin_types_compatible_p(typeof(ptr), struct __tagptr##n) ? \
+   (1UL << (n)) - 1 :
+
+#define __tagptr_mask(ptr) (\
+   __tagptr_mask_1(ptr, 1) ( \
+   __tagptr_mask_1(ptr, 2) ( \
+   __tagptr_mask_1(ptr, 3) ( \
+   __tagptr_mask_1(ptr, 4) ( \
+   __bad_tagptr_type(), 0)
+
+/* generate a tagged pointer from a raw value */
+#define tagptr_init(type, val) \
+   ((typeof(type)){ .v = (uintptr_t)(val) })
+
+/*
+ * directly cast a tagged pointer to the native pointer type, which
+ * could be used for backward compatibility of existing code.
+ */
+#define tagptr_cast_ptr(tptr) ((void *)(tptr).v)
+
+/* encode tagged pointers */
+#define tagptr_fold(type, ptr, _tags) ({ \
+   const typeof(_tags) tags = (_tags); \
+   if (__builtin_constant_p(tags) && (tags & ~__tagptr_mask(type))) \
+   __bad_tagptr_tags(); \
+tagptr_init(type, (uintptr_t)(ptr) | tags); })
+
+/* decode tagged pointers */
+#define tagptr_unfold_ptr(tptr) \
+   ((void *)((tptr).v & ~__tagptr_mask(tptr)))
+
+#define tagptr_unfold_tags(tptr) \
+   ((tptr).v & __tagptr_mask(tptr))
+
+/* operations for the tagger pointer */
+#define tagptr_eq(_tptr1, _tptr2) ({ \
+   typeof(_tptr1) tptr1 = (_tptr1); \
+   typeof(_tptr2) tptr2 = (_tptr2); \
+   (void)( == ); \
+(tptr1).v == (tptr2).v; })
+
+/* lock-free CAS operation */
+#define tagptr_cmpxchg(_ptptr, _o, _n) ({ \
+   typeof(_ptptr) ptptr = (_ptptr); \
+   typeof(_o) o = (_o); \
+   typeof(_n) n = (_n); \
+   (void)( == ); \
+   (void)( == ptptr); \
+tagptr_init(o, cmpxchg(>v, o.v, n.v)); })
+
+/* wrap WRITE_ONCE if atomic update is needed */
+#define tagptr_replace_tags(_ptptr, tags) ({ \
+   typeof(_ptptr) ptptr = (_ptptr); \
+   *ptptr = tagptr_fold(*ptptr, tagptr_unfold_ptr(*ptptr), tags); \
+*ptptr; })
+
+#define tagptr_set_tags(_ptptr, _tags) ({ \
+   typeof(_ptptr) ptptr = (_ptptr); \
+   const typeof(_tags) tags = (_tags); \
+   if (__builtin_constant_p(tags) && (tags & ~__tagptr_mask(*ptptr))) \
+   __bad_tagptr_tags(); \
+   ptptr->v |= tags; \
+*ptptr; })
+
+#define tagptr_clear_tags(_ptptr, _tags) ({ \
+   typeof(_ptptr) ptptr = (_ptptr); \
+   const typeof(_tags) tags = (_tags); \
+   if (__builtin_constant_p(tags) && (tags & ~__tagptr_mask(*ptptr))) \
+   __bad_tagptr_tags(); \
+   ptptr->v &= ~tags; \
+*ptptr; })
+
+#endif
+
-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 12/25] staging: erofs: support tracepoint

2018-07-26 Thread Gao Xiang
From: Chao Yu 

Add basic tracepoints for ->readpage{,s}, ->lookup,
->destroy_inode, fill_inode and map_blocks.

Reviewed-by: Gao Xiang 
Signed-off-by: Chao Yu 
---
 drivers/staging/erofs/data.c   |  13 +-
 drivers/staging/erofs/include/trace/events/erofs.h | 240 +
 drivers/staging/erofs/inode.c  |   4 +
 drivers/staging/erofs/namei.c  |   4 +
 drivers/staging/erofs/super.c  |   3 +
 5 files changed, 261 insertions(+), 3 deletions(-)
 create mode 100644 drivers/staging/erofs/include/trace/events/erofs.h

diff --git a/drivers/staging/erofs/data.c b/drivers/staging/erofs/data.c
index 4ddb5c0..47d1787 100644
--- a/drivers/staging/erofs/data.c
+++ b/drivers/staging/erofs/data.c
@@ -13,6 +13,8 @@
 #include "internal.h"
 #include 
 
+#include 
+
 static inline void read_endio(struct bio *bio)
 {
int i;
@@ -113,6 +115,7 @@ static int erofs_map_blocks_flatmode(struct inode *inode,
u64 offset = map->m_la;
struct erofs_vnode *vi = EROFS_V(inode);
 
+   trace_erofs_map_blocks_flatmode_enter(inode, map, flags);
BUG_ON(is_inode_layout_compression(inode));
 
nblocks = DIV_ROUND_UP(inode->i_size, PAGE_SIZE);
@@ -150,8 +153,7 @@ static int erofs_map_blocks_flatmode(struct inode *inode,
 
 out:
map->m_llen = map->m_plen;
-   debugln("%s, m_la 0x%llx m_pa %llx m_len %llu",
-   __func__, map->m_la, map->m_pa, map->m_plen);
+   trace_erofs_map_blocks_flatmode_exit(inode, map, flags, 0);
return 0;
 }
 
@@ -305,6 +307,8 @@ static int erofs_raw_access_readpage(struct file *file, 
struct page *page)
erofs_off_t last_block;
struct bio *bio;
 
+   trace_erofs_readpage(page, true);
+
bio = erofs_read_raw_page(NULL, page->mapping,
page, _block, 1, false);
 
@@ -322,9 +326,12 @@ static int erofs_raw_access_readpages(struct file *filp,
erofs_off_t last_block;
struct bio *bio = NULL;
gfp_t gfp = readahead_gfp_mask(mapping);
+   struct page *page = list_last_entry(pages, struct page, lru);
+
+   trace_erofs_readpages(mapping->host, page, nr_pages, true);
 
for (; nr_pages; --nr_pages) {
-   struct page *page = list_entry(pages->prev, struct page, lru);
+   page = list_entry(pages->prev, struct page, lru);
 
prefetchw(>flags);
list_del(>lru);
diff --git a/drivers/staging/erofs/include/trace/events/erofs.h 
b/drivers/staging/erofs/include/trace/events/erofs.h
new file mode 100644
index 000..5aead93
--- /dev/null
+++ b/drivers/staging/erofs/include/trace/events/erofs.h
@@ -0,0 +1,240 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM erofs
+
+#if !defined(_TRACE_EROFS_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_EROFS_H
+
+#include 
+
+#define show_dev(dev)  MAJOR(dev), MINOR(dev)
+#define show_dev_nid(entry)show_dev(entry->dev), entry->nid
+
+#define show_file_type(type)   \
+   __print_symbolic(type,  \
+   { 0,"FILE" },   \
+   { 1,"DIR" })
+
+#define show_map_flags(flags) __print_flags(flags, "|",\
+   { EROFS_GET_BLOCKS_RAW, "RAW" })
+
+#define show_mflags(flags) __print_flags(flags, "",\
+   { EROFS_MAP_MAPPED, "M" },  \
+   { EROFS_MAP_META,   "I" },  \
+   { EROFS_MAP_ZIPPED, "Z" })
+
+TRACE_EVENT(erofs_lookup,
+
+   TP_PROTO(struct inode *dir, struct dentry *dentry, unsigned int flags),
+
+   TP_ARGS(dir, dentry, flags),
+
+   TP_STRUCT__entry(
+   __field(dev_t,  dev )
+   __field(erofs_nid_t,nid )
+   __field(const char *,   name)
+   __field(unsigned int,   flags   )
+   ),
+
+   TP_fast_assign(
+   __entry->dev= dir->i_sb->s_dev;
+   __entry->nid= EROFS_V(dir)->nid;
+   __entry->name   = dentry->d_name.name;
+   __entry->flags  = flags;
+   ),
+
+   TP_printk("dev = (%d,%d), pnid = %llu, name:%s, flags:%x",
+   show_dev_nid(__entry),
+   __entry->name,
+   __entry->flags)
+);
+
+TRACE_EVENT(erofs_fill_inode,
+   TP_PROTO(struct inode *inode, int isdir),
+   TP_ARGS(inode, isdir),
+
+   TP_STRUCT__entry(
+   __field(dev_t,  dev )
+   __field(erofs_nid_t,nid )
+   __field(erofs_blk_t,blkaddr )
+   __field(unsigned int,   ofs )
+   __field(int,isdir   )
+   ),
+
+   TP_fast_assign(
+   __entry->dev= inode->i_sb->s_dev;
+   __entry->nid= EROFS_V(inode)->nid;
+   

[PATCH 11/25] staging: erofs: introduce error injection infrastructure

2018-07-26 Thread Gao Xiang
From: Chao Yu 

This patch introduces error injection infrastructure, with it, we can
inject error in any kernel exported common functions which erofs used,
so that it can force erofs running into error paths, it turns out that
tests can cover real rare paths more easily to find bugs.

Reviewed-by: Gao Xiang 
Signed-off-by: Chao Yu 
---
 drivers/staging/erofs/Kconfig|  6 +
 drivers/staging/erofs/inode.c|  3 ++-
 drivers/staging/erofs/internal.h | 57 
 drivers/staging/erofs/super.c| 38 +++
 4 files changed, 103 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/erofs/Kconfig b/drivers/staging/erofs/Kconfig
index 1a5ec1b..edda055 100644
--- a/drivers/staging/erofs/Kconfig
+++ b/drivers/staging/erofs/Kconfig
@@ -71,3 +71,9 @@ config EROFS_FS_USE_VM_MAP_RAM
 
  If you don't know what these are, say N.
 
+config EROFS_FAULT_INJECTION
+   bool "EROFS fault injection facility"
+   depends on EROFS_FS
+   help
+ Test EROFS to inject faults such as ENOMEM, EIO, and so on.
+ If unsure, say N.
diff --git a/drivers/staging/erofs/inode.c b/drivers/staging/erofs/inode.c
index c011811..a6d3e12 100644
--- a/drivers/staging/erofs/inode.c
+++ b/drivers/staging/erofs/inode.c
@@ -113,6 +113,7 @@ static int read_inode(struct inode *inode, void *data)
 static int fill_inline_data(struct inode *inode, void *data, unsigned m_pofs)
 {
struct erofs_vnode *vi = EROFS_V(inode);
+   struct erofs_sb_info *sbi = EROFS_I_SB(inode);
int mode = vi->data_mapping_mode;
 
DBG_BUGON(mode >= EROFS_INODE_LAYOUT_MAX);
@@ -123,7 +124,7 @@ static int fill_inline_data(struct inode *inode, void 
*data, unsigned m_pofs)
 
/* fast symlink (following ext4) */
if (S_ISLNK(inode->i_mode) && inode->i_size < PAGE_SIZE) {
-   char *lnk = kmalloc(inode->i_size + 1, GFP_KERNEL);
+   char *lnk = erofs_kmalloc(sbi, inode->i_size + 1, GFP_KERNEL);
 
if (unlikely(lnk == NULL))
return -ENOMEM;
diff --git a/drivers/staging/erofs/internal.h b/drivers/staging/erofs/internal.h
index 5862705..ca22486 100644
--- a/drivers/staging/erofs/internal.h
+++ b/drivers/staging/erofs/internal.h
@@ -42,6 +42,22 @@
 #define DBG_BUGON(...)  ((void)0)
 #endif
 
+#ifdef CONFIG_EROFS_FAULT_INJECTION
+enum {
+   FAULT_KMALLOC,
+   FAULT_MAX,
+};
+
+extern char *erofs_fault_name[FAULT_MAX];
+#define IS_FAULT_SET(fi, type) ((fi)->inject_type & (1 << (type)))
+
+struct erofs_fault_info {
+   atomic_t inject_ops;
+   unsigned int inject_rate;
+   unsigned int inject_type;
+};
+#endif
+
 /* EROFS_SUPER_MAGIC_V1 to represent the whole file system */
 #define EROFS_SUPER_MAGIC   EROFS_SUPER_MAGIC_V1
 
@@ -70,14 +86,55 @@ struct erofs_sb_info {
char *dev_name;
 
unsigned int mount_opt;
+
+#ifdef CONFIG_EROFS_FAULT_INJECTION
+   struct erofs_fault_info fault_info; /* For fault injection */
+#endif
 };
 
+#ifdef CONFIG_EROFS_FAULT_INJECTION
+#define erofs_show_injection_info(type)
\
+   infoln("inject %s in %s of %pS", erofs_fault_name[type],\
+   __func__, __builtin_return_address(0))
+
+static inline bool time_to_inject(struct erofs_sb_info *sbi, int type)
+{
+   struct erofs_fault_info *ffi = >fault_info;
+
+   if (!ffi->inject_rate)
+   return false;
+
+   if (!IS_FAULT_SET(ffi, type))
+   return false;
+
+   atomic_inc(>inject_ops);
+   if (atomic_read(>inject_ops) >= ffi->inject_rate) {
+   atomic_set(>inject_ops, 0);
+   return true;
+   }
+   return false;
+}
+#endif
+
+static inline void *erofs_kmalloc(struct erofs_sb_info *sbi,
+   size_t size, gfp_t flags)
+{
+#ifdef CONFIG_EROFS_FAULT_INJECTION
+   if (time_to_inject(sbi, FAULT_KMALLOC)) {
+   erofs_show_injection_info(FAULT_KMALLOC);
+   return NULL;
+   }
+#endif
+   return kmalloc(size, flags);
+}
+
 #define EROFS_SB(sb) ((struct erofs_sb_info *)(sb)->s_fs_info)
 #define EROFS_I_SB(inode) ((struct erofs_sb_info *)(inode)->i_sb->s_fs_info)
 
 /* Mount flags set via mount options or defaults */
 #define EROFS_MOUNT_XATTR_USER 0x0010
 #define EROFS_MOUNT_POSIX_ACL  0x0020
+#define EROFS_MOUNT_FAULT_INJECTION0x0040
 
 #define clear_opt(sbi, option) ((sbi)->mount_opt &= ~EROFS_MOUNT_##option)
 #define set_opt(sbi, option)   ((sbi)->mount_opt |= EROFS_MOUNT_##option)
diff --git a/drivers/staging/erofs/super.c b/drivers/staging/erofs/super.c
index 4a8a266..701425f 100644
--- a/drivers/staging/erofs/super.c
+++ b/drivers/staging/erofs/super.c
@@ -129,6 +129,26 @@ static int superblock_read(struct super_block *sb)
return ret;
 }
 
+#ifdef CONFIG_EROFS_FAULT_INJECTION
+char *erofs_fault_name[FAULT_MAX] = {
+   

[PATCH 14/25] staging: erofs: introduce pagevec for unzip subsystem

2018-07-26 Thread Gao Xiang
For each compressed cluster, there is a straight-forward
way of allocating a fixed or variable-sized (for VLE) array
to record the corresponding file pages for its decompression
if we decide to decompress these pages asynchronously (eg.
read-ahead case), however it could take much extra on-heap
memory compared with traditional uncompressed filesystems.

This patch introduces a pagevec solution to reuse some
allocated file page in the time-sharing approach storing
parts of the array itself in order to minimize the extra
memory overhead, thus only a constant and small-sized array
used for booting the whole array itself up will be needed.

Signed-off-by: Gao Xiang 
---
 drivers/staging/erofs/unzip_pagevec.h | 172 ++
 1 file changed, 172 insertions(+)
 create mode 100644 drivers/staging/erofs/unzip_pagevec.h

diff --git a/drivers/staging/erofs/unzip_pagevec.h 
b/drivers/staging/erofs/unzip_pagevec.h
new file mode 100644
index 000..0956615
--- /dev/null
+++ b/drivers/staging/erofs/unzip_pagevec.h
@@ -0,0 +1,172 @@
+/* SPDX-License-Identifier: GPL-2.0
+ *
+ * linux/drivers/staging/erofs/unzip_pagevec.h
+ *
+ * Copyright (C) 2018 HUAWEI, Inc.
+ * http://www.huawei.com/
+ * Created by Gao Xiang 
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file COPYING in the main directory of the Linux
+ * distribution for more details.
+ */
+#ifndef __EROFS_UNZIP_PAGEVEC_H
+#define __EROFS_UNZIP_PAGEVEC_H
+
+#include 
+
+/* page type in pagevec for unzip subsystem */
+enum z_erofs_page_type {
+   /* including Z_EROFS_VLE_PAGE_TAIL_EXCLUSIVE */
+   Z_EROFS_PAGE_TYPE_EXCLUSIVE,
+
+   Z_EROFS_VLE_PAGE_TYPE_TAIL_SHARED,
+
+   Z_EROFS_VLE_PAGE_TYPE_HEAD,
+   Z_EROFS_VLE_PAGE_TYPE_MAX
+};
+
+extern void __compiletime_error("Z_EROFS_PAGE_TYPE_EXCLUSIVE != 0")
+   __bad_page_type_exclusive(void);
+
+/* pagevec tagged pointer */
+typedef tagptr2_t  erofs_vtptr_t;
+
+/* pagevec collector */
+struct z_erofs_pagevec_ctor {
+   struct page *curr, *next;
+   erofs_vtptr_t *pages;
+
+   unsigned int nr, index;
+};
+
+static inline void z_erofs_pagevec_ctor_exit(struct z_erofs_pagevec_ctor *ctor,
+bool atomic)
+{
+   if (ctor->curr == NULL)
+   return;
+
+   if (atomic)
+   kunmap_atomic(ctor->pages);
+   else
+   kunmap(ctor->curr);
+}
+
+static inline struct page *
+z_erofs_pagevec_ctor_next_page(struct z_erofs_pagevec_ctor *ctor,
+  unsigned nr)
+{
+   unsigned index;
+
+   /* keep away from occupied pages */
+   if (ctor->next != NULL)
+   return ctor->next;
+
+   for (index = 0; index < nr; ++index) {
+   const erofs_vtptr_t t = ctor->pages[index];
+   const unsigned tags = tagptr_unfold_tags(t);
+
+   if (tags == Z_EROFS_PAGE_TYPE_EXCLUSIVE)
+   return tagptr_unfold_ptr(t);
+   }
+
+   if (unlikely(nr >= ctor->nr))
+   BUG();
+
+   return NULL;
+}
+
+static inline void
+z_erofs_pagevec_ctor_pagedown(struct z_erofs_pagevec_ctor *ctor,
+ bool atomic)
+{
+   struct page *next = z_erofs_pagevec_ctor_next_page(ctor, ctor->nr);
+
+   z_erofs_pagevec_ctor_exit(ctor, atomic);
+
+   ctor->curr = next;
+   ctor->next = NULL;
+   ctor->pages = atomic ?
+   kmap_atomic(ctor->curr) : kmap(ctor->curr);
+
+   ctor->nr = PAGE_SIZE / sizeof(struct page *);
+   ctor->index = 0;
+}
+
+static inline void z_erofs_pagevec_ctor_init(struct z_erofs_pagevec_ctor *ctor,
+unsigned nr,
+erofs_vtptr_t *pages, unsigned i)
+{
+   ctor->nr = nr;
+   ctor->curr = ctor->next = NULL;
+   ctor->pages = pages;
+
+   if (i >= nr) {
+   i -= nr;
+   z_erofs_pagevec_ctor_pagedown(ctor, false);
+   while (i > ctor->nr) {
+   i -= ctor->nr;
+   z_erofs_pagevec_ctor_pagedown(ctor, false);
+   }
+   }
+
+   ctor->next = z_erofs_pagevec_ctor_next_page(ctor, i);
+   ctor->index = i;
+}
+
+static inline bool
+z_erofs_pagevec_ctor_enqueue(struct z_erofs_pagevec_ctor *ctor,
+struct page *page,
+enum z_erofs_page_type type,
+bool *occupied)
+{
+   *occupied = false;
+   if (unlikely(ctor->next == NULL && type))
+   if (ctor->index + 1 == ctor->nr)
+   return false;
+
+   if (unlikely(ctor->index >= ctor->nr))
+   z_erofs_pagevec_ctor_pagedown(ctor, false);
+
+   /* exclusive page type must be 0 */
+   if (Z_EROFS_PAGE_TYPE_EXCLUSIVE != (uintptr_t)NULL)
+   __bad_page_type_exclusive();
+
+   

[PATCH 10/25] staging: erofs: support special inode

2018-07-26 Thread Gao Xiang
From: Chao Yu 

This patch adds to support special inode, such as block dev, char,
socket, pipe inode.

Reviewed-by: Gao Xiang 
Signed-off-by: Chao Yu 
---
 drivers/staging/erofs/inode.c| 36 ++--
 drivers/staging/erofs/internal.h |  1 +
 2 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/erofs/inode.c b/drivers/staging/erofs/inode.c
index 15ed919..c011811 100644
--- a/drivers/staging/erofs/inode.c
+++ b/drivers/staging/erofs/inode.c
@@ -34,8 +34,18 @@ static int read_inode(struct inode *inode, void *data)
vi->inode_isize = sizeof(struct erofs_inode_v2);
vi->xattr_isize = ondisk_xattr_ibody_size(v2->i_xattr_icount);
 
-   vi->raw_blkaddr = le32_to_cpu(v2->i_u.raw_blkaddr);
inode->i_mode = le16_to_cpu(v2->i_mode);
+   if (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
+   S_ISLNK(inode->i_mode)) {
+   vi->raw_blkaddr = le32_to_cpu(v2->i_u.raw_blkaddr);
+   } else if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
+   inode->i_rdev =
+   new_decode_dev(le32_to_cpu(v2->i_u.rdev));
+   } else if (S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) {
+   inode->i_rdev = 0;
+   } else {
+   return -EIO;
+   }
 
i_uid_write(inode, le32_to_cpu(v2->i_uid));
i_gid_write(inode, le32_to_cpu(v2->i_gid));
@@ -54,8 +64,18 @@ static int read_inode(struct inode *inode, void *data)
vi->inode_isize = sizeof(struct erofs_inode_v1);
vi->xattr_isize = ondisk_xattr_ibody_size(v1->i_xattr_icount);
 
-   vi->raw_blkaddr = le32_to_cpu(v1->i_u.raw_blkaddr);
inode->i_mode = le16_to_cpu(v1->i_mode);
+   if (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
+   S_ISLNK(inode->i_mode)) {
+   vi->raw_blkaddr = le32_to_cpu(v1->i_u.raw_blkaddr);
+   } else if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
+   inode->i_rdev =
+   new_decode_dev(le32_to_cpu(v1->i_u.rdev));
+   } else if (S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) {
+   inode->i_rdev = 0;
+   } else {
+   return -EIO;
+   }
 
i_uid_write(inode, le16_to_cpu(v1->i_uid));
i_gid_write(inode, le16_to_cpu(v1->i_gid));
@@ -173,6 +193,12 @@ static int fill_inode(struct inode *inode, int isdir)
_symlink_inode_operations;
 #endif
inode_nohighmem(inode);
+   } else if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) ||
+   S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) {
+#ifdef CONFIG_EROFS_FS_XATTR
+   inode->i_op = _special_inode_operations;
+#endif
+   init_special_inode(inode, inode->i_mode, inode->i_rdev);
} else {
err = -EIO;
goto out_unlock;
@@ -232,6 +258,12 @@ struct inode *erofs_iget(struct super_block *sb,
 };
 #endif
 
+const struct inode_operations erofs_special_inode_operations = {
+#ifdef CONFIG_EROFS_FS_XATTR
+   .listxattr = erofs_listxattr,
+#endif
+};
+
 #ifdef CONFIG_EROFS_FS_XATTR
 const struct inode_operations erofs_fast_symlink_xattr_iops = {
.get_link = simple_get_link,
diff --git a/drivers/staging/erofs/internal.h b/drivers/staging/erofs/internal.h
index 8a8caf0..5862705 100644
--- a/drivers/staging/erofs/internal.h
+++ b/drivers/staging/erofs/internal.h
@@ -252,6 +252,7 @@ int erofs_namei(struct inode *dir, struct qstr *name,
 #ifdef CONFIG_EROFS_FS_XATTR
 extern const struct inode_operations erofs_symlink_xattr_iops;
 extern const struct inode_operations erofs_fast_symlink_xattr_iops;
+extern const struct inode_operations erofs_special_inode_operations;
 #endif
 
 static inline void set_inode_fast_symlink(struct inode *inode)
-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 06/25] staging: erofs: add directory operations

2018-07-26 Thread Gao Xiang
This adds functions for directory, mainly readdir.

Signed-off-by: Miao Xie 
Signed-off-by: Chao Yu 
Signed-off-by: Gao Xiang 
---
 drivers/staging/erofs/dir.c | 145 
 1 file changed, 145 insertions(+)
 create mode 100644 drivers/staging/erofs/dir.c

diff --git a/drivers/staging/erofs/dir.c b/drivers/staging/erofs/dir.c
new file mode 100644
index 000..be6ae3b
--- /dev/null
+++ b/drivers/staging/erofs/dir.c
@@ -0,0 +1,145 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * linux/drivers/staging/erofs/dir.c
+ *
+ * Copyright (C) 2017-2018 HUAWEI, Inc.
+ * http://www.huawei.com/
+ * Created by Gao Xiang 
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file COPYING in the main directory of the Linux
+ * distribution for more details.
+ */
+#include "internal.h"
+
+static const unsigned char erofs_filetype_table[EROFS_FT_MAX] = {
+   [EROFS_FT_UNKNOWN]  = DT_UNKNOWN,
+   [EROFS_FT_REG_FILE] = DT_REG,
+   [EROFS_FT_DIR]  = DT_DIR,
+   [EROFS_FT_CHRDEV]   = DT_CHR,
+   [EROFS_FT_BLKDEV]   = DT_BLK,
+   [EROFS_FT_FIFO] = DT_FIFO,
+   [EROFS_FT_SOCK] = DT_SOCK,
+   [EROFS_FT_SYMLINK]  = DT_LNK,
+};
+
+static int erofs_fill_dentries(struct dir_context *ctx,
+   void *dentry_blk, unsigned *ofs,
+   unsigned nameoff, unsigned maxsize)
+{
+   struct erofs_dirent *de = dentry_blk;
+   const struct erofs_dirent *end = dentry_blk + nameoff;
+
+   de = dentry_blk + *ofs;
+   while (de < end) {
+   const char *de_name;
+   int de_namelen;
+   unsigned char d_type;
+#ifdef CONFIG_EROFS_FS_DEBUG
+   unsigned dbg_namelen;
+   unsigned char dbg_namebuf[EROFS_NAME_LEN];
+#endif
+
+   if (unlikely(de->file_type < EROFS_FT_MAX))
+   d_type = erofs_filetype_table[de->file_type];
+   else
+   d_type = DT_UNKNOWN;
+
+   nameoff = le16_to_cpu(de->nameoff);
+   de_name = (char *)dentry_blk + nameoff;
+
+   de_namelen = unlikely(de + 1 >= end) ?
+   /* last directory entry */
+   strnlen(de_name, maxsize - nameoff) :
+   le16_to_cpu(de[1].nameoff) - nameoff;
+
+   /* the corrupted directory found */
+   BUG_ON(de_namelen < 0);
+
+#ifdef CONFIG_EROFS_FS_DEBUG
+   dbg_namelen = min(EROFS_NAME_LEN - 1, de_namelen);
+   memcpy(dbg_namebuf, de_name, dbg_namelen);
+   dbg_namebuf[dbg_namelen] = '\0';
+
+   debugln("%s, found de_name %s de_len %d d_type %d", __func__,
+   dbg_namebuf, de_namelen, d_type);
+#endif
+
+   if (!dir_emit(ctx, de_name, de_namelen,
+   le64_to_cpu(de->nid), d_type))
+   /* stoped by some reason */
+   return 1;
+   ++de;
+   *ofs += sizeof(struct erofs_dirent);
+   }
+   *ofs = maxsize;
+   return 0;
+}
+
+static int erofs_readdir(struct file *f, struct dir_context *ctx)
+{
+   struct inode *dir = file_inode(f);
+   struct address_space *mapping = dir->i_mapping;
+   const size_t dirsize = i_size_read(dir);
+   unsigned i = ctx->pos / EROFS_BLKSIZ;
+   unsigned ofs = ctx->pos % EROFS_BLKSIZ;
+   int err = 0;
+   bool initial = true;
+
+   while (ctx->pos < dirsize) {
+   struct page *dentry_page;
+   struct erofs_dirent *de;
+   unsigned nameoff, maxsize;
+
+   dentry_page = read_mapping_page(mapping, i, NULL);
+   if (IS_ERR(dentry_page))
+   continue;
+
+   lock_page(dentry_page);
+   de = (struct erofs_dirent *)kmap(dentry_page);
+
+   nameoff = le16_to_cpu(de->nameoff);
+
+   if (unlikely(nameoff < sizeof(struct erofs_dirent) ||
+   nameoff >= PAGE_SIZE)) {
+   errln("%s, invalid de[0].nameoff %u",
+   __func__, nameoff);
+
+   err = -EIO;
+   goto skip_this;
+   }
+
+   maxsize = min_t(unsigned, dirsize - ctx->pos + ofs, PAGE_SIZE);
+
+   /* search dirents at the arbitrary position */
+   if (unlikely(initial)) {
+   initial = false;
+
+   ofs = roundup(ofs, sizeof(struct erofs_dirent));
+   if (unlikely(ofs >= nameoff))
+   goto skip_this;
+   }
+
+   err = erofs_fill_dentries(ctx, de, , nameoff, maxsize);
+skip_this:
+   kunmap(dentry_page);
+
+   unlock_page(dentry_page);
+   put_page(dentry_page);
+
+   

[PATCH 09/25] staging: erofs: introduce xattr & acl support

2018-07-26 Thread Gao Xiang
This implements xattr and acl functionalities.

Inline and shared xattrs are introduced for flexibility.
Specifically, if the same xattr occurs for many times
in a large number of inodes or the value of a xattr is so large
that it isn't suitable to be inlined, a shared xattr
kept in the xattr meta will be used instead.

Signed-off-by: Miao Xie 
Signed-off-by: Chao Yu 
Signed-off-by: Gao Xiang 
---
 drivers/staging/erofs/Kconfig|  37 +++
 drivers/staging/erofs/Makefile   |   1 +
 drivers/staging/erofs/inode.c|  33 ++-
 drivers/staging/erofs/internal.h |  22 ++
 drivers/staging/erofs/namei.c|   4 +
 drivers/staging/erofs/super.c|  67 +
 drivers/staging/erofs/xattr.c| 579 +++
 drivers/staging/erofs/xattr.h|  93 +++
 8 files changed, 835 insertions(+), 1 deletion(-)
 create mode 100644 drivers/staging/erofs/xattr.c
 create mode 100644 drivers/staging/erofs/xattr.h

diff --git a/drivers/staging/erofs/Kconfig b/drivers/staging/erofs/Kconfig
index 077430f..1a5ec1b 100644
--- a/drivers/staging/erofs/Kconfig
+++ b/drivers/staging/erofs/Kconfig
@@ -26,6 +26,43 @@ config EROFS_FS_DEBUG
 
  For daily use, say N.
 
+config EROFS_FS_XATTR
+   bool "EROFS extended attributes"
+   depends on EROFS_FS
+   default y
+   help
+ Extended attributes are name:value pairs associated with inodes by
+ the kernel or by users (see the attr(5) manual page, or visit
+  for details).
+
+ If unsure, say N.
+
+config EROFS_FS_POSIX_ACL
+   bool "EROFS Access Control Lists"
+   depends on EROFS_FS_XATTR
+   select FS_POSIX_ACL
+   default y
+   help
+ Posix Access Control Lists (ACLs) support permissions for users and
+ groups beyond the owner/group/world scheme.
+
+ To learn more about Access Control Lists, visit the POSIX ACLs for
+ Linux website .
+
+ If you don't know what Access Control Lists are, say N.
+
+config EROFS_FS_SECURITY
+   bool "EROFS Security Labels"
+   depends on EROFS_FS_XATTR
+   help
+ Security labels provide an access control facility to support Linux
+ Security Models (LSMs) accepted by AppArmor, SELinux, Smack and TOMOYO
+ Linux. This option enables an extended attribute handler for file
+ security labels in the erofs filesystem, so that it requires enabling
+ the extended attribute support in advance.
+
+ If you are not using a security module, say N.
+
 config EROFS_FS_USE_VM_MAP_RAM
bool "EROFS VM_MAP_RAM Support"
depends on EROFS_FS
diff --git a/drivers/staging/erofs/Makefile b/drivers/staging/erofs/Makefile
index 31e909e..977b7e0 100644
--- a/drivers/staging/erofs/Makefile
+++ b/drivers/staging/erofs/Makefile
@@ -8,4 +8,5 @@ obj-$(CONFIG_EROFS_FS) += erofs.o
 # staging requirement: to be self-contained in its own directory
 ccflags-y += -I$(src)/include
 erofs-objs := super.o inode.o data.o namei.o dir.o
+erofs-$(CONFIG_EROFS_FS_XATTR) += xattr.o
 
diff --git a/drivers/staging/erofs/inode.c b/drivers/staging/erofs/inode.c
index 74e65be..15ed919 100644
--- a/drivers/staging/erofs/inode.c
+++ b/drivers/staging/erofs/inode.c
@@ -10,7 +10,7 @@
  * License.  See the file COPYING in the main directory of the Linux
  * distribution for more details.
  */
-#include "internal.h"
+#include "xattr.h"
 
 /* no locking */
 static int read_inode(struct inode *inode, void *data)
@@ -152,15 +152,26 @@ static int fill_inode(struct inode *inode, int isdir)
if (!err) {
/* setup the new inode */
if (S_ISREG(inode->i_mode)) {
+#ifdef CONFIG_EROFS_FS_XATTR
+   if (vi->xattr_isize)
+   inode->i_op = _generic_xattr_iops;
+#endif
inode->i_fop = _ro_fops;
} else if (S_ISDIR(inode->i_mode)) {
inode->i_op =
+#ifdef CONFIG_EROFS_FS_XATTR
+   vi->xattr_isize ? _dir_xattr_iops :
+#endif
_dir_iops;
inode->i_fop = _dir_fops;
} else if (S_ISLNK(inode->i_mode)) {
/* by default, page_get_link is used for symlink */
inode->i_op =
+#ifdef CONFIG_EROFS_FS_XATTR
+   _symlink_xattr_iops,
+#else
_symlink_inode_operations;
+#endif
inode_nohighmem(inode);
} else {
err = -EIO;
@@ -208,3 +219,23 @@ struct inode *erofs_iget(struct super_block *sb,
return inode;
 }
 
+#ifdef CONFIG_EROFS_FS_XATTR
+const struct inode_operations erofs_generic_xattr_iops = {
+   .listxattr = erofs_listxattr,
+};
+#endif
+
+#ifdef CONFIG_EROFS_FS_XATTR
+const struct inode_operations erofs_symlink_xattr_iops = {
+   .get_link = 

[PATCH 08/25] staging: erofs: update Kconfig and Makefile

2018-07-26 Thread Gao Xiang
This commit adds Makefile and Kconfig for erofs, and
updates Makefile and Kconfig files in the fs directory.

Signed-off-by: Miao Xie 
Signed-off-by: Chao Yu 
Signed-off-by: Gao Xiang 
---
 drivers/staging/Kconfig|  2 ++
 drivers/staging/Makefile   |  1 +
 drivers/staging/erofs/Kconfig  | 36 
 drivers/staging/erofs/Makefile | 11 +++
 4 files changed, 50 insertions(+)
 create mode 100644 drivers/staging/erofs/Kconfig
 create mode 100644 drivers/staging/erofs/Makefile

diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig
index 75a4804..de9c95a 100644
--- a/drivers/staging/Kconfig
+++ b/drivers/staging/Kconfig
@@ -126,4 +126,6 @@ source "drivers/staging/mt7621-eth/Kconfig"
 
 source "drivers/staging/mt7621-dts/Kconfig"
 
+source "drivers/staging/erofs/Kconfig"
+
 endif # STAGING
diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile
index e84959a..a33ac34 100644
--- a/drivers/staging/Makefile
+++ b/drivers/staging/Makefile
@@ -54,3 +54,4 @@ obj-$(CONFIG_SOC_MT7621)  += mt7621-dma/
 obj-$(CONFIG_SOC_MT7621)   += mt7621-mmc/
 obj-$(CONFIG_SOC_MT7621)   += mt7621-eth/
 obj-$(CONFIG_SOC_MT7621)   += mt7621-dts/
+obj-$(CONFIG_EROFS_FS) += erofs/
diff --git a/drivers/staging/erofs/Kconfig b/drivers/staging/erofs/Kconfig
new file mode 100644
index 000..077430f
--- /dev/null
+++ b/drivers/staging/erofs/Kconfig
@@ -0,0 +1,36 @@
+# SPDX-License-Identifier: GPL-2.0
+
+config EROFS_FS
+   tristate "EROFS filesystem support"
+   depends on BLOCK
+   help
+ EROFS(Enhanced Read-Only File System) is a lightweight
+ read-only file system with modern designs (eg. page-sized
+ blocks, inline xattrs/data, etc.) for scenarios which need
+ high-performance read-only requirements, eg. firmwares in
+ mobile phone or LIVECDs.
+
+ It also provides VLE compression support, focusing on
+ random read improvements, keeping relatively lower
+ compression ratios, which is useful for high-performance
+ devices with limited memory and ROM space.
+
+ If unsure, say N.
+
+config EROFS_FS_DEBUG
+   bool "EROFS debugging feature"
+   depends on EROFS_FS
+   help
+ Print EROFS debugging messages and enable more BUG_ONs
+ which check the filesystem consistency aggressively.
+
+ For daily use, say N.
+
+config EROFS_FS_USE_VM_MAP_RAM
+   bool "EROFS VM_MAP_RAM Support"
+   depends on EROFS_FS
+   help
+ use vm_map_ram/vm_unmap_ram instead of vmap/vunmap.
+
+ If you don't know what these are, say N.
+
diff --git a/drivers/staging/erofs/Makefile b/drivers/staging/erofs/Makefile
new file mode 100644
index 000..31e909e
--- /dev/null
+++ b/drivers/staging/erofs/Makefile
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0
+
+EROFS_VERSION = "1.0pre1"
+
+ccflags-y += -Wall -DEROFS_VERSION=\"$(EROFS_VERSION)\"
+
+obj-$(CONFIG_EROFS_FS) += erofs.o
+# staging requirement: to be self-contained in its own directory
+ccflags-y += -I$(src)/include
+erofs-objs := super.o inode.o data.o namei.o dir.o
+
-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 03/25] staging: erofs: add super block operations

2018-07-26 Thread Gao Xiang
This commit adds erofs super block operations, including (u)mount,
remount_fs, show_options, statfs, in addition to some private
icache management functions.

Signed-off-by: Miao Xie 
Signed-off-by: Chao Yu 
Signed-off-by: Gao Xiang 
---
 drivers/staging/erofs/super.c | 415 ++
 1 file changed, 415 insertions(+)
 create mode 100644 drivers/staging/erofs/super.c

diff --git a/drivers/staging/erofs/super.c b/drivers/staging/erofs/super.c
new file mode 100644
index 000..98ae03d
--- /dev/null
+++ b/drivers/staging/erofs/super.c
@@ -0,0 +1,415 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * linux/drivers/staging/erofs/super.c
+ *
+ * Copyright (C) 2017-2018 HUAWEI, Inc.
+ * http://www.huawei.com/
+ * Created by Gao Xiang 
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file COPYING in the main directory of the Linux
+ * distribution for more details.
+ */
+#include 
+#include 
+#include 
+#include 
+#include "internal.h"
+
+static struct kmem_cache *erofs_inode_cachep __read_mostly;
+
+static void init_once(void *ptr)
+{
+   struct erofs_vnode *vi = ptr;
+
+   inode_init_once(>vfs_inode);
+}
+
+static int erofs_init_inode_cache(void)
+{
+   erofs_inode_cachep = kmem_cache_create("erofs_inode",
+   sizeof(struct erofs_vnode), 0,
+   SLAB_RECLAIM_ACCOUNT, init_once);
+
+   return erofs_inode_cachep != NULL ? 0 : -ENOMEM;
+}
+
+static void erofs_exit_inode_cache(void)
+{
+   BUG_ON(erofs_inode_cachep == NULL);
+   kmem_cache_destroy(erofs_inode_cachep);
+}
+
+static struct inode *alloc_inode(struct super_block *sb)
+{
+   struct erofs_vnode *vi =
+   kmem_cache_alloc(erofs_inode_cachep, GFP_KERNEL);
+
+   if (vi == NULL)
+   return NULL;
+
+   /* zero out everything except vfs_inode */
+   memset(vi, 0, offsetof(struct erofs_vnode, vfs_inode));
+   return >vfs_inode;
+}
+
+static void i_callback(struct rcu_head *head)
+{
+   struct inode *inode = container_of(head, struct inode, i_rcu);
+   struct erofs_vnode *vi = EROFS_V(inode);
+
+   /* be careful RCU symlink path (see ext4_inode_info->i_data)! */
+   if (is_inode_fast_symlink(inode))
+   kfree(inode->i_link);
+
+   kfree(vi->xattr_shared_xattrs);
+
+   kmem_cache_free(erofs_inode_cachep, vi);
+}
+
+static void destroy_inode(struct inode *inode)
+{
+   call_rcu(>i_rcu, i_callback);
+}
+
+static int superblock_read(struct super_block *sb)
+{
+   struct erofs_sb_info *sbi;
+   struct buffer_head *bh;
+   struct erofs_super_block *layout;
+   unsigned blkszbits;
+   int ret;
+
+   bh = sb_bread(sb, 0);
+
+   if (bh == NULL) {
+   errln("cannot read erofs superblock");
+   return -EIO;
+   }
+
+   sbi = EROFS_SB(sb);
+   layout = (struct erofs_super_block *)((u8 *)bh->b_data
++ EROFS_SUPER_OFFSET);
+
+   ret = -EINVAL;
+   if (le32_to_cpu(layout->magic) != EROFS_SUPER_MAGIC_V1) {
+   errln("cannot find valid erofs superblock");
+   goto out;
+   }
+
+   blkszbits = layout->blkszbits;
+   /* 9(512 bytes) + LOG_SECTORS_PER_BLOCK == LOG_BLOCK_SIZE */
+   if (unlikely(blkszbits != LOG_BLOCK_SIZE)) {
+   errln("blksize %u isn't supported on this platform",
+   1 << blkszbits);
+   goto out;
+   }
+
+   sbi->blocks = le32_to_cpu(layout->blocks);
+   sbi->meta_blkaddr = le32_to_cpu(layout->meta_blkaddr);
+   sbi->islotbits = ffs(sizeof(struct erofs_inode_v1)) - 1;
+
+   sbi->root_nid = le16_to_cpu(layout->root_nid);
+   sbi->inos = le64_to_cpu(layout->inos);
+
+   sbi->build_time = le64_to_cpu(layout->build_time);
+   sbi->build_time_nsec = le32_to_cpu(layout->build_time_nsec);
+
+   memcpy(>s_uuid, layout->uuid, sizeof(layout->uuid));
+   memcpy(sbi->volume_name, layout->volume_name,
+   sizeof(layout->volume_name));
+
+   ret = 0;
+out:
+   brelse(bh);
+   return ret;
+}
+
+static void default_options(struct erofs_sb_info *sbi)
+{
+}
+
+enum {
+   Opt_err
+};
+
+static match_table_t erofs_tokens = {
+   {Opt_err, NULL}
+};
+
+static int parse_options(struct super_block *sb, char *options)
+{
+   substring_t args[MAX_OPT_ARGS];
+   char *p;
+
+   if (!options)
+   return 0;
+
+   while ((p = strsep(, ",")) != NULL) {
+   int token;
+
+   if (!*p)
+   continue;
+
+   args[0].to = args[0].from = NULL;
+   token = match_token(p, erofs_tokens, args);
+
+   switch (token) {
+   default:
+   errln("Unrecognized mount option \"%s\" "
+   "or missing value", p);
+   return -EINVAL;
+   }
+   

[PATCH 04/25] staging: erofs: add raw address_space operations

2018-07-26 Thread Gao Xiang
This commit adds functions for meta and raw data, and also
provides address_space_operations for raw data access.

Signed-off-by: Miao Xie 
Signed-off-by: Chao Yu 
Signed-off-by: Gao Xiang 
---
 drivers/staging/erofs/data.c | 362 +++
 1 file changed, 362 insertions(+)
 create mode 100644 drivers/staging/erofs/data.c

diff --git a/drivers/staging/erofs/data.c b/drivers/staging/erofs/data.c
new file mode 100644
index 000..4ddb5c0
--- /dev/null
+++ b/drivers/staging/erofs/data.c
@@ -0,0 +1,362 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * linux/drivers/staging/erofs/data.c
+ *
+ * Copyright (C) 2017-2018 HUAWEI, Inc.
+ * http://www.huawei.com/
+ * Created by Gao Xiang 
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file COPYING in the main directory of the Linux
+ * distribution for more details.
+ */
+#include "internal.h"
+#include 
+
+static inline void read_endio(struct bio *bio)
+{
+   int i;
+   struct bio_vec *bvec;
+   const blk_status_t err = bio->bi_status;
+
+   bio_for_each_segment_all(bvec, bio, i) {
+   struct page *page = bvec->bv_page;
+
+   /* page is already locked */
+   BUG_ON(PageUptodate(page));
+
+   if (unlikely(err))
+   SetPageError(page);
+   else
+   SetPageUptodate(page);
+
+   unlock_page(page);
+   /* page could be reclaimed now */
+   }
+   bio_put(bio);
+}
+
+static void __submit_bio(struct bio *bio, unsigned op, unsigned op_flags)
+{
+   bio_set_op_attrs(bio, op, op_flags);
+   submit_bio(bio);
+}
+
+static struct bio *prepare_bio(struct super_block *sb,
+   erofs_blk_t blkaddr, unsigned nr_pages)
+{
+   struct bio *bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, nr_pages);
+
+   BUG_ON(bio == NULL);
+
+   bio->bi_end_io = read_endio;
+   bio_set_dev(bio, sb->s_bdev);
+   bio->bi_iter.bi_sector = blkaddr << LOG_SECTORS_PER_BLOCK;
+
+   return bio;
+}
+
+/* prio -- true is used for dir */
+struct page *erofs_get_meta_page(struct super_block *sb,
+   erofs_blk_t blkaddr, bool prio)
+{
+   struct inode *bd_inode = sb->s_bdev->bd_inode;
+   struct address_space *mapping = bd_inode->i_mapping;
+   struct page *page;
+
+repeat:
+   page = find_or_create_page(mapping, blkaddr,
+   /*
+* Prefer looping in the allocator rather than here,
+* at least that code knows what it's doing.
+*/
+   mapping_gfp_constraint(mapping, ~__GFP_FS) | __GFP_NOFAIL);
+
+   BUG_ON(!page || !PageLocked(page));
+
+   if (!PageUptodate(page)) {
+   struct bio *bio;
+   int err;
+
+   bio = prepare_bio(sb, blkaddr, 1);
+   err = bio_add_page(bio, page, PAGE_SIZE, 0);
+   BUG_ON(err != PAGE_SIZE);
+
+   __submit_bio(bio, REQ_OP_READ,
+   REQ_META | (prio ? REQ_PRIO : 0));
+
+   lock_page(page);
+
+   /* the page has been truncated by others? */
+   if (unlikely(page->mapping != mapping)) {
+   unlock_page(page);
+   put_page(page);
+   goto repeat;
+   }
+
+   /* more likely a read error */
+   if (unlikely(!PageUptodate(page))) {
+   unlock_page(page);
+   put_page(page);
+
+   page = ERR_PTR(-EIO);
+   }
+   }
+   return page;
+}
+
+static int erofs_map_blocks_flatmode(struct inode *inode,
+   struct erofs_map_blocks *map,
+   int flags)
+{
+   erofs_blk_t nblocks, lastblk;
+   u64 offset = map->m_la;
+   struct erofs_vnode *vi = EROFS_V(inode);
+
+   BUG_ON(is_inode_layout_compression(inode));
+
+   nblocks = DIV_ROUND_UP(inode->i_size, PAGE_SIZE);
+   lastblk = nblocks - is_inode_layout_inline(inode);
+
+   if (unlikely(offset >= inode->i_size)) {
+   /* leave out-of-bound access unmapped */
+   map->m_flags = 0;
+   map->m_plen = 0;
+   goto out;
+   }
+
+   /* there is no hole in flatmode */
+   map->m_flags = EROFS_MAP_MAPPED;
+
+   if (offset < blknr_to_addr(lastblk)) {
+   map->m_pa = blknr_to_addr(vi->raw_blkaddr) + map->m_la;
+   map->m_plen = blknr_to_addr(lastblk) - offset;
+   } else if (is_inode_layout_inline(inode)) {
+   /* 2 - inode inline B: inode, [xattrs], inline last blk... */
+   struct erofs_sb_info *sbi = EROFS_SB(inode->i_sb);
+
+   map->m_pa = iloc(sbi, vi->nid) + vi->inode_isize +
+   vi->xattr_isize + erofs_blkoff(map->m_la);
+   map->m_plen = inode->i_size - offset;
+
+   /* inline data should locate in one meta block */
+ 

[PATCH 05/25] staging: erofs: add inode operations

2018-07-26 Thread Gao Xiang
This adds core functions to get, read an inode.

Signed-off-by: Miao Xie 
Signed-off-by: Chao Yu 
Signed-off-by: Gao Xiang 
---
 drivers/staging/erofs/inode.c | 210 ++
 1 file changed, 210 insertions(+)
 create mode 100644 drivers/staging/erofs/inode.c

diff --git a/drivers/staging/erofs/inode.c b/drivers/staging/erofs/inode.c
new file mode 100644
index 000..74e65be
--- /dev/null
+++ b/drivers/staging/erofs/inode.c
@@ -0,0 +1,210 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * linux/drivers/staging/erofs/inode.c
+ *
+ * Copyright (C) 2017-2018 HUAWEI, Inc.
+ * http://www.huawei.com/
+ * Created by Gao Xiang 
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file COPYING in the main directory of the Linux
+ * distribution for more details.
+ */
+#include "internal.h"
+
+/* no locking */
+static int read_inode(struct inode *inode, void *data)
+{
+   struct erofs_vnode *vi = EROFS_V(inode);
+   struct erofs_inode_v1 *v1 = data;
+   const unsigned advise = le16_to_cpu(v1->i_advise);
+
+   vi->data_mapping_mode = __inode_data_mapping(advise);
+
+   if (unlikely(vi->data_mapping_mode >= EROFS_INODE_LAYOUT_MAX)) {
+   errln("unknown data mapping mode %u of nid %llu",
+   vi->data_mapping_mode, vi->nid);
+   DBG_BUGON(1);
+   return -EIO;
+   }
+
+   if (__inode_version(advise) == EROFS_INODE_LAYOUT_V2) {
+   struct erofs_inode_v2 *v2 = data;
+
+   vi->inode_isize = sizeof(struct erofs_inode_v2);
+   vi->xattr_isize = ondisk_xattr_ibody_size(v2->i_xattr_icount);
+
+   vi->raw_blkaddr = le32_to_cpu(v2->i_u.raw_blkaddr);
+   inode->i_mode = le16_to_cpu(v2->i_mode);
+
+   i_uid_write(inode, le32_to_cpu(v2->i_uid));
+   i_gid_write(inode, le32_to_cpu(v2->i_gid));
+   set_nlink(inode, le32_to_cpu(v2->i_nlink));
+
+   /* ns timestamp */
+   inode->i_mtime.tv_sec = inode->i_ctime.tv_sec =
+   le64_to_cpu(v2->i_ctime);
+   inode->i_mtime.tv_nsec = inode->i_ctime.tv_nsec =
+   le32_to_cpu(v2->i_ctime_nsec);
+
+   inode->i_size = le64_to_cpu(v2->i_size);
+   } else if (__inode_version(advise) == EROFS_INODE_LAYOUT_V1) {
+   struct erofs_sb_info *sbi = EROFS_SB(inode->i_sb);
+
+   vi->inode_isize = sizeof(struct erofs_inode_v1);
+   vi->xattr_isize = ondisk_xattr_ibody_size(v1->i_xattr_icount);
+
+   vi->raw_blkaddr = le32_to_cpu(v1->i_u.raw_blkaddr);
+   inode->i_mode = le16_to_cpu(v1->i_mode);
+
+   i_uid_write(inode, le16_to_cpu(v1->i_uid));
+   i_gid_write(inode, le16_to_cpu(v1->i_gid));
+   set_nlink(inode, le16_to_cpu(v1->i_nlink));
+
+   /* use build time to derive all file time */
+   inode->i_mtime.tv_sec = inode->i_ctime.tv_sec =
+   sbi->build_time;
+   inode->i_mtime.tv_nsec = inode->i_ctime.tv_nsec =
+   sbi->build_time_nsec;
+
+   inode->i_size = le32_to_cpu(v1->i_size);
+   } else {
+   errln("unsupported on-disk inode version %u of nid %llu",
+   __inode_version(advise), vi->nid);
+   DBG_BUGON(1);
+   return -EIO;
+   }
+
+   /* measure inode.i_blocks as the generic filesystem */
+   inode->i_blocks = ((inode->i_size - 1) >> 9) + 1;
+   return 0;
+}
+
+/*
+ * try_lock can be required since locking order is:
+ *   file data(fs_inode)
+ *meta(bd_inode)
+ * but the majority of the callers is "iget",
+ * in that case we are pretty sure no deadlock since
+ * no data operations exist. However I tend to
+ * try_lock since it takes no much overhead and
+ * will success immediately.
+ */
+static int fill_inline_data(struct inode *inode, void *data, unsigned m_pofs)
+{
+   struct erofs_vnode *vi = EROFS_V(inode);
+   int mode = vi->data_mapping_mode;
+
+   DBG_BUGON(mode >= EROFS_INODE_LAYOUT_MAX);
+
+   /* should be inode inline C */
+   if (mode != EROFS_INODE_LAYOUT_INLINE)
+   return 0;
+
+   /* fast symlink (following ext4) */
+   if (S_ISLNK(inode->i_mode) && inode->i_size < PAGE_SIZE) {
+   char *lnk = kmalloc(inode->i_size + 1, GFP_KERNEL);
+
+   if (unlikely(lnk == NULL))
+   return -ENOMEM;
+
+   m_pofs += vi->inode_isize + vi->xattr_isize;
+   BUG_ON(m_pofs + inode->i_size > PAGE_SIZE);
+
+   /* get in-page inline data */
+   memcpy(lnk, data + m_pofs, inode->i_size);
+   lnk[inode->i_size] = '\0';
+
+   inode->i_link = lnk;
+   set_inode_fast_symlink(inode);
+   }
+   return -EAGAIN;
+}
+

[PATCH 02/25] staging: erofs: add erofs in-memory stuffs

2018-07-26 Thread Gao Xiang
 - erofs_sb_info:
   contains erofs-specific in-memory information.

 - erofs_vnode:
   contains vfs_inode and other fs-specific information.
   same as super block, the only one in-memory definition exists.

 - erofs_map_blocks
   plays a role in the file L2P mapping

Signed-off-by: Miao Xie 
Signed-off-by: Chao Yu 
Signed-off-by: Gao Xiang 
---
 drivers/staging/erofs/internal.h | 281 +++
 1 file changed, 281 insertions(+)
 create mode 100644 drivers/staging/erofs/internal.h

diff --git a/drivers/staging/erofs/internal.h b/drivers/staging/erofs/internal.h
new file mode 100644
index 000..d0992d2
--- /dev/null
+++ b/drivers/staging/erofs/internal.h
@@ -0,0 +1,281 @@
+/* SPDX-License-Identifier: GPL-2.0
+ *
+ * linux/drivers/staging/erofs/internal.h
+ *
+ * Copyright (C) 2017-2018 HUAWEI, Inc.
+ * http://www.huawei.com/
+ * Created by Gao Xiang 
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file COPYING in the main directory of the Linux
+ * distribution for more details.
+ */
+#ifndef __INTERNAL_H
+#define __INTERNAL_H
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "erofs_fs.h"
+
+/* redefine pr_fmt "erofs: " */
+#undef pr_fmt
+#define pr_fmt(fmt) "erofs: " fmt
+
+#define errln(x, ...)   pr_err(x "\n", ##__VA_ARGS__)
+#define infoln(x, ...)  pr_info(x "\n", ##__VA_ARGS__)
+#ifdef CONFIG_EROFS_FS_DEBUG
+#define debugln(x, ...) pr_debug(x "\n", ##__VA_ARGS__)
+
+#define dbg_might_sleep might_sleep
+#define DBG_BUGON   BUG_ON
+#else
+#define debugln(x, ...) ((void)0)
+
+#define dbg_might_sleep()   ((void)0)
+#define DBG_BUGON(...)  ((void)0)
+#endif
+
+/* EROFS_SUPER_MAGIC_V1 to represent the whole file system */
+#define EROFS_SUPER_MAGIC   EROFS_SUPER_MAGIC_V1
+
+typedef u64 erofs_nid_t;
+
+struct erofs_sb_info {
+   u32 blocks;
+   u32 meta_blkaddr;
+
+   /* inode slot unit size in bit shift */
+   unsigned char islotbits;
+
+   u32 build_time_nsec;
+   u64 build_time;
+
+   /* what we really care is nid, rather than ino.. */
+   erofs_nid_t root_nid;
+   /* used for statfs, f_files - f_favail */
+   u64 inos;
+
+   u8 uuid[16];/* 128-bit uuid for volume */
+   u8 volume_name[16]; /* volume name */
+   char *dev_name;
+
+   unsigned int mount_opt;
+};
+
+#define EROFS_SB(sb) ((struct erofs_sb_info *)(sb)->s_fs_info)
+#define EROFS_I_SB(inode) ((struct erofs_sb_info *)(inode)->i_sb->s_fs_info)
+
+#define clear_opt(sbi, option) ((sbi)->mount_opt &= ~EROFS_MOUNT_##option)
+#define set_opt(sbi, option)   ((sbi)->mount_opt |= EROFS_MOUNT_##option)
+#define test_opt(sbi, option)  ((sbi)->mount_opt & EROFS_MOUNT_##option)
+
+/* we strictly follow PAGE_SIZE and no buffer head yet */
+#define LOG_BLOCK_SIZE PAGE_SHIFT
+
+#undef LOG_SECTORS_PER_BLOCK
+#define LOG_SECTORS_PER_BLOCK  (PAGE_SHIFT - 9)
+
+#undef SECTORS_PER_BLOCK
+#define SECTORS_PER_BLOCK  (1 << SECTORS_PER_BLOCK)
+
+#define EROFS_BLKSIZ   (1 << LOG_BLOCK_SIZE)
+
+#if (EROFS_BLKSIZ % 4096 || !EROFS_BLKSIZ)
+#error erofs cannot be used in this platform
+#endif
+
+#define ROOT_NID(sb)   ((sb)->root_nid)
+
+typedef u64 erofs_off_t;
+
+/* data type for filesystem-wide blocks number */
+typedef u32 erofs_blk_t;
+
+#define erofs_blknr(addr)   ((addr) / EROFS_BLKSIZ)
+#define erofs_blkoff(addr)  ((addr) % EROFS_BLKSIZ)
+#define blknr_to_addr(nr)   ((erofs_off_t)(nr) * EROFS_BLKSIZ)
+
+static inline erofs_off_t iloc(struct erofs_sb_info *sbi, erofs_nid_t nid)
+{
+   return blknr_to_addr(sbi->meta_blkaddr) + (nid << sbi->islotbits);
+}
+
+#define inode_set_inited_xattr(inode)   (EROFS_V(inode)->flags |= 1)
+#define inode_has_inited_xattr(inode)   (EROFS_V(inode)->flags & 1)
+
+struct erofs_vnode {
+   erofs_nid_t nid;
+   unsigned int flags;
+
+   unsigned char data_mapping_mode;
+   /* inline size in bytes */
+   unsigned char inode_isize;
+   unsigned short xattr_isize;
+
+   unsigned xattr_shared_count;
+   unsigned *xattr_shared_xattrs;
+
+   erofs_blk_t raw_blkaddr;
+
+   /* the corresponding vfs inode */
+   struct inode vfs_inode;
+};
+
+#define EROFS_V(ptr)   \
+   container_of(ptr, struct erofs_vnode, vfs_inode)
+
+#define __inode_advise(x, bit, bits) \
+   (((x) >> (bit)) & ((1 << (bits)) - 1))
+
+#define __inode_version(advise)\
+   __inode_advise(advise, EROFS_I_VERSION_BIT, \
+   EROFS_I_VERSION_BITS)
+
+#define __inode_data_mapping(advise)   \
+   __inode_advise(advise, EROFS_I_DATA_MAPPING_BIT,\
+   EROFS_I_DATA_MAPPING_BITS)
+
+static inline unsigned long inode_datablocks(struct inode *inode)
+{
+   /* since i_size cannot be changed */
+   return DIV_ROUND_UP(inode->i_size, EROFS_BLKSIZ);
+}
+
+static 

[PATCH 01/25] staging: erofs: add on-disk layout

2018-07-26 Thread Gao Xiang
This commit adds the on-disk layout header file of erofs.

Note that the on-disk layout is still WIP, and some fields are
reserved for the future use by design.

Any comments are welcome.

Thanks-to: Li Guifu 
Thanks-to: Sun Qiuyang 
Signed-off-by: Miao Xie 
Signed-off-by: Chao Yu 
Signed-off-by: Gao Xiang 
---
 drivers/staging/erofs/erofs_fs.h | 266 +++
 1 file changed, 266 insertions(+)
 create mode 100644 drivers/staging/erofs/erofs_fs.h

diff --git a/drivers/staging/erofs/erofs_fs.h b/drivers/staging/erofs/erofs_fs.h
new file mode 100644
index 000..2f8e2bf
--- /dev/null
+++ b/drivers/staging/erofs/erofs_fs.h
@@ -0,0 +1,266 @@
+/* SPDX-License-Identifier: GPL-2.0 OR Apache-2.0
+ *
+ * linux/drivers/staging/erofs/erofs_fs.h
+ *
+ * Copyright (C) 2017-2018 HUAWEI, Inc.
+ * http://www.huawei.com/
+ * Created by Gao Xiang 
+ *
+ * This file is dual-licensed; you may select either the GNU General Public
+ * License version 2 or Apache License, Version 2.0. See the file COPYING
+ * in the main directory of the Linux distribution for more details.
+ */
+#ifndef __EROFS_FS_H
+#define __EROFS_FS_H
+
+/* Enhanced(Extended) ROM File System */
+#define EROFS_SUPER_MAGIC_V10xE0F5E1E2
+#define EROFS_SUPER_OFFSET  1024
+
+struct erofs_super_block {
+/*  0 */__le32 magic;   /* in the little endian */
+/*  4 */__le32 checksum;/* crc32c(super_block) */
+/*  8 */__le32 features;
+/* 12 */__u8 blkszbits; /* support block_size == PAGE_SIZE only */
+/* 13 */__u8 reserved;
+
+/* 14 */__le16 root_nid;
+/* 16 */__le64 inos;/* total valid ino # (== f_files - f_favail) */
+
+/* 24 */__le64 build_time;  /* inode v1 time derivation */
+/* 32 */__le32 build_time_nsec;
+/* 36 */__le32 blocks;  /* used for statfs */
+/* 40 */__le32 meta_blkaddr;
+/* 44 */__le32 xattr_blkaddr;
+/* 48 */__u8 uuid[16];  /* 128-bit uuid for volume */
+/* 64 */__u8 volume_name[16];   /* volume name */
+
+/* 80 */__u8 reserved2[48]; /* 128 bytes */
+} __packed;
+
+#define __EROFS_BIT(_prefix, _cur, _pre)   enum {  \
+   _prefix ## _cur ## _BIT = _prefix ## _pre ## _BIT + \
+   _prefix ## _pre ## _BITS }
+
+/*
+ * erofs inode data mapping:
+ * 0 - inode plain without inline data A:
+ * inode, [xattrs], ... | ... | no-holed data
+ * 1 - inode VLE compression B:
+ * inode, [xattrs], extents ... | ...
+ * 2 - inode plain with inline data C:
+ * inode, [xattrs], last_inline_data, ... | ... | no-holed data
+ * 3~7 - reserved
+ */
+enum {
+   EROFS_INODE_LAYOUT_PLAIN,
+   EROFS_INODE_LAYOUT_COMPRESSION,
+   EROFS_INODE_LAYOUT_INLINE,
+   EROFS_INODE_LAYOUT_MAX
+};
+#define EROFS_I_VERSION_BITS1
+#define EROFS_I_DATA_MAPPING_BITS   3
+
+#define EROFS_I_VERSION_BIT 0
+__EROFS_BIT(EROFS_I_, DATA_MAPPING, VERSION);
+
+struct erofs_inode_v1 {
+/*  0 */__le16 i_advise;
+
+/* 1 header + n-1 * 4 bytes inline xattr to keep continuity */
+/*  2 */__le16 i_xattr_icount;
+/*  4 */__le16 i_mode;
+/*  6 */__le16 i_nlink;
+/*  8 */__le32 i_size;
+/* 12 */__le32 i_reserved;
+/* 16 */union {
+   /* file total compressed blocks for data mapping 1 */
+   __le32 compressed_blocks;
+   __le32 raw_blkaddr;
+
+   /* for device files, used to indicate old/new device # */
+   __le32 rdev;
+   } i_u __packed;
+/* 20 */__le32 i_ino;   /* only used for 32-bit stat compatibility */
+/* 24 */__le16 i_uid;
+/* 26 */__le16 i_gid;
+/* 28 */__le32 i_checksum;
+} __packed;
+
+/* 32 bytes on-disk inode */
+#define EROFS_INODE_LAYOUT_V1   0
+/* 64 bytes on-disk inode */
+#define EROFS_INODE_LAYOUT_V2   1
+
+struct erofs_inode_v2 {
+   __le16 i_advise;
+
+   /* 1 header + n-1 * 4 bytes inline xattr to keep continuity */
+   __le16 i_xattr_icount;
+   __le16 i_mode;
+   __le16 i_reserved;  /* 8 bytes */
+   __le64 i_size;  /* 16 bytes */
+   union {
+   /* file total compressed blocks for data mapping 1 */
+   __le32 compressed_blocks;
+   __le32 raw_blkaddr;
+
+   /* for device files, used to indicate old/new device # */
+   __le32 rdev;
+   } i_u __packed;
+
+   /* only used for 32-bit stat compatibility */
+   __le32 i_ino;   /* 24 bytes */
+
+   __le32 i_uid;
+   __le32 i_gid;
+   __le64 i_ctime; /* 32 bytes */
+   __le32 i_ctime_nsec;
+   __le32 i_nlink;
+   __u8   i_reserved2[12];
+   __le32 i_checksum;  /* 64 bytes */
+} __packed;
+
+#define EROFS_MAX_SHARED_XATTRS (128)
+/* h_shared_count between 129 ... 255 are special # */
+#define EROFS_SHARED_XATTR_EXTENT   (255)
+
+/*
+ * inline xattrs (n == i_xattr_icount):
+ * erofs_xattr_ibody_header(1) + (n - 1) * 4 bytes
+ *  12 bytes   /   \
+ */ \
+ 

[PATCH 00/25] staging: erofs: introduce erofs file system

2018-07-26 Thread Gao Xiang
Hi,

This is actually the 2nd patchset of erofs file system,
the original patchset can be found at

Link: https://marc.info/?l=linux-fsdevel=152776480425624

In order to keep up with the mainline linux-kernel changes and
improve it in a more active and timely manner, we put forword
this upstream proposal for linux-staging.

EROFS file system is a read-only file system with compression
support designed for certain devices (especially embeded
devices) with very limited physical memory and lots of memory
consumers, such as Android devices. It aimes to provide
a complete compression solution for such devices focuing
on high performance and little extra memory overhead.

It is perferred to select larger compressed cluster sizes
(generally >= 128k) for traditional compression file systems.
It reads and decompresses a large compressed cluster at once,
which has a good-looking random read number when memory
is sufficient because all historial decompressed data
is expected to be cached in memory. However, it also
induces destructive effects when such devices have no enough
spare memory for caching and decompression.

EROFS file system acts in some different way. It uses
fixed-sized compressed size rather than fixed-sized input
size, namely VLE (variable-length extent) compression,
which has at least three adventages:

 1) all data read from block device at once can be
utilized, and read amplification can be easier to
estimate and control;
 2) generally, it has a better compression ratio than
fixed-sized input compression approaches configured
with the same size;
 3) aggressively optimized paths such as partial page
read can be implemented to gain better performance
for page-unaligned read (unimplemented yet, in TODO list).

As can be seen, VLE compression does a great job in small
compressed cluster sizes, which is of course suitable for
devices with limited memory. In this patchset, an in-place
decompresion is also introduced to minimize extra memory usage.


Apart from compression, EROFS also has the following features
available and some limits:
 o page-sized block support (currently, and no buffer-head);
 o 32-bit block address (16TB for 4KB block);
 o selectable v1 (32 bytes) / v2 (64 bytes) inode;
 o 32-bit / 64-bit file size;
 o 64-bit node number for addressing inodes;
 o 64-bit s and 32-bit ns timestamps;
 o inline data support;
 o inline and shared xattr support;
 o metadata and data can be mixed (optional);
 o special inode support;
 o posix acl support.


The file system is still actively WIP, see _TODO_ for more details.

Any comments are welcome. :)


Change log from the original patchset
=

 o Introduce a new erofs decompression subsystem, which has
   better sequencial read than the original patchset, and
   its random read remains almost the same (note that erofs
   still only fully support page-sized compressed cluster as
   the compression unit, however some additional code enabling
   larger compressed clustersizes is also added in this version);

 o Avoid LINUX_VERSION macros for linux-staging upstream

 o several bugfix and cleanup


Short log
=

Chao Yu (3):
  staging: erofs: support special inode
  staging: erofs: introduce error injection infrastructure
  staging: erofs: support tracepoint

Gao Xiang (22):
  staging: erofs: add on-disk layout
  staging: erofs: add erofs in-memory stuffs
  staging: erofs: add super block operations
  staging: erofs: add raw address_space operations
  staging: erofs: add inode operations
  staging: erofs: add directory operations
  staging: erofs: add namei functions
  staging: erofs: update Kconfig and Makefile
  staging: erofs: introduce xattr & acl support
  staging: erofs: : introduce tagged pointer
  staging: erofs: introduce pagevec for unzip subsystem
  staging: erofs: add erofs_map_blocks_iter
  staging: erofs: add erofs_allocpage
  staging: erofs: globalize prepare_bio and __submit_bio
  staging: erofs: introduce a customized LZ4 decompression
  staging: erofs: add a generic z_erofs VLE decompressor
  staging: erofs: introduce superblock registration
  staging: erofs: introduce erofs shrinker
  staging: erofs: introduce workstation for decompression
  staging: erofs: introduce VLE decompression support
  staging: erofs: introduce cached decompression
  staging: erofs: add a TODO and update MAINTAINERS for staging

 MAINTAINERS|7 +
 drivers/staging/Kconfig|2 +
 drivers/staging/Makefile   |1 +
 drivers/staging/erofs/Kconfig  |  141 ++
 drivers/staging/erofs/Makefile |   13 +
 drivers/staging/erofs/TODO |   45 +
 drivers/staging/erofs/data.c   |  385 +
 drivers/staging/erofs/dir.c|  145 ++
 drivers/staging/erofs/erofs_fs.h   |  266 
 

Re: [PATCH v4 00/15] staging: mt7621-pci: avoid custom pci config read and writes

2018-07-26 Thread Sergio Paracuellos
On Thu, Jul 26, 2018 at 08:02:17PM +1000, NeilBrown wrote:
> On Thu, Jul 26 2018, Sergio Paracuellos wrote:
> 
> >
> > Ok, I think the problem is we are not setting the bridge->windows retrieved
> > with devm_request_pci_bus_resources in "res". So we have to set those 
> > properly
> > to the bridge to get all correctly assigned. So I think adding this should 
> > make
> > the system to work:
> >
> > + list_splice_init(, >windows);
> > bridge->busnr = 0;
> > bridge->dev.parent = dev;
> > bridge->sysdata = pcie;
> >
> >
> > (Sorry don't access to code now and cannot diff).
> >
> > Let me know if this works. Is this the hopefully good one?
> 
> This one, at least, makes a difference.
> 
> I now see
> [2.42] pci :01:00.0: BAR 5: assigned [mem 0x6000-0x61ff]
> 
> which is promising.

Yes, this and also the dmesg are promising and seems resources are correctly
assigned now.

> 
> However it gets to:
> 
> [8.62] pci :00:00.0: enabling device (0004 -> 0006)
> [8.64] ahci :01:00.0: enabling device ( -> 0002)
> 

So after setup the PCI system topology is the driver responsability to enable
the device. It means only make the hardware memory space accesible and
this is the (-> 0002) of the log message (set the memory space bit of PCI 
COMMAND
register to 1 to make it accesible to allow the device to respond to memory 
space acceses).
So it is correct the behaviour of trying to enable this but it should not hang. 
This trace is in
drivers/pci/setup-res.c +495 (function pci_enable_resources). It would be 
helpful
a more deeper debug to know exactly where it really hangs. 

Thanks in advance.

> and hangs.
> 
> Full dmesg pasted below.
> 
> Thanks,
> NeilBrown

Best regards,
Sergio Paracuellos
> 
> 
> [0.00] Linux version 4.18.0-rc5+ (neilb@noble) (gcc version 7.2.0 
> (GCC)) #231 SMP Thu Jul 26 19:57:52 AEST 2018
> [0.00] SoC Type: MediaTek MT7621 ver:1 eco:3
> [0.00] bootconsole [early0] enabled
> [0.00] CPU0 revision is: 0001992f (MIPS 1004Kc)
> [0.00] MIPS: machine is GB-PC1
> [0.00] Determined physical RAM map:
> [0.00]  memory: 1c00 @  (usable)
> [0.00]  memory: 0400 @ 2000 (usable)
> [0.00] Initrd not found or empty - disabling initrd
> [0.00] VPE topology {2,2} total 4
> [0.00] Primary instruction cache 32kB, VIPT, 4-way, linesize 32 bytes.
> [0.00] Primary data cache 32kB, 4-way, PIPT, no aliases, linesize 32 
> bytes
> [0.00] MIPS secondary cache 256kB, 8-way, linesize 32 bytes.
> [0.00] Zone ranges:
> [0.00]   Normal   [mem 0x-0x1fff]
> [0.00]   HighMem  [mem 0x2000-0x23ff]
> [0.00] Movable zone start for each node
> [0.00] Early memory node ranges
> [0.00]   node   0: [mem 0x-0x1bff]
> [0.00]   node   0: [mem 0x2000-0x23ff]
> [0.00] Initmem setup node 0 [mem 
> 0x-0x23ff]
> [0.00] random: get_random_bytes called from start_kernel+0xb4/0x4ec 
> with crng_init=0
> [0.00] percpu: Embedded 15 pages/cpu @(ptrval) s30480 r8192 d22768 
> u61440
> [0.00] Built 1 zonelists, mobility grouping on.  Total pages: 130048
> [0.00] Kernel command line: console=ttyS0,57600
> [0.00] Dentry cache hash table entries: 65536 (order: 6, 262144 bytes)
> [0.00] Inode-cache hash table entries: 32768 (order: 5, 131072 bytes)
> [0.00] Writing ErrCtl register=00010882
> [0.00] Readback ErrCtl register=00010882
> [0.00] Memory: 504788K/524288K available (6131K kernel code, 232K 
> rwdata, 1052K rodata, 6524K init, 241K bss, 19500K reserved, 0K cma-reserved, 
> 65536K highmem)
> [0.00] SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=4, Nodes=1
> [0.00] Hierarchical RCU implementation.
> [0.00] NR_IRQS: 256
> [0.00] clocksource: GIC: mask: 0x max_cycles: 
> 0xcf914c9718, max_idle_ns: 440795231327 ns
> [0.00] sched_clock: 32 bits at 100 Hz, resolution 1000ns, wraps 
> every 2147483647500ns
> [0.01] Calibrating delay loop... 597.60 BogoMIPS (lpj=2988032)
> [0.07] pid_max: default: 32768 minimum: 301
> [0.08] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
> [0.09] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 
> bytes)
> [0.10] Hierarchical SRCU implementation.
> [0.11] smp: Bringing up secondary CPUs ...
> [0.12] Primary instruction cache 32kB, VIPT, 4-way, linesize 32 bytes.
> [0.12] Primary data cache 32kB, 4-way, PIPT, no aliases, linesize 32 
> bytes
> [0.12] MIPS secondary cache 256kB, 8-way, linesize 32 bytes.
> [0.12] CPU1 revision is: 0001992f (MIPS 1004Kc)
> [0.18] Synchronize counters for CPU 1: done.
> [0.22] 

Re: [PATCH v4 00/15] staging: mt7621-pci: avoid custom pci config read and writes

2018-07-26 Thread NeilBrown
On Thu, Jul 26 2018, Sergio Paracuellos wrote:

>
> Ok, I think the problem is we are not setting the bridge->windows retrieved
> with devm_request_pci_bus_resources in "res". So we have to set those properly
> to the bridge to get all correctly assigned. So I think adding this should 
> make
> the system to work:
>
> + list_splice_init(, >windows);
> bridge->busnr = 0;
> bridge->dev.parent = dev;
> bridge->sysdata = pcie;
>
>
> (Sorry don't access to code now and cannot diff).
>
> Let me know if this works. Is this the hopefully good one?

This one, at least, makes a difference.

I now see
[2.42] pci :01:00.0: BAR 5: assigned [mem 0x6000-0x61ff]

which is promising.

However it gets to:

[8.62] pci :00:00.0: enabling device (0004 -> 0006)
[8.64] ahci :01:00.0: enabling device ( -> 0002)

and hangs.

Full dmesg pasted below.

Thanks,
NeilBrown


[0.00] Linux version 4.18.0-rc5+ (neilb@noble) (gcc version 7.2.0 
(GCC)) #231 SMP Thu Jul 26 19:57:52 AEST 2018
[0.00] SoC Type: MediaTek MT7621 ver:1 eco:3
[0.00] bootconsole [early0] enabled
[0.00] CPU0 revision is: 0001992f (MIPS 1004Kc)
[0.00] MIPS: machine is GB-PC1
[0.00] Determined physical RAM map:
[0.00]  memory: 1c00 @  (usable)
[0.00]  memory: 0400 @ 2000 (usable)
[0.00] Initrd not found or empty - disabling initrd
[0.00] VPE topology {2,2} total 4
[0.00] Primary instruction cache 32kB, VIPT, 4-way, linesize 32 bytes.
[0.00] Primary data cache 32kB, 4-way, PIPT, no aliases, linesize 32 
bytes
[0.00] MIPS secondary cache 256kB, 8-way, linesize 32 bytes.
[0.00] Zone ranges:
[0.00]   Normal   [mem 0x-0x1fff]
[0.00]   HighMem  [mem 0x2000-0x23ff]
[0.00] Movable zone start for each node
[0.00] Early memory node ranges
[0.00]   node   0: [mem 0x-0x1bff]
[0.00]   node   0: [mem 0x2000-0x23ff]
[0.00] Initmem setup node 0 [mem 0x-0x23ff]
[0.00] random: get_random_bytes called from start_kernel+0xb4/0x4ec 
with crng_init=0
[0.00] percpu: Embedded 15 pages/cpu @(ptrval) s30480 r8192 d22768 
u61440
[0.00] Built 1 zonelists, mobility grouping on.  Total pages: 130048
[0.00] Kernel command line: console=ttyS0,57600
[0.00] Dentry cache hash table entries: 65536 (order: 6, 262144 bytes)
[0.00] Inode-cache hash table entries: 32768 (order: 5, 131072 bytes)
[0.00] Writing ErrCtl register=00010882
[0.00] Readback ErrCtl register=00010882
[0.00] Memory: 504788K/524288K available (6131K kernel code, 232K 
rwdata, 1052K rodata, 6524K init, 241K bss, 19500K reserved, 0K cma-reserved, 
65536K highmem)
[0.00] SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=4, Nodes=1
[0.00] Hierarchical RCU implementation.
[0.00] NR_IRQS: 256
[0.00] clocksource: GIC: mask: 0x max_cycles: 
0xcf914c9718, max_idle_ns: 440795231327 ns
[0.00] sched_clock: 32 bits at 100 Hz, resolution 1000ns, wraps 
every 2147483647500ns
[0.01] Calibrating delay loop... 597.60 BogoMIPS (lpj=2988032)
[0.07] pid_max: default: 32768 minimum: 301
[0.08] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
[0.09] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
[0.10] Hierarchical SRCU implementation.
[0.11] smp: Bringing up secondary CPUs ...
[0.12] Primary instruction cache 32kB, VIPT, 4-way, linesize 32 bytes.
[0.12] Primary data cache 32kB, 4-way, PIPT, no aliases, linesize 32 
bytes
[0.12] MIPS secondary cache 256kB, 8-way, linesize 32 bytes.
[0.12] CPU1 revision is: 0001992f (MIPS 1004Kc)
[0.18] Synchronize counters for CPU 1: done.
[0.22] Primary instruction cache 32kB, VIPT, 4-way, linesize 32 bytes.
[0.22] Primary data cache 32kB, 4-way, PIPT, no aliases, linesize 32 
bytes
[0.22] MIPS secondary cache 256kB, 8-way, linesize 32 bytes.
[0.22] CPU2 revision is: 0001992f (MIPS 1004Kc)
[0.28] Synchronize counters for CPU 2: done.
[0.32] Primary instruction cache 32kB, VIPT, 4-way, linesize 32 bytes.
[0.32] Primary data cache 32kB, 4-way, PIPT, no aliases, linesize 32 
bytes
[0.32] MIPS secondary cache 256kB, 8-way, linesize 32 bytes.
[0.32] CPU3 revision is: 0001992f (MIPS 1004Kc)
[0.38] Synchronize counters for CPU 3: done.
[0.42] smp: Brought up 1 node, 4 CPUs
[0.43] devtmpfs: initialized
[0.48] clocksource: jiffies: mask: 0x max_cycles: 0x, 
max_idle_ns: 1911260446275 ns
[0.49] futex hash table entries: 1024 (order: 3, 32768 bytes)
[0.50] pinctrl core: initialized pinctrl 

Re: [PATCH v4 00/15] staging: mt7621-pci: avoid custom pci config read and writes

2018-07-26 Thread Sergio Paracuellos
On Thu, Jul 26, 2018 at 04:45:41PM +1000, NeilBrown wrote:
> On Thu, Jul 26 2018, Sergio Paracuellos wrote:
> 
> > On Thu, Jul 26, 2018 at 6:50 AM, NeilBrown  wrote:
> >> On Wed, Jul 25 2018, Sergio Paracuellos wrote:
> >>
> >>> On Wed, Jul 25, 2018 at 08:21:35AM +1000, NeilBrown wrote:
>  On Mon, Jul 16 2018, Sergio Paracuellos wrote:
> 
>  > This patch series include an attempt to avoid the use of custom
>  > read and writes in driver code and use PCI subsystem common ones.
>  >
>  > In order to do this 'map_bus' callback is implemented and also
>  > data structures for driver are included. The regs base address
>  > is being readed from device tree and the driver gets clean a lot
>  > of code.
>  >
>  > Changes in v4:
>  > - Rebased onto staging-next.
>  >
>  > Changes in v3:
>  > - Include new patches to delete all RALINK_BASE definition
>  >   dependant code and be able to avoid use of pci_legacy code.
>  > - use devm_of_pci_get_host_bridge_resources,
>  >   devm_request_pci_bus_resources and pci_scan_root_bus_bridge
>  >   and pci_bus_add_devices
>  >
>  > Changes in v2:
>  > - squash PATCH 1 and PATCH 2 of previous series in only PATCH 1
>  > - Change name for host structure.
>  > - Create a new port structure (platform has 3 pcie controllers)
>  > - Replace the use of pci_generic_config_[read|write]32 in favour
>  >   of pci_generic_config_[read|write] and change map_bus implemen-
>  >   tation for hopefully the right one.
>  >
>  > Best regards,
> 
>  Thanks for these.
>  I added
>  diff --git a/arch/mips/ralink/Kconfig b/arch/mips/ralink/Kconfig
>  index 1f9cb0e3c79a..50779b3379db 100644
>  --- a/arch/mips/ralink/Kconfig
>  +++ b/arch/mips/ralink/Kconfig
>  @@ -51,6 +51,7 @@ choice
>  select COMMON_CLK
>  select CLKSRC_MIPS_GIC
>  select HW_HAS_PCI
>  +   select PCI_DRIVERS_GENERIC
>   endchoice
> 
>   choice
> 
>  so that I could build and test it - maybe there is somewhere else that
>  "select" can go while this is still in staging..
> 
>  The system boots and can see the three pcie-attached SATA controllers:
> 
>  # lspci
>  00:00.0 PCI bridge: Device 0e8d:0801 (rev 01)
>  00:01.0 PCI bridge: Device 0e8d:0801 (rev 01)
>  00:02.0 PCI bridge: Device 0e8d:0801 (rev 01)
>  01:00.0 IDE interface: ASMedia Technology Inc. ASM1061 SATA IDE 
>  Controller (rev 02)
>  02:00.0 IDE interface: ASMedia Technology Inc. ASM1061 SATA IDE 
>  Controller (rev 02)
>  03:00.0 IDE interface: ASMedia Technology Inc. ASM1061 SATA IDE 
>  Controller (rev 02)
> 
>  but it cannot see the drive that is plugged into one of these.
>  Below is the first 10 seconds of dmesg.
>  I suspect the relevant bit is
> 
>  [8.68] ahci: probe of :01:00.0 failed with error -22
>  [8.70] ahci: probe of :02:00.0 failed with error -22
>  [8.71] ahci: probe of :03:00.0 failed with error -22
> 
>  I haven't dug deeper yet.
> >>>
> >>> Hi Neil,
> >>>
> >>> Can you please make a test for me? Can you comment lines about pinctrl in 
> >>> the pcie
> >>> node of the device tree? I am not sure we have to use the reset pin there 
> >>> but just
> >>> use the reset_control in a proper way. These two:
> >>>
> >>> pinctrl-names = "default";
> >>> pinctrl-0 = <_pins>;
> >>>
> >>> Does this change make the plugged drives to work?
> >>
> >> Thanks for the suggestion.  No, this does change anything.
> >> I had a go at sprinking printks to see what exactly was failing.
> >> It is pcim_iomap_regions().
> >> "mask" is 0x20, is t wants to map region 5.
> >> However region 5 has size zero - hence -EINVAL.
> >
> > Thanks for this analysis. It is really helpful.
> >
> >>
> >> In the dmesg there is:
> >>
>  [2.53] pci :01:00.0: BAR 5: no space for [mem size 
>  0x0200]
>  [2.54] pci :01:00.0: BAR 5: failed to assign [mem size 
>  0x0200]
> >>
> >> I think this is where resource 5 is not getting set up properly.
> >> That is as far as I got today.
> >
> > It seems there are not space in bridges to assign to the downstream 
> > devices...
> >
> > As far as I know Linux assigns space for endpoint BARs, but it doesn't
> > automatically
> > reassign bridge windows to make space for downstream devices. We can
> > try two things.
> >
> > 1) Call pci_bus_size_bridges as follows (if you prefer I can send v5
> > including this change in the
> > first PATCH of the series, but I think it is better to test this
> > before sending anything):
> >
> > diff --git a/drivers/staging/mt7621-pci/pci-mt7621.c
> > b/drivers/staging/mt7621-pci/pci-mt7621.c
> > index f8e81aa..1f329d6 100644
> > --- 

Re: [PATCH v4 00/15] staging: mt7621-pci: avoid custom pci config read and writes

2018-07-26 Thread Sergio Paracuellos
On Thu, Jul 26, 2018 at 04:45:41PM +1000, NeilBrown wrote:
> On Thu, Jul 26 2018, Sergio Paracuellos wrote:
> 
> > On Thu, Jul 26, 2018 at 6:50 AM, NeilBrown  wrote:
> >> On Wed, Jul 25 2018, Sergio Paracuellos wrote:
> >>
> >>> On Wed, Jul 25, 2018 at 08:21:35AM +1000, NeilBrown wrote:
>  On Mon, Jul 16 2018, Sergio Paracuellos wrote:
> 
>  > This patch series include an attempt to avoid the use of custom
>  > read and writes in driver code and use PCI subsystem common ones.
>  >
>  > In order to do this 'map_bus' callback is implemented and also
>  > data structures for driver are included. The regs base address
>  > is being readed from device tree and the driver gets clean a lot
>  > of code.
>  >
>  > Changes in v4:
>  > - Rebased onto staging-next.
>  >
>  > Changes in v3:
>  > - Include new patches to delete all RALINK_BASE definition
>  >   dependant code and be able to avoid use of pci_legacy code.
>  > - use devm_of_pci_get_host_bridge_resources,
>  >   devm_request_pci_bus_resources and pci_scan_root_bus_bridge
>  >   and pci_bus_add_devices
>  >
>  > Changes in v2:
>  > - squash PATCH 1 and PATCH 2 of previous series in only PATCH 1
>  > - Change name for host structure.
>  > - Create a new port structure (platform has 3 pcie controllers)
>  > - Replace the use of pci_generic_config_[read|write]32 in favour
>  >   of pci_generic_config_[read|write] and change map_bus implemen-
>  >   tation for hopefully the right one.
>  >
>  > Best regards,
> 
>  Thanks for these.
>  I added
>  diff --git a/arch/mips/ralink/Kconfig b/arch/mips/ralink/Kconfig
>  index 1f9cb0e3c79a..50779b3379db 100644
>  --- a/arch/mips/ralink/Kconfig
>  +++ b/arch/mips/ralink/Kconfig
>  @@ -51,6 +51,7 @@ choice
>  select COMMON_CLK
>  select CLKSRC_MIPS_GIC
>  select HW_HAS_PCI
>  +   select PCI_DRIVERS_GENERIC
>   endchoice
> 
>   choice
> 
>  so that I could build and test it - maybe there is somewhere else that
>  "select" can go while this is still in staging..
> 
>  The system boots and can see the three pcie-attached SATA controllers:
> 
>  # lspci
>  00:00.0 PCI bridge: Device 0e8d:0801 (rev 01)
>  00:01.0 PCI bridge: Device 0e8d:0801 (rev 01)
>  00:02.0 PCI bridge: Device 0e8d:0801 (rev 01)
>  01:00.0 IDE interface: ASMedia Technology Inc. ASM1061 SATA IDE 
>  Controller (rev 02)
>  02:00.0 IDE interface: ASMedia Technology Inc. ASM1061 SATA IDE 
>  Controller (rev 02)
>  03:00.0 IDE interface: ASMedia Technology Inc. ASM1061 SATA IDE 
>  Controller (rev 02)
> 
>  but it cannot see the drive that is plugged into one of these.
>  Below is the first 10 seconds of dmesg.
>  I suspect the relevant bit is
> 
>  [8.68] ahci: probe of :01:00.0 failed with error -22
>  [8.70] ahci: probe of :02:00.0 failed with error -22
>  [8.71] ahci: probe of :03:00.0 failed with error -22
> 
>  I haven't dug deeper yet.
> >>>
> >>> Hi Neil,
> >>>
> >>> Can you please make a test for me? Can you comment lines about pinctrl in 
> >>> the pcie
> >>> node of the device tree? I am not sure we have to use the reset pin there 
> >>> but just
> >>> use the reset_control in a proper way. These two:
> >>>
> >>> pinctrl-names = "default";
> >>> pinctrl-0 = <_pins>;
> >>>
> >>> Does this change make the plugged drives to work?
> >>
> >> Thanks for the suggestion.  No, this does change anything.
> >> I had a go at sprinking printks to see what exactly was failing.
> >> It is pcim_iomap_regions().
> >> "mask" is 0x20, is t wants to map region 5.
> >> However region 5 has size zero - hence -EINVAL.
> >
> > Thanks for this analysis. It is really helpful.
> >
> >>
> >> In the dmesg there is:
> >>
>  [2.53] pci :01:00.0: BAR 5: no space for [mem size 
>  0x0200]
>  [2.54] pci :01:00.0: BAR 5: failed to assign [mem size 
>  0x0200]
> >>
> >> I think this is where resource 5 is not getting set up properly.
> >> That is as far as I got today.
> >
> > It seems there are not space in bridges to assign to the downstream 
> > devices...
> >
> > As far as I know Linux assigns space for endpoint BARs, but it doesn't
> > automatically
> > reassign bridge windows to make space for downstream devices. We can
> > try two things.
> >
> > 1) Call pci_bus_size_bridges as follows (if you prefer I can send v5
> > including this change in the
> > first PATCH of the series, but I think it is better to test this
> > before sending anything):
> >
> > diff --git a/drivers/staging/mt7621-pci/pci-mt7621.c
> > b/drivers/staging/mt7621-pci/pci-mt7621.c
> > index f8e81aa..1f329d6 100644
> > --- 

Re: [PATCH v4 00/15] staging: mt7621-pci: avoid custom pci config read and writes

2018-07-26 Thread NeilBrown
On Thu, Jul 26 2018, Sergio Paracuellos wrote:

> On Thu, Jul 26, 2018 at 6:50 AM, NeilBrown  wrote:
>> On Wed, Jul 25 2018, Sergio Paracuellos wrote:
>>
>>> On Wed, Jul 25, 2018 at 08:21:35AM +1000, NeilBrown wrote:
 On Mon, Jul 16 2018, Sergio Paracuellos wrote:

 > This patch series include an attempt to avoid the use of custom
 > read and writes in driver code and use PCI subsystem common ones.
 >
 > In order to do this 'map_bus' callback is implemented and also
 > data structures for driver are included. The regs base address
 > is being readed from device tree and the driver gets clean a lot
 > of code.
 >
 > Changes in v4:
 > - Rebased onto staging-next.
 >
 > Changes in v3:
 > - Include new patches to delete all RALINK_BASE definition
 >   dependant code and be able to avoid use of pci_legacy code.
 > - use devm_of_pci_get_host_bridge_resources,
 >   devm_request_pci_bus_resources and pci_scan_root_bus_bridge
 >   and pci_bus_add_devices
 >
 > Changes in v2:
 > - squash PATCH 1 and PATCH 2 of previous series in only PATCH 1
 > - Change name for host structure.
 > - Create a new port structure (platform has 3 pcie controllers)
 > - Replace the use of pci_generic_config_[read|write]32 in favour
 >   of pci_generic_config_[read|write] and change map_bus implemen-
 >   tation for hopefully the right one.
 >
 > Best regards,

 Thanks for these.
 I added
 diff --git a/arch/mips/ralink/Kconfig b/arch/mips/ralink/Kconfig
 index 1f9cb0e3c79a..50779b3379db 100644
 --- a/arch/mips/ralink/Kconfig
 +++ b/arch/mips/ralink/Kconfig
 @@ -51,6 +51,7 @@ choice
 select COMMON_CLK
 select CLKSRC_MIPS_GIC
 select HW_HAS_PCI
 +   select PCI_DRIVERS_GENERIC
  endchoice

  choice

 so that I could build and test it - maybe there is somewhere else that
 "select" can go while this is still in staging..

 The system boots and can see the three pcie-attached SATA controllers:

 # lspci
 00:00.0 PCI bridge: Device 0e8d:0801 (rev 01)
 00:01.0 PCI bridge: Device 0e8d:0801 (rev 01)
 00:02.0 PCI bridge: Device 0e8d:0801 (rev 01)
 01:00.0 IDE interface: ASMedia Technology Inc. ASM1061 SATA IDE Controller 
 (rev 02)
 02:00.0 IDE interface: ASMedia Technology Inc. ASM1061 SATA IDE Controller 
 (rev 02)
 03:00.0 IDE interface: ASMedia Technology Inc. ASM1061 SATA IDE Controller 
 (rev 02)

 but it cannot see the drive that is plugged into one of these.
 Below is the first 10 seconds of dmesg.
 I suspect the relevant bit is

 [8.68] ahci: probe of :01:00.0 failed with error -22
 [8.70] ahci: probe of :02:00.0 failed with error -22
 [8.71] ahci: probe of :03:00.0 failed with error -22

 I haven't dug deeper yet.
>>>
>>> Hi Neil,
>>>
>>> Can you please make a test for me? Can you comment lines about pinctrl in 
>>> the pcie
>>> node of the device tree? I am not sure we have to use the reset pin there 
>>> but just
>>> use the reset_control in a proper way. These two:
>>>
>>> pinctrl-names = "default";
>>> pinctrl-0 = <_pins>;
>>>
>>> Does this change make the plugged drives to work?
>>
>> Thanks for the suggestion.  No, this does change anything.
>> I had a go at sprinking printks to see what exactly was failing.
>> It is pcim_iomap_regions().
>> "mask" is 0x20, is t wants to map region 5.
>> However region 5 has size zero - hence -EINVAL.
>
> Thanks for this analysis. It is really helpful.
>
>>
>> In the dmesg there is:
>>
 [2.53] pci :01:00.0: BAR 5: no space for [mem size 0x0200]
 [2.54] pci :01:00.0: BAR 5: failed to assign [mem size 
 0x0200]
>>
>> I think this is where resource 5 is not getting set up properly.
>> That is as far as I got today.
>
> It seems there are not space in bridges to assign to the downstream devices...
>
> As far as I know Linux assigns space for endpoint BARs, but it doesn't
> automatically
> reassign bridge windows to make space for downstream devices. We can
> try two things.
>
> 1) Call pci_bus_size_bridges as follows (if you prefer I can send v5
> including this change in the
> first PATCH of the series, but I think it is better to test this
> before sending anything):
>
> diff --git a/drivers/staging/mt7621-pci/pci-mt7621.c
> b/drivers/staging/mt7621-pci/pci-mt7621.c
> index f8e81aa..1f329d6 100644
> --- a/drivers/staging/mt7621-pci/pci-mt7621.c
> +++ b/drivers/staging/mt7621-pci/pci-mt7621.c
> @@ -629,6 +629,7 @@ pcie(2/1/0) link status pcie2_num
> pcie1_num   pcie0_num
>
> bus = bridge->bus;
>
> +   pci_bus_size_bridges(bridge->bus);
> pci_assign_unassigned_bus_resources(bridge->bus);
> 

Re: [PATCH v4 00/15] staging: mt7621-pci: avoid custom pci config read and writes

2018-07-26 Thread Sergio Paracuellos
On Thu, Jul 26, 2018 at 6:50 AM, NeilBrown  wrote:
> On Wed, Jul 25 2018, Sergio Paracuellos wrote:
>
>> On Wed, Jul 25, 2018 at 08:21:35AM +1000, NeilBrown wrote:
>>> On Mon, Jul 16 2018, Sergio Paracuellos wrote:
>>>
>>> > This patch series include an attempt to avoid the use of custom
>>> > read and writes in driver code and use PCI subsystem common ones.
>>> >
>>> > In order to do this 'map_bus' callback is implemented and also
>>> > data structures for driver are included. The regs base address
>>> > is being readed from device tree and the driver gets clean a lot
>>> > of code.
>>> >
>>> > Changes in v4:
>>> > - Rebased onto staging-next.
>>> >
>>> > Changes in v3:
>>> > - Include new patches to delete all RALINK_BASE definition
>>> >   dependant code and be able to avoid use of pci_legacy code.
>>> > - use devm_of_pci_get_host_bridge_resources,
>>> >   devm_request_pci_bus_resources and pci_scan_root_bus_bridge
>>> >   and pci_bus_add_devices
>>> >
>>> > Changes in v2:
>>> > - squash PATCH 1 and PATCH 2 of previous series in only PATCH 1
>>> > - Change name for host structure.
>>> > - Create a new port structure (platform has 3 pcie controllers)
>>> > - Replace the use of pci_generic_config_[read|write]32 in favour
>>> >   of pci_generic_config_[read|write] and change map_bus implemen-
>>> >   tation for hopefully the right one.
>>> >
>>> > Best regards,
>>>
>>> Thanks for these.
>>> I added
>>> diff --git a/arch/mips/ralink/Kconfig b/arch/mips/ralink/Kconfig
>>> index 1f9cb0e3c79a..50779b3379db 100644
>>> --- a/arch/mips/ralink/Kconfig
>>> +++ b/arch/mips/ralink/Kconfig
>>> @@ -51,6 +51,7 @@ choice
>>> select COMMON_CLK
>>> select CLKSRC_MIPS_GIC
>>> select HW_HAS_PCI
>>> +   select PCI_DRIVERS_GENERIC
>>>  endchoice
>>>
>>>  choice
>>>
>>> so that I could build and test it - maybe there is somewhere else that
>>> "select" can go while this is still in staging..
>>>
>>> The system boots and can see the three pcie-attached SATA controllers:
>>>
>>> # lspci
>>> 00:00.0 PCI bridge: Device 0e8d:0801 (rev 01)
>>> 00:01.0 PCI bridge: Device 0e8d:0801 (rev 01)
>>> 00:02.0 PCI bridge: Device 0e8d:0801 (rev 01)
>>> 01:00.0 IDE interface: ASMedia Technology Inc. ASM1061 SATA IDE Controller 
>>> (rev 02)
>>> 02:00.0 IDE interface: ASMedia Technology Inc. ASM1061 SATA IDE Controller 
>>> (rev 02)
>>> 03:00.0 IDE interface: ASMedia Technology Inc. ASM1061 SATA IDE Controller 
>>> (rev 02)
>>>
>>> but it cannot see the drive that is plugged into one of these.
>>> Below is the first 10 seconds of dmesg.
>>> I suspect the relevant bit is
>>>
>>> [8.68] ahci: probe of :01:00.0 failed with error -22
>>> [8.70] ahci: probe of :02:00.0 failed with error -22
>>> [8.71] ahci: probe of :03:00.0 failed with error -22
>>>
>>> I haven't dug deeper yet.
>>
>> Hi Neil,
>>
>> Can you please make a test for me? Can you comment lines about pinctrl in 
>> the pcie
>> node of the device tree? I am not sure we have to use the reset pin there 
>> but just
>> use the reset_control in a proper way. These two:
>>
>> pinctrl-names = "default";
>> pinctrl-0 = <_pins>;
>>
>> Does this change make the plugged drives to work?
>
> Thanks for the suggestion.  No, this does change anything.
> I had a go at sprinking printks to see what exactly was failing.
> It is pcim_iomap_regions().
> "mask" is 0x20, is t wants to map region 5.
> However region 5 has size zero - hence -EINVAL.

Thanks for this analysis. It is really helpful.

>
> In the dmesg there is:
>
>>> [2.53] pci :01:00.0: BAR 5: no space for [mem size 0x0200]
>>> [2.54] pci :01:00.0: BAR 5: failed to assign [mem size 
>>> 0x0200]
>
> I think this is where resource 5 is not getting set up properly.
> That is as far as I got today.

It seems there are not space in bridges to assign to the downstream devices...

As far as I know Linux assigns space for endpoint BARs, but it doesn't
automatically
reassign bridge windows to make space for downstream devices. We can
try two things.

1) Call pci_bus_size_bridges as follows (if you prefer I can send v5
including this change in the
first PATCH of the series, but I think it is better to test this
before sending anything):

diff --git a/drivers/staging/mt7621-pci/pci-mt7621.c
b/drivers/staging/mt7621-pci/pci-mt7621.c
index f8e81aa..1f329d6 100644
--- a/drivers/staging/mt7621-pci/pci-mt7621.c
+++ b/drivers/staging/mt7621-pci/pci-mt7621.c
@@ -629,6 +629,7 @@ pcie(2/1/0) link status pcie2_num
pcie1_num   pcie0_num

bus = bridge->bus;

+   pci_bus_size_bridges(bridge->bus);
pci_assign_unassigned_bus_resources(bridge->bus);
list_for_each_entry(child, >children, node)
pcie_bus_configure_settings(child);

I think after this change the problem should disappear but if that is
not the case

2) if that does not work, we can