port.c 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754
  1. /*
  2. * This file is provided under a dual BSD/GPLv2 license. When using or
  3. * redistributing this file, you may do so under either license.
  4. *
  5. * GPL LICENSE SUMMARY
  6. *
  7. * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of version 2 of the GNU General Public License as
  11. * published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  21. * The full GNU General Public License is included in this distribution
  22. * in the file called LICENSE.GPL.
  23. *
  24. * BSD LICENSE
  25. *
  26. * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
  27. * All rights reserved.
  28. *
  29. * Redistribution and use in source and binary forms, with or without
  30. * modification, are permitted provided that the following conditions
  31. * are met:
  32. *
  33. * * Redistributions of source code must retain the above copyright
  34. * notice, this list of conditions and the following disclaimer.
  35. * * Redistributions in binary form must reproduce the above copyright
  36. * notice, this list of conditions and the following disclaimer in
  37. * the documentation and/or other materials provided with the
  38. * distribution.
  39. * * Neither the name of Intel Corporation nor the names of its
  40. * contributors may be used to endorse or promote products derived
  41. * from this software without specific prior written permission.
  42. *
  43. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  44. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  45. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  46. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  47. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  48. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  49. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  50. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  51. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  52. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  53. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  54. */
  55. #include "isci.h"
  56. #include "port.h"
  57. #include "request.h"
  58. #define SCIC_SDS_PORT_HARD_RESET_TIMEOUT (1000)
  59. #define SCU_DUMMY_INDEX (0xFFFF)
  60. static struct device *sciport_to_dev(struct isci_port *iport)
  61. {
  62. int i = iport->physical_port_index;
  63. struct isci_port *table;
  64. struct isci_host *ihost;
  65. if (i == SCIC_SDS_DUMMY_PORT)
  66. i = SCI_MAX_PORTS+1;
  67. table = iport - i;
  68. ihost = container_of(table, typeof(*ihost), ports[0]);
  69. return &ihost->pdev->dev;
  70. }
  71. static void sci_port_get_protocols(struct isci_port *iport, struct sci_phy_proto *proto)
  72. {
  73. u8 index;
  74. proto->all = 0;
  75. for (index = 0; index < SCI_MAX_PHYS; index++) {
  76. struct isci_phy *iphy = iport->phy_table[index];
  77. if (!iphy)
  78. continue;
  79. sci_phy_get_protocols(iphy, proto);
  80. }
  81. }
  82. static u32 sci_port_get_phys(struct isci_port *iport)
  83. {
  84. u32 index;
  85. u32 mask;
  86. mask = 0;
  87. for (index = 0; index < SCI_MAX_PHYS; index++)
  88. if (iport->phy_table[index])
  89. mask |= (1 << index);
  90. return mask;
  91. }
  92. /**
  93. * sci_port_get_properties() - This method simply returns the properties
  94. * regarding the port, such as: physical index, protocols, sas address, etc.
  95. * @port: this parameter specifies the port for which to retrieve the physical
  96. * index.
  97. * @properties: This parameter specifies the properties structure into which to
  98. * copy the requested information.
  99. *
  100. * Indicate if the user specified a valid port. SCI_SUCCESS This value is
  101. * returned if the specified port was valid. SCI_FAILURE_INVALID_PORT This
  102. * value is returned if the specified port is not valid. When this value is
  103. * returned, no data is copied to the properties output parameter.
  104. */
  105. enum sci_status sci_port_get_properties(struct isci_port *iport,
  106. struct sci_port_properties *prop)
  107. {
  108. if (!iport || iport->logical_port_index == SCIC_SDS_DUMMY_PORT)
  109. return SCI_FAILURE_INVALID_PORT;
  110. prop->index = iport->logical_port_index;
  111. prop->phy_mask = sci_port_get_phys(iport);
  112. sci_port_get_sas_address(iport, &prop->local.sas_address);
  113. sci_port_get_protocols(iport, &prop->local.protocols);
  114. sci_port_get_attached_sas_address(iport, &prop->remote.sas_address);
  115. return SCI_SUCCESS;
  116. }
  117. static void sci_port_bcn_enable(struct isci_port *iport)
  118. {
  119. struct isci_phy *iphy;
  120. u32 val;
  121. int i;
  122. for (i = 0; i < ARRAY_SIZE(iport->phy_table); i++) {
  123. iphy = iport->phy_table[i];
  124. if (!iphy)
  125. continue;
  126. val = readl(&iphy->link_layer_registers->link_layer_control);
  127. /* clear the bit by writing 1. */
  128. writel(val, &iphy->link_layer_registers->link_layer_control);
  129. }
  130. }
  131. static void isci_port_bc_change_received(struct isci_host *ihost,
  132. struct isci_port *iport,
  133. struct isci_phy *iphy)
  134. {
  135. dev_dbg(&ihost->pdev->dev,
  136. "%s: isci_phy = %p, sas_phy = %p\n",
  137. __func__, iphy, &iphy->sas_phy);
  138. ihost->sas_ha.notify_port_event(&iphy->sas_phy, PORTE_BROADCAST_RCVD);
  139. sci_port_bcn_enable(iport);
  140. }
  141. static void isci_port_link_up(struct isci_host *isci_host,
  142. struct isci_port *iport,
  143. struct isci_phy *iphy)
  144. {
  145. unsigned long flags;
  146. struct sci_port_properties properties;
  147. unsigned long success = true;
  148. dev_dbg(&isci_host->pdev->dev,
  149. "%s: isci_port = %p\n",
  150. __func__, iport);
  151. spin_lock_irqsave(&iphy->sas_phy.frame_rcvd_lock, flags);
  152. sci_port_get_properties(iport, &properties);
  153. if (iphy->protocol == SCIC_SDS_PHY_PROTOCOL_SATA) {
  154. u64 attached_sas_address;
  155. iphy->sas_phy.oob_mode = SATA_OOB_MODE;
  156. iphy->sas_phy.frame_rcvd_size = sizeof(struct dev_to_host_fis);
  157. /*
  158. * For direct-attached SATA devices, the SCI core will
  159. * automagically assign a SAS address to the end device
  160. * for the purpose of creating a port. This SAS address
  161. * will not be the same as assigned to the PHY and needs
  162. * to be obtained from struct sci_port_properties properties.
  163. */
  164. attached_sas_address = properties.remote.sas_address.high;
  165. attached_sas_address <<= 32;
  166. attached_sas_address |= properties.remote.sas_address.low;
  167. swab64s(&attached_sas_address);
  168. memcpy(&iphy->sas_phy.attached_sas_addr,
  169. &attached_sas_address, sizeof(attached_sas_address));
  170. } else if (iphy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) {
  171. iphy->sas_phy.oob_mode = SAS_OOB_MODE;
  172. iphy->sas_phy.frame_rcvd_size = sizeof(struct sas_identify_frame);
  173. /* Copy the attached SAS address from the IAF */
  174. memcpy(iphy->sas_phy.attached_sas_addr,
  175. iphy->frame_rcvd.iaf.sas_addr, SAS_ADDR_SIZE);
  176. } else {
  177. dev_err(&isci_host->pdev->dev, "%s: unkown target\n", __func__);
  178. success = false;
  179. }
  180. iphy->sas_phy.phy->negotiated_linkrate = sci_phy_linkrate(iphy);
  181. spin_unlock_irqrestore(&iphy->sas_phy.frame_rcvd_lock, flags);
  182. /* Notify libsas that we have an address frame, if indeed
  183. * we've found an SSP, SMP, or STP target */
  184. if (success)
  185. isci_host->sas_ha.notify_port_event(&iphy->sas_phy,
  186. PORTE_BYTES_DMAED);
  187. }
  188. /**
  189. * isci_port_link_down() - This function is called by the sci core when a link
  190. * becomes inactive.
  191. * @isci_host: This parameter specifies the isci host object.
  192. * @phy: This parameter specifies the isci phy with the active link.
  193. * @port: This parameter specifies the isci port with the active link.
  194. *
  195. */
  196. static void isci_port_link_down(struct isci_host *isci_host,
  197. struct isci_phy *isci_phy,
  198. struct isci_port *isci_port)
  199. {
  200. struct isci_remote_device *isci_device;
  201. dev_dbg(&isci_host->pdev->dev,
  202. "%s: isci_port = %p\n", __func__, isci_port);
  203. if (isci_port) {
  204. /* check to see if this is the last phy on this port. */
  205. if (isci_phy->sas_phy.port &&
  206. isci_phy->sas_phy.port->num_phys == 1) {
  207. /* change the state for all devices on this port. The
  208. * next task sent to this device will be returned as
  209. * SAS_TASK_UNDELIVERED, and the scsi mid layer will
  210. * remove the target
  211. */
  212. list_for_each_entry(isci_device,
  213. &isci_port->remote_dev_list,
  214. node) {
  215. dev_dbg(&isci_host->pdev->dev,
  216. "%s: isci_device = %p\n",
  217. __func__, isci_device);
  218. set_bit(IDEV_GONE, &isci_device->flags);
  219. }
  220. }
  221. }
  222. /* Notify libsas of the borken link, this will trigger calls to our
  223. * isci_port_deformed and isci_dev_gone functions.
  224. */
  225. sas_phy_disconnected(&isci_phy->sas_phy);
  226. isci_host->sas_ha.notify_phy_event(&isci_phy->sas_phy,
  227. PHYE_LOSS_OF_SIGNAL);
  228. dev_dbg(&isci_host->pdev->dev,
  229. "%s: isci_port = %p - Done\n", __func__, isci_port);
  230. }
  231. static bool is_port_ready_state(enum sci_port_states state)
  232. {
  233. switch (state) {
  234. case SCI_PORT_READY:
  235. case SCI_PORT_SUB_WAITING:
  236. case SCI_PORT_SUB_OPERATIONAL:
  237. case SCI_PORT_SUB_CONFIGURING:
  238. return true;
  239. default:
  240. return false;
  241. }
  242. }
  243. /* flag dummy rnc hanling when exiting a ready state */
  244. static void port_state_machine_change(struct isci_port *iport,
  245. enum sci_port_states state)
  246. {
  247. struct sci_base_state_machine *sm = &iport->sm;
  248. enum sci_port_states old_state = sm->current_state_id;
  249. if (is_port_ready_state(old_state) && !is_port_ready_state(state))
  250. iport->ready_exit = true;
  251. sci_change_state(sm, state);
  252. iport->ready_exit = false;
  253. }
  254. /**
  255. * isci_port_hard_reset_complete() - This function is called by the sci core
  256. * when the hard reset complete notification has been received.
  257. * @port: This parameter specifies the sci port with the active link.
  258. * @completion_status: This parameter specifies the core status for the reset
  259. * process.
  260. *
  261. */
  262. static void isci_port_hard_reset_complete(struct isci_port *isci_port,
  263. enum sci_status completion_status)
  264. {
  265. struct isci_host *ihost = isci_port->owning_controller;
  266. dev_dbg(&ihost->pdev->dev,
  267. "%s: isci_port = %p, completion_status=%x\n",
  268. __func__, isci_port, completion_status);
  269. /* Save the status of the hard reset from the port. */
  270. isci_port->hard_reset_status = completion_status;
  271. if (completion_status != SCI_SUCCESS) {
  272. /* The reset failed. The port state is now SCI_PORT_FAILED. */
  273. if (isci_port->active_phy_mask == 0) {
  274. int phy_idx = isci_port->last_active_phy;
  275. struct isci_phy *iphy = &ihost->phys[phy_idx];
  276. /* Generate the link down now to the host, since it
  277. * was intercepted by the hard reset state machine when
  278. * it really happened.
  279. */
  280. isci_port_link_down(ihost, iphy, isci_port);
  281. }
  282. /* Advance the port state so that link state changes will be
  283. * noticed.
  284. */
  285. port_state_machine_change(isci_port, SCI_PORT_SUB_WAITING);
  286. }
  287. clear_bit(IPORT_RESET_PENDING, &isci_port->state);
  288. wake_up(&ihost->eventq);
  289. }
  290. /* This method will return a true value if the specified phy can be assigned to
  291. * this port The following is a list of phys for each port that are allowed: -
  292. * Port 0 - 3 2 1 0 - Port 1 - 1 - Port 2 - 3 2 - Port 3 - 3 This method
  293. * doesn't preclude all configurations. It merely ensures that a phy is part
  294. * of the allowable set of phy identifiers for that port. For example, one
  295. * could assign phy 3 to port 0 and no other phys. Please refer to
  296. * sci_port_is_phy_mask_valid() for information regarding whether the
  297. * phy_mask for a port can be supported. bool true if this is a valid phy
  298. * assignment for the port false if this is not a valid phy assignment for the
  299. * port
  300. */
  301. bool sci_port_is_valid_phy_assignment(struct isci_port *iport, u32 phy_index)
  302. {
  303. struct isci_host *ihost = iport->owning_controller;
  304. struct sci_user_parameters *user = &ihost->user_parameters;
  305. /* Initialize to invalid value. */
  306. u32 existing_phy_index = SCI_MAX_PHYS;
  307. u32 index;
  308. if ((iport->physical_port_index == 1) && (phy_index != 1))
  309. return false;
  310. if (iport->physical_port_index == 3 && phy_index != 3)
  311. return false;
  312. if (iport->physical_port_index == 2 &&
  313. (phy_index == 0 || phy_index == 1))
  314. return false;
  315. for (index = 0; index < SCI_MAX_PHYS; index++)
  316. if (iport->phy_table[index] && index != phy_index)
  317. existing_phy_index = index;
  318. /* Ensure that all of the phys in the port are capable of
  319. * operating at the same maximum link rate.
  320. */
  321. if (existing_phy_index < SCI_MAX_PHYS &&
  322. user->phys[phy_index].max_speed_generation !=
  323. user->phys[existing_phy_index].max_speed_generation)
  324. return false;
  325. return true;
  326. }
  327. /**
  328. *
  329. * @sci_port: This is the port object for which to determine if the phy mask
  330. * can be supported.
  331. *
  332. * This method will return a true value if the port's phy mask can be supported
  333. * by the SCU. The following is a list of valid PHY mask configurations for
  334. * each port: - Port 0 - [[3 2] 1] 0 - Port 1 - [1] - Port 2 - [[3] 2]
  335. * - Port 3 - [3] This method returns a boolean indication specifying if the
  336. * phy mask can be supported. true if this is a valid phy assignment for the
  337. * port false if this is not a valid phy assignment for the port
  338. */
  339. static bool sci_port_is_phy_mask_valid(
  340. struct isci_port *iport,
  341. u32 phy_mask)
  342. {
  343. if (iport->physical_port_index == 0) {
  344. if (((phy_mask & 0x0F) == 0x0F)
  345. || ((phy_mask & 0x03) == 0x03)
  346. || ((phy_mask & 0x01) == 0x01)
  347. || (phy_mask == 0))
  348. return true;
  349. } else if (iport->physical_port_index == 1) {
  350. if (((phy_mask & 0x02) == 0x02)
  351. || (phy_mask == 0))
  352. return true;
  353. } else if (iport->physical_port_index == 2) {
  354. if (((phy_mask & 0x0C) == 0x0C)
  355. || ((phy_mask & 0x04) == 0x04)
  356. || (phy_mask == 0))
  357. return true;
  358. } else if (iport->physical_port_index == 3) {
  359. if (((phy_mask & 0x08) == 0x08)
  360. || (phy_mask == 0))
  361. return true;
  362. }
  363. return false;
  364. }
  365. /*
  366. * This method retrieves a currently active (i.e. connected) phy contained in
  367. * the port. Currently, the lowest order phy that is connected is returned.
  368. * This method returns a pointer to a SCIS_SDS_PHY object. NULL This value is
  369. * returned if there are no currently active (i.e. connected to a remote end
  370. * point) phys contained in the port. All other values specify a struct sci_phy
  371. * object that is active in the port.
  372. */
  373. static struct isci_phy *sci_port_get_a_connected_phy(struct isci_port *iport)
  374. {
  375. u32 index;
  376. struct isci_phy *iphy;
  377. for (index = 0; index < SCI_MAX_PHYS; index++) {
  378. /* Ensure that the phy is both part of the port and currently
  379. * connected to the remote end-point.
  380. */
  381. iphy = iport->phy_table[index];
  382. if (iphy && sci_port_active_phy(iport, iphy))
  383. return iphy;
  384. }
  385. return NULL;
  386. }
  387. static enum sci_status sci_port_set_phy(struct isci_port *iport, struct isci_phy *iphy)
  388. {
  389. /* Check to see if we can add this phy to a port
  390. * that means that the phy is not part of a port and that the port does
  391. * not already have a phy assinged to the phy index.
  392. */
  393. if (!iport->phy_table[iphy->phy_index] &&
  394. !phy_get_non_dummy_port(iphy) &&
  395. sci_port_is_valid_phy_assignment(iport, iphy->phy_index)) {
  396. /* Phy is being added in the stopped state so we are in MPC mode
  397. * make logical port index = physical port index
  398. */
  399. iport->logical_port_index = iport->physical_port_index;
  400. iport->phy_table[iphy->phy_index] = iphy;
  401. sci_phy_set_port(iphy, iport);
  402. return SCI_SUCCESS;
  403. }
  404. return SCI_FAILURE;
  405. }
  406. static enum sci_status sci_port_clear_phy(struct isci_port *iport, struct isci_phy *iphy)
  407. {
  408. /* Make sure that this phy is part of this port */
  409. if (iport->phy_table[iphy->phy_index] == iphy &&
  410. phy_get_non_dummy_port(iphy) == iport) {
  411. struct isci_host *ihost = iport->owning_controller;
  412. /* Yep it is assigned to this port so remove it */
  413. sci_phy_set_port(iphy, &ihost->ports[SCI_MAX_PORTS]);
  414. iport->phy_table[iphy->phy_index] = NULL;
  415. return SCI_SUCCESS;
  416. }
  417. return SCI_FAILURE;
  418. }
  419. void sci_port_get_sas_address(struct isci_port *iport, struct sci_sas_address *sas)
  420. {
  421. u32 index;
  422. sas->high = 0;
  423. sas->low = 0;
  424. for (index = 0; index < SCI_MAX_PHYS; index++)
  425. if (iport->phy_table[index])
  426. sci_phy_get_sas_address(iport->phy_table[index], sas);
  427. }
  428. void sci_port_get_attached_sas_address(struct isci_port *iport, struct sci_sas_address *sas)
  429. {
  430. struct isci_phy *iphy;
  431. /*
  432. * Ensure that the phy is both part of the port and currently
  433. * connected to the remote end-point.
  434. */
  435. iphy = sci_port_get_a_connected_phy(iport);
  436. if (iphy) {
  437. if (iphy->protocol != SCIC_SDS_PHY_PROTOCOL_SATA) {
  438. sci_phy_get_attached_sas_address(iphy, sas);
  439. } else {
  440. sci_phy_get_sas_address(iphy, sas);
  441. sas->low += iphy->phy_index;
  442. }
  443. } else {
  444. sas->high = 0;
  445. sas->low = 0;
  446. }
  447. }
  448. /**
  449. * sci_port_construct_dummy_rnc() - create dummy rnc for si workaround
  450. *
  451. * @sci_port: logical port on which we need to create the remote node context
  452. * @rni: remote node index for this remote node context.
  453. *
  454. * This routine will construct a dummy remote node context data structure
  455. * This structure will be posted to the hardware to work around a scheduler
  456. * error in the hardware.
  457. */
  458. static void sci_port_construct_dummy_rnc(struct isci_port *iport, u16 rni)
  459. {
  460. union scu_remote_node_context *rnc;
  461. rnc = &iport->owning_controller->remote_node_context_table[rni];
  462. memset(rnc, 0, sizeof(union scu_remote_node_context));
  463. rnc->ssp.remote_sas_address_hi = 0;
  464. rnc->ssp.remote_sas_address_lo = 0;
  465. rnc->ssp.remote_node_index = rni;
  466. rnc->ssp.remote_node_port_width = 1;
  467. rnc->ssp.logical_port_index = iport->physical_port_index;
  468. rnc->ssp.nexus_loss_timer_enable = false;
  469. rnc->ssp.check_bit = false;
  470. rnc->ssp.is_valid = true;
  471. rnc->ssp.is_remote_node_context = true;
  472. rnc->ssp.function_number = 0;
  473. rnc->ssp.arbitration_wait_time = 0;
  474. }
  475. /*
  476. * construct a dummy task context data structure. This
  477. * structure will be posted to the hardwre to work around a scheduler error
  478. * in the hardware.
  479. */
  480. static void sci_port_construct_dummy_task(struct isci_port *iport, u16 tag)
  481. {
  482. struct isci_host *ihost = iport->owning_controller;
  483. struct scu_task_context *task_context;
  484. task_context = &ihost->task_context_table[ISCI_TAG_TCI(tag)];
  485. memset(task_context, 0, sizeof(struct scu_task_context));
  486. task_context->initiator_request = 1;
  487. task_context->connection_rate = 1;
  488. task_context->logical_port_index = iport->physical_port_index;
  489. task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_SSP;
  490. task_context->task_index = ISCI_TAG_TCI(tag);
  491. task_context->valid = SCU_TASK_CONTEXT_VALID;
  492. task_context->context_type = SCU_TASK_CONTEXT_TYPE;
  493. task_context->remote_node_index = iport->reserved_rni;
  494. task_context->do_not_dma_ssp_good_response = 1;
  495. task_context->task_phase = 0x01;
  496. }
  497. static void sci_port_destroy_dummy_resources(struct isci_port *iport)
  498. {
  499. struct isci_host *ihost = iport->owning_controller;
  500. if (iport->reserved_tag != SCI_CONTROLLER_INVALID_IO_TAG)
  501. isci_free_tag(ihost, iport->reserved_tag);
  502. if (iport->reserved_rni != SCU_DUMMY_INDEX)
  503. sci_remote_node_table_release_remote_node_index(&ihost->available_remote_nodes,
  504. 1, iport->reserved_rni);
  505. iport->reserved_rni = SCU_DUMMY_INDEX;
  506. iport->reserved_tag = SCI_CONTROLLER_INVALID_IO_TAG;
  507. }
  508. void sci_port_setup_transports(struct isci_port *iport, u32 device_id)
  509. {
  510. u8 index;
  511. for (index = 0; index < SCI_MAX_PHYS; index++) {
  512. if (iport->active_phy_mask & (1 << index))
  513. sci_phy_setup_transport(iport->phy_table[index], device_id);
  514. }
  515. }
  516. static void sci_port_resume_phy(struct isci_port *iport, struct isci_phy *iphy)
  517. {
  518. sci_phy_resume(iphy);
  519. iport->enabled_phy_mask |= 1 << iphy->phy_index;
  520. }
  521. static void sci_port_activate_phy(struct isci_port *iport,
  522. struct isci_phy *iphy,
  523. u8 flags)
  524. {
  525. struct isci_host *ihost = iport->owning_controller;
  526. if (iphy->protocol != SCIC_SDS_PHY_PROTOCOL_SATA && (flags & PF_RESUME))
  527. sci_phy_resume(iphy);
  528. iport->active_phy_mask |= 1 << iphy->phy_index;
  529. sci_controller_clear_invalid_phy(ihost, iphy);
  530. if (flags & PF_NOTIFY)
  531. isci_port_link_up(ihost, iport, iphy);
  532. }
  533. void sci_port_deactivate_phy(struct isci_port *iport, struct isci_phy *iphy,
  534. bool do_notify_user)
  535. {
  536. struct isci_host *ihost = iport->owning_controller;
  537. iport->active_phy_mask &= ~(1 << iphy->phy_index);
  538. iport->enabled_phy_mask &= ~(1 << iphy->phy_index);
  539. if (!iport->active_phy_mask)
  540. iport->last_active_phy = iphy->phy_index;
  541. iphy->max_negotiated_speed = SAS_LINK_RATE_UNKNOWN;
  542. /* Re-assign the phy back to the LP as if it were a narrow port for APC
  543. * mode. For MPC mode, the phy will remain in the port.
  544. */
  545. if (iport->owning_controller->oem_parameters.controller.mode_type ==
  546. SCIC_PORT_AUTOMATIC_CONFIGURATION_MODE)
  547. writel(iphy->phy_index,
  548. &iport->port_pe_configuration_register[iphy->phy_index]);
  549. if (do_notify_user == true)
  550. isci_port_link_down(ihost, iphy, iport);
  551. }
  552. static void sci_port_invalid_link_up(struct isci_port *iport, struct isci_phy *iphy)
  553. {
  554. struct isci_host *ihost = iport->owning_controller;
  555. /*
  556. * Check to see if we have alreay reported this link as bad and if
  557. * not go ahead and tell the SCI_USER that we have discovered an
  558. * invalid link.
  559. */
  560. if ((ihost->invalid_phy_mask & (1 << iphy->phy_index)) == 0) {
  561. ihost->invalid_phy_mask |= 1 << iphy->phy_index;
  562. dev_warn(&ihost->pdev->dev, "Invalid link up!\n");
  563. }
  564. }
  565. /**
  566. * sci_port_general_link_up_handler - phy can be assigned to port?
  567. * @sci_port: sci_port object for which has a phy that has gone link up.
  568. * @sci_phy: This is the struct isci_phy object that has gone link up.
  569. * @flags: PF_RESUME, PF_NOTIFY to sci_port_activate_phy
  570. *
  571. * Determine if this phy can be assigned to this port . If the phy is
  572. * not a valid PHY for this port then the function will notify the user.
  573. * A PHY can only be part of a port if it's attached SAS ADDRESS is the
  574. * same as all other PHYs in the same port.
  575. */
  576. static void sci_port_general_link_up_handler(struct isci_port *iport,
  577. struct isci_phy *iphy,
  578. u8 flags)
  579. {
  580. struct sci_sas_address port_sas_address;
  581. struct sci_sas_address phy_sas_address;
  582. sci_port_get_attached_sas_address(iport, &port_sas_address);
  583. sci_phy_get_attached_sas_address(iphy, &phy_sas_address);
  584. /* If the SAS address of the new phy matches the SAS address of
  585. * other phys in the port OR this is the first phy in the port,
  586. * then activate the phy and allow it to be used for operations
  587. * in this port.
  588. */
  589. if ((phy_sas_address.high == port_sas_address.high &&
  590. phy_sas_address.low == port_sas_address.low) ||
  591. iport->active_phy_mask == 0) {
  592. struct sci_base_state_machine *sm = &iport->sm;
  593. sci_port_activate_phy(iport, iphy, flags);
  594. if (sm->current_state_id == SCI_PORT_RESETTING)
  595. port_state_machine_change(iport, SCI_PORT_READY);
  596. } else
  597. sci_port_invalid_link_up(iport, iphy);
  598. }
  599. /**
  600. * This method returns false if the port only has a single phy object assigned.
  601. * If there are no phys or more than one phy then the method will return
  602. * true.
  603. * @sci_port: The port for which the wide port condition is to be checked.
  604. *
  605. * bool true Is returned if this is a wide ported port. false Is returned if
  606. * this is a narrow port.
  607. */
  608. static bool sci_port_is_wide(struct isci_port *iport)
  609. {
  610. u32 index;
  611. u32 phy_count = 0;
  612. for (index = 0; index < SCI_MAX_PHYS; index++) {
  613. if (iport->phy_table[index] != NULL) {
  614. phy_count++;
  615. }
  616. }
  617. return phy_count != 1;
  618. }
  619. /**
  620. * This method is called by the PHY object when the link is detected. if the
  621. * port wants the PHY to continue on to the link up state then the port
  622. * layer must return true. If the port object returns false the phy object
  623. * must halt its attempt to go link up.
  624. * @sci_port: The port associated with the phy object.
  625. * @sci_phy: The phy object that is trying to go link up.
  626. *
  627. * true if the phy object can continue to the link up condition. true Is
  628. * returned if this phy can continue to the ready state. false Is returned if
  629. * can not continue on to the ready state. This notification is in place for
  630. * wide ports and direct attached phys. Since there are no wide ported SATA
  631. * devices this could become an invalid port configuration.
  632. */
  633. bool sci_port_link_detected(
  634. struct isci_port *iport,
  635. struct isci_phy *iphy)
  636. {
  637. if ((iport->logical_port_index != SCIC_SDS_DUMMY_PORT) &&
  638. (iphy->protocol == SCIC_SDS_PHY_PROTOCOL_SATA)) {
  639. if (sci_port_is_wide(iport)) {
  640. sci_port_invalid_link_up(iport, iphy);
  641. return false;
  642. } else {
  643. struct isci_host *ihost = iport->owning_controller;
  644. struct isci_port *dst_port = &(ihost->ports[iphy->phy_index]);
  645. writel(iphy->phy_index,
  646. &dst_port->port_pe_configuration_register[iphy->phy_index]);
  647. }
  648. }
  649. return true;
  650. }
  651. static void port_timeout(unsigned long data)
  652. {
  653. struct sci_timer *tmr = (struct sci_timer *)data;
  654. struct isci_port *iport = container_of(tmr, typeof(*iport), timer);
  655. struct isci_host *ihost = iport->owning_controller;
  656. unsigned long flags;
  657. u32 current_state;
  658. spin_lock_irqsave(&ihost->scic_lock, flags);
  659. if (tmr->cancel)
  660. goto done;
  661. current_state = iport->sm.current_state_id;
  662. if (current_state == SCI_PORT_RESETTING) {
  663. /* if the port is still in the resetting state then the timeout
  664. * fired before the reset completed.
  665. */
  666. port_state_machine_change(iport, SCI_PORT_FAILED);
  667. } else if (current_state == SCI_PORT_STOPPED) {
  668. /* if the port is stopped then the start request failed In this
  669. * case stay in the stopped state.
  670. */
  671. dev_err(sciport_to_dev(iport),
  672. "%s: SCIC Port 0x%p failed to stop before tiemout.\n",
  673. __func__,
  674. iport);
  675. } else if (current_state == SCI_PORT_STOPPING) {
  676. dev_dbg(sciport_to_dev(iport),
  677. "%s: port%d: stop complete timeout\n",
  678. __func__, iport->physical_port_index);
  679. } else {
  680. /* The port is in the ready state and we have a timer
  681. * reporting a timeout this should not happen.
  682. */
  683. dev_err(sciport_to_dev(iport),
  684. "%s: SCIC Port 0x%p is processing a timeout operation "
  685. "in state %d.\n", __func__, iport, current_state);
  686. }
  687. done:
  688. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  689. }
  690. /* --------------------------------------------------------------------------- */
  691. /**
  692. * This function updates the hardwares VIIT entry for this port.
  693. *
  694. *
  695. */
  696. static void sci_port_update_viit_entry(struct isci_port *iport)
  697. {
  698. struct sci_sas_address sas_address;
  699. sci_port_get_sas_address(iport, &sas_address);
  700. writel(sas_address.high,
  701. &iport->viit_registers->initiator_sas_address_hi);
  702. writel(sas_address.low,
  703. &iport->viit_registers->initiator_sas_address_lo);
  704. /* This value get cleared just in case its not already cleared */
  705. writel(0, &iport->viit_registers->reserved);
  706. /* We are required to update the status register last */
  707. writel(SCU_VIIT_ENTRY_ID_VIIT |
  708. SCU_VIIT_IPPT_INITIATOR |
  709. ((1 << iport->physical_port_index) << SCU_VIIT_ENTRY_LPVIE_SHIFT) |
  710. SCU_VIIT_STATUS_ALL_VALID,
  711. &iport->viit_registers->status);
  712. }
  713. enum sas_linkrate sci_port_get_max_allowed_speed(struct isci_port *iport)
  714. {
  715. u16 index;
  716. struct isci_phy *iphy;
  717. enum sas_linkrate max_allowed_speed = SAS_LINK_RATE_6_0_GBPS;
  718. /*
  719. * Loop through all of the phys in this port and find the phy with the
  720. * lowest maximum link rate. */
  721. for (index = 0; index < SCI_MAX_PHYS; index++) {
  722. iphy = iport->phy_table[index];
  723. if (iphy && sci_port_active_phy(iport, iphy) &&
  724. iphy->max_negotiated_speed < max_allowed_speed)
  725. max_allowed_speed = iphy->max_negotiated_speed;
  726. }
  727. return max_allowed_speed;
  728. }
  729. static void sci_port_suspend_port_task_scheduler(struct isci_port *iport)
  730. {
  731. u32 pts_control_value;
  732. pts_control_value = readl(&iport->port_task_scheduler_registers->control);
  733. pts_control_value |= SCU_PTSxCR_GEN_BIT(SUSPEND);
  734. writel(pts_control_value, &iport->port_task_scheduler_registers->control);
  735. }
  736. /**
  737. * sci_port_post_dummy_request() - post dummy/workaround request
  738. * @sci_port: port to post task
  739. *
  740. * Prevent the hardware scheduler from posting new requests to the front
  741. * of the scheduler queue causing a starvation problem for currently
  742. * ongoing requests.
  743. *
  744. */
  745. static void sci_port_post_dummy_request(struct isci_port *iport)
  746. {
  747. struct isci_host *ihost = iport->owning_controller;
  748. u16 tag = iport->reserved_tag;
  749. struct scu_task_context *tc;
  750. u32 command;
  751. tc = &ihost->task_context_table[ISCI_TAG_TCI(tag)];
  752. tc->abort = 0;
  753. command = SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
  754. iport->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT |
  755. ISCI_TAG_TCI(tag);
  756. sci_controller_post_request(ihost, command);
  757. }
  758. /**
  759. * This routine will abort the dummy request. This will alow the hardware to
  760. * power down parts of the silicon to save power.
  761. *
  762. * @sci_port: The port on which the task must be aborted.
  763. *
  764. */
  765. static void sci_port_abort_dummy_request(struct isci_port *iport)
  766. {
  767. struct isci_host *ihost = iport->owning_controller;
  768. u16 tag = iport->reserved_tag;
  769. struct scu_task_context *tc;
  770. u32 command;
  771. tc = &ihost->task_context_table[ISCI_TAG_TCI(tag)];
  772. tc->abort = 1;
  773. command = SCU_CONTEXT_COMMAND_REQUEST_POST_TC_ABORT |
  774. iport->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT |
  775. ISCI_TAG_TCI(tag);
  776. sci_controller_post_request(ihost, command);
  777. }
  778. /**
  779. *
  780. * @sci_port: This is the struct isci_port object to resume.
  781. *
  782. * This method will resume the port task scheduler for this port object. none
  783. */
  784. static void
  785. sci_port_resume_port_task_scheduler(struct isci_port *iport)
  786. {
  787. u32 pts_control_value;
  788. pts_control_value = readl(&iport->port_task_scheduler_registers->control);
  789. pts_control_value &= ~SCU_PTSxCR_GEN_BIT(SUSPEND);
  790. writel(pts_control_value, &iport->port_task_scheduler_registers->control);
  791. }
  792. static void sci_port_ready_substate_waiting_enter(struct sci_base_state_machine *sm)
  793. {
  794. struct isci_port *iport = container_of(sm, typeof(*iport), sm);
  795. sci_port_suspend_port_task_scheduler(iport);
  796. iport->not_ready_reason = SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS;
  797. if (iport->active_phy_mask != 0) {
  798. /* At least one of the phys on the port is ready */
  799. port_state_machine_change(iport,
  800. SCI_PORT_SUB_OPERATIONAL);
  801. }
  802. }
  803. static void scic_sds_port_ready_substate_waiting_exit(
  804. struct sci_base_state_machine *sm)
  805. {
  806. struct isci_port *iport = container_of(sm, typeof(*iport), sm);
  807. sci_port_resume_port_task_scheduler(iport);
  808. }
  809. static void sci_port_ready_substate_operational_enter(struct sci_base_state_machine *sm)
  810. {
  811. u32 index;
  812. struct isci_port *iport = container_of(sm, typeof(*iport), sm);
  813. struct isci_host *ihost = iport->owning_controller;
  814. dev_dbg(&ihost->pdev->dev, "%s: port%d ready\n",
  815. __func__, iport->physical_port_index);
  816. for (index = 0; index < SCI_MAX_PHYS; index++) {
  817. if (iport->phy_table[index]) {
  818. writel(iport->physical_port_index,
  819. &iport->port_pe_configuration_register[
  820. iport->phy_table[index]->phy_index]);
  821. if (((iport->active_phy_mask^iport->enabled_phy_mask) & (1 << index)) != 0)
  822. sci_port_resume_phy(iport, iport->phy_table[index]);
  823. }
  824. }
  825. sci_port_update_viit_entry(iport);
  826. /*
  827. * Post the dummy task for the port so the hardware can schedule
  828. * io correctly
  829. */
  830. sci_port_post_dummy_request(iport);
  831. }
  832. static void sci_port_invalidate_dummy_remote_node(struct isci_port *iport)
  833. {
  834. struct isci_host *ihost = iport->owning_controller;
  835. u8 phys_index = iport->physical_port_index;
  836. union scu_remote_node_context *rnc;
  837. u16 rni = iport->reserved_rni;
  838. u32 command;
  839. rnc = &ihost->remote_node_context_table[rni];
  840. rnc->ssp.is_valid = false;
  841. /* ensure the preceding tc abort request has reached the
  842. * controller and give it ample time to act before posting the rnc
  843. * invalidate
  844. */
  845. readl(&ihost->smu_registers->interrupt_status); /* flush */
  846. udelay(10);
  847. command = SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE |
  848. phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
  849. sci_controller_post_request(ihost, command);
  850. }
  851. /**
  852. *
  853. * @object: This is the object which is cast to a struct isci_port object.
  854. *
  855. * This method will perform the actions required by the struct isci_port on
  856. * exiting the SCI_PORT_SUB_OPERATIONAL. This function reports
  857. * the port not ready and suspends the port task scheduler. none
  858. */
  859. static void sci_port_ready_substate_operational_exit(struct sci_base_state_machine *sm)
  860. {
  861. struct isci_port *iport = container_of(sm, typeof(*iport), sm);
  862. struct isci_host *ihost = iport->owning_controller;
  863. /*
  864. * Kill the dummy task for this port if it has not yet posted
  865. * the hardware will treat this as a NOP and just return abort
  866. * complete.
  867. */
  868. sci_port_abort_dummy_request(iport);
  869. dev_dbg(&ihost->pdev->dev, "%s: port%d !ready\n",
  870. __func__, iport->physical_port_index);
  871. if (iport->ready_exit)
  872. sci_port_invalidate_dummy_remote_node(iport);
  873. }
  874. static void sci_port_ready_substate_configuring_enter(struct sci_base_state_machine *sm)
  875. {
  876. struct isci_port *iport = container_of(sm, typeof(*iport), sm);
  877. struct isci_host *ihost = iport->owning_controller;
  878. if (iport->active_phy_mask == 0) {
  879. dev_dbg(&ihost->pdev->dev, "%s: port%d !ready\n",
  880. __func__, iport->physical_port_index);
  881. port_state_machine_change(iport, SCI_PORT_SUB_WAITING);
  882. } else
  883. port_state_machine_change(iport, SCI_PORT_SUB_OPERATIONAL);
  884. }
  885. enum sci_status sci_port_start(struct isci_port *iport)
  886. {
  887. struct isci_host *ihost = iport->owning_controller;
  888. enum sci_status status = SCI_SUCCESS;
  889. enum sci_port_states state;
  890. u32 phy_mask;
  891. state = iport->sm.current_state_id;
  892. if (state != SCI_PORT_STOPPED) {
  893. dev_warn(sciport_to_dev(iport),
  894. "%s: in wrong state: %d\n", __func__, state);
  895. return SCI_FAILURE_INVALID_STATE;
  896. }
  897. if (iport->assigned_device_count > 0) {
  898. /* TODO This is a start failure operation because
  899. * there are still devices assigned to this port.
  900. * There must be no devices assigned to a port on a
  901. * start operation.
  902. */
  903. return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
  904. }
  905. if (iport->reserved_rni == SCU_DUMMY_INDEX) {
  906. u16 rni = sci_remote_node_table_allocate_remote_node(
  907. &ihost->available_remote_nodes, 1);
  908. if (rni != SCU_DUMMY_INDEX)
  909. sci_port_construct_dummy_rnc(iport, rni);
  910. else
  911. status = SCI_FAILURE_INSUFFICIENT_RESOURCES;
  912. iport->reserved_rni = rni;
  913. }
  914. if (iport->reserved_tag == SCI_CONTROLLER_INVALID_IO_TAG) {
  915. u16 tag;
  916. tag = isci_alloc_tag(ihost);
  917. if (tag == SCI_CONTROLLER_INVALID_IO_TAG)
  918. status = SCI_FAILURE_INSUFFICIENT_RESOURCES;
  919. else
  920. sci_port_construct_dummy_task(iport, tag);
  921. iport->reserved_tag = tag;
  922. }
  923. if (status == SCI_SUCCESS) {
  924. phy_mask = sci_port_get_phys(iport);
  925. /*
  926. * There are one or more phys assigned to this port. Make sure
  927. * the port's phy mask is in fact legal and supported by the
  928. * silicon.
  929. */
  930. if (sci_port_is_phy_mask_valid(iport, phy_mask) == true) {
  931. port_state_machine_change(iport,
  932. SCI_PORT_READY);
  933. return SCI_SUCCESS;
  934. }
  935. status = SCI_FAILURE;
  936. }
  937. if (status != SCI_SUCCESS)
  938. sci_port_destroy_dummy_resources(iport);
  939. return status;
  940. }
  941. enum sci_status sci_port_stop(struct isci_port *iport)
  942. {
  943. enum sci_port_states state;
  944. state = iport->sm.current_state_id;
  945. switch (state) {
  946. case SCI_PORT_STOPPED:
  947. return SCI_SUCCESS;
  948. case SCI_PORT_SUB_WAITING:
  949. case SCI_PORT_SUB_OPERATIONAL:
  950. case SCI_PORT_SUB_CONFIGURING:
  951. case SCI_PORT_RESETTING:
  952. port_state_machine_change(iport,
  953. SCI_PORT_STOPPING);
  954. return SCI_SUCCESS;
  955. default:
  956. dev_warn(sciport_to_dev(iport),
  957. "%s: in wrong state: %d\n", __func__, state);
  958. return SCI_FAILURE_INVALID_STATE;
  959. }
  960. }
  961. static enum sci_status sci_port_hard_reset(struct isci_port *iport, u32 timeout)
  962. {
  963. enum sci_status status = SCI_FAILURE_INVALID_PHY;
  964. struct isci_phy *iphy = NULL;
  965. enum sci_port_states state;
  966. u32 phy_index;
  967. state = iport->sm.current_state_id;
  968. if (state != SCI_PORT_SUB_OPERATIONAL) {
  969. dev_warn(sciport_to_dev(iport),
  970. "%s: in wrong state: %d\n", __func__, state);
  971. return SCI_FAILURE_INVALID_STATE;
  972. }
  973. /* Select a phy on which we can send the hard reset request. */
  974. for (phy_index = 0; phy_index < SCI_MAX_PHYS && !iphy; phy_index++) {
  975. iphy = iport->phy_table[phy_index];
  976. if (iphy && !sci_port_active_phy(iport, iphy)) {
  977. /*
  978. * We found a phy but it is not ready select
  979. * different phy
  980. */
  981. iphy = NULL;
  982. }
  983. }
  984. /* If we have a phy then go ahead and start the reset procedure */
  985. if (!iphy)
  986. return status;
  987. status = sci_phy_reset(iphy);
  988. if (status != SCI_SUCCESS)
  989. return status;
  990. sci_mod_timer(&iport->timer, timeout);
  991. iport->not_ready_reason = SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED;
  992. port_state_machine_change(iport, SCI_PORT_RESETTING);
  993. return SCI_SUCCESS;
  994. }
  995. /**
  996. * sci_port_add_phy() -
  997. * @sci_port: This parameter specifies the port in which the phy will be added.
  998. * @sci_phy: This parameter is the phy which is to be added to the port.
  999. *
  1000. * This method will add a PHY to the selected port. This method returns an
  1001. * enum sci_status. SCI_SUCCESS the phy has been added to the port. Any other
  1002. * status is a failure to add the phy to the port.
  1003. */
  1004. enum sci_status sci_port_add_phy(struct isci_port *iport,
  1005. struct isci_phy *iphy)
  1006. {
  1007. enum sci_status status;
  1008. enum sci_port_states state;
  1009. state = iport->sm.current_state_id;
  1010. switch (state) {
  1011. case SCI_PORT_STOPPED: {
  1012. struct sci_sas_address port_sas_address;
  1013. /* Read the port assigned SAS Address if there is one */
  1014. sci_port_get_sas_address(iport, &port_sas_address);
  1015. if (port_sas_address.high != 0 && port_sas_address.low != 0) {
  1016. struct sci_sas_address phy_sas_address;
  1017. /* Make sure that the PHY SAS Address matches the SAS Address
  1018. * for this port
  1019. */
  1020. sci_phy_get_sas_address(iphy, &phy_sas_address);
  1021. if (port_sas_address.high != phy_sas_address.high ||
  1022. port_sas_address.low != phy_sas_address.low)
  1023. return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
  1024. }
  1025. return sci_port_set_phy(iport, iphy);
  1026. }
  1027. case SCI_PORT_SUB_WAITING:
  1028. case SCI_PORT_SUB_OPERATIONAL:
  1029. status = sci_port_set_phy(iport, iphy);
  1030. if (status != SCI_SUCCESS)
  1031. return status;
  1032. sci_port_general_link_up_handler(iport, iphy, PF_NOTIFY|PF_RESUME);
  1033. iport->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
  1034. port_state_machine_change(iport, SCI_PORT_SUB_CONFIGURING);
  1035. return status;
  1036. case SCI_PORT_SUB_CONFIGURING:
  1037. status = sci_port_set_phy(iport, iphy);
  1038. if (status != SCI_SUCCESS)
  1039. return status;
  1040. sci_port_general_link_up_handler(iport, iphy, PF_NOTIFY);
  1041. /* Re-enter the configuring state since this may be the last phy in
  1042. * the port.
  1043. */
  1044. port_state_machine_change(iport,
  1045. SCI_PORT_SUB_CONFIGURING);
  1046. return SCI_SUCCESS;
  1047. default:
  1048. dev_warn(sciport_to_dev(iport),
  1049. "%s: in wrong state: %d\n", __func__, state);
  1050. return SCI_FAILURE_INVALID_STATE;
  1051. }
  1052. }
  1053. /**
  1054. * sci_port_remove_phy() -
  1055. * @sci_port: This parameter specifies the port in which the phy will be added.
  1056. * @sci_phy: This parameter is the phy which is to be added to the port.
  1057. *
  1058. * This method will remove the PHY from the selected PORT. This method returns
  1059. * an enum sci_status. SCI_SUCCESS the phy has been removed from the port. Any
  1060. * other status is a failure to add the phy to the port.
  1061. */
  1062. enum sci_status sci_port_remove_phy(struct isci_port *iport,
  1063. struct isci_phy *iphy)
  1064. {
  1065. enum sci_status status;
  1066. enum sci_port_states state;
  1067. state = iport->sm.current_state_id;
  1068. switch (state) {
  1069. case SCI_PORT_STOPPED:
  1070. return sci_port_clear_phy(iport, iphy);
  1071. case SCI_PORT_SUB_OPERATIONAL:
  1072. status = sci_port_clear_phy(iport, iphy);
  1073. if (status != SCI_SUCCESS)
  1074. return status;
  1075. sci_port_deactivate_phy(iport, iphy, true);
  1076. iport->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
  1077. port_state_machine_change(iport,
  1078. SCI_PORT_SUB_CONFIGURING);
  1079. return SCI_SUCCESS;
  1080. case SCI_PORT_SUB_CONFIGURING:
  1081. status = sci_port_clear_phy(iport, iphy);
  1082. if (status != SCI_SUCCESS)
  1083. return status;
  1084. sci_port_deactivate_phy(iport, iphy, true);
  1085. /* Re-enter the configuring state since this may be the last phy in
  1086. * the port
  1087. */
  1088. port_state_machine_change(iport,
  1089. SCI_PORT_SUB_CONFIGURING);
  1090. return SCI_SUCCESS;
  1091. default:
  1092. dev_warn(sciport_to_dev(iport),
  1093. "%s: in wrong state: %d\n", __func__, state);
  1094. return SCI_FAILURE_INVALID_STATE;
  1095. }
  1096. }
  1097. enum sci_status sci_port_link_up(struct isci_port *iport,
  1098. struct isci_phy *iphy)
  1099. {
  1100. enum sci_port_states state;
  1101. state = iport->sm.current_state_id;
  1102. switch (state) {
  1103. case SCI_PORT_SUB_WAITING:
  1104. /* Since this is the first phy going link up for the port we
  1105. * can just enable it and continue
  1106. */
  1107. sci_port_activate_phy(iport, iphy, PF_NOTIFY|PF_RESUME);
  1108. port_state_machine_change(iport,
  1109. SCI_PORT_SUB_OPERATIONAL);
  1110. return SCI_SUCCESS;
  1111. case SCI_PORT_SUB_OPERATIONAL:
  1112. sci_port_general_link_up_handler(iport, iphy, PF_NOTIFY|PF_RESUME);
  1113. return SCI_SUCCESS;
  1114. case SCI_PORT_RESETTING:
  1115. /* TODO We should make sure that the phy that has gone
  1116. * link up is the same one on which we sent the reset. It is
  1117. * possible that the phy on which we sent the reset is not the
  1118. * one that has gone link up and we want to make sure that
  1119. * phy being reset comes back. Consider the case where a
  1120. * reset is sent but before the hardware processes the reset it
  1121. * get a link up on the port because of a hot plug event.
  1122. * because of the reset request this phy will go link down
  1123. * almost immediately.
  1124. */
  1125. /* In the resetting state we don't notify the user regarding
  1126. * link up and link down notifications.
  1127. */
  1128. sci_port_general_link_up_handler(iport, iphy, PF_RESUME);
  1129. return SCI_SUCCESS;
  1130. default:
  1131. dev_warn(sciport_to_dev(iport),
  1132. "%s: in wrong state: %d\n", __func__, state);
  1133. return SCI_FAILURE_INVALID_STATE;
  1134. }
  1135. }
  1136. enum sci_status sci_port_link_down(struct isci_port *iport,
  1137. struct isci_phy *iphy)
  1138. {
  1139. enum sci_port_states state;
  1140. state = iport->sm.current_state_id;
  1141. switch (state) {
  1142. case SCI_PORT_SUB_OPERATIONAL:
  1143. sci_port_deactivate_phy(iport, iphy, true);
  1144. /* If there are no active phys left in the port, then
  1145. * transition the port to the WAITING state until such time
  1146. * as a phy goes link up
  1147. */
  1148. if (iport->active_phy_mask == 0)
  1149. port_state_machine_change(iport,
  1150. SCI_PORT_SUB_WAITING);
  1151. return SCI_SUCCESS;
  1152. case SCI_PORT_RESETTING:
  1153. /* In the resetting state we don't notify the user regarding
  1154. * link up and link down notifications. */
  1155. sci_port_deactivate_phy(iport, iphy, false);
  1156. return SCI_SUCCESS;
  1157. default:
  1158. dev_warn(sciport_to_dev(iport),
  1159. "%s: in wrong state: %d\n", __func__, state);
  1160. return SCI_FAILURE_INVALID_STATE;
  1161. }
  1162. }
  1163. enum sci_status sci_port_start_io(struct isci_port *iport,
  1164. struct isci_remote_device *idev,
  1165. struct isci_request *ireq)
  1166. {
  1167. enum sci_port_states state;
  1168. state = iport->sm.current_state_id;
  1169. switch (state) {
  1170. case SCI_PORT_SUB_WAITING:
  1171. return SCI_FAILURE_INVALID_STATE;
  1172. case SCI_PORT_SUB_OPERATIONAL:
  1173. iport->started_request_count++;
  1174. return SCI_SUCCESS;
  1175. default:
  1176. dev_warn(sciport_to_dev(iport),
  1177. "%s: in wrong state: %d\n", __func__, state);
  1178. return SCI_FAILURE_INVALID_STATE;
  1179. }
  1180. }
  1181. enum sci_status sci_port_complete_io(struct isci_port *iport,
  1182. struct isci_remote_device *idev,
  1183. struct isci_request *ireq)
  1184. {
  1185. enum sci_port_states state;
  1186. state = iport->sm.current_state_id;
  1187. switch (state) {
  1188. case SCI_PORT_STOPPED:
  1189. dev_warn(sciport_to_dev(iport),
  1190. "%s: in wrong state: %d\n", __func__, state);
  1191. return SCI_FAILURE_INVALID_STATE;
  1192. case SCI_PORT_STOPPING:
  1193. sci_port_decrement_request_count(iport);
  1194. if (iport->started_request_count == 0)
  1195. port_state_machine_change(iport,
  1196. SCI_PORT_STOPPED);
  1197. break;
  1198. case SCI_PORT_READY:
  1199. case SCI_PORT_RESETTING:
  1200. case SCI_PORT_FAILED:
  1201. case SCI_PORT_SUB_WAITING:
  1202. case SCI_PORT_SUB_OPERATIONAL:
  1203. sci_port_decrement_request_count(iport);
  1204. break;
  1205. case SCI_PORT_SUB_CONFIGURING:
  1206. sci_port_decrement_request_count(iport);
  1207. if (iport->started_request_count == 0) {
  1208. port_state_machine_change(iport,
  1209. SCI_PORT_SUB_OPERATIONAL);
  1210. }
  1211. break;
  1212. }
  1213. return SCI_SUCCESS;
  1214. }
  1215. static void sci_port_enable_port_task_scheduler(struct isci_port *iport)
  1216. {
  1217. u32 pts_control_value;
  1218. /* enable the port task scheduler in a suspended state */
  1219. pts_control_value = readl(&iport->port_task_scheduler_registers->control);
  1220. pts_control_value |= SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND);
  1221. writel(pts_control_value, &iport->port_task_scheduler_registers->control);
  1222. }
  1223. static void sci_port_disable_port_task_scheduler(struct isci_port *iport)
  1224. {
  1225. u32 pts_control_value;
  1226. pts_control_value = readl(&iport->port_task_scheduler_registers->control);
  1227. pts_control_value &=
  1228. ~(SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND));
  1229. writel(pts_control_value, &iport->port_task_scheduler_registers->control);
  1230. }
  1231. static void sci_port_post_dummy_remote_node(struct isci_port *iport)
  1232. {
  1233. struct isci_host *ihost = iport->owning_controller;
  1234. u8 phys_index = iport->physical_port_index;
  1235. union scu_remote_node_context *rnc;
  1236. u16 rni = iport->reserved_rni;
  1237. u32 command;
  1238. rnc = &ihost->remote_node_context_table[rni];
  1239. rnc->ssp.is_valid = true;
  1240. command = SCU_CONTEXT_COMMAND_POST_RNC_32 |
  1241. phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
  1242. sci_controller_post_request(ihost, command);
  1243. /* ensure hardware has seen the post rnc command and give it
  1244. * ample time to act before sending the suspend
  1245. */
  1246. readl(&ihost->smu_registers->interrupt_status); /* flush */
  1247. udelay(10);
  1248. command = SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX_RX |
  1249. phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
  1250. sci_controller_post_request(ihost, command);
  1251. }
  1252. static void sci_port_stopped_state_enter(struct sci_base_state_machine *sm)
  1253. {
  1254. struct isci_port *iport = container_of(sm, typeof(*iport), sm);
  1255. if (iport->sm.previous_state_id == SCI_PORT_STOPPING) {
  1256. /*
  1257. * If we enter this state becasuse of a request to stop
  1258. * the port then we want to disable the hardwares port
  1259. * task scheduler. */
  1260. sci_port_disable_port_task_scheduler(iport);
  1261. }
  1262. }
  1263. static void sci_port_stopped_state_exit(struct sci_base_state_machine *sm)
  1264. {
  1265. struct isci_port *iport = container_of(sm, typeof(*iport), sm);
  1266. /* Enable and suspend the port task scheduler */
  1267. sci_port_enable_port_task_scheduler(iport);
  1268. }
  1269. static void sci_port_ready_state_enter(struct sci_base_state_machine *sm)
  1270. {
  1271. struct isci_port *iport = container_of(sm, typeof(*iport), sm);
  1272. struct isci_host *ihost = iport->owning_controller;
  1273. u32 prev_state;
  1274. prev_state = iport->sm.previous_state_id;
  1275. if (prev_state == SCI_PORT_RESETTING)
  1276. isci_port_hard_reset_complete(iport, SCI_SUCCESS);
  1277. else
  1278. dev_dbg(&ihost->pdev->dev, "%s: port%d !ready\n",
  1279. __func__, iport->physical_port_index);
  1280. /* Post and suspend the dummy remote node context for this port. */
  1281. sci_port_post_dummy_remote_node(iport);
  1282. /* Start the ready substate machine */
  1283. port_state_machine_change(iport,
  1284. SCI_PORT_SUB_WAITING);
  1285. }
  1286. static void sci_port_resetting_state_exit(struct sci_base_state_machine *sm)
  1287. {
  1288. struct isci_port *iport = container_of(sm, typeof(*iport), sm);
  1289. sci_del_timer(&iport->timer);
  1290. }
  1291. static void sci_port_stopping_state_exit(struct sci_base_state_machine *sm)
  1292. {
  1293. struct isci_port *iport = container_of(sm, typeof(*iport), sm);
  1294. sci_del_timer(&iport->timer);
  1295. sci_port_destroy_dummy_resources(iport);
  1296. }
  1297. static void sci_port_failed_state_enter(struct sci_base_state_machine *sm)
  1298. {
  1299. struct isci_port *iport = container_of(sm, typeof(*iport), sm);
  1300. isci_port_hard_reset_complete(iport, SCI_FAILURE_TIMEOUT);
  1301. }
  1302. /* --------------------------------------------------------------------------- */
  1303. static const struct sci_base_state sci_port_state_table[] = {
  1304. [SCI_PORT_STOPPED] = {
  1305. .enter_state = sci_port_stopped_state_enter,
  1306. .exit_state = sci_port_stopped_state_exit
  1307. },
  1308. [SCI_PORT_STOPPING] = {
  1309. .exit_state = sci_port_stopping_state_exit
  1310. },
  1311. [SCI_PORT_READY] = {
  1312. .enter_state = sci_port_ready_state_enter,
  1313. },
  1314. [SCI_PORT_SUB_WAITING] = {
  1315. .enter_state = sci_port_ready_substate_waiting_enter,
  1316. .exit_state = scic_sds_port_ready_substate_waiting_exit,
  1317. },
  1318. [SCI_PORT_SUB_OPERATIONAL] = {
  1319. .enter_state = sci_port_ready_substate_operational_enter,
  1320. .exit_state = sci_port_ready_substate_operational_exit
  1321. },
  1322. [SCI_PORT_SUB_CONFIGURING] = {
  1323. .enter_state = sci_port_ready_substate_configuring_enter
  1324. },
  1325. [SCI_PORT_RESETTING] = {
  1326. .exit_state = sci_port_resetting_state_exit
  1327. },
  1328. [SCI_PORT_FAILED] = {
  1329. .enter_state = sci_port_failed_state_enter,
  1330. }
  1331. };
  1332. void sci_port_construct(struct isci_port *iport, u8 index,
  1333. struct isci_host *ihost)
  1334. {
  1335. sci_init_sm(&iport->sm, sci_port_state_table, SCI_PORT_STOPPED);
  1336. iport->logical_port_index = SCIC_SDS_DUMMY_PORT;
  1337. iport->physical_port_index = index;
  1338. iport->active_phy_mask = 0;
  1339. iport->enabled_phy_mask = 0;
  1340. iport->last_active_phy = 0;
  1341. iport->ready_exit = false;
  1342. iport->owning_controller = ihost;
  1343. iport->started_request_count = 0;
  1344. iport->assigned_device_count = 0;
  1345. iport->reserved_rni = SCU_DUMMY_INDEX;
  1346. iport->reserved_tag = SCI_CONTROLLER_INVALID_IO_TAG;
  1347. sci_init_timer(&iport->timer, port_timeout);
  1348. iport->port_task_scheduler_registers = NULL;
  1349. for (index = 0; index < SCI_MAX_PHYS; index++)
  1350. iport->phy_table[index] = NULL;
  1351. }
  1352. void isci_port_init(struct isci_port *iport, struct isci_host *ihost, int index)
  1353. {
  1354. INIT_LIST_HEAD(&iport->remote_dev_list);
  1355. INIT_LIST_HEAD(&iport->domain_dev_list);
  1356. iport->isci_host = ihost;
  1357. }
  1358. void sci_port_broadcast_change_received(struct isci_port *iport, struct isci_phy *iphy)
  1359. {
  1360. struct isci_host *ihost = iport->owning_controller;
  1361. /* notify the user. */
  1362. isci_port_bc_change_received(ihost, iport, iphy);
  1363. }
  1364. static void wait_port_reset(struct isci_host *ihost, struct isci_port *iport)
  1365. {
  1366. wait_event(ihost->eventq, !test_bit(IPORT_RESET_PENDING, &iport->state));
  1367. }
  1368. int isci_port_perform_hard_reset(struct isci_host *ihost, struct isci_port *iport,
  1369. struct isci_phy *iphy)
  1370. {
  1371. unsigned long flags;
  1372. enum sci_status status;
  1373. int ret = TMF_RESP_FUNC_COMPLETE;
  1374. dev_dbg(&ihost->pdev->dev, "%s: iport = %p\n",
  1375. __func__, iport);
  1376. spin_lock_irqsave(&ihost->scic_lock, flags);
  1377. set_bit(IPORT_RESET_PENDING, &iport->state);
  1378. #define ISCI_PORT_RESET_TIMEOUT SCIC_SDS_SIGNATURE_FIS_TIMEOUT
  1379. status = sci_port_hard_reset(iport, ISCI_PORT_RESET_TIMEOUT);
  1380. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  1381. if (status == SCI_SUCCESS) {
  1382. wait_port_reset(ihost, iport);
  1383. dev_dbg(&ihost->pdev->dev,
  1384. "%s: iport = %p; hard reset completion\n",
  1385. __func__, iport);
  1386. if (iport->hard_reset_status != SCI_SUCCESS) {
  1387. ret = TMF_RESP_FUNC_FAILED;
  1388. dev_err(&ihost->pdev->dev,
  1389. "%s: iport = %p; hard reset failed (0x%x)\n",
  1390. __func__, iport, iport->hard_reset_status);
  1391. }
  1392. } else {
  1393. clear_bit(IPORT_RESET_PENDING, &iport->state);
  1394. wake_up(&ihost->eventq);
  1395. ret = TMF_RESP_FUNC_FAILED;
  1396. dev_err(&ihost->pdev->dev,
  1397. "%s: iport = %p; sci_port_hard_reset call"
  1398. " failed 0x%x\n",
  1399. __func__, iport, status);
  1400. }
  1401. /* If the hard reset for the port has failed, consider this
  1402. * the same as link failures on all phys in the port.
  1403. */
  1404. if (ret != TMF_RESP_FUNC_COMPLETE) {
  1405. dev_err(&ihost->pdev->dev,
  1406. "%s: iport = %p; hard reset failed "
  1407. "(0x%x) - driving explicit link fail for all phys\n",
  1408. __func__, iport, iport->hard_reset_status);
  1409. }
  1410. return ret;
  1411. }
  1412. int isci_ata_check_ready(struct domain_device *dev)
  1413. {
  1414. struct isci_port *iport = dev->port->lldd_port;
  1415. struct isci_host *ihost = dev_to_ihost(dev);
  1416. struct isci_remote_device *idev;
  1417. unsigned long flags;
  1418. int rc = 0;
  1419. spin_lock_irqsave(&ihost->scic_lock, flags);
  1420. idev = isci_lookup_device(dev);
  1421. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  1422. if (!idev)
  1423. goto out;
  1424. if (test_bit(IPORT_RESET_PENDING, &iport->state))
  1425. goto out;
  1426. rc = !!iport->active_phy_mask;
  1427. out:
  1428. isci_put_device(idev);
  1429. return rc;
  1430. }
  1431. void isci_port_deformed(struct asd_sas_phy *phy)
  1432. {
  1433. struct isci_host *ihost = phy->ha->lldd_ha;
  1434. struct isci_port *iport = phy->port->lldd_port;
  1435. unsigned long flags;
  1436. int i;
  1437. /* we got a port notification on a port that was subsequently
  1438. * torn down and libsas is just now catching up
  1439. */
  1440. if (!iport)
  1441. return;
  1442. spin_lock_irqsave(&ihost->scic_lock, flags);
  1443. for (i = 0; i < SCI_MAX_PHYS; i++) {
  1444. if (iport->active_phy_mask & 1 << i)
  1445. break;
  1446. }
  1447. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  1448. if (i >= SCI_MAX_PHYS)
  1449. dev_dbg(&ihost->pdev->dev, "%s: port: %ld\n",
  1450. __func__, (long) (iport - &ihost->ports[0]));
  1451. }
  1452. void isci_port_formed(struct asd_sas_phy *phy)
  1453. {
  1454. struct isci_host *ihost = phy->ha->lldd_ha;
  1455. struct isci_phy *iphy = to_iphy(phy);
  1456. struct asd_sas_port *port = phy->port;
  1457. struct isci_port *iport;
  1458. unsigned long flags;
  1459. int i;
  1460. /* initial ports are formed as the driver is still initializing,
  1461. * wait for that process to complete
  1462. */
  1463. wait_for_start(ihost);
  1464. spin_lock_irqsave(&ihost->scic_lock, flags);
  1465. for (i = 0; i < SCI_MAX_PORTS; i++) {
  1466. iport = &ihost->ports[i];
  1467. if (iport->active_phy_mask & 1 << iphy->phy_index)
  1468. break;
  1469. }
  1470. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  1471. if (i >= SCI_MAX_PORTS)
  1472. iport = NULL;
  1473. port->lldd_port = iport;
  1474. }