@@ -3172,6 +3172,7 @@ static ssize_t srp_create_target(struct device *dev,
struct srp_device *srp_dev = host->srp_dev;
struct ib_device *ibdev = srp_dev->dev;
int ret, node_idx, node, cpu, i;
+ unsigned int max_max_sectors;
bool multich = false;
target_host = scsi_host_alloc(&srp_template,
@@ -3228,6 +3229,25 @@ static ssize_t srp_create_target(struct device *dev,
target->sg_tablesize = target->cmd_sg_cnt;
}
+ if (srp_dev->use_fast_reg || srp_dev->use_fmr) {
+ /*
+ * FR and FMR can only map one HCA page per entry. If the
+ * start address is not aligned on a HCA page boundary two
+ * entries will be used for the head and the tail although
+ * these two entries combined contain at most one HCA page of
+ * data. Hence the "- 1" in the calculation below.
+ */
+ max_max_sectors = (srp_dev->max_pages_per_mr - 1) <<
+ (ilog2(srp_dev->mr_page_size) - 9);
+ if (target->scsi_host->max_sectors > max_max_sectors) {
+ shost_printk(KERN_WARNING, target->scsi_host,
+ PFX "Reducing max_sectors from %d to %d\n",
+ target->scsi_host->max_sectors,
+ max_max_sectors);
+ target->scsi_host->max_sectors = max_max_sectors;
+ }
+ }
+
target_host->sg_tablesize = target->sg_tablesize;
target->mr_pool_size = target->scsi_host->can_queue;
target->indirect_size = target->sg_tablesize *