mpt2sas_config.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455
  1. /*
  2. * This module provides common API for accessing firmware configuration pages
  3. *
  4. * This code is based on drivers/scsi/mpt2sas/mpt2_base.c
  5. * Copyright (C) 2007-2010 LSI Corporation
  6. * (mailto:DL-MPTFusionLinux@lsi.com)
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * NO WARRANTY
  19. * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
  20. * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
  21. * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
  22. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
  23. * solely responsible for determining the appropriateness of using and
  24. * distributing the Program and assumes all risks associated with its
  25. * exercise of rights under this Agreement, including but not limited to
  26. * the risks and costs of program errors, damage to or loss of data,
  27. * programs or equipment, and unavailability or interruption of operations.
  28. * DISCLAIMER OF LIABILITY
  29. * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
  30. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31. * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
  32. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  33. * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  34. * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
  35. * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
  36. * You should have received a copy of the GNU General Public License
  37. * along with this program; if not, write to the Free Software
  38. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
  39. * USA.
  40. */
  41. #include <linux/module.h>
  42. #include <linux/kernel.h>
  43. #include <linux/init.h>
  44. #include <linux/errno.h>
  45. #include <linux/blkdev.h>
  46. #include <linux/sched.h>
  47. #include <linux/workqueue.h>
  48. #include <linux/delay.h>
  49. #include <linux/pci.h>
  50. #include <linux/slab.h>
  51. #include "mpt2sas_base.h"
  52. /* local definitions */
  53. /* Timeout for config page request (in seconds) */
  54. #define MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT 15
  55. /* Common sgl flags for READING a config page. */
  56. #define MPT2_CONFIG_COMMON_SGLFLAGS ((MPI2_SGE_FLAGS_SIMPLE_ELEMENT | \
  57. MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER \
  58. | MPI2_SGE_FLAGS_END_OF_LIST) << MPI2_SGE_FLAGS_SHIFT)
  59. /* Common sgl flags for WRITING a config page. */
  60. #define MPT2_CONFIG_COMMON_WRITE_SGLFLAGS ((MPI2_SGE_FLAGS_SIMPLE_ELEMENT | \
  61. MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER \
  62. | MPI2_SGE_FLAGS_END_OF_LIST | MPI2_SGE_FLAGS_HOST_TO_IOC) \
  63. << MPI2_SGE_FLAGS_SHIFT)
  64. /**
  65. * struct config_request - obtain dma memory via routine
  66. * @sz: size
  67. * @page: virt pointer
  68. * @page_dma: phys pointer
  69. *
  70. */
  71. struct config_request{
  72. u16 sz;
  73. void *page;
  74. dma_addr_t page_dma;
  75. };
  76. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  77. /**
  78. * _config_display_some_debug - debug routine
  79. * @ioc: per adapter object
  80. * @smid: system request message index
  81. * @calling_function_name: string pass from calling function
  82. * @mpi_reply: reply message frame
  83. * Context: none.
  84. *
  85. * Function for displaying debug info helpful when debugging issues
  86. * in this module.
  87. */
  88. static void
  89. _config_display_some_debug(struct MPT2SAS_ADAPTER *ioc, u16 smid,
  90. char *calling_function_name, MPI2DefaultReply_t *mpi_reply)
  91. {
  92. Mpi2ConfigRequest_t *mpi_request;
  93. char *desc = NULL;
  94. if (!(ioc->logging_level & MPT_DEBUG_CONFIG))
  95. return;
  96. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
  97. switch (mpi_request->Header.PageType & MPI2_CONFIG_PAGETYPE_MASK) {
  98. case MPI2_CONFIG_PAGETYPE_IO_UNIT:
  99. desc = "io_unit";
  100. break;
  101. case MPI2_CONFIG_PAGETYPE_IOC:
  102. desc = "ioc";
  103. break;
  104. case MPI2_CONFIG_PAGETYPE_BIOS:
  105. desc = "bios";
  106. break;
  107. case MPI2_CONFIG_PAGETYPE_RAID_VOLUME:
  108. desc = "raid_volume";
  109. break;
  110. case MPI2_CONFIG_PAGETYPE_MANUFACTURING:
  111. desc = "manufaucturing";
  112. break;
  113. case MPI2_CONFIG_PAGETYPE_RAID_PHYSDISK:
  114. desc = "physdisk";
  115. break;
  116. case MPI2_CONFIG_PAGETYPE_EXTENDED:
  117. switch (mpi_request->ExtPageType) {
  118. case MPI2_CONFIG_EXTPAGETYPE_SAS_IO_UNIT:
  119. desc = "sas_io_unit";
  120. break;
  121. case MPI2_CONFIG_EXTPAGETYPE_SAS_EXPANDER:
  122. desc = "sas_expander";
  123. break;
  124. case MPI2_CONFIG_EXTPAGETYPE_SAS_DEVICE:
  125. desc = "sas_device";
  126. break;
  127. case MPI2_CONFIG_EXTPAGETYPE_SAS_PHY:
  128. desc = "sas_phy";
  129. break;
  130. case MPI2_CONFIG_EXTPAGETYPE_LOG:
  131. desc = "log";
  132. break;
  133. case MPI2_CONFIG_EXTPAGETYPE_ENCLOSURE:
  134. desc = "enclosure";
  135. break;
  136. case MPI2_CONFIG_EXTPAGETYPE_RAID_CONFIG:
  137. desc = "raid_config";
  138. break;
  139. case MPI2_CONFIG_EXTPAGETYPE_DRIVER_MAPPING:
  140. desc = "driver_mapping";
  141. break;
  142. }
  143. break;
  144. }
  145. if (!desc)
  146. return;
  147. printk(MPT2SAS_INFO_FMT "%s: %s(%d), action(%d), form(0x%08x), "
  148. "smid(%d)\n", ioc->name, calling_function_name, desc,
  149. mpi_request->Header.PageNumber, mpi_request->Action,
  150. le32_to_cpu(mpi_request->PageAddress), smid);
  151. if (!mpi_reply)
  152. return;
  153. if (mpi_reply->IOCStatus || mpi_reply->IOCLogInfo)
  154. printk(MPT2SAS_INFO_FMT
  155. "\tiocstatus(0x%04x), loginfo(0x%08x)\n",
  156. ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
  157. le32_to_cpu(mpi_reply->IOCLogInfo));
  158. }
  159. #endif
  160. /**
  161. * _config_alloc_config_dma_memory - obtain physical memory
  162. * @ioc: per adapter object
  163. * @mem: struct config_request
  164. *
  165. * A wrapper for obtaining dma-able memory for config page request.
  166. *
  167. * Returns 0 for success, non-zero for failure.
  168. */
  169. static int
  170. _config_alloc_config_dma_memory(struct MPT2SAS_ADAPTER *ioc,
  171. struct config_request *mem)
  172. {
  173. int r = 0;
  174. if (mem->sz > ioc->config_page_sz) {
  175. mem->page = dma_alloc_coherent(&ioc->pdev->dev, mem->sz,
  176. &mem->page_dma, GFP_KERNEL);
  177. if (!mem->page) {
  178. printk(MPT2SAS_ERR_FMT "%s: dma_alloc_coherent"
  179. " failed asking for (%d) bytes!!\n",
  180. ioc->name, __func__, mem->sz);
  181. r = -ENOMEM;
  182. }
  183. } else { /* use tmp buffer if less than 512 bytes */
  184. mem->page = ioc->config_page;
  185. mem->page_dma = ioc->config_page_dma;
  186. }
  187. return r;
  188. }
  189. /**
  190. * _config_free_config_dma_memory - wrapper to free the memory
  191. * @ioc: per adapter object
  192. * @mem: struct config_request
  193. *
  194. * A wrapper to free dma-able memory when using _config_alloc_config_dma_memory.
  195. *
  196. * Returns 0 for success, non-zero for failure.
  197. */
  198. static void
  199. _config_free_config_dma_memory(struct MPT2SAS_ADAPTER *ioc,
  200. struct config_request *mem)
  201. {
  202. if (mem->sz > ioc->config_page_sz)
  203. dma_free_coherent(&ioc->pdev->dev, mem->sz, mem->page,
  204. mem->page_dma);
  205. }
  206. /**
  207. * mpt2sas_config_done - config page completion routine
  208. * @ioc: per adapter object
  209. * @smid: system request message index
  210. * @msix_index: MSIX table index supplied by the OS
  211. * @reply: reply message frame(lower 32bit addr)
  212. * Context: none.
  213. *
  214. * The callback handler when using _config_request.
  215. *
  216. * Return 1 meaning mf should be freed from _base_interrupt
  217. * 0 means the mf is freed from this function.
  218. */
  219. u8
  220. mpt2sas_config_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
  221. u32 reply)
  222. {
  223. MPI2DefaultReply_t *mpi_reply;
  224. if (ioc->config_cmds.status == MPT2_CMD_NOT_USED)
  225. return 1;
  226. if (ioc->config_cmds.smid != smid)
  227. return 1;
  228. ioc->config_cmds.status |= MPT2_CMD_COMPLETE;
  229. mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
  230. if (mpi_reply) {
  231. ioc->config_cmds.status |= MPT2_CMD_REPLY_VALID;
  232. memcpy(ioc->config_cmds.reply, mpi_reply,
  233. mpi_reply->MsgLength*4);
  234. }
  235. ioc->config_cmds.status &= ~MPT2_CMD_PENDING;
  236. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  237. _config_display_some_debug(ioc, smid, "config_done", mpi_reply);
  238. #endif
  239. ioc->config_cmds.smid = USHRT_MAX;
  240. complete(&ioc->config_cmds.done);
  241. return 1;
  242. }
  243. /**
  244. * _config_request - main routine for sending config page requests
  245. * @ioc: per adapter object
  246. * @mpi_request: request message frame
  247. * @mpi_reply: reply mf payload returned from firmware
  248. * @timeout: timeout in seconds
  249. * @config_page: contents of the config page
  250. * @config_page_sz: size of config page
  251. * Context: sleep
  252. *
  253. * A generic API for config page requests to firmware.
  254. *
  255. * The ioc->config_cmds.status flag should be MPT2_CMD_NOT_USED before calling
  256. * this API.
  257. *
  258. * The callback index is set inside `ioc->config_cb_idx.
  259. *
  260. * Returns 0 for success, non-zero for failure.
  261. */
  262. static int
  263. _config_request(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigRequest_t
  264. *mpi_request, Mpi2ConfigReply_t *mpi_reply, int timeout,
  265. void *config_page, u16 config_page_sz)
  266. {
  267. u16 smid;
  268. u32 ioc_state;
  269. unsigned long timeleft;
  270. Mpi2ConfigRequest_t *config_request;
  271. int r;
  272. u8 retry_count, issue_host_reset = 0;
  273. u16 wait_state_count;
  274. struct config_request mem;
  275. mutex_lock(&ioc->config_cmds.mutex);
  276. if (ioc->config_cmds.status != MPT2_CMD_NOT_USED) {
  277. printk(MPT2SAS_ERR_FMT "%s: config_cmd in use\n",
  278. ioc->name, __func__);
  279. mutex_unlock(&ioc->config_cmds.mutex);
  280. return -EAGAIN;
  281. }
  282. retry_count = 0;
  283. memset(&mem, 0, sizeof(struct config_request));
  284. mpi_request->VF_ID = 0; /* TODO */
  285. mpi_request->VP_ID = 0;
  286. if (config_page) {
  287. mpi_request->Header.PageVersion = mpi_reply->Header.PageVersion;
  288. mpi_request->Header.PageNumber = mpi_reply->Header.PageNumber;
  289. mpi_request->Header.PageType = mpi_reply->Header.PageType;
  290. mpi_request->Header.PageLength = mpi_reply->Header.PageLength;
  291. mpi_request->ExtPageLength = mpi_reply->ExtPageLength;
  292. mpi_request->ExtPageType = mpi_reply->ExtPageType;
  293. if (mpi_request->Header.PageLength)
  294. mem.sz = mpi_request->Header.PageLength * 4;
  295. else
  296. mem.sz = le16_to_cpu(mpi_reply->ExtPageLength) * 4;
  297. r = _config_alloc_config_dma_memory(ioc, &mem);
  298. if (r != 0)
  299. goto out;
  300. if (mpi_request->Action ==
  301. MPI2_CONFIG_ACTION_PAGE_WRITE_CURRENT ||
  302. mpi_request->Action ==
  303. MPI2_CONFIG_ACTION_PAGE_WRITE_NVRAM) {
  304. ioc->base_add_sg_single(&mpi_request->PageBufferSGE,
  305. MPT2_CONFIG_COMMON_WRITE_SGLFLAGS | mem.sz,
  306. mem.page_dma);
  307. memcpy(mem.page, config_page, min_t(u16, mem.sz,
  308. config_page_sz));
  309. } else {
  310. memset(config_page, 0, config_page_sz);
  311. ioc->base_add_sg_single(&mpi_request->PageBufferSGE,
  312. MPT2_CONFIG_COMMON_SGLFLAGS | mem.sz, mem.page_dma);
  313. }
  314. }
  315. retry_config:
  316. if (retry_count) {
  317. if (retry_count > 2) { /* attempt only 2 retries */
  318. r = -EFAULT;
  319. goto free_mem;
  320. }
  321. printk(MPT2SAS_INFO_FMT "%s: attempting retry (%d)\n",
  322. ioc->name, __func__, retry_count);
  323. }
  324. wait_state_count = 0;
  325. ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
  326. while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
  327. if (wait_state_count++ == MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT) {
  328. printk(MPT2SAS_ERR_FMT
  329. "%s: failed due to ioc not operational\n",
  330. ioc->name, __func__);
  331. ioc->config_cmds.status = MPT2_CMD_NOT_USED;
  332. r = -EFAULT;
  333. goto free_mem;
  334. }
  335. ssleep(1);
  336. ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
  337. printk(MPT2SAS_INFO_FMT "%s: waiting for "
  338. "operational state(count=%d)\n", ioc->name,
  339. __func__, wait_state_count);
  340. }
  341. if (wait_state_count)
  342. printk(MPT2SAS_INFO_FMT "%s: ioc is operational\n",
  343. ioc->name, __func__);
  344. smid = mpt2sas_base_get_smid(ioc, ioc->config_cb_idx);
  345. if (!smid) {
  346. printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
  347. ioc->name, __func__);
  348. ioc->config_cmds.status = MPT2_CMD_NOT_USED;
  349. r = -EAGAIN;
  350. goto free_mem;
  351. }
  352. r = 0;
  353. memset(mpi_reply, 0, sizeof(Mpi2ConfigReply_t));
  354. ioc->config_cmds.status = MPT2_CMD_PENDING;
  355. config_request = mpt2sas_base_get_msg_frame(ioc, smid);
  356. ioc->config_cmds.smid = smid;
  357. memcpy(config_request, mpi_request, sizeof(Mpi2ConfigRequest_t));
  358. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  359. _config_display_some_debug(ioc, smid, "config_request", NULL);
  360. #endif
  361. init_completion(&ioc->config_cmds.done);
  362. mpt2sas_base_put_smid_default(ioc, smid);
  363. timeleft = wait_for_completion_timeout(&ioc->config_cmds.done,
  364. timeout*HZ);
  365. if (!(ioc->config_cmds.status & MPT2_CMD_COMPLETE)) {
  366. printk(MPT2SAS_ERR_FMT "%s: timeout\n",
  367. ioc->name, __func__);
  368. _debug_dump_mf(mpi_request,
  369. sizeof(Mpi2ConfigRequest_t)/4);
  370. retry_count++;
  371. if (ioc->config_cmds.smid == smid)
  372. mpt2sas_base_free_smid(ioc, smid);
  373. if ((ioc->shost_recovery) || (ioc->config_cmds.status &
  374. MPT2_CMD_RESET) || ioc->pci_error_recovery)
  375. goto retry_config;
  376. issue_host_reset = 1;
  377. r = -EFAULT;
  378. goto free_mem;
  379. }
  380. if (ioc->config_cmds.status & MPT2_CMD_REPLY_VALID)
  381. memcpy(mpi_reply, ioc->config_cmds.reply,
  382. sizeof(Mpi2ConfigReply_t));
  383. if (retry_count)
  384. printk(MPT2SAS_INFO_FMT "%s: retry (%d) completed!!\n",
  385. ioc->name, __func__, retry_count);
  386. if (config_page && mpi_request->Action ==
  387. MPI2_CONFIG_ACTION_PAGE_READ_CURRENT)
  388. memcpy(config_page, mem.page, min_t(u16, mem.sz,
  389. config_page_sz));
  390. free_mem:
  391. if (config_page)
  392. _config_free_config_dma_memory(ioc, &mem);
  393. out:
  394. ioc->config_cmds.status = MPT2_CMD_NOT_USED;
  395. mutex_unlock(&ioc->config_cmds.mutex);
  396. if (issue_host_reset)
  397. mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
  398. FORCE_BIG_HAMMER);
  399. return r;
  400. }
  401. /**
  402. * mpt2sas_config_get_manufacturing_pg0 - obtain manufacturing page 0
  403. * @ioc: per adapter object
  404. * @mpi_reply: reply mf payload returned from firmware
  405. * @config_page: contents of the config page
  406. * Context: sleep.
  407. *
  408. * Returns 0 for success, non-zero for failure.
  409. */
  410. int
  411. mpt2sas_config_get_manufacturing_pg0(struct MPT2SAS_ADAPTER *ioc,
  412. Mpi2ConfigReply_t *mpi_reply, Mpi2ManufacturingPage0_t *config_page)
  413. {
  414. Mpi2ConfigRequest_t mpi_request;
  415. int r;
  416. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  417. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  418. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  419. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_MANUFACTURING;
  420. mpi_request.Header.PageNumber = 0;
  421. mpi_request.Header.PageVersion = MPI2_MANUFACTURING0_PAGEVERSION;
  422. mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
  423. r = _config_request(ioc, &mpi_request, mpi_reply,
  424. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  425. if (r)
  426. goto out;
  427. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  428. r = _config_request(ioc, &mpi_request, mpi_reply,
  429. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  430. sizeof(*config_page));
  431. out:
  432. return r;
  433. }
  434. /**
  435. * mpt2sas_config_get_manufacturing_pg10 - obtain manufacturing page 10
  436. * @ioc: per adapter object
  437. * @mpi_reply: reply mf payload returned from firmware
  438. * @config_page: contents of the config page
  439. * Context: sleep.
  440. *
  441. * Returns 0 for success, non-zero for failure.
  442. */
  443. int
  444. mpt2sas_config_get_manufacturing_pg10(struct MPT2SAS_ADAPTER *ioc,
  445. Mpi2ConfigReply_t *mpi_reply, Mpi2ManufacturingPage10_t *config_page)
  446. {
  447. Mpi2ConfigRequest_t mpi_request;
  448. int r;
  449. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  450. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  451. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  452. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_MANUFACTURING;
  453. mpi_request.Header.PageNumber = 10;
  454. mpi_request.Header.PageVersion = MPI2_MANUFACTURING0_PAGEVERSION;
  455. mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
  456. r = _config_request(ioc, &mpi_request, mpi_reply,
  457. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  458. if (r)
  459. goto out;
  460. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  461. r = _config_request(ioc, &mpi_request, mpi_reply,
  462. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  463. sizeof(*config_page));
  464. out:
  465. return r;
  466. }
  467. /**
  468. * mpt2sas_config_get_bios_pg2 - obtain bios page 2
  469. * @ioc: per adapter object
  470. * @mpi_reply: reply mf payload returned from firmware
  471. * @config_page: contents of the config page
  472. * Context: sleep.
  473. *
  474. * Returns 0 for success, non-zero for failure.
  475. */
  476. int
  477. mpt2sas_config_get_bios_pg2(struct MPT2SAS_ADAPTER *ioc,
  478. Mpi2ConfigReply_t *mpi_reply, Mpi2BiosPage2_t *config_page)
  479. {
  480. Mpi2ConfigRequest_t mpi_request;
  481. int r;
  482. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  483. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  484. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  485. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_BIOS;
  486. mpi_request.Header.PageNumber = 2;
  487. mpi_request.Header.PageVersion = MPI2_BIOSPAGE2_PAGEVERSION;
  488. mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
  489. r = _config_request(ioc, &mpi_request, mpi_reply,
  490. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  491. if (r)
  492. goto out;
  493. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  494. r = _config_request(ioc, &mpi_request, mpi_reply,
  495. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  496. sizeof(*config_page));
  497. out:
  498. return r;
  499. }
  500. /**
  501. * mpt2sas_config_get_bios_pg3 - obtain bios page 3
  502. * @ioc: per adapter object
  503. * @mpi_reply: reply mf payload returned from firmware
  504. * @config_page: contents of the config page
  505. * Context: sleep.
  506. *
  507. * Returns 0 for success, non-zero for failure.
  508. */
  509. int
  510. mpt2sas_config_get_bios_pg3(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
  511. *mpi_reply, Mpi2BiosPage3_t *config_page)
  512. {
  513. Mpi2ConfigRequest_t mpi_request;
  514. int r;
  515. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  516. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  517. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  518. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_BIOS;
  519. mpi_request.Header.PageNumber = 3;
  520. mpi_request.Header.PageVersion = MPI2_BIOSPAGE3_PAGEVERSION;
  521. mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
  522. r = _config_request(ioc, &mpi_request, mpi_reply,
  523. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  524. if (r)
  525. goto out;
  526. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  527. r = _config_request(ioc, &mpi_request, mpi_reply,
  528. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  529. sizeof(*config_page));
  530. out:
  531. return r;
  532. }
  533. /**
  534. * mpt2sas_config_get_iounit_pg0 - obtain iounit page 0
  535. * @ioc: per adapter object
  536. * @mpi_reply: reply mf payload returned from firmware
  537. * @config_page: contents of the config page
  538. * Context: sleep.
  539. *
  540. * Returns 0 for success, non-zero for failure.
  541. */
  542. int
  543. mpt2sas_config_get_iounit_pg0(struct MPT2SAS_ADAPTER *ioc,
  544. Mpi2ConfigReply_t *mpi_reply, Mpi2IOUnitPage0_t *config_page)
  545. {
  546. Mpi2ConfigRequest_t mpi_request;
  547. int r;
  548. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  549. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  550. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  551. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_IO_UNIT;
  552. mpi_request.Header.PageNumber = 0;
  553. mpi_request.Header.PageVersion = MPI2_IOUNITPAGE0_PAGEVERSION;
  554. mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
  555. r = _config_request(ioc, &mpi_request, mpi_reply,
  556. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  557. if (r)
  558. goto out;
  559. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  560. r = _config_request(ioc, &mpi_request, mpi_reply,
  561. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  562. sizeof(*config_page));
  563. out:
  564. return r;
  565. }
  566. /**
  567. * mpt2sas_config_get_iounit_pg1 - obtain iounit page 1
  568. * @ioc: per adapter object
  569. * @mpi_reply: reply mf payload returned from firmware
  570. * @config_page: contents of the config page
  571. * Context: sleep.
  572. *
  573. * Returns 0 for success, non-zero for failure.
  574. */
  575. int
  576. mpt2sas_config_get_iounit_pg1(struct MPT2SAS_ADAPTER *ioc,
  577. Mpi2ConfigReply_t *mpi_reply, Mpi2IOUnitPage1_t *config_page)
  578. {
  579. Mpi2ConfigRequest_t mpi_request;
  580. int r;
  581. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  582. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  583. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  584. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_IO_UNIT;
  585. mpi_request.Header.PageNumber = 1;
  586. mpi_request.Header.PageVersion = MPI2_IOUNITPAGE1_PAGEVERSION;
  587. mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
  588. r = _config_request(ioc, &mpi_request, mpi_reply,
  589. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  590. if (r)
  591. goto out;
  592. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  593. r = _config_request(ioc, &mpi_request, mpi_reply,
  594. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  595. sizeof(*config_page));
  596. out:
  597. return r;
  598. }
  599. /**
  600. * mpt2sas_config_set_iounit_pg1 - set iounit page 1
  601. * @ioc: per adapter object
  602. * @mpi_reply: reply mf payload returned from firmware
  603. * @config_page: contents of the config page
  604. * Context: sleep.
  605. *
  606. * Returns 0 for success, non-zero for failure.
  607. */
  608. int
  609. mpt2sas_config_set_iounit_pg1(struct MPT2SAS_ADAPTER *ioc,
  610. Mpi2ConfigReply_t *mpi_reply, Mpi2IOUnitPage1_t *config_page)
  611. {
  612. Mpi2ConfigRequest_t mpi_request;
  613. int r;
  614. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  615. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  616. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  617. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_IO_UNIT;
  618. mpi_request.Header.PageNumber = 1;
  619. mpi_request.Header.PageVersion = MPI2_IOUNITPAGE1_PAGEVERSION;
  620. mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
  621. r = _config_request(ioc, &mpi_request, mpi_reply,
  622. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  623. if (r)
  624. goto out;
  625. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_WRITE_CURRENT;
  626. r = _config_request(ioc, &mpi_request, mpi_reply,
  627. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  628. sizeof(*config_page));
  629. out:
  630. return r;
  631. }
  632. /**
  633. * mpt2sas_config_get_ioc_pg8 - obtain ioc page 8
  634. * @ioc: per adapter object
  635. * @mpi_reply: reply mf payload returned from firmware
  636. * @config_page: contents of the config page
  637. * Context: sleep.
  638. *
  639. * Returns 0 for success, non-zero for failure.
  640. */
  641. int
  642. mpt2sas_config_get_ioc_pg8(struct MPT2SAS_ADAPTER *ioc,
  643. Mpi2ConfigReply_t *mpi_reply, Mpi2IOCPage8_t *config_page)
  644. {
  645. Mpi2ConfigRequest_t mpi_request;
  646. int r;
  647. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  648. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  649. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  650. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_IOC;
  651. mpi_request.Header.PageNumber = 8;
  652. mpi_request.Header.PageVersion = MPI2_IOCPAGE8_PAGEVERSION;
  653. mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
  654. r = _config_request(ioc, &mpi_request, mpi_reply,
  655. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  656. if (r)
  657. goto out;
  658. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  659. r = _config_request(ioc, &mpi_request, mpi_reply,
  660. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  661. sizeof(*config_page));
  662. out:
  663. return r;
  664. }
  665. /**
  666. * mpt2sas_config_get_sas_device_pg0 - obtain sas device page 0
  667. * @ioc: per adapter object
  668. * @mpi_reply: reply mf payload returned from firmware
  669. * @config_page: contents of the config page
  670. * @form: GET_NEXT_HANDLE or HANDLE
  671. * @handle: device handle
  672. * Context: sleep.
  673. *
  674. * Returns 0 for success, non-zero for failure.
  675. */
  676. int
  677. mpt2sas_config_get_sas_device_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
  678. *mpi_reply, Mpi2SasDevicePage0_t *config_page, u32 form, u32 handle)
  679. {
  680. Mpi2ConfigRequest_t mpi_request;
  681. int r;
  682. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  683. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  684. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  685. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
  686. mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_DEVICE;
  687. mpi_request.Header.PageVersion = MPI2_SASDEVICE0_PAGEVERSION;
  688. mpi_request.Header.PageNumber = 0;
  689. mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
  690. r = _config_request(ioc, &mpi_request, mpi_reply,
  691. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  692. if (r)
  693. goto out;
  694. mpi_request.PageAddress = cpu_to_le32(form | handle);
  695. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  696. r = _config_request(ioc, &mpi_request, mpi_reply,
  697. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  698. sizeof(*config_page));
  699. out:
  700. return r;
  701. }
  702. /**
  703. * mpt2sas_config_get_sas_device_pg1 - obtain sas device page 1
  704. * @ioc: per adapter object
  705. * @mpi_reply: reply mf payload returned from firmware
  706. * @config_page: contents of the config page
  707. * @form: GET_NEXT_HANDLE or HANDLE
  708. * @handle: device handle
  709. * Context: sleep.
  710. *
  711. * Returns 0 for success, non-zero for failure.
  712. */
  713. int
  714. mpt2sas_config_get_sas_device_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
  715. *mpi_reply, Mpi2SasDevicePage1_t *config_page, u32 form, u32 handle)
  716. {
  717. Mpi2ConfigRequest_t mpi_request;
  718. int r;
  719. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  720. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  721. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  722. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
  723. mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_DEVICE;
  724. mpi_request.Header.PageVersion = MPI2_SASDEVICE1_PAGEVERSION;
  725. mpi_request.Header.PageNumber = 1;
  726. mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
  727. r = _config_request(ioc, &mpi_request, mpi_reply,
  728. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  729. if (r)
  730. goto out;
  731. mpi_request.PageAddress = cpu_to_le32(form | handle);
  732. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  733. r = _config_request(ioc, &mpi_request, mpi_reply,
  734. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  735. sizeof(*config_page));
  736. out:
  737. return r;
  738. }
  739. /**
  740. * mpt2sas_config_get_number_hba_phys - obtain number of phys on the host
  741. * @ioc: per adapter object
  742. * @num_phys: pointer returned with the number of phys
  743. * Context: sleep.
  744. *
  745. * Returns 0 for success, non-zero for failure.
  746. */
  747. int
  748. mpt2sas_config_get_number_hba_phys(struct MPT2SAS_ADAPTER *ioc, u8 *num_phys)
  749. {
  750. Mpi2ConfigRequest_t mpi_request;
  751. int r;
  752. u16 ioc_status;
  753. Mpi2ConfigReply_t mpi_reply;
  754. Mpi2SasIOUnitPage0_t config_page;
  755. *num_phys = 0;
  756. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  757. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  758. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  759. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
  760. mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
  761. mpi_request.Header.PageNumber = 0;
  762. mpi_request.Header.PageVersion = MPI2_SASIOUNITPAGE0_PAGEVERSION;
  763. mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
  764. r = _config_request(ioc, &mpi_request, &mpi_reply,
  765. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  766. if (r)
  767. goto out;
  768. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  769. r = _config_request(ioc, &mpi_request, &mpi_reply,
  770. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, &config_page,
  771. sizeof(Mpi2SasIOUnitPage0_t));
  772. if (!r) {
  773. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  774. MPI2_IOCSTATUS_MASK;
  775. if (ioc_status == MPI2_IOCSTATUS_SUCCESS)
  776. *num_phys = config_page.NumPhys;
  777. }
  778. out:
  779. return r;
  780. }
  781. /**
  782. * mpt2sas_config_get_sas_iounit_pg0 - obtain sas iounit page 0
  783. * @ioc: per adapter object
  784. * @mpi_reply: reply mf payload returned from firmware
  785. * @config_page: contents of the config page
  786. * @sz: size of buffer passed in config_page
  787. * Context: sleep.
  788. *
  789. * Calling function should call config_get_number_hba_phys prior to
  790. * this function, so enough memory is allocated for config_page.
  791. *
  792. * Returns 0 for success, non-zero for failure.
  793. */
  794. int
  795. mpt2sas_config_get_sas_iounit_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
  796. *mpi_reply, Mpi2SasIOUnitPage0_t *config_page, u16 sz)
  797. {
  798. Mpi2ConfigRequest_t mpi_request;
  799. int r;
  800. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  801. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  802. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  803. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
  804. mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
  805. mpi_request.Header.PageNumber = 0;
  806. mpi_request.Header.PageVersion = MPI2_SASIOUNITPAGE0_PAGEVERSION;
  807. mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
  808. r = _config_request(ioc, &mpi_request, mpi_reply,
  809. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  810. if (r)
  811. goto out;
  812. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  813. r = _config_request(ioc, &mpi_request, mpi_reply,
  814. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sz);
  815. out:
  816. return r;
  817. }
  818. /**
  819. * mpt2sas_config_get_sas_iounit_pg1 - obtain sas iounit page 1
  820. * @ioc: per adapter object
  821. * @mpi_reply: reply mf payload returned from firmware
  822. * @config_page: contents of the config page
  823. * @sz: size of buffer passed in config_page
  824. * Context: sleep.
  825. *
  826. * Calling function should call config_get_number_hba_phys prior to
  827. * this function, so enough memory is allocated for config_page.
  828. *
  829. * Returns 0 for success, non-zero for failure.
  830. */
  831. int
  832. mpt2sas_config_get_sas_iounit_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
  833. *mpi_reply, Mpi2SasIOUnitPage1_t *config_page, u16 sz)
  834. {
  835. Mpi2ConfigRequest_t mpi_request;
  836. int r;
  837. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  838. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  839. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  840. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
  841. mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
  842. mpi_request.Header.PageNumber = 1;
  843. mpi_request.Header.PageVersion = MPI2_SASIOUNITPAGE1_PAGEVERSION;
  844. mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
  845. r = _config_request(ioc, &mpi_request, mpi_reply,
  846. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  847. if (r)
  848. goto out;
  849. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  850. r = _config_request(ioc, &mpi_request, mpi_reply,
  851. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sz);
  852. out:
  853. return r;
  854. }
  855. /**
  856. * mpt2sas_config_set_sas_iounit_pg1 - send sas iounit page 1
  857. * @ioc: per adapter object
  858. * @mpi_reply: reply mf payload returned from firmware
  859. * @config_page: contents of the config page
  860. * @sz: size of buffer passed in config_page
  861. * Context: sleep.
  862. *
  863. * Calling function should call config_get_number_hba_phys prior to
  864. * this function, so enough memory is allocated for config_page.
  865. *
  866. * Returns 0 for success, non-zero for failure.
  867. */
  868. int
  869. mpt2sas_config_set_sas_iounit_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
  870. *mpi_reply, Mpi2SasIOUnitPage1_t *config_page, u16 sz)
  871. {
  872. Mpi2ConfigRequest_t mpi_request;
  873. int r;
  874. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  875. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  876. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  877. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
  878. mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
  879. mpi_request.Header.PageNumber = 1;
  880. mpi_request.Header.PageVersion = MPI2_SASIOUNITPAGE1_PAGEVERSION;
  881. mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
  882. r = _config_request(ioc, &mpi_request, mpi_reply,
  883. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  884. if (r)
  885. goto out;
  886. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_WRITE_CURRENT;
  887. _config_request(ioc, &mpi_request, mpi_reply,
  888. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sz);
  889. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_WRITE_NVRAM;
  890. r = _config_request(ioc, &mpi_request, mpi_reply,
  891. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sz);
  892. out:
  893. return r;
  894. }
  895. /**
  896. * mpt2sas_config_get_expander_pg0 - obtain expander page 0
  897. * @ioc: per adapter object
  898. * @mpi_reply: reply mf payload returned from firmware
  899. * @config_page: contents of the config page
  900. * @form: GET_NEXT_HANDLE or HANDLE
  901. * @handle: expander handle
  902. * Context: sleep.
  903. *
  904. * Returns 0 for success, non-zero for failure.
  905. */
  906. int
  907. mpt2sas_config_get_expander_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
  908. *mpi_reply, Mpi2ExpanderPage0_t *config_page, u32 form, u32 handle)
  909. {
  910. Mpi2ConfigRequest_t mpi_request;
  911. int r;
  912. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  913. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  914. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  915. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
  916. mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_EXPANDER;
  917. mpi_request.Header.PageNumber = 0;
  918. mpi_request.Header.PageVersion = MPI2_SASEXPANDER0_PAGEVERSION;
  919. mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
  920. r = _config_request(ioc, &mpi_request, mpi_reply,
  921. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  922. if (r)
  923. goto out;
  924. mpi_request.PageAddress = cpu_to_le32(form | handle);
  925. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  926. r = _config_request(ioc, &mpi_request, mpi_reply,
  927. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  928. sizeof(*config_page));
  929. out:
  930. return r;
  931. }
  932. /**
  933. * mpt2sas_config_get_expander_pg1 - obtain expander page 1
  934. * @ioc: per adapter object
  935. * @mpi_reply: reply mf payload returned from firmware
  936. * @config_page: contents of the config page
  937. * @phy_number: phy number
  938. * @handle: expander handle
  939. * Context: sleep.
  940. *
  941. * Returns 0 for success, non-zero for failure.
  942. */
  943. int
  944. mpt2sas_config_get_expander_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
  945. *mpi_reply, Mpi2ExpanderPage1_t *config_page, u32 phy_number,
  946. u16 handle)
  947. {
  948. Mpi2ConfigRequest_t mpi_request;
  949. int r;
  950. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  951. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  952. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  953. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
  954. mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_EXPANDER;
  955. mpi_request.Header.PageNumber = 1;
  956. mpi_request.Header.PageVersion = MPI2_SASEXPANDER1_PAGEVERSION;
  957. mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
  958. r = _config_request(ioc, &mpi_request, mpi_reply,
  959. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  960. if (r)
  961. goto out;
  962. mpi_request.PageAddress =
  963. cpu_to_le32(MPI2_SAS_EXPAND_PGAD_FORM_HNDL_PHY_NUM |
  964. (phy_number << MPI2_SAS_EXPAND_PGAD_PHYNUM_SHIFT) | handle);
  965. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  966. r = _config_request(ioc, &mpi_request, mpi_reply,
  967. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  968. sizeof(*config_page));
  969. out:
  970. return r;
  971. }
  972. /**
  973. * mpt2sas_config_get_enclosure_pg0 - obtain enclosure page 0
  974. * @ioc: per adapter object
  975. * @mpi_reply: reply mf payload returned from firmware
  976. * @config_page: contents of the config page
  977. * @form: GET_NEXT_HANDLE or HANDLE
  978. * @handle: expander handle
  979. * Context: sleep.
  980. *
  981. * Returns 0 for success, non-zero for failure.
  982. */
  983. int
  984. mpt2sas_config_get_enclosure_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
  985. *mpi_reply, Mpi2SasEnclosurePage0_t *config_page, u32 form, u32 handle)
  986. {
  987. Mpi2ConfigRequest_t mpi_request;
  988. int r;
  989. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  990. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  991. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  992. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
  993. mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_ENCLOSURE;
  994. mpi_request.Header.PageNumber = 0;
  995. mpi_request.Header.PageVersion = MPI2_SASENCLOSURE0_PAGEVERSION;
  996. mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
  997. r = _config_request(ioc, &mpi_request, mpi_reply,
  998. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  999. if (r)
  1000. goto out;
  1001. mpi_request.PageAddress = cpu_to_le32(form | handle);
  1002. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  1003. r = _config_request(ioc, &mpi_request, mpi_reply,
  1004. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  1005. sizeof(*config_page));
  1006. out:
  1007. return r;
  1008. }
  1009. /**
  1010. * mpt2sas_config_get_phy_pg0 - obtain phy page 0
  1011. * @ioc: per adapter object
  1012. * @mpi_reply: reply mf payload returned from firmware
  1013. * @config_page: contents of the config page
  1014. * @phy_number: phy number
  1015. * Context: sleep.
  1016. *
  1017. * Returns 0 for success, non-zero for failure.
  1018. */
  1019. int
  1020. mpt2sas_config_get_phy_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
  1021. *mpi_reply, Mpi2SasPhyPage0_t *config_page, u32 phy_number)
  1022. {
  1023. Mpi2ConfigRequest_t mpi_request;
  1024. int r;
  1025. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  1026. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  1027. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  1028. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
  1029. mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_PHY;
  1030. mpi_request.Header.PageNumber = 0;
  1031. mpi_request.Header.PageVersion = MPI2_SASPHY0_PAGEVERSION;
  1032. mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
  1033. r = _config_request(ioc, &mpi_request, mpi_reply,
  1034. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  1035. if (r)
  1036. goto out;
  1037. mpi_request.PageAddress =
  1038. cpu_to_le32(MPI2_SAS_PHY_PGAD_FORM_PHY_NUMBER | phy_number);
  1039. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  1040. r = _config_request(ioc, &mpi_request, mpi_reply,
  1041. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  1042. sizeof(*config_page));
  1043. out:
  1044. return r;
  1045. }
  1046. /**
  1047. * mpt2sas_config_get_phy_pg1 - obtain phy page 1
  1048. * @ioc: per adapter object
  1049. * @mpi_reply: reply mf payload returned from firmware
  1050. * @config_page: contents of the config page
  1051. * @phy_number: phy number
  1052. * Context: sleep.
  1053. *
  1054. * Returns 0 for success, non-zero for failure.
  1055. */
  1056. int
  1057. mpt2sas_config_get_phy_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
  1058. *mpi_reply, Mpi2SasPhyPage1_t *config_page, u32 phy_number)
  1059. {
  1060. Mpi2ConfigRequest_t mpi_request;
  1061. int r;
  1062. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  1063. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  1064. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  1065. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
  1066. mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_PHY;
  1067. mpi_request.Header.PageNumber = 1;
  1068. mpi_request.Header.PageVersion = MPI2_SASPHY1_PAGEVERSION;
  1069. mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
  1070. r = _config_request(ioc, &mpi_request, mpi_reply,
  1071. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  1072. if (r)
  1073. goto out;
  1074. mpi_request.PageAddress =
  1075. cpu_to_le32(MPI2_SAS_PHY_PGAD_FORM_PHY_NUMBER | phy_number);
  1076. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  1077. r = _config_request(ioc, &mpi_request, mpi_reply,
  1078. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  1079. sizeof(*config_page));
  1080. out:
  1081. return r;
  1082. }
  1083. /**
  1084. * mpt2sas_config_get_raid_volume_pg1 - obtain raid volume page 1
  1085. * @ioc: per adapter object
  1086. * @mpi_reply: reply mf payload returned from firmware
  1087. * @config_page: contents of the config page
  1088. * @form: GET_NEXT_HANDLE or HANDLE
  1089. * @handle: volume handle
  1090. * Context: sleep.
  1091. *
  1092. * Returns 0 for success, non-zero for failure.
  1093. */
  1094. int
  1095. mpt2sas_config_get_raid_volume_pg1(struct MPT2SAS_ADAPTER *ioc,
  1096. Mpi2ConfigReply_t *mpi_reply, Mpi2RaidVolPage1_t *config_page, u32 form,
  1097. u32 handle)
  1098. {
  1099. Mpi2ConfigRequest_t mpi_request;
  1100. int r;
  1101. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  1102. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  1103. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  1104. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_RAID_VOLUME;
  1105. mpi_request.Header.PageNumber = 1;
  1106. mpi_request.Header.PageVersion = MPI2_RAIDVOLPAGE1_PAGEVERSION;
  1107. mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
  1108. r = _config_request(ioc, &mpi_request, mpi_reply,
  1109. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  1110. if (r)
  1111. goto out;
  1112. mpi_request.PageAddress = cpu_to_le32(form | handle);
  1113. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  1114. r = _config_request(ioc, &mpi_request, mpi_reply,
  1115. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  1116. sizeof(*config_page));
  1117. out:
  1118. return r;
  1119. }
  1120. /**
  1121. * mpt2sas_config_get_number_pds - obtain number of phys disk assigned to volume
  1122. * @ioc: per adapter object
  1123. * @handle: volume handle
  1124. * @num_pds: returns pds count
  1125. * Context: sleep.
  1126. *
  1127. * Returns 0 for success, non-zero for failure.
  1128. */
  1129. int
  1130. mpt2sas_config_get_number_pds(struct MPT2SAS_ADAPTER *ioc, u16 handle,
  1131. u8 *num_pds)
  1132. {
  1133. Mpi2ConfigRequest_t mpi_request;
  1134. Mpi2RaidVolPage0_t config_page;
  1135. Mpi2ConfigReply_t mpi_reply;
  1136. int r;
  1137. u16 ioc_status;
  1138. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  1139. *num_pds = 0;
  1140. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  1141. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  1142. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_RAID_VOLUME;
  1143. mpi_request.Header.PageNumber = 0;
  1144. mpi_request.Header.PageVersion = MPI2_RAIDVOLPAGE0_PAGEVERSION;
  1145. mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
  1146. r = _config_request(ioc, &mpi_request, &mpi_reply,
  1147. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  1148. if (r)
  1149. goto out;
  1150. mpi_request.PageAddress =
  1151. cpu_to_le32(MPI2_RAID_VOLUME_PGAD_FORM_HANDLE | handle);
  1152. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  1153. r = _config_request(ioc, &mpi_request, &mpi_reply,
  1154. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, &config_page,
  1155. sizeof(Mpi2RaidVolPage0_t));
  1156. if (!r) {
  1157. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  1158. MPI2_IOCSTATUS_MASK;
  1159. if (ioc_status == MPI2_IOCSTATUS_SUCCESS)
  1160. *num_pds = config_page.NumPhysDisks;
  1161. }
  1162. out:
  1163. return r;
  1164. }
  1165. /**
  1166. * mpt2sas_config_get_raid_volume_pg0 - obtain raid volume page 0
  1167. * @ioc: per adapter object
  1168. * @mpi_reply: reply mf payload returned from firmware
  1169. * @config_page: contents of the config page
  1170. * @form: GET_NEXT_HANDLE or HANDLE
  1171. * @handle: volume handle
  1172. * @sz: size of buffer passed in config_page
  1173. * Context: sleep.
  1174. *
  1175. * Returns 0 for success, non-zero for failure.
  1176. */
  1177. int
  1178. mpt2sas_config_get_raid_volume_pg0(struct MPT2SAS_ADAPTER *ioc,
  1179. Mpi2ConfigReply_t *mpi_reply, Mpi2RaidVolPage0_t *config_page, u32 form,
  1180. u32 handle, u16 sz)
  1181. {
  1182. Mpi2ConfigRequest_t mpi_request;
  1183. int r;
  1184. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  1185. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  1186. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  1187. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_RAID_VOLUME;
  1188. mpi_request.Header.PageNumber = 0;
  1189. mpi_request.Header.PageVersion = MPI2_RAIDVOLPAGE0_PAGEVERSION;
  1190. mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
  1191. r = _config_request(ioc, &mpi_request, mpi_reply,
  1192. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  1193. if (r)
  1194. goto out;
  1195. mpi_request.PageAddress = cpu_to_le32(form | handle);
  1196. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  1197. r = _config_request(ioc, &mpi_request, mpi_reply,
  1198. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sz);
  1199. out:
  1200. return r;
  1201. }
  1202. /**
  1203. * mpt2sas_config_get_phys_disk_pg0 - obtain phys disk page 0
  1204. * @ioc: per adapter object
  1205. * @mpi_reply: reply mf payload returned from firmware
  1206. * @config_page: contents of the config page
  1207. * @form: GET_NEXT_PHYSDISKNUM, PHYSDISKNUM, DEVHANDLE
  1208. * @form_specific: specific to the form
  1209. * Context: sleep.
  1210. *
  1211. * Returns 0 for success, non-zero for failure.
  1212. */
  1213. int
  1214. mpt2sas_config_get_phys_disk_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
  1215. *mpi_reply, Mpi2RaidPhysDiskPage0_t *config_page, u32 form,
  1216. u32 form_specific)
  1217. {
  1218. Mpi2ConfigRequest_t mpi_request;
  1219. int r;
  1220. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  1221. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  1222. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  1223. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_RAID_PHYSDISK;
  1224. mpi_request.Header.PageNumber = 0;
  1225. mpi_request.Header.PageVersion = MPI2_RAIDPHYSDISKPAGE0_PAGEVERSION;
  1226. mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
  1227. r = _config_request(ioc, &mpi_request, mpi_reply,
  1228. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  1229. if (r)
  1230. goto out;
  1231. mpi_request.PageAddress = cpu_to_le32(form | form_specific);
  1232. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  1233. r = _config_request(ioc, &mpi_request, mpi_reply,
  1234. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  1235. sizeof(*config_page));
  1236. out:
  1237. return r;
  1238. }
  1239. /**
  1240. * mpt2sas_config_get_volume_handle - returns volume handle for give hidden raid components
  1241. * @ioc: per adapter object
  1242. * @pd_handle: phys disk handle
  1243. * @volume_handle: volume handle
  1244. * Context: sleep.
  1245. *
  1246. * Returns 0 for success, non-zero for failure.
  1247. */
  1248. int
  1249. mpt2sas_config_get_volume_handle(struct MPT2SAS_ADAPTER *ioc, u16 pd_handle,
  1250. u16 *volume_handle)
  1251. {
  1252. Mpi2RaidConfigurationPage0_t *config_page = NULL;
  1253. Mpi2ConfigRequest_t mpi_request;
  1254. Mpi2ConfigReply_t mpi_reply;
  1255. int r, i, config_page_sz;
  1256. u16 ioc_status;
  1257. int config_num;
  1258. u16 element_type;
  1259. u16 phys_disk_dev_handle;
  1260. *volume_handle = 0;
  1261. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  1262. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  1263. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  1264. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
  1265. mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_RAID_CONFIG;
  1266. mpi_request.Header.PageVersion = MPI2_RAIDCONFIG0_PAGEVERSION;
  1267. mpi_request.Header.PageNumber = 0;
  1268. mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
  1269. r = _config_request(ioc, &mpi_request, &mpi_reply,
  1270. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  1271. if (r)
  1272. goto out;
  1273. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  1274. config_page_sz = (le16_to_cpu(mpi_reply.ExtPageLength) * 4);
  1275. config_page = kmalloc(config_page_sz, GFP_KERNEL);
  1276. if (!config_page) {
  1277. r = -1;
  1278. goto out;
  1279. }
  1280. config_num = 0xff;
  1281. while (1) {
  1282. mpi_request.PageAddress = cpu_to_le32(config_num +
  1283. MPI2_RAID_PGAD_FORM_GET_NEXT_CONFIGNUM);
  1284. r = _config_request(ioc, &mpi_request, &mpi_reply,
  1285. MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  1286. config_page_sz);
  1287. if (r)
  1288. goto out;
  1289. r = -1;
  1290. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  1291. MPI2_IOCSTATUS_MASK;
  1292. if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
  1293. goto out;
  1294. for (i = 0; i < config_page->NumElements; i++) {
  1295. element_type = le16_to_cpu(config_page->
  1296. ConfigElement[i].ElementFlags) &
  1297. MPI2_RAIDCONFIG0_EFLAGS_MASK_ELEMENT_TYPE;
  1298. if (element_type ==
  1299. MPI2_RAIDCONFIG0_EFLAGS_VOL_PHYS_DISK_ELEMENT ||
  1300. element_type ==
  1301. MPI2_RAIDCONFIG0_EFLAGS_OCE_ELEMENT) {
  1302. phys_disk_dev_handle =
  1303. le16_to_cpu(config_page->ConfigElement[i].
  1304. PhysDiskDevHandle);
  1305. if (phys_disk_dev_handle == pd_handle) {
  1306. *volume_handle =
  1307. le16_to_cpu(config_page->
  1308. ConfigElement[i].VolDevHandle);
  1309. r = 0;
  1310. goto out;
  1311. }
  1312. } else if (element_type ==
  1313. MPI2_RAIDCONFIG0_EFLAGS_HOT_SPARE_ELEMENT) {
  1314. *volume_handle = 0;
  1315. r = 0;
  1316. goto out;
  1317. }
  1318. }
  1319. config_num = config_page->ConfigNum;
  1320. }
  1321. out:
  1322. kfree(config_page);
  1323. return r;
  1324. }
  1325. /**
  1326. * mpt2sas_config_get_volume_wwid - returns wwid given the volume handle
  1327. * @ioc: per adapter object
  1328. * @volume_handle: volume handle
  1329. * @wwid: volume wwid
  1330. * Context: sleep.
  1331. *
  1332. * Returns 0 for success, non-zero for failure.
  1333. */
  1334. int
  1335. mpt2sas_config_get_volume_wwid(struct MPT2SAS_ADAPTER *ioc, u16 volume_handle,
  1336. u64 *wwid)
  1337. {
  1338. Mpi2ConfigReply_t mpi_reply;
  1339. Mpi2RaidVolPage1_t raid_vol_pg1;
  1340. *wwid = 0;
  1341. if (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
  1342. &raid_vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE,
  1343. volume_handle))) {
  1344. *wwid = le64_to_cpu(raid_vol_pg1.WWID);
  1345. return 0;
  1346. } else
  1347. return -1;
  1348. }