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