33 #include <linux/kernel.h>
35 #include <linux/types.h>
36 #include <linux/sched.h>
37 #include <linux/pci.h>
39 #include <linux/slab.h>
46 #include <scsi/scsi.h>
64 "allocate hardware fibs pci_alloc_consistent(%p, %d * (%d + %d), %p)\n",
108 while (((i = fib_map_alloc(dev)) == -
ENOMEM)
135 for (i = 0, fibptr = &dev->
fibs[i];
143 fibptr->
next = fibptr+1;
149 hw_fib = (
struct hw_fib *)((
unsigned char *)hw_fib +
151 hw_fib_pa = hw_fib_pa +
180 spin_unlock_irqrestore(&dev->
fib_lock, flags);
184 spin_unlock_irqrestore(&dev->
fib_lock, flags);
189 fibptr->
size =
sizeof(
struct fib);
211 unsigned long flags, flagsv;
214 if (fibptr->
done == 2) {
215 spin_unlock_irqrestore(&fibptr->
event_lock, flagsv);
218 spin_unlock_irqrestore(&fibptr->
event_lock, flagsv);
223 if (fibptr->
hw_fib_va->header.XferState != 0) {
224 printk(
KERN_WARNING "aac_fib_free, XferState != 0, fibptr = 0x%p, XferState = 0x%x\n",
228 fibptr->
next = fibptr->
dev->free_fib;
229 fibptr->
dev->free_fib = fibptr;
230 spin_unlock_irqrestore(&fibptr->
dev->fib_lock, flags);
260 static void fib_dealloc(
struct fib * fibptr)
263 hw_fib->
header.XferState = 0;
355 while (!aac_get_entry(dev, qid, &entry, index, nonotify)) {
364 while (!aac_get_entry(dev, qid, &entry, index, nonotify)) {
371 entry->
addr = hw_fib->
header.SenderFibAddress;
373 hw_fib->
header.u.ReceiverFibAddress = hw_fib->
header.SenderFibAddress;
416 unsigned long flags = 0;
417 unsigned long qflags;
418 unsigned long mflags = 0;
436 if (wait && !reply) {
438 }
else if (!wait && reply) {
441 }
else if (!wait && !reply) {
444 }
else if (wait && reply) {
517 spin_unlock_irqrestore(&fibptr->
event_lock, flags);
521 spin_unlock_irqrestore(&dev->
sync_lock, sflags);
524 spin_unlock_irqrestore(&dev->
sync_lock, sflags);
543 spin_unlock_irqrestore(&fibptr->
event_lock, flags);
557 spin_unlock_irqrestore(&fibptr->
event_lock, flags);
573 spin_unlock_irqrestore(q->
lock, qflags);
575 printk(
KERN_ERR "aacraid: aac_fib_send: first asynchronous command timed out.\n"
576 "Usually a result of a PCI interrupt routing problem;\n"
577 "update mother board BIOS or consider utilizing one of\n"
578 "the SAFE mode kernel options (acpi, apic etc)\n");
585 "Usually a result of a serious unrecoverable hardware problem\n",
601 if (fibptr->
done == 0) {
603 spin_unlock_irqrestore(&fibptr->
event_lock, flags);
606 spin_unlock_irqrestore(&fibptr->
event_lock, flags);
677 le32_add_cpu(q->
headers.consumer, 1);
710 unsigned long nointr = 0;
711 unsigned long qflags;
719 if (hw_fib->
header.XferState == 0) {
757 spin_unlock_irqrestore(q->
lock, qflags);
763 "Unknown xferstate detected.\n");
785 if (hw_fib->
header.XferState == 0)
802 if (fibptr->
done == 2) {
803 spin_unlock_irqrestore(&fibptr->
event_lock, flags);
806 spin_unlock_irqrestore(&fibptr->
event_lock, flags);
842 int length = val & 0xffff;
843 int level = (val >> 16) & 0xffff;
871 #define AIF_SNIFF_TIMEOUT (30*HZ)
872 static void aac_handle_aif(
struct aac_dev * dev,
struct fib * fibptr)
883 } device_config_needed =
NOTHING;
922 dev->
fsa_dev[container].config_needed = CHANGE;
934 if (container != (
u32)-1) {
937 if ((dev->
fsa_dev[container].config_waiting_on ==
940 dev->
fsa_dev[container].config_waiting_on = 0;
941 }
else for (container = 0;
943 if ((dev->
fsa_dev[container].config_waiting_on ==
946 dev->
fsa_dev[container].config_waiting_on = 0;
964 dev->
fsa_dev[container].config_waiting_on =
977 dev->
fsa_dev[container].config_waiting_on =
990 if (dev->
fsa_dev[container].config_waiting_on &&
993 dev->
fsa_dev[container].config_needed = CHANGE;
994 dev->
fsa_dev[container].config_waiting_on =
1005 if ((container >> 28)) {
1006 container = (
u32)-1;
1009 channel = (container >> 24) & 0xF;
1011 container = (
u32)-1;
1014 id = container & 0xFFFF;
1016 container = (
u32)-1;
1019 lun = (container >> 16) & 0xFF;
1020 container = (
u32)-1;
1022 device_config_needed =
1023 (((
__le32 *)aifcmd->data)[0] ==
1025 if (device_config_needed ==
ADD) {
1048 ((
__le32 *)aifcmd->data)[2]);
1049 if ((container >> 28)) {
1050 container = (
u32)-1;
1053 channel = (container >> 24) & 0xF;
1055 container = (
u32)-1;
1058 id = container & 0xFFFF;
1059 lun = (container >> 16) & 0xFF;
1060 container = (
u32)-1;
1064 ((
channel = (
id >> 7) & 0x3F) >=
1067 lun = (
id >> 4) & 7;
1071 device_config_needed =
1072 (((
__le32 *)aifcmd->data)[3]
1084 if (container != (
u32)-1) {
1087 if ((dev->
fsa_dev[container].config_waiting_on ==
1090 dev->
fsa_dev[container].config_waiting_on = 0;
1091 }
else for (container = 0;
1093 if ((dev->
fsa_dev[container].config_waiting_on ==
1096 dev->
fsa_dev[container].config_waiting_on = 0;
1110 (((
__le32 *)aifcmd->data)[6] == ((
__le32 *)aifcmd->data)[5] ||
1119 dev->
fsa_dev[container].config_waiting_on =
1122 dev->
fsa_dev[container].config_waiting_stamp =
1127 ((
__le32 *)aifcmd->data)[6] == 0 &&
1136 dev->
fsa_dev[container].config_waiting_on =
1139 dev->
fsa_dev[container].config_waiting_stamp =
1148 if (device_config_needed ==
NOTHING)
1150 if ((dev->
fsa_dev[container].config_waiting_on == 0) &&
1153 device_config_needed =
1154 dev->
fsa_dev[container].config_needed;
1162 if (device_config_needed ==
NOTHING)
1183 (device_config_needed !=
NOTHING)) {
1184 if (dev->
fsa_dev[container].valid == 1)
1185 dev->
fsa_dev[container].valid = 2;
1190 switch (device_config_needed) {
1192 #if (defined(AAC_DEBUG_INSTRUMENT_AIF_DELETE))
1195 if (scsi_device_online(
device)) {
1198 "Device offlined - %s\n",
1201 "enclosure services event");
1206 if (!scsi_device_online(
device)) {
1208 "Device online - %s\n",
1211 "enclosure services event");
1217 && (!dev->
fsa_dev[container].valid)) {
1218 #if (defined(AAC_DEBUG_INSTRUMENT_AIF_DELETE))
1221 if (!scsi_device_online(
device))
1225 "Device offlined - %s\n",
1236 device_config_needed =
NOTHING;
1238 if (device_config_needed ==
ADD)
1242 device_config_needed =
NOTHING;
1247 static int _aac_reset_adapter(
struct aac_dev *aac,
int forced)
1292 unsigned long flagv;
1295 spin_unlock_irqrestore(&fib->
event_lock, flagv);
1335 if (quirks & AAC_QUIRK_31BIT)
1340 if (IS_ERR(aac->
thread)) {
1341 retval = PTR_ERR(aac->
thread);
1360 command_list =
NULL;
1362 unsigned long flags;
1369 spin_unlock_irqrestore(&dev->
list_lock, flags);
1371 while ((command = command_list)) {
1372 command_list = (
struct scsi_cmnd *)command->
SCp.buffer;
1393 unsigned long flagv = 0;
1401 spin_unlock_irqrestore(&aac->
fib_lock, flagv);
1405 spin_unlock_irqrestore(&aac->
fib_lock, flagv);
1427 spin_unlock_irqrestore(&dev->
list_lock, flagv);
1445 spin_unlock_irqrestore(host->
host_lock, flagv);
1447 if ((forced < 2) && (retval == -
ENODEV)) {
1487 unsigned long time_now, flagv = 0;
1496 spin_unlock_irqrestore(&aac->
fib_lock, flagv);
1531 if (fibctx->
count > 20) {
1544 entry = entry->
next;
1553 hw_fib = kzalloc(
sizeof(
struct hw_fib),
GFP_ATOMIC);
1554 fib = kzalloc(
sizeof(
struct fib),
GFP_ATOMIC);
1555 if (fib && hw_fib) {
1562 fib->
size =
sizeof (
struct fib);
1588 entry = entry->
next;
1591 spin_unlock_irqrestore(&aac->
fib_lock, flagv);
1609 spin_unlock_irqrestore(host->
host_lock, flagv);
1632 struct fib *fib, *newfib;
1634 unsigned long flags;
1636 unsigned long next_jiffies =
jiffies +
HZ;
1637 unsigned long next_check_jiffies = next_jiffies;
1638 long difference =
HZ;
1665 fib =
list_entry(entry,
struct fib, fiblink);
1673 memset(fib, 0,
sizeof(
struct fib));
1675 fib->
size =
sizeof(
struct fib);
1685 aac_handle_aif(dev, fib);
1692 u32 time_now, time_last;
1693 unsigned long flagv;
1695 struct hw_fib ** hw_fib_pool, ** hw_fib_p;
1696 struct fib ** fib_pool, ** fib_p;
1703 aac_handle_aif(dev, fib);
1715 /
sizeof(
struct hw_fib);
1719 entry = entry->
next;
1722 spin_unlock_irqrestore(&dev->
fib_lock, flagv);
1728 hw_fib_p = hw_fib_pool;
1730 while (hw_fib_p < &hw_fib_pool[num]) {
1736 kfree(*(--hw_fib_p));
1740 if ((num = hw_fib_p - hw_fib_pool) == 0) {
1758 hw_fib_p = hw_fib_pool;
1769 if (fibctx->
count > 20)
1783 entry = entry->
next;
1792 if (hw_fib_p < &hw_fib_pool[num]) {
1793 hw_newfib = *hw_fib_p;
1794 *(hw_fib_p++) =
NULL;
1800 memcpy(hw_newfib, hw_fib,
sizeof(
struct hw_fib));
1801 memcpy(newfib, fib,
sizeof(
struct fib));
1817 entry = entry->
next;
1824 spin_unlock_irqrestore(&dev->
fib_lock, flagv);
1826 hw_fib_p = hw_fib_pool;
1828 while (hw_fib_p < &hw_fib_pool[num]) {
1848 if ((
time_before(next_check_jiffies,next_jiffies))
1849 && ((difference = next_check_jiffies -
jiffies) <= 0)) {
1850 next_check_jiffies = next_jiffies;
1854 next_check_jiffies =
jiffies + difference;
1859 && ((difference = next_jiffies -
jiffies) <= 0)) {
1865 if (!ret && !dev->
queues)
1873 if (((1000000 - (1000000 / HZ)) > now.
tv_usec)
1874 && (now.
tv_usec > (1000000 / HZ)))
1875 difference = (((1000000 - now.
tv_usec) * HZ)
1876 + 500000) / 1000000;
1877 else if (ret == 0) {
1911 difference = 10 *
HZ;
1913 next_jiffies =
jiffies + difference;
1915 difference = next_check_jiffies -
jiffies;
1917 if (difference <= 0)