2 * Linux MegaRAID driver for SAS based RAID controllers
4 * Copyright (c) 2009-2013 LSI Corporation
5 * Copyright (c) 2013-2014 Avago Technologies
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * FILE: megaraid_sas_fp.c
22 * Authors: Avago Technologies
26 * Kashyap Desai <kashyap.desai@avagotech.com>
27 * Sumit Saxena <sumit.saxena@avagotech.com>
29 * Send feedback to: megaraidlinux.pdl@avagotech.com
31 * Mail to: Avago Technologies, 350 West Trimble Road, Building 90,
32 * San Jose, California 95131
35 #include <linux/kernel.h>
36 #include <linux/types.h>
37 #include <linux/pci.h>
38 #include <linux/list.h>
39 #include <linux/moduleparam.h>
40 #include <linux/module.h>
41 #include <linux/spinlock.h>
42 #include <linux/interrupt.h>
43 #include <linux/delay.h>
44 #include <linux/uio.h>
45 #include <linux/uaccess.h>
47 #include <linux/compat.h>
48 #include <linux/blkdev.h>
49 #include <linux/poll.h>
51 #include <scsi/scsi.h>
52 #include <scsi/scsi_cmnd.h>
53 #include <scsi/scsi_device.h>
54 #include <scsi/scsi_host.h>
56 #include "megaraid_sas_fusion.h"
57 #include "megaraid_sas.h"
58 #include <asm/div64.h>
60 #define LB_PENDING_CMDS_DEFAULT 4
61 static unsigned int lb_pending_cmds
= LB_PENDING_CMDS_DEFAULT
;
62 module_param(lb_pending_cmds
, int, S_IRUGO
);
63 MODULE_PARM_DESC(lb_pending_cmds
, "Change raid-1 load balancing outstanding "
64 "threshold. Valid Values are 1-128. Default: 4");
67 #define ABS_DIFF(a, b) (((a) > (b)) ? ((a) - (b)) : ((b) - (a)))
68 #define MR_LD_STATE_OPTIMAL 3
70 #define SPAN_ROW_SIZE(map, ld, index_) (MR_LdSpanPtrGet(ld, index_, map)->spanRowSize)
71 #define SPAN_ROW_DATA_SIZE(map_, ld, index_) (MR_LdSpanPtrGet(ld, index_, map)->spanRowDataSize)
72 #define SPAN_INVALID 0xff
75 static void mr_update_span_set(struct MR_DRV_RAID_MAP_ALL
*map
,
76 PLD_SPAN_INFO ldSpanInfo
);
77 static u8
mr_spanset_get_phy_params(struct megasas_instance
*instance
, u32 ld
,
78 u64 stripRow
, u16 stripRef
, struct IO_REQUEST_INFO
*io_info
,
79 struct RAID_CONTEXT
*pRAID_Context
, struct MR_DRV_RAID_MAP_ALL
*map
);
80 static u64
get_row_from_strip(struct megasas_instance
*instance
, u32 ld
,
81 u64 strip
, struct MR_DRV_RAID_MAP_ALL
*map
);
83 u32
mega_mod64(u64 dividend
, u32 divisor
)
89 printk(KERN_ERR
"megasas : DIVISOR is zero, in div fn\n");
91 remainder
= do_div(d
, divisor
);
96 * @param dividend : Dividend
97 * @param divisor : Divisor
101 u64
mega_div64_32(uint64_t dividend
, uint32_t divisor
)
107 printk(KERN_ERR
"megasas : DIVISOR is zero in mod fn\n");
110 remainder
= do_div(d
, divisor
);
115 struct MR_LD_RAID
*MR_LdRaidGet(u32 ld
, struct MR_DRV_RAID_MAP_ALL
*map
)
117 return &map
->raidMap
.ldSpanMap
[ld
].ldRaid
;
120 static struct MR_SPAN_BLOCK_INFO
*MR_LdSpanInfoGet(u32 ld
,
121 struct MR_DRV_RAID_MAP_ALL
124 return &map
->raidMap
.ldSpanMap
[ld
].spanBlock
[0];
127 static u8
MR_LdDataArmGet(u32 ld
, u32 armIdx
, struct MR_DRV_RAID_MAP_ALL
*map
)
129 return map
->raidMap
.ldSpanMap
[ld
].dataArmMap
[armIdx
];
132 u16
MR_ArPdGet(u32 ar
, u32 arm
, struct MR_DRV_RAID_MAP_ALL
*map
)
134 return le16_to_cpu(map
->raidMap
.arMapInfo
[ar
].pd
[arm
]);
137 u16
MR_LdSpanArrayGet(u32 ld
, u32 span
, struct MR_DRV_RAID_MAP_ALL
*map
)
139 return le16_to_cpu(map
->raidMap
.ldSpanMap
[ld
].spanBlock
[span
].span
.arrayRef
);
142 __le16
MR_PdDevHandleGet(u32 pd
, struct MR_DRV_RAID_MAP_ALL
*map
)
144 return map
->raidMap
.devHndlInfo
[pd
].curDevHdl
;
147 static u8
MR_PdInterfaceTypeGet(u32 pd
, struct MR_DRV_RAID_MAP_ALL
*map
)
149 return map
->raidMap
.devHndlInfo
[pd
].interfaceType
;
152 u16
MR_GetLDTgtId(u32 ld
, struct MR_DRV_RAID_MAP_ALL
*map
)
154 return le16_to_cpu(map
->raidMap
.ldSpanMap
[ld
].ldRaid
.targetId
);
157 u16
MR_TargetIdToLdGet(u32 ldTgtId
, struct MR_DRV_RAID_MAP_ALL
*map
)
159 return map
->raidMap
.ldTgtIdToLd
[ldTgtId
];
162 static struct MR_LD_SPAN
*MR_LdSpanPtrGet(u32 ld
, u32 span
,
163 struct MR_DRV_RAID_MAP_ALL
*map
)
165 return &map
->raidMap
.ldSpanMap
[ld
].spanBlock
[span
].span
;
169 * This function will Populate Driver Map using firmware raid map
171 void MR_PopulateDrvRaidMap(struct megasas_instance
*instance
)
173 struct fusion_context
*fusion
= instance
->ctrl_context
;
174 struct MR_FW_RAID_MAP_ALL
*fw_map_old
= NULL
;
175 struct MR_FW_RAID_MAP
*pFwRaidMap
= NULL
;
178 struct MR_FW_RAID_MAP_DYNAMIC
*fw_map_dyn
;
179 struct MR_FW_RAID_MAP_EXT
*fw_map_ext
;
180 struct MR_RAID_MAP_DESC_TABLE
*desc_table
;
183 struct MR_DRV_RAID_MAP_ALL
*drv_map
=
184 fusion
->ld_drv_map
[(instance
->map_id
& 1)];
185 struct MR_DRV_RAID_MAP
*pDrvRaidMap
= &drv_map
->raidMap
;
186 void *raid_map_data
= NULL
;
188 memset(drv_map
, 0, fusion
->drv_map_sz
);
189 memset(pDrvRaidMap
->ldTgtIdToLd
,
190 0xff, (sizeof(u16
) * MAX_LOGICAL_DRIVES_DYN
));
192 if (instance
->max_raid_mapsize
) {
193 fw_map_dyn
= fusion
->ld_map
[(instance
->map_id
& 1)];
195 (struct MR_RAID_MAP_DESC_TABLE
*)((void *)fw_map_dyn
+ le32_to_cpu(fw_map_dyn
->desc_table_offset
));
196 if (desc_table
!= fw_map_dyn
->raid_map_desc_table
)
197 dev_dbg(&instance
->pdev
->dev
, "offsets of desc table are not matching desc %p original %p\n",
198 desc_table
, fw_map_dyn
->raid_map_desc_table
);
200 ld_count
= (u16
)le16_to_cpu(fw_map_dyn
->ld_count
);
201 pDrvRaidMap
->ldCount
= (__le16
)cpu_to_le16(ld_count
);
202 pDrvRaidMap
->fpPdIoTimeoutSec
=
203 fw_map_dyn
->fp_pd_io_timeout_sec
;
204 pDrvRaidMap
->totalSize
=
205 cpu_to_le32(sizeof(struct MR_DRV_RAID_MAP_ALL
));
206 /* point to actual data starting point*/
207 raid_map_data
= (void *)fw_map_dyn
+
208 le32_to_cpu(fw_map_dyn
->desc_table_offset
) +
209 le32_to_cpu(fw_map_dyn
->desc_table_size
);
211 for (i
= 0; i
< le32_to_cpu(fw_map_dyn
->desc_table_num_elements
); ++i
) {
212 switch (le32_to_cpu(desc_table
->raid_map_desc_type
)) {
213 case RAID_MAP_DESC_TYPE_DEVHDL_INFO
:
214 fw_map_dyn
->dev_hndl_info
=
215 (struct MR_DEV_HANDLE_INFO
*)(raid_map_data
+ le32_to_cpu(desc_table
->raid_map_desc_offset
));
216 memcpy(pDrvRaidMap
->devHndlInfo
,
217 fw_map_dyn
->dev_hndl_info
,
218 sizeof(struct MR_DEV_HANDLE_INFO
) *
219 le32_to_cpu(desc_table
->raid_map_desc_elements
));
221 case RAID_MAP_DESC_TYPE_TGTID_INFO
:
222 fw_map_dyn
->ld_tgt_id_to_ld
=
223 (u16
*)(raid_map_data
+
224 le32_to_cpu(desc_table
->raid_map_desc_offset
));
225 for (j
= 0; j
< le32_to_cpu(desc_table
->raid_map_desc_elements
); j
++) {
226 pDrvRaidMap
->ldTgtIdToLd
[j
] =
227 le16_to_cpu(fw_map_dyn
->ld_tgt_id_to_ld
[j
]);
230 case RAID_MAP_DESC_TYPE_ARRAY_INFO
:
231 fw_map_dyn
->ar_map_info
=
232 (struct MR_ARRAY_INFO
*)
233 (raid_map_data
+ le32_to_cpu(desc_table
->raid_map_desc_offset
));
234 memcpy(pDrvRaidMap
->arMapInfo
,
235 fw_map_dyn
->ar_map_info
,
236 sizeof(struct MR_ARRAY_INFO
) *
237 le32_to_cpu(desc_table
->raid_map_desc_elements
));
239 case RAID_MAP_DESC_TYPE_SPAN_INFO
:
240 fw_map_dyn
->ld_span_map
=
241 (struct MR_LD_SPAN_MAP
*)
243 le32_to_cpu(desc_table
->raid_map_desc_offset
));
244 memcpy(pDrvRaidMap
->ldSpanMap
,
245 fw_map_dyn
->ld_span_map
,
246 sizeof(struct MR_LD_SPAN_MAP
) *
247 le32_to_cpu(desc_table
->raid_map_desc_elements
));
250 dev_dbg(&instance
->pdev
->dev
, "wrong number of desctableElements %d\n",
251 fw_map_dyn
->desc_table_num_elements
);
256 } else if (instance
->supportmax256vd
) {
258 (struct MR_FW_RAID_MAP_EXT
*)fusion
->ld_map
[(instance
->map_id
& 1)];
259 ld_count
= (u16
)le16_to_cpu(fw_map_ext
->ldCount
);
260 if (ld_count
> MAX_LOGICAL_DRIVES_EXT
) {
261 dev_dbg(&instance
->pdev
->dev
, "megaraid_sas: LD count exposed in RAID map in not valid\n");
265 pDrvRaidMap
->ldCount
= (__le16
)cpu_to_le16(ld_count
);
266 pDrvRaidMap
->fpPdIoTimeoutSec
= fw_map_ext
->fpPdIoTimeoutSec
;
267 for (i
= 0; i
< (MAX_LOGICAL_DRIVES_EXT
); i
++)
268 pDrvRaidMap
->ldTgtIdToLd
[i
] =
269 (u16
)fw_map_ext
->ldTgtIdToLd
[i
];
270 memcpy(pDrvRaidMap
->ldSpanMap
, fw_map_ext
->ldSpanMap
,
271 sizeof(struct MR_LD_SPAN_MAP
) * ld_count
);
272 memcpy(pDrvRaidMap
->arMapInfo
, fw_map_ext
->arMapInfo
,
273 sizeof(struct MR_ARRAY_INFO
) * MAX_API_ARRAYS_EXT
);
274 memcpy(pDrvRaidMap
->devHndlInfo
, fw_map_ext
->devHndlInfo
,
275 sizeof(struct MR_DEV_HANDLE_INFO
) *
276 MAX_RAIDMAP_PHYSICAL_DEVICES
);
278 /* New Raid map will not set totalSize, so keep expected value
279 * for legacy code in ValidateMapInfo
281 pDrvRaidMap
->totalSize
=
282 cpu_to_le32(sizeof(struct MR_FW_RAID_MAP_EXT
));
284 fw_map_old
= (struct MR_FW_RAID_MAP_ALL
*)
285 fusion
->ld_map
[(instance
->map_id
& 1)];
286 pFwRaidMap
= &fw_map_old
->raidMap
;
287 ld_count
= (u16
)le32_to_cpu(pFwRaidMap
->ldCount
);
288 pDrvRaidMap
->totalSize
= pFwRaidMap
->totalSize
;
289 pDrvRaidMap
->ldCount
= (__le16
)cpu_to_le16(ld_count
);
290 pDrvRaidMap
->fpPdIoTimeoutSec
= pFwRaidMap
->fpPdIoTimeoutSec
;
291 for (i
= 0; i
< MAX_RAIDMAP_LOGICAL_DRIVES
+ MAX_RAIDMAP_VIEWS
; i
++)
292 pDrvRaidMap
->ldTgtIdToLd
[i
] =
293 (u8
)pFwRaidMap
->ldTgtIdToLd
[i
];
294 for (i
= 0; i
< ld_count
; i
++) {
295 pDrvRaidMap
->ldSpanMap
[i
] = pFwRaidMap
->ldSpanMap
[i
];
297 memcpy(pDrvRaidMap
->arMapInfo
, pFwRaidMap
->arMapInfo
,
298 sizeof(struct MR_ARRAY_INFO
) * MAX_RAIDMAP_ARRAYS
);
299 memcpy(pDrvRaidMap
->devHndlInfo
, pFwRaidMap
->devHndlInfo
,
300 sizeof(struct MR_DEV_HANDLE_INFO
) *
301 MAX_RAIDMAP_PHYSICAL_DEVICES
);
306 * This function will validate Map info data provided by FW
308 u8
MR_ValidateMapInfo(struct megasas_instance
*instance
)
310 struct fusion_context
*fusion
;
311 struct MR_DRV_RAID_MAP_ALL
*drv_map
;
312 struct MR_DRV_RAID_MAP
*pDrvRaidMap
;
313 struct LD_LOAD_BALANCE_INFO
*lbInfo
;
314 PLD_SPAN_INFO ldSpanInfo
;
315 struct MR_LD_RAID
*raid
;
321 MR_PopulateDrvRaidMap(instance
);
323 fusion
= instance
->ctrl_context
;
324 drv_map
= fusion
->ld_drv_map
[(instance
->map_id
& 1)];
325 pDrvRaidMap
= &drv_map
->raidMap
;
327 lbInfo
= fusion
->load_balance_info
;
328 ldSpanInfo
= fusion
->log_to_span
;
330 if (instance
->max_raid_mapsize
)
331 expected_size
= sizeof(struct MR_DRV_RAID_MAP_ALL
);
332 else if (instance
->supportmax256vd
)
333 expected_size
= sizeof(struct MR_FW_RAID_MAP_EXT
);
336 (sizeof(struct MR_FW_RAID_MAP
) - sizeof(struct MR_LD_SPAN_MAP
) +
337 (sizeof(struct MR_LD_SPAN_MAP
) * le16_to_cpu(pDrvRaidMap
->ldCount
)));
339 if (le32_to_cpu(pDrvRaidMap
->totalSize
) != expected_size
) {
340 dev_dbg(&instance
->pdev
->dev
, "megasas: map info structure size 0x%x",
341 le32_to_cpu(pDrvRaidMap
->totalSize
));
342 dev_dbg(&instance
->pdev
->dev
, "is not matching expected size 0x%x\n",
343 (unsigned int)expected_size
);
344 dev_err(&instance
->pdev
->dev
, "megasas: span map %x, pDrvRaidMap->totalSize : %x\n",
345 (unsigned int)sizeof(struct MR_LD_SPAN_MAP
),
346 le32_to_cpu(pDrvRaidMap
->totalSize
));
350 if (instance
->UnevenSpanSupport
)
351 mr_update_span_set(drv_map
, ldSpanInfo
);
354 mr_update_load_balance_params(drv_map
, lbInfo
);
356 num_lds
= le16_to_cpu(drv_map
->raidMap
.ldCount
);
358 /*Convert Raid capability values to CPU arch */
359 for (i
= 0; (num_lds
> 0) && (i
< MAX_LOGICAL_DRIVES_EXT
); i
++) {
360 ld
= MR_TargetIdToLdGet(i
, drv_map
);
362 /* For non existing VDs, iterate to next VD*/
363 if (ld
>= (MAX_LOGICAL_DRIVES_EXT
- 1))
366 raid
= MR_LdRaidGet(ld
, drv_map
);
367 le32_to_cpus((u32
*)&raid
->capability
);
375 u32
MR_GetSpanBlock(u32 ld
, u64 row
, u64
*span_blk
,
376 struct MR_DRV_RAID_MAP_ALL
*map
)
378 struct MR_SPAN_BLOCK_INFO
*pSpanBlock
= MR_LdSpanInfoGet(ld
, map
);
379 struct MR_QUAD_ELEMENT
*quad
;
380 struct MR_LD_RAID
*raid
= MR_LdRaidGet(ld
, map
);
383 for (span
= 0; span
< raid
->spanDepth
; span
++, pSpanBlock
++) {
385 for (j
= 0; j
< le32_to_cpu(pSpanBlock
->block_span_info
.noElements
); j
++) {
386 quad
= &pSpanBlock
->block_span_info
.quad
[j
];
388 if (le32_to_cpu(quad
->diff
) == 0)
390 if (le64_to_cpu(quad
->logStart
) <= row
&& row
<=
391 le64_to_cpu(quad
->logEnd
) && (mega_mod64(row
- le64_to_cpu(quad
->logStart
),
392 le32_to_cpu(quad
->diff
))) == 0) {
393 if (span_blk
!= NULL
) {
395 blk
= mega_div64_32((row
-le64_to_cpu(quad
->logStart
)), le32_to_cpu(quad
->diff
));
398 blk
= (blk
+ le64_to_cpu(quad
->offsetInSpan
)) << raid
->stripeShift
;
409 ******************************************************************************
411 * This routine calculates the Span block for given row using spanset.
414 * instance - HBA instance
415 * ld - Logical drive number
422 * block - Absolute Block number in the physical disk
423 * div_error - Devide error code.
426 u32
mr_spanset_get_span_block(struct megasas_instance
*instance
,
427 u32 ld
, u64 row
, u64
*span_blk
, struct MR_DRV_RAID_MAP_ALL
*map
)
429 struct fusion_context
*fusion
= instance
->ctrl_context
;
430 struct MR_LD_RAID
*raid
= MR_LdRaidGet(ld
, map
);
431 LD_SPAN_SET
*span_set
;
432 struct MR_QUAD_ELEMENT
*quad
;
434 PLD_SPAN_INFO ldSpanInfo
= fusion
->log_to_span
;
436 for (info
= 0; info
< MAX_QUAD_DEPTH
; info
++) {
437 span_set
= &(ldSpanInfo
[ld
].span_set
[info
]);
439 if (span_set
->span_row_data_width
== 0)
442 if (row
> span_set
->data_row_end
)
445 for (span
= 0; span
< raid
->spanDepth
; span
++)
446 if (le32_to_cpu(map
->raidMap
.ldSpanMap
[ld
].spanBlock
[span
].
447 block_span_info
.noElements
) >= info
+1) {
448 quad
= &map
->raidMap
.ldSpanMap
[ld
].
450 block_span_info
.quad
[info
];
451 if (le32_to_cpu(quad
->diff
) == 0)
453 if (le64_to_cpu(quad
->logStart
) <= row
&&
454 row
<= le64_to_cpu(quad
->logEnd
) &&
455 (mega_mod64(row
- le64_to_cpu(quad
->logStart
),
456 le32_to_cpu(quad
->diff
))) == 0) {
457 if (span_blk
!= NULL
) {
460 ((row
- le64_to_cpu(quad
->logStart
)),
461 le32_to_cpu(quad
->diff
));
462 blk
= (blk
+ le64_to_cpu(quad
->offsetInSpan
))
463 << raid
->stripeShift
;
474 ******************************************************************************
476 * This routine calculates the row for given strip using spanset.
479 * instance - HBA instance
480 * ld - Logical drive number
486 * row - row associated with strip
489 static u64
get_row_from_strip(struct megasas_instance
*instance
,
490 u32 ld
, u64 strip
, struct MR_DRV_RAID_MAP_ALL
*map
)
492 struct fusion_context
*fusion
= instance
->ctrl_context
;
493 struct MR_LD_RAID
*raid
= MR_LdRaidGet(ld
, map
);
494 LD_SPAN_SET
*span_set
;
495 PLD_SPAN_INFO ldSpanInfo
= fusion
->log_to_span
;
496 u32 info
, strip_offset
, span
, span_offset
;
497 u64 span_set_Strip
, span_set_Row
, retval
;
499 for (info
= 0; info
< MAX_QUAD_DEPTH
; info
++) {
500 span_set
= &(ldSpanInfo
[ld
].span_set
[info
]);
502 if (span_set
->span_row_data_width
== 0)
504 if (strip
> span_set
->data_strip_end
)
507 span_set_Strip
= strip
- span_set
->data_strip_start
;
508 strip_offset
= mega_mod64(span_set_Strip
,
509 span_set
->span_row_data_width
);
510 span_set_Row
= mega_div64_32(span_set_Strip
,
511 span_set
->span_row_data_width
) * span_set
->diff
;
512 for (span
= 0, span_offset
= 0; span
< raid
->spanDepth
; span
++)
513 if (le32_to_cpu(map
->raidMap
.ldSpanMap
[ld
].spanBlock
[span
].
514 block_span_info
.noElements
) >= info
+1) {
516 span_set
->strip_offset
[span
])
522 retval
= (span_set
->data_row_start
+ span_set_Row
+
531 ******************************************************************************
533 * This routine calculates the Start Strip for given row using spanset.
536 * instance - HBA instance
537 * ld - Logical drive number
543 * Strip - Start strip associated with row
546 static u64
get_strip_from_row(struct megasas_instance
*instance
,
547 u32 ld
, u64 row
, struct MR_DRV_RAID_MAP_ALL
*map
)
549 struct fusion_context
*fusion
= instance
->ctrl_context
;
550 struct MR_LD_RAID
*raid
= MR_LdRaidGet(ld
, map
);
551 LD_SPAN_SET
*span_set
;
552 struct MR_QUAD_ELEMENT
*quad
;
553 PLD_SPAN_INFO ldSpanInfo
= fusion
->log_to_span
;
557 for (info
= 0; info
< MAX_QUAD_DEPTH
; info
++) {
558 span_set
= &(ldSpanInfo
[ld
].span_set
[info
]);
560 if (span_set
->span_row_data_width
== 0)
562 if (row
> span_set
->data_row_end
)
565 for (span
= 0; span
< raid
->spanDepth
; span
++)
566 if (le32_to_cpu(map
->raidMap
.ldSpanMap
[ld
].spanBlock
[span
].
567 block_span_info
.noElements
) >= info
+1) {
568 quad
= &map
->raidMap
.ldSpanMap
[ld
].
569 spanBlock
[span
].block_span_info
.quad
[info
];
570 if (le64_to_cpu(quad
->logStart
) <= row
&&
571 row
<= le64_to_cpu(quad
->logEnd
) &&
572 mega_mod64((row
- le64_to_cpu(quad
->logStart
)),
573 le32_to_cpu(quad
->diff
)) == 0) {
574 strip
= mega_div64_32
575 (((row
- span_set
->data_row_start
)
576 - le64_to_cpu(quad
->logStart
)),
577 le32_to_cpu(quad
->diff
));
578 strip
*= span_set
->span_row_data_width
;
579 strip
+= span_set
->data_strip_start
;
580 strip
+= span_set
->strip_offset
[span
];
585 dev_err(&instance
->pdev
->dev
, "get_strip_from_row"
586 "returns invalid strip for ld=%x, row=%lx\n",
587 ld
, (long unsigned int)row
);
592 ******************************************************************************
594 * This routine calculates the Physical Arm for given strip using spanset.
597 * instance - HBA instance
598 * ld - Logical drive number
604 * Phys Arm - Phys Arm associated with strip
607 static u32
get_arm_from_strip(struct megasas_instance
*instance
,
608 u32 ld
, u64 strip
, struct MR_DRV_RAID_MAP_ALL
*map
)
610 struct fusion_context
*fusion
= instance
->ctrl_context
;
611 struct MR_LD_RAID
*raid
= MR_LdRaidGet(ld
, map
);
612 LD_SPAN_SET
*span_set
;
613 PLD_SPAN_INFO ldSpanInfo
= fusion
->log_to_span
;
614 u32 info
, strip_offset
, span
, span_offset
, retval
;
616 for (info
= 0 ; info
< MAX_QUAD_DEPTH
; info
++) {
617 span_set
= &(ldSpanInfo
[ld
].span_set
[info
]);
619 if (span_set
->span_row_data_width
== 0)
621 if (strip
> span_set
->data_strip_end
)
624 strip_offset
= (uint
)mega_mod64
625 ((strip
- span_set
->data_strip_start
),
626 span_set
->span_row_data_width
);
628 for (span
= 0, span_offset
= 0; span
< raid
->spanDepth
; span
++)
629 if (le32_to_cpu(map
->raidMap
.ldSpanMap
[ld
].spanBlock
[span
].
630 block_span_info
.noElements
) >= info
+1) {
632 span_set
->strip_offset
[span
])
634 span_set
->strip_offset
[span
];
639 retval
= (strip_offset
- span_offset
);
643 dev_err(&instance
->pdev
->dev
, "get_arm_from_strip"
644 "returns invalid arm for ld=%x strip=%lx\n",
645 ld
, (long unsigned int)strip
);
650 /* This Function will return Phys arm */
651 u8
get_arm(struct megasas_instance
*instance
, u32 ld
, u8 span
, u64 stripe
,
652 struct MR_DRV_RAID_MAP_ALL
*map
)
654 struct MR_LD_RAID
*raid
= MR_LdRaidGet(ld
, map
);
655 /* Need to check correct default value */
658 switch (raid
->level
) {
662 arm
= mega_mod64(stripe
, SPAN_ROW_SIZE(map
, ld
, span
));
665 /* start with logical arm */
666 arm
= get_arm_from_strip(instance
, ld
, stripe
, map
);
677 ******************************************************************************
679 * This routine calculates the arm, span and block for the specified stripe and
680 * reference in stripe using spanset
684 * ld - Logical drive number
685 * stripRow - Stripe number
686 * stripRef - Reference in stripe
691 * block - Absolute Block number in the physical disk
693 static u8
mr_spanset_get_phy_params(struct megasas_instance
*instance
, u32 ld
,
694 u64 stripRow
, u16 stripRef
, struct IO_REQUEST_INFO
*io_info
,
695 struct RAID_CONTEXT
*pRAID_Context
,
696 struct MR_DRV_RAID_MAP_ALL
*map
)
698 struct MR_LD_RAID
*raid
= MR_LdRaidGet(ld
, map
);
699 u32 pd
, arRef
, r1_alt_pd
;
703 u64
*pdBlock
= &io_info
->pdBlock
;
704 __le16
*pDevHandle
= &io_info
->devHandle
;
705 u8
*pPdInterface
= &io_info
->pd_interface
;
706 u32 logArm
, rowMod
, armQ
, arm
;
707 struct fusion_context
*fusion
;
709 fusion
= instance
->ctrl_context
;
710 *pDevHandle
= cpu_to_le16(MR_DEVHANDLE_INVALID
);
712 /*Get row and span from io_info for Uneven Span IO.*/
713 row
= io_info
->start_row
;
714 span
= io_info
->start_span
;
717 if (raid
->level
== 6) {
718 logArm
= get_arm_from_strip(instance
, ld
, stripRow
, map
);
721 rowMod
= mega_mod64(row
, SPAN_ROW_SIZE(map
, ld
, span
));
722 armQ
= SPAN_ROW_SIZE(map
, ld
, span
) - 1 - rowMod
;
723 arm
= armQ
+ 1 + logArm
;
724 if (arm
>= SPAN_ROW_SIZE(map
, ld
, span
))
725 arm
-= SPAN_ROW_SIZE(map
, ld
, span
);
728 /* Calculate the arm */
729 physArm
= get_arm(instance
, ld
, span
, stripRow
, map
);
733 arRef
= MR_LdSpanArrayGet(ld
, span
, map
);
734 pd
= MR_ArPdGet(arRef
, physArm
, map
);
736 if (pd
!= MR_PD_INVALID
) {
737 *pDevHandle
= MR_PdDevHandleGet(pd
, map
);
738 *pPdInterface
= MR_PdInterfaceTypeGet(pd
, map
);
739 /* get second pd also for raid 1/10 fast path writes*/
740 if ((instance
->adapter_type
== VENTURA_SERIES
) &&
741 (raid
->level
== 1) &&
743 r1_alt_pd
= MR_ArPdGet(arRef
, physArm
+ 1, map
);
744 if (r1_alt_pd
!= MR_PD_INVALID
)
745 io_info
->r1_alt_dev_handle
=
746 MR_PdDevHandleGet(r1_alt_pd
, map
);
749 if ((raid
->level
>= 5) &&
750 ((instance
->adapter_type
== THUNDERBOLT_SERIES
) ||
751 ((instance
->adapter_type
== INVADER_SERIES
) &&
752 (raid
->regTypeReqOnRead
!= REGION_TYPE_UNUSED
))))
753 pRAID_Context
->reg_lock_flags
= REGION_TYPE_EXCLUSIVE
;
754 else if (raid
->level
== 1) {
755 physArm
= physArm
+ 1;
756 pd
= MR_ArPdGet(arRef
, physArm
, map
);
757 if (pd
!= MR_PD_INVALID
) {
758 *pDevHandle
= MR_PdDevHandleGet(pd
, map
);
759 *pPdInterface
= MR_PdInterfaceTypeGet(pd
, map
);
764 *pdBlock
+= stripRef
+ le64_to_cpu(MR_LdSpanPtrGet(ld
, span
, map
)->startBlk
);
765 if (instance
->adapter_type
== VENTURA_SERIES
) {
766 ((struct RAID_CONTEXT_G35
*)pRAID_Context
)->span_arm
=
767 (span
<< RAID_CTX_SPANARM_SPAN_SHIFT
) | physArm
;
769 (span
<< RAID_CTX_SPANARM_SPAN_SHIFT
) | physArm
;
771 pRAID_Context
->span_arm
=
772 (span
<< RAID_CTX_SPANARM_SPAN_SHIFT
) | physArm
;
773 io_info
->span_arm
= pRAID_Context
->span_arm
;
775 io_info
->pd_after_lb
= pd
;
780 ******************************************************************************
782 * This routine calculates the arm, span and block for the specified stripe and
783 * reference in stripe.
787 * ld - Logical drive number
788 * stripRow - Stripe number
789 * stripRef - Reference in stripe
794 * block - Absolute Block number in the physical disk
796 u8
MR_GetPhyParams(struct megasas_instance
*instance
, u32 ld
, u64 stripRow
,
797 u16 stripRef
, struct IO_REQUEST_INFO
*io_info
,
798 struct RAID_CONTEXT
*pRAID_Context
,
799 struct MR_DRV_RAID_MAP_ALL
*map
)
801 struct MR_LD_RAID
*raid
= MR_LdRaidGet(ld
, map
);
802 u32 pd
, arRef
, r1_alt_pd
;
806 u64
*pdBlock
= &io_info
->pdBlock
;
807 __le16
*pDevHandle
= &io_info
->devHandle
;
808 u8
*pPdInterface
= &io_info
->pd_interface
;
809 struct fusion_context
*fusion
;
811 fusion
= instance
->ctrl_context
;
812 *pDevHandle
= cpu_to_le16(MR_DEVHANDLE_INVALID
);
814 row
= mega_div64_32(stripRow
, raid
->rowDataSize
);
816 if (raid
->level
== 6) {
817 /* logical arm within row */
818 u32 logArm
= mega_mod64(stripRow
, raid
->rowDataSize
);
819 u32 rowMod
, armQ
, arm
;
821 if (raid
->rowSize
== 0)
823 /* get logical row mod */
824 rowMod
= mega_mod64(row
, raid
->rowSize
);
825 armQ
= raid
->rowSize
-1-rowMod
; /* index of Q drive */
826 arm
= armQ
+1+logArm
; /* data always logically follows Q */
827 if (arm
>= raid
->rowSize
) /* handle wrap condition */
828 arm
-= raid
->rowSize
;
831 if (raid
->modFactor
== 0)
833 physArm
= MR_LdDataArmGet(ld
, mega_mod64(stripRow
,
838 if (raid
->spanDepth
== 1) {
840 *pdBlock
= row
<< raid
->stripeShift
;
842 span
= (u8
)MR_GetSpanBlock(ld
, row
, pdBlock
, map
);
843 if (span
== SPAN_INVALID
)
847 /* Get the array on which this span is present */
848 arRef
= MR_LdSpanArrayGet(ld
, span
, map
);
849 pd
= MR_ArPdGet(arRef
, physArm
, map
); /* Get the pd */
851 if (pd
!= MR_PD_INVALID
) {
852 /* Get dev handle from Pd. */
853 *pDevHandle
= MR_PdDevHandleGet(pd
, map
);
854 *pPdInterface
= MR_PdInterfaceTypeGet(pd
, map
);
855 /* get second pd also for raid 1/10 fast path writes*/
856 if ((instance
->adapter_type
== VENTURA_SERIES
) &&
857 (raid
->level
== 1) &&
859 r1_alt_pd
= MR_ArPdGet(arRef
, physArm
+ 1, map
);
860 if (r1_alt_pd
!= MR_PD_INVALID
)
861 io_info
->r1_alt_dev_handle
=
862 MR_PdDevHandleGet(r1_alt_pd
, map
);
865 if ((raid
->level
>= 5) &&
866 ((instance
->adapter_type
== THUNDERBOLT_SERIES
) ||
867 ((instance
->adapter_type
== INVADER_SERIES
) &&
868 (raid
->regTypeReqOnRead
!= REGION_TYPE_UNUSED
))))
869 pRAID_Context
->reg_lock_flags
= REGION_TYPE_EXCLUSIVE
;
870 else if (raid
->level
== 1) {
871 /* Get alternate Pd. */
872 physArm
= physArm
+ 1;
873 pd
= MR_ArPdGet(arRef
, physArm
, map
);
874 if (pd
!= MR_PD_INVALID
) {
875 /* Get dev handle from Pd */
876 *pDevHandle
= MR_PdDevHandleGet(pd
, map
);
877 *pPdInterface
= MR_PdInterfaceTypeGet(pd
, map
);
882 *pdBlock
+= stripRef
+ le64_to_cpu(MR_LdSpanPtrGet(ld
, span
, map
)->startBlk
);
883 if (instance
->adapter_type
== VENTURA_SERIES
) {
884 ((struct RAID_CONTEXT_G35
*)pRAID_Context
)->span_arm
=
885 (span
<< RAID_CTX_SPANARM_SPAN_SHIFT
) | physArm
;
887 (span
<< RAID_CTX_SPANARM_SPAN_SHIFT
) | physArm
;
889 pRAID_Context
->span_arm
=
890 (span
<< RAID_CTX_SPANARM_SPAN_SHIFT
) | physArm
;
891 io_info
->span_arm
= pRAID_Context
->span_arm
;
893 io_info
->pd_after_lb
= pd
;
898 ******************************************************************************
900 * MR_BuildRaidContext function
902 * This function will initiate command processing. The start/end row and strip
903 * information is calculated then the lock is acquired.
904 * This function will return 0 if region lock was acquired OR return num strips
907 MR_BuildRaidContext(struct megasas_instance
*instance
,
908 struct IO_REQUEST_INFO
*io_info
,
909 struct RAID_CONTEXT
*pRAID_Context
,
910 struct MR_DRV_RAID_MAP_ALL
*map
, u8
**raidLUN
)
912 struct fusion_context
*fusion
;
913 struct MR_LD_RAID
*raid
;
914 u32 stripSize
, stripe_mask
;
915 u64 endLba
, endStrip
, endRow
, start_row
, start_strip
;
918 u8 num_strips
, numRows
;
919 u16 ref_in_start_stripe
, ref_in_end_stripe
;
921 u32 numBlocks
, ldTgtId
;
924 u8 startlba_span
= SPAN_INVALID
;
925 u64
*pdBlock
= &io_info
->pdBlock
;
928 ldStartBlock
= io_info
->ldStartBlock
;
929 numBlocks
= io_info
->numBlocks
;
930 ldTgtId
= io_info
->ldTgtId
;
931 isRead
= io_info
->isRead
;
932 io_info
->IoforUnevenSpan
= 0;
933 io_info
->start_span
= SPAN_INVALID
;
934 fusion
= instance
->ctrl_context
;
936 ld
= MR_TargetIdToLdGet(ldTgtId
, map
);
937 raid
= MR_LdRaidGet(ld
, map
);
938 /*check read ahead bit*/
939 io_info
->ra_capable
= raid
->capability
.ra_capable
;
942 * if rowDataSize @RAID map and spanRowDataSize @SPAN INFO are zero
945 if (raid
->rowDataSize
== 0) {
946 if (MR_LdSpanPtrGet(ld
, 0, map
)->spanRowDataSize
== 0)
948 else if (instance
->UnevenSpanSupport
) {
949 io_info
->IoforUnevenSpan
= 1;
951 dev_info(&instance
->pdev
->dev
,
952 "raid->rowDataSize is 0, but has SPAN[0]"
953 "rowDataSize = 0x%0x,"
954 "but there is _NO_ UnevenSpanSupport\n",
955 MR_LdSpanPtrGet(ld
, 0, map
)->spanRowDataSize
);
960 stripSize
= 1 << raid
->stripeShift
;
961 stripe_mask
= stripSize
-1;
965 * calculate starting row and stripe, and number of strips and rows
967 start_strip
= ldStartBlock
>> raid
->stripeShift
;
968 ref_in_start_stripe
= (u16
)(ldStartBlock
& stripe_mask
);
969 endLba
= ldStartBlock
+ numBlocks
- 1;
970 ref_in_end_stripe
= (u16
)(endLba
& stripe_mask
);
971 endStrip
= endLba
>> raid
->stripeShift
;
972 num_strips
= (u8
)(endStrip
- start_strip
+ 1); /* End strip */
974 if (io_info
->IoforUnevenSpan
) {
975 start_row
= get_row_from_strip(instance
, ld
, start_strip
, map
);
976 endRow
= get_row_from_strip(instance
, ld
, endStrip
, map
);
977 if (start_row
== -1ULL || endRow
== -1ULL) {
978 dev_info(&instance
->pdev
->dev
, "return from %s %d."
979 "Send IO w/o region lock.\n",
984 if (raid
->spanDepth
== 1) {
986 *pdBlock
= start_row
<< raid
->stripeShift
;
988 startlba_span
= (u8
)mr_spanset_get_span_block(instance
,
989 ld
, start_row
, pdBlock
, map
);
990 if (startlba_span
== SPAN_INVALID
) {
991 dev_info(&instance
->pdev
->dev
, "return from %s %d"
992 "for row 0x%llx,start strip %llx"
993 "endSrip %llx\n", __func__
, __LINE__
,
994 (unsigned long long)start_row
,
995 (unsigned long long)start_strip
,
996 (unsigned long long)endStrip
);
999 io_info
->start_span
= startlba_span
;
1000 io_info
->start_row
= start_row
;
1002 start_row
= mega_div64_32(start_strip
, raid
->rowDataSize
);
1003 endRow
= mega_div64_32(endStrip
, raid
->rowDataSize
);
1005 numRows
= (u8
)(endRow
- start_row
+ 1);
1008 * calculate region info.
1011 /* assume region is at the start of the first row */
1012 regStart
= start_row
<< raid
->stripeShift
;
1013 /* assume this IO needs the full row - we'll adjust if not true */
1014 regSize
= stripSize
;
1016 io_info
->do_fp_rlbypass
= raid
->capability
.fpBypassRegionLock
;
1018 /* Check if we can send this I/O via FastPath */
1019 if (raid
->capability
.fpCapable
) {
1021 io_info
->fpOkForIo
= (raid
->capability
.fpReadCapable
&&
1022 ((num_strips
== 1) ||
1024 fpReadAcrossStripe
));
1026 io_info
->fpOkForIo
= (raid
->capability
.fpWriteCapable
&&
1027 ((num_strips
== 1) ||
1029 fpWriteAcrossStripe
));
1031 io_info
->fpOkForIo
= false;
1034 /* single-strip IOs can always lock only the data needed */
1035 if (num_strips
== 1) {
1036 regStart
+= ref_in_start_stripe
;
1037 regSize
= numBlocks
;
1039 /* multi-strip IOs always need to full stripe locked */
1040 } else if (io_info
->IoforUnevenSpan
== 0) {
1042 * For Even span region lock optimization.
1043 * If the start strip is the last in the start row
1045 if (start_strip
== (start_row
+ 1) * raid
->rowDataSize
- 1) {
1046 regStart
+= ref_in_start_stripe
;
1047 /* initialize count to sectors from startref to end
1049 regSize
= stripSize
- ref_in_start_stripe
;
1052 /* add complete rows in the middle of the transfer */
1054 regSize
+= (numRows
-2) << raid
->stripeShift
;
1056 /* if IO ends within first strip of last row*/
1057 if (endStrip
== endRow
*raid
->rowDataSize
)
1058 regSize
+= ref_in_end_stripe
+1;
1060 regSize
+= stripSize
;
1063 * For Uneven span region lock optimization.
1064 * If the start strip is the last in the start row
1066 if (start_strip
== (get_strip_from_row(instance
, ld
, start_row
, map
) +
1067 SPAN_ROW_DATA_SIZE(map
, ld
, startlba_span
) - 1)) {
1068 regStart
+= ref_in_start_stripe
;
1069 /* initialize count to sectors from
1070 * startRef to end of strip
1072 regSize
= stripSize
- ref_in_start_stripe
;
1074 /* Add complete rows in the middle of the transfer*/
1077 /* Add complete rows in the middle of the transfer*/
1078 regSize
+= (numRows
-2) << raid
->stripeShift
;
1080 /* if IO ends within first strip of last row */
1081 if (endStrip
== get_strip_from_row(instance
, ld
, endRow
, map
))
1082 regSize
+= ref_in_end_stripe
+ 1;
1084 regSize
+= stripSize
;
1087 pRAID_Context
->timeout_value
=
1088 cpu_to_le16(raid
->fpIoTimeoutForLd
?
1089 raid
->fpIoTimeoutForLd
:
1090 map
->raidMap
.fpPdIoTimeoutSec
);
1091 if (instance
->adapter_type
== INVADER_SERIES
)
1092 pRAID_Context
->reg_lock_flags
= (isRead
) ?
1093 raid
->regTypeReqOnRead
: raid
->regTypeReqOnWrite
;
1094 else if (instance
->adapter_type
== THUNDERBOLT_SERIES
)
1095 pRAID_Context
->reg_lock_flags
= (isRead
) ?
1096 REGION_TYPE_SHARED_READ
: raid
->regTypeReqOnWrite
;
1097 pRAID_Context
->virtual_disk_tgt_id
= raid
->targetId
;
1098 pRAID_Context
->reg_lock_row_lba
= cpu_to_le64(regStart
);
1099 pRAID_Context
->reg_lock_length
= cpu_to_le32(regSize
);
1100 pRAID_Context
->config_seq_num
= raid
->seqNum
;
1101 /* save pointer to raid->LUN array */
1102 *raidLUN
= raid
->LUN
;
1105 /*Get Phy Params only if FP capable, or else leave it to MR firmware
1106 to do the calculation.*/
1107 if (io_info
->fpOkForIo
) {
1108 retval
= io_info
->IoforUnevenSpan
?
1109 mr_spanset_get_phy_params(instance
, ld
,
1110 start_strip
, ref_in_start_stripe
,
1111 io_info
, pRAID_Context
, map
) :
1112 MR_GetPhyParams(instance
, ld
, start_strip
,
1113 ref_in_start_stripe
, io_info
,
1114 pRAID_Context
, map
);
1115 /* If IO on an invalid Pd, then FP is not possible.*/
1116 if (io_info
->devHandle
== MR_DEVHANDLE_INVALID
)
1117 io_info
->fpOkForIo
= false;
1119 } else if (isRead
) {
1121 for (stripIdx
= 0; stripIdx
< num_strips
; stripIdx
++) {
1122 retval
= io_info
->IoforUnevenSpan
?
1123 mr_spanset_get_phy_params(instance
, ld
,
1124 start_strip
+ stripIdx
,
1125 ref_in_start_stripe
, io_info
,
1126 pRAID_Context
, map
) :
1127 MR_GetPhyParams(instance
, ld
,
1128 start_strip
+ stripIdx
, ref_in_start_stripe
,
1129 io_info
, pRAID_Context
, map
);
1138 ******************************************************************************
1140 * This routine pepare spanset info from Valid Raid map and store it into
1141 * local copy of ldSpanInfo per instance data structure.
1145 * ldSpanInfo - ldSpanInfo per HBA instance
1148 void mr_update_span_set(struct MR_DRV_RAID_MAP_ALL
*map
,
1149 PLD_SPAN_INFO ldSpanInfo
)
1152 u32 element
, span_row_width
;
1154 struct MR_LD_RAID
*raid
;
1155 LD_SPAN_SET
*span_set
, *span_set_prev
;
1156 struct MR_QUAD_ELEMENT
*quad
;
1161 for (ldCount
= 0; ldCount
< MAX_LOGICAL_DRIVES_EXT
; ldCount
++) {
1162 ld
= MR_TargetIdToLdGet(ldCount
, map
);
1163 if (ld
>= (MAX_LOGICAL_DRIVES_EXT
- 1))
1165 raid
= MR_LdRaidGet(ld
, map
);
1166 for (element
= 0; element
< MAX_QUAD_DEPTH
; element
++) {
1167 for (span
= 0; span
< raid
->spanDepth
; span
++) {
1168 if (le32_to_cpu(map
->raidMap
.ldSpanMap
[ld
].spanBlock
[span
].
1169 block_span_info
.noElements
) <
1172 span_set
= &(ldSpanInfo
[ld
].span_set
[element
]);
1173 quad
= &map
->raidMap
.ldSpanMap
[ld
].
1174 spanBlock
[span
].block_span_info
.
1177 span_set
->diff
= le32_to_cpu(quad
->diff
);
1179 for (count
= 0, span_row_width
= 0;
1180 count
< raid
->spanDepth
; count
++) {
1181 if (le32_to_cpu(map
->raidMap
.ldSpanMap
[ld
].
1184 noElements
) >= element
+ 1) {
1185 span_set
->strip_offset
[count
] =
1189 (ld
, count
, map
)->spanRowDataSize
;
1193 span_set
->span_row_data_width
= span_row_width
;
1194 span_row
= mega_div64_32(((le64_to_cpu(quad
->logEnd
) -
1195 le64_to_cpu(quad
->logStart
)) + le32_to_cpu(quad
->diff
)),
1196 le32_to_cpu(quad
->diff
));
1199 span_set
->log_start_lba
= 0;
1200 span_set
->log_end_lba
=
1201 ((span_row
<< raid
->stripeShift
)
1202 * span_row_width
) - 1;
1204 span_set
->span_row_start
= 0;
1205 span_set
->span_row_end
= span_row
- 1;
1207 span_set
->data_strip_start
= 0;
1208 span_set
->data_strip_end
=
1209 (span_row
* span_row_width
) - 1;
1211 span_set
->data_row_start
= 0;
1212 span_set
->data_row_end
=
1213 (span_row
* le32_to_cpu(quad
->diff
)) - 1;
1215 span_set_prev
= &(ldSpanInfo
[ld
].
1216 span_set
[element
- 1]);
1217 span_set
->log_start_lba
=
1218 span_set_prev
->log_end_lba
+ 1;
1219 span_set
->log_end_lba
=
1220 span_set
->log_start_lba
+
1221 ((span_row
<< raid
->stripeShift
)
1222 * span_row_width
) - 1;
1224 span_set
->span_row_start
=
1225 span_set_prev
->span_row_end
+ 1;
1226 span_set
->span_row_end
=
1227 span_set
->span_row_start
+ span_row
- 1;
1229 span_set
->data_strip_start
=
1230 span_set_prev
->data_strip_end
+ 1;
1231 span_set
->data_strip_end
=
1232 span_set
->data_strip_start
+
1233 (span_row
* span_row_width
) - 1;
1235 span_set
->data_row_start
=
1236 span_set_prev
->data_row_end
+ 1;
1237 span_set
->data_row_end
=
1238 span_set
->data_row_start
+
1239 (span_row
* le32_to_cpu(quad
->diff
)) - 1;
1243 if (span
== raid
->spanDepth
)
1249 void mr_update_load_balance_params(struct MR_DRV_RAID_MAP_ALL
*drv_map
,
1250 struct LD_LOAD_BALANCE_INFO
*lbInfo
)
1254 struct MR_LD_RAID
*raid
;
1256 if (lb_pending_cmds
> 128 || lb_pending_cmds
< 1)
1257 lb_pending_cmds
= LB_PENDING_CMDS_DEFAULT
;
1259 for (ldCount
= 0; ldCount
< MAX_LOGICAL_DRIVES_EXT
; ldCount
++) {
1260 ld
= MR_TargetIdToLdGet(ldCount
, drv_map
);
1261 if (ld
>= MAX_LOGICAL_DRIVES_EXT
) {
1262 lbInfo
[ldCount
].loadBalanceFlag
= 0;
1266 raid
= MR_LdRaidGet(ld
, drv_map
);
1267 if ((raid
->level
!= 1) ||
1268 (raid
->ldState
!= MR_LD_STATE_OPTIMAL
)) {
1269 lbInfo
[ldCount
].loadBalanceFlag
= 0;
1272 lbInfo
[ldCount
].loadBalanceFlag
= 1;
1276 u8
megasas_get_best_arm_pd(struct megasas_instance
*instance
,
1277 struct LD_LOAD_BALANCE_INFO
*lbInfo
,
1278 struct IO_REQUEST_INFO
*io_info
,
1279 struct MR_DRV_RAID_MAP_ALL
*drv_map
)
1281 struct MR_LD_RAID
*raid
;
1283 u16 pend0
, pend1
, ld
;
1285 u8 bestArm
, pd0
, pd1
, span
, arm
;
1286 u32 arRef
, span_row_size
;
1288 u64 block
= io_info
->ldStartBlock
;
1289 u32 count
= io_info
->numBlocks
;
1291 span
= ((io_info
->span_arm
& RAID_CTX_SPANARM_SPAN_MASK
)
1292 >> RAID_CTX_SPANARM_SPAN_SHIFT
);
1293 arm
= (io_info
->span_arm
& RAID_CTX_SPANARM_ARM_MASK
);
1295 ld
= MR_TargetIdToLdGet(io_info
->ldTgtId
, drv_map
);
1296 raid
= MR_LdRaidGet(ld
, drv_map
);
1297 span_row_size
= instance
->UnevenSpanSupport
?
1298 SPAN_ROW_SIZE(drv_map
, ld
, span
) : raid
->rowSize
;
1300 arRef
= MR_LdSpanArrayGet(ld
, span
, drv_map
);
1301 pd0
= MR_ArPdGet(arRef
, arm
, drv_map
);
1302 pd1
= MR_ArPdGet(arRef
, (arm
+ 1) >= span_row_size
?
1303 (arm
+ 1 - span_row_size
) : arm
+ 1, drv_map
);
1305 /* Get PD1 Dev Handle */
1307 pd1_dev_handle
= MR_PdDevHandleGet(pd1
, drv_map
);
1309 if (pd1_dev_handle
== MR_DEVHANDLE_INVALID
) {
1312 /* get the pending cmds for the data and mirror arms */
1313 pend0
= atomic_read(&lbInfo
->scsi_pending_cmds
[pd0
]);
1314 pend1
= atomic_read(&lbInfo
->scsi_pending_cmds
[pd1
]);
1316 /* Determine the disk whose head is nearer to the req. block */
1317 diff0
= ABS_DIFF(block
, lbInfo
->last_accessed_block
[pd0
]);
1318 diff1
= ABS_DIFF(block
, lbInfo
->last_accessed_block
[pd1
]);
1319 bestArm
= (diff0
<= diff1
? arm
: arm
^ 1);
1321 /* Make balance count from 16 to 4 to
1322 * keep driver in sync with Firmware
1324 if ((bestArm
== arm
&& pend0
> pend1
+ lb_pending_cmds
) ||
1325 (bestArm
!= arm
&& pend1
> pend0
+ lb_pending_cmds
))
1328 /* Update the last accessed block on the correct pd */
1330 (span
<< RAID_CTX_SPANARM_SPAN_SHIFT
) | bestArm
;
1331 io_info
->pd_after_lb
= (bestArm
== arm
) ? pd0
: pd1
;
1334 lbInfo
->last_accessed_block
[io_info
->pd_after_lb
] = block
+ count
- 1;
1335 return io_info
->pd_after_lb
;
1338 __le16
get_updated_dev_handle(struct megasas_instance
*instance
,
1339 struct LD_LOAD_BALANCE_INFO
*lbInfo
,
1340 struct IO_REQUEST_INFO
*io_info
,
1341 struct MR_DRV_RAID_MAP_ALL
*drv_map
)
1346 /* get best new arm (PD ID) */
1347 arm_pd
= megasas_get_best_arm_pd(instance
, lbInfo
, io_info
, drv_map
);
1348 devHandle
= MR_PdDevHandleGet(arm_pd
, drv_map
);
1349 io_info
->pd_interface
= MR_PdInterfaceTypeGet(arm_pd
, drv_map
);
1350 atomic_inc(&lbInfo
->scsi_pending_cmds
[arm_pd
]);