Lines Matching refs:pkg
172 tb_cfg_request_find(struct tb_ctl *ctl, struct ctl_pkg *pkg) in tb_cfg_request_find() argument
176 mutex_lock(&pkg->ctl->request_queue_lock); in tb_cfg_request_find()
177 list_for_each_entry(iter, &pkg->ctl->request_queue, list) { in tb_cfg_request_find()
179 if (iter->match(iter, pkg)) { in tb_cfg_request_find()
185 mutex_unlock(&pkg->ctl->request_queue_lock); in tb_cfg_request_find()
193 static int check_header(const struct ctl_pkg *pkg, u32 len, in check_header() argument
196 struct tb_cfg_header *header = pkg->buffer; in check_header()
199 if (WARN(len != pkg->frame.size, in check_header()
201 len, pkg->frame.size)) in check_header()
203 if (WARN(type != pkg->frame.eof, "wrong eof (expected %#x, got %#x)\n", in check_header()
204 type, pkg->frame.eof)) in check_header()
206 if (WARN(pkg->frame.sof, "wrong sof (expected 0x0, got %#x)\n", in check_header()
207 pkg->frame.sof)) in check_header()
245 struct cfg_error_pkg *pkg = response->buffer; in decode_error() local
247 res.response_route = tb_cfg_get_route(&pkg->header); in decode_error()
249 res.err = check_header(response, sizeof(*pkg), TB_CFG_PKG_ERROR, in decode_error()
250 tb_cfg_get_route(&pkg->header)); in decode_error()
255 res.tb_error = pkg->error; in decode_error()
256 res.response_port = pkg->port; in decode_error()
261 static struct tb_cfg_result parse_header(const struct ctl_pkg *pkg, u32 len, in parse_header() argument
264 struct tb_cfg_header *header = pkg->buffer; in parse_header()
267 if (pkg->frame.eof == TB_CFG_PKG_ERROR) in parse_header()
268 return decode_error(pkg); in parse_header()
272 res.err = check_header(pkg, len, type, route); in parse_header()
323 static void tb_ctl_pkg_free(struct ctl_pkg *pkg) in tb_ctl_pkg_free() argument
325 if (pkg) { in tb_ctl_pkg_free()
326 dma_pool_free(pkg->ctl->frame_pool, in tb_ctl_pkg_free()
327 pkg->buffer, pkg->frame.buffer_phy); in tb_ctl_pkg_free()
328 kfree(pkg); in tb_ctl_pkg_free()
334 struct ctl_pkg *pkg = kzalloc(sizeof(*pkg), GFP_KERNEL); in tb_ctl_pkg_alloc() local
335 if (!pkg) in tb_ctl_pkg_alloc()
337 pkg->ctl = ctl; in tb_ctl_pkg_alloc()
338 pkg->buffer = dma_pool_alloc(ctl->frame_pool, GFP_KERNEL, in tb_ctl_pkg_alloc()
339 &pkg->frame.buffer_phy); in tb_ctl_pkg_alloc()
340 if (!pkg->buffer) { in tb_ctl_pkg_alloc()
341 kfree(pkg); in tb_ctl_pkg_alloc()
344 return pkg; in tb_ctl_pkg_alloc()
353 struct ctl_pkg *pkg = container_of(frame, typeof(*pkg), frame); in tb_ctl_tx_callback() local
354 tb_ctl_pkg_free(pkg); in tb_ctl_tx_callback()
368 struct ctl_pkg *pkg; in tb_ctl_tx() local
378 pkg = tb_ctl_pkg_alloc(ctl); in tb_ctl_tx()
379 if (!pkg) in tb_ctl_tx()
381 pkg->frame.callback = tb_ctl_tx_callback; in tb_ctl_tx()
382 pkg->frame.size = len + 4; in tb_ctl_tx()
383 pkg->frame.sof = type; in tb_ctl_tx()
384 pkg->frame.eof = type; in tb_ctl_tx()
388 cpu_to_be32_array(pkg->buffer, data, len / 4); in tb_ctl_tx()
389 *(__be32 *) (pkg->buffer + len) = tb_crc(pkg->buffer, len); in tb_ctl_tx()
391 res = tb_ring_tx(ctl->tx, &pkg->frame); in tb_ctl_tx()
393 tb_ctl_pkg_free(pkg); in tb_ctl_tx()
401 struct ctl_pkg *pkg, size_t size) in tb_ctl_handle_event() argument
403 trace_tb_event(ctl->index, type, pkg->buffer, size); in tb_ctl_handle_event()
404 return ctl->callback(ctl->callback_data, type, pkg->buffer, size); in tb_ctl_handle_event()
407 static void tb_ctl_rx_submit(struct ctl_pkg *pkg) in tb_ctl_rx_submit() argument
409 tb_ring_rx(pkg->ctl->rx, &pkg->frame); /* in tb_ctl_rx_submit()
417 static int tb_async_error(const struct ctl_pkg *pkg) in tb_async_error() argument
419 const struct cfg_error_pkg *error = pkg->buffer; in tb_async_error()
421 if (pkg->frame.eof != TB_CFG_PKG_ERROR) in tb_async_error()
446 struct ctl_pkg *pkg = container_of(frame, typeof(*pkg), frame); in tb_ctl_rx_callback() local
457 tb_ctl_err(pkg->ctl, "RX: invalid size %#x, dropping packet\n", in tb_ctl_rx_callback()
463 crc32 = tb_crc(pkg->buffer, frame->size); in tb_ctl_rx_callback()
464 be32_to_cpu_array(pkg->buffer, pkg->buffer, frame->size / 4); in tb_ctl_rx_callback()
472 if (*(__be32 *)(pkg->buffer + frame->size) != crc32) { in tb_ctl_rx_callback()
473 tb_ctl_err(pkg->ctl, in tb_ctl_rx_callback()
477 if (tb_async_error(pkg)) { in tb_ctl_rx_callback()
478 tb_ctl_handle_event(pkg->ctl, frame->eof, in tb_ctl_rx_callback()
479 pkg, frame->size); in tb_ctl_rx_callback()
487 if (*(__be32 *)(pkg->buffer + frame->size) != crc32) { in tb_ctl_rx_callback()
488 tb_ctl_err(pkg->ctl, in tb_ctl_rx_callback()
494 if (tb_ctl_handle_event(pkg->ctl, frame->eof, pkg, frame->size)) in tb_ctl_rx_callback()
508 req = tb_cfg_request_find(pkg->ctl, pkg); in tb_ctl_rx_callback()
510 trace_tb_rx(pkg->ctl->index, frame->eof, pkg->buffer, frame->size, !req); in tb_ctl_rx_callback()
513 if (req->copy(req, pkg)) in tb_ctl_rx_callback()
519 tb_ctl_rx_submit(pkg); in tb_ctl_rx_callback()
773 struct cfg_ack_pkg pkg = { in tb_cfg_ack_notification() local
820 return tb_ctl_tx(ctl, &pkg, sizeof(pkg), TB_CFG_PKG_NOTIFY_ACK); in tb_cfg_ack_notification()
835 struct cfg_error_pkg pkg = { in tb_cfg_ack_plug() local
844 return tb_ctl_tx(ctl, &pkg, sizeof(pkg), TB_CFG_PKG_ERROR); in tb_cfg_ack_plug()
848 const struct ctl_pkg *pkg) in tb_cfg_match() argument
850 u64 route = tb_cfg_get_route(pkg->buffer) & ~BIT_ULL(63); in tb_cfg_match()
852 if (pkg->frame.eof == TB_CFG_PKG_ERROR) in tb_cfg_match()
855 if (pkg->frame.eof != req->response_type) in tb_cfg_match()
859 if (pkg->frame.size != req->response_size) in tb_cfg_match()
862 if (pkg->frame.eof == TB_CFG_PKG_READ || in tb_cfg_match()
863 pkg->frame.eof == TB_CFG_PKG_WRITE) { in tb_cfg_match()
865 const struct cfg_read_pkg *res_hdr = pkg->buffer; in tb_cfg_match()
874 static bool tb_cfg_copy(struct tb_cfg_request *req, const struct ctl_pkg *pkg) in tb_cfg_copy() argument
879 res = parse_header(pkg, req->response_size, req->response_type, in tb_cfg_copy()
882 memcpy(req->response, pkg->buffer, req->response_size); in tb_cfg_copy()