[PATCH v3 1/2] fjes: Do not load fjes driver if system does not have extended socket device.

2017-03-21 Thread YASUAKI ISHIMATSU
The fjes driver is used only by FUJITSU servers and almost of all
servers in the world never use it. But currently if ACPI PNP0C02
is defined in the ACPI table, the following message is always shown:

 "FUJITSU Extended Socket Network Device Driver - version 1.2
  - Copyright (c) 2015 FUJITSU LIMITED"

The message makes users confused because there is no reason that
the message is shown in other vendor servers.

To avoid the confusion, the patch adds a check that the server
has a extended socket device or not.

Signed-off-by: Yasuaki Ishimatsu 
CC: Taku Izumi 
---
v3:
- Rebase on net tree

v2:
- Order local variable declarations from longest to shortest line

 drivers/net/fjes/fjes_main.c | 52 +++-
 1 file changed, 47 insertions(+), 5 deletions(-)

diff --git a/drivers/net/fjes/fjes_main.c b/drivers/net/fjes/fjes_main.c
index c4b3c4b..7b58964 100644
--- a/drivers/net/fjes/fjes_main.c
+++ b/drivers/net/fjes/fjes_main.c
@@ -45,6 +45,8 @@
 MODULE_LICENSE("GPL");
 MODULE_VERSION(DRV_VERSION);

+#define ACPI_MOTHERBOARD_RESOURCE_HID "PNP0C02"
+
 static int fjes_request_irq(struct fjes_adapter *);
 static void fjes_free_irq(struct fjes_adapter *);

@@ -78,7 +80,7 @@
 static int fjes_poll(struct napi_struct *, int);

 static const struct acpi_device_id fjes_acpi_ids[] = {
-   {"PNP0C02", 0},
+   {ACPI_MOTHERBOARD_RESOURCE_HID, 0},
{"", 0},
 };
 MODULE_DEVICE_TABLE(acpi, fjes_acpi_ids);
@@ -115,18 +117,17 @@
},
 };

-static int fjes_acpi_add(struct acpi_device *device)
+static bool is_extended_socket_device(struct acpi_device *device)
 {
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL};
char str_buf[sizeof(FJES_ACPI_SYMBOL) + 1];
-   struct platform_device *plat_dev;
union acpi_object *str;
acpi_status status;
int result;

status = acpi_evaluate_object(device->handle, "_STR", NULL, &buffer);
if (ACPI_FAILURE(status))
-   return -ENODEV;
+   return false;

str = buffer.pointer;
result = utf16s_to_utf8s((wchar_t *)str->string.pointer,
@@ -136,10 +137,21 @@ static int fjes_acpi_add(struct acpi_device *device)

if (strncmp(FJES_ACPI_SYMBOL, str_buf, strlen(FJES_ACPI_SYMBOL)) != 0) {
kfree(buffer.pointer);
-   return -ENODEV;
+   return false;
}
kfree(buffer.pointer);

+   return true;
+}
+
+static int fjes_acpi_add(struct acpi_device *device)
+{
+   struct platform_device *plat_dev;
+   acpi_status status;
+
+   if (!is_extended_socket_device(device))
+   return -ENODEV;
+
status = acpi_walk_resources(device->handle, METHOD_NAME__CRS,
 fjes_get_acpi_resource, fjes_resource);
if (ACPI_FAILURE(status))
@@ -1473,11 +1485,41 @@ static void fjes_watch_unshare_task(struct work_struct 
*work)
}
 }

+static acpi_status
+acpi_find_extended_socket_device(acpi_handle obj_handle, u32 level,
+void *context, void **return_value)
+{
+   struct acpi_device *device;
+   bool *found = context;
+   int result;
+
+   result = acpi_bus_get_device(obj_handle, &device);
+   if (result)
+   return AE_OK;
+
+   if (strcmp(acpi_device_hid(device), ACPI_MOTHERBOARD_RESOURCE_HID))
+   return AE_OK;
+
+   if (!is_extended_socket_device(device))
+   return AE_OK;
+
+   *found = true;
+   return AE_CTRL_TERMINATE;
+}
+
 /* fjes_init_module - Driver Registration Routine */
 static int __init fjes_init_module(void)
 {
+   bool found = false;
int result;

+   acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
+   acpi_find_extended_socket_device, NULL, &found,
+   NULL);
+
+   if (!found)
+   return -ENODEV;
+
pr_info("%s - version %s - %s\n",
fjes_driver_string, fjes_driver_version, fjes_copyright);

-- 
1.8.3.1



On 03/21/2017 11:28 AM, YASUAKI ISHIMATSU wrote:
> The fjes driver is used only by FUJITSU servers and almost of all
> servers in the world never use it. But currently if ACPI PNP0C02
> is defined in the ACPI table, the following message is always shown:
> 
>  "FUJITSU Extended Socket Network Device Driver - version 1.2
>   - Copyright (c) 2015 FUJITSU LIMITED"
> 
> The message makes users confused because there is no reason that
> the message is shown in other vendor servers.
> 
> To avoid the confusion, the patch adds several checks.
> 
> v3:
>   - Rebase on latest net tree.
>   - Add _STA method check to avoid loading fjes driver.
> 
> v2:
>   - Order local variable declarations from longest to shortest line
> 
>

[PATCH v3 2/2] fjes: Do not load fjes driver if extended socket device is not power on.

2017-03-21 Thread YASUAKI ISHIMATSU
The extended device socket cannot turn on/off while system is running.
So when system boots up and the device is not power on, the fjes driver
does not need be loaded.

To check the status of the device, the patch adds ACPI _STA method check.

Signed-off-by: Yasuaki Ishimatsu 
CC: Taku Izumi 
---
 drivers/net/fjes/fjes_main.c | 24 
 1 file changed, 24 insertions(+)

diff --git a/drivers/net/fjes/fjes_main.c b/drivers/net/fjes/fjes_main.c
index 7b58964..ae48c80 100644
--- a/drivers/net/fjes/fjes_main.c
+++ b/drivers/net/fjes/fjes_main.c
@@ -144,6 +144,24 @@ static bool is_extended_socket_device(struct acpi_device 
*device)
return true;
 }

+static int acpi_check_extended_socket_status(struct acpi_device *device)
+{
+   unsigned long long sta;
+   acpi_status status;
+
+   status = acpi_evaluate_integer(device->handle, "_STA", NULL, &sta);
+   if (ACPI_FAILURE(status))
+   return -ENODEV;
+
+   if (!((sta & ACPI_STA_DEVICE_PRESENT) &&
+ (sta & ACPI_STA_DEVICE_ENABLED) &&
+ (sta & ACPI_STA_DEVICE_UI) &&
+ (sta & ACPI_STA_DEVICE_FUNCTIONING)))
+   return -ENODEV;
+
+   return 0;
+}
+
 static int fjes_acpi_add(struct acpi_device *device)
 {
struct platform_device *plat_dev;
@@ -152,6 +170,9 @@ static int fjes_acpi_add(struct acpi_device *device)
if (!is_extended_socket_device(device))
return -ENODEV;

+   if (acpi_check_extended_socket_status(device))
+   return -ENODEV;
+
status = acpi_walk_resources(device->handle, METHOD_NAME__CRS,
 fjes_get_acpi_resource, fjes_resource);
if (ACPI_FAILURE(status))
@@ -1503,6 +1524,9 @@ static void fjes_watch_unshare_task(struct work_struct 
*work)
if (!is_extended_socket_device(device))
return AE_OK;

+   if (acpi_check_extended_socket_status(device))
+   return AE_OK;
+
*found = true;
return AE_CTRL_TERMINATE;
 }
-- 
1.8.3.1


On 03/21/2017 11:28 AM, YASUAKI ISHIMATSU wrote:
> The fjes driver is used only by FUJITSU servers and almost of all
> servers in the world never use it. But currently if ACPI PNP0C02
> is defined in the ACPI table, the following message is always shown:
> 
>  "FUJITSU Extended Socket Network Device Driver - version 1.2
>   - Copyright (c) 2015 FUJITSU LIMITED"
> 
> The message makes users confused because there is no reason that
> the message is shown in other vendor servers.
> 
> To avoid the confusion, the patch adds several checks.
> 
> v3:
>   - Rebase on latest net tree.
>   - Add _STA method check to avoid loading fjes driver.
> 
> v2:
>   - Order local variable declarations from longest to shortest line
> 
> Yasuaki Ishimatsu(2):
>   fjes: Do not load fjes driver if system does not have extended socket 
> device.
>   fjes: Do not load fjes driver if extended socket device is not power on.
> 
>  drivers/net/fjes/fjes_main.c | 76 
> +---
>  1 file changed, 71 insertions(+), 5 deletions(-)
> 


[PATCH v3 0/2] fjes: Do not load fjes driver

2017-03-21 Thread YASUAKI ISHIMATSU
The fjes driver is used only by FUJITSU servers and almost of all
servers in the world never use it. But currently if ACPI PNP0C02
is defined in the ACPI table, the following message is always shown:

 "FUJITSU Extended Socket Network Device Driver - version 1.2
  - Copyright (c) 2015 FUJITSU LIMITED"

The message makes users confused because there is no reason that
the message is shown in other vendor servers.

To avoid the confusion, the patch adds several checks.

v3:
  - Rebase on latest net tree.
  - Add _STA method check to avoid loading fjes driver.

v2:
  - Order local variable declarations from longest to shortest line

Yasuaki Ishimatsu(2):
  fjes: Do not load fjes driver if system does not have extended socket device.
  fjes: Do not load fjes driver if extended socket device is not power on.

 drivers/net/fjes/fjes_main.c | 76 +---
 1 file changed, 71 insertions(+), 5 deletions(-)


Re: [PATCH v2] fjes: Do not load fjes driver if system does not have extended socket device.

2017-03-14 Thread YASUAKI ISHIMATSU



On 03/12/2017 09:02 PM, Izumi, Taku wrote:

Ishimatsu-san,

 Sorry for my late response.



Which tree did you apply the patch to?

The patch can apply to net-next tree with no conflicts as follows:


  Not net-next but net tree:
git://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git


I'll update the patch soon.

Thanks,
Yasuaki Ishimatsu



  I'll review and test your patch soon.

  Sincerely,
  Taku Izumi



# git clone
git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git
Cloning into 'net-next'...
remote: Counting objects: 5265118, done.
remote: Compressing objects: 100% (805485/805485), done.
Receiving objects: 100% (5265118/5265118), 910.11 MiB | 23.42 MiB/s, done.
remote: Total 5265118 (delta 4419240), reused 5264459 (delta 4418809)
Resolving deltas: 100% (4419240/4419240), done.
Checking out files: 100% (58005/58005), done.
# head -n 30 fjes.patch
Subject: [PATCH v2] fjes: Do not load fjes driver if system does not have
extended socket device.
Date: Wed, 8 Mar 2017 16:05:18 -0500
From: Yasuaki Ishimatsu 
To: netdev@vger.kernel.org
CC: David Miller , izumi.t...@jp.fujitsu.com

The fjes driver is used only by FUJITSU servers and almost of all servers
in the world never use it. But currently if ACPI PNP0C02 is defined in the
ACPI table, the following message is always shown:

  "FUJITSU Extended Socket Network Device Driver - version 1.2
   - Copyright (c) 2015 FUJITSU LIMITED"

The message makes users confused because there is no reason that the message
is shown in other vendor servers.

To avoid the confusion, the patch adds a check that the server has a extended
socket device or not.

Signed-off-by: Yasuaki Ishimatsu 
CC: Taku Izumi 
---
v2:
- Order local variable declarations from longest to shortest line

  drivers/net/fjes/fjes_main.c | 52
+++-
  1 file changed, 47 insertions(+), 5 deletions(-)

diff --git a/drivers/net/fjes/fjes_main.c b/drivers/net/fjes/fjes_main.c
index b77e4ecf..a57c2cb 100644 # cd net-next/ # git am ../fjes.patch
Applying: fjes: Do not load fjes driver if system does not have extended
socket device.
#


Thanks,
Yasuaki Ishimatsu




Re: [PATCH v2] fjes: Do not load fjes driver if system does not have extended socket device.

2017-03-14 Thread YASUAKI ISHIMATSU



On 03/12/2017 02:29 PM, Bjørn Mork wrote:

Yasuaki Ishimatsu  writes:


The fjes driver is used only by FUJITSU servers and almost of all
servers in the world never use it. But currently if ACPI PNP0C02
is defined in the ACPI table, the following message is always shown:

 "FUJITSU Extended Socket Network Device Driver - version 1.2
  - Copyright (c) 2015 FUJITSU LIMITED"


Matching on PNP0C02 is fundamentally wrong. It's a way to load a device
driver on all ACPI systems.  You should not do that. I don't think it is
fair to make everyone suffer because of your inability to properly
narrow down the driver matching rules.


There are so many similar matching rules. But these modules are not
listed in blacklist because these modules has proper check like my patch
and no one suffers.

So I don't think the matching rule is fundamentally wrong.

Thanks,
Yasuaki Ishimatsu


Could we please just delete the whole MODULE_DEVICE_TABLE() from this
driver until a proper solution is found? That way we don't need to
blacklist the driver everywhere.





Bjørn



Re: [PATCH v2] fjes: Do not load fjes driver if system does not have extended socket device.

2017-03-10 Thread Yasuaki Ishimatsu



On 03/09/2017 08:35 PM, David Miller wrote:

From: Yasuaki Ishimatsu 
Date: Wed, 8 Mar 2017 16:05:18 -0500


The fjes driver is used only by FUJITSU servers and almost of all
servers in the world never use it. But currently if ACPI PNP0C02
is defined in the ACPI table, the following message is always shown:

 "FUJITSU Extended Socket Network Device Driver - version 1.2
  - Copyright (c) 2015 FUJITSU LIMITED"

The message makes users confused because there is no reason that
the message is shown in other vendor servers.

To avoid the confusion, the patch adds a check that the server
has a extended socket device or not.

Signed-off-by: Yasuaki Ishimatsu 
CC: Taku Izumi 
---
v2:
- Order local variable declarations from longest to shortest line


This patch does not apply cleanly to the net tree.



Which tree did you apply the patch to?

The patch can apply to net-next tree with no conflicts as follows:

# git clone git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git
Cloning into 'net-next'...
remote: Counting objects: 5265118, done.
remote: Compressing objects: 100% (805485/805485), done.
Receiving objects: 100% (5265118/5265118), 910.11 MiB | 23.42 MiB/s, done.
remote: Total 5265118 (delta 4419240), reused 5264459 (delta 4418809)
Resolving deltas: 100% (4419240/4419240), done.
Checking out files: 100% (58005/58005), done.
# head -n 30 fjes.patch
Subject: [PATCH v2] fjes: Do not load fjes driver if system does not have 
extended socket device.
Date: Wed, 8 Mar 2017 16:05:18 -0500
From: Yasuaki Ishimatsu 
To: netdev@vger.kernel.org
CC: David Miller , izumi.t...@jp.fujitsu.com

The fjes driver is used only by FUJITSU servers and almost of all
servers in the world never use it. But currently if ACPI PNP0C02
is defined in the ACPI table, the following message is always shown:

 "FUJITSU Extended Socket Network Device Driver - version 1.2
  - Copyright (c) 2015 FUJITSU LIMITED"

The message makes users confused because there is no reason that
the message is shown in other vendor servers.

To avoid the confusion, the patch adds a check that the server
has a extended socket device or not.

Signed-off-by: Yasuaki Ishimatsu 
CC: Taku Izumi 
---
v2:
- Order local variable declarations from longest to shortest line

 drivers/net/fjes/fjes_main.c | 52 +++-
 1 file changed, 47 insertions(+), 5 deletions(-)

diff --git a/drivers/net/fjes/fjes_main.c b/drivers/net/fjes/fjes_main.c
index b77e4ecf..a57c2cb 100644
# cd net-next/
# git am ../fjes.patch
Applying: fjes: Do not load fjes driver if system does not have extended socket 
device.
#


Thanks,
Yasuaki Ishimatsu


[PATCH v2] fjes: Do not load fjes driver if system does not have extended socket device.

2017-03-08 Thread Yasuaki Ishimatsu

The fjes driver is used only by FUJITSU servers and almost of all
servers in the world never use it. But currently if ACPI PNP0C02
is defined in the ACPI table, the following message is always shown:

 "FUJITSU Extended Socket Network Device Driver - version 1.2
  - Copyright (c) 2015 FUJITSU LIMITED"

The message makes users confused because there is no reason that
the message is shown in other vendor servers.

To avoid the confusion, the patch adds a check that the server
has a extended socket device or not.

Signed-off-by: Yasuaki Ishimatsu 
CC: Taku Izumi 
---
v2:
- Order local variable declarations from longest to shortest line

 drivers/net/fjes/fjes_main.c | 52 +++-
 1 file changed, 47 insertions(+), 5 deletions(-)

diff --git a/drivers/net/fjes/fjes_main.c b/drivers/net/fjes/fjes_main.c
index b77e4ecf..a57c2cb 100644
--- a/drivers/net/fjes/fjes_main.c
+++ b/drivers/net/fjes/fjes_main.c
@@ -45,6 +45,8 @@
 MODULE_LICENSE("GPL");
 MODULE_VERSION(DRV_VERSION);

+#define ACPI_MOTHERBOARD_RESOURCE_HID "PNP0C02"
+
 static int fjes_request_irq(struct fjes_adapter *);
 static void fjes_free_irq(struct fjes_adapter *);

@@ -79,7 +81,7 @@
 static int fjes_poll(struct napi_struct *, int);

 static const struct acpi_device_id fjes_acpi_ids[] = {
-   {"PNP0C02", 0},
+   {ACPI_MOTHERBOARD_RESOURCE_HID, 0},
{"", 0},
 };
 MODULE_DEVICE_TABLE(acpi, fjes_acpi_ids);
@@ -116,18 +118,17 @@
},
 };

-static int fjes_acpi_add(struct acpi_device *device)
+static bool is_extended_socket_device(struct acpi_device *device)
 {
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL};
char str_buf[sizeof(FJES_ACPI_SYMBOL) + 1];
-   struct platform_device *plat_dev;
union acpi_object *str;
acpi_status status;
int result;

status = acpi_evaluate_object(device->handle, "_STR", NULL, &buffer);
if (ACPI_FAILURE(status))
-   return -ENODEV;
+   return false;

str = buffer.pointer;
result = utf16s_to_utf8s((wchar_t *)str->string.pointer,
@@ -137,10 +138,21 @@ static int fjes_acpi_add(struct acpi_device *device)

if (strncmp(FJES_ACPI_SYMBOL, str_buf, strlen(FJES_ACPI_SYMBOL)) != 0) {
kfree(buffer.pointer);
-   return -ENODEV;
+   return false;
}
kfree(buffer.pointer);

+   return true;
+}
+
+static int fjes_acpi_add(struct acpi_device *device)
+{
+   struct platform_device *plat_dev;
+   acpi_status status;
+
+   if (!is_extended_socket_device(device))
+   return -ENODEV;
+
status = acpi_walk_resources(device->handle, METHOD_NAME__CRS,
 fjes_get_acpi_resource, fjes_resource);
if (ACPI_FAILURE(status))
@@ -1476,11 +1488,41 @@ static void fjes_watch_unshare_task(struct work_struct 
*work)
}
 }

+static acpi_status
+acpi_find_extended_socket_device(acpi_handle obj_handle, u32 level,
+void *context, void **return_value)
+{
+   struct acpi_device *device;
+   bool *found = context;
+   int result;
+
+   result = acpi_bus_get_device(obj_handle, &device);
+   if (result)
+   return AE_OK;
+
+   if (strcmp(acpi_device_hid(device), ACPI_MOTHERBOARD_RESOURCE_HID))
+   return AE_OK;
+
+   if (!is_extended_socket_device(device))
+   return AE_OK;
+
+   *found = true;
+   return AE_CTRL_TERMINATE;
+}
+
 /* fjes_init_module - Driver Registration Routine */
 static int __init fjes_init_module(void)
 {
+   bool found = false;
int result;

+   acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
+   acpi_find_extended_socket_device, NULL, &found,
+   NULL);
+
+   if (!found)
+   return -ENODEV;
+
pr_info("%s - version %s - %s\n",
fjes_driver_string, fjes_driver_version, fjes_copyright);

--
1.8.3.1



Re: [PATCH] fjes: Do not load fjes driver if system does not have extended socket device.

2017-03-08 Thread Yasuaki Ishimatsu

Hi David,

On 03/07/2017 04:44 PM, David Miller wrote:

From: Yasuaki Ishimatsu 
Date: Thu, 2 Mar 2017 11:56:44 -0500


+
 /* fjes_init_module - Driver Registration Routine */
 static int __init fjes_init_module(void)
 {
int result;
+   bool found = false;
+


Please order local variable declarations from longest to shortest
line.


Thank you for your review.
I'll update it soon.

Thanks,
Yasuaki Ishimatsu


Thanks.



[PATCH] fjes: Do not load fjes driver if system does not have extended socket device.

2017-03-02 Thread Yasuaki Ishimatsu

The fjes driver is used only by FUJITSU servers and almost of all
servers in the world never use it. But currently if ACPI PNP0C02
is defined in the ACPI table, the following message is always shown:

 "FUJITSU Extended Socket Network Device Driver - version 1.2
  - Copyright (c) 2015 FUJITSU LIMITED"

The message makes users confused because there is no reason that
the message is shown in other vendor servers.

To avoid the confusion, the patch adds a check that the server
has a extended socket device or not.

Signed-off-by: Yasuaki Ishimatsu 
CC: Taku Izumi 
---
 drivers/net/fjes/fjes_main.c | 52 +++-
 1 file changed, 47 insertions(+), 5 deletions(-)

diff --git a/drivers/net/fjes/fjes_main.c b/drivers/net/fjes/fjes_main.c
index b77e4ecf..fe58c01 100644
--- a/drivers/net/fjes/fjes_main.c
+++ b/drivers/net/fjes/fjes_main.c
@@ -45,6 +45,8 @@
 MODULE_LICENSE("GPL");
 MODULE_VERSION(DRV_VERSION);

+#define ACPI_MOTHERBOARD_RESOURCE_HID "PNP0C02"
+
 static int fjes_request_irq(struct fjes_adapter *);
 static void fjes_free_irq(struct fjes_adapter *);

@@ -79,7 +81,7 @@
 static int fjes_poll(struct napi_struct *, int);

 static const struct acpi_device_id fjes_acpi_ids[] = {
-   {"PNP0C02", 0},
+   {ACPI_MOTHERBOARD_RESOURCE_HID, 0},
{"", 0},
 };
 MODULE_DEVICE_TABLE(acpi, fjes_acpi_ids);
@@ -116,18 +118,17 @@
},
 };

-static int fjes_acpi_add(struct acpi_device *device)
+static bool is_extended_socket_device(struct acpi_device *device)
 {
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL};
char str_buf[sizeof(FJES_ACPI_SYMBOL) + 1];
-   struct platform_device *plat_dev;
union acpi_object *str;
acpi_status status;
int result;

status = acpi_evaluate_object(device->handle, "_STR", NULL, &buffer);
if (ACPI_FAILURE(status))
-   return -ENODEV;
+   return false;

str = buffer.pointer;
result = utf16s_to_utf8s((wchar_t *)str->string.pointer,
@@ -137,10 +138,21 @@ static int fjes_acpi_add(struct acpi_device *device)

if (strncmp(FJES_ACPI_SYMBOL, str_buf, strlen(FJES_ACPI_SYMBOL)) != 0) {
kfree(buffer.pointer);
-   return -ENODEV;
+   return false;
}
kfree(buffer.pointer);

+   return true;
+}
+
+static int fjes_acpi_add(struct acpi_device *device)
+{
+   struct platform_device *plat_dev;
+   acpi_status status;
+
+   if (!is_extended_socket_device(device))
+   return -ENODEV;
+
status = acpi_walk_resources(device->handle, METHOD_NAME__CRS,
 fjes_get_acpi_resource, fjes_resource);
if (ACPI_FAILURE(status))
@@ -1476,10 +1488,40 @@ static void fjes_watch_unshare_task(struct work_struct 
*work)
}
 }

+static acpi_status
+acpi_find_extended_socket_device(acpi_handle obj_handle, u32 level,
+void *context, void **return_value)
+{
+   struct acpi_device *device;
+   bool *found = context;
+   int result;
+
+   result = acpi_bus_get_device(obj_handle, &device);
+   if (result)
+   return AE_OK;
+
+   if (strcmp(acpi_device_hid(device), ACPI_MOTHERBOARD_RESOURCE_HID))
+   return AE_OK;
+
+   if (!is_extended_socket_device(device))
+   return AE_OK;
+
+   *found = true;
+   return AE_CTRL_TERMINATE;
+}
+
 /* fjes_init_module - Driver Registration Routine */
 static int __init fjes_init_module(void)
 {
int result;
+   bool found = false;
+
+   acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
+   acpi_find_extended_socket_device, NULL, &found,
+   NULL);
+
+   if (!found)
+   return -ENODEV;

pr_info("%s - version %s - %s\n",
fjes_driver_string, fjes_driver_version, fjes_copyright);
--
1.8.3.1



Re: [PATCH] fjes: Move fjes driver info message into fjes_acpi_add()

2017-02-22 Thread Yasuaki Ishimatsu

Thank you for quick response.
I'll think of other solution.

Thanks,
Yasuaki Ishimatsu

On 02/22/2017 03:45 PM, David Miller wrote:

From: Yasuaki Ishimatsu 
Date: Wed, 22 Feb 2017 15:40:49 -0500


To avoid the confusion, the patch moves the message into
fjes_acpi_add() so that it is shows only when fjes_acpi_add()
succeeded.


This change means it'll never be printed for platform driver matches,
which is even worse than what we have now.



[PATCH] fjes: Move fjes driver info message into fjes_acpi_add()

2017-02-22 Thread Yasuaki Ishimatsu

The fjes driver is used only by FUJITSU servers and almost of all
servers in the world never use it. But currently if ACPI PNP0C02
is defined in the ACPI table, the following message is always shown:

 "FUJITSU Extended Socket Network Device Driver - version 1.2
  - Copyright (c) 2015 FUJITSU LIMITED"

The message makes users confused because there is no reason that
the message is shown in other vendor servers.

To avoid the confusion, the patch moves the message into
fjes_acpi_add() so that it is shows only when fjes_acpi_add()
succeeded.

Signed-off-by: Yasuaki Ishimatsu 
CC: Taku Izumi 
---
 drivers/net/fjes/fjes_main.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/fjes/fjes_main.c b/drivers/net/fjes/fjes_main.c
index b77e4ecf..8e1329c 100644
--- a/drivers/net/fjes/fjes_main.c
+++ b/drivers/net/fjes/fjes_main.c
@@ -151,6 +151,9 @@ static int fjes_acpi_add(struct acpi_device *device)
   ARRAY_SIZE(fjes_resource));
device->driver_data = plat_dev;

+   pr_info("%s - version %s - %s\n",
+   fjes_driver_string, fjes_driver_version, fjes_copyright);
+
return 0;
 }

@@ -1481,9 +1484,6 @@ static int __init fjes_init_module(void)
 {
int result;

-   pr_info("%s - version %s - %s\n",
-   fjes_driver_string, fjes_driver_version, fjes_copyright);
-
fjes_dbg_init();

result = platform_driver_register(&fjes_driver);
--
1.8.3.1



Re: [PATCH v2 18/22] fjes: unshare_watch_task

2015-07-13 Thread Yasuaki Ishimatsu
gt;hw_info.buffer_unshare_reserve_bit);
> +
> + if ((!stop_req ||
> +  (is_shared && (!is_shared || !stop_req_done))) &&
> + (is_shared || !unshare_watch || !unshare_reserve))
> + continue;
> +

> + mutex_lock(&hw->hw_info.lock);
> + ret = fjes_hw_unregister_buff_addr(hw, epidx);
> + switch (ret) {
> + case 0:
> + break;
> + case -ENOMSG:
> + case -EBUSY:
> + default:
> + if (!work_pending(
> + &adapter->force_close_task)) {
> + adapter->force_reset = true;
> + schedule_work(
> + &adapter->force_close_task);
> +         }
> + break;
> + }
> + mutex_unlock(&hw->hw_info.lock);
> +
> + fjes_hw_setup_epbuf(&hw->ep_shm_info[epidx].tx,
> + netdev->dev_addr, netdev->mtu);
> +
> + clear_bit(epidx, &hw->txrx_stop_req_bit);
> + clear_bit(epidx, &unshare_watch_bitmask);
> + clear_bit(epidx,
> +   &hw->hw_info.buffer_unshare_reserve_bit);

How about creating a new function? There are the same codes below.

Thanks,
Yasuaki Ishimatsu

> + }
> +
> + msleep(100);
> + wait_time += 100;
> + }
> +
> + if (hw->hw_info.buffer_unshare_reserve_bit) {
> + for (epidx = 0; epidx < hw->max_epid; epidx++) {
> + if (epidx == hw->my_epid)
> + continue;
> +
> + if (test_bit(epidx,
> +  &hw->hw_info.buffer_unshare_reserve_bit)) {
> + mutex_lock(&hw->hw_info.lock);
> +
> + ret = fjes_hw_unregister_buff_addr(hw, epidx);
> + switch (ret) {
> + case 0:
> + break;
> + case -ENOMSG:
> + case -EBUSY:
> + default:
> + if (!work_pending(
> + &adapter->force_close_task)) {
> + adapter->force_reset = true;
> + schedule_work(
> + 
> &adapter->force_close_task);
> + }
> + break;
> + }
> + mutex_unlock(&hw->hw_info.lock);
> +
> + fjes_hw_setup_epbuf(
> + &hw->ep_shm_info[epidx].tx,
> + netdev->dev_addr, netdev->mtu);
> +
> + clear_bit(epidx, &hw->txrx_stop_req_bit);
> + clear_bit(epidx, &unshare_watch_bitmask);
> + clear_bit(epidx, 
> &hw->hw_info.buffer_unshare_reserve_bit);
> + }
> +
> + if (test_bit(epidx, &unshare_watch_bitmask)) {
> + hw->ep_shm_info[epidx].tx.info->v1i.rx_status &=
> + ~FJES_RX_STOP_REQ_DONE;
> + }
> + }
> + }
> +}
> +
>  /* fjes_init_module - Driver Registration Routine */
>  static int __init fjes_init_module(void)
>  {
> -- 
> 1.8.3.1
> 
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 15/22] fjes: net_device_ops.ndo_vlan_rx_add/kill_vid

2015-07-13 Thread Yasuaki Ishimatsu
Hi Izumi-san,

On Wed, 24 Jun 2015 11:55:47 +0900
Taku Izumi  wrote:

> This patch adds net_device_ops.ndo_vlan_rx_add_vid and
> net_device_ops.ndo_vlan_rx_kill_vid callback.
> 
> Signed-off-by: Taku Izumi 
> ---
>  drivers/net/fjes/fjes_hw.c   | 27 +++
>  drivers/net/fjes/fjes_hw.h   |  2 ++
>  drivers/net/fjes/fjes_main.c | 40 
>  3 files changed, 69 insertions(+)
> 
> diff --git a/drivers/net/fjes/fjes_hw.c b/drivers/net/fjes/fjes_hw.c
> index 5e3f847..8363e22 100644
> --- a/drivers/net/fjes/fjes_hw.c
> +++ b/drivers/net/fjes/fjes_hw.c
> @@ -827,6 +827,33 @@ bool fjes_hw_check_vlan_id(struct epbuf_handler *epbh, 
> u16 vlan_id)
>   return ret;
>  }
>  
> +bool fjes_hw_set_vlan_id(struct epbuf_handler *epbh, u16 vlan_id)
> +{
> + union ep_buffer_info *info = epbh->info;
> + int i;
> +
> + for (i = 0; i < EP_BUFFER_SUPPORT_VLAN_MAX; i++) {
> + if (info->v1i.vlan_id[i] == 0) {
> + info->v1i.vlan_id[i] = vlan_id;
> + return true;
> + }
> + }
> + return false;
> +}
> +
> +void fjes_hw_del_vlan_id(struct epbuf_handler *epbh, u16 vlan_id)
> +{
> + union ep_buffer_info *info = epbh->info;
> + int i;
> +

> + if (0 != vlan_id) {

How about using the following if statement so than you can delete
indent?

if (vlan_id == 0)
return;

> + for (i = 0; i < EP_BUFFER_SUPPORT_VLAN_MAX; i++) {
> + if (vlan_id == info->v1i.vlan_id[i])
> + info->v1i.vlan_id[i] = 0;
> + }
> + }
> +}
> +
>  bool fjes_hw_epbuf_rx_is_empty(struct epbuf_handler *epbh)
>  {
>   union ep_buffer_info *info = epbh->info;
> diff --git a/drivers/net/fjes/fjes_hw.h b/drivers/net/fjes/fjes_hw.h
> index ea30aeb..afad03e 100644
> --- a/drivers/net/fjes/fjes_hw.h
> +++ b/drivers/net/fjes/fjes_hw.h
> @@ -321,6 +321,8 @@ int fjes_hw_epid_is_shared(struct fjes_device_shared_info 
> *, int);
>  bool fjes_hw_check_epbuf_version(struct epbuf_handler *, u32);
>  bool fjes_hw_check_mtu(struct epbuf_handler *, u32);
>  bool fjes_hw_check_vlan_id(struct epbuf_handler *, u16);
> +bool fjes_hw_set_vlan_id(struct epbuf_handler *, u16);
> +void fjes_hw_del_vlan_id(struct epbuf_handler *, u16);
>  bool fjes_hw_epbuf_rx_is_empty(struct epbuf_handler *);
>  void *fjes_hw_epbuf_rx_curpkt_get_addr(struct epbuf_handler *, size_t *);
>  void fjes_hw_epbuf_rx_curpkt_drop(struct epbuf_handler *);
> diff --git a/drivers/net/fjes/fjes_main.c b/drivers/net/fjes/fjes_main.c
> index e2e69e0..bb4c8e4 100644
> --- a/drivers/net/fjes/fjes_main.c
> +++ b/drivers/net/fjes/fjes_main.c
> @@ -58,6 +58,8 @@ static irqreturn_t fjes_intr(int, void*);
>  static struct rtnl_link_stats64 *
>  fjes_get_stats64(struct net_device *, struct rtnl_link_stats64 *);
>  static int fjes_change_mtu(struct net_device *, int);
> +static int fjes_vlan_rx_add_vid(struct net_device *, __be16 proto, u16);
> +static int fjes_vlan_rx_kill_vid(struct net_device *, __be16 proto, u16);
>  static void fjes_tx_retry(struct net_device *);
>  
>  static int fjes_acpi_add(struct acpi_device *);
> @@ -229,6 +231,8 @@ static const struct net_device_ops fjes_netdev_ops = {
>   .ndo_get_stats64= fjes_get_stats64,
>   .ndo_change_mtu = fjes_change_mtu,
>   .ndo_tx_timeout = fjes_tx_retry,
> + .ndo_vlan_rx_add_vid= fjes_vlan_rx_add_vid,
> + .ndo_vlan_rx_kill_vid = fjes_vlan_rx_kill_vid,
>  };
>  
>  /* fjes_open - Called when a network interface is made active */
> @@ -757,6 +761,42 @@ static int fjes_change_mtu(struct net_device *netdev, 
> int new_mtu)
>   return -EINVAL;
>  }
>  
> +static int fjes_vlan_rx_add_vid(struct net_device *netdev,
> + __be16 proto, u16 vid)
> +{
> + struct fjes_adapter *adapter = netdev_priv(netdev);
> + bool ret = true;
> + int epid;
> +
> + for (epid = 0; epid < adapter->hw.max_epid; epid++) {
> + if (epid == adapter->hw.my_epid)
> + continue;
> +
> + if (!fjes_hw_check_vlan_id(
> + &adapter->hw.ep_shm_info[epid].tx, vid))
> + ret = fjes_hw_set_vlan_id(
> + &adapter->hw.ep_shm_info[epid].tx, vid);
> + }
> +
> + return ret ? 0 : -ENOSPC;
> +}
> +

> +static int fjes_vlan_rx_kill_vid(struct net_device *netdev,
> +  __be16 proto, u16 vid)

The function always returns 0. So how about defining the function
as void?

Thanks,
Ysauaki Ishimatsu

> +{
> + struct fjes_adapter *adapter = netdev_priv(netdev);
> + int epid;
> +
> + for (epid = 0; epid < adapter->hw.max_epid; epid++) {
> + if (epid == adapter->hw.my_epid)
> + continue;
> +
> + fjes_hw_del_vlan_id(&adapter->hw.ep_shm_info[epid].tx, vid);
> + }
> +
> + return 0;
> +}
> +
>  static i

Re: [PATCH v2 10/22] fjes: tx_stall_task

2015-07-13 Thread Yasuaki Ishimatsu
Hi Izum-san,

On Wed, 24 Jun 2015 11:55:42 +0900
Taku Izumi  wrote:

> This patch adds tx_stall_task.
> When receiver's buffer is full, sender stops
> its tx queue. This task is used to monitor
> receiver's status and when receiver's buffer
> is avairable, it resumes tx queue.
> 
> Signed-off-by: Taku Izumi 
> ---
>  drivers/net/fjes/fjes.h  |  2 ++
>  drivers/net/fjes/fjes_main.c | 63 
> 
>  2 files changed, 65 insertions(+)
> 
> diff --git a/drivers/net/fjes/fjes.h b/drivers/net/fjes/fjes.h
> index 8e9899e..b04ea9d 100644
> --- a/drivers/net/fjes/fjes.h
> +++ b/drivers/net/fjes/fjes.h
> @@ -30,6 +30,7 @@
>  #define FJES_MAX_QUEUES  1
>  #define FJES_TX_RETRY_INTERVAL   (20 * HZ)
>  #define FJES_TX_RETRY_TIMEOUT(100)
> +#define FJES_TX_TX_STALL_TIMEOUT (FJES_TX_RETRY_INTERVAL / 2)
>  #define FJES_OPEN_ZONE_UPDATE_WAIT   (300) /* msec */
>  
>  /* board specific private data structure */
> @@ -52,6 +53,7 @@ struct fjes_adapter {
>  
>   struct workqueue_struct *txrx_wq;
>  
> + struct work_struct tx_stall_task;
>   struct work_struct raise_intr_rxdata_task;
>  
>   struct fjes_hw hw;
> diff --git a/drivers/net/fjes/fjes_main.c b/drivers/net/fjes/fjes_main.c
> index 735aa5e..f4c2445 100644
> --- a/drivers/net/fjes/fjes_main.c
> +++ b/drivers/net/fjes/fjes_main.c
> @@ -53,6 +53,7 @@ static int fjes_setup_resources(struct fjes_adapter *);
>  static void fjes_free_resources(struct fjes_adapter *);
>  static netdev_tx_t fjes_xmit_frame(struct sk_buff *, struct net_device *);
>  static void fjes_raise_intr_rxdata_task(struct work_struct *);
> +static void fjes_tx_stall_task(struct work_struct *);
>  static irqreturn_t fjes_intr(int, void*);
>  
>  static int fjes_acpi_add(struct acpi_device *);
> @@ -281,6 +282,7 @@ static int fjes_close(struct net_device *netdev)
>   fjes_free_irq(adapter);
>  
>   cancel_work_sync(&adapter->raise_intr_rxdata_task);
> + cancel_work_sync(&adapter->tx_stall_task);
>  
>   fjes_hw_wait_epstop(hw);
>  
> @@ -410,6 +412,61 @@ static void fjes_free_resources(struct fjes_adapter 
> *adapter)
>   }
>  }
>  
> +static void fjes_tx_stall_task(struct work_struct *work)
> +{
> + struct fjes_adapter *adapter = container_of(work,
> + struct fjes_adapter, tx_stall_task);
> + struct fjes_hw *hw = &adapter->hw;
> + struct net_device *netdev = adapter->netdev;
> + enum ep_partner_status pstatus;
> + int epid;
> + int max_epid, my_epid;
> + union ep_buffer_info *info;
> + int all_queue_available;
> + int i;
> + int sendable;
> +
> + if (((long)jiffies -
> + (long)(netdev->trans_start)) > FJES_TX_TX_STALL_TIMEOUT) {
> + netif_wake_queue(netdev);
> + return;
> + }
> +
> + my_epid = hw->my_epid;
> + max_epid = hw->max_epid;
> +

> + for (i = 0; i < 5; i++) {

Why do you loop 5 times?

Thanks,
Yasuaki Ishimatsu

> + all_queue_available = 1;
> +
> + for (epid = 0; epid < max_epid; epid++) {
> + if (my_epid == epid)
> + continue;
> +
> + pstatus = fjes_hw_get_partner_ep_status(hw, epid);
> + sendable = (pstatus == EP_PARTNER_SHARED);
> + if (!sendable)
> + continue;
> +
> + info = adapter->hw.ep_shm_info[epid].tx.info;
> +
> + if (EP_RING_FULL(info->v1i.head, info->v1i.tail,
> +  info->v1i.count_max)) {
> + all_queue_available = 0;
> + break;
> + }
> + }
> +
> + if (all_queue_available) {
> + netif_wake_queue(netdev);
> + return;
> + }
> + }
> +
> + usleep_range(50, 100);
> +
> + queue_work(adapter->txrx_wq, &adapter->tx_stall_task);
> +}
> +
>  static void fjes_raise_intr_rxdata_task(struct work_struct *work)
>  {
>   struct fjes_adapter *adapter = container_of(work,
> @@ -606,6 +663,10 @@ fjes_xmit_frame(struct sk_buff *skb, struct net_device 
> *netdev)
>   netdev->trans_start = jiffies;
>   netif_tx_stop_queue(cur_queue);
>  
> + if 
> (!work_pending(&adapter->tx_stall_task))
> +

Re: [PATCH v2 08/22] fjes: net_device_ops.ndo_start_xmit

2015-07-10 Thread Yasuaki Ishimatsu
stats
> + .tx_carrier_errors += 1;
> +
> + ret = NETDEV_TX_OK;
> + } else if (!fjes_hw_check_mtu(
> + &adapter->hw.ep_shm_info[dest_epid].rx,
> + netdev->mtu)) {

> + adapter->stats64.tx_dropped += 1;
> + hw->ep_shm_info[my_epid].net_stats.tx_dropped += 1;
> + adapter->stats64.tx_errors += 1;
> + hw->ep_shm_info[my_epid].net_stats.tx_errors += 1;

There are same codes in the fjes_xmit_frame().
How about create a new function to unify them?

> +
> + ret = NETDEV_TX_OK;
> + } else if (vlan &&
> +!fjes_hw_check_vlan_id(
> + &adapter->hw.ep_shm_info[dest_epid].rx,
> + vlan_id)) {
> + ret = NETDEV_TX_OK;
> + } else {
> + if (len < VLAN_ETH_HLEN) {
> + memset(shortpkt, 0, VLAN_ETH_HLEN);
> + memcpy(shortpkt, skb->data, skb->len);
> + len = VLAN_ETH_HLEN;
> + data = shortpkt;
> + }
> +
> + if (adapter->tx_retry_count == 0) {
> + adapter->tx_start_jiffies = jiffies;
> + adapter->tx_retry_count = 1;
> + } else {
> + adapter->tx_retry_count++;
> + }
> +
> + if (fjes_tx_send(adapter, dest_epid, data, len)) {
> + if (is_multi) {
> + ret = NETDEV_TX_OK;
> + } else if (
> +((long)jiffies -
> + (long)adapter->tx_start_jiffies) >=
> + FJES_TX_RETRY_TIMEOUT) {
> + adapter->stats64.tx_fifo_errors += 1;
> + hw->ep_shm_info[my_epid].net_stats
> + .tx_fifo_errors 
> += 1;
> + adapter->stats64.tx_errors += 1;
> + hw->ep_shm_info[my_epid].net_stats
> + .tx_errors += 1;
> +
> + ret = NETDEV_TX_OK;
> + } else {
> + netdev->trans_start = jiffies;
> + netif_tx_stop_queue(cur_queue);
> +

> + ret = NETDEV_TX_BUSY;

Even if ret set NETDEV_TX_BUSY, it may be changed to NETDEV_TX_OK
in the for loop. Is it OK?

> + }
> + } else {
> + if (!is_multi) {
> + adapter->stats64.tx_packets += 1;
> + hw->ep_shm_info[my_epid].net_stats
> + .tx_packets += 
> 1;
> + adapter->stats64.tx_bytes += len;
> + hw->ep_shm_info[my_epid].net_stats
> + .tx_bytes += 
> len;
> + }
> +
> + adapter->tx_retry_count = 0;
> + ret = NETDEV_TX_OK;
> + }
> + }
> + }
> +
> + if (ret == NETDEV_TX_OK) {
> + dev_kfree_skb(skb);
> + if (is_multi) {
> + adapter->stats64.tx_packets += 1;
> + hw->ep_shm_info[my_epid].net_stats.tx_packets += 1;

> + adapter->stats64.tx_bytes += 1;
adapter->stats64.tx_bytes +=len?

Thanks,
Yasuaki Ishimatsu

> + hw->ep_shm_info[my_epid].net_stats.tx_bytes += len;
> + }
> + }
> +
> + return ret;
> +}
> +
>  static irqreturn_t fjes_intr(int irq, void *data)
>  {
>   struct fjes_adapter *adapter = data;
> -- 
> 1.8.3.1
> 
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 06/22] fjes: buffer address regist/unregistration routine

2015-07-07 Thread Yasuaki Ishimatsu

On Wed, 24 Jun 2015 11:55:38 +0900
Taku Izumi  wrote:

> This patch adds buffer address regist/unregistration routine.
> 
> This function is mainly invoked when network device's
> activation (open) and deactivation (close)
> in order to retist/unregist shared buffer address.
> 
> Signed-off-by: Taku Izumi 
> ---
>  drivers/net/fjes/fjes_hw.c | 187 
> +
>  drivers/net/fjes/fjes_hw.h |   9 ++-
>  2 files changed, 195 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/fjes/fjes_hw.c b/drivers/net/fjes/fjes_hw.c
> index 1ffa62e..4451e70 100644
> --- a/drivers/net/fjes/fjes_hw.c
> +++ b/drivers/net/fjes/fjes_hw.c
> @@ -453,6 +453,193 @@ int fjes_hw_request_info(struct fjes_hw *hw)
>   return result;
>  }
>  
> +int fjes_hw_register_buff_addr(struct fjes_hw *hw, int dest_epid,
> +struct ep_share_mem_info *buf_pair)
> +{
> + union fjes_device_command_req *req_buf = hw->hw_info.req_buf;
> + union fjes_device_command_res *res_buf = hw->hw_info.res_buf;
> + enum fjes_dev_command_response_e ret;
> + int i, idx;
> + int page_count;
> + void *addr;
> + int timeout;
> + int result;
> +
> + if (test_bit(dest_epid, &hw->hw_info.buffer_share_bit))
> + return 0;
> +
> + memset(req_buf, 0, hw->hw_info.req_buf_size);
> + memset(res_buf, 0, hw->hw_info.res_buf_size);
> +
> + req_buf->share_buffer.length =
> + FJES_DEV_COMMAND_SHARE_BUFFER_REQ_LEN(buf_pair->tx.size,
> +   buf_pair->rx.size);
> + req_buf->share_buffer.epid = dest_epid;
> +
> + idx = 0;
> + req_buf->share_buffer.buffer[idx++] = buf_pair->tx.size;
> + page_count = buf_pair->tx.size / EP_BUFFER_INFO_SIZE;
> + for (i = 0; i < page_count; i++) {
> + addr = ((u8 *)(buf_pair->tx.buffer)) +
> + (i * EP_BUFFER_INFO_SIZE);
> + req_buf->share_buffer.buffer[idx++] =
> + (__le64)(page_to_phys(vmalloc_to_page(addr)) +
> + offset_in_page(addr));
> + }
> +
> + req_buf->share_buffer.buffer[idx++] = buf_pair->rx.size;
> + page_count = buf_pair->rx.size / EP_BUFFER_INFO_SIZE;
> + for (i = 0; i < page_count; i++) {
> + addr = ((u8 *)(buf_pair->rx.buffer)) +
> + (i * EP_BUFFER_INFO_SIZE);
> + req_buf->share_buffer.buffer[idx++] =
> + (__le64)(page_to_phys(vmalloc_to_page(addr)) +
> + offset_in_page(addr));
> + }
> +

> + res_buf->share_buffer.length = 0;
> + res_buf->share_buffer.code = 0;
> +
> + ret = fjes_hw_issue_request_command(hw, FJES_CMD_REQ_SHARE_BUFFER);
> +
> + timeout = FJES_COMMAND_REQ_BUFF_TIMEOUT * 1000;
> + while ((ret == FJES_CMD_STATUS_NORMAL) &&
> +(res_buf->share_buffer.length ==
> + FJES_DEV_COMMAND_SHARE_BUFFER_RES_LEN) &&
> +(res_buf->share_buffer.code == FJES_CMD_REQ_RES_CODE_BUSY) &&
> +(timeout > 0)) {
> + msleep(200 + hw->my_epid * 20);
> + timeout -= (200 + hw->my_epid * 20);
> +
> + res_buf->share_buffer.length = 0;
> + res_buf->share_buffer.code = 0;
> +
> + ret =
> + fjes_hw_issue_request_command(hw,
> +   
> FJES_CMD_REQ_SHARE_BUFFER);
> + }
> +
> + result = 0;
> +
> + if (res_buf->share_buffer.length !=
> + FJES_DEV_COMMAND_SHARE_BUFFER_RES_LEN)
> + result = -ENOMSG;
> + else if (ret == FJES_CMD_STATUS_NORMAL) {
> + switch (res_buf->share_buffer.code) {
> + case FJES_CMD_REQ_RES_CODE_NORMAL:
> + result = 0;
> + set_bit(dest_epid, &hw->hw_info.buffer_share_bit);
> + break;
> + case FJES_CMD_REQ_RES_CODE_BUSY:
> + result = -EBUSY;
> + break;
> + default:
> + result = -EPERM;
> + break;
> + }
> + } else {
> + switch (ret) {
> + case FJES_CMD_STATUS_UNKNOWN:
> + result = -EPERM;
> + break;
> + case FJES_CMD_STATUS_TIMEOUT:
> + result = -EBUSY;

Re: [PATCH v2 02/22] fjes: Hardware initialization routine

2015-07-07 Thread Yasuaki Ishimatsu
OMEM;
> +
> + hw->hw_info.share->epnum = hw->max_epid;
> +
> + return 0;
> +}
> +
> +static int fjes_hw_alloc_epbuf(struct epbuf_handler *epbh)
> +{
> + void *mem;
> +
> + mem = vzalloc(EP_BUFFER_SIZE);
> + if (!mem)
> + return -ENOMEM;
> +
> + epbh->buffer = mem;
> + epbh->size = EP_BUFFER_SIZE;
> +
> + epbh->info = (union ep_buffer_info *)mem;
> + epbh->ring = (u8 *)(mem + sizeof(union ep_buffer_info));
> +
> + return 0;
> +}
> +
> +void fjes_hw_setup_epbuf(struct epbuf_handler *epbh, u8 *mac_addr, u32 mtu)
> +{
> + union ep_buffer_info *info = epbh->info;
> + int i;
> + u16 vlan_id[EP_BUFFER_SUPPORT_VLAN_MAX];
> +
> + for (i = 0; i < EP_BUFFER_SUPPORT_VLAN_MAX; i++)
> + vlan_id[i] = info->v1i.vlan_id[i];
> +
> + memset(info, 0, sizeof(union ep_buffer_info));
> +
> + info->v1i.version = 0;  /* version 0 */
> +
> + for (i = 0; i < ETH_ALEN; i++)
> + info->v1i.mac_addr[i] = mac_addr[i];
> +
> + info->v1i.head = 0;
> + info->v1i.tail = 1;
> +
> + info->v1i.info_size = sizeof(union ep_buffer_info);
> + info->v1i.buffer_size = epbh->size - info->v1i.info_size;
> +
> + info->v1i.frame_max = FJES_MTU_TO_FRAME_SIZE(mtu);
> + info->v1i.count_max =
> + EP_RING_NUM(info->v1i.buffer_size, info->v1i.frame_max);
> +
> + for (i = 0; i < EP_BUFFER_SUPPORT_VLAN_MAX; i++)
> + info->v1i.vlan_id[i] = vlan_id[i];
> +}
> +
> +void
> +fjes_hw_init_command_registers(struct fjes_hw *hw,
> +struct fjes_device_command_param *param)
> +{
> + /* Request Buffer length */
> + wr32(XSCT_REQBL, (__le32)(param->req_len));
> + /* Response Buffer Length */
> + wr32(XSCT_RESPBL, (__le32)(param->res_len));
> +
> + /* Request Buffer Address */
> + wr32(XSCT_REQBAL,
> +  (__le32)(param->req_start & GENMASK_ULL(31, 0)));
> + wr32(XSCT_REQBAH,
> +  (__le32)((param->req_start & GENMASK_ULL(63, 32)) >> 32));
> +
> + /* Response Buffer Address */
> + wr32(XSCT_RESPBAL,
> +  (__le32)(param->res_start & GENMASK_ULL(31, 0)));
> + wr32(XSCT_RESPBAH,
> +  (__le32)((param->res_start & GENMASK_ULL(63, 32)) >> 32));
> +
> + /* Share status address */
> + wr32(XSCT_SHSTSAL,
> +  (__le32)(param->share_start & GENMASK_ULL(31, 0)));
> + wr32(XSCT_SHSTSAH,
> +  (__le32)((param->share_start & GENMASK_ULL(63, 32)) >> 32));
> +}
> +
> +static int fjes_hw_setup(struct fjes_hw *hw)
> +{
> + int epidx;
> + void *buf;
> + struct ep_share_mem_info *buf_pair;
> + size_t mem_size;
> + int result;
> + u8 mac[ETH_ALEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
> + struct fjes_device_command_param param;
> +
> + hw->hw_info.max_epid = &hw->max_epid;
> + hw->hw_info.my_epid = &hw->my_epid;
> +
> + buf =
> + kcalloc(hw->max_epid,
> + sizeof(struct ep_share_mem_info), GFP_KERNEL);
> + if (!buf)
> + return -ENOMEM;
> +
> + hw->ep_shm_info = (struct ep_share_mem_info *)buf;
> +
> + mem_size = FJES_DEV_REQ_BUF_SIZE(hw->max_epid);
> + hw->hw_info.req_buf = kzalloc(mem_size, GFP_KERNEL);
> + if (!(hw->hw_info.req_buf))
> + return -ENOMEM;
> +
> + hw->hw_info.req_buf_size = mem_size;
> +
> + mem_size = FJES_DEV_RES_BUF_SIZE(hw->max_epid);
> + hw->hw_info.res_buf = kzalloc(mem_size, GFP_KERNEL);
> + if (!(hw->hw_info.res_buf))
> + return -ENOMEM;
> +
> + hw->hw_info.res_buf_size = mem_size;
> +
> + result = fjes_hw_alloc_shared_status_region(hw);
> + if (result)
> + return result;
> +
> + hw->hw_info.buffer_share_bit = 0;
> + hw->hw_info.buffer_unshare_reserve_bit = 0;
> +
> + for (epidx = 0; epidx < hw->max_epid; epidx++) {

> + if (epidx != hw->my_epid) {

How about use the following condition so that you can delete a indent.

if (epidx == hw->my_epid)
continue;

Thanks,
Yasuaki Ishimatsu

> + buf_pair = &hw->ep_shm_info[epidx];
> +
> + result = fjes_hw_alloc_epbuf(&buf_pair->tx);
> + if (result)
> + return result;
> +
> + result = fjes_hw_alloc_epbuf(&buf_pair->rx);
> +  

Re: [PATCH v2 06/22] fjes: buffer address regist/unregistration routine

2015-07-06 Thread Yasuaki Ishimatsu

On Wed, 24 Jun 2015 11:55:38 +0900
Taku Izumi  wrote:

> This patch adds buffer address regist/unregistration routine.
> 
> This function is mainly invoked when network device's
> activation (open) and deactivation (close)

> in order to retist/unregist shared buffer address.
  register/unregister

> 
> Signed-off-by: Taku Izumi 
> ---
>  drivers/net/fjes/fjes_hw.c | 187 
> +
>  drivers/net/fjes/fjes_hw.h |   9 ++-
>  2 files changed, 195 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/fjes/fjes_hw.c b/drivers/net/fjes/fjes_hw.c
> index 1ffa62e..4451e70 100644
> --- a/drivers/net/fjes/fjes_hw.c
> +++ b/drivers/net/fjes/fjes_hw.c
> @@ -453,6 +453,193 @@ int fjes_hw_request_info(struct fjes_hw *hw)
>   return result;
>  }
>  
> +int fjes_hw_register_buff_addr(struct fjes_hw *hw, int dest_epid,
> +struct ep_share_mem_info *buf_pair)
> +{
> + union fjes_device_command_req *req_buf = hw->hw_info.req_buf;
> + union fjes_device_command_res *res_buf = hw->hw_info.res_buf;
> + enum fjes_dev_command_response_e ret;
> + int i, idx;
> + int page_count;
> + void *addr;
> + int timeout;
> + int result;
> +
> + if (test_bit(dest_epid, &hw->hw_info.buffer_share_bit))
> + return 0;
> +
> + memset(req_buf, 0, hw->hw_info.req_buf_size);
> + memset(res_buf, 0, hw->hw_info.res_buf_size);
> +
> + req_buf->share_buffer.length =
> + FJES_DEV_COMMAND_SHARE_BUFFER_REQ_LEN(buf_pair->tx.size,
> +   buf_pair->rx.size);
> + req_buf->share_buffer.epid = dest_epid;
> +
> + idx = 0;
> + req_buf->share_buffer.buffer[idx++] = buf_pair->tx.size;
> + page_count = buf_pair->tx.size / EP_BUFFER_INFO_SIZE;
> + for (i = 0; i < page_count; i++) {
> + addr = ((u8 *)(buf_pair->tx.buffer)) +
> + (i * EP_BUFFER_INFO_SIZE);
> + req_buf->share_buffer.buffer[idx++] =
> + (__le64)(page_to_phys(vmalloc_to_page(addr)) +
> + offset_in_page(addr));
> + }
> +
> + req_buf->share_buffer.buffer[idx++] = buf_pair->rx.size;
> + page_count = buf_pair->rx.size / EP_BUFFER_INFO_SIZE;
> + for (i = 0; i < page_count; i++) {
> + addr = ((u8 *)(buf_pair->rx.buffer)) +
> + (i * EP_BUFFER_INFO_SIZE);
> + req_buf->share_buffer.buffer[idx++] =
> + (__le64)(page_to_phys(vmalloc_to_page(addr)) +
> + offset_in_page(addr));
> + }
> +
> + res_buf->share_buffer.length = 0;
> + res_buf->share_buffer.code = 0;
> +
> + ret = fjes_hw_issue_request_command(hw, FJES_CMD_REQ_SHARE_BUFFER);
> +
> + timeout = FJES_COMMAND_REQ_BUFF_TIMEOUT * 1000;
> + while ((ret == FJES_CMD_STATUS_NORMAL) &&
> +(res_buf->share_buffer.length ==
> + FJES_DEV_COMMAND_SHARE_BUFFER_RES_LEN) &&
> +(res_buf->share_buffer.code == FJES_CMD_REQ_RES_CODE_BUSY) &&
> +(timeout > 0)) {
> + msleep(200 + hw->my_epid * 20);
> + timeout -= (200 + hw->my_epid * 20);
> +
> + res_buf->share_buffer.length = 0;
> + res_buf->share_buffer.code = 0;
> +
> + ret =
> + fjes_hw_issue_request_command(hw,
> +   
> FJES_CMD_REQ_SHARE_BUFFER);
> + }
> +
> + result = 0;
> +
> + if (res_buf->share_buffer.length !=
> + FJES_DEV_COMMAND_SHARE_BUFFER_RES_LEN)
> + result = -ENOMSG;
> + else if (ret == FJES_CMD_STATUS_NORMAL) {
> + switch (res_buf->share_buffer.code) {
> + case FJES_CMD_REQ_RES_CODE_NORMAL:
> + result = 0;
> + set_bit(dest_epid, &hw->hw_info.buffer_share_bit);
> + break;
> + case FJES_CMD_REQ_RES_CODE_BUSY:
> + result = -EBUSY;
> + break;
> + default:
> + result = -EPERM;
> + break;
> + }
> + } else {
> + switch (ret) {
> + case FJES_CMD_STATUS_UNKNOWN:
> + result = -EPERM;
> + break;
> + case FJES_CMD_STATUS_TIMEOUT:
> + result = -EBUSY;
> + break;
> + case FJES_CMD_STATUS_ERROR_PARAM:
> + case FJES_CMD_STATUS_ERROR_STATUS:
> + default:
> + result = -EPERM;
> + break;
> + }
> + }
> +
> + return result;
> +}
> +
> +int fjes_hw_unregister_buff_addr(struct fjes_hw *hw, int dest_epid)
> +{
> + union fjes_device_command_req *req_buf = hw->hw_info.req_buf;
> +  

Re: [PATCH 02/22] fjes: Hardware initialization routine

2015-06-19 Thread Yasuaki Ishimatsu
   return -ENOMEM;
> +
> + hw->hw_info.share->epnum = hw->max_epid;
> +
> + return 0;
> +}
> +
> +static int fjes_hw_alloc_epbuf(struct epbuf_handler *epbh)
> +{
> + void *mem;
> +

> + mem = vmalloc(EP_BUFFER_SIZE);
> + if (!mem)
> + return -ENOMEM;
> + memset(mem, 0, EP_BUFFER_SIZE);

How about use vzalloc().

> +
> + epbh->buffer = mem;
> + epbh->size = EP_BUFFER_SIZE;
> +
> + epbh->info = (union ep_buffer_info *)mem;
> + epbh->ring = (u8 *) (mem + sizeof(union ep_buffer_info));
> +
> + return 0;
> +}
> +
> +void fjes_hw_setup_epbuf(struct epbuf_handler *epbh, u8 *mac_addr, u32 mtu)
> +{
> +
> + union ep_buffer_info *info = epbh->info;
> + int i;
> + u16 vlan_id[EP_BUFFER_SUPPORT_VLAN_MAX];
> +
> + for (i = 0; i < EP_BUFFER_SUPPORT_VLAN_MAX; i++)
> + vlan_id[i] = info->v1i.vlan_id[i];
> +
> + memset((void *)info, 0, sizeof(union ep_buffer_info));
> +
> + info->v1i.version = 0;  /* version 0 */
> +
> + for (i = 0; i < ETH_ALEN; i++)
> + info->v1i.mac_addr[i] = mac_addr[i];
> +
> + info->v1i.head = 0;
> + info->v1i.tail = 1;
> +
> + info->v1i.info_size = sizeof(union ep_buffer_info);
> + info->v1i.buffer_size = epbh->size - info->v1i.info_size;
> +
> + info->v1i.frame_max = FJES_MTU_TO_FRAME_SIZE(mtu);
> + info->v1i.count_max =
> + EP_RING_NUM(info->v1i.buffer_size, info->v1i.frame_max);
> +
> + for (i = 0; i < EP_BUFFER_SUPPORT_VLAN_MAX; i++)
> + info->v1i.vlan_id[i] = vlan_id[i];
> +
> +}
> +
> +
> +void fjes_hw_init_command_registers(struct fjes_hw *hw,
> + struct fjes_device_command_param *param)
> +{
> +
> + /* Request Buffer length */
> + wr32(XSCT_REQBL, (__le32)(param->req_len));
> + /* Response Buffer Length */
> + wr32(XSCT_RESPBL, (__le32)(param->res_len));
> +
> + /* Request Buffer Address */
> + wr32(XSCT_REQBAL,
> + (__le32)(param->req_start & GENMASK_ULL(31, 0)));
> + wr32(XSCT_REQBAH,
> + (__le32)((param->req_start & GENMASK_ULL(63, 32)) >> 32));
> +
> + /* Response Buffer Address */
> + wr32(XSCT_RESPBAL,
> + (__le32)(param->res_start & GENMASK_ULL(31, 0)));
> + wr32(XSCT_RESPBAH,
> + (__le32)((param->res_start & GENMASK_ULL(63, 32)) >> 32));
> +
> + /* Share status address */
> + wr32(XSCT_SHSTSAL,
> + (__le32)(param->share_start & GENMASK_ULL(31, 0)));
> + wr32(XSCT_SHSTSAH,
> + (__le32)((param->share_start & GENMASK_ULL(63, 32)) >> 32));
> +}
> +
> +static int fjes_hw_setup(struct fjes_hw *hw)
> +{
> + int epidx;
> + void *buf;
> + struct ep_share_mem_info *buf_pair;
> + size_t mem_size;
> + int result;
> + u8 mac[ETH_ALEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
> + struct fjes_device_command_param param;
> +
> + hw->hw_info.max_epid = &(hw->max_epid);
> + hw->hw_info.my_epid = &(hw->my_epid);
> +
> +
> + mem_size = sizeof(struct ep_share_mem_info) * (hw->max_epid);
> + buf = kzalloc(mem_size, GFP_KERNEL);
> + if (!buf)
> + return -ENOMEM;
> +
> + hw->ep_shm_info = (struct ep_share_mem_info *)buf;
> +
> + mem_size = FJES_DEV_REQ_BUF_SIZE(hw->max_epid);
> + hw->hw_info.req_buf = kzalloc(mem_size, GFP_KERNEL);
> + if (!(hw->hw_info.req_buf))
> + return -ENOMEM;
> +
> + hw->hw_info.req_buf_size = mem_size;
> +
> + mem_size = FJES_DEV_RES_BUF_SIZE(hw->max_epid);
> + hw->hw_info.res_buf = kzalloc(mem_size, GFP_KERNEL);
> + if (!(hw->hw_info.res_buf))
> + return -ENOMEM;
> +
> + hw->hw_info.res_buf_size = mem_size;
> +
> + result = fjes_hw_alloc_shared_status_region(hw);
> + if (result)
> + return result;
> +
> + hw->hw_info.buffer_share_bit = 0;
> + hw->hw_info.buffer_unshare_reserve_bit = 0;
> +
> + for (epidx = 0; epidx < hw->max_epid; epidx++) {
> + if (epidx != hw->my_epid) {
> + buf_pair = &(hw->ep_shm_info[epidx]);
> +
> +     result = fjes_hw_alloc_epbuf(&(buf_pair->tx));
> + if (result)
> + return result;
> +
> + result = fjes_hw_alloc_epbuf(&(buf_pair->rx));
> + if (result)
> +