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

scsi: imm: Move the SCSI pointer to private command data

Set .cmd_size in the SCSI host template instead of using the SCSI pointer.
This patch prepares for removal of the SCSI pointer from struct scsi_cmnd.

Link: https://lore.kernel.org/r/20220218195117.25689-25-bvanassche@acm.org
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Bart Van Assche and committed by
Martin K. Petersen
6b66f09c 5c113eb3

+50 -43
+45 -43
drivers/scsi/imm.c
··· 66 66 { 67 67 dev->base = dev->dev->port->base; 68 68 if (dev->cur_cmd) 69 - dev->cur_cmd->SCp.phase = 1; 69 + imm_scsi_pointer(dev->cur_cmd)->phase = 1; 70 70 else 71 71 wake_up(dev->waiting); 72 72 } ··· 618 618 * The driver appears to remain stable if we speed up the parallel port 619 619 * i/o in this function, but not elsewhere. 620 620 */ 621 - static int imm_completion(struct scsi_cmnd *cmd) 621 + static int imm_completion(struct scsi_cmnd *const cmd) 622 622 { 623 623 /* Return codes: 624 624 * -1 Error 625 625 * 0 Told to schedule 626 626 * 1 Finished data transfer 627 627 */ 628 + struct scsi_pointer *scsi_pointer = imm_scsi_pointer(cmd); 628 629 imm_struct *dev = imm_dev(cmd->device->host); 629 630 unsigned short ppb = dev->base; 630 631 unsigned long start_jiffies = jiffies; ··· 661 660 * a) Drive status is screwy (!ready && !present) 662 661 * b) Drive is requesting/sending more data than expected 663 662 */ 664 - if (((r & 0x88) != 0x88) || (cmd->SCp.this_residual <= 0)) { 663 + if ((r & 0x88) != 0x88 || scsi_pointer->this_residual <= 0) { 665 664 imm_fail(dev, DID_ERROR); 666 665 return -1; /* ERROR_RETURN */ 667 666 } 668 667 /* determine if we should use burst I/O */ 669 668 if (dev->rd == 0) { 670 - fast = (bulk 671 - && (cmd->SCp.this_residual >= 672 - IMM_BURST_SIZE)) ? IMM_BURST_SIZE : 2; 673 - status = imm_out(dev, cmd->SCp.ptr, fast); 669 + fast = bulk && scsi_pointer->this_residual >= 670 + IMM_BURST_SIZE ? IMM_BURST_SIZE : 2; 671 + status = imm_out(dev, scsi_pointer->ptr, fast); 674 672 } else { 675 - fast = (bulk 676 - && (cmd->SCp.this_residual >= 677 - IMM_BURST_SIZE)) ? IMM_BURST_SIZE : 1; 678 - status = imm_in(dev, cmd->SCp.ptr, fast); 673 + fast = bulk && scsi_pointer->this_residual >= 674 + IMM_BURST_SIZE ? IMM_BURST_SIZE : 1; 675 + status = imm_in(dev, scsi_pointer->ptr, fast); 679 676 } 680 677 681 - cmd->SCp.ptr += fast; 682 - cmd->SCp.this_residual -= fast; 678 + scsi_pointer->ptr += fast; 679 + scsi_pointer->this_residual -= fast; 683 680 684 681 if (!status) { 685 682 imm_fail(dev, DID_BUS_BUSY); 686 683 return -1; /* ERROR_RETURN */ 687 684 } 688 - if (cmd->SCp.buffer && !cmd->SCp.this_residual) { 685 + if (scsi_pointer->buffer && !scsi_pointer->this_residual) { 689 686 /* if scatter/gather, advance to the next segment */ 690 - if (cmd->SCp.buffers_residual--) { 691 - cmd->SCp.buffer = sg_next(cmd->SCp.buffer); 692 - cmd->SCp.this_residual = 693 - cmd->SCp.buffer->length; 694 - cmd->SCp.ptr = sg_virt(cmd->SCp.buffer); 687 + if (scsi_pointer->buffers_residual--) { 688 + scsi_pointer->buffer = 689 + sg_next(scsi_pointer->buffer); 690 + scsi_pointer->this_residual = 691 + scsi_pointer->buffer->length; 692 + scsi_pointer->ptr = sg_virt(scsi_pointer->buffer); 695 693 696 694 /* 697 695 * Make sure that we transfer even number of bytes 698 696 * otherwise it makes imm_byte_out() messy. 699 697 */ 700 - if (cmd->SCp.this_residual & 0x01) 701 - cmd->SCp.this_residual++; 698 + if (scsi_pointer->this_residual & 0x01) 699 + scsi_pointer->this_residual++; 702 700 } 703 701 } 704 702 /* Now check to see if the drive is ready to comunicate */ ··· 762 762 } 763 763 #endif 764 764 765 - if (cmd->SCp.phase > 1) 765 + if (imm_scsi_pointer(cmd)->phase > 1) 766 766 imm_disconnect(dev); 767 767 768 768 imm_pb_dismiss(dev); ··· 774 774 return; 775 775 } 776 776 777 - static int imm_engine(imm_struct *dev, struct scsi_cmnd *cmd) 777 + static int imm_engine(imm_struct *dev, struct scsi_cmnd *const cmd) 778 778 { 779 + struct scsi_pointer *scsi_pointer = imm_scsi_pointer(cmd); 779 780 unsigned short ppb = dev->base; 780 781 unsigned char l = 0, h = 0; 781 782 int retv, x; ··· 787 786 if (dev->failed) 788 787 return 0; 789 788 790 - switch (cmd->SCp.phase) { 789 + switch (scsi_pointer->phase) { 791 790 case 0: /* Phase 0 - Waiting for parport */ 792 791 if (time_after(jiffies, dev->jstart + HZ)) { 793 792 /* ··· 801 800 802 801 case 1: /* Phase 1 - Connected */ 803 802 imm_connect(dev, CONNECT_EPP_MAYBE); 804 - cmd->SCp.phase++; 803 + scsi_pointer->phase++; 805 804 fallthrough; 806 805 807 806 case 2: /* Phase 2 - We are now talking to the scsi bus */ ··· 809 808 imm_fail(dev, DID_NO_CONNECT); 810 809 return 0; 811 810 } 812 - cmd->SCp.phase++; 811 + scsi_pointer->phase++; 813 812 fallthrough; 814 813 815 814 case 3: /* Phase 3 - Ready to accept a command */ ··· 819 818 820 819 if (!imm_send_command(cmd)) 821 820 return 0; 822 - cmd->SCp.phase++; 821 + scsi_pointer->phase++; 823 822 fallthrough; 824 823 825 824 case 4: /* Phase 4 - Setup scatter/gather buffers */ 826 825 if (scsi_bufflen(cmd)) { 827 - cmd->SCp.buffer = scsi_sglist(cmd); 828 - cmd->SCp.this_residual = cmd->SCp.buffer->length; 829 - cmd->SCp.ptr = sg_virt(cmd->SCp.buffer); 826 + scsi_pointer->buffer = scsi_sglist(cmd); 827 + scsi_pointer->this_residual = scsi_pointer->buffer->length; 828 + scsi_pointer->ptr = sg_virt(scsi_pointer->buffer); 830 829 } else { 831 - cmd->SCp.buffer = NULL; 832 - cmd->SCp.this_residual = 0; 833 - cmd->SCp.ptr = NULL; 830 + scsi_pointer->buffer = NULL; 831 + scsi_pointer->this_residual = 0; 832 + scsi_pointer->ptr = NULL; 834 833 } 835 - cmd->SCp.buffers_residual = scsi_sg_count(cmd) - 1; 836 - cmd->SCp.phase++; 837 - if (cmd->SCp.this_residual & 0x01) 838 - cmd->SCp.this_residual++; 834 + scsi_pointer->buffers_residual = scsi_sg_count(cmd) - 1; 835 + scsi_pointer->phase++; 836 + if (scsi_pointer->this_residual & 0x01) 837 + scsi_pointer->this_residual++; 839 838 fallthrough; 840 839 841 840 case 5: /* Phase 5 - Pre-Data transfer stage */ ··· 852 851 if ((dev->dp) && (dev->rd)) 853 852 if (imm_negotiate(dev)) 854 853 return 0; 855 - cmd->SCp.phase++; 854 + scsi_pointer->phase++; 856 855 fallthrough; 857 856 858 857 case 6: /* Phase 6 - Data transfer stage */ ··· 868 867 if (retv == 0) 869 868 return 1; 870 869 } 871 - cmd->SCp.phase++; 870 + scsi_pointer->phase++; 872 871 fallthrough; 873 872 874 873 case 7: /* Phase 7 - Post data transfer stage */ ··· 880 879 w_ctr(ppb, 0x4); 881 880 } 882 881 } 883 - cmd->SCp.phase++; 882 + scsi_pointer->phase++; 884 883 fallthrough; 885 884 886 885 case 8: /* Phase 8 - Read status/message */ ··· 923 922 dev->jstart = jiffies; 924 923 dev->cur_cmd = cmd; 925 924 cmd->result = DID_ERROR << 16; /* default return code */ 926 - cmd->SCp.phase = 0; /* bus free */ 925 + imm_scsi_pointer(cmd)->phase = 0; /* bus free */ 927 926 928 927 schedule_delayed_work(&dev->imm_tq, 0); 929 928 ··· 962 961 * have tied the SCSI_MESSAGE line high in the interface 963 962 */ 964 963 965 - switch (cmd->SCp.phase) { 964 + switch (imm_scsi_pointer(cmd)->phase) { 966 965 case 0: /* Do not have access to parport */ 967 966 case 1: /* Have not connected to interface */ 968 967 dev->cur_cmd = NULL; /* Forget the problem */ ··· 988 987 { 989 988 imm_struct *dev = imm_dev(cmd->device->host); 990 989 991 - if (cmd->SCp.phase) 990 + if (imm_scsi_pointer(cmd)->phase) 992 991 imm_disconnect(dev); 993 992 dev->cur_cmd = NULL; /* Forget the problem */ 994 993 ··· 1110 1109 .sg_tablesize = SG_ALL, 1111 1110 .can_queue = 1, 1112 1111 .slave_alloc = imm_adjust_queue, 1112 + .cmd_size = sizeof(struct scsi_pointer), 1113 1113 }; 1114 1114 1115 1115 /***************************************************************************
+5
drivers/scsi/imm.h
··· 139 139 #define w_ctr(x,y) outb(y, (x)+2) 140 140 #endif 141 141 142 + static inline struct scsi_pointer *imm_scsi_pointer(struct scsi_cmnd *cmd) 143 + { 144 + return scsi_cmd_priv(cmd); 145 + } 146 + 142 147 static int imm_engine(imm_struct *, struct scsi_cmnd *); 143 148 144 149 #endif /* _IMM_H */