comminit.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  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_MINIPORT_REVISION);
  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. cmd = (struct aac_close *) fib_data(fibctx);
  210. cmd->command = cpu_to_le32(VM_CloseAll);
  211. cmd->cid = cpu_to_le32(0xfffffffe);
  212. status = aac_fib_send(ContainerCommand,
  213. fibctx,
  214. sizeof(struct aac_close),
  215. FsaNormal,
  216. -2 /* Timeout silently */, 1,
  217. NULL, NULL);
  218. if (status >= 0)
  219. aac_fib_complete(fibctx);
  220. /* FIB should be freed only after getting the response from the F/W */
  221. if (status != -ERESTARTSYS)
  222. aac_fib_free(fibctx);
  223. dev->adapter_shutdown = 1;
  224. if ((dev->pdev->device == PMC_DEVICE_S7 ||
  225. dev->pdev->device == PMC_DEVICE_S8 ||
  226. dev->pdev->device == PMC_DEVICE_S9) &&
  227. dev->msi_enabled)
  228. aac_src_access_devreg(dev, AAC_ENABLE_INTX);
  229. return status;
  230. }
  231. /**
  232. * aac_comm_init - Initialise FSA data structures
  233. * @dev: Adapter to initialise
  234. *
  235. * Initializes the data structures that are required for the FSA commuication
  236. * interface to operate.
  237. * Returns
  238. * 1 - if we were able to init the commuication interface.
  239. * 0 - If there were errors initing. This is a fatal error.
  240. */
  241. static int aac_comm_init(struct aac_dev * dev)
  242. {
  243. unsigned long hdrsize = (sizeof(u32) * NUMBER_OF_COMM_QUEUES) * 2;
  244. unsigned long queuesize = sizeof(struct aac_entry) * TOTAL_QUEUE_ENTRIES;
  245. u32 *headers;
  246. struct aac_entry * queues;
  247. unsigned long size;
  248. struct aac_queue_block * comm = dev->queues;
  249. /*
  250. * Now allocate and initialize the zone structures used as our
  251. * pool of FIB context records. The size of the zone is based
  252. * on the system memory size. We also initialize the mutex used
  253. * to protect the zone.
  254. */
  255. spin_lock_init(&dev->fib_lock);
  256. /*
  257. * Allocate the physically contiguous space for the commuication
  258. * queue headers.
  259. */
  260. size = hdrsize + queuesize;
  261. if (!aac_alloc_comm(dev, (void * *)&headers, size, QUEUE_ALIGNMENT))
  262. return -ENOMEM;
  263. queues = (struct aac_entry *)(((ulong)headers) + hdrsize);
  264. /* Adapter to Host normal priority Command queue */
  265. comm->queue[HostNormCmdQueue].base = queues;
  266. aac_queue_init(dev, &comm->queue[HostNormCmdQueue], headers, HOST_NORM_CMD_ENTRIES);
  267. queues += HOST_NORM_CMD_ENTRIES;
  268. headers += 2;
  269. /* Adapter to Host high priority command queue */
  270. comm->queue[HostHighCmdQueue].base = queues;
  271. aac_queue_init(dev, &comm->queue[HostHighCmdQueue], headers, HOST_HIGH_CMD_ENTRIES);
  272. queues += HOST_HIGH_CMD_ENTRIES;
  273. headers +=2;
  274. /* Host to adapter normal priority command queue */
  275. comm->queue[AdapNormCmdQueue].base = queues;
  276. aac_queue_init(dev, &comm->queue[AdapNormCmdQueue], headers, ADAP_NORM_CMD_ENTRIES);
  277. queues += ADAP_NORM_CMD_ENTRIES;
  278. headers += 2;
  279. /* host to adapter high priority command queue */
  280. comm->queue[AdapHighCmdQueue].base = queues;
  281. aac_queue_init(dev, &comm->queue[AdapHighCmdQueue], headers, ADAP_HIGH_CMD_ENTRIES);
  282. queues += ADAP_HIGH_CMD_ENTRIES;
  283. headers += 2;
  284. /* adapter to host normal priority response queue */
  285. comm->queue[HostNormRespQueue].base = queues;
  286. aac_queue_init(dev, &comm->queue[HostNormRespQueue], headers, HOST_NORM_RESP_ENTRIES);
  287. queues += HOST_NORM_RESP_ENTRIES;
  288. headers += 2;
  289. /* adapter to host high priority response queue */
  290. comm->queue[HostHighRespQueue].base = queues;
  291. aac_queue_init(dev, &comm->queue[HostHighRespQueue], headers, HOST_HIGH_RESP_ENTRIES);
  292. queues += HOST_HIGH_RESP_ENTRIES;
  293. headers += 2;
  294. /* host to adapter normal priority response queue */
  295. comm->queue[AdapNormRespQueue].base = queues;
  296. aac_queue_init(dev, &comm->queue[AdapNormRespQueue], headers, ADAP_NORM_RESP_ENTRIES);
  297. queues += ADAP_NORM_RESP_ENTRIES;
  298. headers += 2;
  299. /* host to adapter high priority response queue */
  300. comm->queue[AdapHighRespQueue].base = queues;
  301. aac_queue_init(dev, &comm->queue[AdapHighRespQueue], headers, ADAP_HIGH_RESP_ENTRIES);
  302. comm->queue[AdapNormCmdQueue].lock = comm->queue[HostNormRespQueue].lock;
  303. comm->queue[AdapHighCmdQueue].lock = comm->queue[HostHighRespQueue].lock;
  304. comm->queue[AdapNormRespQueue].lock = comm->queue[HostNormCmdQueue].lock;
  305. comm->queue[AdapHighRespQueue].lock = comm->queue[HostHighCmdQueue].lock;
  306. return 0;
  307. }
  308. void aac_define_int_mode(struct aac_dev *dev)
  309. {
  310. int i, msi_count, min_msix;
  311. msi_count = i = 0;
  312. /* max. vectors from GET_COMM_PREFERRED_SETTINGS */
  313. if (dev->max_msix == 0 ||
  314. dev->pdev->device == PMC_DEVICE_S6 ||
  315. dev->sync_mode) {
  316. dev->max_msix = 1;
  317. dev->vector_cap =
  318. dev->scsi_host_ptr->can_queue +
  319. AAC_NUM_MGT_FIB;
  320. return;
  321. }
  322. /* Don't bother allocating more MSI-X vectors than cpus */
  323. msi_count = min(dev->max_msix,
  324. (unsigned int)num_online_cpus());
  325. dev->max_msix = msi_count;
  326. if (msi_count > AAC_MAX_MSIX)
  327. msi_count = AAC_MAX_MSIX;
  328. for (i = 0; i < msi_count; i++)
  329. dev->msixentry[i].entry = i;
  330. if (msi_count > 1 &&
  331. pci_find_capability(dev->pdev, PCI_CAP_ID_MSIX)) {
  332. min_msix = 2;
  333. i = pci_enable_msix_range(dev->pdev,
  334. dev->msixentry,
  335. min_msix,
  336. msi_count);
  337. if (i > 0) {
  338. dev->msi_enabled = 1;
  339. msi_count = i;
  340. } else {
  341. dev->msi_enabled = 0;
  342. printk(KERN_ERR "%s%d: MSIX not supported!! Will try MSI 0x%x.\n",
  343. dev->name, dev->id, i);
  344. }
  345. }
  346. if (!dev->msi_enabled) {
  347. msi_count = 1;
  348. i = pci_enable_msi(dev->pdev);
  349. if (!i) {
  350. dev->msi_enabled = 1;
  351. dev->msi = 1;
  352. } else {
  353. printk(KERN_ERR "%s%d: MSI not supported!! Will try INTx 0x%x.\n",
  354. dev->name, dev->id, i);
  355. }
  356. }
  357. if (!dev->msi_enabled)
  358. dev->max_msix = msi_count = 1;
  359. else {
  360. if (dev->max_msix > msi_count)
  361. dev->max_msix = msi_count;
  362. }
  363. dev->vector_cap =
  364. (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB) /
  365. msi_count;
  366. }
  367. struct aac_dev *aac_init_adapter(struct aac_dev *dev)
  368. {
  369. u32 status[5];
  370. struct Scsi_Host * host = dev->scsi_host_ptr;
  371. extern int aac_sync_mode;
  372. /*
  373. * Check the preferred comm settings, defaults from template.
  374. */
  375. dev->management_fib_count = 0;
  376. spin_lock_init(&dev->manage_lock);
  377. spin_lock_init(&dev->sync_lock);
  378. spin_lock_init(&dev->iq_lock);
  379. dev->max_fib_size = sizeof(struct hw_fib);
  380. dev->sg_tablesize = host->sg_tablesize = (dev->max_fib_size
  381. - sizeof(struct aac_fibhdr)
  382. - sizeof(struct aac_write) + sizeof(struct sgentry))
  383. / sizeof(struct sgentry);
  384. dev->comm_interface = AAC_COMM_PRODUCER;
  385. dev->raw_io_interface = dev->raw_io_64 = 0;
  386. /*
  387. * Enable INTX mode, if not done already Enabled
  388. */
  389. if (aac_is_msix_mode(dev)) {
  390. aac_change_to_intx(dev);
  391. dev_info(&dev->pdev->dev, "Changed firmware to INTX mode");
  392. }
  393. if ((!aac_adapter_sync_cmd(dev, GET_ADAPTER_PROPERTIES,
  394. 0, 0, 0, 0, 0, 0,
  395. status+0, status+1, status+2, status+3, NULL)) &&
  396. (status[0] == 0x00000001)) {
  397. dev->doorbell_mask = status[3];
  398. if (status[1] & le32_to_cpu(AAC_OPT_NEW_COMM_64))
  399. dev->raw_io_64 = 1;
  400. dev->sync_mode = aac_sync_mode;
  401. if (dev->a_ops.adapter_comm &&
  402. (status[1] & le32_to_cpu(AAC_OPT_NEW_COMM))) {
  403. dev->comm_interface = AAC_COMM_MESSAGE;
  404. dev->raw_io_interface = 1;
  405. if ((status[1] & le32_to_cpu(AAC_OPT_NEW_COMM_TYPE1))) {
  406. /* driver supports TYPE1 (Tupelo) */
  407. dev->comm_interface = AAC_COMM_MESSAGE_TYPE1;
  408. } else if ((status[1] & le32_to_cpu(AAC_OPT_NEW_COMM_TYPE2))) {
  409. /* driver supports TYPE2 (Denali) */
  410. dev->comm_interface = AAC_COMM_MESSAGE_TYPE2;
  411. } else if ((status[1] & le32_to_cpu(AAC_OPT_NEW_COMM_TYPE4)) ||
  412. (status[1] & le32_to_cpu(AAC_OPT_NEW_COMM_TYPE3))) {
  413. /* driver doesn't TYPE3 and TYPE4 */
  414. /* switch to sync. mode */
  415. dev->comm_interface = AAC_COMM_MESSAGE_TYPE2;
  416. dev->sync_mode = 1;
  417. }
  418. }
  419. if ((dev->comm_interface == AAC_COMM_MESSAGE) &&
  420. (status[2] > dev->base_size)) {
  421. aac_adapter_ioremap(dev, 0);
  422. dev->base_size = status[2];
  423. if (aac_adapter_ioremap(dev, status[2])) {
  424. /* remap failed, go back ... */
  425. dev->comm_interface = AAC_COMM_PRODUCER;
  426. if (aac_adapter_ioremap(dev, AAC_MIN_FOOTPRINT_SIZE)) {
  427. printk(KERN_WARNING
  428. "aacraid: unable to map adapter.\n");
  429. return NULL;
  430. }
  431. }
  432. }
  433. }
  434. dev->max_msix = 0;
  435. dev->msi_enabled = 0;
  436. dev->adapter_shutdown = 0;
  437. if ((!aac_adapter_sync_cmd(dev, GET_COMM_PREFERRED_SETTINGS,
  438. 0, 0, 0, 0, 0, 0,
  439. status+0, status+1, status+2, status+3, status+4))
  440. && (status[0] == 0x00000001)) {
  441. /*
  442. * status[1] >> 16 maximum command size in KB
  443. * status[1] & 0xFFFF maximum FIB size
  444. * status[2] >> 16 maximum SG elements to driver
  445. * status[2] & 0xFFFF maximum SG elements from driver
  446. * status[3] & 0xFFFF maximum number FIBs outstanding
  447. */
  448. host->max_sectors = (status[1] >> 16) << 1;
  449. /* Multiple of 32 for PMC */
  450. dev->max_fib_size = status[1] & 0xFFE0;
  451. host->sg_tablesize = status[2] >> 16;
  452. dev->sg_tablesize = status[2] & 0xFFFF;
  453. if (dev->pdev->device == PMC_DEVICE_S7 ||
  454. dev->pdev->device == PMC_DEVICE_S8 ||
  455. dev->pdev->device == PMC_DEVICE_S9)
  456. host->can_queue = ((status[3] >> 16) ? (status[3] >> 16) :
  457. (status[3] & 0xFFFF)) - AAC_NUM_MGT_FIB;
  458. else
  459. host->can_queue = (status[3] & 0xFFFF) - AAC_NUM_MGT_FIB;
  460. dev->max_num_aif = status[4] & 0xFFFF;
  461. /*
  462. * NOTE:
  463. * All these overrides are based on a fixed internal
  464. * knowledge and understanding of existing adapters,
  465. * acbsize should be set with caution.
  466. */
  467. if (acbsize == 512) {
  468. host->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
  469. dev->max_fib_size = 512;
  470. dev->sg_tablesize = host->sg_tablesize
  471. = (512 - sizeof(struct aac_fibhdr)
  472. - sizeof(struct aac_write) + sizeof(struct sgentry))
  473. / sizeof(struct sgentry);
  474. host->can_queue = AAC_NUM_IO_FIB;
  475. } else if (acbsize == 2048) {
  476. host->max_sectors = 512;
  477. dev->max_fib_size = 2048;
  478. host->sg_tablesize = 65;
  479. dev->sg_tablesize = 81;
  480. host->can_queue = 512 - AAC_NUM_MGT_FIB;
  481. } else if (acbsize == 4096) {
  482. host->max_sectors = 1024;
  483. dev->max_fib_size = 4096;
  484. host->sg_tablesize = 129;
  485. dev->sg_tablesize = 166;
  486. host->can_queue = 256 - AAC_NUM_MGT_FIB;
  487. } else if (acbsize == 8192) {
  488. host->max_sectors = 2048;
  489. dev->max_fib_size = 8192;
  490. host->sg_tablesize = 257;
  491. dev->sg_tablesize = 337;
  492. host->can_queue = 128 - AAC_NUM_MGT_FIB;
  493. } else if (acbsize > 0) {
  494. printk("Illegal acbsize=%d ignored\n", acbsize);
  495. }
  496. }
  497. {
  498. if (numacb > 0) {
  499. if (numacb < host->can_queue)
  500. host->can_queue = numacb;
  501. else
  502. printk("numacb=%d ignored\n", numacb);
  503. }
  504. }
  505. if (host->can_queue > AAC_NUM_IO_FIB)
  506. host->can_queue = AAC_NUM_IO_FIB;
  507. if (dev->pdev->device == PMC_DEVICE_S6 ||
  508. dev->pdev->device == PMC_DEVICE_S7 ||
  509. dev->pdev->device == PMC_DEVICE_S8 ||
  510. dev->pdev->device == PMC_DEVICE_S9)
  511. aac_define_int_mode(dev);
  512. /*
  513. * Ok now init the communication subsystem
  514. */
  515. dev->queues = kzalloc(sizeof(struct aac_queue_block), GFP_KERNEL);
  516. if (dev->queues == NULL) {
  517. printk(KERN_ERR "Error could not allocate comm region.\n");
  518. return NULL;
  519. }
  520. if (aac_comm_init(dev)<0){
  521. kfree(dev->queues);
  522. return NULL;
  523. }
  524. /*
  525. * Initialize the list of fibs
  526. */
  527. if (aac_fib_setup(dev) < 0) {
  528. kfree(dev->queues);
  529. return NULL;
  530. }
  531. INIT_LIST_HEAD(&dev->fib_list);
  532. INIT_LIST_HEAD(&dev->sync_fib_list);
  533. return dev;
  534. }