Lines Matching refs:hdev
32 bt_dev_dbg(hdev, \
34 hci_dmp_cb(skb)->pkt_type, hdev->dump.state)
51 static int hci_devcd_update_state(struct hci_dev *hdev, int state) in hci_devcd_update_state() argument
53 bt_dev_dbg(hdev, "Updating devcoredump state from %d to %d.", in hci_devcd_update_state()
54 hdev->dump.state, state); in hci_devcd_update_state()
56 hdev->dump.state = state; in hci_devcd_update_state()
58 return hci_devcd_update_hdr_state(hdev->dump.head, in hci_devcd_update_state()
59 hdev->dump.alloc_size, state); in hci_devcd_update_state()
62 static int hci_devcd_mkheader(struct hci_dev *hdev, struct sk_buff *skb) in hci_devcd_mkheader() argument
72 if (hdev->dump.dmp_hdr) in hci_devcd_mkheader()
73 hdev->dump.dmp_hdr(hdev, skb); in hci_devcd_mkheader()
81 static void hci_devcd_notify(struct hci_dev *hdev, int state) in hci_devcd_notify() argument
83 if (hdev->dump.notify_change) in hci_devcd_notify()
84 hdev->dump.notify_change(hdev, state); in hci_devcd_notify()
88 void hci_devcd_reset(struct hci_dev *hdev) in hci_devcd_reset() argument
90 hdev->dump.head = NULL; in hci_devcd_reset()
91 hdev->dump.tail = NULL; in hci_devcd_reset()
92 hdev->dump.alloc_size = 0; in hci_devcd_reset()
94 hci_devcd_update_state(hdev, HCI_DEVCOREDUMP_IDLE); in hci_devcd_reset()
96 cancel_delayed_work(&hdev->dump.dump_timeout); in hci_devcd_reset()
97 skb_queue_purge(&hdev->dump.dump_q); in hci_devcd_reset()
101 static void hci_devcd_free(struct hci_dev *hdev) in hci_devcd_free() argument
103 vfree(hdev->dump.head); in hci_devcd_free()
105 hci_devcd_reset(hdev); in hci_devcd_free()
109 static int hci_devcd_alloc(struct hci_dev *hdev, u32 size) in hci_devcd_alloc() argument
111 hdev->dump.head = vmalloc(size); in hci_devcd_alloc()
112 if (!hdev->dump.head) in hci_devcd_alloc()
115 hdev->dump.alloc_size = size; in hci_devcd_alloc()
116 hdev->dump.tail = hdev->dump.head; in hci_devcd_alloc()
117 hdev->dump.end = hdev->dump.head + size; in hci_devcd_alloc()
119 hci_devcd_update_state(hdev, HCI_DEVCOREDUMP_IDLE); in hci_devcd_alloc()
125 static bool hci_devcd_copy(struct hci_dev *hdev, char *buf, u32 size) in hci_devcd_copy() argument
127 if (hdev->dump.tail + size > hdev->dump.end) in hci_devcd_copy()
130 memcpy(hdev->dump.tail, buf, size); in hci_devcd_copy()
131 hdev->dump.tail += size; in hci_devcd_copy()
137 static bool hci_devcd_memset(struct hci_dev *hdev, u8 pattern, u32 len) in hci_devcd_memset() argument
139 if (hdev->dump.tail + len > hdev->dump.end) in hci_devcd_memset()
142 memset(hdev->dump.tail, pattern, len); in hci_devcd_memset()
143 hdev->dump.tail += len; in hci_devcd_memset()
149 static int hci_devcd_prepare(struct hci_dev *hdev, u32 dump_size) in hci_devcd_prepare() argument
159 dump_hdr_size = hci_devcd_mkheader(hdev, skb); in hci_devcd_prepare()
161 if (hci_devcd_alloc(hdev, dump_hdr_size + dump_size)) { in hci_devcd_prepare()
167 if (!hci_devcd_copy(hdev, skb->data, skb->len)) { in hci_devcd_prepare()
168 bt_dev_err(hdev, "Failed to insert header"); in hci_devcd_prepare()
169 hci_devcd_free(hdev); in hci_devcd_prepare()
181 static void hci_devcd_handle_pkt_init(struct hci_dev *hdev, struct sk_buff *skb) in hci_devcd_handle_pkt_init() argument
185 if (hdev->dump.state != HCI_DEVCOREDUMP_IDLE) { in hci_devcd_handle_pkt_init()
191 bt_dev_dbg(hdev, "Invalid dump init pkt"); in hci_devcd_handle_pkt_init()
197 bt_dev_err(hdev, "Zero size dump init pkt"); in hci_devcd_handle_pkt_init()
201 if (hci_devcd_prepare(hdev, dump_size)) { in hci_devcd_handle_pkt_init()
202 bt_dev_err(hdev, "Failed to prepare for dump"); in hci_devcd_handle_pkt_init()
206 hci_devcd_update_state(hdev, HCI_DEVCOREDUMP_ACTIVE); in hci_devcd_handle_pkt_init()
207 queue_delayed_work(hdev->workqueue, &hdev->dump.dump_timeout, in hci_devcd_handle_pkt_init()
208 hdev->dump.timeout); in hci_devcd_handle_pkt_init()
211 static void hci_devcd_handle_pkt_skb(struct hci_dev *hdev, struct sk_buff *skb) in hci_devcd_handle_pkt_skb() argument
213 if (hdev->dump.state != HCI_DEVCOREDUMP_ACTIVE) { in hci_devcd_handle_pkt_skb()
218 if (!hci_devcd_copy(hdev, skb->data, skb->len)) in hci_devcd_handle_pkt_skb()
219 bt_dev_dbg(hdev, "Failed to insert skb"); in hci_devcd_handle_pkt_skb()
222 static void hci_devcd_handle_pkt_pattern(struct hci_dev *hdev, in hci_devcd_handle_pkt_pattern() argument
227 if (hdev->dump.state != HCI_DEVCOREDUMP_ACTIVE) { in hci_devcd_handle_pkt_pattern()
233 bt_dev_dbg(hdev, "Invalid pattern skb"); in hci_devcd_handle_pkt_pattern()
239 if (!hci_devcd_memset(hdev, pattern->pattern, pattern->len)) in hci_devcd_handle_pkt_pattern()
240 bt_dev_dbg(hdev, "Failed to set pattern"); in hci_devcd_handle_pkt_pattern()
243 static void hci_devcd_handle_pkt_complete(struct hci_dev *hdev, in hci_devcd_handle_pkt_complete() argument
248 if (hdev->dump.state != HCI_DEVCOREDUMP_ACTIVE) { in hci_devcd_handle_pkt_complete()
253 hci_devcd_update_state(hdev, HCI_DEVCOREDUMP_DONE); in hci_devcd_handle_pkt_complete()
254 dump_size = hdev->dump.tail - hdev->dump.head; in hci_devcd_handle_pkt_complete()
256 bt_dev_dbg(hdev, "complete with size %u (expect %zu)", dump_size, in hci_devcd_handle_pkt_complete()
257 hdev->dump.alloc_size); in hci_devcd_handle_pkt_complete()
259 dev_coredumpv(&hdev->dev, hdev->dump.head, dump_size, GFP_KERNEL); in hci_devcd_handle_pkt_complete()
262 static void hci_devcd_handle_pkt_abort(struct hci_dev *hdev, in hci_devcd_handle_pkt_abort() argument
267 if (hdev->dump.state != HCI_DEVCOREDUMP_ACTIVE) { in hci_devcd_handle_pkt_abort()
272 hci_devcd_update_state(hdev, HCI_DEVCOREDUMP_ABORT); in hci_devcd_handle_pkt_abort()
273 dump_size = hdev->dump.tail - hdev->dump.head; in hci_devcd_handle_pkt_abort()
275 bt_dev_dbg(hdev, "aborted with size %u (expect %zu)", dump_size, in hci_devcd_handle_pkt_abort()
276 hdev->dump.alloc_size); in hci_devcd_handle_pkt_abort()
279 dev_coredumpv(&hdev->dev, hdev->dump.head, dump_size, GFP_KERNEL); in hci_devcd_handle_pkt_abort()
314 struct hci_dev *hdev = container_of(work, struct hci_dev, dump.dump_rx); in hci_devcd_rx() local
318 while ((skb = skb_dequeue(&hdev->dump.dump_q))) { in hci_devcd_rx()
322 if (hdev->dump.state == HCI_DEVCOREDUMP_TIMEOUT) { in hci_devcd_rx()
327 hci_dev_lock(hdev); in hci_devcd_rx()
328 start_state = hdev->dump.state; in hci_devcd_rx()
332 hci_devcd_handle_pkt_init(hdev, skb); in hci_devcd_rx()
336 hci_devcd_handle_pkt_skb(hdev, skb); in hci_devcd_rx()
340 hci_devcd_handle_pkt_pattern(hdev, skb); in hci_devcd_rx()
344 hci_devcd_handle_pkt_complete(hdev, skb); in hci_devcd_rx()
348 hci_devcd_handle_pkt_abort(hdev, skb); in hci_devcd_rx()
352 bt_dev_dbg(hdev, "Unknown packet (%d) for state (%d). ", in hci_devcd_rx()
353 hci_dmp_cb(skb)->pkt_type, hdev->dump.state); in hci_devcd_rx()
357 hci_dev_unlock(hdev); in hci_devcd_rx()
363 if (start_state != hdev->dump.state) in hci_devcd_rx()
364 hci_devcd_notify(hdev, hdev->dump.state); in hci_devcd_rx()
367 hci_dev_lock(hdev); in hci_devcd_rx()
368 if (hdev->dump.state == HCI_DEVCOREDUMP_DONE || in hci_devcd_rx()
369 hdev->dump.state == HCI_DEVCOREDUMP_ABORT) in hci_devcd_rx()
370 hci_devcd_reset(hdev); in hci_devcd_rx()
371 hci_dev_unlock(hdev); in hci_devcd_rx()
378 struct hci_dev *hdev = container_of(work, struct hci_dev, in hci_devcd_timeout() local
382 hci_devcd_notify(hdev, HCI_DEVCOREDUMP_TIMEOUT); in hci_devcd_timeout()
384 hci_dev_lock(hdev); in hci_devcd_timeout()
386 cancel_work(&hdev->dump.dump_rx); in hci_devcd_timeout()
388 hci_devcd_update_state(hdev, HCI_DEVCOREDUMP_TIMEOUT); in hci_devcd_timeout()
390 dump_size = hdev->dump.tail - hdev->dump.head; in hci_devcd_timeout()
391 bt_dev_dbg(hdev, "timeout with size %u (expect %zu)", dump_size, in hci_devcd_timeout()
392 hdev->dump.alloc_size); in hci_devcd_timeout()
395 dev_coredumpv(&hdev->dev, hdev->dump.head, dump_size, GFP_KERNEL); in hci_devcd_timeout()
397 hci_devcd_reset(hdev); in hci_devcd_timeout()
399 hci_dev_unlock(hdev); in hci_devcd_timeout()
403 int hci_devcd_register(struct hci_dev *hdev, coredump_t coredump, in hci_devcd_register() argument
415 hci_dev_lock(hdev); in hci_devcd_register()
416 hdev->dump.coredump = coredump; in hci_devcd_register()
417 hdev->dump.dmp_hdr = dmp_hdr; in hci_devcd_register()
418 hdev->dump.notify_change = notify_change; in hci_devcd_register()
419 hdev->dump.supported = true; in hci_devcd_register()
420 hdev->dump.timeout = DEVCOREDUMP_TIMEOUT; in hci_devcd_register()
421 hci_dev_unlock(hdev); in hci_devcd_register()
427 static inline bool hci_devcd_enabled(struct hci_dev *hdev) in hci_devcd_enabled() argument
429 return hdev->dump.supported; in hci_devcd_enabled()
432 int hci_devcd_init(struct hci_dev *hdev, u32 dump_size) in hci_devcd_init() argument
436 if (!hci_devcd_enabled(hdev)) in hci_devcd_init()
446 skb_queue_tail(&hdev->dump.dump_q, skb); in hci_devcd_init()
447 queue_work(hdev->workqueue, &hdev->dump.dump_rx); in hci_devcd_init()
453 int hci_devcd_append(struct hci_dev *hdev, struct sk_buff *skb) in hci_devcd_append() argument
458 if (!hci_devcd_enabled(hdev)) { in hci_devcd_append()
465 skb_queue_tail(&hdev->dump.dump_q, skb); in hci_devcd_append()
466 queue_work(hdev->workqueue, &hdev->dump.dump_rx); in hci_devcd_append()
472 int hci_devcd_append_pattern(struct hci_dev *hdev, u8 pattern, u32 len) in hci_devcd_append_pattern() argument
477 if (!hci_devcd_enabled(hdev)) in hci_devcd_append_pattern()
490 skb_queue_tail(&hdev->dump.dump_q, skb); in hci_devcd_append_pattern()
491 queue_work(hdev->workqueue, &hdev->dump.dump_rx); in hci_devcd_append_pattern()
497 int hci_devcd_complete(struct hci_dev *hdev) in hci_devcd_complete() argument
501 if (!hci_devcd_enabled(hdev)) in hci_devcd_complete()
510 skb_queue_tail(&hdev->dump.dump_q, skb); in hci_devcd_complete()
511 queue_work(hdev->workqueue, &hdev->dump.dump_rx); in hci_devcd_complete()
517 int hci_devcd_abort(struct hci_dev *hdev) in hci_devcd_abort() argument
521 if (!hci_devcd_enabled(hdev)) in hci_devcd_abort()
530 skb_queue_tail(&hdev->dump.dump_q, skb); in hci_devcd_abort()
531 queue_work(hdev->workqueue, &hdev->dump.dump_rx); in hci_devcd_abort()