📄 aic94xx_sds.c
字号:
u8 sata_link_rates; u8 _r[5];} __attribute__ ((packed));struct asd_ctrla_phy_settings { u8 id0; /* P'h'y */ u8 _r; u16 next; u8 num_phys; /* number of PHYs in the PCI function */ u8 _r2[3]; struct asd_ctrla_phy_entry phy_ent[ASD_MAX_PHYS];} __attribute__ ((packed));struct asd_ll_el { u8 id0; u8 id1; __le16 next; u8 something_here[0];} __attribute__ ((packed));static int asd_poll_flash(struct asd_ha_struct *asd_ha){ int c; u8 d; for (c = 5000; c > 0; c--) { d = asd_read_reg_byte(asd_ha, asd_ha->hw_prof.flash.bar); d ^= asd_read_reg_byte(asd_ha, asd_ha->hw_prof.flash.bar); if (!d) return 0; udelay(5); } return -ENOENT;}static int asd_reset_flash(struct asd_ha_struct *asd_ha){ int err; err = asd_poll_flash(asd_ha); if (err) return err; asd_write_reg_byte(asd_ha, asd_ha->hw_prof.flash.bar, FLASH_RESET); err = asd_poll_flash(asd_ha); return err;}static inline int asd_read_flash_seg(struct asd_ha_struct *asd_ha, void *buffer, u32 offs, int size){ asd_read_reg_string(asd_ha, buffer, asd_ha->hw_prof.flash.bar+offs, size); return 0;}/** * asd_find_flash_dir - finds and reads the flash directory * @asd_ha: pointer to the host adapter structure * @flash_dir: pointer to flash directory structure * * If found, the flash directory segment will be copied to * @flash_dir. Return 1 if found, 0 if not. */static int asd_find_flash_dir(struct asd_ha_struct *asd_ha, struct asd_flash_dir *flash_dir){ u32 v; for (v = 0; v < ASD_FLASH_SIZE; v += FLASH_NEXT_ENTRY_OFFS) { asd_read_flash_seg(asd_ha, flash_dir, v, sizeof(FLASH_DIR_COOKIE)-1); if (memcmp(flash_dir->cookie, FLASH_DIR_COOKIE, sizeof(FLASH_DIR_COOKIE)-1) == 0) { asd_ha->hw_prof.flash.dir_offs = v; asd_read_flash_seg(asd_ha, flash_dir, v, sizeof(*flash_dir)); return 1; } } return 0;}static int asd_flash_getid(struct asd_ha_struct *asd_ha){ int err = 0; u32 reg; reg = asd_read_reg_dword(asd_ha, EXSICNFGR); if (pci_read_config_dword(asd_ha->pcidev, PCI_CONF_FLSH_BAR, &asd_ha->hw_prof.flash.bar)) { asd_printk("couldn't read PCI_CONF_FLSH_BAR of %s\n", pci_name(asd_ha->pcidev)); return -ENOENT; } asd_ha->hw_prof.flash.present = 1; asd_ha->hw_prof.flash.wide = reg & FLASHW ? 1 : 0; err = asd_reset_flash(asd_ha); if (err) { ASD_DPRINTK("couldn't reset flash(%d)\n", err); return err; } return 0;}static u16 asd_calc_flash_chksum(u16 *p, int size){ u16 chksum = 0; while (size-- > 0) chksum += *p++; return chksum;}static int asd_find_flash_de(struct asd_flash_dir *flash_dir, u32 entry_type, u32 *offs, u32 *size){ int i; struct asd_flash_de *de; for (i = 0; i < FLASH_MAX_DIR_ENTRIES; i++) { u32 type = le32_to_cpu(flash_dir->dir_entry[i].type); type &= FLASH_DE_TYPE_MASK; if (type == entry_type) break; } if (i >= FLASH_MAX_DIR_ENTRIES) return -ENOENT; de = &flash_dir->dir_entry[i]; *offs = le32_to_cpu(de->offs); *size = le32_to_cpu(de->pad_size); return 0;}static int asd_validate_ms(struct asd_manuf_sec *ms){ if (ms->sig[0] != 'S' || ms->sig[1] != 'M') { ASD_DPRINTK("manuf sec: no valid sig(%c%c)\n", ms->sig[0], ms->sig[1]); return -ENOENT; } if (ms->maj != 0) { asd_printk("unsupported manuf. sector. major version:%x\n", ms->maj); return -ENOENT; } ms->offs_next = le16_to_cpu((__force __le16) ms->offs_next); ms->chksum = le16_to_cpu((__force __le16) ms->chksum); ms->size = le16_to_cpu((__force __le16) ms->size); if (asd_calc_flash_chksum((u16 *)ms, ms->size/2)) { asd_printk("failed manuf sector checksum\n"); } return 0;}static int asd_ms_get_sas_addr(struct asd_ha_struct *asd_ha, struct asd_manuf_sec *ms){ memcpy(asd_ha->hw_prof.sas_addr, ms->sas_addr, SAS_ADDR_SIZE); return 0;}static int asd_ms_get_pcba_sn(struct asd_ha_struct *asd_ha, struct asd_manuf_sec *ms){ memcpy(asd_ha->hw_prof.pcba_sn, ms->pcba_sn, ASD_PCBA_SN_SIZE); asd_ha->hw_prof.pcba_sn[ASD_PCBA_SN_SIZE] = '\0'; return 0;}/** * asd_find_ll_by_id - find a linked list entry by its id * @start: void pointer to the first element in the linked list * @id0: the first byte of the id (offs 0) * @id1: the second byte of the id (offs 1) * * @start has to be the _base_ element start, since the * linked list entries's offset is from this pointer. * Some linked list entries use only the first id, in which case * you can pass 0xFF for the second. */static void *asd_find_ll_by_id(void * const start, const u8 id0, const u8 id1){ struct asd_ll_el *el = start; do { switch (id1) { default: if (el->id1 == id1) case 0xFF: if (el->id0 == id0) return el; } el = start + le16_to_cpu(el->next); } while (el != start); return NULL;}/** * asd_ms_get_phy_params - get phy parameters from the manufacturing sector * @asd_ha: pointer to the host adapter structure * @manuf_sec: pointer to the manufacturing sector * * The manufacturing sector contans also the linked list of sub-segments, * since when it was read, its size was taken from the flash directory, * not from the structure size. * * HIDDEN phys do not count in the total count. REPORTED phys cannot * be enabled but are reported and counted towards the total. * ENABLED phys are enabled by default and count towards the total. * The absolute total phy number is ASD_MAX_PHYS. hw_prof->num_phys * merely specifies the number of phys the host adapter decided to * report. E.g., it is possible for phys 0, 1 and 2 to be HIDDEN, * phys 3, 4 and 5 to be REPORTED and phys 6 and 7 to be ENABLED. * In this case ASD_MAX_PHYS is 8, hw_prof->num_phys is 5, and only 2 * are actually enabled (enabled by default, max number of phys * enableable in this case). */static int asd_ms_get_phy_params(struct asd_ha_struct *asd_ha, struct asd_manuf_sec *manuf_sec){ int i; int en_phys = 0; int rep_phys = 0; struct asd_manuf_phy_param *phy_param; struct asd_manuf_phy_param dflt_phy_param; phy_param = asd_find_ll_by_id(manuf_sec, 'P', 'M'); if (!phy_param) { ASD_DPRINTK("ms: no phy parameters found\n"); ASD_DPRINTK("ms: Creating default phy parameters\n"); dflt_phy_param.sig[0] = 'P'; dflt_phy_param.sig[1] = 'M'; dflt_phy_param.maj = 0; dflt_phy_param.min = 2; dflt_phy_param.num_phy_desc = 8; dflt_phy_param.phy_desc_size = sizeof(struct asd_manuf_phy_desc); for (i =0; i < ASD_MAX_PHYS; i++) { dflt_phy_param.phy_desc[i].state = 0; dflt_phy_param.phy_desc[i].phy_id = i; dflt_phy_param.phy_desc[i].phy_control_0 = 0xf6; dflt_phy_param.phy_desc[i].phy_control_1 = 0x10; dflt_phy_param.phy_desc[i].phy_control_2 = 0x43; dflt_phy_param.phy_desc[i].phy_control_3 = 0xeb; } phy_param = &dflt_phy_param; } if (phy_param->maj != 0) { asd_printk("unsupported manuf. phy param major version:0x%x\n", phy_param->maj); return -ENOENT; } ASD_DPRINTK("ms: num_phy_desc: %d\n", phy_param->num_phy_desc); asd_ha->hw_prof.enabled_phys = 0; for (i = 0; i < phy_param->num_phy_desc; i++) { struct asd_manuf_phy_desc *pd = &phy_param->phy_desc[i]; switch (pd->state & 0xF) { case MS_PHY_STATE_HIDDEN: ASD_DPRINTK("ms: phy%d: HIDDEN\n", i); continue; case MS_PHY_STATE_REPORTED: ASD_DPRINTK("ms: phy%d: REPORTED\n", i); asd_ha->hw_prof.enabled_phys &= ~(1 << i); rep_phys++; continue; case MS_PHY_STATE_ENABLED: ASD_DPRINTK("ms: phy%d: ENABLED\n", i); asd_ha->hw_prof.enabled_phys |= (1 << i); en_phys++; break; } asd_ha->hw_prof.phy_desc[i].phy_control_0 = pd->phy_control_0; asd_ha->hw_prof.phy_desc[i].phy_control_1 = pd->phy_control_1; asd_ha->hw_prof.phy_desc[i].phy_control_2 = pd->phy_control_2; asd_ha->hw_prof.phy_desc[i].phy_control_3 = pd->phy_control_3; } asd_ha->hw_prof.max_phys = rep_phys + en_phys; asd_ha->hw_prof.num_phys = en_phys; ASD_DPRINTK("ms: max_phys:0x%x, num_phys:0x%x\n", asd_ha->hw_prof.max_phys, asd_ha->hw_prof.num_phys); ASD_DPRINTK("ms: enabled_phys:0x%x\n", asd_ha->hw_prof.enabled_phys); return 0;}static int asd_ms_get_connector_map(struct asd_ha_struct *asd_ha, struct asd_manuf_sec *manuf_sec){ struct asd_ms_conn_map *cm; cm = asd_find_ll_by_id(manuf_sec, 'M', 'C'); if (!cm) { ASD_DPRINTK("ms: no connector map found\n"); return 0; } if (cm->maj != 0) { ASD_DPRINTK("ms: unsupported: connector map major version 0x%x" "\n", cm->maj); return -ENOENT; } /* XXX */ return 0;}/** * asd_process_ms - find and extract information from the manufacturing sector * @asd_ha: pointer to the host adapter structure * @flash_dir: pointer to the flash directory */static int asd_process_ms(struct asd_ha_struct *asd_ha, struct asd_flash_dir *flash_dir){ int err; struct asd_manuf_sec *manuf_sec; u32 offs, size; err = asd_find_flash_de(flash_dir, FLASH_DE_MS, &offs, &size); if (err) { ASD_DPRINTK("Couldn't find the manuf. sector\n"); goto out; } if (size == 0) goto out; err = -ENOMEM; manuf_sec = kmalloc(size, GFP_KERNEL); if (!manuf_sec) { ASD_DPRINTK("no mem for manuf sector\n"); goto out; } err = asd_read_flash_seg(asd_ha, (void *)manuf_sec, offs, size); if (err) { ASD_DPRINTK("couldn't read manuf sector at 0x%x, size 0x%x\n", offs, size); goto out2; } err = asd_validate_ms(manuf_sec); if (err) { ASD_DPRINTK("couldn't validate manuf sector\n"); goto out2; } err = asd_ms_get_sas_addr(asd_ha, manuf_sec); if (err) { ASD_DPRINTK("couldn't read the SAS_ADDR\n"); goto out2; } ASD_DPRINTK("manuf sect SAS_ADDR %llx\n", SAS_ADDR(asd_ha->hw_prof.sas_addr)); err = asd_ms_get_pcba_sn(asd_ha, manuf_sec); if (err) { ASD_DPRINTK("couldn't read the PCBA SN\n"); goto out2; } ASD_DPRINTK("manuf sect PCBA SN %s\n", asd_ha->hw_prof.pcba_sn); err = asd_ms_get_phy_params(asd_ha, manuf_sec); if (err) { ASD_DPRINTK("ms: couldn't get phy parameters\n"); goto out2; } err = asd_ms_get_connector_map(asd_ha, manuf_sec); if (err) { ASD_DPRINTK("ms: couldn't get connector map\n"); goto out2; }out2: kfree(manuf_sec);out: return err;}static int asd_process_ctrla_phy_settings(struct asd_ha_struct *asd_ha, struct asd_ctrla_phy_settings *ps){ int i; for (i = 0; i < ps->num_phys; i++) { struct asd_ctrla_phy_entry *pe = &ps->phy_ent[i]; if (!PHY_ENABLED(asd_ha, i)) continue; if (*(u64 *)pe->sas_addr == 0) { asd_ha->hw_prof.enabled_phys &= ~(1 << i); continue; } /* This is the SAS address which should be sent in IDENTIFY. */ memcpy(asd_ha->hw_prof.phy_desc[i].sas_addr, pe->sas_addr, SAS_ADDR_SIZE); asd_ha->hw_prof.phy_desc[i].max_sas_lrate = (pe->sas_link_rates & 0xF0) >> 4; asd_ha->hw_prof.phy_desc[i].min_sas_lrate = (pe->sas_link_rates & 0x0F); asd_ha->hw_prof.phy_desc[i].max_sata_lrate = (pe->sata_link_rates & 0xF0) >> 4; asd_ha->hw_prof.phy_desc[i].min_sata_lrate = (pe->sata_link_rates & 0x0F); asd_ha->hw_prof.phy_desc[i].flags = pe->flags; ASD_DPRINTK("ctrla: phy%d: sas_addr: %llx, sas rate:0x%x-0x%x," " sata rate:0x%x-0x%x, flags:0x%x\n", i, SAS_ADDR(asd_ha->hw_prof.phy_desc[i].sas_addr), asd_ha->hw_prof.phy_desc[i].max_sas_lrate, asd_ha->hw_prof.phy_desc[i].min_sas_lrate, asd_ha->hw_prof.phy_desc[i].max_sata_lrate, asd_ha->hw_prof.phy_desc[i].min_sata_lrate, asd_ha->hw_prof.phy_desc[i].flags); } return 0;}/** * asd_process_ctrl_a_user - process CTRL-A user settings * @asd_ha: pointer to the host adapter structure * @flash_dir: pointer to the flash directory */static int asd_process_ctrl_a_user(struct asd_ha_struct *asd_ha, struct asd_flash_dir *flash_dir){ int err, i; u32 offs, size; struct asd_ll_el *el; struct asd_ctrla_phy_settings *ps; struct asd_ctrla_phy_settings dflt_ps; err = asd_find_flash_de(flash_dir, FLASH_DE_CTRL_A_USER, &offs, &size); if (err) { ASD_DPRINTK("couldn't find CTRL-A user settings section\n"); ASD_DPRINTK("Creating default CTRL-A user settings section\n"); dflt_ps.id0 = 'h'; dflt_ps.num_phys = 8; for (i =0; i < ASD_MAX_PHYS; i++) { memcpy(dflt_ps.phy_ent[i].sas_addr, asd_ha->hw_prof.sas_addr, SAS_ADDR_SIZE); dflt_ps.phy_ent[i].sas_link_rates = 0x98; dflt_ps.phy_ent[i].flags = 0x0; dflt_ps.phy_ent[i].sata_link_rates = 0x0; } size = sizeof(struct asd_ctrla_phy_settings); ps = &dflt_ps; } if (size == 0) goto out; err = -ENOMEM; el = kmalloc(size, GFP_KERNEL); if (!el) { ASD_DPRINTK("no mem for ctrla user settings section\n"); goto out; } err = asd_read_flash_seg(asd_ha, (void *)el, offs, size); if (err) { ASD_DPRINTK("couldn't read ctrla phy settings section\n"); goto out2; } err = -ENOENT; ps = asd_find_ll_by_id(el, 'h', 0xFF); if (!ps) { ASD_DPRINTK("couldn't find ctrla phy settings struct\n"); goto out2; } err = asd_process_ctrla_phy_settings(asd_ha, ps); if (err) { ASD_DPRINTK("couldn't process ctrla phy settings\n"); goto out2; }out2: kfree(el);out: return err;}/** * asd_read_flash - read flash memory * @asd_ha: pointer to the host adapter structure */int asd_read_flash(struct asd_ha_struct *asd_ha){ int err; struct asd_flash_dir *flash_dir; err = asd_flash_getid(asd_ha); if (err) return err; flash_dir = kmalloc(sizeof(*flash_dir), GFP_KERNEL); if (!flash_dir) return -ENOMEM; err = -ENOENT; if (!asd_find_flash_dir(asd_ha, flash_dir)) { ASD_DPRINTK("couldn't find flash directory\n"); goto out; } if (le32_to_cpu(flash_dir->rev) != 2) { asd_printk("unsupported flash dir version:0x%x\n", le32_to_cpu(flash_dir->rev)); goto out; } err = asd_process_ms(asd_ha, flash_dir); if (err) { ASD_DPRINTK("couldn't process manuf sector settings\n"); goto out; } err = asd_process_ctrl_a_user(asd_ha, flash_dir); if (err) { ASD_DPRINTK("couldn't process CTRL-A user settings\n"); goto out; }out: kfree(flash_dir); return err;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -