-
-#if 0
-/*
- * qla2x00_get_lun_mask_from_config
- * Get lun mask from the configuration parameters.
- * Bit order is little endian.
- *
- * Input:
- * ha -- Host adapter
- * tgt -- target/device number
- * port -- pointer to port
- */
-static void
-qla2x00_get_lun_mask_from_config(scsi_qla_host_t *ha,
- fc_port_t *fcport, uint16_t tgt, uint16_t dev_no)
-{
- char propbuf[60]; /* size of search string */
- int rval, lun, bit;
- lun_bit_mask_t lun_mask, *mask_ptr = &lun_mask;
-
- /* Get "target-N-device-N-lun-mask" as a 256 bit lun_mask*/
- sprintf(propbuf, "scsi-qla%ld-tgt-%d-di-%d-lun-disabled",
- ha->instance, tgt, dev_no);
-
- rval = qla2x00_get_prop_xstr(ha, propbuf,
- (uint8_t *)&lun_mask, sizeof(lun_bit_mask_t));
- if (rval == sizeof(lun_bit_mask_t)) {
- memset(&fcport->lun_mask, 0, sizeof(lun_bit_mask_t));
- for (lun = 8 * sizeof(lun_bit_mask_t) - 1, bit = 0;
- lun >= 0; lun--, bit++) {
- if (EXT_IS_LUN_BIT_SET(mask_ptr, lun))
- EXT_SET_LUN_BIT((&fcport->lun_mask), bit);
- }
-
- DEBUG3(printk("scsi(%ld): returning lun mask for fcport "
- "%02x%02x%02x%02x%02x%02x%02x%02x:\n",
- ha->host_no,
- fcport->port_name[0], fcport->port_name[1],
- fcport->port_name[2], fcport->port_name[3],
- fcport->port_name[4], fcport->port_name[5],
- fcport->port_name[6], fcport->port_name[7]));
- DEBUG3(qla2x00_dump_buffer((uint8_t *)&fcport->lun_mask,
- sizeof(lun_bit_mask_t));)
- }
-}
-#endif
-
-/*
- * qla2x00_bstr_to_hex
- * Convert hex byte string to number.
- *
- * Input:
- * s = byte string pointer.
- * bp = byte pointer for number.
- * size = number of bytes.
- *
- * Context:
- * Kernel/Interrupt context.
- */
-static int
-qla2x00_bstr_to_hex(char *s, uint8_t *bp, int size)
-{
- int cnt;
- uint8_t n;
-
- for (cnt = 0; *s != '\0' && cnt / 2 < size; cnt++) {
- if (*s >= 'A' && *s <= 'F') {
- n = (*s++ - 'A') + 10;
- } else if (*s >= 'a' && *s <= 'f') {
- n = (*s++ - 'a') + 10;
- } else if (*s >= '0' && *s <= '9') {
- n = *s++ - '0';
- } else {
- cnt = 0;
- break;
- }
-
- if (cnt & BIT_0)
- *bp++ |= n;
- else
- *bp = n << 4;
- }
-
- /* fixme(dg) Need to swap data little endian */
-
- return (cnt / 2);
-}
-
-/*
- * qla2x00_get_prop_xstr
- * Get a string property value for the specified property name and
- * convert from the property string found in the configuration file,
- * which are ASCII characters representing nibbles, 2 characters represent
- * the hexdecimal value for a byte in the byte array.
- * The byte array is initialized to zero.
- * The resulting converted value is in big endian format (MSB at byte0).
- *
- * Input:
- * ha = adapter state pointer.
- * propname = property name pointer.
- * propval = pointer where to store converted property val.
- * size = max or expected size of 'propval' array.
- *
- * Returns:
- * 0 = empty value string or invalid character in string
- * >0 = count of characters converted
- * -1 = property not found
- *
- * Context:
- * Kernel context.
- */
-int
-qla2x00_get_prop_xstr(scsi_qla_host_t *ha,
- char *propname, uint8_t *propval, int size)
-{
- char *propstr;
- int rval = -1;
- static char buf[LINESIZE];
-
- /* Get the requested property string */
- rval = qla2x00_find_propname(ha, propname, buf, ha->cmdline, size*2);
- DEBUG3(printk("%s(): Ret rval from find propname = %d\n",
- __func__,
- rval);)
-
- propstr = &buf[0];
- if (*propstr == '=')
- propstr++; /* ignore equal sign */
-
- if (rval == 0) { /* not found */
- return (-1);
- }
-
- rval = qla2x00_bstr_to_hex(propstr, (uint8_t *)propval, size);
- if (rval == 0) {
- /* Invalid character in value string */
- qla_printk(KERN_INFO, ha,
- "%s(): %s Invalid hex string for property\n",
- __func__,
- propname);
- qla_printk(KERN_INFO, ha,
- " Invalid string - %s\n",
- propstr);
- }
-
- return (rval);
-}
-
-/*
- * qla2x00_find_propname
- * Get property in database.
- *
- * Input:
- * ha = adapter structure pointer.
- * db = pointer to database
- * propstr = pointer to dest array for string
- * propname = name of property to search for.
- * siz = size of property
- *
- * Returns:
- * 0 = no property
- * size = index of property
- *
- * Context:
- * Kernel context.
- */
-static int
-qla2x00_find_propname(scsi_qla_host_t *ha,
- char *propname, char *propstr,
- char *db, int siz)
-{
- char *cp;
-
- /* find the specified string */
- if (db) {
- /* find the property name */
- if ((cp = strstr(db,propname)) != NULL) {
- while ((*cp) && *cp != '=')
- cp++;
- if (*cp) {
- strncpy(propstr, cp, siz+1);
- propstr[siz+1] = '\0';
- DEBUG(printk("qla2x00_find_propname: found "
- "property = {%s}\n",
- propstr);)
- return (siz); /* match */
- }
- }
- }
-
- return (0);
-}
-
-#if 0
-/*
- * qla2x00_get_prop_16chars
- * Get an 8-byte property value for the specified property name by
- * converting from the property string found in the configuration file.
- * The resulting converted value is in big endian format (MSB at byte0).
- *
- * Input:
- * ha = adapter state pointer.
- * propname = property name pointer.
- * propval = pointer to location for the converted property val.
- * db = pointer to database
- *
- * Returns:
- * 0 = value returned successfully.
- *
- * Context:
- * Kernel context.
- */
-static int
-qla2x00_get_prop_16chars(scsi_qla_host_t *ha,
- char *propname, char *propval, char *db)
-{
- char *propstr;
- int i, k;
- int rval;
- uint8_t nval;
- uint8_t *pchar;
- uint8_t *ret_byte;
- uint8_t *tmp_byte;
- uint8_t *retval = (uint8_t*)propval;
- uint8_t tmpval[8] = {0, 0, 0, 0, 0, 0, 0, 0};
- uint16_t max_byte_cnt = 8; /* 16 chars = 8 bytes */
- uint16_t max_strlen = 16;
- static char buf[LINESIZE];
-
- rval = qla2x00_find_propname(ha, propname, buf, db, max_strlen);
-
- propstr = &buf[0];
- if (*propstr == '=')
- propstr++; /* ignore equal sign */
-
- if (rval == 0) {
- return (1);
- }
-
- /* Convert string to numbers. */
- pchar = (uint8_t *)propstr;
- tmp_byte = (uint8_t *)tmpval;
-
- rval = 0;
- for (i = 0; i < max_strlen; i++) {
- /*
- * Check for invalid character, two at a time,
- * then convert them starting with first byte.
- */
-
- if ((pchar[i] >= '0') && (pchar[i] <= '9')) {
- nval = pchar[i] - '0';
- } else if ((pchar[i] >= 'A') && (pchar[i] <= 'F')) {
- nval = pchar[i] - 'A' + 10;
- } else if ((pchar[i] >= 'a') && (pchar[i] <= 'f')) {
- nval = pchar[i] - 'a' + 10;
- } else {
- /* invalid character */
- rval = 1;
- break;
- }
-
- if (i & BIT_0) {
- *tmp_byte = *tmp_byte | nval;
- tmp_byte++;
- } else {
- *tmp_byte = *tmp_byte | nval << 4;
- }
- }
-
- if (rval != 0) {
- /* Encountered invalid character. */
- return (rval);
- }
-
- /* Copy over the converted value. */
- ret_byte = retval;
- tmp_byte = tmpval;
-
- i = max_byte_cnt;
- k = 0;
- while (i--) {
- *ret_byte++ = *tmp_byte++;
- }
-
- /* big endian retval[0]; */
- return (0);
-}
-
-/*
-* qla2x00_get_properties
-* Find all properties for the specified adapeter in
-* command line.
-*
-* Input:
-* ha = adapter block pointer.
-* cmdline = pointer to command line string
-*
-* Context:
-* Kernel context.
-*/
-static void
-qla2x00_get_properties(scsi_qla_host_t *ha, char *cmdline)
-{
- int rval;
- static char propbuf[LINESIZE];
- uint8_t fc_name[8];
-
- /* Adapter FC node names. */
- sprintf(propbuf, "scsi-qla%d-adapter-node", (int) ha->instance);
- rval = qla2x00_get_prop_16chars(ha, propbuf, fc_name, cmdline);
- if (rval == QLA_SUCCESS)
- memcpy(ha->init_cb->node_name, fc_name, WWN_SIZE);
-
- /* DG 04/07 check portname of adapter */
- sprintf(propbuf, "scsi-qla%d-adapter-port", (int)ha->instance);
- rval = qla2x00_get_prop_16chars(ha, propbuf, fc_name, cmdline);
- if (rval == QLA_SUCCESS &&
- memcmp(ha->init_cb->port_name, fc_name, WWN_SIZE)) {
- /*
- * Adapter port name is WWN, and cannot be changed.
- * Inform users of the mismatch, then just continue driver
- * loading using the original adapter port name in NVRAM.
- */
- qla_printk(KERN_WARNING, ha,
- "Found mismatch in adapter port names.\n");
- qla_printk(KERN_INFO, ha,
- " qla%ld port name found in NVRAM -> "
- "%02x%02x%02x%02x%02x%02x%02x%02x\n",
- ha->instance,
- ha->init_cb->port_name[0],
- ha->init_cb->port_name[1],
- ha->init_cb->port_name[2],
- ha->init_cb->port_name[3],
- ha->init_cb->port_name[4],
- ha->init_cb->port_name[5],
- ha->init_cb->port_name[6],
- ha->init_cb->port_name[7]);
- qla_printk(KERN_INFO, ha,
- " qla%ld port name found on command line -> "
- "%02x%02x%02x%02x%02x%02x%02x%02x\n",
- ha->instance,
- fc_name[0], fc_name[1], fc_name[2], fc_name[3],
- fc_name[4], fc_name[5], fc_name[6], fc_name[7]);
- qla_printk(KERN_INFO, ha,
- " Using port name from NVRAM.\n");
- }
-
- qla2x00_cfg_persistent_binding(ha);
-}
-
-/*
- * qla2x00_cfg_persistent_binding
- * Get driver configuration file target persistent binding entries.
- *
- * Input:
- * ha = adapter block pointer.
- *
- * Context:
- * Kernel context.
- */
-static void
-qla2x00_cfg_persistent_binding(scsi_qla_host_t *ha)
-{
- int rval;
- static char propbuf[LINESIZE];
- char *cmdline = ha->cmdline;
- uint16_t tgt;
- port_id_t d_id;
- uint8_t portid[3];
- uint8_t port_name[8];
-
- for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
- if (ha->binding_type == BIND_BY_PORT_ID) {
- sprintf(propbuf, "scsi-qla%d-tgt-%d-di-0-pid",
- (int)ha->instance, tgt);
- rval = qla2x00_get_prop_xstr(ha,
- propbuf, portid, sizeof(portid));
- if (rval != sizeof(portid))
- continue;
-
- memset(&d_id, 0, sizeof(port_id_t));
- d_id.r.d_id[0] = portid[2];
- d_id.r.d_id[1] = portid[1];
- d_id.r.d_id[2] = portid[0];
- } else {
- sprintf(propbuf, "scsi-qla%d-tgt-%d-di-0-port",
- (int)ha->instance, tgt);
- rval = qla2x00_get_prop_16chars(ha,
- propbuf, port_name, cmdline);
- if (rval != QLA_SUCCESS)
- continue;
-
- /* Fallthru since port_name already populated */
- }
-
- /*
- * Create target context for device.
- */
- if (ha->binding_type == BIND_BY_PORT_ID) {
- qla2x00_persistent_bind(ha, NULL, NULL, &d_id, tgt);
- } else {
- qla2x00_persistent_bind(ha, NULL, port_name, NULL, tgt);
- }
- }
-}
-
-/*
- * qla2x00_persistent_bind
- * Allocates target and fcport.
- *
- * Input:
- * ha: adapter state pointer.
- * node_name: node name pointer.
- * port_name: port name pointer.
- * d_id: port ID pointer.
- * tgt: OS target number.
- *
- * Returns:
- * success = target queue pointer.
- * failure = NULL.
- *
- * Context:
- * Kernel context.
- */
-static os_tgt_t *
-qla2x00_persistent_bind(scsi_qla_host_t *ha, uint8_t *node_name,
- uint8_t *port_name, port_id_t *d_id, uint16_t tgt)
-{
- os_tgt_t *tq;
- uint16_t tgt2;
-
- /*
- * Check for duplicates.
- */
- for (tgt2 = 0; tgt2 < MAX_TARGETS; tgt2++) {
- if ((tq = TGT_Q(ha, tgt2)) == NULL) {
- continue;
- }
-
- if (ha->binding_type == BIND_BY_PORT_ID) {
- if (tq->d_id.b24 != d_id->b24) {
- continue;
- }
- } else if (memcmp(tq->port_name, port_name, WWN_SIZE) != 0) {
- continue;
- }
-
- qla_printk(KERN_WARNING, ha,
- "Duplicate persistent bindings found for "
- "WWPN: %02x%02x%02x%02x%02x%02x%02x%02x.\n",
- port_name[0], port_name[1], port_name[2], port_name[3],
- port_name[4], port_name[5], port_name[6], port_name[7]);
-
- return (tq);
- }
-
- tq = qla2x00_tgt_alloc(ha, tgt);
- if (tq == NULL) {
- return (NULL);
- }
-
- if (node_name != NULL) {
- memcpy(tq->node_name, node_name, WWN_SIZE);
- }
- if (port_name != NULL) {
- memcpy(tq->port_name, port_name, WWN_SIZE);
- }
- if (d_id != NULL) {
- tq->d_id.b24 = d_id->b24;
- }
-
- return (tq);
-}
-#endif
-