45 #include <sys/ioctl.h>
53 #include "elx_pt_ioctl.h"
55 #define MIN(x, y) ((x) < (y) ? (x) : (y))
66 typedef struct device_type_info_s {
82 typedef struct device_protocol_info_s {
99 typedef struct pci_device_map_s {
141 for (i=0; i<argc; i++) {
142 if ((i >= (argc-1)) || (path && hostname))
144 if (strcmp(argv[i],
"--host") == 0){
145 hostname = argv[i+1];
147 if (strcmp(argv[i],
"--path") == 0){
153 if (hostname != NULL) {
172 next = current->
next;
176 if (current->
desc == NULL) {
178 if (rc && (current->
fd != -1)) {
218 if (device != NULL) {
230 for (i=0; i<
ARRAY_SIZE(pci_device_map); i++) {
233 device->
type = pci_device_map[i].
type;
267 if (strlen(input) != 18) {
272 for (i=0; i<8; i++) {
277 output[i] = strtoul(buf, NULL, 0);
291 if (strlen(input) != 17) {
296 for (i=0; i<6; i++) {
301 output[i] = strtoul(buf, NULL, 0);
386 return device->
fwrev;
497 static char result[80];
501 strncpy(result,
"Lancer A0",
sizeof(result));
504 strncpy(result,
"Lancer B0",
sizeof(result));
507 strncpy(result,
"Unknown",
sizeof(result));
528 static char result[80];
538 switch (asic_id & 0xff00) {
540 strncpy (result,
"Skyhawk-R",
sizeof(result));
543 strncpy (result,
"Corsair",
sizeof(result));
546 strncpy (result,
"Lancer",
sizeof(result));
549 strncpy(result,
"Unknown",
sizeof(result));
553 strncat(result,
" ", 1);
556 sprintf(temp,
"%c", (((asic_id & 0x00f0) >> 4) +
'A'));
557 strncat(result, temp, 1);
559 sprintf(temp,
"%d", (asic_id & 0x000f));
560 strncat(result, temp, 1);
604 char *device_type_string =
"Unknown";
605 char *protocol_string =
"Unknown";
606 static char result[80];
609 for (i=0;i<
ARRAY_SIZE(device_type_info);i++) {
610 if (device_type_info[i].type == device->
type) {
611 device_type_string = device_type_info[i].
name;
616 for (i=0;i<
ARRAY_SIZE(device_protocol_info);i++) {
617 if (device_protocol_info[i].protocol == device->
protocol) {
618 protocol_string = device_protocol_info[i].
name;
623 sprintf(result,
"%s %s", device_type_string, protocol_string);
644 static char result[80];
666 static char result[80];
694 for (i=0; i<argc; i++) {
695 if (strcmp(argv[i],
"-d") == 0) {
698 index = strtoul(argv[i+1], NULL, 10);
705 while (device != NULL) {
709 device = device->
next;
735 while (device != NULL) {
739 device = device->
next;
767 static char result[1024];
774 if (strcmp(key,
"/ocs/businfo") == 0) {
778 if (strlen(result) == 0) {
779 printf(
"*** elxu_device_get_value called for non-OCS driver for key \"%s\"\n", key);
788 uint8_t *tx_buf = NULL;
789 uint8_t *rx_buf = NULL;
792 if (tx_buf == NULL) {
793 printf(
"%s: failed to allocate TX buffer\n", __func__);
795 goto exit_lancer_run_loopback;
801 tx_buf[i] = (
char)i & 0xFF;
803 rx_buf = malloc(LOOPBACK_BUF_SIZE);
804 if (rx_buf == NULL) {
805 printf(
"%s: failed to allocate RX buffer\n", __func__);
807 goto exit_lancer_run_loopback;
809 memset(rx_buf, 0, LOOPBACK_BUF_SIZE);
812 rc =
elxu_device_exec(device_p,
"/ocs/driver/link_loopback", tx_buf, LOOPBACK_BUF_SIZE, rx_buf, LOOPBACK_BUF_SIZE);
815 tx_buf, LOOPBACK_BUF_SIZE, rx_buf, LOOPBACK_BUF_SIZE);
817 printf(
"Invalid loopback type\n");
827 rc = memcmp(tx_buf, rx_buf, LOOPBACK_BUF_SIZE);
830 printf(
"Data comparision b/w tx and rx buf is failed\n");
835 exit_lancer_run_loopback:
848 rc =
elxu_device_exec(device_p,
"/ocs/driver/set_loopback", type, 4, NULL, 0);
851 printf(
"%s: failed to set loopback mode\n", __func__);
861 rc =
elxu_device_exec(device_p,
"/ocs/driver/get_link_state", NULL, 0, status,
sizeof(uint32_t));
863 printf(
"%s: Get link status mbox command failed\n", __func__);
872 rc =
elxu_device_exec(device_p,
"/ocs/driver/set_link_state", status,
sizeof(uint32_t), NULL, 0);
874 printf(
"%s: Set link status mbox command failed\n", __func__);
883 elx_pt_ioctl_mbox_t mbox;
886 if (num_buffers > 1) {
887 uint32_t sge_size = num_buffers *
sizeof(
sli4_sge_t);
893 if (dma_sge == NULL) {
894 printf(
"%s: failed to allocate dma memory\n", __func__);
897 memset(dma_sge->
vaddr, 0, sge_size);
898 sge = dma_sge->
vaddr;
900 for (i = 0; i < num_buffers; i++) {
901 sge[i].buffer_address_high =
addr32_hi(dump_buffers[i]->paddr);
902 sge[i].buffer_address_low =
addr32_lo(dump_buffers[i]->paddr);
903 sge[i].last = (i == num_buffers - 1 ? 1 : 0);
904 sge[i].buffer_length = dump_buffers[i]->
size;
907 bzero(&req,
sizeof(req));
916 mbox.words = (uint32_t *)&req;
917 mbox.num_words = (
sizeof(req) +
sizeof(
mbox_hbd_t) + 3) / 4;
918 rc = ioctl(device->
fd, IOCTL_CMD_ELX_PT_MBOX, &mbox);
920 printf(
"%s: IOCTL is failed\n", __func__);
953 void* arg_out,
int arg_out_len)
958 return mgmt_exec(device, name, arg_in, arg_in_len,
959 arg_out, arg_out_len);
963 if (strcmp(name,
"/ocs/driver/gendump") == 0) {
974 if (strcmp(name,
"/ocs/driver/dump_to_host") == 0) {
976 #define ELX_PT_MAX_DMA_ALLOC 64*1024
979 uint32_t rem_bytes, i, offset;
985 if ((arg_out_len == 0) || (arg_out == NULL)) {
986 printf(
"%s: Input buffer is invalid\n", __func__);
991 dma_buffers = malloc(
sizeof(
memref_t *) * num_buffers);
992 if (dma_buffers == NULL) {
993 printf(
"%s: failed to allocate dma_buffers memory\n", __func__);
998 rem_bytes = arg_out_len;
999 for (i = 0; i < num_buffers; i++) {
1002 if (dma_buffers[i] == NULL) {
1003 printf(
"%s: failed to allocate dma memory %d\n", __func__,i);
1005 goto free_and_return;
1007 rem_bytes -= num_bytes;
1016 for (i = 0; i < num_buffers; i++) {
1017 memcpy((uint8_t *)arg_out + offset, dma_buffers[i]->vaddr, dma_buffers[i]->size);
1018 offset += dma_buffers[i]->
size;
1022 for (i = 0; i < num_buffers; i++) {
1029 if (strcmp(name,
"/ocs/firmware_write") == 0) {
1037 elx_pt_ioctl_mbox_t mbox;
1038 int change_status = 0;
1041 #define FW_BUFFER_SIZE 64*1024
1049 if (dma_buffer == NULL) {
1054 remaining = arg_in_len;
1060 mbox.words = (uint32_t *)&req;
1061 mbox.num_words = (
sizeof(req) + 3) / 4;
1064 while (remaining > 0) {
1067 memcpy(dma_buffer->
vaddr, chunk_p, chunk_size);
1070 bzero(&req,
sizeof(req));
1087 rc = ioctl(device->
fd, IOCTL_CMD_ELX_PT_MBOX, &mbox);
1096 printf(
"WRITE_OBJECT returned status %d\n", rsp->
status);
1101 chunk_p += chunk_size;
1102 remaining -= chunk_size;
1108 printf(
"."); fflush(stdout);
1113 snprintf(arg_out, arg_out_len,
"%d", change_status);
1121 printf(
"*** elxu_device_exec called for non-OCS driver for function \"%s\"\n", name);
1133 for (i=0; i<
ARRAY_SIZE(pci_device_map); i++) {
1136 device->
type = pci_device_map[i].
type;
uint16_t subsystem_device
uint32_t object_name[OBJECT_NAME_LENGTH]
uint32_t buffer_address_low
const char * elxu_get_vendor_name(elxu_device_t *device)
Return the vendor name for a device.
memref_t * elx_pt_dma_alloc(elxu_device_t *device, int size)
Request a DMA allocation through elx_pt.
#define PCI_DEVICE_ID_LANCER_FCOE
char * elxu_get_modeldesc(elxu_device_t *device)
Return the model description for a device.
uint32_t elxu_get_asic_id(elxu_device_t *device)
Return the ASIC ID value for a device.
int is_fc(elxu_device_t *device_p)
Return true IFF the HBA is a FC HBA.
static elxu_device_t * device_list
int elxu_device_exec(elxu_device_t *device, char *name, void *arg_in, int arg_in_len, void *arg_out, int arg_out_len)
Execute a management function on a device.
static uint32_t addr32_lo(uintptr_t addr)
uint32_t buffer_address_high
elxu_device_t * os_build_device_list(char *path)
elxu_device_protocol_e protocol
#define PCI_VENDOR_ID_EMULEX
int elx_pt_set_dump_location(elxu_device_t *device, uint32_t num_buffers, memref_t **dump_buffers, uint8_t fdb)
#define PCI_DEVICE_ID_PRISM
elxu_device_t * elxu_device_from_args(int argc, char *argv[])
Return a pointer to a device based on command line args.
int mgmt_exec(elxu_device_t *device, char *name, void *arg_in, int arg_in_len, void *arg_out, int arg_out_len)
#define PCI_DEVICE_ID_SKYHAWK_FCOE
void os_close_device(elxu_device_t *device)
Close a device file.
#define PCI_DEVICE_ID_LANCER_G6
char * elxu_get_ipl(elxu_device_t *device)
Return the IPL version for a device.
int os_ioctl_device(elxu_device_t *device, int req, void *arg)
Send an ioctl to an open device.
int elxu_lancer_set_link_state(elxu_device_t *device_p, uint32_t *status)
struct elxu_device_struct * next
uint32_t device_buffer_descriptor_count
device name specifier This structure is used to describe the type and name of the device ioctl connec...
int is_lancer_g5(elxu_device_t *device_p)
Return true IFF the HBA is a Lancer G5.
static void dev_parse_wwn(char *, uint8_t *)
int elxu_lancer_set_loopback(elxu_device_t *device_p, const char *fname, int *type)
#define PCI_DEVICE_ID_SKYHAWK_ISCSI_TGT
int is_uspace(elxu_device_t *device_p)
Return true IFF the device is managed by a user space driver.
int elxu_ioctl_device(elxu_device_t *device, int req, void *arg)
Send an ioctl to a device.
int is_lancer(elxu_device_t *device_p)
Return true IFF the HBA is a Lancer.
#define PCI_DEVICE_ID_SKYHAWK_ISCSI_INI
const char * elxu_get_subsystem_vendor(elxu_device_t *device)
Return the PCI subsystem vendor value for a device.
#define INTERNAL_LOOPBACK
static device_protocol_info_t device_protocol_info[]
static device_type_info_t device_type_info[]
void fill_device_details(elxu_device_t *device)
mbox_hbd_t device_buffer_descriptor[1]
#define MBOX_SUBSYSTEM_COMMON
char * elxu_get_serialnumber(elxu_device_t *device)
Return the serial number for a device.
const char * elxu_get_device_name(elxu_device_t *device)
Return the device name for a device.
#define OPCODE_COMMON_WRITE_OBJECT
uint32_t elxu_get_phy_port_num(elxu_device_t *device)
Return the physical port number for a device.
#define PCI_VENDOR_ID_ATTO
int is_skyhawk(elxu_device_t *device_p)
Return true IFF the HBA is a Skyhawk.
int is_fcoe(elxu_device_t *device_p)
Return true IFF the HBA is a FCoE HBA.
elxu_device_t * elxu_device_by_index(int index)
Return a pointer to a device given an index.
#define PCI_DEVICE_ID_LANCER_FC
int is_nic(elxu_device_t *device_p)
Return true IFF the HBA is a NIC HBA.
char * elxu_device_get_value(elxu_device_t *device, char *key)
Return a property value for a device.
pci_device_map_t pci_device_map[]
elxu_device_protocol_e protocol
void elxu_build_device_list(int argc, char *argv[])
Create a list of devices.
#define OPCODE_COMMON_SET_DUMP_LOCATION
#define ELX_PT_MAX_DMA_ALLOC
elxu_device_t * elxu_open_device(elxu_device_name_t *devname)
Open a device file.
uint32_t elxu_get_sliintf(elxu_device_t *device)
Return the sli_intf value for a device.
void elxu_close_device(elxu_device_t *device)
Close a device.
int is_iscsi(elxu_device_t *device_p)
Return true IFF the HBA is an iSCSI HBA.
void set_protocol(elxu_device_t *device)
void elxu_delete_device_list()
int mbox_fw_reset_pt(elxu_device_t *device, int dd)
#define LOOPBACK_BUF_SIZE
int is_prism(elxu_device_t *device_p)
Return true IFF the HBA is a Prism.
static uint32_t addr32_hi(uintptr_t addr)
elxu_device_t * os_open_device(elxu_device_name_t *devname)
Open a device file.
char * elxu_get_fwrev(elxu_device_t *device)
Return the firmware revision for a device.
char * elxu_decode_family(uint32_t family)
Lookup a family name.
uint32_t desired_write_length
#define PCI_DEVICE_ID_SKYHAWK_NIC
void elx_pt_dma_free(memref_t *memref)
Free a DMA allocation through elx_pt.
int elxu_lancer_run_loopback(elxu_device_t *device_p, const char *fname, int type)
elxu_device_protocol_e protocol
elxu_device_t * os_build_device_list_uspace(char *hostname)
static void dev_parse_mac(char *, uint8_t *)
int elxu_lancer_get_link_state(elxu_device_t *device_p, uint32_t *status)
elxu_device_driver_e driver
#define EXTERNAL_LOOPBACK
char device_file_name[1024]
const char * elxu_get_subsystem_device(elxu_device_t *device)
Return the PCI subsystem device value for a device.
int is_calypso(elxu_device_t *device_p)
Return true IFF the HBA is a Calypso.
char * elxu_decode_asic_id(uint32_t asic_id)
Lookup an ASIC ID name.
uint16_t subsystem_vendor
#define PCI_DEVICE_ID_LANCER_G6_ATTO
#define PCI_DEVICE_ID_LANCER_NIC
int os_remove_device(elxu_device_t *device)
char * mgmt_get_value(elxu_device_t *device, char *name)