Commit c70f1fb7 authored by Xiang Chen's avatar Xiang Chen Committed by Martin K. Petersen

scsi: hisi_sas: alloc queue id of slot according to device id

Currently slots are allocated from queues in a round-robin fashion.
This causes a problem for internal commands in device mode. For this
mode, we should ensure that the internal abort command is the last
command seen in the host for that device. We can only ensure this when
we place the internal abort command after the preceding commands for
device that in the same queue, as there is no order in which the host
will select a queue to execute the next command.

This queue restriction makes supporting scsi mq more tricky in
the future, but should not be a blocker.

Note: Even though v1 hw does not support internal abort, the
      allocation method is chosen to be the same for consistency.
Signed-off-by: default avatarXiang Chen <chenxiang66@hisilicon.com>
Signed-off-by: default avatarJohn Garry <john.garry@huawei.com>
Reviewed-by: default avatarZhangfei Gao <zhangfei.gao@linaro.org>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent d3b688d3
...@@ -150,7 +150,8 @@ struct hisi_sas_hw { ...@@ -150,7 +150,8 @@ struct hisi_sas_hw {
struct domain_device *device); struct domain_device *device);
struct hisi_sas_device *(*alloc_dev)(struct domain_device *device); struct hisi_sas_device *(*alloc_dev)(struct domain_device *device);
void (*sl_notify)(struct hisi_hba *hisi_hba, int phy_no); void (*sl_notify)(struct hisi_hba *hisi_hba, int phy_no);
int (*get_free_slot)(struct hisi_hba *hisi_hba, int *q, int *s); int (*get_free_slot)(struct hisi_hba *hisi_hba, u32 dev_id,
int *q, int *s);
void (*start_delivery)(struct hisi_hba *hisi_hba); void (*start_delivery)(struct hisi_hba *hisi_hba);
int (*prep_ssp)(struct hisi_hba *hisi_hba, int (*prep_ssp)(struct hisi_hba *hisi_hba,
struct hisi_sas_slot *slot, int is_tmf, struct hisi_sas_slot *slot, int is_tmf,
...@@ -207,7 +208,6 @@ struct hisi_hba { ...@@ -207,7 +208,6 @@ struct hisi_hba {
struct hisi_sas_port port[HISI_SAS_MAX_PHYS]; struct hisi_sas_port port[HISI_SAS_MAX_PHYS];
int queue_count; int queue_count;
int queue;
struct hisi_sas_slot *slot_prep; struct hisi_sas_slot *slot_prep;
struct dma_pool *sge_page_pool; struct dma_pool *sge_page_pool;
......
...@@ -232,8 +232,8 @@ static int hisi_sas_task_prep(struct sas_task *task, struct hisi_hba *hisi_hba, ...@@ -232,8 +232,8 @@ static int hisi_sas_task_prep(struct sas_task *task, struct hisi_hba *hisi_hba,
rc = hisi_sas_slot_index_alloc(hisi_hba, &slot_idx); rc = hisi_sas_slot_index_alloc(hisi_hba, &slot_idx);
if (rc) if (rc)
goto err_out; goto err_out;
rc = hisi_hba->hw->get_free_slot(hisi_hba, &dlvry_queue, rc = hisi_hba->hw->get_free_slot(hisi_hba, sas_dev->device_id,
&dlvry_queue_slot); &dlvry_queue, &dlvry_queue_slot);
if (rc) if (rc)
goto err_out_tag; goto err_out_tag;
...@@ -987,8 +987,8 @@ hisi_sas_internal_abort_task_exec(struct hisi_hba *hisi_hba, u64 device_id, ...@@ -987,8 +987,8 @@ hisi_sas_internal_abort_task_exec(struct hisi_hba *hisi_hba, u64 device_id,
rc = hisi_sas_slot_index_alloc(hisi_hba, &slot_idx); rc = hisi_sas_slot_index_alloc(hisi_hba, &slot_idx);
if (rc) if (rc)
goto err_out; goto err_out;
rc = hisi_hba->hw->get_free_slot(hisi_hba, &dlvry_queue, rc = hisi_hba->hw->get_free_slot(hisi_hba, sas_dev->device_id,
&dlvry_queue_slot); &dlvry_queue, &dlvry_queue_slot);
if (rc) if (rc)
goto err_out_tag; goto err_out_tag;
......
...@@ -862,29 +862,23 @@ static int get_wideport_bitmap_v1_hw(struct hisi_hba *hisi_hba, int port_id) ...@@ -862,29 +862,23 @@ static int get_wideport_bitmap_v1_hw(struct hisi_hba *hisi_hba, int port_id)
* The callpath to this function and upto writing the write * The callpath to this function and upto writing the write
* queue pointer should be safe from interruption. * queue pointer should be safe from interruption.
*/ */
static int get_free_slot_v1_hw(struct hisi_hba *hisi_hba, int *q, int *s) static int get_free_slot_v1_hw(struct hisi_hba *hisi_hba, u32 dev_id,
int *q, int *s)
{ {
struct device *dev = &hisi_hba->pdev->dev; struct device *dev = &hisi_hba->pdev->dev;
struct hisi_sas_dq *dq; struct hisi_sas_dq *dq;
u32 r, w; u32 r, w;
int queue = hisi_hba->queue; int queue = dev_id % hisi_hba->queue_count;
while (1) { dq = &hisi_hba->dq[queue];
dq = &hisi_hba->dq[queue]; w = dq->wr_point;
w = dq->wr_point; r = hisi_sas_read32_relaxed(hisi_hba,
r = hisi_sas_read32_relaxed(hisi_hba, DLVRY_Q_0_RD_PTR + (queue * 0x14));
DLVRY_Q_0_RD_PTR + (queue * 0x14)); if (r == (w+1) % HISI_SAS_QUEUE_SLOTS) {
if (r == (w+1) % HISI_SAS_QUEUE_SLOTS) { dev_warn(dev, "could not find free slot\n");
queue = (queue + 1) % hisi_hba->queue_count; return -EAGAIN;
if (queue == hisi_hba->queue) {
dev_warn(dev, "could not find free slot\n");
return -EAGAIN;
}
continue;
}
break;
} }
hisi_hba->queue = (queue + 1) % hisi_hba->queue_count;
*q = queue; *q = queue;
*s = w; *s = w;
return 0; return 0;
......
...@@ -1089,29 +1089,24 @@ static int get_wideport_bitmap_v2_hw(struct hisi_hba *hisi_hba, int port_id) ...@@ -1089,29 +1089,24 @@ static int get_wideport_bitmap_v2_hw(struct hisi_hba *hisi_hba, int port_id)
* The callpath to this function and upto writing the write * The callpath to this function and upto writing the write
* queue pointer should be safe from interruption. * queue pointer should be safe from interruption.
*/ */
static int get_free_slot_v2_hw(struct hisi_hba *hisi_hba, int *q, int *s) static int get_free_slot_v2_hw(struct hisi_hba *hisi_hba, u32 dev_id,
int *q, int *s)
{ {
struct device *dev = &hisi_hba->pdev->dev; struct device *dev = &hisi_hba->pdev->dev;
struct hisi_sas_dq *dq; struct hisi_sas_dq *dq;
u32 r, w; u32 r, w;
int queue = hisi_hba->queue; int queue = dev_id % hisi_hba->queue_count;
while (1) { dq = &hisi_hba->dq[queue];
dq = &hisi_hba->dq[queue]; w = dq->wr_point;
w = dq->wr_point; r = hisi_sas_read32_relaxed(hisi_hba,
r = hisi_sas_read32_relaxed(hisi_hba, DLVRY_Q_0_RD_PTR + (queue * 0x14));
DLVRY_Q_0_RD_PTR + (queue * 0x14)); if (r == (w+1) % HISI_SAS_QUEUE_SLOTS) {
if (r == (w+1) % HISI_SAS_QUEUE_SLOTS) { dev_warn(dev, "full queue=%d r=%d w=%d\n\n",
queue = (queue + 1) % hisi_hba->queue_count; queue, r, w);
if (queue == hisi_hba->queue) { return -EAGAIN;
dev_warn(dev, "could not find free slot\n");
return -EAGAIN;
}
continue;
}
break;
} }
hisi_hba->queue = (queue + 1) % hisi_hba->queue_count;
*q = queue; *q = queue;
*s = w; *s = w;
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment