port.c 53 KB

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