2 * Linux MegaRAID driver for SAS based RAID controllers
4 * Copyright (c) 2009-2013 LSI Corporation
5 * Copyright (c) 2013-2016 Avago Technologies
6 * Copyright (c) 2016-2018 Broadcom Inc.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * FILE: megaraid_sas_fp.c
23 * Authors: Broadcom Inc.
27 * Kashyap Desai <kashyap.desai@broadcom.com>
28 * Sumit Saxena <sumit.saxena@broadcom.com>
30 * Send feedback to: megaraidlinux.pdl@broadcom.com
33 #include <linux/kernel.h>
34 #include <linux/types.h>
35 #include <linux/pci.h>
36 #include <linux/list.h>
37 #include <linux/moduleparam.h>
38 #include <linux/module.h>
39 #include <linux/spinlock.h>
40 #include <linux/interrupt.h>
41 #include <linux/delay.h>
42 #include <linux/uio.h>
43 #include <linux/uaccess.h>
45 #include <linux/compat.h>
46 #include <linux/blkdev.h>
47 #include <linux/poll.h>
49 #include <scsi/scsi.h>
50 #include <scsi/scsi_cmnd.h>
51 #include <scsi/scsi_device.h>
52 #include <scsi/scsi_host.h>
54 #include "megaraid_sas_fusion.h"
55 #include "megaraid_sas.h"
56 #include <asm/div64.h>
58 #define LB_PENDING_CMDS_DEFAULT 4
59 static unsigned int lb_pending_cmds
= LB_PENDING_CMDS_DEFAULT
;
60 module_param(lb_pending_cmds
, int, S_IRUGO
);
61 MODULE_PARM_DESC(lb_pending_cmds
, "Change raid-1 load balancing outstanding "
62 "threshold. Valid Values are 1-128. Default: 4");
65 #define ABS_DIFF(a, b) (((a) > (b)) ? ((a) - (b)) : ((b) - (a)))
66 #define MR_LD_STATE_OPTIMAL 3
68 #define SPAN_ROW_SIZE(map, ld, index_) (MR_LdSpanPtrGet(ld, index_, map)->spanRowSize)
69 #define SPAN_ROW_DATA_SIZE(map_, ld, index_) (MR_LdSpanPtrGet(ld, index_, map)->spanRowDataSize)
70 #define SPAN_INVALID 0xff
73 static void mr_update_span_set(struct MR_DRV_RAID_MAP_ALL
*map
,
74 PLD_SPAN_INFO ldSpanInfo
);
75 static u8
mr_spanset_get_phy_params(struct megasas_instance
*instance
, u32 ld
,
76 u64 stripRow
, u16 stripRef
, struct IO_REQUEST_INFO
*io_info
,
77 struct RAID_CONTEXT
*pRAID_Context
, struct MR_DRV_RAID_MAP_ALL
*map
);
78 static u64
get_row_from_strip(struct megasas_instance
*instance
, u32 ld
,
79 u64 strip
, struct MR_DRV_RAID_MAP_ALL
*map
);
81 u32
mega_mod64(u64 dividend
, u32 divisor
)
87 printk(KERN_ERR
"megasas : DIVISOR is zero, in div fn\n");
89 remainder
= do_div(d
, divisor
);
94 * @param dividend : Dividend
95 * @param divisor : Divisor
99 u64
mega_div64_32(uint64_t dividend
, uint32_t divisor
)
105 printk(KERN_ERR
"megasas : DIVISOR is zero in mod fn\n");
108 remainder
= do_div(d
, divisor
);
113 struct MR_LD_RAID
*MR_LdRaidGet(u32 ld
, struct MR_DRV_RAID_MAP_ALL
*map
)
115 return &map
->raidMap
.ldSpanMap
[ld
].ldRaid
;
118 static struct MR_SPAN_BLOCK_INFO
*MR_LdSpanInfoGet(u32 ld
,
119 struct MR_DRV_RAID_MAP_ALL
122 return &map
->raidMap
.ldSpanMap
[ld
].spanBlock
[0];
125 static u8
MR_LdDataArmGet(u32 ld
, u32 armIdx
, struct MR_DRV_RAID_MAP_ALL
*map
)
127 return map
->raidMap
.ldSpanMap
[ld
].dataArmMap
[armIdx
];
130 u16
MR_ArPdGet(u32 ar
, u32 arm
, struct MR_DRV_RAID_MAP_ALL
*map
)
132 return le16_to_cpu(map
->raidMap
.arMapInfo
[ar
].pd
[arm
]);
135 u16
MR_LdSpanArrayGet(u32 ld
, u32 span
, struct MR_DRV_RAID_MAP_ALL
*map
)
137 return le16_to_cpu(map
->raidMap
.ldSpanMap
[ld
].spanBlock
[span
].span
.arrayRef
);
140 __le16
MR_PdDevHandleGet(u32 pd
, struct MR_DRV_RAID_MAP_ALL
*map
)
142 return map
->raidMap
.devHndlInfo
[pd
].curDevHdl
;
145 static u8
MR_PdInterfaceTypeGet(u32 pd
, struct MR_DRV_RAID_MAP_ALL
*map
)
147 return map
->raidMap
.devHndlInfo
[pd
].interfaceType
;
150 u16
MR_GetLDTgtId(u32 ld
, struct MR_DRV_RAID_MAP_ALL
*map
)
152 return le16_to_cpu(map
->raidMap
.ldSpanMap
[ld
].ldRaid
.targetId
);
155 u16
MR_TargetIdToLdGet(u32 ldTgtId
, struct MR_DRV_RAID_MAP_ALL
*map
)
157 return map
->raidMap
.ldTgtIdToLd
[ldTgtId
];
160 static struct MR_LD_SPAN
*MR_LdSpanPtrGet(u32 ld
, u32 span
,
161 struct MR_DRV_RAID_MAP_ALL
*map
)
163 return &map
->raidMap
.ldSpanMap
[ld
].spanBlock
[span
].span
;
167 * This function will Populate Driver Map using firmware raid map
169 static int MR_PopulateDrvRaidMap(struct megasas_instance
*instance
, u64 map_id
)
171 struct fusion_context
*fusion
= instance
->ctrl_context
;
172 struct MR_FW_RAID_MAP_ALL
*fw_map_old
= NULL
;
173 struct MR_FW_RAID_MAP
*pFwRaidMap
= NULL
;
176 struct MR_FW_RAID_MAP_DYNAMIC
*fw_map_dyn
;
177 struct MR_FW_RAID_MAP_EXT
*fw_map_ext
;
178 struct MR_RAID_MAP_DESC_TABLE
*desc_table
;
181 struct MR_DRV_RAID_MAP_ALL
*drv_map
=
182 fusion
->ld_drv_map
[(map_id
& 1)];
183 struct MR_DRV_RAID_MAP
*pDrvRaidMap
= &drv_map
->raidMap
;
184 void *raid_map_data
= NULL
;
186 memset(drv_map
, 0, fusion
->drv_map_sz
);
187 memset(pDrvRaidMap
->ldTgtIdToLd
,
188 0xff, (sizeof(u16
) * MAX_LOGICAL_DRIVES_DYN
));
190 if (instance
->max_raid_mapsize
) {
191 fw_map_dyn
= fusion
->ld_map
[(map_id
& 1)];
193 (struct MR_RAID_MAP_DESC_TABLE
*)((void *)fw_map_dyn
+ le32_to_cpu(fw_map_dyn
->desc_table_offset
));
194 if (desc_table
!= fw_map_dyn
->raid_map_desc_table
)
195 dev_dbg(&instance
->pdev
->dev
, "offsets of desc table are not matching desc %p original %p\n",
196 desc_table
, fw_map_dyn
->raid_map_desc_table
);
198 ld_count
= (u16
)le16_to_cpu(fw_map_dyn
->ld_count
);
199 pDrvRaidMap
->ldCount
= (__le16
)cpu_to_le16(ld_count
);
200 pDrvRaidMap
->fpPdIoTimeoutSec
=
201 fw_map_dyn
->fp_pd_io_timeout_sec
;
202 pDrvRaidMap
->totalSize
=
203 cpu_to_le32(sizeof(struct MR_DRV_RAID_MAP_ALL
));
204 /* point to actual data starting point*/
205 raid_map_data
= (void *)fw_map_dyn
+
206 le32_to_cpu(fw_map_dyn
->desc_table_offset
) +
207 le32_to_cpu(fw_map_dyn
->desc_table_size
);
209 for (i
= 0; i
< le32_to_cpu(fw_map_dyn
->desc_table_num_elements
); ++i
) {
210 switch (le32_to_cpu(desc_table
->raid_map_desc_type
)) {
211 case RAID_MAP_DESC_TYPE_DEVHDL_INFO
:
212 fw_map_dyn
->dev_hndl_info
=
213 (struct MR_DEV_HANDLE_INFO
*)(raid_map_data
+ le32_to_cpu(desc_table
->raid_map_desc_offset
));
214 memcpy(pDrvRaidMap
->devHndlInfo
,
215 fw_map_dyn
->dev_hndl_info
,
216 sizeof(struct MR_DEV_HANDLE_INFO
) *
217 le32_to_cpu(desc_table
->raid_map_desc_elements
));
219 case RAID_MAP_DESC_TYPE_TGTID_INFO
:
220 fw_map_dyn
->ld_tgt_id_to_ld
=
221 (u16
*)(raid_map_data
+
222 le32_to_cpu(desc_table
->raid_map_desc_offset
));
223 for (j
= 0; j
< le32_to_cpu(desc_table
->raid_map_desc_elements
); j
++) {
224 pDrvRaidMap
->ldTgtIdToLd
[j
] =
225 le16_to_cpu(fw_map_dyn
->ld_tgt_id_to_ld
[j
]);
228 case RAID_MAP_DESC_TYPE_ARRAY_INFO
:
229 fw_map_dyn
->ar_map_info
=
230 (struct MR_ARRAY_INFO
*)
231 (raid_map_data
+ le32_to_cpu(desc_table
->raid_map_desc_offset
));
232 memcpy(pDrvRaidMap
->arMapInfo
,
233 fw_map_dyn
->ar_map_info
,
234 sizeof(struct MR_ARRAY_INFO
) *
235 le32_to_cpu(desc_table
->raid_map_desc_elements
));
237 case RAID_MAP_DESC_TYPE_SPAN_INFO
:
238 fw_map_dyn
->ld_span_map
=
239 (struct MR_LD_SPAN_MAP
*)
241 le32_to_cpu(desc_table
->raid_map_desc_offset
));
242 memcpy(pDrvRaidMap
->ldSpanMap
,
243 fw_map_dyn
->ld_span_map
,
244 sizeof(struct MR_LD_SPAN_MAP
) *
245 le32_to_cpu(desc_table
->raid_map_desc_elements
));
248 dev_dbg(&instance
->pdev
->dev
, "wrong number of desctableElements %d\n",
249 fw_map_dyn
->desc_table_num_elements
);
254 } else if (instance
->supportmax256vd
) {
256 (struct MR_FW_RAID_MAP_EXT
*)fusion
->ld_map
[(map_id
& 1)];
257 ld_count
= (u16
)le16_to_cpu(fw_map_ext
->ldCount
);
258 if (ld_count
> MAX_LOGICAL_DRIVES_EXT
) {
259 dev_dbg(&instance
->pdev
->dev
, "megaraid_sas: LD count exposed in RAID map in not valid\n");
263 pDrvRaidMap
->ldCount
= (__le16
)cpu_to_le16(ld_count
);
264 pDrvRaidMap
->fpPdIoTimeoutSec
= fw_map_ext
->fpPdIoTimeoutSec
;
265 for (i
= 0; i
< (MAX_LOGICAL_DRIVES_EXT
); i
++)
266 pDrvRaidMap
->ldTgtIdToLd
[i
] =
267 (u16
)fw_map_ext
->ldTgtIdToLd
[i
];
268 memcpy(pDrvRaidMap
->ldSpanMap
, fw_map_ext
->ldSpanMap
,
269 sizeof(struct MR_LD_SPAN_MAP
) * ld_count
);
270 memcpy(pDrvRaidMap
->arMapInfo
, fw_map_ext
->arMapInfo
,
271 sizeof(struct MR_ARRAY_INFO
) * MAX_API_ARRAYS_EXT
);
272 memcpy(pDrvRaidMap
->devHndlInfo
, fw_map_ext
->devHndlInfo
,
273 sizeof(struct MR_DEV_HANDLE_INFO
) *
274 MAX_RAIDMAP_PHYSICAL_DEVICES
);
276 /* New Raid map will not set totalSize, so keep expected value
277 * for legacy code in ValidateMapInfo
279 pDrvRaidMap
->totalSize
=
280 cpu_to_le32(sizeof(struct MR_FW_RAID_MAP_EXT
));
282 fw_map_old
= (struct MR_FW_RAID_MAP_ALL
*)
283 fusion
->ld_map
[(map_id
& 1)];
284 pFwRaidMap
= &fw_map_old
->raidMap
;
285 ld_count
= (u16
)le32_to_cpu(pFwRaidMap
->ldCount
);
286 if (ld_count
> MAX_LOGICAL_DRIVES
) {
287 dev_dbg(&instance
->pdev
->dev
,
288 "LD count exposed in RAID map in not valid\n");
292 pDrvRaidMap
->totalSize
= pFwRaidMap
->totalSize
;
293 pDrvRaidMap
->ldCount
= (__le16
)cpu_to_le16(ld_count
);
294 pDrvRaidMap
->fpPdIoTimeoutSec
= pFwRaidMap
->fpPdIoTimeoutSec
;
295 for (i
= 0; i
< MAX_RAIDMAP_LOGICAL_DRIVES
+ MAX_RAIDMAP_VIEWS
; i
++)
296 pDrvRaidMap
->ldTgtIdToLd
[i
] =
297 (u8
)pFwRaidMap
->ldTgtIdToLd
[i
];
298 for (i
= 0; i
< ld_count
; i
++) {
299 pDrvRaidMap
->ldSpanMap
[i
] = pFwRaidMap
->ldSpanMap
[i
];
301 memcpy(pDrvRaidMap
->arMapInfo
, pFwRaidMap
->arMapInfo
,
302 sizeof(struct MR_ARRAY_INFO
) * MAX_RAIDMAP_ARRAYS
);
303 memcpy(pDrvRaidMap
->devHndlInfo
, pFwRaidMap
->devHndlInfo
,
304 sizeof(struct MR_DEV_HANDLE_INFO
) *
305 MAX_RAIDMAP_PHYSICAL_DEVICES
);
312 * This function will validate Map info data provided by FW
314 u8
MR_ValidateMapInfo(struct megasas_instance
*instance
, u64 map_id
)
316 struct fusion_context
*fusion
;
317 struct MR_DRV_RAID_MAP_ALL
*drv_map
;
318 struct MR_DRV_RAID_MAP
*pDrvRaidMap
;
319 struct LD_LOAD_BALANCE_INFO
*lbInfo
;
320 PLD_SPAN_INFO ldSpanInfo
;
321 struct MR_LD_RAID
*raid
;
326 if (MR_PopulateDrvRaidMap(instance
, map_id
))
329 fusion
= instance
->ctrl_context
;
330 drv_map
= fusion
->ld_drv_map
[(map_id
& 1)];
331 pDrvRaidMap
= &drv_map
->raidMap
;
333 lbInfo
= fusion
->load_balance_info
;
334 ldSpanInfo
= fusion
->log_to_span
;
336 if (instance
->max_raid_mapsize
)
337 expected_size
= sizeof(struct MR_DRV_RAID_MAP_ALL
);
338 else if (instance
->supportmax256vd
)
339 expected_size
= sizeof(struct MR_FW_RAID_MAP_EXT
);
342 (sizeof(struct MR_FW_RAID_MAP
) - sizeof(struct MR_LD_SPAN_MAP
) +
343 (sizeof(struct MR_LD_SPAN_MAP
) * le16_to_cpu(pDrvRaidMap
->ldCount
)));
345 if (le32_to_cpu(pDrvRaidMap
->totalSize
) != expected_size
) {
346 dev_dbg(&instance
->pdev
->dev
, "megasas: map info structure size 0x%x",
347 le32_to_cpu(pDrvRaidMap
->totalSize
));
348 dev_dbg(&instance
->pdev
->dev
, "is not matching expected size 0x%x\n",
349 (unsigned int)expected_size
);
350 dev_err(&instance
->pdev
->dev
, "megasas: span map %x, pDrvRaidMap->totalSize : %x\n",
351 (unsigned int)sizeof(struct MR_LD_SPAN_MAP
),
352 le32_to_cpu(pDrvRaidMap
->totalSize
));
356 if (instance
->UnevenSpanSupport
)
357 mr_update_span_set(drv_map
, ldSpanInfo
);
360 mr_update_load_balance_params(drv_map
, lbInfo
);
362 num_lds
= le16_to_cpu(drv_map
->raidMap
.ldCount
);
364 /*Convert Raid capability values to CPU arch */
365 for (i
= 0; (num_lds
> 0) && (i
< MAX_LOGICAL_DRIVES_EXT
); i
++) {
366 ld
= MR_TargetIdToLdGet(i
, drv_map
);
368 /* For non existing VDs, iterate to next VD*/
369 if (ld
>= (MAX_LOGICAL_DRIVES_EXT
- 1))
372 raid
= MR_LdRaidGet(ld
, drv_map
);
373 le32_to_cpus((u32
*)&raid
->capability
);
381 u32
MR_GetSpanBlock(u32 ld
, u64 row
, u64
*span_blk
,
382 struct MR_DRV_RAID_MAP_ALL
*map
)
384 struct MR_SPAN_BLOCK_INFO
*pSpanBlock
= MR_LdSpanInfoGet(ld
, map
);
385 struct MR_QUAD_ELEMENT
*quad
;
386 struct MR_LD_RAID
*raid
= MR_LdRaidGet(ld
, map
);
389 for (span
= 0; span
< raid
->spanDepth
; span
++, pSpanBlock
++) {
391 for (j
= 0; j
< le32_to_cpu(pSpanBlock
->block_span_info
.noElements
); j
++) {
392 quad
= &pSpanBlock
->block_span_info
.quad
[j
];
394 if (le32_to_cpu(quad
->diff
) == 0)
396 if (le64_to_cpu(quad
->logStart
) <= row
&& row
<=
397 le64_to_cpu(quad
->logEnd
) && (mega_mod64(row
- le64_to_cpu(quad
->logStart
),
398 le32_to_cpu(quad
->diff
))) == 0) {
399 if (span_blk
!= NULL
) {
401 blk
= mega_div64_32((row
-le64_to_cpu(quad
->logStart
)), le32_to_cpu(quad
->diff
));
404 blk
= (blk
+ le64_to_cpu(quad
->offsetInSpan
)) << raid
->stripeShift
;
415 ******************************************************************************
417 * This routine calculates the Span block for given row using spanset.
420 * instance - HBA instance
421 * ld - Logical drive number
428 * block - Absolute Block number in the physical disk
429 * div_error - Devide error code.
432 u32
mr_spanset_get_span_block(struct megasas_instance
*instance
,
433 u32 ld
, u64 row
, u64
*span_blk
, struct MR_DRV_RAID_MAP_ALL
*map
)
435 struct fusion_context
*fusion
= instance
->ctrl_context
;
436 struct MR_LD_RAID
*raid
= MR_LdRaidGet(ld
, map
);
437 LD_SPAN_SET
*span_set
;
438 struct MR_QUAD_ELEMENT
*quad
;
440 PLD_SPAN_INFO ldSpanInfo
= fusion
->log_to_span
;
442 for (info
= 0; info
< MAX_QUAD_DEPTH
; info
++) {
443 span_set
= &(ldSpanInfo
[ld
].span_set
[info
]);
445 if (span_set
->span_row_data_width
== 0)
448 if (row
> span_set
->data_row_end
)
451 for (span
= 0; span
< raid
->spanDepth
; span
++)
452 if (le32_to_cpu(map
->raidMap
.ldSpanMap
[ld
].spanBlock
[span
].
453 block_span_info
.noElements
) >= info
+1) {
454 quad
= &map
->raidMap
.ldSpanMap
[ld
].
456 block_span_info
.quad
[info
];
457 if (le32_to_cpu(quad
->diff
) == 0)
459 if (le64_to_cpu(quad
->logStart
) <= row
&&
460 row
<= le64_to_cpu(quad
->logEnd
) &&
461 (mega_mod64(row
- le64_to_cpu(quad
->logStart
),
462 le32_to_cpu(quad
->diff
))) == 0) {
463 if (span_blk
!= NULL
) {
466 ((row
- le64_to_cpu(quad
->logStart
)),
467 le32_to_cpu(quad
->diff
));
468 blk
= (blk
+ le64_to_cpu(quad
->offsetInSpan
))
469 << raid
->stripeShift
;
480 ******************************************************************************
482 * This routine calculates the row for given strip using spanset.
485 * instance - HBA instance
486 * ld - Logical drive number
492 * row - row associated with strip
495 static u64
get_row_from_strip(struct megasas_instance
*instance
,
496 u32 ld
, u64 strip
, struct MR_DRV_RAID_MAP_ALL
*map
)
498 struct fusion_context
*fusion
= instance
->ctrl_context
;
499 struct MR_LD_RAID
*raid
= MR_LdRaidGet(ld
, map
);
500 LD_SPAN_SET
*span_set
;
501 PLD_SPAN_INFO ldSpanInfo
= fusion
->log_to_span
;
502 u32 info
, strip_offset
, span
, span_offset
;
503 u64 span_set_Strip
, span_set_Row
, retval
;
505 for (info
= 0; info
< MAX_QUAD_DEPTH
; info
++) {
506 span_set
= &(ldSpanInfo
[ld
].span_set
[info
]);
508 if (span_set
->span_row_data_width
== 0)
510 if (strip
> span_set
->data_strip_end
)
513 span_set_Strip
= strip
- span_set
->data_strip_start
;
514 strip_offset
= mega_mod64(span_set_Strip
,
515 span_set
->span_row_data_width
);
516 span_set_Row
= mega_div64_32(span_set_Strip
,
517 span_set
->span_row_data_width
) * span_set
->diff
;
518 for (span
= 0, span_offset
= 0; span
< raid
->spanDepth
; span
++)
519 if (le32_to_cpu(map
->raidMap
.ldSpanMap
[ld
].spanBlock
[span
].
520 block_span_info
.noElements
) >= info
+1) {
522 span_set
->strip_offset
[span
])
528 retval
= (span_set
->data_row_start
+ span_set_Row
+
537 ******************************************************************************
539 * This routine calculates the Start Strip for given row using spanset.
542 * instance - HBA instance
543 * ld - Logical drive number
549 * Strip - Start strip associated with row
552 static u64
get_strip_from_row(struct megasas_instance
*instance
,
553 u32 ld
, u64 row
, struct MR_DRV_RAID_MAP_ALL
*map
)
555 struct fusion_context
*fusion
= instance
->ctrl_context
;
556 struct MR_LD_RAID
*raid
= MR_LdRaidGet(ld
, map
);
557 LD_SPAN_SET
*span_set
;
558 struct MR_QUAD_ELEMENT
*quad
;
559 PLD_SPAN_INFO ldSpanInfo
= fusion
->log_to_span
;
563 for (info
= 0; info
< MAX_QUAD_DEPTH
; info
++) {
564 span_set
= &(ldSpanInfo
[ld
].span_set
[info
]);
566 if (span_set
->span_row_data_width
== 0)
568 if (row
> span_set
->data_row_end
)
571 for (span
= 0; span
< raid
->spanDepth
; span
++)
572 if (le32_to_cpu(map
->raidMap
.ldSpanMap
[ld
].spanBlock
[span
].
573 block_span_info
.noElements
) >= info
+1) {
574 quad
= &map
->raidMap
.ldSpanMap
[ld
].
575 spanBlock
[span
].block_span_info
.quad
[info
];
576 if (le64_to_cpu(quad
->logStart
) <= row
&&
577 row
<= le64_to_cpu(quad
->logEnd
) &&
578 mega_mod64((row
- le64_to_cpu(quad
->logStart
)),
579 le32_to_cpu(quad
->diff
)) == 0) {
580 strip
= mega_div64_32
581 (((row
- span_set
->data_row_start
)
582 - le64_to_cpu(quad
->logStart
)),
583 le32_to_cpu(quad
->diff
));
584 strip
*= span_set
->span_row_data_width
;
585 strip
+= span_set
->data_strip_start
;
586 strip
+= span_set
->strip_offset
[span
];
591 dev_err(&instance
->pdev
->dev
, "get_strip_from_row"
592 "returns invalid strip for ld=%x, row=%lx\n",
593 ld
, (long unsigned int)row
);
598 ******************************************************************************
600 * This routine calculates the Physical Arm for given strip using spanset.
603 * instance - HBA instance
604 * ld - Logical drive number
610 * Phys Arm - Phys Arm associated with strip
613 static u32
get_arm_from_strip(struct megasas_instance
*instance
,
614 u32 ld
, u64 strip
, struct MR_DRV_RAID_MAP_ALL
*map
)
616 struct fusion_context
*fusion
= instance
->ctrl_context
;
617 struct MR_LD_RAID
*raid
= MR_LdRaidGet(ld
, map
);
618 LD_SPAN_SET
*span_set
;
619 PLD_SPAN_INFO ldSpanInfo
= fusion
->log_to_span
;
620 u32 info
, strip_offset
, span
, span_offset
, retval
;
622 for (info
= 0 ; info
< MAX_QUAD_DEPTH
; info
++) {
623 span_set
= &(ldSpanInfo
[ld
].span_set
[info
]);
625 if (span_set
->span_row_data_width
== 0)
627 if (strip
> span_set
->data_strip_end
)
630 strip_offset
= (uint
)mega_mod64
631 ((strip
- span_set
->data_strip_start
),
632 span_set
->span_row_data_width
);
634 for (span
= 0, span_offset
= 0; span
< raid
->spanDepth
; span
++)
635 if (le32_to_cpu(map
->raidMap
.ldSpanMap
[ld
].spanBlock
[span
].
636 block_span_info
.noElements
) >= info
+1) {
638 span_set
->strip_offset
[span
])
640 span_set
->strip_offset
[span
];
645 retval
= (strip_offset
- span_offset
);
649 dev_err(&instance
->pdev
->dev
, "get_arm_from_strip"
650 "returns invalid arm for ld=%x strip=%lx\n",
651 ld
, (long unsigned int)strip
);
656 /* This Function will return Phys arm */
657 u8
get_arm(struct megasas_instance
*instance
, u32 ld
, u8 span
, u64 stripe
,
658 struct MR_DRV_RAID_MAP_ALL
*map
)
660 struct MR_LD_RAID
*raid
= MR_LdRaidGet(ld
, map
);
661 /* Need to check correct default value */
664 switch (raid
->level
) {
668 arm
= mega_mod64(stripe
, SPAN_ROW_SIZE(map
, ld
, span
));
671 /* start with logical arm */
672 arm
= get_arm_from_strip(instance
, ld
, stripe
, map
);
683 ******************************************************************************
685 * This routine calculates the arm, span and block for the specified stripe and
686 * reference in stripe using spanset
690 * ld - Logical drive number
691 * stripRow - Stripe number
692 * stripRef - Reference in stripe
697 * block - Absolute Block number in the physical disk
699 static u8
mr_spanset_get_phy_params(struct megasas_instance
*instance
, u32 ld
,
700 u64 stripRow
, u16 stripRef
, struct IO_REQUEST_INFO
*io_info
,
701 struct RAID_CONTEXT
*pRAID_Context
,
702 struct MR_DRV_RAID_MAP_ALL
*map
)
704 struct MR_LD_RAID
*raid
= MR_LdRaidGet(ld
, map
);
705 u32 pd
, arRef
, r1_alt_pd
;
709 u64
*pdBlock
= &io_info
->pdBlock
;
710 __le16
*pDevHandle
= &io_info
->devHandle
;
711 u8
*pPdInterface
= &io_info
->pd_interface
;
712 u32 logArm
, rowMod
, armQ
, arm
;
713 struct fusion_context
*fusion
;
715 fusion
= instance
->ctrl_context
;
716 *pDevHandle
= cpu_to_le16(MR_DEVHANDLE_INVALID
);
718 /*Get row and span from io_info for Uneven Span IO.*/
719 row
= io_info
->start_row
;
720 span
= io_info
->start_span
;
723 if (raid
->level
== 6) {
724 logArm
= get_arm_from_strip(instance
, ld
, stripRow
, map
);
727 rowMod
= mega_mod64(row
, SPAN_ROW_SIZE(map
, ld
, span
));
728 armQ
= SPAN_ROW_SIZE(map
, ld
, span
) - 1 - rowMod
;
729 arm
= armQ
+ 1 + logArm
;
730 if (arm
>= SPAN_ROW_SIZE(map
, ld
, span
))
731 arm
-= SPAN_ROW_SIZE(map
, ld
, span
);
734 /* Calculate the arm */
735 physArm
= get_arm(instance
, ld
, span
, stripRow
, map
);
739 arRef
= MR_LdSpanArrayGet(ld
, span
, map
);
740 pd
= MR_ArPdGet(arRef
, physArm
, map
);
742 if (pd
!= MR_PD_INVALID
) {
743 *pDevHandle
= MR_PdDevHandleGet(pd
, map
);
744 *pPdInterface
= MR_PdInterfaceTypeGet(pd
, map
);
745 /* get second pd also for raid 1/10 fast path writes*/
746 if ((instance
->adapter_type
>= VENTURA_SERIES
) &&
747 (raid
->level
== 1) &&
749 r1_alt_pd
= MR_ArPdGet(arRef
, physArm
+ 1, map
);
750 if (r1_alt_pd
!= MR_PD_INVALID
)
751 io_info
->r1_alt_dev_handle
=
752 MR_PdDevHandleGet(r1_alt_pd
, map
);
755 if ((raid
->level
>= 5) &&
756 ((instance
->adapter_type
== THUNDERBOLT_SERIES
) ||
757 ((instance
->adapter_type
== INVADER_SERIES
) &&
758 (raid
->regTypeReqOnRead
!= REGION_TYPE_UNUSED
))))
759 pRAID_Context
->reg_lock_flags
= REGION_TYPE_EXCLUSIVE
;
760 else if (raid
->level
== 1) {
761 physArm
= physArm
+ 1;
762 pd
= MR_ArPdGet(arRef
, physArm
, map
);
763 if (pd
!= MR_PD_INVALID
) {
764 *pDevHandle
= MR_PdDevHandleGet(pd
, map
);
765 *pPdInterface
= MR_PdInterfaceTypeGet(pd
, map
);
770 *pdBlock
+= stripRef
+ le64_to_cpu(MR_LdSpanPtrGet(ld
, span
, map
)->startBlk
);
771 if (instance
->adapter_type
>= VENTURA_SERIES
) {
772 ((struct RAID_CONTEXT_G35
*)pRAID_Context
)->span_arm
=
773 (span
<< RAID_CTX_SPANARM_SPAN_SHIFT
) | physArm
;
775 (span
<< RAID_CTX_SPANARM_SPAN_SHIFT
) | physArm
;
777 pRAID_Context
->span_arm
=
778 (span
<< RAID_CTX_SPANARM_SPAN_SHIFT
) | physArm
;
779 io_info
->span_arm
= pRAID_Context
->span_arm
;
781 io_info
->pd_after_lb
= pd
;
786 ******************************************************************************
788 * This routine calculates the arm, span and block for the specified stripe and
789 * reference in stripe.
793 * ld - Logical drive number
794 * stripRow - Stripe number
795 * stripRef - Reference in stripe
800 * block - Absolute Block number in the physical disk
802 u8
MR_GetPhyParams(struct megasas_instance
*instance
, u32 ld
, u64 stripRow
,
803 u16 stripRef
, struct IO_REQUEST_INFO
*io_info
,
804 struct RAID_CONTEXT
*pRAID_Context
,
805 struct MR_DRV_RAID_MAP_ALL
*map
)
807 struct MR_LD_RAID
*raid
= MR_LdRaidGet(ld
, map
);
808 u32 pd
, arRef
, r1_alt_pd
;
812 u64
*pdBlock
= &io_info
->pdBlock
;
813 __le16
*pDevHandle
= &io_info
->devHandle
;
814 u8
*pPdInterface
= &io_info
->pd_interface
;
815 struct fusion_context
*fusion
;
817 fusion
= instance
->ctrl_context
;
818 *pDevHandle
= cpu_to_le16(MR_DEVHANDLE_INVALID
);
820 row
= mega_div64_32(stripRow
, raid
->rowDataSize
);
822 if (raid
->level
== 6) {
823 /* logical arm within row */
824 u32 logArm
= mega_mod64(stripRow
, raid
->rowDataSize
);
825 u32 rowMod
, armQ
, arm
;
827 if (raid
->rowSize
== 0)
829 /* get logical row mod */
830 rowMod
= mega_mod64(row
, raid
->rowSize
);
831 armQ
= raid
->rowSize
-1-rowMod
; /* index of Q drive */
832 arm
= armQ
+1+logArm
; /* data always logically follows Q */
833 if (arm
>= raid
->rowSize
) /* handle wrap condition */
834 arm
-= raid
->rowSize
;
837 if (raid
->modFactor
== 0)
839 physArm
= MR_LdDataArmGet(ld
, mega_mod64(stripRow
,
844 if (raid
->spanDepth
== 1) {
846 *pdBlock
= row
<< raid
->stripeShift
;
848 span
= (u8
)MR_GetSpanBlock(ld
, row
, pdBlock
, map
);
849 if (span
== SPAN_INVALID
)
853 /* Get the array on which this span is present */
854 arRef
= MR_LdSpanArrayGet(ld
, span
, map
);
855 pd
= MR_ArPdGet(arRef
, physArm
, map
); /* Get the pd */
857 if (pd
!= MR_PD_INVALID
) {
858 /* Get dev handle from Pd. */
859 *pDevHandle
= MR_PdDevHandleGet(pd
, map
);
860 *pPdInterface
= MR_PdInterfaceTypeGet(pd
, map
);
861 /* get second pd also for raid 1/10 fast path writes*/
862 if ((instance
->adapter_type
>= VENTURA_SERIES
) &&
863 (raid
->level
== 1) &&
865 r1_alt_pd
= MR_ArPdGet(arRef
, physArm
+ 1, map
);
866 if (r1_alt_pd
!= MR_PD_INVALID
)
867 io_info
->r1_alt_dev_handle
=
868 MR_PdDevHandleGet(r1_alt_pd
, map
);
871 if ((raid
->level
>= 5) &&
872 ((instance
->adapter_type
== THUNDERBOLT_SERIES
) ||
873 ((instance
->adapter_type
== INVADER_SERIES
) &&
874 (raid
->regTypeReqOnRead
!= REGION_TYPE_UNUSED
))))
875 pRAID_Context
->reg_lock_flags
= REGION_TYPE_EXCLUSIVE
;
876 else if (raid
->level
== 1) {
877 /* Get alternate Pd. */
878 physArm
= physArm
+ 1;
879 pd
= MR_ArPdGet(arRef
, physArm
, map
);
880 if (pd
!= MR_PD_INVALID
) {
881 /* Get dev handle from Pd */
882 *pDevHandle
= MR_PdDevHandleGet(pd
, map
);
883 *pPdInterface
= MR_PdInterfaceTypeGet(pd
, map
);
888 *pdBlock
+= stripRef
+ le64_to_cpu(MR_LdSpanPtrGet(ld
, span
, map
)->startBlk
);
889 if (instance
->adapter_type
>= VENTURA_SERIES
) {
890 ((struct RAID_CONTEXT_G35
*)pRAID_Context
)->span_arm
=
891 (span
<< RAID_CTX_SPANARM_SPAN_SHIFT
) | physArm
;
893 (span
<< RAID_CTX_SPANARM_SPAN_SHIFT
) | physArm
;
895 pRAID_Context
->span_arm
=
896 (span
<< RAID_CTX_SPANARM_SPAN_SHIFT
) | physArm
;
897 io_info
->span_arm
= pRAID_Context
->span_arm
;
899 io_info
->pd_after_lb
= pd
;
904 ******************************************************************************
906 * MR_BuildRaidContext function
908 * This function will initiate command processing. The start/end row and strip
909 * information is calculated then the lock is acquired.
910 * This function will return 0 if region lock was acquired OR return num strips
913 MR_BuildRaidContext(struct megasas_instance
*instance
,
914 struct IO_REQUEST_INFO
*io_info
,
915 struct RAID_CONTEXT
*pRAID_Context
,
916 struct MR_DRV_RAID_MAP_ALL
*map
, u8
**raidLUN
)
918 struct fusion_context
*fusion
;
919 struct MR_LD_RAID
*raid
;
920 u32 stripSize
, stripe_mask
;
921 u64 endLba
, endStrip
, endRow
, start_row
, start_strip
;
924 u8 num_strips
, numRows
;
925 u16 ref_in_start_stripe
, ref_in_end_stripe
;
927 u32 numBlocks
, ldTgtId
;
930 u8 startlba_span
= SPAN_INVALID
;
931 u64
*pdBlock
= &io_info
->pdBlock
;
934 ldStartBlock
= io_info
->ldStartBlock
;
935 numBlocks
= io_info
->numBlocks
;
936 ldTgtId
= io_info
->ldTgtId
;
937 isRead
= io_info
->isRead
;
938 io_info
->IoforUnevenSpan
= 0;
939 io_info
->start_span
= SPAN_INVALID
;
940 fusion
= instance
->ctrl_context
;
942 ld
= MR_TargetIdToLdGet(ldTgtId
, map
);
943 raid
= MR_LdRaidGet(ld
, map
);
944 /*check read ahead bit*/
945 io_info
->ra_capable
= raid
->capability
.ra_capable
;
948 * if rowDataSize @RAID map and spanRowDataSize @SPAN INFO are zero
951 if (raid
->rowDataSize
== 0) {
952 if (MR_LdSpanPtrGet(ld
, 0, map
)->spanRowDataSize
== 0)
954 else if (instance
->UnevenSpanSupport
) {
955 io_info
->IoforUnevenSpan
= 1;
957 dev_info(&instance
->pdev
->dev
,
958 "raid->rowDataSize is 0, but has SPAN[0]"
959 "rowDataSize = 0x%0x,"
960 "but there is _NO_ UnevenSpanSupport\n",
961 MR_LdSpanPtrGet(ld
, 0, map
)->spanRowDataSize
);
966 stripSize
= 1 << raid
->stripeShift
;
967 stripe_mask
= stripSize
-1;
971 * calculate starting row and stripe, and number of strips and rows
973 start_strip
= ldStartBlock
>> raid
->stripeShift
;
974 ref_in_start_stripe
= (u16
)(ldStartBlock
& stripe_mask
);
975 endLba
= ldStartBlock
+ numBlocks
- 1;
976 ref_in_end_stripe
= (u16
)(endLba
& stripe_mask
);
977 endStrip
= endLba
>> raid
->stripeShift
;
978 num_strips
= (u8
)(endStrip
- start_strip
+ 1); /* End strip */
980 if (io_info
->IoforUnevenSpan
) {
981 start_row
= get_row_from_strip(instance
, ld
, start_strip
, map
);
982 endRow
= get_row_from_strip(instance
, ld
, endStrip
, map
);
983 if (start_row
== -1ULL || endRow
== -1ULL) {
984 dev_info(&instance
->pdev
->dev
, "return from %s %d."
985 "Send IO w/o region lock.\n",
990 if (raid
->spanDepth
== 1) {
992 *pdBlock
= start_row
<< raid
->stripeShift
;
994 startlba_span
= (u8
)mr_spanset_get_span_block(instance
,
995 ld
, start_row
, pdBlock
, map
);
996 if (startlba_span
== SPAN_INVALID
) {
997 dev_info(&instance
->pdev
->dev
, "return from %s %d"
998 "for row 0x%llx,start strip %llx"
999 "endSrip %llx\n", __func__
, __LINE__
,
1000 (unsigned long long)start_row
,
1001 (unsigned long long)start_strip
,
1002 (unsigned long long)endStrip
);
1005 io_info
->start_span
= startlba_span
;
1006 io_info
->start_row
= start_row
;
1008 start_row
= mega_div64_32(start_strip
, raid
->rowDataSize
);
1009 endRow
= mega_div64_32(endStrip
, raid
->rowDataSize
);
1011 numRows
= (u8
)(endRow
- start_row
+ 1);
1014 * calculate region info.
1017 /* assume region is at the start of the first row */
1018 regStart
= start_row
<< raid
->stripeShift
;
1019 /* assume this IO needs the full row - we'll adjust if not true */
1020 regSize
= stripSize
;
1022 io_info
->do_fp_rlbypass
= raid
->capability
.fpBypassRegionLock
;
1024 /* Check if we can send this I/O via FastPath */
1025 if (raid
->capability
.fpCapable
) {
1027 io_info
->fpOkForIo
= (raid
->capability
.fpReadCapable
&&
1028 ((num_strips
== 1) ||
1030 fpReadAcrossStripe
));
1032 io_info
->fpOkForIo
= (raid
->capability
.fpWriteCapable
&&
1033 ((num_strips
== 1) ||
1035 fpWriteAcrossStripe
));
1037 io_info
->fpOkForIo
= false;
1040 /* single-strip IOs can always lock only the data needed */
1041 if (num_strips
== 1) {
1042 regStart
+= ref_in_start_stripe
;
1043 regSize
= numBlocks
;
1045 /* multi-strip IOs always need to full stripe locked */
1046 } else if (io_info
->IoforUnevenSpan
== 0) {
1048 * For Even span region lock optimization.
1049 * If the start strip is the last in the start row
1051 if (start_strip
== (start_row
+ 1) * raid
->rowDataSize
- 1) {
1052 regStart
+= ref_in_start_stripe
;
1053 /* initialize count to sectors from startref to end
1055 regSize
= stripSize
- ref_in_start_stripe
;
1058 /* add complete rows in the middle of the transfer */
1060 regSize
+= (numRows
-2) << raid
->stripeShift
;
1062 /* if IO ends within first strip of last row*/
1063 if (endStrip
== endRow
*raid
->rowDataSize
)
1064 regSize
+= ref_in_end_stripe
+1;
1066 regSize
+= stripSize
;
1069 * For Uneven span region lock optimization.
1070 * If the start strip is the last in the start row
1072 if (start_strip
== (get_strip_from_row(instance
, ld
, start_row
, map
) +
1073 SPAN_ROW_DATA_SIZE(map
, ld
, startlba_span
) - 1)) {
1074 regStart
+= ref_in_start_stripe
;
1075 /* initialize count to sectors from
1076 * startRef to end of strip
1078 regSize
= stripSize
- ref_in_start_stripe
;
1080 /* Add complete rows in the middle of the transfer*/
1083 /* Add complete rows in the middle of the transfer*/
1084 regSize
+= (numRows
-2) << raid
->stripeShift
;
1086 /* if IO ends within first strip of last row */
1087 if (endStrip
== get_strip_from_row(instance
, ld
, endRow
, map
))
1088 regSize
+= ref_in_end_stripe
+ 1;
1090 regSize
+= stripSize
;
1093 pRAID_Context
->timeout_value
=
1094 cpu_to_le16(raid
->fpIoTimeoutForLd
?
1095 raid
->fpIoTimeoutForLd
:
1096 map
->raidMap
.fpPdIoTimeoutSec
);
1097 if (instance
->adapter_type
== INVADER_SERIES
)
1098 pRAID_Context
->reg_lock_flags
= (isRead
) ?
1099 raid
->regTypeReqOnRead
: raid
->regTypeReqOnWrite
;
1100 else if (instance
->adapter_type
== THUNDERBOLT_SERIES
)
1101 pRAID_Context
->reg_lock_flags
= (isRead
) ?
1102 REGION_TYPE_SHARED_READ
: raid
->regTypeReqOnWrite
;
1103 pRAID_Context
->virtual_disk_tgt_id
= raid
->targetId
;
1104 pRAID_Context
->reg_lock_row_lba
= cpu_to_le64(regStart
);
1105 pRAID_Context
->reg_lock_length
= cpu_to_le32(regSize
);
1106 pRAID_Context
->config_seq_num
= raid
->seqNum
;
1107 /* save pointer to raid->LUN array */
1108 *raidLUN
= raid
->LUN
;
1111 /*Get Phy Params only if FP capable, or else leave it to MR firmware
1112 to do the calculation.*/
1113 if (io_info
->fpOkForIo
) {
1114 retval
= io_info
->IoforUnevenSpan
?
1115 mr_spanset_get_phy_params(instance
, ld
,
1116 start_strip
, ref_in_start_stripe
,
1117 io_info
, pRAID_Context
, map
) :
1118 MR_GetPhyParams(instance
, ld
, start_strip
,
1119 ref_in_start_stripe
, io_info
,
1120 pRAID_Context
, map
);
1121 /* If IO on an invalid Pd, then FP is not possible.*/
1122 if (io_info
->devHandle
== MR_DEVHANDLE_INVALID
)
1123 io_info
->fpOkForIo
= false;
1125 } else if (isRead
) {
1127 for (stripIdx
= 0; stripIdx
< num_strips
; stripIdx
++) {
1128 retval
= io_info
->IoforUnevenSpan
?
1129 mr_spanset_get_phy_params(instance
, ld
,
1130 start_strip
+ stripIdx
,
1131 ref_in_start_stripe
, io_info
,
1132 pRAID_Context
, map
) :
1133 MR_GetPhyParams(instance
, ld
,
1134 start_strip
+ stripIdx
, ref_in_start_stripe
,
1135 io_info
, pRAID_Context
, map
);
1144 ******************************************************************************
1146 * This routine pepare spanset info from Valid Raid map and store it into
1147 * local copy of ldSpanInfo per instance data structure.
1151 * ldSpanInfo - ldSpanInfo per HBA instance
1154 void mr_update_span_set(struct MR_DRV_RAID_MAP_ALL
*map
,
1155 PLD_SPAN_INFO ldSpanInfo
)
1158 u32 element
, span_row_width
;
1160 struct MR_LD_RAID
*raid
;
1161 LD_SPAN_SET
*span_set
, *span_set_prev
;
1162 struct MR_QUAD_ELEMENT
*quad
;
1167 for (ldCount
= 0; ldCount
< MAX_LOGICAL_DRIVES_EXT
; ldCount
++) {
1168 ld
= MR_TargetIdToLdGet(ldCount
, map
);
1169 if (ld
>= (MAX_LOGICAL_DRIVES_EXT
- 1))
1171 raid
= MR_LdRaidGet(ld
, map
);
1172 for (element
= 0; element
< MAX_QUAD_DEPTH
; element
++) {
1173 for (span
= 0; span
< raid
->spanDepth
; span
++) {
1174 if (le32_to_cpu(map
->raidMap
.ldSpanMap
[ld
].spanBlock
[span
].
1175 block_span_info
.noElements
) <
1178 span_set
= &(ldSpanInfo
[ld
].span_set
[element
]);
1179 quad
= &map
->raidMap
.ldSpanMap
[ld
].
1180 spanBlock
[span
].block_span_info
.
1183 span_set
->diff
= le32_to_cpu(quad
->diff
);
1185 for (count
= 0, span_row_width
= 0;
1186 count
< raid
->spanDepth
; count
++) {
1187 if (le32_to_cpu(map
->raidMap
.ldSpanMap
[ld
].
1190 noElements
) >= element
+ 1) {
1191 span_set
->strip_offset
[count
] =
1195 (ld
, count
, map
)->spanRowDataSize
;
1199 span_set
->span_row_data_width
= span_row_width
;
1200 span_row
= mega_div64_32(((le64_to_cpu(quad
->logEnd
) -
1201 le64_to_cpu(quad
->logStart
)) + le32_to_cpu(quad
->diff
)),
1202 le32_to_cpu(quad
->diff
));
1205 span_set
->log_start_lba
= 0;
1206 span_set
->log_end_lba
=
1207 ((span_row
<< raid
->stripeShift
)
1208 * span_row_width
) - 1;
1210 span_set
->span_row_start
= 0;
1211 span_set
->span_row_end
= span_row
- 1;
1213 span_set
->data_strip_start
= 0;
1214 span_set
->data_strip_end
=
1215 (span_row
* span_row_width
) - 1;
1217 span_set
->data_row_start
= 0;
1218 span_set
->data_row_end
=
1219 (span_row
* le32_to_cpu(quad
->diff
)) - 1;
1221 span_set_prev
= &(ldSpanInfo
[ld
].
1222 span_set
[element
- 1]);
1223 span_set
->log_start_lba
=
1224 span_set_prev
->log_end_lba
+ 1;
1225 span_set
->log_end_lba
=
1226 span_set
->log_start_lba
+
1227 ((span_row
<< raid
->stripeShift
)
1228 * span_row_width
) - 1;
1230 span_set
->span_row_start
=
1231 span_set_prev
->span_row_end
+ 1;
1232 span_set
->span_row_end
=
1233 span_set
->span_row_start
+ span_row
- 1;
1235 span_set
->data_strip_start
=
1236 span_set_prev
->data_strip_end
+ 1;
1237 span_set
->data_strip_end
=
1238 span_set
->data_strip_start
+
1239 (span_row
* span_row_width
) - 1;
1241 span_set
->data_row_start
=
1242 span_set_prev
->data_row_end
+ 1;
1243 span_set
->data_row_end
=
1244 span_set
->data_row_start
+
1245 (span_row
* le32_to_cpu(quad
->diff
)) - 1;
1249 if (span
== raid
->spanDepth
)
1255 void mr_update_load_balance_params(struct MR_DRV_RAID_MAP_ALL
*drv_map
,
1256 struct LD_LOAD_BALANCE_INFO
*lbInfo
)
1260 struct MR_LD_RAID
*raid
;
1262 if (lb_pending_cmds
> 128 || lb_pending_cmds
< 1)
1263 lb_pending_cmds
= LB_PENDING_CMDS_DEFAULT
;
1265 for (ldCount
= 0; ldCount
< MAX_LOGICAL_DRIVES_EXT
; ldCount
++) {
1266 ld
= MR_TargetIdToLdGet(ldCount
, drv_map
);
1267 if (ld
>= MAX_LOGICAL_DRIVES_EXT
- 1) {
1268 lbInfo
[ldCount
].loadBalanceFlag
= 0;
1272 raid
= MR_LdRaidGet(ld
, drv_map
);
1273 if ((raid
->level
!= 1) ||
1274 (raid
->ldState
!= MR_LD_STATE_OPTIMAL
)) {
1275 lbInfo
[ldCount
].loadBalanceFlag
= 0;
1278 lbInfo
[ldCount
].loadBalanceFlag
= 1;
1282 u8
megasas_get_best_arm_pd(struct megasas_instance
*instance
,
1283 struct LD_LOAD_BALANCE_INFO
*lbInfo
,
1284 struct IO_REQUEST_INFO
*io_info
,
1285 struct MR_DRV_RAID_MAP_ALL
*drv_map
)
1287 struct MR_LD_RAID
*raid
;
1289 u16 pend0
, pend1
, ld
;
1291 u8 bestArm
, pd0
, pd1
, span
, arm
;
1292 u32 arRef
, span_row_size
;
1294 u64 block
= io_info
->ldStartBlock
;
1295 u32 count
= io_info
->numBlocks
;
1297 span
= ((io_info
->span_arm
& RAID_CTX_SPANARM_SPAN_MASK
)
1298 >> RAID_CTX_SPANARM_SPAN_SHIFT
);
1299 arm
= (io_info
->span_arm
& RAID_CTX_SPANARM_ARM_MASK
);
1301 ld
= MR_TargetIdToLdGet(io_info
->ldTgtId
, drv_map
);
1302 raid
= MR_LdRaidGet(ld
, drv_map
);
1303 span_row_size
= instance
->UnevenSpanSupport
?
1304 SPAN_ROW_SIZE(drv_map
, ld
, span
) : raid
->rowSize
;
1306 arRef
= MR_LdSpanArrayGet(ld
, span
, drv_map
);
1307 pd0
= MR_ArPdGet(arRef
, arm
, drv_map
);
1308 pd1
= MR_ArPdGet(arRef
, (arm
+ 1) >= span_row_size
?
1309 (arm
+ 1 - span_row_size
) : arm
+ 1, drv_map
);
1311 /* Get PD1 Dev Handle */
1313 pd1_dev_handle
= MR_PdDevHandleGet(pd1
, drv_map
);
1315 if (pd1_dev_handle
== MR_DEVHANDLE_INVALID
) {
1318 /* get the pending cmds for the data and mirror arms */
1319 pend0
= atomic_read(&lbInfo
->scsi_pending_cmds
[pd0
]);
1320 pend1
= atomic_read(&lbInfo
->scsi_pending_cmds
[pd1
]);
1322 /* Determine the disk whose head is nearer to the req. block */
1323 diff0
= ABS_DIFF(block
, lbInfo
->last_accessed_block
[pd0
]);
1324 diff1
= ABS_DIFF(block
, lbInfo
->last_accessed_block
[pd1
]);
1325 bestArm
= (diff0
<= diff1
? arm
: arm
^ 1);
1327 /* Make balance count from 16 to 4 to
1328 * keep driver in sync with Firmware
1330 if ((bestArm
== arm
&& pend0
> pend1
+ lb_pending_cmds
) ||
1331 (bestArm
!= arm
&& pend1
> pend0
+ lb_pending_cmds
))
1334 /* Update the last accessed block on the correct pd */
1336 (span
<< RAID_CTX_SPANARM_SPAN_SHIFT
) | bestArm
;
1337 io_info
->pd_after_lb
= (bestArm
== arm
) ? pd0
: pd1
;
1340 lbInfo
->last_accessed_block
[io_info
->pd_after_lb
] = block
+ count
- 1;
1341 return io_info
->pd_after_lb
;
1344 __le16
get_updated_dev_handle(struct megasas_instance
*instance
,
1345 struct LD_LOAD_BALANCE_INFO
*lbInfo
,
1346 struct IO_REQUEST_INFO
*io_info
,
1347 struct MR_DRV_RAID_MAP_ALL
*drv_map
)
1352 /* get best new arm (PD ID) */
1353 arm_pd
= megasas_get_best_arm_pd(instance
, lbInfo
, io_info
, drv_map
);
1354 devHandle
= MR_PdDevHandleGet(arm_pd
, drv_map
);
1355 io_info
->pd_interface
= MR_PdInterfaceTypeGet(arm_pd
, drv_map
);
1356 atomic_inc(&lbInfo
->scsi_pending_cmds
[arm_pd
]);