mpt2sas_transport.c 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027
  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. u64 *sas_address_le;
  280. u16 wait_state_count;
  281. if (ioc->shost_recovery || ioc->pci_error_recovery) {
  282. printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
  283. __func__, ioc->name);
  284. return -EFAULT;
  285. }
  286. mutex_lock(&ioc->transport_cmds.mutex);
  287. if (ioc->transport_cmds.status != MPT2_CMD_NOT_USED) {
  288. printk(MPT2SAS_ERR_FMT "%s: transport_cmds in use\n",
  289. ioc->name, __func__);
  290. rc = -EAGAIN;
  291. goto out;
  292. }
  293. ioc->transport_cmds.status = MPT2_CMD_PENDING;
  294. wait_state_count = 0;
  295. ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
  296. while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
  297. if (wait_state_count++ == 10) {
  298. printk(MPT2SAS_ERR_FMT
  299. "%s: failed due to ioc not operational\n",
  300. ioc->name, __func__);
  301. rc = -EFAULT;
  302. goto out;
  303. }
  304. ssleep(1);
  305. ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
  306. printk(MPT2SAS_INFO_FMT "%s: waiting for "
  307. "operational state(count=%d)\n", ioc->name,
  308. __func__, wait_state_count);
  309. }
  310. if (wait_state_count)
  311. printk(MPT2SAS_INFO_FMT "%s: ioc is operational\n",
  312. ioc->name, __func__);
  313. smid = mpt2sas_base_get_smid(ioc, ioc->transport_cb_idx);
  314. if (!smid) {
  315. printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
  316. ioc->name, __func__);
  317. rc = -EAGAIN;
  318. goto out;
  319. }
  320. rc = 0;
  321. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
  322. ioc->transport_cmds.smid = smid;
  323. sz = sizeof(struct rep_manu_request) + sizeof(struct rep_manu_reply);
  324. data_out = pci_alloc_consistent(ioc->pdev, sz, &data_out_dma);
  325. if (!data_out) {
  326. printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__,
  327. __LINE__, __func__);
  328. rc = -ENOMEM;
  329. mpt2sas_base_free_smid(ioc, smid);
  330. goto out;
  331. }
  332. manufacture_request = data_out;
  333. manufacture_request->smp_frame_type = 0x40;
  334. manufacture_request->function = 1;
  335. manufacture_request->reserved = 0;
  336. manufacture_request->request_length = 0;
  337. memset(mpi_request, 0, sizeof(Mpi2SmpPassthroughRequest_t));
  338. mpi_request->Function = MPI2_FUNCTION_SMP_PASSTHROUGH;
  339. mpi_request->PhysicalPort = 0xFF;
  340. mpi_request->VF_ID = 0; /* TODO */
  341. mpi_request->VP_ID = 0;
  342. sas_address_le = (u64 *)&mpi_request->SASAddress;
  343. *sas_address_le = cpu_to_le64(sas_address);
  344. mpi_request->RequestDataLength =
  345. cpu_to_le16(sizeof(struct rep_manu_request));
  346. psge = &mpi_request->SGL;
  347. /* WRITE sgel first */
  348. sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT |
  349. MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_HOST_TO_IOC);
  350. sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
  351. ioc->base_add_sg_single(psge, sgl_flags |
  352. sizeof(struct rep_manu_request), data_out_dma);
  353. /* incr sgel */
  354. psge += ioc->sge_size;
  355. /* READ sgel last */
  356. sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT |
  357. MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER |
  358. MPI2_SGE_FLAGS_END_OF_LIST);
  359. sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
  360. ioc->base_add_sg_single(psge, sgl_flags |
  361. sizeof(struct rep_manu_reply), data_out_dma +
  362. sizeof(struct rep_manu_request));
  363. dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT "report_manufacture - "
  364. "send to sas_addr(0x%016llx)\n", ioc->name,
  365. (unsigned long long)sas_address));
  366. mpt2sas_base_put_smid_default(ioc, smid);
  367. init_completion(&ioc->transport_cmds.done);
  368. timeleft = wait_for_completion_timeout(&ioc->transport_cmds.done,
  369. 10*HZ);
  370. if (!(ioc->transport_cmds.status & MPT2_CMD_COMPLETE)) {
  371. printk(MPT2SAS_ERR_FMT "%s: timeout\n",
  372. ioc->name, __func__);
  373. _debug_dump_mf(mpi_request,
  374. sizeof(Mpi2SmpPassthroughRequest_t)/4);
  375. if (!(ioc->transport_cmds.status & MPT2_CMD_RESET))
  376. issue_reset = 1;
  377. goto issue_host_reset;
  378. }
  379. dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT "report_manufacture - "
  380. "complete\n", ioc->name));
  381. if (ioc->transport_cmds.status & MPT2_CMD_REPLY_VALID) {
  382. u8 *tmp;
  383. mpi_reply = ioc->transport_cmds.reply;
  384. dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT
  385. "report_manufacture - reply data transfer size(%d)\n",
  386. ioc->name, le16_to_cpu(mpi_reply->ResponseDataLength)));
  387. if (le16_to_cpu(mpi_reply->ResponseDataLength) !=
  388. sizeof(struct rep_manu_reply))
  389. goto out;
  390. manufacture_reply = data_out + sizeof(struct rep_manu_request);
  391. strncpy(edev->vendor_id, manufacture_reply->vendor_id,
  392. SAS_EXPANDER_VENDOR_ID_LEN);
  393. strncpy(edev->product_id, manufacture_reply->product_id,
  394. SAS_EXPANDER_PRODUCT_ID_LEN);
  395. strncpy(edev->product_rev, manufacture_reply->product_rev,
  396. SAS_EXPANDER_PRODUCT_REV_LEN);
  397. edev->level = manufacture_reply->sas_format & 1;
  398. if (edev->level) {
  399. strncpy(edev->component_vendor_id,
  400. manufacture_reply->component_vendor_id,
  401. SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN);
  402. tmp = (u8 *)&manufacture_reply->component_id;
  403. edev->component_id = tmp[0] << 8 | tmp[1];
  404. edev->component_revision_id =
  405. manufacture_reply->component_revision_id;
  406. }
  407. } else
  408. dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT
  409. "report_manufacture - no reply\n", ioc->name));
  410. issue_host_reset:
  411. if (issue_reset)
  412. mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
  413. FORCE_BIG_HAMMER);
  414. out:
  415. ioc->transport_cmds.status = MPT2_CMD_NOT_USED;
  416. if (data_out)
  417. pci_free_consistent(ioc->pdev, sz, data_out, data_out_dma);
  418. mutex_unlock(&ioc->transport_cmds.mutex);
  419. return rc;
  420. }
  421. /**
  422. * _transport_delete_port - helper function to removing a port
  423. * @ioc: per adapter object
  424. * @mpt2sas_port: mpt2sas per port object
  425. *
  426. * Returns nothing.
  427. */
  428. static void
  429. _transport_delete_port(struct MPT2SAS_ADAPTER *ioc,
  430. struct _sas_port *mpt2sas_port)
  431. {
  432. u64 sas_address = mpt2sas_port->remote_identify.sas_address;
  433. enum sas_device_type device_type =
  434. mpt2sas_port->remote_identify.device_type;
  435. dev_printk(KERN_INFO, &mpt2sas_port->port->dev,
  436. "remove: sas_addr(0x%016llx)\n",
  437. (unsigned long long) sas_address);
  438. ioc->logging_level |= MPT_DEBUG_TRANSPORT;
  439. if (device_type == SAS_END_DEVICE)
  440. mpt2sas_device_remove(ioc, sas_address);
  441. else if (device_type == SAS_EDGE_EXPANDER_DEVICE ||
  442. device_type == SAS_FANOUT_EXPANDER_DEVICE)
  443. mpt2sas_expander_remove(ioc, sas_address);
  444. ioc->logging_level &= ~MPT_DEBUG_TRANSPORT;
  445. }
  446. /**
  447. * _transport_delete_phy - helper function to removing single phy from port
  448. * @ioc: per adapter object
  449. * @mpt2sas_port: mpt2sas per port object
  450. * @mpt2sas_phy: mpt2sas per phy object
  451. *
  452. * Returns nothing.
  453. */
  454. static void
  455. _transport_delete_phy(struct MPT2SAS_ADAPTER *ioc,
  456. struct _sas_port *mpt2sas_port, struct _sas_phy *mpt2sas_phy)
  457. {
  458. u64 sas_address = mpt2sas_port->remote_identify.sas_address;
  459. dev_printk(KERN_INFO, &mpt2sas_phy->phy->dev,
  460. "remove: sas_addr(0x%016llx), phy(%d)\n",
  461. (unsigned long long) sas_address, mpt2sas_phy->phy_id);
  462. list_del(&mpt2sas_phy->port_siblings);
  463. mpt2sas_port->num_phys--;
  464. sas_port_delete_phy(mpt2sas_port->port, mpt2sas_phy->phy);
  465. mpt2sas_phy->phy_belongs_to_port = 0;
  466. }
  467. /**
  468. * _transport_add_phy - helper function to adding single phy to port
  469. * @ioc: per adapter object
  470. * @mpt2sas_port: mpt2sas per port object
  471. * @mpt2sas_phy: mpt2sas per phy object
  472. *
  473. * Returns nothing.
  474. */
  475. static void
  476. _transport_add_phy(struct MPT2SAS_ADAPTER *ioc, struct _sas_port *mpt2sas_port,
  477. struct _sas_phy *mpt2sas_phy)
  478. {
  479. u64 sas_address = mpt2sas_port->remote_identify.sas_address;
  480. dev_printk(KERN_INFO, &mpt2sas_phy->phy->dev,
  481. "add: sas_addr(0x%016llx), phy(%d)\n", (unsigned long long)
  482. sas_address, mpt2sas_phy->phy_id);
  483. list_add_tail(&mpt2sas_phy->port_siblings, &mpt2sas_port->phy_list);
  484. mpt2sas_port->num_phys++;
  485. sas_port_add_phy(mpt2sas_port->port, mpt2sas_phy->phy);
  486. mpt2sas_phy->phy_belongs_to_port = 1;
  487. }
  488. /**
  489. * _transport_add_phy_to_an_existing_port - adding new phy to existing port
  490. * @ioc: per adapter object
  491. * @sas_node: sas node object (either expander or sas host)
  492. * @mpt2sas_phy: mpt2sas per phy object
  493. * @sas_address: sas address of device/expander were phy needs to be added to
  494. *
  495. * Returns nothing.
  496. */
  497. static void
  498. _transport_add_phy_to_an_existing_port(struct MPT2SAS_ADAPTER *ioc,
  499. struct _sas_node *sas_node, struct _sas_phy *mpt2sas_phy, u64 sas_address)
  500. {
  501. struct _sas_port *mpt2sas_port;
  502. struct _sas_phy *phy_srch;
  503. if (mpt2sas_phy->phy_belongs_to_port == 1)
  504. return;
  505. list_for_each_entry(mpt2sas_port, &sas_node->sas_port_list,
  506. port_list) {
  507. if (mpt2sas_port->remote_identify.sas_address !=
  508. sas_address)
  509. continue;
  510. list_for_each_entry(phy_srch, &mpt2sas_port->phy_list,
  511. port_siblings) {
  512. if (phy_srch == mpt2sas_phy)
  513. return;
  514. }
  515. _transport_add_phy(ioc, mpt2sas_port, mpt2sas_phy);
  516. return;
  517. }
  518. }
  519. /**
  520. * _transport_del_phy_from_an_existing_port - delete phy from existing port
  521. * @ioc: per adapter object
  522. * @sas_node: sas node object (either expander or sas host)
  523. * @mpt2sas_phy: mpt2sas per phy object
  524. *
  525. * Returns nothing.
  526. */
  527. static void
  528. _transport_del_phy_from_an_existing_port(struct MPT2SAS_ADAPTER *ioc,
  529. struct _sas_node *sas_node, struct _sas_phy *mpt2sas_phy)
  530. {
  531. struct _sas_port *mpt2sas_port, *next;
  532. struct _sas_phy *phy_srch;
  533. if (mpt2sas_phy->phy_belongs_to_port == 0)
  534. return;
  535. list_for_each_entry_safe(mpt2sas_port, next, &sas_node->sas_port_list,
  536. port_list) {
  537. list_for_each_entry(phy_srch, &mpt2sas_port->phy_list,
  538. port_siblings) {
  539. if (phy_srch != mpt2sas_phy)
  540. continue;
  541. if (mpt2sas_port->num_phys == 1)
  542. _transport_delete_port(ioc, mpt2sas_port);
  543. else
  544. _transport_delete_phy(ioc, mpt2sas_port,
  545. mpt2sas_phy);
  546. return;
  547. }
  548. }
  549. }
  550. /**
  551. * _transport_sanity_check - sanity check when adding a new port
  552. * @ioc: per adapter object
  553. * @sas_node: sas node object (either expander or sas host)
  554. * @sas_address: sas address of device being added
  555. *
  556. * See the explanation above from _transport_delete_duplicate_port
  557. */
  558. static void
  559. _transport_sanity_check(struct MPT2SAS_ADAPTER *ioc, struct _sas_node *sas_node,
  560. u64 sas_address)
  561. {
  562. int i;
  563. for (i = 0; i < sas_node->num_phys; i++) {
  564. if (sas_node->phy[i].remote_identify.sas_address != sas_address)
  565. continue;
  566. if (sas_node->phy[i].phy_belongs_to_port == 1)
  567. _transport_del_phy_from_an_existing_port(ioc, sas_node,
  568. &sas_node->phy[i]);
  569. }
  570. }
  571. /**
  572. * mpt2sas_transport_port_add - insert port to the list
  573. * @ioc: per adapter object
  574. * @handle: handle of attached device
  575. * @sas_address: sas address of parent expander or sas host
  576. * Context: This function will acquire ioc->sas_node_lock.
  577. *
  578. * Adding new port object to the sas_node->sas_port_list.
  579. *
  580. * Returns mpt2sas_port.
  581. */
  582. struct _sas_port *
  583. mpt2sas_transport_port_add(struct MPT2SAS_ADAPTER *ioc, u16 handle,
  584. u64 sas_address)
  585. {
  586. struct _sas_phy *mpt2sas_phy, *next;
  587. struct _sas_port *mpt2sas_port;
  588. unsigned long flags;
  589. struct _sas_node *sas_node;
  590. struct sas_rphy *rphy;
  591. int i;
  592. struct sas_port *port;
  593. mpt2sas_port = kzalloc(sizeof(struct _sas_port),
  594. GFP_KERNEL);
  595. if (!mpt2sas_port) {
  596. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  597. ioc->name, __FILE__, __LINE__, __func__);
  598. return NULL;
  599. }
  600. INIT_LIST_HEAD(&mpt2sas_port->port_list);
  601. INIT_LIST_HEAD(&mpt2sas_port->phy_list);
  602. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  603. sas_node = _transport_sas_node_find_by_sas_address(ioc, sas_address);
  604. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  605. if (!sas_node) {
  606. printk(MPT2SAS_ERR_FMT "%s: Could not find "
  607. "parent sas_address(0x%016llx)!\n", ioc->name,
  608. __func__, (unsigned long long)sas_address);
  609. goto out_fail;
  610. }
  611. if ((_transport_set_identify(ioc, handle,
  612. &mpt2sas_port->remote_identify))) {
  613. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  614. ioc->name, __FILE__, __LINE__, __func__);
  615. goto out_fail;
  616. }
  617. if (mpt2sas_port->remote_identify.device_type == SAS_PHY_UNUSED) {
  618. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  619. ioc->name, __FILE__, __LINE__, __func__);
  620. goto out_fail;
  621. }
  622. _transport_sanity_check(ioc, sas_node,
  623. mpt2sas_port->remote_identify.sas_address);
  624. for (i = 0; i < sas_node->num_phys; i++) {
  625. if (sas_node->phy[i].remote_identify.sas_address !=
  626. mpt2sas_port->remote_identify.sas_address)
  627. continue;
  628. list_add_tail(&sas_node->phy[i].port_siblings,
  629. &mpt2sas_port->phy_list);
  630. mpt2sas_port->num_phys++;
  631. }
  632. if (!mpt2sas_port->num_phys) {
  633. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  634. ioc->name, __FILE__, __LINE__, __func__);
  635. goto out_fail;
  636. }
  637. port = sas_port_alloc_num(sas_node->parent_dev);
  638. if ((sas_port_add(port))) {
  639. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  640. ioc->name, __FILE__, __LINE__, __func__);
  641. goto out_fail;
  642. }
  643. list_for_each_entry(mpt2sas_phy, &mpt2sas_port->phy_list,
  644. port_siblings) {
  645. if ((ioc->logging_level & MPT_DEBUG_TRANSPORT))
  646. dev_printk(KERN_INFO, &port->dev, "add: handle(0x%04x)"
  647. ", sas_addr(0x%016llx), phy(%d)\n", handle,
  648. (unsigned long long)
  649. mpt2sas_port->remote_identify.sas_address,
  650. mpt2sas_phy->phy_id);
  651. sas_port_add_phy(port, mpt2sas_phy->phy);
  652. mpt2sas_phy->phy_belongs_to_port = 1;
  653. }
  654. mpt2sas_port->port = port;
  655. if (mpt2sas_port->remote_identify.device_type == SAS_END_DEVICE)
  656. rphy = sas_end_device_alloc(port);
  657. else
  658. rphy = sas_expander_alloc(port,
  659. mpt2sas_port->remote_identify.device_type);
  660. rphy->identify = mpt2sas_port->remote_identify;
  661. if ((sas_rphy_add(rphy))) {
  662. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  663. ioc->name, __FILE__, __LINE__, __func__);
  664. }
  665. if ((ioc->logging_level & MPT_DEBUG_TRANSPORT))
  666. dev_printk(KERN_INFO, &rphy->dev, "add: handle(0x%04x), "
  667. "sas_addr(0x%016llx)\n", handle,
  668. (unsigned long long)
  669. mpt2sas_port->remote_identify.sas_address);
  670. mpt2sas_port->rphy = rphy;
  671. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  672. list_add_tail(&mpt2sas_port->port_list, &sas_node->sas_port_list);
  673. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  674. /* fill in report manufacture */
  675. if (mpt2sas_port->remote_identify.device_type ==
  676. MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER ||
  677. mpt2sas_port->remote_identify.device_type ==
  678. MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER)
  679. _transport_expander_report_manufacture(ioc,
  680. mpt2sas_port->remote_identify.sas_address,
  681. rphy_to_expander_device(rphy));
  682. return mpt2sas_port;
  683. out_fail:
  684. list_for_each_entry_safe(mpt2sas_phy, next, &mpt2sas_port->phy_list,
  685. port_siblings)
  686. list_del(&mpt2sas_phy->port_siblings);
  687. kfree(mpt2sas_port);
  688. return NULL;
  689. }
  690. /**
  691. * mpt2sas_transport_port_remove - remove port from the list
  692. * @ioc: per adapter object
  693. * @sas_address: sas address of attached device
  694. * @sas_address_parent: sas address of parent expander or sas host
  695. * Context: This function will acquire ioc->sas_node_lock.
  696. *
  697. * Removing object and freeing associated memory from the
  698. * ioc->sas_port_list.
  699. *
  700. * Return nothing.
  701. */
  702. void
  703. mpt2sas_transport_port_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
  704. u64 sas_address_parent)
  705. {
  706. int i;
  707. unsigned long flags;
  708. struct _sas_port *mpt2sas_port, *next;
  709. struct _sas_node *sas_node;
  710. u8 found = 0;
  711. struct _sas_phy *mpt2sas_phy, *next_phy;
  712. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  713. sas_node = _transport_sas_node_find_by_sas_address(ioc,
  714. sas_address_parent);
  715. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  716. if (!sas_node)
  717. return;
  718. list_for_each_entry_safe(mpt2sas_port, next, &sas_node->sas_port_list,
  719. port_list) {
  720. if (mpt2sas_port->remote_identify.sas_address != sas_address)
  721. continue;
  722. found = 1;
  723. list_del(&mpt2sas_port->port_list);
  724. goto out;
  725. }
  726. out:
  727. if (!found)
  728. return;
  729. for (i = 0; i < sas_node->num_phys; i++) {
  730. if (sas_node->phy[i].remote_identify.sas_address == sas_address)
  731. memset(&sas_node->phy[i].remote_identify, 0 ,
  732. sizeof(struct sas_identify));
  733. }
  734. list_for_each_entry_safe(mpt2sas_phy, next_phy,
  735. &mpt2sas_port->phy_list, port_siblings) {
  736. if ((ioc->logging_level & MPT_DEBUG_TRANSPORT))
  737. dev_printk(KERN_INFO, &mpt2sas_port->port->dev,
  738. "remove: sas_addr(0x%016llx), phy(%d)\n",
  739. (unsigned long long)
  740. mpt2sas_port->remote_identify.sas_address,
  741. mpt2sas_phy->phy_id);
  742. mpt2sas_phy->phy_belongs_to_port = 0;
  743. sas_port_delete_phy(mpt2sas_port->port, mpt2sas_phy->phy);
  744. list_del(&mpt2sas_phy->port_siblings);
  745. }
  746. sas_port_delete(mpt2sas_port->port);
  747. kfree(mpt2sas_port);
  748. }
  749. /**
  750. * mpt2sas_transport_add_host_phy - report sas_host phy to transport
  751. * @ioc: per adapter object
  752. * @mpt2sas_phy: mpt2sas per phy object
  753. * @phy_pg0: sas phy page 0
  754. * @parent_dev: parent device class object
  755. *
  756. * Returns 0 for success, non-zero for failure.
  757. */
  758. int
  759. mpt2sas_transport_add_host_phy(struct MPT2SAS_ADAPTER *ioc, struct _sas_phy
  760. *mpt2sas_phy, Mpi2SasPhyPage0_t phy_pg0, struct device *parent_dev)
  761. {
  762. struct sas_phy *phy;
  763. int phy_index = mpt2sas_phy->phy_id;
  764. INIT_LIST_HEAD(&mpt2sas_phy->port_siblings);
  765. phy = sas_phy_alloc(parent_dev, phy_index);
  766. if (!phy) {
  767. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  768. ioc->name, __FILE__, __LINE__, __func__);
  769. return -1;
  770. }
  771. if ((_transport_set_identify(ioc, mpt2sas_phy->handle,
  772. &mpt2sas_phy->identify))) {
  773. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  774. ioc->name, __FILE__, __LINE__, __func__);
  775. return -1;
  776. }
  777. phy->identify = mpt2sas_phy->identify;
  778. mpt2sas_phy->attached_handle = le16_to_cpu(phy_pg0.AttachedDevHandle);
  779. if (mpt2sas_phy->attached_handle)
  780. _transport_set_identify(ioc, mpt2sas_phy->attached_handle,
  781. &mpt2sas_phy->remote_identify);
  782. phy->identify.phy_identifier = mpt2sas_phy->phy_id;
  783. phy->negotiated_linkrate = _transport_convert_phy_link_rate(
  784. phy_pg0.NegotiatedLinkRate & MPI2_SAS_NEG_LINK_RATE_MASK_PHYSICAL);
  785. phy->minimum_linkrate_hw = _transport_convert_phy_link_rate(
  786. phy_pg0.HwLinkRate & MPI2_SAS_HWRATE_MIN_RATE_MASK);
  787. phy->maximum_linkrate_hw = _transport_convert_phy_link_rate(
  788. phy_pg0.HwLinkRate >> 4);
  789. phy->minimum_linkrate = _transport_convert_phy_link_rate(
  790. phy_pg0.ProgrammedLinkRate & MPI2_SAS_PRATE_MIN_RATE_MASK);
  791. phy->maximum_linkrate = _transport_convert_phy_link_rate(
  792. phy_pg0.ProgrammedLinkRate >> 4);
  793. if ((sas_phy_add(phy))) {
  794. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  795. ioc->name, __FILE__, __LINE__, __func__);
  796. sas_phy_free(phy);
  797. return -1;
  798. }
  799. if ((ioc->logging_level & MPT_DEBUG_TRANSPORT))
  800. dev_printk(KERN_INFO, &phy->dev,
  801. "add: handle(0x%04x), sas_addr(0x%016llx)\n"
  802. "\tattached_handle(0x%04x), sas_addr(0x%016llx)\n",
  803. mpt2sas_phy->handle, (unsigned long long)
  804. mpt2sas_phy->identify.sas_address,
  805. mpt2sas_phy->attached_handle,
  806. (unsigned long long)
  807. mpt2sas_phy->remote_identify.sas_address);
  808. mpt2sas_phy->phy = phy;
  809. return 0;
  810. }
  811. /**
  812. * mpt2sas_transport_add_expander_phy - report expander phy to transport
  813. * @ioc: per adapter object
  814. * @mpt2sas_phy: mpt2sas per phy object
  815. * @expander_pg1: expander page 1
  816. * @parent_dev: parent device class object
  817. *
  818. * Returns 0 for success, non-zero for failure.
  819. */
  820. int
  821. mpt2sas_transport_add_expander_phy(struct MPT2SAS_ADAPTER *ioc, struct _sas_phy
  822. *mpt2sas_phy, Mpi2ExpanderPage1_t expander_pg1, struct device *parent_dev)
  823. {
  824. struct sas_phy *phy;
  825. int phy_index = mpt2sas_phy->phy_id;
  826. INIT_LIST_HEAD(&mpt2sas_phy->port_siblings);
  827. phy = sas_phy_alloc(parent_dev, phy_index);
  828. if (!phy) {
  829. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  830. ioc->name, __FILE__, __LINE__, __func__);
  831. return -1;
  832. }
  833. if ((_transport_set_identify(ioc, mpt2sas_phy->handle,
  834. &mpt2sas_phy->identify))) {
  835. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  836. ioc->name, __FILE__, __LINE__, __func__);
  837. return -1;
  838. }
  839. phy->identify = mpt2sas_phy->identify;
  840. mpt2sas_phy->attached_handle =
  841. le16_to_cpu(expander_pg1.AttachedDevHandle);
  842. if (mpt2sas_phy->attached_handle)
  843. _transport_set_identify(ioc, mpt2sas_phy->attached_handle,
  844. &mpt2sas_phy->remote_identify);
  845. phy->identify.phy_identifier = mpt2sas_phy->phy_id;
  846. phy->negotiated_linkrate = _transport_convert_phy_link_rate(
  847. expander_pg1.NegotiatedLinkRate &
  848. MPI2_SAS_NEG_LINK_RATE_MASK_PHYSICAL);
  849. phy->minimum_linkrate_hw = _transport_convert_phy_link_rate(
  850. expander_pg1.HwLinkRate & MPI2_SAS_HWRATE_MIN_RATE_MASK);
  851. phy->maximum_linkrate_hw = _transport_convert_phy_link_rate(
  852. expander_pg1.HwLinkRate >> 4);
  853. phy->minimum_linkrate = _transport_convert_phy_link_rate(
  854. expander_pg1.ProgrammedLinkRate & MPI2_SAS_PRATE_MIN_RATE_MASK);
  855. phy->maximum_linkrate = _transport_convert_phy_link_rate(
  856. expander_pg1.ProgrammedLinkRate >> 4);
  857. if ((sas_phy_add(phy))) {
  858. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  859. ioc->name, __FILE__, __LINE__, __func__);
  860. sas_phy_free(phy);
  861. return -1;
  862. }
  863. if ((ioc->logging_level & MPT_DEBUG_TRANSPORT))
  864. dev_printk(KERN_INFO, &phy->dev,
  865. "add: handle(0x%04x), sas_addr(0x%016llx)\n"
  866. "\tattached_handle(0x%04x), sas_addr(0x%016llx)\n",
  867. mpt2sas_phy->handle, (unsigned long long)
  868. mpt2sas_phy->identify.sas_address,
  869. mpt2sas_phy->attached_handle,
  870. (unsigned long long)
  871. mpt2sas_phy->remote_identify.sas_address);
  872. mpt2sas_phy->phy = phy;
  873. return 0;
  874. }
  875. /**
  876. * mpt2sas_transport_update_links - refreshing phy link changes
  877. * @ioc: per adapter object
  878. * @sas_address: sas address of parent expander or sas host
  879. * @handle: attached device handle
  880. * @phy_numberv: phy number
  881. * @link_rate: new link rate
  882. *
  883. * Returns nothing.
  884. */
  885. void
  886. mpt2sas_transport_update_links(struct MPT2SAS_ADAPTER *ioc,
  887. u64 sas_address, u16 handle, u8 phy_number, u8 link_rate)
  888. {
  889. unsigned long flags;
  890. struct _sas_node *sas_node;
  891. struct _sas_phy *mpt2sas_phy;
  892. if (ioc->shost_recovery || ioc->pci_error_recovery)
  893. return;
  894. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  895. sas_node = _transport_sas_node_find_by_sas_address(ioc, sas_address);
  896. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  897. if (!sas_node)
  898. return;
  899. mpt2sas_phy = &sas_node->phy[phy_number];
  900. mpt2sas_phy->attached_handle = handle;
  901. if (handle && (link_rate >= MPI2_SAS_NEG_LINK_RATE_1_5)) {
  902. _transport_set_identify(ioc, handle,
  903. &mpt2sas_phy->remote_identify);
  904. _transport_add_phy_to_an_existing_port(ioc, sas_node,
  905. mpt2sas_phy, mpt2sas_phy->remote_identify.sas_address);
  906. } else
  907. memset(&mpt2sas_phy->remote_identify, 0 , sizeof(struct
  908. sas_identify));
  909. if (mpt2sas_phy->phy)
  910. mpt2sas_phy->phy->negotiated_linkrate =
  911. _transport_convert_phy_link_rate(link_rate);
  912. if ((ioc->logging_level & MPT_DEBUG_TRANSPORT))
  913. dev_printk(KERN_INFO, &mpt2sas_phy->phy->dev,
  914. "refresh: parent sas_addr(0x%016llx),\n"
  915. "\tlink_rate(0x%02x), phy(%d)\n"
  916. "\tattached_handle(0x%04x), sas_addr(0x%016llx)\n",
  917. (unsigned long long)sas_address,
  918. link_rate, phy_number, handle, (unsigned long long)
  919. mpt2sas_phy->remote_identify.sas_address);
  920. }
  921. static inline void *
  922. phy_to_ioc(struct sas_phy *phy)
  923. {
  924. struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
  925. return shost_priv(shost);
  926. }
  927. static inline void *
  928. rphy_to_ioc(struct sas_rphy *rphy)
  929. {
  930. struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent->parent);
  931. return shost_priv(shost);
  932. }
  933. /* report phy error log structure */
  934. struct phy_error_log_request{
  935. u8 smp_frame_type; /* 0x40 */
  936. u8 function; /* 0x11 */
  937. u8 allocated_response_length;
  938. u8 request_length; /* 02 */
  939. u8 reserved_1[5];
  940. u8 phy_identifier;
  941. u8 reserved_2[2];
  942. };
  943. /* report phy error log reply structure */
  944. struct phy_error_log_reply{
  945. u8 smp_frame_type; /* 0x41 */
  946. u8 function; /* 0x11 */
  947. u8 function_result;
  948. u8 response_length;
  949. u16 expander_change_count;
  950. u8 reserved_1[3];
  951. u8 phy_identifier;
  952. u8 reserved_2[2];
  953. u32 invalid_dword;
  954. u32 running_disparity_error;
  955. u32 loss_of_dword_sync;
  956. u32 phy_reset_problem;
  957. };
  958. /**
  959. * _transport_get_expander_phy_error_log - return expander counters
  960. * @ioc: per adapter object
  961. * @phy: The sas phy object
  962. *
  963. * Returns 0 for success, non-zero for failure.
  964. *
  965. */
  966. static int
  967. _transport_get_expander_phy_error_log(struct MPT2SAS_ADAPTER *ioc,
  968. struct sas_phy *phy)
  969. {
  970. Mpi2SmpPassthroughRequest_t *mpi_request;
  971. Mpi2SmpPassthroughReply_t *mpi_reply;
  972. struct phy_error_log_request *phy_error_log_request;
  973. struct phy_error_log_reply *phy_error_log_reply;
  974. int rc;
  975. u16 smid;
  976. u32 ioc_state;
  977. unsigned long timeleft;
  978. void *psge;
  979. u32 sgl_flags;
  980. u8 issue_reset = 0;
  981. void *data_out = NULL;
  982. dma_addr_t data_out_dma;
  983. u32 sz;
  984. u64 *sas_address_le;
  985. u16 wait_state_count;
  986. if (ioc->shost_recovery || ioc->pci_error_recovery) {
  987. printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
  988. __func__, ioc->name);
  989. return -EFAULT;
  990. }
  991. mutex_lock(&ioc->transport_cmds.mutex);
  992. if (ioc->transport_cmds.status != MPT2_CMD_NOT_USED) {
  993. printk(MPT2SAS_ERR_FMT "%s: transport_cmds in use\n",
  994. ioc->name, __func__);
  995. rc = -EAGAIN;
  996. goto out;
  997. }
  998. ioc->transport_cmds.status = MPT2_CMD_PENDING;
  999. wait_state_count = 0;
  1000. ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
  1001. while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
  1002. if (wait_state_count++ == 10) {
  1003. printk(MPT2SAS_ERR_FMT
  1004. "%s: failed due to ioc not operational\n",
  1005. ioc->name, __func__);
  1006. rc = -EFAULT;
  1007. goto out;
  1008. }
  1009. ssleep(1);
  1010. ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
  1011. printk(MPT2SAS_INFO_FMT "%s: waiting for "
  1012. "operational state(count=%d)\n", ioc->name,
  1013. __func__, wait_state_count);
  1014. }
  1015. if (wait_state_count)
  1016. printk(MPT2SAS_INFO_FMT "%s: ioc is operational\n",
  1017. ioc->name, __func__);
  1018. smid = mpt2sas_base_get_smid(ioc, ioc->transport_cb_idx);
  1019. if (!smid) {
  1020. printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
  1021. ioc->name, __func__);
  1022. rc = -EAGAIN;
  1023. goto out;
  1024. }
  1025. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
  1026. ioc->transport_cmds.smid = smid;
  1027. sz = sizeof(struct phy_error_log_request) +
  1028. sizeof(struct phy_error_log_reply);
  1029. data_out = pci_alloc_consistent(ioc->pdev, sz, &data_out_dma);
  1030. if (!data_out) {
  1031. printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__,
  1032. __LINE__, __func__);
  1033. rc = -ENOMEM;
  1034. mpt2sas_base_free_smid(ioc, smid);
  1035. goto out;
  1036. }
  1037. rc = -EINVAL;
  1038. memset(data_out, 0, sz);
  1039. phy_error_log_request = data_out;
  1040. phy_error_log_request->smp_frame_type = 0x40;
  1041. phy_error_log_request->function = 0x11;
  1042. phy_error_log_request->request_length = 2;
  1043. phy_error_log_request->allocated_response_length = 0;
  1044. phy_error_log_request->phy_identifier = phy->number;
  1045. memset(mpi_request, 0, sizeof(Mpi2SmpPassthroughRequest_t));
  1046. mpi_request->Function = MPI2_FUNCTION_SMP_PASSTHROUGH;
  1047. mpi_request->PhysicalPort = 0xFF;
  1048. mpi_request->VF_ID = 0; /* TODO */
  1049. mpi_request->VP_ID = 0;
  1050. sas_address_le = (u64 *)&mpi_request->SASAddress;
  1051. *sas_address_le = cpu_to_le64(phy->identify.sas_address);
  1052. mpi_request->RequestDataLength =
  1053. cpu_to_le16(sizeof(struct phy_error_log_request));
  1054. psge = &mpi_request->SGL;
  1055. /* WRITE sgel first */
  1056. sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT |
  1057. MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_HOST_TO_IOC);
  1058. sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
  1059. ioc->base_add_sg_single(psge, sgl_flags |
  1060. sizeof(struct phy_error_log_request), data_out_dma);
  1061. /* incr sgel */
  1062. psge += ioc->sge_size;
  1063. /* READ sgel last */
  1064. sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT |
  1065. MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER |
  1066. MPI2_SGE_FLAGS_END_OF_LIST);
  1067. sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
  1068. ioc->base_add_sg_single(psge, sgl_flags |
  1069. sizeof(struct phy_error_log_reply), data_out_dma +
  1070. sizeof(struct phy_error_log_request));
  1071. dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT "phy_error_log - "
  1072. "send to sas_addr(0x%016llx), phy(%d)\n", ioc->name,
  1073. (unsigned long long)phy->identify.sas_address, phy->number));
  1074. mpt2sas_base_put_smid_default(ioc, smid);
  1075. init_completion(&ioc->transport_cmds.done);
  1076. timeleft = wait_for_completion_timeout(&ioc->transport_cmds.done,
  1077. 10*HZ);
  1078. if (!(ioc->transport_cmds.status & MPT2_CMD_COMPLETE)) {
  1079. printk(MPT2SAS_ERR_FMT "%s: timeout\n",
  1080. ioc->name, __func__);
  1081. _debug_dump_mf(mpi_request,
  1082. sizeof(Mpi2SmpPassthroughRequest_t)/4);
  1083. if (!(ioc->transport_cmds.status & MPT2_CMD_RESET))
  1084. issue_reset = 1;
  1085. goto issue_host_reset;
  1086. }
  1087. dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT "phy_error_log - "
  1088. "complete\n", ioc->name));
  1089. if (ioc->transport_cmds.status & MPT2_CMD_REPLY_VALID) {
  1090. mpi_reply = ioc->transport_cmds.reply;
  1091. dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT
  1092. "phy_error_log - reply data transfer size(%d)\n",
  1093. ioc->name, le16_to_cpu(mpi_reply->ResponseDataLength)));
  1094. if (le16_to_cpu(mpi_reply->ResponseDataLength) !=
  1095. sizeof(struct phy_error_log_reply))
  1096. goto out;
  1097. phy_error_log_reply = data_out +
  1098. sizeof(struct phy_error_log_request);
  1099. dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT
  1100. "phy_error_log - function_result(%d)\n",
  1101. ioc->name, phy_error_log_reply->function_result));
  1102. phy->invalid_dword_count =
  1103. be32_to_cpu(phy_error_log_reply->invalid_dword);
  1104. phy->running_disparity_error_count =
  1105. be32_to_cpu(phy_error_log_reply->running_disparity_error);
  1106. phy->loss_of_dword_sync_count =
  1107. be32_to_cpu(phy_error_log_reply->loss_of_dword_sync);
  1108. phy->phy_reset_problem_count =
  1109. be32_to_cpu(phy_error_log_reply->phy_reset_problem);
  1110. rc = 0;
  1111. } else
  1112. dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT
  1113. "phy_error_log - no reply\n", ioc->name));
  1114. issue_host_reset:
  1115. if (issue_reset)
  1116. mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
  1117. FORCE_BIG_HAMMER);
  1118. out:
  1119. ioc->transport_cmds.status = MPT2_CMD_NOT_USED;
  1120. if (data_out)
  1121. pci_free_consistent(ioc->pdev, sz, data_out, data_out_dma);
  1122. mutex_unlock(&ioc->transport_cmds.mutex);
  1123. return rc;
  1124. }
  1125. /**
  1126. * _transport_get_linkerrors - return phy counters for both hba and expanders
  1127. * @phy: The sas phy object
  1128. *
  1129. * Returns 0 for success, non-zero for failure.
  1130. *
  1131. */
  1132. static int
  1133. _transport_get_linkerrors(struct sas_phy *phy)
  1134. {
  1135. struct MPT2SAS_ADAPTER *ioc = phy_to_ioc(phy);
  1136. unsigned long flags;
  1137. Mpi2ConfigReply_t mpi_reply;
  1138. Mpi2SasPhyPage1_t phy_pg1;
  1139. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  1140. if (_transport_sas_node_find_by_sas_address(ioc,
  1141. phy->identify.sas_address) == NULL) {
  1142. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  1143. return -EINVAL;
  1144. }
  1145. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  1146. if (phy->identify.sas_address != ioc->sas_hba.sas_address)
  1147. return _transport_get_expander_phy_error_log(ioc, phy);
  1148. /* get hba phy error logs */
  1149. if ((mpt2sas_config_get_phy_pg1(ioc, &mpi_reply, &phy_pg1,
  1150. phy->number))) {
  1151. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1152. ioc->name, __FILE__, __LINE__, __func__);
  1153. return -ENXIO;
  1154. }
  1155. if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo)
  1156. printk(MPT2SAS_INFO_FMT "phy(%d), ioc_status"
  1157. "(0x%04x), loginfo(0x%08x)\n", ioc->name,
  1158. phy->number, le16_to_cpu(mpi_reply.IOCStatus),
  1159. le32_to_cpu(mpi_reply.IOCLogInfo));
  1160. phy->invalid_dword_count = le32_to_cpu(phy_pg1.InvalidDwordCount);
  1161. phy->running_disparity_error_count =
  1162. le32_to_cpu(phy_pg1.RunningDisparityErrorCount);
  1163. phy->loss_of_dword_sync_count =
  1164. le32_to_cpu(phy_pg1.LossDwordSynchCount);
  1165. phy->phy_reset_problem_count =
  1166. le32_to_cpu(phy_pg1.PhyResetProblemCount);
  1167. return 0;
  1168. }
  1169. /**
  1170. * _transport_get_enclosure_identifier -
  1171. * @phy: The sas phy object
  1172. *
  1173. * Obtain the enclosure logical id for an expander.
  1174. * Returns 0 for success, non-zero for failure.
  1175. */
  1176. static int
  1177. _transport_get_enclosure_identifier(struct sas_rphy *rphy, u64 *identifier)
  1178. {
  1179. struct MPT2SAS_ADAPTER *ioc = rphy_to_ioc(rphy);
  1180. struct _sas_device *sas_device;
  1181. unsigned long flags;
  1182. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  1183. sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  1184. rphy->identify.sas_address);
  1185. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  1186. if (!sas_device)
  1187. return -ENXIO;
  1188. *identifier = sas_device->enclosure_logical_id;
  1189. return 0;
  1190. }
  1191. /**
  1192. * _transport_get_bay_identifier -
  1193. * @phy: The sas phy object
  1194. *
  1195. * Returns the slot id for a device that resides inside an enclosure.
  1196. */
  1197. static int
  1198. _transport_get_bay_identifier(struct sas_rphy *rphy)
  1199. {
  1200. struct MPT2SAS_ADAPTER *ioc = rphy_to_ioc(rphy);
  1201. struct _sas_device *sas_device;
  1202. unsigned long flags;
  1203. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  1204. sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  1205. rphy->identify.sas_address);
  1206. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  1207. if (!sas_device)
  1208. return -ENXIO;
  1209. return sas_device->slot;
  1210. }
  1211. /* phy control request structure */
  1212. struct phy_control_request{
  1213. u8 smp_frame_type; /* 0x40 */
  1214. u8 function; /* 0x91 */
  1215. u8 allocated_response_length;
  1216. u8 request_length; /* 0x09 */
  1217. u16 expander_change_count;
  1218. u8 reserved_1[3];
  1219. u8 phy_identifier;
  1220. u8 phy_operation;
  1221. u8 reserved_2[13];
  1222. u64 attached_device_name;
  1223. u8 programmed_min_physical_link_rate;
  1224. u8 programmed_max_physical_link_rate;
  1225. u8 reserved_3[6];
  1226. };
  1227. /* phy control reply structure */
  1228. struct phy_control_reply{
  1229. u8 smp_frame_type; /* 0x41 */
  1230. u8 function; /* 0x11 */
  1231. u8 function_result;
  1232. u8 response_length;
  1233. };
  1234. #define SMP_PHY_CONTROL_LINK_RESET (0x01)
  1235. #define SMP_PHY_CONTROL_HARD_RESET (0x02)
  1236. #define SMP_PHY_CONTROL_DISABLE (0x03)
  1237. /**
  1238. * _transport_expander_phy_control - expander phy control
  1239. * @ioc: per adapter object
  1240. * @phy: The sas phy object
  1241. *
  1242. * Returns 0 for success, non-zero for failure.
  1243. *
  1244. */
  1245. static int
  1246. _transport_expander_phy_control(struct MPT2SAS_ADAPTER *ioc,
  1247. struct sas_phy *phy, u8 phy_operation)
  1248. {
  1249. Mpi2SmpPassthroughRequest_t *mpi_request;
  1250. Mpi2SmpPassthroughReply_t *mpi_reply;
  1251. struct phy_control_request *phy_control_request;
  1252. struct phy_control_reply *phy_control_reply;
  1253. int rc;
  1254. u16 smid;
  1255. u32 ioc_state;
  1256. unsigned long timeleft;
  1257. void *psge;
  1258. u32 sgl_flags;
  1259. u8 issue_reset = 0;
  1260. void *data_out = NULL;
  1261. dma_addr_t data_out_dma;
  1262. u32 sz;
  1263. u64 *sas_address_le;
  1264. u16 wait_state_count;
  1265. if (ioc->shost_recovery) {
  1266. printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
  1267. __func__, ioc->name);
  1268. return -EFAULT;
  1269. }
  1270. mutex_lock(&ioc->transport_cmds.mutex);
  1271. if (ioc->transport_cmds.status != MPT2_CMD_NOT_USED) {
  1272. printk(MPT2SAS_ERR_FMT "%s: transport_cmds in use\n",
  1273. ioc->name, __func__);
  1274. rc = -EAGAIN;
  1275. goto out;
  1276. }
  1277. ioc->transport_cmds.status = MPT2_CMD_PENDING;
  1278. wait_state_count = 0;
  1279. ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
  1280. while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
  1281. if (wait_state_count++ == 10) {
  1282. printk(MPT2SAS_ERR_FMT
  1283. "%s: failed due to ioc not operational\n",
  1284. ioc->name, __func__);
  1285. rc = -EFAULT;
  1286. goto out;
  1287. }
  1288. ssleep(1);
  1289. ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
  1290. printk(MPT2SAS_INFO_FMT "%s: waiting for "
  1291. "operational state(count=%d)\n", ioc->name,
  1292. __func__, wait_state_count);
  1293. }
  1294. if (wait_state_count)
  1295. printk(MPT2SAS_INFO_FMT "%s: ioc is operational\n",
  1296. ioc->name, __func__);
  1297. smid = mpt2sas_base_get_smid(ioc, ioc->transport_cb_idx);
  1298. if (!smid) {
  1299. printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
  1300. ioc->name, __func__);
  1301. rc = -EAGAIN;
  1302. goto out;
  1303. }
  1304. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
  1305. ioc->transport_cmds.smid = smid;
  1306. sz = sizeof(struct phy_control_request) +
  1307. sizeof(struct phy_control_reply);
  1308. data_out = pci_alloc_consistent(ioc->pdev, sz, &data_out_dma);
  1309. if (!data_out) {
  1310. printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__,
  1311. __LINE__, __func__);
  1312. rc = -ENOMEM;
  1313. mpt2sas_base_free_smid(ioc, smid);
  1314. goto out;
  1315. }
  1316. rc = -EINVAL;
  1317. memset(data_out, 0, sz);
  1318. phy_control_request = data_out;
  1319. phy_control_request->smp_frame_type = 0x40;
  1320. phy_control_request->function = 0x91;
  1321. phy_control_request->request_length = 9;
  1322. phy_control_request->allocated_response_length = 0;
  1323. phy_control_request->phy_identifier = phy->number;
  1324. phy_control_request->phy_operation = phy_operation;
  1325. phy_control_request->programmed_min_physical_link_rate =
  1326. phy->minimum_linkrate << 4;
  1327. phy_control_request->programmed_max_physical_link_rate =
  1328. phy->maximum_linkrate << 4;
  1329. memset(mpi_request, 0, sizeof(Mpi2SmpPassthroughRequest_t));
  1330. mpi_request->Function = MPI2_FUNCTION_SMP_PASSTHROUGH;
  1331. mpi_request->PhysicalPort = 0xFF;
  1332. mpi_request->VF_ID = 0; /* TODO */
  1333. mpi_request->VP_ID = 0;
  1334. sas_address_le = (u64 *)&mpi_request->SASAddress;
  1335. *sas_address_le = cpu_to_le64(phy->identify.sas_address);
  1336. mpi_request->RequestDataLength =
  1337. cpu_to_le16(sizeof(struct phy_error_log_request));
  1338. psge = &mpi_request->SGL;
  1339. /* WRITE sgel first */
  1340. sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT |
  1341. MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_HOST_TO_IOC);
  1342. sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
  1343. ioc->base_add_sg_single(psge, sgl_flags |
  1344. sizeof(struct phy_control_request), data_out_dma);
  1345. /* incr sgel */
  1346. psge += ioc->sge_size;
  1347. /* READ sgel last */
  1348. sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT |
  1349. MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER |
  1350. MPI2_SGE_FLAGS_END_OF_LIST);
  1351. sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
  1352. ioc->base_add_sg_single(psge, sgl_flags |
  1353. sizeof(struct phy_control_reply), data_out_dma +
  1354. sizeof(struct phy_control_request));
  1355. dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT "phy_control - "
  1356. "send to sas_addr(0x%016llx), phy(%d), opcode(%d)\n", ioc->name,
  1357. (unsigned long long)phy->identify.sas_address, phy->number,
  1358. phy_operation));
  1359. mpt2sas_base_put_smid_default(ioc, smid);
  1360. init_completion(&ioc->transport_cmds.done);
  1361. timeleft = wait_for_completion_timeout(&ioc->transport_cmds.done,
  1362. 10*HZ);
  1363. if (!(ioc->transport_cmds.status & MPT2_CMD_COMPLETE)) {
  1364. printk(MPT2SAS_ERR_FMT "%s: timeout\n",
  1365. ioc->name, __func__);
  1366. _debug_dump_mf(mpi_request,
  1367. sizeof(Mpi2SmpPassthroughRequest_t)/4);
  1368. if (!(ioc->transport_cmds.status & MPT2_CMD_RESET))
  1369. issue_reset = 1;
  1370. goto issue_host_reset;
  1371. }
  1372. dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT "phy_control - "
  1373. "complete\n", ioc->name));
  1374. if (ioc->transport_cmds.status & MPT2_CMD_REPLY_VALID) {
  1375. mpi_reply = ioc->transport_cmds.reply;
  1376. dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT
  1377. "phy_control - reply data transfer size(%d)\n",
  1378. ioc->name, le16_to_cpu(mpi_reply->ResponseDataLength)));
  1379. if (le16_to_cpu(mpi_reply->ResponseDataLength) !=
  1380. sizeof(struct phy_control_reply))
  1381. goto out;
  1382. phy_control_reply = data_out +
  1383. sizeof(struct phy_control_request);
  1384. dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT
  1385. "phy_control - function_result(%d)\n",
  1386. ioc->name, phy_control_reply->function_result));
  1387. rc = 0;
  1388. } else
  1389. dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT
  1390. "phy_control - no reply\n", ioc->name));
  1391. issue_host_reset:
  1392. if (issue_reset)
  1393. mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
  1394. FORCE_BIG_HAMMER);
  1395. out:
  1396. ioc->transport_cmds.status = MPT2_CMD_NOT_USED;
  1397. if (data_out)
  1398. pci_free_consistent(ioc->pdev, sz, data_out, data_out_dma);
  1399. mutex_unlock(&ioc->transport_cmds.mutex);
  1400. return rc;
  1401. }
  1402. /**
  1403. * _transport_phy_reset -
  1404. * @phy: The sas phy object
  1405. * @hard_reset:
  1406. *
  1407. * Returns 0 for success, non-zero for failure.
  1408. */
  1409. static int
  1410. _transport_phy_reset(struct sas_phy *phy, int hard_reset)
  1411. {
  1412. struct MPT2SAS_ADAPTER *ioc = phy_to_ioc(phy);
  1413. Mpi2SasIoUnitControlReply_t mpi_reply;
  1414. Mpi2SasIoUnitControlRequest_t mpi_request;
  1415. unsigned long flags;
  1416. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  1417. if (_transport_sas_node_find_by_sas_address(ioc,
  1418. phy->identify.sas_address) == NULL) {
  1419. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  1420. return -EINVAL;
  1421. }
  1422. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  1423. /* handle expander phys */
  1424. if (phy->identify.sas_address != ioc->sas_hba.sas_address)
  1425. return _transport_expander_phy_control(ioc, phy,
  1426. (hard_reset == 1) ? SMP_PHY_CONTROL_HARD_RESET :
  1427. SMP_PHY_CONTROL_LINK_RESET);
  1428. /* handle hba phys */
  1429. memset(&mpi_request, 0, sizeof(Mpi2SasIoUnitControlReply_t));
  1430. mpi_request.Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
  1431. mpi_request.Operation = hard_reset ?
  1432. MPI2_SAS_OP_PHY_HARD_RESET : MPI2_SAS_OP_PHY_LINK_RESET;
  1433. mpi_request.PhyNum = phy->number;
  1434. if ((mpt2sas_base_sas_iounit_control(ioc, &mpi_reply, &mpi_request))) {
  1435. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1436. ioc->name, __FILE__, __LINE__, __func__);
  1437. return -ENXIO;
  1438. }
  1439. if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo)
  1440. printk(MPT2SAS_INFO_FMT "phy(%d), ioc_status"
  1441. "(0x%04x), loginfo(0x%08x)\n", ioc->name,
  1442. phy->number, le16_to_cpu(mpi_reply.IOCStatus),
  1443. le32_to_cpu(mpi_reply.IOCLogInfo));
  1444. return 0;
  1445. }
  1446. /**
  1447. * _transport_phy_enable - enable/disable phys
  1448. * @phy: The sas phy object
  1449. * @enable: enable phy when true
  1450. *
  1451. * Only support sas_host direct attached phys.
  1452. * Returns 0 for success, non-zero for failure.
  1453. */
  1454. static int
  1455. _transport_phy_enable(struct sas_phy *phy, int enable)
  1456. {
  1457. struct MPT2SAS_ADAPTER *ioc = phy_to_ioc(phy);
  1458. Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
  1459. Mpi2ConfigReply_t mpi_reply;
  1460. u16 ioc_status;
  1461. u16 sz;
  1462. int rc = 0;
  1463. unsigned long flags;
  1464. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  1465. if (_transport_sas_node_find_by_sas_address(ioc,
  1466. phy->identify.sas_address) == NULL) {
  1467. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  1468. return -EINVAL;
  1469. }
  1470. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  1471. /* handle expander phys */
  1472. if (phy->identify.sas_address != ioc->sas_hba.sas_address)
  1473. return _transport_expander_phy_control(ioc, phy,
  1474. (enable == 1) ? SMP_PHY_CONTROL_LINK_RESET :
  1475. SMP_PHY_CONTROL_DISABLE);
  1476. /* handle hba phys */
  1477. /* sas_iounit page 1 */
  1478. sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
  1479. sizeof(Mpi2SasIOUnit1PhyData_t));
  1480. sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
  1481. if (!sas_iounit_pg1) {
  1482. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1483. ioc->name, __FILE__, __LINE__, __func__);
  1484. rc = -ENOMEM;
  1485. goto out;
  1486. }
  1487. if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
  1488. sas_iounit_pg1, sz))) {
  1489. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1490. ioc->name, __FILE__, __LINE__, __func__);
  1491. rc = -ENXIO;
  1492. goto out;
  1493. }
  1494. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  1495. MPI2_IOCSTATUS_MASK;
  1496. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  1497. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1498. ioc->name, __FILE__, __LINE__, __func__);
  1499. rc = -EIO;
  1500. goto out;
  1501. }
  1502. if (enable)
  1503. sas_iounit_pg1->PhyData[phy->number].PhyFlags
  1504. &= ~MPI2_SASIOUNIT1_PHYFLAGS_PHY_DISABLE;
  1505. else
  1506. sas_iounit_pg1->PhyData[phy->number].PhyFlags
  1507. |= MPI2_SASIOUNIT1_PHYFLAGS_PHY_DISABLE;
  1508. mpt2sas_config_set_sas_iounit_pg1(ioc, &mpi_reply, sas_iounit_pg1, sz);
  1509. /* link reset */
  1510. if (enable)
  1511. _transport_phy_reset(phy, 0);
  1512. out:
  1513. kfree(sas_iounit_pg1);
  1514. return rc;
  1515. }
  1516. /**
  1517. * _transport_phy_speed - set phy min/max link rates
  1518. * @phy: The sas phy object
  1519. * @rates: rates defined in sas_phy_linkrates
  1520. *
  1521. * Only support sas_host direct attached phys.
  1522. * Returns 0 for success, non-zero for failure.
  1523. */
  1524. static int
  1525. _transport_phy_speed(struct sas_phy *phy, struct sas_phy_linkrates *rates)
  1526. {
  1527. struct MPT2SAS_ADAPTER *ioc = phy_to_ioc(phy);
  1528. Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
  1529. Mpi2SasPhyPage0_t phy_pg0;
  1530. Mpi2ConfigReply_t mpi_reply;
  1531. u16 ioc_status;
  1532. u16 sz;
  1533. int i;
  1534. int rc = 0;
  1535. unsigned long flags;
  1536. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  1537. if (_transport_sas_node_find_by_sas_address(ioc,
  1538. phy->identify.sas_address) == NULL) {
  1539. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  1540. return -EINVAL;
  1541. }
  1542. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  1543. if (!rates->minimum_linkrate)
  1544. rates->minimum_linkrate = phy->minimum_linkrate;
  1545. else if (rates->minimum_linkrate < phy->minimum_linkrate_hw)
  1546. rates->minimum_linkrate = phy->minimum_linkrate_hw;
  1547. if (!rates->maximum_linkrate)
  1548. rates->maximum_linkrate = phy->maximum_linkrate;
  1549. else if (rates->maximum_linkrate > phy->maximum_linkrate_hw)
  1550. rates->maximum_linkrate = phy->maximum_linkrate_hw;
  1551. /* handle expander phys */
  1552. if (phy->identify.sas_address != ioc->sas_hba.sas_address) {
  1553. phy->minimum_linkrate = rates->minimum_linkrate;
  1554. phy->maximum_linkrate = rates->maximum_linkrate;
  1555. return _transport_expander_phy_control(ioc, phy,
  1556. SMP_PHY_CONTROL_LINK_RESET);
  1557. }
  1558. /* handle hba phys */
  1559. /* sas_iounit page 1 */
  1560. sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
  1561. sizeof(Mpi2SasIOUnit1PhyData_t));
  1562. sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
  1563. if (!sas_iounit_pg1) {
  1564. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1565. ioc->name, __FILE__, __LINE__, __func__);
  1566. rc = -ENOMEM;
  1567. goto out;
  1568. }
  1569. if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
  1570. sas_iounit_pg1, sz))) {
  1571. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1572. ioc->name, __FILE__, __LINE__, __func__);
  1573. rc = -ENXIO;
  1574. goto out;
  1575. }
  1576. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  1577. MPI2_IOCSTATUS_MASK;
  1578. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  1579. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1580. ioc->name, __FILE__, __LINE__, __func__);
  1581. rc = -EIO;
  1582. goto out;
  1583. }
  1584. for (i = 0; i < ioc->sas_hba.num_phys; i++) {
  1585. if (phy->number != i) {
  1586. sas_iounit_pg1->PhyData[i].MaxMinLinkRate =
  1587. (ioc->sas_hba.phy[i].phy->minimum_linkrate +
  1588. (ioc->sas_hba.phy[i].phy->maximum_linkrate << 4));
  1589. } else {
  1590. sas_iounit_pg1->PhyData[i].MaxMinLinkRate =
  1591. (rates->minimum_linkrate +
  1592. (rates->maximum_linkrate << 4));
  1593. }
  1594. }
  1595. if (mpt2sas_config_set_sas_iounit_pg1(ioc, &mpi_reply, sas_iounit_pg1,
  1596. sz)) {
  1597. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1598. ioc->name, __FILE__, __LINE__, __func__);
  1599. rc = -ENXIO;
  1600. goto out;
  1601. }
  1602. /* link reset */
  1603. _transport_phy_reset(phy, 0);
  1604. /* read phy page 0, then update the rates in the sas transport phy */
  1605. if (!mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
  1606. phy->number)) {
  1607. phy->minimum_linkrate = _transport_convert_phy_link_rate(
  1608. phy_pg0.ProgrammedLinkRate & MPI2_SAS_PRATE_MIN_RATE_MASK);
  1609. phy->maximum_linkrate = _transport_convert_phy_link_rate(
  1610. phy_pg0.ProgrammedLinkRate >> 4);
  1611. phy->negotiated_linkrate = _transport_convert_phy_link_rate(
  1612. phy_pg0.NegotiatedLinkRate &
  1613. MPI2_SAS_NEG_LINK_RATE_MASK_PHYSICAL);
  1614. }
  1615. out:
  1616. kfree(sas_iounit_pg1);
  1617. return rc;
  1618. }
  1619. /**
  1620. * _transport_smp_handler - transport portal for smp passthru
  1621. * @shost: shost object
  1622. * @rphy: sas transport rphy object
  1623. * @req:
  1624. *
  1625. * This used primarily for smp_utils.
  1626. * Example:
  1627. * smp_rep_general /sys/class/bsg/expander-5:0
  1628. */
  1629. static int
  1630. _transport_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
  1631. struct request *req)
  1632. {
  1633. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  1634. Mpi2SmpPassthroughRequest_t *mpi_request;
  1635. Mpi2SmpPassthroughReply_t *mpi_reply;
  1636. int rc;
  1637. u16 smid;
  1638. u32 ioc_state;
  1639. unsigned long timeleft;
  1640. void *psge;
  1641. u32 sgl_flags;
  1642. u8 issue_reset = 0;
  1643. dma_addr_t dma_addr_in = 0;
  1644. dma_addr_t dma_addr_out = 0;
  1645. u16 wait_state_count;
  1646. struct request *rsp = req->next_rq;
  1647. if (!rsp) {
  1648. printk(MPT2SAS_ERR_FMT "%s: the smp response space is "
  1649. "missing\n", ioc->name, __func__);
  1650. return -EINVAL;
  1651. }
  1652. /* do we need to support multiple segments? */
  1653. if (req->bio->bi_vcnt > 1 || rsp->bio->bi_vcnt > 1) {
  1654. printk(MPT2SAS_ERR_FMT "%s: multiple segments req %u %u, "
  1655. "rsp %u %u\n", ioc->name, __func__, req->bio->bi_vcnt,
  1656. blk_rq_bytes(req), rsp->bio->bi_vcnt, blk_rq_bytes(rsp));
  1657. return -EINVAL;
  1658. }
  1659. if (ioc->shost_recovery) {
  1660. printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
  1661. __func__, ioc->name);
  1662. return -EFAULT;
  1663. }
  1664. rc = mutex_lock_interruptible(&ioc->transport_cmds.mutex);
  1665. if (rc)
  1666. return rc;
  1667. if (ioc->transport_cmds.status != MPT2_CMD_NOT_USED) {
  1668. printk(MPT2SAS_ERR_FMT "%s: transport_cmds in use\n", ioc->name,
  1669. __func__);
  1670. rc = -EAGAIN;
  1671. goto out;
  1672. }
  1673. ioc->transport_cmds.status = MPT2_CMD_PENDING;
  1674. wait_state_count = 0;
  1675. ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
  1676. while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
  1677. if (wait_state_count++ == 10) {
  1678. printk(MPT2SAS_ERR_FMT
  1679. "%s: failed due to ioc not operational\n",
  1680. ioc->name, __func__);
  1681. rc = -EFAULT;
  1682. goto out;
  1683. }
  1684. ssleep(1);
  1685. ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
  1686. printk(MPT2SAS_INFO_FMT "%s: waiting for "
  1687. "operational state(count=%d)\n", ioc->name,
  1688. __func__, wait_state_count);
  1689. }
  1690. if (wait_state_count)
  1691. printk(MPT2SAS_INFO_FMT "%s: ioc is operational\n",
  1692. ioc->name, __func__);
  1693. smid = mpt2sas_base_get_smid(ioc, ioc->transport_cb_idx);
  1694. if (!smid) {
  1695. printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
  1696. ioc->name, __func__);
  1697. rc = -EAGAIN;
  1698. goto out;
  1699. }
  1700. rc = 0;
  1701. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
  1702. ioc->transport_cmds.smid = smid;
  1703. memset(mpi_request, 0, sizeof(Mpi2SmpPassthroughRequest_t));
  1704. mpi_request->Function = MPI2_FUNCTION_SMP_PASSTHROUGH;
  1705. mpi_request->PhysicalPort = 0xFF;
  1706. mpi_request->VF_ID = 0; /* TODO */
  1707. mpi_request->VP_ID = 0;
  1708. *((u64 *)&mpi_request->SASAddress) = (rphy) ?
  1709. cpu_to_le64(rphy->identify.sas_address) :
  1710. cpu_to_le64(ioc->sas_hba.sas_address);
  1711. mpi_request->RequestDataLength = cpu_to_le16(blk_rq_bytes(req) - 4);
  1712. psge = &mpi_request->SGL;
  1713. /* WRITE sgel first */
  1714. sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT |
  1715. MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_HOST_TO_IOC);
  1716. sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
  1717. dma_addr_out = pci_map_single(ioc->pdev, bio_data(req->bio),
  1718. blk_rq_bytes(req), PCI_DMA_BIDIRECTIONAL);
  1719. if (!dma_addr_out) {
  1720. mpt2sas_base_free_smid(ioc, smid);
  1721. goto unmap;
  1722. }
  1723. ioc->base_add_sg_single(psge, sgl_flags | (blk_rq_bytes(req) - 4),
  1724. dma_addr_out);
  1725. /* incr sgel */
  1726. psge += ioc->sge_size;
  1727. /* READ sgel last */
  1728. sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT |
  1729. MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER |
  1730. MPI2_SGE_FLAGS_END_OF_LIST);
  1731. sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
  1732. dma_addr_in = pci_map_single(ioc->pdev, bio_data(rsp->bio),
  1733. blk_rq_bytes(rsp), PCI_DMA_BIDIRECTIONAL);
  1734. if (!dma_addr_in) {
  1735. mpt2sas_base_free_smid(ioc, smid);
  1736. goto unmap;
  1737. }
  1738. ioc->base_add_sg_single(psge, sgl_flags | (blk_rq_bytes(rsp) + 4),
  1739. dma_addr_in);
  1740. dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT "%s - "
  1741. "sending smp request\n", ioc->name, __func__));
  1742. mpt2sas_base_put_smid_default(ioc, smid);
  1743. init_completion(&ioc->transport_cmds.done);
  1744. timeleft = wait_for_completion_timeout(&ioc->transport_cmds.done,
  1745. 10*HZ);
  1746. if (!(ioc->transport_cmds.status & MPT2_CMD_COMPLETE)) {
  1747. printk(MPT2SAS_ERR_FMT "%s : timeout\n",
  1748. __func__, ioc->name);
  1749. _debug_dump_mf(mpi_request,
  1750. sizeof(Mpi2SmpPassthroughRequest_t)/4);
  1751. if (!(ioc->transport_cmds.status & MPT2_CMD_RESET))
  1752. issue_reset = 1;
  1753. goto issue_host_reset;
  1754. }
  1755. dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT "%s - "
  1756. "complete\n", ioc->name, __func__));
  1757. if (ioc->transport_cmds.status & MPT2_CMD_REPLY_VALID) {
  1758. mpi_reply = ioc->transport_cmds.reply;
  1759. dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT
  1760. "%s - reply data transfer size(%d)\n",
  1761. ioc->name, __func__,
  1762. le16_to_cpu(mpi_reply->ResponseDataLength)));
  1763. memcpy(req->sense, mpi_reply, sizeof(*mpi_reply));
  1764. req->sense_len = sizeof(*mpi_reply);
  1765. req->resid_len = 0;
  1766. rsp->resid_len -=
  1767. le16_to_cpu(mpi_reply->ResponseDataLength);
  1768. } else {
  1769. dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT
  1770. "%s - no reply\n", ioc->name, __func__));
  1771. rc = -ENXIO;
  1772. }
  1773. issue_host_reset:
  1774. if (issue_reset) {
  1775. mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
  1776. FORCE_BIG_HAMMER);
  1777. rc = -ETIMEDOUT;
  1778. }
  1779. unmap:
  1780. if (dma_addr_out)
  1781. pci_unmap_single(ioc->pdev, dma_addr_out, blk_rq_bytes(req),
  1782. PCI_DMA_BIDIRECTIONAL);
  1783. if (dma_addr_in)
  1784. pci_unmap_single(ioc->pdev, dma_addr_in, blk_rq_bytes(rsp),
  1785. PCI_DMA_BIDIRECTIONAL);
  1786. out:
  1787. ioc->transport_cmds.status = MPT2_CMD_NOT_USED;
  1788. mutex_unlock(&ioc->transport_cmds.mutex);
  1789. return rc;
  1790. }
  1791. struct sas_function_template mpt2sas_transport_functions = {
  1792. .get_linkerrors = _transport_get_linkerrors,
  1793. .get_enclosure_identifier = _transport_get_enclosure_identifier,
  1794. .get_bay_identifier = _transport_get_bay_identifier,
  1795. .phy_reset = _transport_phy_reset,
  1796. .phy_enable = _transport_phy_enable,
  1797. .set_phy_speed = _transport_phy_speed,
  1798. .smp_handler = _transport_smp_handler,
  1799. };
  1800. struct scsi_transport_template *mpt2sas_transport_template;