-/**
- * qla2x00_ms_req_pkt() - Retrieve a Management Server request packet from
- * the request ring.
- * @ha: HA context
- * @sp: pointer to handle post function call
- *
- * Note: The caller must hold the hardware lock before calling this routine.
- *
- * Returns NULL if function failed, else, a pointer to the request packet.
- */
-request_t *
-qla2x00_ms_req_pkt(scsi_qla_host_t *ha, srb_t *sp)
-{
- device_reg_t *reg = ha->iobase;
- request_t *pkt = NULL;
- uint16_t cnt, i, index;
- uint32_t *dword_ptr;
- uint32_t timer;
- uint8_t found = 0;
- uint16_t req_cnt = 1;
-
- /* Wait 1 second for slot. */
- for (timer = HZ; timer; timer--) {
- if ((req_cnt + 2) >= ha->req_q_cnt) {
- /* Calculate number of free request entries. */
- cnt = qla2x00_debounce_register(ISP_REQ_Q_OUT(ha, reg));
- if (ha->req_ring_index < cnt) {
- ha->req_q_cnt = cnt - ha->req_ring_index;
- } else {
- ha->req_q_cnt = REQUEST_ENTRY_CNT -
- (ha->req_ring_index - cnt);
- }
- }
-
- /* Check for room in outstanding command list. */
- cnt = ha->current_outstanding_cmd;
- for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) {
- cnt++;
- if (cnt == MAX_OUTSTANDING_COMMANDS)
- cnt = 1;
-
- if (ha->outstanding_cmds[cnt] == 0) {
- found = 1;
- ha->current_outstanding_cmd = cnt;
- break;
- }
- }
-
- /* If room for request in request ring. */
- if (found && (req_cnt + 2) < ha->req_q_cnt) {
- pkt = ha->request_ring_ptr;
-
- /* Zero out packet. */
- dword_ptr = (uint32_t *)pkt;
- for (i = 0; i < REQUEST_ENTRY_SIZE / 4; i++ )
- *dword_ptr++ = 0;
-
- DEBUG5(printk("%s(): putting sp=%p in "
- "outstanding_cmds[%x]\n",
- __func__,
- sp, cnt));
-
- ha->outstanding_cmds[cnt] = sp;
-
- /* save the handle */
- sp->cmd->host_scribble = (unsigned char *) (u_long) cnt;
- CMD_SP(sp->cmd) = (void *)sp;
-
- ha->req_q_cnt--;
- pkt->handle = (uint32_t)cnt;
-
- /* Set system defined field. */
- pkt->sys_define = (uint8_t)ha->req_ring_index;
- pkt->entry_status = 0;
-
- break;
- }
-
- /* Release ring specific lock */
- spin_unlock(&ha->hardware_lock);
- udelay(20);
-
- /* Check for pending interrupts. */
- qla2x00_poll(ha);
-
- spin_lock_irq(&ha->hardware_lock);
- }
- if (!pkt) {
- DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
- }
-
- return (pkt);
-}
-