Deleted Added
sdiff udiff text old ( 288420 ) new ( 293350 )
full compact
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 $");
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;
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 */
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);
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);
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;
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;
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;
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 ---