Lines Matching refs:bd
26 #define bsg_dbg(bd, fmt, ...) \ argument
27 pr_debug("%s: " fmt, (bd)->name, ##__VA_ARGS__)
198 struct bsg_device *bd; in bsg_alloc_device() local
200 bd = kzalloc(sizeof(struct bsg_device), GFP_KERNEL); in bsg_alloc_device()
201 if (unlikely(!bd)) in bsg_alloc_device()
204 spin_lock_init(&bd->lock); in bsg_alloc_device()
205 bd->max_queue = BSG_DEFAULT_CMDS; in bsg_alloc_device()
206 INIT_HLIST_NODE(&bd->dev_list); in bsg_alloc_device()
207 return bd; in bsg_alloc_device()
210 static int bsg_put_device(struct bsg_device *bd) in bsg_put_device() argument
212 struct request_queue *q = bd->queue; in bsg_put_device()
216 if (!refcount_dec_and_test(&bd->ref_count)) { in bsg_put_device()
221 hlist_del(&bd->dev_list); in bsg_put_device()
224 bsg_dbg(bd, "tearing down\n"); in bsg_put_device()
229 kfree(bd); in bsg_put_device()
238 struct bsg_device *bd; in bsg_add_device() local
246 bd = bsg_alloc_device(); in bsg_add_device()
247 if (!bd) { in bsg_add_device()
252 bd->queue = rq; in bsg_add_device()
254 refcount_set(&bd->ref_count, 1); in bsg_add_device()
255 hlist_add_head(&bd->dev_list, bsg_dev_idx_hash(iminor(inode))); in bsg_add_device()
257 strncpy(bd->name, dev_name(rq->bsg_dev.class_dev), sizeof(bd->name) - 1); in bsg_add_device()
258 bsg_dbg(bd, "bound to <%s>, max queue %d\n", in bsg_add_device()
259 format_dev_t(buf, inode->i_rdev), bd->max_queue); in bsg_add_device()
261 return bd; in bsg_add_device()
266 struct bsg_device *bd; in __bsg_get_device() local
270 hlist_for_each_entry(bd, bsg_dev_idx_hash(minor), dev_list) { in __bsg_get_device()
271 if (bd->queue == q) { in __bsg_get_device()
272 refcount_inc(&bd->ref_count); in __bsg_get_device()
276 bd = NULL; in __bsg_get_device()
278 return bd; in __bsg_get_device()
283 struct bsg_device *bd; in bsg_get_device() local
293 bd = ERR_PTR(-ENODEV); in bsg_get_device()
297 bd = __bsg_get_device(iminor(inode), bcd->queue); in bsg_get_device()
298 if (!bd) in bsg_get_device()
299 bd = bsg_add_device(inode, bcd->queue, file); in bsg_get_device()
303 return bd; in bsg_get_device()
308 struct bsg_device *bd; in bsg_open() local
310 bd = bsg_get_device(inode, file); in bsg_open()
312 if (IS_ERR(bd)) in bsg_open()
313 return PTR_ERR(bd); in bsg_open()
315 file->private_data = bd; in bsg_open()
321 struct bsg_device *bd = file->private_data; in bsg_release() local
324 return bsg_put_device(bd); in bsg_release()
327 static int bsg_get_command_q(struct bsg_device *bd, int __user *uarg) in bsg_get_command_q() argument
329 return put_user(bd->max_queue, uarg); in bsg_get_command_q()
332 static int bsg_set_command_q(struct bsg_device *bd, int __user *uarg) in bsg_set_command_q() argument
341 spin_lock_irq(&bd->lock); in bsg_set_command_q()
342 bd->max_queue = queue; in bsg_set_command_q()
343 spin_unlock_irq(&bd->lock); in bsg_set_command_q()
349 struct bsg_device *bd = file->private_data; in bsg_ioctl() local
357 return bsg_get_command_q(bd, uarg); in bsg_ioctl()
359 return bsg_set_command_q(bd, uarg); in bsg_ioctl()
373 return scsi_cmd_ioctl(bd->queue, NULL, file->f_mode, cmd, uarg); in bsg_ioctl()
375 return bsg_sg_io(bd->queue, file->f_mode, uarg); in bsg_ioctl()