PageRenderTime 68ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 1ms

/kernel/linux-source-2.6.32/drivers/scsi/mpt2sas/mpt2sas_base.c

https://bitbucket.org/ChuloChumo/sctp_thesis
C | 3727 lines | 2603 code | 423 blank | 701 comment | 361 complexity | a271c9ae883802b0c9df0c2748816304 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0

Large files files are truncated, but you can click here to view the full file

  1. /*
  2. * This is the Fusion MPT base driver providing common API layer interface
  3. * for access to MPT (Message Passing Technology) firmware.
  4. *
  5. * This code is based on drivers/scsi/mpt2sas/mpt2_base.c
  6. * Copyright (C) 2007-2009 LSI Corporation
  7. * (mailto:DL-MPTFusionLinux@lsi.com)
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * NO WARRANTY
  20. * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
  21. * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
  22. * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
  23. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
  24. * solely responsible for determining the appropriateness of using and
  25. * distributing the Program and assumes all risks associated with its
  26. * exercise of rights under this Agreement, including but not limited to
  27. * the risks and costs of program errors, damage to or loss of data,
  28. * programs or equipment, and unavailability or interruption of operations.
  29. * DISCLAIMER OF LIABILITY
  30. * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
  31. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  32. * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
  33. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  34. * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  35. * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
  36. * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
  37. * You should have received a copy of the GNU General Public License
  38. * along with this program; if not, write to the Free Software
  39. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
  40. * USA.
  41. */
  42. #include <linux/version.h>
  43. #include <linux/kernel.h>
  44. #include <linux/module.h>
  45. #include <linux/errno.h>
  46. #include <linux/init.h>
  47. #include <linux/slab.h>
  48. #include <linux/types.h>
  49. #include <linux/pci.h>
  50. #include <linux/kdev_t.h>
  51. #include <linux/blkdev.h>
  52. #include <linux/delay.h>
  53. #include <linux/interrupt.h>
  54. #include <linux/dma-mapping.h>
  55. #include <linux/sort.h>
  56. #include <linux/io.h>
  57. #include "mpt2sas_base.h"
  58. static MPT_CALLBACK mpt_callbacks[MPT_MAX_CALLBACKS];
  59. #define FAULT_POLLING_INTERVAL 1000 /* in milliseconds */
  60. #define MPT2SAS_MAX_REQUEST_QUEUE 600 /* maximum controller queue depth */
  61. static int max_queue_depth = -1;
  62. module_param(max_queue_depth, int, 0);
  63. MODULE_PARM_DESC(max_queue_depth, " max controller queue depth ");
  64. static int max_sgl_entries = -1;
  65. module_param(max_sgl_entries, int, 0);
  66. MODULE_PARM_DESC(max_sgl_entries, " max sg entries ");
  67. static int msix_disable = -1;
  68. module_param(msix_disable, int, 0);
  69. MODULE_PARM_DESC(msix_disable, " disable msix routed interrupts (default=0)");
  70. /**
  71. * _base_fault_reset_work - workq handling ioc fault conditions
  72. * @work: input argument, used to derive ioc
  73. * Context: sleep.
  74. *
  75. * Return nothing.
  76. */
  77. static void
  78. _base_fault_reset_work(struct work_struct *work)
  79. {
  80. struct MPT2SAS_ADAPTER *ioc =
  81. container_of(work, struct MPT2SAS_ADAPTER, fault_reset_work.work);
  82. unsigned long flags;
  83. u32 doorbell;
  84. int rc;
  85. spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
  86. if (ioc->shost_recovery)
  87. goto rearm_timer;
  88. spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
  89. doorbell = mpt2sas_base_get_iocstate(ioc, 0);
  90. if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
  91. rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
  92. FORCE_BIG_HAMMER);
  93. printk(MPT2SAS_WARN_FMT "%s: hard reset: %s\n", ioc->name,
  94. __func__, (rc == 0) ? "success" : "failed");
  95. doorbell = mpt2sas_base_get_iocstate(ioc, 0);
  96. if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT)
  97. mpt2sas_base_fault_info(ioc, doorbell &
  98. MPI2_DOORBELL_DATA_MASK);
  99. }
  100. spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
  101. rearm_timer:
  102. if (ioc->fault_reset_work_q)
  103. queue_delayed_work(ioc->fault_reset_work_q,
  104. &ioc->fault_reset_work,
  105. msecs_to_jiffies(FAULT_POLLING_INTERVAL));
  106. spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
  107. }
  108. /**
  109. * mpt2sas_base_start_watchdog - start the fault_reset_work_q
  110. * @ioc: pointer to scsi command object
  111. * Context: sleep.
  112. *
  113. * Return nothing.
  114. */
  115. void
  116. mpt2sas_base_start_watchdog(struct MPT2SAS_ADAPTER *ioc)
  117. {
  118. unsigned long flags;
  119. if (ioc->fault_reset_work_q)
  120. return;
  121. /* initialize fault polling */
  122. INIT_DELAYED_WORK(&ioc->fault_reset_work, _base_fault_reset_work);
  123. snprintf(ioc->fault_reset_work_q_name,
  124. sizeof(ioc->fault_reset_work_q_name), "poll_%d_status", ioc->id);
  125. ioc->fault_reset_work_q =
  126. create_singlethread_workqueue(ioc->fault_reset_work_q_name);
  127. if (!ioc->fault_reset_work_q) {
  128. printk(MPT2SAS_ERR_FMT "%s: failed (line=%d)\n",
  129. ioc->name, __func__, __LINE__);
  130. return;
  131. }
  132. spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
  133. if (ioc->fault_reset_work_q)
  134. queue_delayed_work(ioc->fault_reset_work_q,
  135. &ioc->fault_reset_work,
  136. msecs_to_jiffies(FAULT_POLLING_INTERVAL));
  137. spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
  138. }
  139. /**
  140. * mpt2sas_base_stop_watchdog - stop the fault_reset_work_q
  141. * @ioc: pointer to scsi command object
  142. * Context: sleep.
  143. *
  144. * Return nothing.
  145. */
  146. void
  147. mpt2sas_base_stop_watchdog(struct MPT2SAS_ADAPTER *ioc)
  148. {
  149. unsigned long flags;
  150. struct workqueue_struct *wq;
  151. spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
  152. wq = ioc->fault_reset_work_q;
  153. ioc->fault_reset_work_q = NULL;
  154. spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
  155. if (wq) {
  156. if (!cancel_delayed_work(&ioc->fault_reset_work))
  157. flush_workqueue(wq);
  158. destroy_workqueue(wq);
  159. }
  160. }
  161. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  162. /**
  163. * _base_sas_ioc_info - verbose translation of the ioc status
  164. * @ioc: pointer to scsi command object
  165. * @mpi_reply: reply mf payload returned from firmware
  166. * @request_hdr: request mf
  167. *
  168. * Return nothing.
  169. */
  170. static void
  171. _base_sas_ioc_info(struct MPT2SAS_ADAPTER *ioc, MPI2DefaultReply_t *mpi_reply,
  172. MPI2RequestHeader_t *request_hdr)
  173. {
  174. u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
  175. MPI2_IOCSTATUS_MASK;
  176. char *desc = NULL;
  177. u16 frame_sz;
  178. char *func_str = NULL;
  179. /* SCSI_IO, RAID_PASS are handled from _scsih_scsi_ioc_info */
  180. if (request_hdr->Function == MPI2_FUNCTION_SCSI_IO_REQUEST ||
  181. request_hdr->Function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH ||
  182. request_hdr->Function == MPI2_FUNCTION_EVENT_NOTIFICATION)
  183. return;
  184. switch (ioc_status) {
  185. /****************************************************************************
  186. * Common IOCStatus values for all replies
  187. ****************************************************************************/
  188. case MPI2_IOCSTATUS_INVALID_FUNCTION:
  189. desc = "invalid function";
  190. break;
  191. case MPI2_IOCSTATUS_BUSY:
  192. desc = "busy";
  193. break;
  194. case MPI2_IOCSTATUS_INVALID_SGL:
  195. desc = "invalid sgl";
  196. break;
  197. case MPI2_IOCSTATUS_INTERNAL_ERROR:
  198. desc = "internal error";
  199. break;
  200. case MPI2_IOCSTATUS_INVALID_VPID:
  201. desc = "invalid vpid";
  202. break;
  203. case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
  204. desc = "insufficient resources";
  205. break;
  206. case MPI2_IOCSTATUS_INVALID_FIELD:
  207. desc = "invalid field";
  208. break;
  209. case MPI2_IOCSTATUS_INVALID_STATE:
  210. desc = "invalid state";
  211. break;
  212. case MPI2_IOCSTATUS_OP_STATE_NOT_SUPPORTED:
  213. desc = "op state not supported";
  214. break;
  215. /****************************************************************************
  216. * Config IOCStatus values
  217. ****************************************************************************/
  218. case MPI2_IOCSTATUS_CONFIG_INVALID_ACTION:
  219. desc = "config invalid action";
  220. break;
  221. case MPI2_IOCSTATUS_CONFIG_INVALID_TYPE:
  222. desc = "config invalid type";
  223. break;
  224. case MPI2_IOCSTATUS_CONFIG_INVALID_PAGE:
  225. desc = "config invalid page";
  226. break;
  227. case MPI2_IOCSTATUS_CONFIG_INVALID_DATA:
  228. desc = "config invalid data";
  229. break;
  230. case MPI2_IOCSTATUS_CONFIG_NO_DEFAULTS:
  231. desc = "config no defaults";
  232. break;
  233. case MPI2_IOCSTATUS_CONFIG_CANT_COMMIT:
  234. desc = "config cant commit";
  235. break;
  236. /****************************************************************************
  237. * SCSI IO Reply
  238. ****************************************************************************/
  239. case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
  240. case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
  241. case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
  242. case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
  243. case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
  244. case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
  245. case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
  246. case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
  247. case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
  248. case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
  249. case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
  250. case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
  251. break;
  252. /****************************************************************************
  253. * For use by SCSI Initiator and SCSI Target end-to-end data protection
  254. ****************************************************************************/
  255. case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
  256. desc = "eedp guard error";
  257. break;
  258. case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
  259. desc = "eedp ref tag error";
  260. break;
  261. case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
  262. desc = "eedp app tag error";
  263. break;
  264. /****************************************************************************
  265. * SCSI Target values
  266. ****************************************************************************/
  267. case MPI2_IOCSTATUS_TARGET_INVALID_IO_INDEX:
  268. desc = "target invalid io index";
  269. break;
  270. case MPI2_IOCSTATUS_TARGET_ABORTED:
  271. desc = "target aborted";
  272. break;
  273. case MPI2_IOCSTATUS_TARGET_NO_CONN_RETRYABLE:
  274. desc = "target no conn retryable";
  275. break;
  276. case MPI2_IOCSTATUS_TARGET_NO_CONNECTION:
  277. desc = "target no connection";
  278. break;
  279. case MPI2_IOCSTATUS_TARGET_XFER_COUNT_MISMATCH:
  280. desc = "target xfer count mismatch";
  281. break;
  282. case MPI2_IOCSTATUS_TARGET_DATA_OFFSET_ERROR:
  283. desc = "target data offset error";
  284. break;
  285. case MPI2_IOCSTATUS_TARGET_TOO_MUCH_WRITE_DATA:
  286. desc = "target too much write data";
  287. break;
  288. case MPI2_IOCSTATUS_TARGET_IU_TOO_SHORT:
  289. desc = "target iu too short";
  290. break;
  291. case MPI2_IOCSTATUS_TARGET_ACK_NAK_TIMEOUT:
  292. desc = "target ack nak timeout";
  293. break;
  294. case MPI2_IOCSTATUS_TARGET_NAK_RECEIVED:
  295. desc = "target nak received";
  296. break;
  297. /****************************************************************************
  298. * Serial Attached SCSI values
  299. ****************************************************************************/
  300. case MPI2_IOCSTATUS_SAS_SMP_REQUEST_FAILED:
  301. desc = "smp request failed";
  302. break;
  303. case MPI2_IOCSTATUS_SAS_SMP_DATA_OVERRUN:
  304. desc = "smp data overrun";
  305. break;
  306. /****************************************************************************
  307. * Diagnostic Buffer Post / Diagnostic Release values
  308. ****************************************************************************/
  309. case MPI2_IOCSTATUS_DIAGNOSTIC_RELEASED:
  310. desc = "diagnostic released";
  311. break;
  312. default:
  313. break;
  314. }
  315. if (!desc)
  316. return;
  317. switch (request_hdr->Function) {
  318. case MPI2_FUNCTION_CONFIG:
  319. frame_sz = sizeof(Mpi2ConfigRequest_t) + ioc->sge_size;
  320. func_str = "config_page";
  321. break;
  322. case MPI2_FUNCTION_SCSI_TASK_MGMT:
  323. frame_sz = sizeof(Mpi2SCSITaskManagementRequest_t);
  324. func_str = "task_mgmt";
  325. break;
  326. case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL:
  327. frame_sz = sizeof(Mpi2SasIoUnitControlRequest_t);
  328. func_str = "sas_iounit_ctl";
  329. break;
  330. case MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR:
  331. frame_sz = sizeof(Mpi2SepRequest_t);
  332. func_str = "enclosure";
  333. break;
  334. case MPI2_FUNCTION_IOC_INIT:
  335. frame_sz = sizeof(Mpi2IOCInitRequest_t);
  336. func_str = "ioc_init";
  337. break;
  338. case MPI2_FUNCTION_PORT_ENABLE:
  339. frame_sz = sizeof(Mpi2PortEnableRequest_t);
  340. func_str = "port_enable";
  341. break;
  342. case MPI2_FUNCTION_SMP_PASSTHROUGH:
  343. frame_sz = sizeof(Mpi2SmpPassthroughRequest_t) + ioc->sge_size;
  344. func_str = "smp_passthru";
  345. break;
  346. default:
  347. frame_sz = 32;
  348. func_str = "unknown";
  349. break;
  350. }
  351. printk(MPT2SAS_WARN_FMT "ioc_status: %s(0x%04x), request(0x%p),"
  352. " (%s)\n", ioc->name, desc, ioc_status, request_hdr, func_str);
  353. _debug_dump_mf(request_hdr, frame_sz/4);
  354. }
  355. /**
  356. * _base_display_event_data - verbose translation of firmware asyn events
  357. * @ioc: pointer to scsi command object
  358. * @mpi_reply: reply mf payload returned from firmware
  359. *
  360. * Return nothing.
  361. */
  362. static void
  363. _base_display_event_data(struct MPT2SAS_ADAPTER *ioc,
  364. Mpi2EventNotificationReply_t *mpi_reply)
  365. {
  366. char *desc = NULL;
  367. u16 event;
  368. if (!(ioc->logging_level & MPT_DEBUG_EVENTS))
  369. return;
  370. event = le16_to_cpu(mpi_reply->Event);
  371. switch (event) {
  372. case MPI2_EVENT_LOG_DATA:
  373. desc = "Log Data";
  374. break;
  375. case MPI2_EVENT_STATE_CHANGE:
  376. desc = "Status Change";
  377. break;
  378. case MPI2_EVENT_HARD_RESET_RECEIVED:
  379. desc = "Hard Reset Received";
  380. break;
  381. case MPI2_EVENT_EVENT_CHANGE:
  382. desc = "Event Change";
  383. break;
  384. case MPI2_EVENT_TASK_SET_FULL:
  385. desc = "Task Set Full";
  386. break;
  387. case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
  388. desc = "Device Status Change";
  389. break;
  390. case MPI2_EVENT_IR_OPERATION_STATUS:
  391. desc = "IR Operation Status";
  392. break;
  393. case MPI2_EVENT_SAS_DISCOVERY:
  394. desc = "Discovery";
  395. break;
  396. case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
  397. desc = "SAS Broadcast Primitive";
  398. break;
  399. case MPI2_EVENT_SAS_INIT_DEVICE_STATUS_CHANGE:
  400. desc = "SAS Init Device Status Change";
  401. break;
  402. case MPI2_EVENT_SAS_INIT_TABLE_OVERFLOW:
  403. desc = "SAS Init Table Overflow";
  404. break;
  405. case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
  406. desc = "SAS Topology Change List";
  407. break;
  408. case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
  409. desc = "SAS Enclosure Device Status Change";
  410. break;
  411. case MPI2_EVENT_IR_VOLUME:
  412. desc = "IR Volume";
  413. break;
  414. case MPI2_EVENT_IR_PHYSICAL_DISK:
  415. desc = "IR Physical Disk";
  416. break;
  417. case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
  418. desc = "IR Configuration Change List";
  419. break;
  420. case MPI2_EVENT_LOG_ENTRY_ADDED:
  421. desc = "Log Entry Added";
  422. break;
  423. }
  424. if (!desc)
  425. return;
  426. printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, desc);
  427. }
  428. #endif
  429. /**
  430. * _base_sas_log_info - verbose translation of firmware log info
  431. * @ioc: pointer to scsi command object
  432. * @log_info: log info
  433. *
  434. * Return nothing.
  435. */
  436. static void
  437. _base_sas_log_info(struct MPT2SAS_ADAPTER *ioc , u32 log_info)
  438. {
  439. union loginfo_type {
  440. u32 loginfo;
  441. struct {
  442. u32 subcode:16;
  443. u32 code:8;
  444. u32 originator:4;
  445. u32 bus_type:4;
  446. } dw;
  447. };
  448. union loginfo_type sas_loginfo;
  449. char *originator_str = NULL;
  450. sas_loginfo.loginfo = log_info;
  451. if (sas_loginfo.dw.bus_type != 3 /*SAS*/)
  452. return;
  453. /* each nexus loss loginfo */
  454. if (log_info == 0x31170000)
  455. return;
  456. /* eat the loginfos associated with task aborts */
  457. if (ioc->ignore_loginfos && (log_info == 30050000 || log_info ==
  458. 0x31140000 || log_info == 0x31130000))
  459. return;
  460. switch (sas_loginfo.dw.originator) {
  461. case 0:
  462. originator_str = "IOP";
  463. break;
  464. case 1:
  465. originator_str = "PL";
  466. break;
  467. case 2:
  468. originator_str = "IR";
  469. break;
  470. }
  471. printk(MPT2SAS_WARN_FMT "log_info(0x%08x): originator(%s), "
  472. "code(0x%02x), sub_code(0x%04x)\n", ioc->name, log_info,
  473. originator_str, sas_loginfo.dw.code,
  474. sas_loginfo.dw.subcode);
  475. }
  476. /**
  477. * mpt2sas_base_fault_info - verbose translation of firmware FAULT code
  478. * @ioc: pointer to scsi command object
  479. * @fault_code: fault code
  480. *
  481. * Return nothing.
  482. */
  483. void
  484. mpt2sas_base_fault_info(struct MPT2SAS_ADAPTER *ioc , u16 fault_code)
  485. {
  486. printk(MPT2SAS_ERR_FMT "fault_state(0x%04x)!\n",
  487. ioc->name, fault_code);
  488. }
  489. /**
  490. * _base_display_reply_info -
  491. * @ioc: pointer to scsi command object
  492. * @smid: system request message index
  493. * @msix_index: MSIX table index supplied by the OS
  494. * @reply: reply message frame(lower 32bit addr)
  495. *
  496. * Return nothing.
  497. */
  498. static void
  499. _base_display_reply_info(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
  500. u32 reply)
  501. {
  502. MPI2DefaultReply_t *mpi_reply;
  503. u16 ioc_status;
  504. mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
  505. ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
  506. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  507. if ((ioc_status & MPI2_IOCSTATUS_MASK) &&
  508. (ioc->logging_level & MPT_DEBUG_REPLY)) {
  509. _base_sas_ioc_info(ioc , mpi_reply,
  510. mpt2sas_base_get_msg_frame(ioc, smid));
  511. }
  512. #endif
  513. if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
  514. _base_sas_log_info(ioc, le32_to_cpu(mpi_reply->IOCLogInfo));
  515. }
  516. /**
  517. * mpt2sas_base_done - base internal command completion routine
  518. * @ioc: pointer to scsi command object
  519. * @smid: system request message index
  520. * @msix_index: MSIX table index supplied by the OS
  521. * @reply: reply message frame(lower 32bit addr)
  522. *
  523. * Return 1 meaning mf should be freed from _base_interrupt
  524. * 0 means the mf is freed from this function.
  525. */
  526. u8
  527. mpt2sas_base_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
  528. u32 reply)
  529. {
  530. MPI2DefaultReply_t *mpi_reply;
  531. mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
  532. if (mpi_reply && mpi_reply->Function == MPI2_FUNCTION_EVENT_ACK)
  533. return 1;
  534. if (ioc->base_cmds.status == MPT2_CMD_NOT_USED)
  535. return 1;
  536. ioc->base_cmds.status |= MPT2_CMD_COMPLETE;
  537. if (mpi_reply) {
  538. ioc->base_cmds.status |= MPT2_CMD_REPLY_VALID;
  539. memcpy(ioc->base_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
  540. }
  541. ioc->base_cmds.status &= ~MPT2_CMD_PENDING;
  542. complete(&ioc->base_cmds.done);
  543. return 1;
  544. }
  545. /**
  546. * _base_async_event - main callback handler for firmware asyn events
  547. * @ioc: pointer to scsi command object
  548. * @msix_index: MSIX table index supplied by the OS
  549. * @reply: reply message frame(lower 32bit addr)
  550. *
  551. * Return 1 meaning mf should be freed from _base_interrupt
  552. * 0 means the mf is freed from this function.
  553. */
  554. static u8
  555. _base_async_event(struct MPT2SAS_ADAPTER *ioc, u8 msix_index, u32 reply)
  556. {
  557. Mpi2EventNotificationReply_t *mpi_reply;
  558. Mpi2EventAckRequest_t *ack_request;
  559. u16 smid;
  560. mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
  561. if (!mpi_reply)
  562. return 1;
  563. if (mpi_reply->Function != MPI2_FUNCTION_EVENT_NOTIFICATION)
  564. return 1;
  565. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  566. _base_display_event_data(ioc, mpi_reply);
  567. #endif
  568. if (!(mpi_reply->AckRequired & MPI2_EVENT_NOTIFICATION_ACK_REQUIRED))
  569. goto out;
  570. smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx);
  571. if (!smid) {
  572. printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
  573. ioc->name, __func__);
  574. goto out;
  575. }
  576. ack_request = mpt2sas_base_get_msg_frame(ioc, smid);
  577. memset(ack_request, 0, sizeof(Mpi2EventAckRequest_t));
  578. ack_request->Function = MPI2_FUNCTION_EVENT_ACK;
  579. ack_request->Event = mpi_reply->Event;
  580. ack_request->EventContext = mpi_reply->EventContext;
  581. ack_request->VF_ID = 0; /* TODO */
  582. ack_request->VP_ID = 0;
  583. mpt2sas_base_put_smid_default(ioc, smid);
  584. out:
  585. /* scsih callback handler */
  586. mpt2sas_scsih_event_callback(ioc, msix_index, reply);
  587. /* ctl callback handler */
  588. mpt2sas_ctl_event_callback(ioc, msix_index, reply);
  589. return 1;
  590. }
  591. /**
  592. * _base_get_cb_idx - obtain the callback index
  593. * @ioc: per adapter object
  594. * @smid: system request message index
  595. *
  596. * Return callback index.
  597. */
  598. static u8
  599. _base_get_cb_idx(struct MPT2SAS_ADAPTER *ioc, u16 smid)
  600. {
  601. int i;
  602. u8 cb_idx = 0xFF;
  603. if (smid >= ioc->hi_priority_smid) {
  604. if (smid < ioc->internal_smid) {
  605. i = smid - ioc->hi_priority_smid;
  606. cb_idx = ioc->hpr_lookup[i].cb_idx;
  607. } else {
  608. i = smid - ioc->internal_smid;
  609. cb_idx = ioc->internal_lookup[i].cb_idx;
  610. }
  611. } else {
  612. i = smid - 1;
  613. cb_idx = ioc->scsi_lookup[i].cb_idx;
  614. }
  615. return cb_idx;
  616. }
  617. /**
  618. * _base_mask_interrupts - disable interrupts
  619. * @ioc: pointer to scsi command object
  620. *
  621. * Disabling ResetIRQ, Reply and Doorbell Interrupts
  622. *
  623. * Return nothing.
  624. */
  625. static void
  626. _base_mask_interrupts(struct MPT2SAS_ADAPTER *ioc)
  627. {
  628. u32 him_register;
  629. ioc->mask_interrupts = 1;
  630. him_register = readl(&ioc->chip->HostInterruptMask);
  631. him_register |= MPI2_HIM_DIM + MPI2_HIM_RIM + MPI2_HIM_RESET_IRQ_MASK;
  632. writel(him_register, &ioc->chip->HostInterruptMask);
  633. readl(&ioc->chip->HostInterruptMask);
  634. }
  635. /**
  636. * _base_unmask_interrupts - enable interrupts
  637. * @ioc: pointer to scsi command object
  638. *
  639. * Enabling only Reply Interrupts
  640. *
  641. * Return nothing.
  642. */
  643. static void
  644. _base_unmask_interrupts(struct MPT2SAS_ADAPTER *ioc)
  645. {
  646. u32 him_register;
  647. him_register = readl(&ioc->chip->HostInterruptMask);
  648. him_register &= ~MPI2_HIM_RIM;
  649. writel(him_register, &ioc->chip->HostInterruptMask);
  650. ioc->mask_interrupts = 0;
  651. }
  652. union reply_descriptor {
  653. u64 word;
  654. struct {
  655. u32 low;
  656. u32 high;
  657. } u;
  658. };
  659. /**
  660. * _base_interrupt - MPT adapter (IOC) specific interrupt handler.
  661. * @irq: irq number (not used)
  662. * @bus_id: bus identifier cookie == pointer to MPT_ADAPTER structure
  663. * @r: pt_regs pointer (not used)
  664. *
  665. * Return IRQ_HANDLE if processed, else IRQ_NONE.
  666. */
  667. static irqreturn_t
  668. _base_interrupt(int irq, void *bus_id)
  669. {
  670. union reply_descriptor rd;
  671. u32 completed_cmds;
  672. u8 request_desript_type;
  673. u16 smid;
  674. u8 cb_idx;
  675. u32 reply;
  676. u8 msix_index;
  677. struct MPT2SAS_ADAPTER *ioc = bus_id;
  678. Mpi2ReplyDescriptorsUnion_t *rpf;
  679. u8 rc;
  680. if (ioc->mask_interrupts)
  681. return IRQ_NONE;
  682. rpf = &ioc->reply_post_free[ioc->reply_post_host_index];
  683. request_desript_type = rpf->Default.ReplyFlags
  684. & MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK;
  685. if (request_desript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED)
  686. return IRQ_NONE;
  687. completed_cmds = 0;
  688. do {
  689. rd.word = rpf->Words;
  690. if (rd.u.low == UINT_MAX || rd.u.high == UINT_MAX)
  691. goto out;
  692. reply = 0;
  693. cb_idx = 0xFF;
  694. smid = le16_to_cpu(rpf->Default.DescriptorTypeDependent1);
  695. msix_index = rpf->Default.MSIxIndex;
  696. if (request_desript_type ==
  697. MPI2_RPY_DESCRIPT_FLAGS_ADDRESS_REPLY) {
  698. reply = le32_to_cpu
  699. (rpf->AddressReply.ReplyFrameAddress);
  700. } else if (request_desript_type ==
  701. MPI2_RPY_DESCRIPT_FLAGS_TARGET_COMMAND_BUFFER)
  702. goto next;
  703. else if (request_desript_type ==
  704. MPI2_RPY_DESCRIPT_FLAGS_TARGETASSIST_SUCCESS)
  705. goto next;
  706. if (smid)
  707. cb_idx = _base_get_cb_idx(ioc, smid);
  708. if (smid && cb_idx != 0xFF) {
  709. rc = mpt_callbacks[cb_idx](ioc, smid, msix_index,
  710. reply);
  711. if (reply)
  712. _base_display_reply_info(ioc, smid, msix_index,
  713. reply);
  714. if (rc)
  715. mpt2sas_base_free_smid(ioc, smid);
  716. }
  717. if (!smid)
  718. _base_async_event(ioc, msix_index, reply);
  719. /* reply free queue handling */
  720. if (reply) {
  721. ioc->reply_free_host_index =
  722. (ioc->reply_free_host_index ==
  723. (ioc->reply_free_queue_depth - 1)) ?
  724. 0 : ioc->reply_free_host_index + 1;
  725. ioc->reply_free[ioc->reply_free_host_index] =
  726. cpu_to_le32(reply);
  727. wmb();
  728. writel(ioc->reply_free_host_index,
  729. &ioc->chip->ReplyFreeHostIndex);
  730. }
  731. next:
  732. rpf->Words = ULLONG_MAX;
  733. ioc->reply_post_host_index = (ioc->reply_post_host_index ==
  734. (ioc->reply_post_queue_depth - 1)) ? 0 :
  735. ioc->reply_post_host_index + 1;
  736. request_desript_type =
  737. ioc->reply_post_free[ioc->reply_post_host_index].Default.
  738. ReplyFlags & MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK;
  739. completed_cmds++;
  740. if (request_desript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED)
  741. goto out;
  742. if (!ioc->reply_post_host_index)
  743. rpf = ioc->reply_post_free;
  744. else
  745. rpf++;
  746. } while (1);
  747. out:
  748. if (!completed_cmds)
  749. return IRQ_NONE;
  750. wmb();
  751. writel(ioc->reply_post_host_index, &ioc->chip->ReplyPostHostIndex);
  752. return IRQ_HANDLED;
  753. }
  754. /**
  755. * mpt2sas_base_release_callback_handler - clear interupt callback handler
  756. * @cb_idx: callback index
  757. *
  758. * Return nothing.
  759. */
  760. void
  761. mpt2sas_base_release_callback_handler(u8 cb_idx)
  762. {
  763. mpt_callbacks[cb_idx] = NULL;
  764. }
  765. /**
  766. * mpt2sas_base_register_callback_handler - obtain index for the interrupt callback handler
  767. * @cb_func: callback function
  768. *
  769. * Returns cb_func.
  770. */
  771. u8
  772. mpt2sas_base_register_callback_handler(MPT_CALLBACK cb_func)
  773. {
  774. u8 cb_idx;
  775. for (cb_idx = MPT_MAX_CALLBACKS-1; cb_idx; cb_idx--)
  776. if (mpt_callbacks[cb_idx] == NULL)
  777. break;
  778. mpt_callbacks[cb_idx] = cb_func;
  779. return cb_idx;
  780. }
  781. /**
  782. * mpt2sas_base_initialize_callback_handler - initialize the interrupt callback handler
  783. *
  784. * Return nothing.
  785. */
  786. void
  787. mpt2sas_base_initialize_callback_handler(void)
  788. {
  789. u8 cb_idx;
  790. for (cb_idx = 0; cb_idx < MPT_MAX_CALLBACKS; cb_idx++)
  791. mpt2sas_base_release_callback_handler(cb_idx);
  792. }
  793. /**
  794. * mpt2sas_base_build_zero_len_sge - build zero length sg entry
  795. * @ioc: per adapter object
  796. * @paddr: virtual address for SGE
  797. *
  798. * Create a zero length scatter gather entry to insure the IOCs hardware has
  799. * something to use if the target device goes brain dead and tries
  800. * to send data even when none is asked for.
  801. *
  802. * Return nothing.
  803. */
  804. void
  805. mpt2sas_base_build_zero_len_sge(struct MPT2SAS_ADAPTER *ioc, void *paddr)
  806. {
  807. u32 flags_length = (u32)((MPI2_SGE_FLAGS_LAST_ELEMENT |
  808. MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST |
  809. MPI2_SGE_FLAGS_SIMPLE_ELEMENT) <<
  810. MPI2_SGE_FLAGS_SHIFT);
  811. ioc->base_add_sg_single(paddr, flags_length, -1);
  812. }
  813. /**
  814. * _base_add_sg_single_32 - Place a simple 32 bit SGE at address pAddr.
  815. * @paddr: virtual address for SGE
  816. * @flags_length: SGE flags and data transfer length
  817. * @dma_addr: Physical address
  818. *
  819. * Return nothing.
  820. */
  821. static void
  822. _base_add_sg_single_32(void *paddr, u32 flags_length, dma_addr_t dma_addr)
  823. {
  824. Mpi2SGESimple32_t *sgel = paddr;
  825. flags_length |= (MPI2_SGE_FLAGS_32_BIT_ADDRESSING |
  826. MPI2_SGE_FLAGS_SYSTEM_ADDRESS) << MPI2_SGE_FLAGS_SHIFT;
  827. sgel->FlagsLength = cpu_to_le32(flags_length);
  828. sgel->Address = cpu_to_le32(dma_addr);
  829. }
  830. /**
  831. * _base_add_sg_single_64 - Place a simple 64 bit SGE at address pAddr.
  832. * @paddr: virtual address for SGE
  833. * @flags_length: SGE flags and data transfer length
  834. * @dma_addr: Physical address
  835. *
  836. * Return nothing.
  837. */
  838. static void
  839. _base_add_sg_single_64(void *paddr, u32 flags_length, dma_addr_t dma_addr)
  840. {
  841. Mpi2SGESimple64_t *sgel = paddr;
  842. flags_length |= (MPI2_SGE_FLAGS_64_BIT_ADDRESSING |
  843. MPI2_SGE_FLAGS_SYSTEM_ADDRESS) << MPI2_SGE_FLAGS_SHIFT;
  844. sgel->FlagsLength = cpu_to_le32(flags_length);
  845. sgel->Address = cpu_to_le64(dma_addr);
  846. }
  847. #define convert_to_kb(x) ((x) << (PAGE_SHIFT - 10))
  848. /**
  849. * _base_config_dma_addressing - set dma addressing
  850. * @ioc: per adapter object
  851. * @pdev: PCI device struct
  852. *
  853. * Returns 0 for success, non-zero for failure.
  854. */
  855. static int
  856. _base_config_dma_addressing(struct MPT2SAS_ADAPTER *ioc, struct pci_dev *pdev)
  857. {
  858. struct sysinfo s;
  859. char *desc = NULL;
  860. if (sizeof(dma_addr_t) > 4) {
  861. const uint64_t required_mask =
  862. dma_get_required_mask(&pdev->dev);
  863. if ((required_mask > DMA_BIT_MASK(32)) && !pci_set_dma_mask(pdev,
  864. DMA_BIT_MASK(64)) && !pci_set_consistent_dma_mask(pdev,
  865. DMA_BIT_MASK(64))) {
  866. ioc->base_add_sg_single = &_base_add_sg_single_64;
  867. ioc->sge_size = sizeof(Mpi2SGESimple64_t);
  868. desc = "64";
  869. goto out;
  870. }
  871. }
  872. if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))
  873. && !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) {
  874. ioc->base_add_sg_single = &_base_add_sg_single_32;
  875. ioc->sge_size = sizeof(Mpi2SGESimple32_t);
  876. desc = "32";
  877. } else
  878. return -ENODEV;
  879. out:
  880. si_meminfo(&s);
  881. printk(MPT2SAS_INFO_FMT "%s BIT PCI BUS DMA ADDRESSING SUPPORTED, "
  882. "total mem (%ld kB)\n", ioc->name, desc, convert_to_kb(s.totalram));
  883. return 0;
  884. }
  885. /**
  886. * _base_save_msix_table - backup msix vector table
  887. * @ioc: per adapter object
  888. *
  889. * This address an errata where diag reset clears out the table
  890. */
  891. static void
  892. _base_save_msix_table(struct MPT2SAS_ADAPTER *ioc)
  893. {
  894. int i;
  895. if (!ioc->msix_enable || ioc->msix_table_backup == NULL)
  896. return;
  897. for (i = 0; i < ioc->msix_vector_count; i++)
  898. ioc->msix_table_backup[i] = ioc->msix_table[i];
  899. }
  900. /**
  901. * _base_restore_msix_table - this restores the msix vector table
  902. * @ioc: per adapter object
  903. *
  904. */
  905. static void
  906. _base_restore_msix_table(struct MPT2SAS_ADAPTER *ioc)
  907. {
  908. int i;
  909. if (!ioc->msix_enable || ioc->msix_table_backup == NULL)
  910. return;
  911. for (i = 0; i < ioc->msix_vector_count; i++)
  912. ioc->msix_table[i] = ioc->msix_table_backup[i];
  913. }
  914. /**
  915. * _base_check_enable_msix - checks MSIX capabable.
  916. * @ioc: per adapter object
  917. *
  918. * Check to see if card is capable of MSIX, and set number
  919. * of avaliable msix vectors
  920. */
  921. static int
  922. _base_check_enable_msix(struct MPT2SAS_ADAPTER *ioc)
  923. {
  924. int base;
  925. u16 message_control;
  926. u32 msix_table_offset;
  927. base = pci_find_capability(ioc->pdev, PCI_CAP_ID_MSIX);
  928. if (!base) {
  929. dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "msix not "
  930. "supported\n", ioc->name));
  931. return -EINVAL;
  932. }
  933. /* get msix vector count */
  934. pci_read_config_word(ioc->pdev, base + 2, &message_control);
  935. ioc->msix_vector_count = (message_control & 0x3FF) + 1;
  936. /* get msix table */
  937. pci_read_config_dword(ioc->pdev, base + 4, &msix_table_offset);
  938. msix_table_offset &= 0xFFFFFFF8;
  939. ioc->msix_table = (u32 *)((void *)ioc->chip + msix_table_offset);
  940. dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "msix is supported, "
  941. "vector_count(%d), table_offset(0x%08x), table(%p)\n", ioc->name,
  942. ioc->msix_vector_count, msix_table_offset, ioc->msix_table));
  943. return 0;
  944. }
  945. /**
  946. * _base_disable_msix - disables msix
  947. * @ioc: per adapter object
  948. *
  949. */
  950. static void
  951. _base_disable_msix(struct MPT2SAS_ADAPTER *ioc)
  952. {
  953. if (ioc->msix_enable) {
  954. pci_disable_msix(ioc->pdev);
  955. kfree(ioc->msix_table_backup);
  956. ioc->msix_table_backup = NULL;
  957. ioc->msix_enable = 0;
  958. }
  959. }
  960. /**
  961. * _base_enable_msix - enables msix, failback to io_apic
  962. * @ioc: per adapter object
  963. *
  964. */
  965. static int
  966. _base_enable_msix(struct MPT2SAS_ADAPTER *ioc)
  967. {
  968. struct msix_entry entries;
  969. int r;
  970. u8 try_msix = 0;
  971. if (msix_disable == -1 || msix_disable == 0)
  972. try_msix = 1;
  973. if (!try_msix)
  974. goto try_ioapic;
  975. if (_base_check_enable_msix(ioc) != 0)
  976. goto try_ioapic;
  977. ioc->msix_table_backup = kcalloc(ioc->msix_vector_count,
  978. sizeof(u32), GFP_KERNEL);
  979. if (!ioc->msix_table_backup) {
  980. dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "allocation for "
  981. "msix_table_backup failed!!!\n", ioc->name));
  982. goto try_ioapic;
  983. }
  984. memset(&entries, 0, sizeof(struct msix_entry));
  985. r = pci_enable_msix(ioc->pdev, &entries, 1);
  986. if (r) {
  987. dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "pci_enable_msix "
  988. "failed (r=%d) !!!\n", ioc->name, r));
  989. goto try_ioapic;
  990. }
  991. r = request_irq(entries.vector, _base_interrupt, IRQF_SHARED,
  992. ioc->name, ioc);
  993. if (r) {
  994. dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "unable to allocate "
  995. "interrupt %d !!!\n", ioc->name, entries.vector));
  996. pci_disable_msix(ioc->pdev);
  997. goto try_ioapic;
  998. }
  999. ioc->pci_irq = entries.vector;
  1000. ioc->msix_enable = 1;
  1001. return 0;
  1002. /* failback to io_apic interrupt routing */
  1003. try_ioapic:
  1004. r = request_irq(ioc->pdev->irq, _base_interrupt, IRQF_SHARED,
  1005. ioc->name, ioc);
  1006. if (r) {
  1007. printk(MPT2SAS_ERR_FMT "unable to allocate interrupt %d!\n",
  1008. ioc->name, ioc->pdev->irq);
  1009. r = -EBUSY;
  1010. goto out_fail;
  1011. }
  1012. ioc->pci_irq = ioc->pdev->irq;
  1013. return 0;
  1014. out_fail:
  1015. return r;
  1016. }
  1017. /**
  1018. * mpt2sas_base_map_resources - map in controller resources (io/irq/memap)
  1019. * @ioc: per adapter object
  1020. *
  1021. * Returns 0 for success, non-zero for failure.
  1022. */
  1023. int
  1024. mpt2sas_base_map_resources(struct MPT2SAS_ADAPTER *ioc)
  1025. {
  1026. struct pci_dev *pdev = ioc->pdev;
  1027. u32 memap_sz;
  1028. u32 pio_sz;
  1029. int i, r = 0;
  1030. dinitprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n",
  1031. ioc->name, __func__));
  1032. ioc->bars = pci_select_bars(pdev, IORESOURCE_MEM);
  1033. if (pci_enable_device_mem(pdev)) {
  1034. printk(MPT2SAS_WARN_FMT "pci_enable_device_mem: "
  1035. "failed\n", ioc->name);
  1036. return -ENODEV;
  1037. }
  1038. if (pci_request_selected_regions(pdev, ioc->bars,
  1039. MPT2SAS_DRIVER_NAME)) {
  1040. printk(MPT2SAS_WARN_FMT "pci_request_selected_regions: "
  1041. "failed\n", ioc->name);
  1042. r = -ENODEV;
  1043. goto out_fail;
  1044. }
  1045. pci_set_master(pdev);
  1046. if (_base_config_dma_addressing(ioc, pdev) != 0) {
  1047. printk(MPT2SAS_WARN_FMT "no suitable DMA mask for %s\n",
  1048. ioc->name, pci_name(pdev));
  1049. r = -ENODEV;
  1050. goto out_fail;
  1051. }
  1052. for (i = 0, memap_sz = 0, pio_sz = 0 ; i < DEVICE_COUNT_RESOURCE; i++) {
  1053. if (pci_resource_flags(pdev, i) & PCI_BASE_ADDRESS_SPACE_IO) {
  1054. if (pio_sz)
  1055. continue;
  1056. ioc->pio_chip = pci_resource_start(pdev, i);
  1057. pio_sz = pci_resource_len(pdev, i);
  1058. } else {
  1059. if (memap_sz)
  1060. continue;
  1061. ioc->chip_phys = pci_resource_start(pdev, i);
  1062. memap_sz = pci_resource_len(pdev, i);
  1063. ioc->chip = ioremap(ioc->chip_phys, memap_sz);
  1064. if (ioc->chip == NULL) {
  1065. printk(MPT2SAS_ERR_FMT "unable to map adapter "
  1066. "memory!\n", ioc->name);
  1067. r = -EINVAL;
  1068. goto out_fail;
  1069. }
  1070. }
  1071. }
  1072. _base_mask_interrupts(ioc);
  1073. r = _base_enable_msix(ioc);
  1074. if (r)
  1075. goto out_fail;
  1076. printk(MPT2SAS_INFO_FMT "%s: IRQ %d\n",
  1077. ioc->name, ((ioc->msix_enable) ? "PCI-MSI-X enabled" :
  1078. "IO-APIC enabled"), ioc->pci_irq);
  1079. printk(MPT2SAS_INFO_FMT "iomem(0x%lx), mapped(0x%p), size(%d)\n",
  1080. ioc->name, ioc->chip_phys, ioc->chip, memap_sz);
  1081. printk(MPT2SAS_INFO_FMT "ioport(0x%lx), size(%d)\n",
  1082. ioc->name, ioc->pio_chip, pio_sz);
  1083. return 0;
  1084. out_fail:
  1085. if (ioc->chip_phys)
  1086. iounmap(ioc->chip);
  1087. ioc->chip_phys = 0;
  1088. ioc->pci_irq = -1;
  1089. pci_release_selected_regions(ioc->pdev, ioc->bars);
  1090. pci_disable_device(pdev);
  1091. return r;
  1092. }
  1093. /**
  1094. * mpt2sas_base_get_msg_frame - obtain request mf pointer
  1095. * @ioc: per adapter object
  1096. * @smid: system request message index(smid zero is invalid)
  1097. *
  1098. * Returns virt pointer to message frame.
  1099. */
  1100. void *
  1101. mpt2sas_base_get_msg_frame(struct MPT2SAS_ADAPTER *ioc, u16 smid)
  1102. {
  1103. return (void *)(ioc->request + (smid * ioc->request_sz));
  1104. }
  1105. /**
  1106. * mpt2sas_base_get_sense_buffer - obtain a sense buffer assigned to a mf request
  1107. * @ioc: per adapter object
  1108. * @smid: system request message index
  1109. *
  1110. * Returns virt pointer to sense buffer.
  1111. */
  1112. void *
  1113. mpt2sas_base_get_sense_buffer(struct MPT2SAS_ADAPTER *ioc, u16 smid)
  1114. {
  1115. return (void *)(ioc->sense + ((smid - 1) * SCSI_SENSE_BUFFERSIZE));
  1116. }
  1117. /**
  1118. * mpt2sas_base_get_sense_buffer_dma - obtain a sense buffer assigned to a mf request
  1119. * @ioc: per adapter object
  1120. * @smid: system request message index
  1121. *
  1122. * Returns phys pointer to sense buffer.
  1123. */
  1124. dma_addr_t
  1125. mpt2sas_base_get_sense_buffer_dma(struct MPT2SAS_ADAPTER *ioc, u16 smid)
  1126. {
  1127. return ioc->sense_dma + ((smid - 1) * SCSI_SENSE_BUFFERSIZE);
  1128. }
  1129. /**
  1130. * mpt2sas_base_get_reply_virt_addr - obtain reply frames virt address
  1131. * @ioc: per adapter object
  1132. * @phys_addr: lower 32 physical addr of the reply
  1133. *
  1134. * Converts 32bit lower physical addr into a virt address.
  1135. */
  1136. void *
  1137. mpt2sas_base_get_reply_virt_addr(struct MPT2SAS_ADAPTER *ioc, u32 phys_addr)
  1138. {
  1139. if (!phys_addr)
  1140. return NULL;
  1141. return ioc->reply + (phys_addr - (u32)ioc->reply_dma);
  1142. }
  1143. /**
  1144. * mpt2sas_base_get_smid - obtain a free smid from internal queue
  1145. * @ioc: per adapter object
  1146. * @cb_idx: callback index
  1147. *
  1148. * Returns smid (zero is invalid)
  1149. */
  1150. u16
  1151. mpt2sas_base_get_smid(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx)
  1152. {
  1153. unsigned long flags;
  1154. struct request_tracker *request;
  1155. u16 smid;
  1156. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  1157. if (list_empty(&ioc->internal_free_list)) {
  1158. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  1159. printk(MPT2SAS_ERR_FMT "%s: smid not available\n",
  1160. ioc->name, __func__);
  1161. return 0;
  1162. }
  1163. request = list_entry(ioc->internal_free_list.next,
  1164. struct request_tracker, tracker_list);
  1165. request->cb_idx = cb_idx;
  1166. smid = request->smid;
  1167. list_del(&request->tracker_list);
  1168. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  1169. return smid;
  1170. }
  1171. /**
  1172. * mpt2sas_base_get_smid_scsiio - obtain a free smid from scsiio queue
  1173. * @ioc: per adapter object
  1174. * @cb_idx: callback index
  1175. * @scmd: pointer to scsi command object
  1176. *
  1177. * Returns smid (zero is invalid)
  1178. */
  1179. u16
  1180. mpt2sas_base_get_smid_scsiio(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx,
  1181. struct scsi_cmnd *scmd)
  1182. {
  1183. unsigned long flags;
  1184. struct request_tracker *request;
  1185. u16 smid;
  1186. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  1187. if (list_empty(&ioc->free_list)) {
  1188. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  1189. printk(MPT2SAS_ERR_FMT "%s: smid not available\n",
  1190. ioc->name, __func__);
  1191. return 0;
  1192. }
  1193. request = list_entry(ioc->free_list.next,
  1194. struct request_tracker, tracker_list);
  1195. request->scmd = scmd;
  1196. request->cb_idx = cb_idx;
  1197. smid = request->smid;
  1198. list_del(&request->tracker_list);
  1199. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  1200. return smid;
  1201. }
  1202. /**
  1203. * mpt2sas_base_get_smid_hpr - obtain a free smid from hi-priority queue
  1204. * @ioc: per adapter object
  1205. * @cb_idx: callback index
  1206. *
  1207. * Returns smid (zero is invalid)
  1208. */
  1209. u16
  1210. mpt2sas_base_get_smid_hpr(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx)
  1211. {
  1212. unsigned long flags;
  1213. struct request_tracker *request;
  1214. u16 smid;
  1215. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  1216. if (list_empty(&ioc->hpr_free_list)) {
  1217. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  1218. return 0;
  1219. }
  1220. request = list_entry(ioc->hpr_free_list.next,
  1221. struct request_tracker, tracker_list);
  1222. request->cb_idx = cb_idx;
  1223. smid = request->smid;
  1224. list_del(&request->tracker_list);
  1225. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  1226. return smid;
  1227. }
  1228. /**
  1229. * mpt2sas_base_free_smid - put smid back on free_list
  1230. * @ioc: per adapter object
  1231. * @smid: system request message index
  1232. *
  1233. * Return nothing.
  1234. */
  1235. void
  1236. mpt2sas_base_free_smid(struct MPT2SAS_ADAPTER *ioc, u16 smid)
  1237. {
  1238. unsigned long flags;
  1239. int i;
  1240. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  1241. if (smid >= ioc->hi_priority_smid) {
  1242. if (smid < ioc->internal_smid) {
  1243. /* hi-priority */
  1244. i = smid - ioc->hi_priority_smid;
  1245. ioc->hpr_lookup[i].cb_idx = 0xFF;
  1246. list_add_tail(&ioc->hpr_lookup[i].tracker_list,
  1247. &ioc->hpr_free_list);
  1248. } else {
  1249. /* internal queue */
  1250. i = smid - ioc->internal_smid;
  1251. ioc->internal_lookup[i].cb_idx = 0xFF;
  1252. list_add_tail(&ioc->internal_lookup[i].tracker_list,
  1253. &ioc->internal_free_list);
  1254. }
  1255. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  1256. return;
  1257. }
  1258. /* scsiio queue */
  1259. i = smid - 1;
  1260. ioc->scsi_lookup[i].cb_idx = 0xFF;
  1261. ioc->scsi_lookup[i].scmd = NULL;
  1262. list_add_tail(&ioc->scsi_lookup[i].tracker_list,
  1263. &ioc->free_list);
  1264. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  1265. /*
  1266. * See _wait_for_commands_to_complete() call with regards to this code.
  1267. */
  1268. if (ioc->shost_recovery && ioc->pending_io_count) {
  1269. if (ioc->pending_io_count == 1)
  1270. wake_up(&ioc->reset_wq);
  1271. ioc->pending_io_count--;
  1272. }
  1273. }
  1274. /**
  1275. * _base_writeq - 64 bit write to MMIO
  1276. * @ioc: per adapter object
  1277. * @b: data payload
  1278. * @addr: address in MMIO space
  1279. * @writeq_lock: spin lock
  1280. *
  1281. * Glue for handling an atomic 64 bit word to MMIO. This special handling takes
  1282. * care of 32 bit environment where its not quarenteed to send the entire word
  1283. * in one transfer.
  1284. */
  1285. #ifndef writeq
  1286. static inline void _base_writeq(__u64 b, volatile void __iomem *addr,
  1287. spinlock_t *writeq_lock)
  1288. {
  1289. unsigned long flags;
  1290. __u64 data_out = cpu_to_le64(b);
  1291. spin_lock_irqsave(writeq_lock, flags);
  1292. writel((u32)(data_out), addr);
  1293. writel((u32)(data_out >> 32), (addr + 4));
  1294. spin_unlock_irqrestore(writeq_lock, flags);
  1295. }
  1296. #else
  1297. static inline void _base_writeq(__u64 b, volatile void __iomem *addr,
  1298. spinlock_t *writeq_lock)
  1299. {
  1300. writeq(cpu_to_le64(b), addr);
  1301. }
  1302. #endif
  1303. /**
  1304. * mpt2sas_base_put_smid_scsi_io - send SCSI_IO request to firmware
  1305. * @ioc: per adapter object
  1306. * @smid: system request message index
  1307. * @handle: device handle
  1308. *
  1309. * Return nothing.
  1310. */
  1311. void
  1312. mpt2sas_base_put_smid_scsi_io(struct MPT2SAS_ADAPTER *ioc, u16 smid, u16 handle)
  1313. {
  1314. Mpi2RequestDescriptorUnion_t descriptor;
  1315. u64 *request = (u64 *)&descriptor;
  1316. descriptor.SCSIIO.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO;
  1317. descriptor.SCSIIO.MSIxIndex = 0; /* TODO */
  1318. descriptor.SCSIIO.SMID = cpu_to_le16(smid);
  1319. descriptor.SCSIIO.DevHandle = cpu_to_le16(handle);
  1320. descriptor.SCSIIO.LMID = 0;
  1321. _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow,
  1322. &ioc->scsi_lookup_lock);
  1323. }
  1324. /**
  1325. * mpt2sas_base_put_smid_hi_priority - send Task Managment request to firmware
  1326. * @ioc: per adapter object
  1327. * @smid: system request message index
  1328. *
  1329. * Return nothing.
  1330. */
  1331. void
  1332. mpt2sas_base_put_smid_hi_priority(struct MPT2SAS_ADAPTER *ioc, u16 smid)
  1333. {
  1334. Mpi2RequestDescriptorUnion_t descriptor;
  1335. u64 *request = (u64 *)&descriptor;
  1336. descriptor.HighPriority.RequestFlags =
  1337. MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY;
  1338. descriptor.HighPriority.MSIxIndex = 0; /* TODO */
  1339. descriptor.HighPriority.SMID = cpu_to_le16(smid);
  1340. descriptor.HighPriority.LMID = 0;
  1341. descriptor.HighPriority.Reserved1 = 0;
  1342. _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow,
  1343. &ioc->scsi_lookup_lock);
  1344. }
  1345. /**
  1346. * mpt2sas_base_put_smid_default - Default, primarily used for config pages
  1347. * @ioc: per adapter object
  1348. * @smid: system request message index
  1349. *
  1350. * Return nothing.
  1351. */
  1352. void
  1353. mpt2sas_base_put_smid_default(struct MPT2SAS_ADAPTER *ioc, u16 smid)
  1354. {
  1355. Mpi2RequestDescriptorUnion_t descriptor;
  1356. u64 *request = (u64 *)&descriptor;
  1357. descriptor.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
  1358. descriptor.Default.MSIxIndex = 0; /* TODO */
  1359. descriptor.Default.SMID = cpu_to_le16(smid);
  1360. descriptor.Default.LMID = 0;
  1361. descriptor.Default.DescriptorTypeDependent = 0;
  1362. _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow,
  1363. &ioc->scsi_lookup_lock);
  1364. }
  1365. /**
  1366. * mpt2sas_base_put_smid_target_assist - send Target Assist/Status to firmware
  1367. * @ioc: per adapter object
  1368. * @smid: system request message index
  1369. * @io_index: value used to track the IO
  1370. *
  1371. * Return nothing.
  1372. */
  1373. void
  1374. mpt2sas_base_put_smid_target_assist(struct MPT2SAS_ADAPTER *ioc, u16 smid,
  1375. u16 io_index)
  1376. {
  1377. Mpi2RequestDescriptorUnion_t descriptor;
  1378. u64 *request = (u64 *)&descriptor;
  1379. descriptor.SCSITarget.RequestFlags =
  1380. MPI2_REQ_DESCRIPT_FLAGS_SCSI_TARGET;
  1381. descriptor.SCSITarget.MSIxIndex = 0; /* TODO */
  1382. descriptor.SCSITarget.SMID = cpu_to_le16(smid);
  1383. descriptor.SCSITarget.LMID = 0;
  1384. descriptor.SCSITarget.IoIndex = cpu_to_le16(io_index);
  1385. _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow,
  1386. &ioc->scsi_lookup_lock);
  1387. }
  1388. /**
  1389. * _base_display_dell_branding - Disply branding string
  1390. * @ioc: per adapter object
  1391. *
  1392. * Return nothing.
  1393. */
  1394. static void
  1395. _base_display_dell_branding(struct MPT2SAS_ADAPTER *ioc)
  1396. {
  1397. char dell_branding[MPT2SAS_DELL_BRANDING_SIZE];
  1398. if (ioc->pdev->subsystem_vendor != PCI_VENDOR_ID_DELL)
  1399. return;
  1400. memset(dell_branding, 0, MPT2SAS_DELL_BRANDING_SIZE);
  1401. switch (ioc->pdev->subsystem_device) {
  1402. case MPT2SAS_DELL_6GBPS_SAS_HBA_SSDID:
  1403. strncpy(dell_branding, MPT2SAS_DELL_6GBPS_SAS_HBA_BRANDING,
  1404. MPT2SAS_DELL_BRANDING_SIZE - 1);
  1405. break;
  1406. case MPT2SAS_DELL_PERC_H200_ADAPTER_SSDID:
  1407. strncpy(dell_branding, MPT2SAS_DELL_PERC_H200_ADAPTER_BRANDING,
  1408. MPT2SAS_DELL_BRANDING_SIZE - 1);
  1409. break;
  1410. case MPT2SAS_DELL_PERC_H200_INTEGRATED_SSDID:
  1411. strncpy(dell_branding,
  1412. MPT2SAS_DELL_PERC_H200_INTEGRATED_BRANDING,
  1413. MPT2SAS_DELL_BRANDING_SIZE - 1);
  1414. break;
  1415. case MPT2SAS_DELL_PERC_H200_MODULAR_SSDID:
  1416. strncpy(dell_branding,
  1417. MPT2SAS_DELL_PERC_H200_MODULAR_BRANDING,
  1418. MPT2SAS_DELL_BRANDING_SIZE - 1);
  1419. break;
  1420. case MPT2SAS_DELL_PERC_H200_EMBEDDED_SSDID:
  1421. strncpy(dell_branding,
  1422. MPT2SAS_DELL_PERC_H200_EMBEDDED_BRANDING,
  1423. MPT2SAS_DELL_BRANDING_SIZE - 1);
  1424. break;
  1425. case MPT2SAS_DELL_PERC_H200_SSDID:
  1426. strncpy(dell_branding, MPT2SAS_DELL_PERC_H200_BRANDING,
  1427. MPT2SAS_DELL_BRANDING_SIZE - 1);
  1428. break;
  1429. case MPT2SAS_DELL_6GBPS_SAS_SSDID:
  1430. strncpy(dell_branding, MPT2SAS_DELL_6GBPS_SAS_BRANDING,
  1431. MPT2SAS_DELL_BRANDING_SIZE - 1);
  1432. break;
  1433. default:
  1434. sprintf(dell_branding, "0x%4X", ioc->pdev->subsystem_device);
  1435. break;
  1436. }
  1437. printk(MPT2SAS_INFO_FMT "%s: Vendor(0x%04X), Device(0x%04X),"
  1438. " SSVID(0x%04X), SSDID(0x%04X)\n", ioc->name, dell_branding,
  1439. ioc->pdev->vendor, ioc->pdev->device, ioc->pdev->subsystem_vendor,
  1440. ioc->pdev->subsystem_device);
  1441. }
  1442. /**
  1443. * _base_display_ioc_capabilities - Disply IOC's capabilities.
  1444. * @ioc: per adapter object
  1445. *
  1446. * Return nothing.
  1447. */
  1448. static void
  1449. _base_display_ioc_capabilities(struct MPT2SAS_ADAPTER *ioc)
  1450. {
  1451. int i = 0;
  1452. char desc[16];
  1453. u8 revision;
  1454. u32 iounit_pg1_flags;
  1455. pci_read_config_byte(ioc->pdev, PCI_CLASS_REVISION, &revision);
  1456. strncpy(desc, ioc->manu_pg0.ChipName, 16);
  1457. printk(MPT2SAS_INFO_FMT "%s: FWVersion(%02d.%02d.%02d.%02d), "
  1458. "ChipRevision(0x%02x), BiosVersion(%02d.%02d.%02d.%02d)\n",
  1459. ioc->name, desc,
  1460. (ioc->facts.FWVersion.Word & 0xFF000000) >> 24,
  1461. (ioc->facts.FWVersion.Word & 0x00FF0000) >> 16,
  1462. (ioc->facts.FWVersion.Word & 0x0000FF00) >> 8,
  1463. ioc->facts.FWVersion.Word & 0x000000FF,
  1464. revision,
  1465. (ioc->bios_pg3.BiosVersion & 0xFF000000) >> 24,
  1466. (ioc->bios_pg3.BiosVersion & 0x00FF0000) >> 16,
  1467. (ioc->bios_pg3.BiosVersion & 0x0000FF00) >> 8,
  1468. ioc->bios_pg3.BiosVersion & 0x000000FF);
  1469. _base_display_dell_branding(ioc);
  1470. printk(MPT2SAS_INFO_FMT "Protocol=(", ioc->name);
  1471. if (ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR) {
  1472. printk("Initiator");
  1473. i++;
  1474. }
  1475. if (ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_TARGET) {
  1476. printk("%sTarget", i ? "," : "");
  1477. i++;
  1478. }
  1479. i = 0;
  1480. printk("), ");
  1481. printk("Capabilities=(");
  1482. if (ioc->facts.IOCCapabilities &
  1483. MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID) {
  1484. printk("Raid");
  1485. i++;
  1486. }
  1487. if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR) {
  1488. printk("%sTLR", i ? "," : "");
  1489. i++;
  1490. }
  1491. if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_MULTICAST) {
  1492. printk("%sMulticast", i ? "," : "");
  1493. i++;
  1494. }
  1495. if (ioc->facts.IOCCapabilities &
  1496. MPI2_IOCFACTS_CAPABILITY_BIDIRECTIONAL_TARGET) {
  1497. printk("%sBIDI Target", i ? "," : "");
  1498. i++;
  1499. }
  1500. if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_EEDP) {
  1501. printk("%sEEDP", i ? "," : "");
  1502. i++;
  1503. }
  1504. if (ioc->facts.IOCCapabilities &
  1505. MPI2_IOCFACTS_CAPABILITY_SNAPSHOT_BUFFER) {
  1506. printk("%sSnapshot Buffer", i ? "," : "");
  1507. i++;
  1508. }
  1509. if (ioc->facts.IOCCapabilities &
  1510. MPI2_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER) {
  1511. printk("%sDiag Trace Buffer", i ? "," : "");
  1512. i++;
  1513. }
  1514. if (ioc->facts.IOCCapabilities &
  1515. MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING) {
  1516. printk("%sTask Set Full", i ? "," : "");
  1517. i++;
  1518. }
  1519. iounit_pg1_flags = le32_to_cpu(ioc->iounit_pg1.Flags);
  1520. if (!(iounit_pg1_flags & MPI2_IOUNITPAGE1_NATIVE_COMMAND_Q_DISABLE)) {
  1521. printk("%sNCQ", i ? "," : "");
  1522. i++;
  1523. }
  1524. printk(")\n");
  1525. }
  1526. /**
  1527. * _base_static_config_pages - static start of day config pages
  1528. * @ioc: per adapter object
  1529. *
  1530. * Return nothing.
  1531. */
  1532. static void
  1533. _base_static_config_pages(struct MPT2SAS_ADAPTER *ioc)
  1534. {
  1535. Mpi2ConfigReply_t mpi_reply;
  1536. u32 iounit_pg1_flags;
  1537. mpt2sas_config_get_manufacturing_pg0(ioc, &mpi_reply, &ioc->manu_pg0);
  1538. if (ioc->ir_firmware)
  1539. mpt2sas_config_get_manufacturing_pg10(ioc, &mpi_reply,
  1540. &ioc->manu_pg10);
  1541. mpt2sas_config_get_bios_pg2(ioc, &mpi_reply, &ioc->bios_pg2);
  1542. mpt2sas_config_get_bios_pg3(ioc, &mpi_reply, &ioc->bios_pg3);
  1543. mpt2sas_config_get_ioc_pg8(ioc, &mpi_reply, &ioc->ioc_pg8);
  1544. mpt2sas_config_get_iounit_pg0(ioc, &mpi_reply, &ioc->iounit_pg0);
  1545. mpt2sas_config_get_iounit_pg1(ioc, &mpi_reply, &ioc->iounit_pg1);
  1546. _base_display_ioc_capabilities(ioc);
  1547. /*
  1548. * Enable task_set_full handling in iounit_pg1 when the
  1549. * facts capabilities indicate that its supported.
  1550. */
  1551. iounit_pg1_flags = le32_to_cpu(ioc->iounit_pg1.Flags);
  1552. if ((ioc->facts.IOCCapabilities &
  1553. MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING))
  1554. iounit_pg1_flags &=
  1555. ~MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING;
  1556. else
  1557. iounit_pg1_flags |=
  1558. MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING;
  1559. ioc->iounit_pg1.Flags = cpu_to_le32(iounit_pg1_flags);
  1560. mpt2sas_config_set_iounit_pg1(ioc, &mpi_reply, &ioc->iounit_pg1);
  1561. }
  1562. /**
  1563. * _base_release_memory_pools - release memory
  1564. * @ioc: per adapter object
  1565. *
  1566. * Free memory allocated from _base_allocate_memory_pools.
  1567. *
  1568. * Return nothing.
  1569. */
  1570. static void
  1571. _base_release_memory_pools(struct MPT2SAS_ADAPTER *ioc)
  1572. {
  1573. dexitprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n", ioc->name,
  1574. __func__));
  1575. if (ioc->request) {
  1576. pci_free_consistent(ioc->pdev, ioc->request_dma_sz,
  1577. ioc->request, ioc->request_dma);
  1578. dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "request_pool(0x%p)"
  1579. ": free\n", ioc->name, ioc->request));
  1580. ioc->request = NULL;
  1581. }
  1582. if (ioc->sense) {
  1583. pci_pool_free(ioc->sense_dma_pool, ioc->sense, ioc->sense_dma);
  1584. if (ioc->sense_dma_pool)
  1585. pci_pool_destroy(ioc->sense_dma_pool);
  1586. dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "sense_pool(0x%p)"
  1587. ": free\n", ioc->name, ioc->sense));
  1588. ioc->sense = NULL;
  1589. }
  1590. if (ioc->reply) {
  1591. pci_pool_free(ioc->reply_dma_pool, ioc->reply, ioc->reply_dma);
  1592. if (ioc->reply_dma_pool)
  1593. pci_pool_destroy(ioc->reply_dma_pool);
  1594. dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_pool(0x%p)"
  1595. ": free\n", ioc->name, ioc->reply));
  1596. ioc->reply = NULL;
  1597. }
  1598. if (ioc->reply_free) {
  1599. pci_pool_free(ioc->reply_free_dma_pool, ioc->reply_free,
  1600. ioc->reply_free_dma);
  1601. if (ioc->reply_free_dma_pool)
  1602. pci_pool_destroy(ioc->reply_free_dma_pool);
  1603. dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_free_pool"
  1604. "(0x%p): free\n", ioc->name, ioc->reply_free));
  1605. ioc->reply_free = NULL;
  1606. }
  1607. if (ioc->reply_post_free) {
  1608. pci_pool_free(ioc->reply_post_free_dma_pool,
  1609. ioc->reply_post_free, ioc->reply_post_free_dma);
  1610. if (ioc->reply_post_free_dma_pool)
  1611. pci_pool_destroy(ioc->reply_post_free_dma_pool);
  1612. dexitprintk(ioc, printk(MPT2SAS_INFO_FMT
  1613. "reply_post_free_pool(0x%p): free\n", ioc->name,
  1614. ioc->reply_post_free));
  1615. ioc->reply_post_free = NULL;
  1616. }
  1617. if (ioc->config_page) {
  1618. dexitprintk(ioc, printk(MPT2SAS_INFO_FMT
  1619. "config_page(0x%p): free\n", ioc->name,
  1620. ioc->config_page));
  1621. pci_free_consistent(ioc->pdev, ioc->config_page_sz,
  1622. ioc->config_page, ioc->config_page_dma);
  1623. }
  1624. kfree(ioc->scsi_lookup);
  1625. kfree(ioc->hpr_lookup);
  1626. kfree(ioc->interna

Large files files are truncated, but you can click here to view the full file