Lines Matching +full:sense +full:- +full:mode
1 // SPDX-License-Identifier: GPL-2.0
58 return jiffies_to_clock_t(q->sg_timeout); in sg_get_timeout()
66 q->sg_timeout = clock_t_to_jiffies(timeout); in sg_set_timeout()
82 int val = min_t(int, q->sg_reserved_size, max_sectors_bytes(q)); in sg_get_reserved_size()
95 return -EINVAL; in sg_set_reserved_size()
97 q->sg_reserved_size = min(size, max_sectors_bytes(q)); in sg_set_reserved_size()
112 /* Basic read-only commands */ in blk_set_cmd_filter_defaults()
113 __set_bit(TEST_UNIT_READY, filter->read_ok); in blk_set_cmd_filter_defaults()
114 __set_bit(REQUEST_SENSE, filter->read_ok); in blk_set_cmd_filter_defaults()
115 __set_bit(READ_6, filter->read_ok); in blk_set_cmd_filter_defaults()
116 __set_bit(READ_10, filter->read_ok); in blk_set_cmd_filter_defaults()
117 __set_bit(READ_12, filter->read_ok); in blk_set_cmd_filter_defaults()
118 __set_bit(READ_16, filter->read_ok); in blk_set_cmd_filter_defaults()
119 __set_bit(READ_BUFFER, filter->read_ok); in blk_set_cmd_filter_defaults()
120 __set_bit(READ_DEFECT_DATA, filter->read_ok); in blk_set_cmd_filter_defaults()
121 __set_bit(READ_CAPACITY, filter->read_ok); in blk_set_cmd_filter_defaults()
122 __set_bit(READ_LONG, filter->read_ok); in blk_set_cmd_filter_defaults()
123 __set_bit(INQUIRY, filter->read_ok); in blk_set_cmd_filter_defaults()
124 __set_bit(MODE_SENSE, filter->read_ok); in blk_set_cmd_filter_defaults()
125 __set_bit(MODE_SENSE_10, filter->read_ok); in blk_set_cmd_filter_defaults()
126 __set_bit(LOG_SENSE, filter->read_ok); in blk_set_cmd_filter_defaults()
127 __set_bit(START_STOP, filter->read_ok); in blk_set_cmd_filter_defaults()
128 __set_bit(GPCMD_VERIFY_10, filter->read_ok); in blk_set_cmd_filter_defaults()
129 __set_bit(VERIFY_16, filter->read_ok); in blk_set_cmd_filter_defaults()
130 __set_bit(REPORT_LUNS, filter->read_ok); in blk_set_cmd_filter_defaults()
131 __set_bit(SERVICE_ACTION_IN_16, filter->read_ok); in blk_set_cmd_filter_defaults()
132 __set_bit(RECEIVE_DIAGNOSTIC, filter->read_ok); in blk_set_cmd_filter_defaults()
133 __set_bit(MAINTENANCE_IN, filter->read_ok); in blk_set_cmd_filter_defaults()
134 __set_bit(GPCMD_READ_BUFFER_CAPACITY, filter->read_ok); in blk_set_cmd_filter_defaults()
137 __set_bit(GPCMD_PLAY_CD, filter->read_ok); in blk_set_cmd_filter_defaults()
138 __set_bit(GPCMD_PLAY_AUDIO_10, filter->read_ok); in blk_set_cmd_filter_defaults()
139 __set_bit(GPCMD_PLAY_AUDIO_MSF, filter->read_ok); in blk_set_cmd_filter_defaults()
140 __set_bit(GPCMD_PLAY_AUDIO_TI, filter->read_ok); in blk_set_cmd_filter_defaults()
141 __set_bit(GPCMD_PAUSE_RESUME, filter->read_ok); in blk_set_cmd_filter_defaults()
144 __set_bit(GPCMD_READ_CD, filter->read_ok); in blk_set_cmd_filter_defaults()
145 __set_bit(GPCMD_READ_CD_MSF, filter->read_ok); in blk_set_cmd_filter_defaults()
146 __set_bit(GPCMD_READ_DISC_INFO, filter->read_ok); in blk_set_cmd_filter_defaults()
147 __set_bit(GPCMD_READ_CDVD_CAPACITY, filter->read_ok); in blk_set_cmd_filter_defaults()
148 __set_bit(GPCMD_READ_DVD_STRUCTURE, filter->read_ok); in blk_set_cmd_filter_defaults()
149 __set_bit(GPCMD_READ_HEADER, filter->read_ok); in blk_set_cmd_filter_defaults()
150 __set_bit(GPCMD_READ_TRACK_RZONE_INFO, filter->read_ok); in blk_set_cmd_filter_defaults()
151 __set_bit(GPCMD_READ_SUBCHANNEL, filter->read_ok); in blk_set_cmd_filter_defaults()
152 __set_bit(GPCMD_READ_TOC_PMA_ATIP, filter->read_ok); in blk_set_cmd_filter_defaults()
153 __set_bit(GPCMD_REPORT_KEY, filter->read_ok); in blk_set_cmd_filter_defaults()
154 __set_bit(GPCMD_SCAN, filter->read_ok); in blk_set_cmd_filter_defaults()
155 __set_bit(GPCMD_GET_CONFIGURATION, filter->read_ok); in blk_set_cmd_filter_defaults()
156 __set_bit(GPCMD_READ_FORMAT_CAPACITIES, filter->read_ok); in blk_set_cmd_filter_defaults()
157 __set_bit(GPCMD_GET_EVENT_STATUS_NOTIFICATION, filter->read_ok); in blk_set_cmd_filter_defaults()
158 __set_bit(GPCMD_GET_PERFORMANCE, filter->read_ok); in blk_set_cmd_filter_defaults()
159 __set_bit(GPCMD_SEEK, filter->read_ok); in blk_set_cmd_filter_defaults()
160 __set_bit(GPCMD_STOP_PLAY_SCAN, filter->read_ok); in blk_set_cmd_filter_defaults()
163 __set_bit(WRITE_6, filter->write_ok); in blk_set_cmd_filter_defaults()
164 __set_bit(WRITE_10, filter->write_ok); in blk_set_cmd_filter_defaults()
165 __set_bit(WRITE_VERIFY, filter->write_ok); in blk_set_cmd_filter_defaults()
166 __set_bit(WRITE_12, filter->write_ok); in blk_set_cmd_filter_defaults()
167 __set_bit(WRITE_VERIFY_12, filter->write_ok); in blk_set_cmd_filter_defaults()
168 __set_bit(WRITE_16, filter->write_ok); in blk_set_cmd_filter_defaults()
169 __set_bit(WRITE_LONG, filter->write_ok); in blk_set_cmd_filter_defaults()
170 __set_bit(WRITE_LONG_2, filter->write_ok); in blk_set_cmd_filter_defaults()
171 __set_bit(WRITE_SAME, filter->write_ok); in blk_set_cmd_filter_defaults()
172 __set_bit(WRITE_SAME_16, filter->write_ok); in blk_set_cmd_filter_defaults()
173 __set_bit(WRITE_SAME_32, filter->write_ok); in blk_set_cmd_filter_defaults()
174 __set_bit(ERASE, filter->write_ok); in blk_set_cmd_filter_defaults()
175 __set_bit(GPCMD_MODE_SELECT_10, filter->write_ok); in blk_set_cmd_filter_defaults()
176 __set_bit(MODE_SELECT, filter->write_ok); in blk_set_cmd_filter_defaults()
177 __set_bit(LOG_SELECT, filter->write_ok); in blk_set_cmd_filter_defaults()
178 __set_bit(GPCMD_BLANK, filter->write_ok); in blk_set_cmd_filter_defaults()
179 __set_bit(GPCMD_CLOSE_TRACK, filter->write_ok); in blk_set_cmd_filter_defaults()
180 __set_bit(GPCMD_FLUSH_CACHE, filter->write_ok); in blk_set_cmd_filter_defaults()
181 __set_bit(GPCMD_FORMAT_UNIT, filter->write_ok); in blk_set_cmd_filter_defaults()
182 __set_bit(GPCMD_REPAIR_RZONE_TRACK, filter->write_ok); in blk_set_cmd_filter_defaults()
183 __set_bit(GPCMD_RESERVE_RZONE_TRACK, filter->write_ok); in blk_set_cmd_filter_defaults()
184 __set_bit(GPCMD_SEND_DVD_STRUCTURE, filter->write_ok); in blk_set_cmd_filter_defaults()
185 __set_bit(GPCMD_SEND_EVENT, filter->write_ok); in blk_set_cmd_filter_defaults()
186 __set_bit(GPCMD_SEND_KEY, filter->write_ok); in blk_set_cmd_filter_defaults()
187 __set_bit(GPCMD_SEND_OPC, filter->write_ok); in blk_set_cmd_filter_defaults()
188 __set_bit(GPCMD_SEND_CUE_SHEET, filter->write_ok); in blk_set_cmd_filter_defaults()
189 __set_bit(GPCMD_SET_SPEED, filter->write_ok); in blk_set_cmd_filter_defaults()
190 __set_bit(GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL, filter->write_ok); in blk_set_cmd_filter_defaults()
191 __set_bit(GPCMD_LOAD_UNLOAD, filter->write_ok); in blk_set_cmd_filter_defaults()
192 __set_bit(GPCMD_SET_STREAMING, filter->write_ok); in blk_set_cmd_filter_defaults()
193 __set_bit(GPCMD_SET_READ_AHEAD, filter->write_ok); in blk_set_cmd_filter_defaults()
196 __set_bit(ZBC_OUT, filter->write_ok); in blk_set_cmd_filter_defaults()
197 __set_bit(ZBC_IN, filter->read_ok); in blk_set_cmd_filter_defaults()
200 int blk_verify_command(unsigned char *cmd, fmode_t mode) in blk_verify_command() argument
208 /* Anybody who can open the device can do a read-safe command */ in blk_verify_command()
209 if (test_bit(cmd[0], filter->read_ok)) in blk_verify_command()
212 /* Write-safe commands require a writable open */ in blk_verify_command()
213 if (test_bit(cmd[0], filter->write_ok) && (mode & FMODE_WRITE)) in blk_verify_command()
216 return -EPERM; in blk_verify_command()
221 struct sg_io_hdr *hdr, fmode_t mode) in blk_fill_sghdr_rq() argument
225 if (copy_from_user(req->cmd, hdr->cmdp, hdr->cmd_len)) in blk_fill_sghdr_rq()
226 return -EFAULT; in blk_fill_sghdr_rq()
227 if (blk_verify_command(req->cmd, mode)) in blk_fill_sghdr_rq()
228 return -EPERM; in blk_fill_sghdr_rq()
233 req->cmd_len = hdr->cmd_len; in blk_fill_sghdr_rq()
235 rq->timeout = msecs_to_jiffies(hdr->timeout); in blk_fill_sghdr_rq()
236 if (!rq->timeout) in blk_fill_sghdr_rq()
237 rq->timeout = q->sg_timeout; in blk_fill_sghdr_rq()
238 if (!rq->timeout) in blk_fill_sghdr_rq()
239 rq->timeout = BLK_DEFAULT_SG_TIMEOUT; in blk_fill_sghdr_rq()
240 if (rq->timeout < BLK_MIN_SG_TIMEOUT) in blk_fill_sghdr_rq()
241 rq->timeout = BLK_MIN_SG_TIMEOUT; in blk_fill_sghdr_rq()
255 hdr->status = req->result & 0xff; in blk_complete_sghdr_rq()
256 hdr->masked_status = status_byte(req->result); in blk_complete_sghdr_rq()
257 hdr->msg_status = msg_byte(req->result); in blk_complete_sghdr_rq()
258 hdr->host_status = host_byte(req->result); in blk_complete_sghdr_rq()
259 hdr->driver_status = driver_byte(req->result); in blk_complete_sghdr_rq()
260 hdr->info = 0; in blk_complete_sghdr_rq()
261 if (hdr->masked_status || hdr->host_status || hdr->driver_status) in blk_complete_sghdr_rq()
262 hdr->info |= SG_INFO_CHECK; in blk_complete_sghdr_rq()
263 hdr->resid = req->resid_len; in blk_complete_sghdr_rq()
264 hdr->sb_len_wr = 0; in blk_complete_sghdr_rq()
266 if (req->sense_len && hdr->sbp) { in blk_complete_sghdr_rq()
267 int len = min((unsigned int) hdr->mx_sb_len, req->sense_len); in blk_complete_sghdr_rq()
269 if (!copy_to_user(hdr->sbp, req->sense, len)) in blk_complete_sghdr_rq()
270 hdr->sb_len_wr = len; in blk_complete_sghdr_rq()
272 ret = -EFAULT; in blk_complete_sghdr_rq()
283 struct sg_io_hdr *hdr, fmode_t mode) in sg_io() argument
293 if (hdr->interface_id != 'S') in sg_io()
294 return -EINVAL; in sg_io()
296 if (hdr->dxfer_len > (queue_max_hw_sectors(q) << 9)) in sg_io()
297 return -EIO; in sg_io()
299 if (hdr->dxfer_len) in sg_io()
300 switch (hdr->dxfer_direction) { in sg_io()
302 return -EINVAL; in sg_io()
310 if (hdr->flags & SG_FLAG_Q_AT_HEAD) in sg_io()
313 ret = -ENOMEM; in sg_io()
319 if (hdr->cmd_len > BLK_MAX_CDB) { in sg_io()
320 req->cmd = kzalloc(hdr->cmd_len, GFP_KERNEL); in sg_io()
321 if (!req->cmd) in sg_io()
325 ret = blk_fill_sghdr_rq(q, rq, hdr, mode); in sg_io()
330 if (hdr->iovec_count) { in sg_io()
334 ret = import_iovec(rq_data_dir(rq), hdr->dxferp, in sg_io()
335 hdr->iovec_count, 0, &iov, &i); in sg_io()
340 iov_iter_truncate(&i, hdr->dxfer_len); in sg_io()
344 } else if (hdr->dxfer_len) in sg_io()
345 ret = blk_rq_map_user(q, rq, NULL, hdr->dxferp, hdr->dxfer_len, in sg_io()
351 bio = rq->bio; in sg_io()
352 req->retries = 0; in sg_io()
358 * N.B. a non-zero SCSI status is _not_ necessarily an error. in sg_io()
362 hdr->duration = jiffies_to_msecs(jiffies - start_time); in sg_io()
374 * sg_scsi_ioctl -- handle deprecated SCSI_IOCTL_SEND_COMMAND ioctl
377 * @mode: mode used to open the file through which the ioctl has been
382 * the request queue @q. If @file is non-NULL it's used to perform
383 * fine-grained permission checks that allow users to send down
384 * non-destructive SCSI commands. If the caller has a struct gendisk
386 * driver to use the information contained in it. A non-NULL @disk
391 * - This interface is deprecated - users should use the SG_IO
394 * - The SCSI command length is determined by examining the 1st byte
396 * - Data transfers are limited to PAGE_SIZE
397 * - The length (x + y) must be at least OMAX_SB_LEN bytes long to
398 * accommodate the sense buffer when an error occurs.
399 * The sense buffer is truncated to OMAX_SB_LEN (16) bytes so that
401 * - If a Unix error occurs (e.g. ENOMEM) then the user will receive
407 int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode, in sg_scsi_ioctl() argument
418 return -EINVAL; in sg_scsi_ioctl()
423 if (get_user(in_len, &sic->inlen)) in sg_scsi_ioctl()
424 return -EFAULT; in sg_scsi_ioctl()
425 if (get_user(out_len, &sic->outlen)) in sg_scsi_ioctl()
426 return -EFAULT; in sg_scsi_ioctl()
428 return -EINVAL; in sg_scsi_ioctl()
429 if (get_user(opcode, sic->data)) in sg_scsi_ioctl()
430 return -EFAULT; in sg_scsi_ioctl()
434 buffer = kzalloc(bytes, q->bounce_gfp | GFP_USER| __GFP_NOWARN); in sg_scsi_ioctl()
436 return -ENOMEM; in sg_scsi_ioctl()
452 err = -EFAULT; in sg_scsi_ioctl()
453 req->cmd_len = cmdlen; in sg_scsi_ioctl()
454 if (copy_from_user(req->cmd, sic->data, cmdlen)) in sg_scsi_ioctl()
457 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len)) in sg_scsi_ioctl()
460 err = blk_verify_command(req->cmd, mode); in sg_scsi_ioctl()
465 req->retries = 5; in sg_scsi_ioctl()
470 rq->timeout = FORMAT_UNIT_TIMEOUT; in sg_scsi_ioctl()
471 req->retries = 1; in sg_scsi_ioctl()
474 rq->timeout = START_STOP_TIMEOUT; in sg_scsi_ioctl()
477 rq->timeout = MOVE_MEDIUM_TIMEOUT; in sg_scsi_ioctl()
480 rq->timeout = READ_ELEMENT_STATUS_TIMEOUT; in sg_scsi_ioctl()
483 rq->timeout = READ_DEFECT_DATA_TIMEOUT; in sg_scsi_ioctl()
484 req->retries = 1; in sg_scsi_ioctl()
487 rq->timeout = BLK_DEFAULT_SG_TIMEOUT; in sg_scsi_ioctl()
498 err = req->result & 0xff; /* only 8 bit SCSI status */ in sg_scsi_ioctl()
500 if (req->sense_len && req->sense) { in sg_scsi_ioctl()
501 bytes = (OMAX_SB_LEN > req->sense_len) ? in sg_scsi_ioctl()
502 req->sense_len : OMAX_SB_LEN; in sg_scsi_ioctl()
503 if (copy_to_user(sic->data, req->sense, bytes)) in sg_scsi_ioctl()
504 err = -EFAULT; in sg_scsi_ioctl()
507 if (copy_to_user(sic->data, buffer, out_len)) in sg_scsi_ioctl()
508 err = -EFAULT; in sg_scsi_ioctl()
531 rq->timeout = BLK_DEFAULT_SG_TIMEOUT; in __blk_send_generic()
532 scsi_req(rq)->cmd[0] = cmd; in __blk_send_generic()
533 scsi_req(rq)->cmd[4] = data; in __blk_send_generic()
534 scsi_req(rq)->cmd_len = 6; in __blk_send_generic()
536 err = scsi_req(rq)->result ? -EIO : 0; in __blk_send_generic()
553 .interface_id = hdr->interface_id, in put_sg_io_hdr()
554 .dxfer_direction = hdr->dxfer_direction, in put_sg_io_hdr()
555 .cmd_len = hdr->cmd_len, in put_sg_io_hdr()
556 .mx_sb_len = hdr->mx_sb_len, in put_sg_io_hdr()
557 .iovec_count = hdr->iovec_count, in put_sg_io_hdr()
558 .dxfer_len = hdr->dxfer_len, in put_sg_io_hdr()
559 .dxferp = (uintptr_t)hdr->dxferp, in put_sg_io_hdr()
560 .cmdp = (uintptr_t)hdr->cmdp, in put_sg_io_hdr()
561 .sbp = (uintptr_t)hdr->sbp, in put_sg_io_hdr()
562 .timeout = hdr->timeout, in put_sg_io_hdr()
563 .flags = hdr->flags, in put_sg_io_hdr()
564 .pack_id = hdr->pack_id, in put_sg_io_hdr()
565 .usr_ptr = (uintptr_t)hdr->usr_ptr, in put_sg_io_hdr()
566 .status = hdr->status, in put_sg_io_hdr()
567 .masked_status = hdr->masked_status, in put_sg_io_hdr()
568 .msg_status = hdr->msg_status, in put_sg_io_hdr()
569 .sb_len_wr = hdr->sb_len_wr, in put_sg_io_hdr()
570 .host_status = hdr->host_status, in put_sg_io_hdr()
571 .driver_status = hdr->driver_status, in put_sg_io_hdr()
572 .resid = hdr->resid, in put_sg_io_hdr()
573 .duration = hdr->duration, in put_sg_io_hdr()
574 .info = hdr->info, in put_sg_io_hdr()
578 return -EFAULT; in put_sg_io_hdr()
585 return -EFAULT; in put_sg_io_hdr()
598 return -EFAULT; in get_sg_io_hdr()
630 return -EFAULT; in get_sg_io_hdr()
642 compat_caddr_t sense; member
659 return -EFAULT; in scsi_get_cdrom_generic_arg()
665 .sense = compat_ptr(cgc32.sense), in scsi_get_cdrom_generic_arg()
671 memcpy(&cgc->cmd, &cgc32.cmd, CDROM_PACKET_SIZE); in scsi_get_cdrom_generic_arg()
676 return -EFAULT; in scsi_get_cdrom_generic_arg()
687 .buffer = (uintptr_t)(cgc->buffer), in scsi_put_cdrom_generic_arg()
688 .buflen = cgc->buflen, in scsi_put_cdrom_generic_arg()
689 .stat = cgc->stat, in scsi_put_cdrom_generic_arg()
690 .sense = (uintptr_t)(cgc->sense), in scsi_put_cdrom_generic_arg()
691 .data_direction = cgc->data_direction, in scsi_put_cdrom_generic_arg()
692 .quiet = cgc->quiet, in scsi_put_cdrom_generic_arg()
693 .timeout = cgc->timeout, in scsi_put_cdrom_generic_arg()
694 .unused = (uintptr_t)(cgc->unused), in scsi_put_cdrom_generic_arg()
696 memcpy(&cgc32.cmd, &cgc->cmd, CDROM_PACKET_SIZE); in scsi_put_cdrom_generic_arg()
699 return -EFAULT; in scsi_put_cdrom_generic_arg()
705 return -EFAULT; in scsi_put_cdrom_generic_arg()
712 fmode_t mode, void __user *arg) in scsi_cdrom_send_packet() argument
741 return -EINVAL; in scsi_cdrom_send_packet()
745 hdr.sbp = cgc.sense; in scsi_cdrom_send_packet()
749 hdr.cmdp = ((struct cdrom_generic_command __user*) arg)->cmd; in scsi_cdrom_send_packet()
752 err = sg_io(q, bd_disk, &hdr, mode); in scsi_cdrom_send_packet()
753 if (err == -EFAULT) in scsi_cdrom_send_packet()
754 return -EFAULT; in scsi_cdrom_send_packet()
757 return -EIO; in scsi_cdrom_send_packet()
762 return -EFAULT; in scsi_cdrom_send_packet()
767 int scsi_cmd_ioctl(struct request_queue *q, struct gendisk *bd_disk, fmode_t mode, in scsi_cmd_ioctl() argument
773 return -ENXIO; in scsi_cmd_ioctl()
809 err = sg_io(q, bd_disk, &hdr, mode); in scsi_cmd_ioctl()
810 if (err == -EFAULT) in scsi_cmd_ioctl()
814 err = -EFAULT; in scsi_cmd_ioctl()
818 err = scsi_cdrom_send_packet(q, bd_disk, mode, arg); in scsi_cmd_ioctl()
825 …ARNING "program %s is using a deprecated SCSI ioctl, please convert it to SG_IO\n", current->comm); in scsi_cmd_ioctl()
826 err = -EINVAL; in scsi_cmd_ioctl()
830 err = sg_scsi_ioctl(q, bd_disk, mode, arg); in scsi_cmd_ioctl()
839 err = -ENOTTY; in scsi_cmd_ioctl()
854 return -ENOIOCTLCMD; in scsi_verify_blk_ioctl()
858 int scsi_cmd_blk_ioctl(struct block_device *bd, fmode_t mode, in scsi_cmd_blk_ioctl() argument
867 return scsi_cmd_ioctl(bd->bd_disk->queue, bd->bd_disk, mode, cmd, arg); in scsi_cmd_blk_ioctl()
872 * scsi_req_init - initialize certain fields of a scsi_request structure
879 memset(req->__cmd, 0, sizeof(req->__cmd)); in scsi_req_init()
880 req->cmd = req->__cmd; in scsi_req_init()
881 req->cmd_len = BLK_MAX_CDB; in scsi_req_init()
882 req->sense_len = 0; in scsi_req_init()