Lines Matching refs:bd
27 #define bsg_dbg(bd, fmt, ...) \ argument
28 pr_debug("%s: " fmt, (bd)->name, ##__VA_ARGS__)
201 struct bsg_device *bd; in bsg_alloc_device() local
203 bd = kzalloc(sizeof(struct bsg_device), GFP_KERNEL); in bsg_alloc_device()
204 if (unlikely(!bd)) in bsg_alloc_device()
207 spin_lock_init(&bd->lock); in bsg_alloc_device()
208 bd->max_queue = BSG_DEFAULT_CMDS; in bsg_alloc_device()
209 INIT_HLIST_NODE(&bd->dev_list); in bsg_alloc_device()
210 return bd; in bsg_alloc_device()
213 static int bsg_put_device(struct bsg_device *bd) in bsg_put_device() argument
215 struct request_queue *q = bd->queue; in bsg_put_device()
219 if (!refcount_dec_and_test(&bd->ref_count)) { in bsg_put_device()
224 hlist_del(&bd->dev_list); in bsg_put_device()
227 bsg_dbg(bd, "tearing down\n"); in bsg_put_device()
232 kfree(bd); in bsg_put_device()
241 struct bsg_device *bd; in bsg_add_device() local
249 bd = bsg_alloc_device(); in bsg_add_device()
250 if (!bd) { in bsg_add_device()
255 bd->queue = rq; in bsg_add_device()
257 refcount_set(&bd->ref_count, 1); in bsg_add_device()
258 hlist_add_head(&bd->dev_list, bsg_dev_idx_hash(iminor(inode))); in bsg_add_device()
260 strncpy(bd->name, dev_name(rq->bsg_dev.class_dev), sizeof(bd->name) - 1); in bsg_add_device()
261 bsg_dbg(bd, "bound to <%s>, max queue %d\n", in bsg_add_device()
262 format_dev_t(buf, inode->i_rdev), bd->max_queue); in bsg_add_device()
264 return bd; in bsg_add_device()
269 struct bsg_device *bd; in __bsg_get_device() local
273 hlist_for_each_entry(bd, bsg_dev_idx_hash(minor), dev_list) { in __bsg_get_device()
274 if (bd->queue == q) { in __bsg_get_device()
275 refcount_inc(&bd->ref_count); in __bsg_get_device()
279 bd = NULL; in __bsg_get_device()
281 return bd; in __bsg_get_device()
286 struct bsg_device *bd; in bsg_get_device() local
296 bd = ERR_PTR(-ENODEV); in bsg_get_device()
300 bd = __bsg_get_device(iminor(inode), bcd->queue); in bsg_get_device()
301 if (!bd) in bsg_get_device()
302 bd = bsg_add_device(inode, bcd->queue, file); in bsg_get_device()
306 return bd; in bsg_get_device()
311 struct bsg_device *bd; in bsg_open() local
314 bd = bsg_get_device(inode, file); in bsg_open()
316 if (IS_ERR(bd)) in bsg_open()
317 return PTR_ERR(bd); in bsg_open()
319 bcd = &bd->queue->bsg_dev; in bsg_open()
321 file->private_data = bd; in bsg_open()
327 struct bsg_device *bd = file->private_data; in bsg_release() local
332 bcd = &bd->queue->bsg_dev; in bsg_release()
334 return bsg_put_device(bd); in bsg_release()
337 static int bsg_get_command_q(struct bsg_device *bd, int __user *uarg) in bsg_get_command_q() argument
339 return put_user(bd->max_queue, uarg); in bsg_get_command_q()
342 static int bsg_set_command_q(struct bsg_device *bd, int __user *uarg) in bsg_set_command_q() argument
351 spin_lock_irq(&bd->lock); in bsg_set_command_q()
352 bd->max_queue = queue; in bsg_set_command_q()
353 spin_unlock_irq(&bd->lock); in bsg_set_command_q()
359 struct bsg_device *bd = file->private_data; in bsg_ioctl() local
367 return bsg_get_command_q(bd, uarg); in bsg_ioctl()
369 return bsg_set_command_q(bd, uarg); in bsg_ioctl()
382 return scsi_cmd_ioctl(bd->queue, NULL, file->f_mode, cmd, uarg); in bsg_ioctl()
384 return bsg_sg_io(bd->queue, file->f_mode, uarg); in bsg_ioctl()