On Wed, Feb 15, 2023 at 01:05:20PM +0800, Li, Ming wrote: > On 2/11/2023 4:25 AM, Lukas Wunner wrote: > > An upcoming user of DOE is CMA (Component Measurement and Authentication, > > PCIe r6.0 sec 6.31). > > > > It builds on SPDM (Security Protocol and Data Model): > > https://www.dmtf.org/dsp/DSP0274 > > > > SPDM message sizes are not always a multiple of dwords. To transport > > them over DOE without using bounce buffers, allow sending requests and > > receiving responses whose final dword is only partially populated. [...] > > + if (payload_length) { > > + /* Read all payload dwords except the last */ > > + for (; i < payload_length - 1; i++) { > > + pci_read_config_dword(pdev, offset + PCI_DOE_READ, > > + &val); > > + task->response_pl[i] = cpu_to_le32(val); > > + pci_write_config_dword(pdev, offset + PCI_DOE_READ, 0); > > + } > > + > > + /* Read last payload dword */ > > pci_read_config_dword(pdev, offset + PCI_DOE_READ, &val); > > - task->response_pl[i] = cpu_to_le32(val); > > + cpu_to_le32s(&val); > > + memcpy(&task->response_pl[i], &val, remainder); > > This "Read last payload dword" seems like making sense only when remainder != sizeof(u32). > If remainder == sizeof(u32), it should be read in above reading loops. > But this implementation also looks good to me. The last payload dword requires special handling anyway because of the Data Object Ready check (see quoted remainder of the function below). Up until now that special handling is done with an if-clause that checks if the last loop iteration has been reached. The support for non-dword responses adds more special handling of the last payload dword, which is why I decided to go the full distance and move handling of the last dword out of the loop. Thanks, Lukas > > /* Prior to the last ack, ensure Data Object Ready */ > > - if (i == (payload_length - 1) && !pci_doe_data_obj_ready(doe_mb)) > > + if (!pci_doe_data_obj_ready(doe_mb)) > > return -EIO; > > pci_write_config_dword(pdev, offset + PCI_DOE_READ, 0); > > + i++; > > } > > > > /* Flush excess length */