Lines Matching refs:pkg

147 tb_cfg_request_find(struct tb_ctl *ctl, struct ctl_pkg *pkg)
152 mutex_lock(&pkg->ctl->request_queue_lock);
153 list_for_each_entry(req, &pkg->ctl->request_queue, list) {
155 if (req->match(req, pkg)) {
161 mutex_unlock(&pkg->ctl->request_queue_lock);
169 static int check_header(const struct ctl_pkg *pkg, u32 len,
172 struct tb_cfg_header *header = pkg->buffer;
175 if (WARN(len != pkg->frame.size,
177 len, pkg->frame.size))
179 if (WARN(type != pkg->frame.eof, "wrong eof (expected %#x, got %#x)\n",
180 type, pkg->frame.eof))
182 if (WARN(pkg->frame.sof, "wrong sof (expected 0x0, got %#x)\n",
183 pkg->frame.sof))
221 struct cfg_error_pkg *pkg = response->buffer;
224 res.response_route = tb_cfg_get_route(&pkg->header);
226 res.err = check_header(response, sizeof(*pkg), TB_CFG_PKG_ERROR,
227 tb_cfg_get_route(&pkg->header));
231 if (pkg->zero1)
232 tb_ctl_warn(ctl, "pkg->zero1 is %#x\n", pkg->zero1);
233 if (pkg->zero2)
234 tb_ctl_warn(ctl, "pkg->zero2 is %#x\n", pkg->zero2);
235 if (pkg->zero3)
236 tb_ctl_warn(ctl, "pkg->zero3 is %#x\n", pkg->zero3);
239 res.tb_error = pkg->error;
240 res.response_port = pkg->port;
245 static struct tb_cfg_result parse_header(const struct ctl_pkg *pkg, u32 len,
248 struct tb_cfg_header *header = pkg->buffer;
251 if (pkg->frame.eof == TB_CFG_PKG_ERROR)
252 return decode_error(pkg);
256 res.err = check_header(pkg, len, type, route);
307 static void tb_ctl_pkg_free(struct ctl_pkg *pkg)
309 if (pkg) {
310 dma_pool_free(pkg->ctl->frame_pool,
311 pkg->buffer, pkg->frame.buffer_phy);
312 kfree(pkg);
318 struct ctl_pkg *pkg = kzalloc(sizeof(*pkg), GFP_KERNEL);
319 if (!pkg)
321 pkg->ctl = ctl;
322 pkg->buffer = dma_pool_alloc(ctl->frame_pool, GFP_KERNEL,
323 &pkg->frame.buffer_phy);
324 if (!pkg->buffer) {
325 kfree(pkg);
328 return pkg;
337 struct ctl_pkg *pkg = container_of(frame, typeof(*pkg), frame);
338 tb_ctl_pkg_free(pkg);
352 struct ctl_pkg *pkg;
362 pkg = tb_ctl_pkg_alloc(ctl);
363 if (!pkg)
365 pkg->frame.callback = tb_ctl_tx_callback;
366 pkg->frame.size = len + 4;
367 pkg->frame.sof = type;
368 pkg->frame.eof = type;
369 cpu_to_be32_array(pkg->buffer, data, len / 4);
370 *(__be32 *) (pkg->buffer + len) = tb_crc(pkg->buffer, len);
372 res = tb_ring_tx(ctl->tx, &pkg->frame);
374 tb_ctl_pkg_free(pkg);
382 struct ctl_pkg *pkg, size_t size)
384 return ctl->callback(ctl->callback_data, type, pkg->buffer, size);
387 static void tb_ctl_rx_submit(struct ctl_pkg *pkg)
389 tb_ring_rx(pkg->ctl->rx, &pkg->frame); /*
397 static int tb_async_error(const struct ctl_pkg *pkg)
399 const struct cfg_error_pkg *error = pkg->buffer;
401 if (pkg->frame.eof != TB_CFG_PKG_ERROR)
418 struct ctl_pkg *pkg = container_of(frame, typeof(*pkg), frame);
429 tb_ctl_err(pkg->ctl, "RX: invalid size %#x, dropping packet\n",
435 crc32 = tb_crc(pkg->buffer, frame->size);
436 be32_to_cpu_array(pkg->buffer, pkg->buffer, frame->size / 4);
444 if (*(__be32 *)(pkg->buffer + frame->size) != crc32) {
445 tb_ctl_err(pkg->ctl,
449 if (tb_async_error(pkg)) {
450 tb_ctl_handle_event(pkg->ctl, frame->eof,
451 pkg, frame->size);
459 if (*(__be32 *)(pkg->buffer + frame->size) != crc32) {
460 tb_ctl_err(pkg->ctl,
466 if (tb_ctl_handle_event(pkg->ctl, frame->eof, pkg, frame->size))
480 req = tb_cfg_request_find(pkg->ctl, pkg);
482 if (req->copy(req, pkg))
488 tb_ctl_rx_submit(pkg);
730 struct cfg_error_pkg pkg = {
739 return tb_ctl_tx(ctl, &pkg, sizeof(pkg), TB_CFG_PKG_ERROR);
743 const struct ctl_pkg *pkg)
745 u64 route = tb_cfg_get_route(pkg->buffer) & ~BIT_ULL(63);
747 if (pkg->frame.eof == TB_CFG_PKG_ERROR)
750 if (pkg->frame.eof != req->response_type)
754 if (pkg->frame.size != req->response_size)
757 if (pkg->frame.eof == TB_CFG_PKG_READ ||
758 pkg->frame.eof == TB_CFG_PKG_WRITE) {
760 const struct cfg_read_pkg *res_hdr = pkg->buffer;
769 static bool tb_cfg_copy(struct tb_cfg_request *req, const struct ctl_pkg *pkg)
774 res = parse_header(pkg, req->response_size, req->response_type,
777 memcpy(req->response, pkg->buffer, req->response_size);