Add streaming API for firmware and FPGA manager
cover Add streaming API for firmware and FPGA manager
From: Yi Li <[email protected]>
As the FPGA hardware advances, the firmware image size grows (hundres of MBs or more). It could be an issue for kernel to allocate a big buffer to load the whole firmware file.
Here is an attempt to read the firmware file into a small buffer and program the FPGA in a loop (or so call the streaming mode). It should not be a performance hit for FPGA programing since the majority of time spend is with the FPGA CvP/PR-IP interface.
pseudo code in fpga manager:
while (size > 0) {
ret = stream_firmware(&fw, image_name, dev, offset, streamsize);
ret = mgr->mops->write(mgr, fw->data, fw->size);
offset += fw->size;
size -= fw->size;
}Thanks,
Yi
Yi Li (2):
firmware class: Add stream_firmware API.
fpga manager: Add fpga_mgr_firmware_stream API
drivers/base/firmware_class.c | 128 ++++++++++++++++++++++++++++++++++++++++++ drivers/fpga/fpga-mgr.c | 77 +++++++++++++++++++++++++ include/linux/firmware.h | 2 + include/linux/fpga/fpga-mgr.h | 4 ++ 4 files changed, 211 insertions(+)
Signature · 1 line
2.7.4
RFC 1/2 firmware class: Add stream_firmware API.
From: Yi Li <[email protected]>
Add function to load firmware in multiple chucks instead of
loading the whole big firmware file at once.
--- drivers/base/firmware_class.c | 128 ++++++++++++++++++++++++++++++++++++++++++ include/linux/firmware.h | 2 + 2 files changed, 130 insertions(+)
drivers/base/firmware_class.c +128 -0
@@ -436,6 +436,62 @@ fw_get_filesystem_firmware(struct device *device, struct firmware_buf *buf)return rc; } +static int +fw_stream_filesystem_firmware (struct device *device,struct firmware_buf *buf, +size_t offset,size_t length) +{ +int i, len; +char *path; +int rc =0 ; +struct file *file; + + buf->size =0 ; + + path =__getname (); +if (!path) +return -ENOMEM ; + +for (i =0 ; i <ARRAY_SIZE (fw_path); i++) { +/* skip the unset customized path */ +if (!fw_path[i][0 ]) +continue ; + + len =snprintf (path,PATH_MAX ,"%s/%s" , + fw_path[i], buf->fw_id); +if (len >=PATH_MAX ) { + rc = -ENAMETOOLONG ; +break ; + } + +if (!path || !*path) +continue ; + +if (!buf->data) { + buf->data =vmalloc (length); +if (!buf->data) { + rc = -ENOMEM ; +break ; + } + } + + file =filp_open (path,O_RDONLY ,0 ); +if (IS_ERR (file)) +continue ; + + buf->size =kernel_read (file, offset, (char *) buf->data, + length); +fput (file); +break ; + } + +__putname (path); + +if (rc) +dev_err (device,"loading %s failed with error %d\n" , + path, rc); +return rc; +} +/* firmware holds the ownership of pages */ static void firmware_free_data (const struct firmware *fw) {
@@ -1267,6 +1323,78 @@ request_firmware(const struct firmware **firmware_p, const char *name, }EXPORT_SYMBOL (request_firmware); +static int +_stream_firmware (const struct firmware **firmware_p,const char *name, +struct device *device,void *buf,size_t size, +unsigned int opt_flags,size_t offset,size_t length) +{ +int ret; +struct firmware *fw =NULL ; +struct firmware_buf *fbuf; + +if ((!firmware_p) || (!name || name[0 ] =='\0' )) { +dev_err (device,"invalid firmware pointer or file name\n" ); +return -EINVAL ; + } + +if (!*firmware_p) { + ret =_request_firmware_prepare (&fw, name, device, buf, size); +if (ret <=0 ) { +dev_err (device,"%s: _request_firmware_prepare failed %d\n" , + __func__, ret); + } + }else { + fw = (struct firmware *) *firmware_p; + } + + fbuf = (struct firmware_buf *) fw->priv; + ret =fw_stream_filesystem_firmware (device, fbuf, offset, length); + fw->size = fbuf->size; + fw->data = fbuf->data; + *firmware_p = fw; + +if (ret) +dev_err (device,"streaming with error %d\n" , ret); +return ret; +} + +/** +* stream_firmware: - send firmware request and wait for it +* @firmware_p: pointer to firmware image +* @name: name of firmware file +* @device: device for which firmware is being loaded +* @offset: offset of the file to read from +* @length: length in bytes to read +* +* @firmware_p will be used to return a firmware image by the name +* of @name for device @device. +* +* Should be called from user context where sleeping is allowed. +* +* @name will be used as $FIRMWARE in the uevent environment and +* should be distinctive enough not to be confused with any other +* firmware image for this or any other device. +* +* Caller must hold the reference count of @device. +* +* The function can be called safely inside device's suspend and +* resume callback. +**/ +int +stream_firmware (const struct firmware **firmware_p,const char *name, +struct device *device,size_t offset,size_t length) +{ +size_t ret; + +/* Need to pin this module until return */ +__module_get (THIS_MODULE ); + ret =_stream_firmware (firmware_p, name, device,NULL ,0 , +FW_OPT_UEVENT |FW_OPT_NO_WARN , offset, length); +module_put (THIS_MODULE ); +return ret; +} +EXPORT_SYMBOL (stream_firmware); +/** * request_firmware_direct: - load firmware directly without usermode helper * @firmware_p: pointer to firmware image
include/linux/firmware.h +2 -0
@@ -41,6 +41,8 @@ struct builtin_fw {#if defined(CONFIG_FW_LOADER ) || (defined(CONFIG_FW_LOADER_MODULE ) && defined(MODULE ))int request_firmware (const struct firmware **fw,const char *name,struct device *device); +int stream_firmware (const struct firmware **fw,const char *name, +struct device *device,size_t offset,size_t length); int request_firmware_nowait( struct module *module, bool uevent, const char *name, struct device *device, gfp_t gfp, void *context,
Signature · 1 line
2.7.4
Re: [RFC 1/2] firmware class: Add stream_firmware API.
Quoted 1 line · On Thu, 9 Mar 2017, [email protected] wrote:
From: Yi Li <[email protected]>
Hi Yi,
Just one question below.
Matthew Gerlach
Quoted 30 lines
Add function to load firmware in multiple chucks instead of
loading the whole big firmware file at once.
Signed-off-by Yi Li <[email protected]>---
drivers/base/firmware_class.c| 128 ++++++++++++++++++++++++++++++++++++++++++include/linux/firmware.h| 2 +2 files changed, 130 insertions(+)drivers/base/firmware_class.c +12
-0@@ -436,6 +436,62 @@ fw_get_filesystem_firmware(struct device *device, struct firmware_buf *buf)return rc; } +static int +fw_stream_filesystem_firmware (struct device *device,struct firmware_buf *buf, +size_t offset,size_t length) +{ +int i, len; +char *path; +int rc =0 ; +struct file *file; + + buf->size =0 ; + + path =__getname ();
drivers/base/firmware_class.c fw_get_filesystem_firmware(struct device *device, struct firmware_buf *buf) · line 460
Quoted 10 lines
drivers/base/firmware_class.c +10
-0+if (!path) +return -ENOMEM ; + +for (i =0 ; i <ARRAY_SIZE (fw_path); i++) { +/* skip the unset customized path */ +if (!fw_path[i][0 ]) +continue ; + + len =snprintf (path,PATH_MAX ,"%s/%s" , + fw_path[i], buf->fw_id);
I'm probably being paranoid, but is it safe to assume the length of the buffer returned by __getname() is at least PATH_MAX? It seems like the length should be pagesize.
Quoted 137 lines
drivers/base/firmware_class.c +106
-0+if (len >=PATH_MAX ) { + rc = -ENAMETOOLONG ; +break ; + } + +if (!path || !*path) +continue ; + +if (!buf->data) { + buf->data =vmalloc (length); +if (!buf->data) { + rc = -ENOMEM ; +break ; + } + } + + file =filp_open (path,O_RDONLY ,0 ); +if (IS_ERR (file)) +continue ; + + buf->size =kernel_read (file, offset, (char *) buf->data, + length); +fput (file); +break ; + } + +__putname (path); + +if (rc) +dev_err (device,"loading %s failed with error %d\n" , + path, rc); +return rc; +} +/* firmware holds the ownership of pages */ static void firmware_free_data (const struct firmware *fw) {@@ -1267,6 +1323,78 @@ request_firmware(const struct firmware **firmware_p, const char *name, }EXPORT_SYMBOL (request_firmware); +static int +_stream_firmware (const struct firmware **firmware_p,const char *name, +struct device *device,void *buf,size_t size, +unsigned int opt_flags,size_t offset,size_t length) +{ +int ret; +struct firmware *fw =NULL ; +struct firmware_buf *fbuf; + +if ((!firmware_p) || (!name || name[0 ] =='\0' )) { +dev_err (device,"invalid firmware pointer or file name\n" ); +return -EINVAL ; + } + +if (!*firmware_p) { + ret =_request_firmware_prepare (&fw, name, device, buf, size); +if (ret <=0 ) { +dev_err (device,"%s: _request_firmware_prepare failed %d\n" , + __func__, ret); + } + }else { + fw = (struct firmware *) *firmware_p; + } + + fbuf = (struct firmware_buf *) fw->priv; + ret =fw_stream_filesystem_firmware (device, fbuf, offset, length); + fw->size = fbuf->size; + fw->data = fbuf->data; + *firmware_p = fw; + +if (ret) +dev_err (device,"streaming with error %d\n" , ret); +return ret; +} + +/** +* stream_firmware: - send firmware request and wait for it +* @firmware_p: pointer to firmware image +* @name: name of firmware file +* @device: device for which firmware is being loaded +* @offset: offset of the file to read from +* @length: length in bytes to read +* +* @firmware_p will be used to return a firmware image by the name +* of @name for device @device. +* +* Should be called from user context where sleeping is allowed. +* +* @name will be used as $FIRMWARE in the uevent environment and +* should be distinctive enough not to be confused with any other +* firmware image for this or any other device. +* +* Caller must hold the reference count of @device. +* +* The function can be called safely inside device's suspend and +* resume callback. +**/ +int +stream_firmware (const struct firmware **firmware_p,const char *name, +struct device *device,size_t offset,size_t length) +{ +size_t ret; + +/* Need to pin this module until return */ +__module_get (THIS_MODULE ); + ret =_stream_firmware (firmware_p, name, device,NULL ,0 , +FW_OPT_UEVENT |FW_OPT_NO_WARN , offset, length); +module_put (THIS_MODULE ); +return ret; +} +EXPORT_SYMBOL (stream_firmware); +/** * request_firmware_direct: - load firmware directly without usermode helper * @firmware_p: pointer to firmware image include/linux/firmware.h +2
-0@@ -41,6 +41,8 @@ struct builtin_fw {#if defined(CONFIG_FW_LOADER ) || (defined(CONFIG_FW_LOADER_MODULE ) && defined(MODULE ))int request_firmware (const struct firmware **fw,const char *name,struct device *device); +int stream_firmware (const struct firmware **fw,const char *name, +struct device *device,size_t offset,size_t length);int request_firmware_nowait(
struct module *module, bool uevent,
const char *name, struct device *device,gfp_tgfp, void *context,Signature · 6 lines
2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-fpga" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC 1/2] firmware class: Add stream_firmware API.
Hi Matthew
Quoted 52 lines · On 3/10/2017 11:44 AM, [email protected] wrote:
Quoted 1 line · On Thu, 9 Mar 2017, [email protected] wrote:
From: Yi Li <[email protected]>
Hi Yi,
Just one question below.
Matthew Gerlach
Quoted 38 lines
Add function to load firmware in multiple chucks instead of
loading the whole big firmware file at once.
Signed-off-by Yi Li <[email protected]>---
drivers/base/firmware_class.c| 128
++++++++++++++++++++++++++++++++++++++++++include/linux/firmware.h| 2 +2 files changed, 130 insertions(+)drivers/base/firmware_class.c +17
-0@@ -436,6 +436,62 @@ fw_get_filesystem_firmware(struct device *device, struct firmware_buf *buf)return rc; } +static int +fw_stream_filesystem_firmware (struct device *device,struct firmware_buf *buf, +size_t offset,size_t length) +{ +int i, len; +char *path; +int rc =0 ; +struct file *file; + + buf->size =0 ; + + path =__getname (); +if (!path) +return -ENOMEM ; + +for (i =0 ; i <ARRAY_SIZE (fw_path); i++) { +/* skip the unset customized path */
Quoted 8 lines
drivers/base/firmware_class.c fw_get_filesystem_firmware(struct device *device, struct firmware_buf *buf) · line 460
Quoted 5 lines
drivers/base/firmware_class.c +5
-0+if (!fw_path[i][0 ]) +continue ; + + len =snprintf (path,PATH_MAX ,"%s/%s" , + fw_path[i], buf->fw_id);I'm probably being paranoid, but is it safe to assume the length of the buffer returned by
__getname()is at leastPATH_MAX? It seems like the length should be pagesize.
The size should be the maximum number of char of the string be produced, not the input size.
According to https://www.gnu.org/software/libc/manual/html_node/Formatted-Output-Functions.html
Function:/int/*snprintf*/(char *s, size_tsize, const char *template, …)
/The|snprintf|function is similar to|sprintf|, except that thesizeargument specifies the maximum number of characters to produce. The trailing null character is counted towards this limit, so you should allocate at leastsizecharacters for the strings. Ifsizeis zero, nothing, not even the null byte, shall be written andsmay be a null pointer. The return value is the number of characters which would be generated for the given input, excluding the trailing null. If this value is greater than or equal tosize, not all characters from the result have been stored ins
Quoted 141 lines
Quoted 141 lines
drivers/base/firmware_class.c +34
-0+if (len >=PATH_MAX ) { + rc = -ENAMETOOLONG ; +break ; + } + +if (!path || !*path) +continue ; + +if (!buf->data) { + buf->data =vmalloc (length); +if (!buf->data) { + rc = -ENOMEM ; +break ; + } + } + + file =filp_open (path,O_RDONLY ,0 ); +if (IS_ERR (file)) +continue ; + + buf->size =kernel_read (file, offset, (char *) buf->data, + length); +fput (file); +break ; + } + +__putname (path); + +if (rc) +dev_err (device,"loading %s failed with error %d\n" , + path, rc); +return rc; +} +/* firmware holds the ownership of pages */ static void
firmware_free_data(const struct firmware *fw){drivers/base/firmware_class.c +72
-0@@ -1267,6 +1323,78 @@ request_firmware(const struct firmware **firmware_p, const char *name, }EXPORT_SYMBOL (request_firmware); +static int +_stream_firmware (const struct firmware **firmware_p,const char *name, +struct device *device,void *buf,size_t size, +unsigned int opt_flags,size_t offset,size_t length) +{ +int ret; +struct firmware *fw =NULL ; +struct firmware_buf *fbuf; + +if ((!firmware_p) || (!name || name[0 ] =='\0' )) { +dev_err (device,"invalid firmware pointer or file name\n" ); +return -EINVAL ; + } + +if (!*firmware_p) { + ret =_request_firmware_prepare (&fw, name, device, buf, size); +if (ret <=0 ) { + dev_err(device, "%s: _request_firmware_prepare failed %d\n", + __func__, ret); + } + }else { + fw = (struct firmware *) *firmware_p; + } + + fbuf = (struct firmware_buf *) fw->priv; + ret =fw_stream_filesystem_firmware (device, fbuf, offset, length); + fw->size = fbuf->size; + fw->data = fbuf->data; + *firmware_p = fw; + +if (ret) +dev_err (device,"streaming with error %d\n" , ret); +return ret; +} + +/** +* stream_firmware: - send firmware request and wait for it +* @firmware_p: pointer to firmware image +* @name: name of firmware file +* @device: device for which firmware is being loaded +* @offset: offset of the file to read from +* @length: length in bytes to read +* +* @firmware_p will be used to return a firmware image by the name +* of @name for device @device. +* +* Should be called from user context where sleeping is allowed. +* +* @name will be used as $FIRMWARE in the uevent environment and +* should be distinctive enough not to be confused with any other +* firmware image for this or any other device. +* +* Caller must hold the reference count of @device. +* +* The function can be called safely inside device's suspend and +* resume callback. +**/ +int +stream_firmware (const struct firmware **firmware_p,const char *name, +struct device *device,size_t offset,size_t length) +{ +size_t ret; + +/* Need to pin this module until return */ +__module_get (THIS_MODULE ); + ret =_stream_firmware (firmware_p, name, device,NULL ,0 , +FW_OPT_UEVENT |FW_OPT_NO_WARN , offset, length); +module_put (THIS_MODULE ); +return ret; +} +EXPORT_SYMBOL (stream_firmware); +/** *
request_firmware_direct: - load firmware directly without usermode
helper
* @firmware_p: pointer to firmware imageinclude/linux/firmware.h +2
-0@@ -41,6 +41,8 @@ struct builtin_fw {#if defined(CONFIG_FW_LOADER ) || (defined(CONFIG_FW_LOADER_MODULE ) && defined(MODULE ))int request_firmware (const struct firmware **fw,const char *name,struct device *device); +int stream_firmware (const struct firmware **fw,const char *name, +struct device *device,size_t offset,size_t length);int request_firmware_nowait(
struct module *module, bool uevent,
const char *name, struct device *device,gfp_tgfp, void *context,Signature · 6 lines
2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-fpga" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC 1/2] firmware class: Add stream_firmware API.
Quoted 2 lines · Yi
Hi Matthew
Hi Yi,
Quoted 63 lines · On 3/10/2017 11:44 AM, [email protected] wrote:
Quoted 52 lines · On Thu, 9 Mar 2017, [email protected] wrote:
Quoted 2 lines
From: Yi Li <[email protected]>
Hi Yi,
Just one question below.
Matthew Gerlach
Quoted 38 lines
Add function to load firmware in multiple chucks instead of
loading the whole big firmware file at once.
Signed-off-by Yi Li <[email protected]>---
drivers/base/firmware_class.c| 128
++++++++++++++++++++++++++++++++++++++++++include/linux/firmware.h| 2 +2 files changed, 130 insertions(+)drivers/base/firmware_class.c +17
-0@@ -436,6 +436,62 @@ fw_get_filesystem_firmware(struct device *device, struct firmware_buf *buf)return rc; } +static int +fw_stream_filesystem_firmware (struct device *device,struct firmware_buf *buf, +size_t offset,size_t length) +{ +int i, len; +char *path; +int rc =0 ; +struct file *file; + + buf->size =0 ; + + path =__getname (); +if (!path) +return -ENOMEM ; + +for (i =0 ; i <ARRAY_SIZE (fw_path); i++) { +/* skip the unset customized path */ Quoted 8 lines
drivers/base/firmware_class.c fw_get_filesystem_firmware(struct device *device, struct firmware_buf *buf) · line 460
Quoted 5 lines
drivers/base/firmware_class.c +5
-0+if (!fw_path[i][0 ]) +continue ; + + len =snprintf (path,PATH_MAX ,"%s/%s" , + fw_path[i], buf->fw_id);I'm probably being paranoid, but is it safe to assume the length of the buffer returned by
__getname()is at leastPATH_MAX? It seems like the length should be pagesize.
Quoted 6 lines
The size should be the maximum number of char of the string be produced, not the input size.
According to https://www.gnu.org/software/libc/manual/html_node/Formatted-Output-Functions.html
Function:/int/*snprintf*/(char *s,size_tsize, const char *template, …)
/The|snprintf|function is similar to|sprintf|, except that thesizeargument specifies the maximum number of characters to produce. The trailing null character is counted towards this limit, so you should allocate at leastsizecharacters for the strings. Ifsizeis zero, nothing, not even the null byte, shall be written andsmay be a null pointer. The return value is the number of characters which would be generated for the given input, excluding the trailing null. If this value is greater than or equal tosize, not all characters from the result have been stored ins
I am familiar with the functionality of snprintf versus sprintf. In the
snprintf call above, you are saying that memory pointed to by the variable path, has at least PATH_MAX number of bytes. My question is how can you know that the memory returned by __getname() has PATH_MAX number of bytes?
Quoted 146 lines
Quoted 135 lines
Quoted 135 lines
drivers/base/firmware_class.c +34
-0+if (len >=PATH_MAX ) { + rc = -ENAMETOOLONG ; +break ; + } + +if (!path || !*path) +continue ; + +if (!buf->data) { + buf->data =vmalloc (length); +if (!buf->data) { + rc = -ENOMEM ; +break ; + } + } + + file =filp_open (path,O_RDONLY ,0 ); +if (IS_ERR (file)) +continue ; + + buf->size =kernel_read (file, offset, (char *) buf->data, + length); +fput (file); +break ; + } + +__putname (path); + +if (rc) +dev_err (device,"loading %s failed with error %d\n" , + path, rc); +return rc; +} +/* firmware holds the ownership of pages */ static void
firmware_free_data(const struct firmware *fw){drivers/base/firmware_class.c +72
-0@@ -1267,6 +1323,78 @@ request_firmware(const struct firmware **firmware_p, const char *name, }EXPORT_SYMBOL (request_firmware); +static int +_stream_firmware (const struct firmware **firmware_p,const char *name, +struct device *device,void *buf,size_t size, +unsigned int opt_flags,size_t offset,size_t length) +{ +int ret; +struct firmware *fw =NULL ; +struct firmware_buf *fbuf; + +if ((!firmware_p) || (!name || name[0 ] =='\0' )) { +dev_err (device,"invalid firmware pointer or file name\n" ); +return -EINVAL ; + } + +if (!*firmware_p) { + ret =_request_firmware_prepare (&fw, name, device, buf, size); +if (ret <=0 ) { +dev_err (device,"%s: _request_firmware_prepare failed %d\n" , + __func__, ret); + } + }else { + fw = (struct firmware *) *firmware_p; + } + + fbuf = (struct firmware_buf *) fw->priv; + ret =fw_stream_filesystem_firmware (device, fbuf, offset, length); + fw->size = fbuf->size; + fw->data = fbuf->data; + *firmware_p = fw; + +if (ret) +dev_err (device,"streaming with error %d\n" , ret); +return ret; +} + +/** +* stream_firmware: - send firmware request and wait for it +* @firmware_p: pointer to firmware image +* @name: name of firmware file +* @device: device for which firmware is being loaded +* @offset: offset of the file to read from +* @length: length in bytes to read +* +* @firmware_p will be used to return a firmware image by the name +* of @name for device @device. +* +* Should be called from user context where sleeping is allowed. +* +* @name will be used as $FIRMWARE in the uevent environment and +* should be distinctive enough not to be confused with any other +* firmware image for this or any other device. +* +* Caller must hold the reference count of @device. +* +* The function can be called safely inside device's suspend and +* resume callback. +**/ +int +stream_firmware (const struct firmware **firmware_p,const char *name, +struct device *device,size_t offset,size_t length) +{ +size_t ret; + +/* Need to pin this module until return */ +__module_get (THIS_MODULE ); + ret =_stream_firmware (firmware_p, name, device,NULL ,0 , +FW_OPT_UEVENT |FW_OPT_NO_WARN , offset, length); +module_put (THIS_MODULE ); +return ret; +} +EXPORT_SYMBOL (stream_firmware); +/** * request_firmware_direct: - load firmware directly without usermode helper
* @firmware_p: pointer to firmware imageinclude/linux/firmware.h +2
-0@@ -41,6 +41,8 @@ struct builtin_fw {#if defined(CONFIG_FW_LOADER ) || (defined(CONFIG_FW_LOADER_MODULE ) && defined(MODULE ))int request_firmware (const struct firmware **fw,const char *name,struct device *device); +int stream_firmware (const struct firmware **fw,const char *name, +struct device *device,size_t offset,size_t length);int request_firmware_nowait(
struct module *module, bool uevent,
const char *name, struct device *device,gfp_tgfp, void *context,Signature · 1 line
2.7.4Quoted 5 lines
Quoted 5 lines
Signature · 3 lines
To unsubscribe from this list: send the line "unsubscribe linux-fpga" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html--
To unsubscribe from this list: send the line "unsubscribe linux-fpga" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC 1/2] firmware class: Add stream_firmware API.
hi Matthew,
Quoted 79 lines · On 3/13/2017 4:09 PM, [email protected] wrote:
Quoted 2 lines · Yi
Hi Matthew
Hi Yi,
Quoted 63 lines · On 3/10/2017 11:44 AM, [email protected] wrote:
Quoted 52 lines · On Thu, 9 Mar 2017, [email protected] wrote:
Quoted 2 lines
From: Yi Li <[email protected]>
Hi Yi,
Just one question below.
Matthew Gerlach
Quoted 38 lines
Add function to load firmware in multiple chucks instead of
loading the whole big firmware file at once.
Signed-off-by Yi Li <[email protected]>---
drivers/base/firmware_class.c| 128
++++++++++++++++++++++++++++++++++++++++++include/linux/firmware.h| 2 +2 files changed, 130 insertions(+)drivers/base/firmware_class.c +17
-0@@ -436,6 +436,62 @@ fw_get_filesystem_firmware(struct device *device, struct firmware_buf *buf)return rc; } +static int +fw_stream_filesystem_firmware (struct device *device,struct firmware_buf *buf, +size_t offset,size_t length) +{ +int i, len; +char *path; +int rc =0 ; +struct file *file; + + buf->size =0 ; + + path =__getname (); +if (!path) +return -ENOMEM ; + +for (i =0 ; i <ARRAY_SIZE (fw_path); i++) { +/* skip the unset customized path */ Quoted 8 lines
drivers/base/firmware_class.c fw_get_filesystem_firmware(struct device *device, struct firmware_buf *buf) · line 460
Quoted 5 lines
drivers/base/firmware_class.c +5
-0+if (!fw_path[i][0 ]) +continue ; + + len =snprintf (path,PATH_MAX ,"%s/%s" , + fw_path[i], buf->fw_id);I'm probably being paranoid, but is it safe to assume the length of the buffer returned by
__getname()is at leastPATH_MAX? It seems like the length should be pagesize.Quoted 6 lines
The size should be the maximum number of char of the string be produced, not the input size.
According to https://www.gnu.org/software/libc/manual/html_node/Formatted-Output-Functions.html
Function:/int/*snprintf*/(char *s,size_tsize, const char *template, …)
/The|snprintf|function is similar to|sprintf|, except that thesizeargument specifies the maximum number of characters to produce. The trailing null character is counted towards this limit, so you should allocate at leastsizecharacters for the strings. Ifsizeis zero, nothing, not even the null byte, shall be written andsmay be a null pointer. The return value is the number of characters which would be generated for the given input, excluding the trailing null. If this value is greater than or equal tosize, not all characters from the result have been stored ins
Quoted 4 lines
I am familiar with the functionality of snprintf versus sprintf. In the
snprintf call above, you are saying that memory pointed to by the variable path, has at leastPATH_MAXnumber of bytes. My question is how can you know that the memory returned by__getname()hasPATH_MAXnumber of bytes?
Ah, now I understand the concerns.
The __getname() will allocate an buffer object from names_cachep
extern struct kmem_cache <http://lxr.free-electrons.com/ident?i=kmem_cache> *names_cachep <http://lxr.free-electrons.com/ident?i=names_cachep>;
#define __getname <http://lxr.free-electrons.com/ident?i=__getname>() kmem_cache_alloc <http://lxr.free-electrons.com/ident?i=kmem_cache_alloc>(names_cachep <http://lxr.free-electrons.com/ident?i=names_cachep>, GFP_KERNEL <http://lxr.free-electrons.com/ident?i=GFP_KERNEL>)
names_cachep is created in fs/dcaches.c vfs_caches_init function with object size equal to PATH_MAX.names_cachep <http://lxr.free-electrons.com/ident?i=names_cachep> = kmem_cache_create <http://lxr.free-electrons.com/ident?i=kmem_cache_create>(/"names_cache"/, PATH_MAX <http://lxr.free-electrons.com/ident?i=PATH_MAX>, 0,SLAB_HWCACHE_ALIGN <http://lxr.free-electrons.com/ident?i=SLAB_HWCACHE_ALIGN>|SLAB_PANIC <http://lxr.free-electrons.com/ident?i=SLAB_PANIC>, NULL <http://lxr.free-electrons.com/ident?i=NULL>);
so __getname() should allocate buffer with size of PATH_MAX.
The code is borrowed from fw_get_filesystem_firmware function, which should be reviewed and safe to use. :)
Thanks,
Yi
Quoted 152 lines
Quoted 152 lines
Quoted 146 lines
Quoted 146 lines
drivers/base/firmware_class.c +34
-0+if (len >=PATH_MAX ) { + rc = -ENAMETOOLONG ; +break ; + } + +if (!path || !*path) +continue ; + +if (!buf->data) { + buf->data =vmalloc (length); +if (!buf->data) { + rc = -ENOMEM ; +break ; + } + } + + file =filp_open (path,O_RDONLY ,0 ); +if (IS_ERR (file)) +continue ; + + buf->size =kernel_read (file, offset, (char *) buf->data, + length); +fput (file); +break ; + } + +__putname (path); + +if (rc) +dev_err (device,"loading %s failed with error %d\n" , + path, rc); +return rc; +} +/* firmware holds the ownership of pages */ static void
firmware_free_data(const struct firmware *fw){drivers/base/firmware_class.c +18
-0@@ -1267,6 +1323,78 @@ request_firmware(const struct firmware **firmware_p, const char *name, }EXPORT_SYMBOL (request_firmware); +static int +_stream_firmware (const struct firmware **firmware_p,const char *name, +struct device *device,void *buf,size_t size, +unsigned int opt_flags,size_t offset,size_t length) +{ +int ret; +struct firmware *fw =NULL ; +struct firmware_buf *fbuf; + +if ((!firmware_p) || (!name || name[0 ] =='\0' )) { +dev_err (device,"invalid firmware pointer or file name\n" ); +return -EINVAL ; + } + +if (!*firmware_p) { + ret =_request_firmware_prepare (&fw, name, device, buf, size); +if (ret <=0 ) { + dev_err(device, "%s: _request_firmware_prepare failed%d\n",
drivers/base/firmware_class.c +8
-0+ __func__, ret); + } + }else { + fw = (struct firmware *) *firmware_p; + } + + fbuf = (struct firmware_buf *) fw->priv; + ret = fw_stream_filesystem_firmware(device, fbuf, offset,length);
drivers/base/firmware_class.c +18
-0+ fw->size = fbuf->size; + fw->data = fbuf->data; + *firmware_p = fw; + +if (ret) +dev_err (device,"streaming with error %d\n" , ret); +return ret; +} + +/** +* stream_firmware: - send firmware request and wait for it +* @firmware_p: pointer to firmware image +* @name: name of firmware file +* @device: device for which firmware is being loaded +* @offset: offset of the file to read from +* @length: length in bytes to read +* +* @firmware_p will be used to return a firmware image by the name
+ * of @name for device @device.
+ *
+ * Should be called from user context where sleeping is allowed.
+ *
+ * @name will be used as $FIRMWARE in the uevent environment and
+ * should be distinctive enough not to be confused with any
other
+ * firmware image for this or any other device.
+ *
+ * Caller must hold the reference count of @device.
+ *
+ * The function can be called safely inside device's suspend and
+ * resume callback.
+ **/drivers/base/firmware_class.c +15
-0+int +stream_firmware (const struct firmware **firmware_p,const char *name, +struct device *device,size_t offset,size_t length) +{ +size_t ret; + +/* Need to pin this module until return */ +__module_get (THIS_MODULE ); + ret =_stream_firmware (firmware_p, name, device,NULL ,0 , +FW_OPT_UEVENT |FW_OPT_NO_WARN , offset, length); +module_put (THIS_MODULE ); +return ret; +} +EXPORT_SYMBOL (stream_firmware); +/**
*request_firmware_direct: - load firmware directly without
usermode helper
* @firmware_p: pointer to firmware imageinclude/linux/firmware.h +2
-0@@ -41,6 +41,8 @@ struct builtin_fw {#if defined(CONFIG_FW_LOADER ) || (defined(CONFIG_FW_LOADER_MODULE ) && defined(MODULE ))int request_firmware (const struct firmware **fw,const char *name,struct device *device); +int stream_firmware (const struct firmware **fw,const char *name, +struct device *device,size_t offset,size_t length);int request_firmware_nowait(
struct module *module, bool uevent,
const char *name, struct device *device,gfp_tgfp, void *context,Signature · 6 lines
2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-fpga" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.htmlSignature · 3 lines
To unsubscribe from this list: send the line "unsubscribe linux-fpga" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC 1/2] firmware class: Add stream_firmware API.
Quoted 2 lines · Yi
hi Matthew,
Hi Yi,
Quoted 92 lines · On 3/13/2017 4:09 PM, [email protected] wrote:
Quoted 79 lines · Yi
Quoted 3 lines
Hi Matthew
Hi Yi,
Quoted 63 lines · On 3/10/2017 11:44 AM, [email protected] wrote:
Quoted 52 lines · On Thu, 9 Mar 2017, [email protected] wrote:
Quoted 2 lines
From: Yi Li <[email protected]>
Hi Yi,
Just one question below.
Matthew Gerlach
Quoted 38 lines
Add function to load firmware in multiple chucks instead of
loading the whole big firmware file at once.
Signed-off-by Yi Li <[email protected]>---
drivers/base/firmware_class.c| 128
++++++++++++++++++++++++++++++++++++++++++include/linux/firmware.h| 2 +2 files changed, 130 insertions(+)drivers/base/firmware_class.c +17
-0@@ -436,6 +436,62 @@ fw_get_filesystem_firmware(struct device *device, struct firmware_buf *buf)return rc; } +static int +fw_stream_filesystem_firmware (struct device *device,struct firmware_buf *buf, +size_t offset,size_t length) +{ +int i, len; +char *path; +int rc =0 ; +struct file *file; + + buf->size =0 ; + + path =__getname (); +if (!path) +return -ENOMEM ; + +for (i =0 ; i <ARRAY_SIZE (fw_path); i++) { +/* skip the unset customized path */ Quoted 8 lines
drivers/base/firmware_class.c fw_get_filesystem_firmware(struct device *device, struct firmware_buf *buf) · line 460
Quoted 5 lines
drivers/base/firmware_class.c +5
-0+if (!fw_path[i][0 ]) +continue ; + + len =snprintf (path,PATH_MAX ,"%s/%s" , + fw_path[i], buf->fw_id);I'm probably being paranoid, but is it safe to assume the length of the buffer returned by
__getname()is at leastPATH_MAX? It seems like the length should be pagesize.Quoted 6 lines
The size should be the maximum number of char of the string be produced, not the input size.
According to https://www.gnu.org/software/libc/manual/html_node/Formatted-Output-Functions.html
Function:/int/*snprintf*/(char *s,size_tsize, const char *template, …)
/The|snprintf|function is similar to|sprintf|, except that thesizeargument specifies the maximum number of characters to produce. The trailing null character is counted towards this limit, so you should allocate at leastsizecharacters for the strings. Ifsizeis zero, nothing, not even the null byte, shall be written andsmay be a null pointer. The return value is the number of characters which would be generated for the given input, excluding the trailing null. If this value is greater than or equal tosize, not all characters from the result have been stored insQuoted 4 lines
I am familiar with the functionality of snprintf versus sprintf. In the
snprintf call above, you are saying that memory pointed to by the variable path, has at leastPATH_MAXnumber of bytes. My question is how can you know that the memory returned by__getname()hasPATH_MAXnumber of bytes?Ah, now I understand the concerns.
The
__getname()will allocate an buffer object fromnames_cachep
extern structkmem_cache<http://lxr.free-electrons.com/ident?i=kmem_cache>*names_cachep<http://lxr.free-electrons.com/ident?i=names_cachep>;
#define__getname<http://lxr.free-electrons.com/ident?i=__getname>()kmem_cache_alloc<http://lxr.free-electrons.com/ident?i=kmem_cache_alloc>(names_cachep <http://lxr.free-electrons.com/ident?i=names_cachep>,GFP_KERNEL<http://lxr.free-electrons.com/ident?i=GFP_KERNEL>)
Quoted 6 lines
names_cachepis created infs/dcaches.cvfs_caches_initfunction with object size equal toPATH_MAX.names_cachep<http://lxr.free-electrons.com/ident?i=names_cachep> =kmem_cache_create<http://lxr.free-electrons.com/ident?i=kmem_cache_create>(/"names_cache"/,PATH_MAX<http://lxr.free-electrons.com/ident?i=PATH_MAX>, 0,SLAB_HWCACHE_ALIGN <http://lxr.free-electrons.com/ident?i=SLAB_HWCACHE_ALIGN>|SLAB_PANIC <http://lxr.free-electrons.com/ident?i=SLAB_PANIC>, NULL <http://lxr.free-electrons.com/ident?i=NULL>);so
__getname()should allocate buffer with size ofPATH_MAX.The code is borrowed from
fw_get_filesystem_firmwarefunction, which should be reviewed and safe to use. :)
Thanks for following up. I am no longer paranoid.
Matthew Gerlach
Quoted 154 lines
Thanks,
YiQuoted 147 lines
Quoted 147 lines
Quoted 141 lines
Quoted 141 lines
drivers/base/firmware_class.c +34
-0+if (len >=PATH_MAX ) { + rc = -ENAMETOOLONG ; +break ; + } + +if (!path || !*path) +continue ; + +if (!buf->data) { + buf->data =vmalloc (length); +if (!buf->data) { + rc = -ENOMEM ; +break ; + } + } + + file =filp_open (path,O_RDONLY ,0 ); +if (IS_ERR (file)) +continue ; + + buf->size =kernel_read (file, offset, (char *) buf->data, + length); +fput (file); +break ; + } + +__putname (path); + +if (rc) +dev_err (device,"loading %s failed with error %d\n" , + path, rc); +return rc; +} +/* firmware holds the ownership of pages */ static void
firmware_free_data(const struct firmware *fw){drivers/base/firmware_class.c +72
-0@@ -1267,6 +1323,78 @@ request_firmware(const struct firmware **firmware_p, const char *name, }EXPORT_SYMBOL (request_firmware); +static int +_stream_firmware (const struct firmware **firmware_p,const char *name, +struct device *device,void *buf,size_t size, +unsigned int opt_flags,size_t offset,size_t length) +{ +int ret; +struct firmware *fw =NULL ; +struct firmware_buf *fbuf; + +if ((!firmware_p) || (!name || name[0 ] =='\0' )) { +dev_err (device,"invalid firmware pointer or file name\n" ); +return -EINVAL ; + } + +if (!*firmware_p) { + ret =_request_firmware_prepare (&fw, name, device, buf, size); +if (ret <=0 ) { + dev_err(device, "%s: _request_firmware_prepare failed %d\n", + __func__, ret); + } + }else { + fw = (struct firmware *) *firmware_p; + } + + fbuf = (struct firmware_buf *) fw->priv; + ret =fw_stream_filesystem_firmware (device, fbuf, offset, length); + fw->size = fbuf->size; + fw->data = fbuf->data; + *firmware_p = fw; + +if (ret) +dev_err (device,"streaming with error %d\n" , ret); +return ret; +} + +/** +* stream_firmware: - send firmware request and wait for it +* @firmware_p: pointer to firmware image +* @name: name of firmware file +* @device: device for which firmware is being loaded +* @offset: offset of the file to read from +* @length: length in bytes to read +* +* @firmware_p will be used to return a firmware image by the name +* of @name for device @device. +* +* Should be called from user context where sleeping is allowed. +* +* @name will be used as $FIRMWARE in the uevent environment and +* should be distinctive enough not to be confused with any other +* firmware image for this or any other device. +* +* Caller must hold the reference count of @device. +* +* The function can be called safely inside device's suspend and +* resume callback. +**/ +int +stream_firmware (const struct firmware **firmware_p,const char *name, +struct device *device,size_t offset,size_t length) +{ +size_t ret; + +/* Need to pin this module until return */ +__module_get (THIS_MODULE ); + ret =_stream_firmware (firmware_p, name, device,NULL ,0 , +FW_OPT_UEVENT |FW_OPT_NO_WARN , offset, length); +module_put (THIS_MODULE ); +return ret; +} +EXPORT_SYMBOL (stream_firmware); +/** *
request_firmware_direct: - load firmware directly without usermode
helper
* @firmware_p: pointer to firmware imageinclude/linux/firmware.h +2
-0@@ -41,6 +41,8 @@ struct builtin_fw {#if defined(CONFIG_FW_LOADER ) || (defined(CONFIG_FW_LOADER_MODULE ) && defined(MODULE ))int request_firmware (const struct firmware **fw,const char *name,struct device *device); +int stream_firmware (const struct firmware **fw,const char *name, +struct device *device,size_t offset,size_t length);int request_firmware_nowait(
struct module *module, bool uevent,
const char *name, struct device *device,gfp_tgfp, void *context,Signature · 6 lines
2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-fpga" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.htmlSignature · 3 lines
To unsubscribe from this list: send the line "unsubscribe linux-fpga" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC 1/2] firmware class: Add stream_firmware API.
In reply to [email protected]On Thu, Mar 9, 2017 at 6:18 PM, <[email protected]> wrote:
Hi Yi,
As FPGA image sizes are increasing, this change can be really helpful. I have one comment below.
Alan Tull
Quoted 47 lines
From: Yi Li <[email protected]>
Add function to load firmware in multiple chucks instead of
loading the whole big firmware file at once.
Signed-off-by Yi Li <[email protected]>--- drivers/base/firmware_class.c | 128 ++++++++++++++++++++++++++++++++++++++++++ include/linux/firmware.h | 2 + 2 files changed, 130 insertions(+)drivers/base/firmware_class.c +27
-0@@ -436,6 +436,62 @@ fw_get_filesystem_firmware(struct device *device, struct firmware_buf *buf)return rc; } +static int +fw_stream_filesystem_firmware (struct device *device,struct firmware_buf *buf, +size_t offset,size_t length) +{ +int i, len; +char *path; +int rc =0 ; +struct file *file; + + buf->size =0 ; + + path =__getname (); +if (!path) +return -ENOMEM ; + +for (i =0 ; i <ARRAY_SIZE (fw_path); i++) { +/* skip the unset customized path */ +if (!fw_path[i][0 ]) +continue ; + + len =snprintf (path,PATH_MAX ,"%s/%s" , + fw_path[i], buf->fw_id); +if (len >=PATH_MAX ) { + rc = -ENAMETOOLONG ; +break ; + } +
drivers/base/firmware_class.c fw_get_filesystem_firmware(struct device *device, struct firmware_buf *buf) · line 475
Quoted 10 lines
drivers/base/firmware_class.c +10
-0+if (!path || !*path) +continue ; + +if (!buf->data) { + buf->data =vmalloc (length); +if (!buf->data) { + rc = -ENOMEM ; +break ; + } + }
Your implementation is pretty straightforward. My one complaint is that this searches for the file on the firmware path each time we need to get the next chunk of the firmware. Could you change this to find the file in the firmware path once and save that path somewhere? Possibly added to struct firmware_buf since that's the priv.
Quoted 121 lines
drivers/base/firmware_class.c +91
-0+ + file =filp_open (path,O_RDONLY ,0 ); +if (IS_ERR (file)) +continue ; + + buf->size =kernel_read (file, offset, (char *) buf->data, + length); +fput (file); +break ; + } + +__putname (path); + +if (rc) +dev_err (device,"loading %s failed with error %d\n" , + path, rc); +return rc; +} +/* firmware holds the ownership of pages */ static void firmware_free_data (const struct firmware *fw) {@@ -1267,6 +1323,78 @@ request_firmware(const struct firmware **firmware_p, const char *name, }EXPORT_SYMBOL (request_firmware); +static int +_stream_firmware (const struct firmware **firmware_p,const char *name, +struct device *device,void *buf,size_t size, +unsigned int opt_flags,size_t offset,size_t length) +{ +int ret; +struct firmware *fw =NULL ; +struct firmware_buf *fbuf; + +if ((!firmware_p) || (!name || name[0 ] =='\0' )) { +dev_err (device,"invalid firmware pointer or file name\n" ); +return -EINVAL ; + } + +if (!*firmware_p) { + ret =_request_firmware_prepare (&fw, name, device, buf, size); +if (ret <=0 ) { +dev_err (device,"%s: _request_firmware_prepare failed %d\n" , + __func__, ret); + } + }else { + fw = (struct firmware *) *firmware_p; + } + + fbuf = (struct firmware_buf *) fw->priv; + ret =fw_stream_filesystem_firmware (device, fbuf, offset, length); + fw->size = fbuf->size; + fw->data = fbuf->data; + *firmware_p = fw; + +if (ret) +dev_err (device,"streaming with error %d\n" , ret); +return ret; +} + +/** +* stream_firmware: - send firmware request and wait for it +* @firmware_p: pointer to firmware image +* @name: name of firmware file +* @device: device for which firmware is being loaded +* @offset: offset of the file to read from +* @length: length in bytes to read +* +* @firmware_p will be used to return a firmware image by the name +* of @name for device @device. +* +* Should be called from user context where sleeping is allowed. +* +* @name will be used as $FIRMWARE in the uevent environment and +* should be distinctive enough not to be confused with any other +* firmware image for this or any other device. +* +* Caller must hold the reference count of @device. +* +* The function can be called safely inside device's suspend and +* resume callback. +**/ +int +stream_firmware (const struct firmware **firmware_p,const char *name, +struct device *device,size_t offset,size_t length) +{ +size_t ret; + +/* Need to pin this module until return */ +__module_get (THIS_MODULE ); + ret =_stream_firmware (firmware_p, name, device,NULL ,0 , +FW_OPT_UEVENT |FW_OPT_NO_WARN , offset, length); +module_put (THIS_MODULE ); +return ret; +} +EXPORT_SYMBOL (stream_firmware); +/** * request_firmware_direct: - load firmware directly without usermode helper * @firmware_p: pointer to firmware image include/linux/firmware.h +2
-1@@ -41,6 +41,8 @@ struct builtin_fw {#if defined(CONFIG_FW_LOADER ) || (defined(CONFIG_FW_LOADER_MODULE ) && defined(MODULE ))int request_firmware (const struct firmware **fw,const char *name,struct device *device); +int stream_firmware (const struct firmware **fw,const char *name, +struct device *device,size_t offset,size_t length); int request_firmware_nowait( struct module *module, bool uevent, const char *name, struct device *device, gfp_t gfp, void *context, --2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-fpga" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC 1/2] firmware class: Add stream_firmware API.
Quoted 10 lines · Alan Tull
drivers/base/firmware_class.c request_firmware(const struct firmware **firmware_p, const char *name, · line 1392
Quoted 10 lines
drivers/base/firmware_class.c +10
-0+int +stream_firmware (const struct firmware **firmware_p,const char *name, +struct device *device,size_t offset,size_t length) +{ +size_t ret; + +/* Need to pin this module until return */ +__module_get (THIS_MODULE ); + ret =_stream_firmware (firmware_p, name, device,NULL ,0 , +FW_OPT_UEVENT |FW_OPT_NO_WARN , offset, length);
IIUC, here you are setting size == 0 and buf == NULL to prevent _request_firmware_prepare from attempting to load from built in firmware.
So three of the parameters buf, size, and opt_flags are fixed and don't need to be passed to _stream_firmware().
Alternatively, I wonder how hard it would be to code this so that the streaming interface will fall back and successfully get the built in or cached firmware if it exists and stream it out in PAGE_SIZE chunks.
Alan Tull
Re: [RFC 1/2] firmware class: Add stream_firmware API.
Alan
Quoted 16 lines · Alan Tull
Quoted 10 lines · Alan Tull
drivers/base/firmware_class.c request_firmware(const struct firmware **firmware_p, const char *name, · line 1392
Quoted 10 lines
drivers/base/firmware_class.c +10
-0+int +stream_firmware (const struct firmware **firmware_p,const char *name, +struct device *device,size_t offset,size_t length) +{ +size_t ret; + +/* Need to pin this module until return */ +__module_get (THIS_MODULE ); + ret =_stream_firmware (firmware_p, name, device,NULL ,0 , +FW_OPT_UEVENT |FW_OPT_NO_WARN , offset, length);IIUC, here you are setting size == 0 and buf == NULL to prevent
_request_firmware_preparefrom attempting to load from built in firmware.
Quoted 2 lines
So three of the parameters buf, size, and
opt_flagsare fixed and don't need to be passed to_stream_firmware().
Sure.
Quoted 3 lines
Alternatively, I wonder how hard it would be to code this so that the streaming interface will fall back and successfully get the built in or cached firmware if it exists and stream it out in
PAGE_SIZEchunks.
That's an interesting idea, I will try it out and submit patch for review later. On another hand, if the kernel already cache the whole firmware image, why should we use streaming instead of regular request_firmware?
Quoted 6 lines
Alan Tull
--
To unsubscribe from this list: send the line "unsubscribe linux-fpga" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC 1/2] firmware class: Add stream_firmware API.
Quoted 30 lines · Yi
Alan
Quoted 20 lines · Alan Tull
Quoted 11 lines · Alan Tull
Quoted 11 lines
drivers/base/firmware_class.c +10
-0+int +stream_firmware (const struct firmware **firmware_p,const char *name, +struct device *device,size_t offset,size_t length) +{ +size_t ret; + +/* Need to pin this module until return */ +__module_get (THIS_MODULE ); + ret = _stream_firmware(firmware_p, name, device, NULL, 0, + FW_OPT_UEVENT | FW_OPT_NO_WARN, offset,length);
IIUC, here you are setting size == 0 and buf == NULL to prevent
_request_firmware_preparefrom attempting to load from built in firmware.Quoted 2 lines
So three of the parameters buf, size, and
opt_flagsare fixed and don't need to be passed to_stream_firmware().Sure.
Quoted 8 lines
Quoted 3 lines
Alternatively, I wonder how hard it would be to code this so that the streaming interface will fall back and successfully get the built in or cached firmware if it exists and stream it out in
PAGE_SIZEchunks.That's an interesting idea, I will try it out and submit patch for review later. On another hand, if the kernel already cache the whole firmware image, why should we use streaming instead of regular
request_firmware?
The caller doesn't know whether the firmware is cached or not. The caller just wants the firmware if it exists, wherever it is. If that can be made automatic then the caller doesn't have to first attempt stream_firmware and then if that fails fall back to calling request_firmware.
Quoted 9 lines
Quoted 7 lines
Alan Tull
--
To unsubscribe from this list: send the line "unsubscribe linux-fpga" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Luis R. Rodriguez
maintainerRe: [RFC 1/2] firmware class: Add stream_firmware API.
In reply to [email protected]Quoted 65 lines · On Thu, Mar 09, 2017 at 06:18:09PM -0600, [email protected] wrote:
From: Yi Li <[email protected]>
Add function to load firmware in multiple chucks instead of
loading the whole big firmware file at once.
Signed-off-by Yi Li <[email protected]>--- drivers/base/firmware_class.c | 128 ++++++++++++++++++++++++++++++++++++++++++ include/linux/firmware.h | 2 + 2 files changed, 130 insertions(+)drivers/base/firmware_class.c +45
-0@@ -436,6 +436,62 @@ fw_get_filesystem_firmware(struct device *device, struct firmware_buf *buf)return rc; } +static int +fw_stream_filesystem_firmware (struct device *device,struct firmware_buf *buf, +size_t offset,size_t length) +{ +int i, len; +char *path; +int rc =0 ; +struct file *file; + + buf->size =0 ; + + path =__getname (); +if (!path) +return -ENOMEM ; + +for (i =0 ; i <ARRAY_SIZE (fw_path); i++) { +/* skip the unset customized path */ +if (!fw_path[i][0 ]) +continue ; + + len =snprintf (path,PATH_MAX ,"%s/%s" , + fw_path[i], buf->fw_id); +if (len >=PATH_MAX ) { + rc = -ENAMETOOLONG ; +break ; + } + +if (!path || !*path) +continue ; + +if (!buf->data) { + buf->data =vmalloc (length); +if (!buf->data) { + rc = -ENOMEM ; +break ; + } + } + + file =filp_open (path,O_RDONLY ,0 ); +if (IS_ERR (file)) +continue ; + + buf->size =kernel_read (file, offset, (char *) buf->data, + length); +fput (file);
drivers/base/firmware_class.c fw_get_filesystem_firmware(struct device *device, struct firmware_buf *buf) · line 493
Quoted 10 lines
drivers/base/firmware_class.c +10
-0+break ; + } + +__putname (path); + +if (rc) +dev_err (device,"loading %s failed with error %d\n" , + path, rc); +return rc; +}
Yet another API call to read files form the fs seems rather odd, are you sure nothing can be done to re-purpose the existing call ?
drivers/base/firmware_class.c fw_get_filesystem_firmware(struct device *device, struct firmware_buf *buf) · line 495
Quoted 2 lines
drivers/base/firmware_class.c +2
-0+ +EXPORT_SYMBOL (stream_firmware);
New functionality should be EXPORT_SYMBOL_GPL().
include/linux/firmware.h struct builtin_fw { · line 45
Quoted 10 lines
include/linux/firmware.h +2
-0@@ -41,6 +41,8 @@ struct builtin_fw {#if defined(CONFIG_FW_LOADER ) || (defined(CONFIG_FW_LOADER_MODULE ) && defined(MODULE ))int request_firmware (const struct firmware **fw,const char *name,struct device *device); +int stream_firmware (const struct firmware **fw,const char *name, +struct device *device,size_t offset,size_t length);
Have you looked at the rather new request_firmware_into_buf() ? I hated that as it did not get any proper code *review* but its there now... If we can leverage off of it to give us something useful for actual upstream drivers rather than cruft outside of the kernel I'd be a bit happier.
Also, please note that I had been noting we keep extending the firmware API with loose APIs, I've been consolidating a bit of this into a newer API which provides a flexible API for us. Since this is not upstream I don't expect you to work off of that, but I will Cc you on some updated patches which will fold in this work, I am expecting that the API we will ultimately use for this feature you are preoposing could be folded there.
So for now, please consider the review notes above, and we can later see how we fold this into a new set of APIs which I hope to bake this week.
Luis
Re: [RFC 1/2] firmware class: Add stream_firmware API.
hi Luis,
Quoted 70 lines · Luis R. Rodriguez
Quoted 69 lines · On Thu, Mar 09, 2017 at 06:18:09PM -0600, [email protected] wrote:
From: Yi Li <[email protected]>
Add function to load firmware in multiple chucks instead of
loading the whole big firmware file at once.
Signed-off-by Yi Li <[email protected]>--- drivers/base/firmware_class.c | 128 ++++++++++++++++++++++++++++++++++++++++++ include/linux/firmware.h | 2 + 2 files changed, 130 insertions(+)drivers/base/firmware_class.c +49
-0@@ -436,6 +436,62 @@ fw_get_filesystem_firmware(struct device *device, struct firmware_buf *buf)return rc; } +static int +fw_stream_filesystem_firmware (struct device *device,struct firmware_buf *buf, +size_t offset,size_t length) +{ +int i, len; +char *path; +int rc =0 ; +struct file *file; + + buf->size =0 ; + + path =__getname (); +if (!path) +return -ENOMEM ; + +for (i =0 ; i <ARRAY_SIZE (fw_path); i++) { +/* skip the unset customized path */ +if (!fw_path[i][0 ]) +continue ; + + len =snprintf (path,PATH_MAX ,"%s/%s" , + fw_path[i], buf->fw_id); +if (len >=PATH_MAX ) { + rc = -ENAMETOOLONG ; +break ; + } + +if (!path || !*path) +continue ; + +if (!buf->data) { + buf->data =vmalloc (length); +if (!buf->data) { + rc = -ENOMEM ; +break ; + } + } + + file =filp_open (path,O_RDONLY ,0 ); +if (IS_ERR (file)) +continue ; + + buf->size =kernel_read (file, offset, (char *) buf->data, + length); +fput (file); +break ; + } + +__putname (path);
Quoted 8 lines
drivers/base/firmware_class.c fw_get_filesystem_firmware(struct device *device, struct firmware_buf *buf) · line 493
Quoted 6 lines
drivers/base/firmware_class.c +6
-0+ +if (rc) +dev_err (device,"loading %s failed with error %d\n" , + path, rc); +return rc; +}Yet another API call to read files form the fs seems rather odd, are you sure nothing can be done to re-purpose the existing call ?
Agree, I also hated to duplicate the read files from fs, what we are missing in existing API is an "offset", which will enable loading the firmware in pieces.
Quoted 4 lines
drivers/base/firmware_class.c fw_get_filesystem_firmware(struct device *device, struct firmware_buf *buf) · line 495
Quoted 3 lines
drivers/base/firmware_class.c +2
-0+ +EXPORT_SYMBOL (stream_firmware);New functionality should be
EXPORT_SYMBOL_GPL().
Got it.
Quoted 15 lines
include/linux/firmware.h struct builtin_fw { · line 45
Quoted 11 lines
include/linux/firmware.h +2
-0@@ -41,6 +41,8 @@ struct builtin_fw {#if defined(CONFIG_FW_LOADER ) || (defined(CONFIG_FW_LOADER_MODULE ) && defined(MODULE ))int request_firmware (const struct firmware **fw,const char *name,struct device *device); +int stream_firmware (const struct firmware **fw,const char *name, +struct device *device,size_t offset,size_t length);Have you looked at the rather new
request_firmware_into_buf()? I hated that as it did not get any proper code *review* but its there now... If we can leverage off of it to give us something useful for actual upstream drivers rather than cruft outside of the kernel I'd be a bit happier.
Yes, I looked request_firmware_into_buf API, it still load the whole firmware image into a big memory buffer (but allocated outside of firmware class).
Quoted 10 lines
Also, please note that I had been noting we keep extending the firmware API with loose APIs, I've been consolidating a bit of this into a newer API which provides a flexible API for us. Since this is not upstream I don't expect you to work off of that, but I will Cc you on some updated patches which will fold in this work, I am expecting that the API we will ultimately use for this feature you are preoposing could be folded there.
So for now, please consider the review notes above, and we can later see how we fold this into a new set of APIs which I hope to bake this week.
Cool, copy me on the updated patches. I am also working on the patch based on Alan Tull's comments. Pardon me if I am slow this 2 weeks due to family emergency.
Quoted 6 lines
Luis
--
To unsubscribe from this list: send the line "unsubscribe linux-fpga" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
RFC 2/2 fpga manager: Add fpga_mgr_firmware_stream API
In reply to [email protected]From: Yi Li <[email protected]>
Add fpga_mgr_firmware_stream API, which can load and program firmware
in trucks to FPGA instead of the whole file.
--- drivers/fpga/fpga-mgr.c | 77 +++++++++++++++++++++++++++++++++++++++++++ include/linux/fpga/fpga-mgr.h | 4 +++ 2 files changed, 81 insertions(+)
drivers/fpga/fpga-mgr.c +77 -0
@@ -27,10 +27,15 @@#include <linux/slab.h> #include <linux/scatterlist.h> #include <linux/highmem.h> +#include <linux/sizes.h> static DEFINE_IDA (fpga_mgr_ida);static struct class *fpga_mgr_class; +static int streamsize =SZ_4K ; +module_param (streamsize, int,0664 ); +MODULE_PARM_DESC (streamsize,"buffer size for firmware streaming" ); +/* * Call the low level driver's write_init function. This will do the * device-specific things to get the FPGA into the state where it is ready to
@@ -309,6 +314,78 @@ int fpga_mgr_firmware_load(struct fpga_manager *mgr, }EXPORT_SYMBOL_GPL (fpga_mgr_firmware_load); +/** +* fpga_mgr_firmware_load - request firmware and load to fpga +* @mgr: fpga manager +* @info: fpga image specific information +* @image_name: name of image file on the firmware search path +* +* Request an FPGA image using the firmware class, then write out to the FPGA. +* Update the state before each step to provide info on what step failed if +* there is a failure. This code assumes the caller got the mgr pointer +* from of_fpga_mgr_get() or fpga_mgr_get() and checked that it is not an error +* code. +* +* Return: 0 on success, negative error code otherwise. +*/ +int fpga_mgr_firmware_stream (struct fpga_manager *mgr, +struct fpga_image_info *info, +const char *image_name) +{ +struct device *dev = &mgr->dev; +const struct firmware *fw =NULL ; +int ret; +size_t size =INT_MAX , offset =0 ; +bool start_flag =1 ; + +dev_info (dev,"writing %s to %s with buffer size %d\n" , + image_name, mgr->name, streamsize); + + mgr->state =FPGA_MGR_STATE_FIRMWARE_REQ ; + +while (size >0 ) { + ret =stream_firmware (&fw, image_name, dev, offset, streamsize); +if (ret) { +dev_err (dev,"Error reading firmware %d\n" , ret); + mgr->state =FPGA_MGR_STATE_FIRMWARE_REQ_ERR ; +break ; + } + +/* +* init. +*/ +if (start_flag) { + ret =fpga_mgr_write_init_buf (mgr, info, fw->data, + fw->size); + start_flag =0 ; +if (ret) +break ; + } + +/* +* Write the FPGA image to the FPGA. +*/ + mgr->state =FPGA_MGR_STATE_WRITE ; + ret = mgr->mops->write (mgr, fw->data, fw->size); +if (ret) { +dev_err (dev,"Error while writing image data to FPGA\n" ); + mgr->state =FPGA_MGR_STATE_WRITE_ERR ; +break ; + } + + offset += fw->size; + size -= fw->size; +if (fw->size < streamsize) +break ; + } + + ret =fpga_mgr_write_complete (mgr, info); + +release_firmware (fw); +return ret; +} +EXPORT_SYMBOL_GPL (fpga_mgr_firmware_stream); +int fpga_mgr_load (struct fpga_manager *mgr,struct fpga_image_info *info) {if (info->firmware_name)
include/linux/fpga/fpga-mgr.h +4 -0
@@ -151,6 +151,10 @@ int fpga_mgr_firmware_load(struct fpga_manager *mgr,struct fpga_image_info *info, const char *image_name); +int fpga_mgr_firmware_stream (struct fpga_manager *mgr, +struct fpga_image_info *info, +const char *image_name); +int fpga_mgr_load (struct fpga_manager *mgr,struct fpga_image_info *info);int fpga_mgr_lock (struct fpga_manager *mgr);
Signature · 1 line
2.7.4
Re: [RFC 2/2] fpga manager: Add fpga_mgr_firmware_stream API
On Thu, Mar 9, 2017 at 6:18 PM, <[email protected]> wrote:
Hi Yi,
Thanks for your RFC. I believe this functionality is badly needed.
I had a few comments about the chunk size and some nits about comments below...
Quoted 18 lines
From: Yi Li <[email protected]>
Add
fpga_mgr_firmware_streamAPI, which can load and program firmwarein trucks to FPGA instead of the whole file.
Signed-off-by Yi Li <[email protected]>--- drivers/fpga/fpga-mgr.c | 77 +++++++++++++++++++++++++++++++++++++++++++ include/linux/fpga/fpga-mgr.h | 4 +++ 2 files changed, 81 insertions(+)drivers/fpga/fpga-mgr.c +0
-0@@ -27,10 +27,15 @@#include <linux/slab.h>
drivers/fpga/fpga-mgr.c line 37
Quoted 10 lines
drivers/fpga/fpga-mgr.c +4
-0#include <linux/scatterlist.h> #include <linux/highmem.h> +#include <linux/sizes.h> static DEFINE_IDA (fpga_mgr_ida);static struct class *fpga_mgr_class; +static int streamsize =SZ_4K ; +module_param (streamsize, int,0664 ); +MODULE_PARM_DESC (streamsize,"buffer size for firmware streaming" );
I think we could fix the chunk size at PAGE_SIZE unless someone can state a reason for needing something different. Below I have one reason why we will sometimes need > PAGE_SIZE.
Quoted 15 lines
drivers/fpga/fpga-mgr.c +8
-0+/* * Call the low level driver's write_init function. This will do the * device-specific things to get the FPGA into the state where it is ready to @@ -309,6 +314,78 @@ int fpga_mgr_firmware_load(struct fpga_manager *mgr, }EXPORT_SYMBOL_GPL (fpga_mgr_firmware_load); +/** +* fpga_mgr_firmware_load - request firmware and load to fpga +* @mgr: fpga manager +* @info: fpga image specific information +* @image_name: name of image file on the firmware search path +* +* Request an FPGA image using the firmware class, then write out to the FPGA.
drivers/fpga/fpga-mgr.c int fpga_mgr_firmware_load(struct fpga_manager *mgr, · line 333
Quoted 10 lines
drivers/fpga/fpga-mgr.c +10
-0+* Update the state before each step to provide info on what step failed if +* there is a failure. This code assumes the caller got the mgr pointer +* from of_fpga_mgr_get() or fpga_mgr_get() and checked that it is not an error +* code. +* +* Return: 0 on success, negative error code otherwise. +*/ +int fpga_mgr_firmware_stream (struct fpga_manager *mgr, +struct fpga_image_info *info, +const char *image_name)
No need for both fpga_mgr_firmware_load and fpga_mgr_firmware_stream. Just replace the old fpga_mgr_firmware_load with this function.
Quoted 13 lines
drivers/fpga/fpga-mgr.c +13
-0+{ +struct device *dev = &mgr->dev; +const struct firmware *fw =NULL ; +int ret; +size_t size =INT_MAX , offset =0 ; +bool start_flag =1 ; + +dev_info (dev,"writing %s to %s with buffer size %d\n" , + image_name, mgr->name, streamsize); + + mgr->state =FPGA_MGR_STATE_FIRMWARE_REQ ; + +while (size >0 ) {
drivers/fpga/fpga-mgr.c int fpga_mgr_firmware_load(struct fpga_manager *mgr, · line 356
Quoted 10 lines
drivers/fpga/fpga-mgr.c +10
-0+ ret =stream_firmware (&fw, image_name, dev, offset, streamsize); +if (ret) { +dev_err (dev,"Error reading firmware %d\n" , ret); + mgr->state =FPGA_MGR_STATE_FIRMWARE_REQ_ERR ; +break ; + } + +/* +* init. +*/
We don't really need this comment.
drivers/fpga/fpga-mgr.c int fpga_mgr_firmware_load(struct fpga_manager *mgr, · line 359
Quoted 3 lines
drivers/fpga/fpga-mgr.c +3
-0+if (start_flag) { + ret =fpga_mgr_write_init_buf (mgr, info, fw->data, + fw->size);
When the fpga manager is registered, one of the ops is initial_header_size, which specifies how much buffer the write_init needs. So this call could fail if initial_header_size < streamsize.
I suggest that you make the streamsize equal to the smallest multiple of PAGE_SIZE that is >= initial_header_size.
drivers/fpga/fpga-mgr.c int fpga_mgr_firmware_load(struct fpga_manager *mgr, · line 367
Quoted 8 lines
drivers/fpga/fpga-mgr.c +8
-0+ start_flag =0 ; +if (ret) +break ; + } + +/* +* Write the FPGA image to the FPGA. +*/
Or this comment.
Quoted 29 lines
drivers/fpga/fpga-mgr.c +21
-0+ mgr->state =FPGA_MGR_STATE_WRITE ; + ret = mgr->mops->write (mgr, fw->data, fw->size); +if (ret) { +dev_err (dev,"Error while writing image data to FPGA\n" ); + mgr->state =FPGA_MGR_STATE_WRITE_ERR ; +break ; + } + + offset += fw->size; + size -= fw->size; +if (fw->size < streamsize) +break ; + } + + ret =fpga_mgr_write_complete (mgr, info); + +release_firmware (fw); +return ret; +} +EXPORT_SYMBOL_GPL (fpga_mgr_firmware_stream); +int fpga_mgr_load (struct fpga_manager *mgr,struct fpga_image_info *info) {if (info->firmware_name)include/linux/fpga/fpga-mgr.h +0
-0
include/linux/fpga/fpga-mgr.h int fpga_mgr_firmware_load(struct fpga_manager *mgr, · line 156
Quoted 6 lines
include/linux/fpga/fpga-mgr.h +3
-0@@ -151,6 +151,10 @@ int fpga_mgr_firmware_load(struct fpga_manager *mgr,struct fpga_image_info *info, const char *image_name); +int fpga_mgr_firmware_stream (struct fpga_manager *mgr, +struct fpga_image_info *info, +const char *image_name);
Don't need both fpga_mgr_firmware_load and fpga_mgr_firmware_stream, so no need to change the header.
Quoted 7 lines
include/linux/fpga/fpga-mgr.h +1
-1+int fpga_mgr_load (struct fpga_manager *mgr,struct fpga_image_info *info);int fpga_mgr_lock (struct fpga_manager *mgr); --2.7.4
Re: [RFC 2/2] fpga manager: Add fpga_mgr_firmware_stream API
Thanks Alan for the comments.
Quoted 59 lines · Alan Tull
On Thu, Mar 9, 2017 at 6:18 PM, <[email protected]> wrote:
Hi Yi,
Thanks for your RFC. I believe this functionality is badly needed.
I had a few comments about the chunk size and some nits about comments below...
Quoted 18 lines
From: Yi Li <[email protected]>
Add
fpga_mgr_firmware_streamAPI, which can load and program firmwarein trucks to FPGA instead of the whole file.
Signed-off-by Yi Li <[email protected]>--- drivers/fpga/fpga-mgr.c | 77 +++++++++++++++++++++++++++++++++++++++++++ include/linux/fpga/fpga-mgr.h | 4 +++ 2 files changed, 81 insertions(+)drivers/fpga/fpga-mgr.c +0
-0@@ -27,10 +27,15 @@#include <linux/slab.h> drivers/fpga/fpga-mgr.c line 37
Quoted 10 lines
drivers/fpga/fpga-mgr.c +4
-0#include <linux/scatterlist.h> #include <linux/highmem.h> +#include <linux/sizes.h> static DEFINE_IDA (fpga_mgr_ida);static struct class *fpga_mgr_class; +static int streamsize =SZ_4K ; +module_param (streamsize, int,0664 ); +MODULE_PARM_DESC (streamsize,"buffer size for firmware streaming" );I think we could fix the chunk size at
PAGE_SIZEunless someone can state a reason for needing something different. Below I have one reason why we will sometimes need >PAGE_SIZE.Quoted 19 lines
drivers/fpga/fpga-mgr.c +12
-0+/* * Call the low level driver's write_init function. This will do the * device-specific things to get the FPGA into the state where it is ready to @@ -309,6 +314,78 @@ int fpga_mgr_firmware_load(struct fpga_manager *mgr, }EXPORT_SYMBOL_GPL (fpga_mgr_firmware_load); +/** +* fpga_mgr_firmware_load - request firmware and load to fpga +* @mgr: fpga manager +* @info: fpga image specific information +* @image_name: name of image file on the firmware search path +* +* Request an FPGA image using the firmware class, then write out to the FPGA. +* Update the state before each step to provide info on what step failed if +* there is a failure. This code assumes the caller got the mgr pointer +* from of_fpga_mgr_get() or fpga_mgr_get() and checked that it is not an error +* code.
Quoted 8 lines
drivers/fpga/fpga-mgr.c int fpga_mgr_firmware_load(struct fpga_manager *mgr, · line 333
Quoted 6 lines
drivers/fpga/fpga-mgr.c +6
-0+* +* Return: 0 on success, negative error code otherwise. +*/ +int fpga_mgr_firmware_stream (struct fpga_manager *mgr, +struct fpga_image_info *info, +const char *image_name)No need for both
fpga_mgr_firmware_loadandfpga_mgr_firmware_stream. Just replace the oldfpga_mgr_firmware_loadwith this function.
Sure, will do.
Quoted 29 lines
Quoted 14 lines
drivers/fpga/fpga-mgr.c +13
-0+{ +struct device *dev = &mgr->dev; +const struct firmware *fw =NULL ; +int ret; +size_t size =INT_MAX , offset =0 ; +bool start_flag =1 ; + +dev_info (dev,"writing %s to %s with buffer size %d\n" , + image_name, mgr->name, streamsize); + + mgr->state =FPGA_MGR_STATE_FIRMWARE_REQ ; + +while (size >0 ) {drivers/fpga/fpga-mgr.c int fpga_mgr_firmware_load(struct fpga_manager *mgr, · line 356
Quoted 10 lines
drivers/fpga/fpga-mgr.c +10
-0+ ret =stream_firmware (&fw, image_name, dev, offset, streamsize); +if (ret) { +dev_err (dev,"Error reading firmware %d\n" , ret); + mgr->state =FPGA_MGR_STATE_FIRMWARE_REQ_ERR ; +break ; + } + +/* +* init. +*/ We don't really need this comment.
drivers/fpga/fpga-mgr.c int fpga_mgr_firmware_load(struct fpga_manager *mgr, · line 359
Quoted 3 lines
drivers/fpga/fpga-mgr.c +3
-0+if (start_flag) { + ret =fpga_mgr_write_init_buf (mgr, info, fw->data, + fw->size);
Quoted 6 lines
When the fpga manager is registered, one of the ops is
initial_header_size, which specifies how much buffer thewrite_initneeds. So this call could fail ifinitial_header_size< streamsize.I suggest that you make the streamsize equal to the smallest multiple of
PAGE_SIZEthat is >=initial_header_size.
Agree, we can fix the streamsize to something bigger than initial_header_size for the bitstream file. Another reason to have the variable streamsize is for the performance, although with Altera Cyclone V FPGA CvP I did not see much difference when increasing the buffer size, since the bottleneck is with programming through PCIe and the time spent with firmware file reading is negligible.
Quoted 60 lines
drivers/fpga/fpga-mgr.c int fpga_mgr_firmware_load(struct fpga_manager *mgr, · line 367
Quoted 9 lines
drivers/fpga/fpga-mgr.c +8
-0+ start_flag =0 ; +if (ret) +break ; + } + +/* +* Write the FPGA image to the FPGA. +*/ Or this comment.
Quoted 29 lines
drivers/fpga/fpga-mgr.c +21
-0+ mgr->state =FPGA_MGR_STATE_WRITE ; + ret = mgr->mops->write (mgr, fw->data, fw->size); +if (ret) { +dev_err (dev,"Error while writing image data to FPGA\n" ); + mgr->state =FPGA_MGR_STATE_WRITE_ERR ; +break ; + } + + offset += fw->size; + size -= fw->size; +if (fw->size < streamsize) +break ; + } + + ret =fpga_mgr_write_complete (mgr, info); + +release_firmware (fw); +return ret; +} +EXPORT_SYMBOL_GPL (fpga_mgr_firmware_stream); +int fpga_mgr_load (struct fpga_manager *mgr,struct fpga_image_info *info) {if (info->firmware_name)include/linux/fpga/fpga-mgr.h +0
-0include/linux/fpga/fpga-mgr.h int fpga_mgr_firmware_load(struct fpga_manager *mgr, · line 156
Quoted 6 lines
include/linux/fpga/fpga-mgr.h +3
-0@@ -151,6 +151,10 @@ int fpga_mgr_firmware_load(struct fpga_manager *mgr,struct fpga_image_info *info, const char *image_name); +int fpga_mgr_firmware_stream (struct fpga_manager *mgr, +struct fpga_image_info *info, +const char *image_name);Don't need both
fpga_mgr_firmware_loadandfpga_mgr_firmware_stream, so no need to change the header.Quoted 7 lines
include/linux/fpga/fpga-mgr.h +1
-1+int fpga_mgr_load (struct fpga_manager *mgr,struct fpga_image_info *info);int fpga_mgr_lock (struct fpga_manager *mgr); --2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-fpga" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 1 line · On Thu, 9 Mar 2017, [email protected] wrote:
From: Yi Li <[email protected]>
Hi Yi,
This functionality is extremely helpful. I am working with a
firmware image of about 90 MBs, and even using scatter-gather instead of a continguous piece of memory is a lot of memory.
Matthew Gerlach
Quoted 38 lines
As the FPGA hardware advances, the firmware image size grows (hundres of MBs or more). It could be an issue for kernel to allocate a big buffer to load the whole firmware file.
Here is an attempt to read the firmware file into a small buffer and program the FPGA in a loop (or so call the streaming mode). It should not be a performance hit for FPGA programing since the majority of time spend is with the FPGA CvP/PR-IP interface.pseudo code in fpga manager:
while (size > 0) { ret = stream_firmware(&fw, image_name, dev, offset, streamsize); ret = mgr->mops->write(mgr, fw->data, fw->size); offset += fw->size; size -= fw->size; }Thanks,
YiYi Li (2):
firmware class: Addstream_firmwareAPI.
fpga manager: Addfpga_mgr_firmware_streamAPIdrivers/base/firmware_class.c | 128 ++++++++++++++++++++++++++++++++++++++++++ drivers/fpga/fpga-mgr.c | 77 +++++++++++++++++++++++++ include/linux/firmware.h | 2 + include/linux/fpga/fpga-mgr.h | 4 ++ 4 files changed, 211 insertions(+)Signature · 6 lines
2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-fpga" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html