Lines Matching full:block
41 struct w1_cb_block *block; member
49 * @block: block to calculate
55 static u16 w1_reply_len(struct w1_cb_block *block) in w1_reply_len() argument
57 if (!block->cn) in w1_reply_len()
59 return (u8 *)block->cn - (u8 *)block->first_cn + block->cn->len; in w1_reply_len()
62 static void w1_unref_block(struct w1_cb_block *block) in w1_unref_block() argument
64 if (atomic_sub_return(1, &block->refcnt) == 0) { in w1_unref_block()
65 u16 len = w1_reply_len(block); in w1_unref_block()
67 cn_netlink_send_mult(block->first_cn, len, in w1_unref_block()
68 block->portid, 0, GFP_KERNEL); in w1_unref_block()
70 kfree(block); in w1_unref_block()
76 * @block: block to make space on
82 static void w1_reply_make_space(struct w1_cb_block *block, u16 space) in w1_reply_make_space() argument
84 u16 len = w1_reply_len(block); in w1_reply_make_space()
85 if (len + space >= block->maxlen) { in w1_reply_make_space()
86 cn_netlink_send_mult(block->first_cn, len, block->portid, 0, GFP_KERNEL); in w1_reply_make_space()
87 block->first_cn->len = 0; in w1_reply_make_space()
88 block->cn = NULL; in w1_reply_make_space()
89 block->msg = NULL; in w1_reply_make_space()
90 block->cmd = NULL; in w1_reply_make_space()
95 static void w1_netlink_check_send(struct w1_cb_block *block) in w1_netlink_check_send() argument
97 if (!(block->request_cn.flags & W1_CN_BUNDLE) && block->cn) in w1_netlink_check_send()
98 w1_reply_make_space(block, block->maxlen); in w1_netlink_check_send()
102 * w1_netlink_setup_msg() - prepare to write block->msg
103 * @block: block to operate on
106 * block->cn will be setup with the correct ack, advancing if needed
107 * block->cn->len does not include space for block->msg
108 * block->msg advances but remains uninitialized
110 static void w1_netlink_setup_msg(struct w1_cb_block *block, u32 ack) in w1_netlink_setup_msg() argument
112 if (block->cn && block->cn->ack == ack) { in w1_netlink_setup_msg()
113 block->msg = (struct w1_netlink_msg *)(block->cn->data + block->cn->len); in w1_netlink_setup_msg()
116 if (block->cn) in w1_netlink_setup_msg()
117 block->cn = (struct cn_msg *)(block->cn->data + in w1_netlink_setup_msg()
118 block->cn->len); in w1_netlink_setup_msg()
120 block->cn = block->first_cn; in w1_netlink_setup_msg()
122 memcpy(block->cn, &block->request_cn, sizeof(*block->cn)); in w1_netlink_setup_msg()
123 block->cn->len = 0; in w1_netlink_setup_msg()
124 block->cn->ack = ack; in w1_netlink_setup_msg()
125 block->msg = (struct w1_netlink_msg *)block->cn->data; in w1_netlink_setup_msg()
133 static void w1_netlink_queue_cmd(struct w1_cb_block *block, in w1_netlink_queue_cmd() argument
137 w1_reply_make_space(block, sizeof(struct cn_msg) + in w1_netlink_queue_cmd()
144 w1_netlink_setup_msg(block, block->request_cn.seq + 1); in w1_netlink_queue_cmd()
145 memcpy(block->msg, block->cur_msg, sizeof(*block->msg)); in w1_netlink_queue_cmd()
146 block->cn->len += sizeof(*block->msg); in w1_netlink_queue_cmd()
147 block->msg->len = 0; in w1_netlink_queue_cmd()
148 block->cmd = (struct w1_netlink_cmd *)(block->msg->data); in w1_netlink_queue_cmd()
151 if (block->cmd != cmd) in w1_netlink_queue_cmd()
152 memcpy(block->cmd, cmd, space); in w1_netlink_queue_cmd()
153 block->cn->len += space; in w1_netlink_queue_cmd()
154 block->msg->len += space; in w1_netlink_queue_cmd()
160 static void w1_netlink_queue_status(struct w1_cb_block *block, in w1_netlink_queue_status() argument
165 w1_reply_make_space(block, space); in w1_netlink_queue_status()
166 w1_netlink_setup_msg(block, block->request_cn.ack); in w1_netlink_queue_status()
168 memcpy(block->msg, req_msg, sizeof(*req_msg)); in w1_netlink_queue_status()
169 block->cn->len += sizeof(*req_msg); in w1_netlink_queue_status()
170 block->msg->len = 0; in w1_netlink_queue_status()
171 block->msg->status = (u8)-error; in w1_netlink_queue_status()
173 struct w1_netlink_cmd *cmd = (struct w1_netlink_cmd *)block->msg->data; in w1_netlink_queue_status()
175 block->cn->len += sizeof(*cmd); in w1_netlink_queue_status()
176 block->msg->len += sizeof(*cmd); in w1_netlink_queue_status()
179 w1_netlink_check_send(block); in w1_netlink_queue_status()
189 * Use when a block isn't available to queue the message to and cn, msg
236 struct w1_cb_block *block = dev->priv; in w1_send_slave() local
237 struct w1_netlink_cmd *cache_cmd = block->cmd; in w1_send_slave()
240 w1_reply_make_space(block, sizeof(*data)); in w1_send_slave()
243 if (!block->cmd) { in w1_send_slave()
245 w1_netlink_queue_cmd(block, cache_cmd); in w1_send_slave()
248 data = (u64 *)(block->cmd->data + block->cmd->len); in w1_send_slave()
251 block->cn->len += sizeof(*data); in w1_send_slave()
252 block->msg->len += sizeof(*data); in w1_send_slave()
253 block->cmd->len += sizeof(*data); in w1_send_slave()
453 dev->priv = node->block; in w1_process_cb()
456 node->block->cur_msg = node->msg; in w1_process_cb()
468 w1_netlink_check_send(node->block); in w1_process_cb()
470 w1_netlink_queue_status(node->block, node->msg, cmd, err); in w1_process_cb()
479 w1_netlink_queue_status(node->block, node->msg, cmd, err); in w1_process_cb()
482 * the block in w1_process_cb()
495 w1_unref_block(node->block); in w1_process_cb()
543 struct w1_cb_block *block = NULL; in w1_cn_callback() local
591 /* allocate space for the block, a copy of the original message, in w1_cn_callback()
595 * cn->len doesn't include itself which is part of the block in w1_cn_callback()
597 size = /* block + original message */ in w1_cn_callback()
603 block = kzalloc(size, GFP_KERNEL); in w1_cn_callback()
604 if (!block) { in w1_cn_callback()
612 atomic_set(&block->refcnt, 1); in w1_cn_callback()
613 block->portid = nsp->portid; in w1_cn_callback()
614 memcpy(&block->request_cn, cn, sizeof(*cn) + cn->len); in w1_cn_callback()
615 node = (struct w1_cb_node *)(block->request_cn.data + cn->len); in w1_cn_callback()
626 block->maxlen = reply_size; in w1_cn_callback()
627 block->first_cn = (struct cn_msg *)(node + node_count); in w1_cn_callback()
628 memset(block->first_cn, 0, sizeof(*block->first_cn)); in w1_cn_callback()
678 atomic_inc(&block->refcnt); in w1_cn_callback()
680 node->block = block; in w1_cn_callback()
681 node->msg = (struct w1_netlink_msg *)((u8 *)&block->request_cn + in w1_cn_callback()
693 /* Can't queue because that modifies block and another in w1_cn_callback()
709 if (block) in w1_cn_callback()
710 w1_unref_block(block); in w1_cn_callback()