Skip to content

Commit 98bd4be

Browse files
shligitaxboe
authored andcommitted
libata: move sas ata tag allocation to libata-scsi.c
Basically move the sas ata tag allocation to libata-scsi.c to make it clear these staffs are just for sas. Signed-off-by: Shaohua Li <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 12cb5ce commit 98bd4be

File tree

3 files changed

+46
-77
lines changed

3 files changed

+46
-77
lines changed

drivers/ata/libata-core.c

Lines changed: 17 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,15 +1525,6 @@ static void ata_qc_complete_internal(struct ata_queued_cmd *qc)
15251525
complete(waiting);
15261526
}
15271527

1528-
static bool ata_valid_internal_tag(struct ata_port *ap, struct ata_device *dev,
1529-
unsigned int tag)
1530-
{
1531-
if (!ap->scsi_host)
1532-
return !test_and_set_bit(tag, &ap->sas_tag_allocated);
1533-
return !dev->sdev ||
1534-
!blk_queue_find_tag(dev->sdev->request_queue, tag);
1535-
}
1536-
15371528
/**
15381529
* ata_exec_internal_sg - execute libata internal command
15391530
* @dev: Device to which the command is sent
@@ -1594,7 +1585,6 @@ unsigned ata_exec_internal_sg(struct ata_device *dev,
15941585
else
15951586
tag = 0;
15961587

1597-
BUG_ON(!ata_valid_internal_tag(ap, dev, tag));
15981588
qc = __ata_qc_from_tag(ap, tag);
15991589

16001590
qc->tag = tag;
@@ -4734,80 +4724,36 @@ void swap_buf_le16(u16 *buf, unsigned int buf_words)
47344724
}
47354725

47364726
/**
4737-
* ata_qc_new - Request an available ATA command, for queueing
4738-
* @ap: target port
4739-
*
4740-
* Some ATA host controllers may implement a queue depth which is less
4741-
* than ATA_MAX_QUEUE. So we shouldn't allocate a tag which is beyond
4742-
* the hardware limitation.
4727+
* ata_qc_new_init - Request an available ATA command, and initialize it
4728+
* @dev: Device from whom we request an available command structure
47434729
*
47444730
* LOCKING:
47454731
* None.
47464732
*/
47474733

4748-
static struct ata_queued_cmd *sas_ata_qc_new(struct ata_port *ap)
4749-
{
4750-
struct ata_queued_cmd *qc = NULL;
4751-
unsigned int max_queue = ap->host->n_tags;
4752-
unsigned int i, tag;
4753-
4754-
for (i = 0, tag = ap->sas_last_tag + 1; i < max_queue; i++, tag++) {
4755-
tag = tag < max_queue ? tag : 0;
4756-
4757-
/* the last tag is reserved for internal command. */
4758-
if (tag == ATA_TAG_INTERNAL)
4759-
continue;
4760-
4761-
if (!test_and_set_bit(tag, &ap->sas_tag_allocated)) {
4762-
qc = __ata_qc_from_tag(ap, tag);
4763-
qc->tag = tag;
4764-
ap->sas_last_tag = tag;
4765-
break;
4766-
}
4767-
}
4768-
4769-
return qc;
4770-
}
4771-
4772-
static struct ata_queued_cmd *ata_qc_new(struct ata_port *ap, int blktag)
4734+
struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev, int tag)
47734735
{
4736+
struct ata_port *ap = dev->link->ap;
47744737
struct ata_queued_cmd *qc;
47754738

47764739
/* no command while frozen */
47774740
if (unlikely(ap->pflags & ATA_PFLAG_FROZEN))
47784741
return NULL;
47794742

4780-
/* SATA will directly use block tag. libsas need its own tag management */
4781-
if (ap->scsi_host) {
4782-
qc = __ata_qc_from_tag(ap, blktag);
4783-
qc->tag = blktag;
4784-
return qc;
4743+
/* libsas case */
4744+
if (!ap->scsi_host) {
4745+
tag = ata_sas_allocate_tag(ap);
4746+
if (tag < 0)
4747+
return NULL;
47854748
}
47864749

4787-
return sas_ata_qc_new(ap);
4788-
}
4789-
4790-
/**
4791-
* ata_qc_new_init - Request an available ATA command, and initialize it
4792-
* @dev: Device from whom we request an available command structure
4793-
*
4794-
* LOCKING:
4795-
* None.
4796-
*/
4797-
4798-
struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev, int blktag)
4799-
{
4800-
struct ata_port *ap = dev->link->ap;
4801-
struct ata_queued_cmd *qc;
4802-
4803-
qc = ata_qc_new(ap, blktag);
4804-
if (qc) {
4805-
qc->scsicmd = NULL;
4806-
qc->ap = ap;
4807-
qc->dev = dev;
4750+
qc = __ata_qc_from_tag(ap, tag);
4751+
qc->tag = tag;
4752+
qc->scsicmd = NULL;
4753+
qc->ap = ap;
4754+
qc->dev = dev;
48084755

4809-
ata_qc_reinit(qc);
4810-
}
4756+
ata_qc_reinit(qc);
48114757

48124758
return qc;
48134759
}
@@ -4822,12 +4768,6 @@ struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev, int blktag)
48224768
* LOCKING:
48234769
* spin_lock_irqsave(host lock)
48244770
*/
4825-
static void sas_ata_qc_free(unsigned int tag, struct ata_port *ap)
4826-
{
4827-
if (!ap->scsi_host)
4828-
clear_bit(tag, &ap->sas_tag_allocated);
4829-
}
4830-
48314771
void ata_qc_free(struct ata_queued_cmd *qc)
48324772
{
48334773
struct ata_port *ap;
@@ -4840,7 +4780,8 @@ void ata_qc_free(struct ata_queued_cmd *qc)
48404780
tag = qc->tag;
48414781
if (likely(ata_tag_valid(tag))) {
48424782
qc->tag = ATA_TAG_POISON;
4843-
sas_ata_qc_free(tag, ap);
4783+
if (!ap->scsi_host)
4784+
ata_sas_free_tag(tag, ap);
48444785
}
48454786
}
48464787

drivers/ata/libata-scsi.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3666,7 +3666,8 @@ int ata_scsi_add_hosts(struct ata_host *host, struct scsi_host_template *sht)
36663666
*/
36673667
shost->max_host_blocked = 1;
36683668

3669-
scsi_init_shared_tag_map(shost, host->n_tags);
3669+
if (scsi_init_shared_tag_map(shost, host->n_tags))
3670+
goto err_add;
36703671

36713672
rc = scsi_add_host_with_dma(ap->scsi_host,
36723673
&ap->tdev, ap->host->dev);
@@ -4230,3 +4231,28 @@ int ata_sas_queuecmd(struct scsi_cmnd *cmd, struct ata_port *ap)
42304231
return rc;
42314232
}
42324233
EXPORT_SYMBOL_GPL(ata_sas_queuecmd);
4234+
4235+
int ata_sas_allocate_tag(struct ata_port *ap)
4236+
{
4237+
unsigned int max_queue = ap->host->n_tags;
4238+
unsigned int i, tag;
4239+
4240+
for (i = 0, tag = ap->sas_last_tag + 1; i < max_queue; i++, tag++) {
4241+
tag = tag < max_queue ? tag : 0;
4242+
4243+
/* the last tag is reserved for internal command. */
4244+
if (tag == ATA_TAG_INTERNAL)
4245+
continue;
4246+
4247+
if (!test_and_set_bit(tag, &ap->sas_tag_allocated)) {
4248+
ap->sas_last_tag = tag;
4249+
return tag;
4250+
}
4251+
}
4252+
return -1;
4253+
}
4254+
4255+
void ata_sas_free_tag(unsigned int tag, struct ata_port *ap)
4256+
{
4257+
clear_bit(tag, &ap->sas_tag_allocated);
4258+
}

drivers/ata/libata.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ extern void ata_scsi_dev_rescan(struct work_struct *work);
145145
extern int ata_bus_probe(struct ata_port *ap);
146146
extern int ata_scsi_user_scan(struct Scsi_Host *shost, unsigned int channel,
147147
unsigned int id, u64 lun);
148+
int ata_sas_allocate_tag(struct ata_port *ap);
149+
void ata_sas_free_tag(unsigned int tag, struct ata_port *ap);
148150

149151

150152
/* libata-eh.c */

0 commit comments

Comments
 (0)