@@ -291,7 +291,7 @@ static void srp_free_target_ib(struct srp_target_port *target)
291291
292292 for (i = 0 ; i < SRP_RQ_SIZE ; ++ i )
293293 srp_free_iu (target -> srp_host , target -> rx_ring [i ]);
294- for (i = 0 ; i < SRP_SQ_SIZE + 1 ; ++ i )
294+ for (i = 0 ; i < SRP_SQ_SIZE ; ++ i )
295295 srp_free_iu (target -> srp_host , target -> tx_ring [i ]);
296296}
297297
@@ -822,7 +822,7 @@ static int srp_post_recv(struct srp_target_port *target)
822822
823823 spin_lock_irqsave (target -> scsi_host -> host_lock , flags );
824824
825- next = target -> rx_head & ( SRP_RQ_SIZE - 1 ) ;
825+ next = target -> rx_head & SRP_RQ_MASK ;
826826 wr .wr_id = next ;
827827 iu = target -> rx_ring [next ];
828828
@@ -989,19 +989,19 @@ static void srp_send_completion(struct ib_cq *cq, void *target_ptr)
989989static struct srp_iu * __srp_get_tx_iu (struct srp_target_port * target ,
990990 enum srp_request_type req_type )
991991{
992- s32 min = (req_type == SRP_REQ_TASK_MGMT ) ? 1 : 2 ;
992+ s32 rsv = (req_type == SRP_REQ_TASK_MGMT ) ? 0 : SRP_TSK_MGMT_SQ_SIZE ;
993993
994994 srp_send_completion (target -> send_cq , target );
995995
996996 if (target -> tx_head - target -> tx_tail >= SRP_SQ_SIZE )
997997 return NULL ;
998998
999- if (target -> req_lim < min ) {
999+ if (target -> req_lim <= rsv ) {
10001000 ++ target -> zero_req_lim ;
10011001 return NULL ;
10021002 }
10031003
1004- return target -> tx_ring [target -> tx_head & SRP_SQ_SIZE ];
1004+ return target -> tx_ring [target -> tx_head & SRP_SQ_MASK ];
10051005}
10061006
10071007/*
@@ -1020,7 +1020,7 @@ static int __srp_post_send(struct srp_target_port *target,
10201020 list .lkey = target -> srp_host -> srp_dev -> mr -> lkey ;
10211021
10221022 wr .next = NULL ;
1023- wr .wr_id = target -> tx_head & SRP_SQ_SIZE ;
1023+ wr .wr_id = target -> tx_head & SRP_SQ_MASK ;
10241024 wr .sg_list = & list ;
10251025 wr .num_sge = 1 ;
10261026 wr .opcode = IB_WR_SEND ;
@@ -1121,7 +1121,7 @@ static int srp_alloc_iu_bufs(struct srp_target_port *target)
11211121 goto err ;
11221122 }
11231123
1124- for (i = 0 ; i < SRP_SQ_SIZE + 1 ; ++ i ) {
1124+ for (i = 0 ; i < SRP_SQ_SIZE ; ++ i ) {
11251125 target -> tx_ring [i ] = srp_alloc_iu (target -> srp_host ,
11261126 srp_max_iu_len ,
11271127 GFP_KERNEL , DMA_TO_DEVICE );
@@ -1137,7 +1137,7 @@ static int srp_alloc_iu_bufs(struct srp_target_port *target)
11371137 target -> rx_ring [i ] = NULL ;
11381138 }
11391139
1140- for (i = 0 ; i < SRP_SQ_SIZE + 1 ; ++ i ) {
1140+ for (i = 0 ; i < SRP_SQ_SIZE ; ++ i ) {
11411141 srp_free_iu (target -> srp_host , target -> tx_ring [i ]);
11421142 target -> tx_ring [i ] = NULL ;
11431143 }
@@ -1626,9 +1626,9 @@ static struct scsi_host_template srp_template = {
16261626 .eh_abort_handler = srp_abort ,
16271627 .eh_device_reset_handler = srp_reset_device ,
16281628 .eh_host_reset_handler = srp_reset_host ,
1629- .can_queue = SRP_SQ_SIZE ,
1629+ .can_queue = SRP_CMD_SQ_SIZE ,
16301630 .this_id = -1 ,
1631- .cmd_per_lun = SRP_SQ_SIZE ,
1631+ .cmd_per_lun = SRP_CMD_SQ_SIZE ,
16321632 .use_clustering = ENABLE_CLUSTERING ,
16331633 .shost_attrs = srp_host_attrs
16341634};
@@ -1813,7 +1813,7 @@ static int srp_parse_options(const char *buf, struct srp_target_port *target)
18131813 printk (KERN_WARNING PFX "bad max cmd_per_lun parameter '%s'\n" , p );
18141814 goto out ;
18151815 }
1816- target -> scsi_host -> cmd_per_lun = min (token , SRP_SQ_SIZE );
1816+ target -> scsi_host -> cmd_per_lun = min (token , SRP_CMD_SQ_SIZE );
18171817 break ;
18181818
18191819 case SRP_OPT_IO_CLASS :
@@ -1891,7 +1891,7 @@ static ssize_t srp_create_target(struct device *dev,
18911891
18921892 INIT_LIST_HEAD (& target -> free_reqs );
18931893 INIT_LIST_HEAD (& target -> req_queue );
1894- for (i = 0 ; i < SRP_SQ_SIZE ; ++ i ) {
1894+ for (i = 0 ; i < SRP_CMD_SQ_SIZE ; ++ i ) {
18951895 target -> req_ring [i ].index = i ;
18961896 list_add_tail (& target -> req_ring [i ].list , & target -> free_reqs );
18971897 }
@@ -2159,6 +2159,9 @@ static int __init srp_init_module(void)
21592159{
21602160 int ret ;
21612161
2162+ BUILD_BUG_ON_NOT_POWER_OF_2 (SRP_SQ_SIZE );
2163+ BUILD_BUG_ON_NOT_POWER_OF_2 (SRP_RQ_SIZE );
2164+
21622165 if (srp_sg_tablesize > 255 ) {
21632166 printk (KERN_WARNING PFX "Clamping srp_sg_tablesize to 255\n" );
21642167 srp_sg_tablesize = 255 ;
0 commit comments