phy.c 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288
  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. /**
  403. * This method will attempt to stop the phy object.
  404. * @sci_phy:
  405. *
  406. * enum sci_status SCI_SUCCESS if the phy is going to stop SCI_INVALID_STATE
  407. * if the phy is not in a valid state to stop
  408. */
  409. enum sci_status scic_sds_phy_stop(struct scic_sds_phy *sci_phy)
  410. {
  411. return sci_phy->state_handlers->stop_handler(sci_phy);
  412. }
  413. /**
  414. * This method will attempt to reset the phy. This request is only valid when
  415. * the phy is in an ready state
  416. * @sci_phy:
  417. *
  418. * enum sci_status
  419. */
  420. enum sci_status scic_sds_phy_reset(
  421. struct scic_sds_phy *sci_phy)
  422. {
  423. return sci_phy->state_handlers->reset_handler(sci_phy);
  424. }
  425. /**
  426. * This method will process the event code received.
  427. * @sci_phy:
  428. * @event_code:
  429. *
  430. * enum sci_status
  431. */
  432. enum sci_status scic_sds_phy_event_handler(
  433. struct scic_sds_phy *sci_phy,
  434. u32 event_code)
  435. {
  436. return sci_phy->state_handlers->event_handler(sci_phy, event_code);
  437. }
  438. /**
  439. * This method will process the frame index received.
  440. * @sci_phy:
  441. * @frame_index:
  442. *
  443. * enum sci_status
  444. */
  445. enum sci_status scic_sds_phy_frame_handler(
  446. struct scic_sds_phy *sci_phy,
  447. u32 frame_index)
  448. {
  449. return sci_phy->state_handlers->frame_handler(sci_phy, frame_index);
  450. }
  451. /**
  452. * This method will give the phy permission to consume power
  453. * @sci_phy:
  454. *
  455. * enum sci_status
  456. */
  457. enum sci_status scic_sds_phy_consume_power_handler(
  458. struct scic_sds_phy *sci_phy)
  459. {
  460. return sci_phy->state_handlers->consume_power_handler(sci_phy);
  461. }
  462. /*
  463. * *****************************************************************************
  464. * * SCIC SDS PHY HELPER FUNCTIONS
  465. * ***************************************************************************** */
  466. /**
  467. *
  468. * @sci_phy: The phy object that received SAS PHY DETECTED.
  469. *
  470. * This method continues the link training for the phy as if it were a SAS PHY
  471. * instead of a SATA PHY. This is done because the completion queue had a SAS
  472. * PHY DETECTED event when the state machine was expecting a SATA PHY event.
  473. * none
  474. */
  475. static void scic_sds_phy_start_sas_link_training(
  476. struct scic_sds_phy *sci_phy)
  477. {
  478. u32 phy_control;
  479. phy_control =
  480. readl(&sci_phy->link_layer_registers->phy_configuration);
  481. phy_control |= SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD);
  482. writel(phy_control,
  483. &sci_phy->link_layer_registers->phy_configuration);
  484. sci_base_state_machine_change_state(
  485. &sci_phy->state_machine,
  486. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
  487. );
  488. sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SAS;
  489. }
  490. /**
  491. *
  492. * @sci_phy: The phy object that received a SATA SPINUP HOLD event
  493. *
  494. * This method continues the link training for the phy as if it were a SATA PHY
  495. * instead of a SAS PHY. This is done because the completion queue had a SATA
  496. * SPINUP HOLD event when the state machine was expecting a SAS PHY event. none
  497. */
  498. static void scic_sds_phy_start_sata_link_training(
  499. struct scic_sds_phy *sci_phy)
  500. {
  501. sci_base_state_machine_change_state(
  502. &sci_phy->state_machine,
  503. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
  504. );
  505. sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA;
  506. }
  507. /**
  508. * scic_sds_phy_complete_link_training - perform processing common to
  509. * all protocols upon completion of link training.
  510. * @sci_phy: This parameter specifies the phy object for which link training
  511. * has completed.
  512. * @max_link_rate: This parameter specifies the maximum link rate to be
  513. * associated with this phy.
  514. * @next_state: This parameter specifies the next state for the phy's starting
  515. * sub-state machine.
  516. *
  517. */
  518. static void scic_sds_phy_complete_link_training(
  519. struct scic_sds_phy *sci_phy,
  520. enum sas_linkrate max_link_rate,
  521. u32 next_state)
  522. {
  523. sci_phy->max_negotiated_speed = max_link_rate;
  524. sci_base_state_machine_change_state(&sci_phy->state_machine,
  525. next_state);
  526. }
  527. static void scic_sds_phy_restart_starting_state(
  528. struct scic_sds_phy *sci_phy)
  529. {
  530. /* Re-enter the base state machine starting state */
  531. sci_base_state_machine_change_state(&sci_phy->state_machine,
  532. SCI_BASE_PHY_STATE_STARTING);
  533. }
  534. /* ****************************************************************************
  535. * SCIC SDS PHY general handlers
  536. ************************************************************************** */
  537. static enum sci_status scic_sds_phy_starting_substate_general_stop_handler(
  538. struct scic_sds_phy *phy)
  539. {
  540. sci_base_state_machine_change_state(&phy->state_machine,
  541. SCI_BASE_PHY_STATE_STOPPED);
  542. return SCI_SUCCESS;
  543. }
  544. /*
  545. * *****************************************************************************
  546. * * SCIC SDS PHY EVENT_HANDLERS
  547. * ***************************************************************************** */
  548. /**
  549. *
  550. * @phy: This struct scic_sds_phy object which has received an event.
  551. * @event_code: This is the event code which the phy object is to decode.
  552. *
  553. * This method is called when an event notification is received for the phy
  554. * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. -
  555. * decode the event - sas phy detected causes a state transition to the wait
  556. * for speed event notification. - any other events log a warning message and
  557. * set a failure status enum sci_status SCI_SUCCESS on any valid event notification
  558. * SCI_FAILURE on any unexpected event notifation
  559. */
  560. static enum sci_status scic_sds_phy_starting_substate_await_ossp_event_handler(
  561. struct scic_sds_phy *sci_phy,
  562. u32 event_code)
  563. {
  564. u32 result = SCI_SUCCESS;
  565. switch (scu_get_event_code(event_code)) {
  566. case SCU_EVENT_SAS_PHY_DETECTED:
  567. scic_sds_phy_start_sas_link_training(sci_phy);
  568. sci_phy->is_in_link_training = true;
  569. break;
  570. case SCU_EVENT_SATA_SPINUP_HOLD:
  571. scic_sds_phy_start_sata_link_training(sci_phy);
  572. sci_phy->is_in_link_training = true;
  573. break;
  574. default:
  575. dev_dbg(sciphy_to_dev(sci_phy),
  576. "%s: PHY starting substate machine received "
  577. "unexpected event_code %x\n",
  578. __func__,
  579. event_code);
  580. result = SCI_FAILURE;
  581. break;
  582. }
  583. return result;
  584. }
  585. /**
  586. *
  587. * @phy: This struct scic_sds_phy object which has received an event.
  588. * @event_code: This is the event code which the phy object is to decode.
  589. *
  590. * This method is called when an event notification is received for the phy
  591. * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. -
  592. * decode the event - sas phy detected returns us back to this state. - speed
  593. * event detected causes a state transition to the wait for iaf. - identify
  594. * timeout is an un-expected event and the state machine is restarted. - link
  595. * failure events restart the starting state machine - any other events log a
  596. * warning message and set a failure status enum sci_status SCI_SUCCESS on any valid
  597. * event notification SCI_FAILURE on any unexpected event notifation
  598. */
  599. static enum sci_status scic_sds_phy_starting_substate_await_sas_phy_speed_event_handler(
  600. struct scic_sds_phy *sci_phy,
  601. u32 event_code)
  602. {
  603. u32 result = SCI_SUCCESS;
  604. switch (scu_get_event_code(event_code)) {
  605. case SCU_EVENT_SAS_PHY_DETECTED:
  606. /*
  607. * Why is this being reported again by the controller?
  608. * We would re-enter this state so just stay here */
  609. break;
  610. case SCU_EVENT_SAS_15:
  611. case SCU_EVENT_SAS_15_SSC:
  612. scic_sds_phy_complete_link_training(
  613. sci_phy,
  614. SAS_LINK_RATE_1_5_GBPS,
  615. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF);
  616. break;
  617. case SCU_EVENT_SAS_30:
  618. case SCU_EVENT_SAS_30_SSC:
  619. scic_sds_phy_complete_link_training(
  620. sci_phy,
  621. SAS_LINK_RATE_3_0_GBPS,
  622. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF);
  623. break;
  624. case SCU_EVENT_SAS_60:
  625. case SCU_EVENT_SAS_60_SSC:
  626. scic_sds_phy_complete_link_training(
  627. sci_phy,
  628. SAS_LINK_RATE_6_0_GBPS,
  629. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF);
  630. break;
  631. case SCU_EVENT_SATA_SPINUP_HOLD:
  632. /*
  633. * We were doing SAS PHY link training and received a SATA PHY event
  634. * continue OOB/SN as if this were a SATA PHY */
  635. scic_sds_phy_start_sata_link_training(sci_phy);
  636. break;
  637. case SCU_EVENT_LINK_FAILURE:
  638. /* Link failure change state back to the starting state */
  639. scic_sds_phy_restart_starting_state(sci_phy);
  640. break;
  641. default:
  642. dev_warn(sciphy_to_dev(sci_phy),
  643. "%s: PHY starting substate machine received "
  644. "unexpected event_code %x\n",
  645. __func__,
  646. event_code);
  647. result = SCI_FAILURE;
  648. break;
  649. }
  650. return result;
  651. }
  652. /**
  653. *
  654. * @phy: This struct scic_sds_phy object which has received an event.
  655. * @event_code: This is the event code which the phy object is to decode.
  656. *
  657. * This method is called when an event notification is received for the phy
  658. * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. -
  659. * decode the event - sas phy detected event backs up the state machine to the
  660. * await speed notification. - identify timeout is an un-expected event and the
  661. * state machine is restarted. - link failure events restart the starting state
  662. * machine - any other events log a warning message and set a failure status
  663. * enum sci_status SCI_SUCCESS on any valid event notification SCI_FAILURE on any
  664. * unexpected event notifation
  665. */
  666. static enum sci_status scic_sds_phy_starting_substate_await_iaf_uf_event_handler(
  667. struct scic_sds_phy *sci_phy,
  668. u32 event_code)
  669. {
  670. u32 result = SCI_SUCCESS;
  671. switch (scu_get_event_code(event_code)) {
  672. case SCU_EVENT_SAS_PHY_DETECTED:
  673. /* Backup the state machine */
  674. scic_sds_phy_start_sas_link_training(sci_phy);
  675. break;
  676. case SCU_EVENT_SATA_SPINUP_HOLD:
  677. /*
  678. * We were doing SAS PHY link training and received a SATA PHY event
  679. * continue OOB/SN as if this were a SATA PHY */
  680. scic_sds_phy_start_sata_link_training(sci_phy);
  681. break;
  682. case SCU_EVENT_RECEIVED_IDENTIFY_TIMEOUT:
  683. case SCU_EVENT_LINK_FAILURE:
  684. case SCU_EVENT_HARD_RESET_RECEIVED:
  685. /* Start the oob/sn state machine over again */
  686. scic_sds_phy_restart_starting_state(sci_phy);
  687. break;
  688. default:
  689. dev_warn(sciphy_to_dev(sci_phy),
  690. "%s: PHY starting substate machine received "
  691. "unexpected event_code %x\n",
  692. __func__,
  693. event_code);
  694. result = SCI_FAILURE;
  695. break;
  696. }
  697. return result;
  698. }
  699. /**
  700. *
  701. * @phy: This struct scic_sds_phy object which has received an event.
  702. * @event_code: This is the event code which the phy object is to decode.
  703. *
  704. * This method is called when an event notification is received for the phy
  705. * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_POWER. -
  706. * decode the event - link failure events restart the starting state machine -
  707. * any other events log a warning message and set a failure status enum sci_status
  708. * SCI_SUCCESS on a link failure event SCI_FAILURE on any unexpected event
  709. * notifation
  710. */
  711. static enum sci_status scic_sds_phy_starting_substate_await_sas_power_event_handler(
  712. struct scic_sds_phy *sci_phy,
  713. u32 event_code)
  714. {
  715. u32 result = SCI_SUCCESS;
  716. switch (scu_get_event_code(event_code)) {
  717. case SCU_EVENT_LINK_FAILURE:
  718. /* Link failure change state back to the starting state */
  719. scic_sds_phy_restart_starting_state(sci_phy);
  720. break;
  721. default:
  722. dev_warn(sciphy_to_dev(sci_phy),
  723. "%s: PHY starting substate machine received unexpected "
  724. "event_code %x\n",
  725. __func__,
  726. event_code);
  727. result = SCI_FAILURE;
  728. break;
  729. }
  730. return result;
  731. }
  732. /**
  733. *
  734. * @phy: This struct scic_sds_phy object which has received an event.
  735. * @event_code: This is the event code which the phy object is to decode.
  736. *
  737. * This method is called when an event notification is received for the phy
  738. * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. -
  739. * decode the event - link failure events restart the starting state machine -
  740. * sata spinup hold events are ignored since they are expected - any other
  741. * events log a warning message and set a failure status enum sci_status SCI_SUCCESS
  742. * on a link failure event SCI_FAILURE on any unexpected event notifation
  743. */
  744. static enum sci_status scic_sds_phy_starting_substate_await_sata_power_event_handler(
  745. struct scic_sds_phy *sci_phy,
  746. u32 event_code)
  747. {
  748. u32 result = SCI_SUCCESS;
  749. switch (scu_get_event_code(event_code)) {
  750. case SCU_EVENT_LINK_FAILURE:
  751. /* Link failure change state back to the starting state */
  752. scic_sds_phy_restart_starting_state(sci_phy);
  753. break;
  754. case SCU_EVENT_SATA_SPINUP_HOLD:
  755. /* These events are received every 10ms and are expected while in this state */
  756. break;
  757. case SCU_EVENT_SAS_PHY_DETECTED:
  758. /*
  759. * There has been a change in the phy type before OOB/SN for the
  760. * SATA finished start down the SAS link traning path. */
  761. scic_sds_phy_start_sas_link_training(sci_phy);
  762. break;
  763. default:
  764. dev_warn(sciphy_to_dev(sci_phy),
  765. "%s: PHY starting substate machine received "
  766. "unexpected event_code %x\n",
  767. __func__,
  768. event_code);
  769. result = SCI_FAILURE;
  770. break;
  771. }
  772. return result;
  773. }
  774. /**
  775. * scic_sds_phy_starting_substate_await_sata_phy_event_handler -
  776. * @phy: This struct scic_sds_phy object which has received an event.
  777. * @event_code: This is the event code which the phy object is to decode.
  778. *
  779. * This method is called when an event notification is received for the phy
  780. * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. -
  781. * decode the event - link failure events restart the starting state machine -
  782. * sata spinup hold events are ignored since they are expected - sata phy
  783. * detected event change to the wait speed event - any other events log a
  784. * warning message and set a failure status enum sci_status SCI_SUCCESS on a link
  785. * failure event SCI_FAILURE on any unexpected event notifation
  786. */
  787. static enum sci_status scic_sds_phy_starting_substate_await_sata_phy_event_handler(
  788. struct scic_sds_phy *sci_phy, u32 event_code)
  789. {
  790. u32 result = SCI_SUCCESS;
  791. switch (scu_get_event_code(event_code)) {
  792. case SCU_EVENT_LINK_FAILURE:
  793. /* Link failure change state back to the starting state */
  794. scic_sds_phy_restart_starting_state(sci_phy);
  795. break;
  796. case SCU_EVENT_SATA_SPINUP_HOLD:
  797. /* These events might be received since we dont know how many may be in
  798. * the completion queue while waiting for power
  799. */
  800. break;
  801. case SCU_EVENT_SATA_PHY_DETECTED:
  802. sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA;
  803. /* We have received the SATA PHY notification change state */
  804. sci_base_state_machine_change_state(&sci_phy->state_machine,
  805. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN);
  806. break;
  807. case SCU_EVENT_SAS_PHY_DETECTED:
  808. /* There has been a change in the phy type before OOB/SN for the
  809. * SATA finished start down the SAS link traning path.
  810. */
  811. scic_sds_phy_start_sas_link_training(sci_phy);
  812. break;
  813. default:
  814. dev_warn(sciphy_to_dev(sci_phy),
  815. "%s: PHY starting substate machine received "
  816. "unexpected event_code %x\n",
  817. __func__,
  818. event_code);
  819. result = SCI_FAILURE;
  820. break;
  821. }
  822. return result;
  823. }
  824. /**
  825. *
  826. * @phy: This struct scic_sds_phy object which has received an event.
  827. * @event_code: This is the event code which the phy object is to decode.
  828. *
  829. * This method is called when an event notification is received for the phy
  830. * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN.
  831. * - decode the event - sata phy detected returns us back to this state. -
  832. * speed event detected causes a state transition to the wait for signature. -
  833. * link failure events restart the starting state machine - any other events
  834. * log a warning message and set a failure status enum sci_status SCI_SUCCESS on any
  835. * valid event notification SCI_FAILURE on any unexpected event notifation
  836. */
  837. static enum sci_status scic_sds_phy_starting_substate_await_sata_speed_event_handler(
  838. struct scic_sds_phy *sci_phy,
  839. u32 event_code)
  840. {
  841. u32 result = SCI_SUCCESS;
  842. switch (scu_get_event_code(event_code)) {
  843. case SCU_EVENT_SATA_PHY_DETECTED:
  844. /*
  845. * The hardware reports multiple SATA PHY detected events
  846. * ignore the extras */
  847. break;
  848. case SCU_EVENT_SATA_15:
  849. case SCU_EVENT_SATA_15_SSC:
  850. scic_sds_phy_complete_link_training(
  851. sci_phy,
  852. SAS_LINK_RATE_1_5_GBPS,
  853. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF);
  854. break;
  855. case SCU_EVENT_SATA_30:
  856. case SCU_EVENT_SATA_30_SSC:
  857. scic_sds_phy_complete_link_training(
  858. sci_phy,
  859. SAS_LINK_RATE_3_0_GBPS,
  860. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF);
  861. break;
  862. case SCU_EVENT_SATA_60:
  863. case SCU_EVENT_SATA_60_SSC:
  864. scic_sds_phy_complete_link_training(
  865. sci_phy,
  866. SAS_LINK_RATE_6_0_GBPS,
  867. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF);
  868. break;
  869. case SCU_EVENT_LINK_FAILURE:
  870. /* Link failure change state back to the starting state */
  871. scic_sds_phy_restart_starting_state(sci_phy);
  872. break;
  873. case SCU_EVENT_SAS_PHY_DETECTED:
  874. /*
  875. * There has been a change in the phy type before OOB/SN for the
  876. * SATA finished start down the SAS link traning path. */
  877. scic_sds_phy_start_sas_link_training(sci_phy);
  878. break;
  879. default:
  880. dev_warn(sciphy_to_dev(sci_phy),
  881. "%s: PHY starting substate machine received "
  882. "unexpected event_code %x\n",
  883. __func__,
  884. event_code);
  885. result = SCI_FAILURE;
  886. break;
  887. }
  888. return result;
  889. }
  890. /**
  891. * scic_sds_phy_starting_substate_await_sig_fis_event_handler -
  892. * @phy: This struct scic_sds_phy object which has received an event.
  893. * @event_code: This is the event code which the phy object is to decode.
  894. *
  895. * This method is called when an event notification is received for the phy
  896. * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. -
  897. * decode the event - sas phy detected event backs up the state machine to the
  898. * await speed notification. - identify timeout is an un-expected event and the
  899. * state machine is restarted. - link failure events restart the starting state
  900. * machine - any other events log a warning message and set a failure status
  901. * enum sci_status SCI_SUCCESS on any valid event notification SCI_FAILURE on any
  902. * unexpected event notifation
  903. */
  904. static enum sci_status scic_sds_phy_starting_substate_await_sig_fis_event_handler(
  905. struct scic_sds_phy *sci_phy, u32 event_code)
  906. {
  907. u32 result = SCI_SUCCESS;
  908. switch (scu_get_event_code(event_code)) {
  909. case SCU_EVENT_SATA_PHY_DETECTED:
  910. /* Backup the state machine */
  911. sci_base_state_machine_change_state(&sci_phy->state_machine,
  912. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN);
  913. break;
  914. case SCU_EVENT_LINK_FAILURE:
  915. /* Link failure change state back to the starting state */
  916. scic_sds_phy_restart_starting_state(sci_phy);
  917. break;
  918. default:
  919. dev_warn(sciphy_to_dev(sci_phy),
  920. "%s: PHY starting substate machine received "
  921. "unexpected event_code %x\n",
  922. __func__,
  923. event_code);
  924. result = SCI_FAILURE;
  925. break;
  926. }
  927. return result;
  928. }
  929. /*
  930. * *****************************************************************************
  931. * * SCIC SDS PHY FRAME_HANDLERS
  932. * ***************************************************************************** */
  933. /**
  934. *
  935. * @phy: This is struct scic_sds_phy object which is being requested to decode the
  936. * frame data.
  937. * @frame_index: This is the index of the unsolicited frame which was received
  938. * for this phy.
  939. *
  940. * This method decodes the unsolicited frame when the struct scic_sds_phy is in the
  941. * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. - Get the UF Header - If the UF
  942. * is an IAF - Copy IAF data to local phy object IAF data buffer. - Change
  943. * starting substate to wait power. - else - log warning message of unexpected
  944. * unsolicted frame - release frame buffer enum sci_status SCI_SUCCESS
  945. */
  946. static enum sci_status scic_sds_phy_starting_substate_await_iaf_uf_frame_handler(
  947. struct scic_sds_phy *sci_phy, u32 frame_index)
  948. {
  949. enum sci_status result;
  950. u32 *frame_words;
  951. struct sas_identify_frame iaf;
  952. struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
  953. result = scic_sds_unsolicited_frame_control_get_header(
  954. &(scic_sds_phy_get_controller(sci_phy)->uf_control),
  955. frame_index,
  956. (void **)&frame_words);
  957. if (result != SCI_SUCCESS)
  958. return result;
  959. sci_swab32_cpy(&iaf, frame_words, sizeof(iaf) / sizeof(u32));
  960. if (iaf.frame_type == 0) {
  961. u32 state;
  962. memcpy(&iphy->frame_rcvd.iaf, &iaf, sizeof(iaf));
  963. if (iaf.smp_tport) {
  964. /* We got the IAF for an expander PHY go to the final
  965. * state since there are no power requirements for
  966. * expander phys.
  967. */
  968. state = SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL;
  969. } else {
  970. /* We got the IAF we can now go to the await spinup
  971. * semaphore state
  972. */
  973. state = SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER;
  974. }
  975. sci_base_state_machine_change_state(
  976. &sci_phy->state_machine,
  977. state);
  978. result = SCI_SUCCESS;
  979. } else
  980. dev_warn(sciphy_to_dev(sci_phy),
  981. "%s: PHY starting substate machine received "
  982. "unexpected frame id %x\n",
  983. __func__,
  984. frame_index);
  985. scic_sds_controller_release_frame(scic_sds_phy_get_controller(sci_phy),
  986. frame_index);
  987. return result;
  988. }
  989. /**
  990. *
  991. * @phy: This is struct scic_sds_phy object which is being requested to decode the
  992. * frame data.
  993. * @frame_index: This is the index of the unsolicited frame which was received
  994. * for this phy.
  995. *
  996. * This method decodes the unsolicited frame when the struct scic_sds_phy is in the
  997. * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Get the UF Header - If
  998. * the UF is an SIGNATURE FIS - Copy IAF data to local phy object SIGNATURE FIS
  999. * data buffer. - else - log warning message of unexpected unsolicted frame -
  1000. * release frame buffer enum sci_status SCI_SUCCESS Must decode the SIGNATURE FIS
  1001. * data
  1002. */
  1003. static enum sci_status scic_sds_phy_starting_substate_await_sig_fis_frame_handler(
  1004. struct scic_sds_phy *sci_phy,
  1005. u32 frame_index)
  1006. {
  1007. enum sci_status result;
  1008. struct dev_to_host_fis *frame_header;
  1009. u32 *fis_frame_data;
  1010. struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
  1011. result = scic_sds_unsolicited_frame_control_get_header(
  1012. &(scic_sds_phy_get_controller(sci_phy)->uf_control),
  1013. frame_index,
  1014. (void **)&frame_header);
  1015. if (result != SCI_SUCCESS)
  1016. return result;
  1017. if ((frame_header->fis_type == FIS_REGD2H) &&
  1018. !(frame_header->status & ATA_BUSY)) {
  1019. scic_sds_unsolicited_frame_control_get_buffer(
  1020. &(scic_sds_phy_get_controller(sci_phy)->uf_control),
  1021. frame_index,
  1022. (void **)&fis_frame_data);
  1023. scic_sds_controller_copy_sata_response(&iphy->frame_rcvd.fis,
  1024. frame_header,
  1025. fis_frame_data);
  1026. /* got IAF we can now go to the await spinup semaphore state */
  1027. sci_base_state_machine_change_state(&sci_phy->state_machine,
  1028. SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL);
  1029. result = SCI_SUCCESS;
  1030. } else
  1031. dev_warn(sciphy_to_dev(sci_phy),
  1032. "%s: PHY starting substate machine received "
  1033. "unexpected frame id %x\n",
  1034. __func__,
  1035. frame_index);
  1036. /* Regardless of the result we are done with this frame with it */
  1037. scic_sds_controller_release_frame(scic_sds_phy_get_controller(sci_phy),
  1038. frame_index);
  1039. return result;
  1040. }
  1041. /*
  1042. * *****************************************************************************
  1043. * * SCIC SDS PHY POWER_HANDLERS
  1044. * ***************************************************************************** */
  1045. /*
  1046. * This method is called by the struct scic_sds_controller when the phy object is
  1047. * granted power. - The notify enable spinups are turned on for this phy object
  1048. * - The phy state machine is transitioned to the
  1049. * SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL. enum sci_status SCI_SUCCESS
  1050. */
  1051. static enum sci_status scic_sds_phy_starting_substate_await_sas_power_consume_power_handler(
  1052. struct scic_sds_phy *sci_phy)
  1053. {
  1054. u32 enable_spinup;
  1055. enable_spinup = readl(&sci_phy->link_layer_registers->notify_enable_spinup_control);
  1056. enable_spinup |= SCU_ENSPINUP_GEN_BIT(ENABLE);
  1057. writel(enable_spinup, &sci_phy->link_layer_registers->notify_enable_spinup_control);
  1058. /* Change state to the final state this substate machine has run to completion */
  1059. sci_base_state_machine_change_state(&sci_phy->state_machine,
  1060. SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL);
  1061. return SCI_SUCCESS;
  1062. }
  1063. /*
  1064. * This method is called by the struct scic_sds_controller when the phy object is
  1065. * granted power. - The phy state machine is transitioned to the
  1066. * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. enum sci_status SCI_SUCCESS
  1067. */
  1068. static enum sci_status scic_sds_phy_starting_substate_await_sata_power_consume_power_handler(
  1069. struct scic_sds_phy *sci_phy)
  1070. {
  1071. u32 scu_sas_pcfg_value;
  1072. /* Release the spinup hold state and reset the OOB state machine */
  1073. scu_sas_pcfg_value =
  1074. readl(&sci_phy->link_layer_registers->phy_configuration);
  1075. scu_sas_pcfg_value &=
  1076. ~(SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD) | SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE));
  1077. scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
  1078. writel(scu_sas_pcfg_value,
  1079. &sci_phy->link_layer_registers->phy_configuration);
  1080. /* Now restart the OOB operation */
  1081. scu_sas_pcfg_value &= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
  1082. scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
  1083. writel(scu_sas_pcfg_value,
  1084. &sci_phy->link_layer_registers->phy_configuration);
  1085. /* Change state to the final state this substate machine has run to completion */
  1086. sci_base_state_machine_change_state(&sci_phy->state_machine,
  1087. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN);
  1088. return SCI_SUCCESS;
  1089. }
  1090. static enum sci_status default_phy_handler(struct scic_sds_phy *sci_phy,
  1091. const char *func)
  1092. {
  1093. dev_dbg(sciphy_to_dev(sci_phy),
  1094. "%s: in wrong state: %d\n", func,
  1095. sci_base_state_machine_get_state(&sci_phy->state_machine));
  1096. return SCI_FAILURE_INVALID_STATE;
  1097. }
  1098. static enum sci_status
  1099. scic_sds_phy_default_stop_handler(struct scic_sds_phy *sci_phy)
  1100. {
  1101. return default_phy_handler(sci_phy, __func__);
  1102. }
  1103. static enum sci_status
  1104. scic_sds_phy_default_reset_handler(struct scic_sds_phy *sci_phy)
  1105. {
  1106. return default_phy_handler(sci_phy, __func__);
  1107. }
  1108. static enum sci_status
  1109. scic_sds_phy_default_destroy_handler(struct scic_sds_phy *sci_phy)
  1110. {
  1111. return default_phy_handler(sci_phy, __func__);
  1112. }
  1113. static enum sci_status
  1114. scic_sds_phy_default_frame_handler(struct scic_sds_phy *sci_phy,
  1115. u32 frame_index)
  1116. {
  1117. struct scic_sds_controller *scic = scic_sds_phy_get_controller(sci_phy);
  1118. default_phy_handler(sci_phy, __func__);
  1119. scic_sds_controller_release_frame(scic, frame_index);
  1120. return SCI_FAILURE_INVALID_STATE;
  1121. }
  1122. static enum sci_status
  1123. scic_sds_phy_default_event_handler(struct scic_sds_phy *sci_phy,
  1124. u32 event_code)
  1125. {
  1126. return default_phy_handler(sci_phy, __func__);
  1127. }
  1128. static enum sci_status
  1129. scic_sds_phy_default_consume_power_handler(struct scic_sds_phy *sci_phy)
  1130. {
  1131. return default_phy_handler(sci_phy, __func__);
  1132. }
  1133. static enum sci_status
  1134. scic_sds_phy_stopped_state_destroy_handler(struct scic_sds_phy *sci_phy)
  1135. {
  1136. return SCI_SUCCESS;
  1137. }
  1138. static enum sci_status
  1139. scic_sds_phy_ready_state_stop_handler(struct scic_sds_phy *sci_phy)
  1140. {
  1141. sci_base_state_machine_change_state(&sci_phy->state_machine,
  1142. SCI_BASE_PHY_STATE_STOPPED);
  1143. return SCI_SUCCESS;
  1144. }
  1145. static enum sci_status
  1146. scic_sds_phy_ready_state_reset_handler(struct scic_sds_phy *sci_phy)
  1147. {
  1148. sci_base_state_machine_change_state(&sci_phy->state_machine,
  1149. SCI_BASE_PHY_STATE_RESETTING);
  1150. return SCI_SUCCESS;
  1151. }
  1152. /**
  1153. * scic_sds_phy_ready_state_event_handler -
  1154. * @phy: This is the struct scic_sds_phy object which has received the event.
  1155. *
  1156. * This method request the struct scic_sds_phy handle the received event. The only
  1157. * event that we are interested in while in the ready state is the link failure
  1158. * event. - decoded event is a link failure - transition the struct scic_sds_phy back
  1159. * to the SCI_BASE_PHY_STATE_STARTING state. - any other event received will
  1160. * report a warning message enum sci_status SCI_SUCCESS if the event received is a
  1161. * link failure SCI_FAILURE_INVALID_STATE for any other event received.
  1162. */
  1163. static enum sci_status scic_sds_phy_ready_state_event_handler(struct scic_sds_phy *sci_phy,
  1164. u32 event_code)
  1165. {
  1166. enum sci_status result = SCI_FAILURE;
  1167. switch (scu_get_event_code(event_code)) {
  1168. case SCU_EVENT_LINK_FAILURE:
  1169. /* Link failure change state back to the starting state */
  1170. sci_base_state_machine_change_state(&sci_phy->state_machine,
  1171. SCI_BASE_PHY_STATE_STARTING);
  1172. result = SCI_SUCCESS;
  1173. break;
  1174. case SCU_EVENT_BROADCAST_CHANGE:
  1175. /* Broadcast change received. Notify the port. */
  1176. if (scic_sds_phy_get_port(sci_phy) != NULL)
  1177. scic_sds_port_broadcast_change_received(sci_phy->owning_port, sci_phy);
  1178. else
  1179. sci_phy->bcn_received_while_port_unassigned = true;
  1180. break;
  1181. default:
  1182. dev_warn(sciphy_to_dev(sci_phy),
  1183. "%sP SCIC PHY 0x%p ready state machine received "
  1184. "unexpected event_code %x\n",
  1185. __func__, sci_phy, event_code);
  1186. result = SCI_FAILURE_INVALID_STATE;
  1187. break;
  1188. }
  1189. return result;
  1190. }
  1191. static enum sci_status scic_sds_phy_resetting_state_event_handler(struct scic_sds_phy *sci_phy,
  1192. u32 event_code)
  1193. {
  1194. enum sci_status result = SCI_FAILURE;
  1195. switch (scu_get_event_code(event_code)) {
  1196. case SCU_EVENT_HARD_RESET_TRANSMITTED:
  1197. /* Link failure change state back to the starting state */
  1198. sci_base_state_machine_change_state(&sci_phy->state_machine,
  1199. SCI_BASE_PHY_STATE_STARTING);
  1200. result = SCI_SUCCESS;
  1201. break;
  1202. default:
  1203. dev_warn(sciphy_to_dev(sci_phy),
  1204. "%s: SCIC PHY 0x%p resetting state machine received "
  1205. "unexpected event_code %x\n",
  1206. __func__, sci_phy, event_code);
  1207. result = SCI_FAILURE_INVALID_STATE;
  1208. break;
  1209. }
  1210. return result;
  1211. }
  1212. /* --------------------------------------------------------------------------- */
  1213. static const struct scic_sds_phy_state_handler scic_sds_phy_state_handler_table[] = {
  1214. [SCI_BASE_PHY_STATE_INITIAL] = {
  1215. .stop_handler = scic_sds_phy_default_stop_handler,
  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. [SCI_BASE_PHY_STATE_STOPPED] = {
  1223. .stop_handler = scic_sds_phy_default_stop_handler,
  1224. .reset_handler = scic_sds_phy_default_reset_handler,
  1225. .destruct_handler = scic_sds_phy_stopped_state_destroy_handler,
  1226. .frame_handler = scic_sds_phy_default_frame_handler,
  1227. .event_handler = scic_sds_phy_default_event_handler,
  1228. .consume_power_handler = scic_sds_phy_default_consume_power_handler
  1229. },
  1230. [SCI_BASE_PHY_STATE_STARTING] = {
  1231. .stop_handler = scic_sds_phy_default_stop_handler,
  1232. .reset_handler = scic_sds_phy_default_reset_handler,
  1233. .destruct_handler = scic_sds_phy_default_destroy_handler,
  1234. .frame_handler = scic_sds_phy_default_frame_handler,
  1235. .event_handler = scic_sds_phy_default_event_handler,
  1236. .consume_power_handler = scic_sds_phy_default_consume_power_handler
  1237. },
  1238. [SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL] = {
  1239. .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
  1240. .reset_handler = scic_sds_phy_default_reset_handler,
  1241. .destruct_handler = scic_sds_phy_default_destroy_handler,
  1242. .frame_handler = scic_sds_phy_default_frame_handler,
  1243. .event_handler = scic_sds_phy_default_event_handler,
  1244. .consume_power_handler = scic_sds_phy_default_consume_power_handler
  1245. },
  1246. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN] = {
  1247. .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
  1248. .reset_handler = scic_sds_phy_default_reset_handler,
  1249. .destruct_handler = scic_sds_phy_default_destroy_handler,
  1250. .frame_handler = scic_sds_phy_default_frame_handler,
  1251. .event_handler = scic_sds_phy_starting_substate_await_ossp_event_handler,
  1252. .consume_power_handler = scic_sds_phy_default_consume_power_handler
  1253. },
  1254. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN] = {
  1255. .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
  1256. .reset_handler = scic_sds_phy_default_reset_handler,
  1257. .destruct_handler = scic_sds_phy_default_destroy_handler,
  1258. .frame_handler = scic_sds_phy_default_frame_handler,
  1259. .event_handler = scic_sds_phy_starting_substate_await_sas_phy_speed_event_handler,
  1260. .consume_power_handler = scic_sds_phy_default_consume_power_handler
  1261. },
  1262. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF] = {
  1263. .stop_handler = scic_sds_phy_default_stop_handler,
  1264. .reset_handler = scic_sds_phy_default_reset_handler,
  1265. .destruct_handler = scic_sds_phy_default_destroy_handler,
  1266. .frame_handler = scic_sds_phy_starting_substate_await_iaf_uf_frame_handler,
  1267. .event_handler = scic_sds_phy_starting_substate_await_iaf_uf_event_handler,
  1268. .consume_power_handler = scic_sds_phy_default_consume_power_handler
  1269. },
  1270. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER] = {
  1271. .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
  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_sas_power_event_handler,
  1276. .consume_power_handler = scic_sds_phy_starting_substate_await_sas_power_consume_power_handler
  1277. },
  1278. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER] = {
  1279. .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
  1280. .reset_handler = scic_sds_phy_default_reset_handler,
  1281. .destruct_handler = scic_sds_phy_default_destroy_handler,
  1282. .frame_handler = scic_sds_phy_default_frame_handler,
  1283. .event_handler = scic_sds_phy_starting_substate_await_sata_power_event_handler,
  1284. .consume_power_handler = scic_sds_phy_starting_substate_await_sata_power_consume_power_handler
  1285. },
  1286. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN] = {
  1287. .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
  1288. .reset_handler = scic_sds_phy_default_reset_handler,
  1289. .destruct_handler = scic_sds_phy_default_destroy_handler,
  1290. .frame_handler = scic_sds_phy_default_frame_handler,
  1291. .event_handler = scic_sds_phy_starting_substate_await_sata_phy_event_handler,
  1292. .consume_power_handler = scic_sds_phy_default_consume_power_handler
  1293. },
  1294. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN] = {
  1295. .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
  1296. .reset_handler = scic_sds_phy_default_reset_handler,
  1297. .destruct_handler = scic_sds_phy_default_destroy_handler,
  1298. .frame_handler = scic_sds_phy_default_frame_handler,
  1299. .event_handler = scic_sds_phy_starting_substate_await_sata_speed_event_handler,
  1300. .consume_power_handler = scic_sds_phy_default_consume_power_handler
  1301. },
  1302. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF] = {
  1303. .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
  1304. .reset_handler = scic_sds_phy_default_reset_handler,
  1305. .destruct_handler = scic_sds_phy_default_destroy_handler,
  1306. .frame_handler = scic_sds_phy_starting_substate_await_sig_fis_frame_handler,
  1307. .event_handler = scic_sds_phy_starting_substate_await_sig_fis_event_handler,
  1308. .consume_power_handler = scic_sds_phy_default_consume_power_handler
  1309. },
  1310. [SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL] = {
  1311. .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
  1312. .reset_handler = scic_sds_phy_default_reset_handler,
  1313. .destruct_handler = scic_sds_phy_default_destroy_handler,
  1314. .frame_handler = scic_sds_phy_default_frame_handler,
  1315. .event_handler = scic_sds_phy_default_event_handler,
  1316. .consume_power_handler = scic_sds_phy_default_consume_power_handler
  1317. },
  1318. [SCI_BASE_PHY_STATE_READY] = {
  1319. .stop_handler = scic_sds_phy_ready_state_stop_handler,
  1320. .reset_handler = scic_sds_phy_ready_state_reset_handler,
  1321. .destruct_handler = scic_sds_phy_default_destroy_handler,
  1322. .frame_handler = scic_sds_phy_default_frame_handler,
  1323. .event_handler = scic_sds_phy_ready_state_event_handler,
  1324. .consume_power_handler = scic_sds_phy_default_consume_power_handler
  1325. },
  1326. [SCI_BASE_PHY_STATE_RESETTING] = {
  1327. .stop_handler = scic_sds_phy_default_stop_handler,
  1328. .reset_handler = scic_sds_phy_default_reset_handler,
  1329. .destruct_handler = scic_sds_phy_default_destroy_handler,
  1330. .frame_handler = scic_sds_phy_default_frame_handler,
  1331. .event_handler = scic_sds_phy_resetting_state_event_handler,
  1332. .consume_power_handler = scic_sds_phy_default_consume_power_handler
  1333. },
  1334. [SCI_BASE_PHY_STATE_FINAL] = {
  1335. .stop_handler = scic_sds_phy_default_stop_handler,
  1336. .reset_handler = scic_sds_phy_default_reset_handler,
  1337. .destruct_handler = scic_sds_phy_default_destroy_handler,
  1338. .frame_handler = scic_sds_phy_default_frame_handler,
  1339. .event_handler = scic_sds_phy_default_event_handler,
  1340. .consume_power_handler = scic_sds_phy_default_consume_power_handler
  1341. }
  1342. };
  1343. /*
  1344. * ****************************************************************************
  1345. * * PHY STARTING SUBSTATE METHODS
  1346. * **************************************************************************** */
  1347. /**
  1348. * scic_sds_phy_starting_initial_substate_enter -
  1349. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1350. *
  1351. * This method will perform the actions required by the struct scic_sds_phy on
  1352. * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL. - The initial state
  1353. * handlers are put in place for the struct scic_sds_phy object. - The state is
  1354. * changed to the wait phy type event notification. none
  1355. */
  1356. static void scic_sds_phy_starting_initial_substate_enter(void *object)
  1357. {
  1358. struct scic_sds_phy *sci_phy = object;
  1359. scic_sds_phy_set_base_state_handlers(
  1360. sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL);
  1361. /* This is just an temporary state go off to the starting state */
  1362. sci_base_state_machine_change_state(&sci_phy->state_machine,
  1363. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN);
  1364. }
  1365. /**
  1366. *
  1367. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1368. *
  1369. * This method will perform the actions required by the struct scic_sds_phy on
  1370. * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_PHY_TYPE_EN. - Set the
  1371. * struct scic_sds_phy object state handlers for this state. none
  1372. */
  1373. static void scic_sds_phy_starting_await_ossp_en_substate_enter(void *object)
  1374. {
  1375. struct scic_sds_phy *sci_phy = object;
  1376. scic_sds_phy_set_base_state_handlers(
  1377. sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN
  1378. );
  1379. }
  1380. /**
  1381. *
  1382. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1383. *
  1384. * This method will perform the actions required by the struct scic_sds_phy on
  1385. * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. - Set the
  1386. * struct scic_sds_phy object state handlers for this state. none
  1387. */
  1388. static void scic_sds_phy_starting_await_sas_speed_en_substate_enter(
  1389. void *object)
  1390. {
  1391. struct scic_sds_phy *sci_phy = object;
  1392. scic_sds_phy_set_base_state_handlers(
  1393. sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
  1394. );
  1395. }
  1396. /**
  1397. *
  1398. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1399. *
  1400. * This method will perform the actions required by the struct scic_sds_phy on
  1401. * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. - Set the
  1402. * struct scic_sds_phy object state handlers for this state. none
  1403. */
  1404. static void scic_sds_phy_starting_await_iaf_uf_substate_enter(void *object)
  1405. {
  1406. struct scic_sds_phy *sci_phy = object;
  1407. scic_sds_phy_set_base_state_handlers(
  1408. sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
  1409. );
  1410. }
  1411. /**
  1412. *
  1413. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1414. *
  1415. * This method will perform the actions required by the struct scic_sds_phy on
  1416. * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER. - Set the
  1417. * struct scic_sds_phy object state handlers for this state. - Add this phy object to
  1418. * the power control queue none
  1419. */
  1420. static void scic_sds_phy_starting_await_sas_power_substate_enter(void *object)
  1421. {
  1422. struct scic_sds_phy *sci_phy = object;
  1423. scic_sds_phy_set_base_state_handlers(
  1424. sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER
  1425. );
  1426. scic_sds_controller_power_control_queue_insert(
  1427. scic_sds_phy_get_controller(sci_phy),
  1428. sci_phy
  1429. );
  1430. }
  1431. /**
  1432. *
  1433. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1434. *
  1435. * This method will perform the actions required by the struct scic_sds_phy on exiting
  1436. * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER. - Remove the
  1437. * struct scic_sds_phy object from the power control queue. none
  1438. */
  1439. static void scic_sds_phy_starting_await_sas_power_substate_exit(void *object)
  1440. {
  1441. struct scic_sds_phy *sci_phy = object;
  1442. scic_sds_controller_power_control_queue_remove(
  1443. scic_sds_phy_get_controller(sci_phy), sci_phy
  1444. );
  1445. }
  1446. /**
  1447. *
  1448. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1449. *
  1450. * This method will perform the actions required by the struct scic_sds_phy on
  1451. * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. - Set the
  1452. * struct scic_sds_phy object state handlers for this state. - Add this phy object to
  1453. * the power control queue none
  1454. */
  1455. static void scic_sds_phy_starting_await_sata_power_substate_enter(void *object)
  1456. {
  1457. struct scic_sds_phy *sci_phy = object;
  1458. scic_sds_phy_set_base_state_handlers(
  1459. sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
  1460. );
  1461. scic_sds_controller_power_control_queue_insert(
  1462. scic_sds_phy_get_controller(sci_phy),
  1463. sci_phy
  1464. );
  1465. }
  1466. /**
  1467. *
  1468. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1469. *
  1470. * This method will perform the actions required by the struct scic_sds_phy on exiting
  1471. * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. - Remove the
  1472. * struct scic_sds_phy object from the power control queue. none
  1473. */
  1474. static void scic_sds_phy_starting_await_sata_power_substate_exit(void *object)
  1475. {
  1476. struct scic_sds_phy *sci_phy = object;
  1477. scic_sds_controller_power_control_queue_remove(
  1478. scic_sds_phy_get_controller(sci_phy),
  1479. sci_phy
  1480. );
  1481. }
  1482. /**
  1483. *
  1484. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1485. *
  1486. * This function will perform the actions required by the struct scic_sds_phy on
  1487. * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. - Set the
  1488. * struct scic_sds_phy object state handlers for this state. none
  1489. */
  1490. static void scic_sds_phy_starting_await_sata_phy_substate_enter(void *object)
  1491. {
  1492. struct scic_sds_phy *sci_phy = object;
  1493. scic_sds_phy_set_base_state_handlers(
  1494. sci_phy,
  1495. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN);
  1496. isci_timer_start(sci_phy->sata_timeout_timer,
  1497. SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT);
  1498. }
  1499. /**
  1500. *
  1501. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1502. *
  1503. * This method will perform the actions required by the struct scic_sds_phy
  1504. * on exiting
  1505. * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - stop the timer
  1506. * that was started on entry to await sata phy event notification none
  1507. */
  1508. static inline void scic_sds_phy_starting_await_sata_phy_substate_exit(
  1509. void *object)
  1510. {
  1511. struct scic_sds_phy *sci_phy = object;
  1512. isci_timer_stop(sci_phy->sata_timeout_timer);
  1513. }
  1514. /**
  1515. *
  1516. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1517. *
  1518. * This method will perform the actions required by the struct scic_sds_phy on
  1519. * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - Set the
  1520. * struct scic_sds_phy object state handlers for this state. none
  1521. */
  1522. static void scic_sds_phy_starting_await_sata_speed_substate_enter(void *object)
  1523. {
  1524. struct scic_sds_phy *sci_phy = object;
  1525. scic_sds_phy_set_base_state_handlers(
  1526. sci_phy,
  1527. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN);
  1528. isci_timer_start(sci_phy->sata_timeout_timer,
  1529. SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT);
  1530. }
  1531. /**
  1532. *
  1533. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1534. *
  1535. * This function will perform the actions required by the
  1536. * struct scic_sds_phy on exiting
  1537. * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - stop the timer
  1538. * that was started on entry to await sata phy event notification none
  1539. */
  1540. static inline void scic_sds_phy_starting_await_sata_speed_substate_exit(
  1541. void *object)
  1542. {
  1543. struct scic_sds_phy *sci_phy = object;
  1544. isci_timer_stop(sci_phy->sata_timeout_timer);
  1545. }
  1546. /**
  1547. *
  1548. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1549. *
  1550. * This function will perform the actions required by the struct scic_sds_phy on
  1551. * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Set the
  1552. * struct scic_sds_phy object state handlers for this state.
  1553. * - Start the SIGNATURE FIS
  1554. * timeout timer none
  1555. */
  1556. static void scic_sds_phy_starting_await_sig_fis_uf_substate_enter(void *object)
  1557. {
  1558. bool continue_to_ready_state;
  1559. struct scic_sds_phy *sci_phy = object;
  1560. scic_sds_phy_set_base_state_handlers(
  1561. sci_phy,
  1562. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF);
  1563. continue_to_ready_state = scic_sds_port_link_detected(
  1564. sci_phy->owning_port,
  1565. sci_phy);
  1566. if (continue_to_ready_state) {
  1567. /*
  1568. * Clear the PE suspend condition so we can actually
  1569. * receive SIG FIS
  1570. * The hardware will not respond to the XRDY until the PE
  1571. * suspend condition is cleared.
  1572. */
  1573. scic_sds_phy_resume(sci_phy);
  1574. isci_timer_start(sci_phy->sata_timeout_timer,
  1575. SCIC_SDS_SIGNATURE_FIS_TIMEOUT);
  1576. } else
  1577. sci_phy->is_in_link_training = false;
  1578. }
  1579. /**
  1580. *
  1581. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1582. *
  1583. * This function will perform the actions required by the
  1584. * struct scic_sds_phy on exiting
  1585. * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Stop the SIGNATURE
  1586. * FIS timeout timer. none
  1587. */
  1588. static inline void scic_sds_phy_starting_await_sig_fis_uf_substate_exit(
  1589. void *object)
  1590. {
  1591. struct scic_sds_phy *sci_phy = object;
  1592. isci_timer_stop(sci_phy->sata_timeout_timer);
  1593. }
  1594. /**
  1595. *
  1596. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1597. *
  1598. * This method will perform the actions required by the struct scic_sds_phy on
  1599. * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL. - Set the struct scic_sds_phy
  1600. * object state handlers for this state. - Change base state machine to the
  1601. * ready state. none
  1602. */
  1603. static void scic_sds_phy_starting_final_substate_enter(void *object)
  1604. {
  1605. struct scic_sds_phy *sci_phy = object;
  1606. scic_sds_phy_set_base_state_handlers(sci_phy,
  1607. SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL);
  1608. /* State machine has run to completion so exit out and change
  1609. * the base state machine to the ready state
  1610. */
  1611. sci_base_state_machine_change_state(&sci_phy->state_machine,
  1612. SCI_BASE_PHY_STATE_READY);
  1613. }
  1614. /*
  1615. * ****************************************************************************
  1616. * * PHY STATE PRIVATE METHODS
  1617. * **************************************************************************** */
  1618. /**
  1619. *
  1620. * @sci_phy: This is the struct scic_sds_phy object to stop.
  1621. *
  1622. * This method will stop the struct scic_sds_phy object. This does not reset the
  1623. * protocol engine it just suspends it and places it in a state where it will
  1624. * not cause the end device to power up. none
  1625. */
  1626. static void scu_link_layer_stop_protocol_engine(
  1627. struct scic_sds_phy *sci_phy)
  1628. {
  1629. u32 scu_sas_pcfg_value;
  1630. u32 enable_spinup_value;
  1631. /* Suspend the protocol engine and place it in a sata spinup hold state */
  1632. scu_sas_pcfg_value =
  1633. readl(&sci_phy->link_layer_registers->phy_configuration);
  1634. scu_sas_pcfg_value |=
  1635. (SCU_SAS_PCFG_GEN_BIT(OOB_RESET) |
  1636. SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE) |
  1637. SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD));
  1638. writel(scu_sas_pcfg_value,
  1639. &sci_phy->link_layer_registers->phy_configuration);
  1640. /* Disable the notify enable spinup primitives */
  1641. enable_spinup_value = readl(&sci_phy->link_layer_registers->notify_enable_spinup_control);
  1642. enable_spinup_value &= ~SCU_ENSPINUP_GEN_BIT(ENABLE);
  1643. writel(enable_spinup_value, &sci_phy->link_layer_registers->notify_enable_spinup_control);
  1644. }
  1645. /**
  1646. *
  1647. *
  1648. * This method will start the OOB/SN state machine for this struct scic_sds_phy object.
  1649. */
  1650. static void scu_link_layer_start_oob(
  1651. struct scic_sds_phy *sci_phy)
  1652. {
  1653. u32 scu_sas_pcfg_value;
  1654. scu_sas_pcfg_value =
  1655. readl(&sci_phy->link_layer_registers->phy_configuration);
  1656. scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
  1657. scu_sas_pcfg_value &=
  1658. ~(SCU_SAS_PCFG_GEN_BIT(OOB_RESET) |
  1659. SCU_SAS_PCFG_GEN_BIT(HARD_RESET));
  1660. writel(scu_sas_pcfg_value,
  1661. &sci_phy->link_layer_registers->phy_configuration);
  1662. }
  1663. /**
  1664. *
  1665. *
  1666. * This method will transmit a hard reset request on the specified phy. The SCU
  1667. * hardware requires that we reset the OOB state machine and set the hard reset
  1668. * bit in the phy configuration register. We then must start OOB over with the
  1669. * hard reset bit set.
  1670. */
  1671. static void scu_link_layer_tx_hard_reset(
  1672. struct scic_sds_phy *sci_phy)
  1673. {
  1674. u32 phy_configuration_value;
  1675. /*
  1676. * SAS Phys must wait for the HARD_RESET_TX event notification to transition
  1677. * to the starting state. */
  1678. phy_configuration_value =
  1679. readl(&sci_phy->link_layer_registers->phy_configuration);
  1680. phy_configuration_value |=
  1681. (SCU_SAS_PCFG_GEN_BIT(HARD_RESET) |
  1682. SCU_SAS_PCFG_GEN_BIT(OOB_RESET));
  1683. writel(phy_configuration_value,
  1684. &sci_phy->link_layer_registers->phy_configuration);
  1685. /* Now take the OOB state machine out of reset */
  1686. phy_configuration_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
  1687. phy_configuration_value &= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
  1688. writel(phy_configuration_value,
  1689. &sci_phy->link_layer_registers->phy_configuration);
  1690. }
  1691. /*
  1692. * ****************************************************************************
  1693. * * PHY BASE STATE METHODS
  1694. * **************************************************************************** */
  1695. /**
  1696. *
  1697. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1698. *
  1699. * This method will perform the actions required by the struct scic_sds_phy on
  1700. * entering the SCI_BASE_PHY_STATE_INITIAL. - This function sets the state
  1701. * handlers for the phy object base state machine initial state. none
  1702. */
  1703. static void scic_sds_phy_initial_state_enter(void *object)
  1704. {
  1705. struct scic_sds_phy *sci_phy = object;
  1706. scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_INITIAL);
  1707. }
  1708. /**
  1709. *
  1710. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1711. *
  1712. * This function will perform the actions required by the struct scic_sds_phy on
  1713. * entering the SCI_BASE_PHY_STATE_INITIAL. - This function sets the state
  1714. * handlers for the phy object base state machine initial state. - The SCU
  1715. * hardware is requested to stop the protocol engine. none
  1716. */
  1717. static void scic_sds_phy_stopped_state_enter(void *object)
  1718. {
  1719. struct scic_sds_phy *sci_phy = object;
  1720. struct scic_sds_controller *scic = scic_sds_phy_get_controller(sci_phy);
  1721. struct isci_host *ihost = scic_to_ihost(scic);
  1722. /*
  1723. * @todo We need to get to the controller to place this PE in a
  1724. * reset state
  1725. */
  1726. scic_sds_phy_set_base_state_handlers(sci_phy,
  1727. SCI_BASE_PHY_STATE_STOPPED);
  1728. if (sci_phy->sata_timeout_timer != NULL) {
  1729. isci_del_timer(ihost, sci_phy->sata_timeout_timer);
  1730. sci_phy->sata_timeout_timer = NULL;
  1731. }
  1732. scu_link_layer_stop_protocol_engine(sci_phy);
  1733. if (sci_phy->state_machine.previous_state_id !=
  1734. SCI_BASE_PHY_STATE_INITIAL)
  1735. scic_sds_controller_link_down(
  1736. scic_sds_phy_get_controller(sci_phy),
  1737. scic_sds_phy_get_port(sci_phy),
  1738. sci_phy);
  1739. }
  1740. /**
  1741. *
  1742. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1743. *
  1744. * This method will perform the actions required by the struct scic_sds_phy on
  1745. * entering the SCI_BASE_PHY_STATE_STARTING. - This function sets the state
  1746. * handlers for the phy object base state machine starting state. - The SCU
  1747. * hardware is requested to start OOB/SN on this protocl engine. - The phy
  1748. * starting substate machine is started. - If the previous state was the ready
  1749. * state then the struct scic_sds_controller is informed that the phy has gone link
  1750. * down. none
  1751. */
  1752. static void scic_sds_phy_starting_state_enter(void *object)
  1753. {
  1754. struct scic_sds_phy *sci_phy = object;
  1755. scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_STARTING);
  1756. scu_link_layer_stop_protocol_engine(sci_phy);
  1757. scu_link_layer_start_oob(sci_phy);
  1758. /* We don't know what kind of phy we are going to be just yet */
  1759. sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_UNKNOWN;
  1760. sci_phy->bcn_received_while_port_unassigned = false;
  1761. if (sci_phy->state_machine.previous_state_id
  1762. == SCI_BASE_PHY_STATE_READY) {
  1763. scic_sds_controller_link_down(
  1764. scic_sds_phy_get_controller(sci_phy),
  1765. scic_sds_phy_get_port(sci_phy),
  1766. sci_phy
  1767. );
  1768. }
  1769. sci_base_state_machine_change_state(&sci_phy->state_machine,
  1770. SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL);
  1771. }
  1772. /**
  1773. *
  1774. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1775. *
  1776. * This method will perform the actions required by the struct scic_sds_phy on
  1777. * entering the SCI_BASE_PHY_STATE_READY. - This function sets the state
  1778. * handlers for the phy object base state machine ready state. - The SCU
  1779. * hardware protocol engine is resumed. - The struct scic_sds_controller is informed
  1780. * that the phy object has gone link up. none
  1781. */
  1782. static void scic_sds_phy_ready_state_enter(void *object)
  1783. {
  1784. struct scic_sds_phy *sci_phy = object;
  1785. scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_READY);
  1786. scic_sds_controller_link_up(
  1787. scic_sds_phy_get_controller(sci_phy),
  1788. scic_sds_phy_get_port(sci_phy),
  1789. sci_phy
  1790. );
  1791. }
  1792. /**
  1793. *
  1794. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1795. *
  1796. * This method will perform the actions required by the struct scic_sds_phy on exiting
  1797. * the SCI_BASE_PHY_STATE_INITIAL. This function suspends the SCU hardware
  1798. * protocol engine represented by this struct scic_sds_phy object. none
  1799. */
  1800. static void scic_sds_phy_ready_state_exit(void *object)
  1801. {
  1802. struct scic_sds_phy *sci_phy = object;
  1803. scic_sds_phy_suspend(sci_phy);
  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_RESETTING. - This function sets the state
  1811. * handlers for the phy object base state machine resetting state. none
  1812. */
  1813. static void scic_sds_phy_resetting_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_RESETTING);
  1817. /*
  1818. * The phy is being reset, therefore deactivate it from the port.
  1819. * In the resetting state we don't notify the user regarding
  1820. * link up and link down notifications. */
  1821. scic_sds_port_deactivate_phy(sci_phy->owning_port, sci_phy, false);
  1822. if (sci_phy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) {
  1823. scu_link_layer_tx_hard_reset(sci_phy);
  1824. } else {
  1825. /*
  1826. * The SCU does not need to have a discrete reset state so
  1827. * just go back to the starting state.
  1828. */
  1829. sci_base_state_machine_change_state(
  1830. &sci_phy->state_machine,
  1831. SCI_BASE_PHY_STATE_STARTING);
  1832. }
  1833. }
  1834. /**
  1835. *
  1836. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1837. *
  1838. * This method will perform the actions required by the struct scic_sds_phy on
  1839. * entering the SCI_BASE_PHY_STATE_FINAL. - This function sets the state
  1840. * handlers for the phy object base state machine final state. none
  1841. */
  1842. static void scic_sds_phy_final_state_enter(void *object)
  1843. {
  1844. struct scic_sds_phy *sci_phy = object;
  1845. scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_FINAL);
  1846. /* Nothing to do here */
  1847. }
  1848. /* --------------------------------------------------------------------------- */
  1849. static const struct sci_base_state scic_sds_phy_state_table[] = {
  1850. [SCI_BASE_PHY_STATE_INITIAL] = {
  1851. .enter_state = scic_sds_phy_initial_state_enter,
  1852. },
  1853. [SCI_BASE_PHY_STATE_STOPPED] = {
  1854. .enter_state = scic_sds_phy_stopped_state_enter,
  1855. },
  1856. [SCI_BASE_PHY_STATE_STARTING] = {
  1857. .enter_state = scic_sds_phy_starting_state_enter,
  1858. },
  1859. [SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL] = {
  1860. .enter_state = scic_sds_phy_starting_initial_substate_enter,
  1861. },
  1862. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN] = {
  1863. .enter_state = scic_sds_phy_starting_await_ossp_en_substate_enter,
  1864. },
  1865. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN] = {
  1866. .enter_state = scic_sds_phy_starting_await_sas_speed_en_substate_enter,
  1867. },
  1868. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF] = {
  1869. .enter_state = scic_sds_phy_starting_await_iaf_uf_substate_enter,
  1870. },
  1871. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER] = {
  1872. .enter_state = scic_sds_phy_starting_await_sas_power_substate_enter,
  1873. .exit_state = scic_sds_phy_starting_await_sas_power_substate_exit,
  1874. },
  1875. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER] = {
  1876. .enter_state = scic_sds_phy_starting_await_sata_power_substate_enter,
  1877. .exit_state = scic_sds_phy_starting_await_sata_power_substate_exit
  1878. },
  1879. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN] = {
  1880. .enter_state = scic_sds_phy_starting_await_sata_phy_substate_enter,
  1881. .exit_state = scic_sds_phy_starting_await_sata_phy_substate_exit
  1882. },
  1883. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN] = {
  1884. .enter_state = scic_sds_phy_starting_await_sata_speed_substate_enter,
  1885. .exit_state = scic_sds_phy_starting_await_sata_speed_substate_exit
  1886. },
  1887. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF] = {
  1888. .enter_state = scic_sds_phy_starting_await_sig_fis_uf_substate_enter,
  1889. .exit_state = scic_sds_phy_starting_await_sig_fis_uf_substate_exit
  1890. },
  1891. [SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL] = {
  1892. .enter_state = scic_sds_phy_starting_final_substate_enter,
  1893. },
  1894. [SCI_BASE_PHY_STATE_READY] = {
  1895. .enter_state = scic_sds_phy_ready_state_enter,
  1896. .exit_state = scic_sds_phy_ready_state_exit,
  1897. },
  1898. [SCI_BASE_PHY_STATE_RESETTING] = {
  1899. .enter_state = scic_sds_phy_resetting_state_enter,
  1900. },
  1901. [SCI_BASE_PHY_STATE_FINAL] = {
  1902. .enter_state = scic_sds_phy_final_state_enter,
  1903. },
  1904. };
  1905. void scic_sds_phy_construct(struct scic_sds_phy *sci_phy,
  1906. struct scic_sds_port *owning_port, u8 phy_index)
  1907. {
  1908. sci_base_state_machine_construct(&sci_phy->state_machine,
  1909. sci_phy,
  1910. scic_sds_phy_state_table,
  1911. SCI_BASE_PHY_STATE_INITIAL);
  1912. sci_base_state_machine_start(&sci_phy->state_machine);
  1913. /* Copy the rest of the input data to our locals */
  1914. sci_phy->owning_port = owning_port;
  1915. sci_phy->phy_index = phy_index;
  1916. sci_phy->bcn_received_while_port_unassigned = false;
  1917. sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_UNKNOWN;
  1918. sci_phy->link_layer_registers = NULL;
  1919. sci_phy->max_negotiated_speed = SAS_LINK_RATE_UNKNOWN;
  1920. sci_phy->sata_timeout_timer = NULL;
  1921. }
  1922. void isci_phy_init(struct isci_phy *iphy, struct isci_host *ihost, int index)
  1923. {
  1924. union scic_oem_parameters oem;
  1925. u64 sci_sas_addr;
  1926. __be64 sas_addr;
  1927. scic_oem_parameters_get(&ihost->sci, &oem);
  1928. sci_sas_addr = oem.sds1.phys[index].sas_address.high;
  1929. sci_sas_addr <<= 32;
  1930. sci_sas_addr |= oem.sds1.phys[index].sas_address.low;
  1931. sas_addr = cpu_to_be64(sci_sas_addr);
  1932. memcpy(iphy->sas_addr, &sas_addr, sizeof(sas_addr));
  1933. iphy->isci_port = NULL;
  1934. iphy->sas_phy.enabled = 0;
  1935. iphy->sas_phy.id = index;
  1936. iphy->sas_phy.sas_addr = &iphy->sas_addr[0];
  1937. iphy->sas_phy.frame_rcvd = (u8 *)&iphy->frame_rcvd;
  1938. iphy->sas_phy.ha = &ihost->sas_ha;
  1939. iphy->sas_phy.lldd_phy = iphy;
  1940. iphy->sas_phy.enabled = 1;
  1941. iphy->sas_phy.class = SAS;
  1942. iphy->sas_phy.iproto = SAS_PROTOCOL_ALL;
  1943. iphy->sas_phy.tproto = 0;
  1944. iphy->sas_phy.type = PHY_TYPE_PHYSICAL;
  1945. iphy->sas_phy.role = PHY_ROLE_INITIATOR;
  1946. iphy->sas_phy.oob_mode = OOB_NOT_CONNECTED;
  1947. iphy->sas_phy.linkrate = SAS_LINK_RATE_UNKNOWN;
  1948. memset(&iphy->frame_rcvd, 0, sizeof(iphy->frame_rcvd));
  1949. }
  1950. /**
  1951. * isci_phy_control() - This function is one of the SAS Domain Template
  1952. * functions. This is a phy management function.
  1953. * @phy: This parameter specifies the sphy being controlled.
  1954. * @func: This parameter specifies the phy control function being invoked.
  1955. * @buf: This parameter is specific to the phy function being invoked.
  1956. *
  1957. * status, zero indicates success.
  1958. */
  1959. int isci_phy_control(struct asd_sas_phy *sas_phy,
  1960. enum phy_func func,
  1961. void *buf)
  1962. {
  1963. int ret = 0;
  1964. struct isci_phy *iphy = sas_phy->lldd_phy;
  1965. struct isci_port *iport = iphy->isci_port;
  1966. struct isci_host *ihost = sas_phy->ha->lldd_ha;
  1967. unsigned long flags;
  1968. dev_dbg(&ihost->pdev->dev,
  1969. "%s: phy %p; func %d; buf %p; isci phy %p, port %p\n",
  1970. __func__, sas_phy, func, buf, iphy, iport);
  1971. switch (func) {
  1972. case PHY_FUNC_DISABLE:
  1973. spin_lock_irqsave(&ihost->scic_lock, flags);
  1974. scic_sds_phy_stop(&iphy->sci);
  1975. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  1976. break;
  1977. case PHY_FUNC_LINK_RESET:
  1978. spin_lock_irqsave(&ihost->scic_lock, flags);
  1979. scic_sds_phy_stop(&iphy->sci);
  1980. scic_sds_phy_start(&iphy->sci);
  1981. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  1982. break;
  1983. case PHY_FUNC_HARD_RESET:
  1984. if (!iport)
  1985. return -ENODEV;
  1986. /* Perform the port reset. */
  1987. ret = isci_port_perform_hard_reset(ihost, iport, iphy);
  1988. break;
  1989. default:
  1990. dev_dbg(&ihost->pdev->dev,
  1991. "%s: phy %p; func %d NOT IMPLEMENTED!\n",
  1992. __func__, sas_phy, func);
  1993. ret = -ENOSYS;
  1994. break;
  1995. }
  1996. return ret;
  1997. }