Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

scsi: qla2xxx: Introduce qla2xxx_get_next_handle()

This patch reduces code duplication.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Bart Van Assche and committed by
Martin K. Petersen
bcc85657 3cb5f3ae

+42 -114
+1
drivers/scsi/qla2xxx/qla_gbl.h
··· 272 272 extern void qla2x00_build_scsi_iocbs_64(srb_t *, cmd_entry_t *, uint16_t); 273 273 extern void qla24xx_build_scsi_iocbs(srb_t *, struct cmd_type_7 *, 274 274 uint16_t, struct req_que *); 275 + extern uint32_t qla2xxx_get_next_handle(struct req_que *req); 275 276 extern int qla2x00_start_scsi(srb_t *sp); 276 277 extern int qla24xx_start_scsi(srb_t *sp); 277 278 int qla2x00_marker(struct scsi_qla_host *, struct qla_qpair *,
+37 -91
drivers/scsi/qla2xxx/qla_iocb.c
··· 292 292 } 293 293 } 294 294 295 + /* 296 + * Find the first handle that is not in use, starting from 297 + * req->current_outstanding_cmd + 1. The caller must hold the lock that is 298 + * associated with @req. 299 + */ 300 + uint32_t qla2xxx_get_next_handle(struct req_que *req) 301 + { 302 + uint32_t index, handle = req->current_outstanding_cmd; 303 + 304 + for (index = 1; index < req->num_outstanding_cmds; index++) { 305 + handle++; 306 + if (handle == req->num_outstanding_cmds) 307 + handle = 1; 308 + if (!req->outstanding_cmds[handle]) 309 + return handle; 310 + } 311 + 312 + return 0; 313 + } 314 + 295 315 /** 296 316 * qla2x00_start_scsi() - Send a SCSI command to the ISP 297 317 * @sp: command to send to the ISP ··· 326 306 scsi_qla_host_t *vha; 327 307 struct scsi_cmnd *cmd; 328 308 uint32_t *clr_ptr; 329 - uint32_t index; 330 309 uint32_t handle; 331 310 cmd_entry_t *cmd_pkt; 332 311 uint16_t cnt; ··· 358 339 /* Acquire ring specific lock */ 359 340 spin_lock_irqsave(&ha->hardware_lock, flags); 360 341 361 - /* Check for room in outstanding command list. */ 362 - handle = req->current_outstanding_cmd; 363 - for (index = 1; index < req->num_outstanding_cmds; index++) { 364 - handle++; 365 - if (handle == req->num_outstanding_cmds) 366 - handle = 1; 367 - if (!req->outstanding_cmds[handle]) 368 - break; 369 - } 370 - if (index == req->num_outstanding_cmds) 342 + handle = qla2xxx_get_next_handle(req); 343 + if (handle == 0) 371 344 goto queuing_error; 372 345 373 346 /* Map the sg table so we have an accurate count of sg entries needed */ ··· 1595 1584 int nseg; 1596 1585 unsigned long flags; 1597 1586 uint32_t *clr_ptr; 1598 - uint32_t index; 1599 1587 uint32_t handle; 1600 1588 struct cmd_type_7 *cmd_pkt; 1601 1589 uint16_t cnt; ··· 1622 1612 /* Acquire ring specific lock */ 1623 1613 spin_lock_irqsave(&ha->hardware_lock, flags); 1624 1614 1625 - /* Check for room in outstanding command list. */ 1626 - handle = req->current_outstanding_cmd; 1627 - for (index = 1; index < req->num_outstanding_cmds; index++) { 1628 - handle++; 1629 - if (handle == req->num_outstanding_cmds) 1630 - handle = 1; 1631 - if (!req->outstanding_cmds[handle]) 1632 - break; 1633 - } 1634 - if (index == req->num_outstanding_cmds) 1615 + handle = qla2xxx_get_next_handle(req); 1616 + if (handle == 0) 1635 1617 goto queuing_error; 1636 1618 1637 1619 /* Map the sg table so we have an accurate count of sg entries needed */ ··· 1726 1724 int nseg; 1727 1725 unsigned long flags; 1728 1726 uint32_t *clr_ptr; 1729 - uint32_t index; 1730 1727 uint32_t handle; 1731 1728 uint16_t cnt; 1732 1729 uint16_t req_cnt = 0; ··· 1766 1765 /* Acquire ring specific lock */ 1767 1766 spin_lock_irqsave(&ha->hardware_lock, flags); 1768 1767 1769 - /* Check for room in outstanding command list. */ 1770 - handle = req->current_outstanding_cmd; 1771 - for (index = 1; index < req->num_outstanding_cmds; index++) { 1772 - handle++; 1773 - if (handle == req->num_outstanding_cmds) 1774 - handle = 1; 1775 - if (!req->outstanding_cmds[handle]) 1776 - break; 1777 - } 1778 - 1779 - if (index == req->num_outstanding_cmds) 1768 + handle = qla2xxx_get_next_handle(req); 1769 + if (handle == 0) 1780 1770 goto queuing_error; 1781 1771 1782 1772 /* Compute number of required data segments */ ··· 1912 1920 int nseg; 1913 1921 unsigned long flags; 1914 1922 uint32_t *clr_ptr; 1915 - uint32_t index; 1916 1923 uint32_t handle; 1917 1924 struct cmd_type_7 *cmd_pkt; 1918 1925 uint16_t cnt; ··· 1942 1951 vha->marker_needed = 0; 1943 1952 } 1944 1953 1945 - /* Check for room in outstanding command list. */ 1946 - handle = req->current_outstanding_cmd; 1947 - for (index = 1; index < req->num_outstanding_cmds; index++) { 1948 - handle++; 1949 - if (handle == req->num_outstanding_cmds) 1950 - handle = 1; 1951 - if (!req->outstanding_cmds[handle]) 1952 - break; 1953 - } 1954 - if (index == req->num_outstanding_cmds) 1954 + handle = qla2xxx_get_next_handle(req); 1955 + if (handle == 0) 1955 1956 goto queuing_error; 1956 1957 1957 1958 /* Map the sg table so we have an accurate count of sg entries needed */ ··· 2047 2064 int nseg; 2048 2065 unsigned long flags; 2049 2066 uint32_t *clr_ptr; 2050 - uint32_t index; 2051 2067 uint32_t handle; 2052 2068 uint16_t cnt; 2053 2069 uint16_t req_cnt = 0; ··· 2101 2119 vha->marker_needed = 0; 2102 2120 } 2103 2121 2104 - /* Check for room in outstanding command list. */ 2105 - handle = req->current_outstanding_cmd; 2106 - for (index = 1; index < req->num_outstanding_cmds; index++) { 2107 - handle++; 2108 - if (handle == req->num_outstanding_cmds) 2109 - handle = 1; 2110 - if (!req->outstanding_cmds[handle]) 2111 - break; 2112 - } 2113 - 2114 - if (index == req->num_outstanding_cmds) 2122 + handle = qla2xxx_get_next_handle(req); 2123 + if (handle == 0) 2115 2124 goto queuing_error; 2116 2125 2117 2126 /* Compute number of required data segments */ ··· 2249 2276 struct qla_hw_data *ha = vha->hw; 2250 2277 struct req_que *req = qpair->req; 2251 2278 device_reg_t *reg = ISP_QUE_REG(ha, req->id); 2252 - uint32_t index, handle; 2279 + uint32_t handle; 2253 2280 request_t *pkt; 2254 2281 uint16_t cnt, req_cnt; 2255 2282 ··· 2289 2316 goto queuing_error; 2290 2317 2291 2318 if (sp) { 2292 - /* Check for room in outstanding command list. */ 2293 - handle = req->current_outstanding_cmd; 2294 - for (index = 1; index < req->num_outstanding_cmds; index++) { 2295 - handle++; 2296 - if (handle == req->num_outstanding_cmds) 2297 - handle = 1; 2298 - if (!req->outstanding_cmds[handle]) 2299 - break; 2300 - } 2301 - if (index == req->num_outstanding_cmds) { 2319 + handle = qla2xxx_get_next_handle(req); 2320 + if (handle == 0) { 2302 2321 ql_log(ql_log_warn, vha, 0x700b, 2303 2322 "No room on outstanding cmd array.\n"); 2304 2323 goto queuing_error; ··· 3077 3112 unsigned long flags; 3078 3113 struct scsi_cmnd *cmd; 3079 3114 uint32_t *clr_ptr; 3080 - uint32_t index; 3081 3115 uint32_t handle; 3082 3116 uint16_t cnt; 3083 3117 uint16_t req_cnt; ··· 3116 3152 /* Acquire ring specific lock */ 3117 3153 spin_lock_irqsave(&ha->hardware_lock, flags); 3118 3154 3119 - /* Check for room in outstanding command list. */ 3120 - handle = req->current_outstanding_cmd; 3121 - for (index = 1; index < req->num_outstanding_cmds; index++) { 3122 - handle++; 3123 - if (handle == req->num_outstanding_cmds) 3124 - handle = 1; 3125 - if (!req->outstanding_cmds[handle]) 3126 - break; 3127 - } 3128 - if (index == req->num_outstanding_cmds) 3155 + handle = qla2xxx_get_next_handle(req); 3156 + if (handle == 0) 3129 3157 goto queuing_error; 3130 3158 3131 3159 /* Map the sg table so we have an accurate count of sg entries needed */ ··· 3725 3769 struct qla_hw_data *ha = vha->hw; 3726 3770 unsigned long flags; 3727 3771 uint32_t handle; 3728 - uint32_t index; 3729 3772 uint16_t req_cnt; 3730 3773 uint16_t cnt; 3731 3774 uint32_t *clr_ptr; ··· 3749 3794 /* Acquire ring specific lock */ 3750 3795 spin_lock_irqsave(&ha->hardware_lock, flags); 3751 3796 3752 - /* Check for room in outstanding command list. */ 3753 - handle = req->current_outstanding_cmd; 3754 - for (index = 1; index < req->num_outstanding_cmds; index++) { 3755 - handle++; 3756 - if (handle == req->num_outstanding_cmds) 3757 - handle = 1; 3758 - if (!req->outstanding_cmds[handle]) 3759 - break; 3760 - } 3761 - 3762 - if (index == req->num_outstanding_cmds) { 3797 + handle = qla2xxx_get_next_handle(req); 3798 + if (handle == 0) { 3763 3799 rval = EXT_STATUS_BUSY; 3764 3800 goto queuing_error; 3765 3801 }
+2 -11
drivers/scsi/qla2xxx/qla_mr.c
··· 3071 3071 { 3072 3072 int nseg; 3073 3073 unsigned long flags; 3074 - uint32_t index; 3075 3074 uint32_t handle; 3076 3075 uint16_t cnt; 3077 3076 uint16_t req_cnt; ··· 3094 3095 /* Acquire ring specific lock */ 3095 3096 spin_lock_irqsave(&ha->hardware_lock, flags); 3096 3097 3097 - /* Check for room in outstanding command list. */ 3098 - handle = req->current_outstanding_cmd; 3099 - for (index = 1; index < req->num_outstanding_cmds; index++) { 3100 - handle++; 3101 - if (handle == req->num_outstanding_cmds) 3102 - handle = 1; 3103 - if (!req->outstanding_cmds[handle]) 3104 - break; 3105 - } 3106 - if (index == req->num_outstanding_cmds) 3098 + handle = qla2xxx_get_next_handle(req); 3099 + if (handle == 0) 3107 3100 goto queuing_error; 3108 3101 3109 3102 /* Map the sg table so we have an accurate count of sg entries needed */
+2 -12
drivers/scsi/qla2xxx/qla_nvme.c
··· 353 353 { 354 354 unsigned long flags; 355 355 uint32_t *clr_ptr; 356 - uint32_t index; 357 356 uint32_t handle; 358 357 struct cmd_nvme *cmd_pkt; 359 358 uint16_t cnt, i; ··· 376 377 /* Acquire qpair specific lock */ 377 378 spin_lock_irqsave(&qpair->qp_lock, flags); 378 379 379 - /* Check for room in outstanding command list. */ 380 - handle = req->current_outstanding_cmd; 381 - for (index = 1; index < req->num_outstanding_cmds; index++) { 382 - handle++; 383 - if (handle == req->num_outstanding_cmds) 384 - handle = 1; 385 - if (!req->outstanding_cmds[handle]) 386 - break; 387 - } 388 - 389 - if (index == req->num_outstanding_cmds) { 380 + handle = qla2xxx_get_next_handle(req); 381 + if (handle == 0) { 390 382 rval = -EBUSY; 391 383 goto queuing_error; 392 384 }