static ssize_t flash_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) { struct qib_devdata *dd; ssize_t ret; loff_t pos; char *tmp; pos = *ppos; if (pos < 0) { ret = -EINVAL; goto bail; } if (pos >= sizeof(struct qib_flash)) { ret = 0; goto bail; } if (count > sizeof(struct qib_flash) - pos) count = sizeof(struct qib_flash) - pos; tmp = kmalloc(count, GFP_KERNEL); if (!tmp) { ret = -ENOMEM; goto bail; } dd = private2dd(file); if (qib_eeprom_read(dd, pos, tmp, count)) { qib_dev_err(dd, "failed to read from flash\n"); ret = -ENXIO; goto bail_tmp; } if (copy_to_user(buf, tmp, count)) { ret = -EFAULT; goto bail_tmp; } *ppos = pos + count; ret = count; bail_tmp: kfree(tmp); bail: return ret; }
/** * qib_get_eeprom_info- get the GUID et al. from the TSWI EEPROM device * @dd: the qlogic_ib device * * We have the capability to use the nguid field, and get * the guid from the first chip's flash, to use for all of them. */ void qib_get_eeprom_info(struct qib_devdata *dd) { void *buf; struct qib_flash *ifp; __be64 guid; int len, eep_stat; u8 csum, *bguid; int t = dd->unit; struct qib_devdata *dd0 = qib_lookup(0); if (t && dd0->nguid > 1 && t <= dd0->nguid) { u8 oguid; dd->base_guid = dd0->base_guid; bguid = (u8 *) &dd->base_guid; oguid = bguid[7]; bguid[7] += t; if (oguid > bguid[7]) { if (bguid[6] == 0xff) { if (bguid[5] == 0xff) { qib_dev_err(dd, "Can't set %s GUID" " from base, wraps to" " OUI!\n", qib_get_unit_name(t)); dd->base_guid = 0; goto bail; } bguid[5]++; } bguid[6]++; } dd->nguid = 1; goto bail; } /* * Read full flash, not just currently used part, since it may have * been written with a newer definition. * */ len = sizeof(struct qib_flash); buf = vmalloc(len); if (!buf) { qib_dev_err(dd, "Couldn't allocate memory to read %u " "bytes from eeprom for GUID\n", len); goto bail; } /* * Use "public" eeprom read function, which does locking and * figures out device. This will migrate to chip-specific. */ eep_stat = qib_eeprom_read(dd, 0, buf, len); if (eep_stat) { qib_dev_err(dd, "Failed reading GUID from eeprom\n"); goto done; } ifp = (struct qib_flash *)buf; csum = flash_csum(ifp, 0); if (csum != ifp->if_csum) { qib_devinfo(dd->pcidev, "Bad I2C flash checksum: " "0x%x, not 0x%x\n", csum, ifp->if_csum); goto done; } if (*(__be64 *) ifp->if_guid == cpu_to_be64(0) || *(__be64 *) ifp->if_guid == ~cpu_to_be64(0)) { qib_dev_err(dd, "Invalid GUID %llx from flash; ignoring\n", *(unsigned long long *) ifp->if_guid); /* don't allow GUID if all 0 or all 1's */ goto done; } /* complain, but allow it */ if (*(u64 *) ifp->if_guid == 0x100007511000000ULL) qib_devinfo(dd->pcidev, "Warning, GUID %llx is " "default, probably not correct!\n", *(unsigned long long *) ifp->if_guid); bguid = ifp->if_guid; if (!bguid[0] && !bguid[1] && !bguid[2]) { /* * Original incorrect GUID format in flash; fix in * core copy, by shifting up 2 octets; don't need to * change top octet, since both it and shifted are 0. */ bguid[1] = bguid[3]; bguid[2] = bguid[4]; bguid[3] = 0; bguid[4] = 0; guid = *(__be64 *) ifp->if_guid; } else guid = *(__be64 *) ifp->if_guid; dd->base_guid = guid; dd->nguid = ifp->if_numguid; /* * Things are slightly complicated by the desire to transparently * support both the Pathscale 10-digit serial number and the QLogic * 13-character version. */ if ((ifp->if_fversion > 1) && ifp->if_sprefix[0] && ((u8 *) ifp->if_sprefix)[0] != 0xFF) { char *snp = dd->serial; /* * This board has a Serial-prefix, which is stored * elsewhere for backward-compatibility. */ memcpy(snp, ifp->if_sprefix, sizeof ifp->if_sprefix); snp[sizeof ifp->if_sprefix] = '\0'; len = strlen(snp); snp += len; len = (sizeof dd->serial) - len; if (len > sizeof ifp->if_serial) len = sizeof ifp->if_serial; memcpy(snp, ifp->if_serial, len); } else memcpy(dd->serial, ifp->if_serial, sizeof ifp->if_serial); if (!strstr(ifp->if_comment, "Tested successfully")) qib_dev_err(dd, "Board SN %s did not pass functional " "test: %s\n", dd->serial, ifp->if_comment); memcpy(&dd->eep_st_errs, &ifp->if_errcntp, QIB_EEP_LOG_CNT); /* * Power-on (actually "active") hours are kept as little-endian value * in EEPROM, but as seconds in a (possibly as small as 24-bit) * atomic_t while running. */ atomic_set(&dd->active_time, 0); dd->eep_hrs = ifp->if_powerhour[0] | (ifp->if_powerhour[1] << 8); done: vfree(buf); bail:; }