Commit c1529fa25e20f4c5d92d82165a8ff5fe27eae974
Committed by
James Bottomley
1 parent
5738f99643
Exists in
smarc-l5.0.0_1.0.0-ga
and in
5 other branches
[SCSI] megaraid_sas: Add fpRead/WriteCapable, fpRead/WriteAcrossStripe checks
The following patch for megaraid_sas fixes the fastpath code decision logic to use fpRead/WriteCapable, fpRead/WriteAcrossStripe flags instead of the old logic. This fixes a bug where fastpath writes could be sent to a read only LD. Signed-off-by: Adam Radford <aradford@gmail.com> Signed-off-by: James Bottomley <JBottomley@Parallels.com>
Showing 1 changed file with 13 additions and 8 deletions Inline Diff
drivers/scsi/megaraid/megaraid_sas_fp.c
1 | /* | 1 | /* |
2 | * Linux MegaRAID driver for SAS based RAID controllers | 2 | * Linux MegaRAID driver for SAS based RAID controllers |
3 | * | 3 | * |
4 | * Copyright (c) 2009-2011 LSI Corporation. | 4 | * Copyright (c) 2009-2011 LSI Corporation. |
5 | * | 5 | * |
6 | * This program is free software; you can redistribute it and/or | 6 | * This program is free software; you can redistribute it and/or |
7 | * modify it under the terms of the GNU General Public License | 7 | * modify it under the terms of the GNU General Public License |
8 | * as published by the Free Software Foundation; either version 2 | 8 | * as published by the Free Software Foundation; either version 2 |
9 | * of the License, or (at your option) any later version. | 9 | * of the License, or (at your option) any later version. |
10 | * | 10 | * |
11 | * This program is distributed in the hope that it will be useful, | 11 | * This program is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU General Public License for more details. | 14 | * GNU General Public License for more details. |
15 | * | 15 | * |
16 | * You should have received a copy of the GNU General Public License | 16 | * You should have received a copy of the GNU General Public License |
17 | * along with this program; if not, write to the Free Software | 17 | * along with this program; if not, write to the Free Software |
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 | * | 19 | * |
20 | * FILE: megaraid_sas_fp.c | 20 | * FILE: megaraid_sas_fp.c |
21 | * | 21 | * |
22 | * Authors: LSI Corporation | 22 | * Authors: LSI Corporation |
23 | * Sumant Patro | 23 | * Sumant Patro |
24 | * Varad Talamacki | 24 | * Varad Talamacki |
25 | * Manoj Jose | 25 | * Manoj Jose |
26 | * | 26 | * |
27 | * Send feedback to: <megaraidlinux@lsi.com> | 27 | * Send feedback to: <megaraidlinux@lsi.com> |
28 | * | 28 | * |
29 | * Mail to: LSI Corporation, 1621 Barber Lane, Milpitas, CA 95035 | 29 | * Mail to: LSI Corporation, 1621 Barber Lane, Milpitas, CA 95035 |
30 | * ATTN: Linuxraid | 30 | * ATTN: Linuxraid |
31 | */ | 31 | */ |
32 | 32 | ||
33 | #include <linux/kernel.h> | 33 | #include <linux/kernel.h> |
34 | #include <linux/types.h> | 34 | #include <linux/types.h> |
35 | #include <linux/pci.h> | 35 | #include <linux/pci.h> |
36 | #include <linux/list.h> | 36 | #include <linux/list.h> |
37 | #include <linux/moduleparam.h> | 37 | #include <linux/moduleparam.h> |
38 | #include <linux/module.h> | 38 | #include <linux/module.h> |
39 | #include <linux/spinlock.h> | 39 | #include <linux/spinlock.h> |
40 | #include <linux/interrupt.h> | 40 | #include <linux/interrupt.h> |
41 | #include <linux/delay.h> | 41 | #include <linux/delay.h> |
42 | #include <linux/uio.h> | 42 | #include <linux/uio.h> |
43 | #include <linux/uaccess.h> | 43 | #include <linux/uaccess.h> |
44 | #include <linux/fs.h> | 44 | #include <linux/fs.h> |
45 | #include <linux/compat.h> | 45 | #include <linux/compat.h> |
46 | #include <linux/blkdev.h> | 46 | #include <linux/blkdev.h> |
47 | #include <linux/poll.h> | 47 | #include <linux/poll.h> |
48 | 48 | ||
49 | #include <scsi/scsi.h> | 49 | #include <scsi/scsi.h> |
50 | #include <scsi/scsi_cmnd.h> | 50 | #include <scsi/scsi_cmnd.h> |
51 | #include <scsi/scsi_device.h> | 51 | #include <scsi/scsi_device.h> |
52 | #include <scsi/scsi_host.h> | 52 | #include <scsi/scsi_host.h> |
53 | 53 | ||
54 | #include "megaraid_sas_fusion.h" | 54 | #include "megaraid_sas_fusion.h" |
55 | #include "megaraid_sas.h" | 55 | #include "megaraid_sas.h" |
56 | #include <asm/div64.h> | 56 | #include <asm/div64.h> |
57 | 57 | ||
58 | #define ABS_DIFF(a, b) (((a) > (b)) ? ((a) - (b)) : ((b) - (a))) | 58 | #define ABS_DIFF(a, b) (((a) > (b)) ? ((a) - (b)) : ((b) - (a))) |
59 | #define MR_LD_STATE_OPTIMAL 3 | 59 | #define MR_LD_STATE_OPTIMAL 3 |
60 | #define FALSE 0 | 60 | #define FALSE 0 |
61 | #define TRUE 1 | 61 | #define TRUE 1 |
62 | 62 | ||
63 | /* Prototypes */ | 63 | /* Prototypes */ |
64 | void | 64 | void |
65 | mr_update_load_balance_params(struct MR_FW_RAID_MAP_ALL *map, | 65 | mr_update_load_balance_params(struct MR_FW_RAID_MAP_ALL *map, |
66 | struct LD_LOAD_BALANCE_INFO *lbInfo); | 66 | struct LD_LOAD_BALANCE_INFO *lbInfo); |
67 | 67 | ||
68 | u32 mega_mod64(u64 dividend, u32 divisor) | 68 | u32 mega_mod64(u64 dividend, u32 divisor) |
69 | { | 69 | { |
70 | u64 d; | 70 | u64 d; |
71 | u32 remainder; | 71 | u32 remainder; |
72 | 72 | ||
73 | if (!divisor) | 73 | if (!divisor) |
74 | printk(KERN_ERR "megasas : DIVISOR is zero, in div fn\n"); | 74 | printk(KERN_ERR "megasas : DIVISOR is zero, in div fn\n"); |
75 | d = dividend; | 75 | d = dividend; |
76 | remainder = do_div(d, divisor); | 76 | remainder = do_div(d, divisor); |
77 | return remainder; | 77 | return remainder; |
78 | } | 78 | } |
79 | 79 | ||
80 | /** | 80 | /** |
81 | * @param dividend : Dividend | 81 | * @param dividend : Dividend |
82 | * @param divisor : Divisor | 82 | * @param divisor : Divisor |
83 | * | 83 | * |
84 | * @return quotient | 84 | * @return quotient |
85 | **/ | 85 | **/ |
86 | u64 mega_div64_32(uint64_t dividend, uint32_t divisor) | 86 | u64 mega_div64_32(uint64_t dividend, uint32_t divisor) |
87 | { | 87 | { |
88 | u32 remainder; | 88 | u32 remainder; |
89 | u64 d; | 89 | u64 d; |
90 | 90 | ||
91 | if (!divisor) | 91 | if (!divisor) |
92 | printk(KERN_ERR "megasas : DIVISOR is zero in mod fn\n"); | 92 | printk(KERN_ERR "megasas : DIVISOR is zero in mod fn\n"); |
93 | 93 | ||
94 | d = dividend; | 94 | d = dividend; |
95 | remainder = do_div(d, divisor); | 95 | remainder = do_div(d, divisor); |
96 | 96 | ||
97 | return d; | 97 | return d; |
98 | } | 98 | } |
99 | 99 | ||
100 | struct MR_LD_RAID *MR_LdRaidGet(u32 ld, struct MR_FW_RAID_MAP_ALL *map) | 100 | struct MR_LD_RAID *MR_LdRaidGet(u32 ld, struct MR_FW_RAID_MAP_ALL *map) |
101 | { | 101 | { |
102 | return &map->raidMap.ldSpanMap[ld].ldRaid; | 102 | return &map->raidMap.ldSpanMap[ld].ldRaid; |
103 | } | 103 | } |
104 | 104 | ||
105 | static struct MR_SPAN_BLOCK_INFO *MR_LdSpanInfoGet(u32 ld, | 105 | static struct MR_SPAN_BLOCK_INFO *MR_LdSpanInfoGet(u32 ld, |
106 | struct MR_FW_RAID_MAP_ALL | 106 | struct MR_FW_RAID_MAP_ALL |
107 | *map) | 107 | *map) |
108 | { | 108 | { |
109 | return &map->raidMap.ldSpanMap[ld].spanBlock[0]; | 109 | return &map->raidMap.ldSpanMap[ld].spanBlock[0]; |
110 | } | 110 | } |
111 | 111 | ||
112 | static u8 MR_LdDataArmGet(u32 ld, u32 armIdx, struct MR_FW_RAID_MAP_ALL *map) | 112 | static u8 MR_LdDataArmGet(u32 ld, u32 armIdx, struct MR_FW_RAID_MAP_ALL *map) |
113 | { | 113 | { |
114 | return map->raidMap.ldSpanMap[ld].dataArmMap[armIdx]; | 114 | return map->raidMap.ldSpanMap[ld].dataArmMap[armIdx]; |
115 | } | 115 | } |
116 | 116 | ||
117 | static u16 MR_ArPdGet(u32 ar, u32 arm, struct MR_FW_RAID_MAP_ALL *map) | 117 | static u16 MR_ArPdGet(u32 ar, u32 arm, struct MR_FW_RAID_MAP_ALL *map) |
118 | { | 118 | { |
119 | return map->raidMap.arMapInfo[ar].pd[arm]; | 119 | return map->raidMap.arMapInfo[ar].pd[arm]; |
120 | } | 120 | } |
121 | 121 | ||
122 | static u16 MR_LdSpanArrayGet(u32 ld, u32 span, struct MR_FW_RAID_MAP_ALL *map) | 122 | static u16 MR_LdSpanArrayGet(u32 ld, u32 span, struct MR_FW_RAID_MAP_ALL *map) |
123 | { | 123 | { |
124 | return map->raidMap.ldSpanMap[ld].spanBlock[span].span.arrayRef; | 124 | return map->raidMap.ldSpanMap[ld].spanBlock[span].span.arrayRef; |
125 | } | 125 | } |
126 | 126 | ||
127 | static u16 MR_PdDevHandleGet(u32 pd, struct MR_FW_RAID_MAP_ALL *map) | 127 | static u16 MR_PdDevHandleGet(u32 pd, struct MR_FW_RAID_MAP_ALL *map) |
128 | { | 128 | { |
129 | return map->raidMap.devHndlInfo[pd].curDevHdl; | 129 | return map->raidMap.devHndlInfo[pd].curDevHdl; |
130 | } | 130 | } |
131 | 131 | ||
132 | u16 MR_GetLDTgtId(u32 ld, struct MR_FW_RAID_MAP_ALL *map) | 132 | u16 MR_GetLDTgtId(u32 ld, struct MR_FW_RAID_MAP_ALL *map) |
133 | { | 133 | { |
134 | return map->raidMap.ldSpanMap[ld].ldRaid.targetId; | 134 | return map->raidMap.ldSpanMap[ld].ldRaid.targetId; |
135 | } | 135 | } |
136 | 136 | ||
137 | u16 MR_TargetIdToLdGet(u32 ldTgtId, struct MR_FW_RAID_MAP_ALL *map) | 137 | u16 MR_TargetIdToLdGet(u32 ldTgtId, struct MR_FW_RAID_MAP_ALL *map) |
138 | { | 138 | { |
139 | return map->raidMap.ldTgtIdToLd[ldTgtId]; | 139 | return map->raidMap.ldTgtIdToLd[ldTgtId]; |
140 | } | 140 | } |
141 | 141 | ||
142 | static struct MR_LD_SPAN *MR_LdSpanPtrGet(u32 ld, u32 span, | 142 | static struct MR_LD_SPAN *MR_LdSpanPtrGet(u32 ld, u32 span, |
143 | struct MR_FW_RAID_MAP_ALL *map) | 143 | struct MR_FW_RAID_MAP_ALL *map) |
144 | { | 144 | { |
145 | return &map->raidMap.ldSpanMap[ld].spanBlock[span].span; | 145 | return &map->raidMap.ldSpanMap[ld].spanBlock[span].span; |
146 | } | 146 | } |
147 | 147 | ||
148 | /* | 148 | /* |
149 | * This function will validate Map info data provided by FW | 149 | * This function will validate Map info data provided by FW |
150 | */ | 150 | */ |
151 | u8 MR_ValidateMapInfo(struct MR_FW_RAID_MAP_ALL *map, | 151 | u8 MR_ValidateMapInfo(struct MR_FW_RAID_MAP_ALL *map, |
152 | struct LD_LOAD_BALANCE_INFO *lbInfo) | 152 | struct LD_LOAD_BALANCE_INFO *lbInfo) |
153 | { | 153 | { |
154 | struct MR_FW_RAID_MAP *pFwRaidMap = &map->raidMap; | 154 | struct MR_FW_RAID_MAP *pFwRaidMap = &map->raidMap; |
155 | 155 | ||
156 | if (pFwRaidMap->totalSize != | 156 | if (pFwRaidMap->totalSize != |
157 | (sizeof(struct MR_FW_RAID_MAP) -sizeof(struct MR_LD_SPAN_MAP) + | 157 | (sizeof(struct MR_FW_RAID_MAP) -sizeof(struct MR_LD_SPAN_MAP) + |
158 | (sizeof(struct MR_LD_SPAN_MAP) *pFwRaidMap->ldCount))) { | 158 | (sizeof(struct MR_LD_SPAN_MAP) *pFwRaidMap->ldCount))) { |
159 | printk(KERN_ERR "megasas: map info structure size 0x%x is not matching with ld count\n", | 159 | printk(KERN_ERR "megasas: map info structure size 0x%x is not matching with ld count\n", |
160 | (unsigned int)((sizeof(struct MR_FW_RAID_MAP) - | 160 | (unsigned int)((sizeof(struct MR_FW_RAID_MAP) - |
161 | sizeof(struct MR_LD_SPAN_MAP)) + | 161 | sizeof(struct MR_LD_SPAN_MAP)) + |
162 | (sizeof(struct MR_LD_SPAN_MAP) * | 162 | (sizeof(struct MR_LD_SPAN_MAP) * |
163 | pFwRaidMap->ldCount))); | 163 | pFwRaidMap->ldCount))); |
164 | printk(KERN_ERR "megasas: span map %x, pFwRaidMap->totalSize " | 164 | printk(KERN_ERR "megasas: span map %x, pFwRaidMap->totalSize " |
165 | ": %x\n", (unsigned int)sizeof(struct MR_LD_SPAN_MAP), | 165 | ": %x\n", (unsigned int)sizeof(struct MR_LD_SPAN_MAP), |
166 | pFwRaidMap->totalSize); | 166 | pFwRaidMap->totalSize); |
167 | return 0; | 167 | return 0; |
168 | } | 168 | } |
169 | 169 | ||
170 | mr_update_load_balance_params(map, lbInfo); | 170 | mr_update_load_balance_params(map, lbInfo); |
171 | 171 | ||
172 | return 1; | 172 | return 1; |
173 | } | 173 | } |
174 | 174 | ||
175 | u32 MR_GetSpanBlock(u32 ld, u64 row, u64 *span_blk, | 175 | u32 MR_GetSpanBlock(u32 ld, u64 row, u64 *span_blk, |
176 | struct MR_FW_RAID_MAP_ALL *map, int *div_error) | 176 | struct MR_FW_RAID_MAP_ALL *map, int *div_error) |
177 | { | 177 | { |
178 | struct MR_SPAN_BLOCK_INFO *pSpanBlock = MR_LdSpanInfoGet(ld, map); | 178 | struct MR_SPAN_BLOCK_INFO *pSpanBlock = MR_LdSpanInfoGet(ld, map); |
179 | struct MR_QUAD_ELEMENT *quad; | 179 | struct MR_QUAD_ELEMENT *quad; |
180 | struct MR_LD_RAID *raid = MR_LdRaidGet(ld, map); | 180 | struct MR_LD_RAID *raid = MR_LdRaidGet(ld, map); |
181 | u32 span, j; | 181 | u32 span, j; |
182 | 182 | ||
183 | for (span = 0; span < raid->spanDepth; span++, pSpanBlock++) { | 183 | for (span = 0; span < raid->spanDepth; span++, pSpanBlock++) { |
184 | 184 | ||
185 | for (j = 0; j < pSpanBlock->block_span_info.noElements; j++) { | 185 | for (j = 0; j < pSpanBlock->block_span_info.noElements; j++) { |
186 | quad = &pSpanBlock->block_span_info.quad[j]; | 186 | quad = &pSpanBlock->block_span_info.quad[j]; |
187 | 187 | ||
188 | if (quad->diff == 0) { | 188 | if (quad->diff == 0) { |
189 | *div_error = 1; | 189 | *div_error = 1; |
190 | return span; | 190 | return span; |
191 | } | 191 | } |
192 | if (quad->logStart <= row && row <= quad->logEnd && | 192 | if (quad->logStart <= row && row <= quad->logEnd && |
193 | (mega_mod64(row-quad->logStart, quad->diff)) == 0) { | 193 | (mega_mod64(row-quad->logStart, quad->diff)) == 0) { |
194 | if (span_blk != NULL) { | 194 | if (span_blk != NULL) { |
195 | u64 blk, debugBlk; | 195 | u64 blk, debugBlk; |
196 | blk = | 196 | blk = |
197 | mega_div64_32( | 197 | mega_div64_32( |
198 | (row-quad->logStart), | 198 | (row-quad->logStart), |
199 | quad->diff); | 199 | quad->diff); |
200 | debugBlk = blk; | 200 | debugBlk = blk; |
201 | 201 | ||
202 | blk = (blk + quad->offsetInSpan) << | 202 | blk = (blk + quad->offsetInSpan) << |
203 | raid->stripeShift; | 203 | raid->stripeShift; |
204 | *span_blk = blk; | 204 | *span_blk = blk; |
205 | } | 205 | } |
206 | return span; | 206 | return span; |
207 | } | 207 | } |
208 | } | 208 | } |
209 | } | 209 | } |
210 | return span; | 210 | return span; |
211 | } | 211 | } |
212 | 212 | ||
213 | /* | 213 | /* |
214 | ****************************************************************************** | 214 | ****************************************************************************** |
215 | * | 215 | * |
216 | * This routine calculates the arm, span and block for the specified stripe and | 216 | * This routine calculates the arm, span and block for the specified stripe and |
217 | * reference in stripe. | 217 | * reference in stripe. |
218 | * | 218 | * |
219 | * Inputs : | 219 | * Inputs : |
220 | * | 220 | * |
221 | * ld - Logical drive number | 221 | * ld - Logical drive number |
222 | * stripRow - Stripe number | 222 | * stripRow - Stripe number |
223 | * stripRef - Reference in stripe | 223 | * stripRef - Reference in stripe |
224 | * | 224 | * |
225 | * Outputs : | 225 | * Outputs : |
226 | * | 226 | * |
227 | * span - Span number | 227 | * span - Span number |
228 | * block - Absolute Block number in the physical disk | 228 | * block - Absolute Block number in the physical disk |
229 | */ | 229 | */ |
230 | u8 MR_GetPhyParams(struct megasas_instance *instance, u32 ld, u64 stripRow, | 230 | u8 MR_GetPhyParams(struct megasas_instance *instance, u32 ld, u64 stripRow, |
231 | u16 stripRef, u64 *pdBlock, u16 *pDevHandle, | 231 | u16 stripRef, u64 *pdBlock, u16 *pDevHandle, |
232 | struct RAID_CONTEXT *pRAID_Context, | 232 | struct RAID_CONTEXT *pRAID_Context, |
233 | struct MR_FW_RAID_MAP_ALL *map) | 233 | struct MR_FW_RAID_MAP_ALL *map) |
234 | { | 234 | { |
235 | struct MR_LD_RAID *raid = MR_LdRaidGet(ld, map); | 235 | struct MR_LD_RAID *raid = MR_LdRaidGet(ld, map); |
236 | u32 pd, arRef; | 236 | u32 pd, arRef; |
237 | u8 physArm, span; | 237 | u8 physArm, span; |
238 | u64 row; | 238 | u64 row; |
239 | u8 retval = TRUE; | 239 | u8 retval = TRUE; |
240 | int error_code = 0; | 240 | int error_code = 0; |
241 | 241 | ||
242 | row = mega_div64_32(stripRow, raid->rowDataSize); | 242 | row = mega_div64_32(stripRow, raid->rowDataSize); |
243 | 243 | ||
244 | if (raid->level == 6) { | 244 | if (raid->level == 6) { |
245 | /* logical arm within row */ | 245 | /* logical arm within row */ |
246 | u32 logArm = mega_mod64(stripRow, raid->rowDataSize); | 246 | u32 logArm = mega_mod64(stripRow, raid->rowDataSize); |
247 | u32 rowMod, armQ, arm; | 247 | u32 rowMod, armQ, arm; |
248 | 248 | ||
249 | if (raid->rowSize == 0) | 249 | if (raid->rowSize == 0) |
250 | return FALSE; | 250 | return FALSE; |
251 | /* get logical row mod */ | 251 | /* get logical row mod */ |
252 | rowMod = mega_mod64(row, raid->rowSize); | 252 | rowMod = mega_mod64(row, raid->rowSize); |
253 | armQ = raid->rowSize-1-rowMod; /* index of Q drive */ | 253 | armQ = raid->rowSize-1-rowMod; /* index of Q drive */ |
254 | arm = armQ+1+logArm; /* data always logically follows Q */ | 254 | arm = armQ+1+logArm; /* data always logically follows Q */ |
255 | if (arm >= raid->rowSize) /* handle wrap condition */ | 255 | if (arm >= raid->rowSize) /* handle wrap condition */ |
256 | arm -= raid->rowSize; | 256 | arm -= raid->rowSize; |
257 | physArm = (u8)arm; | 257 | physArm = (u8)arm; |
258 | } else { | 258 | } else { |
259 | if (raid->modFactor == 0) | 259 | if (raid->modFactor == 0) |
260 | return FALSE; | 260 | return FALSE; |
261 | physArm = MR_LdDataArmGet(ld, mega_mod64(stripRow, | 261 | physArm = MR_LdDataArmGet(ld, mega_mod64(stripRow, |
262 | raid->modFactor), | 262 | raid->modFactor), |
263 | map); | 263 | map); |
264 | } | 264 | } |
265 | 265 | ||
266 | if (raid->spanDepth == 1) { | 266 | if (raid->spanDepth == 1) { |
267 | span = 0; | 267 | span = 0; |
268 | *pdBlock = row << raid->stripeShift; | 268 | *pdBlock = row << raid->stripeShift; |
269 | } else { | 269 | } else { |
270 | span = (u8)MR_GetSpanBlock(ld, row, pdBlock, map, &error_code); | 270 | span = (u8)MR_GetSpanBlock(ld, row, pdBlock, map, &error_code); |
271 | if (error_code == 1) | 271 | if (error_code == 1) |
272 | return FALSE; | 272 | return FALSE; |
273 | } | 273 | } |
274 | 274 | ||
275 | /* Get the array on which this span is present */ | 275 | /* Get the array on which this span is present */ |
276 | arRef = MR_LdSpanArrayGet(ld, span, map); | 276 | arRef = MR_LdSpanArrayGet(ld, span, map); |
277 | pd = MR_ArPdGet(arRef, physArm, map); /* Get the pd */ | 277 | pd = MR_ArPdGet(arRef, physArm, map); /* Get the pd */ |
278 | 278 | ||
279 | if (pd != MR_PD_INVALID) | 279 | if (pd != MR_PD_INVALID) |
280 | /* Get dev handle from Pd. */ | 280 | /* Get dev handle from Pd. */ |
281 | *pDevHandle = MR_PdDevHandleGet(pd, map); | 281 | *pDevHandle = MR_PdDevHandleGet(pd, map); |
282 | else { | 282 | else { |
283 | *pDevHandle = MR_PD_INVALID; /* set dev handle as invalid. */ | 283 | *pDevHandle = MR_PD_INVALID; /* set dev handle as invalid. */ |
284 | if ((raid->level >= 5) && | 284 | if ((raid->level >= 5) && |
285 | ((instance->pdev->device != PCI_DEVICE_ID_LSI_INVADER) || | 285 | ((instance->pdev->device != PCI_DEVICE_ID_LSI_INVADER) || |
286 | (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER && | 286 | (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER && |
287 | raid->regTypeReqOnRead != REGION_TYPE_UNUSED))) | 287 | raid->regTypeReqOnRead != REGION_TYPE_UNUSED))) |
288 | pRAID_Context->regLockFlags = REGION_TYPE_EXCLUSIVE; | 288 | pRAID_Context->regLockFlags = REGION_TYPE_EXCLUSIVE; |
289 | else if (raid->level == 1) { | 289 | else if (raid->level == 1) { |
290 | /* Get alternate Pd. */ | 290 | /* Get alternate Pd. */ |
291 | pd = MR_ArPdGet(arRef, physArm + 1, map); | 291 | pd = MR_ArPdGet(arRef, physArm + 1, map); |
292 | if (pd != MR_PD_INVALID) | 292 | if (pd != MR_PD_INVALID) |
293 | /* Get dev handle from Pd */ | 293 | /* Get dev handle from Pd */ |
294 | *pDevHandle = MR_PdDevHandleGet(pd, map); | 294 | *pDevHandle = MR_PdDevHandleGet(pd, map); |
295 | } | 295 | } |
296 | } | 296 | } |
297 | 297 | ||
298 | *pdBlock += stripRef + MR_LdSpanPtrGet(ld, span, map)->startBlk; | 298 | *pdBlock += stripRef + MR_LdSpanPtrGet(ld, span, map)->startBlk; |
299 | pRAID_Context->spanArm = (span << RAID_CTX_SPANARM_SPAN_SHIFT) | | 299 | pRAID_Context->spanArm = (span << RAID_CTX_SPANARM_SPAN_SHIFT) | |
300 | physArm; | 300 | physArm; |
301 | return retval; | 301 | return retval; |
302 | } | 302 | } |
303 | 303 | ||
304 | /* | 304 | /* |
305 | ****************************************************************************** | 305 | ****************************************************************************** |
306 | * | 306 | * |
307 | * MR_BuildRaidContext function | 307 | * MR_BuildRaidContext function |
308 | * | 308 | * |
309 | * This function will initiate command processing. The start/end row and strip | 309 | * This function will initiate command processing. The start/end row and strip |
310 | * information is calculated then the lock is acquired. | 310 | * information is calculated then the lock is acquired. |
311 | * This function will return 0 if region lock was acquired OR return num strips | 311 | * This function will return 0 if region lock was acquired OR return num strips |
312 | */ | 312 | */ |
313 | u8 | 313 | u8 |
314 | MR_BuildRaidContext(struct megasas_instance *instance, | 314 | MR_BuildRaidContext(struct megasas_instance *instance, |
315 | struct IO_REQUEST_INFO *io_info, | 315 | struct IO_REQUEST_INFO *io_info, |
316 | struct RAID_CONTEXT *pRAID_Context, | 316 | struct RAID_CONTEXT *pRAID_Context, |
317 | struct MR_FW_RAID_MAP_ALL *map) | 317 | struct MR_FW_RAID_MAP_ALL *map) |
318 | { | 318 | { |
319 | struct MR_LD_RAID *raid; | 319 | struct MR_LD_RAID *raid; |
320 | u32 ld, stripSize, stripe_mask; | 320 | u32 ld, stripSize, stripe_mask; |
321 | u64 endLba, endStrip, endRow, start_row, start_strip; | 321 | u64 endLba, endStrip, endRow, start_row, start_strip; |
322 | u64 regStart; | 322 | u64 regStart; |
323 | u32 regSize; | 323 | u32 regSize; |
324 | u8 num_strips, numRows; | 324 | u8 num_strips, numRows; |
325 | u16 ref_in_start_stripe, ref_in_end_stripe; | 325 | u16 ref_in_start_stripe, ref_in_end_stripe; |
326 | u64 ldStartBlock; | 326 | u64 ldStartBlock; |
327 | u32 numBlocks, ldTgtId; | 327 | u32 numBlocks, ldTgtId; |
328 | u8 isRead; | 328 | u8 isRead; |
329 | u8 retval = 0; | 329 | u8 retval = 0; |
330 | 330 | ||
331 | ldStartBlock = io_info->ldStartBlock; | 331 | ldStartBlock = io_info->ldStartBlock; |
332 | numBlocks = io_info->numBlocks; | 332 | numBlocks = io_info->numBlocks; |
333 | ldTgtId = io_info->ldTgtId; | 333 | ldTgtId = io_info->ldTgtId; |
334 | isRead = io_info->isRead; | 334 | isRead = io_info->isRead; |
335 | 335 | ||
336 | ld = MR_TargetIdToLdGet(ldTgtId, map); | 336 | ld = MR_TargetIdToLdGet(ldTgtId, map); |
337 | raid = MR_LdRaidGet(ld, map); | 337 | raid = MR_LdRaidGet(ld, map); |
338 | 338 | ||
339 | stripSize = 1 << raid->stripeShift; | 339 | stripSize = 1 << raid->stripeShift; |
340 | stripe_mask = stripSize-1; | 340 | stripe_mask = stripSize-1; |
341 | /* | 341 | /* |
342 | * calculate starting row and stripe, and number of strips and rows | 342 | * calculate starting row and stripe, and number of strips and rows |
343 | */ | 343 | */ |
344 | start_strip = ldStartBlock >> raid->stripeShift; | 344 | start_strip = ldStartBlock >> raid->stripeShift; |
345 | ref_in_start_stripe = (u16)(ldStartBlock & stripe_mask); | 345 | ref_in_start_stripe = (u16)(ldStartBlock & stripe_mask); |
346 | endLba = ldStartBlock + numBlocks - 1; | 346 | endLba = ldStartBlock + numBlocks - 1; |
347 | ref_in_end_stripe = (u16)(endLba & stripe_mask); | 347 | ref_in_end_stripe = (u16)(endLba & stripe_mask); |
348 | endStrip = endLba >> raid->stripeShift; | 348 | endStrip = endLba >> raid->stripeShift; |
349 | num_strips = (u8)(endStrip - start_strip + 1); /* End strip */ | 349 | num_strips = (u8)(endStrip - start_strip + 1); /* End strip */ |
350 | if (raid->rowDataSize == 0) | 350 | if (raid->rowDataSize == 0) |
351 | return FALSE; | 351 | return FALSE; |
352 | start_row = mega_div64_32(start_strip, raid->rowDataSize); | 352 | start_row = mega_div64_32(start_strip, raid->rowDataSize); |
353 | endRow = mega_div64_32(endStrip, raid->rowDataSize); | 353 | endRow = mega_div64_32(endStrip, raid->rowDataSize); |
354 | numRows = (u8)(endRow - start_row + 1); | 354 | numRows = (u8)(endRow - start_row + 1); |
355 | 355 | ||
356 | /* | 356 | /* |
357 | * calculate region info. | 357 | * calculate region info. |
358 | */ | 358 | */ |
359 | 359 | ||
360 | /* assume region is at the start of the first row */ | 360 | /* assume region is at the start of the first row */ |
361 | regStart = start_row << raid->stripeShift; | 361 | regStart = start_row << raid->stripeShift; |
362 | /* assume this IO needs the full row - we'll adjust if not true */ | 362 | /* assume this IO needs the full row - we'll adjust if not true */ |
363 | regSize = stripSize; | 363 | regSize = stripSize; |
364 | 364 | ||
365 | /* If IO spans more than 1 strip, fp is not possible | 365 | /* Check if we can send this I/O via FastPath */ |
366 | FP is not possible for writes on non-0 raid levels | 366 | if (raid->capability.fpCapable) { |
367 | FP is not possible if LD is not capable */ | 367 | if (isRead) |
368 | if (num_strips > 1 || (!isRead && raid->level != 0) || | 368 | io_info->fpOkForIo = (raid->capability.fpReadCapable && |
369 | !raid->capability.fpCapable) { | 369 | ((num_strips == 1) || |
370 | raid->capability. | ||
371 | fpReadAcrossStripe)); | ||
372 | else | ||
373 | io_info->fpOkForIo = (raid->capability.fpWriteCapable && | ||
374 | ((num_strips == 1) || | ||
375 | raid->capability. | ||
376 | fpWriteAcrossStripe)); | ||
377 | } else | ||
370 | io_info->fpOkForIo = FALSE; | 378 | io_info->fpOkForIo = FALSE; |
371 | } else { | ||
372 | io_info->fpOkForIo = TRUE; | ||
373 | } | ||
374 | 379 | ||
375 | if (numRows == 1) { | 380 | if (numRows == 1) { |
376 | /* single-strip IOs can always lock only the data needed */ | 381 | /* single-strip IOs can always lock only the data needed */ |
377 | if (num_strips == 1) { | 382 | if (num_strips == 1) { |
378 | regStart += ref_in_start_stripe; | 383 | regStart += ref_in_start_stripe; |
379 | regSize = numBlocks; | 384 | regSize = numBlocks; |
380 | } | 385 | } |
381 | /* multi-strip IOs always need to full stripe locked */ | 386 | /* multi-strip IOs always need to full stripe locked */ |
382 | } else { | 387 | } else { |
383 | if (start_strip == (start_row + 1) * raid->rowDataSize - 1) { | 388 | if (start_strip == (start_row + 1) * raid->rowDataSize - 1) { |
384 | /* If the start strip is the last in the start row */ | 389 | /* If the start strip is the last in the start row */ |
385 | regStart += ref_in_start_stripe; | 390 | regStart += ref_in_start_stripe; |
386 | regSize = stripSize - ref_in_start_stripe; | 391 | regSize = stripSize - ref_in_start_stripe; |
387 | /* initialize count to sectors from startref to end | 392 | /* initialize count to sectors from startref to end |
388 | of strip */ | 393 | of strip */ |
389 | } | 394 | } |
390 | 395 | ||
391 | if (numRows > 2) | 396 | if (numRows > 2) |
392 | /* Add complete rows in the middle of the transfer */ | 397 | /* Add complete rows in the middle of the transfer */ |
393 | regSize += (numRows-2) << raid->stripeShift; | 398 | regSize += (numRows-2) << raid->stripeShift; |
394 | 399 | ||
395 | /* if IO ends within first strip of last row */ | 400 | /* if IO ends within first strip of last row */ |
396 | if (endStrip == endRow*raid->rowDataSize) | 401 | if (endStrip == endRow*raid->rowDataSize) |
397 | regSize += ref_in_end_stripe+1; | 402 | regSize += ref_in_end_stripe+1; |
398 | else | 403 | else |
399 | regSize += stripSize; | 404 | regSize += stripSize; |
400 | } | 405 | } |
401 | 406 | ||
402 | pRAID_Context->timeoutValue = map->raidMap.fpPdIoTimeoutSec; | 407 | pRAID_Context->timeoutValue = map->raidMap.fpPdIoTimeoutSec; |
403 | if (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) | 408 | if (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) |
404 | pRAID_Context->regLockFlags = (isRead) ? | 409 | pRAID_Context->regLockFlags = (isRead) ? |
405 | raid->regTypeReqOnRead : raid->regTypeReqOnWrite; | 410 | raid->regTypeReqOnRead : raid->regTypeReqOnWrite; |
406 | else | 411 | else |
407 | pRAID_Context->regLockFlags = (isRead) ? | 412 | pRAID_Context->regLockFlags = (isRead) ? |
408 | REGION_TYPE_SHARED_READ : raid->regTypeReqOnWrite; | 413 | REGION_TYPE_SHARED_READ : raid->regTypeReqOnWrite; |
409 | pRAID_Context->VirtualDiskTgtId = raid->targetId; | 414 | pRAID_Context->VirtualDiskTgtId = raid->targetId; |
410 | pRAID_Context->regLockRowLBA = regStart; | 415 | pRAID_Context->regLockRowLBA = regStart; |
411 | pRAID_Context->regLockLength = regSize; | 416 | pRAID_Context->regLockLength = regSize; |
412 | pRAID_Context->configSeqNum = raid->seqNum; | 417 | pRAID_Context->configSeqNum = raid->seqNum; |
413 | 418 | ||
414 | /*Get Phy Params only if FP capable, or else leave it to MR firmware | 419 | /*Get Phy Params only if FP capable, or else leave it to MR firmware |
415 | to do the calculation.*/ | 420 | to do the calculation.*/ |
416 | if (io_info->fpOkForIo) { | 421 | if (io_info->fpOkForIo) { |
417 | retval = MR_GetPhyParams(instance, ld, start_strip, | 422 | retval = MR_GetPhyParams(instance, ld, start_strip, |
418 | ref_in_start_stripe, | 423 | ref_in_start_stripe, |
419 | &io_info->pdBlock, | 424 | &io_info->pdBlock, |
420 | &io_info->devHandle, pRAID_Context, | 425 | &io_info->devHandle, pRAID_Context, |
421 | map); | 426 | map); |
422 | /* If IO on an invalid Pd, then FP i snot possible */ | 427 | /* If IO on an invalid Pd, then FP i snot possible */ |
423 | if (io_info->devHandle == MR_PD_INVALID) | 428 | if (io_info->devHandle == MR_PD_INVALID) |
424 | io_info->fpOkForIo = FALSE; | 429 | io_info->fpOkForIo = FALSE; |
425 | return retval; | 430 | return retval; |
426 | } else if (isRead) { | 431 | } else if (isRead) { |
427 | uint stripIdx; | 432 | uint stripIdx; |
428 | for (stripIdx = 0; stripIdx < num_strips; stripIdx++) { | 433 | for (stripIdx = 0; stripIdx < num_strips; stripIdx++) { |
429 | if (!MR_GetPhyParams(instance, ld, | 434 | if (!MR_GetPhyParams(instance, ld, |
430 | start_strip + stripIdx, | 435 | start_strip + stripIdx, |
431 | ref_in_start_stripe, | 436 | ref_in_start_stripe, |
432 | &io_info->pdBlock, | 437 | &io_info->pdBlock, |
433 | &io_info->devHandle, | 438 | &io_info->devHandle, |
434 | pRAID_Context, map)) | 439 | pRAID_Context, map)) |
435 | return TRUE; | 440 | return TRUE; |
436 | } | 441 | } |
437 | } | 442 | } |
438 | return TRUE; | 443 | return TRUE; |
439 | } | 444 | } |
440 | 445 | ||
441 | void | 446 | void |
442 | mr_update_load_balance_params(struct MR_FW_RAID_MAP_ALL *map, | 447 | mr_update_load_balance_params(struct MR_FW_RAID_MAP_ALL *map, |
443 | struct LD_LOAD_BALANCE_INFO *lbInfo) | 448 | struct LD_LOAD_BALANCE_INFO *lbInfo) |
444 | { | 449 | { |
445 | int ldCount; | 450 | int ldCount; |
446 | u16 ld; | 451 | u16 ld; |
447 | struct MR_LD_RAID *raid; | 452 | struct MR_LD_RAID *raid; |
448 | 453 | ||
449 | for (ldCount = 0; ldCount < MAX_LOGICAL_DRIVES; ldCount++) { | 454 | for (ldCount = 0; ldCount < MAX_LOGICAL_DRIVES; ldCount++) { |
450 | ld = MR_TargetIdToLdGet(ldCount, map); | 455 | ld = MR_TargetIdToLdGet(ldCount, map); |
451 | if (ld >= MAX_LOGICAL_DRIVES) { | 456 | if (ld >= MAX_LOGICAL_DRIVES) { |
452 | lbInfo[ldCount].loadBalanceFlag = 0; | 457 | lbInfo[ldCount].loadBalanceFlag = 0; |
453 | continue; | 458 | continue; |
454 | } | 459 | } |
455 | 460 | ||
456 | raid = MR_LdRaidGet(ld, map); | 461 | raid = MR_LdRaidGet(ld, map); |
457 | 462 | ||
458 | /* Two drive Optimal RAID 1 */ | 463 | /* Two drive Optimal RAID 1 */ |
459 | if ((raid->level == 1) && (raid->rowSize == 2) && | 464 | if ((raid->level == 1) && (raid->rowSize == 2) && |
460 | (raid->spanDepth == 1) && raid->ldState == | 465 | (raid->spanDepth == 1) && raid->ldState == |
461 | MR_LD_STATE_OPTIMAL) { | 466 | MR_LD_STATE_OPTIMAL) { |
462 | u32 pd, arRef; | 467 | u32 pd, arRef; |
463 | 468 | ||
464 | lbInfo[ldCount].loadBalanceFlag = 1; | 469 | lbInfo[ldCount].loadBalanceFlag = 1; |
465 | 470 | ||
466 | /* Get the array on which this span is present */ | 471 | /* Get the array on which this span is present */ |
467 | arRef = MR_LdSpanArrayGet(ld, 0, map); | 472 | arRef = MR_LdSpanArrayGet(ld, 0, map); |
468 | 473 | ||
469 | /* Get the Pd */ | 474 | /* Get the Pd */ |
470 | pd = MR_ArPdGet(arRef, 0, map); | 475 | pd = MR_ArPdGet(arRef, 0, map); |
471 | /* Get dev handle from Pd */ | 476 | /* Get dev handle from Pd */ |
472 | lbInfo[ldCount].raid1DevHandle[0] = | 477 | lbInfo[ldCount].raid1DevHandle[0] = |
473 | MR_PdDevHandleGet(pd, map); | 478 | MR_PdDevHandleGet(pd, map); |
474 | /* Get the Pd */ | 479 | /* Get the Pd */ |
475 | pd = MR_ArPdGet(arRef, 1, map); | 480 | pd = MR_ArPdGet(arRef, 1, map); |
476 | 481 | ||
477 | /* Get the dev handle from Pd */ | 482 | /* Get the dev handle from Pd */ |
478 | lbInfo[ldCount].raid1DevHandle[1] = | 483 | lbInfo[ldCount].raid1DevHandle[1] = |
479 | MR_PdDevHandleGet(pd, map); | 484 | MR_PdDevHandleGet(pd, map); |
480 | } else | 485 | } else |
481 | lbInfo[ldCount].loadBalanceFlag = 0; | 486 | lbInfo[ldCount].loadBalanceFlag = 0; |
482 | } | 487 | } |
483 | } | 488 | } |
484 | 489 | ||
485 | u8 megasas_get_best_arm(struct LD_LOAD_BALANCE_INFO *lbInfo, u8 arm, u64 block, | 490 | u8 megasas_get_best_arm(struct LD_LOAD_BALANCE_INFO *lbInfo, u8 arm, u64 block, |
486 | u32 count) | 491 | u32 count) |
487 | { | 492 | { |
488 | u16 pend0, pend1; | 493 | u16 pend0, pend1; |
489 | u64 diff0, diff1; | 494 | u64 diff0, diff1; |
490 | u8 bestArm; | 495 | u8 bestArm; |
491 | 496 | ||
492 | /* get the pending cmds for the data and mirror arms */ | 497 | /* get the pending cmds for the data and mirror arms */ |
493 | pend0 = atomic_read(&lbInfo->scsi_pending_cmds[0]); | 498 | pend0 = atomic_read(&lbInfo->scsi_pending_cmds[0]); |
494 | pend1 = atomic_read(&lbInfo->scsi_pending_cmds[1]); | 499 | pend1 = atomic_read(&lbInfo->scsi_pending_cmds[1]); |
495 | 500 | ||
496 | /* Determine the disk whose head is nearer to the req. block */ | 501 | /* Determine the disk whose head is nearer to the req. block */ |
497 | diff0 = ABS_DIFF(block, lbInfo->last_accessed_block[0]); | 502 | diff0 = ABS_DIFF(block, lbInfo->last_accessed_block[0]); |
498 | diff1 = ABS_DIFF(block, lbInfo->last_accessed_block[1]); | 503 | diff1 = ABS_DIFF(block, lbInfo->last_accessed_block[1]); |
499 | bestArm = (diff0 <= diff1 ? 0 : 1); | 504 | bestArm = (diff0 <= diff1 ? 0 : 1); |
500 | 505 | ||
501 | if ((bestArm == arm && pend0 > pend1 + 16) || | 506 | if ((bestArm == arm && pend0 > pend1 + 16) || |
502 | (bestArm != arm && pend1 > pend0 + 16)) | 507 | (bestArm != arm && pend1 > pend0 + 16)) |
503 | bestArm ^= 1; | 508 | bestArm ^= 1; |
504 | 509 | ||
505 | /* Update the last accessed block on the correct pd */ | 510 | /* Update the last accessed block on the correct pd */ |
506 | lbInfo->last_accessed_block[bestArm] = block + count - 1; | 511 | lbInfo->last_accessed_block[bestArm] = block + count - 1; |
507 | 512 | ||
508 | return bestArm; | 513 | return bestArm; |
509 | } | 514 | } |
510 | 515 | ||
511 | u16 get_updated_dev_handle(struct LD_LOAD_BALANCE_INFO *lbInfo, | 516 | u16 get_updated_dev_handle(struct LD_LOAD_BALANCE_INFO *lbInfo, |
512 | struct IO_REQUEST_INFO *io_info) | 517 | struct IO_REQUEST_INFO *io_info) |
513 | { | 518 | { |
514 | u8 arm, old_arm; | 519 | u8 arm, old_arm; |
515 | u16 devHandle; | 520 | u16 devHandle; |
516 | 521 | ||
517 | old_arm = lbInfo->raid1DevHandle[0] == io_info->devHandle ? 0 : 1; | 522 | old_arm = lbInfo->raid1DevHandle[0] == io_info->devHandle ? 0 : 1; |
518 | 523 | ||
519 | /* get best new arm */ | 524 | /* get best new arm */ |
520 | arm = megasas_get_best_arm(lbInfo, old_arm, io_info->ldStartBlock, | 525 | arm = megasas_get_best_arm(lbInfo, old_arm, io_info->ldStartBlock, |
521 | io_info->numBlocks); | 526 | io_info->numBlocks); |
522 | devHandle = lbInfo->raid1DevHandle[arm]; | 527 | devHandle = lbInfo->raid1DevHandle[arm]; |
523 | atomic_inc(&lbInfo->scsi_pending_cmds[arm]); | 528 | atomic_inc(&lbInfo->scsi_pending_cmds[arm]); |
524 | 529 |