The branch main has been updated by imp:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=5ecf95544907c2ed318486ac24af3e105ec2701b

commit 5ecf95544907c2ed318486ac24af3e105ec2701b
Author:     Warner Losh <i...@freebsd.org>
AuthorDate: 2025-06-19 14:01:12 +0000
Commit:     Warner Losh <i...@freebsd.org>
CommitDate: 2025-06-19 15:52:25 +0000

    pass: Use pointer to ccb header rather than longer construct
    
    Take a pointer to the ccb header in a few places where it's not
    ambiguous (eg we have multiple ccbs in the routine). The code is a
    little shorter this way. In places we had mulitple ccbs, I refrained
    from doing this since that's more complex to manage. This also means
    that we're making a stronger guarantee to the compiler we're only
    accessing this part of the ccb, which reduces a few warnings from gcc
    with picky settings we normally disable for CAM).
    
    This makes the driver slightly less SCSI specific where csio was used to
    do this needlessly.
    
    There's no functional change.
    
    Sponsored by:           Netflix
---
 sys/cam/scsi/scsi_pass.c | 48 ++++++++++++++++++++++++++----------------------
 1 file changed, 26 insertions(+), 22 deletions(-)

diff --git a/sys/cam/scsi/scsi_pass.c b/sys/cam/scsi/scsi_pass.c
index a6787be8737f..7bf9fa72b245 100644
--- a/sys/cam/scsi/scsi_pass.c
+++ b/sys/cam/scsi/scsi_pass.c
@@ -896,23 +896,23 @@ static void
 passdone(struct cam_periph *periph, union ccb *done_ccb)
 { 
        struct pass_softc *softc;
-       struct ccb_scsiio *csio;
+       struct ccb_hdr *hdr;
 
        softc = (struct pass_softc *)periph->softc;
 
        cam_periph_assert(periph, MA_OWNED);
 
-       csio = &done_ccb->csio;
-       switch (csio->ccb_h.ccb_type) {
+       hdr = &done_ccb->ccb_h;
+       switch (hdr->ccb_type) {
        case PASS_CCB_QUEUED_IO: {
                struct pass_io_req *io_req;
 
-               io_req = done_ccb->ccb_h.ccb_ioreq;
+               io_req = hdr->ccb_ioreq;
 #if 0
                xpt_print(periph->path, "%s: called for user CCB %p\n",
                          __func__, io_req->user_ccb_ptr);
 #endif
-               if (((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) 
&&
+               if (((hdr->status & CAM_STATUS_MASK) != CAM_REQ_CMP) &&
                    ((io_req->flags & PASS_IO_ABANDONED) == 0)) {
                        int error;
                        uint32_t cam_flags, sense_flags;
@@ -936,14 +936,14 @@ passdone(struct cam_periph *periph, union ccb *done_ccb)
                /*
                 * Log data/transaction completion with devstat(9).
                 */
-               switch (done_ccb->ccb_h.func_code) {
+               switch (hdr->func_code) {
                case XPT_SCSI_IO:
                        devstat_end_transaction(softc->device_stats,
                            done_ccb->csio.dxfer_len - done_ccb->csio.resid,
                            done_ccb->csio.tag_action & 0x3,
-                           ((done_ccb->ccb_h.flags & CAM_DIR_MASK) ==
+                           ((hdr->flags & CAM_DIR_MASK) ==
                            CAM_DIR_NONE) ? DEVSTAT_NO_DATA :
-                           (done_ccb->ccb_h.flags & CAM_DIR_OUT) ?
+                           (hdr->flags & CAM_DIR_OUT) ?
                            DEVSTAT_WRITE : DEVSTAT_READ, NULL,
                            &io_req->start_time);
                        break;
@@ -951,9 +951,9 @@ passdone(struct cam_periph *periph, union ccb *done_ccb)
                        devstat_end_transaction(softc->device_stats,
                            done_ccb->ataio.dxfer_len - done_ccb->ataio.resid,
                            0, /* Not used in ATA */
-                           ((done_ccb->ccb_h.flags & CAM_DIR_MASK) ==
+                           ((hdr->flags & CAM_DIR_MASK) ==
                            CAM_DIR_NONE) ? DEVSTAT_NO_DATA : 
-                           (done_ccb->ccb_h.flags & CAM_DIR_OUT) ?
+                           (hdr->flags & CAM_DIR_OUT) ?
                            DEVSTAT_WRITE : DEVSTAT_READ, NULL,
                            &io_req->start_time);
                        break;
@@ -1118,12 +1118,14 @@ static void
 passiocleanup(struct pass_softc *softc, struct pass_io_req *io_req)
 {
        union ccb *ccb;
+       struct ccb_hdr *hdr;
        uint8_t **data_ptrs[CAM_PERIPH_MAXMAPS];
        int i, numbufs;
 
        ccb = &io_req->ccb;
+       hdr = &ccb->ccb_h;
 
-       switch (ccb->ccb_h.func_code) {
+       switch (hdr->func_code) {
        case XPT_DEV_MATCH:
                numbufs = min(io_req->num_bufs, 2);
 
@@ -1279,6 +1281,7 @@ static int
 passmemsetup(struct cam_periph *periph, struct pass_io_req *io_req)
 {
        union ccb *ccb;
+       struct ccb_hdr *hdr;
        struct pass_softc *softc;
        int numbufs, i;
        uint8_t **data_ptrs[CAM_PERIPH_MAXMAPS];
@@ -1295,11 +1298,12 @@ passmemsetup(struct cam_periph *periph, struct 
pass_io_req *io_req)
 
        error = 0;
        ccb = &io_req->ccb;
+       hdr = &ccb->ccb_h;
        maxmap = 0;
        num_segs = 0;
        seg_cnt_ptr = NULL;
 
-       switch(ccb->ccb_h.func_code) {
+       switch(hdr->func_code) {
        case XPT_DEV_MATCH:
                if (ccb->cdm.match_buf_len == 0) {
                        printf("%s: invalid match buffer length 0\n", __func__);
@@ -1323,40 +1327,40 @@ passmemsetup(struct cam_periph *periph, struct 
pass_io_req *io_req)
                break;
        case XPT_SCSI_IO:
        case XPT_CONT_TARGET_IO:
-               if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_NONE)
+               if ((hdr->flags & CAM_DIR_MASK) == CAM_DIR_NONE)
                        return(0);
 
                /*
                 * The user shouldn't be able to supply a bio.
                 */
-               if ((ccb->ccb_h.flags & CAM_DATA_MASK) == CAM_DATA_BIO)
+               if ((hdr->flags & CAM_DATA_MASK) == CAM_DATA_BIO)
                        return (EINVAL);
 
-               io_req->data_flags = ccb->ccb_h.flags & CAM_DATA_MASK;
+               io_req->data_flags = hdr->flags & CAM_DATA_MASK;
 
                data_ptrs[0] = &ccb->csio.data_ptr;
                lengths[0] = ccb->csio.dxfer_len;
-               dirs[0] = ccb->ccb_h.flags & CAM_DIR_MASK;
+               dirs[0] = hdr->flags & CAM_DIR_MASK;
                num_segs = ccb->csio.sglist_cnt;
                seg_cnt_ptr = &ccb->csio.sglist_cnt;
                numbufs = 1;
                maxmap = softc->maxio;
                break;
        case XPT_ATA_IO:
-               if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_NONE)
+               if ((hdr->flags & CAM_DIR_MASK) == CAM_DIR_NONE)
                        return(0);
 
                /*
                 * We only support a single virtual address for ATA I/O.
                 */
-               if ((ccb->ccb_h.flags & CAM_DATA_MASK) != CAM_DATA_VADDR)
+               if ((hdr->flags & CAM_DATA_MASK) != CAM_DATA_VADDR)
                        return (EINVAL);
 
                io_req->data_flags = CAM_DATA_VADDR;
 
                data_ptrs[0] = &ccb->ataio.data_ptr;
                lengths[0] = ccb->ataio.dxfer_len;
-               dirs[0] = ccb->ccb_h.flags & CAM_DIR_MASK;
+               dirs[0] = hdr->flags & CAM_DIR_MASK;
                numbufs = 1;
                maxmap = softc->maxio;
                break;
@@ -1385,14 +1389,14 @@ passmemsetup(struct cam_periph *periph, struct 
pass_io_req *io_req)
                break;
        case XPT_NVME_ADMIN:
        case XPT_NVME_IO:
-               if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_NONE)
+               if ((hdr->flags & CAM_DIR_MASK) == CAM_DIR_NONE)
                        return (0);
 
-               io_req->data_flags = ccb->ccb_h.flags & CAM_DATA_MASK;
+               io_req->data_flags = hdr->flags & CAM_DATA_MASK;
 
                data_ptrs[0] = &ccb->nvmeio.data_ptr;
                lengths[0] = ccb->nvmeio.dxfer_len;
-               dirs[0] = ccb->ccb_h.flags & CAM_DIR_MASK;
+               dirs[0] = hdr->flags & CAM_DIR_MASK;
                num_segs = ccb->nvmeio.sglist_cnt;
                seg_cnt_ptr = &ccb->nvmeio.sglist_cnt;
                numbufs = 1;

Reply via email to