2 * Copyright (c) 2015, AVAGO Tech. All rights reserved. Author: Marian Choy
3 * Copyright (c) 2014, LSI Corp. All rights reserved. Author: Marian Choy
4 * Support: freebsdraid@avagotech.com
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
10 * 1. Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer. 2. Redistributions
12 * in binary form must reproduce the above copyright notice, this list of
13 * conditions and the following disclaimer in the documentation and/or other
14 * materials provided with the distribution. 3. Neither the name of the
15 * <ORGANIZATION> nor the names of its contributors may be used to endorse or
16 * promote products derived from this software without specific prior written
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
31 * The views and conclusions contained in the software and documentation are
32 * those of the authors and should not be interpreted as representing
33 * official policies,either expressed or implied, of the FreeBSD Project.
35 * Send feedback to: <megaraidfbsd@avagotech.com> Mail to: AVAGO TECHNOLOGIES, 1621
36 * Barber Lane, Milpitas, CA 95035 ATTN: MegaRaid FreeBSD
40 #include <sys/cdefs.h>
41 __FBSDID("$FreeBSD$");
43 #include <dev/mrsas/mrsas.h>
46 #include <cam/cam_ccb.h>
47 #include <cam/cam_sim.h>
48 #include <cam/cam_xpt_sim.h>
49 #include <cam/cam_debug.h>
50 #include <cam/cam_periph.h>
51 #include <cam/cam_xpt_periph.h>
56 u_int8_t MR_ValidateMapInfo(struct mrsas_softc *sc);
58 mrsas_get_best_arm_pd(struct mrsas_softc *sc,
59 PLD_LOAD_BALANCE_INFO lbInfo, struct IO_REQUEST_INFO *io_info);
61 MR_BuildRaidContext(struct mrsas_softc *sc,
62 struct IO_REQUEST_INFO *io_info,
63 RAID_CONTEXT * pRAID_Context, MR_DRV_RAID_MAP_ALL * map);
65 MR_GetPhyParams(struct mrsas_softc *sc, u_int32_t ld,
66 u_int64_t stripRow, u_int16_t stripRef, struct IO_REQUEST_INFO *io_info,
67 RAID_CONTEXT * pRAID_Context,
68 MR_DRV_RAID_MAP_ALL * map);
69 u_int8_t MR_TargetIdToLdGet(u_int32_t ldTgtId, MR_DRV_RAID_MAP_ALL *map);
70 u_int32_t MR_LdBlockSizeGet(u_int32_t ldTgtId, MR_DRV_RAID_MAP_ALL * map);
71 u_int16_t MR_GetLDTgtId(u_int32_t ld, MR_DRV_RAID_MAP_ALL * map);
73 mrsas_get_updated_dev_handle(struct mrsas_softc *sc,
74 PLD_LOAD_BALANCE_INFO lbInfo, struct IO_REQUEST_INFO *io_info);
75 u_int32_t mega_mod64(u_int64_t dividend, u_int32_t divisor);
77 MR_GetSpanBlock(u_int32_t ld, u_int64_t row, u_int64_t *span_blk,
78 MR_DRV_RAID_MAP_ALL * map, int *div_error);
79 u_int64_t mega_div64_32(u_int64_t dividend, u_int32_t divisor);
81 mrsas_update_load_balance_params(struct mrsas_softc *sc,
82 MR_DRV_RAID_MAP_ALL * map, PLD_LOAD_BALANCE_INFO lbInfo);
84 mrsas_set_pd_lba(MRSAS_RAID_SCSI_IO_REQUEST * io_request,
85 u_int8_t cdb_len, struct IO_REQUEST_INFO *io_info, union ccb *ccb,
86 MR_DRV_RAID_MAP_ALL * local_map_ptr, u_int32_t ref_tag,
87 u_int32_t ld_block_size);
89 MR_LdSpanArrayGet(u_int32_t ld, u_int32_t span,
90 MR_DRV_RAID_MAP_ALL * map);
91 static u_int16_t MR_PdDevHandleGet(u_int32_t pd, MR_DRV_RAID_MAP_ALL * map);
93 MR_ArPdGet(u_int32_t ar, u_int32_t arm,
94 MR_DRV_RAID_MAP_ALL * map);
96 MR_LdSpanPtrGet(u_int32_t ld, u_int32_t span,
97 MR_DRV_RAID_MAP_ALL * map);
99 MR_LdDataArmGet(u_int32_t ld, u_int32_t armIdx,
100 MR_DRV_RAID_MAP_ALL * map);
101 static MR_SPAN_BLOCK_INFO *
102 MR_LdSpanInfoGet(u_int32_t ld,
103 MR_DRV_RAID_MAP_ALL * map);
104 MR_LD_RAID *MR_LdRaidGet(u_int32_t ld, MR_DRV_RAID_MAP_ALL * map);
105 static int MR_PopulateDrvRaidMap(struct mrsas_softc *sc);
108 * Spanset related function prototypes Added for PRL11 configuration (Uneven
111 void mr_update_span_set(MR_DRV_RAID_MAP_ALL * map, PLD_SPAN_INFO ldSpanInfo);
113 mr_spanset_get_phy_params(struct mrsas_softc *sc, u_int32_t ld,
114 u_int64_t stripRow, u_int16_t stripRef, struct IO_REQUEST_INFO *io_info,
115 RAID_CONTEXT * pRAID_Context, MR_DRV_RAID_MAP_ALL * map);
117 get_row_from_strip(struct mrsas_softc *sc, u_int32_t ld,
118 u_int64_t strip, MR_DRV_RAID_MAP_ALL * map);
120 mr_spanset_get_span_block(struct mrsas_softc *sc,
121 u_int32_t ld, u_int64_t row, u_int64_t *span_blk,
122 MR_DRV_RAID_MAP_ALL * map, int *div_error);
124 get_arm(struct mrsas_softc *sc, u_int32_t ld, u_int8_t span,
125 u_int64_t stripe, MR_DRV_RAID_MAP_ALL * map);
128 * Spanset related defines Added for PRL11 configuration(Uneven span support)
130 #define SPAN_ROW_SIZE(map, ld, index_) MR_LdSpanPtrGet(ld, index_, map)->spanRowSize
131 #define SPAN_ROW_DATA_SIZE(map_, ld, index_) \
132 MR_LdSpanPtrGet(ld, index_, map)->spanRowDataSize
133 #define SPAN_INVALID 0xff
140 typedef u_int64_t REGION_KEY;
141 typedef u_int32_t REGION_LEN;
143 #define MR_LD_STATE_OPTIMAL 3
147 #define LB_PENDING_CMDS_DEFAULT 4
153 #define ABS_DIFF(a,b) ( ((a) > (b)) ? ((a) - (b)) : ((b) - (a)) )
157 (((unsigned int)(x) & (unsigned int)0x000000ffUL) << 24) | \
158 (((unsigned int)(x) & (unsigned int)0x0000ff00UL) << 8) | \
159 (((unsigned int)(x) & (unsigned int)0x00ff0000UL) >> 8) | \
160 (((unsigned int)(x) & (unsigned int)0xff000000UL) >> 24) ))
163 * In-line functions for mod and divide of 64-bit dividend and 32-bit
164 * divisor. Assumes a check for a divisor of zero is not possible.
166 * @param dividend: Dividend
167 * @param divisor: Divisor
171 #define mega_mod64(dividend, divisor) ({ \
173 remainder = ((u_int64_t) (dividend)) % (u_int32_t) (divisor); \
176 #define mega_div64_32(dividend, divisor) ({ \
178 quotient = ((u_int64_t) (dividend)) / (u_int32_t) (divisor); \
182 * Various RAID map access functions. These functions access the various
183 * parts of the RAID map and returns the appropriate parameters.
187 MR_LdRaidGet(u_int32_t ld, MR_DRV_RAID_MAP_ALL * map)
189 return (&map->raidMap.ldSpanMap[ld].ldRaid);
193 MR_GetLDTgtId(u_int32_t ld, MR_DRV_RAID_MAP_ALL * map)
195 return (map->raidMap.ldSpanMap[ld].ldRaid.targetId);
199 MR_LdSpanArrayGet(u_int32_t ld, u_int32_t span, MR_DRV_RAID_MAP_ALL * map)
201 return map->raidMap.ldSpanMap[ld].spanBlock[span].span.arrayRef;
205 MR_LdDataArmGet(u_int32_t ld, u_int32_t armIdx, MR_DRV_RAID_MAP_ALL * map)
207 return map->raidMap.ldSpanMap[ld].dataArmMap[armIdx];
211 MR_PdDevHandleGet(u_int32_t pd, MR_DRV_RAID_MAP_ALL * map)
213 return map->raidMap.devHndlInfo[pd].curDevHdl;
216 static u_int8_t MR_PdInterfaceTypeGet(u_int32_t pd, MR_DRV_RAID_MAP_ALL *map)
218 return map->raidMap.devHndlInfo[pd].interfaceType;
222 MR_ArPdGet(u_int32_t ar, u_int32_t arm, MR_DRV_RAID_MAP_ALL * map)
224 return map->raidMap.arMapInfo[ar].pd[arm];
228 MR_LdSpanPtrGet(u_int32_t ld, u_int32_t span, MR_DRV_RAID_MAP_ALL * map)
230 return &map->raidMap.ldSpanMap[ld].spanBlock[span].span;
233 static MR_SPAN_BLOCK_INFO *
234 MR_LdSpanInfoGet(u_int32_t ld, MR_DRV_RAID_MAP_ALL * map)
236 return &map->raidMap.ldSpanMap[ld].spanBlock[0];
240 MR_TargetIdToLdGet(u_int32_t ldTgtId, MR_DRV_RAID_MAP_ALL * map)
242 return map->raidMap.ldTgtIdToLd[ldTgtId];
246 MR_LdBlockSizeGet(u_int32_t ldTgtId, MR_DRV_RAID_MAP_ALL * map)
249 u_int32_t ld, ldBlockSize = MRSAS_SCSIBLOCKSIZE;
251 ld = MR_TargetIdToLdGet(ldTgtId, map);
254 * Check if logical drive was removed.
256 if (ld >= MAX_LOGICAL_DRIVES)
259 raid = MR_LdRaidGet(ld, map);
260 ldBlockSize = raid->logicalBlockLength;
262 ldBlockSize = MRSAS_SCSIBLOCKSIZE;
268 * This function will Populate Driver Map using Dynamic firmware raid map
271 MR_PopulateDrvRaidMapVentura(struct mrsas_softc *sc)
276 MR_FW_RAID_MAP_DYNAMIC *fw_map_dyn;
277 MR_RAID_MAP_DESC_TABLE *desc_table;
278 MR_DRV_RAID_MAP_ALL *drv_map = sc->ld_drv_map[(sc->map_id & 1)];
279 MR_DRV_RAID_MAP *pDrvRaidMap = &drv_map->raidMap;
280 void *raid_map_data = NULL;
282 fw_map_dyn = (MR_FW_RAID_MAP_DYNAMIC *) sc->raidmap_mem[(sc->map_id & 1)];
284 if (fw_map_dyn == NULL) {
285 device_printf(sc->mrsas_dev,
286 "from %s %d map0 %p map1 %p map size %d \n", __func__, __LINE__,
287 sc->raidmap_mem[0], sc->raidmap_mem[1], sc->maxRaidMapSize);
291 device_printf(sc->mrsas_dev,
292 " raidMapSize 0x%x, descTableOffset 0x%x, "
293 " descTableSize 0x%x, descTableNumElements 0x%x \n",
294 fw_map_dyn->raidMapSize, fw_map_dyn->descTableOffset,
295 fw_map_dyn->descTableSize, fw_map_dyn->descTableNumElements);
297 desc_table = (MR_RAID_MAP_DESC_TABLE *) ((char *)fw_map_dyn +
298 fw_map_dyn->descTableOffset);
299 if (desc_table != fw_map_dyn->raidMapDescTable) {
300 device_printf(sc->mrsas_dev,
301 "offsets of desc table are not matching returning "
302 " FW raid map has been changed: desc %p original %p\n",
303 desc_table, fw_map_dyn->raidMapDescTable);
305 memset(drv_map, 0, sc->drv_map_sz);
306 ld_count = fw_map_dyn->ldCount;
307 pDrvRaidMap->ldCount = ld_count;
308 pDrvRaidMap->fpPdIoTimeoutSec = fw_map_dyn->fpPdIoTimeoutSec;
309 pDrvRaidMap->totalSize = sizeof(MR_DRV_RAID_MAP_ALL);
310 /* point to actual data starting point */
311 raid_map_data = (char *)fw_map_dyn +
312 fw_map_dyn->descTableOffset + fw_map_dyn->descTableSize;
314 for (i = 0; i < fw_map_dyn->descTableNumElements; ++i) {
316 device_printf(sc->mrsas_dev,
317 "desc table is null, coming out %p \n", desc_table);
321 device_printf(sc->mrsas_dev, "raid_map_data %p \n", raid_map_data);
322 device_printf(sc->mrsas_dev,
323 "desc table %p \n", desc_table);
324 device_printf(sc->mrsas_dev,
325 "raidmap type %d, raidmapOffset 0x%x, "
326 " raid map number of elements 0%x, raidmapsize 0x%x\n",
327 desc_table->raidMapDescType, desc_table->raidMapDescOffset,
328 desc_table->raidMapDescElements, desc_table->raidMapDescBufferSize);
330 switch (desc_table->raidMapDescType) {
331 case RAID_MAP_DESC_TYPE_DEVHDL_INFO:
332 fw_map_dyn->RaidMapDescPtrs.ptrStruct.devHndlInfo = (MR_DEV_HANDLE_INFO *)
333 ((char *)raid_map_data + desc_table->raidMapDescOffset);
335 device_printf(sc->mrsas_dev,
336 "devHndlInfo address %p\n", fw_map_dyn->RaidMapDescPtrs.ptrStruct.devHndlInfo);
338 memcpy(pDrvRaidMap->devHndlInfo, fw_map_dyn->RaidMapDescPtrs.ptrStruct.devHndlInfo,
339 sizeof(MR_DEV_HANDLE_INFO) * desc_table->raidMapDescElements);
341 case RAID_MAP_DESC_TYPE_TGTID_INFO:
342 fw_map_dyn->RaidMapDescPtrs.ptrStruct.ldTgtIdToLd = (u_int16_t *)
343 ((char *)raid_map_data + desc_table->raidMapDescOffset);
345 device_printf(sc->mrsas_dev,
346 "ldTgtIdToLd address %p\n", fw_map_dyn->RaidMapDescPtrs.ptrStruct.ldTgtIdToLd);
348 for (j = 0; j < desc_table->raidMapDescElements; j++) {
349 pDrvRaidMap->ldTgtIdToLd[j] = fw_map_dyn->RaidMapDescPtrs.ptrStruct.ldTgtIdToLd[j];
351 device_printf(sc->mrsas_dev,
352 " %d drv ldTgtIdToLd %d\n", j, pDrvRaidMap->ldTgtIdToLd[j]);
356 case RAID_MAP_DESC_TYPE_ARRAY_INFO:
357 fw_map_dyn->RaidMapDescPtrs.ptrStruct.arMapInfo = (MR_ARRAY_INFO *) ((char *)raid_map_data +
358 desc_table->raidMapDescOffset);
360 device_printf(sc->mrsas_dev,
361 "arMapInfo address %p\n", fw_map_dyn->RaidMapDescPtrs.ptrStruct.arMapInfo);
363 memcpy(pDrvRaidMap->arMapInfo, fw_map_dyn->RaidMapDescPtrs.ptrStruct.arMapInfo,
364 sizeof(MR_ARRAY_INFO) * desc_table->raidMapDescElements);
366 case RAID_MAP_DESC_TYPE_SPAN_INFO:
367 fw_map_dyn->RaidMapDescPtrs.ptrStruct.ldSpanMap = (MR_LD_SPAN_MAP *) ((char *)raid_map_data +
368 desc_table->raidMapDescOffset);
369 memcpy(pDrvRaidMap->ldSpanMap, fw_map_dyn->RaidMapDescPtrs.ptrStruct.ldSpanMap,
370 sizeof(MR_LD_SPAN_MAP) * desc_table->raidMapDescElements);
372 device_printf(sc->mrsas_dev,
373 "ldSpanMap address %p\n", fw_map_dyn->RaidMapDescPtrs.ptrStruct.ldSpanMap);
374 device_printf(sc->mrsas_dev,
375 "MR_LD_SPAN_MAP size 0x%lx\n", sizeof(MR_LD_SPAN_MAP));
376 for (j = 0; j < ld_count; j++) {
377 printf("mrsas(%d) : fw_map_dyn->ldSpanMap[%d].ldRaid.targetId 0x%x "
378 "fw_map_dyn->ldSpanMap[%d].ldRaid.seqNum 0x%x size 0x%x\n",
379 j, j, fw_map_dyn->RaidMapDescPtrs.ptrStruct.ldSpanMap[j].ldRaid.targetId, j,
380 fw_map_dyn->RaidMapDescPtrs.ptrStruct.ldSpanMap[j].ldRaid.seqNum,
381 (u_int32_t)fw_map_dyn->RaidMapDescPtrs.ptrStruct.ldSpanMap[j].ldRaid.rowSize);
382 printf("mrsas(%d) : pDrvRaidMap->ldSpanMap[%d].ldRaid.targetId 0x%x "
383 "pDrvRaidMap->ldSpanMap[%d].ldRaid.seqNum 0x%x size 0x%x\n",
384 j, j, pDrvRaidMap->ldSpanMap[j].ldRaid.targetId, j,
385 pDrvRaidMap->ldSpanMap[j].ldRaid.seqNum,
386 (u_int32_t)pDrvRaidMap->ldSpanMap[j].ldRaid.rowSize);
387 printf("mrsas : drv raid map all %p raid map %p LD RAID MAP %p/%p\n",
388 drv_map, pDrvRaidMap, &fw_map_dyn->RaidMapDescPtrs.ptrStruct.ldSpanMap[j].ldRaid,
389 &pDrvRaidMap->ldSpanMap[j].ldRaid);
394 device_printf(sc->mrsas_dev,
395 "wrong number of desctableElements %d\n",
396 fw_map_dyn->descTableNumElements);
404 * This function will Populate Driver Map using firmware raid map
407 MR_PopulateDrvRaidMap(struct mrsas_softc *sc)
409 MR_FW_RAID_MAP_ALL *fw_map_old = NULL;
410 MR_FW_RAID_MAP_EXT *fw_map_ext;
411 MR_FW_RAID_MAP *pFwRaidMap = NULL;
415 MR_DRV_RAID_MAP_ALL *drv_map = sc->ld_drv_map[(sc->map_id & 1)];
416 MR_DRV_RAID_MAP *pDrvRaidMap = &drv_map->raidMap;
418 if (sc->maxRaidMapSize) {
419 return MR_PopulateDrvRaidMapVentura(sc);
420 } else if (sc->max256vdSupport) {
421 fw_map_ext = (MR_FW_RAID_MAP_EXT *) sc->raidmap_mem[(sc->map_id & 1)];
422 ld_count = (u_int16_t)(fw_map_ext->ldCount);
423 if (ld_count > MAX_LOGICAL_DRIVES_EXT) {
424 device_printf(sc->mrsas_dev,
425 "mrsas: LD count exposed in RAID map in not valid\n");
429 for (i = 0; i < ld_count; i++) {
430 printf("mrsas : Index 0x%x Target Id 0x%x Seq Num 0x%x Size 0/%lx\n",
431 i, fw_map_ext->ldSpanMap[i].ldRaid.targetId,
432 fw_map_ext->ldSpanMap[i].ldRaid.seqNum,
433 fw_map_ext->ldSpanMap[i].ldRaid.size);
436 memset(drv_map, 0, sc->drv_map_sz);
437 pDrvRaidMap->ldCount = ld_count;
438 pDrvRaidMap->fpPdIoTimeoutSec = fw_map_ext->fpPdIoTimeoutSec;
439 for (i = 0; i < (MAX_LOGICAL_DRIVES_EXT); i++) {
440 pDrvRaidMap->ldTgtIdToLd[i] = (u_int16_t)fw_map_ext->ldTgtIdToLd[i];
442 memcpy(pDrvRaidMap->ldSpanMap, fw_map_ext->ldSpanMap, sizeof(MR_LD_SPAN_MAP) * ld_count);
444 for (i = 0; i < ld_count; i++) {
445 printf("mrsas(%d) : fw_map_ext->ldSpanMap[%d].ldRaid.targetId 0x%x "
446 "fw_map_ext->ldSpanMap[%d].ldRaid.seqNum 0x%x size 0x%x\n",
447 i, i, fw_map_ext->ldSpanMap[i].ldRaid.targetId, i,
448 fw_map_ext->ldSpanMap[i].ldRaid.seqNum,
449 (u_int32_t)fw_map_ext->ldSpanMap[i].ldRaid.rowSize);
450 printf("mrsas(%d) : pDrvRaidMap->ldSpanMap[%d].ldRaid.targetId 0x%x"
451 "pDrvRaidMap->ldSpanMap[%d].ldRaid.seqNum 0x%x size 0x%x\n", i, i,
452 pDrvRaidMap->ldSpanMap[i].ldRaid.targetId, i,
453 pDrvRaidMap->ldSpanMap[i].ldRaid.seqNum,
454 (u_int32_t)pDrvRaidMap->ldSpanMap[i].ldRaid.rowSize);
455 printf("mrsas : drv raid map all %p raid map %p LD RAID MAP %p/%p\n",
456 drv_map, pDrvRaidMap, &fw_map_ext->ldSpanMap[i].ldRaid,
457 &pDrvRaidMap->ldSpanMap[i].ldRaid);
460 memcpy(pDrvRaidMap->arMapInfo, fw_map_ext->arMapInfo,
461 sizeof(MR_ARRAY_INFO) * MAX_API_ARRAYS_EXT);
462 memcpy(pDrvRaidMap->devHndlInfo, fw_map_ext->devHndlInfo,
463 sizeof(MR_DEV_HANDLE_INFO) * MAX_RAIDMAP_PHYSICAL_DEVICES);
465 pDrvRaidMap->totalSize = sizeof(MR_FW_RAID_MAP_EXT);
467 fw_map_old = (MR_FW_RAID_MAP_ALL *) sc->raidmap_mem[(sc->map_id & 1)];
468 pFwRaidMap = &fw_map_old->raidMap;
471 for (i = 0; i < pFwRaidMap->ldCount; i++) {
472 device_printf(sc->mrsas_dev,
473 "Index 0x%x Target Id 0x%x Seq Num 0x%x Size 0/%lx\n", i,
474 fw_map_old->raidMap.ldSpanMap[i].ldRaid.targetId,
475 fw_map_old->raidMap.ldSpanMap[i].ldRaid.seqNum,
476 fw_map_old->raidMap.ldSpanMap[i].ldRaid.size);
480 memset(drv_map, 0, sc->drv_map_sz);
481 pDrvRaidMap->totalSize = pFwRaidMap->totalSize;
482 pDrvRaidMap->ldCount = pFwRaidMap->ldCount;
483 pDrvRaidMap->fpPdIoTimeoutSec =
484 pFwRaidMap->fpPdIoTimeoutSec;
486 for (i = 0; i < MAX_RAIDMAP_LOGICAL_DRIVES + MAX_RAIDMAP_VIEWS; i++) {
487 pDrvRaidMap->ldTgtIdToLd[i] =
488 (u_int8_t)pFwRaidMap->ldTgtIdToLd[i];
491 for (i = 0; i < pDrvRaidMap->ldCount; i++) {
492 pDrvRaidMap->ldSpanMap[i] =
493 pFwRaidMap->ldSpanMap[i];
496 device_printf(sc->mrsas_dev, "pFwRaidMap->ldSpanMap[%d].ldRaid.targetId 0x%x "
497 "pFwRaidMap->ldSpanMap[%d].ldRaid.seqNum 0x%x size 0x%x\n",
498 i, i, pFwRaidMap->ldSpanMap[i].ldRaid.targetId,
499 pFwRaidMap->ldSpanMap[i].ldRaid.seqNum,
500 (u_int32_t)pFwRaidMap->ldSpanMap[i].ldRaid.rowSize);
501 device_printf(sc->mrsas_dev, "pDrvRaidMap->ldSpanMap[%d].ldRaid.targetId 0x%x"
502 "pDrvRaidMap->ldSpanMap[%d].ldRaid.seqNum 0x%x size 0x%x\n", i, i,
503 pDrvRaidMap->ldSpanMap[i].ldRaid.targetId,
504 pDrvRaidMap->ldSpanMap[i].ldRaid.seqNum,
505 (u_int32_t)pDrvRaidMap->ldSpanMap[i].ldRaid.rowSize);
506 device_printf(sc->mrsas_dev, "drv raid map all %p raid map %p LD RAID MAP %p/%p\n",
507 drv_map, pDrvRaidMap,
508 &pFwRaidMap->ldSpanMap[i].ldRaid, &pDrvRaidMap->ldSpanMap[i].ldRaid);
512 memcpy(pDrvRaidMap->arMapInfo, pFwRaidMap->arMapInfo,
513 sizeof(MR_ARRAY_INFO) * MAX_RAIDMAP_ARRAYS);
514 memcpy(pDrvRaidMap->devHndlInfo, pFwRaidMap->devHndlInfo,
515 sizeof(MR_DEV_HANDLE_INFO) *
516 MAX_RAIDMAP_PHYSICAL_DEVICES);
522 * MR_ValidateMapInfo: Validate RAID map
523 * input: Adapter instance soft state
525 * This function checks and validates the loaded RAID map. It returns 0 if
526 * successful, and 1 otherwise.
529 MR_ValidateMapInfo(struct mrsas_softc *sc)
534 if (MR_PopulateDrvRaidMap(sc))
537 MR_DRV_RAID_MAP_ALL *drv_map = sc->ld_drv_map[(sc->map_id & 1)];
538 MR_DRV_RAID_MAP *pDrvRaidMap = &drv_map->raidMap;
540 u_int32_t expected_map_size;
542 drv_map = sc->ld_drv_map[(sc->map_id & 1)];
543 pDrvRaidMap = &drv_map->raidMap;
544 PLD_SPAN_INFO ldSpanInfo = (PLD_SPAN_INFO) & sc->log_to_span;
546 if (sc->maxRaidMapSize)
547 expected_map_size = sizeof(MR_DRV_RAID_MAP_ALL);
548 else if (sc->max256vdSupport)
549 expected_map_size = sizeof(MR_FW_RAID_MAP_EXT);
552 (sizeof(MR_FW_RAID_MAP) - sizeof(MR_LD_SPAN_MAP)) +
553 (sizeof(MR_LD_SPAN_MAP) * pDrvRaidMap->ldCount);
555 if (pDrvRaidMap->totalSize != expected_map_size) {
556 device_printf(sc->mrsas_dev, "map size %x not matching ld count\n", expected_map_size);
557 device_printf(sc->mrsas_dev, "span map= %x\n", (unsigned int)sizeof(MR_LD_SPAN_MAP));
558 device_printf(sc->mrsas_dev, "pDrvRaidMap->totalSize=%x\n", pDrvRaidMap->totalSize);
561 if (sc->UnevenSpanSupport) {
562 mr_update_span_set(drv_map, ldSpanInfo);
564 mrsas_update_load_balance_params(sc, drv_map, sc->load_balance_info);
571 * Function to print info about span set created in driver from FW raid map
574 * ldSpanInfo: ld map span info per HBA instance
580 getSpanInfo(MR_DRV_RAID_MAP_ALL * map, PLD_SPAN_INFO ldSpanInfo)
586 LD_SPAN_SET *span_set;
587 MR_QUAD_ELEMENT *quad;
591 for (ldCount = 0; ldCount < MAX_LOGICAL_DRIVES; ldCount++) {
592 ld = MR_TargetIdToLdGet(ldCount, map);
593 if (ld >= MAX_LOGICAL_DRIVES) {
596 raid = MR_LdRaidGet(ld, map);
597 printf("LD %x: span_depth=%x\n", ld, raid->spanDepth);
598 for (span = 0; span < raid->spanDepth; span++)
599 printf("Span=%x, number of quads=%x\n", span,
600 map->raidMap.ldSpanMap[ld].spanBlock[span].
601 block_span_info.noElements);
602 for (element = 0; element < MAX_QUAD_DEPTH; element++) {
603 span_set = &(ldSpanInfo[ld].span_set[element]);
604 if (span_set->span_row_data_width == 0)
607 printf("Span Set %x: width=%x, diff=%x\n", element,
608 (unsigned int)span_set->span_row_data_width,
609 (unsigned int)span_set->diff);
610 printf("logical LBA start=0x%08lx, end=0x%08lx\n",
611 (long unsigned int)span_set->log_start_lba,
612 (long unsigned int)span_set->log_end_lba);
613 printf("span row start=0x%08lx, end=0x%08lx\n",
614 (long unsigned int)span_set->span_row_start,
615 (long unsigned int)span_set->span_row_end);
616 printf("data row start=0x%08lx, end=0x%08lx\n",
617 (long unsigned int)span_set->data_row_start,
618 (long unsigned int)span_set->data_row_end);
619 printf("data strip start=0x%08lx, end=0x%08lx\n",
620 (long unsigned int)span_set->data_strip_start,
621 (long unsigned int)span_set->data_strip_end);
623 for (span = 0; span < raid->spanDepth; span++) {
624 if (map->raidMap.ldSpanMap[ld].spanBlock[span].
625 block_span_info.noElements >= element + 1) {
626 quad = &map->raidMap.ldSpanMap[ld].
627 spanBlock[span].block_span_info.
629 printf("Span=%x, Quad=%x, diff=%x\n", span,
630 element, quad->diff);
631 printf("offset_in_span=0x%08lx\n",
632 (long unsigned int)quad->offsetInSpan);
633 printf("logical start=0x%08lx, end=0x%08lx\n",
634 (long unsigned int)quad->logStart,
635 (long unsigned int)quad->logEnd);
646 * This routine calculates the Span block for given row using spanset.
648 * Inputs : HBA instance
649 * ld: Logical drive number
653 * Outputs : span - Span number block
654 * - Absolute Block number in the physical disk
655 * div_error - Devide error code.
659 mr_spanset_get_span_block(struct mrsas_softc *sc, u_int32_t ld, u_int64_t row,
660 u_int64_t *span_blk, MR_DRV_RAID_MAP_ALL * map, int *div_error)
662 MR_LD_RAID *raid = MR_LdRaidGet(ld, map);
663 LD_SPAN_SET *span_set;
664 MR_QUAD_ELEMENT *quad;
665 u_int32_t span, info;
666 PLD_SPAN_INFO ldSpanInfo = sc->log_to_span;
668 for (info = 0; info < MAX_QUAD_DEPTH; info++) {
669 span_set = &(ldSpanInfo[ld].span_set[info]);
671 if (span_set->span_row_data_width == 0)
673 if (row > span_set->data_row_end)
676 for (span = 0; span < raid->spanDepth; span++)
677 if (map->raidMap.ldSpanMap[ld].spanBlock[span].
678 block_span_info.noElements >= info + 1) {
679 quad = &map->raidMap.ldSpanMap[ld].
681 block_span_info.quad[info];
682 if (quad->diff == 0) {
686 if (quad->logStart <= row &&
687 row <= quad->logEnd &&
688 (mega_mod64(row - quad->logStart,
690 if (span_blk != NULL) {
694 ((row - quad->logStart),
696 blk = (blk + quad->offsetInSpan)
697 << raid->stripeShift;
709 * This routine calculates the row for given strip using spanset.
711 * Inputs : HBA instance
712 * ld: Logical drive number
716 * Outputs : row - row associated with strip
720 get_row_from_strip(struct mrsas_softc *sc,
721 u_int32_t ld, u_int64_t strip, MR_DRV_RAID_MAP_ALL * map)
723 MR_LD_RAID *raid = MR_LdRaidGet(ld, map);
724 LD_SPAN_SET *span_set;
725 PLD_SPAN_INFO ldSpanInfo = sc->log_to_span;
726 u_int32_t info, strip_offset, span, span_offset;
727 u_int64_t span_set_Strip, span_set_Row;
729 for (info = 0; info < MAX_QUAD_DEPTH; info++) {
730 span_set = &(ldSpanInfo[ld].span_set[info]);
732 if (span_set->span_row_data_width == 0)
734 if (strip > span_set->data_strip_end)
737 span_set_Strip = strip - span_set->data_strip_start;
738 strip_offset = mega_mod64(span_set_Strip,
739 span_set->span_row_data_width);
740 span_set_Row = mega_div64_32(span_set_Strip,
741 span_set->span_row_data_width) * span_set->diff;
742 for (span = 0, span_offset = 0; span < raid->spanDepth; span++)
743 if (map->raidMap.ldSpanMap[ld].spanBlock[span].
744 block_span_info.noElements >= info + 1) {
746 span_set->strip_offset[span])
751 mrsas_dprint(sc, MRSAS_PRL11, "AVAGO Debug : Strip 0x%llx, span_set_Strip 0x%llx, span_set_Row 0x%llx "
752 "data width 0x%llx span offset 0x%llx\n", (unsigned long long)strip,
753 (unsigned long long)span_set_Strip,
754 (unsigned long long)span_set_Row,
755 (unsigned long long)span_set->span_row_data_width, (unsigned long long)span_offset);
756 mrsas_dprint(sc, MRSAS_PRL11, "AVAGO Debug : For strip 0x%llx row is 0x%llx\n", (unsigned long long)strip,
757 (unsigned long long)span_set->data_row_start +
758 (unsigned long long)span_set_Row + (span_offset - 1));
759 return (span_set->data_row_start + span_set_Row + (span_offset - 1));
766 * This routine calculates the Start Strip for given row using spanset.
768 * Inputs: HBA instance
769 * ld: Logical drive number
773 * Outputs : Strip - Start strip associated with row
777 get_strip_from_row(struct mrsas_softc *sc,
778 u_int32_t ld, u_int64_t row, MR_DRV_RAID_MAP_ALL * map)
780 MR_LD_RAID *raid = MR_LdRaidGet(ld, map);
781 LD_SPAN_SET *span_set;
782 MR_QUAD_ELEMENT *quad;
783 PLD_SPAN_INFO ldSpanInfo = sc->log_to_span;
784 u_int32_t span, info;
787 for (info = 0; info < MAX_QUAD_DEPTH; info++) {
788 span_set = &(ldSpanInfo[ld].span_set[info]);
790 if (span_set->span_row_data_width == 0)
792 if (row > span_set->data_row_end)
795 for (span = 0; span < raid->spanDepth; span++)
796 if (map->raidMap.ldSpanMap[ld].spanBlock[span].
797 block_span_info.noElements >= info + 1) {
798 quad = &map->raidMap.ldSpanMap[ld].
799 spanBlock[span].block_span_info.quad[info];
800 if (quad->logStart <= row &&
801 row <= quad->logEnd &&
802 mega_mod64((row - quad->logStart),
804 strip = mega_div64_32
805 (((row - span_set->data_row_start)
808 strip *= span_set->span_row_data_width;
809 strip += span_set->data_strip_start;
810 strip += span_set->strip_offset[span];
815 mrsas_dprint(sc, MRSAS_PRL11, "AVAGO Debug - get_strip_from_row: returns invalid "
816 "strip for ld=%x, row=%lx\n", ld, (long unsigned int)row);
821 * *****************************************************************************
824 * This routine calculates the Physical Arm for given strip using spanset.
826 * Inputs : HBA instance
827 * Logical drive number
831 * Outputs : Phys Arm - Phys Arm associated with strip
835 get_arm_from_strip(struct mrsas_softc *sc,
836 u_int32_t ld, u_int64_t strip, MR_DRV_RAID_MAP_ALL * map)
838 MR_LD_RAID *raid = MR_LdRaidGet(ld, map);
839 LD_SPAN_SET *span_set;
840 PLD_SPAN_INFO ldSpanInfo = sc->log_to_span;
841 u_int32_t info, strip_offset, span, span_offset;
843 for (info = 0; info < MAX_QUAD_DEPTH; info++) {
844 span_set = &(ldSpanInfo[ld].span_set[info]);
846 if (span_set->span_row_data_width == 0)
848 if (strip > span_set->data_strip_end)
851 strip_offset = (u_int32_t)mega_mod64
852 ((strip - span_set->data_strip_start),
853 span_set->span_row_data_width);
855 for (span = 0, span_offset = 0; span < raid->spanDepth; span++)
856 if (map->raidMap.ldSpanMap[ld].spanBlock[span].
857 block_span_info.noElements >= info + 1) {
858 if (strip_offset >= span_set->strip_offset[span])
859 span_offset = span_set->strip_offset[span];
863 mrsas_dprint(sc, MRSAS_PRL11, "AVAGO PRL11: get_arm_from_strip: "
864 "for ld=0x%x strip=0x%lx arm is 0x%x\n", ld,
865 (long unsigned int)strip, (strip_offset - span_offset));
866 return (strip_offset - span_offset);
869 mrsas_dprint(sc, MRSAS_PRL11, "AVAGO Debug: - get_arm_from_strip: returns invalid arm"
870 " for ld=%x strip=%lx\n", ld, (long unsigned int)strip);
875 /* This Function will return Phys arm */
877 get_arm(struct mrsas_softc *sc, u_int32_t ld, u_int8_t span, u_int64_t stripe,
878 MR_DRV_RAID_MAP_ALL * map)
880 MR_LD_RAID *raid = MR_LdRaidGet(ld, map);
882 /* Need to check correct default value */
885 switch (raid->level) {
889 arm = mega_mod64(stripe, SPAN_ROW_SIZE(map, ld, span));
892 /* start with logical arm */
893 arm = get_arm_from_strip(sc, ld, stripe, map);
903 * This routine calculates the arm, span and block for the specified stripe and
904 * reference in stripe using spanset
908 * ld - Logical drive number
909 * stripRow: Stripe number
910 * stripRef: Reference in stripe
912 * Outputs : span - Span number block - Absolute Block
913 * number in the physical disk
916 mr_spanset_get_phy_params(struct mrsas_softc *sc, u_int32_t ld, u_int64_t stripRow,
917 u_int16_t stripRef, struct IO_REQUEST_INFO *io_info,
918 RAID_CONTEXT * pRAID_Context, MR_DRV_RAID_MAP_ALL * map)
920 MR_LD_RAID *raid = MR_LdRaidGet(ld, map);
921 u_int32_t pd, arRef, r1_alt_pd;
922 u_int8_t physArm, span;
924 u_int8_t retval = TRUE;
925 u_int64_t *pdBlock = &io_info->pdBlock;
926 u_int16_t *pDevHandle = &io_info->devHandle;
927 u_int8_t *pPdInterface = &io_info->pdInterface;
929 u_int32_t logArm, rowMod, armQ, arm;
931 /* Get row and span from io_info for Uneven Span IO. */
932 row = io_info->start_row;
933 span = io_info->start_span;
935 if (raid->level == 6) {
936 logArm = get_arm_from_strip(sc, ld, stripRow, map);
937 rowMod = mega_mod64(row, SPAN_ROW_SIZE(map, ld, span));
938 armQ = SPAN_ROW_SIZE(map, ld, span) - 1 - rowMod;
939 arm = armQ + 1 + logArm;
940 if (arm >= SPAN_ROW_SIZE(map, ld, span))
941 arm -= SPAN_ROW_SIZE(map, ld, span);
942 physArm = (u_int8_t)arm;
944 /* Calculate the arm */
945 physArm = get_arm(sc, ld, span, stripRow, map);
947 arRef = MR_LdSpanArrayGet(ld, span, map);
948 pd = MR_ArPdGet(arRef, physArm, map);
950 if (pd != MR_PD_INVALID) {
951 *pDevHandle = MR_PdDevHandleGet(pd, map);
952 *pPdInterface = MR_PdInterfaceTypeGet(pd, map);
953 /* get second pd also for raid 1/10 fast path writes */
954 if ((raid->level == 1) && !io_info->isRead) {
955 r1_alt_pd = MR_ArPdGet(arRef, physArm + 1, map);
956 if (r1_alt_pd != MR_PD_INVALID)
957 io_info->r1_alt_dev_handle = MR_PdDevHandleGet(r1_alt_pd, map);
960 *pDevHandle = MR_DEVHANDLE_INVALID;
961 if ((raid->level >= 5) && ((sc->device_id == MRSAS_TBOLT) ||
962 (sc->mrsas_gen3_ctrl &&
963 raid->regTypeReqOnRead != REGION_TYPE_UNUSED)))
964 pRAID_Context->regLockFlags = REGION_TYPE_EXCLUSIVE;
965 else if (raid->level == 1) {
966 pd = MR_ArPdGet(arRef, physArm + 1, map);
967 if (pd != MR_PD_INVALID) {
968 *pDevHandle = MR_PdDevHandleGet(pd, map);
969 *pPdInterface = MR_PdInterfaceTypeGet(pd, map);
974 *pdBlock += stripRef + MR_LdSpanPtrGet(ld, span, map)->startBlk;
975 if (sc->is_ventura || sc->is_aero) {
976 ((RAID_CONTEXT_G35 *) pRAID_Context)->spanArm =
977 (span << RAID_CTX_SPANARM_SPAN_SHIFT) | physArm;
978 io_info->span_arm = (span << RAID_CTX_SPANARM_SPAN_SHIFT) | physArm;
980 pRAID_Context->spanArm = (span << RAID_CTX_SPANARM_SPAN_SHIFT) | physArm;
981 io_info->span_arm = pRAID_Context->spanArm;
987 * MR_BuildRaidContext: Set up Fast path RAID context
989 * This function will initiate command processing. The start/end row and strip
990 * information is calculated then the lock is acquired. This function will
991 * return 0 if region lock was acquired OR return num strips.
994 MR_BuildRaidContext(struct mrsas_softc *sc, struct IO_REQUEST_INFO *io_info,
995 RAID_CONTEXT * pRAID_Context, MR_DRV_RAID_MAP_ALL * map)
998 u_int32_t ld, stripSize, stripe_mask;
999 u_int64_t endLba, endStrip, endRow, start_row, start_strip;
1000 REGION_KEY regStart;
1002 u_int8_t num_strips, numRows;
1003 u_int16_t ref_in_start_stripe, ref_in_end_stripe;
1004 u_int64_t ldStartBlock;
1005 u_int32_t numBlocks, ldTgtId;
1006 u_int8_t isRead, stripIdx;
1007 u_int8_t retval = 0;
1008 u_int8_t startlba_span = SPAN_INVALID;
1009 u_int64_t *pdBlock = &io_info->pdBlock;
1012 ldStartBlock = io_info->ldStartBlock;
1013 numBlocks = io_info->numBlocks;
1014 ldTgtId = io_info->ldTgtId;
1015 isRead = io_info->isRead;
1017 io_info->IoforUnevenSpan = 0;
1018 io_info->start_span = SPAN_INVALID;
1020 ld = MR_TargetIdToLdGet(ldTgtId, map);
1021 raid = MR_LdRaidGet(ld, map);
1023 /* check read ahead bit */
1024 io_info->raCapable = raid->capability.raCapable;
1026 if (raid->rowDataSize == 0) {
1027 if (MR_LdSpanPtrGet(ld, 0, map)->spanRowDataSize == 0)
1029 else if (sc->UnevenSpanSupport) {
1030 io_info->IoforUnevenSpan = 1;
1032 mrsas_dprint(sc, MRSAS_PRL11, "AVAGO Debug: raid->rowDataSize is 0, but has SPAN[0] rowDataSize = 0x%0x,"
1033 " but there is _NO_ UnevenSpanSupport\n",
1034 MR_LdSpanPtrGet(ld, 0, map)->spanRowDataSize);
1038 stripSize = 1 << raid->stripeShift;
1039 stripe_mask = stripSize - 1;
1041 * calculate starting row and stripe, and number of strips and rows
1043 start_strip = ldStartBlock >> raid->stripeShift;
1044 ref_in_start_stripe = (u_int16_t)(ldStartBlock & stripe_mask);
1045 endLba = ldStartBlock + numBlocks - 1;
1046 ref_in_end_stripe = (u_int16_t)(endLba & stripe_mask);
1047 endStrip = endLba >> raid->stripeShift;
1048 num_strips = (u_int8_t)(endStrip - start_strip + 1); /* End strip */
1049 if (io_info->IoforUnevenSpan) {
1050 start_row = get_row_from_strip(sc, ld, start_strip, map);
1051 endRow = get_row_from_strip(sc, ld, endStrip, map);
1052 if (raid->spanDepth == 1) {
1054 *pdBlock = start_row << raid->stripeShift;
1056 startlba_span = (u_int8_t)mr_spanset_get_span_block(sc, ld, start_row,
1057 pdBlock, map, &error_code);
1058 if (error_code == 1) {
1059 mrsas_dprint(sc, MRSAS_PRL11, "AVAGO Debug: return from %s %d. Send IO w/o region lock.\n",
1060 __func__, __LINE__);
1064 if (startlba_span == SPAN_INVALID) {
1065 mrsas_dprint(sc, MRSAS_PRL11, "AVAGO Debug: return from %s %d for row 0x%llx,"
1066 "start strip %llx endSrip %llx\n", __func__,
1067 __LINE__, (unsigned long long)start_row,
1068 (unsigned long long)start_strip,
1069 (unsigned long long)endStrip);
1072 io_info->start_span = startlba_span;
1073 io_info->start_row = start_row;
1074 mrsas_dprint(sc, MRSAS_PRL11, "AVAGO Debug: Check Span number from %s %d for row 0x%llx, "
1075 " start strip 0x%llx endSrip 0x%llx span 0x%x\n",
1076 __func__, __LINE__, (unsigned long long)start_row,
1077 (unsigned long long)start_strip,
1078 (unsigned long long)endStrip, startlba_span);
1079 mrsas_dprint(sc, MRSAS_PRL11, "AVAGO Debug : 1. start_row 0x%llx endRow 0x%llx Start span 0x%x\n",
1080 (unsigned long long)start_row, (unsigned long long)endRow, startlba_span);
1082 start_row = mega_div64_32(start_strip, raid->rowDataSize);
1083 endRow = mega_div64_32(endStrip, raid->rowDataSize);
1086 numRows = (u_int8_t)(endRow - start_row + 1); /* get the row count */
1089 * Calculate region info. (Assume region at start of first row, and
1090 * assume this IO needs the full row - will adjust if not true.)
1092 regStart = start_row << raid->stripeShift;
1093 regSize = stripSize;
1095 /* Check if we can send this I/O via FastPath */
1096 if (raid->capability.fpCapable) {
1098 io_info->fpOkForIo = (raid->capability.fpReadCapable &&
1099 ((num_strips == 1) ||
1100 raid->capability.fpReadAcrossStripe));
1102 io_info->fpOkForIo = (raid->capability.fpWriteCapable &&
1103 ((num_strips == 1) ||
1104 raid->capability.fpWriteAcrossStripe));
1106 io_info->fpOkForIo = FALSE;
1109 if (num_strips == 1) {
1110 regStart += ref_in_start_stripe;
1111 regSize = numBlocks;
1113 } else if (io_info->IoforUnevenSpan == 0) {
1115 * For Even span region lock optimization. If the start strip
1116 * is the last in the start row
1118 if (start_strip == (start_row + 1) * raid->rowDataSize - 1) {
1119 regStart += ref_in_start_stripe;
1121 * initialize count to sectors from startRef to end
1124 regSize = stripSize - ref_in_start_stripe;
1126 /* add complete rows in the middle of the transfer */
1128 regSize += (numRows - 2) << raid->stripeShift;
1130 /* if IO ends within first strip of last row */
1131 if (endStrip == endRow * raid->rowDataSize)
1132 regSize += ref_in_end_stripe + 1;
1134 regSize += stripSize;
1136 if (start_strip == (get_strip_from_row(sc, ld, start_row, map) +
1137 SPAN_ROW_DATA_SIZE(map, ld, startlba_span) - 1)) {
1138 regStart += ref_in_start_stripe;
1140 * initialize count to sectors from startRef to end
1143 regSize = stripSize - ref_in_start_stripe;
1145 /* add complete rows in the middle of the transfer */
1147 regSize += (numRows - 2) << raid->stripeShift;
1149 /* if IO ends within first strip of last row */
1150 if (endStrip == get_strip_from_row(sc, ld, endRow, map))
1151 regSize += ref_in_end_stripe + 1;
1153 regSize += stripSize;
1155 pRAID_Context->timeoutValue = map->raidMap.fpPdIoTimeoutSec;
1156 if (sc->mrsas_gen3_ctrl)
1157 pRAID_Context->regLockFlags = (isRead) ? raid->regTypeReqOnRead : raid->regTypeReqOnWrite;
1158 else if (sc->device_id == MRSAS_TBOLT)
1159 pRAID_Context->regLockFlags = (isRead) ? REGION_TYPE_SHARED_READ : raid->regTypeReqOnWrite;
1160 pRAID_Context->VirtualDiskTgtId = raid->targetId;
1161 pRAID_Context->regLockRowLBA = regStart;
1162 pRAID_Context->regLockLength = regSize;
1163 pRAID_Context->configSeqNum = raid->seqNum;
1166 * Get Phy Params only if FP capable, or else leave it to MR firmware
1167 * to do the calculation.
1169 if (io_info->fpOkForIo) {
1170 retval = io_info->IoforUnevenSpan ?
1171 mr_spanset_get_phy_params(sc, ld, start_strip,
1172 ref_in_start_stripe, io_info, pRAID_Context, map) :
1173 MR_GetPhyParams(sc, ld, start_strip,
1174 ref_in_start_stripe, io_info, pRAID_Context, map);
1175 /* If IO on an invalid Pd, then FP is not possible */
1176 if (io_info->devHandle == MR_DEVHANDLE_INVALID)
1177 io_info->fpOkForIo = FALSE;
1179 * if FP possible, set the SLUD bit in regLockFlags for
1182 else if ((sc->is_ventura || sc->is_aero) && !isRead &&
1183 (raid->writeMode == MR_RL_WRITE_BACK_MODE) && (raid->level <= 1) &&
1184 raid->capability.fpCacheBypassCapable) {
1185 ((RAID_CONTEXT_G35 *) pRAID_Context)->routingFlags.bits.sld = 1;
1189 } else if (isRead) {
1190 for (stripIdx = 0; stripIdx < num_strips; stripIdx++) {
1191 retval = io_info->IoforUnevenSpan ?
1192 mr_spanset_get_phy_params(sc, ld, start_strip + stripIdx,
1193 ref_in_start_stripe, io_info, pRAID_Context, map) :
1194 MR_GetPhyParams(sc, ld, start_strip + stripIdx,
1195 ref_in_start_stripe, io_info, pRAID_Context, map);
1201 /* Just for testing what arm we get for strip. */
1202 get_arm_from_strip(sc, ld, start_strip, map);
1209 * This routine pepare spanset info from Valid Raid map and store it into local
1210 * copy of ldSpanInfo per instance data structure.
1213 * ldSpanInfo per HBA instance
1217 mr_update_span_set(MR_DRV_RAID_MAP_ALL * map, PLD_SPAN_INFO ldSpanInfo)
1219 u_int8_t span, count;
1220 u_int32_t element, span_row_width;
1223 LD_SPAN_SET *span_set, *span_set_prev;
1224 MR_QUAD_ELEMENT *quad;
1228 for (ldCount = 0; ldCount < MAX_LOGICAL_DRIVES; ldCount++) {
1229 ld = MR_TargetIdToLdGet(ldCount, map);
1230 if (ld >= MAX_LOGICAL_DRIVES)
1232 raid = MR_LdRaidGet(ld, map);
1233 for (element = 0; element < MAX_QUAD_DEPTH; element++) {
1234 for (span = 0; span < raid->spanDepth; span++) {
1235 if (map->raidMap.ldSpanMap[ld].spanBlock[span].
1236 block_span_info.noElements < element + 1)
1239 span_set = &(ldSpanInfo[ld].span_set[element]);
1240 quad = &map->raidMap.ldSpanMap[ld].
1241 spanBlock[span].block_span_info.quad[element];
1243 span_set->diff = quad->diff;
1245 for (count = 0, span_row_width = 0;
1246 count < raid->spanDepth; count++) {
1247 if (map->raidMap.ldSpanMap[ld].spanBlock[count].
1248 block_span_info.noElements >= element + 1) {
1249 span_set->strip_offset[count] = span_row_width;
1251 MR_LdSpanPtrGet(ld, count, map)->spanRowDataSize;
1253 printf("AVAGO Debug span %x rowDataSize %x\n", count,
1254 MR_LdSpanPtrGet(ld, count, map)->spanRowDataSize);
1259 span_set->span_row_data_width = span_row_width;
1260 span_row = mega_div64_32(((quad->logEnd -
1261 quad->logStart) + quad->diff), quad->diff);
1264 span_set->log_start_lba = 0;
1265 span_set->log_end_lba =
1266 ((span_row << raid->stripeShift) * span_row_width) - 1;
1268 span_set->span_row_start = 0;
1269 span_set->span_row_end = span_row - 1;
1271 span_set->data_strip_start = 0;
1272 span_set->data_strip_end = (span_row * span_row_width) - 1;
1274 span_set->data_row_start = 0;
1275 span_set->data_row_end = (span_row * quad->diff) - 1;
1277 span_set_prev = &(ldSpanInfo[ld].span_set[element - 1]);
1278 span_set->log_start_lba = span_set_prev->log_end_lba + 1;
1279 span_set->log_end_lba = span_set->log_start_lba +
1280 ((span_row << raid->stripeShift) * span_row_width) - 1;
1282 span_set->span_row_start = span_set_prev->span_row_end + 1;
1283 span_set->span_row_end =
1284 span_set->span_row_start + span_row - 1;
1286 span_set->data_strip_start =
1287 span_set_prev->data_strip_end + 1;
1288 span_set->data_strip_end = span_set->data_strip_start +
1289 (span_row * span_row_width) - 1;
1291 span_set->data_row_start = span_set_prev->data_row_end + 1;
1292 span_set->data_row_end = span_set->data_row_start +
1293 (span_row * quad->diff) - 1;
1297 if (span == raid->spanDepth)
1298 break; /* no quads remain */
1302 getSpanInfo(map, ldSpanInfo); /* to get span set info */
1307 * mrsas_update_load_balance_params: Update load balance parmas
1309 * sc - driver softc instance
1310 * drv_map - driver RAID map
1311 * lbInfo - Load balance info
1313 * This function updates the load balance parameters for the LD config of a two
1314 * drive optimal RAID-1.
1317 mrsas_update_load_balance_params(struct mrsas_softc *sc,
1318 MR_DRV_RAID_MAP_ALL * drv_map, PLD_LOAD_BALANCE_INFO lbInfo)
1324 if (sc->lb_pending_cmds > 128 || sc->lb_pending_cmds < 1)
1325 sc->lb_pending_cmds = LB_PENDING_CMDS_DEFAULT;
1327 for (ldCount = 0; ldCount < MAX_LOGICAL_DRIVES_EXT; ldCount++) {
1328 ld = MR_TargetIdToLdGet(ldCount, drv_map);
1329 if (ld >= MAX_LOGICAL_DRIVES_EXT) {
1330 lbInfo[ldCount].loadBalanceFlag = 0;
1333 raid = MR_LdRaidGet(ld, drv_map);
1334 if ((raid->level != 1) ||
1335 (raid->ldState != MR_LD_STATE_OPTIMAL)) {
1336 lbInfo[ldCount].loadBalanceFlag = 0;
1339 lbInfo[ldCount].loadBalanceFlag = 1;
1344 * mrsas_set_pd_lba: Sets PD LBA
1345 * input: io_request pointer
1349 * Local RAID map pointer
1350 * Start block of IO Block Size
1352 * Used to set the PD logical block address in CDB for FP IOs.
1355 mrsas_set_pd_lba(MRSAS_RAID_SCSI_IO_REQUEST * io_request, u_int8_t cdb_len,
1356 struct IO_REQUEST_INFO *io_info, union ccb *ccb,
1357 MR_DRV_RAID_MAP_ALL * local_map_ptr, u_int32_t ref_tag,
1358 u_int32_t ld_block_size)
1362 u_int64_t start_blk = io_info->pdBlock;
1363 u_int8_t *cdb = io_request->CDB.CDB32;
1364 u_int32_t num_blocks = io_info->numBlocks;
1365 u_int8_t opcode = 0, flagvals = 0, groupnum = 0, control = 0;
1366 struct ccb_hdr *ccb_h = &(ccb->ccb_h);
1368 /* Check if T10 PI (DIF) is enabled for this LD */
1369 ld = MR_TargetIdToLdGet(io_info->ldTgtId, local_map_ptr);
1370 raid = MR_LdRaidGet(ld, local_map_ptr);
1371 if (raid->capability.ldPiMode == MR_PROT_INFO_TYPE_CONTROLLER) {
1372 memset(cdb, 0, sizeof(io_request->CDB.CDB32));
1373 cdb[0] = MRSAS_SCSI_VARIABLE_LENGTH_CMD;
1374 cdb[7] = MRSAS_SCSI_ADDL_CDB_LEN;
1376 if (ccb_h->flags == CAM_DIR_OUT)
1377 cdb[9] = MRSAS_SCSI_SERVICE_ACTION_READ32;
1379 cdb[9] = MRSAS_SCSI_SERVICE_ACTION_WRITE32;
1380 cdb[10] = MRSAS_RD_WR_PROTECT_CHECK_ALL;
1383 cdb[12] = (u_int8_t)((start_blk >> 56) & 0xff);
1384 cdb[13] = (u_int8_t)((start_blk >> 48) & 0xff);
1385 cdb[14] = (u_int8_t)((start_blk >> 40) & 0xff);
1386 cdb[15] = (u_int8_t)((start_blk >> 32) & 0xff);
1387 cdb[16] = (u_int8_t)((start_blk >> 24) & 0xff);
1388 cdb[17] = (u_int8_t)((start_blk >> 16) & 0xff);
1389 cdb[18] = (u_int8_t)((start_blk >> 8) & 0xff);
1390 cdb[19] = (u_int8_t)(start_blk & 0xff);
1392 /* Logical block reference tag */
1393 io_request->CDB.EEDP32.PrimaryReferenceTag = swap32(ref_tag);
1394 io_request->CDB.EEDP32.PrimaryApplicationTagMask = 0xffff;
1395 io_request->IoFlags = 32; /* Specify 32-byte cdb */
1397 /* Transfer length */
1398 cdb[28] = (u_int8_t)((num_blocks >> 24) & 0xff);
1399 cdb[29] = (u_int8_t)((num_blocks >> 16) & 0xff);
1400 cdb[30] = (u_int8_t)((num_blocks >> 8) & 0xff);
1401 cdb[31] = (u_int8_t)(num_blocks & 0xff);
1403 /* set SCSI IO EEDP Flags */
1404 if (ccb_h->flags == CAM_DIR_OUT) {
1405 io_request->EEDPFlags =
1406 MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
1407 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
1408 MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP |
1409 MPI2_SCSIIO_EEDPFLAGS_CHECK_APPTAG |
1410 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
1412 io_request->EEDPFlags =
1413 MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
1414 MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
1416 io_request->Control |= (0x4 << 26);
1417 io_request->EEDPBlockSize = ld_block_size;
1419 /* Some drives don't support 16/12 byte CDB's, convert to 10 */
1420 if (((cdb_len == 12) || (cdb_len == 16)) &&
1421 (start_blk <= 0xffffffff)) {
1422 if (cdb_len == 16) {
1423 opcode = cdb[0] == READ_16 ? READ_10 : WRITE_10;
1428 opcode = cdb[0] == READ_12 ? READ_10 : WRITE_10;
1434 memset(cdb, 0, sizeof(io_request->CDB.CDB32));
1441 /* Transfer length */
1442 cdb[8] = (u_int8_t)(num_blocks & 0xff);
1443 cdb[7] = (u_int8_t)((num_blocks >> 8) & 0xff);
1445 io_request->IoFlags = 10; /* Specify 10-byte cdb */
1447 } else if ((cdb_len < 16) && (start_blk > 0xffffffff)) {
1448 /* Convert to 16 byte CDB for large LBA's */
1451 opcode = cdb[0] == READ_6 ? READ_16 : WRITE_16;
1455 opcode = cdb[0] == READ_10 ? READ_16 : WRITE_16;
1461 opcode = cdb[0] == READ_12 ? READ_16 : WRITE_16;
1468 memset(cdb, 0, sizeof(io_request->CDB.CDB32));
1475 /* Transfer length */
1476 cdb[13] = (u_int8_t)(num_blocks & 0xff);
1477 cdb[12] = (u_int8_t)((num_blocks >> 8) & 0xff);
1478 cdb[11] = (u_int8_t)((num_blocks >> 16) & 0xff);
1479 cdb[10] = (u_int8_t)((num_blocks >> 24) & 0xff);
1481 io_request->IoFlags = 16; /* Specify 16-byte cdb */
1483 } else if ((cdb_len == 6) && (start_blk > 0x1fffff)) {
1484 /* convert to 10 byte CDB */
1485 opcode = cdb[0] == READ_6 ? READ_10 : WRITE_10;
1488 memset(cdb, 0, sizeof(io_request->CDB.CDB32));
1492 /* Set transfer length */
1493 cdb[8] = (u_int8_t)(num_blocks & 0xff);
1494 cdb[7] = (u_int8_t)((num_blocks >> 8) & 0xff);
1496 /* Specify 10-byte cdb */
1499 /* Fall through normal case, just load LBA here */
1500 u_int8_t val = cdb[1] & 0xE0;
1504 cdb[3] = (u_int8_t)(start_blk & 0xff);
1505 cdb[2] = (u_int8_t)((start_blk >> 8) & 0xff);
1506 cdb[1] = val | ((u_int8_t)(start_blk >> 16) & 0x1f);
1509 cdb[5] = (u_int8_t)(start_blk & 0xff);
1510 cdb[4] = (u_int8_t)((start_blk >> 8) & 0xff);
1511 cdb[3] = (u_int8_t)((start_blk >> 16) & 0xff);
1512 cdb[2] = (u_int8_t)((start_blk >> 24) & 0xff);
1515 cdb[9] = (u_int8_t)(start_blk & 0xff);
1516 cdb[8] = (u_int8_t)((start_blk >> 8) & 0xff);
1517 cdb[7] = (u_int8_t)((start_blk >> 16) & 0xff);
1518 cdb[6] = (u_int8_t)((start_blk >> 24) & 0xff);
1519 cdb[5] = (u_int8_t)((start_blk >> 32) & 0xff);
1520 cdb[4] = (u_int8_t)((start_blk >> 40) & 0xff);
1521 cdb[3] = (u_int8_t)((start_blk >> 48) & 0xff);
1522 cdb[2] = (u_int8_t)((start_blk >> 56) & 0xff);
1529 * mrsas_get_best_arm_pd: Determine the best spindle arm
1532 * lbInfo - Load balance info
1533 * io_info - IO request info
1535 * This function determines and returns the best arm by looking at the
1536 * parameters of the last PD access.
1539 mrsas_get_best_arm_pd(struct mrsas_softc *sc,
1540 PLD_LOAD_BALANCE_INFO lbInfo, struct IO_REQUEST_INFO *io_info)
1543 MR_DRV_RAID_MAP_ALL *drv_map;
1544 u_int16_t pd1_devHandle;
1545 u_int16_t pend0, pend1, ld;
1546 u_int64_t diff0, diff1;
1547 u_int8_t bestArm, pd0, pd1, span, arm;
1548 u_int32_t arRef, span_row_size;
1550 u_int64_t block = io_info->ldStartBlock;
1551 u_int32_t count = io_info->numBlocks;
1553 span = ((io_info->span_arm & RAID_CTX_SPANARM_SPAN_MASK)
1554 >> RAID_CTX_SPANARM_SPAN_SHIFT);
1555 arm = (io_info->span_arm & RAID_CTX_SPANARM_ARM_MASK);
1557 drv_map = sc->ld_drv_map[(sc->map_id & 1)];
1558 ld = MR_TargetIdToLdGet(io_info->ldTgtId, drv_map);
1559 raid = MR_LdRaidGet(ld, drv_map);
1560 span_row_size = sc->UnevenSpanSupport ?
1561 SPAN_ROW_SIZE(drv_map, ld, span) : raid->rowSize;
1563 arRef = MR_LdSpanArrayGet(ld, span, drv_map);
1564 pd0 = MR_ArPdGet(arRef, arm, drv_map);
1565 pd1 = MR_ArPdGet(arRef, (arm + 1) >= span_row_size ?
1566 (arm + 1 - span_row_size) : arm + 1, drv_map);
1568 /* Get PD1 Dev Handle */
1569 pd1_devHandle = MR_PdDevHandleGet(pd1, drv_map);
1570 if (pd1_devHandle == MR_DEVHANDLE_INVALID) {
1573 /* get the pending cmds for the data and mirror arms */
1574 pend0 = mrsas_atomic_read(&lbInfo->scsi_pending_cmds[pd0]);
1575 pend1 = mrsas_atomic_read(&lbInfo->scsi_pending_cmds[pd1]);
1577 /* Determine the disk whose head is nearer to the req. block */
1578 diff0 = ABS_DIFF(block, lbInfo->last_accessed_block[pd0]);
1579 diff1 = ABS_DIFF(block, lbInfo->last_accessed_block[pd1]);
1580 bestArm = (diff0 <= diff1 ? arm : arm ^ 1);
1582 if ((bestArm == arm && pend0 > pend1 + sc->lb_pending_cmds) ||
1583 (bestArm != arm && pend1 > pend0 + sc->lb_pending_cmds))
1586 /* Update the last accessed block on the correct pd */
1587 io_info->span_arm = (span << RAID_CTX_SPANARM_SPAN_SHIFT) | bestArm;
1588 io_info->pd_after_lb = (bestArm == arm) ? pd0 : pd1;
1591 lbInfo->last_accessed_block[bestArm == arm ? pd0 : pd1] = block + count - 1;
1594 printf("AVAGO Debug R1 Load balance occur - span 0x%x arm 0x%x bestArm 0x%x "
1595 "io_info->span_arm 0x%x\n",
1596 span, arm, bestArm, io_info->span_arm);
1599 return io_info->pd_after_lb;
1603 * mrsas_get_updated_dev_handle: Get the update dev handle
1605 * sc - Adapter instance soft state
1606 * lbInfo - Load balance info
1607 * io_info - io_info pointer
1609 * This function determines and returns the updated dev handle.
1612 mrsas_get_updated_dev_handle(struct mrsas_softc *sc,
1613 PLD_LOAD_BALANCE_INFO lbInfo, struct IO_REQUEST_INFO *io_info)
1616 u_int16_t devHandle;
1617 MR_DRV_RAID_MAP_ALL *drv_map;
1619 drv_map = sc->ld_drv_map[(sc->map_id & 1)];
1621 /* get best new arm */
1622 arm_pd = mrsas_get_best_arm_pd(sc, lbInfo, io_info);
1623 devHandle = MR_PdDevHandleGet(arm_pd, drv_map);
1624 io_info->pdInterface = MR_PdInterfaceTypeGet(arm_pd, drv_map);
1625 mrsas_atomic_inc(&lbInfo->scsi_pending_cmds[arm_pd]);
1631 * MR_GetPhyParams: Calculates arm, span, and block
1632 * Inputs: Adapter soft state
1633 * Logical drive number (LD)
1634 * Stripe number(stripRow)
1635 * Reference in stripe (stripRef)
1637 * Outputs: Absolute Block number in the physical disk
1639 * This routine calculates the arm, span and block for the specified stripe and
1640 * reference in stripe.
1643 MR_GetPhyParams(struct mrsas_softc *sc, u_int32_t ld,
1645 u_int16_t stripRef, struct IO_REQUEST_INFO *io_info,
1646 RAID_CONTEXT * pRAID_Context, MR_DRV_RAID_MAP_ALL * map)
1648 MR_LD_RAID *raid = MR_LdRaidGet(ld, map);
1649 u_int32_t pd, arRef, r1_alt_pd;
1650 u_int8_t physArm, span;
1652 u_int8_t retval = TRUE;
1654 u_int64_t *pdBlock = &io_info->pdBlock;
1655 u_int16_t *pDevHandle = &io_info->devHandle;
1656 u_int8_t *pPdInterface = &io_info->pdInterface;
1657 u_int32_t rowMod, armQ, arm, logArm;
1659 row = mega_div64_32(stripRow, raid->rowDataSize);
1661 if (raid->level == 6) {
1662 /* logical arm within row */
1663 logArm = mega_mod64(stripRow, raid->rowDataSize);
1664 if (raid->rowSize == 0)
1666 rowMod = mega_mod64(row, raid->rowSize); /* get logical row mod */
1667 armQ = raid->rowSize - 1 - rowMod; /* index of Q drive */
1668 arm = armQ + 1 + logArm;/* data always logically follows Q */
1669 if (arm >= raid->rowSize) /* handle wrap condition */
1670 arm -= raid->rowSize;
1671 physArm = (u_int8_t)arm;
1673 if (raid->modFactor == 0)
1675 physArm = MR_LdDataArmGet(ld, mega_mod64(stripRow, raid->modFactor), map);
1678 if (raid->spanDepth == 1) {
1680 *pdBlock = row << raid->stripeShift;
1682 span = (u_int8_t)MR_GetSpanBlock(ld, row, pdBlock, map, &error_code);
1683 if (error_code == 1)
1687 /* Get the array on which this span is present */
1688 arRef = MR_LdSpanArrayGet(ld, span, map);
1690 pd = MR_ArPdGet(arRef, physArm, map); /* Get the Pd. */
1692 if (pd != MR_PD_INVALID) {
1693 /* Get dev handle from Pd */
1694 *pDevHandle = MR_PdDevHandleGet(pd, map);
1695 *pPdInterface = MR_PdInterfaceTypeGet(pd, map);
1696 /* get second pd also for raid 1/10 fast path writes */
1697 if ((raid->level == 1) && !io_info->isRead) {
1698 r1_alt_pd = MR_ArPdGet(arRef, physArm + 1, map);
1699 if (r1_alt_pd != MR_PD_INVALID)
1700 io_info->r1_alt_dev_handle = MR_PdDevHandleGet(r1_alt_pd, map);
1703 *pDevHandle = MR_DEVHANDLE_INVALID; /* set dev handle as invalid. */
1704 if ((raid->level >= 5) && ((sc->device_id == MRSAS_TBOLT) ||
1705 (sc->mrsas_gen3_ctrl &&
1706 raid->regTypeReqOnRead != REGION_TYPE_UNUSED)))
1707 pRAID_Context->regLockFlags = REGION_TYPE_EXCLUSIVE;
1708 else if (raid->level == 1) {
1709 /* Get Alternate Pd. */
1710 pd = MR_ArPdGet(arRef, physArm + 1, map);
1711 if (pd != MR_PD_INVALID) {
1712 /* Get dev handle from Pd. */
1713 *pDevHandle = MR_PdDevHandleGet(pd, map);
1714 *pPdInterface = MR_PdInterfaceTypeGet(pd, map);
1719 *pdBlock += stripRef + MR_LdSpanPtrGet(ld, span, map)->startBlk;
1720 if (sc->is_ventura || sc->is_aero) {
1721 ((RAID_CONTEXT_G35 *) pRAID_Context)->spanArm =
1722 (span << RAID_CTX_SPANARM_SPAN_SHIFT) | physArm;
1723 io_info->span_arm = (span << RAID_CTX_SPANARM_SPAN_SHIFT) | physArm;
1725 pRAID_Context->spanArm = (span << RAID_CTX_SPANARM_SPAN_SHIFT) | physArm;
1726 io_info->span_arm = pRAID_Context->spanArm;
1732 * MR_GetSpanBlock: Calculates span block
1738 * Outputs: Span number Error code
1740 * This routine calculates the span from the span block info.
1743 MR_GetSpanBlock(u_int32_t ld, u_int64_t row, u_int64_t *span_blk,
1744 MR_DRV_RAID_MAP_ALL * map, int *div_error)
1746 MR_SPAN_BLOCK_INFO *pSpanBlock = MR_LdSpanInfoGet(ld, map);
1747 MR_QUAD_ELEMENT *quad;
1748 MR_LD_RAID *raid = MR_LdRaidGet(ld, map);
1750 u_int64_t blk, debugBlk;
1752 for (span = 0; span < raid->spanDepth; span++, pSpanBlock++) {
1753 for (j = 0; j < pSpanBlock->block_span_info.noElements; j++) {
1754 quad = &pSpanBlock->block_span_info.quad[j];
1755 if (quad->diff == 0) {
1759 if (quad->logStart <= row && row <= quad->logEnd &&
1760 (mega_mod64(row - quad->logStart, quad->diff)) == 0) {
1761 if (span_blk != NULL) {
1762 blk = mega_div64_32((row - quad->logStart), quad->diff);
1764 blk = (blk + quad->offsetInSpan) << raid->stripeShift;