11 * Author:
12 * Swaminathan K S
13 * Arun Chandrashekhar
14 * Manju R
15 * Rasheed
16 * Shakeel Bukhari
17 *
18 *
19 * This module contains functions for device drivers
20 * to get pd-ld mapping information.
21 *
22 * **********************************************************************
23 */
24
25 #include <sys/scsi/scsi.h>
26 #include "mr_sas.h"
27 #include "ld_pd_map.h"
28
29 /*
30 * This function will check if FAST IO is possible on this logical drive
31 * by checking the EVENT information availabe in the driver
32 */
33 #define MR_LD_STATE_OPTIMAL 3
34 #define ABS_DIFF(a, b) (((a) > (b)) ? ((a) - (b)) : ((b) - (a)))
35
36 static void mr_update_load_balance_params(MR_FW_RAID_MAP_ALL *,
37 PLD_LOAD_BALANCE_INFO);
38
39 #define FALSE 0
40 #define TRUE 1
41
42 typedef U64 REGION_KEY;
43 typedef U32 REGION_LEN;
44 extern int debug_level_g;
45
46
47 MR_LD_RAID
48 *MR_LdRaidGet(U32 ld, MR_FW_RAID_MAP_ALL *map)
49 {
50 return (&map->raidMap.ldSpanMap[ld].ldRaid);
51 }
193 * Outputs :
194 *
195 * span - Span number
196 * block - Absolute Block number in the physical disk
197 */
198 U8
199 MR_GetPhyParams(struct mrsas_instance *instance, U32 ld, U64 stripRow,
200 U16 stripRef, U64 *pdBlock, U16 *pDevHandle,
201 MPI2_SCSI_IO_VENDOR_UNIQUE *pRAID_Context, MR_FW_RAID_MAP_ALL *map)
202 {
203 MR_LD_RAID *raid = MR_LdRaidGet(ld, map);
204 U32 pd, arRef;
205 U8 physArm, span;
206 U64 row;
207 int error_code = 0;
208 U8 retval = TRUE;
209 U32 rowMod;
210 U32 armQ;
211 U32 arm;
212
213 row = (stripRow / raid->rowDataSize);
214
215 if (raid->level == 6) {
216 U32 logArm = (stripRow % (raid->rowDataSize));
217
218 if (raid->rowSize == 0) {
219 return (FALSE);
220 }
221 rowMod = (row % (raid->rowSize));
222 armQ = raid->rowSize-1-rowMod;
223 arm = armQ+1+logArm;
224 if (arm >= raid->rowSize)
225 arm -= raid->rowSize;
226 physArm = (U8)arm;
227 } else {
228 if (raid->modFactor == 0)
229 return (FALSE);
230 physArm = MR_LdDataArmGet(ld,
231 (stripRow % (raid->modFactor)), map);
232 }
233 if (raid->spanDepth == 1) {
234 span = 0;
235 *pdBlock = row << raid->stripeShift;
236 } else
237 span = (U8)MR_GetSpanBlock(ld, row, pdBlock, map, &error_code);
238
239 if (error_code == 1)
240 return (FALSE);
241
242 /* Get the array on which this span is present. */
243 arRef = MR_LdSpanArrayGet(ld, span, map);
316 ld = MR_TargetIdToLdGet(ldTgtId, map);
317
318 if (ld >= MAX_LOGICAL_DRIVES) {
319 io_info->fpOkForIo = FALSE;
320 return (FALSE);
321 }
322
323 raid = MR_LdRaidGet(ld, map);
324
325 stripSize = 1 << raid->stripeShift;
326 stripe_mask = stripSize-1;
327 /*
328 * calculate starting row and stripe, and number of strips and rows
329 */
330 start_strip = ldStartBlock >> raid->stripeShift;
331 ref_in_start_stripe = (U16)(ldStartBlock & stripe_mask);
332 endLba = ldStartBlock + numBlocks - 1;
333 ref_in_end_stripe = (U16)(endLba & stripe_mask);
334 endStrip = endLba >> raid->stripeShift;
335 num_strips = (U8)(endStrip - start_strip + 1);
336 /* Check to make sure is not deviding by zero */
337 if (raid->rowDataSize == 0)
338 return (FALSE);
339 start_row = (start_strip / raid->rowDataSize);
340 endRow = (endStrip / raid->rowDataSize);
341 /* get the row count */
342 numRows = (U8)(endRow - start_row + 1);
343
344 /*
345 * calculate region info.
346 */
347 regStart = start_row << raid->stripeShift;
348 regSize = stripSize;
349
350 /* Check if we can send this I/O via FastPath */
351 if (raid->capability.fpCapable) {
352 if (isRead)
353 io_info->fpOkForIo = (raid->capability.fpReadCapable &&
354 ((num_strips == 1) ||
355 raid->capability.fpReadAcrossStripe));
356 else
357 io_info->fpOkForIo =
358 (raid->capability.fpWriteCapable &&
359 ((num_strips == 1) ||
360 raid->capability.fpWriteAcrossStripe));
361 } else
362 io_info->fpOkForIo = FALSE;
363
364
365 /*
366 * Check for DIF support
367 */
368 if (!raid->capability.ldPiMode) {
369 io_info->ldPI = FALSE;
370 } else {
371 io_info->ldPI = TRUE;
372 }
373
374 if (numRows == 1) {
375 if (num_strips == 1) {
376 regStart += ref_in_start_stripe;
377 regSize = numBlocks;
378 }
379 } else {
380 if (start_strip == (start_row + 1) * raid->rowDataSize - 1) {
381 regStart += ref_in_start_stripe;
382 regSize = stripSize - ref_in_start_stripe;
383 }
384
385 if (numRows > 2) {
386 regSize += (numRows-2) << raid->stripeShift;
387 }
388
389 if (endStrip == endRow*raid->rowDataSize) {
390 regSize += ref_in_end_stripe+1;
391 } else {
392 regSize += stripSize;
393 }
394 }
395
396 pRAID_Context->timeoutValue = map->raidMap.fpPdIoTimeoutSec;
397
398 if (instance->device_id == PCI_DEVICE_ID_LSI_INVADER) {
399 pRAID_Context->regLockFlags = (isRead) ?
400 raid->regTypeReqOnRead : raid->regTypeReqOnWrite;
401 } else {
402 pRAID_Context->regLockFlags = (isRead) ?
403 REGION_TYPE_SHARED_READ : raid->regTypeReqOnWrite;
404 }
405
406 pRAID_Context->ldTargetId = raid->targetId;
407 pRAID_Context->regLockRowLBA = regStart;
408 pRAID_Context->regLockLength = regSize;
409 pRAID_Context->configSeqNum = raid->seqNum;
410
|
11 * Author:
12 * Swaminathan K S
13 * Arun Chandrashekhar
14 * Manju R
15 * Rasheed
16 * Shakeel Bukhari
17 *
18 *
19 * This module contains functions for device drivers
20 * to get pd-ld mapping information.
21 *
22 * **********************************************************************
23 */
24
25 #include <sys/scsi/scsi.h>
26 #include "mr_sas.h"
27 #include "ld_pd_map.h"
28
29 /*
30 * This function will check if FAST IO is possible on this logical drive
31 * by checking the EVENT information available in the driver
32 */
33 #define MR_LD_STATE_OPTIMAL 3
34 #define ABS_DIFF(a, b) (((a) > (b)) ? ((a) - (b)) : ((b) - (a)))
35
36 static void mr_update_load_balance_params(MR_FW_RAID_MAP_ALL *,
37 PLD_LOAD_BALANCE_INFO);
38
39 #define FALSE 0
40 #define TRUE 1
41
42 typedef U64 REGION_KEY;
43 typedef U32 REGION_LEN;
44 extern int debug_level_g;
45
46
47 MR_LD_RAID
48 *MR_LdRaidGet(U32 ld, MR_FW_RAID_MAP_ALL *map)
49 {
50 return (&map->raidMap.ldSpanMap[ld].ldRaid);
51 }
193 * Outputs :
194 *
195 * span - Span number
196 * block - Absolute Block number in the physical disk
197 */
198 U8
199 MR_GetPhyParams(struct mrsas_instance *instance, U32 ld, U64 stripRow,
200 U16 stripRef, U64 *pdBlock, U16 *pDevHandle,
201 MPI2_SCSI_IO_VENDOR_UNIQUE *pRAID_Context, MR_FW_RAID_MAP_ALL *map)
202 {
203 MR_LD_RAID *raid = MR_LdRaidGet(ld, map);
204 U32 pd, arRef;
205 U8 physArm, span;
206 U64 row;
207 int error_code = 0;
208 U8 retval = TRUE;
209 U32 rowMod;
210 U32 armQ;
211 U32 arm;
212
213 ASSERT(raid->rowDataSize != 0);
214
215 row = (stripRow / raid->rowDataSize);
216
217 if (raid->level == 6) {
218 U32 logArm = (stripRow % (raid->rowDataSize));
219
220 if (raid->rowSize == 0) {
221 return (FALSE);
222 }
223 rowMod = (row % (raid->rowSize));
224 armQ = raid->rowSize-1-rowMod;
225 arm = armQ + 1 + logArm;
226 if (arm >= raid->rowSize)
227 arm -= raid->rowSize;
228 physArm = (U8)arm;
229 } else {
230 if (raid->modFactor == 0)
231 return (FALSE);
232 physArm = MR_LdDataArmGet(ld,
233 (stripRow % (raid->modFactor)), map);
234 }
235 if (raid->spanDepth == 1) {
236 span = 0;
237 *pdBlock = row << raid->stripeShift;
238 } else
239 span = (U8)MR_GetSpanBlock(ld, row, pdBlock, map, &error_code);
240
241 if (error_code == 1)
242 return (FALSE);
243
244 /* Get the array on which this span is present. */
245 arRef = MR_LdSpanArrayGet(ld, span, map);
318 ld = MR_TargetIdToLdGet(ldTgtId, map);
319
320 if (ld >= MAX_LOGICAL_DRIVES) {
321 io_info->fpOkForIo = FALSE;
322 return (FALSE);
323 }
324
325 raid = MR_LdRaidGet(ld, map);
326
327 stripSize = 1 << raid->stripeShift;
328 stripe_mask = stripSize-1;
329 /*
330 * calculate starting row and stripe, and number of strips and rows
331 */
332 start_strip = ldStartBlock >> raid->stripeShift;
333 ref_in_start_stripe = (U16)(ldStartBlock & stripe_mask);
334 endLba = ldStartBlock + numBlocks - 1;
335 ref_in_end_stripe = (U16)(endLba & stripe_mask);
336 endStrip = endLba >> raid->stripeShift;
337 num_strips = (U8)(endStrip - start_strip + 1);
338 /* Check to make sure is not dividing by zero */
339 if (raid->rowDataSize == 0)
340 return (FALSE);
341 start_row = (start_strip / raid->rowDataSize);
342 endRow = (endStrip / raid->rowDataSize);
343 /* get the row count */
344 numRows = (U8)(endRow - start_row + 1);
345
346 /*
347 * calculate region info.
348 */
349 regStart = start_row << raid->stripeShift;
350 regSize = stripSize;
351
352 /* Check if we can send this I/O via FastPath */
353 if (raid->capability.fpCapable) {
354 if (isRead) {
355 io_info->fpOkForIo = (raid->capability.fpReadCapable &&
356 ((num_strips == 1) ||
357 raid->capability.fpReadAcrossStripe));
358 } else {
359 io_info->fpOkForIo =
360 (raid->capability.fpWriteCapable &&
361 ((num_strips == 1) ||
362 raid->capability.fpWriteAcrossStripe));
363 }
364 } else
365 io_info->fpOkForIo = FALSE;
366
367
368 /*
369 * Check for DIF support
370 */
371 if (!raid->capability.ldPiMode) {
372 io_info->ldPI = FALSE;
373 } else {
374 io_info->ldPI = TRUE;
375 }
376
377 if (numRows == 1) {
378 if (num_strips == 1) {
379 regStart += ref_in_start_stripe;
380 regSize = numBlocks;
381 }
382 } else {
383 if (start_strip == (start_row + 1) * raid->rowDataSize - 1) {
384 regStart += ref_in_start_stripe;
385 regSize = stripSize - ref_in_start_stripe;
386 }
387
388 if (numRows > 2) {
389 regSize += (numRows - 2) << raid->stripeShift;
390 }
391
392 if (endStrip == endRow * raid->rowDataSize) {
393 regSize += ref_in_end_stripe + 1;
394 } else {
395 regSize += stripSize;
396 }
397 }
398
399 pRAID_Context->timeoutValue = map->raidMap.fpPdIoTimeoutSec;
400
401 if (instance->device_id == PCI_DEVICE_ID_LSI_INVADER) {
402 pRAID_Context->regLockFlags = (isRead) ?
403 raid->regTypeReqOnRead : raid->regTypeReqOnWrite;
404 } else {
405 pRAID_Context->regLockFlags = (isRead) ?
406 REGION_TYPE_SHARED_READ : raid->regTypeReqOnWrite;
407 }
408
409 pRAID_Context->ldTargetId = raid->targetId;
410 pRAID_Context->regLockRowLBA = regStart;
411 pRAID_Context->regLockLength = regSize;
412 pRAID_Context->configSeqNum = raid->seqNum;
413
|