Lines Matching refs:ecu

19 	struct j1939_ecu *ecu = container_of(kref, struct j1939_ecu, kref);  in __j1939_ecu_release()  local
20 struct j1939_priv *priv = ecu->priv; in __j1939_ecu_release()
22 list_del(&ecu->list); in __j1939_ecu_release()
23 kfree(ecu); in __j1939_ecu_release()
27 void j1939_ecu_put(struct j1939_ecu *ecu) in j1939_ecu_put() argument
29 kref_put(&ecu->kref, __j1939_ecu_release); in j1939_ecu_put()
32 static void j1939_ecu_get(struct j1939_ecu *ecu) in j1939_ecu_get() argument
34 kref_get(&ecu->kref); in j1939_ecu_get()
37 static bool j1939_ecu_is_mapped_locked(struct j1939_ecu *ecu) in j1939_ecu_is_mapped_locked() argument
39 struct j1939_priv *priv = ecu->priv; in j1939_ecu_is_mapped_locked()
43 return j1939_ecu_find_by_addr_locked(priv, ecu->addr) == ecu; in j1939_ecu_is_mapped_locked()
48 static void j1939_ecu_map_locked(struct j1939_ecu *ecu) in j1939_ecu_map_locked() argument
50 struct j1939_priv *priv = ecu->priv; in j1939_ecu_map_locked()
55 if (!j1939_address_is_unicast(ecu->addr)) in j1939_ecu_map_locked()
58 ent = &priv->ents[ecu->addr]; in j1939_ecu_map_locked()
60 if (ent->ecu) { in j1939_ecu_map_locked()
62 ecu->addr, ecu->name); in j1939_ecu_map_locked()
66 j1939_ecu_get(ecu); in j1939_ecu_map_locked()
67 ent->ecu = ecu; in j1939_ecu_map_locked()
68 ent->nusers += ecu->nusers; in j1939_ecu_map_locked()
72 void j1939_ecu_unmap_locked(struct j1939_ecu *ecu) in j1939_ecu_unmap_locked() argument
74 struct j1939_priv *priv = ecu->priv; in j1939_ecu_unmap_locked()
79 if (!j1939_address_is_unicast(ecu->addr)) in j1939_ecu_unmap_locked()
82 if (!j1939_ecu_is_mapped_locked(ecu)) in j1939_ecu_unmap_locked()
85 ent = &priv->ents[ecu->addr]; in j1939_ecu_unmap_locked()
86 ent->ecu = NULL; in j1939_ecu_unmap_locked()
87 ent->nusers -= ecu->nusers; in j1939_ecu_unmap_locked()
88 j1939_ecu_put(ecu); in j1939_ecu_unmap_locked()
91 void j1939_ecu_unmap(struct j1939_ecu *ecu) in j1939_ecu_unmap() argument
93 write_lock_bh(&ecu->priv->lock); in j1939_ecu_unmap()
94 j1939_ecu_unmap_locked(ecu); in j1939_ecu_unmap()
95 write_unlock_bh(&ecu->priv->lock); in j1939_ecu_unmap()
104 if (priv->ents[i].ecu) in j1939_ecu_unmap_all()
105 j1939_ecu_unmap_locked(priv->ents[i].ecu); in j1939_ecu_unmap_all()
109 void j1939_ecu_timer_start(struct j1939_ecu *ecu) in j1939_ecu_timer_start() argument
114 j1939_ecu_get(ecu); in j1939_ecu_timer_start()
117 hrtimer_start(&ecu->ac_timer, ms_to_ktime(250), in j1939_ecu_timer_start()
121 void j1939_ecu_timer_cancel(struct j1939_ecu *ecu) in j1939_ecu_timer_cancel() argument
123 if (hrtimer_cancel(&ecu->ac_timer)) in j1939_ecu_timer_cancel()
124 j1939_ecu_put(ecu); in j1939_ecu_timer_cancel()
129 struct j1939_ecu *ecu = in j1939_ecu_timer_handler() local
131 struct j1939_priv *priv = ecu->priv; in j1939_ecu_timer_handler()
137 j1939_ecu_map_locked(ecu); in j1939_ecu_timer_handler()
142 j1939_ecu_put(ecu); in j1939_ecu_timer_handler()
150 struct j1939_ecu *ecu; in j1939_ecu_create_locked() local
154 ecu = kzalloc(sizeof(*ecu), gfp_any()); in j1939_ecu_create_locked()
155 if (!ecu) in j1939_ecu_create_locked()
157 kref_init(&ecu->kref); in j1939_ecu_create_locked()
158 ecu->addr = J1939_IDLE_ADDR; in j1939_ecu_create_locked()
159 ecu->name = name; in j1939_ecu_create_locked()
161 hrtimer_init(&ecu->ac_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_SOFT); in j1939_ecu_create_locked()
162 ecu->ac_timer.function = j1939_ecu_timer_handler; in j1939_ecu_create_locked()
163 INIT_LIST_HEAD(&ecu->list); in j1939_ecu_create_locked()
166 ecu->priv = priv; in j1939_ecu_create_locked()
167 list_add_tail(&ecu->list, &priv->ecus); in j1939_ecu_create_locked()
169 return ecu; in j1939_ecu_create_locked()
177 return priv->ents[addr].ecu; in j1939_ecu_find_by_addr_locked()
182 struct j1939_ecu *ecu; in j1939_ecu_get_by_addr_locked() local
189 ecu = j1939_ecu_find_by_addr_locked(priv, addr); in j1939_ecu_get_by_addr_locked()
190 if (ecu) in j1939_ecu_get_by_addr_locked()
191 j1939_ecu_get(ecu); in j1939_ecu_get_by_addr_locked()
193 return ecu; in j1939_ecu_get_by_addr_locked()
198 struct j1939_ecu *ecu; in j1939_ecu_get_by_addr() local
201 ecu = j1939_ecu_get_by_addr_locked(priv, addr); in j1939_ecu_get_by_addr()
204 return ecu; in j1939_ecu_get_by_addr()
211 struct j1939_ecu *ecu; in j1939_ecu_find_by_name_locked() local
215 list_for_each_entry(ecu, &priv->ecus, list) { in j1939_ecu_find_by_name_locked()
216 if (ecu->name == name) in j1939_ecu_find_by_name_locked()
217 return ecu; in j1939_ecu_find_by_name_locked()
226 struct j1939_ecu *ecu; in j1939_ecu_get_by_name_locked() local
233 ecu = j1939_ecu_find_by_name_locked(priv, name); in j1939_ecu_get_by_name_locked()
234 if (ecu) in j1939_ecu_get_by_name_locked()
235 j1939_ecu_get(ecu); in j1939_ecu_get_by_name_locked()
237 return ecu; in j1939_ecu_get_by_name_locked()
242 struct j1939_ecu *ecu; in j1939_ecu_get_by_name() local
245 ecu = j1939_ecu_get_by_name_locked(priv, name); in j1939_ecu_get_by_name()
248 return ecu; in j1939_ecu_get_by_name()
253 struct j1939_ecu *ecu; in j1939_name_to_addr() local
260 ecu = j1939_ecu_find_by_name_locked(priv, name); in j1939_name_to_addr()
261 if (ecu && j1939_ecu_is_mapped_locked(ecu)) in j1939_name_to_addr()
263 addr = ecu->addr; in j1939_name_to_addr()
278 struct j1939_ecu *ecu; in j1939_local_ecu_get() local
289 ecu = j1939_ecu_get_by_name_locked(priv, name); in j1939_local_ecu_get()
290 if (!ecu) in j1939_local_ecu_get()
291 ecu = j1939_ecu_create_locked(priv, name); in j1939_local_ecu_get()
292 err = PTR_ERR_OR_ZERO(ecu); in j1939_local_ecu_get()
296 ecu->nusers++; in j1939_local_ecu_get()
298 if (j1939_ecu_is_mapped_locked(ecu)) in j1939_local_ecu_get()
300 priv->ents[ecu->addr].nusers++; in j1939_local_ecu_get()
310 struct j1939_ecu *ecu; in j1939_local_ecu_put() local
320 ecu = j1939_ecu_find_by_name_locked(priv, name); in j1939_local_ecu_put()
321 if (WARN_ON_ONCE(!ecu)) in j1939_local_ecu_put()
324 ecu->nusers--; in j1939_local_ecu_put()
326 if (j1939_ecu_is_mapped_locked(ecu)) in j1939_local_ecu_put()
328 priv->ents[ecu->addr].nusers--; in j1939_local_ecu_put()
329 j1939_ecu_put(ecu); in j1939_local_ecu_put()