📄 sbp2.c
字号:
scsi_id->sbp2_device_type_and_lun = SBP2_DEVICE_TYPE_LUN_UNINITIALIZED; list_add_tail(&scsi_id->list, &scsi_group->scsi_id_list); } /* Update the generic fields in all the LUN's */ list_for_each (lh, &scsi_group->scsi_id_list) { scsi_id = list_entry(lh, struct scsi_id_instance_data, list); scsi_id->sbp2_management_agent_addr = management_agent_addr; scsi_id->sbp2_command_set_spec_id = command_set_spec_id; scsi_id->sbp2_command_set = command_set; scsi_id->sbp2_unit_characteristics = unit_characteristics; scsi_id->sbp2_firmware_revision = firmware_revision; scsi_id->workarounds = workarounds; } }}/* * This function is called in order to determine the max speed and packet * size we can use in our ORBs. Note, that we (the driver and host) only * initiate the transaction. The SBP-2 device actually transfers the data * (by reading from the DMA area we tell it). This means that the SBP-2 * device decides the actual maximum data it can transfer. We just tell it * the speed that it needs to use, and the max_rec the host supports, and * it takes care of the rest. */static int sbp2_max_speed_and_size(struct scsi_id_instance_data *scsi_id){ struct sbp2scsi_host_info *hi = scsi_id->hi; SBP2_DEBUG("sbp2_max_speed_and_size"); /* Initial setting comes from the hosts speed map */ scsi_id->speed_code = hi->host->speed_map[NODEID_TO_NODE(hi->host->node_id) * 64 + NODEID_TO_NODE(scsi_id->ne->nodeid)]; /* Bump down our speed if the user requested it */ if (scsi_id->speed_code > sbp2_max_speed) { scsi_id->speed_code = sbp2_max_speed; SBP2_ERR("Forcing SBP-2 max speed down to %s", hpsb_speedto_str[scsi_id->speed_code]); } /* Payload size is the lesser of what our speed supports and what * our host supports. */ scsi_id->max_payload_size = min(sbp2_speedto_max_payload[scsi_id->speed_code], (u8)(((be32_to_cpu(hi->host->csr.rom[2]) >> 12) & 0xf) - 1)); SBP2_ERR("Node " NODE_BUS_FMT ": Max speed [%s] - Max payload [%u]", NODE_BUS_ARGS(hi->host, scsi_id->ne->nodeid), hpsb_speedto_str[scsi_id->speed_code], 1 << ((u32)scsi_id->max_payload_size + 2)); return(0);}/* * This function is called in order to perform a SBP-2 agent reset. */static int sbp2_agent_reset(struct scsi_id_instance_data *scsi_id, int wait) { struct sbp2scsi_host_info *hi = scsi_id->hi; struct hpsb_packet *packet; quadlet_t data; SBP2_DEBUG("sbp2_agent_reset"); /* * Ok, let's write to the target's management agent register */ data = ntohl(SBP2_AGENT_RESET_DATA); packet = sbp2util_allocate_write_packet(hi, scsi_id->ne, scsi_id->sbp2_command_block_agent_addr + SBP2_AGENT_RESET_OFFSET, 4, &data, wait ? 0 : 1); if (!packet) { SBP2_ERR("sbp2util_allocate_write_packet failed"); return(-ENOMEM); } if (!hpsb_send_packet(packet)) { SBP2_ERR("hpsb_send_packet failed"); sbp2_free_packet(packet); return(-EIO); } if (wait) { down(&packet->state_change); down(&packet->state_change); sbp2_free_packet(packet); } /* * Need to make sure orb pointer is written on next command */ scsi_id->last_orb = NULL; return(0);}/* * This function is called to create the actual command orb and s/g list * out of the scsi command itself. */static int sbp2_create_command_orb(struct scsi_id_instance_data *scsi_id, struct sbp2_command_info *command, unchar *scsi_cmd, unsigned int scsi_use_sg, unsigned int scsi_request_bufflen, void *scsi_request_buffer, unsigned char scsi_dir){ struct sbp2scsi_host_info *hi = scsi_id->hi; struct scatterlist *sgpnt = (struct scatterlist *) scsi_request_buffer; struct sbp2_command_orb *command_orb = &command->command_orb; struct sbp2_unrestricted_page_table *scatter_gather_element = &command->scatter_gather_element[0]; int dma_dir = scsi_to_pci_dma_dir (scsi_dir); u32 sg_count, sg_len, orb_direction; dma_addr_t sg_addr; int i; /* * Set-up our command ORB.. * * NOTE: We're doing unrestricted page tables (s/g), as this is * best performance (at least with the devices I have). This means * that data_size becomes the number of s/g elements, and * page_size should be zero (for unrestricted). */ command_orb->next_ORB_hi = ORB_SET_NULL_PTR(1); command_orb->next_ORB_lo = 0x0; command_orb->misc = ORB_SET_MAX_PAYLOAD(scsi_id->max_payload_size); command_orb->misc |= ORB_SET_SPEED(scsi_id->speed_code); command_orb->misc |= ORB_SET_NOTIFY(1); /* Notify us when complete */ /* * Get the direction of the transfer. If the direction is unknown, then use our * goofy table as a back-up. */ switch (scsi_dir) { case SCSI_DATA_NONE: orb_direction = ORB_DIRECTION_NO_DATA_TRANSFER; break; case SCSI_DATA_WRITE: orb_direction = ORB_DIRECTION_WRITE_TO_MEDIA; break; case SCSI_DATA_READ: orb_direction = ORB_DIRECTION_READ_FROM_MEDIA; break; case SCSI_DATA_UNKNOWN: default: SBP2_ERR("SCSI data transfer direction not specified. " "Update the SBP2 direction table in sbp2.h if " "necessary for your application"); print_command (scsi_cmd); orb_direction = sbp2scsi_direction_table[*scsi_cmd]; break; } /* * Set-up our pagetable stuff... unfortunately, this has become * messier than I'd like. Need to clean this up a bit. ;-) */ if (orb_direction == ORB_DIRECTION_NO_DATA_TRANSFER) { SBP2_DEBUG("No data transfer"); /* * Handle no data transfer */ command_orb->data_descriptor_hi = 0x0; command_orb->data_descriptor_lo = 0x0; command_orb->misc |= ORB_SET_DIRECTION(1); } else if (scsi_use_sg) { SBP2_DEBUG("Use scatter/gather"); /* * Special case if only one element (and less than 64KB in size) */ if ((scsi_use_sg == 1) && (sgpnt[0].length <= SBP2_MAX_SG_ELEMENT_LENGTH)) { SBP2_DEBUG("Only one s/g element"); command->dma_dir = dma_dir; command->dma_size = sgpnt[0].length; command->dma_type = CMD_DMA_PAGE; command->cmd_dma = pci_map_page(hi->host->pdev, sgpnt[0].page, sgpnt[0].offset, command->dma_size, command->dma_dir); SBP2_DMA_ALLOC("single page scatter element"); command_orb->data_descriptor_hi = ORB_SET_NODE_ID(hi->host->node_id); command_orb->data_descriptor_lo = command->cmd_dma; command_orb->misc |= ORB_SET_DATA_SIZE(command->dma_size); command_orb->misc |= ORB_SET_DIRECTION(orb_direction); } else { int count = pci_map_sg(hi->host->pdev, sgpnt, scsi_use_sg, dma_dir); SBP2_DMA_ALLOC("scatter list"); command->dma_size = scsi_use_sg; command->dma_dir = dma_dir; command->sge_buffer = sgpnt; /* use page tables (s/g) */ command_orb->misc |= ORB_SET_PAGE_TABLE_PRESENT(0x1); command_orb->misc |= ORB_SET_DIRECTION(orb_direction); command_orb->data_descriptor_hi = ORB_SET_NODE_ID(hi->host->node_id); command_orb->data_descriptor_lo = command->sge_dma; /* * Loop through and fill out our sbp-2 page tables * (and split up anything too large) */ for (i = 0, sg_count = 0 ; i < count; i++, sgpnt++) { sg_len = sg_dma_len(sgpnt); sg_addr = sg_dma_address(sgpnt); while (sg_len) { scatter_gather_element[sg_count].segment_base_lo = sg_addr; if (sg_len > SBP2_MAX_SG_ELEMENT_LENGTH) { scatter_gather_element[sg_count].length_segment_base_hi = PAGE_TABLE_SET_SEGMENT_LENGTH(SBP2_MAX_SG_ELEMENT_LENGTH); sg_addr += SBP2_MAX_SG_ELEMENT_LENGTH; sg_len -= SBP2_MAX_SG_ELEMENT_LENGTH; } else { scatter_gather_element[sg_count].length_segment_base_hi = PAGE_TABLE_SET_SEGMENT_LENGTH(sg_len); sg_len = 0; } sg_count++; } } /* Number of page table (s/g) elements */ command_orb->misc |= ORB_SET_DATA_SIZE(sg_count); sbp2util_packet_dump(scatter_gather_element, (sizeof(struct sbp2_unrestricted_page_table)) * sg_count, "sbp2 s/g list", command->sge_dma); /* * Byte swap page tables if necessary */ sbp2util_cpu_to_be32_buffer(scatter_gather_element, (sizeof(struct sbp2_unrestricted_page_table)) * sg_count); } } else { SBP2_DEBUG("No scatter/gather"); command->dma_dir = dma_dir; command->dma_size = scsi_request_bufflen; command->dma_type = CMD_DMA_SINGLE; command->cmd_dma = pci_map_single (hi->host->pdev, scsi_request_buffer, command->dma_size, command->dma_dir); SBP2_DMA_ALLOC("single bulk"); /* * Handle case where we get a command w/o s/g enabled (but * check for transfers larger than 64K) */ if (scsi_request_bufflen <= SBP2_MAX_SG_ELEMENT_LENGTH) { command_orb->data_descriptor_hi = ORB_SET_NODE_ID(hi->host->node_id); command_orb->data_descriptor_lo = command->cmd_dma; command_orb->misc |= ORB_SET_DATA_SIZE(scsi_request_bufflen); command_orb->misc |= ORB_SET_DIRECTION(orb_direction); /* * Sanity, in case our direction table is not * up-to-date */ if (!scsi_request_bufflen) { command_orb->data_descriptor_hi = 0x0; command_orb->data_descriptor_lo = 0x0; command_orb->misc |= ORB_SET_DIRECTION(1); } } else { /* * Need to turn this into page tables, since the * buffer is too large. */ command_orb->data_descriptor_hi = ORB_SET_NODE_ID(hi->host->node_id); command_orb->data_descriptor_lo = command->sge_dma; /* Use page tables (s/g) */ command_orb->misc |= ORB_SET_PAGE_TABLE_PRESENT(0x1); command_orb->misc |= ORB_SET_DIRECTION(orb_direction); /* * fill out our sbp-2 page tables (and split up * the large buffer) */ sg_count = 0; sg_len = scsi_request_bufflen; sg_addr = command->cmd_dma; while (sg_len) { scatter_gather_element[sg_count].segment_base_lo = sg_addr; if (sg_len > SBP2_MAX_SG_ELEMENT_LENGTH) { scatter_gather_element[sg_count].length_segment_base_hi = PAGE_TABLE_SET_SEGMENT_LENGTH(SBP2_MAX_SG_ELEMENT_LENGTH); sg_addr += SBP2_MAX_SG_ELEMENT_LENGTH; sg_len -= SBP2_MAX_SG_ELEMENT_LENGTH; } else { scatter_gather_element[sg_count].length_segment_base_hi = PAGE_TABLE_SET_SEGMENT_LENGTH(sg_len); sg_len = 0; } sg_count++; } /* Number of page table (s/g) elements */ command_orb->misc |= ORB_SET_DATA_SIZE(sg_count); sbp2util_packet_dump(scatter_gather_element, (sizeof(struct sbp2_unrestricted_page_table)) * sg_count, "sbp2 s/g list", command->sge_dma); /* * Byte swap page tables if necessary */ sbp2util_cpu_to_be32_buffer(scatter_gather_element, (sizeof(struct sbp2_unrestricted_page_table)) * sg_count); } } /* * Byte swap command ORB if necessary */ sbp2util_cpu_to_be32_buffer(command_orb, sizeof(struct sbp2_command_orb)); /* * Put our scsi command in the command ORB */ memset(command_orb->cdb, 0, 12); memcpy(command_orb->cdb, scsi_cmd, COMMAND_SIZE(*scsi_cmd)); return(0);} /* * This function is called in order to begin a regular SBP-2 command. */static int sbp2_link_orb_command(struct scsi_id_instance_data *scsi_id, struct sbp2_command_info *command){ struct sbp2scsi_host_info *hi = scsi_id->hi; struct hpsb_packet *packet; struct sbp2_command_orb *command_orb = &command->command_orb; outstanding_orb_incr; SBP2_ORB_DEBUG("sending command orb %p, total orbs = %x", command_orb, global_outstanding_command_orbs); pci_dma_sync_single(hi->host->pdev, command->command_orb_dma, sizeof(struct sbp2_command_orb), PCI_DMA_BIDIRECTIONAL); pci_dma_sync_single(hi->host->pdev, command->sge_dma, sizeof(command->scatter_gather_element), PCI_DMA_BIDIRECTIONAL); /* * Check to see if there are any previous orbs to use */ if (scsi_id->last_orb == NULL) { /* * Ok, let's write to the target's management agent register */ if (hpsb_node_entry_valid(scsi_id->ne)) { packet = sbp2util_allocate_write_packet(hi, scsi_id->ne, scsi_id->sbp2_command_block_agent_addr + SBP2_ORB_POINTER_OFFSET, 8, NULL, 1); if (!packet) { SBP2_ERR("sbp2util_allocate_write_packet failed"); return(-ENOMEM); } packet->data[0] = ORB_SET_NODE_ID(hi->host->node_id); packet->data[1] = command->command_orb_dma; sbp2util_cpu_to_be32_buffer(packet->data, 8); SBP2_ORB_DEBUG("write command agent, command orb %p", command_orb); if (!hpsb_send_packet(packet)) { SBP2_ERR("hpsb_send_packet failed"); sbp2_free_packet(packet); return(-EIO); } SBP2_ORB_DEBUG("write command agent complete"); } scsi_id->last_orb = command_orb; scsi_id->last_orb_dma = command->command_orb_dma; } else { /* * We have an orb already sent (maybe or maybe not * processed) that we can append this orb to. So do so, * and ring the doorbell. Have to be very careful * modifying these next orb pointers, as they are accessed * both by the sbp2 device and us. */ scsi_id->last_orb->next_ORB_lo = cpu_to_be32(command->command_orb_dma); /* Tells hardware that this pointer is valid */ scsi_id->las
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -