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

scsi: sd: Make protection lookup tables static and relocate functions

Currently the protection lookup tables in sd_prot_flag_mask() and
sd_prot_op() are declared as non-static. As such, they will be rebuilt for
each respective function call.

Optimise by making them static.

This saves ~100B object code for sd.c:

Before:
text data bss dec hex filename
25403 1024 16 26443 674b drivers/scsi/sd.o

After:
text data bss dec hex filename
25299 1024 16 26339 66e3 drivers/scsi/sd.o

In addition, since those same functions are declared in sd.h, but each are
only referenced in sd.c, relocate them to that same c file.

The inline specifier is dropped also, since gcc should be able to make the
decision to inline.

Signed-off-by: John Garry <john.garry@huawei.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

John Garry and committed by
Martin K. Petersen
082c2cd2 1afb4b85

+62 -62
+62
drivers/scsi/sd.c
··· 659 659 } 660 660 #endif /* CONFIG_BLK_SED_OPAL */ 661 661 662 + /* 663 + * Look up the DIX operation based on whether the command is read or 664 + * write and whether dix and dif are enabled. 665 + */ 666 + static unsigned int sd_prot_op(bool write, bool dix, bool dif) 667 + { 668 + /* Lookup table: bit 2 (write), bit 1 (dix), bit 0 (dif) */ 669 + static const unsigned int ops[] = { /* wrt dix dif */ 670 + SCSI_PROT_NORMAL, /* 0 0 0 */ 671 + SCSI_PROT_READ_STRIP, /* 0 0 1 */ 672 + SCSI_PROT_READ_INSERT, /* 0 1 0 */ 673 + SCSI_PROT_READ_PASS, /* 0 1 1 */ 674 + SCSI_PROT_NORMAL, /* 1 0 0 */ 675 + SCSI_PROT_WRITE_INSERT, /* 1 0 1 */ 676 + SCSI_PROT_WRITE_STRIP, /* 1 1 0 */ 677 + SCSI_PROT_WRITE_PASS, /* 1 1 1 */ 678 + }; 679 + 680 + return ops[write << 2 | dix << 1 | dif]; 681 + } 682 + 683 + /* 684 + * Returns a mask of the protection flags that are valid for a given DIX 685 + * operation. 686 + */ 687 + static unsigned int sd_prot_flag_mask(unsigned int prot_op) 688 + { 689 + static const unsigned int flag_mask[] = { 690 + [SCSI_PROT_NORMAL] = 0, 691 + 692 + [SCSI_PROT_READ_STRIP] = SCSI_PROT_TRANSFER_PI | 693 + SCSI_PROT_GUARD_CHECK | 694 + SCSI_PROT_REF_CHECK | 695 + SCSI_PROT_REF_INCREMENT, 696 + 697 + [SCSI_PROT_READ_INSERT] = SCSI_PROT_REF_INCREMENT | 698 + SCSI_PROT_IP_CHECKSUM, 699 + 700 + [SCSI_PROT_READ_PASS] = SCSI_PROT_TRANSFER_PI | 701 + SCSI_PROT_GUARD_CHECK | 702 + SCSI_PROT_REF_CHECK | 703 + SCSI_PROT_REF_INCREMENT | 704 + SCSI_PROT_IP_CHECKSUM, 705 + 706 + [SCSI_PROT_WRITE_INSERT] = SCSI_PROT_TRANSFER_PI | 707 + SCSI_PROT_REF_INCREMENT, 708 + 709 + [SCSI_PROT_WRITE_STRIP] = SCSI_PROT_GUARD_CHECK | 710 + SCSI_PROT_REF_CHECK | 711 + SCSI_PROT_REF_INCREMENT | 712 + SCSI_PROT_IP_CHECKSUM, 713 + 714 + [SCSI_PROT_WRITE_PASS] = SCSI_PROT_TRANSFER_PI | 715 + SCSI_PROT_GUARD_CHECK | 716 + SCSI_PROT_REF_CHECK | 717 + SCSI_PROT_REF_INCREMENT | 718 + SCSI_PROT_IP_CHECKSUM, 719 + }; 720 + 721 + return flag_mask[prot_op]; 722 + } 723 + 662 724 static unsigned char sd_setup_protect_cmnd(struct scsi_cmnd *scmd, 663 725 unsigned int dix, unsigned int dif) 664 726 {
-62
drivers/scsi/sd.h
··· 188 188 return sector >> (ilog2(sdev->sector_size) - 9); 189 189 } 190 190 191 - /* 192 - * Look up the DIX operation based on whether the command is read or 193 - * write and whether dix and dif are enabled. 194 - */ 195 - static inline unsigned int sd_prot_op(bool write, bool dix, bool dif) 196 - { 197 - /* Lookup table: bit 2 (write), bit 1 (dix), bit 0 (dif) */ 198 - const unsigned int ops[] = { /* wrt dix dif */ 199 - SCSI_PROT_NORMAL, /* 0 0 0 */ 200 - SCSI_PROT_READ_STRIP, /* 0 0 1 */ 201 - SCSI_PROT_READ_INSERT, /* 0 1 0 */ 202 - SCSI_PROT_READ_PASS, /* 0 1 1 */ 203 - SCSI_PROT_NORMAL, /* 1 0 0 */ 204 - SCSI_PROT_WRITE_INSERT, /* 1 0 1 */ 205 - SCSI_PROT_WRITE_STRIP, /* 1 1 0 */ 206 - SCSI_PROT_WRITE_PASS, /* 1 1 1 */ 207 - }; 208 - 209 - return ops[write << 2 | dix << 1 | dif]; 210 - } 211 - 212 - /* 213 - * Returns a mask of the protection flags that are valid for a given DIX 214 - * operation. 215 - */ 216 - static inline unsigned int sd_prot_flag_mask(unsigned int prot_op) 217 - { 218 - const unsigned int flag_mask[] = { 219 - [SCSI_PROT_NORMAL] = 0, 220 - 221 - [SCSI_PROT_READ_STRIP] = SCSI_PROT_TRANSFER_PI | 222 - SCSI_PROT_GUARD_CHECK | 223 - SCSI_PROT_REF_CHECK | 224 - SCSI_PROT_REF_INCREMENT, 225 - 226 - [SCSI_PROT_READ_INSERT] = SCSI_PROT_REF_INCREMENT | 227 - SCSI_PROT_IP_CHECKSUM, 228 - 229 - [SCSI_PROT_READ_PASS] = SCSI_PROT_TRANSFER_PI | 230 - SCSI_PROT_GUARD_CHECK | 231 - SCSI_PROT_REF_CHECK | 232 - SCSI_PROT_REF_INCREMENT | 233 - SCSI_PROT_IP_CHECKSUM, 234 - 235 - [SCSI_PROT_WRITE_INSERT] = SCSI_PROT_TRANSFER_PI | 236 - SCSI_PROT_REF_INCREMENT, 237 - 238 - [SCSI_PROT_WRITE_STRIP] = SCSI_PROT_GUARD_CHECK | 239 - SCSI_PROT_REF_CHECK | 240 - SCSI_PROT_REF_INCREMENT | 241 - SCSI_PROT_IP_CHECKSUM, 242 - 243 - [SCSI_PROT_WRITE_PASS] = SCSI_PROT_TRANSFER_PI | 244 - SCSI_PROT_GUARD_CHECK | 245 - SCSI_PROT_REF_CHECK | 246 - SCSI_PROT_REF_INCREMENT | 247 - SCSI_PROT_IP_CHECKSUM, 248 - }; 249 - 250 - return flag_mask[prot_op]; 251 - } 252 - 253 191 #ifdef CONFIG_BLK_DEV_INTEGRITY 254 192 255 193 extern void sd_dif_config_host(struct scsi_disk *);