ioctl.c (9c79794016d679440487dea61b3b986397c9ecbb) ioctl.c (1713e81b9cdf06d2a9a365a7ded13a54fad84798)
1/*
1/*
2 * Copyright (c) 2004-2005 HighPoint Technologies, Inc.
2 * Copyright (c) 2003-2004 HighPoint Technologies, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright

--- 6 unchanged lines hidden (view full) ---

17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright

--- 6 unchanged lines hidden (view full) ---

17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD$
27 */
28/*
29 * ioctl.c ioctl interface implementation
30 */
31#include <sys/param.h>
32#include <sys/systm.h>
33#include <sys/kernel.h>
34#include <sys/malloc.h>
35
25 */
26/*
27 * ioctl.c ioctl interface implementation
28 */
29#include <sys/param.h>
30#include <sys/systm.h>
31#include <sys/kernel.h>
32#include <sys/malloc.h>
33
36#if (__FreeBSD_version < 500000)
37#include <sys/proc.h>
38#include <sys/kthread.h>
39#include <sys/wait.h>
40#include <sys/sysproto.h>
41#endif
42
43#ifndef __KERNEL__
44#define __KERNEL__
45#endif
46
47#include <dev/hptmv/global.h>
48#include <dev/hptmv/hptintf.h>
49#include <dev/hptmv/osbsd.h>
34#include <dev/hptmv/global.h>
35#include <dev/hptmv/hptintf.h>
36#include <dev/hptmv/osbsd.h>
50#include <dev/hptmv/access601.h>
37#include <contrib/dev/hptmv/access601.h>
51
52#pragma pack(1)
53
54typedef struct _HPT_REBUILD_PARAM
55{
56 DEVICEID idMirror;
57 DWORD Lba;
58 UCHAR nSector;

--- 7 unchanged lines hidden (view full) ---

66
67static int hpt_get_event(PHPT_EVENT pEvent);
68static int hpt_set_array_state(DEVICEID idArray, DWORD state);
69static intrmask_t lock_driver_idle(IAL_ADAPTER_T *pAdapter);
70static void HPTLIBAPI thread_io_done(_VBUS_ARG PCommand pCmd);
71static int HPTLIBAPI R1ControlSgl(_VBUS_ARG PCommand pCmd,
72 FPSCAT_GATH pSgTable, int logical);
73
38
39#pragma pack(1)
40
41typedef struct _HPT_REBUILD_PARAM
42{
43 DEVICEID idMirror;
44 DWORD Lba;
45 UCHAR nSector;

--- 7 unchanged lines hidden (view full) ---

53
54static int hpt_get_event(PHPT_EVENT pEvent);
55static int hpt_set_array_state(DEVICEID idArray, DWORD state);
56static intrmask_t lock_driver_idle(IAL_ADAPTER_T *pAdapter);
57static void HPTLIBAPI thread_io_done(_VBUS_ARG PCommand pCmd);
58static int HPTLIBAPI R1ControlSgl(_VBUS_ARG PCommand pCmd,
59 FPSCAT_GATH pSgTable, int logical);
60
74static void
75get_disk_location(PDevice pDev, int *controller, int *channel)
61static void get_disk_location(PDevice pDev, int *controller, int *channel)
76{
77 IAL_ADAPTER_T *pAdapTemp;
78 int i, j;
79
62{
63 IAL_ADAPTER_T *pAdapTemp;
64 int i, j;
65
80 *controller = *channel = 0;
81
82 for (i=1, pAdapTemp = gIal_Adapter; pAdapTemp; pAdapTemp = pAdapTemp->next, i++) {
83 for (j=0; j<MV_SATA_CHANNELS_NUM; j++) {
84 if (pDev == &pAdapTemp->VDevices[j].u.disk) {
85 *controller = i;
86 *channel = j;
87 return;
88 }
89 }
66 for (i=1, pAdapTemp = gIal_Adapter; pAdapTemp; pAdapTemp = pAdapTemp->next, i++) {
67 for (j=0; j<MV_SATA_CHANNELS_NUM; j++)
68 if (pDev==&pAdapTemp->VDevices[j].u.disk) {
69 *controller = i;
70 *channel = j;
71 return;
72 }
90 }
91}
92
73 }
74}
75
93static int
94event_queue_add(PHPT_EVENT pEvent)
76static int event_queue_add(PHPT_EVENT pEvent)
95{
96 int p;
97 p = (event_queue_tail + 1) % MAX_EVENTS;
98 if (p==event_queue_head)
99 {
100 return -1;
101 }
102 hpt_event_queue[event_queue_tail] = *pEvent;
103 event_queue_tail = p;
104 return 0;
105}
106
77{
78 int p;
79 p = (event_queue_tail + 1) % MAX_EVENTS;
80 if (p==event_queue_head)
81 {
82 return -1;
83 }
84 hpt_event_queue[event_queue_tail] = *pEvent;
85 event_queue_tail = p;
86 return 0;
87}
88
107static int
108event_queue_remove(PHPT_EVENT pEvent)
89static int event_queue_remove(PHPT_EVENT pEvent)
109{
110 if (event_queue_head != event_queue_tail)
111 {
112 *pEvent = hpt_event_queue[event_queue_head];
113 event_queue_head++;
114 event_queue_head %= MAX_EVENTS;
115 return 0;
116 }
117 return -1;
118}
119
90{
91 if (event_queue_head != event_queue_tail)
92 {
93 *pEvent = hpt_event_queue[event_queue_head];
94 event_queue_head++;
95 event_queue_head %= MAX_EVENTS;
96 return 0;
97 }
98 return -1;
99}
100
120void HPTLIBAPI
121ioctl_ReportEvent(UCHAR event, PVOID param)
101void HPTLIBAPI ioctl_ReportEvent(UCHAR event, PVOID param)
122{
123 HPT_EVENT e;
124 ZeroMemory(&e, sizeof(e));
125 e.EventType = event;
126 switch(event)
127 {
128 case ET_INITIALIZE_ABORTED:
129 case ET_INITIALIZE_FAILED:

--- 25 unchanged lines hidden (view full) ---

155 event_queue_add(&e);
156 if (event==ET_DEVICE_REMOVED) {
157 int controller, channel;
158 get_disk_location(&((PVDevice)param)->u.disk, &controller, &channel);
159 hpt_printk(("Device removed: controller %d channel %d\n", controller, channel));
160 }
161}
162
102{
103 HPT_EVENT e;
104 ZeroMemory(&e, sizeof(e));
105 e.EventType = event;
106 switch(event)
107 {
108 case ET_INITIALIZE_ABORTED:
109 case ET_INITIALIZE_FAILED:

--- 25 unchanged lines hidden (view full) ---

135 event_queue_add(&e);
136 if (event==ET_DEVICE_REMOVED) {
137 int controller, channel;
138 get_disk_location(&((PVDevice)param)->u.disk, &controller, &channel);
139 hpt_printk(("Device removed: controller %d channel %d\n", controller, channel));
140 }
141}
142
163static int
164hpt_delete_array(_VBUS_ARG DEVICEID id, DWORD options)
143static int hpt_delete_array(_VBUS_ARG DEVICEID id, DWORD options)
165{
166 PVDevice pArray = ID_TO_VDEV(id);
167 BOOLEAN del_block0 = (options & DAF_KEEP_DATA_IF_POSSIBLE)?0:1;
168 int i;
169 PVDevice pa;
170
144{
145 PVDevice pArray = ID_TO_VDEV(id);
146 BOOLEAN del_block0 = (options & DAF_KEEP_DATA_IF_POSSIBLE)?0:1;
147 int i;
148 PVDevice pa;
149
171 if ((id==0) || check_VDevice_valid(pArray))
150 if((id== HPT_NULL_ID) || check_VDevice_valid(pArray))
172 return -1;
173
174 if(!mIsArray(pArray)) return -1;
175
176 if (pArray->u.array.rf_rebuilding || pArray->u.array.rf_verifying ||
177 pArray->u.array.rf_initializing)
178 return -1;
179

--- 10 unchanged lines hidden (view full) ---

190 fDeleteArray(_VBUS_P pArray, del_block0);
191 return 0;
192
193}
194
195/* just to prevent driver from sending more commands */
196static void HPTLIBAPI nothing(_VBUS_ARG void *notused){}
197
151 return -1;
152
153 if(!mIsArray(pArray)) return -1;
154
155 if (pArray->u.array.rf_rebuilding || pArray->u.array.rf_verifying ||
156 pArray->u.array.rf_initializing)
157 return -1;
158

--- 10 unchanged lines hidden (view full) ---

169 fDeleteArray(_VBUS_P pArray, del_block0);
170 return 0;
171
172}
173
174/* just to prevent driver from sending more commands */
175static void HPTLIBAPI nothing(_VBUS_ARG void *notused){}
176
198intrmask_t
199lock_driver_idle(IAL_ADAPTER_T *pAdapter)
177static intrmask_t lock_driver_idle(IAL_ADAPTER_T *pAdapter)
200{
201 intrmask_t oldspl;
202 _VBUS_INST(&pAdapter->VBus)
203 oldspl = lock_driver();
204 while (pAdapter->outstandingCommands) {
205 KdPrint(("outstandingCommands is %d, wait..\n", pAdapter->outstandingCommands));
206 if (!mWaitingForIdle(_VBUS_P0)) CallWhenIdle(_VBUS_P nothing, 0);
207 unlock_driver(oldspl);
178{
179 intrmask_t oldspl;
180 _VBUS_INST(&pAdapter->VBus)
181 oldspl = lock_driver();
182 while (pAdapter->outstandingCommands) {
183 KdPrint(("outstandingCommands is %d, wait..\n", pAdapter->outstandingCommands));
184 if (!mWaitingForIdle(_VBUS_P0)) CallWhenIdle(_VBUS_P nothing, 0);
185 unlock_driver(oldspl);
208/*Schedule out*/
209#if (__FreeBSD_version < 500000)
210 YIELD_THREAD;
211#else
212#if (__FreeBSD_version > 700033)
213 pause("switch", 1);
214#else
215 tsleep(lock_driver_idle, PPAUSE, "switch", 1);
216#endif
217#endif
218 oldspl = lock_driver();
219 }
220 CheckIdleCall(_VBUS_P0);
221 return oldspl;
222}
223
224int Kernel_DeviceIoControl(_VBUS_ARG
225 DWORD dwIoControlCode, /* operation control code */

--- 17 unchanged lines hidden (view full) ---

243 struct cam_periph *periph = NULL;
244
245 if (nInBufferSize!=sizeof(DEVICEID)+sizeof(DWORD)) return -1;
246 if (nOutBufferSize!=sizeof(int)) return -1;
247 idArray = *(DEVICEID *)lpInBuffer;
248
249 pArray = ID_TO_VDEV(idArray);
250
186 oldspl = lock_driver();
187 }
188 CheckIdleCall(_VBUS_P0);
189 return oldspl;
190}
191
192int Kernel_DeviceIoControl(_VBUS_ARG
193 DWORD dwIoControlCode, /* operation control code */

--- 17 unchanged lines hidden (view full) ---

211 struct cam_periph *periph = NULL;
212
213 if (nInBufferSize!=sizeof(DEVICEID)+sizeof(DWORD)) return -1;
214 if (nOutBufferSize!=sizeof(int)) return -1;
215 idArray = *(DEVICEID *)lpInBuffer;
216
217 pArray = ID_TO_VDEV(idArray);
218
251 if((idArray == 0) || check_VDevice_valid(pArray))
219 if((idArray == HPT_NULL_ID) || check_VDevice_valid(pArray))
252 return -1;
253
254 if(!mIsArray(pArray))
255 return -1;
256
257 _vbus_p=pArray->pVBus;
258 pAdapter = (IAL_ADAPTER_T *)_vbus_p->OsExt;
259
260 for(i = 0; i < MAX_VDEVICE_PER_VBUS; i++) {
261 if(pArray == _vbus_p->pVDevice[i])
262 {
263 periph = hpt_get_periph(pAdapter->mvSataAdapter.adapterId, i);
220 return -1;
221
222 if(!mIsArray(pArray))
223 return -1;
224
225 _vbus_p=pArray->pVBus;
226 pAdapter = (IAL_ADAPTER_T *)_vbus_p->OsExt;
227
228 for(i = 0; i < MAX_VDEVICE_PER_VBUS; i++) {
229 if(pArray == _vbus_p->pVDevice[i])
230 {
231 periph = hpt_get_periph(pAdapter->mvSataAdapter.adapterId, i);
264 if (periph != NULL && periph->refcount >= 1)
232 if (periph != NULL && periph->refcount == 1)
265 {
266 hpt_printk(("Can not delete a mounted device.\n"));
267 return -1;
268 }
269 }
270 /* the Mounted Disk isn't delete */
271 }
272

--- 63 unchanged lines hidden (view full) ---

336 /* read-only ioctl functions can be called directly. */
337 case HPT_IOCTL_GET_VERSION:
338 case HPT_IOCTL_GET_CONTROLLER_IDS:
339 case HPT_IOCTL_GET_CONTROLLER_COUNT:
340 case HPT_IOCTL_GET_CONTROLLER_INFO:
341 case HPT_IOCTL_GET_CHANNEL_INFO:
342 case HPT_IOCTL_GET_LOGICAL_DEVICES:
343 case HPT_IOCTL_GET_DEVICE_INFO:
233 {
234 hpt_printk(("Can not delete a mounted device.\n"));
235 return -1;
236 }
237 }
238 /* the Mounted Disk isn't delete */
239 }
240

--- 63 unchanged lines hidden (view full) ---

304 /* read-only ioctl functions can be called directly. */
305 case HPT_IOCTL_GET_VERSION:
306 case HPT_IOCTL_GET_CONTROLLER_IDS:
307 case HPT_IOCTL_GET_CONTROLLER_COUNT:
308 case HPT_IOCTL_GET_CONTROLLER_INFO:
309 case HPT_IOCTL_GET_CHANNEL_INFO:
310 case HPT_IOCTL_GET_LOGICAL_DEVICES:
311 case HPT_IOCTL_GET_DEVICE_INFO:
344 case HPT_IOCTL_GET_DEVICE_INFO_V2:
345 case HPT_IOCTL_GET_EVENT:
346 case HPT_IOCTL_GET_DRIVER_CAPABILITIES:
347 if(hpt_default_ioctl(_VBUS_P dwIoControlCode, lpInBuffer, nInBufferSize,
348 lpOutBuffer, nOutBufferSize, lpBytesReturned) == -1) return -1;
349 break;
350
351 default:
352 /*
353 * GUI always use /proc/scsi/hptmv/0, so the _vbus_p param will be
354 * wrong for second controller.
355 */
356 switch(dwIoControlCode) {
357 case HPT_IOCTL_CREATE_ARRAY:
358 pVDev = ID_TO_VDEV(((PCREATE_ARRAY_PARAMS)lpInBuffer)->Members[0]); break;
312 case HPT_IOCTL_GET_EVENT:
313 case HPT_IOCTL_GET_DRIVER_CAPABILITIES:
314 if(hpt_default_ioctl(_VBUS_P dwIoControlCode, lpInBuffer, nInBufferSize,
315 lpOutBuffer, nOutBufferSize, lpBytesReturned) == -1) return -1;
316 break;
317
318 default:
319 /*
320 * GUI always use /proc/scsi/hptmv/0, so the _vbus_p param will be
321 * wrong for second controller.
322 */
323 switch(dwIoControlCode) {
324 case HPT_IOCTL_CREATE_ARRAY:
325 pVDev = ID_TO_VDEV(((PCREATE_ARRAY_PARAMS)lpInBuffer)->Members[0]); break;
359 case HPT_IOCTL_CREATE_ARRAY_V2:
360 pVDev = ID_TO_VDEV(((PCREATE_ARRAY_PARAMS_V2)lpInBuffer)->Members[0]); break;
361 case HPT_IOCTL_SET_ARRAY_INFO:
362 pVDev = ID_TO_VDEV(((PHPT_SET_ARRAY_INFO)lpInBuffer)->idArray); break;
363 case HPT_IOCTL_SET_DEVICE_INFO:
364 pVDev = ID_TO_VDEV(((PHPT_SET_DEVICE_INFO)lpInBuffer)->idDisk); break;
326 case HPT_IOCTL_SET_ARRAY_INFO:
327 pVDev = ID_TO_VDEV(((PHPT_SET_ARRAY_INFO)lpInBuffer)->idArray); break;
328 case HPT_IOCTL_SET_DEVICE_INFO:
329 pVDev = ID_TO_VDEV(((PHPT_SET_DEVICE_INFO)lpInBuffer)->idDisk); break;
365 case HPT_IOCTL_SET_DEVICE_INFO_V2:
366 pVDev = ID_TO_VDEV(((PHPT_SET_DEVICE_INFO_V2)lpInBuffer)->idDisk); break;
367 case HPT_IOCTL_SET_BOOT_MARK:
368 case HPT_IOCTL_ADD_SPARE_DISK:
369 case HPT_IOCTL_REMOVE_SPARE_DISK:
370 pVDev = ID_TO_VDEV(*(DEVICEID *)lpInBuffer); break;
371 case HPT_IOCTL_ADD_DISK_TO_ARRAY:
372 pVDev = ID_TO_VDEV(((PHPT_ADD_DISK_TO_ARRAY)lpInBuffer)->idArray); break;
373 default:
374 pVDev = 0;

--- 39 unchanged lines hidden (view full) ---

414 else if(((PCREATE_ARRAY_PARAMS)lpInBuffer)->CreateFlags & CAF_CREATE_R5_BUILD_PARITY)
415 {
416 hpt_queue_dpc((HPT_DPC)hpt_rebuild_data_block, pAdapter, ID_TO_VDEV(*(DEVICEID *)lpOutBuffer), REBUILD_PARITY);
417 }
418 unlock_driver(oldspl);
419 break;
420 }
421
330 case HPT_IOCTL_SET_BOOT_MARK:
331 case HPT_IOCTL_ADD_SPARE_DISK:
332 case HPT_IOCTL_REMOVE_SPARE_DISK:
333 pVDev = ID_TO_VDEV(*(DEVICEID *)lpInBuffer); break;
334 case HPT_IOCTL_ADD_DISK_TO_ARRAY:
335 pVDev = ID_TO_VDEV(((PHPT_ADD_DISK_TO_ARRAY)lpInBuffer)->idArray); break;
336 default:
337 pVDev = 0;

--- 39 unchanged lines hidden (view full) ---

377 else if(((PCREATE_ARRAY_PARAMS)lpInBuffer)->CreateFlags & CAF_CREATE_R5_BUILD_PARITY)
378 {
379 hpt_queue_dpc((HPT_DPC)hpt_rebuild_data_block, pAdapter, ID_TO_VDEV(*(DEVICEID *)lpOutBuffer), REBUILD_PARITY);
380 }
381 unlock_driver(oldspl);
382 break;
383 }
384
422
423 case HPT_IOCTL_CREATE_ARRAY_V2:
424 {
425 pAdapter=(IAL_ADAPTER_T *)(ID_TO_VDEV(*(DEVICEID *)lpOutBuffer))->pVBus->OsExt;
426 oldspl = lock_driver();
427 if(((PCREATE_ARRAY_PARAMS_V2)lpInBuffer)->CreateFlags & CAF_CREATE_AND_DUPLICATE) {
428 (ID_TO_VDEV(*(DEVICEID *)lpOutBuffer))->u.array.rf_auto_rebuild = 0;
429 hpt_queue_dpc((HPT_DPC)hpt_rebuild_data_block, pAdapter, ID_TO_VDEV(*(DEVICEID *)lpOutBuffer), DUPLICATE);
430 } else if(((PCREATE_ARRAY_PARAMS_V2)lpInBuffer)->CreateFlags & CAF_CREATE_R5_ZERO_INIT) {
431 hpt_queue_dpc((HPT_DPC)hpt_rebuild_data_block, pAdapter, ID_TO_VDEV(*(DEVICEID *)lpOutBuffer), INITIALIZE);
432 } else if(((PCREATE_ARRAY_PARAMS_V2)lpInBuffer)->CreateFlags & CAF_CREATE_R5_BUILD_PARITY) {
433 hpt_queue_dpc((HPT_DPC)hpt_rebuild_data_block, pAdapter, ID_TO_VDEV(*(DEVICEID *)lpOutBuffer), REBUILD_PARITY);
434 }
435 unlock_driver(oldspl);
436 break;
437 }
438 case HPT_IOCTL_ADD_DISK_TO_ARRAY:
439 {
440 PVDevice pArray = ID_TO_VDEV(((PHPT_ADD_DISK_TO_ARRAY)lpInBuffer)->idArray);
441 pAdapter=(IAL_ADAPTER_T *)pArray->pVBus->OsExt;
385 case HPT_IOCTL_ADD_DISK_TO_ARRAY:
386 {
387 PVDevice pArray = ID_TO_VDEV(((PHPT_ADD_DISK_TO_ARRAY)lpInBuffer)->idArray);
388 pAdapter=(IAL_ADAPTER_T *)pArray->pVBus->OsExt;
442 if(pArray->u.array.rf_rebuilding == 0)
389 if(pArray->u.array.rf_rebuilding == HPT_NULL_ID)
443 {
444 DWORD timeout = 0;
445 oldspl = lock_driver();
446 pArray->u.array.rf_auto_rebuild = 0;
447 pArray->u.array.rf_abort_rebuild = 0;
448 hpt_queue_dpc((HPT_DPC)hpt_rebuild_data_block, pAdapter, pArray, DUPLICATE);
449 unlock_driver(oldspl);
450 while (!pArray->u.array.rf_rebuilding)
451 {
390 {
391 DWORD timeout = 0;
392 oldspl = lock_driver();
393 pArray->u.array.rf_auto_rebuild = 0;
394 pArray->u.array.rf_abort_rebuild = 0;
395 hpt_queue_dpc((HPT_DPC)hpt_rebuild_data_block, pAdapter, pArray, DUPLICATE);
396 unlock_driver(oldspl);
397 while (!pArray->u.array.rf_rebuilding)
398 {
452#if (__FreeBSD_version > 700033)
453 pause("pause", 1);
454#else
455 tsleep((caddr_t)Kernel_DeviceIoControl, PPAUSE, "pause", 1);
399 tsleep((caddr_t)Kernel_DeviceIoControl, PPAUSE, "pause", 1);
456#endif
457 if ( timeout >= hz*3)
458 break;
459 timeout ++;
460 }
461 }
462 break;
463 }
464 }
465#endif
466 return 0;
467 }
468 }
469
470 if (lpBytesReturned)
471 *lpBytesReturned = nOutBufferSize;
472 return 0;
473}
474
400 if ( timeout >= hz*3)
401 break;
402 timeout ++;
403 }
404 }
405 break;
406 }
407 }
408#endif
409 return 0;
410 }
411 }
412
413 if (lpBytesReturned)
414 *lpBytesReturned = nOutBufferSize;
415 return 0;
416}
417
475static int
476hpt_get_event(PHPT_EVENT pEvent)
418static int hpt_get_event(PHPT_EVENT pEvent)
477{
478 intrmask_t oldspl = lock_driver();
479 int ret = event_queue_remove(pEvent);
480 unlock_driver(oldspl);
481 return ret;
482}
483
419{
420 intrmask_t oldspl = lock_driver();
421 int ret = event_queue_remove(pEvent);
422 unlock_driver(oldspl);
423 return ret;
424}
425
484static int
485hpt_set_array_state(DEVICEID idArray, DWORD state)
426static int hpt_set_array_state(DEVICEID idArray, DWORD state)
486{
487 IAL_ADAPTER_T *pAdapter;
488 PVDevice pVDevice = ID_TO_VDEV(idArray);
489 int i;
490 DWORD timeout = 0;
491 intrmask_t oldspl;
492
427{
428 IAL_ADAPTER_T *pAdapter;
429 PVDevice pVDevice = ID_TO_VDEV(idArray);
430 int i;
431 DWORD timeout = 0;
432 intrmask_t oldspl;
433
493 if(idArray == 0 || check_VDevice_valid(pVDevice)) return -1;
434 if(idArray == HPT_NULL_ID || check_VDevice_valid(pVDevice))
435 return -1;
494 if(!mIsArray(pVDevice))
495 return -1;
496 if(!pVDevice->vf_online || pVDevice->u.array.rf_broken) return -1;
497
498 pAdapter=(IAL_ADAPTER_T *)pVDevice->pVBus->OsExt;
499
500 switch(state)
501 {

--- 11 unchanged lines hidden (view full) ---

513
514 hpt_queue_dpc((HPT_DPC)hpt_rebuild_data_block, pAdapter, pVDevice,
515 (UCHAR)((pVDevice->u.array.CriticalMembers || pVDevice->VDeviceType == VD_RAID_1)? DUPLICATE : REBUILD_PARITY));
516
517 unlock_driver(oldspl);
518
519 while (!pVDevice->u.array.rf_rebuilding)
520 {
436 if(!mIsArray(pVDevice))
437 return -1;
438 if(!pVDevice->vf_online || pVDevice->u.array.rf_broken) return -1;
439
440 pAdapter=(IAL_ADAPTER_T *)pVDevice->pVBus->OsExt;
441
442 switch(state)
443 {

--- 11 unchanged lines hidden (view full) ---

455
456 hpt_queue_dpc((HPT_DPC)hpt_rebuild_data_block, pAdapter, pVDevice,
457 (UCHAR)((pVDevice->u.array.CriticalMembers || pVDevice->VDeviceType == VD_RAID_1)? DUPLICATE : REBUILD_PARITY));
458
459 unlock_driver(oldspl);
460
461 while (!pVDevice->u.array.rf_rebuilding)
462 {
521#if (__FreeBSD_version > 700033)
522 pause("pause", 1);
523#else
524 tsleep((caddr_t)hpt_set_array_state, PPAUSE, "pause", 1);
463 tsleep((caddr_t)hpt_set_array_state, PPAUSE, "pause", 1);
525#endif
526 if ( timeout >= hz*20)
527 break;
528 timeout ++;
529 }
530 }
531
532 break;
533
534 case MIRROR_REBUILD_ABORT:
535 {
536 for(i = 0; i < pVDevice->u.array.bArnMember; i++) {
464 if ( timeout >= hz*20)
465 break;
466 timeout ++;
467 }
468 }
469
470 break;
471
472 case MIRROR_REBUILD_ABORT:
473 {
474 for(i = 0; i < pVDevice->u.array.bArnMember; i++) {
537 if(pVDevice->u.array.pMember[i] != 0 && pVDevice->u.array.pMember[i]->VDeviceType == VD_RAID_1)
475 if(pVDevice->u.array.pMember[i] != NULL && pVDevice->u.array.pMember[i]->VDeviceType == VD_RAID_1)
538 hpt_set_array_state(VDEV_TO_ID(pVDevice->u.array.pMember[i]), state);
539 }
540
541 if(pVDevice->u.array.rf_rebuilding != 1)
542 return -1;
543
544 oldspl = lock_driver();
545 pVDevice->u.array.rf_abort_rebuild = 1;
546 unlock_driver(oldspl);
547
548 while (pVDevice->u.array.rf_abort_rebuild)
549 {
476 hpt_set_array_state(VDEV_TO_ID(pVDevice->u.array.pMember[i]), state);
477 }
478
479 if(pVDevice->u.array.rf_rebuilding != 1)
480 return -1;
481
482 oldspl = lock_driver();
483 pVDevice->u.array.rf_abort_rebuild = 1;
484 unlock_driver(oldspl);
485
486 while (pVDevice->u.array.rf_abort_rebuild)
487 {
550#if (__FreeBSD_version > 700033)
551 pause("pause", 1);
552#else
553 tsleep((caddr_t)hpt_set_array_state, PPAUSE, "pause", 1);
488 tsleep((caddr_t)hpt_set_array_state, PPAUSE, "pause", 1);
554#endif
555 if ( timeout >= hz*20)
556 break;
557 timeout ++;
558 }
559 }
560 break;
561
562 case AS_VERIFY_START:

--- 7 unchanged lines hidden (view full) ---

570
571 oldspl = lock_driver();
572 pVDevice->u.array.RebuildSectors = 0;
573 hpt_queue_dpc((HPT_DPC)hpt_rebuild_data_block, pAdapter, pVDevice, VERIFY);
574 unlock_driver(oldspl);
575
576 while (!pVDevice->u.array.rf_verifying)
577 {
489 if ( timeout >= hz*20)
490 break;
491 timeout ++;
492 }
493 }
494 break;
495
496 case AS_VERIFY_START:

--- 7 unchanged lines hidden (view full) ---

504
505 oldspl = lock_driver();
506 pVDevice->u.array.RebuildSectors = 0;
507 hpt_queue_dpc((HPT_DPC)hpt_rebuild_data_block, pAdapter, pVDevice, VERIFY);
508 unlock_driver(oldspl);
509
510 while (!pVDevice->u.array.rf_verifying)
511 {
578#if (__FreeBSD_version > 700033)
579 pause("pause", 1);
580#else
581 tsleep((caddr_t)hpt_set_array_state, PPAUSE, "pause", 1);
512 tsleep((caddr_t)hpt_set_array_state, PPAUSE, "pause", 1);
582#endif
583 if ( timeout >= hz*20)
584 break;
585 timeout ++;
586 }
587 }
588 break;
589
590 case AS_VERIFY_ABORT:
591 {
592 if(pVDevice->u.array.rf_verifying != 1)
593 return -1;
594
595 oldspl = lock_driver();
596 pVDevice->u.array.rf_abort_rebuild = 1;
597 unlock_driver(oldspl);
598
599 while (pVDevice->u.array.rf_abort_rebuild)
600 {
513 if ( timeout >= hz*20)
514 break;
515 timeout ++;
516 }
517 }
518 break;
519
520 case AS_VERIFY_ABORT:
521 {
522 if(pVDevice->u.array.rf_verifying != 1)
523 return -1;
524
525 oldspl = lock_driver();
526 pVDevice->u.array.rf_abort_rebuild = 1;
527 unlock_driver(oldspl);
528
529 while (pVDevice->u.array.rf_abort_rebuild)
530 {
601#if (__FreeBSD_version > 700033)
602 pause("pause", 1);
603#else
604 tsleep((caddr_t)hpt_set_array_state, PPAUSE, "pause", 1);
531 tsleep((caddr_t)hpt_set_array_state, PPAUSE, "pause", 1);
605#endif
606 if ( timeout >= hz*80)
607 break;
608 timeout ++;
609 }
610 }
611 break;
612
613 case AS_INITIALIZE_START:

--- 4 unchanged lines hidden (view full) ---

618 return -1;
619
620 oldspl = lock_driver();
621 hpt_queue_dpc((HPT_DPC)hpt_rebuild_data_block, pAdapter, pVDevice, VERIFY);
622 unlock_driver(oldspl);
623
624 while (!pVDevice->u.array.rf_initializing)
625 {
532 if ( timeout >= hz*80)
533 break;
534 timeout ++;
535 }
536 }
537 break;
538
539 case AS_INITIALIZE_START:

--- 4 unchanged lines hidden (view full) ---

544 return -1;
545
546 oldspl = lock_driver();
547 hpt_queue_dpc((HPT_DPC)hpt_rebuild_data_block, pAdapter, pVDevice, VERIFY);
548 unlock_driver(oldspl);
549
550 while (!pVDevice->u.array.rf_initializing)
551 {
626#if (__FreeBSD_version > 700033)
627 pause("pause", 1);
628#else
629 tsleep((caddr_t)hpt_set_array_state, PPAUSE, "pause", 1);
552 tsleep((caddr_t)hpt_set_array_state, PPAUSE, "pause", 1);
630#endif
631 if ( timeout >= hz*80)
632 break;
633 timeout ++;
634 }
635 }
636 break;
637
638 case AS_INITIALIZE_ABORT:
639 {
640 if(pVDevice->u.array.rf_initializing != 1)
641 return -1;
642
643 oldspl = lock_driver();
644 pVDevice->u.array.rf_abort_rebuild = 1;
645 unlock_driver(oldspl);
646
647 while (pVDevice->u.array.rf_abort_rebuild)
648 {
553 if ( timeout >= hz*80)
554 break;
555 timeout ++;
556 }
557 }
558 break;
559
560 case AS_INITIALIZE_ABORT:
561 {
562 if(pVDevice->u.array.rf_initializing != 1)
563 return -1;
564
565 oldspl = lock_driver();
566 pVDevice->u.array.rf_abort_rebuild = 1;
567 unlock_driver(oldspl);
568
569 while (pVDevice->u.array.rf_abort_rebuild)
570 {
649#if (__FreeBSD_version > 700033)
650 pause("pause", 1);
651#else
652 tsleep((caddr_t)hpt_set_array_state, PPAUSE, "pause", 1);
571 tsleep((caddr_t)hpt_set_array_state, PPAUSE, "pause", 1);
653#endif
654 if ( timeout >= hz*80)
655 break;
656 timeout ++;
657 }
658 }
659 break;
660
661 default:
662 return -1;
663 }
664
665 return 0;
666}
667
572 if ( timeout >= hz*80)
573 break;
574 timeout ++;
575 }
576 }
577 break;
578
579 default:
580 return -1;
581 }
582
583 return 0;
584}
585
668int HPTLIBAPI
669R1ControlSgl(_VBUS_ARG PCommand pCmd, FPSCAT_GATH pSgTable, int logical)
586static int HPTLIBAPI R1ControlSgl(_VBUS_ARG PCommand pCmd, FPSCAT_GATH pSgTable, int logical)
670{
671 ULONG bufferSize = SECTOR_TO_BYTE(pCmd->uCmd.R1Control.nSectors);
672 if (pCmd->uCmd.R1Control.Command==CTRL_CMD_VERIFY)
673 bufferSize<<=1;
674 if (logical) {
675 pSgTable->dSgAddress = (ULONG_PTR)pCmd->uCmd.R1Control.Buffer;
676 pSgTable->wSgSize = (USHORT)bufferSize;
677 pSgTable->wSgFlag = SG_FLAG_EOT;

--- 46 unchanged lines hidden (view full) ---

724 idx++;
725
726 }while (bufferSize);
727 }
728 return 1;
729}
730
731static int End_Job=0;
587{
588 ULONG bufferSize = SECTOR_TO_BYTE(pCmd->uCmd.R1Control.nSectors);
589 if (pCmd->uCmd.R1Control.Command==CTRL_CMD_VERIFY)
590 bufferSize<<=1;
591 if (logical) {
592 pSgTable->dSgAddress = (ULONG_PTR)pCmd->uCmd.R1Control.Buffer;
593 pSgTable->wSgSize = (USHORT)bufferSize;
594 pSgTable->wSgFlag = SG_FLAG_EOT;

--- 46 unchanged lines hidden (view full) ---

641 idx++;
642
643 }while (bufferSize);
644 }
645 return 1;
646}
647
648static int End_Job=0;
732void HPTLIBAPI
733thread_io_done(_VBUS_ARG PCommand pCmd)
649static void HPTLIBAPI thread_io_done(_VBUS_ARG PCommand pCmd)
734{
735 End_Job = 1;
736 wakeup((caddr_t)pCmd);
737}
738
650{
651 End_Job = 1;
652 wakeup((caddr_t)pCmd);
653}
654
739void
740hpt_rebuild_data_block(IAL_ADAPTER_T *pAdapter, PVDevice pArray, UCHAR flags)
655void hpt_rebuild_data_block(IAL_ADAPTER_T *pAdapter, PVDevice pArray, UCHAR flags)
741{
742 DWORD timeout = 0;
743 ULONG capacity = pArray->VDeviceCapacity / (pArray->u.array.bArnMember-1);
744 PCommand pCmd;
745 UINT result;
746 int needsync=0, retry=0, needdelete=0;
747 void *buffer = 0;
748 intrmask_t oldspl;

--- 43 unchanged lines hidden (view full) ---

792 pCmd->cf_control = 1;
793 End_Job = 0;
794
795 if (pArray->VDeviceType==VD_RAID_1)
796 {
797 #define MAX_REBUILD_SECTORS 0x40
798
799 /* take care for discontinuous buffer in R1ControlSgl */
656{
657 DWORD timeout = 0;
658 ULONG capacity = pArray->VDeviceCapacity / (pArray->u.array.bArnMember-1);
659 PCommand pCmd;
660 UINT result;
661 int needsync=0, retry=0, needdelete=0;
662 void *buffer = 0;
663 intrmask_t oldspl;

--- 43 unchanged lines hidden (view full) ---

707 pCmd->cf_control = 1;
708 End_Job = 0;
709
710 if (pArray->VDeviceType==VD_RAID_1)
711 {
712 #define MAX_REBUILD_SECTORS 0x40
713
714 /* take care for discontinuous buffer in R1ControlSgl */
800 unlock_driver(oldspl);
801 buffer = malloc(SECTOR_TO_BYTE(MAX_REBUILD_SECTORS), M_DEVBUF, M_NOWAIT);
715 buffer = malloc(SECTOR_TO_BYTE(MAX_REBUILD_SECTORS), M_DEVBUF, M_NOWAIT);
802 oldspl = lock_driver();
803 if(!buffer) {
804 FreeCommand(_VBUS_P pCmd);
805 hpt_printk(("can't allocate rebuild buffer\n"));
806 goto fail;
807 }
808 switch(flags)
809 {
810 case DUPLICATE:

--- 52 unchanged lines hidden (view full) ---

863 if (!End_Job) {
864 hpt_printk(("timeout, reset\n"));
865 fResetVBus(_VBUS_P0);
866 }
867 }
868
869 result = pCmd->Result;
870 FreeCommand(_VBUS_P pCmd);
716 if(!buffer) {
717 FreeCommand(_VBUS_P pCmd);
718 hpt_printk(("can't allocate rebuild buffer\n"));
719 goto fail;
720 }
721 switch(flags)
722 {
723 case DUPLICATE:

--- 52 unchanged lines hidden (view full) ---

776 if (!End_Job) {
777 hpt_printk(("timeout, reset\n"));
778 fResetVBus(_VBUS_P0);
779 }
780 }
781
782 result = pCmd->Result;
783 FreeCommand(_VBUS_P pCmd);
871 unlock_driver(oldspl);
872 if (buffer) free(buffer, M_DEVBUF);
784 if (buffer) free(buffer, M_DEVBUF);
873 oldspl = lock_driver();
874 KdPrintI(("cmd finished %d", result));
875
876 switch(result)
877 {
878 case RETURN_SUCCESS:
879 if (!pArray->u.array.rf_abort_rebuild)
880 {
881 if(pArray->u.array.RebuildSectors < capacity)

--- 114 unchanged lines hidden (view full) ---

996 }
997
998 while (pAdapter->outstandingCommands)
999 {
1000 KdPrintI(("currcmds is %d, wait..\n", pAdapter->outstandingCommands));
1001 /* put this to have driver stop processing system commands quickly */
1002 if (!mWaitingForIdle(_VBUS_P0)) CallWhenIdle(_VBUS_P nothing, 0);
1003 unlock_driver(oldspl);
785 KdPrintI(("cmd finished %d", result));
786
787 switch(result)
788 {
789 case RETURN_SUCCESS:
790 if (!pArray->u.array.rf_abort_rebuild)
791 {
792 if(pArray->u.array.RebuildSectors < capacity)

--- 114 unchanged lines hidden (view full) ---

907 }
908
909 while (pAdapter->outstandingCommands)
910 {
911 KdPrintI(("currcmds is %d, wait..\n", pAdapter->outstandingCommands));
912 /* put this to have driver stop processing system commands quickly */
913 if (!mWaitingForIdle(_VBUS_P0)) CallWhenIdle(_VBUS_P nothing, 0);
914 unlock_driver(oldspl);
1004 /*Schedule out*/
1005#if (__FreeBSD_version < 500000)
1006 YIELD_THREAD;
1007#else
1008#if (__FreeBSD_version > 700033)
1009 pause("switch", 1);
1010#else
1011 tsleep(hpt_rebuild_data_block, PPAUSE, "switch", 1);
1012#endif
1013#endif
1014 oldspl = lock_driver();
1015 }
1016
1017 if (needsync) SyncArrayInfo(pArray);
1018 if(needdelete && (pArray->u.array.rf_duplicate_must_done || (flags == INITIALIZE)))
1019 fDeleteArray(_VBUS_P pArray, TRUE);
1020
1021 Check_Idle_Call(pAdapter);
1022 unlock_driver(oldspl);
1023}
915 oldspl = lock_driver();
916 }
917
918 if (needsync) SyncArrayInfo(pArray);
919 if(needdelete && (pArray->u.array.rf_duplicate_must_done || (flags == INITIALIZE)))
920 fDeleteArray(_VBUS_P pArray, TRUE);
921
922 Check_Idle_Call(pAdapter);
923 unlock_driver(oldspl);
924}