comminit.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. /*
  2. * Adaptec AAC series RAID controller driver
  3. * (c) Copyright 2001 Red Hat Inc.
  4. *
  5. * based on the old aacraid driver that is..
  6. * Adaptec aacraid device driver for Linux.
  7. *
  8. * Copyright (c) 2000-2010 Adaptec, Inc.
  9. * 2010 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2, or (at your option)
  14. * any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; see the file COPYING. If not, write to
  23. * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  24. *
  25. * Module Name:
  26. * comminit.c
  27. *
  28. * Abstract: This supports the initialization of the host adapter commuication interface.
  29. * This is a platform dependent module for the pci cyclone board.
  30. *
  31. */
  32. #include <linux/kernel.h>
  33. #include <linux/init.h>
  34. #include <linux/types.h>
  35. #include <linux/pci.h>
  36. #include <linux/spinlock.h>
  37. #include <linux/slab.h>
  38. #include <linux/blkdev.h>
  39. #include <linux/delay.h>
  40. #include <linux/completion.h>
  41. #include <linux/mm.h>
  42. #include <scsi/scsi_host.h>
  43. #include "aacraid.h"
  44. struct aac_common aac_config = {
  45. .irq_mod = 1
  46. };
  47. static inline int aac_is_msix_mode(struct aac_dev *dev)
  48. {
  49. u32 status = 0;
  50. if (dev->pdev->device == PMC_DEVICE_S6 ||
  51. dev->pdev->device == PMC_DEVICE_S7 ||
  52. dev->pdev->device == PMC_DEVICE_S8) {
  53. status = src_readl(dev, MUnit.OMR);
  54. }
  55. return (status & AAC_INT_MODE_MSIX);
  56. }
  57. static inline void aac_change_to_intx(struct aac_dev *dev)
  58. {
  59. aac_src_access_devreg(dev, AAC_DISABLE_MSIX);
  60. aac_src_access_devreg(dev, AAC_ENABLE_INTX);
  61. }
  62. static int aac_alloc_comm(struct aac_dev *dev, void **commaddr, unsigned long commsize, unsigned long commalign)
  63. {
  64. unsigned char *base;
  65. unsigned long size, align;
  66. const unsigned long fibsize = dev->max_fib_size;
  67. const unsigned long printfbufsiz = 256;
  68. unsigned long host_rrq_size = 0;
  69. struct aac_init *init;
  70. dma_addr_t phys;
  71. unsigned long aac_max_hostphysmempages;
  72. if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE1 ||
  73. dev->comm_interface == AAC_COMM_MESSAGE_TYPE2)
  74. host_rrq_size = (dev->scsi_host_ptr->can_queue
  75. + AAC_NUM_MGT_FIB) * sizeof(u32);
  76. size = fibsize + sizeof(struct aac_init) + commsize +
  77. commalign + printfbufsiz + host_rrq_size;
  78. base = pci_alloc_consistent(dev->pdev, size, &phys);
  79. if(base == NULL)
  80. {
  81. printk(KERN_ERR "aacraid: unable to create mapping.\n");
  82. return 0;
  83. }
  84. dev->comm_addr = (void *)base;
  85. dev->comm_phys = phys;
  86. dev->comm_size = size;
  87. if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE1 ||
  88. dev->comm_interface == AAC_COMM_MESSAGE_TYPE2) {
  89. dev->host_rrq = (u32 *)(base + fibsize);
  90. dev->host_rrq_pa = phys + fibsize;
  91. memset(dev->host_rrq, 0, host_rrq_size);
  92. }
  93. dev->init = (struct aac_init *)(base + fibsize + host_rrq_size);
  94. dev->init_pa = phys + fibsize + host_rrq_size;
  95. init = dev->init;
  96. init->InitStructRevision = cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION);
  97. if (dev->max_fib_size != sizeof(struct hw_fib))
  98. init->InitStructRevision = cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION_4);
  99. init->Sa_MSIXVectors = cpu_to_le32(SA_INIT_NUM_MSIXVECTORS);
  100. init->fsrev = cpu_to_le32(dev->fsrev);
  101. /*
  102. * Adapter Fibs are the first thing allocated so that they
  103. * start page aligned
  104. */
  105. dev->aif_base_va = (struct hw_fib *)base;
  106. init->AdapterFibsVirtualAddress = 0;
  107. init->AdapterFibsPhysicalAddress = cpu_to_le32((u32)phys);
  108. init->AdapterFibsSize = cpu_to_le32(fibsize);
  109. init->AdapterFibAlign = cpu_to_le32(sizeof(struct hw_fib));
  110. /*
  111. * number of 4k pages of host physical memory. The aacraid fw needs
  112. * this number to be less than 4gb worth of pages. New firmware doesn't
  113. * have any issues with the mapping system, but older Firmware did, and
  114. * had *troubles* dealing with the math overloading past 32 bits, thus
  115. * we must limit this field.
  116. */
  117. aac_max_hostphysmempages = dma_get_required_mask(&dev->pdev->dev) >> 12;
  118. if (aac_max_hostphysmempages < AAC_MAX_HOSTPHYSMEMPAGES)
  119. init->HostPhysMemPages = cpu_to_le32(aac_max_hostphysmempages);
  120. else
  121. init->HostPhysMemPages = cpu_to_le32(AAC_MAX_HOSTPHYSMEMPAGES);
  122. init->InitFlags = cpu_to_le32(INITFLAGS_DRIVER_USES_UTC_TIME |
  123. INITFLAGS_DRIVER_SUPPORTS_PM);
  124. init->MaxIoCommands = cpu_to_le32(dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB);
  125. init->MaxIoSize = cpu_to_le32(dev->scsi_host_ptr->max_sectors << 9);
  126. init->MaxFibSize = cpu_to_le32(dev->max_fib_size);
  127. init->MaxNumAif = cpu_to_le32(dev->max_num_aif);
  128. if (dev->comm_interface == AAC_COMM_MESSAGE) {
  129. init->InitFlags |= cpu_to_le32(INITFLAGS_NEW_COMM_SUPPORTED);
  130. dprintk((KERN_WARNING"aacraid: New Comm Interface enabled\n"));
  131. } else if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE1) {
  132. init->InitStructRevision = cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION_6);
  133. init->InitFlags |= cpu_to_le32(INITFLAGS_NEW_COMM_SUPPORTED |
  134. INITFLAGS_NEW_COMM_TYPE1_SUPPORTED | INITFLAGS_FAST_JBOD_SUPPORTED);
  135. init->HostRRQ_AddrHigh = cpu_to_le32((u32)((u64)dev->host_rrq_pa >> 32));
  136. init->HostRRQ_AddrLow = cpu_to_le32((u32)(dev->host_rrq_pa & 0xffffffff));
  137. dprintk((KERN_WARNING"aacraid: New Comm Interface type1 enabled\n"));
  138. } else if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE2) {
  139. init->InitStructRevision = cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION_7);
  140. init->InitFlags |= cpu_to_le32(INITFLAGS_NEW_COMM_SUPPORTED |
  141. INITFLAGS_NEW_COMM_TYPE2_SUPPORTED | INITFLAGS_FAST_JBOD_SUPPORTED);
  142. init->HostRRQ_AddrHigh = cpu_to_le32((u32)((u64)dev->host_rrq_pa >> 32));
  143. init->HostRRQ_AddrLow = cpu_to_le32((u32)(dev->host_rrq_pa & 0xffffffff));
  144. /* number of MSI-X */
  145. init->Sa_MSIXVectors = cpu_to_le32(dev->max_msix);
  146. dprintk((KERN_WARNING"aacraid: New Comm Interface type2 enabled\n"));
  147. }
  148. /*
  149. * Increment the base address by the amount already used
  150. */
  151. base = base + fibsize + host_rrq_size + sizeof(struct aac_init);
  152. phys = (dma_addr_t)((ulong)phys + fibsize + host_rrq_size +
  153. sizeof(struct aac_init));
  154. /*
  155. * Align the beginning of Headers to commalign
  156. */
  157. align = (commalign - ((uintptr_t)(base) & (commalign - 1)));
  158. base = base + align;
  159. phys = phys + align;
  160. /*
  161. * Fill in addresses of the Comm Area Headers and Queues
  162. */
  163. *commaddr = base;
  164. init->CommHeaderAddress = cpu_to_le32((u32)phys);
  165. /*
  166. * Increment the base address by the size of the CommArea
  167. */
  168. base = base + commsize;
  169. phys = phys + commsize;
  170. /*
  171. * Place the Printf buffer area after the Fast I/O comm area.
  172. */
  173. dev->printfbuf = (void *)base;
  174. init->printfbuf = cpu_to_le32(phys);
  175. init->printfbufsiz = cpu_to_le32(printfbufsiz);
  176. memset(base, 0, printfbufsiz);
  177. return 1;
  178. }
  179. static void aac_queue_init(struct aac_dev * dev, struct aac_queue * q, u32 *mem, int qsize)
  180. {
  181. atomic_set(&q->numpending, 0);
  182. q->dev = dev;
  183. init_waitqueue_head(&q->cmdready);
  184. INIT_LIST_HEAD(&q->cmdq);
  185. init_waitqueue_head(&q->qfull);
  186. spin_lock_init(&q->lockdata);
  187. q->lock = &q->lockdata;
  188. q->headers.producer = (__le32 *)mem;
  189. q->headers.consumer = (__le32 *)(mem+1);
  190. *(q->headers.producer) = cpu_to_le32(qsize);
  191. *(q->headers.consumer) = cpu_to_le32(qsize);
  192. q->entries = qsize;
  193. }
  194. /**
  195. * aac_send_shutdown - shutdown an adapter
  196. * @dev: Adapter to shutdown
  197. *
  198. * This routine will send a VM_CloseAll (shutdown) request to the adapter.
  199. */
  200. int aac_send_shutdown(struct aac_dev * dev)
  201. {
  202. struct fib * fibctx;
  203. struct aac_close *cmd;
  204. int status;
  205. fibctx = aac_fib_alloc(dev);
  206. if (!fibctx)
  207. return -ENOMEM;
  208. aac_fib_init(fibctx);
  209. mutex_lock(&dev->ioctl_mutex);
  210. dev->adapter_shutdown = 1;
  211. mutex_unlock(&dev->ioctl_mutex);
  212. cmd = (struct aac_close *) fib_data(fibctx);
  213. cmd->command = cpu_to_le32(VM_CloseAll);
  214. cmd->cid = cpu_to_le32(0xfffffffe);
  215. status = aac_fib_send(ContainerCommand,
  216. fibctx,
  217. sizeof(struct aac_close),
  218. FsaNormal,
  219. -2 /* Timeout silently */, 1,
  220. NULL, NULL);
  221. if (status >= 0)
  222. aac_fib_complete(fibctx);
  223. /* FIB should be freed only after getting the response from the F/W */
  224. if (status != -ERESTARTSYS)
  225. aac_fib_free(fibctx);
  226. if ((dev->pdev->device == PMC_DEVICE_S7 ||
  227. dev->pdev->device == PMC_DEVICE_S8 ||
  228. dev->pdev->device == PMC_DEVICE_S9) &&
  229. dev->msi_enabled)
  230. aac_src_access_devreg(dev, AAC_ENABLE_INTX);
  231. return status;
  232. }
  233. /**
  234. * aac_comm_init - Initialise FSA data structures
  235. * @dev: Adapter to initialise
  236. *
  237. * Initializes the data structures that are required for the FSA commuication
  238. * interface to operate.
  239. * Returns
  240. * 1 - if we were able to init the commuication interface.
  241. * 0 - If there were errors initing. This is a fatal error.
  242. */
  243. static int aac_comm_init(struct aac_dev * dev)
  244. {
  245. unsigned long hdrsize = (sizeof(u32) * NUMBER_OF_COMM_QUEUES) * 2;
  246. unsigned long queuesize = sizeof(struct aac_entry) * TOTAL_QUEUE_ENTRIES;
  247. u32 *headers;
  248. struct aac_entry * queues;
  249. unsigned long size;
  250. struct aac_queue_block * comm = dev->queues;
  251. /*
  252. * Now allocate and initialize the zone structures used as our
  253. * pool of FIB context records. The size of the zone is based
  254. * on the system memory size. We also initialize the mutex used
  255. * to protect the zone.
  256. */
  257. spin_lock_init(&dev->fib_lock);
  258. /*
  259. * Allocate the physically contiguous space for the commuication
  260. * queue headers.
  261. */
  262. size = hdrsize + queuesize;
  263. if (!aac_alloc_comm(dev, (void * *)&headers, size, QUEUE_ALIGNMENT))
  264. return -ENOMEM;
  265. queues = (struct aac_entry *)(((ulong)headers) + hdrsize);
  266. /* Adapter to Host normal priority Command queue */
  267. comm->queue[HostNormCmdQueue].base = queues;
  268. aac_queue_init(dev, &comm->queue[HostNormCmdQueue], headers, HOST_NORM_CMD_ENTRIES);
  269. queues += HOST_NORM_CMD_ENTRIES;
  270. headers += 2;
  271. /* Adapter to Host high priority command queue */
  272. comm->queue[HostHighCmdQueue].base = queues;
  273. aac_queue_init(dev, &comm->queue[HostHighCmdQueue], headers, HOST_HIGH_CMD_ENTRIES);
  274. queues += HOST_HIGH_CMD_ENTRIES;
  275. headers +=2;
  276. /* Host to adapter normal priority command queue */
  277. comm->queue[AdapNormCmdQueue].base = queues;
  278. aac_queue_init(dev, &comm->queue[AdapNormCmdQueue], headers, ADAP_NORM_CMD_ENTRIES);
  279. queues += ADAP_NORM_CMD_ENTRIES;
  280. headers += 2;
  281. /* host to adapter high priority command queue */
  282. comm->queue[AdapHighCmdQueue].base = queues;
  283. aac_queue_init(dev, &comm->queue[AdapHighCmdQueue], headers, ADAP_HIGH_CMD_ENTRIES);
  284. queues += ADAP_HIGH_CMD_ENTRIES;
  285. headers += 2;
  286. /* adapter to host normal priority response queue */
  287. comm->queue[HostNormRespQueue].base = queues;
  288. aac_queue_init(dev, &comm->queue[HostNormRespQueue], headers, HOST_NORM_RESP_ENTRIES);
  289. queues += HOST_NORM_RESP_ENTRIES;
  290. headers += 2;
  291. /* adapter to host high priority response queue */
  292. comm->queue[HostHighRespQueue].base = queues;
  293. aac_queue_init(dev, &comm->queue[HostHighRespQueue], headers, HOST_HIGH_RESP_ENTRIES);
  294. queues += HOST_HIGH_RESP_ENTRIES;
  295. headers += 2;
  296. /* host to adapter normal priority response queue */
  297. comm->queue[AdapNormRespQueue].base = queues;
  298. aac_queue_init(dev, &comm->queue[AdapNormRespQueue], headers, ADAP_NORM_RESP_ENTRIES);
  299. queues += ADAP_NORM_RESP_ENTRIES;
  300. headers += 2;
  301. /* host to adapter high priority response queue */
  302. comm->queue[AdapHighRespQueue].base = queues;
  303. aac_queue_init(dev, &comm->queue[AdapHighRespQueue], headers, ADAP_HIGH_RESP_ENTRIES);
  304. comm->queue[AdapNormCmdQueue].lock = comm->queue[HostNormRespQueue].lock;
  305. comm->queue[AdapHighCmdQueue].lock = comm->queue[HostHighRespQueue].lock;
  306. comm->queue[AdapNormRespQueue].lock = comm->queue[HostNormCmdQueue].lock;
  307. comm->queue[AdapHighRespQueue].lock = comm->queue[HostHighCmdQueue].lock;
  308. return 0;
  309. }
  310. void aac_define_int_mode(struct aac_dev *dev)
  311. {
  312. int i, msi_count, min_msix;
  313. msi_count = i = 0;
  314. /* max. vectors from GET_COMM_PREFERRED_SETTINGS */
  315. if (dev->max_msix == 0 ||
  316. dev->pdev->device == PMC_DEVICE_S6 ||
  317. dev->sync_mode) {
  318. dev->max_msix = 1;
  319. dev->vector_cap =
  320. dev->scsi_host_ptr->can_queue +
  321. AAC_NUM_MGT_FIB;
  322. return;
  323. }
  324. /* Don't bother allocating more MSI-X vectors than cpus */
  325. msi_count = min(dev->max_msix,
  326. (unsigned int)num_online_cpus());
  327. dev->max_msix = msi_count;
  328. if (msi_count > AAC_MAX_MSIX)
  329. msi_count = AAC_MAX_MSIX;
  330. for (i = 0; i < msi_count; i++)
  331. dev->msixentry[i].entry = i;
  332. if (msi_count > 1 &&
  333. pci_find_capability(dev->pdev, PCI_CAP_ID_MSIX)) {
  334. min_msix = 2;
  335. i = pci_enable_msix_range(dev->pdev,
  336. dev->msixentry,
  337. min_msix,
  338. msi_count);
  339. if (i > 0) {
  340. dev->msi_enabled = 1;
  341. msi_count = i;
  342. } else {
  343. dev->msi_enabled = 0;
  344. dev_err(&dev->pdev->dev,
  345. "MSIX not supported!! Will try INTX 0x%x.\n", i);
  346. }
  347. }
  348. if (!dev->msi_enabled)
  349. dev->max_msix = msi_count = 1;
  350. else {
  351. if (dev->max_msix > msi_count)
  352. dev->max_msix = msi_count;
  353. }
  354. dev->vector_cap =
  355. (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB) /
  356. msi_count;
  357. }
  358. struct aac_dev *aac_init_adapter(struct aac_dev *dev)
  359. {
  360. u32 status[5];
  361. struct Scsi_Host * host = dev->scsi_host_ptr;
  362. extern int aac_sync_mode;
  363. /*
  364. * Check the preferred comm settings, defaults from template.
  365. */
  366. dev->management_fib_count = 0;
  367. spin_lock_init(&dev->manage_lock);
  368. spin_lock_init(&dev->sync_lock);
  369. spin_lock_init(&dev->iq_lock);
  370. dev->max_fib_size = sizeof(struct hw_fib);
  371. dev->sg_tablesize = host->sg_tablesize = (dev->max_fib_size
  372. - sizeof(struct aac_fibhdr)
  373. - sizeof(struct aac_write) + sizeof(struct sgentry))
  374. / sizeof(struct sgentry);
  375. dev->comm_interface = AAC_COMM_PRODUCER;
  376. dev->raw_io_interface = dev->raw_io_64 = 0;
  377. /*
  378. * Enable INTX mode, if not done already Enabled
  379. */
  380. if (aac_is_msix_mode(dev)) {
  381. aac_change_to_intx(dev);
  382. dev_info(&dev->pdev->dev, "Changed firmware to INTX mode");
  383. }
  384. if ((!aac_adapter_sync_cmd(dev, GET_ADAPTER_PROPERTIES,
  385. 0, 0, 0, 0, 0, 0,
  386. status+0, status+1, status+2, status+3, NULL)) &&
  387. (status[0] == 0x00000001)) {
  388. dev->doorbell_mask = status[3];
  389. if (status[1] & le32_to_cpu(AAC_OPT_NEW_COMM_64))
  390. dev->raw_io_64 = 1;
  391. dev->sync_mode = aac_sync_mode;
  392. if (dev->a_ops.adapter_comm &&
  393. (status[1] & le32_to_cpu(AAC_OPT_NEW_COMM))) {
  394. dev->comm_interface = AAC_COMM_MESSAGE;
  395. dev->raw_io_interface = 1;
  396. if ((status[1] & le32_to_cpu(AAC_OPT_NEW_COMM_TYPE1))) {
  397. /* driver supports TYPE1 (Tupelo) */
  398. dev->comm_interface = AAC_COMM_MESSAGE_TYPE1;
  399. } else if ((status[1] & le32_to_cpu(AAC_OPT_NEW_COMM_TYPE2))) {
  400. /* driver supports TYPE2 (Denali) */
  401. dev->comm_interface = AAC_COMM_MESSAGE_TYPE2;
  402. } else if ((status[1] & le32_to_cpu(AAC_OPT_NEW_COMM_TYPE4)) ||
  403. (status[1] & le32_to_cpu(AAC_OPT_NEW_COMM_TYPE3))) {
  404. /* driver doesn't TYPE3 and TYPE4 */
  405. /* switch to sync. mode */
  406. dev->comm_interface = AAC_COMM_MESSAGE_TYPE2;
  407. dev->sync_mode = 1;
  408. }
  409. }
  410. if ((dev->comm_interface == AAC_COMM_MESSAGE) &&
  411. (status[2] > dev->base_size)) {
  412. aac_adapter_ioremap(dev, 0);
  413. dev->base_size = status[2];
  414. if (aac_adapter_ioremap(dev, status[2])) {
  415. /* remap failed, go back ... */
  416. dev->comm_interface = AAC_COMM_PRODUCER;
  417. if (aac_adapter_ioremap(dev, AAC_MIN_FOOTPRINT_SIZE)) {
  418. printk(KERN_WARNING
  419. "aacraid: unable to map adapter.\n");
  420. return NULL;
  421. }
  422. }
  423. }
  424. }
  425. dev->max_msix = 0;
  426. dev->msi_enabled = 0;
  427. dev->adapter_shutdown = 0;
  428. if ((!aac_adapter_sync_cmd(dev, GET_COMM_PREFERRED_SETTINGS,
  429. 0, 0, 0, 0, 0, 0,
  430. status+0, status+1, status+2, status+3, status+4))
  431. && (status[0] == 0x00000001)) {
  432. /*
  433. * status[1] >> 16 maximum command size in KB
  434. * status[1] & 0xFFFF maximum FIB size
  435. * status[2] >> 16 maximum SG elements to driver
  436. * status[2] & 0xFFFF maximum SG elements from driver
  437. * status[3] & 0xFFFF maximum number FIBs outstanding
  438. */
  439. host->max_sectors = (status[1] >> 16) << 1;
  440. /* Multiple of 32 for PMC */
  441. dev->max_fib_size = status[1] & 0xFFE0;
  442. host->sg_tablesize = status[2] >> 16;
  443. dev->sg_tablesize = status[2] & 0xFFFF;
  444. if (dev->pdev->device == PMC_DEVICE_S7 ||
  445. dev->pdev->device == PMC_DEVICE_S8 ||
  446. dev->pdev->device == PMC_DEVICE_S9)
  447. host->can_queue = ((status[3] >> 16) ? (status[3] >> 16) :
  448. (status[3] & 0xFFFF)) - AAC_NUM_MGT_FIB;
  449. else
  450. host->can_queue = (status[3] & 0xFFFF) - AAC_NUM_MGT_FIB;
  451. dev->max_num_aif = status[4] & 0xFFFF;
  452. /*
  453. * NOTE:
  454. * All these overrides are based on a fixed internal
  455. * knowledge and understanding of existing adapters,
  456. * acbsize should be set with caution.
  457. */
  458. if (acbsize == 512) {
  459. host->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
  460. dev->max_fib_size = 512;
  461. dev->sg_tablesize = host->sg_tablesize
  462. = (512 - sizeof(struct aac_fibhdr)
  463. - sizeof(struct aac_write) + sizeof(struct sgentry))
  464. / sizeof(struct sgentry);
  465. host->can_queue = AAC_NUM_IO_FIB;
  466. } else if (acbsize == 2048) {
  467. host->max_sectors = 512;
  468. dev->max_fib_size = 2048;
  469. host->sg_tablesize = 65;
  470. dev->sg_tablesize = 81;
  471. host->can_queue = 512 - AAC_NUM_MGT_FIB;
  472. } else if (acbsize == 4096) {
  473. host->max_sectors = 1024;
  474. dev->max_fib_size = 4096;
  475. host->sg_tablesize = 129;
  476. dev->sg_tablesize = 166;
  477. host->can_queue = 256 - AAC_NUM_MGT_FIB;
  478. } else if (acbsize == 8192) {
  479. host->max_sectors = 2048;
  480. dev->max_fib_size = 8192;
  481. host->sg_tablesize = 257;
  482. dev->sg_tablesize = 337;
  483. host->can_queue = 128 - AAC_NUM_MGT_FIB;
  484. } else if (acbsize > 0) {
  485. printk("Illegal acbsize=%d ignored\n", acbsize);
  486. }
  487. }
  488. {
  489. if (numacb > 0) {
  490. if (numacb < host->can_queue)
  491. host->can_queue = numacb;
  492. else
  493. printk("numacb=%d ignored\n", numacb);
  494. }
  495. }
  496. if (host->can_queue > AAC_NUM_IO_FIB)
  497. host->can_queue = AAC_NUM_IO_FIB;
  498. if (dev->pdev->device == PMC_DEVICE_S6 ||
  499. dev->pdev->device == PMC_DEVICE_S7 ||
  500. dev->pdev->device == PMC_DEVICE_S8 ||
  501. dev->pdev->device == PMC_DEVICE_S9)
  502. aac_define_int_mode(dev);
  503. /*
  504. * Ok now init the communication subsystem
  505. */
  506. dev->queues = kzalloc(sizeof(struct aac_queue_block), GFP_KERNEL);
  507. if (dev->queues == NULL) {
  508. printk(KERN_ERR "Error could not allocate comm region.\n");
  509. return NULL;
  510. }
  511. if (aac_comm_init(dev)<0){
  512. kfree(dev->queues);
  513. return NULL;
  514. }
  515. /*
  516. * Initialize the list of fibs
  517. */
  518. if (aac_fib_setup(dev) < 0) {
  519. kfree(dev->queues);
  520. return NULL;
  521. }
  522. INIT_LIST_HEAD(&dev->fib_list);
  523. INIT_LIST_HEAD(&dev->sync_fib_list);
  524. return dev;
  525. }