phy.c 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255
  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 "host.h"
  57. #include "phy.h"
  58. #include "scu_event_codes.h"
  59. #include "timers.h"
  60. #include "probe_roms.h"
  61. /* Maximum arbitration wait time in micro-seconds */
  62. #define SCIC_SDS_PHY_MAX_ARBITRATION_WAIT_TIME (700)
  63. enum sas_linkrate sci_phy_linkrate(struct scic_sds_phy *sci_phy)
  64. {
  65. return sci_phy->max_negotiated_speed;
  66. }
  67. /*
  68. * *****************************************************************************
  69. * * SCIC SDS PHY Internal Methods
  70. * ***************************************************************************** */
  71. /**
  72. * This method will initialize the phy transport layer registers
  73. * @sci_phy:
  74. * @transport_layer_registers
  75. *
  76. * enum sci_status
  77. */
  78. static enum sci_status scic_sds_phy_transport_layer_initialization(
  79. struct scic_sds_phy *sci_phy,
  80. struct scu_transport_layer_registers __iomem *transport_layer_registers)
  81. {
  82. u32 tl_control;
  83. sci_phy->transport_layer_registers = transport_layer_registers;
  84. writel(SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX,
  85. &sci_phy->transport_layer_registers->stp_rni);
  86. /*
  87. * Hardware team recommends that we enable the STP prefetch for all
  88. * transports
  89. */
  90. tl_control = readl(&sci_phy->transport_layer_registers->control);
  91. tl_control |= SCU_TLCR_GEN_BIT(STP_WRITE_DATA_PREFETCH);
  92. writel(tl_control, &sci_phy->transport_layer_registers->control);
  93. return SCI_SUCCESS;
  94. }
  95. /**
  96. * This method will initialize the phy link layer registers
  97. * @sci_phy:
  98. * @link_layer_registers:
  99. *
  100. * enum sci_status
  101. */
  102. static enum sci_status
  103. scic_sds_phy_link_layer_initialization(struct scic_sds_phy *sci_phy,
  104. struct scu_link_layer_registers __iomem *link_layer_registers)
  105. {
  106. struct scic_sds_controller *scic =
  107. sci_phy->owning_port->owning_controller;
  108. int phy_idx = sci_phy->phy_index;
  109. struct sci_phy_user_params *phy_user =
  110. &scic->user_parameters.sds1.phys[phy_idx];
  111. struct sci_phy_oem_params *phy_oem =
  112. &scic->oem_parameters.sds1.phys[phy_idx];
  113. u32 phy_configuration;
  114. struct scic_phy_cap phy_cap;
  115. u32 parity_check = 0;
  116. u32 parity_count = 0;
  117. u32 llctl, link_rate;
  118. u32 clksm_value = 0;
  119. sci_phy->link_layer_registers = link_layer_registers;
  120. /* Set our IDENTIFY frame data */
  121. #define SCI_END_DEVICE 0x01
  122. writel(SCU_SAS_TIID_GEN_BIT(SMP_INITIATOR) |
  123. SCU_SAS_TIID_GEN_BIT(SSP_INITIATOR) |
  124. SCU_SAS_TIID_GEN_BIT(STP_INITIATOR) |
  125. SCU_SAS_TIID_GEN_BIT(DA_SATA_HOST) |
  126. SCU_SAS_TIID_GEN_VAL(DEVICE_TYPE, SCI_END_DEVICE),
  127. &sci_phy->link_layer_registers->transmit_identification);
  128. /* Write the device SAS Address */
  129. writel(0xFEDCBA98,
  130. &sci_phy->link_layer_registers->sas_device_name_high);
  131. writel(phy_idx, &sci_phy->link_layer_registers->sas_device_name_low);
  132. /* Write the source SAS Address */
  133. writel(phy_oem->sas_address.high,
  134. &sci_phy->link_layer_registers->source_sas_address_high);
  135. writel(phy_oem->sas_address.low,
  136. &sci_phy->link_layer_registers->source_sas_address_low);
  137. /* Clear and Set the PHY Identifier */
  138. writel(0, &sci_phy->link_layer_registers->identify_frame_phy_id);
  139. writel(SCU_SAS_TIPID_GEN_VALUE(ID, phy_idx),
  140. &sci_phy->link_layer_registers->identify_frame_phy_id);
  141. /* Change the initial state of the phy configuration register */
  142. phy_configuration =
  143. readl(&sci_phy->link_layer_registers->phy_configuration);
  144. /* Hold OOB state machine in reset */
  145. phy_configuration |= SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
  146. writel(phy_configuration,
  147. &sci_phy->link_layer_registers->phy_configuration);
  148. /* Configure the SNW capabilities */
  149. phy_cap.all = 0;
  150. phy_cap.start = 1;
  151. phy_cap.gen3_no_ssc = 1;
  152. phy_cap.gen2_no_ssc = 1;
  153. phy_cap.gen1_no_ssc = 1;
  154. if (scic->oem_parameters.sds1.controller.do_enable_ssc == true) {
  155. phy_cap.gen3_ssc = 1;
  156. phy_cap.gen2_ssc = 1;
  157. phy_cap.gen1_ssc = 1;
  158. }
  159. /*
  160. * The SAS specification indicates that the phy_capabilities that
  161. * are transmitted shall have an even parity. Calculate the parity. */
  162. parity_check = phy_cap.all;
  163. while (parity_check != 0) {
  164. if (parity_check & 0x1)
  165. parity_count++;
  166. parity_check >>= 1;
  167. }
  168. /*
  169. * If parity indicates there are an odd number of bits set, then
  170. * set the parity bit to 1 in the phy capabilities. */
  171. if ((parity_count % 2) != 0)
  172. phy_cap.parity = 1;
  173. writel(phy_cap.all, &sci_phy->link_layer_registers->phy_capabilities);
  174. /* Set the enable spinup period but disable the ability to send
  175. * notify enable spinup
  176. */
  177. writel(SCU_ENSPINUP_GEN_VAL(COUNT,
  178. phy_user->notify_enable_spin_up_insertion_frequency),
  179. &sci_phy->link_layer_registers->notify_enable_spinup_control);
  180. /* Write the ALIGN Insertion Ferequency for connected phy and
  181. * inpendent of connected state
  182. */
  183. clksm_value = SCU_ALIGN_INSERTION_FREQUENCY_GEN_VAL(CONNECTED,
  184. phy_user->in_connection_align_insertion_frequency);
  185. clksm_value |= SCU_ALIGN_INSERTION_FREQUENCY_GEN_VAL(GENERAL,
  186. phy_user->align_insertion_frequency);
  187. writel(clksm_value, &sci_phy->link_layer_registers->clock_skew_management);
  188. /* @todo Provide a way to write this register correctly */
  189. writel(0x02108421,
  190. &sci_phy->link_layer_registers->afe_lookup_table_control);
  191. llctl = SCU_SAS_LLCTL_GEN_VAL(NO_OUTBOUND_TASK_TIMEOUT,
  192. (u8)scic->user_parameters.sds1.no_outbound_task_timeout);
  193. switch(phy_user->max_speed_generation) {
  194. case SCIC_SDS_PARM_GEN3_SPEED:
  195. link_rate = SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN3;
  196. break;
  197. case SCIC_SDS_PARM_GEN2_SPEED:
  198. link_rate = SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN2;
  199. break;
  200. default:
  201. link_rate = SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN1;
  202. break;
  203. }
  204. llctl |= SCU_SAS_LLCTL_GEN_VAL(MAX_LINK_RATE, link_rate);
  205. writel(llctl, &sci_phy->link_layer_registers->link_layer_control);
  206. if (is_a0() || is_a2()) {
  207. /* Program the max ARB time for the PHY to 700us so we inter-operate with
  208. * the PMC expander which shuts down PHYs if the expander PHY generates too
  209. * many breaks. This time value will guarantee that the initiator PHY will
  210. * generate the break.
  211. */
  212. writel(SCIC_SDS_PHY_MAX_ARBITRATION_WAIT_TIME,
  213. &sci_phy->link_layer_registers->maximum_arbitration_wait_timer_timeout);
  214. }
  215. /*
  216. * Set the link layer hang detection to 500ms (0x1F4) from its default
  217. * value of 128ms. Max value is 511 ms.
  218. */
  219. writel(0x1F4, &sci_phy->link_layer_registers->link_layer_hang_detection_timeout);
  220. /* We can exit the initial state to the stopped state */
  221. sci_base_state_machine_change_state(&sci_phy->state_machine,
  222. SCI_BASE_PHY_STATE_STOPPED);
  223. return SCI_SUCCESS;
  224. }
  225. /**
  226. * This function will handle the sata SIGNATURE FIS timeout condition. It will
  227. * restart the starting substate machine since we dont know what has actually
  228. * happening.
  229. */
  230. static void scic_sds_phy_sata_timeout(void *phy)
  231. {
  232. struct scic_sds_phy *sci_phy = phy;
  233. dev_dbg(sciphy_to_dev(sci_phy),
  234. "%s: SCIC SDS Phy 0x%p did not receive signature fis before "
  235. "timeout.\n",
  236. __func__,
  237. sci_phy);
  238. sci_base_state_machine_change_state(&sci_phy->state_machine,
  239. SCI_BASE_PHY_STATE_STARTING);
  240. }
  241. /**
  242. * This method returns the port currently containing this phy. If the phy is
  243. * currently contained by the dummy port, then the phy is considered to not
  244. * be part of a port.
  245. * @sci_phy: This parameter specifies the phy for which to retrieve the
  246. * containing port.
  247. *
  248. * This method returns a handle to a port that contains the supplied phy.
  249. * NULL This value is returned if the phy is not part of a real
  250. * port (i.e. it's contained in the dummy port). !NULL All other
  251. * values indicate a handle/pointer to the port containing the phy.
  252. */
  253. struct scic_sds_port *scic_sds_phy_get_port(
  254. struct scic_sds_phy *sci_phy)
  255. {
  256. if (scic_sds_port_get_index(sci_phy->owning_port) == SCIC_SDS_DUMMY_PORT)
  257. return NULL;
  258. return sci_phy->owning_port;
  259. }
  260. /**
  261. * This method will assign a port to the phy object.
  262. * @out]: sci_phy This parameter specifies the phy for which to assign a port
  263. * object.
  264. *
  265. *
  266. */
  267. void scic_sds_phy_set_port(
  268. struct scic_sds_phy *sci_phy,
  269. struct scic_sds_port *sci_port)
  270. {
  271. sci_phy->owning_port = sci_port;
  272. if (sci_phy->bcn_received_while_port_unassigned) {
  273. sci_phy->bcn_received_while_port_unassigned = false;
  274. scic_sds_port_broadcast_change_received(sci_phy->owning_port, sci_phy);
  275. }
  276. }
  277. /**
  278. * This method will initialize the constructed phy
  279. * @sci_phy:
  280. * @link_layer_registers:
  281. *
  282. * enum sci_status
  283. */
  284. enum sci_status scic_sds_phy_initialize(
  285. struct scic_sds_phy *sci_phy,
  286. struct scu_transport_layer_registers __iomem *transport_layer_registers,
  287. struct scu_link_layer_registers __iomem *link_layer_registers)
  288. {
  289. struct scic_sds_controller *scic = scic_sds_phy_get_controller(sci_phy);
  290. struct isci_host *ihost = scic_to_ihost(scic);
  291. /* Create the SIGNATURE FIS Timeout timer for this phy */
  292. sci_phy->sata_timeout_timer =
  293. isci_timer_create(
  294. ihost,
  295. sci_phy,
  296. scic_sds_phy_sata_timeout);
  297. /* Perfrom the initialization of the TL hardware */
  298. scic_sds_phy_transport_layer_initialization(
  299. sci_phy,
  300. transport_layer_registers);
  301. /* Perofrm the initialization of the PE hardware */
  302. scic_sds_phy_link_layer_initialization(sci_phy, link_layer_registers);
  303. /*
  304. * There is nothing that needs to be done in this state just
  305. * transition to the stopped state. */
  306. sci_base_state_machine_change_state(&sci_phy->state_machine,
  307. SCI_BASE_PHY_STATE_STOPPED);
  308. return SCI_SUCCESS;
  309. }
  310. /**
  311. * This method assigns the direct attached device ID for this phy.
  312. *
  313. * @sci_phy The phy for which the direct attached device id is to
  314. * be assigned.
  315. * @device_id The direct attached device ID to assign to the phy.
  316. * This will either be the RNi for the device or an invalid RNi if there
  317. * is no current device assigned to the phy.
  318. */
  319. void scic_sds_phy_setup_transport(
  320. struct scic_sds_phy *sci_phy,
  321. u32 device_id)
  322. {
  323. u32 tl_control;
  324. writel(device_id, &sci_phy->transport_layer_registers->stp_rni);
  325. /*
  326. * The read should guarantee that the first write gets posted
  327. * before the next write
  328. */
  329. tl_control = readl(&sci_phy->transport_layer_registers->control);
  330. tl_control |= SCU_TLCR_GEN_BIT(CLEAR_TCI_NCQ_MAPPING_TABLE);
  331. writel(tl_control, &sci_phy->transport_layer_registers->control);
  332. }
  333. /**
  334. *
  335. * @sci_phy: The phy object to be suspended.
  336. *
  337. * This function will perform the register reads/writes to suspend the SCU
  338. * hardware protocol engine. none
  339. */
  340. static void scic_sds_phy_suspend(
  341. struct scic_sds_phy *sci_phy)
  342. {
  343. u32 scu_sas_pcfg_value;
  344. scu_sas_pcfg_value =
  345. readl(&sci_phy->link_layer_registers->phy_configuration);
  346. scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE);
  347. writel(scu_sas_pcfg_value,
  348. &sci_phy->link_layer_registers->phy_configuration);
  349. scic_sds_phy_setup_transport(
  350. sci_phy,
  351. SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX);
  352. }
  353. void scic_sds_phy_resume(struct scic_sds_phy *sci_phy)
  354. {
  355. u32 scu_sas_pcfg_value;
  356. scu_sas_pcfg_value =
  357. readl(&sci_phy->link_layer_registers->phy_configuration);
  358. scu_sas_pcfg_value &= ~SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE);
  359. writel(scu_sas_pcfg_value,
  360. &sci_phy->link_layer_registers->phy_configuration);
  361. }
  362. void scic_sds_phy_get_sas_address(struct scic_sds_phy *sci_phy,
  363. struct sci_sas_address *sas_address)
  364. {
  365. sas_address->high = readl(&sci_phy->link_layer_registers->source_sas_address_high);
  366. sas_address->low = readl(&sci_phy->link_layer_registers->source_sas_address_low);
  367. }
  368. void scic_sds_phy_get_attached_sas_address(struct scic_sds_phy *sci_phy,
  369. struct sci_sas_address *sas_address)
  370. {
  371. struct sas_identify_frame *iaf;
  372. struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
  373. iaf = &iphy->frame_rcvd.iaf;
  374. memcpy(sas_address, iaf->sas_addr, SAS_ADDR_SIZE);
  375. }
  376. void scic_sds_phy_get_protocols(struct scic_sds_phy *sci_phy,
  377. struct scic_phy_proto *protocols)
  378. {
  379. protocols->all =
  380. (u16)(readl(&sci_phy->
  381. link_layer_registers->transmit_identification) &
  382. 0x0000FFFF);
  383. }
  384. enum sci_status scic_sds_phy_start(struct scic_sds_phy *sci_phy)
  385. {
  386. struct scic_sds_controller *scic = sci_phy->owning_port->owning_controller;
  387. enum scic_sds_phy_states state = sci_phy->state_machine.current_state_id;
  388. struct isci_host *ihost = scic_to_ihost(scic);
  389. if (state != SCI_BASE_PHY_STATE_STOPPED) {
  390. dev_dbg(sciphy_to_dev(sci_phy),
  391. "%s: in wrong state: %d\n", __func__, state);
  392. return SCI_FAILURE_INVALID_STATE;
  393. }
  394. /* Create the SIGNATURE FIS Timeout timer for this phy */
  395. sci_phy->sata_timeout_timer = isci_timer_create(ihost, sci_phy,
  396. scic_sds_phy_sata_timeout);
  397. if (sci_phy->sata_timeout_timer)
  398. sci_base_state_machine_change_state(&sci_phy->state_machine,
  399. SCI_BASE_PHY_STATE_STARTING);
  400. return SCI_SUCCESS;
  401. }
  402. enum sci_status scic_sds_phy_stop(struct scic_sds_phy *sci_phy)
  403. {
  404. enum scic_sds_phy_states state = sci_phy->state_machine.current_state_id;
  405. switch (state) {
  406. case SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL:
  407. case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN:
  408. case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN:
  409. case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER:
  410. case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER:
  411. case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN:
  412. case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN:
  413. case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF:
  414. case SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL:
  415. case SCI_BASE_PHY_STATE_READY:
  416. break;
  417. default:
  418. dev_dbg(sciphy_to_dev(sci_phy),
  419. "%s: in wrong state: %d\n", __func__, state);
  420. return SCI_FAILURE_INVALID_STATE;
  421. }
  422. sci_base_state_machine_change_state(&sci_phy->state_machine,
  423. SCI_BASE_PHY_STATE_STOPPED);
  424. return SCI_SUCCESS;
  425. }
  426. /**
  427. * This method will attempt to reset the phy. This request is only valid when
  428. * the phy is in an ready state
  429. * @sci_phy:
  430. *
  431. * enum sci_status
  432. */
  433. enum sci_status scic_sds_phy_reset(
  434. struct scic_sds_phy *sci_phy)
  435. {
  436. return sci_phy->state_handlers->reset_handler(sci_phy);
  437. }
  438. /**
  439. * This method will process the event code received.
  440. * @sci_phy:
  441. * @event_code:
  442. *
  443. * enum sci_status
  444. */
  445. enum sci_status scic_sds_phy_event_handler(
  446. struct scic_sds_phy *sci_phy,
  447. u32 event_code)
  448. {
  449. return sci_phy->state_handlers->event_handler(sci_phy, event_code);
  450. }
  451. /**
  452. * This method will process the frame index received.
  453. * @sci_phy:
  454. * @frame_index:
  455. *
  456. * enum sci_status
  457. */
  458. enum sci_status scic_sds_phy_frame_handler(
  459. struct scic_sds_phy *sci_phy,
  460. u32 frame_index)
  461. {
  462. return sci_phy->state_handlers->frame_handler(sci_phy, frame_index);
  463. }
  464. /**
  465. * This method will give the phy permission to consume power
  466. * @sci_phy:
  467. *
  468. * enum sci_status
  469. */
  470. enum sci_status scic_sds_phy_consume_power_handler(
  471. struct scic_sds_phy *sci_phy)
  472. {
  473. return sci_phy->state_handlers->consume_power_handler(sci_phy);
  474. }
  475. /*
  476. * *****************************************************************************
  477. * * SCIC SDS PHY HELPER FUNCTIONS
  478. * ***************************************************************************** */
  479. /**
  480. *
  481. * @sci_phy: The phy object that received SAS PHY DETECTED.
  482. *
  483. * This method continues the link training for the phy as if it were a SAS PHY
  484. * instead of a SATA PHY. This is done because the completion queue had a SAS
  485. * PHY DETECTED event when the state machine was expecting a SATA PHY event.
  486. * none
  487. */
  488. static void scic_sds_phy_start_sas_link_training(
  489. struct scic_sds_phy *sci_phy)
  490. {
  491. u32 phy_control;
  492. phy_control =
  493. readl(&sci_phy->link_layer_registers->phy_configuration);
  494. phy_control |= SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD);
  495. writel(phy_control,
  496. &sci_phy->link_layer_registers->phy_configuration);
  497. sci_base_state_machine_change_state(
  498. &sci_phy->state_machine,
  499. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
  500. );
  501. sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SAS;
  502. }
  503. /**
  504. *
  505. * @sci_phy: The phy object that received a SATA SPINUP HOLD event
  506. *
  507. * This method continues the link training for the phy as if it were a SATA PHY
  508. * instead of a SAS PHY. This is done because the completion queue had a SATA
  509. * SPINUP HOLD event when the state machine was expecting a SAS PHY event. none
  510. */
  511. static void scic_sds_phy_start_sata_link_training(
  512. struct scic_sds_phy *sci_phy)
  513. {
  514. sci_base_state_machine_change_state(
  515. &sci_phy->state_machine,
  516. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
  517. );
  518. sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA;
  519. }
  520. /**
  521. * scic_sds_phy_complete_link_training - perform processing common to
  522. * all protocols upon completion of link training.
  523. * @sci_phy: This parameter specifies the phy object for which link training
  524. * has completed.
  525. * @max_link_rate: This parameter specifies the maximum link rate to be
  526. * associated with this phy.
  527. * @next_state: This parameter specifies the next state for the phy's starting
  528. * sub-state machine.
  529. *
  530. */
  531. static void scic_sds_phy_complete_link_training(
  532. struct scic_sds_phy *sci_phy,
  533. enum sas_linkrate max_link_rate,
  534. u32 next_state)
  535. {
  536. sci_phy->max_negotiated_speed = max_link_rate;
  537. sci_base_state_machine_change_state(&sci_phy->state_machine,
  538. next_state);
  539. }
  540. static void scic_sds_phy_restart_starting_state(
  541. struct scic_sds_phy *sci_phy)
  542. {
  543. /* Re-enter the base state machine starting state */
  544. sci_base_state_machine_change_state(&sci_phy->state_machine,
  545. SCI_BASE_PHY_STATE_STARTING);
  546. }
  547. /**
  548. *
  549. * @phy: This struct scic_sds_phy object which has received an event.
  550. * @event_code: This is the event code which the phy object is to decode.
  551. *
  552. * This method is called when an event notification is received for the phy
  553. * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. -
  554. * decode the event - sas phy detected causes a state transition to the wait
  555. * for speed event notification. - any other events log a warning message and
  556. * set a failure status enum sci_status SCI_SUCCESS on any valid event notification
  557. * SCI_FAILURE on any unexpected event notifation
  558. */
  559. static enum sci_status scic_sds_phy_starting_substate_await_ossp_event_handler(
  560. struct scic_sds_phy *sci_phy,
  561. u32 event_code)
  562. {
  563. u32 result = SCI_SUCCESS;
  564. switch (scu_get_event_code(event_code)) {
  565. case SCU_EVENT_SAS_PHY_DETECTED:
  566. scic_sds_phy_start_sas_link_training(sci_phy);
  567. sci_phy->is_in_link_training = true;
  568. break;
  569. case SCU_EVENT_SATA_SPINUP_HOLD:
  570. scic_sds_phy_start_sata_link_training(sci_phy);
  571. sci_phy->is_in_link_training = true;
  572. break;
  573. default:
  574. dev_dbg(sciphy_to_dev(sci_phy),
  575. "%s: PHY starting substate machine received "
  576. "unexpected event_code %x\n",
  577. __func__,
  578. event_code);
  579. result = SCI_FAILURE;
  580. break;
  581. }
  582. return result;
  583. }
  584. /**
  585. *
  586. * @phy: This struct scic_sds_phy object which has received an event.
  587. * @event_code: This is the event code which the phy object is to decode.
  588. *
  589. * This method is called when an event notification is received for the phy
  590. * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. -
  591. * decode the event - sas phy detected returns us back to this state. - speed
  592. * event detected causes a state transition to the wait for iaf. - identify
  593. * timeout is an un-expected event and the state machine is restarted. - link
  594. * failure events restart the starting state machine - any other events log a
  595. * warning message and set a failure status enum sci_status SCI_SUCCESS on any valid
  596. * event notification SCI_FAILURE on any unexpected event notifation
  597. */
  598. static enum sci_status scic_sds_phy_starting_substate_await_sas_phy_speed_event_handler(
  599. struct scic_sds_phy *sci_phy,
  600. u32 event_code)
  601. {
  602. u32 result = SCI_SUCCESS;
  603. switch (scu_get_event_code(event_code)) {
  604. case SCU_EVENT_SAS_PHY_DETECTED:
  605. /*
  606. * Why is this being reported again by the controller?
  607. * We would re-enter this state so just stay here */
  608. break;
  609. case SCU_EVENT_SAS_15:
  610. case SCU_EVENT_SAS_15_SSC:
  611. scic_sds_phy_complete_link_training(
  612. sci_phy,
  613. SAS_LINK_RATE_1_5_GBPS,
  614. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF);
  615. break;
  616. case SCU_EVENT_SAS_30:
  617. case SCU_EVENT_SAS_30_SSC:
  618. scic_sds_phy_complete_link_training(
  619. sci_phy,
  620. SAS_LINK_RATE_3_0_GBPS,
  621. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF);
  622. break;
  623. case SCU_EVENT_SAS_60:
  624. case SCU_EVENT_SAS_60_SSC:
  625. scic_sds_phy_complete_link_training(
  626. sci_phy,
  627. SAS_LINK_RATE_6_0_GBPS,
  628. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF);
  629. break;
  630. case SCU_EVENT_SATA_SPINUP_HOLD:
  631. /*
  632. * We were doing SAS PHY link training and received a SATA PHY event
  633. * continue OOB/SN as if this were a SATA PHY */
  634. scic_sds_phy_start_sata_link_training(sci_phy);
  635. break;
  636. case SCU_EVENT_LINK_FAILURE:
  637. /* Link failure change state back to the starting state */
  638. scic_sds_phy_restart_starting_state(sci_phy);
  639. break;
  640. default:
  641. dev_warn(sciphy_to_dev(sci_phy),
  642. "%s: PHY starting substate machine received "
  643. "unexpected event_code %x\n",
  644. __func__,
  645. event_code);
  646. result = SCI_FAILURE;
  647. break;
  648. }
  649. return result;
  650. }
  651. /**
  652. *
  653. * @phy: This struct scic_sds_phy object which has received an event.
  654. * @event_code: This is the event code which the phy object is to decode.
  655. *
  656. * This method is called when an event notification is received for the phy
  657. * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. -
  658. * decode the event - sas phy detected event backs up the state machine to the
  659. * await speed notification. - identify timeout is an un-expected event and the
  660. * state machine is restarted. - link failure events restart the starting state
  661. * machine - any other events log a warning message and set a failure status
  662. * enum sci_status SCI_SUCCESS on any valid event notification SCI_FAILURE on any
  663. * unexpected event notifation
  664. */
  665. static enum sci_status scic_sds_phy_starting_substate_await_iaf_uf_event_handler(
  666. struct scic_sds_phy *sci_phy,
  667. u32 event_code)
  668. {
  669. u32 result = SCI_SUCCESS;
  670. switch (scu_get_event_code(event_code)) {
  671. case SCU_EVENT_SAS_PHY_DETECTED:
  672. /* Backup the state machine */
  673. scic_sds_phy_start_sas_link_training(sci_phy);
  674. break;
  675. case SCU_EVENT_SATA_SPINUP_HOLD:
  676. /*
  677. * We were doing SAS PHY link training and received a SATA PHY event
  678. * continue OOB/SN as if this were a SATA PHY */
  679. scic_sds_phy_start_sata_link_training(sci_phy);
  680. break;
  681. case SCU_EVENT_RECEIVED_IDENTIFY_TIMEOUT:
  682. case SCU_EVENT_LINK_FAILURE:
  683. case SCU_EVENT_HARD_RESET_RECEIVED:
  684. /* Start the oob/sn state machine over again */
  685. scic_sds_phy_restart_starting_state(sci_phy);
  686. break;
  687. default:
  688. dev_warn(sciphy_to_dev(sci_phy),
  689. "%s: PHY starting substate machine received "
  690. "unexpected event_code %x\n",
  691. __func__,
  692. event_code);
  693. result = SCI_FAILURE;
  694. break;
  695. }
  696. return result;
  697. }
  698. /**
  699. *
  700. * @phy: This struct scic_sds_phy object which has received an event.
  701. * @event_code: This is the event code which the phy object is to decode.
  702. *
  703. * This method is called when an event notification is received for the phy
  704. * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_POWER. -
  705. * decode the event - link failure events restart the starting state machine -
  706. * any other events log a warning message and set a failure status enum sci_status
  707. * SCI_SUCCESS on a link failure event SCI_FAILURE on any unexpected event
  708. * notifation
  709. */
  710. static enum sci_status scic_sds_phy_starting_substate_await_sas_power_event_handler(
  711. struct scic_sds_phy *sci_phy,
  712. u32 event_code)
  713. {
  714. u32 result = SCI_SUCCESS;
  715. switch (scu_get_event_code(event_code)) {
  716. case SCU_EVENT_LINK_FAILURE:
  717. /* Link failure change state back to the starting state */
  718. scic_sds_phy_restart_starting_state(sci_phy);
  719. break;
  720. default:
  721. dev_warn(sciphy_to_dev(sci_phy),
  722. "%s: PHY starting substate machine received unexpected "
  723. "event_code %x\n",
  724. __func__,
  725. event_code);
  726. result = SCI_FAILURE;
  727. break;
  728. }
  729. return result;
  730. }
  731. /**
  732. *
  733. * @phy: This struct scic_sds_phy object which has received an event.
  734. * @event_code: This is the event code which the phy object is to decode.
  735. *
  736. * This method is called when an event notification is received for the phy
  737. * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. -
  738. * decode the event - link failure events restart the starting state machine -
  739. * sata spinup hold events are ignored since they are expected - any other
  740. * events log a warning message and set a failure status enum sci_status SCI_SUCCESS
  741. * on a link failure event SCI_FAILURE on any unexpected event notifation
  742. */
  743. static enum sci_status scic_sds_phy_starting_substate_await_sata_power_event_handler(
  744. struct scic_sds_phy *sci_phy,
  745. u32 event_code)
  746. {
  747. u32 result = SCI_SUCCESS;
  748. switch (scu_get_event_code(event_code)) {
  749. case SCU_EVENT_LINK_FAILURE:
  750. /* Link failure change state back to the starting state */
  751. scic_sds_phy_restart_starting_state(sci_phy);
  752. break;
  753. case SCU_EVENT_SATA_SPINUP_HOLD:
  754. /* These events are received every 10ms and are expected while in this state */
  755. break;
  756. case SCU_EVENT_SAS_PHY_DETECTED:
  757. /*
  758. * There has been a change in the phy type before OOB/SN for the
  759. * SATA finished start down the SAS link traning path. */
  760. scic_sds_phy_start_sas_link_training(sci_phy);
  761. break;
  762. default:
  763. dev_warn(sciphy_to_dev(sci_phy),
  764. "%s: PHY starting substate machine received "
  765. "unexpected event_code %x\n",
  766. __func__,
  767. event_code);
  768. result = SCI_FAILURE;
  769. break;
  770. }
  771. return result;
  772. }
  773. /**
  774. * scic_sds_phy_starting_substate_await_sata_phy_event_handler -
  775. * @phy: This struct scic_sds_phy object which has received an event.
  776. * @event_code: This is the event code which the phy object is to decode.
  777. *
  778. * This method is called when an event notification is received for the phy
  779. * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. -
  780. * decode the event - link failure events restart the starting state machine -
  781. * sata spinup hold events are ignored since they are expected - sata phy
  782. * detected event change to the wait speed event - any other events log a
  783. * warning message and set a failure status enum sci_status SCI_SUCCESS on a link
  784. * failure event SCI_FAILURE on any unexpected event notifation
  785. */
  786. static enum sci_status scic_sds_phy_starting_substate_await_sata_phy_event_handler(
  787. struct scic_sds_phy *sci_phy, u32 event_code)
  788. {
  789. u32 result = SCI_SUCCESS;
  790. switch (scu_get_event_code(event_code)) {
  791. case SCU_EVENT_LINK_FAILURE:
  792. /* Link failure change state back to the starting state */
  793. scic_sds_phy_restart_starting_state(sci_phy);
  794. break;
  795. case SCU_EVENT_SATA_SPINUP_HOLD:
  796. /* These events might be received since we dont know how many may be in
  797. * the completion queue while waiting for power
  798. */
  799. break;
  800. case SCU_EVENT_SATA_PHY_DETECTED:
  801. sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA;
  802. /* We have received the SATA PHY notification change state */
  803. sci_base_state_machine_change_state(&sci_phy->state_machine,
  804. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN);
  805. break;
  806. case SCU_EVENT_SAS_PHY_DETECTED:
  807. /* There has been a change in the phy type before OOB/SN for the
  808. * SATA finished start down the SAS link traning path.
  809. */
  810. scic_sds_phy_start_sas_link_training(sci_phy);
  811. break;
  812. default:
  813. dev_warn(sciphy_to_dev(sci_phy),
  814. "%s: PHY starting substate machine received "
  815. "unexpected event_code %x\n",
  816. __func__,
  817. event_code);
  818. result = SCI_FAILURE;
  819. break;
  820. }
  821. return result;
  822. }
  823. /**
  824. *
  825. * @phy: This struct scic_sds_phy object which has received an event.
  826. * @event_code: This is the event code which the phy object is to decode.
  827. *
  828. * This method is called when an event notification is received for the phy
  829. * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN.
  830. * - decode the event - sata phy detected returns us back to this state. -
  831. * speed event detected causes a state transition to the wait for signature. -
  832. * link failure events restart the starting state machine - any other events
  833. * log a warning message and set a failure status enum sci_status SCI_SUCCESS on any
  834. * valid event notification SCI_FAILURE on any unexpected event notifation
  835. */
  836. static enum sci_status scic_sds_phy_starting_substate_await_sata_speed_event_handler(
  837. struct scic_sds_phy *sci_phy,
  838. u32 event_code)
  839. {
  840. u32 result = SCI_SUCCESS;
  841. switch (scu_get_event_code(event_code)) {
  842. case SCU_EVENT_SATA_PHY_DETECTED:
  843. /*
  844. * The hardware reports multiple SATA PHY detected events
  845. * ignore the extras */
  846. break;
  847. case SCU_EVENT_SATA_15:
  848. case SCU_EVENT_SATA_15_SSC:
  849. scic_sds_phy_complete_link_training(
  850. sci_phy,
  851. SAS_LINK_RATE_1_5_GBPS,
  852. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF);
  853. break;
  854. case SCU_EVENT_SATA_30:
  855. case SCU_EVENT_SATA_30_SSC:
  856. scic_sds_phy_complete_link_training(
  857. sci_phy,
  858. SAS_LINK_RATE_3_0_GBPS,
  859. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF);
  860. break;
  861. case SCU_EVENT_SATA_60:
  862. case SCU_EVENT_SATA_60_SSC:
  863. scic_sds_phy_complete_link_training(
  864. sci_phy,
  865. SAS_LINK_RATE_6_0_GBPS,
  866. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF);
  867. break;
  868. case SCU_EVENT_LINK_FAILURE:
  869. /* Link failure change state back to the starting state */
  870. scic_sds_phy_restart_starting_state(sci_phy);
  871. break;
  872. case SCU_EVENT_SAS_PHY_DETECTED:
  873. /*
  874. * There has been a change in the phy type before OOB/SN for the
  875. * SATA finished start down the SAS link traning path. */
  876. scic_sds_phy_start_sas_link_training(sci_phy);
  877. break;
  878. default:
  879. dev_warn(sciphy_to_dev(sci_phy),
  880. "%s: PHY starting substate machine received "
  881. "unexpected event_code %x\n",
  882. __func__,
  883. event_code);
  884. result = SCI_FAILURE;
  885. break;
  886. }
  887. return result;
  888. }
  889. /**
  890. * scic_sds_phy_starting_substate_await_sig_fis_event_handler -
  891. * @phy: This struct scic_sds_phy object which has received an event.
  892. * @event_code: This is the event code which the phy object is to decode.
  893. *
  894. * This method is called when an event notification is received for the phy
  895. * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. -
  896. * decode the event - sas phy detected event backs up the state machine to the
  897. * await speed notification. - identify timeout is an un-expected event and the
  898. * state machine is restarted. - link failure events restart the starting state
  899. * machine - any other events log a warning message and set a failure status
  900. * enum sci_status SCI_SUCCESS on any valid event notification SCI_FAILURE on any
  901. * unexpected event notifation
  902. */
  903. static enum sci_status scic_sds_phy_starting_substate_await_sig_fis_event_handler(
  904. struct scic_sds_phy *sci_phy, u32 event_code)
  905. {
  906. u32 result = SCI_SUCCESS;
  907. switch (scu_get_event_code(event_code)) {
  908. case SCU_EVENT_SATA_PHY_DETECTED:
  909. /* Backup the state machine */
  910. sci_base_state_machine_change_state(&sci_phy->state_machine,
  911. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN);
  912. break;
  913. case SCU_EVENT_LINK_FAILURE:
  914. /* Link failure change state back to the starting state */
  915. scic_sds_phy_restart_starting_state(sci_phy);
  916. break;
  917. default:
  918. dev_warn(sciphy_to_dev(sci_phy),
  919. "%s: PHY starting substate machine received "
  920. "unexpected event_code %x\n",
  921. __func__,
  922. event_code);
  923. result = SCI_FAILURE;
  924. break;
  925. }
  926. return result;
  927. }
  928. /*
  929. * *****************************************************************************
  930. * * SCIC SDS PHY FRAME_HANDLERS
  931. * ***************************************************************************** */
  932. /**
  933. *
  934. * @phy: This is struct scic_sds_phy object which is being requested to decode the
  935. * frame data.
  936. * @frame_index: This is the index of the unsolicited frame which was received
  937. * for this phy.
  938. *
  939. * This method decodes the unsolicited frame when the struct scic_sds_phy is in the
  940. * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. - Get the UF Header - If the UF
  941. * is an IAF - Copy IAF data to local phy object IAF data buffer. - Change
  942. * starting substate to wait power. - else - log warning message of unexpected
  943. * unsolicted frame - release frame buffer enum sci_status SCI_SUCCESS
  944. */
  945. static enum sci_status scic_sds_phy_starting_substate_await_iaf_uf_frame_handler(
  946. struct scic_sds_phy *sci_phy, u32 frame_index)
  947. {
  948. enum sci_status result;
  949. u32 *frame_words;
  950. struct sas_identify_frame iaf;
  951. struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
  952. result = scic_sds_unsolicited_frame_control_get_header(
  953. &(scic_sds_phy_get_controller(sci_phy)->uf_control),
  954. frame_index,
  955. (void **)&frame_words);
  956. if (result != SCI_SUCCESS)
  957. return result;
  958. sci_swab32_cpy(&iaf, frame_words, sizeof(iaf) / sizeof(u32));
  959. if (iaf.frame_type == 0) {
  960. u32 state;
  961. memcpy(&iphy->frame_rcvd.iaf, &iaf, sizeof(iaf));
  962. if (iaf.smp_tport) {
  963. /* We got the IAF for an expander PHY go to the final
  964. * state since there are no power requirements for
  965. * expander phys.
  966. */
  967. state = SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL;
  968. } else {
  969. /* We got the IAF we can now go to the await spinup
  970. * semaphore state
  971. */
  972. state = SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER;
  973. }
  974. sci_base_state_machine_change_state(
  975. &sci_phy->state_machine,
  976. state);
  977. result = SCI_SUCCESS;
  978. } else
  979. dev_warn(sciphy_to_dev(sci_phy),
  980. "%s: PHY starting substate machine received "
  981. "unexpected frame id %x\n",
  982. __func__,
  983. frame_index);
  984. scic_sds_controller_release_frame(scic_sds_phy_get_controller(sci_phy),
  985. frame_index);
  986. return result;
  987. }
  988. /**
  989. *
  990. * @phy: This is struct scic_sds_phy object which is being requested to decode the
  991. * frame data.
  992. * @frame_index: This is the index of the unsolicited frame which was received
  993. * for this phy.
  994. *
  995. * This method decodes the unsolicited frame when the struct scic_sds_phy is in the
  996. * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Get the UF Header - If
  997. * the UF is an SIGNATURE FIS - Copy IAF data to local phy object SIGNATURE FIS
  998. * data buffer. - else - log warning message of unexpected unsolicted frame -
  999. * release frame buffer enum sci_status SCI_SUCCESS Must decode the SIGNATURE FIS
  1000. * data
  1001. */
  1002. static enum sci_status scic_sds_phy_starting_substate_await_sig_fis_frame_handler(
  1003. struct scic_sds_phy *sci_phy,
  1004. u32 frame_index)
  1005. {
  1006. enum sci_status result;
  1007. struct dev_to_host_fis *frame_header;
  1008. u32 *fis_frame_data;
  1009. struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
  1010. result = scic_sds_unsolicited_frame_control_get_header(
  1011. &(scic_sds_phy_get_controller(sci_phy)->uf_control),
  1012. frame_index,
  1013. (void **)&frame_header);
  1014. if (result != SCI_SUCCESS)
  1015. return result;
  1016. if ((frame_header->fis_type == FIS_REGD2H) &&
  1017. !(frame_header->status & ATA_BUSY)) {
  1018. scic_sds_unsolicited_frame_control_get_buffer(
  1019. &(scic_sds_phy_get_controller(sci_phy)->uf_control),
  1020. frame_index,
  1021. (void **)&fis_frame_data);
  1022. scic_sds_controller_copy_sata_response(&iphy->frame_rcvd.fis,
  1023. frame_header,
  1024. fis_frame_data);
  1025. /* got IAF we can now go to the await spinup semaphore state */
  1026. sci_base_state_machine_change_state(&sci_phy->state_machine,
  1027. SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL);
  1028. result = SCI_SUCCESS;
  1029. } else
  1030. dev_warn(sciphy_to_dev(sci_phy),
  1031. "%s: PHY starting substate machine received "
  1032. "unexpected frame id %x\n",
  1033. __func__,
  1034. frame_index);
  1035. /* Regardless of the result we are done with this frame with it */
  1036. scic_sds_controller_release_frame(scic_sds_phy_get_controller(sci_phy),
  1037. frame_index);
  1038. return result;
  1039. }
  1040. /*
  1041. * *****************************************************************************
  1042. * * SCIC SDS PHY POWER_HANDLERS
  1043. * ***************************************************************************** */
  1044. /*
  1045. * This method is called by the struct scic_sds_controller when the phy object is
  1046. * granted power. - The notify enable spinups are turned on for this phy object
  1047. * - The phy state machine is transitioned to the
  1048. * SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL. enum sci_status SCI_SUCCESS
  1049. */
  1050. static enum sci_status scic_sds_phy_starting_substate_await_sas_power_consume_power_handler(
  1051. struct scic_sds_phy *sci_phy)
  1052. {
  1053. u32 enable_spinup;
  1054. enable_spinup = readl(&sci_phy->link_layer_registers->notify_enable_spinup_control);
  1055. enable_spinup |= SCU_ENSPINUP_GEN_BIT(ENABLE);
  1056. writel(enable_spinup, &sci_phy->link_layer_registers->notify_enable_spinup_control);
  1057. /* Change state to the final state this substate machine has run to completion */
  1058. sci_base_state_machine_change_state(&sci_phy->state_machine,
  1059. SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL);
  1060. return SCI_SUCCESS;
  1061. }
  1062. /*
  1063. * This method is called by the struct scic_sds_controller when the phy object is
  1064. * granted power. - The phy state machine is transitioned to the
  1065. * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. enum sci_status SCI_SUCCESS
  1066. */
  1067. static enum sci_status scic_sds_phy_starting_substate_await_sata_power_consume_power_handler(
  1068. struct scic_sds_phy *sci_phy)
  1069. {
  1070. u32 scu_sas_pcfg_value;
  1071. /* Release the spinup hold state and reset the OOB state machine */
  1072. scu_sas_pcfg_value =
  1073. readl(&sci_phy->link_layer_registers->phy_configuration);
  1074. scu_sas_pcfg_value &=
  1075. ~(SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD) | SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE));
  1076. scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
  1077. writel(scu_sas_pcfg_value,
  1078. &sci_phy->link_layer_registers->phy_configuration);
  1079. /* Now restart the OOB operation */
  1080. scu_sas_pcfg_value &= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
  1081. scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
  1082. writel(scu_sas_pcfg_value,
  1083. &sci_phy->link_layer_registers->phy_configuration);
  1084. /* Change state to the final state this substate machine has run to completion */
  1085. sci_base_state_machine_change_state(&sci_phy->state_machine,
  1086. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN);
  1087. return SCI_SUCCESS;
  1088. }
  1089. static enum sci_status default_phy_handler(struct scic_sds_phy *sci_phy,
  1090. const char *func)
  1091. {
  1092. dev_dbg(sciphy_to_dev(sci_phy),
  1093. "%s: in wrong state: %d\n", func,
  1094. sci_base_state_machine_get_state(&sci_phy->state_machine));
  1095. return SCI_FAILURE_INVALID_STATE;
  1096. }
  1097. static enum sci_status
  1098. scic_sds_phy_default_reset_handler(struct scic_sds_phy *sci_phy)
  1099. {
  1100. return default_phy_handler(sci_phy, __func__);
  1101. }
  1102. static enum sci_status
  1103. scic_sds_phy_default_destroy_handler(struct scic_sds_phy *sci_phy)
  1104. {
  1105. return default_phy_handler(sci_phy, __func__);
  1106. }
  1107. static enum sci_status
  1108. scic_sds_phy_default_frame_handler(struct scic_sds_phy *sci_phy,
  1109. u32 frame_index)
  1110. {
  1111. struct scic_sds_controller *scic = scic_sds_phy_get_controller(sci_phy);
  1112. default_phy_handler(sci_phy, __func__);
  1113. scic_sds_controller_release_frame(scic, frame_index);
  1114. return SCI_FAILURE_INVALID_STATE;
  1115. }
  1116. static enum sci_status
  1117. scic_sds_phy_default_event_handler(struct scic_sds_phy *sci_phy,
  1118. u32 event_code)
  1119. {
  1120. return default_phy_handler(sci_phy, __func__);
  1121. }
  1122. static enum sci_status
  1123. scic_sds_phy_default_consume_power_handler(struct scic_sds_phy *sci_phy)
  1124. {
  1125. return default_phy_handler(sci_phy, __func__);
  1126. }
  1127. static enum sci_status
  1128. scic_sds_phy_stopped_state_destroy_handler(struct scic_sds_phy *sci_phy)
  1129. {
  1130. return SCI_SUCCESS;
  1131. }
  1132. static enum sci_status
  1133. scic_sds_phy_ready_state_reset_handler(struct scic_sds_phy *sci_phy)
  1134. {
  1135. sci_base_state_machine_change_state(&sci_phy->state_machine,
  1136. SCI_BASE_PHY_STATE_RESETTING);
  1137. return SCI_SUCCESS;
  1138. }
  1139. /**
  1140. * scic_sds_phy_ready_state_event_handler -
  1141. * @phy: This is the struct scic_sds_phy object which has received the event.
  1142. *
  1143. * This method request the struct scic_sds_phy handle the received event. The only
  1144. * event that we are interested in while in the ready state is the link failure
  1145. * event. - decoded event is a link failure - transition the struct scic_sds_phy back
  1146. * to the SCI_BASE_PHY_STATE_STARTING state. - any other event received will
  1147. * report a warning message enum sci_status SCI_SUCCESS if the event received is a
  1148. * link failure SCI_FAILURE_INVALID_STATE for any other event received.
  1149. */
  1150. static enum sci_status scic_sds_phy_ready_state_event_handler(struct scic_sds_phy *sci_phy,
  1151. u32 event_code)
  1152. {
  1153. enum sci_status result = SCI_FAILURE;
  1154. switch (scu_get_event_code(event_code)) {
  1155. case SCU_EVENT_LINK_FAILURE:
  1156. /* Link failure change state back to the starting state */
  1157. sci_base_state_machine_change_state(&sci_phy->state_machine,
  1158. SCI_BASE_PHY_STATE_STARTING);
  1159. result = SCI_SUCCESS;
  1160. break;
  1161. case SCU_EVENT_BROADCAST_CHANGE:
  1162. /* Broadcast change received. Notify the port. */
  1163. if (scic_sds_phy_get_port(sci_phy) != NULL)
  1164. scic_sds_port_broadcast_change_received(sci_phy->owning_port, sci_phy);
  1165. else
  1166. sci_phy->bcn_received_while_port_unassigned = true;
  1167. break;
  1168. default:
  1169. dev_warn(sciphy_to_dev(sci_phy),
  1170. "%sP SCIC PHY 0x%p ready state machine received "
  1171. "unexpected event_code %x\n",
  1172. __func__, sci_phy, event_code);
  1173. result = SCI_FAILURE_INVALID_STATE;
  1174. break;
  1175. }
  1176. return result;
  1177. }
  1178. static enum sci_status scic_sds_phy_resetting_state_event_handler(struct scic_sds_phy *sci_phy,
  1179. u32 event_code)
  1180. {
  1181. enum sci_status result = SCI_FAILURE;
  1182. switch (scu_get_event_code(event_code)) {
  1183. case SCU_EVENT_HARD_RESET_TRANSMITTED:
  1184. /* Link failure change state back to the starting state */
  1185. sci_base_state_machine_change_state(&sci_phy->state_machine,
  1186. SCI_BASE_PHY_STATE_STARTING);
  1187. result = SCI_SUCCESS;
  1188. break;
  1189. default:
  1190. dev_warn(sciphy_to_dev(sci_phy),
  1191. "%s: SCIC PHY 0x%p resetting state machine received "
  1192. "unexpected event_code %x\n",
  1193. __func__, sci_phy, event_code);
  1194. result = SCI_FAILURE_INVALID_STATE;
  1195. break;
  1196. }
  1197. return result;
  1198. }
  1199. /* --------------------------------------------------------------------------- */
  1200. static const struct scic_sds_phy_state_handler scic_sds_phy_state_handler_table[] = {
  1201. [SCI_BASE_PHY_STATE_INITIAL] = {
  1202. .reset_handler = scic_sds_phy_default_reset_handler,
  1203. .destruct_handler = scic_sds_phy_default_destroy_handler,
  1204. .frame_handler = scic_sds_phy_default_frame_handler,
  1205. .event_handler = scic_sds_phy_default_event_handler,
  1206. .consume_power_handler = scic_sds_phy_default_consume_power_handler
  1207. },
  1208. [SCI_BASE_PHY_STATE_STOPPED] = {
  1209. .reset_handler = scic_sds_phy_default_reset_handler,
  1210. .destruct_handler = scic_sds_phy_stopped_state_destroy_handler,
  1211. .frame_handler = scic_sds_phy_default_frame_handler,
  1212. .event_handler = scic_sds_phy_default_event_handler,
  1213. .consume_power_handler = scic_sds_phy_default_consume_power_handler
  1214. },
  1215. [SCI_BASE_PHY_STATE_STARTING] = {
  1216. .reset_handler = scic_sds_phy_default_reset_handler,
  1217. .destruct_handler = scic_sds_phy_default_destroy_handler,
  1218. .frame_handler = scic_sds_phy_default_frame_handler,
  1219. .event_handler = scic_sds_phy_default_event_handler,
  1220. .consume_power_handler = scic_sds_phy_default_consume_power_handler
  1221. },
  1222. [SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL] = {
  1223. .reset_handler = scic_sds_phy_default_reset_handler,
  1224. .destruct_handler = scic_sds_phy_default_destroy_handler,
  1225. .frame_handler = scic_sds_phy_default_frame_handler,
  1226. .event_handler = scic_sds_phy_default_event_handler,
  1227. .consume_power_handler = scic_sds_phy_default_consume_power_handler
  1228. },
  1229. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN] = {
  1230. .reset_handler = scic_sds_phy_default_reset_handler,
  1231. .destruct_handler = scic_sds_phy_default_destroy_handler,
  1232. .frame_handler = scic_sds_phy_default_frame_handler,
  1233. .event_handler = scic_sds_phy_starting_substate_await_ossp_event_handler,
  1234. .consume_power_handler = scic_sds_phy_default_consume_power_handler
  1235. },
  1236. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN] = {
  1237. .reset_handler = scic_sds_phy_default_reset_handler,
  1238. .destruct_handler = scic_sds_phy_default_destroy_handler,
  1239. .frame_handler = scic_sds_phy_default_frame_handler,
  1240. .event_handler = scic_sds_phy_starting_substate_await_sas_phy_speed_event_handler,
  1241. .consume_power_handler = scic_sds_phy_default_consume_power_handler
  1242. },
  1243. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF] = {
  1244. .reset_handler = scic_sds_phy_default_reset_handler,
  1245. .destruct_handler = scic_sds_phy_default_destroy_handler,
  1246. .frame_handler = scic_sds_phy_starting_substate_await_iaf_uf_frame_handler,
  1247. .event_handler = scic_sds_phy_starting_substate_await_iaf_uf_event_handler,
  1248. .consume_power_handler = scic_sds_phy_default_consume_power_handler
  1249. },
  1250. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER] = {
  1251. .reset_handler = scic_sds_phy_default_reset_handler,
  1252. .destruct_handler = scic_sds_phy_default_destroy_handler,
  1253. .frame_handler = scic_sds_phy_default_frame_handler,
  1254. .event_handler = scic_sds_phy_starting_substate_await_sas_power_event_handler,
  1255. .consume_power_handler = scic_sds_phy_starting_substate_await_sas_power_consume_power_handler
  1256. },
  1257. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER] = {
  1258. .reset_handler = scic_sds_phy_default_reset_handler,
  1259. .destruct_handler = scic_sds_phy_default_destroy_handler,
  1260. .frame_handler = scic_sds_phy_default_frame_handler,
  1261. .event_handler = scic_sds_phy_starting_substate_await_sata_power_event_handler,
  1262. .consume_power_handler = scic_sds_phy_starting_substate_await_sata_power_consume_power_handler
  1263. },
  1264. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN] = {
  1265. .reset_handler = scic_sds_phy_default_reset_handler,
  1266. .destruct_handler = scic_sds_phy_default_destroy_handler,
  1267. .frame_handler = scic_sds_phy_default_frame_handler,
  1268. .event_handler = scic_sds_phy_starting_substate_await_sata_phy_event_handler,
  1269. .consume_power_handler = scic_sds_phy_default_consume_power_handler
  1270. },
  1271. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN] = {
  1272. .reset_handler = scic_sds_phy_default_reset_handler,
  1273. .destruct_handler = scic_sds_phy_default_destroy_handler,
  1274. .frame_handler = scic_sds_phy_default_frame_handler,
  1275. .event_handler = scic_sds_phy_starting_substate_await_sata_speed_event_handler,
  1276. .consume_power_handler = scic_sds_phy_default_consume_power_handler
  1277. },
  1278. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF] = {
  1279. .reset_handler = scic_sds_phy_default_reset_handler,
  1280. .destruct_handler = scic_sds_phy_default_destroy_handler,
  1281. .frame_handler = scic_sds_phy_starting_substate_await_sig_fis_frame_handler,
  1282. .event_handler = scic_sds_phy_starting_substate_await_sig_fis_event_handler,
  1283. .consume_power_handler = scic_sds_phy_default_consume_power_handler
  1284. },
  1285. [SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL] = {
  1286. .reset_handler = scic_sds_phy_default_reset_handler,
  1287. .destruct_handler = scic_sds_phy_default_destroy_handler,
  1288. .frame_handler = scic_sds_phy_default_frame_handler,
  1289. .event_handler = scic_sds_phy_default_event_handler,
  1290. .consume_power_handler = scic_sds_phy_default_consume_power_handler
  1291. },
  1292. [SCI_BASE_PHY_STATE_READY] = {
  1293. .reset_handler = scic_sds_phy_ready_state_reset_handler,
  1294. .destruct_handler = scic_sds_phy_default_destroy_handler,
  1295. .frame_handler = scic_sds_phy_default_frame_handler,
  1296. .event_handler = scic_sds_phy_ready_state_event_handler,
  1297. .consume_power_handler = scic_sds_phy_default_consume_power_handler
  1298. },
  1299. [SCI_BASE_PHY_STATE_RESETTING] = {
  1300. .reset_handler = scic_sds_phy_default_reset_handler,
  1301. .destruct_handler = scic_sds_phy_default_destroy_handler,
  1302. .frame_handler = scic_sds_phy_default_frame_handler,
  1303. .event_handler = scic_sds_phy_resetting_state_event_handler,
  1304. .consume_power_handler = scic_sds_phy_default_consume_power_handler
  1305. },
  1306. [SCI_BASE_PHY_STATE_FINAL] = {
  1307. .reset_handler = scic_sds_phy_default_reset_handler,
  1308. .destruct_handler = scic_sds_phy_default_destroy_handler,
  1309. .frame_handler = scic_sds_phy_default_frame_handler,
  1310. .event_handler = scic_sds_phy_default_event_handler,
  1311. .consume_power_handler = scic_sds_phy_default_consume_power_handler
  1312. }
  1313. };
  1314. /*
  1315. * ****************************************************************************
  1316. * * PHY STARTING SUBSTATE METHODS
  1317. * **************************************************************************** */
  1318. /**
  1319. * scic_sds_phy_starting_initial_substate_enter -
  1320. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1321. *
  1322. * This method will perform the actions required by the struct scic_sds_phy on
  1323. * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL. - The initial state
  1324. * handlers are put in place for the struct scic_sds_phy object. - The state is
  1325. * changed to the wait phy type event notification. none
  1326. */
  1327. static void scic_sds_phy_starting_initial_substate_enter(void *object)
  1328. {
  1329. struct scic_sds_phy *sci_phy = object;
  1330. scic_sds_phy_set_base_state_handlers(
  1331. sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL);
  1332. /* This is just an temporary state go off to the starting state */
  1333. sci_base_state_machine_change_state(&sci_phy->state_machine,
  1334. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN);
  1335. }
  1336. /**
  1337. *
  1338. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1339. *
  1340. * This method will perform the actions required by the struct scic_sds_phy on
  1341. * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_PHY_TYPE_EN. - Set the
  1342. * struct scic_sds_phy object state handlers for this state. none
  1343. */
  1344. static void scic_sds_phy_starting_await_ossp_en_substate_enter(void *object)
  1345. {
  1346. struct scic_sds_phy *sci_phy = object;
  1347. scic_sds_phy_set_base_state_handlers(
  1348. sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN
  1349. );
  1350. }
  1351. /**
  1352. *
  1353. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1354. *
  1355. * This method will perform the actions required by the struct scic_sds_phy on
  1356. * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. - Set the
  1357. * struct scic_sds_phy object state handlers for this state. none
  1358. */
  1359. static void scic_sds_phy_starting_await_sas_speed_en_substate_enter(
  1360. void *object)
  1361. {
  1362. struct scic_sds_phy *sci_phy = object;
  1363. scic_sds_phy_set_base_state_handlers(
  1364. sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
  1365. );
  1366. }
  1367. /**
  1368. *
  1369. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1370. *
  1371. * This method will perform the actions required by the struct scic_sds_phy on
  1372. * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. - Set the
  1373. * struct scic_sds_phy object state handlers for this state. none
  1374. */
  1375. static void scic_sds_phy_starting_await_iaf_uf_substate_enter(void *object)
  1376. {
  1377. struct scic_sds_phy *sci_phy = object;
  1378. scic_sds_phy_set_base_state_handlers(
  1379. sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
  1380. );
  1381. }
  1382. /**
  1383. *
  1384. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1385. *
  1386. * This method will perform the actions required by the struct scic_sds_phy on
  1387. * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER. - Set the
  1388. * struct scic_sds_phy object state handlers for this state. - Add this phy object to
  1389. * the power control queue none
  1390. */
  1391. static void scic_sds_phy_starting_await_sas_power_substate_enter(void *object)
  1392. {
  1393. struct scic_sds_phy *sci_phy = object;
  1394. scic_sds_phy_set_base_state_handlers(
  1395. sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER
  1396. );
  1397. scic_sds_controller_power_control_queue_insert(
  1398. scic_sds_phy_get_controller(sci_phy),
  1399. sci_phy
  1400. );
  1401. }
  1402. /**
  1403. *
  1404. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1405. *
  1406. * This method will perform the actions required by the struct scic_sds_phy on exiting
  1407. * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER. - Remove the
  1408. * struct scic_sds_phy object from the power control queue. none
  1409. */
  1410. static void scic_sds_phy_starting_await_sas_power_substate_exit(void *object)
  1411. {
  1412. struct scic_sds_phy *sci_phy = object;
  1413. scic_sds_controller_power_control_queue_remove(
  1414. scic_sds_phy_get_controller(sci_phy), sci_phy
  1415. );
  1416. }
  1417. /**
  1418. *
  1419. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1420. *
  1421. * This method will perform the actions required by the struct scic_sds_phy on
  1422. * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. - Set the
  1423. * struct scic_sds_phy object state handlers for this state. - Add this phy object to
  1424. * the power control queue none
  1425. */
  1426. static void scic_sds_phy_starting_await_sata_power_substate_enter(void *object)
  1427. {
  1428. struct scic_sds_phy *sci_phy = object;
  1429. scic_sds_phy_set_base_state_handlers(
  1430. sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
  1431. );
  1432. scic_sds_controller_power_control_queue_insert(
  1433. scic_sds_phy_get_controller(sci_phy),
  1434. sci_phy
  1435. );
  1436. }
  1437. /**
  1438. *
  1439. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1440. *
  1441. * This method will perform the actions required by the struct scic_sds_phy on exiting
  1442. * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. - Remove the
  1443. * struct scic_sds_phy object from the power control queue. none
  1444. */
  1445. static void scic_sds_phy_starting_await_sata_power_substate_exit(void *object)
  1446. {
  1447. struct scic_sds_phy *sci_phy = object;
  1448. scic_sds_controller_power_control_queue_remove(
  1449. scic_sds_phy_get_controller(sci_phy),
  1450. sci_phy
  1451. );
  1452. }
  1453. /**
  1454. *
  1455. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1456. *
  1457. * This function will perform the actions required by the struct scic_sds_phy on
  1458. * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. - Set the
  1459. * struct scic_sds_phy object state handlers for this state. none
  1460. */
  1461. static void scic_sds_phy_starting_await_sata_phy_substate_enter(void *object)
  1462. {
  1463. struct scic_sds_phy *sci_phy = object;
  1464. scic_sds_phy_set_base_state_handlers(
  1465. sci_phy,
  1466. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN);
  1467. isci_timer_start(sci_phy->sata_timeout_timer,
  1468. SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT);
  1469. }
  1470. /**
  1471. *
  1472. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1473. *
  1474. * This method will perform the actions required by the struct scic_sds_phy
  1475. * on exiting
  1476. * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - stop the timer
  1477. * that was started on entry to await sata phy event notification none
  1478. */
  1479. static inline void scic_sds_phy_starting_await_sata_phy_substate_exit(
  1480. void *object)
  1481. {
  1482. struct scic_sds_phy *sci_phy = object;
  1483. isci_timer_stop(sci_phy->sata_timeout_timer);
  1484. }
  1485. /**
  1486. *
  1487. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1488. *
  1489. * This method will perform the actions required by the struct scic_sds_phy on
  1490. * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - Set the
  1491. * struct scic_sds_phy object state handlers for this state. none
  1492. */
  1493. static void scic_sds_phy_starting_await_sata_speed_substate_enter(void *object)
  1494. {
  1495. struct scic_sds_phy *sci_phy = object;
  1496. scic_sds_phy_set_base_state_handlers(
  1497. sci_phy,
  1498. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN);
  1499. isci_timer_start(sci_phy->sata_timeout_timer,
  1500. SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT);
  1501. }
  1502. /**
  1503. *
  1504. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1505. *
  1506. * This function will perform the actions required by the
  1507. * struct scic_sds_phy on exiting
  1508. * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - stop the timer
  1509. * that was started on entry to await sata phy event notification none
  1510. */
  1511. static inline void scic_sds_phy_starting_await_sata_speed_substate_exit(
  1512. void *object)
  1513. {
  1514. struct scic_sds_phy *sci_phy = object;
  1515. isci_timer_stop(sci_phy->sata_timeout_timer);
  1516. }
  1517. /**
  1518. *
  1519. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1520. *
  1521. * This function will perform the actions required by the struct scic_sds_phy on
  1522. * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Set the
  1523. * struct scic_sds_phy object state handlers for this state.
  1524. * - Start the SIGNATURE FIS
  1525. * timeout timer none
  1526. */
  1527. static void scic_sds_phy_starting_await_sig_fis_uf_substate_enter(void *object)
  1528. {
  1529. bool continue_to_ready_state;
  1530. struct scic_sds_phy *sci_phy = object;
  1531. scic_sds_phy_set_base_state_handlers(
  1532. sci_phy,
  1533. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF);
  1534. continue_to_ready_state = scic_sds_port_link_detected(
  1535. sci_phy->owning_port,
  1536. sci_phy);
  1537. if (continue_to_ready_state) {
  1538. /*
  1539. * Clear the PE suspend condition so we can actually
  1540. * receive SIG FIS
  1541. * The hardware will not respond to the XRDY until the PE
  1542. * suspend condition is cleared.
  1543. */
  1544. scic_sds_phy_resume(sci_phy);
  1545. isci_timer_start(sci_phy->sata_timeout_timer,
  1546. SCIC_SDS_SIGNATURE_FIS_TIMEOUT);
  1547. } else
  1548. sci_phy->is_in_link_training = false;
  1549. }
  1550. /**
  1551. *
  1552. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1553. *
  1554. * This function will perform the actions required by the
  1555. * struct scic_sds_phy on exiting
  1556. * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Stop the SIGNATURE
  1557. * FIS timeout timer. none
  1558. */
  1559. static inline void scic_sds_phy_starting_await_sig_fis_uf_substate_exit(
  1560. void *object)
  1561. {
  1562. struct scic_sds_phy *sci_phy = object;
  1563. isci_timer_stop(sci_phy->sata_timeout_timer);
  1564. }
  1565. /**
  1566. *
  1567. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1568. *
  1569. * This method will perform the actions required by the struct scic_sds_phy on
  1570. * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL. - Set the struct scic_sds_phy
  1571. * object state handlers for this state. - Change base state machine to the
  1572. * ready state. none
  1573. */
  1574. static void scic_sds_phy_starting_final_substate_enter(void *object)
  1575. {
  1576. struct scic_sds_phy *sci_phy = object;
  1577. scic_sds_phy_set_base_state_handlers(sci_phy,
  1578. SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL);
  1579. /* State machine has run to completion so exit out and change
  1580. * the base state machine to the ready state
  1581. */
  1582. sci_base_state_machine_change_state(&sci_phy->state_machine,
  1583. SCI_BASE_PHY_STATE_READY);
  1584. }
  1585. /*
  1586. * ****************************************************************************
  1587. * * PHY STATE PRIVATE METHODS
  1588. * **************************************************************************** */
  1589. /**
  1590. *
  1591. * @sci_phy: This is the struct scic_sds_phy object to stop.
  1592. *
  1593. * This method will stop the struct scic_sds_phy object. This does not reset the
  1594. * protocol engine it just suspends it and places it in a state where it will
  1595. * not cause the end device to power up. none
  1596. */
  1597. static void scu_link_layer_stop_protocol_engine(
  1598. struct scic_sds_phy *sci_phy)
  1599. {
  1600. u32 scu_sas_pcfg_value;
  1601. u32 enable_spinup_value;
  1602. /* Suspend the protocol engine and place it in a sata spinup hold state */
  1603. scu_sas_pcfg_value =
  1604. readl(&sci_phy->link_layer_registers->phy_configuration);
  1605. scu_sas_pcfg_value |=
  1606. (SCU_SAS_PCFG_GEN_BIT(OOB_RESET) |
  1607. SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE) |
  1608. SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD));
  1609. writel(scu_sas_pcfg_value,
  1610. &sci_phy->link_layer_registers->phy_configuration);
  1611. /* Disable the notify enable spinup primitives */
  1612. enable_spinup_value = readl(&sci_phy->link_layer_registers->notify_enable_spinup_control);
  1613. enable_spinup_value &= ~SCU_ENSPINUP_GEN_BIT(ENABLE);
  1614. writel(enable_spinup_value, &sci_phy->link_layer_registers->notify_enable_spinup_control);
  1615. }
  1616. /**
  1617. *
  1618. *
  1619. * This method will start the OOB/SN state machine for this struct scic_sds_phy object.
  1620. */
  1621. static void scu_link_layer_start_oob(
  1622. struct scic_sds_phy *sci_phy)
  1623. {
  1624. u32 scu_sas_pcfg_value;
  1625. scu_sas_pcfg_value =
  1626. readl(&sci_phy->link_layer_registers->phy_configuration);
  1627. scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
  1628. scu_sas_pcfg_value &=
  1629. ~(SCU_SAS_PCFG_GEN_BIT(OOB_RESET) |
  1630. SCU_SAS_PCFG_GEN_BIT(HARD_RESET));
  1631. writel(scu_sas_pcfg_value,
  1632. &sci_phy->link_layer_registers->phy_configuration);
  1633. }
  1634. /**
  1635. *
  1636. *
  1637. * This method will transmit a hard reset request on the specified phy. The SCU
  1638. * hardware requires that we reset the OOB state machine and set the hard reset
  1639. * bit in the phy configuration register. We then must start OOB over with the
  1640. * hard reset bit set.
  1641. */
  1642. static void scu_link_layer_tx_hard_reset(
  1643. struct scic_sds_phy *sci_phy)
  1644. {
  1645. u32 phy_configuration_value;
  1646. /*
  1647. * SAS Phys must wait for the HARD_RESET_TX event notification to transition
  1648. * to the starting state. */
  1649. phy_configuration_value =
  1650. readl(&sci_phy->link_layer_registers->phy_configuration);
  1651. phy_configuration_value |=
  1652. (SCU_SAS_PCFG_GEN_BIT(HARD_RESET) |
  1653. SCU_SAS_PCFG_GEN_BIT(OOB_RESET));
  1654. writel(phy_configuration_value,
  1655. &sci_phy->link_layer_registers->phy_configuration);
  1656. /* Now take the OOB state machine out of reset */
  1657. phy_configuration_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
  1658. phy_configuration_value &= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
  1659. writel(phy_configuration_value,
  1660. &sci_phy->link_layer_registers->phy_configuration);
  1661. }
  1662. /*
  1663. * ****************************************************************************
  1664. * * PHY BASE STATE METHODS
  1665. * **************************************************************************** */
  1666. /**
  1667. *
  1668. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1669. *
  1670. * This method will perform the actions required by the struct scic_sds_phy on
  1671. * entering the SCI_BASE_PHY_STATE_INITIAL. - This function sets the state
  1672. * handlers for the phy object base state machine initial state. none
  1673. */
  1674. static void scic_sds_phy_initial_state_enter(void *object)
  1675. {
  1676. struct scic_sds_phy *sci_phy = object;
  1677. scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_INITIAL);
  1678. }
  1679. /**
  1680. *
  1681. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1682. *
  1683. * This function will perform the actions required by the struct scic_sds_phy on
  1684. * entering the SCI_BASE_PHY_STATE_INITIAL. - This function sets the state
  1685. * handlers for the phy object base state machine initial state. - The SCU
  1686. * hardware is requested to stop the protocol engine. none
  1687. */
  1688. static void scic_sds_phy_stopped_state_enter(void *object)
  1689. {
  1690. struct scic_sds_phy *sci_phy = object;
  1691. struct scic_sds_controller *scic = scic_sds_phy_get_controller(sci_phy);
  1692. struct isci_host *ihost = scic_to_ihost(scic);
  1693. /*
  1694. * @todo We need to get to the controller to place this PE in a
  1695. * reset state
  1696. */
  1697. scic_sds_phy_set_base_state_handlers(sci_phy,
  1698. SCI_BASE_PHY_STATE_STOPPED);
  1699. if (sci_phy->sata_timeout_timer != NULL) {
  1700. isci_del_timer(ihost, sci_phy->sata_timeout_timer);
  1701. sci_phy->sata_timeout_timer = NULL;
  1702. }
  1703. scu_link_layer_stop_protocol_engine(sci_phy);
  1704. if (sci_phy->state_machine.previous_state_id !=
  1705. SCI_BASE_PHY_STATE_INITIAL)
  1706. scic_sds_controller_link_down(
  1707. scic_sds_phy_get_controller(sci_phy),
  1708. scic_sds_phy_get_port(sci_phy),
  1709. sci_phy);
  1710. }
  1711. /**
  1712. *
  1713. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1714. *
  1715. * This method will perform the actions required by the struct scic_sds_phy on
  1716. * entering the SCI_BASE_PHY_STATE_STARTING. - This function sets the state
  1717. * handlers for the phy object base state machine starting state. - The SCU
  1718. * hardware is requested to start OOB/SN on this protocl engine. - The phy
  1719. * starting substate machine is started. - If the previous state was the ready
  1720. * state then the struct scic_sds_controller is informed that the phy has gone link
  1721. * down. none
  1722. */
  1723. static void scic_sds_phy_starting_state_enter(void *object)
  1724. {
  1725. struct scic_sds_phy *sci_phy = object;
  1726. scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_STARTING);
  1727. scu_link_layer_stop_protocol_engine(sci_phy);
  1728. scu_link_layer_start_oob(sci_phy);
  1729. /* We don't know what kind of phy we are going to be just yet */
  1730. sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_UNKNOWN;
  1731. sci_phy->bcn_received_while_port_unassigned = false;
  1732. if (sci_phy->state_machine.previous_state_id
  1733. == SCI_BASE_PHY_STATE_READY) {
  1734. scic_sds_controller_link_down(
  1735. scic_sds_phy_get_controller(sci_phy),
  1736. scic_sds_phy_get_port(sci_phy),
  1737. sci_phy
  1738. );
  1739. }
  1740. sci_base_state_machine_change_state(&sci_phy->state_machine,
  1741. SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL);
  1742. }
  1743. /**
  1744. *
  1745. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1746. *
  1747. * This method will perform the actions required by the struct scic_sds_phy on
  1748. * entering the SCI_BASE_PHY_STATE_READY. - This function sets the state
  1749. * handlers for the phy object base state machine ready state. - The SCU
  1750. * hardware protocol engine is resumed. - The struct scic_sds_controller is informed
  1751. * that the phy object has gone link up. none
  1752. */
  1753. static void scic_sds_phy_ready_state_enter(void *object)
  1754. {
  1755. struct scic_sds_phy *sci_phy = object;
  1756. scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_READY);
  1757. scic_sds_controller_link_up(
  1758. scic_sds_phy_get_controller(sci_phy),
  1759. scic_sds_phy_get_port(sci_phy),
  1760. sci_phy
  1761. );
  1762. }
  1763. /**
  1764. *
  1765. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1766. *
  1767. * This method will perform the actions required by the struct scic_sds_phy on exiting
  1768. * the SCI_BASE_PHY_STATE_INITIAL. This function suspends the SCU hardware
  1769. * protocol engine represented by this struct scic_sds_phy object. none
  1770. */
  1771. static void scic_sds_phy_ready_state_exit(void *object)
  1772. {
  1773. struct scic_sds_phy *sci_phy = object;
  1774. scic_sds_phy_suspend(sci_phy);
  1775. }
  1776. /**
  1777. *
  1778. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1779. *
  1780. * This method will perform the actions required by the struct scic_sds_phy on
  1781. * entering the SCI_BASE_PHY_STATE_RESETTING. - This function sets the state
  1782. * handlers for the phy object base state machine resetting state. none
  1783. */
  1784. static void scic_sds_phy_resetting_state_enter(void *object)
  1785. {
  1786. struct scic_sds_phy *sci_phy = object;
  1787. scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_RESETTING);
  1788. /*
  1789. * The phy is being reset, therefore deactivate it from the port.
  1790. * In the resetting state we don't notify the user regarding
  1791. * link up and link down notifications. */
  1792. scic_sds_port_deactivate_phy(sci_phy->owning_port, sci_phy, false);
  1793. if (sci_phy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) {
  1794. scu_link_layer_tx_hard_reset(sci_phy);
  1795. } else {
  1796. /*
  1797. * The SCU does not need to have a discrete reset state so
  1798. * just go back to the starting state.
  1799. */
  1800. sci_base_state_machine_change_state(
  1801. &sci_phy->state_machine,
  1802. SCI_BASE_PHY_STATE_STARTING);
  1803. }
  1804. }
  1805. /**
  1806. *
  1807. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1808. *
  1809. * This method will perform the actions required by the struct scic_sds_phy on
  1810. * entering the SCI_BASE_PHY_STATE_FINAL. - This function sets the state
  1811. * handlers for the phy object base state machine final state. none
  1812. */
  1813. static void scic_sds_phy_final_state_enter(void *object)
  1814. {
  1815. struct scic_sds_phy *sci_phy = object;
  1816. scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_FINAL);
  1817. /* Nothing to do here */
  1818. }
  1819. /* --------------------------------------------------------------------------- */
  1820. static const struct sci_base_state scic_sds_phy_state_table[] = {
  1821. [SCI_BASE_PHY_STATE_INITIAL] = {
  1822. .enter_state = scic_sds_phy_initial_state_enter,
  1823. },
  1824. [SCI_BASE_PHY_STATE_STOPPED] = {
  1825. .enter_state = scic_sds_phy_stopped_state_enter,
  1826. },
  1827. [SCI_BASE_PHY_STATE_STARTING] = {
  1828. .enter_state = scic_sds_phy_starting_state_enter,
  1829. },
  1830. [SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL] = {
  1831. .enter_state = scic_sds_phy_starting_initial_substate_enter,
  1832. },
  1833. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN] = {
  1834. .enter_state = scic_sds_phy_starting_await_ossp_en_substate_enter,
  1835. },
  1836. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN] = {
  1837. .enter_state = scic_sds_phy_starting_await_sas_speed_en_substate_enter,
  1838. },
  1839. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF] = {
  1840. .enter_state = scic_sds_phy_starting_await_iaf_uf_substate_enter,
  1841. },
  1842. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER] = {
  1843. .enter_state = scic_sds_phy_starting_await_sas_power_substate_enter,
  1844. .exit_state = scic_sds_phy_starting_await_sas_power_substate_exit,
  1845. },
  1846. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER] = {
  1847. .enter_state = scic_sds_phy_starting_await_sata_power_substate_enter,
  1848. .exit_state = scic_sds_phy_starting_await_sata_power_substate_exit
  1849. },
  1850. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN] = {
  1851. .enter_state = scic_sds_phy_starting_await_sata_phy_substate_enter,
  1852. .exit_state = scic_sds_phy_starting_await_sata_phy_substate_exit
  1853. },
  1854. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN] = {
  1855. .enter_state = scic_sds_phy_starting_await_sata_speed_substate_enter,
  1856. .exit_state = scic_sds_phy_starting_await_sata_speed_substate_exit
  1857. },
  1858. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF] = {
  1859. .enter_state = scic_sds_phy_starting_await_sig_fis_uf_substate_enter,
  1860. .exit_state = scic_sds_phy_starting_await_sig_fis_uf_substate_exit
  1861. },
  1862. [SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL] = {
  1863. .enter_state = scic_sds_phy_starting_final_substate_enter,
  1864. },
  1865. [SCI_BASE_PHY_STATE_READY] = {
  1866. .enter_state = scic_sds_phy_ready_state_enter,
  1867. .exit_state = scic_sds_phy_ready_state_exit,
  1868. },
  1869. [SCI_BASE_PHY_STATE_RESETTING] = {
  1870. .enter_state = scic_sds_phy_resetting_state_enter,
  1871. },
  1872. [SCI_BASE_PHY_STATE_FINAL] = {
  1873. .enter_state = scic_sds_phy_final_state_enter,
  1874. },
  1875. };
  1876. void scic_sds_phy_construct(struct scic_sds_phy *sci_phy,
  1877. struct scic_sds_port *owning_port, u8 phy_index)
  1878. {
  1879. sci_base_state_machine_construct(&sci_phy->state_machine,
  1880. sci_phy,
  1881. scic_sds_phy_state_table,
  1882. SCI_BASE_PHY_STATE_INITIAL);
  1883. sci_base_state_machine_start(&sci_phy->state_machine);
  1884. /* Copy the rest of the input data to our locals */
  1885. sci_phy->owning_port = owning_port;
  1886. sci_phy->phy_index = phy_index;
  1887. sci_phy->bcn_received_while_port_unassigned = false;
  1888. sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_UNKNOWN;
  1889. sci_phy->link_layer_registers = NULL;
  1890. sci_phy->max_negotiated_speed = SAS_LINK_RATE_UNKNOWN;
  1891. sci_phy->sata_timeout_timer = NULL;
  1892. }
  1893. void isci_phy_init(struct isci_phy *iphy, struct isci_host *ihost, int index)
  1894. {
  1895. union scic_oem_parameters oem;
  1896. u64 sci_sas_addr;
  1897. __be64 sas_addr;
  1898. scic_oem_parameters_get(&ihost->sci, &oem);
  1899. sci_sas_addr = oem.sds1.phys[index].sas_address.high;
  1900. sci_sas_addr <<= 32;
  1901. sci_sas_addr |= oem.sds1.phys[index].sas_address.low;
  1902. sas_addr = cpu_to_be64(sci_sas_addr);
  1903. memcpy(iphy->sas_addr, &sas_addr, sizeof(sas_addr));
  1904. iphy->isci_port = NULL;
  1905. iphy->sas_phy.enabled = 0;
  1906. iphy->sas_phy.id = index;
  1907. iphy->sas_phy.sas_addr = &iphy->sas_addr[0];
  1908. iphy->sas_phy.frame_rcvd = (u8 *)&iphy->frame_rcvd;
  1909. iphy->sas_phy.ha = &ihost->sas_ha;
  1910. iphy->sas_phy.lldd_phy = iphy;
  1911. iphy->sas_phy.enabled = 1;
  1912. iphy->sas_phy.class = SAS;
  1913. iphy->sas_phy.iproto = SAS_PROTOCOL_ALL;
  1914. iphy->sas_phy.tproto = 0;
  1915. iphy->sas_phy.type = PHY_TYPE_PHYSICAL;
  1916. iphy->sas_phy.role = PHY_ROLE_INITIATOR;
  1917. iphy->sas_phy.oob_mode = OOB_NOT_CONNECTED;
  1918. iphy->sas_phy.linkrate = SAS_LINK_RATE_UNKNOWN;
  1919. memset(&iphy->frame_rcvd, 0, sizeof(iphy->frame_rcvd));
  1920. }
  1921. /**
  1922. * isci_phy_control() - This function is one of the SAS Domain Template
  1923. * functions. This is a phy management function.
  1924. * @phy: This parameter specifies the sphy being controlled.
  1925. * @func: This parameter specifies the phy control function being invoked.
  1926. * @buf: This parameter is specific to the phy function being invoked.
  1927. *
  1928. * status, zero indicates success.
  1929. */
  1930. int isci_phy_control(struct asd_sas_phy *sas_phy,
  1931. enum phy_func func,
  1932. void *buf)
  1933. {
  1934. int ret = 0;
  1935. struct isci_phy *iphy = sas_phy->lldd_phy;
  1936. struct isci_port *iport = iphy->isci_port;
  1937. struct isci_host *ihost = sas_phy->ha->lldd_ha;
  1938. unsigned long flags;
  1939. dev_dbg(&ihost->pdev->dev,
  1940. "%s: phy %p; func %d; buf %p; isci phy %p, port %p\n",
  1941. __func__, sas_phy, func, buf, iphy, iport);
  1942. switch (func) {
  1943. case PHY_FUNC_DISABLE:
  1944. spin_lock_irqsave(&ihost->scic_lock, flags);
  1945. scic_sds_phy_stop(&iphy->sci);
  1946. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  1947. break;
  1948. case PHY_FUNC_LINK_RESET:
  1949. spin_lock_irqsave(&ihost->scic_lock, flags);
  1950. scic_sds_phy_stop(&iphy->sci);
  1951. scic_sds_phy_start(&iphy->sci);
  1952. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  1953. break;
  1954. case PHY_FUNC_HARD_RESET:
  1955. if (!iport)
  1956. return -ENODEV;
  1957. /* Perform the port reset. */
  1958. ret = isci_port_perform_hard_reset(ihost, iport, iphy);
  1959. break;
  1960. default:
  1961. dev_dbg(&ihost->pdev->dev,
  1962. "%s: phy %p; func %d NOT IMPLEMENTED!\n",
  1963. __func__, sas_phy, func);
  1964. ret = -ENOSYS;
  1965. break;
  1966. }
  1967. return ret;
  1968. }