mpt3sas_config.c 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810
  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. }