Deleted Added
full compact
scsi_sg.c (288420) scsi_sg.c (293350)
1/*-
2 * Copyright (c) 2007 Scott Long
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 16 unchanged lines hidden (view full) ---

25 */
26
27/*
28 * scsi_sg peripheral driver. This driver is meant to implement the Linux
29 * SG passthrough interface for SCSI.
30 */
31
32#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2007 Scott Long
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 16 unchanged lines hidden (view full) ---

25 */
26
27/*
28 * scsi_sg peripheral driver. This driver is meant to implement the Linux
29 * SG passthrough interface for SCSI.
30 */
31
32#include <sys/cdefs.h>
33__FBSDID("$FreeBSD: head/sys/cam/scsi/scsi_sg.c 288420 2015-09-30 13:31:37Z mav $");
33__FBSDID("$FreeBSD: head/sys/cam/scsi/scsi_sg.c 293350 2016-01-07 20:22:55Z kib $");
34
35#include <sys/param.h>
36#include <sys/systm.h>
37#include <sys/kernel.h>
38#include <sys/types.h>
39#include <sys/bio.h>
40#include <sys/malloc.h>
41#include <sys/fcntl.h>

--- 253 unchanged lines hidden (view full) ---

295}
296
297static cam_status
298sgregister(struct cam_periph *periph, void *arg)
299{
300 struct sg_softc *softc;
301 struct ccb_getdev *cgd;
302 struct ccb_pathinq cpi;
34
35#include <sys/param.h>
36#include <sys/systm.h>
37#include <sys/kernel.h>
38#include <sys/types.h>
39#include <sys/bio.h>
40#include <sys/malloc.h>
41#include <sys/fcntl.h>

--- 253 unchanged lines hidden (view full) ---

295}
296
297static cam_status
298sgregister(struct cam_periph *periph, void *arg)
299{
300 struct sg_softc *softc;
301 struct ccb_getdev *cgd;
302 struct ccb_pathinq cpi;
303 int no_tags;
303 struct make_dev_args args;
304 int no_tags, error;
304
305 cgd = (struct ccb_getdev *)arg;
306 if (cgd == NULL) {
307 printf("sgregister: no getdev CCB, can't register device\n");
308 return (CAM_REQ_CMP_ERR);
309 }
310
311 softc = malloc(sizeof(*softc), M_DEVBUF, M_ZERO | M_NOWAIT);

--- 44 unchanged lines hidden (view full) ---

356 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
357 xpt_print(periph->path, "%s: lost periph during "
358 "registration!\n", __func__);
359 cam_periph_lock(periph);
360 return (CAM_REQ_CMP_ERR);
361 }
362
363 /* Register the device */
305
306 cgd = (struct ccb_getdev *)arg;
307 if (cgd == NULL) {
308 printf("sgregister: no getdev CCB, can't register device\n");
309 return (CAM_REQ_CMP_ERR);
310 }
311
312 softc = malloc(sizeof(*softc), M_DEVBUF, M_ZERO | M_NOWAIT);

--- 44 unchanged lines hidden (view full) ---

357 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
358 xpt_print(periph->path, "%s: lost periph during "
359 "registration!\n", __func__);
360 cam_periph_lock(periph);
361 return (CAM_REQ_CMP_ERR);
362 }
363
364 /* Register the device */
364 softc->dev = make_dev(&sg_cdevsw, periph->unit_number,
365 UID_ROOT, GID_OPERATOR, 0600, "%s%d",
366 periph->periph_name, periph->unit_number);
365 make_dev_args_init(&args);
366 args.mda_devsw = &sg_cdevsw;
367 args.mda_unit = periph->unit_number;
368 args.mda_uid = UID_ROOT;
369 args.mda_gid = GID_OPERATOR;
370 args.mda_mode = 0600;
371 args.mda_si_drv1 = periph;
372 error = make_dev_s(&args, &softc->dev, "%s%d",
373 periph->periph_name, periph->unit_number);
374 if (error != 0) {
375 cam_periph_lock(periph);
376 cam_periph_release_locked(periph);
377 return (CAM_REQ_CMP_ERR);
378 }
367 if (periph->unit_number < 26) {
368 (void)make_dev_alias(softc->dev, "sg%c",
369 periph->unit_number + 'a');
370 } else {
371 (void)make_dev_alias(softc->dev, "sg%c%c",
372 ((periph->unit_number / 26) - 1) + 'a',
373 (periph->unit_number % 26) + 'a');
374 }
375 cam_periph_lock(periph);
379 if (periph->unit_number < 26) {
380 (void)make_dev_alias(softc->dev, "sg%c",
381 periph->unit_number + 'a');
382 } else {
383 (void)make_dev_alias(softc->dev, "sg%c%c",
384 ((periph->unit_number / 26) - 1) + 'a',
385 (periph->unit_number % 26) + 'a');
386 }
387 cam_periph_lock(periph);
376 softc->dev->si_drv1 = periph;
377
378 /*
379 * Add as async callback so that we get
380 * notified if this device goes away.
381 */
382 xpt_register_async(AC_LOST_DEVICE, sgasync, periph, periph->path);
383
384 if (bootverbose)

--- 39 unchanged lines hidden (view full) ---

424static int
425sgopen(struct cdev *dev, int flags, int fmt, struct thread *td)
426{
427 struct cam_periph *periph;
428 struct sg_softc *softc;
429 int error = 0;
430
431 periph = (struct cam_periph *)dev->si_drv1;
388
389 /*
390 * Add as async callback so that we get
391 * notified if this device goes away.
392 */
393 xpt_register_async(AC_LOST_DEVICE, sgasync, periph, periph->path);
394
395 if (bootverbose)

--- 39 unchanged lines hidden (view full) ---

435static int
436sgopen(struct cdev *dev, int flags, int fmt, struct thread *td)
437{
438 struct cam_periph *periph;
439 struct sg_softc *softc;
440 int error = 0;
441
442 periph = (struct cam_periph *)dev->si_drv1;
432 if (periph == NULL)
433 return (ENXIO);
434
435 if (cam_periph_acquire(periph) != CAM_REQ_CMP)
436 return (ENXIO);
437
438 /*
439 * Don't allow access when we're running at a high securelevel.
440 */
441 error = securelevel_gt(td->td_ucred, 1);
442 if (error) {

--- 20 unchanged lines hidden (view full) ---

463static int
464sgclose(struct cdev *dev, int flag, int fmt, struct thread *td)
465{
466 struct cam_periph *periph;
467 struct sg_softc *softc;
468 struct mtx *mtx;
469
470 periph = (struct cam_periph *)dev->si_drv1;
443 if (cam_periph_acquire(periph) != CAM_REQ_CMP)
444 return (ENXIO);
445
446 /*
447 * Don't allow access when we're running at a high securelevel.
448 */
449 error = securelevel_gt(td->td_ucred, 1);
450 if (error) {

--- 20 unchanged lines hidden (view full) ---

471static int
472sgclose(struct cdev *dev, int flag, int fmt, struct thread *td)
473{
474 struct cam_periph *periph;
475 struct sg_softc *softc;
476 struct mtx *mtx;
477
478 periph = (struct cam_periph *)dev->si_drv1;
471 if (periph == NULL)
472 return (ENXIO);
473 mtx = cam_periph_mtx(periph);
474 mtx_lock(mtx);
475
476 softc = periph->softc;
477 softc->open_count--;
478
479 cam_periph_release_locked(periph);
480

--- 20 unchanged lines hidden (view full) ---

501 union ccb *ccb;
502 struct ccb_scsiio *csio;
503 struct cam_periph *periph;
504 struct sg_softc *softc;
505 struct sg_io_hdr *req;
506 int dir, error;
507
508 periph = (struct cam_periph *)dev->si_drv1;
479 mtx = cam_periph_mtx(periph);
480 mtx_lock(mtx);
481
482 softc = periph->softc;
483 softc->open_count--;
484
485 cam_periph_release_locked(periph);
486

--- 20 unchanged lines hidden (view full) ---

507 union ccb *ccb;
508 struct ccb_scsiio *csio;
509 struct cam_periph *periph;
510 struct sg_softc *softc;
511 struct sg_io_hdr *req;
512 int dir, error;
513
514 periph = (struct cam_periph *)dev->si_drv1;
509 if (periph == NULL)
510 return (ENXIO);
511
512 cam_periph_lock(periph);
513
514 softc = (struct sg_softc *)periph->softc;
515 error = 0;
516
517 switch (cmd) {
518 case SG_GET_VERSION_NUM:
519 {

--- 496 unchanged lines hidden ---
515 cam_periph_lock(periph);
516
517 softc = (struct sg_softc *)periph->softc;
518 error = 0;
519
520 switch (cmd) {
521 case SG_GET_VERSION_NUM:
522 {

--- 496 unchanged lines hidden ---