Skip to content

Commit 929680a

Browse files
committed
[ctl] ICCom control channel handler
* Added an ICCom control channel handler. It it is intended to be used in ICCom instances direct communication (like protocol negotiations, for example). So messages sent via control channel are consumed by ICCom directly.
1 parent 3547123 commit 929680a

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

include/linux/iccom.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828

2929
// the channel value which is interpreted as (any/all) channel(s)
3030
#define ICCOM_ANY_CHANNEL_VALUE -1
31+
// This channel is used to control the ICCom internal flows,
32+
// like embedded acks, protocol advancement negotiations, etc.
33+
//
34+
// This channel is not to be exposed outside the ICCom, so pls don't
35+
// try to use it for any other communication.
36+
#define ICCOM_CTL_CHANNEL 0
3137

3238

3339
// number of error types to be tracked

src/iccom.c

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4328,6 +4328,20 @@ static inline void __iccom_statistics_init(struct iccom_dev *iccom)
43284328
atomic_long_set(&iccom->p->statistics.messages_ready_in_storage, 0);
43294329
}
43304330

4331+
// Handles the iccom ctl channel messages. Those messages
4332+
// include protocol negotiations messages, embedded
4333+
// ack messages, etc..
4334+
//
4335+
// @channel must always be ICCOM_CTL_CHANNEL.
4336+
// @consumer_data points to iccom_dev.
4337+
static bool __iccom_ctl_msg_handler(unsigned int channel
4338+
, void *msg_data, size_t msg_len
4339+
, void *consumer_data)
4340+
{
4341+
// here the ctl handling logic shall be
4342+
return false;
4343+
}
4344+
43314345
/* -------------------------- KERNEL SPACE API --------------------------*/
43324346

43334347
// API
@@ -4457,6 +4471,9 @@ int iccom_flush(struct iccom_dev *iccom)
44574471
// as global callback for all channels.
44584472
// NOTE: global callback is used only when specific channel
44594473
// callback is not set.
4474+
// NOTE: the ICCOM_CTL_CHANNEL is reserved for the internal
4475+
// ICCom communications, it will not be possible to use it
4476+
// from outside of the ICCom.
44604477
// @message_ready_callback {valid ptr || NULL} the pointer to the
44614478
// callback which is to be called when channel gets a message
44624479
// ready. NULL value disables the callback function on the channel.
@@ -4488,6 +4505,12 @@ int iccom_set_channel_callback(struct iccom_dev *iccom
44884505
iccom_err("broken callback pointer provided");
44894506
return -EINVAL;
44904507
}
4508+
if (channel == ICCOM_CTL_CHANNEL) {
4509+
iccom_err("channel %d is reserved for iccom internal ctl messages"
4510+
" so, can not assign a custom callback to it"
4511+
, ICCOM_CTL_CHANNEL);
4512+
return -EINVAL;
4513+
}
44914514

44924515
return iccom_msg_storage_set_channel_callback(
44934516
&iccom->p->rx_messages, channel
@@ -4519,6 +4542,12 @@ int iccom_remove_channel_callback(struct iccom_dev *iccom
45194542
ICCOM_CHECK_XFER_DEVICE("broken xfer device", return -ENODEV);
45204543
ICCOM_CHECK_CHANNEL("bad channel", return -EBADSLT);
45214544
ICCOM_CHECK_CLOSING("will not invoke", return -EBADFD);
4545+
if (channel == ICCOM_CTL_CHANNEL) {
4546+
iccom_err("channel %d is reserved for iccom internal ctl messages"
4547+
" so, can not remove it's callback"
4548+
, ICCOM_CTL_CHANNEL);
4549+
return -EINVAL;
4550+
}
45224551
return iccom_msg_storage_reset_channel_callback(
45234552
&iccom->p->rx_messages, channel);
45244553
}
@@ -4832,10 +4861,17 @@ int iccom_init(struct iccom_dev *iccom, struct platform_device *pdev)
48324861
goto free_private;
48334862
}
48344863

4864+
if (iccom_msg_storage_set_channel_callback(
4865+
&iccom->p->rx_messages, ICCOM_CTL_CHANNEL
4866+
, __iccom_ctl_msg_handler , iccom) < 0) {
4867+
iccom_err("Could not register ctl channel clbk.");
4868+
goto free_msg_storage;
4869+
}
4870+
48354871
res = __iccom_init_packages_storage(iccom);
48364872
if (res < 0) {
48374873
iccom_err("Could not initialize packages storage.");
4838-
goto free_msg_storage;
4874+
goto unregister_ctl_msgs_handler;
48394875
}
48404876

48414877
iccom->p->last_rx_package_id = ICCOM_PACKAGE_HAVE_NOT_RECEIVED_ID;
@@ -4884,6 +4920,9 @@ int iccom_init(struct iccom_dev *iccom, struct platform_device *pdev)
48844920
mutex_destroy(&iccom->p->sysfs_test_ch_lock);
48854921
free_pkg_storage:
48864922
__iccom_free_packages_storage(iccom);
4923+
unregister_ctl_msgs_handler:
4924+
iccom_msg_storage_reset_channel_callback(
4925+
&iccom->p->rx_messages, ICCOM_CTL_CHANNEL);
48874926
free_msg_storage:
48884927
iccom_msg_storage_free(&iccom->p->rx_messages);
48894928
free_private:

0 commit comments

Comments
 (0)