Commit 4fcf812c authored by Dan Williams's avatar Dan Williams Committed by James Bottomley

[SCSI] libsas: export sas_alloc_task()

Now that isci has added a 3rd open coded user of this functionality just
share the libsas version.
Acked-by: default avatarJack Wang <jack_wang@usish.com>
Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
Signed-off-by: default avatarJames Bottomley <JBottomley@Parallels.com>
parent 7ca3c803
...@@ -1345,29 +1345,6 @@ static void isci_smp_task_done(struct sas_task *task) ...@@ -1345,29 +1345,6 @@ static void isci_smp_task_done(struct sas_task *task)
complete(&task->completion); complete(&task->completion);
} }
static struct sas_task *isci_alloc_task(void)
{
struct sas_task *task = kzalloc(sizeof(*task), GFP_KERNEL);
if (task) {
INIT_LIST_HEAD(&task->list);
spin_lock_init(&task->task_state_lock);
task->task_state_flags = SAS_TASK_STATE_PENDING;
init_timer(&task->timer);
init_completion(&task->completion);
}
return task;
}
static void isci_free_task(struct isci_host *ihost, struct sas_task *task)
{
if (task) {
BUG_ON(!list_empty(&task->list));
kfree(task);
}
}
static int isci_smp_execute_task(struct isci_host *ihost, static int isci_smp_execute_task(struct isci_host *ihost,
struct domain_device *dev, void *req, struct domain_device *dev, void *req,
int req_size, void *resp, int resp_size) int req_size, void *resp, int resp_size)
...@@ -1376,7 +1353,7 @@ static int isci_smp_execute_task(struct isci_host *ihost, ...@@ -1376,7 +1353,7 @@ static int isci_smp_execute_task(struct isci_host *ihost,
struct sas_task *task = NULL; struct sas_task *task = NULL;
for (retry = 0; retry < 3; retry++) { for (retry = 0; retry < 3; retry++) {
task = isci_alloc_task(); task = sas_alloc_task(GFP_KERNEL);
if (!task) if (!task)
return -ENOMEM; return -ENOMEM;
...@@ -1439,13 +1416,13 @@ static int isci_smp_execute_task(struct isci_host *ihost, ...@@ -1439,13 +1416,13 @@ static int isci_smp_execute_task(struct isci_host *ihost,
SAS_ADDR(dev->sas_addr), SAS_ADDR(dev->sas_addr),
task->task_status.resp, task->task_status.resp,
task->task_status.stat); task->task_status.stat);
isci_free_task(ihost, task); sas_free_task(task);
task = NULL; task = NULL;
} }
} }
ex_err: ex_err:
BUG_ON(retry == 3 && task != NULL); BUG_ON(retry == 3 && task != NULL);
isci_free_task(ihost, task); sas_free_task(task);
return res; return res;
} }
......
...@@ -37,7 +37,32 @@ ...@@ -37,7 +37,32 @@
#include "../scsi_sas_internal.h" #include "../scsi_sas_internal.h"
struct kmem_cache *sas_task_cache; static struct kmem_cache *sas_task_cache;
struct sas_task *sas_alloc_task(gfp_t flags)
{
struct sas_task *task = kmem_cache_zalloc(sas_task_cache, flags);
if (task) {
INIT_LIST_HEAD(&task->list);
spin_lock_init(&task->task_state_lock);
task->task_state_flags = SAS_TASK_STATE_PENDING;
init_timer(&task->timer);
init_completion(&task->completion);
}
return task;
}
EXPORT_SYMBOL_GPL(sas_alloc_task);
void sas_free_task(struct sas_task *task)
{
if (task) {
BUG_ON(!list_empty(&task->list));
kmem_cache_free(sas_task_cache, task);
}
}
EXPORT_SYMBOL_GPL(sas_free_task);
/*------------ SAS addr hash -----------*/ /*------------ SAS addr hash -----------*/
void sas_hash_addr(u8 *hashed, const u8 *sas_addr) void sas_hash_addr(u8 *hashed, const u8 *sas_addr)
...@@ -293,8 +318,7 @@ EXPORT_SYMBOL_GPL(sas_domain_release_transport); ...@@ -293,8 +318,7 @@ EXPORT_SYMBOL_GPL(sas_domain_release_transport);
static int __init sas_class_init(void) static int __init sas_class_init(void)
{ {
sas_task_cache = kmem_cache_create("sas_task", sizeof(struct sas_task), sas_task_cache = KMEM_CACHE(sas_task, SLAB_HWCACHE_ALIGN);
0, SLAB_HWCACHE_ALIGN, NULL);
if (!sas_task_cache) if (!sas_task_cache)
return -ENOMEM; return -ENOMEM;
......
...@@ -1387,28 +1387,6 @@ void mvs_dev_gone(struct domain_device *dev) ...@@ -1387,28 +1387,6 @@ void mvs_dev_gone(struct domain_device *dev)
mvs_dev_gone_notify(dev); mvs_dev_gone_notify(dev);
} }
static struct sas_task *mvs_alloc_task(void)
{
struct sas_task *task = kzalloc(sizeof(struct sas_task), GFP_KERNEL);
if (task) {
INIT_LIST_HEAD(&task->list);
spin_lock_init(&task->task_state_lock);
task->task_state_flags = SAS_TASK_STATE_PENDING;
init_timer(&task->timer);
init_completion(&task->completion);
}
return task;
}
static void mvs_free_task(struct sas_task *task)
{
if (task) {
BUG_ON(!list_empty(&task->list));
kfree(task);
}
}
static void mvs_task_done(struct sas_task *task) static void mvs_task_done(struct sas_task *task)
{ {
if (!del_timer(&task->timer)) if (!del_timer(&task->timer))
...@@ -1432,7 +1410,7 @@ static int mvs_exec_internal_tmf_task(struct domain_device *dev, ...@@ -1432,7 +1410,7 @@ static int mvs_exec_internal_tmf_task(struct domain_device *dev,
struct sas_task *task = NULL; struct sas_task *task = NULL;
for (retry = 0; retry < 3; retry++) { for (retry = 0; retry < 3; retry++) {
task = mvs_alloc_task(); task = sas_alloc_task(GFP_KERNEL);
if (!task) if (!task)
return -ENOMEM; return -ENOMEM;
...@@ -1490,15 +1468,14 @@ static int mvs_exec_internal_tmf_task(struct domain_device *dev, ...@@ -1490,15 +1468,14 @@ static int mvs_exec_internal_tmf_task(struct domain_device *dev,
SAS_ADDR(dev->sas_addr), SAS_ADDR(dev->sas_addr),
task->task_status.resp, task->task_status.resp,
task->task_status.stat); task->task_status.stat);
mvs_free_task(task); sas_free_task(task);
task = NULL; task = NULL;
} }
} }
ex_err: ex_err:
BUG_ON(retry == 3 && task != NULL); BUG_ON(retry == 3 && task != NULL);
if (task != NULL) sas_free_task(task);
mvs_free_task(task);
return res; return res;
} }
......
...@@ -669,30 +669,6 @@ int pm8001_dev_found(struct domain_device *dev) ...@@ -669,30 +669,6 @@ int pm8001_dev_found(struct domain_device *dev)
return pm8001_dev_found_notify(dev); return pm8001_dev_found_notify(dev);
} }
/**
* pm8001_alloc_task - allocate a task structure for TMF
*/
static struct sas_task *pm8001_alloc_task(void)
{
struct sas_task *task = kzalloc(sizeof(*task), GFP_KERNEL);
if (task) {
INIT_LIST_HEAD(&task->list);
spin_lock_init(&task->task_state_lock);
task->task_state_flags = SAS_TASK_STATE_PENDING;
init_timer(&task->timer);
init_completion(&task->completion);
}
return task;
}
static void pm8001_free_task(struct sas_task *task)
{
if (task) {
BUG_ON(!list_empty(&task->list));
kfree(task);
}
}
static void pm8001_task_done(struct sas_task *task) static void pm8001_task_done(struct sas_task *task)
{ {
if (!del_timer(&task->timer)) if (!del_timer(&task->timer))
...@@ -728,7 +704,7 @@ static int pm8001_exec_internal_tmf_task(struct domain_device *dev, ...@@ -728,7 +704,7 @@ static int pm8001_exec_internal_tmf_task(struct domain_device *dev,
struct pm8001_hba_info *pm8001_ha = pm8001_find_ha_by_dev(dev); struct pm8001_hba_info *pm8001_ha = pm8001_find_ha_by_dev(dev);
for (retry = 0; retry < 3; retry++) { for (retry = 0; retry < 3; retry++) {
task = pm8001_alloc_task(); task = sas_alloc_task(GFP_KERNEL);
if (!task) if (!task)
return -ENOMEM; return -ENOMEM;
...@@ -789,14 +765,13 @@ static int pm8001_exec_internal_tmf_task(struct domain_device *dev, ...@@ -789,14 +765,13 @@ static int pm8001_exec_internal_tmf_task(struct domain_device *dev,
SAS_ADDR(dev->sas_addr), SAS_ADDR(dev->sas_addr),
task->task_status.resp, task->task_status.resp,
task->task_status.stat)); task->task_status.stat));
pm8001_free_task(task); sas_free_task(task);
task = NULL; task = NULL;
} }
} }
ex_err: ex_err:
BUG_ON(retry == 3 && task != NULL); BUG_ON(retry == 3 && task != NULL);
if (task != NULL) sas_free_task(task);
pm8001_free_task(task);
return res; return res;
} }
...@@ -811,7 +786,7 @@ pm8001_exec_internal_task_abort(struct pm8001_hba_info *pm8001_ha, ...@@ -811,7 +786,7 @@ pm8001_exec_internal_task_abort(struct pm8001_hba_info *pm8001_ha,
struct sas_task *task = NULL; struct sas_task *task = NULL;
for (retry = 0; retry < 3; retry++) { for (retry = 0; retry < 3; retry++) {
task = pm8001_alloc_task(); task = sas_alloc_task(GFP_KERNEL);
if (!task) if (!task)
return -ENOMEM; return -ENOMEM;
...@@ -864,14 +839,13 @@ pm8001_exec_internal_task_abort(struct pm8001_hba_info *pm8001_ha, ...@@ -864,14 +839,13 @@ pm8001_exec_internal_task_abort(struct pm8001_hba_info *pm8001_ha,
SAS_ADDR(dev->sas_addr), SAS_ADDR(dev->sas_addr),
task->task_status.resp, task->task_status.resp,
task->task_status.stat)); task->task_status.stat));
pm8001_free_task(task); sas_free_task(task);
task = NULL; task = NULL;
} }
} }
ex_err: ex_err:
BUG_ON(retry == 3 && task != NULL); BUG_ON(retry == 3 && task != NULL);
if (task != NULL) sas_free_task(task);
pm8001_free_task(task);
return res; return res;
} }
......
...@@ -555,36 +555,14 @@ struct sas_task { ...@@ -555,36 +555,14 @@ struct sas_task {
struct work_struct abort_work; struct work_struct abort_work;
}; };
extern struct kmem_cache *sas_task_cache;
#define SAS_TASK_STATE_PENDING 1 #define SAS_TASK_STATE_PENDING 1
#define SAS_TASK_STATE_DONE 2 #define SAS_TASK_STATE_DONE 2
#define SAS_TASK_STATE_ABORTED 4 #define SAS_TASK_STATE_ABORTED 4
#define SAS_TASK_NEED_DEV_RESET 8 #define SAS_TASK_NEED_DEV_RESET 8
#define SAS_TASK_AT_INITIATOR 16 #define SAS_TASK_AT_INITIATOR 16
static inline struct sas_task *sas_alloc_task(gfp_t flags) extern struct sas_task *sas_alloc_task(gfp_t flags);
{ extern void sas_free_task(struct sas_task *task);
struct sas_task *task = kmem_cache_zalloc(sas_task_cache, flags);
if (task) {
INIT_LIST_HEAD(&task->list);
spin_lock_init(&task->task_state_lock);
task->task_state_flags = SAS_TASK_STATE_PENDING;
init_timer(&task->timer);
init_completion(&task->completion);
}
return task;
}
static inline void sas_free_task(struct sas_task *task)
{
if (task) {
BUG_ON(!list_empty(&task->list));
kmem_cache_free(sas_task_cache, task);
}
}
struct sas_domain_function_template { struct sas_domain_function_template {
/* The class calls these to notify the LLDD of an event. */ /* The class calls these to notify the LLDD of an event. */
......
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