zfcp_erp.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717
  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 |
  658. ZFCP_STATUS_PORT_PHYS_CLOSING |
  659. ZFCP_STATUS_PORT_INVALID_WWPN,
  660. &port->status);
  661. }
  662. static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
  663. {
  664. struct zfcp_port *port = erp_action->port;
  665. int status = atomic_read(&port->status);
  666. switch (erp_action->step) {
  667. case ZFCP_ERP_STEP_UNINITIALIZED:
  668. zfcp_erp_port_strategy_clearstati(port);
  669. if ((status & ZFCP_STATUS_PORT_PHYS_OPEN) &&
  670. (status & ZFCP_STATUS_COMMON_OPEN))
  671. return zfcp_erp_port_forced_strategy_close(erp_action);
  672. else
  673. return ZFCP_ERP_FAILED;
  674. case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
  675. if (status & ZFCP_STATUS_PORT_PHYS_OPEN)
  676. return ZFCP_ERP_SUCCEEDED;
  677. }
  678. return ZFCP_ERP_FAILED;
  679. }
  680. static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
  681. {
  682. int retval;
  683. retval = zfcp_fsf_close_port(erp_action);
  684. if (retval == -ENOMEM)
  685. return ZFCP_ERP_NOMEM;
  686. erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
  687. if (retval)
  688. return ZFCP_ERP_FAILED;
  689. return ZFCP_ERP_CONTINUES;
  690. }
  691. static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
  692. {
  693. int retval;
  694. retval = zfcp_fsf_open_port(erp_action);
  695. if (retval == -ENOMEM)
  696. return ZFCP_ERP_NOMEM;
  697. erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
  698. if (retval)
  699. return ZFCP_ERP_FAILED;
  700. return ZFCP_ERP_CONTINUES;
  701. }
  702. static int zfcp_erp_open_ptp_port(struct zfcp_erp_action *act)
  703. {
  704. struct zfcp_adapter *adapter = act->adapter;
  705. struct zfcp_port *port = act->port;
  706. if (port->wwpn != adapter->peer_wwpn) {
  707. zfcp_erp_port_failed(port, 25, NULL);
  708. return ZFCP_ERP_FAILED;
  709. }
  710. port->d_id = adapter->peer_d_id;
  711. return zfcp_erp_port_strategy_open_port(act);
  712. }
  713. void zfcp_erp_port_strategy_open_lookup(struct work_struct *work)
  714. {
  715. int retval;
  716. struct zfcp_port *port = container_of(work, struct zfcp_port,
  717. gid_pn_work);
  718. retval = zfcp_fc_ns_gid_pn(&port->erp_action);
  719. if (retval == -ENOMEM)
  720. zfcp_erp_notify(&port->erp_action, ZFCP_ERP_NOMEM);
  721. port->erp_action.step = ZFCP_ERP_STEP_NAMESERVER_LOOKUP;
  722. if (retval)
  723. zfcp_erp_notify(&port->erp_action, ZFCP_ERP_FAILED);
  724. }
  725. static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *act)
  726. {
  727. struct zfcp_adapter *adapter = act->adapter;
  728. struct zfcp_port *port = act->port;
  729. int p_status = atomic_read(&port->status);
  730. switch (act->step) {
  731. case ZFCP_ERP_STEP_UNINITIALIZED:
  732. case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
  733. case ZFCP_ERP_STEP_PORT_CLOSING:
  734. if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP)
  735. return zfcp_erp_open_ptp_port(act);
  736. if (!port->d_id) {
  737. queue_work(zfcp_data.work_queue, &port->gid_pn_work);
  738. return ZFCP_ERP_CONTINUES;
  739. }
  740. case ZFCP_ERP_STEP_NAMESERVER_LOOKUP:
  741. if (!port->d_id) {
  742. if (p_status & (ZFCP_STATUS_PORT_INVALID_WWPN)) {
  743. zfcp_erp_port_failed(port, 26, NULL);
  744. return ZFCP_ERP_EXIT;
  745. }
  746. return ZFCP_ERP_FAILED;
  747. }
  748. return zfcp_erp_port_strategy_open_port(act);
  749. case ZFCP_ERP_STEP_PORT_OPENING:
  750. /* D_ID might have changed during open */
  751. if (p_status & ZFCP_STATUS_COMMON_OPEN) {
  752. if (port->d_id)
  753. return ZFCP_ERP_SUCCEEDED;
  754. else {
  755. act->step = ZFCP_ERP_STEP_PORT_CLOSING;
  756. return ZFCP_ERP_CONTINUES;
  757. }
  758. /* fall through otherwise */
  759. }
  760. }
  761. return ZFCP_ERP_FAILED;
  762. }
  763. static int zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
  764. {
  765. struct zfcp_port *port = erp_action->port;
  766. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC)
  767. goto close_init_done;
  768. switch (erp_action->step) {
  769. case ZFCP_ERP_STEP_UNINITIALIZED:
  770. zfcp_erp_port_strategy_clearstati(port);
  771. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN)
  772. return zfcp_erp_port_strategy_close(erp_action);
  773. break;
  774. case ZFCP_ERP_STEP_PORT_CLOSING:
  775. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN)
  776. return ZFCP_ERP_FAILED;
  777. break;
  778. }
  779. close_init_done:
  780. if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
  781. return ZFCP_ERP_EXIT;
  782. return zfcp_erp_port_strategy_open_common(erp_action);
  783. }
  784. static void zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
  785. {
  786. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  787. ZFCP_STATUS_UNIT_SHARED |
  788. ZFCP_STATUS_UNIT_READONLY,
  789. &unit->status);
  790. }
  791. static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
  792. {
  793. int retval = zfcp_fsf_close_unit(erp_action);
  794. if (retval == -ENOMEM)
  795. return ZFCP_ERP_NOMEM;
  796. erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
  797. if (retval)
  798. return ZFCP_ERP_FAILED;
  799. return ZFCP_ERP_CONTINUES;
  800. }
  801. static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
  802. {
  803. int retval = zfcp_fsf_open_unit(erp_action);
  804. if (retval == -ENOMEM)
  805. return ZFCP_ERP_NOMEM;
  806. erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
  807. if (retval)
  808. return ZFCP_ERP_FAILED;
  809. return ZFCP_ERP_CONTINUES;
  810. }
  811. static int zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
  812. {
  813. struct zfcp_unit *unit = erp_action->unit;
  814. switch (erp_action->step) {
  815. case ZFCP_ERP_STEP_UNINITIALIZED:
  816. zfcp_erp_unit_strategy_clearstati(unit);
  817. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
  818. return zfcp_erp_unit_strategy_close(erp_action);
  819. /* already closed, fall through */
  820. case ZFCP_ERP_STEP_UNIT_CLOSING:
  821. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
  822. return ZFCP_ERP_FAILED;
  823. if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
  824. return ZFCP_ERP_EXIT;
  825. return zfcp_erp_unit_strategy_open(erp_action);
  826. case ZFCP_ERP_STEP_UNIT_OPENING:
  827. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
  828. return ZFCP_ERP_SUCCEEDED;
  829. }
  830. return ZFCP_ERP_FAILED;
  831. }
  832. static int zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
  833. {
  834. switch (result) {
  835. case ZFCP_ERP_SUCCEEDED :
  836. atomic_set(&unit->erp_counter, 0);
  837. zfcp_erp_unit_unblock(unit);
  838. break;
  839. case ZFCP_ERP_FAILED :
  840. atomic_inc(&unit->erp_counter);
  841. if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS) {
  842. dev_err(&unit->port->adapter->ccw_device->dev,
  843. "ERP failed for unit 0x%016Lx on "
  844. "port 0x%016Lx\n",
  845. (unsigned long long)unit->fcp_lun,
  846. (unsigned long long)unit->port->wwpn);
  847. zfcp_erp_unit_failed(unit, 21, NULL);
  848. }
  849. break;
  850. }
  851. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
  852. zfcp_erp_unit_block(unit, 0);
  853. result = ZFCP_ERP_EXIT;
  854. }
  855. return result;
  856. }
  857. static int zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
  858. {
  859. switch (result) {
  860. case ZFCP_ERP_SUCCEEDED :
  861. atomic_set(&port->erp_counter, 0);
  862. zfcp_erp_port_unblock(port);
  863. break;
  864. case ZFCP_ERP_FAILED :
  865. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC) {
  866. zfcp_erp_port_block(port, 0);
  867. result = ZFCP_ERP_EXIT;
  868. }
  869. atomic_inc(&port->erp_counter);
  870. if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS) {
  871. dev_err(&port->adapter->ccw_device->dev,
  872. "ERP failed for remote port 0x%016Lx\n",
  873. (unsigned long long)port->wwpn);
  874. zfcp_erp_port_failed(port, 22, NULL);
  875. }
  876. break;
  877. }
  878. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
  879. zfcp_erp_port_block(port, 0);
  880. result = ZFCP_ERP_EXIT;
  881. }
  882. return result;
  883. }
  884. static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter,
  885. int result)
  886. {
  887. switch (result) {
  888. case ZFCP_ERP_SUCCEEDED :
  889. atomic_set(&adapter->erp_counter, 0);
  890. zfcp_erp_adapter_unblock(adapter);
  891. break;
  892. case ZFCP_ERP_FAILED :
  893. atomic_inc(&adapter->erp_counter);
  894. if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS) {
  895. dev_err(&adapter->ccw_device->dev,
  896. "ERP cannot recover an error "
  897. "on the FCP device\n");
  898. zfcp_erp_adapter_failed(adapter, 23, NULL);
  899. }
  900. break;
  901. }
  902. if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
  903. zfcp_erp_adapter_block(adapter, 0);
  904. result = ZFCP_ERP_EXIT;
  905. }
  906. return result;
  907. }
  908. static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action,
  909. int result)
  910. {
  911. struct zfcp_adapter *adapter = erp_action->adapter;
  912. struct zfcp_port *port = erp_action->port;
  913. struct zfcp_unit *unit = erp_action->unit;
  914. switch (erp_action->action) {
  915. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  916. result = zfcp_erp_strategy_check_unit(unit, result);
  917. break;
  918. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  919. case ZFCP_ERP_ACTION_REOPEN_PORT:
  920. result = zfcp_erp_strategy_check_port(port, result);
  921. break;
  922. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  923. result = zfcp_erp_strategy_check_adapter(adapter, result);
  924. break;
  925. }
  926. return result;
  927. }
  928. static int zfcp_erp_strat_change_det(atomic_t *target_status, u32 erp_status)
  929. {
  930. int status = atomic_read(target_status);
  931. if ((status & ZFCP_STATUS_COMMON_RUNNING) &&
  932. (erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
  933. return 1; /* take it online */
  934. if (!(status & ZFCP_STATUS_COMMON_RUNNING) &&
  935. !(erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
  936. return 1; /* take it offline */
  937. return 0;
  938. }
  939. static int zfcp_erp_strategy_statechange(struct zfcp_erp_action *act, int ret)
  940. {
  941. int action = act->action;
  942. struct zfcp_adapter *adapter = act->adapter;
  943. struct zfcp_port *port = act->port;
  944. struct zfcp_unit *unit = act->unit;
  945. u32 erp_status = act->status;
  946. switch (action) {
  947. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  948. if (zfcp_erp_strat_change_det(&adapter->status, erp_status)) {
  949. _zfcp_erp_adapter_reopen(adapter,
  950. ZFCP_STATUS_COMMON_ERP_FAILED,
  951. 67, NULL);
  952. return ZFCP_ERP_EXIT;
  953. }
  954. break;
  955. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  956. case ZFCP_ERP_ACTION_REOPEN_PORT:
  957. if (zfcp_erp_strat_change_det(&port->status, erp_status)) {
  958. _zfcp_erp_port_reopen(port,
  959. ZFCP_STATUS_COMMON_ERP_FAILED,
  960. 68, NULL);
  961. return ZFCP_ERP_EXIT;
  962. }
  963. break;
  964. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  965. if (zfcp_erp_strat_change_det(&unit->status, erp_status)) {
  966. _zfcp_erp_unit_reopen(unit,
  967. ZFCP_STATUS_COMMON_ERP_FAILED,
  968. 69, NULL);
  969. return ZFCP_ERP_EXIT;
  970. }
  971. break;
  972. }
  973. return ret;
  974. }
  975. static void zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
  976. {
  977. struct zfcp_adapter *adapter = erp_action->adapter;
  978. adapter->erp_total_count--;
  979. if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
  980. adapter->erp_low_mem_count--;
  981. erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
  982. }
  983. list_del(&erp_action->list);
  984. zfcp_rec_dbf_event_action(144, erp_action);
  985. switch (erp_action->action) {
  986. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  987. atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
  988. &erp_action->unit->status);
  989. break;
  990. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  991. case ZFCP_ERP_ACTION_REOPEN_PORT:
  992. atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
  993. &erp_action->port->status);
  994. break;
  995. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  996. atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
  997. &erp_action->adapter->status);
  998. break;
  999. }
  1000. }
  1001. struct zfcp_erp_add_work {
  1002. struct zfcp_unit *unit;
  1003. struct work_struct work;
  1004. };
  1005. static void zfcp_erp_scsi_scan(struct work_struct *work)
  1006. {
  1007. struct zfcp_erp_add_work *p =
  1008. container_of(work, struct zfcp_erp_add_work, work);
  1009. struct zfcp_unit *unit = p->unit;
  1010. struct fc_rport *rport = unit->port->rport;
  1011. if (rport && rport->port_state == FC_PORTSTATE_ONLINE)
  1012. scsi_scan_target(&rport->dev, 0, rport->scsi_target_id,
  1013. scsilun_to_int((struct scsi_lun *)&unit->fcp_lun), 0);
  1014. atomic_clear_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
  1015. zfcp_unit_put(unit);
  1016. wake_up(&unit->port->adapter->erp_done_wqh);
  1017. kfree(p);
  1018. }
  1019. static void zfcp_erp_schedule_work(struct zfcp_unit *unit)
  1020. {
  1021. struct zfcp_erp_add_work *p;
  1022. p = kzalloc(sizeof(*p), GFP_KERNEL);
  1023. if (!p) {
  1024. dev_err(&unit->port->adapter->ccw_device->dev,
  1025. "Registering unit 0x%016Lx on port 0x%016Lx failed\n",
  1026. (unsigned long long)unit->fcp_lun,
  1027. (unsigned long long)unit->port->wwpn);
  1028. return;
  1029. }
  1030. zfcp_unit_get(unit);
  1031. atomic_set_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
  1032. INIT_WORK(&p->work, zfcp_erp_scsi_scan);
  1033. p->unit = unit;
  1034. queue_work(zfcp_data.work_queue, &p->work);
  1035. }
  1036. static void zfcp_erp_rport_register(struct zfcp_port *port)
  1037. {
  1038. struct fc_rport_identifiers ids;
  1039. ids.node_name = port->wwnn;
  1040. ids.port_name = port->wwpn;
  1041. ids.port_id = port->d_id;
  1042. ids.roles = FC_RPORT_ROLE_FCP_TARGET;
  1043. port->rport = fc_remote_port_add(port->adapter->scsi_host, 0, &ids);
  1044. if (!port->rport) {
  1045. dev_err(&port->adapter->ccw_device->dev,
  1046. "Registering port 0x%016Lx failed\n",
  1047. (unsigned long long)port->wwpn);
  1048. return;
  1049. }
  1050. scsi_target_unblock(&port->rport->dev);
  1051. port->rport->maxframe_size = port->maxframe_size;
  1052. port->rport->supported_classes = port->supported_classes;
  1053. }
  1054. static void zfcp_erp_rports_del(struct zfcp_adapter *adapter)
  1055. {
  1056. struct zfcp_port *port;
  1057. list_for_each_entry(port, &adapter->port_list_head, list) {
  1058. if (!port->rport)
  1059. continue;
  1060. fc_remote_port_delete(port->rport);
  1061. port->rport = NULL;
  1062. }
  1063. }
  1064. static void zfcp_erp_action_cleanup(struct zfcp_erp_action *act, int result)
  1065. {
  1066. struct zfcp_adapter *adapter = act->adapter;
  1067. struct zfcp_port *port = act->port;
  1068. struct zfcp_unit *unit = act->unit;
  1069. switch (act->action) {
  1070. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  1071. if ((result == ZFCP_ERP_SUCCEEDED) &&
  1072. !unit->device && port->rport) {
  1073. atomic_set_mask(ZFCP_STATUS_UNIT_REGISTERED,
  1074. &unit->status);
  1075. if (!(atomic_read(&unit->status) &
  1076. ZFCP_STATUS_UNIT_SCSI_WORK_PENDING))
  1077. zfcp_erp_schedule_work(unit);
  1078. }
  1079. zfcp_unit_put(unit);
  1080. break;
  1081. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  1082. case ZFCP_ERP_ACTION_REOPEN_PORT:
  1083. if (atomic_read(&port->status) & ZFCP_STATUS_PORT_NO_WWPN) {
  1084. zfcp_port_put(port);
  1085. return;
  1086. }
  1087. if ((result == ZFCP_ERP_SUCCEEDED) && !port->rport)
  1088. zfcp_erp_rport_register(port);
  1089. if ((result != ZFCP_ERP_SUCCEEDED) && port->rport) {
  1090. fc_remote_port_delete(port->rport);
  1091. port->rport = NULL;
  1092. }
  1093. zfcp_port_put(port);
  1094. break;
  1095. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  1096. if (result != ZFCP_ERP_SUCCEEDED) {
  1097. unregister_service_level(&adapter->service_level);
  1098. zfcp_erp_rports_del(adapter);
  1099. } else {
  1100. register_service_level(&adapter->service_level);
  1101. schedule_work(&adapter->scan_work);
  1102. }
  1103. zfcp_adapter_put(adapter);
  1104. break;
  1105. }
  1106. }
  1107. static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
  1108. {
  1109. switch (erp_action->action) {
  1110. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  1111. return zfcp_erp_adapter_strategy(erp_action);
  1112. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  1113. return zfcp_erp_port_forced_strategy(erp_action);
  1114. case ZFCP_ERP_ACTION_REOPEN_PORT:
  1115. return zfcp_erp_port_strategy(erp_action);
  1116. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  1117. return zfcp_erp_unit_strategy(erp_action);
  1118. }
  1119. return ZFCP_ERP_FAILED;
  1120. }
  1121. static int zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
  1122. {
  1123. int retval;
  1124. struct zfcp_adapter *adapter = erp_action->adapter;
  1125. unsigned long flags;
  1126. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1127. write_lock(&adapter->erp_lock);
  1128. zfcp_erp_strategy_check_fsfreq(erp_action);
  1129. if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
  1130. zfcp_erp_action_dequeue(erp_action);
  1131. retval = ZFCP_ERP_DISMISSED;
  1132. goto unlock;
  1133. }
  1134. zfcp_erp_action_to_running(erp_action);
  1135. /* no lock to allow for blocking operations */
  1136. write_unlock(&adapter->erp_lock);
  1137. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1138. retval = zfcp_erp_strategy_do_action(erp_action);
  1139. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1140. write_lock(&adapter->erp_lock);
  1141. if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED)
  1142. retval = ZFCP_ERP_CONTINUES;
  1143. switch (retval) {
  1144. case ZFCP_ERP_NOMEM:
  1145. if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
  1146. ++adapter->erp_low_mem_count;
  1147. erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
  1148. }
  1149. if (adapter->erp_total_count == adapter->erp_low_mem_count)
  1150. _zfcp_erp_adapter_reopen(adapter, 0, 66, NULL);
  1151. else {
  1152. zfcp_erp_strategy_memwait(erp_action);
  1153. retval = ZFCP_ERP_CONTINUES;
  1154. }
  1155. goto unlock;
  1156. case ZFCP_ERP_CONTINUES:
  1157. if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
  1158. --adapter->erp_low_mem_count;
  1159. erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
  1160. }
  1161. goto unlock;
  1162. }
  1163. retval = zfcp_erp_strategy_check_target(erp_action, retval);
  1164. zfcp_erp_action_dequeue(erp_action);
  1165. retval = zfcp_erp_strategy_statechange(erp_action, retval);
  1166. if (retval == ZFCP_ERP_EXIT)
  1167. goto unlock;
  1168. zfcp_erp_strategy_followup_actions(erp_action);
  1169. unlock:
  1170. write_unlock(&adapter->erp_lock);
  1171. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1172. if (retval != ZFCP_ERP_CONTINUES)
  1173. zfcp_erp_action_cleanup(erp_action, retval);
  1174. return retval;
  1175. }
  1176. static int zfcp_erp_thread(void *data)
  1177. {
  1178. struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
  1179. struct list_head *next;
  1180. struct zfcp_erp_action *act;
  1181. unsigned long flags;
  1182. int ignore;
  1183. daemonize("zfcperp%s", dev_name(&adapter->ccw_device->dev));
  1184. /* Block all signals */
  1185. siginitsetinv(&current->blocked, 0);
  1186. atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
  1187. wake_up(&adapter->erp_thread_wqh);
  1188. while (!(atomic_read(&adapter->status) &
  1189. ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL)) {
  1190. write_lock_irqsave(&adapter->erp_lock, flags);
  1191. next = adapter->erp_ready_head.next;
  1192. write_unlock_irqrestore(&adapter->erp_lock, flags);
  1193. if (next != &adapter->erp_ready_head) {
  1194. act = list_entry(next, struct zfcp_erp_action, list);
  1195. /* there is more to come after dismission, no notify */
  1196. if (zfcp_erp_strategy(act) != ZFCP_ERP_DISMISSED)
  1197. zfcp_erp_wakeup(adapter);
  1198. }
  1199. zfcp_rec_dbf_event_thread_lock(4, adapter);
  1200. ignore = down_interruptible(&adapter->erp_ready_sem);
  1201. zfcp_rec_dbf_event_thread_lock(5, adapter);
  1202. }
  1203. atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
  1204. wake_up(&adapter->erp_thread_wqh);
  1205. return 0;
  1206. }
  1207. /**
  1208. * zfcp_erp_thread_setup - Start ERP thread for adapter
  1209. * @adapter: Adapter to start the ERP thread for
  1210. *
  1211. * Returns 0 on success or error code from kernel_thread()
  1212. */
  1213. int zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
  1214. {
  1215. int retval;
  1216. atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
  1217. retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD);
  1218. if (retval < 0) {
  1219. dev_err(&adapter->ccw_device->dev,
  1220. "Creating an ERP thread for the FCP device failed.\n");
  1221. return retval;
  1222. }
  1223. wait_event(adapter->erp_thread_wqh,
  1224. atomic_read(&adapter->status) &
  1225. ZFCP_STATUS_ADAPTER_ERP_THREAD_UP);
  1226. return 0;
  1227. }
  1228. /**
  1229. * zfcp_erp_thread_kill - Stop ERP thread.
  1230. * @adapter: Adapter where the ERP thread should be stopped.
  1231. *
  1232. * The caller of this routine ensures that the specified adapter has
  1233. * been shut down and that this operation has been completed. Thus,
  1234. * there are no pending erp_actions which would need to be handled
  1235. * here.
  1236. */
  1237. void zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
  1238. {
  1239. atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status);
  1240. up(&adapter->erp_ready_sem);
  1241. zfcp_rec_dbf_event_thread_lock(3, adapter);
  1242. wait_event(adapter->erp_thread_wqh,
  1243. !(atomic_read(&adapter->status) &
  1244. ZFCP_STATUS_ADAPTER_ERP_THREAD_UP));
  1245. atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
  1246. &adapter->status);
  1247. }
  1248. /**
  1249. * zfcp_erp_adapter_failed - Set adapter status to failed.
  1250. * @adapter: Failed adapter.
  1251. * @id: Event id for debug trace.
  1252. * @ref: Reference for debug trace.
  1253. */
  1254. void zfcp_erp_adapter_failed(struct zfcp_adapter *adapter, u8 id, void *ref)
  1255. {
  1256. zfcp_erp_modify_adapter_status(adapter, id, ref,
  1257. ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
  1258. }
  1259. /**
  1260. * zfcp_erp_port_failed - Set port status to failed.
  1261. * @port: Failed port.
  1262. * @id: Event id for debug trace.
  1263. * @ref: Reference for debug trace.
  1264. */
  1265. void zfcp_erp_port_failed(struct zfcp_port *port, u8 id, void *ref)
  1266. {
  1267. zfcp_erp_modify_port_status(port, id, ref,
  1268. ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
  1269. }
  1270. /**
  1271. * zfcp_erp_unit_failed - Set unit status to failed.
  1272. * @unit: Failed unit.
  1273. * @id: Event id for debug trace.
  1274. * @ref: Reference for debug trace.
  1275. */
  1276. void zfcp_erp_unit_failed(struct zfcp_unit *unit, u8 id, void *ref)
  1277. {
  1278. zfcp_erp_modify_unit_status(unit, id, ref,
  1279. ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
  1280. }
  1281. /**
  1282. * zfcp_erp_wait - wait for completion of error recovery on an adapter
  1283. * @adapter: adapter for which to wait for completion of its error recovery
  1284. */
  1285. void zfcp_erp_wait(struct zfcp_adapter *adapter)
  1286. {
  1287. wait_event(adapter->erp_done_wqh,
  1288. !(atomic_read(&adapter->status) &
  1289. ZFCP_STATUS_ADAPTER_ERP_PENDING));
  1290. }
  1291. /**
  1292. * zfcp_erp_modify_adapter_status - change adapter status bits
  1293. * @adapter: adapter to change the status
  1294. * @id: id for the debug trace
  1295. * @ref: reference for the debug trace
  1296. * @mask: status bits to change
  1297. * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
  1298. *
  1299. * Changes in common status bits are propagated to attached ports and units.
  1300. */
  1301. void zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter, u8 id,
  1302. void *ref, u32 mask, int set_or_clear)
  1303. {
  1304. struct zfcp_port *port;
  1305. u32 common_mask = mask & ZFCP_COMMON_FLAGS;
  1306. if (set_or_clear == ZFCP_SET) {
  1307. if (status_change_set(mask, &adapter->status))
  1308. zfcp_rec_dbf_event_adapter(id, ref, adapter);
  1309. atomic_set_mask(mask, &adapter->status);
  1310. } else {
  1311. if (status_change_clear(mask, &adapter->status))
  1312. zfcp_rec_dbf_event_adapter(id, ref, adapter);
  1313. atomic_clear_mask(mask, &adapter->status);
  1314. if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
  1315. atomic_set(&adapter->erp_counter, 0);
  1316. }
  1317. if (common_mask)
  1318. list_for_each_entry(port, &adapter->port_list_head, list)
  1319. zfcp_erp_modify_port_status(port, id, ref, common_mask,
  1320. set_or_clear);
  1321. }
  1322. /**
  1323. * zfcp_erp_modify_port_status - change port status bits
  1324. * @port: port to change the status bits
  1325. * @id: id for the debug trace
  1326. * @ref: reference for the debug trace
  1327. * @mask: status bits to change
  1328. * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
  1329. *
  1330. * Changes in common status bits are propagated to attached units.
  1331. */
  1332. void zfcp_erp_modify_port_status(struct zfcp_port *port, u8 id, void *ref,
  1333. u32 mask, int set_or_clear)
  1334. {
  1335. struct zfcp_unit *unit;
  1336. u32 common_mask = mask & ZFCP_COMMON_FLAGS;
  1337. if (set_or_clear == ZFCP_SET) {
  1338. if (status_change_set(mask, &port->status))
  1339. zfcp_rec_dbf_event_port(id, ref, port);
  1340. atomic_set_mask(mask, &port->status);
  1341. } else {
  1342. if (status_change_clear(mask, &port->status))
  1343. zfcp_rec_dbf_event_port(id, ref, port);
  1344. atomic_clear_mask(mask, &port->status);
  1345. if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
  1346. atomic_set(&port->erp_counter, 0);
  1347. }
  1348. if (common_mask)
  1349. list_for_each_entry(unit, &port->unit_list_head, list)
  1350. zfcp_erp_modify_unit_status(unit, id, ref, common_mask,
  1351. set_or_clear);
  1352. }
  1353. /**
  1354. * zfcp_erp_modify_unit_status - change unit status bits
  1355. * @unit: unit to change the status bits
  1356. * @id: id for the debug trace
  1357. * @ref: reference for the debug trace
  1358. * @mask: status bits to change
  1359. * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
  1360. */
  1361. void zfcp_erp_modify_unit_status(struct zfcp_unit *unit, u8 id, void *ref,
  1362. u32 mask, int set_or_clear)
  1363. {
  1364. if (set_or_clear == ZFCP_SET) {
  1365. if (status_change_set(mask, &unit->status))
  1366. zfcp_rec_dbf_event_unit(id, ref, unit);
  1367. atomic_set_mask(mask, &unit->status);
  1368. } else {
  1369. if (status_change_clear(mask, &unit->status))
  1370. zfcp_rec_dbf_event_unit(id, ref, unit);
  1371. atomic_clear_mask(mask, &unit->status);
  1372. if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
  1373. atomic_set(&unit->erp_counter, 0);
  1374. }
  1375. }
  1376. }
  1377. /**
  1378. * zfcp_erp_port_boxed - Mark port as "boxed" and start ERP
  1379. * @port: The "boxed" port.
  1380. * @id: The debug trace id.
  1381. * @id: Reference for the debug trace.
  1382. */
  1383. void zfcp_erp_port_boxed(struct zfcp_port *port, u8 id, void *ref)
  1384. {
  1385. unsigned long flags;
  1386. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1387. zfcp_erp_modify_port_status(port, id, ref,
  1388. ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
  1389. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1390. zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
  1391. }
  1392. /**
  1393. * zfcp_erp_unit_boxed - Mark unit as "boxed" and start ERP
  1394. * @port: The "boxed" unit.
  1395. * @id: The debug trace id.
  1396. * @id: Reference for the debug trace.
  1397. */
  1398. void zfcp_erp_unit_boxed(struct zfcp_unit *unit, u8 id, void *ref)
  1399. {
  1400. zfcp_erp_modify_unit_status(unit, id, ref,
  1401. ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
  1402. zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
  1403. }
  1404. /**
  1405. * zfcp_erp_port_access_denied - Adapter denied access to port.
  1406. * @port: port where access has been denied
  1407. * @id: id for debug trace
  1408. * @ref: reference for debug trace
  1409. *
  1410. * Since the adapter has denied access, stop using the port and the
  1411. * attached units.
  1412. */
  1413. void zfcp_erp_port_access_denied(struct zfcp_port *port, u8 id, void *ref)
  1414. {
  1415. unsigned long flags;
  1416. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1417. zfcp_erp_modify_port_status(port, id, ref,
  1418. ZFCP_STATUS_COMMON_ERP_FAILED |
  1419. ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
  1420. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1421. }
  1422. /**
  1423. * zfcp_erp_unit_access_denied - Adapter denied access to unit.
  1424. * @unit: unit where access has been denied
  1425. * @id: id for debug trace
  1426. * @ref: reference for debug trace
  1427. *
  1428. * Since the adapter has denied access, stop using the unit.
  1429. */
  1430. void zfcp_erp_unit_access_denied(struct zfcp_unit *unit, u8 id, void *ref)
  1431. {
  1432. zfcp_erp_modify_unit_status(unit, id, ref,
  1433. ZFCP_STATUS_COMMON_ERP_FAILED |
  1434. ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
  1435. }
  1436. static void zfcp_erp_unit_access_changed(struct zfcp_unit *unit, u8 id,
  1437. void *ref)
  1438. {
  1439. int status = atomic_read(&unit->status);
  1440. if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1441. ZFCP_STATUS_COMMON_ACCESS_BOXED)))
  1442. return;
  1443. zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
  1444. }
  1445. static void zfcp_erp_port_access_changed(struct zfcp_port *port, u8 id,
  1446. void *ref)
  1447. {
  1448. struct zfcp_unit *unit;
  1449. int status = atomic_read(&port->status);
  1450. if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1451. ZFCP_STATUS_COMMON_ACCESS_BOXED))) {
  1452. list_for_each_entry(unit, &port->unit_list_head, list)
  1453. zfcp_erp_unit_access_changed(unit, id, ref);
  1454. return;
  1455. }
  1456. zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
  1457. }
  1458. /**
  1459. * zfcp_erp_adapter_access_changed - Process change in adapter ACT
  1460. * @adapter: Adapter where the Access Control Table (ACT) changed
  1461. * @id: Id for debug trace
  1462. * @ref: Reference for debug trace
  1463. */
  1464. void zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter, u8 id,
  1465. void *ref)
  1466. {
  1467. struct zfcp_port *port;
  1468. unsigned long flags;
  1469. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
  1470. return;
  1471. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1472. list_for_each_entry(port, &adapter->port_list_head, list)
  1473. zfcp_erp_port_access_changed(port, id, ref);
  1474. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1475. }