Lines Matching refs:pkg
174 tb_cfg_request_find(struct tb_ctl *ctl, struct ctl_pkg *pkg) in tb_cfg_request_find() argument
178 mutex_lock(&pkg->ctl->request_queue_lock); in tb_cfg_request_find()
179 list_for_each_entry(iter, &pkg->ctl->request_queue, list) { in tb_cfg_request_find()
181 if (iter->match(iter, pkg)) { in tb_cfg_request_find()
187 mutex_unlock(&pkg->ctl->request_queue_lock); in tb_cfg_request_find()
195 static int check_header(const struct ctl_pkg *pkg, u32 len, in check_header() argument
198 struct tb_cfg_header *header = pkg->buffer; in check_header()
201 if (WARN(len != pkg->frame.size, in check_header()
203 len, pkg->frame.size)) in check_header()
205 if (WARN(type != pkg->frame.eof, "wrong eof (expected %#x, got %#x)\n", in check_header()
206 type, pkg->frame.eof)) in check_header()
208 if (WARN(pkg->frame.sof, "wrong sof (expected 0x0, got %#x)\n", in check_header()
209 pkg->frame.sof)) in check_header()
247 struct cfg_error_pkg *pkg = response->buffer; in decode_error() local
249 res.response_route = tb_cfg_get_route(&pkg->header); in decode_error()
251 res.err = check_header(response, sizeof(*pkg), TB_CFG_PKG_ERROR, in decode_error()
252 tb_cfg_get_route(&pkg->header)); in decode_error()
257 res.tb_error = pkg->error; in decode_error()
258 res.response_port = pkg->port; in decode_error()
263 static struct tb_cfg_result parse_header(const struct ctl_pkg *pkg, u32 len, in parse_header() argument
266 struct tb_cfg_header *header = pkg->buffer; in parse_header()
269 if (pkg->frame.eof == TB_CFG_PKG_ERROR) in parse_header()
270 return decode_error(pkg); in parse_header()
274 res.err = check_header(pkg, len, type, route); in parse_header()
325 static void tb_ctl_pkg_free(struct ctl_pkg *pkg) in tb_ctl_pkg_free() argument
327 if (pkg) { in tb_ctl_pkg_free()
328 dma_pool_free(pkg->ctl->frame_pool, in tb_ctl_pkg_free()
329 pkg->buffer, pkg->frame.buffer_phy); in tb_ctl_pkg_free()
330 kfree(pkg); in tb_ctl_pkg_free()
336 struct ctl_pkg *pkg = kzalloc_obj(*pkg); in tb_ctl_pkg_alloc() local
337 if (!pkg) in tb_ctl_pkg_alloc()
339 pkg->ctl = ctl; in tb_ctl_pkg_alloc()
340 pkg->buffer = dma_pool_alloc(ctl->frame_pool, GFP_KERNEL, in tb_ctl_pkg_alloc()
341 &pkg->frame.buffer_phy); in tb_ctl_pkg_alloc()
342 if (!pkg->buffer) { in tb_ctl_pkg_alloc()
343 kfree(pkg); in tb_ctl_pkg_alloc()
346 return pkg; in tb_ctl_pkg_alloc()
355 struct ctl_pkg *pkg = container_of(frame, typeof(*pkg), frame); in tb_ctl_tx_callback() local
356 tb_ctl_pkg_free(pkg); in tb_ctl_tx_callback()
370 struct ctl_pkg *pkg; in tb_ctl_tx() local
380 pkg = tb_ctl_pkg_alloc(ctl); in tb_ctl_tx()
381 if (!pkg) in tb_ctl_tx()
383 pkg->frame.callback = tb_ctl_tx_callback; in tb_ctl_tx()
384 pkg->frame.size = len + 4; in tb_ctl_tx()
385 pkg->frame.sof = type; in tb_ctl_tx()
386 pkg->frame.eof = type; in tb_ctl_tx()
390 cpu_to_be32_array(pkg->buffer, data, len / 4); in tb_ctl_tx()
391 *(__be32 *) (pkg->buffer + len) = tb_crc(pkg->buffer, len); in tb_ctl_tx()
393 res = tb_ring_tx(ctl->tx, &pkg->frame); in tb_ctl_tx()
395 tb_ctl_pkg_free(pkg); in tb_ctl_tx()
403 struct ctl_pkg *pkg, size_t size) in tb_ctl_handle_event() argument
405 trace_tb_event(ctl->index, type, pkg->buffer, size); in tb_ctl_handle_event()
406 return ctl->callback(ctl->callback_data, type, pkg->buffer, size); in tb_ctl_handle_event()
409 static void tb_ctl_rx_submit(struct ctl_pkg *pkg) in tb_ctl_rx_submit() argument
411 tb_ring_rx(pkg->ctl->rx, &pkg->frame); /* in tb_ctl_rx_submit()
419 static int tb_async_error(const struct ctl_pkg *pkg) in tb_async_error() argument
421 const struct cfg_error_pkg *error = pkg->buffer; in tb_async_error()
423 if (pkg->frame.eof != TB_CFG_PKG_ERROR) in tb_async_error()
448 struct ctl_pkg *pkg = container_of(frame, typeof(*pkg), frame); in tb_ctl_rx_callback() local
459 tb_ctl_err(pkg->ctl, "RX: invalid size %#x, dropping packet\n", in tb_ctl_rx_callback()
465 crc32 = tb_crc(pkg->buffer, frame->size); in tb_ctl_rx_callback()
466 be32_to_cpu_array(pkg->buffer, pkg->buffer, frame->size / 4); in tb_ctl_rx_callback()
474 if (*(__be32 *)(pkg->buffer + frame->size) != crc32) { in tb_ctl_rx_callback()
475 tb_ctl_err(pkg->ctl, in tb_ctl_rx_callback()
479 if (tb_async_error(pkg)) { in tb_ctl_rx_callback()
480 tb_ctl_handle_event(pkg->ctl, frame->eof, in tb_ctl_rx_callback()
481 pkg, frame->size); in tb_ctl_rx_callback()
489 if (*(__be32 *)(pkg->buffer + frame->size) != crc32) { in tb_ctl_rx_callback()
490 tb_ctl_err(pkg->ctl, in tb_ctl_rx_callback()
496 if (tb_ctl_handle_event(pkg->ctl, frame->eof, pkg, frame->size)) in tb_ctl_rx_callback()
510 req = tb_cfg_request_find(pkg->ctl, pkg); in tb_ctl_rx_callback()
512 trace_tb_rx(pkg->ctl->index, frame->eof, pkg->buffer, frame->size, !req); in tb_ctl_rx_callback()
515 if (req->copy(req, pkg)) in tb_ctl_rx_callback()
521 tb_ctl_rx_submit(pkg); in tb_ctl_rx_callback()
781 struct cfg_ack_pkg pkg = { in tb_cfg_ack_notification() local
828 return tb_ctl_tx(ctl, &pkg, sizeof(pkg), TB_CFG_PKG_NOTIFY_ACK); in tb_cfg_ack_notification()
844 struct cfg_error_pkg pkg = { in tb_cfg_ack_plug() local
853 return tb_ctl_tx(ctl, &pkg, sizeof(pkg), TB_CFG_PKG_ERROR); in tb_cfg_ack_plug()
857 const struct ctl_pkg *pkg) in tb_cfg_match() argument
859 u64 route = tb_cfg_get_route(pkg->buffer) & ~BIT_ULL(63); in tb_cfg_match()
861 if (pkg->frame.eof == TB_CFG_PKG_ERROR) in tb_cfg_match()
864 if (pkg->frame.eof != req->response_type) in tb_cfg_match()
868 if (pkg->frame.size != req->response_size) in tb_cfg_match()
871 if (pkg->frame.eof == TB_CFG_PKG_READ || in tb_cfg_match()
872 pkg->frame.eof == TB_CFG_PKG_WRITE) { in tb_cfg_match()
874 const struct cfg_read_pkg *res_hdr = pkg->buffer; in tb_cfg_match()
883 static bool tb_cfg_copy(struct tb_cfg_request *req, const struct ctl_pkg *pkg) in tb_cfg_copy() argument
888 res = parse_header(pkg, req->response_size, req->response_type, in tb_cfg_copy()
891 memcpy(req->response, pkg->buffer, req->response_size); in tb_cfg_copy()