mfi.c (174779) | mfi.c (175897) |
---|---|
1/*- 2 * Copyright (c) 2006 IronPort Systems 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 --- 37 unchanged lines hidden (view full) --- 46 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 48 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * SUCH DAMAGE. 51 */ 52 53#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2006 IronPort Systems 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 --- 37 unchanged lines hidden (view full) --- 46 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 48 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * SUCH DAMAGE. 51 */ 52 53#include <sys/cdefs.h> |
54__FBSDID("$FreeBSD: head/sys/dev/mfi/mfi.c 174779 2007-12-19 17:22:07Z ambrisko $"); | 54__FBSDID("$FreeBSD: head/sys/dev/mfi/mfi.c 175897 2008-02-02 17:29:28Z ambrisko $"); |
55 56#include "opt_mfi.h" 57 58#include <sys/param.h> 59#include <sys/systm.h> 60#include <sys/sysctl.h> 61#include <sys/malloc.h> 62#include <sys/kernel.h> --- 505 unchanged lines hidden (view full) --- 568 uint32_t *hdr_data; 569 570 /* 571 * Zero out the important fields of the frame, but make sure the 572 * context field is preserved. For efficiency, handle the fields 573 * as 32 bit words. Clear out the first S/G entry too for safety. 574 */ 575 hdr = &cm->cm_frame->header; | 55 56#include "opt_mfi.h" 57 58#include <sys/param.h> 59#include <sys/systm.h> 60#include <sys/sysctl.h> 61#include <sys/malloc.h> 62#include <sys/kernel.h> --- 505 unchanged lines hidden (view full) --- 568 uint32_t *hdr_data; 569 570 /* 571 * Zero out the important fields of the frame, but make sure the 572 * context field is preserved. For efficiency, handle the fields 573 * as 32 bit words. Clear out the first S/G entry too for safety. 574 */ 575 hdr = &cm->cm_frame->header; |
576 if (hdr->sg_count) { | 576 if (cm->cm_data != NULL && hdr->sg_count) { |
577 cm->cm_sg->sg32[0].len = 0; 578 cm->cm_sg->sg32[0].addr = 0; 579 } 580 581 hdr_data = (uint32_t *)cm->cm_frame; 582 hdr_data[0] = 0; /* cmd, sense_len, cmd_status, scsi_status */ 583 hdr_data[1] = 0; /* target_id, lun_id, cdb_len, sg_count */ 584 hdr_data[4] = 0; /* flags, timeout */ --- 1502 unchanged lines hidden (view full) --- 2087 2088 /* 2089 * save off original context since copying from user 2090 * will clobber some data 2091 */ 2092 context = cm->cm_frame->header.context; 2093 2094 bcopy(ioc->mfi_frame.raw, cm->cm_frame, | 577 cm->cm_sg->sg32[0].len = 0; 578 cm->cm_sg->sg32[0].addr = 0; 579 } 580 581 hdr_data = (uint32_t *)cm->cm_frame; 582 hdr_data[0] = 0; /* cmd, sense_len, cmd_status, scsi_status */ 583 hdr_data[1] = 0; /* target_id, lun_id, cdb_len, sg_count */ 584 hdr_data[4] = 0; /* flags, timeout */ --- 1502 unchanged lines hidden (view full) --- 2087 2088 /* 2089 * save off original context since copying from user 2090 * will clobber some data 2091 */ 2092 context = cm->cm_frame->header.context; 2093 2094 bcopy(ioc->mfi_frame.raw, cm->cm_frame, |
2095 ioc->mfi_sgl_off); /* Linux can do 2 frames ? */ 2096 cm->cm_total_frame_size = ioc->mfi_sgl_off; 2097 cm->cm_sg = 2098 (union mfi_sgl *)&cm->cm_frame->bytes[ioc->mfi_sgl_off]; 2099 cm->cm_flags = MFI_CMD_DATAIN | MFI_CMD_DATAOUT; | 2095 2 * MFI_DCMD_FRAME_SIZE); /* this isn't quite right */ 2096 cm->cm_total_frame_size = (sizeof(union mfi_sgl) * ioc->mfi_sge_count) + ioc->mfi_sgl_off; 2097 if (ioc->mfi_sge_count) { 2098 cm->cm_sg = 2099 (union mfi_sgl *)&cm->cm_frame->bytes[ioc->mfi_sgl_off]; 2100 } 2101 cm->cm_flags = 0; 2102 if (cm->cm_frame->header.flags & MFI_FRAME_DATAIN) 2103 cm->cm_flags |= MFI_CMD_DATAIN; 2104 if (cm->cm_frame->header.flags & MFI_FRAME_DATAOUT) 2105 cm->cm_flags |= MFI_CMD_DATAOUT; 2106 /* Legacy app shim */ 2107 if (cm->cm_flags == 0) 2108 cm->cm_flags |= MFI_CMD_DATAIN | MFI_CMD_DATAOUT; |
2100 cm->cm_len = cm->cm_frame->header.data_len; | 2109 cm->cm_len = cm->cm_frame->header.data_len; |
2101 cm->cm_data = data = malloc(cm->cm_len, M_MFIBUF, 2102 M_WAITOK | M_ZERO); 2103 if (cm->cm_data == NULL) { 2104 device_printf(sc->mfi_dev, "Malloc failed\n"); 2105 goto out; | 2110 if (cm->cm_flags & (MFI_CMD_DATAIN | MFI_CMD_DATAOUT)) { 2111 cm->cm_data = data = malloc(cm->cm_len, M_MFIBUF, 2112 M_WAITOK | M_ZERO); 2113 if (cm->cm_data == NULL) { 2114 device_printf(sc->mfi_dev, "Malloc failed\n"); 2115 goto out; 2116 } 2117 } else { 2118 cm->cm_data = 0; |
2106 } 2107 2108 /* restore header context */ 2109 cm->cm_frame->header.context = context; 2110 2111 temp = data; | 2119 } 2120 2121 /* restore header context */ 2122 cm->cm_frame->header.context = context; 2123 2124 temp = data; |
2112 for (i = 0; i < ioc->mfi_sge_count; i++) { 2113 error = copyin(ioc->mfi_sgl[i].iov_base, 2114 temp, 2115 ioc->mfi_sgl[i].iov_len); 2116 if (error != 0) { 2117 device_printf(sc->mfi_dev, 2118 "Copy in failed\n"); 2119 goto out; | 2125 if (cm->cm_flags & MFI_CMD_DATAOUT) { 2126 for (i = 0; i < ioc->mfi_sge_count; i++) { 2127 error = copyin(ioc->mfi_sgl[i].iov_base, 2128 temp, 2129 ioc->mfi_sgl[i].iov_len); 2130 if (error != 0) { 2131 device_printf(sc->mfi_dev, 2132 "Copy in failed\n"); 2133 goto out; 2134 } 2135 temp = &temp[ioc->mfi_sgl[i].iov_len]; |
2120 } | 2136 } |
2121 temp = &temp[ioc->mfi_sgl[i].iov_len]; | |
2122 } 2123 2124 if (cm->cm_frame->header.cmd == MFI_CMD_DCMD) 2125 locked = mfi_config_lock(sc, cm->cm_frame->dcmd.opcode); 2126 2127 mtx_lock(&sc->mfi_io_lock); 2128 error = mfi_check_command_pre(sc, cm); 2129 if (error) { --- 7 unchanged lines hidden (view full) --- 2137 mtx_unlock(&sc->mfi_io_lock); 2138 goto out; 2139 } 2140 2141 mfi_check_command_post(sc, cm); 2142 mtx_unlock(&sc->mfi_io_lock); 2143 2144 temp = data; | 2137 } 2138 2139 if (cm->cm_frame->header.cmd == MFI_CMD_DCMD) 2140 locked = mfi_config_lock(sc, cm->cm_frame->dcmd.opcode); 2141 2142 mtx_lock(&sc->mfi_io_lock); 2143 error = mfi_check_command_pre(sc, cm); 2144 if (error) { --- 7 unchanged lines hidden (view full) --- 2152 mtx_unlock(&sc->mfi_io_lock); 2153 goto out; 2154 } 2155 2156 mfi_check_command_post(sc, cm); 2157 mtx_unlock(&sc->mfi_io_lock); 2158 2159 temp = data; |
2145 for (i = 0; i < ioc->mfi_sge_count; i++) { 2146 error = copyout(temp, 2147 ioc->mfi_sgl[i].iov_base, 2148 ioc->mfi_sgl[i].iov_len); 2149 if (error != 0) { 2150 device_printf(sc->mfi_dev, 2151 "Copy out failed\n"); 2152 goto out; | 2160 if (cm->cm_flags & MFI_CMD_DATAIN) { 2161 for (i = 0; i < ioc->mfi_sge_count; i++) { 2162 error = copyout(temp, 2163 ioc->mfi_sgl[i].iov_base, 2164 ioc->mfi_sgl[i].iov_len); 2165 if (error != 0) { 2166 device_printf(sc->mfi_dev, 2167 "Copy out failed\n"); 2168 goto out; 2169 } 2170 temp = &temp[ioc->mfi_sgl[i].iov_len]; |
2153 } | 2171 } |
2154 temp = &temp[ioc->mfi_sgl[i].iov_len]; | |
2155 } 2156 2157 if (ioc->mfi_sense_len) { 2158 /* copy out sense */ 2159 sense_ptr = &((struct mfi_ioc_packet*)arg) 2160 ->mfi_frame.raw[0]; 2161 error = copyout(cm->cm_sense, sense_ptr, 2162 ioc->mfi_sense_len); --- 110 unchanged lines hidden (view full) --- 2273 2274 /* 2275 * save off original context since copying from user 2276 * will clobber some data 2277 */ 2278 context = cm->cm_frame->header.context; 2279 2280 bcopy(l_ioc.lioc_frame.raw, cm->cm_frame, | 2172 } 2173 2174 if (ioc->mfi_sense_len) { 2175 /* copy out sense */ 2176 sense_ptr = &((struct mfi_ioc_packet*)arg) 2177 ->mfi_frame.raw[0]; 2178 error = copyout(cm->cm_sense, sense_ptr, 2179 ioc->mfi_sense_len); --- 110 unchanged lines hidden (view full) --- 2290 2291 /* 2292 * save off original context since copying from user 2293 * will clobber some data 2294 */ 2295 context = cm->cm_frame->header.context; 2296 2297 bcopy(l_ioc.lioc_frame.raw, cm->cm_frame, |
2281 l_ioc.lioc_sgl_off); /* Linux can do 2 frames ? */ 2282 cm->cm_total_frame_size = l_ioc.lioc_sgl_off; 2283 cm->cm_sg = 2284 (union mfi_sgl *)&cm->cm_frame->bytes[l_ioc.lioc_sgl_off]; 2285 cm->cm_flags = MFI_CMD_DATAIN | MFI_CMD_DATAOUT; | 2298 2 * MFI_DCMD_FRAME_SIZE); /* this isn't quite right */ 2299 cm->cm_total_frame_size = (sizeof(union mfi_sgl) * l_ioc.lioc_sge_count) + l_ioc.lioc_sgl_off; 2300 if (l_ioc.lioc_sge_count) 2301 cm->cm_sg = 2302 (union mfi_sgl *)&cm->cm_frame->bytes[l_ioc.lioc_sgl_off]; 2303 cm->cm_flags = 0; 2304 if (cm->cm_frame->header.flags & MFI_FRAME_DATAIN) 2305 cm->cm_flags |= MFI_CMD_DATAIN; 2306 if (cm->cm_frame->header.flags & MFI_FRAME_DATAOUT) 2307 cm->cm_flags |= MFI_CMD_DATAOUT; |
2286 cm->cm_len = cm->cm_frame->header.data_len; | 2308 cm->cm_len = cm->cm_frame->header.data_len; |
2287 cm->cm_data = data = malloc(cm->cm_len, M_MFIBUF, 2288 M_WAITOK | M_ZERO); | 2309 if (cm->cm_flags & (MFI_CMD_DATAIN | MFI_CMD_DATAOUT)) { 2310 cm->cm_data = data = malloc(cm->cm_len, M_MFIBUF, 2311 M_WAITOK | M_ZERO); 2312 if (cm->cm_data == NULL) { 2313 device_printf(sc->mfi_dev, "Malloc failed\n"); 2314 goto out; 2315 } 2316 } else { 2317 cm->cm_data = 0; 2318 } |
2289 2290 /* restore header context */ 2291 cm->cm_frame->header.context = context; 2292 2293 temp = data; | 2319 2320 /* restore header context */ 2321 cm->cm_frame->header.context = context; 2322 2323 temp = data; |
2294 for (i = 0; i < l_ioc.lioc_sge_count; i++) { 2295 temp_convert = 2296 (void *)(uintptr_t)l_ioc.lioc_sgl[i].iov_base; 2297 error = copyin(temp_convert, 2298 temp, 2299 l_ioc.lioc_sgl[i].iov_len); 2300 if (error != 0) { 2301 device_printf(sc->mfi_dev, 2302 "Copy in failed\n"); 2303 goto out; | 2324 if (cm->cm_flags & MFI_CMD_DATAOUT) { 2325 for (i = 0; i < l_ioc.lioc_sge_count; i++) { 2326 temp_convert = 2327 (void *)(uintptr_t)l_ioc.lioc_sgl[i].iov_base; 2328 error = copyin(temp_convert, 2329 temp, 2330 l_ioc.lioc_sgl[i].iov_len); 2331 if (error != 0) { 2332 device_printf(sc->mfi_dev, 2333 "Copy in failed\n"); 2334 goto out; 2335 } 2336 temp = &temp[l_ioc.lioc_sgl[i].iov_len]; |
2304 } | 2337 } |
2305 temp = &temp[l_ioc.lioc_sgl[i].iov_len]; | |
2306 } 2307 2308 if (cm->cm_frame->header.cmd == MFI_CMD_DCMD) 2309 locked = mfi_config_lock(sc, cm->cm_frame->dcmd.opcode); 2310 2311 mtx_lock(&sc->mfi_io_lock); 2312 error = mfi_check_command_pre(sc, cm); 2313 if (error) { --- 7 unchanged lines hidden (view full) --- 2321 mtx_unlock(&sc->mfi_io_lock); 2322 goto out; 2323 } 2324 2325 mfi_check_command_post(sc, cm); 2326 mtx_unlock(&sc->mfi_io_lock); 2327 2328 temp = data; | 2338 } 2339 2340 if (cm->cm_frame->header.cmd == MFI_CMD_DCMD) 2341 locked = mfi_config_lock(sc, cm->cm_frame->dcmd.opcode); 2342 2343 mtx_lock(&sc->mfi_io_lock); 2344 error = mfi_check_command_pre(sc, cm); 2345 if (error) { --- 7 unchanged lines hidden (view full) --- 2353 mtx_unlock(&sc->mfi_io_lock); 2354 goto out; 2355 } 2356 2357 mfi_check_command_post(sc, cm); 2358 mtx_unlock(&sc->mfi_io_lock); 2359 2360 temp = data; |
2329 for (i = 0; i < l_ioc.lioc_sge_count; i++) { 2330 temp_convert = 2331 (void *)(uintptr_t)l_ioc.lioc_sgl[i].iov_base; 2332 error = copyout(temp, 2333 temp_convert, 2334 l_ioc.lioc_sgl[i].iov_len); 2335 if (error != 0) { 2336 device_printf(sc->mfi_dev, 2337 "Copy out failed\n"); 2338 goto out; | 2361 if (cm->cm_flags & MFI_CMD_DATAIN) { 2362 for (i = 0; i < l_ioc.lioc_sge_count; i++) { 2363 temp_convert = 2364 (void *)(uintptr_t)l_ioc.lioc_sgl[i].iov_base; 2365 error = copyout(temp, 2366 temp_convert, 2367 l_ioc.lioc_sgl[i].iov_len); 2368 if (error != 0) { 2369 device_printf(sc->mfi_dev, 2370 "Copy out failed\n"); 2371 goto out; 2372 } 2373 temp = &temp[l_ioc.lioc_sgl[i].iov_len]; |
2339 } | 2374 } |
2340 temp = &temp[l_ioc.lioc_sgl[i].iov_len]; | |
2341 } 2342 2343 if (l_ioc.lioc_sense_len) { 2344 /* copy out sense */ 2345 sense_ptr = &((struct mfi_linux_ioc_packet*)arg) 2346 ->lioc_frame.raw[0]; 2347 error = copyout(cm->cm_sense, sense_ptr, 2348 l_ioc.lioc_sense_len); --- 172 unchanged lines hidden --- | 2375 } 2376 2377 if (l_ioc.lioc_sense_len) { 2378 /* copy out sense */ 2379 sense_ptr = &((struct mfi_linux_ioc_packet*)arg) 2380 ->lioc_frame.raw[0]; 2381 error = copyout(cm->cm_sense, sense_ptr, 2382 l_ioc.lioc_sense_len); --- 172 unchanged lines hidden --- |