This source file includes following definitions.
- _warpdrive_disable_ddio
- mpt3sas_get_num_volumes
- mpt3sas_init_warpdrive_properties
- mpt3sas_setup_direct_io
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 #include <linux/kernel.h>
42 #include <linux/module.h>
43 #include <linux/errno.h>
44 #include <linux/types.h>
45 #include <asm/unaligned.h>
46
47 #include "mpt3sas_base.h"
48
49
50
51
52
53 static void
54 _warpdrive_disable_ddio(struct MPT3SAS_ADAPTER *ioc)
55 {
56 Mpi2RaidVolPage1_t vol_pg1;
57 Mpi2ConfigReply_t mpi_reply;
58 struct _raid_device *raid_device;
59 u16 handle;
60 u16 ioc_status;
61 unsigned long flags;
62
63 handle = 0xFFFF;
64 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
65 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
66 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
67 MPI2_IOCSTATUS_MASK;
68 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
69 break;
70 handle = le16_to_cpu(vol_pg1.DevHandle);
71 spin_lock_irqsave(&ioc->raid_device_lock, flags);
72 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
73 if (raid_device)
74 raid_device->direct_io_enabled = 0;
75 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
76 }
77 return;
78 }
79
80
81
82
83
84
85 u8
86 mpt3sas_get_num_volumes(struct MPT3SAS_ADAPTER *ioc)
87 {
88 Mpi2RaidVolPage1_t vol_pg1;
89 Mpi2ConfigReply_t mpi_reply;
90 u16 handle;
91 u8 vol_cnt = 0;
92 u16 ioc_status;
93
94 handle = 0xFFFF;
95 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
96 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
97 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
98 MPI2_IOCSTATUS_MASK;
99 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
100 break;
101 vol_cnt++;
102 handle = le16_to_cpu(vol_pg1.DevHandle);
103 }
104 return vol_cnt;
105 }
106
107
108
109
110
111
112
113 void
114 mpt3sas_init_warpdrive_properties(struct MPT3SAS_ADAPTER *ioc,
115 struct _raid_device *raid_device)
116 {
117 Mpi2RaidVolPage0_t *vol_pg0;
118 Mpi2RaidPhysDiskPage0_t pd_pg0;
119 Mpi2ConfigReply_t mpi_reply;
120 u16 sz;
121 u8 num_pds, count;
122 unsigned long stripe_sz, block_sz;
123 u8 stripe_exp, block_exp;
124 u64 dev_max_lba;
125
126 if (!ioc->is_warpdrive)
127 return;
128
129 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) {
130 ioc_info(ioc, "WarpDrive : Direct IO is disabled globally as drives are exposed\n");
131 return;
132 }
133 if (mpt3sas_get_num_volumes(ioc) > 1) {
134 _warpdrive_disable_ddio(ioc);
135 ioc_info(ioc, "WarpDrive : Direct IO is disabled globally as number of drives > 1\n");
136 return;
137 }
138 if ((mpt3sas_config_get_number_pds(ioc, raid_device->handle,
139 &num_pds)) || !num_pds) {
140 ioc_info(ioc, "WarpDrive : Direct IO is disabled Failure in computing number of drives\n");
141 return;
142 }
143
144 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
145 sizeof(Mpi2RaidVol0PhysDisk_t));
146 vol_pg0 = kzalloc(sz, GFP_KERNEL);
147 if (!vol_pg0) {
148 ioc_info(ioc, "WarpDrive : Direct IO is disabled Memory allocation failure for RVPG0\n");
149 return;
150 }
151
152 if ((mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
153 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
154 ioc_info(ioc, "WarpDrive : Direct IO is disabled Failure in retrieving RVPG0\n");
155 kfree(vol_pg0);
156 return;
157 }
158
159
160
161
162
163 if (num_pds > MPT_MAX_WARPDRIVE_PDS) {
164 ioc_warn(ioc, "WarpDrive : Direct IO is disabled for the drive with handle(0x%04x): num_mem=%d, max_mem_allowed=%d\n",
165 raid_device->handle, num_pds, MPT_MAX_WARPDRIVE_PDS);
166 kfree(vol_pg0);
167 return;
168 }
169 for (count = 0; count < num_pds; count++) {
170 if (mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
171 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
172 vol_pg0->PhysDisk[count].PhysDiskNum) ||
173 le16_to_cpu(pd_pg0.DevHandle) ==
174 MPT3SAS_INVALID_DEVICE_HANDLE) {
175 ioc_info(ioc, "WarpDrive : Direct IO is disabled for the drive with handle(0x%04x) member handle retrieval failed for member number=%d\n",
176 raid_device->handle,
177 vol_pg0->PhysDisk[count].PhysDiskNum);
178 goto out_error;
179 }
180
181 dev_max_lba = le64_to_cpu(pd_pg0.DeviceMaxLBA);
182 if (dev_max_lba >> 32) {
183 ioc_info(ioc, "WarpDrive : Direct IO is disabled for the drive with handle(0x%04x) member handle (0x%04x) unsupported max lba 0x%016llx\n",
184 raid_device->handle,
185 le16_to_cpu(pd_pg0.DevHandle),
186 (u64)dev_max_lba);
187 goto out_error;
188 }
189
190 raid_device->pd_handle[count] = le16_to_cpu(pd_pg0.DevHandle);
191 }
192
193
194
195
196
197 if (raid_device->volume_type != MPI2_RAID_VOL_TYPE_RAID0) {
198 ioc_info(ioc, "WarpDrive : Direct IO is disabled for the drive with handle(0x%04x): type=%d, s_sz=%uK, blk_size=%u\n",
199 raid_device->handle, raid_device->volume_type,
200 (le32_to_cpu(vol_pg0->StripeSize) *
201 le16_to_cpu(vol_pg0->BlockSize)) / 1024,
202 le16_to_cpu(vol_pg0->BlockSize));
203 goto out_error;
204 }
205
206 stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
207 stripe_exp = find_first_bit(&stripe_sz, 32);
208 if (stripe_exp == 32) {
209 ioc_info(ioc, "WarpDrive : Direct IO is disabled for the drive with handle(0x%04x) invalid stripe sz %uK\n",
210 raid_device->handle,
211 (le32_to_cpu(vol_pg0->StripeSize) *
212 le16_to_cpu(vol_pg0->BlockSize)) / 1024);
213 goto out_error;
214 }
215 raid_device->stripe_exponent = stripe_exp;
216 block_sz = le16_to_cpu(vol_pg0->BlockSize);
217 block_exp = find_first_bit(&block_sz, 16);
218 if (block_exp == 16) {
219 ioc_info(ioc, "WarpDrive : Direct IO is disabled for the drive with handle(0x%04x) invalid block sz %u\n",
220 raid_device->handle, le16_to_cpu(vol_pg0->BlockSize));
221 goto out_error;
222 }
223 raid_device->block_exponent = block_exp;
224 raid_device->direct_io_enabled = 1;
225
226 ioc_info(ioc, "WarpDrive : Direct IO is Enabled for the drive with handle(0x%04x)\n",
227 raid_device->handle);
228
229
230
231
232 raid_device->max_lba = le64_to_cpu(vol_pg0->MaxLBA);
233 raid_device->stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
234 raid_device->block_sz = le16_to_cpu(vol_pg0->BlockSize);
235
236
237 kfree(vol_pg0);
238 return;
239
240 out_error:
241 raid_device->direct_io_enabled = 0;
242 for (count = 0; count < num_pds; count++)
243 raid_device->pd_handle[count] = 0;
244 kfree(vol_pg0);
245 return;
246 }
247
248
249
250
251
252
253
254
255 void
256 mpt3sas_setup_direct_io(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
257 struct _raid_device *raid_device, Mpi25SCSIIORequest_t *mpi_request)
258 {
259 sector_t v_lba, p_lba, stripe_off, column, io_size;
260 u32 stripe_sz, stripe_exp;
261 u8 num_pds, cmd = scmd->cmnd[0];
262 struct scsiio_tracker *st = scsi_cmd_priv(scmd);
263
264 if (cmd != READ_10 && cmd != WRITE_10 &&
265 cmd != READ_16 && cmd != WRITE_16)
266 return;
267
268 if (cmd == READ_10 || cmd == WRITE_10)
269 v_lba = get_unaligned_be32(&mpi_request->CDB.CDB32[2]);
270 else
271 v_lba = get_unaligned_be64(&mpi_request->CDB.CDB32[2]);
272
273 io_size = scsi_bufflen(scmd) >> raid_device->block_exponent;
274
275 if (v_lba + io_size - 1 > raid_device->max_lba)
276 return;
277
278 stripe_sz = raid_device->stripe_sz;
279 stripe_exp = raid_device->stripe_exponent;
280 stripe_off = v_lba & (stripe_sz - 1);
281
282
283 if (stripe_off + io_size > stripe_sz)
284 return;
285
286 num_pds = raid_device->num_pds;
287 p_lba = v_lba >> stripe_exp;
288 column = sector_div(p_lba, num_pds);
289 p_lba = (p_lba << stripe_exp) + stripe_off;
290 mpi_request->DevHandle = cpu_to_le16(raid_device->pd_handle[column]);
291
292 if (cmd == READ_10 || cmd == WRITE_10)
293 put_unaligned_be32(lower_32_bits(p_lba),
294 &mpi_request->CDB.CDB32[2]);
295 else
296 put_unaligned_be64(p_lba, &mpi_request->CDB.CDB32[2]);
297
298 st->direct_io = 1;
299 }