mpt3sas_config.c 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809
  1. /*
  2. * This module provides common API for accessing firmware configuration pages
  3. *
  4. * This code is based on drivers/scsi/mpt3sas/mpt3sas_base.c
  5. * Copyright (C) 2012-2014 LSI Corporation
  6. * Copyright (C) 2013-2014 Avago Technologies
  7. * (mailto: MPT-FusionLinux.pdl@avagotech.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/module.h>
  43. #include <linux/kernel.h>
  44. #include <linux/init.h>
  45. #include <linux/errno.h>
  46. #include <linux/blkdev.h>
  47. #include <linux/sched.h>
  48. #include <linux/workqueue.h>
  49. #include <linux/delay.h>
  50. #include <linux/pci.h>
  51. #include "mpt3sas_base.h"
  52. /* local definitions */
  53. /* Timeout for config page request (in seconds) */
  54. #define MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT 15
  55. /* Common sgl flags for READING a config page. */
  56. #define MPT3_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 MPT3_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. /**
  77. * _config_display_some_debug - debug routine
  78. * @ioc: per adapter object
  79. * @smid: system request message index
  80. * @calling_function_name: string pass from calling function
  81. * @mpi_reply: reply message frame
  82. * Context: none.
  83. *
  84. * Function for displaying debug info helpful when debugging issues
  85. * in this module.
  86. */
  87. static void
  88. _config_display_some_debug(struct MPT3SAS_ADAPTER *ioc, u16 smid,
  89. char *calling_function_name, MPI2DefaultReply_t *mpi_reply)
  90. {
  91. Mpi2ConfigRequest_t *mpi_request;
  92. char *desc = NULL;
  93. if (!(ioc->logging_level & MPT_DEBUG_CONFIG))
  94. return;
  95. mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
  96. switch (mpi_request->Header.PageType & MPI2_CONFIG_PAGETYPE_MASK) {
  97. case MPI2_CONFIG_PAGETYPE_IO_UNIT:
  98. desc = "io_unit";
  99. break;
  100. case MPI2_CONFIG_PAGETYPE_IOC:
  101. desc = "ioc";
  102. break;
  103. case MPI2_CONFIG_PAGETYPE_BIOS:
  104. desc = "bios";
  105. break;
  106. case MPI2_CONFIG_PAGETYPE_RAID_VOLUME:
  107. desc = "raid_volume";
  108. break;
  109. case MPI2_CONFIG_PAGETYPE_MANUFACTURING:
  110. desc = "manufaucturing";
  111. break;
  112. case MPI2_CONFIG_PAGETYPE_RAID_PHYSDISK:
  113. desc = "physdisk";
  114. break;
  115. case MPI2_CONFIG_PAGETYPE_EXTENDED:
  116. switch (mpi_request->ExtPageType) {
  117. case MPI2_CONFIG_EXTPAGETYPE_SAS_IO_UNIT:
  118. desc = "sas_io_unit";
  119. break;
  120. case MPI2_CONFIG_EXTPAGETYPE_SAS_EXPANDER:
  121. desc = "sas_expander";
  122. break;
  123. case MPI2_CONFIG_EXTPAGETYPE_SAS_DEVICE:
  124. desc = "sas_device";
  125. break;
  126. case MPI2_CONFIG_EXTPAGETYPE_SAS_PHY:
  127. desc = "sas_phy";
  128. break;
  129. case MPI2_CONFIG_EXTPAGETYPE_LOG:
  130. desc = "log";
  131. break;
  132. case MPI2_CONFIG_EXTPAGETYPE_ENCLOSURE:
  133. desc = "enclosure";
  134. break;
  135. case MPI2_CONFIG_EXTPAGETYPE_RAID_CONFIG:
  136. desc = "raid_config";
  137. break;
  138. case MPI2_CONFIG_EXTPAGETYPE_DRIVER_MAPPING:
  139. desc = "driver_mapping";
  140. break;
  141. case MPI2_CONFIG_EXTPAGETYPE_SAS_PORT:
  142. desc = "sas_port";
  143. break;
  144. case MPI2_CONFIG_EXTPAGETYPE_EXT_MANUFACTURING:
  145. desc = "ext_manufacturing";
  146. break;
  147. case MPI2_CONFIG_EXTPAGETYPE_PCIE_IO_UNIT:
  148. desc = "pcie_io_unit";
  149. break;
  150. case MPI2_CONFIG_EXTPAGETYPE_PCIE_SWITCH:
  151. desc = "pcie_switch";
  152. break;
  153. case MPI2_CONFIG_EXTPAGETYPE_PCIE_DEVICE:
  154. desc = "pcie_device";
  155. break;
  156. case MPI2_CONFIG_EXTPAGETYPE_PCIE_LINK:
  157. desc = "pcie_link";
  158. break;
  159. }
  160. break;
  161. }
  162. if (!desc)
  163. return;
  164. pr_info(MPT3SAS_FMT
  165. "%s: %s(%d), action(%d), form(0x%08x), smid(%d)\n",
  166. ioc->name, calling_function_name, desc,
  167. mpi_request->Header.PageNumber, mpi_request->Action,
  168. le32_to_cpu(mpi_request->PageAddress), smid);
  169. if (!mpi_reply)
  170. return;
  171. if (mpi_reply->IOCStatus || mpi_reply->IOCLogInfo)
  172. pr_info(MPT3SAS_FMT
  173. "\tiocstatus(0x%04x), loginfo(0x%08x)\n",
  174. ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
  175. le32_to_cpu(mpi_reply->IOCLogInfo));
  176. }
  177. /**
  178. * _config_alloc_config_dma_memory - obtain physical memory
  179. * @ioc: per adapter object
  180. * @mem: struct config_request
  181. *
  182. * A wrapper for obtaining dma-able memory for config page request.
  183. *
  184. * Return: 0 for success, non-zero for failure.
  185. */
  186. static int
  187. _config_alloc_config_dma_memory(struct MPT3SAS_ADAPTER *ioc,
  188. struct config_request *mem)
  189. {
  190. int r = 0;
  191. if (mem->sz > ioc->config_page_sz) {
  192. mem->page = dma_alloc_coherent(&ioc->pdev->dev, mem->sz,
  193. &mem->page_dma, GFP_KERNEL);
  194. if (!mem->page) {
  195. pr_err(MPT3SAS_FMT
  196. "%s: dma_alloc_coherent failed asking for (%d) bytes!!\n",
  197. ioc->name, __func__, mem->sz);
  198. r = -ENOMEM;
  199. }
  200. } else { /* use tmp buffer if less than 512 bytes */
  201. mem->page = ioc->config_page;
  202. mem->page_dma = ioc->config_page_dma;
  203. }
  204. ioc->config_vaddr = mem->page;
  205. return r;
  206. }
  207. /**
  208. * _config_free_config_dma_memory - wrapper to free the memory
  209. * @ioc: per adapter object
  210. * @mem: struct config_request
  211. *
  212. * A wrapper to free dma-able memory when using _config_alloc_config_dma_memory.
  213. *
  214. * Return: 0 for success, non-zero for failure.
  215. */
  216. static void
  217. _config_free_config_dma_memory(struct MPT3SAS_ADAPTER *ioc,
  218. struct config_request *mem)
  219. {
  220. if (mem->sz > ioc->config_page_sz)
  221. dma_free_coherent(&ioc->pdev->dev, mem->sz, mem->page,
  222. mem->page_dma);
  223. }
  224. /**
  225. * mpt3sas_config_done - config page completion routine
  226. * @ioc: per adapter object
  227. * @smid: system request message index
  228. * @msix_index: MSIX table index supplied by the OS
  229. * @reply: reply message frame(lower 32bit addr)
  230. * Context: none.
  231. *
  232. * The callback handler when using _config_request.
  233. *
  234. * Return: 1 meaning mf should be freed from _base_interrupt
  235. * 0 means the mf is freed from this function.
  236. */
  237. u8
  238. mpt3sas_config_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
  239. u32 reply)
  240. {
  241. MPI2DefaultReply_t *mpi_reply;
  242. if (ioc->config_cmds.status == MPT3_CMD_NOT_USED)
  243. return 1;
  244. if (ioc->config_cmds.smid != smid)
  245. return 1;
  246. ioc->config_cmds.status |= MPT3_CMD_COMPLETE;
  247. mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
  248. if (mpi_reply) {
  249. ioc->config_cmds.status |= MPT3_CMD_REPLY_VALID;
  250. memcpy(ioc->config_cmds.reply, mpi_reply,
  251. mpi_reply->MsgLength*4);
  252. }
  253. ioc->config_cmds.status &= ~MPT3_CMD_PENDING;
  254. _config_display_some_debug(ioc, smid, "config_done", mpi_reply);
  255. ioc->config_cmds.smid = USHRT_MAX;
  256. complete(&ioc->config_cmds.done);
  257. return 1;
  258. }
  259. /**
  260. * _config_request - main routine for sending config page requests
  261. * @ioc: per adapter object
  262. * @mpi_request: request message frame
  263. * @mpi_reply: reply mf payload returned from firmware
  264. * @timeout: timeout in seconds
  265. * @config_page: contents of the config page
  266. * @config_page_sz: size of config page
  267. * Context: sleep
  268. *
  269. * A generic API for config page requests to firmware.
  270. *
  271. * The ioc->config_cmds.status flag should be MPT3_CMD_NOT_USED before calling
  272. * this API.
  273. *
  274. * The callback index is set inside `ioc->config_cb_idx.
  275. *
  276. * Return: 0 for success, non-zero for failure.
  277. */
  278. static int
  279. _config_request(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigRequest_t
  280. *mpi_request, Mpi2ConfigReply_t *mpi_reply, int timeout,
  281. void *config_page, u16 config_page_sz)
  282. {
  283. u16 smid;
  284. u32 ioc_state;
  285. Mpi2ConfigRequest_t *config_request;
  286. int r;
  287. u8 retry_count, issue_host_reset = 0;
  288. u16 wait_state_count;
  289. struct config_request mem;
  290. u32 ioc_status = UINT_MAX;
  291. mutex_lock(&ioc->config_cmds.mutex);
  292. if (ioc->config_cmds.status != MPT3_CMD_NOT_USED) {
  293. pr_err(MPT3SAS_FMT "%s: config_cmd in use\n",
  294. ioc->name, __func__);
  295. mutex_unlock(&ioc->config_cmds.mutex);
  296. return -EAGAIN;
  297. }
  298. retry_count = 0;
  299. memset(&mem, 0, sizeof(struct config_request));
  300. mpi_request->VF_ID = 0; /* TODO */
  301. mpi_request->VP_ID = 0;
  302. if (config_page) {
  303. mpi_request->Header.PageVersion = mpi_reply->Header.PageVersion;
  304. mpi_request->Header.PageNumber = mpi_reply->Header.PageNumber;
  305. mpi_request->Header.PageType = mpi_reply->Header.PageType;
  306. mpi_request->Header.PageLength = mpi_reply->Header.PageLength;
  307. mpi_request->ExtPageLength = mpi_reply->ExtPageLength;
  308. mpi_request->ExtPageType = mpi_reply->ExtPageType;
  309. if (mpi_request->Header.PageLength)
  310. mem.sz = mpi_request->Header.PageLength * 4;
  311. else
  312. mem.sz = le16_to_cpu(mpi_reply->ExtPageLength) * 4;
  313. r = _config_alloc_config_dma_memory(ioc, &mem);
  314. if (r != 0)
  315. goto out;
  316. if (mpi_request->Action ==
  317. MPI2_CONFIG_ACTION_PAGE_WRITE_CURRENT ||
  318. mpi_request->Action ==
  319. MPI2_CONFIG_ACTION_PAGE_WRITE_NVRAM) {
  320. ioc->base_add_sg_single(&mpi_request->PageBufferSGE,
  321. MPT3_CONFIG_COMMON_WRITE_SGLFLAGS | mem.sz,
  322. mem.page_dma);
  323. memcpy(mem.page, config_page, min_t(u16, mem.sz,
  324. config_page_sz));
  325. } else {
  326. memset(config_page, 0, config_page_sz);
  327. ioc->base_add_sg_single(&mpi_request->PageBufferSGE,
  328. MPT3_CONFIG_COMMON_SGLFLAGS | mem.sz, mem.page_dma);
  329. memset(mem.page, 0, min_t(u16, mem.sz, config_page_sz));
  330. }
  331. }
  332. retry_config:
  333. if (retry_count) {
  334. if (retry_count > 2) { /* attempt only 2 retries */
  335. r = -EFAULT;
  336. goto free_mem;
  337. }
  338. pr_info(MPT3SAS_FMT "%s: attempting retry (%d)\n",
  339. ioc->name, __func__, retry_count);
  340. }
  341. wait_state_count = 0;
  342. ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
  343. while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
  344. if (wait_state_count++ == MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT) {
  345. pr_err(MPT3SAS_FMT
  346. "%s: failed due to ioc not operational\n",
  347. ioc->name, __func__);
  348. ioc->config_cmds.status = MPT3_CMD_NOT_USED;
  349. r = -EFAULT;
  350. goto free_mem;
  351. }
  352. ssleep(1);
  353. ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
  354. pr_info(MPT3SAS_FMT
  355. "%s: waiting for operational state(count=%d)\n",
  356. ioc->name, __func__, wait_state_count);
  357. }
  358. if (wait_state_count)
  359. pr_info(MPT3SAS_FMT "%s: ioc is operational\n",
  360. ioc->name, __func__);
  361. smid = mpt3sas_base_get_smid(ioc, ioc->config_cb_idx);
  362. if (!smid) {
  363. pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
  364. ioc->name, __func__);
  365. ioc->config_cmds.status = MPT3_CMD_NOT_USED;
  366. r = -EAGAIN;
  367. goto free_mem;
  368. }
  369. r = 0;
  370. memset(mpi_reply, 0, sizeof(Mpi2ConfigReply_t));
  371. ioc->config_cmds.status = MPT3_CMD_PENDING;
  372. config_request = mpt3sas_base_get_msg_frame(ioc, smid);
  373. ioc->config_cmds.smid = smid;
  374. memcpy(config_request, mpi_request, sizeof(Mpi2ConfigRequest_t));
  375. _config_display_some_debug(ioc, smid, "config_request", NULL);
  376. init_completion(&ioc->config_cmds.done);
  377. mpt3sas_base_put_smid_default(ioc, smid);
  378. wait_for_completion_timeout(&ioc->config_cmds.done, timeout*HZ);
  379. if (!(ioc->config_cmds.status & MPT3_CMD_COMPLETE)) {
  380. mpt3sas_base_check_cmd_timeout(ioc,
  381. ioc->config_cmds.status, mpi_request,
  382. sizeof(Mpi2ConfigRequest_t)/4);
  383. retry_count++;
  384. if (ioc->config_cmds.smid == smid)
  385. mpt3sas_base_free_smid(ioc, smid);
  386. if ((ioc->shost_recovery) || (ioc->config_cmds.status &
  387. MPT3_CMD_RESET) || ioc->pci_error_recovery)
  388. goto retry_config;
  389. issue_host_reset = 1;
  390. r = -EFAULT;
  391. goto free_mem;
  392. }
  393. if (ioc->config_cmds.status & MPT3_CMD_REPLY_VALID) {
  394. memcpy(mpi_reply, ioc->config_cmds.reply,
  395. sizeof(Mpi2ConfigReply_t));
  396. /* Reply Frame Sanity Checks to workaround FW issues */
  397. if ((mpi_request->Header.PageType & 0xF) !=
  398. (mpi_reply->Header.PageType & 0xF)) {
  399. _debug_dump_mf(mpi_request, ioc->request_sz/4);
  400. _debug_dump_reply(mpi_reply, ioc->request_sz/4);
  401. panic(KERN_WARNING MPT3SAS_FMT "%s: Firmware BUG:" \
  402. " mpi_reply mismatch: Requested PageType(0x%02x)" \
  403. " Reply PageType(0x%02x)\n", \
  404. ioc->name, __func__,
  405. (mpi_request->Header.PageType & 0xF),
  406. (mpi_reply->Header.PageType & 0xF));
  407. }
  408. if (((mpi_request->Header.PageType & 0xF) ==
  409. MPI2_CONFIG_PAGETYPE_EXTENDED) &&
  410. mpi_request->ExtPageType != mpi_reply->ExtPageType) {
  411. _debug_dump_mf(mpi_request, ioc->request_sz/4);
  412. _debug_dump_reply(mpi_reply, ioc->request_sz/4);
  413. panic(KERN_WARNING MPT3SAS_FMT "%s: Firmware BUG:" \
  414. " mpi_reply mismatch: Requested ExtPageType(0x%02x)"
  415. " Reply ExtPageType(0x%02x)\n",
  416. ioc->name, __func__, mpi_request->ExtPageType,
  417. mpi_reply->ExtPageType);
  418. }
  419. ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
  420. & MPI2_IOCSTATUS_MASK;
  421. }
  422. if (retry_count)
  423. pr_info(MPT3SAS_FMT "%s: retry (%d) completed!!\n", \
  424. ioc->name, __func__, retry_count);
  425. if ((ioc_status == MPI2_IOCSTATUS_SUCCESS) &&
  426. config_page && mpi_request->Action ==
  427. MPI2_CONFIG_ACTION_PAGE_READ_CURRENT) {
  428. u8 *p = (u8 *)mem.page;
  429. /* Config Page Sanity Checks to workaround FW issues */
  430. if (p) {
  431. if ((mpi_request->Header.PageType & 0xF) !=
  432. (p[3] & 0xF)) {
  433. _debug_dump_mf(mpi_request, ioc->request_sz/4);
  434. _debug_dump_reply(mpi_reply, ioc->request_sz/4);
  435. _debug_dump_config(p, min_t(u16, mem.sz,
  436. config_page_sz)/4);
  437. panic(KERN_WARNING MPT3SAS_FMT
  438. "%s: Firmware BUG:" \
  439. " config page mismatch:"
  440. " Requested PageType(0x%02x)"
  441. " Reply PageType(0x%02x)\n",
  442. ioc->name, __func__,
  443. (mpi_request->Header.PageType & 0xF),
  444. (p[3] & 0xF));
  445. }
  446. if (((mpi_request->Header.PageType & 0xF) ==
  447. MPI2_CONFIG_PAGETYPE_EXTENDED) &&
  448. (mpi_request->ExtPageType != p[6])) {
  449. _debug_dump_mf(mpi_request, ioc->request_sz/4);
  450. _debug_dump_reply(mpi_reply, ioc->request_sz/4);
  451. _debug_dump_config(p, min_t(u16, mem.sz,
  452. config_page_sz)/4);
  453. panic(KERN_WARNING MPT3SAS_FMT
  454. "%s: Firmware BUG:" \
  455. " config page mismatch:"
  456. " Requested ExtPageType(0x%02x)"
  457. " Reply ExtPageType(0x%02x)\n",
  458. ioc->name, __func__,
  459. mpi_request->ExtPageType, p[6]);
  460. }
  461. }
  462. memcpy(config_page, mem.page, min_t(u16, mem.sz,
  463. config_page_sz));
  464. }
  465. free_mem:
  466. if (config_page)
  467. _config_free_config_dma_memory(ioc, &mem);
  468. out:
  469. ioc->config_cmds.status = MPT3_CMD_NOT_USED;
  470. mutex_unlock(&ioc->config_cmds.mutex);
  471. if (issue_host_reset)
  472. mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
  473. return r;
  474. }
  475. /**
  476. * mpt3sas_config_get_manufacturing_pg0 - obtain manufacturing page 0
  477. * @ioc: per adapter object
  478. * @mpi_reply: reply mf payload returned from firmware
  479. * @config_page: contents of the config page
  480. * Context: sleep.
  481. *
  482. * Return: 0 for success, non-zero for failure.
  483. */
  484. int
  485. mpt3sas_config_get_manufacturing_pg0(struct MPT3SAS_ADAPTER *ioc,
  486. Mpi2ConfigReply_t *mpi_reply, Mpi2ManufacturingPage0_t *config_page)
  487. {
  488. Mpi2ConfigRequest_t mpi_request;
  489. int r;
  490. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  491. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  492. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  493. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_MANUFACTURING;
  494. mpi_request.Header.PageNumber = 0;
  495. mpi_request.Header.PageVersion = MPI2_MANUFACTURING0_PAGEVERSION;
  496. ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE);
  497. r = _config_request(ioc, &mpi_request, mpi_reply,
  498. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  499. if (r)
  500. goto out;
  501. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  502. r = _config_request(ioc, &mpi_request, mpi_reply,
  503. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  504. sizeof(*config_page));
  505. out:
  506. return r;
  507. }
  508. /**
  509. * mpt3sas_config_get_manufacturing_pg7 - obtain manufacturing page 7
  510. * @ioc: per adapter object
  511. * @mpi_reply: reply mf payload returned from firmware
  512. * @config_page: contents of the config page
  513. * @sz: size of buffer passed in config_page
  514. * Context: sleep.
  515. *
  516. * Return: 0 for success, non-zero for failure.
  517. */
  518. int
  519. mpt3sas_config_get_manufacturing_pg7(struct MPT3SAS_ADAPTER *ioc,
  520. Mpi2ConfigReply_t *mpi_reply, Mpi2ManufacturingPage7_t *config_page,
  521. u16 sz)
  522. {
  523. Mpi2ConfigRequest_t mpi_request;
  524. int r;
  525. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  526. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  527. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  528. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_MANUFACTURING;
  529. mpi_request.Header.PageNumber = 7;
  530. mpi_request.Header.PageVersion = MPI2_MANUFACTURING7_PAGEVERSION;
  531. ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE);
  532. r = _config_request(ioc, &mpi_request, mpi_reply,
  533. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  534. if (r)
  535. goto out;
  536. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  537. r = _config_request(ioc, &mpi_request, mpi_reply,
  538. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  539. sz);
  540. out:
  541. return r;
  542. }
  543. /**
  544. * mpt3sas_config_get_manufacturing_pg10 - obtain manufacturing page 10
  545. * @ioc: per adapter object
  546. * @mpi_reply: reply mf payload returned from firmware
  547. * @config_page: contents of the config page
  548. * Context: sleep.
  549. *
  550. * Return: 0 for success, non-zero for failure.
  551. */
  552. int
  553. mpt3sas_config_get_manufacturing_pg10(struct MPT3SAS_ADAPTER *ioc,
  554. Mpi2ConfigReply_t *mpi_reply,
  555. struct Mpi2ManufacturingPage10_t *config_page)
  556. {
  557. Mpi2ConfigRequest_t mpi_request;
  558. int r;
  559. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  560. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  561. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  562. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_MANUFACTURING;
  563. mpi_request.Header.PageNumber = 10;
  564. mpi_request.Header.PageVersion = MPI2_MANUFACTURING0_PAGEVERSION;
  565. ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE);
  566. r = _config_request(ioc, &mpi_request, mpi_reply,
  567. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  568. if (r)
  569. goto out;
  570. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  571. r = _config_request(ioc, &mpi_request, mpi_reply,
  572. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  573. sizeof(*config_page));
  574. out:
  575. return r;
  576. }
  577. /**
  578. * mpt3sas_config_get_manufacturing_pg11 - obtain manufacturing page 11
  579. * @ioc: per adapter object
  580. * @mpi_reply: reply mf payload returned from firmware
  581. * @config_page: contents of the config page
  582. * Context: sleep.
  583. *
  584. * Return: 0 for success, non-zero for failure.
  585. */
  586. int
  587. mpt3sas_config_get_manufacturing_pg11(struct MPT3SAS_ADAPTER *ioc,
  588. Mpi2ConfigReply_t *mpi_reply,
  589. struct Mpi2ManufacturingPage11_t *config_page)
  590. {
  591. Mpi2ConfigRequest_t mpi_request;
  592. int r;
  593. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  594. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  595. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  596. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_MANUFACTURING;
  597. mpi_request.Header.PageNumber = 11;
  598. mpi_request.Header.PageVersion = MPI2_MANUFACTURING0_PAGEVERSION;
  599. ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE);
  600. r = _config_request(ioc, &mpi_request, mpi_reply,
  601. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  602. if (r)
  603. goto out;
  604. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  605. r = _config_request(ioc, &mpi_request, mpi_reply,
  606. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  607. sizeof(*config_page));
  608. out:
  609. return r;
  610. }
  611. /**
  612. * mpt3sas_config_set_manufacturing_pg11 - set manufacturing page 11
  613. * @ioc: per adapter object
  614. * @mpi_reply: reply mf payload returned from firmware
  615. * @config_page: contents of the config page
  616. * Context: sleep.
  617. *
  618. * Return: 0 for success, non-zero for failure.
  619. */
  620. int
  621. mpt3sas_config_set_manufacturing_pg11(struct MPT3SAS_ADAPTER *ioc,
  622. Mpi2ConfigReply_t *mpi_reply,
  623. struct Mpi2ManufacturingPage11_t *config_page)
  624. {
  625. Mpi2ConfigRequest_t mpi_request;
  626. int r;
  627. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  628. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  629. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  630. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_MANUFACTURING;
  631. mpi_request.Header.PageNumber = 11;
  632. mpi_request.Header.PageVersion = MPI2_MANUFACTURING0_PAGEVERSION;
  633. ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE);
  634. r = _config_request(ioc, &mpi_request, mpi_reply,
  635. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  636. if (r)
  637. goto out;
  638. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_WRITE_CURRENT;
  639. r = _config_request(ioc, &mpi_request, mpi_reply,
  640. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  641. sizeof(*config_page));
  642. out:
  643. return r;
  644. }
  645. /**
  646. * mpt3sas_config_get_bios_pg2 - obtain bios page 2
  647. * @ioc: per adapter object
  648. * @mpi_reply: reply mf payload returned from firmware
  649. * @config_page: contents of the config page
  650. * Context: sleep.
  651. *
  652. * Return: 0 for success, non-zero for failure.
  653. */
  654. int
  655. mpt3sas_config_get_bios_pg2(struct MPT3SAS_ADAPTER *ioc,
  656. Mpi2ConfigReply_t *mpi_reply, Mpi2BiosPage2_t *config_page)
  657. {
  658. Mpi2ConfigRequest_t mpi_request;
  659. int r;
  660. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  661. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  662. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  663. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_BIOS;
  664. mpi_request.Header.PageNumber = 2;
  665. mpi_request.Header.PageVersion = MPI2_BIOSPAGE2_PAGEVERSION;
  666. ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE);
  667. r = _config_request(ioc, &mpi_request, mpi_reply,
  668. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  669. if (r)
  670. goto out;
  671. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  672. r = _config_request(ioc, &mpi_request, mpi_reply,
  673. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  674. sizeof(*config_page));
  675. out:
  676. return r;
  677. }
  678. /**
  679. * mpt3sas_config_get_bios_pg3 - obtain bios page 3
  680. * @ioc: per adapter object
  681. * @mpi_reply: reply mf payload returned from firmware
  682. * @config_page: contents of the config page
  683. * Context: sleep.
  684. *
  685. * Return: 0 for success, non-zero for failure.
  686. */
  687. int
  688. mpt3sas_config_get_bios_pg3(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigReply_t
  689. *mpi_reply, Mpi2BiosPage3_t *config_page)
  690. {
  691. Mpi2ConfigRequest_t mpi_request;
  692. int r;
  693. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  694. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  695. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  696. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_BIOS;
  697. mpi_request.Header.PageNumber = 3;
  698. mpi_request.Header.PageVersion = MPI2_BIOSPAGE3_PAGEVERSION;
  699. ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE);
  700. r = _config_request(ioc, &mpi_request, mpi_reply,
  701. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  702. if (r)
  703. goto out;
  704. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  705. r = _config_request(ioc, &mpi_request, mpi_reply,
  706. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  707. sizeof(*config_page));
  708. out:
  709. return r;
  710. }
  711. /**
  712. * mpt3sas_config_get_iounit_pg0 - obtain iounit page 0
  713. * @ioc: per adapter object
  714. * @mpi_reply: reply mf payload returned from firmware
  715. * @config_page: contents of the config page
  716. * Context: sleep.
  717. *
  718. * Return: 0 for success, non-zero for failure.
  719. */
  720. int
  721. mpt3sas_config_get_iounit_pg0(struct MPT3SAS_ADAPTER *ioc,
  722. Mpi2ConfigReply_t *mpi_reply, Mpi2IOUnitPage0_t *config_page)
  723. {
  724. Mpi2ConfigRequest_t mpi_request;
  725. int r;
  726. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  727. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  728. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  729. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_IO_UNIT;
  730. mpi_request.Header.PageNumber = 0;
  731. mpi_request.Header.PageVersion = MPI2_IOUNITPAGE0_PAGEVERSION;
  732. ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE);
  733. r = _config_request(ioc, &mpi_request, mpi_reply,
  734. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  735. if (r)
  736. goto out;
  737. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  738. r = _config_request(ioc, &mpi_request, mpi_reply,
  739. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  740. sizeof(*config_page));
  741. out:
  742. return r;
  743. }
  744. /**
  745. * mpt3sas_config_get_iounit_pg1 - obtain iounit page 1
  746. * @ioc: per adapter object
  747. * @mpi_reply: reply mf payload returned from firmware
  748. * @config_page: contents of the config page
  749. * Context: sleep.
  750. *
  751. * Return: 0 for success, non-zero for failure.
  752. */
  753. int
  754. mpt3sas_config_get_iounit_pg1(struct MPT3SAS_ADAPTER *ioc,
  755. Mpi2ConfigReply_t *mpi_reply, Mpi2IOUnitPage1_t *config_page)
  756. {
  757. Mpi2ConfigRequest_t mpi_request;
  758. int r;
  759. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  760. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  761. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  762. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_IO_UNIT;
  763. mpi_request.Header.PageNumber = 1;
  764. mpi_request.Header.PageVersion = MPI2_IOUNITPAGE1_PAGEVERSION;
  765. ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE);
  766. r = _config_request(ioc, &mpi_request, mpi_reply,
  767. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  768. if (r)
  769. goto out;
  770. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  771. r = _config_request(ioc, &mpi_request, mpi_reply,
  772. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  773. sizeof(*config_page));
  774. out:
  775. return r;
  776. }
  777. /**
  778. * mpt3sas_config_set_iounit_pg1 - set iounit page 1
  779. * @ioc: per adapter object
  780. * @mpi_reply: reply mf payload returned from firmware
  781. * @config_page: contents of the config page
  782. * Context: sleep.
  783. *
  784. * Return: 0 for success, non-zero for failure.
  785. */
  786. int
  787. mpt3sas_config_set_iounit_pg1(struct MPT3SAS_ADAPTER *ioc,
  788. Mpi2ConfigReply_t *mpi_reply, Mpi2IOUnitPage1_t *config_page)
  789. {
  790. Mpi2ConfigRequest_t mpi_request;
  791. int r;
  792. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  793. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  794. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  795. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_IO_UNIT;
  796. mpi_request.Header.PageNumber = 1;
  797. mpi_request.Header.PageVersion = MPI2_IOUNITPAGE1_PAGEVERSION;
  798. ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE);
  799. r = _config_request(ioc, &mpi_request, mpi_reply,
  800. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  801. if (r)
  802. goto out;
  803. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_WRITE_CURRENT;
  804. r = _config_request(ioc, &mpi_request, mpi_reply,
  805. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  806. sizeof(*config_page));
  807. out:
  808. return r;
  809. }
  810. /**
  811. * mpt3sas_config_get_iounit_pg3 - obtain iounit page 3
  812. * @ioc: per adapter object
  813. * @mpi_reply: reply mf payload returned from firmware
  814. * @config_page: contents of the config page
  815. * @sz: size of buffer passed in config_page
  816. * Context: sleep.
  817. *
  818. * Return: 0 for success, non-zero for failure.
  819. */
  820. int
  821. mpt3sas_config_get_iounit_pg3(struct MPT3SAS_ADAPTER *ioc,
  822. Mpi2ConfigReply_t *mpi_reply, Mpi2IOUnitPage3_t *config_page, u16 sz)
  823. {
  824. Mpi2ConfigRequest_t mpi_request;
  825. int r;
  826. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  827. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  828. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  829. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_IO_UNIT;
  830. mpi_request.Header.PageNumber = 3;
  831. mpi_request.Header.PageVersion = MPI2_IOUNITPAGE3_PAGEVERSION;
  832. ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE);
  833. r = _config_request(ioc, &mpi_request, mpi_reply,
  834. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  835. if (r)
  836. goto out;
  837. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  838. r = _config_request(ioc, &mpi_request, mpi_reply,
  839. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sz);
  840. out:
  841. return r;
  842. }
  843. /**
  844. * mpt3sas_config_get_iounit_pg8 - obtain iounit page 8
  845. * @ioc: per adapter object
  846. * @mpi_reply: reply mf payload returned from firmware
  847. * @config_page: contents of the config page
  848. * Context: sleep.
  849. *
  850. * Return: 0 for success, non-zero for failure.
  851. */
  852. int
  853. mpt3sas_config_get_iounit_pg8(struct MPT3SAS_ADAPTER *ioc,
  854. Mpi2ConfigReply_t *mpi_reply, Mpi2IOUnitPage8_t *config_page)
  855. {
  856. Mpi2ConfigRequest_t mpi_request;
  857. int r;
  858. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  859. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  860. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  861. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_IO_UNIT;
  862. mpi_request.Header.PageNumber = 8;
  863. mpi_request.Header.PageVersion = MPI2_IOUNITPAGE8_PAGEVERSION;
  864. ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE);
  865. r = _config_request(ioc, &mpi_request, mpi_reply,
  866. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  867. if (r)
  868. goto out;
  869. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  870. r = _config_request(ioc, &mpi_request, mpi_reply,
  871. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  872. sizeof(*config_page));
  873. out:
  874. return r;
  875. }
  876. /**
  877. * mpt3sas_config_get_ioc_pg8 - obtain ioc page 8
  878. * @ioc: per adapter object
  879. * @mpi_reply: reply mf payload returned from firmware
  880. * @config_page: contents of the config page
  881. * Context: sleep.
  882. *
  883. * Return: 0 for success, non-zero for failure.
  884. */
  885. int
  886. mpt3sas_config_get_ioc_pg8(struct MPT3SAS_ADAPTER *ioc,
  887. Mpi2ConfigReply_t *mpi_reply, Mpi2IOCPage8_t *config_page)
  888. {
  889. Mpi2ConfigRequest_t mpi_request;
  890. int r;
  891. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  892. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  893. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  894. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_IOC;
  895. mpi_request.Header.PageNumber = 8;
  896. mpi_request.Header.PageVersion = MPI2_IOCPAGE8_PAGEVERSION;
  897. ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE);
  898. r = _config_request(ioc, &mpi_request, mpi_reply,
  899. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  900. if (r)
  901. goto out;
  902. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  903. r = _config_request(ioc, &mpi_request, mpi_reply,
  904. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  905. sizeof(*config_page));
  906. out:
  907. return r;
  908. }
  909. /**
  910. * mpt3sas_config_get_sas_device_pg0 - obtain sas device page 0
  911. * @ioc: per adapter object
  912. * @mpi_reply: reply mf payload returned from firmware
  913. * @config_page: contents of the config page
  914. * @form: GET_NEXT_HANDLE or HANDLE
  915. * @handle: device handle
  916. * Context: sleep.
  917. *
  918. * Return: 0 for success, non-zero for failure.
  919. */
  920. int
  921. mpt3sas_config_get_sas_device_pg0(struct MPT3SAS_ADAPTER *ioc,
  922. Mpi2ConfigReply_t *mpi_reply, Mpi2SasDevicePage0_t *config_page,
  923. u32 form, u32 handle)
  924. {
  925. Mpi2ConfigRequest_t mpi_request;
  926. int r;
  927. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  928. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  929. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  930. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
  931. mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_DEVICE;
  932. mpi_request.Header.PageVersion = MPI2_SASDEVICE0_PAGEVERSION;
  933. mpi_request.Header.PageNumber = 0;
  934. ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE);
  935. r = _config_request(ioc, &mpi_request, mpi_reply,
  936. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  937. if (r)
  938. goto out;
  939. mpi_request.PageAddress = cpu_to_le32(form | handle);
  940. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  941. r = _config_request(ioc, &mpi_request, mpi_reply,
  942. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  943. sizeof(*config_page));
  944. out:
  945. return r;
  946. }
  947. /**
  948. * mpt3sas_config_get_sas_device_pg1 - obtain sas device page 1
  949. * @ioc: per adapter object
  950. * @mpi_reply: reply mf payload returned from firmware
  951. * @config_page: contents of the config page
  952. * @form: GET_NEXT_HANDLE or HANDLE
  953. * @handle: device handle
  954. * Context: sleep.
  955. *
  956. * Return: 0 for success, non-zero for failure.
  957. */
  958. int
  959. mpt3sas_config_get_sas_device_pg1(struct MPT3SAS_ADAPTER *ioc,
  960. Mpi2ConfigReply_t *mpi_reply, Mpi2SasDevicePage1_t *config_page,
  961. u32 form, u32 handle)
  962. {
  963. Mpi2ConfigRequest_t mpi_request;
  964. int r;
  965. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  966. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  967. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  968. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
  969. mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_DEVICE;
  970. mpi_request.Header.PageVersion = MPI2_SASDEVICE1_PAGEVERSION;
  971. mpi_request.Header.PageNumber = 1;
  972. ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE);
  973. r = _config_request(ioc, &mpi_request, mpi_reply,
  974. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  975. if (r)
  976. goto out;
  977. mpi_request.PageAddress = cpu_to_le32(form | handle);
  978. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  979. r = _config_request(ioc, &mpi_request, mpi_reply,
  980. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  981. sizeof(*config_page));
  982. out:
  983. return r;
  984. }
  985. /**
  986. * mpt3sas_config_get_pcie_device_pg0 - obtain pcie device page 0
  987. * @ioc: per adapter object
  988. * @mpi_reply: reply mf payload returned from firmware
  989. * @config_page: contents of the config page
  990. * @form: GET_NEXT_HANDLE or HANDLE
  991. * @handle: device handle
  992. * Context: sleep.
  993. *
  994. * Return: 0 for success, non-zero for failure.
  995. */
  996. int
  997. mpt3sas_config_get_pcie_device_pg0(struct MPT3SAS_ADAPTER *ioc,
  998. Mpi2ConfigReply_t *mpi_reply, Mpi26PCIeDevicePage0_t *config_page,
  999. u32 form, u32 handle)
  1000. {
  1001. Mpi2ConfigRequest_t mpi_request;
  1002. int r;
  1003. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  1004. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  1005. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  1006. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
  1007. mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_PCIE_DEVICE;
  1008. mpi_request.Header.PageVersion = MPI26_PCIEDEVICE0_PAGEVERSION;
  1009. mpi_request.Header.PageNumber = 0;
  1010. ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE);
  1011. r = _config_request(ioc, &mpi_request, mpi_reply,
  1012. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  1013. if (r)
  1014. goto out;
  1015. mpi_request.PageAddress = cpu_to_le32(form | handle);
  1016. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  1017. r = _config_request(ioc, &mpi_request, mpi_reply,
  1018. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  1019. sizeof(*config_page));
  1020. out:
  1021. return r;
  1022. }
  1023. /**
  1024. * mpt3sas_config_get_pcie_device_pg2 - obtain pcie device page 2
  1025. * @ioc: per adapter object
  1026. * @mpi_reply: reply mf payload returned from firmware
  1027. * @config_page: contents of the config page
  1028. * @form: GET_NEXT_HANDLE or HANDLE
  1029. * @handle: device handle
  1030. * Context: sleep.
  1031. *
  1032. * Return: 0 for success, non-zero for failure.
  1033. */
  1034. int
  1035. mpt3sas_config_get_pcie_device_pg2(struct MPT3SAS_ADAPTER *ioc,
  1036. Mpi2ConfigReply_t *mpi_reply, Mpi26PCIeDevicePage2_t *config_page,
  1037. u32 form, u32 handle)
  1038. {
  1039. Mpi2ConfigRequest_t mpi_request;
  1040. int r;
  1041. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  1042. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  1043. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  1044. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
  1045. mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_PCIE_DEVICE;
  1046. mpi_request.Header.PageVersion = MPI26_PCIEDEVICE2_PAGEVERSION;
  1047. mpi_request.Header.PageNumber = 2;
  1048. ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE);
  1049. r = _config_request(ioc, &mpi_request, mpi_reply,
  1050. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  1051. if (r)
  1052. goto out;
  1053. mpi_request.PageAddress = cpu_to_le32(form | handle);
  1054. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  1055. r = _config_request(ioc, &mpi_request, mpi_reply,
  1056. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  1057. sizeof(*config_page));
  1058. out:
  1059. return r;
  1060. }
  1061. /**
  1062. * mpt3sas_config_get_number_hba_phys - obtain number of phys on the host
  1063. * @ioc: per adapter object
  1064. * @num_phys: pointer returned with the number of phys
  1065. * Context: sleep.
  1066. *
  1067. * Return: 0 for success, non-zero for failure.
  1068. */
  1069. int
  1070. mpt3sas_config_get_number_hba_phys(struct MPT3SAS_ADAPTER *ioc, u8 *num_phys)
  1071. {
  1072. Mpi2ConfigRequest_t mpi_request;
  1073. int r;
  1074. u16 ioc_status;
  1075. Mpi2ConfigReply_t mpi_reply;
  1076. Mpi2SasIOUnitPage0_t config_page;
  1077. *num_phys = 0;
  1078. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  1079. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  1080. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  1081. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
  1082. mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
  1083. mpi_request.Header.PageNumber = 0;
  1084. mpi_request.Header.PageVersion = MPI2_SASIOUNITPAGE0_PAGEVERSION;
  1085. ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE);
  1086. r = _config_request(ioc, &mpi_request, &mpi_reply,
  1087. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  1088. if (r)
  1089. goto out;
  1090. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  1091. r = _config_request(ioc, &mpi_request, &mpi_reply,
  1092. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, &config_page,
  1093. sizeof(Mpi2SasIOUnitPage0_t));
  1094. if (!r) {
  1095. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  1096. MPI2_IOCSTATUS_MASK;
  1097. if (ioc_status == MPI2_IOCSTATUS_SUCCESS)
  1098. *num_phys = config_page.NumPhys;
  1099. }
  1100. out:
  1101. return r;
  1102. }
  1103. /**
  1104. * mpt3sas_config_get_sas_iounit_pg0 - obtain sas iounit page 0
  1105. * @ioc: per adapter object
  1106. * @mpi_reply: reply mf payload returned from firmware
  1107. * @config_page: contents of the config page
  1108. * @sz: size of buffer passed in config_page
  1109. * Context: sleep.
  1110. *
  1111. * Calling function should call config_get_number_hba_phys prior to
  1112. * this function, so enough memory is allocated for config_page.
  1113. *
  1114. * Return: 0 for success, non-zero for failure.
  1115. */
  1116. int
  1117. mpt3sas_config_get_sas_iounit_pg0(struct MPT3SAS_ADAPTER *ioc,
  1118. Mpi2ConfigReply_t *mpi_reply, Mpi2SasIOUnitPage0_t *config_page,
  1119. u16 sz)
  1120. {
  1121. Mpi2ConfigRequest_t mpi_request;
  1122. int r;
  1123. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  1124. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  1125. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  1126. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
  1127. mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
  1128. mpi_request.Header.PageNumber = 0;
  1129. mpi_request.Header.PageVersion = MPI2_SASIOUNITPAGE0_PAGEVERSION;
  1130. ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE);
  1131. r = _config_request(ioc, &mpi_request, mpi_reply,
  1132. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  1133. if (r)
  1134. goto out;
  1135. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  1136. r = _config_request(ioc, &mpi_request, mpi_reply,
  1137. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sz);
  1138. out:
  1139. return r;
  1140. }
  1141. /**
  1142. * mpt3sas_config_get_sas_iounit_pg1 - obtain sas iounit page 1
  1143. * @ioc: per adapter object
  1144. * @mpi_reply: reply mf payload returned from firmware
  1145. * @config_page: contents of the config page
  1146. * @sz: size of buffer passed in config_page
  1147. * Context: sleep.
  1148. *
  1149. * Calling function should call config_get_number_hba_phys prior to
  1150. * this function, so enough memory is allocated for config_page.
  1151. *
  1152. * Return: 0 for success, non-zero for failure.
  1153. */
  1154. int
  1155. mpt3sas_config_get_sas_iounit_pg1(struct MPT3SAS_ADAPTER *ioc,
  1156. Mpi2ConfigReply_t *mpi_reply, Mpi2SasIOUnitPage1_t *config_page,
  1157. u16 sz)
  1158. {
  1159. Mpi2ConfigRequest_t mpi_request;
  1160. int r;
  1161. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  1162. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  1163. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  1164. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
  1165. mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
  1166. mpi_request.Header.PageNumber = 1;
  1167. mpi_request.Header.PageVersion = MPI2_SASIOUNITPAGE1_PAGEVERSION;
  1168. ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE);
  1169. r = _config_request(ioc, &mpi_request, mpi_reply,
  1170. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  1171. if (r)
  1172. goto out;
  1173. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  1174. r = _config_request(ioc, &mpi_request, mpi_reply,
  1175. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sz);
  1176. out:
  1177. return r;
  1178. }
  1179. /**
  1180. * mpt3sas_config_set_sas_iounit_pg1 - send sas iounit page 1
  1181. * @ioc: per adapter object
  1182. * @mpi_reply: reply mf payload returned from firmware
  1183. * @config_page: contents of the config page
  1184. * @sz: size of buffer passed in config_page
  1185. * Context: sleep.
  1186. *
  1187. * Calling function should call config_get_number_hba_phys prior to
  1188. * this function, so enough memory is allocated for config_page.
  1189. *
  1190. * Return: 0 for success, non-zero for failure.
  1191. */
  1192. int
  1193. mpt3sas_config_set_sas_iounit_pg1(struct MPT3SAS_ADAPTER *ioc,
  1194. Mpi2ConfigReply_t *mpi_reply, Mpi2SasIOUnitPage1_t *config_page,
  1195. u16 sz)
  1196. {
  1197. Mpi2ConfigRequest_t mpi_request;
  1198. int r;
  1199. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  1200. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  1201. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  1202. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
  1203. mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
  1204. mpi_request.Header.PageNumber = 1;
  1205. mpi_request.Header.PageVersion = MPI2_SASIOUNITPAGE1_PAGEVERSION;
  1206. ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE);
  1207. r = _config_request(ioc, &mpi_request, mpi_reply,
  1208. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  1209. if (r)
  1210. goto out;
  1211. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_WRITE_CURRENT;
  1212. _config_request(ioc, &mpi_request, mpi_reply,
  1213. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sz);
  1214. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_WRITE_NVRAM;
  1215. r = _config_request(ioc, &mpi_request, mpi_reply,
  1216. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sz);
  1217. out:
  1218. return r;
  1219. }
  1220. /**
  1221. * mpt3sas_config_get_expander_pg0 - obtain expander page 0
  1222. * @ioc: per adapter object
  1223. * @mpi_reply: reply mf payload returned from firmware
  1224. * @config_page: contents of the config page
  1225. * @form: GET_NEXT_HANDLE or HANDLE
  1226. * @handle: expander handle
  1227. * Context: sleep.
  1228. *
  1229. * Return: 0 for success, non-zero for failure.
  1230. */
  1231. int
  1232. mpt3sas_config_get_expander_pg0(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigReply_t
  1233. *mpi_reply, Mpi2ExpanderPage0_t *config_page, u32 form, u32 handle)
  1234. {
  1235. Mpi2ConfigRequest_t mpi_request;
  1236. int r;
  1237. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  1238. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  1239. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  1240. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
  1241. mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_EXPANDER;
  1242. mpi_request.Header.PageNumber = 0;
  1243. mpi_request.Header.PageVersion = MPI2_SASEXPANDER0_PAGEVERSION;
  1244. ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE);
  1245. r = _config_request(ioc, &mpi_request, mpi_reply,
  1246. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  1247. if (r)
  1248. goto out;
  1249. mpi_request.PageAddress = cpu_to_le32(form | handle);
  1250. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  1251. r = _config_request(ioc, &mpi_request, mpi_reply,
  1252. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  1253. sizeof(*config_page));
  1254. out:
  1255. return r;
  1256. }
  1257. /**
  1258. * mpt3sas_config_get_expander_pg1 - obtain expander page 1
  1259. * @ioc: per adapter object
  1260. * @mpi_reply: reply mf payload returned from firmware
  1261. * @config_page: contents of the config page
  1262. * @phy_number: phy number
  1263. * @handle: expander handle
  1264. * Context: sleep.
  1265. *
  1266. * Return: 0 for success, non-zero for failure.
  1267. */
  1268. int
  1269. mpt3sas_config_get_expander_pg1(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigReply_t
  1270. *mpi_reply, Mpi2ExpanderPage1_t *config_page, u32 phy_number,
  1271. u16 handle)
  1272. {
  1273. Mpi2ConfigRequest_t mpi_request;
  1274. int r;
  1275. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  1276. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  1277. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  1278. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
  1279. mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_EXPANDER;
  1280. mpi_request.Header.PageNumber = 1;
  1281. mpi_request.Header.PageVersion = MPI2_SASEXPANDER1_PAGEVERSION;
  1282. ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE);
  1283. r = _config_request(ioc, &mpi_request, mpi_reply,
  1284. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  1285. if (r)
  1286. goto out;
  1287. mpi_request.PageAddress =
  1288. cpu_to_le32(MPI2_SAS_EXPAND_PGAD_FORM_HNDL_PHY_NUM |
  1289. (phy_number << MPI2_SAS_EXPAND_PGAD_PHYNUM_SHIFT) | handle);
  1290. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  1291. r = _config_request(ioc, &mpi_request, mpi_reply,
  1292. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  1293. sizeof(*config_page));
  1294. out:
  1295. return r;
  1296. }
  1297. /**
  1298. * mpt3sas_config_get_enclosure_pg0 - obtain enclosure page 0
  1299. * @ioc: per adapter object
  1300. * @mpi_reply: reply mf payload returned from firmware
  1301. * @config_page: contents of the config page
  1302. * @form: GET_NEXT_HANDLE or HANDLE
  1303. * @handle: expander handle
  1304. * Context: sleep.
  1305. *
  1306. * Return: 0 for success, non-zero for failure.
  1307. */
  1308. int
  1309. mpt3sas_config_get_enclosure_pg0(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigReply_t
  1310. *mpi_reply, Mpi2SasEnclosurePage0_t *config_page, u32 form, u32 handle)
  1311. {
  1312. Mpi2ConfigRequest_t mpi_request;
  1313. int r;
  1314. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  1315. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  1316. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  1317. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
  1318. mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_ENCLOSURE;
  1319. mpi_request.Header.PageNumber = 0;
  1320. mpi_request.Header.PageVersion = MPI2_SASENCLOSURE0_PAGEVERSION;
  1321. ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE);
  1322. r = _config_request(ioc, &mpi_request, mpi_reply,
  1323. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  1324. if (r)
  1325. goto out;
  1326. mpi_request.PageAddress = cpu_to_le32(form | handle);
  1327. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  1328. r = _config_request(ioc, &mpi_request, mpi_reply,
  1329. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  1330. sizeof(*config_page));
  1331. out:
  1332. return r;
  1333. }
  1334. /**
  1335. * mpt3sas_config_get_phy_pg0 - obtain phy page 0
  1336. * @ioc: per adapter object
  1337. * @mpi_reply: reply mf payload returned from firmware
  1338. * @config_page: contents of the config page
  1339. * @phy_number: phy number
  1340. * Context: sleep.
  1341. *
  1342. * Return: 0 for success, non-zero for failure.
  1343. */
  1344. int
  1345. mpt3sas_config_get_phy_pg0(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigReply_t
  1346. *mpi_reply, Mpi2SasPhyPage0_t *config_page, u32 phy_number)
  1347. {
  1348. Mpi2ConfigRequest_t mpi_request;
  1349. int r;
  1350. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  1351. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  1352. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  1353. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
  1354. mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_PHY;
  1355. mpi_request.Header.PageNumber = 0;
  1356. mpi_request.Header.PageVersion = MPI2_SASPHY0_PAGEVERSION;
  1357. ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE);
  1358. r = _config_request(ioc, &mpi_request, mpi_reply,
  1359. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  1360. if (r)
  1361. goto out;
  1362. mpi_request.PageAddress =
  1363. cpu_to_le32(MPI2_SAS_PHY_PGAD_FORM_PHY_NUMBER | phy_number);
  1364. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  1365. r = _config_request(ioc, &mpi_request, mpi_reply,
  1366. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  1367. sizeof(*config_page));
  1368. out:
  1369. return r;
  1370. }
  1371. /**
  1372. * mpt3sas_config_get_phy_pg1 - obtain phy page 1
  1373. * @ioc: per adapter object
  1374. * @mpi_reply: reply mf payload returned from firmware
  1375. * @config_page: contents of the config page
  1376. * @phy_number: phy number
  1377. * Context: sleep.
  1378. *
  1379. * Return: 0 for success, non-zero for failure.
  1380. */
  1381. int
  1382. mpt3sas_config_get_phy_pg1(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigReply_t
  1383. *mpi_reply, Mpi2SasPhyPage1_t *config_page, u32 phy_number)
  1384. {
  1385. Mpi2ConfigRequest_t mpi_request;
  1386. int r;
  1387. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  1388. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  1389. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  1390. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
  1391. mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_PHY;
  1392. mpi_request.Header.PageNumber = 1;
  1393. mpi_request.Header.PageVersion = MPI2_SASPHY1_PAGEVERSION;
  1394. ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE);
  1395. r = _config_request(ioc, &mpi_request, mpi_reply,
  1396. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  1397. if (r)
  1398. goto out;
  1399. mpi_request.PageAddress =
  1400. cpu_to_le32(MPI2_SAS_PHY_PGAD_FORM_PHY_NUMBER | phy_number);
  1401. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  1402. r = _config_request(ioc, &mpi_request, mpi_reply,
  1403. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  1404. sizeof(*config_page));
  1405. out:
  1406. return r;
  1407. }
  1408. /**
  1409. * mpt3sas_config_get_raid_volume_pg1 - obtain raid volume page 1
  1410. * @ioc: per adapter object
  1411. * @mpi_reply: reply mf payload returned from firmware
  1412. * @config_page: contents of the config page
  1413. * @form: GET_NEXT_HANDLE or HANDLE
  1414. * @handle: volume handle
  1415. * Context: sleep.
  1416. *
  1417. * Return: 0 for success, non-zero for failure.
  1418. */
  1419. int
  1420. mpt3sas_config_get_raid_volume_pg1(struct MPT3SAS_ADAPTER *ioc,
  1421. Mpi2ConfigReply_t *mpi_reply, Mpi2RaidVolPage1_t *config_page, u32 form,
  1422. u32 handle)
  1423. {
  1424. Mpi2ConfigRequest_t mpi_request;
  1425. int r;
  1426. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  1427. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  1428. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  1429. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_RAID_VOLUME;
  1430. mpi_request.Header.PageNumber = 1;
  1431. mpi_request.Header.PageVersion = MPI2_RAIDVOLPAGE1_PAGEVERSION;
  1432. ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE);
  1433. r = _config_request(ioc, &mpi_request, mpi_reply,
  1434. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  1435. if (r)
  1436. goto out;
  1437. mpi_request.PageAddress = cpu_to_le32(form | handle);
  1438. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  1439. r = _config_request(ioc, &mpi_request, mpi_reply,
  1440. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  1441. sizeof(*config_page));
  1442. out:
  1443. return r;
  1444. }
  1445. /**
  1446. * mpt3sas_config_get_number_pds - obtain number of phys disk assigned to volume
  1447. * @ioc: per adapter object
  1448. * @handle: volume handle
  1449. * @num_pds: returns pds count
  1450. * Context: sleep.
  1451. *
  1452. * Return: 0 for success, non-zero for failure.
  1453. */
  1454. int
  1455. mpt3sas_config_get_number_pds(struct MPT3SAS_ADAPTER *ioc, u16 handle,
  1456. u8 *num_pds)
  1457. {
  1458. Mpi2ConfigRequest_t mpi_request;
  1459. Mpi2RaidVolPage0_t config_page;
  1460. Mpi2ConfigReply_t mpi_reply;
  1461. int r;
  1462. u16 ioc_status;
  1463. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  1464. *num_pds = 0;
  1465. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  1466. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  1467. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_RAID_VOLUME;
  1468. mpi_request.Header.PageNumber = 0;
  1469. mpi_request.Header.PageVersion = MPI2_RAIDVOLPAGE0_PAGEVERSION;
  1470. ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE);
  1471. r = _config_request(ioc, &mpi_request, &mpi_reply,
  1472. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  1473. if (r)
  1474. goto out;
  1475. mpi_request.PageAddress =
  1476. cpu_to_le32(MPI2_RAID_VOLUME_PGAD_FORM_HANDLE | handle);
  1477. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  1478. r = _config_request(ioc, &mpi_request, &mpi_reply,
  1479. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, &config_page,
  1480. sizeof(Mpi2RaidVolPage0_t));
  1481. if (!r) {
  1482. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  1483. MPI2_IOCSTATUS_MASK;
  1484. if (ioc_status == MPI2_IOCSTATUS_SUCCESS)
  1485. *num_pds = config_page.NumPhysDisks;
  1486. }
  1487. out:
  1488. return r;
  1489. }
  1490. /**
  1491. * mpt3sas_config_get_raid_volume_pg0 - obtain raid volume page 0
  1492. * @ioc: per adapter object
  1493. * @mpi_reply: reply mf payload returned from firmware
  1494. * @config_page: contents of the config page
  1495. * @form: GET_NEXT_HANDLE or HANDLE
  1496. * @handle: volume handle
  1497. * @sz: size of buffer passed in config_page
  1498. * Context: sleep.
  1499. *
  1500. * Return: 0 for success, non-zero for failure.
  1501. */
  1502. int
  1503. mpt3sas_config_get_raid_volume_pg0(struct MPT3SAS_ADAPTER *ioc,
  1504. Mpi2ConfigReply_t *mpi_reply, Mpi2RaidVolPage0_t *config_page, u32 form,
  1505. u32 handle, u16 sz)
  1506. {
  1507. Mpi2ConfigRequest_t mpi_request;
  1508. int r;
  1509. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  1510. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  1511. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  1512. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_RAID_VOLUME;
  1513. mpi_request.Header.PageNumber = 0;
  1514. mpi_request.Header.PageVersion = MPI2_RAIDVOLPAGE0_PAGEVERSION;
  1515. ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE);
  1516. r = _config_request(ioc, &mpi_request, mpi_reply,
  1517. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  1518. if (r)
  1519. goto out;
  1520. mpi_request.PageAddress = cpu_to_le32(form | handle);
  1521. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  1522. r = _config_request(ioc, &mpi_request, mpi_reply,
  1523. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sz);
  1524. out:
  1525. return r;
  1526. }
  1527. /**
  1528. * mpt3sas_config_get_phys_disk_pg0 - obtain phys disk page 0
  1529. * @ioc: per adapter object
  1530. * @mpi_reply: reply mf payload returned from firmware
  1531. * @config_page: contents of the config page
  1532. * @form: GET_NEXT_PHYSDISKNUM, PHYSDISKNUM, DEVHANDLE
  1533. * @form_specific: specific to the form
  1534. * Context: sleep.
  1535. *
  1536. * Return: 0 for success, non-zero for failure.
  1537. */
  1538. int
  1539. mpt3sas_config_get_phys_disk_pg0(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigReply_t
  1540. *mpi_reply, Mpi2RaidPhysDiskPage0_t *config_page, u32 form,
  1541. u32 form_specific)
  1542. {
  1543. Mpi2ConfigRequest_t mpi_request;
  1544. int r;
  1545. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  1546. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  1547. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  1548. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_RAID_PHYSDISK;
  1549. mpi_request.Header.PageNumber = 0;
  1550. mpi_request.Header.PageVersion = MPI2_RAIDPHYSDISKPAGE0_PAGEVERSION;
  1551. ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE);
  1552. r = _config_request(ioc, &mpi_request, mpi_reply,
  1553. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  1554. if (r)
  1555. goto out;
  1556. mpi_request.PageAddress = cpu_to_le32(form | form_specific);
  1557. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  1558. r = _config_request(ioc, &mpi_request, mpi_reply,
  1559. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  1560. sizeof(*config_page));
  1561. out:
  1562. return r;
  1563. }
  1564. /**
  1565. * mpt3sas_config_get_volume_handle - returns volume handle for give hidden
  1566. * raid components
  1567. * @ioc: per adapter object
  1568. * @pd_handle: phys disk handle
  1569. * @volume_handle: volume handle
  1570. * Context: sleep.
  1571. *
  1572. * Return: 0 for success, non-zero for failure.
  1573. */
  1574. int
  1575. mpt3sas_config_get_volume_handle(struct MPT3SAS_ADAPTER *ioc, u16 pd_handle,
  1576. u16 *volume_handle)
  1577. {
  1578. Mpi2RaidConfigurationPage0_t *config_page = NULL;
  1579. Mpi2ConfigRequest_t mpi_request;
  1580. Mpi2ConfigReply_t mpi_reply;
  1581. int r, i, config_page_sz;
  1582. u16 ioc_status;
  1583. int config_num;
  1584. u16 element_type;
  1585. u16 phys_disk_dev_handle;
  1586. *volume_handle = 0;
  1587. memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
  1588. mpi_request.Function = MPI2_FUNCTION_CONFIG;
  1589. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
  1590. mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
  1591. mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_RAID_CONFIG;
  1592. mpi_request.Header.PageVersion = MPI2_RAIDCONFIG0_PAGEVERSION;
  1593. mpi_request.Header.PageNumber = 0;
  1594. ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE);
  1595. r = _config_request(ioc, &mpi_request, &mpi_reply,
  1596. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
  1597. if (r)
  1598. goto out;
  1599. mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
  1600. config_page_sz = (le16_to_cpu(mpi_reply.ExtPageLength) * 4);
  1601. config_page = kmalloc(config_page_sz, GFP_KERNEL);
  1602. if (!config_page) {
  1603. r = -1;
  1604. goto out;
  1605. }
  1606. config_num = 0xff;
  1607. while (1) {
  1608. mpi_request.PageAddress = cpu_to_le32(config_num +
  1609. MPI2_RAID_PGAD_FORM_GET_NEXT_CONFIGNUM);
  1610. r = _config_request(ioc, &mpi_request, &mpi_reply,
  1611. MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
  1612. config_page_sz);
  1613. if (r)
  1614. goto out;
  1615. r = -1;
  1616. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  1617. MPI2_IOCSTATUS_MASK;
  1618. if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
  1619. goto out;
  1620. for (i = 0; i < config_page->NumElements; i++) {
  1621. element_type = le16_to_cpu(config_page->
  1622. ConfigElement[i].ElementFlags) &
  1623. MPI2_RAIDCONFIG0_EFLAGS_MASK_ELEMENT_TYPE;
  1624. if (element_type ==
  1625. MPI2_RAIDCONFIG0_EFLAGS_VOL_PHYS_DISK_ELEMENT ||
  1626. element_type ==
  1627. MPI2_RAIDCONFIG0_EFLAGS_OCE_ELEMENT) {
  1628. phys_disk_dev_handle =
  1629. le16_to_cpu(config_page->ConfigElement[i].
  1630. PhysDiskDevHandle);
  1631. if (phys_disk_dev_handle == pd_handle) {
  1632. *volume_handle =
  1633. le16_to_cpu(config_page->
  1634. ConfigElement[i].VolDevHandle);
  1635. r = 0;
  1636. goto out;
  1637. }
  1638. } else if (element_type ==
  1639. MPI2_RAIDCONFIG0_EFLAGS_HOT_SPARE_ELEMENT) {
  1640. *volume_handle = 0;
  1641. r = 0;
  1642. goto out;
  1643. }
  1644. }
  1645. config_num = config_page->ConfigNum;
  1646. }
  1647. out:
  1648. kfree(config_page);
  1649. return r;
  1650. }
  1651. /**
  1652. * mpt3sas_config_get_volume_wwid - returns wwid given the volume handle
  1653. * @ioc: per adapter object
  1654. * @volume_handle: volume handle
  1655. * @wwid: volume wwid
  1656. * Context: sleep.
  1657. *
  1658. * Return: 0 for success, non-zero for failure.
  1659. */
  1660. int
  1661. mpt3sas_config_get_volume_wwid(struct MPT3SAS_ADAPTER *ioc, u16 volume_handle,
  1662. u64 *wwid)
  1663. {
  1664. Mpi2ConfigReply_t mpi_reply;
  1665. Mpi2RaidVolPage1_t raid_vol_pg1;
  1666. *wwid = 0;
  1667. if (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
  1668. &raid_vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE,
  1669. volume_handle))) {
  1670. *wwid = le64_to_cpu(raid_vol_pg1.WWID);
  1671. return 0;
  1672. } else
  1673. return -1;
  1674. }