neh.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. /*
  2. * WUSB Wire Adapter: Radio Control Interface (WUSB[8])
  3. * Notification and Event Handling
  4. *
  5. * Copyright (C) 2005-2006 Intel Corporation
  6. * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License version
  10. * 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  20. * 02110-1301, USA.
  21. *
  22. *
  23. * The RC interface of the Host Wire Adapter (USB dongle) or WHCI PCI
  24. * card delivers a stream of notifications and events to the
  25. * notification end event endpoint or area. This code takes care of
  26. * getting a buffer with that data, breaking it up in separate
  27. * notifications and events and then deliver those.
  28. *
  29. * Events are answers to commands and they carry a context ID that
  30. * associates them to the command. Notifications are that,
  31. * notifications, they come out of the blue and have a context ID of
  32. * zero. Think of the context ID kind of like a handler. The
  33. * uwb_rc_neh_* code deals with managing context IDs.
  34. *
  35. * This is why you require a handle to operate on a UWB host. When you
  36. * open a handle a context ID is assigned to you.
  37. *
  38. * So, as it is done is:
  39. *
  40. * 1. Add an event handler [uwb_rc_neh_add()] (assigns a ctx id)
  41. * 2. Issue command [rc->cmd(rc, ...)]
  42. * 3. Arm the timeout timer [uwb_rc_neh_arm()]
  43. * 4, Release the reference to the neh [uwb_rc_neh_put()]
  44. * 5. Wait for the callback
  45. * 6. Command result (RCEB) is passed to the callback
  46. *
  47. * If (2) fails, you should remove the handle [uwb_rc_neh_rm()]
  48. * instead of arming the timer.
  49. *
  50. * Handles are for using in *serialized* code, single thread.
  51. *
  52. * When the notification/event comes, the IRQ handler/endpoint
  53. * callback passes the data read to uwb_rc_neh_grok() which will break
  54. * it up in a discrete series of events, look up who is listening for
  55. * them and execute the pertinent callbacks.
  56. *
  57. * If the reader detects an error while reading the data stream, call
  58. * uwb_rc_neh_error().
  59. *
  60. * CONSTRAINTS/ASSUMPTIONS:
  61. *
  62. * - Most notifications/events are small (less thank .5k), copying
  63. * around is ok.
  64. *
  65. * - Notifications/events are ALWAYS smaller than PAGE_SIZE
  66. *
  67. * - Notifications/events always come in a single piece (ie: a buffer
  68. * will always contain entire notifications/events).
  69. *
  70. * - we cannot know in advance how long each event is (because they
  71. * lack a length field in their header--smart move by the standards
  72. * body, btw). So we need a facility to get the event size given the
  73. * header. This is what the EST code does (notif/Event Size
  74. * Tables), check nest.c--as well, you can associate the size to
  75. * the handle [w/ neh->extra_size()].
  76. *
  77. * - Most notifications/events are fixed size; only a few are variable
  78. * size (NEST takes care of that).
  79. *
  80. * - Listeners of events expect them, so they usually provide a
  81. * buffer, as they know the size. Listeners to notifications don't,
  82. * so we allocate their buffers dynamically.
  83. */
  84. #include <linux/kernel.h>
  85. #include <linux/timer.h>
  86. #include <linux/slab.h>
  87. #include <linux/err.h>
  88. #include "uwb-internal.h"
  89. /*
  90. * UWB Radio Controller Notification/Event Handle
  91. *
  92. * Represents an entity waiting for an event coming from the UWB Radio
  93. * Controller with a given context id (context) and type (evt_type and
  94. * evt). On reception of the notification/event, the callback (cb) is
  95. * called with the event.
  96. *
  97. * If the timer expires before the event is received, the callback is
  98. * called with -ETIMEDOUT as the event size.
  99. */
  100. struct uwb_rc_neh {
  101. struct kref kref;
  102. struct uwb_rc *rc;
  103. u8 evt_type;
  104. __le16 evt;
  105. u8 context;
  106. u8 completed;
  107. uwb_rc_cmd_cb_f cb;
  108. void *arg;
  109. struct timer_list timer;
  110. struct list_head list_node;
  111. };
  112. static void uwb_rc_neh_timer(unsigned long arg);
  113. static void uwb_rc_neh_release(struct kref *kref)
  114. {
  115. struct uwb_rc_neh *neh = container_of(kref, struct uwb_rc_neh, kref);
  116. kfree(neh);
  117. }
  118. static void uwb_rc_neh_get(struct uwb_rc_neh *neh)
  119. {
  120. kref_get(&neh->kref);
  121. }
  122. /**
  123. * uwb_rc_neh_put - release reference to a neh
  124. * @neh: the neh
  125. */
  126. void uwb_rc_neh_put(struct uwb_rc_neh *neh)
  127. {
  128. kref_put(&neh->kref, uwb_rc_neh_release);
  129. }
  130. /**
  131. * Assigns @neh a context id from @rc's pool
  132. *
  133. * @rc: UWB Radio Controller descriptor; @rc->neh_lock taken
  134. * @neh: Notification/Event Handle
  135. * @returns 0 if context id was assigned ok; < 0 errno on error (if
  136. * all the context IDs are taken).
  137. *
  138. * (assumes @wa is locked).
  139. *
  140. * NOTE: WUSB spec reserves context ids 0x00 for notifications and
  141. * 0xff is invalid, so they must not be used. Initialization
  142. * fills up those two in the bitmap so they are not allocated.
  143. *
  144. * We spread the allocation around to reduce the possibility of two
  145. * consecutive opened @neh's getting the same context ID assigned (to
  146. * avoid surprises with late events that timed out long time ago). So
  147. * first we search from where @rc->ctx_roll is, if not found, we
  148. * search from zero.
  149. */
  150. static
  151. int __uwb_rc_ctx_get(struct uwb_rc *rc, struct uwb_rc_neh *neh)
  152. {
  153. int result;
  154. result = find_next_zero_bit(rc->ctx_bm, UWB_RC_CTX_MAX,
  155. rc->ctx_roll++);
  156. if (result < UWB_RC_CTX_MAX)
  157. goto found;
  158. result = find_first_zero_bit(rc->ctx_bm, UWB_RC_CTX_MAX);
  159. if (result < UWB_RC_CTX_MAX)
  160. goto found;
  161. return -ENFILE;
  162. found:
  163. set_bit(result, rc->ctx_bm);
  164. neh->context = result;
  165. return 0;
  166. }
  167. /** Releases @neh's context ID back to @rc (@rc->neh_lock is locked). */
  168. static
  169. void __uwb_rc_ctx_put(struct uwb_rc *rc, struct uwb_rc_neh *neh)
  170. {
  171. struct device *dev = &rc->uwb_dev.dev;
  172. if (neh->context == 0)
  173. return;
  174. if (test_bit(neh->context, rc->ctx_bm) == 0) {
  175. dev_err(dev, "context %u not set in bitmap\n",
  176. neh->context);
  177. WARN_ON(1);
  178. }
  179. clear_bit(neh->context, rc->ctx_bm);
  180. neh->context = 0;
  181. }
  182. /**
  183. * uwb_rc_neh_add - add a neh for a radio controller command
  184. * @rc: the radio controller
  185. * @cmd: the radio controller command
  186. * @expected_type: the type of the expected response event
  187. * @expected_event: the expected event ID
  188. * @cb: callback for when the event is received
  189. * @arg: argument for the callback
  190. *
  191. * Creates a neh and adds it to the list of those waiting for an
  192. * event. A context ID will be assigned to the command.
  193. */
  194. struct uwb_rc_neh *uwb_rc_neh_add(struct uwb_rc *rc, struct uwb_rccb *cmd,
  195. u8 expected_type, u16 expected_event,
  196. uwb_rc_cmd_cb_f cb, void *arg)
  197. {
  198. int result;
  199. unsigned long flags;
  200. struct device *dev = &rc->uwb_dev.dev;
  201. struct uwb_rc_neh *neh;
  202. neh = kzalloc(sizeof(*neh), GFP_KERNEL);
  203. if (neh == NULL) {
  204. result = -ENOMEM;
  205. goto error_kzalloc;
  206. }
  207. kref_init(&neh->kref);
  208. INIT_LIST_HEAD(&neh->list_node);
  209. init_timer(&neh->timer);
  210. neh->timer.function = uwb_rc_neh_timer;
  211. neh->timer.data = (unsigned long)neh;
  212. neh->rc = rc;
  213. neh->evt_type = expected_type;
  214. neh->evt = cpu_to_le16(expected_event);
  215. neh->cb = cb;
  216. neh->arg = arg;
  217. spin_lock_irqsave(&rc->neh_lock, flags);
  218. result = __uwb_rc_ctx_get(rc, neh);
  219. if (result >= 0) {
  220. cmd->bCommandContext = neh->context;
  221. list_add_tail(&neh->list_node, &rc->neh_list);
  222. uwb_rc_neh_get(neh);
  223. }
  224. spin_unlock_irqrestore(&rc->neh_lock, flags);
  225. if (result < 0)
  226. goto error_ctx_get;
  227. return neh;
  228. error_ctx_get:
  229. kfree(neh);
  230. error_kzalloc:
  231. dev_err(dev, "cannot open handle to radio controller: %d\n", result);
  232. return ERR_PTR(result);
  233. }
  234. static void __uwb_rc_neh_rm(struct uwb_rc *rc, struct uwb_rc_neh *neh)
  235. {
  236. __uwb_rc_ctx_put(rc, neh);
  237. list_del(&neh->list_node);
  238. }
  239. /**
  240. * uwb_rc_neh_rm - remove a neh.
  241. * @rc: the radio controller
  242. * @neh: the neh to remove
  243. *
  244. * Remove an active neh immediately instead of waiting for the event
  245. * (or a time out).
  246. */
  247. void uwb_rc_neh_rm(struct uwb_rc *rc, struct uwb_rc_neh *neh)
  248. {
  249. unsigned long flags;
  250. spin_lock_irqsave(&rc->neh_lock, flags);
  251. __uwb_rc_neh_rm(rc, neh);
  252. spin_unlock_irqrestore(&rc->neh_lock, flags);
  253. del_timer_sync(&neh->timer);
  254. uwb_rc_neh_put(neh);
  255. }
  256. /**
  257. * uwb_rc_neh_arm - arm an event handler timeout timer
  258. *
  259. * @rc: UWB Radio Controller
  260. * @neh: Notification/event handler for @rc
  261. *
  262. * The timer is only armed if the neh is active.
  263. */
  264. void uwb_rc_neh_arm(struct uwb_rc *rc, struct uwb_rc_neh *neh)
  265. {
  266. unsigned long flags;
  267. spin_lock_irqsave(&rc->neh_lock, flags);
  268. if (neh->context)
  269. mod_timer(&neh->timer,
  270. jiffies + msecs_to_jiffies(UWB_RC_CMD_TIMEOUT_MS));
  271. spin_unlock_irqrestore(&rc->neh_lock, flags);
  272. }
  273. static void uwb_rc_neh_cb(struct uwb_rc_neh *neh, struct uwb_rceb *rceb, size_t size)
  274. {
  275. (*neh->cb)(neh->rc, neh->arg, rceb, size);
  276. uwb_rc_neh_put(neh);
  277. }
  278. static bool uwb_rc_neh_match(struct uwb_rc_neh *neh, const struct uwb_rceb *rceb)
  279. {
  280. return neh->evt_type == rceb->bEventType
  281. && neh->evt == rceb->wEvent
  282. && neh->context == rceb->bEventContext;
  283. }
  284. /**
  285. * Find the handle waiting for a RC Radio Control Event
  286. *
  287. * @rc: UWB Radio Controller
  288. * @rceb: Pointer to the RCEB buffer
  289. * @event_size: Pointer to the size of the RCEB buffer. Might be
  290. * adjusted to take into account the @neh->extra_size
  291. * settings.
  292. *
  293. * If the listener has no buffer (NULL buffer), one is allocated for
  294. * the right size (the amount of data received). @neh->ptr will point
  295. * to the event payload, which always starts with a 'struct
  296. * uwb_rceb'. kfree() it when done.
  297. */
  298. static
  299. struct uwb_rc_neh *uwb_rc_neh_lookup(struct uwb_rc *rc,
  300. const struct uwb_rceb *rceb)
  301. {
  302. struct uwb_rc_neh *neh = NULL, *h;
  303. unsigned long flags;
  304. spin_lock_irqsave(&rc->neh_lock, flags);
  305. list_for_each_entry(h, &rc->neh_list, list_node) {
  306. if (uwb_rc_neh_match(h, rceb)) {
  307. neh = h;
  308. break;
  309. }
  310. }
  311. if (neh)
  312. __uwb_rc_neh_rm(rc, neh);
  313. spin_unlock_irqrestore(&rc->neh_lock, flags);
  314. return neh;
  315. }
  316. /*
  317. * Process notifications coming from the radio control interface
  318. *
  319. * @rc: UWB Radio Control Interface descriptor
  320. * @neh: Notification/Event Handler @neh->ptr points to
  321. * @uwb_evt->buffer.
  322. *
  323. * This function is called by the event/notif handling subsystem when
  324. * notifications arrive (hwarc_probe() arms a notification/event handle
  325. * that calls back this function for every received notification; this
  326. * function then will rearm itself).
  327. *
  328. * Notification data buffers are dynamically allocated by the NEH
  329. * handling code in neh.c [uwb_rc_neh_lookup()]. What is actually
  330. * allocated is space to contain the notification data.
  331. *
  332. * Buffers are prefixed with a Radio Control Event Block (RCEB) as
  333. * defined by the WUSB Wired-Adapter Radio Control interface. We
  334. * just use it for the notification code.
  335. *
  336. * On each case statement we just transcode endianess of the different
  337. * fields. We declare a pointer to a RCI definition of an event, and
  338. * then to a UWB definition of the same event (which are the same,
  339. * remember). Event if we use different pointers
  340. */
  341. static
  342. void uwb_rc_notif(struct uwb_rc *rc, struct uwb_rceb *rceb, ssize_t size)
  343. {
  344. struct device *dev = &rc->uwb_dev.dev;
  345. struct uwb_event *uwb_evt;
  346. if (size == -ESHUTDOWN)
  347. return;
  348. if (size < 0) {
  349. dev_err(dev, "ignoring event with error code %zu\n",
  350. size);
  351. return;
  352. }
  353. uwb_evt = kzalloc(sizeof(*uwb_evt), GFP_ATOMIC);
  354. if (unlikely(uwb_evt == NULL)) {
  355. dev_err(dev, "no memory to queue event 0x%02x/%04x/%02x\n",
  356. rceb->bEventType, le16_to_cpu(rceb->wEvent),
  357. rceb->bEventContext);
  358. return;
  359. }
  360. uwb_evt->rc = __uwb_rc_get(rc); /* will be put by uwbd's uwbd_event_handle() */
  361. uwb_evt->ts_jiffies = jiffies;
  362. uwb_evt->type = UWB_EVT_TYPE_NOTIF;
  363. uwb_evt->notif.size = size;
  364. uwb_evt->notif.rceb = rceb;
  365. uwbd_event_queue(uwb_evt);
  366. }
  367. static void uwb_rc_neh_grok_event(struct uwb_rc *rc, struct uwb_rceb *rceb, size_t size)
  368. {
  369. struct device *dev = &rc->uwb_dev.dev;
  370. struct uwb_rc_neh *neh;
  371. struct uwb_rceb *notif;
  372. unsigned long flags;
  373. if (rceb->bEventContext == 0) {
  374. notif = kmalloc(size, GFP_ATOMIC);
  375. if (notif) {
  376. memcpy(notif, rceb, size);
  377. uwb_rc_notif(rc, notif, size);
  378. } else
  379. dev_err(dev, "event 0x%02x/%04x/%02x (%zu bytes): no memory\n",
  380. rceb->bEventType, le16_to_cpu(rceb->wEvent),
  381. rceb->bEventContext, size);
  382. } else {
  383. neh = uwb_rc_neh_lookup(rc, rceb);
  384. if (neh) {
  385. spin_lock_irqsave(&rc->neh_lock, flags);
  386. /* to guard against a timeout */
  387. neh->completed = 1;
  388. del_timer(&neh->timer);
  389. spin_unlock_irqrestore(&rc->neh_lock, flags);
  390. uwb_rc_neh_cb(neh, rceb, size);
  391. } else
  392. dev_warn(dev, "event 0x%02x/%04x/%02x (%zu bytes): nobody cared\n",
  393. rceb->bEventType, le16_to_cpu(rceb->wEvent),
  394. rceb->bEventContext, size);
  395. }
  396. }
  397. /**
  398. * Given a buffer with one or more UWB RC events/notifications, break
  399. * them up and dispatch them.
  400. *
  401. * @rc: UWB Radio Controller
  402. * @buf: Buffer with the stream of notifications/events
  403. * @buf_size: Amount of data in the buffer
  404. *
  405. * Note each notification/event starts always with a 'struct
  406. * uwb_rceb', so the minimum size if 4 bytes.
  407. *
  408. * The device may pass us events formatted differently than expected.
  409. * These are first filtered, potentially creating a new event in a new
  410. * memory location. If a new event is created by the filter it is also
  411. * freed here.
  412. *
  413. * For each notif/event, tries to guess the size looking at the EST
  414. * tables, then looks for a neh that is waiting for that event and if
  415. * found, copies the payload to the neh's buffer and calls it back. If
  416. * not, the data is ignored.
  417. *
  418. * Note that if we can't find a size description in the EST tables, we
  419. * still might find a size in the 'neh' handle in uwb_rc_neh_lookup().
  420. *
  421. * Assumptions:
  422. *
  423. * @rc->neh_lock is NOT taken
  424. *
  425. * We keep track of various sizes here:
  426. * size: contains the size of the buffer that is processed for the
  427. * incoming event. this buffer may contain events that are not
  428. * formatted as WHCI.
  429. * real_size: the actual space taken by this event in the buffer.
  430. * We need to keep track of the real size of an event to be able to
  431. * advance the buffer correctly.
  432. * event_size: the size of the event as expected by the core layer
  433. * [OR] the size of the event after filtering. if the filtering
  434. * created a new event in a new memory location then this is
  435. * effectively the size of a new event buffer
  436. */
  437. void uwb_rc_neh_grok(struct uwb_rc *rc, void *buf, size_t buf_size)
  438. {
  439. struct device *dev = &rc->uwb_dev.dev;
  440. void *itr;
  441. struct uwb_rceb *rceb;
  442. size_t size, real_size, event_size;
  443. int needtofree;
  444. itr = buf;
  445. size = buf_size;
  446. while (size > 0) {
  447. if (size < sizeof(*rceb)) {
  448. dev_err(dev, "not enough data in event buffer to "
  449. "process incoming events (%zu left, minimum is "
  450. "%zu)\n", size, sizeof(*rceb));
  451. break;
  452. }
  453. rceb = itr;
  454. if (rc->filter_event) {
  455. needtofree = rc->filter_event(rc, &rceb, size,
  456. &real_size, &event_size);
  457. if (needtofree < 0 && needtofree != -ENOANO) {
  458. dev_err(dev, "BUG: Unable to filter event "
  459. "(0x%02x/%04x/%02x) from "
  460. "device. \n", rceb->bEventType,
  461. le16_to_cpu(rceb->wEvent),
  462. rceb->bEventContext);
  463. break;
  464. }
  465. } else
  466. needtofree = -ENOANO;
  467. /* do real processing if there was no filtering or the
  468. * filtering didn't act */
  469. if (needtofree == -ENOANO) {
  470. ssize_t ret = uwb_est_find_size(rc, rceb, size);
  471. if (ret < 0)
  472. break;
  473. if (ret > size) {
  474. dev_err(dev, "BUG: hw sent incomplete event "
  475. "0x%02x/%04x/%02x (%zd bytes), only got "
  476. "%zu bytes. We don't handle that.\n",
  477. rceb->bEventType, le16_to_cpu(rceb->wEvent),
  478. rceb->bEventContext, ret, size);
  479. break;
  480. }
  481. real_size = event_size = ret;
  482. }
  483. uwb_rc_neh_grok_event(rc, rceb, event_size);
  484. if (needtofree == 1)
  485. kfree(rceb);
  486. itr += real_size;
  487. size -= real_size;
  488. }
  489. }
  490. EXPORT_SYMBOL_GPL(uwb_rc_neh_grok);
  491. /**
  492. * The entity that reads from the device notification/event channel has
  493. * detected an error.
  494. *
  495. * @rc: UWB Radio Controller
  496. * @error: Errno error code
  497. *
  498. */
  499. void uwb_rc_neh_error(struct uwb_rc *rc, int error)
  500. {
  501. struct uwb_rc_neh *neh;
  502. unsigned long flags;
  503. for (;;) {
  504. spin_lock_irqsave(&rc->neh_lock, flags);
  505. if (list_empty(&rc->neh_list)) {
  506. spin_unlock_irqrestore(&rc->neh_lock, flags);
  507. break;
  508. }
  509. neh = list_first_entry(&rc->neh_list, struct uwb_rc_neh, list_node);
  510. __uwb_rc_neh_rm(rc, neh);
  511. spin_unlock_irqrestore(&rc->neh_lock, flags);
  512. del_timer_sync(&neh->timer);
  513. uwb_rc_neh_cb(neh, NULL, error);
  514. }
  515. }
  516. EXPORT_SYMBOL_GPL(uwb_rc_neh_error);
  517. static void uwb_rc_neh_timer(unsigned long arg)
  518. {
  519. struct uwb_rc_neh *neh = (struct uwb_rc_neh *)arg;
  520. struct uwb_rc *rc = neh->rc;
  521. unsigned long flags;
  522. spin_lock_irqsave(&rc->neh_lock, flags);
  523. if (neh->completed) {
  524. spin_unlock_irqrestore(&rc->neh_lock, flags);
  525. return;
  526. }
  527. if (neh->context)
  528. __uwb_rc_neh_rm(rc, neh);
  529. else
  530. neh = NULL;
  531. spin_unlock_irqrestore(&rc->neh_lock, flags);
  532. if (neh)
  533. uwb_rc_neh_cb(neh, NULL, -ETIMEDOUT);
  534. }
  535. /** Initializes the @rc's neh subsystem
  536. */
  537. void uwb_rc_neh_create(struct uwb_rc *rc)
  538. {
  539. spin_lock_init(&rc->neh_lock);
  540. INIT_LIST_HEAD(&rc->neh_list);
  541. set_bit(0, rc->ctx_bm); /* 0 is reserved (see [WUSB] table 8-65) */
  542. set_bit(0xff, rc->ctx_bm); /* and 0xff is invalid */
  543. rc->ctx_roll = 1;
  544. }
  545. /** Release's the @rc's neh subsystem */
  546. void uwb_rc_neh_destroy(struct uwb_rc *rc)
  547. {
  548. unsigned long flags;
  549. struct uwb_rc_neh *neh;
  550. for (;;) {
  551. spin_lock_irqsave(&rc->neh_lock, flags);
  552. if (list_empty(&rc->neh_list)) {
  553. spin_unlock_irqrestore(&rc->neh_lock, flags);
  554. break;
  555. }
  556. neh = list_first_entry(&rc->neh_list, struct uwb_rc_neh, list_node);
  557. __uwb_rc_neh_rm(rc, neh);
  558. spin_unlock_irqrestore(&rc->neh_lock, flags);
  559. del_timer_sync(&neh->timer);
  560. uwb_rc_neh_put(neh);
  561. }
  562. }