comminit.c 18 KB

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