Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc/powernv: Fix endianness problems in EEH

EEH information fetched from OPAL need fix before using in LE environment.
To be included in sparse's endian check, declare them as __beXX and
access them by accessors.

Cc: Gavin Shan <gwshan@linux.vnet.ibm.com>

Signed-off-by: Guo Chao <yan@linux.vnet.ibm.com>
Acked-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

authored by

Guo Chao and committed by
Benjamin Herrenschmidt
ddf0322a 8b9f9269

+120 -99
+51 -51
arch/powerpc/include/asm/opal.h
··· 599 599 }; 600 600 601 601 struct OpalIoPhbErrorCommon { 602 - uint32_t version; 603 - uint32_t ioType; 604 - uint32_t len; 602 + __be32 version; 603 + __be32 ioType; 604 + __be32 len; 605 605 }; 606 606 607 607 struct OpalIoP7IOCPhbErrorData { ··· 666 666 struct OpalIoPhb3ErrorData { 667 667 struct OpalIoPhbErrorCommon common; 668 668 669 - uint32_t brdgCtl; 669 + __be32 brdgCtl; 670 670 671 671 /* PHB3 UTL regs */ 672 - uint32_t portStatusReg; 673 - uint32_t rootCmplxStatus; 674 - uint32_t busAgentStatus; 672 + __be32 portStatusReg; 673 + __be32 rootCmplxStatus; 674 + __be32 busAgentStatus; 675 675 676 676 /* PHB3 cfg regs */ 677 - uint32_t deviceStatus; 678 - uint32_t slotStatus; 679 - uint32_t linkStatus; 680 - uint32_t devCmdStatus; 681 - uint32_t devSecStatus; 677 + __be32 deviceStatus; 678 + __be32 slotStatus; 679 + __be32 linkStatus; 680 + __be32 devCmdStatus; 681 + __be32 devSecStatus; 682 682 683 683 /* cfg AER regs */ 684 - uint32_t rootErrorStatus; 685 - uint32_t uncorrErrorStatus; 686 - uint32_t corrErrorStatus; 687 - uint32_t tlpHdr1; 688 - uint32_t tlpHdr2; 689 - uint32_t tlpHdr3; 690 - uint32_t tlpHdr4; 691 - uint32_t sourceId; 684 + __be32 rootErrorStatus; 685 + __be32 uncorrErrorStatus; 686 + __be32 corrErrorStatus; 687 + __be32 tlpHdr1; 688 + __be32 tlpHdr2; 689 + __be32 tlpHdr3; 690 + __be32 tlpHdr4; 691 + __be32 sourceId; 692 692 693 - uint32_t rsv3; 693 + __be32 rsv3; 694 694 695 695 /* Record data about the call to allocate a buffer */ 696 - uint64_t errorClass; 697 - uint64_t correlator; 696 + __be64 errorClass; 697 + __be64 correlator; 698 698 699 - uint64_t nFir; /* 000 */ 700 - uint64_t nFirMask; /* 003 */ 701 - uint64_t nFirWOF; /* 008 */ 699 + __be64 nFir; /* 000 */ 700 + __be64 nFirMask; /* 003 */ 701 + __be64 nFirWOF; /* 008 */ 702 702 703 703 /* PHB3 MMIO Error Regs */ 704 - uint64_t phbPlssr; /* 120 */ 705 - uint64_t phbCsr; /* 110 */ 706 - uint64_t lemFir; /* C00 */ 707 - uint64_t lemErrorMask; /* C18 */ 708 - uint64_t lemWOF; /* C40 */ 709 - uint64_t phbErrorStatus; /* C80 */ 710 - uint64_t phbFirstErrorStatus; /* C88 */ 711 - uint64_t phbErrorLog0; /* CC0 */ 712 - uint64_t phbErrorLog1; /* CC8 */ 713 - uint64_t mmioErrorStatus; /* D00 */ 714 - uint64_t mmioFirstErrorStatus; /* D08 */ 715 - uint64_t mmioErrorLog0; /* D40 */ 716 - uint64_t mmioErrorLog1; /* D48 */ 717 - uint64_t dma0ErrorStatus; /* D80 */ 718 - uint64_t dma0FirstErrorStatus; /* D88 */ 719 - uint64_t dma0ErrorLog0; /* DC0 */ 720 - uint64_t dma0ErrorLog1; /* DC8 */ 721 - uint64_t dma1ErrorStatus; /* E00 */ 722 - uint64_t dma1FirstErrorStatus; /* E08 */ 723 - uint64_t dma1ErrorLog0; /* E40 */ 724 - uint64_t dma1ErrorLog1; /* E48 */ 725 - uint64_t pestA[OPAL_PHB3_NUM_PEST_REGS]; 726 - uint64_t pestB[OPAL_PHB3_NUM_PEST_REGS]; 704 + __be64 phbPlssr; /* 120 */ 705 + __be64 phbCsr; /* 110 */ 706 + __be64 lemFir; /* C00 */ 707 + __be64 lemErrorMask; /* C18 */ 708 + __be64 lemWOF; /* C40 */ 709 + __be64 phbErrorStatus; /* C80 */ 710 + __be64 phbFirstErrorStatus; /* C88 */ 711 + __be64 phbErrorLog0; /* CC0 */ 712 + __be64 phbErrorLog1; /* CC8 */ 713 + __be64 mmioErrorStatus; /* D00 */ 714 + __be64 mmioFirstErrorStatus; /* D08 */ 715 + __be64 mmioErrorLog0; /* D40 */ 716 + __be64 mmioErrorLog1; /* D48 */ 717 + __be64 dma0ErrorStatus; /* D80 */ 718 + __be64 dma0FirstErrorStatus; /* D88 */ 719 + __be64 dma0ErrorLog0; /* DC0 */ 720 + __be64 dma0ErrorLog1; /* DC8 */ 721 + __be64 dma1ErrorStatus; /* E00 */ 722 + __be64 dma1FirstErrorStatus; /* E08 */ 723 + __be64 dma1ErrorLog0; /* E40 */ 724 + __be64 dma1ErrorLog1; /* E48 */ 725 + __be64 pestA[OPAL_PHB3_NUM_PEST_REGS]; 726 + __be64 pestB[OPAL_PHB3_NUM_PEST_REGS]; 727 727 }; 728 728 729 729 enum { ··· 851 851 int64_t opal_set_slot_led_status(uint64_t phb_id, uint64_t slot_id, uint8_t led_type, uint8_t led_action); 852 852 int64_t opal_get_epow_status(__be64 *status); 853 853 int64_t opal_set_system_attention_led(uint8_t led_action); 854 - int64_t opal_pci_next_error(uint64_t phb_id, uint64_t *first_frozen_pe, 855 - uint16_t *pci_error_type, uint16_t *severity); 854 + int64_t opal_pci_next_error(uint64_t phb_id, __be64 *first_frozen_pe, 855 + __be16 *pci_error_type, __be16 *severity); 856 856 int64_t opal_pci_poll(uint64_t phb_id); 857 857 int64_t opal_return_cpu(void); 858 858 int64_t opal_reinit_cpus(uint64_t flags);
+19 -17
arch/powerpc/platforms/powernv/eeh-ioda.c
··· 267 267 { 268 268 s64 ret = 0; 269 269 u8 fstate; 270 - u16 pcierr; 270 + __be16 pcierr; 271 271 u32 pe_no; 272 272 int result; 273 273 struct pci_controller *hose = pe->phb; ··· 316 316 result = 0; 317 317 result &= ~EEH_STATE_RESET_ACTIVE; 318 318 319 - if (pcierr != OPAL_EEH_PHB_ERROR) { 319 + if (be16_to_cpu(pcierr) != OPAL_EEH_PHB_ERROR) { 320 320 result |= EEH_STATE_MMIO_ACTIVE; 321 321 result |= EEH_STATE_DMA_ACTIVE; 322 322 result |= EEH_STATE_MMIO_ENABLED; ··· 706 706 struct pci_controller *hose; 707 707 struct pnv_phb *phb; 708 708 struct eeh_pe *phb_pe; 709 - u64 frozen_pe_no; 710 - u16 err_type, severity; 709 + __be64 frozen_pe_no; 710 + __be16 err_type, severity; 711 711 long rc; 712 712 int ret = EEH_NEXT_ERR_NONE; 713 713 ··· 742 742 } 743 743 744 744 /* If the PHB doesn't have error, stop processing */ 745 - if (err_type == OPAL_EEH_NO_ERROR || 746 - severity == OPAL_EEH_SEV_NO_ERROR) { 745 + if (be16_to_cpu(err_type) == OPAL_EEH_NO_ERROR || 746 + be16_to_cpu(severity) == OPAL_EEH_SEV_NO_ERROR) { 747 747 pr_devel("%s: No error found on PHB#%x\n", 748 748 __func__, hose->global_number); 749 749 continue; ··· 755 755 * specific PHB. 756 756 */ 757 757 pr_devel("%s: Error (%d, %d, %llu) on PHB#%x\n", 758 - __func__, err_type, severity, 759 - frozen_pe_no, hose->global_number); 760 - switch (err_type) { 758 + __func__, be16_to_cpu(err_type), be16_to_cpu(severity), 759 + be64_to_cpu(frozen_pe_no), hose->global_number); 760 + switch (be16_to_cpu(err_type)) { 761 761 case OPAL_EEH_IOC_ERROR: 762 - if (severity == OPAL_EEH_SEV_IOC_DEAD) { 762 + if (be16_to_cpu(severity) == OPAL_EEH_SEV_IOC_DEAD) { 763 763 pr_err("EEH: dead IOC detected\n"); 764 764 ret = EEH_NEXT_ERR_DEAD_IOC; 765 - } else if (severity == OPAL_EEH_SEV_INF) { 765 + } else if (be16_to_cpu(severity) == OPAL_EEH_SEV_INF) { 766 766 pr_info("EEH: IOC informative error " 767 767 "detected\n"); 768 768 ioda_eeh_hub_diag(hose); ··· 771 771 772 772 break; 773 773 case OPAL_EEH_PHB_ERROR: 774 - if (severity == OPAL_EEH_SEV_PHB_DEAD) { 774 + if (be16_to_cpu(severity) == OPAL_EEH_SEV_PHB_DEAD) { 775 775 *pe = phb_pe; 776 776 pr_err("EEH: dead PHB#%x detected\n", 777 777 hose->global_number); 778 778 ret = EEH_NEXT_ERR_DEAD_PHB; 779 - } else if (severity == OPAL_EEH_SEV_PHB_FENCED) { 779 + } else if (be16_to_cpu(severity) == 780 + OPAL_EEH_SEV_PHB_FENCED) { 780 781 *pe = phb_pe; 781 782 pr_err("EEH: fenced PHB#%x detected\n", 782 783 hose->global_number); 783 784 ret = EEH_NEXT_ERR_FENCED_PHB; 784 - } else if (severity == OPAL_EEH_SEV_INF) { 785 + } else if (be16_to_cpu(severity) == OPAL_EEH_SEV_INF) { 785 786 pr_info("EEH: PHB#%x informative error " 786 787 "detected\n", 787 788 hose->global_number); ··· 802 801 * progress with recovery. We needn't report 803 802 * it again. 804 803 */ 805 - if (ioda_eeh_get_pe(hose, frozen_pe_no, pe)) { 804 + if (ioda_eeh_get_pe(hose, 805 + be64_to_cpu(frozen_pe_no), pe)) { 806 806 *pe = phb_pe; 807 807 pr_err("EEH: Escalated fenced PHB#%x " 808 808 "detected for PE#%llx\n", 809 809 hose->global_number, 810 - frozen_pe_no); 810 + be64_to_cpu(frozen_pe_no)); 811 811 ret = EEH_NEXT_ERR_FENCED_PHB; 812 812 } else if ((*pe)->state & EEH_PE_ISOLATED) { 813 813 ret = EEH_NEXT_ERR_NONE; ··· 821 819 break; 822 820 default: 823 821 pr_warn("%s: Unexpected error type %d\n", 824 - __func__, err_type); 822 + __func__, be16_to_cpu(err_type)); 825 823 } 826 824 827 825 /*
+50 -31
arch/powerpc/platforms/powernv/pci.c
··· 206 206 207 207 data = (struct OpalIoPhb3ErrorData*)common; 208 208 pr_info("PHB3 PHB#%d Diag-data (Version: %d)\n", 209 - hose->global_number, common->version); 209 + hose->global_number, be32_to_cpu(common->version)); 210 210 if (data->brdgCtl) 211 211 pr_info("brdgCtl: %08x\n", 212 - data->brdgCtl); 212 + be32_to_cpu(data->brdgCtl)); 213 213 if (data->portStatusReg || data->rootCmplxStatus || 214 214 data->busAgentStatus) 215 215 pr_info("UtlSts: %08x %08x %08x\n", 216 - data->portStatusReg, data->rootCmplxStatus, 217 - data->busAgentStatus); 216 + be32_to_cpu(data->portStatusReg), 217 + be32_to_cpu(data->rootCmplxStatus), 218 + be32_to_cpu(data->busAgentStatus)); 218 219 if (data->deviceStatus || data->slotStatus || 219 220 data->linkStatus || data->devCmdStatus || 220 221 data->devSecStatus) 221 222 pr_info("RootSts: %08x %08x %08x %08x %08x\n", 222 - data->deviceStatus, data->slotStatus, 223 - data->linkStatus, data->devCmdStatus, 224 - data->devSecStatus); 223 + be32_to_cpu(data->deviceStatus), 224 + be32_to_cpu(data->slotStatus), 225 + be32_to_cpu(data->linkStatus), 226 + be32_to_cpu(data->devCmdStatus), 227 + be32_to_cpu(data->devSecStatus)); 225 228 if (data->rootErrorStatus || data->uncorrErrorStatus || 226 229 data->corrErrorStatus) 227 230 pr_info("RootErrSts: %08x %08x %08x\n", 228 - data->rootErrorStatus, data->uncorrErrorStatus, 229 - data->corrErrorStatus); 231 + be32_to_cpu(data->rootErrorStatus), 232 + be32_to_cpu(data->uncorrErrorStatus), 233 + be32_to_cpu(data->corrErrorStatus)); 230 234 if (data->tlpHdr1 || data->tlpHdr2 || 231 235 data->tlpHdr3 || data->tlpHdr4) 232 236 pr_info("RootErrLog: %08x %08x %08x %08x\n", 233 - data->tlpHdr1, data->tlpHdr2, 234 - data->tlpHdr3, data->tlpHdr4); 237 + be32_to_cpu(data->tlpHdr1), 238 + be32_to_cpu(data->tlpHdr2), 239 + be32_to_cpu(data->tlpHdr3), 240 + be32_to_cpu(data->tlpHdr4)); 235 241 if (data->sourceId || data->errorClass || 236 242 data->correlator) 237 243 pr_info("RootErrLog1: %08x %016llx %016llx\n", 238 - data->sourceId, data->errorClass, 239 - data->correlator); 244 + be32_to_cpu(data->sourceId), 245 + be64_to_cpu(data->errorClass), 246 + be64_to_cpu(data->correlator)); 240 247 if (data->nFir) 241 248 pr_info("nFir: %016llx %016llx %016llx\n", 242 - data->nFir, data->nFirMask, 243 - data->nFirWOF); 249 + be64_to_cpu(data->nFir), 250 + be64_to_cpu(data->nFirMask), 251 + be64_to_cpu(data->nFirWOF)); 244 252 if (data->phbPlssr || data->phbCsr) 245 253 pr_info("PhbSts: %016llx %016llx\n", 246 - data->phbPlssr, data->phbCsr); 254 + be64_to_cpu(data->phbPlssr), 255 + be64_to_cpu(data->phbCsr)); 247 256 if (data->lemFir) 248 257 pr_info("Lem: %016llx %016llx %016llx\n", 249 - data->lemFir, data->lemErrorMask, 250 - data->lemWOF); 258 + be64_to_cpu(data->lemFir), 259 + be64_to_cpu(data->lemErrorMask), 260 + be64_to_cpu(data->lemWOF)); 251 261 if (data->phbErrorStatus) 252 262 pr_info("PhbErr: %016llx %016llx %016llx %016llx\n", 253 - data->phbErrorStatus, data->phbFirstErrorStatus, 254 - data->phbErrorLog0, data->phbErrorLog1); 263 + be64_to_cpu(data->phbErrorStatus), 264 + be64_to_cpu(data->phbFirstErrorStatus), 265 + be64_to_cpu(data->phbErrorLog0), 266 + be64_to_cpu(data->phbErrorLog1)); 255 267 if (data->mmioErrorStatus) 256 268 pr_info("OutErr: %016llx %016llx %016llx %016llx\n", 257 - data->mmioErrorStatus, data->mmioFirstErrorStatus, 258 - data->mmioErrorLog0, data->mmioErrorLog1); 269 + be64_to_cpu(data->mmioErrorStatus), 270 + be64_to_cpu(data->mmioFirstErrorStatus), 271 + be64_to_cpu(data->mmioErrorLog0), 272 + be64_to_cpu(data->mmioErrorLog1)); 259 273 if (data->dma0ErrorStatus) 260 274 pr_info("InAErr: %016llx %016llx %016llx %016llx\n", 261 - data->dma0ErrorStatus, data->dma0FirstErrorStatus, 262 - data->dma0ErrorLog0, data->dma0ErrorLog1); 275 + be64_to_cpu(data->dma0ErrorStatus), 276 + be64_to_cpu(data->dma0FirstErrorStatus), 277 + be64_to_cpu(data->dma0ErrorLog0), 278 + be64_to_cpu(data->dma0ErrorLog1)); 263 279 if (data->dma1ErrorStatus) 264 280 pr_info("InBErr: %016llx %016llx %016llx %016llx\n", 265 - data->dma1ErrorStatus, data->dma1FirstErrorStatus, 266 - data->dma1ErrorLog0, data->dma1ErrorLog1); 281 + be64_to_cpu(data->dma1ErrorStatus), 282 + be64_to_cpu(data->dma1FirstErrorStatus), 283 + be64_to_cpu(data->dma1ErrorLog0), 284 + be64_to_cpu(data->dma1ErrorLog1)); 267 285 268 286 for (i = 0; i < OPAL_PHB3_NUM_PEST_REGS; i++) { 269 - if ((data->pestA[i] >> 63) == 0 && 270 - (data->pestB[i] >> 63) == 0) 287 + if ((be64_to_cpu(data->pestA[i]) >> 63) == 0 && 288 + (be64_to_cpu(data->pestB[i]) >> 63) == 0) 271 289 continue; 272 290 273 291 pr_info("PE[%3d] A/B: %016llx %016llx\n", 274 - i, data->pestA[i], data->pestB[i]); 292 + i, be64_to_cpu(data->pestA[i]), 293 + be64_to_cpu(data->pestB[i])); 275 294 } 276 295 } 277 296 ··· 303 284 return; 304 285 305 286 common = (struct OpalIoPhbErrorCommon *)log_buff; 306 - switch (common->ioType) { 287 + switch (be32_to_cpu(common->ioType)) { 307 288 case OPAL_PHB_ERROR_DATA_TYPE_P7IOC: 308 289 pnv_pci_dump_p7ioc_diag_data(hose, common); 309 290 break; ··· 312 293 break; 313 294 default: 314 295 pr_warn("%s: Unrecognized ioType %d\n", 315 - __func__, common->ioType); 296 + __func__, be32_to_cpu(common->ioType)); 316 297 } 317 298 } 318 299