{"id":659,"date":"2015-11-27T13:15:20","date_gmt":"2015-11-27T04:15:20","guid":{"rendered":"http:\/\/naraeon.net\/?p=659"},"modified":"2024-09-24T22:43:38","modified_gmt":"2024-09-24T13:43:38","slug":"pci-express-linkwidth-linkspeed","status":"publish","type":"post","link":"https:\/\/www.naraeon.net\/en\/pci-express-linkwidth-linkspeed\/","title":{"rendered":"Get PCI express link width \/ specification version Programmatically"},"content":{"rendered":"<p>Many people include me find how to get PCI express link width \/ specification version programmatically. But there&#8217;re too many useless articles. Like examples about NetworkAdapters(I applied &#8220;-NetworkAdapter&#8221; and 90% of search results are gone!). And some of the remaining results say it must be solved with drivers. Others say just give up windows and use linux(?).<br \/>\nUnfortunately now I don&#8217;t have any reference link, because of the <a href=\"https:\/\/www.naraeon.net\/samsung-950-pro-nvme-passthrough\/\">catastrophic failure of my RAID1 storage<\/a>.<\/p>\n<h2>1. WMI<\/h2>\n<p>Cannot do this. <a href=\"http:\/\/www.programdoc.com\/38_1126_1.htm\">One of the answer from programdoc<\/a> says, even WMI specialist can&#8217;t do this.<br \/>\nI found a crude hack to do this. Please aware it&#8217;s a hack. I don&#8217;t guarantee anything about next queries.<\/p>\n<p>Firstly get DeviceID <span class=\"pl-s\">Property<\/span> of drive.<br \/>\nASSOCIATORS OF {Win32_DiskDrive.DeviceID=&#8217;\\\\.\\PhysicalDrive(Number)&#8217;} WHERE ResultClass=Win32_PnPEntity<br \/>\nThen get DeviceID\u00a0<span class=\"pl-s\">Property<\/span> of controller.<br \/>\nASSOCIATORS OF {Win32_PnPEntity.DeviceID='(DeviceID from above query result)&#8217;} WHERE AssocClass=Win32_SCSIControllerDevice<br \/>\n<span class=\"pl-s\">Get bus number(BusNum Property) of the controller.<br \/>\nASSOCIATORS OF {Win32_PnPEntity.DeviceID=<span class=\"pl-cce\">&#8216;(DeviceID from above query result)&#8217;} WHERE AssocClass=Win32_DeviceBus<br \/>\nLastly Find the bus number(BusNumber Property) in Win32_SystemSlot classes.<br \/>\nSELECT * FROM Win32_SystemSlot WHERE BusNumber='(BusNum from above query result)&#8217;<br \/>\n<\/span><\/span><br \/>\nIn this way, you can find link width with MaxDataWidth property. Since it is gathered from SMBIOS, +3 from its value and you can read the value in SMBIOS way.<br \/>\nBut in this way you can&#8217;t get the specification version. Though SMBIOS specification has seperated value for 1.0, 2.0, 3.0 slot, mainboards like mine(B75M) only shows 1.0 value.<br \/>\nIn short, the problem is that, the relationship between bus and slot is hard to find.<\/p>\n<h2>2. Driver<\/h2>\n<p>Read the PCI Express register. I didn&#8217;t tried this way. It needs too much efforts to do this small thing.<\/p>\n<h2>3. WMI + SetupAPI<\/h2>\n<p>Here comes the ultimate solution.<br \/>\nFirstly execute to the second query at &#8216;1. WMI&#8217; section. Then you&#8217;ll get DeviceID of the controller.<br \/>\nThen open the class with SetupDiGetClassDevs function. You can find class GUID at Device Manager \u2192 Select Device and Open Properties \u2192 Details \u2192 Class GUID.<br \/>\nTo find the device with the same DeviceID, iterate devices with SetupDiEnumDeviceInfo and get DeviceID with CM_Get_Device_IDW.<br \/>\nIf you find the device, use SetupDiGetDeviceProperty with next keys.<\/p>\n<p>DEVPKEY_PciDevice_CurrentLinkSpeed (pid: 9)<br \/>\nDEVPKEY_PciDevice_CurrentLinkWidth (pid: 10)<br \/>\nDEVPKEY_PciDevice_MaxLinkSpeed (pid: 11)<br \/>\nDEVPKEY_PciDevice_MaxLinkWidth (pid: 12)<\/p>\n<p>GUID for them is {3ab22e31-8264-4b4e-9af5-a8d2d8e33e62}.<br \/>\nMax- means maximum values that device supports, Current- means negotiated values.<br \/>\n-LinkSpeed represents specification version, -LinkWidth represents number of lanes. Be aware of LinkWidth value is the raw value so don&#8217;t try to read this in SMBIOS way.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Many people include me find how to get PCI express link width \/ specification version programmatically. But there&#8217;re too many useless articles. Like examples about NetworkAdapters(I applied &#8220;-NetworkAdapter&#8221; and 90% of search results are gone!). And some of the remaining results say it must be solved with drivers. Others say just give up windows and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[57],"tags":[58,62,99,61,60,100],"class_list":["post-659","post","type-post","status-publish","format-standard","hentry","category-nvmetools","tag-nvme","tag-nvmexpress","tag-pciexpress","tag-samsung950","tag-samsung950pro","tag-wmi"],"translation":{"provider":"WPGlobus","version":"3.0.2","language":"en","enabled_languages":["kr","en"],"languages":{"kr":{"title":true,"content":true,"excerpt":false},"en":{"title":true,"content":true,"excerpt":false}}},"_links":{"self":[{"href":"https:\/\/www.naraeon.net\/en\/wp-json\/wp\/v2\/posts\/659","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.naraeon.net\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.naraeon.net\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.naraeon.net\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.naraeon.net\/en\/wp-json\/wp\/v2\/comments?post=659"}],"version-history":[{"count":12,"href":"https:\/\/www.naraeon.net\/en\/wp-json\/wp\/v2\/posts\/659\/revisions"}],"predecessor-version":[{"id":1862,"href":"https:\/\/www.naraeon.net\/en\/wp-json\/wp\/v2\/posts\/659\/revisions\/1862"}],"wp:attachment":[{"href":"https:\/\/www.naraeon.net\/en\/wp-json\/wp\/v2\/media?parent=659"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.naraeon.net\/en\/wp-json\/wp\/v2\/categories?post=659"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.naraeon.net\/en\/wp-json\/wp\/v2\/tags?post=659"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}