Lines Matching refs:bd
26 #define bsg_dbg(bd, fmt, ...) \ argument
27 pr_debug("%s: " fmt, (bd)->name, ##__VA_ARGS__)
200 struct bsg_device *bd; in bsg_alloc_device() local
202 bd = kzalloc(sizeof(struct bsg_device), GFP_KERNEL); in bsg_alloc_device()
203 if (unlikely(!bd)) in bsg_alloc_device()
206 spin_lock_init(&bd->lock); in bsg_alloc_device()
207 bd->max_queue = BSG_DEFAULT_CMDS; in bsg_alloc_device()
208 INIT_HLIST_NODE(&bd->dev_list); in bsg_alloc_device()
209 return bd; in bsg_alloc_device()
212 static int bsg_put_device(struct bsg_device *bd) in bsg_put_device() argument
214 struct request_queue *q = bd->queue; in bsg_put_device()
218 if (!refcount_dec_and_test(&bd->ref_count)) { in bsg_put_device()
223 hlist_del(&bd->dev_list); in bsg_put_device()
226 bsg_dbg(bd, "tearing down\n"); in bsg_put_device()
231 kfree(bd); in bsg_put_device()
240 struct bsg_device *bd; in bsg_add_device() local
248 bd = bsg_alloc_device(); in bsg_add_device()
249 if (!bd) { in bsg_add_device()
254 bd->queue = rq; in bsg_add_device()
256 refcount_set(&bd->ref_count, 1); in bsg_add_device()
257 hlist_add_head(&bd->dev_list, bsg_dev_idx_hash(iminor(inode))); in bsg_add_device()
259 strncpy(bd->name, dev_name(rq->bsg_dev.class_dev), sizeof(bd->name) - 1); in bsg_add_device()
260 bsg_dbg(bd, "bound to <%s>, max queue %d\n", in bsg_add_device()
261 format_dev_t(buf, inode->i_rdev), bd->max_queue); in bsg_add_device()
263 return bd; in bsg_add_device()
268 struct bsg_device *bd; in __bsg_get_device() local
272 hlist_for_each_entry(bd, bsg_dev_idx_hash(minor), dev_list) { in __bsg_get_device()
273 if (bd->queue == q) { in __bsg_get_device()
274 refcount_inc(&bd->ref_count); in __bsg_get_device()
278 bd = NULL; in __bsg_get_device()
280 return bd; in __bsg_get_device()
285 struct bsg_device *bd; in bsg_get_device() local
295 bd = ERR_PTR(-ENODEV); in bsg_get_device()
299 bd = __bsg_get_device(iminor(inode), bcd->queue); in bsg_get_device()
300 if (!bd) in bsg_get_device()
301 bd = bsg_add_device(inode, bcd->queue, file); in bsg_get_device()
305 return bd; in bsg_get_device()
310 struct bsg_device *bd; in bsg_open() local
312 bd = bsg_get_device(inode, file); in bsg_open()
314 if (IS_ERR(bd)) in bsg_open()
315 return PTR_ERR(bd); in bsg_open()
317 file->private_data = bd; in bsg_open()
323 struct bsg_device *bd = file->private_data; in bsg_release() local
326 return bsg_put_device(bd); in bsg_release()
329 static int bsg_get_command_q(struct bsg_device *bd, int __user *uarg) in bsg_get_command_q() argument
331 return put_user(bd->max_queue, uarg); in bsg_get_command_q()
334 static int bsg_set_command_q(struct bsg_device *bd, int __user *uarg) in bsg_set_command_q() argument
343 spin_lock_irq(&bd->lock); in bsg_set_command_q()
344 bd->max_queue = queue; in bsg_set_command_q()
345 spin_unlock_irq(&bd->lock); in bsg_set_command_q()
351 struct bsg_device *bd = file->private_data; in bsg_ioctl() local
359 return bsg_get_command_q(bd, uarg); in bsg_ioctl()
361 return bsg_set_command_q(bd, uarg); in bsg_ioctl()
374 return scsi_cmd_ioctl(bd->queue, NULL, file->f_mode, cmd, uarg); in bsg_ioctl()
376 return bsg_sg_io(bd->queue, file->f_mode, uarg); in bsg_ioctl()