Re: regression: UFO removal breaks kvm live migration

2017-11-07 Thread Jason Wang



On 2017年11月08日 15:26, David Miller wrote:

From: Willem de Bruijn 
Date: Wed, 8 Nov 2017 12:36:26 +0900


On Tue, Nov 7, 2017 at 5:02 PM, Michal Kubecek  wrote:

I didn't have time to think it through yet but perhaps we could allow
setting TUN_F_UFO and ignore its value.

If the feature is enabled guests may try to send UFO packets, which
the host is no longer able to fragment.

virtio_net_hdr_to_skb will drop the packets immediately based on
gso_type and tun_get_user will return EINVAL.

Still, perhaps that's preferable as migration will succeed and most
guests won't ever try to send those packets in the first place.

However, this would create the situation where there is no way
to properly probe for the actual presence of UFO support.


I think we should not have any assumption on how guest will use the 
feature. So I could not come a better than bring it back partially for 
TAP, looks like we only need segment them in tun_get_user().


Thanks


Re: [PATCH net-next v3] net: mvpp2: add ethtool GOP statistics

2017-11-07 Thread Miquel RAYNAL
Hi David,

> > On Wed, Nov 08, 2017 at 01:54:56PM +0900, David Miller wrote:  
> >> From: Miquel Raynal 
> >> Date: Mon,  6 Nov 2017 22:56:53 +0100
> >>   
> >> > Add ethtool statistics support by reading the GOP statistics
> >> > from the hardware counters. Also implement a workqueue to gather
> >> > the statistics every second or some 32-bit counters could
> >> > overflow.
> >> > 
> >> > Suggested-by: Stefan Chulski 
> >> > Signed-off-by: Miquel Raynal   
> >> 
> >> Applied, thanks.  
> > 
> > Miquèl actually sent a v4 of this patch, fixing an issue found in
> > previous versions (including this one) of this patch.  
> 
> Oops, Miquel please send a relative fix.

No problem, I will send you a fix.

Thanks,
Miquèl



Re: [PATCH] Bluetooth: Use common error handling code in bt_init()

2017-11-07 Thread Marcel Holtmann
Hi Markus,

> * Improve jump targets so that a bit of exception handling can be better
>  reused at the end of this function.
> 
> * Adjust five condition checks.
> 
> This issue was detected by using the Coccinelle software.
> 
> Signed-off-by: Markus Elfring 
> ---
> net/bluetooth/af_bluetooth.c | 38 +-
> 1 file changed, 17 insertions(+), 21 deletions(-)

patch has been applied to bluetooth-next tree.

Regards

Marcel



Re: mlx5 broken affinity

2017-11-07 Thread Sagi Grimberg



Depending on the machine and the number of queues this might even result in
completely losing the ability to suspend/hibernate because the number of
available vectors on CPU0 is not sufficient to accomodate all queue
interrupts.


Would it be possible to keep the managed facility until a user overrides
an affinity assignment? This way if the user didn't touch it, we keep
all the perks, and in case the user overrides it, we log the implication
so the user is aware?


A lot of things are possible, the question is whether it makes sense. The
whole point is to have resources (queues, interrupts etc.) per CPU and have
them strictly associated.


Not arguing here.


Why would you give the user a knob to destroy what you carefully optimized?


Well, looks like someone relies on this knob, the question is if he is
doing something better for his workload. I don't know, its really up to
the user to say.


Just because we can and just because users love those knobs or is there any
real technical reason?


Again, I think Jes or others can provide more information.


[PATCH v2] af_netlink: give correct bounds to dump skb for NLMSG_DONE

2017-11-07 Thread Jason A. Donenfeld
The way people generally use netlink_dump is that they fill in the skb
as much as possible, breaking when nla_put returns an error. Then, they
get called again and start filling out the next skb, and again, and so
forth. The mechanism at work here is the ability for the iterative
dumping function to detect when the skb is filled up and not fill it
past the brim, waiting for a fresh skb for the rest of the data.

However, if the attributes are small and nicely packed, it is possible
that a dump callback function successfully fills in attributes until the
skb is of size 4080 (libmnl's default page-sized receive buffer size).
The dump function completes, satisfied, and then, if it happens to be
that this is actually the last skb, and no further ones are to be sent,
then netlink_dump will add on the NLMSG_DONE part:

  nlh = nlmsg_put_answer(skb, cb, NLMSG_DONE, sizeof(len), NLM_F_MULTI);

It is very important that netlink_dump does this, of course. However, in
this example, that call to nlmsg_put_answer will fail, because the
previous filling by the dump function did not leave it enough room. And
how could it possibly have done so? All of the nla_put variety of
functions simply check to see if the skb has enough tailroom,
independent of the context it is in.

In order to keep the important assumptions of all netlink dump users, it
is therefore important to give them an skb that has this end part of the
tail already reserved, so that the call to nlmsg_put_answer does not
fail. Otherwise, library authors are forced to find some bizarre sized
receive buffer that has a large modulo relative to the common sizes of
messages received, which is ugly and buggy.

This patch thus saves the NLMSG_DONE for an additional message, for the
case that things are dangerously close to the brim. This requires
keeping track of the errno from ->dump() across calls.

Signed-off-by: Jason A. Donenfeld 
---
Changes v1->v2:
  - This implements things without having to twiddle with the skb, at
the expense of potentially having an extra back-and-forth and quite
a bit of added complexity.


 net/netlink/af_netlink.c | 14 --
 net/netlink/af_netlink.h |  1 +
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index b93148e8e9fb..7020689e643e 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -2136,7 +2136,7 @@ static int netlink_dump(struct sock *sk)
struct sk_buff *skb = NULL;
struct nlmsghdr *nlh;
struct module *module;
-   int len, err = -ENOBUFS;
+   int err = -ENOBUFS;
int alloc_min_size;
int alloc_size;
 
@@ -2183,9 +2183,10 @@ static int netlink_dump(struct sock *sk)
skb_reserve(skb, skb_tailroom(skb) - alloc_size);
netlink_skb_set_owner_r(skb, sk);
 
-   len = cb->dump(skb, cb);
+   if (nlk->dump_done_errno > 0)
+   nlk->dump_done_errno = cb->dump(skb, cb);
 
-   if (len > 0) {
+   if (nlk->dump_done_errno > 0 || skb_tailroom(skb) < 
nlmsg_total_size(sizeof(nlk->dump_done_errno))) {
mutex_unlock(nlk->cb_mutex);
 
if (sk_filter(sk, skb))
@@ -2195,13 +2196,13 @@ static int netlink_dump(struct sock *sk)
return 0;
}
 
-   nlh = nlmsg_put_answer(skb, cb, NLMSG_DONE, sizeof(len), NLM_F_MULTI);
-   if (!nlh)
+   nlh = nlmsg_put_answer(skb, cb, NLMSG_DONE, 
sizeof(nlk->dump_done_errno), NLM_F_MULTI);
+   if (WARN_ON(!nlh))
goto errout_skb;
 
nl_dump_check_consistent(cb, nlh);
 
-   memcpy(nlmsg_data(nlh), , sizeof(len));
+   memcpy(nlmsg_data(nlh), >dump_done_errno, 
sizeof(nlk->dump_done_errno));
 
if (sk_filter(sk, skb))
kfree_skb(skb);
@@ -2273,6 +2274,7 @@ int __netlink_dump_start(struct sock *ssk, struct sk_buff 
*skb,
}
 
nlk->cb_running = true;
+   nlk->dump_done_errno = INT_MAX;
 
mutex_unlock(nlk->cb_mutex);
 
diff --git a/net/netlink/af_netlink.h b/net/netlink/af_netlink.h
index 028188597eaa..962de7b3c023 100644
--- a/net/netlink/af_netlink.h
+++ b/net/netlink/af_netlink.h
@@ -34,6 +34,7 @@ struct netlink_sock {
wait_queue_head_t   wait;
boolbound;
boolcb_running;
+   int dump_done_errno;
struct netlink_callback cb;
struct mutex*cb_mutex;
struct mutexcb_def_mutex;
-- 
2.15.0



[PATCH net-next 1/2] net: hns3: fix a bug when getting phy address from NCL_config file

2017-11-07 Thread Lipeng
From: Fuyun Liang 

Driver gets phy address from NCL_config file and uses the phy address
to initialize phydev. There are 5 bits for phy address. And C22 phy
address has 5 bits. So 0-31 are all valid address for phy. If there
is no phy, it will crash. Because driver always get a valid phy address.

This patch fixes the phy address to 8 bits, and use 0xff to indicate
invalid phy address.

Fixes: 46a3df9f9718 (net: hns3: Add HNS3 Acceleration Engine & Compatibility 
Layer Support)
Signed-off-by: Fuyun Liang 
Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index 844c83e..ce5ed88 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -390,7 +390,7 @@ struct hclge_pf_res_cmd {
 #define HCLGE_CFG_TQP_DESC_N_S 16
 #define HCLGE_CFG_TQP_DESC_N_M GENMASK(31, 16)
 #define HCLGE_CFG_PHY_ADDR_S   0
-#define HCLGE_CFG_PHY_ADDR_M   GENMASK(4, 0)
+#define HCLGE_CFG_PHY_ADDR_M   GENMASK(7, 0)
 #define HCLGE_CFG_MEDIA_TP_S   8
 #define HCLGE_CFG_MEDIA_TP_M   GENMASK(15, 8)
 #define HCLGE_CFG_RX_BUF_LEN_S 16
-- 
1.9.1



[PATCH net-next 2/2] net: hns3: cleanup mac auto-negotiation state query in hclge_update_speed_duplex

2017-11-07 Thread Lipeng
From: Fuyun Liang 

When checking whether auto-negotiation is on, driver only needs to
check the value of mac.autoneg(SW) directly, and does not need to
query it from hardware. Because this value is always synchronized
with the auto-negotiation state of hardware.

This patch removes mac auto-negotiation state query in
hclge_update_speed_duplex().

Fixes: 46a3df9f9718 (net: hns3: Add HNS3 Acceleration Engine & Compatibility 
Layer Support)
Signed-off-by: Fuyun Liang 
Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 13 +
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index c6ba890..781d5a8 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -2325,18 +2325,7 @@ static int hclge_update_speed_duplex(struct hclge_dev 
*hdev)
/* get the speed and duplex as autoneg'result from mac cmd when phy
 * doesn't exit.
 */
-   if (mac.phydev)
-   return 0;
-
-   /* update mac->antoneg. */
-   ret = hclge_query_autoneg_result(hdev);
-   if (ret) {
-   dev_err(>pdev->dev,
-   "autoneg result query failed %d\n", ret);
-   return ret;
-   }
-
-   if (!mac.autoneg)
+   if (mac.phydev || !mac.autoneg)
return 0;
 
ret = hclge_query_mac_an_speed_dup(hdev, , );
-- 
1.9.1



[PATCH net-next 0/2] net: hns3: Bug fixes & Code improvements in HNS3 driver

2017-11-07 Thread Lipeng
This patch-set introduces some bug fixes and code improvements.
As [patch 1/2] depends on the patch {5392902 net: hns3: Consistently using
GENMASK in hns3 driver}, which exists in net-next, not exists in net, so
push this serise to nex-next.

Fuyun Liang (2):
  {topost} net: hns3: fix a bug when getting phy address from NCL_config
file
  {topost} net: hns3: cleanup mac auto-negotiation state query in
hclge_update_speed_duplex

 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h  |  2 +-
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 13 +
 2 files changed, 2 insertions(+), 13 deletions(-)

-- 
1.9.1



[net 3/6] net/mlx5: FPGA, return -EINVAL if size is zero

2017-11-07 Thread Saeed Mahameed
From: Kamal Heib 

In the current code, if a size of zero is passed to
mlx5_fpga_mem_{read|write}_i2c() functions the "err"
return value will not initialized.

Fixes: a9956d35d199 ('net/mlx5: FPGA, Add SBU infrastructure')
Signed-off-by: Kamal Heib 
Reviewed-by: Yevgeny Kliteynik 
Signed-off-by: Saeed Mahameed 
---
 drivers/net/ethernet/mellanox/mlx5/core/fpga/sdk.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/fpga/sdk.c 
b/drivers/net/ethernet/mellanox/mlx5/core/fpga/sdk.c
index 3c11d6e2160a..14962969c5ba 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/fpga/sdk.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/fpga/sdk.c
@@ -66,6 +66,9 @@ static int mlx5_fpga_mem_read_i2c(struct mlx5_fpga_device 
*fdev, size_t size,
u8 actual_size;
int err;
 
+   if (!size)
+   return -EINVAL;
+
if (!fdev->mdev)
return -ENOTCONN;
 
@@ -95,6 +98,9 @@ static int mlx5_fpga_mem_write_i2c(struct mlx5_fpga_device 
*fdev, size_t size,
u8 actual_size;
int err;
 
+   if (!size)
+   return -EINVAL;
+
if (!fdev->mdev)
return -ENOTCONN;
 
-- 
2.14.2



[net 4/6] net/mlx5e: Fix napi poll with zero budget

2017-11-07 Thread Saeed Mahameed
napi->poll can be called with budget 0, e.g. in netpoll scenarios
where the caller only wants to poll TX rings
(poll_one_napi@net/core/netpoll.c).

The below commit changed RX polling from "while" loop to "do {} while",
which caused to ignore the initial budget and handle at least one RX
packet.

This fixes the following warning:
[ 2852.049194] mlx5e_napi_poll+0x0/0x260 [mlx5_core] exceeded budget in poll
[ 2852.049195] [ cut here ]
[ 2852.049195] WARNING: CPU: 0 PID: 25691 at net/core/netpoll.c:171 
netpoll_poll_dev+0x18a/0x1a0

Fixes: 4b7dfc992514 ("net/mlx5e: Early-return on empty completion queues")
Signed-off-by: Saeed Mahameed 
Reviewed-by: Tariq Toukan 
Reported-by: Martin KaFai Lau 
Tested-by: Martin KaFai Lau 
Cc: kernel-t...@fb.com
Signed-off-by: Saeed Mahameed 
---
 drivers/net/ethernet/mellanox/mlx5/core/en_txrx.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_txrx.c 
b/drivers/net/ethernet/mellanox/mlx5/core/en_txrx.c
index e906b754415c..ab92298eafc3 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_txrx.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_txrx.c
@@ -49,7 +49,7 @@ int mlx5e_napi_poll(struct napi_struct *napi, int budget)
struct mlx5e_channel *c = container_of(napi, struct mlx5e_channel,
   napi);
bool busy = false;
-   int work_done;
+   int work_done = 0;
int i;
 
for (i = 0; i < c->num_tc; i++)
@@ -58,15 +58,17 @@ int mlx5e_napi_poll(struct napi_struct *napi, int budget)
if (c->xdp)
busy |= mlx5e_poll_xdpsq_cq(>rq.xdpsq.cq);
 
-   work_done = mlx5e_poll_rx_cq(>rq.cq, budget);
-   busy |= work_done == budget;
+   if (likely(budget)) { /* budget=0 means: don't poll rx rings */
+   work_done = mlx5e_poll_rx_cq(>rq.cq, budget);
+   busy |= work_done == budget;
+   }
 
busy |= c->rq.post_wqes(>rq);
 
if (busy) {
if (likely(mlx5e_channel_no_affinity_change(c)))
return budget;
-   if (work_done == budget)
+   if (budget && work_done == budget)
work_done--;
}
 
-- 
2.14.2



[net 2/6] net/mlx5: Cancel health poll before sending panic teardown command

2017-11-07 Thread Saeed Mahameed
From: Huy Nguyen 

After the panic teardown firmware command, health_care detects the error
in PCI bus and calls the mlx5_pci_err_detected. This health_care flow is
no longer needed because the panic teardown firmware command will bring
down the PCI bus communication with the HCA.

The solution is to cancel the health care timer and its pending
workqueue request before sending panic teardown firmware command.

Kernel trace:
mlx5_core 0033:01:00.0: Shutdown was called
mlx5_core 0033:01:00.0: health_care:154:(pid 9304): handling bad device here
mlx5_core 0033:01:00.0: mlx5_handle_bad_state:114:(pid 9304): NIC state 1
mlx5_core 0033:01:00.0: mlx5_pci_err_detected was called
mlx5_core 0033:01:00.0: mlx5_enter_error_state:96:(pid 9304): start
mlx5_3:mlx5_ib_event:3061:(pid 9304): warning: event on port 0
mlx5_core 0033:01:00.0: mlx5_enter_error_state:104:(pid 9304): end
Unable to handle kernel paging request for data at address 0x003f
Faulting instruction address: 0xc008434b8c80

Fixes: 8812c24d28f4 ('net/mlx5: Add fast unload support in shutdown flow')
Signed-off-by: Huy Nguyen 
Reviewed-by: Majd Dibbiny 
Signed-off-by: Saeed Mahameed 
---
 drivers/net/ethernet/mellanox/mlx5/core/main.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/main.c 
b/drivers/net/ethernet/mellanox/mlx5/core/main.c
index 0d2c8dcd6eae..06562c9a6b9c 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/main.c
@@ -1482,9 +1482,16 @@ static int mlx5_try_fast_unload(struct mlx5_core_dev 
*dev)
return -EAGAIN;
}
 
+   /* Panic tear down fw command will stop the PCI bus communication
+* with the HCA, so the health polll is no longer needed.
+*/
+   mlx5_drain_health_wq(dev);
+   mlx5_stop_health_poll(dev);
+
ret = mlx5_cmd_force_teardown_hca(dev);
if (ret) {
mlx5_core_dbg(dev, "Firmware couldn't do fast unload error: 
%d\n", ret);
+   mlx5_start_health_poll(dev);
return ret;
}
 
-- 
2.14.2



[net 5/6] net/mlx5e: Set page to null in case dma mapping fails

2017-11-07 Thread Saeed Mahameed
From: Inbar Karmy 

Currently, when dma mapping fails, put_page is called,
but the page is not set to null. Later, in the page_reuse treatment in
mlx5e_free_rx_descs(), mlx5e_page_release() is called for the second time,
improperly doing dma_unmap (for a non-mapped address) and an extra put_page.
Prevent this by nullifying the page pointer when dma_map fails.

Fixes: accd58833237 ("net/mlx5e: Introduce RX Page-Reuse")
Signed-off-by: Inbar Karmy 
Reviewed-by: Tariq Toukan 
Cc: kernel-t...@fb.com
Signed-off-by: Saeed Mahameed 
---
 drivers/net/ethernet/mellanox/mlx5/core/en_rx.c | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c 
b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
index 15a1687483cc..91b1b0938931 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
@@ -215,22 +215,20 @@ static inline bool mlx5e_rx_cache_get(struct mlx5e_rq *rq,
 static inline int mlx5e_page_alloc_mapped(struct mlx5e_rq *rq,
  struct mlx5e_dma_info *dma_info)
 {
-   struct page *page;
-
if (mlx5e_rx_cache_get(rq, dma_info))
return 0;
 
-   page = dev_alloc_pages(rq->buff.page_order);
-   if (unlikely(!page))
+   dma_info->page = dev_alloc_pages(rq->buff.page_order);
+   if (unlikely(!dma_info->page))
return -ENOMEM;
 
-   dma_info->addr = dma_map_page(rq->pdev, page, 0,
+   dma_info->addr = dma_map_page(rq->pdev, dma_info->page, 0,
  RQ_PAGE_SIZE(rq), rq->buff.map_dir);
if (unlikely(dma_mapping_error(rq->pdev, dma_info->addr))) {
-   put_page(page);
+   put_page(dma_info->page);
+   dma_info->page = NULL;
return -ENOMEM;
}
-   dma_info->page = page;
 
return 0;
 }
-- 
2.14.2



[net 6/6] net/mlx5e: Increase Striding RQ minimum size limit to 4 multi-packet WQEs

2017-11-07 Thread Saeed Mahameed
From: Eugenia Emantayev 

This is to prevent the case of working with a single MPWQE
(1 WQE is always reserved as RQ is linked-list).
When the WQE is fully consumed, HW should still have available buffer
in order not to drop packets.

Fixes: 461017cb006a ("net/mlx5e: Support RX multi-packet WQE (Striding RQ)")
Signed-off-by: Eugenia Emantayev 
Reviewed-by: Tariq Toukan 
Cc: kernel-t...@fb.com
Signed-off-by: Saeed Mahameed 
---
 drivers/net/ethernet/mellanox/mlx5/core/en.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en.h 
b/drivers/net/ethernet/mellanox/mlx5/core/en.h
index cc13d3dbd366..13b5ef9d8703 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en.h
@@ -67,7 +67,7 @@
 #define MLX5E_PARAMS_DEFAULT_LOG_RQ_SIZE0xa
 #define MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE0xd
 
-#define MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE_MPW0x1
+#define MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE_MPW0x2
 #define MLX5E_PARAMS_DEFAULT_LOG_RQ_SIZE_MPW0x3
 #define MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE_MPW0x6
 
-- 
2.14.2



[net 1/6] net/mlx5: Loop over temp list to release delay events

2017-11-07 Thread Saeed Mahameed
From: Huy Nguyen 

list_splice_init initializing waiting_events_list after splicing it to
temp list, therefore we should loop over temp list to fire the events.

Fixes: 4ca637a20a52 ("net/mlx5: Delay events till mlx5 interface's add complete 
for pci resume")
Signed-off-by: Huy Nguyen 
Signed-off-by: Feras Daoud 
Signed-off-by: Saeed Mahameed 
---
 drivers/net/ethernet/mellanox/mlx5/core/dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/dev.c 
b/drivers/net/ethernet/mellanox/mlx5/core/dev.c
index fc281712869b..17b723218b0c 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/dev.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/dev.c
@@ -93,7 +93,7 @@ static void delayed_event_release(struct mlx5_device_context 
*dev_ctx,
list_splice_init(>waiting_events_list, );
if (!dev_ctx->context)
goto out;
-   list_for_each_entry_safe(de, n, >waiting_events_list, list)
+   list_for_each_entry_safe(de, n, , list)
dev_ctx->intf->event(dev, dev_ctx->context, de->event, 
de->param);
 
 out:
-- 
2.14.2



[pull request][net 0/6] Mellanox, mlx5 fixes 2017-11-08

2017-11-07 Thread Saeed Mahameed
Hi Dave,

The follwoing series includes some fixes for mlx5 core and etherent
driver.

Sorry for the late submission but as you can see i have some very
critical fixes below that i would like them merged into this RC. 

Please pull and let me know if there is any problem.

For -stable:
('net/mlx5e: Set page to null in case dma mapping fails') kernels >= 4.13
('net/mlx5: FPGA, return -EINVAL if size is zero') kernels >= 4.13
('net/mlx5: Cancel health poll before sending panic teardown command') kernels 
>= 4.13

Thanks,
Saeed.

--- 

The following changes since commit 7fd078337201cf7468f53c3d9ef81ff78cb6df3b:

  net: qmi_wwan: fix divide by 0 on bad descriptors (2017-11-08 13:42:43 +0900)

are available in the git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/saeed/linux.git 
tags/mlx5-fixes-2017-11-08

for you to fetch changes up to a45ff49e52ba34e1607a6bf228bad56a5a9469b8:

  net/mlx5e: Increase Striding RQ minimum size limit to 4 multi-packet WQEs 
(2017-11-07 21:36:21 -0800)


mlx5-fixes-2017-11-08

This series includes some fixes for mlx5 core and ethernet driver.


Eugenia Emantayev (1):
  net/mlx5e: Increase Striding RQ minimum size limit to 4 multi-packet WQEs

Huy Nguyen (2):
  net/mlx5: Loop over temp list to release delay events
  net/mlx5: Cancel health poll before sending panic teardown command

Inbar Karmy (1):
  net/mlx5e: Set page to null in case dma mapping fails

Kamal Heib (1):
  net/mlx5: FPGA, return -EINVAL if size is zero

Saeed Mahameed (1):
  net/mlx5e: Fix napi poll with zero budget

 drivers/net/ethernet/mellanox/mlx5/core/dev.c  |  2 +-
 drivers/net/ethernet/mellanox/mlx5/core/en.h   |  2 +-
 drivers/net/ethernet/mellanox/mlx5/core/en_rx.c| 12 +---
 drivers/net/ethernet/mellanox/mlx5/core/en_txrx.c  | 10 ++
 drivers/net/ethernet/mellanox/mlx5/core/fpga/sdk.c |  6 ++
 drivers/net/ethernet/mellanox/mlx5/core/main.c |  7 +++
 6 files changed, 26 insertions(+), 13 deletions(-)


Re: [PATCH v2 iproute2] libnetlink: Handle extack messages for non-error case

2017-11-07 Thread Ido Schimmel
On Tue, Nov 07, 2017 at 08:05:18PM -0800, David Ahern wrote:
> Kernel can now return non-fatal error messages in extack facility.
> Update iproute2 to dump to use if present.
> - rename nl_dump_ext_err to nl_dump_ext_ack
> - rename errmsg to msg
> - add call to nl_dump_ext_ack in rtnl_dump_done and __rtnl_talk for
>   non-error path
> 
> Signed-off-by: David Ahern 

Tested-by: Ido Schimmel 


Re: [PATCH net-next 0/2] net: hns3: Bug fixes & Code improvements in HNS3 driver

2017-11-07 Thread lipeng (Y)

please ignore this patch-set.

I should remove  "{topost}" from the subject.

sorry for that, I will resend the patch-set.


On 2017/11/8 15:31, Lipeng wrote:

This patch-set introduces some bug fixes and code improvements.
As [patch 1/2] depends on the patch {5392902 net: hns3: Consistently using
GENMASK in hns3 driver}, which exists in net-next, not exists in net, so
push this serise to nex-next.

Fuyun Liang (2):
   {topost} net: hns3: fix a bug when getting phy address from NCL_config
 file
   {topost} net: hns3: cleanup mac auto-negotiation state query in
 hclge_update_speed_duplex

  drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h  |  2 +-
  drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 13 +
  2 files changed, 2 insertions(+), 13 deletions(-)






[PATCH] Bluetooth: Use common error handling code in bt_init()

2017-11-07 Thread SF Markus Elfring
From: Markus Elfring 
Date: Wed, 8 Nov 2017 08:03:04 +0100

* Improve jump targets so that a bit of exception handling can be better
  reused at the end of this function.

* Adjust five condition checks.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring 
---
 net/bluetooth/af_bluetooth.c | 38 +-
 1 file changed, 17 insertions(+), 21 deletions(-)

diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c
index 91e3ba280706..f044202346c6 100644
--- a/net/bluetooth/af_bluetooth.c
+++ b/net/bluetooth/af_bluetooth.c
@@ -766,43 +766,39 @@ static int __init bt_init(void)
return err;
 
err = sock_register(_sock_family_ops);
-   if (err < 0) {
-   bt_sysfs_cleanup();
-   return err;
-   }
+   if (err)
+   goto cleanup_sysfs;
 
BT_INFO("HCI device and connection manager initialized");
 
err = hci_sock_init();
-   if (err < 0)
-   goto error;
+   if (err)
+   goto unregister_socket;
 
err = l2cap_init();
-   if (err < 0)
-   goto sock_err;
+   if (err)
+   goto cleanup_socket;
 
err = sco_init();
-   if (err < 0) {
-   l2cap_exit();
-   goto sock_err;
-   }
+   if (err)
+   goto cleanup_cap;
 
err = mgmt_init();
-   if (err < 0) {
-   sco_exit();
-   l2cap_exit();
-   goto sock_err;
-   }
+   if (err)
+   goto cleanup_sco;
 
return 0;
 
-sock_err:
+cleanup_sco:
+   sco_exit();
+cleanup_cap:
+   l2cap_exit();
+cleanup_socket:
hci_sock_cleanup();
-
-error:
+unregister_socket:
sock_unregister(PF_BLUETOOTH);
+cleanup_sysfs:
bt_sysfs_cleanup();
-
return err;
 }
 
-- 
2.15.0



Re: [PATCH net-next v17] openvswitch: enable NSH support

2017-11-07 Thread David Miller
From: Yi Yang 
Date: Tue,  7 Nov 2017 21:07:02 +0800

 ...
> OVS master and 2.8 branch has merged NSH userspace
> patch series, this patch is to enable NSH support
> in kernel data path in order that OVS can support
> NSH in compat mode by porting this.
> 
> Signed-off-by: Yi Yang 
> Acked-by: Jiri Benc 
> Acked-by: Eric Garver 
> Acked-by: Pravin Shelar 

Applied, thanks!


Re: [PATCH net] qmi_wwan: Add missing skb_reset_mac_header-call

2017-11-07 Thread David Miller
From: Kristian Evensen 
Date: Tue,  7 Nov 2017 13:47:56 +0100

> When we receive a packet on a QMI device in raw IP mode, we should call
> skb_reset_mac_header() to ensure that skb->mac_header contains a valid
> offset in the packet. While it shouldn't really matter, the packets have
> no MAC header and the interface is configured as-such, it seems certain
> parts of the network stack expects a "good" value in skb->mac_header.
> 
> Without the skb_reset_mac_header() call added in this patch, for example
> shaping traffic (using tc) triggers the following oops on the first
> received packet:
 ...
> While the oops is for a 4.9-kernel, I was able to trigger the same oops with
> net-next as of yesterday.
> 
> Signed-off-by: Kristian Evensen 

Applied, with Fixes: tag added, and queued up for -stable.

Thanks!


Re: [PATCH net] bonding: fix slave stuck in BOND_LINK_FAIL state

2017-11-07 Thread David Miller
From: Jay Vosburgh 
Date: Tue, 07 Nov 2017 19:50:07 +0900

>   The bonding miimon logic has a flaw, in that a failure of the
> rtnl_trylock can cause a slave to become permanently stuck in
> BOND_LINK_FAIL state.
> 
>   The sequence of events to cause this is as follows:
> 
>   1) bond_miimon_inspect finds that a slave's link is down, and so
> calls bond_propose_link_state, setting slave->new_link_state to
> BOND_LINK_FAIL, then sets slave->new_link to BOND_LINK_DOWN and returns
> non-zero.
> 
>   2) In bond_mii_monitor, the rtnl_trylock fails, and the timer is
> rescheduled.  No change is committed.
> 
>   3) bond_miimon_inspect is called again, but this time the slave
> from step 1 has recovered.  slave->new_link is reset to NOCHANGE, and, as
> slave->link was never changed, the switch enters the BOND_LINK_UP case,
> and does nothing.  The pending BOND_LINK_FAIL state from step 1 remains
> pending, as new_link_state is not reset.
> 
>   4) The state from step 3 persists until another slave changes link
> state and causes bond_miimon_inspect to return non-zero.  At this point,
> the BOND_LINK_FAIL state change on the slave from steps 1-3 is committed,
> and the slave will remain stuck in BOND_LINK_FAIL state even though it
> is actually link up.
> 
>   The remedy for this is to initialize new_link_state on each entry
> to bond_miimon_inspect, as is already done with new_link.
> 
> Reported-by: Alex Sidorenko 
> Reviewed-by: Jarod Wilson 
> Signed-off-by: Jay Vosburgh 
> Fixes: fb9eb899a6dc ("bonding: handle link transition from FAIL to UP 
> correctly")

Applied and queued up for -stable.

As discussed with some others here at netdev... rtnl_trylock() really needs
to be re-evaluated if not removed completely.


Re: [PATCH] af_netlink: give correct bounds to dump skb for NLMSG_DONE

2017-11-07 Thread Jason A. Donenfeld
Erf, your patch doesn't handle what happens if len comes back
negative, but I'll fix it up and send a v2 using this approach.

I think I really prefer v1 though.

Jason


[PATCH net-next 1/2] {topost} net: hns3: fix a bug when getting phy address from NCL_config file

2017-11-07 Thread Lipeng
From: Fuyun Liang 

Driver gets phy address from NCL_config file and uses the phy address
to initialize phydev. There are 5 bits for phy address. And C22 phy
address has 5 bits. So 0-31 are all valid address for phy. If there
is no phy, it will crash. Because driver always get a valid phy address.

This patch fixes the phy address to 8 bits, and use 0xff to indicate
invalid phy address.

Fixes: 46a3df9f9718 (net: hns3: Add HNS3 Acceleration Engine & Compatibility 
Layer Support)
Signed-off-by: Fuyun Liang 
Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index 844c83e..ce5ed88 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -390,7 +390,7 @@ struct hclge_pf_res_cmd {
 #define HCLGE_CFG_TQP_DESC_N_S 16
 #define HCLGE_CFG_TQP_DESC_N_M GENMASK(31, 16)
 #define HCLGE_CFG_PHY_ADDR_S   0
-#define HCLGE_CFG_PHY_ADDR_M   GENMASK(4, 0)
+#define HCLGE_CFG_PHY_ADDR_M   GENMASK(7, 0)
 #define HCLGE_CFG_MEDIA_TP_S   8
 #define HCLGE_CFG_MEDIA_TP_M   GENMASK(15, 8)
 #define HCLGE_CFG_RX_BUF_LEN_S 16
-- 
1.9.1



[PATCH net-next 2/2] {topost} net: hns3: cleanup mac auto-negotiation state query in hclge_update_speed_duplex

2017-11-07 Thread Lipeng
From: Fuyun Liang 

When checking whether auto-negotiation is on, driver only needs to
check the value of mac.autoneg(SW) directly, and does not need to
query it from hardware. Because this value is always synchronized
with the auto-negotiation state of hardware.

This patch removes mac auto-negotiation state query in
hclge_update_speed_duplex().

Fixes: 46a3df9f9718 (net: hns3: Add HNS3 Acceleration Engine & Compatibility 
Layer Support)
Signed-off-by: Fuyun Liang 
Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 13 +
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index c6ba890..781d5a8 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -2325,18 +2325,7 @@ static int hclge_update_speed_duplex(struct hclge_dev 
*hdev)
/* get the speed and duplex as autoneg'result from mac cmd when phy
 * doesn't exit.
 */
-   if (mac.phydev)
-   return 0;
-
-   /* update mac->antoneg. */
-   ret = hclge_query_autoneg_result(hdev);
-   if (ret) {
-   dev_err(>pdev->dev,
-   "autoneg result query failed %d\n", ret);
-   return ret;
-   }
-
-   if (!mac.autoneg)
+   if (mac.phydev || !mac.autoneg)
return 0;
 
ret = hclge_query_mac_an_speed_dup(hdev, , );
-- 
1.9.1



Re: [lldp-devel] Fwd: [PATCH RESEND] Fix segfault on "lldptool -t -i eth2 -V PFC -c enabled"

2017-11-07 Thread Hannes Reinecke
On 11/07/2017 04:56 PM, Sowmini Varadhan wrote:
> 
> We are trying to use DCBX via lldpad for some of our applications,
> and finding/fixing bugs and enhancements as we go. 
> 
> However our attempts to upstream these fixes is encountering silence
> from the lldp-devel list e.g.,
>   http://lists.open-lldp.org/pipermail/lldp-devel/2017-October/001252.html
> 
> Any suggestions on available options for the care and feeding of lldpad? 
> 
> There must be other users/maintainers of DCBX implementations- could you
> please share your experiences in this space?
> 
We tried to get the list maintainership moved to over to us by the time
Intel decided to drop FCoE. But for some reasons this never worked out,
so while the list is technically alive we don't have any means of
managing it.
Maybe we should be moving it to somewhere else.
But yes, we _do_ take fixes for it.

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)


[PATCH net-next 0/2] net: hns3: Bug fixes & Code improvements in HNS3 driver

2017-11-07 Thread Lipeng
This patch-set introduces some bug fixes and code improvements.
As [patch 1/2] depends on the patch {5392902 net: hns3: Consistently using
GENMASK in hns3 driver}, which exists in net-next, not exists in net, so
push this serise to nex-next.

Fuyun Liang (2):
  {topost} net: hns3: fix a bug when getting phy address from NCL_config
file
  {topost} net: hns3: cleanup mac auto-negotiation state query in
hclge_update_speed_duplex

 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h  |  2 +-
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 13 +
 2 files changed, 2 insertions(+), 13 deletions(-)

-- 
1.9.1



Re: [PATCH] pktgen: document 32-bit timestamp overflow

2017-11-07 Thread David Miller
From: Arnd Bergmann 
Date: Tue,  7 Nov 2017 11:38:32 +0100

> Timestamps in pktgen are currently retrieved using the deprecated
> do_gettimeofday() function that wraps its signed 32-bit seconds in 2038
> (on 32-bit architectures) and requires a division operation to calculate
> microseconds.
> 
> The pktgen header is also defined with the same limitations, hardcoding
> to a 32-bit seconds field that can be interpreted as unsigned to produce
> times that only wrap in 2106. Whatever code reads the timestamps should
> be aware of that problem in general, but probably doesn't care too
> much as we are mostly interested in the time passing between packets,
> and that is correctly represented.
> 
> Using 64-bit nanoseconds would be cheaper and good for 584 years. Using
> monotonic times would also make this unambiguous by avoiding the overflow,
> but would make it harder to correlate to the times with those on remote
> machines. Either approach would require adding a new runtime flag and
> implementing the same thing on the remote side, which we probably don't
> want to do unless someone sees it as a real problem. Also, this should
> be coordinated with other pktgen implementations and might need a new
> magic number.
> 
> For the moment, I'm documenting the overflow in the source code, and
> changing the implementation over to an open-coded ktime_get_real_ts64()
> plus division, so we don't have to look at it again while scanning for
> deprecated time interfaces.
> 
> Signed-off-by: Arnd Bergmann 

Applied to net-next, thanks Arnd.


Re: [PATCH] net/tcp: track all ipv4/tcp state transition in tcp_set_state

2017-11-07 Thread David Miller
From: Yafang Shao 
Date: Tue,  7 Nov 2017 18:36:28 +0800

> When I hooked the function tcp_set_state with kprobe to track the ipv4/tcp
> state transistion, I found state transition from TCP_LISTEN to TCP_SYN_RECV
> is missed.
> 
> I think it is better to use the helper to do state transition instead of
> assigning the state to sk_state directly.
> Then we can monitor the whole tcp lifespans with kprobe or ftrace easily.
> 
> Signed-off-by: Yafang Shao 

This is really heavy handed and excessive for these cases.

They don't have to handle any of the issues dealt with in
tcp_set_state().

I would prefer if you made a special helper to net/tcp.h which did:

static inline void __tcp_set_state(struct sock *sk, int state)
{
trace_tcp_set_state(sk, sk->sk_state, state);
sk->sk_state = state;
}


Re: [PATCH] af_netlink: give correct bounds to dump skb for NLMSG_DONE

2017-11-07 Thread Jason A. Donenfeld
Hi Johannes,

Yes indeed. It sacrifices 24 bytes for making things much less
complex. However, if you prefer increasing the complexity of the state
machine a bit instead, I suppose we could roll with this approach
instead...

Jason


[PATCH 02/31] nds32: Kernel booting and initialization

2017-11-07 Thread Greentime Hu
From: Greentime Hu 

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/kernel/head.S  |  211 +++
 arch/nds32/kernel/setup.c |  406 +
 2 files changed, 617 insertions(+)
 create mode 100644 arch/nds32/kernel/head.S
 create mode 100644 arch/nds32/kernel/setup.c

diff --git a/arch/nds32/kernel/head.S b/arch/nds32/kernel/head.S
new file mode 100644
index 000..c2e1a5e
--- /dev/null
+++ b/arch/nds32/kernel/head.S
@@ -0,0 +1,211 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#ifdef CONFIG_CPU_BIG_ENDIAN
+#define OF_DT_MAGIC 0xd00dfeed
+#else
+#define OF_DT_MAGIC 0xedfe0dd0
+#endif
+
+   .globl  swapper_pg_dir
+   .equswapper_pg_dir, TEXTADDR - 0x4000
+
+/*
+ * Kernel startup entry point.
+ */
+   .section ".head.text", "ax"
+   .type   _stext, %function
+ENTRY(_stext)
+   setgie.d! Disable interrupt
+   isb
+/*
+ * Disable I/D-cache and enable it at a proper time
+ */
+   mfsr$r0, $mr8
+   li  $r1, #~(CACHE_CTL_mskIC_EN|CACHE_CTL_mskDC_EN)
+   and $r0, $r0, $r1
+   mtsr$r0, $mr8
+
+/*
+ * Process device tree blob
+ */
+   andi$r0,$r2,#0x3
+   li  $r10, 0
+   bne $r0, $r10, _nodtb
+   lwi $r0, [$r2]
+   li  $r1, OF_DT_MAGIC
+   bne $r0, $r1, _nodtb
+   move$r10, $r2
+_nodtb:
+
+/*
+ * Create a temporary mapping area for booting, before start_kernel
+ */
+   sethi   $r4, hi20(swapper_pg_dir)
+   li  $p0, (PAGE_OFFSET - PHYS_OFFSET)
+   sub $r4, $r4, $p0
+   tlbop   FlushAll! invalidate TLB\n"
+   isb
+   mtsr$r4, $L1_PPTB   ! load page table pointer\n"
+
+/* set NTC0 cacheable/writeback, mutliple page size in use */
+   mfsr$r3, $MMU_CTL
+   li  $r0, #~MMU_CTL_mskNTC0
+   and $r3, $r3, $r0
+#ifdef CONFIG_ANDES_PAGE_SIZE_4KB
+   ori $r3, $r3, #(MMU_CTL_mskMPZIU|(MMU_CTL_CACHEABLE_WB << 
MMU_CTL_offNTC0))
+#else
+   ori $r3, $r3, #(MMU_CTL_mskMPZIU|(MMU_CTL_CACHEABLE_WB << 
MMU_CTL_offNTC0)|MMU_CTL_mskD)
+#endif
+   mtsr$r3, $MMU_CTL
+   isb
+
+/* set page size and size of kernel image */
+mfsr$r0, $MMU_CFG
+srli$r3, $r0, MMU_CFG_offfEPSZ
+zeb $r3, $r3
+bnez$r3, _extra_page_size_support
+#ifdef CONFIG_ANDES_PAGE_SIZE_4KB
+li  $r5, #SZ_4K ! Use 4KB page size
+#else
+li  $r5, #SZ_8K ! Use 8KB page size
+li  $r3, #1
+#endif
+mtsr$r3, $TLB_MISC
+b   _image_size_check
+
+_extra_page_size_support:! Use epzs pages size
+clz $r6, $r3
+subri   $r2, $r6, #31
+li  $r3, #1
+sll $r3, $r3, $r2
+/* MMU_CFG.EPSZ value -> meaning */
+mul $r5, $r3, $r3
+slli$r5, $r5, #14
+/* MMU_CFG.EPSZ  -> TLB_MISC.ACC_PSZ */
+addi$r3, $r2, #0x2
+mtsr$r3, $TLB_MISC
+
+_image_size_check:
+/* calculate the image maximum size accepted by TLB config */
+andi$r6, $r0, MMU_CFG_mskTBW
+andi$r0, $r0, MMU_CFG_mskTBS
+srli$r6, $r6, MMU_CFG_offTBW
+srli$r0, $r0, MMU_CFG_offTBS
+/*
+ * we just map the kernel to the maximum way - 1 of tlb
+ * reserver one way for UART VA mapping
+ * it will cause page fault if UART mapping cover the kernel mapping
+ *
+ * direct mapping is not supported now.
+ */
+li  $r2, 't'
+beqz$r6, __error ! MMU_CFG.TBW = 0 is direct mappin
+addi$r0, $r0, #0x2   ! MMU_CFG.TBS value -> meaning
+sll $r0, $r6, $r0! entries = k-way * n-set
+mul $r6, $r0, $r5! max size = entries * page size
+/* check kernel image size */
+la  $r3, (_end - PAGE_OFFSET)
+li  $r2, 's'
+bgt $r3, $r6, __error
+
+   li  $r2, #(PHYS_OFFSET + TLB_DATA_kernel_text_attr)
+li  $r3, PAGE_OFFSET
+

[PATCH 03/31] nds32: Support early_printk

2017-11-07 Thread Greentime Hu
From: Greentime Hu 

Signed-off-by: Rick Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/kernel/early_printk.c |  124 ++
 1 file changed, 124 insertions(+)
 create mode 100644 arch/nds32/kernel/early_printk.c

diff --git a/arch/nds32/kernel/early_printk.c b/arch/nds32/kernel/early_printk.c
new file mode 100644
index 000..269c3cd
--- /dev/null
+++ b/arch/nds32/kernel/early_printk.c
@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+extern void __iomem *early_io_map(phys_addr_t phys);
+static void __iomem *early_base;
+static void (*printch) (char ch);
+
+/*
+ * 8250/16550 (8-bit aligned registers) single character TX.
+ */
+static void uart8250_8bit_printch(char ch)
+{
+   while (!(readb(early_base + UART_LSR) & UART_LSR_THRE)) ;
+   writeb(ch, early_base + UART_TX);
+}
+
+/*
+ * 8250/16550 (32-bit aligned registers) single character TX.
+ */
+static void uart8250_32bit_printch(char ch)
+{
+   while (!(readl(early_base + (UART_LSR << 2)) & UART_LSR_THRE)) ;
+   writel(ch, early_base + (UART_TX << 2));
+}
+
+struct earlycon_match {
+   const char *name;
+   void (*printch) (char ch);
+};
+
+static const struct earlycon_match earlycon_match[] __initconst = {
+   {.name = "uart8250-8bit",.printch = uart8250_8bit_printch,},
+   {.name = "uart8250-32bit",.printch = uart8250_32bit_printch,},
+   {}
+};
+
+static void early_write(struct console *con, const char *s, unsigned n)
+{
+   while (n-- > 0) {
+   if (*s == '\n')
+   printch('\r');
+   printch(*s);
+   s++;
+   }
+}
+
+static struct console early_console_dev = {
+   .name = "earlycon",
+   .write = early_write,
+   .flags = CON_PRINTBUFFER | CON_BOOT,
+   .index = -1,
+};
+
+/*
+ * Parse earlyprintk=... parameter in the format:
+ *
+ *   [,][,]
+ *
+ * and register the early console. It is assumed that the UART has been
+ * initialised by the bootloader already.
+ */
+static int __init setup_early_printk(char *buf)
+{
+   const struct earlycon_match *match = earlycon_match;
+   phys_addr_t paddr = 0;
+
+   if (!buf) {
+   pr_warning("No earlyprintk arguments passed.\n");
+   return 0;
+   }
+
+   while (match->name) {
+   size_t len = strlen(match->name);
+   if (!strncmp(buf, match->name, len)) {
+   buf += len;
+   break;
+   }
+   match++;
+   }
+   if (!match->name) {
+   pr_warning("Unknown earlyprintk arguments: %s\n", buf);
+   return 0;
+   }
+
+   /* I/O address */
+   if (!strncmp(buf, ",0x", 3)) {
+   char *e;
+   paddr = simple_strtoul(buf + 1, , 16);
+   buf = e;
+   }
+
+   if (paddr)
+   early_base = early_io_map(paddr);
+
+   if (!strcmp(CONFIG_NDS32_BUILTIN_DTB, "ae3xx"))
+   early_base += 32;
+
+   printch = match->printch;
+   register_console(_console_dev);
+
+   return 0;
+}
+
+early_param("earlyprintk", setup_early_printk);
-- 
1.7.9.5



[PATCH 00/31] Andes(nds32) Linux Kernel Port

2017-11-07 Thread Greentime Hu
This patchset adds core architecture support to Linux for Andestech's
N13, N15, D15, N10, D10 processor cores.

Based on the 16/32-bit AndeStar RISC-like architecture, we designed the
configurable AndesCore series of embedded processor families. AndesCores
range from highly performance-efficient small-footprint cores for
microcontrollers and deeply-embedded applications to 1GHz+ cores running
Linux, covering general-purpose N-series cores for a wide range of computing
need, DSP-capable D-series cores for digital signal control,
instruction-extensible E-series cores for application-specific acceleration,
and secure S-series cores for best protection of the most valuable.

The patches are based on v4.14-rc8, and can also be found in the
following git tree:
  https://github.com/andestech/linux.git nds32-4.14-rc8

The build script and toolchain repositories are able to be found here:
  https://github.com/andestech/build_script.git

Freely available instruction set and architecture overview documents can
be found on the following page:
  http://www.andestech.com/product.php?cls=9


Vincent Ren-Wei Chen and I will maintain this port. Thanks to everyone who
helped us and contributed to it. :) Any feedback is welcome.

Greentime Hu (31):
  nds32: Assembly macros and definitions
  nds32: Kernel booting and initialization
  nds32: Support early_printk
  nds32: Exception handling
  nds32: MMU definitions
  nds32: MMU initialization
  nds32: MMU fault handling and page table management
  nds32: Cache and TLB routines
  nds32: Process management
  nds32: IRQ handling
  nds32: Atomic operations
  nds32: Device specific operations
  nds32: DMA mapping API
  nds32: ELF definitions
  nds32: System calls handling
  nds32: VDSO support
  nds32: Signal handling support
  nds32: Library functions
  nds32: Debugging support
  nds32: L2 cache support
  nds32: Loadable modules
  nds32: Generic timers support
  nds32: Device tree support
  nds32: Miscellaneous header files
  nds32: defconfig
  nds32: Build infrastructure
  dt-bindings: interrupt-controller: Andestech Internal Vector
Interrupt Controller
  irqchip: Andestech Internal Vector Interrupt Controller driver
  MAINTAINERS: Add nds32
  dt-bindings: nds32 CPU Bindings
  net: faraday add nds32 support.

 .../interrupt-controller/andestech,ativic32.txt|   27 +
 Documentation/devicetree/bindings/nds32/cpus.txt   |   33 +
 MAINTAINERS|9 +
 arch/nds32/Kconfig |  107 +++
 arch/nds32/Kconfig.cpu |  100 ++
 arch/nds32/Kconfig.debug   |   14 +
 arch/nds32/Makefile|   60 ++
 arch/nds32/boot/Makefile   |   15 +
 arch/nds32/boot/dts/Makefile   |8 +
 arch/nds32/boot/dts/ae3xx.dts  |   55 ++
 arch/nds32/boot/dts/ag101p.dts |   60 ++
 arch/nds32/configs/ae3xx_defconfig |  110 +++
 arch/nds32/configs/ag101p_defconfig|  109 +++
 arch/nds32/include/asm/Kbuild  |   54 ++
 arch/nds32/include/asm/assembler.h |   52 ++
 arch/nds32/include/asm/bitfield.h  |  982 
 arch/nds32/include/asm/cache.h |   25 +
 arch/nds32/include/asm/cache_info.h|   26 +
 arch/nds32/include/asm/cacheflush.h|   57 ++
 arch/nds32/include/asm/current.h   |   25 +
 arch/nds32/include/asm/delay.h |   51 +
 arch/nds32/include/asm/dma-mapping.h   |   27 +
 arch/nds32/include/asm/elf.h   |  192 
 arch/nds32/include/asm/fixmap.h|   41 +
 arch/nds32/include/asm/futex.h |  116 +++
 arch/nds32/include/asm/highmem.h   |   78 ++
 arch/nds32/include/asm/io.h|   33 +
 arch/nds32/include/asm/irqflags.h  |   49 +
 arch/nds32/include/asm/l2_cache.h  |  158 
 arch/nds32/include/asm/linkage.h   |   24 +
 arch/nds32/include/asm/memory.h|  147 +++
 arch/nds32/include/asm/mmu.h   |   25 +
 arch/nds32/include/asm/mmu_context.h   |   81 ++
 arch/nds32/include/asm/module.h|   24 +
 arch/nds32/include/asm/nds32.h |   92 ++
 arch/nds32/include/asm/page.h  |   78 ++
 arch/nds32/include/asm/pgalloc.h   |  109 +++
 arch/nds32/include/asm/pgtable.h   |  426 +
 arch/nds32/include/asm/proc-fns.h  |   94 ++
 arch/nds32/include/asm/processor.h |  116 +++
 arch/nds32/include/asm/ptrace.h|   79 ++
 arch/nds32/include/asm/shmparam.h  |   33 +
 arch/nds32/include/asm/spinlock.h  |  178 
 arch/nds32/include/asm/string.h  

[PATCH 07/31] nds32: MMU fault handling and page table management

2017-11-07 Thread Greentime Hu
From: Greentime Hu 

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/lib/copy_page.S |   50 ++
 arch/nds32/mm/extable.c|   29 +++
 arch/nds32/mm/fault.c  |  420 
 arch/nds32/mm/mmap.c   |   88 ++
 4 files changed, 587 insertions(+)
 create mode 100644 arch/nds32/lib/copy_page.S
 create mode 100644 arch/nds32/mm/extable.c
 create mode 100644 arch/nds32/mm/fault.c
 create mode 100644 arch/nds32/mm/mmap.c

diff --git a/arch/nds32/lib/copy_page.S b/arch/nds32/lib/copy_page.S
new file mode 100644
index 000..a55a5cc
--- /dev/null
+++ b/arch/nds32/lib/copy_page.S
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#include 
+#include 
+
+   .text
+ENTRY(copy_page)
+   pushm   $r2, $r10
+   movi$r2, PAGE_SIZE >> 5
+.Lcopy_loop:
+   lmw.bim $r3, [$r1], $r10
+   smw.bim $r3, [$r0], $r10
+   subi45  $r2, #1
+   bnez38  $r2, .Lcopy_loop
+   popm$r2, $r10
+   ret
+ENDPROC(copy_page)
+
+ENTRY(clear_page)
+   pushm   $r1, $r9
+   movi$r1, PAGE_SIZE >> 5
+   movi55  $r2, #0
+   movi55  $r3, #0
+   movi55  $r4, #0
+   movi55  $r5, #0
+   movi55  $r6, #0
+   movi55  $r7, #0
+   movi55  $r8, #0
+   movi55  $r9, #0
+.Lclear_loop:
+   smw.bim $r2, [$r0], $r9
+   subi45  $r1, #1
+   bnez38  $r1, .Lclear_loop
+   popm$r1, $r9
+ret
+ENDPROC(clear_page)
diff --git a/arch/nds32/mm/extable.c b/arch/nds32/mm/extable.c
new file mode 100644
index 000..bce62d7
--- /dev/null
+++ b/arch/nds32/mm/extable.c
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#include 
+#include 
+
+int fixup_exception(struct pt_regs *regs)
+{
+   const struct exception_table_entry *fixup;
+
+   fixup = search_exception_tables(instruction_pointer(regs));
+   if (fixup)
+   regs->ipc = fixup->fixup;
+
+   return fixup != NULL;
+}
diff --git a/arch/nds32/mm/fault.c b/arch/nds32/mm/fault.c
new file mode 100644
index 000..e15b2c1
--- /dev/null
+++ b/arch/nds32/mm/fault.c
@@ -0,0 +1,420 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+extern void die(const char *str, struct pt_regs *regs, long err);
+
+/*
+ * This is useful to dump out the page tables associated with
+ * 'addr' in mm 'mm'.
+ */
+void show_pte(struct mm_struct *mm, unsigned long addr)
+{
+   pgd_t *pgd;
+   if (!mm)
+   mm = _mm;
+
+   pr_alert("pgd = %p\n", mm->pgd);
+   pgd = pgd_offset(mm, addr);
+   pr_alert("[%08lx] *pgd=%08lx", addr, pgd_val(*pgd));
+
+   do {
+   pmd_t *pmd;
+
+   if (pgd_none(*pgd))
+   break;
+
+   if (pgd_bad(*pgd)) {
+   pr_alert("(bad)");
+   break;
+   }
+
+   pmd = pmd_offset(pgd, addr);
+#if PTRS_PER_PMD != 1
+   pr_alert(", 

[PATCH 05/31] nds32: MMU definitions

2017-11-07 Thread Greentime Hu
From: Greentime Hu 

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/include/asm/fixmap.h   |   41 
 arch/nds32/include/asm/highmem.h  |   78 +++
 arch/nds32/include/asm/memory.h   |  147 +
 arch/nds32/include/asm/mmu.h  |   25 +++
 arch/nds32/include/asm/page.h |   78 +++
 arch/nds32/include/asm/pgalloc.h  |  109 ++
 arch/nds32/include/asm/pgtable.h  |  426 +
 arch/nds32/include/asm/shmparam.h |   33 +++
 8 files changed, 937 insertions(+)
 create mode 100644 arch/nds32/include/asm/fixmap.h
 create mode 100644 arch/nds32/include/asm/highmem.h
 create mode 100644 arch/nds32/include/asm/memory.h
 create mode 100644 arch/nds32/include/asm/mmu.h
 create mode 100644 arch/nds32/include/asm/page.h
 create mode 100644 arch/nds32/include/asm/pgalloc.h
 create mode 100644 arch/nds32/include/asm/pgtable.h
 create mode 100644 arch/nds32/include/asm/shmparam.h

diff --git a/arch/nds32/include/asm/fixmap.h b/arch/nds32/include/asm/fixmap.h
new file mode 100644
index 000..38e8ee1
--- /dev/null
+++ b/arch/nds32/include/asm/fixmap.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#ifndef __ASM_NDS32_FIXMAP_H
+#define __ASM_NDS32_FIXMAP_H
+
+#ifdef CONFIG_HIGHMEM
+#include 
+#include 
+#endif
+
+enum fixed_addresses {
+   FIX_KMAP_RESERVED,
+   FIX_KMAP_BEGIN,
+#ifdef CONFIG_HIGHMEM
+   FIX_KMAP_END = FIX_KMAP_BEGIN + (KM_TYPE_NR * NR_CPUS),
+#endif
+#ifdef CONFIG_EARLY_PRINTK
+   FIX_EARLY_DEBUG,
+#endif
+   __end_of_fixed_addresses
+};
+#define FIXADDR_TOP ((unsigned long) (-(16 * PAGE_SIZE)))
+#define FIXADDR_SIZE   ((__end_of_fixed_addresses) << PAGE_SHIFT)
+#define FIXADDR_START  (FIXADDR_TOP - FIXADDR_SIZE)
+
+#include 
+#endif /* __ASM_NDS32_FIXMAP_H */
diff --git a/arch/nds32/include/asm/highmem.h b/arch/nds32/include/asm/highmem.h
new file mode 100644
index 000..6a569c1
--- /dev/null
+++ b/arch/nds32/include/asm/highmem.h
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#ifndef _ASM_HIGHMEM_H
+#define _ASM_HIGHMEM_H
+
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * Right now we initialize only a single pte table. It can be extended
+ * easily, subsequent pte tables have to be allocated in one physical
+ * chunk of RAM.
+ */
+/*
+ * Ordering is (from lower to higher memory addresses):
+ *
+ * high_memory
+ * Persistent kmap area
+ * PKMAP_BASE
+ * fixed_addresses
+ * FIXADDR_START
+ * FIXADDR_TOP
+ * Vmalloc area
+ * VMALLOC_START
+ * VMALLOC_END
+ */
+#define PKMAP_BASE ((FIXADDR_START - PGDIR_SIZE) & (PGDIR_MASK))
+#define LAST_PKMAP PTRS_PER_PTE
+#define LAST_PKMAP_MASK(LAST_PKMAP - 1)
+#define PKMAP_NR(virt) (((virt) - (PKMAP_BASE)) >> PAGE_SHIFT)
+#define PKMAP_ADDR(nr) (PKMAP_BASE + ((nr) << PAGE_SHIFT))
+#define kmap_prot  PAGE_KERNEL
+
+static inline void flush_cache_kmaps(void)
+{
+   cpu_dcache_wbinval_all();
+}
+
+/* declarations for highmem.c */
+extern unsigned long highstart_pfn, highend_pfn;
+
+extern pte_t *pkmap_page_table;
+
+extern void *kmap_high(struct page *page);
+extern void kunmap_high(struct page *page);
+
+extern void kmap_init(void);
+
+/*
+ * The following functions are already defined by 
+ * when CONFIG_HIGHMEM is not set.
+ */
+#ifdef CONFIG_HIGHMEM
+extern void *kmap(struct page *page);
+extern void kunmap(struct page *page);
+extern void *kmap_atomic(struct page *page);
+extern void __kunmap_atomic(void *kvaddr);
+extern void *kmap_atomic_pfn(unsigned long pfn);
+extern 

[PATCH 06/31] nds32: MMU initialization

2017-11-07 Thread Greentime Hu
From: Greentime Hu 

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/mm/highmem.c  |   92 +
 arch/nds32/mm/init.c |  328 ++
 arch/nds32/mm/mm-nds32.c |  103 +++
 3 files changed, 523 insertions(+)
 create mode 100644 arch/nds32/mm/highmem.c
 create mode 100644 arch/nds32/mm/init.c
 create mode 100644 arch/nds32/mm/mm-nds32.c

diff --git a/arch/nds32/mm/highmem.c b/arch/nds32/mm/highmem.c
new file mode 100644
index 000..d5101bd
--- /dev/null
+++ b/arch/nds32/mm/highmem.c
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+void *kmap(struct page *page)
+{
+   unsigned long vaddr;
+   might_sleep();
+   if (!PageHighMem(page))
+   return page_address(page);
+   vaddr = (unsigned long)kmap_high(page);
+   return (void *)vaddr;
+}
+
+EXPORT_SYMBOL(kmap);
+
+void kunmap(struct page *page)
+{
+   BUG_ON(in_interrupt());
+   if (!PageHighMem(page))
+   return;
+   kunmap_high(page);
+}
+
+EXPORT_SYMBOL(kunmap);
+
+void *kmap_atomic(struct page *page)
+{
+   unsigned int idx;
+   unsigned long vaddr, pte;
+   int type;
+   pte_t *ptep;
+
+   preempt_disable();
+   pagefault_disable();
+   if (!PageHighMem(page))
+   return page_address(page);
+
+   type = kmap_atomic_idx_push();
+
+   idx = type + KM_TYPE_NR * smp_processor_id();
+   vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
+   pte = (page_to_pfn(page) << PAGE_SHIFT) | (PAGE_KERNEL);
+   ptep = pte_offset_kernel(pmd_off_k(vaddr), vaddr);
+   set_pte(ptep, pte);
+
+   __nds32__tlbop_inv(vaddr);
+   __nds32__mtsr_dsb(vaddr, NDS32_SR_TLB_VPN);
+   __nds32__tlbop_rwr(pte);
+   __nds32__isb();
+   return (void *)vaddr;
+}
+
+EXPORT_SYMBOL(kmap_atomic);
+
+void __kunmap_atomic(void *kvaddr)
+{
+   if (kvaddr >= (void *)FIXADDR_START) {
+   unsigned long vaddr = (unsigned long)kvaddr;
+   pte_t *ptep;
+   kmap_atomic_idx_pop();
+   __nds32__tlbop_inv(vaddr);
+   __nds32__isb();
+   ptep = pte_offset_kernel(pmd_off_k(vaddr), vaddr);
+   set_pte(ptep, 0);
+   }
+   pagefault_enable();
+   preempt_enable();
+}
+
+EXPORT_SYMBOL(__kunmap_atomic);
diff --git a/arch/nds32/mm/init.c b/arch/nds32/mm/init.c
new file mode 100644
index 000..9dee3ee
--- /dev/null
+++ b/arch/nds32/mm/init.c
@@ -0,0 +1,328 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
+DEFINE_SPINLOCK(anon_alias_lock);
+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
+extern unsigned long phys_initrd_start;
+extern unsigned long phys_initrd_size;
+
+/*
+ * empty_zero_page is a special page that is used for
+ * zero-initialized data and COW.
+ */
+struct page *empty_zero_page;
+#ifdef CONFIG_EARLY_PRINTK
+#include 
+
+/*
+ * Using tlbop to create an early I/O mapping
+ */
+void __iomem *__init early_io_map(phys_addr_t pa)
+{
+   unsigned long va;
+   pa &= PAGE_MASK;
+   pa += pgprot_val(PAGE_DEVICE);
+   va = __fix_to_virt(FIX_EARLY_DEBUG);
+   /* insert and lock this page to tlb entry directly */
+
+   __nds32__mtsr_dsb(va, NDS32_SR_TLB_VPN);
+   __nds32__tlbop_rwlk(pa);
+   __nds32__isb();
+   return (void __iomem *)va;
+}
+
+int __init 

[PATCH 01/31] nds32: Assembly macros and definitions

2017-11-07 Thread Greentime Hu
From: Greentime Hu 

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/include/asm/assembler.h |   52 ++
 arch/nds32/include/asm/bitfield.h  |  982 
 arch/nds32/include/asm/nds32.h |   92 
 arch/nds32/kernel/asm-offsets.c|   40 ++
 4 files changed, 1166 insertions(+)
 create mode 100644 arch/nds32/include/asm/assembler.h
 create mode 100644 arch/nds32/include/asm/bitfield.h
 create mode 100644 arch/nds32/include/asm/nds32.h
 create mode 100644 arch/nds32/kernel/asm-offsets.c

diff --git a/arch/nds32/include/asm/assembler.h 
b/arch/nds32/include/asm/assembler.h
new file mode 100644
index 000..d469af0
--- /dev/null
+++ b/arch/nds32/include/asm/assembler.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#ifndef __NDS32_ASSEMBLER_H__
+#define __NDS32_ASSEMBLER_H__
+
+.macro gie_disable
+   setgie.d
+   dsb
+.endm
+
+.macro gie_enable
+   setgie.e
+   dsb
+.endm
+
+.macro gie_save oldpsw
+   mfsr \oldpsw, $ir0
+   setgie.d
+dsb
+.endm
+
+.macro gie_restore oldpsw
+   andi \oldpsw, \oldpsw, #0x1
+   beqz \oldpsw, 7001f
+   setgie.e
+   dsb
+7001:
+.endm
+
+
+#define USER(insn,  reg, addr, opr)\
+:  insn  reg, addr, opr;   \
+   .section __ex_table,"a";\
+   .align 3;   \
+   .long   b, 9001f;   \
+   .previous
+
+#endif /* __NDS32_ASSEMBLER_H__ */
diff --git a/arch/nds32/include/asm/bitfield.h 
b/arch/nds32/include/asm/bitfield.h
new file mode 100644
index 000..bb032ce
--- /dev/null
+++ b/arch/nds32/include/asm/bitfield.h
@@ -0,0 +1,982 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#ifndef __NDS32_BITFIELD_H__
+#define __NDS32_BITFIELD_H__
+/**
+ * cr0: CPU_VER (CPU Version Register)
+ */
+#define CPU_VER_offCFGID   0   /* Minor configuration */
+#define CPU_VER_offREV 16  /* Revision of the CPU version */
+#define CPU_VER_offCPUID   24  /* Major CPU versions */
+
+#define CPU_VER_mskCFGID   ( 0x  << CPU_VER_offCFGID )
+#define CPU_VER_mskREV ( 0xFF  << CPU_VER_offREV )
+#define CPU_VER_mskCPUID   ( 0xFF  << CPU_VER_offCPUID )
+
+/**
+ * cr1: ICM_CFG (Instruction Cache/Memory Configuration Register)
+ */
+#define ICM_CFG_offISET0   /* I-cache sets (# of cache 
lines) per way */
+#define ICM_CFG_offIWAY3   /* I-cache ways */
+#define ICM_CFG_offISZ 6   /* I-cache line size */
+#define ICM_CFG_offILCK9   /* I-cache locking support */
+#define ICM_CFG_offILMB10  /* On-chip ILM banks */
+#define ICM_CFG_offBSAV13  /* ILM base register alignment 
version */
+/* bit 15:31 reserved */
+
+#define ICM_CFG_mskISET( 0x7  << ICM_CFG_offISET )
+#define ICM_CFG_mskIWAY( 0x7  << ICM_CFG_offIWAY )
+#define ICM_CFG_mskISZ ( 0x7  << ICM_CFG_offISZ )
+#define ICM_CFG_mskILCK( 0x1  << ICM_CFG_offILCK )
+#define ICM_CFG_mskILMB( 0x7  << ICM_CFG_offILMB )
+#define ICM_CFG_mskBSAV( 0x3  << ICM_CFG_offBSAV )
+
+/**
+ * cr2: DCM_CFG (Data Cache/Memory Configuration Register)
+ 

[PATCH 10/31] nds32: IRQ handling

2017-11-07 Thread Greentime Hu
From: Greentime Hu 

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/include/asm/irqflags.h |   49 +
 arch/nds32/kernel/irq.c   |   34 +
 2 files changed, 83 insertions(+)
 create mode 100644 arch/nds32/include/asm/irqflags.h
 create mode 100644 arch/nds32/kernel/irq.c

diff --git a/arch/nds32/include/asm/irqflags.h 
b/arch/nds32/include/asm/irqflags.h
new file mode 100644
index 000..7c1940f
--- /dev/null
+++ b/arch/nds32/include/asm/irqflags.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#include 
+#include 
+
+#define arch_local_irq_disable()   \
+   GIE_DISABLE();
+
+#define arch_local_irq_enable()\
+   GIE_ENABLE();
+static inline unsigned long arch_local_irq_save(void)
+{
+   unsigned long flags;
+   flags = __nds32__mfsr(NDS32_SR_PSW) & PSW_mskGIE;
+   GIE_DISABLE();
+   return flags;
+}
+
+static inline unsigned long arch_local_save_flags(void)
+{
+   unsigned long flags;
+   flags = __nds32__mfsr(NDS32_SR_PSW) & PSW_mskGIE;
+   return flags;
+}
+
+static inline void arch_local_irq_restore(unsigned long flags)
+{
+   if(flags)
+   GIE_ENABLE();
+}
+
+static inline int arch_irqs_disabled_flags(unsigned long flags)
+{
+   return !flags;
+}
diff --git a/arch/nds32/kernel/irq.c b/arch/nds32/kernel/irq.c
new file mode 100644
index 000..1b935f7
--- /dev/null
+++ b/arch/nds32/kernel/irq.c
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#include 
+
+void __init init_IRQ(void)
+{
+   irqchip_init();
+}
+
+#ifdef CONFIG_TRACE_IRQFLAGS
+void notrace arch_trace_hardirqs_on(void)
+{
+   trace_hardirqs_on();
+}
+
+void notrace arch_trace_hardirqs_off(void)
+{
+   trace_hardirqs_off();
+}
+#endif
-- 
1.7.9.5



Re: [PATCH v2] net: macb: add of_node_put to error paths

2017-11-07 Thread David Miller
From: Michael Grzeschik 
Date: Tue,  7 Nov 2017 10:59:49 +0100

> @@ -611,6 +611,7 @@ static int macb_mii_init(struct macb *bp)
>  err_out_unregister_bus:
>   mdiobus_unregister(bp->mii_bus);
>  err_out_free_mdiobus:
> + of_node_put(bp->phy_node);
>   if ((np) && (of_phy_is_fixed_link(np)))
>   of_phy_deregister_fixed_link(np);
>   mdiobus_free(bp->mii_bus);

This is relative to another patch which has not been applied.

Please do not do this.


[PATCH 14/31] nds32: ELF definitions

2017-11-07 Thread Greentime Hu
From: Greentime Hu 

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/include/asm/elf.h |  192 ++
 arch/nds32/include/uapi/asm/auxvec.h |   25 +
 arch/nds32/include/uapi/asm/param.h  |   24 +
 3 files changed, 241 insertions(+)
 create mode 100644 arch/nds32/include/asm/elf.h
 create mode 100644 arch/nds32/include/uapi/asm/auxvec.h
 create mode 100644 arch/nds32/include/uapi/asm/param.h

diff --git a/arch/nds32/include/asm/elf.h b/arch/nds32/include/asm/elf.h
new file mode 100644
index 000..a6e4c56
--- /dev/null
+++ b/arch/nds32/include/asm/elf.h
@@ -0,0 +1,192 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#ifndef __ASMNDS32_ELF_H
+#define __ASMNDS32_ELF_H
+
+/*
+ * ELF register definitions..
+ */
+
+#include 
+
+typedef unsigned long elf_greg_t;
+typedef unsigned long elf_freg_t[3];
+
+extern unsigned int elf_hwcap;
+
+#define EM_NDS32   167
+
+#define R_NDS32_NONE   0
+#define R_NDS32_16_RELA19
+#define R_NDS32_32_RELA20
+#define R_NDS32_9_PCREL_RELA   22
+#define R_NDS32_15_PCREL_RELA  23
+#define R_NDS32_17_PCREL_RELA  24
+#define R_NDS32_25_PCREL_RELA  25
+#define R_NDS32_HI20_RELA  26
+#define R_NDS32_LO12S3_RELA27
+#define R_NDS32_LO12S2_RELA28
+#define R_NDS32_LO12S1_RELA29
+#define R_NDS32_LO12S0_RELA30
+#define R_NDS32_SDA15S3_RELA   31
+#define R_NDS32_SDA15S2_RELA   32
+#define R_NDS32_SDA15S1_RELA   33
+#define R_NDS32_SDA15S0_RELA   34
+#define R_NDS32_GOT20  37
+#define R_NDS32_25_PLTREL  38
+#define R_NDS32_COPY   39
+#define R_NDS32_GLOB_DAT   40
+#define R_NDS32_JMP_SLOT   41
+#define R_NDS32_RELATIVE   42
+#define R_NDS32_GOTOFF 43
+#define R_NDS32_GOTPC2044
+#define R_NDS32_GOT_HI20   45
+#define R_NDS32_GOT_LO12   46
+#define R_NDS32_GOTPC_HI20 47
+#define R_NDS32_GOTPC_LO12 48
+#define R_NDS32_GOTOFF_HI2049
+#define R_NDS32_GOTOFF_LO1250
+#define R_NDS32_INSN16 51
+#define R_NDS32_LABEL  52
+#define R_NDS32_LONGCALL1  53
+#define R_NDS32_LONGCALL2  54
+#define R_NDS32_LONGCALL3  55
+#define R_NDS32_LONGJUMP1  56
+#define R_NDS32_LONGJUMP2  57
+#define R_NDS32_LONGJUMP3  58
+#define R_NDS32_LOADSTORE  59
+#define R_NDS32_9_FIXED_RELA   60
+#define R_NDS32_15_FIXED_RELA  61
+#define R_NDS32_17_FIXED_RELA  62
+#define R_NDS32_25_FIXED_RELA  63
+#define R_NDS32_PLTREL_HI2064
+#define R_NDS32_PLTREL_LO1265
+#define R_NDS32_PLT_GOTREL_HI2066
+#define R_NDS32_PLT_GOTREL_LO1267
+#define R_NDS32_LO12S0_ORI_RELA72
+#define R_NDS32_DWARF2_OP1_RELA77
+#define R_NDS32_DWARF2_OP2_RELA78
+#define R_NDS32_DWARF2_LEB_RELA79
+#define R_NDS32_WORD_9_PCREL_RELA  94
+#define R_NDS32_LONGCALL4  107
+#define R_NDS32_RELA_NOP_MIX   192
+#define R_NDS32_RELA_NOP_MAX   255
+
+#define ELF_NGREG (sizeof (struct pt_regs) / sizeof(elf_greg_t))
+typedef elf_greg_t elf_gregset_t[ELF_NGREG];
+
+/* Core file format: The core file is written in such a way that gdb
+   can understand it and provide useful information to the user (under
+   linux we use the 'trad-core' bfd).  There are quite a number of
+   obstacles to being able to view the contents of the floating point
+   registers, and until these are solved you will not be able to view the
+   contents of them.  Actually, you can read in the core file and look at
+   the contents of the user struct to find out what the floating point
+   registers contain.
+   The actual file contents are as follows:
+   UPAGE: 1 page consisting of a user struct that tells gdb what is present
+   in the file.  Directly after this is a copy of the task_struct, which
+   is currently not used by gdb, but it may come in useful at some point.
+   All of the 

[PATCH 09/31] nds32: Process management

2017-11-07 Thread Greentime Hu
From: Greentime Hu 

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/include/asm/current.h |   25 
 arch/nds32/include/asm/processor.h   |  116 ++
 arch/nds32/include/asm/thread_info.h |   91 ++
 arch/nds32/kernel/process.c  |  219 ++
 4 files changed, 451 insertions(+)
 create mode 100644 arch/nds32/include/asm/current.h
 create mode 100644 arch/nds32/include/asm/processor.h
 create mode 100644 arch/nds32/include/asm/thread_info.h
 create mode 100644 arch/nds32/kernel/process.c

diff --git a/arch/nds32/include/asm/current.h b/arch/nds32/include/asm/current.h
new file mode 100644
index 000..027f7df
--- /dev/null
+++ b/arch/nds32/include/asm/current.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#ifndef _ASM_NDS32_CURRENT_H
+#define _ASM_NDS32_CURRENT_H
+
+#ifndef __ASSEMBLY__
+register struct task_struct *current asm("$r25");
+#endif /* __ASSEMBLY__ */
+#define tsk $r25
+
+#endif /* _ASM_NDS32_CURRENT_H */
diff --git a/arch/nds32/include/asm/processor.h 
b/arch/nds32/include/asm/processor.h
new file mode 100644
index 000..03dab61
--- /dev/null
+++ b/arch/nds32/include/asm/processor.h
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#ifndef __ASM_NDS32_PROCESSOR_H
+#define __ASM_NDS32_PROCESSOR_H
+
+/*
+ * Default implementation of macro that returns current
+ * instruction pointer ("program counter").
+ */
+#define current_text_addr() ({ __label__ _l; _l: &&_l;})
+
+#ifdef __KERNEL__
+
+#include 
+#include 
+#include 
+
+#define KERNEL_STACK_SIZE  PAGE_SIZE
+#define STACK_TOP  TASK_SIZE
+#define STACK_TOP_MAX   TASK_SIZE
+
+struct cpu_context {
+   unsigned long r6;
+   unsigned long r7;
+   unsigned long r8;
+   unsigned long r9;
+   unsigned long r10;
+   unsigned long r11;
+   unsigned long r12;
+   unsigned long r13;
+   unsigned long r14;
+   unsigned long fp;
+   unsigned long pc;
+   unsigned long sp;
+};
+
+struct thread_struct {
+   struct cpu_context cpu_context; /* cpu context */
+   /* fault info */
+   unsigned long address;
+   unsigned long trap_no;
+   unsigned long error_code;
+};
+
+#define INIT_THREAD  { }
+
+#ifdef __NDS32_EB__
+#define PSW_DE PSW_mskBE
+#else
+#define PSW_DE 0x0
+#endif
+
+#ifdef CONFIG_WBNA
+#define PSW_valWBNAPSW_mskWBNA
+#else
+#define PSW_valWBNA0x0
+#endif
+
+#ifdef CONFIG_HWZOL
+#definePSW_valINIT (PSW_CPL_ANY | PSW_mskAEN | PSW_valWBNA | PSW_mskDT 
| PSW_mskIT | PSW_DE | PSW_mskGIE)
+#else
+#definePSW_valINIT (PSW_CPL_ANY | PSW_valWBNA | PSW_mskDT | PSW_mskIT 
| PSW_DE | PSW_mskGIE)
+#endif
+
+#define start_thread(regs,pc,stack)\
+({ \
+   set_fs(USER_DS);\
+   memzero(regs, sizeof(struct pt_regs));  \
+   regs->ipsw = PSW_valINIT;   \
+   regs->ir0 = (PSW_CPL_ANY | PSW_valWBNA | PSW_mskDT | PSW_mskIT | PSW_DE 
| PSW_SYSTEM | PSW_INTL_1); \
+   regs->ipc = pc; \
+   regs->sp = stack;   \
+})
+
+/* Forward declaration, a strange C thing */
+struct task_struct;
+
+/* Free all resources held by a thread. */
+#define release_thread(thread) do { } while(0)
+
+/* Prepare to copy thread state - unlazy all lazy status */
+#define prepare_to_copy(tsk)   do { } while (0)
+
+unsigned long get_wchan(struct task_struct *p);
+
+#define cpu_relax()barrier()
+
+#define task_pt_regs(task) \
+   ((struct 

[PATCH 11/31] nds32: Atomic operations

2017-11-07 Thread Greentime Hu
From: Greentime Hu 

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/include/asm/futex.h|  116 
 arch/nds32/include/asm/spinlock.h |  178 +
 2 files changed, 294 insertions(+)
 create mode 100644 arch/nds32/include/asm/futex.h
 create mode 100644 arch/nds32/include/asm/spinlock.h

diff --git a/arch/nds32/include/asm/futex.h b/arch/nds32/include/asm/futex.h
new file mode 100644
index 000..5aa107c
--- /dev/null
+++ b/arch/nds32/include/asm/futex.h
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#ifndef __NDS32_FUTEX_H__
+#define __NDS32_FUTEX_H__
+
+#include 
+#include 
+#include 
+
+#define __futex_atomic_ex_table(err_reg)   \
+   "   .pushsection __ex_table,\"a\"\n"\
+   "   .align  3\n"\
+   "   .long   1b, 4f\n"   \
+   "   .long   2b, 4f\n"   \
+   "   .popsection\n"  \
+   "   .pushsection .fixup,\"ax\"\n"   \
+   "4: move%0, " err_reg "\n"  \
+   "   j   3b\n"   \
+   "   .popsection"
+
+#define __futex_atomic_op(insn, ret, oldval, tmp, uaddr, oparg)\
+   smp_mb();   \
+   asm volatile(   \
+   "   movi$ta, #0\n"  \
+   "1: llw %1, [%2+$ta]\n" \
+   "   " insn "\n" \
+   "2: scw %0, [%2+$ta]\n" \
+   "   beqz%0, 1b\n"   \
+   "   movi%0, #0\n"   \
+   "3:\n"  \
+   __futex_atomic_ex_table("%4")   \
+   : "=" (ret), "=" (oldval)   \
+   : "r" (uaddr), "r" (oparg), "i" (-EFAULT)   \
+   : "cc", "memory")
+static inline int
+futex_atomic_cmpxchg_inatomic(u32 * uval, u32 __user * uaddr,
+ u32 oldval, u32 newval)
+{
+   int ret = 0;
+   u32 val, tmp, flags;
+
+   if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
+   return -EFAULT;
+
+   smp_mb();
+   asm volatile ("   movi$ta, #0\n"
+ "1: llw %1, [%6 + $ta]\n"
+ "   sub %3, %1, %4\n"
+ "   cmovz   %2, %5, %3\n"
+ "   cmovn   %2, %1, %3\n"
+ "2: scw %2, [%6 + $ta]\n"
+ "   beqz%2, 1b\n"
+ "3:\n   " __futex_atomic_ex_table("%7")
+ :"+"(ret), "="(val), "="(tmp), "="(flags)
+ :"r"(oldval), "r"(newval), "r"(uaddr), "i"(-EFAULT)
+ :"$ta", "memory");
+   smp_mb();
+
+   *uval = val;
+   return ret;
+}
+
+static inline int
+arch_futex_atomic_op_inuser(int op, int oparg, int *oval, u32 __user *uaddr)
+{
+   int oldval = 0, ret;
+
+
+   pagefault_disable();
+   switch (op) {
+   case FUTEX_OP_SET:
+   __futex_atomic_op("move %0, %3", ret, oldval, tmp, uaddr,
+ oparg);
+   break;
+   case FUTEX_OP_ADD:
+   __futex_atomic_op("add  %0, %1, %3", ret, oldval, tmp, uaddr,
+ oparg);
+   break;
+   case FUTEX_OP_OR:
+   __futex_atomic_op("or   %0, %1, %3", ret, oldval, tmp, uaddr,
+ oparg);
+   break;
+   case FUTEX_OP_ANDN:
+   __futex_atomic_op("and  %0, %1, %3", ret, oldval, tmp, uaddr,
+ ~oparg);
+   break;
+   case FUTEX_OP_XOR:
+   __futex_atomic_op("xor  %0, %1, %3", ret, oldval, tmp, uaddr,
+ oparg);
+   break;
+   default:
+   ret = -ENOSYS;
+   }
+
+   

[PATCH 12/31] nds32: Device specific operations

2017-11-07 Thread Greentime Hu
From: Greentime Hu 

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/include/asm/io.h |   33 +
 arch/nds32/mm/ioremap.c |   67 +++
 2 files changed, 100 insertions(+)
 create mode 100644 arch/nds32/include/asm/io.h
 create mode 100644 arch/nds32/mm/ioremap.c

diff --git a/arch/nds32/include/asm/io.h b/arch/nds32/include/asm/io.h
new file mode 100644
index 000..98b3ae9
--- /dev/null
+++ b/arch/nds32/include/asm/io.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#ifndef __ASM_NDS32_IO_H
+#define __ASM_NDS32_IO_H
+
+#ifdef __KERNEL__
+
+#include 
+extern void __iomem *__ioremap(unsigned long, size_t, unsigned long,
+  unsigned long);
+extern void __iounmap(void __iomem * addr);
+
+#define ioremap(cookie,size)   __ioremap(cookie,size,0,1)
+#define ioremap_nocache(cookie,size)   __ioremap(cookie,size,0,1)
+#define iounmap(cookie)__iounmap(cookie)
+#include 
+
+#endif /* __KERNEL__ */
+#endif /* __ASM_NDS32_IO_H */
diff --git a/arch/nds32/mm/ioremap.c b/arch/nds32/mm/ioremap.c
new file mode 100644
index 000..532e6cf
--- /dev/null
+++ b/arch/nds32/mm/ioremap.c
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+void __iomem *__ioremap(unsigned long phys_addr, size_t size,
+   unsigned long flags, unsigned long align)
+{
+   struct vm_struct *area;
+   unsigned long addr, offset, last_addr;
+   pgprot_t prot;
+
+   /* Don't allow wraparound or zero size */
+   last_addr = phys_addr + size - 1;
+   if (!size || last_addr < phys_addr)
+   return NULL;
+
+   /*
+* Mappings have to be page-aligned
+*/
+   offset = phys_addr & ~PAGE_MASK;
+   phys_addr &= PAGE_MASK;
+   size = PAGE_ALIGN(last_addr + 1) - phys_addr;
+
+   /*
+* Ok, go for it..
+*/
+   area = get_vm_area(size, VM_IOREMAP);
+   if (!area)
+   return NULL;
+
+   area->phys_addr = phys_addr;
+   addr = (unsigned long)area->addr;
+   prot = __pgprot(_PAGE_V | _PAGE_M_KRW | _PAGE_D |
+   _PAGE_G | _PAGE_C_DEV);
+   if (ioremap_page_range(addr, addr + size, phys_addr, prot)) {
+   vunmap((void *)addr);
+   return NULL;
+   }
+   return (__force void __iomem *)(offset + (char *)addr);
+
+}
+
+EXPORT_SYMBOL(__ioremap);
+
+void __iounmap(void __iomem * addr)
+{
+   vunmap((void *)(PAGE_MASK & (unsigned long)addr));
+}
+
+EXPORT_SYMBOL(__iounmap);
-- 
1.7.9.5



[PATCH 13/31] nds32: DMA mapping API

2017-11-07 Thread Greentime Hu
From: Greentime Hu 

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/include/asm/dma-mapping.h |   27 ++
 arch/nds32/kernel/dma.c  |  478 ++
 2 files changed, 505 insertions(+)
 create mode 100644 arch/nds32/include/asm/dma-mapping.h
 create mode 100644 arch/nds32/kernel/dma.c

diff --git a/arch/nds32/include/asm/dma-mapping.h 
b/arch/nds32/include/asm/dma-mapping.h
new file mode 100644
index 000..63dbeb7
--- /dev/null
+++ b/arch/nds32/include/asm/dma-mapping.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#ifndef ASMNDS32_DMA_MAPPING_H
+#define ASMNDS32_DMA_MAPPING_H
+
+extern struct dma_map_ops nds32_dma_ops;
+
+static inline struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus)
+{
+   return _dma_ops;
+}
+
+#endif
diff --git a/arch/nds32/kernel/dma.c b/arch/nds32/kernel/dma.c
new file mode 100644
index 000..939702e
--- /dev/null
+++ b/arch/nds32/kernel/dma.c
@@ -0,0 +1,478 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * This is the page table (2MB) covering uncached, DMA consistent allocations
+ */
+static pte_t *consistent_pte;
+static DEFINE_RAW_SPINLOCK(consistent_lock);
+
+/*
+ * VM region handling support.
+ *
+ * This should become something generic, handling VM region allocations for
+ * vmalloc and similar (ioremap, module space, etc).
+ *
+ * I envisage vmalloc()'s supporting vm_struct becoming:
+ *
+ *  struct vm_struct {
+ *struct vm_region region;
+ *unsigned longflags;
+ *struct page  **pages;
+ *unsigned int nr_pages;
+ *unsigned longphys_addr;
+ *  };
+ *
+ * get_vm_area() would then call vm_region_alloc with an appropriate
+ * struct vm_region head (eg):
+ *
+ *  struct vm_region vmalloc_head = {
+ * .vm_list= LIST_HEAD_INIT(vmalloc_head.vm_list),
+ * .vm_start   = VMALLOC_START,
+ * .vm_end = VMALLOC_END,
+ *  };
+ *
+ * However, vmalloc_head.vm_start is variable (typically, it is dependent on
+ * the amount of RAM found at boot time.)  I would imagine that get_vm_area()
+ * would have to initialise this each time prior to calling vm_region_alloc().
+ */
+struct arch_vm_region {
+   struct list_head vm_list;
+   unsigned long vm_start;
+   unsigned long vm_end;
+   struct page *vm_pages;
+};
+
+static struct arch_vm_region consistent_head = {
+   .vm_list = LIST_HEAD_INIT(consistent_head.vm_list),
+   .vm_start = CONSISTENT_BASE,
+   .vm_end = CONSISTENT_END,
+};
+
+static struct arch_vm_region *vm_region_alloc(struct arch_vm_region *head,
+ size_t size, int gfp)
+{
+   unsigned long addr = head->vm_start, end = head->vm_end - size;
+   unsigned long flags;
+   struct arch_vm_region *c, *new;
+
+   new = kmalloc(sizeof(struct arch_vm_region), gfp);
+   if (!new)
+   goto out;
+
+   raw_spin_lock_irqsave(_lock, flags);
+
+   list_for_each_entry(c, >vm_list, vm_list) {
+   if ((addr + size) < addr)
+   goto nospc;
+   if ((addr + size) <= c->vm_start)
+   goto found;
+   addr = c->vm_end;
+   if (addr > end)
+   goto nospc;
+   }
+
+found:
+   /*
+* Insert this entry _before_ the one we found.
+*/
+   list_add_tail(>vm_list, >vm_list);
+   new->vm_start = addr;
+   new->vm_end = addr + size;
+
+   

Re: regression: UFO removal breaks kvm live migration

2017-11-07 Thread David Miller
From: Willem de Bruijn 
Date: Wed, 8 Nov 2017 12:36:26 +0900

> On Tue, Nov 7, 2017 at 5:02 PM, Michal Kubecek  wrote:
>> I didn't have time to think it through yet but perhaps we could allow
>> setting TUN_F_UFO and ignore its value.
> 
> If the feature is enabled guests may try to send UFO packets, which
> the host is no longer able to fragment.
> 
> virtio_net_hdr_to_skb will drop the packets immediately based on
> gso_type and tun_get_user will return EINVAL.
> 
> Still, perhaps that's preferable as migration will succeed and most
> guests won't ever try to send those packets in the first place.

However, this would create the situation where there is no way
to properly probe for the actual presence of UFO support.


[PATCH 19/31] nds32: Debugging support

2017-11-07 Thread Greentime Hu
From: Greentime Hu 

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/include/uapi/asm/ptrace.h |   42 +
 arch/nds32/kernel/ptrace.c   |  325 ++
 2 files changed, 367 insertions(+)
 create mode 100644 arch/nds32/include/uapi/asm/ptrace.h
 create mode 100644 arch/nds32/kernel/ptrace.c

diff --git a/arch/nds32/include/uapi/asm/ptrace.h 
b/arch/nds32/include/uapi/asm/ptrace.h
new file mode 100644
index 000..20f9718
--- /dev/null
+++ b/arch/nds32/include/uapi/asm/ptrace.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#ifndef __UAPI_ASM_NDS32_PTRACE_H
+#define __UAPI_ASM_NDS32_PTRACE_H
+
+#ifndef __ASSEMBLY__
+
+/*
+ * User structures for general purpose register.
+ */
+struct user_pt_regs {
+   long uregs[26];
+   long fp;
+   long gp;
+   long lp;
+   long sp;
+   long ipc;
+#if defined(CONFIG_HWZOL)
+   long lb;
+   long le;
+   long lc;
+#else
+   long dummy[3];
+#endif
+   long syscallno;
+};
+#endif
+#endif
diff --git a/arch/nds32/kernel/ptrace.c b/arch/nds32/kernel/ptrace.c
new file mode 100644
index 000..d91b3b8
--- /dev/null
+++ b/arch/nds32/kernel/ptrace.c
@@ -0,0 +1,325 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+enum nds32_regset {
+   REGSET_GPR,
+};
+
+static int gpr_get(struct task_struct *target,
+  const struct user_regset *regset,
+  unsigned int pos, unsigned int count,
+  void *kbuf, void __user * ubuf)
+{
+   struct user_pt_regs *uregs = _pt_regs(target)->user_regs;
+   return user_regset_copyout(, , , , uregs, 0, -1);
+}
+
+static int gpr_set(struct task_struct *target, const struct user_regset 
*regset,
+  unsigned int pos, unsigned int count,
+  const void *kbuf, const void __user * ubuf)
+{
+   int err;
+   struct user_pt_regs newregs = task_pt_regs(target)->user_regs;
+
+   err = user_regset_copyin(, , , , , 0, -1);
+   if (err)
+   return err;
+
+   task_pt_regs(target)->user_regs = newregs;
+   return 0;
+}
+
+static const struct user_regset nds32_regsets[] = {
+   [REGSET_GPR] = {
+   .core_note_type = NT_PRSTATUS,
+   .n = sizeof(struct user_pt_regs) / sizeof(u32),
+   .size = sizeof(u32),
+   .align = sizeof(u32),
+   .get = gpr_get,
+   .set = gpr_set}
+};
+
+static const struct user_regset_view nds32_user_view = {
+   .name = "nds32",.e_machine = EM_NDS32,
+   .regsets = nds32_regsets,.n = ARRAY_SIZE(nds32_regsets)
+};
+
+const struct user_regset_view *task_user_regset_view(struct task_struct *task)
+{
+   return _user_view;
+}
+
+/* get_user_reg()
+ *
+ * This routine will get a word off of the processes privileged stack.
+ * the offset is how far from the base addr as stored in the THREAD.
+ * this routine assumes that all the privileged stacks are in our
+ * data space.
+ */
+static inline unsigned int get_user_reg(struct task_struct *task, int offset)
+{
+   return task_pt_regs(task)->uregs[offset];
+}
+
+/* put_user_reg()
+ *
+ * this routine will put a word on the processes privileged stack.
+ * the offset is how far from the base addr as stored in the THREAD.
+ * this routine assumes that all the privileged stacks are in our
+ * data space.
+ */
+static inline int put_user_reg(struct task_struct *task, int offset, 

[PATCH 17/31] nds32: Signal handling support

2017-11-07 Thread Greentime Hu
From: Greentime Hu 

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/include/uapi/asm/sigcontext.h |   73 ++
 arch/nds32/include/uapi/asm/signal.h |   23 ++
 arch/nds32/kernel/signal.c   |  370 ++
 3 files changed, 466 insertions(+)
 create mode 100644 arch/nds32/include/uapi/asm/sigcontext.h
 create mode 100644 arch/nds32/include/uapi/asm/signal.h
 create mode 100644 arch/nds32/kernel/signal.c

diff --git a/arch/nds32/include/uapi/asm/sigcontext.h 
b/arch/nds32/include/uapi/asm/sigcontext.h
new file mode 100644
index 000..1c0dfcb
--- /dev/null
+++ b/arch/nds32/include/uapi/asm/sigcontext.h
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#ifndef _ASMNDS32_SIGCONTEXT_H
+#define _ASMNDS32_SIGCONTEXT_H
+
+/*
+ * Signal context structure - contains all info to do with the state
+ * before the signal handler was invoked.  Note: only add new entries
+ * to the end of the structure.
+ */
+
+struct zol_struct {
+   unsigned long nds32_lc; /* $LC */
+   unsigned long nds32_le; /* $LE */
+   unsigned long nds32_lb; /* $LB */
+};
+
+struct sigcontext {
+   unsigned long trap_no;
+   unsigned long error_code;
+   unsigned long oldmask;
+   unsigned long nds32_r0;
+   unsigned long nds32_r1;
+   unsigned long nds32_r2;
+   unsigned long nds32_r3;
+   unsigned long nds32_r4;
+   unsigned long nds32_r5;
+   unsigned long nds32_r6;
+   unsigned long nds32_r7;
+   unsigned long nds32_r8;
+   unsigned long nds32_r9;
+   unsigned long nds32_r10;
+   unsigned long nds32_r11;
+   unsigned long nds32_r12;
+   unsigned long nds32_r13;
+   unsigned long nds32_r14;
+   unsigned long nds32_r15;
+   unsigned long nds32_r16;
+   unsigned long nds32_r17;
+   unsigned long nds32_r18;
+   unsigned long nds32_r19;
+   unsigned long nds32_r20;
+   unsigned long nds32_r21;
+   unsigned long nds32_r22;
+   unsigned long nds32_r23;
+   unsigned long nds32_r24;
+   unsigned long nds32_r25;
+   unsigned long nds32_fp; /* $r28 */
+   unsigned long nds32_gp; /* $r29 */
+   unsigned long nds32_lp; /* $r30 */
+   unsigned long nds32_sp; /* $r31 */
+   unsigned long nds32_ipc;
+   unsigned long fault_address;
+   unsigned long used_math_flag;
+   /* FPU Registers */
+   struct zol_struct zol;
+};
+
+#endif
diff --git a/arch/nds32/include/uapi/asm/signal.h 
b/arch/nds32/include/uapi/asm/signal.h
new file mode 100644
index 000..5ef6915
--- /dev/null
+++ b/arch/nds32/include/uapi/asm/signal.h
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#ifndef _ASMNDS32_SIGNAL_H
+#define _ASMNDS32_SIGNAL_H
+
+#define SA_RESTORER0x0400
+
+#include 
+#endif
diff --git a/arch/nds32/kernel/signal.c b/arch/nds32/kernel/signal.c
new file mode 100644
index 000..4bcc45b
--- /dev/null
+++ b/arch/nds32/kernel/signal.c
@@ -0,0 +1,370 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#include 

[PATCH 16/31] nds32: VDSO support

2017-11-07 Thread Greentime Hu
From: Greentime Hu 

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/include/asm/vdso.h  |   35 
 arch/nds32/include/asm/vdso_datapage.h |   51 ++
 arch/nds32/kernel/vdso.c   |  243 ++
 arch/nds32/kernel/vdso/Makefile|   82 +
 arch/nds32/kernel/vdso/datapage.S  |   34 
 arch/nds32/kernel/vdso/gen_vdso_offsets.sh |   15 ++
 arch/nds32/kernel/vdso/gettimeofday.c  |  260 
 arch/nds32/kernel/vdso/note.S  |   29 
 arch/nds32/kernel/vdso/sigreturn.S |   32 
 arch/nds32/kernel/vdso/vdso.S  |   33 
 arch/nds32/kernel/vdso/vdso.lds.S  |   87 ++
 11 files changed, 901 insertions(+)
 create mode 100644 arch/nds32/include/asm/vdso.h
 create mode 100644 arch/nds32/include/asm/vdso_datapage.h
 create mode 100644 arch/nds32/kernel/vdso.c
 create mode 100644 arch/nds32/kernel/vdso/Makefile
 create mode 100644 arch/nds32/kernel/vdso/datapage.S
 create mode 100755 arch/nds32/kernel/vdso/gen_vdso_offsets.sh
 create mode 100644 arch/nds32/kernel/vdso/gettimeofday.c
 create mode 100644 arch/nds32/kernel/vdso/note.S
 create mode 100644 arch/nds32/kernel/vdso/sigreturn.S
 create mode 100644 arch/nds32/kernel/vdso/vdso.S
 create mode 100644 arch/nds32/kernel/vdso/vdso.lds.S

diff --git a/arch/nds32/include/asm/vdso.h b/arch/nds32/include/asm/vdso.h
new file mode 100644
index 000..7298c49
--- /dev/null
+++ b/arch/nds32/include/asm/vdso.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#ifndef __ASM_VDSO_H
+#define __ASM_VDSO_H
+
+#ifdef __KERNEL__
+
+#ifndef __ASSEMBLY__
+
+#include 
+
+#define VDSO_SYMBOL(base, name)
   \
+({\
+   (unsigned long)(vdso_offset_##name + (unsigned long)(base)); \
+})
+
+#endif /* !__ASSEMBLY__ */
+
+#endif /* __KERNEL__ */
+
+#endif /* __ASM_VDSO_H */
diff --git a/arch/nds32/include/asm/vdso_datapage.h 
b/arch/nds32/include/asm/vdso_datapage.h
new file mode 100644
index 000..ffae33c
--- /dev/null
+++ b/arch/nds32/include/asm/vdso_datapage.h
@@ -0,0 +1,51 @@
+/*
+ * Adapted from arm64 version.
+ *
+ * Copyright (C) 2012 ARM Limited
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+#ifndef __ASM_VDSO_DATAPAGE_H
+#define __ASM_VDSO_DATAPAGE_H
+
+#ifdef __KERNEL__
+
+#ifndef __ASSEMBLY__
+
+struct vdso_data {
+   bool cycle_count_down;  /* timer cyclye counter is decrease with time */
+   u32 cycle_count_offset; /* offset of timer cycle counter register */
+   u32 seq_count;  /* sequence count - odd during updates */
+   u32 xtime_coarse_sec;   /* coarse time */
+   u32 xtime_coarse_nsec;
+
+   u32 wtm_clock_sec;  /* wall to monotonic offset */
+   u32 wtm_clock_nsec;
+   u32 xtime_clock_sec;/* CLOCK_REALTIME - seconds */
+   u32 cs_mult;/* clocksource multiplier */
+   u32 cs_shift;   /* Cycle to nanosecond divisor (power of two) */
+
+   u64 cs_cycle_last;  /* last cycle value */
+   u64 cs_mask;/* clocksource mask */
+
+   u64 xtime_clock_nsec;   /* CLOCK_REALTIME sub-ns base */
+   u32 tz_minuteswest; /* timezone info for gettimeofday(2) */
+   u32 tz_dsttime;
+};
+
+#endif /* !__ASSEMBLY__ */
+
+#endif /* __KERNEL__ */
+
+#endif /* __ASM_VDSO_DATAPAGE_H */
diff --git a/arch/nds32/kernel/vdso.c b/arch/nds32/kernel/vdso.c
new file mode 100644
index 000..d7ef70c
--- /dev/null
+++ b/arch/nds32/kernel/vdso.c
@@ -0,0 +1,243 @@
+/*
+ * VDSO implementation 

[PATCH 15/31] nds32: System calls handling

2017-11-07 Thread Greentime Hu
From: Greentime Hu 

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/include/asm/syscall.h |  203 ++
 arch/nds32/include/asm/syscalls.h|   27 +
 arch/nds32/include/asm/unistd.h  |   21 
 arch/nds32/include/uapi/asm/unistd.h |   36 ++
 arch/nds32/kernel/ex-scall.S |  146 
 arch/nds32/kernel/sys_nds32.c|   63 +++
 arch/nds32/kernel/syscall_table.c|   28 +
 7 files changed, 524 insertions(+)
 create mode 100644 arch/nds32/include/asm/syscall.h
 create mode 100644 arch/nds32/include/asm/syscalls.h
 create mode 100644 arch/nds32/include/asm/unistd.h
 create mode 100644 arch/nds32/include/uapi/asm/unistd.h
 create mode 100644 arch/nds32/kernel/ex-scall.S
 create mode 100644 arch/nds32/kernel/sys_nds32.c
 create mode 100644 arch/nds32/kernel/syscall_table.c

diff --git a/arch/nds32/include/asm/syscall.h b/arch/nds32/include/asm/syscall.h
new file mode 100644
index 000..3066bae
--- /dev/null
+++ b/arch/nds32/include/asm/syscall.h
@@ -0,0 +1,203 @@
+/*
+ * Access to user system call parameters and results
+ *
+ * Copyright (C) 2008-2009 Red Hat, Inc.  All rights reserved.
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU General Public License v.2.
+ *
+ * This file is a stub providing documentation for what functions
+ * asm-ARCH/syscall.h files need to define.  Most arch definitions
+ * will be simple inlines.
+ *
+ * All of these functions expect to be called with no locks,
+ * and only when the caller is sure that the task of interest
+ * cannot return to user mode while we are looking at it.
+ */
+
+#ifndef _ASM_NDS32_SYSCALL_H
+#define _ASM_NDS32_SYSCALL_H   1
+
+#include 
+struct task_struct;
+struct pt_regs;
+
+/**
+ * syscall_get_nr - find what system call a task is executing
+ * @task:  task of interest, must be blocked
+ * @regs:  task_pt_regs() of @task
+ *
+ * If @task is executing a system call or is at system call
+ * tracing about to attempt one, returns the system call number.
+ * If @task is not executing a system call, i.e. it's blocked
+ * inside the kernel for a fault or signal, returns -1.
+ *
+ * Note this returns int even on 64-bit machines.  Only 32 bits of
+ * system call number can be meaningful.  If the actual arch value
+ * is 64 bits, this truncates to 32 bits so 0x means -1.
+ *
+ * It's only valid to call this when @task is known to be blocked.
+ */
+int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
+{
+   return regs->syscallno;
+}
+
+/**
+ * syscall_rollback - roll back registers after an aborted system call
+ * @task:  task of interest, must be in system call exit tracing
+ * @regs:  task_pt_regs() of @task
+ *
+ * It's only valid to call this when @task is stopped for system
+ * call exit tracing (due to TIF_SYSCALL_TRACE or TIF_SYSCALL_AUDIT),
+ * after tracehook_report_syscall_entry() returned nonzero to prevent
+ * the system call from taking place.
+ *
+ * This rolls back the register state in @regs so it's as if the
+ * system call instruction was a no-op.  The registers containing
+ * the system call number and arguments are as they were before the
+ * system call instruction.  This may not be the same as what the
+ * register state looked like at system call entry tracing.
+ */
+void syscall_rollback(struct task_struct *task, struct pt_regs *regs)
+{
+   regs->uregs[0] = regs->orig_r0;
+}
+
+/**
+ * syscall_get_error - check result of traced system call
+ * @task:  task of interest, must be blocked
+ * @regs:  task_pt_regs() of @task
+ *
+ * Returns 0 if the system call succeeded, or -ERRORCODE if it failed.
+ *
+ * It's only valid to call this when @task is stopped for tracing on exit
+ * from a system call, due to %TIF_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT.
+ */
+long syscall_get_error(struct task_struct *task, struct pt_regs *regs)
+{
+   unsigned long error = regs->uregs[0];
+   return IS_ERR_VALUE(error) ? error : 0;
+}
+
+/**
+ * syscall_get_return_value - get the return value of a traced system call
+ * @task:  task of interest, must be blocked
+ * @regs:  task_pt_regs() of @task
+ *
+ * Returns the return value of the successful system call.
+ * This value is meaningless if syscall_get_error() returned nonzero.
+ *
+ * It's only valid to call this when @task is stopped for tracing on exit
+ * from a system call, due to %TIF_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT.
+ */
+long syscall_get_return_value(struct task_struct *task, struct pt_regs *regs)
+{
+   return regs->uregs[0];
+}
+
+/**
+ * syscall_set_return_value - change the return value of a traced system call
+ * @task:  task of interest, must be blocked

[PATCH 22/31] nds32: Generic timers support

2017-11-07 Thread Greentime Hu
From: Greentime Hu 

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/kernel/time.c |   22 ++
 1 file changed, 22 insertions(+)
 create mode 100644 arch/nds32/kernel/time.c

diff --git a/arch/nds32/kernel/time.c b/arch/nds32/kernel/time.c
new file mode 100644
index 000..96e2f87
--- /dev/null
+++ b/arch/nds32/kernel/time.c
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#include 
+
+void __init time_init(void)
+{
+   timer_probe();
+}
-- 
1.7.9.5



[PATCH 23/31] nds32: Device tree support

2017-11-07 Thread Greentime Hu
From: Greentime Hu 

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/boot/dts/Makefile   |8 ++
 arch/nds32/boot/dts/ae3xx.dts  |   55 
 arch/nds32/boot/dts/ag101p.dts |   60 
 arch/nds32/kernel/devtree.c|   45 ++
 4 files changed, 168 insertions(+)
 create mode 100644 arch/nds32/boot/dts/Makefile
 create mode 100644 arch/nds32/boot/dts/ae3xx.dts
 create mode 100644 arch/nds32/boot/dts/ag101p.dts
 create mode 100644 arch/nds32/kernel/devtree.c

diff --git a/arch/nds32/boot/dts/Makefile b/arch/nds32/boot/dts/Makefile
new file mode 100644
index 000..d31faa8
--- /dev/null
+++ b/arch/nds32/boot/dts/Makefile
@@ -0,0 +1,8 @@
+ifneq '$(CONFIG_NDS32_BUILTIN_DTB)' '""'
+BUILTIN_DTB := $(patsubst "%",%,$(CONFIG_NDS32_BUILTIN_DTB)).dtb.o
+else
+BUILTIN_DTB :=
+endif
+obj-$(CONFIG_OF) += $(BUILTIN_DTB)
+
+clean-files := *.dtb *.dtb.S
diff --git a/arch/nds32/boot/dts/ae3xx.dts b/arch/nds32/boot/dts/ae3xx.dts
new file mode 100644
index 000..b6c85dc
--- /dev/null
+++ b/arch/nds32/boot/dts/ae3xx.dts
@@ -0,0 +1,55 @@
+/dts-v1/;
+/ {
+   compatible = "nds32 ae3xx";
+   #address-cells = <1>;
+   #size-cells = <1>;
+   interrupt-parent = <>;
+
+   chosen {
+   bootargs = "console=ttyS0,38400n8 
earlyprintk=uart8250-32bit,0xf030 debug loglevel=7";
+   };
+
+   memory@0 {
+   device_type = "memory";
+   reg = <0x 0x4000>;
+   };
+
+   cpus {
+   cpu@0 {
+   device_type = "cpu";
+   compatible = "andestech,n13", "andestech,n15";
+   };
+   };
+
+   intc: interrupt-controller {
+   compatible = "andestech,ativic32";
+   #interrupt-cells = <2>;
+   interrupt-controller;
+   };
+
+   serial0: serial@f030 {
+   compatible = "andestech,uart16550", "ns16550a";
+   reg = <0xf030 0x1000>;
+   interrupts = <8 4>;
+   clock-frequency = <14745600>;
+   reg-shift = <2>;
+   reg-offset = <32>;
+   no-loopback-test = <1>;
+   };
+
+   timer0: timer@f040 {
+   compatible = "andestech,atcpit100";
+   reg = <0xf040 0x1000>;
+   interrupts = <2 4>;
+   clock-frequency = <3000>;
+   cycle-count-offset = <0x38>;
+   cycle-count-down;
+   };
+
+   mac0: mac@e010 {
+   compatible = "andestech,atmac100";
+   reg = <0xe010 0x1000>;
+   interrupts = <18 4>;
+   };
+
+};
diff --git a/arch/nds32/boot/dts/ag101p.dts b/arch/nds32/boot/dts/ag101p.dts
new file mode 100644
index 000..b34760b
--- /dev/null
+++ b/arch/nds32/boot/dts/ag101p.dts
@@ -0,0 +1,60 @@
+/dts-v1/;
+/ {
+   compatible = "nds32 ag101p";
+   #address-cells = <1>;
+   #size-cells = <1>;
+   interrupt-parent = <>;
+
+   chosen {
+   bootargs = "console=ttyS0,38400n8 
earlyprintk=uart8250-32bit,0x9960 debug loglevel=7";
+   };
+
+   memory@0 {
+   device_type = "memory";
+   reg = <0x 0x4000>;
+   };
+
+   cpus {
+   cpu@0 {
+   device_type = "cpu";
+   compatible = "andestech,n13";
+   next-level-cache = <>;
+   };
+   };
+
+   intc: interrupt-controller {
+   compatible = "andestech,atnointc010";
+   #interrupt-cells = <2>;
+   interrupt-controller;
+   };
+
+   serial0: serial@9960 {
+   compatible = "andestech,uart16550", "ns16550a";
+   reg = <0x9960 0x1000>;
+   interrupts = <7 4>;
+   clock-frequency = <14745600>;
+   reg-shift = <2>;
+   no-loopback-test = <1>;
+   };
+
+   timer0: timer@9840 {
+   compatible = "andestech,atftmr010";
+   reg = <0x9840 0x1000>;
+   interrupts = <19 4>;
+   clock-frequency = <1500>;
+   cycle-count-offset = <0x20>;
+   };
+
+   mac0: mac@9090 {
+   compatible = "andestech,atmac100";
+   reg = <0x9090 0x1000>;
+   interrupts = <25 4>;
+   };
+
+   L2: l2-cache {
+   compatible = "andestech,atl2c";
+   reg = <0x90f0 0x1000>;
+   cache-unified;
+   cache-level = <2>;
+   };
+};
diff --git a/arch/nds32/kernel/devtree.c b/arch/nds32/kernel/devtree.c
new file mode 100644
index 000..2af0f1c
--- /dev/null
+++ b/arch/nds32/kernel/devtree.c
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology 

[PATCH 18/31] nds32: Library functions

2017-11-07 Thread Greentime Hu
From: Greentime Hu 

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/include/asm/string.h  |   30 +++
 arch/nds32/include/asm/swab.h|   48 +
 arch/nds32/include/asm/uaccess.h |  385 ++
 arch/nds32/kernel/nds32_ksyms.c  |   54 ++
 arch/nds32/lib/Makefile  |4 +
 arch/nds32/lib/getuser.S |   57 ++
 arch/nds32/lib/memcpy.S  |   93 +
 arch/nds32/lib/memmove.S |   83 
 arch/nds32/lib/memset.S  |   46 +
 arch/nds32/lib/memzero.S |   31 +++
 arch/nds32/lib/putuser.S |   53 ++
 arch/nds32/lib/uaccess.S |  160 
 12 files changed, 1044 insertions(+)
 create mode 100644 arch/nds32/include/asm/string.h
 create mode 100644 arch/nds32/include/asm/swab.h
 create mode 100644 arch/nds32/include/asm/uaccess.h
 create mode 100644 arch/nds32/kernel/nds32_ksyms.c
 create mode 100644 arch/nds32/lib/Makefile
 create mode 100644 arch/nds32/lib/getuser.S
 create mode 100644 arch/nds32/lib/memcpy.S
 create mode 100644 arch/nds32/lib/memmove.S
 create mode 100644 arch/nds32/lib/memset.S
 create mode 100644 arch/nds32/lib/memzero.S
 create mode 100644 arch/nds32/lib/putuser.S
 create mode 100644 arch/nds32/lib/uaccess.S

diff --git a/arch/nds32/include/asm/string.h b/arch/nds32/include/asm/string.h
new file mode 100644
index 000..cf4d4b8
--- /dev/null
+++ b/arch/nds32/include/asm/string.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#ifndef __ASM_NDS32_STRING_H
+#define __ASM_NDS32_STRING_H
+
+#define __HAVE_ARCH_MEMCPY
+extern void *memcpy(void *, const void *, __kernel_size_t);
+
+#define __HAVE_ARCH_MEMMOVE
+extern void *memmove(void *, const void *, __kernel_size_t);
+
+#define __HAVE_ARCH_MEMSET
+extern void *memset(void *, int, __kernel_size_t);
+
+extern void *memzero(void *ptr, __kernel_size_t n);
+#endif
diff --git a/arch/nds32/include/asm/swab.h b/arch/nds32/include/asm/swab.h
new file mode 100644
index 000..4815d6a
--- /dev/null
+++ b/arch/nds32/include/asm/swab.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#ifndef __NDS32_SWAB_H__
+#define __NDS32_SWAB_H__
+
+#include 
+#include 
+
+static __inline__ __attribute_const__ __u32 ___arch__swab32(__u32 x)
+{
+   __asm__("wsbh   %0, %0\n\t" /* word swap byte within halfword */
+   "rotri  %0, %0, #16\n"
+   :"=r"(x)
+   :"0"(x));
+   return x;
+}
+
+static __inline__ __attribute_const__ __u16 ___arch__swab16(__u16 x)
+{
+   __asm__("wsbh   %0, %0\n"   /* word swap byte within halfword */
+   :"=r"(x)
+   :"0"(x));
+   return x;
+}
+
+#define __arch_swab32(x) ___arch__swab32(x)
+#define __arch_swab16(x) ___arch__swab16(x)
+
+#if !defined(__STRICT_ANSI__) || defined(__KERNEL__)
+#define __BYTEORDER_HAS_U64__
+#define __SWAB_64_THRU_32__
+#endif
+
+#endif /* __NDS32_SWAB_H__ */
diff --git a/arch/nds32/include/asm/uaccess.h b/arch/nds32/include/asm/uaccess.h
new file mode 100644
index 000..b87a41a
--- /dev/null
+++ b/arch/nds32/include/asm/uaccess.h
@@ -0,0 +1,385 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You 

[PATCH 21/31] nds32: Loadable modules

2017-11-07 Thread Greentime Hu
From: Greentime Hu 

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/include/asm/module.h |   24 
 arch/nds32/kernel/module.c  |  299 +++
 2 files changed, 323 insertions(+)
 create mode 100644 arch/nds32/include/asm/module.h
 create mode 100644 arch/nds32/kernel/module.c

diff --git a/arch/nds32/include/asm/module.h b/arch/nds32/include/asm/module.h
new file mode 100644
index 000..5ed2b75
--- /dev/null
+++ b/arch/nds32/include/asm/module.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#ifndef _ASM_NDS32_MODULE_H
+#define _ASM_NDS32_MODULE_H
+
+#include 
+
+#define MODULE_ARCH_VERMAGIC   "NDS32v3"
+
+#endif /* _ASM_NDS32_MODULE_H */
diff --git a/arch/nds32/kernel/module.c b/arch/nds32/kernel/module.c
new file mode 100644
index 000..bb34e23
--- /dev/null
+++ b/arch/nds32/kernel/module.c
@@ -0,0 +1,299 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#include 
+#include 
+#include 
+
+#include 
+
+void *module_alloc(unsigned long size)
+{
+   return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
+   GFP_KERNEL, PAGE_KERNEL, 0, NUMA_NO_NODE,
+   __builtin_return_address(0));
+}
+
+void module_free(struct module *module, void *region)
+{
+   vfree(region);
+}
+
+int module_frob_arch_sections(Elf_Ehdr * hdr,
+ Elf_Shdr * sechdrs,
+ char *secstrings, struct module *mod)
+{
+   return 0;
+}
+
+void do_reloc16(unsigned int val, unsigned int *loc, unsigned int val_mask,
+   unsigned int val_shift, unsigned int loc_mask,
+   unsigned int partial_in_place, unsigned int swap)
+{
+   unsigned int tmp = 0, tmp2 = 0;
+
+   __asm__ __volatile__("\tlhi.bi\t%0, [%2], 0\n"
+"\tbeqz\t%3, 1f\n"
+"\twsbh\t%0, %1\n"
+"1:\n":"=r"(tmp):"0"(tmp), "r"(loc), "r"(swap)
+   );
+
+   tmp2 = tmp & loc_mask;
+   if (partial_in_place) {
+   tmp &= (!loc_mask);
+   tmp =
+   tmp2 | ((tmp + ((val & val_mask) >> val_shift)) & val_mask);
+   } else {
+   tmp = tmp2 | ((val & val_mask) >> val_shift);
+   }
+
+   __asm__ __volatile__("\tbeqz\t%3, 2f\n"
+"\twsbh\t%0, %1\n"
+"2:\n"
+"\tshi.bi\t%0, [%2], 0\n":"=r"(tmp):"0"(tmp),
+"r"(loc), "r"(swap)
+   );
+}
+
+void do_reloc32(unsigned int val, unsigned int *loc, unsigned int val_mask,
+   unsigned int val_shift, unsigned int loc_mask,
+   unsigned int partial_in_place, unsigned int swap)
+{
+   unsigned int tmp = 0, tmp2 = 0;
+
+   __asm__ __volatile__("\tlmw.bi\t%0, [%2], %0, 0\n"
+"\tbeqz\t%3, 1f\n"
+"\twsbh\t%0, %1\n"
+"\trotri\t%0, %1, 16\n"
+"1:\n":"=r"(tmp):"0"(tmp), "r"(loc), "r"(swap)
+   );
+
+   tmp2 = tmp & loc_mask;
+   if (partial_in_place) {
+   tmp &= (!loc_mask);
+   tmp =
+   tmp2 | ((tmp + ((val & val_mask) >> val_shift)) & val_mask);
+   } else {
+   tmp = tmp2 | ((val & val_mask) >> val_shift);
+   }
+
+   __asm__ __volatile__("\tbeqz\t%3, 2f\n"
+"\twsbh\t%0, %1\n"
+"\trotri\t%0, %1, 16\n"
+"2:\n"
+"\tsmw.bi\t%0, 

[PATCH 24/31] nds32: Miscellaneous header files

2017-11-07 Thread Greentime Hu
From: Greentime Hu 

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/include/asm/delay.h|   51 +
 arch/nds32/include/asm/linkage.h  |   24 ++
 arch/nds32/include/uapi/asm/byteorder.h   |   26 +++
 arch/nds32/include/uapi/asm/posix_types.h |   41 +++
 4 files changed, 142 insertions(+)
 create mode 100644 arch/nds32/include/asm/delay.h
 create mode 100644 arch/nds32/include/asm/linkage.h
 create mode 100644 arch/nds32/include/uapi/asm/byteorder.h
 create mode 100644 arch/nds32/include/uapi/asm/posix_types.h

diff --git a/arch/nds32/include/asm/delay.h b/arch/nds32/include/asm/delay.h
new file mode 100644
index 000..bdeeb76
--- /dev/null
+++ b/arch/nds32/include/asm/delay.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#ifndef __NDS32_DELAY_H__
+#define __NDS32_DELAY_H__
+
+#include 
+
+static inline void __delay(unsigned long loops)
+{
+   __asm__ __volatile__(".align 2\n"
+"1:\n"
+"\taddi\t%0, %0, -1\n"
+"\tbgtz\t%0, 1b\n"
+:"=r"(loops)
+:"0"(loops));
+}
+
+static inline void __udelay(unsigned long usecs, unsigned long lpj)
+{
+   usecs *= (unsigned long)(((0x8000ULL / (50 / HZ)) +
+ 0x8000ULL) >> 32);
+   usecs = (unsigned long)(((unsigned long long)usecs * lpj) >> 32);
+   __delay(usecs);
+}
+
+#define udelay(usecs) __udelay((usecs), loops_per_jiffy)
+
+/* make sure "usecs *= ..." in udelay do not overflow. */
+#if HZ >= 1000
+#define MAX_UDELAY_MS  1
+#elif HZ <= 200
+#define MAX_UDELAY_MS  5
+#else
+#define MAX_UDELAY_MS  (1000 / HZ)
+#endif
+
+#endif
diff --git a/arch/nds32/include/asm/linkage.h b/arch/nds32/include/asm/linkage.h
new file mode 100644
index 000..d17abd8
--- /dev/null
+++ b/arch/nds32/include/asm/linkage.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#ifndef __ASM_LINKAGE_H
+#define __ASM_LINKAGE_H
+
+/* This file is required by include/linux/linkage.h */
+#define __ALIGN .align 2
+#define __ALIGN_STR ".align 2"
+
+#endif
diff --git a/arch/nds32/include/uapi/asm/byteorder.h 
b/arch/nds32/include/uapi/asm/byteorder.h
new file mode 100644
index 000..198e8dd
--- /dev/null
+++ b/arch/nds32/include/uapi/asm/byteorder.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#ifndef __NDS32_BYTEORDER_H__
+#define __NDS32_BYTEORDER_H__
+
+#ifdef __NDS32_EB__
+#include 
+#else
+#include 
+#endif
+
+#endif /* __NDS32_BYTEORDER_H__ */
diff --git a/arch/nds32/include/uapi/asm/posix_types.h 
b/arch/nds32/include/uapi/asm/posix_types.h
new file mode 100644
index 000..d0aca66
--- /dev/null
+++ b/arch/nds32/include/uapi/asm/posix_types.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General 

[PATCH 28/31] irqchip: Andestech Internal Vector Interrupt Controller driver

2017-11-07 Thread Greentime Hu
From: Greentime Hu 

Signed-off-by: Rick Chen 
Signed-off-by: Greentime Hu 
---
 drivers/irqchip/Makefile   |1 +
 drivers/irqchip/irq-ativic32.c |  149 
 2 files changed, 150 insertions(+)
 create mode 100644 drivers/irqchip/irq-ativic32.c

diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile
index b842dfd..201ca9f 100644
--- a/drivers/irqchip/Makefile
+++ b/drivers/irqchip/Makefile
@@ -80,3 +80,4 @@ obj-$(CONFIG_ARCH_ASPEED) += irq-aspeed-vic.o 
irq-aspeed-i2c-ic.o
 obj-$(CONFIG_STM32_EXTI)   += irq-stm32-exti.o
 obj-$(CONFIG_QCOM_IRQ_COMBINER)+= qcom-irq-combiner.o
 obj-$(CONFIG_IRQ_UNIPHIER_AIDET)   += irq-uniphier-aidet.o
+obj-$(CONFIG_NDS32)+= irq-ativic32.o
diff --git a/drivers/irqchip/irq-ativic32.c b/drivers/irqchip/irq-ativic32.c
new file mode 100644
index 000..d3dae59
--- /dev/null
+++ b/drivers/irqchip/irq-ativic32.c
@@ -0,0 +1,149 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static void ativic32_ack_irq(struct irq_data *data)
+{
+   __nds32__mtsr_dsb(1 << data->hwirq, NDS32_SR_INT_PEND2);
+}
+
+static void ativic32_mask_irq(struct irq_data *data)
+{
+   unsigned long int_mask2 = __nds32__mfsr(NDS32_SR_INT_MASK2);
+   __nds32__mtsr_dsb(int_mask2 & (~(1 << data->hwirq)), 
NDS32_SR_INT_MASK2);
+}
+
+static void ativic32_mask_ack_irq(struct irq_data *data)
+{
+   unsigned long int_mask2 = __nds32__mfsr(NDS32_SR_INT_MASK2);
+   __nds32__mtsr_dsb(int_mask2 & (~(1 << data->hwirq)), 
NDS32_SR_INT_MASK2);
+   __nds32__mtsr_dsb((1 << data->hwirq), NDS32_SR_INT_PEND2);
+
+}
+
+static void ativic32_unmask_irq(struct irq_data *data)
+{
+   unsigned long int_mask2 = __nds32__mfsr(NDS32_SR_INT_MASK2);
+   __nds32__mtsr_dsb(int_mask2 | (1 << data->hwirq), NDS32_SR_INT_MASK2);
+}
+
+static int ativic32_set_type(struct irq_data *data, unsigned int flow_type)
+{
+   printk(KERN_WARNING "interrupt type is not configurable\n");
+   return 0;
+}
+
+static struct irq_chip ativic32_chip = {
+   .name = "ativic32",
+   .irq_ack = ativic32_ack_irq,
+   .irq_mask = ativic32_mask_irq,
+   .irq_mask_ack = ativic32_mask_ack_irq,
+   .irq_unmask = ativic32_unmask_irq,
+   .irq_set_type = ativic32_set_type,
+};
+
+static unsigned int __initdata nivic_map[6] = { 6, 2, 10, 16, 24, 32 };
+
+struct irq_domain *root_domain;
+static int ativic32_irq_domain_map(struct irq_domain *id, unsigned int virq,
+ irq_hw_number_t hw)
+{
+
+   unsigned long int_trigger_type;
+   int_trigger_type = __nds32__mfsr(NDS32_SR_INT_TRIGGER);
+   if (int_trigger_type & (1 << hw))
+   irq_set_chip_and_handler(virq, _chip, handle_edge_irq);
+   else
+   irq_set_chip_and_handler(virq, _chip, 
handle_level_irq);
+
+   return 0;
+}
+
+static struct irq_domain_ops ativic32_ops = {
+   .map = ativic32_irq_domain_map,
+   .xlate = irq_domain_xlate_onecell
+};
+
+static int get_intr_src(void)
+{
+   return ((__nds32__mfsr(NDS32_SR_ITYPE)_mskVECTOR) >> 
ITYPE_offVECTOR)
+   - NDS32_VECTOR_offINTERRUPT;
+}
+
+asmlinkage void asm_do_IRQ(struct pt_regs *regs)
+{
+   struct pt_regs *old_regs = set_irq_regs(regs);
+   int virq;
+   int irq = get_intr_src();
+
+   /*
+* Some hardware gives randomly wrong interrupts.  Rather
+* than crashing, do something sensible.
+*/
+   if (unlikely(irq >= NR_IRQS)) {
+   pr_emerg( "IRQ exceeds NR_IRQS\n");
+   BUG();
+   }
+
+   irq_enter();
+   virq = irq_find_mapping(root_domain, irq);
+   generic_handle_irq(virq);
+   irq_exit();
+   set_irq_regs(old_regs);
+
+}
+
+int __init ativic32_init_irq(struct device_node *node, struct device_node 
*parent)
+{
+   unsigned long int_vec_base, nivic, i;
+
+   if (WARN(parent, "non-root ativic32 are not supported"))
+   return -EINVAL;
+
+   int_vec_base = __nds32__mfsr(NDS32_SR_IVB);
+
+   if (((int_vec_base & IVB_mskIVIC_VER) >> IVB_offIVIC_VER) == 0) {
+   panic("Unable to use NOINTC option to boot on 

[PATCH 25/31] nds32: defconfig

2017-11-07 Thread Greentime Hu
From: Greentime Hu 

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/configs/ae3xx_defconfig  |  110 +++
 arch/nds32/configs/ag101p_defconfig |  109 ++
 2 files changed, 219 insertions(+)
 create mode 100644 arch/nds32/configs/ae3xx_defconfig
 create mode 100644 arch/nds32/configs/ag101p_defconfig

diff --git a/arch/nds32/configs/ae3xx_defconfig 
b/arch/nds32/configs/ae3xx_defconfig
new file mode 100644
index 000..14d49a3
--- /dev/null
+++ b/arch/nds32/configs/ae3xx_defconfig
@@ -0,0 +1,110 @@
+CONFIG_CROSS_COMPILE="nds32le-linux-"
+CONFIG_SYSVIPC=y
+CONFIG_POSIX_MQUEUE=y
+CONFIG_HIGH_RES_TIMERS=y
+CONFIG_BSD_PROCESS_ACCT=y
+CONFIG_BSD_PROCESS_ACCT_V3=y
+CONFIG_IKCONFIG=y
+CONFIG_IKCONFIG_PROC=y
+CONFIG_LOG_BUF_SHIFT=14
+CONFIG_NAMESPACES=y
+CONFIG_USER_NS=y
+CONFIG_RELAY=y
+CONFIG_BLK_DEV_INITRD=y
+CONFIG_SYSCTL_SYSCALL=y
+CONFIG_KALLSYMS_ALL=y
+CONFIG_EMBEDDED=y
+# CONFIG_VM_EVENT_COUNTERS is not set
+# CONFIG_SLUB_DEBUG is not set
+CONFIG_PROFILING=y
+CONFIG_MODULES=y
+CONFIG_MODULE_UNLOAD=y
+# CONFIG_BLK_DEV_BSG is not set
+# CONFIG_HWZOL is not set
+CONFIG_ANDES_PAGE_SIZE_8KB=y
+CONFIG_NDS32_BUILTIN_DTB="ae3xx"
+CONFIG_PREEMPT=y
+# CONFIG_COMPACTION is not set
+CONFIG_HZ_100=y
+# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
+CONFIG_NET=y
+CONFIG_PACKET=y
+CONFIG_UNIX=y
+CONFIG_NET_KEY=y
+CONFIG_INET=y
+CONFIG_IP_MULTICAST=y
+# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
+# CONFIG_INET_XFRM_MODE_TUNNEL is not set
+# CONFIG_INET_XFRM_MODE_BEET is not set
+# CONFIG_INET_DIAG is not set
+# CONFIG_IPV6 is not set
+CONFIG_BRIDGE=y
+CONFIG_BLK_DEV_LOOP=y
+CONFIG_BLK_DEV_RAM=y
+CONFIG_BLK_DEV_RAM_SIZE=8192
+CONFIG_NETDEVICES=y
+CONFIG_TUN=y
+# CONFIG_NET_CADENCE is not set
+# CONFIG_NET_VENDOR_BROADCOM is not set
+CONFIG_FTMAC100=y
+# CONFIG_NET_VENDOR_INTEL is not set
+# CONFIG_NET_VENDOR_MARVELL is not set
+# CONFIG_NET_VENDOR_MICREL is not set
+# CONFIG_NET_VENDOR_NATSEMI is not set
+# CONFIG_NET_VENDOR_SEEQ is not set
+# CONFIG_NET_VENDOR_STMICRO is not set
+# CONFIG_NET_VENDOR_WIZNET is not set
+CONFIG_INPUT_EVDEV=y
+# CONFIG_INPUT_KEYBOARD is not set
+# CONFIG_INPUT_MOUSE is not set
+CONFIG_INPUT_TOUCHSCREEN=y
+# CONFIG_SERIO is not set
+CONFIG_SERIAL_8250=y
+# CONFIG_SERIAL_8250_DEPRECATED_OPTIONS is not set
+CONFIG_SERIAL_8250_CONSOLE=y
+CONFIG_SERIAL_8250_NR_UARTS=3
+CONFIG_SERIAL_8250_RUNTIME_UARTS=3
+CONFIG_SERIAL_OF_PLATFORM=y
+# CONFIG_HW_RANDOM is not set
+# CONFIG_HWMON is not set
+CONFIG_WATCHDOG=y
+CONFIG_FB=y
+# CONFIG_VGA_CONSOLE is not set
+CONFIG_FRAMEBUFFER_CONSOLE=y
+CONFIG_LOGO=y
+CONFIG_SOUND=y
+CONFIG_SND=y
+# CONFIG_SND_SUPPORT_OLD_API is not set
+# CONFIG_SND_VERBOSE_PROCFS is not set
+# CONFIG_USB_SUPPORT is not set
+CONFIG_MMC=y
+CONFIG_RTC_CLASS=y
+# CONFIG_RTC_HCTOSYS is not set
+CONFIG_CLKSRC_ATCPIT100=y
+CONFIG_EXT2_FS=y
+CONFIG_FUSE_FS=y
+CONFIG_MSDOS_FS=y
+CONFIG_VFAT_FS=y
+CONFIG_TMPFS=y
+CONFIG_TMPFS_POSIX_ACL=y
+CONFIG_CONFIGFS_FS=y
+CONFIG_NFS_FS=y
+CONFIG_NFS_V3_ACL=y
+CONFIG_NFS_V4=y
+CONFIG_NFS_V4_1=y
+CONFIG_NFS_USE_LEGACY_DNS=y
+CONFIG_NLS_CODEPAGE_437=y
+CONFIG_NLS_ISO8859_1=y
+CONFIG_DEBUG_INFO=y
+CONFIG_DEBUG_INFO_DWARF4=y
+CONFIG_GDB_SCRIPTS=y
+CONFIG_READABLE_ASM=y
+CONFIG_HEADERS_CHECK=y
+CONFIG_DEBUG_SECTION_MISMATCH=y
+CONFIG_MAGIC_SYSRQ=y
+CONFIG_PANIC_ON_OOPS=y
+# CONFIG_SCHED_DEBUG is not set
+# CONFIG_DEBUG_PREEMPT is not set
+CONFIG_STACKTRACE=y
+CONFIG_RCU_CPU_STALL_TIMEOUT=300
+# CONFIG_CRYPTO_HW is not set
diff --git a/arch/nds32/configs/ag101p_defconfig 
b/arch/nds32/configs/ag101p_defconfig
new file mode 100644
index 000..0641a97
--- /dev/null
+++ b/arch/nds32/configs/ag101p_defconfig
@@ -0,0 +1,109 @@
+CONFIG_CROSS_COMPILE="nds32le-linux-"
+CONFIG_SYSVIPC=y
+CONFIG_POSIX_MQUEUE=y
+CONFIG_HIGH_RES_TIMERS=y
+CONFIG_BSD_PROCESS_ACCT=y
+CONFIG_BSD_PROCESS_ACCT_V3=y
+CONFIG_IKCONFIG=y
+CONFIG_IKCONFIG_PROC=y
+CONFIG_LOG_BUF_SHIFT=14
+CONFIG_NAMESPACES=y
+CONFIG_USER_NS=y
+CONFIG_RELAY=y
+CONFIG_BLK_DEV_INITRD=y
+CONFIG_SYSCTL_SYSCALL=y
+CONFIG_KALLSYMS_ALL=y
+CONFIG_EMBEDDED=y
+# CONFIG_VM_EVENT_COUNTERS is not set
+# CONFIG_SLUB_DEBUG is not set
+CONFIG_PROFILING=y
+CONFIG_MODULES=y
+CONFIG_MODULE_UNLOAD=y
+# CONFIG_BLK_DEV_BSG is not set
+# CONFIG_HWZOL is not set
+CONFIG_NDS32_BUILTIN_DTB="ag101p"
+CONFIG_PREEMPT=y
+# CONFIG_COMPACTION is not set
+CONFIG_HZ_100=y
+# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
+CONFIG_NET=y
+CONFIG_PACKET=y
+CONFIG_UNIX=y
+CONFIG_NET_KEY=y
+CONFIG_INET=y
+CONFIG_IP_MULTICAST=y
+# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
+# CONFIG_INET_XFRM_MODE_TUNNEL is not set
+# CONFIG_INET_XFRM_MODE_BEET is not set
+# CONFIG_INET_DIAG is not set
+# CONFIG_IPV6 is not set
+CONFIG_BRIDGE=y
+CONFIG_BLK_DEV_LOOP=y
+CONFIG_BLK_DEV_RAM=y
+CONFIG_BLK_DEV_RAM_SIZE=8192
+CONFIG_NETDEVICES=y
+CONFIG_TUN=y
+# CONFIG_NET_CADENCE is not set
+# 

[PATCH 20/31] nds32: L2 cache support

2017-11-07 Thread Greentime Hu
From: Greentime Hu 

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/include/asm/l2_cache.h |  158 +
 arch/nds32/kernel/atl2c.c |   77 ++
 2 files changed, 235 insertions(+)
 create mode 100644 arch/nds32/include/asm/l2_cache.h
 create mode 100644 arch/nds32/kernel/atl2c.c

diff --git a/arch/nds32/include/asm/l2_cache.h 
b/arch/nds32/include/asm/l2_cache.h
new file mode 100644
index 000..b8530bd
--- /dev/null
+++ b/arch/nds32/include/asm/l2_cache.h
@@ -0,0 +1,158 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#ifndef L2_CACHE_H
+#define L2_CACHE_H
+
+/* This is defined for head.S to use due to device tree is not yet built. */
+#define L2CC_PA_BASE   0x90F0
+
+/* CCTL_CMD_OP */
+#define L2_CA_CONF_OFF 0x0
+#defineL2_IF_CONF_OFF  0x4
+#define L2CC_SETUP_OFF 0x8
+#define L2CC_PROT_OFF  0xC
+#define L2CC_CTRL_OFF  0x10
+#define L2_INT_EN_OFF   0x20
+#define L2_STA_OFF  0x24
+#define RDERR_ADDR_OFF 0x28
+#define WRERR_ADDR_OFF 0x2c
+#define EVDPTERR_ADDR_OFF  0x30
+#define IMPL3ERR_ADDR_OFF  0x34
+#define L2_CNT0_CTRL_OFF0x40
+#define L2_EVNT_CNT0_OFF0x44
+#define L2_CNT1_CTRL_OFF0x48
+#define L2_EVNT_CNT1_OFF0x4c
+#define L2_CCTL_CMD_OFF0x60
+#define L2_CCTL_STATUS_OFF 0x64
+#define L2_LINE_TAG_OFF0x68
+#define L2_LINE_DPT_OFF0x70
+
+#define CCTL_CMD_L2_IX_INVAL0x0
+#define CCTL_CMD_L2_PA_INVAL0x1
+#define CCTL_CMD_L2_IX_WB   0x2
+#define CCTL_CMD_L2_PA_WB   0x3
+#define CCTL_CMD_L2_PA_WBINVAL  0x5
+#define CCTL_CMD_L2_SYNC0xa
+
+/* CCTL_CMD_TYPE */
+#define CCTL_SINGLE_CMD 0
+#define CCTL_BLOCK_CMD  0x10
+#define CCTL_ALL_CMD   0x10
+
+/**
+ * L2_CA_CONF (Cache architecture configuration)
+ */
+#define L2_CA_CONF_offL2SET0
+#define L2_CA_CONF_offL2WAY4
+#define L2_CA_CONF_offL2CLSZ8
+#define L2_CA_CONF_offL2DW 11
+#define L2_CA_CONF_offL2PT 14
+#define L2_CA_CONF_offL2VER16
+
+#define L2_CA_CONF_mskL2SET(0xFUL << L2_CA_CONF_offL2SET)
+#define L2_CA_CONF_mskL2WAY(0xFUL << L2_CA_CONF_offL2WAY)
+#define L2_CA_CONF_mskL2CLSZ(0x7UL << L2_CA_CONF_offL2CLSZ)
+#define L2_CA_CONF_mskL2DW (0x7UL << L2_CA_CONF_offL2DW)
+#define L2_CA_CONF_mskL2PT (0x3UL << L2_CA_CONF_offL2PT)
+#define L2_CA_CONF_mskL2VER(0xUL << L2_CA_CONF_offL2VER)
+
+/**
+ * L2CC_SETUP (L2CC Setup register)
+ */
+#define L2CC_SETUP_offPART  0
+#define L2CC_SETUP_mskPART  (0x3UL << L2CC_SETUP_offPART)
+#define L2CC_SETUP_offDDLATC4
+#define L2CC_SETUP_mskDDLATC(0x3UL << L2CC_SETUP_offDDLATC)
+#define L2CC_SETUP_offTDLATC8
+#define L2CC_SETUP_mskTDLATC(0x3UL << L2CC_SETUP_offTDLATC)
+
+/**
+ * L2CC_PROT (L2CC Protect register)
+ */
+#define L2CC_PROT_offMRWEN  31
+#define L2CC_PROT_mskMRWEN  (0x1UL << L2CC_PROT_offMRWEN)
+
+/**
+ * L2_CCTL_STATUS_Mn (The L2CCTL command working status for Master n)
+ */
+#define L2CC_CTRL_offEN 31
+#define L2CC_CTRL_mskEN (0x1UL << L2CC_CTRL_offEN)
+
+/**
+ * L2_CCTL_STATUS_Mn (The L2CCTL command working status for Master n)
+ */
+#define L2_CCTL_STATUS_offCMD_COMP  31
+#define L2_CCTL_STATUS_mskCMD_COMP  (0x1 << L2_CCTL_STATUS_offCMD_COMP)
+

[PATCH 26/31] nds32: Build infrastructure

2017-11-07 Thread Greentime Hu
From: Greentime Hu 

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/Kconfig |  107 
 arch/nds32/Kconfig.cpu |  100 +
 arch/nds32/Kconfig.debug   |   14 +
 arch/nds32/Makefile|   60 
 arch/nds32/boot/Makefile   |   15 +
 arch/nds32/include/asm/Kbuild  |   54 ++
 arch/nds32/include/uapi/asm/Kbuild |   26 +
 arch/nds32/kernel/Makefile |   24 
 arch/nds32/kernel/vmlinux.lds.S|   70 +++
 arch/nds32/mm/Makefile |7 +++
 10 files changed, 477 insertions(+)
 create mode 100644 arch/nds32/Kconfig
 create mode 100644 arch/nds32/Kconfig.cpu
 create mode 100644 arch/nds32/Kconfig.debug
 create mode 100644 arch/nds32/Makefile
 create mode 100644 arch/nds32/boot/Makefile
 create mode 100644 arch/nds32/include/asm/Kbuild
 create mode 100644 arch/nds32/include/uapi/asm/Kbuild
 create mode 100644 arch/nds32/kernel/Makefile
 create mode 100644 arch/nds32/kernel/vmlinux.lds.S
 create mode 100644 arch/nds32/mm/Makefile

diff --git a/arch/nds32/Kconfig b/arch/nds32/Kconfig
new file mode 100644
index 000..112f470
--- /dev/null
+++ b/arch/nds32/Kconfig
@@ -0,0 +1,107 @@
+#
+# For a description of the syntax of this configuration file,
+# see Documentation/kbuild/kconfig-language.txt.
+#
+
+config NDS32
+def_bool y
+   select ARCH_HAS_RAW_COPY_USER
+   select ARCH_WANT_FRAME_POINTERS if FTRACE
+   select ARCH_WANT_IPC_PARSE_VERSION
+   select CLKSRC_MMIO
+   select CLONE_BACKWARDS
+   select TIMER_OF
+   select FRAME_POINTER
+   select GENERIC_ATOMIC64
+   select GENERIC_CPU_DEVICES
+   select GENERIC_CLOCKEVENTS
+   select GENERIC_IOMAP
+   select GENERIC_IRQ_CHIP
+   select GENERIC_IRQ_PROBE
+   select GENERIC_IRQ_SHOW
+   select GENERIC_STRNCPY_FROM_USER
+   select GENERIC_STRNLEN_USER
+   select GENERIC_TIME_VSYSCALL
+   select HAVE_ARCH_TRACEHOOK
+   select HAVE_GENERIC_IOMAP
+   select HAVE_DEBUG_KMEMLEAK
+   select HAVE_IDE
+   select HAVE_MEMBLOCK
+   select HAVE_MEMBLOCK_NODE_MAP
+   select HAVE_UID16
+   select HAVE_REGS_AND_STACK_ACCESS_API
+   select IRQ_DOMAIN
+   select LOCKDEP_SUPPORT
+   select MODULES_USE_ELF_REL
+   select MODULES_USE_ELF_RELA
+   select OF
+   select OF_EARLY_FLATTREE
+   select OLD_SIGACTION
+   select OLD_SIGSUSPEND3
+   select NO_IOPORT_MAP
+   select RTC_LIB
+   select THREAD_INFO_IN_TASK
+   select SYS_SUPPORTS_APM_EMULATION
+   help
+ Andes(nds32) Linux support.
+
+config GENERIC_CALIBRATE_DELAY
+   def_bool y
+
+config GENERIC_CSUM
+def_bool y
+
+config GENERIC_HWEIGHT
+def_bool y
+
+config GENERIC_LOCKBREAK
+def_bool y
+   depends on PREEMPT
+
+config RWSEM_GENERIC_SPINLOCK
+   def_bool y
+
+config TRACE_IRQFLAGS_SUPPORT
+   def_bool y
+
+config STACKTRACE_SUPPORT
+def_bool y
+
+config PGTABLE_LEVELS
+   default 2
+
+source "init/Kconfig"
+
+menu "System Type"
+source "arch/nds32/Kconfig.cpu"
+config NR_CPUS
+   int
+   default 1
+
+config MMU
+def_bool y
+
+config NDS32_BUILTIN_DTB
+string "Builtin DTB"
+default ""
+   help
+ User can use it to specify the dts of the SoC
+endmenu
+
+menu "Kernel Features"
+source "kernel/Kconfig.preempt"
+source "mm/Kconfig"
+source "kernel/Kconfig.hz"
+endmenu
+
+menu "Executable file formats"
+source "fs/Kconfig.binfmt"
+endmenu
+
+source "net/Kconfig"
+source "drivers/Kconfig"
+source "fs/Kconfig"
+source "arch/nds32/Kconfig.debug"
+source "security/Kconfig"
+source "crypto/Kconfig"
+source "lib/Kconfig"
diff --git a/arch/nds32/Kconfig.cpu b/arch/nds32/Kconfig.cpu
new file mode 100644
index 000..40eaa97
--- /dev/null
+++ b/arch/nds32/Kconfig.cpu
@@ -0,0 +1,100 @@
+comment "Processor Features"
+config HWZOL
+   bool "hardware zero overhead loop support"
+   default y
+   help
+ A set of Zero-Overhead Loop mechanism is provided to reduce the
+ instruction fetch and execution overhead of loop-control instructions.
+ It will save 3 registers($LB, $LC, $LE) for context saving if say Y.
+ You don't need to save these registers if you can make sure your user
+ program doesn't use these registers.
+
+ If unsure, say N.
+
+config CPU_CACHE_NONALIASING
+   bool "Non-aliasing cache"
+   help
+ If this CPU is using VIPT data cache and its cache way size is larger
+ than page size, say N. If it is using PIPT data cache, say Y.
+
+ If unsure, say Y.
+
+choice
+   prompt "Paging -- page size "
+   default ANDES_PAGE_SIZE_4KB
+config  ANDES_PAGE_SIZE_4KB
+   

[PATCH 27/31] dt-bindings: interrupt-controller: Andestech Internal Vector Interrupt Controller

2017-11-07 Thread Greentime Hu
From: Greentime Hu 

Signed-off-by: Rick Chen 
Signed-off-by: Greentime Hu 
---
 .../interrupt-controller/andestech,ativic32.txt|   27 
 1 file changed, 27 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/interrupt-controller/andestech,ativic32.txt

diff --git 
a/Documentation/devicetree/bindings/interrupt-controller/andestech,ativic32.txt 
b/Documentation/devicetree/bindings/interrupt-controller/andestech,ativic32.txt
new file mode 100644
index 000..6bac908
--- /dev/null
+++ 
b/Documentation/devicetree/bindings/interrupt-controller/andestech,ativic32.txt
@@ -0,0 +1,27 @@
+* Andestech Internal Vector Interrupt Controller
+
+The Internal Vector Interrupt Controller (IVIC) is a basic interrupt controller
+suitable for a simpler SoC platform not requiring a more sophisticated and
+bigger External Vector Interrupt Controller.
+
+
+Main node required properties:
+
+- compatible : should at least contain  "andestech,ativic32".
+- interrupt-parent: Empty for the interrupt controller itself
+- interrupt-controller : Identifies the node as an interrupt controller
+- #interrupt-cells: The number of cells to define the interrupts. Should be 2.
+   The first cell is the IRQ number
+   The second cell is used to specify mode:
+   1 = low-to-high edge triggered
+   2 = high-to-low edge triggered
+   4 = active high level-sensitive
+   8 = active low level-sensitive
+   Default for internal sources should be set to 4 (active high).
+
+Examples:
+   intc: interrupt-controller {
+   compatible = "andestech,ativic32";
+   #interrupt-cells = <2>;
+   interrupt-controller;
+   };
-- 
1.7.9.5



[PATCH 29/31] MAINTAINERS: Add nds32

2017-11-07 Thread Greentime Hu
From: Greentime Hu 

Signed-off-by: Greentime Hu 
---
 MAINTAINERS |9 +
 1 file changed, 9 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 2f4e462..bce1181 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -857,6 +857,15 @@ X: drivers/iio/*/adjd*
 F: drivers/staging/iio/*/ad*
 F: drivers/staging/iio/trigger/iio-trig-bfin-timer.c
 
+ANDES ARCHITECTURE
+M: Greentime Hu 
+M: Vincent Chen 
+T: git https://github.com/andestech/linux.git
+S: Supported
+F: arch/nds32
+K: nds32
+N: nds32
+
 ANDROID CONFIG FRAGMENTS
 M: Rob Herring 
 S: Supported
-- 
1.7.9.5



[PATCH 31/31] net: faraday add nds32 support.

2017-11-07 Thread Greentime Hu
From: Greentime Hu 

Signed-off-by: Greentime Hu 
---
 drivers/net/ethernet/faraday/Kconfig |6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/faraday/Kconfig 
b/drivers/net/ethernet/faraday/Kconfig
index 040c7f1..0ae6e9a 100644
--- a/drivers/net/ethernet/faraday/Kconfig
+++ b/drivers/net/ethernet/faraday/Kconfig
@@ -5,7 +5,7 @@
 config NET_VENDOR_FARADAY
bool "Faraday devices"
default y
-   depends on ARM
+   depends on ARM || NDS32
---help---
  If you have a network (Ethernet) card belonging to this class, say Y.
 
@@ -18,7 +18,7 @@ if NET_VENDOR_FARADAY
 
 config FTMAC100
tristate "Faraday FTMAC100 10/100 Ethernet support"
-   depends on ARM
+   depends on ARM || NDS32
select MII
---help---
  This driver supports the FTMAC100 10/100 Ethernet controller
@@ -27,7 +27,7 @@ config FTMAC100
 
 config FTGMAC100
tristate "Faraday FTGMAC100 Gigabit Ethernet support"
-   depends on ARM
+   depends on ARM || NDS32
select PHYLIB
---help---
  This driver supports the FTGMAC100 Gigabit Ethernet controller
-- 
1.7.9.5



[PATCH 30/31] dt-bindings: nds32 CPU Bindings

2017-11-07 Thread Greentime Hu
From: Greentime Hu 

Signed-off-by: Vincent Chen 
Signed-off-by: Rick Chen 
Signed-off-by: Zong Li 
Signed-off-by: Greentime Hu 
---
 Documentation/devicetree/bindings/nds32/cpus.txt |   33 ++
 1 file changed, 33 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/nds32/cpus.txt

diff --git a/Documentation/devicetree/bindings/nds32/cpus.txt 
b/Documentation/devicetree/bindings/nds32/cpus.txt
new file mode 100644
index 000..97394cb
--- /dev/null
+++ b/Documentation/devicetree/bindings/nds32/cpus.txt
@@ -0,0 +1,33 @@
+* Andestech Processor Binding
+
+This binding specifies what properties must be available in the device tree
+representation of a Andestech Processor Core, which is the root node in the
+tree.
+
+Required properties:
+
+   - compatible:
+   Usage: required
+   Value type: 
+   Definition: should be one of:
+   "andestech,n13"
+   "andestech,n15"
+   "andestech,d15"
+   "andestech,n10"
+   "andestech,d10"
+
+- device_type
+   Usage: required
+   Value type: 
+   Definition: must be "cpu"
+
+* Examples
+
+/ {
+   cpus {
+   cpu@0 {
+   device_type = "cpu";
+   compatible = "andestech,n13", "andestech,n15";
+   };
+   };
+};
-- 
1.7.9.5



[PATCH 08/31] nds32: Cache and TLB routines

2017-11-07 Thread Greentime Hu
From: Greentime Hu 

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/include/asm/cache.h |   25 ++
 arch/nds32/include/asm/cache_info.h|   26 ++
 arch/nds32/include/asm/cacheflush.h|   57 +++
 arch/nds32/include/asm/mmu_context.h   |   81 +
 arch/nds32/include/asm/proc-fns.h  |   94 +
 arch/nds32/include/asm/tlb.h   |   41 +++
 arch/nds32/include/asm/tlbflush.h  |   60 
 arch/nds32/include/uapi/asm/cachectl.h |   19 +
 arch/nds32/kernel/cacheinfo.c  |   62 
 arch/nds32/mm/cacheflush.c |  331 +
 arch/nds32/mm/proc-n13.c   |  608 
 arch/nds32/mm/tlb.c|   63 
 12 files changed, 1467 insertions(+)
 create mode 100644 arch/nds32/include/asm/cache.h
 create mode 100644 arch/nds32/include/asm/cache_info.h
 create mode 100644 arch/nds32/include/asm/cacheflush.h
 create mode 100644 arch/nds32/include/asm/mmu_context.h
 create mode 100644 arch/nds32/include/asm/proc-fns.h
 create mode 100644 arch/nds32/include/asm/tlb.h
 create mode 100644 arch/nds32/include/asm/tlbflush.h
 create mode 100644 arch/nds32/include/uapi/asm/cachectl.h
 create mode 100644 arch/nds32/kernel/cacheinfo.c
 create mode 100644 arch/nds32/mm/cacheflush.c
 create mode 100644 arch/nds32/mm/proc-n13.c
 create mode 100644 arch/nds32/mm/tlb.c

diff --git a/arch/nds32/include/asm/cache.h b/arch/nds32/include/asm/cache.h
new file mode 100644
index 000..36ec549
--- /dev/null
+++ b/arch/nds32/include/asm/cache.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#ifndef __NDS32_CACHE_H__
+#define __NDS32_CACHE_H__
+
+#define L1_CACHE_BYTES 32
+#define L1_CACHE_SHIFT 5
+
+#define ARCH_DMA_MINALIGN   L1_CACHE_BYTES
+
+#endif /* __NDS32_CACHE_H__ */
diff --git a/arch/nds32/include/asm/cache_info.h 
b/arch/nds32/include/asm/cache_info.h
new file mode 100644
index 000..a59d73d
--- /dev/null
+++ b/arch/nds32/include/asm/cache_info.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+struct cache_info {
+   unsigned char ways;
+   unsigned char line_size;
+   unsigned short sets;
+   unsigned short size;
+#if !defined(CONFIG_CPU_CACHE_NONALIASING)
+   unsigned short aliasing_num;
+   unsigned int aliasing_mask;
+#endif
+};
diff --git a/arch/nds32/include/asm/cacheflush.h 
b/arch/nds32/include/asm/cacheflush.h
new file mode 100644
index 000..0c7c9db
--- /dev/null
+++ b/arch/nds32/include/asm/cacheflush.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#ifndef __NDS32_CACHEFLUSH_H__
+#define __NDS32_CACHEFLUSH_H__
+
+#include 
+
+#define PG_dcache_dirty PG_arch_1
+
+#ifndef CONFIG_CPU_CACHE_NONALIASING
+void flush_cache_mm(struct mm_struct *mm);
+void flush_cache_dup_mm(struct mm_struct *mm);
+void flush_cache_range(struct vm_area_struct *vma,
+  unsigned long start, unsigned long end);
+void flush_cache_page(struct vm_area_struct *vma,
+ unsigned long addr, unsigned long pfn);

[PATCH 04/31] nds32: Exception handling

2017-11-07 Thread Greentime Hu
From: Greentime Hu 

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/include/asm/ptrace.h |   79 ++
 arch/nds32/kernel/ex-entry.S|  169 
 arch/nds32/kernel/ex-exit.S |  207 ++
 arch/nds32/kernel/stacktrace.c  |   60 +
 arch/nds32/kernel/traps.c   |  442 ++
 arch/nds32/mm/alignment.c   |  564 +++
 6 files changed, 1521 insertions(+)
 create mode 100644 arch/nds32/include/asm/ptrace.h
 create mode 100644 arch/nds32/kernel/ex-entry.S
 create mode 100644 arch/nds32/kernel/ex-exit.S
 create mode 100644 arch/nds32/kernel/stacktrace.c
 create mode 100644 arch/nds32/kernel/traps.c
 create mode 100644 arch/nds32/mm/alignment.c

diff --git a/arch/nds32/include/asm/ptrace.h b/arch/nds32/include/asm/ptrace.h
new file mode 100644
index 000..2c9c03d
--- /dev/null
+++ b/arch/nds32/include/asm/ptrace.h
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#ifndef __ASM_NDS32_PTRACE_H
+#define __ASM_NDS32_PTRACE_H
+
+#define PTRACE_GETREGS 12
+#define PTRACE_SETREGS 13
+#define PTRACE_GETFPREGS   14
+#define PTRACE_SETFPREGS   15
+
+#include 
+
+#ifndef __ASSEMBLY__
+
+struct pt_regs {
+   union {
+   struct user_pt_regs user_regs;
+   struct {
+   long uregs[26];
+   long fp;
+   long gp;
+   long lp;
+   long sp;
+   long ipc;
+#if defined(CONFIG_HWZOL)
+   long lb;
+   long le;
+   long lc;
+#else
+   long dummy[3];
+#endif
+   long syscallno;
+   };
+   };
+   long orig_r0;
+   long ir0;
+   long ipsw;
+   long pipsw;
+   long pipc;
+   long pp0;
+   long pp1;
+   long fucop_ctl;
+   long osp;
+};
+
+#include 
+extern void show_regs(struct pt_regs *);
+/* Avoid circular header include via sched.h */
+struct task_struct;
+extern void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
+int error_code, int si_code);
+
+#define arch_has_single_step() (1)
+#define user_mode(regs)(((regs)->ipsw & PSW_mskPOM) == 
0)
+#define interrupts_enabled(regs)   (!!((regs)->ipsw & PSW_mskGIE))
+#define valid_user_regs(regs)  (user_mode(regs) && 
interrupts_enabled(regs))
+#define regs_return_value(regs)((regs)->uregs[0])
+#define instruction_pointer(regs)  ((regs)->ipc)
+#define user_stack_pointer(regs)((regs)->sp)
+#define profile_pc(regs)   instruction_pointer(regs)
+
+#define ARCH_HAS_USER_SINGLE_STEP_INFO
+
+#endif /* __ASSEMBLY__ */
+#endif
diff --git a/arch/nds32/kernel/ex-entry.S b/arch/nds32/kernel/ex-entry.S
new file mode 100644
index 000..3e977cf
--- /dev/null
+++ b/arch/nds32/kernel/ex-entry.S
@@ -0,0 +1,169 @@
+/*
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+   .macro push_zol
+#ifdef CONFIG_HWZOL
+   mfusr   $r14, $LB
+   mfusr   $r15, $LE
+   mfusr   $r16, $LC
+#endif
+   .endm
+
+   .macro  save_user_regs
+
+   smw.adm $sp, [$sp], $sp, #0x1
+addi$sp, $sp, -OSP_OFFSET /* move $SP to the bottom of pt_regs*/
+
+   /*push $r0 ~ $r25*/
+   smw.bim $r0, [$sp], $r25
+   /*push $fp, $gp, $lp*/
+   smw.bim $sp, [$sp], $sp, #0xe
+
+   mfsr$r12, $SP_USR
+   mfsr$r13, $IPC
+#ifdef CONFIG_HWZOL
+   push_zol
+#endif
+   

Re: [PATCH] af_netlink: give correct bounds to dump skb for NLMSG_DONE

2017-11-07 Thread Johannes Berg
On Tue, 2017-11-07 at 20:29 +0900, Jason A. Donenfeld wrote:
> 
> This patch thus reserves and restores the required length for
> NLMSG_DONE during the call to the dump function.
> 

That basically removes that space though, even when the dump isn't
complete... wouldn't it be better to do something like this?

diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index f34750691c5c..fccf83598dab 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -2183,9 +2183,15 @@ static int netlink_dump(struct sock *sk)
skb_reserve(skb, skb_tailroom(skb) - alloc_size);
netlink_skb_set_owner_r(skb, sk);
 
-   len = cb->dump(skb, cb);
+   /* if the dump is already done, just complete */
+   if (nlk->dump_done)
+   len = 0;
+   else
+   len = cb->dump(skb, cb);
+
+   nlk->dump_done = len == 0;
 
-   if (len > 0) {
+   if (len > 0 || skb_tailroom(skb) < nlmsg_total_size(sizeof(len))) {
mutex_unlock(nlk->cb_mutex);
 
if (sk_filter(sk, skb))
@@ -2196,7 +2202,7 @@ static int netlink_dump(struct sock *sk)
}
 
nlh = nlmsg_put_answer(skb, cb, NLMSG_DONE, sizeof(len), NLM_F_MULTI);
-   if (!nlh)
+   if (WARN_ON(!nlh))
goto errout_skb;
 
nl_dump_check_consistent(cb, nlh);
@@ -2273,6 +2279,7 @@ int __netlink_dump_start(struct sock *ssk, struct sk_buff 
*skb,
}
 
nlk->cb_running = true;
+   nlk->dump_done = false;
 
mutex_unlock(nlk->cb_mutex);
 
diff --git a/net/netlink/af_netlink.h b/net/netlink/af_netlink.h
index 3490f2430532..91a3652d384f 100644
--- a/net/netlink/af_netlink.h
+++ b/net/netlink/af_netlink.h
@@ -33,6 +33,7 @@ struct netlink_sock {
wait_queue_head_t   wait;
boolbound;
boolcb_running;
+   booldump_done;
struct netlink_callback cb;
struct mutex*cb_mutex;
struct mutexcb_def_mutex;


https://p.sipsolutions.net/90574c3c0116d68a.txt

(untested)

johannes


Re: [PATCH] af_netlink: give correct bounds to dump skb for NLMSG_DONE

2017-11-07 Thread Jason A. Donenfeld
By the way, in case you're curious, here's the {up,down,cross}stream
WireGuard commit that works around it via its compat layer (a rat's
nest of hideous backports for all the weird kernels people want
WireGuard to run on, which I cannot wait to remove):

https://git.zx2c4.com/WireGuard/commit/?id=f689ea7acc23dc8e0968699d964ee382b04fbbe4

Particularly relavent here is the last chunk of that, which is part of
the automated test suite, which reproduces the issue by finding the
tightest possible packing.


[PATCH v2 net-next] net: netlink: Update attr validation to require exact length for some types

2017-11-07 Thread David Ahern
Attributes using NLA_U* and NLA_S* (where * is 8, 16,32 and 64) are
expected to be an exact length. Split these data types from
nla_attr_minlen into nla_attr_len and update validate_nla to require
the attribute to have exact length for them.

Signed-off-by: David Ahern 
---
v2
- fix check in nla_policy_len - reported by kernel test robot

 lib/nlattr.c | 19 ---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/lib/nlattr.c b/lib/nlattr.c
index 3d8295c85505..8bf78b4b78f0 100644
--- a/lib/nlattr.c
+++ b/lib/nlattr.c
@@ -15,19 +15,23 @@
 #include 
 #include 
 
-static const u8 nla_attr_minlen[NLA_TYPE_MAX+1] = {
+/* for these data types attribute length must be exactly given size */
+static const u8 nla_attr_len[NLA_TYPE_MAX+1] = {
[NLA_U8]= sizeof(u8),
[NLA_U16]   = sizeof(u16),
[NLA_U32]   = sizeof(u32),
[NLA_U64]   = sizeof(u64),
-   [NLA_MSECS] = sizeof(u64),
-   [NLA_NESTED]= NLA_HDRLEN,
[NLA_S8]= sizeof(s8),
[NLA_S16]   = sizeof(s16),
[NLA_S32]   = sizeof(s32),
[NLA_S64]   = sizeof(s64),
 };
 
+static const u8 nla_attr_minlen[NLA_TYPE_MAX+1] = {
+   [NLA_MSECS] = sizeof(u64),
+   [NLA_NESTED]= NLA_HDRLEN,
+};
+
 static int validate_nla_bitfield32(const struct nlattr *nla,
   u32 *valid_flags_allowed)
 {
@@ -65,6 +69,13 @@ static int validate_nla(const struct nlattr *nla, int 
maxtype,
 
BUG_ON(pt->type > NLA_TYPE_MAX);
 
+   /* for data types NLA_U* and NLA_S* require exact length */
+   if (nla_attr_len[pt->type]) {
+   if (attrlen != nla_attr_len[pt->type])
+   return -ERANGE;
+   return 0;
+   }
+
switch (pt->type) {
case NLA_FLAG:
if (attrlen > 0)
@@ -191,6 +202,8 @@ nla_policy_len(const struct nla_policy *p, int n)
for (i = 0; i < n; i++, p++) {
if (p->len)
len += nla_total_size(p->len);
+   else if (nla_attr_len[p->type])
+   len += nla_total_size(nla_attr_len[p->type]);
else if (nla_attr_minlen[p->type])
len += nla_total_size(nla_attr_minlen[p->type]);
}
-- 
2.1.4



[PATCH] net: ipv6: sysctl to specify IPv6 ND traffic class

2017-11-07 Thread Maciej Żenczykowski
From: Maciej Żenczykowski 

Add a per-device sysctl to specify the default traffic class to use for
kernel originated IPv6 Neighbour Discovery packets.

Currently this includes:

  - Router Solicitation (ICMPv6 type 133)
ndisc_send_rs() -> ndisc_send_skb() -> ip6_nd_hdr()

  - Neighbour Solicitation (ICMPv6 type 135)
ndisc_send_ns() -> ndisc_send_skb() -> ip6_nd_hdr()

  - Neighbour Advertisement (ICMPv6 type 136)
ndisc_send_na() -> ndisc_send_skb() -> ip6_nd_hdr()

  - Redirect (ICMPv6 type 137)
ndisc_send_redirect() -> ndisc_send_skb() -> ip6_nd_hdr()

and if the kernel ever gets around to generating RA's,
it would presumably also include:

  - Router Advertisement (ICMPv6 type 134)
(radvd daemon could pick up on the kernel setting and use it)

Interface drivers may examine the Traffic Class value and translate
the DiffServ Code Point into a link-layer appropriate traffic
prioritization scheme.  An example of mapping IETF DSCP values to
IEEE 802.11 User Priority values can be found here:

https://tools.ietf.org/html/draft-ietf-tsvwg-ieee-802-11

The expected primary use case is to properly prioritize ND over wifi.

Testing:
  jzem22:~# cat /proc/sys/net/ipv6/conf/eth0/ndisc_tclass
  0
  jzem22:~# echo -1 > /proc/sys/net/ipv6/conf/eth0/ndisc_tclass
  -bash: echo: write error: Invalid argument
  jzem22:~# echo 256 > /proc/sys/net/ipv6/conf/eth0/ndisc_tclass
  -bash: echo: write error: Invalid argument
  jzem22:~# echo 0 > /proc/sys/net/ipv6/conf/eth0/ndisc_tclass
  jzem22:~# echo 255 > /proc/sys/net/ipv6/conf/eth0/ndisc_tclass
  jzem22:~# cat /proc/sys/net/ipv6/conf/eth0/ndisc_tclass
  255
  jzem22:~# echo 34 > /proc/sys/net/ipv6/conf/eth0/ndisc_tclass
  jzem22:~# cat /proc/sys/net/ipv6/conf/eth0/ndisc_tclass
  34

  jzem22:~# echo $[0xDC] > /proc/sys/net/ipv6/conf/eth0/ndisc_tclass
  jzem22:~# tcpdump -v -i eth0 icmp6 and src host jzem22.pgc and dst host 
fe80::1
  tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 262144 
bytes
  IP6 (class 0xdc, hlim 255, next-header ICMPv6 (58) payload length: 24)
  jzem22.pgc > fe80::1: [icmp6 sum ok] ICMP6, neighbor advertisement,
  length 24, tgt is jzem22.pgc, Flags [solicited]

(based on original change written by Erik Kline, with minor changes)

v2: fix 'suspicious rcu_dereference_check() usage'
by explicitly grabbing the rcu_read_lock.

Cc: Lorenzo Colitti 
Signed-off-by: Erik Kline 
Signed-off-by: Maciej Żenczykowski 
---
 Documentation/networking/ip-sysctl.txt |  9 +
 include/linux/ipv6.h   |  1 +
 include/uapi/linux/ipv6.h  |  1 +
 net/ipv6/addrconf.c| 11 +++
 net/ipv6/ndisc.c   |  9 -
 5 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/Documentation/networking/ip-sysctl.txt 
b/Documentation/networking/ip-sysctl.txt
index 54410a1d4065..d8676dda7fa6 100644
--- a/Documentation/networking/ip-sysctl.txt
+++ b/Documentation/networking/ip-sysctl.txt
@@ -1732,6 +1732,15 @@ ndisc_notify - BOOLEAN
1 - Generate unsolicited neighbour advertisements when device is brought
up or hardware address changes.
 
+ndisc_tclass - INTEGER
+   The IPv6 Traffic Class to use by default when sending IPv6 Neighbor
+   Discovery (Router Solicitation, Router Advertisement, Neighbor
+   Solicitation, Neighbor Advertisement, Redirect) messages.
+   These 8 bits can be interpreted as 6 high order bits holding the DSCP
+   value and 2 low order bits representing ECN (which you probably want
+   to leave cleared).
+   0 - (default)
+
 mldv1_unsolicited_report_interval - INTEGER
The interval in milliseconds in which the next unsolicited
MLDv1 report retransmit will take place.
diff --git a/include/linux/ipv6.h b/include/linux/ipv6.h
index ea04ca024f0d..cb18c6290ca8 100644
--- a/include/linux/ipv6.h
+++ b/include/linux/ipv6.h
@@ -73,6 +73,7 @@ struct ipv6_devconf {
__u32   enhanced_dad;
__u32   addr_gen_mode;
__s32   disable_policy;
+   __s32   ndisc_tclass;
 
struct ctl_table_header *sysctl_header;
 };
diff --git a/include/uapi/linux/ipv6.h b/include/uapi/linux/ipv6.h
index b22a9c4e1b12..9c0f4a92bcff 100644
--- a/include/uapi/linux/ipv6.h
+++ b/include/uapi/linux/ipv6.h
@@ -186,6 +186,7 @@ enum {
DEVCONF_ADDR_GEN_MODE,
DEVCONF_DISABLE_POLICY,
DEVCONF_ACCEPT_RA_RT_INFO_MIN_PLEN,
+   DEVCONF_NDISC_TCLASS,
DEVCONF_MAX
 };
 
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 6233e06fa35c..a6dffd65eb9d 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -5059,6 +5059,7 @@ static inline void ipv6_store_devconf(struct ipv6_devconf 
*cnf,
array[DEVCONF_ENHANCED_DAD] = cnf->enhanced_dad;
array[DEVCONF_ADDR_GEN_MODE] = cnf->addr_gen_mode;
array[DEVCONF_DISABLE_POLICY] = 

Re: [PATCH net-next V2 3/3] tun: add eBPF based queue selection method

2017-11-07 Thread Michael S. Tsirkin
On Wed, Nov 08, 2017 at 02:28:53PM +0900, Jason Wang wrote:
> 
> 
> On 2017年11月04日 08:56, Willem de Bruijn wrote:
> > On Fri, Nov 3, 2017 at 5:56 PM, Willem de Bruijn
> >  wrote:
> > > On Tue, Oct 31, 2017 at 7:32 PM, Jason Wang  wrote:
> > > > This patch introduces an eBPF based queue selection method based on
> > > > the flow steering policy ops. Userspace could load an eBPF program
> > > > through TUNSETSTEERINGEBPF. This gives much more flexibility compare
> > > > to simple but hard coded policy in kernel.
> > > > 
> > > > Signed-off-by: Jason Wang 
> > > > ---
> > > > +static int tun_set_steering_ebpf(struct tun_struct *tun, void __user 
> > > > *data)
> > > > +{
> > > > +   struct bpf_prog *prog;
> > > > +   u32 fd;
> > > > +
> > > > +   if (copy_from_user(, data, sizeof(fd)))
> > > > +   return -EFAULT;
> > > > +
> > > > +   prog = bpf_prog_get_type(fd, BPF_PROG_TYPE_SOCKET_FILTER);
> > > If the idea is to allow guests to pass BPF programs down to the host,
> > > you may want to define a new program type that is more restrictive than
> > > socket filter.
> > > 
> > > The external functions allowed for socket filters (sk_filter_func_proto)
> > > are relatively few (compared to, say, clsact), but may still leak host
> > > information to a guest. More importantly, guest security considerations
> > > limits how we can extend socket filters later.
> > Unless the idea is for the hypervisor to prepared the BPF based on a
> > limited set of well defined modes that the guest can configure. Then
> > socket filters are fine, as the BPF is prepared by a regular host process.
> 
> Yes, I think the idea is to let qemu to build a BPF program now.
> 
> Passing eBPF program from guest to host is interesting, but an obvious issue
> is how to deal with the accessing of map.
> 
> Thanks

Fundamentally, I suspect the way to solve it is to allow
the program to specify "should be offloaded to host".

And then it would access the host map rather than the guest map.

Then add some control path API for guest to poke at the host map.

It's not that there's anything special about the host map -
it's just separate from the guest - so if we wanted to
do something that can work on bare-metal we could -
just do something like a namespace and put all host
maps there. But I'm not sure it's worth the complexity.

Cc Aaron who wanted to look at this.

-- 
MST


Re: Page allocator bottleneck

2017-11-07 Thread Tariq Toukan



On 03/11/2017 10:40 PM, Mel Gorman wrote:

On Thu, Nov 02, 2017 at 07:21:09PM +0200, Tariq Toukan wrote:



On 18/09/2017 12:16 PM, Tariq Toukan wrote:



On 15/09/2017 1:23 PM, Mel Gorman wrote:

On Thu, Sep 14, 2017 at 07:49:31PM +0300, Tariq Toukan wrote:

Insights: Major degradation between #1 and #2, not getting any
close to linerate! Degradation is fixed between #2 and #3. This is
because page allocator cannot stand the higher allocation rate. In
#2, we also see that the addition of rings (cores) reduces BW (!!),
as result of increasing congestion over shared resources.



Unfortunately, no surprises there.


Congestion in this case is very clear. When monitored in perf
top: 85.58% [kernel] [k] queued_spin_lock_slowpath



While it's not proven, the most likely candidate is the zone lock
and that should be confirmed using a call-graph profile. If so, then
the suggestion to tune to the size of the per-cpu allocator would
mitigate the problem.


Indeed, I tuned the per-cpu allocator and bottleneck is released.



Hi all,

After leaving this task for a while doing other tasks, I got back to it now
and see that the good behavior I observed earlier was not stable.

Recall: I work with a modified driver that allocates a page (4K) per packet
(MTU=1500), in order to simulate the stress on page-allocator in 200Gbps
NICs.



There is almost new in the data that hasn't been discussed before. The
suggestion to free on a remote per-cpu list would be expensive as it would
require per-cpu lists to have a lock for safe remote access.
That's right, but each such lock will be significantly less congested 
than the buddy allocator lock. In the flow in subject two cores need to 
synchronize (one allocates, one frees).
We also need to evaluate the cost of acquiring and releasing the lock in 
the case of no congestion at all.



 However,
I'd be curious if you could test the mm-pagealloc-irqpvec-v1r4 branch
ttps://git.kernel.org/pub/scm/linux/kernel/git/mel/linux.git .  It's an
unfinished prototype I worked on a few weeks ago. I was going to revisit
in about a months time when 4.15-rc1 was out. I'd be interested in seeing
if it has a postive gain in normal page allocations without destroying
the performance of interrupt and softirq allocation contexts. The
interrupt/softirq context testing is crucial as that is something that
hurt us before when trying to improve page allocator performance.

Yes, I will test that once I get back in office (after netdev conference 
and vacation).

Can you please elaborate in a few words about the idea behind the prototype?
Does it address page-allocator scalability issues, or only the rate of 
single core page allocations?


Re: [PATCH net-next v3] net: mvpp2: add ethtool GOP statistics

2017-11-07 Thread David Miller
From: Antoine Tenart 
Date: Wed, 8 Nov 2017 06:17:10 +0100

> Hi David,
> 
> On Wed, Nov 08, 2017 at 01:54:56PM +0900, David Miller wrote:
>> From: Miquel Raynal 
>> Date: Mon,  6 Nov 2017 22:56:53 +0100
>> 
>> > Add ethtool statistics support by reading the GOP statistics from the
>> > hardware counters. Also implement a workqueue to gather the statistics
>> > every second or some 32-bit counters could overflow.
>> > 
>> > Suggested-by: Stefan Chulski 
>> > Signed-off-by: Miquel Raynal 
>> 
>> Applied, thanks.
> 
> Miquèl actually sent a v4 of this patch, fixing an issue found in
> previous versions (including this one) of this patch.

Oops, Miquel please send a relative fix.

Thank you.


Re: [PATCH] qrtr: Move to postcore_initcall

2017-11-07 Thread David Miller
From: Bjorn Andersson 
Date: Mon,  6 Nov 2017 20:50:35 -0800

> Registering qrtr with module_init makes the ability of typical platform
> code to create AF_QIPCRTR socket during probe a matter of link order
> luck. Moving qrtr to postcore_initcall() avoids this.
> 
> Signed-off-by: Bjorn Andersson 

Applied.


Re: [PATCH 00/23] Netfilter/IPVS updates for net-next

2017-11-07 Thread David Miller
From: Pablo Neira Ayuso 
Date: Tue,  7 Nov 2017 01:51:50 +0100

> The following patchset contains Netfilter/IPVS updates for your net-next
> tree, they are:
 ...
> You can pull these changes from:
> 
>   git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git

Pulled, thanks a lot!


[PATCH net-next 2/2] net/ncsi: Don't return error on normal response

2017-11-07 Thread Samuel Mendoza-Jonas
Several response handlers return EBUSY if the data corresponding to the
command/response pair is already set. There is no reason to return an
error here; the channel is advertising something as enabled because we
told it to enable it, and it's possible that the feature has been
enabled previously.

Signed-off-by: Samuel Mendoza-Jonas 
---
 net/ncsi/ncsi-rsp.c | 31 ++-
 1 file changed, 14 insertions(+), 17 deletions(-)

diff --git a/net/ncsi/ncsi-rsp.c b/net/ncsi/ncsi-rsp.c
index 58186c4102f0..efd933ff5570 100644
--- a/net/ncsi/ncsi-rsp.c
+++ b/net/ncsi/ncsi-rsp.c
@@ -146,7 +146,7 @@ static int ncsi_rsp_handler_ec(struct ncsi_request *nr)
 
ncm = >modes[NCSI_MODE_ENABLE];
if (ncm->enable)
-   return -EBUSY;
+   return 0;
 
ncm->enable = 1;
return 0;
@@ -173,7 +173,7 @@ static int ncsi_rsp_handler_dc(struct ncsi_request *nr)
 
ncm = >modes[NCSI_MODE_ENABLE];
if (!ncm->enable)
-   return -EBUSY;
+   return 0;
 
ncm->enable = 0;
return 0;
@@ -217,7 +217,7 @@ static int ncsi_rsp_handler_ecnt(struct ncsi_request *nr)
 
ncm = >modes[NCSI_MODE_TX_ENABLE];
if (ncm->enable)
-   return -EBUSY;
+   return 0;
 
ncm->enable = 1;
return 0;
@@ -239,7 +239,7 @@ static int ncsi_rsp_handler_dcnt(struct ncsi_request *nr)
 
ncm = >modes[NCSI_MODE_TX_ENABLE];
if (!ncm->enable)
-   return -EBUSY;
+   return 0;
 
ncm->enable = 1;
return 0;
@@ -263,7 +263,7 @@ static int ncsi_rsp_handler_ae(struct ncsi_request *nr)
/* Check if the AEN has been enabled */
ncm = >modes[NCSI_MODE_AEN];
if (ncm->enable)
-   return -EBUSY;
+   return 0;
 
/* Update to AEN configuration */
cmd = (struct ncsi_cmd_ae_pkt *)skb_network_header(nr->cmd);
@@ -382,7 +382,7 @@ static int ncsi_rsp_handler_ev(struct ncsi_request *nr)
/* Check if VLAN mode has been enabled */
ncm = >modes[NCSI_MODE_VLAN];
if (ncm->enable)
-   return -EBUSY;
+   return 0;
 
/* Update to VLAN mode */
cmd = (struct ncsi_cmd_ev_pkt *)skb_network_header(nr->cmd);
@@ -409,7 +409,7 @@ static int ncsi_rsp_handler_dv(struct ncsi_request *nr)
/* Check if VLAN mode has been enabled */
ncm = >modes[NCSI_MODE_VLAN];
if (!ncm->enable)
-   return -EBUSY;
+   return 0;
 
/* Update to VLAN mode */
ncm->enable = 0;
@@ -455,13 +455,10 @@ static int ncsi_rsp_handler_sma(struct ncsi_request *nr)
 
bitmap = >bitmap;
if (cmd->at_e & 0x1) {
-   if (test_and_set_bit(cmd->index, bitmap))
-   return -EBUSY;
+   set_bit(cmd->index, bitmap);
memcpy(ncf->data + 6 * cmd->index, cmd->mac, 6);
} else {
-   if (!test_and_clear_bit(cmd->index, bitmap))
-   return -EBUSY;
-
+   clear_bit(cmd->index, bitmap);
memset(ncf->data + 6 * cmd->index, 0, 6);
}
 
@@ -485,7 +482,7 @@ static int ncsi_rsp_handler_ebf(struct ncsi_request *nr)
/* Check if broadcast filter has been enabled */
ncm = >modes[NCSI_MODE_BC];
if (ncm->enable)
-   return -EBUSY;
+   return 0;
 
/* Update to broadcast filter mode */
cmd = (struct ncsi_cmd_ebf_pkt *)skb_network_header(nr->cmd);
@@ -511,7 +508,7 @@ static int ncsi_rsp_handler_dbf(struct ncsi_request *nr)
/* Check if broadcast filter isn't enabled */
ncm = >modes[NCSI_MODE_BC];
if (!ncm->enable)
-   return -EBUSY;
+   return 0;
 
/* Update to broadcast filter mode */
ncm->enable = 0;
@@ -538,7 +535,7 @@ static int ncsi_rsp_handler_egmf(struct ncsi_request *nr)
/* Check if multicast filter has been enabled */
ncm = >modes[NCSI_MODE_MC];
if (ncm->enable)
-   return -EBUSY;
+   return 0;
 
/* Update to multicast filter mode */
cmd = (struct ncsi_cmd_egmf_pkt *)skb_network_header(nr->cmd);
@@ -564,7 +561,7 @@ static int ncsi_rsp_handler_dgmf(struct ncsi_request *nr)
/* Check if multicast filter has been enabled */
ncm = >modes[NCSI_MODE_MC];
if (!ncm->enable)
-   return -EBUSY;
+   return 0;
 
/* Update to multicast filter mode */
ncm->enable = 0;
@@ -591,7 +588,7 @@ static int ncsi_rsp_handler_snfc(struct ncsi_request *nr)
/* Check if flow control has been enabled */
ncm = >modes[NCSI_MODE_FC];
if (ncm->enable)
-   return -EBUSY;
+   return 0;
 
/* Update to flow control mode */
cmd = (struct ncsi_cmd_snfc_pkt *)skb_network_header(nr->cmd);
-- 
2.14.3



Re: [net-next v3 3/4] openvswitch: Add meter infrastructure

2017-11-07 Thread kbuild test robot
Hi Andy,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on net-next/master]

url:
https://github.com/0day-ci/linux/commits/Andy-Zhou/Openvswitch-meter-action/20171108-053451
config: i386-randconfig-i0-201745 (attached as .config)
compiler: gcc-4.8 (Debian 4.8.4-1) 4.8.4
reproduce:
# save the attached .config to linux build tree
make ARCH=i386 

All errors (new ones prefixed by >>):

   net/openvswitch/meter.o: In function `ovs_meter_cmd_set':
>> meter.c:(.text+0x8b4): undefined reference to `__udivdi3'
   net/openvswitch/meter.o: In function `ovs_meter_execute':
   meter.c:(.text+0xeb0): undefined reference to `__udivdi3'

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: application/gzip


[PATCH net-next 1/2] net/ncsi: Improve general state logging

2017-11-07 Thread Samuel Mendoza-Jonas
The NCSI driver is mostly silent which becomes a headache when trying to
determine what has occurred on the NCSI connection. This adds additional
logging in a few key areas such as state transitions and calling out
certain errors more visibly.

Signed-off-by: Samuel Mendoza-Jonas 
---
 net/ncsi/ncsi-aen.c| 15 +-
 net/ncsi/ncsi-manage.c | 76 +-
 net/ncsi/ncsi-rsp.c| 10 ++-
 3 files changed, 80 insertions(+), 21 deletions(-)

diff --git a/net/ncsi/ncsi-aen.c b/net/ncsi/ncsi-aen.c
index f135938bf781..67e708e98ccf 100644
--- a/net/ncsi/ncsi-aen.c
+++ b/net/ncsi/ncsi-aen.c
@@ -73,6 +73,9 @@ static int ncsi_aen_handler_lsc(struct ncsi_dev_priv *ndp,
ncm->data[2] = data;
ncm->data[4] = ntohl(lsc->oem_status);
 
+   netdev_info(ndp->ndev.dev, "NCSI: LSC AEN - channel %u state %s\n",
+   nc->id, data & 0x1 ? "up" : "down");
+
chained = !list_empty(>link);
state = nc->state;
spin_unlock_irqrestore(>lock, flags);
@@ -145,6 +148,8 @@ static int ncsi_aen_handler_hncdsc(struct ncsi_dev_priv 
*ndp,
ncm = >modes[NCSI_MODE_LINK];
hncdsc = (struct ncsi_aen_hncdsc_pkt *)h;
ncm->data[3] = ntohl(hncdsc->status);
+   netdev_info(ndp->ndev.dev, "NCSI: HNCDSC AEN - channel %u state %s\n",
+   nc->id, ncm->data[3] & 0x3 ? "up" : "down");
if (!list_empty(>link) ||
nc->state != NCSI_CHANNEL_ACTIVE) {
spin_unlock_irqrestore(>lock, flags);
@@ -212,10 +217,18 @@ int ncsi_aen_handler(struct ncsi_dev_priv *ndp, struct 
sk_buff *skb)
}
 
ret = ncsi_validate_aen_pkt(h, nah->payload);
-   if (ret)
+   if (ret) {
+   netdev_warn(ndp->ndev.dev,
+   "NCSI: 'bad' packet ignored for AEN type 0x%x\n",
+   h->type);
goto out;
+   }
 
ret = nah->handler(ndp, h);
+   if (ret)
+   netdev_err(ndp->ndev.dev,
+  "NCSI: Handler for AEN type 0x%x returned %d\n",
+  h->type, ret);
 out:
consume_skb(skb);
return ret;
diff --git a/net/ncsi/ncsi-manage.c b/net/ncsi/ncsi-manage.c
index 47baf914eec2..a2b904a718c6 100644
--- a/net/ncsi/ncsi-manage.c
+++ b/net/ncsi/ncsi-manage.c
@@ -229,6 +229,8 @@ static void ncsi_channel_monitor(unsigned long data)
case NCSI_CHANNEL_MONITOR_WAIT ... NCSI_CHANNEL_MONITOR_WAIT_MAX:
break;
default:
+   netdev_err(ndp->ndev.dev, "NCSI Channel %d timed out!\n",
+  nc->id);
if (!(ndp->flags & NCSI_DEV_HWA)) {
ncsi_report_link(ndp, true);
ndp->flags |= NCSI_DEV_RESHUFFLE;
@@ -682,7 +684,7 @@ static int clear_one_vid(struct ncsi_dev_priv *ndp, struct 
ncsi_channel *nc,
data = ncsi_get_filter(nc, NCSI_FILTER_VLAN, index);
if (!data) {
netdev_err(ndp->ndev.dev,
-  "ncsi: failed to retrieve filter %d\n", index);
+  "NCSI: failed to retrieve filter %d\n", index);
/* Set the VLAN id to 0 - this will still disable the entry in
 * the filter table, but we won't know what it was.
 */
@@ -692,7 +694,7 @@ static int clear_one_vid(struct ncsi_dev_priv *ndp, struct 
ncsi_channel *nc,
}
 
netdev_printk(KERN_DEBUG, ndp->ndev.dev,
- "ncsi: removed vlan tag %u at index %d\n",
+ "NCSI: removed vlan tag %u at index %d\n",
  vid, index + 1);
ncsi_remove_filter(nc, NCSI_FILTER_VLAN, index);
 
@@ -718,7 +720,7 @@ static int set_one_vid(struct ncsi_dev_priv *ndp, struct 
ncsi_channel *nc,
if (index < 0) {
/* New tag to add */
netdev_printk(KERN_DEBUG, ndp->ndev.dev,
- "ncsi: new vlan id to set: %u\n",
+ "NCSI: new vlan id to set: %u\n",
  vlan->vid);
break;
}
@@ -745,7 +747,7 @@ static int set_one_vid(struct ncsi_dev_priv *ndp, struct 
ncsi_channel *nc,
}
 
netdev_printk(KERN_DEBUG, ndp->ndev.dev,
- "ncsi: set vid %u in packet, index %u\n",
+ "NCSI: set vid %u in packet, index %u\n",
  vlan->vid, index + 1);
nca->type = NCSI_PKT_CMD_SVF;
nca->words[1] = vlan->vid;
@@ -784,8 +786,11 @@ static void ncsi_configure_channel(struct ncsi_dev_priv 
*ndp)
nca.package = np->id;
nca.channel = NCSI_RESERVED_CHANNEL;
ret = ncsi_xmit_cmd();
-   if (ret)
+   if (ret) {
+   netdev_err(ndp->ndev.dev,
+

Re: [PATCH net-next V2 3/3] tun: add eBPF based queue selection method

2017-11-07 Thread Jason Wang



On 2017年11月04日 08:56, Willem de Bruijn wrote:

On Fri, Nov 3, 2017 at 5:56 PM, Willem de Bruijn
 wrote:

On Tue, Oct 31, 2017 at 7:32 PM, Jason Wang  wrote:

This patch introduces an eBPF based queue selection method based on
the flow steering policy ops. Userspace could load an eBPF program
through TUNSETSTEERINGEBPF. This gives much more flexibility compare
to simple but hard coded policy in kernel.

Signed-off-by: Jason Wang 
---
+static int tun_set_steering_ebpf(struct tun_struct *tun, void __user *data)
+{
+   struct bpf_prog *prog;
+   u32 fd;
+
+   if (copy_from_user(, data, sizeof(fd)))
+   return -EFAULT;
+
+   prog = bpf_prog_get_type(fd, BPF_PROG_TYPE_SOCKET_FILTER);

If the idea is to allow guests to pass BPF programs down to the host,
you may want to define a new program type that is more restrictive than
socket filter.

The external functions allowed for socket filters (sk_filter_func_proto)
are relatively few (compared to, say, clsact), but may still leak host
information to a guest. More importantly, guest security considerations
limits how we can extend socket filters later.

Unless the idea is for the hypervisor to prepared the BPF based on a
limited set of well defined modes that the guest can configure. Then
socket filters are fine, as the BPF is prepared by a regular host process.


Yes, I think the idea is to let qemu to build a BPF program now.

Passing eBPF program from guest to host is interesting, but an obvious 
issue is how to deal with the accessing of map.


Thanks


Re: [PATCH net-next v3] net: mvpp2: add ethtool GOP statistics

2017-11-07 Thread Antoine Tenart
Hi David,

On Wed, Nov 08, 2017 at 01:54:56PM +0900, David Miller wrote:
> From: Miquel Raynal 
> Date: Mon,  6 Nov 2017 22:56:53 +0100
> 
> > Add ethtool statistics support by reading the GOP statistics from the
> > hardware counters. Also implement a workqueue to gather the statistics
> > every second or some 32-bit counters could overflow.
> > 
> > Suggested-by: Stefan Chulski 
> > Signed-off-by: Miquel Raynal 
> 
> Applied, thanks.

Miquèl actually sent a v4 of this patch, fixing an issue found in
previous versions (including this one) of this patch.

Thanks,
Antoine

-- 
Antoine Ténart, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com


Re: [PATCH v2 net-next 0/6] mv88e6xxx broadcast flooding in hardware

2017-11-07 Thread David Miller
From: David Miller 
Date: Wed, 08 Nov 2017 13:58:09 +0900 (KST)

> From: Andrew Lunn 
> Date: Tue,  7 Nov 2017 00:02:25 +0100
> 
>> This patchset makes the mv88e6xxx driver perform flooding in hardware,
>> rather than let the software bridge perform the flooding. This is a
>> prerequisite for IGMP snooping on the bridge interface.
>> 
>> In order to make hardware broadcasting work, a few other issues need
>> fixing or improving. SWITCHDEV_ATTR_ID_PORT_PARENT_ID is broken, which
>> is apparent when testing on the ZII devel board with multiple
>> switches.
>> 
>> Some of these patches are taken from a previous RFC patchset of IGMP
>> support.
> 
> Series applied, thanks Andrew.

Hmmm, I think there might be some in-flight conflict with Vivien's recent
DSA refactoring.

net/dsa/slave.c: In function ‘dsa_slave_port_attr_get’:
net/dsa/slave.c:349:35: error: ‘struct dsa_switch_tree’ has no member named 
‘tree’
   attr->u.ppid.id_len = sizeof(dst->tree);
   ^~
net/dsa/slave.c:350:32: error: ‘struct dsa_switch_tree’ has no member named 
‘tree’
   memcpy(>u.ppid.id, >tree, attr->u.ppid.id_len);
^~

Anyways, I had to revert, please fix this up and resubmit.

Thank you!


Re: [PATCH v2 net-next 0/6] mv88e6xxx broadcast flooding in hardware

2017-11-07 Thread David Miller
From: Andrew Lunn 
Date: Tue,  7 Nov 2017 00:02:25 +0100

> This patchset makes the mv88e6xxx driver perform flooding in hardware,
> rather than let the software bridge perform the flooding. This is a
> prerequisite for IGMP snooping on the bridge interface.
> 
> In order to make hardware broadcasting work, a few other issues need
> fixing or improving. SWITCHDEV_ATTR_ID_PORT_PARENT_ID is broken, which
> is apparent when testing on the ZII devel board with multiple
> switches.
> 
> Some of these patches are taken from a previous RFC patchset of IGMP
> support.

Series applied, thanks Andrew.


[PATCH net-next V4 3/3] tools: bpftool: optionally show filenames of pinned objects

2017-11-07 Thread Prashant Bhole
Making it optional to show file names of pinned objects because
it scans complete bpf-fs filesystem which is costly.
Added option -f|--bpffs. Documentation updated.

Signed-off-by: Prashant Bhole 
---
v2:
 - Change command line option from {-l|--pinned} to {-f|--bpffs}
 - Updated documentation

v3:
 - No change

v4:
 - No change

 tools/bpf/bpftool/Documentation/bpftool-map.rst  |  5 -
 tools/bpf/bpftool/Documentation/bpftool-prog.rst |  5 -
 tools/bpf/bpftool/main.c | 14 +++---
 tools/bpf/bpftool/main.h |  3 ++-
 tools/bpf/bpftool/map.c  |  3 ++-
 tools/bpf/bpftool/prog.c |  3 ++-
 6 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/tools/bpf/bpftool/Documentation/bpftool-map.rst 
b/tools/bpf/bpftool/Documentation/bpftool-map.rst
index abb9ee940b15..9f51a268eb06 100644
--- a/tools/bpf/bpftool/Documentation/bpftool-map.rst
+++ b/tools/bpf/bpftool/Documentation/bpftool-map.rst
@@ -12,7 +12,7 @@ SYNOPSIS
 
**bpftool** [*OPTIONS*] **map** *COMMAND*
 
-   *OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] }
+   *OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] | { 
**-f** | **--bpffs** } }
 
*COMMANDS* :=
{ **show** | **dump** | **update** | **lookup** | **getnext** | 
**delete**
@@ -86,6 +86,9 @@ OPTIONS
-p, --pretty
  Generate human-readable JSON output. Implies **-j**.
 
+   -f, --bpffs
+ Show file names of pinned maps.
+
 EXAMPLES
 
 **# bpftool map show**
diff --git a/tools/bpf/bpftool/Documentation/bpftool-prog.rst 
b/tools/bpf/bpftool/Documentation/bpftool-prog.rst
index 0f25d3c39e05..36e8d1c3c40d 100644
--- a/tools/bpf/bpftool/Documentation/bpftool-prog.rst
+++ b/tools/bpf/bpftool/Documentation/bpftool-prog.rst
@@ -12,7 +12,7 @@ SYNOPSIS
 
**bpftool** [*OPTIONS*] **prog** *COMMAND*
 
-   *OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] }
+   *OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] | { 
**-f** | **--bpffs** } }
 
*COMMANDS* :=
{ **show** | **dump xlated** | **dump jited** | **pin** | **help** }
@@ -75,6 +75,9 @@ OPTIONS
-p, --pretty
  Generate human-readable JSON output. Implies **-j**.
 
+   -f, --bpffs
+ Show file names of pinned programs.
+
 EXAMPLES
 
 **# bpftool prog show**
diff --git a/tools/bpf/bpftool/main.c b/tools/bpf/bpftool/main.c
index 6ad53f1797fa..d6e4762170a4 100644
--- a/tools/bpf/bpftool/main.c
+++ b/tools/bpf/bpftool/main.c
@@ -54,6 +54,7 @@ static int (*last_do_help)(int argc, char **argv);
 json_writer_t *json_wtr;
 bool pretty_output;
 bool json_output;
+bool show_pinned;
 struct pinned_obj_table prog_table;
 struct pinned_obj_table map_table;
 
@@ -265,6 +266,7 @@ int main(int argc, char **argv)
{ "help",   no_argument,NULL,   'h' },
{ "pretty", no_argument,NULL,   'p' },
{ "version",no_argument,NULL,   'V' },
+   { "bpffs",  no_argument,NULL,   'f' },
{ 0 }
};
int opt, ret;
@@ -272,12 +274,13 @@ int main(int argc, char **argv)
last_do_help = do_help;
pretty_output = false;
json_output = false;
+   show_pinned = false;
bin_name = argv[0];
 
hash_init(prog_table.table);
hash_init(map_table.table);
 
-   while ((opt = getopt_long(argc, argv, "Vhpj",
+   while ((opt = getopt_long(argc, argv, "Vhpjf",
  options, NULL)) >= 0) {
switch (opt) {
case 'V':
@@ -290,6 +293,9 @@ int main(int argc, char **argv)
case 'j':
json_output = true;
break;
+   case 'f':
+   show_pinned = true;
+   break;
default:
usage();
}
@@ -316,8 +322,10 @@ int main(int argc, char **argv)
if (json_output)
jsonw_destroy(_wtr);
 
-   delete_pinned_obj_table(_table);
-   delete_pinned_obj_table(_table);
+   if (show_pinned) {
+   delete_pinned_obj_table(_table);
+   delete_pinned_obj_table(_table);
+   }
 
return ret;
 }
diff --git a/tools/bpf/bpftool/main.h b/tools/bpf/bpftool/main.h
index 726f6e27a706..32846a0e42fb 100644
--- a/tools/bpf/bpftool/main.h
+++ b/tools/bpf/bpftool/main.h
@@ -59,7 +59,7 @@
 #define HELP_SPEC_PROGRAM  \
"PROG := { id PROG_ID | pinned FILE | tag PROG_TAG }"
 #define HELP_SPEC_OPTIONS  \
-   "OPTIONS := { {-j|--json} [{-p|--pretty}] }"
+   "OPTIONS := { {-j|--json} [{-p|--pretty}] | {-f|--bpffs} }"
 
 enum 

[PATCH net-next V4 1/3] tools: bpftool: open pinned object without type check

2017-11-07 Thread Prashant Bhole
This was needed for opening any file in bpf-fs without knowing
its object type

Signed-off-by: Prashant Bhole 
---
v2:
 - No change

v3:
 - No change

v4:
 - No change

 tools/bpf/bpftool/common.c | 15 +--
 tools/bpf/bpftool/main.h   |  1 +
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/tools/bpf/bpftool/common.c b/tools/bpf/bpftool/common.c
index f0288269dae8..4556947709ee 100644
--- a/tools/bpf/bpftool/common.c
+++ b/tools/bpf/bpftool/common.c
@@ -91,9 +91,8 @@ static int mnt_bpffs(const char *target, char *buff, size_t 
bufflen)
return 0;
 }
 
-int open_obj_pinned_any(char *path, enum bpf_obj_type exp_type)
+int open_obj_pinned(char *path)
 {
-   enum bpf_obj_type type;
int fd;
 
fd = bpf_obj_get(path);
@@ -105,6 +104,18 @@ int open_obj_pinned_any(char *path, enum bpf_obj_type 
exp_type)
return -1;
}
 
+   return fd;
+}
+
+int open_obj_pinned_any(char *path, enum bpf_obj_type exp_type)
+{
+   enum bpf_obj_type type;
+   int fd;
+
+   fd = open_obj_pinned(path);
+   if (fd < 0)
+   return -1;
+
type = get_fd_type(fd);
if (type < 0) {
close(fd);
diff --git a/tools/bpf/bpftool/main.h b/tools/bpf/bpftool/main.h
index d315d01be645..4b5685005cb0 100644
--- a/tools/bpf/bpftool/main.h
+++ b/tools/bpf/bpftool/main.h
@@ -86,6 +86,7 @@ int cmd_select(const struct cmd *cmds, int argc, char **argv,
 int get_fd_type(int fd);
 const char *get_fd_type_name(enum bpf_obj_type type);
 char *get_fdinfo(int fd, const char *key);
+int open_obj_pinned(char *path);
 int open_obj_pinned_any(char *path, enum bpf_obj_type exp_type);
 int do_pin_any(int argc, char **argv, int (*get_fd_by_id)(__u32));
 
-- 
2.13.6




[PATCH net-next V4 2/3] tools: bpftool: show filenames of pinned objects

2017-11-07 Thread Prashant Bhole
Added support to show filenames of pinned objects.

For example:

root@test# ./bpftool prog
3: tracepoint  name tracepoint__irq  tag f677a7dd722299a3
loaded_at Oct 26/11:39  uid 0
xlated 160B  not jited  memlock 4096B  map_ids 4
pinned /sys/fs/bpf/softirq_prog

4: tracepoint  name tracepoint__irq  tag ea5dc530d00b92b6
loaded_at Oct 26/11:39  uid 0
xlated 392B  not jited  memlock 4096B  map_ids 4,6

root@test# ./bpftool --json --pretty prog
[{
"id": 3,
"type": "tracepoint",
"name": "tracepoint__irq",
"tag": "f677a7dd722299a3",
"loaded_at": "Oct 26/11:39",
"uid": 0,
"bytes_xlated": 160,
"jited": false,
"bytes_memlock": 4096,
"map_ids": [4
],
"pinned": ["/sys/fs/bpf/softirq_prog"
]
},{
"id": 4,
"type": "tracepoint",
"name": "tracepoint__irq",
"tag": "ea5dc530d00b92b6",
"loaded_at": "Oct 26/11:39",
"uid": 0,
"bytes_xlated": 392,
"jited": false,
"bytes_memlock": 4096,
"map_ids": [4,6
],
"pinned": []
}
]

root@test# ./bpftool map
4: hash  name start  flags 0x0
key 4B  value 16B  max_entries 10240  memlock 1003520B
pinned /sys/fs/bpf/softirq_map1
5: hash  name iptr  flags 0x0
key 4B  value 8B  max_entries 10240  memlock 921600B

root@test# ./bpftool --json --pretty map
[{
"id": 4,
"type": "hash",
"name": "start",
"flags": 0,
"bytes_key": 4,
"bytes_value": 16,
"max_entries": 10240,
"bytes_memlock": 1003520,
"pinned": ["/sys/fs/bpf/softirq_map1"
]
},{
"id": 5,
"type": "hash",
"name": "iptr",
"flags": 0,
"bytes_key": 4,
"bytes_value": 8,
"max_entries": 10240,
"bytes_memlock": 921600,
"pinned": []
}
]

Signed-off-by: Prashant Bhole 
---
v2:
 - Dynamically identify bpf-fs moutpoint
 - Close files descriptors before returning on error
 - Fixed line break for proper output formatting
 - Code style: wrapped lines > 80, used reverse christmastree style

v3:
 - Handle multiple bpffs mountpoints
 - Code style: fixed line break indentation

v4:
 - Removed unnecessary hash empty check
 - Code style changes

 tools/bpf/bpftool/common.c | 82 ++
 tools/bpf/bpftool/main.c   |  8 +
 tools/bpf/bpftool/main.h   | 17 ++
 tools/bpf/bpftool/map.c| 21 
 tools/bpf/bpftool/prog.c   | 24 ++
 5 files changed, 152 insertions(+)

diff --git a/tools/bpf/bpftool/common.c b/tools/bpf/bpftool/common.c
index 4556947709ee..55e91fa9a43a 100644
--- a/tools/bpf/bpftool/common.c
+++ b/tools/bpf/bpftool/common.c
@@ -34,7 +34,9 @@
 /* Author: Jakub Kicinski  */
 
 #include 
+#include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -290,3 +292,83 @@ void print_hex_data_json(uint8_t *data, size_t len)
jsonw_printf(json_wtr, "\"0x%02hhx\"", data[i]);
jsonw_end_array(json_wtr);
 }
+
+int build_pinned_obj_table(struct pinned_obj_table *tab,
+  enum bpf_obj_type type)
+{
+   struct bpf_prog_info pinned_info = {};
+   struct pinned_obj *obj_node = NULL;
+   __u32 len = sizeof(pinned_info);
+   struct mntent *mntent = NULL;
+   enum bpf_obj_type objtype;
+   FILE *mntfile = NULL;
+   FTSENT *ftse = NULL;
+   FTS *fts = NULL;
+   int fd, err;
+
+   mntfile = setmntent("/proc/mounts", "r");
+   if (!mntfile)
+   return -1;
+
+   while ((mntent = getmntent(mntfile))) {
+   char *path[] = { mntent->mnt_dir, NULL };
+
+   if (strncmp(mntent->mnt_type, "bpf", 3) != 0)
+   continue;
+
+   fts = fts_open(path, 0, NULL);
+   if (!fts)
+   continue;
+
+   while ((ftse = fts_read(fts))) {
+   if (!(ftse->fts_info & FTS_F))
+   continue;
+   fd = open_obj_pinned(ftse->fts_path);
+   if (fd < 0)
+   continue;
+
+   objtype = get_fd_type(fd);
+   if (objtype != type) {
+   close(fd);
+   continue;
+   }
+   memset(_info, 0, sizeof(pinned_info));
+   err = bpf_obj_get_info_by_fd(fd, _info, );
+   if (err) {
+   close(fd);
+   continue;
+   }
+
+   obj_node = malloc(sizeof(*obj_node));
+   if (!obj_node) {
+   close(fd);
+   fts_close(fts);
+   

[PATCH net-next V4 0/3] tools: bpftool: show filenames of pinned objects

2017-11-07 Thread Prashant Bhole
This patchset adds support to show pinned objects in object details.

Patch1 adds a funtionality to open a path in bpf-fs regardless of its object
type.

Patch2 adds actual functionality by scanning the bpf-fs once and adding
object information in hash table, with object id as a key. One object may be
associated with multiple paths because an object can be pinned multiple times

Patch3 adds command line option to enable this functionality. Making it optional
because scanning bpf-fs can be costly.

v1->v2:
 - Dynamically identify bpf-fs moutpoint
 - Close files descriptors before returning on error
 - Change command line option from {-l|--pinned} to {-f|--bpffs}
 - Updated documentation
 - Fixed line break for proper output formatting
 - Code style: wrapped lines > 80, used reverse christmastree style

v2->v3:
 - Handle multiple bpffs mountpoints
 - Code style: fixed line break indentation

v3->v4:
 - Removed unnecessary hash empty check
 - Code style changes

Prashant Bhole (3):
  tools: bpftool: open pinned object without type check
  tools: bpftool: show filenames of pinned objects
  tools: bpftool: optionally show filenames of pinned objects

 tools/bpf/bpftool/Documentation/bpftool-map.rst  |  5 +-
 tools/bpf/bpftool/Documentation/bpftool-prog.rst |  5 +-
 tools/bpf/bpftool/common.c   | 97 +++-
 tools/bpf/bpftool/main.c | 18 -
 tools/bpf/bpftool/main.h | 21 -
 tools/bpf/bpftool/map.c  | 22 ++
 tools/bpf/bpftool/prog.c | 25 ++
 7 files changed, 187 insertions(+), 6 deletions(-)

-- 
2.13.6




Re: [PATCH net-next v3] net: mvpp2: add ethtool GOP statistics

2017-11-07 Thread David Miller
From: Miquel Raynal 
Date: Mon,  6 Nov 2017 22:56:53 +0100

> Add ethtool statistics support by reading the GOP statistics from the
> hardware counters. Also implement a workqueue to gather the statistics
> every second or some 32-bit counters could overflow.
> 
> Suggested-by: Stefan Chulski 
> Signed-off-by: Miquel Raynal 

Applied, thanks.


Re: [PATCH 0/4] fsl/fman: Fix some error handling code in mac_probe

2017-11-07 Thread David Miller
From: Christophe JAILLET 
Date: Mon,  6 Nov 2017 22:53:28 +0100

> Commit c6e26ea8c893 ("dpaa_eth: change device used") generated some
> conflicts in my patches waiting for submission. So I took a closer look at
> it.
> 
> 
> So here is a serie of 4 patches.
> 
> The 1st one is just about a spurious call to 'dev_set_drvdata()', which is
> done in only 1 error handling path in the function.
> 
> The 2nd one removes some devm_iounmap/release/kfree functions which look
> useless to me.
> 
> The 3rd one fixes a missing of_node_put.
> 
> The 4th one is just cosmetic and removes a useless message.

Series applied to net-next, thank you.


Re: [PATCH 21/21] sunrpc: exit_net cleanup check added

2017-11-07 Thread Vasily Averin
On 2017-11-08 04:22, Stephen Hemminger wrote:
> On Sun, 5 Nov 2017 13:02:44 +0300
> Vasily Averin  wrote:
>> +WARN(!list_empty(>all_clients),
>> + "net %p exit: sunrpc all_clients list is not empty\n", net);
> 
> Don't print a kernel pointer, this is a security leak.

Yes, you're right, I've submitted fixed patch in v3 already,
but seems will prepare v4 with simple  WARN_ON_ONCE(!list_empty())


Re: [PATCH] rtnetlink: fix missing size for IFLA_IF_NETNSID

2017-11-07 Thread David Miller
From: Colin King 
Date: Mon,  6 Nov 2017 15:04:54 +

> From: Colin Ian King 
> 
> The size for IFLA_IF_NETNSID is missing from the size calculation
> because the proceeding semicolon was not removed. Fix this by removing
> the semicolon.
> 
> Detected by CoverityScan, CID#1461135 ("Structurally dead code")
> 
> Fixes: 79e1ad148c84 ("rtnetlink: use netnsid to query interface")
> Signed-off-by: Colin Ian King 

Applied to net-next, thank you!


Re: [PATCH net,stable] net: cdc_ether: fix divide by 0 on bad descriptors

2017-11-07 Thread David Miller
From: Bjørn Mork 
Date: Mon,  6 Nov 2017 15:37:22 +0100

> Setting dev->hard_mtu to 0 will cause a divide error in
> usbnet_probe. Protect against devices with bogus CDC Ethernet
> functional descriptors by ignoring a zero wMaxSegmentSize.
> 
> Signed-off-by: Bjørn Mork 

Applied and queued up for -stable.


Re: [PATCH] bnxt: fix bnxt_hwrm_fw_set_time for y2038

2017-11-07 Thread David Miller
From: Arnd Bergmann 
Date: Mon,  6 Nov 2017 15:04:39 +0100

> On 32-bit architectures, rtc_time_to_tm() returns incorrect results
> in 2038 or later, and do_gettimeofday() is broken for the same reason.
> 
> This changes the code to use ktime_get_real_seconds() and time64_to_tm()
> instead, both of them are 2038-safe, and we can also get rid of the
> CONFIG_RTC_LIB dependency that way.
> 
> Signed-off-by: Arnd Bergmann 

Applied, thanks Arnd.

The RTC_LIB dependency should have been done via KConfig anyways.


Re: [PATCH net,stable] net: qmi_wwan: fix divide by 0 on bad descriptors

2017-11-07 Thread David Miller
From: Bjørn Mork 
Date: Mon,  6 Nov 2017 15:32:18 +0100

> A CDC Ethernet functional descriptor with wMaxSegmentSize = 0 will
> cause a divide error in usbnet_probe:
> 
> divide error:  [#1] PREEMPT SMP KASAN
 ...
> Fix by simply ignoring the bogus descriptor, as it is optional
> for QMI devices anyway.
> 
> Fixes: 423ce8caab7e ("net: usb: qmi_wwan: New driver for Huawei QMI based 
> WWAN devices")
> Reported-by: Andrey Konovalov 
> Signed-off-by: Bjørn Mork 

Applied and queued up for -stable.


Re: [PATCH net-next] net: dsa: lan9303: Drop port range check

2017-11-07 Thread David Miller
From: Egil Hjelmeland 
Date: Mon,  6 Nov 2017 15:19:49 +0100

> Now that ds->num_ports is 3, there is no need to check range of "port"
> parameter.
> 
> Signed-off-by: Egil Hjelmeland 

Applied.


Re: [net-next 1/1] tipc: improve link resiliency when rps is activated

2017-11-07 Thread David Miller
From: Jon Maloy 
Date: Mon, 6 Nov 2017 12:44:11 +0100

> + return core & (num_online_cpus() - 1);

Well, this isn't exactly correct.  The number of online cpus is not
necessarily a power of two.

And furthermore it shouldn't even be necessary.  Just pass the whole
key around, it will have the modulus applied to it when needed
elsewhere in the call chains.


Re: [PATCH] [net-next?] of: add of_property_read_variable_* dummy helpers

2017-11-07 Thread David Miller
From: Arnd Bergmann 
Date: Mon,  6 Nov 2017 14:26:10 +0100

> Commit a67e9472da42 ("of: Add array read functions with min/max size
> limits") added a new interface for reading variable-length arrays from
> DT properties. One user was added in dsa recently and this causes a
> build error because that code can be built with CONFIG_OF disabled:
> 
> net/dsa/dsa2.c: In function 'dsa_switch_parse_member_of':
> net/dsa/dsa2.c:678:7: error: implicit declaration of function 
> 'of_property_read_variable_u32_array'; did you mean 
> 'of_property_read_u32_array'? [-Werror=implicit-function-declaration]
> 
> This adds a dummy functions for of_property_read_variable_u32_array()
> and a few others that had been missing here. I decided to move
> of_property_read_string() and of_property_read_string_helper() in the
> process to make it easier to compare the two sets of function prototypes
> to make sure they match.
> 
> Fixes: 975e6e32215e ("net: dsa: rework switch parsing")
> Signed-off-by: Arnd Bergmann 

Applied, thanks Arnd.


Re: [PATCH net-next] bnxt: delete some unreachable code

2017-11-07 Thread David Miller
From: Dan Carpenter 
Date: Mon, 6 Nov 2017 14:43:01 +0300

> We return on the previous line so this "return 0;" statement should just
> be deleted.
> 
> Signed-off-by: Dan Carpenter 

Applied, thanks Dan.


Re: [PATCH net-next V3 2/3] tools: bpftool: show filenames of pinned objects

2017-11-07 Thread Jakub Kicinski
On Wed, 8 Nov 2017 11:34:44 +0900, Prashant Bhole wrote:
> > > + FILE *mntfile = NULL;
> > > + FTSENT *ftse = NULL;
> > > + FTS *fts = NULL;
> > > + int fd, err;
> > > +
> > > + mntfile = setmntent("/proc/mounts", "r");
> > > + if (!mntfile)
> > > + return -1;
> > > +
> > > + while ((mntent = getmntent(mntfile)) != NULL) {  
> > 
> > Please try to avoid comparisons to NULL, writing:
> > 
> > if (ptr)
> > 
> > is more intuitive to most C programmers than:
> > 
> > if (ptr != NULL)  
> 
> Jakub,
> Thank you for comments. I agree with using 'if (ptr)' for simple check, but
> here it is an assignment.
> It doesn't look intuitive and looks like a typo if I change it to:
>  while ((mntent = getmntent(mntfile))) {

I still prefer this, if you don't mind.

> >   
> > > + char *path[] = {mntent->mnt_dir, 0};  
> > 
> > Shouldn't there be spaces after and before the curly braces?  Does  
> checkpatch --
> > strict not warn about this?  
> 
> I will add spaces. checkpatch complained about this not being static const,
> but doing so causes compiler warning because it doesn't match with signature
> of fts_open()

Right, that's OK to ignore.  Could you also make the 0 into a NULL,
though?

> I will submit v4 with changes for other comments if you are ok with replies
> above.

Thank you!


Re: [PATCH] net: ipv6: sysctl to specify IPv6 ND traffic class

2017-11-07 Thread Erik Kline
Thanks.

Signed-off-by: Erik Kline 

On 7 November 2017 at 16:59, Maciej Żenczykowski  wrote:
> From: Maciej Żenczykowski 
>
> Add a per-device sysctl to specify the default traffic class to use for
> kernel originated IPv6 Neighbour Discovery packets.
>
> Currently this includes:
>
>   - Router Solicitation (ICMPv6 type 133)
> ndisc_send_rs() -> ndisc_send_skb() -> ip6_nd_hdr()
>
>   - Neighbour Solicitation (ICMPv6 type 135)
> ndisc_send_ns() -> ndisc_send_skb() -> ip6_nd_hdr()
>
>   - Neighbour Advertisement (ICMPv6 type 136)
> ndisc_send_na() -> ndisc_send_skb() -> ip6_nd_hdr()
>
>   - Redirect (ICMPv6 type 137)
> ndisc_send_redirect() -> ndisc_send_skb() -> ip6_nd_hdr()
>
> and if the kernel ever gets around to generating RA's,
> it would presumably also include:
>
>   - Router Advertisement (ICMPv6 type 134)
> (radvd daemon could pick up on the kernel setting and use it)
>
> Interface drivers may examine the Traffic Class value and translate
> the DiffServ Code Point into a link-layer appropriate traffic
> prioritization scheme.  An example of mapping IETF DSCP values to
> IEEE 802.11 User Priority values can be found here:
>
> https://tools.ietf.org/html/draft-ietf-tsvwg-ieee-802-11
>
> The expected primary use case is to properly prioritize ND over wifi.
>
> Testing:
>   jzem22:~# cat /proc/sys/net/ipv6/conf/eth0/ndisc_tclass
>   0
>   jzem22:~# echo -1 > /proc/sys/net/ipv6/conf/eth0/ndisc_tclass
>   -bash: echo: write error: Invalid argument
>   jzem22:~# echo 256 > /proc/sys/net/ipv6/conf/eth0/ndisc_tclass
>   -bash: echo: write error: Invalid argument
>   jzem22:~# echo 0 > /proc/sys/net/ipv6/conf/eth0/ndisc_tclass
>   jzem22:~# echo 255 > /proc/sys/net/ipv6/conf/eth0/ndisc_tclass
>   jzem22:~# cat /proc/sys/net/ipv6/conf/eth0/ndisc_tclass
>   255
>   jzem22:~# echo 34 > /proc/sys/net/ipv6/conf/eth0/ndisc_tclass
>   jzem22:~# cat /proc/sys/net/ipv6/conf/eth0/ndisc_tclass
>   34
>
>   jzem22:~# echo $[0xDC] > /proc/sys/net/ipv6/conf/eth0/ndisc_tclass
>   jzem22:~# tcpdump -v -i eth0 icmp6 and src host jzem22.pgc and dst host 
> fe80::1
>   tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 
> 262144 bytes
>   IP6 (class 0xdc, hlim 255, next-header ICMPv6 (58) payload length: 24)
>   jzem22.pgc > fe80::1: [icmp6 sum ok] ICMP6, neighbor advertisement,
>   length 24, tgt is jzem22.pgc, Flags [solicited]
>
> (based on original change written by Erik Kline, with minor changes)
>
> Cc: Lorenzo Colitti 
> Cc: Erik Kline 
> Signed-off-by: Maciej Żenczykowski 
> ---
>  Documentation/networking/ip-sysctl.txt |  9 +
>  include/linux/ipv6.h   |  1 +
>  include/uapi/linux/ipv6.h  |  1 +
>  net/ipv6/addrconf.c| 11 +++
>  net/ipv6/ndisc.c   |  4 +++-
>  5 files changed, 25 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/networking/ip-sysctl.txt 
> b/Documentation/networking/ip-sysctl.txt
> index 54410a1d4065..d8676dda7fa6 100644
> --- a/Documentation/networking/ip-sysctl.txt
> +++ b/Documentation/networking/ip-sysctl.txt
> @@ -1732,6 +1732,15 @@ ndisc_notify - BOOLEAN
> 1 - Generate unsolicited neighbour advertisements when device is 
> brought
> up or hardware address changes.
>
> +ndisc_tclass - INTEGER
> +   The IPv6 Traffic Class to use by default when sending IPv6 Neighbor
> +   Discovery (Router Solicitation, Router Advertisement, Neighbor
> +   Solicitation, Neighbor Advertisement, Redirect) messages.
> +   These 8 bits can be interpreted as 6 high order bits holding the DSCP
> +   value and 2 low order bits representing ECN (which you probably want
> +   to leave cleared).
> +   0 - (default)
> +
>  mldv1_unsolicited_report_interval - INTEGER
> The interval in milliseconds in which the next unsolicited
> MLDv1 report retransmit will take place.
> diff --git a/include/linux/ipv6.h b/include/linux/ipv6.h
> index ea04ca024f0d..cb18c6290ca8 100644
> --- a/include/linux/ipv6.h
> +++ b/include/linux/ipv6.h
> @@ -73,6 +73,7 @@ struct ipv6_devconf {
> __u32   enhanced_dad;
> __u32   addr_gen_mode;
> __s32   disable_policy;
> +   __s32   ndisc_tclass;
>
> struct ctl_table_header *sysctl_header;
>  };
> diff --git a/include/uapi/linux/ipv6.h b/include/uapi/linux/ipv6.h
> index b22a9c4e1b12..9c0f4a92bcff 100644
> --- a/include/uapi/linux/ipv6.h
> +++ b/include/uapi/linux/ipv6.h
> @@ -186,6 +186,7 @@ enum {
> DEVCONF_ADDR_GEN_MODE,
> DEVCONF_DISABLE_POLICY,
> DEVCONF_ACCEPT_RA_RT_INFO_MIN_PLEN,
> +   DEVCONF_NDISC_TCLASS,
> DEVCONF_MAX
>  };
>
> diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
> index 6233e06fa35c..a6dffd65eb9d 100644
> --- a/net/ipv6/addrconf.c
> +++ b/net/ipv6/addrconf.c
> @@ 

Re: [PATCH v2 net-next 0/4] net: dsa: lan9303: Linting

2017-11-07 Thread David Miller
From: Egil Hjelmeland 
Date: Mon,  6 Nov 2017 12:42:00 +0100

> This series is non-functional. 
>  - Correct some errors in comments and documentation.
> Remove scripts/checkpatch.pl WARNINGs and most CHECKs:
>  - Replace msleep(1) with usleep_range()
>  - Adjust indenting
>  
> Changes v1 -> v2:
>  - Removed patch 4 "Remove unnecessary parentheses", to be addressed later

Series applied, thank you.


Re: [PATCH net-next] dpaa_eth: fix error return code in dpaa_eth_probe()

2017-11-07 Thread David Miller
From: Wei Yongjun 
Date: Mon, 6 Nov 2017 11:12:08 +

> Fix to return a negative error code from the dpaa_bp_alloc() error
> handling case instead of 0, as done elsewhere in this function.
> 
> Signed-off-by: Wei Yongjun 

Applied.


Re: [PATCH] staging: octeon: Fix stopping of the interface.

2017-11-07 Thread Florian Fainelli


On 11/07/2017 07:06 PM, Steven J. Hill wrote:
> Before disconnecting the PHY when a port is being taken down,
> a call to phy_stop() is necessary.

Indeed, thanks for fixing this!

> 
> Signed-off-by: Steven J. Hill 
> Acked-by: David Daney 

Acked-by: Florian Fainelli 
-- 
Florian


Re: [PATCH net-next] mlxsw: spectrum: Fix error return code in mlxsw_sp_port_create()

2017-11-07 Thread David Miller
From: Wei Yongjun 
Date: Mon, 6 Nov 2017 11:11:28 +

> Fix to return a negative error code from the VID  create error handling
> case instead of 0, as done elsewhere in this function.
> 
> Fixes: c57529e1d5d8 ("mlxsw: spectrum: Replace vPorts with Port-VLAN")
> Signed-off-by: Wei Yongjun 

Applied.


  1   2   3   4   >