siano: add high level SDIO interface driver for SMS based cards
Hi Alexey,
I numbered your comments and append all answers to the end of this email.
Quoted 40 lines · Alexey Klimov
From: Alexey Klimov <[email protected]>
Subject: Re: [PATCH 1/1] siano: add high level SDIO interface driver for SMS based cards
To: "Uri Shkolnik" <[email protected]>
Cc: "Mauro Carvalho Chehab" <[email protected]>, "Michael Krufky" <[email protected]>, [email protected]
Date: Friday, March 13, 2009, 12:46 AM
Hello, UriQuoted 5 lines · Uri Shkolnik
# HG changeset patch
# User Uri Shkolnik <[email protected]>
# Date 1236865697 -7200
# Node ID7352ee1288f651d19d58c7bb479a98f070ad98e6# Parent
3392722cc5b687586c4d898b73050ab6e59bf401Quoted 1 line
siano: add high level SDIO interface driver for SMS
based cards
Quoted 12 lines
From: Uri Shkolnik <[email protected]>
This patch provides SDIO interface driver for SMS (Siano Mobile Silicon) based devices. The patch includes SMS high level SDIO driver and requires patching the kernel SDIO stack, those stack patches had been provided previously.
I would like to thank Pierre Ossman, MMC maintainer, who wrote this driver.
Quoted 6 lines
Priority: normal
Signed-off-by Pierre Ossman <[email protected]>Signed-off-by Uri Shkolnik <[email protected]>diff -r
3392722cc5b6-r7352ee1288f6
linux/drivers/media/dvb/siano/smssdio.cQuoted 1 line
--- /dev/null Thu Jan 01 00:00:00
1970 +0000
Quoted 1 line
+++
b/linux/drivers/media/dvb/siano/smssdio.c
Thu Mar 12 15:48:17 2009 +0200
Quoted 8 lines
Review line 2
Quoted 3 lines
(quoted diff) +2
-0@@ -0,0 +1,356 @@ +/* + * smssdio.c - Siano 1xxx SDIO interfacedriver
Review line 4
Quoted 2 lines
(quoted diff) +2
-0+ * + * Copyright 2008 Pierre OssmanI'm sorry, but may be 2009 ?
[ #1 ]
Quoted 130 lines
Review line 9
Quoted 6 lines
(quoted diff) +5
-0+ * + * Based on code by Siano Mobile Silicon, Inc., + * Copyright (C) 2006-2008, Uri Shkolnik + * + * This program is free software; you canredistribute it and/or modify
Review line 10
Quoted 1 line
(quoted diff) +1
-0+ * it under the terms of the GNU General PublicLicense as published by
Review line 11
Quoted 1 line
(quoted diff) +1
-0+ * the Free Software Foundation; either version 2 ofthe License, or (at
Review line 15
Quoted 4 lines
(quoted diff) +4
-0+ * your option) any later version. + * + * + * This hardware is a bit odd in that all transfersshould be done
Review line 16
Quoted 1 line
(quoted diff) +1
-0+ * to/from the SMSSDIO_DATA register, yet the"increase address" bit
Review line 19
Quoted 3 lines
(quoted diff) +3
-0+ * always needs to be set. + * + * Also, buffers from the card are always aligned to128 byte
Review line 28
Quoted 9 lines
(quoted diff) +9
-0+ * boundaries. + */ + +/* + * General cleanup notes: + * + * - only typedefs should be name *_t + * + * - use ERR_PTR and friends for
smscore_register_device()Quoted 9 lines
(quoted diff) +9
-0+ * + * - smscore_getbuffer should zero fields + * + * Fix stop command + */ + +#include <linux/moduleparam.h> +#include <linux/firmware.h> +#include <linux/delay.h>Review line 47
Quoted 10 lines
(quoted diff) +10
-0+#include <linux/mmc/card.h> +#include <linux/mmc/sdio_func.h> +#include <linux/mmc/sdio_ids.h> + +#include "smscoreapi.h" +#include "sms-cards.h" + +/* Registers */ + +#define SMSSDIO_DATA
0x00Review line 48
Quoted 1 line
(quoted diff) +1
-0+#define SMSSDIO_INT
0x04Review line 51
Quoted 3 lines
(quoted diff) +3
-0+ +static const struct sdio_device_id smssdio_ids[] = { + {SDIO_DEVICE(SDIO_VENDOR_ID_SIANO,
SDIO_DEVICE_ID_SIANO_STELLAR),Review line 52
Quoted 1 line
(quoted diff) +1
-0+ .driver_data =
SMS1XXX_BOARD_SIANO_STELLAR},Review line 53
Quoted 1 line
(quoted diff) +1
-0+ {SDIO_DEVICE(SDIO_VENDOR_ID_SIANO,
SDIO_DEVICE_ID_SIANO_NOVA_A0),Review line 54
Quoted 1 line
(quoted diff) +1
-0+ .driver_data =
SMS1XXX_BOARD_SIANO_NOVA_A},Review line 55
Quoted 1 line
(quoted diff) +1
-0+ {SDIO_DEVICE(SDIO_VENDOR_ID_SIANO,
SDIO_DEVICE_ID_SIANO_NOVA_B0),Review line 56
Quoted 1 line
(quoted diff) +1
-0+ .driver_data =
SMS1XXX_BOARD_SIANO_NOVA_B},Review line 57
Quoted 1 line
(quoted diff) +1
-0+ {SDIO_DEVICE(SDIO_VENDOR_ID_SIANO,
SDIO_DEVICE_ID_SIANO_VEGA_A0),Review line 58
Quoted 1 line
(quoted diff) +1
-0+ .driver_data =
SMS1XXX_BOARD_SIANO_VEGA},Review line 59
Quoted 1 line
(quoted diff) +1
-0+ {SDIO_DEVICE(SDIO_VENDOR_ID_SIANO,
SDIO_DEVICE_ID_SIANO_VENICE),Review line 60
Quoted 1 line
(quoted diff) +1
-0+ .driver_data =
SMS1XXX_BOARD_SIANO_VEGA},Review line 71
Quoted 11 lines
(quoted diff) +11
-0+ { /* end: all zeroes */ }, +}; + +MODULE_DEVICE_TABLE(sdio, smssdio_ids); + +struct smssdio_device { + struct sdio_func *func; + + struct smscore_device_t *coredev; + + struct smscore_buffer_t
*split_cb;Review line 73
Quoted 3 lines
(quoted diff) +2
-0+}; ++/*******************************************************************/
Review line 74
Quoted 1 line
(quoted diff) +1
-0+/* Siano core callbacks
*/Quoted 1 line
+/*******************************************************************/
Review
Quoted 2 lines
(quoted diff) +2
-0+ +static int smssdio_sendrequest(void *context, void*buffer,
size_tsize)Review
Quoted 9 lines
(quoted diff) +9
-0+{ + int ret; + struct smssdio_device *smsdev; + + smsdev = context; + + sdio_claim_host(smsdev->func); + + while (size >=
smsdev->func->cur_blksize) {Quoted 1 line
+ ret =
sdio_write_blocks(smsdev->func, SMSSDIO_DATA, buffer, 1);Quoted 2 lines
+ if (ret)
+goto out;
Quoted 2 lines
+
+ buffer +=
smsdev->func->cur_blksize;Quoted 1 line
+ size -=
smsdev->func->cur_blksize;Quoted 4 lines
+ }
+
+ if (size) {
+ ret =sdio_write_bytes(smsdev->func,
SMSSDIO_DATA,Quoted 1 line
+
buffer, size);
Quoted 8 lines
Quoted 2 lines
+ if (ret)
+goto out;
Quoted 1 line
+ }
Do you really need this check and goto ? Without them, as i see, the algorithm will do the same.
[ #2 ]
Quoted 320 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ +out: +
sdio_release_host(smsdev->func);Review
Quoted 5 lines
(quoted diff) +4
-0+ + return ret; +} ++/*******************************************************************/
Quoted 1 line
+/* SDIO callbacks
*/Quoted 1 line
+/*******************************************************************/
Review
Quoted 2 lines
(quoted diff) +2
-0+ +static void smssdio_interrupt(struct sdio_func*func)
Review
Quoted 12 lines
(quoted diff) +12
-0+{ + int ret, isr; + + struct smssdio_device *smsdev; + struct smscore_buffer_t *cb; + struct SmsMsgHdr_ST *hdr; + size_t size; + + smsdev = sdio_get_drvdata(func); + + /* + * The interruptregister has no defined meaning. It is just
Quoted 1 line
+ * a way of turning of
the level triggered interrupt.
Quoted 2 lines
+ */
+ isr = sdio_readb(func,
SMSSDIO_INT, &ret);Quoted 2 lines
+ if (ret) {
+dev_err(&smsdev->func->dev,
Quoted 1 line
+
"Unable to read interrupt register!\n");
Quoted 4 lines
+ return;
+ }
+
+ if (smsdev->split_cb== NULL){
Quoted 1 line
+ cb =
smscore_getbuffer(smsdev->coredev);Quoted 2 lines
+ if (!cb) {
+dev_err(&smsdev->func->dev,
Quoted 1 line
+
"Unable to allocate
data buffer!\n");Quoted 1 line
+
return;
Quoted 3 lines
+ }
+
+ ret =
sdio_read_blocks(smsdev->func, cb->p, SMSSDIO_DATA, 1);Quoted 2 lines
+ if (ret) {
+dev_err(&smsdev->func->dev,
Quoted 1 line
+
"Error %d reading
initial block!\n", ret);Quoted 1 line
+
return;
Quoted 3 lines
+ }
+
+ hdr =
cb->p;Quoted 2 lines
+
+ if(
hdr->msgFlags&MSG_HDR_FLAG_SPLIT_MSG) {Quoted 1 line
+
smsdev->split_cb= cb;Quoted 1 line
+
return;
Quoted 3 lines
+ }
+
+ size =
hdr->msgLength-smsdev->func->cur_blksize;Quoted 2 lines
+ } else {
+ cb =
smsdev->split_cb;Quoted 1 line
+ hdr =
cb->p;Quoted 2 lines
+
+ size =
hdr->msgLength-sizeof(struct SmsMsgHdr_ST);Quoted 2 lines
+
+
smsdev->split_cb= NULL;Quoted 3 lines
+ }
+
+ if (hdr->msgLength>
smsdev->func->cur_blksize) {Quoted 3 lines
+ void *buffer;
+
+ size =
ALIGN(size, 128);Quoted 1 line
+ buffer =
cb->p+hdr->msgLength;Quoted 2 lines
+
+
BUG_ON(smsdev->func->cur_blksize != 128);Quoted 3 lines
+
+ /*
+ *First attempt to transfer all of it in one go...
Quoted 2 lines
+ */
+ ret =sdio_read_blocks(smsdev->func, buffer,
Quoted 1 line
+
SMSSDIO_DATA, size / 128);Quoted 1 line
+ if (ret
&& ret !=
-EINVAL) {Quoted 1 line
+
smscore_putbuffer(smsdev->coredev,
cb);Quoted 1 line
+
dev_err(&smsdev->func->dev,
Quoted 1 line
+
"Error %d reading data
from card!\n", ret);Quoted 1 line
+
return;
Quoted 4 lines
+ }
+
+ /*
+ *..then fall back to one block at a time if that is
Quoted 1 line
+ *
not possible...
Quoted 2 lines
+ *
+ *(we have to do this manually because of the
Quoted 1 line
+ *
problem with the "increase address" bit)
Quoted 2 lines
+ */
+ if (ret ==
-EINVAL) {Quoted 1 line
+
while (size) {
Quoted 1 line
+
ret =
sdio_read_blocks(smsdev->func,Quoted 1 line
+
buffer,SMSSDIO_DATA, 1);Quoted 1 line
+
if (ret) {
Quoted 1 line
+
smscore_putbuffer(smsdev->coredev, cb);Quoted 1 line
+
dev_err(&smsdev->func->dev,Quoted 1 line
+
"Error %d reading "Quoted 1 line
+
"data from card!\n", ret);Quoted 1 line
+
return;Quoted 1 line
+
}
Quoted 2 lines
+
+buffer +=
smsdev->func->cur_blksize;Quoted 1 line
+
if (size >
smsdev->func->cur_blksize)Quoted 1 line
+
size -=smsdev->func->cur_blksize;Quoted 1 line
+
else
Quoted 1 line
+
size = 0;Quoted 1 line
+
}
Review
Quoted 7 lines
+ }
+ }(quoted diff) +5
-0+ + cb->size = hdr->msgLength; + cb->offset = 0; + +
smscore_onresponse(smsdev->coredev, cb);Review
Quoted 4 lines
(quoted diff) +4
-0+} + +static int smssdio_probe(struct sdio_func *func, +const struct
sdio_device_id
*id)Review
Quoted 10 lines
(quoted diff) +10
-0+{ + int ret; + + int board_id; + struct smssdio_device *smsdev; + struct smsdevice_params_t params; + + board_id = id->driver_data; + + smsdev = kzalloc(sizeof(struct
smssdio_device),GFP_KERNEL);Quoted 2 lines
+ if (!smsdev)
+ return
-ENOMEM;Review
Quoted 4 lines
(quoted diff) +4
-0+ + smsdev->func = func; + + memset(¶ms, 0,
sizeof(struct smsdevice_params_t));Quoted 2 lines
+
+ params.device =
&func->dev;Quoted 1 line
+ params.buffer_size =
0x5000; /* ?? */
Quoted 1 line
+ params.num_buffers =
22; /* ?? */
Quoted 3 lines
+ params.context = smsdev;
+
+ snprintf(params.devpath,sizeof(params.devpath),
Quoted 1 line
+
"sdio\\%s",
sdio_func_id(func));Quoted 2 lines
+
+ params.sendrequest_handler =
smssdio_sendrequest;Quoted 2 lines
+
+ params.device_type =sms_get_board(board_id)->type;
Quoted 2 lines
+
+ if (params.device_type !=
SMS_STELLAR)Quoted 1 line
+ params.flags |=
SMS_DEVICE_FAMILY2;Quoted 3 lines
+ else {
+ /*
+ *FIXME: Stellar needs special handling...
Quoted 6 lines
+ */
+ ret =-ENODEV;
+ goto free;
+ }
+
+ ret =smscore_register_device(¶ms,
&smsdev->coredev);Quoted 4 lines
+ if (ret < 0)
+ goto free;
+
+
smscore_set_board_id(smsdev->coredev, board_id);Review
Quoted 8 lines
(quoted diff) +8
-0+ + sdio_claim_host(func); + + ret = sdio_enable_func(func); + if (ret) + goto release; + + ret = sdio_set_block_size(func,128);
Quoted 4 lines
+ if (ret)
+ goto disable;
+
+ ret = sdio_claim_irq(func,
smssdio_interrupt);Review
Quoted 8 lines
+ if (ret)
+ goto disable;(quoted diff) +6
-0+ + sdio_set_drvdata(func, smsdev); + + sdio_release_host(func); + + ret =
smscore_start_device(smsdev->coredev);Review
Quoted 13 lines
+ if (ret < 0)
+ goto reclaim;(quoted diff) +11
-0+ + return 0; + +reclaim: + sdio_claim_host(func); + sdio_release_irq(func); +disable: + sdio_disable_func(func); +release: + sdio_release_host(func); +
smscore_unregister_device(smsdev->coredev);Quoted 5 lines
(quoted diff) +5
-0+free: + kfree(smsdev); + + return ret; +}Review
Quoted 10 lines
(quoted diff) +10
-0+ +static void smssdio_remove(struct sdio_func *func) +{ + struct smssdio_device *smsdev; + + smsdev = sdio_get_drvdata(func); + + /* FIXME: racy! */ + if (smsdev->split_cb) +
smscore_putbuffer(smsdev->coredev, smsdev->split_cb);
Quoted 4 lines
May be you want to introduce mutex lock or even spinlock to prevent race
condition ?
[ #3 ]
Quoted 27 lines
Quoted 3 lines
+
+
smscore_unregister_device(smsdev->coredev);Quoted 7 lines
(quoted diff) +6
-0+ + sdio_claim_host(func); + sdio_release_irq(func); + sdio_disable_func(func); + sdio_release_host(func); +Review
Quoted 10 lines
(quoted diff) +10
-0+ kfree(smsdev); +} + +static struct sdio_driver smssdio_driver = { + .name = "smssdio", + .id_table = smssdio_ids, + .probe = smssdio_probe, + .remove = smssdio_remove, +}; ++/*******************************************************************/
Quoted 1 line
+/* Module functions
*/Quoted 1 line
Quoted 6 lines
+/*******************************************************************/
Review
Quoted 2 lines
(quoted diff) +2
-0+ +int smssdio_register(void)Dont you want to make this function static int
__init?
[ #4 ]
Quoted 9 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+{ + int ret = 0; + + printk(KERN_INFO "smssdio: SianoSMS1xxx SDIO driver\n");
Quoted 1 line
+ printk(KERN_INFO "smssdio:
Copyright Pierre Ossman\n");
Quoted 2 lines
+
+ ret =
Quoted 8 lines
sdio_register_driver(&smssdio_driver);Review
Quoted 5 lines
(quoted diff) +5
-0+ + return ret; +} + +void smssdio_unregister(void)And the same here - static void
__exit?
[#5 ]
Quoted 4 lines
Quoted 3 lines
+{
+
sdio_unregister_driver(&smssdio_driver);
Quoted 12 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+} + +MODULE_DESCRIPTION("Siano SMS1xxx SDIO driver"); +MODULE_AUTHOR("Pierre Ossman"); +MODULE_LICENSE("GPL");Good luck,
Signature · 1 line
best regards, Klimov Alexey
First, before anything else, I would like to thank you for the detailed review.
Regarding this patch and your comments regarding it - A preliminary fact must be shared. This patch had been written by Pierre Ossman, who is the Linux kernel MMC maintainer. He wrote this patch back in summer 2008, and the commit of it has been delayed from various reasons.
This fact establishes two additional issues -
1) Regarding your comment #1, yes it should be 2008... (and not 2009)
2) Regarding re-submitting this particular patch, with some corrections - As it has been requested clearly by Pierre, I must not alter his file, only patch on top of it (e.g. commit it and only than patch it further), unless, of course, if something is broken (than I'll contact him and ask his permission to alter this principal patch). But since this driver passes various QA tests and it works fine (and since your comments do not indicate broken things, just suggest improvements), I must obey Pierre's request. So if needed, we'll create a second, following patch, in order to answer your (and others) comments.
Comment #2 - True, this is redundant code, and it will be deleted.
Comment #3 - The first half of a "split message" (which is a device --> host message that is combined from exactly two parts), may be submitted and before the second half is process, the device is removed. Actually, there is no risk with this, since all buffers (dynamically allocated kernel buffers) are freed as a result of this event by the main module component, the "smscore".
Comment #4 & #5 - Here I must ask a question. The module's init and exit points are in the main component ("smscore"), the SDIO interface drivers is used by this main component, and actually those _register and _unregister functions are inner implementation of the SMS module. Are those module inner component's main entry and exit points need to be flagged as __init and __exit as well?
Best regard,
and thanks again,
Uri
Quoted 1 line · Uri Shkolnik
Hi Alexey,
Hi, Uri
Quoted 597 lines
I numbered your comments and append all answers to the end of this email.
Quoted 40 lines · Alexey Klimov
From: Alexey Klimov <[email protected]>
Subject: Re: [PATCH 1/1] siano: add high level SDIO interface driver for SMS based cards
To: "Uri Shkolnik" <[email protected]>
Cc: "Mauro Carvalho Chehab" <[email protected]>, "Michael Krufky" <[email protected]>, [email protected]
Date: Friday, March 13, 2009, 12:46 AM
Hello, UriQuoted 5 lines · Uri Shkolnik
# HG changeset patch
# User Uri Shkolnik <[email protected]>
# Date 1236865697 -7200
# Node ID7352ee1288f651d19d58c7bb479a98f070ad98e6# Parent
3392722cc5b687586c4d898b73050ab6e59bf401Quoted 1 line
siano: add high level SDIO interface driver for SMS
based cards
Quoted 12 lines
From: Uri Shkolnik <[email protected]>
This patch provides SDIO interface driver for SMS (Siano Mobile Silicon) based devices. The patch includes SMS high level SDIO driver and requires patching the kernel SDIO stack, those stack patches had been provided previously.
I would like to thank Pierre Ossman, MMC maintainer, who wrote this driver.
Quoted 6 lines
Priority: normal
Signed-off-by Pierre Ossman <[email protected]>Signed-off-by Uri Shkolnik <[email protected]>diff -r
3392722cc5b6-r7352ee1288f6
linux/drivers/media/dvb/siano/smssdio.cQuoted 1 line
---
/dev/nullThu Jan 01 00:00:001970 +0000
Quoted 1 line
+++
b/linux/drivers/media/dvb/siano/smssdio.c
Thu Mar 12 15:48:17 2009 +0200Quoted 8 lines
Review line 2
Quoted 3 lines
(quoted diff) +2
-0@@ -0,0 +1,356 @@ +/* + * smssdio.c - Siano 1xxx SDIO interfacedriver
Review line 4
Quoted 2 lines
(quoted diff) +2
-0+ * + * Copyright 2008 Pierre OssmanI'm sorry, but may be 2009 ?
[ #1 ]
Quoted 129 lines
Review line 9
Quoted 6 lines
(quoted diff) +5
-0+ * + * Based on code by Siano Mobile Silicon, Inc., + * Copyright (C) 2006-2008, Uri Shkolnik + * + * This program is free software; you canredistribute it and/or modify
Review line 10
Quoted 1 line
(quoted diff) +1
-0+ * it under the terms of the GNU General PublicLicense as published by
Review line 11
Quoted 1 line
(quoted diff) +1
-0+ * the Free Software Foundation; either version 2 ofthe License, or (at
Review line 15
Quoted 4 lines
(quoted diff) +4
-0+ * your option) any later version. + * + * + * This hardware is a bit odd in that all transfersshould be done
Review line 16
Quoted 1 line
(quoted diff) +1
-0+ * to/from the SMSSDIO_DATA register, yet the"increase address" bit
Review line 19
Quoted 3 lines
(quoted diff) +3
-0+ * always needs to be set. + * + * Also, buffers from the card are always aligned to128 byte
Review line 28
Quoted 9 lines
(quoted diff) +9
-0+ * boundaries. + */ + +/* + * General cleanup notes: + * + * - only typedefs should be name *_t + * + * - use ERR_PTR and friends for
smscore_register_device()Quoted 9 lines
(quoted diff) +9
-0+ * + * - smscore_getbuffer should zero fields + * + * Fix stop command + */ + +#include <linux/moduleparam.h> +#include <linux/firmware.h> +#include <linux/delay.h>Review line 47
Quoted 10 lines
(quoted diff) +10
-0+#include <linux/mmc/card.h> +#include <linux/mmc/sdio_func.h> +#include <linux/mmc/sdio_ids.h> + +#include "smscoreapi.h" +#include "sms-cards.h" + +/* Registers */ + +#define SMSSDIO_DATA0x00Review line 48
Quoted 1 line
(quoted diff) +1
-0+#define SMSSDIO_INT0x04Review line 51
Quoted 3 lines
(quoted diff) +3
-0+ +static const struct sdio_device_id smssdio_ids[] = { + {SDIO_DEVICE(SDIO_VENDOR_ID_SIANO,
SDIO_DEVICE_ID_SIANO_STELLAR),Review line 52
Quoted 1 line
(quoted diff) +1
-0+ .driver_data =
SMS1XXX_BOARD_SIANO_STELLAR},Review line 53
Quoted 1 line
(quoted diff) +1
-0+ {SDIO_DEVICE(SDIO_VENDOR_ID_SIANO,
SDIO_DEVICE_ID_SIANO_NOVA_A0),Review line 54
Quoted 1 line
(quoted diff) +1
-0+ .driver_data =
SMS1XXX_BOARD_SIANO_NOVA_A},Review line 55
Quoted 1 line
(quoted diff) +1
-0+ {SDIO_DEVICE(SDIO_VENDOR_ID_SIANO,
SDIO_DEVICE_ID_SIANO_NOVA_B0),Review line 56
Quoted 1 line
(quoted diff) +1
-0+ .driver_data =
SMS1XXX_BOARD_SIANO_NOVA_B},Review line 57
Quoted 1 line
(quoted diff) +1
-0+ {SDIO_DEVICE(SDIO_VENDOR_ID_SIANO,
SDIO_DEVICE_ID_SIANO_VEGA_A0),Review line 58
Quoted 1 line
(quoted diff) +1
-0+ .driver_data =
SMS1XXX_BOARD_SIANO_VEGA},Review line 59
Quoted 1 line
(quoted diff) +1
-0+ {SDIO_DEVICE(SDIO_VENDOR_ID_SIANO,
SDIO_DEVICE_ID_SIANO_VENICE),Review line 60
Quoted 1 line
(quoted diff) +1
-0+ .driver_data =
SMS1XXX_BOARD_SIANO_VEGA},Review line 71
Quoted 11 lines
(quoted diff) +11
-0+ { /* end: all zeroes */ }, +}; + +MODULE_DEVICE_TABLE(sdio, smssdio_ids); + +struct smssdio_device { + struct sdio_func *func; + + struct smscore_device_t *coredev; + + struct smscore_buffer_t
*split_cb;Review line 73
Quoted 3 lines
(quoted diff) +2
-0+}; ++/*******************************************************************/
Review line 74
Quoted 1 line
(quoted diff) +1
-0+/* Siano core callbacks*/Quoted 1 line
+/*******************************************************************/
Review
Quoted 2 lines
(quoted diff) +2
-0+ +static int smssdio_sendrequest(void *context, void*buffer,
size_tsize)Review
Quoted 9 lines
(quoted diff) +9
-0+{ + int ret; + struct smssdio_device *smsdev; + + smsdev = context; + + sdio_claim_host(smsdev->func); + + while (size >=
smsdev->func->cur_blksize) {Quoted 1 line
+ ret =
sdio_write_blocks(smsdev->func, SMSSDIO_DATA, buffer, 1);Review
Quoted 2 lines
(quoted diff) +2
-0+ if (ret) +goto out;Review
Quoted 2 lines
(quoted diff) +2
-0+ + buffer +=
smsdev->func->cur_blksize;Quoted 1 line
+ size -=
smsdev->func->cur_blksize;Review
Quoted 4 lines
(quoted diff) +4
-0+ } + + if (size) { + ret =sdio_write_bytes(smsdev->func,
SMSSDIO_DATA,Quoted 1 line
+
Quoted 9 lines
buffer, size);Review
Quoted 2 lines
(quoted diff) +2
-0+ if (ret) +goto out;Quoted 1 line
+ }
Do you really need this check and goto ? Without them, as i see, the algorithm will do the same.
[ #2 ]
Quoted 320 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ +out: +
sdio_release_host(smsdev->func);Review
Quoted 5 lines
(quoted diff) +4
-0+ + return ret; +} ++/*******************************************************************/
Quoted 1 line
+/* SDIO callbacks
*/Quoted 1 line
+/*******************************************************************/
Review
Quoted 2 lines
(quoted diff) +2
-0+ +static void smssdio_interrupt(struct sdio_func*func)
Review
Quoted 12 lines
(quoted diff) +12
-0+{ + int ret, isr; + + struct smssdio_device *smsdev; + struct smscore_buffer_t *cb; + struct SmsMsgHdr_ST *hdr; + size_t size; + + smsdev = sdio_get_drvdata(func); + + /* + * The interruptregister has no defined meaning. It is just
Quoted 1 line
+ * a way of turning of
the level triggered interrupt.
Review
Quoted 2 lines
(quoted diff) +2
-0+ */ + isr = sdio_readb(func,
SMSSDIO_INT, &ret);Review
Quoted 2 lines
(quoted diff) +2
-0+ if (ret) { +dev_err(&smsdev->func->dev,
Quoted 1 line
+
"Unable to read interrupt register!\n");Review
Quoted 4 lines
(quoted diff) +4
-0+ return; + } + + if (smsdev->split_cb == NULL){
Quoted 1 line
+ cb =
smscore_getbuffer(smsdev->coredev);Review
Quoted 2 lines
(quoted diff) +2
-0+ if (!cb) { +dev_err(&smsdev->func->dev,Quoted 1 line
+
"Unable to allocate
data buffer!\n");Quoted 1 line
+
return;Review
Quoted 3 lines
(quoted diff) +3
-0+ } + + ret =
sdio_read_blocks(smsdev->func, cb->p, SMSSDIO_DATA, 1);Review
Quoted 2 lines
(quoted diff) +2
-0+ if (ret) { +dev_err(&smsdev->func->dev,Quoted 1 line
+
"Error %d reading
initial block!\n", ret);Quoted 1 line
+
return;Review
Quoted 3 lines
(quoted diff) +3
-0+ } + + hdr =
cb->p;Review
Quoted 2 lines
(quoted diff) +2
-0+ + if(
hdr->msgFlags&MSG_HDR_FLAG_SPLIT_MSG) {Quoted 1 line
+
smsdev->split_cb = cb;Quoted 1 line
+
return;Review
Quoted 3 lines
(quoted diff) +3
-0+ } + + size =
hdr->msgLength-smsdev->func->cur_blksize;Review
Quoted 2 lines
(quoted diff) +2
-0+ } else { + cb =
smsdev->split_cb;Quoted 1 line
+ hdr =
cb->p;Review
Quoted 2 lines
(quoted diff) +2
-0+ + size =
hdr->msgLength-sizeof(struct SmsMsgHdr_ST);Review
Quoted 2 lines
(quoted diff) +2
-0+ +
smsdev->split_cb= NULL;Review
Quoted 3 lines
(quoted diff) +3
-0+ } + + if (hdr->msgLength >
smsdev->func->cur_blksize) {Review
Quoted 3 lines
(quoted diff) +3
-0+ void *buffer; + + size =
ALIGN(size, 128);Quoted 1 line
+ buffer =
cb->p+hdr->msgLength;Review
Quoted 2 lines
(quoted diff) +2
-0+ +
BUG_ON(smsdev->func->cur_blksize != 128);Review
Quoted 3 lines
(quoted diff) +3
-0+ + /* + *First attempt to transfer all of it in one go...
Review
Quoted 2 lines
(quoted diff) +2
-0+ */ + ret =sdio_read_blocks(smsdev->func, buffer,
Quoted 1 line
+
SMSSDIO_DATA, size / 128);Quoted 1 line
+ if (ret
&& ret !=
-EINVAL) {Quoted 1 line
+
smscore_putbuffer(smsdev->coredev,cb);
Quoted 1 line
+
dev_err(&smsdev->func->dev,Quoted 1 line
+
"Error %d reading data
from card!\n", ret);Quoted 1 line
+
return;Review
Quoted 4 lines
(quoted diff) +4
-0+ } + + /* + *..then fall back to one block at a time if that is
Quoted 1 line
+ *
not possible...
Review
Quoted 2 lines
(quoted diff) +2
-0+ * + *(we have to do this manually because of the
Quoted 1 line
+ *
problem with the "increase address" bit)
Review
Quoted 2 lines
(quoted diff) +2
-0+ */ + if (ret ==
-EINVAL) {Quoted 1 line
+
while (size) {Quoted 1 line
+
ret =
sdio_read_blocks(smsdev->func,Quoted 1 line
+
buffer,
SMSSDIO_DATA, 1);Quoted 1 line
+
if (ret) {Quoted 1 line
+
smscore_putbuffer(smsdev->coredev, cb);Quoted 1 line
+
dev_err(&smsdev->func->dev,
Quoted 1 line
+
"Error %d reading "
Quoted 1 line
+
"data from card!\n", ret);Quoted 1 line
+
return;
Quoted 1 line
+
}Review
Quoted 2 lines
(quoted diff) +2
-0+ +buffer +=
smsdev->func->cur_blksize;Quoted 1 line
+
if (size >
smsdev->func->cur_blksize)Quoted 1 line
+
size -=
smsdev->func->cur_blksize;Quoted 1 line
+
else
Quoted 1 line
+
size = 0;
Quoted 1 line
+
}Review
Quoted 7 lines
(quoted diff) +7
-0+ } + } + + cb->size = hdr->msgLength; + cb->offset = 0; + +
smscore_onresponse(smsdev->coredev, cb);Review
Quoted 4 lines
(quoted diff) +4
-0+} + +static int smssdio_probe(struct sdio_func *func, +const struct
sdio_device_id
*id)Review
Quoted 10 lines
(quoted diff) +10
-0+{ + int ret; + + int board_id; + struct smssdio_device *smsdev; + struct smsdevice_params_t params; + + board_id = id->driver_data; + + smsdev = kzalloc(sizeof(struct
smssdio_device),GFP_KERNEL);Review
Quoted 2 lines
(quoted diff) +2
-0+ if (!smsdev) + return
-ENOMEM;Review
Quoted 4 lines
(quoted diff) +4
-0+ + smsdev->func = func; + + memset(¶ms, 0,
sizeof(struct smsdevice_params_t));Review
Quoted 2 lines
(quoted diff) +2
-0+ + params.device =
&func->dev;Quoted 1 line
+ params.buffer_size =
0x5000; /* ?? */Quoted 1 line
+ params.num_buffers =
22; /* ?? */
Review
Quoted 3 lines
(quoted diff) +3
-0+ params.context = smsdev; + + snprintf(params.devpath,sizeof(params.devpath),
Quoted 1 line
+
"sdio\\%s",
sdio_func_id(func));Review
Quoted 2 lines
(quoted diff) +2
-0+ + params.sendrequest_handler =
smssdio_sendrequest;Review
Quoted 2 lines
(quoted diff) +2
-0+ + params.device_type =sms_get_board(board_id)->type;
Review
Quoted 2 lines
(quoted diff) +2
-0+ + if (params.device_type !=
SMS_STELLAR)Quoted 1 line
+ params.flags |=
SMS_DEVICE_FAMILY2;Review
Quoted 3 lines
(quoted diff) +3
-0+ else { + /* + *FIXME: Stellar needs special handling...
Review
Quoted 6 lines
(quoted diff) +6
-0+ */ + ret = -ENODEV; + goto free; + } + + ret =smscore_register_device(¶ms,
&smsdev->coredev);Review
Quoted 4 lines
(quoted diff) +4
-0+ if (ret < 0) + goto free; + +
smscore_set_board_id(smsdev->coredev, board_id);Review
Quoted 8 lines
(quoted diff) +8
-0+ + sdio_claim_host(func); + + ret = sdio_enable_func(func); + if (ret) + goto release; + + ret = sdio_set_block_size(func,128);
Review
Quoted 4 lines
(quoted diff) +4
-0+ if (ret) + goto disable; + + ret = sdio_claim_irq(func,
smssdio_interrupt);Review
Quoted 8 lines
(quoted diff) +8
-0+ if (ret) + goto disable; + + sdio_set_drvdata(func, smsdev); + + sdio_release_host(func); + + ret =
smscore_start_device(smsdev->coredev);Review
Quoted 13 lines
(quoted diff) +13
-0+ if (ret < 0) + goto reclaim; + + return 0; + +reclaim: + sdio_claim_host(func); + sdio_release_irq(func); +disable: + sdio_disable_func(func); +release: + sdio_release_host(func); +
smscore_unregister_device(smsdev->coredev);Quoted 5 lines
(quoted diff) +5
-0+free: + kfree(smsdev); + + return ret; +}Review
Quoted 10 lines
(quoted diff) +10
-0+ +static void smssdio_remove(struct sdio_func *func) +{ + struct smssdio_device *smsdev; + + smsdev = sdio_get_drvdata(func); + + /* FIXME: racy! */ + if (smsdev->split_cb) +
smscore_putbuffer(smsdev->coredev, smsdev->split_cb);Quoted 4 lines
May be you want to introduce mutex lock or even spinlock to prevent race
condition ?[ #3 ]
Quoted 25 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ +
smscore_unregister_device(smsdev->coredev);Quoted 7 lines
(quoted diff) +6
-0+ + sdio_claim_host(func); + sdio_release_irq(func); + sdio_disable_func(func); + sdio_release_host(func); +Review
Quoted 10 lines
(quoted diff) +10
-0+ kfree(smsdev); +} + +static struct sdio_driver smssdio_driver = { + .name = "smssdio", + .id_table = smssdio_ids, + .probe = smssdio_probe, + .remove = smssdio_remove, +}; ++/*******************************************************************/
Quoted 1 line
+/* Module functions
Quoted 8 lines
*/Quoted 1 line
+/*******************************************************************/
Review
Quoted 2 lines
(quoted diff) +2
-0+ +int smssdio_register(void)Dont you want to make this function static int
__init?[ #4 ]
Quoted 9 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+{ + int ret = 0; + + printk(KERN_INFO "smssdio: SianoSMS1xxx SDIO driver\n");
Quoted 1 line
+ printk(KERN_INFO "smssdio:
Copyright Pierre Ossman\n");
Review
Quoted 2 lines
(quoted diff) +2
-0+ + ret =Quoted 8 lines
sdio_register_driver(&smssdio_driver);Review
Quoted 5 lines
(quoted diff) +5
-0+ + return ret; +} + +void smssdio_unregister(void)And the same here - static void
__exit?[#5 ]
Quoted 4 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+{ +
sdio_unregister_driver(&smssdio_driver);Quoted 12 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+} + +MODULE_DESCRIPTION("Siano SMS1xxx SDIO driver"); +MODULE_AUTHOR("Pierre Ossman"); +MODULE_LICENSE("GPL");Good luck,
Signature · 1 line
best regards, Klimov AlexeyFirst, before anything else, I would like to thank you for the detailed review.
Regarding this patch and your comments regarding it - A preliminary fact must be shared. This patch had been written by Pierre Ossman, who is the Linux kernel MMC maintainer. He wrote this patch back in summer 2008, and the commit of it has been delayed from various reasons.
Quoted 8 lines
This fact establishes two additional issues -
1) Regarding your comment #1, yes it should be 2008... (and not 2009)
2) Regarding re-submitting this particular patch, with some corrections - As it has been requested clearly by Pierre, I must not alter his file, only patch on top of it (e.g. commit it and only than patch it further), unless, of course, if something is broken (than I'll contact him and ask his permission to alter this principal patch). But since this driver passes various QA tests and it works fine (and since your comments do not indicate broken things, just suggest improvements), I must obey Pierre's request. So if needed, we'll create a second, following patch, in order to answer your (and others) comments.Comment #2 - True, this is redundant code, and it will be deleted.
Comment #3 - The first half of a "split message" (which is a device --> host message that is combined from exactly two parts), may be submitted and before the second half is process, the device is removed. Actually, there is no risk with this, since all buffers (dynamically allocated kernel buffers) are freed as a result of this event by the main module component, the "smscore".
So, is there possible race condition or not?
If yes - you can repair it. If no, well why this comment is here? :-)
Quoted 1 line
Comment #4 & #5 - Here I must ask a question. The module's init and exit points are in the main component ("smscore"), the SDIO interface drivers is used by this main component, and actually those
_registerand_unregisterfunctions are inner implementation of the SMS module. Are those module inner component's main entry and exit points need to be flagged as__initand__exitas well?
I chechked what you said, and you are right. It can't be static and looks like __init and __exit shouldn't be here also. You said that you did test patches, so compilation with export function with extern should be ok on your side. I wish that there is no dependency problem with order of modules loading with exported functions.
Sorry for pointing out to this question.
Signature · 1 line
Best regards, Klimov Alexey