qmi: Use FAM instead of allocating a member
PATCH 1/8 qmi: Use FAM instead of allocating a member
Instead of allocating a separate buffer inside the request object, use a flexible array member (FAM). This allows the request metadata and data to be allocated within the same memory region. The only downside is that the data buffer is not released once the request has been sent over the socket. Since most requests are quite small, this shouldn't affect performance.
--- drivers/qmimodem/qmi.c | 45 ++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 26 deletions(-)
drivers/qmimodem/qmi.c +19 -26
@@ -129,10 +129,10 @@ struct qmi_result {struct qmi_request {uint16_t tid;uint8_t client; -void *buf; -size_t len;qmi_message_func_t callback;void *user_data; +uint16_t len; +uint8_t data[]; };struct qmi_notify {
@@ -192,22 +192,20 @@ static struct qmi_request *__request_alloc(uint8_t service,struct qmi_request *req;struct qmi_mux_hdr *hdr;struct qmi_message_hdr *msg; -uint16_t headroom; - - req = l_new(struct qmi_request, 1); +uint16_t hdrlen =QMI_MUX_HDR_SIZE ; +uint16_t msglen;if (service ==QMI_SERVICE_CONTROL ) - headroom =QMI_CONTROL_HDR_SIZE ; + hdrlen +=QMI_CONTROL_HDR_SIZE ;else - headroom =QMI_SERVICE_HDR_SIZE ; - - req->len =QMI_MUX_HDR_SIZE + headroom +QMI_MESSAGE_HDR_SIZE + length; - - req->buf =l_malloc (req->len); + hdrlen +=QMI_SERVICE_HDR_SIZE ; + msglen = hdrlen +QMI_MESSAGE_HDR_SIZE + length; + req =l_malloc (sizeof (struct qmi_request ) + msglen); + req->len = msglen; req->client = client; - hdr = req->buf; + hdr = (struct qmi_mux_hdr *) req->data; hdr->frame =0x01 ; hdr->length =L_CPU_TO_LE16 (req->len -1 );
@@ -215,14 +213,13 @@ static struct qmi_request *__request_alloc(uint8_t service, hdr->service = service; hdr->client = client; - msg = req->buf +QMI_MUX_HDR_SIZE + headroom; + msg = (struct qmi_message_hdr *) &req->data[hdrlen]; msg->message =L_CPU_TO_LE16 (message); msg->length =L_CPU_TO_LE16 (length);if (data && length >0 ) -memcpy (req->buf +QMI_MUX_HDR_SIZE + headroom + -QMI_MESSAGE_HDR_SIZE , data, length); +memcpy (req->data + hdrlen +QMI_MESSAGE_HDR_SIZE , data, length); req->callback = func; req->user_data = user_data;
@@ -234,7 +231,6 @@ static void __request_free(void *data) {struct qmi_request *req = data; -l_free (req->buf);l_free (req); }
@@ -637,26 +633,23 @@ static bool can_write_data(struct l_io *io, void *user_data)if (!req)return false; - bytes_written =write (l_io_get_fd (device->io), req->buf, req->len); + bytes_written =write (l_io_get_fd (device->io), req->data, req->len);if (bytes_written <0 )return false; -l_util_hexdump (false, req->buf, bytes_written, +l_util_hexdump (false, req->data, bytes_written, device->debug_func, device->debug_data); -__debug_msg (' ' , req->buf, bytes_written, +__debug_msg (' ' , req->data, bytes_written, device->debug_func, device->debug_data); - hdr = req->buf; + hdr = (struct qmi_mux_hdr *) req->data;if (hdr->service ==QMI_SERVICE_CONTROL )l_queue_push_tail (device->control_queue, req);else l_queue_push_tail (device->service_queue, req); -l_free (req->buf); - req->buf =NULL ; -if (l_queue_length (device->req_queue) >0 )return true;
@@ -686,12 +679,12 @@ static uint16_t __request_submit(struct qmi_device *device, {struct qmi_mux_hdr *mux; - mux = req->buf; + mux = (struct qmi_mux_hdr *) req->data;if (mux->service ==QMI_SERVICE_CONTROL ) {struct qmi_control_hdr *hdr; - hdr = req->buf +QMI_MUX_HDR_SIZE ; + hdr = (struct qmi_control_hdr *) &req->data[QMI_MUX_HDR_SIZE ]; hdr->type =0x00 ; hdr->transaction = device->next_control_tid++;if (device->next_control_tid ==0 )
@@ -700,7 +693,7 @@ static uint16_t __request_submit(struct qmi_device *device, }else {struct qmi_service_hdr *hdr; - hdr = req->buf +QMI_MUX_HDR_SIZE ; + hdr = (struct qmi_service_hdr *) &req->data[QMI_MUX_HDR_SIZE ]; hdr->type =0x00 ; hdr->transaction = device->next_service_tid++;if (device->next_service_tid <256 )
Signature · 1 line
2.43.0
PATCH 2/8 qmi: Ensure tid is initialized
When the qmi_request structure is allocated, the tid member is never initialized properly. This is usually okay since the request is submitted afterwards, but it is still better to initialize this member properly.
--- drivers/qmimodem/qmi.c | 1 + 1 file changed, 1 insertion(+)
drivers/qmimodem/qmi.c +1 -0
@@ -202,6 +202,7 @@ static struct qmi_request *__request_alloc(uint8_t service, msglen = hdrlen +QMI_MESSAGE_HDR_SIZE + length; req =l_malloc (sizeof (struct qmi_request ) + msglen); + req->tid =0 ; req->len = msglen; req->client = client;
Signature · 1 line
2.43.0
PATCH 3/8 qmi: Move and rename QMUX sync logic
In reply to Denis KenziorThis logic is QMUX only, move it to be spatially near the rest of QMUX specific logic and just above where these functions are used.
--- drivers/qmimodem/qmi.c | 58 +++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 29 deletions(-)
drivers/qmimodem/qmi.c +29 -29
@@ -1079,34 +1079,6 @@ static void discover_data_free(void *user_data)l_free (data); } -static void qmi_device_sync_callback (uint16_t message,uint16_t length, -const void *buffer,void *user_data) -{ -struct discover_data *data = user_data; - -if (data->func) - data->func (data->user_data); - -__qmi_device_discovery_complete (data->device, &data->super); -} - -/* sync will release all previous clients */ -static bool qmi_device_sync (struct qmi_device *device, -struct discover_data *data) -{ -struct qmi_request *req; - -__debug_device (device,"Sending sync to reset QMI" ); - - req =__request_alloc (QMI_SERVICE_CONTROL ,0x00 , -QMI_CTL_SYNC ,NULL ,0 , - qmi_device_sync_callback, data); - -__request_submit (device, req); - -return true; -} -int qmi_device_discover (struct qmi_device *device,qmi_discover_func_t func,void *user_data,qmi_destroy_func_t destroy) {
@@ -1402,6 +1374,34 @@ static struct qmi_request *find_control_request(struct qmi_device *device,return req; } +static void qmux_sync_callback (uint16_t message,uint16_t length, +const void *buffer,void *user_data) +{ +struct discover_data *data = user_data; + +if (data->func) + data->func (data->user_data); + +__qmi_device_discovery_complete (data->device, &data->super); +} + +/* sync will release all previous clients */ +static bool qmi_device_qmux_sync (struct qmi_device *device, +struct discover_data *data) +{ +struct qmi_request *req; + +__debug_device (device,"Sending sync to reset QMI" ); + + req =__request_alloc (QMI_SERVICE_CONTROL ,0x00 , +QMI_CTL_SYNC ,NULL ,0 , + qmux_sync_callback, data); + +__request_submit (device, req); + +return true; +} +static void qmux_discover_callback (uint16_t message,uint16_t length,const void *buffer,void *user_data) {
@@ -1479,7 +1479,7 @@ done:/* if the device support the QMI call SYNC over the CTL interface */ if ((qmux->control_major ==1 && qmux->control_minor >=5 ) || qmux->control_major >1 ) { -qmi_device_sync (data->device, data); +qmi_device_qmux_sync (data->device, data);return ; }
Signature · 1 line
2.43.0
PATCH 4/8 qmi: Introduce __ctl_request_submit
In reply to Denis Kenzior__request_submit was handling both CTL and non-CTL requests. Split this function into two, one for submitting CTL requests, and one that handles normal service traffic. This allows CTL requests to be isolated into QMUX specific driver methods that use them. While here, also move next_control_tid member into the QMUX qmi_device subclass.
--- drivers/qmimodem/qmi.c | 71 ++++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 30 deletions(-)
drivers/qmimodem/qmi.c +41 -30
@@ -77,7 +77,6 @@ struct qmi_device {struct l_queue *control_queue;struct l_queue *service_queue;struct l_queue *discovery_queue; -uint8_t next_control_tid;uint16_t next_service_tid;qmi_debug_func_t debug_func;void *debug_data;
@@ -100,6 +99,7 @@ struct qmi_device_qmux {qmi_destroy_func_t shutdown_destroy;struct l_idle *shutdown_idle;unsigned int release_users; +uint8_t next_control_tid; };struct qmi_service {
@@ -678,32 +678,18 @@ static void wakeup_writer(struct qmi_device *device)static uint16_t __request_submit (struct qmi_device *device,struct qmi_request *req) { -struct qmi_mux_hdr *mux; +struct qmi_service_hdr *hdr = + (struct qmi_service_hdr *) &req->data[QMI_MUX_HDR_SIZE ]; - mux = (struct qmi_mux_hdr *) req->data; + hdr->type =0x00 ; + hdr->transaction = device->next_service_tid++; -if (mux->service ==QMI_SERVICE_CONTROL ) { -struct qmi_control_hdr *hdr; +if (device->next_service_tid <256 ) + device->next_service_tid =256 ; - hdr = (struct qmi_control_hdr *) &req->data[QMI_MUX_HDR_SIZE ]; - hdr->type =0x00 ; - hdr->transaction = device->next_control_tid++; -if (device->next_control_tid ==0 ) - device->next_control_tid =1 ; - req->tid = hdr->transaction; - }else { -struct qmi_service_hdr *hdr; - - hdr = (struct qmi_service_hdr *) &req->data[QMI_MUX_HDR_SIZE ]; - hdr->type =0x00 ; - hdr->transaction = device->next_service_tid++; -if (device->next_service_tid <256 ) - device->next_service_tid =256 ; - req->tid = hdr->transaction; - } + req->tid = hdr->transaction;l_queue_push_tail (device->req_queue, req); -wakeup_writer (device);return req->tid;
@@ -934,7 +920,6 @@ static int qmi_device_init(struct qmi_device *device, int fd, device->service_list =l_hashmap_new (); - device->next_control_tid =1 ; device->next_service_tid =256 ; device->ops = ops;
@@ -1310,6 +1295,26 @@ struct service_create_shared_data {struct l_idle *idle; }; +static uint8_t __ctl_request_submit (struct qmi_device_qmux *qmux, +struct qmi_request *req) +{ +struct qmi_control_hdr *hdr = + (struct qmi_control_hdr *) &req->data[QMI_MUX_HDR_SIZE ]; + + hdr->type =0x00 ; + hdr->transaction = qmux->next_control_tid++; + +if (qmux->next_control_tid ==0 ) + qmux->next_control_tid =1 ; + + req->tid = hdr->transaction; + +l_queue_push_tail (qmux->super.req_queue, req); +wakeup_writer (&qmux->super); + +return req->tid; +} +static void service_create_shared_reply (struct l_idle *idle,void *user_data) {struct service_create_shared_data *data = user_data;
@@ -1386,18 +1391,18 @@ static void qmux_sync_callback(uint16_t message, uint16_t length, }/* sync will release all previous clients */ -static bool qmi_device_qmux_sync (struct qmi_device *device, +static bool qmi_device_qmux_sync (struct qmi_device_qmux *qmux,struct discover_data *data) {struct qmi_request *req; -__debug_device (device,"Sending sync to reset QMI" ); +__debug_device (&qmux->super,"Sending sync to reset QMI" ); req =__request_alloc (QMI_SERVICE_CONTROL ,0x00 ,QMI_CTL_SYNC ,NULL ,0 , qmux_sync_callback, data); -__request_submit (device, req); +__ctl_request_submit (qmux, req);return true; }
@@ -1479,7 +1484,7 @@ done:/* if the device support the QMI call SYNC over the CTL interface */ if ((qmux->control_major ==1 && qmux->control_minor >=5 ) || qmux->control_major >1 ) { -qmi_device_qmux_sync (data->device, data); +qmi_device_qmux_sync (qmux, data);return ; }
@@ -1516,6 +1521,8 @@ static int qmi_device_qmux_discover(struct qmi_device *device, void *user_data, qmi_destroy_func_t destroy) { +struct qmi_device_qmux *qmux = + l_container_of(device, struct qmi_device_qmux, super);struct discover_data *data;struct qmi_request *req;
@@ -1536,7 +1543,7 @@ static int qmi_device_qmux_discover(struct qmi_device *device,QMI_CTL_GET_VERSION_INFO , NULL, 0, qmux_discover_callback, data); - data->tid =__request_submit (device, req); + data->tid =__ctl_request_submit (qmux, req); data->timeout =l_timeout_create (5 , qmux_discover_reply_timeout, data,NULL );
@@ -1662,6 +1669,8 @@ static int qmi_device_qmux_client_create(struct qmi_device *device, qmi_create_func_t func, void *user_data, qmi_destroy_func_t destroy) { + struct qmi_device_qmux *qmux = + l_container_of(device, struct qmi_device_qmux, super);unsigned char client_req[] = {0x01 ,0x01 ,0x00 , service_type };struct qmi_request *req;struct qmux_client_create_data *data;
@@ -1697,7 +1706,7 @@ static int qmi_device_qmux_client_create(struct qmi_device *device, client_req,sizeof (client_req), qmux_client_create_callback, data); - data->tid =__request_submit (device, req); + data->tid =__ctl_request_submit (qmux, req); data->timeout =l_timeout_create (8 , qmux_client_create_reply, data,NULL );
@@ -1734,7 +1743,7 @@ static void qmi_device_qmux_client_release(struct qmi_device *device, release_req,sizeof (release_req), qmux_client_release_callback, qmux); -__request_submit (device, req); +__ctl_request_submit (qmux, req); }static void qmux_shutdown_destroy (void *user_data)
@@ -1829,6 +1838,8 @@ struct qmi_device *qmi_device_new_qmux(const char *device)return NULL ; } + qmux->next_control_tid =1 ; +return &qmux->super; }
Signature · 1 line
2.43.0
PATCH 5/8 qmi: Split RX path into QMUX and generic parts
In reply to Denis Kenziorhandle_packet currently handles both CTL and generic service messages coming from the device. In all cases, QMUX framing is assumed. Split up this function into two, one for parsing and handling the CTL packets, and one for all other service messages.
As a result, the reader handler is renamed to received_qmux_data() and set into l_io inside qmi_device_new_qmux() constructor.
--- drivers/qmimodem/qmi.c | 211 +++++++++++++++++++++-------------------- 1 file changed, 110 insertions(+), 101 deletions(-)
drivers/qmimodem/qmi.c +110 -101
@@ -751,65 +751,30 @@ static void handle_indication(struct qmi_device *device,service_notify (NULL , service, &result); } -static void handle_packet (struct qmi_device *device, -const struct qmi_mux_hdr *hdr,const void *buf) +static void __rx_message (struct qmi_device *device, +uint8_t service_type,uint8_t client_id, +const void *buf) { +const struct qmi_service_hdr *service = buf; +const struct qmi_message_hdr *msg = buf +QMI_SERVICE_HDR_SIZE ; +const void *data = buf +QMI_SERVICE_HDR_SIZE +QMI_MESSAGE_HDR_SIZE ;struct qmi_request *req; -uint16_t message, length; -const void *data; - -if (hdr->service ==QMI_SERVICE_CONTROL ) { -const struct qmi_control_hdr *control = buf; -const struct qmi_message_hdr *msg; -unsigned int tid; - -/* Ignore control messages with client identifier */ -if (hdr->client !=0x00 ) -return ; - - msg = buf +QMI_CONTROL_HDR_SIZE ; - - message =L_LE16_TO_CPU (msg->message); - length =L_LE16_TO_CPU (msg->length); - - data = buf +QMI_CONTROL_HDR_SIZE +QMI_MESSAGE_HDR_SIZE ; - - tid = control->transaction; - -if (control->type ==0x02 && control->transaction ==0x00 ) { -handle_indication (device, hdr->service, hdr->client, - message, length, data); -return ; - } - - req =l_queue_remove_if (device->control_queue, - __request_compare, -L_UINT_TO_PTR (tid)); - }else { -const struct qmi_service_hdr *service = buf; -const struct qmi_message_hdr *msg; -unsigned int tid; - - msg = buf +QMI_SERVICE_HDR_SIZE ; - - message =L_LE16_TO_CPU (msg->message); - length =L_LE16_TO_CPU (msg->length); - - data = buf +QMI_SERVICE_HDR_SIZE +QMI_MESSAGE_HDR_SIZE ; +unsigned int tid; +uint16_t message; +uint16_t length; - tid =L_LE16_TO_CPU (service->transaction); + message =L_LE16_TO_CPU (msg->message); + length =L_LE16_TO_CPU (msg->length); + tid =L_LE16_TO_CPU (service->transaction); -if (service->type ==0x04 ) { -handle_indication (device, hdr->service, hdr->client, - message, length, data); -return ; - } - - req =l_queue_remove_if (device->service_queue, - __request_compare, -L_UINT_TO_PTR (tid)); +if (service->type ==0x04 ) { +handle_indication (device, service_type, client_id, + message, length, data); +return ; } + req =l_queue_remove_if (device->service_queue, __request_compare, +L_UINT_TO_PTR (tid));if (!req)return ;
@@ -819,53 +784,6 @@ static void handle_packet(struct qmi_device *device,__request_free (req); } -static bool received_data (struct l_io *io,void *user_data) -{ -struct qmi_device *device = user_data; -struct qmi_mux_hdr *hdr; -unsigned char buf[2048 ]; -ssize_t bytes_read; -uint16_t offset; - - bytes_read =read (l_io_get_fd (device->io), buf,sizeof (buf)); -if (bytes_read <0 ) -return true; - -l_util_hexdump (true, buf, bytes_read, - device->debug_func, device->debug_data); - - offset =0 ; - -while (offset < bytes_read) { -uint16_t len; - -/* Check if QMI mux header fits into packet */ -if (bytes_read - offset <QMI_MUX_HDR_SIZE ) -break ; - - hdr = (void *) (buf + offset); - -/* Check for fixed frame and flags value */ -if (hdr->frame !=0x01 || hdr->flags !=0x80 ) -break ; - - len =L_LE16_TO_CPU (hdr->length) +1 ; - -/* Check that packet size matches frame size */ -if (bytes_read - offset < len) -break ; - -__debug_msg (' ' , buf + offset, len, - device->debug_func, device->debug_data); - -handle_packet (device, hdr, buf + offset +QMI_MUX_HDR_SIZE ); - - offset += len; - } - -return true; -} -static void __qmi_device_discovery_started (struct qmi_device *device,struct discovery *d) {
@@ -911,7 +829,6 @@ static int qmi_device_init(struct qmi_device *device, int fd, device->io =l_io_new (fd);l_io_set_close_on_destroy (device->io, true); -l_io_set_read_handler (device->io, received_data, device,NULL ); device->req_queue =l_queue_new (); device->control_queue =l_queue_new ();
@@ -1285,6 +1202,97 @@ done:return res; } +static void __rx_ctl_message (struct qmi_device_qmux *qmux, +uint8_t service_type,uint8_t client_id, +const void *buf) +{ +const struct qmi_control_hdr *control = buf; +const struct qmi_message_hdr *msg = buf +QMI_CONTROL_HDR_SIZE ; +const void *data = buf +QMI_CONTROL_HDR_SIZE +QMI_MESSAGE_HDR_SIZE ; +struct qmi_request *req; +uint16_t message; +uint16_t length; +unsigned int tid; + +/* Ignore control messages with client identifier */ +if (client_id !=0x00 ) +return ; + + message =L_LE16_TO_CPU (msg->message); + length =L_LE16_TO_CPU (msg->length); + tid = control->transaction; + +if (control->type ==0x02 && control->transaction ==0x00 ) { +handle_indication (&qmux->super, service_type, client_id, + message, length, data); +return ; + } + + req =l_queue_remove_if (qmux->super.control_queue, __request_compare, +L_UINT_TO_PTR (tid)); +if (!req) +return ; + +if (req->callback) + req->callback (message, length, data, req->user_data); + +__request_free (req); +} + +static bool received_qmux_data (struct l_io *io,void *user_data) +{ +struct qmi_device_qmux *qmux = user_data; +struct qmi_mux_hdr *hdr; +unsigned char buf[2048 ]; +ssize_t bytes_read; +uint16_t offset; + + bytes_read =read (l_io_get_fd (qmux->super.io), buf,sizeof (buf)); +if (bytes_read <0 ) +return true; + +l_util_hexdump (true, buf, bytes_read, + qmux->super.debug_func, qmux->super.debug_data); + + offset =0 ; + +while (offset < bytes_read) { +uint16_t len; +const void *msg; + +/* Check if QMI mux header fits into packet */ +if (bytes_read - offset <QMI_MUX_HDR_SIZE ) +break ; + + hdr = (void *) (buf + offset); + +/* Check for fixed frame and flags value */ +if (hdr->frame !=0x01 || hdr->flags !=0x80 ) +break ; + + len =L_LE16_TO_CPU (hdr->length) +1 ; + +/* Check that packet size matches frame size */ +if (bytes_read - offset < len) +break ; + +__debug_msg (' ' , buf + offset, len, + qmux->super.debug_func, qmux->super.debug_data); + + msg = buf + offset +QMI_MUX_HDR_SIZE ; + +if (hdr->service ==QMI_SERVICE_CONTROL ) +__rx_ctl_message (qmux, hdr->service, hdr->client, msg); +else +__rx_message (&qmux->super, + hdr->service, hdr->client, msg); + + offset += len; + } + +return true; +} +struct service_create_shared_data {struct discovery super;struct qmi_service *service;
@@ -1839,6 +1847,7 @@ struct qmi_device *qmi_device_new_qmux(const char *device) } qmux->next_control_tid =1 ; +l_io_set_read_handler (qmux->super.io, received_qmux_data, qmux,NULL );return &qmux->super; }
Signature · 1 line
2.43.0
PATCH 6/8 qmi: Introduce write driver method
In reply to Denis KenziorIntroduce a new write driver method which will abstract away the details of submitting a QMI message to the underlying device / protocol. qmi_device will continue managing the request queue and setup the l_io write handler accordingly.
--- drivers/qmimodem/qmi.c | 68 ++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 26 deletions(-)
drivers/qmimodem/qmi.c +42 -26
@@ -48,6 +48,15 @@ struct discovery {qmi_destroy_func_t destroy; }; +struct qmi_request { +uint16_t tid; +uint8_t client; +qmi_message_func_t callback; +void *user_data; +uint16_t len; +uint8_t data[]; +}; +struct qmi_version {uint8_t type;uint16_t major;
@@ -56,6 +65,7 @@ struct qmi_version { };struct qmi_device_ops { +int (*write)(struct qmi_device *device,struct qmi_request *req);int (*discover)(struct qmi_device *device,qmi_discover_func_t discover_func,void *user,qmi_destroy_func_t destroy);
@@ -126,15 +136,6 @@ struct qmi_result {uint16_t length; }; -struct qmi_request { -uint16_t tid; -uint8_t client; -qmi_message_func_t callback; -void *user_data; -uint16_t len; -uint8_t data[]; -}; -struct qmi_notify {uint16_t id;uint16_t message;
@@ -626,30 +627,18 @@ static void __debug_device(struct qmi_device *device,static bool can_write_data (struct l_io *io,void *user_data) {struct qmi_device *device = user_data; -struct qmi_mux_hdr *hdr;struct qmi_request *req; -ssize_t bytes_written; +int r; req =l_queue_pop_head (device->req_queue);if (!req)return false; - bytes_written =write (l_io_get_fd (device->io), req->data, req->len); -if (bytes_written <0 ) + r = device->ops->write (device, req); +if (r <0 ) { +__request_free (req);return false; - -l_util_hexdump (false, req->data, bytes_written, - device->debug_func, device->debug_data); - -__debug_msg (' ' , req->data, bytes_written, - device->debug_func, device->debug_data); - - hdr = (struct qmi_mux_hdr *) req->data; - -if (hdr->service ==QMI_SERVICE_CONTROL ) -l_queue_push_tail (device->control_queue, req); -else -l_queue_push_tail (device->service_queue, req); + }if (l_queue_length (device->req_queue) >0 )return true;
@@ -1202,6 +1191,32 @@ done:return res; } +static int qmi_device_qmux_write (struct qmi_device *device, +struct qmi_request *req) +{ +struct qmi_mux_hdr *hdr; +ssize_t bytes_written; + + bytes_written =write (l_io_get_fd (device->io), req->data, req->len); +if (bytes_written <0 ) +return -errno; + +l_util_hexdump (false, req->data, bytes_written, + device->debug_func, device->debug_data); + +__debug_msg (' ' , req->data, bytes_written, + device->debug_func, device->debug_data); + + hdr = (struct qmi_mux_hdr *) req->data; + +if (hdr->service ==QMI_SERVICE_CONTROL ) +l_queue_push_tail (device->control_queue, req); +else +l_queue_push_tail (device->service_queue, req); + +return 0 ; +} +static void __rx_ctl_message (struct qmi_device_qmux *qmux,uint8_t service_type,uint8_t client_id,const void *buf)
@@ -1822,6 +1837,7 @@ static void qmi_device_qmux_destroy(struct qmi_device *device) }static const struct qmi_device_ops qmux_ops = { + .write = qmi_device_qmux_write, .discover = qmi_device_qmux_discover, .client_create = qmi_device_qmux_client_create, .client_release = qmi_device_qmux_client_release,
Signature · 1 line
2.43.0
PATCH 7/8 qmi: Move control_queue member to qmux subclass
In reply to Denis Kenziorcontrol_queue is only used by the QMUX transport. Move it out from the qmi_device structure into the QMUX specific qmi_device_qmux structure.
--- drivers/qmimodem/qmi.c | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-)
drivers/qmimodem/qmi.c +24 -18
@@ -84,7 +84,6 @@ struct qmi_device_ops {struct qmi_device {struct l_io *io;struct l_queue *req_queue; -struct l_queue *control_queue;struct l_queue *service_queue;struct l_queue *discovery_queue;uint16_t next_service_tid;
@@ -110,6 +109,7 @@ struct qmi_device_qmux {struct l_idle *shutdown_idle;unsigned int release_users;uint8_t next_control_tid; +struct l_queue *control_queue; };struct qmi_service {
@@ -820,7 +820,6 @@ static int qmi_device_init(struct qmi_device *device, int fd,l_io_set_close_on_destroy (device->io, true); device->req_queue =l_queue_new (); - device->control_queue =l_queue_new (); device->service_queue =l_queue_new (); device->discovery_queue =l_queue_new ();
@@ -846,7 +845,6 @@ void qmi_device_free(struct qmi_device *device)__debug_device (device,"device %p free" , device); -l_queue_destroy (device->control_queue, __request_free);l_queue_destroy (device->service_queue, __request_free);l_queue_destroy (device->req_queue, __request_free);l_queue_destroy (device->discovery_queue, __discovery_free);
@@ -1194,6 +1192,8 @@ done:static int qmi_device_qmux_write (struct qmi_device *device,struct qmi_request *req) { +struct qmi_device_qmux *qmux = + l_container_of(device, struct qmi_device_qmux, super);struct qmi_mux_hdr *hdr;ssize_t bytes_written;
@@ -1210,7 +1210,7 @@ static int qmi_device_qmux_write(struct qmi_device *device, hdr = (struct qmi_mux_hdr *) req->data;if (hdr->service ==QMI_SERVICE_CONTROL ) -l_queue_push_tail (device->control_queue, req); +l_queue_push_tail (qmux->control_queue, req);else l_queue_push_tail (device->service_queue, req);
@@ -1243,7 +1243,7 @@ static void __rx_ctl_message(struct qmi_device_qmux *qmux,return ; } - req =l_queue_remove_if (qmux->super.control_queue, __request_compare, + req =l_queue_remove_if (qmux->control_queue, __request_compare,L_UINT_TO_PTR (tid));if (!req)return ;
@@ -1383,22 +1383,21 @@ static void service_create_shared_data_free(void *user_data)l_free (data); } -static struct qmi_request *find_control_request (struct qmi_device *device, +static struct qmi_request *find_control_request (struct qmi_device_qmux *qmux,uint16_t tid) { -struct qmi_request *req =NULL ; -unsigned int _tid = tid; +struct qmi_request *req; -if (_tid !=0 ) { - req =l_queue_remove_if (device->req_queue, __request_compare, -L_UINT_TO_PTR (_tid)); +if (!tid) +return NULL ; -if (!req) - req =l_queue_remove_if (device->control_queue, - __request_compare, -L_UINT_TO_PTR (_tid)); - } + req =l_queue_remove_if (qmux->super.req_queue, + __request_compare,L_UINT_TO_PTR (tid)); +if (req) +return req; + req =l_queue_remove_if (qmux->control_queue, + __request_compare,L_UINT_TO_PTR (tid));return req; }
@@ -1522,13 +1521,15 @@ static void qmux_discover_reply_timeout(struct l_timeout *timeout, {struct discover_data *data = user_data;struct qmi_device *device = data->device; +struct qmi_device_qmux *qmux = + l_container_of(device, struct qmi_device_qmux, super);struct qmi_request *req;l_timeout_remove (data->timeout); data->timeout =NULL ;/* remove request from queues */ - req =find_control_request (device, data->tid); + req =find_control_request (qmux, data->tid);if (data->func) data->func (data->user_data);
@@ -1605,6 +1606,8 @@ static void qmux_client_create_reply(struct l_timeout *timeout, void *user_data) {struct qmux_client_create_data *data = user_data;struct qmi_device *device = data->device; +struct qmi_device_qmux *qmux = + l_container_of(device, struct qmi_device_qmux, super);struct qmi_request *req;DBG ("" );
@@ -1612,7 +1615,7 @@ static void qmux_client_create_reply(struct l_timeout *timeout, void *user_data)service_create_shared_pending_reply (device, data->type,NULL );/* remove request from queues */ - req =find_control_request (device, data->tid); + req =find_control_request (qmux, data->tid);l_timeout_remove (data->timeout); data->timeout =NULL ;
@@ -1829,6 +1832,8 @@ static void qmi_device_qmux_destroy(struct qmi_device *device)struct qmi_device_qmux *qmux = l_container_of(device, struct qmi_device_qmux, super); +l_queue_destroy (qmux->control_queue, __request_free); +if (qmux->shutdown_idle)l_idle_remove (qmux->shutdown_idle);
@@ -1863,6 +1868,7 @@ struct qmi_device *qmi_device_new_qmux(const char *device) } qmux->next_control_tid =1 ; + qmux->control_queue =l_queue_new ();l_io_set_read_handler (qmux->super.io, received_qmux_data, qmux,NULL );return &qmux->super;
Signature · 1 line
2.43.0
PATCH 8/8 qmi: Make sure to set transaction id as LE16
In reply to Denis KenziorTransaction identifier for QMI service messages was always read in as LE16 value, however when allocating a request it was set in host byte order. Fix that.
--- drivers/qmimodem/qmi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/qmimodem/qmi.c +3 -3
@@ -670,13 +670,13 @@ static uint16_t __request_submit(struct qmi_device *device,struct qmi_service_hdr *hdr = (struct qmi_service_hdr *) &req->data[QMI_MUX_HDR_SIZE ]; - hdr->type =0x00 ; - hdr->transaction = device->next_service_tid++; + req->tid = device->next_service_tid++;if (device->next_service_tid <256 ) device->next_service_tid =256 ; - req->tid = hdr->transaction; + hdr->type =0x00 ; + hdr->transaction =L_CPU_TO_LE16 (req->tid);l_queue_push_tail (device->req_queue, req);wakeup_writer (device);
Signature · 1 line
2.43.0
This series was applied to ofono.git (master) by Denis Kenzior <[email protected]>:
Hello:
This series was applied to ofono.git (master)
by Denis Kenzior <[email protected]>:
Quoted 8 lines · On Mon, 26 Feb 2024 09:34:20 -0600 you wrote:
Instead of allocating a separate buffer inside the request object, use a flexible array member (FAM). This allows the request metadata and data to be allocated within the same memory region. The only downside is that the data buffer is not released once the request has been sent over the socket. Since most requests are quite small, this shouldn't affect performance.
[...]
Here is the summary with links:
- [1/8] qmi: Use FAM instead of allocating a member
https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=e2a311461036 - [2/8] qmi: Ensure tid is initialized https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=1a801dfb93db - [3/8] qmi: Move and rename QMUX sync logic https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=051150db7f67 - [4/8] qmi: Introduce __ctl_request_submit https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=84f9d568a394 - [5/8] qmi: Split RX path into QMUX and generic parts https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=8a09d514f60d - [6/8] qmi: Introduce write driver method https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=a9ebacb42317 - [7/8] qmi: Move control_queue member to qmux subclass https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=d3f4c6cb3959 - [8/8] qmi: Make sure to set transaction id as LE16 https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=df0c32bda186
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html