28 #include <linux/pci.h>
29 #include <linux/slab.h>
55 #define OCM_DE_OCM_DIR 0x00
56 #define OCM_DE_WIN_DRVR 0x01
57 #define OCM_DE_BIOS_CHIM 0x02
58 #define OCM_DE_RAID_ENGN 0x03
59 #define OCM_DE_BIOS_INTL 0x04
60 #define OCM_DE_BIOS_CHIM_OSM 0x05
61 #define OCM_DE_BIOS_CHIM_DYNAMIC 0x06
62 #define OCM_DE_ADDC2C_RES0 0x07
63 #define OCM_DE_ADDC2C_RES1 0x08
64 #define OCM_DE_ADDC2C_RES2 0x09
65 #define OCM_DE_ADDC2C_RES3 0x0A
67 #define OCM_INIT_DIR_ENTRIES 5
105 .size = {128, 235, 1},
141 for ( ; size > 0; size--, offs++, p++)
142 *p = asd_read_ocm_byte(asd_ha, offs);
150 int err = asd_read_ocm_seg(asd_ha, dir, offs,
sizeof(*dir));
156 if (dir->
sig[0] !=
'M' || dir->
sig[1] !=
'O') {
157 ASD_DPRINTK(
"no valid dir signature(%c%c) at start of OCM\n",
158 dir->
sig[0], dir->
sig[1]);
161 if (dir->
major != 0) {
162 asd_printk(
"unsupported major version of ocm dir:0x%x\n",
186 for ( ; size > 0; size--, offs++, p++)
187 asd_write_ocm_byte(asd_ha, offs, *p);
192 #define THREE_TO_NUM(X) ((X)[0] | ((X)[1] << 8) | ((X)[2] << 16))
200 for (i = 0; i < dir->
num_de; i++) {
201 if (dir->
entry[i].type == type)
212 #define OCM_BIOS_CHIM_DE 2
213 #define BC_BIOS_PRESENT 1
230 asd_printk(
"no memory for bios_chim struct\n");
233 err = asd_read_ocm_seg(asd_ha, (
void *)bc_struct, offs,
241 ASD_DPRINTK(
"BIOS_CHIM entry has no valid sig(%c%c%c%c)\n",
242 bc_struct->
sig[0], bc_struct->
sig[1],
243 bc_struct->
sig[2], bc_struct->
sig[3]);
247 if (bc_struct->
major != 1) {
248 asd_printk(
"BIOS_CHIM unsupported major version:0x%x\n",
254 asd_ha->
hw_prof.bios.present = 1;
273 err = asd_read_ocm_seg(asd_ha, (
void *)asd_ha->
hw_prof.ue.area,
274 offs +
sizeof(*bc_struct), size);
280 ASD_DPRINTK(
"couldn't read ue entries(%d)\n", err);
296 asd_write_ocm_dword(asd_ha, i, 0);
299 asd_write_ocm_seg(asd_ha, &OCMDirInit, 0,
304 asd_write_ocm_seg(asd_ha, &OCMDirEntriesInit[i],
325 asd_printk(
"couldn't access PCIC_INTRPT_STAT of %s\n",
331 "reinitialize it and ignore it, current IntrptStatus"
335 err = pci_write_config_dword(pcidev,
338 asd_printk(
"couldn't write PCIC_INTRPT_STAT of %s\n",
343 asd_hwi_initialize_ocm_dir(asd_ha);
359 if (asd_hwi_check_ocm_access(asd_ha))
368 err = asd_read_ocm_dir(asd_ha, dir, 0);
372 err = asd_get_bios_chim(asd_ha, dir);
380 #define FLASH_RESET 0xF0
382 #define ASD_FLASH_SIZE 0x200000
383 #define FLASH_DIR_COOKIE "*** ADAPTEC FLASH DIRECTORY *** "
384 #define FLASH_NEXT_ENTRY_OFFS 0x2000
385 #define FLASH_MAX_DIR_ENTRIES 32
387 #define FLASH_DE_TYPE_MASK 0x3FFFFFFF
388 #define FLASH_DE_MS 0x120
389 #define FLASH_DE_CTRL_A_USER 0xE0
432 #define MS_PHY_STATE_ENABLED 0
433 #define MS_PHY_STATE_REPORTED 1
434 #define MS_PHY_STATE_HIDDEN 2
457 static const char *asd_sb_type[] = {
460 [2 ... 0x7F] =
"unknown",
462 [0x81 ... 0xFF] =
"VENDOR_UNIQUExx"
474 static const char *asd_conn_type[] = {
475 [0 ... 7] =
"unknown",
479 [0x80] =
"PCIX_DAUGHTER0",
480 [0x81] =
"SAS_DAUGHTER0",
481 [0x82 ... 0xFF] =
"VENDOR_UNIQUExx"
484 static const char *asd_conn_location[] = {
508 static const char *asd_node_type[] = {
514 "MULTI_DROP_I2C_BUS",
571 for (c = 5000; c > 0; c--) {
585 err = asd_poll_flash(asd_ha);
589 err = asd_poll_flash(asd_ha);
595 void *buffer,
u32 offs,
int size)
615 asd_read_flash_seg(asd_ha, flash_dir, v,
620 asd_read_flash_seg(asd_ha, flash_dir, v,
637 asd_printk(
"couldn't read PCI_CONF_FLSH_BAR of %s\n",
638 pci_name(asd_ha->
pcidev));
641 asd_ha->
hw_prof.flash.present = 1;
643 err = asd_reset_flash(asd_ha);
651 static u16 asd_calc_flash_chksum(
u16 *p,
int size)
662 static int asd_find_flash_de(
struct asd_flash_dir *flash_dir,
u32 entry_type,
672 if (type == entry_type)
675 if (i >= FLASH_MAX_DIR_ENTRIES)
685 if (ms->
sig[0] !=
'S' || ms->
sig[1] !=
'M') {
691 asd_printk(
"unsupported manuf. sector. major version:%x\n",
699 if (asd_calc_flash_chksum((
u16 *)ms, ms->
size/2)) {
732 static void *asd_find_ll_by_id(
void *
const start,
const u8 id0,
const u8 id1)
745 }
while (el != start);
770 static int asd_ms_get_phy_params(
struct asd_ha_struct *asd_ha,
779 phy_param = asd_find_ll_by_id(manuf_sec,
'P',
'M');
782 ASD_DPRINTK(
"ms: Creating default phy parameters\n");
783 dflt_phy_param.sig[0] =
'P';
784 dflt_phy_param.sig[1] =
'M';
785 dflt_phy_param.maj = 0;
786 dflt_phy_param.min = 2;
787 dflt_phy_param.num_phy_desc = 8;
790 dflt_phy_param.phy_desc[
i].state = 0;
791 dflt_phy_param.phy_desc[
i].phy_id =
i;
792 dflt_phy_param.phy_desc[
i].phy_control_0 = 0xf6;
793 dflt_phy_param.phy_desc[
i].phy_control_1 = 0x10;
794 dflt_phy_param.phy_desc[
i].phy_control_2 = 0x43;
795 dflt_phy_param.phy_desc[
i].phy_control_3 = 0xeb;
798 phy_param = &dflt_phy_param;
802 if (phy_param->maj != 0) {
803 asd_printk(
"unsupported manuf. phy param major version:0x%x\n",
808 ASD_DPRINTK(
"ms: num_phy_desc: %d\n", phy_param->num_phy_desc);
809 asd_ha->
hw_prof.enabled_phys = 0;
810 for (i = 0; i < phy_param->num_phy_desc; i++) {
812 switch (pd->
state & 0xF) {
818 asd_ha->
hw_prof.enabled_phys &= ~(1 <<
i);
823 asd_ha->
hw_prof.enabled_phys |= (1 <<
i);
832 asd_ha->
hw_prof.max_phys = rep_phys + en_phys;
833 asd_ha->
hw_prof.num_phys = en_phys;
840 static int asd_ms_get_connector_map(
struct asd_ha_struct *asd_ha,
845 cm = asd_find_ll_by_id(manuf_sec,
'M',
'C');
852 ASD_DPRINTK(
"ms: unsupported: connector map major version 0x%x"
875 err = asd_find_flash_de(flash_dir,
FLASH_DE_MS, &offs, &size);
891 err = asd_read_flash_seg(asd_ha, (
void *)manuf_sec, offs, size);
893 ASD_DPRINTK(
"couldn't read manuf sector at 0x%x, size 0x%x\n",
898 err = asd_validate_ms(manuf_sec);
904 err = asd_ms_get_sas_addr(asd_ha, manuf_sec);
912 err = asd_ms_get_pcba_sn(asd_ha, manuf_sec);
919 err = asd_ms_get_phy_params(asd_ha, manuf_sec);
925 err = asd_ms_get_connector_map(asd_ha, manuf_sec);
937 static int asd_process_ctrla_phy_settings(
struct asd_ha_struct *asd_ha,
941 for (i = 0; i < ps->
num_phys; i++) {
947 asd_ha->
hw_prof.enabled_phys &= ~(1 <<
i);
953 asd_ha->
hw_prof.phy_desc[
i].max_sas_lrate =
955 asd_ha->
hw_prof.phy_desc[
i].min_sas_lrate =
957 asd_ha->
hw_prof.phy_desc[
i].max_sata_lrate =
959 asd_ha->
hw_prof.phy_desc[
i].min_sata_lrate =
962 ASD_DPRINTK(
"ctrla: phy%d: sas_addr: %llx, sas rate:0x%x-0x%x,"
963 " sata rate:0x%x-0x%x, flags:0x%x\n",
966 asd_ha->
hw_prof.phy_desc[i].max_sas_lrate,
967 asd_ha->
hw_prof.phy_desc[i].min_sas_lrate,
968 asd_ha->
hw_prof.phy_desc[i].max_sata_lrate,
969 asd_ha->
hw_prof.phy_desc[i].min_sata_lrate,
970 asd_ha->
hw_prof.phy_desc[i].flags);
981 static int asd_process_ctrl_a_user(
struct asd_ha_struct *asd_ha,
992 ASD_DPRINTK(
"couldn't find CTRL-A user settings section\n");
993 ASD_DPRINTK(
"Creating default CTRL-A user settings section\n");
996 dflt_ps.num_phys = 8;
998 memcpy(dflt_ps.phy_ent[i].sas_addr,
1000 dflt_ps.phy_ent[
i].sas_link_rates = 0x98;
1001 dflt_ps.phy_ent[
i].flags = 0x0;
1002 dflt_ps.phy_ent[
i].sata_link_rates = 0x0;
1015 ASD_DPRINTK(
"no mem for ctrla user settings section\n");
1019 err = asd_read_flash_seg(asd_ha, (
void *)el, offs, size);
1021 ASD_DPRINTK(
"couldn't read ctrla phy settings section\n");
1026 ps = asd_find_ll_by_id(el,
'h', 0xFF);
1028 ASD_DPRINTK(
"couldn't find ctrla phy settings struct\n");
1032 err = asd_process_ctrla_phy_settings(asd_ha, ps);
1034 ASD_DPRINTK(
"couldn't process ctrla phy settings\n");
1052 err = asd_flash_getid(asd_ha);
1061 if (!asd_find_flash_dir(asd_ha, flash_dir)) {
1067 asd_printk(
"unsupported flash dir version:0x%x\n",
1072 err = asd_process_ms(asd_ha, flash_dir);
1074 ASD_DPRINTK(
"couldn't process manuf sector settings\n");
1078 err = asd_process_ctrl_a_user(asd_ha, flash_dir);
1080 ASD_DPRINTK(
"couldn't process CTRL-A user settings\n");
1097 const void *
src,
u32 dest_offset,
u32 bytes_to_verify)
1104 reg = asd_ha->
hw_prof.flash.bar;
1108 nv_offset = dest_offset;
1109 src_buf = (
const u8 *)src;
1110 for (i = 0; i < bytes_to_verify; i++) {
1112 if (flash_char != src_buf[i]) {
1128 const void *
src,
u32 dest_offset,
u32 bytes_to_write)
1134 reg = asd_ha->
hw_prof.flash.bar;
1139 ASD_DPRINTK(
"couldn't find the type of flash. err=%d\n", err);
1143 nv_offset = dest_offset;
1151 err = asd_reset_flash(asd_ha);
1153 ASD_DPRINTK(
"couldn't reset flash. err=%d\n", err);
1157 src_buf = (
const u8 *)src;
1158 for (i = 0; i < bytes_to_write; i++) {
1160 switch (asd_ha->
hw_prof.flash.method) {
1164 (reg + 0xAAA), 0xAA);
1166 (reg + 0x555), 0x55);
1168 (reg + 0xAAA), 0xA0);
1170 (reg + nv_offset + i),
1177 (reg + 0x555), 0xAA);
1179 (reg + 0x2AA), 0x55);
1181 (reg + 0x555), 0xA0);
1183 (reg + nv_offset + i),
1191 (nv_offset + i), 0) != 0) {
1192 ASD_DPRINTK(
"aicx: Write failed at offset:0x%x\n",
1193 reg + nv_offset + i);
1198 err = asd_reset_flash(asd_ha);
1200 ASD_DPRINTK(
"couldn't reset flash. err=%d\n", err);
1207 u32 sector_addr,
u8 erase_flag)
1211 u8 nv_data1, nv_data2;
1218 reg = asd_ha->
hw_prof.flash.bar;
1220 for (loop_cnt = 0; loop_cnt < 50000; loop_cnt++) {
1227 if (toggle_bit1 == 0) {
1237 ^ (nv_data2 & FLASH_STATUS_BIT_MASK_DQ6));
1239 if (toggle_bit1 == 0)
1274 reg = asd_ha->
hw_prof.flash.bar;
1283 while (sector_addr < flash_addr+size) {
1284 switch (asd_ha->
hw_prof.flash.method) {
1324 reg = asd_ha->
hw_prof.flash.bar;
1327 err = asd_reset_flash(asd_ha);
1329 ASD_DPRINTK(
"couldn't reset flash. err=%d\n", err);
1341 inc = asd_ha->
hw_prof.flash.wide ? 2 : 1;
1349 err = asd_reset_flash(asd_ha);
1351 ASD_DPRINTK(
"couldn't reset flash. err=%d\n", err);
1354 ASD_DPRINTK(
"Flash MethodA manuf_id(0x%x) dev_id(0x%x) "
1355 "sec_prot(0x%x)\n", manuf_id, dev_id, sec_prot);
1356 err = asd_reset_flash(asd_ha);
1400 err = asd_reset_flash(asd_ha);
1402 ASD_DPRINTK(
"couldn't reset flash. err=%d\n", err);
1414 ASD_DPRINTK(
"Flash MethodB manuf_id(0x%x) dev_id(0x%x) sec_prot"
1415 "(0x%x)\n", manuf_id, dev_id, sec_prot);
1417 err = asd_reset_flash(asd_ha);
1419 ASD_DPRINTK(
"couldn't reset flash. err=%d\n", err);
1471 asd_ha->
hw_prof.flash.manuf = manuf_id;
1473 asd_ha->
hw_prof.flash.sec_prot = sec_prot;