mpt2sas_transport.c 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023
  1. /*
  2. * SAS Transport Layer for MPT (Message Passing Technology) based controllers
  3. *
  4. * This code is based on drivers/scsi/mpt2sas/mpt2_transport.c
  5. * Copyright (C) 2007-2010 LSI Corporation
  6. * (mailto:DL-MPTFusionLinux@lsi.com)
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * NO WARRANTY
  19. * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
  20. * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
  21. * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
  22. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
  23. * solely responsible for determining the appropriateness of using and
  24. * distributing the Program and assumes all risks associated with its
  25. * exercise of rights under this Agreement, including but not limited to
  26. * the risks and costs of program errors, damage to or loss of data,
  27. * programs or equipment, and unavailability or interruption of operations.
  28. * DISCLAIMER OF LIABILITY
  29. * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
  30. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31. * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
  32. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  33. * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  34. * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
  35. * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
  36. * You should have received a copy of the GNU General Public License
  37. * along with this program; if not, write to the Free Software
  38. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
  39. * USA.
  40. */
  41. #include <linux/module.h>
  42. #include <linux/kernel.h>
  43. #include <linux/init.h>
  44. #include <linux/errno.h>
  45. #include <linux/sched.h>
  46. #include <linux/workqueue.h>
  47. #include <linux/delay.h>
  48. #include <linux/pci.h>
  49. #include <linux/slab.h>
  50. #include <scsi/scsi.h>
  51. #include <scsi/scsi_cmnd.h>
  52. #include <scsi/scsi_device.h>
  53. #include <scsi/scsi_host.h>
  54. #include <scsi/scsi_transport_sas.h>
  55. #include <scsi/scsi_dbg.h>
  56. #include "mpt2sas_base.h"
  57. /**
  58. * _transport_sas_node_find_by_sas_address - sas node search
  59. * @ioc: per adapter object
  60. * @sas_address: sas address of expander or sas host
  61. * Context: Calling function should acquire ioc->sas_node_lock.
  62. *
  63. * Search for either hba phys or expander device based on handle, then returns
  64. * the sas_node object.
  65. */
  66. static struct _sas_node *
  67. _transport_sas_node_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
  68. u64 sas_address)
  69. {
  70. if (ioc->sas_hba.sas_address == sas_address)
  71. return &ioc->sas_hba;
  72. else
  73. return mpt2sas_scsih_expander_find_by_sas_address(ioc,
  74. sas_address);
  75. }
  76. /**
  77. * _transport_convert_phy_link_rate -
  78. * @link_rate: link rate returned from mpt firmware
  79. *
  80. * Convert link_rate from mpi fusion into sas_transport form.
  81. */
  82. static enum sas_linkrate
  83. _transport_convert_phy_link_rate(u8 link_rate)
  84. {
  85. enum sas_linkrate rc;
  86. switch (link_rate) {
  87. case MPI2_SAS_NEG_LINK_RATE_1_5:
  88. rc = SAS_LINK_RATE_1_5_GBPS;
  89. break;
  90. case MPI2_SAS_NEG_LINK_RATE_3_0:
  91. rc = SAS_LINK_RATE_3_0_GBPS;
  92. break;
  93. case MPI2_SAS_NEG_LINK_RATE_6_0:
  94. rc = SAS_LINK_RATE_6_0_GBPS;
  95. break;
  96. case MPI2_SAS_NEG_LINK_RATE_PHY_DISABLED:
  97. rc = SAS_PHY_DISABLED;
  98. break;
  99. case MPI2_SAS_NEG_LINK_RATE_NEGOTIATION_FAILED:
  100. rc = SAS_LINK_RATE_FAILED;
  101. break;
  102. case MPI2_SAS_NEG_LINK_RATE_PORT_SELECTOR:
  103. rc = SAS_SATA_PORT_SELECTOR;
  104. break;
  105. case MPI2_SAS_NEG_LINK_RATE_SMP_RESET_IN_PROGRESS:
  106. rc = SAS_PHY_RESET_IN_PROGRESS;
  107. break;
  108. default:
  109. case MPI2_SAS_NEG_LINK_RATE_SATA_OOB_COMPLETE:
  110. case MPI2_SAS_NEG_LINK_RATE_UNKNOWN_LINK_RATE:
  111. rc = SAS_LINK_RATE_UNKNOWN;
  112. break;
  113. }
  114. return rc;
  115. }
  116. /**
  117. * _transport_set_identify - set identify for phys and end devices
  118. * @ioc: per adapter object
  119. * @handle: device handle
  120. * @identify: sas identify info
  121. *
  122. * Populates sas identify info.
  123. *
  124. * Returns 0 for success, non-zero for failure.
  125. */
  126. static int
  127. _transport_set_identify(struct MPT2SAS_ADAPTER *ioc, u16 handle,
  128. struct sas_identify *identify)
  129. {
  130. Mpi2SasDevicePage0_t sas_device_pg0;
  131. Mpi2ConfigReply_t mpi_reply;
  132. u32 device_info;
  133. u32 ioc_status;
  134. if (ioc->shost_recovery || ioc->pci_error_recovery) {
  135. printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
  136. __func__, ioc->name);
  137. return -EFAULT;
  138. }
  139. if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
  140. MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
  141. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  142. ioc->name, __FILE__, __LINE__, __func__);
  143. return -ENXIO;
  144. }
  145. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  146. MPI2_IOCSTATUS_MASK;
  147. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  148. printk(MPT2SAS_ERR_FMT "handle(0x%04x), ioc_status(0x%04x)"
  149. "\nfailure at %s:%d/%s()!\n", ioc->name, handle, ioc_status,
  150. __FILE__, __LINE__, __func__);
  151. return -EIO;
  152. }
  153. memset(identify, 0, sizeof(*identify));
  154. device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
  155. /* sas_address */
  156. identify->sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
  157. /* device_type */
  158. switch (device_info & MPI2_SAS_DEVICE_INFO_MASK_DEVICE_TYPE) {
  159. case MPI2_SAS_DEVICE_INFO_NO_DEVICE:
  160. identify->device_type = SAS_PHY_UNUSED;
  161. break;
  162. case MPI2_SAS_DEVICE_INFO_END_DEVICE:
  163. identify->device_type = SAS_END_DEVICE;
  164. break;
  165. case MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER:
  166. identify->device_type = SAS_EDGE_EXPANDER_DEVICE;
  167. break;
  168. case MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER:
  169. identify->device_type = SAS_FANOUT_EXPANDER_DEVICE;
  170. break;
  171. }
  172. /* initiator_port_protocols */
  173. if (device_info & MPI2_SAS_DEVICE_INFO_SSP_INITIATOR)
  174. identify->initiator_port_protocols |= SAS_PROTOCOL_SSP;
  175. if (device_info & MPI2_SAS_DEVICE_INFO_STP_INITIATOR)
  176. identify->initiator_port_protocols |= SAS_PROTOCOL_STP;
  177. if (device_info & MPI2_SAS_DEVICE_INFO_SMP_INITIATOR)
  178. identify->initiator_port_protocols |= SAS_PROTOCOL_SMP;
  179. if (device_info & MPI2_SAS_DEVICE_INFO_SATA_HOST)
  180. identify->initiator_port_protocols |= SAS_PROTOCOL_SATA;
  181. /* target_port_protocols */
  182. if (device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET)
  183. identify->target_port_protocols |= SAS_PROTOCOL_SSP;
  184. if (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET)
  185. identify->target_port_protocols |= SAS_PROTOCOL_STP;
  186. if (device_info & MPI2_SAS_DEVICE_INFO_SMP_TARGET)
  187. identify->target_port_protocols |= SAS_PROTOCOL_SMP;
  188. if (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
  189. identify->target_port_protocols |= SAS_PROTOCOL_SATA;
  190. return 0;
  191. }
  192. /**
  193. * mpt2sas_transport_done - internal transport layer callback handler.
  194. * @ioc: per adapter object
  195. * @smid: system request message index
  196. * @msix_index: MSIX table index supplied by the OS
  197. * @reply: reply message frame(lower 32bit addr)
  198. *
  199. * Callback handler when sending internal generated transport cmds.
  200. * The callback index passed is `ioc->transport_cb_idx`
  201. *
  202. * Return 1 meaning mf should be freed from _base_interrupt
  203. * 0 means the mf is freed from this function.
  204. */
  205. u8
  206. mpt2sas_transport_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
  207. u32 reply)
  208. {
  209. MPI2DefaultReply_t *mpi_reply;
  210. mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
  211. if (ioc->transport_cmds.status == MPT2_CMD_NOT_USED)
  212. return 1;
  213. if (ioc->transport_cmds.smid != smid)
  214. return 1;
  215. ioc->transport_cmds.status |= MPT2_CMD_COMPLETE;
  216. if (mpi_reply) {
  217. memcpy(ioc->transport_cmds.reply, mpi_reply,
  218. mpi_reply->MsgLength*4);
  219. ioc->transport_cmds.status |= MPT2_CMD_REPLY_VALID;
  220. }
  221. ioc->transport_cmds.status &= ~MPT2_CMD_PENDING;
  222. complete(&ioc->transport_cmds.done);
  223. return 1;
  224. }
  225. /* report manufacture request structure */
  226. struct rep_manu_request{
  227. u8 smp_frame_type;
  228. u8 function;
  229. u8 reserved;
  230. u8 request_length;
  231. };
  232. /* report manufacture reply structure */
  233. struct rep_manu_reply{
  234. u8 smp_frame_type; /* 0x41 */
  235. u8 function; /* 0x01 */
  236. u8 function_result;
  237. u8 response_length;
  238. u16 expander_change_count;
  239. u8 reserved0[2];
  240. u8 sas_format;
  241. u8 reserved2[3];
  242. u8 vendor_id[SAS_EXPANDER_VENDOR_ID_LEN];
  243. u8 product_id[SAS_EXPANDER_PRODUCT_ID_LEN];
  244. u8 product_rev[SAS_EXPANDER_PRODUCT_REV_LEN];
  245. u8 component_vendor_id[SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN];
  246. u16 component_id;
  247. u8 component_revision_id;
  248. u8 reserved3;
  249. u8 vendor_specific[8];
  250. };
  251. /**
  252. * _transport_expander_report_manufacture - obtain SMP report_manufacture
  253. * @ioc: per adapter object
  254. * @sas_address: expander sas address
  255. * @edev: the sas_expander_device object
  256. *
  257. * Fills in the sas_expander_device object when SMP port is created.
  258. *
  259. * Returns 0 for success, non-zero for failure.
  260. */
  261. static int
  262. _transport_expander_report_manufacture(struct MPT2SAS_ADAPTER *ioc,
  263. u64 sas_address, struct sas_expander_device *edev)
  264. {
  265. Mpi2SmpPassthroughRequest_t *mpi_request;
  266. Mpi2SmpPassthroughReply_t *mpi_reply;
  267. struct rep_manu_reply *manufacture_reply;
  268. struct rep_manu_request *manufacture_request;
  269. int rc;
  270. u16 smid;
  271. u32 ioc_state;
  272. unsigned long timeleft;
  273. void *psge;
  274. u32 sgl_flags;
  275. u8 issue_reset = 0;
  276. void *data_out = NULL;
  277. dma_addr_t data_out_dma;
  278. u32 sz;
  279. u16 wait_state_count;
  280. if (ioc->shost_recovery || ioc->pci_error_recovery) {
  281. printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
  282. __func__, ioc->name);
  283. return -EFAULT;
  284. }
  285. mutex_lock(&ioc->transport_cmds.mutex);
  286. if (ioc->transport_cmds.status != MPT2_CMD_NOT_USED) {
  287. printk(MPT2SAS_ERR_FMT "%s: transport_cmds in use\n",
  288. ioc->name, __func__);
  289. rc = -EAGAIN;
  290. goto out;
  291. }
  292. ioc->transport_cmds.status = MPT2_CMD_PENDING;
  293. wait_state_count = 0;
  294. ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
  295. while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
  296. if (wait_state_count++ == 10) {
  297. printk(MPT2SAS_ERR_FMT
  298. "%s: failed due to ioc not operational\n",
  299. ioc->name, __func__);
  300. rc = -EFAULT;
  301. goto out;
  302. }
  303. ssleep(1);
  304. ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
  305. printk(MPT2SAS_INFO_FMT "%s: waiting for "
  306. "operational state(count=%d)\n", ioc->name,
  307. __func__, wait_state_count);
  308. }
  309. if (wait_state_count)
  310. printk(MPT2SAS_INFO_FMT "%s: ioc is operational\n",
  311. ioc->name, __func__);
  312. smid = mpt2sas_base_get_smid(ioc, ioc->transport_cb_idx);
  313. if (!smid) {
  314. printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
  315. ioc->name, __func__);
  316. rc = -EAGAIN;
  317. goto out;
  318. }
  319. rc = 0;
  320. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
  321. ioc->transport_cmds.smid = smid;
  322. sz = sizeof(struct rep_manu_request) + sizeof(struct rep_manu_reply);
  323. data_out = pci_alloc_consistent(ioc->pdev, sz, &data_out_dma);
  324. if (!data_out) {
  325. printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__,
  326. __LINE__, __func__);
  327. rc = -ENOMEM;
  328. mpt2sas_base_free_smid(ioc, smid);
  329. goto out;
  330. }
  331. manufacture_request = data_out;
  332. manufacture_request->smp_frame_type = 0x40;
  333. manufacture_request->function = 1;
  334. manufacture_request->reserved = 0;
  335. manufacture_request->request_length = 0;
  336. memset(mpi_request, 0, sizeof(Mpi2SmpPassthroughRequest_t));
  337. mpi_request->Function = MPI2_FUNCTION_SMP_PASSTHROUGH;
  338. mpi_request->PhysicalPort = 0xFF;
  339. mpi_request->VF_ID = 0; /* TODO */
  340. mpi_request->VP_ID = 0;
  341. mpi_request->SASAddress = cpu_to_le64(sas_address);
  342. mpi_request->RequestDataLength =
  343. cpu_to_le16(sizeof(struct rep_manu_request));
  344. psge = &mpi_request->SGL;
  345. /* WRITE sgel first */
  346. sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT |
  347. MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_HOST_TO_IOC);
  348. sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
  349. ioc->base_add_sg_single(psge, sgl_flags |
  350. sizeof(struct rep_manu_request), data_out_dma);
  351. /* incr sgel */
  352. psge += ioc->sge_size;
  353. /* READ sgel last */
  354. sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT |
  355. MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER |
  356. MPI2_SGE_FLAGS_END_OF_LIST);
  357. sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
  358. ioc->base_add_sg_single(psge, sgl_flags |
  359. sizeof(struct rep_manu_reply), data_out_dma +
  360. sizeof(struct rep_manu_request));
  361. dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT "report_manufacture - "
  362. "send to sas_addr(0x%016llx)\n", ioc->name,
  363. (unsigned long long)sas_address));
  364. init_completion(&ioc->transport_cmds.done);
  365. mpt2sas_base_put_smid_default(ioc, smid);
  366. timeleft = wait_for_completion_timeout(&ioc->transport_cmds.done,
  367. 10*HZ);
  368. if (!(ioc->transport_cmds.status & MPT2_CMD_COMPLETE)) {
  369. printk(MPT2SAS_ERR_FMT "%s: timeout\n",
  370. ioc->name, __func__);
  371. _debug_dump_mf(mpi_request,
  372. sizeof(Mpi2SmpPassthroughRequest_t)/4);
  373. if (!(ioc->transport_cmds.status & MPT2_CMD_RESET))
  374. issue_reset = 1;
  375. goto issue_host_reset;
  376. }
  377. dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT "report_manufacture - "
  378. "complete\n", ioc->name));
  379. if (ioc->transport_cmds.status & MPT2_CMD_REPLY_VALID) {
  380. u8 *tmp;
  381. mpi_reply = ioc->transport_cmds.reply;
  382. dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT
  383. "report_manufacture - reply data transfer size(%d)\n",
  384. ioc->name, le16_to_cpu(mpi_reply->ResponseDataLength)));
  385. if (le16_to_cpu(mpi_reply->ResponseDataLength) !=
  386. sizeof(struct rep_manu_reply))
  387. goto out;
  388. manufacture_reply = data_out + sizeof(struct rep_manu_request);
  389. strncpy(edev->vendor_id, manufacture_reply->vendor_id,
  390. SAS_EXPANDER_VENDOR_ID_LEN);
  391. strncpy(edev->product_id, manufacture_reply->product_id,
  392. SAS_EXPANDER_PRODUCT_ID_LEN);
  393. strncpy(edev->product_rev, manufacture_reply->product_rev,
  394. SAS_EXPANDER_PRODUCT_REV_LEN);
  395. edev->level = manufacture_reply->sas_format & 1;
  396. if (edev->level) {
  397. strncpy(edev->component_vendor_id,
  398. manufacture_reply->component_vendor_id,
  399. SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN);
  400. tmp = (u8 *)&manufacture_reply->component_id;
  401. edev->component_id = tmp[0] << 8 | tmp[1];
  402. edev->component_revision_id =
  403. manufacture_reply->component_revision_id;
  404. }
  405. } else
  406. dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT
  407. "report_manufacture - no reply\n", ioc->name));
  408. issue_host_reset:
  409. if (issue_reset)
  410. mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
  411. FORCE_BIG_HAMMER);
  412. out:
  413. ioc->transport_cmds.status = MPT2_CMD_NOT_USED;
  414. if (data_out)
  415. pci_free_consistent(ioc->pdev, sz, data_out, data_out_dma);
  416. mutex_unlock(&ioc->transport_cmds.mutex);
  417. return rc;
  418. }
  419. /**
  420. * _transport_delete_port - helper function to removing a port
  421. * @ioc: per adapter object
  422. * @mpt2sas_port: mpt2sas per port object
  423. *
  424. * Returns nothing.
  425. */
  426. static void
  427. _transport_delete_port(struct MPT2SAS_ADAPTER *ioc,
  428. struct _sas_port *mpt2sas_port)
  429. {
  430. u64 sas_address = mpt2sas_port->remote_identify.sas_address;
  431. enum sas_device_type device_type =
  432. mpt2sas_port->remote_identify.device_type;
  433. dev_printk(KERN_INFO, &mpt2sas_port->port->dev,
  434. "remove: sas_addr(0x%016llx)\n",
  435. (unsigned long long) sas_address);
  436. ioc->logging_level |= MPT_DEBUG_TRANSPORT;
  437. if (device_type == SAS_END_DEVICE)
  438. mpt2sas_device_remove(ioc, sas_address);
  439. else if (device_type == SAS_EDGE_EXPANDER_DEVICE ||
  440. device_type == SAS_FANOUT_EXPANDER_DEVICE)
  441. mpt2sas_expander_remove(ioc, sas_address);
  442. ioc->logging_level &= ~MPT_DEBUG_TRANSPORT;
  443. }
  444. /**
  445. * _transport_delete_phy - helper function to removing single phy from port
  446. * @ioc: per adapter object
  447. * @mpt2sas_port: mpt2sas per port object
  448. * @mpt2sas_phy: mpt2sas per phy object
  449. *
  450. * Returns nothing.
  451. */
  452. static void
  453. _transport_delete_phy(struct MPT2SAS_ADAPTER *ioc,
  454. struct _sas_port *mpt2sas_port, struct _sas_phy *mpt2sas_phy)
  455. {
  456. u64 sas_address = mpt2sas_port->remote_identify.sas_address;
  457. dev_printk(KERN_INFO, &mpt2sas_phy->phy->dev,
  458. "remove: sas_addr(0x%016llx), phy(%d)\n",
  459. (unsigned long long) sas_address, mpt2sas_phy->phy_id);
  460. list_del(&mpt2sas_phy->port_siblings);
  461. mpt2sas_port->num_phys--;
  462. sas_port_delete_phy(mpt2sas_port->port, mpt2sas_phy->phy);
  463. mpt2sas_phy->phy_belongs_to_port = 0;
  464. }
  465. /**
  466. * _transport_add_phy - helper function to adding single phy to port
  467. * @ioc: per adapter object
  468. * @mpt2sas_port: mpt2sas per port object
  469. * @mpt2sas_phy: mpt2sas per phy object
  470. *
  471. * Returns nothing.
  472. */
  473. static void
  474. _transport_add_phy(struct MPT2SAS_ADAPTER *ioc, struct _sas_port *mpt2sas_port,
  475. struct _sas_phy *mpt2sas_phy)
  476. {
  477. u64 sas_address = mpt2sas_port->remote_identify.sas_address;
  478. dev_printk(KERN_INFO, &mpt2sas_phy->phy->dev,
  479. "add: sas_addr(0x%016llx), phy(%d)\n", (unsigned long long)
  480. sas_address, mpt2sas_phy->phy_id);
  481. list_add_tail(&mpt2sas_phy->port_siblings, &mpt2sas_port->phy_list);
  482. mpt2sas_port->num_phys++;
  483. sas_port_add_phy(mpt2sas_port->port, mpt2sas_phy->phy);
  484. mpt2sas_phy->phy_belongs_to_port = 1;
  485. }
  486. /**
  487. * _transport_add_phy_to_an_existing_port - adding new phy to existing port
  488. * @ioc: per adapter object
  489. * @sas_node: sas node object (either expander or sas host)
  490. * @mpt2sas_phy: mpt2sas per phy object
  491. * @sas_address: sas address of device/expander were phy needs to be added to
  492. *
  493. * Returns nothing.
  494. */
  495. static void
  496. _transport_add_phy_to_an_existing_port(struct MPT2SAS_ADAPTER *ioc,
  497. struct _sas_node *sas_node, struct _sas_phy *mpt2sas_phy, u64 sas_address)
  498. {
  499. struct _sas_port *mpt2sas_port;
  500. struct _sas_phy *phy_srch;
  501. if (mpt2sas_phy->phy_belongs_to_port == 1)
  502. return;
  503. list_for_each_entry(mpt2sas_port, &sas_node->sas_port_list,
  504. port_list) {
  505. if (mpt2sas_port->remote_identify.sas_address !=
  506. sas_address)
  507. continue;
  508. list_for_each_entry(phy_srch, &mpt2sas_port->phy_list,
  509. port_siblings) {
  510. if (phy_srch == mpt2sas_phy)
  511. return;
  512. }
  513. _transport_add_phy(ioc, mpt2sas_port, mpt2sas_phy);
  514. return;
  515. }
  516. }
  517. /**
  518. * _transport_del_phy_from_an_existing_port - delete phy from existing port
  519. * @ioc: per adapter object
  520. * @sas_node: sas node object (either expander or sas host)
  521. * @mpt2sas_phy: mpt2sas per phy object
  522. *
  523. * Returns nothing.
  524. */
  525. static void
  526. _transport_del_phy_from_an_existing_port(struct MPT2SAS_ADAPTER *ioc,
  527. struct _sas_node *sas_node, struct _sas_phy *mpt2sas_phy)
  528. {
  529. struct _sas_port *mpt2sas_port, *next;
  530. struct _sas_phy *phy_srch;
  531. if (mpt2sas_phy->phy_belongs_to_port == 0)
  532. return;
  533. list_for_each_entry_safe(mpt2sas_port, next, &sas_node->sas_port_list,
  534. port_list) {
  535. list_for_each_entry(phy_srch, &mpt2sas_port->phy_list,
  536. port_siblings) {
  537. if (phy_srch != mpt2sas_phy)
  538. continue;
  539. if (mpt2sas_port->num_phys == 1)
  540. _transport_delete_port(ioc, mpt2sas_port);
  541. else
  542. _transport_delete_phy(ioc, mpt2sas_port,
  543. mpt2sas_phy);
  544. return;
  545. }
  546. }
  547. }
  548. /**
  549. * _transport_sanity_check - sanity check when adding a new port
  550. * @ioc: per adapter object
  551. * @sas_node: sas node object (either expander or sas host)
  552. * @sas_address: sas address of device being added
  553. *
  554. * See the explanation above from _transport_delete_duplicate_port
  555. */
  556. static void
  557. _transport_sanity_check(struct MPT2SAS_ADAPTER *ioc, struct _sas_node *sas_node,
  558. u64 sas_address)
  559. {
  560. int i;
  561. for (i = 0; i < sas_node->num_phys; i++) {
  562. if (sas_node->phy[i].remote_identify.sas_address != sas_address)
  563. continue;
  564. if (sas_node->phy[i].phy_belongs_to_port == 1)
  565. _transport_del_phy_from_an_existing_port(ioc, sas_node,
  566. &sas_node->phy[i]);
  567. }
  568. }
  569. /**
  570. * mpt2sas_transport_port_add - insert port to the list
  571. * @ioc: per adapter object
  572. * @handle: handle of attached device
  573. * @sas_address: sas address of parent expander or sas host
  574. * Context: This function will acquire ioc->sas_node_lock.
  575. *
  576. * Adding new port object to the sas_node->sas_port_list.
  577. *
  578. * Returns mpt2sas_port.
  579. */
  580. struct _sas_port *
  581. mpt2sas_transport_port_add(struct MPT2SAS_ADAPTER *ioc, u16 handle,
  582. u64 sas_address)
  583. {
  584. struct _sas_phy *mpt2sas_phy, *next;
  585. struct _sas_port *mpt2sas_port;
  586. unsigned long flags;
  587. struct _sas_node *sas_node;
  588. struct sas_rphy *rphy;
  589. int i;
  590. struct sas_port *port;
  591. mpt2sas_port = kzalloc(sizeof(struct _sas_port),
  592. GFP_KERNEL);
  593. if (!mpt2sas_port) {
  594. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  595. ioc->name, __FILE__, __LINE__, __func__);
  596. return NULL;
  597. }
  598. INIT_LIST_HEAD(&mpt2sas_port->port_list);
  599. INIT_LIST_HEAD(&mpt2sas_port->phy_list);
  600. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  601. sas_node = _transport_sas_node_find_by_sas_address(ioc, sas_address);
  602. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  603. if (!sas_node) {
  604. printk(MPT2SAS_ERR_FMT "%s: Could not find "
  605. "parent sas_address(0x%016llx)!\n", ioc->name,
  606. __func__, (unsigned long long)sas_address);
  607. goto out_fail;
  608. }
  609. if ((_transport_set_identify(ioc, handle,
  610. &mpt2sas_port->remote_identify))) {
  611. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  612. ioc->name, __FILE__, __LINE__, __func__);
  613. goto out_fail;
  614. }
  615. if (mpt2sas_port->remote_identify.device_type == SAS_PHY_UNUSED) {
  616. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  617. ioc->name, __FILE__, __LINE__, __func__);
  618. goto out_fail;
  619. }
  620. _transport_sanity_check(ioc, sas_node,
  621. mpt2sas_port->remote_identify.sas_address);
  622. for (i = 0; i < sas_node->num_phys; i++) {
  623. if (sas_node->phy[i].remote_identify.sas_address !=
  624. mpt2sas_port->remote_identify.sas_address)
  625. continue;
  626. list_add_tail(&sas_node->phy[i].port_siblings,
  627. &mpt2sas_port->phy_list);
  628. mpt2sas_port->num_phys++;
  629. }
  630. if (!mpt2sas_port->num_phys) {
  631. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  632. ioc->name, __FILE__, __LINE__, __func__);
  633. goto out_fail;
  634. }
  635. port = sas_port_alloc_num(sas_node->parent_dev);
  636. if ((sas_port_add(port))) {
  637. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  638. ioc->name, __FILE__, __LINE__, __func__);
  639. goto out_fail;
  640. }
  641. list_for_each_entry(mpt2sas_phy, &mpt2sas_port->phy_list,
  642. port_siblings) {
  643. if ((ioc->logging_level & MPT_DEBUG_TRANSPORT))
  644. dev_printk(KERN_INFO, &port->dev, "add: handle(0x%04x)"
  645. ", sas_addr(0x%016llx), phy(%d)\n", handle,
  646. (unsigned long long)
  647. mpt2sas_port->remote_identify.sas_address,
  648. mpt2sas_phy->phy_id);
  649. sas_port_add_phy(port, mpt2sas_phy->phy);
  650. mpt2sas_phy->phy_belongs_to_port = 1;
  651. }
  652. mpt2sas_port->port = port;
  653. if (mpt2sas_port->remote_identify.device_type == SAS_END_DEVICE)
  654. rphy = sas_end_device_alloc(port);
  655. else
  656. rphy = sas_expander_alloc(port,
  657. mpt2sas_port->remote_identify.device_type);
  658. rphy->identify = mpt2sas_port->remote_identify;
  659. if ((sas_rphy_add(rphy))) {
  660. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  661. ioc->name, __FILE__, __LINE__, __func__);
  662. }
  663. if ((ioc->logging_level & MPT_DEBUG_TRANSPORT))
  664. dev_printk(KERN_INFO, &rphy->dev, "add: handle(0x%04x), "
  665. "sas_addr(0x%016llx)\n", handle,
  666. (unsigned long long)
  667. mpt2sas_port->remote_identify.sas_address);
  668. mpt2sas_port->rphy = rphy;
  669. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  670. list_add_tail(&mpt2sas_port->port_list, &sas_node->sas_port_list);
  671. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  672. /* fill in report manufacture */
  673. if (mpt2sas_port->remote_identify.device_type ==
  674. MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER ||
  675. mpt2sas_port->remote_identify.device_type ==
  676. MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER)
  677. _transport_expander_report_manufacture(ioc,
  678. mpt2sas_port->remote_identify.sas_address,
  679. rphy_to_expander_device(rphy));
  680. return mpt2sas_port;
  681. out_fail:
  682. list_for_each_entry_safe(mpt2sas_phy, next, &mpt2sas_port->phy_list,
  683. port_siblings)
  684. list_del(&mpt2sas_phy->port_siblings);
  685. kfree(mpt2sas_port);
  686. return NULL;
  687. }
  688. /**
  689. * mpt2sas_transport_port_remove - remove port from the list
  690. * @ioc: per adapter object
  691. * @sas_address: sas address of attached device
  692. * @sas_address_parent: sas address of parent expander or sas host
  693. * Context: This function will acquire ioc->sas_node_lock.
  694. *
  695. * Removing object and freeing associated memory from the
  696. * ioc->sas_port_list.
  697. *
  698. * Return nothing.
  699. */
  700. void
  701. mpt2sas_transport_port_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
  702. u64 sas_address_parent)
  703. {
  704. int i;
  705. unsigned long flags;
  706. struct _sas_port *mpt2sas_port, *next;
  707. struct _sas_node *sas_node;
  708. u8 found = 0;
  709. struct _sas_phy *mpt2sas_phy, *next_phy;
  710. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  711. sas_node = _transport_sas_node_find_by_sas_address(ioc,
  712. sas_address_parent);
  713. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  714. if (!sas_node)
  715. return;
  716. list_for_each_entry_safe(mpt2sas_port, next, &sas_node->sas_port_list,
  717. port_list) {
  718. if (mpt2sas_port->remote_identify.sas_address != sas_address)
  719. continue;
  720. found = 1;
  721. list_del(&mpt2sas_port->port_list);
  722. goto out;
  723. }
  724. out:
  725. if (!found)
  726. return;
  727. for (i = 0; i < sas_node->num_phys; i++) {
  728. if (sas_node->phy[i].remote_identify.sas_address == sas_address)
  729. memset(&sas_node->phy[i].remote_identify, 0 ,
  730. sizeof(struct sas_identify));
  731. }
  732. list_for_each_entry_safe(mpt2sas_phy, next_phy,
  733. &mpt2sas_port->phy_list, port_siblings) {
  734. if ((ioc->logging_level & MPT_DEBUG_TRANSPORT))
  735. dev_printk(KERN_INFO, &mpt2sas_port->port->dev,
  736. "remove: sas_addr(0x%016llx), phy(%d)\n",
  737. (unsigned long long)
  738. mpt2sas_port->remote_identify.sas_address,
  739. mpt2sas_phy->phy_id);
  740. mpt2sas_phy->phy_belongs_to_port = 0;
  741. sas_port_delete_phy(mpt2sas_port->port, mpt2sas_phy->phy);
  742. list_del(&mpt2sas_phy->port_siblings);
  743. }
  744. sas_port_delete(mpt2sas_port->port);
  745. kfree(mpt2sas_port);
  746. }
  747. /**
  748. * mpt2sas_transport_add_host_phy - report sas_host phy to transport
  749. * @ioc: per adapter object
  750. * @mpt2sas_phy: mpt2sas per phy object
  751. * @phy_pg0: sas phy page 0
  752. * @parent_dev: parent device class object
  753. *
  754. * Returns 0 for success, non-zero for failure.
  755. */
  756. int
  757. mpt2sas_transport_add_host_phy(struct MPT2SAS_ADAPTER *ioc, struct _sas_phy
  758. *mpt2sas_phy, Mpi2SasPhyPage0_t phy_pg0, struct device *parent_dev)
  759. {
  760. struct sas_phy *phy;
  761. int phy_index = mpt2sas_phy->phy_id;
  762. INIT_LIST_HEAD(&mpt2sas_phy->port_siblings);
  763. phy = sas_phy_alloc(parent_dev, phy_index);
  764. if (!phy) {
  765. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  766. ioc->name, __FILE__, __LINE__, __func__);
  767. return -1;
  768. }
  769. if ((_transport_set_identify(ioc, mpt2sas_phy->handle,
  770. &mpt2sas_phy->identify))) {
  771. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  772. ioc->name, __FILE__, __LINE__, __func__);
  773. return -1;
  774. }
  775. phy->identify = mpt2sas_phy->identify;
  776. mpt2sas_phy->attached_handle = le16_to_cpu(phy_pg0.AttachedDevHandle);
  777. if (mpt2sas_phy->attached_handle)
  778. _transport_set_identify(ioc, mpt2sas_phy->attached_handle,
  779. &mpt2sas_phy->remote_identify);
  780. phy->identify.phy_identifier = mpt2sas_phy->phy_id;
  781. phy->negotiated_linkrate = _transport_convert_phy_link_rate(
  782. phy_pg0.NegotiatedLinkRate & MPI2_SAS_NEG_LINK_RATE_MASK_PHYSICAL);
  783. phy->minimum_linkrate_hw = _transport_convert_phy_link_rate(
  784. phy_pg0.HwLinkRate & MPI2_SAS_HWRATE_MIN_RATE_MASK);
  785. phy->maximum_linkrate_hw = _transport_convert_phy_link_rate(
  786. phy_pg0.HwLinkRate >> 4);
  787. phy->minimum_linkrate = _transport_convert_phy_link_rate(
  788. phy_pg0.ProgrammedLinkRate & MPI2_SAS_PRATE_MIN_RATE_MASK);
  789. phy->maximum_linkrate = _transport_convert_phy_link_rate(
  790. phy_pg0.ProgrammedLinkRate >> 4);
  791. if ((sas_phy_add(phy))) {
  792. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  793. ioc->name, __FILE__, __LINE__, __func__);
  794. sas_phy_free(phy);
  795. return -1;
  796. }
  797. if ((ioc->logging_level & MPT_DEBUG_TRANSPORT))
  798. dev_printk(KERN_INFO, &phy->dev,
  799. "add: handle(0x%04x), sas_addr(0x%016llx)\n"
  800. "\tattached_handle(0x%04x), sas_addr(0x%016llx)\n",
  801. mpt2sas_phy->handle, (unsigned long long)
  802. mpt2sas_phy->identify.sas_address,
  803. mpt2sas_phy->attached_handle,
  804. (unsigned long long)
  805. mpt2sas_phy->remote_identify.sas_address);
  806. mpt2sas_phy->phy = phy;
  807. return 0;
  808. }
  809. /**
  810. * mpt2sas_transport_add_expander_phy - report expander phy to transport
  811. * @ioc: per adapter object
  812. * @mpt2sas_phy: mpt2sas per phy object
  813. * @expander_pg1: expander page 1
  814. * @parent_dev: parent device class object
  815. *
  816. * Returns 0 for success, non-zero for failure.
  817. */
  818. int
  819. mpt2sas_transport_add_expander_phy(struct MPT2SAS_ADAPTER *ioc, struct _sas_phy
  820. *mpt2sas_phy, Mpi2ExpanderPage1_t expander_pg1, struct device *parent_dev)
  821. {
  822. struct sas_phy *phy;
  823. int phy_index = mpt2sas_phy->phy_id;
  824. INIT_LIST_HEAD(&mpt2sas_phy->port_siblings);
  825. phy = sas_phy_alloc(parent_dev, phy_index);
  826. if (!phy) {
  827. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  828. ioc->name, __FILE__, __LINE__, __func__);
  829. return -1;
  830. }
  831. if ((_transport_set_identify(ioc, mpt2sas_phy->handle,
  832. &mpt2sas_phy->identify))) {
  833. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  834. ioc->name, __FILE__, __LINE__, __func__);
  835. return -1;
  836. }
  837. phy->identify = mpt2sas_phy->identify;
  838. mpt2sas_phy->attached_handle =
  839. le16_to_cpu(expander_pg1.AttachedDevHandle);
  840. if (mpt2sas_phy->attached_handle)
  841. _transport_set_identify(ioc, mpt2sas_phy->attached_handle,
  842. &mpt2sas_phy->remote_identify);
  843. phy->identify.phy_identifier = mpt2sas_phy->phy_id;
  844. phy->negotiated_linkrate = _transport_convert_phy_link_rate(
  845. expander_pg1.NegotiatedLinkRate &
  846. MPI2_SAS_NEG_LINK_RATE_MASK_PHYSICAL);
  847. phy->minimum_linkrate_hw = _transport_convert_phy_link_rate(
  848. expander_pg1.HwLinkRate & MPI2_SAS_HWRATE_MIN_RATE_MASK);
  849. phy->maximum_linkrate_hw = _transport_convert_phy_link_rate(
  850. expander_pg1.HwLinkRate >> 4);
  851. phy->minimum_linkrate = _transport_convert_phy_link_rate(
  852. expander_pg1.ProgrammedLinkRate & MPI2_SAS_PRATE_MIN_RATE_MASK);
  853. phy->maximum_linkrate = _transport_convert_phy_link_rate(
  854. expander_pg1.ProgrammedLinkRate >> 4);
  855. if ((sas_phy_add(phy))) {
  856. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  857. ioc->name, __FILE__, __LINE__, __func__);
  858. sas_phy_free(phy);
  859. return -1;
  860. }
  861. if ((ioc->logging_level & MPT_DEBUG_TRANSPORT))
  862. dev_printk(KERN_INFO, &phy->dev,
  863. "add: handle(0x%04x), sas_addr(0x%016llx)\n"
  864. "\tattached_handle(0x%04x), sas_addr(0x%016llx)\n",
  865. mpt2sas_phy->handle, (unsigned long long)
  866. mpt2sas_phy->identify.sas_address,
  867. mpt2sas_phy->attached_handle,
  868. (unsigned long long)
  869. mpt2sas_phy->remote_identify.sas_address);
  870. mpt2sas_phy->phy = phy;
  871. return 0;
  872. }
  873. /**
  874. * mpt2sas_transport_update_links - refreshing phy link changes
  875. * @ioc: per adapter object
  876. * @sas_address: sas address of parent expander or sas host
  877. * @handle: attached device handle
  878. * @phy_numberv: phy number
  879. * @link_rate: new link rate
  880. *
  881. * Returns nothing.
  882. */
  883. void
  884. mpt2sas_transport_update_links(struct MPT2SAS_ADAPTER *ioc,
  885. u64 sas_address, u16 handle, u8 phy_number, u8 link_rate)
  886. {
  887. unsigned long flags;
  888. struct _sas_node *sas_node;
  889. struct _sas_phy *mpt2sas_phy;
  890. if (ioc->shost_recovery || ioc->pci_error_recovery)
  891. return;
  892. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  893. sas_node = _transport_sas_node_find_by_sas_address(ioc, sas_address);
  894. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  895. if (!sas_node)
  896. return;
  897. mpt2sas_phy = &sas_node->phy[phy_number];
  898. mpt2sas_phy->attached_handle = handle;
  899. if (handle && (link_rate >= MPI2_SAS_NEG_LINK_RATE_1_5)) {
  900. _transport_set_identify(ioc, handle,
  901. &mpt2sas_phy->remote_identify);
  902. _transport_add_phy_to_an_existing_port(ioc, sas_node,
  903. mpt2sas_phy, mpt2sas_phy->remote_identify.sas_address);
  904. } else
  905. memset(&mpt2sas_phy->remote_identify, 0 , sizeof(struct
  906. sas_identify));
  907. if (mpt2sas_phy->phy)
  908. mpt2sas_phy->phy->negotiated_linkrate =
  909. _transport_convert_phy_link_rate(link_rate);
  910. if ((ioc->logging_level & MPT_DEBUG_TRANSPORT))
  911. dev_printk(KERN_INFO, &mpt2sas_phy->phy->dev,
  912. "refresh: parent sas_addr(0x%016llx),\n"
  913. "\tlink_rate(0x%02x), phy(%d)\n"
  914. "\tattached_handle(0x%04x), sas_addr(0x%016llx)\n",
  915. (unsigned long long)sas_address,
  916. link_rate, phy_number, handle, (unsigned long long)
  917. mpt2sas_phy->remote_identify.sas_address);
  918. }
  919. static inline void *
  920. phy_to_ioc(struct sas_phy *phy)
  921. {
  922. struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
  923. return shost_priv(shost);
  924. }
  925. static inline void *
  926. rphy_to_ioc(struct sas_rphy *rphy)
  927. {
  928. struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent->parent);
  929. return shost_priv(shost);
  930. }
  931. /* report phy error log structure */
  932. struct phy_error_log_request{
  933. u8 smp_frame_type; /* 0x40 */
  934. u8 function; /* 0x11 */
  935. u8 allocated_response_length;
  936. u8 request_length; /* 02 */
  937. u8 reserved_1[5];
  938. u8 phy_identifier;
  939. u8 reserved_2[2];
  940. };
  941. /* report phy error log reply structure */
  942. struct phy_error_log_reply{
  943. u8 smp_frame_type; /* 0x41 */
  944. u8 function; /* 0x11 */
  945. u8 function_result;
  946. u8 response_length;
  947. __be16 expander_change_count;
  948. u8 reserved_1[3];
  949. u8 phy_identifier;
  950. u8 reserved_2[2];
  951. __be32 invalid_dword;
  952. __be32 running_disparity_error;
  953. __be32 loss_of_dword_sync;
  954. __be32 phy_reset_problem;
  955. };
  956. /**
  957. * _transport_get_expander_phy_error_log - return expander counters
  958. * @ioc: per adapter object
  959. * @phy: The sas phy object
  960. *
  961. * Returns 0 for success, non-zero for failure.
  962. *
  963. */
  964. static int
  965. _transport_get_expander_phy_error_log(struct MPT2SAS_ADAPTER *ioc,
  966. struct sas_phy *phy)
  967. {
  968. Mpi2SmpPassthroughRequest_t *mpi_request;
  969. Mpi2SmpPassthroughReply_t *mpi_reply;
  970. struct phy_error_log_request *phy_error_log_request;
  971. struct phy_error_log_reply *phy_error_log_reply;
  972. int rc;
  973. u16 smid;
  974. u32 ioc_state;
  975. unsigned long timeleft;
  976. void *psge;
  977. u32 sgl_flags;
  978. u8 issue_reset = 0;
  979. void *data_out = NULL;
  980. dma_addr_t data_out_dma;
  981. u32 sz;
  982. u16 wait_state_count;
  983. if (ioc->shost_recovery || ioc->pci_error_recovery) {
  984. printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
  985. __func__, ioc->name);
  986. return -EFAULT;
  987. }
  988. mutex_lock(&ioc->transport_cmds.mutex);
  989. if (ioc->transport_cmds.status != MPT2_CMD_NOT_USED) {
  990. printk(MPT2SAS_ERR_FMT "%s: transport_cmds in use\n",
  991. ioc->name, __func__);
  992. rc = -EAGAIN;
  993. goto out;
  994. }
  995. ioc->transport_cmds.status = MPT2_CMD_PENDING;
  996. wait_state_count = 0;
  997. ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
  998. while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
  999. if (wait_state_count++ == 10) {
  1000. printk(MPT2SAS_ERR_FMT
  1001. "%s: failed due to ioc not operational\n",
  1002. ioc->name, __func__);
  1003. rc = -EFAULT;
  1004. goto out;
  1005. }
  1006. ssleep(1);
  1007. ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
  1008. printk(MPT2SAS_INFO_FMT "%s: waiting for "
  1009. "operational state(count=%d)\n", ioc->name,
  1010. __func__, wait_state_count);
  1011. }
  1012. if (wait_state_count)
  1013. printk(MPT2SAS_INFO_FMT "%s: ioc is operational\n",
  1014. ioc->name, __func__);
  1015. smid = mpt2sas_base_get_smid(ioc, ioc->transport_cb_idx);
  1016. if (!smid) {
  1017. printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
  1018. ioc->name, __func__);
  1019. rc = -EAGAIN;
  1020. goto out;
  1021. }
  1022. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
  1023. ioc->transport_cmds.smid = smid;
  1024. sz = sizeof(struct phy_error_log_request) +
  1025. sizeof(struct phy_error_log_reply);
  1026. data_out = pci_alloc_consistent(ioc->pdev, sz, &data_out_dma);
  1027. if (!data_out) {
  1028. printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__,
  1029. __LINE__, __func__);
  1030. rc = -ENOMEM;
  1031. mpt2sas_base_free_smid(ioc, smid);
  1032. goto out;
  1033. }
  1034. rc = -EINVAL;
  1035. memset(data_out, 0, sz);
  1036. phy_error_log_request = data_out;
  1037. phy_error_log_request->smp_frame_type = 0x40;
  1038. phy_error_log_request->function = 0x11;
  1039. phy_error_log_request->request_length = 2;
  1040. phy_error_log_request->allocated_response_length = 0;
  1041. phy_error_log_request->phy_identifier = phy->number;
  1042. memset(mpi_request, 0, sizeof(Mpi2SmpPassthroughRequest_t));
  1043. mpi_request->Function = MPI2_FUNCTION_SMP_PASSTHROUGH;
  1044. mpi_request->PhysicalPort = 0xFF;
  1045. mpi_request->VF_ID = 0; /* TODO */
  1046. mpi_request->VP_ID = 0;
  1047. mpi_request->SASAddress = cpu_to_le64(phy->identify.sas_address);
  1048. mpi_request->RequestDataLength =
  1049. cpu_to_le16(sizeof(struct phy_error_log_request));
  1050. psge = &mpi_request->SGL;
  1051. /* WRITE sgel first */
  1052. sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT |
  1053. MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_HOST_TO_IOC);
  1054. sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
  1055. ioc->base_add_sg_single(psge, sgl_flags |
  1056. sizeof(struct phy_error_log_request), data_out_dma);
  1057. /* incr sgel */
  1058. psge += ioc->sge_size;
  1059. /* READ sgel last */
  1060. sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT |
  1061. MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER |
  1062. MPI2_SGE_FLAGS_END_OF_LIST);
  1063. sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
  1064. ioc->base_add_sg_single(psge, sgl_flags |
  1065. sizeof(struct phy_error_log_reply), data_out_dma +
  1066. sizeof(struct phy_error_log_request));
  1067. dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT "phy_error_log - "
  1068. "send to sas_addr(0x%016llx), phy(%d)\n", ioc->name,
  1069. (unsigned long long)phy->identify.sas_address, phy->number));
  1070. init_completion(&ioc->transport_cmds.done);
  1071. mpt2sas_base_put_smid_default(ioc, smid);
  1072. timeleft = wait_for_completion_timeout(&ioc->transport_cmds.done,
  1073. 10*HZ);
  1074. if (!(ioc->transport_cmds.status & MPT2_CMD_COMPLETE)) {
  1075. printk(MPT2SAS_ERR_FMT "%s: timeout\n",
  1076. ioc->name, __func__);
  1077. _debug_dump_mf(mpi_request,
  1078. sizeof(Mpi2SmpPassthroughRequest_t)/4);
  1079. if (!(ioc->transport_cmds.status & MPT2_CMD_RESET))
  1080. issue_reset = 1;
  1081. goto issue_host_reset;
  1082. }
  1083. dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT "phy_error_log - "
  1084. "complete\n", ioc->name));
  1085. if (ioc->transport_cmds.status & MPT2_CMD_REPLY_VALID) {
  1086. mpi_reply = ioc->transport_cmds.reply;
  1087. dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT
  1088. "phy_error_log - reply data transfer size(%d)\n",
  1089. ioc->name, le16_to_cpu(mpi_reply->ResponseDataLength)));
  1090. if (le16_to_cpu(mpi_reply->ResponseDataLength) !=
  1091. sizeof(struct phy_error_log_reply))
  1092. goto out;
  1093. phy_error_log_reply = data_out +
  1094. sizeof(struct phy_error_log_request);
  1095. dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT
  1096. "phy_error_log - function_result(%d)\n",
  1097. ioc->name, phy_error_log_reply->function_result));
  1098. phy->invalid_dword_count =
  1099. be32_to_cpu(phy_error_log_reply->invalid_dword);
  1100. phy->running_disparity_error_count =
  1101. be32_to_cpu(phy_error_log_reply->running_disparity_error);
  1102. phy->loss_of_dword_sync_count =
  1103. be32_to_cpu(phy_error_log_reply->loss_of_dword_sync);
  1104. phy->phy_reset_problem_count =
  1105. be32_to_cpu(phy_error_log_reply->phy_reset_problem);
  1106. rc = 0;
  1107. } else
  1108. dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT
  1109. "phy_error_log - no reply\n", ioc->name));
  1110. issue_host_reset:
  1111. if (issue_reset)
  1112. mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
  1113. FORCE_BIG_HAMMER);
  1114. out:
  1115. ioc->transport_cmds.status = MPT2_CMD_NOT_USED;
  1116. if (data_out)
  1117. pci_free_consistent(ioc->pdev, sz, data_out, data_out_dma);
  1118. mutex_unlock(&ioc->transport_cmds.mutex);
  1119. return rc;
  1120. }
  1121. /**
  1122. * _transport_get_linkerrors - return phy counters for both hba and expanders
  1123. * @phy: The sas phy object
  1124. *
  1125. * Returns 0 for success, non-zero for failure.
  1126. *
  1127. */
  1128. static int
  1129. _transport_get_linkerrors(struct sas_phy *phy)
  1130. {
  1131. struct MPT2SAS_ADAPTER *ioc = phy_to_ioc(phy);
  1132. unsigned long flags;
  1133. Mpi2ConfigReply_t mpi_reply;
  1134. Mpi2SasPhyPage1_t phy_pg1;
  1135. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  1136. if (_transport_sas_node_find_by_sas_address(ioc,
  1137. phy->identify.sas_address) == NULL) {
  1138. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  1139. return -EINVAL;
  1140. }
  1141. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  1142. if (phy->identify.sas_address != ioc->sas_hba.sas_address)
  1143. return _transport_get_expander_phy_error_log(ioc, phy);
  1144. /* get hba phy error logs */
  1145. if ((mpt2sas_config_get_phy_pg1(ioc, &mpi_reply, &phy_pg1,
  1146. phy->number))) {
  1147. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1148. ioc->name, __FILE__, __LINE__, __func__);
  1149. return -ENXIO;
  1150. }
  1151. if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo)
  1152. printk(MPT2SAS_INFO_FMT "phy(%d), ioc_status"
  1153. "(0x%04x), loginfo(0x%08x)\n", ioc->name,
  1154. phy->number, le16_to_cpu(mpi_reply.IOCStatus),
  1155. le32_to_cpu(mpi_reply.IOCLogInfo));
  1156. phy->invalid_dword_count = le32_to_cpu(phy_pg1.InvalidDwordCount);
  1157. phy->running_disparity_error_count =
  1158. le32_to_cpu(phy_pg1.RunningDisparityErrorCount);
  1159. phy->loss_of_dword_sync_count =
  1160. le32_to_cpu(phy_pg1.LossDwordSynchCount);
  1161. phy->phy_reset_problem_count =
  1162. le32_to_cpu(phy_pg1.PhyResetProblemCount);
  1163. return 0;
  1164. }
  1165. /**
  1166. * _transport_get_enclosure_identifier -
  1167. * @phy: The sas phy object
  1168. *
  1169. * Obtain the enclosure logical id for an expander.
  1170. * Returns 0 for success, non-zero for failure.
  1171. */
  1172. static int
  1173. _transport_get_enclosure_identifier(struct sas_rphy *rphy, u64 *identifier)
  1174. {
  1175. struct MPT2SAS_ADAPTER *ioc = rphy_to_ioc(rphy);
  1176. struct _sas_device *sas_device;
  1177. unsigned long flags;
  1178. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  1179. sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  1180. rphy->identify.sas_address);
  1181. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  1182. if (!sas_device)
  1183. return -ENXIO;
  1184. *identifier = sas_device->enclosure_logical_id;
  1185. return 0;
  1186. }
  1187. /**
  1188. * _transport_get_bay_identifier -
  1189. * @phy: The sas phy object
  1190. *
  1191. * Returns the slot id for a device that resides inside an enclosure.
  1192. */
  1193. static int
  1194. _transport_get_bay_identifier(struct sas_rphy *rphy)
  1195. {
  1196. struct MPT2SAS_ADAPTER *ioc = rphy_to_ioc(rphy);
  1197. struct _sas_device *sas_device;
  1198. unsigned long flags;
  1199. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  1200. sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  1201. rphy->identify.sas_address);
  1202. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  1203. if (!sas_device)
  1204. return -ENXIO;
  1205. return sas_device->slot;
  1206. }
  1207. /* phy control request structure */
  1208. struct phy_control_request{
  1209. u8 smp_frame_type; /* 0x40 */
  1210. u8 function; /* 0x91 */
  1211. u8 allocated_response_length;
  1212. u8 request_length; /* 0x09 */
  1213. u16 expander_change_count;
  1214. u8 reserved_1[3];
  1215. u8 phy_identifier;
  1216. u8 phy_operation;
  1217. u8 reserved_2[13];
  1218. u64 attached_device_name;
  1219. u8 programmed_min_physical_link_rate;
  1220. u8 programmed_max_physical_link_rate;
  1221. u8 reserved_3[6];
  1222. };
  1223. /* phy control reply structure */
  1224. struct phy_control_reply{
  1225. u8 smp_frame_type; /* 0x41 */
  1226. u8 function; /* 0x11 */
  1227. u8 function_result;
  1228. u8 response_length;
  1229. };
  1230. #define SMP_PHY_CONTROL_LINK_RESET (0x01)
  1231. #define SMP_PHY_CONTROL_HARD_RESET (0x02)
  1232. #define SMP_PHY_CONTROL_DISABLE (0x03)
  1233. /**
  1234. * _transport_expander_phy_control - expander phy control
  1235. * @ioc: per adapter object
  1236. * @phy: The sas phy object
  1237. *
  1238. * Returns 0 for success, non-zero for failure.
  1239. *
  1240. */
  1241. static int
  1242. _transport_expander_phy_control(struct MPT2SAS_ADAPTER *ioc,
  1243. struct sas_phy *phy, u8 phy_operation)
  1244. {
  1245. Mpi2SmpPassthroughRequest_t *mpi_request;
  1246. Mpi2SmpPassthroughReply_t *mpi_reply;
  1247. struct phy_control_request *phy_control_request;
  1248. struct phy_control_reply *phy_control_reply;
  1249. int rc;
  1250. u16 smid;
  1251. u32 ioc_state;
  1252. unsigned long timeleft;
  1253. void *psge;
  1254. u32 sgl_flags;
  1255. u8 issue_reset = 0;
  1256. void *data_out = NULL;
  1257. dma_addr_t data_out_dma;
  1258. u32 sz;
  1259. u16 wait_state_count;
  1260. if (ioc->shost_recovery) {
  1261. printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
  1262. __func__, ioc->name);
  1263. return -EFAULT;
  1264. }
  1265. mutex_lock(&ioc->transport_cmds.mutex);
  1266. if (ioc->transport_cmds.status != MPT2_CMD_NOT_USED) {
  1267. printk(MPT2SAS_ERR_FMT "%s: transport_cmds in use\n",
  1268. ioc->name, __func__);
  1269. rc = -EAGAIN;
  1270. goto out;
  1271. }
  1272. ioc->transport_cmds.status = MPT2_CMD_PENDING;
  1273. wait_state_count = 0;
  1274. ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
  1275. while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
  1276. if (wait_state_count++ == 10) {
  1277. printk(MPT2SAS_ERR_FMT
  1278. "%s: failed due to ioc not operational\n",
  1279. ioc->name, __func__);
  1280. rc = -EFAULT;
  1281. goto out;
  1282. }
  1283. ssleep(1);
  1284. ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
  1285. printk(MPT2SAS_INFO_FMT "%s: waiting for "
  1286. "operational state(count=%d)\n", ioc->name,
  1287. __func__, wait_state_count);
  1288. }
  1289. if (wait_state_count)
  1290. printk(MPT2SAS_INFO_FMT "%s: ioc is operational\n",
  1291. ioc->name, __func__);
  1292. smid = mpt2sas_base_get_smid(ioc, ioc->transport_cb_idx);
  1293. if (!smid) {
  1294. printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
  1295. ioc->name, __func__);
  1296. rc = -EAGAIN;
  1297. goto out;
  1298. }
  1299. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
  1300. ioc->transport_cmds.smid = smid;
  1301. sz = sizeof(struct phy_control_request) +
  1302. sizeof(struct phy_control_reply);
  1303. data_out = pci_alloc_consistent(ioc->pdev, sz, &data_out_dma);
  1304. if (!data_out) {
  1305. printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__,
  1306. __LINE__, __func__);
  1307. rc = -ENOMEM;
  1308. mpt2sas_base_free_smid(ioc, smid);
  1309. goto out;
  1310. }
  1311. rc = -EINVAL;
  1312. memset(data_out, 0, sz);
  1313. phy_control_request = data_out;
  1314. phy_control_request->smp_frame_type = 0x40;
  1315. phy_control_request->function = 0x91;
  1316. phy_control_request->request_length = 9;
  1317. phy_control_request->allocated_response_length = 0;
  1318. phy_control_request->phy_identifier = phy->number;
  1319. phy_control_request->phy_operation = phy_operation;
  1320. phy_control_request->programmed_min_physical_link_rate =
  1321. phy->minimum_linkrate << 4;
  1322. phy_control_request->programmed_max_physical_link_rate =
  1323. phy->maximum_linkrate << 4;
  1324. memset(mpi_request, 0, sizeof(Mpi2SmpPassthroughRequest_t));
  1325. mpi_request->Function = MPI2_FUNCTION_SMP_PASSTHROUGH;
  1326. mpi_request->PhysicalPort = 0xFF;
  1327. mpi_request->VF_ID = 0; /* TODO */
  1328. mpi_request->VP_ID = 0;
  1329. mpi_request->SASAddress = cpu_to_le64(phy->identify.sas_address);
  1330. mpi_request->RequestDataLength =
  1331. cpu_to_le16(sizeof(struct phy_error_log_request));
  1332. psge = &mpi_request->SGL;
  1333. /* WRITE sgel first */
  1334. sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT |
  1335. MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_HOST_TO_IOC);
  1336. sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
  1337. ioc->base_add_sg_single(psge, sgl_flags |
  1338. sizeof(struct phy_control_request), data_out_dma);
  1339. /* incr sgel */
  1340. psge += ioc->sge_size;
  1341. /* READ sgel last */
  1342. sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT |
  1343. MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER |
  1344. MPI2_SGE_FLAGS_END_OF_LIST);
  1345. sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
  1346. ioc->base_add_sg_single(psge, sgl_flags |
  1347. sizeof(struct phy_control_reply), data_out_dma +
  1348. sizeof(struct phy_control_request));
  1349. dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT "phy_control - "
  1350. "send to sas_addr(0x%016llx), phy(%d), opcode(%d)\n", ioc->name,
  1351. (unsigned long long)phy->identify.sas_address, phy->number,
  1352. phy_operation));
  1353. init_completion(&ioc->transport_cmds.done);
  1354. mpt2sas_base_put_smid_default(ioc, smid);
  1355. timeleft = wait_for_completion_timeout(&ioc->transport_cmds.done,
  1356. 10*HZ);
  1357. if (!(ioc->transport_cmds.status & MPT2_CMD_COMPLETE)) {
  1358. printk(MPT2SAS_ERR_FMT "%s: timeout\n",
  1359. ioc->name, __func__);
  1360. _debug_dump_mf(mpi_request,
  1361. sizeof(Mpi2SmpPassthroughRequest_t)/4);
  1362. if (!(ioc->transport_cmds.status & MPT2_CMD_RESET))
  1363. issue_reset = 1;
  1364. goto issue_host_reset;
  1365. }
  1366. dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT "phy_control - "
  1367. "complete\n", ioc->name));
  1368. if (ioc->transport_cmds.status & MPT2_CMD_REPLY_VALID) {
  1369. mpi_reply = ioc->transport_cmds.reply;
  1370. dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT
  1371. "phy_control - reply data transfer size(%d)\n",
  1372. ioc->name, le16_to_cpu(mpi_reply->ResponseDataLength)));
  1373. if (le16_to_cpu(mpi_reply->ResponseDataLength) !=
  1374. sizeof(struct phy_control_reply))
  1375. goto out;
  1376. phy_control_reply = data_out +
  1377. sizeof(struct phy_control_request);
  1378. dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT
  1379. "phy_control - function_result(%d)\n",
  1380. ioc->name, phy_control_reply->function_result));
  1381. rc = 0;
  1382. } else
  1383. dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT
  1384. "phy_control - no reply\n", ioc->name));
  1385. issue_host_reset:
  1386. if (issue_reset)
  1387. mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
  1388. FORCE_BIG_HAMMER);
  1389. out:
  1390. ioc->transport_cmds.status = MPT2_CMD_NOT_USED;
  1391. if (data_out)
  1392. pci_free_consistent(ioc->pdev, sz, data_out, data_out_dma);
  1393. mutex_unlock(&ioc->transport_cmds.mutex);
  1394. return rc;
  1395. }
  1396. /**
  1397. * _transport_phy_reset -
  1398. * @phy: The sas phy object
  1399. * @hard_reset:
  1400. *
  1401. * Returns 0 for success, non-zero for failure.
  1402. */
  1403. static int
  1404. _transport_phy_reset(struct sas_phy *phy, int hard_reset)
  1405. {
  1406. struct MPT2SAS_ADAPTER *ioc = phy_to_ioc(phy);
  1407. Mpi2SasIoUnitControlReply_t mpi_reply;
  1408. Mpi2SasIoUnitControlRequest_t mpi_request;
  1409. unsigned long flags;
  1410. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  1411. if (_transport_sas_node_find_by_sas_address(ioc,
  1412. phy->identify.sas_address) == NULL) {
  1413. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  1414. return -EINVAL;
  1415. }
  1416. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  1417. /* handle expander phys */
  1418. if (phy->identify.sas_address != ioc->sas_hba.sas_address)
  1419. return _transport_expander_phy_control(ioc, phy,
  1420. (hard_reset == 1) ? SMP_PHY_CONTROL_HARD_RESET :
  1421. SMP_PHY_CONTROL_LINK_RESET);
  1422. /* handle hba phys */
  1423. memset(&mpi_request, 0, sizeof(Mpi2SasIoUnitControlReply_t));
  1424. mpi_request.Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
  1425. mpi_request.Operation = hard_reset ?
  1426. MPI2_SAS_OP_PHY_HARD_RESET : MPI2_SAS_OP_PHY_LINK_RESET;
  1427. mpi_request.PhyNum = phy->number;
  1428. if ((mpt2sas_base_sas_iounit_control(ioc, &mpi_reply, &mpi_request))) {
  1429. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1430. ioc->name, __FILE__, __LINE__, __func__);
  1431. return -ENXIO;
  1432. }
  1433. if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo)
  1434. printk(MPT2SAS_INFO_FMT "phy(%d), ioc_status"
  1435. "(0x%04x), loginfo(0x%08x)\n", ioc->name,
  1436. phy->number, le16_to_cpu(mpi_reply.IOCStatus),
  1437. le32_to_cpu(mpi_reply.IOCLogInfo));
  1438. return 0;
  1439. }
  1440. /**
  1441. * _transport_phy_enable - enable/disable phys
  1442. * @phy: The sas phy object
  1443. * @enable: enable phy when true
  1444. *
  1445. * Only support sas_host direct attached phys.
  1446. * Returns 0 for success, non-zero for failure.
  1447. */
  1448. static int
  1449. _transport_phy_enable(struct sas_phy *phy, int enable)
  1450. {
  1451. struct MPT2SAS_ADAPTER *ioc = phy_to_ioc(phy);
  1452. Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
  1453. Mpi2ConfigReply_t mpi_reply;
  1454. u16 ioc_status;
  1455. u16 sz;
  1456. int rc = 0;
  1457. unsigned long flags;
  1458. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  1459. if (_transport_sas_node_find_by_sas_address(ioc,
  1460. phy->identify.sas_address) == NULL) {
  1461. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  1462. return -EINVAL;
  1463. }
  1464. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  1465. /* handle expander phys */
  1466. if (phy->identify.sas_address != ioc->sas_hba.sas_address)
  1467. return _transport_expander_phy_control(ioc, phy,
  1468. (enable == 1) ? SMP_PHY_CONTROL_LINK_RESET :
  1469. SMP_PHY_CONTROL_DISABLE);
  1470. /* handle hba phys */
  1471. /* sas_iounit page 1 */
  1472. sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
  1473. sizeof(Mpi2SasIOUnit1PhyData_t));
  1474. sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
  1475. if (!sas_iounit_pg1) {
  1476. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1477. ioc->name, __FILE__, __LINE__, __func__);
  1478. rc = -ENOMEM;
  1479. goto out;
  1480. }
  1481. if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
  1482. sas_iounit_pg1, sz))) {
  1483. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1484. ioc->name, __FILE__, __LINE__, __func__);
  1485. rc = -ENXIO;
  1486. goto out;
  1487. }
  1488. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  1489. MPI2_IOCSTATUS_MASK;
  1490. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  1491. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1492. ioc->name, __FILE__, __LINE__, __func__);
  1493. rc = -EIO;
  1494. goto out;
  1495. }
  1496. if (enable)
  1497. sas_iounit_pg1->PhyData[phy->number].PhyFlags
  1498. &= ~MPI2_SASIOUNIT1_PHYFLAGS_PHY_DISABLE;
  1499. else
  1500. sas_iounit_pg1->PhyData[phy->number].PhyFlags
  1501. |= MPI2_SASIOUNIT1_PHYFLAGS_PHY_DISABLE;
  1502. mpt2sas_config_set_sas_iounit_pg1(ioc, &mpi_reply, sas_iounit_pg1, sz);
  1503. /* link reset */
  1504. if (enable)
  1505. _transport_phy_reset(phy, 0);
  1506. out:
  1507. kfree(sas_iounit_pg1);
  1508. return rc;
  1509. }
  1510. /**
  1511. * _transport_phy_speed - set phy min/max link rates
  1512. * @phy: The sas phy object
  1513. * @rates: rates defined in sas_phy_linkrates
  1514. *
  1515. * Only support sas_host direct attached phys.
  1516. * Returns 0 for success, non-zero for failure.
  1517. */
  1518. static int
  1519. _transport_phy_speed(struct sas_phy *phy, struct sas_phy_linkrates *rates)
  1520. {
  1521. struct MPT2SAS_ADAPTER *ioc = phy_to_ioc(phy);
  1522. Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
  1523. Mpi2SasPhyPage0_t phy_pg0;
  1524. Mpi2ConfigReply_t mpi_reply;
  1525. u16 ioc_status;
  1526. u16 sz;
  1527. int i;
  1528. int rc = 0;
  1529. unsigned long flags;
  1530. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  1531. if (_transport_sas_node_find_by_sas_address(ioc,
  1532. phy->identify.sas_address) == NULL) {
  1533. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  1534. return -EINVAL;
  1535. }
  1536. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  1537. if (!rates->minimum_linkrate)
  1538. rates->minimum_linkrate = phy->minimum_linkrate;
  1539. else if (rates->minimum_linkrate < phy->minimum_linkrate_hw)
  1540. rates->minimum_linkrate = phy->minimum_linkrate_hw;
  1541. if (!rates->maximum_linkrate)
  1542. rates->maximum_linkrate = phy->maximum_linkrate;
  1543. else if (rates->maximum_linkrate > phy->maximum_linkrate_hw)
  1544. rates->maximum_linkrate = phy->maximum_linkrate_hw;
  1545. /* handle expander phys */
  1546. if (phy->identify.sas_address != ioc->sas_hba.sas_address) {
  1547. phy->minimum_linkrate = rates->minimum_linkrate;
  1548. phy->maximum_linkrate = rates->maximum_linkrate;
  1549. return _transport_expander_phy_control(ioc, phy,
  1550. SMP_PHY_CONTROL_LINK_RESET);
  1551. }
  1552. /* handle hba phys */
  1553. /* sas_iounit page 1 */
  1554. sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
  1555. sizeof(Mpi2SasIOUnit1PhyData_t));
  1556. sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
  1557. if (!sas_iounit_pg1) {
  1558. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1559. ioc->name, __FILE__, __LINE__, __func__);
  1560. rc = -ENOMEM;
  1561. goto out;
  1562. }
  1563. if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
  1564. sas_iounit_pg1, sz))) {
  1565. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1566. ioc->name, __FILE__, __LINE__, __func__);
  1567. rc = -ENXIO;
  1568. goto out;
  1569. }
  1570. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  1571. MPI2_IOCSTATUS_MASK;
  1572. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  1573. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1574. ioc->name, __FILE__, __LINE__, __func__);
  1575. rc = -EIO;
  1576. goto out;
  1577. }
  1578. for (i = 0; i < ioc->sas_hba.num_phys; i++) {
  1579. if (phy->number != i) {
  1580. sas_iounit_pg1->PhyData[i].MaxMinLinkRate =
  1581. (ioc->sas_hba.phy[i].phy->minimum_linkrate +
  1582. (ioc->sas_hba.phy[i].phy->maximum_linkrate << 4));
  1583. } else {
  1584. sas_iounit_pg1->PhyData[i].MaxMinLinkRate =
  1585. (rates->minimum_linkrate +
  1586. (rates->maximum_linkrate << 4));
  1587. }
  1588. }
  1589. if (mpt2sas_config_set_sas_iounit_pg1(ioc, &mpi_reply, sas_iounit_pg1,
  1590. sz)) {
  1591. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1592. ioc->name, __FILE__, __LINE__, __func__);
  1593. rc = -ENXIO;
  1594. goto out;
  1595. }
  1596. /* link reset */
  1597. _transport_phy_reset(phy, 0);
  1598. /* read phy page 0, then update the rates in the sas transport phy */
  1599. if (!mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
  1600. phy->number)) {
  1601. phy->minimum_linkrate = _transport_convert_phy_link_rate(
  1602. phy_pg0.ProgrammedLinkRate & MPI2_SAS_PRATE_MIN_RATE_MASK);
  1603. phy->maximum_linkrate = _transport_convert_phy_link_rate(
  1604. phy_pg0.ProgrammedLinkRate >> 4);
  1605. phy->negotiated_linkrate = _transport_convert_phy_link_rate(
  1606. phy_pg0.NegotiatedLinkRate &
  1607. MPI2_SAS_NEG_LINK_RATE_MASK_PHYSICAL);
  1608. }
  1609. out:
  1610. kfree(sas_iounit_pg1);
  1611. return rc;
  1612. }
  1613. /**
  1614. * _transport_smp_handler - transport portal for smp passthru
  1615. * @shost: shost object
  1616. * @rphy: sas transport rphy object
  1617. * @req:
  1618. *
  1619. * This used primarily for smp_utils.
  1620. * Example:
  1621. * smp_rep_general /sys/class/bsg/expander-5:0
  1622. */
  1623. static int
  1624. _transport_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
  1625. struct request *req)
  1626. {
  1627. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  1628. Mpi2SmpPassthroughRequest_t *mpi_request;
  1629. Mpi2SmpPassthroughReply_t *mpi_reply;
  1630. int rc;
  1631. u16 smid;
  1632. u32 ioc_state;
  1633. unsigned long timeleft;
  1634. void *psge;
  1635. u32 sgl_flags;
  1636. u8 issue_reset = 0;
  1637. dma_addr_t dma_addr_in = 0;
  1638. dma_addr_t dma_addr_out = 0;
  1639. u16 wait_state_count;
  1640. struct request *rsp = req->next_rq;
  1641. if (!rsp) {
  1642. printk(MPT2SAS_ERR_FMT "%s: the smp response space is "
  1643. "missing\n", ioc->name, __func__);
  1644. return -EINVAL;
  1645. }
  1646. /* do we need to support multiple segments? */
  1647. if (req->bio->bi_vcnt > 1 || rsp->bio->bi_vcnt > 1) {
  1648. printk(MPT2SAS_ERR_FMT "%s: multiple segments req %u %u, "
  1649. "rsp %u %u\n", ioc->name, __func__, req->bio->bi_vcnt,
  1650. blk_rq_bytes(req), rsp->bio->bi_vcnt, blk_rq_bytes(rsp));
  1651. return -EINVAL;
  1652. }
  1653. if (ioc->shost_recovery) {
  1654. printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
  1655. __func__, ioc->name);
  1656. return -EFAULT;
  1657. }
  1658. rc = mutex_lock_interruptible(&ioc->transport_cmds.mutex);
  1659. if (rc)
  1660. return rc;
  1661. if (ioc->transport_cmds.status != MPT2_CMD_NOT_USED) {
  1662. printk(MPT2SAS_ERR_FMT "%s: transport_cmds in use\n", ioc->name,
  1663. __func__);
  1664. rc = -EAGAIN;
  1665. goto out;
  1666. }
  1667. ioc->transport_cmds.status = MPT2_CMD_PENDING;
  1668. wait_state_count = 0;
  1669. ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
  1670. while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
  1671. if (wait_state_count++ == 10) {
  1672. printk(MPT2SAS_ERR_FMT
  1673. "%s: failed due to ioc not operational\n",
  1674. ioc->name, __func__);
  1675. rc = -EFAULT;
  1676. goto out;
  1677. }
  1678. ssleep(1);
  1679. ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
  1680. printk(MPT2SAS_INFO_FMT "%s: waiting for "
  1681. "operational state(count=%d)\n", ioc->name,
  1682. __func__, wait_state_count);
  1683. }
  1684. if (wait_state_count)
  1685. printk(MPT2SAS_INFO_FMT "%s: ioc is operational\n",
  1686. ioc->name, __func__);
  1687. smid = mpt2sas_base_get_smid(ioc, ioc->transport_cb_idx);
  1688. if (!smid) {
  1689. printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
  1690. ioc->name, __func__);
  1691. rc = -EAGAIN;
  1692. goto out;
  1693. }
  1694. rc = 0;
  1695. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
  1696. ioc->transport_cmds.smid = smid;
  1697. memset(mpi_request, 0, sizeof(Mpi2SmpPassthroughRequest_t));
  1698. mpi_request->Function = MPI2_FUNCTION_SMP_PASSTHROUGH;
  1699. mpi_request->PhysicalPort = 0xFF;
  1700. mpi_request->VF_ID = 0; /* TODO */
  1701. mpi_request->VP_ID = 0;
  1702. mpi_request->SASAddress = (rphy) ?
  1703. cpu_to_le64(rphy->identify.sas_address) :
  1704. cpu_to_le64(ioc->sas_hba.sas_address);
  1705. mpi_request->RequestDataLength = cpu_to_le16(blk_rq_bytes(req) - 4);
  1706. psge = &mpi_request->SGL;
  1707. /* WRITE sgel first */
  1708. sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT |
  1709. MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_HOST_TO_IOC);
  1710. sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
  1711. dma_addr_out = pci_map_single(ioc->pdev, bio_data(req->bio),
  1712. blk_rq_bytes(req), PCI_DMA_BIDIRECTIONAL);
  1713. if (!dma_addr_out) {
  1714. mpt2sas_base_free_smid(ioc, smid);
  1715. goto unmap;
  1716. }
  1717. ioc->base_add_sg_single(psge, sgl_flags | (blk_rq_bytes(req) - 4),
  1718. dma_addr_out);
  1719. /* incr sgel */
  1720. psge += ioc->sge_size;
  1721. /* READ sgel last */
  1722. sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT |
  1723. MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER |
  1724. MPI2_SGE_FLAGS_END_OF_LIST);
  1725. sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
  1726. dma_addr_in = pci_map_single(ioc->pdev, bio_data(rsp->bio),
  1727. blk_rq_bytes(rsp), PCI_DMA_BIDIRECTIONAL);
  1728. if (!dma_addr_in) {
  1729. mpt2sas_base_free_smid(ioc, smid);
  1730. goto unmap;
  1731. }
  1732. ioc->base_add_sg_single(psge, sgl_flags | (blk_rq_bytes(rsp) + 4),
  1733. dma_addr_in);
  1734. dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT "%s - "
  1735. "sending smp request\n", ioc->name, __func__));
  1736. init_completion(&ioc->transport_cmds.done);
  1737. mpt2sas_base_put_smid_default(ioc, smid);
  1738. timeleft = wait_for_completion_timeout(&ioc->transport_cmds.done,
  1739. 10*HZ);
  1740. if (!(ioc->transport_cmds.status & MPT2_CMD_COMPLETE)) {
  1741. printk(MPT2SAS_ERR_FMT "%s : timeout\n",
  1742. __func__, ioc->name);
  1743. _debug_dump_mf(mpi_request,
  1744. sizeof(Mpi2SmpPassthroughRequest_t)/4);
  1745. if (!(ioc->transport_cmds.status & MPT2_CMD_RESET))
  1746. issue_reset = 1;
  1747. goto issue_host_reset;
  1748. }
  1749. dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT "%s - "
  1750. "complete\n", ioc->name, __func__));
  1751. if (ioc->transport_cmds.status & MPT2_CMD_REPLY_VALID) {
  1752. mpi_reply = ioc->transport_cmds.reply;
  1753. dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT
  1754. "%s - reply data transfer size(%d)\n",
  1755. ioc->name, __func__,
  1756. le16_to_cpu(mpi_reply->ResponseDataLength)));
  1757. memcpy(req->sense, mpi_reply, sizeof(*mpi_reply));
  1758. req->sense_len = sizeof(*mpi_reply);
  1759. req->resid_len = 0;
  1760. rsp->resid_len -=
  1761. le16_to_cpu(mpi_reply->ResponseDataLength);
  1762. } else {
  1763. dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT
  1764. "%s - no reply\n", ioc->name, __func__));
  1765. rc = -ENXIO;
  1766. }
  1767. issue_host_reset:
  1768. if (issue_reset) {
  1769. mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
  1770. FORCE_BIG_HAMMER);
  1771. rc = -ETIMEDOUT;
  1772. }
  1773. unmap:
  1774. if (dma_addr_out)
  1775. pci_unmap_single(ioc->pdev, dma_addr_out, blk_rq_bytes(req),
  1776. PCI_DMA_BIDIRECTIONAL);
  1777. if (dma_addr_in)
  1778. pci_unmap_single(ioc->pdev, dma_addr_in, blk_rq_bytes(rsp),
  1779. PCI_DMA_BIDIRECTIONAL);
  1780. out:
  1781. ioc->transport_cmds.status = MPT2_CMD_NOT_USED;
  1782. mutex_unlock(&ioc->transport_cmds.mutex);
  1783. return rc;
  1784. }
  1785. struct sas_function_template mpt2sas_transport_functions = {
  1786. .get_linkerrors = _transport_get_linkerrors,
  1787. .get_enclosure_identifier = _transport_get_enclosure_identifier,
  1788. .get_bay_identifier = _transport_get_bay_identifier,
  1789. .phy_reset = _transport_phy_reset,
  1790. .phy_enable = _transport_phy_enable,
  1791. .set_phy_speed = _transport_phy_speed,
  1792. .smp_handler = _transport_smp_handler,
  1793. };
  1794. struct scsi_transport_template *mpt2sas_transport_template;