diff options
Diffstat (limited to 'drivers/scsi/scsi_lib.c')
-rw-r--r-- | drivers/scsi/scsi_lib.c | 74 |
1 files changed, 18 insertions, 56 deletions
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 4560713ecb14..e1c7eebfe907 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c | |||
@@ -8,6 +8,7 @@ | |||
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <linux/bio.h> | 10 | #include <linux/bio.h> |
11 | #include <linux/bitops.h> | ||
11 | #include <linux/blkdev.h> | 12 | #include <linux/blkdev.h> |
12 | #include <linux/completion.h> | 13 | #include <linux/completion.h> |
13 | #include <linux/kernel.h> | 14 | #include <linux/kernel.h> |
@@ -34,13 +35,6 @@ | |||
34 | #define SG_MEMPOOL_NR ARRAY_SIZE(scsi_sg_pools) | 35 | #define SG_MEMPOOL_NR ARRAY_SIZE(scsi_sg_pools) |
35 | #define SG_MEMPOOL_SIZE 2 | 36 | #define SG_MEMPOOL_SIZE 2 |
36 | 37 | ||
37 | /* | ||
38 | * The maximum number of SG segments that we will put inside a scatterlist | ||
39 | * (unless chaining is used). Should ideally fit inside a single page, to | ||
40 | * avoid a higher order allocation. | ||
41 | */ | ||
42 | #define SCSI_MAX_SG_SEGMENTS 128 | ||
43 | |||
44 | struct scsi_host_sg_pool { | 38 | struct scsi_host_sg_pool { |
45 | size_t size; | 39 | size_t size; |
46 | char *name; | 40 | char *name; |
@@ -48,19 +42,26 @@ struct scsi_host_sg_pool { | |||
48 | mempool_t *pool; | 42 | mempool_t *pool; |
49 | }; | 43 | }; |
50 | 44 | ||
51 | #define SP(x) { x, "sgpool-" #x } | 45 | #define SP(x) { x, "sgpool-" __stringify(x) } |
46 | #if (SCSI_MAX_SG_SEGMENTS < 32) | ||
47 | #error SCSI_MAX_SG_SEGMENTS is too small (must be 32 or greater) | ||
48 | #endif | ||
52 | static struct scsi_host_sg_pool scsi_sg_pools[] = { | 49 | static struct scsi_host_sg_pool scsi_sg_pools[] = { |
53 | SP(8), | 50 | SP(8), |
54 | SP(16), | 51 | SP(16), |
55 | #if (SCSI_MAX_SG_SEGMENTS > 16) | ||
56 | SP(32), | ||
57 | #if (SCSI_MAX_SG_SEGMENTS > 32) | 52 | #if (SCSI_MAX_SG_SEGMENTS > 32) |
58 | SP(64), | 53 | SP(32), |
59 | #if (SCSI_MAX_SG_SEGMENTS > 64) | 54 | #if (SCSI_MAX_SG_SEGMENTS > 64) |
55 | SP(64), | ||
56 | #if (SCSI_MAX_SG_SEGMENTS > 128) | ||
60 | SP(128), | 57 | SP(128), |
58 | #if (SCSI_MAX_SG_SEGMENTS > 256) | ||
59 | #error SCSI_MAX_SG_SEGMENTS is too large (256 MAX) | ||
61 | #endif | 60 | #endif |
62 | #endif | 61 | #endif |
63 | #endif | 62 | #endif |
63 | #endif | ||
64 | SP(SCSI_MAX_SG_SEGMENTS) | ||
64 | }; | 65 | }; |
65 | #undef SP | 66 | #undef SP |
66 | 67 | ||
@@ -692,42 +693,16 @@ static struct scsi_cmnd *scsi_end_request(struct scsi_cmnd *cmd, int error, | |||
692 | return NULL; | 693 | return NULL; |
693 | } | 694 | } |
694 | 695 | ||
695 | /* | ||
696 | * Like SCSI_MAX_SG_SEGMENTS, but for archs that have sg chaining. This limit | ||
697 | * is totally arbitrary, a setting of 2048 will get you at least 8mb ios. | ||
698 | */ | ||
699 | #define SCSI_MAX_SG_CHAIN_SEGMENTS 2048 | ||
700 | |||
701 | static inline unsigned int scsi_sgtable_index(unsigned short nents) | 696 | static inline unsigned int scsi_sgtable_index(unsigned short nents) |
702 | { | 697 | { |
703 | unsigned int index; | 698 | unsigned int index; |
704 | 699 | ||
705 | switch (nents) { | 700 | BUG_ON(nents > SCSI_MAX_SG_SEGMENTS); |
706 | case 1 ... 8: | 701 | |
702 | if (nents <= 8) | ||
707 | index = 0; | 703 | index = 0; |
708 | break; | 704 | else |
709 | case 9 ... 16: | 705 | index = get_count_order(nents) - 3; |
710 | index = 1; | ||
711 | break; | ||
712 | #if (SCSI_MAX_SG_SEGMENTS > 16) | ||
713 | case 17 ... 32: | ||
714 | index = 2; | ||
715 | break; | ||
716 | #if (SCSI_MAX_SG_SEGMENTS > 32) | ||
717 | case 33 ... 64: | ||
718 | index = 3; | ||
719 | break; | ||
720 | #if (SCSI_MAX_SG_SEGMENTS > 64) | ||
721 | case 65 ... 128: | ||
722 | index = 4; | ||
723 | break; | ||
724 | #endif | ||
725 | #endif | ||
726 | #endif | ||
727 | default: | ||
728 | printk(KERN_ERR "scsi: bad segment count=%d\n", nents); | ||
729 | BUG(); | ||
730 | } | ||
731 | 706 | ||
732 | return index; | 707 | return index; |
733 | } | 708 | } |
@@ -1603,20 +1578,7 @@ struct request_queue *__scsi_alloc_queue(struct Scsi_Host *shost, | |||
1603 | * this limit is imposed by hardware restrictions | 1578 | * this limit is imposed by hardware restrictions |
1604 | */ | 1579 | */ |
1605 | blk_queue_max_hw_segments(q, shost->sg_tablesize); | 1580 | blk_queue_max_hw_segments(q, shost->sg_tablesize); |
1606 | 1581 | blk_queue_max_phys_segments(q, SCSI_MAX_SG_CHAIN_SEGMENTS); | |
1607 | /* | ||
1608 | * In the future, sg chaining support will be mandatory and this | ||
1609 | * ifdef can then go away. Right now we don't have all archs | ||
1610 | * converted, so better keep it safe. | ||
1611 | */ | ||
1612 | #ifdef ARCH_HAS_SG_CHAIN | ||
1613 | if (shost->use_sg_chaining) | ||
1614 | blk_queue_max_phys_segments(q, SCSI_MAX_SG_CHAIN_SEGMENTS); | ||
1615 | else | ||
1616 | blk_queue_max_phys_segments(q, SCSI_MAX_SG_SEGMENTS); | ||
1617 | #else | ||
1618 | blk_queue_max_phys_segments(q, SCSI_MAX_SG_SEGMENTS); | ||
1619 | #endif | ||
1620 | 1582 | ||
1621 | blk_queue_max_sectors(q, shost->max_sectors); | 1583 | blk_queue_max_sectors(q, shost->max_sectors); |
1622 | blk_queue_bounce_limit(q, scsi_calculate_bounce_limit(shost)); | 1584 | blk_queue_bounce_limit(q, scsi_calculate_bounce_limit(shost)); |