zfcp_erp.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703
  1. /*
  2. * zfcp device driver
  3. *
  4. * Error Recovery Procedures (ERP).
  5. *
  6. * Copyright IBM Corporation 2002, 2008
  7. */
  8. #define KMSG_COMPONENT "zfcp"
  9. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  10. #include "zfcp_ext.h"
  11. #define ZFCP_MAX_ERPS 3
  12. enum zfcp_erp_act_flags {
  13. ZFCP_STATUS_ERP_TIMEDOUT = 0x10000000,
  14. ZFCP_STATUS_ERP_CLOSE_ONLY = 0x01000000,
  15. ZFCP_STATUS_ERP_DISMISSING = 0x00100000,
  16. ZFCP_STATUS_ERP_DISMISSED = 0x00200000,
  17. ZFCP_STATUS_ERP_LOWMEM = 0x00400000,
  18. };
  19. enum zfcp_erp_steps {
  20. ZFCP_ERP_STEP_UNINITIALIZED = 0x0000,
  21. ZFCP_ERP_STEP_FSF_XCONFIG = 0x0001,
  22. ZFCP_ERP_STEP_PHYS_PORT_CLOSING = 0x0010,
  23. ZFCP_ERP_STEP_PORT_CLOSING = 0x0100,
  24. ZFCP_ERP_STEP_NAMESERVER_LOOKUP = 0x0400,
  25. ZFCP_ERP_STEP_PORT_OPENING = 0x0800,
  26. ZFCP_ERP_STEP_UNIT_CLOSING = 0x1000,
  27. ZFCP_ERP_STEP_UNIT_OPENING = 0x2000,
  28. };
  29. enum zfcp_erp_act_type {
  30. ZFCP_ERP_ACTION_REOPEN_UNIT = 1,
  31. ZFCP_ERP_ACTION_REOPEN_PORT = 2,
  32. ZFCP_ERP_ACTION_REOPEN_PORT_FORCED = 3,
  33. ZFCP_ERP_ACTION_REOPEN_ADAPTER = 4,
  34. };
  35. enum zfcp_erp_act_state {
  36. ZFCP_ERP_ACTION_RUNNING = 1,
  37. ZFCP_ERP_ACTION_READY = 2,
  38. };
  39. enum zfcp_erp_act_result {
  40. ZFCP_ERP_SUCCEEDED = 0,
  41. ZFCP_ERP_FAILED = 1,
  42. ZFCP_ERP_CONTINUES = 2,
  43. ZFCP_ERP_EXIT = 3,
  44. ZFCP_ERP_DISMISSED = 4,
  45. ZFCP_ERP_NOMEM = 5,
  46. };
  47. static void zfcp_erp_adapter_block(struct zfcp_adapter *adapter, int mask)
  48. {
  49. zfcp_erp_modify_adapter_status(adapter, 15, NULL,
  50. ZFCP_STATUS_COMMON_UNBLOCKED | mask,
  51. ZFCP_CLEAR);
  52. }
  53. static int zfcp_erp_action_exists(struct zfcp_erp_action *act)
  54. {
  55. struct zfcp_erp_action *curr_act;
  56. list_for_each_entry(curr_act, &act->adapter->erp_running_head, list)
  57. if (act == curr_act)
  58. return ZFCP_ERP_ACTION_RUNNING;
  59. return 0;
  60. }
  61. static void zfcp_erp_action_ready(struct zfcp_erp_action *act)
  62. {
  63. struct zfcp_adapter *adapter = act->adapter;
  64. list_move(&act->list, &act->adapter->erp_ready_head);
  65. zfcp_rec_dbf_event_action(146, act);
  66. up(&adapter->erp_ready_sem);
  67. zfcp_rec_dbf_event_thread(2, adapter);
  68. }
  69. static void zfcp_erp_action_dismiss(struct zfcp_erp_action *act)
  70. {
  71. act->status |= ZFCP_STATUS_ERP_DISMISSED;
  72. if (zfcp_erp_action_exists(act) == ZFCP_ERP_ACTION_RUNNING)
  73. zfcp_erp_action_ready(act);
  74. }
  75. static void zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit)
  76. {
  77. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
  78. zfcp_erp_action_dismiss(&unit->erp_action);
  79. }
  80. static void zfcp_erp_action_dismiss_port(struct zfcp_port *port)
  81. {
  82. struct zfcp_unit *unit;
  83. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
  84. zfcp_erp_action_dismiss(&port->erp_action);
  85. else
  86. list_for_each_entry(unit, &port->unit_list_head, list)
  87. zfcp_erp_action_dismiss_unit(unit);
  88. }
  89. static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
  90. {
  91. struct zfcp_port *port;
  92. if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
  93. zfcp_erp_action_dismiss(&adapter->erp_action);
  94. else
  95. list_for_each_entry(port, &adapter->port_list_head, list)
  96. zfcp_erp_action_dismiss_port(port);
  97. }
  98. static int zfcp_erp_required_act(int want, struct zfcp_adapter *adapter,
  99. struct zfcp_port *port,
  100. struct zfcp_unit *unit)
  101. {
  102. int need = want;
  103. int u_status, p_status, a_status;
  104. switch (want) {
  105. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  106. u_status = atomic_read(&unit->status);
  107. if (u_status & ZFCP_STATUS_COMMON_ERP_INUSE)
  108. return 0;
  109. p_status = atomic_read(&port->status);
  110. if (!(p_status & ZFCP_STATUS_COMMON_RUNNING) ||
  111. p_status & ZFCP_STATUS_COMMON_ERP_FAILED)
  112. return 0;
  113. if (!(p_status & ZFCP_STATUS_COMMON_UNBLOCKED))
  114. need = ZFCP_ERP_ACTION_REOPEN_PORT;
  115. /* fall through */
  116. case ZFCP_ERP_ACTION_REOPEN_PORT:
  117. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  118. p_status = atomic_read(&port->status);
  119. if (p_status & ZFCP_STATUS_COMMON_ERP_INUSE)
  120. return 0;
  121. a_status = atomic_read(&adapter->status);
  122. if (!(a_status & ZFCP_STATUS_COMMON_RUNNING) ||
  123. a_status & ZFCP_STATUS_COMMON_ERP_FAILED)
  124. return 0;
  125. if (!(a_status & ZFCP_STATUS_COMMON_UNBLOCKED))
  126. need = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
  127. /* fall through */
  128. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  129. a_status = atomic_read(&adapter->status);
  130. if (a_status & ZFCP_STATUS_COMMON_ERP_INUSE)
  131. return 0;
  132. }
  133. return need;
  134. }
  135. static struct zfcp_erp_action *zfcp_erp_setup_act(int need,
  136. struct zfcp_adapter *adapter,
  137. struct zfcp_port *port,
  138. struct zfcp_unit *unit)
  139. {
  140. struct zfcp_erp_action *erp_action;
  141. u32 status = 0;
  142. switch (need) {
  143. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  144. zfcp_unit_get(unit);
  145. atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
  146. erp_action = &unit->erp_action;
  147. if (!(atomic_read(&unit->status) & ZFCP_STATUS_COMMON_RUNNING))
  148. status = ZFCP_STATUS_ERP_CLOSE_ONLY;
  149. break;
  150. case ZFCP_ERP_ACTION_REOPEN_PORT:
  151. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  152. zfcp_port_get(port);
  153. zfcp_erp_action_dismiss_port(port);
  154. atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
  155. erp_action = &port->erp_action;
  156. if (!(atomic_read(&port->status) & ZFCP_STATUS_COMMON_RUNNING))
  157. status = ZFCP_STATUS_ERP_CLOSE_ONLY;
  158. break;
  159. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  160. zfcp_adapter_get(adapter);
  161. zfcp_erp_action_dismiss_adapter(adapter);
  162. atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
  163. erp_action = &adapter->erp_action;
  164. if (!(atomic_read(&adapter->status) &
  165. ZFCP_STATUS_COMMON_RUNNING))
  166. status = ZFCP_STATUS_ERP_CLOSE_ONLY;
  167. break;
  168. default:
  169. return NULL;
  170. }
  171. memset(erp_action, 0, sizeof(struct zfcp_erp_action));
  172. erp_action->adapter = adapter;
  173. erp_action->port = port;
  174. erp_action->unit = unit;
  175. erp_action->action = need;
  176. erp_action->status = status;
  177. return erp_action;
  178. }
  179. static int zfcp_erp_action_enqueue(int want, struct zfcp_adapter *adapter,
  180. struct zfcp_port *port,
  181. struct zfcp_unit *unit, u8 id, void *ref)
  182. {
  183. int retval = 1, need;
  184. struct zfcp_erp_action *act = NULL;
  185. if (!(atomic_read(&adapter->status) &
  186. ZFCP_STATUS_ADAPTER_ERP_THREAD_UP))
  187. return -EIO;
  188. need = zfcp_erp_required_act(want, adapter, port, unit);
  189. if (!need)
  190. goto out;
  191. atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
  192. act = zfcp_erp_setup_act(need, adapter, port, unit);
  193. if (!act)
  194. goto out;
  195. ++adapter->erp_total_count;
  196. list_add_tail(&act->list, &adapter->erp_ready_head);
  197. up(&adapter->erp_ready_sem);
  198. zfcp_rec_dbf_event_thread(1, adapter);
  199. retval = 0;
  200. out:
  201. zfcp_rec_dbf_event_trigger(id, ref, want, need, act,
  202. adapter, port, unit);
  203. return retval;
  204. }
  205. static int _zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter,
  206. int clear_mask, u8 id, void *ref)
  207. {
  208. zfcp_erp_adapter_block(adapter, clear_mask);
  209. /* ensure propagation of failed status to new devices */
  210. if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
  211. zfcp_erp_adapter_failed(adapter, 13, NULL);
  212. return -EIO;
  213. }
  214. return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER,
  215. adapter, NULL, NULL, id, ref);
  216. }
  217. /**
  218. * zfcp_erp_adapter_reopen - Reopen adapter.
  219. * @adapter: Adapter to reopen.
  220. * @clear: Status flags to clear.
  221. * @id: Id for debug trace event.
  222. * @ref: Reference for debug trace event.
  223. */
  224. void zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter, int clear,
  225. u8 id, void *ref)
  226. {
  227. unsigned long flags;
  228. read_lock_irqsave(&zfcp_data.config_lock, flags);
  229. write_lock(&adapter->erp_lock);
  230. _zfcp_erp_adapter_reopen(adapter, clear, id, ref);
  231. write_unlock(&adapter->erp_lock);
  232. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  233. }
  234. /**
  235. * zfcp_erp_adapter_shutdown - Shutdown adapter.
  236. * @adapter: Adapter to shut down.
  237. * @clear: Status flags to clear.
  238. * @id: Id for debug trace event.
  239. * @ref: Reference for debug trace event.
  240. */
  241. void zfcp_erp_adapter_shutdown(struct zfcp_adapter *adapter, int clear,
  242. u8 id, void *ref)
  243. {
  244. int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
  245. zfcp_erp_adapter_reopen(adapter, clear | flags, id, ref);
  246. }
  247. /**
  248. * zfcp_erp_port_shutdown - Shutdown port
  249. * @port: Port to shut down.
  250. * @clear: Status flags to clear.
  251. * @id: Id for debug trace event.
  252. * @ref: Reference for debug trace event.
  253. */
  254. void zfcp_erp_port_shutdown(struct zfcp_port *port, int clear, u8 id, void *ref)
  255. {
  256. int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
  257. zfcp_erp_port_reopen(port, clear | flags, id, ref);
  258. }
  259. /**
  260. * zfcp_erp_unit_shutdown - Shutdown unit
  261. * @unit: Unit to shut down.
  262. * @clear: Status flags to clear.
  263. * @id: Id for debug trace event.
  264. * @ref: Reference for debug trace event.
  265. */
  266. void zfcp_erp_unit_shutdown(struct zfcp_unit *unit, int clear, u8 id, void *ref)
  267. {
  268. int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
  269. zfcp_erp_unit_reopen(unit, clear | flags, id, ref);
  270. }
  271. static void zfcp_erp_port_block(struct zfcp_port *port, int clear)
  272. {
  273. zfcp_erp_modify_port_status(port, 17, NULL,
  274. ZFCP_STATUS_COMMON_UNBLOCKED | clear,
  275. ZFCP_CLEAR);
  276. }
  277. static void _zfcp_erp_port_forced_reopen(struct zfcp_port *port,
  278. int clear, u8 id, void *ref)
  279. {
  280. zfcp_erp_port_block(port, clear);
  281. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
  282. return;
  283. zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED,
  284. port->adapter, port, NULL, id, ref);
  285. }
  286. /**
  287. * zfcp_erp_port_forced_reopen - Forced close of port and open again
  288. * @port: Port to force close and to reopen.
  289. * @id: Id for debug trace event.
  290. * @ref: Reference for debug trace event.
  291. */
  292. void zfcp_erp_port_forced_reopen(struct zfcp_port *port, int clear, u8 id,
  293. void *ref)
  294. {
  295. unsigned long flags;
  296. struct zfcp_adapter *adapter = port->adapter;
  297. read_lock_irqsave(&zfcp_data.config_lock, flags);
  298. write_lock(&adapter->erp_lock);
  299. _zfcp_erp_port_forced_reopen(port, clear, id, ref);
  300. write_unlock(&adapter->erp_lock);
  301. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  302. }
  303. static int _zfcp_erp_port_reopen(struct zfcp_port *port, int clear, u8 id,
  304. void *ref)
  305. {
  306. zfcp_erp_port_block(port, clear);
  307. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
  308. /* ensure propagation of failed status to new devices */
  309. zfcp_erp_port_failed(port, 14, NULL);
  310. return -EIO;
  311. }
  312. return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT,
  313. port->adapter, port, NULL, id, ref);
  314. }
  315. /**
  316. * zfcp_erp_port_reopen - trigger remote port recovery
  317. * @port: port to recover
  318. * @clear_mask: flags in port status to be cleared
  319. *
  320. * Returns 0 if recovery has been triggered, < 0 if not.
  321. */
  322. int zfcp_erp_port_reopen(struct zfcp_port *port, int clear, u8 id, void *ref)
  323. {
  324. unsigned long flags;
  325. int retval;
  326. struct zfcp_adapter *adapter = port->adapter;
  327. read_lock_irqsave(&zfcp_data.config_lock, flags);
  328. write_lock(&adapter->erp_lock);
  329. retval = _zfcp_erp_port_reopen(port, clear, id, ref);
  330. write_unlock(&adapter->erp_lock);
  331. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  332. return retval;
  333. }
  334. static void zfcp_erp_unit_block(struct zfcp_unit *unit, int clear_mask)
  335. {
  336. zfcp_erp_modify_unit_status(unit, 19, NULL,
  337. ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
  338. ZFCP_CLEAR);
  339. }
  340. static void _zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear, u8 id,
  341. void *ref)
  342. {
  343. struct zfcp_adapter *adapter = unit->port->adapter;
  344. zfcp_erp_unit_block(unit, clear);
  345. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
  346. return;
  347. zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT,
  348. adapter, unit->port, unit, id, ref);
  349. }
  350. /**
  351. * zfcp_erp_unit_reopen - initiate reopen of a unit
  352. * @unit: unit to be reopened
  353. * @clear_mask: specifies flags in unit status to be cleared
  354. * Return: 0 on success, < 0 on error
  355. */
  356. void zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear, u8 id, void *ref)
  357. {
  358. unsigned long flags;
  359. struct zfcp_port *port = unit->port;
  360. struct zfcp_adapter *adapter = port->adapter;
  361. read_lock_irqsave(&zfcp_data.config_lock, flags);
  362. write_lock(&adapter->erp_lock);
  363. _zfcp_erp_unit_reopen(unit, clear, id, ref);
  364. write_unlock(&adapter->erp_lock);
  365. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  366. }
  367. static int status_change_set(unsigned long mask, atomic_t *status)
  368. {
  369. return (atomic_read(status) ^ mask) & mask;
  370. }
  371. static int status_change_clear(unsigned long mask, atomic_t *status)
  372. {
  373. return atomic_read(status) & mask;
  374. }
  375. static void zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter)
  376. {
  377. if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status))
  378. zfcp_rec_dbf_event_adapter(16, NULL, adapter);
  379. atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status);
  380. }
  381. static void zfcp_erp_port_unblock(struct zfcp_port *port)
  382. {
  383. if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status))
  384. zfcp_rec_dbf_event_port(18, NULL, port);
  385. atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status);
  386. }
  387. static void zfcp_erp_unit_unblock(struct zfcp_unit *unit)
  388. {
  389. if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status))
  390. zfcp_rec_dbf_event_unit(20, NULL, unit);
  391. atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status);
  392. }
  393. static void zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
  394. {
  395. list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
  396. zfcp_rec_dbf_event_action(145, erp_action);
  397. }
  398. static void zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *act)
  399. {
  400. struct zfcp_adapter *adapter = act->adapter;
  401. if (!act->fsf_req)
  402. return;
  403. spin_lock(&adapter->req_list_lock);
  404. if (zfcp_reqlist_find_safe(adapter, act->fsf_req) &&
  405. act->fsf_req->erp_action == act) {
  406. if (act->status & (ZFCP_STATUS_ERP_DISMISSED |
  407. ZFCP_STATUS_ERP_TIMEDOUT)) {
  408. act->fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
  409. zfcp_rec_dbf_event_action(142, act);
  410. act->fsf_req->erp_action = NULL;
  411. }
  412. if (act->status & ZFCP_STATUS_ERP_TIMEDOUT)
  413. zfcp_rec_dbf_event_action(143, act);
  414. if (act->fsf_req->status & (ZFCP_STATUS_FSFREQ_COMPLETED |
  415. ZFCP_STATUS_FSFREQ_DISMISSED))
  416. act->fsf_req = NULL;
  417. } else
  418. act->fsf_req = NULL;
  419. spin_unlock(&adapter->req_list_lock);
  420. }
  421. /**
  422. * zfcp_erp_notify - Trigger ERP action.
  423. * @erp_action: ERP action to continue.
  424. * @set_mask: ERP action status flags to set.
  425. */
  426. void zfcp_erp_notify(struct zfcp_erp_action *erp_action, unsigned long set_mask)
  427. {
  428. struct zfcp_adapter *adapter = erp_action->adapter;
  429. unsigned long flags;
  430. write_lock_irqsave(&adapter->erp_lock, flags);
  431. if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
  432. erp_action->status |= set_mask;
  433. zfcp_erp_action_ready(erp_action);
  434. }
  435. write_unlock_irqrestore(&adapter->erp_lock, flags);
  436. }
  437. /**
  438. * zfcp_erp_timeout_handler - Trigger ERP action from timed out ERP request
  439. * @data: ERP action (from timer data)
  440. */
  441. void zfcp_erp_timeout_handler(unsigned long data)
  442. {
  443. struct zfcp_erp_action *act = (struct zfcp_erp_action *) data;
  444. zfcp_erp_notify(act, ZFCP_STATUS_ERP_TIMEDOUT);
  445. }
  446. static void zfcp_erp_memwait_handler(unsigned long data)
  447. {
  448. zfcp_erp_notify((struct zfcp_erp_action *)data, 0);
  449. }
  450. static void zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
  451. {
  452. init_timer(&erp_action->timer);
  453. erp_action->timer.function = zfcp_erp_memwait_handler;
  454. erp_action->timer.data = (unsigned long) erp_action;
  455. erp_action->timer.expires = jiffies + HZ;
  456. add_timer(&erp_action->timer);
  457. }
  458. static void _zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter,
  459. int clear, u8 id, void *ref)
  460. {
  461. struct zfcp_port *port;
  462. list_for_each_entry(port, &adapter->port_list_head, list)
  463. _zfcp_erp_port_reopen(port, clear, id, ref);
  464. }
  465. static void _zfcp_erp_unit_reopen_all(struct zfcp_port *port, int clear, u8 id,
  466. void *ref)
  467. {
  468. struct zfcp_unit *unit;
  469. list_for_each_entry(unit, &port->unit_list_head, list)
  470. _zfcp_erp_unit_reopen(unit, clear, id, ref);
  471. }
  472. static void zfcp_erp_strategy_followup_actions(struct zfcp_erp_action *act)
  473. {
  474. struct zfcp_adapter *adapter = act->adapter;
  475. struct zfcp_port *port = act->port;
  476. struct zfcp_unit *unit = act->unit;
  477. u32 status = act->status;
  478. /* initiate follow-up actions depending on success of finished action */
  479. switch (act->action) {
  480. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  481. if (status == ZFCP_ERP_SUCCEEDED)
  482. _zfcp_erp_port_reopen_all(adapter, 0, 70, NULL);
  483. else
  484. _zfcp_erp_adapter_reopen(adapter, 0, 71, NULL);
  485. break;
  486. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  487. if (status == ZFCP_ERP_SUCCEEDED)
  488. _zfcp_erp_port_reopen(port, 0, 72, NULL);
  489. else
  490. _zfcp_erp_adapter_reopen(adapter, 0, 73, NULL);
  491. break;
  492. case ZFCP_ERP_ACTION_REOPEN_PORT:
  493. if (status == ZFCP_ERP_SUCCEEDED)
  494. _zfcp_erp_unit_reopen_all(port, 0, 74, NULL);
  495. else
  496. _zfcp_erp_port_forced_reopen(port, 0, 75, NULL);
  497. break;
  498. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  499. if (status != ZFCP_ERP_SUCCEEDED)
  500. _zfcp_erp_port_reopen(unit->port, 0, 76, NULL);
  501. break;
  502. }
  503. }
  504. static void zfcp_erp_wakeup(struct zfcp_adapter *adapter)
  505. {
  506. unsigned long flags;
  507. read_lock_irqsave(&zfcp_data.config_lock, flags);
  508. read_lock(&adapter->erp_lock);
  509. if (list_empty(&adapter->erp_ready_head) &&
  510. list_empty(&adapter->erp_running_head)) {
  511. atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
  512. &adapter->status);
  513. wake_up(&adapter->erp_done_wqh);
  514. }
  515. read_unlock(&adapter->erp_lock);
  516. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  517. }
  518. static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *act)
  519. {
  520. if (zfcp_qdio_open(act->adapter))
  521. return ZFCP_ERP_FAILED;
  522. init_waitqueue_head(&act->adapter->request_wq);
  523. atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &act->adapter->status);
  524. return ZFCP_ERP_SUCCEEDED;
  525. }
  526. static void zfcp_erp_enqueue_ptp_port(struct zfcp_adapter *adapter)
  527. {
  528. struct zfcp_port *port;
  529. port = zfcp_port_enqueue(adapter, adapter->peer_wwpn, 0,
  530. adapter->peer_d_id);
  531. if (IS_ERR(port)) /* error or port already attached */
  532. return;
  533. _zfcp_erp_port_reopen(port, 0, 150, NULL);
  534. }
  535. static int zfcp_erp_adapter_strat_fsf_xconf(struct zfcp_erp_action *erp_action)
  536. {
  537. int retries;
  538. int sleep = 1;
  539. struct zfcp_adapter *adapter = erp_action->adapter;
  540. atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
  541. for (retries = 7; retries; retries--) {
  542. atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  543. &adapter->status);
  544. write_lock_irq(&adapter->erp_lock);
  545. zfcp_erp_action_to_running(erp_action);
  546. write_unlock_irq(&adapter->erp_lock);
  547. if (zfcp_fsf_exchange_config_data(erp_action)) {
  548. atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  549. &adapter->status);
  550. return ZFCP_ERP_FAILED;
  551. }
  552. zfcp_rec_dbf_event_thread_lock(6, adapter);
  553. down(&adapter->erp_ready_sem);
  554. zfcp_rec_dbf_event_thread_lock(7, adapter);
  555. if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT)
  556. break;
  557. if (!(atomic_read(&adapter->status) &
  558. ZFCP_STATUS_ADAPTER_HOST_CON_INIT))
  559. break;
  560. ssleep(sleep);
  561. sleep *= 2;
  562. }
  563. atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  564. &adapter->status);
  565. if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_XCONFIG_OK))
  566. return ZFCP_ERP_FAILED;
  567. if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP)
  568. zfcp_erp_enqueue_ptp_port(adapter);
  569. return ZFCP_ERP_SUCCEEDED;
  570. }
  571. static int zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *act)
  572. {
  573. int ret;
  574. struct zfcp_adapter *adapter = act->adapter;
  575. write_lock_irq(&adapter->erp_lock);
  576. zfcp_erp_action_to_running(act);
  577. write_unlock_irq(&adapter->erp_lock);
  578. ret = zfcp_fsf_exchange_port_data(act);
  579. if (ret == -EOPNOTSUPP)
  580. return ZFCP_ERP_SUCCEEDED;
  581. if (ret)
  582. return ZFCP_ERP_FAILED;
  583. zfcp_rec_dbf_event_thread_lock(8, adapter);
  584. down(&adapter->erp_ready_sem);
  585. zfcp_rec_dbf_event_thread_lock(9, adapter);
  586. if (act->status & ZFCP_STATUS_ERP_TIMEDOUT)
  587. return ZFCP_ERP_FAILED;
  588. return ZFCP_ERP_SUCCEEDED;
  589. }
  590. static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *act)
  591. {
  592. if (zfcp_erp_adapter_strat_fsf_xconf(act) == ZFCP_ERP_FAILED)
  593. return ZFCP_ERP_FAILED;
  594. if (zfcp_erp_adapter_strategy_open_fsf_xport(act) == ZFCP_ERP_FAILED)
  595. return ZFCP_ERP_FAILED;
  596. atomic_set(&act->adapter->stat_miss, 16);
  597. if (zfcp_status_read_refill(act->adapter))
  598. return ZFCP_ERP_FAILED;
  599. return ZFCP_ERP_SUCCEEDED;
  600. }
  601. static int zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *act,
  602. int close)
  603. {
  604. int retval = ZFCP_ERP_SUCCEEDED;
  605. struct zfcp_adapter *adapter = act->adapter;
  606. if (close)
  607. goto close_only;
  608. retval = zfcp_erp_adapter_strategy_open_qdio(act);
  609. if (retval != ZFCP_ERP_SUCCEEDED)
  610. goto failed_qdio;
  611. retval = zfcp_erp_adapter_strategy_open_fsf(act);
  612. if (retval != ZFCP_ERP_SUCCEEDED)
  613. goto failed_openfcp;
  614. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &act->adapter->status);
  615. return ZFCP_ERP_SUCCEEDED;
  616. close_only:
  617. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  618. &act->adapter->status);
  619. failed_openfcp:
  620. /* close queues to ensure that buffers are not accessed by adapter */
  621. zfcp_qdio_close(adapter);
  622. zfcp_fsf_req_dismiss_all(adapter);
  623. adapter->fsf_req_seq_no = 0;
  624. /* all ports and units are closed */
  625. zfcp_erp_modify_adapter_status(adapter, 24, NULL,
  626. ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR);
  627. failed_qdio:
  628. atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
  629. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
  630. &act->adapter->status);
  631. return retval;
  632. }
  633. static int zfcp_erp_adapter_strategy(struct zfcp_erp_action *act)
  634. {
  635. int retval;
  636. zfcp_erp_adapter_strategy_generic(act, 1); /* close */
  637. if (act->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
  638. return ZFCP_ERP_EXIT;
  639. retval = zfcp_erp_adapter_strategy_generic(act, 0); /* open */
  640. if (retval == ZFCP_ERP_FAILED)
  641. ssleep(8);
  642. return retval;
  643. }
  644. static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *act)
  645. {
  646. int retval;
  647. retval = zfcp_fsf_close_physical_port(act);
  648. if (retval == -ENOMEM)
  649. return ZFCP_ERP_NOMEM;
  650. act->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
  651. if (retval)
  652. return ZFCP_ERP_FAILED;
  653. return ZFCP_ERP_CONTINUES;
  654. }
  655. static void zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
  656. {
  657. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED, &port->status);
  658. }
  659. static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
  660. {
  661. struct zfcp_port *port = erp_action->port;
  662. int status = atomic_read(&port->status);
  663. switch (erp_action->step) {
  664. case ZFCP_ERP_STEP_UNINITIALIZED:
  665. zfcp_erp_port_strategy_clearstati(port);
  666. if ((status & ZFCP_STATUS_PORT_PHYS_OPEN) &&
  667. (status & ZFCP_STATUS_COMMON_OPEN))
  668. return zfcp_erp_port_forced_strategy_close(erp_action);
  669. else
  670. return ZFCP_ERP_FAILED;
  671. case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
  672. if (status & ZFCP_STATUS_PORT_PHYS_OPEN)
  673. return ZFCP_ERP_SUCCEEDED;
  674. }
  675. return ZFCP_ERP_FAILED;
  676. }
  677. static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
  678. {
  679. int retval;
  680. retval = zfcp_fsf_close_port(erp_action);
  681. if (retval == -ENOMEM)
  682. return ZFCP_ERP_NOMEM;
  683. erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
  684. if (retval)
  685. return ZFCP_ERP_FAILED;
  686. return ZFCP_ERP_CONTINUES;
  687. }
  688. static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
  689. {
  690. int retval;
  691. retval = zfcp_fsf_open_port(erp_action);
  692. if (retval == -ENOMEM)
  693. return ZFCP_ERP_NOMEM;
  694. erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
  695. if (retval)
  696. return ZFCP_ERP_FAILED;
  697. return ZFCP_ERP_CONTINUES;
  698. }
  699. static int zfcp_erp_open_ptp_port(struct zfcp_erp_action *act)
  700. {
  701. struct zfcp_adapter *adapter = act->adapter;
  702. struct zfcp_port *port = act->port;
  703. if (port->wwpn != adapter->peer_wwpn) {
  704. zfcp_erp_port_failed(port, 25, NULL);
  705. return ZFCP_ERP_FAILED;
  706. }
  707. port->d_id = adapter->peer_d_id;
  708. return zfcp_erp_port_strategy_open_port(act);
  709. }
  710. void zfcp_erp_port_strategy_open_lookup(struct work_struct *work)
  711. {
  712. int retval;
  713. struct zfcp_port *port = container_of(work, struct zfcp_port,
  714. gid_pn_work);
  715. retval = zfcp_fc_ns_gid_pn(&port->erp_action);
  716. if (retval == -ENOMEM)
  717. zfcp_erp_notify(&port->erp_action, ZFCP_ERP_NOMEM);
  718. port->erp_action.step = ZFCP_ERP_STEP_NAMESERVER_LOOKUP;
  719. if (retval)
  720. zfcp_erp_notify(&port->erp_action, ZFCP_ERP_FAILED);
  721. }
  722. static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *act)
  723. {
  724. struct zfcp_adapter *adapter = act->adapter;
  725. struct zfcp_port *port = act->port;
  726. int p_status = atomic_read(&port->status);
  727. switch (act->step) {
  728. case ZFCP_ERP_STEP_UNINITIALIZED:
  729. case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
  730. case ZFCP_ERP_STEP_PORT_CLOSING:
  731. if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP)
  732. return zfcp_erp_open_ptp_port(act);
  733. if (!port->d_id) {
  734. queue_work(zfcp_data.work_queue, &port->gid_pn_work);
  735. return ZFCP_ERP_CONTINUES;
  736. }
  737. case ZFCP_ERP_STEP_NAMESERVER_LOOKUP:
  738. if (!port->d_id)
  739. return ZFCP_ERP_FAILED;
  740. return zfcp_erp_port_strategy_open_port(act);
  741. case ZFCP_ERP_STEP_PORT_OPENING:
  742. /* D_ID might have changed during open */
  743. if (p_status & ZFCP_STATUS_COMMON_OPEN) {
  744. if (port->d_id)
  745. return ZFCP_ERP_SUCCEEDED;
  746. else {
  747. act->step = ZFCP_ERP_STEP_PORT_CLOSING;
  748. return ZFCP_ERP_CONTINUES;
  749. }
  750. /* fall through otherwise */
  751. }
  752. }
  753. return ZFCP_ERP_FAILED;
  754. }
  755. static int zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
  756. {
  757. struct zfcp_port *port = erp_action->port;
  758. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC)
  759. goto close_init_done;
  760. switch (erp_action->step) {
  761. case ZFCP_ERP_STEP_UNINITIALIZED:
  762. zfcp_erp_port_strategy_clearstati(port);
  763. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN)
  764. return zfcp_erp_port_strategy_close(erp_action);
  765. break;
  766. case ZFCP_ERP_STEP_PORT_CLOSING:
  767. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN)
  768. return ZFCP_ERP_FAILED;
  769. break;
  770. }
  771. close_init_done:
  772. if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
  773. return ZFCP_ERP_EXIT;
  774. return zfcp_erp_port_strategy_open_common(erp_action);
  775. }
  776. static void zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
  777. {
  778. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  779. ZFCP_STATUS_UNIT_SHARED |
  780. ZFCP_STATUS_UNIT_READONLY,
  781. &unit->status);
  782. }
  783. static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
  784. {
  785. int retval = zfcp_fsf_close_unit(erp_action);
  786. if (retval == -ENOMEM)
  787. return ZFCP_ERP_NOMEM;
  788. erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
  789. if (retval)
  790. return ZFCP_ERP_FAILED;
  791. return ZFCP_ERP_CONTINUES;
  792. }
  793. static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
  794. {
  795. int retval = zfcp_fsf_open_unit(erp_action);
  796. if (retval == -ENOMEM)
  797. return ZFCP_ERP_NOMEM;
  798. erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
  799. if (retval)
  800. return ZFCP_ERP_FAILED;
  801. return ZFCP_ERP_CONTINUES;
  802. }
  803. static int zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
  804. {
  805. struct zfcp_unit *unit = erp_action->unit;
  806. switch (erp_action->step) {
  807. case ZFCP_ERP_STEP_UNINITIALIZED:
  808. zfcp_erp_unit_strategy_clearstati(unit);
  809. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
  810. return zfcp_erp_unit_strategy_close(erp_action);
  811. /* already closed, fall through */
  812. case ZFCP_ERP_STEP_UNIT_CLOSING:
  813. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
  814. return ZFCP_ERP_FAILED;
  815. if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
  816. return ZFCP_ERP_EXIT;
  817. return zfcp_erp_unit_strategy_open(erp_action);
  818. case ZFCP_ERP_STEP_UNIT_OPENING:
  819. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
  820. return ZFCP_ERP_SUCCEEDED;
  821. }
  822. return ZFCP_ERP_FAILED;
  823. }
  824. static int zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
  825. {
  826. switch (result) {
  827. case ZFCP_ERP_SUCCEEDED :
  828. atomic_set(&unit->erp_counter, 0);
  829. zfcp_erp_unit_unblock(unit);
  830. break;
  831. case ZFCP_ERP_FAILED :
  832. atomic_inc(&unit->erp_counter);
  833. if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS) {
  834. dev_err(&unit->port->adapter->ccw_device->dev,
  835. "ERP failed for unit 0x%016Lx on "
  836. "port 0x%016Lx\n",
  837. (unsigned long long)unit->fcp_lun,
  838. (unsigned long long)unit->port->wwpn);
  839. zfcp_erp_unit_failed(unit, 21, NULL);
  840. }
  841. break;
  842. }
  843. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
  844. zfcp_erp_unit_block(unit, 0);
  845. result = ZFCP_ERP_EXIT;
  846. }
  847. return result;
  848. }
  849. static int zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
  850. {
  851. switch (result) {
  852. case ZFCP_ERP_SUCCEEDED :
  853. atomic_set(&port->erp_counter, 0);
  854. zfcp_erp_port_unblock(port);
  855. break;
  856. case ZFCP_ERP_FAILED :
  857. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC) {
  858. zfcp_erp_port_block(port, 0);
  859. result = ZFCP_ERP_EXIT;
  860. }
  861. atomic_inc(&port->erp_counter);
  862. if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS) {
  863. dev_err(&port->adapter->ccw_device->dev,
  864. "ERP failed for remote port 0x%016Lx\n",
  865. (unsigned long long)port->wwpn);
  866. zfcp_erp_port_failed(port, 22, NULL);
  867. }
  868. break;
  869. }
  870. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
  871. zfcp_erp_port_block(port, 0);
  872. result = ZFCP_ERP_EXIT;
  873. }
  874. return result;
  875. }
  876. static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter,
  877. int result)
  878. {
  879. switch (result) {
  880. case ZFCP_ERP_SUCCEEDED :
  881. atomic_set(&adapter->erp_counter, 0);
  882. zfcp_erp_adapter_unblock(adapter);
  883. break;
  884. case ZFCP_ERP_FAILED :
  885. atomic_inc(&adapter->erp_counter);
  886. if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS) {
  887. dev_err(&adapter->ccw_device->dev,
  888. "ERP cannot recover an error "
  889. "on the FCP device\n");
  890. zfcp_erp_adapter_failed(adapter, 23, NULL);
  891. }
  892. break;
  893. }
  894. if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
  895. zfcp_erp_adapter_block(adapter, 0);
  896. result = ZFCP_ERP_EXIT;
  897. }
  898. return result;
  899. }
  900. static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action,
  901. int result)
  902. {
  903. struct zfcp_adapter *adapter = erp_action->adapter;
  904. struct zfcp_port *port = erp_action->port;
  905. struct zfcp_unit *unit = erp_action->unit;
  906. switch (erp_action->action) {
  907. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  908. result = zfcp_erp_strategy_check_unit(unit, result);
  909. break;
  910. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  911. case ZFCP_ERP_ACTION_REOPEN_PORT:
  912. result = zfcp_erp_strategy_check_port(port, result);
  913. break;
  914. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  915. result = zfcp_erp_strategy_check_adapter(adapter, result);
  916. break;
  917. }
  918. return result;
  919. }
  920. static int zfcp_erp_strat_change_det(atomic_t *target_status, u32 erp_status)
  921. {
  922. int status = atomic_read(target_status);
  923. if ((status & ZFCP_STATUS_COMMON_RUNNING) &&
  924. (erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
  925. return 1; /* take it online */
  926. if (!(status & ZFCP_STATUS_COMMON_RUNNING) &&
  927. !(erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
  928. return 1; /* take it offline */
  929. return 0;
  930. }
  931. static int zfcp_erp_strategy_statechange(struct zfcp_erp_action *act, int ret)
  932. {
  933. int action = act->action;
  934. struct zfcp_adapter *adapter = act->adapter;
  935. struct zfcp_port *port = act->port;
  936. struct zfcp_unit *unit = act->unit;
  937. u32 erp_status = act->status;
  938. switch (action) {
  939. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  940. if (zfcp_erp_strat_change_det(&adapter->status, erp_status)) {
  941. _zfcp_erp_adapter_reopen(adapter,
  942. ZFCP_STATUS_COMMON_ERP_FAILED,
  943. 67, NULL);
  944. return ZFCP_ERP_EXIT;
  945. }
  946. break;
  947. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  948. case ZFCP_ERP_ACTION_REOPEN_PORT:
  949. if (zfcp_erp_strat_change_det(&port->status, erp_status)) {
  950. _zfcp_erp_port_reopen(port,
  951. ZFCP_STATUS_COMMON_ERP_FAILED,
  952. 68, NULL);
  953. return ZFCP_ERP_EXIT;
  954. }
  955. break;
  956. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  957. if (zfcp_erp_strat_change_det(&unit->status, erp_status)) {
  958. _zfcp_erp_unit_reopen(unit,
  959. ZFCP_STATUS_COMMON_ERP_FAILED,
  960. 69, NULL);
  961. return ZFCP_ERP_EXIT;
  962. }
  963. break;
  964. }
  965. return ret;
  966. }
  967. static void zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
  968. {
  969. struct zfcp_adapter *adapter = erp_action->adapter;
  970. adapter->erp_total_count--;
  971. if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
  972. adapter->erp_low_mem_count--;
  973. erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
  974. }
  975. list_del(&erp_action->list);
  976. zfcp_rec_dbf_event_action(144, erp_action);
  977. switch (erp_action->action) {
  978. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  979. atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
  980. &erp_action->unit->status);
  981. break;
  982. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  983. case ZFCP_ERP_ACTION_REOPEN_PORT:
  984. atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
  985. &erp_action->port->status);
  986. break;
  987. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  988. atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
  989. &erp_action->adapter->status);
  990. break;
  991. }
  992. }
  993. struct zfcp_erp_add_work {
  994. struct zfcp_unit *unit;
  995. struct work_struct work;
  996. };
  997. static void zfcp_erp_scsi_scan(struct work_struct *work)
  998. {
  999. struct zfcp_erp_add_work *p =
  1000. container_of(work, struct zfcp_erp_add_work, work);
  1001. struct zfcp_unit *unit = p->unit;
  1002. struct fc_rport *rport = unit->port->rport;
  1003. if (rport && rport->port_state == FC_PORTSTATE_ONLINE)
  1004. scsi_scan_target(&rport->dev, 0, rport->scsi_target_id,
  1005. scsilun_to_int((struct scsi_lun *)&unit->fcp_lun), 0);
  1006. atomic_clear_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
  1007. zfcp_unit_put(unit);
  1008. wake_up(&unit->port->adapter->erp_done_wqh);
  1009. kfree(p);
  1010. }
  1011. static void zfcp_erp_schedule_work(struct zfcp_unit *unit)
  1012. {
  1013. struct zfcp_erp_add_work *p;
  1014. p = kzalloc(sizeof(*p), GFP_KERNEL);
  1015. if (!p) {
  1016. dev_err(&unit->port->adapter->ccw_device->dev,
  1017. "Registering unit 0x%016Lx on port 0x%016Lx failed\n",
  1018. (unsigned long long)unit->fcp_lun,
  1019. (unsigned long long)unit->port->wwpn);
  1020. return;
  1021. }
  1022. zfcp_unit_get(unit);
  1023. atomic_set_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
  1024. INIT_WORK(&p->work, zfcp_erp_scsi_scan);
  1025. p->unit = unit;
  1026. queue_work(zfcp_data.work_queue, &p->work);
  1027. }
  1028. static void zfcp_erp_rport_register(struct zfcp_port *port)
  1029. {
  1030. struct fc_rport_identifiers ids;
  1031. ids.node_name = port->wwnn;
  1032. ids.port_name = port->wwpn;
  1033. ids.port_id = port->d_id;
  1034. ids.roles = FC_RPORT_ROLE_FCP_TARGET;
  1035. port->rport = fc_remote_port_add(port->adapter->scsi_host, 0, &ids);
  1036. if (!port->rport) {
  1037. dev_err(&port->adapter->ccw_device->dev,
  1038. "Registering port 0x%016Lx failed\n",
  1039. (unsigned long long)port->wwpn);
  1040. return;
  1041. }
  1042. scsi_target_unblock(&port->rport->dev);
  1043. port->rport->maxframe_size = port->maxframe_size;
  1044. port->rport->supported_classes = port->supported_classes;
  1045. }
  1046. static void zfcp_erp_rports_del(struct zfcp_adapter *adapter)
  1047. {
  1048. struct zfcp_port *port;
  1049. list_for_each_entry(port, &adapter->port_list_head, list) {
  1050. if (!port->rport)
  1051. continue;
  1052. fc_remote_port_delete(port->rport);
  1053. port->rport = NULL;
  1054. }
  1055. }
  1056. static void zfcp_erp_action_cleanup(struct zfcp_erp_action *act, int result)
  1057. {
  1058. struct zfcp_adapter *adapter = act->adapter;
  1059. struct zfcp_port *port = act->port;
  1060. struct zfcp_unit *unit = act->unit;
  1061. switch (act->action) {
  1062. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  1063. if ((result == ZFCP_ERP_SUCCEEDED) &&
  1064. !unit->device && port->rport) {
  1065. if (!(atomic_read(&unit->status) &
  1066. ZFCP_STATUS_UNIT_SCSI_WORK_PENDING))
  1067. zfcp_erp_schedule_work(unit);
  1068. }
  1069. zfcp_unit_put(unit);
  1070. break;
  1071. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  1072. case ZFCP_ERP_ACTION_REOPEN_PORT:
  1073. if ((result == ZFCP_ERP_SUCCEEDED) && !port->rport)
  1074. zfcp_erp_rport_register(port);
  1075. if ((result != ZFCP_ERP_SUCCEEDED) && port->rport) {
  1076. fc_remote_port_delete(port->rport);
  1077. port->rport = NULL;
  1078. }
  1079. zfcp_port_put(port);
  1080. break;
  1081. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  1082. if (result != ZFCP_ERP_SUCCEEDED) {
  1083. unregister_service_level(&adapter->service_level);
  1084. zfcp_erp_rports_del(adapter);
  1085. } else {
  1086. register_service_level(&adapter->service_level);
  1087. schedule_work(&adapter->scan_work);
  1088. }
  1089. zfcp_adapter_put(adapter);
  1090. break;
  1091. }
  1092. }
  1093. static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
  1094. {
  1095. switch (erp_action->action) {
  1096. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  1097. return zfcp_erp_adapter_strategy(erp_action);
  1098. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  1099. return zfcp_erp_port_forced_strategy(erp_action);
  1100. case ZFCP_ERP_ACTION_REOPEN_PORT:
  1101. return zfcp_erp_port_strategy(erp_action);
  1102. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  1103. return zfcp_erp_unit_strategy(erp_action);
  1104. }
  1105. return ZFCP_ERP_FAILED;
  1106. }
  1107. static int zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
  1108. {
  1109. int retval;
  1110. struct zfcp_adapter *adapter = erp_action->adapter;
  1111. unsigned long flags;
  1112. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1113. write_lock(&adapter->erp_lock);
  1114. zfcp_erp_strategy_check_fsfreq(erp_action);
  1115. if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
  1116. zfcp_erp_action_dequeue(erp_action);
  1117. retval = ZFCP_ERP_DISMISSED;
  1118. goto unlock;
  1119. }
  1120. zfcp_erp_action_to_running(erp_action);
  1121. /* no lock to allow for blocking operations */
  1122. write_unlock(&adapter->erp_lock);
  1123. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1124. retval = zfcp_erp_strategy_do_action(erp_action);
  1125. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1126. write_lock(&adapter->erp_lock);
  1127. if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED)
  1128. retval = ZFCP_ERP_CONTINUES;
  1129. switch (retval) {
  1130. case ZFCP_ERP_NOMEM:
  1131. if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
  1132. ++adapter->erp_low_mem_count;
  1133. erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
  1134. }
  1135. if (adapter->erp_total_count == adapter->erp_low_mem_count)
  1136. _zfcp_erp_adapter_reopen(adapter, 0, 66, NULL);
  1137. else {
  1138. zfcp_erp_strategy_memwait(erp_action);
  1139. retval = ZFCP_ERP_CONTINUES;
  1140. }
  1141. goto unlock;
  1142. case ZFCP_ERP_CONTINUES:
  1143. if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
  1144. --adapter->erp_low_mem_count;
  1145. erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
  1146. }
  1147. goto unlock;
  1148. }
  1149. retval = zfcp_erp_strategy_check_target(erp_action, retval);
  1150. zfcp_erp_action_dequeue(erp_action);
  1151. retval = zfcp_erp_strategy_statechange(erp_action, retval);
  1152. if (retval == ZFCP_ERP_EXIT)
  1153. goto unlock;
  1154. zfcp_erp_strategy_followup_actions(erp_action);
  1155. unlock:
  1156. write_unlock(&adapter->erp_lock);
  1157. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1158. if (retval != ZFCP_ERP_CONTINUES)
  1159. zfcp_erp_action_cleanup(erp_action, retval);
  1160. return retval;
  1161. }
  1162. static int zfcp_erp_thread(void *data)
  1163. {
  1164. struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
  1165. struct list_head *next;
  1166. struct zfcp_erp_action *act;
  1167. unsigned long flags;
  1168. int ignore;
  1169. daemonize("zfcperp%s", dev_name(&adapter->ccw_device->dev));
  1170. /* Block all signals */
  1171. siginitsetinv(&current->blocked, 0);
  1172. atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
  1173. wake_up(&adapter->erp_thread_wqh);
  1174. while (!(atomic_read(&adapter->status) &
  1175. ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL)) {
  1176. write_lock_irqsave(&adapter->erp_lock, flags);
  1177. next = adapter->erp_ready_head.next;
  1178. write_unlock_irqrestore(&adapter->erp_lock, flags);
  1179. if (next != &adapter->erp_ready_head) {
  1180. act = list_entry(next, struct zfcp_erp_action, list);
  1181. /* there is more to come after dismission, no notify */
  1182. if (zfcp_erp_strategy(act) != ZFCP_ERP_DISMISSED)
  1183. zfcp_erp_wakeup(adapter);
  1184. }
  1185. zfcp_rec_dbf_event_thread_lock(4, adapter);
  1186. ignore = down_interruptible(&adapter->erp_ready_sem);
  1187. zfcp_rec_dbf_event_thread_lock(5, adapter);
  1188. }
  1189. atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
  1190. wake_up(&adapter->erp_thread_wqh);
  1191. return 0;
  1192. }
  1193. /**
  1194. * zfcp_erp_thread_setup - Start ERP thread for adapter
  1195. * @adapter: Adapter to start the ERP thread for
  1196. *
  1197. * Returns 0 on success or error code from kernel_thread()
  1198. */
  1199. int zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
  1200. {
  1201. int retval;
  1202. atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
  1203. retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD);
  1204. if (retval < 0) {
  1205. dev_err(&adapter->ccw_device->dev,
  1206. "Creating an ERP thread for the FCP device failed.\n");
  1207. return retval;
  1208. }
  1209. wait_event(adapter->erp_thread_wqh,
  1210. atomic_read(&adapter->status) &
  1211. ZFCP_STATUS_ADAPTER_ERP_THREAD_UP);
  1212. return 0;
  1213. }
  1214. /**
  1215. * zfcp_erp_thread_kill - Stop ERP thread.
  1216. * @adapter: Adapter where the ERP thread should be stopped.
  1217. *
  1218. * The caller of this routine ensures that the specified adapter has
  1219. * been shut down and that this operation has been completed. Thus,
  1220. * there are no pending erp_actions which would need to be handled
  1221. * here.
  1222. */
  1223. void zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
  1224. {
  1225. atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status);
  1226. up(&adapter->erp_ready_sem);
  1227. zfcp_rec_dbf_event_thread_lock(3, adapter);
  1228. wait_event(adapter->erp_thread_wqh,
  1229. !(atomic_read(&adapter->status) &
  1230. ZFCP_STATUS_ADAPTER_ERP_THREAD_UP));
  1231. atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
  1232. &adapter->status);
  1233. }
  1234. /**
  1235. * zfcp_erp_adapter_failed - Set adapter status to failed.
  1236. * @adapter: Failed adapter.
  1237. * @id: Event id for debug trace.
  1238. * @ref: Reference for debug trace.
  1239. */
  1240. void zfcp_erp_adapter_failed(struct zfcp_adapter *adapter, u8 id, void *ref)
  1241. {
  1242. zfcp_erp_modify_adapter_status(adapter, id, ref,
  1243. ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
  1244. }
  1245. /**
  1246. * zfcp_erp_port_failed - Set port status to failed.
  1247. * @port: Failed port.
  1248. * @id: Event id for debug trace.
  1249. * @ref: Reference for debug trace.
  1250. */
  1251. void zfcp_erp_port_failed(struct zfcp_port *port, u8 id, void *ref)
  1252. {
  1253. zfcp_erp_modify_port_status(port, id, ref,
  1254. ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
  1255. }
  1256. /**
  1257. * zfcp_erp_unit_failed - Set unit status to failed.
  1258. * @unit: Failed unit.
  1259. * @id: Event id for debug trace.
  1260. * @ref: Reference for debug trace.
  1261. */
  1262. void zfcp_erp_unit_failed(struct zfcp_unit *unit, u8 id, void *ref)
  1263. {
  1264. zfcp_erp_modify_unit_status(unit, id, ref,
  1265. ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
  1266. }
  1267. /**
  1268. * zfcp_erp_wait - wait for completion of error recovery on an adapter
  1269. * @adapter: adapter for which to wait for completion of its error recovery
  1270. */
  1271. void zfcp_erp_wait(struct zfcp_adapter *adapter)
  1272. {
  1273. wait_event(adapter->erp_done_wqh,
  1274. !(atomic_read(&adapter->status) &
  1275. ZFCP_STATUS_ADAPTER_ERP_PENDING));
  1276. }
  1277. /**
  1278. * zfcp_erp_modify_adapter_status - change adapter status bits
  1279. * @adapter: adapter to change the status
  1280. * @id: id for the debug trace
  1281. * @ref: reference for the debug trace
  1282. * @mask: status bits to change
  1283. * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
  1284. *
  1285. * Changes in common status bits are propagated to attached ports and units.
  1286. */
  1287. void zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter, u8 id,
  1288. void *ref, u32 mask, int set_or_clear)
  1289. {
  1290. struct zfcp_port *port;
  1291. u32 common_mask = mask & ZFCP_COMMON_FLAGS;
  1292. if (set_or_clear == ZFCP_SET) {
  1293. if (status_change_set(mask, &adapter->status))
  1294. zfcp_rec_dbf_event_adapter(id, ref, adapter);
  1295. atomic_set_mask(mask, &adapter->status);
  1296. } else {
  1297. if (status_change_clear(mask, &adapter->status))
  1298. zfcp_rec_dbf_event_adapter(id, ref, adapter);
  1299. atomic_clear_mask(mask, &adapter->status);
  1300. if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
  1301. atomic_set(&adapter->erp_counter, 0);
  1302. }
  1303. if (common_mask)
  1304. list_for_each_entry(port, &adapter->port_list_head, list)
  1305. zfcp_erp_modify_port_status(port, id, ref, common_mask,
  1306. set_or_clear);
  1307. }
  1308. /**
  1309. * zfcp_erp_modify_port_status - change port status bits
  1310. * @port: port to change the status bits
  1311. * @id: id for the debug trace
  1312. * @ref: reference for the debug trace
  1313. * @mask: status bits to change
  1314. * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
  1315. *
  1316. * Changes in common status bits are propagated to attached units.
  1317. */
  1318. void zfcp_erp_modify_port_status(struct zfcp_port *port, u8 id, void *ref,
  1319. u32 mask, int set_or_clear)
  1320. {
  1321. struct zfcp_unit *unit;
  1322. u32 common_mask = mask & ZFCP_COMMON_FLAGS;
  1323. if (set_or_clear == ZFCP_SET) {
  1324. if (status_change_set(mask, &port->status))
  1325. zfcp_rec_dbf_event_port(id, ref, port);
  1326. atomic_set_mask(mask, &port->status);
  1327. } else {
  1328. if (status_change_clear(mask, &port->status))
  1329. zfcp_rec_dbf_event_port(id, ref, port);
  1330. atomic_clear_mask(mask, &port->status);
  1331. if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
  1332. atomic_set(&port->erp_counter, 0);
  1333. }
  1334. if (common_mask)
  1335. list_for_each_entry(unit, &port->unit_list_head, list)
  1336. zfcp_erp_modify_unit_status(unit, id, ref, common_mask,
  1337. set_or_clear);
  1338. }
  1339. /**
  1340. * zfcp_erp_modify_unit_status - change unit status bits
  1341. * @unit: unit to change the status bits
  1342. * @id: id for the debug trace
  1343. * @ref: reference for the debug trace
  1344. * @mask: status bits to change
  1345. * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
  1346. */
  1347. void zfcp_erp_modify_unit_status(struct zfcp_unit *unit, u8 id, void *ref,
  1348. u32 mask, int set_or_clear)
  1349. {
  1350. if (set_or_clear == ZFCP_SET) {
  1351. if (status_change_set(mask, &unit->status))
  1352. zfcp_rec_dbf_event_unit(id, ref, unit);
  1353. atomic_set_mask(mask, &unit->status);
  1354. } else {
  1355. if (status_change_clear(mask, &unit->status))
  1356. zfcp_rec_dbf_event_unit(id, ref, unit);
  1357. atomic_clear_mask(mask, &unit->status);
  1358. if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
  1359. atomic_set(&unit->erp_counter, 0);
  1360. }
  1361. }
  1362. }
  1363. /**
  1364. * zfcp_erp_port_boxed - Mark port as "boxed" and start ERP
  1365. * @port: The "boxed" port.
  1366. * @id: The debug trace id.
  1367. * @id: Reference for the debug trace.
  1368. */
  1369. void zfcp_erp_port_boxed(struct zfcp_port *port, u8 id, void *ref)
  1370. {
  1371. unsigned long flags;
  1372. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1373. zfcp_erp_modify_port_status(port, id, ref,
  1374. ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
  1375. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1376. zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
  1377. }
  1378. /**
  1379. * zfcp_erp_unit_boxed - Mark unit as "boxed" and start ERP
  1380. * @port: The "boxed" unit.
  1381. * @id: The debug trace id.
  1382. * @id: Reference for the debug trace.
  1383. */
  1384. void zfcp_erp_unit_boxed(struct zfcp_unit *unit, u8 id, void *ref)
  1385. {
  1386. zfcp_erp_modify_unit_status(unit, id, ref,
  1387. ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
  1388. zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
  1389. }
  1390. /**
  1391. * zfcp_erp_port_access_denied - Adapter denied access to port.
  1392. * @port: port where access has been denied
  1393. * @id: id for debug trace
  1394. * @ref: reference for debug trace
  1395. *
  1396. * Since the adapter has denied access, stop using the port and the
  1397. * attached units.
  1398. */
  1399. void zfcp_erp_port_access_denied(struct zfcp_port *port, u8 id, void *ref)
  1400. {
  1401. unsigned long flags;
  1402. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1403. zfcp_erp_modify_port_status(port, id, ref,
  1404. ZFCP_STATUS_COMMON_ERP_FAILED |
  1405. ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
  1406. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1407. }
  1408. /**
  1409. * zfcp_erp_unit_access_denied - Adapter denied access to unit.
  1410. * @unit: unit where access has been denied
  1411. * @id: id for debug trace
  1412. * @ref: reference for debug trace
  1413. *
  1414. * Since the adapter has denied access, stop using the unit.
  1415. */
  1416. void zfcp_erp_unit_access_denied(struct zfcp_unit *unit, u8 id, void *ref)
  1417. {
  1418. zfcp_erp_modify_unit_status(unit, id, ref,
  1419. ZFCP_STATUS_COMMON_ERP_FAILED |
  1420. ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
  1421. }
  1422. static void zfcp_erp_unit_access_changed(struct zfcp_unit *unit, u8 id,
  1423. void *ref)
  1424. {
  1425. int status = atomic_read(&unit->status);
  1426. if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1427. ZFCP_STATUS_COMMON_ACCESS_BOXED)))
  1428. return;
  1429. zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
  1430. }
  1431. static void zfcp_erp_port_access_changed(struct zfcp_port *port, u8 id,
  1432. void *ref)
  1433. {
  1434. struct zfcp_unit *unit;
  1435. int status = atomic_read(&port->status);
  1436. if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1437. ZFCP_STATUS_COMMON_ACCESS_BOXED))) {
  1438. list_for_each_entry(unit, &port->unit_list_head, list)
  1439. zfcp_erp_unit_access_changed(unit, id, ref);
  1440. return;
  1441. }
  1442. zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
  1443. }
  1444. /**
  1445. * zfcp_erp_adapter_access_changed - Process change in adapter ACT
  1446. * @adapter: Adapter where the Access Control Table (ACT) changed
  1447. * @id: Id for debug trace
  1448. * @ref: Reference for debug trace
  1449. */
  1450. void zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter, u8 id,
  1451. void *ref)
  1452. {
  1453. struct zfcp_port *port;
  1454. unsigned long flags;
  1455. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
  1456. return;
  1457. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1458. list_for_each_entry(port, &adapter->port_list_head, list)
  1459. zfcp_erp_port_access_changed(port, id, ref);
  1460. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1461. }