Lines Matching refs:pkg

159 tb_cfg_request_find(struct tb_ctl *ctl, struct ctl_pkg *pkg)  in tb_cfg_request_find()  argument
163 mutex_lock(&pkg->ctl->request_queue_lock); in tb_cfg_request_find()
164 list_for_each_entry(iter, &pkg->ctl->request_queue, list) { in tb_cfg_request_find()
166 if (iter->match(iter, pkg)) { in tb_cfg_request_find()
172 mutex_unlock(&pkg->ctl->request_queue_lock); in tb_cfg_request_find()
180 static int check_header(const struct ctl_pkg *pkg, u32 len, in check_header() argument
183 struct tb_cfg_header *header = pkg->buffer; in check_header()
186 if (WARN(len != pkg->frame.size, in check_header()
188 len, pkg->frame.size)) in check_header()
190 if (WARN(type != pkg->frame.eof, "wrong eof (expected %#x, got %#x)\n", in check_header()
191 type, pkg->frame.eof)) in check_header()
193 if (WARN(pkg->frame.sof, "wrong sof (expected 0x0, got %#x)\n", in check_header()
194 pkg->frame.sof)) in check_header()
232 struct cfg_error_pkg *pkg = response->buffer; in decode_error() local
234 res.response_route = tb_cfg_get_route(&pkg->header); in decode_error()
236 res.err = check_header(response, sizeof(*pkg), TB_CFG_PKG_ERROR, in decode_error()
237 tb_cfg_get_route(&pkg->header)); in decode_error()
242 res.tb_error = pkg->error; in decode_error()
243 res.response_port = pkg->port; in decode_error()
248 static struct tb_cfg_result parse_header(const struct ctl_pkg *pkg, u32 len, in parse_header() argument
251 struct tb_cfg_header *header = pkg->buffer; in parse_header()
254 if (pkg->frame.eof == TB_CFG_PKG_ERROR) in parse_header()
255 return decode_error(pkg); in parse_header()
259 res.err = check_header(pkg, len, type, route); in parse_header()
310 static void tb_ctl_pkg_free(struct ctl_pkg *pkg) in tb_ctl_pkg_free() argument
312 if (pkg) { in tb_ctl_pkg_free()
313 dma_pool_free(pkg->ctl->frame_pool, in tb_ctl_pkg_free()
314 pkg->buffer, pkg->frame.buffer_phy); in tb_ctl_pkg_free()
315 kfree(pkg); in tb_ctl_pkg_free()
321 struct ctl_pkg *pkg = kzalloc(sizeof(*pkg), GFP_KERNEL); in tb_ctl_pkg_alloc() local
322 if (!pkg) in tb_ctl_pkg_alloc()
324 pkg->ctl = ctl; in tb_ctl_pkg_alloc()
325 pkg->buffer = dma_pool_alloc(ctl->frame_pool, GFP_KERNEL, in tb_ctl_pkg_alloc()
326 &pkg->frame.buffer_phy); in tb_ctl_pkg_alloc()
327 if (!pkg->buffer) { in tb_ctl_pkg_alloc()
328 kfree(pkg); in tb_ctl_pkg_alloc()
331 return pkg; in tb_ctl_pkg_alloc()
340 struct ctl_pkg *pkg = container_of(frame, typeof(*pkg), frame); in tb_ctl_tx_callback() local
341 tb_ctl_pkg_free(pkg); in tb_ctl_tx_callback()
355 struct ctl_pkg *pkg; in tb_ctl_tx() local
365 pkg = tb_ctl_pkg_alloc(ctl); in tb_ctl_tx()
366 if (!pkg) in tb_ctl_tx()
368 pkg->frame.callback = tb_ctl_tx_callback; in tb_ctl_tx()
369 pkg->frame.size = len + 4; in tb_ctl_tx()
370 pkg->frame.sof = type; in tb_ctl_tx()
371 pkg->frame.eof = type; in tb_ctl_tx()
372 cpu_to_be32_array(pkg->buffer, data, len / 4); in tb_ctl_tx()
373 *(__be32 *) (pkg->buffer + len) = tb_crc(pkg->buffer, len); in tb_ctl_tx()
375 res = tb_ring_tx(ctl->tx, &pkg->frame); in tb_ctl_tx()
377 tb_ctl_pkg_free(pkg); in tb_ctl_tx()
385 struct ctl_pkg *pkg, size_t size) in tb_ctl_handle_event() argument
387 return ctl->callback(ctl->callback_data, type, pkg->buffer, size); in tb_ctl_handle_event()
390 static void tb_ctl_rx_submit(struct ctl_pkg *pkg) in tb_ctl_rx_submit() argument
392 tb_ring_rx(pkg->ctl->rx, &pkg->frame); /* in tb_ctl_rx_submit()
400 static int tb_async_error(const struct ctl_pkg *pkg) in tb_async_error() argument
402 const struct cfg_error_pkg *error = pkg->buffer; in tb_async_error()
404 if (pkg->frame.eof != TB_CFG_PKG_ERROR) in tb_async_error()
429 struct ctl_pkg *pkg = container_of(frame, typeof(*pkg), frame); in tb_ctl_rx_callback() local
440 tb_ctl_err(pkg->ctl, "RX: invalid size %#x, dropping packet\n", in tb_ctl_rx_callback()
446 crc32 = tb_crc(pkg->buffer, frame->size); in tb_ctl_rx_callback()
447 be32_to_cpu_array(pkg->buffer, pkg->buffer, frame->size / 4); in tb_ctl_rx_callback()
455 if (*(__be32 *)(pkg->buffer + frame->size) != crc32) { in tb_ctl_rx_callback()
456 tb_ctl_err(pkg->ctl, in tb_ctl_rx_callback()
460 if (tb_async_error(pkg)) { in tb_ctl_rx_callback()
461 tb_ctl_handle_event(pkg->ctl, frame->eof, in tb_ctl_rx_callback()
462 pkg, frame->size); in tb_ctl_rx_callback()
470 if (*(__be32 *)(pkg->buffer + frame->size) != crc32) { in tb_ctl_rx_callback()
471 tb_ctl_err(pkg->ctl, in tb_ctl_rx_callback()
477 if (tb_ctl_handle_event(pkg->ctl, frame->eof, pkg, frame->size)) in tb_ctl_rx_callback()
491 req = tb_cfg_request_find(pkg->ctl, pkg); in tb_ctl_rx_callback()
493 if (req->copy(req, pkg)) in tb_ctl_rx_callback()
499 tb_ctl_rx_submit(pkg); in tb_ctl_rx_callback()
750 struct cfg_ack_pkg pkg = { in tb_cfg_ack_notification() local
797 return tb_ctl_tx(ctl, &pkg, sizeof(pkg), TB_CFG_PKG_NOTIFY_ACK); in tb_cfg_ack_notification()
812 struct cfg_error_pkg pkg = { in tb_cfg_ack_plug() local
821 return tb_ctl_tx(ctl, &pkg, sizeof(pkg), TB_CFG_PKG_ERROR); in tb_cfg_ack_plug()
825 const struct ctl_pkg *pkg) in tb_cfg_match() argument
827 u64 route = tb_cfg_get_route(pkg->buffer) & ~BIT_ULL(63); in tb_cfg_match()
829 if (pkg->frame.eof == TB_CFG_PKG_ERROR) in tb_cfg_match()
832 if (pkg->frame.eof != req->response_type) in tb_cfg_match()
836 if (pkg->frame.size != req->response_size) in tb_cfg_match()
839 if (pkg->frame.eof == TB_CFG_PKG_READ || in tb_cfg_match()
840 pkg->frame.eof == TB_CFG_PKG_WRITE) { in tb_cfg_match()
842 const struct cfg_read_pkg *res_hdr = pkg->buffer; in tb_cfg_match()
851 static bool tb_cfg_copy(struct tb_cfg_request *req, const struct ctl_pkg *pkg) in tb_cfg_copy() argument
856 res = parse_header(pkg, req->response_size, req->response_type, in tb_cfg_copy()
859 memcpy(req->response, pkg->buffer, req->response_size); in tb_cfg_copy()