Re: [PATCH 3/6] x86/hyper-v: reenlightenment notifications support

2017-12-12 Thread Vitaly Kuznetsov
Roman Kagan  writes:

> On Mon, Dec 11, 2017 at 10:56:33AM +0100, Vitaly Kuznetsov wrote:
>> Roman Kagan  writes:
>> > On Fri, Dec 08, 2017 at 11:49:57AM +0100, Vitaly Kuznetsov wrote:
>> >> +void register_hv_tsc_update(void (*cb)(void))
>> >> +{
>> >
>> > The function name seems unfortunate.  IMHO such a name suggests
>> > registering a callback on a notifier chain (rather than unconditionally
>> > replacing the old callback), and having no other side effects.
>> 
>> I see, any suggestion? register_hv_reenlightenment_cb? 
>> register_hv_tscchange_cb?
>
> IMHO arm_hv_reenlightenment_cb or arm_hv_tscchange_cb would be better,
> but I'm not very good at giving descriptive names.
>

I would probably try to avoid using 'arm' word in x86 code to assist
poor git-greppers :-) And we actually need a pair of functions
(enable/disable). I will probably go with

set_hv_tscchange_cb()
clear_hv_tscchange_cb()

in v2 unless there's a better suggestion.

>> 
>> >
>> >> + struct hv_reenlightenment_control re_ctrl = {
>> >> + .vector = HYPERV_REENLIGHTENMENT_VECTOR,
>> >> + .enabled = 1,
>> >> + .target_vp = hv_vp_index[smp_processor_id()]
>> >> + };
>> >> + struct hv_tsc_emulation_control emu_ctrl = {.enabled = 1};
>> >> +
>> >> + if (!(ms_hyperv.features & HV_X64_ACCESS_REENLIGHTENMENT))
>> >> + return;
>> >
>> > What happens then?  L2 guests keep running with their clocks ticking at
>> > a different speed?
>> >
>> 
>> In reallity this never happens -- in case nested virtualization is
>> supported reenlightenment is also available. In theory, L0 can emulate
>> TSC acceess for forever after migration.
>
> I would think that Hyper-V only started rdtsc emulation if
> TSC_EMULATION_CONTROL was turned on, which wouldn't happen here.
>

Yes, this is the de-facto behavior I observe with WS2016.

> But indeed, normally this shouldn't be a problem.  It may make sense
> just to issue a warning if the feature is unsupported, though.

Will do in v2, thanks.

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


Re: [PATCH 6/6] x86/kvm: support Hyper-V reenlightenment

2017-12-12 Thread Vitaly Kuznetsov
Vitaly Kuznetsov  writes:

> Roman Kagan  writes:
>
>> On Fri, Dec 08, 2017 at 11:50:00AM +0100, Vitaly Kuznetsov wrote:
>>> When we run nested KVM on Hyper-V guests we need to update masterclocks for
>>> all guests when L1 migrates to a host with different TSC frequency.
>>> Implement the procedure in the following way:
>>> - Pause all guests.
>>> - Tell our host (Hyper-V) to stop emulating TSC accesses.
>>> - Update our gtod copy, recompute clocks.
>>> - Unpause all guests.
>>> 
>>> This is somewhat similar to cpufreq but we have two important differences:
>>> we can only disable TSC emulation globally (on all CPUs) and we don't know
>>> the new TSC frequency until we turn the emulation off so we can't
>>> 'prepare' ourselves to the event.
>>> 
>>> Signed-off-by: Vitaly Kuznetsov 
>>> ---
>>>  arch/x86/kvm/x86.c | 45 +
>>>  1 file changed, 45 insertions(+)
>>> 
>>> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
>>> index 96e04a0cb921..04d90712ffd2 100644
>>> --- a/arch/x86/kvm/x86.c
>>> +++ b/arch/x86/kvm/x86.c
>>> @@ -68,6 +68,7 @@
>>>  #include 
>>>  #include 
>>>  #include 
>>> +#include 
>>>  
>>>  #define CREATE_TRACE_POINTS
>>>  #include "trace.h"
>>> @@ -5946,6 +5947,43 @@ static void tsc_khz_changed(void *data)
>>> __this_cpu_write(cpu_tsc_khz, khz);
>>>  }
>>>  
>>> +void kvm_hyperv_tsc_notifier(void)
>>> +{
>>> +#ifdef CONFIG_X86_64
>>> +   struct kvm *kvm;
>>> +   struct kvm_vcpu *vcpu;
>>> +   int cpu;
>>> +
>>> +   spin_lock(&kvm_lock);
>>> +   list_for_each_entry(kvm, &vm_list, vm_list)
>>> +   kvm_make_mclock_inprogress_request(kvm);
>>> +
>>> +   hyperv_stop_tsc_emulation();
>>> +
>>> +   /* TSC frequency always matches when on Hyper-V */
>>> +   for_each_present_cpu(cpu)
>>> +   per_cpu(cpu_tsc_khz, cpu) = tsc_khz;
>>> +   kvm_max_guest_tsc_khz = tsc_khz;
>>> +
>>> +   list_for_each_entry(kvm, &vm_list, vm_list) {
>>> +   struct kvm_arch *ka = &kvm->arch;
>>> +
>>> +   spin_lock(&ka->pvclock_gtod_sync_lock);
>>> +
>>> +   pvclock_update_vm_gtod_copy(kvm);
>>> +
>>> +   kvm_for_each_vcpu(cpu, vcpu, kvm)
>>> +   kvm_make_request(KVM_REQ_CLOCK_UPDATE, vcpu);
>>> +
>>> +   kvm_for_each_vcpu(cpu, vcpu, kvm)
>>> +   kvm_clear_request(KVM_REQ_MCLOCK_INPROGRESS, vcpu);
>>> +
>>> +   spin_unlock(&ka->pvclock_gtod_sync_lock);
>>> +   }
>>> +   spin_unlock(&kvm_lock);
>>
>> Can't you skip all this if the tsc frequency hasn't changed (which
>> should probably be the case when the CPU supports tsc frequency
>> scaling)?
>>
>
> The thing is that we don't know if it changed or not: only after
> disabling TSC emulation we'll be able to read the new one from the host
> and we need to do this with all VMs paused.

(having second thoughts here)

While we don't know if TSC frequency has changed or not, we can check
the emulation status before calling the callback and if TSC accesses are
not emulated omit the call. However, it seems that Hyper-V host (as of
WS2016) turns on emulation regardless of the TSC scaling presence.

I'll add emulation status check before issuing the callback in v2. The
change will go to PATCH3.

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


Re: [PATCH v2] drivers: visorbus: move driver out of staging

2017-12-12 Thread Christoph Hellwig
Hi David,

as said before, please submit the actual files as new code to the
kernel.  The code will need a full review, and a simple move is not
going to cut it.  Posting the actual code as patches will allow for the
proper review that is needed.
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] Staging: comedi: drivers: serial2002 fixed a blank line coding style

2017-12-12 Thread Ian Abbott

On 08/12/17 18:56, Vikash Kesarwani wrote:

Fixed a blank line coding style after a declaration

Signed-off-by: Vikash Kesarwani 
---
  drivers/staging/comedi/drivers/serial2002.c | 1 +
  1 file changed, 1 insertion(+)

diff --git a/drivers/staging/comedi/drivers/serial2002.c 
b/drivers/staging/comedi/drivers/serial2002.c
index cc18e25103ca..c9d478fddead 100644
--- a/drivers/staging/comedi/drivers/serial2002.c
+++ b/drivers/staging/comedi/drivers/serial2002.c
@@ -107,6 +107,7 @@ static long serial2002_tty_ioctl(struct file *f, unsigned 
int op,
  static int serial2002_tty_write(struct file *f, unsigned char *buf, int count)
  {
loff_t pos = 0;
+
return kernel_write(f, buf, count, &pos);
  }
  



Looks okay, thanks.

Reviewed-by: Ian Abbott 

--
-=( Ian Abbott @ MEV Ltd.E-mail:  )=-
-=(  Web: http://www.mev.co.uk/  )=-
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[BUG] vme_ca91cx42: a possible sleep-in-atomic bug in ca91cx42_master_set

2017-12-12 Thread Jia-Ju Bai
According to drivers/vme/bridges/vme_ca91cx42.c, the driver may sleep 
under a spinlock.

The function call path is:
ca91cx42_master_set (acquire the spinlock)
  ca91cx42_alloc_resource
ioremap_nocache --> may sleep

I do not find a good way to fix it, so I only report.
This possible bug is found by my static analysis tool (DSAC) and checked 
by my code review.



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


[PATCH] vme: Fix a possible sleep-in-atomic bug in vme_tsi148

2017-12-12 Thread Jia-Ju Bai
The driver may sleep under a spinlock.
The function call path is:
tsi148_master_write \ tsi148_master_read (acquire the spinlock)
  vme_register_error_handler
kmalloc(GFP_KERNEL) --> may sleep

To fix it, GFP_KERNEL is replaced with GFP_ATOMIC.

This bug is found by my static analysis tool(DSAC) and checked by my code 
review.

Signed-off-by: Jia-Ju Bai 
---
 drivers/vme/vme.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/vme/vme.c b/drivers/vme/vme.c
index 8124622..92500f6 100644
--- a/drivers/vme/vme.c
+++ b/drivers/vme/vme.c
@@ -1290,7 +1290,7 @@ struct vme_error_handler *vme_register_error_handler(
 {
struct vme_error_handler *handler;
 
-   handler = kmalloc(sizeof(*handler), GFP_KERNEL);
+   handler = kmalloc(sizeof(*handler), GFP_ATOMIC);
if (!handler)
return NULL;
 
-- 
1.7.9.5

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


Re: [PATCH v4 3/5] staging: Introduce NVIDIA Tegra video decoder driver

2017-12-12 Thread Hans Verkuil
On 10/12/17 19:56, Dmitry Osipenko wrote:
> On 05.12.2017 16:03, Hans Verkuil wrote:
>> On 12/05/17 13:17, Dmitry Osipenko wrote:
>>> Hi Hans,
>>>
>>> On 04.12.2017 17:04, Hans Verkuil wrote:
 Hi Dmitry,

 As you already mention in the TODO, this should become a v4l2 codec driver.

 Good existing examples are the coda, qcom/venus and mtk-vcodec drivers.

 One thing that is not clear from this code is if the tegra hardware is a
 stateful or stateless codec, i.e. does it keep track of the decoder state
 in the hardware, or does the application have to keep track of the state 
 and
 provide the state information together with the video data?

 I ask because at the moment only stateful codecs are supported. Work is 
 ongoing
 to support stateless codecs, but we don't support that for now.

>>>
>>> It is stateless. Is there anything ready to try out? If yes, could you 
>>> please
>>> give a reference to that work?
>>
>> I rebased my two year old 'requests2' branch to the latest mainline version 
>> and
>> gave it the imaginative name 'requests3':
>>
>> https://git.linuxtv.org/hverkuil/media_tree.git/log/?h=requests3
>>
>> (Note: only compile tested!)
> 
> Thank you very much.
> 
>> This is what ChromeOS has been using (actually they use a slightly older 
>> version)
>> and the new version that is currently being developed will be similar, so 
>> any work
>> you do on top of this will carry over to the final version without too much 
>> effort.
>>
>> At least, that's the intention :-)
>>
>> I've CC-ed Maxime and Giulio as well: they are looking into adding support 
>> for
>> the stateless allwinner codec based on this code as well. There may well be
>> opportunities for you to work together, esp. on the userspace side. Note that
>> Rockchip has the same issue, they too have a stateless HW codec.
> 
> IIUC, we will have to define video decoder parameters in V4L API and then 
> make a
> V4L driver / userspace prototype (ffmpeg for example) that will use the 
> requests
> API for video decoding in order to upstream the requests API. Does it sound 
> good?

Correct.

Hugues Fruchet made an example bit parser for mpeg:

https://www.spinics.net/lists/linux-media/msg115017.html

So something similar would work.

My recommendation would be to make a separate library that can be shared among
different implementations (i.e. in gstreamer, in vdpau, using a libv4l2 plugin, 
etc., etc.).

That can easily be hosted as part of v4l-utils to keep it in sync with the
kernel drivers. If it's independent of the various drivers, then it can be
hosted anywhere of course.

BTW, we as V4L2 core developers have no plans on working on such a library :-)

Regards,

Hans

> 
>>>
 Anyway, I'm OK with merging this in staging. Although I think it should go
 to staging/media since we want to keep track of it.

>>>
>>> Awesome, I'll move driver to staging/media in V5. Thanks!
>>
>> Nice, thanks!

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


[PATCH] rtl8188eu: Fix a possible sleep-in-atomic bug in set_tx_beacon_cmd

2017-12-12 Thread Jia-Ju Bai
The driver may sleep under a spinlock.
The function call path is:
update_beacon (acquire the spinlock)
  update_BCNTIM
set_tx_beacon_cmd
  kzalloc(GFP_KERNEL) --> may sleep
  kmemdup(GFP_KERNEL) --> may sleep

To fix it, GFP_KERNEL is replaced with GFP_ATOMIC.

This bug is found by my static analysis tool(DSAC) and checked by my code 
review.

Signed-off-by: Jia-Ju Bai 
---
 drivers/staging/rtl8188eu/core/rtw_mlme_ext.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c 
b/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
index d73e9bd..bcb6919 100644
--- a/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
+++ b/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
@@ -5395,14 +5395,14 @@ u8 set_tx_beacon_cmd(struct adapter *padapter)
int len_diff = 0;
 
 
-   ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
+   ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
if (!ph2c) {
res = _FAIL;
goto exit;
}
 
ptxBeacon_parm = kmemdup(&(pmlmeinfo->network),
-   sizeof(struct wlan_bssid_ex), GFP_KERNEL);
+   sizeof(struct wlan_bssid_ex), GFP_ATOMIC);
if (ptxBeacon_parm == NULL) {
kfree(ph2c);
res = _FAIL;
-- 
1.7.9.5

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


[PATCH 01/24] staging: ccree: remove ahash wrappers

2017-12-12 Thread Gilad Ben-Yossef
Remove a no longer needed abstraction around ccree hash crypto API
internals that used to allow same ops to be used in synchronous and
asynchronous fashion.

Signed-off-by: Gilad Ben-Yossef 
---
 drivers/staging/ccree/ssi_hash.c | 260 ---
 1 file changed, 76 insertions(+), 184 deletions(-)

diff --git a/drivers/staging/ccree/ssi_hash.c b/drivers/staging/ccree/ssi_hash.c
index 0c4f3db..a762eef 100644
--- a/drivers/staging/ccree/ssi_hash.c
+++ b/drivers/staging/ccree/ssi_hash.c
@@ -426,13 +426,15 @@ static void ssi_hash_complete(struct device *dev, void 
*ssi_req)
req->base.complete(&req->base, 0);
 }
 
-static int ssi_hash_digest(struct ahash_req_ctx *state,
-  struct ssi_hash_ctx *ctx,
-  unsigned int digestsize,
-  struct scatterlist *src,
-  unsigned int nbytes, u8 *result,
-  void *async_req)
+static int ssi_ahash_digest(struct ahash_request *req)
 {
+   struct ahash_req_ctx *state = ahash_request_ctx(req);
+   struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
+   struct ssi_hash_ctx *ctx = crypto_ahash_ctx(tfm);
+   u32 digestsize = crypto_ahash_digestsize(tfm);
+   struct scatterlist *src = req->src;
+   unsigned int nbytes = req->nbytes;
+   u8 *result = req->result;
struct device *dev = drvdata_to_dev(ctx->drvdata);
bool is_hmac = ctx->is_hmac;
struct ssi_crypto_req ssi_req = {};
@@ -460,11 +462,9 @@ static int ssi_hash_digest(struct ahash_req_ctx *state,
return -ENOMEM;
}
 
-   if (async_req) {
-   /* Setup DX request structure */
-   ssi_req.user_cb = (void *)ssi_hash_digest_complete;
-   ssi_req.user_arg = (void *)async_req;
-   }
+   /* Setup DX request structure */
+   ssi_req.user_cb = ssi_hash_digest_complete;
+   ssi_req.user_arg = req;
 
/* If HMAC then load hash IPAD xor key, if HASH then load initial
 * digest
@@ -563,44 +563,32 @@ ctx->drvdata, ctx->hash_mode), HASH_LEN_SIZE);
set_cipher_mode(&desc[idx], ctx->hw_mode);
/* TODO */
set_dout_dlli(&desc[idx], state->digest_result_dma_addr, digestsize,
- NS_BIT, (async_req ? 1 : 0));
-   if (async_req)
-   set_queue_last_ind(&desc[idx]);
+ NS_BIT, 1);
+   set_queue_last_ind(&desc[idx]);
set_flow_mode(&desc[idx], S_HASH_to_DOUT);
set_setup_mode(&desc[idx], SETUP_WRITE_STATE0);
set_cipher_config1(&desc[idx], HASH_PADDING_DISABLED);
ssi_set_hash_endianity(ctx->hash_mode, &desc[idx]);
idx++;
 
-   if (async_req) {
-   rc = send_request(ctx->drvdata, &ssi_req, desc, idx, 1);
-   if (rc != -EINPROGRESS) {
-   dev_err(dev, "send_request() failed (rc=%d)\n", rc);
-   cc_unmap_hash_request(dev, state, src, true);
-   ssi_hash_unmap_result(dev, state, digestsize, result);
-   ssi_hash_unmap_request(dev, state, ctx);
-   }
-   } else {
-   rc = send_request(ctx->drvdata, &ssi_req, desc, idx, 0);
-   if (rc) {
-   dev_err(dev, "send_request() failed (rc=%d)\n", rc);
-   cc_unmap_hash_request(dev, state, src, true);
-   } else {
-   cc_unmap_hash_request(dev, state, src, false);
-   }
+   rc = send_request(ctx->drvdata, &ssi_req, desc, idx, 1);
+   if (rc != -EINPROGRESS) {
+   dev_err(dev, "send_request() failed (rc=%d)\n", rc);
+   cc_unmap_hash_request(dev, state, src, true);
ssi_hash_unmap_result(dev, state, digestsize, result);
ssi_hash_unmap_request(dev, state, ctx);
}
return rc;
 }
 
-static int ssi_hash_update(struct ahash_req_ctx *state,
-  struct ssi_hash_ctx *ctx,
-  unsigned int block_size,
-  struct scatterlist *src,
-  unsigned int nbytes,
-  void *async_req)
+static int ssi_ahash_update(struct ahash_request *req)
 {
+   struct ahash_req_ctx *state = ahash_request_ctx(req);
+   struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
+   struct ssi_hash_ctx *ctx = crypto_ahash_ctx(tfm);
+   unsigned int block_size = crypto_tfm_alg_blocksize(&tfm->base);
+   struct scatterlist *src = req->src;
+   unsigned int nbytes = req->nbytes;
struct device *dev = drvdata_to_dev(ctx->drvdata);
struct ssi_crypto_req ssi_req = {};
struct cc_hw_desc desc[SSI_MAX_AHASH_SEQ_LEN];
@@ -628,11 +616,9 @@ static int ssi_hash_update(struct ahash_req_ctx *state,
return -ENOMEM;
}
 
-   if (async_req) {
-   /* Setup DX request str

[PATCH 00/24] staging: ccree: cleanups and simplification

2017-12-12 Thread Gilad Ben-Yossef
More CCREE code cleanup and simplifications, including:
- Drop code supporting long code synch cipher and hash usage
- Drop ifdef out code for features not supported by HW
- More naming convention and name space cleanup
- Coding style fixes

This patch set goes on top of Dan Carpenter's patch entitled
"staging: ccree: Uninitialized return in ssi_ahash_import()"
sent to the list.

Signed-off-by: Gilad Ben-Yossef 

Gilad Ben-Yossef (24):
  staging: ccree: remove ahash wrappers
  staging: ccree: fix hash naming convention
  staging: ccree: amend hash func def for readability
  staging: ccree: func params should follow func name
  staging: ccree: shorten parameter name
  staging: ccree: fix func def and decl coding style
  staging: ccree: simplify expression with local var
  staging: ccree: fix func call param indentation
  staging: ccree: fix reg mgr naming convention
  staging: ccree: fix req mgr func def coding style
  staging: ccree: remove cipher sync blkcipher remains
  staging: ccree: fix cipher naming convention
  staging: ccree: fix cipher func def coding style
  staging: ccree: fix ivgen naming convention
  staging: ccree: fix ivgen func def coding style
  staging: ccree: drop unsupported MULTI2 mode code
  staging: ccree: remove SSI_CC_HAS_ macros
  staging: ccree: rename all SSI to CC
  staging: ccree: rename all DX to CC
  staging: ccree: rename vars/structs/enums from ssi_ to cc_
  staging: ccree: fix buf mgr naming convention
  staging: ccree: fix sram mgr naming convention
  staging: ccree: simplify freeing SRAM memory address
  staging: ccree: fix FIPS mgr naming convention

 drivers/staging/ccree/cc_crypto_ctx.h|  17 -
 drivers/staging/ccree/cc_hw_queue_defs.h |   6 +-
 drivers/staging/ccree/cc_lli_defs.h  |   2 +-
 drivers/staging/ccree/dx_crys_kernel.h   | 314 +--
 drivers/staging/ccree/dx_host.h  | 262 +-
 drivers/staging/ccree/dx_reg_common.h|  10 +-
 drivers/staging/ccree/ssi_aead.c | 176 +++
 drivers/staging/ccree/ssi_aead.h |  20 +-
 drivers/staging/ccree/ssi_buffer_mgr.c   | 320 +---
 drivers/staging/ccree/ssi_buffer_mgr.h   |  36 +-
 drivers/staging/ccree/ssi_cipher.c   | 604 --
 drivers/staging/ccree/ssi_cipher.h   |  16 +-
 drivers/staging/ccree/ssi_config.h   |  12 +-
 drivers/staging/ccree/ssi_driver.c   | 106 ++--
 drivers/staging/ccree/ssi_driver.h   |  79 ++-
 drivers/staging/ccree/ssi_fips.c |  22 +-
 drivers/staging/ccree/ssi_fips.h |  22 +-
 drivers/staging/ccree/ssi_hash.c | 857 +--
 drivers/staging/ccree/ssi_hash.h |  30 +-
 drivers/staging/ccree/ssi_ivgen.c|  88 ++--
 drivers/staging/ccree/ssi_ivgen.h|  24 +-
 drivers/staging/ccree/ssi_pm.c   |  18 +-
 drivers/staging/ccree/ssi_pm.h   |  10 +-
 drivers/staging/ccree/ssi_request_mgr.c  | 136 +++--
 drivers/staging/ccree/ssi_request_mgr.h  |  23 +-
 drivers/staging/ccree/ssi_sram_mgr.c |  31 +-
 drivers/staging/ccree/ssi_sram_mgr.h |  29 +-
 drivers/staging/ccree/ssi_sysfs.c|  22 +-
 drivers/staging/ccree/ssi_sysfs.h|  10 +-
 29 files changed, 1419 insertions(+), 1883 deletions(-)

-- 
2.7.4

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


[PATCH 02/24] staging: ccree: fix hash naming convention

2017-12-12 Thread Gilad Ben-Yossef
The hash files were using a naming convention which was inconsistent
(ssi vs. cc), included a useless prefix (ssi_hash) and often used too
long function names producing monster such as
ssi_ahash_get_initial_digest_len_sram_addr() that made the call site
hard to read.

Make the code more readable by switching to a simpler, consistent naming
convention for the file.

Signed-off-by: Gilad Ben-Yossef 
---
 drivers/staging/ccree/ssi_aead.c   |  10 +-
 drivers/staging/ccree/ssi_driver.c |   8 +-
 drivers/staging/ccree/ssi_hash.c   | 494 ++---
 drivers/staging/ccree/ssi_hash.h   |  16 +-
 drivers/staging/ccree/ssi_pm.c |   2 +-
 5 files changed, 257 insertions(+), 273 deletions(-)

diff --git a/drivers/staging/ccree/ssi_aead.c b/drivers/staging/ccree/ssi_aead.c
index 5548c7b..408ea24 100644
--- a/drivers/staging/ccree/ssi_aead.c
+++ b/drivers/staging/ccree/ssi_aead.c
@@ -1023,10 +1023,8 @@ static void cc_set_hmac_desc(struct aead_request *req, 
struct cc_hw_desc desc[],
/* Load init. digest len (64 bytes) */
hw_desc_init(&desc[idx]);
set_cipher_mode(&desc[idx], hash_mode);
-   set_din_sram(&desc[idx],
-ssi_ahash_get_initial_digest_len_sram_addr(ctx->drvdata,
-   hash_mode),
-   HASH_LEN_SIZE);
+   set_din_sram(&desc[idx], cc_digest_len_addr(ctx->drvdata, hash_mode),
+HASH_LEN_SIZE);
set_flow_mode(&desc[idx], S_DIN_to_HASH);
set_setup_mode(&desc[idx], SETUP_LOAD_KEY0);
idx++;
@@ -1152,9 +1150,7 @@ static void cc_proc_scheme_desc(struct aead_request *req,
/* Load init. digest len (64 bytes) */
hw_desc_init(&desc[idx]);
set_cipher_mode(&desc[idx], hash_mode);
-   set_din_sram(&desc[idx],
-ssi_ahash_get_initial_digest_len_sram_addr(ctx->drvdata,
-   hash_mode),
+   set_din_sram(&desc[idx], cc_digest_len_addr(ctx->drvdata, hash_mode),
 HASH_LEN_SIZE);
set_cipher_config1(&desc[idx], HASH_PADDING_ENABLED);
set_flow_mode(&desc[idx], S_DIN_to_HASH);
diff --git a/drivers/staging/ccree/ssi_driver.c 
b/drivers/staging/ccree/ssi_driver.c
index a0d8eb8..513c5e4 100644
--- a/drivers/staging/ccree/ssi_driver.c
+++ b/drivers/staging/ccree/ssi_driver.c
@@ -358,9 +358,9 @@ static int init_cc_resources(struct platform_device 
*plat_dev)
}
 
/* hash must be allocated before aead since hash exports APIs */
-   rc = ssi_hash_alloc(new_drvdata);
+   rc = cc_hash_alloc(new_drvdata);
if (rc) {
-   dev_err(dev, "ssi_hash_alloc failed\n");
+   dev_err(dev, "cc_hash_alloc failed\n");
goto post_cipher_err;
}
 
@@ -379,7 +379,7 @@ static int init_cc_resources(struct platform_device 
*plat_dev)
return 0;
 
 post_hash_err:
-   ssi_hash_free(new_drvdata);
+   cc_hash_free(new_drvdata);
 post_cipher_err:
ssi_ablkcipher_free(new_drvdata);
 post_ivgen_err:
@@ -417,7 +417,7 @@ static void cleanup_cc_resources(struct platform_device 
*plat_dev)
(struct ssi_drvdata *)platform_get_drvdata(plat_dev);
 
cc_aead_free(drvdata);
-   ssi_hash_free(drvdata);
+   cc_hash_free(drvdata);
ssi_ablkcipher_free(drvdata);
ssi_ivgen_fini(drvdata);
cc_pm_fini(drvdata);
diff --git a/drivers/staging/ccree/ssi_hash.c b/drivers/staging/ccree/ssi_hash.c
index a762eef..6bc42e4 100644
--- a/drivers/staging/ccree/ssi_hash.c
+++ b/drivers/staging/ccree/ssi_hash.c
@@ -31,10 +31,10 @@
 #include "ssi_hash.h"
 #include "ssi_sram_mgr.h"
 
-#define SSI_MAX_AHASH_SEQ_LEN 12
-#define SSI_MAX_OPAD_KEYS_SIZE SSI_MAX_HASH_BLCK_SIZE
+#define CC_MAX_HASH_SEQ_LEN 12
+#define CC_MAX_OPAD_KEYS_SIZE CC_MAX_HASH_BLCK_SIZE
 
-struct ssi_hash_handle {
+struct cc_hash_handle {
ssi_sram_addr_t digest_len_sram_addr; /* const value in SRAM*/
ssi_sram_addr_t larval_digest_sram_addr;   /* const value in SRAM */
struct list_head hash_list;
@@ -64,16 +64,15 @@ static const u64 sha512_init[] = {
SHA512_H3, SHA512_H2, SHA512_H1, SHA512_H0 };
 #endif
 
-static void ssi_hash_create_xcbc_setup(
+static void cc_setup_xcbc(
struct ahash_request *areq,
struct cc_hw_desc desc[],
unsigned int *seq_size);
 
-static void ssi_hash_create_cmac_setup(struct ahash_request *areq,
-  struct cc_hw_desc desc[],
-  unsigned int *seq_size);
+static void cc_setup_cmac(struct ahash_request *areq, struct cc_hw_desc desc[],
+ unsigned int *seq_size);
 
-struct ssi_hash_alg {
+struct cc_hash_alg {
struct list_head entry;
int hash_mode;
int hw_mode;
@@ -88,13 +87,13 @@ struct hash_key_req_ctx {
 };
 
 /* hash pe

[PATCH 03/24] staging: ccree: amend hash func def for readability

2017-12-12 Thread Gilad Ben-Yossef
Func definitions in the hash implementation were did not adhere to
coding style. Fix them for better readability.

Signed-off-by: Gilad Ben-Yossef 
---
 drivers/staging/ccree/ssi_hash.c | 20 +++-
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/ccree/ssi_hash.c b/drivers/staging/ccree/ssi_hash.c
index 6bc42e4..a80279e 100644
--- a/drivers/staging/ccree/ssi_hash.c
+++ b/drivers/staging/ccree/ssi_hash.c
@@ -64,10 +64,8 @@ static const u64 sha512_init[] = {
SHA512_H3, SHA512_H2, SHA512_H1, SHA512_H0 };
 #endif
 
-static void cc_setup_xcbc(
-   struct ahash_request *areq,
-   struct cc_hw_desc desc[],
-   unsigned int *seq_size);
+static void cc_setup_xcbc(struct ahash_request *areq, struct cc_hw_desc desc[],
+ unsigned int *seq_size);
 
 static void cc_setup_cmac(struct ahash_request *areq, struct cc_hw_desc desc[],
  unsigned int *seq_size);
@@ -106,12 +104,9 @@ struct cc_hash_ctx {
bool is_hmac;
 };
 
-static void cc_set_desc(
-   struct ahash_req_ctx *areq_ctx,
-   struct cc_hash_ctx *ctx,
-   unsigned int flow_mode, struct cc_hw_desc desc[],
-   bool is_not_last_data,
-   unsigned int *seq_size);
+static void cc_set_desc(struct ahash_req_ctx *areq_ctx, struct cc_hash_ctx 
*ctx,
+   unsigned int flow_mode, struct cc_hw_desc desc[],
+   bool is_not_last_data, unsigned int *seq_size);
 
 static void cc_set_endianity(u32 mode, struct cc_hw_desc *desc)
 {
@@ -1971,9 +1966,8 @@ static struct cc_hash_template driver_hash[] = {
 
 };
 
-static struct cc_hash_alg *
-cc_alloc_hash_alg(struct cc_hash_template *template, struct device *dev,
- bool keyed)
+static struct cc_hash_alg *cc_alloc_hash_alg(struct cc_hash_template *template,
+struct device *dev, bool keyed)
 {
struct cc_hash_alg *t_crypto_alg;
struct crypto_alg *alg;
-- 
2.7.4

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


[PATCH 04/24] staging: ccree: func params should follow func name

2017-12-12 Thread Gilad Ben-Yossef
Fix some call sites with func params not following func name in AEAD
code.

Signed-off-by: Gilad Ben-Yossef 
---
 drivers/staging/ccree/ssi_aead.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/ccree/ssi_aead.c b/drivers/staging/ccree/ssi_aead.c
index 408ea24..75a578e 100644
--- a/drivers/staging/ccree/ssi_aead.c
+++ b/drivers/staging/ccree/ssi_aead.c
@@ -1226,8 +1226,9 @@ static void cc_hmac_authenc(struct aead_request *req, 
struct cc_hw_desc desc[],
struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
struct aead_req_ctx *req_ctx = aead_request_ctx(req);
int direct = req_ctx->gen_ctx.op_type;
-   unsigned int data_flow_mode = cc_get_data_flow(
-   direct, ctx->flow_mode, req_ctx->is_single_pass);
+   unsigned int data_flow_mode =
+   cc_get_data_flow(direct, ctx->flow_mode,
+req_ctx->is_single_pass);
 
if (req_ctx->is_single_pass) {
/**
@@ -1278,8 +1279,9 @@ cc_xcbc_authenc(struct aead_request *req, struct 
cc_hw_desc desc[],
struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
struct aead_req_ctx *req_ctx = aead_request_ctx(req);
int direct = req_ctx->gen_ctx.op_type;
-   unsigned int data_flow_mode = cc_get_data_flow(
-   direct, ctx->flow_mode, req_ctx->is_single_pass);
+   unsigned int data_flow_mode =
+   cc_get_data_flow(direct, ctx->flow_mode,
+req_ctx->is_single_pass);
 
if (req_ctx->is_single_pass) {
/**
-- 
2.7.4

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


[PATCH 05/24] staging: ccree: shorten parameter name

2017-12-12 Thread Gilad Ben-Yossef
Shorten parameter name for better code readability

Signed-off-by: Gilad Ben-Yossef 
---
 drivers/staging/ccree/ssi_aead.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/ccree/ssi_aead.c b/drivers/staging/ccree/ssi_aead.c
index 75a578e..62d45e9 100644
--- a/drivers/staging/ccree/ssi_aead.c
+++ b/drivers/staging/ccree/ssi_aead.c
@@ -2687,7 +2687,7 @@ static struct ssi_alg_template aead_algs[] = {
 };
 
 static struct ssi_crypto_alg *cc_create_aead_alg(
-   struct ssi_alg_template *template,
+   struct ssi_alg_template *tmpl,
struct device *dev)
 {
struct ssi_crypto_alg *t_alg;
@@ -2697,26 +2697,26 @@ static struct ssi_crypto_alg *cc_create_aead_alg(
if (!t_alg)
return ERR_PTR(-ENOMEM);
 
-   alg = &template->template_aead;
+   alg = &tmpl->template_aead;
 
snprintf(alg->base.cra_name, CRYPTO_MAX_ALG_NAME, "%s",
-template->name);
+tmpl->name);
snprintf(alg->base.cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s",
-template->driver_name);
+tmpl->driver_name);
alg->base.cra_module = THIS_MODULE;
alg->base.cra_priority = SSI_CRA_PRIO;
 
alg->base.cra_ctxsize = sizeof(struct cc_aead_ctx);
alg->base.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_KERN_DRIVER_ONLY |
-template->type;
+tmpl->type;
alg->init = cc_aead_init;
alg->exit = cc_aead_exit;
 
t_alg->aead_alg = *alg;
 
-   t_alg->cipher_mode = template->cipher_mode;
-   t_alg->flow_mode = template->flow_mode;
-   t_alg->auth_mode = template->auth_mode;
+   t_alg->cipher_mode = tmpl->cipher_mode;
+   t_alg->flow_mode = tmpl->flow_mode;
+   t_alg->auth_mode = tmpl->auth_mode;
 
return t_alg;
 }
-- 
2.7.4

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


[PATCH 06/24] staging: ccree: fix func def and decl coding style

2017-12-12 Thread Gilad Ben-Yossef
Fix functions definition and declaration indentation according to
coding style guide lines for better code readability

Signed-off-by: Gilad Ben-Yossef 
---
 drivers/staging/ccree/ssi_aead.c   |   5 +-
 drivers/staging/ccree/ssi_buffer_mgr.c | 144 +
 drivers/staging/ccree/ssi_sram_mgr.h   |   7 +-
 3 files changed, 63 insertions(+), 93 deletions(-)

diff --git a/drivers/staging/ccree/ssi_aead.c b/drivers/staging/ccree/ssi_aead.c
index 62d45e9..112fba3 100644
--- a/drivers/staging/ccree/ssi_aead.c
+++ b/drivers/staging/ccree/ssi_aead.c
@@ -2686,9 +2686,8 @@ static struct ssi_alg_template aead_algs[] = {
 #endif /*SSI_CC_HAS_AES_GCM*/
 };
 
-static struct ssi_crypto_alg *cc_create_aead_alg(
-   struct ssi_alg_template *tmpl,
-   struct device *dev)
+static struct ssi_crypto_alg *cc_create_aead_alg(struct ssi_alg_template *tmpl,
+struct device *dev)
 {
struct ssi_crypto_alg *t_alg;
struct aead_alg *alg;
diff --git a/drivers/staging/ccree/ssi_buffer_mgr.c 
b/drivers/staging/ccree/ssi_buffer_mgr.c
index c5bc027..099d83d 100644
--- a/drivers/staging/ccree/ssi_buffer_mgr.c
+++ b/drivers/staging/ccree/ssi_buffer_mgr.c
@@ -100,9 +100,10 @@ static void cc_copy_mac(struct device *dev, struct 
aead_request *req,
  * @nbytes: [IN] Total SGL data bytes.
  * @lbytes: [OUT] Returns the amount of bytes at the last entry
  */
-static unsigned int cc_get_sgl_nents(
-   struct device *dev, struct scatterlist *sg_list,
-   unsigned int nbytes, u32 *lbytes, bool *is_chained)
+static unsigned int cc_get_sgl_nents(struct device *dev,
+struct scatterlist *sg_list,
+unsigned int nbytes, u32 *lbytes,
+bool *is_chained)
 {
unsigned int nents = 0;
 
@@ -155,10 +156,8 @@ void cc_zero_sgl(struct scatterlist *sgl, u32 data_len)
  * @end:
  * @direct:
  */
-void cc_copy_sg_portion(
-   struct device *dev, u8 *dest,
-   struct scatterlist *sg, u32 to_skip,
-   u32 end, enum ssi_sg_cpy_direct direct)
+void cc_copy_sg_portion(struct device *dev, u8 *dest, struct scatterlist *sg,
+   u32 to_skip, u32 end, enum ssi_sg_cpy_direct direct)
 {
u32 nents, lbytes;
 
@@ -167,9 +166,9 @@ void cc_copy_sg_portion(
   (direct == SSI_SG_TO_BUF));
 }
 
-static int cc_render_buff_to_mlli(
-   struct device *dev, dma_addr_t buff_dma, u32 buff_size,
-   u32 *curr_nents, u32 **mlli_entry_pp)
+static int cc_render_buff_to_mlli(struct device *dev, dma_addr_t buff_dma,
+ u32 buff_size, u32 *curr_nents,
+ u32 **mlli_entry_pp)
 {
u32 *mlli_entry_p = *mlli_entry_pp;
u32 new_nents;
@@ -203,10 +202,9 @@ static int cc_render_buff_to_mlli(
return 0;
 }
 
-static int cc_render_sg_to_mlli(
-   struct device *dev, struct scatterlist *sgl,
-   u32 sgl_data_len, u32 sgl_offset, u32 *curr_nents,
-   u32 **mlli_entry_pp)
+static int cc_render_sg_to_mlli(struct device *dev, struct scatterlist *sgl,
+   u32 sgl_data_len, u32 sgl_offset,
+   u32 *curr_nents, u32 **mlli_entry_pp)
 {
struct scatterlist *curr_sgl = sgl;
u32 *mlli_entry_p = *mlli_entry_pp;
@@ -231,10 +229,8 @@ static int cc_render_sg_to_mlli(
return 0;
 }
 
-static int cc_generate_mlli(
-   struct device *dev,
-   struct buffer_array *sg_data,
-   struct mlli_params *mlli_params)
+static int cc_generate_mlli(struct device *dev, struct buffer_array *sg_data,
+   struct mlli_params *mlli_params)
 {
u32 *mlli_p;
u32 total_nents = 0, prev_total_nents = 0;
@@ -292,10 +288,10 @@ static int cc_generate_mlli(
return rc;
 }
 
-static void cc_add_buffer_entry(
-   struct device *dev, struct buffer_array *sgl_data,
-   dma_addr_t buffer_dma, unsigned int buffer_len,
-   bool is_last_entry, u32 *mlli_nents)
+static void cc_add_buffer_entry(struct device *dev,
+   struct buffer_array *sgl_data,
+   dma_addr_t buffer_dma, unsigned int buffer_len,
+   bool is_last_entry, u32 *mlli_nents)
 {
unsigned int index = sgl_data->num_of_buffers;
 
@@ -313,15 +309,10 @@ static void cc_add_buffer_entry(
sgl_data->num_of_buffers++;
 }
 
-static void cc_add_sg_entry(
-   struct device *dev,
-   struct buffer_array *sgl_data,
-   unsigned int nents,
-   struct scatterlist *sgl,
-   unsigned int data_len,
-   unsigned int data_offset,
-   bool is_last_table,
-   u32 *mlli_nents)
+static void cc_add_sg_entry(struct device *dev, struct buffer_array *sgl_data,
+   unsigned int nents, struct scatterlist *sgl,
+  

[PATCH 07/24] staging: ccree: simplify expression with local var

2017-12-12 Thread Gilad Ben-Yossef
Simplify expression by using a local variable for better code
readability.

Signed-off-by: Gilad Ben-Yossef 
---
 drivers/staging/ccree/ssi_buffer_mgr.c | 22 ++
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/ccree/ssi_buffer_mgr.c 
b/drivers/staging/ccree/ssi_buffer_mgr.c
index 099d83d..490dd5a 100644
--- a/drivers/staging/ccree/ssi_buffer_mgr.c
+++ b/drivers/staging/ccree/ssi_buffer_mgr.c
@@ -917,6 +917,7 @@ static int cc_prepare_aead_data_mlli(struct ssi_drvdata 
*drvdata,
unsigned int authsize = areq_ctx->req_authsize;
int rc = 0, icv_nents;
struct device *dev = drvdata_to_dev(drvdata);
+   struct scatterlist *sg;
 
if (req->src == req->dst) {
/*INPLACE*/
@@ -955,12 +956,11 @@ static int cc_prepare_aead_data_mlli(struct ssi_drvdata 
*drvdata,
areq_ctx->mac_buf_dma_addr;
}
} else { /* Contig. ICV */
+   sg = &areq_ctx->src_sgl[areq_ctx->src.nents - 1];
/*Should hanlde if the sg is not contig.*/
-   areq_ctx->icv_dma_addr = sg_dma_address(
-   &areq_ctx->src_sgl[areq_ctx->src.nents - 1]) +
+   areq_ctx->icv_dma_addr = sg_dma_address(sg) +
(*src_last_bytes - authsize);
-   areq_ctx->icv_virt_addr = sg_virt(
-   &areq_ctx->src_sgl[areq_ctx->src.nents - 1]) +
+   areq_ctx->icv_virt_addr = sg_virt(sg) +
(*src_last_bytes - authsize);
}
 
@@ -993,12 +993,11 @@ static int cc_prepare_aead_data_mlli(struct ssi_drvdata 
*drvdata,
areq_ctx->icv_virt_addr = areq_ctx->backup_mac;
 
} else { /* Contig. ICV */
+   sg = &areq_ctx->src_sgl[areq_ctx->src.nents - 1];
/*Should hanlde if the sg is not contig.*/
-   areq_ctx->icv_dma_addr = sg_dma_address(
-   &areq_ctx->src_sgl[areq_ctx->src.nents - 1]) +
+   areq_ctx->icv_dma_addr = sg_dma_address(sg) +
(*src_last_bytes - authsize);
-   areq_ctx->icv_virt_addr = sg_virt(
-   &areq_ctx->src_sgl[areq_ctx->src.nents - 1]) +
+   areq_ctx->icv_virt_addr = sg_virt(sg) +
(*src_last_bytes - authsize);
}
 
@@ -1023,12 +1022,11 @@ static int cc_prepare_aead_data_mlli(struct ssi_drvdata 
*drvdata,
}
 
if (!areq_ctx->is_icv_fragmented) {
+   sg = &areq_ctx->dst_sgl[areq_ctx->dst.nents - 1];
/* Contig. ICV */
-   areq_ctx->icv_dma_addr = sg_dma_address(
-   &areq_ctx->dst_sgl[areq_ctx->dst.nents - 1]) +
+   areq_ctx->icv_dma_addr = sg_dma_address(sg) +
(*dst_last_bytes - authsize);
-   areq_ctx->icv_virt_addr = sg_virt(
-   &areq_ctx->dst_sgl[areq_ctx->dst.nents - 1]) +
+   areq_ctx->icv_virt_addr = sg_virt(sg) +
(*dst_last_bytes - authsize);
} else {
areq_ctx->icv_dma_addr = areq_ctx->mac_buf_dma_addr;
-- 
2.7.4

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


[PATCH 09/24] staging: ccree: fix reg mgr naming convention

2017-12-12 Thread Gilad Ben-Yossef
The request manager files were using a func naming convention which was
inconsistent (ssi vs. cc), included a useless prefix (ssi_request_mgr)
and often too long.

Make the code more readable by switching to a simpler, consistent naming
convention.

Signed-off-by: Gilad Ben-Yossef 
---
 drivers/staging/ccree/ssi_driver.c  |  8 +++
 drivers/staging/ccree/ssi_request_mgr.c | 40 -
 drivers/staging/ccree/ssi_request_mgr.h |  4 ++--
 3 files changed, 25 insertions(+), 27 deletions(-)

diff --git a/drivers/staging/ccree/ssi_driver.c 
b/drivers/staging/ccree/ssi_driver.c
index 513c5e4..491e2b9 100644
--- a/drivers/staging/ccree/ssi_driver.c
+++ b/drivers/staging/ccree/ssi_driver.c
@@ -326,9 +326,9 @@ static int init_cc_resources(struct platform_device 
*plat_dev)
goto post_sram_mgr_err;
}
 
-   rc = request_mgr_init(new_drvdata);
+   rc = cc_req_mgr_init(new_drvdata);
if (rc) {
-   dev_err(dev, "request_mgr_init failed\n");
+   dev_err(dev, "cc_req_mgr_init failed\n");
goto post_sram_mgr_err;
}
 
@@ -389,7 +389,7 @@ static int init_cc_resources(struct platform_device 
*plat_dev)
 post_buf_mgr_err:
 cc_buffer_mgr_fini(new_drvdata);
 post_req_mgr_err:
-   request_mgr_fini(new_drvdata);
+   cc_req_mgr_fini(new_drvdata);
 post_sram_mgr_err:
ssi_sram_mgr_fini(new_drvdata);
 post_fips_init_err:
@@ -422,7 +422,7 @@ static void cleanup_cc_resources(struct platform_device 
*plat_dev)
ssi_ivgen_fini(drvdata);
cc_pm_fini(drvdata);
cc_buffer_mgr_fini(drvdata);
-   request_mgr_fini(drvdata);
+   cc_req_mgr_fini(drvdata);
ssi_sram_mgr_fini(drvdata);
ssi_fips_fini(drvdata);
 #ifdef ENABLE_CC_SYSFS
diff --git a/drivers/staging/ccree/ssi_request_mgr.c 
b/drivers/staging/ccree/ssi_request_mgr.c
index 5f34336..dbdfd0c 100644
--- a/drivers/staging/ccree/ssi_request_mgr.c
+++ b/drivers/staging/ccree/ssi_request_mgr.c
@@ -33,7 +33,7 @@
 
 #define SSI_MAX_POLL_ITER  10
 
-struct ssi_request_mgr_handle {
+struct cc_req_mgr_handle {
/* Request manager resources */
unsigned int hw_queue_size; /* HW capability */
unsigned int min_free_hw_slots;
@@ -68,9 +68,9 @@ static void comp_handler(unsigned long devarg);
 static void comp_work_handler(struct work_struct *work);
 #endif
 
-void request_mgr_fini(struct ssi_drvdata *drvdata)
+void cc_req_mgr_fini(struct ssi_drvdata *drvdata)
 {
-   struct ssi_request_mgr_handle *req_mgr_h = drvdata->request_mgr_handle;
+   struct cc_req_mgr_handle *req_mgr_h = drvdata->request_mgr_handle;
struct device *dev = drvdata_to_dev(drvdata);
 
if (!req_mgr_h)
@@ -92,14 +92,14 @@ void request_mgr_fini(struct ssi_drvdata *drvdata)
/* Kill tasklet */
tasklet_kill(&req_mgr_h->comptask);
 #endif
-   memset(req_mgr_h, 0, sizeof(struct ssi_request_mgr_handle));
+   memset(req_mgr_h, 0, sizeof(struct cc_req_mgr_handle));
kfree(req_mgr_h);
drvdata->request_mgr_handle = NULL;
 }
 
-int request_mgr_init(struct ssi_drvdata *drvdata)
+int cc_req_mgr_init(struct ssi_drvdata *drvdata)
 {
-   struct ssi_request_mgr_handle *req_mgr_h;
+   struct cc_req_mgr_handle *req_mgr_h;
struct device *dev = drvdata_to_dev(drvdata);
int rc = 0;
 
@@ -161,7 +161,7 @@ int request_mgr_init(struct ssi_drvdata *drvdata)
return 0;
 
 req_mgr_init_err:
-   request_mgr_fini(drvdata);
+   cc_req_mgr_fini(drvdata);
return rc;
 }
 
@@ -202,9 +202,9 @@ static void request_mgr_complete(struct device *dev, void 
*dx_compl_h)
complete(this_compl);
 }
 
-static int request_mgr_queues_status_check(
+static int cc_queues_status(
struct ssi_drvdata *drvdata,
-   struct ssi_request_mgr_handle *req_mgr_h,
+   struct cc_req_mgr_handle *req_mgr_h,
unsigned int total_seq_len)
 {
unsigned long poll_queue;
@@ -264,7 +264,7 @@ int send_request(
struct cc_hw_desc *desc, unsigned int len, bool is_dout)
 {
void __iomem *cc_base = drvdata->cc_base;
-   struct ssi_request_mgr_handle *req_mgr_h = drvdata->request_mgr_handle;
+   struct cc_req_mgr_handle *req_mgr_h = drvdata->request_mgr_handle;
unsigned int used_sw_slots;
unsigned int iv_seq_len = 0;
unsigned int total_seq_len = len; /*initial sequence length*/
@@ -291,8 +291,7 @@ int send_request(
 * in case iv gen add the max size and in case of no dout add 1
 * for the internal completion descriptor
 */
-   rc = request_mgr_queues_status_check(drvdata, req_mgr_h,
-max_required_seq_len);
+   rc = cc_queues_status(drvdata, req_mgr_h, max_required_seq_len);
if (rc == 0)
/* There is enough place in the queue */
 

[PATCH 08/24] staging: ccree: fix func call param indentation

2017-12-12 Thread Gilad Ben-Yossef
Fix function call parameter indentation according to coding
style guide lines.

Signed-off-by: Gilad Ben-Yossef 
---
 drivers/staging/ccree/ssi_buffer_mgr.c | 28 +++-
 drivers/staging/ccree/ssi_hash.c   | 10 --
 2 files changed, 15 insertions(+), 23 deletions(-)

diff --git a/drivers/staging/ccree/ssi_buffer_mgr.c 
b/drivers/staging/ccree/ssi_buffer_mgr.c
index 490dd5a..4ab76dc 100644
--- a/drivers/staging/ccree/ssi_buffer_mgr.c
+++ b/drivers/staging/ccree/ssi_buffer_mgr.c
@@ -239,9 +239,9 @@ static int cc_generate_mlli(struct device *dev, struct 
buffer_array *sg_data,
dev_dbg(dev, "NUM of SG's = %d\n", sg_data->num_of_buffers);
 
/* Allocate memory from the pointed pool */
-   mlli_params->mlli_virt_addr = dma_pool_alloc(
-   mlli_params->curr_pool, GFP_KERNEL,
-   &mlli_params->mlli_dma_addr);
+   mlli_params->mlli_virt_addr =
+   dma_pool_alloc(mlli_params->curr_pool, GFP_KERNEL,
+  &mlli_params->mlli_dma_addr);
if (!mlli_params->mlli_virt_addr) {
dev_err(dev, "dma_pool_alloc() failed\n");
rc = -ENOMEM;
@@ -881,27 +881,21 @@ static void cc_prepare_aead_data_dlli(struct aead_request 
*req,
areq_ctx->is_icv_fragmented = false;
if (req->src == req->dst) {
/*INPLACE*/
-   areq_ctx->icv_dma_addr = sg_dma_address(
-   areq_ctx->src_sgl) +
+   areq_ctx->icv_dma_addr = sg_dma_address(areq_ctx->src_sgl) +
(*src_last_bytes - authsize);
-   areq_ctx->icv_virt_addr = sg_virt(
-   areq_ctx->src_sgl) +
+   areq_ctx->icv_virt_addr = sg_virt(areq_ctx->src_sgl) +
(*src_last_bytes - authsize);
} else if (direct == DRV_CRYPTO_DIRECTION_DECRYPT) {
/*NON-INPLACE and DECRYPT*/
-   areq_ctx->icv_dma_addr = sg_dma_address(
-   areq_ctx->src_sgl) +
+   areq_ctx->icv_dma_addr = sg_dma_address(areq_ctx->src_sgl) +
(*src_last_bytes - authsize);
-   areq_ctx->icv_virt_addr = sg_virt(
-   areq_ctx->src_sgl) +
+   areq_ctx->icv_virt_addr = sg_virt(areq_ctx->src_sgl) +
(*src_last_bytes - authsize);
} else {
/*NON-INPLACE and ENCRYPT*/
-   areq_ctx->icv_dma_addr = sg_dma_address(
-   areq_ctx->dst_sgl) +
+   areq_ctx->icv_dma_addr = sg_dma_address(areq_ctx->dst_sgl) +
(*dst_last_bytes - authsize);
-   areq_ctx->icv_virt_addr = sg_virt(
-   areq_ctx->dst_sgl) +
+   areq_ctx->icv_virt_addr = sg_virt(areq_ctx->dst_sgl) +
(*dst_last_bytes - authsize);
}
 }
@@ -1660,8 +1654,8 @@ int cc_buffer_mgr_init(struct ssi_drvdata *drvdata)
 
drvdata->buff_mgr_handle = buff_mgr_handle;
 
-   buff_mgr_handle->mlli_buffs_pool = dma_pool_create(
-   "dx_single_mlli_tables", dev,
+   buff_mgr_handle->mlli_buffs_pool =
+   dma_pool_create("dx_single_mlli_tables", dev,
MAX_NUM_OF_TOTAL_MLLI_ENTRIES *
LLI_ENTRY_BYTE_SIZE,
MLLI_TABLE_MIN_ALIGNMENT, 0);
diff --git a/drivers/staging/ccree/ssi_hash.c b/drivers/staging/ccree/ssi_hash.c
index a80279e..29c17f3 100644
--- a/drivers/staging/ccree/ssi_hash.c
+++ b/drivers/staging/ccree/ssi_hash.c
@@ -951,9 +951,8 @@ static int cc_hash_setkey(struct crypto_ahash *ahash, const 
u8 *key,
ctx->is_hmac = true;
 
if (keylen) {
-   ctx->key_params.key_dma_addr = dma_map_single(
-   dev, (void *)key,
-   keylen, DMA_TO_DEVICE);
+   ctx->key_params.key_dma_addr =
+   dma_map_single(dev, (void *)key, keylen, DMA_TO_DEVICE);
if (dma_mapping_error(dev, ctx->key_params.key_dma_addr)) {
dev_err(dev, "Mapping key va=0x%p len=%u for DMA 
failed\n",
key, keylen);
@@ -1132,9 +1131,8 @@ static int cc_xcbc_setkey(struct crypto_ahash *ahash,
 
ctx->key_params.keylen = keylen;
 
-   ctx->key_params.key_dma_addr = dma_map_single(
-   dev, (void *)key,
-   keylen, DMA_TO_DEVICE);
+   ctx->key_params.key_dma_addr =
+   dma_map_single(dev, (void *)key, keylen, DMA_TO_DEVICE);
if (dma_mapping_error(dev, ctx->key_params.key_dma_addr)) {
dev_err(dev, "Mapping key va=0x%p len=%u for DMA failed\n",
key, keylen);
-- 
2.7.4

___
deve

[PATCH 11/24] staging: ccree: remove cipher sync blkcipher remains

2017-12-12 Thread Gilad Ben-Yossef
Remove the remains of no longer existing support for running
blkcipher is sync mode.

Signed-off-by: Gilad Ben-Yossef 
---
 drivers/staging/ccree/ssi_cipher.c | 156 -
 1 file changed, 51 insertions(+), 105 deletions(-)

diff --git a/drivers/staging/ccree/ssi_cipher.c 
b/drivers/staging/ccree/ssi_cipher.c
index 7b484f1..0dc63f1 100644
--- a/drivers/staging/ccree/ssi_cipher.c
+++ b/drivers/staging/ccree/ssi_cipher.c
@@ -180,7 +180,7 @@ static unsigned int get_max_keysize(struct crypto_tfm *tfm)
return 0;
 }
 
-static int ssi_blkcipher_init(struct crypto_tfm *tfm)
+static int ssi_ablkcipher_init(struct crypto_tfm *tfm)
 {
struct ssi_ablkcipher_ctx *ctx_p = crypto_tfm_ctx(tfm);
struct crypto_alg *alg = tfm->__crt_alg;
@@ -189,10 +189,13 @@ static int ssi_blkcipher_init(struct crypto_tfm *tfm)
struct device *dev = drvdata_to_dev(ssi_alg->drvdata);
int rc = 0;
unsigned int max_key_buf_size = get_max_keysize(tfm);
+   struct ablkcipher_tfm *ablktfm = &tfm->crt_ablkcipher;
 
dev_dbg(dev, "Initializing context @%p for %s\n", ctx_p,
crypto_tfm_alg_name(tfm));
 
+   ablktfm->reqsize = sizeof(struct blkcipher_req_ctx);
+
ctx_p->cipher_mode = ssi_alg->cipher_mode;
ctx_p->flow_mode = ssi_alg->flow_mode;
ctx_p->drvdata = ssi_alg->drvdata;
@@ -297,10 +300,10 @@ static enum cc_hw_crypto_key hw_key_to_cc_hw_key(int 
slot_num)
return END_OF_KEYS;
 }
 
-static int ssi_blkcipher_setkey(struct crypto_tfm *tfm,
-   const u8 *key,
+static int ssi_ablkcipher_setkey(struct crypto_ablkcipher *atfm, const u8 *key,
unsigned int keylen)
 {
+   struct crypto_tfm *tfm = crypto_ablkcipher_tfm(atfm);
struct ssi_ablkcipher_ctx *ctx_p = crypto_tfm_ctx(tfm);
struct device *dev = drvdata_to_dev(ctx_p->drvdata);
u32 tmp[DES_EXPKEY_WORDS];
@@ -700,62 +703,59 @@ ssi_blkcipher_create_data_desc(
}
 }
 
-static int ssi_blkcipher_complete(struct device *dev,
- struct ssi_ablkcipher_ctx *ctx_p,
- struct blkcipher_req_ctx *req_ctx,
- struct scatterlist *dst,
- struct scatterlist *src,
- unsigned int ivsize,
- void *areq)
+static void ssi_ablkcipher_complete(struct device *dev, void *ssi_req)
 {
+   struct ablkcipher_request *areq = (struct ablkcipher_request *)ssi_req;
+   struct scatterlist *dst = areq->dst;
+   struct scatterlist *src = areq->src;
+   struct blkcipher_req_ctx *req_ctx = ablkcipher_request_ctx(areq);
+   struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(areq);
+   unsigned int ivsize = crypto_ablkcipher_ivsize(tfm);
int completion_error = 0;
struct ablkcipher_request *req = (struct ablkcipher_request *)areq;
 
cc_unmap_blkcipher_request(dev, req_ctx, ivsize, src, dst);
kfree(req_ctx->iv);
 
-   if (areq) {
-   /*
-* The crypto API expects us to set the req->info to the last
-* ciphertext block. For encrypt, simply copy from the result.
-* For decrypt, we must copy from a saved buffer since this
-* could be an in-place decryption operation and the src is
-* lost by this point.
-*/
-   if (req_ctx->gen_ctx.op_type == DRV_CRYPTO_DIRECTION_DECRYPT)  {
-   memcpy(req->info, req_ctx->backup_info, ivsize);
-   kfree(req_ctx->backup_info);
-   } else {
-   scatterwalk_map_and_copy(req->info, req->dst,
-(req->nbytes - ivsize),
-ivsize, 0);
-   }
-
-   ablkcipher_request_complete(areq, completion_error);
-   return 0;
+   /*
+* The crypto API expects us to set the req->info to the last
+* ciphertext block. For encrypt, simply copy from the result.
+* For decrypt, we must copy from a saved buffer since this
+* could be an in-place decryption operation and the src is
+* lost by this point.
+*/
+   if (req_ctx->gen_ctx.op_type == DRV_CRYPTO_DIRECTION_DECRYPT)  {
+   memcpy(req->info, req_ctx->backup_info, ivsize);
+   kfree(req_ctx->backup_info);
+   } else {
+   scatterwalk_map_and_copy(req->info, req->dst,
+(req->nbytes - ivsize),
+ivsize, 0);
}
-   return completion_error;
+
+   ablkcipher_request_complete(areq, completion_error);
 }
 
-static int ssi_blkcipher_process(
-   struct crypto_tfm *tfm,
-   struct blkcipher_req_ctx *req_ctx,
-

[PATCH 13/24] staging: ccree: fix cipher func def coding style

2017-12-12 Thread Gilad Ben-Yossef
Fix cipher functions definition indentation according to coding
style guide lines for better code readability

Signed-off-by: Gilad Ben-Yossef 
---
 drivers/staging/ccree/ssi_cipher.c | 38 +++---
 1 file changed, 15 insertions(+), 23 deletions(-)

diff --git a/drivers/staging/ccree/ssi_cipher.c 
b/drivers/staging/ccree/ssi_cipher.c
index d7687a4..0b464d8 100644
--- a/drivers/staging/ccree/ssi_cipher.c
+++ b/drivers/staging/ccree/ssi_cipher.c
@@ -435,14 +435,11 @@ static int cc_cipher_setkey(struct crypto_ablkcipher 
*atfm, const u8 *key,
return 0;
 }
 
-static void
-cc_setup_cipher_desc(
-   struct crypto_tfm *tfm,
-   struct blkcipher_req_ctx *req_ctx,
-   unsigned int ivsize,
-   unsigned int nbytes,
-   struct cc_hw_desc desc[],
-   unsigned int *seq_size)
+static void cc_setup_cipher_desc(struct crypto_tfm *tfm,
+struct blkcipher_req_ctx *req_ctx,
+unsigned int ivsize, unsigned int nbytes,
+struct cc_hw_desc desc[],
+unsigned int *seq_size)
 {
struct cc_cipher_ctx *ctx_p = crypto_tfm_ctx(tfm);
struct device *dev = drvdata_to_dev(ctx_p->drvdata);
@@ -565,12 +562,10 @@ cc_setup_cipher_desc(
 }
 
 #if SSI_CC_HAS_MULTI2
-static void cc_setup_multi2_desc(
-   struct crypto_tfm *tfm,
-   struct blkcipher_req_ctx *req_ctx,
-   unsigned int ivsize,
-   struct cc_hw_desc desc[],
-   unsigned int *seq_size)
+static void cc_setup_multi2_desc(struct crypto_tfm *tfm,
+struct blkcipher_req_ctx *req_ctx,
+unsigned int ivsize, struct cc_hw_desc desc[],
+unsigned int *seq_size)
 {
struct cc_cipher_ctx *ctx_p = crypto_tfm_ctx(tfm);
 
@@ -609,15 +604,12 @@ static void cc_setup_multi2_desc(
 }
 #endif /*SSI_CC_HAS_MULTI2*/
 
-static void
-cc_setup_cipher_data(
-   struct crypto_tfm *tfm,
-   struct blkcipher_req_ctx *req_ctx,
-   struct scatterlist *dst, struct scatterlist *src,
-   unsigned int nbytes,
-   void *areq,
-   struct cc_hw_desc desc[],
-   unsigned int *seq_size)
+static void cc_setup_cipher_data(struct crypto_tfm *tfm,
+struct blkcipher_req_ctx *req_ctx,
+struct scatterlist *dst,
+struct scatterlist *src, unsigned int nbytes,
+void *areq, struct cc_hw_desc desc[],
+unsigned int *seq_size)
 {
struct cc_cipher_ctx *ctx_p = crypto_tfm_ctx(tfm);
struct device *dev = drvdata_to_dev(ctx_p->drvdata);
-- 
2.7.4

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


[PATCH 14/24] staging: ccree: fix ivgen naming convention

2017-12-12 Thread Gilad Ben-Yossef
The ivgen files were using a func naming convention which was
inconsistent (ssi vs. cc), included a long prefix (ssi_ivgen)
and often too long.

Make the code more readable by switching to a simpler, consistent naming
convention.

Signed-off-by: Gilad Ben-Yossef 
---
 drivers/staging/ccree/ssi_driver.c  |  8 ++--
 drivers/staging/ccree/ssi_ivgen.c   | 66 -
 drivers/staging/ccree/ssi_ivgen.h   |  8 ++--
 drivers/staging/ccree/ssi_pm.c  |  2 +-
 drivers/staging/ccree/ssi_request_mgr.c |  7 ++--
 5 files changed, 46 insertions(+), 45 deletions(-)

diff --git a/drivers/staging/ccree/ssi_driver.c 
b/drivers/staging/ccree/ssi_driver.c
index 2a0dd85..f4164eb 100644
--- a/drivers/staging/ccree/ssi_driver.c
+++ b/drivers/staging/ccree/ssi_driver.c
@@ -344,9 +344,9 @@ static int init_cc_resources(struct platform_device 
*plat_dev)
goto post_buf_mgr_err;
}
 
-   rc = ssi_ivgen_init(new_drvdata);
+   rc = cc_ivgen_init(new_drvdata);
if (rc) {
-   dev_err(dev, "ssi_ivgen_init failed\n");
+   dev_err(dev, "cc_ivgen_init failed\n");
goto post_power_mgr_err;
}
 
@@ -383,7 +383,7 @@ static int init_cc_resources(struct platform_device 
*plat_dev)
 post_cipher_err:
cc_cipher_free(new_drvdata);
 post_ivgen_err:
-   ssi_ivgen_fini(new_drvdata);
+   cc_ivgen_fini(new_drvdata);
 post_power_mgr_err:
cc_pm_fini(new_drvdata);
 post_buf_mgr_err:
@@ -419,7 +419,7 @@ static void cleanup_cc_resources(struct platform_device 
*plat_dev)
cc_aead_free(drvdata);
cc_hash_free(drvdata);
cc_cipher_free(drvdata);
-   ssi_ivgen_fini(drvdata);
+   cc_ivgen_fini(drvdata);
cc_pm_fini(drvdata);
cc_buffer_mgr_fini(drvdata);
cc_req_mgr_fini(drvdata);
diff --git a/drivers/staging/ccree/ssi_ivgen.c 
b/drivers/staging/ccree/ssi_ivgen.c
index febee22..ad6cd97 100644
--- a/drivers/staging/ccree/ssi_ivgen.c
+++ b/drivers/staging/ccree/ssi_ivgen.c
@@ -24,15 +24,15 @@
 #include "ssi_buffer_mgr.h"
 
 /* The max. size of pool *MUST* be <= SRAM total size */
-#define SSI_IVPOOL_SIZE 1024
+#define CC_IVPOOL_SIZE 1024
 /* The first 32B fraction of pool are dedicated to the
  * next encryption "key" & "IV" for pool regeneration
  */
-#define SSI_IVPOOL_META_SIZE (CC_AES_IV_SIZE + AES_KEYSIZE_128)
-#define SSI_IVPOOL_GEN_SEQ_LEN 4
+#define CC_IVPOOL_META_SIZE (CC_AES_IV_SIZE + AES_KEYSIZE_128)
+#define CC_IVPOOL_GEN_SEQ_LEN  4
 
 /**
- * struct ssi_ivgen_ctx -IV pool generation context
+ * struct cc_ivgen_ctx -IV pool generation context
  * @pool:  the start address of the iv-pool resides in internal RAM
  * @ctr_key_dma:   address of pool's encryption key material in internal RAM
  * @ctr_iv_dma:address of pool's counter iv in internal RAM
@@ -40,7 +40,7 @@
  * @pool_meta: virt. address of the initial enc. key/IV
  * @pool_meta_dma: phys. address of the initial enc. key/IV
  */
-struct ssi_ivgen_ctx {
+struct cc_ivgen_ctx {
ssi_sram_addr_t pool;
ssi_sram_addr_t ctr_key;
ssi_sram_addr_t ctr_iv;
@@ -50,21 +50,21 @@ struct ssi_ivgen_ctx {
 };
 
 /*!
- * Generates SSI_IVPOOL_SIZE of random bytes by
+ * Generates CC_IVPOOL_SIZE of random bytes by
  * encrypting 0's using AES128-CTR.
  *
  * \param ivgen iv-pool context
  * \param iv_seq IN/OUT array to the descriptors sequence
  * \param iv_seq_len IN/OUT pointer to the sequence length
  */
-static int ssi_ivgen_generate_pool(
-   struct ssi_ivgen_ctx *ivgen_ctx,
+static int cc_gen_iv_pool(
+   struct cc_ivgen_ctx *ivgen_ctx,
struct cc_hw_desc iv_seq[],
unsigned int *iv_seq_len)
 {
unsigned int idx = *iv_seq_len;
 
-   if ((*iv_seq_len + SSI_IVPOOL_GEN_SEQ_LEN) > SSI_IVPOOL_SEQ_LEN) {
+   if ((*iv_seq_len + CC_IVPOOL_GEN_SEQ_LEN) > SSI_IVPOOL_SEQ_LEN) {
/* The sequence will be longer than allowed */
return -EINVAL;
}
@@ -97,15 +97,15 @@ static int ssi_ivgen_generate_pool(
 
/* Generate IV pool */
hw_desc_init(&iv_seq[idx]);
-   set_din_const(&iv_seq[idx], 0, SSI_IVPOOL_SIZE);
-   set_dout_sram(&iv_seq[idx], ivgen_ctx->pool, SSI_IVPOOL_SIZE);
+   set_din_const(&iv_seq[idx], 0, CC_IVPOOL_SIZE);
+   set_dout_sram(&iv_seq[idx], ivgen_ctx->pool, CC_IVPOOL_SIZE);
set_flow_mode(&iv_seq[idx], DIN_AES_DOUT);
idx++;
 
*iv_seq_len = idx; /* Update sequence length */
 
/* queue ordering assures pool readiness */
-   ivgen_ctx->next_iv_ofs = SSI_IVPOOL_META_SIZE;
+   ivgen_ctx->next_iv_ofs = CC_IVPOOL_META_SIZE;
 
return 0;
 }
@@ -118,15 +118,15 @@ static int ssi_ivgen_generate_pool(
  *
  * \return int Zero for success, negative value otherwise.
  */
-int ssi_ivgen_init_sram_pool(struct ssi_drvdata *drvdata)
+int cc_init_iv_sram(struct ssi_drvdata *drvdata)
 {
-   struct ssi_ivgen_ctx *ivgen_ctx = drvdata->ivgen_han

[PATCH 10/24] staging: ccree: fix req mgr func def coding style

2017-12-12 Thread Gilad Ben-Yossef
Fix request manager functions definition indentation according to coding
style guide lines for better code readability

Signed-off-by: Gilad Ben-Yossef 
---
 drivers/staging/ccree/ssi_request_mgr.c | 21 +
 drivers/staging/ccree/ssi_request_mgr.h |  9 -
 2 files changed, 13 insertions(+), 17 deletions(-)

diff --git a/drivers/staging/ccree/ssi_request_mgr.c 
b/drivers/staging/ccree/ssi_request_mgr.c
index dbdfd0c..91f5e2d 100644
--- a/drivers/staging/ccree/ssi_request_mgr.c
+++ b/drivers/staging/ccree/ssi_request_mgr.c
@@ -165,9 +165,8 @@ int cc_req_mgr_init(struct ssi_drvdata *drvdata)
return rc;
 }
 
-static void enqueue_seq(
-   void __iomem *cc_base,
-   struct cc_hw_desc seq[], unsigned int seq_len)
+static void enqueue_seq(void __iomem *cc_base, struct cc_hw_desc seq[],
+   unsigned int seq_len)
 {
int i, w;
void * __iomem reg = cc_base + CC_REG(DSCRPTR_QUEUE_WORD0);
@@ -202,10 +201,9 @@ static void request_mgr_complete(struct device *dev, void 
*dx_compl_h)
complete(this_compl);
 }
 
-static int cc_queues_status(
-   struct ssi_drvdata *drvdata,
-   struct cc_req_mgr_handle *req_mgr_h,
-   unsigned int total_seq_len)
+static int cc_queues_status(struct ssi_drvdata *drvdata,
+   struct cc_req_mgr_handle *req_mgr_h,
+   unsigned int total_seq_len)
 {
unsigned long poll_queue;
struct device *dev = drvdata_to_dev(drvdata);
@@ -259,9 +257,8 @@ static int cc_queues_status(
  *
  * \return int Returns -EINPROGRESS if "is_dout=true"; "0" if "is_dout=false"
  */
-int send_request(
-   struct ssi_drvdata *drvdata, struct ssi_crypto_req *ssi_req,
-   struct cc_hw_desc *desc, unsigned int len, bool is_dout)
+int send_request(struct ssi_drvdata *drvdata, struct ssi_crypto_req *ssi_req,
+struct cc_hw_desc *desc, unsigned int len, bool is_dout)
 {
void __iomem *cc_base = drvdata->cc_base;
struct cc_req_mgr_handle *req_mgr_h = drvdata->request_mgr_handle;
@@ -413,8 +410,8 @@ int send_request(
  *
  * \return int Returns "0" upon success
  */
-int send_request_init(
-   struct ssi_drvdata *drvdata, struct cc_hw_desc *desc, unsigned int len)
+int send_request_init(struct ssi_drvdata *drvdata, struct cc_hw_desc *desc,
+ unsigned int len)
 {
void __iomem *cc_base = drvdata->cc_base;
struct cc_req_mgr_handle *req_mgr_h = drvdata->request_mgr_handle;
diff --git a/drivers/staging/ccree/ssi_request_mgr.h 
b/drivers/staging/ccree/ssi_request_mgr.h
index d018f51..91e0d47 100644
--- a/drivers/staging/ccree/ssi_request_mgr.h
+++ b/drivers/staging/ccree/ssi_request_mgr.h
@@ -38,12 +38,11 @@ int cc_req_mgr_init(struct ssi_drvdata *drvdata);
  *
  * \return int Returns -EINPROGRESS if "is_dout=true"; "0" if "is_dout=false"
  */
-int send_request(
-   struct ssi_drvdata *drvdata, struct ssi_crypto_req *ssi_req,
-   struct cc_hw_desc *desc, unsigned int len, bool is_dout);
+int send_request(struct ssi_drvdata *drvdata, struct ssi_crypto_req *ssi_req,
+struct cc_hw_desc *desc, unsigned int len, bool is_dout);
 
-int send_request_init(
-   struct ssi_drvdata *drvdata, struct cc_hw_desc *desc, unsigned int len);
+int send_request_init(struct ssi_drvdata *drvdata, struct cc_hw_desc *desc,
+ unsigned int len);
 
 void complete_request(struct ssi_drvdata *drvdata);
 
-- 
2.7.4

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


[PATCH 12/24] staging: ccree: fix cipher naming convention

2017-12-12 Thread Gilad Ben-Yossef
The blkcipher files were using a func naming convention which was
inconsistent (ssi vs. cc), included a long prefix (ssi_ablkcipher)
and often too long.

Make the code more readable by switching to a simpler, consistent naming
convention.

Signed-off-by: Gilad Ben-Yossef 
---
 drivers/staging/ccree/ssi_cipher.c | 221 ++---
 drivers/staging/ccree/ssi_cipher.h |   8 +-
 drivers/staging/ccree/ssi_driver.c |   8 +-
 3 files changed, 118 insertions(+), 119 deletions(-)

diff --git a/drivers/staging/ccree/ssi_cipher.c 
b/drivers/staging/ccree/ssi_cipher.c
index 0dc63f1..d7687a4 100644
--- a/drivers/staging/ccree/ssi_cipher.c
+++ b/drivers/staging/ccree/ssi_cipher.c
@@ -38,9 +38,9 @@
 
 #define template_ablkciphertemplate_u.ablkcipher
 
-#define SSI_MIN_AES_XTS_SIZE 0x10
-#define SSI_MAX_AES_XTS_SIZE 0x2000
-struct ssi_blkcipher_handle {
+#define CC_MIN_AES_XTS_SIZE 0x10
+#define CC_MAX_AES_XTS_SIZE 0x2000
+struct cc_cipher_handle {
struct list_head blkcipher_alg_list;
 };
 
@@ -54,7 +54,7 @@ struct cc_hw_key_info {
enum cc_hw_crypto_key key2_slot;
 };
 
-struct ssi_ablkcipher_ctx {
+struct cc_cipher_ctx {
struct ssi_drvdata *drvdata;
int keylen;
int key_round_number;
@@ -67,9 +67,9 @@ struct ssi_ablkcipher_ctx {
struct crypto_shash *shash_tfm;
 };
 
-static void ssi_ablkcipher_complete(struct device *dev, void *ssi_req);
+static void cc_cipher_complete(struct device *dev, void *ssi_req);
 
-static int validate_keys_sizes(struct ssi_ablkcipher_ctx *ctx_p, u32 size)
+static int validate_keys_sizes(struct cc_cipher_ctx *ctx_p, u32 size)
 {
switch (ctx_p->flow_mode) {
case S_DIN_to_AES:
@@ -109,15 +109,15 @@ static int validate_keys_sizes(struct ssi_ablkcipher_ctx 
*ctx_p, u32 size)
return -EINVAL;
 }
 
-static int validate_data_size(struct ssi_ablkcipher_ctx *ctx_p,
+static int validate_data_size(struct cc_cipher_ctx *ctx_p,
  unsigned int size)
 {
switch (ctx_p->flow_mode) {
case S_DIN_to_AES:
switch (ctx_p->cipher_mode) {
case DRV_CIPHER_XTS:
-   if (size >= SSI_MIN_AES_XTS_SIZE &&
-   size <= SSI_MAX_AES_XTS_SIZE &&
+   if (size >= CC_MIN_AES_XTS_SIZE &&
+   size <= CC_MAX_AES_XTS_SIZE &&
IS_ALIGNED(size, AES_BLOCK_SIZE))
return 0;
break;
@@ -180,9 +180,9 @@ static unsigned int get_max_keysize(struct crypto_tfm *tfm)
return 0;
 }
 
-static int ssi_ablkcipher_init(struct crypto_tfm *tfm)
+static int cc_cipher_init(struct crypto_tfm *tfm)
 {
-   struct ssi_ablkcipher_ctx *ctx_p = crypto_tfm_ctx(tfm);
+   struct cc_cipher_ctx *ctx_p = crypto_tfm_ctx(tfm);
struct crypto_alg *alg = tfm->__crt_alg;
struct ssi_crypto_alg *ssi_alg =
container_of(alg, struct ssi_crypto_alg, crypto_alg);
@@ -232,9 +232,9 @@ static int ssi_ablkcipher_init(struct crypto_tfm *tfm)
return rc;
 }
 
-static void ssi_blkcipher_exit(struct crypto_tfm *tfm)
+static void cc_cipher_exit(struct crypto_tfm *tfm)
 {
-   struct ssi_ablkcipher_ctx *ctx_p = crypto_tfm_ctx(tfm);
+   struct cc_cipher_ctx *ctx_p = crypto_tfm_ctx(tfm);
struct device *dev = drvdata_to_dev(ctx_p->drvdata);
unsigned int max_key_buf_size = get_max_keysize(tfm);
 
@@ -270,7 +270,7 @@ static const u8 zero_buff[] = { 0x0, 0x0, 0x0, 0x0, 
0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
 
 /* The function verifies that tdes keys are not weak.*/
-static int ssi_verify_3des_keys(const u8 *key, unsigned int keylen)
+static int cc_verify_3des_keys(const u8 *key, unsigned int keylen)
 {
struct tdes_keys *tdes_key = (struct tdes_keys *)key;
 
@@ -300,11 +300,11 @@ static enum cc_hw_crypto_key hw_key_to_cc_hw_key(int 
slot_num)
return END_OF_KEYS;
 }
 
-static int ssi_ablkcipher_setkey(struct crypto_ablkcipher *atfm, const u8 *key,
-   unsigned int keylen)
+static int cc_cipher_setkey(struct crypto_ablkcipher *atfm, const u8 *key,
+   unsigned int keylen)
 {
struct crypto_tfm *tfm = crypto_ablkcipher_tfm(atfm);
-   struct ssi_ablkcipher_ctx *ctx_p = crypto_tfm_ctx(tfm);
+   struct cc_cipher_ctx *ctx_p = crypto_tfm_ctx(tfm);
struct device *dev = drvdata_to_dev(ctx_p->drvdata);
u32 tmp[DES_EXPKEY_WORDS];
unsigned int max_key_buf_size = get_max_keysize(tfm);
@@ -329,7 +329,7 @@ static int ssi_ablkcipher_setkey(struct crypto_ablkcipher 
*atfm, const u8 *key,
return -EINVAL;
}
 
-   if (ssi_is_hw_key(tfm)) {
+   if (cc_is_hw_key(tfm)) {
/* setting HW key slots */
struct arm_hw_key_info *hki = (struct arm_hw_key_info *)key;
 
@@ -363,7 +363,7 @@

[PATCH 16/24] staging: ccree: drop unsupported MULTI2 mode code

2017-12-12 Thread Gilad Ben-Yossef
Remove the code support for MULTI2 mode which is not supported
by the current hardware.

Signed-off-by: Gilad Ben-Yossef 
---
 drivers/staging/ccree/cc_crypto_ctx.h|  17 
 drivers/staging/ccree/cc_hw_queue_defs.h |   2 -
 drivers/staging/ccree/ssi_cipher.c   | 167 ---
 drivers/staging/ccree/ssi_driver.h   |   1 -
 4 files changed, 18 insertions(+), 169 deletions(-)

diff --git a/drivers/staging/ccree/cc_crypto_ctx.h 
b/drivers/staging/ccree/cc_crypto_ctx.h
index 591f6fd..0e34d9a 100644
--- a/drivers/staging/ccree/cc_crypto_ctx.h
+++ b/drivers/staging/ccree/cc_crypto_ctx.h
@@ -82,15 +82,6 @@
 
 #define CC_HMAC_BLOCK_SIZE_MAX CC_HASH_BLOCK_SIZE_MAX
 
-#define CC_MULTI2_SYSTEM_KEY_SIZE  32
-#define CC_MULTI2_DATA_KEY_SIZE8
-#define CC_MULTI2_SYSTEM_N_DATA_KEY_SIZE \
-   (CC_MULTI2_SYSTEM_KEY_SIZE + CC_MULTI2_DATA_KEY_SIZE)
-#defineCC_MULTI2_BLOCK_SIZE8
-#defineCC_MULTI2_IV_SIZE   8
-#defineCC_MULTI2_MIN_NUM_ROUNDS8
-#defineCC_MULTI2_MAX_NUM_ROUNDS128
-
 #define CC_DRV_ALG_MAX_BLOCK_SIZE CC_HASH_BLOCK_SIZE_MAX
 
 enum drv_engine_type {
@@ -168,14 +159,6 @@ enum drv_hash_hw_mode {
DRV_HASH_HW_RESERVE32B = S32_MAX
 };
 
-enum drv_multi2_mode {
-   DRV_MULTI2_NULL = -1,
-   DRV_MULTI2_ECB = 0,
-   DRV_MULTI2_CBC = 1,
-   DRV_MULTI2_OFB = 2,
-   DRV_MULTI2_RESERVE32B = S32_MAX
-};
-
 /* drv_crypto_key_type[1:0] is mapped to cipher_do[1:0] */
 /* drv_crypto_key_type[2] is mapped to cipher_config2 */
 enum drv_crypto_key_type {
diff --git a/drivers/staging/ccree/cc_hw_queue_defs.h 
b/drivers/staging/ccree/cc_hw_queue_defs.h
index c5aaa79..3ca548d 100644
--- a/drivers/staging/ccree/cc_hw_queue_defs.h
+++ b/drivers/staging/ccree/cc_hw_queue_defs.h
@@ -120,7 +120,6 @@ enum cc_flow_mode {
AES_to_AES_to_HASH_and_DOUT = 13,
AES_to_AES_to_HASH  = 14,
AES_to_HASH_and_AES = 15,
-   DIN_MULTI2_DOUT = 16,
DIN_AES_AESMAC  = 17,
HASH_to_DOUT= 18,
/* setup flows */
@@ -128,7 +127,6 @@ enum cc_flow_mode {
S_DIN_to_AES2   = 33,
S_DIN_to_DES= 34,
S_DIN_to_RC4= 35,
-   S_DIN_to_MULTI2 = 36,
S_DIN_to_HASH   = 37,
S_AES_to_DOUT   = 38,
S_AES2_to_DOUT  = 39,
diff --git a/drivers/staging/ccree/ssi_cipher.c 
b/drivers/staging/ccree/ssi_cipher.c
index 0b464d8..a158213 100644
--- a/drivers/staging/ccree/ssi_cipher.c
+++ b/drivers/staging/ccree/ssi_cipher.c
@@ -97,12 +97,6 @@ static int validate_keys_sizes(struct cc_cipher_ctx *ctx_p, 
u32 size)
if (size == DES3_EDE_KEY_SIZE || size == DES_KEY_SIZE)
return 0;
break;
-#if SSI_CC_HAS_MULTI2
-   case S_DIN_to_MULTI2:
-   if (size == CC_MULTI2_SYSTEM_N_DATA_KEY_SIZE)
-   return 0;
-   break;
-#endif
default:
break;
}
@@ -143,20 +137,6 @@ static int validate_data_size(struct cc_cipher_ctx *ctx_p,
if (IS_ALIGNED(size, DES_BLOCK_SIZE))
return 0;
break;
-#if SSI_CC_HAS_MULTI2
-   case S_DIN_to_MULTI2:
-   switch (ctx_p->cipher_mode) {
-   case DRV_MULTI2_CBC:
-   if (IS_ALIGNED(size, CC_MULTI2_BLOCK_SIZE))
-   return 0;
-   break;
-   case DRV_MULTI2_OFB:
-   return 0;
-   default:
-   break;
-   }
-   break;
-#endif /*SSI_CC_HAS_MULTI2*/
default:
break;
}
@@ -315,14 +295,6 @@ static int cc_cipher_setkey(struct crypto_ablkcipher 
*atfm, const u8 *key,
 
/* STAT_PHASE_0: Init and sanity checks */
 
-#if SSI_CC_HAS_MULTI2
-   /* last byte of key buffer is round number and should not be a part
-* of key size
-*/
-   if (ctx_p->flow_mode == S_DIN_to_MULTI2)
-   keylen -= 1;
-#endif /*SSI_CC_HAS_MULTI2*/
-
if (validate_keys_sizes(ctx_p, keylen)) {
dev_err(dev, "Unsupported key size %d.\n", keylen);
crypto_tfm_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
@@ -393,38 +365,23 @@ static int cc_cipher_setkey(struct crypto_ablkcipher 
*atfm, const u8 *key,
dma_sync_single_for_cpu(dev, ctx_p->user.key_dma_addr,
max_key_buf_size, DMA_TO_DEVICE);
 
-   if (ctx_p->flow_mode == S_DIN_to_MULTI2) {
-#if SSI_CC_HAS_MULTI2
-   memcpy(ctx_p->user.key, key, CC_MULTI2_SYSTEM_N_DATA_KEY_SIZE);
-   ctx_p->key_round_number =
-   key[CC_MULTI2_SYSTEM_N_DATA_KEY_SIZE];
-   

[PATCH 15/24] staging: ccree: fix ivgen func def coding style

2017-12-12 Thread Gilad Ben-Yossef
Fix ivgen functions definition indentation according to coding
style guide lines for better code readability

Signed-off-by: Gilad Ben-Yossef 
---
 drivers/staging/ccree/ssi_ivgen.c | 16 +---
 drivers/staging/ccree/ssi_ivgen.h | 10 +++---
 2 files changed, 8 insertions(+), 18 deletions(-)

diff --git a/drivers/staging/ccree/ssi_ivgen.c 
b/drivers/staging/ccree/ssi_ivgen.c
index ad6cd97..c499361 100644
--- a/drivers/staging/ccree/ssi_ivgen.c
+++ b/drivers/staging/ccree/ssi_ivgen.c
@@ -57,10 +57,8 @@ struct cc_ivgen_ctx {
  * \param iv_seq IN/OUT array to the descriptors sequence
  * \param iv_seq_len IN/OUT pointer to the sequence length
  */
-static int cc_gen_iv_pool(
-   struct cc_ivgen_ctx *ivgen_ctx,
-   struct cc_hw_desc iv_seq[],
-   unsigned int *iv_seq_len)
+static int cc_gen_iv_pool(struct cc_ivgen_ctx *ivgen_ctx,
+ struct cc_hw_desc iv_seq[], unsigned int *iv_seq_len)
 {
unsigned int idx = *iv_seq_len;
 
@@ -236,13 +234,9 @@ int cc_ivgen_init(struct ssi_drvdata *drvdata)
  *
  * \return int Zero for success, negative value otherwise.
  */
-int cc_get_iv(
-   struct ssi_drvdata *drvdata,
-   dma_addr_t iv_out_dma[],
-   unsigned int iv_out_dma_len,
-   unsigned int iv_out_size,
-   struct cc_hw_desc iv_seq[],
-   unsigned int *iv_seq_len)
+int cc_get_iv(struct ssi_drvdata *drvdata, dma_addr_t iv_out_dma[],
+ unsigned int iv_out_dma_len, unsigned int iv_out_size,
+ struct cc_hw_desc iv_seq[], unsigned int *iv_seq_len)
 {
struct cc_ivgen_ctx *ivgen_ctx = drvdata->ivgen_handle;
unsigned int idx = *iv_seq_len;
diff --git a/drivers/staging/ccree/ssi_ivgen.h 
b/drivers/staging/ccree/ssi_ivgen.h
index fe3d919..bbd0245 100644
--- a/drivers/staging/ccree/ssi_ivgen.h
+++ b/drivers/staging/ccree/ssi_ivgen.h
@@ -61,12 +61,8 @@ int cc_init_iv_sram(struct ssi_drvdata *drvdata);
  *
  * \return int Zero for success, negative value otherwise.
  */
-int cc_get_iv(
-   struct ssi_drvdata *drvdata,
-   dma_addr_t iv_out_dma[],
-   unsigned int iv_out_dma_len,
-   unsigned int iv_out_size,
-   struct cc_hw_desc iv_seq[],
-   unsigned int *iv_seq_len);
+int cc_get_iv(struct ssi_drvdata *drvdata, dma_addr_t iv_out_dma[],
+ unsigned int iv_out_dma_len, unsigned int iv_out_size,
+ struct cc_hw_desc iv_seq[], unsigned int *iv_seq_len);
 
 #endif /*__SSI_IVGEN_H__*/
-- 
2.7.4

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


[PATCH 17/24] staging: ccree: remove SSI_CC_HAS_ macros

2017-12-12 Thread Gilad Ben-Yossef
Remove macro controlling build of various features. This
needs to happen dynamically in registration time.

Signed-off-by: Gilad Ben-Yossef 
---
 drivers/staging/ccree/ssi_aead.c   | 33 -
 drivers/staging/ccree/ssi_buffer_mgr.c |  4 
 drivers/staging/ccree/ssi_cipher.c |  8 
 drivers/staging/ccree/ssi_driver.h |  8 
 drivers/staging/ccree/ssi_hash.c   |  5 -
 5 files changed, 58 deletions(-)

diff --git a/drivers/staging/ccree/ssi_aead.c b/drivers/staging/ccree/ssi_aead.c
index 112fba3..ac9961c 100644
--- a/drivers/staging/ccree/ssi_aead.c
+++ b/drivers/staging/ccree/ssi_aead.c
@@ -662,7 +662,6 @@ cc_aead_setkey(struct crypto_aead *tfm, const u8 *key, 
unsigned int keylen)
return rc;
 }
 
-#if SSI_CC_HAS_AES_CCM
 static int cc_rfc4309_ccm_setkey(struct crypto_aead *tfm, const u8 *key,
 unsigned int keylen)
 {
@@ -676,7 +675,6 @@ static int cc_rfc4309_ccm_setkey(struct crypto_aead *tfm, 
const u8 *key,
 
return cc_aead_setkey(tfm, key, keylen);
 }
-#endif /*SSI_CC_HAS_AES_CCM*/
 
 static int cc_aead_setauthsize(struct crypto_aead *authenc,
   unsigned int authsize)
@@ -696,7 +694,6 @@ static int cc_aead_setauthsize(struct crypto_aead *authenc,
return 0;
 }
 
-#if SSI_CC_HAS_AES_CCM
 static int cc_rfc4309_ccm_setauthsize(struct crypto_aead *authenc,
  unsigned int authsize)
 {
@@ -730,7 +727,6 @@ static int cc_ccm_setauthsize(struct crypto_aead *authenc,
 
return cc_aead_setauthsize(authenc, authsize);
 }
-#endif /*SSI_CC_HAS_AES_CCM*/
 
 static void cc_set_assoc_desc(struct aead_request *areq, unsigned int 
flow_mode,
  struct cc_hw_desc desc[], unsigned int *seq_size)
@@ -1374,7 +1370,6 @@ static int validate_data_size(struct cc_aead_ctx *ctx,
return -EINVAL;
 }
 
-#if SSI_CC_HAS_AES_CCM
 static unsigned int format_ccm_a0(u8 *pa0_buff, u32 header_size)
 {
unsigned int len = 0;
@@ -1623,9 +1618,6 @@ static void cc_proc_rfc4309_ccm(struct aead_request *req)
req->iv = areq_ctx->ctr_iv;
req->assoclen -= CCM_BLOCK_IV_SIZE;
 }
-#endif /*SSI_CC_HAS_AES_CCM*/
-
-#if SSI_CC_HAS_AES_GCM
 
 static void cc_set_ghash_desc(struct aead_request *req,
  struct cc_hw_desc desc[], unsigned int *seq_size)
@@ -1952,8 +1944,6 @@ static void cc_proc_rfc4_gcm(struct aead_request *req)
req->assoclen -= GCM_BLOCK_RFC4_IV_SIZE;
 }
 
-#endif /*SSI_CC_HAS_AES_GCM*/
-
 static int cc_proc_aead(struct aead_request *req,
enum drv_crypto_direction direct)
 {
@@ -2020,7 +2010,6 @@ static int cc_proc_aead(struct aead_request *req,
areq_ctx->hw_iv_size = crypto_aead_ivsize(tfm);
}
 
-#if SSI_CC_HAS_AES_CCM
if (ctx->cipher_mode == DRV_CIPHER_CCM) {
rc = config_ccm_adata(req);
if (rc) {
@@ -2031,11 +2020,7 @@ static int cc_proc_aead(struct aead_request *req,
} else {
areq_ctx->ccm_hdr_size = ccm_header_size_null;
}
-#else
-   areq_ctx->ccm_hdr_size = ccm_header_size_null;
-#endif /*SSI_CC_HAS_AES_CCM*/
 
-#if SSI_CC_HAS_AES_GCM
if (ctx->cipher_mode == DRV_CIPHER_GCTR) {
rc = config_gcm_context(req);
if (rc) {
@@ -2044,7 +2029,6 @@ static int cc_proc_aead(struct aead_request *req,
goto exit;
}
}
-#endif /*SSI_CC_HAS_AES_GCM*/
 
rc = cc_map_aead_request(ctx->drvdata, req);
if (rc) {
@@ -2100,18 +2084,12 @@ static int cc_proc_aead(struct aead_request *req,
case DRV_HASH_XCBC_MAC:
cc_xcbc_authenc(req, desc, &seq_len);
break;
-#if (SSI_CC_HAS_AES_CCM || SSI_CC_HAS_AES_GCM)
case DRV_HASH_NULL:
-#if SSI_CC_HAS_AES_CCM
if (ctx->cipher_mode == DRV_CIPHER_CCM)
cc_ccm(req, desc, &seq_len);
-#endif /*SSI_CC_HAS_AES_CCM*/
-#if SSI_CC_HAS_AES_GCM
if (ctx->cipher_mode == DRV_CIPHER_GCTR)
cc_gcm(req, desc, &seq_len);
-#endif /*SSI_CC_HAS_AES_GCM*/
break;
-#endif
default:
dev_err(dev, "Unsupported authenc (%d)\n", ctx->auth_mode);
cc_unmap_aead_request(dev, req);
@@ -2151,7 +2129,6 @@ static int cc_aead_encrypt(struct aead_request *req)
return rc;
 }
 
-#if SSI_CC_HAS_AES_CCM
 static int cc_rfc4309_ccm_encrypt(struct aead_request *req)
 {
/* Very similar to cc_aead_encrypt() above. */
@@ -2180,7 +2157,6 @@ static int cc_rfc4309_ccm_encrypt(struct aead_request 
*req)
 out:
return rc;
 }
-#endif /* SSI_CC_HAS_AES_CCM */
 
 static int cc_aead_decrypt(struct aead_request *req)
 {
@@ -2201,7 +2177,6 @@ static int cc_aead_decrypt(struct aead_request *req)
return rc;
 }
 
-#if SSI_CC_HAS_AES_CCM
 static int cc_rfc4309_ccm_decrypt(struct aead_

[PATCH 18/24] staging: ccree: rename all SSI to CC

2017-12-12 Thread Gilad Ben-Yossef
Unify naming convention by renaming all SSI macros to CC.

Signed-off-by: Gilad Ben-Yossef 
---
 drivers/staging/ccree/ssi_aead.c| 26 +--
 drivers/staging/ccree/ssi_aead.h|  6 +--
 drivers/staging/ccree/ssi_buffer_mgr.c  | 78 -
 drivers/staging/ccree/ssi_buffer_mgr.h  | 14 +++---
 drivers/staging/ccree/ssi_cipher.c  |  4 +-
 drivers/staging/ccree/ssi_cipher.h  |  6 +--
 drivers/staging/ccree/ssi_config.h  |  4 +-
 drivers/staging/ccree/ssi_driver.c  | 26 +--
 drivers/staging/ccree/ssi_driver.h  | 22 +-
 drivers/staging/ccree/ssi_fips.c|  2 +-
 drivers/staging/ccree/ssi_fips.h|  6 +--
 drivers/staging/ccree/ssi_hash.c|  6 +--
 drivers/staging/ccree/ssi_hash.h|  6 +--
 drivers/staging/ccree/ssi_ivgen.c   |  8 ++--
 drivers/staging/ccree/ssi_ivgen.h   |  8 ++--
 drivers/staging/ccree/ssi_pm.c  |  2 +-
 drivers/staging/ccree/ssi_pm.h  |  6 +--
 drivers/staging/ccree/ssi_request_mgr.c | 16 +++
 drivers/staging/ccree/ssi_sram_mgr.c|  2 +-
 drivers/staging/ccree/ssi_sram_mgr.h| 10 ++---
 drivers/staging/ccree/ssi_sysfs.h   |  6 +--
 21 files changed, 132 insertions(+), 132 deletions(-)

diff --git a/drivers/staging/ccree/ssi_aead.c b/drivers/staging/ccree/ssi_aead.c
index ac9961c..d07b38d 100644
--- a/drivers/staging/ccree/ssi_aead.c
+++ b/drivers/staging/ccree/ssi_aead.c
@@ -257,7 +257,7 @@ static void cc_aead_complete(struct device *dev, void 
*ssi_req)
cc_copy_sg_portion(dev, areq_ctx->mac_buf,
   areq_ctx->dst_sgl, skip,
   (skip + ctx->authsize),
-  SSI_SG_FROM_BUF);
+  CC_SG_FROM_BUF);
}
 
/* If an IV was generated, copy it back to the user provided
@@ -739,7 +739,7 @@ static void cc_set_assoc_desc(struct aead_request *areq, 
unsigned int flow_mode,
struct device *dev = drvdata_to_dev(ctx->drvdata);
 
switch (assoc_dma_type) {
-   case SSI_DMA_BUF_DLLI:
+   case CC_DMA_BUF_DLLI:
dev_dbg(dev, "ASSOC buffer type DLLI\n");
hw_desc_init(&desc[idx]);
set_din_type(&desc[idx], DMA_DLLI, sg_dma_address(areq->src),
@@ -749,7 +749,7 @@ static void cc_set_assoc_desc(struct aead_request *areq, 
unsigned int flow_mode,
areq_ctx->cryptlen > 0)
set_din_not_last_indication(&desc[idx]);
break;
-   case SSI_DMA_BUF_MLLI:
+   case CC_DMA_BUF_MLLI:
dev_dbg(dev, "ASSOC buffer type MLLI\n");
hw_desc_init(&desc[idx]);
set_din_type(&desc[idx], DMA_MLLI, areq_ctx->assoc.sram_addr,
@@ -759,7 +759,7 @@ static void cc_set_assoc_desc(struct aead_request *areq, 
unsigned int flow_mode,
areq_ctx->cryptlen > 0)
set_din_not_last_indication(&desc[idx]);
break;
-   case SSI_DMA_BUF_NULL:
+   case CC_DMA_BUF_NULL:
default:
dev_err(dev, "Invalid ASSOC buffer type\n");
}
@@ -780,7 +780,7 @@ static void cc_proc_authen_desc(struct aead_request *areq,
struct device *dev = drvdata_to_dev(ctx->drvdata);
 
switch (data_dma_type) {
-   case SSI_DMA_BUF_DLLI:
+   case CC_DMA_BUF_DLLI:
{
struct scatterlist *cipher =
(direct == DRV_CRYPTO_DIRECTION_ENCRYPT) ?
@@ -797,7 +797,7 @@ static void cc_proc_authen_desc(struct aead_request *areq,
set_flow_mode(&desc[idx], flow_mode);
break;
}
-   case SSI_DMA_BUF_MLLI:
+   case CC_DMA_BUF_MLLI:
{
/* DOUBLE-PASS flow (as default)
 * assoc. + iv + data -compact in one table
@@ -823,7 +823,7 @@ static void cc_proc_authen_desc(struct aead_request *areq,
set_flow_mode(&desc[idx], flow_mode);
break;
}
-   case SSI_DMA_BUF_NULL:
+   case CC_DMA_BUF_NULL:
default:
dev_err(dev, "AUTHENC: Invalid SRC/DST buffer type\n");
}
@@ -847,7 +847,7 @@ static void cc_proc_cipher_desc(struct aead_request *areq,
return; /*null processing*/
 
switch (data_dma_type) {
-   case SSI_DMA_BUF_DLLI:
+   case CC_DMA_BUF_DLLI:
dev_dbg(dev, "CIPHER: SRC/DST buffer type DLLI\n");
hw_desc_init(&desc[idx]);
set_din_type(&desc[idx], DMA_DLLI,
@@ -860,7 +860,7 @@ static void cc_proc_cipher_desc(struct aead_request *areq,
  areq_ctx->cryptlen, NS_BIT, 0);
set_flow_mode(&desc[idx], flow_mode);
break;
-   case SSI_DMA_BUF_MLLI:
+   case CC_DMA_BUF_MLLI:
dev_dbg(dev, "CIPHER: SRC/DST buffer type MLLI\n"

[PATCH 19/24] staging: ccree: rename all DX to CC

2017-12-12 Thread Gilad Ben-Yossef
Unify naming convention by renaming all DX macros to CC.

Signed-off-by: Gilad Ben-Yossef 
---
 drivers/staging/ccree/cc_hw_queue_defs.h |   4 +-
 drivers/staging/ccree/cc_lli_defs.h  |   2 +-
 drivers/staging/ccree/dx_crys_kernel.h   | 314 +++
 drivers/staging/ccree/dx_host.h  | 262 +-
 drivers/staging/ccree/dx_reg_common.h|  10 +-
 drivers/staging/ccree/ssi_config.h   |   8 +-
 drivers/staging/ccree/ssi_driver.c   |  18 +-
 drivers/staging/ccree/ssi_driver.h   |  26 +--
 drivers/staging/ccree/ssi_hash.c |  18 +-
 drivers/staging/ccree/ssi_hash.h |   2 +-
 drivers/staging/ccree/ssi_request_mgr.c  |   2 +-
 drivers/staging/ccree/ssi_sysfs.c|  10 +-
 12 files changed, 338 insertions(+), 338 deletions(-)

diff --git a/drivers/staging/ccree/cc_hw_queue_defs.h 
b/drivers/staging/ccree/cc_hw_queue_defs.h
index 3ca548d..7c25a4f 100644
--- a/drivers/staging/ccree/cc_hw_queue_defs.h
+++ b/drivers/staging/ccree/cc_hw_queue_defs.h
@@ -31,11 +31,11 @@
 #define HW_QUEUE_SLOTS_MAX  15
 
 #define CC_REG_LOW(word, name)  \
-   (DX_DSCRPTR_QUEUE_WORD ## word ## _ ## name ## _BIT_SHIFT)
+   (CC_DSCRPTR_QUEUE_WORD ## word ## _ ## name ## _BIT_SHIFT)
 
 #define CC_REG_HIGH(word, name) \
(CC_REG_LOW(word, name) + \
-DX_DSCRPTR_QUEUE_WORD ## word ## _ ## name ## _BIT_SIZE - 1)
+CC_DSCRPTR_QUEUE_WORD ## word ## _ ## name ## _BIT_SIZE - 1)
 
 #define CC_GENMASK(word, name) \
GENMASK(CC_REG_HIGH(word, name), CC_REG_LOW(word, name))
diff --git a/drivers/staging/ccree/cc_lli_defs.h 
b/drivers/staging/ccree/cc_lli_defs.h
index a9c417b..861634a 100644
--- a/drivers/staging/ccree/cc_lli_defs.h
+++ b/drivers/staging/ccree/cc_lli_defs.h
@@ -20,7 +20,7 @@
 #include 
 
 /* Max DLLI size
- *  AKA DX_DSCRPTR_QUEUE_WORD1_DIN_SIZE_BIT_SIZE
+ *  AKA CC_DSCRPTR_QUEUE_WORD1_DIN_SIZE_BIT_SIZE
  */
 #define DLLI_SIZE_BIT_SIZE 0x18
 
diff --git a/drivers/staging/ccree/dx_crys_kernel.h 
b/drivers/staging/ccree/dx_crys_kernel.h
index 2196030..30719f4 100644
--- a/drivers/staging/ccree/dx_crys_kernel.h
+++ b/drivers/staging/ccree/dx_crys_kernel.h
@@ -14,167 +14,167 @@
  * along with this program; if not, see .
  */
 
-#ifndef __DX_CRYS_KERNEL_H__
-#define __DX_CRYS_KERNEL_H__
+#ifndef __CC_CRYS_KERNEL_H__
+#define __CC_CRYS_KERNEL_H__
 
 // --
 // BLOCK: DSCRPTR
 // --
-#define DX_DSCRPTR_COMPLETION_COUNTER_REG_OFFSET   0xE00UL
-#define DX_DSCRPTR_COMPLETION_COUNTER_COMPLETION_COUNTER_BIT_SHIFT 0x0UL
-#define DX_DSCRPTR_COMPLETION_COUNTER_COMPLETION_COUNTER_BIT_SIZE  0x6UL
-#define DX_DSCRPTR_COMPLETION_COUNTER_OVERFLOW_COUNTER_BIT_SHIFT   0x6UL
-#define DX_DSCRPTR_COMPLETION_COUNTER_OVERFLOW_COUNTER_BIT_SIZE0x1UL
-#define DX_DSCRPTR_SW_RESET_REG_OFFSET 0xE40UL
-#define DX_DSCRPTR_SW_RESET_VALUE_BIT_SHIFT0x0UL
-#define DX_DSCRPTR_SW_RESET_VALUE_BIT_SIZE 0x1UL
-#define DX_DSCRPTR_QUEUE_SRAM_SIZE_REG_OFFSET  0xE60UL
-#define DX_DSCRPTR_QUEUE_SRAM_SIZE_NUM_OF_DSCRPTR_BIT_SHIFT0x0UL
-#define DX_DSCRPTR_QUEUE_SRAM_SIZE_NUM_OF_DSCRPTR_BIT_SIZE 0xAUL
-#define DX_DSCRPTR_QUEUE_SRAM_SIZE_DSCRPTR_SRAM_SIZE_BIT_SHIFT 0xAUL
-#define DX_DSCRPTR_QUEUE_SRAM_SIZE_DSCRPTR_SRAM_SIZE_BIT_SIZE  0xCUL
-#define DX_DSCRPTR_QUEUE_SRAM_SIZE_SRAM_SIZE_BIT_SHIFT 0x16UL
-#define DX_DSCRPTR_QUEUE_SRAM_SIZE_SRAM_SIZE_BIT_SIZE  0x3UL
-#define DX_DSCRPTR_SINGLE_ADDR_EN_REG_OFFSET   0xE64UL
-#define DX_DSCRPTR_SINGLE_ADDR_EN_VALUE_BIT_SHIFT  0x0UL
-#define DX_DSCRPTR_SINGLE_ADDR_EN_VALUE_BIT_SIZE   0x1UL
-#define DX_DSCRPTR_MEASURE_CNTR_REG_OFFSET 0xE68UL
-#define DX_DSCRPTR_MEASURE_CNTR_VALUE_BIT_SHIFT0x0UL
-#define DX_DSCRPTR_MEASURE_CNTR_VALUE_BIT_SIZE 0x20UL
-#define DX_DSCRPTR_QUEUE_WORD0_REG_OFFSET  0xE80UL
-#define DX_DSCRPTR_QUEUE_WORD0_VALUE_BIT_SHIFT 0x0UL
-#define DX_DSCRPTR_QUEUE_WORD0_VALUE_BIT_SIZE  0x20UL
-#define DX_DSCRPTR_QUEUE_WORD1_REG_OFFSET  0xE84UL
-#define DX_DSCRPTR_QUEUE_WORD1_DIN_DMA_MODE_BIT_SHIFT  0x0UL
-#define DX_DSCRPTR_QUEUE_WORD1_DIN_DMA_MODE_BIT_SIZE   0x2UL
-#define DX_DSCRPTR_QUEUE_WORD1_DIN_SIZE_BIT_SHIFT  0x2UL
-#define DX_DSCRPTR_QUEUE_WORD1_DIN_SIZE_BIT_SIZE   0x18UL
-#define DX_DSCRPTR_QUEUE_WORD1_NS_BIT_BIT_SHIFT0x1AUL
-#define DX_DSCRPTR_QUEUE_WORD1_NS_BIT_BIT_SIZE 0x1UL
-#define DX_DSCRPTR_QUEUE_WORD1_DIN_CONST_VALUE_BIT_SHIFT   0x1BUL
-#define DX_DSCRPTR_QUEUE_WORD1_DIN_CONST_VALUE_BIT_SIZE0x1UL
-#define DX_DSCRPTR_QUEUE_WORD1_NOT_LAST_BIT_SHIFT  0x1CUL
-#define DX_DSCRPTR_QUEUE_WORD1_NOT_LAST_BIT_SIZE   0x1UL
-#define DX_DSCRPTR_QUEUE_WORD1_LOCK_QUEUE_BIT_SHIFT0x1DUL
-#define DX_DSCRPTR_QUEUE_WORD1_LOCK_QUEUE_BIT_SIZE 0x1UL
-#define DX_DSCRPTR_QUEUE_WORD1_NOT_USED_BIT_SHIFT  0x1EUL
-#define DX_DSCRPTR_QUEUE_WORD1_NOT_USED_BIT_SIZE   0x2UL
-#define DX_DSCRPTR_QUEU

[PATCH 21/24] staging: ccree: fix buf mgr naming convention

2017-12-12 Thread Gilad Ben-Yossef
The buffer manager files were using a func naming convention which was
inconsistent (ssi vs. cc) and often too long.

Make the code more readable by switching to a simpler, consistent naming
convention.

Signed-off-by: Gilad Ben-Yossef 
---
 drivers/staging/ccree/ssi_buffer_mgr.c | 28 
 1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/drivers/staging/ccree/ssi_buffer_mgr.c 
b/drivers/staging/ccree/ssi_buffer_mgr.c
index 8649bcb..6846d93 100644
--- a/drivers/staging/ccree/ssi_buffer_mgr.c
+++ b/drivers/staging/ccree/ssi_buffer_mgr.c
@@ -413,11 +413,9 @@ static int cc_map_sg(struct device *dev, struct 
scatterlist *sg,
 }
 
 static int
-ssi_aead_handle_config_buf(struct device *dev,
-  struct aead_req_ctx *areq_ctx,
-  u8 *config_data,
-  struct buffer_array *sg_data,
-  unsigned int assoclen)
+cc_set_aead_conf_buf(struct device *dev, struct aead_req_ctx *areq_ctx,
+u8 *config_data, struct buffer_array *sg_data,
+unsigned int assoclen)
 {
dev_dbg(dev, " handle additional data config set to DLLI\n");
/* create sg for the current buffer */
@@ -441,10 +439,9 @@ ssi_aead_handle_config_buf(struct device *dev,
return 0;
 }
 
-static int ssi_ahash_handle_curr_buf(struct device *dev,
-struct ahash_req_ctx *areq_ctx,
-u8 *curr_buff, u32 curr_buff_cnt,
-struct buffer_array *sg_data)
+static int cc_set_hash_buf(struct device *dev, struct ahash_req_ctx *areq_ctx,
+  u8 *curr_buff, u32 curr_buff_cnt,
+  struct buffer_array *sg_data)
 {
dev_dbg(dev, " handle curr buff %x set to   DLLI\n", curr_buff_cnt);
/* create sg for the current buffer */
@@ -1259,9 +1256,8 @@ int cc_map_aead_request(struct cc_drvdata *drvdata, 
struct aead_request *req)
}
areq_ctx->ccm_iv0_dma_addr = dma_addr;
 
-   if (ssi_aead_handle_config_buf(dev, areq_ctx,
-  areq_ctx->ccm_config, &sg_data,
-  req->assoclen)) {
+   if (cc_set_aead_conf_buf(dev, areq_ctx, areq_ctx->ccm_config,
+&sg_data, req->assoclen)) {
rc = -ENOMEM;
goto aead_map_failure;
}
@@ -1432,8 +1428,8 @@ int cc_map_hash_request_final(struct cc_drvdata *drvdata, 
void *ctx,
/*TODO: copy data in case that buffer is enough for operation */
/* map the previous buffer */
if (*curr_buff_cnt) {
-   if (ssi_ahash_handle_curr_buf(dev, areq_ctx, curr_buff,
- *curr_buff_cnt, &sg_data)) {
+   if (cc_set_hash_buf(dev, areq_ctx, curr_buff, *curr_buff_cnt,
+   &sg_data)) {
return -ENOMEM;
}
}
@@ -1545,8 +1541,8 @@ int cc_map_hash_request_update(struct cc_drvdata 
*drvdata, void *ctx,
}
 
if (*curr_buff_cnt) {
-   if (ssi_ahash_handle_curr_buf(dev, areq_ctx, curr_buff,
- *curr_buff_cnt, &sg_data)) {
+   if (cc_set_hash_buf(dev, areq_ctx, curr_buff, *curr_buff_cnt,
+   &sg_data)) {
return -ENOMEM;
}
/* change the buffer index for next operation */
-- 
2.7.4

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


[PATCH 22/24] staging: ccree: fix sram mgr naming convention

2017-12-12 Thread Gilad Ben-Yossef
The SRAM manager files were using a naming convention which was
inconsistent (ssi vs. cc) and often too long.

Make the code more readable by switching to a simpler, consistent naming
convention.

Signed-off-by: Gilad Ben-Yossef 
---
 drivers/staging/ccree/ssi_driver.c   |  8 
 drivers/staging/ccree/ssi_sram_mgr.c | 18 +-
 drivers/staging/ccree/ssi_sram_mgr.h |  4 ++--
 3 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/drivers/staging/ccree/ssi_driver.c 
b/drivers/staging/ccree/ssi_driver.c
index 3f02ceb..6e7a396 100644
--- a/drivers/staging/ccree/ssi_driver.c
+++ b/drivers/staging/ccree/ssi_driver.c
@@ -312,9 +312,9 @@ static int init_cc_resources(struct platform_device 
*plat_dev)
dev_err(dev, "CC_FIPS_INIT failed 0x%x\n", rc);
goto post_sysfs_err;
}
-   rc = ssi_sram_mgr_init(new_drvdata);
+   rc = cc_sram_mgr_init(new_drvdata);
if (rc) {
-   dev_err(dev, "ssi_sram_mgr_init failed\n");
+   dev_err(dev, "cc_sram_mgr_init failed\n");
goto post_fips_init_err;
}
 
@@ -391,7 +391,7 @@ static int init_cc_resources(struct platform_device 
*plat_dev)
 post_req_mgr_err:
cc_req_mgr_fini(new_drvdata);
 post_sram_mgr_err:
-   ssi_sram_mgr_fini(new_drvdata);
+   cc_sram_mgr_fini(new_drvdata);
 post_fips_init_err:
ssi_fips_fini(new_drvdata);
 post_sysfs_err:
@@ -423,7 +423,7 @@ static void cleanup_cc_resources(struct platform_device 
*plat_dev)
cc_pm_fini(drvdata);
cc_buffer_mgr_fini(drvdata);
cc_req_mgr_fini(drvdata);
-   ssi_sram_mgr_fini(drvdata);
+   cc_sram_mgr_fini(drvdata);
ssi_fips_fini(drvdata);
 #ifdef ENABLE_CC_SYSFS
ssi_sysfs_fini();
diff --git a/drivers/staging/ccree/ssi_sram_mgr.c 
b/drivers/staging/ccree/ssi_sram_mgr.c
index 5d83af5..b664e9b 100644
--- a/drivers/staging/ccree/ssi_sram_mgr.c
+++ b/drivers/staging/ccree/ssi_sram_mgr.c
@@ -18,37 +18,37 @@
 #include "ssi_sram_mgr.h"
 
 /**
- * struct ssi_sram_mgr_ctx -Internal RAM context manager
+ * struct cc_sram_ctx -Internal RAM context manager
  * @sram_free_offset:   the offset to the non-allocated area
  */
-struct ssi_sram_mgr_ctx {
+struct cc_sram_ctx {
cc_sram_addr_t sram_free_offset;
 };
 
 /**
- * ssi_sram_mgr_fini() - Cleanup SRAM pool.
+ * cc_sram_mgr_fini() - Cleanup SRAM pool.
  *
  * @drvdata: Associated device driver context
  */
-void ssi_sram_mgr_fini(struct cc_drvdata *drvdata)
+void cc_sram_mgr_fini(struct cc_drvdata *drvdata)
 {
-   struct ssi_sram_mgr_ctx *smgr_ctx = drvdata->sram_mgr_handle;
+   struct cc_sram_ctx *smgr_ctx = drvdata->sram_mgr_handle;
 
/* Free "this" context */
if (smgr_ctx) {
-   memset(smgr_ctx, 0, sizeof(struct ssi_sram_mgr_ctx));
+   memset(smgr_ctx, 0, sizeof(struct cc_sram_ctx));
kfree(smgr_ctx);
}
 }
 
 /**
- * ssi_sram_mgr_init() - Initializes SRAM pool.
+ * cc_sram_mgr_init() - Initializes SRAM pool.
  *  The pool starts right at the beginning of SRAM.
  *  Returns zero for success, negative value otherwise.
  *
  * @drvdata: Associated device driver context
  */
-int ssi_sram_mgr_init(struct cc_drvdata *drvdata)
+int cc_sram_mgr_init(struct cc_drvdata *drvdata)
 {
/* Allocate "this" context */
drvdata->sram_mgr_handle = kzalloc(sizeof(*drvdata->sram_mgr_handle),
@@ -71,7 +71,7 @@ int ssi_sram_mgr_init(struct cc_drvdata *drvdata)
  */
 cc_sram_addr_t cc_sram_alloc(struct cc_drvdata *drvdata, u32 size)
 {
-   struct ssi_sram_mgr_ctx *smgr_ctx = drvdata->sram_mgr_handle;
+   struct cc_sram_ctx *smgr_ctx = drvdata->sram_mgr_handle;
struct device *dev = drvdata_to_dev(drvdata);
cc_sram_addr_t p;
 
diff --git a/drivers/staging/ccree/ssi_sram_mgr.h 
b/drivers/staging/ccree/ssi_sram_mgr.h
index 52f5288..181968a 100644
--- a/drivers/staging/ccree/ssi_sram_mgr.h
+++ b/drivers/staging/ccree/ssi_sram_mgr.h
@@ -40,14 +40,14 @@ typedef u64 cc_sram_addr_t;
  *
  * \return int Zero for success, negative value otherwise.
  */
-int ssi_sram_mgr_init(struct cc_drvdata *drvdata);
+int cc_sram_mgr_init(struct cc_drvdata *drvdata);
 
 /*!
  * Uninits SRAM pool.
  *
  * \param drvdata
  */
-void ssi_sram_mgr_fini(struct cc_drvdata *drvdata);
+void cc_sram_mgr_fini(struct cc_drvdata *drvdata);
 
 /*!
  * Allocated buffer from SRAM pool.
-- 
2.7.4

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


[PATCH 20/24] staging: ccree: rename vars/structs/enums from ssi_ to cc_

2017-12-12 Thread Gilad Ben-Yossef
Unify naming convention by renaming all ssi_ vars/structs/enums
and variables to cc_*

Signed-off-by: Gilad Ben-Yossef 
---
 drivers/staging/ccree/ssi_aead.c|  82 +--
 drivers/staging/ccree/ssi_aead.h|  14 ++--
 drivers/staging/ccree/ssi_buffer_mgr.c  |  30 +++
 drivers/staging/ccree/ssi_buffer_mgr.h  |  22 +++---
 drivers/staging/ccree/ssi_cipher.c  |  72 -
 drivers/staging/ccree/ssi_cipher.h  |   6 +-
 drivers/staging/ccree/ssi_driver.c  |  16 ++--
 drivers/staging/ccree/ssi_driver.h  |  30 +++
 drivers/staging/ccree/ssi_fips.c|  20 ++---
 drivers/staging/ccree/ssi_fips.h|  16 ++--
 drivers/staging/ccree/ssi_hash.c| 136 
 drivers/staging/ccree/ssi_hash.h|  12 +--
 drivers/staging/ccree/ssi_ivgen.c   |  14 ++--
 drivers/staging/ccree/ssi_ivgen.h   |   8 +-
 drivers/staging/ccree/ssi_pm.c  |  12 +--
 drivers/staging/ccree/ssi_pm.h  |   4 +-
 drivers/staging/ccree/ssi_request_mgr.c |  70 
 drivers/staging/ccree/ssi_request_mgr.h |  18 ++---
 drivers/staging/ccree/ssi_sram_mgr.c|  12 +--
 drivers/staging/ccree/ssi_sram_mgr.h|  14 ++--
 drivers/staging/ccree/ssi_sysfs.c   |  12 +--
 drivers/staging/ccree/ssi_sysfs.h   |   4 +-
 22 files changed, 312 insertions(+), 312 deletions(-)

diff --git a/drivers/staging/ccree/ssi_aead.c b/drivers/staging/ccree/ssi_aead.c
index d07b38d..73ae970 100644
--- a/drivers/staging/ccree/ssi_aead.c
+++ b/drivers/staging/ccree/ssi_aead.c
@@ -52,7 +52,7 @@
 #define ICV_VERIF_OK 0x01
 
 struct cc_aead_handle {
-   ssi_sram_addr_t sram_workspace_addr;
+   cc_sram_addr_t sram_workspace_addr;
struct list_head aead_list;
 };
 
@@ -69,7 +69,7 @@ struct cc_xcbc_s {
 };
 
 struct cc_aead_ctx {
-   struct ssi_drvdata *drvdata;
+   struct cc_drvdata *drvdata;
u8 ctr_nonce[MAX_NONCE_SIZE]; /* used for ctr3686 iv and aes ccm */
u8 *enckey;
dma_addr_t enckey_dma_addr;
@@ -148,18 +148,18 @@ static int cc_aead_init(struct crypto_aead *tfm)
 {
struct aead_alg *alg = crypto_aead_alg(tfm);
struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
-   struct ssi_crypto_alg *ssi_alg =
-   container_of(alg, struct ssi_crypto_alg, aead_alg);
-   struct device *dev = drvdata_to_dev(ssi_alg->drvdata);
+   struct cc_crypto_alg *cc_alg =
+   container_of(alg, struct cc_crypto_alg, aead_alg);
+   struct device *dev = drvdata_to_dev(cc_alg->drvdata);
 
dev_dbg(dev, "Initializing context @%p for %s\n", ctx,
crypto_tfm_alg_name(&tfm->base));
 
/* Initialize modes in instance */
-   ctx->cipher_mode = ssi_alg->cipher_mode;
-   ctx->flow_mode = ssi_alg->flow_mode;
-   ctx->auth_mode = ssi_alg->auth_mode;
-   ctx->drvdata = ssi_alg->drvdata;
+   ctx->cipher_mode = cc_alg->cipher_mode;
+   ctx->flow_mode = cc_alg->flow_mode;
+   ctx->auth_mode = cc_alg->auth_mode;
+   ctx->drvdata = cc_alg->drvdata;
crypto_aead_set_reqsize(tfm, sizeof(struct aead_req_ctx));
 
/* Allocate key buffer, cache line aligned */
@@ -226,11 +226,11 @@ static int cc_aead_init(struct crypto_aead *tfm)
return -ENOMEM;
 }
 
-static void cc_aead_complete(struct device *dev, void *ssi_req)
+static void cc_aead_complete(struct device *dev, void *cc_req)
 {
-   struct aead_request *areq = (struct aead_request *)ssi_req;
+   struct aead_request *areq = (struct aead_request *)cc_req;
struct aead_req_ctx *areq_ctx = aead_request_ctx(areq);
-   struct crypto_aead *tfm = crypto_aead_reqtfm(ssi_req);
+   struct crypto_aead *tfm = crypto_aead_reqtfm(cc_req);
struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
int err = 0;
 
@@ -442,7 +442,7 @@ cc_get_plain_hmac_key(struct crypto_aead *tfm, const u8 
*key,
struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
struct device *dev = drvdata_to_dev(ctx->drvdata);
u32 larval_addr = cc_larval_digest_addr(ctx->drvdata, ctx->auth_mode);
-   struct ssi_crypto_req ssi_req = {};
+   struct cc_crypto_req cc_req = {};
unsigned int blocksize;
unsigned int digestsize;
unsigned int hashmode;
@@ -546,7 +546,7 @@ cc_get_plain_hmac_key(struct crypto_aead *tfm, const u8 
*key,
idx++;
}
 
-   rc = send_request(ctx->drvdata, &ssi_req, desc, idx, 0);
+   rc = send_request(ctx->drvdata, &cc_req, desc, idx, 0);
if (rc)
dev_err(dev, "send_request() failed (rc=%d)\n", rc);
 
@@ -561,7 +561,7 @@ cc_aead_setkey(struct crypto_aead *tfm, const u8 *key, 
unsigned int keylen)
 {
struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
struct rtattr *rta = (struct rtattr *)key;
-   struct ssi_crypto_req ssi_req = {};
+   struct cc_crypto_req cc_req = {};
struct crypto_authenc_key_param *param;

[PATCH 23/24] staging: ccree: simplify freeing SRAM memory address

2017-12-12 Thread Gilad Ben-Yossef
The code freeing the SRAM memory address was zeroing the address
on release although there is nothing secret about it. Simplify
the code by simply calling kfree directly.

Signed-off-by: Gilad Ben-Yossef 
---
 drivers/staging/ccree/ssi_sram_mgr.c | 7 +--
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/staging/ccree/ssi_sram_mgr.c 
b/drivers/staging/ccree/ssi_sram_mgr.c
index b664e9b..f72d64a 100644
--- a/drivers/staging/ccree/ssi_sram_mgr.c
+++ b/drivers/staging/ccree/ssi_sram_mgr.c
@@ -32,13 +32,8 @@ struct cc_sram_ctx {
  */
 void cc_sram_mgr_fini(struct cc_drvdata *drvdata)
 {
-   struct cc_sram_ctx *smgr_ctx = drvdata->sram_mgr_handle;
-
/* Free "this" context */
-   if (smgr_ctx) {
-   memset(smgr_ctx, 0, sizeof(struct cc_sram_ctx));
-   kfree(smgr_ctx);
-   }
+   kfree(drvdata->sram_mgr_handle);
 }
 
 /**
-- 
2.7.4

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


[PATCH 24/24] staging: ccree: fix FIPS mgr naming convention

2017-12-12 Thread Gilad Ben-Yossef
The FIPS manager files were using a naming convention which was
inconsistent (ssi vs. cc) and often too long.

Make the code more readable by switching to a simpler, consistent naming
convention.

Signed-off-by: Gilad Ben-Yossef 
---
 drivers/staging/ccree/ssi_driver.c | 6 +++---
 drivers/staging/ccree/ssi_fips.c   | 4 ++--
 drivers/staging/ccree/ssi_fips.h   | 8 
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/ccree/ssi_driver.c 
b/drivers/staging/ccree/ssi_driver.c
index 6e7a396..28cfbb4 100644
--- a/drivers/staging/ccree/ssi_driver.c
+++ b/drivers/staging/ccree/ssi_driver.c
@@ -307,7 +307,7 @@ static int init_cc_resources(struct platform_device 
*plat_dev)
}
 #endif
 
-   rc = ssi_fips_init(new_drvdata);
+   rc = cc_fips_init(new_drvdata);
if (rc) {
dev_err(dev, "CC_FIPS_INIT failed 0x%x\n", rc);
goto post_sysfs_err;
@@ -393,7 +393,7 @@ static int init_cc_resources(struct platform_device 
*plat_dev)
 post_sram_mgr_err:
cc_sram_mgr_fini(new_drvdata);
 post_fips_init_err:
-   ssi_fips_fini(new_drvdata);
+   cc_fips_fini(new_drvdata);
 post_sysfs_err:
 #ifdef ENABLE_CC_SYSFS
ssi_sysfs_fini();
@@ -424,7 +424,7 @@ static void cleanup_cc_resources(struct platform_device 
*plat_dev)
cc_buffer_mgr_fini(drvdata);
cc_req_mgr_fini(drvdata);
cc_sram_mgr_fini(drvdata);
-   ssi_fips_fini(drvdata);
+   cc_fips_fini(drvdata);
 #ifdef ENABLE_CC_SYSFS
ssi_sysfs_fini();
 #endif
diff --git a/drivers/staging/ccree/ssi_fips.c b/drivers/staging/ccree/ssi_fips.c
index 036215f..a1d7782 100644
--- a/drivers/staging/ccree/ssi_fips.c
+++ b/drivers/staging/ccree/ssi_fips.c
@@ -51,7 +51,7 @@ void cc_set_ree_fips_status(struct cc_drvdata *drvdata, bool 
status)
cc_iowrite(drvdata, CC_REG(HOST_GPR0), val);
 }
 
-void ssi_fips_fini(struct cc_drvdata *drvdata)
+void cc_fips_fini(struct cc_drvdata *drvdata)
 {
struct cc_fips_handle *fips_h = drvdata->fips_handle;
 
@@ -105,7 +105,7 @@ static void fips_dsr(unsigned long devarg)
 }
 
 /* The function called once at driver entry point .*/
-int ssi_fips_init(struct cc_drvdata *p_drvdata)
+int cc_fips_init(struct cc_drvdata *p_drvdata)
 {
struct cc_fips_handle *fips_h;
struct device *dev = drvdata_to_dev(p_drvdata);
diff --git a/drivers/staging/ccree/ssi_fips.h b/drivers/staging/ccree/ssi_fips.h
index 5eed9f6..8321dde 100644
--- a/drivers/staging/ccree/ssi_fips.h
+++ b/drivers/staging/ccree/ssi_fips.h
@@ -27,19 +27,19 @@ enum cc_fips_status {
CC_FIPS_SYNC_STATUS_RESERVE32B = S32_MAX
 };
 
-int ssi_fips_init(struct cc_drvdata *p_drvdata);
-void ssi_fips_fini(struct cc_drvdata *drvdata);
+int cc_fips_init(struct cc_drvdata *p_drvdata);
+void cc_fips_fini(struct cc_drvdata *drvdata);
 void fips_handler(struct cc_drvdata *drvdata);
 void cc_set_ree_fips_status(struct cc_drvdata *drvdata, bool ok);
 
 #else  /* CONFIG_CRYPTO_FIPS */
 
-static inline int ssi_fips_init(struct cc_drvdata *p_drvdata)
+static inline int cc_fips_init(struct cc_drvdata *p_drvdata)
 {
return 0;
 }
 
-static inline void ssi_fips_fini(struct cc_drvdata *drvdata) {}
+static inline void cc_fips_fini(struct cc_drvdata *drvdata) {}
 static inline void cc_set_ree_fips_status(struct cc_drvdata *drvdata,
  bool ok) {}
 static inline void fips_handler(struct cc_drvdata *drvdata) {}
-- 
2.7.4

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


Re: first try to send data with pi433 on Raspberry Pi

2017-12-12 Thread Oliver Graute
On 11/12/17, Marcus Wolf wrote:
> 
> Am 11.12.2017 um 20:40 schrieb Oliver Graute:
> >Hello list,
> >
> >I just got my pi433 working somehow on Raspberry Pi Model B Rev 2.
> >
> >Here are my findings:
> >
> >first I need to enabling spi in config.txt on boot partition.
> >
> >dtparam=spi=on
> >
> >then adding this node to bcm2835-rpi-b-rev2.dts and compile.
> >
> >&spi0_gpio7 {
> > pi433: pi433@0 {
> > compatible = "Smarthome-Wolf,pi433";
> > reg = <0>; /* CE 0 */
> > #address-cells = <1>;
> > #size-cells = <0>;
> > spi-max-frequency = <1000>;
> >
> > pinctrl-0 = <&pi433_pins>;
> > DIO0-gpio = <&gpio 24 0>;
> > DIO1-gpio = <&gpio 25 0>;
> > DIO2-gpio = <&gpio  7 0>;
> > status = "okay";
> > };
> >};
> >
> >Then loading spi_bcm2835 and pi433 modules:
> >
> >modprobe spi_bcm2835
> >modprobe pi433
> >
> >Is this the right usage to send some data over the air?
> >
> >echo 1 > /dev/pi433
> >[   64.258257] pi433 pi433: thread: going to wait for new messages
> >
> thanks for testing with real hardware :-)
> 
> In my product, I use Raspbian. Therefore, I work with a kernel from
> Raspbian. Raspbian supports device tree overlays.

I used a buildroot system for this very first test. 

> So I don't use dtparam=spi=on, but dtoverlay=pi433.
> I don't modify the bcm2835-rpi-b-rev2.dts, but use the
> pi433-overlay.dts, provided in the driver documentation.
> 
> I am not sure, whether you need to load spi_bcm2835. I never did
> that, but maybe it is done implicitly on my system.
> 
> 
> Never adressed Pi433 from command line, but always used a program to do so.
> Anyway: The way you did it, you missed to setup the tx and/or rx
> configuration. I am not sure, whether there are useful defaults in
> the current version of the driver, allowing you can start with tx
> right from the start. Most probably all entries are preset with
> zero, that might lead to an not really perfect configuration of the
> chip. So you need to use the ioctl first, to set usefull config
> params.

ok so I need to configure tx and rx before somehow. I'll look into it.
If you could provide some example howto address /dev/pi433 from
userspace and example settings would be nice.
 
> I don't know, what generates the hundrets of "write: generated new
> msg with 2 bytes.".
> This message is shown up, as soon as you ask the driver to send
> something. There is an internal (SW) queue, where tx jobs get
> stored. The message tells you, that a telegram with 2 bytes was
> stored in this queue. I guess the two bytes are the '1' and a new
> line, generated by the echo. The repetition of the message is quite
> strange.

yes its strange, I also assume thats related to missing configuration.

> Maybe due to misssing configuration / bad default settings.
> As soon, as there is something in the queue, the driver should leave
> RX mode (where he was waiting for messages in the air) and start to
> transfer the messages from the queue with the given (or in your case
> missing) configuration for TX. As soon as the queue is empty, the
> driver should reconfigure for RX and restart listening on the air.
> 
> Unfortunally I can't find the source code from my testprogram, that
> is compatible with the current version of the driver. Hope I didn't
> format the wrong SD-card.
> Just found sources for the "old" version of the driver, that was
> intended to support more then just Pi433...
> 
> Will provide the source as soon as I find it.

that would be great


Best regards,

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


Re: first try to send data with pi433 on Raspberry Pi

2017-12-12 Thread Marcin Ciupak
On Mon, Dec 11, 2017 at 10:29:54PM +0200, Marcus Wolf wrote:
> 
> Am 11.12.2017 um 20:40 schrieb Oliver Graute:
> > Hello list,
> > 
> > I just got my pi433 working somehow on Raspberry Pi Model B Rev 2.
> > 
> > Here are my findings:
> > 
> > first I need to enabling spi in config.txt on boot partition.
> > 
> > dtparam=spi=on
> > 
> > then adding this node to bcm2835-rpi-b-rev2.dts and compile.
> > 
> > &spi0_gpio7 {
> > pi433: pi433 at 0 {
> > compatible = "Smarthome-Wolf,pi433";
> > reg = <0>; /* CE 0 */
> > #address-cells = <1>;
> > #size-cells = <0>;
> > spi-max-frequency = <1000>;
> > 
> > pinctrl-0 = <&pi433_pins>;
> > DIO0-gpio = <&gpio 24 0>;
> > DIO1-gpio = <&gpio 25 0>;
> > DIO2-gpio = <&gpio  7 0>;
> > status = "okay";
> > };
> > };
> > 
> > Then loading spi_bcm2835 and pi433 modules:
> > 
> > modprobe spi_bcm2835
> > modprobe pi433
> > 
> > Is this the right usage to send some data over the air?
> > 
> > echo 1 > /dev/pi433
> > 
> > [   31.223963] spi-bcm2835 20204000.spi: registered master spi0
> > [   31.224300] spi spi0.0: setup mode 0, 8 bits/w, 1000 Hz max --> 0
> > [   31.224625] spi-bcm2835 20204000.spi: registered child spi0.0
> > [   31.224687] spi spi0.1: setup mode 0, 8 bits/w, 12500 Hz max --> 0
> > [   31.224977] spi-bcm2835 20204000.spi: registered child spi0.1
> > [   34.062430] random: crng init done
> > [   43.122779] pi433: module is from the staging directory, the quality is 
> > unknown, you have been warned.
> > [   43.143436] pi433 spi0.0: setup mode 0, 8 bits/w, 1000 Hz max --> 0
> > [   43.143465] pi433 spi0.0: spi interface setup: mode 0x 0, 8 bits per 
> > word, 1000hz max speed
> > [   43.143587] pi433 spi0.0: found pi433 (ver. 0x24)
> > [   43.144027] pi433 spi0.0: DIO0 succesfully configured
> > [   43.144259] pi433 spi0.0: DIO1 succesfully configured
> > [   43.144274] pi433 spi0.0: set: mode
> > [   43.144387] pi433 spi0.0: read 0x4 from reg 0x1
> > [   43.144463] pi433 spi0.0: wrote 0x4 to reg 0x1
> > [   43.144476] pi433 spi0.0: set: data mode
> > [   43.144548] pi433 spi0.0: read 0x8 from reg 0x2
> > [   43.144617] pi433 spi0.0: wrote 0x8 to reg 0x2
> > [   43.144632] pi433 spi0.0: set: amp #0
> > [   43.144703] pi433 spi0.0: read 0x9f from reg 0x11
> > [   43.144772] pi433 spi0.0: wrote 0x9f to reg 0x11
> > [   43.144785] pi433 spi0.0: set: amp #1
> > [   43.144856] pi433 spi0.0: read 0x9f from reg 0x11
> > [   43.144923] pi433 spi0.0: wrote 0x9f to reg 0x11
> > [   43.144936] pi433 spi0.0: set: amp #2
> > [   43.145007] pi433 spi0.0: read 0x9f from reg 0x11
> > [   43.145074] pi433 spi0.0: wrote 0x9f to reg 0x11
> > [   43.145088] pi433 spi0.0: set: power level
> > [   43.145158] pi433 spi0.0: read 0x9f from reg 0x11
> > [   43.145225] pi433 spi0.0: wrote 0x9f to reg 0x11
> > [   43.145237] pi433 spi0.0: set: antenna impedance
> > [   43.145308] pi433 spi0.0: read 0x8 from reg 0x18
> > [   43.145376] pi433 spi0.0: wrote 0x8 to reg 0x18
> > [   43.145935] pi433 pi433: created device for major 244, minor 0
> > [   43.148742] pi433 pi433: thread: going to wait for new messages
> > 
> > Now I got hundreds messages of kind:
> > 
> > [   64.221295] pi433 pi433: write: generated new msg with 2 bytes.
> > 
> > snip
> > 
> > [   64.222671] pi433 pi433: write: generated new msg with 2 bytes.
> > [   64.223882] pi433 pi433: read 2 message byte(s) from fifo queue.
> > [   64.223919] pi433 spi0.0: set: mode
> > [   64.224010] pi433 spi0.0: read 0x4 from reg 0x1
> > [   64.224053] pi433 spi0.0: wrote 0x4 to reg 0x1
> > [   64.224064] pi433 spi0.0: set: fifo threshold
> > [   64.224100] pi433 spi0.0: read 0xf from reg 0x3c
> > [   64.224129] pi433 spi0.0: wrote 0xf to reg 0x3c
> > [   64.224159] pi433 spi0.0: 0 - 0x0
> > [   64.224170] pi433 spi0.0: set: payload length
> > [   64.224197] pi433 spi0.0: wrote 0x0 to reg 0x38
> > [   64.224209] pi433 spi0.0: set: frequency
> > [   64.224237] pi433 spi0.0: wrote 0x0 to reg 0x7
> > [   64.224263] pi433 spi0.0: wrote 0x0 to reg 0x8
> > [   64.224292] pi433 spi0.0: wrote 0x0 to reg 0x9
> > [   64.224303] pi433 spi0.0: set: bit rate
> > [   64.224331] pi433 spi0.0: wrote 0x1a to reg 0x3
> > [   64.224359] pi433 spi0.0: wrote 0x88 to reg 0x4
> > [   64.224370] pi433 spi0.0: set: modulation
> > [   64.224404] pi433 spi0.0: read 0x8 from reg 0x2
> > [   64.224431] pi433 spi0.0: wrote 0x8 to reg 0x2
> > [   64.224442] pi433 spi0.0: set: deviation
> > [   64.224450] pi433 spi0.0: set_deviation: illegal input param
> > [   64.224458] pi433 spi0.0: set: deviation
> > [   64.224466] pi433 spi0.0: set_deviation: illegal input param
> > [   64.224475] pi433 spi0.0: set: DIO mapping
> > [   64.224506] pi433 spi0.0: read 0x0 from reg 0x25
> > [   64.224537] pi433 spi0.0: wrote 0x0 to reg 0x25
> > [   64.224555] pi433 spi0.0: set: DIO mapping
> > [   64.224591] pi433 spi0.0: read 0x0 from reg 0x25

[PATCH] staging: comedi: s626.c - fix multiline dereference

2017-12-12 Thread Roman Lakeev
 staging: comedi: s626.c - fix the following checkpatch issues:
 WARNING: Avoid multiple line dereference - prefer 
'devpriv->rps_buf.logical_base'
 #1380: FILE: drivers/s626.c:1380:
 + (unsigned long)devpriv->
 +rps_buf.logical_base);

 WARNING: Avoid multiple line dereference - prefer 'cmd->scan_begin_arg'
 #1898: FILE: drivers/s626.c:1898:
 +  err |= comedi_check_trigger_arg_min(&cmd->
 +  
scan_begin_arg,

 Signed-off-by: Roman Lakeev 
---
 drivers/staging/comedi/drivers/s626.c | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/comedi/drivers/s626.c 
b/drivers/staging/comedi/drivers/s626.c
index 8d9187025d51..0b3cfe934e14 100644
--- a/drivers/staging/comedi/drivers/s626.c
+++ b/drivers/staging/comedi/drivers/s626.c
@@ -1376,8 +1376,7 @@ static void s626_reset_adc(struct comedi_device *dev, u8 
*ppl)
jmp_adrs =
(u32)devpriv->rps_buf.physical_base +
(u32)((unsigned long)rps -
-  (unsigned long)devpriv->
- rps_buf.logical_base);
+ (unsigned long)devpriv->rps_buf.logical_base);
for (i = 0; i < (10 * S626_RPSCLK_PER_US / 2); i++) {
jmp_adrs += 8;  /* Repeat to implement time delay: */
/* Jump to next RPS instruction. */
@@ -1894,9 +1893,9 @@ static int s626_ai_cmdtest(struct comedi_device *dev,

if (cmd->scan_begin_src == TRIG_TIMER) {
arg = cmd->convert_arg * cmd->scan_end_arg;
-   err |= comedi_check_trigger_arg_min(&cmd->
-   scan_begin_arg,
-   arg);
+   err |= comedi_check_trigger_arg_min(
+   &cmd->scan_begin_arg,
+   arg);
}
}

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


[PATCH] staging: pi433: Fix disordered switch case

2017-12-12 Thread Kari Argillander
Case: SHAPING_0_5 is writing DATAMODUL_MODLATION_SHAPE_0_3 value and
vice versa

Signed-off-by: Kari Argillander 
---
I have checked that defines are correct accounting to the datasheet.

My first patch. Hopefully everything goes like needs to.  I do not know
if this should go to stable because patch is for the staging area and it
is known to be unstable.  But because Greg is maintainer for both I do
not cc stable here.
---
 drivers/staging/pi433/rf69.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/pi433/rf69.c b/drivers/staging/pi433/rf69.c
index 8b6d68f10e8a..bc6d5b6cd186 100644
--- a/drivers/staging/pi433/rf69.c
+++ b/drivers/staging/pi433/rf69.c
@@ -133,8 +133,8 @@ int rf69_set_modulation_shaping(struct spi_device *spi,
switch (mod_shaping) {
case SHAPING_OFF: return rf69_read_mod_write(spi, 
REG_DATAMODUL, MASK_DATAMODUL_MODULATION_SHAPE, 
DATAMODUL_MODULATION_SHAPE_NONE);
case SHAPING_1_0: return rf69_read_mod_write(spi, 
REG_DATAMODUL, MASK_DATAMODUL_MODULATION_SHAPE, DATAMODUL_MODULATION_SHAPE_1_0);
-   case SHAPING_0_5: return rf69_read_mod_write(spi, 
REG_DATAMODUL, MASK_DATAMODUL_MODULATION_SHAPE, DATAMODUL_MODULATION_SHAPE_0_3);
-   case SHAPING_0_3: return rf69_read_mod_write(spi, 
REG_DATAMODUL, MASK_DATAMODUL_MODULATION_SHAPE, DATAMODUL_MODULATION_SHAPE_0_5);
+   case SHAPING_0_5: return rf69_read_mod_write(spi, 
REG_DATAMODUL, MASK_DATAMODUL_MODULATION_SHAPE, DATAMODUL_MODULATION_SHAPE_0_5);
+   case SHAPING_0_3: return rf69_read_mod_write(spi, 
REG_DATAMODUL, MASK_DATAMODUL_MODULATION_SHAPE, DATAMODUL_MODULATION_SHAPE_0_3);
default:
dev_dbg(&spi->dev, "set: illegal input param");
return -EINVAL;
-- 
2.15.1

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


binder epoll bug (was KASAN: use-after-free Read in __lock_acquire (2))

2017-12-12 Thread Eric Biggers
[+Cc binder maintainers and list]
[-Cc lockdep maintainers, USB maintainers, and other random people]

On Sat, Dec 02, 2017 at 08:08:01AM -0800, syzbot wrote:
> BUG: KASAN: use-after-free in __lock_acquire+0x465e/0x47f0
> kernel/locking/lockdep.c:3378
> Read of size 8 at addr 8801cd8e13f0 by task syzkaller236979/3086
> 
> CPU: 1 PID: 3086 Comm: syzkaller236979 Not tainted 4.15.0-rc1+ #115
> Hardware name: Google Google Compute Engine/Google Compute Engine,
> BIOS Google 01/01/2011
> Call Trace:
>  __dump_stack lib/dump_stack.c:17 [inline]
>  dump_stack+0x194/0x257 lib/dump_stack.c:53
>  print_address_description+0x73/0x250 mm/kasan/report.c:252
>  kasan_report_error mm/kasan/report.c:351 [inline]
>  kasan_report+0x25b/0x340 mm/kasan/report.c:409
>  __asan_report_load8_noabort+0x14/0x20 mm/kasan/report.c:430
>  __lock_acquire+0x465e/0x47f0 kernel/locking/lockdep.c:3378
>  lock_acquire+0x1d5/0x580 kernel/locking/lockdep.c:4004
>  __raw_spin_lock_irqsave include/linux/spinlock_api_smp.h:110 [inline]
>  _raw_spin_lock_irqsave+0x96/0xc0 kernel/locking/spinlock.c:159
>  remove_wait_queue+0x81/0x350 kernel/sched/wait.c:50
>  ep_remove_wait_queue fs/eventpoll.c:595 [inline]
>  ep_unregister_pollwait.isra.7+0x18c/0x590 fs/eventpoll.c:613
>  ep_free+0x13f/0x320 fs/eventpoll.c:830
>  ep_eventpoll_release+0x44/0x60 fs/eventpoll.c:862
>  __fput+0x333/0x7f0 fs/file_table.c:210
>  fput+0x15/0x20 fs/file_table.c:244
>  task_work_run+0x199/0x270 kernel/task_work.c:113
>  exit_task_work include/linux/task_work.h:22 [inline]
>  do_exit+0x9bb/0x1ae0 kernel/exit.c:865
>  do_group_exit+0x149/0x400 kernel/exit.c:968
>  SYSC_exit_group kernel/exit.c:979 [inline]
>  SyS_exit_group+0x1d/0x20 kernel/exit.c:977
>  do_syscall_32_irqs_on arch/x86/entry/common.c:327 [inline]
>  do_fast_syscall_32+0x3ee/0xf9d arch/x86/entry/common.c:389
>  entry_SYSENTER_compat+0x51/0x60 arch/x86/entry/entry_64_compat.S:125
> RIP: 0023:0xf7f97c79
> RSP: 002b:ffcb51bc EFLAGS: 0296 ORIG_RAX: 00fc
> RAX: ffda RBX:  RCX: 080f0298
> RDX:  RSI: 080d9b18 RDI: 080f02a0
> RBP: 0001 R08:  R09: 
> R10:  R11:  R12: 
> R13:  R14:  R15: 
> 
> Allocated by task 3086:
>  save_stack+0x43/0xd0 mm/kasan/kasan.c:447
>  set_track mm/kasan/kasan.c:459 [inline]
>  kasan_kmalloc+0xad/0xe0 mm/kasan/kasan.c:551
>  kmem_cache_alloc_trace+0x136/0x750 mm/slab.c:3613
>  kmalloc include/linux/slab.h:499 [inline]
>  kzalloc include/linux/slab.h:688 [inline]
>  binder_get_thread+0x1cf/0x870 drivers/android/binder.c:4184
>  binder_poll+0x8c/0x390 drivers/android/binder.c:4286
>  ep_item_poll.isra.10+0xec/0x320 fs/eventpoll.c:884
>  ep_insert+0x6a3/0x1b10 fs/eventpoll.c:1455
>  SYSC_epoll_ctl fs/eventpoll.c:2106 [inline]
>  SyS_epoll_ctl+0x12e4/0x1ab0 fs/eventpoll.c:1992
>  do_syscall_32_irqs_on arch/x86/entry/common.c:327 [inline]
>  do_fast_syscall_32+0x3ee/0xf9d arch/x86/entry/common.c:389
>  entry_SYSENTER_compat+0x51/0x60 arch/x86/entry/entry_64_compat.S:125
> 
> Freed by task 3086:
>  save_stack+0x43/0xd0 mm/kasan/kasan.c:447
>  set_track mm/kasan/kasan.c:459 [inline]
>  kasan_slab_free+0x71/0xc0 mm/kasan/kasan.c:524
>  __cache_free mm/slab.c:3491 [inline]
>  kfree+0xca/0x250 mm/slab.c:3806
>  binder_free_thread drivers/android/binder.c:4211 [inline]
>  binder_thread_dec_tmpref+0x27f/0x310 drivers/android/binder.c:1808
>  binder_thread_release+0x27d/0x540 drivers/android/binder.c:4275
>  binder_ioctl+0xc05/0x141a drivers/android/binder.c:4492
>  C_SYSC_ioctl fs/compat_ioctl.c:1473 [inline]
>  compat_SyS_ioctl+0x151/0x2a30 fs/compat_ioctl.c:1419
>  do_syscall_32_irqs_on arch/x86/entry/common.c:327 [inline]
>  do_fast_syscall_32+0x3ee/0xf9d arch/x86/entry/common.c:389
>  entry_SYSENTER_compat+0x51/0x60 arch/x86/entry/entry_64_compat.S:125

This is a bug in the binder driver.  binder_poll() tells the poll system to use
the wait queue embedded in the 'struct binder_thread', but then the
BINDER_THREAD_EXIT ioctl will free the 'struct binder_thread' out from under it.

Perhaps either the waitqueue should be associated with the 'struct binder_proc'
rather than the 'struct binder_thread', or binder_poll() should take a reference
to the 'struct binder_thread'.  But I'm not too familiar with binder or epoll,
so I don't know which solution is best.

Here is a program which reproduces the bug, assuming /dev/binder0 exists:

#include 
#include 
#include 
#include 

#define BINDER_THREAD_EXIT 0x40046208ul

int main()
{
int fd, epfd;
struct epoll_event event = { .events = EPOLLIN };

fd = open("/dev/binder0", O_RDONLY);
epfd = epoll_create(1000);
epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &event);
ioctl(f

Re: My Proposal...can we discuss on proposal.

2017-12-12 Thread Ms. Liza Wong

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


[PATCH net-next 0/6] hv_netvsc: minor changes

2017-12-12 Thread Stephen Hemminger
This includes minor cleanup of code in send and receive path and
also a new statistic to check for allocation failures. This also
eliminates some of the extra RCU when not needed.

There is a theoritical bug where buffered data could be blocked
for longer than necessary if the ring buffer got full. This
has not been seen in the wild, found by inspection.

The reference count between net device and internal RNDIS
is not needed.

Stephen Hemminger (6):
  hv_netvsc: copy_to_send buf can be void
  hv_netvsc: track memory allocation failures in ethtool stats
  hv_netvsc: simplify function args in receive status path
  hv_netvsc: pass netvsc_device to receive callback
  hv_netvsc: remove open_cnt reference count
  hv_netvsc: empty current transmit aggregation if flow blocked

 drivers/net/hyperv/hyperv_net.h   |  9 
 drivers/net/hyperv/netvsc.c   | 44 ---
 drivers/net/hyperv/netvsc_drv.c   | 33 +++--
 drivers/net/hyperv/rndis_filter.c | 29 +++---
 4 files changed, 47 insertions(+), 68 deletions(-)

-- 
2.11.0

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


[PATCH net-next 1/6] hv_netvsc: copy_to_send buf can be void

2017-12-12 Thread Stephen Hemminger
Since only caller does not care about return value.

Signed-off-by: Stephen Hemminger 
---
 drivers/net/hyperv/netvsc.c | 22 --
 1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c
index e4bcd202a56a..9407907c4988 100644
--- a/drivers/net/hyperv/netvsc.c
+++ b/drivers/net/hyperv/netvsc.c
@@ -696,19 +696,18 @@ static u32 netvsc_get_next_send_section(struct 
netvsc_device *net_device)
return NETVSC_INVALID_INDEX;
 }
 
-static u32 netvsc_copy_to_send_buf(struct netvsc_device *net_device,
-  unsigned int section_index,
-  u32 pend_size,
-  struct hv_netvsc_packet *packet,
-  struct rndis_message *rndis_msg,
-  struct hv_page_buffer *pb,
-  struct sk_buff *skb)
+static void netvsc_copy_to_send_buf(struct netvsc_device *net_device,
+   unsigned int section_index,
+   u32 pend_size,
+   struct hv_netvsc_packet *packet,
+   struct rndis_message *rndis_msg,
+   struct hv_page_buffer *pb,
+   struct sk_buff *skb)
 {
char *start = net_device->send_buf;
char *dest = start + (section_index * net_device->send_section_size)
 + pend_size;
int i;
-   u32 msg_size = 0;
u32 padding = 0;
u32 page_count = packet->cp_partial ? packet->rmsg_pgcnt :
packet->page_buf_cnt;
@@ -728,16 +727,11 @@ static u32 netvsc_copy_to_send_buf(struct netvsc_device 
*net_device,
u32 len = pb[i].len;
 
memcpy(dest, (src + offset), len);
-   msg_size += len;
dest += len;
}
 
-   if (padding) {
+   if (padding)
memset(dest, 0, padding);
-   msg_size += padding;
-   }
-
-   return msg_size;
 }
 
 static inline int netvsc_send_pkt(
-- 
2.11.0

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


[PATCH net-next 5/6] hv_netvsc: remove open_cnt reference count

2017-12-12 Thread Stephen Hemminger
There is only ever a single instance of network device object
referencing the internal rndis object. Therefore the open_cnt atomic
is not necessary.

Signed-off-by: Stephen Hemminger 
---
 drivers/net/hyperv/hyperv_net.h   |  2 --
 drivers/net/hyperv/netvsc.c   |  2 +-
 drivers/net/hyperv/rndis_filter.c | 10 +++---
 3 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
index eb01943b23c3..8ebe72bf89ff 100644
--- a/drivers/net/hyperv/hyperv_net.h
+++ b/drivers/net/hyperv/hyperv_net.h
@@ -810,8 +810,6 @@ struct netvsc_device {
u32 max_pkt; /* max number of pkt in one send, e.g. 8 */
u32 pkt_align; /* alignment bytes, e.g. 8 */
 
-   atomic_t open_cnt;
-
struct netvsc_channel chan_table[VRSS_CHANNEL_MAX];
 
struct rcu_head rcu;
diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c
index d8165407bcda..6dd97f232f87 100644
--- a/drivers/net/hyperv/netvsc.c
+++ b/drivers/net/hyperv/netvsc.c
@@ -73,7 +73,7 @@ static struct netvsc_device *alloc_net_device(void)
 
init_waitqueue_head(&net_device->wait_drain);
net_device->destroy = false;
-   atomic_set(&net_device->open_cnt, 0);
+
net_device->max_pkt = RNDIS_MAX_PKT_DEFAULT;
net_device->pkt_align = RNDIS_PKT_ALIGN_DEFAULT;
 
diff --git a/drivers/net/hyperv/rndis_filter.c 
b/drivers/net/hyperv/rndis_filter.c
index 025110a19d4a..035976949177 100644
--- a/drivers/net/hyperv/rndis_filter.c
+++ b/drivers/net/hyperv/rndis_filter.c
@@ -1362,9 +1362,6 @@ int rndis_filter_open(struct netvsc_device *nvdev)
if (!nvdev)
return -EINVAL;
 
-   if (atomic_inc_return(&nvdev->open_cnt) != 1)
-   return 0;
-
return rndis_filter_open_device(nvdev->extension);
 }
 
@@ -1373,13 +1370,12 @@ int rndis_filter_close(struct netvsc_device *nvdev)
if (!nvdev)
return -EINVAL;
 
-   if (atomic_dec_return(&nvdev->open_cnt) != 0)
-   return 0;
-
return rndis_filter_close_device(nvdev->extension);
 }
 
 bool rndis_filter_opened(const struct netvsc_device *nvdev)
 {
-   return atomic_read(&nvdev->open_cnt) > 0;
+   const struct rndis_device *dev = nvdev->extension;
+
+   return dev->state == RNDIS_DEV_DATAINITIALIZED;
 }
-- 
2.11.0

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


[PATCH net-next 3/6] hv_netvsc: simplify function args in receive status path

2017-12-12 Thread Stephen Hemminger
The caller (netvsc_receive) already has the net device pointer,
and should just pass that to functions rather than the hyperv device.
This eliminates several impossible error paths in the process.

Signed-off-by: Stephen Hemminger 
---
 drivers/net/hyperv/hyperv_net.h   |  3 +--
 drivers/net/hyperv/netvsc.c   |  2 +-
 drivers/net/hyperv/netvsc_drv.c   | 12 ++--
 drivers/net/hyperv/rndis_filter.c |  9 +++--
 4 files changed, 7 insertions(+), 19 deletions(-)

diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
index 42bbde1cbe45..6463b7f5aa00 100644
--- a/drivers/net/hyperv/hyperv_net.h
+++ b/drivers/net/hyperv/hyperv_net.h
@@ -199,7 +199,7 @@ int netvsc_send(struct net_device_context *ndc,
struct rndis_message *rndis_msg,
struct hv_page_buffer *page_buffer,
struct sk_buff *skb);
-void netvsc_linkstatus_callback(struct hv_device *device_obj,
+void netvsc_linkstatus_callback(struct net_device *net,
struct rndis_message *resp);
 int netvsc_recv_callback(struct net_device *net,
 struct vmbus_channel *channel,
@@ -222,7 +222,6 @@ int rndis_filter_set_rss_param(struct rndis_device *rdev,
   const u8 *key);
 int rndis_filter_receive(struct net_device *ndev,
 struct netvsc_device *net_dev,
-struct hv_device *dev,
 struct vmbus_channel *channel,
 void *data, u32 buflen);
 
diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c
index 9407907c4988..d8165407bcda 100644
--- a/drivers/net/hyperv/netvsc.c
+++ b/drivers/net/hyperv/netvsc.c
@@ -1077,7 +1077,7 @@ static int netvsc_receive(struct net_device *ndev,
u32 buflen = vmxferpage_packet->ranges[i].byte_count;
 
/* Pass it to the upper layer */
-   status = rndis_filter_receive(ndev, net_device, device,
+   status = rndis_filter_receive(ndev, net_device,
  channel, data, buflen);
}
 
diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index d16b68974d80..6f12f81fd8aa 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -656,22 +656,14 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct 
net_device *net)
 /*
  * netvsc_linkstatus_callback - Link up/down notification
  */
-void netvsc_linkstatus_callback(struct hv_device *device_obj,
+void netvsc_linkstatus_callback(struct net_device *net,
struct rndis_message *resp)
 {
struct rndis_indicate_status *indicate = &resp->msg.indicate_status;
-   struct net_device *net;
-   struct net_device_context *ndev_ctx;
+   struct net_device_context *ndev_ctx = netdev_priv(net);
struct netvsc_reconfig *event;
unsigned long flags;
 
-   net = hv_get_drvdata(device_obj);
-
-   if (!net)
-   return;
-
-   ndev_ctx = netdev_priv(net);
-
/* Update the physical link speed when changing to another vSwitch */
if (indicate->status == RNDIS_STATUS_LINK_SPEED_CHANGE) {
u32 speed;
diff --git a/drivers/net/hyperv/rndis_filter.c 
b/drivers/net/hyperv/rndis_filter.c
index 673492063307..901838b2bcc9 100644
--- a/drivers/net/hyperv/rndis_filter.c
+++ b/drivers/net/hyperv/rndis_filter.c
@@ -134,11 +134,9 @@ static void put_rndis_request(struct rndis_device *dev,
kfree(req);
 }
 
-static void dump_rndis_message(struct hv_device *hv_dev,
+static void dump_rndis_message(struct net_device *netdev,
   const struct rndis_message *rndis_msg)
 {
-   struct net_device *netdev = hv_get_drvdata(hv_dev);
-
switch (rndis_msg->ndis_msg_type) {
case RNDIS_MSG_PACKET:
netdev_dbg(netdev, "RNDIS_MSG_PACKET (len %u, "
@@ -397,7 +395,6 @@ static int rndis_filter_receive_data(struct net_device 
*ndev,
 
 int rndis_filter_receive(struct net_device *ndev,
 struct netvsc_device *net_dev,
-struct hv_device *dev,
 struct vmbus_channel *channel,
 void *data, u32 buflen)
 {
@@ -419,7 +416,7 @@ int rndis_filter_receive(struct net_device *ndev,
}
 
if (netif_msg_rx_status(net_device_ctx))
-   dump_rndis_message(dev, rndis_msg);
+   dump_rndis_message(ndev, rndis_msg);
 
switch (rndis_msg->ndis_msg_type) {
case RNDIS_MSG_PACKET:
@@ -434,7 +431,7 @@ int rndis_filter_receive(struct net_device *ndev,
 
case RNDIS_MSG_INDICATE:
/* notification msgs */
-   netvsc_linkstatus_callback(dev, rndis_msg);
+   netvsc_linkstatus_callback(ndev, rndis_msg);
break;
default:
netdev_err(ndev,
-- 
2.11.0

___

[PATCH net-next 2/6] hv_netvsc: track memory allocation failures in ethtool stats

2017-12-12 Thread Stephen Hemminger
When skb can not be allocated, update ethtool statisitics
rather than rx_dropped which is intended for netif_receive.

Signed-off-by: Stephen Hemminger 
---
 drivers/net/hyperv/hyperv_net.h | 1 +
 drivers/net/hyperv/netvsc_drv.c | 5 +++--
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
index 3d940c67ea94..42bbde1cbe45 100644
--- a/drivers/net/hyperv/hyperv_net.h
+++ b/drivers/net/hyperv/hyperv_net.h
@@ -692,6 +692,7 @@ struct netvsc_ethtool_stats {
unsigned long tx_busy;
unsigned long tx_send_full;
unsigned long rx_comp_busy;
+   unsigned long rx_no_memory;
unsigned long stop_queue;
unsigned long wake_queue;
 };
diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index dc70de674ca9..d16b68974d80 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -777,8 +777,8 @@ int netvsc_recv_callback(struct net_device *net,
skb = netvsc_alloc_recv_skb(net, &nvchan->napi,
csum_info, vlan, data, len);
if (unlikely(!skb)) {
+   ++net_device_ctx->eth_stats.rx_no_memory;
 drop:
-   ++net->stats.rx_dropped;
rcu_read_unlock();
return NVSP_STAT_FAIL;
}
@@ -1129,12 +1129,13 @@ static const struct {
u16 offset;
 } netvsc_stats[] = {
{ "tx_scattered", offsetof(struct netvsc_ethtool_stats, tx_scattered) },
-   { "tx_no_memory",  offsetof(struct netvsc_ethtool_stats, tx_no_memory) 
},
+   { "tx_no_memory", offsetof(struct netvsc_ethtool_stats, tx_no_memory) },
{ "tx_no_space",  offsetof(struct netvsc_ethtool_stats, tx_no_space) },
{ "tx_too_big",   offsetof(struct netvsc_ethtool_stats, tx_too_big) },
{ "tx_busy",  offsetof(struct netvsc_ethtool_stats, tx_busy) },
{ "tx_send_full", offsetof(struct netvsc_ethtool_stats, tx_send_full) },
{ "rx_comp_busy", offsetof(struct netvsc_ethtool_stats, rx_comp_busy) },
+   { "rx_no_memory", offsetof(struct netvsc_ethtool_stats, rx_no_memory) },
{ "stop_queue", offsetof(struct netvsc_ethtool_stats, stop_queue) },
{ "wake_queue", offsetof(struct netvsc_ethtool_stats, wake_queue) },
 }, vf_stats[] = {
-- 
2.11.0

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


[PATCH net-next 6/6] hv_netvsc: empty current transmit aggregation if flow blocked

2017-12-12 Thread Stephen Hemminger
If the transmit queue is known full, then don't keep aggregating
data. And the cp_partial flag which indicates that the current
aggregation buffer is full can be folded in to avoid more
conditionals.

Signed-off-by: Stephen Hemminger 
---
 drivers/net/hyperv/hyperv_net.h   |  2 +-
 drivers/net/hyperv/netvsc.c   | 20 ++--
 drivers/net/hyperv/netvsc_drv.c   |  2 +-
 drivers/net/hyperv/rndis_filter.c |  3 +--
 4 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
index 8ebe72bf89ff..c46ecd8cb7cd 100644
--- a/drivers/net/hyperv/hyperv_net.h
+++ b/drivers/net/hyperv/hyperv_net.h
@@ -194,7 +194,7 @@ struct netvsc_device *netvsc_device_add(struct hv_device 
*device,
const struct netvsc_device_info *info);
 int netvsc_alloc_recv_comp_ring(struct netvsc_device *net_device, u32 q_idx);
 void netvsc_device_remove(struct hv_device *device);
-int netvsc_send(struct net_device_context *ndc,
+int netvsc_send(struct net_device *net,
struct hv_netvsc_packet *packet,
struct rndis_message *rndis_msg,
struct hv_page_buffer *page_buffer,
diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c
index 6dd97f232f87..66cfd0eb3434 100644
--- a/drivers/net/hyperv/netvsc.c
+++ b/drivers/net/hyperv/netvsc.c
@@ -702,7 +702,7 @@ static void netvsc_copy_to_send_buf(struct netvsc_device 
*net_device,
struct hv_netvsc_packet *packet,
struct rndis_message *rndis_msg,
struct hv_page_buffer *pb,
-   struct sk_buff *skb)
+   bool xmit_more)
 {
char *start = net_device->send_buf;
char *dest = start + (section_index * net_device->send_section_size)
@@ -715,7 +715,7 @@ static void netvsc_copy_to_send_buf(struct netvsc_device 
*net_device,
 
/* Add padding */
remain = packet->total_data_buflen & (net_device->pkt_align - 1);
-   if (skb->xmit_more && remain && !packet->cp_partial) {
+   if (xmit_more && remain) {
padding = net_device->pkt_align - remain;
rndis_msg->msg_len += padding;
packet->total_data_buflen += padding;
@@ -824,12 +824,13 @@ static inline void move_pkt_msd(struct hv_netvsc_packet 
**msd_send,
 }
 
 /* RCU already held by caller */
-int netvsc_send(struct net_device_context *ndev_ctx,
+int netvsc_send(struct net_device *ndev,
struct hv_netvsc_packet *packet,
struct rndis_message *rndis_msg,
struct hv_page_buffer *pb,
struct sk_buff *skb)
 {
+   struct net_device_context *ndev_ctx = netdev_priv(ndev);
struct netvsc_device *net_device
= rcu_dereference_bh(ndev_ctx->nvdev);
struct hv_device *device = ndev_ctx->device_ctx;
@@ -840,7 +841,7 @@ int netvsc_send(struct net_device_context *ndev_ctx,
struct multi_send_data *msdp;
struct hv_netvsc_packet *msd_send = NULL, *cur_send = NULL;
struct sk_buff *msd_skb = NULL;
-   bool try_batch;
+   bool try_batch, xmit_more;
 
/* If device is rescinded, return error and packet will get dropped. */
if (unlikely(!net_device || net_device->destroy))
@@ -891,10 +892,17 @@ int netvsc_send(struct net_device_context *ndev_ctx,
}
}
 
+   /* Keep aggregating only if stack says more data is coming
+* and not doing mixed modes send and not flow blocked
+*/
+   xmit_more = skb->xmit_more &&
+   !packet->cp_partial &&
+   !netif_xmit_stopped(netdev_get_tx_queue(ndev, packet->q_idx));
+
if (section_index != NETVSC_INVALID_INDEX) {
netvsc_copy_to_send_buf(net_device,
section_index, msd_len,
-   packet, rndis_msg, pb, skb);
+   packet, rndis_msg, pb, xmit_more);
 
packet->send_buf_index = section_index;
 
@@ -914,7 +922,7 @@ int netvsc_send(struct net_device_context *ndev_ctx,
if (msdp->skb)
dev_consume_skb_any(msdp->skb);
 
-   if (skb->xmit_more && !packet->cp_partial) {
+   if (xmit_more) {
msdp->skb = skb;
msdp->pkt = packet;
msdp->count++;
diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index 36091ed570e2..3737c1fefb04 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -630,7 +630,7 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct 
net_device *net)
/* timestamp packet in software */
skb_tx_timestamp(skb);
 
-   ret = netvsc_send(net_device_ctx, packet, rndis_msg,

[PATCH net-next 4/6] hv_netvsc: pass netvsc_device to receive callback

2017-12-12 Thread Stephen Hemminger
The netvsc_receive_callback function was using RCU to find the
appropriate underlying netvsc_device. Since calling function already
had that pointer, this was unnecessary.

Signed-off-by: Stephen Hemminger 
---
 drivers/net/hyperv/hyperv_net.h   |  1 +
 drivers/net/hyperv/netvsc_drv.c   | 14 ++
 drivers/net/hyperv/rndis_filter.c |  7 +--
 3 files changed, 8 insertions(+), 14 deletions(-)

diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
index 6463b7f5aa00..eb01943b23c3 100644
--- a/drivers/net/hyperv/hyperv_net.h
+++ b/drivers/net/hyperv/hyperv_net.h
@@ -202,6 +202,7 @@ int netvsc_send(struct net_device_context *ndc,
 void netvsc_linkstatus_callback(struct net_device *net,
struct rndis_message *resp);
 int netvsc_recv_callback(struct net_device *net,
+struct netvsc_device *nvdev,
 struct vmbus_channel *channel,
 void  *data, u32 len,
 const struct ndis_tcp_ip_checksum_info *csum_info,
diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index 6f12f81fd8aa..36091ed570e2 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -743,34 +743,26 @@ static struct sk_buff *netvsc_alloc_recv_skb(struct 
net_device *net,
  * "wire" on the specified device.
  */
 int netvsc_recv_callback(struct net_device *net,
+struct netvsc_device *net_device,
 struct vmbus_channel *channel,
 void  *data, u32 len,
 const struct ndis_tcp_ip_checksum_info *csum_info,
 const struct ndis_pkt_8021q_info *vlan)
 {
struct net_device_context *net_device_ctx = netdev_priv(net);
-   struct netvsc_device *net_device;
u16 q_idx = channel->offermsg.offer.sub_channel_index;
-   struct netvsc_channel *nvchan;
+   struct netvsc_channel *nvchan = &net_device->chan_table[q_idx];
struct sk_buff *skb;
struct netvsc_stats *rx_stats;
 
if (net->reg_state != NETREG_REGISTERED)
return NVSP_STAT_FAIL;
 
-   rcu_read_lock();
-   net_device = rcu_dereference(net_device_ctx->nvdev);
-   if (unlikely(!net_device))
-   goto drop;
-
-   nvchan = &net_device->chan_table[q_idx];
-
/* Allocate a skb - TODO direct I/O to pages? */
skb = netvsc_alloc_recv_skb(net, &nvchan->napi,
csum_info, vlan, data, len);
if (unlikely(!skb)) {
++net_device_ctx->eth_stats.rx_no_memory;
-drop:
rcu_read_unlock();
return NVSP_STAT_FAIL;
}
@@ -794,8 +786,6 @@ int netvsc_recv_callback(struct net_device *net,
u64_stats_update_end(&rx_stats->syncp);
 
napi_gro_receive(&nvchan->napi, skb);
-   rcu_read_unlock();
-
return 0;
 }
 
diff --git a/drivers/net/hyperv/rndis_filter.c 
b/drivers/net/hyperv/rndis_filter.c
index 901838b2bcc9..025110a19d4a 100644
--- a/drivers/net/hyperv/rndis_filter.c
+++ b/drivers/net/hyperv/rndis_filter.c
@@ -352,6 +352,7 @@ static inline void *rndis_get_ppi(struct rndis_packet 
*rpkt, u32 type)
 }
 
 static int rndis_filter_receive_data(struct net_device *ndev,
+struct netvsc_device *nvdev,
 struct rndis_device *dev,
 struct rndis_message *msg,
 struct vmbus_channel *channel,
@@ -388,7 +389,8 @@ static int rndis_filter_receive_data(struct net_device 
*ndev,
 */
data = (void *)((unsigned long)data + data_offset);
csum_info = rndis_get_ppi(rndis_pkt, TCPIP_CHKSUM_PKTINFO);
-   return netvsc_recv_callback(ndev, channel,
+
+   return netvsc_recv_callback(ndev, nvdev, channel,
data, rndis_pkt->data_len,
csum_info, vlan);
 }
@@ -420,7 +422,8 @@ int rndis_filter_receive(struct net_device *ndev,
 
switch (rndis_msg->ndis_msg_type) {
case RNDIS_MSG_PACKET:
-   return rndis_filter_receive_data(ndev, rndis_dev, rndis_msg,
+   return rndis_filter_receive_data(ndev, net_dev,
+rndis_dev, rndis_msg,
 channel, data, buflen);
case RNDIS_MSG_INIT_C:
case RNDIS_MSG_QUERY_C:
-- 
2.11.0

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


RE: [PATCH 3/6] x86/hyper-v: reenlightenment notifications support

2017-12-12 Thread Michael Kelley (EOSG)
On Fri, Dec 08, 2017 at 11:49:57AM +0100, Vitaly Kuznetsov wrote:

> -Original Message-
> From: Vitaly Kuznetsov [mailto:vkuzn...@redhat.com]
> Sent: Friday, December 8, 2017 2:50 AM
> To: k...@vger.kernel.org; x...@kernel.org
> Cc: Paolo Bonzini ; Radim Krčmář ; 
> Thomas
> Gleixner ; Ingo Molnar ; H. Peter Anvin
> ; KY Srinivasan ; Haiyang Zhang
> ; Stephen Hemminger ; Michael
> Kelley (EOSG) ; Andy Lutomirski 
> ;
> Mohammed Gamal ; Cathy Avery ; linux-
> ker...@vger.kernel.org; de...@linuxdriverproject.org
> Subject: [PATCH 3/6] x86/hyper-v: reenlightenment notifications support
> 
> Hyper-V supports Live Migration notification. This is supposed to be used in 
> conjunction with
> TSC emulation: when we are migrated to a host with different TSC frequency 
> for some short
> period host emulates our accesses to TSC and sends us an interrupt to notify 
> about the event.
> When we're done updating everything we can disable TSC emulation and 
> everything will start
> working fast again.
> 
> We didn't need these notifications before as Hyper-V guests are not supposed 
> to use TSC as a
> clocksource: in Linux we even mark it as unstable on boot. Guests normally 
> use 'tsc page'
> clocksouce and host updates its values on migrations automatically.
> 
> Things change when we want to run nested virtualization: even when we pass 
> through PV
> clocksources (kvm-clock or tsc page) to our guests we need to know TSC 
> frequency and when it
> changes.
> 
> Hyper-V Top Level Functional Specification (as of v5.0b) wrongly specifies
> EAX:BIT(12) of CPUID:0x4009 as the feature identification bit. The right 
> one to check is
> EAX:BIT(13) of CPUID:0x4003. I was assured that the fix in on the way.
> 
> Signed-off-by: Vitaly Kuznetsov 

[snip]

> diff --git a/arch/x86/include/asm/irq_vectors.h
> b/arch/x86/include/asm/irq_vectors.h
> index 67421f649cfa..e71c1120426b 100644
> --- a/arch/x86/include/asm/irq_vectors.h
> +++ b/arch/x86/include/asm/irq_vectors.h
> @@ -103,7 +103,12 @@
>  #endif
> 
>  #define MANAGED_IRQ_SHUTDOWN_VECTOR  0xef
> -#define LOCAL_TIMER_VECTOR   0xee
> +
> +#if IS_ENABLED(CONFIG_HYPERV)
> +#define HYPERV_REENLIGHTENMENT_VECTOR0xee
> +#endif
> +
> +#define LOCAL_TIMER_VECTOR   0xed
> 
>  #define NR_VECTORS256

[snip]

Since you are pre-allocating a new vector, would you want to update the 
irq_cpustat_t
data structure and your interrupt handler to count the occurrences of these 
interrupts,
and update arch_show_interrupts() to show the count?  Then cat /proc/interrupts
will show the count.   The reenlightenment interrupts will presumably be rare, 
but so
are some of the others that are already counted and displayed, and it seems like
consistency should be maintained.

Michael

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