Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ide: don't abuse cmd_type

Currently the legacy ide driver defines several request types of it's own,
which is in the way of removing that field entirely.

Instead add a type field to struct ide_request and use that to distinguish
the different types of IDE-internal requests.

It's a bit of a mess, but so is the surrounding code..

Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Jens Axboe <axboe@fb.com>

authored by

Christoph Hellwig and committed by
Jens Axboe
2f5a8e80 57292b58

+117 -51
+12 -6
drivers/ide/ide-atapi.c
··· 95 95 rq = blk_get_request(drive->queue, READ, __GFP_RECLAIM); 96 96 scsi_req_init(rq); 97 97 rq->cmd_type = REQ_TYPE_DRV_PRIV; 98 + ide_req(rq)->type = ATA_PRIV_MISC; 98 99 rq->special = (char *)pc; 99 100 100 101 if (buf && bufflen) { ··· 194 193 195 194 BUG_ON(sense_len > sizeof(*sense)); 196 195 197 - if (rq->cmd_type == REQ_TYPE_ATA_SENSE || drive->sense_rq_armed) 196 + if (ata_sense_request(rq) || drive->sense_rq_armed) 198 197 return; 199 198 200 199 memset(sense, 0, sizeof(*sense)); ··· 212 211 } 213 212 214 213 sense_rq->rq_disk = rq->rq_disk; 215 - sense_rq->cmd_type = REQ_TYPE_ATA_SENSE; 214 + sense_rq->cmd_type = REQ_TYPE_DRV_PRIV; 215 + ide_req(sense_rq)->type = ATA_PRIV_SENSE; 216 216 sense_rq->rq_flags |= RQF_PREEMPT; 217 217 218 218 req->cmd[0] = GPCMD_REQUEST_SENSE; ··· 315 313 switch (rq->cmd_type) { 316 314 case REQ_TYPE_FS: 317 315 return 32768; 318 - case REQ_TYPE_ATA_SENSE: 319 316 case REQ_TYPE_BLOCK_PC: 320 - case REQ_TYPE_ATA_PC: 321 317 return blk_rq_bytes(rq); 318 + case REQ_TYPE_DRV_PRIV: 319 + switch (ide_req(rq)->type) { 320 + case ATA_PRIV_PC: 321 + case ATA_PRIV_SENSE: 322 + return blk_rq_bytes(rq); 323 + } 322 324 default: 323 325 return 0; 324 326 } ··· 383 377 drive->name, __func__, ireason); 384 378 } 385 379 386 - if (dev_is_idecd(drive) && rq->cmd_type == REQ_TYPE_ATA_PC) 380 + if (dev_is_idecd(drive) && ata_pc_request(rq)) 387 381 rq->rq_flags |= RQF_FAILED; 388 382 389 383 return 1; ··· 486 480 if (uptodate == 0) 487 481 drive->failed_pc = NULL; 488 482 489 - if (rq->cmd_type == REQ_TYPE_DRV_PRIV) { 483 + if (ata_misc_request(rq)) { 490 484 rq->errors = 0; 491 485 error = 0; 492 486 } else {
+15 -10
drivers/ide/ide-cd.c
··· 210 210 static void ide_cd_complete_failed_rq(ide_drive_t *drive, struct request *rq) 211 211 { 212 212 /* 213 - * For REQ_TYPE_ATA_SENSE, "rq->special" points to the original 213 + * For ATA_PRIV_SENSE, "rq->special" points to the original 214 214 * failed request. Also, the sense data should be read 215 215 * directly from rq which might be different from the original 216 216 * sense buffer if it got copied during mapping. ··· 282 282 "stat 0x%x", 283 283 rq->cmd[0], rq->cmd_type, err, stat); 284 284 285 - if (rq->cmd_type == REQ_TYPE_ATA_SENSE) { 285 + if (ata_sense_request(rq)) { 286 286 /* 287 287 * We got an error trying to get sense info from the drive 288 288 * (probably while trying to recover from a former error). ··· 438 438 rq = blk_get_request(drive->queue, write, __GFP_RECLAIM); 439 439 scsi_req_init(rq); 440 440 memcpy(scsi_req(rq)->cmd, cmd, BLK_MAX_CDB); 441 - rq->cmd_type = REQ_TYPE_ATA_PC; 441 + rq->cmd_type = REQ_TYPE_DRV_PRIV; 442 + ide_req(rq)->type = ATA_PRIV_PC; 442 443 rq->rq_flags |= rq_flags; 443 444 rq->timeout = timeout; 444 445 if (buffer) { ··· 521 520 ide_expiry_t *expiry = NULL; 522 521 int dma_error = 0, dma, thislen, uptodate = 0; 523 522 int write = (rq_data_dir(rq) == WRITE) ? 1 : 0, rc = 0; 524 - int sense = (rq->cmd_type == REQ_TYPE_ATA_SENSE); 523 + int sense = ata_sense_request(rq); 525 524 unsigned int timeout; 526 525 u16 len; 527 526 u8 ireason, stat; ··· 786 785 if (cdrom_start_rw(drive, rq) == ide_stopped) 787 786 goto out_end; 788 787 break; 789 - case REQ_TYPE_ATA_SENSE: 790 788 case REQ_TYPE_BLOCK_PC: 791 - case REQ_TYPE_ATA_PC: 789 + handle_pc: 792 790 if (!rq->timeout) 793 791 rq->timeout = ATAPI_WAIT_PC; 794 - 795 792 cdrom_do_block_pc(drive, rq); 796 793 break; 797 794 case REQ_TYPE_DRV_PRIV: 798 - /* right now this can only be a reset... */ 799 - uptodate = 1; 800 - goto out_end; 795 + switch (ide_req(rq)->type) { 796 + case ATA_PRIV_MISC: 797 + /* right now this can only be a reset... */ 798 + uptodate = 1; 799 + goto out_end; 800 + case ATA_PRIV_SENSE: 801 + case ATA_PRIV_PC: 802 + goto handle_pc; 803 + } 801 804 default: 802 805 BUG(); 803 806 }
+1
drivers/ide/ide-cd_ioctl.c
··· 306 306 rq = blk_get_request(drive->queue, READ, __GFP_RECLAIM); 307 307 scsi_req_init(rq); 308 308 rq->cmd_type = REQ_TYPE_DRV_PRIV; 309 + ide_req(rq)->type = ATA_PRIV_MISC; 309 310 rq->rq_flags = RQF_QUIET; 310 311 ret = blk_execute_rq(drive->queue, cd->disk, rq, 0); 311 312 blk_put_request(rq);
+1
drivers/ide/ide-devsets.c
··· 168 168 rq = blk_get_request(q, READ, __GFP_RECLAIM); 169 169 scsi_req_init(rq); 170 170 rq->cmd_type = REQ_TYPE_DRV_PRIV; 171 + ide_req(rq)->type = ATA_PRIV_MISC; 171 172 scsi_req(rq)->cmd_len = 5; 172 173 scsi_req(rq)->cmd[0] = REQ_DEVSET_EXEC; 173 174 *(int *)&scsi_req(rq)->cmd[1] = arg;
+4 -2
drivers/ide/ide-disk.c
··· 453 453 cmd->tf_flags = IDE_TFLAG_DYN; 454 454 cmd->protocol = ATA_PROT_NODATA; 455 455 456 - rq->cmd_type = REQ_TYPE_ATA_TASKFILE; 456 + rq->cmd_type = REQ_TYPE_DRV_PRIV; 457 + ide_req(rq)->type = ATA_PRIV_TASKFILE; 457 458 rq->special = cmd; 458 459 cmd->rq = rq; 459 460 ··· 480 479 481 480 rq = blk_get_request(drive->queue, READ, __GFP_RECLAIM); 482 481 scsi_req_init(rq); 483 - rq->cmd_type = REQ_TYPE_ATA_TASKFILE; 482 + rq->cmd_type = REQ_TYPE_DRV_PRIV; 483 + ide_req(rq)->type = ATA_PRIV_TASKFILE; 484 484 485 485 drive->mult_req = arg; 486 486 drive->special_flags |= IDE_SFLAG_SET_MULTMODE;
+2 -2
drivers/ide/ide-eh.c
··· 124 124 125 125 /* retry only "normal" I/O: */ 126 126 if (rq->cmd_type != REQ_TYPE_FS) { 127 - if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) { 127 + if (ata_taskfile_request(rq)) { 128 128 struct ide_cmd *cmd = rq->special; 129 129 130 130 if (cmd) ··· 147 147 { 148 148 struct request *rq = drive->hwif->rq; 149 149 150 - if (rq && rq->cmd_type == REQ_TYPE_DRV_PRIV && 150 + if (rq && ata_misc_request(rq) && 151 151 scsi_req(rq)->cmd[0] == REQ_DRIVE_RESET) { 152 152 if (err <= 0 && rq->errors == 0) 153 153 rq->errors = -EIO;
+12 -6
drivers/ide/ide-floppy.c
··· 97 97 "Aborting request!\n"); 98 98 } 99 99 100 - if (rq->cmd_type == REQ_TYPE_DRV_PRIV) 100 + if (ata_misc_request(rq)) 101 101 rq->errors = uptodate ? 0 : IDE_DRV_ERROR_GENERAL; 102 102 103 103 return uptodate; ··· 246 246 } else 247 247 printk(KERN_ERR PFX "%s: I/O error\n", drive->name); 248 248 249 - if (rq->cmd_type == REQ_TYPE_DRV_PRIV) { 249 + if (ata_misc_request(rq)) { 250 250 rq->errors = 0; 251 251 ide_complete_rq(drive, 0, blk_rq_bytes(rq)); 252 252 return ide_stopped; ··· 265 265 pc = &floppy->queued_pc; 266 266 idefloppy_create_rw_cmd(drive, pc, rq, (unsigned long)block); 267 267 break; 268 - case REQ_TYPE_DRV_PRIV: 269 - case REQ_TYPE_ATA_SENSE: 270 - pc = (struct ide_atapi_pc *)rq->special; 271 - break; 272 268 case REQ_TYPE_BLOCK_PC: 273 269 pc = &floppy->queued_pc; 274 270 idefloppy_blockpc_cmd(floppy, pc, rq); 271 + break; 272 + case REQ_TYPE_DRV_PRIV: 273 + switch (ide_req(rq)->type) { 274 + case ATA_PRIV_MISC: 275 + case ATA_PRIV_SENSE: 276 + pc = (struct ide_atapi_pc *)rq->special; 277 + break; 278 + default: 279 + BUG(); 280 + } 275 281 break; 276 282 default: 277 283 BUG();
+4 -4
drivers/ide/ide-io.c
··· 102 102 drive->dev_flags |= IDE_DFLAG_PARKED; 103 103 } 104 104 105 - if (rq && rq->cmd_type == REQ_TYPE_ATA_TASKFILE) { 105 + if (rq && ata_taskfile_request(rq)) { 106 106 struct ide_cmd *orig_cmd = rq->special; 107 107 108 108 if (cmd->tf_flags & IDE_TFLAG_DYN) ··· 135 135 136 136 void ide_kill_rq(ide_drive_t *drive, struct request *rq) 137 137 { 138 - u8 drv_req = (rq->cmd_type == REQ_TYPE_DRV_PRIV) && rq->rq_disk; 138 + u8 drv_req = ata_misc_request(rq) && rq->rq_disk; 139 139 u8 media = drive->media; 140 140 141 141 drive->failed_pc = NULL; ··· 340 340 if (drive->current_speed == 0xff) 341 341 ide_config_drive_speed(drive, drive->desired_speed); 342 342 343 - if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) 343 + if (ata_taskfile_request(rq)) 344 344 return execute_drive_cmd(drive, rq); 345 345 else if (ata_pm_request(rq)) { 346 346 struct ide_pm_state *pm = rq->special; ··· 353 353 pm->pm_step == IDE_PM_COMPLETED) 354 354 ide_complete_pm_rq(drive, rq); 355 355 return startstop; 356 - } else if (!rq->rq_disk && rq->cmd_type == REQ_TYPE_DRV_PRIV) 356 + } else if (!rq->rq_disk && ata_misc_request(rq)) 357 357 /* 358 358 * TODO: Once all ULDs have been modified to 359 359 * check for specific op codes rather than
+3 -1
drivers/ide/ide-ioctls.c
··· 127 127 128 128 rq = blk_get_request(drive->queue, READ, __GFP_RECLAIM); 129 129 scsi_req_init(rq); 130 - rq->cmd_type = REQ_TYPE_ATA_TASKFILE; 130 + rq->cmd_type = REQ_TYPE_DRV_PRIV; 131 + ide_req(rq)->type = ATA_PRIV_TASKFILE; 131 132 err = blk_execute_rq(drive->queue, NULL, rq, 0); 132 133 blk_put_request(rq); 133 134 ··· 226 225 rq = blk_get_request(drive->queue, READ, __GFP_RECLAIM); 227 226 scsi_req_init(rq); 228 227 rq->cmd_type = REQ_TYPE_DRV_PRIV; 228 + ide_req(rq)->type = ATA_PRIV_MISC; 229 229 scsi_req(rq)->cmd_len = 1; 230 230 scsi_req(rq)->cmd[0] = REQ_DRIVE_RESET; 231 231 if (blk_execute_rq(drive->queue, NULL, rq, 1))
+2
drivers/ide/ide-park.c
··· 36 36 scsi_req(rq)->cmd[0] = REQ_PARK_HEADS; 37 37 scsi_req(rq)->cmd_len = 1; 38 38 rq->cmd_type = REQ_TYPE_DRV_PRIV; 39 + ide_req(rq)->type = ATA_PRIV_MISC; 39 40 rq->special = &timeout; 40 41 rc = blk_execute_rq(q, NULL, rq, 1); 41 42 blk_put_request(rq); ··· 55 54 scsi_req(rq)->cmd[0] = REQ_UNPARK_HEADS; 56 55 scsi_req(rq)->cmd_len = 1; 57 56 rq->cmd_type = REQ_TYPE_DRV_PRIV; 57 + ide_req(rq)->type = ATA_PRIV_MISC; 58 58 elv_add_request(q, rq, ELEVATOR_INSERT_FRONT); 59 59 60 60 out:
+10 -6
drivers/ide/ide-pm.c
··· 20 20 memset(&rqpm, 0, sizeof(rqpm)); 21 21 rq = blk_get_request(drive->queue, READ, __GFP_RECLAIM); 22 22 scsi_req_init(rq); 23 - rq->cmd_type = REQ_TYPE_ATA_PM_SUSPEND; 23 + rq->cmd_type = REQ_TYPE_DRV_PRIV; 24 + ide_req(rq)->type = ATA_PRIV_PM_SUSPEND; 24 25 rq->special = &rqpm; 25 26 rqpm.pm_step = IDE_PM_START_SUSPEND; 26 27 if (mesg.event == PM_EVENT_PRETHAW) ··· 92 91 memset(&rqpm, 0, sizeof(rqpm)); 93 92 rq = blk_get_request(drive->queue, READ, __GFP_RECLAIM); 94 93 scsi_req_init(rq); 95 - rq->cmd_type = REQ_TYPE_ATA_PM_RESUME; 94 + rq->cmd_type = REQ_TYPE_DRV_PRIV; 95 + ide_req(rq)->type = ATA_PRIV_PM_RESUME; 96 96 rq->rq_flags |= RQF_PREEMPT; 97 97 rq->special = &rqpm; 98 98 rqpm.pm_step = IDE_PM_START_RESUME; ··· 225 223 226 224 #ifdef DEBUG_PM 227 225 printk("%s: completing PM request, %s\n", drive->name, 228 - (rq->cmd_type == REQ_TYPE_ATA_PM_SUSPEND) ? "suspend" : "resume"); 226 + (ide_req(rq)->type == ATA_PRIV_PM_SUSPEND) ? "suspend" : "resume"); 229 227 #endif 230 228 spin_lock_irqsave(q->queue_lock, flags); 231 - if (rq->cmd_type == REQ_TYPE_ATA_PM_SUSPEND) 229 + if (ide_req(rq)->type == ATA_PRIV_PM_SUSPEND) 232 230 blk_stop_queue(q); 233 231 else 234 232 drive->dev_flags &= ~IDE_DFLAG_BLOCKED; ··· 244 242 { 245 243 struct ide_pm_state *pm = rq->special; 246 244 247 - if (rq->cmd_type == REQ_TYPE_ATA_PM_SUSPEND && 245 + if (rq->cmd_type == REQ_TYPE_DRV_PRIV && 246 + ide_req(rq)->type == ATA_PRIV_PM_SUSPEND && 248 247 pm->pm_step == IDE_PM_START_SUSPEND) 249 248 /* Mark drive blocked when starting the suspend sequence. */ 250 249 drive->dev_flags |= IDE_DFLAG_BLOCKED; 251 - else if (rq->cmd_type == REQ_TYPE_ATA_PM_RESUME && 250 + else if (rq->cmd_type == REQ_TYPE_DRV_PRIV && 251 + ide_req(rq)->type == ATA_PRIV_PM_RESUME && 252 252 pm->pm_step == IDE_PM_START_RESUME) { 253 253 /* 254 254 * The first thing we do on wakeup is to wait for BSY bit to
+4 -2
drivers/ide/ide-tape.c
··· 577 577 req->cmd[0], (unsigned long long)blk_rq_pos(rq), 578 578 blk_rq_sectors(rq)); 579 579 580 - BUG_ON(!(rq->cmd_type == REQ_TYPE_DRV_PRIV || 581 - rq->cmd_type == REQ_TYPE_ATA_SENSE)); 580 + BUG_ON(rq->cmd_type != REQ_TYPE_DRV_PRIV); 581 + BUG_ON(ide_req(rq)->type != ATA_PRIV_MISC && 582 + ide_req(rq)->type != ATA_PRIV_SENSE); 582 583 583 584 /* Retry a failed packet command */ 584 585 if (drive->failed_pc && drive->pc->c[0] == REQUEST_SENSE) { ··· 857 856 rq = blk_get_request(drive->queue, READ, __GFP_RECLAIM); 858 857 scsi_req_init(rq); 859 858 rq->cmd_type = REQ_TYPE_DRV_PRIV; 859 + ide_req(rq)->type = ATA_PRIV_MISC; 860 860 scsi_req(rq)->cmd[13] = cmd; 861 861 rq->rq_disk = tape->disk; 862 862 rq->__sector = tape->first_frame;
+2 -1
drivers/ide/ide-taskfile.c
··· 432 432 433 433 rq = blk_get_request(drive->queue, rw, __GFP_RECLAIM); 434 434 scsi_req_init(rq); 435 - rq->cmd_type = REQ_TYPE_ATA_TASKFILE; 435 + rq->cmd_type = REQ_TYPE_DRV_PRIV; 436 + ide_req(rq)->type = ATA_PRIV_TASKFILE; 436 437 437 438 /* 438 439 * (ks) We transfer currently only whole sectors.
+45 -11
include/linux/ide.h
··· 40 40 41 41 struct device; 42 42 43 - /* IDE-specific values for req->cmd_type */ 44 - enum ata_cmd_type_bits { 45 - REQ_TYPE_ATA_TASKFILE = REQ_TYPE_DRV_PRIV + 1, 46 - REQ_TYPE_ATA_PC, 47 - REQ_TYPE_ATA_SENSE, /* sense request */ 48 - REQ_TYPE_ATA_PM_SUSPEND,/* suspend request */ 49 - REQ_TYPE_ATA_PM_RESUME, /* resume request */ 43 + /* values for ide_request.type */ 44 + enum ata_priv_type { 45 + ATA_PRIV_MISC, 46 + ATA_PRIV_TASKFILE, 47 + ATA_PRIV_PC, 48 + ATA_PRIV_SENSE, /* sense request */ 49 + ATA_PRIV_PM_SUSPEND, /* suspend request */ 50 + ATA_PRIV_PM_RESUME, /* resume request */ 50 51 }; 51 - 52 - #define ata_pm_request(rq) \ 53 - ((rq)->cmd_type == REQ_TYPE_ATA_PM_SUSPEND || \ 54 - (rq)->cmd_type == REQ_TYPE_ATA_PM_RESUME) 55 52 56 53 struct ide_request { 57 54 struct scsi_request sreq; 58 55 u8 sense[SCSI_SENSE_BUFFERSIZE]; 56 + u8 type; 59 57 }; 58 + 59 + static inline struct ide_request *ide_req(struct request *rq) 60 + { 61 + return blk_mq_rq_to_pdu(rq); 62 + } 63 + 64 + static inline bool ata_misc_request(struct request *rq) 65 + { 66 + return rq->cmd_type == REQ_TYPE_DRV_PRIV && 67 + ide_req(rq)->type == ATA_PRIV_MISC; 68 + } 69 + 70 + static inline bool ata_taskfile_request(struct request *rq) 71 + { 72 + return rq->cmd_type == REQ_TYPE_DRV_PRIV && 73 + ide_req(rq)->type == ATA_PRIV_TASKFILE; 74 + } 75 + 76 + static inline bool ata_pc_request(struct request *rq) 77 + { 78 + return rq->cmd_type == REQ_TYPE_DRV_PRIV && 79 + ide_req(rq)->type == ATA_PRIV_PC; 80 + } 81 + 82 + static inline bool ata_sense_request(struct request *rq) 83 + { 84 + return rq->cmd_type == REQ_TYPE_DRV_PRIV && 85 + ide_req(rq)->type == ATA_PRIV_SENSE; 86 + } 87 + 88 + static inline bool ata_pm_request(struct request *rq) 89 + { 90 + return rq->cmd_type == REQ_TYPE_DRV_PRIV && 91 + (ide_req(rq)->type == ATA_PRIV_PM_SUSPEND || 92 + ide_req(rq)->type == ATA_PRIV_PM_RESUME); 93 + } 60 94 61 95 /* Error codes returned in rq->errors to the higher part of the driver. */ 62 96 enum {