41 #include <linux/slab.h>
73 pm8001_tag_clear(pm8001_ha, tag);
96 pm8001_tag_set(pm8001_ha, tag);
104 for (i = 0; i < pm8001_ha->
tags_num; ++
i)
105 pm8001_tag_clear(pm8001_ha, i);
123 u64 align_offset = 0;
128 if (!mem_virt_alloc) {
132 memset((
void *)mem_virt_alloc, 0, mem_size+align);
133 *pphys_addr = mem_dma_handle;
134 phys_align = (*pphys_addr + align_offset) & ~align_offset;
135 *virt_addr = (
void *)mem_virt_alloc + phys_align - *pphys_addr;
170 pm8001_ha = sas_phy->
ha->lldd_ha;
176 pm8001_ha->
phy[
phy_id].minimum_linkrate =
180 pm8001_ha->
phy[
phy_id].maximum_linkrate =
183 if (pm8001_ha->
phy[
phy_id].phy_state == 0) {
191 if (pm8001_ha->
phy[
phy_id].phy_state == 0) {
199 if (pm8001_ha->
phy[
phy_id].phy_state == 0) {
216 (
phy_id < 4) ? 0x30000 : 0x40000)) {
217 spin_unlock_irqrestore(&pm8001_ha->
lock, flags);
221 struct sas_phy *
phy = sas_phy->
phy;
223 pm8001_ha->
io_mem[2].memvirtaddr)
224 + 0x1034 + (0x4000 * (
phy_id & 3)));
232 spin_unlock_irqrestore(&pm8001_ha->
lock, flags);
253 for (i = 0; i < pm8001_ha->
chip->n_phy; ++
i)
335 return dev->
port->id;
339 return pdev->
port->id;
354 #define DEV_IS_GONE(pm8001_dev) \
355 ((!pm8001_dev || (pm8001_dev->dev_type == NO_DEVICE)))
356 static int pm8001_task_exec(
struct sas_task *task,
const int num,
367 unsigned long flags = 0;
377 pm8001_ha = pm8001_find_ha_by_dev(task->
dev);
383 port = &pm8001_ha->
port[sas_find_local_port_id(dev)];
390 spin_unlock_irqrestore(&pm8001_ha->
lock, flags);
434 rc = pm8001_task_prep_smp(pm8001_ha, ccb);
438 rc = pm8001_task_prep_ssp_tm(pm8001_ha,
441 rc = pm8001_task_prep_ssp(pm8001_ha, ccb);
446 rc = pm8001_task_prep_ata(pm8001_ha, ccb);
450 "unknown sas_task proto: 0x%x\n",
473 pm8001_tag_free(pm8001_ha, tag);
475 dev_printk(
KERN_ERR, pm8001_ha->
dev,
"pm8001 exec failed[%d]!\n",
rc);
481 spin_unlock_irqrestore(&pm8001_ha->
lock, flags);
496 return pm8001_task_exec(task, num, gfp_flags, 0,
NULL);
501 pm8001_tag_clear(pm8001_ha, ccb_idx);
556 if (dev == PM8001_MAX_DEVICES) {
559 PM8001_MAX_DEVICES));
564 static void pm8001_free_dev(
struct pm8001_device *pm8001_dev)
566 u32 id = pm8001_dev->
id;
567 memset(pm8001_dev, 0,
sizeof(*pm8001_dev));
586 static int pm8001_dev_found_notify(
struct domain_device *dev)
588 unsigned long flags = 0;
595 pm8001_ha = pm8001_find_ha_by_dev(dev);
599 if (!pm8001_device) {
610 for (phy_id = 0; phy_id < parent_dev->
ex_dev.num_phys;
619 if (phy_id == parent_dev->
ex_dev.num_phys) {
629 dev->
rphy->identify.phy_identifier;
635 spin_unlock_irqrestore(&pm8001_ha->
lock, flags);
642 spin_unlock_irqrestore(&pm8001_ha->
lock, flags);
648 return pm8001_dev_found_notify(dev);
651 static void pm8001_task_done(
struct sas_task *task)
658 static void pm8001_tmf_timedout(
unsigned long data)
666 #define PM8001_TASK_TIMEOUT 20
678 static int pm8001_exec_internal_tmf_task(
struct domain_device *dev,
685 for (retry = 0; retry < 3; retry++) {
695 task->
slow_task->timer.function = pm8001_tmf_timedout;
699 res = pm8001_task_exec(task, 1,
GFP_KERNEL, 1, tmf);
743 "0x%x status 0x%x\n",
767 for (retry = 0; retry < 3; retry++) {
776 task->
slow_task->timer.function = pm8001_tmf_timedout;
783 ccb = &pm8001_ha->
ccb_info[ccb_tag];
789 pm8001_dev, flag, task_tag, ccb_tag);
817 "0x%x status 0x%x\n",
835 static void pm8001_dev_gone_notify(
struct domain_device *dev)
837 unsigned long flags = 0;
840 struct pm8001_device *pm8001_dev = dev->
lldd_dev;
842 pm8001_ha = pm8001_find_ha_by_dev(dev);
852 spin_unlock_irqrestore(&pm8001_ha->
lock, flags);
853 pm8001_exec_internal_task_abort(pm8001_ha, pm8001_dev ,
858 pm8001_free_dev(pm8001_dev);
864 spin_unlock_irqrestore(&pm8001_ha->
lock, flags);
869 pm8001_dev_gone_notify(dev);
888 struct pm8001_device *device_to_close)
893 if (pm8001_ha ==
NULL)
901 struct pm8001_device *pm8001_dev;
909 if (!device_to_close) {
912 if (((d %
sizeof(*pm8001_dev)) != 0)
915 }
else if (pm8001_dev != device_to_close)
918 if (!tag || (tag == 0xFFFFFFFF))
923 if (task_to_close && (task != task_to_close))
946 spin_unlock_irqrestore(&pm8001_ha->
lock, flags);
952 spin_unlock_irqrestore(&pm8001_ha->
lock, flags);
962 struct pm8001_device *pm8001_dev;
970 pm8001_ha = pm8001_find_ha_by_dev(dev);
973 if (dev_is_sata(dev)) {
981 rc = pm8001_exec_internal_task_abort(pm8001_ha, pm8001_dev ,
994 sas_put_local_phy(phy);
1003 struct pm8001_device *pm8001_dev = dev->
lldd_dev;
1005 if (dev_is_sata(dev)) {
1007 rc = pm8001_exec_internal_task_abort(pm8001_ha, pm8001_dev ,
1010 sas_put_local_phy(phy);
1016 rc = pm8001_issue_ssp_tmf(dev, lun, &tmf_task);
1027 u32 tag = 0xdeadbeef;
1039 pm8001_find_ha_by_dev(dev);
1042 rc = pm8001_find_tag(task, &tag);
1048 for (i = 0; i < 16; i++)
1054 rc = pm8001_issue_ssp_tmf(dev, lun.
scsi_lun, &tmf_task);
1066 " reset the phy\n"));
1077 unsigned long flags;
1078 u32 tag = 0xdeadbeef;
1084 struct pm8001_device *pm8001_dev;
1101 pm8001_ha = pm8001_find_ha_by_dev(dev);
1103 rc = pm8001_find_tag(task, &tag);
1114 rc = pm8001_issue_ssp_tmf(dev, lun.
scsi_lun, &tmf_task);
1115 pm8001_exec_internal_task_abort(pm8001_ha, pm8001_dev,
1121 pm8001_ha = pm8001_find_ha_by_dev(dev);
1122 rc = pm8001_find_tag(task, &tag);
1128 rc = pm8001_exec_internal_task_abort(pm8001_ha, pm8001_dev,
1134 pm8001_ha = pm8001_find_ha_by_dev(dev);
1135 rc = pm8001_find_tag(task, &tag);
1141 rc = pm8001_exec_internal_task_abort(pm8001_ha, pm8001_dev,
1157 rc = pm8001_issue_ssp_tmf(dev, lun, &tmf_task);
1167 rc = pm8001_issue_ssp_tmf(dev, lun, &tmf_task);
1176 struct pm8001_device *pm8001_dev = dev->
lldd_dev;
1183 rc = pm8001_issue_ssp_tmf(dev, lun, &tmf_task);