isp_library.c (201758) | isp_library.c (203444) |
---|---|
1/*- 2 * Copyright (c) 1997-2009 by Matthew Jacob 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 * --- 21 unchanged lines hidden (view full) --- 30 */ 31#ifdef __NetBSD__ 32#include <sys/cdefs.h> 33__KERNEL_RCSID(0, "$NetBSD$"); 34#include <dev/ic/isp_netbsd.h> 35#endif 36#ifdef __FreeBSD__ 37#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1997-2009 by Matthew Jacob 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 * --- 21 unchanged lines hidden (view full) --- 30 */ 31#ifdef __NetBSD__ 32#include <sys/cdefs.h> 33__KERNEL_RCSID(0, "$NetBSD$"); 34#include <dev/ic/isp_netbsd.h> 35#endif 36#ifdef __FreeBSD__ 37#include <sys/cdefs.h> |
38__FBSDID("$FreeBSD: head/sys/dev/isp/isp_library.c 201758 2010-01-07 21:01:37Z mbr $"); | 38__FBSDID("$FreeBSD: head/sys/dev/isp/isp_library.c 203444 2010-02-03 21:09:32Z mjacob $"); |
39#include <dev/isp/isp_freebsd.h> 40#endif 41#ifdef __OpenBSD__ 42#include <dev/ic/isp_openbsd.h> 43#endif 44#ifdef __linux__ 45#include "isp_linux.h" 46#endif --- 194 unchanged lines hidden (view full) --- 241 if (isp->isp_dblev & ISP_LOGDEBUG1) { 242 isp_print_bytes(isp, "first queue entry", QENTRY_LEN, fqe); 243 } 244 ISP_ADD_REQUEST(isp, nxt); 245 return (CMD_QUEUED); 246} 247 248int | 39#include <dev/isp/isp_freebsd.h> 40#endif 41#ifdef __OpenBSD__ 42#include <dev/ic/isp_openbsd.h> 43#endif 44#ifdef __linux__ 45#include "isp_linux.h" 46#endif --- 194 unchanged lines hidden (view full) --- 241 if (isp->isp_dblev & ISP_LOGDEBUG1) { 242 isp_print_bytes(isp, "first queue entry", QENTRY_LEN, fqe); 243 } 244 ISP_ADD_REQUEST(isp, nxt); 245 return (CMD_QUEUED); 246} 247 248int |
249isp_save_xs(ispsoftc_t *isp, XS_T *xs, uint32_t *handlep) | 249isp_allocate_xs(ispsoftc_t *isp, XS_T *xs, uint32_t *handlep) |
250{ | 250{ |
251 uint16_t i, j; | 251 isp_hdl_t *hdp; |
252 | 252 |
253 for (j = isp->isp_lasthdls, i = 0; i < isp->isp_maxcmds; i++) { 254 if (isp->isp_xflist[j] == NULL) { 255 break; 256 } 257 if (++j == isp->isp_maxcmds) { 258 j = 0; 259 } 260 } 261 if (i == isp->isp_maxcmds) { | 253 hdp = isp->isp_xffree; 254 if (hdp == NULL) { |
262 return (-1); 263 } | 255 return (-1); 256 } |
264 isp->isp_xflist[j] = xs; 265 *handlep = j+1; 266 if (++j == isp->isp_maxcmds) { 267 j = 0; 268 } 269 isp->isp_lasthdls = (uint32_t)j; | 257 isp->isp_xffree = hdp->cmd; 258 hdp->cmd = xs; 259 hdp->handle = (hdp - isp->isp_xflist); 260 hdp->handle |= (ISP_HANDLE_INITIATOR << ISP_HANDLE_USAGE_SHIFT); 261 hdp->handle |= (isp->isp_seqno++ << ISP_HANDLE_SEQ_SHIFT); 262 *handlep = hdp->handle; |
270 return (0); 271} 272 273XS_T * 274isp_find_xs(ispsoftc_t *isp, uint32_t handle) 275{ | 263 return (0); 264} 265 266XS_T * 267isp_find_xs(ispsoftc_t *isp, uint32_t handle) 268{ |
276 if (handle < 1 || handle > (uint32_t) isp->isp_maxcmds) { | 269 if (!ISP_VALID_INI_HANDLE(isp, handle)) { 270 isp_prt(isp, ISP_LOGERR, "%s: bad handle 0x%x", __func__, handle); |
277 return (NULL); | 271 return (NULL); |
278 } else { 279 return (isp->isp_xflist[handle - 1]); | |
280 } | 272 } |
273 return (isp->isp_xflist[(handle & ISP_HANDLE_CMD_MASK)].cmd); |
|
281} 282 283uint32_t 284isp_find_handle(ispsoftc_t *isp, XS_T *xs) 285{ | 274} 275 276uint32_t 277isp_find_handle(ispsoftc_t *isp, XS_T *xs) 278{ |
286 uint16_t i; | 279 uint32_t i, foundhdl = ISP_HANDLE_FREE; 280 |
287 if (xs != NULL) { 288 for (i = 0; i < isp->isp_maxcmds; i++) { | 281 if (xs != NULL) { 282 for (i = 0; i < isp->isp_maxcmds; i++) { |
289 if (isp->isp_xflist[i] == xs) { 290 return ((uint32_t) (i+1)); | 283 if (isp->isp_xflist[i].cmd != xs) { 284 continue; |
291 } | 285 } |
286 foundhdl = isp->isp_xflist[i].handle; 287 break; |
|
292 } 293 } | 288 } 289 } |
294 return (0); | 290 return (foundhdl); |
295} 296 297uint32_t | 291} 292 293uint32_t |
298isp_handle_index(uint32_t handle) | 294isp_handle_index(ispsoftc_t *isp, uint32_t handle) |
299{ | 295{ |
300 return (handle - 1); | 296 if (!ISP_VALID_HANDLE(isp, handle)) { 297 return (handle & ISP_HANDLE_CMD_MASK); 298 } else { 299 isp_prt(isp, ISP_LOGERR, "%s: bad handle 0x%x", __func__, handle); 300 return (ISP_BAD_HANDLE_INDEX); 301 } |
301} 302 303void 304isp_destroy_handle(ispsoftc_t *isp, uint32_t handle) 305{ | 302} 303 304void 305isp_destroy_handle(ispsoftc_t *isp, uint32_t handle) 306{ |
306 if (handle > 0 && handle <= (uint32_t) isp->isp_maxcmds) { 307 isp->isp_xflist[handle - 1] = NULL; | 307 if (!ISP_VALID_INI_HANDLE(isp, handle)) { 308 isp_prt(isp, ISP_LOGERR, "%s: bad handle 0x%x", __func__, handle); 309 } else { 310 isp->isp_xflist[(handle & ISP_HANDLE_CMD_MASK)].handle = ISP_HANDLE_FREE; 311 isp->isp_xflist[(handle & ISP_HANDLE_CMD_MASK)].cmd = isp->isp_xffree; 312 isp->isp_xffree = &isp->isp_xflist[(handle & ISP_HANDLE_CMD_MASK)]; |
308 } 309} 310 311/* 312 * Make sure we have space to put something on the request queue. 313 * Return a pointer to that entry if we do. A side effect of this 314 * function is to update the output index. The input index 315 * stays the same. --- 296 unchanged lines hidden (view full) --- 612 } else { 613 return (EINVAL); 614 } 615} 616 617void 618isp_clear_commands(ispsoftc_t *isp) 619{ | 313 } 314} 315 316/* 317 * Make sure we have space to put something on the request queue. 318 * Return a pointer to that entry if we do. A side effect of this 319 * function is to update the output index. The input index 320 * stays the same. --- 296 unchanged lines hidden (view full) --- 617 } else { 618 return (EINVAL); 619 } 620} 621 622void 623isp_clear_commands(ispsoftc_t *isp) 624{ |
620 XS_T *xs; 621 uint32_t tmp, handle; | 625 uint32_t tmp; 626 isp_hdl_t *hdp; |
622#ifdef ISP_TARGET_MODE 623 isp_notify_t notify; 624#endif 625 626 for (tmp = 0; isp->isp_xflist && tmp < isp->isp_maxcmds; tmp++) { | 627#ifdef ISP_TARGET_MODE 628 isp_notify_t notify; 629#endif 630 631 for (tmp = 0; isp->isp_xflist && tmp < isp->isp_maxcmds; tmp++) { |
627 xs = isp->isp_xflist[tmp]; 628 if (xs == NULL) { | 632 XS_T *xs; 633 634 hdp = &isp->isp_xflist[tmp]; 635 if (hdp->handle == ISP_HANDLE_FREE) { |
629 continue; 630 } | 636 continue; 637 } |
631 handle = isp_find_handle(isp, xs); 632 if (handle == 0) { 633 continue; 634 } | 638 xs = hdp->cmd; |
635 if (XS_XFRLEN(xs)) { | 639 if (XS_XFRLEN(xs)) { |
636 ISP_DMAFREE(isp, xs, handle); | 640 ISP_DMAFREE(isp, xs, hdp->handle); |
637 XS_SET_RESID(xs, XS_XFRLEN(xs)); 638 } else { 639 XS_SET_RESID(xs, 0); 640 } | 641 XS_SET_RESID(xs, XS_XFRLEN(xs)); 642 } else { 643 XS_SET_RESID(xs, 0); 644 } |
641 isp_destroy_handle(isp, handle); | 645 hdp->handle = 0; 646 hdp->cmd = NULL; |
642 XS_SETERR(xs, HBA_BUSRESET); 643 isp_done(xs); 644 } 645#ifdef ISP_TARGET_MODE 646 for (tmp = 0; isp->isp_tgtlist && tmp < isp->isp_maxcmds; tmp++) { 647 uint8_t local[QENTRY_LEN]; | 647 XS_SETERR(xs, HBA_BUSRESET); 648 isp_done(xs); 649 } 650#ifdef ISP_TARGET_MODE 651 for (tmp = 0; isp->isp_tgtlist && tmp < isp->isp_maxcmds; tmp++) { 652 uint8_t local[QENTRY_LEN]; |
648 649 xs = isp->isp_tgtlist[tmp]; 650 if (xs == NULL) { | 653 hdp = &isp->isp_tgt_xflist[tmp]; 654 if (hdp->handle == ISP_HANDLE_FREE) { |
651 continue; 652 } | 655 continue; 656 } |
653 handle = isp_find_tgt_handle(isp, xs); 654 if (handle == 0) { 655 continue; 656 } 657 ISP_DMAFREE(isp, xs, handle); 658 | 657 ISP_DMAFREE(isp, hdp->cmd, hdp->handle); |
659 ISP_MEMZERO(local, QENTRY_LEN); 660 if (IS_24XX(isp)) { 661 ct7_entry_t *ctio = (ct7_entry_t *) local; | 658 ISP_MEMZERO(local, QENTRY_LEN); 659 if (IS_24XX(isp)) { 660 ct7_entry_t *ctio = (ct7_entry_t *) local; |
662 ctio->ct_syshandle = handle; | 661 ctio->ct_syshandle = hdp->handle; |
663 ctio->ct_nphdl = CT_HBA_RESET; 664 ctio->ct_header.rqs_entry_type = RQSTYPE_CTIO7; 665 } else if (IS_FC(isp)) { 666 ct2_entry_t *ctio = (ct2_entry_t *) local; | 662 ctio->ct_nphdl = CT_HBA_RESET; 663 ctio->ct_header.rqs_entry_type = RQSTYPE_CTIO7; 664 } else if (IS_FC(isp)) { 665 ct2_entry_t *ctio = (ct2_entry_t *) local; |
667 ctio->ct_syshandle = handle; | 666 ctio->ct_syshandle = hdp->handle; |
668 ctio->ct_status = CT_HBA_RESET; 669 ctio->ct_header.rqs_entry_type = RQSTYPE_CTIO2; 670 } else { 671 ct_entry_t *ctio = (ct_entry_t *) local; 672 ctio->ct_syshandle = handle & 0xffff; 673 ctio->ct_status = CT_HBA_RESET & 0xff; 674 ctio->ct_header.rqs_entry_type = RQSTYPE_CTIO; 675 } --- 1548 unchanged lines hidden (view full) --- 2224 if (isp->isp_dblev & ISP_LOGTDEBUG1) { 2225 isp_print_bytes(isp, "first queue entry", QENTRY_LEN, fqe); 2226 } 2227 ISP_ADD_REQUEST(isp, nxt); 2228 return (CMD_QUEUED); 2229} 2230 2231int | 667 ctio->ct_status = CT_HBA_RESET; 668 ctio->ct_header.rqs_entry_type = RQSTYPE_CTIO2; 669 } else { 670 ct_entry_t *ctio = (ct_entry_t *) local; 671 ctio->ct_syshandle = handle & 0xffff; 672 ctio->ct_status = CT_HBA_RESET & 0xff; 673 ctio->ct_header.rqs_entry_type = RQSTYPE_CTIO; 674 } --- 1548 unchanged lines hidden (view full) --- 2223 if (isp->isp_dblev & ISP_LOGTDEBUG1) { 2224 isp_print_bytes(isp, "first queue entry", QENTRY_LEN, fqe); 2225 } 2226 ISP_ADD_REQUEST(isp, nxt); 2227 return (CMD_QUEUED); 2228} 2229 2230int |
2232isp_save_xs_tgt(ispsoftc_t *isp, void *xs, uint32_t *handlep) | 2231isp_allocate_xs_tgt(ispsoftc_t *isp, void *xs, uint32_t *handlep) |
2233{ | 2232{ |
2234 int i; | 2233 isp_hdl_t *hdp; |
2235 | 2234 |
2236 for (i = 0; i < (int) isp->isp_maxcmds; i++) { 2237 if (isp->isp_tgtlist[i] == NULL) { 2238 break; 2239 } 2240 } 2241 if (i == isp->isp_maxcmds) { | 2235 hdp = isp->isp_tgtfree; 2236 if (hdp == NULL) { |
2242 return (-1); 2243 } | 2237 return (-1); 2238 } |
2244 isp->isp_tgtlist[i] = xs; 2245 *handlep = (i+1) | 0x8000; | 2239 isp->isp_tgtfree = hdp->cmd; 2240 hdp->cmd = xs; 2241 hdp->handle = (hdp - isp->isp_tgtlist); 2242 hdp->handle |= (ISP_HANDLE_TARGET << ISP_HANDLE_USAGE_SHIFT); 2243 hdp->handle |= (isp->isp_seqno++ << ISP_HANDLE_SEQ_SHIFT); 2244 *handlep = hdp->handle; |
2246 return (0); 2247} 2248 2249void * 2250isp_find_xs_tgt(ispsoftc_t *isp, uint32_t handle) 2251{ | 2245 return (0); 2246} 2247 2248void * 2249isp_find_xs_tgt(ispsoftc_t *isp, uint32_t handle) 2250{ |
2252 if (handle == 0 || IS_TARGET_HANDLE(handle) == 0 || (handle & ISP_HANDLE_MASK) > isp->isp_maxcmds) { 2253 isp_prt(isp, ISP_LOGERR, "bad handle %u in isp_find_xs_tgt", handle); | 2251 if (!ISP_VALID_TGT_HANDLE(isp, handle)) { 2252 isp_prt(isp, ISP_LOGERR, "%s: bad handle 0x%x", __func__, handle); |
2254 return (NULL); | 2253 return (NULL); |
2255 } else { 2256 return (isp->isp_tgtlist[(handle & ISP_HANDLE_MASK) - 1]); | |
2257 } | 2254 } |
2255 return (isp->isp_tgtlist[(handle & ISP_HANDLE_CMD_MASK)].cmd); |
|
2258} 2259 2260uint32_t 2261isp_find_tgt_handle(ispsoftc_t *isp, void *xs) 2262{ | 2256} 2257 2258uint32_t 2259isp_find_tgt_handle(ispsoftc_t *isp, void *xs) 2260{ |
2263 int i; | 2261 uint32_t i, foundhdl = ISP_HANDLE_FREE; 2262 |
2264 if (xs != NULL) { 2265 for (i = 0; i < isp->isp_maxcmds; i++) { | 2263 if (xs != NULL) { 2264 for (i = 0; i < isp->isp_maxcmds; i++) { |
2266 if (isp->isp_tgtlist[i] == xs) { 2267 uint32_t handle = i; 2268 handle += 1; 2269 handle &= ISP_HANDLE_MASK; 2270 handle |= 0x8000; 2271 return (handle); | 2265 if (isp->isp_tgtlist[i].cmd != xs) { 2266 continue; |
2272 } | 2267 } |
2268 foundhdl = isp->isp_tgtlist[i].handle; 2269 break; |
|
2273 } 2274 } | 2270 } 2271 } |
2275 return (0); | 2272 return (foundhdl); |
2276} 2277 2278void 2279isp_destroy_tgt_handle(ispsoftc_t *isp, uint32_t handle) 2280{ | 2273} 2274 2275void 2276isp_destroy_tgt_handle(ispsoftc_t *isp, uint32_t handle) 2277{ |
2281 if (handle == 0 || IS_TARGET_HANDLE(handle) == 0 || (handle & ISP_HANDLE_MASK) > isp->isp_maxcmds) { 2282 isp_prt(isp, ISP_LOGERR, "bad handle in isp_destroy_tgt_handle"); | 2278 if (!ISP_VALID_TGT_HANDLE(handle)) { 2279 isp_prt(isp, ISP_LOGERR, "%s: bad handle 0x%x", __func__, handle); |
2283 } else { | 2280 } else { |
2284 isp->isp_tgtlist[(handle & ISP_HANDLE_MASK) - 1] = NULL; | 2281 isp->isp_tgtlist[(handle & ISP_HANDLE_CMD_MASK)].handle = ISP_HANDLE_FREE; 2282 isp->isp_tgtlist[(handle & ISP_HANDLE_CMD_MASK)].cmd = isp->isp_tgtfree; 2283 isp->isp_tgtfree = &isp->isp_tgtlist[(handle & ISP_HANDLE_CMD_MASK)]; |
2285 } 2286} 2287 2288/* 2289 * Find target mode entries 2290 */ 2291int 2292isp_find_pdb_by_wwn(ispsoftc_t *isp, int chan, uint64_t wwn, fcportdb_t **lptr) --- 1518 unchanged lines hidden --- | 2284 } 2285} 2286 2287/* 2288 * Find target mode entries 2289 */ 2290int 2291isp_find_pdb_by_wwn(ispsoftc_t *isp, int chan, uint64_t wwn, fcportdb_t **lptr) --- 1518 unchanged lines hidden --- |