comminit.c 20 KB

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