port.c 57 KB

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