38 #include <sys/types.h>
42 #include <sys/types.h>
43 #include <sys/ioctl.h>
56 #include "elx_pt_ioctl.h"
61 #define ELX_PT_SERIAL_NUM_SIZE 32
81 char path[FILENAME_MAX];
90 dirs[0] = driver_path;
96 ftsp = fts_open(dirs, FTS_COMFOLLOW | FTS_NOCHDIR, NULL);
101 chp = fts_children(ftsp, 0);
114 snprintf(path,
sizeof(path),
"/dev/%s_%d",
"ocs", total);
116 if (rc != 0 && errno != ENOENT) {
117 perror(
"Error removing /dev/ocs*\n");
123 while((ftsent = fts_read(ftsp)) != NULL) {
124 if (ftsent->fts_info != FTS_F) {
127 if (strncmp(ftsent->fts_path,
"/proc/ocs", strlen(
"/proc/ocs"))) {
135 if (strncmp(ftsent->fts_path,
"/proc/ocsu", strlen(
"/proc/ocsu")) == 0) {
139 proc_file = fopen(ftsent->fts_path,
"r");
141 if (proc_file == NULL) {
146 rc = fscanf(proc_file,
"%d,%d", &major, &count);
153 drv = strdup(ftsent->fts_path + strlen(
"/proc/"));
159 if ((p = strchr(drv,
'_'))) {
163 for (idx = 0; idx < count; idx ++) {
164 snprintf(path,
sizeof(path),
"/dev/%s_%d", drv, total);
166 rc = mknod(path, S_IFCHR | 0644, makedev(major, idx));
168 printf(
"Failed creating %s\n", path);
197 struct dirent *entry;
200 char config_file_name[1024];
202 char driver_link_name[1024];
203 char driver_path[1024];
211 pci_dir = opendir(
"/sys/bus/pci/devices");
212 if (pci_dir == NULL) {
228 char device_file_name[256];
233 sprintf(device_file_name,
"/dev/ocs_%d", ocs_index);
234 fd = open(device_file_name, O_RDONLY);
243 bzero(new_device,
sizeof(*new_device));
246 new_device->
next = list;
266 while ((entry = readdir(pci_dir))) {
267 snprintf(config_file_name,
sizeof(config_file_name),
268 "/sys/bus/pci/devices/%s/config", entry->d_name);
269 config_file = open(config_file_name, O_RDWR);
270 if (config_file < 0) {
273 if ((read(config_file, &vendor_id,
sizeof(vendor_id)) <
sizeof(vendor_id)) ||
274 (read(config_file, &device_id,
sizeof(device_id)) <
sizeof(device_id))) {
275 fprintf(stderr ,
"couldn't read vendor ID or device ID");
280 bzero(new_device,
sizeof(*new_device));
283 new_device->
next = list;
287 new_device->
vendor = vendor_id;
288 new_device->
device = device_id;
289 strcpy(new_device->
bus_addr, entry->d_name);
294 snprintf(driver_link_name,
sizeof(driver_link_name),
295 "/sys/bus/pci/devices/%s/driver", entry->d_name);
296 n = readlink(driver_link_name, driver_path,
sizeof(driver_path) - 1);
308 list = new_device->
next;
312 driver_path[n] =
'\0';
313 driver_name = strrchr(driver_path,
'/') + 1;
314 if (strncmp(driver_name,
"ocs_", 4) == 0) {
316 list = new_device->
next;
319 }
else if (strcmp(driver_name,
"elx_pt") == 0) {
321 }
else if (strcmp(driver_name,
"be2net") == 0) {
327 list = new_device->
next;
335 list = new_device->
next;
359 desc = ocsu_open(hostname, devidx);
366 memset(device_p,
'\0',
sizeof(*device_p));
369 "%s[%d]", hostname, devidx);
370 device_p->
desc = desc;
383 device_p->
next = list;
388 ocsu_close(device_p->
desc);
398 char driver_name[80];
401 char dev_file_name[80];
405 elx_pt_ioctl_info_t info;
406 char *serial_num = NULL;
409 proc_file = fopen(
"/proc/devices",
"r");
410 if (proc_file == NULL) {
415 while (fgets(line,
sizeof(line), proc_file)) {
416 if (strstr(line,
"elx_pt")) {
417 sscanf(line,
"%d %s", &i, driver_name);
418 if (strcmp(driver_name,
"elx_pt") == 0) {
430 for (minor=0; minor<
MAXDEVS; minor++) {
432 snprintf(dev_file_name,
sizeof(dev_file_name),
"/dev/elx_pt%d", minor);
433 fd = open(dev_file_name, O_RDWR);
435 if (errno ==
EBUSY) {
440 rc = mknod(dev_file_name, S_IFCHR, makedev(major, minor));
444 fd = open(dev_file_name, O_RDWR);
453 bzero(&info,
sizeof(info));
454 rc = ioctl(fd, IOCTL_CMD_ELX_PT_GET_INFO, &info);
462 if (strcmp(info.bus_addr, device->
bus_addr) == 0) {
464 elx_pt_ioctl_mbox_t mbox;
467 device->
vendor = info.vendor;
468 device->
device = info.device;
469 device->
asic_id = info.asic_id;
473 bzero(&attr,
sizeof(attr));
478 mbox.words = (uint32_t *)&attr;
479 mbox.num_words = (
sizeof(attr) + 3) / 4;
481 rc = ioctl(fd, IOCTL_CMD_ELX_PT_MBOX, &mbox);
492 device->
serialnum = strdup((
char *)serial_num);
523 char path[FILENAME_MAX];
527 if (device == NULL) {
540 if (device->
fd < 0) {
545 if (device->
desc == NULL) {
548 snprintf(path,
sizeof(path),
"%s[%d]", devname->
hostname, devname->
devidx);
559 if (device->
desc != NULL) {
560 rc = ocsu_ioctl(device->
desc, req, arg);
562 rc = ioctl(device->
fd, req, arg);
569 if (device->
desc != NULL) {
570 ocsu_close(device->
desc);
583 #define MAX_CONNECTIONS 256
600 printf(
"No connections found\n");
606 printf(
" Connection ID: 0x%x\n", info[i].connection_id);
607 printf(
" Connection Handle: 0x%x\n", info[i].connection_handle);
608 printf(
" Source Address: %s\n",
610 printf(
" Source Port: %d\n", info[i].source_port);
611 printf(
" Dest Address: %s\n",
613 printf(
" Dest Port: %d\n", info[i].dest_port);
622 if (address_type < 3) {
624 sprintf(ret,
"%d.%d.%d.%d",
631 sprintf(ret,
"%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x",
632 address[0], address[1],
633 address[2], address[3],
634 address[4], address[5],
635 address[6], address[7],
636 address[8], address[9],
637 address[10], address[11],
638 address[12], address[13],
639 address[14], address[15]);
uint8_t controller_serial_number[32]
int is_fc(elxu_device_t *device_p)
Return true IFF the HBA is a FC HBA.
static char * format_ip_address(uint8_t *address, uint8_t address_type)
#define OCS_IOCTL_CMD_CONNECTION_INFO
elxu_device_t * os_build_device_list(char *path)
#define PCI_VENDOR_ID_EMULEX
connection info ioctl structure
void os_close_device(elxu_device_t *device)
Close a device file.
int os_ioctl_device(elxu_device_t *device, int req, void *arg)
Send an ioctl to an open device.
struct elxu_device_struct * next
#define OCS_IOCTL_CMD_DRIVER_INFO
device name specifier This structure is used to describe the type and name of the device ioctl connec...
void * zmalloc(uint32_t len)
Allocates and zeroes memory to be used.
int elxu_ioctl_device(elxu_device_t *device, int req, void *arg)
Send an ioctl to a device.
#define ELX_PT_SERIAL_NUM_SIZE
uint8_t firmware_version_string[32]
uint8_t controller_description[64]
static void pt_device_init(elxu_device_t *device)
static int os_create_device_files(char *driver_path)
void fill_device_details(elxu_device_t *device)
void mbox_get_wwn_pt(int fd, uint8_t *wwnn, uint8_t *wwpn)
#define OPCODE_COMMON_GET_CNTL_ATTRIBUTES
#define MBOX_SUBSYSTEM_COMMON
void elxu_get_connection_info(elxu_device_t *device)
Print iSCSI connection info for the given device.
elxu_device_t * elxu_device_by_index(int index)
Return a pointer to a device given an index.
int is_nic(elxu_device_t *device_p)
Return true IFF the HBA is a NIC HBA.
ocs_ioctl_connection_info_t * connections
int is_iscsi(elxu_device_t *device_p)
Return true IFF the HBA is an iSCSI HBA.
DRIVER_INFO ioctl structure.
void set_protocol(elxu_device_t *device)
void mbox_get_mac_pt(elxu_device_t *device, uint8_t *mac_addr)
elxu_device_t * os_open_device(elxu_device_name_t *devname)
Open a device file.
elxu_device_t * os_build_device_list_uspace(char *hostname)
elxu_device_driver_e driver
char device_file_name[1024]
int mbox_get_serialnum_pt(elxu_device_t *device, char *serial_num, int serial_num_size)
int os_remove_device(elxu_device_t *device)