aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/mpt2sas/mpt2sas_config.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/mpt2sas/mpt2sas_config.c')
-rw-r--r--drivers/scsi/mpt2sas/mpt2sas_config.c904
1 files changed, 226 insertions, 678 deletions
diff --git a/drivers/scsi/mpt2sas/mpt2sas_config.c b/drivers/scsi/mpt2sas/mpt2sas_config.c
index 6ddee161beb3..ab8c560865d8 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_config.c
+++ b/drivers/scsi/mpt2sas/mpt2sas_config.c
@@ -72,15 +72,15 @@
72 72
73/** 73/**
74 * struct config_request - obtain dma memory via routine 74 * struct config_request - obtain dma memory via routine
75 * @config_page_sz: size 75 * @sz: size
76 * @config_page: virt pointer 76 * @page: virt pointer
77 * @config_page_dma: phys pointer 77 * @page_dma: phys pointer
78 * 78 *
79 */ 79 */
80struct config_request{ 80struct config_request{
81 u16 config_page_sz; 81 u16 sz;
82 void *config_page; 82 void *page;
83 dma_addr_t config_page_dma; 83 dma_addr_t page_dma;
84}; 84};
85 85
86#ifdef CONFIG_SCSI_MPT2SAS_LOGGING 86#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
@@ -175,6 +175,55 @@ _config_display_some_debug(struct MPT2SAS_ADAPTER *ioc, u16 smid,
175#endif 175#endif
176 176
177/** 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 * Returns 0 for success, non-zero for failure.
185 */
186static int
187_config_alloc_config_dma_memory(struct MPT2SAS_ADAPTER *ioc,
188 struct config_request *mem)
189{
190 int r = 0;
191
192 if (mem->sz > ioc->config_page_sz) {
193 mem->page = dma_alloc_coherent(&ioc->pdev->dev, mem->sz,
194 &mem->page_dma, GFP_KERNEL);
195 if (!mem->page) {
196 printk(MPT2SAS_ERR_FMT "%s: dma_alloc_coherent"
197 " failed asking for (%d) bytes!!\n",
198 ioc->name, __func__, mem->sz);
199 r = -ENOMEM;
200 }
201 } else { /* use tmp buffer if less than 512 bytes */
202 mem->page = ioc->config_page;
203 mem->page_dma = ioc->config_page_dma;
204 }
205 return r;
206}
207
208/**
209 * _config_free_config_dma_memory - wrapper to free the memory
210 * @ioc: per adapter object
211 * @mem: struct config_request
212 *
213 * A wrapper to free dma-able memory when using _config_alloc_config_dma_memory.
214 *
215 * Returns 0 for success, non-zero for failure.
216 */
217static void
218_config_free_config_dma_memory(struct MPT2SAS_ADAPTER *ioc,
219 struct config_request *mem)
220{
221 if (mem->sz > ioc->config_page_sz)
222 dma_free_coherent(&ioc->pdev->dev, mem->sz, mem->page,
223 mem->page_dma);
224}
225
226/**
178 * mpt2sas_config_done - config page completion routine 227 * mpt2sas_config_done - config page completion routine
179 * @ioc: per adapter object 228 * @ioc: per adapter object
180 * @smid: system request message index 229 * @smid: system request message index
@@ -206,6 +255,7 @@ mpt2sas_config_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 VF_ID, u32 reply)
206#ifdef CONFIG_SCSI_MPT2SAS_LOGGING 255#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
207 _config_display_some_debug(ioc, smid, "config_done", mpi_reply); 256 _config_display_some_debug(ioc, smid, "config_done", mpi_reply);
208#endif 257#endif
258 ioc->config_cmds.smid = USHORT_MAX;
209 complete(&ioc->config_cmds.done); 259 complete(&ioc->config_cmds.done);
210} 260}
211 261
@@ -215,7 +265,9 @@ mpt2sas_config_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 VF_ID, u32 reply)
215 * @mpi_request: request message frame 265 * @mpi_request: request message frame
216 * @mpi_reply: reply mf payload returned from firmware 266 * @mpi_reply: reply mf payload returned from firmware
217 * @timeout: timeout in seconds 267 * @timeout: timeout in seconds
218 * Context: sleep, the calling function needs to acquire the config_cmds.mutex 268 * @config_page: contents of the config page
269 * @config_page_sz: size of config page
270 * Context: sleep
219 * 271 *
220 * A generic API for config page requests to firmware. 272 * A generic API for config page requests to firmware.
221 * 273 *
@@ -228,16 +280,17 @@ mpt2sas_config_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 VF_ID, u32 reply)
228 */ 280 */
229static int 281static int
230_config_request(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigRequest_t 282_config_request(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigRequest_t
231 *mpi_request, Mpi2ConfigReply_t *mpi_reply, int timeout) 283 *mpi_request, Mpi2ConfigReply_t *mpi_reply, int timeout,
284 void *config_page, u16 config_page_sz)
232{ 285{
233 u16 smid; 286 u16 smid;
234 u32 ioc_state; 287 u32 ioc_state;
235 unsigned long timeleft; 288 unsigned long timeleft;
236 Mpi2ConfigRequest_t *config_request; 289 Mpi2ConfigRequest_t *config_request;
237 int r; 290 int r;
238 u8 retry_count; 291 u8 retry_count, issue_host_reset = 0;
239 u8 issue_host_reset = 0;
240 u16 wait_state_count; 292 u16 wait_state_count;
293 struct config_request mem;
241 294
242 mutex_lock(&ioc->config_cmds.mutex); 295 mutex_lock(&ioc->config_cmds.mutex);
243 if (ioc->config_cmds.status != MPT2_CMD_NOT_USED) { 296 if (ioc->config_cmds.status != MPT2_CMD_NOT_USED) {
@@ -246,12 +299,44 @@ _config_request(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigRequest_t
246 mutex_unlock(&ioc->config_cmds.mutex); 299 mutex_unlock(&ioc->config_cmds.mutex);
247 return -EAGAIN; 300 return -EAGAIN;
248 } 301 }
302
249 retry_count = 0; 303 retry_count = 0;
304 memset(&mem, 0, sizeof(struct config_request));
305
306 if (config_page) {
307 mpi_request->Header.PageVersion = mpi_reply->Header.PageVersion;
308 mpi_request->Header.PageNumber = mpi_reply->Header.PageNumber;
309 mpi_request->Header.PageType = mpi_reply->Header.PageType;
310 mpi_request->Header.PageLength = mpi_reply->Header.PageLength;
311 mpi_request->ExtPageLength = mpi_reply->ExtPageLength;
312 mpi_request->ExtPageType = mpi_reply->ExtPageType;
313 if (mpi_request->Header.PageLength)
314 mem.sz = mpi_request->Header.PageLength * 4;
315 else
316 mem.sz = le16_to_cpu(mpi_reply->ExtPageLength) * 4;
317 r = _config_alloc_config_dma_memory(ioc, &mem);
318 if (r != 0)
319 goto out;
320 if (mpi_request->Action ==
321 MPI2_CONFIG_ACTION_PAGE_WRITE_CURRENT) {
322 ioc->base_add_sg_single(&mpi_request->PageBufferSGE,
323 MPT2_CONFIG_COMMON_WRITE_SGLFLAGS | mem.sz,
324 mem.page_dma);
325 memcpy(mem.page, config_page, min_t(u16, mem.sz,
326 config_page_sz));
327 } else {
328 memset(config_page, 0, config_page_sz);
329 ioc->base_add_sg_single(&mpi_request->PageBufferSGE,
330 MPT2_CONFIG_COMMON_SGLFLAGS | mem.sz, mem.page_dma);
331 }
332 }
250 333
251 retry_config: 334 retry_config:
252 if (retry_count) { 335 if (retry_count) {
253 if (retry_count > 2) /* attempt only 2 retries */ 336 if (retry_count > 2) { /* attempt only 2 retries */
254 return -EFAULT; 337 r = -EFAULT;
338 goto free_mem;
339 }
255 printk(MPT2SAS_INFO_FMT "%s: attempting retry (%d)\n", 340 printk(MPT2SAS_INFO_FMT "%s: attempting retry (%d)\n",
256 ioc->name, __func__, retry_count); 341 ioc->name, __func__, retry_count);
257 } 342 }
@@ -262,8 +347,9 @@ _config_request(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigRequest_t
262 printk(MPT2SAS_ERR_FMT 347 printk(MPT2SAS_ERR_FMT
263 "%s: failed due to ioc not operational\n", 348 "%s: failed due to ioc not operational\n",
264 ioc->name, __func__); 349 ioc->name, __func__);
350 ioc->config_cmds.status = MPT2_CMD_NOT_USED;
265 r = -EFAULT; 351 r = -EFAULT;
266 goto out; 352 goto free_mem;
267 } 353 }
268 ssleep(1); 354 ssleep(1);
269 ioc_state = mpt2sas_base_get_iocstate(ioc, 1); 355 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
@@ -279,8 +365,9 @@ _config_request(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigRequest_t
279 if (!smid) { 365 if (!smid) {
280 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", 366 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
281 ioc->name, __func__); 367 ioc->name, __func__);
368 ioc->config_cmds.status = MPT2_CMD_NOT_USED;
282 r = -EAGAIN; 369 r = -EAGAIN;
283 goto out; 370 goto free_mem;
284 } 371 }
285 372
286 r = 0; 373 r = 0;
@@ -292,6 +379,7 @@ _config_request(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigRequest_t
292#ifdef CONFIG_SCSI_MPT2SAS_LOGGING 379#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
293 _config_display_some_debug(ioc, smid, "config_request", NULL); 380 _config_display_some_debug(ioc, smid, "config_request", NULL);
294#endif 381#endif
382 init_completion(&ioc->config_cmds.done);
295 mpt2sas_base_put_smid_default(ioc, smid, config_request->VF_ID); 383 mpt2sas_base_put_smid_default(ioc, smid, config_request->VF_ID);
296 timeleft = wait_for_completion_timeout(&ioc->config_cmds.done, 384 timeleft = wait_for_completion_timeout(&ioc->config_cmds.done,
297 timeout*HZ); 385 timeout*HZ);
@@ -303,22 +391,31 @@ _config_request(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigRequest_t
303 retry_count++; 391 retry_count++;
304 if (ioc->config_cmds.smid == smid) 392 if (ioc->config_cmds.smid == smid)
305 mpt2sas_base_free_smid(ioc, smid); 393 mpt2sas_base_free_smid(ioc, smid);
306 if ((ioc->shost_recovery) || 394 if ((ioc->shost_recovery) || (ioc->config_cmds.status &
307 (ioc->config_cmds.status & MPT2_CMD_RESET)) 395 MPT2_CMD_RESET))
308 goto retry_config; 396 goto retry_config;
309 issue_host_reset = 1; 397 issue_host_reset = 1;
310 r = -EFAULT; 398 r = -EFAULT;
311 goto out; 399 goto free_mem;
312 } 400 }
401
313 if (ioc->config_cmds.status & MPT2_CMD_REPLY_VALID) 402 if (ioc->config_cmds.status & MPT2_CMD_REPLY_VALID)
314 memcpy(mpi_reply, ioc->config_cmds.reply, 403 memcpy(mpi_reply, ioc->config_cmds.reply,
315 sizeof(Mpi2ConfigReply_t)); 404 sizeof(Mpi2ConfigReply_t));
316 if (retry_count) 405 if (retry_count)
317 printk(MPT2SAS_INFO_FMT "%s: retry completed!!\n", 406 printk(MPT2SAS_INFO_FMT "%s: retry (%d) completed!!\n",
318 ioc->name, __func__); 407 ioc->name, __func__, retry_count);
319out: 408 if (config_page && mpi_request->Action ==
409 MPI2_CONFIG_ACTION_PAGE_READ_CURRENT)
410 memcpy(config_page, mem.page, min_t(u16, mem.sz,
411 config_page_sz));
412 free_mem:
413 if (config_page)
414 _config_free_config_dma_memory(ioc, &mem);
415 out:
320 ioc->config_cmds.status = MPT2_CMD_NOT_USED; 416 ioc->config_cmds.status = MPT2_CMD_NOT_USED;
321 mutex_unlock(&ioc->config_cmds.mutex); 417 mutex_unlock(&ioc->config_cmds.mutex);
418
322 if (issue_host_reset) 419 if (issue_host_reset)
323 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, 420 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
324 FORCE_BIG_HAMMER); 421 FORCE_BIG_HAMMER);
@@ -326,46 +423,43 @@ out:
326} 423}
327 424
328/** 425/**
329 * _config_alloc_config_dma_memory - obtain physical memory 426 * mpt2sas_config_get_manufacturing_pg0 - obtain manufacturing page 0
330 * @ioc: per adapter object 427 * @ioc: per adapter object
331 * @mem: struct config_request 428 * @mpi_reply: reply mf payload returned from firmware
332 * 429 * @config_page: contents of the config page
333 * A wrapper for obtaining dma-able memory for config page request. 430 * Context: sleep.
334 * 431 *
335 * Returns 0 for success, non-zero for failure. 432 * Returns 0 for success, non-zero for failure.
336 */ 433 */
337static int 434int
338_config_alloc_config_dma_memory(struct MPT2SAS_ADAPTER *ioc, 435mpt2sas_config_get_manufacturing_pg0(struct MPT2SAS_ADAPTER *ioc,
339 struct config_request *mem) 436 Mpi2ConfigReply_t *mpi_reply, Mpi2ManufacturingPage0_t *config_page)
340{ 437{
341 int r = 0; 438 Mpi2ConfigRequest_t mpi_request;
439 int r;
342 440
343 mem->config_page = pci_alloc_consistent(ioc->pdev, mem->config_page_sz, 441 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
344 &mem->config_page_dma); 442 mpi_request.Function = MPI2_FUNCTION_CONFIG;
345 if (!mem->config_page) 443 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
346 r = -ENOMEM; 444 mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_MANUFACTURING;
347 return r; 445 mpi_request.Header.PageNumber = 0;
348} 446 mpi_request.Header.PageVersion = MPI2_MANUFACTURING0_PAGEVERSION;
447 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
448 r = _config_request(ioc, &mpi_request, mpi_reply,
449 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
450 if (r)
451 goto out;
349 452
350/** 453 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
351 * _config_free_config_dma_memory - wrapper to free the memory 454 r = _config_request(ioc, &mpi_request, mpi_reply,
352 * @ioc: per adapter object 455 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
353 * @mem: struct config_request 456 sizeof(*config_page));
354 * 457 out:
355 * A wrapper to free dma-able memory when using _config_alloc_config_dma_memory. 458 return r;
356 *
357 * Returns 0 for success, non-zero for failure.
358 */
359static void
360_config_free_config_dma_memory(struct MPT2SAS_ADAPTER *ioc,
361 struct config_request *mem)
362{
363 pci_free_consistent(ioc->pdev, mem->config_page_sz, mem->config_page,
364 mem->config_page_dma);
365} 459}
366 460
367/** 461/**
368 * mpt2sas_config_get_manufacturing_pg0 - obtain manufacturing page 0 462 * mpt2sas_config_get_manufacturing_pg10 - obtain manufacturing page 10
369 * @ioc: per adapter object 463 * @ioc: per adapter object
370 * @mpi_reply: reply mf payload returned from firmware 464 * @mpi_reply: reply mf payload returned from firmware
371 * @config_page: contents of the config page 465 * @config_page: contents of the config page
@@ -374,53 +468,28 @@ _config_free_config_dma_memory(struct MPT2SAS_ADAPTER *ioc,
374 * Returns 0 for success, non-zero for failure. 468 * Returns 0 for success, non-zero for failure.
375 */ 469 */
376int 470int
377mpt2sas_config_get_manufacturing_pg0(struct MPT2SAS_ADAPTER *ioc, 471mpt2sas_config_get_manufacturing_pg10(struct MPT2SAS_ADAPTER *ioc,
378 Mpi2ConfigReply_t *mpi_reply, Mpi2ManufacturingPage0_t *config_page) 472 Mpi2ConfigReply_t *mpi_reply, Mpi2ManufacturingPage10_t *config_page)
379{ 473{
380 Mpi2ConfigRequest_t mpi_request; 474 Mpi2ConfigRequest_t mpi_request;
381 int r; 475 int r;
382 struct config_request mem;
383 476
384 memset(config_page, 0, sizeof(Mpi2ManufacturingPage0_t));
385 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); 477 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
386 mpi_request.Function = MPI2_FUNCTION_CONFIG; 478 mpi_request.Function = MPI2_FUNCTION_CONFIG;
387 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; 479 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
388 mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_MANUFACTURING; 480 mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_MANUFACTURING;
389 mpi_request.Header.PageNumber = 0; 481 mpi_request.Header.PageNumber = 10;
390 mpi_request.Header.PageVersion = MPI2_MANUFACTURING0_PAGEVERSION; 482 mpi_request.Header.PageVersion = MPI2_MANUFACTURING0_PAGEVERSION;
391 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); 483 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
392 r = _config_request(ioc, &mpi_request, mpi_reply, 484 r = _config_request(ioc, &mpi_request, mpi_reply,
393 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 485 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
394 if (r) 486 if (r)
395 goto out; 487 goto out;
396 488
397 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; 489 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
398 mpi_request.Header.PageVersion = mpi_reply->Header.PageVersion;
399 mpi_request.Header.PageNumber = mpi_reply->Header.PageNumber;
400 mpi_request.Header.PageType = mpi_reply->Header.PageType;
401 mpi_request.Header.PageLength = mpi_reply->Header.PageLength;
402 mem.config_page_sz = le16_to_cpu(mpi_reply->Header.PageLength) * 4;
403 if (mem.config_page_sz > ioc->config_page_sz) {
404 r = _config_alloc_config_dma_memory(ioc, &mem);
405 if (r)
406 goto out;
407 } else {
408 mem.config_page_dma = ioc->config_page_dma;
409 mem.config_page = ioc->config_page;
410 }
411 ioc->base_add_sg_single(&mpi_request.PageBufferSGE,
412 MPT2_CONFIG_COMMON_SGLFLAGS | mem.config_page_sz,
413 mem.config_page_dma);
414 r = _config_request(ioc, &mpi_request, mpi_reply, 490 r = _config_request(ioc, &mpi_request, mpi_reply,
415 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 491 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
416 if (!r) 492 sizeof(*config_page));
417 memcpy(config_page, mem.config_page,
418 min_t(u16, mem.config_page_sz,
419 sizeof(Mpi2ManufacturingPage0_t)));
420
421 if (mem.config_page_sz > ioc->config_page_sz)
422 _config_free_config_dma_memory(ioc, &mem);
423
424 out: 493 out:
425 return r; 494 return r;
426} 495}
@@ -440,9 +509,7 @@ mpt2sas_config_get_bios_pg2(struct MPT2SAS_ADAPTER *ioc,
440{ 509{
441 Mpi2ConfigRequest_t mpi_request; 510 Mpi2ConfigRequest_t mpi_request;
442 int r; 511 int r;
443 struct config_request mem;
444 512
445 memset(config_page, 0, sizeof(Mpi2BiosPage2_t));
446 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); 513 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
447 mpi_request.Function = MPI2_FUNCTION_CONFIG; 514 mpi_request.Function = MPI2_FUNCTION_CONFIG;
448 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; 515 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
@@ -451,37 +518,14 @@ mpt2sas_config_get_bios_pg2(struct MPT2SAS_ADAPTER *ioc,
451 mpi_request.Header.PageVersion = MPI2_BIOSPAGE2_PAGEVERSION; 518 mpi_request.Header.PageVersion = MPI2_BIOSPAGE2_PAGEVERSION;
452 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); 519 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
453 r = _config_request(ioc, &mpi_request, mpi_reply, 520 r = _config_request(ioc, &mpi_request, mpi_reply,
454 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 521 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
455 if (r) 522 if (r)
456 goto out; 523 goto out;
457 524
458 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; 525 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
459 mpi_request.Header.PageVersion = mpi_reply->Header.PageVersion;
460 mpi_request.Header.PageNumber = mpi_reply->Header.PageNumber;
461 mpi_request.Header.PageType = mpi_reply->Header.PageType;
462 mpi_request.Header.PageLength = mpi_reply->Header.PageLength;
463 mem.config_page_sz = le16_to_cpu(mpi_reply->Header.PageLength) * 4;
464 if (mem.config_page_sz > ioc->config_page_sz) {
465 r = _config_alloc_config_dma_memory(ioc, &mem);
466 if (r)
467 goto out;
468 } else {
469 mem.config_page_dma = ioc->config_page_dma;
470 mem.config_page = ioc->config_page;
471 }
472 ioc->base_add_sg_single(&mpi_request.PageBufferSGE,
473 MPT2_CONFIG_COMMON_SGLFLAGS | mem.config_page_sz,
474 mem.config_page_dma);
475 r = _config_request(ioc, &mpi_request, mpi_reply, 526 r = _config_request(ioc, &mpi_request, mpi_reply,
476 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 527 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
477 if (!r) 528 sizeof(*config_page));
478 memcpy(config_page, mem.config_page,
479 min_t(u16, mem.config_page_sz,
480 sizeof(Mpi2BiosPage2_t)));
481
482 if (mem.config_page_sz > ioc->config_page_sz)
483 _config_free_config_dma_memory(ioc, &mem);
484
485 out: 529 out:
486 return r; 530 return r;
487} 531}
@@ -501,9 +545,7 @@ mpt2sas_config_get_bios_pg3(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
501{ 545{
502 Mpi2ConfigRequest_t mpi_request; 546 Mpi2ConfigRequest_t mpi_request;
503 int r; 547 int r;
504 struct config_request mem;
505 548
506 memset(config_page, 0, sizeof(Mpi2BiosPage3_t));
507 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); 549 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
508 mpi_request.Function = MPI2_FUNCTION_CONFIG; 550 mpi_request.Function = MPI2_FUNCTION_CONFIG;
509 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; 551 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
@@ -512,37 +554,14 @@ mpt2sas_config_get_bios_pg3(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
512 mpi_request.Header.PageVersion = MPI2_BIOSPAGE3_PAGEVERSION; 554 mpi_request.Header.PageVersion = MPI2_BIOSPAGE3_PAGEVERSION;
513 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); 555 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
514 r = _config_request(ioc, &mpi_request, mpi_reply, 556 r = _config_request(ioc, &mpi_request, mpi_reply,
515 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 557 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
516 if (r) 558 if (r)
517 goto out; 559 goto out;
518 560
519 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; 561 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
520 mpi_request.Header.PageVersion = mpi_reply->Header.PageVersion;
521 mpi_request.Header.PageNumber = mpi_reply->Header.PageNumber;
522 mpi_request.Header.PageType = mpi_reply->Header.PageType;
523 mpi_request.Header.PageLength = mpi_reply->Header.PageLength;
524 mem.config_page_sz = le16_to_cpu(mpi_reply->Header.PageLength) * 4;
525 if (mem.config_page_sz > ioc->config_page_sz) {
526 r = _config_alloc_config_dma_memory(ioc, &mem);
527 if (r)
528 goto out;
529 } else {
530 mem.config_page_dma = ioc->config_page_dma;
531 mem.config_page = ioc->config_page;
532 }
533 ioc->base_add_sg_single(&mpi_request.PageBufferSGE,
534 MPT2_CONFIG_COMMON_SGLFLAGS | mem.config_page_sz,
535 mem.config_page_dma);
536 r = _config_request(ioc, &mpi_request, mpi_reply, 562 r = _config_request(ioc, &mpi_request, mpi_reply,
537 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 563 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
538 if (!r) 564 sizeof(*config_page));
539 memcpy(config_page, mem.config_page,
540 min_t(u16, mem.config_page_sz,
541 sizeof(Mpi2BiosPage3_t)));
542
543 if (mem.config_page_sz > ioc->config_page_sz)
544 _config_free_config_dma_memory(ioc, &mem);
545
546 out: 565 out:
547 return r; 566 return r;
548} 567}
@@ -562,9 +581,7 @@ mpt2sas_config_get_iounit_pg0(struct MPT2SAS_ADAPTER *ioc,
562{ 581{
563 Mpi2ConfigRequest_t mpi_request; 582 Mpi2ConfigRequest_t mpi_request;
564 int r; 583 int r;
565 struct config_request mem;
566 584
567 memset(config_page, 0, sizeof(Mpi2IOUnitPage0_t));
568 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); 585 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
569 mpi_request.Function = MPI2_FUNCTION_CONFIG; 586 mpi_request.Function = MPI2_FUNCTION_CONFIG;
570 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; 587 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
@@ -573,37 +590,14 @@ mpt2sas_config_get_iounit_pg0(struct MPT2SAS_ADAPTER *ioc,
573 mpi_request.Header.PageVersion = MPI2_IOUNITPAGE0_PAGEVERSION; 590 mpi_request.Header.PageVersion = MPI2_IOUNITPAGE0_PAGEVERSION;
574 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); 591 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
575 r = _config_request(ioc, &mpi_request, mpi_reply, 592 r = _config_request(ioc, &mpi_request, mpi_reply,
576 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 593 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
577 if (r) 594 if (r)
578 goto out; 595 goto out;
579 596
580 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; 597 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
581 mpi_request.Header.PageVersion = mpi_reply->Header.PageVersion;
582 mpi_request.Header.PageNumber = mpi_reply->Header.PageNumber;
583 mpi_request.Header.PageType = mpi_reply->Header.PageType;
584 mpi_request.Header.PageLength = mpi_reply->Header.PageLength;
585 mem.config_page_sz = le16_to_cpu(mpi_reply->Header.PageLength) * 4;
586 if (mem.config_page_sz > ioc->config_page_sz) {
587 r = _config_alloc_config_dma_memory(ioc, &mem);
588 if (r)
589 goto out;
590 } else {
591 mem.config_page_dma = ioc->config_page_dma;
592 mem.config_page = ioc->config_page;
593 }
594 ioc->base_add_sg_single(&mpi_request.PageBufferSGE,
595 MPT2_CONFIG_COMMON_SGLFLAGS | mem.config_page_sz,
596 mem.config_page_dma);
597 r = _config_request(ioc, &mpi_request, mpi_reply, 598 r = _config_request(ioc, &mpi_request, mpi_reply,
598 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 599 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
599 if (!r) 600 sizeof(*config_page));
600 memcpy(config_page, mem.config_page,
601 min_t(u16, mem.config_page_sz,
602 sizeof(Mpi2IOUnitPage0_t)));
603
604 if (mem.config_page_sz > ioc->config_page_sz)
605 _config_free_config_dma_memory(ioc, &mem);
606
607 out: 601 out:
608 return r; 602 return r;
609} 603}
@@ -623,9 +617,7 @@ mpt2sas_config_get_iounit_pg1(struct MPT2SAS_ADAPTER *ioc,
623{ 617{
624 Mpi2ConfigRequest_t mpi_request; 618 Mpi2ConfigRequest_t mpi_request;
625 int r; 619 int r;
626 struct config_request mem;
627 620
628 memset(config_page, 0, sizeof(Mpi2IOUnitPage1_t));
629 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); 621 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
630 mpi_request.Function = MPI2_FUNCTION_CONFIG; 622 mpi_request.Function = MPI2_FUNCTION_CONFIG;
631 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; 623 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
@@ -634,37 +626,14 @@ mpt2sas_config_get_iounit_pg1(struct MPT2SAS_ADAPTER *ioc,
634 mpi_request.Header.PageVersion = MPI2_IOUNITPAGE1_PAGEVERSION; 626 mpi_request.Header.PageVersion = MPI2_IOUNITPAGE1_PAGEVERSION;
635 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); 627 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
636 r = _config_request(ioc, &mpi_request, mpi_reply, 628 r = _config_request(ioc, &mpi_request, mpi_reply,
637 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 629 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
638 if (r) 630 if (r)
639 goto out; 631 goto out;
640 632
641 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; 633 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
642 mpi_request.Header.PageVersion = mpi_reply->Header.PageVersion;
643 mpi_request.Header.PageNumber = mpi_reply->Header.PageNumber;
644 mpi_request.Header.PageType = mpi_reply->Header.PageType;
645 mpi_request.Header.PageLength = mpi_reply->Header.PageLength;
646 mem.config_page_sz = le16_to_cpu(mpi_reply->Header.PageLength) * 4;
647 if (mem.config_page_sz > ioc->config_page_sz) {
648 r = _config_alloc_config_dma_memory(ioc, &mem);
649 if (r)
650 goto out;
651 } else {
652 mem.config_page_dma = ioc->config_page_dma;
653 mem.config_page = ioc->config_page;
654 }
655 ioc->base_add_sg_single(&mpi_request.PageBufferSGE,
656 MPT2_CONFIG_COMMON_SGLFLAGS | mem.config_page_sz,
657 mem.config_page_dma);
658 r = _config_request(ioc, &mpi_request, mpi_reply, 634 r = _config_request(ioc, &mpi_request, mpi_reply,
659 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 635 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
660 if (!r) 636 sizeof(*config_page));
661 memcpy(config_page, mem.config_page,
662 min_t(u16, mem.config_page_sz,
663 sizeof(Mpi2IOUnitPage1_t)));
664
665 if (mem.config_page_sz > ioc->config_page_sz)
666 _config_free_config_dma_memory(ioc, &mem);
667
668 out: 637 out:
669 return r; 638 return r;
670} 639}
@@ -680,11 +649,10 @@ mpt2sas_config_get_iounit_pg1(struct MPT2SAS_ADAPTER *ioc,
680 */ 649 */
681int 650int
682mpt2sas_config_set_iounit_pg1(struct MPT2SAS_ADAPTER *ioc, 651mpt2sas_config_set_iounit_pg1(struct MPT2SAS_ADAPTER *ioc,
683 Mpi2ConfigReply_t *mpi_reply, Mpi2IOUnitPage1_t config_page) 652 Mpi2ConfigReply_t *mpi_reply, Mpi2IOUnitPage1_t *config_page)
684{ 653{
685 Mpi2ConfigRequest_t mpi_request; 654 Mpi2ConfigRequest_t mpi_request;
686 int r; 655 int r;
687 struct config_request mem;
688 656
689 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); 657 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
690 mpi_request.Function = MPI2_FUNCTION_CONFIG; 658 mpi_request.Function = MPI2_FUNCTION_CONFIG;
@@ -694,38 +662,14 @@ mpt2sas_config_set_iounit_pg1(struct MPT2SAS_ADAPTER *ioc,
694 mpi_request.Header.PageVersion = MPI2_IOUNITPAGE1_PAGEVERSION; 662 mpi_request.Header.PageVersion = MPI2_IOUNITPAGE1_PAGEVERSION;
695 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); 663 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
696 r = _config_request(ioc, &mpi_request, mpi_reply, 664 r = _config_request(ioc, &mpi_request, mpi_reply,
697 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 665 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
698 if (r) 666 if (r)
699 goto out; 667 goto out;
700 668
701 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_WRITE_CURRENT; 669 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_WRITE_CURRENT;
702 mpi_request.Header.PageVersion = mpi_reply->Header.PageVersion;
703 mpi_request.Header.PageNumber = mpi_reply->Header.PageNumber;
704 mpi_request.Header.PageType = mpi_reply->Header.PageType;
705 mpi_request.Header.PageLength = mpi_reply->Header.PageLength;
706 mem.config_page_sz = le16_to_cpu(mpi_reply->Header.PageLength) * 4;
707 if (mem.config_page_sz > ioc->config_page_sz) {
708 r = _config_alloc_config_dma_memory(ioc, &mem);
709 if (r)
710 goto out;
711 } else {
712 mem.config_page_dma = ioc->config_page_dma;
713 mem.config_page = ioc->config_page;
714 }
715
716 memset(mem.config_page, 0, mem.config_page_sz);
717 memcpy(mem.config_page, &config_page,
718 sizeof(Mpi2IOUnitPage1_t));
719
720 ioc->base_add_sg_single(&mpi_request.PageBufferSGE,
721 MPT2_CONFIG_COMMON_WRITE_SGLFLAGS | mem.config_page_sz,
722 mem.config_page_dma);
723 r = _config_request(ioc, &mpi_request, mpi_reply, 670 r = _config_request(ioc, &mpi_request, mpi_reply,
724 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 671 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
725 672 sizeof(*config_page));
726 if (mem.config_page_sz > ioc->config_page_sz)
727 _config_free_config_dma_memory(ioc, &mem);
728
729 out: 673 out:
730 return r; 674 return r;
731} 675}
@@ -745,9 +689,7 @@ mpt2sas_config_get_ioc_pg8(struct MPT2SAS_ADAPTER *ioc,
745{ 689{
746 Mpi2ConfigRequest_t mpi_request; 690 Mpi2ConfigRequest_t mpi_request;
747 int r; 691 int r;
748 struct config_request mem;
749 692
750 memset(config_page, 0, sizeof(Mpi2IOCPage8_t));
751 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); 693 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
752 mpi_request.Function = MPI2_FUNCTION_CONFIG; 694 mpi_request.Function = MPI2_FUNCTION_CONFIG;
753 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; 695 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
@@ -756,37 +698,14 @@ mpt2sas_config_get_ioc_pg8(struct MPT2SAS_ADAPTER *ioc,
756 mpi_request.Header.PageVersion = MPI2_IOCPAGE8_PAGEVERSION; 698 mpi_request.Header.PageVersion = MPI2_IOCPAGE8_PAGEVERSION;
757 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); 699 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
758 r = _config_request(ioc, &mpi_request, mpi_reply, 700 r = _config_request(ioc, &mpi_request, mpi_reply,
759 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 701 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
760 if (r) 702 if (r)
761 goto out; 703 goto out;
762 704
763 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; 705 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
764 mpi_request.Header.PageVersion = mpi_reply->Header.PageVersion;
765 mpi_request.Header.PageNumber = mpi_reply->Header.PageNumber;
766 mpi_request.Header.PageType = mpi_reply->Header.PageType;
767 mpi_request.Header.PageLength = mpi_reply->Header.PageLength;
768 mem.config_page_sz = le16_to_cpu(mpi_reply->Header.PageLength) * 4;
769 if (mem.config_page_sz > ioc->config_page_sz) {
770 r = _config_alloc_config_dma_memory(ioc, &mem);
771 if (r)
772 goto out;
773 } else {
774 mem.config_page_dma = ioc->config_page_dma;
775 mem.config_page = ioc->config_page;
776 }
777 ioc->base_add_sg_single(&mpi_request.PageBufferSGE,
778 MPT2_CONFIG_COMMON_SGLFLAGS | mem.config_page_sz,
779 mem.config_page_dma);
780 r = _config_request(ioc, &mpi_request, mpi_reply, 706 r = _config_request(ioc, &mpi_request, mpi_reply,
781 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 707 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
782 if (!r) 708 sizeof(*config_page));
783 memcpy(config_page, mem.config_page,
784 min_t(u16, mem.config_page_sz,
785 sizeof(Mpi2IOCPage8_t)));
786
787 if (mem.config_page_sz > ioc->config_page_sz)
788 _config_free_config_dma_memory(ioc, &mem);
789
790 out: 709 out:
791 return r; 710 return r;
792} 711}
@@ -808,9 +727,7 @@ mpt2sas_config_get_sas_device_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
808{ 727{
809 Mpi2ConfigRequest_t mpi_request; 728 Mpi2ConfigRequest_t mpi_request;
810 int r; 729 int r;
811 struct config_request mem;
812 730
813 memset(config_page, 0, sizeof(Mpi2SasDevicePage0_t));
814 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); 731 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
815 mpi_request.Function = MPI2_FUNCTION_CONFIG; 732 mpi_request.Function = MPI2_FUNCTION_CONFIG;
816 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; 733 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
@@ -820,39 +737,15 @@ mpt2sas_config_get_sas_device_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
820 mpi_request.Header.PageNumber = 0; 737 mpi_request.Header.PageNumber = 0;
821 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); 738 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
822 r = _config_request(ioc, &mpi_request, mpi_reply, 739 r = _config_request(ioc, &mpi_request, mpi_reply,
823 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 740 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
824 if (r) 741 if (r)
825 goto out; 742 goto out;
826 743
827 mpi_request.PageAddress = cpu_to_le32(form | handle); 744 mpi_request.PageAddress = cpu_to_le32(form | handle);
828 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; 745 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
829 mpi_request.Header.PageVersion = mpi_reply->Header.PageVersion;
830 mpi_request.Header.PageNumber = mpi_reply->Header.PageNumber;
831 mpi_request.Header.PageType = mpi_reply->Header.PageType;
832 mpi_request.ExtPageLength = mpi_reply->ExtPageLength;
833 mpi_request.ExtPageType = mpi_reply->ExtPageType;
834 mem.config_page_sz = le16_to_cpu(mpi_reply->ExtPageLength) * 4;
835 if (mem.config_page_sz > ioc->config_page_sz) {
836 r = _config_alloc_config_dma_memory(ioc, &mem);
837 if (r)
838 goto out;
839 } else {
840 mem.config_page_dma = ioc->config_page_dma;
841 mem.config_page = ioc->config_page;
842 }
843 ioc->base_add_sg_single(&mpi_request.PageBufferSGE,
844 MPT2_CONFIG_COMMON_SGLFLAGS | mem.config_page_sz,
845 mem.config_page_dma);
846 r = _config_request(ioc, &mpi_request, mpi_reply, 746 r = _config_request(ioc, &mpi_request, mpi_reply,
847 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 747 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
848 if (!r) 748 sizeof(*config_page));
849 memcpy(config_page, mem.config_page,
850 min_t(u16, mem.config_page_sz,
851 sizeof(Mpi2SasDevicePage0_t)));
852
853 if (mem.config_page_sz > ioc->config_page_sz)
854 _config_free_config_dma_memory(ioc, &mem);
855
856 out: 749 out:
857 return r; 750 return r;
858} 751}
@@ -874,9 +767,7 @@ mpt2sas_config_get_sas_device_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
874{ 767{
875 Mpi2ConfigRequest_t mpi_request; 768 Mpi2ConfigRequest_t mpi_request;
876 int r; 769 int r;
877 struct config_request mem;
878 770
879 memset(config_page, 0, sizeof(Mpi2SasDevicePage1_t));
880 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); 771 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
881 mpi_request.Function = MPI2_FUNCTION_CONFIG; 772 mpi_request.Function = MPI2_FUNCTION_CONFIG;
882 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; 773 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
@@ -886,39 +777,15 @@ mpt2sas_config_get_sas_device_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
886 mpi_request.Header.PageNumber = 1; 777 mpi_request.Header.PageNumber = 1;
887 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); 778 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
888 r = _config_request(ioc, &mpi_request, mpi_reply, 779 r = _config_request(ioc, &mpi_request, mpi_reply,
889 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 780 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
890 if (r) 781 if (r)
891 goto out; 782 goto out;
892 783
893 mpi_request.PageAddress = cpu_to_le32(form | handle); 784 mpi_request.PageAddress = cpu_to_le32(form | handle);
894 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; 785 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
895 mpi_request.Header.PageVersion = mpi_reply->Header.PageVersion;
896 mpi_request.Header.PageNumber = mpi_reply->Header.PageNumber;
897 mpi_request.Header.PageType = mpi_reply->Header.PageType;
898 mpi_request.ExtPageLength = mpi_reply->ExtPageLength;
899 mpi_request.ExtPageType = mpi_reply->ExtPageType;
900 mem.config_page_sz = le16_to_cpu(mpi_reply->ExtPageLength) * 4;
901 if (mem.config_page_sz > ioc->config_page_sz) {
902 r = _config_alloc_config_dma_memory(ioc, &mem);
903 if (r)
904 goto out;
905 } else {
906 mem.config_page_dma = ioc->config_page_dma;
907 mem.config_page = ioc->config_page;
908 }
909 ioc->base_add_sg_single(&mpi_request.PageBufferSGE,
910 MPT2_CONFIG_COMMON_SGLFLAGS | mem.config_page_sz,
911 mem.config_page_dma);
912 r = _config_request(ioc, &mpi_request, mpi_reply, 786 r = _config_request(ioc, &mpi_request, mpi_reply,
913 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 787 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
914 if (!r) 788 sizeof(*config_page));
915 memcpy(config_page, mem.config_page,
916 min_t(u16, mem.config_page_sz,
917 sizeof(Mpi2SasDevicePage1_t)));
918
919 if (mem.config_page_sz > ioc->config_page_sz)
920 _config_free_config_dma_memory(ioc, &mem);
921
922 out: 789 out:
923 return r; 790 return r;
924} 791}
@@ -936,11 +803,11 @@ mpt2sas_config_get_number_hba_phys(struct MPT2SAS_ADAPTER *ioc, u8 *num_phys)
936{ 803{
937 Mpi2ConfigRequest_t mpi_request; 804 Mpi2ConfigRequest_t mpi_request;
938 int r; 805 int r;
939 struct config_request mem;
940 u16 ioc_status; 806 u16 ioc_status;
941 Mpi2ConfigReply_t mpi_reply; 807 Mpi2ConfigReply_t mpi_reply;
942 Mpi2SasIOUnitPage0_t config_page; 808 Mpi2SasIOUnitPage0_t config_page;
943 809
810 *num_phys = 0;
944 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); 811 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
945 mpi_request.Function = MPI2_FUNCTION_CONFIG; 812 mpi_request.Function = MPI2_FUNCTION_CONFIG;
946 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; 813 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
@@ -950,44 +817,20 @@ mpt2sas_config_get_number_hba_phys(struct MPT2SAS_ADAPTER *ioc, u8 *num_phys)
950 mpi_request.Header.PageVersion = MPI2_SASIOUNITPAGE0_PAGEVERSION; 817 mpi_request.Header.PageVersion = MPI2_SASIOUNITPAGE0_PAGEVERSION;
951 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); 818 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
952 r = _config_request(ioc, &mpi_request, &mpi_reply, 819 r = _config_request(ioc, &mpi_request, &mpi_reply,
953 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 820 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
954 if (r) 821 if (r)
955 goto out; 822 goto out;
956 823
957 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; 824 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
958 mpi_request.Header.PageVersion = mpi_reply.Header.PageVersion;
959 mpi_request.Header.PageNumber = mpi_reply.Header.PageNumber;
960 mpi_request.Header.PageType = mpi_reply.Header.PageType;
961 mpi_request.ExtPageLength = mpi_reply.ExtPageLength;
962 mpi_request.ExtPageType = mpi_reply.ExtPageType;
963 mem.config_page_sz = le16_to_cpu(mpi_reply.ExtPageLength) * 4;
964 if (mem.config_page_sz > ioc->config_page_sz) {
965 r = _config_alloc_config_dma_memory(ioc, &mem);
966 if (r)
967 goto out;
968 } else {
969 mem.config_page_dma = ioc->config_page_dma;
970 mem.config_page = ioc->config_page;
971 }
972 ioc->base_add_sg_single(&mpi_request.PageBufferSGE,
973 MPT2_CONFIG_COMMON_SGLFLAGS | mem.config_page_sz,
974 mem.config_page_dma);
975 r = _config_request(ioc, &mpi_request, &mpi_reply, 825 r = _config_request(ioc, &mpi_request, &mpi_reply,
976 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 826 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, &config_page,
827 sizeof(Mpi2SasIOUnitPage0_t));
977 if (!r) { 828 if (!r) {
978 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & 829 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
979 MPI2_IOCSTATUS_MASK; 830 MPI2_IOCSTATUS_MASK;
980 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) { 831 if (ioc_status == MPI2_IOCSTATUS_SUCCESS)
981 memcpy(&config_page, mem.config_page,
982 min_t(u16, mem.config_page_sz,
983 sizeof(Mpi2SasIOUnitPage0_t)));
984 *num_phys = config_page.NumPhys; 832 *num_phys = config_page.NumPhys;
985 }
986 } 833 }
987
988 if (mem.config_page_sz > ioc->config_page_sz)
989 _config_free_config_dma_memory(ioc, &mem);
990
991 out: 834 out:
992 return r; 835 return r;
993} 836}
@@ -1011,8 +854,7 @@ mpt2sas_config_get_sas_iounit_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1011{ 854{
1012 Mpi2ConfigRequest_t mpi_request; 855 Mpi2ConfigRequest_t mpi_request;
1013 int r; 856 int r;
1014 struct config_request mem; 857
1015 memset(config_page, 0, sz);
1016 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); 858 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
1017 mpi_request.Function = MPI2_FUNCTION_CONFIG; 859 mpi_request.Function = MPI2_FUNCTION_CONFIG;
1018 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; 860 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
@@ -1022,37 +864,13 @@ mpt2sas_config_get_sas_iounit_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1022 mpi_request.Header.PageVersion = MPI2_SASIOUNITPAGE0_PAGEVERSION; 864 mpi_request.Header.PageVersion = MPI2_SASIOUNITPAGE0_PAGEVERSION;
1023 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); 865 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
1024 r = _config_request(ioc, &mpi_request, mpi_reply, 866 r = _config_request(ioc, &mpi_request, mpi_reply,
1025 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 867 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
1026 if (r) 868 if (r)
1027 goto out; 869 goto out;
1028 870
1029 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; 871 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
1030 mpi_request.Header.PageVersion = mpi_reply->Header.PageVersion;
1031 mpi_request.Header.PageNumber = mpi_reply->Header.PageNumber;
1032 mpi_request.Header.PageType = mpi_reply->Header.PageType;
1033 mpi_request.ExtPageLength = mpi_reply->ExtPageLength;
1034 mpi_request.ExtPageType = mpi_reply->ExtPageType;
1035 mem.config_page_sz = le16_to_cpu(mpi_reply->ExtPageLength) * 4;
1036 if (mem.config_page_sz > ioc->config_page_sz) {
1037 r = _config_alloc_config_dma_memory(ioc, &mem);
1038 if (r)
1039 goto out;
1040 } else {
1041 mem.config_page_dma = ioc->config_page_dma;
1042 mem.config_page = ioc->config_page;
1043 }
1044 ioc->base_add_sg_single(&mpi_request.PageBufferSGE,
1045 MPT2_CONFIG_COMMON_SGLFLAGS | mem.config_page_sz,
1046 mem.config_page_dma);
1047 r = _config_request(ioc, &mpi_request, mpi_reply, 872 r = _config_request(ioc, &mpi_request, mpi_reply,
1048 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 873 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sz);
1049 if (!r)
1050 memcpy(config_page, mem.config_page,
1051 min_t(u16, sz, mem.config_page_sz));
1052
1053 if (mem.config_page_sz > ioc->config_page_sz)
1054 _config_free_config_dma_memory(ioc, &mem);
1055
1056 out: 874 out:
1057 return r; 875 return r;
1058} 876}
@@ -1076,9 +894,7 @@ mpt2sas_config_get_sas_iounit_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1076{ 894{
1077 Mpi2ConfigRequest_t mpi_request; 895 Mpi2ConfigRequest_t mpi_request;
1078 int r; 896 int r;
1079 struct config_request mem;
1080 897
1081 memset(config_page, 0, sz);
1082 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); 898 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
1083 mpi_request.Function = MPI2_FUNCTION_CONFIG; 899 mpi_request.Function = MPI2_FUNCTION_CONFIG;
1084 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; 900 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
@@ -1088,37 +904,13 @@ mpt2sas_config_get_sas_iounit_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1088 mpi_request.Header.PageVersion = MPI2_SASIOUNITPAGE0_PAGEVERSION; 904 mpi_request.Header.PageVersion = MPI2_SASIOUNITPAGE0_PAGEVERSION;
1089 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); 905 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
1090 r = _config_request(ioc, &mpi_request, mpi_reply, 906 r = _config_request(ioc, &mpi_request, mpi_reply,
1091 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 907 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
1092 if (r) 908 if (r)
1093 goto out; 909 goto out;
1094 910
1095 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; 911 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
1096 mpi_request.Header.PageVersion = mpi_reply->Header.PageVersion;
1097 mpi_request.Header.PageNumber = mpi_reply->Header.PageNumber;
1098 mpi_request.Header.PageType = mpi_reply->Header.PageType;
1099 mpi_request.ExtPageLength = mpi_reply->ExtPageLength;
1100 mpi_request.ExtPageType = mpi_reply->ExtPageType;
1101 mem.config_page_sz = le16_to_cpu(mpi_reply->ExtPageLength) * 4;
1102 if (mem.config_page_sz > ioc->config_page_sz) {
1103 r = _config_alloc_config_dma_memory(ioc, &mem);
1104 if (r)
1105 goto out;
1106 } else {
1107 mem.config_page_dma = ioc->config_page_dma;
1108 mem.config_page = ioc->config_page;
1109 }
1110 ioc->base_add_sg_single(&mpi_request.PageBufferSGE,
1111 MPT2_CONFIG_COMMON_SGLFLAGS | mem.config_page_sz,
1112 mem.config_page_dma);
1113 r = _config_request(ioc, &mpi_request, mpi_reply, 912 r = _config_request(ioc, &mpi_request, mpi_reply,
1114 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 913 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sz);
1115 if (!r)
1116 memcpy(config_page, mem.config_page,
1117 min_t(u16, sz, mem.config_page_sz));
1118
1119 if (mem.config_page_sz > ioc->config_page_sz)
1120 _config_free_config_dma_memory(ioc, &mem);
1121
1122 out: 914 out:
1123 return r; 915 return r;
1124} 916}
@@ -1140,9 +932,7 @@ mpt2sas_config_get_expander_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1140{ 932{
1141 Mpi2ConfigRequest_t mpi_request; 933 Mpi2ConfigRequest_t mpi_request;
1142 int r; 934 int r;
1143 struct config_request mem;
1144 935
1145 memset(config_page, 0, sizeof(Mpi2ExpanderPage0_t));
1146 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); 936 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
1147 mpi_request.Function = MPI2_FUNCTION_CONFIG; 937 mpi_request.Function = MPI2_FUNCTION_CONFIG;
1148 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; 938 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
@@ -1152,39 +942,15 @@ mpt2sas_config_get_expander_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1152 mpi_request.Header.PageVersion = MPI2_SASEXPANDER0_PAGEVERSION; 942 mpi_request.Header.PageVersion = MPI2_SASEXPANDER0_PAGEVERSION;
1153 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); 943 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
1154 r = _config_request(ioc, &mpi_request, mpi_reply, 944 r = _config_request(ioc, &mpi_request, mpi_reply,
1155 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 945 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
1156 if (r) 946 if (r)
1157 goto out; 947 goto out;
1158 948
1159 mpi_request.PageAddress = cpu_to_le32(form | handle); 949 mpi_request.PageAddress = cpu_to_le32(form | handle);
1160 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; 950 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
1161 mpi_request.Header.PageVersion = mpi_reply->Header.PageVersion;
1162 mpi_request.Header.PageNumber = mpi_reply->Header.PageNumber;
1163 mpi_request.Header.PageType = mpi_reply->Header.PageType;
1164 mpi_request.ExtPageLength = mpi_reply->ExtPageLength;
1165 mpi_request.ExtPageType = mpi_reply->ExtPageType;
1166 mem.config_page_sz = le16_to_cpu(mpi_reply->ExtPageLength) * 4;
1167 if (mem.config_page_sz > ioc->config_page_sz) {
1168 r = _config_alloc_config_dma_memory(ioc, &mem);
1169 if (r)
1170 goto out;
1171 } else {
1172 mem.config_page_dma = ioc->config_page_dma;
1173 mem.config_page = ioc->config_page;
1174 }
1175 ioc->base_add_sg_single(&mpi_request.PageBufferSGE,
1176 MPT2_CONFIG_COMMON_SGLFLAGS | mem.config_page_sz,
1177 mem.config_page_dma);
1178 r = _config_request(ioc, &mpi_request, mpi_reply, 951 r = _config_request(ioc, &mpi_request, mpi_reply,
1179 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 952 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
1180 if (!r) 953 sizeof(*config_page));
1181 memcpy(config_page, mem.config_page,
1182 min_t(u16, mem.config_page_sz,
1183 sizeof(Mpi2ExpanderPage0_t)));
1184
1185 if (mem.config_page_sz > ioc->config_page_sz)
1186 _config_free_config_dma_memory(ioc, &mem);
1187
1188 out: 954 out:
1189 return r; 955 return r;
1190} 956}
@@ -1207,9 +973,7 @@ mpt2sas_config_get_expander_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1207{ 973{
1208 Mpi2ConfigRequest_t mpi_request; 974 Mpi2ConfigRequest_t mpi_request;
1209 int r; 975 int r;
1210 struct config_request mem;
1211 976
1212 memset(config_page, 0, sizeof(Mpi2ExpanderPage1_t));
1213 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); 977 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
1214 mpi_request.Function = MPI2_FUNCTION_CONFIG; 978 mpi_request.Function = MPI2_FUNCTION_CONFIG;
1215 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; 979 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
@@ -1219,7 +983,7 @@ mpt2sas_config_get_expander_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1219 mpi_request.Header.PageVersion = MPI2_SASEXPANDER1_PAGEVERSION; 983 mpi_request.Header.PageVersion = MPI2_SASEXPANDER1_PAGEVERSION;
1220 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); 984 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
1221 r = _config_request(ioc, &mpi_request, mpi_reply, 985 r = _config_request(ioc, &mpi_request, mpi_reply,
1222 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 986 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
1223 if (r) 987 if (r)
1224 goto out; 988 goto out;
1225 989
@@ -1227,33 +991,9 @@ mpt2sas_config_get_expander_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1227 cpu_to_le32(MPI2_SAS_EXPAND_PGAD_FORM_HNDL_PHY_NUM | 991 cpu_to_le32(MPI2_SAS_EXPAND_PGAD_FORM_HNDL_PHY_NUM |
1228 (phy_number << MPI2_SAS_EXPAND_PGAD_PHYNUM_SHIFT) | handle); 992 (phy_number << MPI2_SAS_EXPAND_PGAD_PHYNUM_SHIFT) | handle);
1229 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; 993 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
1230 mpi_request.Header.PageVersion = mpi_reply->Header.PageVersion;
1231 mpi_request.Header.PageNumber = mpi_reply->Header.PageNumber;
1232 mpi_request.Header.PageType = mpi_reply->Header.PageType;
1233 mpi_request.ExtPageLength = mpi_reply->ExtPageLength;
1234 mpi_request.ExtPageType = mpi_reply->ExtPageType;
1235 mem.config_page_sz = le16_to_cpu(mpi_reply->ExtPageLength) * 4;
1236 if (mem.config_page_sz > ioc->config_page_sz) {
1237 r = _config_alloc_config_dma_memory(ioc, &mem);
1238 if (r)
1239 goto out;
1240 } else {
1241 mem.config_page_dma = ioc->config_page_dma;
1242 mem.config_page = ioc->config_page;
1243 }
1244 ioc->base_add_sg_single(&mpi_request.PageBufferSGE,
1245 MPT2_CONFIG_COMMON_SGLFLAGS | mem.config_page_sz,
1246 mem.config_page_dma);
1247 r = _config_request(ioc, &mpi_request, mpi_reply, 994 r = _config_request(ioc, &mpi_request, mpi_reply,
1248 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 995 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
1249 if (!r) 996 sizeof(*config_page));
1250 memcpy(config_page, mem.config_page,
1251 min_t(u16, mem.config_page_sz,
1252 sizeof(Mpi2ExpanderPage1_t)));
1253
1254 if (mem.config_page_sz > ioc->config_page_sz)
1255 _config_free_config_dma_memory(ioc, &mem);
1256
1257 out: 997 out:
1258 return r; 998 return r;
1259} 999}
@@ -1275,9 +1015,7 @@ mpt2sas_config_get_enclosure_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1275{ 1015{
1276 Mpi2ConfigRequest_t mpi_request; 1016 Mpi2ConfigRequest_t mpi_request;
1277 int r; 1017 int r;
1278 struct config_request mem;
1279 1018
1280 memset(config_page, 0, sizeof(Mpi2SasEnclosurePage0_t));
1281 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); 1019 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
1282 mpi_request.Function = MPI2_FUNCTION_CONFIG; 1020 mpi_request.Function = MPI2_FUNCTION_CONFIG;
1283 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; 1021 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
@@ -1287,39 +1025,15 @@ mpt2sas_config_get_enclosure_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1287 mpi_request.Header.PageVersion = MPI2_SASENCLOSURE0_PAGEVERSION; 1025 mpi_request.Header.PageVersion = MPI2_SASENCLOSURE0_PAGEVERSION;
1288 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); 1026 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
1289 r = _config_request(ioc, &mpi_request, mpi_reply, 1027 r = _config_request(ioc, &mpi_request, mpi_reply,
1290 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 1028 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
1291 if (r) 1029 if (r)
1292 goto out; 1030 goto out;
1293 1031
1294 mpi_request.PageAddress = cpu_to_le32(form | handle); 1032 mpi_request.PageAddress = cpu_to_le32(form | handle);
1295 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; 1033 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
1296 mpi_request.Header.PageVersion = mpi_reply->Header.PageVersion;
1297 mpi_request.Header.PageNumber = mpi_reply->Header.PageNumber;
1298 mpi_request.Header.PageType = mpi_reply->Header.PageType;
1299 mpi_request.ExtPageLength = mpi_reply->ExtPageLength;
1300 mpi_request.ExtPageType = mpi_reply->ExtPageType;
1301 mem.config_page_sz = le16_to_cpu(mpi_reply->ExtPageLength) * 4;
1302 if (mem.config_page_sz > ioc->config_page_sz) {
1303 r = _config_alloc_config_dma_memory(ioc, &mem);
1304 if (r)
1305 goto out;
1306 } else {
1307 mem.config_page_dma = ioc->config_page_dma;
1308 mem.config_page = ioc->config_page;
1309 }
1310 ioc->base_add_sg_single(&mpi_request.PageBufferSGE,
1311 MPT2_CONFIG_COMMON_SGLFLAGS | mem.config_page_sz,
1312 mem.config_page_dma);
1313 r = _config_request(ioc, &mpi_request, mpi_reply, 1034 r = _config_request(ioc, &mpi_request, mpi_reply,
1314 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 1035 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
1315 if (!r) 1036 sizeof(*config_page));
1316 memcpy(config_page, mem.config_page,
1317 min_t(u16, mem.config_page_sz,
1318 sizeof(Mpi2SasEnclosurePage0_t)));
1319
1320 if (mem.config_page_sz > ioc->config_page_sz)
1321 _config_free_config_dma_memory(ioc, &mem);
1322
1323 out: 1037 out:
1324 return r; 1038 return r;
1325} 1039}
@@ -1340,9 +1054,7 @@ mpt2sas_config_get_phy_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1340{ 1054{
1341 Mpi2ConfigRequest_t mpi_request; 1055 Mpi2ConfigRequest_t mpi_request;
1342 int r; 1056 int r;
1343 struct config_request mem;
1344 1057
1345 memset(config_page, 0, sizeof(Mpi2SasPhyPage0_t));
1346 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); 1058 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
1347 mpi_request.Function = MPI2_FUNCTION_CONFIG; 1059 mpi_request.Function = MPI2_FUNCTION_CONFIG;
1348 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; 1060 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
@@ -1352,40 +1064,16 @@ mpt2sas_config_get_phy_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1352 mpi_request.Header.PageVersion = MPI2_SASPHY0_PAGEVERSION; 1064 mpi_request.Header.PageVersion = MPI2_SASPHY0_PAGEVERSION;
1353 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); 1065 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
1354 r = _config_request(ioc, &mpi_request, mpi_reply, 1066 r = _config_request(ioc, &mpi_request, mpi_reply,
1355 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 1067 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
1356 if (r) 1068 if (r)
1357 goto out; 1069 goto out;
1358 1070
1359 mpi_request.PageAddress = 1071 mpi_request.PageAddress =
1360 cpu_to_le32(MPI2_SAS_PHY_PGAD_FORM_PHY_NUMBER | phy_number); 1072 cpu_to_le32(MPI2_SAS_PHY_PGAD_FORM_PHY_NUMBER | phy_number);
1361 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; 1073 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
1362 mpi_request.Header.PageVersion = mpi_reply->Header.PageVersion;
1363 mpi_request.Header.PageNumber = mpi_reply->Header.PageNumber;
1364 mpi_request.Header.PageType = mpi_reply->Header.PageType;
1365 mpi_request.ExtPageLength = mpi_reply->ExtPageLength;
1366 mpi_request.ExtPageType = mpi_reply->ExtPageType;
1367 mem.config_page_sz = le16_to_cpu(mpi_reply->ExtPageLength) * 4;
1368 if (mem.config_page_sz > ioc->config_page_sz) {
1369 r = _config_alloc_config_dma_memory(ioc, &mem);
1370 if (r)
1371 goto out;
1372 } else {
1373 mem.config_page_dma = ioc->config_page_dma;
1374 mem.config_page = ioc->config_page;
1375 }
1376 ioc->base_add_sg_single(&mpi_request.PageBufferSGE,
1377 MPT2_CONFIG_COMMON_SGLFLAGS | mem.config_page_sz,
1378 mem.config_page_dma);
1379 r = _config_request(ioc, &mpi_request, mpi_reply, 1074 r = _config_request(ioc, &mpi_request, mpi_reply,
1380 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 1075 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
1381 if (!r) 1076 sizeof(*config_page));
1382 memcpy(config_page, mem.config_page,
1383 min_t(u16, mem.config_page_sz,
1384 sizeof(Mpi2SasPhyPage0_t)));
1385
1386 if (mem.config_page_sz > ioc->config_page_sz)
1387 _config_free_config_dma_memory(ioc, &mem);
1388
1389 out: 1077 out:
1390 return r; 1078 return r;
1391} 1079}
@@ -1406,9 +1094,7 @@ mpt2sas_config_get_phy_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1406{ 1094{
1407 Mpi2ConfigRequest_t mpi_request; 1095 Mpi2ConfigRequest_t mpi_request;
1408 int r; 1096 int r;
1409 struct config_request mem;
1410 1097
1411 memset(config_page, 0, sizeof(Mpi2SasPhyPage1_t));
1412 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); 1098 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
1413 mpi_request.Function = MPI2_FUNCTION_CONFIG; 1099 mpi_request.Function = MPI2_FUNCTION_CONFIG;
1414 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; 1100 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
@@ -1418,40 +1104,16 @@ mpt2sas_config_get_phy_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1418 mpi_request.Header.PageVersion = MPI2_SASPHY1_PAGEVERSION; 1104 mpi_request.Header.PageVersion = MPI2_SASPHY1_PAGEVERSION;
1419 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); 1105 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
1420 r = _config_request(ioc, &mpi_request, mpi_reply, 1106 r = _config_request(ioc, &mpi_request, mpi_reply,
1421 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 1107 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
1422 if (r) 1108 if (r)
1423 goto out; 1109 goto out;
1424 1110
1425 mpi_request.PageAddress = 1111 mpi_request.PageAddress =
1426 cpu_to_le32(MPI2_SAS_PHY_PGAD_FORM_PHY_NUMBER | phy_number); 1112 cpu_to_le32(MPI2_SAS_PHY_PGAD_FORM_PHY_NUMBER | phy_number);
1427 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; 1113 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
1428 mpi_request.Header.PageVersion = mpi_reply->Header.PageVersion;
1429 mpi_request.Header.PageNumber = mpi_reply->Header.PageNumber;
1430 mpi_request.Header.PageType = mpi_reply->Header.PageType;
1431 mpi_request.ExtPageLength = mpi_reply->ExtPageLength;
1432 mpi_request.ExtPageType = mpi_reply->ExtPageType;
1433 mem.config_page_sz = le16_to_cpu(mpi_reply->ExtPageLength) * 4;
1434 if (mem.config_page_sz > ioc->config_page_sz) {
1435 r = _config_alloc_config_dma_memory(ioc, &mem);
1436 if (r)
1437 goto out;
1438 } else {
1439 mem.config_page_dma = ioc->config_page_dma;
1440 mem.config_page = ioc->config_page;
1441 }
1442 ioc->base_add_sg_single(&mpi_request.PageBufferSGE,
1443 MPT2_CONFIG_COMMON_SGLFLAGS | mem.config_page_sz,
1444 mem.config_page_dma);
1445 r = _config_request(ioc, &mpi_request, mpi_reply, 1114 r = _config_request(ioc, &mpi_request, mpi_reply,
1446 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 1115 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
1447 if (!r) 1116 sizeof(*config_page));
1448 memcpy(config_page, mem.config_page,
1449 min_t(u16, mem.config_page_sz,
1450 sizeof(Mpi2SasPhyPage1_t)));
1451
1452 if (mem.config_page_sz > ioc->config_page_sz)
1453 _config_free_config_dma_memory(ioc, &mem);
1454
1455 out: 1117 out:
1456 return r; 1118 return r;
1457} 1119}
@@ -1474,9 +1136,7 @@ mpt2sas_config_get_raid_volume_pg1(struct MPT2SAS_ADAPTER *ioc,
1474{ 1136{
1475 Mpi2ConfigRequest_t mpi_request; 1137 Mpi2ConfigRequest_t mpi_request;
1476 int r; 1138 int r;
1477 struct config_request mem;
1478 1139
1479 memset(config_page, 0, sizeof(Mpi2RaidVolPage1_t));
1480 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); 1140 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
1481 mpi_request.Function = MPI2_FUNCTION_CONFIG; 1141 mpi_request.Function = MPI2_FUNCTION_CONFIG;
1482 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; 1142 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
@@ -1485,38 +1145,15 @@ mpt2sas_config_get_raid_volume_pg1(struct MPT2SAS_ADAPTER *ioc,
1485 mpi_request.Header.PageVersion = MPI2_RAIDVOLPAGE1_PAGEVERSION; 1145 mpi_request.Header.PageVersion = MPI2_RAIDVOLPAGE1_PAGEVERSION;
1486 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); 1146 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
1487 r = _config_request(ioc, &mpi_request, mpi_reply, 1147 r = _config_request(ioc, &mpi_request, mpi_reply,
1488 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 1148 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
1489 if (r) 1149 if (r)
1490 goto out; 1150 goto out;
1491 1151
1492 mpi_request.PageAddress = cpu_to_le32(form | handle); 1152 mpi_request.PageAddress = cpu_to_le32(form | handle);
1493 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; 1153 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
1494 mpi_request.Header.PageVersion = mpi_reply->Header.PageVersion;
1495 mpi_request.Header.PageNumber = mpi_reply->Header.PageNumber;
1496 mpi_request.Header.PageType = mpi_reply->Header.PageType;
1497 mpi_request.Header.PageLength = mpi_reply->Header.PageLength;
1498 mem.config_page_sz = le16_to_cpu(mpi_reply->Header.PageLength) * 4;
1499 if (mem.config_page_sz > ioc->config_page_sz) {
1500 r = _config_alloc_config_dma_memory(ioc, &mem);
1501 if (r)
1502 goto out;
1503 } else {
1504 mem.config_page_dma = ioc->config_page_dma;
1505 mem.config_page = ioc->config_page;
1506 }
1507 ioc->base_add_sg_single(&mpi_request.PageBufferSGE,
1508 MPT2_CONFIG_COMMON_SGLFLAGS | mem.config_page_sz,
1509 mem.config_page_dma);
1510 r = _config_request(ioc, &mpi_request, mpi_reply, 1154 r = _config_request(ioc, &mpi_request, mpi_reply,
1511 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 1155 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
1512 if (!r) 1156 sizeof(*config_page));
1513 memcpy(config_page, mem.config_page,
1514 min_t(u16, mem.config_page_sz,
1515 sizeof(Mpi2RaidVolPage1_t)));
1516
1517 if (mem.config_page_sz > ioc->config_page_sz)
1518 _config_free_config_dma_memory(ioc, &mem);
1519
1520 out: 1157 out:
1521 return r; 1158 return r;
1522} 1159}
@@ -1535,10 +1172,9 @@ mpt2sas_config_get_number_pds(struct MPT2SAS_ADAPTER *ioc, u16 handle,
1535 u8 *num_pds) 1172 u8 *num_pds)
1536{ 1173{
1537 Mpi2ConfigRequest_t mpi_request; 1174 Mpi2ConfigRequest_t mpi_request;
1538 Mpi2RaidVolPage0_t *config_page; 1175 Mpi2RaidVolPage0_t config_page;
1539 Mpi2ConfigReply_t mpi_reply; 1176 Mpi2ConfigReply_t mpi_reply;
1540 int r; 1177 int r;
1541 struct config_request mem;
1542 u16 ioc_status; 1178 u16 ioc_status;
1543 1179
1544 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); 1180 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
@@ -1550,43 +1186,23 @@ mpt2sas_config_get_number_pds(struct MPT2SAS_ADAPTER *ioc, u16 handle,
1550 mpi_request.Header.PageVersion = MPI2_RAIDVOLPAGE0_PAGEVERSION; 1186 mpi_request.Header.PageVersion = MPI2_RAIDVOLPAGE0_PAGEVERSION;
1551 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); 1187 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
1552 r = _config_request(ioc, &mpi_request, &mpi_reply, 1188 r = _config_request(ioc, &mpi_request, &mpi_reply,
1553 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 1189 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
1554 if (r) 1190 if (r)
1555 goto out; 1191 goto out;
1556 1192
1557 mpi_request.PageAddress = 1193 mpi_request.PageAddress =
1558 cpu_to_le32(MPI2_RAID_VOLUME_PGAD_FORM_HANDLE | handle); 1194 cpu_to_le32(MPI2_RAID_VOLUME_PGAD_FORM_HANDLE | handle);
1559 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; 1195 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
1560 mpi_request.Header.PageVersion = mpi_reply.Header.PageVersion;
1561 mpi_request.Header.PageNumber = mpi_reply.Header.PageNumber;
1562 mpi_request.Header.PageType = mpi_reply.Header.PageType;
1563 mpi_request.Header.PageLength = mpi_reply.Header.PageLength;
1564 mem.config_page_sz = le16_to_cpu(mpi_reply.Header.PageLength) * 4;
1565 if (mem.config_page_sz > ioc->config_page_sz) {
1566 r = _config_alloc_config_dma_memory(ioc, &mem);
1567 if (r)
1568 goto out;
1569 } else {
1570 mem.config_page_dma = ioc->config_page_dma;
1571 mem.config_page = ioc->config_page;
1572 }
1573 ioc->base_add_sg_single(&mpi_request.PageBufferSGE,
1574 MPT2_CONFIG_COMMON_SGLFLAGS | mem.config_page_sz,
1575 mem.config_page_dma);
1576 r = _config_request(ioc, &mpi_request, &mpi_reply, 1196 r = _config_request(ioc, &mpi_request, &mpi_reply,
1577 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 1197 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, &config_page,
1198 sizeof(Mpi2RaidVolPage0_t));
1578 if (!r) { 1199 if (!r) {
1579 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & 1200 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1580 MPI2_IOCSTATUS_MASK; 1201 MPI2_IOCSTATUS_MASK;
1581 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) { 1202 if (ioc_status == MPI2_IOCSTATUS_SUCCESS)
1582 config_page = mem.config_page; 1203 *num_pds = config_page.NumPhysDisks;
1583 *num_pds = config_page->NumPhysDisks;
1584 }
1585 } 1204 }
1586 1205
1587 if (mem.config_page_sz > ioc->config_page_sz)
1588 _config_free_config_dma_memory(ioc, &mem);
1589
1590 out: 1206 out:
1591 return r; 1207 return r;
1592} 1208}
@@ -1610,10 +1226,8 @@ mpt2sas_config_get_raid_volume_pg0(struct MPT2SAS_ADAPTER *ioc,
1610{ 1226{
1611 Mpi2ConfigRequest_t mpi_request; 1227 Mpi2ConfigRequest_t mpi_request;
1612 int r; 1228 int r;
1613 struct config_request mem;
1614 1229
1615 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); 1230 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
1616 memset(config_page, 0, sz);
1617 mpi_request.Function = MPI2_FUNCTION_CONFIG; 1231 mpi_request.Function = MPI2_FUNCTION_CONFIG;
1618 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; 1232 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
1619 mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_RAID_VOLUME; 1233 mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_RAID_VOLUME;
@@ -1621,37 +1235,14 @@ mpt2sas_config_get_raid_volume_pg0(struct MPT2SAS_ADAPTER *ioc,
1621 mpi_request.Header.PageVersion = MPI2_RAIDVOLPAGE0_PAGEVERSION; 1235 mpi_request.Header.PageVersion = MPI2_RAIDVOLPAGE0_PAGEVERSION;
1622 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); 1236 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
1623 r = _config_request(ioc, &mpi_request, mpi_reply, 1237 r = _config_request(ioc, &mpi_request, mpi_reply,
1624 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 1238 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
1625 if (r) 1239 if (r)
1626 goto out; 1240 goto out;
1627 1241
1628 mpi_request.PageAddress = cpu_to_le32(form | handle); 1242 mpi_request.PageAddress = cpu_to_le32(form | handle);
1629 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; 1243 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
1630 mpi_request.Header.PageVersion = mpi_reply->Header.PageVersion;
1631 mpi_request.Header.PageNumber = mpi_reply->Header.PageNumber;
1632 mpi_request.Header.PageType = mpi_reply->Header.PageType;
1633 mpi_request.Header.PageLength = mpi_reply->Header.PageLength;
1634 mem.config_page_sz = le16_to_cpu(mpi_reply->Header.PageLength) * 4;
1635 if (mem.config_page_sz > ioc->config_page_sz) {
1636 r = _config_alloc_config_dma_memory(ioc, &mem);
1637 if (r)
1638 goto out;
1639 } else {
1640 mem.config_page_dma = ioc->config_page_dma;
1641 mem.config_page = ioc->config_page;
1642 }
1643 ioc->base_add_sg_single(&mpi_request.PageBufferSGE,
1644 MPT2_CONFIG_COMMON_SGLFLAGS | mem.config_page_sz,
1645 mem.config_page_dma);
1646 r = _config_request(ioc, &mpi_request, mpi_reply, 1244 r = _config_request(ioc, &mpi_request, mpi_reply,
1647 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 1245 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sz);
1648 if (!r)
1649 memcpy(config_page, mem.config_page,
1650 min_t(u16, sz, mem.config_page_sz));
1651
1652 if (mem.config_page_sz > ioc->config_page_sz)
1653 _config_free_config_dma_memory(ioc, &mem);
1654
1655 out: 1246 out:
1656 return r; 1247 return r;
1657} 1248}
@@ -1674,10 +1265,8 @@ mpt2sas_config_get_phys_disk_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1674{ 1265{
1675 Mpi2ConfigRequest_t mpi_request; 1266 Mpi2ConfigRequest_t mpi_request;
1676 int r; 1267 int r;
1677 struct config_request mem;
1678 1268
1679 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); 1269 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
1680 memset(config_page, 0, sizeof(Mpi2RaidPhysDiskPage0_t));
1681 mpi_request.Function = MPI2_FUNCTION_CONFIG; 1270 mpi_request.Function = MPI2_FUNCTION_CONFIG;
1682 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; 1271 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
1683 mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_RAID_PHYSDISK; 1272 mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_RAID_PHYSDISK;
@@ -1685,38 +1274,15 @@ mpt2sas_config_get_phys_disk_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1685 mpi_request.Header.PageVersion = MPI2_RAIDPHYSDISKPAGE0_PAGEVERSION; 1274 mpi_request.Header.PageVersion = MPI2_RAIDPHYSDISKPAGE0_PAGEVERSION;
1686 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); 1275 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
1687 r = _config_request(ioc, &mpi_request, mpi_reply, 1276 r = _config_request(ioc, &mpi_request, mpi_reply,
1688 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 1277 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
1689 if (r) 1278 if (r)
1690 goto out; 1279 goto out;
1691 1280
1692 mpi_request.PageAddress = cpu_to_le32(form | form_specific); 1281 mpi_request.PageAddress = cpu_to_le32(form | form_specific);
1693 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; 1282 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
1694 mpi_request.Header.PageVersion = mpi_reply->Header.PageVersion;
1695 mpi_request.Header.PageNumber = mpi_reply->Header.PageNumber;
1696 mpi_request.Header.PageType = mpi_reply->Header.PageType;
1697 mpi_request.Header.PageLength = mpi_reply->Header.PageLength;
1698 mem.config_page_sz = le16_to_cpu(mpi_reply->Header.PageLength) * 4;
1699 if (mem.config_page_sz > ioc->config_page_sz) {
1700 r = _config_alloc_config_dma_memory(ioc, &mem);
1701 if (r)
1702 goto out;
1703 } else {
1704 mem.config_page_dma = ioc->config_page_dma;
1705 mem.config_page = ioc->config_page;
1706 }
1707 ioc->base_add_sg_single(&mpi_request.PageBufferSGE,
1708 MPT2_CONFIG_COMMON_SGLFLAGS | mem.config_page_sz,
1709 mem.config_page_dma);
1710 r = _config_request(ioc, &mpi_request, mpi_reply, 1283 r = _config_request(ioc, &mpi_request, mpi_reply,
1711 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 1284 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
1712 if (!r) 1285 sizeof(*config_page));
1713 memcpy(config_page, mem.config_page,
1714 min_t(u16, mem.config_page_sz,
1715 sizeof(Mpi2RaidPhysDiskPage0_t)));
1716
1717 if (mem.config_page_sz > ioc->config_page_sz)
1718 _config_free_config_dma_memory(ioc, &mem);
1719
1720 out: 1286 out:
1721 return r; 1287 return r;
1722} 1288}
@@ -1734,11 +1300,10 @@ int
1734mpt2sas_config_get_volume_handle(struct MPT2SAS_ADAPTER *ioc, u16 pd_handle, 1300mpt2sas_config_get_volume_handle(struct MPT2SAS_ADAPTER *ioc, u16 pd_handle,
1735 u16 *volume_handle) 1301 u16 *volume_handle)
1736{ 1302{
1737 Mpi2RaidConfigurationPage0_t *config_page; 1303 Mpi2RaidConfigurationPage0_t *config_page = NULL;
1738 Mpi2ConfigRequest_t mpi_request; 1304 Mpi2ConfigRequest_t mpi_request;
1739 Mpi2ConfigReply_t mpi_reply; 1305 Mpi2ConfigReply_t mpi_reply;
1740 int r, i; 1306 int r, i, config_page_sz;
1741 struct config_request mem;
1742 u16 ioc_status; 1307 u16 ioc_status;
1743 1308
1744 *volume_handle = 0; 1309 *volume_handle = 0;
@@ -1751,40 +1316,27 @@ mpt2sas_config_get_volume_handle(struct MPT2SAS_ADAPTER *ioc, u16 pd_handle,
1751 mpi_request.Header.PageNumber = 0; 1316 mpi_request.Header.PageNumber = 0;
1752 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); 1317 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
1753 r = _config_request(ioc, &mpi_request, &mpi_reply, 1318 r = _config_request(ioc, &mpi_request, &mpi_reply,
1754 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 1319 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
1755 if (r) 1320 if (r)
1756 goto out; 1321 goto out;
1757 1322
1758 mpi_request.PageAddress = 1323 mpi_request.PageAddress =
1759 cpu_to_le32(MPI2_RAID_PGAD_FORM_ACTIVE_CONFIG); 1324 cpu_to_le32(MPI2_RAID_PGAD_FORM_ACTIVE_CONFIG);
1760 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; 1325 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
1761 mpi_request.Header.PageVersion = mpi_reply.Header.PageVersion; 1326 config_page_sz = (le16_to_cpu(mpi_reply.ExtPageLength) * 4);
1762 mpi_request.Header.PageNumber = mpi_reply.Header.PageNumber; 1327 config_page = kmalloc(config_page_sz, GFP_KERNEL);
1763 mpi_request.Header.PageType = mpi_reply.Header.PageType; 1328 if (!config_page)
1764 mpi_request.ExtPageLength = mpi_reply.ExtPageLength; 1329 goto out;
1765 mpi_request.ExtPageType = mpi_reply.ExtPageType;
1766 mem.config_page_sz = le16_to_cpu(mpi_reply.ExtPageLength) * 4;
1767 if (mem.config_page_sz > ioc->config_page_sz) {
1768 r = _config_alloc_config_dma_memory(ioc, &mem);
1769 if (r)
1770 goto out;
1771 } else {
1772 mem.config_page_dma = ioc->config_page_dma;
1773 mem.config_page = ioc->config_page;
1774 }
1775 ioc->base_add_sg_single(&mpi_request.PageBufferSGE,
1776 MPT2_CONFIG_COMMON_SGLFLAGS | mem.config_page_sz,
1777 mem.config_page_dma);
1778 r = _config_request(ioc, &mpi_request, &mpi_reply, 1330 r = _config_request(ioc, &mpi_request, &mpi_reply,
1779 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT); 1331 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
1332 config_page_sz);
1780 if (r) 1333 if (r)
1781 goto out; 1334 goto out;
1782 1335
1783 r = -1; 1336 r = -1;
1784 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; 1337 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
1785 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) 1338 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
1786 goto done; 1339 goto out;
1787 config_page = mem.config_page;
1788 for (i = 0; i < config_page->NumElements; i++) { 1340 for (i = 0; i < config_page->NumElements; i++) {
1789 if ((config_page->ConfigElement[i].ElementFlags & 1341 if ((config_page->ConfigElement[i].ElementFlags &
1790 MPI2_RAIDCONFIG0_EFLAGS_MASK_ELEMENT_TYPE) != 1342 MPI2_RAIDCONFIG0_EFLAGS_MASK_ELEMENT_TYPE) !=
@@ -1795,15 +1347,11 @@ mpt2sas_config_get_volume_handle(struct MPT2SAS_ADAPTER *ioc, u16 pd_handle,
1795 *volume_handle = le16_to_cpu(config_page-> 1347 *volume_handle = le16_to_cpu(config_page->
1796 ConfigElement[i].VolDevHandle); 1348 ConfigElement[i].VolDevHandle);
1797 r = 0; 1349 r = 0;
1798 goto done; 1350 goto out;
1799 } 1351 }
1800 } 1352 }
1801
1802 done:
1803 if (mem.config_page_sz > ioc->config_page_sz)
1804 _config_free_config_dma_memory(ioc, &mem);
1805
1806 out: 1353 out:
1354 kfree(config_page);
1807 return r; 1355 return r;
1808} 1356}
1809 1357