aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi
diff options
context:
space:
mode:
authorDan Williams <dan.j.williams@intel.com>2011-07-29 20:26:39 -0400
committerJames Bottomley <JBottomley@Parallels.com>2011-08-27 10:35:13 -0400
commit4fcf812ca392303aa79dd50e96e83a29faa13bd0 (patch)
tree411c33d701989b44ba2f4ecb64fd0cba92214958 /drivers/scsi
parent7ca3c803e85080afdff4097e60fefec865027809 (diff)
[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: Jack Wang <jack_wang@usish.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com> Signed-off-by: James Bottomley <JBottomley@Parallels.com>
Diffstat (limited to 'drivers/scsi')
-rw-r--r--drivers/scsi/isci/task.c29
-rw-r--r--drivers/scsi/libsas/sas_init.c30
-rw-r--r--drivers/scsi/mvsas/mv_sas.c29
-rw-r--r--drivers/scsi/pm8001/pm8001_sas.c38
4 files changed, 39 insertions, 87 deletions
diff --git a/drivers/scsi/isci/task.c b/drivers/scsi/isci/task.c
index d6bcdd013dc9..e2d9418683ce 100644
--- a/drivers/scsi/isci/task.c
+++ b/drivers/scsi/isci/task.c
@@ -1345,29 +1345,6 @@ static void isci_smp_task_done(struct sas_task *task)
1345 complete(&task->completion); 1345 complete(&task->completion);
1346} 1346}
1347 1347
1348static struct sas_task *isci_alloc_task(void)
1349{
1350 struct sas_task *task = kzalloc(sizeof(*task), GFP_KERNEL);
1351
1352 if (task) {
1353 INIT_LIST_HEAD(&task->list);
1354 spin_lock_init(&task->task_state_lock);
1355 task->task_state_flags = SAS_TASK_STATE_PENDING;
1356 init_timer(&task->timer);
1357 init_completion(&task->completion);
1358 }
1359
1360 return task;
1361}
1362
1363static void isci_free_task(struct isci_host *ihost, struct sas_task *task)
1364{
1365 if (task) {
1366 BUG_ON(!list_empty(&task->list));
1367 kfree(task);
1368 }
1369}
1370
1371static int isci_smp_execute_task(struct isci_host *ihost, 1348static int isci_smp_execute_task(struct isci_host *ihost,
1372 struct domain_device *dev, void *req, 1349 struct domain_device *dev, void *req,
1373 int req_size, void *resp, int resp_size) 1350 int req_size, void *resp, int resp_size)
@@ -1376,7 +1353,7 @@ static int isci_smp_execute_task(struct isci_host *ihost,
1376 struct sas_task *task = NULL; 1353 struct sas_task *task = NULL;
1377 1354
1378 for (retry = 0; retry < 3; retry++) { 1355 for (retry = 0; retry < 3; retry++) {
1379 task = isci_alloc_task(); 1356 task = sas_alloc_task(GFP_KERNEL);
1380 if (!task) 1357 if (!task)
1381 return -ENOMEM; 1358 return -ENOMEM;
1382 1359
@@ -1439,13 +1416,13 @@ static int isci_smp_execute_task(struct isci_host *ihost,
1439 SAS_ADDR(dev->sas_addr), 1416 SAS_ADDR(dev->sas_addr),
1440 task->task_status.resp, 1417 task->task_status.resp,
1441 task->task_status.stat); 1418 task->task_status.stat);
1442 isci_free_task(ihost, task); 1419 sas_free_task(task);
1443 task = NULL; 1420 task = NULL;
1444 } 1421 }
1445 } 1422 }
1446ex_err: 1423ex_err:
1447 BUG_ON(retry == 3 && task != NULL); 1424 BUG_ON(retry == 3 && task != NULL);
1448 isci_free_task(ihost, task); 1425 sas_free_task(task);
1449 return res; 1426 return res;
1450} 1427}
1451 1428
diff --git a/drivers/scsi/libsas/sas_init.c b/drivers/scsi/libsas/sas_init.c
index 2dc55343f671..dd56ea827665 100644
--- a/drivers/scsi/libsas/sas_init.c
+++ b/drivers/scsi/libsas/sas_init.c
@@ -37,7 +37,32 @@
37 37
38#include "../scsi_sas_internal.h" 38#include "../scsi_sas_internal.h"
39 39
40struct kmem_cache *sas_task_cache; 40static struct kmem_cache *sas_task_cache;
41
42struct sas_task *sas_alloc_task(gfp_t flags)
43{
44 struct sas_task *task = kmem_cache_zalloc(sas_task_cache, flags);
45
46 if (task) {
47 INIT_LIST_HEAD(&task->list);
48 spin_lock_init(&task->task_state_lock);
49 task->task_state_flags = SAS_TASK_STATE_PENDING;
50 init_timer(&task->timer);
51 init_completion(&task->completion);
52 }
53
54 return task;
55}
56EXPORT_SYMBOL_GPL(sas_alloc_task);
57
58void sas_free_task(struct sas_task *task)
59{
60 if (task) {
61 BUG_ON(!list_empty(&task->list));
62 kmem_cache_free(sas_task_cache, task);
63 }
64}
65EXPORT_SYMBOL_GPL(sas_free_task);
41 66
42/*------------ SAS addr hash -----------*/ 67/*------------ SAS addr hash -----------*/
43void sas_hash_addr(u8 *hashed, const u8 *sas_addr) 68void sas_hash_addr(u8 *hashed, const u8 *sas_addr)
@@ -293,8 +318,7 @@ EXPORT_SYMBOL_GPL(sas_domain_release_transport);
293 318
294static int __init sas_class_init(void) 319static int __init sas_class_init(void)
295{ 320{
296 sas_task_cache = kmem_cache_create("sas_task", sizeof(struct sas_task), 321 sas_task_cache = KMEM_CACHE(sas_task, SLAB_HWCACHE_ALIGN);
297 0, SLAB_HWCACHE_ALIGN, NULL);
298 if (!sas_task_cache) 322 if (!sas_task_cache)
299 return -ENOMEM; 323 return -ENOMEM;
300 324
diff --git a/drivers/scsi/mvsas/mv_sas.c b/drivers/scsi/mvsas/mv_sas.c
index 4958fefff365..4196eee33dc9 100644
--- a/drivers/scsi/mvsas/mv_sas.c
+++ b/drivers/scsi/mvsas/mv_sas.c
@@ -1387,28 +1387,6 @@ void mvs_dev_gone(struct domain_device *dev)
1387 mvs_dev_gone_notify(dev); 1387 mvs_dev_gone_notify(dev);
1388} 1388}
1389 1389
1390static struct sas_task *mvs_alloc_task(void)
1391{
1392 struct sas_task *task = kzalloc(sizeof(struct sas_task), GFP_KERNEL);
1393
1394 if (task) {
1395 INIT_LIST_HEAD(&task->list);
1396 spin_lock_init(&task->task_state_lock);
1397 task->task_state_flags = SAS_TASK_STATE_PENDING;
1398 init_timer(&task->timer);
1399 init_completion(&task->completion);
1400 }
1401 return task;
1402}
1403
1404static void mvs_free_task(struct sas_task *task)
1405{
1406 if (task) {
1407 BUG_ON(!list_empty(&task->list));
1408 kfree(task);
1409 }
1410}
1411
1412static void mvs_task_done(struct sas_task *task) 1390static void mvs_task_done(struct sas_task *task)
1413{ 1391{
1414 if (!del_timer(&task->timer)) 1392 if (!del_timer(&task->timer))
@@ -1432,7 +1410,7 @@ static int mvs_exec_internal_tmf_task(struct domain_device *dev,
1432 struct sas_task *task = NULL; 1410 struct sas_task *task = NULL;
1433 1411
1434 for (retry = 0; retry < 3; retry++) { 1412 for (retry = 0; retry < 3; retry++) {
1435 task = mvs_alloc_task(); 1413 task = sas_alloc_task(GFP_KERNEL);
1436 if (!task) 1414 if (!task)
1437 return -ENOMEM; 1415 return -ENOMEM;
1438 1416
@@ -1490,15 +1468,14 @@ static int mvs_exec_internal_tmf_task(struct domain_device *dev,
1490 SAS_ADDR(dev->sas_addr), 1468 SAS_ADDR(dev->sas_addr),
1491 task->task_status.resp, 1469 task->task_status.resp,
1492 task->task_status.stat); 1470 task->task_status.stat);
1493 mvs_free_task(task); 1471 sas_free_task(task);
1494 task = NULL; 1472 task = NULL;
1495 1473
1496 } 1474 }
1497 } 1475 }
1498ex_err: 1476ex_err:
1499 BUG_ON(retry == 3 && task != NULL); 1477 BUG_ON(retry == 3 && task != NULL);
1500 if (task != NULL) 1478 sas_free_task(task);
1501 mvs_free_task(task);
1502 return res; 1479 return res;
1503} 1480}
1504 1481
diff --git a/drivers/scsi/pm8001/pm8001_sas.c b/drivers/scsi/pm8001/pm8001_sas.c
index 6ae059ebb4bb..7dbbf8bb4d88 100644
--- a/drivers/scsi/pm8001/pm8001_sas.c
+++ b/drivers/scsi/pm8001/pm8001_sas.c
@@ -669,30 +669,6 @@ int pm8001_dev_found(struct domain_device *dev)
669 return pm8001_dev_found_notify(dev); 669 return pm8001_dev_found_notify(dev);
670} 670}
671 671
672/**
673 * pm8001_alloc_task - allocate a task structure for TMF
674 */
675static struct sas_task *pm8001_alloc_task(void)
676{
677 struct sas_task *task = kzalloc(sizeof(*task), GFP_KERNEL);
678 if (task) {
679 INIT_LIST_HEAD(&task->list);
680 spin_lock_init(&task->task_state_lock);
681 task->task_state_flags = SAS_TASK_STATE_PENDING;
682 init_timer(&task->timer);
683 init_completion(&task->completion);
684 }
685 return task;
686}
687
688static void pm8001_free_task(struct sas_task *task)
689{
690 if (task) {
691 BUG_ON(!list_empty(&task->list));
692 kfree(task);
693 }
694}
695
696static void pm8001_task_done(struct sas_task *task) 672static void pm8001_task_done(struct sas_task *task)
697{ 673{
698 if (!del_timer(&task->timer)) 674 if (!del_timer(&task->timer))
@@ -728,7 +704,7 @@ static int pm8001_exec_internal_tmf_task(struct domain_device *dev,
728 struct pm8001_hba_info *pm8001_ha = pm8001_find_ha_by_dev(dev); 704 struct pm8001_hba_info *pm8001_ha = pm8001_find_ha_by_dev(dev);
729 705
730 for (retry = 0; retry < 3; retry++) { 706 for (retry = 0; retry < 3; retry++) {
731 task = pm8001_alloc_task(); 707 task = sas_alloc_task(GFP_KERNEL);
732 if (!task) 708 if (!task)
733 return -ENOMEM; 709 return -ENOMEM;
734 710
@@ -789,14 +765,13 @@ static int pm8001_exec_internal_tmf_task(struct domain_device *dev,
789 SAS_ADDR(dev->sas_addr), 765 SAS_ADDR(dev->sas_addr),
790 task->task_status.resp, 766 task->task_status.resp,
791 task->task_status.stat)); 767 task->task_status.stat));
792 pm8001_free_task(task); 768 sas_free_task(task);
793 task = NULL; 769 task = NULL;
794 } 770 }
795 } 771 }
796ex_err: 772ex_err:
797 BUG_ON(retry == 3 && task != NULL); 773 BUG_ON(retry == 3 && task != NULL);
798 if (task != NULL) 774 sas_free_task(task);
799 pm8001_free_task(task);
800 return res; 775 return res;
801} 776}
802 777
@@ -811,7 +786,7 @@ pm8001_exec_internal_task_abort(struct pm8001_hba_info *pm8001_ha,
811 struct sas_task *task = NULL; 786 struct sas_task *task = NULL;
812 787
813 for (retry = 0; retry < 3; retry++) { 788 for (retry = 0; retry < 3; retry++) {
814 task = pm8001_alloc_task(); 789 task = sas_alloc_task(GFP_KERNEL);
815 if (!task) 790 if (!task)
816 return -ENOMEM; 791 return -ENOMEM;
817 792
@@ -864,14 +839,13 @@ pm8001_exec_internal_task_abort(struct pm8001_hba_info *pm8001_ha,
864 SAS_ADDR(dev->sas_addr), 839 SAS_ADDR(dev->sas_addr),
865 task->task_status.resp, 840 task->task_status.resp,
866 task->task_status.stat)); 841 task->task_status.stat));
867 pm8001_free_task(task); 842 sas_free_task(task);
868 task = NULL; 843 task = NULL;
869 } 844 }
870 } 845 }
871ex_err: 846ex_err:
872 BUG_ON(retry == 3 && task != NULL); 847 BUG_ON(retry == 3 && task != NULL);
873 if (task != NULL) 848 sas_free_task(task);
874 pm8001_free_task(task);
875 return res; 849 return res;
876} 850}
877 851